@component-hook/pdf-canvas 1.0.5-alpha.4 → 1.1.0-alpha.0
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/react/pdf-canvas.es.js +686 -686
- package/dist/react/pdf-canvas.umd.js +6 -6
- package/dist/vue/pdf-canvas.es.d.ts +9 -1
- package/dist/vue/pdf-canvas.es.js +2116 -2110
- package/dist/vue/pdf-canvas.umd.js +49 -49
- package/package.json +1 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
(function(
|
|
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(),Oi("log","WebGL: max texture size ".concat(this.maxTextureSize)))}isSupported(t){return!!this.maxTextureSize&&this.maxTextureSize>=t}}const vv={};let Xp;const ni=()=>Xp||(Xp={document,window,isTouchSupported:"ontouchstart"in window||"ontouchstart"in document||window&&window.navigator&&window.navigator.maxTouchPoints>0,WebGLProbe:new yv,dispose(){},copyPasteData:vv}),Vo=()=>ni().document,Hc=()=>ni().window,Wp=()=>{var a;return Math.max((a=ht.devicePixelRatio)!==null&&a!==void 0?a:Hc().devicePixelRatio,1)},xh=new class{constructor(){A(this,"charWidthsCache",{}),A(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}=ht,e=Math.sqrt(t*a);return[Math.floor(e),Math.floor(t/e)]}},rf="6.6.1";function pr(){}const An=Math.PI/2,Ri=2*Math.PI,of=Math.PI/180,Ee=Object.freeze([1,0,0,1,0,0]),af=16,Tn=.4477152502,J="center",dt="left",Ve="top",hf="bottom",It="right",ke="none",lf=/\r?\n/,Up="moving",Gc="scaling",Yp="rotating",cf="rotate",$p="skewing",Sh="resizing",_v="modifyPoly",wv="modifyPath",zc="changed",Vc="scale",Me="scaleX",Je="scaleY",Xo="skewX",Wo="skewY",zt="fill",Pe="stroke",Xc="modified",Uo="json",uf="svg",H=new class{constructor(){this[Uo]=new Map,this[uf]=new Map}has(a){return this[Uo].has(a)}getClass(a){const t=this[Uo].get(a);if(!t)throw new ii("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[uf].get(a)}setSVGClass(a,t){this[uf].set(t??a.type.toLowerCase(),a)}},Wc=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 xv{constructor(){A(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 mr=(a,t)=>{const e=a.indexOf(t);return e!==-1&&a.splice(e,1),a},Ds=a=>{if(a===0)return 1;switch(Math.abs(a)/An){case 1:case 3:return 0;case 2:return-1}return Math.cos(a)},Os=a=>{if(a===0)return 0;const t=a/An,e=Math.sign(a);switch(t){case 1:return e;case 2:return 0;case 3:return-e}return Math.sin(a)};class P{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 P(this.x+t.x,this.y+t.y)}addEquals(t){return this.x+=t.x,this.y+=t.y,this}scalarAdd(t){return new P(this.x+t,this.y+t)}scalarAddEquals(t){return this.x+=t,this.y+=t,this}subtract(t){return new P(this.x-t.x,this.y-t.y)}subtractEquals(t){return this.x-=t.x,this.y-=t.y,this}scalarSubtract(t){return new P(this.x-t,this.y-t)}scalarSubtractEquals(t){return this.x-=t,this.y-=t,this}multiply(t){return new P(this.x*t.x,this.y*t.y)}scalarMultiply(t){return new P(this.x*t,this.y*t)}scalarMultiplyEquals(t){return this.x*=t,this.y*=t,this}divide(t){return new P(this.x/t.x,this.y/t.y)}scalarDivide(t){return new P(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 P(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 P(Math.min(this.x,t.x),Math.min(this.y,t.y))}max(t){return new P(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 P(this.x,this.y)}rotate(t){let e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:df;const s=Os(t),i=Ds(t),n=this.subtract(e);return new P(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 P(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 df=new P(0,0),Uc=a=>!!a&&Array.isArray(a._objects);function qp(a){class t extends a{constructor(){super(...arguments),A(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 c=s.indexOf(h);c!==-1&&(s.splice(c,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])&&(mr(this._objects,s),this._objects.unshift(s),this._onStackOrderChanged(s),!0)}bringObjectToFront(s){return!(!s||s===this._objects[this._objects.length-1])&&(mr(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 mr(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 mr(this._objects,s),this._objects.splice(r,0,s),this._onStackOrderChanged(s),!0}return!1}moveObjectTo(s,i){return s!==this._objects[i]&&(mr(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 c=[],u=new P(i,n),d=u.add(new P(r,o));for(let f=this._objects.length-1;f>=0;f--){const g=this._objects[f];g.selectable&&g.visible&&(h&&g.intersectsWithRect(u,d)||g.isContainedWithinRect(u,d)||h&&g.containsPoint(u)||h&&g.containsPoint(d))&&c.push(g)}return c}}return t}class Kp extends xv{_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 Ch(a){return Hc().requestAnimationFrame(a)}function Qp(a){return Hc().cancelAnimationFrame(a)}let Sv=0;const En=()=>Sv++,ms=()=>{const a=Vo().createElement("canvas");if(!a||a.getContext===void 0)throw new ii("Failed to create `canvas` element");return a},Jp=()=>Vo().createElement("img"),Rs=a=>{const t=ms();return t.width=a.width,t.height=a.height,t},ff=(a,t,e)=>a.toDataURL("image/".concat(t),e),gf=(a,t,e)=>new Promise((s,i)=>{a.toBlob(s,"image/".concat(t),e)}),Rt=a=>a*of,kn=a=>a/of,Zp=a=>a.every((t,e)=>t===Ee[e]),ge=(a,t,e)=>new P(a).transform(t,e),Xe=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 P(a[4],a[5]).transform(e,!0);return e[4]=-s,e[5]=-i,e},Nt=(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]],Yc=(a,t)=>a.reduceRight((e,s)=>s&&e?Nt(s,e,t):s||e,void 0)||Ee.concat(),tm=a=>{let[t,e]=a;return Math.atan2(e,t)},br=a=>{const t=tm(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:kn(t),scaleX:s,scaleY:i,skewX:kn(n),skewY:0,translateX:a[4]||0,translateY:a[5]||0}},Yo=function(a){return[1,0,0,1,a,arguments.length>1&&arguments[1]!==void 0?arguments[1]:0]};function $o(){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=Rt(a),i=Ds(s),n=Os(s);return[i,n,-n,i,t?t-(i*t-n*e):0,e?e-(n*t+i*e):0]}const $c=function(a){return[a,0,0,arguments.length>1&&arguments[1]!==void 0?arguments[1]:a,0,0]},em=a=>Math.tan(Rt(a)),pf=a=>[1,0,em(a),1,0,0],mf=a=>[1,em(a),0,1,0,0],Ah=a=>{let{scaleX:t=1,scaleY:e=1,flipX:s=!1,flipY:i=!1,skewX:n=0,skewY:r=0}=a,o=$c(s?-t:t,i?-e:e);return n&&(o=Nt(o,pf(n),!0)),r&&(o=Nt(o,mf(r),!0)),o},sm=a=>{const{translateX:t=0,translateY:e=0,angle:s=0}=a;let i=Yo(t,e);s&&(i=Nt(i,$o({angle:s})));const n=Ah(a);return Zp(n)||(i=Nt(i,n)),i},Th=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 nf("loadImage"));const n=Jp();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 ii("Error loading ".concat(n.src)))},e&&(n.crossOrigin=e),n.src=a):o()})},qo=function(a){let{signal:t,reviver:e=pr}=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)})})},Eh=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)?qo([o],{signal:t}).then(h=>{let[c]=h;return i.push(c),c}):o),r=Object.keys(a);Promise.all(n).then(o=>o.reduce((h,c,u)=>(h[r[u]]=c,h),{})).then(e).catch(o=>{i.forEach(h=>{h.dispose&&h.dispose()}),s(o)}).finally(()=>{t&&t.removeEventListener("abort",s)})})},yr=function(a){return(arguments.length>1&&arguments[1]!==void 0?arguments[1]:[]).reduce((t,e)=>(e in a&&(t[e]=a[e]),t),{})},bf=(a,t)=>Object.keys(a).reduce((e,s)=>(t(a[s],s,a)&&(e[s]=a[s]),e),{}),im={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"},yf=(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),nm=(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 c=i-n;switch(o=h>.5?c/(2-i-n):c/(i+n),i){case a:r=(t-e)/c+(t<e?6:0);break;case t:r=(e-a)/c+2;break;case e:r=(a-t)/c+4}r/=6}return[Math.round(360*r),Math.round(100*o),Math.round(100*h),s]},rm=function(){let a=arguments.length>0&&arguments[0]!==void 0?arguments[0]:"1";return parseFloat(a)/(a.endsWith("%")?100:1)},qc=a=>Math.min(Math.round(a),255).toString(16).toUpperCase().padStart(2,"0"),om=a=>{let[t,e,s,i=1]=a;const n=Math.round(.3*t+.59*e+.11*s);return[n,n,n,i]};class gt{constructor(t){if(A(this,"isUnrecognised",!1),t)if(t instanceof gt)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=t.toLowerCase())in im&&(t=im[t]),t==="transparent"?[255,255,255,0]:gt.sourceFromHex(t)||gt.sourceFromRgb(t)||gt.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]=nm(...this.getSource());return"hsl(".concat(t,",").concat(e,"%,").concat(s,"%)")}toHsla(){const[t,e,s,i]=nm(...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(qc(t)).concat(qc(e)).concat(qc(s)).concat(qc(Math.round(255*i)))}getAlpha(){return this.getSource()[3]}setAlpha(t){return this._source[3]=t,this}toGrayscale(){return this.setSource(om(this.getSource())),this}toBlackWhite(t){const[e,,,s]=om(this.getSource()),i=e<(t||127)?0:255;return this.setSource([i,i,i,s]),this}overlayWith(t){t instanceof gt||(t=new gt(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 gt.fromRgba(t)}static fromRgba(t){return new gt(gt.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,rm(e[4])]}}static fromHsl(t){return gt.fromHsla(t)}static fromHsla(t){return new gt(gt.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=(gt.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 c=n<=.5?n*(i+1):n+i-n*i,u=2*n-c;r=yf(u,c,s+1/3),o=yf(u,c,s),h=yf(u,c,s-1/3)}return[Math.round(255*r),Math.round(255*o),Math.round(255*h),rm(e[4])]}static fromHex(t){return new gt(gt.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")?kn(s):e.includes("turn")?360*s:s}}const At=(a,t)=>parseFloat(Number(a).toFixed(t)),De=function(a){let t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:af;const e=/\D{0,2}$/.exec(a),s=parseFloat(a),i=ht.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}},vf=a=>{const[t,e]=a.trim().split(" "),[s,i]=(n=t)&&n!==ke?[n.slice(1,4),n.slice(5,8)]:n===ke?[n,n]:["Mid","Mid"];var n;return{meetOrSlice:e||"meet",alignX:s,alignY:i}},kh=a=>"matrix("+a.map(t=>At(t,ht.NUM_FRACTION_DIGITS)).join(" ")+")",Mh=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 gt(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,'" '):"")},bs=a=>!!a&&a.toLive!==void 0,am=a=>!!a&&typeof a.toObject=="function",hm=a=>!!a&&a.offsetX!==void 0&&"source"in a,vr=a=>!!a&&"multiSelectionStacking"in a;function lm(a){const t=a&&Ls(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 Ls=a=>a.ownerDocument||null,cm=a=>{var t;return((t=a.ownerDocument)===null||t===void 0?void 0:t.defaultView)||null},um=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))},_f=(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 dm(a){return a.onselectstart!==void 0&&(a.onselectstart=()=>!1),a.style.userSelect=ke,a}class fm{constructor(t){A(this,"_originalCanvasStyle",void 0),A(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&&Vo().getElementById(t)||ms();var s;if(e.hasAttribute("data-fabric"))throw new ii("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;um(s,i,t,e)}setCSSDimensions(t){_f(this.lower.el,t)}calcOffset(){return function(t){var e;const s=t&&Ls(t),i={left:0,top:0};if(!s)return i;const n=((e=cm(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=lm(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(){ni().dispose(this.lower.el),delete this.lower}}const Cv={backgroundVpt:!0,backgroundColor:"",overlayVpt:!0,overlayColor:"",includeDefaultValues:!0,svgViewportTransformation:!0,renderOnAddRemove:!0,skipOffscreen:!0,enableRetinaScaling:!0,imageSmoothingEnabled:!0,controlsAboveOverlay:!1,allowTouchScrolling:!1,viewportTransform:[...Ee]};class Ph extends qp(Kp){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 Ph.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 fm(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&&(Oi("warn",`Canvas is trying to add an object that belongs to a different canvas.
|
|
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?Wp():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=T({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=ge(t,Xe(i));i[0]=e,i[3]=e;const r=ge(n,i);i[4]+=s.x-r.x,i[5]+=s.y-r.y,this.setViewportTransform(i)}setZoom(t){this.zoomToPoint(new
|
|
1
|
+
(function(nt,q){typeof exports=="object"&&typeof module<"u"?q(exports,require("vue")):typeof define=="function"&&define.amd?define(["exports","vue"],q):(nt=typeof globalThis<"u"?globalThis:nt||self,q(nt["pdf-canvas"]={},nt.Vue))})(this,function(nt,q){"use strict";var CC=Object.defineProperty;var $b=nt=>{throw TypeError(nt)};var AC=(nt,q,_t)=>q in nt?CC(nt,q,{enumerable:!0,configurable:!0,writable:!0,value:_t}):nt[q]=_t;var $=(nt,q,_t)=>AC(nt,typeof q!="symbol"?q+"":q,_t),qg=(nt,q,_t)=>q.has(nt)||$b("Cannot "+_t);var l=(nt,q,_t)=>(qg(nt,q,"read from private field"),_t?_t.call(nt):q.get(nt)),y=(nt,q,_t)=>q.has(nt)?$b("Cannot add the same private member more than once"):q instanceof WeakSet?q.add(nt):q.set(nt,_t),m=(nt,q,_t,A)=>(qg(nt,q,"write to private field"),A?A.call(nt,_t):q.set(nt,_t),_t),w=(nt,q,_t)=>(qg(nt,q,"access private method"),_t);var Ge=(nt,q,_t,A)=>({set _(Bc){m(nt,q,Bc,_t)},get _(){return l(nt,q,A)}});var Xi,kd,Kg,Zh,In,Rr,zs,Lr,tl,el,hd,qb,Le,Kb,Qb,Md,Jb,Qg,sl,Fr,Ir,Nn,Zb,ty,ey,ld,ha,il,we,la,Pd,Bt,jn,nl,Dt,cd,sy,ca,ss,Kt,ae,ua,Ui,da,ws,Bn,Nr,fa,jr,ui,Vs,Br,rl,ol,ga,al,di,Hn,pa,Gn,fi,dd,zn,hl,Vn,Hr,ll,cl,ee,pt,Yi,Gr,ul,dl,Xn,gi,$i,fl,xs,I,Dd,Jg,iy,ny,Od,ry,oy,ay,Zg,hy,tp,ep,ly,ze,xn,cy,uy,sp,dy,Ac,ip,se,pi,Xs,ba,mi,is,ya,bi,$e,qi,zr,yi,Wn,Ws,Tc,Rd,gl,Vr,pl,ml,bl,yl,vl,va,Ki,Xr,Un,Qi,fy,gy,np,Wr,Us,xt,_a,Yn,_l,Ur,he,Yr,Ji,$n,wl,$r,ns,xl,qr,Zi,vi,wa,xa,Ss,Kr,Sl,fd,Y,rp,Cl,op,Ld,py,my,ap,Fd,hp,by,yy,vy,lp,_y,cp,wy,xy,Sy,up,Ec,Qr,Jr,ie,gd,Cy,Al,Sa,Ca,Cs,Ay,Ty,Ey,Id,Tl,Zr,Aa,tn,en,xe,to,eo,j,Te,kc,mh,Nd,bh,ky,dp,yh,Mc,Pc,fp,Dc,Ys,gp,pp,mp,El,kl,so,Ml,Pl,Dl,Ol,Ta,qn,mt,Ea,ka,Rl,bp,Yb,Kn,qe,Ll,Fl,io,sn,Il,Nl,no,Ma,Pa,Qn,Da,jl,Oa,ro,Bl,Hl,oo,ao,Gl,Jn,Ra,nn,My,Py,yp,rs,jd,vp,Dy,Oy,md,Zn,rn,As,vh,Bd,on,yd,vd,ho,lo,La,Hd,Fa,Gd,an,_i,Ia,Na,hn,co,Oc,os,zl,_p,tr,er,uo,go,ja,Ba,Vl,wp,as,Ho,Ry,Ly,Ha,_d,wd,Ga,po,Lt,ln,za,Xl,Wl,Va,cn,$s,un,Ul,dn,Yl,mo,bo,bt,zd,xp,Fy,Iy,Ny,jy,Vd,Xd,Sp,$l,ql,Kl,Ql,Jl,yo,Zl,Cp,tc,ec,Ap,sc,vo,_o,ic,wo,By,Tp,qs,hs,nc,xo,ls,Ut,Hy,Gy,zy,Wd,fn,Ud,Yd,Vy,Ep,Xy,cs,Ks,Xa,Wa,wi,it,So,Co,rc,oc,Ua,Ya,sr,ac,xd,Sd,Jt,Rc,Wy,Uy,Yy,$y,qy,Ky,$a,Ao,pn,hc,us,lc,Ht,Cd,Qy,cc,uc,ir,Qs,Ie,Jy,$d,Zy,tv,kp,dc,qa,Js,To,Ka,Zt,fc,Qa,gc,pc,nr,Zs,Ja,mc,yt,Mp,Pp,Dp,Go,ev,gr,Za,bc,mn,Eo,th,Qe,yc,vc,ko,Ts,ds,le,eh,bn,Se,sh,Es,_c,J,Op,qd,sv,iv,nv,Rp,zo,ks,_h,rv,Kd,Lc,ov,av,hv,lv,cv,Mo,fs,ih,ne,Po,Do,rr,or,ar,Oo,lt,Lp,Fp,Ip,Fc,uv,Qd,Ic,wh,xi,re,oe,Ro,nh,Ne,ce,Ms,Lo,Fo,Io,rh,Jd,je,wc,xc,gs,Si,Ci,oh,ah,hh,ue,Sn,dv,fv,gv,lh,Ad,pv,Ot,de,hr,yn,lr,uh,Ai,Ti,ps,dh,ct,Nc,jc,Zd,Np,tf,jp,ef,mv,No,fh,Ei,cr,vn,Ps,ur,gh,jo,ti,_n,Ce,wn,X,dr,kt,bv,Di,Bp,Hp,sf,si,Cc,Be,Bo,Td,yv,ki,Gp,vv,zp;var _t=typeof document<"u"?document.currentScript:null;function A(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);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 Bc(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 T(a){for(var t=1;t<arguments.length;t++){var e=arguments[t]!=null?arguments[t]:{};t%2?Bc(Object(e),!0).forEach(function(s){A(a,s,e[s])}):Object.getOwnPropertyDescriptors?Object.defineProperties(a,Object.getOwnPropertyDescriptors(e)):Bc(Object(e)).forEach(function(s){Object.defineProperty(a,s,Object.getOwnPropertyDescriptor(e,s))})}return a}function Ct(a,t){if(a==null)return{};var e,s,i=function(r,o){if(r==null)return{};var h={};for(var c in r)if({}.hasOwnProperty.call(r,c)){if(o.indexOf(c)>=0)continue;h[c]=r[c]}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 Cn(a,t){return t||(t=a.slice(0)),Object.freeze(Object.defineProperties(a,{raw:{value:Object.freeze(t)}}))}class Vp{constructor(){A(this,"browserShadowBlurConstant",1),A(this,"DPI",96),A(this,"devicePixelRatio",typeof window<"u"?window.devicePixelRatio:1),A(this,"perfLimitSizeTotal",2097152),A(this,"maxCacheSideLimit",4096),A(this,"minCacheSideLimit",256),A(this,"disableStyleCopyPaste",!1),A(this,"enableGLFiltering",!0),A(this,"textureSize",4096),A(this,"forceGLPutImageData",!1),A(this,"cachesBoundsOfCurve",!1),A(this,"fontPaths",{}),A(this,"NUM_FRACTION_DIGITS",4)}}const ht=new class extends Vp{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=T(T({},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 Vp,e=(a==null?void 0:a.reduce((s,i)=>(s[i]=t[i],s),{}))||t;this.configure(e)}},Oi=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 ii extends Error{constructor(t,e){super("fabric: ".concat(t),e)}}class nf extends ii{constructor(t){super("".concat(t," 'options.signal' is in 'aborted' state"))}}class _v{}class wv extends _v{testPrecision(t,e){const s="precision ".concat(e,` float;
|
|
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(),Oi("log","WebGL: max texture size ".concat(this.maxTextureSize)))}isSupported(t){return!!this.maxTextureSize&&this.maxTextureSize>=t}}const xv={};let Xp;const ni=()=>Xp||(Xp={document,window,isTouchSupported:"ontouchstart"in window||"ontouchstart"in document||window&&window.navigator&&window.navigator.maxTouchPoints>0,WebGLProbe:new wv,dispose(){},copyPasteData:xv}),Vo=()=>ni().document,Hc=()=>ni().window,Wp=()=>{var a;return Math.max((a=ht.devicePixelRatio)!==null&&a!==void 0?a:Hc().devicePixelRatio,1)},xh=new class{constructor(){A(this,"charWidthsCache",{}),A(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}=ht,e=Math.sqrt(t*a);return[Math.floor(e),Math.floor(t/e)]}},rf="6.6.1";function pr(){}const An=Math.PI/2,Ri=2*Math.PI,of=Math.PI/180,Ee=Object.freeze([1,0,0,1,0,0]),af=16,Tn=.4477152502,Q="center",dt="left",Ve="top",hf="bottom",It="right",ke="none",lf=/\r?\n/,Up="moving",Gc="scaling",Yp="rotating",cf="rotate",$p="skewing",Sh="resizing",Sv="modifyPoly",Cv="modifyPath",zc="changed",Vc="scale",Me="scaleX",Je="scaleY",Xo="skewX",Wo="skewY",zt="fill",Pe="stroke",Xc="modified",Uo="json",uf="svg",N=new class{constructor(){this[Uo]=new Map,this[uf]=new Map}has(a){return this[Uo].has(a)}getClass(a){const t=this[Uo].get(a);if(!t)throw new ii("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[uf].get(a)}setSVGClass(a,t){this[uf].set(t??a.type.toLowerCase(),a)}},Wc=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 Av{constructor(){A(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 mr=(a,t)=>{const e=a.indexOf(t);return e!==-1&&a.splice(e,1),a},Ds=a=>{if(a===0)return 1;switch(Math.abs(a)/An){case 1:case 3:return 0;case 2:return-1}return Math.cos(a)},Os=a=>{if(a===0)return 0;const t=a/An,e=Math.sign(a);switch(t){case 1:return e;case 2:return 0;case 3:return-e}return Math.sin(a)};class D{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 D(this.x+t.x,this.y+t.y)}addEquals(t){return this.x+=t.x,this.y+=t.y,this}scalarAdd(t){return new D(this.x+t,this.y+t)}scalarAddEquals(t){return this.x+=t,this.y+=t,this}subtract(t){return new D(this.x-t.x,this.y-t.y)}subtractEquals(t){return this.x-=t.x,this.y-=t.y,this}scalarSubtract(t){return new D(this.x-t,this.y-t)}scalarSubtractEquals(t){return this.x-=t,this.y-=t,this}multiply(t){return new D(this.x*t.x,this.y*t.y)}scalarMultiply(t){return new D(this.x*t,this.y*t)}scalarMultiplyEquals(t){return this.x*=t,this.y*=t,this}divide(t){return new D(this.x/t.x,this.y/t.y)}scalarDivide(t){return new D(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 D(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 D(Math.min(this.x,t.x),Math.min(this.y,t.y))}max(t){return new D(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 D(this.x,this.y)}rotate(t){let e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:df;const s=Os(t),i=Ds(t),n=this.subtract(e);return new D(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 D(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 df=new D(0,0),Uc=a=>!!a&&Array.isArray(a._objects);function qp(a){class t extends a{constructor(){super(...arguments),A(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 c=s.indexOf(h);c!==-1&&(s.splice(c,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])&&(mr(this._objects,s),this._objects.unshift(s),this._onStackOrderChanged(s),!0)}bringObjectToFront(s){return!(!s||s===this._objects[this._objects.length-1])&&(mr(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 mr(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 mr(this._objects,s),this._objects.splice(r,0,s),this._onStackOrderChanged(s),!0}return!1}moveObjectTo(s,i){return s!==this._objects[i]&&(mr(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 c=[],u=new D(i,n),d=u.add(new D(r,o));for(let f=this._objects.length-1;f>=0;f--){const g=this._objects[f];g.selectable&&g.visible&&(h&&g.intersectsWithRect(u,d)||g.isContainedWithinRect(u,d)||h&&g.containsPoint(u)||h&&g.containsPoint(d))&&c.push(g)}return c}}return t}class Kp extends Av{_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 Ch(a){return Hc().requestAnimationFrame(a)}function Qp(a){return Hc().cancelAnimationFrame(a)}let Tv=0;const En=()=>Tv++,ms=()=>{const a=Vo().createElement("canvas");if(!a||a.getContext===void 0)throw new ii("Failed to create `canvas` element");return a},Jp=()=>Vo().createElement("img"),Rs=a=>{const t=ms();return t.width=a.width,t.height=a.height,t},ff=(a,t,e)=>a.toDataURL("image/".concat(t),e),gf=(a,t,e)=>new Promise((s,i)=>{a.toBlob(s,"image/".concat(t),e)}),Rt=a=>a*of,kn=a=>a/of,Zp=a=>a.every((t,e)=>t===Ee[e]),ge=(a,t,e)=>new D(a).transform(t,e),Xe=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 D(a[4],a[5]).transform(e,!0);return e[4]=-s,e[5]=-i,e},Nt=(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]],Yc=(a,t)=>a.reduceRight((e,s)=>s&&e?Nt(s,e,t):s||e,void 0)||Ee.concat(),tm=a=>{let[t,e]=a;return Math.atan2(e,t)},br=a=>{const t=tm(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:kn(t),scaleX:s,scaleY:i,skewX:kn(n),skewY:0,translateX:a[4]||0,translateY:a[5]||0}},Yo=function(a){return[1,0,0,1,a,arguments.length>1&&arguments[1]!==void 0?arguments[1]:0]};function $o(){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=Rt(a),i=Ds(s),n=Os(s);return[i,n,-n,i,t?t-(i*t-n*e):0,e?e-(n*t+i*e):0]}const $c=function(a){return[a,0,0,arguments.length>1&&arguments[1]!==void 0?arguments[1]:a,0,0]},em=a=>Math.tan(Rt(a)),pf=a=>[1,0,em(a),1,0,0],mf=a=>[1,em(a),0,1,0,0],Ah=a=>{let{scaleX:t=1,scaleY:e=1,flipX:s=!1,flipY:i=!1,skewX:n=0,skewY:r=0}=a,o=$c(s?-t:t,i?-e:e);return n&&(o=Nt(o,pf(n),!0)),r&&(o=Nt(o,mf(r),!0)),o},sm=a=>{const{translateX:t=0,translateY:e=0,angle:s=0}=a;let i=Yo(t,e);s&&(i=Nt(i,$o({angle:s})));const n=Ah(a);return Zp(n)||(i=Nt(i,n)),i},Th=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 nf("loadImage"));const n=Jp();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 ii("Error loading ".concat(n.src)))},e&&(n.crossOrigin=e),n.src=a):o()})},qo=function(a){let{signal:t,reviver:e=pr}=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=>N.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)})})},Eh=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&&N.has(o.type)?qo([o],{signal:t}).then(h=>{let[c]=h;return i.push(c),c}):o),r=Object.keys(a);Promise.all(n).then(o=>o.reduce((h,c,u)=>(h[r[u]]=c,h),{})).then(e).catch(o=>{i.forEach(h=>{h.dispose&&h.dispose()}),s(o)}).finally(()=>{t&&t.removeEventListener("abort",s)})})},yr=function(a){return(arguments.length>1&&arguments[1]!==void 0?arguments[1]:[]).reduce((t,e)=>(e in a&&(t[e]=a[e]),t),{})},bf=(a,t)=>Object.keys(a).reduce((e,s)=>(t(a[s],s,a)&&(e[s]=a[s]),e),{}),im={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"},yf=(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),nm=(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 c=i-n;switch(o=h>.5?c/(2-i-n):c/(i+n),i){case a:r=(t-e)/c+(t<e?6:0);break;case t:r=(e-a)/c+2;break;case e:r=(a-t)/c+4}r/=6}return[Math.round(360*r),Math.round(100*o),Math.round(100*h),s]},rm=function(){let a=arguments.length>0&&arguments[0]!==void 0?arguments[0]:"1";return parseFloat(a)/(a.endsWith("%")?100:1)},qc=a=>Math.min(Math.round(a),255).toString(16).toUpperCase().padStart(2,"0"),om=a=>{let[t,e,s,i=1]=a;const n=Math.round(.3*t+.59*e+.11*s);return[n,n,n,i]};class gt{constructor(t){if(A(this,"isUnrecognised",!1),t)if(t instanceof gt)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=t.toLowerCase())in im&&(t=im[t]),t==="transparent"?[255,255,255,0]:gt.sourceFromHex(t)||gt.sourceFromRgb(t)||gt.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]=nm(...this.getSource());return"hsl(".concat(t,",").concat(e,"%,").concat(s,"%)")}toHsla(){const[t,e,s,i]=nm(...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(qc(t)).concat(qc(e)).concat(qc(s)).concat(qc(Math.round(255*i)))}getAlpha(){return this.getSource()[3]}setAlpha(t){return this._source[3]=t,this}toGrayscale(){return this.setSource(om(this.getSource())),this}toBlackWhite(t){const[e,,,s]=om(this.getSource()),i=e<(t||127)?0:255;return this.setSource([i,i,i,s]),this}overlayWith(t){t instanceof gt||(t=new gt(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 gt.fromRgba(t)}static fromRgba(t){return new gt(gt.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,rm(e[4])]}}static fromHsl(t){return gt.fromHsla(t)}static fromHsla(t){return new gt(gt.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=(gt.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 c=n<=.5?n*(i+1):n+i-n*i,u=2*n-c;r=yf(u,c,s+1/3),o=yf(u,c,s),h=yf(u,c,s-1/3)}return[Math.round(255*r),Math.round(255*o),Math.round(255*h),rm(e[4])]}static fromHex(t){return new gt(gt.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")?kn(s):e.includes("turn")?360*s:s}}const At=(a,t)=>parseFloat(Number(a).toFixed(t)),De=function(a){let t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:af;const e=/\D{0,2}$/.exec(a),s=parseFloat(a),i=ht.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}},vf=a=>{const[t,e]=a.trim().split(" "),[s,i]=(n=t)&&n!==ke?[n.slice(1,4),n.slice(5,8)]:n===ke?[n,n]:["Mid","Mid"];var n;return{meetOrSlice:e||"meet",alignX:s,alignY:i}},kh=a=>"matrix("+a.map(t=>At(t,ht.NUM_FRACTION_DIGITS)).join(" ")+")",Mh=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 gt(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,'" '):"")},bs=a=>!!a&&a.toLive!==void 0,am=a=>!!a&&typeof a.toObject=="function",hm=a=>!!a&&a.offsetX!==void 0&&"source"in a,vr=a=>!!a&&"multiSelectionStacking"in a;function lm(a){const t=a&&Ls(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 Ls=a=>a.ownerDocument||null,cm=a=>{var t;return((t=a.ownerDocument)===null||t===void 0?void 0:t.defaultView)||null},um=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))},_f=(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 dm(a){return a.onselectstart!==void 0&&(a.onselectstart=()=>!1),a.style.userSelect=ke,a}class fm{constructor(t){A(this,"_originalCanvasStyle",void 0),A(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&&Vo().getElementById(t)||ms();var s;if(e.hasAttribute("data-fabric"))throw new ii("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;um(s,i,t,e)}setCSSDimensions(t){_f(this.lower.el,t)}calcOffset(){return function(t){var e;const s=t&&Ls(t),i={left:0,top:0};if(!s)return i;const n=((e=cm(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=lm(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(){ni().dispose(this.lower.el),delete this.lower}}const Ev={backgroundVpt:!0,backgroundColor:"",overlayVpt:!0,overlayColor:"",includeDefaultValues:!0,svgViewportTransformation:!0,renderOnAddRemove:!0,skipOffscreen:!0,enableRetinaScaling:!0,imageSmoothingEnabled:!0,controlsAboveOverlay:!1,allowTouchScrolling:!1,viewportTransform:[...Ee]};class Ph extends qp(Kp){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 Ph.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 fm(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&&(Oi("warn",`Canvas is trying to add an object that belongs to a different canvas.
|
|
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?Wp():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=T({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=ge(t,Xe(i));i[0]=e,i[3]=e;const r=ge(n,i);i[4]+=s.x-r.x,i[5]+=s.y-r.y,this.setViewportTransform(i)}setZoom(t){this.zoomToPoint(new D(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 D(-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=Ch(()=>this.renderAndReset()))}calcViewportBoundaries(){const t=this.width,e=this.height,s=Xe(this.viewportTransform),i=ge({x:0,y:0},s),n=ge({x:t,y:e},s),r=i.min(n),o=i.max(n);return this.vptCoords={tl:r,tr:new D(o.x,r.y),bl:new D(r.x,o.y),br:o}}cancelRequestedRender(){this.nextRenderHandle&&(Qp(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=bs(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 D(this.width/2,this.height/2)}centerObjectH(t){return this._centerObject(t,new D(this.getCenterPoint().x,t.getCenterPoint().y))}centerObjectV(t){return this._centerObject(t,new D(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 D(this.getVpCenter().x,t.getCenterPoint().y))}viewportCenterObjectV(t){return this._centerObject(t,new D(t.getCenterPoint().x,this.getVpCenter().y))}getVpCenter(){return ge(this.getCenterPoint(),Xe(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 T(T(T({version:rf},yr(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 bs(r)?r.excludeFromExport||(s.background=r.toObject(e)):r&&(s.background=r),bs(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>
|
|
5
5
|
`),this._setSVGBgOverlayColor(s,"overlay"),this._setSVGBgOverlayImage(s,"overlayImage",e),s.push("</svg>"),s.join("")}_setSVGPreamble(t,e){e.suppressPreamble||t.push('<?xml version="1.0" encoding="',e.encoding||"UTF-8",`" standalone="no" ?>
|
|
6
6
|
`,'<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" ',`"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
|
|
@@ -18,13 +18,13 @@ Resulting to default behavior: removing object from previous canvas and adding t
|
|
|
18
18
|
`.concat(i,`]]></style>
|
|
19
19
|
`):""}_setSVGObjects(t,e){this.forEachObject(s=>{s.excludeFromExport||this._setSVGObject(t,s,e)})}_setSVGObject(t,e,s){t.push(e.toSVG(s))}_setSVGBgOverlayImage(t,e,s){const i=this[e];i&&!i.excludeFromExport&&i.toSVG&&t.push(i.toSVG(s))}_setSVGBgOverlayColor(t,e){const s=this["".concat(e,"Color")];if(s)if(bs(s)){const i=s.repeat||"",n=this.width,r=this.height,o=this["".concat(e,"Vpt")]?kh(Xe(this.viewportTransform)):"";t.push('<rect transform="'.concat(o," translate(").concat(n/2,",").concat(r/2,')" x="').concat(s.offsetX-n/2,'" y="').concat(s.offsetY-r/2,'" width="').concat(i!=="repeat-y"&&i!=="no-repeat"||!hm(s)?n:s.source.width,'" height="').concat(i!=="repeat-x"&&i!=="no-repeat"||!hm(s)?r:s.source.height,'" fill="url(#SVGID_').concat(s.id,`)"></rect>
|
|
20
20
|
`))}else t.push('<rect x="0" y="0" width="100%" height="100%" ','fill="',s,'"',`></rect>
|
|
21
|
-
`)}loadFromJSON(t,e){let{signal:s}=arguments.length>2&&arguments[2]!==void 0?arguments[2]:{};if(!t)return Promise.reject(new ii("`json` is undefined"));const i=typeof t=="string"?JSON.parse(t):t,{objects:n=[],backgroundImage:r,background:o,overlayImage:h,overlay:c,clipPath:u}=i,d=this.renderOnAddRemove;return this.renderOnAddRemove=!1,Promise.all([qo(n,{reviver:e,signal:s}),Eh({backgroundImage:r,backgroundColor:o,overlayImage:h,overlayColor:c,clipPath:u},{signal:s})]).then(f=>{let[g,p]=f;return this.clear(),this.add(...g),this.set(i),this.set(p),this.renderOnAddRemove=d,this})}clone(t){const e=this.toObject(t);return this.cloneWithoutData().loadFromJSON(e)}cloneWithoutData(){const t=Rs(this);return new this.constructor(t)}toDataURL(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};const{format:e="png",quality:s=1,multiplier:i=1,enableRetinaScaling:n=!1}=t,r=i*(n?this.getRetinaScaling():1);return ff(this.toCanvasElement(r,t),e,s)}toBlob(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};const{format:e="png",quality:s=1,multiplier:i=1,enableRetinaScaling:n=!1}=t,r=i*(n?this.getRetinaScaling():1);return gf(this.toCanvasElement(r,t),e,s)}toCanvasElement(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:1,{width:e,height:s,left:i,top:n,filter:r}=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};const o=(e||this.width)*t,h=(s||this.height)*t,c=this.getZoom(),u=this.width,d=this.height,f=this.skipControlsDrawing,g=c*t,p=this.viewportTransform,b=[g,0,0,g,(p[4]-(i||0))*t,(p[5]-(n||0))*t],_=this.enableRetinaScaling,v=Rs({width:o,height:h}),x=r?this._objects.filter(C=>r(C)):this._objects;return this.enableRetinaScaling=!1,this.viewportTransform=b,this.width=o,this.height=h,this.skipControlsDrawing=!0,this.calcViewportBoundaries(),this.renderCanvas(v.getContext("2d"),x),this.viewportTransform=p,this.width=u,this.height=d,this.calcViewportBoundaries(),this.enableRetinaScaling=_,this.skipControlsDrawing=f,v}dispose(){return!this.disposed&&this.elements.cleanupDOM({width:this.width,height:this.height}),Wc.cancelByCanvas(this),this.disposed=!0,new Promise((t,e)=>{const s=()=>{this.destroy(),t(!0)};s.kill=e,this.__cleanupTask&&this.__cleanupTask.kill("aborted"),this.destroyed?t(!1):this.nextRenderHandle?this.__cleanupTask=s:s()})}destroy(){this.destroyed=!0,this.cancelRequestedRender(),this.forEachObject(t=>t.dispose()),this._objects=[],this.backgroundImage&&this.backgroundImage.dispose(),this.backgroundImage=void 0,this.overlayImage&&this.overlayImage.dispose(),this.overlayImage=void 0,this.elements.dispose()}toString(){return"#<Canvas (".concat(this.complexity(),"): { objects: ").concat(this._objects.length," }>")}}A(Ph,"ownDefaults",
|
|
21
|
+
`)}loadFromJSON(t,e){let{signal:s}=arguments.length>2&&arguments[2]!==void 0?arguments[2]:{};if(!t)return Promise.reject(new ii("`json` is undefined"));const i=typeof t=="string"?JSON.parse(t):t,{objects:n=[],backgroundImage:r,background:o,overlayImage:h,overlay:c,clipPath:u}=i,d=this.renderOnAddRemove;return this.renderOnAddRemove=!1,Promise.all([qo(n,{reviver:e,signal:s}),Eh({backgroundImage:r,backgroundColor:o,overlayImage:h,overlayColor:c,clipPath:u},{signal:s})]).then(f=>{let[g,p]=f;return this.clear(),this.add(...g),this.set(i),this.set(p),this.renderOnAddRemove=d,this})}clone(t){const e=this.toObject(t);return this.cloneWithoutData().loadFromJSON(e)}cloneWithoutData(){const t=Rs(this);return new this.constructor(t)}toDataURL(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};const{format:e="png",quality:s=1,multiplier:i=1,enableRetinaScaling:n=!1}=t,r=i*(n?this.getRetinaScaling():1);return ff(this.toCanvasElement(r,t),e,s)}toBlob(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};const{format:e="png",quality:s=1,multiplier:i=1,enableRetinaScaling:n=!1}=t,r=i*(n?this.getRetinaScaling():1);return gf(this.toCanvasElement(r,t),e,s)}toCanvasElement(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:1,{width:e,height:s,left:i,top:n,filter:r}=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};const o=(e||this.width)*t,h=(s||this.height)*t,c=this.getZoom(),u=this.width,d=this.height,f=this.skipControlsDrawing,g=c*t,p=this.viewportTransform,b=[g,0,0,g,(p[4]-(i||0))*t,(p[5]-(n||0))*t],_=this.enableRetinaScaling,v=Rs({width:o,height:h}),x=r?this._objects.filter(C=>r(C)):this._objects;return this.enableRetinaScaling=!1,this.viewportTransform=b,this.width=o,this.height=h,this.skipControlsDrawing=!0,this.calcViewportBoundaries(),this.renderCanvas(v.getContext("2d"),x),this.viewportTransform=p,this.width=u,this.height=d,this.calcViewportBoundaries(),this.enableRetinaScaling=_,this.skipControlsDrawing=f,v}dispose(){return!this.disposed&&this.elements.cleanupDOM({width:this.width,height:this.height}),Wc.cancelByCanvas(this),this.disposed=!0,new Promise((t,e)=>{const s=()=>{this.destroy(),t(!0)};s.kill=e,this.__cleanupTask&&this.__cleanupTask.kill("aborted"),this.destroyed?t(!1):this.nextRenderHandle?this.__cleanupTask=s:s()})}destroy(){this.destroyed=!0,this.cancelRequestedRender(),this.forEachObject(t=>t.dispose()),this._objects=[],this.backgroundImage&&this.backgroundImage.dispose(),this.backgroundImage=void 0,this.overlayImage&&this.overlayImage.dispose(),this.overlayImage=void 0,this.elements.dispose()}toString(){return"#<Canvas (".concat(this.complexity(),"): { objects: ").concat(this._objects.length," }>")}}A(Ph,"ownDefaults",Ev);const kv=["touchstart","touchmove","touchend"],gm=a=>{const t=lm(a.target),e=function(s){const i=s.changedTouches;return i&&i[0]?i[0]:s}(a);return new D(e.clientX+t.left,e.clientY+t.top)},Kc=a=>kv.includes(a.type)||a.pointerType==="touch",wf=a=>{a.preventDefault(),a.stopPropagation()},ri=a=>{let t=0,e=0,s=0,i=0;for(let n=0,r=a.length;n<r;n++){const{x:o,y:h}=a[n];(o>s||!n)&&(s=o),(o<t||!n)&&(t=o),(h>i||!n)&&(i=h),(h<e||!n)&&(e=h)}return{left:t,top:e,width:s-t,height:i-e}},Mv=["translateX","translateY","scaleX","scaleY"],pm=(a,t)=>Ko(a,Nt(t,a.calcOwnMatrix())),Ko=(a,t)=>{const e=br(t),{translateX:s,translateY:i,scaleX:n,scaleY:r}=e,o=Ct(e,Mv),h=new D(s,i);a.flipX=!1,a.flipY=!1,Object.assign(a,o),a.set({scaleX:n,scaleY:r}),a.setPositionByOrigin(h,Q,Q)},mm=a=>{a.scaleX=1,a.scaleY=1,a.skewX=0,a.skewY=0,a.flipX=!1,a.flipY=!1,a.rotate(0)},xf=a=>({scaleX:a.scaleX,scaleY:a.scaleY,skewX:a.skewX,skewY:a.skewY,angle:a.angle,left:a.left,flipX:a.flipX,flipY:a.flipY,top:a.top}),Qc=(a,t,e)=>{const s=a/2,i=t/2,n=[new D(-s,-i),new D(s,-i),new D(-s,i),new D(s,i)].map(o=>o.transform(e)),r=ri(n);return new D(r.width,r.height)},Dh=function(){let a=arguments.length>0&&arguments[0]!==void 0?arguments[0]:Ee;return Nt(Xe(arguments.length>1&&arguments[1]!==void 0?arguments[1]:Ee),a)},_r=function(a){let t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:Ee,e=arguments.length>2&&arguments[2]!==void 0?arguments[2]:Ee;return a.transform(Dh(t,e))},bm=function(a){let t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:Ee,e=arguments.length>2&&arguments[2]!==void 0?arguments[2]:Ee;return a.transform(Dh(t,e),!0)},Sf=(a,t,e)=>{const s=Dh(t,e);return Ko(a,Nt(s,a.calcOwnMatrix())),s},ym=(a,t)=>{var e;const{transform:{target:s}}=t;(e=s.canvas)===null||e===void 0||e.fire("object:".concat(a),T(T({},t),{},{target:s})),s.fire(a,t)},Pv={left:-.5,top:-.5,center:0,bottom:.5,right:.5},Vt=a=>typeof a=="string"?Pv[a]:a-.5,Jc="not-allowed";function vm(a){return Vt(a.originX)===Vt(Q)&&Vt(a.originY)===Vt(Q)}function _m(a){return .5-Vt(a)}const Fs=(a,t)=>a[t],wm=(a,t,e,s)=>({e:a,transform:t,pointer:new D(e,s)});function xm(a,t){const e=a.getTotalAngle()+kn(Math.atan2(t.y,t.x))+360;return Math.round(e%360/45)}function Cf(a,t,e,s,i){var n;let{target:r,corner:o}=a;const h=r.controls[o],c=((n=r.canvas)===null||n===void 0?void 0:n.getZoom())||1,u=r.padding/c,d=function(f,g,p,b){const _=f.getRelativeCenterPoint(),v=p!==void 0&&b!==void 0?f.translateToGivenOrigin(_,Q,Q,p,b):new D(f.left,f.top);return(f.angle?g.rotate(-Rt(f.angle),_):g).subtract(v)}(r,new D(s,i),t,e);return d.x>=u&&(d.x-=u),d.x<=-u&&(d.x+=u),d.y>=u&&(d.y-=u),d.y<=u&&(d.y+=u),d.x-=h.offsetX,d.y-=h.offsetY,d}const Dv=(a,t,e,s)=>{const{target:i,offsetX:n,offsetY:r}=t,o=e-n,h=s-r,c=!Fs(i,"lockMovementX")&&i.left!==o,u=!Fs(i,"lockMovementY")&&i.top!==h;return c&&i.set(dt,o),u&&i.set(Ve,h),(c||u)&&ym(Up,wm(a,t,e,s)),c||u};class Sm{getSvgStyles(t){const e=this.fillRule?this.fillRule:"nonzero",s=this.strokeWidth?this.strokeWidth:"0",i=this.strokeDashArray?this.strokeDashArray.join(" "):ke,n=this.strokeDashOffset?this.strokeDashOffset:"0",r=this.strokeLineCap?this.strokeLineCap:"butt",o=this.strokeLineJoin?this.strokeLineJoin:"miter",h=this.strokeMiterLimit?this.strokeMiterLimit:"4",c=this.opacity!==void 0?this.opacity:"1",u=this.visible?"":" visibility: hidden;",d=t?"":this.getSvgFilter(),f=Mh(zt,this.fill);return[Mh(Pe,this.stroke),"stroke-width: ",s,"; ","stroke-dasharray: ",i,"; ","stroke-linecap: ",r,"; ","stroke-dashoffset: ",n,"; ","stroke-linejoin: ",o,"; ","stroke-miterlimit: ",h,"; ",f,"fill-rule: ",e,"; ","opacity: ",c,";",d,u].join("")}getSvgFilter(){return this.shadow?"filter: url(#SVGID_".concat(this.shadow.id,");"):""}getSvgCommons(){return[this.id?'id="'.concat(this.id,'" '):"",this.clipPath?'clip-path="url(#'.concat(this.clipPath.clipPathId,')" '):""].join("")}getSvgTransform(t){let e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:"";const s=t?this.calcTransformMatrix():this.calcOwnMatrix(),i='transform="'.concat(kh(s));return"".concat(i).concat(e,'" ')}_toSVG(t){return[""]}toSVG(t){return this._createBaseSVGMarkup(this._toSVG(t),{reviver:t})}toClipPathSVG(t){return" "+this._createBaseClipPathSVGMarkup(this._toSVG(t),{reviver:t})}_createBaseClipPathSVGMarkup(t){let{reviver:e,additionalTransform:s=""}=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};const i=[this.getSvgTransform(!0,s),this.getSvgCommons()].join(""),n=t.indexOf("COMMON_PARTS");return t[n]=i,e?e(t.join("")):t.join("")}_createBaseSVGMarkup(t){let{noStyle:e,reviver:s,withShadow:i,additionalTransform:n}=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};const r=e?"":'style="'.concat(this.getSvgStyles(),'" '),o=i?'style="'.concat(this.getSvgFilter(),'" '):"",h=this.clipPath,c=this.strokeUniform?'vector-effect="non-scaling-stroke" ':"",u=h&&h.absolutePositioned,d=this.stroke,f=this.fill,g=this.shadow,p=[],b=t.indexOf("COMMON_PARTS");let _;h&&(h.clipPathId="CLIPPATH_".concat(En()),_='<clipPath id="'.concat(h.clipPathId,`" >
|
|
22
22
|
`).concat(h.toClipPathSVG(s),`</clipPath>
|
|
23
23
|
`)),u&&p.push("<g ",o,this.getSvgCommons(),` >
|
|
24
24
|
`),p.push("<g ",this.getSvgTransform(!1),u?"":o+this.getSvgCommons(),` >
|
|
25
25
|
`);const v=[r,c,e?"":this.addPaintOrder()," ",n?'transform="'.concat(n,'" '):""].join("");return t[b]=v,bs(f)&&p.push(f.toSVG(this)),bs(d)&&p.push(d.toSVG(this)),g&&p.push(g.toSVG(this)),h&&p.push(_),p.push(t.join("")),p.push(`</g>
|
|
26
26
|
`),u&&p.push(`</g>
|
|
27
|
-
`),s?s(p.join("")):p.join("")}addPaintOrder(){return this.paintFirst!==zt?' paint-order="'.concat(this.paintFirst,'" '):""}}function Zc(a){return new RegExp("^("+a.join("|")+")\\b","i")}var Cm;const Is=String.raw(Cm||(Cm=Cn(["(?:[-+]?(?:d*.d+|d+.?)(?:[eE][-+]?d+)?)"],["(?:[-+]?(?:\\d*\\.\\d+|\\d+\\.?)(?:[eE][-+]?\\d+)?)"]))),Af="http://www.w3.org/2000/svg",
|
|
27
|
+
`),s?s(p.join("")):p.join("")}addPaintOrder(){return this.paintFirst!==zt?' paint-order="'.concat(this.paintFirst,'" '):""}}function Zc(a){return new RegExp("^("+a.join("|")+")\\b","i")}var Cm;const Is=String.raw(Cm||(Cm=Cn(["(?:[-+]?(?:d*.d+|d+.?)(?:[eE][-+]?d+)?)"],["(?:[-+]?(?:\\d*\\.\\d+|\\d+\\.?)(?:[eE][-+]?\\d+)?)"]))),Af="http://www.w3.org/2000/svg",Ov=new RegExp("(normal|italic)?\\s*(normal|small-caps)?\\s*(normal|bold|bolder|lighter|100|200|300|400|500|600|700|800|900)?\\s*("+Is+"(?:px|cm|mm|em|pt|pc|in)*)(?:\\/(normal|"+Is+"))?\\s+(.*)"),Rv={cx:dt,x:dt,r:"radius",cy:Ve,y:Ve,display:"visible",visibility:"visible",transform:"transformMatrix","fill-opacity":"fillOpacity","fill-rule":"fillRule","font-family":"fontFamily","font-size":"fontSize","font-style":"fontStyle","font-weight":"fontWeight","letter-spacing":"charSpacing","paint-order":"paintFirst","stroke-dasharray":"strokeDashArray","stroke-dashoffset":"strokeDashOffset","stroke-linecap":"strokeLineCap","stroke-linejoin":"strokeLineJoin","stroke-miterlimit":"strokeMiterLimit","stroke-opacity":"strokeOpacity","stroke-width":"strokeWidth","text-decoration":"textDecoration","text-anchor":"textAnchor",opacity:"opacity","clip-path":"clipPath","clip-rule":"clipRule","vector-effect":"strokeUniform","image-rendering":"imageSmoothing"},Tf="font-size",Ef="clip-path",Lv=Zc(["path","circle","polygon","polyline","ellipse","rect","line","image","text"]),Fv=Zc(["symbol","image","marker","pattern","view","svg"]),Am=Zc(["symbol","g","a","svg","clipPath","defs"]),Tm=new RegExp("^\\s*("+Is+"+)\\s*,?\\s*("+Is+"+)\\s*,?\\s*("+Is+"+)\\s*,?\\s*("+Is+"+)\\s*$"),Iv=new D(1,0),Em=new D,kf=(a,t)=>a.rotate(t),tu=(a,t)=>new D(t).subtract(a),eu=a=>a.distanceFrom(Em),su=(a,t)=>Math.atan2(Qo(a,t),Mm(a,t)),km=a=>su(Iv,a),iu=a=>a.eq(Em)?a:a.scalarDivide(eu(a)),Mf=function(a){let t=!(arguments.length>1&&arguments[1]!==void 0)||arguments[1];return iu(new D(-a.y,a.x).scalarMultiply(t?1:-1))},Qo=(a,t)=>a.x*t.y-a.y*t.x,Mm=(a,t)=>a.x*t.x+a.y*t.y,Pf=(a,t,e)=>{if(a.eq(t)||a.eq(e))return!0;const s=Qo(t,e),i=Qo(t,a),n=Qo(e,a);return s>=0?i>=0&&n<=0:!(i<=0&&n>=0)},Pm="(-?\\d+(?:\\.\\d*)?(?:px)?(?:\\s?|$))?",Dm=new RegExp("(?:\\s|^)"+Pm+Pm+"("+Is+"?(?:px)?)?(?:\\s?|$)(?:$|\\s)");class Li{constructor(t){const e=typeof t=="string"?Li.parseShadow(t):t;Object.assign(this,Li.ownDefaults,e),this.id=En()}static parseShadow(t){const e=t.trim(),[,s=0,i=0,n=0]=(Dm.exec(e)||[]).map(r=>parseFloat(r)||0);return{color:(e.replace(Dm,"")||"rgb(0,0,0)").trim(),offsetX:s,offsetY:i,blur:n}}toString(){return[this.offsetX,this.offsetY,this.blur,this.color].join("px ")}toSVG(t){const e=kf(new D(this.offsetX,this.offsetY),Rt(-t.angle)),s=new gt(this.color);let i=40,n=40;return t.width&&t.height&&(i=100*At((Math.abs(e.x)+this.blur)/t.width,ht.NUM_FRACTION_DIGITS)+20,n=100*At((Math.abs(e.y)+this.blur)/t.height,ht.NUM_FRACTION_DIGITS)+20),t.flipX&&(e.x*=-1),t.flipY&&(e.y*=-1),'<filter id="SVGID_'.concat(this.id,'" y="-').concat(n,'%" height="').concat(100+2*n,'%" x="-').concat(i,'%" width="').concat(100+2*i,`%" >
|
|
28
28
|
<feGaussianBlur in="SourceAlpha" stdDeviation="`).concat(At(this.blur?this.blur/2:0,ht.NUM_FRACTION_DIGITS),`"></feGaussianBlur>
|
|
29
29
|
<feOffset dx="`).concat(At(e.x,ht.NUM_FRACTION_DIGITS),'" dy="').concat(At(e.y,ht.NUM_FRACTION_DIGITS),`" result="oBlur" ></feOffset>
|
|
30
30
|
<feFlood flood-color="`).concat(s.toRgb(),'" flood-opacity="').concat(s.getAlpha(),`"/>
|
|
@@ -34,44 +34,44 @@ Resulting to default behavior: removing object from previous canvas and adding t
|
|
|
34
34
|
<feMergeNode in="SourceGraphic"></feMergeNode>
|
|
35
35
|
</feMerge>
|
|
36
36
|
</filter>
|
|
37
|
-
`)}toObject(){const t={color:this.color,blur:this.blur,offsetX:this.offsetX,offsetY:this.offsetY,affectStroke:this.affectStroke,nonScaling:this.nonScaling,type:this.constructor.type},e=Li.ownDefaults;return this.includeDefaultValues?t:bf(t,(s,i)=>s!==e[i])}static async fromObject(t){return new this(t)}}A(Li,"ownDefaults",{color:"rgb(0,0,0)",blur:0,offsetX:0,offsetY:0,affectStroke:!1,includeDefaultValues:!0,nonScaling:!1}),A(Li,"type","shadow"),H.setClass(Li,"shadow");const wr=(a,t,e)=>Math.max(a,Math.min(t,e)),Lv=[Ve,dt,Me,Je,"flipX","flipY","originX","originY","angle","opacity","globalCompositeOperation","shadow","visible",Xo,Wo],Fi=[zt,Pe,"strokeWidth","strokeDashArray","width","height","paintFirst","strokeUniform","strokeLineCap","strokeDashOffset","strokeLineJoin","strokeMiterLimit","backgroundColor","clipPath"],Fv={top:0,left:0,width:0,height:0,angle:0,flipX:!1,flipY:!1,scaleX:1,scaleY:1,minScaleLimit:0,skewX:0,skewY:0,originX:dt,originY:Ve,strokeWidth:1,strokeUniform:!1,padding:0,opacity:1,paintFirst:zt,fill:"rgb(0,0,0)",fillRule:"nonzero",stroke:null,strokeDashArray:null,strokeDashOffset:0,strokeLineCap:"butt",strokeLineJoin:"miter",strokeMiterLimit:4,globalCompositeOperation:"source-over",backgroundColor:"",shadow:null,visible:!0,includeDefaultValues:!0,excludeFromExport:!1,objectCaching:!0,clipPath:void 0,inverted:!1,absolutePositioned:!1,centeredRotation:!0,centeredScaling:!1,dirty:!0},Df=(a,t,e,s)=>(a<Math.abs(t)?(a=t,s=e/4):s=t===0&&a===0?e/Ri*Math.asin(1):e/Ri*Math.asin(t/a),{a,c:t,p:e,s}),Om=(a,t,e,s,i)=>a*Math.pow(2,10*(s-=1))*Math.sin((s*i-t)*Ri/e),Rm=(a,t,e,s)=>-e*Math.cos(a/s*An)+e+t,Of=(a,t,e,s)=>(a/=s)<1/2.75?e*(7.5625*a*a)+t:a<2/2.75?e*(7.5625*(a-=1.5/2.75)*a+.75)+t:a<2.5/2.75?e*(7.5625*(a-=2.25/2.75)*a+.9375)+t:e*(7.5625*(a-=2.625/2.75)*a+.984375)+t,Lm=(a,t,e,s)=>e-Of(s-a,0,e,s)+t;var Iv=Object.freeze({__proto__:null,defaultEasing:Rm,easeInBack:function(a,t,e,s){let i=arguments.length>4&&arguments[4]!==void 0?arguments[4]:1.70158;return e*(a/=s)*a*((i+1)*a-i)+t},easeInBounce:Lm,easeInCirc:(a,t,e,s)=>-e*(Math.sqrt(1-(a/=s)*a)-1)+t,easeInCubic:(a,t,e,s)=>e*(a/s)**3+t,easeInElastic:(a,t,e,s)=>{const i=e;let n=0;if(a===0)return t;if((a/=s)===1)return t+e;n||(n=.3*s);const{a:r,s:o,p:h}=Df(i,e,n,1.70158);return-Om(r,o,h,a,s)+t},easeInExpo:(a,t,e,s)=>a===0?t:e*2**(10*(a/s-1))+t,easeInOutBack:function(a,t,e,s){let i=arguments.length>4&&arguments[4]!==void 0?arguments[4]:1.70158;return(a/=s/2)<1?e/2*(a*a*((1+(i*=1.525))*a-i))+t:e/2*((a-=2)*a*((1+(i*=1.525))*a+i)+2)+t},easeInOutBounce:(a,t,e,s)=>a<s/2?.5*Lm(2*a,0,e,s)+t:.5*Of(2*a-s,0,e,s)+.5*e+t,easeInOutCirc:(a,t,e,s)=>(a/=s/2)<1?-e/2*(Math.sqrt(1-a**2)-1)+t:e/2*(Math.sqrt(1-(a-=2)*a)+1)+t,easeInOutCubic:(a,t,e,s)=>(a/=s/2)<1?e/2*a**3+t:e/2*((a-2)**3+2)+t,easeInOutElastic:(a,t,e,s)=>{const i=e;let n=0;if(a===0)return t;if((a/=s/2)===2)return t+e;n||(n=s*(.3*1.5));const{a:r,s:o,p:h,c}=Df(i,e,n,1.70158);return a<1?-.5*Om(r,o,h,a,s)+t:r*Math.pow(2,-10*(a-=1))*Math.sin((a*s-o)*Ri/h)*.5+c+t},easeInOutExpo:(a,t,e,s)=>a===0?t:a===s?t+e:(a/=s/2)<1?e/2*2**(10*(a-1))+t:e/2*-(2**(-10*--a)+2)+t,easeInOutQuad:(a,t,e,s)=>(a/=s/2)<1?e/2*a**2+t:-e/2*(--a*(a-2)-1)+t,easeInOutQuart:(a,t,e,s)=>(a/=s/2)<1?e/2*a**4+t:-e/2*((a-=2)*a**3-2)+t,easeInOutQuint:(a,t,e,s)=>(a/=s/2)<1?e/2*a**5+t:e/2*((a-2)**5+2)+t,easeInOutSine:(a,t,e,s)=>-e/2*(Math.cos(Math.PI*a/s)-1)+t,easeInQuad:(a,t,e,s)=>e*(a/=s)*a+t,easeInQuart:(a,t,e,s)=>e*(a/=s)*a**3+t,easeInQuint:(a,t,e,s)=>e*(a/s)**5+t,easeInSine:(a,t,e,s)=>-e*Math.cos(a/s*An)+e+t,easeOutBack:function(a,t,e,s){let i=arguments.length>4&&arguments[4]!==void 0?arguments[4]:1.70158;return e*((a=a/s-1)*a*((i+1)*a+i)+1)+t},easeOutBounce:Of,easeOutCirc:(a,t,e,s)=>e*Math.sqrt(1-(a=a/s-1)*a)+t,easeOutCubic:(a,t,e,s)=>e*((a/s-1)**3+1)+t,easeOutElastic:(a,t,e,s)=>{const i=e;let n=0;if(a===0)return t;if((a/=s)===1)return t+e;n||(n=.3*s);const{a:r,s:o,p:h,c}=Df(i,e,n,1.70158);return r*2**(-10*a)*Math.sin((a*s-o)*Ri/h)+c+t},easeOutExpo:(a,t,e,s)=>a===s?t+e:e*-(2**(-10*a/s)+1)+t,easeOutQuad:(a,t,e,s)=>-e*(a/=s)*(a-2)+t,easeOutQuart:(a,t,e,s)=>-e*((a=a/s-1)*a**3-1)+t,easeOutQuint:(a,t,e,s)=>e*((a/s-1)**5+1)+t,easeOutSine:(a,t,e,s)=>e*Math.sin(a/s*An)+t});const Nv=()=>!1;class Rf{constructor(t){let{startValue:e,byValue:s,duration:i=500,delay:n=0,easing:r=Rm,onStart:o=pr,onChange:h=pr,onComplete:c=pr,abort:u=Nv,target:d}=t;A(this,"_state","pending"),A(this,"durationProgress",0),A(this,"valueProgress",0),this.tick=this.tick.bind(this),this.duration=i,this.delay=n,this.easing=r,this._onStart=o,this._onChange=h,this._onComplete=c,this._abort=u,this.target=d,this.startValue=e,this.byValue=s,this.value=this.startValue,this.endValue=Object.freeze(this.calculate(this.duration).value)}get state(){return this._state}isDone(){return this._state==="aborted"||this._state==="completed"}start(){const t=e=>{this._state==="pending"&&(this.startTime=e||+new Date,this._state="running",this._onStart(),this.tick(this.startTime))};this.register(),this.delay>0?setTimeout(()=>Ch(t),this.delay):Ch(t)}tick(t){const e=(t||+new Date)-this.startTime,s=Math.min(e,this.duration);this.durationProgress=s/this.duration;const{value:i,valueProgress:n}=this.calculate(s);this.value=Object.freeze(i),this.valueProgress=n,this._state!=="aborted"&&(this._abort(this.value,this.valueProgress,this.durationProgress)?(this._state="aborted",this.unregister()):e>=this.duration?(this.durationProgress=this.valueProgress=1,this._onChange(this.endValue,this.valueProgress,this.durationProgress),this._state="completed",this._onComplete(this.endValue,this.valueProgress,this.durationProgress),this.unregister()):(this._onChange(this.value,this.valueProgress,this.durationProgress),Ch(this.tick)))}register(){Wc.push(this)}unregister(){Wc.remove(this)}abort(){this._state="aborted",this.unregister()}}const jv=["startValue","endValue"];class Bv extends Rf{constructor(t){let{startValue:e=0,endValue:s=100}=t;super(T(T({},Ct(t,jv)),{},{startValue:e,byValue:s-e}))}calculate(t){const e=this.easing(t,this.startValue,this.byValue,this.duration);return{value:e,valueProgress:Math.abs((e-this.startValue)/this.byValue)}}}const Hv=["startValue","endValue"];class Gv extends Rf{constructor(t){let{startValue:e=[0],endValue:s=[100]}=t;super(T(T({},Ct(t,Hv)),{},{startValue:e,byValue:s.map((i,n)=>i-e[n])}))}calculate(t){const e=this.startValue.map((s,i)=>this.easing(t,s,this.byValue[i],this.duration,i));return{value:e,valueProgress:Math.abs((e[0]-this.startValue[0])/this.byValue[0])}}}const zv=["startValue","endValue","easing","onChange","onComplete","abort"],Vv=(a,t,e,s)=>t+e*(1-Math.cos(a/s*An)),Lf=a=>a&&((t,e,s)=>a(new gt(t).toRgba(),e,s));class Xv extends Rf{constructor(t){let{startValue:e,endValue:s,easing:i=Vv,onChange:n,onComplete:r,abort:o}=t,h=Ct(t,zv);const c=new gt(e).getSource(),u=new gt(s).getSource();super(T(T({},h),{},{startValue:c,byValue:u.map((d,f)=>d-c[f]),easing:i,onChange:Lf(n),onComplete:Lf(r),abort:Lf(o)}))}calculate(t){const[e,s,i,n]=this.startValue.map((o,h)=>this.easing(t,o,this.byValue[h],this.duration,h)),r=[...[e,s,i].map(Math.round),wr(0,n,1)];return{value:r,valueProgress:r.map((o,h)=>this.byValue[h]!==0?Math.abs((o-this.startValue[h])/this.byValue[h]):0).find(o=>o!==0)||0}}}function Ff(a){const t=(e=>Array.isArray(e.startValue)||Array.isArray(e.endValue))(a)?new Gv(a):new Bv(a);return t.start(),t}function Fm(a){const t=new Xv(a);return t.start(),t}class Mt{constructor(t){this.status=t,this.points=[]}includes(t){return this.points.some(e=>e.eq(t))}append(){for(var t=arguments.length,e=new Array(t),s=0;s<t;s++)e[s]=arguments[s];return this.points=this.points.concat(e.filter(i=>!this.includes(i))),this}static isPointContained(t,e,s){let i=arguments.length>3&&arguments[3]!==void 0&&arguments[3];if(e.eq(s))return t.eq(e);if(e.x===s.x)return t.x===e.x&&(i||t.y>=Math.min(e.y,s.y)&&t.y<=Math.max(e.y,s.y));if(e.y===s.y)return t.y===e.y&&(i||t.x>=Math.min(e.x,s.x)&&t.x<=Math.max(e.x,s.x));{const n=tu(e,s),r=tu(e,t).divide(n);return i?Math.abs(r.x)===Math.abs(r.y):r.x===r.y&&r.x>=0&&r.x<=1}}static isPointInPolygon(t,e){const s=new P(t).setX(Math.min(t.x-1,...e.map(n=>n.x)));let i=0;for(let n=0;n<e.length;n++){const r=this.intersectSegmentSegment(e[n],e[(n+1)%e.length],t,s);if(r.includes(t))return!0;i+=+(r.status==="Intersection")}return i%2==1}static intersectLineLine(t,e,s,i){let n=!(arguments.length>4&&arguments[4]!==void 0)||arguments[4],r=!(arguments.length>5&&arguments[5]!==void 0)||arguments[5];const o=e.x-t.x,h=e.y-t.y,c=i.x-s.x,u=i.y-s.y,d=t.x-s.x,f=t.y-s.y,g=c*f-u*d,p=o*f-h*d,b=u*o-c*h;if(b!==0){const _=g/b,v=p/b;return(n||0<=_&&_<=1)&&(r||0<=v&&v<=1)?new Mt("Intersection").append(new P(t.x+_*o,t.y+_*h)):new Mt}if(g===0||p===0){const _=n||r||Mt.isPointContained(t,s,i)||Mt.isPointContained(e,s,i)||Mt.isPointContained(s,t,e)||Mt.isPointContained(i,t,e);return new Mt(_?"Coincident":void 0)}return new Mt("Parallel")}static intersectSegmentLine(t,e,s,i){return Mt.intersectLineLine(t,e,s,i,!1,!0)}static intersectSegmentSegment(t,e,s,i){return Mt.intersectLineLine(t,e,s,i,!1,!1)}static intersectLinePolygon(t,e,s){let i=!(arguments.length>3&&arguments[3]!==void 0)||arguments[3];const n=new Mt,r=s.length;for(let o,h,c,u=0;u<r;u++){if(o=s[u],h=s[(u+1)%r],c=Mt.intersectLineLine(t,e,o,h,i,!1),c.status==="Coincident")return c;n.append(...c.points)}return n.points.length>0&&(n.status="Intersection"),n}static intersectSegmentPolygon(t,e,s){return Mt.intersectLinePolygon(t,e,s,!1)}static intersectPolygonPolygon(t,e){const s=new Mt,i=t.length,n=[];for(let r=0;r<i;r++){const o=t[r],h=t[(r+1)%i],c=Mt.intersectSegmentPolygon(o,h,e);c.status==="Coincident"?(n.push(c),s.append(o,h)):s.append(...c.points)}return n.length>0&&n.length===t.length?new Mt("Coincident"):(s.points.length>0&&(s.status="Intersection"),s)}static intersectPolygonRectangle(t,e,s){const i=e.min(s),n=e.max(s),r=new P(n.x,i.y),o=new P(i.x,n.y);return Mt.intersectPolygonPolygon(t,[i,r,n,o])}}class Wv extends Kp{getX(){return this.getXY().x}setX(t){this.setXY(this.getXY().setX(t))}getY(){return this.getXY().y}setY(t){this.setXY(this.getXY().setY(t))}getRelativeX(){return this.left}setRelativeX(t){this.left=t}getRelativeY(){return this.top}setRelativeY(t){this.top=t}getXY(){const t=this.getRelativeXY();return this.group?ge(t,this.group.calcTransformMatrix()):t}setXY(t,e,s){this.group&&(t=ge(t,Xe(this.group.calcTransformMatrix()))),this.setRelativeXY(t,e,s)}getRelativeXY(){return new P(this.left,this.top)}setRelativeXY(t){let e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:this.originX,s=arguments.length>2&&arguments[2]!==void 0?arguments[2]:this.originY;this.setPositionByOrigin(t,e,s)}isStrokeAccountedForInDimensions(){return!1}getCoords(){const{tl:t,tr:e,br:s,bl:i}=this.aCoords||(this.aCoords=this.calcACoords()),n=[t,e,s,i];if(this.group){const r=this.group.calcTransformMatrix();return n.map(o=>ge(o,r))}return n}intersectsWithRect(t,e){return Mt.intersectPolygonRectangle(this.getCoords(),t,e).status==="Intersection"}intersectsWithObject(t){const e=Mt.intersectPolygonPolygon(this.getCoords(),t.getCoords());return e.status==="Intersection"||e.status==="Coincident"||t.isContainedWithinObject(this)||this.isContainedWithinObject(t)}isContainedWithinObject(t){return this.getCoords().every(e=>t.containsPoint(e))}isContainedWithinRect(t,e){const{left:s,top:i,width:n,height:r}=this.getBoundingRect();return s>=t.x&&s+n<=e.x&&i>=t.y&&i+r<=e.y}isOverlapping(t){return this.intersectsWithObject(t)||this.isContainedWithinObject(t)||t.isContainedWithinObject(this)}containsPoint(t){return Mt.isPointInPolygon(t,this.getCoords())}isOnScreen(){if(!this.canvas)return!1;const{tl:t,br:e}=this.canvas.vptCoords;return!!this.getCoords().some(s=>s.x<=e.x&&s.x>=t.x&&s.y<=e.y&&s.y>=t.y)||!!this.intersectsWithRect(t,e)||this.containsPoint(t.midPointFrom(e))}isPartiallyOnScreen(){if(!this.canvas)return!1;const{tl:t,br:e}=this.canvas.vptCoords;return this.intersectsWithRect(t,e)?!0:this.getCoords().every(s=>(s.x>=e.x||s.x<=t.x)&&(s.y>=e.y||s.y<=t.y))&&this.containsPoint(t.midPointFrom(e))}getBoundingRect(){return ri(this.getCoords())}getScaledWidth(){return this._getTransformedDimensions().x}getScaledHeight(){return this._getTransformedDimensions().y}scale(t){this._set(Me,t),this._set(Je,t),this.setCoords()}scaleToWidth(t){const e=this.getBoundingRect().width/this.getScaledWidth();return this.scale(t/this.width/e)}scaleToHeight(t){const e=this.getBoundingRect().height/this.getScaledHeight();return this.scale(t/this.height/e)}getCanvasRetinaScaling(){var t;return((t=this.canvas)===null||t===void 0?void 0:t.getRetinaScaling())||1}getTotalAngle(){return this.group?kn(tm(this.calcTransformMatrix())):this.angle}getViewportTransform(){var t;return((t=this.canvas)===null||t===void 0?void 0:t.viewportTransform)||Ee.concat()}calcACoords(){const t=$o({angle:this.angle}),{x:e,y:s}=this.getRelativeCenterPoint(),i=Yo(e,s),n=Nt(i,t),r=this._getTransformedDimensions(),o=r.x/2,h=r.y/2;return{tl:ge({x:-o,y:-h},n),tr:ge({x:o,y:-h},n),bl:ge({x:-o,y:h},n),br:ge({x:o,y:h},n)}}setCoords(){this.aCoords=this.calcACoords()}transformMatrixKey(){let t=arguments.length>0&&arguments[0]!==void 0&&arguments[0],e=[];return!t&&this.group&&(e=this.group.transformMatrixKey(t)),e.push(this.top,this.left,this.width,this.height,this.scaleX,this.scaleY,this.angle,this.strokeWidth,this.skewX,this.skewY,+this.flipX,+this.flipY,Vt(this.originX),Vt(this.originY)),e}calcTransformMatrix(){let t=arguments.length>0&&arguments[0]!==void 0&&arguments[0],e=this.calcOwnMatrix();if(t||!this.group)return e;const s=this.transformMatrixKey(t),i=this.matrixCache;return i&&i.key.every((n,r)=>n===s[r])?i.value:(this.group&&(e=Nt(this.group.calcTransformMatrix(!1),e)),this.matrixCache={key:s,value:e},e)}calcOwnMatrix(){const t=this.transformMatrixKey(!0),e=this.ownMatrixCache;if(e&&e.key===t)return e.value;const s=this.getRelativeCenterPoint(),i={angle:this.angle,translateX:s.x,translateY:s.y,scaleX:this.scaleX,scaleY:this.scaleY,skewX:this.skewX,skewY:this.skewY,flipX:this.flipX,flipY:this.flipY},n=sm(i);return this.ownMatrixCache={key:t,value:n},n}_getNonTransformedDimensions(){return new P(this.width,this.height).scalarAdd(this.strokeWidth)}_calculateCurrentDimensions(t){return this._getTransformedDimensions(t).transform(this.getViewportTransform(),!0).scalarAdd(2*this.padding)}_getTransformedDimensions(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};const e=T({scaleX:this.scaleX,scaleY:this.scaleY,skewX:this.skewX,skewY:this.skewY,width:this.width,height:this.height,strokeWidth:this.strokeWidth},t),s=e.strokeWidth;let i=s,n=0;this.strokeUniform&&(i=0,n=s);const r=e.width+i,o=e.height+i;let h;return h=e.skewX===0&&e.skewY===0?new P(r*e.scaleX,o*e.scaleY):Qc(r,o,Ah(e)),h.scalarAdd(n)}translateToGivenOrigin(t,e,s,i,n){let r=t.x,o=t.y;const h=Vt(i)-Vt(e),c=Vt(n)-Vt(s);if(h||c){const u=this._getTransformedDimensions();r+=h*u.x,o+=c*u.y}return new P(r,o)}translateToCenterPoint(t,e,s){if(e===J&&s===J)return t;const i=this.translateToGivenOrigin(t,e,s,J,J);return this.angle?i.rotate(Rt(this.angle),t):i}translateToOriginPoint(t,e,s){const i=this.translateToGivenOrigin(t,J,J,e,s);return this.angle?i.rotate(Rt(this.angle),t):i}getCenterPoint(){const t=this.getRelativeCenterPoint();return this.group?ge(t,this.group.calcTransformMatrix()):t}getRelativeCenterPoint(){return this.translateToCenterPoint(new P(this.left,this.top),this.originX,this.originY)}getPointByOrigin(t,e){return this.translateToOriginPoint(this.getRelativeCenterPoint(),t,e)}setPositionByOrigin(t,e,s){const i=this.translateToCenterPoint(t,e,s),n=this.translateToOriginPoint(i,this.originX,this.originY);this.set({left:n.x,top:n.y})}_getLeftTopCoords(){return this.translateToOriginPoint(this.getRelativeCenterPoint(),dt,Ve)}}const Uv=["type"],Yv=["extraParam"];let Ii=class Ed extends Wv{static getDefaults(){return Ed.ownDefaults}get type(){const t=this.constructor.type;return t==="FabricObject"?"object":t.toLowerCase()}set type(t){Oi("warn","Setting type has no effect",t)}constructor(t){super(),A(this,"_cacheContext",null),Object.assign(this,Ed.ownDefaults),this.setOptions(t)}_createCacheCanvas(){this._cacheCanvas=ms(),this._cacheContext=this._cacheCanvas.getContext("2d"),this._updateCacheCanvas(),this.dirty=!0}_limitCacheSize(t){const e=t.width,s=t.height,i=ht.maxCacheSideLimit,n=ht.minCacheSideLimit;if(e<=i&&s<=i&&e*s<=ht.perfLimitSizeTotal)return e<n&&(t.width=n),s<n&&(t.height=n),t;const r=e/s,[o,h]=xh.limitDimsByArea(r),c=wr(n,o,i),u=wr(n,h,i);return e>c&&(t.zoomX/=e/c,t.width=c,t.capped=!0),s>u&&(t.zoomY/=s/u,t.height=u,t.capped=!0),t}_getCacheCanvasDimensions(){const t=this.getTotalObjectScaling(),e=this._getTransformedDimensions({skewX:0,skewY:0}),s=e.x*t.x/this.scaleX,i=e.y*t.y/this.scaleY;return{width:Math.ceil(s+2),height:Math.ceil(i+2),zoomX:t.x,zoomY:t.y,x:s,y:i}}_updateCacheCanvas(){const t=this._cacheCanvas,e=this._cacheContext,{width:s,height:i,zoomX:n,zoomY:r,x:o,y:h}=this._limitCacheSize(this._getCacheCanvasDimensions()),c=s!==t.width||i!==t.height,u=this.zoomX!==n||this.zoomY!==r;if(!t||!e)return!1;if(c||u){s!==t.width||i!==t.height?(t.width=s,t.height=i):(e.setTransform(1,0,0,1,0,0),e.clearRect(0,0,t.width,t.height));const d=o/2,f=h/2;return this.cacheTranslationX=Math.round(t.width/2-d)+d,this.cacheTranslationY=Math.round(t.height/2-f)+f,e.translate(this.cacheTranslationX,this.cacheTranslationY),e.scale(n,r),this.zoomX=n,this.zoomY=r,!0}return!1}setOptions(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};this._setOptions(t)}transform(t){const e=this.group&&!this.group._transformDone||this.group&&this.canvas&&t===this.canvas.contextTop,s=this.calcTransformMatrix(!e);t.transform(s[0],s[1],s[2],s[3],s[4],s[5])}getObjectScaling(){if(!this.group)return new P(Math.abs(this.scaleX),Math.abs(this.scaleY));const t=br(this.calcTransformMatrix());return new P(Math.abs(t.scaleX),Math.abs(t.scaleY))}getTotalObjectScaling(){const t=this.getObjectScaling();if(this.canvas){const e=this.canvas.getZoom(),s=this.getCanvasRetinaScaling();return t.scalarMultiply(e*s)}return t}getObjectOpacity(){let t=this.opacity;return this.group&&(t*=this.group.getObjectOpacity()),t}_constrainScale(t){return Math.abs(t)<this.minScaleLimit?t<0?-this.minScaleLimit:this.minScaleLimit:t===0?1e-4:t}_set(t,e){t!==Me&&t!==Je||(e=this._constrainScale(e)),t===Me&&e<0?(this.flipX=!this.flipX,e*=-1):t==="scaleY"&&e<0?(this.flipY=!this.flipY,e*=-1):t!=="shadow"||!e||e instanceof Li||(e=new Li(e));const s=this[t]!==e;return this[t]=e,s&&this.constructor.cacheProperties.includes(t)&&(this.dirty=!0),this.parent&&(this.dirty||s&&this.constructor.stateProperties.includes(t))&&this.parent._set("dirty",!0),this}isNotVisible(){return this.opacity===0||!this.width&&!this.height&&this.strokeWidth===0||!this.visible}render(t){this.isNotVisible()||this.canvas&&this.canvas.skipOffscreen&&!this.group&&!this.isOnScreen()||(t.save(),this._setupCompositeOperation(t),this.drawSelectionBackground(t),this.transform(t),this._setOpacity(t),this._setShadow(t),this.shouldCache()?(this.renderCache(),this.drawCacheOnCanvas(t)):(this._removeCacheCanvas(),this.drawObject(t,!1,{}),this.dirty=!1),t.restore())}drawSelectionBackground(t){}renderCache(t){if(t=t||{},this._cacheCanvas&&this._cacheContext||this._createCacheCanvas(),this.isCacheDirty()&&this._cacheContext){const{zoomX:e,zoomY:s,cacheTranslationX:i,cacheTranslationY:n}=this,{width:r,height:o}=this._cacheCanvas;this.drawObject(this._cacheContext,t.forClipping,{zoomX:e,zoomY:s,cacheTranslationX:i,cacheTranslationY:n,width:r,height:o,parentClipPaths:[]}),this.dirty=!1}}_removeCacheCanvas(){this._cacheCanvas=void 0,this._cacheContext=null}hasStroke(){return this.stroke&&this.stroke!=="transparent"&&this.strokeWidth!==0}hasFill(){return this.fill&&this.fill!=="transparent"}needsItsOwnCache(){return!!(this.paintFirst===Pe&&this.hasFill()&&this.hasStroke()&&this.shadow)||!!this.clipPath}shouldCache(){return this.ownCaching=this.objectCaching&&(!this.parent||!this.parent.isOnACache())||this.needsItsOwnCache(),this.ownCaching}willDrawShadow(){return!!this.shadow&&(this.shadow.offsetX!==0||this.shadow.offsetY!==0)}drawClipPathOnCache(t,e,s){t.save(),e.inverted?t.globalCompositeOperation="destination-out":t.globalCompositeOperation="destination-in",t.setTransform(1,0,0,1,0,0),t.drawImage(s,0,0),t.restore()}drawObject(t,e,s){const i=this.fill,n=this.stroke;e?(this.fill="black",this.stroke="",this._setClippingProperties(t)):this._renderBackground(t),this._render(t),this._drawClipPath(t,this.clipPath,s),this.fill=i,this.stroke=n}createClipPathLayer(t,e){const s=Rs(e),i=s.getContext("2d");if(i.translate(e.cacheTranslationX,e.cacheTranslationY),i.scale(e.zoomX,e.zoomY),t._cacheCanvas=s,e.parentClipPaths.forEach(n=>{n.transform(i)}),e.parentClipPaths.push(t),t.absolutePositioned){const n=Xe(this.calcTransformMatrix());i.transform(n[0],n[1],n[2],n[3],n[4],n[5])}return t.transform(i),t.drawObject(i,!0,e),s}_drawClipPath(t,e,s){if(!e)return;e._transformDone=!0;const i=this.createClipPathLayer(e,s);this.drawClipPathOnCache(t,e,i)}drawCacheOnCanvas(t){t.scale(1/this.zoomX,1/this.zoomY),t.drawImage(this._cacheCanvas,-this.cacheTranslationX,-this.cacheTranslationY)}isCacheDirty(){let t=arguments.length>0&&arguments[0]!==void 0&&arguments[0];if(this.isNotVisible())return!1;const e=this._cacheCanvas,s=this._cacheContext;return!(!e||!s||t||!this._updateCacheCanvas())||!!(this.dirty||this.clipPath&&this.clipPath.absolutePositioned)&&(e&&s&&!t&&(s.save(),s.setTransform(1,0,0,1,0,0),s.clearRect(0,0,e.width,e.height),s.restore()),!0)}_renderBackground(t){if(!this.backgroundColor)return;const e=this._getNonTransformedDimensions();t.fillStyle=this.backgroundColor,t.fillRect(-e.x/2,-e.y/2,e.x,e.y),this._removeShadow(t)}_setOpacity(t){this.group&&!this.group._transformDone?t.globalAlpha=this.getObjectOpacity():t.globalAlpha*=this.opacity}_setStrokeStyles(t,e){const s=e.stroke;s&&(t.lineWidth=e.strokeWidth,t.lineCap=e.strokeLineCap,t.lineDashOffset=e.strokeDashOffset,t.lineJoin=e.strokeLineJoin,t.miterLimit=e.strokeMiterLimit,bs(s)?s.gradientUnits==="percentage"||s.gradientTransform||s.patternTransform?this._applyPatternForTransformedGradient(t,s):(t.strokeStyle=s.toLive(t),this._applyPatternGradientTransform(t,s)):t.strokeStyle=e.stroke)}_setFillStyles(t,e){let{fill:s}=e;s&&(bs(s)?(t.fillStyle=s.toLive(t),this._applyPatternGradientTransform(t,s)):t.fillStyle=s)}_setClippingProperties(t){t.globalAlpha=1,t.strokeStyle="transparent",t.fillStyle="#000000"}_setLineDash(t,e){e&&e.length!==0&&t.setLineDash(e)}_setShadow(t){if(!this.shadow)return;const e=this.shadow,s=this.canvas,i=this.getCanvasRetinaScaling(),[n,,,r]=(s==null?void 0:s.viewportTransform)||Ee,o=n*i,h=r*i,c=e.nonScaling?new P(1,1):this.getObjectScaling();t.shadowColor=e.color,t.shadowBlur=e.blur*ht.browserShadowBlurConstant*(o+h)*(c.x+c.y)/4,t.shadowOffsetX=e.offsetX*o*c.x,t.shadowOffsetY=e.offsetY*h*c.y}_removeShadow(t){this.shadow&&(t.shadowColor="",t.shadowBlur=t.shadowOffsetX=t.shadowOffsetY=0)}_applyPatternGradientTransform(t,e){if(!bs(e))return{offsetX:0,offsetY:0};const s=e.gradientTransform||e.patternTransform,i=-this.width/2+e.offsetX||0,n=-this.height/2+e.offsetY||0;return e.gradientUnits==="percentage"?t.transform(this.width,0,0,this.height,i,n):t.transform(1,0,0,1,i,n),s&&t.transform(s[0],s[1],s[2],s[3],s[4],s[5]),{offsetX:i,offsetY:n}}_renderPaintInOrder(t){this.paintFirst===Pe?(this._renderStroke(t),this._renderFill(t)):(this._renderFill(t),this._renderStroke(t))}_render(t){}_renderFill(t){this.fill&&(t.save(),this._setFillStyles(t,this),this.fillRule==="evenodd"?t.fill("evenodd"):t.fill(),t.restore())}_renderStroke(t){if(this.stroke&&this.strokeWidth!==0){if(this.shadow&&!this.shadow.affectStroke&&this._removeShadow(t),t.save(),this.strokeUniform){const e=this.getObjectScaling();t.scale(1/e.x,1/e.y)}this._setLineDash(t,this.strokeDashArray),this._setStrokeStyles(t,this),t.stroke(),t.restore()}}_applyPatternForTransformedGradient(t,e){var s;const i=this._limitCacheSize(this._getCacheCanvasDimensions()),n=this.getCanvasRetinaScaling(),r=i.x/this.scaleX/n,o=i.y/this.scaleY/n,h=Rs({width:Math.ceil(r),height:Math.ceil(o)}),c=h.getContext("2d");c&&(c.beginPath(),c.moveTo(0,0),c.lineTo(r,0),c.lineTo(r,o),c.lineTo(0,o),c.closePath(),c.translate(r/2,o/2),c.scale(i.zoomX/this.scaleX/n,i.zoomY/this.scaleY/n),this._applyPatternGradientTransform(c,e),c.fillStyle=e.toLive(t),c.fill(),t.translate(-this.width/2-this.strokeWidth/2,-this.height/2-this.strokeWidth/2),t.scale(n*this.scaleX/i.zoomX,n*this.scaleY/i.zoomY),t.strokeStyle=(s=c.createPattern(h,"no-repeat"))!==null&&s!==void 0?s:"")}_findCenterFromElement(){return new P(this.left+this.width/2,this.top+this.height/2)}clone(t){const e=this.toObject(t);return this.constructor.fromObject(e)}cloneAsImage(t){const e=this.toCanvasElement(t);return new(H.getClass("image"))(e)}toCanvasElement(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};const e=xf(this),s=this.group,i=this.shadow,n=Math.abs,r=t.enableRetinaScaling?Wp():1,o=(t.multiplier||1)*r,h=t.canvasProvider||(x=>new Ph(x,{enableRetinaScaling:!1,renderOnAddRemove:!1,skipOffscreen:!1}));delete this.group,t.withoutTransform&&mm(this),t.withoutShadow&&(this.shadow=null),t.viewportTransform&&Sf(this,this.getViewportTransform()),this.setCoords();const c=ms(),u=this.getBoundingRect(),d=this.shadow,f=new P;if(d){const x=d.blur,C=d.nonScaling?new P(1,1):this.getObjectScaling();f.x=2*Math.round(n(d.offsetX)+x)*n(C.x),f.y=2*Math.round(n(d.offsetY)+x)*n(C.y)}const g=u.width+f.x,p=u.height+f.y;c.width=Math.ceil(g),c.height=Math.ceil(p);const b=h(c);t.format==="jpeg"&&(b.backgroundColor="#fff"),this.setPositionByOrigin(new P(b.width/2,b.height/2),J,J);const _=this.canvas;b._objects=[this],this.set("canvas",b),this.setCoords();const v=b.toCanvasElement(o||1,t);return this.set("canvas",_),this.shadow=i,s&&(this.group=s),this.set(e),this.setCoords(),b._objects=[],b.destroy(),v}toDataURL(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};return ff(this.toCanvasElement(t),t.format||"png",t.quality||1)}toBlob(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};return gf(this.toCanvasElement(t),t.format||"png",t.quality||1)}isType(){for(var t=arguments.length,e=new Array(t),s=0;s<t;s++)e[s]=arguments[s];return e.includes(this.constructor.type)||e.includes(this.type)}complexity(){return 1}toJSON(){return this.toObject()}rotate(t){const{centeredRotation:e,originX:s,originY:i}=this;if(e){const{x:n,y:r}=this.getRelativeCenterPoint();this.originX=J,this.originY=J,this.left=n,this.top=r}if(this.set("angle",t),e){const{x:n,y:r}=this.translateToOriginPoint(this.getRelativeCenterPoint(),s,i);this.left=n,this.top=r,this.originX=s,this.originY=i}}setOnGroup(){}_setupCompositeOperation(t){this.globalCompositeOperation&&(t.globalCompositeOperation=this.globalCompositeOperation)}dispose(){Wc.cancelByTarget(this),this.off(),this._set("canvas",void 0),this._cacheCanvas&&ni().dispose(this._cacheCanvas),this._cacheCanvas=void 0,this._cacheContext=null}animate(t,e){return Object.entries(t).reduce((s,i)=>{let[n,r]=i;return s[n]=this._animate(n,r,e),s},{})}_animate(t,e){let s=arguments.length>2&&arguments[2]!==void 0?arguments[2]:{};const i=t.split("."),n=this.constructor.colorProperties.includes(i[i.length-1]),{abort:r,startValue:o,onChange:h,onComplete:c}=s,u=T(T({},s),{},{target:this,startValue:o??i.reduce((d,f)=>d[f],this),endValue:e,abort:r==null?void 0:r.bind(this),onChange:(d,f,g)=>{i.reduce((p,b,_)=>(_===i.length-1&&(p[b]=d),p[b]),this),h&&h(d,f,g)},onComplete:(d,f,g)=>{this.setCoords(),c&&c(d,f,g)}});return n?Fm(u):Ff(u)}isDescendantOf(t){const{parent:e,group:s}=this;return e===t||s===t||!!e&&e.isDescendantOf(t)||!!s&&s!==e&&s.isDescendantOf(t)}getAncestors(){const t=[];let e=this;do e=e.parent,e&&t.push(e);while(e);return t}findCommonAncestors(t){if(this===t)return{fork:[],otherFork:[],common:[this,...this.getAncestors()]};const e=this.getAncestors(),s=t.getAncestors();if(e.length===0&&s.length>0&&this===s[s.length-1])return{fork:[],otherFork:[t,...s.slice(0,s.length-1)],common:[this]};for(let i,n=0;n<e.length;n++){if(i=e[n],i===t)return{fork:[this,...e.slice(0,n)],otherFork:[],common:e.slice(n)};for(let r=0;r<s.length;r++){if(this===s[r])return{fork:[],otherFork:[t,...s.slice(0,r)],common:[this,...e]};if(i===s[r])return{fork:[this,...e.slice(0,n)],otherFork:[t,...s.slice(0,r)],common:e.slice(n)}}}return{fork:[this,...e],otherFork:[t,...s],common:[]}}hasCommonAncestors(t){const e=this.findCommonAncestors(t);return e&&!!e.common.length}isInFrontOf(t){if(this===t)return;const e=this.findCommonAncestors(t);if(e.fork.includes(t))return!0;if(e.otherFork.includes(this))return!1;const s=e.common[0]||this.canvas;if(!s)return;const i=e.fork.pop(),n=e.otherFork.pop(),r=s._objects.indexOf(i),o=s._objects.indexOf(n);return r>-1&&r>o}toObject(){const t=(arguments.length>0&&arguments[0]!==void 0?arguments[0]:[]).concat(Ed.customProperties,this.constructor.customProperties||[]);let e;const s=ht.NUM_FRACTION_DIGITS,{clipPath:i,fill:n,stroke:r,shadow:o,strokeDashArray:h,left:c,top:u,originX:d,originY:f,width:g,height:p,strokeWidth:b,strokeLineCap:_,strokeDashOffset:v,strokeLineJoin:x,strokeUniform:C,strokeMiterLimit:S,scaleX:E,scaleY:k,angle:M,flipX:D,flipY:R,opacity:B,visible:O,backgroundColor:F,fillRule:L,paintFirst:N,globalCompositeOperation:Y,skewX:I,skewY:X}=this;i&&!i.excludeFromExport&&(e=i.toObject(t.concat("inverted","absolutePositioned")));const rt=te=>At(te,s),Gt=T(T({},yr(this,t)),{},{type:this.constructor.type,version:rf,originX:d,originY:f,left:rt(c),top:rt(u),width:rt(g),height:rt(p),fill:am(n)?n.toObject():n,stroke:am(r)?r.toObject():r,strokeWidth:rt(b),strokeDashArray:h&&h.concat(),strokeLineCap:_,strokeDashOffset:v,strokeLineJoin:x,strokeUniform:C,strokeMiterLimit:rt(S),scaleX:rt(E),scaleY:rt(k),angle:rt(M),flipX:D,flipY:R,opacity:rt(B),shadow:o&&o.toObject(),visible:O,backgroundColor:F,fillRule:L,paintFirst:N,globalCompositeOperation:Y,skewX:rt(I),skewY:rt(X)},e?{clipPath:e}:null);return this.includeDefaultValues?Gt:this._removeDefaultValues(Gt)}toDatalessObject(t){return this.toObject(t)}_removeDefaultValues(t){const e=this.constructor.getDefaults(),s=Object.keys(e).length>0?e:Object.getPrototypeOf(this);return bf(t,(i,n)=>{if(n===dt||n===Ve||n==="type")return!0;const r=s[n];return i!==r&&!(Array.isArray(i)&&Array.isArray(r)&&i.length===0&&r.length===0)})}toString(){return"#<".concat(this.constructor.type,">")}static _fromObject(t){let e=Ct(t,Uv),s=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},{extraParam:i}=s,n=Ct(s,Yv);return Eh(e,n).then(r=>i?(delete r[i],new this(e[i],r)):new this(r))}static fromObject(t,e){return this._fromObject(t,e)}};A(Ii,"stateProperties",Lv),A(Ii,"cacheProperties",Fi),A(Ii,"ownDefaults",Fv),A(Ii,"type","FabricObject"),A(Ii,"colorProperties",[zt,Pe,"backgroundColor"]),A(Ii,"customProperties",[]),H.setClass(Ii),H.setClass(Ii,"object");const Jo=(a,t,e)=>(s,i,n,r)=>{const o=t(s,i,n,r);return o&&ym(a,T(T({},wm(s,i,n,r)),e)),o};function Zo(a){return(t,e,s,i)=>{const{target:n,originX:r,originY:o}=e,h=n.getRelativeCenterPoint(),c=n.translateToOriginPoint(h,r,o),u=a(t,e,s,i);return n.setPositionByOrigin(c,e.originX,e.originY),u}}const Im=Jo(Sh,Zo((a,t,e,s)=>{const i=Cf(t,t.originX,t.originY,e,s);if(Vt(t.originX)===Vt(J)||Vt(t.originX)===Vt(It)&&i.x<0||Vt(t.originX)===Vt(dt)&&i.x>0){const{target:n}=t,r=n.strokeWidth/(n.strokeUniform?n.scaleX:1),o=vm(t)?2:1,h=n.width,c=Math.abs(i.x*o/n.scaleX)-r;return n.set("width",Math.max(c,1)),h!==n.width}return!1}));function $v(a,t,e,s,i){s=s||{};const n=this.sizeX||s.cornerSize||i.cornerSize,r=this.sizeY||s.cornerSize||i.cornerSize,o=s.transparentCorners!==void 0?s.transparentCorners:i.transparentCorners,h=o?Pe:zt,c=!o&&(s.cornerStrokeColor||i.cornerStrokeColor);let u,d=t,f=e;a.save(),a.fillStyle=s.cornerColor||i.cornerColor||"",a.strokeStyle=s.cornerStrokeColor||i.cornerStrokeColor||"",n>r?(u=n,a.scale(1,r/n),f=e*n/r):r>n?(u=r,a.scale(n/r,1),d=t*r/n):u=n,a.beginPath(),a.arc(d,f,u/2,0,Ri,!1),a[h](),c&&a.stroke(),a.restore()}function qv(a,t,e,s,i){s=s||{};const n=this.sizeX||s.cornerSize||i.cornerSize,r=this.sizeY||s.cornerSize||i.cornerSize,o=s.transparentCorners!==void 0?s.transparentCorners:i.transparentCorners,h=o?Pe:zt,c=!o&&(s.cornerStrokeColor||i.cornerStrokeColor),u=n/2,d=r/2;a.save(),a.fillStyle=s.cornerColor||i.cornerColor||"",a.strokeStyle=s.cornerStrokeColor||i.cornerStrokeColor||"",a.translate(t,e);const f=i.getTotalAngle();a.rotate(Rt(f)),a["".concat(h,"Rect")](-u,-d,n,r),c&&a.strokeRect(-u,-d,n,r),a.restore()}class Ns{constructor(t){A(this,"visible",!0),A(this,"actionName",Vc),A(this,"angle",0),A(this,"x",0),A(this,"y",0),A(this,"offsetX",0),A(this,"offsetY",0),A(this,"sizeX",0),A(this,"sizeY",0),A(this,"touchSizeX",0),A(this,"touchSizeY",0),A(this,"cursorStyle","crosshair"),A(this,"withConnection",!1),Object.assign(this,t)}shouldActivate(t,e,s,i){var n;let{tl:r,tr:o,br:h,bl:c}=i;return((n=e.canvas)===null||n===void 0?void 0:n.getActiveObject())===e&&e.isControlVisible(t)&&Mt.isPointInPolygon(s,[r,o,h,c])}getActionHandler(t,e,s){return this.actionHandler}getMouseDownHandler(t,e,s){return this.mouseDownHandler}getMouseUpHandler(t,e,s){return this.mouseUpHandler}cursorStyleHandler(t,e,s){return e.cursorStyle}getActionName(t,e,s){return e.actionName}getVisibility(t,e){var s,i;return(s=(i=t._controlsVisibility)===null||i===void 0?void 0:i[e])!==null&&s!==void 0?s:this.visible}setVisibility(t,e,s){this.visible=t}positionHandler(t,e,s,i){return new P(this.x*t.x+this.offsetX,this.y*t.y+this.offsetY).transform(e)}calcCornerCoords(t,e,s,i,n,r){const o=Yc([Yo(s,i),$o({angle:t}),$c((n?this.touchSizeX:this.sizeX)||e,(n?this.touchSizeY:this.sizeY)||e)]);return{tl:new P(-.5,-.5).transform(o),tr:new P(.5,-.5).transform(o),br:new P(.5,.5).transform(o),bl:new P(-.5,.5).transform(o)}}render(t,e,s,i,n){((i=i||{}).cornerStyle||n.cornerStyle)==="circle"?$v.call(this,t,e,s,i,n):qv.call(this,t,e,s,i,n)}}const Kv=(a,t,e)=>e.lockRotation?Jc:t.cursorStyle,Qv=Jo(Yp,Zo((a,t,e,s)=>{let{target:i,ex:n,ey:r,theta:o,originX:h,originY:c}=t;const u=i.translateToOriginPoint(i.getRelativeCenterPoint(),h,c);if(Fs(i,"lockRotation"))return!1;const d=Math.atan2(r-u.y,n-u.x),f=Math.atan2(s-u.y,e-u.x);let g=kn(f-d+o);if(i.snapAngle&&i.snapAngle>0){const b=i.snapAngle,_=i.snapThreshold||b,v=Math.ceil(g/b)*b,x=Math.floor(g/b)*b;Math.abs(g-x)<_?g=x:Math.abs(g-v)<_&&(g=v)}g<0&&(g=360+g),g%=360;const p=i.angle!==g;return i.angle=g,p}));function Nm(a,t){const e=t.canvas,s=a[e.uniScaleKey];return e.uniformScaling&&!s||!e.uniformScaling&&s}function jm(a,t,e){const s=Fs(a,"lockScalingX"),i=Fs(a,"lockScalingY");if(s&&i||!t&&(s||i)&&e||s&&t==="x"||i&&t==="y")return!0;const{width:n,height:r,strokeWidth:o}=a;return n===0&&o===0&&t!=="y"||r===0&&o===0&&t!=="x"}const Jv=["e","se","s","sw","w","nw","n","ne","e"],Oh=(a,t,e)=>{const s=Nm(a,e);if(jm(e,t.x!==0&&t.y===0?"x":t.x===0&&t.y!==0?"y":"",s))return Jc;const i=xm(e,t);return"".concat(Jv[i],"-resize")};function If(a,t,e,s){let i=arguments.length>4&&arguments[4]!==void 0?arguments[4]:{};const n=t.target,r=i.by,o=Nm(a,n);let h,c,u,d,f,g;if(jm(n,r,o))return!1;if(t.gestureScale)c=t.scaleX*t.gestureScale,u=t.scaleY*t.gestureScale;else{if(h=Cf(t,t.originX,t.originY,e,s),f=r!=="y"?Math.sign(h.x||t.signX||1):1,g=r!=="x"?Math.sign(h.y||t.signY||1):1,t.signX||(t.signX=f),t.signY||(t.signY=g),Fs(n,"lockScalingFlip")&&(t.signX!==f||t.signY!==g))return!1;if(d=n._getTransformedDimensions(),o&&!r){const _=Math.abs(h.x)+Math.abs(h.y),{original:v}=t,x=_/(Math.abs(d.x*v.scaleX/n.scaleX)+Math.abs(d.y*v.scaleY/n.scaleY));c=v.scaleX*x,u=v.scaleY*x}else c=Math.abs(h.x*n.scaleX/d.x),u=Math.abs(h.y*n.scaleY/d.y);vm(t)&&(c*=2,u*=2),t.signX!==f&&r!=="y"&&(t.originX=_m(t.originX),c*=-1,t.signX=f),t.signY!==g&&r!=="x"&&(t.originY=_m(t.originY),u*=-1,t.signY=g)}const p=n.scaleX,b=n.scaleY;return r?(r==="x"&&n.set(Me,c),r==="y"&&n.set(Je,u)):(!Fs(n,"lockScalingX")&&n.set(Me,c),!Fs(n,"lockScalingY")&&n.set(Je,u)),p!==n.scaleX||b!==n.scaleY}const nu=Jo(Gc,Zo((a,t,e,s)=>If(a,t,e,s))),Zv=Jo(Gc,Zo((a,t,e,s)=>If(a,t,e,s,{by:"x"}))),t_=Jo(Gc,Zo((a,t,e,s)=>If(a,t,e,s,{by:"y"}))),e_=["target","ex","ey","skewingSide"],Nf={x:{counterAxis:"y",scale:Me,skew:Xo,lockSkewing:"lockSkewingX",origin:"originX",flip:"flipX"},y:{counterAxis:"x",scale:Je,skew:Wo,lockSkewing:"lockSkewingY",origin:"originY",flip:"flipY"}},s_=["ns","nesw","ew","nwse"],i_=(a,t,e)=>{if(t.x!==0&&Fs(e,"lockSkewingY")||t.y!==0&&Fs(e,"lockSkewingX"))return Jc;const s=xm(e,t)%4;return"".concat(s_[s],"-resize")};function Bm(a,t,e,s,i){const{target:n}=e,{counterAxis:r,origin:o,lockSkewing:h,skew:c,flip:u}=Nf[a];if(Fs(n,h))return!1;const{origin:d,flip:f}=Nf[r],g=Vt(e[d])*(n[f]?-1:1),p=-Math.sign(g)*(n[u]?-1:1),b=.5*-((n[c]===0&&Cf(e,J,J,s,i)[a]>0||n[c]>0?1:-1)*p)+.5;return Jo($p,Zo((v,x,C,S)=>function(E,k,M){let{target:D,ex:R,ey:B,skewingSide:O}=k,F=Ct(k,e_);const{skew:L}=Nf[E],N=M.subtract(new P(R,B)).divide(new P(D.scaleX,D.scaleY))[E],Y=D[L],I=F[L],X=Math.tan(Rt(I)),rt=E==="y"?D._getTransformedDimensions({scaleX:1,scaleY:1,skewX:0}).x:D._getTransformedDimensions({scaleX:1,scaleY:1}).y,Gt=2*N*O/Math.max(rt,1)+X,te=kn(Math.atan(Gt));D.set(L,te);const fe=Y!==D[L];if(fe&&E==="y"){const{skewX:Yt,scaleX:St}=D,He=D._getTransformedDimensions({skewY:Y}),Mi=D._getTransformedDimensions(),Ft=Yt!==0?He.x/Mi.x:1;Ft!==1&&D.set(Me,Ft*St)}return fe}(a,x,new P(C,S))))(t,T(T({},e),{},{[o]:b,skewingSide:p}),s,i)}const n_=(a,t,e,s)=>Bm("x",a,t,e,s),r_=(a,t,e,s)=>Bm("y",a,t,e,s);function ru(a,t){return a[t.canvas.altActionKey]}const ou=(a,t,e)=>{const s=ru(a,e);return t.x===0?s?Xo:Je:t.y===0?s?Wo:Me:""},ta=(a,t,e)=>ru(a,e)?i_(0,t,e):Oh(a,t,e),Hm=(a,t,e,s)=>ru(a,t.target)?r_(a,t,e,s):Zv(a,t,e,s),Gm=(a,t,e,s)=>ru(a,t.target)?n_(a,t,e,s):t_(a,t,e,s),zm=()=>({ml:new Ns({x:-.5,y:0,cursorStyleHandler:ta,actionHandler:Hm,getActionName:ou}),mr:new Ns({x:.5,y:0,cursorStyleHandler:ta,actionHandler:Hm,getActionName:ou}),mb:new Ns({x:0,y:.5,cursorStyleHandler:ta,actionHandler:Gm,getActionName:ou}),mt:new Ns({x:0,y:-.5,cursorStyleHandler:ta,actionHandler:Gm,getActionName:ou}),tl:new Ns({x:-.5,y:-.5,cursorStyleHandler:Oh,actionHandler:nu}),tr:new Ns({x:.5,y:-.5,cursorStyleHandler:Oh,actionHandler:nu}),bl:new Ns({x:-.5,y:.5,cursorStyleHandler:Oh,actionHandler:nu}),br:new Ns({x:.5,y:.5,cursorStyleHandler:Oh,actionHandler:nu}),mtr:new Ns({x:0,y:-.5,actionHandler:Qv,cursorStyleHandler:Kv,offsetY:-40,withConnection:!0,actionName:cf})}),o_=()=>({mr:new Ns({x:.5,y:0,actionHandler:Im,cursorStyleHandler:ta,actionName:Sh}),ml:new Ns({x:-.5,y:0,actionHandler:Im,cursorStyleHandler:ta,actionName:Sh})}),a_=()=>T(T({},zm()),o_());class Rh extends Ii{static getDefaults(){return T(T({},super.getDefaults()),Rh.ownDefaults)}constructor(t){super(),Object.assign(this,this.constructor.createControls(),Rh.ownDefaults),this.setOptions(t)}static createControls(){return{controls:zm()}}_updateCacheCanvas(){const t=this.canvas;if(this.noScaleCache&&t&&t._currentTransform){const e=t._currentTransform,s=e.target,i=e.action;if(this===s&&i&&i.startsWith(Vc))return!1}return super._updateCacheCanvas()}getActiveControl(){const t=this.__corner;return t?{key:t,control:this.controls[t],coord:this.oCoords[t]}:void 0}findControl(t){let e=arguments.length>1&&arguments[1]!==void 0&&arguments[1];if(!this.hasControls||!this.canvas)return;this.__corner=void 0;const s=Object.entries(this.oCoords);for(let i=s.length-1;i>=0;i--){const[n,r]=s[i],o=this.controls[n];if(o.shouldActivate(n,this,t,e?r.touchCorner:r.corner))return this.__corner=n,{key:n,control:o,coord:this.oCoords[n]}}}calcOCoords(){const t=this.getViewportTransform(),e=this.getCenterPoint(),s=Yo(e.x,e.y),i=$o({angle:this.getTotalAngle()-(this.group&&this.flipX?180:0)}),n=Nt(s,i),r=Nt(t,n),o=Nt(r,[1/t[0],0,0,1/t[3],0,0]),h=this.group?br(this.calcTransformMatrix()):void 0;h&&(h.scaleX=Math.abs(h.scaleX),h.scaleY=Math.abs(h.scaleY));const c=this._calculateCurrentDimensions(h),u={};return this.forEachControl((d,f)=>{const g=d.positionHandler(c,o,this,d);u[f]=Object.assign(g,this._calcCornerCoords(d,g))}),u}_calcCornerCoords(t,e){const s=this.getTotalAngle();return{corner:t.calcCornerCoords(s,this.cornerSize,e.x,e.y,!1,this),touchCorner:t.calcCornerCoords(s,this.touchCornerSize,e.x,e.y,!0,this)}}setCoords(){super.setCoords(),this.canvas&&(this.oCoords=this.calcOCoords())}forEachControl(t){for(const e in this.controls)t(this.controls[e],e,this)}drawSelectionBackground(t){if(!this.selectionBackgroundColor||this.canvas&&this.canvas._activeObject!==this)return;t.save();const e=this.getRelativeCenterPoint(),s=this._calculateCurrentDimensions(),i=this.getViewportTransform();t.translate(e.x,e.y),t.scale(1/i[0],1/i[3]),t.rotate(Rt(this.angle)),t.fillStyle=this.selectionBackgroundColor,t.fillRect(-s.x/2,-s.y/2,s.x,s.y),t.restore()}strokeBorders(t,e){t.strokeRect(-e.x/2,-e.y/2,e.x,e.y)}_drawBorders(t,e){let s=arguments.length>2&&arguments[2]!==void 0?arguments[2]:{};const i=T({hasControls:this.hasControls,borderColor:this.borderColor,borderDashArray:this.borderDashArray},s);t.save(),t.strokeStyle=i.borderColor,this._setLineDash(t,i.borderDashArray),this.strokeBorders(t,e),i.hasControls&&this.drawControlsConnectingLines(t,e),t.restore()}_renderControls(t){let e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};const{hasBorders:s,hasControls:i}=this,n=T({hasBorders:s,hasControls:i},e),r=this.getViewportTransform(),o=n.hasBorders,h=n.hasControls,c=Nt(r,this.calcTransformMatrix()),u=br(c);t.save(),t.translate(u.translateX,u.translateY),t.lineWidth=this.borderScaleFactor,this.group===this.parent&&(t.globalAlpha=this.isMoving?this.borderOpacityWhenMoving:1),this.flipX&&(u.angle-=180),t.rotate(Rt(this.group?u.angle:this.angle)),o&&this.drawBorders(t,u,e),h&&this.drawControls(t,e),t.restore()}drawBorders(t,e,s){let i;if(s&&s.forActiveSelection||this.group){const n=Qc(this.width,this.height,Ah(e)),r=this.isStrokeAccountedForInDimensions()?df:(this.strokeUniform?new P().scalarAdd(this.canvas?this.canvas.getZoom():1):new P(e.scaleX,e.scaleY)).scalarMultiply(this.strokeWidth);i=n.add(r).scalarAdd(this.borderScaleFactor).scalarAdd(2*this.padding)}else i=this._calculateCurrentDimensions().scalarAdd(this.borderScaleFactor);this._drawBorders(t,i,s)}drawControlsConnectingLines(t,e){let s=!1;t.beginPath(),this.forEachControl((i,n)=>{i.withConnection&&i.getVisibility(this,n)&&(s=!0,t.moveTo(i.x*e.x,i.y*e.y),t.lineTo(i.x*e.x+i.offsetX,i.y*e.y+i.offsetY))}),s&&t.stroke()}drawControls(t){let e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};t.save();const s=this.getCanvasRetinaScaling(),{cornerStrokeColor:i,cornerDashArray:n,cornerColor:r}=this,o=T({cornerStrokeColor:i,cornerDashArray:n,cornerColor:r},e);t.setTransform(s,0,0,s,0,0),t.strokeStyle=t.fillStyle=o.cornerColor,this.transparentCorners||(t.strokeStyle=o.cornerStrokeColor),this._setLineDash(t,o.cornerDashArray),this.forEachControl((h,c)=>{if(h.getVisibility(this,c)){const u=this.oCoords[c];h.render(t,u.x,u.y,o,this)}}),t.restore()}isControlVisible(t){return this.controls[t]&&this.controls[t].getVisibility(this,t)}setControlVisible(t,e){this._controlsVisibility||(this._controlsVisibility={}),this._controlsVisibility[t]=e}setControlsVisibility(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};Object.entries(t).forEach(e=>{let[s,i]=e;return this.setControlVisible(s,i)})}clearContextTop(t){if(!this.canvas)return;const e=this.canvas.contextTop;if(!e)return;const s=this.canvas.viewportTransform;e.save(),e.transform(s[0],s[1],s[2],s[3],s[4],s[5]),this.transform(e);const i=this.width+4,n=this.height+4;return e.clearRect(-i/2,-n/2,i,n),t||e.restore(),e}onDeselect(t){return!1}onSelect(t){return!1}shouldStartDragging(t){return!1}onDragStart(t){return!1}canDrop(t){return!1}renderDragSourceEffect(t){}renderDropTargetEffect(t){}}function Vm(a,t){return t.forEach(e=>{Object.getOwnPropertyNames(e.prototype).forEach(s=>{s!=="constructor"&&Object.defineProperty(a.prototype,s,Object.getOwnPropertyDescriptor(e.prototype,s)||Object.create(null))})}),a}A(Rh,"ownDefaults",{noScaleCache:!0,lockMovementX:!1,lockMovementY:!1,lockRotation:!1,lockScalingX:!1,lockScalingY:!1,lockSkewingX:!1,lockSkewingY:!1,lockScalingFlip:!1,cornerSize:13,touchCornerSize:24,transparentCorners:!0,cornerColor:"rgb(178,204,255)",cornerStrokeColor:"",cornerStyle:"rect",cornerDashArray:null,hasControls:!0,borderColor:"rgb(178,204,255)",borderDashArray:null,borderOpacityWhenMoving:.4,borderScaleFactor:1,hasBorders:!0,selectionBackgroundColor:"",selectable:!0,evented:!0,perPixelTargetFind:!1,activeOn:"down",hoverCursor:null,moveCursor:null});class pe extends Rh{}Vm(pe,[Sm]),H.setClass(pe),H.setClass(pe,"object");const Xm=(a,t,e,s)=>{const i=2*(s=Math.round(s))+1,{data:n}=a.getImageData(t-s,e-s,i,i);for(let r=3;r<n.length;r+=4)if(n[r]>0)return!1;return!0};class Wm{constructor(t){this.options=t,this.strokeProjectionMagnitude=this.options.strokeWidth/2,this.scale=new P(this.options.scaleX,this.options.scaleY),this.strokeUniformScalar=this.options.strokeUniform?new P(1/this.options.scaleX,1/this.options.scaleY):new P(1,1)}createSideVector(t,e){const s=tu(t,e);return this.options.strokeUniform?s.multiply(this.scale):s}projectOrthogonally(t,e,s){return this.applySkew(t.add(this.calcOrthogonalProjection(t,e,s)))}isSkewed(){return this.options.skewX!==0||this.options.skewY!==0}applySkew(t){const e=new P(t);return e.y+=e.x*Math.tan(Rt(this.options.skewY)),e.x+=e.y*Math.tan(Rt(this.options.skewX)),e}scaleUnitVector(t,e){return t.multiply(this.strokeUniformScalar).scalarMultiply(e)}}const h_=new P;class ea extends Wm{static getOrthogonalRotationFactor(t,e){const s=e?su(t,e):km(t);return Math.abs(s)<An?-1:1}constructor(t,e,s,i){super(i),A(this,"AB",void 0),A(this,"AC",void 0),A(this,"alpha",void 0),A(this,"bisector",void 0),this.A=new P(t),this.B=new P(e),this.C=new P(s),this.AB=this.createSideVector(this.A,this.B),this.AC=this.createSideVector(this.A,this.C),this.alpha=su(this.AB,this.AC),this.bisector=iu(kf(this.AB.eq(h_)?this.AC:this.AB,this.alpha/2))}calcOrthogonalProjection(t,e){let s=arguments.length>2&&arguments[2]!==void 0?arguments[2]:this.strokeProjectionMagnitude;const i=this.createSideVector(t,e),n=Mf(i),r=ea.getOrthogonalRotationFactor(n,this.bisector);return this.scaleUnitVector(n,s*r)}projectBevel(){const t=[];return(this.alpha%Ri==0?[this.B]:[this.B,this.C]).forEach(e=>{t.push(this.projectOrthogonally(this.A,e)),t.push(this.projectOrthogonally(this.A,e,-this.strokeProjectionMagnitude))}),t}projectMiter(){const t=[],e=Math.abs(this.alpha),s=1/Math.sin(e/2),i=this.scaleUnitVector(this.bisector,-this.strokeProjectionMagnitude*s),n=this.options.strokeUniform?eu(this.scaleUnitVector(this.bisector,this.options.strokeMiterLimit)):this.options.strokeMiterLimit;return eu(i)/this.strokeProjectionMagnitude<=n&&t.push(this.applySkew(this.A.add(i))),t.push(...this.projectBevel()),t}projectRoundNoSkew(t,e){const s=[],i=new P(ea.getOrthogonalRotationFactor(this.bisector),ea.getOrthogonalRotationFactor(new P(this.bisector.y,this.bisector.x)));return[new P(1,0).scalarMultiply(this.strokeProjectionMagnitude).multiply(this.strokeUniformScalar).multiply(i),new P(0,1).scalarMultiply(this.strokeProjectionMagnitude).multiply(this.strokeUniformScalar).multiply(i)].forEach(n=>{Pf(n,t,e)&&s.push(this.A.add(n))}),s}projectRoundWithSkew(t,e){const s=[],{skewX:i,skewY:n,scaleX:r,scaleY:o,strokeUniform:h}=this.options,c=new P(Math.tan(Rt(i)),Math.tan(Rt(n))),u=this.strokeProjectionMagnitude,d=h?u/o/Math.sqrt(1/o**2+1/r**2*c.y**2):u/Math.sqrt(1+c.y**2),f=new P(Math.sqrt(Math.max(u**2-d**2,0)),d),g=h?u/Math.sqrt(1+c.x**2*(1/o)**2/(1/r+1/r*c.x*c.y)**2):u/Math.sqrt(1+c.x**2/(1+c.x*c.y)**2),p=new P(g,Math.sqrt(Math.max(u**2-g**2,0)));return[p,p.scalarMultiply(-1),f,f.scalarMultiply(-1)].map(b=>this.applySkew(h?b.multiply(this.strokeUniformScalar):b)).forEach(b=>{Pf(b,t,e)&&s.push(this.applySkew(this.A).add(b))}),s}projectRound(){const t=[];t.push(...this.projectBevel());const e=this.alpha%Ri==0,s=this.applySkew(this.A),i=t[e?0:2].subtract(s),n=t[e?1:0].subtract(s),r=e?this.applySkew(this.AB.scalarMultiply(-1)):this.applySkew(this.bisector.multiply(this.strokeUniformScalar).scalarMultiply(-1)),o=Qo(i,r)>0,h=o?i:n,c=o?n:i;return this.isSkewed()?t.push(...this.projectRoundWithSkew(h,c)):t.push(...this.projectRoundNoSkew(h,c)),t}projectPoints(){switch(this.options.strokeLineJoin){case"miter":return this.projectMiter();case"round":return this.projectRound();default:return this.projectBevel()}}project(){return this.projectPoints().map(t=>({originPoint:this.A,projectedPoint:t,angle:this.alpha,bisector:this.bisector}))}}class Um extends Wm{constructor(t,e,s){super(s),this.A=new P(t),this.T=new P(e)}calcOrthogonalProjection(t,e){let s=arguments.length>2&&arguments[2]!==void 0?arguments[2]:this.strokeProjectionMagnitude;const i=this.createSideVector(t,e);return this.scaleUnitVector(Mf(i),s)}projectButt(){return[this.projectOrthogonally(this.A,this.T,this.strokeProjectionMagnitude),this.projectOrthogonally(this.A,this.T,-this.strokeProjectionMagnitude)]}projectRound(){const t=[];if(!this.isSkewed()&&this.A.eq(this.T)){const e=new P(1,1).scalarMultiply(this.strokeProjectionMagnitude).multiply(this.strokeUniformScalar);t.push(this.applySkew(this.A.add(e)),this.applySkew(this.A.subtract(e)))}else t.push(...new ea(this.A,this.T,this.T,this.options).projectRound());return t}projectSquare(){const t=[];if(this.A.eq(this.T)){const e=new P(1,1).scalarMultiply(this.strokeProjectionMagnitude).multiply(this.strokeUniformScalar);t.push(this.A.add(e),this.A.subtract(e))}else{const e=this.calcOrthogonalProjection(this.A,this.T,this.strokeProjectionMagnitude),s=this.scaleUnitVector(iu(this.createSideVector(this.A,this.T)),-this.strokeProjectionMagnitude),i=this.A.add(s);t.push(i.add(e),i.subtract(e))}return t.map(e=>this.applySkew(e))}projectPoints(){switch(this.options.strokeLineCap){case"round":return this.projectRound();case"square":return this.projectSquare();default:return this.projectButt()}}project(){return this.projectPoints().map(t=>({originPoint:this.A,projectedPoint:t}))}}const Ym=function(a,t){let e=arguments.length>2&&arguments[2]!==void 0&&arguments[2];const s=[];if(a.length===0)return s;const i=a.reduce((n,r)=>(n[n.length-1].eq(r)||n.push(new P(r)),n),[new P(a[0])]);if(i.length===1)e=!0;else if(!e){const n=i[0],r=((o,h)=>{for(let c=o.length-1;c>=0;c--)if(h(o[c],c,o))return c;return-1})(i,o=>!o.eq(n));i.splice(r+1)}return i.forEach((n,r,o)=>{let h,c;r===0?(c=o[1],h=e?n:o[o.length-1]):r===o.length-1?(h=o[r-1],c=e?n:o[0]):(h=o[r-1],c=o[r+1]),e&&o.length===1?s.push(...new Um(n,n,t).project()):!e||r!==0&&r!==o.length-1?s.push(...new ea(n,h,c,t).project()):s.push(...new Um(n,r===0?c:h,t).project())}),s},jf=a=>{const t={};return Object.keys(a).forEach(e=>{t[e]={},Object.keys(a[e]).forEach(s=>{t[e][s]=T({},a[e][s])})}),t},$m=a=>a.replace(/&/g,"&").replace(/"/g,""").replace(/'/g,"'").replace(/</g,"<").replace(/>/g,">"),au=a=>{const t=[];for(let e,s=0;s<a.length;s++)(e=l_(a,s))!==!1&&t.push(e);return t},l_=(a,t)=>{const e=a.charCodeAt(t);if(isNaN(e))return"";if(e<55296||e>57343)return a.charAt(t);if(55296<=e&&e<=56319){if(a.length<=t+1)throw"High surrogate without following low surrogate";const i=a.charCodeAt(t+1);if(56320>i||i>57343)throw"High surrogate without following low surrogate";return a.charAt(t)+a.charAt(t+1)}if(t===0)throw"Low surrogate without preceding high surrogate";const s=a.charCodeAt(t-1);if(55296>s||s>56319)throw"Low surrogate without preceding high surrogate";return!1};var c_=Object.freeze({__proto__:null,capitalize:function(a){let t=arguments.length>1&&arguments[1]!==void 0&&arguments[1];return"".concat(a.charAt(0).toUpperCase()).concat(t?a.slice(1):a.slice(1).toLowerCase())},escapeXml:$m,graphemeSplit:au});const hu=function(a,t){let e=arguments.length>2&&arguments[2]!==void 0&&arguments[2];return a.fill!==t.fill||a.stroke!==t.stroke||a.strokeWidth!==t.strokeWidth||a.fontSize!==t.fontSize||a.fontFamily!==t.fontFamily||a.fontWeight!==t.fontWeight||a.fontStyle!==t.fontStyle||a.textBackgroundColor!==t.textBackgroundColor||a.deltaY!==t.deltaY||e&&(a.overline!==t.overline||a.underline!==t.underline||a.linethrough!==t.linethrough)},qm=(a,t)=>{const e=t.split(`
|
|
38
|
-
`),s=[];let i=-1,n={};a=jf(a);for(let r=0;r<e.length;r++){const o=au(e[r]);if(a[r])for(let h=0;h<o.length;h++){i++;const c=a[r][h];c&&Object.keys(c).length>0&&(hu(n,c,!0)?s.push({start:i,end:i+1,style:c}):s[s.length-1].end++),n=c||{}}else i+=o.length,n={}}return s},Km=(a,t)=>{if(!Array.isArray(a))return jf(a);const e=t.split(lf),s={};let i=-1,n=0;for(let r=0;r<e.length;r++){const o=au(e[r]);for(let h=0;h<o.length;h++)i++,a[n]&&a[n].start<=i&&i<a[n].end&&(s[r]=s[r]||{},s[r][h]=T({},a[n].style),i===a[n].end-1&&n++)}return s},Mn=["display","transform",zt,"fill-opacity","fill-rule","opacity",Pe,"stroke-dasharray","stroke-linecap","stroke-dashoffset","stroke-linejoin","stroke-miterlimit","stroke-opacity","stroke-width","id","paint-order","vector-effect","instantiated_by_use","clip-path"];function Qm(a,t){const e=a.nodeName,s=a.getAttribute("class"),i=a.getAttribute("id"),n="(?![a-zA-Z\\-]+)";let r;if(r=new RegExp("^"+e,"i"),t=t.replace(r,""),i&&t.length&&(r=new RegExp("#"+i+n,"i"),t=t.replace(r,"")),s&&t.length){const o=s.split(" ");for(let h=o.length;h--;)r=new RegExp("\\."+o[h]+n,"i"),t=t.replace(r,"")}return t.length===0}function
|
|
39
|
-
`)]}static async fromElement(t,e,s){const i=Ni(t,this.ATTRIBUTE_NAMES,s),{left:n=0,top:r=0,width:o=0,height:h=0,visible:c=!0}=i,u=Ct(i,P_);return new this(T(T(T({},e),u),{},{left:n,top:r,width:o,height:h,visible:!!(c&&o&&h)}))}}A(oi,"type","Rect"),A(oi,"cacheProperties",[...Fi,...r0]),A(oi,"ownDefaults",{rx:0,ry:0}),A(oi,"ATTRIBUTE_NAMES",[...Mn,"x","y","rx","ry","width","height"]),H.setClass(oi),H.setSVGClass(oi);const ji="initialization",cu="added",Gf="removed",uu="imperative",o0=(a,t)=>{const{strokeUniform:e,strokeWidth:s,width:i,height:n,group:r}=t,o=r&&r!==a?Dh(r.calcTransformMatrix(),a.calcTransformMatrix()):null,h=o?t.getRelativeCenterPoint().transform(o):t.getRelativeCenterPoint(),c=!t.isStrokeAccountedForInDimensions(),u=e&&c?bm(new P(s,s),void 0,a.calcTransformMatrix()):df,d=!e&&c?s:0,f=Qc(i+d,n+d,Yc([o,t.calcOwnMatrix()],!0)).add(u).scalarDivide(2);return[h.subtract(f),h.add(f)]};class du{calcLayoutResult(t,e){if(this.shouldPerformLayout(t))return this.calcBoundingBox(e,t)}shouldPerformLayout(t){let{type:e,prevStrategy:s,strategy:i}=t;return e===ji||e===uu||!!s&&i!==s}shouldLayoutClipPath(t){let{type:e,target:{clipPath:s}}=t;return e!==ji&&s&&!s.absolutePositioned}getInitialSize(t,e){return e.size}calcBoundingBox(t,e){const{type:s,target:i}=e;if(s===uu&&e.overrides)return e.overrides;if(t.length===0)return;const{left:n,top:r,width:o,height:h}=ri(t.map(d=>o0(i,d)).reduce((d,f)=>d.concat(f),[])),c=new P(o,h),u=new P(n,r).add(c.scalarDivide(2));if(s===ji){const d=this.getInitialSize(e,{size:c,center:u});return{center:u,relativeCorrection:new P(0,0),size:d}}return{center:u.transform(i.calcOwnMatrix()),size:c}}}A(du,"type","strategy");class zf extends du{shouldPerformLayout(t){return!0}}A(zf,"type","fit-content"),H.setClass(zf);const D_=["strategy"],O_=["target","strategy","bubbles","prevStrategy"],a0="layoutManager";class Lh{constructor(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:new zf;A(this,"strategy",void 0),this.strategy=t,this._subscriptions=new Map}performLayout(t){const e=T(T({bubbles:!0,strategy:this.strategy},t),{},{prevStrategy:this._prevLayoutStrategy,stopPropagation(){this.bubbles=!1}});this.onBeforeLayout(e);const s=this.getLayoutResult(e);s&&this.commitLayout(e,s),this.onAfterLayout(e,s),this._prevLayoutStrategy=e.strategy}attachHandlers(t,e){const{target:s}=e;return[Xc,Up,Sh,Yp,Gc,$p,zc,_v,wv].map(i=>t.on(i,n=>this.performLayout(i===Xc?{type:"object_modified",trigger:i,e:n,target:s}:{type:"object_modifying",trigger:i,e:n,target:s})))}subscribe(t,e){this.unsubscribe(t,e);const s=this.attachHandlers(t,e);this._subscriptions.set(t,s)}unsubscribe(t,e){(this._subscriptions.get(t)||[]).forEach(s=>s()),this._subscriptions.delete(t)}unsubscribeTargets(t){t.targets.forEach(e=>this.unsubscribe(e,t))}subscribeTargets(t){t.targets.forEach(e=>this.subscribe(e,t))}onBeforeLayout(t){const{target:e,type:s}=t,{canvas:i}=e;if(s===ji||s===cu?this.subscribeTargets(t):s===Gf&&this.unsubscribeTargets(t),e.fire("layout:before",{context:t}),i&&i.fire("object:layout:before",{target:e,context:t}),s===uu&&t.deep){const n=Ct(t,D_);e.forEachObject(r=>r.layoutManager&&r.layoutManager.performLayout(T(T({},n),{},{bubbles:!1,target:r})))}}getLayoutResult(t){const{target:e,strategy:s,type:i}=t,n=s.calcLayoutResult(t,e.getObjects());if(!n)return;const r=i===ji?new P:e.getRelativeCenterPoint(),{center:o,correction:h=new P,relativeCorrection:c=new P}=n,u=r.subtract(o).add(h).transform(i===ji?Ee:Xe(e.calcOwnMatrix()),!0).add(c);return{result:n,prevCenter:r,nextCenter:o,offset:u}}commitLayout(t,e){const{target:s}=t,{result:{size:i},nextCenter:n}=e;var r,o;s.set({width:i.x,height:i.y}),this.layoutObjects(t,e),t.type===ji?s.set({left:(r=t.x)!==null&&r!==void 0?r:n.x+i.x*Vt(s.originX),top:(o=t.y)!==null&&o!==void 0?o:n.y+i.y*Vt(s.originY)}):(s.setPositionByOrigin(n,J,J),s.setCoords(),s.set("dirty",!0))}layoutObjects(t,e){const{target:s}=t;s.forEachObject(i=>{i.group===s&&this.layoutObject(t,e,i)}),t.strategy.shouldLayoutClipPath(t)&&this.layoutObject(t,e,s.clipPath)}layoutObject(t,e,s){let{offset:i}=e;s.set({left:s.left+i.x,top:s.top+i.y})}onAfterLayout(t,e){const{target:s,strategy:i,bubbles:n,prevStrategy:r}=t,o=Ct(t,O_),{canvas:h}=s;s.fire("layout:after",{context:t,result:e}),h&&h.fire("object:layout:after",{context:t,result:e,target:s});const c=s.parent;n&&c!=null&&c.layoutManager&&((o.path||(o.path=[])).push(s),c.layoutManager.performLayout(T(T({},o),{},{target:c}))),s.set("dirty",!0)}dispose(){const{_subscriptions:t}=this;t.forEach(e=>e.forEach(s=>s())),t.clear()}toObject(){return{type:a0,strategy:this.strategy.constructor.type}}toJSON(){return this.toObject()}}H.setClass(Lh,a0);const R_=["type","objects","layoutManager"];class L_ extends Lh{performLayout(){}}class ai extends qp(pe){static getDefaults(){return T(T({},super.getDefaults()),ai.ownDefaults)}constructor(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:[],e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};super(),A(this,"_activeObjects",[]),A(this,"__objectSelectionTracker",void 0),A(this,"__objectSelectionDisposer",void 0),Object.assign(this,ai.ownDefaults),this.setOptions(e),this.groupInit(t,e)}groupInit(t,e){var s;this._objects=[...t],this.__objectSelectionTracker=this.__objectSelectionMonitor.bind(this,!0),this.__objectSelectionDisposer=this.__objectSelectionMonitor.bind(this,!1),this.forEachObject(i=>{this.enterGroup(i,!1)}),this.layoutManager=(s=e.layoutManager)!==null&&s!==void 0?s:new Lh,this.layoutManager.performLayout({type:ji,target:this,targets:[...t],x:e.left,y:e.top})}canEnterGroup(t){return t===this||this.isDescendantOf(t)?(Oi("error","Group: circular object trees are not supported, this call has no effect"),!1):this._objects.indexOf(t)===-1||(Oi("error","Group: duplicate objects are not supported inside group, this call has no effect"),!1)}_filterObjectsBeforeEnteringGroup(t){return t.filter((e,s,i)=>this.canEnterGroup(e)&&i.indexOf(e)===s)}add(){for(var t=arguments.length,e=new Array(t),s=0;s<t;s++)e[s]=arguments[s];const i=this._filterObjectsBeforeEnteringGroup(e),n=super.add(...i);return this._onAfterObjectsChange(cu,i),n}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=this._filterObjectsBeforeEnteringGroup(s),r=super.insertAt(t,...n);return this._onAfterObjectsChange(cu,n),r}remove(){const t=super.remove(...arguments);return this._onAfterObjectsChange(Gf,t),t}_onObjectAdded(t){this.enterGroup(t,!0),this.fire("object:added",{target:t}),t.fire("added",{target:this})}_onObjectRemoved(t,e){this.exitGroup(t,e),this.fire("object:removed",{target:t}),t.fire("removed",{target:this})}_onAfterObjectsChange(t,e){this.layoutManager.performLayout({type:t,targets:e,target:this})}_onStackOrderChanged(){this._set("dirty",!0)}_set(t,e){const s=this[t];return super._set(t,e),t==="canvas"&&s!==e&&(this._objects||[]).forEach(i=>{i._set(t,e)}),this}_shouldSetNestedCoords(){return this.subTargetCheck}removeAll(){return this._activeObjects=[],this.remove(...this._objects)}__objectSelectionMonitor(t,e){let{target:s}=e;const i=this._activeObjects;if(t)i.push(s),this._set("dirty",!0);else if(i.length>0){const n=i.indexOf(s);n>-1&&(i.splice(n,1),this._set("dirty",!0))}}_watchObject(t,e){t&&this._watchObject(!1,e),t?(e.on("selected",this.__objectSelectionTracker),e.on("deselected",this.__objectSelectionDisposer)):(e.off("selected",this.__objectSelectionTracker),e.off("deselected",this.__objectSelectionDisposer))}enterGroup(t,e){t.group&&t.group.remove(t),t._set("parent",this),this._enterGroup(t,e)}_enterGroup(t,e){e&&Ko(t,Nt(Xe(this.calcTransformMatrix()),t.calcTransformMatrix())),this._shouldSetNestedCoords()&&t.setCoords(),t._set("group",this),t._set("canvas",this.canvas),this._watchObject(!0,t);const s=this.canvas&&this.canvas.getActiveObject&&this.canvas.getActiveObject();s&&(s===t||t.isDescendantOf(s))&&this._activeObjects.push(t)}exitGroup(t,e){this._exitGroup(t,e),t._set("parent",void 0),t._set("canvas",void 0)}_exitGroup(t,e){t._set("group",void 0),e||(Ko(t,Nt(this.calcTransformMatrix(),t.calcTransformMatrix())),t.setCoords()),this._watchObject(!1,t);const s=this._activeObjects.length>0?this._activeObjects.indexOf(t):-1;s>-1&&this._activeObjects.splice(s,1)}shouldCache(){const t=pe.prototype.shouldCache.call(this);if(t){for(let e=0;e<this._objects.length;e++)if(this._objects[e].willDrawShadow())return this.ownCaching=!1,!1}return t}willDrawShadow(){if(super.willDrawShadow())return!0;for(let t=0;t<this._objects.length;t++)if(this._objects[t].willDrawShadow())return!0;return!1}isOnACache(){return this.ownCaching||!!this.parent&&this.parent.isOnACache()}drawObject(t,e,s){this._renderBackground(t);for(let n=0;n<this._objects.length;n++){var i;const r=this._objects[n];(i=this.canvas)!==null&&i!==void 0&&i.preserveObjectStacking&&r.group!==this?(t.save(),t.transform(...Xe(this.calcTransformMatrix())),r.render(t),t.restore()):r.group===this&&r.render(t)}this._drawClipPath(t,this.clipPath,s)}setCoords(){super.setCoords(),this._shouldSetNestedCoords()&&this.forEachObject(t=>t.setCoords())}triggerLayout(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};this.layoutManager.performLayout(T({target:this,type:uu},t))}render(t){this._transformDone=!0,super.render(t),this._transformDone=!1}__serializeObjects(t,e){const s=this.includeDefaultValues;return this._objects.filter(function(i){return!i.excludeFromExport}).map(function(i){const n=i.includeDefaultValues;i.includeDefaultValues=s;const r=i[t||"toObject"](e);return i.includeDefaultValues=n,r})}toObject(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:[];const e=this.layoutManager.toObject();return T(T(T({},super.toObject(["subTargetCheck","interactive",...t])),e.strategy!=="fit-content"||this.includeDefaultValues?{layoutManager:e}:{}),{},{objects:this.__serializeObjects("toObject",t)})}toString(){return"#<Group: (".concat(this.complexity(),")>")}dispose(){this.layoutManager.unsubscribeTargets({targets:this.getObjects(),target:this}),this._activeObjects=[],this.forEachObject(t=>{this._watchObject(!1,t),t.dispose()}),super.dispose()}_createSVGBgRect(t){if(!this.backgroundColor)return"";const e=oi.prototype._toSVG.call(this),s=e.indexOf("COMMON_PARTS");e[s]='for="group" ';const i=e.join("");return t?t(i):i}_toSVG(t){const e=["<g ","COMMON_PARTS",` >
|
|
37
|
+
`)}toObject(){const t={color:this.color,blur:this.blur,offsetX:this.offsetX,offsetY:this.offsetY,affectStroke:this.affectStroke,nonScaling:this.nonScaling,type:this.constructor.type},e=Li.ownDefaults;return this.includeDefaultValues?t:bf(t,(s,i)=>s!==e[i])}static async fromObject(t){return new this(t)}}A(Li,"ownDefaults",{color:"rgb(0,0,0)",blur:0,offsetX:0,offsetY:0,affectStroke:!1,includeDefaultValues:!0,nonScaling:!1}),A(Li,"type","shadow"),N.setClass(Li,"shadow");const wr=(a,t,e)=>Math.max(a,Math.min(t,e)),Nv=[Ve,dt,Me,Je,"flipX","flipY","originX","originY","angle","opacity","globalCompositeOperation","shadow","visible",Xo,Wo],Fi=[zt,Pe,"strokeWidth","strokeDashArray","width","height","paintFirst","strokeUniform","strokeLineCap","strokeDashOffset","strokeLineJoin","strokeMiterLimit","backgroundColor","clipPath"],jv={top:0,left:0,width:0,height:0,angle:0,flipX:!1,flipY:!1,scaleX:1,scaleY:1,minScaleLimit:0,skewX:0,skewY:0,originX:dt,originY:Ve,strokeWidth:1,strokeUniform:!1,padding:0,opacity:1,paintFirst:zt,fill:"rgb(0,0,0)",fillRule:"nonzero",stroke:null,strokeDashArray:null,strokeDashOffset:0,strokeLineCap:"butt",strokeLineJoin:"miter",strokeMiterLimit:4,globalCompositeOperation:"source-over",backgroundColor:"",shadow:null,visible:!0,includeDefaultValues:!0,excludeFromExport:!1,objectCaching:!0,clipPath:void 0,inverted:!1,absolutePositioned:!1,centeredRotation:!0,centeredScaling:!1,dirty:!0},Df=(a,t,e,s)=>(a<Math.abs(t)?(a=t,s=e/4):s=t===0&&a===0?e/Ri*Math.asin(1):e/Ri*Math.asin(t/a),{a,c:t,p:e,s}),Om=(a,t,e,s,i)=>a*Math.pow(2,10*(s-=1))*Math.sin((s*i-t)*Ri/e),Rm=(a,t,e,s)=>-e*Math.cos(a/s*An)+e+t,Of=(a,t,e,s)=>(a/=s)<1/2.75?e*(7.5625*a*a)+t:a<2/2.75?e*(7.5625*(a-=1.5/2.75)*a+.75)+t:a<2.5/2.75?e*(7.5625*(a-=2.25/2.75)*a+.9375)+t:e*(7.5625*(a-=2.625/2.75)*a+.984375)+t,Lm=(a,t,e,s)=>e-Of(s-a,0,e,s)+t;var Bv=Object.freeze({__proto__:null,defaultEasing:Rm,easeInBack:function(a,t,e,s){let i=arguments.length>4&&arguments[4]!==void 0?arguments[4]:1.70158;return e*(a/=s)*a*((i+1)*a-i)+t},easeInBounce:Lm,easeInCirc:(a,t,e,s)=>-e*(Math.sqrt(1-(a/=s)*a)-1)+t,easeInCubic:(a,t,e,s)=>e*(a/s)**3+t,easeInElastic:(a,t,e,s)=>{const i=e;let n=0;if(a===0)return t;if((a/=s)===1)return t+e;n||(n=.3*s);const{a:r,s:o,p:h}=Df(i,e,n,1.70158);return-Om(r,o,h,a,s)+t},easeInExpo:(a,t,e,s)=>a===0?t:e*2**(10*(a/s-1))+t,easeInOutBack:function(a,t,e,s){let i=arguments.length>4&&arguments[4]!==void 0?arguments[4]:1.70158;return(a/=s/2)<1?e/2*(a*a*((1+(i*=1.525))*a-i))+t:e/2*((a-=2)*a*((1+(i*=1.525))*a+i)+2)+t},easeInOutBounce:(a,t,e,s)=>a<s/2?.5*Lm(2*a,0,e,s)+t:.5*Of(2*a-s,0,e,s)+.5*e+t,easeInOutCirc:(a,t,e,s)=>(a/=s/2)<1?-e/2*(Math.sqrt(1-a**2)-1)+t:e/2*(Math.sqrt(1-(a-=2)*a)+1)+t,easeInOutCubic:(a,t,e,s)=>(a/=s/2)<1?e/2*a**3+t:e/2*((a-2)**3+2)+t,easeInOutElastic:(a,t,e,s)=>{const i=e;let n=0;if(a===0)return t;if((a/=s/2)===2)return t+e;n||(n=s*(.3*1.5));const{a:r,s:o,p:h,c}=Df(i,e,n,1.70158);return a<1?-.5*Om(r,o,h,a,s)+t:r*Math.pow(2,-10*(a-=1))*Math.sin((a*s-o)*Ri/h)*.5+c+t},easeInOutExpo:(a,t,e,s)=>a===0?t:a===s?t+e:(a/=s/2)<1?e/2*2**(10*(a-1))+t:e/2*-(2**(-10*--a)+2)+t,easeInOutQuad:(a,t,e,s)=>(a/=s/2)<1?e/2*a**2+t:-e/2*(--a*(a-2)-1)+t,easeInOutQuart:(a,t,e,s)=>(a/=s/2)<1?e/2*a**4+t:-e/2*((a-=2)*a**3-2)+t,easeInOutQuint:(a,t,e,s)=>(a/=s/2)<1?e/2*a**5+t:e/2*((a-2)**5+2)+t,easeInOutSine:(a,t,e,s)=>-e/2*(Math.cos(Math.PI*a/s)-1)+t,easeInQuad:(a,t,e,s)=>e*(a/=s)*a+t,easeInQuart:(a,t,e,s)=>e*(a/=s)*a**3+t,easeInQuint:(a,t,e,s)=>e*(a/s)**5+t,easeInSine:(a,t,e,s)=>-e*Math.cos(a/s*An)+e+t,easeOutBack:function(a,t,e,s){let i=arguments.length>4&&arguments[4]!==void 0?arguments[4]:1.70158;return e*((a=a/s-1)*a*((i+1)*a+i)+1)+t},easeOutBounce:Of,easeOutCirc:(a,t,e,s)=>e*Math.sqrt(1-(a=a/s-1)*a)+t,easeOutCubic:(a,t,e,s)=>e*((a/s-1)**3+1)+t,easeOutElastic:(a,t,e,s)=>{const i=e;let n=0;if(a===0)return t;if((a/=s)===1)return t+e;n||(n=.3*s);const{a:r,s:o,p:h,c}=Df(i,e,n,1.70158);return r*2**(-10*a)*Math.sin((a*s-o)*Ri/h)+c+t},easeOutExpo:(a,t,e,s)=>a===s?t+e:e*-(2**(-10*a/s)+1)+t,easeOutQuad:(a,t,e,s)=>-e*(a/=s)*(a-2)+t,easeOutQuart:(a,t,e,s)=>-e*((a=a/s-1)*a**3-1)+t,easeOutQuint:(a,t,e,s)=>e*((a/s-1)**5+1)+t,easeOutSine:(a,t,e,s)=>e*Math.sin(a/s*An)+t});const Hv=()=>!1;class Rf{constructor(t){let{startValue:e,byValue:s,duration:i=500,delay:n=0,easing:r=Rm,onStart:o=pr,onChange:h=pr,onComplete:c=pr,abort:u=Hv,target:d}=t;A(this,"_state","pending"),A(this,"durationProgress",0),A(this,"valueProgress",0),this.tick=this.tick.bind(this),this.duration=i,this.delay=n,this.easing=r,this._onStart=o,this._onChange=h,this._onComplete=c,this._abort=u,this.target=d,this.startValue=e,this.byValue=s,this.value=this.startValue,this.endValue=Object.freeze(this.calculate(this.duration).value)}get state(){return this._state}isDone(){return this._state==="aborted"||this._state==="completed"}start(){const t=e=>{this._state==="pending"&&(this.startTime=e||+new Date,this._state="running",this._onStart(),this.tick(this.startTime))};this.register(),this.delay>0?setTimeout(()=>Ch(t),this.delay):Ch(t)}tick(t){const e=(t||+new Date)-this.startTime,s=Math.min(e,this.duration);this.durationProgress=s/this.duration;const{value:i,valueProgress:n}=this.calculate(s);this.value=Object.freeze(i),this.valueProgress=n,this._state!=="aborted"&&(this._abort(this.value,this.valueProgress,this.durationProgress)?(this._state="aborted",this.unregister()):e>=this.duration?(this.durationProgress=this.valueProgress=1,this._onChange(this.endValue,this.valueProgress,this.durationProgress),this._state="completed",this._onComplete(this.endValue,this.valueProgress,this.durationProgress),this.unregister()):(this._onChange(this.value,this.valueProgress,this.durationProgress),Ch(this.tick)))}register(){Wc.push(this)}unregister(){Wc.remove(this)}abort(){this._state="aborted",this.unregister()}}const Gv=["startValue","endValue"];class zv extends Rf{constructor(t){let{startValue:e=0,endValue:s=100}=t;super(T(T({},Ct(t,Gv)),{},{startValue:e,byValue:s-e}))}calculate(t){const e=this.easing(t,this.startValue,this.byValue,this.duration);return{value:e,valueProgress:Math.abs((e-this.startValue)/this.byValue)}}}const Vv=["startValue","endValue"];class Xv extends Rf{constructor(t){let{startValue:e=[0],endValue:s=[100]}=t;super(T(T({},Ct(t,Vv)),{},{startValue:e,byValue:s.map((i,n)=>i-e[n])}))}calculate(t){const e=this.startValue.map((s,i)=>this.easing(t,s,this.byValue[i],this.duration,i));return{value:e,valueProgress:Math.abs((e[0]-this.startValue[0])/this.byValue[0])}}}const Wv=["startValue","endValue","easing","onChange","onComplete","abort"],Uv=(a,t,e,s)=>t+e*(1-Math.cos(a/s*An)),Lf=a=>a&&((t,e,s)=>a(new gt(t).toRgba(),e,s));class Yv extends Rf{constructor(t){let{startValue:e,endValue:s,easing:i=Uv,onChange:n,onComplete:r,abort:o}=t,h=Ct(t,Wv);const c=new gt(e).getSource(),u=new gt(s).getSource();super(T(T({},h),{},{startValue:c,byValue:u.map((d,f)=>d-c[f]),easing:i,onChange:Lf(n),onComplete:Lf(r),abort:Lf(o)}))}calculate(t){const[e,s,i,n]=this.startValue.map((o,h)=>this.easing(t,o,this.byValue[h],this.duration,h)),r=[...[e,s,i].map(Math.round),wr(0,n,1)];return{value:r,valueProgress:r.map((o,h)=>this.byValue[h]!==0?Math.abs((o-this.startValue[h])/this.byValue[h]):0).find(o=>o!==0)||0}}}function Ff(a){const t=(e=>Array.isArray(e.startValue)||Array.isArray(e.endValue))(a)?new Xv(a):new zv(a);return t.start(),t}function Fm(a){const t=new Yv(a);return t.start(),t}class Mt{constructor(t){this.status=t,this.points=[]}includes(t){return this.points.some(e=>e.eq(t))}append(){for(var t=arguments.length,e=new Array(t),s=0;s<t;s++)e[s]=arguments[s];return this.points=this.points.concat(e.filter(i=>!this.includes(i))),this}static isPointContained(t,e,s){let i=arguments.length>3&&arguments[3]!==void 0&&arguments[3];if(e.eq(s))return t.eq(e);if(e.x===s.x)return t.x===e.x&&(i||t.y>=Math.min(e.y,s.y)&&t.y<=Math.max(e.y,s.y));if(e.y===s.y)return t.y===e.y&&(i||t.x>=Math.min(e.x,s.x)&&t.x<=Math.max(e.x,s.x));{const n=tu(e,s),r=tu(e,t).divide(n);return i?Math.abs(r.x)===Math.abs(r.y):r.x===r.y&&r.x>=0&&r.x<=1}}static isPointInPolygon(t,e){const s=new D(t).setX(Math.min(t.x-1,...e.map(n=>n.x)));let i=0;for(let n=0;n<e.length;n++){const r=this.intersectSegmentSegment(e[n],e[(n+1)%e.length],t,s);if(r.includes(t))return!0;i+=+(r.status==="Intersection")}return i%2==1}static intersectLineLine(t,e,s,i){let n=!(arguments.length>4&&arguments[4]!==void 0)||arguments[4],r=!(arguments.length>5&&arguments[5]!==void 0)||arguments[5];const o=e.x-t.x,h=e.y-t.y,c=i.x-s.x,u=i.y-s.y,d=t.x-s.x,f=t.y-s.y,g=c*f-u*d,p=o*f-h*d,b=u*o-c*h;if(b!==0){const _=g/b,v=p/b;return(n||0<=_&&_<=1)&&(r||0<=v&&v<=1)?new Mt("Intersection").append(new D(t.x+_*o,t.y+_*h)):new Mt}if(g===0||p===0){const _=n||r||Mt.isPointContained(t,s,i)||Mt.isPointContained(e,s,i)||Mt.isPointContained(s,t,e)||Mt.isPointContained(i,t,e);return new Mt(_?"Coincident":void 0)}return new Mt("Parallel")}static intersectSegmentLine(t,e,s,i){return Mt.intersectLineLine(t,e,s,i,!1,!0)}static intersectSegmentSegment(t,e,s,i){return Mt.intersectLineLine(t,e,s,i,!1,!1)}static intersectLinePolygon(t,e,s){let i=!(arguments.length>3&&arguments[3]!==void 0)||arguments[3];const n=new Mt,r=s.length;for(let o,h,c,u=0;u<r;u++){if(o=s[u],h=s[(u+1)%r],c=Mt.intersectLineLine(t,e,o,h,i,!1),c.status==="Coincident")return c;n.append(...c.points)}return n.points.length>0&&(n.status="Intersection"),n}static intersectSegmentPolygon(t,e,s){return Mt.intersectLinePolygon(t,e,s,!1)}static intersectPolygonPolygon(t,e){const s=new Mt,i=t.length,n=[];for(let r=0;r<i;r++){const o=t[r],h=t[(r+1)%i],c=Mt.intersectSegmentPolygon(o,h,e);c.status==="Coincident"?(n.push(c),s.append(o,h)):s.append(...c.points)}return n.length>0&&n.length===t.length?new Mt("Coincident"):(s.points.length>0&&(s.status="Intersection"),s)}static intersectPolygonRectangle(t,e,s){const i=e.min(s),n=e.max(s),r=new D(n.x,i.y),o=new D(i.x,n.y);return Mt.intersectPolygonPolygon(t,[i,r,n,o])}}class $v extends Kp{getX(){return this.getXY().x}setX(t){this.setXY(this.getXY().setX(t))}getY(){return this.getXY().y}setY(t){this.setXY(this.getXY().setY(t))}getRelativeX(){return this.left}setRelativeX(t){this.left=t}getRelativeY(){return this.top}setRelativeY(t){this.top=t}getXY(){const t=this.getRelativeXY();return this.group?ge(t,this.group.calcTransformMatrix()):t}setXY(t,e,s){this.group&&(t=ge(t,Xe(this.group.calcTransformMatrix()))),this.setRelativeXY(t,e,s)}getRelativeXY(){return new D(this.left,this.top)}setRelativeXY(t){let e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:this.originX,s=arguments.length>2&&arguments[2]!==void 0?arguments[2]:this.originY;this.setPositionByOrigin(t,e,s)}isStrokeAccountedForInDimensions(){return!1}getCoords(){const{tl:t,tr:e,br:s,bl:i}=this.aCoords||(this.aCoords=this.calcACoords()),n=[t,e,s,i];if(this.group){const r=this.group.calcTransformMatrix();return n.map(o=>ge(o,r))}return n}intersectsWithRect(t,e){return Mt.intersectPolygonRectangle(this.getCoords(),t,e).status==="Intersection"}intersectsWithObject(t){const e=Mt.intersectPolygonPolygon(this.getCoords(),t.getCoords());return e.status==="Intersection"||e.status==="Coincident"||t.isContainedWithinObject(this)||this.isContainedWithinObject(t)}isContainedWithinObject(t){return this.getCoords().every(e=>t.containsPoint(e))}isContainedWithinRect(t,e){const{left:s,top:i,width:n,height:r}=this.getBoundingRect();return s>=t.x&&s+n<=e.x&&i>=t.y&&i+r<=e.y}isOverlapping(t){return this.intersectsWithObject(t)||this.isContainedWithinObject(t)||t.isContainedWithinObject(this)}containsPoint(t){return Mt.isPointInPolygon(t,this.getCoords())}isOnScreen(){if(!this.canvas)return!1;const{tl:t,br:e}=this.canvas.vptCoords;return!!this.getCoords().some(s=>s.x<=e.x&&s.x>=t.x&&s.y<=e.y&&s.y>=t.y)||!!this.intersectsWithRect(t,e)||this.containsPoint(t.midPointFrom(e))}isPartiallyOnScreen(){if(!this.canvas)return!1;const{tl:t,br:e}=this.canvas.vptCoords;return this.intersectsWithRect(t,e)?!0:this.getCoords().every(s=>(s.x>=e.x||s.x<=t.x)&&(s.y>=e.y||s.y<=t.y))&&this.containsPoint(t.midPointFrom(e))}getBoundingRect(){return ri(this.getCoords())}getScaledWidth(){return this._getTransformedDimensions().x}getScaledHeight(){return this._getTransformedDimensions().y}scale(t){this._set(Me,t),this._set(Je,t),this.setCoords()}scaleToWidth(t){const e=this.getBoundingRect().width/this.getScaledWidth();return this.scale(t/this.width/e)}scaleToHeight(t){const e=this.getBoundingRect().height/this.getScaledHeight();return this.scale(t/this.height/e)}getCanvasRetinaScaling(){var t;return((t=this.canvas)===null||t===void 0?void 0:t.getRetinaScaling())||1}getTotalAngle(){return this.group?kn(tm(this.calcTransformMatrix())):this.angle}getViewportTransform(){var t;return((t=this.canvas)===null||t===void 0?void 0:t.viewportTransform)||Ee.concat()}calcACoords(){const t=$o({angle:this.angle}),{x:e,y:s}=this.getRelativeCenterPoint(),i=Yo(e,s),n=Nt(i,t),r=this._getTransformedDimensions(),o=r.x/2,h=r.y/2;return{tl:ge({x:-o,y:-h},n),tr:ge({x:o,y:-h},n),bl:ge({x:-o,y:h},n),br:ge({x:o,y:h},n)}}setCoords(){this.aCoords=this.calcACoords()}transformMatrixKey(){let t=arguments.length>0&&arguments[0]!==void 0&&arguments[0],e=[];return!t&&this.group&&(e=this.group.transformMatrixKey(t)),e.push(this.top,this.left,this.width,this.height,this.scaleX,this.scaleY,this.angle,this.strokeWidth,this.skewX,this.skewY,+this.flipX,+this.flipY,Vt(this.originX),Vt(this.originY)),e}calcTransformMatrix(){let t=arguments.length>0&&arguments[0]!==void 0&&arguments[0],e=this.calcOwnMatrix();if(t||!this.group)return e;const s=this.transformMatrixKey(t),i=this.matrixCache;return i&&i.key.every((n,r)=>n===s[r])?i.value:(this.group&&(e=Nt(this.group.calcTransformMatrix(!1),e)),this.matrixCache={key:s,value:e},e)}calcOwnMatrix(){const t=this.transformMatrixKey(!0),e=this.ownMatrixCache;if(e&&e.key===t)return e.value;const s=this.getRelativeCenterPoint(),i={angle:this.angle,translateX:s.x,translateY:s.y,scaleX:this.scaleX,scaleY:this.scaleY,skewX:this.skewX,skewY:this.skewY,flipX:this.flipX,flipY:this.flipY},n=sm(i);return this.ownMatrixCache={key:t,value:n},n}_getNonTransformedDimensions(){return new D(this.width,this.height).scalarAdd(this.strokeWidth)}_calculateCurrentDimensions(t){return this._getTransformedDimensions(t).transform(this.getViewportTransform(),!0).scalarAdd(2*this.padding)}_getTransformedDimensions(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};const e=T({scaleX:this.scaleX,scaleY:this.scaleY,skewX:this.skewX,skewY:this.skewY,width:this.width,height:this.height,strokeWidth:this.strokeWidth},t),s=e.strokeWidth;let i=s,n=0;this.strokeUniform&&(i=0,n=s);const r=e.width+i,o=e.height+i;let h;return h=e.skewX===0&&e.skewY===0?new D(r*e.scaleX,o*e.scaleY):Qc(r,o,Ah(e)),h.scalarAdd(n)}translateToGivenOrigin(t,e,s,i,n){let r=t.x,o=t.y;const h=Vt(i)-Vt(e),c=Vt(n)-Vt(s);if(h||c){const u=this._getTransformedDimensions();r+=h*u.x,o+=c*u.y}return new D(r,o)}translateToCenterPoint(t,e,s){if(e===Q&&s===Q)return t;const i=this.translateToGivenOrigin(t,e,s,Q,Q);return this.angle?i.rotate(Rt(this.angle),t):i}translateToOriginPoint(t,e,s){const i=this.translateToGivenOrigin(t,Q,Q,e,s);return this.angle?i.rotate(Rt(this.angle),t):i}getCenterPoint(){const t=this.getRelativeCenterPoint();return this.group?ge(t,this.group.calcTransformMatrix()):t}getRelativeCenterPoint(){return this.translateToCenterPoint(new D(this.left,this.top),this.originX,this.originY)}getPointByOrigin(t,e){return this.translateToOriginPoint(this.getRelativeCenterPoint(),t,e)}setPositionByOrigin(t,e,s){const i=this.translateToCenterPoint(t,e,s),n=this.translateToOriginPoint(i,this.originX,this.originY);this.set({left:n.x,top:n.y})}_getLeftTopCoords(){return this.translateToOriginPoint(this.getRelativeCenterPoint(),dt,Ve)}}const qv=["type"],Kv=["extraParam"];let Ii=class Ed extends $v{static getDefaults(){return Ed.ownDefaults}get type(){const t=this.constructor.type;return t==="FabricObject"?"object":t.toLowerCase()}set type(t){Oi("warn","Setting type has no effect",t)}constructor(t){super(),A(this,"_cacheContext",null),Object.assign(this,Ed.ownDefaults),this.setOptions(t)}_createCacheCanvas(){this._cacheCanvas=ms(),this._cacheContext=this._cacheCanvas.getContext("2d"),this._updateCacheCanvas(),this.dirty=!0}_limitCacheSize(t){const e=t.width,s=t.height,i=ht.maxCacheSideLimit,n=ht.minCacheSideLimit;if(e<=i&&s<=i&&e*s<=ht.perfLimitSizeTotal)return e<n&&(t.width=n),s<n&&(t.height=n),t;const r=e/s,[o,h]=xh.limitDimsByArea(r),c=wr(n,o,i),u=wr(n,h,i);return e>c&&(t.zoomX/=e/c,t.width=c,t.capped=!0),s>u&&(t.zoomY/=s/u,t.height=u,t.capped=!0),t}_getCacheCanvasDimensions(){const t=this.getTotalObjectScaling(),e=this._getTransformedDimensions({skewX:0,skewY:0}),s=e.x*t.x/this.scaleX,i=e.y*t.y/this.scaleY;return{width:Math.ceil(s+2),height:Math.ceil(i+2),zoomX:t.x,zoomY:t.y,x:s,y:i}}_updateCacheCanvas(){const t=this._cacheCanvas,e=this._cacheContext,{width:s,height:i,zoomX:n,zoomY:r,x:o,y:h}=this._limitCacheSize(this._getCacheCanvasDimensions()),c=s!==t.width||i!==t.height,u=this.zoomX!==n||this.zoomY!==r;if(!t||!e)return!1;if(c||u){s!==t.width||i!==t.height?(t.width=s,t.height=i):(e.setTransform(1,0,0,1,0,0),e.clearRect(0,0,t.width,t.height));const d=o/2,f=h/2;return this.cacheTranslationX=Math.round(t.width/2-d)+d,this.cacheTranslationY=Math.round(t.height/2-f)+f,e.translate(this.cacheTranslationX,this.cacheTranslationY),e.scale(n,r),this.zoomX=n,this.zoomY=r,!0}return!1}setOptions(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};this._setOptions(t)}transform(t){const e=this.group&&!this.group._transformDone||this.group&&this.canvas&&t===this.canvas.contextTop,s=this.calcTransformMatrix(!e);t.transform(s[0],s[1],s[2],s[3],s[4],s[5])}getObjectScaling(){if(!this.group)return new D(Math.abs(this.scaleX),Math.abs(this.scaleY));const t=br(this.calcTransformMatrix());return new D(Math.abs(t.scaleX),Math.abs(t.scaleY))}getTotalObjectScaling(){const t=this.getObjectScaling();if(this.canvas){const e=this.canvas.getZoom(),s=this.getCanvasRetinaScaling();return t.scalarMultiply(e*s)}return t}getObjectOpacity(){let t=this.opacity;return this.group&&(t*=this.group.getObjectOpacity()),t}_constrainScale(t){return Math.abs(t)<this.minScaleLimit?t<0?-this.minScaleLimit:this.minScaleLimit:t===0?1e-4:t}_set(t,e){t!==Me&&t!==Je||(e=this._constrainScale(e)),t===Me&&e<0?(this.flipX=!this.flipX,e*=-1):t==="scaleY"&&e<0?(this.flipY=!this.flipY,e*=-1):t!=="shadow"||!e||e instanceof Li||(e=new Li(e));const s=this[t]!==e;return this[t]=e,s&&this.constructor.cacheProperties.includes(t)&&(this.dirty=!0),this.parent&&(this.dirty||s&&this.constructor.stateProperties.includes(t))&&this.parent._set("dirty",!0),this}isNotVisible(){return this.opacity===0||!this.width&&!this.height&&this.strokeWidth===0||!this.visible}render(t){this.isNotVisible()||this.canvas&&this.canvas.skipOffscreen&&!this.group&&!this.isOnScreen()||(t.save(),this._setupCompositeOperation(t),this.drawSelectionBackground(t),this.transform(t),this._setOpacity(t),this._setShadow(t),this.shouldCache()?(this.renderCache(),this.drawCacheOnCanvas(t)):(this._removeCacheCanvas(),this.drawObject(t,!1,{}),this.dirty=!1),t.restore())}drawSelectionBackground(t){}renderCache(t){if(t=t||{},this._cacheCanvas&&this._cacheContext||this._createCacheCanvas(),this.isCacheDirty()&&this._cacheContext){const{zoomX:e,zoomY:s,cacheTranslationX:i,cacheTranslationY:n}=this,{width:r,height:o}=this._cacheCanvas;this.drawObject(this._cacheContext,t.forClipping,{zoomX:e,zoomY:s,cacheTranslationX:i,cacheTranslationY:n,width:r,height:o,parentClipPaths:[]}),this.dirty=!1}}_removeCacheCanvas(){this._cacheCanvas=void 0,this._cacheContext=null}hasStroke(){return this.stroke&&this.stroke!=="transparent"&&this.strokeWidth!==0}hasFill(){return this.fill&&this.fill!=="transparent"}needsItsOwnCache(){return!!(this.paintFirst===Pe&&this.hasFill()&&this.hasStroke()&&this.shadow)||!!this.clipPath}shouldCache(){return this.ownCaching=this.objectCaching&&(!this.parent||!this.parent.isOnACache())||this.needsItsOwnCache(),this.ownCaching}willDrawShadow(){return!!this.shadow&&(this.shadow.offsetX!==0||this.shadow.offsetY!==0)}drawClipPathOnCache(t,e,s){t.save(),e.inverted?t.globalCompositeOperation="destination-out":t.globalCompositeOperation="destination-in",t.setTransform(1,0,0,1,0,0),t.drawImage(s,0,0),t.restore()}drawObject(t,e,s){const i=this.fill,n=this.stroke;e?(this.fill="black",this.stroke="",this._setClippingProperties(t)):this._renderBackground(t),this._render(t),this._drawClipPath(t,this.clipPath,s),this.fill=i,this.stroke=n}createClipPathLayer(t,e){const s=Rs(e),i=s.getContext("2d");if(i.translate(e.cacheTranslationX,e.cacheTranslationY),i.scale(e.zoomX,e.zoomY),t._cacheCanvas=s,e.parentClipPaths.forEach(n=>{n.transform(i)}),e.parentClipPaths.push(t),t.absolutePositioned){const n=Xe(this.calcTransformMatrix());i.transform(n[0],n[1],n[2],n[3],n[4],n[5])}return t.transform(i),t.drawObject(i,!0,e),s}_drawClipPath(t,e,s){if(!e)return;e._transformDone=!0;const i=this.createClipPathLayer(e,s);this.drawClipPathOnCache(t,e,i)}drawCacheOnCanvas(t){t.scale(1/this.zoomX,1/this.zoomY),t.drawImage(this._cacheCanvas,-this.cacheTranslationX,-this.cacheTranslationY)}isCacheDirty(){let t=arguments.length>0&&arguments[0]!==void 0&&arguments[0];if(this.isNotVisible())return!1;const e=this._cacheCanvas,s=this._cacheContext;return!(!e||!s||t||!this._updateCacheCanvas())||!!(this.dirty||this.clipPath&&this.clipPath.absolutePositioned)&&(e&&s&&!t&&(s.save(),s.setTransform(1,0,0,1,0,0),s.clearRect(0,0,e.width,e.height),s.restore()),!0)}_renderBackground(t){if(!this.backgroundColor)return;const e=this._getNonTransformedDimensions();t.fillStyle=this.backgroundColor,t.fillRect(-e.x/2,-e.y/2,e.x,e.y),this._removeShadow(t)}_setOpacity(t){this.group&&!this.group._transformDone?t.globalAlpha=this.getObjectOpacity():t.globalAlpha*=this.opacity}_setStrokeStyles(t,e){const s=e.stroke;s&&(t.lineWidth=e.strokeWidth,t.lineCap=e.strokeLineCap,t.lineDashOffset=e.strokeDashOffset,t.lineJoin=e.strokeLineJoin,t.miterLimit=e.strokeMiterLimit,bs(s)?s.gradientUnits==="percentage"||s.gradientTransform||s.patternTransform?this._applyPatternForTransformedGradient(t,s):(t.strokeStyle=s.toLive(t),this._applyPatternGradientTransform(t,s)):t.strokeStyle=e.stroke)}_setFillStyles(t,e){let{fill:s}=e;s&&(bs(s)?(t.fillStyle=s.toLive(t),this._applyPatternGradientTransform(t,s)):t.fillStyle=s)}_setClippingProperties(t){t.globalAlpha=1,t.strokeStyle="transparent",t.fillStyle="#000000"}_setLineDash(t,e){e&&e.length!==0&&t.setLineDash(e)}_setShadow(t){if(!this.shadow)return;const e=this.shadow,s=this.canvas,i=this.getCanvasRetinaScaling(),[n,,,r]=(s==null?void 0:s.viewportTransform)||Ee,o=n*i,h=r*i,c=e.nonScaling?new D(1,1):this.getObjectScaling();t.shadowColor=e.color,t.shadowBlur=e.blur*ht.browserShadowBlurConstant*(o+h)*(c.x+c.y)/4,t.shadowOffsetX=e.offsetX*o*c.x,t.shadowOffsetY=e.offsetY*h*c.y}_removeShadow(t){this.shadow&&(t.shadowColor="",t.shadowBlur=t.shadowOffsetX=t.shadowOffsetY=0)}_applyPatternGradientTransform(t,e){if(!bs(e))return{offsetX:0,offsetY:0};const s=e.gradientTransform||e.patternTransform,i=-this.width/2+e.offsetX||0,n=-this.height/2+e.offsetY||0;return e.gradientUnits==="percentage"?t.transform(this.width,0,0,this.height,i,n):t.transform(1,0,0,1,i,n),s&&t.transform(s[0],s[1],s[2],s[3],s[4],s[5]),{offsetX:i,offsetY:n}}_renderPaintInOrder(t){this.paintFirst===Pe?(this._renderStroke(t),this._renderFill(t)):(this._renderFill(t),this._renderStroke(t))}_render(t){}_renderFill(t){this.fill&&(t.save(),this._setFillStyles(t,this),this.fillRule==="evenodd"?t.fill("evenodd"):t.fill(),t.restore())}_renderStroke(t){if(this.stroke&&this.strokeWidth!==0){if(this.shadow&&!this.shadow.affectStroke&&this._removeShadow(t),t.save(),this.strokeUniform){const e=this.getObjectScaling();t.scale(1/e.x,1/e.y)}this._setLineDash(t,this.strokeDashArray),this._setStrokeStyles(t,this),t.stroke(),t.restore()}}_applyPatternForTransformedGradient(t,e){var s;const i=this._limitCacheSize(this._getCacheCanvasDimensions()),n=this.getCanvasRetinaScaling(),r=i.x/this.scaleX/n,o=i.y/this.scaleY/n,h=Rs({width:Math.ceil(r),height:Math.ceil(o)}),c=h.getContext("2d");c&&(c.beginPath(),c.moveTo(0,0),c.lineTo(r,0),c.lineTo(r,o),c.lineTo(0,o),c.closePath(),c.translate(r/2,o/2),c.scale(i.zoomX/this.scaleX/n,i.zoomY/this.scaleY/n),this._applyPatternGradientTransform(c,e),c.fillStyle=e.toLive(t),c.fill(),t.translate(-this.width/2-this.strokeWidth/2,-this.height/2-this.strokeWidth/2),t.scale(n*this.scaleX/i.zoomX,n*this.scaleY/i.zoomY),t.strokeStyle=(s=c.createPattern(h,"no-repeat"))!==null&&s!==void 0?s:"")}_findCenterFromElement(){return new D(this.left+this.width/2,this.top+this.height/2)}clone(t){const e=this.toObject(t);return this.constructor.fromObject(e)}cloneAsImage(t){const e=this.toCanvasElement(t);return new(N.getClass("image"))(e)}toCanvasElement(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};const e=xf(this),s=this.group,i=this.shadow,n=Math.abs,r=t.enableRetinaScaling?Wp():1,o=(t.multiplier||1)*r,h=t.canvasProvider||(x=>new Ph(x,{enableRetinaScaling:!1,renderOnAddRemove:!1,skipOffscreen:!1}));delete this.group,t.withoutTransform&&mm(this),t.withoutShadow&&(this.shadow=null),t.viewportTransform&&Sf(this,this.getViewportTransform()),this.setCoords();const c=ms(),u=this.getBoundingRect(),d=this.shadow,f=new D;if(d){const x=d.blur,C=d.nonScaling?new D(1,1):this.getObjectScaling();f.x=2*Math.round(n(d.offsetX)+x)*n(C.x),f.y=2*Math.round(n(d.offsetY)+x)*n(C.y)}const g=u.width+f.x,p=u.height+f.y;c.width=Math.ceil(g),c.height=Math.ceil(p);const b=h(c);t.format==="jpeg"&&(b.backgroundColor="#fff"),this.setPositionByOrigin(new D(b.width/2,b.height/2),Q,Q);const _=this.canvas;b._objects=[this],this.set("canvas",b),this.setCoords();const v=b.toCanvasElement(o||1,t);return this.set("canvas",_),this.shadow=i,s&&(this.group=s),this.set(e),this.setCoords(),b._objects=[],b.destroy(),v}toDataURL(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};return ff(this.toCanvasElement(t),t.format||"png",t.quality||1)}toBlob(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};return gf(this.toCanvasElement(t),t.format||"png",t.quality||1)}isType(){for(var t=arguments.length,e=new Array(t),s=0;s<t;s++)e[s]=arguments[s];return e.includes(this.constructor.type)||e.includes(this.type)}complexity(){return 1}toJSON(){return this.toObject()}rotate(t){const{centeredRotation:e,originX:s,originY:i}=this;if(e){const{x:n,y:r}=this.getRelativeCenterPoint();this.originX=Q,this.originY=Q,this.left=n,this.top=r}if(this.set("angle",t),e){const{x:n,y:r}=this.translateToOriginPoint(this.getRelativeCenterPoint(),s,i);this.left=n,this.top=r,this.originX=s,this.originY=i}}setOnGroup(){}_setupCompositeOperation(t){this.globalCompositeOperation&&(t.globalCompositeOperation=this.globalCompositeOperation)}dispose(){Wc.cancelByTarget(this),this.off(),this._set("canvas",void 0),this._cacheCanvas&&ni().dispose(this._cacheCanvas),this._cacheCanvas=void 0,this._cacheContext=null}animate(t,e){return Object.entries(t).reduce((s,i)=>{let[n,r]=i;return s[n]=this._animate(n,r,e),s},{})}_animate(t,e){let s=arguments.length>2&&arguments[2]!==void 0?arguments[2]:{};const i=t.split("."),n=this.constructor.colorProperties.includes(i[i.length-1]),{abort:r,startValue:o,onChange:h,onComplete:c}=s,u=T(T({},s),{},{target:this,startValue:o??i.reduce((d,f)=>d[f],this),endValue:e,abort:r==null?void 0:r.bind(this),onChange:(d,f,g)=>{i.reduce((p,b,_)=>(_===i.length-1&&(p[b]=d),p[b]),this),h&&h(d,f,g)},onComplete:(d,f,g)=>{this.setCoords(),c&&c(d,f,g)}});return n?Fm(u):Ff(u)}isDescendantOf(t){const{parent:e,group:s}=this;return e===t||s===t||!!e&&e.isDescendantOf(t)||!!s&&s!==e&&s.isDescendantOf(t)}getAncestors(){const t=[];let e=this;do e=e.parent,e&&t.push(e);while(e);return t}findCommonAncestors(t){if(this===t)return{fork:[],otherFork:[],common:[this,...this.getAncestors()]};const e=this.getAncestors(),s=t.getAncestors();if(e.length===0&&s.length>0&&this===s[s.length-1])return{fork:[],otherFork:[t,...s.slice(0,s.length-1)],common:[this]};for(let i,n=0;n<e.length;n++){if(i=e[n],i===t)return{fork:[this,...e.slice(0,n)],otherFork:[],common:e.slice(n)};for(let r=0;r<s.length;r++){if(this===s[r])return{fork:[],otherFork:[t,...s.slice(0,r)],common:[this,...e]};if(i===s[r])return{fork:[this,...e.slice(0,n)],otherFork:[t,...s.slice(0,r)],common:e.slice(n)}}}return{fork:[this,...e],otherFork:[t,...s],common:[]}}hasCommonAncestors(t){const e=this.findCommonAncestors(t);return e&&!!e.common.length}isInFrontOf(t){if(this===t)return;const e=this.findCommonAncestors(t);if(e.fork.includes(t))return!0;if(e.otherFork.includes(this))return!1;const s=e.common[0]||this.canvas;if(!s)return;const i=e.fork.pop(),n=e.otherFork.pop(),r=s._objects.indexOf(i),o=s._objects.indexOf(n);return r>-1&&r>o}toObject(){const t=(arguments.length>0&&arguments[0]!==void 0?arguments[0]:[]).concat(Ed.customProperties,this.constructor.customProperties||[]);let e;const s=ht.NUM_FRACTION_DIGITS,{clipPath:i,fill:n,stroke:r,shadow:o,strokeDashArray:h,left:c,top:u,originX:d,originY:f,width:g,height:p,strokeWidth:b,strokeLineCap:_,strokeDashOffset:v,strokeLineJoin:x,strokeUniform:C,strokeMiterLimit:S,scaleX:k,scaleY:M,angle:E,flipX:P,flipY:O,opacity:L,visible:R,backgroundColor:U,fillRule:z,paintFirst:V,globalCompositeOperation:at,skewX:F,skewY:G}=this;i&&!i.excludeFromExport&&(e=i.toObject(t.concat("inverted","absolutePositioned")));const rt=te=>At(te,s),Gt=T(T({},yr(this,t)),{},{type:this.constructor.type,version:rf,originX:d,originY:f,left:rt(c),top:rt(u),width:rt(g),height:rt(p),fill:am(n)?n.toObject():n,stroke:am(r)?r.toObject():r,strokeWidth:rt(b),strokeDashArray:h&&h.concat(),strokeLineCap:_,strokeDashOffset:v,strokeLineJoin:x,strokeUniform:C,strokeMiterLimit:rt(S),scaleX:rt(k),scaleY:rt(M),angle:rt(E),flipX:P,flipY:O,opacity:rt(L),shadow:o&&o.toObject(),visible:R,backgroundColor:U,fillRule:z,paintFirst:V,globalCompositeOperation:at,skewX:rt(F),skewY:rt(G)},e?{clipPath:e}:null);return this.includeDefaultValues?Gt:this._removeDefaultValues(Gt)}toDatalessObject(t){return this.toObject(t)}_removeDefaultValues(t){const e=this.constructor.getDefaults(),s=Object.keys(e).length>0?e:Object.getPrototypeOf(this);return bf(t,(i,n)=>{if(n===dt||n===Ve||n==="type")return!0;const r=s[n];return i!==r&&!(Array.isArray(i)&&Array.isArray(r)&&i.length===0&&r.length===0)})}toString(){return"#<".concat(this.constructor.type,">")}static _fromObject(t){let e=Ct(t,qv),s=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},{extraParam:i}=s,n=Ct(s,Kv);return Eh(e,n).then(r=>i?(delete r[i],new this(e[i],r)):new this(r))}static fromObject(t,e){return this._fromObject(t,e)}};A(Ii,"stateProperties",Nv),A(Ii,"cacheProperties",Fi),A(Ii,"ownDefaults",jv),A(Ii,"type","FabricObject"),A(Ii,"colorProperties",[zt,Pe,"backgroundColor"]),A(Ii,"customProperties",[]),N.setClass(Ii),N.setClass(Ii,"object");const Jo=(a,t,e)=>(s,i,n,r)=>{const o=t(s,i,n,r);return o&&ym(a,T(T({},wm(s,i,n,r)),e)),o};function Zo(a){return(t,e,s,i)=>{const{target:n,originX:r,originY:o}=e,h=n.getRelativeCenterPoint(),c=n.translateToOriginPoint(h,r,o),u=a(t,e,s,i);return n.setPositionByOrigin(c,e.originX,e.originY),u}}const Im=Jo(Sh,Zo((a,t,e,s)=>{const i=Cf(t,t.originX,t.originY,e,s);if(Vt(t.originX)===Vt(Q)||Vt(t.originX)===Vt(It)&&i.x<0||Vt(t.originX)===Vt(dt)&&i.x>0){const{target:n}=t,r=n.strokeWidth/(n.strokeUniform?n.scaleX:1),o=vm(t)?2:1,h=n.width,c=Math.abs(i.x*o/n.scaleX)-r;return n.set("width",Math.max(c,1)),h!==n.width}return!1}));function Qv(a,t,e,s,i){s=s||{};const n=this.sizeX||s.cornerSize||i.cornerSize,r=this.sizeY||s.cornerSize||i.cornerSize,o=s.transparentCorners!==void 0?s.transparentCorners:i.transparentCorners,h=o?Pe:zt,c=!o&&(s.cornerStrokeColor||i.cornerStrokeColor);let u,d=t,f=e;a.save(),a.fillStyle=s.cornerColor||i.cornerColor||"",a.strokeStyle=s.cornerStrokeColor||i.cornerStrokeColor||"",n>r?(u=n,a.scale(1,r/n),f=e*n/r):r>n?(u=r,a.scale(n/r,1),d=t*r/n):u=n,a.beginPath(),a.arc(d,f,u/2,0,Ri,!1),a[h](),c&&a.stroke(),a.restore()}function Jv(a,t,e,s,i){s=s||{};const n=this.sizeX||s.cornerSize||i.cornerSize,r=this.sizeY||s.cornerSize||i.cornerSize,o=s.transparentCorners!==void 0?s.transparentCorners:i.transparentCorners,h=o?Pe:zt,c=!o&&(s.cornerStrokeColor||i.cornerStrokeColor),u=n/2,d=r/2;a.save(),a.fillStyle=s.cornerColor||i.cornerColor||"",a.strokeStyle=s.cornerStrokeColor||i.cornerStrokeColor||"",a.translate(t,e);const f=i.getTotalAngle();a.rotate(Rt(f)),a["".concat(h,"Rect")](-u,-d,n,r),c&&a.strokeRect(-u,-d,n,r),a.restore()}class Ns{constructor(t){A(this,"visible",!0),A(this,"actionName",Vc),A(this,"angle",0),A(this,"x",0),A(this,"y",0),A(this,"offsetX",0),A(this,"offsetY",0),A(this,"sizeX",0),A(this,"sizeY",0),A(this,"touchSizeX",0),A(this,"touchSizeY",0),A(this,"cursorStyle","crosshair"),A(this,"withConnection",!1),Object.assign(this,t)}shouldActivate(t,e,s,i){var n;let{tl:r,tr:o,br:h,bl:c}=i;return((n=e.canvas)===null||n===void 0?void 0:n.getActiveObject())===e&&e.isControlVisible(t)&&Mt.isPointInPolygon(s,[r,o,h,c])}getActionHandler(t,e,s){return this.actionHandler}getMouseDownHandler(t,e,s){return this.mouseDownHandler}getMouseUpHandler(t,e,s){return this.mouseUpHandler}cursorStyleHandler(t,e,s){return e.cursorStyle}getActionName(t,e,s){return e.actionName}getVisibility(t,e){var s,i;return(s=(i=t._controlsVisibility)===null||i===void 0?void 0:i[e])!==null&&s!==void 0?s:this.visible}setVisibility(t,e,s){this.visible=t}positionHandler(t,e,s,i){return new D(this.x*t.x+this.offsetX,this.y*t.y+this.offsetY).transform(e)}calcCornerCoords(t,e,s,i,n,r){const o=Yc([Yo(s,i),$o({angle:t}),$c((n?this.touchSizeX:this.sizeX)||e,(n?this.touchSizeY:this.sizeY)||e)]);return{tl:new D(-.5,-.5).transform(o),tr:new D(.5,-.5).transform(o),br:new D(.5,.5).transform(o),bl:new D(-.5,.5).transform(o)}}render(t,e,s,i,n){((i=i||{}).cornerStyle||n.cornerStyle)==="circle"?Qv.call(this,t,e,s,i,n):Jv.call(this,t,e,s,i,n)}}const Zv=(a,t,e)=>e.lockRotation?Jc:t.cursorStyle,t_=Jo(Yp,Zo((a,t,e,s)=>{let{target:i,ex:n,ey:r,theta:o,originX:h,originY:c}=t;const u=i.translateToOriginPoint(i.getRelativeCenterPoint(),h,c);if(Fs(i,"lockRotation"))return!1;const d=Math.atan2(r-u.y,n-u.x),f=Math.atan2(s-u.y,e-u.x);let g=kn(f-d+o);if(i.snapAngle&&i.snapAngle>0){const b=i.snapAngle,_=i.snapThreshold||b,v=Math.ceil(g/b)*b,x=Math.floor(g/b)*b;Math.abs(g-x)<_?g=x:Math.abs(g-v)<_&&(g=v)}g<0&&(g=360+g),g%=360;const p=i.angle!==g;return i.angle=g,p}));function Nm(a,t){const e=t.canvas,s=a[e.uniScaleKey];return e.uniformScaling&&!s||!e.uniformScaling&&s}function jm(a,t,e){const s=Fs(a,"lockScalingX"),i=Fs(a,"lockScalingY");if(s&&i||!t&&(s||i)&&e||s&&t==="x"||i&&t==="y")return!0;const{width:n,height:r,strokeWidth:o}=a;return n===0&&o===0&&t!=="y"||r===0&&o===0&&t!=="x"}const e_=["e","se","s","sw","w","nw","n","ne","e"],Oh=(a,t,e)=>{const s=Nm(a,e);if(jm(e,t.x!==0&&t.y===0?"x":t.x===0&&t.y!==0?"y":"",s))return Jc;const i=xm(e,t);return"".concat(e_[i],"-resize")};function If(a,t,e,s){let i=arguments.length>4&&arguments[4]!==void 0?arguments[4]:{};const n=t.target,r=i.by,o=Nm(a,n);let h,c,u,d,f,g;if(jm(n,r,o))return!1;if(t.gestureScale)c=t.scaleX*t.gestureScale,u=t.scaleY*t.gestureScale;else{if(h=Cf(t,t.originX,t.originY,e,s),f=r!=="y"?Math.sign(h.x||t.signX||1):1,g=r!=="x"?Math.sign(h.y||t.signY||1):1,t.signX||(t.signX=f),t.signY||(t.signY=g),Fs(n,"lockScalingFlip")&&(t.signX!==f||t.signY!==g))return!1;if(d=n._getTransformedDimensions(),o&&!r){const _=Math.abs(h.x)+Math.abs(h.y),{original:v}=t,x=_/(Math.abs(d.x*v.scaleX/n.scaleX)+Math.abs(d.y*v.scaleY/n.scaleY));c=v.scaleX*x,u=v.scaleY*x}else c=Math.abs(h.x*n.scaleX/d.x),u=Math.abs(h.y*n.scaleY/d.y);vm(t)&&(c*=2,u*=2),t.signX!==f&&r!=="y"&&(t.originX=_m(t.originX),c*=-1,t.signX=f),t.signY!==g&&r!=="x"&&(t.originY=_m(t.originY),u*=-1,t.signY=g)}const p=n.scaleX,b=n.scaleY;return r?(r==="x"&&n.set(Me,c),r==="y"&&n.set(Je,u)):(!Fs(n,"lockScalingX")&&n.set(Me,c),!Fs(n,"lockScalingY")&&n.set(Je,u)),p!==n.scaleX||b!==n.scaleY}const nu=Jo(Gc,Zo((a,t,e,s)=>If(a,t,e,s))),s_=Jo(Gc,Zo((a,t,e,s)=>If(a,t,e,s,{by:"x"}))),i_=Jo(Gc,Zo((a,t,e,s)=>If(a,t,e,s,{by:"y"}))),n_=["target","ex","ey","skewingSide"],Nf={x:{counterAxis:"y",scale:Me,skew:Xo,lockSkewing:"lockSkewingX",origin:"originX",flip:"flipX"},y:{counterAxis:"x",scale:Je,skew:Wo,lockSkewing:"lockSkewingY",origin:"originY",flip:"flipY"}},r_=["ns","nesw","ew","nwse"],o_=(a,t,e)=>{if(t.x!==0&&Fs(e,"lockSkewingY")||t.y!==0&&Fs(e,"lockSkewingX"))return Jc;const s=xm(e,t)%4;return"".concat(r_[s],"-resize")};function Bm(a,t,e,s,i){const{target:n}=e,{counterAxis:r,origin:o,lockSkewing:h,skew:c,flip:u}=Nf[a];if(Fs(n,h))return!1;const{origin:d,flip:f}=Nf[r],g=Vt(e[d])*(n[f]?-1:1),p=-Math.sign(g)*(n[u]?-1:1),b=.5*-((n[c]===0&&Cf(e,Q,Q,s,i)[a]>0||n[c]>0?1:-1)*p)+.5;return Jo($p,Zo((v,x,C,S)=>function(k,M,E){let{target:P,ex:O,ey:L,skewingSide:R}=M,U=Ct(M,n_);const{skew:z}=Nf[k],V=E.subtract(new D(O,L)).divide(new D(P.scaleX,P.scaleY))[k],at=P[z],F=U[z],G=Math.tan(Rt(F)),rt=k==="y"?P._getTransformedDimensions({scaleX:1,scaleY:1,skewX:0}).x:P._getTransformedDimensions({scaleX:1,scaleY:1}).y,Gt=2*V*R/Math.max(rt,1)+G,te=kn(Math.atan(Gt));P.set(z,te);const fe=at!==P[z];if(fe&&k==="y"){const{skewX:Yt,scaleX:St}=P,He=P._getTransformedDimensions({skewY:at}),Mi=P._getTransformedDimensions(),Ft=Yt!==0?He.x/Mi.x:1;Ft!==1&&P.set(Me,Ft*St)}return fe}(a,x,new D(C,S))))(t,T(T({},e),{},{[o]:b,skewingSide:p}),s,i)}const a_=(a,t,e,s)=>Bm("x",a,t,e,s),h_=(a,t,e,s)=>Bm("y",a,t,e,s);function ru(a,t){return a[t.canvas.altActionKey]}const ou=(a,t,e)=>{const s=ru(a,e);return t.x===0?s?Xo:Je:t.y===0?s?Wo:Me:""},ta=(a,t,e)=>ru(a,e)?o_(0,t,e):Oh(a,t,e),Hm=(a,t,e,s)=>ru(a,t.target)?h_(a,t,e,s):s_(a,t,e,s),Gm=(a,t,e,s)=>ru(a,t.target)?a_(a,t,e,s):i_(a,t,e,s),zm=()=>({ml:new Ns({x:-.5,y:0,cursorStyleHandler:ta,actionHandler:Hm,getActionName:ou}),mr:new Ns({x:.5,y:0,cursorStyleHandler:ta,actionHandler:Hm,getActionName:ou}),mb:new Ns({x:0,y:.5,cursorStyleHandler:ta,actionHandler:Gm,getActionName:ou}),mt:new Ns({x:0,y:-.5,cursorStyleHandler:ta,actionHandler:Gm,getActionName:ou}),tl:new Ns({x:-.5,y:-.5,cursorStyleHandler:Oh,actionHandler:nu}),tr:new Ns({x:.5,y:-.5,cursorStyleHandler:Oh,actionHandler:nu}),bl:new Ns({x:-.5,y:.5,cursorStyleHandler:Oh,actionHandler:nu}),br:new Ns({x:.5,y:.5,cursorStyleHandler:Oh,actionHandler:nu}),mtr:new Ns({x:0,y:-.5,actionHandler:t_,cursorStyleHandler:Zv,offsetY:-40,withConnection:!0,actionName:cf})}),l_=()=>({mr:new Ns({x:.5,y:0,actionHandler:Im,cursorStyleHandler:ta,actionName:Sh}),ml:new Ns({x:-.5,y:0,actionHandler:Im,cursorStyleHandler:ta,actionName:Sh})}),c_=()=>T(T({},zm()),l_());class Rh extends Ii{static getDefaults(){return T(T({},super.getDefaults()),Rh.ownDefaults)}constructor(t){super(),Object.assign(this,this.constructor.createControls(),Rh.ownDefaults),this.setOptions(t)}static createControls(){return{controls:zm()}}_updateCacheCanvas(){const t=this.canvas;if(this.noScaleCache&&t&&t._currentTransform){const e=t._currentTransform,s=e.target,i=e.action;if(this===s&&i&&i.startsWith(Vc))return!1}return super._updateCacheCanvas()}getActiveControl(){const t=this.__corner;return t?{key:t,control:this.controls[t],coord:this.oCoords[t]}:void 0}findControl(t){let e=arguments.length>1&&arguments[1]!==void 0&&arguments[1];if(!this.hasControls||!this.canvas)return;this.__corner=void 0;const s=Object.entries(this.oCoords);for(let i=s.length-1;i>=0;i--){const[n,r]=s[i],o=this.controls[n];if(o.shouldActivate(n,this,t,e?r.touchCorner:r.corner))return this.__corner=n,{key:n,control:o,coord:this.oCoords[n]}}}calcOCoords(){const t=this.getViewportTransform(),e=this.getCenterPoint(),s=Yo(e.x,e.y),i=$o({angle:this.getTotalAngle()-(this.group&&this.flipX?180:0)}),n=Nt(s,i),r=Nt(t,n),o=Nt(r,[1/t[0],0,0,1/t[3],0,0]),h=this.group?br(this.calcTransformMatrix()):void 0;h&&(h.scaleX=Math.abs(h.scaleX),h.scaleY=Math.abs(h.scaleY));const c=this._calculateCurrentDimensions(h),u={};return this.forEachControl((d,f)=>{const g=d.positionHandler(c,o,this,d);u[f]=Object.assign(g,this._calcCornerCoords(d,g))}),u}_calcCornerCoords(t,e){const s=this.getTotalAngle();return{corner:t.calcCornerCoords(s,this.cornerSize,e.x,e.y,!1,this),touchCorner:t.calcCornerCoords(s,this.touchCornerSize,e.x,e.y,!0,this)}}setCoords(){super.setCoords(),this.canvas&&(this.oCoords=this.calcOCoords())}forEachControl(t){for(const e in this.controls)t(this.controls[e],e,this)}drawSelectionBackground(t){if(!this.selectionBackgroundColor||this.canvas&&this.canvas._activeObject!==this)return;t.save();const e=this.getRelativeCenterPoint(),s=this._calculateCurrentDimensions(),i=this.getViewportTransform();t.translate(e.x,e.y),t.scale(1/i[0],1/i[3]),t.rotate(Rt(this.angle)),t.fillStyle=this.selectionBackgroundColor,t.fillRect(-s.x/2,-s.y/2,s.x,s.y),t.restore()}strokeBorders(t,e){t.strokeRect(-e.x/2,-e.y/2,e.x,e.y)}_drawBorders(t,e){let s=arguments.length>2&&arguments[2]!==void 0?arguments[2]:{};const i=T({hasControls:this.hasControls,borderColor:this.borderColor,borderDashArray:this.borderDashArray},s);t.save(),t.strokeStyle=i.borderColor,this._setLineDash(t,i.borderDashArray),this.strokeBorders(t,e),i.hasControls&&this.drawControlsConnectingLines(t,e),t.restore()}_renderControls(t){let e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};const{hasBorders:s,hasControls:i}=this,n=T({hasBorders:s,hasControls:i},e),r=this.getViewportTransform(),o=n.hasBorders,h=n.hasControls,c=Nt(r,this.calcTransformMatrix()),u=br(c);t.save(),t.translate(u.translateX,u.translateY),t.lineWidth=this.borderScaleFactor,this.group===this.parent&&(t.globalAlpha=this.isMoving?this.borderOpacityWhenMoving:1),this.flipX&&(u.angle-=180),t.rotate(Rt(this.group?u.angle:this.angle)),o&&this.drawBorders(t,u,e),h&&this.drawControls(t,e),t.restore()}drawBorders(t,e,s){let i;if(s&&s.forActiveSelection||this.group){const n=Qc(this.width,this.height,Ah(e)),r=this.isStrokeAccountedForInDimensions()?df:(this.strokeUniform?new D().scalarAdd(this.canvas?this.canvas.getZoom():1):new D(e.scaleX,e.scaleY)).scalarMultiply(this.strokeWidth);i=n.add(r).scalarAdd(this.borderScaleFactor).scalarAdd(2*this.padding)}else i=this._calculateCurrentDimensions().scalarAdd(this.borderScaleFactor);this._drawBorders(t,i,s)}drawControlsConnectingLines(t,e){let s=!1;t.beginPath(),this.forEachControl((i,n)=>{i.withConnection&&i.getVisibility(this,n)&&(s=!0,t.moveTo(i.x*e.x,i.y*e.y),t.lineTo(i.x*e.x+i.offsetX,i.y*e.y+i.offsetY))}),s&&t.stroke()}drawControls(t){let e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};t.save();const s=this.getCanvasRetinaScaling(),{cornerStrokeColor:i,cornerDashArray:n,cornerColor:r}=this,o=T({cornerStrokeColor:i,cornerDashArray:n,cornerColor:r},e);t.setTransform(s,0,0,s,0,0),t.strokeStyle=t.fillStyle=o.cornerColor,this.transparentCorners||(t.strokeStyle=o.cornerStrokeColor),this._setLineDash(t,o.cornerDashArray),this.forEachControl((h,c)=>{if(h.getVisibility(this,c)){const u=this.oCoords[c];h.render(t,u.x,u.y,o,this)}}),t.restore()}isControlVisible(t){return this.controls[t]&&this.controls[t].getVisibility(this,t)}setControlVisible(t,e){this._controlsVisibility||(this._controlsVisibility={}),this._controlsVisibility[t]=e}setControlsVisibility(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};Object.entries(t).forEach(e=>{let[s,i]=e;return this.setControlVisible(s,i)})}clearContextTop(t){if(!this.canvas)return;const e=this.canvas.contextTop;if(!e)return;const s=this.canvas.viewportTransform;e.save(),e.transform(s[0],s[1],s[2],s[3],s[4],s[5]),this.transform(e);const i=this.width+4,n=this.height+4;return e.clearRect(-i/2,-n/2,i,n),t||e.restore(),e}onDeselect(t){return!1}onSelect(t){return!1}shouldStartDragging(t){return!1}onDragStart(t){return!1}canDrop(t){return!1}renderDragSourceEffect(t){}renderDropTargetEffect(t){}}function Vm(a,t){return t.forEach(e=>{Object.getOwnPropertyNames(e.prototype).forEach(s=>{s!=="constructor"&&Object.defineProperty(a.prototype,s,Object.getOwnPropertyDescriptor(e.prototype,s)||Object.create(null))})}),a}A(Rh,"ownDefaults",{noScaleCache:!0,lockMovementX:!1,lockMovementY:!1,lockRotation:!1,lockScalingX:!1,lockScalingY:!1,lockSkewingX:!1,lockSkewingY:!1,lockScalingFlip:!1,cornerSize:13,touchCornerSize:24,transparentCorners:!0,cornerColor:"rgb(178,204,255)",cornerStrokeColor:"",cornerStyle:"rect",cornerDashArray:null,hasControls:!0,borderColor:"rgb(178,204,255)",borderDashArray:null,borderOpacityWhenMoving:.4,borderScaleFactor:1,hasBorders:!0,selectionBackgroundColor:"",selectable:!0,evented:!0,perPixelTargetFind:!1,activeOn:"down",hoverCursor:null,moveCursor:null});class pe extends Rh{}Vm(pe,[Sm]),N.setClass(pe),N.setClass(pe,"object");const Xm=(a,t,e,s)=>{const i=2*(s=Math.round(s))+1,{data:n}=a.getImageData(t-s,e-s,i,i);for(let r=3;r<n.length;r+=4)if(n[r]>0)return!1;return!0};class Wm{constructor(t){this.options=t,this.strokeProjectionMagnitude=this.options.strokeWidth/2,this.scale=new D(this.options.scaleX,this.options.scaleY),this.strokeUniformScalar=this.options.strokeUniform?new D(1/this.options.scaleX,1/this.options.scaleY):new D(1,1)}createSideVector(t,e){const s=tu(t,e);return this.options.strokeUniform?s.multiply(this.scale):s}projectOrthogonally(t,e,s){return this.applySkew(t.add(this.calcOrthogonalProjection(t,e,s)))}isSkewed(){return this.options.skewX!==0||this.options.skewY!==0}applySkew(t){const e=new D(t);return e.y+=e.x*Math.tan(Rt(this.options.skewY)),e.x+=e.y*Math.tan(Rt(this.options.skewX)),e}scaleUnitVector(t,e){return t.multiply(this.strokeUniformScalar).scalarMultiply(e)}}const u_=new D;class ea extends Wm{static getOrthogonalRotationFactor(t,e){const s=e?su(t,e):km(t);return Math.abs(s)<An?-1:1}constructor(t,e,s,i){super(i),A(this,"AB",void 0),A(this,"AC",void 0),A(this,"alpha",void 0),A(this,"bisector",void 0),this.A=new D(t),this.B=new D(e),this.C=new D(s),this.AB=this.createSideVector(this.A,this.B),this.AC=this.createSideVector(this.A,this.C),this.alpha=su(this.AB,this.AC),this.bisector=iu(kf(this.AB.eq(u_)?this.AC:this.AB,this.alpha/2))}calcOrthogonalProjection(t,e){let s=arguments.length>2&&arguments[2]!==void 0?arguments[2]:this.strokeProjectionMagnitude;const i=this.createSideVector(t,e),n=Mf(i),r=ea.getOrthogonalRotationFactor(n,this.bisector);return this.scaleUnitVector(n,s*r)}projectBevel(){const t=[];return(this.alpha%Ri==0?[this.B]:[this.B,this.C]).forEach(e=>{t.push(this.projectOrthogonally(this.A,e)),t.push(this.projectOrthogonally(this.A,e,-this.strokeProjectionMagnitude))}),t}projectMiter(){const t=[],e=Math.abs(this.alpha),s=1/Math.sin(e/2),i=this.scaleUnitVector(this.bisector,-this.strokeProjectionMagnitude*s),n=this.options.strokeUniform?eu(this.scaleUnitVector(this.bisector,this.options.strokeMiterLimit)):this.options.strokeMiterLimit;return eu(i)/this.strokeProjectionMagnitude<=n&&t.push(this.applySkew(this.A.add(i))),t.push(...this.projectBevel()),t}projectRoundNoSkew(t,e){const s=[],i=new D(ea.getOrthogonalRotationFactor(this.bisector),ea.getOrthogonalRotationFactor(new D(this.bisector.y,this.bisector.x)));return[new D(1,0).scalarMultiply(this.strokeProjectionMagnitude).multiply(this.strokeUniformScalar).multiply(i),new D(0,1).scalarMultiply(this.strokeProjectionMagnitude).multiply(this.strokeUniformScalar).multiply(i)].forEach(n=>{Pf(n,t,e)&&s.push(this.A.add(n))}),s}projectRoundWithSkew(t,e){const s=[],{skewX:i,skewY:n,scaleX:r,scaleY:o,strokeUniform:h}=this.options,c=new D(Math.tan(Rt(i)),Math.tan(Rt(n))),u=this.strokeProjectionMagnitude,d=h?u/o/Math.sqrt(1/o**2+1/r**2*c.y**2):u/Math.sqrt(1+c.y**2),f=new D(Math.sqrt(Math.max(u**2-d**2,0)),d),g=h?u/Math.sqrt(1+c.x**2*(1/o)**2/(1/r+1/r*c.x*c.y)**2):u/Math.sqrt(1+c.x**2/(1+c.x*c.y)**2),p=new D(g,Math.sqrt(Math.max(u**2-g**2,0)));return[p,p.scalarMultiply(-1),f,f.scalarMultiply(-1)].map(b=>this.applySkew(h?b.multiply(this.strokeUniformScalar):b)).forEach(b=>{Pf(b,t,e)&&s.push(this.applySkew(this.A).add(b))}),s}projectRound(){const t=[];t.push(...this.projectBevel());const e=this.alpha%Ri==0,s=this.applySkew(this.A),i=t[e?0:2].subtract(s),n=t[e?1:0].subtract(s),r=e?this.applySkew(this.AB.scalarMultiply(-1)):this.applySkew(this.bisector.multiply(this.strokeUniformScalar).scalarMultiply(-1)),o=Qo(i,r)>0,h=o?i:n,c=o?n:i;return this.isSkewed()?t.push(...this.projectRoundWithSkew(h,c)):t.push(...this.projectRoundNoSkew(h,c)),t}projectPoints(){switch(this.options.strokeLineJoin){case"miter":return this.projectMiter();case"round":return this.projectRound();default:return this.projectBevel()}}project(){return this.projectPoints().map(t=>({originPoint:this.A,projectedPoint:t,angle:this.alpha,bisector:this.bisector}))}}class Um extends Wm{constructor(t,e,s){super(s),this.A=new D(t),this.T=new D(e)}calcOrthogonalProjection(t,e){let s=arguments.length>2&&arguments[2]!==void 0?arguments[2]:this.strokeProjectionMagnitude;const i=this.createSideVector(t,e);return this.scaleUnitVector(Mf(i),s)}projectButt(){return[this.projectOrthogonally(this.A,this.T,this.strokeProjectionMagnitude),this.projectOrthogonally(this.A,this.T,-this.strokeProjectionMagnitude)]}projectRound(){const t=[];if(!this.isSkewed()&&this.A.eq(this.T)){const e=new D(1,1).scalarMultiply(this.strokeProjectionMagnitude).multiply(this.strokeUniformScalar);t.push(this.applySkew(this.A.add(e)),this.applySkew(this.A.subtract(e)))}else t.push(...new ea(this.A,this.T,this.T,this.options).projectRound());return t}projectSquare(){const t=[];if(this.A.eq(this.T)){const e=new D(1,1).scalarMultiply(this.strokeProjectionMagnitude).multiply(this.strokeUniformScalar);t.push(this.A.add(e),this.A.subtract(e))}else{const e=this.calcOrthogonalProjection(this.A,this.T,this.strokeProjectionMagnitude),s=this.scaleUnitVector(iu(this.createSideVector(this.A,this.T)),-this.strokeProjectionMagnitude),i=this.A.add(s);t.push(i.add(e),i.subtract(e))}return t.map(e=>this.applySkew(e))}projectPoints(){switch(this.options.strokeLineCap){case"round":return this.projectRound();case"square":return this.projectSquare();default:return this.projectButt()}}project(){return this.projectPoints().map(t=>({originPoint:this.A,projectedPoint:t}))}}const Ym=function(a,t){let e=arguments.length>2&&arguments[2]!==void 0&&arguments[2];const s=[];if(a.length===0)return s;const i=a.reduce((n,r)=>(n[n.length-1].eq(r)||n.push(new D(r)),n),[new D(a[0])]);if(i.length===1)e=!0;else if(!e){const n=i[0],r=((o,h)=>{for(let c=o.length-1;c>=0;c--)if(h(o[c],c,o))return c;return-1})(i,o=>!o.eq(n));i.splice(r+1)}return i.forEach((n,r,o)=>{let h,c;r===0?(c=o[1],h=e?n:o[o.length-1]):r===o.length-1?(h=o[r-1],c=e?n:o[0]):(h=o[r-1],c=o[r+1]),e&&o.length===1?s.push(...new Um(n,n,t).project()):!e||r!==0&&r!==o.length-1?s.push(...new ea(n,h,c,t).project()):s.push(...new Um(n,r===0?c:h,t).project())}),s},jf=a=>{const t={};return Object.keys(a).forEach(e=>{t[e]={},Object.keys(a[e]).forEach(s=>{t[e][s]=T({},a[e][s])})}),t},$m=a=>a.replace(/&/g,"&").replace(/"/g,""").replace(/'/g,"'").replace(/</g,"<").replace(/>/g,">"),au=a=>{const t=[];for(let e,s=0;s<a.length;s++)(e=d_(a,s))!==!1&&t.push(e);return t},d_=(a,t)=>{const e=a.charCodeAt(t);if(isNaN(e))return"";if(e<55296||e>57343)return a.charAt(t);if(55296<=e&&e<=56319){if(a.length<=t+1)throw"High surrogate without following low surrogate";const i=a.charCodeAt(t+1);if(56320>i||i>57343)throw"High surrogate without following low surrogate";return a.charAt(t)+a.charAt(t+1)}if(t===0)throw"Low surrogate without preceding high surrogate";const s=a.charCodeAt(t-1);if(55296>s||s>56319)throw"Low surrogate without preceding high surrogate";return!1};var f_=Object.freeze({__proto__:null,capitalize:function(a){let t=arguments.length>1&&arguments[1]!==void 0&&arguments[1];return"".concat(a.charAt(0).toUpperCase()).concat(t?a.slice(1):a.slice(1).toLowerCase())},escapeXml:$m,graphemeSplit:au});const hu=function(a,t){let e=arguments.length>2&&arguments[2]!==void 0&&arguments[2];return a.fill!==t.fill||a.stroke!==t.stroke||a.strokeWidth!==t.strokeWidth||a.fontSize!==t.fontSize||a.fontFamily!==t.fontFamily||a.fontWeight!==t.fontWeight||a.fontStyle!==t.fontStyle||a.textBackgroundColor!==t.textBackgroundColor||a.deltaY!==t.deltaY||e&&(a.overline!==t.overline||a.underline!==t.underline||a.linethrough!==t.linethrough)},qm=(a,t)=>{const e=t.split(`
|
|
38
|
+
`),s=[];let i=-1,n={};a=jf(a);for(let r=0;r<e.length;r++){const o=au(e[r]);if(a[r])for(let h=0;h<o.length;h++){i++;const c=a[r][h];c&&Object.keys(c).length>0&&(hu(n,c,!0)?s.push({start:i,end:i+1,style:c}):s[s.length-1].end++),n=c||{}}else i+=o.length,n={}}return s},Km=(a,t)=>{if(!Array.isArray(a))return jf(a);const e=t.split(lf),s={};let i=-1,n=0;for(let r=0;r<e.length;r++){const o=au(e[r]);for(let h=0;h<o.length;h++)i++,a[n]&&a[n].start<=i&&i<a[n].end&&(s[r]=s[r]||{},s[r][h]=T({},a[n].style),i===a[n].end-1&&n++)}return s},Mn=["display","transform",zt,"fill-opacity","fill-rule","opacity",Pe,"stroke-dasharray","stroke-linecap","stroke-dashoffset","stroke-linejoin","stroke-miterlimit","stroke-opacity","stroke-width","id","paint-order","vector-effect","instantiated_by_use","clip-path"];function Qm(a,t){const e=a.nodeName,s=a.getAttribute("class"),i=a.getAttribute("id"),n="(?![a-zA-Z\\-]+)";let r;if(r=new RegExp("^"+e,"i"),t=t.replace(r,""),i&&t.length&&(r=new RegExp("#"+i+n,"i"),t=t.replace(r,"")),s&&t.length){const o=s.split(" ");for(let h=o.length;h--;)r=new RegExp("\\."+o[h]+n,"i"),t=t.replace(r,"")}return t.length===0}function g_(a,t){let e=!0;const s=Qm(a,t.pop());return s&&t.length&&(e=function(i,n){let r,o=!0;for(;i.parentElement&&i.parentElement.nodeType===1&&n.length;)o&&(r=n.pop()),o=Qm(i=i.parentElement,r);return n.length===0}(a,t)),s&&e&&t.length===0}const p_=a=>{var t;return(t=Rv[a])!==null&&t!==void 0?t:a},m_=new RegExp("(".concat(Is,")"),"gi"),b_=a=>a.replace(m_," $1 ").replace(/,/gi," ").replace(/\s+/gi," ");var Jm,Zm,t0,e0,s0,i0,n0;const Oe="(".concat(Is,")"),y_=String.raw(Jm||(Jm=Cn(["(skewX)(",")"],["(skewX)\\(","\\)"])),Oe),v_=String.raw(Zm||(Zm=Cn(["(skewY)(",")"],["(skewY)\\(","\\)"])),Oe),__=String.raw(t0||(t0=Cn(["(rotate)(","(?: "," ",")?)"],["(rotate)\\(","(?: "," ",")?\\)"])),Oe,Oe,Oe),w_=String.raw(e0||(e0=Cn(["(scale)(","(?: ",")?)"],["(scale)\\(","(?: ",")?\\)"])),Oe,Oe),x_=String.raw(s0||(s0=Cn(["(translate)(","(?: ",")?)"],["(translate)\\(","(?: ",")?\\)"])),Oe,Oe),S_=String.raw(i0||(i0=Cn(["(matrix)("," "," "," "," "," ",")"],["(matrix)\\("," "," "," "," "," ","\\)"])),Oe,Oe,Oe,Oe,Oe,Oe),Bf="(?:".concat(S_,"|").concat(x_,"|").concat(__,"|").concat(w_,"|").concat(y_,"|").concat(v_,")"),C_="(?:".concat(Bf,"*)"),A_=String.raw(n0||(n0=Cn(["^s*(?:","?)s*$"],["^\\s*(?:","?)\\s*$"])),C_),T_=new RegExp(A_),E_=new RegExp(Bf),k_=new RegExp(Bf,"g");function lu(a){const t=[];if(!(a=b_(a).replace(/\s*([()])\s*/gi,"$1"))||a&&!T_.test(a))return[...Ee];for(const e of a.matchAll(k_)){const s=E_.exec(e[0]);if(!s)continue;let i=Ee;const n=s.filter(p=>!!p),[,r,...o]=n,[h,c,u,d,f,g]=o.map(p=>parseFloat(p));switch(r){case"translate":i=Yo(h,c);break;case cf:i=$o({angle:h},{x:c,y:u});break;case Vc:i=$c(h,c);break;case Xo:i=pf(h);break;case Wo:i=mf(h);break;case"matrix":i=[h,c,u,d,f,g]}t.push(i)}return Yc(t)}function M_(a,t,e,s){const i=Array.isArray(t);let n,r=t;if(a!==zt&&a!==Pe||t!==ke){if(a==="strokeUniform")return t==="non-scaling-stroke";if(a==="strokeDashArray")r=t===ke?null:t.replace(/,/g," ").split(/\s+/).map(parseFloat);else if(a==="transformMatrix")r=e&&e.transformMatrix?Nt(e.transformMatrix,lu(t)):lu(t);else if(a==="visible")r=t!==ke&&t!=="hidden",e&&e.visible===!1&&(r=!1);else if(a==="opacity")r=parseFloat(t),e&&e.opacity!==void 0&&(r*=e.opacity);else if(a==="textAnchor")r=t==="start"?dt:t==="end"?It:Q;else if(a==="charSpacing")n=De(t,s)/s*1e3;else if(a==="paintFirst"){const o=t.indexOf(zt),h=t.indexOf(Pe);r=zt,(o>-1&&h>-1&&h<o||o===-1&&h>-1)&&(r=Pe)}else{if(a==="href"||a==="xlink:href"||a==="font"||a==="id")return t;if(a==="imageSmoothing")return t==="optimizeQuality";n=i?t.map(De):De(t,s)}}else r="";return!i&&isNaN(n)?r:n}function P_(a,t){const e=a.match(Ov);if(!e)return;const s=e[1],i=e[3],n=e[4],r=e[5],o=e[6];s&&(t.fontStyle=s),i&&(t.fontWeight=isNaN(parseFloat(i))?i:parseFloat(i)),n&&(t.fontSize=De(n)),o&&(t.fontFamily=o),r&&(t.lineHeight=r==="normal"?1:r)}function Hf(a,t){a.replace(/;\s*$/,"").split(";").forEach(e=>{if(!e)return;const[s,i]=e.split(":");t[s.trim().toLowerCase()]=i.trim()})}function D_(a){const t={},e=a.getAttribute("style");return e&&(typeof e=="string"?Hf(e,t):function(s,i){Object.entries(s).forEach(n=>{let[r,o]=n;o!==void 0&&(i[r.toLowerCase()]=o)})}(e,t)),t}const O_={stroke:"strokeOpacity",fill:"fillOpacity"};function Ni(a,t,e){if(!a)return{};let s,i={},n=af;a.parentNode&&Am.test(a.parentNode.nodeName)&&(i=Ni(a.parentElement,t,e),i.fontSize&&(s=n=De(i.fontSize)));const r=T(T(T({},t.reduce((c,u)=>{const d=a.getAttribute(u);return d&&(c[u]=d),c},{})),function(c){let u=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},d={};for(const f in u)g_(c,f.split(" "))&&(d=T(T({},d),u[f]));return d}(a,e)),D_(a));r[Ef]&&a.setAttribute(Ef,r[Ef]),r[Tf]&&(s=De(r[Tf],n),r[Tf]="".concat(s));const o={};for(const c in r){const u=p_(c),d=M_(u,r[c],i,s);o[u]=d}o&&o.font&&P_(o.font,o);const h=T(T({},i),o);return Am.test(a.nodeName)?h:function(c){const u=pe.getDefaults();return Object.entries(O_).forEach(d=>{let[f,g]=d;if(c[g]===void 0||c[f]==="")return;if(c[f]===void 0){if(!u[f])return;c[f]=u[f]}if(c[f].indexOf("url(")===0)return;const p=new gt(c[f]);c[f]=p.setAlpha(At(p.getAlpha()*c[g],2)).toRgba()}),c}(h)}const R_=["left","top","width","height","visible"],r0=["rx","ry"];class oi extends pe{static getDefaults(){return T(T({},super.getDefaults()),oi.ownDefaults)}constructor(t){super(),Object.assign(this,oi.ownDefaults),this.setOptions(t),this._initRxRy()}_initRxRy(){const{rx:t,ry:e}=this;t&&!e?this.ry=t:e&&!t&&(this.rx=e)}_render(t){const{width:e,height:s}=this,i=-e/2,n=-s/2,r=this.rx?Math.min(this.rx,e/2):0,o=this.ry?Math.min(this.ry,s/2):0,h=r!==0||o!==0;t.beginPath(),t.moveTo(i+r,n),t.lineTo(i+e-r,n),h&&t.bezierCurveTo(i+e-Tn*r,n,i+e,n+Tn*o,i+e,n+o),t.lineTo(i+e,n+s-o),h&&t.bezierCurveTo(i+e,n+s-Tn*o,i+e-Tn*r,n+s,i+e-r,n+s),t.lineTo(i+r,n+s),h&&t.bezierCurveTo(i+Tn*r,n+s,i,n+s-Tn*o,i,n+s-o),t.lineTo(i,n+o),h&&t.bezierCurveTo(i,n+Tn*o,i+Tn*r,n,i+r,n),t.closePath(),this._renderPaintInOrder(t)}toObject(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:[];return super.toObject([...r0,...t])}_toSVG(){const{width:t,height:e,rx:s,ry:i}=this;return["<rect ","COMMON_PARTS",'x="'.concat(-t/2,'" y="').concat(-e/2,'" rx="').concat(s,'" ry="').concat(i,'" width="').concat(t,'" height="').concat(e,`" />
|
|
39
|
+
`)]}static async fromElement(t,e,s){const i=Ni(t,this.ATTRIBUTE_NAMES,s),{left:n=0,top:r=0,width:o=0,height:h=0,visible:c=!0}=i,u=Ct(i,R_);return new this(T(T(T({},e),u),{},{left:n,top:r,width:o,height:h,visible:!!(c&&o&&h)}))}}A(oi,"type","Rect"),A(oi,"cacheProperties",[...Fi,...r0]),A(oi,"ownDefaults",{rx:0,ry:0}),A(oi,"ATTRIBUTE_NAMES",[...Mn,"x","y","rx","ry","width","height"]),N.setClass(oi),N.setSVGClass(oi);const ji="initialization",cu="added",Gf="removed",uu="imperative",o0=(a,t)=>{const{strokeUniform:e,strokeWidth:s,width:i,height:n,group:r}=t,o=r&&r!==a?Dh(r.calcTransformMatrix(),a.calcTransformMatrix()):null,h=o?t.getRelativeCenterPoint().transform(o):t.getRelativeCenterPoint(),c=!t.isStrokeAccountedForInDimensions(),u=e&&c?bm(new D(s,s),void 0,a.calcTransformMatrix()):df,d=!e&&c?s:0,f=Qc(i+d,n+d,Yc([o,t.calcOwnMatrix()],!0)).add(u).scalarDivide(2);return[h.subtract(f),h.add(f)]};class du{calcLayoutResult(t,e){if(this.shouldPerformLayout(t))return this.calcBoundingBox(e,t)}shouldPerformLayout(t){let{type:e,prevStrategy:s,strategy:i}=t;return e===ji||e===uu||!!s&&i!==s}shouldLayoutClipPath(t){let{type:e,target:{clipPath:s}}=t;return e!==ji&&s&&!s.absolutePositioned}getInitialSize(t,e){return e.size}calcBoundingBox(t,e){const{type:s,target:i}=e;if(s===uu&&e.overrides)return e.overrides;if(t.length===0)return;const{left:n,top:r,width:o,height:h}=ri(t.map(d=>o0(i,d)).reduce((d,f)=>d.concat(f),[])),c=new D(o,h),u=new D(n,r).add(c.scalarDivide(2));if(s===ji){const d=this.getInitialSize(e,{size:c,center:u});return{center:u,relativeCorrection:new D(0,0),size:d}}return{center:u.transform(i.calcOwnMatrix()),size:c}}}A(du,"type","strategy");class zf extends du{shouldPerformLayout(t){return!0}}A(zf,"type","fit-content"),N.setClass(zf);const L_=["strategy"],F_=["target","strategy","bubbles","prevStrategy"],a0="layoutManager";class Lh{constructor(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:new zf;A(this,"strategy",void 0),this.strategy=t,this._subscriptions=new Map}performLayout(t){const e=T(T({bubbles:!0,strategy:this.strategy},t),{},{prevStrategy:this._prevLayoutStrategy,stopPropagation(){this.bubbles=!1}});this.onBeforeLayout(e);const s=this.getLayoutResult(e);s&&this.commitLayout(e,s),this.onAfterLayout(e,s),this._prevLayoutStrategy=e.strategy}attachHandlers(t,e){const{target:s}=e;return[Xc,Up,Sh,Yp,Gc,$p,zc,Sv,Cv].map(i=>t.on(i,n=>this.performLayout(i===Xc?{type:"object_modified",trigger:i,e:n,target:s}:{type:"object_modifying",trigger:i,e:n,target:s})))}subscribe(t,e){this.unsubscribe(t,e);const s=this.attachHandlers(t,e);this._subscriptions.set(t,s)}unsubscribe(t,e){(this._subscriptions.get(t)||[]).forEach(s=>s()),this._subscriptions.delete(t)}unsubscribeTargets(t){t.targets.forEach(e=>this.unsubscribe(e,t))}subscribeTargets(t){t.targets.forEach(e=>this.subscribe(e,t))}onBeforeLayout(t){const{target:e,type:s}=t,{canvas:i}=e;if(s===ji||s===cu?this.subscribeTargets(t):s===Gf&&this.unsubscribeTargets(t),e.fire("layout:before",{context:t}),i&&i.fire("object:layout:before",{target:e,context:t}),s===uu&&t.deep){const n=Ct(t,L_);e.forEachObject(r=>r.layoutManager&&r.layoutManager.performLayout(T(T({},n),{},{bubbles:!1,target:r})))}}getLayoutResult(t){const{target:e,strategy:s,type:i}=t,n=s.calcLayoutResult(t,e.getObjects());if(!n)return;const r=i===ji?new D:e.getRelativeCenterPoint(),{center:o,correction:h=new D,relativeCorrection:c=new D}=n,u=r.subtract(o).add(h).transform(i===ji?Ee:Xe(e.calcOwnMatrix()),!0).add(c);return{result:n,prevCenter:r,nextCenter:o,offset:u}}commitLayout(t,e){const{target:s}=t,{result:{size:i},nextCenter:n}=e;var r,o;s.set({width:i.x,height:i.y}),this.layoutObjects(t,e),t.type===ji?s.set({left:(r=t.x)!==null&&r!==void 0?r:n.x+i.x*Vt(s.originX),top:(o=t.y)!==null&&o!==void 0?o:n.y+i.y*Vt(s.originY)}):(s.setPositionByOrigin(n,Q,Q),s.setCoords(),s.set("dirty",!0))}layoutObjects(t,e){const{target:s}=t;s.forEachObject(i=>{i.group===s&&this.layoutObject(t,e,i)}),t.strategy.shouldLayoutClipPath(t)&&this.layoutObject(t,e,s.clipPath)}layoutObject(t,e,s){let{offset:i}=e;s.set({left:s.left+i.x,top:s.top+i.y})}onAfterLayout(t,e){const{target:s,strategy:i,bubbles:n,prevStrategy:r}=t,o=Ct(t,F_),{canvas:h}=s;s.fire("layout:after",{context:t,result:e}),h&&h.fire("object:layout:after",{context:t,result:e,target:s});const c=s.parent;n&&c!=null&&c.layoutManager&&((o.path||(o.path=[])).push(s),c.layoutManager.performLayout(T(T({},o),{},{target:c}))),s.set("dirty",!0)}dispose(){const{_subscriptions:t}=this;t.forEach(e=>e.forEach(s=>s())),t.clear()}toObject(){return{type:a0,strategy:this.strategy.constructor.type}}toJSON(){return this.toObject()}}N.setClass(Lh,a0);const I_=["type","objects","layoutManager"];class N_ extends Lh{performLayout(){}}class ai extends qp(pe){static getDefaults(){return T(T({},super.getDefaults()),ai.ownDefaults)}constructor(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:[],e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};super(),A(this,"_activeObjects",[]),A(this,"__objectSelectionTracker",void 0),A(this,"__objectSelectionDisposer",void 0),Object.assign(this,ai.ownDefaults),this.setOptions(e),this.groupInit(t,e)}groupInit(t,e){var s;this._objects=[...t],this.__objectSelectionTracker=this.__objectSelectionMonitor.bind(this,!0),this.__objectSelectionDisposer=this.__objectSelectionMonitor.bind(this,!1),this.forEachObject(i=>{this.enterGroup(i,!1)}),this.layoutManager=(s=e.layoutManager)!==null&&s!==void 0?s:new Lh,this.layoutManager.performLayout({type:ji,target:this,targets:[...t],x:e.left,y:e.top})}canEnterGroup(t){return t===this||this.isDescendantOf(t)?(Oi("error","Group: circular object trees are not supported, this call has no effect"),!1):this._objects.indexOf(t)===-1||(Oi("error","Group: duplicate objects are not supported inside group, this call has no effect"),!1)}_filterObjectsBeforeEnteringGroup(t){return t.filter((e,s,i)=>this.canEnterGroup(e)&&i.indexOf(e)===s)}add(){for(var t=arguments.length,e=new Array(t),s=0;s<t;s++)e[s]=arguments[s];const i=this._filterObjectsBeforeEnteringGroup(e),n=super.add(...i);return this._onAfterObjectsChange(cu,i),n}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=this._filterObjectsBeforeEnteringGroup(s),r=super.insertAt(t,...n);return this._onAfterObjectsChange(cu,n),r}remove(){const t=super.remove(...arguments);return this._onAfterObjectsChange(Gf,t),t}_onObjectAdded(t){this.enterGroup(t,!0),this.fire("object:added",{target:t}),t.fire("added",{target:this})}_onObjectRemoved(t,e){this.exitGroup(t,e),this.fire("object:removed",{target:t}),t.fire("removed",{target:this})}_onAfterObjectsChange(t,e){this.layoutManager.performLayout({type:t,targets:e,target:this})}_onStackOrderChanged(){this._set("dirty",!0)}_set(t,e){const s=this[t];return super._set(t,e),t==="canvas"&&s!==e&&(this._objects||[]).forEach(i=>{i._set(t,e)}),this}_shouldSetNestedCoords(){return this.subTargetCheck}removeAll(){return this._activeObjects=[],this.remove(...this._objects)}__objectSelectionMonitor(t,e){let{target:s}=e;const i=this._activeObjects;if(t)i.push(s),this._set("dirty",!0);else if(i.length>0){const n=i.indexOf(s);n>-1&&(i.splice(n,1),this._set("dirty",!0))}}_watchObject(t,e){t&&this._watchObject(!1,e),t?(e.on("selected",this.__objectSelectionTracker),e.on("deselected",this.__objectSelectionDisposer)):(e.off("selected",this.__objectSelectionTracker),e.off("deselected",this.__objectSelectionDisposer))}enterGroup(t,e){t.group&&t.group.remove(t),t._set("parent",this),this._enterGroup(t,e)}_enterGroup(t,e){e&&Ko(t,Nt(Xe(this.calcTransformMatrix()),t.calcTransformMatrix())),this._shouldSetNestedCoords()&&t.setCoords(),t._set("group",this),t._set("canvas",this.canvas),this._watchObject(!0,t);const s=this.canvas&&this.canvas.getActiveObject&&this.canvas.getActiveObject();s&&(s===t||t.isDescendantOf(s))&&this._activeObjects.push(t)}exitGroup(t,e){this._exitGroup(t,e),t._set("parent",void 0),t._set("canvas",void 0)}_exitGroup(t,e){t._set("group",void 0),e||(Ko(t,Nt(this.calcTransformMatrix(),t.calcTransformMatrix())),t.setCoords()),this._watchObject(!1,t);const s=this._activeObjects.length>0?this._activeObjects.indexOf(t):-1;s>-1&&this._activeObjects.splice(s,1)}shouldCache(){const t=pe.prototype.shouldCache.call(this);if(t){for(let e=0;e<this._objects.length;e++)if(this._objects[e].willDrawShadow())return this.ownCaching=!1,!1}return t}willDrawShadow(){if(super.willDrawShadow())return!0;for(let t=0;t<this._objects.length;t++)if(this._objects[t].willDrawShadow())return!0;return!1}isOnACache(){return this.ownCaching||!!this.parent&&this.parent.isOnACache()}drawObject(t,e,s){this._renderBackground(t);for(let n=0;n<this._objects.length;n++){var i;const r=this._objects[n];(i=this.canvas)!==null&&i!==void 0&&i.preserveObjectStacking&&r.group!==this?(t.save(),t.transform(...Xe(this.calcTransformMatrix())),r.render(t),t.restore()):r.group===this&&r.render(t)}this._drawClipPath(t,this.clipPath,s)}setCoords(){super.setCoords(),this._shouldSetNestedCoords()&&this.forEachObject(t=>t.setCoords())}triggerLayout(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};this.layoutManager.performLayout(T({target:this,type:uu},t))}render(t){this._transformDone=!0,super.render(t),this._transformDone=!1}__serializeObjects(t,e){const s=this.includeDefaultValues;return this._objects.filter(function(i){return!i.excludeFromExport}).map(function(i){const n=i.includeDefaultValues;i.includeDefaultValues=s;const r=i[t||"toObject"](e);return i.includeDefaultValues=n,r})}toObject(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:[];const e=this.layoutManager.toObject();return T(T(T({},super.toObject(["subTargetCheck","interactive",...t])),e.strategy!=="fit-content"||this.includeDefaultValues?{layoutManager:e}:{}),{},{objects:this.__serializeObjects("toObject",t)})}toString(){return"#<Group: (".concat(this.complexity(),")>")}dispose(){this.layoutManager.unsubscribeTargets({targets:this.getObjects(),target:this}),this._activeObjects=[],this.forEachObject(t=>{this._watchObject(!1,t),t.dispose()}),super.dispose()}_createSVGBgRect(t){if(!this.backgroundColor)return"";const e=oi.prototype._toSVG.call(this),s=e.indexOf("COMMON_PARTS");e[s]='for="group" ';const i=e.join("");return t?t(i):i}_toSVG(t){const e=["<g ","COMMON_PARTS",` >
|
|
40
40
|
`],s=this._createSVGBgRect(t);s&&e.push(" ",s);for(let i=0;i<this._objects.length;i++)e.push(" ",this._objects[i].toSVG(t));return e.push(`</g>
|
|
41
|
-
`),e}getSvgStyles(){const t=this.opacity!==void 0&&this.opacity!==1?"opacity: ".concat(this.opacity,";"):"",e=this.visible?"":" visibility: hidden;";return[t,this.getSvgFilter(),e].join("")}toClipPathSVG(t){const e=[],s=this._createSVGBgRect(t);s&&e.push(" ",s);for(let i=0;i<this._objects.length;i++)e.push(" ",this._objects[i].toClipPathSVG(t));return this._createBaseClipPathSVGMarkup(e,{reviver:t})}static fromObject(t,e){let{type:s,objects:i=[],layoutManager:n}=t,r=Ct(t,R_);return Promise.all([qo(i,e),Eh(r,e)]).then(o=>{let[h,c]=o;const u=new this(h,T(T(T({},r),c),{},{layoutManager:new L_}));if(n){const d=H.getClass(n.type),f=H.getClass(n.strategy);u.layoutManager=new d(new f)}else u.layoutManager=new Lh;return u.layoutManager.subscribeTargets({type:ji,target:u,targets:u.getObjects()}),u.setCoords(),u})}}A(ai,"type","Group"),A(ai,"ownDefaults",{strokeWidth:0,subTargetCheck:!1,interactive:!1}),H.setClass(ai);const h0=(a,t)=>Math.min(t.width/a.width,t.height/a.height),l0=(a,t)=>Math.max(t.width/a.width,t.height/a.height),Vf="\\s*,?\\s*",Fh="".concat(Vf,"(").concat(Is,")"),F_="".concat(Fh).concat(Fh).concat(Fh).concat(Vf,"([01])").concat(Vf,"([01])").concat(Fh).concat(Fh),I_={m:"l",M:"L"},N_=(a,t,e,s,i,n,r,o,h,c,u)=>{const d=Ds(a),f=Os(a),g=Ds(t),p=Os(t),b=e*i*g-s*n*p+r,_=s*i*g+e*n*p+o;return["C",c+h*(-e*i*f-s*n*d),u+h*(-s*i*f+e*n*d),b+h*(e*i*p+s*n*g),_+h*(s*i*p-e*n*g),b,_]},c0=(a,t,e,s)=>{const i=Math.atan2(t,a),n=Math.atan2(s,e);return n>=i?n-i:2*Math.PI-(i-n)};function Xf(a,t,e,s,i,n,r,o){let h;if(ht.cachesBoundsOfCurve&&(h=[...arguments].join(),xh.boundsOfCurveCache[h]))return xh.boundsOfCurveCache[h];const c=Math.sqrt,u=Math.abs,d=[],f=[[0,0],[0,0]];let g=6*a-12*e+6*i,p=-3*a+9*e-9*i+3*r,b=3*e-3*a;for(let S=0;S<2;++S){if(S>0&&(g=6*t-12*s+6*n,p=-3*t+9*s-9*n+3*o,b=3*s-3*t),u(p)<1e-12){if(u(g)<1e-12)continue;const R=-b/g;0<R&&R<1&&d.push(R);continue}const E=g*g-4*b*p;if(E<0)continue;const k=c(E),M=(-g+k)/(2*p);0<M&&M<1&&d.push(M);const D=(-g-k)/(2*p);0<D&&D<1&&d.push(D)}let _=d.length;const v=_,x=d0(a,t,e,s,i,n,r,o);for(;_--;){const{x:S,y:E}=x(d[_]);f[0][_]=S,f[1][_]=E}f[0][v]=a,f[1][v]=t,f[0][v+1]=r,f[1][v+1]=o;const C=[new P(Math.min(...f[0]),Math.min(...f[1])),new P(Math.max(...f[0]),Math.max(...f[1]))];return ht.cachesBoundsOfCurve&&(xh.boundsOfCurveCache[h]=C),C}const j_=(a,t,e)=>{let[s,i,n,r,o,h,c,u]=e;const d=((f,g,p,b,_,v,x)=>{if(p===0||b===0)return[];let C=0,S=0,E=0;const k=Math.PI,M=x*of,D=Os(M),R=Ds(M),B=.5*(-R*f-D*g),O=.5*(-R*g+D*f),F=p**2,L=b**2,N=O**2,Y=B**2,I=F*L-F*N-L*Y;let X=Math.abs(p),rt=Math.abs(b);if(I<0){const Pi=Math.sqrt(1-I/(F*L));X*=Pi,rt*=Pi}else E=(_===v?-1:1)*Math.sqrt(I/(F*N+L*Y));const Gt=E*X*O/rt,te=-E*rt*B/X,fe=R*Gt-D*te+.5*f,Yt=D*Gt+R*te+.5*g;let St=c0(1,0,(B-Gt)/X,(O-te)/rt),He=c0((B-Gt)/X,(O-te)/rt,(-B-Gt)/X,(-O-te)/rt);v===0&&He>0?He-=2*k:v===1&&He<0&&(He+=2*k);const Mi=Math.ceil(Math.abs(He/k*2)),Ft=[],ft=He/Mi,fr=8/3*Math.sin(ft/4)*Math.sin(ft/4)/Math.sin(ft/2);let ph=St+ft;for(let Pi=0;Pi<Mi;Pi++)Ft[Pi]=N_(St,ph,R,D,X,rt,fe,Yt,fr,C,S),C=Ft[Pi][5],S=Ft[Pi][6],St=ph,ph+=ft;return Ft})(c-a,u-t,i,n,o,h,r);for(let f=0,g=d.length;f<g;f++)d[f][1]+=a,d[f][2]+=t,d[f][3]+=a,d[f][4]+=t,d[f][5]+=a,d[f][6]+=t;return d},u0=a=>{let t=0,e=0,s=0,i=0;const n=[];let r,o=0,h=0;for(const c of a){const u=[...c];let d;switch(u[0]){case"l":u[1]+=t,u[2]+=e;case"L":t=u[1],e=u[2],d=["L",t,e];break;case"h":u[1]+=t;case"H":t=u[1],d=["L",t,e];break;case"v":u[1]+=e;case"V":e=u[1],d=["L",t,e];break;case"m":u[1]+=t,u[2]+=e;case"M":t=u[1],e=u[2],s=u[1],i=u[2],d=["M",t,e];break;case"c":u[1]+=t,u[2]+=e,u[3]+=t,u[4]+=e,u[5]+=t,u[6]+=e;case"C":o=u[3],h=u[4],t=u[5],e=u[6],d=["C",u[1],u[2],o,h,t,e];break;case"s":u[1]+=t,u[2]+=e,u[3]+=t,u[4]+=e;case"S":r==="C"?(o=2*t-o,h=2*e-h):(o=t,h=e),t=u[3],e=u[4],d=["C",o,h,u[1],u[2],t,e],o=d[3],h=d[4];break;case"q":u[1]+=t,u[2]+=e,u[3]+=t,u[4]+=e;case"Q":o=u[1],h=u[2],t=u[3],e=u[4],d=["Q",o,h,t,e];break;case"t":u[1]+=t,u[2]+=e;case"T":r==="Q"?(o=2*t-o,h=2*e-h):(o=t,h=e),t=u[1],e=u[2],d=["Q",o,h,t,e];break;case"a":u[6]+=t,u[7]+=e;case"A":j_(t,e,u).forEach(f=>n.push(f)),t=u[6],e=u[7];break;case"z":case"Z":t=s,e=i,d=["Z"]}d?(n.push(d),r=d[0]):r=""}return n},fu=(a,t,e,s)=>Math.sqrt((e-a)**2+(s-t)**2),d0=(a,t,e,s,i,n,r,o)=>h=>{const c=h**3,u=(g=>3*g**2*(1-g))(h),d=(g=>3*g*(1-g)**2)(h),f=(g=>(1-g)**3)(h);return new P(r*c+i*u+e*d+a*f,o*c+n*u+s*d+t*f)},f0=a=>a**2,g0=a=>2*a*(1-a),p0=a=>(1-a)**2,B_=(a,t,e,s,i,n,r,o)=>h=>{const c=f0(h),u=g0(h),d=p0(h),f=3*(d*(e-a)+u*(i-e)+c*(r-i)),g=3*(d*(s-t)+u*(n-s)+c*(o-n));return Math.atan2(g,f)},H_=(a,t,e,s,i,n)=>r=>{const o=f0(r),h=g0(r),c=p0(r);return new P(i*o+e*h+a*c,n*o+s*h+t*c)},G_=(a,t,e,s,i,n)=>r=>{const o=1-r,h=2*(o*(e-a)+r*(i-e)),c=2*(o*(s-t)+r*(n-s));return Math.atan2(c,h)},m0=(a,t,e)=>{let s=new P(t,e),i=0;for(let n=1;n<=100;n+=1){const r=a(n/100);i+=fu(s.x,s.y,r.x,r.y),s=r}return i},z_=(a,t)=>{let e,s=0,i=0,n={x:a.x,y:a.y},r=T({},n),o=.01,h=0;const c=a.iterator,u=a.angleFinder;for(;i<t&&o>1e-4;)r=c(s),h=s,e=fu(n.x,n.y,r.x,r.y),e+i>t?(s-=o,o/=2):(n=r,s+=o,i+=e);return T(T({},r),{},{angle:u(h)})},Wf=a=>{let t,e,s=0,i=0,n=0,r=0,o=0;const h=[];for(const c of a){const u={x:i,y:n,command:c[0],length:0};switch(c[0]){case"M":e=u,e.x=r=i=c[1],e.y=o=n=c[2];break;case"L":e=u,e.length=fu(i,n,c[1],c[2]),i=c[1],n=c[2];break;case"C":t=d0(i,n,c[1],c[2],c[3],c[4],c[5],c[6]),e=u,e.iterator=t,e.angleFinder=B_(i,n,c[1],c[2],c[3],c[4],c[5],c[6]),e.length=m0(t,i,n),i=c[5],n=c[6];break;case"Q":t=H_(i,n,c[1],c[2],c[3],c[4]),e=u,e.iterator=t,e.angleFinder=G_(i,n,c[1],c[2],c[3],c[4]),e.length=m0(t,i,n),i=c[3],n=c[4];break;case"Z":e=u,e.destX=r,e.destY=o,e.length=fu(i,n,r,o),i=r,n=o}s+=e.length,h.push(e)}return h.push({length:s,x:i,y:n}),h},b0=function(a,t){let e=arguments.length>2&&arguments[2]!==void 0?arguments[2]:Wf(a),s=0;for(;t-e[s].length>0&&s<e.length-2;)t-=e[s].length,s++;const i=e[s],n=t/i.length,r=a[s];switch(i.command){case"M":return{x:i.x,y:i.y,angle:0};case"Z":return T(T({},new P(i.x,i.y).lerp(new P(i.destX,i.destY),n)),{},{angle:Math.atan2(i.destY-i.y,i.destX-i.x)});case"L":return T(T({},new P(i.x,i.y).lerp(new P(r[1],r[2]),n)),{},{angle:Math.atan2(r[2]-i.y,r[1]-i.x)});case"C":case"Q":return z_(i,t)}},V_=new RegExp("[mzlhvcsqta][^mzlhvcsqta]*","gi"),y0=new RegExp(F_,"g"),X_=new RegExp(Is,"gi"),W_={m:2,l:2,h:1,v:1,c:6,s:4,q:4,t:2,a:7},v0=a=>{var t;const e=[],s=(t=a.match(V_))!==null&&t!==void 0?t:[];for(const i of s){const n=i[0];if(n==="z"||n==="Z"){e.push([n]);continue}const r=W_[n.toLowerCase()];let o=[];if(n==="a"||n==="A"){y0.lastIndex=0;for(let h=null;h=y0.exec(i);)o.push(...h.slice(1))}else o=i.match(X_)||[];for(let h=0;h<o.length;h+=r){const c=new Array(r),u=I_[n];c[0]=h>0&&u?u:n;for(let d=0;d<r;d++)c[d+1]=parseFloat(o[h+d]);e.push(c)}}return e},U_=function(a){let t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:0,e=new P(a[0]),s=new P(a[1]),i=1,n=0;const r=[],o=a.length,h=o>2;let c;for(h&&(i=a[2].x<s.x?-1:a[2].x===s.x?0:1,n=a[2].y<s.y?-1:a[2].y===s.y?0:1),r.push(["M",e.x-i*t,e.y-n*t]),c=1;c<o;c++){if(!e.eq(s)){const u=e.midPointFrom(s);r.push(["Q",e.x,e.y,u.x,u.y])}e=a[c],c+1<a.length&&(s=a[c+1])}return h&&(i=e.x>a[c-2].x?1:e.x===a[c-2].x?0:-1,n=e.y>a[c-2].y?1:e.y===a[c-2].y?0:-1),r.push(["L",e.x+i*t,e.y+n*t]),r},_0=(a,t)=>a.map(e=>e.map((s,i)=>i===0||t===void 0?s:At(s,t)).join(" ")).join(" ");function gu(a,t){const e=a.style;e&&t&&(typeof t=="string"?e.cssText+=";"+t:Object.entries(t).forEach(s=>{let[i,n]=s;return e.setProperty(i,n)}))}const Y_=(a,t)=>Math.floor(Math.random()*(t-a+1))+a;function w0(a){let t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};const e=t.onComplete||pr,s=new(Hc()).XMLHttpRequest,i=t.signal,n=function(){s.abort()},r=function(){i&&i.removeEventListener("abort",n),s.onerror=s.ontimeout=pr};if(i&&i.aborted)throw new nf("request");return i&&i.addEventListener("abort",n,{once:!0}),s.onreadystatechange=function(){s.readyState===4&&(r(),e(s),s.onreadystatechange=pr)},s.onerror=s.ontimeout=r,s.open("get",a,!0),s.send(),s}const pu=(a,t)=>{let e=a._findCenterFromElement();a.transformMatrix&&((s=>{if(s.transformMatrix){const{scaleX:i,scaleY:n,angle:r,skewX:o}=br(s.transformMatrix);s.flipX=!1,s.flipY=!1,s.set(Me,i),s.set(Je,n),s.angle=r,s.skewX=o,s.skewY=0}})(a),e=e.transform(a.transformMatrix)),delete a.transformMatrix,t&&(a.scaleX*=t.scaleX,a.scaleY*=t.scaleY,a.cropX=t.cropX,a.cropY=t.cropY,e.x+=t.offsetLeft,e.y+=t.offsetTop,a.width=t.width,a.height=t.height),a.setPositionByOrigin(e,J,J)};var $_=Object.freeze({__proto__:null,addTransformToObject:pm,animate:Ff,animateColor:Fm,applyTransformToObject:Ko,calcAngleBetweenVectors:su,calcDimensionsMatrix:Ah,calcPlaneChangeMatrix:Dh,calcVectorRotation:km,cancelAnimFrame:Qp,capValue:wr,composeMatrix:sm,copyCanvasElement:a=>{var t;const e=Rs(a);return(t=e.getContext("2d"))===null||t===void 0||t.drawImage(a,0,0),e},cos:Ds,createCanvasElement:ms,createImage:Jp,createRotateMatrix:$o,createScaleMatrix:$c,createSkewXMatrix:pf,createSkewYMatrix:mf,createTranslateMatrix:Yo,createVector:tu,crossProduct:Qo,degreesToRadians:Rt,dotProduct:Mm,ease:Iv,enlivenObjectEnlivables:Eh,enlivenObjects:qo,findScaleToCover:l0,findScaleToFit:h0,getBoundsOfCurve:Xf,getOrthonormalVector:Mf,getPathSegmentsInfo:Wf,getPointOnPath:b0,getPointer:gm,getRandomInt:Y_,getRegularPolygonPath:(a,t)=>{const e=2*Math.PI/a;let s=-An;a%2==0&&(s+=e/2);const i=new Array(a+1);for(let n=0;n<a;n++){const r=n*e+s,{x:o,y:h}=new P(Ds(r),Os(r)).scalarMultiply(t);i[n]=[n===0?"M":"L",o,h]}return i[a]=["Z"],i},getSmoothPathFromPoints:U_,getSvgAttributes:a=>{const t=["instantiated_by_use","style","id","class"];switch(a){case"linearGradient":return t.concat(["x1","y1","x2","y2","gradientUnits","gradientTransform"]);case"radialGradient":return t.concat(["gradientUnits","gradientTransform","cx","cy","r","fx","fy","fr"]);case"stop":return t.concat(["offset","stop-color","stop-opacity"])}return t},getUnitVector:iu,groupSVGElements:(a,t)=>a&&a.length===1?a[0]:new ai(a,t),hasStyleChanged:hu,invertTransform:Xe,isBetweenVectors:Pf,isIdentityMatrix:Zp,isTouchEvent:Kc,isTransparent:Xm,joinPath:_0,loadImage:Th,magnitude:eu,makeBoundingBoxFromPoints:ri,makePathSimpler:u0,matrixToSVG:kh,mergeClipPaths:(a,t)=>{var e;let s=a,i=t;s.inverted&&!i.inverted&&(s=t,i=a),Sf(i,(e=i.group)===null||e===void 0?void 0:e.calcTransformMatrix(),s.calcTransformMatrix());const n=s.inverted&&i.inverted;return n&&(s.inverted=i.inverted=!1),new ai([s],{clipPath:i,inverted:n})},multiplyTransformMatrices:Nt,multiplyTransformMatrixArray:Yc,parsePath:v0,parsePreserveAspectRatioAttribute:vf,parseUnit:De,pick:yr,projectStrokeOnPoints:Ym,qrDecompose:br,radiansToDegrees:kn,removeFromArray:mr,removeTransformFromObject:(a,t)=>{const e=Xe(t),s=Nt(e,a.calcOwnMatrix());Ko(a,s)},removeTransformMatrixForSvgParsing:pu,request:w0,requestAnimFrame:Ch,resetObjectTransform:mm,rotatePoint:(a,t,e)=>a.rotate(e,t),rotateVector:kf,saveObjectTransform:xf,sendObjectToPlane:Sf,sendPointToPlane:_r,sendVectorToPlane:bm,setStyle:gu,sin:Os,sizeAfterTransform:Qc,string:c_,stylesFromArray:Km,stylesToArray:qm,toBlob:gf,toDataURL:ff,toFixed:At,transformPath:(a,t,e)=>(e&&(t=Nt(t,[1,0,0,1,-e.x,-e.y])),a.map(s=>{const i=[...s];for(let n=1;n<s.length-1;n+=2){const{x:r,y:o}=ge({x:s[n],y:s[n+1]},t);i[n]=r,i[n+1]=o}return i})),transformPoint:ge});class q_ extends fm{constructor(t){let{allowTouchScrolling:e=!1,containerClass:s=""}=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};super(t),A(this,"upper",void 0),A(this,"container",void 0);const{el:i}=this.lower,n=this.createUpperCanvas();this.upper={el:n,ctx:n.getContext("2d")},this.applyCanvasStyle(i,{allowTouchScrolling:e}),this.applyCanvasStyle(n,{allowTouchScrolling:e,styles:{position:"absolute",left:"0",top:"0"}});const r=this.createContainerElement();r.classList.add(s),i.parentNode&&i.parentNode.replaceChild(r,i),r.append(i,n),this.container=r}createUpperCanvas(){const{el:t}=this.lower,e=ms();return e.className=t.className,e.classList.remove("lower-canvas"),e.classList.add("upper-canvas"),e.setAttribute("data-fabric","top"),e.style.cssText=t.style.cssText,e.setAttribute("draggable","true"),e}createContainerElement(){const t=Vo().createElement("div");return t.setAttribute("data-fabric","wrapper"),gu(t,{position:"relative"}),dm(t),t}applyCanvasStyle(t,e){const{styles:s,allowTouchScrolling:i}=e;gu(t,T(T({},s),{},{"touch-action":i?"manipulation":ke})),dm(t)}setDimensions(t,e){super.setDimensions(t,e);const{el:s,ctx:i}=this.upper;um(s,i,t,e)}setCSSDimensions(t){super.setCSSDimensions(t),_f(this.upper.el,t),_f(this.container,t)}cleanupDOM(t){const e=this.container,{el:s}=this.lower,{el:i}=this.upper;super.cleanupDOM(t),e.removeChild(i),e.removeChild(s),e.parentNode&&e.parentNode.replaceChild(s,e)}dispose(){super.dispose(),ni().dispose(this.upper.el),delete this.upper,delete this.container}}class mu extends Ph{constructor(){super(...arguments),A(this,"targets",[]),A(this,"_hoveredTargets",[]),A(this,"_objectsToRender",void 0),A(this,"_currentTransform",null),A(this,"_groupSelector",null),A(this,"contextTopDirty",!1)}static getDefaults(){return T(T({},super.getDefaults()),mu.ownDefaults)}get upperCanvasEl(){var t;return(t=this.elements.upper)===null||t===void 0?void 0:t.el}get contextTop(){var t;return(t=this.elements.upper)===null||t===void 0?void 0:t.ctx}get wrapperEl(){return this.elements.container}initElements(t){this.elements=new q_(t,{allowTouchScrolling:this.allowTouchScrolling,containerClass:this.containerClass}),this._createCacheCanvas()}_onObjectAdded(t){this._objectsToRender=void 0,super._onObjectAdded(t)}_onObjectRemoved(t){this._objectsToRender=void 0,t===this._activeObject&&(this.fire("before:selection:cleared",{deselected:[t]}),this._discardActiveObject(),this.fire("selection:cleared",{deselected:[t]}),t.fire("deselected",{target:t})),t===this._hoveredTarget&&(this._hoveredTarget=void 0,this._hoveredTargets=[]),super._onObjectRemoved(t)}_onStackOrderChanged(){this._objectsToRender=void 0,super._onStackOrderChanged()}_chooseObjectsToRender(){const t=this._activeObject;return!this.preserveObjectStacking&&t?this._objects.filter(e=>!e.group&&e!==t).concat(t):this._objects}renderAll(){this.cancelRequestedRender(),this.destroyed||(!this.contextTopDirty||this._groupSelector||this.isDrawingMode||(this.clearContext(this.contextTop),this.contextTopDirty=!1),this.hasLostContext&&(this.renderTopLayer(this.contextTop),this.hasLostContext=!1),!this._objectsToRender&&(this._objectsToRender=this._chooseObjectsToRender()),this.renderCanvas(this.getContext(),this._objectsToRender))}renderTopLayer(t){t.save(),this.isDrawingMode&&this._isCurrentlyDrawing&&(this.freeDrawingBrush&&this.freeDrawingBrush._render(),this.contextTopDirty=!0),this.selection&&this._groupSelector&&(this._drawSelection(t),this.contextTopDirty=!0),t.restore()}renderTop(){const t=this.contextTop;this.clearContext(t),this.renderTopLayer(t),this.fire("after:render",{ctx:t})}setTargetFindTolerance(t){t=Math.round(t),this.targetFindTolerance=t;const e=this.getRetinaScaling(),s=Math.ceil((2*t+1)*e);this.pixelFindCanvasEl.width=this.pixelFindCanvasEl.height=s,this.pixelFindContext.scale(e,e)}isTargetTransparent(t,e,s){const i=this.targetFindTolerance,n=this.pixelFindContext;this.clearContext(n),n.save(),n.translate(-e+i,-s+i),n.transform(...this.viewportTransform);const r=t.selectionBackgroundColor;t.selectionBackgroundColor="",t.render(n),t.selectionBackgroundColor=r,n.restore();const o=Math.round(i*this.getRetinaScaling());return Xm(n,o,o,o)}_isSelectionKeyPressed(t){const e=this.selectionKey;return!!e&&(Array.isArray(e)?!!e.find(s=>!!s&&t[s]===!0):t[e])}_shouldClearSelection(t,e){const s=this.getActiveObjects(),i=this._activeObject;return!!(!e||e&&i&&s.length>1&&s.indexOf(e)===-1&&i!==e&&!this._isSelectionKeyPressed(t)||e&&!e.evented||e&&!e.selectable&&i&&i!==e)}_shouldCenterTransform(t,e,s){if(!t)return;let i;return e===Vc||e===Me||e===Je||e===Sh?i=this.centeredScaling||t.centeredScaling:e===cf&&(i=this.centeredRotation||t.centeredRotation),i?!s:s}_getOriginFromCorner(t,e){const s={x:t.originX,y:t.originY};return e&&(["ml","tl","bl"].includes(e)?s.x=It:["mr","tr","br"].includes(e)&&(s.x=dt),["tl","mt","tr"].includes(e)?s.y=hf:["bl","mb","br"].includes(e)&&(s.y=Ve)),s}_setupCurrentTransform(t,e,s){var i;const n=e.group?_r(this.getScenePoint(t),void 0,e.group.calcTransformMatrix()):this.getScenePoint(t),{key:r="",control:o}=e.getActiveControl()||{},h=s&&o?(i=o.getActionHandler(t,e,o))===null||i===void 0?void 0:i.bind(o):kv,c=((g,p,b,_)=>{if(!p||!g)return"drag";const v=_.controls[p];return v.getActionName(b,v,_)})(s,r,t,e),u=t[this.centeredKey],d=this._shouldCenterTransform(e,c,u)?{x:J,y:J}:this._getOriginFromCorner(e,r),f={target:e,action:c,actionHandler:h,actionPerformed:!1,corner:r,scaleX:e.scaleX,scaleY:e.scaleY,skewX:e.skewX,skewY:e.skewY,offsetX:n.x-e.left,offsetY:n.y-e.top,originX:d.x,originY:d.y,ex:n.x,ey:n.y,lastX:n.x,lastY:n.y,theta:Rt(e.angle),width:e.width,height:e.height,shiftKey:t.shiftKey,altKey:u,original:T(T({},xf(e)),{},{originX:d.x,originY:d.y})};this._currentTransform=f,this.fire("before:transform",{e:t,transform:f})}setCursor(t){this.upperCanvasEl.style.cursor=t}_drawSelection(t){const{x:e,y:s,deltaX:i,deltaY:n}=this._groupSelector,r=new P(e,s).transform(this.viewportTransform),o=new P(e+i,s+n).transform(this.viewportTransform),h=this.selectionLineWidth/2;let c=Math.min(r.x,o.x),u=Math.min(r.y,o.y),d=Math.max(r.x,o.x),f=Math.max(r.y,o.y);this.selectionColor&&(t.fillStyle=this.selectionColor,t.fillRect(c,u,d-c,f-u)),this.selectionLineWidth&&this.selectionBorderColor&&(t.lineWidth=this.selectionLineWidth,t.strokeStyle=this.selectionBorderColor,c+=h,u+=h,d-=h,f-=h,pe.prototype._setLineDash.call(this,t,this.selectionDashArray),t.strokeRect(c,u,d-c,f-u))}findTarget(t){if(this.skipTargetFind)return;const e=this.getViewportPoint(t),s=this._activeObject,i=this.getActiveObjects();if(this.targets=[],s&&i.length>=1){if(s.findControl(e,Kc(t))||i.length>1&&this.searchPossibleTargets([s],e))return s;if(s===this.searchPossibleTargets([s],e)){if(this.preserveObjectStacking){const n=this.targets;this.targets=[];const r=this.searchPossibleTargets(this._objects,e);return t[this.altSelectionKey]&&r&&r!==s?(this.targets=n,s):r}return s}}return this.searchPossibleTargets(this._objects,e)}_pointIsInObjectSelectionArea(t,e){let s=t.getCoords();const i=this.getZoom(),n=t.padding/i;if(n){const[r,o,h,c]=s,u=Math.atan2(o.y-r.y,o.x-r.x),d=Ds(u)*n,f=Os(u)*n,g=d+f,p=d-f;s=[new P(r.x-p,r.y-g),new P(o.x+g,o.y-p),new P(h.x+p,h.y+g),new P(c.x-g,c.y+p)]}return Mt.isPointInPolygon(e,s)}_checkTarget(t,e){return!!(t&&t.visible&&t.evented&&this._pointIsInObjectSelectionArea(t,_r(e,void 0,this.viewportTransform))&&(!this.perPixelTargetFind&&!t.perPixelTargetFind||t.isEditing||!this.isTargetTransparent(t,e.x,e.y)))}_searchPossibleTargets(t,e){let s=t.length;for(;s--;){const i=t[s];if(this._checkTarget(i,e)){if(Uc(i)&&i.subTargetCheck){const n=this._searchPossibleTargets(i._objects,e);n&&this.targets.push(n)}return i}}}searchPossibleTargets(t,e){const s=this._searchPossibleTargets(t,e);if(s&&Uc(s)&&s.interactive&&this.targets[0]){const i=this.targets;for(let n=i.length-1;n>0;n--){const r=i[n];if(!Uc(r)||!r.interactive)return r}return i[0]}return s}getViewportPoint(t){return this._pointer?this._pointer:this.getPointer(t,!0)}getScenePoint(t){return this._absolutePointer?this._absolutePointer:this.getPointer(t)}getPointer(t){let e=arguments.length>1&&arguments[1]!==void 0&&arguments[1];const s=this.upperCanvasEl,i=s.getBoundingClientRect();let n=gm(t),r=i.width||0,o=i.height||0;r&&o||(Ve in i&&hf in i&&(o=Math.abs(i.top-i.bottom)),It in i&&dt in i&&(r=Math.abs(i.right-i.left))),this.calcOffset(),n.x=n.x-this._offset.left,n.y=n.y-this._offset.top,e||(n=_r(n,void 0,this.viewportTransform));const h=this.getRetinaScaling();h!==1&&(n.x/=h,n.y/=h);const c=r===0||o===0?new P(1,1):new P(s.width/r,s.height/o);return n.multiply(c)}_setDimensionsImpl(t,e){this._resetTransformEventData(),super._setDimensionsImpl(t,e),this._isCurrentlyDrawing&&this.freeDrawingBrush&&this.freeDrawingBrush._setBrushStyles(this.contextTop)}_createCacheCanvas(){this.pixelFindCanvasEl=ms(),this.pixelFindContext=this.pixelFindCanvasEl.getContext("2d",{willReadFrequently:!0}),this.setTargetFindTolerance(this.targetFindTolerance)}getTopContext(){return this.elements.upper.ctx}getSelectionContext(){return this.elements.upper.ctx}getSelectionElement(){return this.elements.upper.el}getActiveObject(){return this._activeObject}getActiveObjects(){const t=this._activeObject;return vr(t)?t.getObjects():t?[t]:[]}_fireSelectionEvents(t,e){let s=!1,i=!1;const n=this.getActiveObjects(),r=[],o=[];t.forEach(h=>{n.includes(h)||(s=!0,h.fire("deselected",{e,target:h}),o.push(h))}),n.forEach(h=>{t.includes(h)||(s=!0,h.fire("selected",{e,target:h}),r.push(h))}),t.length>0&&n.length>0?(i=!0,s&&this.fire("selection:updated",{e,selected:r,deselected:o})):n.length>0?(i=!0,this.fire("selection:created",{e,selected:r})):t.length>0&&(i=!0,this.fire("selection:cleared",{e,deselected:o})),i&&(this._objectsToRender=void 0)}setActiveObject(t,e){const s=this.getActiveObjects(),i=this._setActiveObject(t,e);return this._fireSelectionEvents(s,e),i}_setActiveObject(t,e){const s=this._activeObject;return s!==t&&!(!this._discardActiveObject(e,t)&&this._activeObject)&&!t.onSelect({e})&&(this._activeObject=t,vr(t)&&s!==t&&t.set("canvas",this),t.setCoords(),!0)}_discardActiveObject(t,e){const s=this._activeObject;return!!s&&!s.onDeselect({e:t,object:e})&&(this._currentTransform&&this._currentTransform.target===s&&this.endCurrentTransform(t),vr(s)&&s===this._hoveredTarget&&(this._hoveredTarget=void 0),this._activeObject=void 0,!0)}discardActiveObject(t){const e=this.getActiveObjects(),s=this.getActiveObject();e.length&&this.fire("before:selection:cleared",{e:t,deselected:[s]});const i=this._discardActiveObject(t);return this._fireSelectionEvents(e,t),i}endCurrentTransform(t){const e=this._currentTransform;this._finalizeCurrentTransform(t),e&&e.target&&(e.target.isMoving=!1),this._currentTransform=null}_finalizeCurrentTransform(t){const e=this._currentTransform,s=e.target,i={e:t,target:s,transform:e,action:e.action};s._scaling&&(s._scaling=!1),s.setCoords(),e.actionPerformed&&(this.fire("object:modified",i),s.fire(Xc,i))}setViewportTransform(t){super.setViewportTransform(t);const e=this._activeObject;e&&e.setCoords()}destroy(){const t=this._activeObject;vr(t)&&(t.removeAll(),t.dispose()),delete this._activeObject,super.destroy(),this.pixelFindContext=null,this.pixelFindCanvasEl=void 0}clear(){this.discardActiveObject(),this._activeObject=void 0,this.clearContext(this.contextTop),super.clear()}drawControls(t){const e=this._activeObject;e&&e._renderControls(t)}_toObject(t,e,s){const i=this._realizeGroupTransformOnObject(t),n=super._toObject(t,e,s);return t.set(i),n}_realizeGroupTransformOnObject(t){const{group:e}=t;if(e&&vr(e)&&this._activeObject===e){const s=yr(t,["angle","flipX","flipY",dt,Me,Je,Xo,Wo,Ve]);return pm(t,e.calcOwnMatrix()),s}return{}}_setSVGObject(t,e,s){const i=this._realizeGroupTransformOnObject(e);super._setSVGObject(t,e,s),e.set(i)}}A(mu,"ownDefaults",{uniformScaling:!0,uniScaleKey:"shiftKey",centeredScaling:!1,centeredRotation:!1,centeredKey:"altKey",altActionKey:"shiftKey",selection:!0,selectionKey:"shiftKey",selectionColor:"rgba(100, 100, 255, 0.3)",selectionDashArray:[],selectionBorderColor:"rgba(255, 255, 255, 0.3)",selectionLineWidth:1,selectionFullyContained:!1,hoverCursor:"move",moveCursor:"move",defaultCursor:"default",freeDrawingCursor:"crosshair",notAllowedCursor:"not-allowed",perPixelTargetFind:!1,targetFindTolerance:0,skipTargetFind:!1,stopContextMenu:!1,fireRightClick:!1,fireMiddleClick:!1,enablePointerEvents:!1,containerClass:"canvas-container",preserveObjectStacking:!1});class K_{constructor(t){A(this,"targets",[]),A(this,"__disposer",void 0);const e=()=>{const{hiddenTextarea:i}=t.getActiveObject()||{};i&&i.focus()},s=t.upperCanvasEl;s.addEventListener("click",e),this.__disposer=()=>s.removeEventListener("click",e)}exitTextEditing(){this.target=void 0,this.targets.forEach(t=>{t.isEditing&&t.exitEditing()})}add(t){this.targets.push(t)}remove(t){this.unregister(t),mr(this.targets,t)}register(t){this.target=t}unregister(t){t===this.target&&(this.target=void 0)}onMouseMove(t){var e;!((e=this.target)===null||e===void 0)&&e.isEditing&&this.target.updateSelectionOnMouseMove(t)}clear(){this.targets=[],this.target=void 0}dispose(){this.clear(),this.__disposer(),delete this.__disposer}}const Q_=["target","oldTarget","fireCanvas","e"],Ze={passive:!1},sa=(a,t)=>{const e=a.getViewportPoint(t),s=a.getScenePoint(t);return{viewportPoint:e,scenePoint:s,pointer:e,absolutePointer:s}},Pn=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 a.addEventListener(...e)},ys=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 a.removeEventListener(...e)},J_={mouse:{in:"over",out:"out",targetIn:"mouseover",targetOut:"mouseout",canvasIn:"mouse:over",canvasOut:"mouse:out"},drag:{in:"enter",out:"leave",targetIn:"dragenter",targetOut:"dragleave",canvasIn:"drag:enter",canvasOut:"drag:leave"}};class Uf extends mu{constructor(t){super(t,arguments.length>1&&arguments[1]!==void 0?arguments[1]:{}),A(this,"_isClick",void 0),A(this,"textEditingManager",new K_(this)),["_onMouseDown","_onTouchStart","_onMouseMove","_onMouseUp","_onTouchEnd","_onResize","_onMouseWheel","_onMouseOut","_onMouseEnter","_onContextMenu","_onDoubleClick","_onDragStart","_onDragEnd","_onDragProgress","_onDragOver","_onDragEnter","_onDragLeave","_onDrop"].forEach(e=>{this[e]=this[e].bind(this)}),this.addOrRemove(Pn,"add")}_getEventPrefix(){return this.enablePointerEvents?"pointer":"mouse"}addOrRemove(t,e){const s=this.upperCanvasEl,i=this._getEventPrefix();t(cm(s),"resize",this._onResize),t(s,i+"down",this._onMouseDown),t(s,"".concat(i,"move"),this._onMouseMove,Ze),t(s,"".concat(i,"out"),this._onMouseOut),t(s,"".concat(i,"enter"),this._onMouseEnter),t(s,"wheel",this._onMouseWheel),t(s,"contextmenu",this._onContextMenu),t(s,"dblclick",this._onDoubleClick),t(s,"dragstart",this._onDragStart),t(s,"dragend",this._onDragEnd),t(s,"dragover",this._onDragOver),t(s,"dragenter",this._onDragEnter),t(s,"dragleave",this._onDragLeave),t(s,"drop",this._onDrop),this.enablePointerEvents||t(s,"touchstart",this._onTouchStart,Ze)}removeListeners(){this.addOrRemove(ys,"remove");const t=this._getEventPrefix(),e=Ls(this.upperCanvasEl);ys(e,"".concat(t,"up"),this._onMouseUp),ys(e,"touchend",this._onTouchEnd,Ze),ys(e,"".concat(t,"move"),this._onMouseMove,Ze),ys(e,"touchmove",this._onMouseMove,Ze),clearTimeout(this._willAddMouseDown)}_onMouseWheel(t){this.__onMouseWheel(t)}_onMouseOut(t){const e=this._hoveredTarget,s=T({e:t},sa(this,t));this.fire("mouse:out",T(T({},s),{},{target:e})),this._hoveredTarget=void 0,e&&e.fire("mouseout",T({},s)),this._hoveredTargets.forEach(i=>{this.fire("mouse:out",T(T({},s),{},{target:i})),i&&i.fire("mouseout",T({},s))}),this._hoveredTargets=[]}_onMouseEnter(t){this._currentTransform||this.findTarget(t)||(this.fire("mouse:over",T({e:t},sa(this,t))),this._hoveredTarget=void 0,this._hoveredTargets=[])}_onDragStart(t){this._isClick=!1;const e=this.getActiveObject();if(e&&e.onDragStart(t)){this._dragSource=e;const s={e:t,target:e};return this.fire("dragstart",s),e.fire("dragstart",s),void Pn(this.upperCanvasEl,"drag",this._onDragProgress)}wf(t)}_renderDragEffects(t,e,s){let i=!1;const n=this._dropTarget;n&&n!==e&&n!==s&&(n.clearContextTop(),i=!0),e==null||e.clearContextTop(),s!==e&&(s==null||s.clearContextTop());const r=this.contextTop;r.save(),r.transform(...this.viewportTransform),e&&(r.save(),e.transform(r),e.renderDragSourceEffect(t),r.restore(),i=!0),s&&(r.save(),s.transform(r),s.renderDropTargetEffect(t),r.restore(),i=!0),r.restore(),i&&(this.contextTopDirty=!0)}_onDragEnd(t){const e=!!t.dataTransfer&&t.dataTransfer.dropEffect!==ke,s=e?this._activeObject:void 0,i={e:t,target:this._dragSource,subTargets:this.targets,dragSource:this._dragSource,didDrop:e,dropTarget:s};ys(this.upperCanvasEl,"drag",this._onDragProgress),this.fire("dragend",i),this._dragSource&&this._dragSource.fire("dragend",i),delete this._dragSource,this._onMouseUp(t)}_onDragProgress(t){const e={e:t,target:this._dragSource,dragSource:this._dragSource,dropTarget:this._draggedoverTarget};this.fire("drag",e),this._dragSource&&this._dragSource.fire("drag",e)}findDragTargets(t){return this.targets=[],{target:this._searchPossibleTargets(this._objects,this.getViewportPoint(t)),targets:[...this.targets]}}_onDragOver(t){const e="dragover",{target:s,targets:i}=this.findDragTargets(t),n=this._dragSource,r={e:t,target:s,subTargets:i,dragSource:n,canDrop:!1,dropTarget:void 0};let o;this.fire(e,r),this._fireEnterLeaveEvents(s,r),s&&(s.canDrop(t)&&(o=s),s.fire(e,r));for(let h=0;h<i.length;h++){const c=i[h];c.canDrop(t)&&(o=c),c.fire(e,r)}this._renderDragEffects(t,n,o),this._dropTarget=o}_onDragEnter(t){const{target:e,targets:s}=this.findDragTargets(t),i={e:t,target:e,subTargets:s,dragSource:this._dragSource};this.fire("dragenter",i),this._fireEnterLeaveEvents(e,i)}_onDragLeave(t){const e={e:t,target:this._draggedoverTarget,subTargets:this.targets,dragSource:this._dragSource};this.fire("dragleave",e),this._fireEnterLeaveEvents(void 0,e),this._renderDragEffects(t,this._dragSource),this._dropTarget=void 0,this.targets=[],this._hoveredTargets=[]}_onDrop(t){const{target:e,targets:s}=this.findDragTargets(t),i=this._basicEventHandler("drop:before",T({e:t,target:e,subTargets:s,dragSource:this._dragSource},sa(this,t)));i.didDrop=!1,i.dropTarget=void 0,this._basicEventHandler("drop",i),this.fire("drop:after",i)}_onContextMenu(t){const e=this.findTarget(t),s=this.targets||[],i=this._basicEventHandler("contextmenu:before",{e:t,target:e,subTargets:s});return this.stopContextMenu&&wf(t),this._basicEventHandler("contextmenu",i),!1}_onDoubleClick(t){this._cacheTransformEventData(t),this._handleEvent(t,"dblclick"),this._resetTransformEventData()}getPointerId(t){const e=t.changedTouches;return e?e[0]&&e[0].identifier:this.enablePointerEvents?t.pointerId:-1}_isMainEvent(t){return t.isPrimary===!0||t.isPrimary!==!1&&(t.type==="touchend"&&t.touches.length===0||!t.changedTouches||t.changedTouches[0].identifier===this.mainTouchId)}_onTouchStart(t){let e=!this.allowTouchScrolling;const s=this._activeObject;this.mainTouchId===void 0&&(this.mainTouchId=this.getPointerId(t)),this.__onMouseDown(t),(this.isDrawingMode||s&&this._target===s)&&(e=!0),e&&t.preventDefault(),this._resetTransformEventData();const i=this.upperCanvasEl,n=this._getEventPrefix(),r=Ls(i);Pn(r,"touchend",this._onTouchEnd,Ze),e&&Pn(r,"touchmove",this._onMouseMove,Ze),ys(i,"".concat(n,"down"),this._onMouseDown)}_onMouseDown(t){this.__onMouseDown(t),this._resetTransformEventData();const e=this.upperCanvasEl,s=this._getEventPrefix();ys(e,"".concat(s,"move"),this._onMouseMove,Ze);const i=Ls(e);Pn(i,"".concat(s,"up"),this._onMouseUp),Pn(i,"".concat(s,"move"),this._onMouseMove,Ze)}_onTouchEnd(t){if(t.touches.length>0)return;this.__onMouseUp(t),this._resetTransformEventData(),delete this.mainTouchId;const e=this._getEventPrefix(),s=Ls(this.upperCanvasEl);ys(s,"touchend",this._onTouchEnd,Ze),ys(s,"touchmove",this._onMouseMove,Ze),this._willAddMouseDown&&clearTimeout(this._willAddMouseDown),this._willAddMouseDown=setTimeout(()=>{Pn(this.upperCanvasEl,"".concat(e,"down"),this._onMouseDown),this._willAddMouseDown=0},400)}_onMouseUp(t){this.__onMouseUp(t),this._resetTransformEventData();const e=this.upperCanvasEl,s=this._getEventPrefix();if(this._isMainEvent(t)){const i=Ls(this.upperCanvasEl);ys(i,"".concat(s,"up"),this._onMouseUp),ys(i,"".concat(s,"move"),this._onMouseMove,Ze),Pn(e,"".concat(s,"move"),this._onMouseMove,Ze)}}_onMouseMove(t){const e=this.getActiveObject();!this.allowTouchScrolling&&(!e||!e.shouldStartDragging(t))&&t.preventDefault&&t.preventDefault(),this.__onMouseMove(t)}_onResize(){this.calcOffset(),this._resetTransformEventData()}_shouldRender(t){const e=this.getActiveObject();return!!e!=!!t||e&&t&&e!==t}__onMouseUp(t){var e;this._cacheTransformEventData(t),this._handleEvent(t,"up:before");const s=this._currentTransform,i=this._isClick,n=this._target,{button:r}=t;if(r)return(this.fireMiddleClick&&r===1||this.fireRightClick&&r===2)&&this._handleEvent(t,"up"),void this._resetTransformEventData();if(this.isDrawingMode&&this._isCurrentlyDrawing)return void this._onMouseUpInDrawingMode(t);if(!this._isMainEvent(t))return;let o,h,c=!1;if(s&&(this._finalizeCurrentTransform(t),c=s.actionPerformed),!i){const u=n===this._activeObject;this.handleSelection(t),c||(c=this._shouldRender(n)||!u&&n===this._activeObject)}if(n){const u=n.findControl(this.getViewportPoint(t),Kc(t)),{key:d,control:f}=u||{};if(h=d,n.selectable&&n!==this._activeObject&&n.activeOn==="up")this.setActiveObject(n,t),c=!0;else if(f){const g=f.getMouseUpHandler(t,n,f);g&&(o=this.getScenePoint(t),g.call(f,t,s,o.x,o.y))}n.isMoving=!1}if(s&&(s.target!==n||s.corner!==h)){const u=s.target&&s.target.controls[s.corner],d=u&&u.getMouseUpHandler(t,s.target,u);o=o||this.getScenePoint(t),d&&d.call(u,t,s,o.x,o.y)}this._setCursorFromEvent(t,n),this._handleEvent(t,"up"),this._groupSelector=null,this._currentTransform=null,n&&(n.__corner=void 0),c?this.requestRenderAll():i||(e=this._activeObject)!==null&&e!==void 0&&e.isEditing||this.renderTop()}_basicEventHandler(t,e){const{target:s,subTargets:i=[]}=e;this.fire(t,e),s&&s.fire(t,e);for(let n=0;n<i.length;n++)i[n]!==s&&i[n].fire(t,e);return e}_handleEvent(t,e){const s=this._target,i=this.targets||[],n=T(T({e:t,target:s,subTargets:i},sa(this,t)),{},{transform:this._currentTransform},e==="up:before"||e==="up"?{isClick:this._isClick,currentTarget:this.findTarget(t),currentSubTargets:this.targets}:{});this.fire("mouse:".concat(e),n),s&&s.fire("mouse".concat(e),n);for(let r=0;r<i.length;r++)i[r]!==s&&i[r].fire("mouse".concat(e),n)}_onMouseDownInDrawingMode(t){this._isCurrentlyDrawing=!0,this.getActiveObject()&&(this.discardActiveObject(t),this.requestRenderAll());const e=this.getScenePoint(t);this.freeDrawingBrush&&this.freeDrawingBrush.onMouseDown(e,{e:t,pointer:e}),this._handleEvent(t,"down")}_onMouseMoveInDrawingMode(t){if(this._isCurrentlyDrawing){const e=this.getScenePoint(t);this.freeDrawingBrush&&this.freeDrawingBrush.onMouseMove(e,{e:t,pointer:e})}this.setCursor(this.freeDrawingCursor),this._handleEvent(t,"move")}_onMouseUpInDrawingMode(t){const e=this.getScenePoint(t);this.freeDrawingBrush?this._isCurrentlyDrawing=!!this.freeDrawingBrush.onMouseUp({e:t,pointer:e}):this._isCurrentlyDrawing=!1,this._handleEvent(t,"up")}__onMouseDown(t){this._isClick=!0,this._cacheTransformEventData(t),this._handleEvent(t,"down:before");let e=this._target;const{button:s}=t;if(s)return(this.fireMiddleClick&&s===1||this.fireRightClick&&s===2)&&this._handleEvent(t,"down"),void this._resetTransformEventData();if(this.isDrawingMode)return void this._onMouseDownInDrawingMode(t);if(!this._isMainEvent(t)||this._currentTransform)return;let i=this._shouldRender(e),n=!1;if(this.handleMultiSelection(t,e)?(e=this._activeObject,n=!0,i=!0):this._shouldClearSelection(t,e)&&this.discardActiveObject(t),this.selection&&(!e||!e.selectable&&!e.isEditing&&e!==this._activeObject)){const r=this.getScenePoint(t);this._groupSelector={x:r.x,y:r.y,deltaY:0,deltaX:0}}if(e){const r=e===this._activeObject;e.selectable&&e.activeOn==="down"&&this.setActiveObject(e,t);const o=e.findControl(this.getViewportPoint(t),Kc(t));if(e===this._activeObject&&(o||!n)){this._setupCurrentTransform(t,e,r);const h=o?o.control:void 0,c=this.getScenePoint(t),u=h&&h.getMouseDownHandler(t,e,h);u&&u.call(h,t,this._currentTransform,c.x,c.y)}}i&&(this._objectsToRender=void 0),this._handleEvent(t,"down"),i&&this.requestRenderAll()}_resetTransformEventData(){this._target=this._pointer=this._absolutePointer=void 0}_cacheTransformEventData(t){this._resetTransformEventData(),this._pointer=this.getViewportPoint(t),this._absolutePointer=_r(this._pointer,void 0,this.viewportTransform),this._target=this._currentTransform?this._currentTransform.target:this.findTarget(t)}__onMouseMove(t){if(this._isClick=!1,this._cacheTransformEventData(t),this._handleEvent(t,"move:before"),this.isDrawingMode)return void this._onMouseMoveInDrawingMode(t);if(!this._isMainEvent(t))return;const e=this._groupSelector;if(e){const s=this.getScenePoint(t);e.deltaX=s.x-e.x,e.deltaY=s.y-e.y,this.renderTop()}else if(this._currentTransform)this._transformObject(t);else{const s=this.findTarget(t);this._setCursorFromEvent(t,s),this._fireOverOutEvents(t,s)}this.textEditingManager.onMouseMove(t),this._handleEvent(t,"move"),this._resetTransformEventData()}_fireOverOutEvents(t,e){const s=this._hoveredTarget,i=this._hoveredTargets,n=this.targets,r=Math.max(i.length,n.length);this.fireSyntheticInOutEvents("mouse",{e:t,target:e,oldTarget:s,fireCanvas:!0});for(let o=0;o<r;o++)this.fireSyntheticInOutEvents("mouse",{e:t,target:n[o],oldTarget:i[o]});this._hoveredTarget=e,this._hoveredTargets=this.targets.concat()}_fireEnterLeaveEvents(t,e){const s=this._draggedoverTarget,i=this._hoveredTargets,n=this.targets,r=Math.max(i.length,n.length);this.fireSyntheticInOutEvents("drag",T(T({},e),{},{target:t,oldTarget:s,fireCanvas:!0}));for(let o=0;o<r;o++)this.fireSyntheticInOutEvents("drag",T(T({},e),{},{target:n[o],oldTarget:i[o]}));this._draggedoverTarget=t}fireSyntheticInOutEvents(t,e){let{target:s,oldTarget:i,fireCanvas:n,e:r}=e,o=Ct(e,Q_);const{targetIn:h,targetOut:c,canvasIn:u,canvasOut:d}=J_[t],f=i!==s;if(i&&f){const g=T(T({},o),{},{e:r,target:i,nextTarget:s},sa(this,r));n&&this.fire(d,g),i.fire(c,g)}if(s&&f){const g=T(T({},o),{},{e:r,target:s,previousTarget:i},sa(this,r));n&&this.fire(u,g),s.fire(h,g)}}__onMouseWheel(t){this._cacheTransformEventData(t),this._handleEvent(t,"wheel"),this._resetTransformEventData()}_transformObject(t){const e=this.getScenePoint(t),s=this._currentTransform,i=s.target,n=i.group?_r(e,void 0,i.group.calcTransformMatrix()):e;s.shiftKey=t.shiftKey,s.altKey=!!this.centeredKey&&t[this.centeredKey],this._performTransformAction(t,s,n),s.actionPerformed&&this.requestRenderAll()}_performTransformAction(t,e,s){const{action:i,actionHandler:n,target:r}=e,o=!!n&&n(t,e,s.x,s.y);o&&r.setCoords(),i==="drag"&&o&&(e.target.isMoving=!0,this.setCursor(e.target.moveCursor||this.moveCursor)),e.actionPerformed=e.actionPerformed||o}_setCursorFromEvent(t,e){if(!e)return void this.setCursor(this.defaultCursor);let s=e.hoverCursor||this.hoverCursor;const i=vr(this._activeObject)?this._activeObject:null,n=(!i||e.group!==i)&&e.findControl(this.getViewportPoint(t));if(n){const r=n.control;this.setCursor(r.cursorStyleHandler(t,r,e))}else e.subTargetCheck&&this.targets.concat().reverse().map(r=>{s=r.hoverCursor||s}),this.setCursor(s)}handleMultiSelection(t,e){const s=this._activeObject,i=vr(s);if(s&&this._isSelectionKeyPressed(t)&&this.selection&&e&&e.selectable&&(s!==e||i)&&(i||!e.isDescendantOf(s)&&!s.isDescendantOf(e))&&!e.onSelect({e:t})&&!s.getActiveControl()){if(i){const n=s.getObjects();if(e===s){const r=this.getViewportPoint(t);if(!(e=this.searchPossibleTargets(n,r)||this.searchPossibleTargets(this._objects,r))||!e.selectable)return!1}e.group===s?(s.remove(e),this._hoveredTarget=e,this._hoveredTargets=[...this.targets],s.size()===1&&this._setActiveObject(s.item(0),t)):(s.multiSelectAdd(e),this._hoveredTarget=s,this._hoveredTargets=[...this.targets]),this._fireSelectionEvents(n,t)}else{s.isEditing&&s.exitEditing();const n=new(H.getClass("ActiveSelection"))([],{canvas:this});n.multiSelectAdd(s,e),this._hoveredTarget=n,this._setActiveObject(n,t),this._fireSelectionEvents([s],t)}return!0}return!1}handleSelection(t){if(!this.selection||!this._groupSelector)return!1;const{x:e,y:s,deltaX:i,deltaY:n}=this._groupSelector,r=new P(e,s),o=r.add(new P(i,n)),h=r.min(o),c=r.max(o).subtract(h),u=this.collectObjects({left:h.x,top:h.y,width:c.x,height:c.y},{includeIntersecting:!this.selectionFullyContained}),d=r.eq(o)?u[0]?[u[0]]:[]:u.length>1?u.filter(f=>!f.onSelect({e:t})).reverse():u;if(d.length===1)this.setActiveObject(d[0],t);else if(d.length>1){const f=H.getClass("ActiveSelection");this.setActiveObject(new f(d,{canvas:this}),t)}return this._groupSelector=null,!0}clear(){this.textEditingManager.clear(),super.clear()}destroy(){this.removeListeners(),this.textEditingManager.dispose(),super.destroy()}}const x0={x1:0,y1:0,x2:0,y2:0},Z_=T(T({},x0),{},{r1:0,r2:0}),ia=(a,t)=>isNaN(a)&&typeof t=="number"?t:a,tw=/^(\d+\.\d+)%|(\d+)%$/;function S0(a){return a&&tw.test(a)}function C0(a,t){const e=typeof a=="number"?a:typeof a=="string"?parseFloat(a)/(S0(a)?100:1):NaN;return wr(0,ia(e,t),1)}const ew=/\s*;\s*/,sw=/\s*:\s*/;function iw(a,t){let e,s;const i=a.getAttribute("style");if(i){const r=i.split(ew);r[r.length-1]===""&&r.pop();for(let o=r.length;o--;){const[h,c]=r[o].split(sw).map(u=>u.trim());h==="stop-color"?e=c:h==="stop-opacity"&&(s=c)}}const n=new gt(e||a.getAttribute("stop-color")||"rgb(0,0,0)");return{offset:C0(a.getAttribute("offset"),0),color:n.toRgb(),opacity:ia(parseFloat(s||a.getAttribute("stop-opacity")||""),1)*n.getAlpha()*t}}function nw(a,t){const e=[],s=a.getElementsByTagName("stop"),i=C0(t,1);for(let n=s.length;n--;)e.push(iw(s[n],i));return e}function A0(a){return a.nodeName==="linearGradient"||a.nodeName==="LINEARGRADIENT"?"linear":"radial"}function T0(a){return a.getAttribute("gradientUnits")==="userSpaceOnUse"?"pixels":"percentage"}function js(a,t){return a.getAttribute(t)}function rw(a,t){return function(e,s){let i,{width:n,height:r,gradientUnits:o}=s;return Object.keys(e).reduce((h,c)=>{const u=e[c];return u==="Infinity"?i=1:u==="-Infinity"?i=0:(i=typeof u=="string"?parseFloat(u):u,typeof u=="string"&&S0(u)&&(i*=.01,o==="pixels"&&(c!=="x1"&&c!=="x2"&&c!=="r2"||(i*=n),c!=="y1"&&c!=="y2"||(i*=r)))),h[c]=i,h},{})}(A0(a)==="linear"?function(e){return{x1:js(e,"x1")||0,y1:js(e,"y1")||0,x2:js(e,"x2")||"100%",y2:js(e,"y2")||0}}(a):function(e){return{x1:js(e,"fx")||js(e,"cx")||"50%",y1:js(e,"fy")||js(e,"cy")||"50%",r1:0,x2:js(e,"cx")||"50%",y2:js(e,"cy")||"50%",r2:js(e,"r")||"50%"}}(a),T(T({},t),{},{gradientUnits:T0(a)}))}class Ih{constructor(t){const{type:e="linear",gradientUnits:s="pixels",coords:i={},colorStops:n=[],offsetX:r=0,offsetY:o=0,gradientTransform:h,id:c}=t||{};Object.assign(this,{type:e,gradientUnits:s,coords:T(T({},e==="radial"?Z_:x0),i),colorStops:n,offsetX:r,offsetY:o,gradientTransform:h,id:c?"".concat(c,"_").concat(En()):En()})}addColorStop(t){for(const e in t){const s=new gt(t[e]);this.colorStops.push({offset:parseFloat(e),color:s.toRgb(),opacity:s.getAlpha()})}return this}toObject(t){return T(T({},yr(this,t)),{},{type:this.type,coords:T({},this.coords),colorStops:this.colorStops.map(e=>T({},e)),offsetX:this.offsetX,offsetY:this.offsetY,gradientUnits:this.gradientUnits,gradientTransform:this.gradientTransform?[...this.gradientTransform]:void 0})}toSVG(t){let{additionalTransform:e}=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};const s=[],i=this.gradientTransform?this.gradientTransform.concat():Ee.concat(),n=this.gradientUnits==="pixels"?"userSpaceOnUse":"objectBoundingBox",r=this.colorStops.map(d=>T({},d)).sort((d,f)=>d.offset-f.offset);let o=-this.offsetX,h=-this.offsetY;var c;n==="objectBoundingBox"?(o/=t.width,h/=t.height):(o+=t.width/2,h+=t.height/2),(c=t)&&typeof c._renderPathCommands=="function"&&this.gradientUnits!=="percentage"&&(o-=t.pathOffset.x,h-=t.pathOffset.y),i[4]-=o,i[5]-=h;const u=['id="SVGID_'.concat(this.id,'"'),'gradientUnits="'.concat(n,'"'),'gradientTransform="'.concat(e?e+" ":"").concat(kh(i),'"'),""].join(" ");if(this.type==="linear"){const{x1:d,y1:f,x2:g,y2:p}=this.coords;s.push("<linearGradient ",u,' x1="',d,'" y1="',f,'" x2="',g,'" y2="',p,`">
|
|
41
|
+
`),e}getSvgStyles(){const t=this.opacity!==void 0&&this.opacity!==1?"opacity: ".concat(this.opacity,";"):"",e=this.visible?"":" visibility: hidden;";return[t,this.getSvgFilter(),e].join("")}toClipPathSVG(t){const e=[],s=this._createSVGBgRect(t);s&&e.push(" ",s);for(let i=0;i<this._objects.length;i++)e.push(" ",this._objects[i].toClipPathSVG(t));return this._createBaseClipPathSVGMarkup(e,{reviver:t})}static fromObject(t,e){let{type:s,objects:i=[],layoutManager:n}=t,r=Ct(t,I_);return Promise.all([qo(i,e),Eh(r,e)]).then(o=>{let[h,c]=o;const u=new this(h,T(T(T({},r),c),{},{layoutManager:new N_}));if(n){const d=N.getClass(n.type),f=N.getClass(n.strategy);u.layoutManager=new d(new f)}else u.layoutManager=new Lh;return u.layoutManager.subscribeTargets({type:ji,target:u,targets:u.getObjects()}),u.setCoords(),u})}}A(ai,"type","Group"),A(ai,"ownDefaults",{strokeWidth:0,subTargetCheck:!1,interactive:!1}),N.setClass(ai);const h0=(a,t)=>Math.min(t.width/a.width,t.height/a.height),l0=(a,t)=>Math.max(t.width/a.width,t.height/a.height),Vf="\\s*,?\\s*",Fh="".concat(Vf,"(").concat(Is,")"),j_="".concat(Fh).concat(Fh).concat(Fh).concat(Vf,"([01])").concat(Vf,"([01])").concat(Fh).concat(Fh),B_={m:"l",M:"L"},H_=(a,t,e,s,i,n,r,o,h,c,u)=>{const d=Ds(a),f=Os(a),g=Ds(t),p=Os(t),b=e*i*g-s*n*p+r,_=s*i*g+e*n*p+o;return["C",c+h*(-e*i*f-s*n*d),u+h*(-s*i*f+e*n*d),b+h*(e*i*p+s*n*g),_+h*(s*i*p-e*n*g),b,_]},c0=(a,t,e,s)=>{const i=Math.atan2(t,a),n=Math.atan2(s,e);return n>=i?n-i:2*Math.PI-(i-n)};function Xf(a,t,e,s,i,n,r,o){let h;if(ht.cachesBoundsOfCurve&&(h=[...arguments].join(),xh.boundsOfCurveCache[h]))return xh.boundsOfCurveCache[h];const c=Math.sqrt,u=Math.abs,d=[],f=[[0,0],[0,0]];let g=6*a-12*e+6*i,p=-3*a+9*e-9*i+3*r,b=3*e-3*a;for(let S=0;S<2;++S){if(S>0&&(g=6*t-12*s+6*n,p=-3*t+9*s-9*n+3*o,b=3*s-3*t),u(p)<1e-12){if(u(g)<1e-12)continue;const O=-b/g;0<O&&O<1&&d.push(O);continue}const k=g*g-4*b*p;if(k<0)continue;const M=c(k),E=(-g+M)/(2*p);0<E&&E<1&&d.push(E);const P=(-g-M)/(2*p);0<P&&P<1&&d.push(P)}let _=d.length;const v=_,x=d0(a,t,e,s,i,n,r,o);for(;_--;){const{x:S,y:k}=x(d[_]);f[0][_]=S,f[1][_]=k}f[0][v]=a,f[1][v]=t,f[0][v+1]=r,f[1][v+1]=o;const C=[new D(Math.min(...f[0]),Math.min(...f[1])),new D(Math.max(...f[0]),Math.max(...f[1]))];return ht.cachesBoundsOfCurve&&(xh.boundsOfCurveCache[h]=C),C}const G_=(a,t,e)=>{let[s,i,n,r,o,h,c,u]=e;const d=((f,g,p,b,_,v,x)=>{if(p===0||b===0)return[];let C=0,S=0,k=0;const M=Math.PI,E=x*of,P=Os(E),O=Ds(E),L=.5*(-O*f-P*g),R=.5*(-O*g+P*f),U=p**2,z=b**2,V=R**2,at=L**2,F=U*z-U*V-z*at;let G=Math.abs(p),rt=Math.abs(b);if(F<0){const Pi=Math.sqrt(1-F/(U*z));G*=Pi,rt*=Pi}else k=(_===v?-1:1)*Math.sqrt(F/(U*V+z*at));const Gt=k*G*R/rt,te=-k*rt*L/G,fe=O*Gt-P*te+.5*f,Yt=P*Gt+O*te+.5*g;let St=c0(1,0,(L-Gt)/G,(R-te)/rt),He=c0((L-Gt)/G,(R-te)/rt,(-L-Gt)/G,(-R-te)/rt);v===0&&He>0?He-=2*M:v===1&&He<0&&(He+=2*M);const Mi=Math.ceil(Math.abs(He/M*2)),Ft=[],ft=He/Mi,fr=8/3*Math.sin(ft/4)*Math.sin(ft/4)/Math.sin(ft/2);let ph=St+ft;for(let Pi=0;Pi<Mi;Pi++)Ft[Pi]=H_(St,ph,O,P,G,rt,fe,Yt,fr,C,S),C=Ft[Pi][5],S=Ft[Pi][6],St=ph,ph+=ft;return Ft})(c-a,u-t,i,n,o,h,r);for(let f=0,g=d.length;f<g;f++)d[f][1]+=a,d[f][2]+=t,d[f][3]+=a,d[f][4]+=t,d[f][5]+=a,d[f][6]+=t;return d},u0=a=>{let t=0,e=0,s=0,i=0;const n=[];let r,o=0,h=0;for(const c of a){const u=[...c];let d;switch(u[0]){case"l":u[1]+=t,u[2]+=e;case"L":t=u[1],e=u[2],d=["L",t,e];break;case"h":u[1]+=t;case"H":t=u[1],d=["L",t,e];break;case"v":u[1]+=e;case"V":e=u[1],d=["L",t,e];break;case"m":u[1]+=t,u[2]+=e;case"M":t=u[1],e=u[2],s=u[1],i=u[2],d=["M",t,e];break;case"c":u[1]+=t,u[2]+=e,u[3]+=t,u[4]+=e,u[5]+=t,u[6]+=e;case"C":o=u[3],h=u[4],t=u[5],e=u[6],d=["C",u[1],u[2],o,h,t,e];break;case"s":u[1]+=t,u[2]+=e,u[3]+=t,u[4]+=e;case"S":r==="C"?(o=2*t-o,h=2*e-h):(o=t,h=e),t=u[3],e=u[4],d=["C",o,h,u[1],u[2],t,e],o=d[3],h=d[4];break;case"q":u[1]+=t,u[2]+=e,u[3]+=t,u[4]+=e;case"Q":o=u[1],h=u[2],t=u[3],e=u[4],d=["Q",o,h,t,e];break;case"t":u[1]+=t,u[2]+=e;case"T":r==="Q"?(o=2*t-o,h=2*e-h):(o=t,h=e),t=u[1],e=u[2],d=["Q",o,h,t,e];break;case"a":u[6]+=t,u[7]+=e;case"A":G_(t,e,u).forEach(f=>n.push(f)),t=u[6],e=u[7];break;case"z":case"Z":t=s,e=i,d=["Z"]}d?(n.push(d),r=d[0]):r=""}return n},fu=(a,t,e,s)=>Math.sqrt((e-a)**2+(s-t)**2),d0=(a,t,e,s,i,n,r,o)=>h=>{const c=h**3,u=(g=>3*g**2*(1-g))(h),d=(g=>3*g*(1-g)**2)(h),f=(g=>(1-g)**3)(h);return new D(r*c+i*u+e*d+a*f,o*c+n*u+s*d+t*f)},f0=a=>a**2,g0=a=>2*a*(1-a),p0=a=>(1-a)**2,z_=(a,t,e,s,i,n,r,o)=>h=>{const c=f0(h),u=g0(h),d=p0(h),f=3*(d*(e-a)+u*(i-e)+c*(r-i)),g=3*(d*(s-t)+u*(n-s)+c*(o-n));return Math.atan2(g,f)},V_=(a,t,e,s,i,n)=>r=>{const o=f0(r),h=g0(r),c=p0(r);return new D(i*o+e*h+a*c,n*o+s*h+t*c)},X_=(a,t,e,s,i,n)=>r=>{const o=1-r,h=2*(o*(e-a)+r*(i-e)),c=2*(o*(s-t)+r*(n-s));return Math.atan2(c,h)},m0=(a,t,e)=>{let s=new D(t,e),i=0;for(let n=1;n<=100;n+=1){const r=a(n/100);i+=fu(s.x,s.y,r.x,r.y),s=r}return i},W_=(a,t)=>{let e,s=0,i=0,n={x:a.x,y:a.y},r=T({},n),o=.01,h=0;const c=a.iterator,u=a.angleFinder;for(;i<t&&o>1e-4;)r=c(s),h=s,e=fu(n.x,n.y,r.x,r.y),e+i>t?(s-=o,o/=2):(n=r,s+=o,i+=e);return T(T({},r),{},{angle:u(h)})},Wf=a=>{let t,e,s=0,i=0,n=0,r=0,o=0;const h=[];for(const c of a){const u={x:i,y:n,command:c[0],length:0};switch(c[0]){case"M":e=u,e.x=r=i=c[1],e.y=o=n=c[2];break;case"L":e=u,e.length=fu(i,n,c[1],c[2]),i=c[1],n=c[2];break;case"C":t=d0(i,n,c[1],c[2],c[3],c[4],c[5],c[6]),e=u,e.iterator=t,e.angleFinder=z_(i,n,c[1],c[2],c[3],c[4],c[5],c[6]),e.length=m0(t,i,n),i=c[5],n=c[6];break;case"Q":t=V_(i,n,c[1],c[2],c[3],c[4]),e=u,e.iterator=t,e.angleFinder=X_(i,n,c[1],c[2],c[3],c[4]),e.length=m0(t,i,n),i=c[3],n=c[4];break;case"Z":e=u,e.destX=r,e.destY=o,e.length=fu(i,n,r,o),i=r,n=o}s+=e.length,h.push(e)}return h.push({length:s,x:i,y:n}),h},b0=function(a,t){let e=arguments.length>2&&arguments[2]!==void 0?arguments[2]:Wf(a),s=0;for(;t-e[s].length>0&&s<e.length-2;)t-=e[s].length,s++;const i=e[s],n=t/i.length,r=a[s];switch(i.command){case"M":return{x:i.x,y:i.y,angle:0};case"Z":return T(T({},new D(i.x,i.y).lerp(new D(i.destX,i.destY),n)),{},{angle:Math.atan2(i.destY-i.y,i.destX-i.x)});case"L":return T(T({},new D(i.x,i.y).lerp(new D(r[1],r[2]),n)),{},{angle:Math.atan2(r[2]-i.y,r[1]-i.x)});case"C":case"Q":return W_(i,t)}},U_=new RegExp("[mzlhvcsqta][^mzlhvcsqta]*","gi"),y0=new RegExp(j_,"g"),Y_=new RegExp(Is,"gi"),$_={m:2,l:2,h:1,v:1,c:6,s:4,q:4,t:2,a:7},v0=a=>{var t;const e=[],s=(t=a.match(U_))!==null&&t!==void 0?t:[];for(const i of s){const n=i[0];if(n==="z"||n==="Z"){e.push([n]);continue}const r=$_[n.toLowerCase()];let o=[];if(n==="a"||n==="A"){y0.lastIndex=0;for(let h=null;h=y0.exec(i);)o.push(...h.slice(1))}else o=i.match(Y_)||[];for(let h=0;h<o.length;h+=r){const c=new Array(r),u=B_[n];c[0]=h>0&&u?u:n;for(let d=0;d<r;d++)c[d+1]=parseFloat(o[h+d]);e.push(c)}}return e},q_=function(a){let t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:0,e=new D(a[0]),s=new D(a[1]),i=1,n=0;const r=[],o=a.length,h=o>2;let c;for(h&&(i=a[2].x<s.x?-1:a[2].x===s.x?0:1,n=a[2].y<s.y?-1:a[2].y===s.y?0:1),r.push(["M",e.x-i*t,e.y-n*t]),c=1;c<o;c++){if(!e.eq(s)){const u=e.midPointFrom(s);r.push(["Q",e.x,e.y,u.x,u.y])}e=a[c],c+1<a.length&&(s=a[c+1])}return h&&(i=e.x>a[c-2].x?1:e.x===a[c-2].x?0:-1,n=e.y>a[c-2].y?1:e.y===a[c-2].y?0:-1),r.push(["L",e.x+i*t,e.y+n*t]),r},_0=(a,t)=>a.map(e=>e.map((s,i)=>i===0||t===void 0?s:At(s,t)).join(" ")).join(" ");function gu(a,t){const e=a.style;e&&t&&(typeof t=="string"?e.cssText+=";"+t:Object.entries(t).forEach(s=>{let[i,n]=s;return e.setProperty(i,n)}))}const K_=(a,t)=>Math.floor(Math.random()*(t-a+1))+a;function w0(a){let t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};const e=t.onComplete||pr,s=new(Hc()).XMLHttpRequest,i=t.signal,n=function(){s.abort()},r=function(){i&&i.removeEventListener("abort",n),s.onerror=s.ontimeout=pr};if(i&&i.aborted)throw new nf("request");return i&&i.addEventListener("abort",n,{once:!0}),s.onreadystatechange=function(){s.readyState===4&&(r(),e(s),s.onreadystatechange=pr)},s.onerror=s.ontimeout=r,s.open("get",a,!0),s.send(),s}const pu=(a,t)=>{let e=a._findCenterFromElement();a.transformMatrix&&((s=>{if(s.transformMatrix){const{scaleX:i,scaleY:n,angle:r,skewX:o}=br(s.transformMatrix);s.flipX=!1,s.flipY=!1,s.set(Me,i),s.set(Je,n),s.angle=r,s.skewX=o,s.skewY=0}})(a),e=e.transform(a.transformMatrix)),delete a.transformMatrix,t&&(a.scaleX*=t.scaleX,a.scaleY*=t.scaleY,a.cropX=t.cropX,a.cropY=t.cropY,e.x+=t.offsetLeft,e.y+=t.offsetTop,a.width=t.width,a.height=t.height),a.setPositionByOrigin(e,Q,Q)};var Q_=Object.freeze({__proto__:null,addTransformToObject:pm,animate:Ff,animateColor:Fm,applyTransformToObject:Ko,calcAngleBetweenVectors:su,calcDimensionsMatrix:Ah,calcPlaneChangeMatrix:Dh,calcVectorRotation:km,cancelAnimFrame:Qp,capValue:wr,composeMatrix:sm,copyCanvasElement:a=>{var t;const e=Rs(a);return(t=e.getContext("2d"))===null||t===void 0||t.drawImage(a,0,0),e},cos:Ds,createCanvasElement:ms,createImage:Jp,createRotateMatrix:$o,createScaleMatrix:$c,createSkewXMatrix:pf,createSkewYMatrix:mf,createTranslateMatrix:Yo,createVector:tu,crossProduct:Qo,degreesToRadians:Rt,dotProduct:Mm,ease:Bv,enlivenObjectEnlivables:Eh,enlivenObjects:qo,findScaleToCover:l0,findScaleToFit:h0,getBoundsOfCurve:Xf,getOrthonormalVector:Mf,getPathSegmentsInfo:Wf,getPointOnPath:b0,getPointer:gm,getRandomInt:K_,getRegularPolygonPath:(a,t)=>{const e=2*Math.PI/a;let s=-An;a%2==0&&(s+=e/2);const i=new Array(a+1);for(let n=0;n<a;n++){const r=n*e+s,{x:o,y:h}=new D(Ds(r),Os(r)).scalarMultiply(t);i[n]=[n===0?"M":"L",o,h]}return i[a]=["Z"],i},getSmoothPathFromPoints:q_,getSvgAttributes:a=>{const t=["instantiated_by_use","style","id","class"];switch(a){case"linearGradient":return t.concat(["x1","y1","x2","y2","gradientUnits","gradientTransform"]);case"radialGradient":return t.concat(["gradientUnits","gradientTransform","cx","cy","r","fx","fy","fr"]);case"stop":return t.concat(["offset","stop-color","stop-opacity"])}return t},getUnitVector:iu,groupSVGElements:(a,t)=>a&&a.length===1?a[0]:new ai(a,t),hasStyleChanged:hu,invertTransform:Xe,isBetweenVectors:Pf,isIdentityMatrix:Zp,isTouchEvent:Kc,isTransparent:Xm,joinPath:_0,loadImage:Th,magnitude:eu,makeBoundingBoxFromPoints:ri,makePathSimpler:u0,matrixToSVG:kh,mergeClipPaths:(a,t)=>{var e;let s=a,i=t;s.inverted&&!i.inverted&&(s=t,i=a),Sf(i,(e=i.group)===null||e===void 0?void 0:e.calcTransformMatrix(),s.calcTransformMatrix());const n=s.inverted&&i.inverted;return n&&(s.inverted=i.inverted=!1),new ai([s],{clipPath:i,inverted:n})},multiplyTransformMatrices:Nt,multiplyTransformMatrixArray:Yc,parsePath:v0,parsePreserveAspectRatioAttribute:vf,parseUnit:De,pick:yr,projectStrokeOnPoints:Ym,qrDecompose:br,radiansToDegrees:kn,removeFromArray:mr,removeTransformFromObject:(a,t)=>{const e=Xe(t),s=Nt(e,a.calcOwnMatrix());Ko(a,s)},removeTransformMatrixForSvgParsing:pu,request:w0,requestAnimFrame:Ch,resetObjectTransform:mm,rotatePoint:(a,t,e)=>a.rotate(e,t),rotateVector:kf,saveObjectTransform:xf,sendObjectToPlane:Sf,sendPointToPlane:_r,sendVectorToPlane:bm,setStyle:gu,sin:Os,sizeAfterTransform:Qc,string:f_,stylesFromArray:Km,stylesToArray:qm,toBlob:gf,toDataURL:ff,toFixed:At,transformPath:(a,t,e)=>(e&&(t=Nt(t,[1,0,0,1,-e.x,-e.y])),a.map(s=>{const i=[...s];for(let n=1;n<s.length-1;n+=2){const{x:r,y:o}=ge({x:s[n],y:s[n+1]},t);i[n]=r,i[n+1]=o}return i})),transformPoint:ge});class J_ extends fm{constructor(t){let{allowTouchScrolling:e=!1,containerClass:s=""}=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};super(t),A(this,"upper",void 0),A(this,"container",void 0);const{el:i}=this.lower,n=this.createUpperCanvas();this.upper={el:n,ctx:n.getContext("2d")},this.applyCanvasStyle(i,{allowTouchScrolling:e}),this.applyCanvasStyle(n,{allowTouchScrolling:e,styles:{position:"absolute",left:"0",top:"0"}});const r=this.createContainerElement();r.classList.add(s),i.parentNode&&i.parentNode.replaceChild(r,i),r.append(i,n),this.container=r}createUpperCanvas(){const{el:t}=this.lower,e=ms();return e.className=t.className,e.classList.remove("lower-canvas"),e.classList.add("upper-canvas"),e.setAttribute("data-fabric","top"),e.style.cssText=t.style.cssText,e.setAttribute("draggable","true"),e}createContainerElement(){const t=Vo().createElement("div");return t.setAttribute("data-fabric","wrapper"),gu(t,{position:"relative"}),dm(t),t}applyCanvasStyle(t,e){const{styles:s,allowTouchScrolling:i}=e;gu(t,T(T({},s),{},{"touch-action":i?"manipulation":ke})),dm(t)}setDimensions(t,e){super.setDimensions(t,e);const{el:s,ctx:i}=this.upper;um(s,i,t,e)}setCSSDimensions(t){super.setCSSDimensions(t),_f(this.upper.el,t),_f(this.container,t)}cleanupDOM(t){const e=this.container,{el:s}=this.lower,{el:i}=this.upper;super.cleanupDOM(t),e.removeChild(i),e.removeChild(s),e.parentNode&&e.parentNode.replaceChild(s,e)}dispose(){super.dispose(),ni().dispose(this.upper.el),delete this.upper,delete this.container}}class mu extends Ph{constructor(){super(...arguments),A(this,"targets",[]),A(this,"_hoveredTargets",[]),A(this,"_objectsToRender",void 0),A(this,"_currentTransform",null),A(this,"_groupSelector",null),A(this,"contextTopDirty",!1)}static getDefaults(){return T(T({},super.getDefaults()),mu.ownDefaults)}get upperCanvasEl(){var t;return(t=this.elements.upper)===null||t===void 0?void 0:t.el}get contextTop(){var t;return(t=this.elements.upper)===null||t===void 0?void 0:t.ctx}get wrapperEl(){return this.elements.container}initElements(t){this.elements=new J_(t,{allowTouchScrolling:this.allowTouchScrolling,containerClass:this.containerClass}),this._createCacheCanvas()}_onObjectAdded(t){this._objectsToRender=void 0,super._onObjectAdded(t)}_onObjectRemoved(t){this._objectsToRender=void 0,t===this._activeObject&&(this.fire("before:selection:cleared",{deselected:[t]}),this._discardActiveObject(),this.fire("selection:cleared",{deselected:[t]}),t.fire("deselected",{target:t})),t===this._hoveredTarget&&(this._hoveredTarget=void 0,this._hoveredTargets=[]),super._onObjectRemoved(t)}_onStackOrderChanged(){this._objectsToRender=void 0,super._onStackOrderChanged()}_chooseObjectsToRender(){const t=this._activeObject;return!this.preserveObjectStacking&&t?this._objects.filter(e=>!e.group&&e!==t).concat(t):this._objects}renderAll(){this.cancelRequestedRender(),this.destroyed||(!this.contextTopDirty||this._groupSelector||this.isDrawingMode||(this.clearContext(this.contextTop),this.contextTopDirty=!1),this.hasLostContext&&(this.renderTopLayer(this.contextTop),this.hasLostContext=!1),!this._objectsToRender&&(this._objectsToRender=this._chooseObjectsToRender()),this.renderCanvas(this.getContext(),this._objectsToRender))}renderTopLayer(t){t.save(),this.isDrawingMode&&this._isCurrentlyDrawing&&(this.freeDrawingBrush&&this.freeDrawingBrush._render(),this.contextTopDirty=!0),this.selection&&this._groupSelector&&(this._drawSelection(t),this.contextTopDirty=!0),t.restore()}renderTop(){const t=this.contextTop;this.clearContext(t),this.renderTopLayer(t),this.fire("after:render",{ctx:t})}setTargetFindTolerance(t){t=Math.round(t),this.targetFindTolerance=t;const e=this.getRetinaScaling(),s=Math.ceil((2*t+1)*e);this.pixelFindCanvasEl.width=this.pixelFindCanvasEl.height=s,this.pixelFindContext.scale(e,e)}isTargetTransparent(t,e,s){const i=this.targetFindTolerance,n=this.pixelFindContext;this.clearContext(n),n.save(),n.translate(-e+i,-s+i),n.transform(...this.viewportTransform);const r=t.selectionBackgroundColor;t.selectionBackgroundColor="",t.render(n),t.selectionBackgroundColor=r,n.restore();const o=Math.round(i*this.getRetinaScaling());return Xm(n,o,o,o)}_isSelectionKeyPressed(t){const e=this.selectionKey;return!!e&&(Array.isArray(e)?!!e.find(s=>!!s&&t[s]===!0):t[e])}_shouldClearSelection(t,e){const s=this.getActiveObjects(),i=this._activeObject;return!!(!e||e&&i&&s.length>1&&s.indexOf(e)===-1&&i!==e&&!this._isSelectionKeyPressed(t)||e&&!e.evented||e&&!e.selectable&&i&&i!==e)}_shouldCenterTransform(t,e,s){if(!t)return;let i;return e===Vc||e===Me||e===Je||e===Sh?i=this.centeredScaling||t.centeredScaling:e===cf&&(i=this.centeredRotation||t.centeredRotation),i?!s:s}_getOriginFromCorner(t,e){const s={x:t.originX,y:t.originY};return e&&(["ml","tl","bl"].includes(e)?s.x=It:["mr","tr","br"].includes(e)&&(s.x=dt),["tl","mt","tr"].includes(e)?s.y=hf:["bl","mb","br"].includes(e)&&(s.y=Ve)),s}_setupCurrentTransform(t,e,s){var i;const n=e.group?_r(this.getScenePoint(t),void 0,e.group.calcTransformMatrix()):this.getScenePoint(t),{key:r="",control:o}=e.getActiveControl()||{},h=s&&o?(i=o.getActionHandler(t,e,o))===null||i===void 0?void 0:i.bind(o):Dv,c=((g,p,b,_)=>{if(!p||!g)return"drag";const v=_.controls[p];return v.getActionName(b,v,_)})(s,r,t,e),u=t[this.centeredKey],d=this._shouldCenterTransform(e,c,u)?{x:Q,y:Q}:this._getOriginFromCorner(e,r),f={target:e,action:c,actionHandler:h,actionPerformed:!1,corner:r,scaleX:e.scaleX,scaleY:e.scaleY,skewX:e.skewX,skewY:e.skewY,offsetX:n.x-e.left,offsetY:n.y-e.top,originX:d.x,originY:d.y,ex:n.x,ey:n.y,lastX:n.x,lastY:n.y,theta:Rt(e.angle),width:e.width,height:e.height,shiftKey:t.shiftKey,altKey:u,original:T(T({},xf(e)),{},{originX:d.x,originY:d.y})};this._currentTransform=f,this.fire("before:transform",{e:t,transform:f})}setCursor(t){this.upperCanvasEl.style.cursor=t}_drawSelection(t){const{x:e,y:s,deltaX:i,deltaY:n}=this._groupSelector,r=new D(e,s).transform(this.viewportTransform),o=new D(e+i,s+n).transform(this.viewportTransform),h=this.selectionLineWidth/2;let c=Math.min(r.x,o.x),u=Math.min(r.y,o.y),d=Math.max(r.x,o.x),f=Math.max(r.y,o.y);this.selectionColor&&(t.fillStyle=this.selectionColor,t.fillRect(c,u,d-c,f-u)),this.selectionLineWidth&&this.selectionBorderColor&&(t.lineWidth=this.selectionLineWidth,t.strokeStyle=this.selectionBorderColor,c+=h,u+=h,d-=h,f-=h,pe.prototype._setLineDash.call(this,t,this.selectionDashArray),t.strokeRect(c,u,d-c,f-u))}findTarget(t){if(this.skipTargetFind)return;const e=this.getViewportPoint(t),s=this._activeObject,i=this.getActiveObjects();if(this.targets=[],s&&i.length>=1){if(s.findControl(e,Kc(t))||i.length>1&&this.searchPossibleTargets([s],e))return s;if(s===this.searchPossibleTargets([s],e)){if(this.preserveObjectStacking){const n=this.targets;this.targets=[];const r=this.searchPossibleTargets(this._objects,e);return t[this.altSelectionKey]&&r&&r!==s?(this.targets=n,s):r}return s}}return this.searchPossibleTargets(this._objects,e)}_pointIsInObjectSelectionArea(t,e){let s=t.getCoords();const i=this.getZoom(),n=t.padding/i;if(n){const[r,o,h,c]=s,u=Math.atan2(o.y-r.y,o.x-r.x),d=Ds(u)*n,f=Os(u)*n,g=d+f,p=d-f;s=[new D(r.x-p,r.y-g),new D(o.x+g,o.y-p),new D(h.x+p,h.y+g),new D(c.x-g,c.y+p)]}return Mt.isPointInPolygon(e,s)}_checkTarget(t,e){return!!(t&&t.visible&&t.evented&&this._pointIsInObjectSelectionArea(t,_r(e,void 0,this.viewportTransform))&&(!this.perPixelTargetFind&&!t.perPixelTargetFind||t.isEditing||!this.isTargetTransparent(t,e.x,e.y)))}_searchPossibleTargets(t,e){let s=t.length;for(;s--;){const i=t[s];if(this._checkTarget(i,e)){if(Uc(i)&&i.subTargetCheck){const n=this._searchPossibleTargets(i._objects,e);n&&this.targets.push(n)}return i}}}searchPossibleTargets(t,e){const s=this._searchPossibleTargets(t,e);if(s&&Uc(s)&&s.interactive&&this.targets[0]){const i=this.targets;for(let n=i.length-1;n>0;n--){const r=i[n];if(!Uc(r)||!r.interactive)return r}return i[0]}return s}getViewportPoint(t){return this._pointer?this._pointer:this.getPointer(t,!0)}getScenePoint(t){return this._absolutePointer?this._absolutePointer:this.getPointer(t)}getPointer(t){let e=arguments.length>1&&arguments[1]!==void 0&&arguments[1];const s=this.upperCanvasEl,i=s.getBoundingClientRect();let n=gm(t),r=i.width||0,o=i.height||0;r&&o||(Ve in i&&hf in i&&(o=Math.abs(i.top-i.bottom)),It in i&&dt in i&&(r=Math.abs(i.right-i.left))),this.calcOffset(),n.x=n.x-this._offset.left,n.y=n.y-this._offset.top,e||(n=_r(n,void 0,this.viewportTransform));const h=this.getRetinaScaling();h!==1&&(n.x/=h,n.y/=h);const c=r===0||o===0?new D(1,1):new D(s.width/r,s.height/o);return n.multiply(c)}_setDimensionsImpl(t,e){this._resetTransformEventData(),super._setDimensionsImpl(t,e),this._isCurrentlyDrawing&&this.freeDrawingBrush&&this.freeDrawingBrush._setBrushStyles(this.contextTop)}_createCacheCanvas(){this.pixelFindCanvasEl=ms(),this.pixelFindContext=this.pixelFindCanvasEl.getContext("2d",{willReadFrequently:!0}),this.setTargetFindTolerance(this.targetFindTolerance)}getTopContext(){return this.elements.upper.ctx}getSelectionContext(){return this.elements.upper.ctx}getSelectionElement(){return this.elements.upper.el}getActiveObject(){return this._activeObject}getActiveObjects(){const t=this._activeObject;return vr(t)?t.getObjects():t?[t]:[]}_fireSelectionEvents(t,e){let s=!1,i=!1;const n=this.getActiveObjects(),r=[],o=[];t.forEach(h=>{n.includes(h)||(s=!0,h.fire("deselected",{e,target:h}),o.push(h))}),n.forEach(h=>{t.includes(h)||(s=!0,h.fire("selected",{e,target:h}),r.push(h))}),t.length>0&&n.length>0?(i=!0,s&&this.fire("selection:updated",{e,selected:r,deselected:o})):n.length>0?(i=!0,this.fire("selection:created",{e,selected:r})):t.length>0&&(i=!0,this.fire("selection:cleared",{e,deselected:o})),i&&(this._objectsToRender=void 0)}setActiveObject(t,e){const s=this.getActiveObjects(),i=this._setActiveObject(t,e);return this._fireSelectionEvents(s,e),i}_setActiveObject(t,e){const s=this._activeObject;return s!==t&&!(!this._discardActiveObject(e,t)&&this._activeObject)&&!t.onSelect({e})&&(this._activeObject=t,vr(t)&&s!==t&&t.set("canvas",this),t.setCoords(),!0)}_discardActiveObject(t,e){const s=this._activeObject;return!!s&&!s.onDeselect({e:t,object:e})&&(this._currentTransform&&this._currentTransform.target===s&&this.endCurrentTransform(t),vr(s)&&s===this._hoveredTarget&&(this._hoveredTarget=void 0),this._activeObject=void 0,!0)}discardActiveObject(t){const e=this.getActiveObjects(),s=this.getActiveObject();e.length&&this.fire("before:selection:cleared",{e:t,deselected:[s]});const i=this._discardActiveObject(t);return this._fireSelectionEvents(e,t),i}endCurrentTransform(t){const e=this._currentTransform;this._finalizeCurrentTransform(t),e&&e.target&&(e.target.isMoving=!1),this._currentTransform=null}_finalizeCurrentTransform(t){const e=this._currentTransform,s=e.target,i={e:t,target:s,transform:e,action:e.action};s._scaling&&(s._scaling=!1),s.setCoords(),e.actionPerformed&&(this.fire("object:modified",i),s.fire(Xc,i))}setViewportTransform(t){super.setViewportTransform(t);const e=this._activeObject;e&&e.setCoords()}destroy(){const t=this._activeObject;vr(t)&&(t.removeAll(),t.dispose()),delete this._activeObject,super.destroy(),this.pixelFindContext=null,this.pixelFindCanvasEl=void 0}clear(){this.discardActiveObject(),this._activeObject=void 0,this.clearContext(this.contextTop),super.clear()}drawControls(t){const e=this._activeObject;e&&e._renderControls(t)}_toObject(t,e,s){const i=this._realizeGroupTransformOnObject(t),n=super._toObject(t,e,s);return t.set(i),n}_realizeGroupTransformOnObject(t){const{group:e}=t;if(e&&vr(e)&&this._activeObject===e){const s=yr(t,["angle","flipX","flipY",dt,Me,Je,Xo,Wo,Ve]);return pm(t,e.calcOwnMatrix()),s}return{}}_setSVGObject(t,e,s){const i=this._realizeGroupTransformOnObject(e);super._setSVGObject(t,e,s),e.set(i)}}A(mu,"ownDefaults",{uniformScaling:!0,uniScaleKey:"shiftKey",centeredScaling:!1,centeredRotation:!1,centeredKey:"altKey",altActionKey:"shiftKey",selection:!0,selectionKey:"shiftKey",selectionColor:"rgba(100, 100, 255, 0.3)",selectionDashArray:[],selectionBorderColor:"rgba(255, 255, 255, 0.3)",selectionLineWidth:1,selectionFullyContained:!1,hoverCursor:"move",moveCursor:"move",defaultCursor:"default",freeDrawingCursor:"crosshair",notAllowedCursor:"not-allowed",perPixelTargetFind:!1,targetFindTolerance:0,skipTargetFind:!1,stopContextMenu:!1,fireRightClick:!1,fireMiddleClick:!1,enablePointerEvents:!1,containerClass:"canvas-container",preserveObjectStacking:!1});class Z_{constructor(t){A(this,"targets",[]),A(this,"__disposer",void 0);const e=()=>{const{hiddenTextarea:i}=t.getActiveObject()||{};i&&i.focus()},s=t.upperCanvasEl;s.addEventListener("click",e),this.__disposer=()=>s.removeEventListener("click",e)}exitTextEditing(){this.target=void 0,this.targets.forEach(t=>{t.isEditing&&t.exitEditing()})}add(t){this.targets.push(t)}remove(t){this.unregister(t),mr(this.targets,t)}register(t){this.target=t}unregister(t){t===this.target&&(this.target=void 0)}onMouseMove(t){var e;!((e=this.target)===null||e===void 0)&&e.isEditing&&this.target.updateSelectionOnMouseMove(t)}clear(){this.targets=[],this.target=void 0}dispose(){this.clear(),this.__disposer(),delete this.__disposer}}const tw=["target","oldTarget","fireCanvas","e"],Ze={passive:!1},sa=(a,t)=>{const e=a.getViewportPoint(t),s=a.getScenePoint(t);return{viewportPoint:e,scenePoint:s,pointer:e,absolutePointer:s}},Pn=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 a.addEventListener(...e)},ys=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 a.removeEventListener(...e)},ew={mouse:{in:"over",out:"out",targetIn:"mouseover",targetOut:"mouseout",canvasIn:"mouse:over",canvasOut:"mouse:out"},drag:{in:"enter",out:"leave",targetIn:"dragenter",targetOut:"dragleave",canvasIn:"drag:enter",canvasOut:"drag:leave"}};class Uf extends mu{constructor(t){super(t,arguments.length>1&&arguments[1]!==void 0?arguments[1]:{}),A(this,"_isClick",void 0),A(this,"textEditingManager",new Z_(this)),["_onMouseDown","_onTouchStart","_onMouseMove","_onMouseUp","_onTouchEnd","_onResize","_onMouseWheel","_onMouseOut","_onMouseEnter","_onContextMenu","_onDoubleClick","_onDragStart","_onDragEnd","_onDragProgress","_onDragOver","_onDragEnter","_onDragLeave","_onDrop"].forEach(e=>{this[e]=this[e].bind(this)}),this.addOrRemove(Pn,"add")}_getEventPrefix(){return this.enablePointerEvents?"pointer":"mouse"}addOrRemove(t,e){const s=this.upperCanvasEl,i=this._getEventPrefix();t(cm(s),"resize",this._onResize),t(s,i+"down",this._onMouseDown),t(s,"".concat(i,"move"),this._onMouseMove,Ze),t(s,"".concat(i,"out"),this._onMouseOut),t(s,"".concat(i,"enter"),this._onMouseEnter),t(s,"wheel",this._onMouseWheel),t(s,"contextmenu",this._onContextMenu),t(s,"dblclick",this._onDoubleClick),t(s,"dragstart",this._onDragStart),t(s,"dragend",this._onDragEnd),t(s,"dragover",this._onDragOver),t(s,"dragenter",this._onDragEnter),t(s,"dragleave",this._onDragLeave),t(s,"drop",this._onDrop),this.enablePointerEvents||t(s,"touchstart",this._onTouchStart,Ze)}removeListeners(){this.addOrRemove(ys,"remove");const t=this._getEventPrefix(),e=Ls(this.upperCanvasEl);ys(e,"".concat(t,"up"),this._onMouseUp),ys(e,"touchend",this._onTouchEnd,Ze),ys(e,"".concat(t,"move"),this._onMouseMove,Ze),ys(e,"touchmove",this._onMouseMove,Ze),clearTimeout(this._willAddMouseDown)}_onMouseWheel(t){this.__onMouseWheel(t)}_onMouseOut(t){const e=this._hoveredTarget,s=T({e:t},sa(this,t));this.fire("mouse:out",T(T({},s),{},{target:e})),this._hoveredTarget=void 0,e&&e.fire("mouseout",T({},s)),this._hoveredTargets.forEach(i=>{this.fire("mouse:out",T(T({},s),{},{target:i})),i&&i.fire("mouseout",T({},s))}),this._hoveredTargets=[]}_onMouseEnter(t){this._currentTransform||this.findTarget(t)||(this.fire("mouse:over",T({e:t},sa(this,t))),this._hoveredTarget=void 0,this._hoveredTargets=[])}_onDragStart(t){this._isClick=!1;const e=this.getActiveObject();if(e&&e.onDragStart(t)){this._dragSource=e;const s={e:t,target:e};return this.fire("dragstart",s),e.fire("dragstart",s),void Pn(this.upperCanvasEl,"drag",this._onDragProgress)}wf(t)}_renderDragEffects(t,e,s){let i=!1;const n=this._dropTarget;n&&n!==e&&n!==s&&(n.clearContextTop(),i=!0),e==null||e.clearContextTop(),s!==e&&(s==null||s.clearContextTop());const r=this.contextTop;r.save(),r.transform(...this.viewportTransform),e&&(r.save(),e.transform(r),e.renderDragSourceEffect(t),r.restore(),i=!0),s&&(r.save(),s.transform(r),s.renderDropTargetEffect(t),r.restore(),i=!0),r.restore(),i&&(this.contextTopDirty=!0)}_onDragEnd(t){const e=!!t.dataTransfer&&t.dataTransfer.dropEffect!==ke,s=e?this._activeObject:void 0,i={e:t,target:this._dragSource,subTargets:this.targets,dragSource:this._dragSource,didDrop:e,dropTarget:s};ys(this.upperCanvasEl,"drag",this._onDragProgress),this.fire("dragend",i),this._dragSource&&this._dragSource.fire("dragend",i),delete this._dragSource,this._onMouseUp(t)}_onDragProgress(t){const e={e:t,target:this._dragSource,dragSource:this._dragSource,dropTarget:this._draggedoverTarget};this.fire("drag",e),this._dragSource&&this._dragSource.fire("drag",e)}findDragTargets(t){return this.targets=[],{target:this._searchPossibleTargets(this._objects,this.getViewportPoint(t)),targets:[...this.targets]}}_onDragOver(t){const e="dragover",{target:s,targets:i}=this.findDragTargets(t),n=this._dragSource,r={e:t,target:s,subTargets:i,dragSource:n,canDrop:!1,dropTarget:void 0};let o;this.fire(e,r),this._fireEnterLeaveEvents(s,r),s&&(s.canDrop(t)&&(o=s),s.fire(e,r));for(let h=0;h<i.length;h++){const c=i[h];c.canDrop(t)&&(o=c),c.fire(e,r)}this._renderDragEffects(t,n,o),this._dropTarget=o}_onDragEnter(t){const{target:e,targets:s}=this.findDragTargets(t),i={e:t,target:e,subTargets:s,dragSource:this._dragSource};this.fire("dragenter",i),this._fireEnterLeaveEvents(e,i)}_onDragLeave(t){const e={e:t,target:this._draggedoverTarget,subTargets:this.targets,dragSource:this._dragSource};this.fire("dragleave",e),this._fireEnterLeaveEvents(void 0,e),this._renderDragEffects(t,this._dragSource),this._dropTarget=void 0,this.targets=[],this._hoveredTargets=[]}_onDrop(t){const{target:e,targets:s}=this.findDragTargets(t),i=this._basicEventHandler("drop:before",T({e:t,target:e,subTargets:s,dragSource:this._dragSource},sa(this,t)));i.didDrop=!1,i.dropTarget=void 0,this._basicEventHandler("drop",i),this.fire("drop:after",i)}_onContextMenu(t){const e=this.findTarget(t),s=this.targets||[],i=this._basicEventHandler("contextmenu:before",{e:t,target:e,subTargets:s});return this.stopContextMenu&&wf(t),this._basicEventHandler("contextmenu",i),!1}_onDoubleClick(t){this._cacheTransformEventData(t),this._handleEvent(t,"dblclick"),this._resetTransformEventData()}getPointerId(t){const e=t.changedTouches;return e?e[0]&&e[0].identifier:this.enablePointerEvents?t.pointerId:-1}_isMainEvent(t){return t.isPrimary===!0||t.isPrimary!==!1&&(t.type==="touchend"&&t.touches.length===0||!t.changedTouches||t.changedTouches[0].identifier===this.mainTouchId)}_onTouchStart(t){let e=!this.allowTouchScrolling;const s=this._activeObject;this.mainTouchId===void 0&&(this.mainTouchId=this.getPointerId(t)),this.__onMouseDown(t),(this.isDrawingMode||s&&this._target===s)&&(e=!0),e&&t.preventDefault(),this._resetTransformEventData();const i=this.upperCanvasEl,n=this._getEventPrefix(),r=Ls(i);Pn(r,"touchend",this._onTouchEnd,Ze),e&&Pn(r,"touchmove",this._onMouseMove,Ze),ys(i,"".concat(n,"down"),this._onMouseDown)}_onMouseDown(t){this.__onMouseDown(t),this._resetTransformEventData();const e=this.upperCanvasEl,s=this._getEventPrefix();ys(e,"".concat(s,"move"),this._onMouseMove,Ze);const i=Ls(e);Pn(i,"".concat(s,"up"),this._onMouseUp),Pn(i,"".concat(s,"move"),this._onMouseMove,Ze)}_onTouchEnd(t){if(t.touches.length>0)return;this.__onMouseUp(t),this._resetTransformEventData(),delete this.mainTouchId;const e=this._getEventPrefix(),s=Ls(this.upperCanvasEl);ys(s,"touchend",this._onTouchEnd,Ze),ys(s,"touchmove",this._onMouseMove,Ze),this._willAddMouseDown&&clearTimeout(this._willAddMouseDown),this._willAddMouseDown=setTimeout(()=>{Pn(this.upperCanvasEl,"".concat(e,"down"),this._onMouseDown),this._willAddMouseDown=0},400)}_onMouseUp(t){this.__onMouseUp(t),this._resetTransformEventData();const e=this.upperCanvasEl,s=this._getEventPrefix();if(this._isMainEvent(t)){const i=Ls(this.upperCanvasEl);ys(i,"".concat(s,"up"),this._onMouseUp),ys(i,"".concat(s,"move"),this._onMouseMove,Ze),Pn(e,"".concat(s,"move"),this._onMouseMove,Ze)}}_onMouseMove(t){const e=this.getActiveObject();!this.allowTouchScrolling&&(!e||!e.shouldStartDragging(t))&&t.preventDefault&&t.preventDefault(),this.__onMouseMove(t)}_onResize(){this.calcOffset(),this._resetTransformEventData()}_shouldRender(t){const e=this.getActiveObject();return!!e!=!!t||e&&t&&e!==t}__onMouseUp(t){var e;this._cacheTransformEventData(t),this._handleEvent(t,"up:before");const s=this._currentTransform,i=this._isClick,n=this._target,{button:r}=t;if(r)return(this.fireMiddleClick&&r===1||this.fireRightClick&&r===2)&&this._handleEvent(t,"up"),void this._resetTransformEventData();if(this.isDrawingMode&&this._isCurrentlyDrawing)return void this._onMouseUpInDrawingMode(t);if(!this._isMainEvent(t))return;let o,h,c=!1;if(s&&(this._finalizeCurrentTransform(t),c=s.actionPerformed),!i){const u=n===this._activeObject;this.handleSelection(t),c||(c=this._shouldRender(n)||!u&&n===this._activeObject)}if(n){const u=n.findControl(this.getViewportPoint(t),Kc(t)),{key:d,control:f}=u||{};if(h=d,n.selectable&&n!==this._activeObject&&n.activeOn==="up")this.setActiveObject(n,t),c=!0;else if(f){const g=f.getMouseUpHandler(t,n,f);g&&(o=this.getScenePoint(t),g.call(f,t,s,o.x,o.y))}n.isMoving=!1}if(s&&(s.target!==n||s.corner!==h)){const u=s.target&&s.target.controls[s.corner],d=u&&u.getMouseUpHandler(t,s.target,u);o=o||this.getScenePoint(t),d&&d.call(u,t,s,o.x,o.y)}this._setCursorFromEvent(t,n),this._handleEvent(t,"up"),this._groupSelector=null,this._currentTransform=null,n&&(n.__corner=void 0),c?this.requestRenderAll():i||(e=this._activeObject)!==null&&e!==void 0&&e.isEditing||this.renderTop()}_basicEventHandler(t,e){const{target:s,subTargets:i=[]}=e;this.fire(t,e),s&&s.fire(t,e);for(let n=0;n<i.length;n++)i[n]!==s&&i[n].fire(t,e);return e}_handleEvent(t,e){const s=this._target,i=this.targets||[],n=T(T({e:t,target:s,subTargets:i},sa(this,t)),{},{transform:this._currentTransform},e==="up:before"||e==="up"?{isClick:this._isClick,currentTarget:this.findTarget(t),currentSubTargets:this.targets}:{});this.fire("mouse:".concat(e),n),s&&s.fire("mouse".concat(e),n);for(let r=0;r<i.length;r++)i[r]!==s&&i[r].fire("mouse".concat(e),n)}_onMouseDownInDrawingMode(t){this._isCurrentlyDrawing=!0,this.getActiveObject()&&(this.discardActiveObject(t),this.requestRenderAll());const e=this.getScenePoint(t);this.freeDrawingBrush&&this.freeDrawingBrush.onMouseDown(e,{e:t,pointer:e}),this._handleEvent(t,"down")}_onMouseMoveInDrawingMode(t){if(this._isCurrentlyDrawing){const e=this.getScenePoint(t);this.freeDrawingBrush&&this.freeDrawingBrush.onMouseMove(e,{e:t,pointer:e})}this.setCursor(this.freeDrawingCursor),this._handleEvent(t,"move")}_onMouseUpInDrawingMode(t){const e=this.getScenePoint(t);this.freeDrawingBrush?this._isCurrentlyDrawing=!!this.freeDrawingBrush.onMouseUp({e:t,pointer:e}):this._isCurrentlyDrawing=!1,this._handleEvent(t,"up")}__onMouseDown(t){this._isClick=!0,this._cacheTransformEventData(t),this._handleEvent(t,"down:before");let e=this._target;const{button:s}=t;if(s)return(this.fireMiddleClick&&s===1||this.fireRightClick&&s===2)&&this._handleEvent(t,"down"),void this._resetTransformEventData();if(this.isDrawingMode)return void this._onMouseDownInDrawingMode(t);if(!this._isMainEvent(t)||this._currentTransform)return;let i=this._shouldRender(e),n=!1;if(this.handleMultiSelection(t,e)?(e=this._activeObject,n=!0,i=!0):this._shouldClearSelection(t,e)&&this.discardActiveObject(t),this.selection&&(!e||!e.selectable&&!e.isEditing&&e!==this._activeObject)){const r=this.getScenePoint(t);this._groupSelector={x:r.x,y:r.y,deltaY:0,deltaX:0}}if(e){const r=e===this._activeObject;e.selectable&&e.activeOn==="down"&&this.setActiveObject(e,t);const o=e.findControl(this.getViewportPoint(t),Kc(t));if(e===this._activeObject&&(o||!n)){this._setupCurrentTransform(t,e,r);const h=o?o.control:void 0,c=this.getScenePoint(t),u=h&&h.getMouseDownHandler(t,e,h);u&&u.call(h,t,this._currentTransform,c.x,c.y)}}i&&(this._objectsToRender=void 0),this._handleEvent(t,"down"),i&&this.requestRenderAll()}_resetTransformEventData(){this._target=this._pointer=this._absolutePointer=void 0}_cacheTransformEventData(t){this._resetTransformEventData(),this._pointer=this.getViewportPoint(t),this._absolutePointer=_r(this._pointer,void 0,this.viewportTransform),this._target=this._currentTransform?this._currentTransform.target:this.findTarget(t)}__onMouseMove(t){if(this._isClick=!1,this._cacheTransformEventData(t),this._handleEvent(t,"move:before"),this.isDrawingMode)return void this._onMouseMoveInDrawingMode(t);if(!this._isMainEvent(t))return;const e=this._groupSelector;if(e){const s=this.getScenePoint(t);e.deltaX=s.x-e.x,e.deltaY=s.y-e.y,this.renderTop()}else if(this._currentTransform)this._transformObject(t);else{const s=this.findTarget(t);this._setCursorFromEvent(t,s),this._fireOverOutEvents(t,s)}this.textEditingManager.onMouseMove(t),this._handleEvent(t,"move"),this._resetTransformEventData()}_fireOverOutEvents(t,e){const s=this._hoveredTarget,i=this._hoveredTargets,n=this.targets,r=Math.max(i.length,n.length);this.fireSyntheticInOutEvents("mouse",{e:t,target:e,oldTarget:s,fireCanvas:!0});for(let o=0;o<r;o++)this.fireSyntheticInOutEvents("mouse",{e:t,target:n[o],oldTarget:i[o]});this._hoveredTarget=e,this._hoveredTargets=this.targets.concat()}_fireEnterLeaveEvents(t,e){const s=this._draggedoverTarget,i=this._hoveredTargets,n=this.targets,r=Math.max(i.length,n.length);this.fireSyntheticInOutEvents("drag",T(T({},e),{},{target:t,oldTarget:s,fireCanvas:!0}));for(let o=0;o<r;o++)this.fireSyntheticInOutEvents("drag",T(T({},e),{},{target:n[o],oldTarget:i[o]}));this._draggedoverTarget=t}fireSyntheticInOutEvents(t,e){let{target:s,oldTarget:i,fireCanvas:n,e:r}=e,o=Ct(e,tw);const{targetIn:h,targetOut:c,canvasIn:u,canvasOut:d}=ew[t],f=i!==s;if(i&&f){const g=T(T({},o),{},{e:r,target:i,nextTarget:s},sa(this,r));n&&this.fire(d,g),i.fire(c,g)}if(s&&f){const g=T(T({},o),{},{e:r,target:s,previousTarget:i},sa(this,r));n&&this.fire(u,g),s.fire(h,g)}}__onMouseWheel(t){this._cacheTransformEventData(t),this._handleEvent(t,"wheel"),this._resetTransformEventData()}_transformObject(t){const e=this.getScenePoint(t),s=this._currentTransform,i=s.target,n=i.group?_r(e,void 0,i.group.calcTransformMatrix()):e;s.shiftKey=t.shiftKey,s.altKey=!!this.centeredKey&&t[this.centeredKey],this._performTransformAction(t,s,n),s.actionPerformed&&this.requestRenderAll()}_performTransformAction(t,e,s){const{action:i,actionHandler:n,target:r}=e,o=!!n&&n(t,e,s.x,s.y);o&&r.setCoords(),i==="drag"&&o&&(e.target.isMoving=!0,this.setCursor(e.target.moveCursor||this.moveCursor)),e.actionPerformed=e.actionPerformed||o}_setCursorFromEvent(t,e){if(!e)return void this.setCursor(this.defaultCursor);let s=e.hoverCursor||this.hoverCursor;const i=vr(this._activeObject)?this._activeObject:null,n=(!i||e.group!==i)&&e.findControl(this.getViewportPoint(t));if(n){const r=n.control;this.setCursor(r.cursorStyleHandler(t,r,e))}else e.subTargetCheck&&this.targets.concat().reverse().map(r=>{s=r.hoverCursor||s}),this.setCursor(s)}handleMultiSelection(t,e){const s=this._activeObject,i=vr(s);if(s&&this._isSelectionKeyPressed(t)&&this.selection&&e&&e.selectable&&(s!==e||i)&&(i||!e.isDescendantOf(s)&&!s.isDescendantOf(e))&&!e.onSelect({e:t})&&!s.getActiveControl()){if(i){const n=s.getObjects();if(e===s){const r=this.getViewportPoint(t);if(!(e=this.searchPossibleTargets(n,r)||this.searchPossibleTargets(this._objects,r))||!e.selectable)return!1}e.group===s?(s.remove(e),this._hoveredTarget=e,this._hoveredTargets=[...this.targets],s.size()===1&&this._setActiveObject(s.item(0),t)):(s.multiSelectAdd(e),this._hoveredTarget=s,this._hoveredTargets=[...this.targets]),this._fireSelectionEvents(n,t)}else{s.isEditing&&s.exitEditing();const n=new(N.getClass("ActiveSelection"))([],{canvas:this});n.multiSelectAdd(s,e),this._hoveredTarget=n,this._setActiveObject(n,t),this._fireSelectionEvents([s],t)}return!0}return!1}handleSelection(t){if(!this.selection||!this._groupSelector)return!1;const{x:e,y:s,deltaX:i,deltaY:n}=this._groupSelector,r=new D(e,s),o=r.add(new D(i,n)),h=r.min(o),c=r.max(o).subtract(h),u=this.collectObjects({left:h.x,top:h.y,width:c.x,height:c.y},{includeIntersecting:!this.selectionFullyContained}),d=r.eq(o)?u[0]?[u[0]]:[]:u.length>1?u.filter(f=>!f.onSelect({e:t})).reverse():u;if(d.length===1)this.setActiveObject(d[0],t);else if(d.length>1){const f=N.getClass("ActiveSelection");this.setActiveObject(new f(d,{canvas:this}),t)}return this._groupSelector=null,!0}clear(){this.textEditingManager.clear(),super.clear()}destroy(){this.removeListeners(),this.textEditingManager.dispose(),super.destroy()}}const x0={x1:0,y1:0,x2:0,y2:0},sw=T(T({},x0),{},{r1:0,r2:0}),ia=(a,t)=>isNaN(a)&&typeof t=="number"?t:a,iw=/^(\d+\.\d+)%|(\d+)%$/;function S0(a){return a&&iw.test(a)}function C0(a,t){const e=typeof a=="number"?a:typeof a=="string"?parseFloat(a)/(S0(a)?100:1):NaN;return wr(0,ia(e,t),1)}const nw=/\s*;\s*/,rw=/\s*:\s*/;function ow(a,t){let e,s;const i=a.getAttribute("style");if(i){const r=i.split(nw);r[r.length-1]===""&&r.pop();for(let o=r.length;o--;){const[h,c]=r[o].split(rw).map(u=>u.trim());h==="stop-color"?e=c:h==="stop-opacity"&&(s=c)}}const n=new gt(e||a.getAttribute("stop-color")||"rgb(0,0,0)");return{offset:C0(a.getAttribute("offset"),0),color:n.toRgb(),opacity:ia(parseFloat(s||a.getAttribute("stop-opacity")||""),1)*n.getAlpha()*t}}function aw(a,t){const e=[],s=a.getElementsByTagName("stop"),i=C0(t,1);for(let n=s.length;n--;)e.push(ow(s[n],i));return e}function A0(a){return a.nodeName==="linearGradient"||a.nodeName==="LINEARGRADIENT"?"linear":"radial"}function T0(a){return a.getAttribute("gradientUnits")==="userSpaceOnUse"?"pixels":"percentage"}function js(a,t){return a.getAttribute(t)}function hw(a,t){return function(e,s){let i,{width:n,height:r,gradientUnits:o}=s;return Object.keys(e).reduce((h,c)=>{const u=e[c];return u==="Infinity"?i=1:u==="-Infinity"?i=0:(i=typeof u=="string"?parseFloat(u):u,typeof u=="string"&&S0(u)&&(i*=.01,o==="pixels"&&(c!=="x1"&&c!=="x2"&&c!=="r2"||(i*=n),c!=="y1"&&c!=="y2"||(i*=r)))),h[c]=i,h},{})}(A0(a)==="linear"?function(e){return{x1:js(e,"x1")||0,y1:js(e,"y1")||0,x2:js(e,"x2")||"100%",y2:js(e,"y2")||0}}(a):function(e){return{x1:js(e,"fx")||js(e,"cx")||"50%",y1:js(e,"fy")||js(e,"cy")||"50%",r1:0,x2:js(e,"cx")||"50%",y2:js(e,"cy")||"50%",r2:js(e,"r")||"50%"}}(a),T(T({},t),{},{gradientUnits:T0(a)}))}class Ih{constructor(t){const{type:e="linear",gradientUnits:s="pixels",coords:i={},colorStops:n=[],offsetX:r=0,offsetY:o=0,gradientTransform:h,id:c}=t||{};Object.assign(this,{type:e,gradientUnits:s,coords:T(T({},e==="radial"?sw:x0),i),colorStops:n,offsetX:r,offsetY:o,gradientTransform:h,id:c?"".concat(c,"_").concat(En()):En()})}addColorStop(t){for(const e in t){const s=new gt(t[e]);this.colorStops.push({offset:parseFloat(e),color:s.toRgb(),opacity:s.getAlpha()})}return this}toObject(t){return T(T({},yr(this,t)),{},{type:this.type,coords:T({},this.coords),colorStops:this.colorStops.map(e=>T({},e)),offsetX:this.offsetX,offsetY:this.offsetY,gradientUnits:this.gradientUnits,gradientTransform:this.gradientTransform?[...this.gradientTransform]:void 0})}toSVG(t){let{additionalTransform:e}=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};const s=[],i=this.gradientTransform?this.gradientTransform.concat():Ee.concat(),n=this.gradientUnits==="pixels"?"userSpaceOnUse":"objectBoundingBox",r=this.colorStops.map(d=>T({},d)).sort((d,f)=>d.offset-f.offset);let o=-this.offsetX,h=-this.offsetY;var c;n==="objectBoundingBox"?(o/=t.width,h/=t.height):(o+=t.width/2,h+=t.height/2),(c=t)&&typeof c._renderPathCommands=="function"&&this.gradientUnits!=="percentage"&&(o-=t.pathOffset.x,h-=t.pathOffset.y),i[4]-=o,i[5]-=h;const u=['id="SVGID_'.concat(this.id,'"'),'gradientUnits="'.concat(n,'"'),'gradientTransform="'.concat(e?e+" ":"").concat(kh(i),'"'),""].join(" ");if(this.type==="linear"){const{x1:d,y1:f,x2:g,y2:p}=this.coords;s.push("<linearGradient ",u,' x1="',d,'" y1="',f,'" x2="',g,'" y2="',p,`">
|
|
42
42
|
`)}else if(this.type==="radial"){const{x1:d,y1:f,x2:g,y2:p,r1:b,r2:_}=this.coords,v=b>_;s.push("<radialGradient ",u,' cx="',v?d:g,'" cy="',v?f:p,'" r="',v?b:_,'" fx="',v?g:d,'" fy="',v?p:f,`">
|
|
43
43
|
`),v&&(r.reverse(),r.forEach(C=>{C.offset=1-C.offset}));const x=Math.min(b,_);if(x>0){const C=x/Math.max(b,_);r.forEach(S=>{S.offset+=C*(1-S.offset)})}}return r.forEach(d=>{let{color:f,offset:g,opacity:p}=d;s.push("<stop ",'offset="',100*g+"%",'" style="stop-color:',f,p!==void 0?";stop-opacity: "+p:";",`"/>
|
|
44
44
|
`)}),s.push(this.type==="linear"?"</linearGradient>":"</radialGradient>",`
|
|
45
|
-
`),s.join("")}toLive(t){const{x1:e,y1:s,x2:i,y2:n,r1:r,r2:o}=this.coords,h=this.type==="linear"?t.createLinearGradient(e,s,i,n):t.createRadialGradient(e,s,r,i,n,o);return this.colorStops.forEach(c=>{let{color:u,opacity:d,offset:f}=c;h.addColorStop(f,d!==void 0?new gt(u).setAlpha(d).toRgba():u)}),h}static async fromObject(t){const{colorStops:e,gradientTransform:s}=t;return new this(T(T({},t),{},{colorStops:e?e.map(i=>T({},i)):void 0,gradientTransform:s?[...s]:void 0}))}static fromElement(t,e,s){const i=T0(t),n=e._findCenterFromElement();return new this(T({id:t.getAttribute("id")||void 0,type:A0(t),coords:
|
|
46
|
-
`)}static async fromObject(t,e){let{type:s,source:i,patternTransform:n}=t,r=Ct(t,
|
|
47
|
-
`)]}_getOffsetTransform(){const t=ht.NUM_FRACTION_DIGITS;return" translate(".concat(At(-this.pathOffset.x,t),", ").concat(At(-this.pathOffset.y,t),")")}toClipPathSVG(t){const e=this._getOffsetTransform();return" "+this._createBaseClipPathSVGMarkup(this._toSVG(),{reviver:t,additionalTransform:e})}toSVG(t){const e=this._getOffsetTransform();return this._createBaseSVGMarkup(this._toSVG(),{reviver:t,additionalTransform:e})}complexity(){return this.path.length}setDimensions(){this.setBoundingBox()}setBoundingBox(t){const{width:e,height:s,pathOffset:i}=this._calcDimensions();this.set({width:e,height:s,pathOffset:i}),t&&this.setPositionByOrigin(i,
|
|
45
|
+
`),s.join("")}toLive(t){const{x1:e,y1:s,x2:i,y2:n,r1:r,r2:o}=this.coords,h=this.type==="linear"?t.createLinearGradient(e,s,i,n):t.createRadialGradient(e,s,r,i,n,o);return this.colorStops.forEach(c=>{let{color:u,opacity:d,offset:f}=c;h.addColorStop(f,d!==void 0?new gt(u).setAlpha(d).toRgba():u)}),h}static async fromObject(t){const{colorStops:e,gradientTransform:s}=t;return new this(T(T({},t),{},{colorStops:e?e.map(i=>T({},i)):void 0,gradientTransform:s?[...s]:void 0}))}static fromElement(t,e,s){const i=T0(t),n=e._findCenterFromElement();return new this(T({id:t.getAttribute("id")||void 0,type:A0(t),coords:hw(t,{width:s.viewBoxWidth||s.width,height:s.viewBoxHeight||s.height}),colorStops:aw(t,s.opacity),gradientUnits:i,gradientTransform:lu(t.getAttribute("gradientTransform")||"")},i==="pixels"?{offsetX:e.width/2-n.x,offsetY:e.height/2-n.y}:{offsetX:0,offsetY:0}))}}A(Ih,"type","Gradient"),N.setClass(Ih,"gradient"),N.setClass(Ih,"linear"),N.setClass(Ih,"radial");const lw=["type","source","patternTransform"];class Yf{get type(){return"pattern"}set type(t){Oi("warn","Setting type has no effect",t)}constructor(t){A(this,"repeat","repeat"),A(this,"offsetX",0),A(this,"offsetY",0),A(this,"crossOrigin",""),this.id=En(),Object.assign(this,t)}isImageSource(){return!!this.source&&typeof this.source.src=="string"}isCanvasSource(){return!!this.source&&!!this.source.toDataURL}sourceToString(){return this.isImageSource()?this.source.src:this.isCanvasSource()?this.source.toDataURL():""}toLive(t){return this.source&&(!this.isImageSource()||this.source.complete&&this.source.naturalWidth!==0&&this.source.naturalHeight!==0)?t.createPattern(this.source,this.repeat):null}toObject(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:[];const{repeat:e,crossOrigin:s}=this;return T(T({},yr(this,t)),{},{type:"pattern",source:this.sourceToString(),repeat:e,crossOrigin:s,offsetX:At(this.offsetX,ht.NUM_FRACTION_DIGITS),offsetY:At(this.offsetY,ht.NUM_FRACTION_DIGITS),patternTransform:this.patternTransform?[...this.patternTransform]:null})}toSVG(t){let{width:e,height:s}=t;const{source:i,repeat:n,id:r}=this,o=ia(this.offsetX/e,0),h=ia(this.offsetY/s,0),c=n==="repeat-y"||n==="no-repeat"?1+Math.abs(o||0):ia(i.width/e,0),u=n==="repeat-x"||n==="no-repeat"?1+Math.abs(h||0):ia(i.height/s,0);return['<pattern id="SVGID_'.concat(r,'" x="').concat(o,'" y="').concat(h,'" width="').concat(c,'" height="').concat(u,'">'),'<image x="0" y="0" width="'.concat(i.width,'" height="').concat(i.height,'" xlink:href="').concat(this.sourceToString(),'"></image>'),"</pattern>",""].join(`
|
|
46
|
+
`)}static async fromObject(t,e){let{type:s,source:i,patternTransform:n}=t,r=Ct(t,lw);const o=await Th(i,T(T({},e),{},{crossOrigin:r.crossOrigin}));return new this(T(T({},r),{},{patternTransform:n&&n.slice(0),source:o}))}}A(Yf,"type","Pattern"),N.setClass(Yf),N.setClass(Yf,"pattern");const cw=["path","left","top"],uw=["d"];class xr extends pe{constructor(t){let e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},{path:s,left:i,top:n}=e,r=Ct(e,cw);super(),Object.assign(this,xr.ownDefaults),this.setOptions(r),this._setPath(t||[],!0),typeof i=="number"&&this.set(dt,i),typeof n=="number"&&this.set(Ve,n)}_setPath(t,e){this.path=u0(Array.isArray(t)?t:v0(t)),this.setBoundingBox(e)}_findCenterFromElement(){const t=this._calcBoundsFromPath();return new D(t.left+t.width/2,t.top+t.height/2)}_renderPathCommands(t){const e=-this.pathOffset.x,s=-this.pathOffset.y;t.beginPath();for(const i of this.path)switch(i[0]){case"L":t.lineTo(i[1]+e,i[2]+s);break;case"M":t.moveTo(i[1]+e,i[2]+s);break;case"C":t.bezierCurveTo(i[1]+e,i[2]+s,i[3]+e,i[4]+s,i[5]+e,i[6]+s);break;case"Q":t.quadraticCurveTo(i[1]+e,i[2]+s,i[3]+e,i[4]+s);break;case"Z":t.closePath()}}_render(t){this._renderPathCommands(t),this._renderPaintInOrder(t)}toString(){return"#<Path (".concat(this.complexity(),'): { "top": ').concat(this.top,', "left": ').concat(this.left," }>")}toObject(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:[];return T(T({},super.toObject(t)),{},{path:this.path.map(e=>e.slice())})}toDatalessObject(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:[];const e=this.toObject(t);return this.sourcePath&&(delete e.path,e.sourcePath=this.sourcePath),e}_toSVG(){const t=_0(this.path,ht.NUM_FRACTION_DIGITS);return["<path ","COMMON_PARTS",'d="'.concat(t,`" stroke-linecap="round" />
|
|
47
|
+
`)]}_getOffsetTransform(){const t=ht.NUM_FRACTION_DIGITS;return" translate(".concat(At(-this.pathOffset.x,t),", ").concat(At(-this.pathOffset.y,t),")")}toClipPathSVG(t){const e=this._getOffsetTransform();return" "+this._createBaseClipPathSVGMarkup(this._toSVG(),{reviver:t,additionalTransform:e})}toSVG(t){const e=this._getOffsetTransform();return this._createBaseSVGMarkup(this._toSVG(),{reviver:t,additionalTransform:e})}complexity(){return this.path.length}setDimensions(){this.setBoundingBox()}setBoundingBox(t){const{width:e,height:s,pathOffset:i}=this._calcDimensions();this.set({width:e,height:s,pathOffset:i}),t&&this.setPositionByOrigin(i,Q,Q)}_calcBoundsFromPath(){const t=[];let e=0,s=0,i=0,n=0;for(const r of this.path)switch(r[0]){case"L":i=r[1],n=r[2],t.push({x:e,y:s},{x:i,y:n});break;case"M":i=r[1],n=r[2],e=i,s=n;break;case"C":t.push(...Xf(i,n,r[1],r[2],r[3],r[4],r[5],r[6])),i=r[5],n=r[6];break;case"Q":t.push(...Xf(i,n,r[1],r[2],r[1],r[2],r[3],r[4])),i=r[3],n=r[4];break;case"Z":i=e,n=s}return ri(t)}_calcDimensions(){const t=this._calcBoundsFromPath();return T(T({},t),{},{pathOffset:new D(t.left+t.width/2,t.top+t.height/2)})}static fromObject(t){return this._fromObject(t,{extraParam:"path"})}static async fromElement(t,e,s){const i=Ni(t,this.ATTRIBUTE_NAMES,s),{d:n}=i;return new this(n,T(T(T({},Ct(i,uw)),e),{},{left:void 0,top:void 0}))}}A(xr,"type","Path"),A(xr,"cacheProperties",[...Fi,"path","fillRule"]),A(xr,"ATTRIBUTE_NAMES",[...Mn,"d"]),N.setClass(xr),N.setSVGClass(xr);const dw=["left","top","radius"],E0=["radius","startAngle","endAngle","counterClockwise"];class Bi extends pe{static getDefaults(){return T(T({},super.getDefaults()),Bi.ownDefaults)}constructor(t){super(),Object.assign(this,Bi.ownDefaults),this.setOptions(t)}_set(t,e){return super._set(t,e),t==="radius"&&this.setRadius(e),this}_render(t){t.beginPath(),t.arc(0,0,this.radius,Rt(this.startAngle),Rt(this.endAngle),this.counterClockwise),this._renderPaintInOrder(t)}getRadiusX(){return this.get("radius")*this.get(Me)}getRadiusY(){return this.get("radius")*this.get(Je)}setRadius(t){this.radius=t,this.set({width:2*t,height:2*t})}toObject(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:[];return super.toObject([...E0,...t])}_toSVG(){const t=(this.endAngle-this.startAngle)%360;if(t===0)return["<circle ","COMMON_PARTS",'cx="0" cy="0" ','r="',"".concat(this.radius),`" />
|
|
48
48
|
`];{const{radius:e}=this,s=Rt(this.startAngle),i=Rt(this.endAngle),n=Ds(s)*e,r=Os(s)*e,o=Ds(i)*e,h=Os(i)*e,c=t>180?1:0,u=this.counterClockwise?0:1;return['<path d="M '.concat(n," ").concat(r," A ").concat(e," ").concat(e," 0 ").concat(c," ").concat(u," ").concat(o," ").concat(h,'" '),"COMMON_PARTS",` />
|
|
49
|
-
`]}}static async fromElement(t,e,s){const i=Ni(t,this.ATTRIBUTE_NAMES,s),{left:n=0,top:r=0,radius:o=0}=i;return new this(T(T({},Ct(i,
|
|
50
|
-
`)]}static async fromElement(t,e,s){const i=Ni(t,this.ATTRIBUTE_NAMES,s),{x1:n=0,y1:r=0,x2:o=0,y2:h=0}=i;return new this([n,r,o,h],Ct(i,
|
|
51
|
-
`)]}_render(t){t.beginPath(),t.save(),t.transform(1,0,0,this.ry/this.rx,0,0),t.arc(0,0,this.rx,0,Ri,!1),t.restore(),this._renderPaintInOrder(t)}static async fromElement(t,e,s){const i=Ni(t,this.ATTRIBUTE_NAMES,s);return i.left=(i.left||0)-i.rx,i.top=(i.top||0)-i.ry,new this(i)}}function
|
|
52
|
-
`)]}_render(t){const e=this.points.length,s=this.pathOffset.x,i=this.pathOffset.y;if(e&&!isNaN(this.points[e-1].y)){t.beginPath(),t.moveTo(this.points[0].x-s,this.points[0].y-i);for(let n=0;n<e;n++){const r=this.points[n];t.lineTo(r.x-s,r.y-i)}!this.isOpen()&&t.closePath(),this._renderPaintInOrder(t)}}complexity(){return this.points.length}static async fromElement(t,e,s){return new this(
|
|
53
|
-
`)}const yw=["textAnchor","textDecoration","dx","dy","top","left","fontSize","strokeWidth"];let Kf;class me extends L0{static getDefaults(){return T(T({},super.getDefaults()),me.ownDefaults)}constructor(t,e){super(),A(this,"__charBounds",[]),Object.assign(this,me.ownDefaults),this.setOptions(e),this.styles||(this.styles={}),this.text=t,this.initialized=!0,this.path&&this.setPathInfo(),this.initDimensions(),this.setCoords()}setPathInfo(){const t=this.path;t&&(t.segmentsInfo=Wf(t.path))}_splitText(){const t=this._splitTextIntoLines(this.text);return this.textLines=t.lines,this._textLines=t.graphemeLines,this._unwrappedTextLines=t._unwrappedLines,this._text=t.graphemeText,t}initDimensions(){this._splitText(),this._clearCache(),this.dirty=!0,this.path?(this.width=this.path.width,this.height=this.path.height):(this.width=this.calcTextWidth()||this.cursorWidth||this.MIN_TEXT_WIDTH,this.height=this.calcTextHeight()),this.textAlign.includes(hi)&&this.enlargeSpaces()}enlargeSpaces(){let t,e,s,i,n,r,o;for(let h=0,c=this._textLines.length;h<c;h++)if((this.textAlign===hi||h!==c-1&&!this.isEndOfWrapping(h))&&(i=0,n=this._textLines[h],e=this.getLineWidth(h),e<this.width&&(o=this.textLines[h].match(this._reSpacesAndTabs)))){s=o.length,t=(this.width-e)/s;for(let u=0;u<=n.length;u++)r=this.__charBounds[h][u],this._reSpaceAndTab.test(n[u])?(r.width+=t,r.kernedWidth+=t,r.left+=i,i+=t):r.left+=i}}isEndOfWrapping(t){return t===this._textLines.length-1}missingNewlineOffset(t){return 1}get2DCursorLocation(t,e){const s=e?this._unwrappedTextLines:this._textLines;let i;for(i=0;i<s.length;i++){if(t<=s[i].length)return{lineIndex:i,charIndex:t};t-=s[i].length+this.missingNewlineOffset(i,e)}return{lineIndex:i-1,charIndex:s[i-1].length<t?s[i-1].length:t}}toString(){return"#<Text (".concat(this.complexity(),'): { "text": "').concat(this.text,'", "fontFamily": "').concat(this.fontFamily,'" }>')}_getCacheCanvasDimensions(){const t=super._getCacheCanvasDimensions(),e=this.fontSize;return t.width+=e*t.zoomX,t.height+=e*t.zoomY,t}_render(t){const e=this.path;e&&!e.isNotVisible()&&e._render(t),this._setTextStyles(t),this._renderTextLinesBackground(t),this._renderTextDecoration(t,"underline"),this._renderText(t),this._renderTextDecoration(t,"overline"),this._renderTextDecoration(t,"linethrough")}_renderText(t){this.paintFirst===Pe?(this._renderTextStroke(t),this._renderTextFill(t)):(this._renderTextFill(t),this._renderTextStroke(t))}_setTextStyles(t,e,s){if(t.textBaseline="alphabetic",this.path)switch(this.pathAlign){case J:t.textBaseline="middle";break;case"ascender":t.textBaseline=Ve;break;case"descender":t.textBaseline=hf}t.font=this._getFontDeclaration(e,s)}calcTextWidth(){let t=this.getLineWidth(0);for(let e=1,s=this._textLines.length;e<s;e++){const i=this.getLineWidth(e);i>t&&(t=i)}return t}_renderTextLine(t,e,s,i,n,r){this._renderChars(t,e,s,i,n,r)}_renderTextLinesBackground(t){if(!this.textBackgroundColor&&!this.styleHas("textBackgroundColor"))return;const e=t.fillStyle,s=this._getLeftOffset();let i=this._getTopOffset();for(let n=0,r=this._textLines.length;n<r;n++){const o=this.getHeightOfLine(n);if(!this.textBackgroundColor&&!this.styleHas("textBackgroundColor",n)){i+=o;continue}const h=this._textLines[n].length,c=this._getLineLeftOffset(n);let u,d,f=0,g=0,p=this.getValueOfPropertyAt(n,0,"textBackgroundColor");for(let b=0;b<h;b++){const _=this.__charBounds[n][b];d=this.getValueOfPropertyAt(n,b,"textBackgroundColor"),this.path?(t.save(),t.translate(_.renderLeft,_.renderTop),t.rotate(_.angle),t.fillStyle=d,d&&t.fillRect(-_.width/2,-o/this.lineHeight*(1-this._fontSizeFraction),_.width,o/this.lineHeight),t.restore()):d!==p?(u=s+c+g,this.direction==="rtl"&&(u=this.width-u-f),t.fillStyle=p,p&&t.fillRect(u,i,f,o/this.lineHeight),g=_.left,f=_.width,p=d):f+=_.kernedWidth}d&&!this.path&&(u=s+c+g,this.direction==="rtl"&&(u=this.width-u-f),t.fillStyle=d,t.fillRect(u,i,f,o/this.lineHeight)),i+=o}t.fillStyle=e,this._removeShadow(t)}_measureChar(t,e,s,i){const n=xh.getFontCache(e),r=this._getFontDeclaration(e),o=s+t,h=s&&r===this._getFontDeclaration(i),c=e.fontSize/this.CACHE_FONT_SIZE;let u,d,f,g;if(s&&n[s]!==void 0&&(f=n[s]),n[t]!==void 0&&(g=u=n[t]),h&&n[o]!==void 0&&(d=n[o],g=d-f),u===void 0||f===void 0||d===void 0){const p=function(){return Kf||(Kf=Rs({width:0,height:0}).getContext("2d")),Kf}();this._setTextStyles(p,e,!0),u===void 0&&(g=u=p.measureText(t).width,n[t]=u),f===void 0&&h&&s&&(f=p.measureText(s).width,n[s]=f),h&&d===void 0&&(d=p.measureText(o).width,n[o]=d,g=d-f)}return{width:u*c,kernedWidth:g*c}}getHeightOfChar(t,e){return this.getValueOfPropertyAt(t,e,"fontSize")}measureLine(t){const e=this._measureLine(t);return this.charSpacing!==0&&(e.width-=this._getWidthOfCharSpacing()),e.width<0&&(e.width=0),e}_measureLine(t){let e,s,i=0;const n=this.pathSide===It,r=this.path,o=this._textLines[t],h=o.length,c=new Array(h);this.__charBounds[t]=c;for(let u=0;u<h;u++){const d=o[u];s=this._getGraphemeBox(d,t,u,e),c[u]=s,i+=s.kernedWidth,e=d}if(c[h]={left:s?s.left+s.width:0,width:0,kernedWidth:0,height:this.fontSize,deltaY:0},r&&r.segmentsInfo){let u=0;const d=r.segmentsInfo[r.segmentsInfo.length-1].length;switch(this.textAlign){case dt:u=n?d-i:0;break;case J:u=(d-i)/2;break;case It:u=n?0:d-i}u+=this.pathStartOffset*(n?-1:1);for(let f=n?h-1:0;n?f>=0:f<h;n?f--:f++)s=c[f],u>d?u%=d:u<0&&(u+=d),this._setGraphemeOnPath(u,s),u+=s.kernedWidth}return{width:i,numOfSpaces:0}}_setGraphemeOnPath(t,e){const s=t+e.kernedWidth/2,i=this.path,n=b0(i.path,s,i.segmentsInfo);e.renderLeft=n.x-i.pathOffset.x,e.renderTop=n.y-i.pathOffset.y,e.angle=n.angle+(this.pathSide===It?Math.PI:0)}_getGraphemeBox(t,e,s,i,n){const r=this.getCompleteStyleDeclaration(e,s),o=i?this.getCompleteStyleDeclaration(e,s-1):{},h=this._measureChar(t,r,i,o);let c,u=h.kernedWidth,d=h.width;this.charSpacing!==0&&(c=this._getWidthOfCharSpacing(),d+=c,u+=c);const f={width:d,left:0,height:r.fontSize,kernedWidth:u,deltaY:r.deltaY};if(s>0&&!n){const g=this.__charBounds[e][s-1];f.left=g.left+g.width+h.kernedWidth-h.width}return f}getHeightOfLine(t){if(this.__lineHeights[t])return this.__lineHeights[t];let e=this.getHeightOfChar(t,0);for(let s=1,i=this._textLines[t].length;s<i;s++)e=Math.max(this.getHeightOfChar(t,s),e);return this.__lineHeights[t]=e*this.lineHeight*this._fontSizeMult}calcTextHeight(){let t,e=0;for(let s=0,i=this._textLines.length;s<i;s++)t=this.getHeightOfLine(s),e+=s===i-1?t/this.lineHeight:t;return e}_getLeftOffset(){return this.direction==="ltr"?-this.width/2:this.width/2}_getTopOffset(){return-this.height/2}_renderTextCommon(t,e){t.save();let s=0;const i=this._getLeftOffset(),n=this._getTopOffset();for(let r=0,o=this._textLines.length;r<o;r++){const h=this.getHeightOfLine(r),c=h/this.lineHeight,u=this._getLineLeftOffset(r);this._renderTextLine(e,t,this._textLines[r],i+u,n+s+c,r),s+=h}t.restore()}_renderTextFill(t){(this.fill||this.styleHas(zt))&&this._renderTextCommon(t,"fillText")}_renderTextStroke(t){(this.stroke&&this.strokeWidth!==0||!this.isEmptyStyles())&&(this.shadow&&!this.shadow.affectStroke&&this._removeShadow(t),t.save(),this._setLineDash(t,this.strokeDashArray),t.beginPath(),this._renderTextCommon(t,"strokeText"),t.closePath(),t.restore())}_renderChars(t,e,s,i,n,r){const o=this.getHeightOfLine(r),h=this.textAlign.includes(hi),c=this.path,u=!h&&this.charSpacing===0&&this.isEmptyStyles(r)&&!c,d=this.direction==="ltr",f=this.direction==="ltr"?1:-1,g=e.direction;let p,b,_,v,x,C="",S=0;if(e.save(),g!==this.direction&&(e.canvas.setAttribute("dir",d?"ltr":"rtl"),e.direction=d?"ltr":"rtl",e.textAlign=d?dt:It),n-=o*this._fontSizeFraction/this.lineHeight,u)return this._renderChar(t,e,r,0,s.join(""),i,n),void e.restore();for(let E=0,k=s.length-1;E<=k;E++)v=E===k||this.charSpacing||c,C+=s[E],_=this.__charBounds[r][E],S===0?(i+=f*(_.kernedWidth-_.width),S+=_.width):S+=_.kernedWidth,h&&!v&&this._reSpaceAndTab.test(s[E])&&(v=!0),v||(p=p||this.getCompleteStyleDeclaration(r,E),b=this.getCompleteStyleDeclaration(r,E+1),v=hu(p,b,!1)),v&&(c?(e.save(),e.translate(_.renderLeft,_.renderTop),e.rotate(_.angle),this._renderChar(t,e,r,E,C,-S/2,0),e.restore()):(x=i,this._renderChar(t,e,r,E,C,x,n)),C="",p=b,i+=f*S,S=0);e.restore()}_applyPatternGradientTransformText(t){const e=this.width+this.strokeWidth,s=this.height+this.strokeWidth,i=Rs({width:e,height:s}),n=i.getContext("2d");return i.width=e,i.height=s,n.beginPath(),n.moveTo(0,0),n.lineTo(e,0),n.lineTo(e,s),n.lineTo(0,s),n.closePath(),n.translate(e/2,s/2),n.fillStyle=t.toLive(n),this._applyPatternGradientTransform(n,t),n.fill(),n.createPattern(i,"no-repeat")}handleFiller(t,e,s){let i,n;return bs(s)?s.gradientUnits==="percentage"||s.gradientTransform||s.patternTransform?(i=-this.width/2,n=-this.height/2,t.translate(i,n),t[e]=this._applyPatternGradientTransformText(s),{offsetX:i,offsetY:n}):(t[e]=s.toLive(t),this._applyPatternGradientTransform(t,s)):(t[e]=s,{offsetX:0,offsetY:0})}_setStrokeStyles(t,e){let{stroke:s,strokeWidth:i}=e;return t.lineWidth=i,t.lineCap=this.strokeLineCap,t.lineDashOffset=this.strokeDashOffset,t.lineJoin=this.strokeLineJoin,t.miterLimit=this.strokeMiterLimit,this.handleFiller(t,"strokeStyle",s)}_setFillStyles(t,e){let{fill:s}=e;return this.handleFiller(t,"fillStyle",s)}_renderChar(t,e,s,i,n,r,o){const h=this._getStyleDeclaration(s,i),c=this.getCompleteStyleDeclaration(s,i),u=t==="fillText"&&c.fill,d=t==="strokeText"&&c.stroke&&c.strokeWidth;if(d||u){if(e.save(),e.font=this._getFontDeclaration(c),h.textBackgroundColor&&this._removeShadow(e),h.deltaY&&(o+=h.deltaY),u){const f=this._setFillStyles(e,c);e.fillText(n,r-f.offsetX,o-f.offsetY)}if(d){const f=this._setStrokeStyles(e,c);e.strokeText(n,r-f.offsetX,o-f.offsetY)}e.restore()}}setSuperscript(t,e){this._setScript(t,e,this.superscript)}setSubscript(t,e){this._setScript(t,e,this.subscript)}_setScript(t,e,s){const i=this.get2DCursorLocation(t,!0),n=this.getValueOfPropertyAt(i.lineIndex,i.charIndex,"fontSize"),r=this.getValueOfPropertyAt(i.lineIndex,i.charIndex,"deltaY"),o={fontSize:n*s.size,deltaY:r+n*s.baseline};this.setSelectionStyles(o,t,e)}_getLineLeftOffset(t){const e=this.getLineWidth(t),s=this.width-e,i=this.textAlign,n=this.direction,r=this.isEndOfWrapping(t);let o=0;return i===hi||i===jh&&!r||i===Nh&&!r||i===yu&&!r?0:(i===J&&(o=s/2),i===It&&(o=s),i===jh&&(o=s/2),i===Nh&&(o=s),n==="rtl"&&(i===It||i===hi||i===Nh?o=0:i===dt||i===yu?o=-s:i!==J&&i!==jh||(o=-s/2)),o)}_clearCache(){this._forceClearCache=!1,this.__lineWidths=[],this.__lineHeights=[],this.__charBounds=[]}getLineWidth(t){if(this.__lineWidths[t]!==void 0)return this.__lineWidths[t];const{width:e}=this.measureLine(t);return this.__lineWidths[t]=e,e}_getWidthOfCharSpacing(){return this.charSpacing!==0?this.fontSize*this.charSpacing/1e3:0}getValueOfPropertyAt(t,e,s){var i;return(i=this._getStyleDeclaration(t,e)[s])!==null&&i!==void 0?i:this[s]}_renderTextDecoration(t,e){if(!this[e]&&!this.styleHas(e))return;let s=this._getTopOffset();const i=this._getLeftOffset(),n=this.path,r=this._getWidthOfCharSpacing(),o=this.offsets[e];for(let h=0,c=this._textLines.length;h<c;h++){const u=this.getHeightOfLine(h);if(!this[e]&&!this.styleHas(e,h)){s+=u;continue}const d=this._textLines[h],f=u/this.lineHeight,g=this._getLineLeftOffset(h);let p,b,_=0,v=0,x=this.getValueOfPropertyAt(h,0,e),C=this.getValueOfPropertyAt(h,0,zt);const S=s+f*(1-this._fontSizeFraction);let E=this.getHeightOfChar(h,0),k=this.getValueOfPropertyAt(h,0,"deltaY");for(let D=0,R=d.length;D<R;D++){const B=this.__charBounds[h][D];p=this.getValueOfPropertyAt(h,D,e),b=this.getValueOfPropertyAt(h,D,zt);const O=this.getHeightOfChar(h,D),F=this.getValueOfPropertyAt(h,D,"deltaY");if(n&&p&&b)t.save(),t.fillStyle=C,t.translate(B.renderLeft,B.renderTop),t.rotate(B.angle),t.fillRect(-B.kernedWidth/2,o*O+F,B.kernedWidth,this.fontSize/15),t.restore();else if((p!==x||b!==C||O!==E||F!==k)&&v>0){let L=i+g+_;this.direction==="rtl"&&(L=this.width-L-v),x&&C&&(t.fillStyle=C,t.fillRect(L,S+o*E+k,v,this.fontSize/15)),_=B.left,v=B.width,x=p,C=b,E=O,k=F}else v+=B.kernedWidth}let M=i+g+_;this.direction==="rtl"&&(M=this.width-M-v),t.fillStyle=b,p&&b&&t.fillRect(M,S+o*E+k,v-r,this.fontSize/15),s+=u}this._removeShadow(t)}_getFontDeclaration(){let{fontFamily:t=this.fontFamily,fontStyle:e=this.fontStyle,fontWeight:s=this.fontWeight,fontSize:i=this.fontSize}=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},n=arguments.length>1?arguments[1]:void 0;const r=t.includes("'")||t.includes('"')||t.includes(",")||me.genericFonts.includes(t.toLowerCase())?t:'"'.concat(t,'"');return[e,s,"".concat(n?this.CACHE_FONT_SIZE:i,"px"),r].join(" ")}render(t){this.visible&&(this.canvas&&this.canvas.skipOffscreen&&!this.group&&!this.isOnScreen()||(this._forceClearCache&&this.initDimensions(),super.render(t)))}graphemeSplit(t){return au(t)}_splitTextIntoLines(t){const e=t.split(this._reNewline),s=new Array(e.length),i=[`
|
|
54
|
-
`];let n=[];for(let r=0;r<e.length;r++)s[r]=this.graphemeSplit(e[r]),n=n.concat(s[r],i);return n.pop(),{_unwrappedLines:s,lines:e,graphemeText:n,graphemeLines:s}}toObject(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:[];return T(T({},super.toObject([...R0,...t])),{},{styles:qm(this.styles,this.text)},this.path?{path:this.path.toObject()}:{})}set(t,e){const{textLayoutProperties:s}=this.constructor;super.set(t,e);let i=!1,n=!1;if(typeof t=="object")for(const r in t)r==="path"&&this.setPathInfo(),i=i||s.includes(r),n=n||r==="path";else i=s.includes(t),n=t==="path";return n&&this.setPathInfo(),i&&this.initialized&&(this.initDimensions(),this.setCoords()),this}complexity(){return 1}static async fromElement(t,e,s){const i=Ni(t,me.ATTRIBUTE_NAMES,s),n=T(T({},e),i),{textAnchor:r=dt,textDecoration:o="",dx:h=0,dy:c=0,top:u=0,left:d=0,fontSize:f=af,strokeWidth:g=1}=n,p=Ct(n,
|
|
55
|
-
`]}_getSVGTextAndBg(a,t){const e=[],s=[];let i,n=a;this.backgroundColor&&s.push(...qf(this.backgroundColor,-this.width/2,-this.height/2,this.width,this.height));for(let r=0,o=this._textLines.length;r<o;r++)i=this._getLineLeftOffset(r),this.direction==="rtl"&&(i+=this.width),(this.textBackgroundColor||this.styleHas("textBackgroundColor",r))&&this._setSVGTextLineBg(s,r,t+i,n),this._setSVGTextLineText(e,r,t+i,n),n+=this.getHeightOfLine(r);return{textSpans:e,textBgRects:s}}_createTextCharSpan(a,t,e,s){const i=this.getSvgSpanStyles(t,a!==a.trim()||!!a.match(mw)),n=i?'style="'.concat(i,'"'):"",r=t.deltaY,o=r?' dy="'.concat(At(r,ht.NUM_FRACTION_DIGITS),'" '):"";return'<tspan x="'.concat(At(e,ht.NUM_FRACTION_DIGITS),'" y="').concat(At(s,ht.NUM_FRACTION_DIGITS),'" ').concat(o).concat(n,">").concat($m(a),"</tspan>")}_setSVGTextLineText(a,t,e,s){const i=this.getHeightOfLine(t),n=this.textAlign.includes(hi),r=this._textLines[t];let o,h,c,u,d,f="",g=0;s+=i*(1-this._fontSizeFraction)/this.lineHeight;for(let p=0,b=r.length-1;p<=b;p++)d=p===b||this.charSpacing,f+=r[p],c=this.__charBounds[t][p],g===0?(e+=c.kernedWidth-c.width,g+=c.width):g+=c.kernedWidth,n&&!d&&this._reSpaceAndTab.test(r[p])&&(d=!0),d||(o=o||this.getCompleteStyleDeclaration(t,p),h=this.getCompleteStyleDeclaration(t,p+1),d=hu(o,h,!0)),d&&(u=this._getStyleDeclaration(t,p),a.push(this._createTextCharSpan(f,u,e,s)),f="",o=h,this.direction==="rtl"?e-=g:e+=g,g=0)}_setSVGTextLineBg(a,t,e,s){const i=this._textLines[t],n=this.getHeightOfLine(t)/this.lineHeight;let r,o=0,h=0,c=this.getValueOfPropertyAt(t,0,"textBackgroundColor");for(let u=0;u<i.length;u++){const{left:d,width:f,kernedWidth:g}=this.__charBounds[t][u];r=this.getValueOfPropertyAt(t,u,"textBackgroundColor"),r!==c?(c&&a.push(...qf(c,e+h,s,o,n)),h=d,o=f,c=r):o+=g}r&&a.push(...qf(c,e+h,s,o,n))}_getSVGLineTopOffset(a){let t,e=0;for(t=0;t<a;t++)e+=this.getHeightOfLine(t);const s=this.getHeightOfLine(t);return{lineTop:e,offset:(this._fontSizeMult-this._fontSizeFraction)*s/(this.lineHeight*this._fontSizeMult)}}getSvgStyles(a){return"".concat(super.getSvgStyles(a)," white-space: pre;")}getSvgSpanStyles(a,t){const{fontFamily:e,strokeWidth:s,stroke:i,fill:n,fontSize:r,fontStyle:o,fontWeight:h,deltaY:c}=a,u=this.getSvgTextDecoration(a);return[i?Mh(Pe,i):"",s?"stroke-width: ".concat(s,"; "):"",e?"font-family: ".concat(e.includes("'")||e.includes('"')?e:"'".concat(e,"'"),"; "):"",r?"font-size: ".concat(r,"px; "):"",o?"font-style: ".concat(o,"; "):"",h?"font-weight: ".concat(h,"; "):"",u&&"text-decoration: ".concat(u,"; "),n?Mh(zt,n):"",c?"baseline-shift: ".concat(-c,"; "):"",t?"white-space: pre; ":""].join("")}getSvgTextDecoration(a){return["overline","underline","line-through"].filter(t=>a[t.replace("-","")]).join(" ")}}]),H.setClass(me),H.setSVGClass(me);class vw{constructor(t){A(this,"target",void 0),A(this,"__mouseDownInPlace",!1),A(this,"__dragStartFired",!1),A(this,"__isDraggingOver",!1),A(this,"__dragStartSelection",void 0),A(this,"__dragImageDisposer",void 0),A(this,"_dispose",void 0),this.target=t;const e=[this.target.on("dragenter",this.dragEnterHandler.bind(this)),this.target.on("dragover",this.dragOverHandler.bind(this)),this.target.on("dragleave",this.dragLeaveHandler.bind(this)),this.target.on("dragend",this.dragEndHandler.bind(this)),this.target.on("drop",this.dropHandler.bind(this))];this._dispose=()=>{e.forEach(s=>s()),this._dispose=void 0}}isPointerOverSelection(t){const e=this.target,s=e.getSelectionStartFromPointer(t);return e.isEditing&&s>=e.selectionStart&&s<=e.selectionEnd&&e.selectionStart<e.selectionEnd}start(t){return this.__mouseDownInPlace=this.isPointerOverSelection(t)}isActive(){return this.__mouseDownInPlace}end(t){const e=this.isActive();return e&&!this.__dragStartFired&&(this.target.setCursorByClick(t),this.target.initDelayedCursor(!0)),this.__mouseDownInPlace=!1,this.__dragStartFired=!1,this.__isDraggingOver=!1,e}getDragStartSelection(){return this.__dragStartSelection}setDragImage(t,e){var s;let{selectionStart:i,selectionEnd:n}=e;const r=this.target,o=r.canvas,h=new P(r.flipX?-1:1,r.flipY?-1:1),c=r._getCursorBoundaries(i),u=new P(c.left+c.leftOffset,c.top+c.topOffset).multiply(h).transform(r.calcTransformMatrix()),d=o.getScenePoint(t).subtract(u),f=r.getCanvasRetinaScaling(),g=r.getBoundingRect(),p=u.subtract(new P(g.left,g.top)),b=o.viewportTransform,_=p.add(d).transform(b,!0),v=r.backgroundColor,x=jf(r.styles);r.backgroundColor="";const C={stroke:"transparent",fill:"transparent",textBackgroundColor:"transparent"};r.setSelectionStyles(C,0,i),r.setSelectionStyles(C,n,r.text.length),r.dirty=!0;const S=r.toCanvasElement({enableRetinaScaling:o.enableRetinaScaling,viewportTransform:!0});r.backgroundColor=v,r.styles=x,r.dirty=!0,gu(S,{position:"fixed",left:"".concat(-S.width,"px"),border:ke,width:"".concat(S.width/f,"px"),height:"".concat(S.height/f,"px")}),this.__dragImageDisposer&&this.__dragImageDisposer(),this.__dragImageDisposer=()=>{S.remove()},Ls(t.target||this.target.hiddenTextarea).body.appendChild(S),(s=t.dataTransfer)===null||s===void 0||s.setDragImage(S,_.x,_.y)}onDragStart(t){this.__dragStartFired=!0;const e=this.target,s=this.isActive();if(s&&t.dataTransfer){const i=this.__dragStartSelection={selectionStart:e.selectionStart,selectionEnd:e.selectionEnd},n=e._text.slice(i.selectionStart,i.selectionEnd).join(""),r=T({text:e.text,value:n},i);t.dataTransfer.setData("text/plain",n),t.dataTransfer.setData("application/fabric",JSON.stringify({value:n,styles:e.getSelectionStyles(i.selectionStart,i.selectionEnd,!0)})),t.dataTransfer.effectAllowed="copyMove",this.setDragImage(t,r)}return e.abortCursorAnimation(),s}canDrop(t){if(this.target.editable&&!this.target.getActiveControl()&&!t.defaultPrevented){if(this.isActive()&&this.__dragStartSelection){const e=this.target.getSelectionStartFromPointer(t),s=this.__dragStartSelection;return e<s.selectionStart||e>s.selectionEnd}return!0}return!1}targetCanDrop(t){return this.target.canDrop(t)}dragEnterHandler(t){let{e}=t;const s=this.targetCanDrop(e);!this.__isDraggingOver&&s&&(this.__isDraggingOver=!0)}dragOverHandler(t){const{e}=t,s=this.targetCanDrop(e);!this.__isDraggingOver&&s?this.__isDraggingOver=!0:this.__isDraggingOver&&!s&&(this.__isDraggingOver=!1),this.__isDraggingOver&&(e.preventDefault(),t.canDrop=!0,t.dropTarget=this.target)}dragLeaveHandler(){(this.__isDraggingOver||this.isActive())&&(this.__isDraggingOver=!1)}dropHandler(t){var e;const{e:s}=t,i=s.defaultPrevented;this.__isDraggingOver=!1,s.preventDefault();let n=(e=s.dataTransfer)===null||e===void 0?void 0:e.getData("text/plain");if(n&&!i){const r=this.target,o=r.canvas;let h=r.getSelectionStartFromPointer(s);const{styles:c}=s.dataTransfer.types.includes("application/fabric")?JSON.parse(s.dataTransfer.getData("application/fabric")):{},u=n[Math.max(0,n.length-1)],d=0;if(this.__dragStartSelection){const f=this.__dragStartSelection.selectionStart,g=this.__dragStartSelection.selectionEnd;h>f&&h<=g?h=f:h>g&&(h-=g-f),r.removeChars(f,g),delete this.__dragStartSelection}r._reNewline.test(u)&&(r._reNewline.test(r._text[h])||h===r._text.length)&&(n=n.trimEnd()),t.didDrop=!0,t.dropTarget=r,r.insertChars(n,c,h),o.setActiveObject(r),r.enterEditing(s),r.selectionStart=Math.min(h+d,r._text.length),r.selectionEnd=Math.min(r.selectionStart+n.length,r._text.length),r.hiddenTextarea.value=r.text,r._updateTextarea(),r.hiddenTextarea.focus(),r.fire(zc,{index:h+d,action:"drop"}),o.fire("text:changed",{target:r}),o.contextTopDirty=!0,o.requestRenderAll()}}dragEndHandler(t){let{e}=t;if(this.isActive()&&this.__dragStartFired&&this.__dragStartSelection){var s;const i=this.target,n=this.target.canvas,{selectionStart:r,selectionEnd:o}=this.__dragStartSelection,h=((s=e.dataTransfer)===null||s===void 0?void 0:s.dropEffect)||ke;h===ke?(i.selectionStart=r,i.selectionEnd=o,i._updateTextarea(),i.hiddenTextarea.focus()):(i.clearContextTop(),h==="move"&&(i.removeChars(r,o),i.selectionStart=i.selectionEnd=r,i.hiddenTextarea&&(i.hiddenTextarea.value=i.text),i._updateTextarea(),i.fire(zc,{index:r,action:"dragend"}),n.fire("text:changed",{target:i}),n.requestRenderAll()),i.exitEditing())}this.__dragImageDisposer&&this.__dragImageDisposer(),delete this.__dragImageDisposer,delete this.__dragStartSelection,this.__isDraggingOver=!1}dispose(){this._dispose&&this._dispose()}}const F0=/[ \n\.,;!\?\-]/;class _w extends me{constructor(){super(...arguments),A(this,"_currentCursorOpacity",1)}initBehavior(){this._tick=this._tick.bind(this),this._onTickComplete=this._onTickComplete.bind(this),this.updateSelectionOnMouseMove=this.updateSelectionOnMouseMove.bind(this)}onDeselect(t){return this.isEditing&&this.exitEditing(),this.selected=!1,super.onDeselect(t)}_animateCursor(t){let{toValue:e,duration:s,delay:i,onComplete:n}=t;return Ff({startValue:this._currentCursorOpacity,endValue:e,duration:s,delay:i,onComplete:n,abort:()=>!this.canvas||this.selectionStart!==this.selectionEnd,onChange:r=>{this._currentCursorOpacity=r,this.renderCursorOrSelection()}})}_tick(t){this._currentTickState=this._animateCursor({toValue:0,duration:this.cursorDuration/2,delay:Math.max(t||0,100),onComplete:this._onTickComplete})}_onTickComplete(){var t;(t=this._currentTickCompleteState)===null||t===void 0||t.abort(),this._currentTickCompleteState=this._animateCursor({toValue:1,duration:this.cursorDuration,onComplete:this._tick})}initDelayedCursor(t){this.abortCursorAnimation(),this._tick(t?0:this.cursorDelay)}abortCursorAnimation(){let t=!1;[this._currentTickState,this._currentTickCompleteState].forEach(e=>{e&&!e.isDone()&&(t=!0,e.abort())}),this._currentCursorOpacity=1,t&&this.clearContextTop()}restartCursorIfNeeded(){[this._currentTickState,this._currentTickCompleteState].some(t=>!t||t.isDone())&&this.initDelayedCursor()}selectAll(){return this.selectionStart=0,this.selectionEnd=this._text.length,this._fireSelectionChanged(),this._updateTextarea(),this}getSelectedText(){return this._text.slice(this.selectionStart,this.selectionEnd).join("")}findWordBoundaryLeft(t){let e=0,s=t-1;if(this._reSpace.test(this._text[s]))for(;this._reSpace.test(this._text[s]);)e++,s--;for(;/\S/.test(this._text[s])&&s>-1;)e++,s--;return t-e}findWordBoundaryRight(t){let e=0,s=t;if(this._reSpace.test(this._text[s]))for(;this._reSpace.test(this._text[s]);)e++,s++;for(;/\S/.test(this._text[s])&&s<this._text.length;)e++,s++;return t+e}findLineBoundaryLeft(t){let e=0,s=t-1;for(;!/\n/.test(this._text[s])&&s>-1;)e++,s--;return t-e}findLineBoundaryRight(t){let e=0,s=t;for(;!/\n/.test(this._text[s])&&s<this._text.length;)e++,s++;return t+e}searchWordBoundary(t,e){const s=this._text;let i=t>0&&this._reSpace.test(s[t])&&(e===-1||!lf.test(s[t-1]))?t-1:t,n=s[i];for(;i>0&&i<s.length&&!F0.test(n);)i+=e,n=s[i];return e===-1&&F0.test(n)&&i++,i}selectWord(t){t=t||this.selectionStart;const e=this.searchWordBoundary(t,-1),s=Math.max(e,this.searchWordBoundary(t,1));this.selectionStart=e,this.selectionEnd=s,this._fireSelectionChanged(),this._updateTextarea(),this.renderCursorOrSelection()}selectLine(t){t=t||this.selectionStart;const e=this.findLineBoundaryLeft(t),s=this.findLineBoundaryRight(t);return this.selectionStart=e,this.selectionEnd=s,this._fireSelectionChanged(),this._updateTextarea(),this}enterEditing(t){!this.isEditing&&this.editable&&(this.enterEditingImpl(),this.fire("editing:entered",t?{e:t}:void 0),this._fireSelectionChanged(),this.canvas&&(this.canvas.fire("text:editing:entered",{target:this,e:t}),this.canvas.requestRenderAll()))}enterEditingImpl(){this.canvas&&(this.canvas.calcOffset(),this.canvas.textEditingManager.exitTextEditing()),this.isEditing=!0,this.initHiddenTextarea(),this.hiddenTextarea.focus(),this.hiddenTextarea.value=this.text,this._updateTextarea(),this._saveEditingProps(),this._setEditingProps(),this._textBeforeEdit=this.text,this._tick()}updateSelectionOnMouseMove(t){if(this.getActiveControl())return;const e=this.hiddenTextarea;Ls(e).activeElement!==e&&e.focus();const s=this.getSelectionStartFromPointer(t),i=this.selectionStart,n=this.selectionEnd;(s===this.__selectionStartOnMouseDown&&i!==n||i!==s&&n!==s)&&(s>this.__selectionStartOnMouseDown?(this.selectionStart=this.__selectionStartOnMouseDown,this.selectionEnd=s):(this.selectionStart=s,this.selectionEnd=this.__selectionStartOnMouseDown),this.selectionStart===i&&this.selectionEnd===n||(this._fireSelectionChanged(),this._updateTextarea(),this.renderCursorOrSelection()))}_setEditingProps(){this.hoverCursor="text",this.canvas&&(this.canvas.defaultCursor=this.canvas.moveCursor="text"),this.borderColor=this.editingBorderColor,this.hasControls=this.selectable=!1,this.lockMovementX=this.lockMovementY=!0}fromStringToGraphemeSelection(t,e,s){const i=s.slice(0,t),n=this.graphemeSplit(i).length;if(t===e)return{selectionStart:n,selectionEnd:n};const r=s.slice(t,e);return{selectionStart:n,selectionEnd:n+this.graphemeSplit(r).length}}fromGraphemeToStringSelection(t,e,s){const i=s.slice(0,t).join("").length;return t===e?{selectionStart:i,selectionEnd:i}:{selectionStart:i,selectionEnd:i+s.slice(t,e).join("").length}}_updateTextarea(){if(this.cursorOffsetCache={},this.hiddenTextarea){if(!this.inCompositionMode){const t=this.fromGraphemeToStringSelection(this.selectionStart,this.selectionEnd,this._text);this.hiddenTextarea.selectionStart=t.selectionStart,this.hiddenTextarea.selectionEnd=t.selectionEnd}this.updateTextareaPosition()}}updateFromTextArea(){if(!this.hiddenTextarea)return;this.cursorOffsetCache={};const t=this.hiddenTextarea;this.text=t.value,this.set("dirty",!0),this.initDimensions(),this.setCoords();const e=this.fromStringToGraphemeSelection(t.selectionStart,t.selectionEnd,t.value);this.selectionEnd=this.selectionStart=e.selectionEnd,this.inCompositionMode||(this.selectionStart=e.selectionStart),this.updateTextareaPosition()}updateTextareaPosition(){if(this.selectionStart===this.selectionEnd){const t=this._calcTextareaPosition();this.hiddenTextarea.style.left=t.left,this.hiddenTextarea.style.top=t.top}}_calcTextareaPosition(){if(!this.canvas)return{left:"1px",top:"1px"};const t=this.inCompositionMode?this.compositionStart:this.selectionStart,e=this._getCursorBoundaries(t),s=this.get2DCursorLocation(t),i=s.lineIndex,n=s.charIndex,r=this.getValueOfPropertyAt(i,n,"fontSize")*this.lineHeight,o=e.leftOffset,h=this.getCanvasRetinaScaling(),c=this.canvas.upperCanvasEl,u=c.width/h,d=c.height/h,f=u-r,g=d-r,p=new P(e.left+o,e.top+e.topOffset+r).transform(this.calcTransformMatrix()).transform(this.canvas.viewportTransform).multiply(new P(c.clientWidth/u,c.clientHeight/d));return p.x<0&&(p.x=0),p.x>f&&(p.x=f),p.y<0&&(p.y=0),p.y>g&&(p.y=g),p.x+=this.canvas._offset.left,p.y+=this.canvas._offset.top,{left:"".concat(p.x,"px"),top:"".concat(p.y,"px"),fontSize:"".concat(r,"px"),charHeight:r}}_saveEditingProps(){this._savedProps={hasControls:this.hasControls,borderColor:this.borderColor,lockMovementX:this.lockMovementX,lockMovementY:this.lockMovementY,hoverCursor:this.hoverCursor,selectable:this.selectable,defaultCursor:this.canvas&&this.canvas.defaultCursor,moveCursor:this.canvas&&this.canvas.moveCursor}}_restoreEditingProps(){this._savedProps&&(this.hoverCursor=this._savedProps.hoverCursor,this.hasControls=this._savedProps.hasControls,this.borderColor=this._savedProps.borderColor,this.selectable=this._savedProps.selectable,this.lockMovementX=this._savedProps.lockMovementX,this.lockMovementY=this._savedProps.lockMovementY,this.canvas&&(this.canvas.defaultCursor=this._savedProps.defaultCursor||this.canvas.defaultCursor,this.canvas.moveCursor=this._savedProps.moveCursor||this.canvas.moveCursor),delete this._savedProps)}_exitEditing(){const t=this.hiddenTextarea;this.selected=!1,this.isEditing=!1,t&&(t.blur&&t.blur(),t.parentNode&&t.parentNode.removeChild(t)),this.hiddenTextarea=null,this.abortCursorAnimation(),this.selectionStart!==this.selectionEnd&&this.clearContextTop()}exitEditingImpl(){this._exitEditing(),this.selectionEnd=this.selectionStart,this._restoreEditingProps(),this._forceClearCache&&(this.initDimensions(),this.setCoords())}exitEditing(){const t=this._textBeforeEdit!==this.text;return this.exitEditingImpl(),this.fire("editing:exited"),t&&this.fire(Xc),this.canvas&&(this.canvas.fire("text:editing:exited",{target:this}),t&&this.canvas.fire("object:modified",{target:this})),this}_removeExtraneousStyles(){for(const t in this.styles)this._textLines[t]||delete this.styles[t]}removeStyleFromTo(t,e){const{lineIndex:s,charIndex:i}=this.get2DCursorLocation(t,!0),{lineIndex:n,charIndex:r}=this.get2DCursorLocation(e,!0);if(s!==n){if(this.styles[s])for(let o=i;o<this._unwrappedTextLines[s].length;o++)delete this.styles[s][o];if(this.styles[n])for(let o=r;o<this._unwrappedTextLines[n].length;o++){const h=this.styles[n][o];h&&(this.styles[s]||(this.styles[s]={}),this.styles[s][i+o-r]=h)}for(let o=s+1;o<=n;o++)delete this.styles[o];this.shiftLineStyles(n,s-n)}else if(this.styles[s]){const o=this.styles[s],h=r-i;for(let c=i;c<r;c++)delete o[c];for(const c in this.styles[s]){const u=parseInt(c,10);u>=r&&(o[u-h]=o[c],delete o[c])}}}shiftLineStyles(t,e){const s=Object.assign({},this.styles);for(const i in this.styles){const n=parseInt(i,10);n>t&&(this.styles[n+e]=s[n],s[n-e]||delete this.styles[n])}}insertNewlineStyleObject(t,e,s,i){const n={},r=this._unwrappedTextLines[t].length,o=r===e;let h=!1;s||(s=1),this.shiftLineStyles(t,s);const c=this.styles[t]?this.styles[t][e===0?e:e-1]:void 0;for(const d in this.styles[t]){const f=parseInt(d,10);f>=e&&(h=!0,n[f-e]=this.styles[t][d],o&&e===0||delete this.styles[t][d])}let u=!1;for(h&&!o&&(this.styles[t+s]=n,u=!0),(u||r>e)&&s--;s>0;)i&&i[s-1]?this.styles[t+s]={0:T({},i[s-1])}:c?this.styles[t+s]={0:T({},c)}:delete this.styles[t+s],s--;this._forceClearCache=!0}insertCharStyleObject(t,e,s,i){this.styles||(this.styles={});const n=this.styles[t],r=n?T({},n):{};s||(s=1);for(const h in r){const c=parseInt(h,10);c>=e&&(n[c+s]=r[c],r[c-s]||delete n[c])}if(this._forceClearCache=!0,i){for(;s--;)Object.keys(i[s]).length&&(this.styles[t]||(this.styles[t]={}),this.styles[t][e+s]=T({},i[s]));return}if(!n)return;const o=n[e?e-1:1];for(;o&&s--;)this.styles[t][e+s]=T({},o)}insertNewStyleBlock(t,e,s){const i=this.get2DCursorLocation(e,!0),n=[0];let r,o=0;for(let h=0;h<t.length;h++)t[h]===`
|
|
56
|
-
`?(o++,n[o]=0):n[o]++;for(n[0]>0&&(this.insertCharStyleObject(i.lineIndex,i.charIndex,n[0],s),s=s&&s.slice(n[0]+1)),o&&this.insertNewlineStyleObject(i.lineIndex,i.charIndex+n[0],o),r=1;r<o;r++)n[r]>0?this.insertCharStyleObject(i.lineIndex+r,0,n[r],s):s&&this.styles[i.lineIndex+r]&&s[0]&&(this.styles[i.lineIndex+r][0]=s[0]),s=s&&s.slice(n[r]+1);n[r]>0&&this.insertCharStyleObject(i.lineIndex+r,0,n[r],s)}removeChars(t){let e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:t+1;this.removeStyleFromTo(t,e),this._text.splice(t,e-t),this.text=this._text.join(""),this.set("dirty",!0),this.initDimensions(),this.setCoords(),this._removeExtraneousStyles()}insertChars(t,e,s){let i=arguments.length>3&&arguments[3]!==void 0?arguments[3]:s;i>s&&this.removeStyleFromTo(s,i);const n=this.graphemeSplit(t);this.insertNewStyleBlock(n,s,e),this._text=[...this._text.slice(0,s),...n,...this._text.slice(i)],this.text=this._text.join(""),this.set("dirty",!0),this.initDimensions(),this.setCoords(),this._removeExtraneousStyles()}setSelectionStartEndWithShift(t,e,s){s<=t?(e===t?this._selectionDirection=dt:this._selectionDirection===It&&(this._selectionDirection=dt,this.selectionEnd=t),this.selectionStart=s):s>t&&s<e?this._selectionDirection===It?this.selectionEnd=s:this.selectionStart=s:(e===t?this._selectionDirection=It:this._selectionDirection===dt&&(this._selectionDirection=It,this.selectionStart=e),this.selectionEnd=s)}}class ww extends _w{initHiddenTextarea(){const t=this.canvas&&Ls(this.canvas.getElement())||Vo(),e=t.createElement("textarea");Object.entries({autocapitalize:"off",autocorrect:"off",autocomplete:"off",spellcheck:"false","data-fabric":"textarea",wrap:"off"}).map(r=>{let[o,h]=r;return e.setAttribute(o,h)});const{top:s,left:i,fontSize:n}=this._calcTextareaPosition();e.style.cssText="position: absolute; top: ".concat(s,"; left: ").concat(i,"; z-index: -999; opacity: 0; width: 1px; height: 1px; font-size: 1px; padding-top: ").concat(n,";"),(this.hiddenTextareaContainer||t.body).appendChild(e),Object.entries({blur:"blur",keydown:"onKeyDown",keyup:"onKeyUp",input:"onInput",copy:"copy",cut:"copy",paste:"paste",compositionstart:"onCompositionStart",compositionupdate:"onCompositionUpdate",compositionend:"onCompositionEnd"}).map(r=>{let[o,h]=r;return e.addEventListener(o,this[h].bind(this))}),this.hiddenTextarea=e}blur(){this.abortCursorAnimation()}onKeyDown(t){if(!this.isEditing)return;const e=this.direction==="rtl"?this.keysMapRtl:this.keysMap;if(t.keyCode in e)this[e[t.keyCode]](t);else{if(!(t.keyCode in this.ctrlKeysMapDown)||!t.ctrlKey&&!t.metaKey)return;this[this.ctrlKeysMapDown[t.keyCode]](t)}t.stopImmediatePropagation(),t.preventDefault(),t.keyCode>=33&&t.keyCode<=40?(this.inCompositionMode=!1,this.clearContextTop(),this.renderCursorOrSelection()):this.canvas&&this.canvas.requestRenderAll()}onKeyUp(t){!this.isEditing||this._copyDone||this.inCompositionMode?this._copyDone=!1:t.keyCode in this.ctrlKeysMapUp&&(t.ctrlKey||t.metaKey)&&(this[this.ctrlKeysMapUp[t.keyCode]](t),t.stopImmediatePropagation(),t.preventDefault(),this.canvas&&this.canvas.requestRenderAll())}onInput(t){const e=this.fromPaste;if(this.fromPaste=!1,t&&t.stopPropagation(),!this.isEditing)return;const s=()=>{this.updateFromTextArea(),this.fire(zc),this.canvas&&(this.canvas.fire("text:changed",{target:this}),this.canvas.requestRenderAll())};if(this.hiddenTextarea.value==="")return this.styles={},void s();const i=this._splitTextIntoLines(this.hiddenTextarea.value).graphemeText,n=this._text.length,r=i.length,o=this.selectionStart,h=this.selectionEnd,c=o!==h;let u,d,f,g,p=r-n;const b=this.fromStringToGraphemeSelection(this.hiddenTextarea.selectionStart,this.hiddenTextarea.selectionEnd,this.hiddenTextarea.value),_=o>b.selectionStart;c?(d=this._text.slice(o,h),p+=h-o):r<n&&(d=_?this._text.slice(h+p,h):this._text.slice(o,o-p));const v=i.slice(b.selectionEnd-p,b.selectionEnd);if(d&&d.length&&(v.length&&(u=this.getSelectionStyles(o,o+1,!1),u=v.map(()=>u[0])),c?(f=o,g=h):_?(f=h-d.length,g=h):(f=h,g=h+d.length),this.removeStyleFromTo(f,g)),v.length){const{copyPasteData:x}=ni();e&&v.join("")===x.copiedText&&!ht.disableStyleCopyPaste&&(u=x.copiedTextStyle),this.insertNewStyleBlock(v,o,u)}s()}onCompositionStart(){this.inCompositionMode=!0}onCompositionEnd(){this.inCompositionMode=!1}onCompositionUpdate(t){let{target:e}=t;const{selectionStart:s,selectionEnd:i}=e;this.compositionStart=s,this.compositionEnd=i,this.updateTextareaPosition()}copy(){if(this.selectionStart===this.selectionEnd)return;const{copyPasteData:t}=ni();t.copiedText=this.getSelectedText(),ht.disableStyleCopyPaste?t.copiedTextStyle=void 0:t.copiedTextStyle=this.getSelectionStyles(this.selectionStart,this.selectionEnd,!0),this._copyDone=!0}paste(){this.fromPaste=!0}_getWidthBeforeCursor(t,e){let s,i=this._getLineLeftOffset(t);return e>0&&(s=this.__charBounds[t][e-1],i+=s.left+s.width),i}getDownCursorOffset(t,e){const s=this._getSelectionForOffset(t,e),i=this.get2DCursorLocation(s),n=i.lineIndex;if(n===this._textLines.length-1||t.metaKey||t.keyCode===34)return this._text.length-s;const r=i.charIndex,o=this._getWidthBeforeCursor(n,r),h=this._getIndexOnLine(n+1,o);return this._textLines[n].slice(r).length+h+1+this.missingNewlineOffset(n)}_getSelectionForOffset(t,e){return t.shiftKey&&this.selectionStart!==this.selectionEnd&&e?this.selectionEnd:this.selectionStart}getUpCursorOffset(t,e){const s=this._getSelectionForOffset(t,e),i=this.get2DCursorLocation(s),n=i.lineIndex;if(n===0||t.metaKey||t.keyCode===33)return-s;const r=i.charIndex,o=this._getWidthBeforeCursor(n,r),h=this._getIndexOnLine(n-1,o),c=this._textLines[n].slice(0,r),u=this.missingNewlineOffset(n-1);return-this._textLines[n-1].length+h-c.length+(1-u)}_getIndexOnLine(t,e){const s=this._textLines[t];let i,n,r=this._getLineLeftOffset(t),o=0;for(let h=0,c=s.length;h<c;h++)if(i=this.__charBounds[t][h].width,r+=i,r>e){n=!0;const u=r-i,d=r,f=Math.abs(u-e);o=Math.abs(d-e)<f?h:h-1;break}return n||(o=s.length-1),o}moveCursorDown(t){this.selectionStart>=this._text.length&&this.selectionEnd>=this._text.length||this._moveCursorUpOrDown("Down",t)}moveCursorUp(t){this.selectionStart===0&&this.selectionEnd===0||this._moveCursorUpOrDown("Up",t)}_moveCursorUpOrDown(t,e){const s=this["get".concat(t,"CursorOffset")](e,this._selectionDirection===It);if(e.shiftKey?this.moveCursorWithShift(s):this.moveCursorWithoutShift(s),s!==0){const i=this.text.length;this.selectionStart=wr(0,this.selectionStart,i),this.selectionEnd=wr(0,this.selectionEnd,i),this.abortCursorAnimation(),this.initDelayedCursor(),this._fireSelectionChanged(),this._updateTextarea()}}moveCursorWithShift(t){const e=this._selectionDirection===dt?this.selectionStart+t:this.selectionEnd+t;return this.setSelectionStartEndWithShift(this.selectionStart,this.selectionEnd,e),t!==0}moveCursorWithoutShift(t){return t<0?(this.selectionStart+=t,this.selectionEnd=this.selectionStart):(this.selectionEnd+=t,this.selectionStart=this.selectionEnd),t!==0}moveCursorLeft(t){this.selectionStart===0&&this.selectionEnd===0||this._moveCursorLeftOrRight("Left",t)}_move(t,e,s){let i;if(t.altKey)i=this["findWordBoundary".concat(s)](this[e]);else{if(!t.metaKey&&t.keyCode!==35&&t.keyCode!==36)return this[e]+=s==="Left"?-1:1,!0;i=this["findLineBoundary".concat(s)](this[e])}return i!==void 0&&this[e]!==i&&(this[e]=i,!0)}_moveLeft(t,e){return this._move(t,e,"Left")}_moveRight(t,e){return this._move(t,e,"Right")}moveCursorLeftWithoutShift(t){let e=!0;return this._selectionDirection=dt,this.selectionEnd===this.selectionStart&&this.selectionStart!==0&&(e=this._moveLeft(t,"selectionStart")),this.selectionEnd=this.selectionStart,e}moveCursorLeftWithShift(t){return this._selectionDirection===It&&this.selectionStart!==this.selectionEnd?this._moveLeft(t,"selectionEnd"):this.selectionStart!==0?(this._selectionDirection=dt,this._moveLeft(t,"selectionStart")):void 0}moveCursorRight(t){this.selectionStart>=this._text.length&&this.selectionEnd>=this._text.length||this._moveCursorLeftOrRight("Right",t)}_moveCursorLeftOrRight(t,e){const s="moveCursor".concat(t).concat(e.shiftKey?"WithShift":"WithoutShift");this._currentCursorOpacity=1,this[s](e)&&(this.abortCursorAnimation(),this.initDelayedCursor(),this._fireSelectionChanged(),this._updateTextarea())}moveCursorRightWithShift(t){return this._selectionDirection===dt&&this.selectionStart!==this.selectionEnd?this._moveRight(t,"selectionStart"):this.selectionEnd!==this._text.length?(this._selectionDirection=It,this._moveRight(t,"selectionEnd")):void 0}moveCursorRightWithoutShift(t){let e=!0;return this._selectionDirection=It,this.selectionStart===this.selectionEnd?(e=this._moveRight(t,"selectionStart"),this.selectionEnd=this.selectionStart):this.selectionStart=this.selectionEnd,e}}const Qf=a=>!!a.button;class xw extends ww{constructor(){super(...arguments),A(this,"draggableTextDelegate",void 0)}initBehavior(){this.on("mousedown",this._mouseDownHandler),this.on("mousedown:before",this._mouseDownHandlerBefore),this.on("mouseup",this.mouseUpHandler),this.on("mousedblclick",this.doubleClickHandler),this.on("tripleclick",this.tripleClickHandler),this.__lastClickTime=+new Date,this.__lastLastClickTime=+new Date,this.__lastPointer={},this.on("mousedown",this.onMouseDown),this.draggableTextDelegate=new vw(this),super.initBehavior()}shouldStartDragging(){return this.draggableTextDelegate.isActive()}onDragStart(t){return this.draggableTextDelegate.onDragStart(t)}canDrop(t){return this.draggableTextDelegate.canDrop(t)}onMouseDown(t){if(!this.canvas)return;this.__newClickTime=+new Date;const e=t.pointer;this.isTripleClick(e)&&(this.fire("tripleclick",t),wf(t.e)),this.__lastLastClickTime=this.__lastClickTime,this.__lastClickTime=this.__newClickTime,this.__lastPointer=e,this.__lastSelected=this.selected&&!this.getActiveControl()}isTripleClick(t){return this.__newClickTime-this.__lastClickTime<500&&this.__lastClickTime-this.__lastLastClickTime<500&&this.__lastPointer.x===t.x&&this.__lastPointer.y===t.y}doubleClickHandler(t){this.isEditing&&this.selectWord(this.getSelectionStartFromPointer(t.e))}tripleClickHandler(t){this.isEditing&&this.selectLine(this.getSelectionStartFromPointer(t.e))}_mouseDownHandler(t){let{e}=t;this.canvas&&this.editable&&!Qf(e)&&!this.getActiveControl()&&(this.draggableTextDelegate.start(e)||(this.canvas.textEditingManager.register(this),this.selected&&(this.inCompositionMode=!1,this.setCursorByClick(e)),this.isEditing&&(this.__selectionStartOnMouseDown=this.selectionStart,this.selectionStart===this.selectionEnd&&this.abortCursorAnimation(),this.renderCursorOrSelection())))}_mouseDownHandlerBefore(t){let{e}=t;this.canvas&&this.editable&&!Qf(e)&&(this.selected=this===this.canvas._activeObject)}mouseUpHandler(t){let{e,transform:s}=t;const i=this.draggableTextDelegate.end(e);if(this.canvas){this.canvas.textEditingManager.unregister(this);const n=this.canvas._activeObject;if(n&&n!==this)return}!this.editable||this.group&&!this.group.interactive||s&&s.actionPerformed||Qf(e)||i||(this.__lastSelected&&!this.getActiveControl()?(this.selected=!1,this.__lastSelected=!1,this.enterEditing(e),this.selectionStart===this.selectionEnd?this.initDelayedCursor(!0):this.renderCursorOrSelection()):this.selected=!0)}setCursorByClick(t){const e=this.getSelectionStartFromPointer(t),s=this.selectionStart,i=this.selectionEnd;t.shiftKey?this.setSelectionStartEndWithShift(s,i,e):(this.selectionStart=e,this.selectionEnd=e),this.isEditing&&(this._fireSelectionChanged(),this._updateTextarea())}getSelectionStartFromPointer(t){const e=this.canvas.getScenePoint(t).transform(Xe(this.calcTransformMatrix())).add(new P(-this._getLeftOffset(),-this._getTopOffset()));let s=0,i=0,n=0;for(let c=0;c<this._textLines.length&&s<=e.y;c++)s+=this.getHeightOfLine(c),n=c,c>0&&(i+=this._textLines[c-1].length+this.missingNewlineOffset(c-1));let r=Math.abs(this._getLineLeftOffset(n));const o=this._textLines[n].length,h=this.__charBounds[n];for(let c=0;c<o;c++){const u=r+h[c].kernedWidth;if(e.x<=u){Math.abs(e.x-u)<=Math.abs(e.x-r)&&i++;break}r=u,i++}return Math.min(this.flipX?o-i:i,this._text.length)}}const vu="moveCursorUp",_u="moveCursorDown",wu="moveCursorLeft",xu="moveCursorRight",Su="exitEditing",Sw=T({selectionStart:0,selectionEnd:0,selectionColor:"rgba(17,119,255,0.3)",isEditing:!1,editable:!0,editingBorderColor:"rgba(102,153,255,0.25)",cursorWidth:2,cursorColor:"",cursorDelay:1e3,cursorDuration:600,caching:!0,hiddenTextareaContainer:null,keysMap:{9:Su,27:Su,33:vu,34:_u,35:xu,36:wu,37:wu,38:vu,39:xu,40:_u},keysMapRtl:{9:Su,27:Su,33:vu,34:_u,35:wu,36:xu,37:xu,38:vu,39:wu,40:_u},ctrlKeysMapDown:{65:"selectAll"},ctrlKeysMapUp:{67:"copy",88:"cut"}},{_selectionDirection:null,_reSpace:/\s|\r?\n/,inCompositionMode:!1});class Gi extends xw{static getDefaults(){return T(T({},super.getDefaults()),Gi.ownDefaults)}get type(){const t=super.type;return t==="itext"?"i-text":t}constructor(t,e){super(t,T(T({},Gi.ownDefaults),e)),this.initBehavior()}_set(t,e){return this.isEditing&&this._savedProps&&t in this._savedProps?(this._savedProps[t]=e,this):(t==="canvas"&&(this.canvas instanceof Uf&&this.canvas.textEditingManager.remove(this),e instanceof Uf&&e.textEditingManager.add(this)),super._set(t,e))}setSelectionStart(t){t=Math.max(t,0),this._updateAndFire("selectionStart",t)}setSelectionEnd(t){t=Math.min(t,this.text.length),this._updateAndFire("selectionEnd",t)}_updateAndFire(t,e){this[t]!==e&&(this._fireSelectionChanged(),this[t]=e),this._updateTextarea()}_fireSelectionChanged(){this.fire("selection:changed"),this.canvas&&this.canvas.fire("text:selection:changed",{target:this})}initDimensions(){this.isEditing&&this.initDelayedCursor(),super.initDimensions()}getSelectionStyles(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:this.selectionStart||0,e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:this.selectionEnd,s=arguments.length>2?arguments[2]:void 0;return super.getSelectionStyles(t,e,s)}setSelectionStyles(t){let e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:this.selectionStart||0,s=arguments.length>2&&arguments[2]!==void 0?arguments[2]:this.selectionEnd;return super.setSelectionStyles(t,e,s)}get2DCursorLocation(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:this.selectionStart,e=arguments.length>1?arguments[1]:void 0;return super.get2DCursorLocation(t,e)}render(t){super.render(t),this.cursorOffsetCache={},this.renderCursorOrSelection()}toCanvasElement(t){const e=this.isEditing;this.isEditing=!1;const s=super.toCanvasElement(t);return this.isEditing=e,s}renderCursorOrSelection(){if(!this.isEditing)return;const t=this.clearContextTop(!0);if(!t)return;const e=this._getCursorBoundaries();this.selectionStart!==this.selectionEnd||this.inCompositionMode?this.renderSelection(t,e):this.renderCursor(t,e),this.canvas.contextTopDirty=!0,t.restore()}_getCursorBoundaries(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:this.selectionStart,e=arguments.length>1?arguments[1]:void 0;const s=this._getLeftOffset(),i=this._getTopOffset(),n=this._getCursorBoundariesOffsets(t,e);return{left:s,top:i,leftOffset:n.left,topOffset:n.top}}_getCursorBoundariesOffsets(t,e){return e?this.__getCursorBoundariesOffsets(t):this.cursorOffsetCache&&"top"in this.cursorOffsetCache?this.cursorOffsetCache:this.cursorOffsetCache=this.__getCursorBoundariesOffsets(t)}__getCursorBoundariesOffsets(t){let e=0,s=0;const{charIndex:i,lineIndex:n}=this.get2DCursorLocation(t);for(let c=0;c<n;c++)e+=this.getHeightOfLine(c);const r=this._getLineLeftOffset(n),o=this.__charBounds[n][i];o&&(s=o.left),this.charSpacing!==0&&i===this._textLines[n].length&&(s-=this._getWidthOfCharSpacing());const h={top:e,left:r+(s>0?s:0)};return this.direction==="rtl"&&(this.textAlign===It||this.textAlign===hi||this.textAlign===Nh?h.left*=-1:this.textAlign===dt||this.textAlign===yu?h.left=r-(s>0?s:0):this.textAlign!==J&&this.textAlign!==jh||(h.left=r-(s>0?s:0))),h}renderCursorAt(t){this._renderCursor(this.canvas.contextTop,this._getCursorBoundaries(t,!0),t)}renderCursor(t,e){this._renderCursor(t,e,this.selectionStart)}getCursorRenderingData(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:this.selectionStart,e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:this._getCursorBoundaries(t);const s=this.get2DCursorLocation(t),i=s.lineIndex,n=s.charIndex>0?s.charIndex-1:0,r=this.getValueOfPropertyAt(i,n,"fontSize"),o=this.getObjectScaling().x*this.canvas.getZoom(),h=this.cursorWidth/o,c=this.getValueOfPropertyAt(i,n,"deltaY"),u=e.topOffset+(1-this._fontSizeFraction)*this.getHeightOfLine(i)/this.lineHeight-r*(1-this._fontSizeFraction);return{color:this.cursorColor||this.getValueOfPropertyAt(i,n,"fill"),opacity:this._currentCursorOpacity,left:e.left+e.leftOffset-h/2,top:u+e.top+c,width:h,height:r}}_renderCursor(t,e,s){const{color:i,opacity:n,left:r,top:o,width:h,height:c}=this.getCursorRenderingData(s,e);t.fillStyle=i,t.globalAlpha=n,t.fillRect(r,o,h,c)}renderSelection(t,e){const s={selectionStart:this.inCompositionMode?this.hiddenTextarea.selectionStart:this.selectionStart,selectionEnd:this.inCompositionMode?this.hiddenTextarea.selectionEnd:this.selectionEnd};this._renderSelection(t,s,e)}renderDragSourceEffect(){const t=this.draggableTextDelegate.getDragStartSelection();this._renderSelection(this.canvas.contextTop,t,this._getCursorBoundaries(t.selectionStart,!0))}renderDropTargetEffect(t){const e=this.getSelectionStartFromPointer(t);this.renderCursorAt(e)}_renderSelection(t,e,s){const i=e.selectionStart,n=e.selectionEnd,r=this.textAlign.includes(hi),o=this.get2DCursorLocation(i),h=this.get2DCursorLocation(n),c=o.lineIndex,u=h.lineIndex,d=o.charIndex<0?0:o.charIndex,f=h.charIndex<0?0:h.charIndex;for(let g=c;g<=u;g++){const p=this._getLineLeftOffset(g)||0;let b=this.getHeightOfLine(g),_=0,v=0,x=0;if(g===c&&(v=this.__charBounds[c][d].left),g>=c&&g<u)x=r&&!this.isEndOfWrapping(g)?this.width:this.getLineWidth(g)||5;else if(g===u)if(f===0)x=this.__charBounds[u][f].left;else{const M=this._getWidthOfCharSpacing();x=this.__charBounds[u][f-1].left+this.__charBounds[u][f-1].width-M}_=b,(this.lineHeight<1||g===u&&this.lineHeight>1)&&(b/=this.lineHeight);let C=s.left+p+v,S=b,E=0;const k=x-v;this.inCompositionMode?(t.fillStyle=this.compositionColor||"black",S=1,E=b):t.fillStyle=this.selectionColor,this.direction==="rtl"&&(this.textAlign===It||this.textAlign===hi||this.textAlign===Nh?C=this.width-C-k:this.textAlign===dt||this.textAlign===yu?C=s.left+p-x:this.textAlign!==J&&this.textAlign!==jh||(C=s.left+p-x)),t.fillRect(C,s.top+s.topOffset+E,k,S),s.topOffset+=_}}getCurrentCharFontSize(){const t=this._getCurrentCharIndex();return this.getValueOfPropertyAt(t.l,t.c,"fontSize")}getCurrentCharColor(){const t=this._getCurrentCharIndex();return this.getValueOfPropertyAt(t.l,t.c,zt)}_getCurrentCharIndex(){const t=this.get2DCursorLocation(this.selectionStart,!0),e=t.charIndex>0?t.charIndex-1:0;return{l:t.lineIndex,c:e}}dispose(){this.exitEditingImpl(),this.draggableTextDelegate.dispose(),super.dispose()}}A(Gi,"ownDefaults",Sw),A(Gi,"type","IText"),H.setClass(Gi),H.setClass(Gi,"i-text");class Ar extends Gi{static getDefaults(){return T(T({},super.getDefaults()),Ar.ownDefaults)}constructor(t,e){super(t,T(T({},Ar.ownDefaults),e))}static createControls(){return{controls:a_()}}initDimensions(){this.initialized&&(this.isEditing&&this.initDelayedCursor(),this._clearCache(),this.dynamicMinWidth=0,this._styleMap=this._generateStyleMap(this._splitText()),this.dynamicMinWidth>this.width&&this._set("width",this.dynamicMinWidth),this.textAlign.includes(hi)&&this.enlargeSpaces(),this.height=this.calcTextHeight())}_generateStyleMap(t){let e=0,s=0,i=0;const n={};for(let r=0;r<t.graphemeLines.length;r++)t.graphemeText[i]===`
|
|
57
|
-
`&&r>0?(s=0,i++,e++):!this.splitByGrapheme&&this._reSpaceAndTab.test(t.graphemeText[i])&&r>0&&(s++,i++),n[r]={line:e,offset:s},i+=t.graphemeLines[r].length,s+=t.graphemeLines[r].length;return n}styleHas(t,e){if(this._styleMap&&!this.isWrapping){const s=this._styleMap[e];s&&(e=s.line)}return super.styleHas(t,e)}isEmptyStyles(t){if(!this.styles)return!0;let e,s=0,i=t+1,n=!1;const r=this._styleMap[t],o=this._styleMap[t+1];r&&(t=r.line,s=r.offset),o&&(i=o.line,n=i===t,e=o.offset);const h=t===void 0?this.styles:{line:this.styles[t]};for(const c in h)for(const u in h[c]){const d=parseInt(u,10);if(d>=s&&(!n||d<e))for(const f in h[c][u])return!1}return!0}_getStyleDeclaration(t,e){if(this._styleMap&&!this.isWrapping){const s=this._styleMap[t];if(!s)return{};t=s.line,e=s.offset+e}return super._getStyleDeclaration(t,e)}_setStyleDeclaration(t,e,s){const i=this._styleMap[t];super._setStyleDeclaration(i.line,i.offset+e,s)}_deleteStyleDeclaration(t,e){const s=this._styleMap[t];super._deleteStyleDeclaration(s.line,s.offset+e)}_getLineStyle(t){const e=this._styleMap[t];return!!this.styles[e.line]}_setLineStyle(t){const e=this._styleMap[t];super._setLineStyle(e.line)}_wrapText(t,e){this.isWrapping=!0;const s=this.getGraphemeDataForRender(t),i=[];for(let n=0;n<s.wordsData.length;n++)i.push(...this._wrapLine(n,e,s));return this.isWrapping=!1,i}getGraphemeDataForRender(t){const e=this.splitByGrapheme,s=e?"":" ";let i=0;return{wordsData:t.map((n,r)=>{let o=0;const h=e?this.graphemeSplit(n):this.wordSplit(n);return h.length===0?[{word:[],width:0}]:h.map(c=>{const u=e?[c]:this.graphemeSplit(c),d=this._measureWord(u,r,o);return i=Math.max(d,i),o+=u.length+s.length,{word:u,width:d}})}),largestWordWidth:i}}_measureWord(t,e){let s,i=arguments.length>2&&arguments[2]!==void 0?arguments[2]:0,n=0;for(let r=0,o=t.length;r<o;r++)n+=this._getGraphemeBox(t[r],e,r+i,s,!0).kernedWidth,s=t[r];return n}wordSplit(t){return t.split(this._wordJoiners)}_wrapLine(t,e,s){let{largestWordWidth:i,wordsData:n}=s,r=arguments.length>3&&arguments[3]!==void 0?arguments[3]:0;const o=this._getWidthOfCharSpacing(),h=this.splitByGrapheme,c=[],u=h?"":" ";let d=0,f=[],g=0,p=0,b=!0;e-=r;const _=Math.max(e,i,this.dynamicMinWidth),v=n[t];let x;for(g=0,x=0;x<v.length;x++){const{word:C,width:S}=v[x];g+=C.length,d+=p+S-o,d>_&&!b?(c.push(f),f=[],d=S,b=!0):d+=o,b||h||f.push(u),f=f.concat(C),p=h?0:this._measureWord([u],t,g),g++,b=!1}return x&&c.push(f),i+r>this.dynamicMinWidth&&(this.dynamicMinWidth=i-o+r),c}isEndOfWrapping(t){return!this._styleMap[t+1]||this._styleMap[t+1].line!==this._styleMap[t].line}missingNewlineOffset(t,e){return this.splitByGrapheme&&!e?this.isEndOfWrapping(t)?1:0:1}_splitTextIntoLines(t){const e=super._splitTextIntoLines(t),s=this._wrapText(e.lines,this.width),i=new Array(s.length);for(let n=0;n<s.length;n++)i[n]=s[n].join("");return e.lines=i,e.graphemeLines=s,e}getMinWidth(){return Math.max(this.minWidth,this.dynamicMinWidth)}_removeExtraneousStyles(){const t=new Map;for(const e in this._styleMap){const s=parseInt(e,10);if(this._textLines[s]){const i=this._styleMap[e].line;t.set("".concat(i),!0)}}for(const e in this.styles)t.has(e)||delete this.styles[e]}toObject(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:[];return super.toObject(["minWidth","splitByGrapheme",...t])}}A(Ar,"type","Textbox"),A(Ar,"textLayoutProperties",[...Gi.textLayoutProperties,"width"]),A(Ar,"ownDefaults",{minWidth:20,dynamicMinWidth:2,lockScalingFlip:!0,noScaleCache:!1,_wordJoiners:/[ \t\r]/,splitByGrapheme:!1}),H.setClass(Ar);class I0 extends du{shouldPerformLayout(t){return!!t.target.clipPath&&super.shouldPerformLayout(t)}shouldLayoutClipPath(){return!1}calcLayoutResult(t,e){const{target:s}=t,{clipPath:i,group:n}=s;if(!i||!this.shouldPerformLayout(t))return;const{width:r,height:o}=ri(o0(s,i)),h=new P(r,o);if(i.absolutePositioned)return{center:_r(i.getRelativeCenterPoint(),void 0,n?n.calcTransformMatrix():void 0),size:h};{const c=i.getRelativeCenterPoint().transform(s.calcOwnMatrix(),!0);if(this.shouldPerformLayout(t)){const{center:u=new P,correction:d=new P}=this.calcBoundingBox(e,t)||{};return{center:u.add(c),correction:d.subtract(c),size:h}}return{center:s.getRelativeCenterPoint().add(c),size:h}}}}A(I0,"type","clip-path"),H.setClass(I0);class N0 extends du{getInitialSize(t,e){let{target:s}=t,{size:i}=e;return new P(s.width||i.x,s.height||i.y)}}A(N0,"type","fixed"),H.setClass(N0);class Cw extends Lh{subscribeTargets(t){const e=t.target;t.targets.reduce((s,i)=>(i.parent&&s.add(i.parent),s),new Set).forEach(s=>{s.layoutManager.subscribeTargets({target:s,targets:[e]})})}unsubscribeTargets(t){const e=t.target,s=e.getObjects();t.targets.reduce((i,n)=>(n.parent&&i.add(n.parent),i),new Set).forEach(i=>{!s.some(n=>n.parent===i)&&i.layoutManager.unsubscribeTargets({target:i,targets:[e]})})}}class Tr extends ai{static getDefaults(){return T(T({},super.getDefaults()),Tr.ownDefaults)}constructor(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:[],e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};super(),Object.assign(this,Tr.ownDefaults),this.setOptions(e);const{left:s,top:i,layoutManager:n}=e;this.groupInit(t,{left:s,top:i,layoutManager:n??new Cw})}_shouldSetNestedCoords(){return!0}__objectSelectionMonitor(){}multiSelectAdd(){for(var t=arguments.length,e=new Array(t),s=0;s<t;s++)e[s]=arguments[s];this.multiSelectionStacking==="selection-order"?this.add(...e):e.forEach(i=>{const n=this._objects.findIndex(o=>o.isInFrontOf(i)),r=n===-1?this.size():n;this.insertAt(r,i)})}canEnterGroup(t){return this.getObjects().some(e=>e.isDescendantOf(t)||t.isDescendantOf(e))?(Oi("error","ActiveSelection: circular object trees are not supported, this call has no effect"),!1):super.canEnterGroup(t)}enterGroup(t,e){t.parent&&t.parent===t.group?t.parent._exitGroup(t):t.group&&t.parent!==t.group&&t.group.remove(t),this._enterGroup(t,e)}exitGroup(t,e){this._exitGroup(t,e),t.parent&&t.parent._enterGroup(t,!0)}_onAfterObjectsChange(t,e){super._onAfterObjectsChange(t,e);const s=new Set;e.forEach(i=>{const{parent:n}=i;n&&s.add(n)}),t===Gf?s.forEach(i=>{i._onAfterObjectsChange(cu,e)}):s.forEach(i=>{i._set("dirty",!0)})}onDeselect(){return this.removeAll(),!1}toString(){return"#<ActiveSelection: (".concat(this.complexity(),")>")}shouldCache(){return!1}isOnACache(){return!1}_renderControls(t,e,s){t.save(),t.globalAlpha=this.isMoving?this.borderOpacityWhenMoving:1;const i=T(T({hasControls:!1},s),{},{forActiveSelection:!0});for(let n=0;n<this._objects.length;n++)this._objects[n]._renderControls(t,i);super._renderControls(t,e),t.restore()}}A(Tr,"type","ActiveSelection"),A(Tr,"ownDefaults",{multiSelectionStacking:"canvas-stacking"}),H.setClass(Tr),H.setClass(Tr,"activeSelection");class Aw{constructor(){A(this,"resources",{})}applyFilters(t,e,s,i,n){const r=n.getContext("2d");if(!r)return;r.drawImage(e,0,0,s,i);const o={sourceWidth:s,sourceHeight:i,imageData:r.getImageData(0,0,s,i),originalEl:e,originalImageData:r.getImageData(0,0,s,i),canvasEl:n,ctx:r,filterBackend:this};t.forEach(c=>{c.applyTo(o)});const{imageData:h}=o;return h.width===s&&h.height===i||(n.width=h.width,n.height=h.height),r.putImageData(h,0,0),o}}class j0{constructor(){let{tileSize:t=ht.textureSize}=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};A(this,"aPosition",new Float32Array([0,0,0,1,1,0,1,1])),A(this,"resources",{}),this.tileSize=t,this.setupGLContext(t,t),this.captureGPUInfo()}setupGLContext(t,e){this.dispose(),this.createWebGLCanvas(t,e)}createWebGLCanvas(t,e){const s=Rs({width:t,height:e}),i=s.getContext("webgl",{alpha:!0,premultipliedAlpha:!1,depth:!1,stencil:!1,antialias:!1});i&&(i.clearColor(0,0,0,0),this.canvas=s,this.gl=i)}applyFilters(t,e,s,i,n,r){const o=this.gl,h=n.getContext("2d");if(!o||!h)return;let c;r&&(c=this.getCachedTexture(r,e));const u={originalWidth:e.width||e.naturalWidth||0,originalHeight:e.height||e.naturalHeight||0,sourceWidth:s,sourceHeight:i,destinationWidth:s,destinationHeight:i,context:o,sourceTexture:this.createTexture(o,s,i,c?void 0:e),targetTexture:this.createTexture(o,s,i),originalTexture:c||this.createTexture(o,s,i,c?void 0:e),passes:t.length,webgl:!0,aPosition:this.aPosition,programCache:this.programCache,pass:0,filterBackend:this,targetCanvas:n},d=o.createFramebuffer();return o.bindFramebuffer(o.FRAMEBUFFER,d),t.forEach(f=>{f&&f.applyTo(u)}),function(f){const g=f.targetCanvas,p=g.width,b=g.height,_=f.destinationWidth,v=f.destinationHeight;p===_&&b===v||(g.width=_,g.height=v)}(u),this.copyGLTo2D(o,u),o.bindTexture(o.TEXTURE_2D,null),o.deleteTexture(u.sourceTexture),o.deleteTexture(u.targetTexture),o.deleteFramebuffer(d),h.setTransform(1,0,0,1,0,0),u}dispose(){this.canvas&&(this.canvas=null,this.gl=null),this.clearWebGLCaches()}clearWebGLCaches(){this.programCache={},this.textureCache={}}createTexture(t,e,s,i,n){const{NEAREST:r,TEXTURE_2D:o,RGBA:h,UNSIGNED_BYTE:c,CLAMP_TO_EDGE:u,TEXTURE_MAG_FILTER:d,TEXTURE_MIN_FILTER:f,TEXTURE_WRAP_S:g,TEXTURE_WRAP_T:p}=t,b=t.createTexture();return t.bindTexture(o,b),t.texParameteri(o,d,n||r),t.texParameteri(o,f,n||r),t.texParameteri(o,g,u),t.texParameteri(o,p,u),i?t.texImage2D(o,0,h,h,c,i):t.texImage2D(o,0,h,e,s,0,h,c,null),b}getCachedTexture(t,e,s){const{textureCache:i}=this;if(i[t])return i[t];{const n=this.createTexture(this.gl,e.width,e.height,e,s);return n&&(i[t]=n),n}}evictCachesForKey(t){this.textureCache[t]&&(this.gl.deleteTexture(this.textureCache[t]),delete this.textureCache[t])}copyGLTo2D(t,e){const s=t.canvas,i=e.targetCanvas,n=i.getContext("2d");if(!n)return;n.translate(0,i.height),n.scale(1,-1);const r=s.height-i.height;n.drawImage(s,0,r,i.width,i.height,0,0,i.width,i.height)}copyGLTo2DPutImageData(t,e){const s=e.targetCanvas.getContext("2d"),i=e.destinationWidth,n=e.destinationHeight,r=i*n*4;if(!s)return;const o=new Uint8Array(this.imageBuffer,0,r),h=new Uint8ClampedArray(this.imageBuffer,0,r);t.readPixels(0,0,i,n,t.RGBA,t.UNSIGNED_BYTE,o);const c=new ImageData(h,i,n);s.putImageData(c,0,0)}captureGPUInfo(){if(this.gpuInfo)return this.gpuInfo;const t=this.gl,e={renderer:"",vendor:""};if(!t)return e;const s=t.getExtension("WEBGL_debug_renderer_info");if(s){const i=t.getParameter(s.UNMASKED_RENDERER_WEBGL),n=t.getParameter(s.UNMASKED_VENDOR_WEBGL);i&&(e.renderer=i.toLowerCase()),n&&(e.vendor=n.toLowerCase())}return this.gpuInfo=e,e}}let Jf;function Tw(){const{WebGLProbe:a}=ni();return a.queryWebGL(ms()),ht.enableGLFiltering&&a.isSupported(ht.textureSize)?new j0({tileSize:ht.textureSize}):new Aw}function Zf(){return!Jf&&(!(arguments.length>0&&arguments[0]!==void 0)||arguments[0])&&(Jf=Tw()),Jf}const Ew=["filters","resizeFilter","src","crossOrigin","type"],B0=["cropX","cropY"];class be extends pe{static getDefaults(){return T(T({},super.getDefaults()),be.ownDefaults)}constructor(t,e){super(),A(this,"_lastScaleX",1),A(this,"_lastScaleY",1),A(this,"_filterScalingX",1),A(this,"_filterScalingY",1),this.filters=[],Object.assign(this,be.ownDefaults),this.setOptions(e),this.cacheKey="texture".concat(En()),this.setElement(typeof t=="string"?(this.canvas&&Ls(this.canvas.getElement())||Vo()).getElementById(t):t,e)}getElement(){return this._element}setElement(t){var e;let s=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};this.removeTexture(this.cacheKey),this.removeTexture("".concat(this.cacheKey,"_filtered")),this._element=t,this._originalElement=t,this._setWidthHeight(s),(e=t.classList)===null||e===void 0||e.add(be.CSS_CANVAS),this.filters.length!==0&&this.applyFilters(),this.resizeFilter&&this.applyResizeFilters()}removeTexture(t){const e=Zf(!1);e instanceof j0&&e.evictCachesForKey(t)}dispose(){super.dispose(),this.removeTexture(this.cacheKey),this.removeTexture("".concat(this.cacheKey,"_filtered")),this._cacheContext=null,["_originalElement","_element","_filteredEl","_cacheCanvas"].forEach(t=>{const e=this[t];e&&ni().dispose(e),this[t]=void 0})}getCrossOrigin(){return this._originalElement&&(this._originalElement.crossOrigin||null)}getOriginalSize(){const t=this.getElement();return t?{width:t.naturalWidth||t.width,height:t.naturalHeight||t.height}:{width:0,height:0}}_stroke(t){if(!this.stroke||this.strokeWidth===0)return;const e=this.width/2,s=this.height/2;t.beginPath(),t.moveTo(-e,-s),t.lineTo(e,-s),t.lineTo(e,s),t.lineTo(-e,s),t.lineTo(-e,-s),t.closePath()}toObject(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:[];const e=[];return this.filters.forEach(s=>{s&&e.push(s.toObject())}),T(T({},super.toObject([...B0,...t])),{},{src:this.getSrc(),crossOrigin:this.getCrossOrigin(),filters:e},this.resizeFilter?{resizeFilter:this.resizeFilter.toObject()}:{})}hasCrop(){return!!this.cropX||!!this.cropY||this.width<this._element.width||this.height<this._element.height}_toSVG(){const t=[],e=this._element,s=-this.width/2,i=-this.height/2;let n=[],r=[],o="",h="";if(!e)return[];if(this.hasCrop()){const c=En();n.push('<clipPath id="imageCrop_'+c+`">
|
|
49
|
+
`]}}static async fromElement(t,e,s){const i=Ni(t,this.ATTRIBUTE_NAMES,s),{left:n=0,top:r=0,radius:o=0}=i;return new this(T(T({},Ct(i,dw)),{},{radius:o,left:n-o,top:r-o}))}static fromObject(t){return super._fromObject(t)}}A(Bi,"type","Circle"),A(Bi,"cacheProperties",[...Fi,...E0]),A(Bi,"ownDefaults",{radius:0,startAngle:0,endAngle:360,counterClockwise:!1}),A(Bi,"ATTRIBUTE_NAMES",["cx","cy","r",...Mn]),N.setClass(Bi),N.setSVGClass(Bi);const fw=["x1","y1","x2","y2"],gw=["x1","y1","x2","y2"],$f=["x1","x2","y1","y2"];class Sr extends pe{constructor(){let[t,e,s,i]=arguments.length>0&&arguments[0]!==void 0?arguments[0]:[0,0,0,0],n=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};super(),Object.assign(this,Sr.ownDefaults),this.setOptions(n),this.x1=t,this.x2=s,this.y1=e,this.y2=i,this._setWidthHeight();const{left:r,top:o}=n;typeof r=="number"&&this.set(dt,r),typeof o=="number"&&this.set(Ve,o)}_setWidthHeight(){const{x1:t,y1:e,x2:s,y2:i}=this;this.width=Math.abs(s-t),this.height=Math.abs(i-e);const{left:n,top:r,width:o,height:h}=ri([{x:t,y:e},{x:s,y:i}]),c=new D(n+o/2,r+h/2);this.setPositionByOrigin(c,Q,Q)}_set(t,e){return super._set(t,e),$f.includes(t)&&this._setWidthHeight(),this}_render(t){t.beginPath();const e=this.calcLinePoints();t.moveTo(e.x1,e.y1),t.lineTo(e.x2,e.y2),t.lineWidth=this.strokeWidth;const s=t.strokeStyle;var i;bs(this.stroke)?t.strokeStyle=this.stroke.toLive(t):t.strokeStyle=(i=this.stroke)!==null&&i!==void 0?i:t.fillStyle,this.stroke&&this._renderStroke(t),t.strokeStyle=s}_findCenterFromElement(){return new D((this.x1+this.x2)/2,(this.y1+this.y2)/2)}toObject(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:[];return T(T({},super.toObject(t)),this.calcLinePoints())}_getNonTransformedDimensions(){const t=super._getNonTransformedDimensions();return this.strokeLineCap==="butt"&&(this.width===0&&(t.y-=this.strokeWidth),this.height===0&&(t.x-=this.strokeWidth)),t}calcLinePoints(){const{x1:t,x2:e,y1:s,y2:i,width:n,height:r}=this,o=t<=e?-1:1,h=s<=i?-1:1;return{x1:o*n/2,x2:o*-n/2,y1:h*r/2,y2:h*-r/2}}_toSVG(){const{x1:t,x2:e,y1:s,y2:i}=this.calcLinePoints();return["<line ","COMMON_PARTS",'x1="'.concat(t,'" y1="').concat(s,'" x2="').concat(e,'" y2="').concat(i,`" />
|
|
50
|
+
`)]}static async fromElement(t,e,s){const i=Ni(t,this.ATTRIBUTE_NAMES,s),{x1:n=0,y1:r=0,x2:o=0,y2:h=0}=i;return new this([n,r,o,h],Ct(i,fw))}static fromObject(t){let{x1:e,y1:s,x2:i,y2:n}=t,r=Ct(t,gw);return this._fromObject(T(T({},r),{},{points:[e,s,i,n]}),{extraParam:"points"})}}A(Sr,"type","Line"),A(Sr,"cacheProperties",[...Fi,...$f]),A(Sr,"ATTRIBUTE_NAMES",Mn.concat($f)),N.setClass(Sr),N.setSVGClass(Sr);class Cr extends pe{static getDefaults(){return T(T({},super.getDefaults()),Cr.ownDefaults)}constructor(t){super(),Object.assign(this,Cr.ownDefaults),this.setOptions(t)}_render(t){const e=this.width/2,s=this.height/2;t.beginPath(),t.moveTo(-e,s),t.lineTo(0,-s),t.lineTo(e,s),t.closePath(),this._renderPaintInOrder(t)}_toSVG(){const t=this.width/2,e=this.height/2;return["<polygon ","COMMON_PARTS",'points="',"".concat(-t," ").concat(e,",0 ").concat(-e,",").concat(t," ").concat(e),'" />']}}A(Cr,"type","Triangle"),A(Cr,"ownDefaults",{width:100,height:100}),N.setClass(Cr),N.setSVGClass(Cr);const k0=["rx","ry"];class Hi extends pe{static getDefaults(){return T(T({},super.getDefaults()),Hi.ownDefaults)}constructor(t){super(),Object.assign(this,Hi.ownDefaults),this.setOptions(t)}_set(t,e){switch(super._set(t,e),t){case"rx":this.rx=e,this.set("width",2*e);break;case"ry":this.ry=e,this.set("height",2*e)}return this}getRx(){return this.get("rx")*this.get(Me)}getRy(){return this.get("ry")*this.get(Je)}toObject(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:[];return super.toObject([...k0,...t])}_toSVG(){return["<ellipse ","COMMON_PARTS",'cx="0" cy="0" rx="'.concat(this.rx,'" ry="').concat(this.ry,`" />
|
|
51
|
+
`)]}_render(t){t.beginPath(),t.save(),t.transform(1,0,0,this.ry/this.rx,0,0),t.arc(0,0,this.rx,0,Ri,!1),t.restore(),this._renderPaintInOrder(t)}static async fromElement(t,e,s){const i=Ni(t,this.ATTRIBUTE_NAMES,s);return i.left=(i.left||0)-i.rx,i.top=(i.top||0)-i.ry,new this(i)}}function pw(a){if(!a)return[];const t=a.replace(/,/g," ").trim().split(/\s+/),e=[];for(let s=0;s<t.length;s+=2)e.push({x:parseFloat(t[s]),y:parseFloat(t[s+1])});return e}A(Hi,"type","Ellipse"),A(Hi,"cacheProperties",[...Fi,...k0]),A(Hi,"ownDefaults",{rx:0,ry:0}),A(Hi,"ATTRIBUTE_NAMES",[...Mn,"cx","cy","rx","ry"]),N.setClass(Hi),N.setSVGClass(Hi);const mw=["left","top"],M0={exactBoundingBox:!1};class Bs extends pe{static getDefaults(){return T(T({},super.getDefaults()),Bs.ownDefaults)}constructor(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:[],e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};super(),A(this,"strokeDiff",void 0),Object.assign(this,Bs.ownDefaults),this.setOptions(e),this.points=t;const{left:s,top:i}=e;this.initialized=!0,this.setBoundingBox(!0),typeof s=="number"&&this.set(dt,s),typeof i=="number"&&this.set(Ve,i)}isOpen(){return!0}_projectStrokeOnPoints(t){return Ym(this.points,t,this.isOpen())}_calcDimensions(t){t=T({scaleX:this.scaleX,scaleY:this.scaleY,skewX:this.skewX,skewY:this.skewY,strokeLineCap:this.strokeLineCap,strokeLineJoin:this.strokeLineJoin,strokeMiterLimit:this.strokeMiterLimit,strokeUniform:this.strokeUniform,strokeWidth:this.strokeWidth},t||{});const e=this.exactBoundingBox?this._projectStrokeOnPoints(t).map(c=>c.projectedPoint):this.points;if(e.length===0)return{left:0,top:0,width:0,height:0,pathOffset:new D,strokeOffset:new D,strokeDiff:new D};const s=ri(e),i=Ah(T(T({},t),{},{scaleX:1,scaleY:1})),n=ri(this.points.map(c=>ge(c,i,!0))),r=new D(this.scaleX,this.scaleY);let o=s.left+s.width/2,h=s.top+s.height/2;return this.exactBoundingBox&&(o-=h*Math.tan(Rt(this.skewX)),h-=o*Math.tan(Rt(this.skewY))),T(T({},s),{},{pathOffset:new D(o,h),strokeOffset:new D(n.left,n.top).subtract(new D(s.left,s.top)).multiply(r),strokeDiff:new D(s.width,s.height).subtract(new D(n.width,n.height)).multiply(r)})}_findCenterFromElement(){const t=ri(this.points);return new D(t.left+t.width/2,t.top+t.height/2)}setDimensions(){this.setBoundingBox()}setBoundingBox(t){const{left:e,top:s,width:i,height:n,pathOffset:r,strokeOffset:o,strokeDiff:h}=this._calcDimensions();this.set({width:i,height:n,pathOffset:r,strokeOffset:o,strokeDiff:h}),t&&this.setPositionByOrigin(new D(e+i/2,s+n/2),Q,Q)}isStrokeAccountedForInDimensions(){return this.exactBoundingBox}_getNonTransformedDimensions(){return this.exactBoundingBox?new D(this.width,this.height):super._getNonTransformedDimensions()}_getTransformedDimensions(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};if(this.exactBoundingBox){let r;if(Object.keys(t).some(o=>this.strokeUniform||this.constructor.layoutProperties.includes(o))){var e,s;const{width:o,height:h}=this._calcDimensions(t);r=new D((e=t.width)!==null&&e!==void 0?e:o,(s=t.height)!==null&&s!==void 0?s:h)}else{var i,n;r=new D((i=t.width)!==null&&i!==void 0?i:this.width,(n=t.height)!==null&&n!==void 0?n:this.height)}return r.multiply(new D(t.scaleX||this.scaleX,t.scaleY||this.scaleY))}return super._getTransformedDimensions(t)}_set(t,e){const s=this.initialized&&this[t]!==e,i=super._set(t,e);return this.exactBoundingBox&&s&&((t===Me||t===Je)&&this.strokeUniform&&this.constructor.layoutProperties.includes("strokeUniform")||this.constructor.layoutProperties.includes(t))&&this.setDimensions(),i}toObject(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:[];return T(T({},super.toObject(t)),{},{points:this.points.map(e=>{let{x:s,y:i}=e;return{x:s,y:i}})})}_toSVG(){const t=[],e=this.pathOffset.x,s=this.pathOffset.y,i=ht.NUM_FRACTION_DIGITS;for(let n=0,r=this.points.length;n<r;n++)t.push(At(this.points[n].x-e,i),",",At(this.points[n].y-s,i)," ");return["<".concat(this.constructor.type.toLowerCase()," "),"COMMON_PARTS",'points="'.concat(t.join(""),`" />
|
|
52
|
+
`)]}_render(t){const e=this.points.length,s=this.pathOffset.x,i=this.pathOffset.y;if(e&&!isNaN(this.points[e-1].y)){t.beginPath(),t.moveTo(this.points[0].x-s,this.points[0].y-i);for(let n=0;n<e;n++){const r=this.points[n];t.lineTo(r.x-s,r.y-i)}!this.isOpen()&&t.closePath(),this._renderPaintInOrder(t)}}complexity(){return this.points.length}static async fromElement(t,e,s){return new this(pw(t.getAttribute("points")),T(T({},Ct(Ni(t,this.ATTRIBUTE_NAMES,s),mw)),e))}static fromObject(t){return this._fromObject(t,{extraParam:"points"})}}A(Bs,"ownDefaults",M0),A(Bs,"type","Polyline"),A(Bs,"layoutProperties",[Xo,Wo,"strokeLineCap","strokeLineJoin","strokeMiterLimit","strokeWidth","strokeUniform","points"]),A(Bs,"cacheProperties",[...Fi,"points"]),A(Bs,"ATTRIBUTE_NAMES",[...Mn]),N.setClass(Bs),N.setSVGClass(Bs);class bu extends Bs{isOpen(){return!1}}A(bu,"ownDefaults",M0),A(bu,"type","Polygon"),N.setClass(bu),N.setSVGClass(bu);const P0=["fontSize","fontWeight","fontFamily","fontStyle"],D0=["underline","overline","linethrough"],O0=[...P0,"lineHeight","text","charSpacing","textAlign","styles","path","pathStartOffset","pathSide","pathAlign"],R0=[...O0,...D0,"textBackgroundColor","direction"],bw=[...P0,...D0,Pe,"strokeWidth",zt,"deltaY","textBackgroundColor"],yw={_reNewline:lf,_reSpacesAndTabs:/[ \t\r]/g,_reSpaceAndTab:/[ \t\r]/,_reWords:/\S+/g,fontSize:40,fontWeight:"normal",fontFamily:"Times New Roman",underline:!1,overline:!1,linethrough:!1,textAlign:dt,fontStyle:"normal",lineHeight:1.16,superscript:{size:.6,baseline:-.35},subscript:{size:.6,baseline:.11},textBackgroundColor:"",stroke:null,shadow:null,path:void 0,pathStartOffset:0,pathSide:dt,pathAlign:"baseline",_fontSizeFraction:.222,offsets:{underline:.1,linethrough:-.315,overline:-.88},_fontSizeMult:1.13,charSpacing:0,deltaY:0,direction:"ltr",CACHE_FONT_SIZE:400,MIN_TEXT_WIDTH:2},hi="justify",yu="justify-left",Nh="justify-right",jh="justify-center";class L0 extends pe{isEmptyStyles(t){if(!this.styles||t!==void 0&&!this.styles[t])return!0;const e=t===void 0?this.styles:{line:this.styles[t]};for(const s in e)for(const i in e[s])for(const n in e[s][i])return!1;return!0}styleHas(t,e){if(!this.styles||e!==void 0&&!this.styles[e])return!1;const s=e===void 0?this.styles:{0:this.styles[e]};for(const i in s)for(const n in s[i])if(s[i][n][t]!==void 0)return!0;return!1}cleanStyle(t){if(!this.styles)return!1;const e=this.styles;let s,i,n=0,r=!0,o=0;for(const h in e){s=0;for(const c in e[h]){const u=e[h][c]||{};n++,u[t]!==void 0?(i?u[t]!==i&&(r=!1):i=u[t],u[t]===this[t]&&delete u[t]):r=!1,Object.keys(u).length!==0?s++:delete e[h][c]}s===0&&delete e[h]}for(let h=0;h<this._textLines.length;h++)o+=this._textLines[h].length;r&&n===o&&(this[t]=i,this.removeStyle(t))}removeStyle(t){if(!this.styles)return;const e=this.styles;let s,i,n;for(i in e){for(n in s=e[i],s)delete s[n][t],Object.keys(s[n]).length===0&&delete s[n];Object.keys(s).length===0&&delete e[i]}}_extendStyles(t,e){const{lineIndex:s,charIndex:i}=this.get2DCursorLocation(t);this._getLineStyle(s)||this._setLineStyle(s);const n=bf(T(T({},this._getStyleDeclaration(s,i)),e),r=>r!==void 0);this._setStyleDeclaration(s,i,n)}getSelectionStyles(t,e,s){const i=[];for(let n=t;n<(e||t);n++)i.push(this.getStyleAtPosition(n,s));return i}getStyleAtPosition(t,e){const{lineIndex:s,charIndex:i}=this.get2DCursorLocation(t);return e?this.getCompleteStyleDeclaration(s,i):this._getStyleDeclaration(s,i)}setSelectionStyles(t,e,s){for(let i=e;i<(s||e);i++)this._extendStyles(i,t);this._forceClearCache=!0}_getStyleDeclaration(t,e){var s;const i=this.styles&&this.styles[t];return i&&(s=i[e])!==null&&s!==void 0?s:{}}getCompleteStyleDeclaration(t,e){return T(T({},yr(this,this.constructor._styleProperties)),this._getStyleDeclaration(t,e))}_setStyleDeclaration(t,e,s){this.styles[t][e]=s}_deleteStyleDeclaration(t,e){delete this.styles[t][e]}_getLineStyle(t){return!!this.styles[t]}_setLineStyle(t){this.styles[t]={}}_deleteLineStyle(t){delete this.styles[t]}}A(L0,"_styleProperties",bw);const vw=/ +/g,_w=/"/g;function qf(a,t,e,s,i){return" ".concat(function(n,r){let{left:o,top:h,width:c,height:u}=r,d=arguments.length>2&&arguments[2]!==void 0?arguments[2]:ht.NUM_FRACTION_DIGITS;const f=Mh(zt,n,!1),[g,p,b,_]=[o,h,c,u].map(v=>At(v,d));return"<rect ".concat(f,' x="').concat(g,'" y="').concat(p,'" width="').concat(b,'" height="').concat(_,'"></rect>')}(a,{left:t,top:e,width:s,height:i}),`
|
|
53
|
+
`)}const ww=["textAnchor","textDecoration","dx","dy","top","left","fontSize","strokeWidth"];let Kf;class me extends L0{static getDefaults(){return T(T({},super.getDefaults()),me.ownDefaults)}constructor(t,e){super(),A(this,"__charBounds",[]),Object.assign(this,me.ownDefaults),this.setOptions(e),this.styles||(this.styles={}),this.text=t,this.initialized=!0,this.path&&this.setPathInfo(),this.initDimensions(),this.setCoords()}setPathInfo(){const t=this.path;t&&(t.segmentsInfo=Wf(t.path))}_splitText(){const t=this._splitTextIntoLines(this.text);return this.textLines=t.lines,this._textLines=t.graphemeLines,this._unwrappedTextLines=t._unwrappedLines,this._text=t.graphemeText,t}initDimensions(){this._splitText(),this._clearCache(),this.dirty=!0,this.path?(this.width=this.path.width,this.height=this.path.height):(this.width=this.calcTextWidth()||this.cursorWidth||this.MIN_TEXT_WIDTH,this.height=this.calcTextHeight()),this.textAlign.includes(hi)&&this.enlargeSpaces()}enlargeSpaces(){let t,e,s,i,n,r,o;for(let h=0,c=this._textLines.length;h<c;h++)if((this.textAlign===hi||h!==c-1&&!this.isEndOfWrapping(h))&&(i=0,n=this._textLines[h],e=this.getLineWidth(h),e<this.width&&(o=this.textLines[h].match(this._reSpacesAndTabs)))){s=o.length,t=(this.width-e)/s;for(let u=0;u<=n.length;u++)r=this.__charBounds[h][u],this._reSpaceAndTab.test(n[u])?(r.width+=t,r.kernedWidth+=t,r.left+=i,i+=t):r.left+=i}}isEndOfWrapping(t){return t===this._textLines.length-1}missingNewlineOffset(t){return 1}get2DCursorLocation(t,e){const s=e?this._unwrappedTextLines:this._textLines;let i;for(i=0;i<s.length;i++){if(t<=s[i].length)return{lineIndex:i,charIndex:t};t-=s[i].length+this.missingNewlineOffset(i,e)}return{lineIndex:i-1,charIndex:s[i-1].length<t?s[i-1].length:t}}toString(){return"#<Text (".concat(this.complexity(),'): { "text": "').concat(this.text,'", "fontFamily": "').concat(this.fontFamily,'" }>')}_getCacheCanvasDimensions(){const t=super._getCacheCanvasDimensions(),e=this.fontSize;return t.width+=e*t.zoomX,t.height+=e*t.zoomY,t}_render(t){const e=this.path;e&&!e.isNotVisible()&&e._render(t),this._setTextStyles(t),this._renderTextLinesBackground(t),this._renderTextDecoration(t,"underline"),this._renderText(t),this._renderTextDecoration(t,"overline"),this._renderTextDecoration(t,"linethrough")}_renderText(t){this.paintFirst===Pe?(this._renderTextStroke(t),this._renderTextFill(t)):(this._renderTextFill(t),this._renderTextStroke(t))}_setTextStyles(t,e,s){if(t.textBaseline="alphabetic",this.path)switch(this.pathAlign){case Q:t.textBaseline="middle";break;case"ascender":t.textBaseline=Ve;break;case"descender":t.textBaseline=hf}t.font=this._getFontDeclaration(e,s)}calcTextWidth(){let t=this.getLineWidth(0);for(let e=1,s=this._textLines.length;e<s;e++){const i=this.getLineWidth(e);i>t&&(t=i)}return t}_renderTextLine(t,e,s,i,n,r){this._renderChars(t,e,s,i,n,r)}_renderTextLinesBackground(t){if(!this.textBackgroundColor&&!this.styleHas("textBackgroundColor"))return;const e=t.fillStyle,s=this._getLeftOffset();let i=this._getTopOffset();for(let n=0,r=this._textLines.length;n<r;n++){const o=this.getHeightOfLine(n);if(!this.textBackgroundColor&&!this.styleHas("textBackgroundColor",n)){i+=o;continue}const h=this._textLines[n].length,c=this._getLineLeftOffset(n);let u,d,f=0,g=0,p=this.getValueOfPropertyAt(n,0,"textBackgroundColor");for(let b=0;b<h;b++){const _=this.__charBounds[n][b];d=this.getValueOfPropertyAt(n,b,"textBackgroundColor"),this.path?(t.save(),t.translate(_.renderLeft,_.renderTop),t.rotate(_.angle),t.fillStyle=d,d&&t.fillRect(-_.width/2,-o/this.lineHeight*(1-this._fontSizeFraction),_.width,o/this.lineHeight),t.restore()):d!==p?(u=s+c+g,this.direction==="rtl"&&(u=this.width-u-f),t.fillStyle=p,p&&t.fillRect(u,i,f,o/this.lineHeight),g=_.left,f=_.width,p=d):f+=_.kernedWidth}d&&!this.path&&(u=s+c+g,this.direction==="rtl"&&(u=this.width-u-f),t.fillStyle=d,t.fillRect(u,i,f,o/this.lineHeight)),i+=o}t.fillStyle=e,this._removeShadow(t)}_measureChar(t,e,s,i){const n=xh.getFontCache(e),r=this._getFontDeclaration(e),o=s+t,h=s&&r===this._getFontDeclaration(i),c=e.fontSize/this.CACHE_FONT_SIZE;let u,d,f,g;if(s&&n[s]!==void 0&&(f=n[s]),n[t]!==void 0&&(g=u=n[t]),h&&n[o]!==void 0&&(d=n[o],g=d-f),u===void 0||f===void 0||d===void 0){const p=function(){return Kf||(Kf=Rs({width:0,height:0}).getContext("2d")),Kf}();this._setTextStyles(p,e,!0),u===void 0&&(g=u=p.measureText(t).width,n[t]=u),f===void 0&&h&&s&&(f=p.measureText(s).width,n[s]=f),h&&d===void 0&&(d=p.measureText(o).width,n[o]=d,g=d-f)}return{width:u*c,kernedWidth:g*c}}getHeightOfChar(t,e){return this.getValueOfPropertyAt(t,e,"fontSize")}measureLine(t){const e=this._measureLine(t);return this.charSpacing!==0&&(e.width-=this._getWidthOfCharSpacing()),e.width<0&&(e.width=0),e}_measureLine(t){let e,s,i=0;const n=this.pathSide===It,r=this.path,o=this._textLines[t],h=o.length,c=new Array(h);this.__charBounds[t]=c;for(let u=0;u<h;u++){const d=o[u];s=this._getGraphemeBox(d,t,u,e),c[u]=s,i+=s.kernedWidth,e=d}if(c[h]={left:s?s.left+s.width:0,width:0,kernedWidth:0,height:this.fontSize,deltaY:0},r&&r.segmentsInfo){let u=0;const d=r.segmentsInfo[r.segmentsInfo.length-1].length;switch(this.textAlign){case dt:u=n?d-i:0;break;case Q:u=(d-i)/2;break;case It:u=n?0:d-i}u+=this.pathStartOffset*(n?-1:1);for(let f=n?h-1:0;n?f>=0:f<h;n?f--:f++)s=c[f],u>d?u%=d:u<0&&(u+=d),this._setGraphemeOnPath(u,s),u+=s.kernedWidth}return{width:i,numOfSpaces:0}}_setGraphemeOnPath(t,e){const s=t+e.kernedWidth/2,i=this.path,n=b0(i.path,s,i.segmentsInfo);e.renderLeft=n.x-i.pathOffset.x,e.renderTop=n.y-i.pathOffset.y,e.angle=n.angle+(this.pathSide===It?Math.PI:0)}_getGraphemeBox(t,e,s,i,n){const r=this.getCompleteStyleDeclaration(e,s),o=i?this.getCompleteStyleDeclaration(e,s-1):{},h=this._measureChar(t,r,i,o);let c,u=h.kernedWidth,d=h.width;this.charSpacing!==0&&(c=this._getWidthOfCharSpacing(),d+=c,u+=c);const f={width:d,left:0,height:r.fontSize,kernedWidth:u,deltaY:r.deltaY};if(s>0&&!n){const g=this.__charBounds[e][s-1];f.left=g.left+g.width+h.kernedWidth-h.width}return f}getHeightOfLine(t){if(this.__lineHeights[t])return this.__lineHeights[t];let e=this.getHeightOfChar(t,0);for(let s=1,i=this._textLines[t].length;s<i;s++)e=Math.max(this.getHeightOfChar(t,s),e);return this.__lineHeights[t]=e*this.lineHeight*this._fontSizeMult}calcTextHeight(){let t,e=0;for(let s=0,i=this._textLines.length;s<i;s++)t=this.getHeightOfLine(s),e+=s===i-1?t/this.lineHeight:t;return e}_getLeftOffset(){return this.direction==="ltr"?-this.width/2:this.width/2}_getTopOffset(){return-this.height/2}_renderTextCommon(t,e){t.save();let s=0;const i=this._getLeftOffset(),n=this._getTopOffset();for(let r=0,o=this._textLines.length;r<o;r++){const h=this.getHeightOfLine(r),c=h/this.lineHeight,u=this._getLineLeftOffset(r);this._renderTextLine(e,t,this._textLines[r],i+u,n+s+c,r),s+=h}t.restore()}_renderTextFill(t){(this.fill||this.styleHas(zt))&&this._renderTextCommon(t,"fillText")}_renderTextStroke(t){(this.stroke&&this.strokeWidth!==0||!this.isEmptyStyles())&&(this.shadow&&!this.shadow.affectStroke&&this._removeShadow(t),t.save(),this._setLineDash(t,this.strokeDashArray),t.beginPath(),this._renderTextCommon(t,"strokeText"),t.closePath(),t.restore())}_renderChars(t,e,s,i,n,r){const o=this.getHeightOfLine(r),h=this.textAlign.includes(hi),c=this.path,u=!h&&this.charSpacing===0&&this.isEmptyStyles(r)&&!c,d=this.direction==="ltr",f=this.direction==="ltr"?1:-1,g=e.direction;let p,b,_,v,x,C="",S=0;if(e.save(),g!==this.direction&&(e.canvas.setAttribute("dir",d?"ltr":"rtl"),e.direction=d?"ltr":"rtl",e.textAlign=d?dt:It),n-=o*this._fontSizeFraction/this.lineHeight,u)return this._renderChar(t,e,r,0,s.join(""),i,n),void e.restore();for(let k=0,M=s.length-1;k<=M;k++)v=k===M||this.charSpacing||c,C+=s[k],_=this.__charBounds[r][k],S===0?(i+=f*(_.kernedWidth-_.width),S+=_.width):S+=_.kernedWidth,h&&!v&&this._reSpaceAndTab.test(s[k])&&(v=!0),v||(p=p||this.getCompleteStyleDeclaration(r,k),b=this.getCompleteStyleDeclaration(r,k+1),v=hu(p,b,!1)),v&&(c?(e.save(),e.translate(_.renderLeft,_.renderTop),e.rotate(_.angle),this._renderChar(t,e,r,k,C,-S/2,0),e.restore()):(x=i,this._renderChar(t,e,r,k,C,x,n)),C="",p=b,i+=f*S,S=0);e.restore()}_applyPatternGradientTransformText(t){const e=this.width+this.strokeWidth,s=this.height+this.strokeWidth,i=Rs({width:e,height:s}),n=i.getContext("2d");return i.width=e,i.height=s,n.beginPath(),n.moveTo(0,0),n.lineTo(e,0),n.lineTo(e,s),n.lineTo(0,s),n.closePath(),n.translate(e/2,s/2),n.fillStyle=t.toLive(n),this._applyPatternGradientTransform(n,t),n.fill(),n.createPattern(i,"no-repeat")}handleFiller(t,e,s){let i,n;return bs(s)?s.gradientUnits==="percentage"||s.gradientTransform||s.patternTransform?(i=-this.width/2,n=-this.height/2,t.translate(i,n),t[e]=this._applyPatternGradientTransformText(s),{offsetX:i,offsetY:n}):(t[e]=s.toLive(t),this._applyPatternGradientTransform(t,s)):(t[e]=s,{offsetX:0,offsetY:0})}_setStrokeStyles(t,e){let{stroke:s,strokeWidth:i}=e;return t.lineWidth=i,t.lineCap=this.strokeLineCap,t.lineDashOffset=this.strokeDashOffset,t.lineJoin=this.strokeLineJoin,t.miterLimit=this.strokeMiterLimit,this.handleFiller(t,"strokeStyle",s)}_setFillStyles(t,e){let{fill:s}=e;return this.handleFiller(t,"fillStyle",s)}_renderChar(t,e,s,i,n,r,o){const h=this._getStyleDeclaration(s,i),c=this.getCompleteStyleDeclaration(s,i),u=t==="fillText"&&c.fill,d=t==="strokeText"&&c.stroke&&c.strokeWidth;if(d||u){if(e.save(),e.font=this._getFontDeclaration(c),h.textBackgroundColor&&this._removeShadow(e),h.deltaY&&(o+=h.deltaY),u){const f=this._setFillStyles(e,c);e.fillText(n,r-f.offsetX,o-f.offsetY)}if(d){const f=this._setStrokeStyles(e,c);e.strokeText(n,r-f.offsetX,o-f.offsetY)}e.restore()}}setSuperscript(t,e){this._setScript(t,e,this.superscript)}setSubscript(t,e){this._setScript(t,e,this.subscript)}_setScript(t,e,s){const i=this.get2DCursorLocation(t,!0),n=this.getValueOfPropertyAt(i.lineIndex,i.charIndex,"fontSize"),r=this.getValueOfPropertyAt(i.lineIndex,i.charIndex,"deltaY"),o={fontSize:n*s.size,deltaY:r+n*s.baseline};this.setSelectionStyles(o,t,e)}_getLineLeftOffset(t){const e=this.getLineWidth(t),s=this.width-e,i=this.textAlign,n=this.direction,r=this.isEndOfWrapping(t);let o=0;return i===hi||i===jh&&!r||i===Nh&&!r||i===yu&&!r?0:(i===Q&&(o=s/2),i===It&&(o=s),i===jh&&(o=s/2),i===Nh&&(o=s),n==="rtl"&&(i===It||i===hi||i===Nh?o=0:i===dt||i===yu?o=-s:i!==Q&&i!==jh||(o=-s/2)),o)}_clearCache(){this._forceClearCache=!1,this.__lineWidths=[],this.__lineHeights=[],this.__charBounds=[]}getLineWidth(t){if(this.__lineWidths[t]!==void 0)return this.__lineWidths[t];const{width:e}=this.measureLine(t);return this.__lineWidths[t]=e,e}_getWidthOfCharSpacing(){return this.charSpacing!==0?this.fontSize*this.charSpacing/1e3:0}getValueOfPropertyAt(t,e,s){var i;return(i=this._getStyleDeclaration(t,e)[s])!==null&&i!==void 0?i:this[s]}_renderTextDecoration(t,e){if(!this[e]&&!this.styleHas(e))return;let s=this._getTopOffset();const i=this._getLeftOffset(),n=this.path,r=this._getWidthOfCharSpacing(),o=this.offsets[e];for(let h=0,c=this._textLines.length;h<c;h++){const u=this.getHeightOfLine(h);if(!this[e]&&!this.styleHas(e,h)){s+=u;continue}const d=this._textLines[h],f=u/this.lineHeight,g=this._getLineLeftOffset(h);let p,b,_=0,v=0,x=this.getValueOfPropertyAt(h,0,e),C=this.getValueOfPropertyAt(h,0,zt);const S=s+f*(1-this._fontSizeFraction);let k=this.getHeightOfChar(h,0),M=this.getValueOfPropertyAt(h,0,"deltaY");for(let P=0,O=d.length;P<O;P++){const L=this.__charBounds[h][P];p=this.getValueOfPropertyAt(h,P,e),b=this.getValueOfPropertyAt(h,P,zt);const R=this.getHeightOfChar(h,P),U=this.getValueOfPropertyAt(h,P,"deltaY");if(n&&p&&b)t.save(),t.fillStyle=C,t.translate(L.renderLeft,L.renderTop),t.rotate(L.angle),t.fillRect(-L.kernedWidth/2,o*R+U,L.kernedWidth,this.fontSize/15),t.restore();else if((p!==x||b!==C||R!==k||U!==M)&&v>0){let z=i+g+_;this.direction==="rtl"&&(z=this.width-z-v),x&&C&&(t.fillStyle=C,t.fillRect(z,S+o*k+M,v,this.fontSize/15)),_=L.left,v=L.width,x=p,C=b,k=R,M=U}else v+=L.kernedWidth}let E=i+g+_;this.direction==="rtl"&&(E=this.width-E-v),t.fillStyle=b,p&&b&&t.fillRect(E,S+o*k+M,v-r,this.fontSize/15),s+=u}this._removeShadow(t)}_getFontDeclaration(){let{fontFamily:t=this.fontFamily,fontStyle:e=this.fontStyle,fontWeight:s=this.fontWeight,fontSize:i=this.fontSize}=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},n=arguments.length>1?arguments[1]:void 0;const r=t.includes("'")||t.includes('"')||t.includes(",")||me.genericFonts.includes(t.toLowerCase())?t:'"'.concat(t,'"');return[e,s,"".concat(n?this.CACHE_FONT_SIZE:i,"px"),r].join(" ")}render(t){this.visible&&(this.canvas&&this.canvas.skipOffscreen&&!this.group&&!this.isOnScreen()||(this._forceClearCache&&this.initDimensions(),super.render(t)))}graphemeSplit(t){return au(t)}_splitTextIntoLines(t){const e=t.split(this._reNewline),s=new Array(e.length),i=[`
|
|
54
|
+
`];let n=[];for(let r=0;r<e.length;r++)s[r]=this.graphemeSplit(e[r]),n=n.concat(s[r],i);return n.pop(),{_unwrappedLines:s,lines:e,graphemeText:n,graphemeLines:s}}toObject(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:[];return T(T({},super.toObject([...R0,...t])),{},{styles:qm(this.styles,this.text)},this.path?{path:this.path.toObject()}:{})}set(t,e){const{textLayoutProperties:s}=this.constructor;super.set(t,e);let i=!1,n=!1;if(typeof t=="object")for(const r in t)r==="path"&&this.setPathInfo(),i=i||s.includes(r),n=n||r==="path";else i=s.includes(t),n=t==="path";return n&&this.setPathInfo(),i&&this.initialized&&(this.initDimensions(),this.setCoords()),this}complexity(){return 1}static async fromElement(t,e,s){const i=Ni(t,me.ATTRIBUTE_NAMES,s),n=T(T({},e),i),{textAnchor:r=dt,textDecoration:o="",dx:h=0,dy:c=0,top:u=0,left:d=0,fontSize:f=af,strokeWidth:g=1}=n,p=Ct(n,ww),b=new this((t.textContent||"").replace(/^\s+|\s+$|\n+/g,"").replace(/\s+/g," "),T({left:d+h,top:u+c,underline:o.includes("underline"),overline:o.includes("overline"),linethrough:o.includes("line-through"),strokeWidth:0,fontSize:f},p)),_=b.getScaledHeight()/b.height,v=((b.height+b.strokeWidth)*b.lineHeight-b.height)*_,x=b.getScaledHeight()+v;let C=0;return r===Q&&(C=b.getScaledWidth()/2),r===It&&(C=b.getScaledWidth()),b.set({left:b.left-C,top:b.top-(x-b.fontSize*(.07+b._fontSizeFraction))/b.lineHeight,strokeWidth:g}),b}static fromObject(t){return this._fromObject(T(T({},t),{},{styles:Km(t.styles||{},t.text)}),{extraParam:"text"})}}A(me,"textLayoutProperties",O0),A(me,"cacheProperties",[...Fi,...R0]),A(me,"ownDefaults",yw),A(me,"type","Text"),A(me,"genericFonts",["serif","sans-serif","monospace","cursive","fantasy","system-ui","ui-serif","ui-sans-serif","ui-monospace","ui-rounded","math","emoji","fangsong"]),A(me,"ATTRIBUTE_NAMES",Mn.concat("x","y","dx","dy","font-family","font-style","font-weight","font-size","letter-spacing","text-decoration","text-anchor")),Vm(me,[class extends Sm{_toSVG(){const a=this._getSVGLeftTopOffsets(),t=this._getSVGTextAndBg(a.textTop,a.textLeft);return this._wrapSVGTextAndBg(t)}toSVG(a){return this._createBaseSVGMarkup(this._toSVG(),{reviver:a,noStyle:!0,withShadow:!0})}_getSVGLeftTopOffsets(){return{textLeft:-this.width/2,textTop:-this.height/2,lineTop:this.getHeightOfLine(0)}}_wrapSVGTextAndBg(a){let{textBgRects:t,textSpans:e}=a;const s=this.getSvgTextDecoration(this);return[t.join(""),' <text xml:space="preserve" ',this.fontFamily?'font-family="'.concat(this.fontFamily.replace(_w,"'"),'" '):"",this.fontSize?'font-size="'.concat(this.fontSize,'" '):"",this.fontStyle?'font-style="'.concat(this.fontStyle,'" '):"",this.fontWeight?'font-weight="'.concat(this.fontWeight,'" '):"",s?'text-decoration="'.concat(s,'" '):"",this.direction==="rtl"?'direction="'.concat(this.direction,'" '):"",'style="',this.getSvgStyles(!0),'"',this.addPaintOrder()," >",e.join(""),`</text>
|
|
55
|
+
`]}_getSVGTextAndBg(a,t){const e=[],s=[];let i,n=a;this.backgroundColor&&s.push(...qf(this.backgroundColor,-this.width/2,-this.height/2,this.width,this.height));for(let r=0,o=this._textLines.length;r<o;r++)i=this._getLineLeftOffset(r),this.direction==="rtl"&&(i+=this.width),(this.textBackgroundColor||this.styleHas("textBackgroundColor",r))&&this._setSVGTextLineBg(s,r,t+i,n),this._setSVGTextLineText(e,r,t+i,n),n+=this.getHeightOfLine(r);return{textSpans:e,textBgRects:s}}_createTextCharSpan(a,t,e,s){const i=this.getSvgSpanStyles(t,a!==a.trim()||!!a.match(vw)),n=i?'style="'.concat(i,'"'):"",r=t.deltaY,o=r?' dy="'.concat(At(r,ht.NUM_FRACTION_DIGITS),'" '):"";return'<tspan x="'.concat(At(e,ht.NUM_FRACTION_DIGITS),'" y="').concat(At(s,ht.NUM_FRACTION_DIGITS),'" ').concat(o).concat(n,">").concat($m(a),"</tspan>")}_setSVGTextLineText(a,t,e,s){const i=this.getHeightOfLine(t),n=this.textAlign.includes(hi),r=this._textLines[t];let o,h,c,u,d,f="",g=0;s+=i*(1-this._fontSizeFraction)/this.lineHeight;for(let p=0,b=r.length-1;p<=b;p++)d=p===b||this.charSpacing,f+=r[p],c=this.__charBounds[t][p],g===0?(e+=c.kernedWidth-c.width,g+=c.width):g+=c.kernedWidth,n&&!d&&this._reSpaceAndTab.test(r[p])&&(d=!0),d||(o=o||this.getCompleteStyleDeclaration(t,p),h=this.getCompleteStyleDeclaration(t,p+1),d=hu(o,h,!0)),d&&(u=this._getStyleDeclaration(t,p),a.push(this._createTextCharSpan(f,u,e,s)),f="",o=h,this.direction==="rtl"?e-=g:e+=g,g=0)}_setSVGTextLineBg(a,t,e,s){const i=this._textLines[t],n=this.getHeightOfLine(t)/this.lineHeight;let r,o=0,h=0,c=this.getValueOfPropertyAt(t,0,"textBackgroundColor");for(let u=0;u<i.length;u++){const{left:d,width:f,kernedWidth:g}=this.__charBounds[t][u];r=this.getValueOfPropertyAt(t,u,"textBackgroundColor"),r!==c?(c&&a.push(...qf(c,e+h,s,o,n)),h=d,o=f,c=r):o+=g}r&&a.push(...qf(c,e+h,s,o,n))}_getSVGLineTopOffset(a){let t,e=0;for(t=0;t<a;t++)e+=this.getHeightOfLine(t);const s=this.getHeightOfLine(t);return{lineTop:e,offset:(this._fontSizeMult-this._fontSizeFraction)*s/(this.lineHeight*this._fontSizeMult)}}getSvgStyles(a){return"".concat(super.getSvgStyles(a)," white-space: pre;")}getSvgSpanStyles(a,t){const{fontFamily:e,strokeWidth:s,stroke:i,fill:n,fontSize:r,fontStyle:o,fontWeight:h,deltaY:c}=a,u=this.getSvgTextDecoration(a);return[i?Mh(Pe,i):"",s?"stroke-width: ".concat(s,"; "):"",e?"font-family: ".concat(e.includes("'")||e.includes('"')?e:"'".concat(e,"'"),"; "):"",r?"font-size: ".concat(r,"px; "):"",o?"font-style: ".concat(o,"; "):"",h?"font-weight: ".concat(h,"; "):"",u&&"text-decoration: ".concat(u,"; "),n?Mh(zt,n):"",c?"baseline-shift: ".concat(-c,"; "):"",t?"white-space: pre; ":""].join("")}getSvgTextDecoration(a){return["overline","underline","line-through"].filter(t=>a[t.replace("-","")]).join(" ")}}]),N.setClass(me),N.setSVGClass(me);class xw{constructor(t){A(this,"target",void 0),A(this,"__mouseDownInPlace",!1),A(this,"__dragStartFired",!1),A(this,"__isDraggingOver",!1),A(this,"__dragStartSelection",void 0),A(this,"__dragImageDisposer",void 0),A(this,"_dispose",void 0),this.target=t;const e=[this.target.on("dragenter",this.dragEnterHandler.bind(this)),this.target.on("dragover",this.dragOverHandler.bind(this)),this.target.on("dragleave",this.dragLeaveHandler.bind(this)),this.target.on("dragend",this.dragEndHandler.bind(this)),this.target.on("drop",this.dropHandler.bind(this))];this._dispose=()=>{e.forEach(s=>s()),this._dispose=void 0}}isPointerOverSelection(t){const e=this.target,s=e.getSelectionStartFromPointer(t);return e.isEditing&&s>=e.selectionStart&&s<=e.selectionEnd&&e.selectionStart<e.selectionEnd}start(t){return this.__mouseDownInPlace=this.isPointerOverSelection(t)}isActive(){return this.__mouseDownInPlace}end(t){const e=this.isActive();return e&&!this.__dragStartFired&&(this.target.setCursorByClick(t),this.target.initDelayedCursor(!0)),this.__mouseDownInPlace=!1,this.__dragStartFired=!1,this.__isDraggingOver=!1,e}getDragStartSelection(){return this.__dragStartSelection}setDragImage(t,e){var s;let{selectionStart:i,selectionEnd:n}=e;const r=this.target,o=r.canvas,h=new D(r.flipX?-1:1,r.flipY?-1:1),c=r._getCursorBoundaries(i),u=new D(c.left+c.leftOffset,c.top+c.topOffset).multiply(h).transform(r.calcTransformMatrix()),d=o.getScenePoint(t).subtract(u),f=r.getCanvasRetinaScaling(),g=r.getBoundingRect(),p=u.subtract(new D(g.left,g.top)),b=o.viewportTransform,_=p.add(d).transform(b,!0),v=r.backgroundColor,x=jf(r.styles);r.backgroundColor="";const C={stroke:"transparent",fill:"transparent",textBackgroundColor:"transparent"};r.setSelectionStyles(C,0,i),r.setSelectionStyles(C,n,r.text.length),r.dirty=!0;const S=r.toCanvasElement({enableRetinaScaling:o.enableRetinaScaling,viewportTransform:!0});r.backgroundColor=v,r.styles=x,r.dirty=!0,gu(S,{position:"fixed",left:"".concat(-S.width,"px"),border:ke,width:"".concat(S.width/f,"px"),height:"".concat(S.height/f,"px")}),this.__dragImageDisposer&&this.__dragImageDisposer(),this.__dragImageDisposer=()=>{S.remove()},Ls(t.target||this.target.hiddenTextarea).body.appendChild(S),(s=t.dataTransfer)===null||s===void 0||s.setDragImage(S,_.x,_.y)}onDragStart(t){this.__dragStartFired=!0;const e=this.target,s=this.isActive();if(s&&t.dataTransfer){const i=this.__dragStartSelection={selectionStart:e.selectionStart,selectionEnd:e.selectionEnd},n=e._text.slice(i.selectionStart,i.selectionEnd).join(""),r=T({text:e.text,value:n},i);t.dataTransfer.setData("text/plain",n),t.dataTransfer.setData("application/fabric",JSON.stringify({value:n,styles:e.getSelectionStyles(i.selectionStart,i.selectionEnd,!0)})),t.dataTransfer.effectAllowed="copyMove",this.setDragImage(t,r)}return e.abortCursorAnimation(),s}canDrop(t){if(this.target.editable&&!this.target.getActiveControl()&&!t.defaultPrevented){if(this.isActive()&&this.__dragStartSelection){const e=this.target.getSelectionStartFromPointer(t),s=this.__dragStartSelection;return e<s.selectionStart||e>s.selectionEnd}return!0}return!1}targetCanDrop(t){return this.target.canDrop(t)}dragEnterHandler(t){let{e}=t;const s=this.targetCanDrop(e);!this.__isDraggingOver&&s&&(this.__isDraggingOver=!0)}dragOverHandler(t){const{e}=t,s=this.targetCanDrop(e);!this.__isDraggingOver&&s?this.__isDraggingOver=!0:this.__isDraggingOver&&!s&&(this.__isDraggingOver=!1),this.__isDraggingOver&&(e.preventDefault(),t.canDrop=!0,t.dropTarget=this.target)}dragLeaveHandler(){(this.__isDraggingOver||this.isActive())&&(this.__isDraggingOver=!1)}dropHandler(t){var e;const{e:s}=t,i=s.defaultPrevented;this.__isDraggingOver=!1,s.preventDefault();let n=(e=s.dataTransfer)===null||e===void 0?void 0:e.getData("text/plain");if(n&&!i){const r=this.target,o=r.canvas;let h=r.getSelectionStartFromPointer(s);const{styles:c}=s.dataTransfer.types.includes("application/fabric")?JSON.parse(s.dataTransfer.getData("application/fabric")):{},u=n[Math.max(0,n.length-1)],d=0;if(this.__dragStartSelection){const f=this.__dragStartSelection.selectionStart,g=this.__dragStartSelection.selectionEnd;h>f&&h<=g?h=f:h>g&&(h-=g-f),r.removeChars(f,g),delete this.__dragStartSelection}r._reNewline.test(u)&&(r._reNewline.test(r._text[h])||h===r._text.length)&&(n=n.trimEnd()),t.didDrop=!0,t.dropTarget=r,r.insertChars(n,c,h),o.setActiveObject(r),r.enterEditing(s),r.selectionStart=Math.min(h+d,r._text.length),r.selectionEnd=Math.min(r.selectionStart+n.length,r._text.length),r.hiddenTextarea.value=r.text,r._updateTextarea(),r.hiddenTextarea.focus(),r.fire(zc,{index:h+d,action:"drop"}),o.fire("text:changed",{target:r}),o.contextTopDirty=!0,o.requestRenderAll()}}dragEndHandler(t){let{e}=t;if(this.isActive()&&this.__dragStartFired&&this.__dragStartSelection){var s;const i=this.target,n=this.target.canvas,{selectionStart:r,selectionEnd:o}=this.__dragStartSelection,h=((s=e.dataTransfer)===null||s===void 0?void 0:s.dropEffect)||ke;h===ke?(i.selectionStart=r,i.selectionEnd=o,i._updateTextarea(),i.hiddenTextarea.focus()):(i.clearContextTop(),h==="move"&&(i.removeChars(r,o),i.selectionStart=i.selectionEnd=r,i.hiddenTextarea&&(i.hiddenTextarea.value=i.text),i._updateTextarea(),i.fire(zc,{index:r,action:"dragend"}),n.fire("text:changed",{target:i}),n.requestRenderAll()),i.exitEditing())}this.__dragImageDisposer&&this.__dragImageDisposer(),delete this.__dragImageDisposer,delete this.__dragStartSelection,this.__isDraggingOver=!1}dispose(){this._dispose&&this._dispose()}}const F0=/[ \n\.,;!\?\-]/;class Sw extends me{constructor(){super(...arguments),A(this,"_currentCursorOpacity",1)}initBehavior(){this._tick=this._tick.bind(this),this._onTickComplete=this._onTickComplete.bind(this),this.updateSelectionOnMouseMove=this.updateSelectionOnMouseMove.bind(this)}onDeselect(t){return this.isEditing&&this.exitEditing(),this.selected=!1,super.onDeselect(t)}_animateCursor(t){let{toValue:e,duration:s,delay:i,onComplete:n}=t;return Ff({startValue:this._currentCursorOpacity,endValue:e,duration:s,delay:i,onComplete:n,abort:()=>!this.canvas||this.selectionStart!==this.selectionEnd,onChange:r=>{this._currentCursorOpacity=r,this.renderCursorOrSelection()}})}_tick(t){this._currentTickState=this._animateCursor({toValue:0,duration:this.cursorDuration/2,delay:Math.max(t||0,100),onComplete:this._onTickComplete})}_onTickComplete(){var t;(t=this._currentTickCompleteState)===null||t===void 0||t.abort(),this._currentTickCompleteState=this._animateCursor({toValue:1,duration:this.cursorDuration,onComplete:this._tick})}initDelayedCursor(t){this.abortCursorAnimation(),this._tick(t?0:this.cursorDelay)}abortCursorAnimation(){let t=!1;[this._currentTickState,this._currentTickCompleteState].forEach(e=>{e&&!e.isDone()&&(t=!0,e.abort())}),this._currentCursorOpacity=1,t&&this.clearContextTop()}restartCursorIfNeeded(){[this._currentTickState,this._currentTickCompleteState].some(t=>!t||t.isDone())&&this.initDelayedCursor()}selectAll(){return this.selectionStart=0,this.selectionEnd=this._text.length,this._fireSelectionChanged(),this._updateTextarea(),this}getSelectedText(){return this._text.slice(this.selectionStart,this.selectionEnd).join("")}findWordBoundaryLeft(t){let e=0,s=t-1;if(this._reSpace.test(this._text[s]))for(;this._reSpace.test(this._text[s]);)e++,s--;for(;/\S/.test(this._text[s])&&s>-1;)e++,s--;return t-e}findWordBoundaryRight(t){let e=0,s=t;if(this._reSpace.test(this._text[s]))for(;this._reSpace.test(this._text[s]);)e++,s++;for(;/\S/.test(this._text[s])&&s<this._text.length;)e++,s++;return t+e}findLineBoundaryLeft(t){let e=0,s=t-1;for(;!/\n/.test(this._text[s])&&s>-1;)e++,s--;return t-e}findLineBoundaryRight(t){let e=0,s=t;for(;!/\n/.test(this._text[s])&&s<this._text.length;)e++,s++;return t+e}searchWordBoundary(t,e){const s=this._text;let i=t>0&&this._reSpace.test(s[t])&&(e===-1||!lf.test(s[t-1]))?t-1:t,n=s[i];for(;i>0&&i<s.length&&!F0.test(n);)i+=e,n=s[i];return e===-1&&F0.test(n)&&i++,i}selectWord(t){t=t||this.selectionStart;const e=this.searchWordBoundary(t,-1),s=Math.max(e,this.searchWordBoundary(t,1));this.selectionStart=e,this.selectionEnd=s,this._fireSelectionChanged(),this._updateTextarea(),this.renderCursorOrSelection()}selectLine(t){t=t||this.selectionStart;const e=this.findLineBoundaryLeft(t),s=this.findLineBoundaryRight(t);return this.selectionStart=e,this.selectionEnd=s,this._fireSelectionChanged(),this._updateTextarea(),this}enterEditing(t){!this.isEditing&&this.editable&&(this.enterEditingImpl(),this.fire("editing:entered",t?{e:t}:void 0),this._fireSelectionChanged(),this.canvas&&(this.canvas.fire("text:editing:entered",{target:this,e:t}),this.canvas.requestRenderAll()))}enterEditingImpl(){this.canvas&&(this.canvas.calcOffset(),this.canvas.textEditingManager.exitTextEditing()),this.isEditing=!0,this.initHiddenTextarea(),this.hiddenTextarea.focus(),this.hiddenTextarea.value=this.text,this._updateTextarea(),this._saveEditingProps(),this._setEditingProps(),this._textBeforeEdit=this.text,this._tick()}updateSelectionOnMouseMove(t){if(this.getActiveControl())return;const e=this.hiddenTextarea;Ls(e).activeElement!==e&&e.focus();const s=this.getSelectionStartFromPointer(t),i=this.selectionStart,n=this.selectionEnd;(s===this.__selectionStartOnMouseDown&&i!==n||i!==s&&n!==s)&&(s>this.__selectionStartOnMouseDown?(this.selectionStart=this.__selectionStartOnMouseDown,this.selectionEnd=s):(this.selectionStart=s,this.selectionEnd=this.__selectionStartOnMouseDown),this.selectionStart===i&&this.selectionEnd===n||(this._fireSelectionChanged(),this._updateTextarea(),this.renderCursorOrSelection()))}_setEditingProps(){this.hoverCursor="text",this.canvas&&(this.canvas.defaultCursor=this.canvas.moveCursor="text"),this.borderColor=this.editingBorderColor,this.hasControls=this.selectable=!1,this.lockMovementX=this.lockMovementY=!0}fromStringToGraphemeSelection(t,e,s){const i=s.slice(0,t),n=this.graphemeSplit(i).length;if(t===e)return{selectionStart:n,selectionEnd:n};const r=s.slice(t,e);return{selectionStart:n,selectionEnd:n+this.graphemeSplit(r).length}}fromGraphemeToStringSelection(t,e,s){const i=s.slice(0,t).join("").length;return t===e?{selectionStart:i,selectionEnd:i}:{selectionStart:i,selectionEnd:i+s.slice(t,e).join("").length}}_updateTextarea(){if(this.cursorOffsetCache={},this.hiddenTextarea){if(!this.inCompositionMode){const t=this.fromGraphemeToStringSelection(this.selectionStart,this.selectionEnd,this._text);this.hiddenTextarea.selectionStart=t.selectionStart,this.hiddenTextarea.selectionEnd=t.selectionEnd}this.updateTextareaPosition()}}updateFromTextArea(){if(!this.hiddenTextarea)return;this.cursorOffsetCache={};const t=this.hiddenTextarea;this.text=t.value,this.set("dirty",!0),this.initDimensions(),this.setCoords();const e=this.fromStringToGraphemeSelection(t.selectionStart,t.selectionEnd,t.value);this.selectionEnd=this.selectionStart=e.selectionEnd,this.inCompositionMode||(this.selectionStart=e.selectionStart),this.updateTextareaPosition()}updateTextareaPosition(){if(this.selectionStart===this.selectionEnd){const t=this._calcTextareaPosition();this.hiddenTextarea.style.left=t.left,this.hiddenTextarea.style.top=t.top}}_calcTextareaPosition(){if(!this.canvas)return{left:"1px",top:"1px"};const t=this.inCompositionMode?this.compositionStart:this.selectionStart,e=this._getCursorBoundaries(t),s=this.get2DCursorLocation(t),i=s.lineIndex,n=s.charIndex,r=this.getValueOfPropertyAt(i,n,"fontSize")*this.lineHeight,o=e.leftOffset,h=this.getCanvasRetinaScaling(),c=this.canvas.upperCanvasEl,u=c.width/h,d=c.height/h,f=u-r,g=d-r,p=new D(e.left+o,e.top+e.topOffset+r).transform(this.calcTransformMatrix()).transform(this.canvas.viewportTransform).multiply(new D(c.clientWidth/u,c.clientHeight/d));return p.x<0&&(p.x=0),p.x>f&&(p.x=f),p.y<0&&(p.y=0),p.y>g&&(p.y=g),p.x+=this.canvas._offset.left,p.y+=this.canvas._offset.top,{left:"".concat(p.x,"px"),top:"".concat(p.y,"px"),fontSize:"".concat(r,"px"),charHeight:r}}_saveEditingProps(){this._savedProps={hasControls:this.hasControls,borderColor:this.borderColor,lockMovementX:this.lockMovementX,lockMovementY:this.lockMovementY,hoverCursor:this.hoverCursor,selectable:this.selectable,defaultCursor:this.canvas&&this.canvas.defaultCursor,moveCursor:this.canvas&&this.canvas.moveCursor}}_restoreEditingProps(){this._savedProps&&(this.hoverCursor=this._savedProps.hoverCursor,this.hasControls=this._savedProps.hasControls,this.borderColor=this._savedProps.borderColor,this.selectable=this._savedProps.selectable,this.lockMovementX=this._savedProps.lockMovementX,this.lockMovementY=this._savedProps.lockMovementY,this.canvas&&(this.canvas.defaultCursor=this._savedProps.defaultCursor||this.canvas.defaultCursor,this.canvas.moveCursor=this._savedProps.moveCursor||this.canvas.moveCursor),delete this._savedProps)}_exitEditing(){const t=this.hiddenTextarea;this.selected=!1,this.isEditing=!1,t&&(t.blur&&t.blur(),t.parentNode&&t.parentNode.removeChild(t)),this.hiddenTextarea=null,this.abortCursorAnimation(),this.selectionStart!==this.selectionEnd&&this.clearContextTop()}exitEditingImpl(){this._exitEditing(),this.selectionEnd=this.selectionStart,this._restoreEditingProps(),this._forceClearCache&&(this.initDimensions(),this.setCoords())}exitEditing(){const t=this._textBeforeEdit!==this.text;return this.exitEditingImpl(),this.fire("editing:exited"),t&&this.fire(Xc),this.canvas&&(this.canvas.fire("text:editing:exited",{target:this}),t&&this.canvas.fire("object:modified",{target:this})),this}_removeExtraneousStyles(){for(const t in this.styles)this._textLines[t]||delete this.styles[t]}removeStyleFromTo(t,e){const{lineIndex:s,charIndex:i}=this.get2DCursorLocation(t,!0),{lineIndex:n,charIndex:r}=this.get2DCursorLocation(e,!0);if(s!==n){if(this.styles[s])for(let o=i;o<this._unwrappedTextLines[s].length;o++)delete this.styles[s][o];if(this.styles[n])for(let o=r;o<this._unwrappedTextLines[n].length;o++){const h=this.styles[n][o];h&&(this.styles[s]||(this.styles[s]={}),this.styles[s][i+o-r]=h)}for(let o=s+1;o<=n;o++)delete this.styles[o];this.shiftLineStyles(n,s-n)}else if(this.styles[s]){const o=this.styles[s],h=r-i;for(let c=i;c<r;c++)delete o[c];for(const c in this.styles[s]){const u=parseInt(c,10);u>=r&&(o[u-h]=o[c],delete o[c])}}}shiftLineStyles(t,e){const s=Object.assign({},this.styles);for(const i in this.styles){const n=parseInt(i,10);n>t&&(this.styles[n+e]=s[n],s[n-e]||delete this.styles[n])}}insertNewlineStyleObject(t,e,s,i){const n={},r=this._unwrappedTextLines[t].length,o=r===e;let h=!1;s||(s=1),this.shiftLineStyles(t,s);const c=this.styles[t]?this.styles[t][e===0?e:e-1]:void 0;for(const d in this.styles[t]){const f=parseInt(d,10);f>=e&&(h=!0,n[f-e]=this.styles[t][d],o&&e===0||delete this.styles[t][d])}let u=!1;for(h&&!o&&(this.styles[t+s]=n,u=!0),(u||r>e)&&s--;s>0;)i&&i[s-1]?this.styles[t+s]={0:T({},i[s-1])}:c?this.styles[t+s]={0:T({},c)}:delete this.styles[t+s],s--;this._forceClearCache=!0}insertCharStyleObject(t,e,s,i){this.styles||(this.styles={});const n=this.styles[t],r=n?T({},n):{};s||(s=1);for(const h in r){const c=parseInt(h,10);c>=e&&(n[c+s]=r[c],r[c-s]||delete n[c])}if(this._forceClearCache=!0,i){for(;s--;)Object.keys(i[s]).length&&(this.styles[t]||(this.styles[t]={}),this.styles[t][e+s]=T({},i[s]));return}if(!n)return;const o=n[e?e-1:1];for(;o&&s--;)this.styles[t][e+s]=T({},o)}insertNewStyleBlock(t,e,s){const i=this.get2DCursorLocation(e,!0),n=[0];let r,o=0;for(let h=0;h<t.length;h++)t[h]===`
|
|
56
|
+
`?(o++,n[o]=0):n[o]++;for(n[0]>0&&(this.insertCharStyleObject(i.lineIndex,i.charIndex,n[0],s),s=s&&s.slice(n[0]+1)),o&&this.insertNewlineStyleObject(i.lineIndex,i.charIndex+n[0],o),r=1;r<o;r++)n[r]>0?this.insertCharStyleObject(i.lineIndex+r,0,n[r],s):s&&this.styles[i.lineIndex+r]&&s[0]&&(this.styles[i.lineIndex+r][0]=s[0]),s=s&&s.slice(n[r]+1);n[r]>0&&this.insertCharStyleObject(i.lineIndex+r,0,n[r],s)}removeChars(t){let e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:t+1;this.removeStyleFromTo(t,e),this._text.splice(t,e-t),this.text=this._text.join(""),this.set("dirty",!0),this.initDimensions(),this.setCoords(),this._removeExtraneousStyles()}insertChars(t,e,s){let i=arguments.length>3&&arguments[3]!==void 0?arguments[3]:s;i>s&&this.removeStyleFromTo(s,i);const n=this.graphemeSplit(t);this.insertNewStyleBlock(n,s,e),this._text=[...this._text.slice(0,s),...n,...this._text.slice(i)],this.text=this._text.join(""),this.set("dirty",!0),this.initDimensions(),this.setCoords(),this._removeExtraneousStyles()}setSelectionStartEndWithShift(t,e,s){s<=t?(e===t?this._selectionDirection=dt:this._selectionDirection===It&&(this._selectionDirection=dt,this.selectionEnd=t),this.selectionStart=s):s>t&&s<e?this._selectionDirection===It?this.selectionEnd=s:this.selectionStart=s:(e===t?this._selectionDirection=It:this._selectionDirection===dt&&(this._selectionDirection=It,this.selectionStart=e),this.selectionEnd=s)}}class Cw extends Sw{initHiddenTextarea(){const t=this.canvas&&Ls(this.canvas.getElement())||Vo(),e=t.createElement("textarea");Object.entries({autocapitalize:"off",autocorrect:"off",autocomplete:"off",spellcheck:"false","data-fabric":"textarea",wrap:"off"}).map(r=>{let[o,h]=r;return e.setAttribute(o,h)});const{top:s,left:i,fontSize:n}=this._calcTextareaPosition();e.style.cssText="position: absolute; top: ".concat(s,"; left: ").concat(i,"; z-index: -999; opacity: 0; width: 1px; height: 1px; font-size: 1px; padding-top: ").concat(n,";"),(this.hiddenTextareaContainer||t.body).appendChild(e),Object.entries({blur:"blur",keydown:"onKeyDown",keyup:"onKeyUp",input:"onInput",copy:"copy",cut:"copy",paste:"paste",compositionstart:"onCompositionStart",compositionupdate:"onCompositionUpdate",compositionend:"onCompositionEnd"}).map(r=>{let[o,h]=r;return e.addEventListener(o,this[h].bind(this))}),this.hiddenTextarea=e}blur(){this.abortCursorAnimation()}onKeyDown(t){if(!this.isEditing)return;const e=this.direction==="rtl"?this.keysMapRtl:this.keysMap;if(t.keyCode in e)this[e[t.keyCode]](t);else{if(!(t.keyCode in this.ctrlKeysMapDown)||!t.ctrlKey&&!t.metaKey)return;this[this.ctrlKeysMapDown[t.keyCode]](t)}t.stopImmediatePropagation(),t.preventDefault(),t.keyCode>=33&&t.keyCode<=40?(this.inCompositionMode=!1,this.clearContextTop(),this.renderCursorOrSelection()):this.canvas&&this.canvas.requestRenderAll()}onKeyUp(t){!this.isEditing||this._copyDone||this.inCompositionMode?this._copyDone=!1:t.keyCode in this.ctrlKeysMapUp&&(t.ctrlKey||t.metaKey)&&(this[this.ctrlKeysMapUp[t.keyCode]](t),t.stopImmediatePropagation(),t.preventDefault(),this.canvas&&this.canvas.requestRenderAll())}onInput(t){const e=this.fromPaste;if(this.fromPaste=!1,t&&t.stopPropagation(),!this.isEditing)return;const s=()=>{this.updateFromTextArea(),this.fire(zc),this.canvas&&(this.canvas.fire("text:changed",{target:this}),this.canvas.requestRenderAll())};if(this.hiddenTextarea.value==="")return this.styles={},void s();const i=this._splitTextIntoLines(this.hiddenTextarea.value).graphemeText,n=this._text.length,r=i.length,o=this.selectionStart,h=this.selectionEnd,c=o!==h;let u,d,f,g,p=r-n;const b=this.fromStringToGraphemeSelection(this.hiddenTextarea.selectionStart,this.hiddenTextarea.selectionEnd,this.hiddenTextarea.value),_=o>b.selectionStart;c?(d=this._text.slice(o,h),p+=h-o):r<n&&(d=_?this._text.slice(h+p,h):this._text.slice(o,o-p));const v=i.slice(b.selectionEnd-p,b.selectionEnd);if(d&&d.length&&(v.length&&(u=this.getSelectionStyles(o,o+1,!1),u=v.map(()=>u[0])),c?(f=o,g=h):_?(f=h-d.length,g=h):(f=h,g=h+d.length),this.removeStyleFromTo(f,g)),v.length){const{copyPasteData:x}=ni();e&&v.join("")===x.copiedText&&!ht.disableStyleCopyPaste&&(u=x.copiedTextStyle),this.insertNewStyleBlock(v,o,u)}s()}onCompositionStart(){this.inCompositionMode=!0}onCompositionEnd(){this.inCompositionMode=!1}onCompositionUpdate(t){let{target:e}=t;const{selectionStart:s,selectionEnd:i}=e;this.compositionStart=s,this.compositionEnd=i,this.updateTextareaPosition()}copy(){if(this.selectionStart===this.selectionEnd)return;const{copyPasteData:t}=ni();t.copiedText=this.getSelectedText(),ht.disableStyleCopyPaste?t.copiedTextStyle=void 0:t.copiedTextStyle=this.getSelectionStyles(this.selectionStart,this.selectionEnd,!0),this._copyDone=!0}paste(){this.fromPaste=!0}_getWidthBeforeCursor(t,e){let s,i=this._getLineLeftOffset(t);return e>0&&(s=this.__charBounds[t][e-1],i+=s.left+s.width),i}getDownCursorOffset(t,e){const s=this._getSelectionForOffset(t,e),i=this.get2DCursorLocation(s),n=i.lineIndex;if(n===this._textLines.length-1||t.metaKey||t.keyCode===34)return this._text.length-s;const r=i.charIndex,o=this._getWidthBeforeCursor(n,r),h=this._getIndexOnLine(n+1,o);return this._textLines[n].slice(r).length+h+1+this.missingNewlineOffset(n)}_getSelectionForOffset(t,e){return t.shiftKey&&this.selectionStart!==this.selectionEnd&&e?this.selectionEnd:this.selectionStart}getUpCursorOffset(t,e){const s=this._getSelectionForOffset(t,e),i=this.get2DCursorLocation(s),n=i.lineIndex;if(n===0||t.metaKey||t.keyCode===33)return-s;const r=i.charIndex,o=this._getWidthBeforeCursor(n,r),h=this._getIndexOnLine(n-1,o),c=this._textLines[n].slice(0,r),u=this.missingNewlineOffset(n-1);return-this._textLines[n-1].length+h-c.length+(1-u)}_getIndexOnLine(t,e){const s=this._textLines[t];let i,n,r=this._getLineLeftOffset(t),o=0;for(let h=0,c=s.length;h<c;h++)if(i=this.__charBounds[t][h].width,r+=i,r>e){n=!0;const u=r-i,d=r,f=Math.abs(u-e);o=Math.abs(d-e)<f?h:h-1;break}return n||(o=s.length-1),o}moveCursorDown(t){this.selectionStart>=this._text.length&&this.selectionEnd>=this._text.length||this._moveCursorUpOrDown("Down",t)}moveCursorUp(t){this.selectionStart===0&&this.selectionEnd===0||this._moveCursorUpOrDown("Up",t)}_moveCursorUpOrDown(t,e){const s=this["get".concat(t,"CursorOffset")](e,this._selectionDirection===It);if(e.shiftKey?this.moveCursorWithShift(s):this.moveCursorWithoutShift(s),s!==0){const i=this.text.length;this.selectionStart=wr(0,this.selectionStart,i),this.selectionEnd=wr(0,this.selectionEnd,i),this.abortCursorAnimation(),this.initDelayedCursor(),this._fireSelectionChanged(),this._updateTextarea()}}moveCursorWithShift(t){const e=this._selectionDirection===dt?this.selectionStart+t:this.selectionEnd+t;return this.setSelectionStartEndWithShift(this.selectionStart,this.selectionEnd,e),t!==0}moveCursorWithoutShift(t){return t<0?(this.selectionStart+=t,this.selectionEnd=this.selectionStart):(this.selectionEnd+=t,this.selectionStart=this.selectionEnd),t!==0}moveCursorLeft(t){this.selectionStart===0&&this.selectionEnd===0||this._moveCursorLeftOrRight("Left",t)}_move(t,e,s){let i;if(t.altKey)i=this["findWordBoundary".concat(s)](this[e]);else{if(!t.metaKey&&t.keyCode!==35&&t.keyCode!==36)return this[e]+=s==="Left"?-1:1,!0;i=this["findLineBoundary".concat(s)](this[e])}return i!==void 0&&this[e]!==i&&(this[e]=i,!0)}_moveLeft(t,e){return this._move(t,e,"Left")}_moveRight(t,e){return this._move(t,e,"Right")}moveCursorLeftWithoutShift(t){let e=!0;return this._selectionDirection=dt,this.selectionEnd===this.selectionStart&&this.selectionStart!==0&&(e=this._moveLeft(t,"selectionStart")),this.selectionEnd=this.selectionStart,e}moveCursorLeftWithShift(t){return this._selectionDirection===It&&this.selectionStart!==this.selectionEnd?this._moveLeft(t,"selectionEnd"):this.selectionStart!==0?(this._selectionDirection=dt,this._moveLeft(t,"selectionStart")):void 0}moveCursorRight(t){this.selectionStart>=this._text.length&&this.selectionEnd>=this._text.length||this._moveCursorLeftOrRight("Right",t)}_moveCursorLeftOrRight(t,e){const s="moveCursor".concat(t).concat(e.shiftKey?"WithShift":"WithoutShift");this._currentCursorOpacity=1,this[s](e)&&(this.abortCursorAnimation(),this.initDelayedCursor(),this._fireSelectionChanged(),this._updateTextarea())}moveCursorRightWithShift(t){return this._selectionDirection===dt&&this.selectionStart!==this.selectionEnd?this._moveRight(t,"selectionStart"):this.selectionEnd!==this._text.length?(this._selectionDirection=It,this._moveRight(t,"selectionEnd")):void 0}moveCursorRightWithoutShift(t){let e=!0;return this._selectionDirection=It,this.selectionStart===this.selectionEnd?(e=this._moveRight(t,"selectionStart"),this.selectionEnd=this.selectionStart):this.selectionStart=this.selectionEnd,e}}const Qf=a=>!!a.button;class Aw extends Cw{constructor(){super(...arguments),A(this,"draggableTextDelegate",void 0)}initBehavior(){this.on("mousedown",this._mouseDownHandler),this.on("mousedown:before",this._mouseDownHandlerBefore),this.on("mouseup",this.mouseUpHandler),this.on("mousedblclick",this.doubleClickHandler),this.on("tripleclick",this.tripleClickHandler),this.__lastClickTime=+new Date,this.__lastLastClickTime=+new Date,this.__lastPointer={},this.on("mousedown",this.onMouseDown),this.draggableTextDelegate=new xw(this),super.initBehavior()}shouldStartDragging(){return this.draggableTextDelegate.isActive()}onDragStart(t){return this.draggableTextDelegate.onDragStart(t)}canDrop(t){return this.draggableTextDelegate.canDrop(t)}onMouseDown(t){if(!this.canvas)return;this.__newClickTime=+new Date;const e=t.pointer;this.isTripleClick(e)&&(this.fire("tripleclick",t),wf(t.e)),this.__lastLastClickTime=this.__lastClickTime,this.__lastClickTime=this.__newClickTime,this.__lastPointer=e,this.__lastSelected=this.selected&&!this.getActiveControl()}isTripleClick(t){return this.__newClickTime-this.__lastClickTime<500&&this.__lastClickTime-this.__lastLastClickTime<500&&this.__lastPointer.x===t.x&&this.__lastPointer.y===t.y}doubleClickHandler(t){this.isEditing&&this.selectWord(this.getSelectionStartFromPointer(t.e))}tripleClickHandler(t){this.isEditing&&this.selectLine(this.getSelectionStartFromPointer(t.e))}_mouseDownHandler(t){let{e}=t;this.canvas&&this.editable&&!Qf(e)&&!this.getActiveControl()&&(this.draggableTextDelegate.start(e)||(this.canvas.textEditingManager.register(this),this.selected&&(this.inCompositionMode=!1,this.setCursorByClick(e)),this.isEditing&&(this.__selectionStartOnMouseDown=this.selectionStart,this.selectionStart===this.selectionEnd&&this.abortCursorAnimation(),this.renderCursorOrSelection())))}_mouseDownHandlerBefore(t){let{e}=t;this.canvas&&this.editable&&!Qf(e)&&(this.selected=this===this.canvas._activeObject)}mouseUpHandler(t){let{e,transform:s}=t;const i=this.draggableTextDelegate.end(e);if(this.canvas){this.canvas.textEditingManager.unregister(this);const n=this.canvas._activeObject;if(n&&n!==this)return}!this.editable||this.group&&!this.group.interactive||s&&s.actionPerformed||Qf(e)||i||(this.__lastSelected&&!this.getActiveControl()?(this.selected=!1,this.__lastSelected=!1,this.enterEditing(e),this.selectionStart===this.selectionEnd?this.initDelayedCursor(!0):this.renderCursorOrSelection()):this.selected=!0)}setCursorByClick(t){const e=this.getSelectionStartFromPointer(t),s=this.selectionStart,i=this.selectionEnd;t.shiftKey?this.setSelectionStartEndWithShift(s,i,e):(this.selectionStart=e,this.selectionEnd=e),this.isEditing&&(this._fireSelectionChanged(),this._updateTextarea())}getSelectionStartFromPointer(t){const e=this.canvas.getScenePoint(t).transform(Xe(this.calcTransformMatrix())).add(new D(-this._getLeftOffset(),-this._getTopOffset()));let s=0,i=0,n=0;for(let c=0;c<this._textLines.length&&s<=e.y;c++)s+=this.getHeightOfLine(c),n=c,c>0&&(i+=this._textLines[c-1].length+this.missingNewlineOffset(c-1));let r=Math.abs(this._getLineLeftOffset(n));const o=this._textLines[n].length,h=this.__charBounds[n];for(let c=0;c<o;c++){const u=r+h[c].kernedWidth;if(e.x<=u){Math.abs(e.x-u)<=Math.abs(e.x-r)&&i++;break}r=u,i++}return Math.min(this.flipX?o-i:i,this._text.length)}}const vu="moveCursorUp",_u="moveCursorDown",wu="moveCursorLeft",xu="moveCursorRight",Su="exitEditing",Tw=T({selectionStart:0,selectionEnd:0,selectionColor:"rgba(17,119,255,0.3)",isEditing:!1,editable:!0,editingBorderColor:"rgba(102,153,255,0.25)",cursorWidth:2,cursorColor:"",cursorDelay:1e3,cursorDuration:600,caching:!0,hiddenTextareaContainer:null,keysMap:{9:Su,27:Su,33:vu,34:_u,35:xu,36:wu,37:wu,38:vu,39:xu,40:_u},keysMapRtl:{9:Su,27:Su,33:vu,34:_u,35:wu,36:xu,37:xu,38:vu,39:wu,40:_u},ctrlKeysMapDown:{65:"selectAll"},ctrlKeysMapUp:{67:"copy",88:"cut"}},{_selectionDirection:null,_reSpace:/\s|\r?\n/,inCompositionMode:!1});class Gi extends Aw{static getDefaults(){return T(T({},super.getDefaults()),Gi.ownDefaults)}get type(){const t=super.type;return t==="itext"?"i-text":t}constructor(t,e){super(t,T(T({},Gi.ownDefaults),e)),this.initBehavior()}_set(t,e){return this.isEditing&&this._savedProps&&t in this._savedProps?(this._savedProps[t]=e,this):(t==="canvas"&&(this.canvas instanceof Uf&&this.canvas.textEditingManager.remove(this),e instanceof Uf&&e.textEditingManager.add(this)),super._set(t,e))}setSelectionStart(t){t=Math.max(t,0),this._updateAndFire("selectionStart",t)}setSelectionEnd(t){t=Math.min(t,this.text.length),this._updateAndFire("selectionEnd",t)}_updateAndFire(t,e){this[t]!==e&&(this._fireSelectionChanged(),this[t]=e),this._updateTextarea()}_fireSelectionChanged(){this.fire("selection:changed"),this.canvas&&this.canvas.fire("text:selection:changed",{target:this})}initDimensions(){this.isEditing&&this.initDelayedCursor(),super.initDimensions()}getSelectionStyles(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:this.selectionStart||0,e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:this.selectionEnd,s=arguments.length>2?arguments[2]:void 0;return super.getSelectionStyles(t,e,s)}setSelectionStyles(t){let e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:this.selectionStart||0,s=arguments.length>2&&arguments[2]!==void 0?arguments[2]:this.selectionEnd;return super.setSelectionStyles(t,e,s)}get2DCursorLocation(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:this.selectionStart,e=arguments.length>1?arguments[1]:void 0;return super.get2DCursorLocation(t,e)}render(t){super.render(t),this.cursorOffsetCache={},this.renderCursorOrSelection()}toCanvasElement(t){const e=this.isEditing;this.isEditing=!1;const s=super.toCanvasElement(t);return this.isEditing=e,s}renderCursorOrSelection(){if(!this.isEditing)return;const t=this.clearContextTop(!0);if(!t)return;const e=this._getCursorBoundaries();this.selectionStart!==this.selectionEnd||this.inCompositionMode?this.renderSelection(t,e):this.renderCursor(t,e),this.canvas.contextTopDirty=!0,t.restore()}_getCursorBoundaries(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:this.selectionStart,e=arguments.length>1?arguments[1]:void 0;const s=this._getLeftOffset(),i=this._getTopOffset(),n=this._getCursorBoundariesOffsets(t,e);return{left:s,top:i,leftOffset:n.left,topOffset:n.top}}_getCursorBoundariesOffsets(t,e){return e?this.__getCursorBoundariesOffsets(t):this.cursorOffsetCache&&"top"in this.cursorOffsetCache?this.cursorOffsetCache:this.cursorOffsetCache=this.__getCursorBoundariesOffsets(t)}__getCursorBoundariesOffsets(t){let e=0,s=0;const{charIndex:i,lineIndex:n}=this.get2DCursorLocation(t);for(let c=0;c<n;c++)e+=this.getHeightOfLine(c);const r=this._getLineLeftOffset(n),o=this.__charBounds[n][i];o&&(s=o.left),this.charSpacing!==0&&i===this._textLines[n].length&&(s-=this._getWidthOfCharSpacing());const h={top:e,left:r+(s>0?s:0)};return this.direction==="rtl"&&(this.textAlign===It||this.textAlign===hi||this.textAlign===Nh?h.left*=-1:this.textAlign===dt||this.textAlign===yu?h.left=r-(s>0?s:0):this.textAlign!==Q&&this.textAlign!==jh||(h.left=r-(s>0?s:0))),h}renderCursorAt(t){this._renderCursor(this.canvas.contextTop,this._getCursorBoundaries(t,!0),t)}renderCursor(t,e){this._renderCursor(t,e,this.selectionStart)}getCursorRenderingData(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:this.selectionStart,e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:this._getCursorBoundaries(t);const s=this.get2DCursorLocation(t),i=s.lineIndex,n=s.charIndex>0?s.charIndex-1:0,r=this.getValueOfPropertyAt(i,n,"fontSize"),o=this.getObjectScaling().x*this.canvas.getZoom(),h=this.cursorWidth/o,c=this.getValueOfPropertyAt(i,n,"deltaY"),u=e.topOffset+(1-this._fontSizeFraction)*this.getHeightOfLine(i)/this.lineHeight-r*(1-this._fontSizeFraction);return{color:this.cursorColor||this.getValueOfPropertyAt(i,n,"fill"),opacity:this._currentCursorOpacity,left:e.left+e.leftOffset-h/2,top:u+e.top+c,width:h,height:r}}_renderCursor(t,e,s){const{color:i,opacity:n,left:r,top:o,width:h,height:c}=this.getCursorRenderingData(s,e);t.fillStyle=i,t.globalAlpha=n,t.fillRect(r,o,h,c)}renderSelection(t,e){const s={selectionStart:this.inCompositionMode?this.hiddenTextarea.selectionStart:this.selectionStart,selectionEnd:this.inCompositionMode?this.hiddenTextarea.selectionEnd:this.selectionEnd};this._renderSelection(t,s,e)}renderDragSourceEffect(){const t=this.draggableTextDelegate.getDragStartSelection();this._renderSelection(this.canvas.contextTop,t,this._getCursorBoundaries(t.selectionStart,!0))}renderDropTargetEffect(t){const e=this.getSelectionStartFromPointer(t);this.renderCursorAt(e)}_renderSelection(t,e,s){const i=e.selectionStart,n=e.selectionEnd,r=this.textAlign.includes(hi),o=this.get2DCursorLocation(i),h=this.get2DCursorLocation(n),c=o.lineIndex,u=h.lineIndex,d=o.charIndex<0?0:o.charIndex,f=h.charIndex<0?0:h.charIndex;for(let g=c;g<=u;g++){const p=this._getLineLeftOffset(g)||0;let b=this.getHeightOfLine(g),_=0,v=0,x=0;if(g===c&&(v=this.__charBounds[c][d].left),g>=c&&g<u)x=r&&!this.isEndOfWrapping(g)?this.width:this.getLineWidth(g)||5;else if(g===u)if(f===0)x=this.__charBounds[u][f].left;else{const E=this._getWidthOfCharSpacing();x=this.__charBounds[u][f-1].left+this.__charBounds[u][f-1].width-E}_=b,(this.lineHeight<1||g===u&&this.lineHeight>1)&&(b/=this.lineHeight);let C=s.left+p+v,S=b,k=0;const M=x-v;this.inCompositionMode?(t.fillStyle=this.compositionColor||"black",S=1,k=b):t.fillStyle=this.selectionColor,this.direction==="rtl"&&(this.textAlign===It||this.textAlign===hi||this.textAlign===Nh?C=this.width-C-M:this.textAlign===dt||this.textAlign===yu?C=s.left+p-x:this.textAlign!==Q&&this.textAlign!==jh||(C=s.left+p-x)),t.fillRect(C,s.top+s.topOffset+k,M,S),s.topOffset+=_}}getCurrentCharFontSize(){const t=this._getCurrentCharIndex();return this.getValueOfPropertyAt(t.l,t.c,"fontSize")}getCurrentCharColor(){const t=this._getCurrentCharIndex();return this.getValueOfPropertyAt(t.l,t.c,zt)}_getCurrentCharIndex(){const t=this.get2DCursorLocation(this.selectionStart,!0),e=t.charIndex>0?t.charIndex-1:0;return{l:t.lineIndex,c:e}}dispose(){this.exitEditingImpl(),this.draggableTextDelegate.dispose(),super.dispose()}}A(Gi,"ownDefaults",Tw),A(Gi,"type","IText"),N.setClass(Gi),N.setClass(Gi,"i-text");class Ar extends Gi{static getDefaults(){return T(T({},super.getDefaults()),Ar.ownDefaults)}constructor(t,e){super(t,T(T({},Ar.ownDefaults),e))}static createControls(){return{controls:c_()}}initDimensions(){this.initialized&&(this.isEditing&&this.initDelayedCursor(),this._clearCache(),this.dynamicMinWidth=0,this._styleMap=this._generateStyleMap(this._splitText()),this.dynamicMinWidth>this.width&&this._set("width",this.dynamicMinWidth),this.textAlign.includes(hi)&&this.enlargeSpaces(),this.height=this.calcTextHeight())}_generateStyleMap(t){let e=0,s=0,i=0;const n={};for(let r=0;r<t.graphemeLines.length;r++)t.graphemeText[i]===`
|
|
57
|
+
`&&r>0?(s=0,i++,e++):!this.splitByGrapheme&&this._reSpaceAndTab.test(t.graphemeText[i])&&r>0&&(s++,i++),n[r]={line:e,offset:s},i+=t.graphemeLines[r].length,s+=t.graphemeLines[r].length;return n}styleHas(t,e){if(this._styleMap&&!this.isWrapping){const s=this._styleMap[e];s&&(e=s.line)}return super.styleHas(t,e)}isEmptyStyles(t){if(!this.styles)return!0;let e,s=0,i=t+1,n=!1;const r=this._styleMap[t],o=this._styleMap[t+1];r&&(t=r.line,s=r.offset),o&&(i=o.line,n=i===t,e=o.offset);const h=t===void 0?this.styles:{line:this.styles[t]};for(const c in h)for(const u in h[c]){const d=parseInt(u,10);if(d>=s&&(!n||d<e))for(const f in h[c][u])return!1}return!0}_getStyleDeclaration(t,e){if(this._styleMap&&!this.isWrapping){const s=this._styleMap[t];if(!s)return{};t=s.line,e=s.offset+e}return super._getStyleDeclaration(t,e)}_setStyleDeclaration(t,e,s){const i=this._styleMap[t];super._setStyleDeclaration(i.line,i.offset+e,s)}_deleteStyleDeclaration(t,e){const s=this._styleMap[t];super._deleteStyleDeclaration(s.line,s.offset+e)}_getLineStyle(t){const e=this._styleMap[t];return!!this.styles[e.line]}_setLineStyle(t){const e=this._styleMap[t];super._setLineStyle(e.line)}_wrapText(t,e){this.isWrapping=!0;const s=this.getGraphemeDataForRender(t),i=[];for(let n=0;n<s.wordsData.length;n++)i.push(...this._wrapLine(n,e,s));return this.isWrapping=!1,i}getGraphemeDataForRender(t){const e=this.splitByGrapheme,s=e?"":" ";let i=0;return{wordsData:t.map((n,r)=>{let o=0;const h=e?this.graphemeSplit(n):this.wordSplit(n);return h.length===0?[{word:[],width:0}]:h.map(c=>{const u=e?[c]:this.graphemeSplit(c),d=this._measureWord(u,r,o);return i=Math.max(d,i),o+=u.length+s.length,{word:u,width:d}})}),largestWordWidth:i}}_measureWord(t,e){let s,i=arguments.length>2&&arguments[2]!==void 0?arguments[2]:0,n=0;for(let r=0,o=t.length;r<o;r++)n+=this._getGraphemeBox(t[r],e,r+i,s,!0).kernedWidth,s=t[r];return n}wordSplit(t){return t.split(this._wordJoiners)}_wrapLine(t,e,s){let{largestWordWidth:i,wordsData:n}=s,r=arguments.length>3&&arguments[3]!==void 0?arguments[3]:0;const o=this._getWidthOfCharSpacing(),h=this.splitByGrapheme,c=[],u=h?"":" ";let d=0,f=[],g=0,p=0,b=!0;e-=r;const _=Math.max(e,i,this.dynamicMinWidth),v=n[t];let x;for(g=0,x=0;x<v.length;x++){const{word:C,width:S}=v[x];g+=C.length,d+=p+S-o,d>_&&!b?(c.push(f),f=[],d=S,b=!0):d+=o,b||h||f.push(u),f=f.concat(C),p=h?0:this._measureWord([u],t,g),g++,b=!1}return x&&c.push(f),i+r>this.dynamicMinWidth&&(this.dynamicMinWidth=i-o+r),c}isEndOfWrapping(t){return!this._styleMap[t+1]||this._styleMap[t+1].line!==this._styleMap[t].line}missingNewlineOffset(t,e){return this.splitByGrapheme&&!e?this.isEndOfWrapping(t)?1:0:1}_splitTextIntoLines(t){const e=super._splitTextIntoLines(t),s=this._wrapText(e.lines,this.width),i=new Array(s.length);for(let n=0;n<s.length;n++)i[n]=s[n].join("");return e.lines=i,e.graphemeLines=s,e}getMinWidth(){return Math.max(this.minWidth,this.dynamicMinWidth)}_removeExtraneousStyles(){const t=new Map;for(const e in this._styleMap){const s=parseInt(e,10);if(this._textLines[s]){const i=this._styleMap[e].line;t.set("".concat(i),!0)}}for(const e in this.styles)t.has(e)||delete this.styles[e]}toObject(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:[];return super.toObject(["minWidth","splitByGrapheme",...t])}}A(Ar,"type","Textbox"),A(Ar,"textLayoutProperties",[...Gi.textLayoutProperties,"width"]),A(Ar,"ownDefaults",{minWidth:20,dynamicMinWidth:2,lockScalingFlip:!0,noScaleCache:!1,_wordJoiners:/[ \t\r]/,splitByGrapheme:!1}),N.setClass(Ar);class I0 extends du{shouldPerformLayout(t){return!!t.target.clipPath&&super.shouldPerformLayout(t)}shouldLayoutClipPath(){return!1}calcLayoutResult(t,e){const{target:s}=t,{clipPath:i,group:n}=s;if(!i||!this.shouldPerformLayout(t))return;const{width:r,height:o}=ri(o0(s,i)),h=new D(r,o);if(i.absolutePositioned)return{center:_r(i.getRelativeCenterPoint(),void 0,n?n.calcTransformMatrix():void 0),size:h};{const c=i.getRelativeCenterPoint().transform(s.calcOwnMatrix(),!0);if(this.shouldPerformLayout(t)){const{center:u=new D,correction:d=new D}=this.calcBoundingBox(e,t)||{};return{center:u.add(c),correction:d.subtract(c),size:h}}return{center:s.getRelativeCenterPoint().add(c),size:h}}}}A(I0,"type","clip-path"),N.setClass(I0);class N0 extends du{getInitialSize(t,e){let{target:s}=t,{size:i}=e;return new D(s.width||i.x,s.height||i.y)}}A(N0,"type","fixed"),N.setClass(N0);class Ew extends Lh{subscribeTargets(t){const e=t.target;t.targets.reduce((s,i)=>(i.parent&&s.add(i.parent),s),new Set).forEach(s=>{s.layoutManager.subscribeTargets({target:s,targets:[e]})})}unsubscribeTargets(t){const e=t.target,s=e.getObjects();t.targets.reduce((i,n)=>(n.parent&&i.add(n.parent),i),new Set).forEach(i=>{!s.some(n=>n.parent===i)&&i.layoutManager.unsubscribeTargets({target:i,targets:[e]})})}}class Tr extends ai{static getDefaults(){return T(T({},super.getDefaults()),Tr.ownDefaults)}constructor(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:[],e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};super(),Object.assign(this,Tr.ownDefaults),this.setOptions(e);const{left:s,top:i,layoutManager:n}=e;this.groupInit(t,{left:s,top:i,layoutManager:n??new Ew})}_shouldSetNestedCoords(){return!0}__objectSelectionMonitor(){}multiSelectAdd(){for(var t=arguments.length,e=new Array(t),s=0;s<t;s++)e[s]=arguments[s];this.multiSelectionStacking==="selection-order"?this.add(...e):e.forEach(i=>{const n=this._objects.findIndex(o=>o.isInFrontOf(i)),r=n===-1?this.size():n;this.insertAt(r,i)})}canEnterGroup(t){return this.getObjects().some(e=>e.isDescendantOf(t)||t.isDescendantOf(e))?(Oi("error","ActiveSelection: circular object trees are not supported, this call has no effect"),!1):super.canEnterGroup(t)}enterGroup(t,e){t.parent&&t.parent===t.group?t.parent._exitGroup(t):t.group&&t.parent!==t.group&&t.group.remove(t),this._enterGroup(t,e)}exitGroup(t,e){this._exitGroup(t,e),t.parent&&t.parent._enterGroup(t,!0)}_onAfterObjectsChange(t,e){super._onAfterObjectsChange(t,e);const s=new Set;e.forEach(i=>{const{parent:n}=i;n&&s.add(n)}),t===Gf?s.forEach(i=>{i._onAfterObjectsChange(cu,e)}):s.forEach(i=>{i._set("dirty",!0)})}onDeselect(){return this.removeAll(),!1}toString(){return"#<ActiveSelection: (".concat(this.complexity(),")>")}shouldCache(){return!1}isOnACache(){return!1}_renderControls(t,e,s){t.save(),t.globalAlpha=this.isMoving?this.borderOpacityWhenMoving:1;const i=T(T({hasControls:!1},s),{},{forActiveSelection:!0});for(let n=0;n<this._objects.length;n++)this._objects[n]._renderControls(t,i);super._renderControls(t,e),t.restore()}}A(Tr,"type","ActiveSelection"),A(Tr,"ownDefaults",{multiSelectionStacking:"canvas-stacking"}),N.setClass(Tr),N.setClass(Tr,"activeSelection");class kw{constructor(){A(this,"resources",{})}applyFilters(t,e,s,i,n){const r=n.getContext("2d");if(!r)return;r.drawImage(e,0,0,s,i);const o={sourceWidth:s,sourceHeight:i,imageData:r.getImageData(0,0,s,i),originalEl:e,originalImageData:r.getImageData(0,0,s,i),canvasEl:n,ctx:r,filterBackend:this};t.forEach(c=>{c.applyTo(o)});const{imageData:h}=o;return h.width===s&&h.height===i||(n.width=h.width,n.height=h.height),r.putImageData(h,0,0),o}}class j0{constructor(){let{tileSize:t=ht.textureSize}=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};A(this,"aPosition",new Float32Array([0,0,0,1,1,0,1,1])),A(this,"resources",{}),this.tileSize=t,this.setupGLContext(t,t),this.captureGPUInfo()}setupGLContext(t,e){this.dispose(),this.createWebGLCanvas(t,e)}createWebGLCanvas(t,e){const s=Rs({width:t,height:e}),i=s.getContext("webgl",{alpha:!0,premultipliedAlpha:!1,depth:!1,stencil:!1,antialias:!1});i&&(i.clearColor(0,0,0,0),this.canvas=s,this.gl=i)}applyFilters(t,e,s,i,n,r){const o=this.gl,h=n.getContext("2d");if(!o||!h)return;let c;r&&(c=this.getCachedTexture(r,e));const u={originalWidth:e.width||e.naturalWidth||0,originalHeight:e.height||e.naturalHeight||0,sourceWidth:s,sourceHeight:i,destinationWidth:s,destinationHeight:i,context:o,sourceTexture:this.createTexture(o,s,i,c?void 0:e),targetTexture:this.createTexture(o,s,i),originalTexture:c||this.createTexture(o,s,i,c?void 0:e),passes:t.length,webgl:!0,aPosition:this.aPosition,programCache:this.programCache,pass:0,filterBackend:this,targetCanvas:n},d=o.createFramebuffer();return o.bindFramebuffer(o.FRAMEBUFFER,d),t.forEach(f=>{f&&f.applyTo(u)}),function(f){const g=f.targetCanvas,p=g.width,b=g.height,_=f.destinationWidth,v=f.destinationHeight;p===_&&b===v||(g.width=_,g.height=v)}(u),this.copyGLTo2D(o,u),o.bindTexture(o.TEXTURE_2D,null),o.deleteTexture(u.sourceTexture),o.deleteTexture(u.targetTexture),o.deleteFramebuffer(d),h.setTransform(1,0,0,1,0,0),u}dispose(){this.canvas&&(this.canvas=null,this.gl=null),this.clearWebGLCaches()}clearWebGLCaches(){this.programCache={},this.textureCache={}}createTexture(t,e,s,i,n){const{NEAREST:r,TEXTURE_2D:o,RGBA:h,UNSIGNED_BYTE:c,CLAMP_TO_EDGE:u,TEXTURE_MAG_FILTER:d,TEXTURE_MIN_FILTER:f,TEXTURE_WRAP_S:g,TEXTURE_WRAP_T:p}=t,b=t.createTexture();return t.bindTexture(o,b),t.texParameteri(o,d,n||r),t.texParameteri(o,f,n||r),t.texParameteri(o,g,u),t.texParameteri(o,p,u),i?t.texImage2D(o,0,h,h,c,i):t.texImage2D(o,0,h,e,s,0,h,c,null),b}getCachedTexture(t,e,s){const{textureCache:i}=this;if(i[t])return i[t];{const n=this.createTexture(this.gl,e.width,e.height,e,s);return n&&(i[t]=n),n}}evictCachesForKey(t){this.textureCache[t]&&(this.gl.deleteTexture(this.textureCache[t]),delete this.textureCache[t])}copyGLTo2D(t,e){const s=t.canvas,i=e.targetCanvas,n=i.getContext("2d");if(!n)return;n.translate(0,i.height),n.scale(1,-1);const r=s.height-i.height;n.drawImage(s,0,r,i.width,i.height,0,0,i.width,i.height)}copyGLTo2DPutImageData(t,e){const s=e.targetCanvas.getContext("2d"),i=e.destinationWidth,n=e.destinationHeight,r=i*n*4;if(!s)return;const o=new Uint8Array(this.imageBuffer,0,r),h=new Uint8ClampedArray(this.imageBuffer,0,r);t.readPixels(0,0,i,n,t.RGBA,t.UNSIGNED_BYTE,o);const c=new ImageData(h,i,n);s.putImageData(c,0,0)}captureGPUInfo(){if(this.gpuInfo)return this.gpuInfo;const t=this.gl,e={renderer:"",vendor:""};if(!t)return e;const s=t.getExtension("WEBGL_debug_renderer_info");if(s){const i=t.getParameter(s.UNMASKED_RENDERER_WEBGL),n=t.getParameter(s.UNMASKED_VENDOR_WEBGL);i&&(e.renderer=i.toLowerCase()),n&&(e.vendor=n.toLowerCase())}return this.gpuInfo=e,e}}let Jf;function Mw(){const{WebGLProbe:a}=ni();return a.queryWebGL(ms()),ht.enableGLFiltering&&a.isSupported(ht.textureSize)?new j0({tileSize:ht.textureSize}):new kw}function Zf(){return!Jf&&(!(arguments.length>0&&arguments[0]!==void 0)||arguments[0])&&(Jf=Mw()),Jf}const Pw=["filters","resizeFilter","src","crossOrigin","type"],B0=["cropX","cropY"];class be extends pe{static getDefaults(){return T(T({},super.getDefaults()),be.ownDefaults)}constructor(t,e){super(),A(this,"_lastScaleX",1),A(this,"_lastScaleY",1),A(this,"_filterScalingX",1),A(this,"_filterScalingY",1),this.filters=[],Object.assign(this,be.ownDefaults),this.setOptions(e),this.cacheKey="texture".concat(En()),this.setElement(typeof t=="string"?(this.canvas&&Ls(this.canvas.getElement())||Vo()).getElementById(t):t,e)}getElement(){return this._element}setElement(t){var e;let s=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};this.removeTexture(this.cacheKey),this.removeTexture("".concat(this.cacheKey,"_filtered")),this._element=t,this._originalElement=t,this._setWidthHeight(s),(e=t.classList)===null||e===void 0||e.add(be.CSS_CANVAS),this.filters.length!==0&&this.applyFilters(),this.resizeFilter&&this.applyResizeFilters()}removeTexture(t){const e=Zf(!1);e instanceof j0&&e.evictCachesForKey(t)}dispose(){super.dispose(),this.removeTexture(this.cacheKey),this.removeTexture("".concat(this.cacheKey,"_filtered")),this._cacheContext=null,["_originalElement","_element","_filteredEl","_cacheCanvas"].forEach(t=>{const e=this[t];e&&ni().dispose(e),this[t]=void 0})}getCrossOrigin(){return this._originalElement&&(this._originalElement.crossOrigin||null)}getOriginalSize(){const t=this.getElement();return t?{width:t.naturalWidth||t.width,height:t.naturalHeight||t.height}:{width:0,height:0}}_stroke(t){if(!this.stroke||this.strokeWidth===0)return;const e=this.width/2,s=this.height/2;t.beginPath(),t.moveTo(-e,-s),t.lineTo(e,-s),t.lineTo(e,s),t.lineTo(-e,s),t.lineTo(-e,-s),t.closePath()}toObject(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:[];const e=[];return this.filters.forEach(s=>{s&&e.push(s.toObject())}),T(T({},super.toObject([...B0,...t])),{},{src:this.getSrc(),crossOrigin:this.getCrossOrigin(),filters:e},this.resizeFilter?{resizeFilter:this.resizeFilter.toObject()}:{})}hasCrop(){return!!this.cropX||!!this.cropY||this.width<this._element.width||this.height<this._element.height}_toSVG(){const t=[],e=this._element,s=-this.width/2,i=-this.height/2;let n=[],r=[],o="",h="";if(!e)return[];if(this.hasCrop()){const c=En();n.push('<clipPath id="imageCrop_'+c+`">
|
|
58
58
|
`,' <rect x="'+s+'" y="'+i+'" width="'+this.width+'" height="'+this.height+`" />
|
|
59
59
|
`,`</clipPath>
|
|
60
60
|
`),o=' clip-path="url(#imageCrop_'+c+')" '}if(this.imageSmoothing||(h=' image-rendering="optimizeSpeed"'),t.push(" <image ","COMMON_PARTS",'xlink:href="'.concat(this.getSvgSrc(!0),'" x="').concat(s-this.cropX,'" y="').concat(i-this.cropY,'" width="').concat(e.width||e.naturalWidth,'" height="').concat(e.height||e.naturalHeight,'"').concat(h).concat(o,`></image>
|
|
61
61
|
`)),this.stroke||this.strokeDashArray){const c=this.fill;this.fill=null,r=[' <rect x="'.concat(s,'" y="').concat(i,'" width="').concat(this.width,'" height="').concat(this.height,'" style="').concat(this.getSvgStyles(),`" />
|
|
62
|
-
`)],this.fill=c}return n=this.paintFirst!==zt?n.concat(r,t):n.concat(t,r),n}getSrc(t){const e=t?this._element:this._originalElement;return e?e.toDataURL?e.toDataURL():this.srcFromAttribute?e.getAttribute("src")||"":e.src:this.src||""}getSvgSrc(t){return this.getSrc(t)}setSrc(t){let{crossOrigin:e,signal:s}=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};return Th(t,{crossOrigin:e,signal:s}).then(i=>{e!==void 0&&this.set({crossOrigin:e}),this.setElement(i)})}toString(){return'#<Image: { src: "'.concat(this.getSrc(),'" }>')}applyResizeFilters(){const t=this.resizeFilter,e=this.minimumScaleTrigger,s=this.getTotalObjectScaling(),i=s.x,n=s.y,r=this._filteredEl||this._originalElement;if(this.group&&this.set("dirty",!0),!t||i>e&&n>e)return this._element=r,this._filterScalingX=1,this._filterScalingY=1,this._lastScaleX=i,void(this._lastScaleY=n);const o=Rs(r),{width:h,height:c}=r;this._element=o,this._lastScaleX=t.scaleX=i,this._lastScaleY=t.scaleY=n,Zf().applyFilters([t],r,h,c,this._element),this._filterScalingX=o.width/this._originalElement.width,this._filterScalingY=o.height/this._originalElement.height}applyFilters(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:this.filters||[];if(t=t.filter(n=>n&&!n.isNeutralState()),this.set("dirty",!0),this.removeTexture("".concat(this.cacheKey,"_filtered")),t.length===0)return this._element=this._originalElement,this._filteredEl=void 0,this._filterScalingX=1,void(this._filterScalingY=1);const e=this._originalElement,s=e.naturalWidth||e.width,i=e.naturalHeight||e.height;if(this._element===this._originalElement){const n=Rs({width:s,height:i});this._element=n,this._filteredEl=n}else this._filteredEl&&(this._element=this._filteredEl,this._filteredEl.getContext("2d").clearRect(0,0,s,i),this._lastScaleX=1,this._lastScaleY=1);Zf().applyFilters(t,this._originalElement,s,i,this._element,this.cacheKey),this._originalElement.width===this._element.width&&this._originalElement.height===this._element.height||(this._filterScalingX=this._element.width/this._originalElement.width,this._filterScalingY=this._element.height/this._originalElement.height)}_render(t){t.imageSmoothingEnabled=this.imageSmoothing,this.isMoving!==!0&&this.resizeFilter&&this._needsResize()&&this.applyResizeFilters(),this._stroke(t),this._renderPaintInOrder(t)}drawCacheOnCanvas(t){t.imageSmoothingEnabled=this.imageSmoothing,super.drawCacheOnCanvas(t)}shouldCache(){return this.needsItsOwnCache()}_renderFill(t){const e=this._element;if(!e)return;const s=this._filterScalingX,i=this._filterScalingY,n=this.width,r=this.height,o=Math.max(this.cropX,0),h=Math.max(this.cropY,0),c=e.naturalWidth||e.width,u=e.naturalHeight||e.height,d=o*s,f=h*i,g=Math.min(n*s,c-d),p=Math.min(r*i,u-f),b=-n/2,_=-r/2,v=Math.min(n,c/s-o),x=Math.min(r,u/i-h);e&&t.drawImage(e,d,f,g,p,b,_,v,x)}_needsResize(){const t=this.getTotalObjectScaling();return t.x!==this._lastScaleX||t.y!==this._lastScaleY}_resetWidthHeight(){this.set(this.getOriginalSize())}_setWidthHeight(){let{width:t,height:e}=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};const s=this.getOriginalSize();this.width=t||s.width,this.height=e||s.height}parsePreserveAspectRatioAttribute(){const t=vf(this.preserveAspectRatio||""),e=this.width,s=this.height,i={width:e,height:s};let n,r=this._element.width,o=this._element.height,h=1,c=1,u=0,d=0,f=0,g=0;return!t||t.alignX===ke&&t.alignY===ke?(h=e/r,c=s/o):(t.meetOrSlice==="meet"&&(h=c=h0(this._element,i),n=(e-r*h)/2,t.alignX==="Min"&&(u=-n),t.alignX==="Max"&&(u=n),n=(s-o*c)/2,t.alignY==="Min"&&(d=-n),t.alignY==="Max"&&(d=n)),t.meetOrSlice==="slice"&&(h=c=l0(this._element,i),n=r-e/h,t.alignX==="Mid"&&(f=n/2),t.alignX==="Max"&&(f=n),n=o-s/c,t.alignY==="Mid"&&(g=n/2),t.alignY==="Max"&&(g=n),r=e/h,o=s/c)),{width:r,height:o,scaleX:h,scaleY:c,offsetLeft:u,offsetTop:d,cropX:f,cropY:g}}static fromObject(t,e){let{filters:s,resizeFilter:i,src:n,crossOrigin:r,type:o}=t,h=Ct(t,Ew);return Promise.all([Th(n,T(T({},e),{},{crossOrigin:r})),s&&qo(s,e),i&&qo([i],e),Eh(h,e)]).then(c=>{let[u,d=[],[f]=[],g={}]=c;return new this(u,T(T({},h),{},{src:n,filters:d,resizeFilter:f},g))})}static fromURL(t){let{crossOrigin:e=null,signal:s}=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},i=arguments.length>2?arguments[2]:void 0;return Th(t,{crossOrigin:e,signal:s}).then(n=>new this(n,i))}static async fromElement(t){let e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},s=arguments.length>2?arguments[2]:void 0;const i=Ni(t,this.ATTRIBUTE_NAMES,s);return this.fromURL(i["xlink:href"],e,i).catch(n=>(Oi("log","Unable to parse Image",n),null))}}function tg(a){if(!Ov.test(a.nodeName))return{};const t=a.getAttribute("viewBox");let e,s,i=1,n=1,r=0,o=0;const h=a.getAttribute("width"),c=a.getAttribute("height"),u=a.getAttribute("x")||0,d=a.getAttribute("y")||0,f=!(t&&Tm.test(t)),g=!h||!c||h==="100%"||c==="100%";let p="",b=0,_=0;if(f&&(u||d)&&a.parentNode&&a.parentNode.nodeName!=="#document"&&(p=" translate("+De(u||"0")+" "+De(d||"0")+") ",e=(a.getAttribute("transform")||"")+p,a.setAttribute("transform",e),a.removeAttribute("x"),a.removeAttribute("y")),f&&g)return{width:0,height:0};const v={width:0,height:0};if(f)return v.width=De(h),v.height=De(c),v;const x=t.match(Tm);r=-parseFloat(x[1]),o=-parseFloat(x[2]);const C=parseFloat(x[3]),S=parseFloat(x[4]);v.minX=r,v.minY=o,v.viewBoxWidth=C,v.viewBoxHeight=S,g?(v.width=C,v.height=S):(v.width=De(h),v.height=De(c),i=v.width/C,n=v.height/S);const E=vf(a.getAttribute("preserveAspectRatio")||"");if(E.alignX!==ke&&(E.meetOrSlice==="meet"&&(n=i=i>n?n:i),E.meetOrSlice==="slice"&&(n=i=i>n?i:n),b=v.width-C*i,_=v.height-S*i,E.alignX==="Mid"&&(b/=2),E.alignY==="Mid"&&(_/=2),E.alignX==="Min"&&(b=0),E.alignY==="Min"&&(_=0)),i===1&&n===1&&r===0&&o===0&&u===0&&d===0)return v;if((u||d)&&a.parentNode.nodeName!=="#document"&&(p=" translate("+De(u||"0")+" "+De(d||"0")+") "),e=p+" matrix("+i+" 0 0 "+n+" "+(r*i+b)+" "+(o*n+_)+") ",a.nodeName==="svg"){for(s=a.ownerDocument.createElementNS(Af,"g");a.firstChild;)s.appendChild(a.firstChild);a.appendChild(s)}else s=a,s.removeAttribute("x"),s.removeAttribute("y"),e=s.getAttribute("transform")+e;return s.setAttribute("transform",e),v}A(be,"type","Image"),A(be,"cacheProperties",[...Fi,...B0]),A(be,"ownDefaults",{strokeWidth:0,srcFromAttribute:!1,minimumScaleTrigger:.5,cropX:0,cropY:0,imageSmoothing:!0}),A(be,"CSS_CANVAS","canvas-img"),A(be,"ATTRIBUTE_NAMES",[...Mn,"x","y","width","height","preserveAspectRatio","xlink:href","crossOrigin","image-rendering"]),H.setClass(be),H.setSVGClass(be);const Cu=a=>a.tagName.replace("svg:",""),kw=Zc(["pattern","defs","symbol","metadata","clipPath","mask","desc"]);function H0(a,t){let e,s,i,n,r=[];for(i=0,n=t.length;i<n;i++)e=t[i],s=a.getElementsByTagNameNS("http://www.w3.org/2000/svg",e),r=r.concat(Array.from(s));return r}const Mw=["gradientTransform","x1","x2","y1","y2","gradientUnits","cx","cy","r","fx","fy"],eg="xlink:href";function G0(a,t){var e;const s=((e=t.getAttribute(eg))===null||e===void 0?void 0:e.slice(1))||"",i=a.getElementById(s);if(i&&i.getAttribute(eg)&&G0(a,i),i&&(Mw.forEach(n=>{const r=i.getAttribute(n);!t.hasAttribute(n)&&r&&t.setAttribute(n,r)}),!t.children.length)){const n=i.cloneNode(!0);for(;n.firstChild;)t.appendChild(n.firstChild)}t.removeAttribute(eg)}const Pw=["linearGradient","radialGradient","svg:linearGradient","svg:radialGradient"];function Dw(a){const t=a.getElementsByTagName("style");let e,s;const i={};for(e=0,s=t.length;e<s;e++){const n=(t[e].textContent||"").replace(/\/\*[\s\S]*?\*\//g,"");n.trim()!==""&&n.split("}").filter((r,o,h)=>h.length>1&&r.trim()).forEach(r=>{if((r.match(/{/g)||[]).length>1&&r.trim().startsWith("@"))return;const o=r.split("{"),h={},c=o[1].trim().split(";").filter(function(u){return u.trim()});for(e=0,s=c.length;e<s;e++){const u=c[e].split(":"),d=u[0].trim(),f=u[1].trim();h[d]=f}(r=o[0].trim()).split(",").forEach(u=>{(u=u.replace(/^svg/i,"").trim())!==""&&(i[u]=T(T({},i[u]||{}),h))})})}return i}const z0=a=>H.getSVGClass(Cu(a).toLowerCase());class Ow{constructor(t,e,s,i,n){this.elements=t,this.options=e,this.reviver=s,this.regexUrl=/^url\(['"]?#([^'"]+)['"]?\)/g,this.doc=i,this.clipPaths=n,this.gradientDefs=function(r){const o=H0(r,Pw),h={};let c=o.length;for(;c--;){const u=o[c];u.getAttribute("xlink:href")&&G0(r,u);const d=u.getAttribute("id");d&&(h[d]=u)}return h}(i),this.cssRules=Dw(i)}parse(){return Promise.all(this.elements.map(t=>this.createObject(t)))}async createObject(t){const e=z0(t);if(e){const s=await e.fromElement(t,this.options,this.cssRules);return this.resolveGradient(s,t,zt),this.resolveGradient(s,t,Pe),s instanceof be&&s._originalElement?pu(s,s.parsePreserveAspectRatioAttribute()):pu(s),await this.resolveClipPath(s,t),this.reviver&&this.reviver(t,s),s}return null}extractPropertyDefinition(t,e,s){const i=t[e],n=this.regexUrl;if(!n.test(i))return;n.lastIndex=0;const r=n.exec(i)[1];return n.lastIndex=0,s[r]}resolveGradient(t,e,s){const i=this.extractPropertyDefinition(t,s,this.gradientDefs);if(i){const n=e.getAttribute(s+"-opacity"),r=Ih.fromElement(i,t,T(T({},this.options),{},{opacity:n}));t.set(s,r)}}async resolveClipPath(t,e,s){const i=this.extractPropertyDefinition(t,"clipPath",this.clipPaths);if(i){const n=Xe(t.calcTransformMatrix()),r=i[0].parentElement;let o=e;for(;!s&&o.parentElement&&o.getAttribute("clip-path")!==t.clipPath;)o=o.parentElement;o.parentElement.appendChild(r);const h=lu("".concat(o.getAttribute("transform")||""," ").concat(r.getAttribute("originalTransform")||""));r.setAttribute("transform","matrix(".concat(h.join(","),")"));const c=await Promise.all(i.map(x=>z0(x).fromElement(x,this.options,this.cssRules).then(C=>(pu(C),C.fillRule=C.clipRule,delete C.clipRule,C)))),u=c.length===1?c[0]:new ai(c),d=Nt(n,u.calcTransformMatrix());u.clipPath&&await this.resolveClipPath(u,o,r.getAttribute("clip-path")?o:void 0);const{scaleX:f,scaleY:g,angle:p,skewX:b,translateX:_,translateY:v}=br(d);u.set({flipX:!1,flipY:!1}),u.set({scaleX:f,scaleY:g,angle:p,skewX:b,skewY:0}),u.setPositionByOrigin(new P(_,v),J,J),t.clipPath=u}else delete t.clipPath}}const V0=a=>Dv.test(Cu(a)),sg=()=>({objects:[],elements:[],options:{},allElements:[]});async function Rw(a,t){let{crossOrigin:e,signal:s}=arguments.length>2&&arguments[2]!==void 0?arguments[2]:{};if(s&&s.aborted)return Oi("log",new nf("parseSVGDocument")),sg();const i=a.documentElement;(function(u){const d=H0(u,["use","svg:use"]),f=["x","y","xlink:href","href","transform"];for(const g of d){const p=g.attributes,b={};for(const R of p)R.value&&(b[R.name]=R.value);const _=(b["xlink:href"]||b.href||"").slice(1);if(_==="")return;const v=u.getElementById(_);if(v===null)return;let x=v.cloneNode(!0);const C=x.attributes,S={};for(const R of C)R.value&&(S[R.name]=R.value);const{x:E=0,y:k=0,transform:M=""}=b,D="".concat(M," ").concat(S.transform||""," translate(").concat(E,", ").concat(k,")");if(tg(x),/^svg$/i.test(x.nodeName)){const R=x.ownerDocument.createElementNS(Af,"g");Object.entries(S).forEach(B=>{let[O,F]=B;return R.setAttributeNS(Af,O,F)}),R.append(...x.childNodes),x=R}for(const R of p){if(!R)continue;const{name:B,value:O}=R;if(!f.includes(B))if(B==="style"){const F={};Hf(O,F),Object.entries(S).forEach(N=>{let[Y,I]=N;F[Y]=I}),Hf(S.style||"",F);const L=Object.entries(F).map(N=>N.join(":")).join(";");x.setAttribute(B,L)}else!S[B]&&x.setAttribute(B,O)}x.setAttribute("transform",D),x.setAttribute("instantiated_by_use","1"),x.removeAttribute("id"),g.parentNode.replaceChild(x,g)}})(a);const n=Array.from(i.getElementsByTagName("*")),r=T(T({},tg(i)),{},{crossOrigin:e,signal:s}),o=n.filter(u=>(tg(u),V0(u)&&!function(d){let f=d;for(;f&&(f=f.parentElement);)if(f&&f.nodeName&&kw.test(Cu(f))&&!f.getAttribute("instantiated_by_use"))return!0;return!1}(u)));if(!o||o&&!o.length)return T(T({},sg()),{},{options:r,allElements:n});const h={};return n.filter(u=>Cu(u)==="clipPath").forEach(u=>{u.setAttribute("originalTransform",u.getAttribute("transform")||"");const d=u.getAttribute("id");h[d]=Array.from(u.getElementsByTagName("*")).filter(f=>V0(f))}),{objects:await new Ow(o,r,t,a,h).parse(),elements:o,options:r,allElements:n}}function Lw(a,t){let e=arguments.length>2&&arguments[2]!==void 0?arguments[2]:{};return new Promise((s,i)=>{w0(a.replace(/^\n\s*/,"").trim(),{onComplete:n=>{const r=n.responseXML;r&&s(r),i()},signal:e.signal})}).then(s=>Rw(s,t,e)).catch(()=>sg())}const Au=a=>a.webgl!==void 0,ig="precision highp float",Fw=`
|
|
62
|
+
`)],this.fill=c}return n=this.paintFirst!==zt?n.concat(r,t):n.concat(t,r),n}getSrc(t){const e=t?this._element:this._originalElement;return e?e.toDataURL?e.toDataURL():this.srcFromAttribute?e.getAttribute("src")||"":e.src:this.src||""}getSvgSrc(t){return this.getSrc(t)}setSrc(t){let{crossOrigin:e,signal:s}=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};return Th(t,{crossOrigin:e,signal:s}).then(i=>{e!==void 0&&this.set({crossOrigin:e}),this.setElement(i)})}toString(){return'#<Image: { src: "'.concat(this.getSrc(),'" }>')}applyResizeFilters(){const t=this.resizeFilter,e=this.minimumScaleTrigger,s=this.getTotalObjectScaling(),i=s.x,n=s.y,r=this._filteredEl||this._originalElement;if(this.group&&this.set("dirty",!0),!t||i>e&&n>e)return this._element=r,this._filterScalingX=1,this._filterScalingY=1,this._lastScaleX=i,void(this._lastScaleY=n);const o=Rs(r),{width:h,height:c}=r;this._element=o,this._lastScaleX=t.scaleX=i,this._lastScaleY=t.scaleY=n,Zf().applyFilters([t],r,h,c,this._element),this._filterScalingX=o.width/this._originalElement.width,this._filterScalingY=o.height/this._originalElement.height}applyFilters(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:this.filters||[];if(t=t.filter(n=>n&&!n.isNeutralState()),this.set("dirty",!0),this.removeTexture("".concat(this.cacheKey,"_filtered")),t.length===0)return this._element=this._originalElement,this._filteredEl=void 0,this._filterScalingX=1,void(this._filterScalingY=1);const e=this._originalElement,s=e.naturalWidth||e.width,i=e.naturalHeight||e.height;if(this._element===this._originalElement){const n=Rs({width:s,height:i});this._element=n,this._filteredEl=n}else this._filteredEl&&(this._element=this._filteredEl,this._filteredEl.getContext("2d").clearRect(0,0,s,i),this._lastScaleX=1,this._lastScaleY=1);Zf().applyFilters(t,this._originalElement,s,i,this._element,this.cacheKey),this._originalElement.width===this._element.width&&this._originalElement.height===this._element.height||(this._filterScalingX=this._element.width/this._originalElement.width,this._filterScalingY=this._element.height/this._originalElement.height)}_render(t){t.imageSmoothingEnabled=this.imageSmoothing,this.isMoving!==!0&&this.resizeFilter&&this._needsResize()&&this.applyResizeFilters(),this._stroke(t),this._renderPaintInOrder(t)}drawCacheOnCanvas(t){t.imageSmoothingEnabled=this.imageSmoothing,super.drawCacheOnCanvas(t)}shouldCache(){return this.needsItsOwnCache()}_renderFill(t){const e=this._element;if(!e)return;const s=this._filterScalingX,i=this._filterScalingY,n=this.width,r=this.height,o=Math.max(this.cropX,0),h=Math.max(this.cropY,0),c=e.naturalWidth||e.width,u=e.naturalHeight||e.height,d=o*s,f=h*i,g=Math.min(n*s,c-d),p=Math.min(r*i,u-f),b=-n/2,_=-r/2,v=Math.min(n,c/s-o),x=Math.min(r,u/i-h);e&&t.drawImage(e,d,f,g,p,b,_,v,x)}_needsResize(){const t=this.getTotalObjectScaling();return t.x!==this._lastScaleX||t.y!==this._lastScaleY}_resetWidthHeight(){this.set(this.getOriginalSize())}_setWidthHeight(){let{width:t,height:e}=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};const s=this.getOriginalSize();this.width=t||s.width,this.height=e||s.height}parsePreserveAspectRatioAttribute(){const t=vf(this.preserveAspectRatio||""),e=this.width,s=this.height,i={width:e,height:s};let n,r=this._element.width,o=this._element.height,h=1,c=1,u=0,d=0,f=0,g=0;return!t||t.alignX===ke&&t.alignY===ke?(h=e/r,c=s/o):(t.meetOrSlice==="meet"&&(h=c=h0(this._element,i),n=(e-r*h)/2,t.alignX==="Min"&&(u=-n),t.alignX==="Max"&&(u=n),n=(s-o*c)/2,t.alignY==="Min"&&(d=-n),t.alignY==="Max"&&(d=n)),t.meetOrSlice==="slice"&&(h=c=l0(this._element,i),n=r-e/h,t.alignX==="Mid"&&(f=n/2),t.alignX==="Max"&&(f=n),n=o-s/c,t.alignY==="Mid"&&(g=n/2),t.alignY==="Max"&&(g=n),r=e/h,o=s/c)),{width:r,height:o,scaleX:h,scaleY:c,offsetLeft:u,offsetTop:d,cropX:f,cropY:g}}static fromObject(t,e){let{filters:s,resizeFilter:i,src:n,crossOrigin:r,type:o}=t,h=Ct(t,Pw);return Promise.all([Th(n,T(T({},e),{},{crossOrigin:r})),s&&qo(s,e),i&&qo([i],e),Eh(h,e)]).then(c=>{let[u,d=[],[f]=[],g={}]=c;return new this(u,T(T({},h),{},{src:n,filters:d,resizeFilter:f},g))})}static fromURL(t){let{crossOrigin:e=null,signal:s}=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},i=arguments.length>2?arguments[2]:void 0;return Th(t,{crossOrigin:e,signal:s}).then(n=>new this(n,i))}static async fromElement(t){let e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},s=arguments.length>2?arguments[2]:void 0;const i=Ni(t,this.ATTRIBUTE_NAMES,s);return this.fromURL(i["xlink:href"],e,i).catch(n=>(Oi("log","Unable to parse Image",n),null))}}function tg(a){if(!Fv.test(a.nodeName))return{};const t=a.getAttribute("viewBox");let e,s,i=1,n=1,r=0,o=0;const h=a.getAttribute("width"),c=a.getAttribute("height"),u=a.getAttribute("x")||0,d=a.getAttribute("y")||0,f=!(t&&Tm.test(t)),g=!h||!c||h==="100%"||c==="100%";let p="",b=0,_=0;if(f&&(u||d)&&a.parentNode&&a.parentNode.nodeName!=="#document"&&(p=" translate("+De(u||"0")+" "+De(d||"0")+") ",e=(a.getAttribute("transform")||"")+p,a.setAttribute("transform",e),a.removeAttribute("x"),a.removeAttribute("y")),f&&g)return{width:0,height:0};const v={width:0,height:0};if(f)return v.width=De(h),v.height=De(c),v;const x=t.match(Tm);r=-parseFloat(x[1]),o=-parseFloat(x[2]);const C=parseFloat(x[3]),S=parseFloat(x[4]);v.minX=r,v.minY=o,v.viewBoxWidth=C,v.viewBoxHeight=S,g?(v.width=C,v.height=S):(v.width=De(h),v.height=De(c),i=v.width/C,n=v.height/S);const k=vf(a.getAttribute("preserveAspectRatio")||"");if(k.alignX!==ke&&(k.meetOrSlice==="meet"&&(n=i=i>n?n:i),k.meetOrSlice==="slice"&&(n=i=i>n?i:n),b=v.width-C*i,_=v.height-S*i,k.alignX==="Mid"&&(b/=2),k.alignY==="Mid"&&(_/=2),k.alignX==="Min"&&(b=0),k.alignY==="Min"&&(_=0)),i===1&&n===1&&r===0&&o===0&&u===0&&d===0)return v;if((u||d)&&a.parentNode.nodeName!=="#document"&&(p=" translate("+De(u||"0")+" "+De(d||"0")+") "),e=p+" matrix("+i+" 0 0 "+n+" "+(r*i+b)+" "+(o*n+_)+") ",a.nodeName==="svg"){for(s=a.ownerDocument.createElementNS(Af,"g");a.firstChild;)s.appendChild(a.firstChild);a.appendChild(s)}else s=a,s.removeAttribute("x"),s.removeAttribute("y"),e=s.getAttribute("transform")+e;return s.setAttribute("transform",e),v}A(be,"type","Image"),A(be,"cacheProperties",[...Fi,...B0]),A(be,"ownDefaults",{strokeWidth:0,srcFromAttribute:!1,minimumScaleTrigger:.5,cropX:0,cropY:0,imageSmoothing:!0}),A(be,"CSS_CANVAS","canvas-img"),A(be,"ATTRIBUTE_NAMES",[...Mn,"x","y","width","height","preserveAspectRatio","xlink:href","crossOrigin","image-rendering"]),N.setClass(be),N.setSVGClass(be);const Cu=a=>a.tagName.replace("svg:",""),Dw=Zc(["pattern","defs","symbol","metadata","clipPath","mask","desc"]);function H0(a,t){let e,s,i,n,r=[];for(i=0,n=t.length;i<n;i++)e=t[i],s=a.getElementsByTagNameNS("http://www.w3.org/2000/svg",e),r=r.concat(Array.from(s));return r}const Ow=["gradientTransform","x1","x2","y1","y2","gradientUnits","cx","cy","r","fx","fy"],eg="xlink:href";function G0(a,t){var e;const s=((e=t.getAttribute(eg))===null||e===void 0?void 0:e.slice(1))||"",i=a.getElementById(s);if(i&&i.getAttribute(eg)&&G0(a,i),i&&(Ow.forEach(n=>{const r=i.getAttribute(n);!t.hasAttribute(n)&&r&&t.setAttribute(n,r)}),!t.children.length)){const n=i.cloneNode(!0);for(;n.firstChild;)t.appendChild(n.firstChild)}t.removeAttribute(eg)}const Rw=["linearGradient","radialGradient","svg:linearGradient","svg:radialGradient"];function Lw(a){const t=a.getElementsByTagName("style");let e,s;const i={};for(e=0,s=t.length;e<s;e++){const n=(t[e].textContent||"").replace(/\/\*[\s\S]*?\*\//g,"");n.trim()!==""&&n.split("}").filter((r,o,h)=>h.length>1&&r.trim()).forEach(r=>{if((r.match(/{/g)||[]).length>1&&r.trim().startsWith("@"))return;const o=r.split("{"),h={},c=o[1].trim().split(";").filter(function(u){return u.trim()});for(e=0,s=c.length;e<s;e++){const u=c[e].split(":"),d=u[0].trim(),f=u[1].trim();h[d]=f}(r=o[0].trim()).split(",").forEach(u=>{(u=u.replace(/^svg/i,"").trim())!==""&&(i[u]=T(T({},i[u]||{}),h))})})}return i}const z0=a=>N.getSVGClass(Cu(a).toLowerCase());class Fw{constructor(t,e,s,i,n){this.elements=t,this.options=e,this.reviver=s,this.regexUrl=/^url\(['"]?#([^'"]+)['"]?\)/g,this.doc=i,this.clipPaths=n,this.gradientDefs=function(r){const o=H0(r,Rw),h={};let c=o.length;for(;c--;){const u=o[c];u.getAttribute("xlink:href")&&G0(r,u);const d=u.getAttribute("id");d&&(h[d]=u)}return h}(i),this.cssRules=Lw(i)}parse(){return Promise.all(this.elements.map(t=>this.createObject(t)))}async createObject(t){const e=z0(t);if(e){const s=await e.fromElement(t,this.options,this.cssRules);return this.resolveGradient(s,t,zt),this.resolveGradient(s,t,Pe),s instanceof be&&s._originalElement?pu(s,s.parsePreserveAspectRatioAttribute()):pu(s),await this.resolveClipPath(s,t),this.reviver&&this.reviver(t,s),s}return null}extractPropertyDefinition(t,e,s){const i=t[e],n=this.regexUrl;if(!n.test(i))return;n.lastIndex=0;const r=n.exec(i)[1];return n.lastIndex=0,s[r]}resolveGradient(t,e,s){const i=this.extractPropertyDefinition(t,s,this.gradientDefs);if(i){const n=e.getAttribute(s+"-opacity"),r=Ih.fromElement(i,t,T(T({},this.options),{},{opacity:n}));t.set(s,r)}}async resolveClipPath(t,e,s){const i=this.extractPropertyDefinition(t,"clipPath",this.clipPaths);if(i){const n=Xe(t.calcTransformMatrix()),r=i[0].parentElement;let o=e;for(;!s&&o.parentElement&&o.getAttribute("clip-path")!==t.clipPath;)o=o.parentElement;o.parentElement.appendChild(r);const h=lu("".concat(o.getAttribute("transform")||""," ").concat(r.getAttribute("originalTransform")||""));r.setAttribute("transform","matrix(".concat(h.join(","),")"));const c=await Promise.all(i.map(x=>z0(x).fromElement(x,this.options,this.cssRules).then(C=>(pu(C),C.fillRule=C.clipRule,delete C.clipRule,C)))),u=c.length===1?c[0]:new ai(c),d=Nt(n,u.calcTransformMatrix());u.clipPath&&await this.resolveClipPath(u,o,r.getAttribute("clip-path")?o:void 0);const{scaleX:f,scaleY:g,angle:p,skewX:b,translateX:_,translateY:v}=br(d);u.set({flipX:!1,flipY:!1}),u.set({scaleX:f,scaleY:g,angle:p,skewX:b,skewY:0}),u.setPositionByOrigin(new D(_,v),Q,Q),t.clipPath=u}else delete t.clipPath}}const V0=a=>Lv.test(Cu(a)),sg=()=>({objects:[],elements:[],options:{},allElements:[]});async function Iw(a,t){let{crossOrigin:e,signal:s}=arguments.length>2&&arguments[2]!==void 0?arguments[2]:{};if(s&&s.aborted)return Oi("log",new nf("parseSVGDocument")),sg();const i=a.documentElement;(function(u){const d=H0(u,["use","svg:use"]),f=["x","y","xlink:href","href","transform"];for(const g of d){const p=g.attributes,b={};for(const O of p)O.value&&(b[O.name]=O.value);const _=(b["xlink:href"]||b.href||"").slice(1);if(_==="")return;const v=u.getElementById(_);if(v===null)return;let x=v.cloneNode(!0);const C=x.attributes,S={};for(const O of C)O.value&&(S[O.name]=O.value);const{x:k=0,y:M=0,transform:E=""}=b,P="".concat(E," ").concat(S.transform||""," translate(").concat(k,", ").concat(M,")");if(tg(x),/^svg$/i.test(x.nodeName)){const O=x.ownerDocument.createElementNS(Af,"g");Object.entries(S).forEach(L=>{let[R,U]=L;return O.setAttributeNS(Af,R,U)}),O.append(...x.childNodes),x=O}for(const O of p){if(!O)continue;const{name:L,value:R}=O;if(!f.includes(L))if(L==="style"){const U={};Hf(R,U),Object.entries(S).forEach(V=>{let[at,F]=V;U[at]=F}),Hf(S.style||"",U);const z=Object.entries(U).map(V=>V.join(":")).join(";");x.setAttribute(L,z)}else!S[L]&&x.setAttribute(L,R)}x.setAttribute("transform",P),x.setAttribute("instantiated_by_use","1"),x.removeAttribute("id"),g.parentNode.replaceChild(x,g)}})(a);const n=Array.from(i.getElementsByTagName("*")),r=T(T({},tg(i)),{},{crossOrigin:e,signal:s}),o=n.filter(u=>(tg(u),V0(u)&&!function(d){let f=d;for(;f&&(f=f.parentElement);)if(f&&f.nodeName&&Dw.test(Cu(f))&&!f.getAttribute("instantiated_by_use"))return!0;return!1}(u)));if(!o||o&&!o.length)return T(T({},sg()),{},{options:r,allElements:n});const h={};return n.filter(u=>Cu(u)==="clipPath").forEach(u=>{u.setAttribute("originalTransform",u.getAttribute("transform")||"");const d=u.getAttribute("id");h[d]=Array.from(u.getElementsByTagName("*")).filter(f=>V0(f))}),{objects:await new Fw(o,r,t,a,h).parse(),elements:o,options:r,allElements:n}}function Nw(a,t){let e=arguments.length>2&&arguments[2]!==void 0?arguments[2]:{};return new Promise((s,i)=>{w0(a.replace(/^\n\s*/,"").trim(),{onComplete:n=>{const r=n.responseXML;r&&s(r),i()},signal:e.signal})}).then(s=>Iw(s,t,e)).catch(()=>sg())}const Au=a=>a.webgl!==void 0,ig="precision highp float",jw=`
|
|
63
63
|
`.concat(ig,`;
|
|
64
64
|
varying vec2 vTexCoord;
|
|
65
65
|
uniform sampler2D uTexture;
|
|
66
66
|
void main() {
|
|
67
67
|
gl_FragColor = texture2D(uTexture, vTexCoord);
|
|
68
|
-
}`),
|
|
68
|
+
}`),Bw=["type"],Hw=["type"],Gw=new RegExp(ig,"g");class $t{get type(){return this.constructor.type}constructor(){let t=Ct(arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},Bw);Object.assign(this,this.constructor.defaults,t)}getFragmentSource(){return jw}getVertexSource(){return`
|
|
69
69
|
attribute vec2 aPosition;
|
|
70
70
|
varying vec2 vTexCoord;
|
|
71
71
|
void main() {
|
|
72
72
|
vTexCoord = aPosition;
|
|
73
73
|
gl_Position = vec4(aPosition * 2.0 - 1.0, 0.0, 1.0);
|
|
74
|
-
}`}createProgram(t){let e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:this.getFragmentSource(),s=arguments.length>2&&arguments[2]!==void 0?arguments[2]:this.getVertexSource();const{WebGLProbe:{GLPrecision:i="highp"}}=ni();i!=="highp"&&(e=e.replace(
|
|
74
|
+
}`}createProgram(t){let e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:this.getFragmentSource(),s=arguments.length>2&&arguments[2]!==void 0?arguments[2]:this.getVertexSource();const{WebGLProbe:{GLPrecision:i="highp"}}=ni();i!=="highp"&&(e=e.replace(Gw,ig.replace("highp",i)));const n=t.createShader(t.VERTEX_SHADER),r=t.createShader(t.FRAGMENT_SHADER),o=t.createProgram();if(!n||!r||!o)throw new ii("Vertex, fragment shader or program creation error");if(t.shaderSource(n,s),t.compileShader(n),!t.getShaderParameter(n,t.COMPILE_STATUS))throw new ii("Vertex shader compile error for ".concat(this.type,": ").concat(t.getShaderInfoLog(n)));if(t.shaderSource(r,e),t.compileShader(r),!t.getShaderParameter(r,t.COMPILE_STATUS))throw new ii("Fragment shader compile error for ".concat(this.type,": ").concat(t.getShaderInfoLog(r)));if(t.attachShader(o,n),t.attachShader(o,r),t.linkProgram(o),!t.getProgramParameter(o,t.LINK_STATUS))throw new ii('Shader link error for "'.concat(this.type,'" ').concat(t.getProgramInfoLog(o)));const h=this.getUniformLocations(t,o)||{};return h.uStepW=t.getUniformLocation(o,"uStepW"),h.uStepH=t.getUniformLocation(o,"uStepH"),{program:o,attributeLocations:this.getAttributeLocations(t,o),uniformLocations:h}}getAttributeLocations(t,e){return{aPosition:t.getAttribLocation(e,"aPosition")}}getUniformLocations(t,e){const s=this.constructor.uniformLocations,i={};for(let n=0;n<s.length;n++)i[s[n]]=t.getUniformLocation(e,s[n]);return i}sendAttributeData(t,e,s){const i=e.aPosition,n=t.createBuffer();t.bindBuffer(t.ARRAY_BUFFER,n),t.enableVertexAttribArray(i),t.vertexAttribPointer(i,2,t.FLOAT,!1,0,0),t.bufferData(t.ARRAY_BUFFER,s,t.STATIC_DRAW)}_setupFrameBuffer(t){const e=t.context;if(t.passes>1){const s=t.destinationWidth,i=t.destinationHeight;t.sourceWidth===s&&t.sourceHeight===i||(e.deleteTexture(t.targetTexture),t.targetTexture=t.filterBackend.createTexture(e,s,i)),e.framebufferTexture2D(e.FRAMEBUFFER,e.COLOR_ATTACHMENT0,e.TEXTURE_2D,t.targetTexture,0)}else e.bindFramebuffer(e.FRAMEBUFFER,null),e.finish()}_swapTextures(t){t.passes--,t.pass++;const e=t.targetTexture;t.targetTexture=t.sourceTexture,t.sourceTexture=e}isNeutralState(t){return!1}applyTo(t){Au(t)?(this._setupFrameBuffer(t),this.applyToWebGL(t),this._swapTextures(t)):this.applyTo2d(t)}applyTo2d(t){}getCacheKey(){return this.type}retrieveShader(t){const e=this.getCacheKey();return t.programCache[e]||(t.programCache[e]=this.createProgram(t.context)),t.programCache[e]}applyToWebGL(t){const e=t.context,s=this.retrieveShader(t);t.pass===0&&t.originalTexture?e.bindTexture(e.TEXTURE_2D,t.originalTexture):e.bindTexture(e.TEXTURE_2D,t.sourceTexture),e.useProgram(s.program),this.sendAttributeData(e,s.attributeLocations,t.aPosition),e.uniform1f(s.uniformLocations.uStepW,1/t.sourceWidth),e.uniform1f(s.uniformLocations.uStepH,1/t.sourceHeight),this.sendUniformData(e,s.uniformLocations),e.viewport(0,0,t.destinationWidth,t.destinationHeight),e.drawArrays(e.TRIANGLE_STRIP,0,4)}bindAdditionalTexture(t,e,s){t.activeTexture(s),t.bindTexture(t.TEXTURE_2D,e),t.activeTexture(t.TEXTURE0)}unbindAdditionalTexture(t,e){t.activeTexture(e),t.bindTexture(t.TEXTURE_2D,null),t.activeTexture(t.TEXTURE0)}sendUniformData(t,e){}createHelpLayer(t){if(!t.helpLayer){const{sourceWidth:e,sourceHeight:s}=t,i=Rs({width:e,height:s});t.helpLayer=i}}toObject(){const t=Object.keys(this.constructor.defaults||{});return T({type:this.type},t.reduce((e,s)=>(e[s]=this[s],e),{}))}toJSON(){return this.toObject()}static async fromObject(t,e){return new this(Ct(t,Hw))}}A($t,"type","BaseFilter"),A($t,"uniformLocations",[]);const zw={multiply:`gl_FragColor.rgb *= uColor.rgb;
|
|
75
75
|
`,screen:`gl_FragColor.rgb = 1.0 - (1.0 - gl_FragColor.rgb) * (1.0 - uColor.rgb);
|
|
76
76
|
`,add:`gl_FragColor.rgb += uColor.rgb;
|
|
77
77
|
`,difference:`gl_FragColor.rgb = abs(gl_FragColor.rgb - uColor.rgb);
|
|
@@ -107,10 +107,10 @@ Resulting to default behavior: removing object from previous canvas and adding t
|
|
|
107
107
|
vec4 color = texture2D(uTexture, vTexCoord);
|
|
108
108
|
gl_FragColor = color;
|
|
109
109
|
if (color.a > 0.0) {
|
|
110
|
-
`.concat(
|
|
110
|
+
`.concat(zw[this.mode],`
|
|
111
111
|
}
|
|
112
112
|
}
|
|
113
|
-
`)}applyTo2d(t){let{imageData:{data:e}}=t;const s=new gt(this.color).getSource(),i=this.alpha,n=s[0]*i,r=s[1]*i,o=s[2]*i,h=1-i;for(let c=0;c<e.length;c+=4){const u=e[c],d=e[c+1],f=e[c+2];let g,p,b;switch(this.mode){case"multiply":g=u*n/255,p=d*r/255,b=f*o/255;break;case"screen":g=255-(255-u)*(255-n)/255,p=255-(255-d)*(255-r)/255,b=255-(255-f)*(255-o)/255;break;case"add":g=u+n,p=d+r,b=f+o;break;case"difference":g=Math.abs(u-n),p=Math.abs(d-r),b=Math.abs(f-o);break;case"subtract":g=u-n,p=d-r,b=f-o;break;case"darken":g=Math.min(u,n),p=Math.min(d,r),b=Math.min(f,o);break;case"lighten":g=Math.max(u,n),p=Math.max(d,r),b=Math.max(f,o);break;case"overlay":g=n<128?2*u*n/255:255-2*(255-u)*(255-n)/255,p=r<128?2*d*r/255:255-2*(255-d)*(255-r)/255,b=o<128?2*f*o/255:255-2*(255-f)*(255-o)/255;break;case"exclusion":g=n+u-2*n*u/255,p=r+d-2*r*d/255,b=o+f-2*o*f/255;break;case"tint":g=n+u*h,p=r+d*h,b=o+f*h}e[c]=g,e[c+1]=p,e[c+2]=b}}sendUniformData(t,e){const s=new gt(this.color).getSource();s[0]=this.alpha*s[0]/255,s[1]=this.alpha*s[1]/255,s[2]=this.alpha*s[2]/255,s[3]=this.alpha,t.uniform4fv(e.uColor,s)}}A(Tu,"defaults",{color:"#F95C63",mode:"multiply",alpha:1}),A(Tu,"type","BlendColor"),A(Tu,"uniformLocations",["uColor"]),
|
|
113
|
+
`)}applyTo2d(t){let{imageData:{data:e}}=t;const s=new gt(this.color).getSource(),i=this.alpha,n=s[0]*i,r=s[1]*i,o=s[2]*i,h=1-i;for(let c=0;c<e.length;c+=4){const u=e[c],d=e[c+1],f=e[c+2];let g,p,b;switch(this.mode){case"multiply":g=u*n/255,p=d*r/255,b=f*o/255;break;case"screen":g=255-(255-u)*(255-n)/255,p=255-(255-d)*(255-r)/255,b=255-(255-f)*(255-o)/255;break;case"add":g=u+n,p=d+r,b=f+o;break;case"difference":g=Math.abs(u-n),p=Math.abs(d-r),b=Math.abs(f-o);break;case"subtract":g=u-n,p=d-r,b=f-o;break;case"darken":g=Math.min(u,n),p=Math.min(d,r),b=Math.min(f,o);break;case"lighten":g=Math.max(u,n),p=Math.max(d,r),b=Math.max(f,o);break;case"overlay":g=n<128?2*u*n/255:255-2*(255-u)*(255-n)/255,p=r<128?2*d*r/255:255-2*(255-d)*(255-r)/255,b=o<128?2*f*o/255:255-2*(255-f)*(255-o)/255;break;case"exclusion":g=n+u-2*n*u/255,p=r+d-2*r*d/255,b=o+f-2*o*f/255;break;case"tint":g=n+u*h,p=r+d*h,b=o+f*h}e[c]=g,e[c+1]=p,e[c+2]=b}}sendUniformData(t,e){const s=new gt(this.color).getSource();s[0]=this.alpha*s[0]/255,s[1]=this.alpha*s[1]/255,s[2]=this.alpha*s[2]/255,s[3]=this.alpha,t.uniform4fv(e.uColor,s)}}A(Tu,"defaults",{color:"#F95C63",mode:"multiply",alpha:1}),A(Tu,"type","BlendColor"),A(Tu,"uniformLocations",["uColor"]),N.setClass(Tu);const Vw={multiply:`
|
|
114
114
|
precision highp float;
|
|
115
115
|
uniform sampler2D uTexture;
|
|
116
116
|
uniform sampler2D uImage;
|
|
@@ -136,7 +136,7 @@ Resulting to default behavior: removing object from previous canvas and adding t
|
|
|
136
136
|
color.a = color2.a;
|
|
137
137
|
gl_FragColor = color;
|
|
138
138
|
}
|
|
139
|
-
`},
|
|
139
|
+
`},Xw=["type","image"];class Eu extends $t{getCacheKey(){return"".concat(this.type,"_").concat(this.mode)}getFragmentSource(){return Vw[this.mode]}getVertexSource(){return`
|
|
140
140
|
attribute vec2 aPosition;
|
|
141
141
|
varying vec2 vTexCoord;
|
|
142
142
|
varying vec2 vTexCoord2;
|
|
@@ -146,7 +146,7 @@ Resulting to default behavior: removing object from previous canvas and adding t
|
|
|
146
146
|
vTexCoord2 = (uTransformMatrix * vec3(aPosition, 1.0)).xy;
|
|
147
147
|
gl_Position = vec4(aPosition * 2.0 - 1.0, 0.0, 1.0);
|
|
148
148
|
}
|
|
149
|
-
`}applyToWebGL(t){const e=t.context,s=this.createTexture(t.filterBackend,this.image);this.bindAdditionalTexture(e,s,e.TEXTURE1),super.applyToWebGL(t),this.unbindAdditionalTexture(e,e.TEXTURE1)}createTexture(t,e){return t.getCachedTexture(e.cacheKey,e.getElement())}calculateMatrix(){const t=this.image,{width:e,height:s}=t.getElement();return[1/t.scaleX,0,0,0,1/t.scaleY,0,-t.left/e,-t.top/s,1]}applyTo2d(t){let{imageData:{data:e,width:s,height:i},filterBackend:{resources:n}}=t;const r=this.image;n.blendImage||(n.blendImage=ms());const o=n.blendImage,h=o.getContext("2d");o.width!==s||o.height!==i?(o.width=s,o.height=i):h.clearRect(0,0,s,i),h.setTransform(r.scaleX,0,0,r.scaleY,r.left,r.top),h.drawImage(r.getElement(),0,0,s,i);const c=h.getImageData(0,0,s,i).data;for(let u=0;u<e.length;u+=4){const d=e[u],f=e[u+1],g=e[u+2],p=e[u+3],b=c[u],_=c[u+1],v=c[u+2],x=c[u+3];switch(this.mode){case"multiply":e[u]=d*b/255,e[u+1]=f*_/255,e[u+2]=g*v/255,e[u+3]=p*x/255;break;case"mask":e[u+3]=x}}}sendUniformData(t,e){const s=this.calculateMatrix();t.uniform1i(e.uImage,1),t.uniformMatrix3fv(e.uTransformMatrix,!1,s)}toObject(){return T(T({},super.toObject()),{},{image:this.image&&this.image.toObject()})}static async fromObject(t,e){let{type:s,image:i}=t,n=Ct(t,
|
|
149
|
+
`}applyToWebGL(t){const e=t.context,s=this.createTexture(t.filterBackend,this.image);this.bindAdditionalTexture(e,s,e.TEXTURE1),super.applyToWebGL(t),this.unbindAdditionalTexture(e,e.TEXTURE1)}createTexture(t,e){return t.getCachedTexture(e.cacheKey,e.getElement())}calculateMatrix(){const t=this.image,{width:e,height:s}=t.getElement();return[1/t.scaleX,0,0,0,1/t.scaleY,0,-t.left/e,-t.top/s,1]}applyTo2d(t){let{imageData:{data:e,width:s,height:i},filterBackend:{resources:n}}=t;const r=this.image;n.blendImage||(n.blendImage=ms());const o=n.blendImage,h=o.getContext("2d");o.width!==s||o.height!==i?(o.width=s,o.height=i):h.clearRect(0,0,s,i),h.setTransform(r.scaleX,0,0,r.scaleY,r.left,r.top),h.drawImage(r.getElement(),0,0,s,i);const c=h.getImageData(0,0,s,i).data;for(let u=0;u<e.length;u+=4){const d=e[u],f=e[u+1],g=e[u+2],p=e[u+3],b=c[u],_=c[u+1],v=c[u+2],x=c[u+3];switch(this.mode){case"multiply":e[u]=d*b/255,e[u+1]=f*_/255,e[u+2]=g*v/255,e[u+3]=p*x/255;break;case"mask":e[u+3]=x}}}sendUniformData(t,e){const s=this.calculateMatrix();t.uniform1i(e.uImage,1),t.uniformMatrix3fv(e.uTransformMatrix,!1,s)}toObject(){return T(T({},super.toObject()),{},{image:this.image&&this.image.toObject()})}static async fromObject(t,e){let{type:s,image:i}=t,n=Ct(t,Xw);return be.fromObject(i,e).then(r=>new this(T(T({},n),{},{image:r})))}}A(Eu,"type","BlendImage"),A(Eu,"defaults",{mode:"multiply",alpha:1}),A(Eu,"uniformLocations",["uTransformMatrix","uImage"]),N.setClass(Eu);class ku extends $t{getFragmentSource(){return`
|
|
150
150
|
precision highp float;
|
|
151
151
|
uniform sampler2D uTexture;
|
|
152
152
|
uniform vec2 uDelta;
|
|
@@ -169,7 +169,7 @@ Resulting to default behavior: removing object from previous canvas and adding t
|
|
|
169
169
|
}
|
|
170
170
|
gl_FragColor = color / total;
|
|
171
171
|
}
|
|
172
|
-
`}applyTo(t){Au(t)?(this.aspectRatio=t.sourceWidth/t.sourceHeight,t.passes++,this._setupFrameBuffer(t),this.horizontal=!0,this.applyToWebGL(t),this._swapTextures(t),this._setupFrameBuffer(t),this.horizontal=!1,this.applyToWebGL(t),this._swapTextures(t)):this.applyTo2d(t)}applyTo2d(t){t.imageData=this.simpleBlur(t)}simpleBlur(t){let{ctx:e,imageData:s,filterBackend:{resources:i}}=t;const{width:n,height:r}=s;i.blurLayer1||(i.blurLayer1=ms(),i.blurLayer2=ms());const o=i.blurLayer1,h=i.blurLayer2;o.width===n&&o.height===r||(h.width=o.width=n,h.height=o.height=r);const c=o.getContext("2d"),u=h.getContext("2d"),d=15,f=.06*this.blur*.5;let g,p,b,_;for(c.putImageData(s,0,0),u.clearRect(0,0,n,r),_=-15;_<=d;_++)g=(Math.random()-.5)/4,p=_/d,b=f*p*n+g,u.globalAlpha=1-Math.abs(p),u.drawImage(o,b,g),c.drawImage(h,0,0),u.globalAlpha=1,u.clearRect(0,0,h.width,h.height);for(_=-15;_<=d;_++)g=(Math.random()-.5)/4,p=_/d,b=f*p*r+g,u.globalAlpha=1-Math.abs(p),u.drawImage(o,g,b),c.drawImage(h,0,0),u.globalAlpha=1,u.clearRect(0,0,h.width,h.height);e.drawImage(o,0,0);const v=e.getImageData(0,0,o.width,o.height);return c.globalAlpha=1,c.clearRect(0,0,o.width,o.height),v}sendUniformData(t,e){const s=this.chooseRightDelta();t.uniform2fv(e.uDelta,s)}isNeutralState(){return this.blur===0}chooseRightDelta(){let t=1;const e=[0,0];this.horizontal?this.aspectRatio>1&&(t=1/this.aspectRatio):this.aspectRatio<1&&(t=this.aspectRatio);const s=t*this.blur*.12;return this.horizontal?e[0]=s:e[1]=s,e}}A(ku,"type","Blur"),A(ku,"defaults",{blur:0}),A(ku,"uniformLocations",["uDelta"]),
|
|
172
|
+
`}applyTo(t){Au(t)?(this.aspectRatio=t.sourceWidth/t.sourceHeight,t.passes++,this._setupFrameBuffer(t),this.horizontal=!0,this.applyToWebGL(t),this._swapTextures(t),this._setupFrameBuffer(t),this.horizontal=!1,this.applyToWebGL(t),this._swapTextures(t)):this.applyTo2d(t)}applyTo2d(t){t.imageData=this.simpleBlur(t)}simpleBlur(t){let{ctx:e,imageData:s,filterBackend:{resources:i}}=t;const{width:n,height:r}=s;i.blurLayer1||(i.blurLayer1=ms(),i.blurLayer2=ms());const o=i.blurLayer1,h=i.blurLayer2;o.width===n&&o.height===r||(h.width=o.width=n,h.height=o.height=r);const c=o.getContext("2d"),u=h.getContext("2d"),d=15,f=.06*this.blur*.5;let g,p,b,_;for(c.putImageData(s,0,0),u.clearRect(0,0,n,r),_=-15;_<=d;_++)g=(Math.random()-.5)/4,p=_/d,b=f*p*n+g,u.globalAlpha=1-Math.abs(p),u.drawImage(o,b,g),c.drawImage(h,0,0),u.globalAlpha=1,u.clearRect(0,0,h.width,h.height);for(_=-15;_<=d;_++)g=(Math.random()-.5)/4,p=_/d,b=f*p*r+g,u.globalAlpha=1-Math.abs(p),u.drawImage(o,g,b),c.drawImage(h,0,0),u.globalAlpha=1,u.clearRect(0,0,h.width,h.height);e.drawImage(o,0,0);const v=e.getImageData(0,0,o.width,o.height);return c.globalAlpha=1,c.clearRect(0,0,o.width,o.height),v}sendUniformData(t,e){const s=this.chooseRightDelta();t.uniform2fv(e.uDelta,s)}isNeutralState(){return this.blur===0}chooseRightDelta(){let t=1;const e=[0,0];this.horizontal?this.aspectRatio>1&&(t=1/this.aspectRatio):this.aspectRatio<1&&(t=this.aspectRatio);const s=t*this.blur*.12;return this.horizontal?e[0]=s:e[1]=s,e}}A(ku,"type","Blur"),A(ku,"defaults",{blur:0}),A(ku,"uniformLocations",["uDelta"]),N.setClass(ku);class Mu extends $t{getFragmentSource(){return`
|
|
173
173
|
precision highp float;
|
|
174
174
|
uniform sampler2D uTexture;
|
|
175
175
|
uniform float uBrightness;
|
|
@@ -179,7 +179,7 @@ Resulting to default behavior: removing object from previous canvas and adding t
|
|
|
179
179
|
color.rgb += uBrightness;
|
|
180
180
|
gl_FragColor = color;
|
|
181
181
|
}
|
|
182
|
-
`}applyTo2d(t){let{imageData:{data:e}}=t;const s=Math.round(255*this.brightness);for(let i=0;i<e.length;i+=4)e[i]+=s,e[i+1]+=s,e[i+2]+=s}isNeutralState(){return this.brightness===0}sendUniformData(t,e){t.uniform1f(e.uBrightness,this.brightness)}}A(Mu,"type","Brightness"),A(Mu,"defaults",{brightness:0}),A(Mu,"uniformLocations",["uBrightness"]),
|
|
182
|
+
`}applyTo2d(t){let{imageData:{data:e}}=t;const s=Math.round(255*this.brightness);for(let i=0;i<e.length;i+=4)e[i]+=s,e[i+1]+=s,e[i+2]+=s}isNeutralState(){return this.brightness===0}sendUniformData(t,e){t.uniform1f(e.uBrightness,this.brightness)}}A(Mu,"type","Brightness"),A(Mu,"defaults",{brightness:0}),A(Mu,"uniformLocations",["uBrightness"]),N.setClass(Mu);const X0={matrix:[1,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,1,0],colorsOnly:!0};class na extends $t{getFragmentSource(){return`
|
|
183
183
|
precision highp float;
|
|
184
184
|
uniform sampler2D uTexture;
|
|
185
185
|
varying vec2 vTexCoord;
|
|
@@ -190,7 +190,7 @@ Resulting to default behavior: removing object from previous canvas and adding t
|
|
|
190
190
|
color *= uColorMatrix;
|
|
191
191
|
color += uConstants;
|
|
192
192
|
gl_FragColor = color;
|
|
193
|
-
}`}applyTo2d(t){const e=t.imageData.data,s=this.matrix,i=this.colorsOnly;for(let n=0;n<e.length;n+=4){const r=e[n],o=e[n+1],h=e[n+2];if(e[n]=r*s[0]+o*s[1]+h*s[2]+255*s[4],e[n+1]=r*s[5]+o*s[6]+h*s[7]+255*s[9],e[n+2]=r*s[10]+o*s[11]+h*s[12]+255*s[14],!i){const c=e[n+3];e[n]+=c*s[3],e[n+1]+=c*s[8],e[n+2]+=c*s[13],e[n+3]=r*s[15]+o*s[16]+h*s[17]+c*s[18]+255*s[19]}}}sendUniformData(t,e){const s=this.matrix,i=[s[0],s[1],s[2],s[3],s[5],s[6],s[7],s[8],s[10],s[11],s[12],s[13],s[15],s[16],s[17],s[18]],n=[s[4],s[9],s[14],s[19]];t.uniformMatrix4fv(e.uColorMatrix,!1,i),t.uniform4fv(e.uConstants,n)}toObject(){return T(T({},super.toObject()),{},{matrix:[...this.matrix]})}}function Er(a,t){var e;const s=(A(e=class extends na{toObject(){return{type:this.type,colorsOnly:this.colorsOnly}}},"type",a),A(e,"defaults",{colorsOnly:!1,matrix:t}),e);return
|
|
193
|
+
}`}applyTo2d(t){const e=t.imageData.data,s=this.matrix,i=this.colorsOnly;for(let n=0;n<e.length;n+=4){const r=e[n],o=e[n+1],h=e[n+2];if(e[n]=r*s[0]+o*s[1]+h*s[2]+255*s[4],e[n+1]=r*s[5]+o*s[6]+h*s[7]+255*s[9],e[n+2]=r*s[10]+o*s[11]+h*s[12]+255*s[14],!i){const c=e[n+3];e[n]+=c*s[3],e[n+1]+=c*s[8],e[n+2]+=c*s[13],e[n+3]=r*s[15]+o*s[16]+h*s[17]+c*s[18]+255*s[19]}}}sendUniformData(t,e){const s=this.matrix,i=[s[0],s[1],s[2],s[3],s[5],s[6],s[7],s[8],s[10],s[11],s[12],s[13],s[15],s[16],s[17],s[18]],n=[s[4],s[9],s[14],s[19]];t.uniformMatrix4fv(e.uColorMatrix,!1,i),t.uniform4fv(e.uConstants,n)}toObject(){return T(T({},super.toObject()),{},{matrix:[...this.matrix]})}}function Er(a,t){var e;const s=(A(e=class extends na{toObject(){return{type:this.type,colorsOnly:this.colorsOnly}}},"type",a),A(e,"defaults",{colorsOnly:!1,matrix:t}),e);return N.setClass(s,a),s}A(na,"type","ColorMatrix"),A(na,"defaults",X0),A(na,"uniformLocations",["uColorMatrix","uConstants"]),N.setClass(na),Er("Brownie",[.5997,.34553,-.27082,0,.186,-.0377,.86095,.15059,0,-.1449,.24113,-.07441,.44972,0,-.02965,0,0,0,1,0]),Er("Vintage",[.62793,.32021,-.03965,0,.03784,.02578,.64411,.03259,0,.02926,.0466,-.08512,.52416,0,.02023,0,0,0,1,0]),Er("Kodachrome",[1.12855,-.39673,-.03992,0,.24991,-.16404,1.08352,-.05498,0,.09698,-.16786,-.56034,1.60148,0,.13972,0,0,0,1,0]),Er("Technicolor",[1.91252,-.85453,-.09155,0,.04624,-.30878,1.76589,-.10601,0,-.27589,-.2311,-.75018,1.84759,0,.12137,0,0,0,1,0]),Er("Polaroid",[1.438,-.062,-.062,0,0,-.122,1.378,-.122,0,0,-.016,-.016,1.483,0,0,0,0,0,1,0]),Er("Sepia",[.393,.769,.189,0,0,.349,.686,.168,0,0,.272,.534,.131,0,0,0,0,0,1,0]),Er("BlackWhite",[1.5,1.5,1.5,0,-1,1.5,1.5,1.5,0,-1,1.5,1.5,1.5,0,-1,0,0,0,1,0]);class W0 extends $t{constructor(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};super(t),this.subFilters=t.subFilters||[]}applyTo(t){Au(t)&&(t.passes+=this.subFilters.length-1),this.subFilters.forEach(e=>{e.applyTo(t)})}toObject(){return{type:this.type,subFilters:this.subFilters.map(t=>t.toObject())}}isNeutralState(){return!this.subFilters.some(t=>!t.isNeutralState())}static fromObject(t,e){return Promise.all((t.subFilters||[]).map(s=>N.getClass(s.type).fromObject(s,e))).then(s=>new this({subFilters:s}))}}A(W0,"type","Composed"),N.setClass(W0);class Pu extends $t{getFragmentSource(){return`
|
|
194
194
|
precision highp float;
|
|
195
195
|
uniform sampler2D uTexture;
|
|
196
196
|
uniform float uContrast;
|
|
@@ -200,7 +200,7 @@ Resulting to default behavior: removing object from previous canvas and adding t
|
|
|
200
200
|
float contrastF = 1.015 * (uContrast + 1.0) / (1.0 * (1.015 - uContrast));
|
|
201
201
|
color.rgb = contrastF * (color.rgb - 0.5) + 0.5;
|
|
202
202
|
gl_FragColor = color;
|
|
203
|
-
}`}isNeutralState(){return this.contrast===0}applyTo2d(t){let{imageData:{data:e}}=t;const s=Math.floor(255*this.contrast),i=259*(s+255)/(255*(259-s));for(let n=0;n<e.length;n+=4)e[n]=i*(e[n]-128)+128,e[n+1]=i*(e[n+1]-128)+128,e[n+2]=i*(e[n+2]-128)+128}sendUniformData(t,e){t.uniform1f(e.uContrast,this.contrast)}}A(Pu,"type","Contrast"),A(Pu,"defaults",{contrast:0}),A(Pu,"uniformLocations",["uContrast"]),
|
|
203
|
+
}`}isNeutralState(){return this.contrast===0}applyTo2d(t){let{imageData:{data:e}}=t;const s=Math.floor(255*this.contrast),i=259*(s+255)/(255*(259-s));for(let n=0;n<e.length;n+=4)e[n]=i*(e[n]-128)+128,e[n+1]=i*(e[n+1]-128)+128,e[n+2]=i*(e[n+2]-128)+128}sendUniformData(t,e){t.uniform1f(e.uContrast,this.contrast)}}A(Pu,"type","Contrast"),A(Pu,"defaults",{contrast:0}),A(Pu,"uniformLocations",["uContrast"]),N.setClass(Pu);const Ww={Convolute_3_1:`
|
|
204
204
|
precision highp float;
|
|
205
205
|
uniform sampler2D uTexture;
|
|
206
206
|
uniform float uMatrix[9];
|
|
@@ -344,7 +344,7 @@ Resulting to default behavior: removing object from previous canvas and adding t
|
|
|
344
344
|
gl_FragColor = color;
|
|
345
345
|
gl_FragColor.a = alpha;
|
|
346
346
|
}
|
|
347
|
-
`};class Du extends $t{getCacheKey(){return"".concat(this.type,"_").concat(Math.sqrt(this.matrix.length),"_").concat(this.opaque?1:0)}getFragmentSource(){return
|
|
347
|
+
`};class Du extends $t{getCacheKey(){return"".concat(this.type,"_").concat(Math.sqrt(this.matrix.length),"_").concat(this.opaque?1:0)}getFragmentSource(){return Ww[this.getCacheKey()]}applyTo2d(t){const e=t.imageData,s=e.data,i=this.matrix,n=Math.round(Math.sqrt(i.length)),r=Math.floor(n/2),o=e.width,h=e.height,c=t.ctx.createImageData(o,h),u=c.data,d=this.opaque?1:0;let f,g,p,b,_,v,x,C,S,k,M,E,P;for(M=0;M<h;M++)for(k=0;k<o;k++){for(_=4*(M*o+k),f=0,g=0,p=0,b=0,P=0;P<n;P++)for(E=0;E<n;E++)x=M+P-r,v=k+E-r,x<0||x>=h||v<0||v>=o||(C=4*(x*o+v),S=i[P*n+E],f+=s[C]*S,g+=s[C+1]*S,p+=s[C+2]*S,d||(b+=s[C+3]*S));u[_]=f,u[_+1]=g,u[_+2]=p,u[_+3]=d?s[_+3]:b}t.imageData=c}sendUniformData(t,e){t.uniform1fv(e.uMatrix,this.matrix)}toObject(){return T(T({},super.toObject()),{},{opaque:this.opaque,matrix:[...this.matrix]})}}A(Du,"type","Convolute"),A(Du,"defaults",{opaque:!1,matrix:[0,0,0,0,1,0,0,0,0]}),A(Du,"uniformLocations",["uMatrix","uOpaque","uHalfSize","uSize"]),N.setClass(Du);const U0="Gamma";class Ou extends $t{getFragmentSource(){return`
|
|
348
348
|
precision highp float;
|
|
349
349
|
uniform sampler2D uTexture;
|
|
350
350
|
uniform vec3 uGamma;
|
|
@@ -358,7 +358,7 @@ Resulting to default behavior: removing object from previous canvas and adding t
|
|
|
358
358
|
gl_FragColor = color;
|
|
359
359
|
gl_FragColor.rgb *= color.a;
|
|
360
360
|
}
|
|
361
|
-
`}constructor(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};super(t),this.gamma=t.gamma||this.constructor.defaults.gamma.concat()}applyTo2d(t){let{imageData:{data:e}}=t;const s=this.gamma,i=1/s[0],n=1/s[1],r=1/s[2];this.rgbValues||(this.rgbValues={r:new Uint8Array(256),g:new Uint8Array(256),b:new Uint8Array(256)});const o=this.rgbValues;for(let h=0;h<256;h++)o.r[h]=255*Math.pow(h/255,i),o.g[h]=255*Math.pow(h/255,n),o.b[h]=255*Math.pow(h/255,r);for(let h=0;h<e.length;h+=4)e[h]=o.r[e[h]],e[h+1]=o.g[e[h+1]],e[h+2]=o.b[e[h+2]]}sendUniformData(t,e){t.uniform3fv(e.uGamma,this.gamma)}isNeutralState(){const{gamma:t}=this;return t[0]===1&&t[1]===1&&t[2]===1}toObject(){return{type:U0,gamma:this.gamma.concat()}}}A(Ou,"type",U0),A(Ou,"defaults",{gamma:[1,1,1]}),A(Ou,"uniformLocations",["uGamma"]),
|
|
361
|
+
`}constructor(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};super(t),this.gamma=t.gamma||this.constructor.defaults.gamma.concat()}applyTo2d(t){let{imageData:{data:e}}=t;const s=this.gamma,i=1/s[0],n=1/s[1],r=1/s[2];this.rgbValues||(this.rgbValues={r:new Uint8Array(256),g:new Uint8Array(256),b:new Uint8Array(256)});const o=this.rgbValues;for(let h=0;h<256;h++)o.r[h]=255*Math.pow(h/255,i),o.g[h]=255*Math.pow(h/255,n),o.b[h]=255*Math.pow(h/255,r);for(let h=0;h<e.length;h+=4)e[h]=o.r[e[h]],e[h+1]=o.g[e[h+1]],e[h+2]=o.b[e[h+2]]}sendUniformData(t,e){t.uniform3fv(e.uGamma,this.gamma)}isNeutralState(){const{gamma:t}=this;return t[0]===1&&t[1]===1&&t[2]===1}toObject(){return{type:U0,gamma:this.gamma.concat()}}}A(Ou,"type",U0),A(Ou,"defaults",{gamma:[1,1,1]}),A(Ou,"uniformLocations",["uGamma"]),N.setClass(Ou);const Uw={average:`
|
|
362
362
|
precision highp float;
|
|
363
363
|
uniform sampler2D uTexture;
|
|
364
364
|
varying vec2 vTexCoord;
|
|
@@ -387,7 +387,7 @@ Resulting to default behavior: removing object from previous canvas and adding t
|
|
|
387
387
|
float average = 0.21 * col.r + 0.72 * col.g + 0.07 * col.b;
|
|
388
388
|
gl_FragColor = vec4(average, average, average, col.a);
|
|
389
389
|
}
|
|
390
|
-
`};class Ru extends $t{applyTo2d(t){let{imageData:{data:e}}=t;for(let s,i=0;i<e.length;i+=4){const n=e[i],r=e[i+1],o=e[i+2];switch(this.mode){case"average":s=(n+r+o)/3;break;case"lightness":s=(Math.min(n,r,o)+Math.max(n,r,o))/2;break;case"luminosity":s=.21*n+.72*r+.07*o}e[i+2]=e[i+1]=e[i]=s}}getCacheKey(){return"".concat(this.type,"_").concat(this.mode)}getFragmentSource(){return
|
|
390
|
+
`};class Ru extends $t{applyTo2d(t){let{imageData:{data:e}}=t;for(let s,i=0;i<e.length;i+=4){const n=e[i],r=e[i+1],o=e[i+2];switch(this.mode){case"average":s=(n+r+o)/3;break;case"lightness":s=(Math.min(n,r,o)+Math.max(n,r,o))/2;break;case"luminosity":s=.21*n+.72*r+.07*o}e[i+2]=e[i+1]=e[i]=s}}getCacheKey(){return"".concat(this.type,"_").concat(this.mode)}getFragmentSource(){return Uw[this.mode]}sendUniformData(t,e){t.uniform1i(e.uMode,1)}isNeutralState(){return!1}}A(Ru,"type","Grayscale"),A(Ru,"defaults",{mode:"average"}),A(Ru,"uniformLocations",["uMode"]),N.setClass(Ru);const Yw=T(T({},X0),{},{rotation:0});class ng extends na{calculateMatrix(){const t=this.rotation*Math.PI,e=Ds(t),s=Os(t),i=1/3,n=Math.sqrt(i)*s,r=1-e;this.matrix=[e+r/3,i*r-n,i*r+n,0,0,i*r+n,e+i*r,i*r-n,0,0,i*r-n,i*r+n,e+i*r,0,0,0,0,0,1,0]}isNeutralState(){return this.rotation===0}applyTo(t){this.calculateMatrix(),super.applyTo(t)}toObject(){return{type:this.type,rotation:this.rotation}}}A(ng,"type","HueRotation"),A(ng,"defaults",Yw),N.setClass(ng);class Lu extends $t{applyTo2d(t){let{imageData:{data:e}}=t;for(let s=0;s<e.length;s+=4)e[s]=255-e[s],e[s+1]=255-e[s+1],e[s+2]=255-e[s+2],this.alpha&&(e[s+3]=255-e[s+3])}getFragmentSource(){return`
|
|
391
391
|
precision highp float;
|
|
392
392
|
uniform sampler2D uTexture;
|
|
393
393
|
uniform int uInvert;
|
|
@@ -405,7 +405,7 @@ Resulting to default behavior: removing object from previous canvas and adding t
|
|
|
405
405
|
gl_FragColor = color;
|
|
406
406
|
}
|
|
407
407
|
}
|
|
408
|
-
`}isNeutralState(){return!this.invert}sendUniformData(t,e){t.uniform1i(e.uInvert,Number(this.invert)),t.uniform1i(e.uAlpha,Number(this.alpha))}}A(Lu,"type","Invert"),A(Lu,"defaults",{alpha:!1,invert:!0}),A(Lu,"uniformLocations",["uInvert","uAlpha"]),
|
|
408
|
+
`}isNeutralState(){return!this.invert}sendUniformData(t,e){t.uniform1i(e.uInvert,Number(this.invert)),t.uniform1i(e.uAlpha,Number(this.alpha))}}A(Lu,"type","Invert"),A(Lu,"defaults",{alpha:!1,invert:!0}),A(Lu,"uniformLocations",["uInvert","uAlpha"]),N.setClass(Lu);class Fu extends $t{getFragmentSource(){return`
|
|
409
409
|
precision highp float;
|
|
410
410
|
uniform sampler2D uTexture;
|
|
411
411
|
uniform float uStepH;
|
|
@@ -420,7 +420,7 @@ Resulting to default behavior: removing object from previous canvas and adding t
|
|
|
420
420
|
color.rgb += (0.5 - rand(vTexCoord, uSeed, 0.1 / uStepH)) * uNoise;
|
|
421
421
|
gl_FragColor = color;
|
|
422
422
|
}
|
|
423
|
-
`}applyTo2d(t){let{imageData:{data:e}}=t;const s=this.noise;for(let i=0;i<e.length;i+=4){const n=(.5-Math.random())*s;e[i]+=n,e[i+1]+=n,e[i+2]+=n}}sendUniformData(t,e){t.uniform1f(e.uNoise,this.noise/255),t.uniform1f(e.uSeed,Math.random())}isNeutralState(){return this.noise===0}}A(Fu,"type","Noise"),A(Fu,"defaults",{noise:0}),A(Fu,"uniformLocations",["uNoise","uSeed"]),
|
|
423
|
+
`}applyTo2d(t){let{imageData:{data:e}}=t;const s=this.noise;for(let i=0;i<e.length;i+=4){const n=(.5-Math.random())*s;e[i]+=n,e[i+1]+=n,e[i+2]+=n}}sendUniformData(t,e){t.uniform1f(e.uNoise,this.noise/255),t.uniform1f(e.uSeed,Math.random())}isNeutralState(){return this.noise===0}}A(Fu,"type","Noise"),A(Fu,"defaults",{noise:0}),A(Fu,"uniformLocations",["uNoise","uSeed"]),N.setClass(Fu);class Iu extends $t{applyTo2d(t){let{imageData:{data:e,width:s,height:i}}=t;for(let n=0;n<i;n+=this.blocksize)for(let r=0;r<s;r+=this.blocksize){const o=4*n*s+4*r,h=e[o],c=e[o+1],u=e[o+2],d=e[o+3];for(let f=n;f<Math.min(n+this.blocksize,i);f++)for(let g=r;g<Math.min(r+this.blocksize,s);g++){const p=4*f*s+4*g;e[p]=h,e[p+1]=c,e[p+2]=u,e[p+3]=d}}}isNeutralState(){return this.blocksize===1}getFragmentSource(){return`
|
|
424
424
|
precision highp float;
|
|
425
425
|
uniform sampler2D uTexture;
|
|
426
426
|
uniform float uBlocksize;
|
|
@@ -438,7 +438,7 @@ Resulting to default behavior: removing object from previous canvas and adding t
|
|
|
438
438
|
vec4 color = texture2D(uTexture, squareCoords);
|
|
439
439
|
gl_FragColor = color;
|
|
440
440
|
}
|
|
441
|
-
`}sendUniformData(t,e){t.uniform1f(e.uBlocksize,this.blocksize)}}A(Iu,"type","Pixelate"),A(Iu,"defaults",{blocksize:4}),A(Iu,"uniformLocations",["uBlocksize"]),
|
|
441
|
+
`}sendUniformData(t,e){t.uniform1f(e.uBlocksize,this.blocksize)}}A(Iu,"type","Pixelate"),A(Iu,"defaults",{blocksize:4}),A(Iu,"uniformLocations",["uBlocksize"]),N.setClass(Iu);class Nu extends $t{getFragmentSource(){return`
|
|
442
442
|
precision highp float;
|
|
443
443
|
uniform sampler2D uTexture;
|
|
444
444
|
uniform vec4 uLow;
|
|
@@ -450,7 +450,7 @@ void main() {
|
|
|
450
450
|
gl_FragColor.a = 0.0;
|
|
451
451
|
}
|
|
452
452
|
}
|
|
453
|
-
`}applyTo2d(t){let{imageData:{data:e}}=t;const s=255*this.distance,i=new gt(this.color).getSource(),n=[i[0]-s,i[1]-s,i[2]-s],r=[i[0]+s,i[1]+s,i[2]+s];for(let o=0;o<e.length;o+=4){const h=e[o],c=e[o+1],u=e[o+2];h>n[0]&&c>n[1]&&u>n[2]&&h<r[0]&&c<r[1]&&u<r[2]&&(e[o+3]=0)}}sendUniformData(t,e){const s=new gt(this.color).getSource(),i=this.distance,n=[0+s[0]/255-i,0+s[1]/255-i,0+s[2]/255-i,1],r=[s[0]/255+i,s[1]/255+i,s[2]/255+i,1];t.uniform4fv(e.uLow,n),t.uniform4fv(e.uHigh,r)}}A(Nu,"type","RemoveColor"),A(Nu,"defaults",{color:"#FFFFFF",distance:.02,useAlpha:!1}),A(Nu,"uniformLocations",["uLow","uHigh"]),
|
|
453
|
+
`}applyTo2d(t){let{imageData:{data:e}}=t;const s=255*this.distance,i=new gt(this.color).getSource(),n=[i[0]-s,i[1]-s,i[2]-s],r=[i[0]+s,i[1]+s,i[2]+s];for(let o=0;o<e.length;o+=4){const h=e[o],c=e[o+1],u=e[o+2];h>n[0]&&c>n[1]&&u>n[2]&&h<r[0]&&c<r[1]&&u<r[2]&&(e[o+3]=0)}}sendUniformData(t,e){const s=new gt(this.color).getSource(),i=this.distance,n=[0+s[0]/255-i,0+s[1]/255-i,0+s[2]/255-i,1],r=[s[0]/255+i,s[1]/255+i,s[2]/255+i,1];t.uniform4fv(e.uLow,n),t.uniform4fv(e.uHigh,r)}}A(Nu,"type","RemoveColor"),A(Nu,"defaults",{color:"#FFFFFF",distance:.02,useAlpha:!1}),A(Nu,"uniformLocations",["uLow","uHigh"]),N.setClass(Nu);class ju extends $t{sendUniformData(t,e){t.uniform2fv(e.uDelta,this.horizontal?[1/this.width,0]:[0,1/this.height]),t.uniform1fv(e.uTaps,this.taps)}getFilterWindow(){const t=this.tempScale;return Math.ceil(this.lanczosLobes/t)}getCacheKey(){const t=this.getFilterWindow();return"".concat(this.type,"_").concat(t)}getFragmentSource(){const t=this.getFilterWindow();return this.generateShader(t)}getTaps(){const t=this.lanczosCreate(this.lanczosLobes),e=this.tempScale,s=this.getFilterWindow(),i=new Array(s);for(let n=1;n<=s;n++)i[n-1]=t(n*e);return i}generateShader(t){const e=new Array(t);for(let s=1;s<=t;s++)e[s-1]="".concat(s,".0 * uDelta");return`
|
|
454
454
|
precision highp float;
|
|
455
455
|
uniform sampler2D uTexture;
|
|
456
456
|
uniform vec2 uDelta;
|
|
@@ -466,7 +466,7 @@ void main() {
|
|
|
466
466
|
`),`
|
|
467
467
|
gl_FragColor = color / sum;
|
|
468
468
|
}
|
|
469
|
-
`)}applyToForWebgl(t){t.passes++,this.width=t.sourceWidth,this.horizontal=!0,this.dW=Math.round(this.width*this.scaleX),this.dH=t.sourceHeight,this.tempScale=this.dW/this.width,this.taps=this.getTaps(),t.destinationWidth=this.dW,super.applyTo(t),t.sourceWidth=t.destinationWidth,this.height=t.sourceHeight,this.horizontal=!1,this.dH=Math.round(this.height*this.scaleY),this.tempScale=this.dH/this.height,this.taps=this.getTaps(),t.destinationHeight=this.dH,super.applyTo(t),t.sourceHeight=t.destinationHeight}applyTo(t){Au(t)?this.applyToForWebgl(t):this.applyTo2d(t)}isNeutralState(){return this.scaleX===1&&this.scaleY===1}lanczosCreate(t){return e=>{if(e>=t||e<=-t)return 0;if(e<11920929e-14&&e>-11920929e-14)return 1;const s=(e*=Math.PI)/t;return Math.sin(e)/e*Math.sin(s)/s}}applyTo2d(t){const e=t.imageData,s=this.scaleX,i=this.scaleY;this.rcpScaleX=1/s,this.rcpScaleY=1/i;const n=e.width,r=e.height,o=Math.round(n*s),h=Math.round(r*i);let c;c=this.resizeType==="sliceHack"?this.sliceByTwo(t,n,r,o,h):this.resizeType==="hermite"?this.hermiteFastResize(t,n,r,o,h):this.resizeType==="bilinear"?this.bilinearFiltering(t,n,r,o,h):this.resizeType==="lanczos"?this.lanczosResize(t,n,r,o,h):new ImageData(o,h),t.imageData=c}sliceByTwo(t,e,s,i,n){const r=t.imageData,o=.5;let h=!1,c=!1,u=e*o,d=s*o;const f=t.filterBackend.resources;let g=0,p=0;const b=e;let _=0;f.sliceByTwo||(f.sliceByTwo=ms());const v=f.sliceByTwo;(v.width<1.5*e||v.height<s)&&(v.width=1.5*e,v.height=s);const x=v.getContext("2d");for(x.clearRect(0,0,1.5*e,s),x.putImageData(r,0,0),i=Math.floor(i),n=Math.floor(n);!h||!c;)e=u,s=d,i<Math.floor(u*o)?u=Math.floor(u*o):(u=i,h=!0),n<Math.floor(d*o)?d=Math.floor(d*o):(d=n,c=!0),x.drawImage(v,g,p,e,s,b,_,u,d),g=b,p=_,_+=d;return x.getImageData(g,p,i,n)}lanczosResize(t,e,s,i,n){const r=t.imageData.data,o=t.ctx.createImageData(i,n),h=o.data,c=this.lanczosCreate(this.lanczosLobes),u=this.rcpScaleX,d=this.rcpScaleY,f=2/this.rcpScaleX,g=2/this.rcpScaleY,p=Math.ceil(u*this.lanczosLobes/2),b=Math.ceil(d*this.lanczosLobes/2),_={},v={x:0,y:0},x={x:0,y:0};return function C(S){let
|
|
469
|
+
`)}applyToForWebgl(t){t.passes++,this.width=t.sourceWidth,this.horizontal=!0,this.dW=Math.round(this.width*this.scaleX),this.dH=t.sourceHeight,this.tempScale=this.dW/this.width,this.taps=this.getTaps(),t.destinationWidth=this.dW,super.applyTo(t),t.sourceWidth=t.destinationWidth,this.height=t.sourceHeight,this.horizontal=!1,this.dH=Math.round(this.height*this.scaleY),this.tempScale=this.dH/this.height,this.taps=this.getTaps(),t.destinationHeight=this.dH,super.applyTo(t),t.sourceHeight=t.destinationHeight}applyTo(t){Au(t)?this.applyToForWebgl(t):this.applyTo2d(t)}isNeutralState(){return this.scaleX===1&&this.scaleY===1}lanczosCreate(t){return e=>{if(e>=t||e<=-t)return 0;if(e<11920929e-14&&e>-11920929e-14)return 1;const s=(e*=Math.PI)/t;return Math.sin(e)/e*Math.sin(s)/s}}applyTo2d(t){const e=t.imageData,s=this.scaleX,i=this.scaleY;this.rcpScaleX=1/s,this.rcpScaleY=1/i;const n=e.width,r=e.height,o=Math.round(n*s),h=Math.round(r*i);let c;c=this.resizeType==="sliceHack"?this.sliceByTwo(t,n,r,o,h):this.resizeType==="hermite"?this.hermiteFastResize(t,n,r,o,h):this.resizeType==="bilinear"?this.bilinearFiltering(t,n,r,o,h):this.resizeType==="lanczos"?this.lanczosResize(t,n,r,o,h):new ImageData(o,h),t.imageData=c}sliceByTwo(t,e,s,i,n){const r=t.imageData,o=.5;let h=!1,c=!1,u=e*o,d=s*o;const f=t.filterBackend.resources;let g=0,p=0;const b=e;let _=0;f.sliceByTwo||(f.sliceByTwo=ms());const v=f.sliceByTwo;(v.width<1.5*e||v.height<s)&&(v.width=1.5*e,v.height=s);const x=v.getContext("2d");for(x.clearRect(0,0,1.5*e,s),x.putImageData(r,0,0),i=Math.floor(i),n=Math.floor(n);!h||!c;)e=u,s=d,i<Math.floor(u*o)?u=Math.floor(u*o):(u=i,h=!0),n<Math.floor(d*o)?d=Math.floor(d*o):(d=n,c=!0),x.drawImage(v,g,p,e,s,b,_,u,d),g=b,p=_,_+=d;return x.getImageData(g,p,i,n)}lanczosResize(t,e,s,i,n){const r=t.imageData.data,o=t.ctx.createImageData(i,n),h=o.data,c=this.lanczosCreate(this.lanczosLobes),u=this.rcpScaleX,d=this.rcpScaleY,f=2/this.rcpScaleX,g=2/this.rcpScaleY,p=Math.ceil(u*this.lanczosLobes/2),b=Math.ceil(d*this.lanczosLobes/2),_={},v={x:0,y:0},x={x:0,y:0};return function C(S){let k,M,E,P,O,L,R,U,z,V,at;for(v.x=(S+.5)*u,x.x=Math.floor(v.x),k=0;k<n;k++){for(v.y=(k+.5)*d,x.y=Math.floor(v.y),O=0,L=0,R=0,U=0,z=0,M=x.x-p;M<=x.x+p;M++)if(!(M<0||M>=e)){V=Math.floor(1e3*Math.abs(M-v.x)),_[V]||(_[V]={});for(let F=x.y-b;F<=x.y+b;F++)F<0||F>=s||(at=Math.floor(1e3*Math.abs(F-v.y)),_[V][at]||(_[V][at]=c(Math.sqrt(Math.pow(V*f,2)+Math.pow(at*g,2))/1e3)),E=_[V][at],E>0&&(P=4*(F*e+M),O+=E,L+=E*r[P],R+=E*r[P+1],U+=E*r[P+2],z+=E*r[P+3]))}P=4*(k*i+S),h[P]=L/O,h[P+1]=R/O,h[P+2]=U/O,h[P+3]=z/O}return++S<i?C(S):o}(0)}bilinearFiltering(t,e,s,i,n){let r,o,h,c,u,d,f,g,p,b,_,v,x,C=0;const S=this.rcpScaleX,k=this.rcpScaleY,M=4*(e-1),E=t.imageData.data,P=t.ctx.createImageData(i,n),O=P.data;for(f=0;f<n;f++)for(g=0;g<i;g++)for(u=Math.floor(S*g),d=Math.floor(k*f),p=S*g-u,b=k*f-d,x=4*(d*e+u),_=0;_<4;_++)r=E[x+_],o=E[x+4+_],h=E[x+M+_],c=E[x+M+4+_],v=r*(1-p)*(1-b)+o*p*(1-b)+h*b*(1-p)+c*p*b,O[C++]=v;return P}hermiteFastResize(t,e,s,i,n){const r=this.rcpScaleX,o=this.rcpScaleY,h=Math.ceil(r/2),c=Math.ceil(o/2),u=t.imageData.data,d=t.ctx.createImageData(i,n),f=d.data;for(let g=0;g<n;g++)for(let p=0;p<i;p++){const b=4*(p+g*i);let _=0,v=0,x=0,C=0,S=0,k=0,M=0;const E=(g+.5)*o;for(let P=Math.floor(g*o);P<(g+1)*o;P++){const O=Math.abs(E-(P+.5))/c,L=(p+.5)*r,R=O*O;for(let U=Math.floor(p*r);U<(p+1)*r;U++){let z=Math.abs(L-(U+.5))/h;const V=Math.sqrt(R+z*z);V>1&&V<-1||(_=2*V*V*V-3*V*V+1,_>0&&(z=4*(U+P*e),M+=_*u[z+3],x+=_,u[z+3]<255&&(_=_*u[z+3]/250),C+=_*u[z],S+=_*u[z+1],k+=_*u[z+2],v+=_))}}f[b]=C/v,f[b+1]=S/v,f[b+2]=k/v,f[b+3]=M/x}return d}}A(ju,"type","Resize"),A(ju,"defaults",{resizeType:"hermite",scaleX:1,scaleY:1,lanczosLobes:3}),A(ju,"uniformLocations",["uDelta","uTaps"]),N.setClass(ju);class Bu extends $t{getFragmentSource(){return`
|
|
470
470
|
precision highp float;
|
|
471
471
|
uniform sampler2D uTexture;
|
|
472
472
|
uniform float uSaturation;
|
|
@@ -480,7 +480,7 @@ void main() {
|
|
|
480
480
|
color.b += rgbMax != color.b ? (rgbMax - color.b) * uSaturation : 0.00;
|
|
481
481
|
gl_FragColor = color;
|
|
482
482
|
}
|
|
483
|
-
`}applyTo2d(t){let{imageData:{data:e}}=t;const s=-this.saturation;for(let i=0;i<e.length;i+=4){const n=e[i],r=e[i+1],o=e[i+2],h=Math.max(n,r,o);e[i]+=h!==n?(h-n)*s:0,e[i+1]+=h!==r?(h-r)*s:0,e[i+2]+=h!==o?(h-o)*s:0}}sendUniformData(t,e){t.uniform1f(e.uSaturation,-this.saturation)}isNeutralState(){return this.saturation===0}}A(Bu,"type","Saturation"),A(Bu,"defaults",{saturation:0}),A(Bu,"uniformLocations",["uSaturation"]),
|
|
483
|
+
`}applyTo2d(t){let{imageData:{data:e}}=t;const s=-this.saturation;for(let i=0;i<e.length;i+=4){const n=e[i],r=e[i+1],o=e[i+2],h=Math.max(n,r,o);e[i]+=h!==n?(h-n)*s:0,e[i+1]+=h!==r?(h-r)*s:0,e[i+2]+=h!==o?(h-o)*s:0}}sendUniformData(t,e){t.uniform1f(e.uSaturation,-this.saturation)}isNeutralState(){return this.saturation===0}}A(Bu,"type","Saturation"),A(Bu,"defaults",{saturation:0}),A(Bu,"uniformLocations",["uSaturation"]),N.setClass(Bu);class Hu extends $t{getFragmentSource(){return`
|
|
484
484
|
precision highp float;
|
|
485
485
|
uniform sampler2D uTexture;
|
|
486
486
|
uniform float uVibrance;
|
|
@@ -495,15 +495,15 @@ void main() {
|
|
|
495
495
|
color.b += max != color.b ? (max - color.b) * amt : 0.00;
|
|
496
496
|
gl_FragColor = color;
|
|
497
497
|
}
|
|
498
|
-
`}applyTo2d(t){let{imageData:{data:e}}=t;const s=-this.vibrance;for(let i=0;i<e.length;i+=4){const n=e[i],r=e[i+1],o=e[i+2],h=Math.max(n,r,o),c=(n+r+o)/3,u=2*Math.abs(h-c)/255*s;e[i]+=h!==n?(h-n)*u:0,e[i+1]+=h!==r?(h-r)*u:0,e[i+2]+=h!==o?(h-o)*u:0}}sendUniformData(t,e){t.uniform1f(e.uVibrance,-this.vibrance)}isNeutralState(){return this.vibrance===0}}A(Hu,"type","Vibrance"),A(Hu,"defaults",{vibrance:0}),A(Hu,"uniformLocations",["uVibrance"]),H.setClass(Hu);const Ww="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 Uw(a){return new URL(Object.assign({"../assets/close.svg":Ww})[`../assets/${a}`],typeof document>"u"&&typeof location>"u"?require("url").pathToFileURL(__filename).href:typeof document>"u"?location.href:_t&&_t.tagName.toUpperCase()==="SCRIPT"&&_t.src||new URL("pdf-canvas.umd.js",document.baseURI).href).href}function Yw(a){return new Promise((t,e)=>{const s=window.URL.createObjectURL(a),i=new Image;i.src=s,i.addEventListener("load",async()=>{window.URL.revokeObjectURL(s),t(await $w(i))}),i.addEventListener("error",n=>{window.URL.revokeObjectURL(s),e(n)})})}function $w(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 Y0=null;function qw(){const a=document.createElement("div");a.style.width="1in",document.body.append(a);const t=a.offsetWidth;return a.remove(),t}function Kw(){const a=Y0??qw();return Y0=a,a/72}function Qw(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 vs=new Map;function Jw(a){const t=new Uf(a);return vs.set(a,t),t}function Zw(a,t){const e=Date.now();return{PDFId:`${a.name}-${e}`,name:a.name.replace(/.pdf/,""),updateDate:e,PDFBase64:t}}function tx(a,t){const e=a.getViewport({scale:t}),s=document.createElement("canvas"),i=s.getContext("2d"),n=Kw()/window.devicePixelRatio;s.width=Math.floor(e.width*n),s.height=Math.floor(e.height*n);const r={canvasContext:i,viewport:e,transform:[n,0,0,n,0,0]},o=a.render(r);return{canvas:s,renderTask:o}}async function ex(a,t,e){const s=a||Uw("close.svg"),{objects:i,options:n}=await Lw(s),r=i.filter(h=>h!==null),o=$_.groupSVGElements(r,n);return r.forEach(h=>{h.stroke=t}),o.hoverCursor="pointer",o.stroke=`${t}-${e}`,o}function sx(a,t){if(!vs.get(a))return;const s=1/3,i=hx(t,s);q0(a,i,s)}async function ix(a,t){const e=await Yw(t),s=Date.now(),n={PDFId:`${t.name}${s}`,name:t.name.replace(/.png|.jpg|.jpeg/,""),updateDate:s,PDFBase64:e};return $0(a,{url:e}),{...n,pages:1}}async function $0(a,{url:t,scale:e=.5}){if(!vs.get(a))return;const i=await be.fromURL(t);i.scale(e),q0(a,i,e)}function q0(a,t,e){const s=vs.get(a);s&&(s.setWidth(t.width*e),s.setHeight(t.height*e),s.backgroundImage=t,s.renderAll())}function Bh(a,t){if(!t)return;const{oCoords:e}=a;if(!e)return;const{x:s,y:i}=e.tl.touchCorner.tl,{height:n,width:r,scaleY:o,scaleX:h}=t;t.top=i-n*o/2,t.left=s-r*h/2,t.setCoords()}function nx(a,t,e){!e||!a||(e.scale(1/t),Bh(a,e))}function rx(a,t,e){a&&(a.borderScaleFactor=1/t,a.cornerSize=6*(1/t),a.touchCornerSize=24*(1/t),a.cornerStrokeColor=e.stroke,a.setCoords())}function ox(a){const t=vs.get(a);t&&(t.discardActiveObject(),t.renderAll())}function ax(a){const t=vs.get(a);t&&(t.clear(),vs.delete(a))}function hx(a,t){return new be(a,{scaleX:t,scaleY:t})}function K0(a,t){if(!t)return;const{left:e,top:s,scaleX:i,scaleY:n,width:r,height:o}=a,h=t.x*r*i,c=t.y*o*n;a.set({left:e-h,top:s-c})}var Hh={};Hh.d=(a,t)=>{for(var e in t)Hh.o(t,e)&&!Hh.o(a,e)&&Object.defineProperty(a,e,{enumerable:!0,get:t[e]})},Hh.o=(a,t)=>Object.prototype.hasOwnProperty.call(a,t);var Q=globalThis.pdfjsLib={};Hh.d(Q,{AbortException:()=>Rn,AnnotationEditorLayer:()=>Gg,AnnotationEditorParamsType:()=>at,AnnotationEditorType:()=>tt,AnnotationEditorUIManager:()=>Mr,AnnotationLayer:()=>iC,AnnotationMode:()=>Dn,ColorPicker:()=>rd,DOMSVGFactory:()=>Dg,DrawLayer:()=>zg,FeatureTest:()=>Re,GlobalWorkerOptions:()=>Vi,ImageKind:()=>Gu,InvalidPDFException:()=>hg,MissingPDFException:()=>zh,OPS:()=>Hs,OutputScale:()=>bg,PDFDataRangeTransport:()=>Db,PDFDateString:()=>pg,PDFWorker:()=>aa,PasswordResponses:()=>dx,PermissionFlag:()=>ux,PixelsPerInch:()=>Ln,RenderingCancelledException:()=>fg,TextLayer:()=>$h,TouchManager:()=>Qu,UnexpectedResponseException:()=>Wu,Util:()=>U,VerbosityLevel:()=>zu,XfaLayer:()=>Fb,build:()=>NS,createValidAbsoluteUrl:()=>mx,fetchData:()=>Yu,getDocument:()=>kS,getFilenameFromUrl:()=>Ax,getPdfFilenameFromUrl:()=>Tx,getXfaPageViewport:()=>Ex,isDataScheme:()=>$u,isPdfFile:()=>gg,noContextMenu:()=>Gs,normalizeUnicode:()=>xx,setLayerDimensions:()=>kr,shadow:()=>it,stopEvent:()=>es,version:()=>IS});const ye=typeof process=="object"&&process+""=="[object process]"&&!process.versions.nw&&!(process.versions.electron&&process.type&&process.type!=="browser"),Q0=[1,0,0,1,0,0],rg=[.001,0,0,.001,0,0],lx=1e7,og=1.35,ts={ANY:1,DISPLAY:2,PRINT:4,ANNOTATIONS_FORMS:16,ANNOTATIONS_STORAGE:32,ANNOTATIONS_DISABLE:64,IS_EDITING:128,OPLIST:256},Dn={DISABLE:0,ENABLE:1,ENABLE_FORMS:2,ENABLE_STORAGE:3},cx="pdfjs_internal_editor_",tt={DISABLE:-1,NONE:0,FREETEXT:3,HIGHLIGHT:9,STAMP:13,INK:15},at={RESIZE:1,CREATE:2,FREETEXT_SIZE:11,FREETEXT_COLOR:12,FREETEXT_OPACITY:13,INK_COLOR:21,INK_THICKNESS:22,INK_OPACITY:23,HIGHLIGHT_COLOR:31,HIGHLIGHT_DEFAULT_COLOR:32,HIGHLIGHT_THICKNESS:33,HIGHLIGHT_FREE:34,HIGHLIGHT_SHOW_ALL:35,DRAW_STEP:41},ux={PRINT:4,MODIFY_CONTENTS:8,COPY:16,MODIFY_ANNOTATIONS:32,FILL_INTERACTIVE_FORMS:256,COPY_FOR_ACCESSIBILITY:512,ASSEMBLE:1024,PRINT_HIGH_QUALITY:2048},ve={FILL:0,STROKE:1,FILL_STROKE:2,INVISIBLE:3,FILL_STROKE_MASK:3,ADD_TO_PATH_FLAG:4},Gu={GRAYSCALE_1BPP:1,RGB_24BPP:2,RGBA_32BPP:3},qt={TEXT:1,LINK:2,FREETEXT:3,LINE:4,SQUARE:5,CIRCLE:6,POLYGON:7,POLYLINE:8,HIGHLIGHT:9,UNDERLINE:10,SQUIGGLY:11,STRIKEOUT:12,STAMP:13,CARET:14,INK:15,POPUP:16,FILEATTACHMENT:17,WIDGET:20},Gh={SOLID:1,DASHED:2,BEVELED:3,INSET:4,UNDERLINE:5},zu={ERRORS:0,WARNINGS:1,INFOS:5},Hs={dependency:1,setLineWidth:2,setLineCap:3,setLineJoin:4,setMiterLimit:5,setDash:6,setRenderingIntent:7,setFlatness:8,setGState:9,save:10,restore:11,transform:12,moveTo:13,lineTo:14,curveTo:15,curveTo2:16,curveTo3:17,closePath:18,rectangle:19,stroke:20,closeStroke:21,fill:22,eoFill:23,fillStroke:24,eoFillStroke:25,closeFillStroke:26,closeEOFillStroke:27,endPath:28,clip:29,eoClip:30,beginText:31,endText:32,setCharSpacing:33,setWordSpacing:34,setHScale:35,setLeading:36,setFont:37,setTextRenderingMode:38,setTextRise:39,moveText:40,setLeadingMoveText:41,setTextMatrix:42,nextLine:43,showText:44,showSpacedText:45,nextLineShowText:46,nextLineSetSpacingShowText:47,setCharWidth:48,setCharWidthAndBounds:49,setStrokeColorSpace:50,setFillColorSpace:51,setStrokeColor:52,setStrokeColorN:53,setFillColor:54,setFillColorN:55,setStrokeGray:56,setFillGray:57,setStrokeRGBColor:58,setFillRGBColor:59,setStrokeCMYKColor:60,setFillCMYKColor:61,shadingFill:62,beginInlineImage:63,beginImageData:64,endInlineImage:65,paintXObject:66,markPoint:67,markPointProps:68,beginMarkedContent:69,beginMarkedContentProps:70,endMarkedContent:71,beginCompat:72,endCompat:73,paintFormXObjectBegin:74,paintFormXObjectEnd:75,beginGroup:76,endGroup:77,beginAnnotation:80,endAnnotation:81,paintImageMaskXObject:83,paintImageMaskXObjectGroup:84,paintImageXObject:85,paintInlineImageXObject:86,paintInlineImageXObjectGroup:87,paintImageXObjectRepeat:88,paintImageMaskXObjectRepeat:89,paintSolidColorImageMask:90,constructPath:91,setStrokeTransparent:92,setFillTransparent:93},dx={NEED_PASSWORD:1,INCORRECT_PASSWORD:2};let Vu=zu.WARNINGS;function fx(a){Number.isInteger(a)&&(Vu=a)}function gx(){return Vu}function Xu(a){Vu>=zu.INFOS&&console.log(`Info: ${a}`)}function et(a){Vu>=zu.WARNINGS&&console.log(`Warning: ${a}`)}function vt(a){throw new Error(a)}function Xt(a,t){a||vt(t)}function px(a){switch(a==null?void 0:a.protocol){case"http:":case"https:":case"ftp:":case"mailto:":case"tel:":return!0;default:return!1}}function mx(a,t=null,e=null){if(!a)return null;try{if(e&&typeof a=="string"){if(e.addDefaultProtocol&&a.startsWith("www.")){const i=a.match(/\./g);(i==null?void 0:i.length)>=2&&(a=`http://${a}`)}if(e.tryConvertEncoding)try{a=wx(a)}catch{}}const s=t?new URL(a,t):new URL(a);if(px(s))return s}catch{}return null}function it(a,t,e,s=!1){return Object.defineProperty(a,t,{value:e,enumerable:!s,configurable:!0,writable:!1}),e}const On=function(){function t(e,s){this.message=e,this.name=s}return t.prototype=new Error,t.constructor=t,t}();class J0 extends On{constructor(t,e){super(t,"PasswordException"),this.code=e}}class ag extends On{constructor(t,e){super(t,"UnknownErrorException"),this.details=e}}class hg extends On{constructor(t){super(t,"InvalidPDFException")}}class zh extends On{constructor(t){super(t,"MissingPDFException")}}class Wu extends On{constructor(t,e){super(t,"UnexpectedResponseException"),this.status=e}}class bx extends On{constructor(t){super(t,"FormatError")}}class Rn extends On{constructor(t){super(t,"AbortException")}}function Z0(a){(typeof a!="object"||(a==null?void 0:a.length)===void 0)&&vt("Invalid argument for bytesToString");const t=a.length,e=8192;if(t<e)return String.fromCharCode.apply(null,a);const s=[];for(let i=0;i<t;i+=e){const n=Math.min(i+e,t),r=a.subarray(i,n);s.push(String.fromCharCode.apply(null,r))}return s.join("")}function Uu(a){typeof a!="string"&&vt("Invalid argument for stringToBytes");const t=a.length,e=new Uint8Array(t);for(let s=0;s<t;++s)e[s]=a.charCodeAt(s)&255;return e}function yx(a){return String.fromCharCode(a>>24&255,a>>16&255,a>>8&255,a&255)}function lg(a){const t=Object.create(null);for(const[e,s]of a)t[e]=s;return t}function vx(){const a=new Uint8Array(4);return a[0]=1,new Uint32Array(a.buffer,0,1)[0]===1}function _x(){try{return new Function(""),!0}catch{return!1}}class Re{static get isLittleEndian(){return it(this,"isLittleEndian",vx())}static get isEvalSupported(){return it(this,"isEvalSupported",_x())}static get isOffscreenCanvasSupported(){return it(this,"isOffscreenCanvasSupported",typeof OffscreenCanvas<"u")}static get isImageDecoderSupported(){return it(this,"isImageDecoderSupported",typeof ImageDecoder<"u")}static get platform(){return typeof navigator<"u"&&typeof(navigator==null?void 0:navigator.platform)=="string"?it(this,"platform",{isMac:navigator.platform.includes("Mac"),isWindows:navigator.platform.includes("Win"),isFirefox:typeof(navigator==null?void 0:navigator.userAgent)=="string"&&navigator.userAgent.includes("Firefox")}):it(this,"platform",{isMac:!1,isWindows:!1,isFirefox:!1})}static get isCSSRoundSupported(){var t,e;return it(this,"isCSSRoundSupported",(e=(t=globalThis.CSS)==null?void 0:t.supports)==null?void 0:e.call(t,"width: round(1.5px, 1px)"))}}const cg=Array.from(Array(256).keys(),a=>a.toString(16).padStart(2,"0"));class U{static makeHexColor(t,e,s){return`#${cg[t]}${cg[e]}${cg[s]}`}static scaleMinMax(t,e){let s;t[0]?(t[0]<0&&(s=e[0],e[0]=e[2],e[2]=s),e[0]*=t[0],e[2]*=t[0],t[3]<0&&(s=e[1],e[1]=e[3],e[3]=s),e[1]*=t[3],e[3]*=t[3]):(s=e[0],e[0]=e[1],e[1]=s,s=e[2],e[2]=e[3],e[3]=s,t[1]<0&&(s=e[1],e[1]=e[3],e[3]=s),e[1]*=t[1],e[3]*=t[1],t[2]<0&&(s=e[0],e[0]=e[2],e[2]=s),e[0]*=t[2],e[2]*=t[2]),e[0]+=t[4],e[1]+=t[5],e[2]+=t[4],e[3]+=t[5]}static transform(t,e){return[t[0]*e[0]+t[2]*e[1],t[1]*e[0]+t[3]*e[1],t[0]*e[2]+t[2]*e[3],t[1]*e[2]+t[3]*e[3],t[0]*e[4]+t[2]*e[5]+t[4],t[1]*e[4]+t[3]*e[5]+t[5]]}static applyTransform(t,e){const s=t[0]*e[0]+t[1]*e[2]+e[4],i=t[0]*e[1]+t[1]*e[3]+e[5];return[s,i]}static applyInverseTransform(t,e){const s=e[0]*e[3]-e[1]*e[2],i=(t[0]*e[3]-t[1]*e[2]+e[2]*e[5]-e[4]*e[3])/s,n=(-t[0]*e[1]+t[1]*e[0]+e[4]*e[1]-e[5]*e[0])/s;return[i,n]}static getAxialAlignedBoundingBox(t,e){const s=this.applyTransform(t,e),i=this.applyTransform(t.slice(2,4),e),n=this.applyTransform([t[0],t[3]],e),r=this.applyTransform([t[2],t[1]],e);return[Math.min(s[0],i[0],n[0],r[0]),Math.min(s[1],i[1],n[1],r[1]),Math.max(s[0],i[0],n[0],r[0]),Math.max(s[1],i[1],n[1],r[1])]}static inverseTransform(t){const e=t[0]*t[3]-t[1]*t[2];return[t[3]/e,-t[1]/e,-t[2]/e,t[0]/e,(t[2]*t[5]-t[4]*t[3])/e,(t[4]*t[1]-t[5]*t[0])/e]}static singularValueDecompose2dScale(t){const e=[t[0],t[2],t[1],t[3]],s=t[0]*e[0]+t[1]*e[2],i=t[0]*e[1]+t[1]*e[3],n=t[2]*e[0]+t[3]*e[2],r=t[2]*e[1]+t[3]*e[3],o=(s+r)/2,h=Math.sqrt((s+r)**2-4*(s*r-n*i))/2,c=o+h||1,u=o-h||1;return[Math.sqrt(c),Math.sqrt(u)]}static normalizeRect(t){const e=t.slice(0);return t[0]>t[2]&&(e[0]=t[2],e[2]=t[0]),t[1]>t[3]&&(e[1]=t[3],e[3]=t[1]),e}static intersect(t,e){const s=Math.max(Math.min(t[0],t[2]),Math.min(e[0],e[2])),i=Math.min(Math.max(t[0],t[2]),Math.max(e[0],e[2]));if(s>i)return null;const n=Math.max(Math.min(t[1],t[3]),Math.min(e[1],e[3])),r=Math.min(Math.max(t[1],t[3]),Math.max(e[1],e[3]));return n>r?null:[s,n,i,r]}static bezierBoundingBox(t,e,s,i,n,r,o,h,c){return c?(c[0]=Math.min(c[0],t,o),c[1]=Math.min(c[1],e,h),c[2]=Math.max(c[2],t,o),c[3]=Math.max(c[3],e,h)):c=[Math.min(t,o),Math.min(e,h),Math.max(t,o),Math.max(e,h)],w(this,Xi,Kg).call(this,t,s,n,o,e,i,r,h,3*(-t+3*(s-n)+o),6*(t-2*s+n),3*(s-t),c),w(this,Xi,Kg).call(this,t,s,n,o,e,i,r,h,3*(-e+3*(i-r)+h),6*(e-2*i+r),3*(i-e),c),c}}Xi=new WeakSet,kd=function(t,e,s,i,n,r,o,h,c,u){if(c<=0||c>=1)return;const d=1-c,f=c*c,g=f*c,p=d*(d*(d*t+3*c*e)+3*f*s)+g*i,b=d*(d*(d*n+3*c*r)+3*f*o)+g*h;u[0]=Math.min(u[0],p),u[1]=Math.min(u[1],b),u[2]=Math.max(u[2],p),u[3]=Math.max(u[3],b)},Kg=function(t,e,s,i,n,r,o,h,c,u,d,f){if(Math.abs(c)<1e-12){Math.abs(u)>=1e-12&&w(this,Xi,kd).call(this,t,e,s,i,n,r,o,h,-d/u,f);return}const g=u**2-4*d*c;if(g<0)return;const p=Math.sqrt(g),b=2*c;w(this,Xi,kd).call(this,t,e,s,i,n,r,o,h,(-u+p)/b,f),w(this,Xi,kd).call(this,t,e,s,i,n,r,o,h,(-u-p)/b,f)},y(U,Xi);function wx(a){return decodeURIComponent(escape(a))}let ug=null,tb=null;function xx(a){return ug||(ug=/([\u00a0\u00b5\u037e\u0eb3\u2000-\u200a\u202f\u2126\ufb00-\ufb04\ufb06\ufb20-\ufb36\ufb38-\ufb3c\ufb3e\ufb40-\ufb41\ufb43-\ufb44\ufb46-\ufba1\ufba4-\ufba9\ufbae-\ufbb1\ufbd3-\ufbdc\ufbde-\ufbe7\ufbea-\ufbf8\ufbfc-\ufbfd\ufc00-\ufc5d\ufc64-\ufcf1\ufcf5-\ufd3d\ufd88\ufdf4\ufdfa-\ufdfb\ufe71\ufe77\ufe79\ufe7b\ufe7d]+)|(\ufb05+)/gu,tb=new Map([["ſt","ſt"]])),a.replaceAll(ug,(t,e,s)=>e?e.normalize("NFKC"):tb.get(s))}function Sx(){if(typeof crypto.randomUUID=="function")return crypto.randomUUID();const a=new Uint8Array(32);return crypto.getRandomValues(a),Z0(a)}const dg="pdfjs_internal_id_";function Cx(a){return Uint8Array.prototype.toBase64?a.toBase64():btoa(Z0(a))}typeof Promise.try!="function"&&(Promise.try=function(a,...t){return new Promise(e=>{e(a(...t))})});const zi="http://www.w3.org/2000/svg",Or=class Or{};q(Or,"CSS",96),q(Or,"PDF",72),q(Or,"PDF_TO_CSS_UNITS",Or.CSS/Or.PDF);let Ln=Or;async function Yu(a,t="text"){if(Xh(a,document.baseURI)){const e=await fetch(a);if(!e.ok)throw new Error(e.statusText);switch(t){case"arraybuffer":return e.arrayBuffer();case"blob":return e.blob();case"json":return e.json()}return e.text()}return new Promise((e,s)=>{const i=new XMLHttpRequest;i.open("GET",a,!0),i.responseType=t,i.onreadystatechange=()=>{if(i.readyState===XMLHttpRequest.DONE){if(i.status===200||i.status===0){switch(t){case"arraybuffer":case"blob":case"json":e(i.response);return}e(i.responseText);return}s(new Error(i.statusText))}},i.send(null)})}class Vh{constructor({viewBox:t,userUnit:e,scale:s,rotation:i,offsetX:n=0,offsetY:r=0,dontFlip:o=!1}){this.viewBox=t,this.userUnit=e,this.scale=s,this.rotation=i,this.offsetX=n,this.offsetY=r,s*=e;const h=(t[2]+t[0])/2,c=(t[3]+t[1])/2;let u,d,f,g;switch(i%=360,i<0&&(i+=360),i){case 180:u=-1,d=0,f=0,g=1;break;case 90:u=0,d=1,f=1,g=0;break;case 270:u=0,d=-1,f=-1,g=0;break;case 0:u=1,d=0,f=0,g=-1;break;default:throw new Error("PageViewport: Invalid rotation, must be a multiple of 90 degrees.")}o&&(f=-f,g=-g);let p,b,_,v;u===0?(p=Math.abs(c-t[1])*s+n,b=Math.abs(h-t[0])*s+r,_=(t[3]-t[1])*s,v=(t[2]-t[0])*s):(p=Math.abs(h-t[0])*s+n,b=Math.abs(c-t[1])*s+r,_=(t[2]-t[0])*s,v=(t[3]-t[1])*s),this.transform=[u*s,d*s,f*s,g*s,p-u*s*h-f*s*c,b-d*s*h-g*s*c],this.width=_,this.height=v}get rawDims(){const{userUnit:t,viewBox:e}=this,s=e.map(i=>i*t);return it(this,"rawDims",{pageWidth:s[2]-s[0],pageHeight:s[3]-s[1],pageX:s[0],pageY:s[1]})}clone({scale:t=this.scale,rotation:e=this.rotation,offsetX:s=this.offsetX,offsetY:i=this.offsetY,dontFlip:n=!1}={}){return new Vh({viewBox:this.viewBox.slice(),userUnit:this.userUnit,scale:t,rotation:e,offsetX:s,offsetY:i,dontFlip:n})}convertToViewportPoint(t,e){return U.applyTransform([t,e],this.transform)}convertToViewportRectangle(t){const e=U.applyTransform([t[0],t[1]],this.transform),s=U.applyTransform([t[2],t[3]],this.transform);return[e[0],e[1],s[0],s[1]]}convertToPdfPoint(t,e){return U.applyInverseTransform([t,e],this.transform)}}class fg extends On{constructor(t,e=0){super(t,"RenderingCancelledException"),this.extraDelay=e}}function $u(a){const t=a.length;let e=0;for(;e<t&&a[e].trim()==="";)e++;return a.substring(e,e+5).toLowerCase()==="data:"}function gg(a){return typeof a=="string"&&/\.pdf$/i.test(a)}function Ax(a){return[a]=a.split(/[#?]/,1),a.substring(a.lastIndexOf("/")+1)}function Tx(a,t="document.pdf"){if(typeof a!="string")return t;if($u(a))return et('getPdfFilenameFromUrl: ignore "data:"-URL for performance reasons.'),t;const e=/^(?:(?:[^:]+:)?\/\/[^/]+)?([^?#]*)(\?[^#]*)?(#.*)?$/,s=/[^/?#=]+\.pdf\b(?!.*\.pdf\b)/i,i=e.exec(a);let n=s.exec(i[1])||s.exec(i[2])||s.exec(i[3]);if(n&&(n=n[0],n.includes("%")))try{n=s.exec(decodeURIComponent(n))[0]}catch{}return n||t}class eb{constructor(){q(this,"started",Object.create(null));q(this,"times",[])}time(t){t in this.started&&et(`Timer is already running for ${t}`),this.started[t]=Date.now()}timeEnd(t){t in this.started||et(`Timer has not been started for ${t}`),this.times.push({name:t,start:this.started[t],end:Date.now()}),delete this.started[t]}toString(){const t=[];let e=0;for(const{name:s}of this.times)e=Math.max(s.length,e);for(const{name:s,start:i,end:n}of this.times)t.push(`${s.padEnd(e)} ${n-i}ms
|
|
499
|
-
`);return t.join("")}}function Xh(a,t){try{const{protocol:e}=t?new URL(a,t):new URL(a);return e==="http:"||e==="https:"}catch{return!1}}function Gs(a){a.preventDefault()}function es(a){a.preventDefault(),a.stopPropagation()}class pg{static toDateObject(t){if(!t||typeof t!="string")return null;l(this,Zh)||m(this,Zh,new RegExp("^D:(\\d{4})(\\d{2})?(\\d{2})?(\\d{2})?(\\d{2})?(\\d{2})?([Z|+|-])?(\\d{2})?'?(\\d{2})?'?"));const e=l(this,Zh).exec(t);if(!e)return null;const s=parseInt(e[1],10);let i=parseInt(e[2],10);i=i>=1&&i<=12?i-1:0;let n=parseInt(e[3],10);n=n>=1&&n<=31?n:1;let r=parseInt(e[4],10);r=r>=0&&r<=23?r:0;let o=parseInt(e[5],10);o=o>=0&&o<=59?o:0;let h=parseInt(e[6],10);h=h>=0&&h<=59?h:0;const c=e[7]||"Z";let u=parseInt(e[8],10);u=u>=0&&u<=23?u:0;let d=parseInt(e[9],10)||0;return d=d>=0&&d<=59?d:0,c==="-"?(r+=u,o+=d):c==="+"&&(r-=u,o-=d),new Date(Date.UTC(s,i,n,r,o,h))}}Zh=new WeakMap,y(pg,Zh);function Ex(a,{scale:t=1,rotation:e=0}){const{width:s,height:i}=a.attributes.style,n=[0,0,parseInt(s),parseInt(i)];return new Vh({viewBox:n,userUnit:1,scale:t,rotation:e})}function mg(a){if(a.startsWith("#")){const t=parseInt(a.slice(1),16);return[(t&16711680)>>16,(t&65280)>>8,t&255]}return a.startsWith("rgb(")?a.slice(4,-1).split(",").map(t=>parseInt(t)):a.startsWith("rgba(")?a.slice(5,-1).split(",").map(t=>parseInt(t)).slice(0,3):(et(`Not a valid color format: "${a}"`),[0,0,0])}function kx(a){const t=document.createElement("span");t.style.visibility="hidden",document.body.append(t);for(const e of a.keys()){t.style.color=e;const s=window.getComputedStyle(t).color;a.set(e,mg(s))}t.remove()}function Tt(a){const{a:t,b:e,c:s,d:i,e:n,f:r}=a.getTransform();return[t,e,s,i,n,r]}function li(a){const{a:t,b:e,c:s,d:i,e:n,f:r}=a.getTransform().invertSelf();return[t,e,s,i,n,r]}function kr(a,t,e=!1,s=!0){if(t instanceof Vh){const{pageWidth:i,pageHeight:n}=t.rawDims,{style:r}=a,o=Re.isCSSRoundSupported,h=`var(--scale-factor) * ${i}px`,c=`var(--scale-factor) * ${n}px`,u=o?`round(down, ${h}, var(--scale-round-x, 1px))`:`calc(${h})`,d=o?`round(down, ${c}, var(--scale-round-y, 1px))`:`calc(${c})`;!e||t.rotation%180===0?(r.width=u,r.height=d):(r.width=d,r.height=u)}s&&a.setAttribute("data-main-rotation",t.rotation)}class bg{constructor(){const t=window.devicePixelRatio||1;this.sx=t,this.sy=t}get scaled(){return this.sx!==1||this.sy!==1}get symmetric(){return this.sx===this.sy}}const Wi=class Wi{constructor(t){y(this,Le);y(this,In,null);y(this,Rr,null);y(this,zs);y(this,Lr,null);y(this,tl,null);m(this,zs,t),l(Wi,el)||m(Wi,el,Object.freeze({freetext:"pdfjs-editor-remove-freetext-button",highlight:"pdfjs-editor-remove-highlight-button",ink:"pdfjs-editor-remove-ink-button",stamp:"pdfjs-editor-remove-stamp-button"}))}render(){const t=m(this,In,document.createElement("div"));t.classList.add("editToolbar","hidden"),t.setAttribute("role","toolbar");const e=l(this,zs)._uiManager._signal;t.addEventListener("contextmenu",Gs,{signal:e}),t.addEventListener("pointerdown",w(Wi,hd,Ub),{signal:e});const s=m(this,Lr,document.createElement("div"));s.className="buttons",t.append(s);const i=l(this,zs).toolbarPosition;if(i){const{style:n}=t,r=l(this,zs)._uiManager.direction==="ltr"?1-i[0]:i[0];n.insetInlineEnd=`${100*r}%`,n.top=`calc(${100*i[1]}% + var(--editor-toolbar-vert-offset))`}return w(this,Le,qb).call(this),t}get div(){return l(this,In)}hide(){var t;l(this,In).classList.add("hidden"),(t=l(this,Rr))==null||t.hideDropdown()}show(){var t;l(this,In).classList.remove("hidden"),(t=l(this,tl))==null||t.shown()}async addAltText(t){const e=await t.render();w(this,Le,Md).call(this,e),l(this,Lr).prepend(e,l(this,Le,Qg)),m(this,tl,t)}addColorPicker(t){m(this,Rr,t);const e=t.renderButton();w(this,Le,Md).call(this,e),l(this,Lr).prepend(e,l(this,Le,Qg))}remove(){var t;l(this,In).remove(),(t=l(this,Rr))==null||t.destroy(),m(this,Rr,null)}};In=new WeakMap,Rr=new WeakMap,zs=new WeakMap,Lr=new WeakMap,tl=new WeakMap,el=new WeakMap,hd=new WeakSet,Ub=function(t){t.stopPropagation()},Le=new WeakSet,Yb=function(t){l(this,zs)._focusEventsAllowed=!1,es(t)},$b=function(t){l(this,zs)._focusEventsAllowed=!0,es(t)},Md=function(t){const e=l(this,zs)._uiManager._signal;t.addEventListener("focusin",w(this,Le,Yb).bind(this),{capture:!0,signal:e}),t.addEventListener("focusout",w(this,Le,$b).bind(this),{capture:!0,signal:e}),t.addEventListener("contextmenu",Gs,{signal:e})},qb=function(){const{editorType:t,_uiManager:e}=l(this,zs),s=document.createElement("button");s.className="delete",s.tabIndex=0,s.setAttribute("data-l10n-id",l(Wi,el)[t]),w(this,Le,Md).call(this,s),s.addEventListener("click",i=>{e.delete()},{signal:e._signal}),l(this,Lr).append(s)},Qg=function(){const t=document.createElement("div");return t.className="divider",t},y(Wi,hd),y(Wi,el,null);let yg=Wi;class Mx{constructor(t){y(this,Nn);y(this,sl,null);y(this,Fr,null);y(this,Ir);m(this,Ir,t)}show(t,e,s){const[i,n]=w(this,Nn,Qb).call(this,e,s),{style:r}=l(this,Fr)||m(this,Fr,w(this,Nn,Kb).call(this));t.append(l(this,Fr)),r.insetInlineEnd=`${100*i}%`,r.top=`calc(${100*n}% + var(--editor-toolbar-vert-offset))`}hide(){l(this,Fr).remove()}}sl=new WeakMap,Fr=new WeakMap,Ir=new WeakMap,Nn=new WeakSet,Kb=function(){const t=m(this,Fr,document.createElement("div"));t.className="editToolbar",t.setAttribute("role","toolbar"),t.addEventListener("contextmenu",Gs,{signal:l(this,Ir)._signal});const e=m(this,sl,document.createElement("div"));return e.className="buttons",t.append(e),w(this,Nn,Jb).call(this),t},Qb=function(t,e){let s=0,i=0;for(const n of t){const r=n.y+n.height;if(r<s)continue;const o=n.x+(e?n.width:0);if(r>s){i=o,s=r;continue}e?o>i&&(i=o):o<i&&(i=o)}return[e?1-i:i,s]},Jb=function(){const t=document.createElement("button");t.className="highlightButton",t.tabIndex=0,t.setAttribute("data-l10n-id","pdfjs-highlight-floating-button1");const e=document.createElement("span");t.append(e),e.className="visuallyHidden",e.setAttribute("data-l10n-id","pdfjs-highlight-floating-button-label");const s=l(this,Ir)._signal;t.addEventListener("contextmenu",Gs,{signal:s}),t.addEventListener("click",()=>{l(this,Ir).highlightSelection("floating_button")},{signal:s}),l(this,sl).append(t)};function qu(a,t,e){for(const s of e)t.addEventListener(s,a[s].bind(a))}class Px{constructor(){y(this,ld,0)}get id(){return`${cx}${Ge(this,ld)._++}`}}ld=new WeakMap;const Vg=class Vg{constructor(){y(this,la);y(this,ha,Sx());y(this,il,0);y(this,we,null)}static get _isSVGFittingCanvas(){const t='data:image/svg+xml;charset=UTF-8,<svg viewBox="0 0 1 1" width="1" height="1" xmlns="http://www.w3.org/2000/svg"><rect width="1" height="1" style="fill:red;"/></svg>',s=new OffscreenCanvas(1,3).getContext("2d",{willReadFrequently:!0}),i=new Image;i.src=t;const n=i.decode().then(()=>(s.drawImage(i,0,0,1,1,0,0,1,3),new Uint32Array(s.getImageData(0,0,1,1).data.buffer)[0]===0));return it(this,"_isSVGFittingCanvas",n)}async getFromFile(t){const{lastModified:e,name:s,size:i,type:n}=t;return w(this,la,Pd).call(this,`${e}_${s}_${i}_${n}`,t)}async getFromUrl(t){return w(this,la,Pd).call(this,t,t)}async getFromBlob(t,e){const s=await e;return w(this,la,Pd).call(this,t,s)}async getFromId(t){l(this,we)||m(this,we,new Map);const e=l(this,we).get(t);if(!e)return null;if(e.bitmap)return e.refCounter+=1,e;if(e.file)return this.getFromFile(e.file);if(e.blobPromise){const{blobPromise:s}=e;return delete e.blobPromise,this.getFromBlob(e.id,s)}return this.getFromUrl(e.url)}getFromCanvas(t,e){l(this,we)||m(this,we,new Map);let s=l(this,we).get(t);if(s!=null&&s.bitmap)return s.refCounter+=1,s;const i=new OffscreenCanvas(e.width,e.height);return i.getContext("2d").drawImage(e,0,0),s={bitmap:i.transferToImageBitmap(),id:`image_${l(this,ha)}_${Ge(this,il)._++}`,refCounter:1,isSvg:!1},l(this,we).set(t,s),l(this,we).set(s.id,s),s}getSvgUrl(t){const e=l(this,we).get(t);return e!=null&&e.isSvg?e.svgUrl:null}deleteId(t){var i;l(this,we)||m(this,we,new Map);const e=l(this,we).get(t);if(!e||(e.refCounter-=1,e.refCounter!==0))return;const{bitmap:s}=e;if(!e.url&&!e.file){const n=new OffscreenCanvas(s.width,s.height);n.getContext("bitmaprenderer").transferFromImageBitmap(s),e.blobPromise=n.convertToBlob()}(i=s.close)==null||i.call(s),e.bitmap=null}isValidId(t){return t.startsWith(`image_${l(this,ha)}_`)}};ha=new WeakMap,il=new WeakMap,we=new WeakMap,la=new WeakSet,Pd=async function(t,e){l(this,we)||m(this,we,new Map);let s=l(this,we).get(t);if(s===null)return null;if(s!=null&&s.bitmap)return s.refCounter+=1,s;try{s||(s={bitmap:null,id:`image_${l(this,ha)}_${Ge(this,il)._++}`,refCounter:0,isSvg:!1});let i;if(typeof e=="string"?(s.url=e,i=await Yu(e,"blob")):e instanceof File?i=s.file=e:e instanceof Blob&&(i=e),i.type==="image/svg+xml"){const n=Vg._isSVGFittingCanvas,r=new FileReader,o=new Image,h=new Promise((c,u)=>{o.onload=()=>{s.bitmap=o,s.isSvg=!0,c()},r.onload=async()=>{const d=s.svgUrl=r.result;o.src=await n?`${d}#svgView(preserveAspectRatio(none))`:d},o.onerror=r.onerror=u});r.readAsDataURL(i),await h}else s.bitmap=await createImageBitmap(i);s.refCounter=1}catch(i){et(i),s=null}return l(this,we).set(t,s),s&&l(this,we).set(s.id,s),s};let vg=Vg;class Dx{constructor(t=128){y(this,Bt,[]);y(this,jn,!1);y(this,nl);y(this,Dt,-1);m(this,nl,t)}add({cmd:t,undo:e,post:s,mustExec:i,type:n=NaN,overwriteIfSameType:r=!1,keepUndo:o=!1}){if(i&&t(),l(this,jn))return;const h={cmd:t,undo:e,post:s,type:n};if(l(this,Dt)===-1){l(this,Bt).length>0&&(l(this,Bt).length=0),m(this,Dt,0),l(this,Bt).push(h);return}if(r&&l(this,Bt)[l(this,Dt)].type===n){o&&(h.undo=l(this,Bt)[l(this,Dt)].undo),l(this,Bt)[l(this,Dt)]=h;return}const c=l(this,Dt)+1;c===l(this,nl)?l(this,Bt).splice(0,1):(m(this,Dt,c),c<l(this,Bt).length&&l(this,Bt).splice(c)),l(this,Bt).push(h)}undo(){if(l(this,Dt)===-1)return;m(this,jn,!0);const{undo:t,post:e}=l(this,Bt)[l(this,Dt)];t(),e==null||e(),m(this,jn,!1),m(this,Dt,l(this,Dt)-1)}redo(){if(l(this,Dt)<l(this,Bt).length-1){m(this,Dt,l(this,Dt)+1),m(this,jn,!0);const{cmd:t,post:e}=l(this,Bt)[l(this,Dt)];t(),e==null||e(),m(this,jn,!1)}}hasSomethingToUndo(){return l(this,Dt)!==-1}hasSomethingToRedo(){return l(this,Dt)<l(this,Bt).length-1}cleanType(t){if(l(this,Dt)!==-1){for(let e=l(this,Dt);e>=0;e--)if(l(this,Bt)[e].type!==t){l(this,Bt).splice(e+1,l(this,Dt)-e),m(this,Dt,e);return}l(this,Bt).length=0,m(this,Dt,-1)}}destroy(){m(this,Bt,null)}}Bt=new WeakMap,jn=new WeakMap,nl=new WeakMap,Dt=new WeakMap;class Wh{constructor(t){y(this,cd);this.buffer=[],this.callbacks=new Map,this.allKeys=new Set;const{isMac:e}=Re.platform;for(const[s,i,n={}]of t)for(const r of s){const o=r.startsWith("mac+");e&&o?(this.callbacks.set(r.slice(4),{callback:i,options:n}),this.allKeys.add(r.split("+").at(-1))):!e&&!o&&(this.callbacks.set(r,{callback:i,options:n}),this.allKeys.add(r.split("+").at(-1)))}}exec(t,e){if(!this.allKeys.has(e.key))return;const s=this.callbacks.get(w(this,cd,Zb).call(this,e));if(!s)return;const{callback:i,options:{bubbles:n=!1,args:r=[],checker:o=null}}=s;o&&!o(t,e)||(i.bind(t,...r,e)(),n||es(e))}}cd=new WeakSet,Zb=function(t){t.altKey&&this.buffer.push("alt"),t.ctrlKey&&this.buffer.push("ctrl"),t.metaKey&&this.buffer.push("meta"),t.shiftKey&&this.buffer.push("shift"),this.buffer.push(t.key);const e=this.buffer.join("+");return this.buffer.length=0,e};const ud=class ud{get _colors(){const t=new Map([["CanvasText",null],["Canvas",null]]);return kx(t),it(this,"_colors",t)}convert(t){const e=mg(t);if(!window.matchMedia("(forced-colors: active)").matches)return e;for(const[s,i]of this._colors)if(i.every((n,r)=>n===e[r]))return ud._colorsMapping.get(s);return e}getHexCode(t){const e=this._colors.get(t);return e?U.makeHexColor(...e):t}};q(ud,"_colorsMapping",new Map([["CanvasText",[0,0,0]],["Canvas",[255,255,255]]]));let _g=ud;const ma=class ma{constructor(t,e,s,i,n,r,o,h,c,u,d,f,g){y(this,j);y(this,ca,new AbortController);y(this,ss,null);y(this,Kt,new Map);y(this,ae,new Map);y(this,ua,null);y(this,Ui,null);y(this,da,null);y(this,ws,new Dx);y(this,Bn,null);y(this,Nr,null);y(this,fa,0);y(this,jr,new Set);y(this,ui,null);y(this,Vs,null);y(this,Br,new Set);q(this,"_editorUndoBar",null);y(this,rl,!1);y(this,ol,!1);y(this,ga,!1);y(this,al,null);y(this,di,null);y(this,Hn,null);y(this,pa,null);y(this,Gn,!1);y(this,fi,null);y(this,dd,new Px);y(this,zn,!1);y(this,hl,!1);y(this,Vn,null);y(this,Hr,null);y(this,ll,null);y(this,cl,null);y(this,ee,tt.NONE);y(this,pt,new Set);y(this,Yi,null);y(this,Gr,null);y(this,ul,null);y(this,dl,{isEditing:!1,isEmpty:!0,hasSomethingToUndo:!1,hasSomethingToRedo:!1,hasSelectedEditor:!1,hasSelectedText:!1});y(this,Xn,[0,0]);y(this,gi,null);y(this,$i,null);y(this,fl,null);y(this,xs,null);const p=this._signal=l(this,ca).signal;m(this,$i,t),m(this,fl,e),m(this,ua,s),this._eventBus=i,i._on("editingaction",this.onEditingAction.bind(this),{signal:p}),i._on("pagechanging",this.onPageChanging.bind(this),{signal:p}),i._on("scalechanging",this.onScaleChanging.bind(this),{signal:p}),i._on("rotationchanging",this.onRotationChanging.bind(this),{signal:p}),i._on("setpreference",this.onSetPreference.bind(this),{signal:p}),i._on("switchannotationeditorparams",b=>this.updateParams(b.type,b.value),{signal:p}),w(this,j,sy).call(this),w(this,j,oy).call(this),w(this,j,Zg).call(this),m(this,Ui,n.annotationStorage),m(this,al,n.filterFactory),m(this,Gr,r),m(this,pa,o||null),m(this,rl,h),m(this,ol,c),m(this,ga,u),m(this,cl,d||null),this.viewParameters={realScale:Ln.PDF_TO_CSS_UNITS,rotation:0},this.isShiftKeyDown=!1,this._editorUndoBar=f||null,this._supportsPinchToZoom=g!==!1}static get _keyboardManager(){const t=ma.prototype,e=r=>l(r,$i).contains(document.activeElement)&&document.activeElement.tagName!=="BUTTON"&&r.hasSomethingToControl(),s=(r,{target:o})=>{if(o instanceof HTMLInputElement){const{type:h}=o;return h!=="text"&&h!=="number"}return!0},i=this.TRANSLATE_SMALL,n=this.TRANSLATE_BIG;return it(this,"_keyboardManager",new Wh([[["ctrl+a","mac+meta+a"],t.selectAll,{checker:s}],[["ctrl+z","mac+meta+z"],t.undo,{checker:s}],[["ctrl+y","ctrl+shift+z","mac+meta+shift+z","ctrl+shift+Z","mac+meta+shift+Z"],t.redo,{checker:s}],[["Backspace","alt+Backspace","ctrl+Backspace","shift+Backspace","mac+Backspace","mac+alt+Backspace","mac+ctrl+Backspace","Delete","ctrl+Delete","shift+Delete","mac+Delete"],t.delete,{checker:s}],[["Enter","mac+Enter"],t.addNewEditorFromKeyboard,{checker:(r,{target:o})=>!(o instanceof HTMLButtonElement)&&l(r,$i).contains(o)&&!r.isEnterHandled}],[[" ","mac+ "],t.addNewEditorFromKeyboard,{checker:(r,{target:o})=>!(o instanceof HTMLButtonElement)&&l(r,$i).contains(document.activeElement)}],[["Escape","mac+Escape"],t.unselectAll],[["ArrowLeft","mac+ArrowLeft"],t.translateSelectedEditors,{args:[-i,0],checker:e}],[["ctrl+ArrowLeft","mac+shift+ArrowLeft"],t.translateSelectedEditors,{args:[-n,0],checker:e}],[["ArrowRight","mac+ArrowRight"],t.translateSelectedEditors,{args:[i,0],checker:e}],[["ctrl+ArrowRight","mac+shift+ArrowRight"],t.translateSelectedEditors,{args:[n,0],checker:e}],[["ArrowUp","mac+ArrowUp"],t.translateSelectedEditors,{args:[0,-i],checker:e}],[["ctrl+ArrowUp","mac+shift+ArrowUp"],t.translateSelectedEditors,{args:[0,-n],checker:e}],[["ArrowDown","mac+ArrowDown"],t.translateSelectedEditors,{args:[0,i],checker:e}],[["ctrl+ArrowDown","mac+shift+ArrowDown"],t.translateSelectedEditors,{args:[0,n],checker:e}]]))}destroy(){var t,e,s,i,n;(t=l(this,xs))==null||t.resolve(),m(this,xs,null),(e=l(this,ca))==null||e.abort(),m(this,ca,null),this._signal=null;for(const r of l(this,ae).values())r.destroy();l(this,ae).clear(),l(this,Kt).clear(),l(this,Br).clear(),m(this,ss,null),l(this,pt).clear(),l(this,ws).destroy(),(s=l(this,ua))==null||s.destroy(),(i=l(this,fi))==null||i.hide(),m(this,fi,null),l(this,di)&&(clearTimeout(l(this,di)),m(this,di,null)),l(this,gi)&&(clearTimeout(l(this,gi)),m(this,gi,null)),(n=this._editorUndoBar)==null||n.destroy()}combinedSignal(t){return AbortSignal.any([this._signal,t.signal])}get mlManager(){return l(this,cl)}get useNewAltTextFlow(){return l(this,ol)}get useNewAltTextWhenAddingImage(){return l(this,ga)}get hcmFilter(){return it(this,"hcmFilter",l(this,Gr)?l(this,al).addHCMFilter(l(this,Gr).foreground,l(this,Gr).background):"none")}get direction(){return it(this,"direction",getComputedStyle(l(this,$i)).direction)}get highlightColors(){return it(this,"highlightColors",l(this,pa)?new Map(l(this,pa).split(",").map(t=>t.split("=").map(e=>e.trim()))):null)}get highlightColorNames(){return it(this,"highlightColorNames",this.highlightColors?new Map(Array.from(this.highlightColors,t=>t.reverse())):null)}setCurrentDrawingSession(t){t?(this.unselectAll(),this.disableUserSelect(!0)):this.disableUserSelect(!1),m(this,Nr,t)}setMainHighlightColorPicker(t){m(this,ll,t)}editAltText(t,e=!1){var s;(s=l(this,ua))==null||s.editAltText(this,t,e)}switchToMode(t,e){this._eventBus.on("annotationeditormodechanged",e,{once:!0,signal:this._signal}),this._eventBus.dispatch("showannotationeditorui",{source:this,mode:t})}setPreference(t,e){this._eventBus.dispatch("setpreference",{source:this,name:t,value:e})}onSetPreference({name:t,value:e}){switch(t){case"enableNewAltTextWhenAddingImage":m(this,ga,e);break}}onPageChanging({pageNumber:t}){m(this,fa,t-1)}focusMainContainer(){l(this,$i).focus()}findParent(t,e){for(const s of l(this,ae).values()){const{x:i,y:n,width:r,height:o}=s.div.getBoundingClientRect();if(t>=i&&t<=i+r&&e>=n&&e<=n+o)return s}return null}disableUserSelect(t=!1){l(this,fl).classList.toggle("noUserSelect",t)}addShouldRescale(t){l(this,Br).add(t)}removeShouldRescale(t){l(this,Br).delete(t)}onScaleChanging({scale:t}){var e;this.commitOrRemove(),this.viewParameters.realScale=t*Ln.PDF_TO_CSS_UNITS;for(const s of l(this,Br))s.onScaleChanging();(e=l(this,Nr))==null||e.onScaleChanging()}onRotationChanging({pagesRotation:t}){this.commitOrRemove(),this.viewParameters.rotation=t}highlightSelection(t=""){const e=document.getSelection();if(!e||e.isCollapsed)return;const{anchorNode:s,anchorOffset:i,focusNode:n,focusOffset:r}=e,o=e.toString(),c=w(this,j,Dd).call(this,e).closest(".textLayer"),u=this.getSelectionBoxes(c);if(!u)return;e.empty();const d=w(this,j,Jg).call(this,c),f=l(this,ee)===tt.NONE,g=()=>{d==null||d.createAndAddNewEditor({x:0,y:0},!1,{methodOfCreation:t,boxes:u,anchorNode:s,anchorOffset:i,focusNode:n,focusOffset:r,text:o}),f&&this.showAllEditors("highlight",!0,!0)};if(f){this.switchToMode(tt.HIGHLIGHT,g);return}g()}addToAnnotationStorage(t){!t.isEmpty()&&l(this,Ui)&&!l(this,Ui).has(t.id)&&l(this,Ui).setValue(t.id,t)}blur(){if(this.isShiftKeyDown=!1,l(this,Gn)&&(m(this,Gn,!1),w(this,j,Od).call(this,"main_toolbar")),!this.hasSelection)return;const{activeElement:t}=document;for(const e of l(this,pt))if(e.div.contains(t)){m(this,Hr,[e,t]),e._focusEventsAllowed=!1;break}}focus(){if(!l(this,Hr))return;const[t,e]=l(this,Hr);m(this,Hr,null),e.addEventListener("focusin",()=>{t._focusEventsAllowed=!0},{once:!0,signal:this._signal}),e.focus()}addEditListeners(){w(this,j,Zg).call(this),w(this,j,tp).call(this)}removeEditListeners(){w(this,j,ry).call(this),w(this,j,ep).call(this)}dragOver(t){for(const{type:e}of t.dataTransfer.items)for(const s of l(this,Vs))if(s.isHandlingMimeForPasting(e)){t.dataTransfer.dropEffect="copy",t.preventDefault();return}}drop(t){for(const e of t.dataTransfer.items)for(const s of l(this,Vs))if(s.isHandlingMimeForPasting(e.type)){s.paste(e,this.currentLayer),t.preventDefault();return}}copy(t){var s;if(t.preventDefault(),(s=l(this,ss))==null||s.commitOrRemove(),!this.hasSelection)return;const e=[];for(const i of l(this,pt)){const n=i.serialize(!0);n&&e.push(n)}e.length!==0&&t.clipboardData.setData("application/pdfjs",JSON.stringify(e))}cut(t){this.copy(t),this.delete()}async paste(t){t.preventDefault();const{clipboardData:e}=t;for(const n of e.items)for(const r of l(this,Vs))if(r.isHandlingMimeForPasting(n.type)){r.paste(n,this.currentLayer);return}let s=e.getData("application/pdfjs");if(!s)return;try{s=JSON.parse(s)}catch(n){et(`paste: "${n.message}".`);return}if(!Array.isArray(s))return;this.unselectAll();const i=this.currentLayer;try{const n=[];for(const h of s){const c=await i.deserialize(h);if(!c)return;n.push(c)}const r=()=>{for(const h of n)w(this,j,sp).call(this,h);w(this,j,ip).call(this,n)},o=()=>{for(const h of n)h.remove()};this.addCommands({cmd:r,undo:o,mustExec:!0})}catch(n){et(`paste: "${n.message}".`)}}keydown(t){!this.isShiftKeyDown&&t.key==="Shift"&&(this.isShiftKeyDown=!0),l(this,ee)!==tt.NONE&&!this.isEditorHandlingKeyboard&&ma._keyboardManager.exec(this,t)}keyup(t){this.isShiftKeyDown&&t.key==="Shift"&&(this.isShiftKeyDown=!1,l(this,Gn)&&(m(this,Gn,!1),w(this,j,Od).call(this,"main_toolbar")))}onEditingAction({name:t}){switch(t){case"undo":case"redo":case"delete":case"selectAll":this[t]();break;case"highlightSelection":this.highlightSelection("context_menu");break}}setEditingState(t){t?(w(this,j,iy).call(this),w(this,j,tp).call(this),w(this,j,ze).call(this,{isEditing:l(this,ee)!==tt.NONE,isEmpty:w(this,j,Ac).call(this),hasSomethingToUndo:l(this,ws).hasSomethingToUndo(),hasSomethingToRedo:l(this,ws).hasSomethingToRedo(),hasSelectedEditor:!1})):(w(this,j,ny).call(this),w(this,j,ep).call(this),w(this,j,ze).call(this,{isEditing:!1}),this.disableUserSelect(!1))}registerEditorTypes(t){if(!l(this,Vs)){m(this,Vs,t);for(const e of l(this,Vs))w(this,j,xn).call(this,e.defaultPropertiesToUpdate)}}getId(){return l(this,dd).id}get currentLayer(){return l(this,ae).get(l(this,fa))}getLayer(t){return l(this,ae).get(t)}get currentPageIndex(){return l(this,fa)}addLayer(t){l(this,ae).set(t.pageIndex,t),l(this,zn)?t.enable():t.disable()}removeLayer(t){l(this,ae).delete(t.pageIndex)}async updateMode(t,e=null,s=!1){var i;if(l(this,ee)!==t&&!(l(this,xs)&&(await l(this,xs).promise,!l(this,xs)))){if(m(this,xs,Promise.withResolvers()),m(this,ee,t),t===tt.NONE){this.setEditingState(!1),w(this,j,hy).call(this),(i=this._editorUndoBar)==null||i.hide(),l(this,xs).resolve();return}this.setEditingState(!0),await w(this,j,ay).call(this),this.unselectAll();for(const n of l(this,ae).values())n.updateMode(t);if(!e){s&&this.addNewEditorFromKeyboard(),l(this,xs).resolve();return}for(const n of l(this,Kt).values())n.annotationElementId===e?(this.setSelected(n),n.enterInEditMode()):n.unselect();l(this,xs).resolve()}}addNewEditorFromKeyboard(){this.currentLayer.canCreateNewEmptyEditor()&&this.currentLayer.addNewEditor()}updateToolbar(t){t!==l(this,ee)&&this._eventBus.dispatch("switchannotationeditormode",{source:this,mode:t})}updateParams(t,e){var s;if(l(this,Vs)){switch(t){case at.CREATE:this.currentLayer.addNewEditor();return;case at.HIGHLIGHT_DEFAULT_COLOR:(s=l(this,ll))==null||s.updateColor(e);break;case at.HIGHLIGHT_SHOW_ALL:this._eventBus.dispatch("reporttelemetry",{source:this,details:{type:"editing",data:{type:"highlight",action:"toggle_visibility"}}}),(l(this,ul)||m(this,ul,new Map)).set(t,e),this.showAllEditors("highlight",e);break}for(const i of l(this,pt))i.updateParams(t,e);for(const i of l(this,Vs))i.updateDefaultParams(t,e)}}showAllEditors(t,e,s=!1){var n;for(const r of l(this,Kt).values())r.editorType===t&&r.show(e);(((n=l(this,ul))==null?void 0:n.get(at.HIGHLIGHT_SHOW_ALL))??!0)!==e&&w(this,j,xn).call(this,[[at.HIGHLIGHT_SHOW_ALL,e]])}enableWaiting(t=!1){if(l(this,hl)!==t){m(this,hl,t);for(const e of l(this,ae).values())t?e.disableClick():e.enableClick(),e.div.classList.toggle("waiting",t)}}getEditors(t){const e=[];for(const s of l(this,Kt).values())s.pageIndex===t&&e.push(s);return e}getEditor(t){return l(this,Kt).get(t)}addEditor(t){l(this,Kt).set(t.id,t)}removeEditor(t){var e;t.div.contains(document.activeElement)&&(l(this,di)&&clearTimeout(l(this,di)),m(this,di,setTimeout(()=>{this.focusMainContainer(),m(this,di,null)},0))),l(this,Kt).delete(t.id),this.unselect(t),(!t.annotationElementId||!l(this,jr).has(t.annotationElementId))&&((e=l(this,Ui))==null||e.remove(t.id))}addDeletedAnnotationElement(t){l(this,jr).add(t.annotationElementId),this.addChangedExistingAnnotation(t),t.deleted=!0}isDeletedAnnotationElement(t){return l(this,jr).has(t)}removeDeletedAnnotationElement(t){l(this,jr).delete(t.annotationElementId),this.removeChangedExistingAnnotation(t),t.deleted=!1}setActiveEditor(t){l(this,ss)!==t&&(m(this,ss,t),t&&w(this,j,xn).call(this,t.propertiesToUpdate))}updateUI(t){l(this,j,ly)===t&&w(this,j,xn).call(this,t.propertiesToUpdate)}updateUIForDefaultProperties(t){w(this,j,xn).call(this,t.defaultPropertiesToUpdate)}toggleSelected(t){if(l(this,pt).has(t)){l(this,pt).delete(t),t.unselect(),w(this,j,ze).call(this,{hasSelectedEditor:this.hasSelection});return}l(this,pt).add(t),t.select(),w(this,j,xn).call(this,t.propertiesToUpdate),w(this,j,ze).call(this,{hasSelectedEditor:!0})}setSelected(t){var e;(e=l(this,Nr))==null||e.commitOrRemove();for(const s of l(this,pt))s!==t&&s.unselect();l(this,pt).clear(),l(this,pt).add(t),t.select(),w(this,j,xn).call(this,t.propertiesToUpdate),w(this,j,ze).call(this,{hasSelectedEditor:!0})}isSelected(t){return l(this,pt).has(t)}get firstSelectedEditor(){return l(this,pt).values().next().value}unselect(t){t.unselect(),l(this,pt).delete(t),w(this,j,ze).call(this,{hasSelectedEditor:this.hasSelection})}get hasSelection(){return l(this,pt).size!==0}get isEnterHandled(){return l(this,pt).size===1&&this.firstSelectedEditor.isEnterHandled}undo(){var t;l(this,ws).undo(),w(this,j,ze).call(this,{hasSomethingToUndo:l(this,ws).hasSomethingToUndo(),hasSomethingToRedo:!0,isEmpty:w(this,j,Ac).call(this)}),(t=this._editorUndoBar)==null||t.hide()}redo(){l(this,ws).redo(),w(this,j,ze).call(this,{hasSomethingToUndo:!0,hasSomethingToRedo:l(this,ws).hasSomethingToRedo(),isEmpty:w(this,j,Ac).call(this)})}addCommands(t){l(this,ws).add(t),w(this,j,ze).call(this,{hasSomethingToUndo:!0,hasSomethingToRedo:!1,isEmpty:w(this,j,Ac).call(this)})}cleanUndoStack(t){l(this,ws).cleanType(t)}delete(){var n;this.commitOrRemove();const t=(n=this.currentLayer)==null?void 0:n.endDrawingSession(!0);if(!this.hasSelection&&!t)return;const e=t?[t]:[...l(this,pt)],s=()=>{var r;(r=this._editorUndoBar)==null||r.show(i,e.length===1?e[0].editorType:e.length);for(const o of e)o.remove()},i=()=>{for(const r of e)w(this,j,sp).call(this,r)};this.addCommands({cmd:s,undo:i,mustExec:!0})}commitOrRemove(){var t;(t=l(this,ss))==null||t.commitOrRemove()}hasSomethingToControl(){return l(this,ss)||this.hasSelection}selectAll(){for(const t of l(this,pt))t.commit();w(this,j,ip).call(this,l(this,Kt).values())}unselectAll(){var t;if(!(l(this,ss)&&(l(this,ss).commitOrRemove(),l(this,ee)!==tt.NONE))&&!((t=l(this,Nr))!=null&&t.commitOrRemove())&&this.hasSelection){for(const e of l(this,pt))e.unselect();l(this,pt).clear(),w(this,j,ze).call(this,{hasSelectedEditor:!1})}}translateSelectedEditors(t,e,s=!1){if(s||this.commitOrRemove(),!this.hasSelection)return;l(this,Xn)[0]+=t,l(this,Xn)[1]+=e;const[i,n]=l(this,Xn),r=[...l(this,pt)],o=1e3;l(this,gi)&&clearTimeout(l(this,gi)),m(this,gi,setTimeout(()=>{m(this,gi,null),l(this,Xn)[0]=l(this,Xn)[1]=0,this.addCommands({cmd:()=>{for(const h of r)l(this,Kt).has(h.id)&&h.translateInPage(i,n)},undo:()=>{for(const h of r)l(this,Kt).has(h.id)&&h.translateInPage(-i,-n)},mustExec:!1})},o));for(const h of r)h.translateInPage(t,e)}setUpDragSession(){if(this.hasSelection){this.disableUserSelect(!0),m(this,ui,new Map);for(const t of l(this,pt))l(this,ui).set(t,{savedX:t.x,savedY:t.y,savedPageIndex:t.pageIndex,newX:0,newY:0,newPageIndex:-1})}}endDragSession(){if(!l(this,ui))return!1;this.disableUserSelect(!1);const t=l(this,ui);m(this,ui,null);let e=!1;for(const[{x:i,y:n,pageIndex:r},o]of t)o.newX=i,o.newY=n,o.newPageIndex=r,e||(e=i!==o.savedX||n!==o.savedY||r!==o.savedPageIndex);if(!e)return!1;const s=(i,n,r,o)=>{if(l(this,Kt).has(i.id)){const h=l(this,ae).get(o);h?i._setParentAndPosition(h,n,r):(i.pageIndex=o,i.x=n,i.y=r)}};return this.addCommands({cmd:()=>{for(const[i,{newX:n,newY:r,newPageIndex:o}]of t)s(i,n,r,o)},undo:()=>{for(const[i,{savedX:n,savedY:r,savedPageIndex:o}]of t)s(i,n,r,o)},mustExec:!0}),!0}dragSelectedEditors(t,e){if(l(this,ui))for(const s of l(this,ui).keys())s.drag(t,e)}rebuild(t){if(t.parent===null){const e=this.getLayer(t.pageIndex);e?(e.changeParent(t),e.addOrRebuild(t)):(this.addEditor(t),this.addToAnnotationStorage(t),t.rebuild())}else t.parent.addOrRebuild(t)}get isEditorHandlingKeyboard(){var t;return((t=this.getActive())==null?void 0:t.shouldGetKeyboardEvents())||l(this,pt).size===1&&this.firstSelectedEditor.shouldGetKeyboardEvents()}isActive(t){return l(this,ss)===t}getActive(){return l(this,ss)}getMode(){return l(this,ee)}get imageManager(){return it(this,"imageManager",new vg)}getSelectionBoxes(t){if(!t)return null;const e=document.getSelection();for(let c=0,u=e.rangeCount;c<u;c++)if(!t.contains(e.getRangeAt(c).commonAncestorContainer))return null;const{x:s,y:i,width:n,height:r}=t.getBoundingClientRect();let o;switch(t.getAttribute("data-main-rotation")){case"90":o=(c,u,d,f)=>({x:(u-i)/r,y:1-(c+d-s)/n,width:f/r,height:d/n});break;case"180":o=(c,u,d,f)=>({x:1-(c+d-s)/n,y:1-(u+f-i)/r,width:d/n,height:f/r});break;case"270":o=(c,u,d,f)=>({x:1-(u+f-i)/r,y:(c-s)/n,width:f/r,height:d/n});break;default:o=(c,u,d,f)=>({x:(c-s)/n,y:(u-i)/r,width:d/n,height:f/r});break}const h=[];for(let c=0,u=e.rangeCount;c<u;c++){const d=e.getRangeAt(c);if(!d.collapsed)for(const{x:f,y:g,width:p,height:b}of d.getClientRects())p===0||b===0||h.push(o(f,g,p,b))}return h.length===0?null:h}addChangedExistingAnnotation({annotationElementId:t,id:e}){(l(this,da)||m(this,da,new Map)).set(t,e)}removeChangedExistingAnnotation({annotationElementId:t}){var e;(e=l(this,da))==null||e.delete(t)}renderAnnotationElement(t){var i;const e=(i=l(this,da))==null?void 0:i.get(t.data.id);if(!e)return;const s=l(this,Ui).getRawValue(e);s&&(l(this,ee)===tt.NONE&&!s.hasBeenModified||s.renderAnnotationElement(t))}};ca=new WeakMap,ss=new WeakMap,Kt=new WeakMap,ae=new WeakMap,ua=new WeakMap,Ui=new WeakMap,da=new WeakMap,ws=new WeakMap,Bn=new WeakMap,Nr=new WeakMap,fa=new WeakMap,jr=new WeakMap,ui=new WeakMap,Vs=new WeakMap,Br=new WeakMap,rl=new WeakMap,ol=new WeakMap,ga=new WeakMap,al=new WeakMap,di=new WeakMap,Hn=new WeakMap,pa=new WeakMap,Gn=new WeakMap,fi=new WeakMap,dd=new WeakMap,zn=new WeakMap,hl=new WeakMap,Vn=new WeakMap,Hr=new WeakMap,ll=new WeakMap,cl=new WeakMap,ee=new WeakMap,pt=new WeakMap,Yi=new WeakMap,Gr=new WeakMap,ul=new WeakMap,dl=new WeakMap,Xn=new WeakMap,gi=new WeakMap,$i=new WeakMap,fl=new WeakMap,xs=new WeakMap,j=new WeakSet,Dd=function({anchorNode:t}){return t.nodeType===Node.TEXT_NODE?t.parentElement:t},Jg=function(t){const{currentLayer:e}=this;if(e.hasTextLayer(t))return e;for(const s of l(this,ae).values())if(s.hasTextLayer(t))return s;return null},ty=function(){const t=document.getSelection();if(!t||t.isCollapsed)return;const s=w(this,j,Dd).call(this,t).closest(".textLayer"),i=this.getSelectionBoxes(s);i&&(l(this,fi)||m(this,fi,new Mx(this)),l(this,fi).show(s,i,this.direction==="ltr"))},ey=function(){var n,r,o;const t=document.getSelection();if(!t||t.isCollapsed){l(this,Yi)&&((n=l(this,fi))==null||n.hide(),m(this,Yi,null),w(this,j,ze).call(this,{hasSelectedText:!1}));return}const{anchorNode:e}=t;if(e===l(this,Yi))return;const i=w(this,j,Dd).call(this,t).closest(".textLayer");if(!i){l(this,Yi)&&((r=l(this,fi))==null||r.hide(),m(this,Yi,null),w(this,j,ze).call(this,{hasSelectedText:!1}));return}if((o=l(this,fi))==null||o.hide(),m(this,Yi,e),w(this,j,ze).call(this,{hasSelectedText:!0}),!(l(this,ee)!==tt.HIGHLIGHT&&l(this,ee)!==tt.NONE)&&(l(this,ee)===tt.HIGHLIGHT&&this.showAllEditors("highlight",!0,!0),m(this,Gn,this.isShiftKeyDown),!this.isShiftKeyDown)){const h=l(this,ee)===tt.HIGHLIGHT?w(this,j,Jg).call(this,i):null;h==null||h.toggleDrawing();const c=new AbortController,u=this.combinedSignal(c),d=f=>{f.type==="pointerup"&&f.button!==0||(c.abort(),h==null||h.toggleDrawing(!0),f.type==="pointerup"&&w(this,j,Od).call(this,"main_toolbar"))};window.addEventListener("pointerup",d,{signal:u}),window.addEventListener("blur",d,{signal:u})}},Od=function(t=""){l(this,ee)===tt.HIGHLIGHT?this.highlightSelection(t):l(this,rl)&&w(this,j,ty).call(this)},sy=function(){document.addEventListener("selectionchange",w(this,j,ey).bind(this),{signal:this._signal})},iy=function(){if(l(this,Hn))return;m(this,Hn,new AbortController);const t=this.combinedSignal(l(this,Hn));window.addEventListener("focus",this.focus.bind(this),{signal:t}),window.addEventListener("blur",this.blur.bind(this),{signal:t})},ny=function(){var t;(t=l(this,Hn))==null||t.abort(),m(this,Hn,null)},Zg=function(){if(l(this,Vn))return;m(this,Vn,new AbortController);const t=this.combinedSignal(l(this,Vn));window.addEventListener("keydown",this.keydown.bind(this),{signal:t}),window.addEventListener("keyup",this.keyup.bind(this),{signal:t})},ry=function(){var t;(t=l(this,Vn))==null||t.abort(),m(this,Vn,null)},tp=function(){if(l(this,Bn))return;m(this,Bn,new AbortController);const t=this.combinedSignal(l(this,Bn));document.addEventListener("copy",this.copy.bind(this),{signal:t}),document.addEventListener("cut",this.cut.bind(this),{signal:t}),document.addEventListener("paste",this.paste.bind(this),{signal:t})},ep=function(){var t;(t=l(this,Bn))==null||t.abort(),m(this,Bn,null)},oy=function(){const t=this._signal;document.addEventListener("dragover",this.dragOver.bind(this),{signal:t}),document.addEventListener("drop",this.drop.bind(this),{signal:t})},ze=function(t){Object.entries(t).some(([s,i])=>l(this,dl)[s]!==i)&&(this._eventBus.dispatch("annotationeditorstateschanged",{source:this,details:Object.assign(l(this,dl),t)}),l(this,ee)===tt.HIGHLIGHT&&t.hasSelectedEditor===!1&&w(this,j,xn).call(this,[[at.HIGHLIGHT_FREE,!0]]))},xn=function(t){this._eventBus.dispatch("annotationeditorparamschanged",{source:this,details:t})},ay=async function(){if(!l(this,zn)){m(this,zn,!0);const t=[];for(const e of l(this,ae).values())t.push(e.enable());await Promise.all(t);for(const e of l(this,Kt).values())e.enable()}},hy=function(){if(this.unselectAll(),l(this,zn)){m(this,zn,!1);for(const t of l(this,ae).values())t.disable();for(const t of l(this,Kt).values())t.disable()}},sp=function(t){const e=l(this,ae).get(t.pageIndex);e?e.addOrRebuild(t):(this.addEditor(t),this.addToAnnotationStorage(t))},ly=function(){let t=null;for(t of l(this,pt));return t},Ac=function(){if(l(this,Kt).size===0)return!0;if(l(this,Kt).size===1)for(const t of l(this,Kt).values())return t.isEmpty();return!1},ip=function(t){for(const e of l(this,pt))e.unselect();l(this,pt).clear();for(const e of t)e.isEmpty()||(l(this,pt).add(e),e.select());w(this,j,ze).call(this,{hasSelectedEditor:this.hasSelection})},q(ma,"TRANSLATE_SMALL",1),q(ma,"TRANSLATE_BIG",10);let Mr=ma;const Fe=class Fe{constructor(t){y(this,Ws);y(this,se,null);y(this,pi,!1);y(this,Xs,null);y(this,ba,null);y(this,mi,null);y(this,is,null);y(this,ya,!1);y(this,bi,null);y(this,$e,null);y(this,qi,null);y(this,zr,null);y(this,yi,!1);m(this,$e,t),m(this,yi,t._uiManager.useNewAltTextFlow),l(Fe,Wn)||m(Fe,Wn,Object.freeze({added:"pdfjs-editor-new-alt-text-added-button","added-label":"pdfjs-editor-new-alt-text-added-button-label",missing:"pdfjs-editor-new-alt-text-missing-button","missing-label":"pdfjs-editor-new-alt-text-missing-button-label",review:"pdfjs-editor-new-alt-text-to-review-button","review-label":"pdfjs-editor-new-alt-text-to-review-button-label"}))}static initialize(t){Fe._l10n??(Fe._l10n=t)}async render(){const t=m(this,Xs,document.createElement("button"));t.className="altText",t.tabIndex="0";const e=m(this,ba,document.createElement("span"));t.append(e),l(this,yi)?(t.classList.add("new"),t.setAttribute("data-l10n-id",l(Fe,Wn).missing),e.setAttribute("data-l10n-id",l(Fe,Wn)["missing-label"])):(t.setAttribute("data-l10n-id","pdfjs-editor-alt-text-button"),e.setAttribute("data-l10n-id","pdfjs-editor-alt-text-button-label"));const s=l(this,$e)._uiManager._signal;t.addEventListener("contextmenu",Gs,{signal:s}),t.addEventListener("pointerdown",n=>n.stopPropagation(),{signal:s});const i=n=>{n.preventDefault(),l(this,$e)._uiManager.editAltText(l(this,$e)),l(this,yi)&&l(this,$e)._reportTelemetry({action:"pdfjs.image.alt_text.image_status_label_clicked",data:{label:l(this,Ws,Tc)}})};return t.addEventListener("click",i,{capture:!0,signal:s}),t.addEventListener("keydown",n=>{n.target===t&&n.key==="Enter"&&(m(this,ya,!0),i(n))},{signal:s}),await w(this,Ws,Rd).call(this),t}finish(){l(this,Xs)&&(l(this,Xs).focus({focusVisible:l(this,ya)}),m(this,ya,!1))}isEmpty(){return l(this,yi)?l(this,se)===null:!l(this,se)&&!l(this,pi)}hasData(){return l(this,yi)?l(this,se)!==null||!!l(this,qi):this.isEmpty()}get guessedText(){return l(this,qi)}async setGuessedText(t){l(this,se)===null&&(m(this,qi,t),m(this,zr,await Fe._l10n.get("pdfjs-editor-new-alt-text-generated-alt-text-with-disclaimer",{generatedAltText:t})),w(this,Ws,Rd).call(this))}toggleAltTextBadge(t=!1){var e;if(!l(this,yi)||l(this,se)){(e=l(this,bi))==null||e.remove(),m(this,bi,null);return}if(!l(this,bi)){const s=m(this,bi,document.createElement("div"));s.className="noAltTextBadge",l(this,$e).div.append(s)}l(this,bi).classList.toggle("hidden",!t)}serialize(t){let e=l(this,se);return!t&&l(this,qi)===e&&(e=l(this,zr)),{altText:e,decorative:l(this,pi),guessedText:l(this,qi),textWithDisclaimer:l(this,zr)}}get data(){return{altText:l(this,se),decorative:l(this,pi)}}set data({altText:t,decorative:e,guessedText:s,textWithDisclaimer:i,cancel:n=!1}){s&&(m(this,qi,s),m(this,zr,i)),!(l(this,se)===t&&l(this,pi)===e)&&(n||(m(this,se,t),m(this,pi,e)),w(this,Ws,Rd).call(this))}toggle(t=!1){l(this,Xs)&&(!t&&l(this,is)&&(clearTimeout(l(this,is)),m(this,is,null)),l(this,Xs).disabled=!t)}shown(){l(this,$e)._reportTelemetry({action:"pdfjs.image.alt_text.image_status_label_displayed",data:{label:l(this,Ws,Tc)}})}destroy(){var t,e;(t=l(this,Xs))==null||t.remove(),m(this,Xs,null),m(this,ba,null),m(this,mi,null),(e=l(this,bi))==null||e.remove(),m(this,bi,null)}};se=new WeakMap,pi=new WeakMap,Xs=new WeakMap,ba=new WeakMap,mi=new WeakMap,is=new WeakMap,ya=new WeakMap,bi=new WeakMap,$e=new WeakMap,qi=new WeakMap,zr=new WeakMap,yi=new WeakMap,Wn=new WeakMap,Ws=new WeakSet,Tc=function(){return l(this,se)&&"added"||l(this,se)===null&&this.guessedText&&"review"||"missing"},Rd=async function(){var i,n,r;const t=l(this,Xs);if(!t)return;if(l(this,yi)){if(t.classList.toggle("done",!!l(this,se)),t.setAttribute("data-l10n-id",l(Fe,Wn)[l(this,Ws,Tc)]),(i=l(this,ba))==null||i.setAttribute("data-l10n-id",l(Fe,Wn)[`${l(this,Ws,Tc)}-label`]),!l(this,se)){(n=l(this,mi))==null||n.remove();return}}else{if(!l(this,se)&&!l(this,pi)){t.classList.remove("done"),(r=l(this,mi))==null||r.remove();return}t.classList.add("done"),t.setAttribute("data-l10n-id","pdfjs-editor-alt-text-edit-button")}let e=l(this,mi);if(!e){m(this,mi,e=document.createElement("span")),e.className="tooltip",e.setAttribute("role","tooltip"),e.id=`alt-text-tooltip-${l(this,$e).id}`;const o=100,h=l(this,$e)._uiManager._signal;h.addEventListener("abort",()=>{clearTimeout(l(this,is)),m(this,is,null)},{once:!0}),t.addEventListener("mouseenter",()=>{m(this,is,setTimeout(()=>{m(this,is,null),l(this,mi).classList.add("show"),l(this,$e)._reportTelemetry({action:"alt_text_tooltip"})},o))},{signal:h}),t.addEventListener("mouseleave",()=>{var c;l(this,is)&&(clearTimeout(l(this,is)),m(this,is,null)),(c=l(this,mi))==null||c.classList.remove("show")},{signal:h})}l(this,pi)?e.setAttribute("data-l10n-id","pdfjs-editor-alt-text-decorative-tooltip"):(e.removeAttribute("data-l10n-id"),e.textContent=l(this,se)),e.parentNode||t.append(e);const s=l(this,$e).getImageForAltText();s==null||s.setAttribute("aria-describedby",e.id)},y(Fe,Wn,null),q(Fe,"_l10n",null);let Ku=Fe;const Xg=class Xg{constructor({container:t,isPinchingDisabled:e=null,isPinchingStopped:s=null,onPinchStart:i=null,onPinching:n=null,onPinchEnd:r=null,signal:o}){y(this,Qi);y(this,gl);y(this,Vr,!1);y(this,pl,null);y(this,ml);y(this,bl);y(this,yl);y(this,vl);y(this,va);y(this,Ki,null);y(this,Xr);y(this,Un,null);m(this,gl,t),m(this,pl,s),m(this,ml,e),m(this,bl,i),m(this,yl,n),m(this,vl,r),m(this,Xr,new AbortController),m(this,va,AbortSignal.any([o,l(this,Xr).signal])),t.addEventListener("touchstart",w(this,Qi,cy).bind(this),{passive:!1,signal:l(this,va)})}get MIN_TOUCH_DISTANCE_TO_PINCH(){return it(this,"MIN_TOUCH_DISTANCE_TO_PINCH",35/(window.devicePixelRatio||1))}destroy(){var t;(t=l(this,Xr))==null||t.abort(),m(this,Xr,null)}};gl=new WeakMap,Vr=new WeakMap,pl=new WeakMap,ml=new WeakMap,bl=new WeakMap,yl=new WeakMap,vl=new WeakMap,va=new WeakMap,Ki=new WeakMap,Xr=new WeakMap,Un=new WeakMap,Qi=new WeakSet,cy=function(t){var i,n,r;if((i=l(this,ml))!=null&&i.call(this)||t.touches.length<2)return;if(!l(this,Un)){m(this,Un,new AbortController);const o=AbortSignal.any([l(this,va),l(this,Un).signal]),h=l(this,gl),c={signal:o,passive:!1};h.addEventListener("touchmove",w(this,Qi,uy).bind(this),c),h.addEventListener("touchend",w(this,Qi,np).bind(this),c),h.addEventListener("touchcancel",w(this,Qi,np).bind(this),c),(n=l(this,bl))==null||n.call(this)}if(es(t),t.touches.length!==2||(r=l(this,pl))!=null&&r.call(this)){m(this,Ki,null);return}let[e,s]=t.touches;e.identifier>s.identifier&&([e,s]=[s,e]),m(this,Ki,{touch0X:e.screenX,touch0Y:e.screenY,touch1X:s.screenX,touch1Y:s.screenY})},uy=function(t){var S;if(!l(this,Ki)||t.touches.length!==2)return;let[e,s]=t.touches;e.identifier>s.identifier&&([e,s]=[s,e]);const{screenX:i,screenY:n}=e,{screenX:r,screenY:o}=s,h=l(this,Ki),{touch0X:c,touch0Y:u,touch1X:d,touch1Y:f}=h,g=d-c,p=f-u,b=r-i,_=o-n,v=Math.hypot(b,_)||1,x=Math.hypot(g,p)||1;if(!l(this,Vr)&&Math.abs(x-v)<=Xg.MIN_TOUCH_DISTANCE_TO_PINCH)return;if(h.touch0X=i,h.touch0Y=n,h.touch1X=r,h.touch1Y=o,t.preventDefault(),!l(this,Vr)){m(this,Vr,!0);return}const C=[(i+r)/2,(n+o)/2];(S=l(this,yl))==null||S.call(this,C,x,v)},np=function(t){var e;l(this,Un).abort(),m(this,Un,null),(e=l(this,vl))==null||e.call(this),l(this,Ki)&&(t.preventDefault(),m(this,Ki,null),m(this,Vr,!1))};let Qu=Xg;const st=class st{constructor(t){y(this,$);y(this,Wr,null);y(this,Us,null);y(this,xt,null);y(this,_a,!1);y(this,Yn,null);y(this,_l,"");y(this,Ur,!1);y(this,he,null);y(this,Yr,null);y(this,Ji,null);y(this,$n,null);y(this,wl,"");y(this,$r,!1);y(this,ns,null);y(this,xl,!1);y(this,qr,!1);y(this,Zi,!1);y(this,vi,null);y(this,wa,0);y(this,xa,0);y(this,Ss,null);y(this,Kr,null);q(this,"_editToolbar",null);q(this,"_initialOptions",Object.create(null));q(this,"_initialData",null);q(this,"_isVisible",!0);q(this,"_uiManager",null);q(this,"_focusEventsAllowed",!0);y(this,Sl,!1);y(this,fd,st._zIndex++);this.parent=t.parent,this.id=t.id,this.width=this.height=null,this.pageIndex=t.parent.pageIndex,this.name=t.name,this.div=null,this._uiManager=t.uiManager,this.annotationElementId=null,this._willKeepAspectRatio=!1,this._initialOptions.isCentered=t.isCentered,this._structTreeParentId=null;const{rotation:e,rawDims:{pageWidth:s,pageHeight:i,pageX:n,pageY:r}}=this.parent.viewport;this.rotation=e,this.pageRotation=(360+e-this._uiManager.viewParameters.rotation)%360,this.pageDimensions=[s,i],this.pageTranslation=[n,r];const[o,h]=this.parentDimensions;this.x=t.x/o,this.y=t.y/h,this.isAttachedToDOM=!1,this.deleted=!1}static get _resizerKeyboardManager(){const t=st.prototype._resizeWithKeyboard,e=Mr.TRANSLATE_SMALL,s=Mr.TRANSLATE_BIG;return it(this,"_resizerKeyboardManager",new Wh([[["ArrowLeft","mac+ArrowLeft"],t,{args:[-e,0]}],[["ctrl+ArrowLeft","mac+shift+ArrowLeft"],t,{args:[-s,0]}],[["ArrowRight","mac+ArrowRight"],t,{args:[e,0]}],[["ctrl+ArrowRight","mac+shift+ArrowRight"],t,{args:[s,0]}],[["ArrowUp","mac+ArrowUp"],t,{args:[0,-e]}],[["ctrl+ArrowUp","mac+shift+ArrowUp"],t,{args:[0,-s]}],[["ArrowDown","mac+ArrowDown"],t,{args:[0,e]}],[["ctrl+ArrowDown","mac+shift+ArrowDown"],t,{args:[0,s]}],[["Escape","mac+Escape"],st.prototype._stopResizingWithKeyboard]]))}get editorType(){return Object.getPrototypeOf(this).constructor._type}static get isDrawer(){return!1}static get _defaultLineColor(){return it(this,"_defaultLineColor",this._colorManager.getHexCode("CanvasText"))}static deleteAnnotationElement(t){const e=new Ox({id:t.parent.getNextId(),parent:t.parent,uiManager:t._uiManager});e.annotationElementId=t.annotationElementId,e.deleted=!0,e._uiManager.addToAnnotationStorage(e)}static initialize(t,e){if(st._l10n??(st._l10n=t),st._l10nResizer||(st._l10nResizer=Object.freeze({topLeft:"pdfjs-editor-resizer-top-left",topMiddle:"pdfjs-editor-resizer-top-middle",topRight:"pdfjs-editor-resizer-top-right",middleRight:"pdfjs-editor-resizer-middle-right",bottomRight:"pdfjs-editor-resizer-bottom-right",bottomMiddle:"pdfjs-editor-resizer-bottom-middle",bottomLeft:"pdfjs-editor-resizer-bottom-left",middleLeft:"pdfjs-editor-resizer-middle-left"})),st._borderLineWidth!==-1)return;const s=getComputedStyle(document.documentElement);st._borderLineWidth=parseFloat(s.getPropertyValue("--outline-width"))||0}static updateDefaultParams(t,e){}static get defaultPropertiesToUpdate(){return[]}static isHandlingMimeForPasting(t){return!1}static paste(t,e){vt("Not implemented")}get propertiesToUpdate(){return[]}get _isDraggable(){return l(this,Sl)}set _isDraggable(t){var e;m(this,Sl,t),(e=this.div)==null||e.classList.toggle("draggable",t)}get isEnterHandled(){return!0}center(){const[t,e]=this.pageDimensions;switch(this.parentRotation){case 90:this.x-=this.height*e/(t*2),this.y+=this.width*t/(e*2);break;case 180:this.x+=this.width/2,this.y+=this.height/2;break;case 270:this.x+=this.height*e/(t*2),this.y-=this.width*t/(e*2);break;default:this.x-=this.width/2,this.y-=this.height/2;break}this.fixAndSetPosition()}addCommands(t){this._uiManager.addCommands(t)}get currentLayer(){return this._uiManager.currentLayer}setInBackground(){this.div.style.zIndex=0}setInForeground(){this.div.style.zIndex=l(this,fd)}setParent(t){t!==null?(this.pageIndex=t.pageIndex,this.pageDimensions=t.pageDimensions):w(this,$,Ec).call(this),this.parent=t}focusin(t){this._focusEventsAllowed&&(l(this,$r)?m(this,$r,!1):this.parent.setSelected(this))}focusout(t){var s;if(!this._focusEventsAllowed||!this.isAttachedToDOM)return;const e=t.relatedTarget;e!=null&&e.closest(`#${this.id}`)||(t.preventDefault(),(s=this.parent)!=null&&s.isMultipleSelection||this.commitOrRemove())}commitOrRemove(){this.isEmpty()?this.remove():this.commit()}commit(){this.addToAnnotationStorage()}addToAnnotationStorage(){this._uiManager.addToAnnotationStorage(this)}setAt(t,e,s,i){const[n,r]=this.parentDimensions;[s,i]=this.screenToPageTranslation(s,i),this.x=(t+s)/n,this.y=(e+i)/r,this.fixAndSetPosition()}translate(t,e){w(this,$,rp).call(this,this.parentDimensions,t,e)}translateInPage(t,e){l(this,ns)||m(this,ns,[this.x,this.y,this.width,this.height]),w(this,$,rp).call(this,this.pageDimensions,t,e),this.div.scrollIntoView({block:"nearest"})}drag(t,e){l(this,ns)||m(this,ns,[this.x,this.y,this.width,this.height]);const{div:s,parentDimensions:[i,n]}=this;if(this.x+=t/i,this.y+=e/n,this.parent&&(this.x<0||this.x>1||this.y<0||this.y>1)){const{x:d,y:f}=this.div.getBoundingClientRect();this.parent.findNewParent(this,d,f)&&(this.x-=Math.floor(this.x),this.y-=Math.floor(this.y))}let{x:r,y:o}=this;const[h,c]=this.getBaseTranslation();r+=h,o+=c;const{style:u}=s;u.left=`${(100*r).toFixed(2)}%`,u.top=`${(100*o).toFixed(2)}%`,this._onTranslating(r,o),s.scrollIntoView({block:"nearest"})}_onTranslating(t,e){}_onTranslated(t,e){}get _hasBeenMoved(){return!!l(this,ns)&&(l(this,ns)[0]!==this.x||l(this,ns)[1]!==this.y)}get _hasBeenResized(){return!!l(this,ns)&&(l(this,ns)[2]!==this.width||l(this,ns)[3]!==this.height)}getBaseTranslation(){const[t,e]=this.parentDimensions,{_borderLineWidth:s}=st,i=s/t,n=s/e;switch(this.rotation){case 90:return[-i,n];case 180:return[i,n];case 270:return[i,-n];default:return[-i,-n]}}get _mustFixPosition(){return!0}fixAndSetPosition(t=this.rotation){const{div:{style:e},pageDimensions:[s,i]}=this;let{x:n,y:r,width:o,height:h}=this;if(o*=s,h*=i,n*=s,r*=i,this._mustFixPosition)switch(t){case 0:n=Math.max(0,Math.min(s-o,n)),r=Math.max(0,Math.min(i-h,r));break;case 90:n=Math.max(0,Math.min(s-h,n)),r=Math.min(i,Math.max(o,r));break;case 180:n=Math.min(s,Math.max(o,n)),r=Math.min(i,Math.max(h,r));break;case 270:n=Math.min(s,Math.max(h,n)),r=Math.max(0,Math.min(i-o,r));break}this.x=n/=s,this.y=r/=i;const[c,u]=this.getBaseTranslation();n+=c,r+=u,e.left=`${(100*n).toFixed(2)}%`,e.top=`${(100*r).toFixed(2)}%`,this.moveInDOM()}screenToPageTranslation(t,e){var s;return w(s=st,Cl,op).call(s,t,e,this.parentRotation)}pageTranslationToScreen(t,e){var s;return w(s=st,Cl,op).call(s,t,e,360-this.parentRotation)}get parentScale(){return this._uiManager.viewParameters.realScale}get parentRotation(){return(this._uiManager.viewParameters.rotation+this.pageRotation)%360}get parentDimensions(){const{parentScale:t,pageDimensions:[e,s]}=this;return[e*t,s*t]}setDims(t,e){const[s,i]=this.parentDimensions,{style:n}=this.div;n.width=`${(100*t/s).toFixed(2)}%`,l(this,Ur)||(n.height=`${(100*e/i).toFixed(2)}%`)}fixDims(){const{style:t}=this.div,{height:e,width:s}=t,i=s.endsWith("%"),n=!l(this,Ur)&&e.endsWith("%");if(i&&n)return;const[r,o]=this.parentDimensions;i||(t.width=`${(100*parseFloat(s)/r).toFixed(2)}%`),!l(this,Ur)&&!n&&(t.height=`${(100*parseFloat(e)/o).toFixed(2)}%`)}getInitialTranslation(){return[0,0]}_onResized(){}static _round(t){return Math.round(t*1e4)/1e4}_onResizing(){}altTextFinish(){var t;(t=l(this,xt))==null||t.finish()}async addEditToolbar(){return this._editToolbar||l(this,qr)?this._editToolbar:(this._editToolbar=new yg(this),this.div.append(this._editToolbar.render()),l(this,xt)&&await this._editToolbar.addAltText(l(this,xt)),this._editToolbar)}removeEditToolbar(){var t;this._editToolbar&&(this._editToolbar.remove(),this._editToolbar=null,(t=l(this,xt))==null||t.destroy())}addContainer(t){var s;const e=(s=this._editToolbar)==null?void 0:s.div;e?e.before(t):this.div.append(t)}getClientDimensions(){return this.div.getBoundingClientRect()}async addAltTextButton(){l(this,xt)||(Ku.initialize(st._l10n),m(this,xt,new Ku(this)),l(this,Wr)&&(l(this,xt).data=l(this,Wr),m(this,Wr,null)),await this.addEditToolbar())}get altTextData(){var t;return(t=l(this,xt))==null?void 0:t.data}set altTextData(t){l(this,xt)&&(l(this,xt).data=t)}get guessedAltText(){var t;return(t=l(this,xt))==null?void 0:t.guessedText}async setGuessedAltText(t){var e;await((e=l(this,xt))==null?void 0:e.setGuessedText(t))}serializeAltText(t){var e;return(e=l(this,xt))==null?void 0:e.serialize(t)}hasAltText(){return!!l(this,xt)&&!l(this,xt).isEmpty()}hasAltTextData(){var t;return((t=l(this,xt))==null?void 0:t.hasData())??!1}render(){var n;this.div=document.createElement("div"),this.div.setAttribute("data-editor-rotation",(360-this.rotation)%360),this.div.className=this.name,this.div.setAttribute("id",this.id),this.div.tabIndex=l(this,_a)?-1:0,this._isVisible||this.div.classList.add("hidden"),this.setInForeground(),w(this,$,cp).call(this);const[t,e]=this.parentDimensions;this.parentRotation%180!==0&&(this.div.style.maxWidth=`${(100*e/t).toFixed(2)}%`,this.div.style.maxHeight=`${(100*t/e).toFixed(2)}%`);const[s,i]=this.getInitialTranslation();return this.translate(s,i),qu(this,this.div,["pointerdown"]),this.isResizable&&this._uiManager._supportsPinchToZoom&&(l(this,Kr)||m(this,Kr,new Qu({container:this.div,isPinchingDisabled:()=>!this.isSelected,onPinchStart:w(this,$,gy).bind(this),onPinching:w(this,$,py).bind(this),onPinchEnd:w(this,$,my).bind(this),signal:this._uiManager._signal}))),(n=this._uiManager._editorUndoBar)==null||n.hide(),this.div}pointerdown(t){const{isMac:e}=Re.platform;if(t.button!==0||t.ctrlKey&&e){t.preventDefault();return}if(m(this,$r,!0),this._isDraggable){w(this,$,by).call(this,t);return}w(this,$,lp).call(this,t)}get isSelected(){return this._uiManager.isSelected(this)}_onStartDragging(){}_onStopDragging(){}moveInDOM(){l(this,vi)&&clearTimeout(l(this,vi)),m(this,vi,setTimeout(()=>{var t;m(this,vi,null),(t=this.parent)==null||t.moveEditorInDOM(this)},0))}_setParentAndPosition(t,e,s){t.changeParent(this),this.x=e,this.y=s,this.fixAndSetPosition(),this._onTranslated()}getRect(t,e,s=this.rotation){const i=this.parentScale,[n,r]=this.pageDimensions,[o,h]=this.pageTranslation,c=t/i,u=e/i,d=this.x*n,f=this.y*r,g=this.width*n,p=this.height*r;switch(s){case 0:return[d+c+o,r-f-u-p+h,d+c+g+o,r-f-u+h];case 90:return[d+u+o,r-f+c+h,d+u+p+o,r-f+c+g+h];case 180:return[d-c-g+o,r-f+u+h,d-c+o,r-f+u+p+h];case 270:return[d-u-p+o,r-f-c-g+h,d-u+o,r-f-c+h];default:throw new Error("Invalid rotation")}}getRectInCurrentCoords(t,e){const[s,i,n,r]=t,o=n-s,h=r-i;switch(this.rotation){case 0:return[s,e-r,o,h];case 90:return[s,e-i,h,o];case 180:return[n,e-i,o,h];case 270:return[n,e-r,h,o];default:throw new Error("Invalid rotation")}}onceAdded(t){}isEmpty(){return!1}enableEditMode(){m(this,qr,!0)}disableEditMode(){m(this,qr,!1)}isInEditMode(){return l(this,qr)}shouldGetKeyboardEvents(){return l(this,Zi)}needsToBeRebuilt(){return this.div&&!this.isAttachedToDOM}get isOnScreen(){const{top:t,left:e,bottom:s,right:i}=this.getClientDimensions(),{innerHeight:n,innerWidth:r}=window;return e<r&&i>0&&t<n&&s>0}rebuild(){w(this,$,cp).call(this)}rotate(t){}resize(){}serializeDeleted(){var t;return{id:this.annotationElementId,deleted:!0,pageIndex:this.pageIndex,popupRef:((t=this._initialData)==null?void 0:t.popupRef)||""}}serialize(t=!1,e=null){vt("An editor must be serializable")}static async deserialize(t,e,s){const i=new this.prototype.constructor({parent:e,id:e.getNextId(),uiManager:s});i.rotation=t.rotation,m(i,Wr,t.accessibilityData);const[n,r]=i.pageDimensions,[o,h,c,u]=i.getRectInCurrentCoords(t.rect,r);return i.x=o/n,i.y=h/r,i.width=c/n,i.height=u/r,i}get hasBeenModified(){return!!this.annotationElementId&&(this.deleted||this.serialize()!==null)}remove(){var t,e;if((t=l(this,$n))==null||t.abort(),m(this,$n,null),this.isEmpty()||this.commit(),this.parent?this.parent.remove(this):this._uiManager.removeEditor(this),l(this,vi)&&(clearTimeout(l(this,vi)),m(this,vi,null)),w(this,$,Ec).call(this),this.removeEditToolbar(),l(this,Ss)){for(const s of l(this,Ss).values())clearTimeout(s);m(this,Ss,null)}this.parent=null,(e=l(this,Kr))==null||e.destroy(),m(this,Kr,null)}get isResizable(){return!1}makeResizable(){this.isResizable&&(w(this,$,dy).call(this),l(this,he).classList.remove("hidden"),qu(this,this.div,["keydown"]))}get toolbarPosition(){return null}keydown(t){if(!this.isResizable||t.target!==this.div||t.key!=="Enter")return;this._uiManager.setSelected(this),m(this,Ji,{savedX:this.x,savedY:this.y,savedWidth:this.width,savedHeight:this.height});const e=l(this,he).children;if(!l(this,Us)){m(this,Us,Array.from(e));const r=w(this,$,yy).bind(this),o=w(this,$,vy).bind(this),h=this._uiManager._signal;for(const c of l(this,Us)){const u=c.getAttribute("data-resizer-name");c.setAttribute("role","spinbutton"),c.addEventListener("keydown",r,{signal:h}),c.addEventListener("blur",o,{signal:h}),c.addEventListener("focus",w(this,$,_y).bind(this,u),{signal:h}),c.setAttribute("data-l10n-id",st._l10nResizer[u])}}const s=l(this,Us)[0];let i=0;for(const r of e){if(r===s)break;i++}const n=(360-this.rotation+this.parentRotation)%360/90*(l(this,Us).length/4);if(n!==i){if(n<i)for(let o=0;o<i-n;o++)l(this,he).append(l(this,he).firstChild);else if(n>i)for(let o=0;o<n-i;o++)l(this,he).firstChild.before(l(this,he).lastChild);let r=0;for(const o of e){const c=l(this,Us)[r++].getAttribute("data-resizer-name");o.setAttribute("data-l10n-id",st._l10nResizer[c])}}w(this,$,up).call(this,0),m(this,Zi,!0),l(this,he).firstChild.focus({focusVisible:!0}),t.preventDefault(),t.stopImmediatePropagation()}_resizeWithKeyboard(t,e){l(this,Zi)&&w(this,$,hp).call(this,l(this,wl),{deltaX:t,deltaY:e,fromKeyboard:!0})}_stopResizingWithKeyboard(){w(this,$,Ec).call(this),this.div.focus()}select(){var t,e,s;if(this.makeResizable(),(t=this.div)==null||t.classList.add("selectedEditor"),!this._editToolbar){this.addEditToolbar().then(()=>{var i,n;(i=this.div)!=null&&i.classList.contains("selectedEditor")&&((n=this._editToolbar)==null||n.show())});return}(e=this._editToolbar)==null||e.show(),(s=l(this,xt))==null||s.toggleAltTextBadge(!1)}unselect(){var t,e,s,i,n;(t=l(this,he))==null||t.classList.add("hidden"),(e=this.div)==null||e.classList.remove("selectedEditor"),(s=this.div)!=null&&s.contains(document.activeElement)&&this._uiManager.currentLayer.div.focus({preventScroll:!0}),(i=this._editToolbar)==null||i.hide(),(n=l(this,xt))==null||n.toggleAltTextBadge(!0)}updateParams(t,e){}disableEditing(){}enableEditing(){}enterInEditMode(){}getImageForAltText(){return null}get contentDiv(){return this.div}get isEditing(){return l(this,xl)}set isEditing(t){m(this,xl,t),this.parent&&(t?(this.parent.setSelected(this),this.parent.setActiveEditor(this)):this.parent.setActiveEditor(null))}setAspectRatio(t,e){m(this,Ur,!0);const s=t/e,{style:i}=this.div;i.aspectRatio=s,i.height="auto"}static get MIN_SIZE(){return 16}static canCreateNewEmptyEditor(){return!0}get telemetryInitialData(){return{action:"added"}}get telemetryFinalData(){return null}_reportTelemetry(t,e=!1){if(e){l(this,Ss)||m(this,Ss,new Map);const{action:s}=t;let i=l(this,Ss).get(s);i&&clearTimeout(i),i=setTimeout(()=>{this._reportTelemetry(t),l(this,Ss).delete(s),l(this,Ss).size===0&&m(this,Ss,null)},st._telemetryTimeout),l(this,Ss).set(s,i);return}t.type||(t.type=this.editorType),this._uiManager._eventBus.dispatch("reporttelemetry",{source:this,details:{type:"editing",data:t}})}show(t=this._isVisible){this.div.classList.toggle("hidden",!t),this._isVisible=t}enable(){this.div&&(this.div.tabIndex=0),m(this,_a,!1)}disable(){this.div&&(this.div.tabIndex=-1),m(this,_a,!0)}renderAnnotationElement(t){let e=t.container.querySelector(".annotationContent");if(!e)e=document.createElement("div"),e.classList.add("annotationContent",this.editorType),t.container.prepend(e);else if(e.nodeName==="CANVAS"){const s=e;e=document.createElement("div"),e.classList.add("annotationContent",this.editorType),s.before(e)}return e}resetAnnotationElement(t){const{firstChild:e}=t.container;(e==null?void 0:e.nodeName)==="DIV"&&e.classList.contains("annotationContent")&&e.remove()}};Wr=new WeakMap,Us=new WeakMap,xt=new WeakMap,_a=new WeakMap,Yn=new WeakMap,_l=new WeakMap,Ur=new WeakMap,he=new WeakMap,Yr=new WeakMap,Ji=new WeakMap,$n=new WeakMap,wl=new WeakMap,$r=new WeakMap,ns=new WeakMap,xl=new WeakMap,qr=new WeakMap,Zi=new WeakMap,vi=new WeakMap,wa=new WeakMap,xa=new WeakMap,Ss=new WeakMap,Kr=new WeakMap,Sl=new WeakMap,fd=new WeakMap,$=new WeakSet,rp=function([t,e],s,i){[s,i]=this.screenToPageTranslation(s,i),this.x+=s/t,this.y+=i/e,this._onTranslating(this.x,this.y),this.fixAndSetPosition()},Cl=new WeakSet,op=function(t,e,s){switch(s){case 90:return[e,-t];case 180:return[-t,-e];case 270:return[-e,t];default:return[t,e]}},Ld=function(t){switch(t){case 90:{const[e,s]=this.pageDimensions;return[0,-e/s,s/e,0]}case 180:return[-1,0,0,-1];case 270:{const[e,s]=this.pageDimensions;return[0,e/s,-s/e,0]}default:return[1,0,0,1]}},dy=function(){if(l(this,he))return;m(this,he,document.createElement("div")),l(this,he).classList.add("resizers");const t=this._willKeepAspectRatio?["topLeft","topRight","bottomRight","bottomLeft"]:["topLeft","topMiddle","topRight","middleRight","bottomRight","bottomMiddle","bottomLeft","middleLeft"],e=this._uiManager._signal;for(const s of t){const i=document.createElement("div");l(this,he).append(i),i.classList.add("resizer",s),i.setAttribute("data-resizer-name",s),i.addEventListener("pointerdown",w(this,$,fy).bind(this,s),{signal:e}),i.addEventListener("contextmenu",Gs,{signal:e}),i.tabIndex=-1}this.div.prepend(l(this,he))},fy=function(t,e){var u;e.preventDefault();const{isMac:s}=Re.platform;if(e.button!==0||e.ctrlKey&&s)return;(u=l(this,xt))==null||u.toggle(!1);const i=this._isDraggable;this._isDraggable=!1,m(this,Yr,[e.screenX,e.screenY]);const n=new AbortController,r=this._uiManager.combinedSignal(n);this.parent.togglePointerEvents(!1),window.addEventListener("pointermove",w(this,$,hp).bind(this,t),{passive:!0,capture:!0,signal:r}),window.addEventListener("touchmove",es,{passive:!1,signal:r}),window.addEventListener("contextmenu",Gs,{signal:r}),m(this,Ji,{savedX:this.x,savedY:this.y,savedWidth:this.width,savedHeight:this.height});const o=this.parent.div.style.cursor,h=this.div.style.cursor;this.div.style.cursor=this.parent.div.style.cursor=window.getComputedStyle(e.target).cursor;const c=()=>{var d;n.abort(),this.parent.togglePointerEvents(!0),(d=l(this,xt))==null||d.toggle(!0),this._isDraggable=i,this.parent.div.style.cursor=o,this.div.style.cursor=h,w(this,$,Fd).call(this)};window.addEventListener("pointerup",c,{signal:r}),window.addEventListener("blur",c,{signal:r})},ap=function(t,e,s,i){this.width=s,this.height=i,this.x=t,this.y=e;const[n,r]=this.parentDimensions;this.setDims(n*s,r*i),this.fixAndSetPosition(),this._onResized()},Fd=function(){if(!l(this,Ji))return;const{savedX:t,savedY:e,savedWidth:s,savedHeight:i}=l(this,Ji);m(this,Ji,null);const n=this.x,r=this.y,o=this.width,h=this.height;n===t&&r===e&&o===s&&h===i||this.addCommands({cmd:w(this,$,ap).bind(this,n,r,o,h),undo:w(this,$,ap).bind(this,t,e,s,i),mustExec:!0})},hp=function(t,e){const[s,i]=this.parentDimensions,n=this.x,r=this.y,o=this.width,h=this.height,c=st.MIN_SIZE/s,u=st.MIN_SIZE/i,d=w(this,$,Ld).call(this,this.rotation),f=(I,X)=>[d[0]*I+d[2]*X,d[1]*I+d[3]*X],g=w(this,$,Ld).call(this,360-this.rotation),p=(I,X)=>[g[0]*I+g[2]*X,g[1]*I+g[3]*X];let b,_,v=!1,x=!1;switch(t){case"topLeft":v=!0,b=(I,X)=>[0,0],_=(I,X)=>[I,X];break;case"topMiddle":b=(I,X)=>[I/2,0],_=(I,X)=>[I/2,X];break;case"topRight":v=!0,b=(I,X)=>[I,0],_=(I,X)=>[0,X];break;case"middleRight":x=!0,b=(I,X)=>[I,X/2],_=(I,X)=>[0,X/2];break;case"bottomRight":v=!0,b=(I,X)=>[I,X],_=(I,X)=>[0,0];break;case"bottomMiddle":b=(I,X)=>[I/2,X],_=(I,X)=>[I/2,0];break;case"bottomLeft":v=!0,b=(I,X)=>[0,X],_=(I,X)=>[I,0];break;case"middleLeft":x=!0,b=(I,X)=>[0,X/2],_=(I,X)=>[I,X/2];break}const C=b(o,h),S=_(o,h);let E=f(...S);const k=st._round(n+E[0]),M=st._round(r+E[1]);let D=1,R=1,B,O;if(e.fromKeyboard)({deltaX:B,deltaY:O}=e);else{const{screenX:I,screenY:X}=e,[rt,Gt]=l(this,Yr);[B,O]=this.screenToPageTranslation(I-rt,X-Gt),l(this,Yr)[0]=I,l(this,Yr)[1]=X}if([B,O]=p(B/s,O/i),v){const I=Math.hypot(o,h);D=R=Math.max(Math.min(Math.hypot(S[0]-C[0]-B,S[1]-C[1]-O)/I,1/o,1/h),c/o,u/h)}else x?D=Math.max(c,Math.min(1,Math.abs(S[0]-C[0]-B)))/o:R=Math.max(u,Math.min(1,Math.abs(S[1]-C[1]-O)))/h;const F=st._round(o*D),L=st._round(h*R);E=f(..._(F,L));const N=k-E[0],Y=M-E[1];l(this,ns)||m(this,ns,[this.x,this.y,this.width,this.height]),this.width=F,this.height=L,this.x=N,this.y=Y,this.setDims(s*F,i*L),this.fixAndSetPosition(),this._onResizing()},gy=function(){var t;m(this,Ji,{savedX:this.x,savedY:this.y,savedWidth:this.width,savedHeight:this.height}),(t=l(this,xt))==null||t.toggle(!1),this.parent.togglePointerEvents(!1)},py=function(t,e,s){let n=.7*(s/e)+1-.7;if(n===1)return;const r=w(this,$,Ld).call(this,this.rotation),o=(k,M)=>[r[0]*k+r[2]*M,r[1]*k+r[3]*M],[h,c]=this.parentDimensions,u=this.x,d=this.y,f=this.width,g=this.height,p=st.MIN_SIZE/h,b=st.MIN_SIZE/c;n=Math.max(Math.min(n,1/f,1/g),p/f,b/g);const _=st._round(f*n),v=st._round(g*n);if(_===f&&v===g)return;l(this,ns)||m(this,ns,[u,d,f,g]);const x=o(f/2,g/2),C=st._round(u+x[0]),S=st._round(d+x[1]),E=o(_/2,v/2);this.x=C-E[0],this.y=S-E[1],this.width=_,this.height=v,this.setDims(h*_,c*v),this.fixAndSetPosition(),this._onResizing()},my=function(){var t;(t=l(this,xt))==null||t.toggle(!0),this.parent.togglePointerEvents(!0),w(this,$,Fd).call(this)},lp=function(t){const{isMac:e}=Re.platform;t.ctrlKey&&!e||t.shiftKey||t.metaKey&&e?this.parent.toggleSelected(this):this.parent.setSelected(this)},by=function(t){const{isSelected:e}=this;this._uiManager.setUpDragSession();let s=!1;const i=new AbortController,n=this._uiManager.combinedSignal(i),r={capture:!0,passive:!1,signal:n},o=c=>{i.abort(),m(this,Yn,null),m(this,$r,!1),this._uiManager.endDragSession()||w(this,$,lp).call(this,c),s&&this._onStopDragging()};e&&(m(this,wa,t.clientX),m(this,xa,t.clientY),m(this,Yn,t.pointerId),m(this,_l,t.pointerType),window.addEventListener("pointermove",c=>{s||(s=!0,this._onStartDragging());const{clientX:u,clientY:d,pointerId:f}=c;if(f!==l(this,Yn)){es(c);return}const[g,p]=this.screenToPageTranslation(u-l(this,wa),d-l(this,xa));m(this,wa,u),m(this,xa,d),this._uiManager.dragSelectedEditors(g,p)},r),window.addEventListener("touchmove",es,r),window.addEventListener("pointerdown",c=>{c.pointerType===l(this,_l)&&(l(this,Kr)||c.isPrimary)&&o(c),es(c)},r));const h=c=>{if(!l(this,Yn)||l(this,Yn)===c.pointerId){o(c);return}es(c)};window.addEventListener("pointerup",h,{signal:n}),window.addEventListener("blur",h,{signal:n})},cp=function(){if(l(this,$n)||!this.div)return;m(this,$n,new AbortController);const t=this._uiManager.combinedSignal(l(this,$n));this.div.addEventListener("focusin",this.focusin.bind(this),{signal:t}),this.div.addEventListener("focusout",this.focusout.bind(this),{signal:t})},yy=function(t){st._resizerKeyboardManager.exec(this,t)},vy=function(t){var e;l(this,Zi)&&((e=t.relatedTarget)==null?void 0:e.parentNode)!==l(this,he)&&w(this,$,Ec).call(this)},_y=function(t){m(this,wl,l(this,Zi)?t:"")},up=function(t){if(l(this,Us))for(const e of l(this,Us))e.tabIndex=t},Ec=function(){m(this,Zi,!1),w(this,$,up).call(this,-1),w(this,$,Fd).call(this)},y(st,Cl),q(st,"_l10n",null),q(st,"_l10nResizer",null),q(st,"_borderLineWidth",-1),q(st,"_colorManager",new _g),q(st,"_zIndex",1),q(st,"_telemetryTimeout",1e3);let Pt=st;class Ox extends Pt{constructor(t){super(t),this.annotationElementId=t.annotationElementId,this.deleted=!0}serialize(){return this.serializeDeleted()}}const sb=3285377520,_s=4294901760,ci=65535;class ib{constructor(t){this.h1=t?t&4294967295:sb,this.h2=t?t&4294967295:sb}update(t){let e,s;if(typeof t=="string"){e=new Uint8Array(t.length*2),s=0;for(let b=0,_=t.length;b<_;b++){const v=t.charCodeAt(b);v<=255?e[s++]=v:(e[s++]=v>>>8,e[s++]=v&255)}}else if(ArrayBuffer.isView(t))e=t.slice(),s=e.byteLength;else throw new Error("Invalid data format, must be a string or TypedArray.");const i=s>>2,n=s-i*4,r=new Uint32Array(e.buffer,0,i);let o=0,h=0,c=this.h1,u=this.h2;const d=3432918353,f=461845907,g=d&ci,p=f&ci;for(let b=0;b<i;b++)b&1?(o=r[b],o=o*d&_s|o*g&ci,o=o<<15|o>>>17,o=o*f&_s|o*p&ci,c^=o,c=c<<13|c>>>19,c=c*5+3864292196):(h=r[b],h=h*d&_s|h*g&ci,h=h<<15|h>>>17,h=h*f&_s|h*p&ci,u^=h,u=u<<13|u>>>19,u=u*5+3864292196);switch(o=0,n){case 3:o^=e[i*4+2]<<16;case 2:o^=e[i*4+1]<<8;case 1:o^=e[i*4],o=o*d&_s|o*g&ci,o=o<<15|o>>>17,o=o*f&_s|o*p&ci,i&1?c^=o:u^=o}this.h1=c,this.h2=u}hexdigest(){let t=this.h1,e=this.h2;return t^=e>>>1,t=t*3981806797&_s|t*36045&ci,e=e*4283543511&_s|((e<<16|t>>>16)*2950163797&_s)>>>16,t^=e>>>1,t=t*444984403&_s|t*60499&ci,e=e*3301882366&_s|((e<<16|t>>>16)*3120437893&_s)>>>16,t^=e>>>1,(t>>>0).toString(16).padStart(8,"0")+(e>>>0).toString(16).padStart(8,"0")}}const wg=Object.freeze({map:null,hash:"",transfer:void 0});class xg{constructor(){y(this,gd);y(this,Qr,!1);y(this,Jr,null);y(this,ie,new Map);this.onSetModified=null,this.onResetModified=null,this.onAnnotationEditor=null}getValue(t,e){const s=l(this,ie).get(t);return s===void 0?e:Object.assign(e,s)}getRawValue(t){return l(this,ie).get(t)}remove(t){if(l(this,ie).delete(t),l(this,ie).size===0&&this.resetModified(),typeof this.onAnnotationEditor=="function"){for(const e of l(this,ie).values())if(e instanceof Pt)return;this.onAnnotationEditor(null)}}setValue(t,e){const s=l(this,ie).get(t);let i=!1;if(s!==void 0)for(const[n,r]of Object.entries(e))s[n]!==r&&(i=!0,s[n]=r);else i=!0,l(this,ie).set(t,e);i&&w(this,gd,wy).call(this),e instanceof Pt&&typeof this.onAnnotationEditor=="function"&&this.onAnnotationEditor(e.constructor._type)}has(t){return l(this,ie).has(t)}getAll(){return l(this,ie).size>0?lg(l(this,ie)):null}setAll(t){for(const[e,s]of Object.entries(t))this.setValue(e,s)}get size(){return l(this,ie).size}resetModified(){l(this,Qr)&&(m(this,Qr,!1),typeof this.onResetModified=="function"&&this.onResetModified())}get print(){return new nb(this)}get serializable(){if(l(this,ie).size===0)return wg;const t=new Map,e=new ib,s=[],i=Object.create(null);let n=!1;for(const[r,o]of l(this,ie)){const h=o instanceof Pt?o.serialize(!1,i):o;h&&(t.set(r,h),e.update(`${r}:${JSON.stringify(h)}`),n||(n=!!h.bitmap))}if(n)for(const r of t.values())r.bitmap&&s.push(r.bitmap);return t.size>0?{map:t,hash:e.hexdigest(),transfer:s}:wg}get editorStats(){let t=null;const e=new Map;for(const s of l(this,ie).values()){if(!(s instanceof Pt))continue;const i=s.telemetryFinalData;if(!i)continue;const{type:n}=i;e.has(n)||e.set(n,Object.getPrototypeOf(s).constructor),t||(t=Object.create(null));const r=t[n]||(t[n]=new Map);for(const[o,h]of Object.entries(i)){if(o==="type")continue;let c=r.get(o);c||(c=new Map,r.set(o,c));const u=c.get(h)??0;c.set(h,u+1)}}for(const[s,i]of e)t[s]=i.computeTelemetryFinalData(t[s]);return t}resetModifiedIds(){m(this,Jr,null)}get modifiedIds(){if(l(this,Jr))return l(this,Jr);const t=[];for(const e of l(this,ie).values())!(e instanceof Pt)||!e.annotationElementId||!e.serialize()||t.push(e.annotationElementId);return m(this,Jr,{ids:new Set(t),hash:t.join(",")})}}Qr=new WeakMap,Jr=new WeakMap,ie=new WeakMap,gd=new WeakSet,wy=function(){l(this,Qr)||(m(this,Qr,!0),typeof this.onSetModified=="function"&&this.onSetModified())};class nb extends xg{constructor(e){super();y(this,Al);const{map:s,hash:i,transfer:n}=e.serializable,r=structuredClone(s,n?{transfer:n}:null);m(this,Al,{map:r,hash:i,transfer:n})}get print(){vt("Should not call PrintAnnotationStorage.print")}get serializable(){return l(this,Al)}get modifiedIds(){return it(this,"modifiedIds",{ids:new Set,hash:""})}}Al=new WeakMap;class Rx{constructor({ownerDocument:t=globalThis.document,styleElement:e=null}){y(this,Sa,new Set);this._document=t,this.nativeFontFaces=new Set,this.styleElement=null,this.loadingRequests=[],this.loadTestFontId=0}addNativeFontFace(t){this.nativeFontFaces.add(t),this._document.fonts.add(t)}removeNativeFontFace(t){this.nativeFontFaces.delete(t),this._document.fonts.delete(t)}insertRule(t){this.styleElement||(this.styleElement=this._document.createElement("style"),this._document.documentElement.getElementsByTagName("head")[0].append(this.styleElement));const e=this.styleElement.sheet;e.insertRule(t,e.cssRules.length)}clear(){for(const t of this.nativeFontFaces)this._document.fonts.delete(t);this.nativeFontFaces.clear(),l(this,Sa).clear(),this.styleElement&&(this.styleElement.remove(),this.styleElement=null)}async loadSystemFont({systemFontInfo:t,_inspectFont:e}){if(!(!t||l(this,Sa).has(t.loadedName))){if(Xt(!this.disableFontFace,"loadSystemFont shouldn't be called when `disableFontFace` is set."),this.isFontLoadingAPISupported){const{loadedName:s,src:i,style:n}=t,r=new FontFace(s,i,n);this.addNativeFontFace(r);try{await r.load(),l(this,Sa).add(s),e==null||e(t)}catch{et(`Cannot load system font: ${t.baseFontName}, installing it could help to improve PDF rendering.`),this.removeNativeFontFace(r)}return}vt("Not implemented: loadSystemFont without the Font Loading API.")}}async bind(t){if(t.attached||t.missingFile&&!t.systemFontInfo)return;if(t.attached=!0,t.systemFontInfo){await this.loadSystemFont(t);return}if(this.isFontLoadingAPISupported){const s=t.createNativeFontFace();if(s){this.addNativeFontFace(s);try{await s.loaded}catch(i){throw et(`Failed to load font '${s.family}': '${i}'.`),t.disableFontFace=!0,i}}return}const e=t.createFontFaceRule();if(e){if(this.insertRule(e),this.isSyncFontLoadingSupported)return;await new Promise(s=>{const i=this._queueLoadingCallback(s);this._prepareFontLoadEvent(t,i)})}}get isFontLoadingAPISupported(){var e;const t=!!((e=this._document)!=null&&e.fonts);return it(this,"isFontLoadingAPISupported",t)}get isSyncFontLoadingSupported(){let t=!1;return(ye||typeof navigator<"u"&&typeof(navigator==null?void 0:navigator.userAgent)=="string"&&/Mozilla\/5.0.*?rv:\d+.*? Gecko/.test(navigator.userAgent))&&(t=!0),it(this,"isSyncFontLoadingSupported",t)}_queueLoadingCallback(t){function e(){for(Xt(!i.done,"completeRequest() cannot be called twice."),i.done=!0;s.length>0&&s[0].done;){const n=s.shift();setTimeout(n.callback,0)}}const{loadingRequests:s}=this,i={done:!1,complete:e,callback:t};return s.push(i),i}get _loadTestFont(){const t=atob("T1RUTwALAIAAAwAwQ0ZGIDHtZg4AAAOYAAAAgUZGVE1lkzZwAAAEHAAAABxHREVGABQAFQAABDgAAAAeT1MvMlYNYwkAAAEgAAAAYGNtYXABDQLUAAACNAAAAUJoZWFk/xVFDQAAALwAAAA2aGhlYQdkA+oAAAD0AAAAJGhtdHgD6AAAAAAEWAAAAAZtYXhwAAJQAAAAARgAAAAGbmFtZVjmdH4AAAGAAAAAsXBvc3T/hgAzAAADeAAAACAAAQAAAAEAALZRFsRfDzz1AAsD6AAAAADOBOTLAAAAAM4KHDwAAAAAA+gDIQAAAAgAAgAAAAAAAAABAAADIQAAAFoD6AAAAAAD6AABAAAAAAAAAAAAAAAAAAAAAQAAUAAAAgAAAAQD6AH0AAUAAAKKArwAAACMAooCvAAAAeAAMQECAAACAAYJAAAAAAAAAAAAAQAAAAAAAAAAAAAAAFBmRWQAwAAuAC4DIP84AFoDIQAAAAAAAQAAAAAAAAAAACAAIAABAAAADgCuAAEAAAAAAAAAAQAAAAEAAAAAAAEAAQAAAAEAAAAAAAIAAQAAAAEAAAAAAAMAAQAAAAEAAAAAAAQAAQAAAAEAAAAAAAUAAQAAAAEAAAAAAAYAAQAAAAMAAQQJAAAAAgABAAMAAQQJAAEAAgABAAMAAQQJAAIAAgABAAMAAQQJAAMAAgABAAMAAQQJAAQAAgABAAMAAQQJAAUAAgABAAMAAQQJAAYAAgABWABYAAAAAAAAAwAAAAMAAAAcAAEAAAAAADwAAwABAAAAHAAEACAAAAAEAAQAAQAAAC7//wAAAC7////TAAEAAAAAAAABBgAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMAAAAAAAD/gwAyAAAAAQAAAAAAAAAAAAAAAAAAAAABAAQEAAEBAQJYAAEBASH4DwD4GwHEAvgcA/gXBIwMAYuL+nz5tQXkD5j3CBLnEQACAQEBIVhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYAAABAQAADwACAQEEE/t3Dov6fAH6fAT+fPp8+nwHDosMCvm1Cvm1DAz6fBQAAAAAAAABAAAAAMmJbzEAAAAAzgTjFQAAAADOBOQpAAEAAAAAAAAADAAUAAQAAAABAAAAAgABAAAAAAAAAAAD6AAAAAAAAA==");return it(this,"_loadTestFont",t)}_prepareFontLoadEvent(t,e){function s(S,E){return S.charCodeAt(E)<<24|S.charCodeAt(E+1)<<16|S.charCodeAt(E+2)<<8|S.charCodeAt(E+3)&255}function i(S,E,k,M){const D=S.substring(0,E),R=S.substring(E+k);return D+M+R}let n,r;const o=this._document.createElement("canvas");o.width=1,o.height=1;const h=o.getContext("2d");let c=0;function u(S,E){if(++c>30){et("Load test font never loaded."),E();return}if(h.font="30px "+S,h.fillText(".",0,20),h.getImageData(0,0,1,1).data[3]>0){E();return}setTimeout(u.bind(null,S,E))}const d=`lt${Date.now()}${this.loadTestFontId++}`;let f=this._loadTestFont;f=i(f,976,d.length,d);const p=16,b=1482184792;let _=s(f,p);for(n=0,r=d.length-3;n<r;n+=4)_=_-b+s(d,n)|0;n<d.length&&(_=_-b+s(d+"XXX",n)|0),f=i(f,p,4,yx(_));const v=`url(data:font/opentype;base64,${btoa(f)});`,x=`@font-face {font-family:"${d}";src:${v}}`;this.insertRule(x);const C=this._document.createElement("div");C.style.visibility="hidden",C.style.width=C.style.height="10px",C.style.position="absolute",C.style.top=C.style.left="0px";for(const S of[t.loadedName,d]){const E=this._document.createElement("span");E.textContent="Hi",E.style.fontFamily=S,C.append(E)}this._document.body.append(C),u(d,()=>{C.remove(),e.complete()})}}Sa=new WeakMap;class Lx{constructor(t,{disableFontFace:e=!1,fontExtraProperties:s=!1,inspectFont:i=null}){this.compiledGlyphs=Object.create(null);for(const n in t)this[n]=t[n];this.disableFontFace=e===!0,this.fontExtraProperties=s===!0,this._inspectFont=i}createNativeFontFace(){var e;if(!this.data||this.disableFontFace)return null;let t;if(!this.cssFontInfo)t=new FontFace(this.loadedName,this.data,{});else{const s={weight:this.cssFontInfo.fontWeight};this.cssFontInfo.italicAngle&&(s.style=`oblique ${this.cssFontInfo.italicAngle}deg`),t=new FontFace(this.cssFontInfo.fontFamily,this.data,s)}return(e=this._inspectFont)==null||e.call(this,this),t}createFontFaceRule(){var s;if(!this.data||this.disableFontFace)return null;const t=`url(data:${this.mimetype};base64,${Cx(this.data)});`;let e;if(!this.cssFontInfo)e=`@font-face {font-family:"${this.loadedName}";src:${t}}`;else{let i=`font-weight: ${this.cssFontInfo.fontWeight};`;this.cssFontInfo.italicAngle&&(i+=`font-style: oblique ${this.cssFontInfo.italicAngle}deg;`),e=`@font-face {font-family:"${this.cssFontInfo.fontFamily}";${i}src:${t}}`}return(s=this._inspectFont)==null||s.call(this,this,t),e}getPathGenerator(t,e){if(this.compiledGlyphs[e]!==void 0)return this.compiledGlyphs[e];const s=this.loadedName+"_path_"+e;let i;try{i=t.get(s)}catch(r){et(`getPathGenerator - ignoring character: "${r}".`)}const n=new Path2D(i||"");return this.fontExtraProperties||t.delete(s),this.compiledGlyphs[e]=n}}const Ju={DATA:1,ERROR:2},Wt={CANCEL:1,CANCEL_COMPLETE:2,CLOSE:3,ENQUEUE:4,ERROR:5,PULL:6,PULL_COMPLETE:7,START_COMPLETE:8};function rb(){}function We(a){if(a instanceof Rn||a instanceof hg||a instanceof zh||a instanceof J0||a instanceof Wu||a instanceof ag)return a;switch(a instanceof Error||typeof a=="object"&&a!==null||vt('wrapReason: Expected "reason" to be a (possibly cloned) Error.'),a.name){case"AbortException":return new Rn(a.message);case"InvalidPDFException":return new hg(a.message);case"MissingPDFException":return new zh(a.message);case"PasswordException":return new J0(a.message,a.code);case"UnexpectedResponseException":return new Wu(a.message,a.status);case"UnknownErrorException":return new ag(a.message,a.details)}return new ag(a.message,a.toString())}class Uh{constructor(t,e,s){y(this,Cs);y(this,Ca,new AbortController);this.sourceName=t,this.targetName=e,this.comObj=s,this.callbackId=1,this.streamId=1,this.streamSinks=Object.create(null),this.streamControllers=Object.create(null),this.callbackCapabilities=Object.create(null),this.actionHandler=Object.create(null),s.addEventListener("message",w(this,Cs,xy).bind(this),{signal:l(this,Ca).signal})}on(t,e){const s=this.actionHandler;if(s[t])throw new Error(`There is already an actionName called "${t}"`);s[t]=e}send(t,e,s){this.comObj.postMessage({sourceName:this.sourceName,targetName:this.targetName,action:t,data:e},s)}sendWithPromise(t,e,s){const i=this.callbackId++,n=Promise.withResolvers();this.callbackCapabilities[i]=n;try{this.comObj.postMessage({sourceName:this.sourceName,targetName:this.targetName,action:t,callbackId:i,data:e},s)}catch(r){n.reject(r)}return n.promise}sendWithStream(t,e,s,i){const n=this.streamId++,r=this.sourceName,o=this.targetName,h=this.comObj;return new ReadableStream({start:c=>{const u=Promise.withResolvers();return this.streamControllers[n]={controller:c,startCall:u,pullCall:null,cancelCall:null,isClosed:!1},h.postMessage({sourceName:r,targetName:o,action:t,streamId:n,data:e,desiredSize:c.desiredSize},i),u.promise},pull:c=>{const u=Promise.withResolvers();return this.streamControllers[n].pullCall=u,h.postMessage({sourceName:r,targetName:o,stream:Wt.PULL,streamId:n,desiredSize:c.desiredSize}),u.promise},cancel:c=>{Xt(c instanceof Error,"cancel must have a valid reason");const u=Promise.withResolvers();return this.streamControllers[n].cancelCall=u,this.streamControllers[n].isClosed=!0,h.postMessage({sourceName:r,targetName:o,stream:Wt.CANCEL,streamId:n,reason:We(c)}),u.promise}},s)}destroy(){var t;(t=l(this,Ca))==null||t.abort(),m(this,Ca,null)}}Ca=new WeakMap,Cs=new WeakSet,xy=function({data:t}){if(t.targetName!==this.sourceName)return;if(t.stream){w(this,Cs,Cy).call(this,t);return}if(t.callback){const s=t.callbackId,i=this.callbackCapabilities[s];if(!i)throw new Error(`Cannot resolve callback ${s}`);if(delete this.callbackCapabilities[s],t.callback===Ju.DATA)i.resolve(t.data);else if(t.callback===Ju.ERROR)i.reject(We(t.reason));else throw new Error("Unexpected callback case");return}const e=this.actionHandler[t.action];if(!e)throw new Error(`Unknown action from worker: ${t.action}`);if(t.callbackId){const s=this.sourceName,i=t.sourceName,n=this.comObj;Promise.try(e,t.data).then(function(r){n.postMessage({sourceName:s,targetName:i,callback:Ju.DATA,callbackId:t.callbackId,data:r})},function(r){n.postMessage({sourceName:s,targetName:i,callback:Ju.ERROR,callbackId:t.callbackId,reason:We(r)})});return}if(t.streamId){w(this,Cs,Sy).call(this,t);return}e(t.data)},Sy=function(t){const e=t.streamId,s=this.sourceName,i=t.sourceName,n=this.comObj,r=this,o=this.actionHandler[t.action],h={enqueue(c,u=1,d){if(this.isCancelled)return;const f=this.desiredSize;this.desiredSize-=u,f>0&&this.desiredSize<=0&&(this.sinkCapability=Promise.withResolvers(),this.ready=this.sinkCapability.promise),n.postMessage({sourceName:s,targetName:i,stream:Wt.ENQUEUE,streamId:e,chunk:c},d)},close(){this.isCancelled||(this.isCancelled=!0,n.postMessage({sourceName:s,targetName:i,stream:Wt.CLOSE,streamId:e}),delete r.streamSinks[e])},error(c){Xt(c instanceof Error,"error must have a valid reason"),!this.isCancelled&&(this.isCancelled=!0,n.postMessage({sourceName:s,targetName:i,stream:Wt.ERROR,streamId:e,reason:We(c)}))},sinkCapability:Promise.withResolvers(),onPull:null,onCancel:null,isCancelled:!1,desiredSize:t.desiredSize,ready:null};h.sinkCapability.resolve(),h.ready=h.sinkCapability.promise,this.streamSinks[e]=h,Promise.try(o,t.data,h).then(function(){n.postMessage({sourceName:s,targetName:i,stream:Wt.START_COMPLETE,streamId:e,success:!0})},function(c){n.postMessage({sourceName:s,targetName:i,stream:Wt.START_COMPLETE,streamId:e,reason:We(c)})})},Cy=function(t){const e=t.streamId,s=this.sourceName,i=t.sourceName,n=this.comObj,r=this.streamControllers[e],o=this.streamSinks[e];switch(t.stream){case Wt.START_COMPLETE:t.success?r.startCall.resolve():r.startCall.reject(We(t.reason));break;case Wt.PULL_COMPLETE:t.success?r.pullCall.resolve():r.pullCall.reject(We(t.reason));break;case Wt.PULL:if(!o){n.postMessage({sourceName:s,targetName:i,stream:Wt.PULL_COMPLETE,streamId:e,success:!0});break}o.desiredSize<=0&&t.desiredSize>0&&o.sinkCapability.resolve(),o.desiredSize=t.desiredSize,Promise.try(o.onPull||rb).then(function(){n.postMessage({sourceName:s,targetName:i,stream:Wt.PULL_COMPLETE,streamId:e,success:!0})},function(c){n.postMessage({sourceName:s,targetName:i,stream:Wt.PULL_COMPLETE,streamId:e,reason:We(c)})});break;case Wt.ENQUEUE:if(Xt(r,"enqueue should have stream controller"),r.isClosed)break;r.controller.enqueue(t.chunk);break;case Wt.CLOSE:if(Xt(r,"close should have stream controller"),r.isClosed)break;r.isClosed=!0,r.controller.close(),w(this,Cs,Id).call(this,r,e);break;case Wt.ERROR:Xt(r,"error should have stream controller"),r.controller.error(We(t.reason)),w(this,Cs,Id).call(this,r,e);break;case Wt.CANCEL_COMPLETE:t.success?r.cancelCall.resolve():r.cancelCall.reject(We(t.reason)),w(this,Cs,Id).call(this,r,e);break;case Wt.CANCEL:if(!o)break;const h=We(t.reason);Promise.try(o.onCancel||rb,h).then(function(){n.postMessage({sourceName:s,targetName:i,stream:Wt.CANCEL_COMPLETE,streamId:e,success:!0})},function(c){n.postMessage({sourceName:s,targetName:i,stream:Wt.CANCEL_COMPLETE,streamId:e,reason:We(c)})}),o.sinkCapability.reject(h),o.isCancelled=!0,delete this.streamSinks[e];break;default:throw new Error("Unexpected stream case")}},Id=async function(t,e){var s,i,n;await Promise.allSettled([(s=t.startCall)==null?void 0:s.promise,(i=t.pullCall)==null?void 0:i.promise,(n=t.cancelCall)==null?void 0:n.promise]),delete this.streamControllers[e]};class ob{constructor({enableHWA:t=!1}){y(this,Tl,!1);m(this,Tl,t)}create(t,e){if(t<=0||e<=0)throw new Error("Invalid canvas size");const s=this._createCanvas(t,e);return{canvas:s,context:s.getContext("2d",{willReadFrequently:!l(this,Tl)})}}reset(t,e,s){if(!t.canvas)throw new Error("Canvas is not specified");if(e<=0||s<=0)throw new Error("Invalid canvas size");t.canvas.width=e,t.canvas.height=s}destroy(t){if(!t.canvas)throw new Error("Canvas is not specified");t.canvas.width=0,t.canvas.height=0,t.canvas=null,t.context=null}_createCanvas(t,e){vt("Abstract method `_createCanvas` called.")}}Tl=new WeakMap;class Fx extends ob{constructor({ownerDocument:t=globalThis.document,enableHWA:e=!1}){super({enableHWA:e}),this._document=t}_createCanvas(t,e){const s=this._document.createElement("canvas");return s.width=t,s.height=e,s}}class ab{constructor({baseUrl:t=null,isCompressed:e=!0}){this.baseUrl=t,this.isCompressed=e}async fetch({name:t}){if(!this.baseUrl)throw new Error("Ensure that the `cMapUrl` and `cMapPacked` API parameters are provided.");if(!t)throw new Error("CMap name must be specified.");const e=this.baseUrl+t+(this.isCompressed?".bcmap":"");return this._fetch(e).then(s=>({cMapData:s,isCompressed:this.isCompressed})).catch(s=>{throw new Error(`Unable to load ${this.isCompressed?"binary ":""}CMap at: ${e}`)})}async _fetch(t){vt("Abstract method `_fetch` called.")}}class hb extends ab{async _fetch(t){const e=await Yu(t,this.isCompressed?"arraybuffer":"text");return e instanceof ArrayBuffer?new Uint8Array(e):Uu(e)}}class lb{addFilter(t){return"none"}addHCMFilter(t,e){return"none"}addAlphaFilter(t){return"none"}addLuminosityFilter(t){return"none"}addHighlightHCMFilter(t,e,s,i,n){return"none"}destroy(t=!1){}}class Ix extends lb{constructor({docId:e,ownerDocument:s=globalThis.document}){super();y(this,G);y(this,Zr);y(this,Aa);y(this,tn);y(this,en);y(this,xe);y(this,to);y(this,eo,0);m(this,en,e),m(this,xe,s)}addFilter(e){if(!e)return"none";let s=l(this,G,Te).get(e);if(s)return s;const[i,n,r]=w(this,G,Nd).call(this,e),o=e.length===1?i:`${i}${n}${r}`;if(s=l(this,G,Te).get(o),s)return l(this,G,Te).set(e,s),s;const h=`g_${l(this,en)}_transfer_map_${Ge(this,eo)._++}`,c=w(this,G,bh).call(this,h);l(this,G,Te).set(e,c),l(this,G,Te).set(o,c);const u=w(this,G,yh).call(this,h);return w(this,G,Pc).call(this,i,n,r,u),c}addHCMFilter(e,s){var p;const i=`${e}-${s}`,n="base";let r=l(this,G,kc).get(n);if((r==null?void 0:r.key)===i||(r?((p=r.filter)==null||p.remove(),r.key=i,r.url="none",r.filter=null):(r={key:i,url:"none",filter:null},l(this,G,kc).set(n,r)),!e||!s))return r.url;const o=w(this,G,Dc).call(this,e);e=U.makeHexColor(...o);const h=w(this,G,Dc).call(this,s);if(s=U.makeHexColor(...h),l(this,G,mh).style.color="",e==="#000000"&&s==="#ffffff"||e===s)return r.url;const c=new Array(256);for(let b=0;b<=255;b++){const _=b/255;c[b]=_<=.03928?_/12.92:((_+.055)/1.055)**2.4}const u=c.join(","),d=`g_${l(this,en)}_hcm_filter`,f=r.filter=w(this,G,yh).call(this,d);w(this,G,Pc).call(this,u,u,u,f),w(this,G,dp).call(this,f);const g=(b,_)=>{const v=o[b]/255,x=h[b]/255,C=new Array(_+1);for(let S=0;S<=_;S++)C[S]=v+S/_*(x-v);return C.join(",")};return w(this,G,Pc).call(this,g(0,5),g(1,5),g(2,5),f),r.url=w(this,G,bh).call(this,d),r.url}addAlphaFilter(e){let s=l(this,G,Te).get(e);if(s)return s;const[i]=w(this,G,Nd).call(this,[e]),n=`alpha_${i}`;if(s=l(this,G,Te).get(n),s)return l(this,G,Te).set(e,s),s;const r=`g_${l(this,en)}_alpha_map_${Ge(this,eo)._++}`,o=w(this,G,bh).call(this,r);l(this,G,Te).set(e,o),l(this,G,Te).set(n,o);const h=w(this,G,yh).call(this,r);return w(this,G,fp).call(this,i,h),o}addLuminosityFilter(e){let s=l(this,G,Te).get(e||"luminosity");if(s)return s;let i,n;if(e?([i]=w(this,G,Nd).call(this,[e]),n=`luminosity_${i}`):n="luminosity",s=l(this,G,Te).get(n),s)return l(this,G,Te).set(e,s),s;const r=`g_${l(this,en)}_luminosity_map_${Ge(this,eo)._++}`,o=w(this,G,bh).call(this,r);l(this,G,Te).set(e,o),l(this,G,Te).set(n,o);const h=w(this,G,yh).call(this,r);return w(this,G,Ay).call(this,h),e&&w(this,G,fp).call(this,i,h),o}addHighlightHCMFilter(e,s,i,n,r){var x;const o=`${s}-${i}-${n}-${r}`;let h=l(this,G,kc).get(e);if((h==null?void 0:h.key)===o||(h?((x=h.filter)==null||x.remove(),h.key=o,h.url="none",h.filter=null):(h={key:o,url:"none",filter:null},l(this,G,kc).set(e,h)),!s||!i))return h.url;const[c,u]=[s,i].map(w(this,G,Dc).bind(this));let d=Math.round(.2126*c[0]+.7152*c[1]+.0722*c[2]),f=Math.round(.2126*u[0]+.7152*u[1]+.0722*u[2]),[g,p]=[n,r].map(w(this,G,Dc).bind(this));f<d&&([d,f,g,p]=[f,d,p,g]),l(this,G,mh).style.color="";const b=(C,S,E)=>{const k=new Array(256),M=(f-d)/E,D=C/255,R=(S-C)/(255*E);let B=0;for(let O=0;O<=E;O++){const F=Math.round(d+O*M),L=D+O*R;for(let N=B;N<=F;N++)k[N]=L;B=F+1}for(let O=B;O<256;O++)k[O]=k[B-1];return k.join(",")},_=`g_${l(this,en)}_hcm_${e}_filter`,v=h.filter=w(this,G,yh).call(this,_);return w(this,G,dp).call(this,v),w(this,G,Pc).call(this,b(g[0],p[0],5),b(g[1],p[1],5),b(g[2],p[2],5),v),h.url=w(this,G,bh).call(this,_),h.url}destroy(e=!1){var s,i,n,r;e&&((s=l(this,to))!=null&&s.size)||((i=l(this,tn))==null||i.parentNode.parentNode.remove(),m(this,tn,null),(n=l(this,Aa))==null||n.clear(),m(this,Aa,null),(r=l(this,to))==null||r.clear(),m(this,to,null),m(this,eo,0))}}Zr=new WeakMap,Aa=new WeakMap,tn=new WeakMap,en=new WeakMap,xe=new WeakMap,to=new WeakMap,eo=new WeakMap,G=new WeakSet,Te=function(){return l(this,Aa)||m(this,Aa,new Map)},kc=function(){return l(this,to)||m(this,to,new Map)},mh=function(){if(!l(this,tn)){const e=l(this,xe).createElement("div"),{style:s}=e;s.visibility="hidden",s.contain="strict",s.width=s.height=0,s.position="absolute",s.top=s.left=0,s.zIndex=-1;const i=l(this,xe).createElementNS(zi,"svg");i.setAttribute("width",0),i.setAttribute("height",0),m(this,tn,l(this,xe).createElementNS(zi,"defs")),e.append(i),i.append(l(this,tn)),l(this,xe).body.append(e)}return l(this,tn)},Nd=function(e){if(e.length===1){const c=e[0],u=new Array(256);for(let f=0;f<256;f++)u[f]=c[f]/255;const d=u.join(",");return[d,d,d]}const[s,i,n]=e,r=new Array(256),o=new Array(256),h=new Array(256);for(let c=0;c<256;c++)r[c]=s[c]/255,o[c]=i[c]/255,h[c]=n[c]/255;return[r.join(","),o.join(","),h.join(",")]},bh=function(e){if(l(this,Zr)===void 0){m(this,Zr,"");const s=l(this,xe).URL;s!==l(this,xe).baseURI&&($u(s)?et('#createUrl: ignore "data:"-URL for performance reasons.'):m(this,Zr,s.split("#",1)[0]))}return`url(${l(this,Zr)}#${e})`},Ay=function(e){const s=l(this,xe).createElementNS(zi,"feColorMatrix");s.setAttribute("type","matrix"),s.setAttribute("values","0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.3 0.59 0.11 0 0"),e.append(s)},dp=function(e){const s=l(this,xe).createElementNS(zi,"feColorMatrix");s.setAttribute("type","matrix"),s.setAttribute("values","0.2126 0.7152 0.0722 0 0 0.2126 0.7152 0.0722 0 0 0.2126 0.7152 0.0722 0 0 0 0 0 1 0"),e.append(s)},yh=function(e){const s=l(this,xe).createElementNS(zi,"filter");return s.setAttribute("color-interpolation-filters","sRGB"),s.setAttribute("id",e),l(this,G,mh).append(s),s},Mc=function(e,s,i){const n=l(this,xe).createElementNS(zi,s);n.setAttribute("type","discrete"),n.setAttribute("tableValues",i),e.append(n)},Pc=function(e,s,i,n){const r=l(this,xe).createElementNS(zi,"feComponentTransfer");n.append(r),w(this,G,Mc).call(this,r,"feFuncR",e),w(this,G,Mc).call(this,r,"feFuncG",s),w(this,G,Mc).call(this,r,"feFuncB",i)},fp=function(e,s){const i=l(this,xe).createElementNS(zi,"feComponentTransfer");s.append(i),w(this,G,Mc).call(this,i,"feFuncA",e)},Dc=function(e){return l(this,G,mh).style.color=e,mg(getComputedStyle(l(this,G,mh)).getPropertyValue("color"))};class cb{constructor({baseUrl:t=null}){this.baseUrl=t}async fetch({filename:t}){if(!this.baseUrl)throw new Error("Ensure that the `standardFontDataUrl` API parameter is provided.");if(!t)throw new Error("Font filename must be specified.");const e=`${this.baseUrl}${t}`;return this._fetch(e).catch(s=>{throw new Error(`Unable to load font data at: ${e}`)})}async _fetch(t){vt("Abstract method `_fetch` called.")}}class ub extends cb{async _fetch(t){const e=await Yu(t,"arraybuffer");return new Uint8Array(e)}}ye&&et("Please use the `legacy` build in Node.js environments.");async function db(a){const e=await process.getBuiltinModule("fs").promises.readFile(a);return new Uint8Array(e)}class Nx extends lb{}class jx extends ob{_createCanvas(t,e){return process.getBuiltinModule("module").createRequire(typeof document>"u"&&typeof location>"u"?require("url").pathToFileURL(__filename).href:typeof document>"u"?location.href:_t&&_t.tagName.toUpperCase()==="SCRIPT"&&_t.src||new URL("pdf-canvas.umd.js",document.baseURI).href)("@napi-rs/canvas").createCanvas(t,e)}}class Bx extends ab{async _fetch(t){return db(t)}}class Hx extends cb{async _fetch(t){return db(t)}}const _e={FILL:"Fill",STROKE:"Stroke",SHADING:"Shading"};function Sg(a,t){if(!t)return;const e=t[2]-t[0],s=t[3]-t[1],i=new Path2D;i.rect(t[0],t[1],e,s),a.clip(i)}class Cg{getPattern(){vt("Abstract method `getPattern` called.")}}class Gx extends Cg{constructor(t){super(),this._type=t[1],this._bbox=t[2],this._colorStops=t[3],this._p0=t[4],this._p1=t[5],this._r0=t[6],this._r1=t[7],this.matrix=null}_createGradient(t){let e;this._type==="axial"?e=t.createLinearGradient(this._p0[0],this._p0[1],this._p1[0],this._p1[1]):this._type==="radial"&&(e=t.createRadialGradient(this._p0[0],this._p0[1],this._r0,this._p1[0],this._p1[1],this._r1));for(const s of this._colorStops)e.addColorStop(s[0],s[1]);return e}getPattern(t,e,s,i){let n;if(i===_e.STROKE||i===_e.FILL){const r=e.current.getClippedPathBoundingBox(i,Tt(t))||[0,0,0,0],o=Math.ceil(r[2]-r[0])||1,h=Math.ceil(r[3]-r[1])||1,c=e.cachedCanvases.getCanvas("pattern",o,h),u=c.context;u.clearRect(0,0,u.canvas.width,u.canvas.height),u.beginPath(),u.rect(0,0,u.canvas.width,u.canvas.height),u.translate(-r[0],-r[1]),s=U.transform(s,[1,0,0,1,r[0],r[1]]),u.transform(...e.baseTransform),this.matrix&&u.transform(...this.matrix),Sg(u,this._bbox),u.fillStyle=this._createGradient(u),u.fill(),n=t.createPattern(c.canvas,"no-repeat");const d=new DOMMatrix(s);n.setTransform(d)}else Sg(t,this._bbox),n=this._createGradient(t);return n}}function Ag(a,t,e,s,i,n,r,o){const h=t.coords,c=t.colors,u=a.data,d=a.width*4;let f;h[e+1]>h[s+1]&&(f=e,e=s,s=f,f=n,n=r,r=f),h[s+1]>h[i+1]&&(f=s,s=i,i=f,f=r,r=o,o=f),h[e+1]>h[s+1]&&(f=e,e=s,s=f,f=n,n=r,r=f);const g=(h[e]+t.offsetX)*t.scaleX,p=(h[e+1]+t.offsetY)*t.scaleY,b=(h[s]+t.offsetX)*t.scaleX,_=(h[s+1]+t.offsetY)*t.scaleY,v=(h[i]+t.offsetX)*t.scaleX,x=(h[i+1]+t.offsetY)*t.scaleY;if(p>=x)return;const C=c[n],S=c[n+1],E=c[n+2],k=c[r],M=c[r+1],D=c[r+2],R=c[o],B=c[o+1],O=c[o+2],F=Math.round(p),L=Math.round(x);let N,Y,I,X,rt,Gt,te,fe;for(let Yt=F;Yt<=L;Yt++){if(Yt<_){const ft=Yt<p?0:(p-Yt)/(p-_);N=g-(g-b)*ft,Y=C-(C-k)*ft,I=S-(S-M)*ft,X=E-(E-D)*ft}else{let ft;Yt>x?ft=1:_===x?ft=0:ft=(_-Yt)/(_-x),N=b-(b-v)*ft,Y=k-(k-R)*ft,I=M-(M-B)*ft,X=D-(D-O)*ft}let St;Yt<p?St=0:Yt>x?St=1:St=(p-Yt)/(p-x),rt=g-(g-v)*St,Gt=C-(C-R)*St,te=S-(S-B)*St,fe=E-(E-O)*St;const He=Math.round(Math.min(N,rt)),Mi=Math.round(Math.max(N,rt));let Ft=d*Yt+He*4;for(let ft=He;ft<=Mi;ft++)St=(N-ft)/(N-rt),St<0?St=0:St>1&&(St=1),u[Ft++]=Y-(Y-Gt)*St|0,u[Ft++]=I-(I-te)*St|0,u[Ft++]=X-(X-fe)*St|0,u[Ft++]=255}}function zx(a,t,e){const s=t.coords,i=t.colors;let n,r;switch(t.type){case"lattice":const o=t.verticesPerRow,h=Math.floor(s.length/o)-1,c=o-1;for(n=0;n<h;n++){let u=n*o;for(let d=0;d<c;d++,u++)Ag(a,e,s[u],s[u+1],s[u+o],i[u],i[u+1],i[u+o]),Ag(a,e,s[u+o+1],s[u+1],s[u+o],i[u+o+1],i[u+1],i[u+o])}break;case"triangles":for(n=0,r=s.length;n<r;n+=3)Ag(a,e,s[n],s[n+1],s[n+2],i[n],i[n+1],i[n+2]);break;default:throw new Error("illegal figure")}}class Vx extends Cg{constructor(t){super(),this._coords=t[2],this._colors=t[3],this._figures=t[4],this._bounds=t[5],this._bbox=t[7],this._background=t[8],this.matrix=null}_createMeshCanvas(t,e,s){const o=Math.floor(this._bounds[0]),h=Math.floor(this._bounds[1]),c=Math.ceil(this._bounds[2])-o,u=Math.ceil(this._bounds[3])-h,d=Math.min(Math.ceil(Math.abs(c*t[0]*1.1)),3e3),f=Math.min(Math.ceil(Math.abs(u*t[1]*1.1)),3e3),g=c/d,p=u/f,b={coords:this._coords,colors:this._colors,offsetX:-o,offsetY:-h,scaleX:1/g,scaleY:1/p},_=d+2*2,v=f+2*2,x=s.getCanvas("mesh",_,v),C=x.context,S=C.createImageData(d,f);if(e){const k=S.data;for(let M=0,D=k.length;M<D;M+=4)k[M]=e[0],k[M+1]=e[1],k[M+2]=e[2],k[M+3]=255}for(const k of this._figures)zx(S,k,b);return C.putImageData(S,2,2),{canvas:x.canvas,offsetX:o-2*g,offsetY:h-2*p,scaleX:g,scaleY:p}}getPattern(t,e,s,i){Sg(t,this._bbox);let n;if(i===_e.SHADING)n=U.singularValueDecompose2dScale(Tt(t));else if(n=U.singularValueDecompose2dScale(e.baseTransform),this.matrix){const o=U.singularValueDecompose2dScale(this.matrix);n=[n[0]*o[0],n[1]*o[1]]}const r=this._createMeshCanvas(n,i===_e.SHADING?null:this._background,e.cachedCanvases);return i!==_e.SHADING&&(t.setTransform(...e.baseTransform),this.matrix&&t.transform(...this.matrix)),t.translate(r.offsetX,r.offsetY),t.scale(r.scaleX,r.scaleY),t.createPattern(r.canvas,"no-repeat")}}class Xx extends Cg{getPattern(){return"hotpink"}}function Wx(a){switch(a[0]){case"RadialAxial":return new Gx(a);case"Mesh":return new Vx(a);case"Dummy":return new Xx}throw new Error(`Unknown IR type: ${a[0]}`)}const fb={COLORED:1,UNCOLORED:2},pd=class pd{constructor(t,e,s,i,n){this.operatorList=t[2],this.matrix=t[3],this.bbox=t[4],this.xstep=t[5],this.ystep=t[6],this.paintType=t[7],this.tilingType=t[8],this.color=e,this.ctx=s,this.canvasGraphicsFactory=i,this.baseTransform=n}createPatternCanvas(t){const{bbox:e,operatorList:s,paintType:i,tilingType:n,color:r,canvasGraphicsFactory:o}=this;let{xstep:h,ystep:c}=this;h=Math.abs(h),c=Math.abs(c),Xu("TilingType: "+n);const u=e[0],d=e[1],f=e[2],g=e[3],p=f-u,b=g-d,_=U.singularValueDecompose2dScale(this.matrix),v=U.singularValueDecompose2dScale(this.baseTransform),x=_[0]*v[0],C=_[1]*v[1];let S=p,E=b,k=!1,M=!1;const D=Math.ceil(h*x),R=Math.ceil(c*C),B=Math.ceil(p*x),O=Math.ceil(b*C);D>=B?S=h:k=!0,R>=O?E=c:M=!0;const F=this.getSizeAndScale(S,this.ctx.canvas.width,x),L=this.getSizeAndScale(E,this.ctx.canvas.height,C),N=t.cachedCanvases.getCanvas("pattern",F.size,L.size),Y=N.context,I=o.createCanvasGraphics(Y);if(I.groupLevel=t.groupLevel,this.setFillAndStrokeStyleToContext(I,i,r),Y.translate(-F.scale*u,-L.scale*d),I.transform(F.scale,0,0,L.scale,0,0),Y.save(),this.clipBbox(I,u,d,f,g),I.baseTransform=Tt(I.ctx),I.executeOperatorList(s),I.endDrawing(),Y.restore(),k||M){const X=N.canvas;k&&(S=h),M&&(E=c);const rt=this.getSizeAndScale(S,this.ctx.canvas.width,x),Gt=this.getSizeAndScale(E,this.ctx.canvas.height,C),te=rt.size,fe=Gt.size,Yt=t.cachedCanvases.getCanvas("pattern-workaround",te,fe),St=Yt.context,He=k?Math.floor(p/h):0,Mi=M?Math.floor(b/c):0;for(let Ft=0;Ft<=He;Ft++)for(let ft=0;ft<=Mi;ft++)St.drawImage(X,te*Ft,fe*ft,te,fe,0,0,te,fe);return{canvas:Yt.canvas,scaleX:rt.scale,scaleY:Gt.scale,offsetX:u,offsetY:d}}return{canvas:N.canvas,scaleX:F.scale,scaleY:L.scale,offsetX:u,offsetY:d}}getSizeAndScale(t,e,s){const i=Math.max(pd.MAX_PATTERN_SIZE,e);let n=Math.ceil(t*s);return n>=i?n=i:s=n/t,{scale:s,size:n}}clipBbox(t,e,s,i,n){const r=i-e,o=n-s;t.ctx.rect(e,s,r,o),t.current.updateRectMinMax(Tt(t.ctx),[e,s,i,n]),t.clip(),t.endPath()}setFillAndStrokeStyleToContext(t,e,s){const i=t.ctx,n=t.current;switch(e){case fb.COLORED:const r=this.ctx;i.fillStyle=r.fillStyle,i.strokeStyle=r.strokeStyle,n.fillColor=r.fillStyle,n.strokeColor=r.strokeStyle;break;case fb.UNCOLORED:const o=U.makeHexColor(s[0],s[1],s[2]);i.fillStyle=o,i.strokeStyle=o,n.fillColor=o,n.strokeColor=o;break;default:throw new bx(`Unsupported paint type: ${e}`)}}getPattern(t,e,s,i){let n=s;i!==_e.SHADING&&(n=U.transform(n,e.baseTransform),this.matrix&&(n=U.transform(n,this.matrix)));const r=this.createPatternCanvas(e);let o=new DOMMatrix(n);o=o.translate(r.offsetX,r.offsetY),o=o.scale(1/r.scaleX,1/r.scaleY);const h=t.createPattern(r.canvas,"repeat");return h.setTransform(o),h}};q(pd,"MAX_PATTERN_SIZE",3e3);let Tg=pd;function Ux({src:a,srcPos:t=0,dest:e,width:s,height:i,nonBlackColor:n=4294967295,inverseDecode:r=!1}){const o=Re.isLittleEndian?4278190080:255,[h,c]=r?[n,o]:[o,n],u=s>>3,d=s&7,f=a.length;e=new Uint32Array(e.buffer);let g=0;for(let p=0;p<i;p++){for(const _=t+u;t<_;t++){const v=t<f?a[t]:255;e[g++]=v&128?c:h,e[g++]=v&64?c:h,e[g++]=v&32?c:h,e[g++]=v&16?c:h,e[g++]=v&8?c:h,e[g++]=v&4?c:h,e[g++]=v&2?c:h,e[g++]=v&1?c:h}if(d===0)continue;const b=t<f?a[t++]:255;for(let _=0;_<d;_++)e[g++]=b&1<<7-_?c:h}return{srcPos:t,destPos:g}}const gb=16,pb=100,Yx=15,mb=10,bb=1e3,Ue=16;function $x(a,t){if(a._removeMirroring)throw new Error("Context is already forwarding operations.");a.__originalSave=a.save,a.__originalRestore=a.restore,a.__originalRotate=a.rotate,a.__originalScale=a.scale,a.__originalTranslate=a.translate,a.__originalTransform=a.transform,a.__originalSetTransform=a.setTransform,a.__originalResetTransform=a.resetTransform,a.__originalClip=a.clip,a.__originalMoveTo=a.moveTo,a.__originalLineTo=a.lineTo,a.__originalBezierCurveTo=a.bezierCurveTo,a.__originalRect=a.rect,a.__originalClosePath=a.closePath,a.__originalBeginPath=a.beginPath,a._removeMirroring=()=>{a.save=a.__originalSave,a.restore=a.__originalRestore,a.rotate=a.__originalRotate,a.scale=a.__originalScale,a.translate=a.__originalTranslate,a.transform=a.__originalTransform,a.setTransform=a.__originalSetTransform,a.resetTransform=a.__originalResetTransform,a.clip=a.__originalClip,a.moveTo=a.__originalMoveTo,a.lineTo=a.__originalLineTo,a.bezierCurveTo=a.__originalBezierCurveTo,a.rect=a.__originalRect,a.closePath=a.__originalClosePath,a.beginPath=a.__originalBeginPath,delete a._removeMirroring},a.save=function(){t.save(),this.__originalSave()},a.restore=function(){t.restore(),this.__originalRestore()},a.translate=function(s,i){t.translate(s,i),this.__originalTranslate(s,i)},a.scale=function(s,i){t.scale(s,i),this.__originalScale(s,i)},a.transform=function(s,i,n,r,o,h){t.transform(s,i,n,r,o,h),this.__originalTransform(s,i,n,r,o,h)},a.setTransform=function(s,i,n,r,o,h){t.setTransform(s,i,n,r,o,h),this.__originalSetTransform(s,i,n,r,o,h)},a.resetTransform=function(){t.resetTransform(),this.__originalResetTransform()},a.rotate=function(s){t.rotate(s),this.__originalRotate(s)},a.clip=function(s){t.clip(s),this.__originalClip(s)},a.moveTo=function(e,s){t.moveTo(e,s),this.__originalMoveTo(e,s)},a.lineTo=function(e,s){t.lineTo(e,s),this.__originalLineTo(e,s)},a.bezierCurveTo=function(e,s,i,n,r,o){t.bezierCurveTo(e,s,i,n,r,o),this.__originalBezierCurveTo(e,s,i,n,r,o)},a.rect=function(e,s,i,n){t.rect(e,s,i,n),this.__originalRect(e,s,i,n)},a.closePath=function(){t.closePath(),this.__originalClosePath()},a.beginPath=function(){t.beginPath(),this.__originalBeginPath()}}class qx{constructor(t){this.canvasFactory=t,this.cache=Object.create(null)}getCanvas(t,e,s){let i;return this.cache[t]!==void 0?(i=this.cache[t],this.canvasFactory.reset(i,e,s)):(i=this.canvasFactory.create(e,s),this.cache[t]=i),i}delete(t){delete this.cache[t]}clear(){for(const t in this.cache){const e=this.cache[t];this.canvasFactory.destroy(e),delete this.cache[t]}}}function Zu(a,t,e,s,i,n,r,o,h,c){const[u,d,f,g,p,b]=Tt(a);if(d===0&&f===0){const x=r*u+p,C=Math.round(x),S=o*g+b,E=Math.round(S),k=(r+h)*u+p,M=Math.abs(Math.round(k)-C)||1,D=(o+c)*g+b,R=Math.abs(Math.round(D)-E)||1;return a.setTransform(Math.sign(u),0,0,Math.sign(g),C,E),a.drawImage(t,e,s,i,n,0,0,M,R),a.setTransform(u,d,f,g,p,b),[M,R]}if(u===0&&g===0){const x=o*f+p,C=Math.round(x),S=r*d+b,E=Math.round(S),k=(o+c)*f+p,M=Math.abs(Math.round(k)-C)||1,D=(r+h)*d+b,R=Math.abs(Math.round(D)-E)||1;return a.setTransform(0,Math.sign(d),Math.sign(f),0,C,E),a.drawImage(t,e,s,i,n,0,0,R,M),a.setTransform(u,d,f,g,p,b),[R,M]}a.drawImage(t,e,s,i,n,r,o,h,c);const _=Math.hypot(u,d),v=Math.hypot(f,g);return[_*h,v*c]}function Kx(a){const{width:t,height:e}=a;if(t>bb||e>bb)return null;const s=1e3,i=new Uint8Array([0,2,4,0,1,0,5,4,8,10,0,8,0,2,1,0]),n=t+1;let r=new Uint8Array(n*(e+1)),o,h,c;const u=t+7&-8;let d=new Uint8Array(u*e),f=0;for(const v of a.data){let x=128;for(;x>0;)d[f++]=v&x?0:255,x>>=1}let g=0;for(f=0,d[f]!==0&&(r[0]=1,++g),h=1;h<t;h++)d[f]!==d[f+1]&&(r[h]=d[f]?2:1,++g),f++;for(d[f]!==0&&(r[h]=2,++g),o=1;o<e;o++){f=o*u,c=o*n,d[f-u]!==d[f]&&(r[c]=d[f]?1:8,++g);let v=(d[f]?4:0)+(d[f-u]?8:0);for(h=1;h<t;h++)v=(v>>2)+(d[f+1]?4:0)+(d[f-u+1]?8:0),i[v]&&(r[c+h]=i[v],++g),f++;if(d[f-u]!==d[f]&&(r[c+h]=d[f]?2:4,++g),g>s)return null}for(f=u*(e-1),c=o*n,d[f]!==0&&(r[c]=8,++g),h=1;h<t;h++)d[f]!==d[f+1]&&(r[c+h]=d[f]?4:8,++g),f++;if(d[f]!==0&&(r[c+h]=4,++g),g>s)return null;const p=new Int32Array([0,n,-1,0,-n,0,0,0,1]),b=new Path2D;for(o=0;g&&o<=e;o++){let v=o*n;const x=v+t;for(;v<x&&!r[v];)v++;if(v===x)continue;b.moveTo(v%n,o);const C=v;let S=r[v];do{const E=p[S];do v+=E;while(!r[v]);const k=r[v];k!==5&&k!==10?(S=k,r[v]=0):(S=k&51*S>>4,r[v]&=S>>2|S<<2),b.lineTo(v%n,v/n|0),r[v]||--g}while(C!==v);--o}return d=null,r=null,function(v){v.save(),v.scale(1/t,-1/e),v.translate(0,-e),v.fill(b),v.beginPath(),v.restore()}}class yb{constructor(t,e){this.alphaIsShape=!1,this.fontSize=0,this.fontSizeScale=1,this.textMatrix=Q0,this.textMatrixScale=1,this.fontMatrix=rg,this.leading=0,this.x=0,this.y=0,this.lineX=0,this.lineY=0,this.charSpacing=0,this.wordSpacing=0,this.textHScale=1,this.textRenderingMode=ve.FILL,this.textRise=0,this.fillColor="#000000",this.strokeColor="#000000",this.patternFill=!1,this.patternStroke=!1,this.fillAlpha=1,this.strokeAlpha=1,this.lineWidth=1,this.activeSMask=null,this.transferMaps="none",this.startNewPathAndClipBox([0,0,t,e])}clone(){const t=Object.create(this);return t.clipBox=this.clipBox.slice(),t}setCurrentPoint(t,e){this.x=t,this.y=e}updatePathMinMax(t,e,s){[e,s]=U.applyTransform([e,s],t),this.minX=Math.min(this.minX,e),this.minY=Math.min(this.minY,s),this.maxX=Math.max(this.maxX,e),this.maxY=Math.max(this.maxY,s)}updateRectMinMax(t,e){const s=U.applyTransform(e,t),i=U.applyTransform(e.slice(2),t),n=U.applyTransform([e[0],e[3]],t),r=U.applyTransform([e[2],e[1]],t);this.minX=Math.min(this.minX,s[0],i[0],n[0],r[0]),this.minY=Math.min(this.minY,s[1],i[1],n[1],r[1]),this.maxX=Math.max(this.maxX,s[0],i[0],n[0],r[0]),this.maxY=Math.max(this.maxY,s[1],i[1],n[1],r[1])}updateScalingPathMinMax(t,e){U.scaleMinMax(t,e),this.minX=Math.min(this.minX,e[0]),this.minY=Math.min(this.minY,e[1]),this.maxX=Math.max(this.maxX,e[2]),this.maxY=Math.max(this.maxY,e[3])}updateCurvePathMinMax(t,e,s,i,n,r,o,h,c,u){const d=U.bezierBoundingBox(e,s,i,n,r,o,h,c,u);u||this.updateRectMinMax(t,d)}getPathBoundingBox(t=_e.FILL,e=null){const s=[this.minX,this.minY,this.maxX,this.maxY];if(t===_e.STROKE){e||vt("Stroke bounding box must include transform.");const i=U.singularValueDecompose2dScale(e),n=i[0]*this.lineWidth/2,r=i[1]*this.lineWidth/2;s[0]-=n,s[1]-=r,s[2]+=n,s[3]+=r}return s}updateClipFromPath(){const t=U.intersect(this.clipBox,this.getPathBoundingBox());this.startNewPathAndClipBox(t||[0,0,0,0])}isEmptyClip(){return this.minX===1/0}startNewPathAndClipBox(t){this.clipBox=t,this.minX=1/0,this.minY=1/0,this.maxX=0,this.maxY=0}getClippedPathBoundingBox(t=_e.FILL,e=null){return U.intersect(this.clipBox,this.getPathBoundingBox(t,e))}}function vb(a,t){if(t instanceof ImageData){a.putImageData(t,0,0);return}const e=t.height,s=t.width,i=e%Ue,n=(e-i)/Ue,r=i===0?n:n+1,o=a.createImageData(s,Ue);let h=0,c;const u=t.data,d=o.data;let f,g,p,b;if(t.kind===Gu.GRAYSCALE_1BPP){const _=u.byteLength,v=new Uint32Array(d.buffer,0,d.byteLength>>2),x=v.length,C=s+7>>3,S=4294967295,E=Re.isLittleEndian?4278190080:255;for(f=0;f<r;f++){for(p=f<n?Ue:i,c=0,g=0;g<p;g++){const k=_-h;let M=0;const D=k>C?s:k*8-7,R=D&-8;let B=0,O=0;for(;M<R;M+=8)O=u[h++],v[c++]=O&128?S:E,v[c++]=O&64?S:E,v[c++]=O&32?S:E,v[c++]=O&16?S:E,v[c++]=O&8?S:E,v[c++]=O&4?S:E,v[c++]=O&2?S:E,v[c++]=O&1?S:E;for(;M<D;M++)B===0&&(O=u[h++],B=128),v[c++]=O&B?S:E,B>>=1}for(;c<x;)v[c++]=0;a.putImageData(o,0,f*Ue)}}else if(t.kind===Gu.RGBA_32BPP){for(g=0,b=s*Ue*4,f=0;f<n;f++)d.set(u.subarray(h,h+b)),h+=b,a.putImageData(o,0,g),g+=Ue;f<r&&(b=s*i*4,d.set(u.subarray(h,h+b)),a.putImageData(o,0,g))}else if(t.kind===Gu.RGB_24BPP)for(p=Ue,b=s*p,f=0;f<r;f++){for(f>=n&&(p=i,b=s*p),c=0,g=b;g--;)d[c++]=u[h++],d[c++]=u[h++],d[c++]=u[h++],d[c++]=255;a.putImageData(o,0,f*Ue)}else throw new Error(`bad image kind: ${t.kind}`)}function _b(a,t){if(t.bitmap){a.drawImage(t.bitmap,0,0);return}const e=t.height,s=t.width,i=e%Ue,n=(e-i)/Ue,r=i===0?n:n+1,o=a.createImageData(s,Ue);let h=0;const c=t.data,u=o.data;for(let d=0;d<r;d++){const f=d<n?Ue:i;({srcPos:h}=Ux({src:c,srcPos:h,dest:u,width:s,height:f,nonBlackColor:0})),a.putImageData(o,0,d*Ue)}}function Yh(a,t){const e=["strokeStyle","fillStyle","fillRule","globalAlpha","lineWidth","lineCap","lineJoin","miterLimit","globalCompositeOperation","font","filter"];for(const s of e)a[s]!==void 0&&(t[s]=a[s]);a.setLineDash!==void 0&&(t.setLineDash(a.getLineDash()),t.lineDashOffset=a.lineDashOffset)}function td(a){if(a.strokeStyle=a.fillStyle="#000000",a.fillRule="nonzero",a.globalAlpha=1,a.lineWidth=1,a.lineCap="butt",a.lineJoin="miter",a.miterLimit=10,a.globalCompositeOperation="source-over",a.font="10px sans-serif",a.setLineDash!==void 0&&(a.setLineDash([]),a.lineDashOffset=0),!ye){const{filter:t}=a;t!=="none"&&t!==""&&(a.filter="none")}}function wb(a,t){if(t)return!0;const e=U.singularValueDecompose2dScale(a);e[0]=Math.fround(e[0]),e[1]=Math.fround(e[1]);const s=Math.fround((globalThis.devicePixelRatio||1)*Ln.PDF_TO_CSS_UNITS);return e[0]<=s&&e[1]<=s}const Qx=["butt","round","square"],Jx=["miter","round","bevel"],Zx={},xb={},Wg=class Wg{constructor(t,e,s,i,n,{optionalContentConfig:r,markedContentStack:o=null},h,c){y(this,Ys);this.ctx=t,this.current=new yb(this.ctx.canvas.width,this.ctx.canvas.height),this.stateStack=[],this.pendingClip=null,this.pendingEOFill=!1,this.res=null,this.xobjs=null,this.commonObjs=e,this.objs=s,this.canvasFactory=i,this.filterFactory=n,this.groupStack=[],this.processingType3=null,this.baseTransform=null,this.baseTransformStack=[],this.groupLevel=0,this.smaskStack=[],this.smaskCounter=0,this.tempSMask=null,this.suspendedCtx=null,this.contentVisible=!0,this.markedContentStack=o||[],this.optionalContentConfig=r,this.cachedCanvases=new qx(this.canvasFactory),this.cachedPatterns=new Map,this.annotationCanvasMap=h,this.viewportScale=1,this.outputScaleX=1,this.outputScaleY=1,this.pageColors=c,this._cachedScaleForStroking=[-1,0],this._cachedGetSinglePixelWidth=null,this._cachedBitmapsMap=new Map}getObject(t,e=null){return typeof t=="string"?t.startsWith("g_")?this.commonObjs.get(t):this.objs.get(t):e}beginDrawing({transform:t,viewport:e,transparency:s=!1,background:i=null}){const n=this.ctx.canvas.width,r=this.ctx.canvas.height,o=this.ctx.fillStyle;if(this.ctx.fillStyle=i||"#ffffff",this.ctx.fillRect(0,0,n,r),this.ctx.fillStyle=o,s){const h=this.cachedCanvases.getCanvas("transparent",n,r);this.compositeCtx=this.ctx,this.transparentCanvas=h.canvas,this.ctx=h.context,this.ctx.save(),this.ctx.transform(...Tt(this.compositeCtx))}this.ctx.save(),td(this.ctx),t&&(this.ctx.transform(...t),this.outputScaleX=t[0],this.outputScaleY=t[0]),this.ctx.transform(...e.transform),this.viewportScale=e.scale,this.baseTransform=Tt(this.ctx)}executeOperatorList(t,e,s,i){const n=t.argsArray,r=t.fnArray;let o=e||0;const h=n.length;if(h===o)return o;const c=h-o>mb&&typeof s=="function",u=c?Date.now()+Yx:0;let d=0;const f=this.commonObjs,g=this.objs;let p;for(;;){if(i!==void 0&&o===i.nextBreakPoint)return i.breakIt(o,s),o;if(p=r[o],p!==Hs.dependency)this[p].apply(this,n[o]);else for(const b of n[o]){const _=b.startsWith("g_")?f:g;if(!_.has(b))return _.get(b,s),o}if(o++,o===h)return o;if(c&&++d>mb){if(Date.now()>u)return s(),o;d=0}}}endDrawing(){w(this,Ys,gp).call(this),this.cachedCanvases.clear(),this.cachedPatterns.clear();for(const t of this._cachedBitmapsMap.values()){for(const e of t.values())typeof HTMLCanvasElement<"u"&&e instanceof HTMLCanvasElement&&(e.width=e.height=0);t.clear()}this._cachedBitmapsMap.clear(),w(this,Ys,pp).call(this)}_scaleImage(t,e){const s=t.width??t.displayWidth,i=t.height??t.displayHeight;let n=Math.max(Math.hypot(e[0],e[1]),1),r=Math.max(Math.hypot(e[2],e[3]),1),o=s,h=i,c="prescale1",u,d;for(;n>2&&o>1||r>2&&h>1;){let f=o,g=h;n>2&&o>1&&(f=o>=16384?Math.floor(o/2)-1||1:Math.ceil(o/2),n/=o/f),r>2&&h>1&&(g=h>=16384?Math.floor(h/2)-1||1:Math.ceil(h)/2,r/=h/g),u=this.cachedCanvases.getCanvas(c,f,g),d=u.context,d.clearRect(0,0,f,g),d.drawImage(t,0,0,o,h,0,0,f,g),t=u.canvas,o=f,h=g,c=c==="prescale1"?"prescale2":"prescale1"}return{img:t,paintWidth:o,paintHeight:h}}_createMaskCanvas(t){const e=this.ctx,{width:s,height:i}=t,n=this.current.fillColor,r=this.current.patternFill,o=Tt(e);let h,c,u,d;if((t.bitmap||t.data)&&t.count>1){const D=t.bitmap||t.data.buffer;c=JSON.stringify(r?o:[o.slice(0,4),n]),h=this._cachedBitmapsMap.get(D),h||(h=new Map,this._cachedBitmapsMap.set(D,h));const R=h.get(c);if(R&&!r){const B=Math.round(Math.min(o[0],o[2])+o[4]),O=Math.round(Math.min(o[1],o[3])+o[5]);return{canvas:R,offsetX:B,offsetY:O}}u=R}u||(d=this.cachedCanvases.getCanvas("maskCanvas",s,i),_b(d.context,t));let f=U.transform(o,[1/s,0,0,-1/i,0,0]);f=U.transform(f,[1,0,0,1,0,-i]);const[g,p,b,_]=U.getAxialAlignedBoundingBox([0,0,s,i],f),v=Math.round(b-g)||1,x=Math.round(_-p)||1,C=this.cachedCanvases.getCanvas("fillCanvas",v,x),S=C.context,E=g,k=p;S.translate(-E,-k),S.transform(...f),u||(u=this._scaleImage(d.canvas,li(S)),u=u.img,h&&r&&h.set(c,u)),S.imageSmoothingEnabled=wb(Tt(S),t.interpolate),Zu(S,u,0,0,u.width,u.height,0,0,s,i),S.globalCompositeOperation="source-in";const M=U.transform(li(S),[1,0,0,1,-E,-k]);return S.fillStyle=r?n.getPattern(e,this,M,_e.FILL):n,S.fillRect(0,0,s,i),h&&!r&&(this.cachedCanvases.delete("fillCanvas"),h.set(c,C.canvas)),{canvas:C.canvas,offsetX:Math.round(E),offsetY:Math.round(k)}}setLineWidth(t){t!==this.current.lineWidth&&(this._cachedScaleForStroking[0]=-1),this.current.lineWidth=t,this.ctx.lineWidth=t}setLineCap(t){this.ctx.lineCap=Qx[t]}setLineJoin(t){this.ctx.lineJoin=Jx[t]}setMiterLimit(t){this.ctx.miterLimit=t}setDash(t,e){const s=this.ctx;s.setLineDash!==void 0&&(s.setLineDash(t),s.lineDashOffset=e)}setRenderingIntent(t){}setFlatness(t){}setGState(t){for(const[e,s]of t)switch(e){case"LW":this.setLineWidth(s);break;case"LC":this.setLineCap(s);break;case"LJ":this.setLineJoin(s);break;case"ML":this.setMiterLimit(s);break;case"D":this.setDash(s[0],s[1]);break;case"RI":this.setRenderingIntent(s);break;case"FL":this.setFlatness(s);break;case"Font":this.setFont(s[0],s[1]);break;case"CA":this.current.strokeAlpha=s;break;case"ca":this.current.fillAlpha=s,this.ctx.globalAlpha=s;break;case"BM":this.ctx.globalCompositeOperation=s;break;case"SMask":this.current.activeSMask=s?this.tempSMask:null,this.tempSMask=null,this.checkSMaskState();break;case"TR":this.ctx.filter=this.current.transferMaps=this.filterFactory.addFilter(s);break}}get inSMaskMode(){return!!this.suspendedCtx}checkSMaskState(){const t=this.inSMaskMode;this.current.activeSMask&&!t?this.beginSMaskMode():!this.current.activeSMask&&t&&this.endSMaskMode()}beginSMaskMode(){if(this.inSMaskMode)throw new Error("beginSMaskMode called while already in smask mode");const t=this.ctx.canvas.width,e=this.ctx.canvas.height,s="smaskGroupAt"+this.groupLevel,i=this.cachedCanvases.getCanvas(s,t,e);this.suspendedCtx=this.ctx,this.ctx=i.context;const n=this.ctx;n.setTransform(...Tt(this.suspendedCtx)),Yh(this.suspendedCtx,n),$x(n,this.suspendedCtx),this.setGState([["BM","source-over"],["ca",1],["CA",1]])}endSMaskMode(){if(!this.inSMaskMode)throw new Error("endSMaskMode called while not in smask mode");this.ctx._removeMirroring(),Yh(this.ctx,this.suspendedCtx),this.ctx=this.suspendedCtx,this.suspendedCtx=null}compose(t){if(!this.current.activeSMask)return;t?(t[0]=Math.floor(t[0]),t[1]=Math.floor(t[1]),t[2]=Math.ceil(t[2]),t[3]=Math.ceil(t[3])):t=[0,0,this.ctx.canvas.width,this.ctx.canvas.height];const e=this.current.activeSMask,s=this.suspendedCtx;this.composeSMask(s,e,this.ctx,t),this.ctx.save(),this.ctx.setTransform(1,0,0,1,0,0),this.ctx.clearRect(0,0,this.ctx.canvas.width,this.ctx.canvas.height),this.ctx.restore()}composeSMask(t,e,s,i){const n=i[0],r=i[1],o=i[2]-n,h=i[3]-r;o===0||h===0||(this.genericComposeSMask(e.context,s,o,h,e.subtype,e.backdrop,e.transferMap,n,r,e.offsetX,e.offsetY),t.save(),t.globalAlpha=1,t.globalCompositeOperation="source-over",t.setTransform(1,0,0,1,0,0),t.drawImage(s.canvas,0,0),t.restore())}genericComposeSMask(t,e,s,i,n,r,o,h,c,u,d){let f=t.canvas,g=h-u,p=c-d;if(r){const _=U.makeHexColor(...r);if(g<0||p<0||g+s>f.width||p+i>f.height){const v=this.cachedCanvases.getCanvas("maskExtension",s,i),x=v.context;x.drawImage(f,-g,-p),x.globalCompositeOperation="destination-atop",x.fillStyle=_,x.fillRect(0,0,s,i),x.globalCompositeOperation="source-over",f=v.canvas,g=p=0}else{t.save(),t.globalAlpha=1,t.setTransform(1,0,0,1,0,0);const v=new Path2D;v.rect(g,p,s,i),t.clip(v),t.globalCompositeOperation="destination-atop",t.fillStyle=_,t.fillRect(g,p,s,i),t.restore()}}e.save(),e.globalAlpha=1,e.setTransform(1,0,0,1,0,0),n==="Alpha"&&o?e.filter=this.filterFactory.addAlphaFilter(o):n==="Luminosity"&&(e.filter=this.filterFactory.addLuminosityFilter(o));const b=new Path2D;b.rect(h,c,s,i),e.clip(b),e.globalCompositeOperation="destination-in",e.drawImage(f,g,p,s,i,h,c,s,i),e.restore()}save(){this.inSMaskMode?(Yh(this.ctx,this.suspendedCtx),this.suspendedCtx.save()):this.ctx.save();const t=this.current;this.stateStack.push(t),this.current=t.clone()}restore(){this.stateStack.length===0&&this.inSMaskMode&&this.endSMaskMode(),this.stateStack.length!==0&&(this.current=this.stateStack.pop(),this.inSMaskMode?(this.suspendedCtx.restore(),Yh(this.suspendedCtx,this.ctx)):this.ctx.restore(),this.checkSMaskState(),this.pendingClip=null,this._cachedScaleForStroking[0]=-1,this._cachedGetSinglePixelWidth=null)}transform(t,e,s,i,n,r){this.ctx.transform(t,e,s,i,n,r),this._cachedScaleForStroking[0]=-1,this._cachedGetSinglePixelWidth=null}constructPath(t,e,s){const i=this.ctx,n=this.current;let r=n.x,o=n.y,h,c;const u=Tt(i),d=u[0]===0&&u[3]===0||u[1]===0&&u[2]===0,f=d?s.slice(0):null;for(let g=0,p=0,b=t.length;g<b;g++)switch(t[g]|0){case Hs.rectangle:r=e[p++],o=e[p++];const _=e[p++],v=e[p++],x=r+_,C=o+v;i.moveTo(r,o),_===0||v===0?i.lineTo(x,C):(i.lineTo(x,o),i.lineTo(x,C),i.lineTo(r,C)),d||n.updateRectMinMax(u,[r,o,x,C]),i.closePath();break;case Hs.moveTo:r=e[p++],o=e[p++],i.moveTo(r,o),d||n.updatePathMinMax(u,r,o);break;case Hs.lineTo:r=e[p++],o=e[p++],i.lineTo(r,o),d||n.updatePathMinMax(u,r,o);break;case Hs.curveTo:h=r,c=o,r=e[p+4],o=e[p+5],i.bezierCurveTo(e[p],e[p+1],e[p+2],e[p+3],r,o),n.updateCurvePathMinMax(u,h,c,e[p],e[p+1],e[p+2],e[p+3],r,o,f),p+=6;break;case Hs.curveTo2:h=r,c=o,i.bezierCurveTo(r,o,e[p],e[p+1],e[p+2],e[p+3]),n.updateCurvePathMinMax(u,h,c,r,o,e[p],e[p+1],e[p+2],e[p+3],f),r=e[p+2],o=e[p+3],p+=4;break;case Hs.curveTo3:h=r,c=o,r=e[p+2],o=e[p+3],i.bezierCurveTo(e[p],e[p+1],r,o,r,o),n.updateCurvePathMinMax(u,h,c,e[p],e[p+1],r,o,r,o,f),p+=4;break;case Hs.closePath:i.closePath();break}d&&n.updateScalingPathMinMax(u,f),n.setCurrentPoint(r,o)}closePath(){this.ctx.closePath()}stroke(t=!0){const e=this.ctx,s=this.current.strokeColor;e.globalAlpha=this.current.strokeAlpha,this.contentVisible&&(typeof s=="object"&&(s!=null&&s.getPattern)?(e.save(),e.strokeStyle=s.getPattern(e,this,li(e),_e.STROKE),this.rescaleAndStroke(!1),e.restore()):this.rescaleAndStroke(!0)),t&&this.consumePath(this.current.getClippedPathBoundingBox()),e.globalAlpha=this.current.fillAlpha}closeStroke(){this.closePath(),this.stroke()}fill(t=!0){const e=this.ctx,s=this.current.fillColor,i=this.current.patternFill;let n=!1;i&&(e.save(),e.fillStyle=s.getPattern(e,this,li(e),_e.FILL),n=!0);const r=this.current.getClippedPathBoundingBox();this.contentVisible&&r!==null&&(this.pendingEOFill?(e.fill("evenodd"),this.pendingEOFill=!1):e.fill()),n&&e.restore(),t&&this.consumePath(r)}eoFill(){this.pendingEOFill=!0,this.fill()}fillStroke(){this.fill(!1),this.stroke(!1),this.consumePath()}eoFillStroke(){this.pendingEOFill=!0,this.fillStroke()}closeFillStroke(){this.closePath(),this.fillStroke()}closeEOFillStroke(){this.pendingEOFill=!0,this.closePath(),this.fillStroke()}endPath(){this.consumePath()}clip(){this.pendingClip=Zx}eoClip(){this.pendingClip=xb}beginText(){this.current.textMatrix=Q0,this.current.textMatrixScale=1,this.current.x=this.current.lineX=0,this.current.y=this.current.lineY=0}endText(){const t=this.pendingTextPaths,e=this.ctx;if(t===void 0){e.beginPath();return}const s=new Path2D,i=e.getTransform().invertSelf();for(const{transform:n,x:r,y:o,fontSize:h,path:c}of t)s.addPath(c,new DOMMatrix(n).preMultiplySelf(i).translate(r,o).scale(h,-h));e.clip(s),e.beginPath(),delete this.pendingTextPaths}setCharSpacing(t){this.current.charSpacing=t}setWordSpacing(t){this.current.wordSpacing=t}setHScale(t){this.current.textHScale=t/100}setLeading(t){this.current.leading=-t}setFont(t,e){var u;const s=this.commonObjs.get(t),i=this.current;if(!s)throw new Error(`Can't find font for ${t}`);if(i.fontMatrix=s.fontMatrix||rg,(i.fontMatrix[0]===0||i.fontMatrix[3]===0)&&et("Invalid font matrix for font "+t),e<0?(e=-e,i.fontDirection=-1):i.fontDirection=1,this.current.font=s,this.current.fontSize=e,s.isType3Font)return;const n=s.loadedName||"sans-serif",r=((u=s.systemFontInfo)==null?void 0:u.css)||`"${n}", ${s.fallbackName}`;let o="normal";s.black?o="900":s.bold&&(o="bold");const h=s.italic?"italic":"normal";let c=e;e<gb?c=gb:e>pb&&(c=pb),this.current.fontSizeScale=e/c,this.ctx.font=`${h} ${o} ${c}px ${r}`}setTextRenderingMode(t){this.current.textRenderingMode=t}setTextRise(t){this.current.textRise=t}moveText(t,e){this.current.x=this.current.lineX+=t,this.current.y=this.current.lineY+=e}setLeadingMoveText(t,e){this.setLeading(-e),this.moveText(t,e)}setTextMatrix(t,e,s,i,n,r){this.current.textMatrix=[t,e,s,i,n,r],this.current.textMatrixScale=Math.hypot(t,e),this.current.x=this.current.lineX=0,this.current.y=this.current.lineY=0}nextLine(){this.moveText(0,this.current.leading)}paintChar(t,e,s,i,n){const r=this.ctx,o=this.current,h=o.font,c=o.textRenderingMode,u=o.fontSize/o.fontSizeScale,d=c&ve.FILL_STROKE_MASK,f=!!(c&ve.ADD_TO_PATH_FLAG),g=o.patternFill&&!h.missingFile,p=o.patternStroke&&!h.missingFile;let b;if((h.disableFontFace||f||g||p)&&(b=h.getPathGenerator(this.commonObjs,t)),h.disableFontFace||g||p){if(r.save(),r.translate(e,s),r.scale(u,-u),d===ve.FILL||d===ve.FILL_STROKE)if(i){const _=r.getTransform();r.setTransform(...i),r.fill(w(this,Ys,mp).call(this,b,_,i))}else r.fill(b);if(d===ve.STROKE||d===ve.FILL_STROKE)if(n){const _=r.getTransform();r.setTransform(...n),r.stroke(w(this,Ys,mp).call(this,b,_,n))}else r.lineWidth/=u,r.stroke(b);r.restore()}else(d===ve.FILL||d===ve.FILL_STROKE)&&r.fillText(t,e,s),(d===ve.STROKE||d===ve.FILL_STROKE)&&r.strokeText(t,e,s);f&&(this.pendingTextPaths||(this.pendingTextPaths=[])).push({transform:Tt(r),x:e,y:s,fontSize:u,path:b})}get isFontSubpixelAAEnabled(){const{context:t}=this.cachedCanvases.getCanvas("isFontSubpixelAAEnabled",10,10);t.scale(1.5,1),t.fillText("I",0,10);const e=t.getImageData(0,0,10,10).data;let s=!1;for(let i=3;i<e.length;i+=4)if(e[i]>0&&e[i]<255){s=!0;break}return it(this,"isFontSubpixelAAEnabled",s)}showText(t){const e=this.current,s=e.font;if(s.isType3Font)return this.showType3Text(t);const i=e.fontSize;if(i===0)return;const n=this.ctx,r=e.fontSizeScale,o=e.charSpacing,h=e.wordSpacing,c=e.fontDirection,u=e.textHScale*c,d=t.length,f=s.vertical,g=f?1:-1,p=s.defaultVMetrics,b=i*e.fontMatrix[0],_=e.textRenderingMode===ve.FILL&&!s.disableFontFace&&!e.patternFill;n.save(),n.transform(...e.textMatrix),n.translate(e.x,e.y+e.textRise),c>0?n.scale(u,-1):n.scale(u,1);let v,x;if(e.patternFill){n.save();const M=e.fillColor.getPattern(n,this,li(n),_e.FILL);v=Tt(n),n.restore(),n.fillStyle=M}if(e.patternStroke){n.save();const M=e.strokeColor.getPattern(n,this,li(n),_e.STROKE);x=Tt(n),n.restore(),n.strokeStyle=M}let C=e.lineWidth;const S=e.textMatrixScale;if(S===0||C===0){const M=e.textRenderingMode&ve.FILL_STROKE_MASK;(M===ve.STROKE||M===ve.FILL_STROKE)&&(C=this.getSinglePixelWidth())}else C/=S;if(r!==1&&(n.scale(r,r),C/=r),n.lineWidth=C,s.isInvalidPDFjsFont){const M=[];let D=0;for(const R of t)M.push(R.unicode),D+=R.width;n.fillText(M.join(""),0,0),e.x+=D*b*u,n.restore(),this.compose();return}let E=0,k;for(k=0;k<d;++k){const M=t[k];if(typeof M=="number"){E+=g*M*i/1e3;continue}let D=!1;const R=(M.isSpace?h:0)+o,B=M.fontChar,O=M.accent;let F,L,N=M.width;if(f){const I=M.vmetric||p,X=-(M.vmetric?I[1]:N*.5)*b,rt=I[2]*b;N=I?-I[0]:N,F=X/r,L=(E+rt)/r}else F=E/r,L=0;if(s.remeasure&&N>0){const I=n.measureText(B).width*1e3/i*r;if(N<I&&this.isFontSubpixelAAEnabled){const X=N/I;D=!0,n.save(),n.scale(X,1),F/=X}else N!==I&&(F+=(N-I)/2e3*i/r)}if(this.contentVisible&&(M.isInFont||s.missingFile)){if(_&&!O)n.fillText(B,F,L);else if(this.paintChar(B,F,L,v,x),O){const I=F+i*O.offset.x/r,X=L-i*O.offset.y/r;this.paintChar(O.fontChar,I,X,v,x)}}const Y=f?N*b-R*c:N*b+R*c;E+=Y,D&&n.restore()}f?e.y-=E:e.x+=E*u,n.restore(),this.compose()}showType3Text(t){const e=this.ctx,s=this.current,i=s.font,n=s.fontSize,r=s.fontDirection,o=i.vertical?1:-1,h=s.charSpacing,c=s.wordSpacing,u=s.textHScale*r,d=s.fontMatrix||rg,f=t.length,g=s.textRenderingMode===ve.INVISIBLE;let p,b,_,v;if(!(g||n===0)){for(this._cachedScaleForStroking[0]=-1,this._cachedGetSinglePixelWidth=null,e.save(),e.transform(...s.textMatrix),e.translate(s.x,s.y),e.scale(u,r),p=0;p<f;++p){if(b=t[p],typeof b=="number"){v=o*b*n/1e3,this.ctx.translate(v,0),s.x+=v*u;continue}const x=(b.isSpace?c:0)+h,C=i.charProcOperatorList[b.operatorListId];if(!C){et(`Type3 character "${b.operatorListId}" is not available.`);continue}this.contentVisible&&(this.processingType3=b,this.save(),e.scale(n,n),e.transform(...d),this.executeOperatorList(C),this.restore()),_=U.applyTransform([b.width,0],d)[0]*n+x,e.translate(_,0),s.x+=_*u}e.restore(),this.processingType3=null}}setCharWidth(t,e){}setCharWidthAndBounds(t,e,s,i,n,r){this.ctx.rect(s,i,n-s,r-i),this.ctx.clip(),this.endPath()}getColorN_Pattern(t){let e;if(t[0]==="TilingPattern"){const s=t[1],i=this.baseTransform||Tt(this.ctx),n={createCanvasGraphics:r=>new Wg(r,this.commonObjs,this.objs,this.canvasFactory,this.filterFactory,{optionalContentConfig:this.optionalContentConfig,markedContentStack:this.markedContentStack})};e=new Tg(t,s,this.ctx,n,i)}else e=this._getPattern(t[1],t[2]);return e}setStrokeColorN(){this.current.strokeColor=this.getColorN_Pattern(arguments),this.current.patternStroke=!0}setFillColorN(){this.current.fillColor=this.getColorN_Pattern(arguments),this.current.patternFill=!0}setStrokeRGBColor(t,e,s){this.ctx.strokeStyle=this.current.strokeColor=U.makeHexColor(t,e,s),this.current.patternStroke=!1}setStrokeTransparent(){this.ctx.strokeStyle=this.current.strokeColor="transparent",this.current.patternStroke=!1}setFillRGBColor(t,e,s){this.ctx.fillStyle=this.current.fillColor=U.makeHexColor(t,e,s),this.current.patternFill=!1}setFillTransparent(){this.ctx.fillStyle=this.current.fillColor="transparent",this.current.patternFill=!1}_getPattern(t,e=null){let s;return this.cachedPatterns.has(t)?s=this.cachedPatterns.get(t):(s=Wx(this.getObject(t)),this.cachedPatterns.set(t,s)),e&&(s.matrix=e),s}shadingFill(t){if(!this.contentVisible)return;const e=this.ctx;this.save();const s=this._getPattern(t);e.fillStyle=s.getPattern(e,this,li(e),_e.SHADING);const i=li(e);if(i){const{width:n,height:r}=e.canvas,[o,h,c,u]=U.getAxialAlignedBoundingBox([0,0,n,r],i);this.ctx.fillRect(o,h,c-o,u-h)}else this.ctx.fillRect(-1e10,-1e10,2e10,2e10);this.compose(this.current.getClippedPathBoundingBox()),this.restore()}beginInlineImage(){vt("Should not call beginInlineImage")}beginImageData(){vt("Should not call beginImageData")}paintFormXObjectBegin(t,e){if(this.contentVisible&&(this.save(),this.baseTransformStack.push(this.baseTransform),t&&this.transform(...t),this.baseTransform=Tt(this.ctx),e)){const s=e[2]-e[0],i=e[3]-e[1];this.ctx.rect(e[0],e[1],s,i),this.current.updateRectMinMax(Tt(this.ctx),e),this.clip(),this.endPath()}}paintFormXObjectEnd(){this.contentVisible&&(this.restore(),this.baseTransform=this.baseTransformStack.pop())}beginGroup(t){if(!this.contentVisible)return;this.save(),this.inSMaskMode&&(this.endSMaskMode(),this.current.activeSMask=null);const e=this.ctx;t.isolated||Xu("TODO: Support non-isolated groups."),t.knockout&&et("Knockout groups not supported.");const s=Tt(e);if(t.matrix&&e.transform(...t.matrix),!t.bbox)throw new Error("Bounding box is required.");let i=U.getAxialAlignedBoundingBox(t.bbox,Tt(e));const n=[0,0,e.canvas.width,e.canvas.height];i=U.intersect(i,n)||[0,0,0,0];const r=Math.floor(i[0]),o=Math.floor(i[1]),h=Math.max(Math.ceil(i[2])-r,1),c=Math.max(Math.ceil(i[3])-o,1);this.current.startNewPathAndClipBox([0,0,h,c]);let u="groupAt"+this.groupLevel;t.smask&&(u+="_smask_"+this.smaskCounter++%2);const d=this.cachedCanvases.getCanvas(u,h,c),f=d.context;f.translate(-r,-o),f.transform(...s),t.smask?this.smaskStack.push({canvas:d.canvas,context:f,offsetX:r,offsetY:o,subtype:t.smask.subtype,backdrop:t.smask.backdrop,transferMap:t.smask.transferMap||null,startTransformInverse:null}):(e.setTransform(1,0,0,1,0,0),e.translate(r,o),e.save()),Yh(e,f),this.ctx=f,this.setGState([["BM","source-over"],["ca",1],["CA",1]]),this.groupStack.push(e),this.groupLevel++}endGroup(t){if(!this.contentVisible)return;this.groupLevel--;const e=this.ctx,s=this.groupStack.pop();if(this.ctx=s,this.ctx.imageSmoothingEnabled=!1,t.smask)this.tempSMask=this.smaskStack.pop(),this.restore();else{this.ctx.restore();const i=Tt(this.ctx);this.restore(),this.ctx.save(),this.ctx.setTransform(...i);const n=U.getAxialAlignedBoundingBox([0,0,e.canvas.width,e.canvas.height],i);this.ctx.drawImage(e.canvas,0,0),this.ctx.restore(),this.compose(n)}}beginAnnotation(t,e,s,i,n){if(w(this,Ys,gp).call(this),td(this.ctx),this.ctx.save(),this.save(),this.baseTransform&&this.ctx.setTransform(...this.baseTransform),e){const r=e[2]-e[0],o=e[3]-e[1];if(n&&this.annotationCanvasMap){s=s.slice(),s[4]-=e[0],s[5]-=e[1],e=e.slice(),e[0]=e[1]=0,e[2]=r,e[3]=o;const[h,c]=U.singularValueDecompose2dScale(Tt(this.ctx)),{viewportScale:u}=this,d=Math.ceil(r*this.outputScaleX*u),f=Math.ceil(o*this.outputScaleY*u);this.annotationCanvas=this.canvasFactory.create(d,f);const{canvas:g,context:p}=this.annotationCanvas;this.annotationCanvasMap.set(t,g),this.annotationCanvas.savedCtx=this.ctx,this.ctx=p,this.ctx.save(),this.ctx.setTransform(h,0,0,-c,0,o*c),td(this.ctx)}else td(this.ctx),this.endPath(),this.ctx.rect(e[0],e[1],r,o),this.ctx.clip(),this.ctx.beginPath()}this.current=new yb(this.ctx.canvas.width,this.ctx.canvas.height),this.transform(...s),this.transform(...i)}endAnnotation(){this.annotationCanvas&&(this.ctx.restore(),w(this,Ys,pp).call(this),this.ctx=this.annotationCanvas.savedCtx,delete this.annotationCanvas.savedCtx,delete this.annotationCanvas)}paintImageMaskXObject(t){if(!this.contentVisible)return;const e=t.count;t=this.getObject(t.data,t),t.count=e;const s=this.ctx,i=this.processingType3;if(i&&(i.compiled===void 0&&(i.compiled=Kx(t)),i.compiled)){i.compiled(s);return}const n=this._createMaskCanvas(t),r=n.canvas;s.save(),s.setTransform(1,0,0,1,0,0),s.drawImage(r,n.offsetX,n.offsetY),s.restore(),this.compose()}paintImageMaskXObjectRepeat(t,e,s=0,i=0,n,r){if(!this.contentVisible)return;t=this.getObject(t.data,t);const o=this.ctx;o.save();const h=Tt(o);o.transform(e,s,i,n,0,0);const c=this._createMaskCanvas(t);o.setTransform(1,0,0,1,c.offsetX-h[4],c.offsetY-h[5]);for(let u=0,d=r.length;u<d;u+=2){const f=U.transform(h,[e,s,i,n,r[u],r[u+1]]),[g,p]=U.applyTransform([0,0],f);o.drawImage(c.canvas,g,p)}o.restore(),this.compose()}paintImageMaskXObjectGroup(t){if(!this.contentVisible)return;const e=this.ctx,s=this.current.fillColor,i=this.current.patternFill;for(const n of t){const{data:r,width:o,height:h,transform:c}=n,u=this.cachedCanvases.getCanvas("maskCanvas",o,h),d=u.context;d.save();const f=this.getObject(r,n);_b(d,f),d.globalCompositeOperation="source-in",d.fillStyle=i?s.getPattern(d,this,li(e),_e.FILL):s,d.fillRect(0,0,o,h),d.restore(),e.save(),e.transform(...c),e.scale(1,-1),Zu(e,u.canvas,0,0,o,h,0,-1,1,1),e.restore()}this.compose()}paintImageXObject(t){if(!this.contentVisible)return;const e=this.getObject(t);if(!e){et("Dependent image isn't ready yet");return}this.paintInlineImageXObject(e)}paintImageXObjectRepeat(t,e,s,i){if(!this.contentVisible)return;const n=this.getObject(t);if(!n){et("Dependent image isn't ready yet");return}const r=n.width,o=n.height,h=[];for(let c=0,u=i.length;c<u;c+=2)h.push({transform:[e,0,0,s,i[c],i[c+1]],x:0,y:0,w:r,h:o});this.paintInlineImageXObjectGroup(n,h)}applyTransferMapsToCanvas(t){return this.current.transferMaps!=="none"&&(t.filter=this.current.transferMaps,t.drawImage(t.canvas,0,0),t.filter="none"),t.canvas}applyTransferMapsToBitmap(t){if(this.current.transferMaps==="none")return t.bitmap;const{bitmap:e,width:s,height:i}=t,n=this.cachedCanvases.getCanvas("inlineImage",s,i),r=n.context;return r.filter=this.current.transferMaps,r.drawImage(e,0,0),r.filter="none",n.canvas}paintInlineImageXObject(t){if(!this.contentVisible)return;const e=t.width,s=t.height,i=this.ctx;if(this.save(),!ye){const{filter:o}=i;o!=="none"&&o!==""&&(i.filter="none")}i.scale(1/e,-1/s);let n;if(t.bitmap)n=this.applyTransferMapsToBitmap(t);else if(typeof HTMLElement=="function"&&t instanceof HTMLElement||!t.data)n=t;else{const h=this.cachedCanvases.getCanvas("inlineImage",e,s).context;vb(h,t),n=this.applyTransferMapsToCanvas(h)}const r=this._scaleImage(n,li(i));i.imageSmoothingEnabled=wb(Tt(i),t.interpolate),Zu(i,r.img,0,0,r.paintWidth,r.paintHeight,0,-s,e,s),this.compose(),this.restore()}paintInlineImageXObjectGroup(t,e){if(!this.contentVisible)return;const s=this.ctx;let i;if(t.bitmap)i=t.bitmap;else{const n=t.width,r=t.height,h=this.cachedCanvases.getCanvas("inlineImage",n,r).context;vb(h,t),i=this.applyTransferMapsToCanvas(h)}for(const n of e)s.save(),s.transform(...n.transform),s.scale(1,-1),Zu(s,i,n.x,n.y,n.w,n.h,0,-1,1,1),s.restore();this.compose()}paintSolidColorImageMask(){this.contentVisible&&(this.ctx.fillRect(0,0,1,1),this.compose())}markPoint(t){}markPointProps(t,e){}beginMarkedContent(t){this.markedContentStack.push({visible:!0})}beginMarkedContentProps(t,e){t==="OC"?this.markedContentStack.push({visible:this.optionalContentConfig.isVisible(e)}):this.markedContentStack.push({visible:!0}),this.contentVisible=this.isContentVisible()}endMarkedContent(){this.markedContentStack.pop(),this.contentVisible=this.isContentVisible()}beginCompat(){}endCompat(){}consumePath(t){const e=this.current.isEmptyClip();this.pendingClip&&this.current.updateClipFromPath(),this.pendingClip||this.compose(t);const s=this.ctx;this.pendingClip&&(e||(this.pendingClip===xb?s.clip("evenodd"):s.clip()),this.pendingClip=null),this.current.startNewPathAndClipBox(this.current.clipBox),s.beginPath()}getSinglePixelWidth(){if(!this._cachedGetSinglePixelWidth){const t=Tt(this.ctx);if(t[1]===0&&t[2]===0)this._cachedGetSinglePixelWidth=1/Math.min(Math.abs(t[0]),Math.abs(t[3]));else{const e=Math.abs(t[0]*t[3]-t[2]*t[1]),s=Math.hypot(t[0],t[2]),i=Math.hypot(t[1],t[3]);this._cachedGetSinglePixelWidth=Math.max(s,i)/e}}return this._cachedGetSinglePixelWidth}getScaleForStroking(){if(this._cachedScaleForStroking[0]===-1){const{lineWidth:t}=this.current,{a:e,b:s,c:i,d:n}=this.ctx.getTransform();let r,o;if(s===0&&i===0){const h=Math.abs(e),c=Math.abs(n);if(h===c)if(t===0)r=o=1/h;else{const u=h*t;r=o=u<1?1/u:1}else if(t===0)r=1/h,o=1/c;else{const u=h*t,d=c*t;r=u<1?1/u:1,o=d<1?1/d:1}}else{const h=Math.abs(e*n-s*i),c=Math.hypot(e,s),u=Math.hypot(i,n);if(t===0)r=u/h,o=c/h;else{const d=t*h;r=u>d?u/d:1,o=c>d?c/d:1}}this._cachedScaleForStroking[0]=r,this._cachedScaleForStroking[1]=o}return this._cachedScaleForStroking}rescaleAndStroke(t){const{ctx:e}=this,{lineWidth:s}=this.current,[i,n]=this.getScaleForStroking();if(e.lineWidth=s||1,i===1&&n===1){e.stroke();return}const r=e.getLineDash();if(t&&e.save(),e.scale(i,n),r.length>0){const o=Math.max(i,n);e.setLineDash(r.map(h=>h/o)),e.lineDashOffset/=o}e.stroke(),t&&e.restore()}isContentVisible(){for(let t=this.markedContentStack.length-1;t>=0;t--)if(!this.markedContentStack[t].visible)return!1;return!0}};Ys=new WeakSet,gp=function(){for(;this.stateStack.length||this.inSMaskMode;)this.restore();this.current.activeSMask=null,this.ctx.restore(),this.transparentCanvas&&(this.ctx=this.compositeCtx,this.ctx.save(),this.ctx.setTransform(1,0,0,1,0,0),this.ctx.drawImage(this.transparentCanvas,0,0),this.ctx.restore(),this.transparentCanvas=null)},pp=function(){if(this.pageColors){const t=this.filterFactory.addHCMFilter(this.pageColors.foreground,this.pageColors.background);if(t!=="none"){const e=this.ctx.filter;this.ctx.filter=t,this.ctx.drawImage(this.ctx.canvas,0,0),this.ctx.filter=e}}},mp=function(t,e,s){const i=new Path2D;return i.addPath(t,new DOMMatrix(s).invertSelf().multiplySelf(e)),i};let ra=Wg;for(const a in Hs)ra.prototype[a]!==void 0&&(ra.prototype[Hs[a]]=ra.prototype[a]);class Vi{static get workerPort(){return l(this,El)}static set workerPort(t){if(!(typeof Worker<"u"&&t instanceof Worker)&&t!==null)throw new Error("Invalid `workerPort` type.");m(this,El,t)}static get workerSrc(){return l(this,kl)}static set workerSrc(t){if(typeof t!="string")throw new Error("Invalid `workerSrc` type.");m(this,kl,t)}}El=new WeakMap,kl=new WeakMap,y(Vi,El,null),y(Vi,kl,"");class tS{constructor({parsedData:t,rawData:e}){y(this,so);y(this,Ml);m(this,so,t),m(this,Ml,e)}getRaw(){return l(this,Ml)}get(t){return l(this,so).get(t)??null}getAll(){return lg(l(this,so))}has(t){return l(this,so).has(t)}}so=new WeakMap,Ml=new WeakMap;const oa=Symbol("INTERNAL");class eS{constructor(t,{name:e,intent:s,usage:i,rbGroups:n}){y(this,Pl,!1);y(this,Dl,!1);y(this,Ol,!1);y(this,Ta,!0);m(this,Pl,!!(t&ts.DISPLAY)),m(this,Dl,!!(t&ts.PRINT)),this.name=e,this.intent=s,this.usage=i,this.rbGroups=n}get visible(){if(l(this,Ol))return l(this,Ta);if(!l(this,Ta))return!1;const{print:t,view:e}=this.usage;return l(this,Pl)?(e==null?void 0:e.viewState)!=="OFF":l(this,Dl)?(t==null?void 0:t.printState)!=="OFF":!0}_setVisible(t,e,s=!1){t!==oa&&vt("Internal method `_setVisible` called."),m(this,Ol,s),m(this,Ta,e)}}Pl=new WeakMap,Dl=new WeakMap,Ol=new WeakMap,Ta=new WeakMap;class sS{constructor(t,e=ts.DISPLAY){y(this,Rl);y(this,qn,null);y(this,mt,new Map);y(this,Ea,null);y(this,ka,null);if(this.renderingIntent=e,this.name=null,this.creator=null,t!==null){this.name=t.name,this.creator=t.creator,m(this,ka,t.order);for(const s of t.groups)l(this,mt).set(s.id,new eS(e,s));if(t.baseState==="OFF")for(const s of l(this,mt).values())s._setVisible(oa,!1);for(const s of t.on)l(this,mt).get(s)._setVisible(oa,!0);for(const s of t.off)l(this,mt).get(s)._setVisible(oa,!1);m(this,Ea,this.getHash())}}isVisible(t){if(l(this,mt).size===0)return!0;if(!t)return Xu("Optional content group not defined."),!0;if(t.type==="OCG")return l(this,mt).has(t.id)?l(this,mt).get(t.id).visible:(et(`Optional content group not found: ${t.id}`),!0);if(t.type==="OCMD"){if(t.expression)return w(this,Rl,bp).call(this,t.expression);if(!t.policy||t.policy==="AnyOn"){for(const e of t.ids){if(!l(this,mt).has(e))return et(`Optional content group not found: ${e}`),!0;if(l(this,mt).get(e).visible)return!0}return!1}else if(t.policy==="AllOn"){for(const e of t.ids){if(!l(this,mt).has(e))return et(`Optional content group not found: ${e}`),!0;if(!l(this,mt).get(e).visible)return!1}return!0}else if(t.policy==="AnyOff"){for(const e of t.ids){if(!l(this,mt).has(e))return et(`Optional content group not found: ${e}`),!0;if(!l(this,mt).get(e).visible)return!0}return!1}else if(t.policy==="AllOff"){for(const e of t.ids){if(!l(this,mt).has(e))return et(`Optional content group not found: ${e}`),!0;if(l(this,mt).get(e).visible)return!1}return!0}return et(`Unknown optional content policy ${t.policy}.`),!0}return et(`Unknown group type ${t.type}.`),!0}setVisibility(t,e=!0,s=!0){var n;const i=l(this,mt).get(t);if(!i){et(`Optional content group not found: ${t}`);return}if(s&&e&&i.rbGroups.length)for(const r of i.rbGroups)for(const o of r)o!==t&&((n=l(this,mt).get(o))==null||n._setVisible(oa,!1,!0));i._setVisible(oa,!!e,!0),m(this,qn,null)}setOCGState({state:t,preserveRB:e}){let s;for(const i of t){switch(i){case"ON":case"OFF":case"Toggle":s=i;continue}const n=l(this,mt).get(i);if(n)switch(s){case"ON":this.setVisibility(i,!0,e);break;case"OFF":this.setVisibility(i,!1,e);break;case"Toggle":this.setVisibility(i,!n.visible,e);break}}m(this,qn,null)}get hasInitialVisibility(){return l(this,Ea)===null||this.getHash()===l(this,Ea)}getOrder(){return l(this,mt).size?l(this,ka)?l(this,ka).slice():[...l(this,mt).keys()]:null}getGroups(){return l(this,mt).size>0?lg(l(this,mt)):null}getGroup(t){return l(this,mt).get(t)||null}getHash(){if(l(this,qn)!==null)return l(this,qn);const t=new ib;for(const[e,s]of l(this,mt))t.update(`${e}:${s.visible}`);return m(this,qn,t.hexdigest())}}qn=new WeakMap,mt=new WeakMap,Ea=new WeakMap,ka=new WeakMap,Rl=new WeakSet,bp=function(t){const e=t.length;if(e<2)return!0;const s=t[0];for(let i=1;i<e;i++){const n=t[i];let r;if(Array.isArray(n))r=w(this,Rl,bp).call(this,n);else if(l(this,mt).has(n))r=l(this,mt).get(n).visible;else return et(`Optional content group not found: ${n}`),!0;switch(s){case"And":if(!r)return!1;break;case"Or":if(r)return!0;break;case"Not":return!r;default:return!0}}return s==="And"};class iS{constructor(t,{disableRange:e=!1,disableStream:s=!1}){Xt(t,'PDFDataTransportStream - missing required "pdfDataRangeTransport" argument.');const{length:i,initialData:n,progressiveDone:r,contentDispositionFilename:o}=t;if(this._queuedChunks=[],this._progressiveDone=r,this._contentDispositionFilename=o,(n==null?void 0:n.length)>0){const h=n instanceof Uint8Array&&n.byteLength===n.buffer.byteLength?n.buffer:new Uint8Array(n).buffer;this._queuedChunks.push(h)}this._pdfDataRangeTransport=t,this._isStreamingSupported=!s,this._isRangeSupported=!e,this._contentLength=i,this._fullRequestReader=null,this._rangeReaders=[],t.addRangeListener((h,c)=>{this._onReceiveData({begin:h,chunk:c})}),t.addProgressListener((h,c)=>{this._onProgress({loaded:h,total:c})}),t.addProgressiveReadListener(h=>{this._onReceiveData({chunk:h})}),t.addProgressiveDoneListener(()=>{this._onProgressiveDone()}),t.transportReady()}_onReceiveData({begin:t,chunk:e}){const s=e instanceof Uint8Array&&e.byteLength===e.buffer.byteLength?e.buffer:new Uint8Array(e).buffer;if(t===void 0)this._fullRequestReader?this._fullRequestReader._enqueue(s):this._queuedChunks.push(s);else{const i=this._rangeReaders.some(function(n){return n._begin!==t?!1:(n._enqueue(s),!0)});Xt(i,"_onReceiveData - no `PDFDataTransportStreamRangeReader` instance found.")}}get _progressiveDataLength(){var t;return((t=this._fullRequestReader)==null?void 0:t._loaded)??0}_onProgress(t){var e,s,i,n;t.total===void 0?(s=(e=this._rangeReaders[0])==null?void 0:e.onProgress)==null||s.call(e,{loaded:t.loaded}):(n=(i=this._fullRequestReader)==null?void 0:i.onProgress)==null||n.call(i,{loaded:t.loaded,total:t.total})}_onProgressiveDone(){var t;(t=this._fullRequestReader)==null||t.progressiveDone(),this._progressiveDone=!0}_removeRangeReader(t){const e=this._rangeReaders.indexOf(t);e>=0&&this._rangeReaders.splice(e,1)}getFullReader(){Xt(!this._fullRequestReader,"PDFDataTransportStream.getFullReader can only be called once.");const t=this._queuedChunks;return this._queuedChunks=null,new nS(this,t,this._progressiveDone,this._contentDispositionFilename)}getRangeReader(t,e){if(e<=this._progressiveDataLength)return null;const s=new rS(this,t,e);return this._pdfDataRangeTransport.requestDataRange(t,e),this._rangeReaders.push(s),s}cancelAllRequests(t){var e;(e=this._fullRequestReader)==null||e.cancel(t);for(const s of this._rangeReaders.slice(0))s.cancel(t);this._pdfDataRangeTransport.abort()}}class nS{constructor(t,e,s=!1,i=null){this._stream=t,this._done=s||!1,this._filename=gg(i)?i:null,this._queuedChunks=e||[],this._loaded=0;for(const n of this._queuedChunks)this._loaded+=n.byteLength;this._requests=[],this._headersReady=Promise.resolve(),t._fullRequestReader=this,this.onProgress=null}_enqueue(t){this._done||(this._requests.length>0?this._requests.shift().resolve({value:t,done:!1}):this._queuedChunks.push(t),this._loaded+=t.byteLength)}get headersReady(){return this._headersReady}get filename(){return this._filename}get isRangeSupported(){return this._stream._isRangeSupported}get isStreamingSupported(){return this._stream._isStreamingSupported}get contentLength(){return this._stream._contentLength}async read(){if(this._queuedChunks.length>0)return{value:this._queuedChunks.shift(),done:!1};if(this._done)return{value:void 0,done:!0};const t=Promise.withResolvers();return this._requests.push(t),t.promise}cancel(t){this._done=!0;for(const e of this._requests)e.resolve({value:void 0,done:!0});this._requests.length=0}progressiveDone(){this._done||(this._done=!0)}}class rS{constructor(t,e,s){this._stream=t,this._begin=e,this._end=s,this._queuedChunk=null,this._requests=[],this._done=!1,this.onProgress=null}_enqueue(t){if(!this._done){if(this._requests.length===0)this._queuedChunk=t;else{this._requests.shift().resolve({value:t,done:!1});for(const s of this._requests)s.resolve({value:void 0,done:!0});this._requests.length=0}this._done=!0,this._stream._removeRangeReader(this)}}get isStreamingSupported(){return!1}async read(){if(this._queuedChunk){const e=this._queuedChunk;return this._queuedChunk=null,{value:e,done:!1}}if(this._done)return{value:void 0,done:!0};const t=Promise.withResolvers();return this._requests.push(t),t.promise}cancel(t){this._done=!0;for(const e of this._requests)e.resolve({value:void 0,done:!0});this._requests.length=0,this._stream._removeRangeReader(this)}}function oS(a){let t=!0,e=s("filename\\*","i").exec(a);if(e){e=e[1];let u=o(e);return u=unescape(u),u=h(u),u=c(u),n(u)}if(e=r(a),e){const u=c(e);return n(u)}if(e=s("filename","i").exec(a),e){e=e[1];let u=o(e);return u=c(u),n(u)}function s(u,d){return new RegExp("(?:^|;)\\s*"+u+'\\s*=\\s*([^";\\s][^;\\s]*|"(?:[^"\\\\]|\\\\"?)+"?)',d)}function i(u,d){if(u){if(!/^[\x00-\xFF]+$/.test(d))return d;try{const f=new TextDecoder(u,{fatal:!0}),g=Uu(d);d=f.decode(g),t=!1}catch{}}return d}function n(u){return t&&/[\x80-\xff]/.test(u)&&(u=i("utf-8",u),t&&(u=i("iso-8859-1",u))),u}function r(u){const d=[];let f;const g=s("filename\\*((?!0\\d)\\d+)(\\*?)","ig");for(;(f=g.exec(u))!==null;){let[,b,_,v]=f;if(b=parseInt(b,10),b in d){if(b===0)break;continue}d[b]=[_,v]}const p=[];for(let b=0;b<d.length&&b in d;++b){let[_,v]=d[b];v=o(v),_&&(v=unescape(v),b===0&&(v=h(v))),p.push(v)}return p.join("")}function o(u){if(u.startsWith('"')){const d=u.slice(1).split('\\"');for(let f=0;f<d.length;++f){const g=d[f].indexOf('"');g!==-1&&(d[f]=d[f].slice(0,g),d.length=f+1),d[f]=d[f].replaceAll(/\\(.)/g,"$1")}u=d.join('"')}return u}function h(u){const d=u.indexOf("'");if(d===-1)return u;const f=u.slice(0,d),p=u.slice(d+1).replace(/^[^']*'/,"");return i(f,p)}function c(u){return!u.startsWith("=?")||/[\x00-\x19\x80-\xff]/.test(u)?u:u.replaceAll(/=\?([\w-]*)\?([QqBb])\?((?:[^?]|\?(?!=))*)\?=/g,function(d,f,g,p){if(g==="q"||g==="Q")return p=p.replaceAll("_"," "),p=p.replaceAll(/=([0-9a-fA-F]{2})/g,function(b,_){return String.fromCharCode(parseInt(_,16))}),i(f,p);try{p=atob(p)}catch{}return i(f,p)})}return""}function Sb(a,t){const e=new Headers;if(!a||!t||typeof t!="object")return e;for(const s in t){const i=t[s];i!==void 0&&e.append(s,i)}return e}function ed(a){try{return new URL(a).origin}catch{}return null}function Cb({responseHeaders:a,isHttp:t,rangeChunkSize:e,disableRange:s}){const i={allowRangeRequests:!1,suggestedLength:void 0},n=parseInt(a.get("Content-Length"),10);return!Number.isInteger(n)||(i.suggestedLength=n,n<=2*e)||s||!t||a.get("Accept-Ranges")!=="bytes"||(a.get("Content-Encoding")||"identity")!=="identity"||(i.allowRangeRequests=!0),i}function Ab(a){const t=a.get("Content-Disposition");if(t){let e=oS(t);if(e.includes("%"))try{e=decodeURIComponent(e)}catch{}if(gg(e))return e}return null}function sd(a,t){return a===404||a===0&&t.startsWith("file:")?new zh('Missing PDF "'+t+'".'):new Wu(`Unexpected server response (${a}) while retrieving PDF "${t}".`,a)}function Tb(a){return a===200||a===206}function Eb(a,t,e){return{method:"GET",headers:a,signal:e.signal,mode:"cors",credentials:t?"include":"same-origin",redirect:"follow"}}function kb(a){return a instanceof Uint8Array?a.buffer:a instanceof ArrayBuffer?a:(et(`getArrayBuffer - unexpected data format: ${a}`),new Uint8Array(a).buffer)}class Mb{constructor(t){q(this,"_responseOrigin",null);this.source=t,this.isHttp=/^https?:/i.test(t.url),this.headers=Sb(this.isHttp,t.httpHeaders),this._fullRequestReader=null,this._rangeRequestReaders=[]}get _progressiveDataLength(){var t;return((t=this._fullRequestReader)==null?void 0:t._loaded)??0}getFullReader(){return Xt(!this._fullRequestReader,"PDFFetchStream.getFullReader can only be called once."),this._fullRequestReader=new aS(this),this._fullRequestReader}getRangeReader(t,e){if(e<=this._progressiveDataLength)return null;const s=new hS(this,t,e);return this._rangeRequestReaders.push(s),s}cancelAllRequests(t){var e;(e=this._fullRequestReader)==null||e.cancel(t);for(const s of this._rangeRequestReaders.slice(0))s.cancel(t)}}class aS{constructor(t){this._stream=t,this._reader=null,this._loaded=0,this._filename=null;const e=t.source;this._withCredentials=e.withCredentials||!1,this._contentLength=e.length,this._headersCapability=Promise.withResolvers(),this._disableRange=e.disableRange||!1,this._rangeChunkSize=e.rangeChunkSize,!this._rangeChunkSize&&!this._disableRange&&(this._disableRange=!0),this._abortController=new AbortController,this._isStreamingSupported=!e.disableStream,this._isRangeSupported=!e.disableRange;const s=new Headers(t.headers),i=e.url;fetch(i,Eb(s,this._withCredentials,this._abortController)).then(n=>{if(t._responseOrigin=ed(n.url),!Tb(n.status))throw sd(n.status,i);this._reader=n.body.getReader(),this._headersCapability.resolve();const r=n.headers,{allowRangeRequests:o,suggestedLength:h}=Cb({responseHeaders:r,isHttp:t.isHttp,rangeChunkSize:this._rangeChunkSize,disableRange:this._disableRange});this._isRangeSupported=o,this._contentLength=h||this._contentLength,this._filename=Ab(r),!this._isStreamingSupported&&this._isRangeSupported&&this.cancel(new Rn("Streaming is disabled."))}).catch(this._headersCapability.reject),this.onProgress=null}get headersReady(){return this._headersCapability.promise}get filename(){return this._filename}get contentLength(){return this._contentLength}get isRangeSupported(){return this._isRangeSupported}get isStreamingSupported(){return this._isStreamingSupported}async read(){var s;await this._headersCapability.promise;const{value:t,done:e}=await this._reader.read();return e?{value:t,done:e}:(this._loaded+=t.byteLength,(s=this.onProgress)==null||s.call(this,{loaded:this._loaded,total:this._contentLength}),{value:kb(t),done:!1})}cancel(t){var e;(e=this._reader)==null||e.cancel(t),this._abortController.abort()}}class hS{constructor(t,e,s){this._stream=t,this._reader=null,this._loaded=0;const i=t.source;this._withCredentials=i.withCredentials||!1,this._readCapability=Promise.withResolvers(),this._isStreamingSupported=!i.disableStream,this._abortController=new AbortController;const n=new Headers(t.headers);n.append("Range",`bytes=${e}-${s-1}`);const r=i.url;fetch(r,Eb(n,this._withCredentials,this._abortController)).then(o=>{const h=ed(o.url);if(h!==t._responseOrigin)throw new Error(`Expected range response-origin "${h}" to match "${t._responseOrigin}".`);if(!Tb(o.status))throw sd(o.status,r);this._readCapability.resolve(),this._reader=o.body.getReader()}).catch(this._readCapability.reject),this.onProgress=null}get isStreamingSupported(){return this._isStreamingSupported}async read(){var s;await this._readCapability.promise;const{value:t,done:e}=await this._reader.read();return e?{value:t,done:e}:(this._loaded+=t.byteLength,(s=this.onProgress)==null||s.call(this,{loaded:this._loaded}),{value:kb(t),done:!1})}cancel(t){var e;(e=this._reader)==null||e.cancel(t),this._abortController.abort()}}const Eg=200,kg=206;function lS(a){const t=a.response;return typeof t!="string"?t:Uu(t).buffer}class cS{constructor({url:t,httpHeaders:e,withCredentials:s}){q(this,"_responseOrigin",null);this.url=t,this.isHttp=/^https?:/i.test(t),this.headers=Sb(this.isHttp,e),this.withCredentials=s||!1,this.currXhrId=0,this.pendingRequests=Object.create(null)}request(t){const e=new XMLHttpRequest,s=this.currXhrId++,i=this.pendingRequests[s]={xhr:e};e.open("GET",this.url),e.withCredentials=this.withCredentials;for(const[n,r]of this.headers)e.setRequestHeader(n,r);return this.isHttp&&"begin"in t&&"end"in t?(e.setRequestHeader("Range",`bytes=${t.begin}-${t.end-1}`),i.expectedStatus=kg):i.expectedStatus=Eg,e.responseType="arraybuffer",Xt(t.onError,"Expected `onError` callback to be provided."),e.onerror=()=>{t.onError(e.status)},e.onreadystatechange=this.onStateChange.bind(this,s),e.onprogress=this.onProgress.bind(this,s),i.onHeadersReceived=t.onHeadersReceived,i.onDone=t.onDone,i.onError=t.onError,i.onProgress=t.onProgress,e.send(null),s}onProgress(t,e){var i;const s=this.pendingRequests[t];s&&((i=s.onProgress)==null||i.call(s,e))}onStateChange(t,e){const s=this.pendingRequests[t];if(!s)return;const i=s.xhr;if(i.readyState>=2&&s.onHeadersReceived&&(s.onHeadersReceived(),delete s.onHeadersReceived),i.readyState!==4||!(t in this.pendingRequests))return;if(delete this.pendingRequests[t],i.status===0&&this.isHttp){s.onError(i.status);return}const n=i.status||Eg;if(!(n===Eg&&s.expectedStatus===kg)&&n!==s.expectedStatus){s.onError(i.status);return}const o=lS(i);if(n===kg){const h=i.getResponseHeader("Content-Range"),c=/bytes (\d+)-(\d+)\/(\d+)/.exec(h);c?s.onDone({begin:parseInt(c[1],10),chunk:o}):(et('Missing or invalid "Content-Range" header.'),s.onError(0))}else o?s.onDone({begin:0,chunk:o}):s.onError(i.status)}getRequestXhr(t){return this.pendingRequests[t].xhr}isPendingRequest(t){return t in this.pendingRequests}abortRequest(t){const e=this.pendingRequests[t].xhr;delete this.pendingRequests[t],e.abort()}}class uS{constructor(t){this._source=t,this._manager=new cS(t),this._rangeChunkSize=t.rangeChunkSize,this._fullRequestReader=null,this._rangeRequestReaders=[]}_onRangeRequestReaderClosed(t){const e=this._rangeRequestReaders.indexOf(t);e>=0&&this._rangeRequestReaders.splice(e,1)}getFullReader(){return Xt(!this._fullRequestReader,"PDFNetworkStream.getFullReader can only be called once."),this._fullRequestReader=new dS(this._manager,this._source),this._fullRequestReader}getRangeReader(t,e){const s=new fS(this._manager,t,e);return s.onClosed=this._onRangeRequestReaderClosed.bind(this),this._rangeRequestReaders.push(s),s}cancelAllRequests(t){var e;(e=this._fullRequestReader)==null||e.cancel(t);for(const s of this._rangeRequestReaders.slice(0))s.cancel(t)}}class dS{constructor(t,e){this._manager=t,this._url=e.url,this._fullRequestId=t.request({onHeadersReceived:this._onHeadersReceived.bind(this),onDone:this._onDone.bind(this),onError:this._onError.bind(this),onProgress:this._onProgress.bind(this)}),this._headersCapability=Promise.withResolvers(),this._disableRange=e.disableRange||!1,this._contentLength=e.length,this._rangeChunkSize=e.rangeChunkSize,!this._rangeChunkSize&&!this._disableRange&&(this._disableRange=!0),this._isStreamingSupported=!1,this._isRangeSupported=!1,this._cachedChunks=[],this._requests=[],this._done=!1,this._storedError=void 0,this._filename=null,this.onProgress=null}_onHeadersReceived(){const t=this._fullRequestId,e=this._manager.getRequestXhr(t);this._manager._responseOrigin=ed(e.responseURL);const s=e.getAllResponseHeaders(),i=new Headers(s?s.trimStart().replace(/[^\S ]+$/,"").split(/[\r\n]+/).map(o=>{const[h,...c]=o.split(": ");return[h,c.join(": ")]}):[]),{allowRangeRequests:n,suggestedLength:r}=Cb({responseHeaders:i,isHttp:this._manager.isHttp,rangeChunkSize:this._rangeChunkSize,disableRange:this._disableRange});n&&(this._isRangeSupported=!0),this._contentLength=r||this._contentLength,this._filename=Ab(i),this._isRangeSupported&&this._manager.abortRequest(t),this._headersCapability.resolve()}_onDone(t){if(t&&(this._requests.length>0?this._requests.shift().resolve({value:t.chunk,done:!1}):this._cachedChunks.push(t.chunk)),this._done=!0,!(this._cachedChunks.length>0)){for(const e of this._requests)e.resolve({value:void 0,done:!0});this._requests.length=0}}_onError(t){this._storedError=sd(t,this._url),this._headersCapability.reject(this._storedError);for(const e of this._requests)e.reject(this._storedError);this._requests.length=0,this._cachedChunks.length=0}_onProgress(t){var e;(e=this.onProgress)==null||e.call(this,{loaded:t.loaded,total:t.lengthComputable?t.total:this._contentLength})}get filename(){return this._filename}get isRangeSupported(){return this._isRangeSupported}get isStreamingSupported(){return this._isStreamingSupported}get contentLength(){return this._contentLength}get headersReady(){return this._headersCapability.promise}async read(){if(await this._headersCapability.promise,this._storedError)throw this._storedError;if(this._cachedChunks.length>0)return{value:this._cachedChunks.shift(),done:!1};if(this._done)return{value:void 0,done:!0};const t=Promise.withResolvers();return this._requests.push(t),t.promise}cancel(t){this._done=!0,this._headersCapability.reject(t);for(const e of this._requests)e.resolve({value:void 0,done:!0});this._requests.length=0,this._manager.isPendingRequest(this._fullRequestId)&&this._manager.abortRequest(this._fullRequestId),this._fullRequestReader=null}}class fS{constructor(t,e,s){this._manager=t,this._url=t.url,this._requestId=t.request({begin:e,end:s,onHeadersReceived:this._onHeadersReceived.bind(this),onDone:this._onDone.bind(this),onError:this._onError.bind(this),onProgress:this._onProgress.bind(this)}),this._requests=[],this._queuedChunk=null,this._done=!1,this._storedError=void 0,this.onProgress=null,this.onClosed=null}_onHeadersReceived(){var e;const t=ed((e=this._manager.getRequestXhr(this._requestId))==null?void 0:e.responseURL);t!==this._manager._responseOrigin&&(this._storedError=new Error(`Expected range response-origin "${t}" to match "${this._manager._responseOrigin}".`),this._onError(0))}_close(){var t;(t=this.onClosed)==null||t.call(this,this)}_onDone(t){const e=t.chunk;this._requests.length>0?this._requests.shift().resolve({value:e,done:!1}):this._queuedChunk=e,this._done=!0;for(const s of this._requests)s.resolve({value:void 0,done:!0});this._requests.length=0,this._close()}_onError(t){this._storedError??(this._storedError=sd(t,this._url));for(const e of this._requests)e.reject(this._storedError);this._requests.length=0,this._queuedChunk=null}_onProgress(t){var e;this.isStreamingSupported||(e=this.onProgress)==null||e.call(this,{loaded:t.loaded})}get isStreamingSupported(){return!1}async read(){if(this._storedError)throw this._storedError;if(this._queuedChunk!==null){const e=this._queuedChunk;return this._queuedChunk=null,{value:e,done:!1}}if(this._done)return{value:void 0,done:!0};const t=Promise.withResolvers();return this._requests.push(t),t.promise}cancel(t){this._done=!0;for(const e of this._requests)e.resolve({value:void 0,done:!0});this._requests.length=0,this._manager.isPendingRequest(this._requestId)&&this._manager.abortRequest(this._requestId),this._close()}}const gS=/^[a-z][a-z0-9\-+.]+:/i;function pS(a){if(gS.test(a))return new URL(a);const t=process.getBuiltinModule("url");return new URL(t.pathToFileURL(a))}class mS{constructor(t){this.source=t,this.url=pS(t.url),Xt(this.url.protocol==="file:","PDFNodeStream only supports file:// URLs."),this._fullRequestReader=null,this._rangeRequestReaders=[]}get _progressiveDataLength(){var t;return((t=this._fullRequestReader)==null?void 0:t._loaded)??0}getFullReader(){return Xt(!this._fullRequestReader,"PDFNodeStream.getFullReader can only be called once."),this._fullRequestReader=new bS(this),this._fullRequestReader}getRangeReader(t,e){if(e<=this._progressiveDataLength)return null;const s=new yS(this,t,e);return this._rangeRequestReaders.push(s),s}cancelAllRequests(t){var e;(e=this._fullRequestReader)==null||e.cancel(t);for(const s of this._rangeRequestReaders.slice(0))s.cancel(t)}}class bS{constructor(t){this._url=t.url,this._done=!1,this._storedError=null,this.onProgress=null;const e=t.source;this._contentLength=e.length,this._loaded=0,this._filename=null,this._disableRange=e.disableRange||!1,this._rangeChunkSize=e.rangeChunkSize,!this._rangeChunkSize&&!this._disableRange&&(this._disableRange=!0),this._isStreamingSupported=!e.disableStream,this._isRangeSupported=!e.disableRange,this._readableStream=null,this._readCapability=Promise.withResolvers(),this._headersCapability=Promise.withResolvers();const s=process.getBuiltinModule("fs");s.promises.lstat(this._url).then(i=>{this._contentLength=i.size,this._setReadableStream(s.createReadStream(this._url)),this._headersCapability.resolve()},i=>{i.code==="ENOENT"&&(i=new zh(`Missing PDF "${this._url}".`)),this._storedError=i,this._headersCapability.reject(i)})}get headersReady(){return this._headersCapability.promise}get filename(){return this._filename}get contentLength(){return this._contentLength}get isRangeSupported(){return this._isRangeSupported}get isStreamingSupported(){return this._isStreamingSupported}async read(){var s;if(await this._readCapability.promise,this._done)return{value:void 0,done:!0};if(this._storedError)throw this._storedError;const t=this._readableStream.read();return t===null?(this._readCapability=Promise.withResolvers(),this.read()):(this._loaded+=t.length,(s=this.onProgress)==null||s.call(this,{loaded:this._loaded,total:this._contentLength}),{value:new Uint8Array(t).buffer,done:!1})}cancel(t){if(!this._readableStream){this._error(t);return}this._readableStream.destroy(t)}_error(t){this._storedError=t,this._readCapability.resolve()}_setReadableStream(t){this._readableStream=t,t.on("readable",()=>{this._readCapability.resolve()}),t.on("end",()=>{t.destroy(),this._done=!0,this._readCapability.resolve()}),t.on("error",e=>{this._error(e)}),!this._isStreamingSupported&&this._isRangeSupported&&this._error(new Rn("streaming is disabled")),this._storedError&&this._readableStream.destroy(this._storedError)}}class yS{constructor(t,e,s){this._url=t.url,this._done=!1,this._storedError=null,this.onProgress=null,this._loaded=0,this._readableStream=null,this._readCapability=Promise.withResolvers();const i=t.source;this._isStreamingSupported=!i.disableStream;const n=process.getBuiltinModule("fs");this._setReadableStream(n.createReadStream(this._url,{start:e,end:s-1}))}get isStreamingSupported(){return this._isStreamingSupported}async read(){var s;if(await this._readCapability.promise,this._done)return{value:void 0,done:!0};if(this._storedError)throw this._storedError;const t=this._readableStream.read();return t===null?(this._readCapability=Promise.withResolvers(),this.read()):(this._loaded+=t.length,(s=this.onProgress)==null||s.call(this,{loaded:this._loaded}),{value:new Uint8Array(t).buffer,done:!1})}cancel(t){if(!this._readableStream){this._error(t);return}this._readableStream.destroy(t)}_error(t){this._storedError=t,this._readCapability.resolve()}_setReadableStream(t){this._readableStream=t,t.on("readable",()=>{this._readCapability.resolve()}),t.on("end",()=>{t.destroy(),this._done=!0,this._readCapability.resolve()}),t.on("error",e=>{this._error(e)}),this._storedError&&this._readableStream.destroy(this._storedError)}}const vS=1e5,Ye=30,_S=.8,Qt=class Qt{constructor({textContentSource:t,container:e,viewport:s}){y(this,nn);y(this,Kn,Promise.withResolvers());y(this,qe,null);y(this,Ll,!1);y(this,Fl,!!((Xb=globalThis.FontInspector)!=null&&Xb.enabled));y(this,io,null);y(this,sn,null);y(this,Il,0);y(this,Nl,0);y(this,no,null);y(this,Ma,null);y(this,Pa,0);y(this,Qn,0);y(this,Da,Object.create(null));y(this,jl,[]);y(this,Oa,null);y(this,ro,[]);y(this,Bl,new WeakMap);y(this,Hl,null);var h;if(t instanceof ReadableStream)m(this,Oa,t);else if(typeof t=="object")m(this,Oa,new ReadableStream({start(c){c.enqueue(t),c.close()}}));else throw new Error('No "textContentSource" parameter specified.');m(this,qe,m(this,Ma,e)),m(this,Qn,s.scale*(globalThis.devicePixelRatio||1)),m(this,Pa,s.rotation),m(this,sn,{div:null,properties:null,ctx:null});const{pageWidth:i,pageHeight:n,pageX:r,pageY:o}=s.rawDims;m(this,Hl,[1,0,0,-1,-r,o+n]),m(this,Nl,i),m(this,Il,n),w(h=Qt,rs,ky).call(h),kr(e,s),l(this,Kn).promise.finally(()=>{l(Qt,Ra).delete(this),m(this,sn,null),m(this,Da,null)}).catch(()=>{})}static get fontFamilyMap(){const{isWindows:t,isFirefox:e}=Re.platform;return it(this,"fontFamilyMap",new Map([["sans-serif",`${t&&e?"Calibri, ":""}sans-serif`],["monospace",`${t&&e?"Lucida Console, ":""}monospace`]]))}render(){const t=()=>{l(this,no).read().then(({value:e,done:s})=>{if(s){l(this,Kn).resolve();return}l(this,io)??m(this,io,e.lang),Object.assign(l(this,Da),e.styles),w(this,nn,Ty).call(this,e.items),t()},l(this,Kn).reject)};return m(this,no,l(this,Oa).getReader()),l(Qt,Ra).add(this),t(),l(this,Kn).promise}update({viewport:t,onBefore:e=null}){var n;const s=t.scale*(globalThis.devicePixelRatio||1),i=t.rotation;if(i!==l(this,Pa)&&(e==null||e(),m(this,Pa,i),kr(l(this,Ma),{rotation:i})),s!==l(this,Qn)){e==null||e(),m(this,Qn,s);const r={div:null,properties:null,ctx:w(n=Qt,rs,jd).call(n,l(this,io))};for(const o of l(this,ro))r.properties=l(this,Bl).get(o),r.div=o,w(this,nn,yp).call(this,r)}}cancel(){var e;const t=new Rn("TextLayer task cancelled.");(e=l(this,no))==null||e.cancel(t).catch(()=>{}),m(this,no,null),l(this,Kn).reject(t)}get textDivs(){return l(this,ro)}get textContentItemsStr(){return l(this,jl)}static cleanup(){if(!(l(this,Ra).size>0)){l(this,oo).clear();for(const{canvas:t}of l(this,ao).values())t.remove();l(this,ao).clear()}}};Kn=new WeakMap,qe=new WeakMap,Ll=new WeakMap,Fl=new WeakMap,io=new WeakMap,sn=new WeakMap,Il=new WeakMap,Nl=new WeakMap,no=new WeakMap,Ma=new WeakMap,Pa=new WeakMap,Qn=new WeakMap,Da=new WeakMap,jl=new WeakMap,Oa=new WeakMap,ro=new WeakMap,Bl=new WeakMap,Hl=new WeakMap,oo=new WeakMap,ao=new WeakMap,Gl=new WeakMap,Jn=new WeakMap,Ra=new WeakMap,nn=new WeakSet,Ty=function(t){var i,n;if(l(this,Ll))return;(n=l(this,sn)).ctx??(n.ctx=w(i=Qt,rs,jd).call(i,l(this,io)));const e=l(this,ro),s=l(this,jl);for(const r of t){if(e.length>vS){et("Ignoring additional textDivs for performance reasons."),m(this,Ll,!0);return}if(r.str===void 0){if(r.type==="beginMarkedContentProps"||r.type==="beginMarkedContent"){const o=l(this,qe);m(this,qe,document.createElement("span")),l(this,qe).classList.add("markedContent"),r.id!==null&&l(this,qe).setAttribute("id",`${r.id}`),o.append(l(this,qe))}else r.type==="endMarkedContent"&&m(this,qe,l(this,qe).parentNode);continue}s.push(r.str),w(this,nn,Ey).call(this,r)}},Ey=function(t){var b;const e=document.createElement("span"),s={angle:0,canvasWidth:0,hasText:t.str!=="",hasEOL:t.hasEOL,fontSize:0};l(this,ro).push(e);const i=U.transform(l(this,Hl),t.transform);let n=Math.atan2(i[1],i[0]);const r=l(this,Da)[t.fontName];r.vertical&&(n+=Math.PI/2);let o=l(this,Fl)&&r.fontSubstitution||r.fontFamily;o=Qt.fontFamilyMap.get(o)||o;const h=Math.hypot(i[2],i[3]),c=h*w(b=Qt,rs,My).call(b,o,l(this,io));let u,d;n===0?(u=i[4],d=i[5]-c):(u=i[4]+c*Math.sin(n),d=i[5]-c*Math.cos(n));const f="calc(var(--scale-factor)*",g=e.style;l(this,qe)===l(this,Ma)?(g.left=`${(100*u/l(this,Nl)).toFixed(2)}%`,g.top=`${(100*d/l(this,Il)).toFixed(2)}%`):(g.left=`${f}${u.toFixed(2)}px)`,g.top=`${f}${d.toFixed(2)}px)`),g.fontSize=`${f}${(l(Qt,Jn)*h).toFixed(2)}px)`,g.fontFamily=o,s.fontSize=h,e.setAttribute("role","presentation"),e.textContent=t.str,e.dir=t.dir,l(this,Fl)&&(e.dataset.fontName=r.fontSubstitutionLoadedName||t.fontName),n!==0&&(s.angle=n*(180/Math.PI));let p=!1;if(t.str.length>1)p=!0;else if(t.str!==" "&&t.transform[0]!==t.transform[3]){const _=Math.abs(t.transform[0]),v=Math.abs(t.transform[3]);_!==v&&Math.max(_,v)/Math.min(_,v)>1.5&&(p=!0)}if(p&&(s.canvasWidth=r.vertical?t.height:t.width),l(this,Bl).set(e,s),l(this,sn).div=e,l(this,sn).properties=s,w(this,nn,yp).call(this,l(this,sn)),s.hasText&&l(this,qe).append(e),s.hasEOL){const _=document.createElement("br");_.setAttribute("role","presentation"),l(this,qe).append(_)}},yp=function(t){var o;const{div:e,properties:s,ctx:i}=t,{style:n}=e;let r="";if(l(Qt,Jn)>1&&(r=`scale(${1/l(Qt,Jn)})`),s.canvasWidth!==0&&s.hasText){const{fontFamily:h}=n,{canvasWidth:c,fontSize:u}=s;w(o=Qt,rs,vp).call(o,i,u*l(this,Qn),h);const{width:d}=i.measureText(e.textContent);d>0&&(r=`scaleX(${c*l(this,Qn)/d}) ${r}`)}s.angle!==0&&(r=`rotate(${s.angle}deg) ${r}`),r.length>0&&(n.transform=r)},rs=new WeakSet,jd=function(t=null){let e=l(this,ao).get(t||(t=""));if(!e){const s=document.createElement("canvas");s.className="hiddenCanvasElement",s.lang=t,document.body.append(s),e=s.getContext("2d",{alpha:!1,willReadFrequently:!0}),l(this,ao).set(t,e),l(this,Gl).set(e,{size:0,family:""})}return e},vp=function(t,e,s){const i=l(this,Gl).get(t);e===i.size&&s===i.family||(t.font=`${e}px ${s}`,i.size=e,i.family=s)},ky=function(){if(l(this,Jn)!==null)return;const t=document.createElement("div");t.style.opacity=0,t.style.lineHeight=1,t.style.fontSize="1px",t.style.position="absolute",t.textContent="X",document.body.append(t),m(this,Jn,t.getBoundingClientRect().height),t.remove()},My=function(t,e){const s=l(this,oo).get(t);if(s)return s;const i=w(this,rs,jd).call(this,e);i.canvas.width=i.canvas.height=Ye,w(this,rs,vp).call(this,i,Ye,t);const n=i.measureText("");let r=n.fontBoundingBoxAscent,o=Math.abs(n.fontBoundingBoxDescent);if(r){const u=r/(r+o);return l(this,oo).set(t,u),i.canvas.width=i.canvas.height=0,u}i.strokeStyle="red",i.clearRect(0,0,Ye,Ye),i.strokeText("g",0,0);let h=i.getImageData(0,0,Ye,Ye).data;o=0;for(let u=h.length-1-3;u>=0;u-=4)if(h[u]>0){o=Math.ceil(u/4/Ye);break}i.clearRect(0,0,Ye,Ye),i.strokeText("A",0,Ye),h=i.getImageData(0,0,Ye,Ye).data,r=0;for(let u=0,d=h.length;u<d;u+=4)if(h[u]>0){r=Ye-Math.floor(u/4/Ye);break}i.canvas.width=i.canvas.height=0;const c=r?r/(r+o):_S;return l(this,oo).set(t,c),c},y(Qt,rs),y(Qt,oo,new Map),y(Qt,ao,new Map),y(Qt,Gl,new WeakMap),y(Qt,Jn,null),y(Qt,Ra,new Set);let $h=Qt;class qh{static textContent(t){const e=[],s={items:e,styles:Object.create(null)};function i(n){var h;if(!n)return;let r=null;const o=n.name;if(o==="#text")r=n.value;else if(qh.shouldBuildText(o))(h=n==null?void 0:n.attributes)!=null&&h.textContent?r=n.attributes.textContent:n.value&&(r=n.value);else return;if(r!==null&&e.push({str:r}),!!n.children)for(const c of n.children)i(c)}return i(t),s}static shouldBuildText(t){return!(t==="textarea"||t==="input"||t==="option"||t==="select")}}const wS=65536,xS=100,SS=5e3,CS=ye?jx:Fx,AS=ye?Bx:hb,TS=ye?Nx:Ix,ES=ye?Hx:ub;function kS(a={}){typeof a=="string"||a instanceof URL?a={url:a}:(a instanceof ArrayBuffer||ArrayBuffer.isView(a))&&(a={data:a});const t=new Mg,{docId:e}=t,s=a.url?MS(a.url):null,i=a.data?PS(a.data):null,n=a.httpHeaders||null,r=a.withCredentials===!0,o=a.password??null,h=a.range instanceof Db?a.range:null,c=Number.isInteger(a.rangeChunkSize)&&a.rangeChunkSize>0?a.rangeChunkSize:wS;let u=a.worker instanceof aa?a.worker:null;const d=a.verbosity,f=typeof a.docBaseUrl=="string"&&!$u(a.docBaseUrl)?a.docBaseUrl:null,g=typeof a.cMapUrl=="string"?a.cMapUrl:null,p=a.cMapPacked!==!1,b=a.CMapReaderFactory||AS,_=typeof a.standardFontDataUrl=="string"?a.standardFontDataUrl:null,v=a.StandardFontDataFactory||ES,x=a.stopAtErrors!==!0,C=Number.isInteger(a.maxImageSize)&&a.maxImageSize>-1?a.maxImageSize:-1,S=a.isEvalSupported!==!1,E=typeof a.isOffscreenCanvasSupported=="boolean"?a.isOffscreenCanvasSupported:!ye,k=typeof a.isImageDecoderSupported=="boolean"?a.isImageDecoderSupported:!ye&&(Re.platform.isFirefox||!globalThis.chrome),M=Number.isInteger(a.canvasMaxAreaInBytes)?a.canvasMaxAreaInBytes:-1,D=typeof a.disableFontFace=="boolean"?a.disableFontFace:ye,R=a.fontExtraProperties===!0,B=a.enableXfa===!0,O=a.ownerDocument||globalThis.document,F=a.disableRange===!0,L=a.disableStream===!0,N=a.disableAutoFetch===!0,Y=a.pdfBug===!0,I=a.CanvasFactory||CS,X=a.FilterFactory||TS,rt=a.enableHWA===!0,Gt=h?h.length:a.length??NaN,te=typeof a.useSystemFonts=="boolean"?a.useSystemFonts:!ye&&!D,fe=typeof a.useWorkerFetch=="boolean"?a.useWorkerFetch:b===hb&&v===ub&&g&&_&&Xh(g,document.baseURI)&&Xh(_,document.baseURI),Yt=null;fx(d);const St={canvasFactory:new I({ownerDocument:O,enableHWA:rt}),filterFactory:new X({docId:e,ownerDocument:O}),cMapReaderFactory:fe?null:new b({baseUrl:g,isCompressed:p}),standardFontDataFactory:fe?null:new v({baseUrl:_})};if(!u){const Ft={verbosity:d,port:Vi.workerPort};u=Ft.port?aa.fromPort(Ft):new aa(Ft),t._worker=u}const He={docId:e,apiVersion:"4.10.38",data:i,password:o,disableAutoFetch:N,rangeChunkSize:c,length:Gt,docBaseUrl:f,enableXfa:B,evaluatorOptions:{maxImageSize:C,disableFontFace:D,ignoreErrors:x,isEvalSupported:S,isOffscreenCanvasSupported:E,isImageDecoderSupported:k,canvasMaxAreaInBytes:M,fontExtraProperties:R,useSystemFonts:te,cMapUrl:fe?g:null,standardFontDataUrl:fe?_:null}},Mi={disableFontFace:D,fontExtraProperties:R,ownerDocument:O,pdfBug:Y,styleElement:Yt,loadingParams:{disableAutoFetch:N,enableXfa:B}};return u.promise.then(function(){if(t.destroyed)throw new Error("Loading aborted");if(u.destroyed)throw new Error("Worker was destroyed");const Ft=u.messageHandler.sendWithPromise("GetDocRequest",He,i?[i.buffer]:null);let ft;if(h)ft=new iS(h,{disableRange:F,disableStream:L});else if(!i){if(!s)throw new Error("getDocument - no `url` parameter provided.");let fr;if(ye)if(Xh(s)){if(typeof fetch>"u"||typeof Response>"u"||!("body"in Response.prototype))throw new Error("getDocument - the Fetch API was disabled in Node.js, see `--no-experimental-fetch`.");fr=Mb}else fr=mS;else fr=Xh(s)?Mb:uS;ft=new fr({url:s,length:Gt,httpHeaders:n,withCredentials:r,rangeChunkSize:c,disableRange:F,disableStream:L})}return Ft.then(fr=>{if(t.destroyed)throw new Error("Loading aborted");if(u.destroyed)throw new Error("Worker was destroyed");const ph=new Uh(e,fr,u.port),Pi=new LS(ph,t,ft,Mi,St);t._transport=Pi,ph.send("Ready",null)})}).catch(t._capability.reject),t}function MS(a){if(a instanceof URL)return a.href;try{return new URL(a,window.location).href}catch{if(ye&&typeof a=="string")return a}throw new Error("Invalid PDF url data: either string or URL-object is expected in the url property.")}function PS(a){if(ye&&typeof Buffer<"u"&&a instanceof Buffer)throw new Error("Please provide binary data as `Uint8Array`, rather than `Buffer`.");if(a instanceof Uint8Array&&a.byteLength===a.buffer.byteLength)return a;if(typeof a=="string")return Uu(a);if(a instanceof ArrayBuffer||ArrayBuffer.isView(a)||typeof a=="object"&&!isNaN(a==null?void 0:a.length))return new Uint8Array(a);throw new Error("Invalid PDF binary data: either TypedArray, string, or array-like object is expected in the data property.")}function Pb(a){return typeof a=="object"&&Number.isInteger(a==null?void 0:a.num)&&a.num>=0&&Number.isInteger(a==null?void 0:a.gen)&&a.gen>=0}const bd=class bd{constructor(){this._capability=Promise.withResolvers(),this._transport=null,this._worker=null,this.docId=`d${Ge(bd,md)._++}`,this.destroyed=!1,this.onPassword=null,this.onProgress=null}get promise(){return this._capability.promise}async destroy(){var t,e,s,i;this.destroyed=!0;try{(t=this._worker)!=null&&t.port&&(this._worker._pendingDestroy=!0),await((e=this._transport)==null?void 0:e.destroy())}catch(n){throw(s=this._worker)!=null&&s.port&&delete this._worker._pendingDestroy,n}this._transport=null,(i=this._worker)==null||i.destroy(),this._worker=null}};md=new WeakMap,y(bd,md,0);let Mg=bd;class Db{constructor(t,e,s=!1,i=null){this.length=t,this.initialData=e,this.progressiveDone=s,this.contentDispositionFilename=i,this._rangeListeners=[],this._progressListeners=[],this._progressiveReadListeners=[],this._progressiveDoneListeners=[],this._readyCapability=Promise.withResolvers()}addRangeListener(t){this._rangeListeners.push(t)}addProgressListener(t){this._progressListeners.push(t)}addProgressiveReadListener(t){this._progressiveReadListeners.push(t)}addProgressiveDoneListener(t){this._progressiveDoneListeners.push(t)}onDataRange(t,e){for(const s of this._rangeListeners)s(t,e)}onDataProgress(t,e){this._readyCapability.promise.then(()=>{for(const s of this._progressListeners)s(t,e)})}onDataProgressiveRead(t){this._readyCapability.promise.then(()=>{for(const e of this._progressiveReadListeners)e(t)})}onDataProgressiveDone(){this._readyCapability.promise.then(()=>{for(const t of this._progressiveDoneListeners)t()})}transportReady(){this._readyCapability.resolve()}requestDataRange(t,e){vt("Abstract method PDFDataRangeTransport.requestDataRange")}abort(){}}class DS{constructor(t,e){this._pdfInfo=t,this._transport=e}get annotationStorage(){return this._transport.annotationStorage}get canvasFactory(){return this._transport.canvasFactory}get filterFactory(){return this._transport.filterFactory}get numPages(){return this._pdfInfo.numPages}get fingerprints(){return this._pdfInfo.fingerprints}get isPureXfa(){return it(this,"isPureXfa",!!this._transport._htmlForXfa)}get allXfaHtml(){return this._transport._htmlForXfa}getPage(t){return this._transport.getPage(t)}getPageIndex(t){return this._transport.getPageIndex(t)}getDestinations(){return this._transport.getDestinations()}getDestination(t){return this._transport.getDestination(t)}getPageLabels(){return this._transport.getPageLabels()}getPageLayout(){return this._transport.getPageLayout()}getPageMode(){return this._transport.getPageMode()}getViewerPreferences(){return this._transport.getViewerPreferences()}getOpenAction(){return this._transport.getOpenAction()}getAttachments(){return this._transport.getAttachments()}getJSActions(){return this._transport.getDocJSActions()}getOutline(){return this._transport.getOutline()}getOptionalContentConfig({intent:t="display"}={}){const{renderingIntent:e}=this._transport.getRenderingIntent(t);return this._transport.getOptionalContentConfig(e)}getPermissions(){return this._transport.getPermissions()}getMetadata(){return this._transport.getMetadata()}getMarkInfo(){return this._transport.getMarkInfo()}getData(){return this._transport.getData()}saveDocument(){return this._transport.saveDocument()}getDownloadInfo(){return this._transport.downloadInfoCapability.promise}cleanup(t=!1){return this._transport.startCleanup(t||this.isPureXfa)}destroy(){return this.loadingTask.destroy()}cachedPageNumber(t){return this._transport.cachedPageNumber(t)}get loadingParams(){return this._transport.loadingParams}get loadingTask(){return this._transport.loadingTask}getFieldObjects(){return this._transport.getFieldObjects()}hasJSActions(){return this._transport.hasJSActions()}getCalculationOrderIds(){return this._transport.getCalculationOrderIds()}}class OS{constructor(t,e,s,i=!1){y(this,As);y(this,Zn,null);y(this,rn,!1);this._pageIndex=t,this._pageInfo=e,this._transport=s,this._stats=i?new eb:null,this._pdfBug=i,this.commonObjs=s.commonObjs,this.objs=new Ob,this._maybeCleanupAfterRender=!1,this._intentStates=new Map,this.destroyed=!1}get pageNumber(){return this._pageIndex+1}get rotate(){return this._pageInfo.rotate}get ref(){return this._pageInfo.ref}get userUnit(){return this._pageInfo.userUnit}get view(){return this._pageInfo.view}getViewport({scale:t,rotation:e=this.rotate,offsetX:s=0,offsetY:i=0,dontFlip:n=!1}={}){return new Vh({viewBox:this.view,userUnit:this.userUnit,scale:t,rotation:e,offsetX:s,offsetY:i,dontFlip:n})}getAnnotations({intent:t="display"}={}){const{renderingIntent:e}=this._transport.getRenderingIntent(t);return this._transport.getAnnotations(this._pageIndex,e)}getJSActions(){return this._transport.getPageJSActions(this._pageIndex)}get filterFactory(){return this._transport.filterFactory}get isPureXfa(){return it(this,"isPureXfa",!!this._transport._htmlForXfa)}async getXfa(){var t;return((t=this._transport._htmlForXfa)==null?void 0:t.children[this._pageIndex])||null}render({canvasContext:t,viewport:e,intent:s="display",annotationMode:i=Dn.ENABLE,transform:n=null,background:r=null,optionalContentConfigPromise:o=null,annotationCanvasMap:h=null,pageColors:c=null,printAnnotationStorage:u=null,isEditing:d=!1}){var S,E;(S=this._stats)==null||S.time("Overall");const f=this._transport.getRenderingIntent(s,i,u,d),{renderingIntent:g,cacheKey:p}=f;m(this,rn,!1),w(this,As,Bd).call(this),o||(o=this._transport.getOptionalContentConfig(g));let b=this._intentStates.get(p);b||(b=Object.create(null),this._intentStates.set(p,b)),b.streamReaderCancelTimeout&&(clearTimeout(b.streamReaderCancelTimeout),b.streamReaderCancelTimeout=null);const _=!!(g&ts.PRINT);b.displayReadyCapability||(b.displayReadyCapability=Promise.withResolvers(),b.operatorList={fnArray:[],argsArray:[],lastChunk:!1,separateAnnots:null},(E=this._stats)==null||E.time("Page Request"),this._pumpOperatorList(f));const v=k=>{var M;b.renderTasks.delete(x),(this._maybeCleanupAfterRender||_)&&m(this,rn,!0),w(this,As,vh).call(this,!_),k?(x.capability.reject(k),this._abortOperatorList({intentState:b,reason:k instanceof Error?k:new Error(k)})):x.capability.resolve(),this._stats&&(this._stats.timeEnd("Rendering"),this._stats.timeEnd("Overall"),(M=globalThis.Stats)!=null&&M.enabled&&globalThis.Stats.add(this.pageNumber,this._stats))},x=new Pg({callback:v,params:{canvasContext:t,viewport:e,transform:n,background:r},objs:this.objs,commonObjs:this.commonObjs,annotationCanvasMap:h,operatorList:b.operatorList,pageIndex:this._pageIndex,canvasFactory:this._transport.canvasFactory,filterFactory:this._transport.filterFactory,useRequestAnimationFrame:!_,pdfBug:this._pdfBug,pageColors:c});(b.renderTasks||(b.renderTasks=new Set)).add(x);const C=x.task;return Promise.all([b.displayReadyCapability.promise,o]).then(([k,M])=>{var D;if(this.destroyed){v();return}if((D=this._stats)==null||D.time("Rendering"),!(M.renderingIntent&g))throw new Error("Must use the same `intent`-argument when calling the `PDFPageProxy.render` and `PDFDocumentProxy.getOptionalContentConfig` methods.");x.initializeGraphics({transparency:k,optionalContentConfig:M}),x.operatorListChanged()}).catch(v),C}getOperatorList({intent:t="display",annotationMode:e=Dn.ENABLE,printAnnotationStorage:s=null,isEditing:i=!1}={}){var c;function n(){o.operatorList.lastChunk&&(o.opListReadCapability.resolve(o.operatorList),o.renderTasks.delete(h))}const r=this._transport.getRenderingIntent(t,e,s,i,!0);let o=this._intentStates.get(r.cacheKey);o||(o=Object.create(null),this._intentStates.set(r.cacheKey,o));let h;return o.opListReadCapability||(h=Object.create(null),h.operatorListChanged=n,o.opListReadCapability=Promise.withResolvers(),(o.renderTasks||(o.renderTasks=new Set)).add(h),o.operatorList={fnArray:[],argsArray:[],lastChunk:!1,separateAnnots:null},(c=this._stats)==null||c.time("Page Request"),this._pumpOperatorList(r)),o.opListReadCapability.promise}streamTextContent({includeMarkedContent:t=!1,disableNormalization:e=!1}={}){return this._transport.messageHandler.sendWithStream("GetTextContent",{pageIndex:this._pageIndex,includeMarkedContent:t===!0,disableNormalization:e===!0},{highWaterMark:100,size(i){return i.items.length}})}getTextContent(t={}){if(this._transport._htmlForXfa)return this.getXfa().then(s=>qh.textContent(s));const e=this.streamTextContent(t);return new Promise(function(s,i){function n(){r.read().then(function({value:h,done:c}){if(c){s(o);return}o.lang??(o.lang=h.lang),Object.assign(o.styles,h.styles),o.items.push(...h.items),n()},i)}const r=e.getReader(),o={items:[],styles:Object.create(null),lang:null};n()})}getStructTree(){return this._transport.getStructTree(this._pageIndex)}_destroy(){this.destroyed=!0;const t=[];for(const e of this._intentStates.values())if(this._abortOperatorList({intentState:e,reason:new Error("Page was destroyed."),force:!0}),!e.opListReadCapability)for(const s of e.renderTasks)t.push(s.completed),s.cancel();return this.objs.clear(),m(this,rn,!1),w(this,As,Bd).call(this),Promise.all(t)}cleanup(t=!1){m(this,rn,!0);const e=w(this,As,vh).call(this,!1);return t&&e&&this._stats&&(this._stats=new eb),e}_startRenderPage(t,e){var i,n;const s=this._intentStates.get(e);s&&((i=this._stats)==null||i.timeEnd("Page Request"),(n=s.displayReadyCapability)==null||n.resolve(t))}_renderPageChunk(t,e){for(let s=0,i=t.length;s<i;s++)e.operatorList.fnArray.push(t.fnArray[s]),e.operatorList.argsArray.push(t.argsArray[s]);e.operatorList.lastChunk=t.lastChunk,e.operatorList.separateAnnots=t.separateAnnots;for(const s of e.renderTasks)s.operatorListChanged();t.lastChunk&&w(this,As,vh).call(this,!0)}_pumpOperatorList({renderingIntent:t,cacheKey:e,annotationStorageSerializable:s,modifiedIds:i}){const{map:n,transfer:r}=s,h=this._transport.messageHandler.sendWithStream("GetOperatorList",{pageIndex:this._pageIndex,intent:t,cacheKey:e,annotationStorage:n,modifiedIds:i},r).getReader(),c=this._intentStates.get(e);c.streamReader=h;const u=()=>{h.read().then(({value:d,done:f})=>{if(f){c.streamReader=null;return}this._transport.destroyed||(this._renderPageChunk(d,c),u())},d=>{if(c.streamReader=null,!this._transport.destroyed){if(c.operatorList){c.operatorList.lastChunk=!0;for(const f of c.renderTasks)f.operatorListChanged();w(this,As,vh).call(this,!0)}if(c.displayReadyCapability)c.displayReadyCapability.reject(d);else if(c.opListReadCapability)c.opListReadCapability.reject(d);else throw d}})};u()}_abortOperatorList({intentState:t,reason:e,force:s=!1}){if(t.streamReader){if(t.streamReaderCancelTimeout&&(clearTimeout(t.streamReaderCancelTimeout),t.streamReaderCancelTimeout=null),!s){if(t.renderTasks.size>0)return;if(e instanceof fg){let i=xS;e.extraDelay>0&&e.extraDelay<1e3&&(i+=e.extraDelay),t.streamReaderCancelTimeout=setTimeout(()=>{t.streamReaderCancelTimeout=null,this._abortOperatorList({intentState:t,reason:e,force:!0})},i);return}}if(t.streamReader.cancel(new Rn(e.message)).catch(()=>{}),t.streamReader=null,!this._transport.destroyed){for(const[i,n]of this._intentStates)if(n===t){this._intentStates.delete(i);break}this.cleanup()}}}get stats(){return this._stats}}Zn=new WeakMap,rn=new WeakMap,As=new WeakSet,vh=function(t=!1){if(w(this,As,Bd).call(this),!l(this,rn)||this.destroyed)return!1;if(t)return m(this,Zn,setTimeout(()=>{m(this,Zn,null),w(this,As,vh).call(this,!1)},SS)),!1;for(const{renderTasks:e,operatorList:s}of this._intentStates.values())if(e.size>0||!s.lastChunk)return!1;return this._intentStates.clear(),this.objs.clear(),m(this,rn,!1),!0},Bd=function(){l(this,Zn)&&(clearTimeout(l(this,Zn)),m(this,Zn,null))};class RS{constructor(){y(this,on,new Map);y(this,yd,Promise.resolve())}postMessage(t,e){const s={data:structuredClone(t,e?{transfer:e}:null)};l(this,yd).then(()=>{for(const[i]of l(this,on))i.call(this,s)})}addEventListener(t,e,s=null){let i=null;if((s==null?void 0:s.signal)instanceof AbortSignal){const{signal:n}=s;if(n.aborted){et("LoopbackPort - cannot use an `aborted` signal.");return}const r=()=>this.removeEventListener(t,e);i=()=>n.removeEventListener("abort",r),n.addEventListener("abort",r)}l(this,on).set(e,i)}removeEventListener(t,e){const s=l(this,on).get(e);s==null||s(),l(this,on).delete(e)}terminate(){for(const[,t]of l(this,on))t==null||t();l(this,on).clear()}}on=new WeakMap,yd=new WeakMap;const Et=class Et{constructor({name:t=null,port:e=null,verbosity:s=gx()}={}){y(this,La);var i;if(this.name=t,this.destroyed=!1,this.verbosity=s,this._readyCapability=Promise.withResolvers(),this._port=null,this._webWorker=null,this._messageHandler=null,e){if((i=l(Et,lo))!=null&&i.has(e))throw new Error("Cannot use more than one PDFWorker per port.");(l(Et,lo)||m(Et,lo,new WeakMap)).set(e,this),this._initializeFromPort(e);return}this._initialize()}get promise(){return this._readyCapability.promise}get port(){return this._port}get messageHandler(){return this._messageHandler}_initializeFromPort(t){this._port=t,this._messageHandler=new Uh("main","worker",t),this._messageHandler.on("ready",function(){}),w(this,La,Hd).call(this)}_initialize(){if(l(Et,ho)||l(Et,Fa,Gd)){this._setupFakeWorker();return}let{workerSrc:t}=Et;try{Et._isSameOrigin(window.location.href,t)||(t=Et._createCDNWrapper(new URL(t,window.location).href));const e=new Worker(t,{type:"module"}),s=new Uh("main","worker",e),i=()=>{n.abort(),s.destroy(),e.terminate(),this.destroyed?this._readyCapability.reject(new Error("Worker was destroyed")):this._setupFakeWorker()},n=new AbortController;e.addEventListener("error",()=>{this._webWorker||i()},{signal:n.signal}),s.on("test",o=>{if(n.abort(),this.destroyed||!o){i();return}this._messageHandler=s,this._port=e,this._webWorker=e,w(this,La,Hd).call(this)}),s.on("ready",o=>{if(n.abort(),this.destroyed){i();return}try{r()}catch{this._setupFakeWorker()}});const r=()=>{const o=new Uint8Array;s.send("test",o,[o.buffer])};r();return}catch{Xu("The worker has been disabled.")}this._setupFakeWorker()}_setupFakeWorker(){l(Et,ho)||(et("Setting up fake worker."),m(Et,ho,!0)),Et._setupFakeWorkerGlobal.then(t=>{if(this.destroyed){this._readyCapability.reject(new Error("Worker was destroyed"));return}const e=new RS;this._port=e;const s=`fake${Ge(Et,vd)._++}`,i=new Uh(s+"_worker",s,e);t.setup(i,e),this._messageHandler=new Uh(s,s+"_worker",e),w(this,La,Hd).call(this)}).catch(t=>{this._readyCapability.reject(new Error(`Setting up fake worker failed: "${t.message}".`))})}destroy(){var t,e,s;this.destroyed=!0,(t=this._webWorker)==null||t.terminate(),this._webWorker=null,(e=l(Et,lo))==null||e.delete(this._port),this._port=null,(s=this._messageHandler)==null||s.destroy(),this._messageHandler=null}static fromPort(t){var s;if(!(t!=null&&t.port))throw new Error("PDFWorker.fromPort - invalid method signature.");const e=(s=l(this,lo))==null?void 0:s.get(t.port);if(e){if(e._pendingDestroy)throw new Error("PDFWorker.fromPort - the worker is being destroyed.\nPlease remember to await `PDFDocumentLoadingTask.destroy()`-calls.");return e}return new Et(t)}static get workerSrc(){if(Vi.workerSrc)return Vi.workerSrc;throw new Error('No "GlobalWorkerOptions.workerSrc" specified.')}static get _setupFakeWorkerGlobal(){return it(this,"_setupFakeWorkerGlobal",(async()=>l(this,Fa,Gd)?l(this,Fa,Gd):(await import(this.workerSrc)).WorkerMessageHandler)())}};vd=new WeakMap,ho=new WeakMap,lo=new WeakMap,La=new WeakSet,Hd=function(){this._readyCapability.resolve(),this._messageHandler.send("configure",{verbosity:this.verbosity})},Fa=new WeakSet,Gd=function(){var t;try{return((t=globalThis.pdfjsWorker)==null?void 0:t.WorkerMessageHandler)||null}catch{return null}},y(Et,Fa),y(Et,vd,0),y(Et,ho,!1),y(Et,lo),ye&&(m(Et,ho,!0),Vi.workerSrc||(Vi.workerSrc="./pdf.worker.mjs")),Et._isSameOrigin=(t,e)=>{let s;try{if(s=new URL(t),!s.origin||s.origin==="null")return!1}catch{return!1}const i=new URL(e,s);return s.origin===i.origin},Et._createCDNWrapper=t=>{const e=`await import("${t}");`;return URL.createObjectURL(new Blob([e],{type:"text/javascript"}))};let aa=Et;class LS{constructor(t,e,s,i,n){y(this,co);y(this,an,new Map);y(this,_i,new Map);y(this,Ia,new Map);y(this,Na,new Map);y(this,hn,null);this.messageHandler=t,this.loadingTask=e,this.commonObjs=new Ob,this.fontLoader=new Rx({ownerDocument:i.ownerDocument,styleElement:i.styleElement}),this.loadingParams=i.loadingParams,this._params=i,this.canvasFactory=n.canvasFactory,this.filterFactory=n.filterFactory,this.cMapReaderFactory=n.cMapReaderFactory,this.standardFontDataFactory=n.standardFontDataFactory,this.destroyed=!1,this.destroyCapability=null,this._networkStream=s,this._fullReader=null,this._lastProgress=null,this.downloadInfoCapability=Promise.withResolvers(),this.setupMessageHandler()}get annotationStorage(){return it(this,"annotationStorage",new xg)}getRenderingIntent(t,e=Dn.ENABLE,s=null,i=!1,n=!1){let r=ts.DISPLAY,o=wg;switch(t){case"any":r=ts.ANY;break;case"display":break;case"print":r=ts.PRINT;break;default:et(`getRenderingIntent - invalid intent: ${t}`)}const h=r&ts.PRINT&&s instanceof nb?s:this.annotationStorage;switch(e){case Dn.DISABLE:r+=ts.ANNOTATIONS_DISABLE;break;case Dn.ENABLE:break;case Dn.ENABLE_FORMS:r+=ts.ANNOTATIONS_FORMS;break;case Dn.ENABLE_STORAGE:r+=ts.ANNOTATIONS_STORAGE,o=h.serializable;break;default:et(`getRenderingIntent - invalid annotationMode: ${e}`)}i&&(r+=ts.IS_EDITING),n&&(r+=ts.OPLIST);const{ids:c,hash:u}=h.modifiedIds,d=[r,o.hash,u];return{renderingIntent:r,cacheKey:d.join("_"),annotationStorageSerializable:o,modifiedIds:c}}destroy(){var s;if(this.destroyCapability)return this.destroyCapability.promise;this.destroyed=!0,this.destroyCapability=Promise.withResolvers(),(s=l(this,hn))==null||s.reject(new Error("Worker was destroyed during onPassword callback"));const t=[];for(const i of l(this,_i).values())t.push(i._destroy());l(this,_i).clear(),l(this,Ia).clear(),l(this,Na).clear(),this.hasOwnProperty("annotationStorage")&&this.annotationStorage.resetModified();const e=this.messageHandler.sendWithPromise("Terminate",null);return t.push(e),Promise.all(t).then(()=>{var i,n;this.commonObjs.clear(),this.fontLoader.clear(),l(this,an).clear(),this.filterFactory.destroy(),$h.cleanup(),(i=this._networkStream)==null||i.cancelAllRequests(new Rn("Worker was terminated.")),(n=this.messageHandler)==null||n.destroy(),this.messageHandler=null,this.destroyCapability.resolve()},this.destroyCapability.reject),this.destroyCapability.promise}setupMessageHandler(){const{messageHandler:t,loadingTask:e}=this;t.on("GetReader",(s,i)=>{Xt(this._networkStream,"GetReader - no `IPDFStream` instance available."),this._fullReader=this._networkStream.getFullReader(),this._fullReader.onProgress=n=>{this._lastProgress={loaded:n.loaded,total:n.total}},i.onPull=()=>{this._fullReader.read().then(function({value:n,done:r}){if(r){i.close();return}Xt(n instanceof ArrayBuffer,"GetReader - expected an ArrayBuffer."),i.enqueue(new Uint8Array(n),1,[n])}).catch(n=>{i.error(n)})},i.onCancel=n=>{this._fullReader.cancel(n),i.ready.catch(r=>{if(!this.destroyed)throw r})}}),t.on("ReaderHeadersReady",async s=>{var o;await this._fullReader.headersReady;const{isStreamingSupported:i,isRangeSupported:n,contentLength:r}=this._fullReader;return(!i||!n)&&(this._lastProgress&&((o=e.onProgress)==null||o.call(e,this._lastProgress)),this._fullReader.onProgress=h=>{var c;(c=e.onProgress)==null||c.call(e,{loaded:h.loaded,total:h.total})}),{isStreamingSupported:i,isRangeSupported:n,contentLength:r}}),t.on("GetRangeReader",(s,i)=>{Xt(this._networkStream,"GetRangeReader - no `IPDFStream` instance available.");const n=this._networkStream.getRangeReader(s.begin,s.end);if(!n){i.close();return}i.onPull=()=>{n.read().then(function({value:r,done:o}){if(o){i.close();return}Xt(r instanceof ArrayBuffer,"GetRangeReader - expected an ArrayBuffer."),i.enqueue(new Uint8Array(r),1,[r])}).catch(r=>{i.error(r)})},i.onCancel=r=>{n.cancel(r),i.ready.catch(o=>{if(!this.destroyed)throw o})}}),t.on("GetDoc",({pdfInfo:s})=>{this._numPages=s.numPages,this._htmlForXfa=s.htmlForXfa,delete s.htmlForXfa,e._capability.resolve(new DS(s,this))}),t.on("DocException",s=>{e._capability.reject(We(s))}),t.on("PasswordRequest",s=>{m(this,hn,Promise.withResolvers());try{if(!e.onPassword)throw We(s);const i=n=>{n instanceof Error?l(this,hn).reject(n):l(this,hn).resolve({password:n})};e.onPassword(i,s.code)}catch(i){l(this,hn).reject(i)}return l(this,hn).promise}),t.on("DataLoaded",s=>{var i;(i=e.onProgress)==null||i.call(e,{loaded:s.length,total:s.length}),this.downloadInfoCapability.resolve(s)}),t.on("StartRenderPage",s=>{if(this.destroyed)return;l(this,_i).get(s.pageIndex)._startRenderPage(s.transparency,s.cacheKey)}),t.on("commonobj",([s,i,n])=>{var r;if(this.destroyed||this.commonObjs.has(s))return null;switch(i){case"Font":const{disableFontFace:o,fontExtraProperties:h,pdfBug:c}=this._params;if("error"in n){const g=n.error;et(`Error during font loading: ${g}`),this.commonObjs.resolve(s,g);break}const u=c&&((r=globalThis.FontInspector)!=null&&r.enabled)?(g,p)=>globalThis.FontInspector.fontAdded(g,p):null,d=new Lx(n,{disableFontFace:o,fontExtraProperties:h,inspectFont:u});this.fontLoader.bind(d).catch(()=>t.sendWithPromise("FontFallback",{id:s})).finally(()=>{!h&&d.data&&(d.data=null),this.commonObjs.resolve(s,d)});break;case"CopyLocalImage":const{imageRef:f}=n;Xt(f,"The imageRef must be defined.");for(const g of l(this,_i).values())for(const[,p]of g.objs)if((p==null?void 0:p.ref)===f)return p.dataLen?(this.commonObjs.resolve(s,structuredClone(p)),p.dataLen):null;break;case"FontPath":case"Image":case"Pattern":this.commonObjs.resolve(s,n);break;default:throw new Error(`Got unknown common object type ${i}`)}return null}),t.on("obj",([s,i,n,r])=>{var h;if(this.destroyed)return;const o=l(this,_i).get(i);if(!o.objs.has(s)){if(o._intentStates.size===0){(h=r==null?void 0:r.bitmap)==null||h.close();return}switch(n){case"Image":o.objs.resolve(s,r),(r==null?void 0:r.dataLen)>lx&&(o._maybeCleanupAfterRender=!0);break;case"Pattern":o.objs.resolve(s,r);break;default:throw new Error(`Got unknown object type ${n}`)}}}),t.on("DocProgress",s=>{var i;this.destroyed||(i=e.onProgress)==null||i.call(e,{loaded:s.loaded,total:s.total})}),t.on("FetchBuiltInCMap",async s=>{if(this.destroyed)throw new Error("Worker was destroyed.");if(!this.cMapReaderFactory)throw new Error("CMapReaderFactory not initialized, see the `useWorkerFetch` parameter.");return this.cMapReaderFactory.fetch(s)}),t.on("FetchStandardFontData",async s=>{if(this.destroyed)throw new Error("Worker was destroyed.");if(!this.standardFontDataFactory)throw new Error("StandardFontDataFactory not initialized, see the `useWorkerFetch` parameter.");return this.standardFontDataFactory.fetch(s)})}getData(){return this.messageHandler.sendWithPromise("GetData",null)}saveDocument(){var s;this.annotationStorage.size<=0&&et("saveDocument called while `annotationStorage` is empty, please use the getData-method instead.");const{map:t,transfer:e}=this.annotationStorage.serializable;return this.messageHandler.sendWithPromise("SaveDocument",{isPureXfa:!!this._htmlForXfa,numPages:this._numPages,annotationStorage:t,filename:((s=this._fullReader)==null?void 0:s.filename)??null},e).finally(()=>{this.annotationStorage.resetModified()})}getPage(t){if(!Number.isInteger(t)||t<=0||t>this._numPages)return Promise.reject(new Error("Invalid page request."));const e=t-1,s=l(this,Ia).get(e);if(s)return s;const i=this.messageHandler.sendWithPromise("GetPage",{pageIndex:e}).then(n=>{if(this.destroyed)throw new Error("Transport destroyed");n.refStr&&l(this,Na).set(n.refStr,t);const r=new OS(e,n,this,this._params.pdfBug);return l(this,_i).set(e,r),r});return l(this,Ia).set(e,i),i}getPageIndex(t){return Pb(t)?this.messageHandler.sendWithPromise("GetPageIndex",{num:t.num,gen:t.gen}):Promise.reject(new Error("Invalid pageIndex request."))}getAnnotations(t,e){return this.messageHandler.sendWithPromise("GetAnnotations",{pageIndex:t,intent:e})}getFieldObjects(){return w(this,co,Oc).call(this,"GetFieldObjects")}hasJSActions(){return w(this,co,Oc).call(this,"HasJSActions")}getCalculationOrderIds(){return this.messageHandler.sendWithPromise("GetCalculationOrderIds",null)}getDestinations(){return this.messageHandler.sendWithPromise("GetDestinations",null)}getDestination(t){return typeof t!="string"?Promise.reject(new Error("Invalid destination request.")):this.messageHandler.sendWithPromise("GetDestination",{id:t})}getPageLabels(){return this.messageHandler.sendWithPromise("GetPageLabels",null)}getPageLayout(){return this.messageHandler.sendWithPromise("GetPageLayout",null)}getPageMode(){return this.messageHandler.sendWithPromise("GetPageMode",null)}getViewerPreferences(){return this.messageHandler.sendWithPromise("GetViewerPreferences",null)}getOpenAction(){return this.messageHandler.sendWithPromise("GetOpenAction",null)}getAttachments(){return this.messageHandler.sendWithPromise("GetAttachments",null)}getDocJSActions(){return w(this,co,Oc).call(this,"GetDocJSActions")}getPageJSActions(t){return this.messageHandler.sendWithPromise("GetPageJSActions",{pageIndex:t})}getStructTree(t){return this.messageHandler.sendWithPromise("GetStructTree",{pageIndex:t})}getOutline(){return this.messageHandler.sendWithPromise("GetOutline",null)}getOptionalContentConfig(t){return w(this,co,Oc).call(this,"GetOptionalContentConfig").then(e=>new sS(e,t))}getPermissions(){return this.messageHandler.sendWithPromise("GetPermissions",null)}getMetadata(){const t="GetMetadata",e=l(this,an).get(t);if(e)return e;const s=this.messageHandler.sendWithPromise(t,null).then(i=>{var n,r;return{info:i[0],metadata:i[1]?new tS(i[1]):null,contentDispositionFilename:((n=this._fullReader)==null?void 0:n.filename)??null,contentLength:((r=this._fullReader)==null?void 0:r.contentLength)??null}});return l(this,an).set(t,s),s}getMarkInfo(){return this.messageHandler.sendWithPromise("GetMarkInfo",null)}async startCleanup(t=!1){if(!this.destroyed){await this.messageHandler.sendWithPromise("Cleanup",null);for(const e of l(this,_i).values())if(!e.cleanup())throw new Error(`startCleanup: Page ${e.pageNumber} is currently rendering.`);this.commonObjs.clear(),t||this.fontLoader.clear(),l(this,an).clear(),this.filterFactory.destroy(!0),$h.cleanup()}}cachedPageNumber(t){if(!Pb(t))return null;const e=t.gen===0?`${t.num}R`:`${t.num}R${t.gen}`;return l(this,Na).get(e)??null}}an=new WeakMap,_i=new WeakMap,Ia=new WeakMap,Na=new WeakMap,hn=new WeakMap,co=new WeakSet,Oc=function(t,e=null){const s=l(this,an).get(t);if(s)return s;const i=this.messageHandler.sendWithPromise(t,e);return l(this,an).set(t,i),i};const Kh=Symbol("INITIAL_DATA");class Ob{constructor(){y(this,zl);y(this,os,Object.create(null))}get(t,e=null){if(e){const i=w(this,zl,_p).call(this,t);return i.promise.then(()=>e(i.data)),null}const s=l(this,os)[t];if(!s||s.data===Kh)throw new Error(`Requesting object that isn't resolved yet ${t}.`);return s.data}has(t){const e=l(this,os)[t];return!!e&&e.data!==Kh}delete(t){const e=l(this,os)[t];return!e||e.data===Kh?!1:(delete l(this,os)[t],!0)}resolve(t,e=null){const s=w(this,zl,_p).call(this,t);s.data=e,s.resolve()}clear(){var t;for(const e in l(this,os)){const{data:s}=l(this,os)[e];(t=s==null?void 0:s.bitmap)==null||t.close()}m(this,os,Object.create(null))}*[Symbol.iterator](){for(const t in l(this,os)){const{data:e}=l(this,os)[t];e!==Kh&&(yield[t,e])}}}os=new WeakMap,zl=new WeakSet,_p=function(t){var e;return(e=l(this,os))[t]||(e[t]={...Promise.withResolvers(),data:Kh})};class FS{constructor(t){y(this,tr,null);m(this,tr,t),this.onContinue=null}get promise(){return l(this,tr).capability.promise}cancel(t=0){l(this,tr).cancel(null,t)}get separateAnnots(){const{separateAnnots:t}=l(this,tr).operatorList;if(!t)return!1;const{annotationCanvasMap:e}=l(this,tr);return t.form||t.canvas&&(e==null?void 0:e.size)>0}}tr=new WeakMap;const fo=class fo{constructor({callback:t,params:e,objs:s,commonObjs:i,annotationCanvasMap:n,operatorList:r,pageIndex:o,canvasFactory:h,filterFactory:c,useRequestAnimationFrame:u=!1,pdfBug:d=!1,pageColors:f=null}){y(this,er,null);this.callback=t,this.params=e,this.objs=s,this.commonObjs=i,this.annotationCanvasMap=n,this.operatorListIdx=null,this.operatorList=r,this._pageIndex=o,this.canvasFactory=h,this.filterFactory=c,this._pdfBug=d,this.pageColors=f,this.running=!1,this.graphicsReadyCallback=null,this.graphicsReady=!1,this._useRequestAnimationFrame=u===!0&&typeof window<"u",this.cancelled=!1,this.capability=Promise.withResolvers(),this.task=new FS(this),this._cancelBound=this.cancel.bind(this),this._continueBound=this._continue.bind(this),this._scheduleNextBound=this._scheduleNext.bind(this),this._nextBound=this._next.bind(this),this._canvas=e.canvasContext.canvas}get completed(){return this.capability.promise.catch(function(){})}initializeGraphics({transparency:t=!1,optionalContentConfig:e}){var o,h;if(this.cancelled)return;if(this._canvas){if(l(fo,uo).has(this._canvas))throw new Error("Cannot use the same canvas during multiple render() operations. Use different canvas or ensure previous operations were cancelled or completed.");l(fo,uo).add(this._canvas)}this._pdfBug&&((o=globalThis.StepperManager)!=null&&o.enabled)&&(this.stepper=globalThis.StepperManager.create(this._pageIndex),this.stepper.init(this.operatorList),this.stepper.nextBreakPoint=this.stepper.getNextBreakPoint());const{canvasContext:s,viewport:i,transform:n,background:r}=this.params;this.gfx=new ra(s,this.commonObjs,this.objs,this.canvasFactory,this.filterFactory,{optionalContentConfig:e},this.annotationCanvasMap,this.pageColors),this.gfx.beginDrawing({transform:n,viewport:i,transparency:t,background:r}),this.operatorListIdx=0,this.graphicsReady=!0,(h=this.graphicsReadyCallback)==null||h.call(this)}cancel(t=null,e=0){var s;this.running=!1,this.cancelled=!0,(s=this.gfx)==null||s.endDrawing(),l(this,er)&&(window.cancelAnimationFrame(l(this,er)),m(this,er,null)),l(fo,uo).delete(this._canvas),this.callback(t||new fg(`Rendering cancelled, page ${this._pageIndex+1}`,e))}operatorListChanged(){var t;if(!this.graphicsReady){this.graphicsReadyCallback||(this.graphicsReadyCallback=this._continueBound);return}(t=this.stepper)==null||t.updateOperatorList(this.operatorList),!this.running&&this._continue()}_continue(){this.running=!0,!this.cancelled&&(this.task.onContinue?this.task.onContinue(this._scheduleNextBound):this._scheduleNext())}_scheduleNext(){this._useRequestAnimationFrame?m(this,er,window.requestAnimationFrame(()=>{m(this,er,null),this._nextBound().catch(this._cancelBound)})):Promise.resolve().then(this._nextBound).catch(this._cancelBound)}async _next(){this.cancelled||(this.operatorListIdx=this.gfx.executeOperatorList(this.operatorList,this.operatorListIdx,this._continueBound,this.stepper),this.operatorListIdx===this.operatorList.argsArray.length&&(this.running=!1,this.operatorList.lastChunk&&(this.gfx.endDrawing(),l(fo,uo).delete(this._canvas),this.callback())))}};er=new WeakMap,uo=new WeakMap,y(fo,uo,new WeakSet);let Pg=fo;const IS="4.10.38",NS="f9bea397f";function Rb(a){return Math.floor(Math.max(0,Math.min(1,a))*255).toString(16).padStart(2,"0")}function Qh(a){return Math.max(0,Math.min(255,255*a))}class Lb{static CMYK_G([t,e,s,i]){return["G",1-Math.min(1,.3*t+.59*s+.11*e+i)]}static G_CMYK([t]){return["CMYK",0,0,0,1-t]}static G_RGB([t]){return["RGB",t,t,t]}static G_rgb([t]){return t=Qh(t),[t,t,t]}static G_HTML([t]){const e=Rb(t);return`#${e}${e}${e}`}static RGB_G([t,e,s]){return["G",.3*t+.59*e+.11*s]}static RGB_rgb(t){return t.map(Qh)}static RGB_HTML(t){return`#${t.map(Rb).join("")}`}static T_HTML(){return"#00000000"}static T_rgb(){return[null]}static CMYK_RGB([t,e,s,i]){return["RGB",1-Math.min(1,t+i),1-Math.min(1,s+i),1-Math.min(1,e+i)]}static CMYK_rgb([t,e,s,i]){return[Qh(1-Math.min(1,t+i)),Qh(1-Math.min(1,s+i)),Qh(1-Math.min(1,e+i))]}static CMYK_HTML(t){const e=this.CMYK_RGB(t).slice(1);return this.RGB_HTML(e)}static RGB_CMYK([t,e,s]){const i=1-t,n=1-e,r=1-s,o=Math.min(i,n,r);return["CMYK",i,n,r,o]}}class jS{create(t,e,s=!1){if(t<=0||e<=0)throw new Error("Invalid SVG dimensions");const i=this._createSVG("svg:svg");return i.setAttribute("version","1.1"),s||(i.setAttribute("width",`${t}px`),i.setAttribute("height",`${e}px`)),i.setAttribute("preserveAspectRatio","none"),i.setAttribute("viewBox",`0 0 ${t} ${e}`),i}createElement(t){if(typeof t!="string")throw new Error("Invalid SVG element type");return this._createSVG(t)}_createSVG(t){vt("Abstract method `_createSVG` called.")}}class Dg extends jS{_createSVG(t){return document.createElementNS(zi,t)}}class Fb{static setupStorage(t,e,s,i,n){const r=i.getValue(e,{value:null});switch(s.name){case"textarea":if(r.value!==null&&(t.textContent=r.value),n==="print")break;t.addEventListener("input",o=>{i.setValue(e,{value:o.target.value})});break;case"input":if(s.attributes.type==="radio"||s.attributes.type==="checkbox"){if(r.value===s.attributes.xfaOn?t.setAttribute("checked",!0):r.value===s.attributes.xfaOff&&t.removeAttribute("checked"),n==="print")break;t.addEventListener("change",o=>{i.setValue(e,{value:o.target.checked?o.target.getAttribute("xfaOn"):o.target.getAttribute("xfaOff")})})}else{if(r.value!==null&&t.setAttribute("value",r.value),n==="print")break;t.addEventListener("input",o=>{i.setValue(e,{value:o.target.value})})}break;case"select":if(r.value!==null){t.setAttribute("value",r.value);for(const o of s.children)o.attributes.value===r.value?o.attributes.selected=!0:o.attributes.hasOwnProperty("selected")&&delete o.attributes.selected}t.addEventListener("input",o=>{const h=o.target.options,c=h.selectedIndex===-1?"":h[h.selectedIndex].value;i.setValue(e,{value:c})});break}}static setAttributes({html:t,element:e,storage:s=null,intent:i,linkService:n}){const{attributes:r}=e,o=t instanceof HTMLAnchorElement;r.type==="radio"&&(r.name=`${r.name}-${i}`);for(const[h,c]of Object.entries(r))if(c!=null)switch(h){case"class":c.length&&t.setAttribute(h,c.join(" "));break;case"dataId":break;case"id":t.setAttribute("data-element-id",c);break;case"style":Object.assign(t.style,c);break;case"textContent":t.textContent=c;break;default:(!o||h!=="href"&&h!=="newWindow")&&t.setAttribute(h,c)}o&&n.addLinkAttributes(t,r.href,r.newWindow),s&&r.dataId&&this.setupStorage(t,r.dataId,e,s)}static render(t){var d,f;const e=t.annotationStorage,s=t.linkService,i=t.xfaHtml,n=t.intent||"display",r=document.createElement(i.name);i.attributes&&this.setAttributes({html:r,element:i,intent:n,linkService:s});const o=n!=="richText",h=t.div;if(h.append(r),t.viewport){const g=`matrix(${t.viewport.transform.join(",")})`;h.style.transform=g}o&&h.setAttribute("class","xfaLayer xfaFont");const c=[];if(i.children.length===0){if(i.value){const g=document.createTextNode(i.value);r.append(g),o&&qh.shouldBuildText(i.name)&&c.push(g)}return{textDivs:c}}const u=[[i,-1,r]];for(;u.length>0;){const[g,p,b]=u.at(-1);if(p+1===g.children.length){u.pop();continue}const _=g.children[++u.at(-1)[1]];if(_===null)continue;const{name:v}=_;if(v==="#text"){const C=document.createTextNode(_.value);c.push(C),b.append(C);continue}const x=(d=_==null?void 0:_.attributes)!=null&&d.xmlns?document.createElementNS(_.attributes.xmlns,v):document.createElement(v);if(b.append(x),_.attributes&&this.setAttributes({html:x,element:_,storage:e,intent:n,linkService:s}),((f=_.children)==null?void 0:f.length)>0)u.push([_,-1,x]);else if(_.value){const C=document.createTextNode(_.value);o&&qh.shouldBuildText(v)&&c.push(C),x.append(C)}}for(const g of h.querySelectorAll(".xfaNonInteractive input, .xfaNonInteractive textarea"))g.setAttribute("readOnly",!0);return{textDivs:c}}static update(t){const e=`matrix(${t.viewport.transform.join(",")})`;t.div.style.transform=e,t.div.hidden=!1}}const Jh=1e3,BS=9,Pr=new WeakSet;function Fn(a){return{width:a[2]-a[0],height:a[3]-a[1]}}class HS{static create(t){switch(t.data.annotationType){case qt.LINK:return new Ib(t);case qt.TEXT:return new GS(t);case qt.WIDGET:switch(t.data.fieldType){case"Tx":return new zS(t);case"Btn":return t.data.radioButton?new Nb(t):t.data.checkBox?new XS(t):new WS(t);case"Ch":return new US(t);case"Sig":return new VS(t)}return new Dr(t);case qt.POPUP:return new Og(t);case qt.FREETEXT:return new jb(t);case qt.LINE:return new $S(t);case qt.SQUARE:return new qS(t);case qt.CIRCLE:return new KS(t);case qt.POLYLINE:return new Bb(t);case qt.CARET:return new JS(t);case qt.INK:return new Rg(t);case qt.POLYGON:return new QS(t);case qt.HIGHLIGHT:return new Hb(t);case qt.UNDERLINE:return new ZS(t);case qt.SQUIGGLY:return new tC(t);case qt.STRIKEOUT:return new eC(t);case qt.STAMP:return new Gb(t);case qt.FILEATTACHMENT:return new sC(t);default:return new jt(t)}}}const Ug=class Ug{constructor(t,{isRenderable:e=!1,ignoreBorder:s=!1,createQuadrilaterals:i=!1}={}){y(this,Vl);y(this,go,null);y(this,ja,!1);y(this,Ba,null);this.isRenderable=e,this.data=t.data,this.layer=t.layer,this.linkService=t.linkService,this.downloadManager=t.downloadManager,this.imageResourcesPath=t.imageResourcesPath,this.renderForms=t.renderForms,this.svgFactory=t.svgFactory,this.annotationStorage=t.annotationStorage,this.enableScripting=t.enableScripting,this.hasJSActions=t.hasJSActions,this._fieldObjects=t.fieldObjects,this.parent=t.parent,e&&(this.container=this._createContainer(s)),i&&this._createQuadrilaterals()}static _hasPopupData({titleObj:t,contentsObj:e,richText:s}){return!!(t!=null&&t.str||e!=null&&e.str||s!=null&&s.str)}get _isEditable(){return this.data.isEditable}get hasPopupData(){return Ug._hasPopupData(this.data)}updateEdited(t){var s;if(!this.container)return;l(this,go)||m(this,go,{rect:this.data.rect.slice(0)});const{rect:e}=t;e&&w(this,Vl,wp).call(this,e),(s=l(this,Ba))==null||s.popup.updateEdited(t)}resetEdited(){var t;l(this,go)&&(w(this,Vl,wp).call(this,l(this,go).rect),(t=l(this,Ba))==null||t.popup.resetEdited(),m(this,go,null))}_createContainer(t){const{data:e,parent:{page:s,viewport:i}}=this,n=document.createElement("section");n.setAttribute("data-annotation-id",e.id),this instanceof Dr||(n.tabIndex=Jh);const{style:r}=n;if(r.zIndex=this.parent.zIndex++,e.alternativeText&&(n.title=e.alternativeText),e.noRotate&&n.classList.add("norotate"),!e.rect||this instanceof Og){const{rotation:b}=e;return!e.hasOwnCanvas&&b!==0&&this.setRotation(b,n),n}const{width:o,height:h}=Fn(e.rect);if(!t&&e.borderStyle.width>0){r.borderWidth=`${e.borderStyle.width}px`;const b=e.borderStyle.horizontalCornerRadius,_=e.borderStyle.verticalCornerRadius;if(b>0||_>0){const x=`calc(${b}px * var(--scale-factor)) / calc(${_}px * var(--scale-factor))`;r.borderRadius=x}else if(this instanceof Nb){const x=`calc(${o}px * var(--scale-factor)) / calc(${h}px * var(--scale-factor))`;r.borderRadius=x}switch(e.borderStyle.style){case Gh.SOLID:r.borderStyle="solid";break;case Gh.DASHED:r.borderStyle="dashed";break;case Gh.BEVELED:et("Unimplemented border style: beveled");break;case Gh.INSET:et("Unimplemented border style: inset");break;case Gh.UNDERLINE:r.borderBottomStyle="solid";break}const v=e.borderColor||null;v?(m(this,ja,!0),r.borderColor=U.makeHexColor(v[0]|0,v[1]|0,v[2]|0)):r.borderWidth=0}const c=U.normalizeRect([e.rect[0],s.view[3]-e.rect[1]+s.view[1],e.rect[2],s.view[3]-e.rect[3]+s.view[1]]),{pageWidth:u,pageHeight:d,pageX:f,pageY:g}=i.rawDims;r.left=`${100*(c[0]-f)/u}%`,r.top=`${100*(c[1]-g)/d}%`;const{rotation:p}=e;return e.hasOwnCanvas||p===0?(r.width=`${100*o/u}%`,r.height=`${100*h/d}%`):this.setRotation(p,n),n}setRotation(t,e=this.container){if(!this.data.rect)return;const{pageWidth:s,pageHeight:i}=this.parent.viewport.rawDims,{width:n,height:r}=Fn(this.data.rect);let o,h;t%180===0?(o=100*n/s,h=100*r/i):(o=100*r/s,h=100*n/i),e.style.width=`${o}%`,e.style.height=`${h}%`,e.setAttribute("data-main-rotation",(360-t)%360)}get _commonActions(){const t=(e,s,i)=>{const n=i.detail[e],r=n[0],o=n.slice(1);i.target.style[s]=Lb[`${r}_HTML`](o),this.annotationStorage.setValue(this.data.id,{[s]:Lb[`${r}_rgb`](o)})};return it(this,"_commonActions",{display:e=>{const{display:s}=e.detail,i=s%2===1;this.container.style.visibility=i?"hidden":"visible",this.annotationStorage.setValue(this.data.id,{noView:i,noPrint:s===1||s===2})},print:e=>{this.annotationStorage.setValue(this.data.id,{noPrint:!e.detail.print})},hidden:e=>{const{hidden:s}=e.detail;this.container.style.visibility=s?"hidden":"visible",this.annotationStorage.setValue(this.data.id,{noPrint:s,noView:s})},focus:e=>{setTimeout(()=>e.target.focus({preventScroll:!1}),0)},userName:e=>{e.target.title=e.detail.userName},readonly:e=>{e.target.disabled=e.detail.readonly},required:e=>{this._setRequired(e.target,e.detail.required)},bgColor:e=>{t("bgColor","backgroundColor",e)},fillColor:e=>{t("fillColor","backgroundColor",e)},fgColor:e=>{t("fgColor","color",e)},textColor:e=>{t("textColor","color",e)},borderColor:e=>{t("borderColor","borderColor",e)},strokeColor:e=>{t("strokeColor","borderColor",e)},rotation:e=>{const s=e.detail.rotation;this.setRotation(s),this.annotationStorage.setValue(this.data.id,{rotation:s})}})}_dispatchEventFromSandbox(t,e){const s=this._commonActions;for(const i of Object.keys(e.detail)){const n=t[i]||s[i];n==null||n(e)}}_setDefaultPropertiesFromJS(t){if(!this.enableScripting)return;const e=this.annotationStorage.getRawValue(this.data.id);if(!e)return;const s=this._commonActions;for(const[i,n]of Object.entries(e)){const r=s[i];if(r){const o={detail:{[i]:n},target:t};r(o),delete e[i]}}}_createQuadrilaterals(){if(!this.container)return;const{quadPoints:t}=this.data;if(!t)return;const[e,s,i,n]=this.data.rect.map(b=>Math.fround(b));if(t.length===8){const[b,_,v,x]=t.subarray(2,6);if(i===b&&n===_&&e===v&&s===x)return}const{style:r}=this.container;let o;if(l(this,ja)){const{borderColor:b,borderWidth:_}=r;r.borderWidth=0,o=["url('data:image/svg+xml;utf8,",'<svg xmlns="http://www.w3.org/2000/svg"',' preserveAspectRatio="none" viewBox="0 0 1 1">',`<g fill="transparent" stroke="${b}" stroke-width="${_}">`],this.container.classList.add("hasBorder")}const h=i-e,c=n-s,{svgFactory:u}=this,d=u.createElement("svg");d.classList.add("quadrilateralsContainer"),d.setAttribute("width",0),d.setAttribute("height",0);const f=u.createElement("defs");d.append(f);const g=u.createElement("clipPath"),p=`clippath_${this.data.id}`;g.setAttribute("id",p),g.setAttribute("clipPathUnits","objectBoundingBox"),f.append(g);for(let b=2,_=t.length;b<_;b+=8){const v=t[b],x=t[b+1],C=t[b+2],S=t[b+3],E=u.createElement("rect"),k=(C-e)/h,M=(n-x)/c,D=(v-C)/h,R=(x-S)/c;E.setAttribute("x",k),E.setAttribute("y",M),E.setAttribute("width",D),E.setAttribute("height",R),g.append(E),o==null||o.push(`<rect vector-effect="non-scaling-stroke" x="${k}" y="${M}" width="${D}" height="${R}"/>`)}l(this,ja)&&(o.push("</g></svg>')"),r.backgroundImage=o.join("")),this.container.append(d),this.container.style.clipPath=`url(#${p})`}_createPopup(){const{data:t}=this,e=m(this,Ba,new Og({data:{color:t.color,titleObj:t.titleObj,modificationDate:t.modificationDate,contentsObj:t.contentsObj,richText:t.richText,parentRect:t.rect,borderStyle:0,id:`popup_${t.id}`,rotation:t.rotation},parent:this.parent,elements:[this]}));this.parent.div.append(e.render())}render(){vt("Abstract method `AnnotationElement.render` called")}_getElementsByName(t,e=null){const s=[];if(this._fieldObjects){const i=this._fieldObjects[t];if(i)for(const{page:n,id:r,exportValues:o}of i){if(n===-1||r===e)continue;const h=typeof o=="string"?o:null,c=document.querySelector(`[data-element-id="${r}"]`);if(c&&!Pr.has(c)){et(`_getElementsByName - element not allowed: ${r}`);continue}s.push({id:r,exportValue:h,domElement:c})}return s}for(const i of document.getElementsByName(t)){const{exportValue:n}=i,r=i.getAttribute("data-element-id");r!==e&&Pr.has(i)&&s.push({id:r,exportValue:n,domElement:i})}return s}show(){var t;this.container&&(this.container.hidden=!1),(t=this.popup)==null||t.maybeShow()}hide(){var t;this.container&&(this.container.hidden=!0),(t=this.popup)==null||t.forceHide()}getElementsToTriggerPopup(){return this.container}addHighlightArea(){const t=this.getElementsToTriggerPopup();if(Array.isArray(t))for(const e of t)e.classList.add("highlightArea");else t.classList.add("highlightArea")}_editOnDoubleClick(){if(!this._isEditable)return;const{annotationEditorType:t,data:{id:e}}=this;this.container.addEventListener("dblclick",()=>{var s;(s=this.linkService.eventBus)==null||s.dispatch("switchannotationeditormode",{source:this,mode:t,editId:e})})}};go=new WeakMap,ja=new WeakMap,Ba=new WeakMap,Vl=new WeakSet,wp=function(t){const{container:{style:e},data:{rect:s,rotation:i},parent:{viewport:{rawDims:{pageWidth:n,pageHeight:r,pageX:o,pageY:h}}}}=this;s==null||s.splice(0,4,...t);const{width:c,height:u}=Fn(t);e.left=`${100*(t[0]-o)/n}%`,e.top=`${100*(r-t[3]+h)/r}%`,i===0?(e.width=`${100*c/n}%`,e.height=`${100*u/r}%`):this.setRotation(i)};let jt=Ug;class Ib extends jt{constructor(e,s=null){super(e,{isRenderable:!0,ignoreBorder:!!(s!=null&&s.ignoreBorder),createQuadrilaterals:!0});y(this,as);this.isTooltipOnly=e.data.isTooltipOnly}render(){const{data:e,linkService:s}=this,i=document.createElement("a");i.setAttribute("data-element-id",e.id);let n=!1;return e.url?(s.addLinkAttributes(i,e.url,e.newWindow),n=!0):e.action?(this._bindNamedAction(i,e.action),n=!0):e.attachment?(w(this,as,Py).call(this,i,e.attachment,e.attachmentDest),n=!0):e.setOCGState?(w(this,as,Dy).call(this,i,e.setOCGState),n=!0):e.dest?(this._bindLink(i,e.dest),n=!0):(e.actions&&(e.actions.Action||e.actions["Mouse Up"]||e.actions["Mouse Down"])&&this.enableScripting&&this.hasJSActions&&(this._bindJSAction(i,e),n=!0),e.resetForm?(this._bindResetFormAction(i,e.resetForm),n=!0):this.isTooltipOnly&&!n&&(this._bindLink(i,""),n=!0)),this.container.classList.add("linkAnnotation"),n&&this.container.append(i),this.container}_bindLink(e,s){e.href=this.linkService.getDestinationHash(s),e.onclick=()=>(s&&this.linkService.goToDestination(s),!1),(s||s==="")&&w(this,as,Ho).call(this)}_bindNamedAction(e,s){e.href=this.linkService.getAnchorUrl(""),e.onclick=()=>(this.linkService.executeNamedAction(s),!1),w(this,as,Ho).call(this)}_bindJSAction(e,s){e.href=this.linkService.getAnchorUrl("");const i=new Map([["Action","onclick"],["Mouse Up","onmouseup"],["Mouse Down","onmousedown"]]);for(const n of Object.keys(s.actions)){const r=i.get(n);r&&(e[r]=()=>{var o;return(o=this.linkService.eventBus)==null||o.dispatch("dispatcheventinsandbox",{source:this,detail:{id:s.id,name:n}}),!1})}e.onclick||(e.onclick=()=>!1),w(this,as,Ho).call(this)}_bindResetFormAction(e,s){const i=e.onclick;if(i||(e.href=this.linkService.getAnchorUrl("")),w(this,as,Ho).call(this),!this._fieldObjects){et('_bindResetFormAction - "resetForm" action not supported, ensure that the `fieldObjects` parameter is provided.'),i||(e.onclick=()=>!1);return}e.onclick=()=>{var d;i==null||i();const{fields:n,refs:r,include:o}=s,h=[];if(n.length!==0||r.length!==0){const f=new Set(r);for(const g of n){const p=this._fieldObjects[g]||[];for(const{id:b}of p)f.add(b)}for(const g of Object.values(this._fieldObjects))for(const p of g)f.has(p.id)===o&&h.push(p)}else for(const f of Object.values(this._fieldObjects))h.push(...f);const c=this.annotationStorage,u=[];for(const f of h){const{id:g}=f;switch(u.push(g),f.type){case"text":{const b=f.defaultValue||"";c.setValue(g,{value:b});break}case"checkbox":case"radiobutton":{const b=f.defaultValue===f.exportValues;c.setValue(g,{value:b});break}case"combobox":case"listbox":{const b=f.defaultValue||"";c.setValue(g,{value:b});break}default:continue}const p=document.querySelector(`[data-element-id="${g}"]`);if(p){if(!Pr.has(p)){et(`_bindResetFormAction - element not allowed: ${g}`);continue}}else continue;p.dispatchEvent(new Event("resetform"))}return this.enableScripting&&((d=this.linkService.eventBus)==null||d.dispatch("dispatcheventinsandbox",{source:this,detail:{id:"app",ids:u,name:"ResetForm"}})),!1}}}as=new WeakSet,Ho=function(){this.container.setAttribute("data-internal-link","")},Py=function(e,s,i=null){e.href=this.linkService.getAnchorUrl(""),s.description&&(e.title=s.description),e.onclick=()=>{var n;return(n=this.downloadManager)==null||n.openOrDownloadData(s.content,s.filename,i),!1},w(this,as,Ho).call(this)},Dy=function(e,s){e.href=this.linkService.getAnchorUrl(""),e.onclick=()=>(this.linkService.executeSetOCGState(s),!1),w(this,as,Ho).call(this)};class GS extends jt{constructor(t){super(t,{isRenderable:!0})}render(){this.container.classList.add("textAnnotation");const t=document.createElement("img");return t.src=this.imageResourcesPath+"annotation-"+this.data.name.toLowerCase()+".svg",t.setAttribute("data-l10n-id","pdfjs-text-annotation-type"),t.setAttribute("data-l10n-args",JSON.stringify({type:this.data.name})),!this.data.popupRef&&this.hasPopupData&&this._createPopup(),this.container.append(t),this.container}}class Dr extends jt{render(){return this.container}showElementAndHideCanvas(t){var e;this.data.hasOwnCanvas&&(((e=t.previousSibling)==null?void 0:e.nodeName)==="CANVAS"&&(t.previousSibling.hidden=!0),t.hidden=!1)}_getKeyModifier(t){return Re.platform.isMac?t.metaKey:t.ctrlKey}_setEventListener(t,e,s,i,n){s.includes("mouse")?t.addEventListener(s,r=>{var o;(o=this.linkService.eventBus)==null||o.dispatch("dispatcheventinsandbox",{source:this,detail:{id:this.data.id,name:i,value:n(r),shift:r.shiftKey,modifier:this._getKeyModifier(r)}})}):t.addEventListener(s,r=>{var o;if(s==="blur"){if(!e.focused||!r.relatedTarget)return;e.focused=!1}else if(s==="focus"){if(e.focused)return;e.focused=!0}n&&((o=this.linkService.eventBus)==null||o.dispatch("dispatcheventinsandbox",{source:this,detail:{id:this.data.id,name:i,value:n(r)}}))})}_setEventListeners(t,e,s,i){var n,r,o;for(const[h,c]of s)(c==="Action"||(n=this.data.actions)!=null&&n[c])&&((c==="Focus"||c==="Blur")&&(e||(e={focused:!1})),this._setEventListener(t,e,h,c,i),c==="Focus"&&!((r=this.data.actions)!=null&&r.Blur)?this._setEventListener(t,e,"blur","Blur",null):c==="Blur"&&!((o=this.data.actions)!=null&&o.Focus)&&this._setEventListener(t,e,"focus","Focus",null))}_setBackgroundColor(t){const e=this.data.backgroundColor||null;t.style.backgroundColor=e===null?"transparent":U.makeHexColor(e[0],e[1],e[2])}_setTextStyle(t){const e=["left","center","right"],{fontColor:s}=this.data.defaultAppearanceData,i=this.data.defaultAppearanceData.fontSize||BS,n=t.style;let r;const o=2,h=c=>Math.round(10*c)/10;if(this.data.multiLine){const c=Math.abs(this.data.rect[3]-this.data.rect[1]-o),u=Math.round(c/(og*i))||1,d=c/u;r=Math.min(i,h(d/og))}else{const c=Math.abs(this.data.rect[3]-this.data.rect[1]-o);r=Math.min(i,h(c/og))}n.fontSize=`calc(${r}px * var(--scale-factor))`,n.color=U.makeHexColor(s[0],s[1],s[2]),this.data.textAlignment!==null&&(n.textAlign=e[this.data.textAlignment])}_setRequired(t,e){e?t.setAttribute("required",!0):t.removeAttribute("required"),t.setAttribute("aria-required",e)}}class zS extends Dr{constructor(t){const e=t.renderForms||t.data.hasOwnCanvas||!t.data.hasAppearance&&!!t.data.fieldValue;super(t,{isRenderable:e})}setPropertyOnSiblings(t,e,s,i){const n=this.annotationStorage;for(const r of this._getElementsByName(t.name,t.id))r.domElement&&(r.domElement[e]=s),n.setValue(r.id,{[i]:s})}render(){var i,n;const t=this.annotationStorage,e=this.data.id;this.container.classList.add("textWidgetAnnotation");let s=null;if(this.renderForms){const r=t.getValue(e,{value:this.data.fieldValue});let o=r.value||"";const h=t.getValue(e,{charLimit:this.data.maxLen}).charLimit;h&&o.length>h&&(o=o.slice(0,h));let c=r.formattedValue||((i=this.data.textContent)==null?void 0:i.join(`
|
|
500
|
-
`))||null;c&&this.data.comb&&(c=c.replaceAll(/\s+/g,""));const u={userValue:o,formattedValue:c,lastCommittedValue:null,commitKey:1,focused:!1};this.data.multiLine?(s=document.createElement("textarea"),s.textContent=c??o,this.data.doNotScroll&&(s.style.overflowY="hidden")):(s=document.createElement("input"),s.type="text",s.setAttribute("value",c??o),this.data.doNotScroll&&(s.style.overflowX="hidden")),this.data.hasOwnCanvas&&(s.hidden=!0),Pr.add(s),s.setAttribute("data-element-id",e),s.disabled=this.data.readOnly,s.name=this.data.fieldName,s.tabIndex=Jh,this._setRequired(s,this.data.required),h&&(s.maxLength=h),s.addEventListener("input",f=>{t.setValue(e,{value:f.target.value}),this.setPropertyOnSiblings(s,"value",f.target.value,"value"),u.formattedValue=null}),s.addEventListener("resetform",f=>{const g=this.data.defaultFieldValue??"";s.value=u.userValue=g,u.formattedValue=null});let d=f=>{const{formattedValue:g}=u;g!=null&&(f.target.value=g),f.target.scrollLeft=0};if(this.enableScripting&&this.hasJSActions){s.addEventListener("focus",g=>{var b;if(u.focused)return;const{target:p}=g;u.userValue&&(p.value=u.userValue),u.lastCommittedValue=p.value,u.commitKey=1,(b=this.data.actions)!=null&&b.Focus||(u.focused=!0)}),s.addEventListener("updatefromsandbox",g=>{this.showElementAndHideCanvas(g.target);const p={value(b){u.userValue=b.detail.value??"",t.setValue(e,{value:u.userValue.toString()}),b.target.value=u.userValue},formattedValue(b){const{formattedValue:_}=b.detail;u.formattedValue=_,_!=null&&b.target!==document.activeElement&&(b.target.value=_),t.setValue(e,{formattedValue:_})},selRange(b){b.target.setSelectionRange(...b.detail.selRange)},charLimit:b=>{var C;const{charLimit:_}=b.detail,{target:v}=b;if(_===0){v.removeAttribute("maxLength");return}v.setAttribute("maxLength",_);let x=u.userValue;!x||x.length<=_||(x=x.slice(0,_),v.value=u.userValue=x,t.setValue(e,{value:x}),(C=this.linkService.eventBus)==null||C.dispatch("dispatcheventinsandbox",{source:this,detail:{id:e,name:"Keystroke",value:x,willCommit:!0,commitKey:1,selStart:v.selectionStart,selEnd:v.selectionEnd}}))}};this._dispatchEventFromSandbox(p,g)}),s.addEventListener("keydown",g=>{var _;u.commitKey=1;let p=-1;if(g.key==="Escape"?p=0:g.key==="Enter"&&!this.data.multiLine?p=2:g.key==="Tab"&&(u.commitKey=3),p===-1)return;const{value:b}=g.target;u.lastCommittedValue!==b&&(u.lastCommittedValue=b,u.userValue=b,(_=this.linkService.eventBus)==null||_.dispatch("dispatcheventinsandbox",{source:this,detail:{id:e,name:"Keystroke",value:b,willCommit:!0,commitKey:p,selStart:g.target.selectionStart,selEnd:g.target.selectionEnd}}))});const f=d;d=null,s.addEventListener("blur",g=>{var b,_;if(!u.focused||!g.relatedTarget)return;(b=this.data.actions)!=null&&b.Blur||(u.focused=!1);const{value:p}=g.target;u.userValue=p,u.lastCommittedValue!==p&&((_=this.linkService.eventBus)==null||_.dispatch("dispatcheventinsandbox",{source:this,detail:{id:e,name:"Keystroke",value:p,willCommit:!0,commitKey:u.commitKey,selStart:g.target.selectionStart,selEnd:g.target.selectionEnd}})),f(g)}),(n=this.data.actions)!=null&&n.Keystroke&&s.addEventListener("beforeinput",g=>{var E;u.lastCommittedValue=null;const{data:p,target:b}=g,{value:_,selectionStart:v,selectionEnd:x}=b;let C=v,S=x;switch(g.inputType){case"deleteWordBackward":{const k=_.substring(0,v).match(/\w*[^\w]*$/);k&&(C-=k[0].length);break}case"deleteWordForward":{const k=_.substring(v).match(/^[^\w]*\w*/);k&&(S+=k[0].length);break}case"deleteContentBackward":v===x&&(C-=1);break;case"deleteContentForward":v===x&&(S+=1);break}g.preventDefault(),(E=this.linkService.eventBus)==null||E.dispatch("dispatcheventinsandbox",{source:this,detail:{id:e,name:"Keystroke",value:_,change:p||"",willCommit:!1,selStart:C,selEnd:S}})}),this._setEventListeners(s,u,[["focus","Focus"],["blur","Blur"],["mousedown","Mouse Down"],["mouseenter","Mouse Enter"],["mouseleave","Mouse Exit"],["mouseup","Mouse Up"]],g=>g.target.value)}if(d&&s.addEventListener("blur",d),this.data.comb){const g=(this.data.rect[2]-this.data.rect[0])/h;s.classList.add("comb"),s.style.letterSpacing=`calc(${g}px * var(--scale-factor) - 1ch)`}}else s=document.createElement("div"),s.textContent=this.data.fieldValue,s.style.verticalAlign="middle",s.style.display="table-cell",this.data.hasOwnCanvas&&(s.hidden=!0);return this._setTextStyle(s),this._setBackgroundColor(s),this._setDefaultPropertiesFromJS(s),this.container.append(s),this.container}}class VS extends Dr{constructor(t){super(t,{isRenderable:!!t.data.hasOwnCanvas})}}class XS extends Dr{constructor(t){super(t,{isRenderable:t.renderForms})}render(){const t=this.annotationStorage,e=this.data,s=e.id;let i=t.getValue(s,{value:e.exportValue===e.fieldValue}).value;typeof i=="string"&&(i=i!=="Off",t.setValue(s,{value:i})),this.container.classList.add("buttonWidgetAnnotation","checkBox");const n=document.createElement("input");return Pr.add(n),n.setAttribute("data-element-id",s),n.disabled=e.readOnly,this._setRequired(n,this.data.required),n.type="checkbox",n.name=e.fieldName,i&&n.setAttribute("checked",!0),n.setAttribute("exportValue",e.exportValue),n.tabIndex=Jh,n.addEventListener("change",r=>{const{name:o,checked:h}=r.target;for(const c of this._getElementsByName(o,s)){const u=h&&c.exportValue===e.exportValue;c.domElement&&(c.domElement.checked=u),t.setValue(c.id,{value:u})}t.setValue(s,{value:h})}),n.addEventListener("resetform",r=>{const o=e.defaultFieldValue||"Off";r.target.checked=o===e.exportValue}),this.enableScripting&&this.hasJSActions&&(n.addEventListener("updatefromsandbox",r=>{const o={value(h){h.target.checked=h.detail.value!=="Off",t.setValue(s,{value:h.target.checked})}};this._dispatchEventFromSandbox(o,r)}),this._setEventListeners(n,null,[["change","Validate"],["change","Action"],["focus","Focus"],["blur","Blur"],["mousedown","Mouse Down"],["mouseenter","Mouse Enter"],["mouseleave","Mouse Exit"],["mouseup","Mouse Up"]],r=>r.target.checked)),this._setBackgroundColor(n),this._setDefaultPropertiesFromJS(n),this.container.append(n),this.container}}class Nb extends Dr{constructor(t){super(t,{isRenderable:t.renderForms})}render(){this.container.classList.add("buttonWidgetAnnotation","radioButton");const t=this.annotationStorage,e=this.data,s=e.id;let i=t.getValue(s,{value:e.fieldValue===e.buttonValue}).value;if(typeof i=="string"&&(i=i!==e.buttonValue,t.setValue(s,{value:i})),i)for(const r of this._getElementsByName(e.fieldName,s))t.setValue(r.id,{value:!1});const n=document.createElement("input");if(Pr.add(n),n.setAttribute("data-element-id",s),n.disabled=e.readOnly,this._setRequired(n,this.data.required),n.type="radio",n.name=e.fieldName,i&&n.setAttribute("checked",!0),n.tabIndex=Jh,n.addEventListener("change",r=>{const{name:o,checked:h}=r.target;for(const c of this._getElementsByName(o,s))t.setValue(c.id,{value:!1});t.setValue(s,{value:h})}),n.addEventListener("resetform",r=>{const o=e.defaultFieldValue;r.target.checked=o!=null&&o===e.buttonValue}),this.enableScripting&&this.hasJSActions){const r=e.buttonValue;n.addEventListener("updatefromsandbox",o=>{const h={value:c=>{const u=r===c.detail.value;for(const d of this._getElementsByName(c.target.name)){const f=u&&d.id===s;d.domElement&&(d.domElement.checked=f),t.setValue(d.id,{value:f})}}};this._dispatchEventFromSandbox(h,o)}),this._setEventListeners(n,null,[["change","Validate"],["change","Action"],["focus","Focus"],["blur","Blur"],["mousedown","Mouse Down"],["mouseenter","Mouse Enter"],["mouseleave","Mouse Exit"],["mouseup","Mouse Up"]],o=>o.target.checked)}return this._setBackgroundColor(n),this._setDefaultPropertiesFromJS(n),this.container.append(n),this.container}}class WS extends Ib{constructor(t){super(t,{ignoreBorder:t.data.hasAppearance})}render(){const t=super.render();t.classList.add("buttonWidgetAnnotation","pushButton");const e=t.lastChild;return this.enableScripting&&this.hasJSActions&&e&&(this._setDefaultPropertiesFromJS(e),e.addEventListener("updatefromsandbox",s=>{this._dispatchEventFromSandbox({},s)})),t}}class US extends Dr{constructor(t){super(t,{isRenderable:t.renderForms})}render(){this.container.classList.add("choiceWidgetAnnotation");const t=this.annotationStorage,e=this.data.id,s=t.getValue(e,{value:this.data.fieldValue}),i=document.createElement("select");Pr.add(i),i.setAttribute("data-element-id",e),i.disabled=this.data.readOnly,this._setRequired(i,this.data.required),i.name=this.data.fieldName,i.tabIndex=Jh;let n=this.data.combo&&this.data.options.length>0;this.data.combo||(i.size=this.data.options.length,this.data.multiSelect&&(i.multiple=!0)),i.addEventListener("resetform",u=>{const d=this.data.defaultFieldValue;for(const f of i.options)f.selected=f.value===d});for(const u of this.data.options){const d=document.createElement("option");d.textContent=u.displayValue,d.value=u.exportValue,s.value.includes(u.exportValue)&&(d.setAttribute("selected",!0),n=!1),i.append(d)}let r=null;if(n){const u=document.createElement("option");u.value=" ",u.setAttribute("hidden",!0),u.setAttribute("selected",!0),i.prepend(u),r=()=>{u.remove(),i.removeEventListener("input",r),r=null},i.addEventListener("input",r)}const o=u=>{const d=u?"value":"textContent",{options:f,multiple:g}=i;return g?Array.prototype.filter.call(f,p=>p.selected).map(p=>p[d]):f.selectedIndex===-1?null:f[f.selectedIndex][d]};let h=o(!1);const c=u=>{const d=u.target.options;return Array.prototype.map.call(d,f=>({displayValue:f.textContent,exportValue:f.value}))};return this.enableScripting&&this.hasJSActions?(i.addEventListener("updatefromsandbox",u=>{const d={value(f){r==null||r();const g=f.detail.value,p=new Set(Array.isArray(g)?g:[g]);for(const b of i.options)b.selected=p.has(b.value);t.setValue(e,{value:o(!0)}),h=o(!1)},multipleSelection(f){i.multiple=!0},remove(f){const g=i.options,p=f.detail.remove;g[p].selected=!1,i.remove(p),g.length>0&&Array.prototype.findIndex.call(g,_=>_.selected)===-1&&(g[0].selected=!0),t.setValue(e,{value:o(!0),items:c(f)}),h=o(!1)},clear(f){for(;i.length!==0;)i.remove(0);t.setValue(e,{value:null,items:[]}),h=o(!1)},insert(f){const{index:g,displayValue:p,exportValue:b}=f.detail.insert,_=i.children[g],v=document.createElement("option");v.textContent=p,v.value=b,_?_.before(v):i.append(v),t.setValue(e,{value:o(!0),items:c(f)}),h=o(!1)},items(f){const{items:g}=f.detail;for(;i.length!==0;)i.remove(0);for(const p of g){const{displayValue:b,exportValue:_}=p,v=document.createElement("option");v.textContent=b,v.value=_,i.append(v)}i.options.length>0&&(i.options[0].selected=!0),t.setValue(e,{value:o(!0),items:c(f)}),h=o(!1)},indices(f){const g=new Set(f.detail.indices);for(const p of f.target.options)p.selected=g.has(p.index);t.setValue(e,{value:o(!0)}),h=o(!1)},editable(f){f.target.disabled=!f.detail.editable}};this._dispatchEventFromSandbox(d,u)}),i.addEventListener("input",u=>{var g;const d=o(!0),f=o(!1);t.setValue(e,{value:d}),u.preventDefault(),(g=this.linkService.eventBus)==null||g.dispatch("dispatcheventinsandbox",{source:this,detail:{id:e,name:"Keystroke",value:h,change:f,changeEx:d,willCommit:!1,commitKey:1,keyDown:!1}})}),this._setEventListeners(i,null,[["focus","Focus"],["blur","Blur"],["mousedown","Mouse Down"],["mouseenter","Mouse Enter"],["mouseleave","Mouse Exit"],["mouseup","Mouse Up"],["input","Action"],["input","Validate"]],u=>u.target.value)):i.addEventListener("input",function(u){t.setValue(e,{value:o(!0)})}),this.data.combo&&this._setTextStyle(i),this._setBackgroundColor(i),this._setDefaultPropertiesFromJS(i),this.container.append(i),this.container}}class Og extends jt{constructor(t){const{data:e,elements:s}=t;super(t,{isRenderable:jt._hasPopupData(e)}),this.elements=s,this.popup=null}render(){this.container.classList.add("popupAnnotation");const t=this.popup=new YS({container:this.container,color:this.data.color,titleObj:this.data.titleObj,modificationDate:this.data.modificationDate,contentsObj:this.data.contentsObj,richText:this.data.richText,rect:this.data.rect,parentRect:this.data.parentRect||null,parent:this.parent,elements:this.elements,open:this.data.open}),e=[];for(const s of this.elements)s.popup=t,s.container.ariaHasPopup="dialog",e.push(s.data.id),s.addHighlightArea();return this.container.setAttribute("aria-controls",e.map(s=>`${dg}${s}`).join(",")),this.container}}class YS{constructor({container:t,color:e,elements:s,titleObj:i,modificationDate:n,contentsObj:r,richText:o,parent:h,rect:c,parentRect:u,open:d}){y(this,bt);y(this,Ha,w(this,bt,Ly).bind(this));y(this,_d,w(this,bt,Sp).bind(this));y(this,wd,w(this,bt,Xd).bind(this));y(this,Ga,w(this,bt,Vd).bind(this));y(this,po,null);y(this,Lt,null);y(this,ln,null);y(this,za,null);y(this,Xl,null);y(this,Wl,null);y(this,Va,null);y(this,cn,!1);y(this,$s,null);y(this,un,null);y(this,Ul,null);y(this,dn,null);y(this,Yl,null);y(this,mo,null);y(this,bo,!1);var f;m(this,Lt,t),m(this,Yl,i),m(this,ln,r),m(this,dn,o),m(this,Wl,h),m(this,po,e),m(this,Ul,c),m(this,Va,u),m(this,Xl,s),m(this,za,pg.toDateObject(n)),this.trigger=s.flatMap(g=>g.getElementsToTriggerPopup());for(const g of this.trigger)g.addEventListener("click",l(this,Ga)),g.addEventListener("mouseenter",l(this,wd)),g.addEventListener("mouseleave",l(this,_d)),g.classList.add("popupTriggerArea");for(const g of s)(f=g.container)==null||f.addEventListener("keydown",l(this,Ha));l(this,Lt).hidden=!0,d&&w(this,bt,Vd).call(this)}render(){if(l(this,$s))return;const t=m(this,$s,document.createElement("div"));if(t.className="popup",l(this,po)){const n=t.style.outlineColor=U.makeHexColor(...l(this,po));CSS.supports("background-color","color-mix(in srgb, red 30%, white)")?t.style.backgroundColor=`color-mix(in srgb, ${n} 30%, white)`:t.style.backgroundColor=U.makeHexColor(...l(this,po).map(o=>Math.floor(.7*(255-o)+o)))}const e=document.createElement("span");e.className="header";const s=document.createElement("h1");if(e.append(s),{dir:s.dir,str:s.textContent}=l(this,Yl),t.append(e),l(this,za)){const n=document.createElement("span");n.classList.add("popupDate"),n.setAttribute("data-l10n-id","pdfjs-annotation-date-time-string"),n.setAttribute("data-l10n-args",JSON.stringify({dateObj:l(this,za).valueOf()})),e.append(n)}const i=l(this,bt,zd);if(i)Fb.render({xfaHtml:i,intent:"richText",div:t}),t.lastChild.classList.add("richText","popupContent");else{const n=this._formatContents(l(this,ln));t.append(n)}l(this,Lt).append(t)}_formatContents({str:t,dir:e}){const s=document.createElement("p");s.classList.add("popupContent"),s.dir=e;const i=t.split(/(?:\r\n?|\n)/);for(let n=0,r=i.length;n<r;++n){const o=i[n];s.append(document.createTextNode(o)),n<r-1&&s.append(document.createElement("br"))}return s}updateEdited({rect:t,popupContent:e}){var s;l(this,mo)||m(this,mo,{contentsObj:l(this,ln),richText:l(this,dn)}),t&&m(this,un,null),e&&(m(this,dn,w(this,bt,Ry).call(this,e)),m(this,ln,null)),(s=l(this,$s))==null||s.remove(),m(this,$s,null)}resetEdited(){var t;l(this,mo)&&({contentsObj:Ge(this,ln)._,richText:Ge(this,dn)._}=l(this,mo),m(this,mo,null),(t=l(this,$s))==null||t.remove(),m(this,$s,null),m(this,un,null))}forceHide(){m(this,bo,this.isVisible),l(this,bo)&&(l(this,Lt).hidden=!0)}maybeShow(){l(this,bo)&&(l(this,$s)||w(this,bt,Xd).call(this),m(this,bo,!1),l(this,Lt).hidden=!1)}get isVisible(){return l(this,Lt).hidden===!1}}Ha=new WeakMap,_d=new WeakMap,wd=new WeakMap,Ga=new WeakMap,po=new WeakMap,Lt=new WeakMap,ln=new WeakMap,za=new WeakMap,Xl=new WeakMap,Wl=new WeakMap,Va=new WeakMap,cn=new WeakMap,$s=new WeakMap,un=new WeakMap,Ul=new WeakMap,dn=new WeakMap,Yl=new WeakMap,mo=new WeakMap,bo=new WeakMap,bt=new WeakSet,zd=function(){const t=l(this,dn),e=l(this,ln);return t!=null&&t.str&&(!(e!=null&&e.str)||e.str===t.str)&&l(this,dn).html||null},xp=function(){var t,e,s;return((s=(e=(t=l(this,bt,zd))==null?void 0:t.attributes)==null?void 0:e.style)==null?void 0:s.fontSize)||0},Oy=function(){var t,e,s;return((s=(e=(t=l(this,bt,zd))==null?void 0:t.attributes)==null?void 0:e.style)==null?void 0:s.color)||null},Ry=function(t){const e=[],s={str:t,html:{name:"div",attributes:{dir:"auto"},children:[{name:"p",children:e}]}},i={style:{color:l(this,bt,Oy),fontSize:l(this,bt,xp)?`calc(${l(this,bt,xp)}px * var(--scale-factor))`:""}};for(const n of t.split(`
|
|
501
|
-
`))e.push({name:"span",value:n,attributes:i});return s},Ly=function(t){t.altKey||t.shiftKey||t.ctrlKey||t.metaKey||(t.key==="Enter"||t.key==="Escape"&&l(this,cn))&&w(this,bt,Vd).call(this)},Fy=function(){if(l(this,un)!==null)return;const{page:{view:t},viewport:{rawDims:{pageWidth:e,pageHeight:s,pageX:i,pageY:n}}}=l(this,Wl);let r=!!l(this,Va),o=r?l(this,Va):l(this,Ul);for(const p of l(this,Xl))if(!o||U.intersect(p.data.rect,o)!==null){o=p.data.rect,r=!0;break}const h=U.normalizeRect([o[0],t[3]-o[1]+t[1],o[2],t[3]-o[3]+t[1]]),u=r?o[2]-o[0]+5:0,d=h[0]+u,f=h[1];m(this,un,[100*(d-i)/e,100*(f-n)/s]);const{style:g}=l(this,Lt);g.left=`${l(this,un)[0]}%`,g.top=`${l(this,un)[1]}%`},Vd=function(){m(this,cn,!l(this,cn)),l(this,cn)?(w(this,bt,Xd).call(this),l(this,Lt).addEventListener("click",l(this,Ga)),l(this,Lt).addEventListener("keydown",l(this,Ha))):(w(this,bt,Sp).call(this),l(this,Lt).removeEventListener("click",l(this,Ga)),l(this,Lt).removeEventListener("keydown",l(this,Ha)))},Xd=function(){l(this,$s)||this.render(),this.isVisible?l(this,cn)&&l(this,Lt).classList.add("focused"):(w(this,bt,Fy).call(this),l(this,Lt).hidden=!1,l(this,Lt).style.zIndex=parseInt(l(this,Lt).style.zIndex)+1e3)},Sp=function(){l(this,Lt).classList.remove("focused"),!(l(this,cn)||!this.isVisible)&&(l(this,Lt).hidden=!0,l(this,Lt).style.zIndex=parseInt(l(this,Lt).style.zIndex)-1e3)};class jb extends jt{constructor(t){super(t,{isRenderable:!0,ignoreBorder:!0}),this.textContent=t.data.textContent,this.textPosition=t.data.textPosition,this.annotationEditorType=tt.FREETEXT}render(){if(this.container.classList.add("freeTextAnnotation"),this.textContent){const t=document.createElement("div");t.classList.add("annotationTextContent"),t.setAttribute("role","comment");for(const e of this.textContent){const s=document.createElement("span");s.textContent=e,t.append(s)}this.container.append(t)}return!this.data.popupRef&&this.hasPopupData&&this._createPopup(),this._editOnDoubleClick(),this.container}}class $S extends jt{constructor(e){super(e,{isRenderable:!0,ignoreBorder:!0});y(this,$l,null)}render(){this.container.classList.add("lineAnnotation");const e=this.data,{width:s,height:i}=Fn(e.rect),n=this.svgFactory.create(s,i,!0),r=m(this,$l,this.svgFactory.createElement("svg:line"));return r.setAttribute("x1",e.rect[2]-e.lineCoordinates[0]),r.setAttribute("y1",e.rect[3]-e.lineCoordinates[1]),r.setAttribute("x2",e.rect[2]-e.lineCoordinates[2]),r.setAttribute("y2",e.rect[3]-e.lineCoordinates[3]),r.setAttribute("stroke-width",e.borderStyle.width||1),r.setAttribute("stroke","transparent"),r.setAttribute("fill","transparent"),n.append(r),this.container.append(n),!e.popupRef&&this.hasPopupData&&this._createPopup(),this.container}getElementsToTriggerPopup(){return l(this,$l)}addHighlightArea(){this.container.classList.add("highlightArea")}}$l=new WeakMap;class qS extends jt{constructor(e){super(e,{isRenderable:!0,ignoreBorder:!0});y(this,ql,null)}render(){this.container.classList.add("squareAnnotation");const e=this.data,{width:s,height:i}=Fn(e.rect),n=this.svgFactory.create(s,i,!0),r=e.borderStyle.width,o=m(this,ql,this.svgFactory.createElement("svg:rect"));return o.setAttribute("x",r/2),o.setAttribute("y",r/2),o.setAttribute("width",s-r),o.setAttribute("height",i-r),o.setAttribute("stroke-width",r||1),o.setAttribute("stroke","transparent"),o.setAttribute("fill","transparent"),n.append(o),this.container.append(n),!e.popupRef&&this.hasPopupData&&this._createPopup(),this.container}getElementsToTriggerPopup(){return l(this,ql)}addHighlightArea(){this.container.classList.add("highlightArea")}}ql=new WeakMap;class KS extends jt{constructor(e){super(e,{isRenderable:!0,ignoreBorder:!0});y(this,Kl,null)}render(){this.container.classList.add("circleAnnotation");const e=this.data,{width:s,height:i}=Fn(e.rect),n=this.svgFactory.create(s,i,!0),r=e.borderStyle.width,o=m(this,Kl,this.svgFactory.createElement("svg:ellipse"));return o.setAttribute("cx",s/2),o.setAttribute("cy",i/2),o.setAttribute("rx",s/2-r/2),o.setAttribute("ry",i/2-r/2),o.setAttribute("stroke-width",r||1),o.setAttribute("stroke","transparent"),o.setAttribute("fill","transparent"),n.append(o),this.container.append(n),!e.popupRef&&this.hasPopupData&&this._createPopup(),this.container}getElementsToTriggerPopup(){return l(this,Kl)}addHighlightArea(){this.container.classList.add("highlightArea")}}Kl=new WeakMap;class Bb extends jt{constructor(e){super(e,{isRenderable:!0,ignoreBorder:!0});y(this,Ql,null);this.containerClassName="polylineAnnotation",this.svgElementName="svg:polyline"}render(){this.container.classList.add(this.containerClassName);const{data:{rect:e,vertices:s,borderStyle:i,popupRef:n}}=this;if(!s)return this.container;const{width:r,height:o}=Fn(e),h=this.svgFactory.create(r,o,!0);let c=[];for(let d=0,f=s.length;d<f;d+=2){const g=s[d]-e[0],p=e[3]-s[d+1];c.push(`${g},${p}`)}c=c.join(" ");const u=m(this,Ql,this.svgFactory.createElement(this.svgElementName));return u.setAttribute("points",c),u.setAttribute("stroke-width",i.width||1),u.setAttribute("stroke","transparent"),u.setAttribute("fill","transparent"),h.append(u),this.container.append(h),!n&&this.hasPopupData&&this._createPopup(),this.container}getElementsToTriggerPopup(){return l(this,Ql)}addHighlightArea(){this.container.classList.add("highlightArea")}}Ql=new WeakMap;class QS extends Bb{constructor(t){super(t),this.containerClassName="polygonAnnotation",this.svgElementName="svg:polygon"}}class JS extends jt{constructor(t){super(t,{isRenderable:!0,ignoreBorder:!0})}render(){return this.container.classList.add("caretAnnotation"),!this.data.popupRef&&this.hasPopupData&&this._createPopup(),this.container}}class Rg extends jt{constructor(e){super(e,{isRenderable:!0,ignoreBorder:!0});y(this,Zl);y(this,Jl,null);y(this,yo,[]);this.containerClassName="inkAnnotation",this.svgElementName="svg:polyline",this.annotationEditorType=this.data.it==="InkHighlight"?tt.HIGHLIGHT:tt.INK}render(){this.container.classList.add(this.containerClassName);const{data:{rect:e,rotation:s,inkLists:i,borderStyle:n,popupRef:r}}=this,{transform:o,width:h,height:c}=w(this,Zl,Cp).call(this,s,e),u=this.svgFactory.create(h,c,!0),d=m(this,Jl,this.svgFactory.createElement("svg:g"));u.append(d),d.setAttribute("stroke-width",n.width||1),d.setAttribute("stroke-linecap","round"),d.setAttribute("stroke-linejoin","round"),d.setAttribute("stroke-miterlimit",10),d.setAttribute("stroke","transparent"),d.setAttribute("fill","transparent"),d.setAttribute("transform",o);for(let f=0,g=i.length;f<g;f++){const p=this.svgFactory.createElement(this.svgElementName);l(this,yo).push(p),p.setAttribute("points",i[f].join(",")),d.append(p)}return!r&&this.hasPopupData&&this._createPopup(),this.container.append(u),this._editOnDoubleClick(),this.container}updateEdited(e){super.updateEdited(e);const{thickness:s,points:i,rect:n}=e,r=l(this,Jl);if(s>=0&&r.setAttribute("stroke-width",s||1),i)for(let o=0,h=l(this,yo).length;o<h;o++)l(this,yo)[o].setAttribute("points",i[o].join(","));if(n){const{transform:o,width:h,height:c}=w(this,Zl,Cp).call(this,this.data.rotation,n);r.parentElement.setAttribute("viewBox",`0 0 ${h} ${c}`),r.setAttribute("transform",o)}}getElementsToTriggerPopup(){return l(this,yo)}addHighlightArea(){this.container.classList.add("highlightArea")}}Jl=new WeakMap,yo=new WeakMap,Zl=new WeakSet,Cp=function(e,s){switch(e){case 90:return{transform:`rotate(90) translate(${-s[0]},${s[1]}) scale(1,-1)`,width:s[3]-s[1],height:s[2]-s[0]};case 180:return{transform:`rotate(180) translate(${-s[2]},${s[1]}) scale(1,-1)`,width:s[2]-s[0],height:s[3]-s[1]};case 270:return{transform:`rotate(270) translate(${-s[2]},${s[3]}) scale(1,-1)`,width:s[3]-s[1],height:s[2]-s[0]};default:return{transform:`translate(${-s[0]},${s[3]}) scale(1,-1)`,width:s[2]-s[0],height:s[3]-s[1]}}};class Hb extends jt{constructor(t){super(t,{isRenderable:!0,ignoreBorder:!0,createQuadrilaterals:!0}),this.annotationEditorType=tt.HIGHLIGHT}render(){return!this.data.popupRef&&this.hasPopupData&&this._createPopup(),this.container.classList.add("highlightAnnotation"),this._editOnDoubleClick(),this.container}}class ZS extends jt{constructor(t){super(t,{isRenderable:!0,ignoreBorder:!0,createQuadrilaterals:!0})}render(){return!this.data.popupRef&&this.hasPopupData&&this._createPopup(),this.container.classList.add("underlineAnnotation"),this.container}}class tC extends jt{constructor(t){super(t,{isRenderable:!0,ignoreBorder:!0,createQuadrilaterals:!0})}render(){return!this.data.popupRef&&this.hasPopupData&&this._createPopup(),this.container.classList.add("squigglyAnnotation"),this.container}}class eC extends jt{constructor(t){super(t,{isRenderable:!0,ignoreBorder:!0,createQuadrilaterals:!0})}render(){return!this.data.popupRef&&this.hasPopupData&&this._createPopup(),this.container.classList.add("strikeoutAnnotation"),this.container}}class Gb extends jt{constructor(t){super(t,{isRenderable:!0,ignoreBorder:!0}),this.annotationEditorType=tt.STAMP}render(){return this.container.classList.add("stampAnnotation"),this.container.setAttribute("role","img"),!this.data.popupRef&&this.hasPopupData&&this._createPopup(),this._editOnDoubleClick(),this.container}}class sC extends jt{constructor(e){var i;super(e,{isRenderable:!0});y(this,ec);y(this,tc,null);const{file:s}=this.data;this.filename=s.filename,this.content=s.content,(i=this.linkService.eventBus)==null||i.dispatch("fileattachmentannotation",{source:this,...s})}render(){this.container.classList.add("fileAttachmentAnnotation");const{container:e,data:s}=this;let i;s.hasAppearance||s.fillAlpha===0?i=document.createElement("div"):(i=document.createElement("img"),i.src=`${this.imageResourcesPath}annotation-${/paperclip/i.test(s.name)?"paperclip":"pushpin"}.svg`,s.fillAlpha&&s.fillAlpha<1&&(i.style=`filter: opacity(${Math.round(s.fillAlpha*100)}%);`)),i.addEventListener("dblclick",w(this,ec,Ap).bind(this)),m(this,tc,i);const{isMac:n}=Re.platform;return e.addEventListener("keydown",r=>{r.key==="Enter"&&(n?r.metaKey:r.ctrlKey)&&w(this,ec,Ap).call(this)}),!s.popupRef&&this.hasPopupData?this._createPopup():i.classList.add("popupTriggerArea"),e.append(i),e}getElementsToTriggerPopup(){return l(this,tc)}addHighlightArea(){this.container.classList.add("highlightArea")}}tc=new WeakMap,ec=new WeakSet,Ap=function(){var e;(e=this.downloadManager)==null||e.openOrDownloadData(this.content,this.filename)};class iC{constructor({div:t,accessibilityManager:e,annotationCanvasMap:s,annotationEditorUIManager:i,page:n,viewport:r,structTreeLayer:o}){y(this,wo);y(this,sc,null);y(this,vo,null);y(this,_o,new Map);y(this,ic,null);this.div=t,m(this,sc,e),m(this,vo,s),m(this,ic,o||null),this.page=n,this.viewport=r,this.zIndex=0,this._annotationEditorUIManager=i}hasEditableAnnotations(){return l(this,_o).size>0}async render(t){var r;const{annotations:e}=t,s=this.div;kr(s,this.viewport);const i=new Map,n={data:null,layer:s,linkService:t.linkService,downloadManager:t.downloadManager,imageResourcesPath:t.imageResourcesPath||"",renderForms:t.renderForms!==!1,svgFactory:new Dg,annotationStorage:t.annotationStorage||new xg,enableScripting:t.enableScripting===!0,hasJSActions:t.hasJSActions,fieldObjects:t.fieldObjects,parent:this,elements:null};for(const o of e){if(o.noHTML)continue;const h=o.annotationType===qt.POPUP;if(h){const d=i.get(o.id);if(!d)continue;n.elements=d}else{const{width:d,height:f}=Fn(o.rect);if(d<=0||f<=0)continue}n.data=o;const c=HS.create(n);if(!c.isRenderable)continue;if(!h&&o.popupRef){const d=i.get(o.popupRef);d?d.push(c):i.set(o.popupRef,[c])}const u=c.render();o.hidden&&(u.style.visibility="hidden"),await w(this,wo,Iy).call(this,u,o.id),c._isEditable&&(l(this,_o).set(c.data.id,c),(r=this._annotationEditorUIManager)==null||r.renderAnnotationElement(c))}w(this,wo,Tp).call(this)}update({viewport:t}){const e=this.div;this.viewport=t,kr(e,{rotation:t.rotation}),w(this,wo,Tp).call(this),e.hidden=!1}getEditableAnnotations(){return Array.from(l(this,_o).values())}getEditableAnnotation(t){return l(this,_o).get(t)}}sc=new WeakMap,vo=new WeakMap,_o=new WeakMap,ic=new WeakMap,wo=new WeakSet,Iy=async function(t,e){var r,o;const s=t.firstChild||t,i=s.id=`${dg}${e}`,n=await((r=l(this,ic))==null?void 0:r.getAriaAttributes(i));if(n)for(const[h,c]of n)s.setAttribute(h,c);this.div.append(t),(o=l(this,sc))==null||o.moveElementInDOM(this.div,t,s,!1)},Tp=function(){if(!l(this,vo))return;const t=this.div;for(const[e,s]of l(this,vo)){const i=t.querySelector(`[data-annotation-id="${e}"]`);if(!i)continue;s.className="annotationContent";const{firstChild:n}=i;n?n.nodeName==="CANVAS"?n.replaceWith(s):n.classList.contains("annotationContent")?n.after(s):n.before(s):i.append(s)}l(this,vo).clear()};const id=/\r\n?|\n/g,wt=class wt extends Pt{constructor(e){super({...e,name:"freeTextEditor"});y(this,Ut);y(this,qs);y(this,hs,"");y(this,nc,`${this.id}-editor`);y(this,xo,null);y(this,ls);m(this,qs,e.color||wt._defaultColor||Pt._defaultLineColor),m(this,ls,e.fontSize||wt._defaultFontSize)}static get _keyboardManager(){const e=wt.prototype,s=r=>r.isEmpty(),i=Mr.TRANSLATE_SMALL,n=Mr.TRANSLATE_BIG;return it(this,"_keyboardManager",new Wh([[["ctrl+s","mac+meta+s","ctrl+p","mac+meta+p"],e.commitOrRemove,{bubbles:!0}],[["ctrl+Enter","mac+meta+Enter","Escape","mac+Escape"],e.commitOrRemove],[["ArrowLeft","mac+ArrowLeft"],e._translateEmpty,{args:[-i,0],checker:s}],[["ctrl+ArrowLeft","mac+shift+ArrowLeft"],e._translateEmpty,{args:[-n,0],checker:s}],[["ArrowRight","mac+ArrowRight"],e._translateEmpty,{args:[i,0],checker:s}],[["ctrl+ArrowRight","mac+shift+ArrowRight"],e._translateEmpty,{args:[n,0],checker:s}],[["ArrowUp","mac+ArrowUp"],e._translateEmpty,{args:[0,-i],checker:s}],[["ctrl+ArrowUp","mac+shift+ArrowUp"],e._translateEmpty,{args:[0,-n],checker:s}],[["ArrowDown","mac+ArrowDown"],e._translateEmpty,{args:[0,i],checker:s}],[["ctrl+ArrowDown","mac+shift+ArrowDown"],e._translateEmpty,{args:[0,n],checker:s}]]))}static initialize(e,s){Pt.initialize(e,s);const i=getComputedStyle(document.documentElement);this._internalPadding=parseFloat(i.getPropertyValue("--freetext-padding"))}static updateDefaultParams(e,s){switch(e){case at.FREETEXT_SIZE:wt._defaultFontSize=s;break;case at.FREETEXT_COLOR:wt._defaultColor=s;break}}updateParams(e,s){switch(e){case at.FREETEXT_SIZE:w(this,Ut,Ny).call(this,s);break;case at.FREETEXT_COLOR:w(this,Ut,jy).call(this,s);break}}static get defaultPropertiesToUpdate(){return[[at.FREETEXT_SIZE,wt._defaultFontSize],[at.FREETEXT_COLOR,wt._defaultColor||Pt._defaultLineColor]]}get propertiesToUpdate(){return[[at.FREETEXT_SIZE,l(this,ls)],[at.FREETEXT_COLOR,l(this,qs)]]}_translateEmpty(e,s){this._uiManager.translateSelectedEditors(e,s,!0)}getInitialTranslation(){const e=this.parentScale;return[-wt._internalPadding*e,-(wt._internalPadding+l(this,ls))*e]}rebuild(){this.parent&&(super.rebuild(),this.div!==null&&(this.isAttachedToDOM||this.parent.add(this)))}enableEditMode(){if(this.isInEditMode())return;this.parent.setEditingState(!1),this.parent.updateToolbar(tt.FREETEXT),super.enableEditMode(),this.overlayDiv.classList.remove("enabled"),this.editorDiv.contentEditable=!0,this._isDraggable=!1,this.div.removeAttribute("aria-activedescendant"),m(this,xo,new AbortController);const e=this._uiManager.combinedSignal(l(this,xo));this.editorDiv.addEventListener("keydown",this.editorDivKeydown.bind(this),{signal:e}),this.editorDiv.addEventListener("focus",this.editorDivFocus.bind(this),{signal:e}),this.editorDiv.addEventListener("blur",this.editorDivBlur.bind(this),{signal:e}),this.editorDiv.addEventListener("input",this.editorDivInput.bind(this),{signal:e}),this.editorDiv.addEventListener("paste",this.editorDivPaste.bind(this),{signal:e})}disableEditMode(){var e;this.isInEditMode()&&(this.parent.setEditingState(!0),super.disableEditMode(),this.overlayDiv.classList.add("enabled"),this.editorDiv.contentEditable=!1,this.div.setAttribute("aria-activedescendant",l(this,nc)),this._isDraggable=!0,(e=l(this,xo))==null||e.abort(),m(this,xo,null),this.div.focus({preventScroll:!0}),this.isEditing=!1,this.parent.div.classList.add("freetextEditing"))}focusin(e){this._focusEventsAllowed&&(super.focusin(e),e.target!==this.editorDiv&&this.editorDiv.focus())}onceAdded(e){var s;this.width||(this.enableEditMode(),e&&this.editorDiv.focus(),(s=this._initialOptions)!=null&&s.isCentered&&this.center(),this._initialOptions=null)}isEmpty(){return!this.editorDiv||this.editorDiv.innerText.trim()===""}remove(){this.isEditing=!1,this.parent&&(this.parent.setEditingState(!0),this.parent.div.classList.add("freetextEditing")),super.remove()}commit(){if(!this.isInEditMode())return;super.commit(),this.disableEditMode();const e=l(this,hs),s=m(this,hs,w(this,Ut,By).call(this).trimEnd());if(e===s)return;const i=n=>{if(m(this,hs,n),!n){this.remove();return}w(this,Ut,Yd).call(this),this._uiManager.rebuild(this),w(this,Ut,Wd).call(this)};this.addCommands({cmd:()=>{i(s)},undo:()=>{i(e)},mustExec:!1}),w(this,Ut,Wd).call(this)}shouldGetKeyboardEvents(){return this.isInEditMode()}enterInEditMode(){this.enableEditMode(),this.editorDiv.focus()}dblclick(e){this.enterInEditMode()}keydown(e){e.target===this.div&&e.key==="Enter"&&(this.enterInEditMode(),e.preventDefault())}editorDivKeydown(e){wt._keyboardManager.exec(this,e)}editorDivFocus(e){this.isEditing=!0}editorDivBlur(e){this.isEditing=!1}editorDivInput(e){this.parent.div.classList.toggle("freetextEditing",this.isEmpty())}disableEditing(){this.editorDiv.setAttribute("role","comment"),this.editorDiv.removeAttribute("aria-multiline")}enableEditing(){this.editorDiv.setAttribute("role","textbox"),this.editorDiv.setAttribute("aria-multiline",!0)}render(){if(this.div)return this.div;let e,s;this.width&&(e=this.x,s=this.y),super.render(),this.editorDiv=document.createElement("div"),this.editorDiv.className="internal",this.editorDiv.setAttribute("id",l(this,nc)),this.editorDiv.setAttribute("data-l10n-id","pdfjs-free-text2"),this.editorDiv.setAttribute("data-l10n-attrs","default-content"),this.enableEditing(),this.editorDiv.contentEditable=!0;const{style:i}=this.editorDiv;if(i.fontSize=`calc(${l(this,ls)}px * var(--scale-factor))`,i.color=l(this,qs),this.div.append(this.editorDiv),this.overlayDiv=document.createElement("div"),this.overlayDiv.classList.add("overlay","enabled"),this.div.append(this.overlayDiv),qu(this,this.div,["dblclick","keydown"]),this.width){const[n,r]=this.parentDimensions;if(this.annotationElementId){const{position:o}=this._initialData;let[h,c]=this.getInitialTranslation();[h,c]=this.pageTranslationToScreen(h,c);const[u,d]=this.pageDimensions,[f,g]=this.pageTranslation;let p,b;switch(this.rotation){case 0:p=e+(o[0]-f)/u,b=s+this.height-(o[1]-g)/d;break;case 90:p=e+(o[0]-f)/u,b=s-(o[1]-g)/d,[h,c]=[c,-h];break;case 180:p=e-this.width+(o[0]-f)/u,b=s-(o[1]-g)/d,[h,c]=[-h,-c];break;case 270:p=e+(o[0]-f-this.height*d)/u,b=s+(o[1]-g-this.width*u)/d,[h,c]=[-c,h];break}this.setAt(p*n,b*r,h,c)}else this.setAt(e*n,s*r,this.width*n,this.height*r);w(this,Ut,Yd).call(this),this._isDraggable=!0,this.editorDiv.contentEditable=!1}else this._isDraggable=!1,this.editorDiv.contentEditable=!0;return this.div}editorDivPaste(e){var p,b,_;const s=e.clipboardData||window.clipboardData,{types:i}=s;if(i.length===1&&i[0]==="text/plain")return;e.preventDefault();const n=w(p=wt,fn,Ep).call(p,s.getData("text")||"").replaceAll(id,`
|
|
498
|
+
`}applyTo2d(t){let{imageData:{data:e}}=t;const s=-this.vibrance;for(let i=0;i<e.length;i+=4){const n=e[i],r=e[i+1],o=e[i+2],h=Math.max(n,r,o),c=(n+r+o)/3,u=2*Math.abs(h-c)/255*s;e[i]+=h!==n?(h-n)*u:0,e[i+1]+=h!==r?(h-r)*u:0,e[i+2]+=h!==o?(h-o)*u:0}}sendUniformData(t,e){t.uniform1f(e.uVibrance,-this.vibrance)}isNeutralState(){return this.vibrance===0}}A(Hu,"type","Vibrance"),A(Hu,"defaults",{vibrance:0}),A(Hu,"uniformLocations",["uVibrance"]),N.setClass(Hu);var Bh={};Bh.d=(a,t)=>{for(var e in t)Bh.o(t,e)&&!Bh.o(a,e)&&Object.defineProperty(a,e,{enumerable:!0,get:t[e]})},Bh.o=(a,t)=>Object.prototype.hasOwnProperty.call(a,t);var K=globalThis.pdfjsLib={};Bh.d(K,{AbortException:()=>Rn,AnnotationEditorLayer:()=>Gg,AnnotationEditorParamsType:()=>ot,AnnotationEditorType:()=>Z,AnnotationEditorUIManager:()=>Mr,AnnotationLayer:()=>zS,AnnotationMode:()=>Dn,ColorPicker:()=>rd,DOMSVGFactory:()=>Dg,DrawLayer:()=>zg,FeatureTest:()=>Re,GlobalWorkerOptions:()=>Vi,ImageKind:()=>Gu,InvalidPDFException:()=>hg,MissingPDFException:()=>Gh,OPS:()=>Hs,OutputScale:()=>bg,PDFDataRangeTransport:()=>Eb,PDFDateString:()=>pg,PDFWorker:()=>aa,PasswordResponses:()=>Qw,PermissionFlag:()=>Kw,PixelsPerInch:()=>Ln,RenderingCancelledException:()=>fg,TextLayer:()=>Yh,TouchManager:()=>Qu,UnexpectedResponseException:()=>Wu,Util:()=>W,VerbosityLevel:()=>zu,XfaLayer:()=>Db,build:()=>xS,createValidAbsoluteUrl:()=>ex,fetchData:()=>Yu,getDocument:()=>fS,getFilenameFromUrl:()=>cx,getPdfFilenameFromUrl:()=>ux,getXfaPageViewport:()=>dx,isDataScheme:()=>$u,isPdfFile:()=>gg,noContextMenu:()=>Gs,normalizeUnicode:()=>ax,setLayerDimensions:()=>kr,shadow:()=>st,stopEvent:()=>es,version:()=>wS});const ye=typeof process=="object"&&process+""=="[object process]"&&!process.versions.nw&&!(process.versions.electron&&process.type&&process.type!=="browser"),Y0=[1,0,0,1,0,0],rg=[.001,0,0,.001,0,0],$w=1e7,og=1.35,ts={ANY:1,DISPLAY:2,PRINT:4,ANNOTATIONS_FORMS:16,ANNOTATIONS_STORAGE:32,ANNOTATIONS_DISABLE:64,IS_EDITING:128,OPLIST:256},Dn={DISABLE:0,ENABLE:1,ENABLE_FORMS:2,ENABLE_STORAGE:3},qw="pdfjs_internal_editor_",Z={DISABLE:-1,NONE:0,FREETEXT:3,HIGHLIGHT:9,STAMP:13,INK:15},ot={RESIZE:1,CREATE:2,FREETEXT_SIZE:11,FREETEXT_COLOR:12,FREETEXT_OPACITY:13,INK_COLOR:21,INK_THICKNESS:22,INK_OPACITY:23,HIGHLIGHT_COLOR:31,HIGHLIGHT_DEFAULT_COLOR:32,HIGHLIGHT_THICKNESS:33,HIGHLIGHT_FREE:34,HIGHLIGHT_SHOW_ALL:35,DRAW_STEP:41},Kw={PRINT:4,MODIFY_CONTENTS:8,COPY:16,MODIFY_ANNOTATIONS:32,FILL_INTERACTIVE_FORMS:256,COPY_FOR_ACCESSIBILITY:512,ASSEMBLE:1024,PRINT_HIGH_QUALITY:2048},ve={FILL:0,STROKE:1,FILL_STROKE:2,INVISIBLE:3,FILL_STROKE_MASK:3,ADD_TO_PATH_FLAG:4},Gu={GRAYSCALE_1BPP:1,RGB_24BPP:2,RGBA_32BPP:3},qt={TEXT:1,LINK:2,FREETEXT:3,LINE:4,SQUARE:5,CIRCLE:6,POLYGON:7,POLYLINE:8,HIGHLIGHT:9,UNDERLINE:10,SQUIGGLY:11,STRIKEOUT:12,STAMP:13,CARET:14,INK:15,POPUP:16,FILEATTACHMENT:17,WIDGET:20},Hh={SOLID:1,DASHED:2,BEVELED:3,INSET:4,UNDERLINE:5},zu={ERRORS:0,WARNINGS:1,INFOS:5},Hs={dependency:1,setLineWidth:2,setLineCap:3,setLineJoin:4,setMiterLimit:5,setDash:6,setRenderingIntent:7,setFlatness:8,setGState:9,save:10,restore:11,transform:12,moveTo:13,lineTo:14,curveTo:15,curveTo2:16,curveTo3:17,closePath:18,rectangle:19,stroke:20,closeStroke:21,fill:22,eoFill:23,fillStroke:24,eoFillStroke:25,closeFillStroke:26,closeEOFillStroke:27,endPath:28,clip:29,eoClip:30,beginText:31,endText:32,setCharSpacing:33,setWordSpacing:34,setHScale:35,setLeading:36,setFont:37,setTextRenderingMode:38,setTextRise:39,moveText:40,setLeadingMoveText:41,setTextMatrix:42,nextLine:43,showText:44,showSpacedText:45,nextLineShowText:46,nextLineSetSpacingShowText:47,setCharWidth:48,setCharWidthAndBounds:49,setStrokeColorSpace:50,setFillColorSpace:51,setStrokeColor:52,setStrokeColorN:53,setFillColor:54,setFillColorN:55,setStrokeGray:56,setFillGray:57,setStrokeRGBColor:58,setFillRGBColor:59,setStrokeCMYKColor:60,setFillCMYKColor:61,shadingFill:62,beginInlineImage:63,beginImageData:64,endInlineImage:65,paintXObject:66,markPoint:67,markPointProps:68,beginMarkedContent:69,beginMarkedContentProps:70,endMarkedContent:71,beginCompat:72,endCompat:73,paintFormXObjectBegin:74,paintFormXObjectEnd:75,beginGroup:76,endGroup:77,beginAnnotation:80,endAnnotation:81,paintImageMaskXObject:83,paintImageMaskXObjectGroup:84,paintImageXObject:85,paintInlineImageXObject:86,paintInlineImageXObjectGroup:87,paintImageXObjectRepeat:88,paintImageMaskXObjectRepeat:89,paintSolidColorImageMask:90,constructPath:91,setStrokeTransparent:92,setFillTransparent:93},Qw={NEED_PASSWORD:1,INCORRECT_PASSWORD:2};let Vu=zu.WARNINGS;function Jw(a){Number.isInteger(a)&&(Vu=a)}function Zw(){return Vu}function Xu(a){Vu>=zu.INFOS&&console.log(`Info: ${a}`)}function tt(a){Vu>=zu.WARNINGS&&console.log(`Warning: ${a}`)}function vt(a){throw new Error(a)}function Xt(a,t){a||vt(t)}function tx(a){switch(a==null?void 0:a.protocol){case"http:":case"https:":case"ftp:":case"mailto:":case"tel:":return!0;default:return!1}}function ex(a,t=null,e=null){if(!a)return null;try{if(e&&typeof a=="string"){if(e.addDefaultProtocol&&a.startsWith("www.")){const i=a.match(/\./g);(i==null?void 0:i.length)>=2&&(a=`http://${a}`)}if(e.tryConvertEncoding)try{a=ox(a)}catch{}}const s=t?new URL(a,t):new URL(a);if(tx(s))return s}catch{}return null}function st(a,t,e,s=!1){return Object.defineProperty(a,t,{value:e,enumerable:!s,configurable:!0,writable:!1}),e}const On=function(){function t(e,s){this.message=e,this.name=s}return t.prototype=new Error,t.constructor=t,t}();class $0 extends On{constructor(t,e){super(t,"PasswordException"),this.code=e}}class ag extends On{constructor(t,e){super(t,"UnknownErrorException"),this.details=e}}class hg extends On{constructor(t){super(t,"InvalidPDFException")}}class Gh extends On{constructor(t){super(t,"MissingPDFException")}}class Wu extends On{constructor(t,e){super(t,"UnexpectedResponseException"),this.status=e}}class sx extends On{constructor(t){super(t,"FormatError")}}class Rn extends On{constructor(t){super(t,"AbortException")}}function q0(a){(typeof a!="object"||(a==null?void 0:a.length)===void 0)&&vt("Invalid argument for bytesToString");const t=a.length,e=8192;if(t<e)return String.fromCharCode.apply(null,a);const s=[];for(let i=0;i<t;i+=e){const n=Math.min(i+e,t),r=a.subarray(i,n);s.push(String.fromCharCode.apply(null,r))}return s.join("")}function Uu(a){typeof a!="string"&&vt("Invalid argument for stringToBytes");const t=a.length,e=new Uint8Array(t);for(let s=0;s<t;++s)e[s]=a.charCodeAt(s)&255;return e}function ix(a){return String.fromCharCode(a>>24&255,a>>16&255,a>>8&255,a&255)}function lg(a){const t=Object.create(null);for(const[e,s]of a)t[e]=s;return t}function nx(){const a=new Uint8Array(4);return a[0]=1,new Uint32Array(a.buffer,0,1)[0]===1}function rx(){try{return new Function(""),!0}catch{return!1}}class Re{static get isLittleEndian(){return st(this,"isLittleEndian",nx())}static get isEvalSupported(){return st(this,"isEvalSupported",rx())}static get isOffscreenCanvasSupported(){return st(this,"isOffscreenCanvasSupported",typeof OffscreenCanvas<"u")}static get isImageDecoderSupported(){return st(this,"isImageDecoderSupported",typeof ImageDecoder<"u")}static get platform(){return typeof navigator<"u"&&typeof(navigator==null?void 0:navigator.platform)=="string"?st(this,"platform",{isMac:navigator.platform.includes("Mac"),isWindows:navigator.platform.includes("Win"),isFirefox:typeof(navigator==null?void 0:navigator.userAgent)=="string"&&navigator.userAgent.includes("Firefox")}):st(this,"platform",{isMac:!1,isWindows:!1,isFirefox:!1})}static get isCSSRoundSupported(){var t,e;return st(this,"isCSSRoundSupported",(e=(t=globalThis.CSS)==null?void 0:t.supports)==null?void 0:e.call(t,"width: round(1.5px, 1px)"))}}const cg=Array.from(Array(256).keys(),a=>a.toString(16).padStart(2,"0"));class W{static makeHexColor(t,e,s){return`#${cg[t]}${cg[e]}${cg[s]}`}static scaleMinMax(t,e){let s;t[0]?(t[0]<0&&(s=e[0],e[0]=e[2],e[2]=s),e[0]*=t[0],e[2]*=t[0],t[3]<0&&(s=e[1],e[1]=e[3],e[3]=s),e[1]*=t[3],e[3]*=t[3]):(s=e[0],e[0]=e[1],e[1]=s,s=e[2],e[2]=e[3],e[3]=s,t[1]<0&&(s=e[1],e[1]=e[3],e[3]=s),e[1]*=t[1],e[3]*=t[1],t[2]<0&&(s=e[0],e[0]=e[2],e[2]=s),e[0]*=t[2],e[2]*=t[2]),e[0]+=t[4],e[1]+=t[5],e[2]+=t[4],e[3]+=t[5]}static transform(t,e){return[t[0]*e[0]+t[2]*e[1],t[1]*e[0]+t[3]*e[1],t[0]*e[2]+t[2]*e[3],t[1]*e[2]+t[3]*e[3],t[0]*e[4]+t[2]*e[5]+t[4],t[1]*e[4]+t[3]*e[5]+t[5]]}static applyTransform(t,e){const s=t[0]*e[0]+t[1]*e[2]+e[4],i=t[0]*e[1]+t[1]*e[3]+e[5];return[s,i]}static applyInverseTransform(t,e){const s=e[0]*e[3]-e[1]*e[2],i=(t[0]*e[3]-t[1]*e[2]+e[2]*e[5]-e[4]*e[3])/s,n=(-t[0]*e[1]+t[1]*e[0]+e[4]*e[1]-e[5]*e[0])/s;return[i,n]}static getAxialAlignedBoundingBox(t,e){const s=this.applyTransform(t,e),i=this.applyTransform(t.slice(2,4),e),n=this.applyTransform([t[0],t[3]],e),r=this.applyTransform([t[2],t[1]],e);return[Math.min(s[0],i[0],n[0],r[0]),Math.min(s[1],i[1],n[1],r[1]),Math.max(s[0],i[0],n[0],r[0]),Math.max(s[1],i[1],n[1],r[1])]}static inverseTransform(t){const e=t[0]*t[3]-t[1]*t[2];return[t[3]/e,-t[1]/e,-t[2]/e,t[0]/e,(t[2]*t[5]-t[4]*t[3])/e,(t[4]*t[1]-t[5]*t[0])/e]}static singularValueDecompose2dScale(t){const e=[t[0],t[2],t[1],t[3]],s=t[0]*e[0]+t[1]*e[2],i=t[0]*e[1]+t[1]*e[3],n=t[2]*e[0]+t[3]*e[2],r=t[2]*e[1]+t[3]*e[3],o=(s+r)/2,h=Math.sqrt((s+r)**2-4*(s*r-n*i))/2,c=o+h||1,u=o-h||1;return[Math.sqrt(c),Math.sqrt(u)]}static normalizeRect(t){const e=t.slice(0);return t[0]>t[2]&&(e[0]=t[2],e[2]=t[0]),t[1]>t[3]&&(e[1]=t[3],e[3]=t[1]),e}static intersect(t,e){const s=Math.max(Math.min(t[0],t[2]),Math.min(e[0],e[2])),i=Math.min(Math.max(t[0],t[2]),Math.max(e[0],e[2]));if(s>i)return null;const n=Math.max(Math.min(t[1],t[3]),Math.min(e[1],e[3])),r=Math.min(Math.max(t[1],t[3]),Math.max(e[1],e[3]));return n>r?null:[s,n,i,r]}static bezierBoundingBox(t,e,s,i,n,r,o,h,c){return c?(c[0]=Math.min(c[0],t,o),c[1]=Math.min(c[1],e,h),c[2]=Math.max(c[2],t,o),c[3]=Math.max(c[3],e,h)):c=[Math.min(t,o),Math.min(e,h),Math.max(t,o),Math.max(e,h)],w(this,Xi,Kg).call(this,t,s,n,o,e,i,r,h,3*(-t+3*(s-n)+o),6*(t-2*s+n),3*(s-t),c),w(this,Xi,Kg).call(this,t,s,n,o,e,i,r,h,3*(-e+3*(i-r)+h),6*(e-2*i+r),3*(i-e),c),c}}Xi=new WeakSet,kd=function(t,e,s,i,n,r,o,h,c,u){if(c<=0||c>=1)return;const d=1-c,f=c*c,g=f*c,p=d*(d*(d*t+3*c*e)+3*f*s)+g*i,b=d*(d*(d*n+3*c*r)+3*f*o)+g*h;u[0]=Math.min(u[0],p),u[1]=Math.min(u[1],b),u[2]=Math.max(u[2],p),u[3]=Math.max(u[3],b)},Kg=function(t,e,s,i,n,r,o,h,c,u,d,f){if(Math.abs(c)<1e-12){Math.abs(u)>=1e-12&&w(this,Xi,kd).call(this,t,e,s,i,n,r,o,h,-d/u,f);return}const g=u**2-4*d*c;if(g<0)return;const p=Math.sqrt(g),b=2*c;w(this,Xi,kd).call(this,t,e,s,i,n,r,o,h,(-u+p)/b,f),w(this,Xi,kd).call(this,t,e,s,i,n,r,o,h,(-u-p)/b,f)},y(W,Xi);function ox(a){return decodeURIComponent(escape(a))}let ug=null,K0=null;function ax(a){return ug||(ug=/([\u00a0\u00b5\u037e\u0eb3\u2000-\u200a\u202f\u2126\ufb00-\ufb04\ufb06\ufb20-\ufb36\ufb38-\ufb3c\ufb3e\ufb40-\ufb41\ufb43-\ufb44\ufb46-\ufba1\ufba4-\ufba9\ufbae-\ufbb1\ufbd3-\ufbdc\ufbde-\ufbe7\ufbea-\ufbf8\ufbfc-\ufbfd\ufc00-\ufc5d\ufc64-\ufcf1\ufcf5-\ufd3d\ufd88\ufdf4\ufdfa-\ufdfb\ufe71\ufe77\ufe79\ufe7b\ufe7d]+)|(\ufb05+)/gu,K0=new Map([["ſt","ſt"]])),a.replaceAll(ug,(t,e,s)=>e?e.normalize("NFKC"):K0.get(s))}function hx(){if(typeof crypto.randomUUID=="function")return crypto.randomUUID();const a=new Uint8Array(32);return crypto.getRandomValues(a),q0(a)}const dg="pdfjs_internal_id_";function lx(a){return Uint8Array.prototype.toBase64?a.toBase64():btoa(q0(a))}typeof Promise.try!="function"&&(Promise.try=function(a,...t){return new Promise(e=>{e(a(...t))})});const zi="http://www.w3.org/2000/svg",Or=class Or{};$(Or,"CSS",96),$(Or,"PDF",72),$(Or,"PDF_TO_CSS_UNITS",Or.CSS/Or.PDF);let Ln=Or;async function Yu(a,t="text"){if(Vh(a,document.baseURI)){const e=await fetch(a);if(!e.ok)throw new Error(e.statusText);switch(t){case"arraybuffer":return e.arrayBuffer();case"blob":return e.blob();case"json":return e.json()}return e.text()}return new Promise((e,s)=>{const i=new XMLHttpRequest;i.open("GET",a,!0),i.responseType=t,i.onreadystatechange=()=>{if(i.readyState===XMLHttpRequest.DONE){if(i.status===200||i.status===0){switch(t){case"arraybuffer":case"blob":case"json":e(i.response);return}e(i.responseText);return}s(new Error(i.statusText))}},i.send(null)})}class zh{constructor({viewBox:t,userUnit:e,scale:s,rotation:i,offsetX:n=0,offsetY:r=0,dontFlip:o=!1}){this.viewBox=t,this.userUnit=e,this.scale=s,this.rotation=i,this.offsetX=n,this.offsetY=r,s*=e;const h=(t[2]+t[0])/2,c=(t[3]+t[1])/2;let u,d,f,g;switch(i%=360,i<0&&(i+=360),i){case 180:u=-1,d=0,f=0,g=1;break;case 90:u=0,d=1,f=1,g=0;break;case 270:u=0,d=-1,f=-1,g=0;break;case 0:u=1,d=0,f=0,g=-1;break;default:throw new Error("PageViewport: Invalid rotation, must be a multiple of 90 degrees.")}o&&(f=-f,g=-g);let p,b,_,v;u===0?(p=Math.abs(c-t[1])*s+n,b=Math.abs(h-t[0])*s+r,_=(t[3]-t[1])*s,v=(t[2]-t[0])*s):(p=Math.abs(h-t[0])*s+n,b=Math.abs(c-t[1])*s+r,_=(t[2]-t[0])*s,v=(t[3]-t[1])*s),this.transform=[u*s,d*s,f*s,g*s,p-u*s*h-f*s*c,b-d*s*h-g*s*c],this.width=_,this.height=v}get rawDims(){const{userUnit:t,viewBox:e}=this,s=e.map(i=>i*t);return st(this,"rawDims",{pageWidth:s[2]-s[0],pageHeight:s[3]-s[1],pageX:s[0],pageY:s[1]})}clone({scale:t=this.scale,rotation:e=this.rotation,offsetX:s=this.offsetX,offsetY:i=this.offsetY,dontFlip:n=!1}={}){return new zh({viewBox:this.viewBox.slice(),userUnit:this.userUnit,scale:t,rotation:e,offsetX:s,offsetY:i,dontFlip:n})}convertToViewportPoint(t,e){return W.applyTransform([t,e],this.transform)}convertToViewportRectangle(t){const e=W.applyTransform([t[0],t[1]],this.transform),s=W.applyTransform([t[2],t[3]],this.transform);return[e[0],e[1],s[0],s[1]]}convertToPdfPoint(t,e){return W.applyInverseTransform([t,e],this.transform)}}class fg extends On{constructor(t,e=0){super(t,"RenderingCancelledException"),this.extraDelay=e}}function $u(a){const t=a.length;let e=0;for(;e<t&&a[e].trim()==="";)e++;return a.substring(e,e+5).toLowerCase()==="data:"}function gg(a){return typeof a=="string"&&/\.pdf$/i.test(a)}function cx(a){return[a]=a.split(/[#?]/,1),a.substring(a.lastIndexOf("/")+1)}function ux(a,t="document.pdf"){if(typeof a!="string")return t;if($u(a))return tt('getPdfFilenameFromUrl: ignore "data:"-URL for performance reasons.'),t;const e=/^(?:(?:[^:]+:)?\/\/[^/]+)?([^?#]*)(\?[^#]*)?(#.*)?$/,s=/[^/?#=]+\.pdf\b(?!.*\.pdf\b)/i,i=e.exec(a);let n=s.exec(i[1])||s.exec(i[2])||s.exec(i[3]);if(n&&(n=n[0],n.includes("%")))try{n=s.exec(decodeURIComponent(n))[0]}catch{}return n||t}class Q0{constructor(){$(this,"started",Object.create(null));$(this,"times",[])}time(t){t in this.started&&tt(`Timer is already running for ${t}`),this.started[t]=Date.now()}timeEnd(t){t in this.started||tt(`Timer has not been started for ${t}`),this.times.push({name:t,start:this.started[t],end:Date.now()}),delete this.started[t]}toString(){const t=[];let e=0;for(const{name:s}of this.times)e=Math.max(s.length,e);for(const{name:s,start:i,end:n}of this.times)t.push(`${s.padEnd(e)} ${n-i}ms
|
|
499
|
+
`);return t.join("")}}function Vh(a,t){try{const{protocol:e}=t?new URL(a,t):new URL(a);return e==="http:"||e==="https:"}catch{return!1}}function Gs(a){a.preventDefault()}function es(a){a.preventDefault(),a.stopPropagation()}class pg{static toDateObject(t){if(!t||typeof t!="string")return null;l(this,Zh)||m(this,Zh,new RegExp("^D:(\\d{4})(\\d{2})?(\\d{2})?(\\d{2})?(\\d{2})?(\\d{2})?([Z|+|-])?(\\d{2})?'?(\\d{2})?'?"));const e=l(this,Zh).exec(t);if(!e)return null;const s=parseInt(e[1],10);let i=parseInt(e[2],10);i=i>=1&&i<=12?i-1:0;let n=parseInt(e[3],10);n=n>=1&&n<=31?n:1;let r=parseInt(e[4],10);r=r>=0&&r<=23?r:0;let o=parseInt(e[5],10);o=o>=0&&o<=59?o:0;let h=parseInt(e[6],10);h=h>=0&&h<=59?h:0;const c=e[7]||"Z";let u=parseInt(e[8],10);u=u>=0&&u<=23?u:0;let d=parseInt(e[9],10)||0;return d=d>=0&&d<=59?d:0,c==="-"?(r+=u,o+=d):c==="+"&&(r-=u,o-=d),new Date(Date.UTC(s,i,n,r,o,h))}}Zh=new WeakMap,y(pg,Zh);function dx(a,{scale:t=1,rotation:e=0}){const{width:s,height:i}=a.attributes.style,n=[0,0,parseInt(s),parseInt(i)];return new zh({viewBox:n,userUnit:1,scale:t,rotation:e})}function mg(a){if(a.startsWith("#")){const t=parseInt(a.slice(1),16);return[(t&16711680)>>16,(t&65280)>>8,t&255]}return a.startsWith("rgb(")?a.slice(4,-1).split(",").map(t=>parseInt(t)):a.startsWith("rgba(")?a.slice(5,-1).split(",").map(t=>parseInt(t)).slice(0,3):(tt(`Not a valid color format: "${a}"`),[0,0,0])}function fx(a){const t=document.createElement("span");t.style.visibility="hidden",document.body.append(t);for(const e of a.keys()){t.style.color=e;const s=window.getComputedStyle(t).color;a.set(e,mg(s))}t.remove()}function Tt(a){const{a:t,b:e,c:s,d:i,e:n,f:r}=a.getTransform();return[t,e,s,i,n,r]}function li(a){const{a:t,b:e,c:s,d:i,e:n,f:r}=a.getTransform().invertSelf();return[t,e,s,i,n,r]}function kr(a,t,e=!1,s=!0){if(t instanceof zh){const{pageWidth:i,pageHeight:n}=t.rawDims,{style:r}=a,o=Re.isCSSRoundSupported,h=`var(--scale-factor) * ${i}px`,c=`var(--scale-factor) * ${n}px`,u=o?`round(down, ${h}, var(--scale-round-x, 1px))`:`calc(${h})`,d=o?`round(down, ${c}, var(--scale-round-y, 1px))`:`calc(${c})`;!e||t.rotation%180===0?(r.width=u,r.height=d):(r.width=d,r.height=u)}s&&a.setAttribute("data-main-rotation",t.rotation)}class bg{constructor(){const t=window.devicePixelRatio||1;this.sx=t,this.sy=t}get scaled(){return this.sx!==1||this.sy!==1}get symmetric(){return this.sx===this.sy}}const Wi=class Wi{constructor(t){y(this,Le);y(this,In,null);y(this,Rr,null);y(this,zs);y(this,Lr,null);y(this,tl,null);m(this,zs,t),l(Wi,el)||m(Wi,el,Object.freeze({freetext:"pdfjs-editor-remove-freetext-button",highlight:"pdfjs-editor-remove-highlight-button",ink:"pdfjs-editor-remove-ink-button",stamp:"pdfjs-editor-remove-stamp-button"}))}render(){const t=m(this,In,document.createElement("div"));t.classList.add("editToolbar","hidden"),t.setAttribute("role","toolbar");const e=l(this,zs)._uiManager._signal;t.addEventListener("contextmenu",Gs,{signal:e}),t.addEventListener("pointerdown",w(Wi,hd,qb),{signal:e});const s=m(this,Lr,document.createElement("div"));s.className="buttons",t.append(s);const i=l(this,zs).toolbarPosition;if(i){const{style:n}=t,r=l(this,zs)._uiManager.direction==="ltr"?1-i[0]:i[0];n.insetInlineEnd=`${100*r}%`,n.top=`calc(${100*i[1]}% + var(--editor-toolbar-vert-offset))`}return w(this,Le,Jb).call(this),t}get div(){return l(this,In)}hide(){var t;l(this,In).classList.add("hidden"),(t=l(this,Rr))==null||t.hideDropdown()}show(){var t;l(this,In).classList.remove("hidden"),(t=l(this,tl))==null||t.shown()}async addAltText(t){const e=await t.render();w(this,Le,Md).call(this,e),l(this,Lr).prepend(e,l(this,Le,Qg)),m(this,tl,t)}addColorPicker(t){m(this,Rr,t);const e=t.renderButton();w(this,Le,Md).call(this,e),l(this,Lr).prepend(e,l(this,Le,Qg))}remove(){var t;l(this,In).remove(),(t=l(this,Rr))==null||t.destroy(),m(this,Rr,null)}};In=new WeakMap,Rr=new WeakMap,zs=new WeakMap,Lr=new WeakMap,tl=new WeakMap,el=new WeakMap,hd=new WeakSet,qb=function(t){t.stopPropagation()},Le=new WeakSet,Kb=function(t){l(this,zs)._focusEventsAllowed=!1,es(t)},Qb=function(t){l(this,zs)._focusEventsAllowed=!0,es(t)},Md=function(t){const e=l(this,zs)._uiManager._signal;t.addEventListener("focusin",w(this,Le,Kb).bind(this),{capture:!0,signal:e}),t.addEventListener("focusout",w(this,Le,Qb).bind(this),{capture:!0,signal:e}),t.addEventListener("contextmenu",Gs,{signal:e})},Jb=function(){const{editorType:t,_uiManager:e}=l(this,zs),s=document.createElement("button");s.className="delete",s.tabIndex=0,s.setAttribute("data-l10n-id",l(Wi,el)[t]),w(this,Le,Md).call(this,s),s.addEventListener("click",i=>{e.delete()},{signal:e._signal}),l(this,Lr).append(s)},Qg=function(){const t=document.createElement("div");return t.className="divider",t},y(Wi,hd),y(Wi,el,null);let yg=Wi;class gx{constructor(t){y(this,Nn);y(this,sl,null);y(this,Fr,null);y(this,Ir);m(this,Ir,t)}show(t,e,s){const[i,n]=w(this,Nn,ty).call(this,e,s),{style:r}=l(this,Fr)||m(this,Fr,w(this,Nn,Zb).call(this));t.append(l(this,Fr)),r.insetInlineEnd=`${100*i}%`,r.top=`calc(${100*n}% + var(--editor-toolbar-vert-offset))`}hide(){l(this,Fr).remove()}}sl=new WeakMap,Fr=new WeakMap,Ir=new WeakMap,Nn=new WeakSet,Zb=function(){const t=m(this,Fr,document.createElement("div"));t.className="editToolbar",t.setAttribute("role","toolbar"),t.addEventListener("contextmenu",Gs,{signal:l(this,Ir)._signal});const e=m(this,sl,document.createElement("div"));return e.className="buttons",t.append(e),w(this,Nn,ey).call(this),t},ty=function(t,e){let s=0,i=0;for(const n of t){const r=n.y+n.height;if(r<s)continue;const o=n.x+(e?n.width:0);if(r>s){i=o,s=r;continue}e?o>i&&(i=o):o<i&&(i=o)}return[e?1-i:i,s]},ey=function(){const t=document.createElement("button");t.className="highlightButton",t.tabIndex=0,t.setAttribute("data-l10n-id","pdfjs-highlight-floating-button1");const e=document.createElement("span");t.append(e),e.className="visuallyHidden",e.setAttribute("data-l10n-id","pdfjs-highlight-floating-button-label");const s=l(this,Ir)._signal;t.addEventListener("contextmenu",Gs,{signal:s}),t.addEventListener("click",()=>{l(this,Ir).highlightSelection("floating_button")},{signal:s}),l(this,sl).append(t)};function qu(a,t,e){for(const s of e)t.addEventListener(s,a[s].bind(a))}class px{constructor(){y(this,ld,0)}get id(){return`${qw}${Ge(this,ld)._++}`}}ld=new WeakMap;const Vg=class Vg{constructor(){y(this,la);y(this,ha,hx());y(this,il,0);y(this,we,null)}static get _isSVGFittingCanvas(){const t='data:image/svg+xml;charset=UTF-8,<svg viewBox="0 0 1 1" width="1" height="1" xmlns="http://www.w3.org/2000/svg"><rect width="1" height="1" style="fill:red;"/></svg>',s=new OffscreenCanvas(1,3).getContext("2d",{willReadFrequently:!0}),i=new Image;i.src=t;const n=i.decode().then(()=>(s.drawImage(i,0,0,1,1,0,0,1,3),new Uint32Array(s.getImageData(0,0,1,1).data.buffer)[0]===0));return st(this,"_isSVGFittingCanvas",n)}async getFromFile(t){const{lastModified:e,name:s,size:i,type:n}=t;return w(this,la,Pd).call(this,`${e}_${s}_${i}_${n}`,t)}async getFromUrl(t){return w(this,la,Pd).call(this,t,t)}async getFromBlob(t,e){const s=await e;return w(this,la,Pd).call(this,t,s)}async getFromId(t){l(this,we)||m(this,we,new Map);const e=l(this,we).get(t);if(!e)return null;if(e.bitmap)return e.refCounter+=1,e;if(e.file)return this.getFromFile(e.file);if(e.blobPromise){const{blobPromise:s}=e;return delete e.blobPromise,this.getFromBlob(e.id,s)}return this.getFromUrl(e.url)}getFromCanvas(t,e){l(this,we)||m(this,we,new Map);let s=l(this,we).get(t);if(s!=null&&s.bitmap)return s.refCounter+=1,s;const i=new OffscreenCanvas(e.width,e.height);return i.getContext("2d").drawImage(e,0,0),s={bitmap:i.transferToImageBitmap(),id:`image_${l(this,ha)}_${Ge(this,il)._++}`,refCounter:1,isSvg:!1},l(this,we).set(t,s),l(this,we).set(s.id,s),s}getSvgUrl(t){const e=l(this,we).get(t);return e!=null&&e.isSvg?e.svgUrl:null}deleteId(t){var i;l(this,we)||m(this,we,new Map);const e=l(this,we).get(t);if(!e||(e.refCounter-=1,e.refCounter!==0))return;const{bitmap:s}=e;if(!e.url&&!e.file){const n=new OffscreenCanvas(s.width,s.height);n.getContext("bitmaprenderer").transferFromImageBitmap(s),e.blobPromise=n.convertToBlob()}(i=s.close)==null||i.call(s),e.bitmap=null}isValidId(t){return t.startsWith(`image_${l(this,ha)}_`)}};ha=new WeakMap,il=new WeakMap,we=new WeakMap,la=new WeakSet,Pd=async function(t,e){l(this,we)||m(this,we,new Map);let s=l(this,we).get(t);if(s===null)return null;if(s!=null&&s.bitmap)return s.refCounter+=1,s;try{s||(s={bitmap:null,id:`image_${l(this,ha)}_${Ge(this,il)._++}`,refCounter:0,isSvg:!1});let i;if(typeof e=="string"?(s.url=e,i=await Yu(e,"blob")):e instanceof File?i=s.file=e:e instanceof Blob&&(i=e),i.type==="image/svg+xml"){const n=Vg._isSVGFittingCanvas,r=new FileReader,o=new Image,h=new Promise((c,u)=>{o.onload=()=>{s.bitmap=o,s.isSvg=!0,c()},r.onload=async()=>{const d=s.svgUrl=r.result;o.src=await n?`${d}#svgView(preserveAspectRatio(none))`:d},o.onerror=r.onerror=u});r.readAsDataURL(i),await h}else s.bitmap=await createImageBitmap(i);s.refCounter=1}catch(i){tt(i),s=null}return l(this,we).set(t,s),s&&l(this,we).set(s.id,s),s};let vg=Vg;class mx{constructor(t=128){y(this,Bt,[]);y(this,jn,!1);y(this,nl);y(this,Dt,-1);m(this,nl,t)}add({cmd:t,undo:e,post:s,mustExec:i,type:n=NaN,overwriteIfSameType:r=!1,keepUndo:o=!1}){if(i&&t(),l(this,jn))return;const h={cmd:t,undo:e,post:s,type:n};if(l(this,Dt)===-1){l(this,Bt).length>0&&(l(this,Bt).length=0),m(this,Dt,0),l(this,Bt).push(h);return}if(r&&l(this,Bt)[l(this,Dt)].type===n){o&&(h.undo=l(this,Bt)[l(this,Dt)].undo),l(this,Bt)[l(this,Dt)]=h;return}const c=l(this,Dt)+1;c===l(this,nl)?l(this,Bt).splice(0,1):(m(this,Dt,c),c<l(this,Bt).length&&l(this,Bt).splice(c)),l(this,Bt).push(h)}undo(){if(l(this,Dt)===-1)return;m(this,jn,!0);const{undo:t,post:e}=l(this,Bt)[l(this,Dt)];t(),e==null||e(),m(this,jn,!1),m(this,Dt,l(this,Dt)-1)}redo(){if(l(this,Dt)<l(this,Bt).length-1){m(this,Dt,l(this,Dt)+1),m(this,jn,!0);const{cmd:t,post:e}=l(this,Bt)[l(this,Dt)];t(),e==null||e(),m(this,jn,!1)}}hasSomethingToUndo(){return l(this,Dt)!==-1}hasSomethingToRedo(){return l(this,Dt)<l(this,Bt).length-1}cleanType(t){if(l(this,Dt)!==-1){for(let e=l(this,Dt);e>=0;e--)if(l(this,Bt)[e].type!==t){l(this,Bt).splice(e+1,l(this,Dt)-e),m(this,Dt,e);return}l(this,Bt).length=0,m(this,Dt,-1)}}destroy(){m(this,Bt,null)}}Bt=new WeakMap,jn=new WeakMap,nl=new WeakMap,Dt=new WeakMap;class Xh{constructor(t){y(this,cd);this.buffer=[],this.callbacks=new Map,this.allKeys=new Set;const{isMac:e}=Re.platform;for(const[s,i,n={}]of t)for(const r of s){const o=r.startsWith("mac+");e&&o?(this.callbacks.set(r.slice(4),{callback:i,options:n}),this.allKeys.add(r.split("+").at(-1))):!e&&!o&&(this.callbacks.set(r,{callback:i,options:n}),this.allKeys.add(r.split("+").at(-1)))}}exec(t,e){if(!this.allKeys.has(e.key))return;const s=this.callbacks.get(w(this,cd,sy).call(this,e));if(!s)return;const{callback:i,options:{bubbles:n=!1,args:r=[],checker:o=null}}=s;o&&!o(t,e)||(i.bind(t,...r,e)(),n||es(e))}}cd=new WeakSet,sy=function(t){t.altKey&&this.buffer.push("alt"),t.ctrlKey&&this.buffer.push("ctrl"),t.metaKey&&this.buffer.push("meta"),t.shiftKey&&this.buffer.push("shift"),this.buffer.push(t.key);const e=this.buffer.join("+");return this.buffer.length=0,e};const ud=class ud{get _colors(){const t=new Map([["CanvasText",null],["Canvas",null]]);return fx(t),st(this,"_colors",t)}convert(t){const e=mg(t);if(!window.matchMedia("(forced-colors: active)").matches)return e;for(const[s,i]of this._colors)if(i.every((n,r)=>n===e[r]))return ud._colorsMapping.get(s);return e}getHexCode(t){const e=this._colors.get(t);return e?W.makeHexColor(...e):t}};$(ud,"_colorsMapping",new Map([["CanvasText",[0,0,0]],["Canvas",[255,255,255]]]));let _g=ud;const ma=class ma{constructor(t,e,s,i,n,r,o,h,c,u,d,f,g){y(this,I);y(this,ca,new AbortController);y(this,ss,null);y(this,Kt,new Map);y(this,ae,new Map);y(this,ua,null);y(this,Ui,null);y(this,da,null);y(this,ws,new mx);y(this,Bn,null);y(this,Nr,null);y(this,fa,0);y(this,jr,new Set);y(this,ui,null);y(this,Vs,null);y(this,Br,new Set);$(this,"_editorUndoBar",null);y(this,rl,!1);y(this,ol,!1);y(this,ga,!1);y(this,al,null);y(this,di,null);y(this,Hn,null);y(this,pa,null);y(this,Gn,!1);y(this,fi,null);y(this,dd,new px);y(this,zn,!1);y(this,hl,!1);y(this,Vn,null);y(this,Hr,null);y(this,ll,null);y(this,cl,null);y(this,ee,Z.NONE);y(this,pt,new Set);y(this,Yi,null);y(this,Gr,null);y(this,ul,null);y(this,dl,{isEditing:!1,isEmpty:!0,hasSomethingToUndo:!1,hasSomethingToRedo:!1,hasSelectedEditor:!1,hasSelectedText:!1});y(this,Xn,[0,0]);y(this,gi,null);y(this,$i,null);y(this,fl,null);y(this,xs,null);const p=this._signal=l(this,ca).signal;m(this,$i,t),m(this,fl,e),m(this,ua,s),this._eventBus=i,i._on("editingaction",this.onEditingAction.bind(this),{signal:p}),i._on("pagechanging",this.onPageChanging.bind(this),{signal:p}),i._on("scalechanging",this.onScaleChanging.bind(this),{signal:p}),i._on("rotationchanging",this.onRotationChanging.bind(this),{signal:p}),i._on("setpreference",this.onSetPreference.bind(this),{signal:p}),i._on("switchannotationeditorparams",b=>this.updateParams(b.type,b.value),{signal:p}),w(this,I,ry).call(this),w(this,I,ly).call(this),w(this,I,Zg).call(this),m(this,Ui,n.annotationStorage),m(this,al,n.filterFactory),m(this,Gr,r),m(this,pa,o||null),m(this,rl,h),m(this,ol,c),m(this,ga,u),m(this,cl,d||null),this.viewParameters={realScale:Ln.PDF_TO_CSS_UNITS,rotation:0},this.isShiftKeyDown=!1,this._editorUndoBar=f||null,this._supportsPinchToZoom=g!==!1}static get _keyboardManager(){const t=ma.prototype,e=r=>l(r,$i).contains(document.activeElement)&&document.activeElement.tagName!=="BUTTON"&&r.hasSomethingToControl(),s=(r,{target:o})=>{if(o instanceof HTMLInputElement){const{type:h}=o;return h!=="text"&&h!=="number"}return!0},i=this.TRANSLATE_SMALL,n=this.TRANSLATE_BIG;return st(this,"_keyboardManager",new Xh([[["ctrl+a","mac+meta+a"],t.selectAll,{checker:s}],[["ctrl+z","mac+meta+z"],t.undo,{checker:s}],[["ctrl+y","ctrl+shift+z","mac+meta+shift+z","ctrl+shift+Z","mac+meta+shift+Z"],t.redo,{checker:s}],[["Backspace","alt+Backspace","ctrl+Backspace","shift+Backspace","mac+Backspace","mac+alt+Backspace","mac+ctrl+Backspace","Delete","ctrl+Delete","shift+Delete","mac+Delete"],t.delete,{checker:s}],[["Enter","mac+Enter"],t.addNewEditorFromKeyboard,{checker:(r,{target:o})=>!(o instanceof HTMLButtonElement)&&l(r,$i).contains(o)&&!r.isEnterHandled}],[[" ","mac+ "],t.addNewEditorFromKeyboard,{checker:(r,{target:o})=>!(o instanceof HTMLButtonElement)&&l(r,$i).contains(document.activeElement)}],[["Escape","mac+Escape"],t.unselectAll],[["ArrowLeft","mac+ArrowLeft"],t.translateSelectedEditors,{args:[-i,0],checker:e}],[["ctrl+ArrowLeft","mac+shift+ArrowLeft"],t.translateSelectedEditors,{args:[-n,0],checker:e}],[["ArrowRight","mac+ArrowRight"],t.translateSelectedEditors,{args:[i,0],checker:e}],[["ctrl+ArrowRight","mac+shift+ArrowRight"],t.translateSelectedEditors,{args:[n,0],checker:e}],[["ArrowUp","mac+ArrowUp"],t.translateSelectedEditors,{args:[0,-i],checker:e}],[["ctrl+ArrowUp","mac+shift+ArrowUp"],t.translateSelectedEditors,{args:[0,-n],checker:e}],[["ArrowDown","mac+ArrowDown"],t.translateSelectedEditors,{args:[0,i],checker:e}],[["ctrl+ArrowDown","mac+shift+ArrowDown"],t.translateSelectedEditors,{args:[0,n],checker:e}]]))}destroy(){var t,e,s,i,n;(t=l(this,xs))==null||t.resolve(),m(this,xs,null),(e=l(this,ca))==null||e.abort(),m(this,ca,null),this._signal=null;for(const r of l(this,ae).values())r.destroy();l(this,ae).clear(),l(this,Kt).clear(),l(this,Br).clear(),m(this,ss,null),l(this,pt).clear(),l(this,ws).destroy(),(s=l(this,ua))==null||s.destroy(),(i=l(this,fi))==null||i.hide(),m(this,fi,null),l(this,di)&&(clearTimeout(l(this,di)),m(this,di,null)),l(this,gi)&&(clearTimeout(l(this,gi)),m(this,gi,null)),(n=this._editorUndoBar)==null||n.destroy()}combinedSignal(t){return AbortSignal.any([this._signal,t.signal])}get mlManager(){return l(this,cl)}get useNewAltTextFlow(){return l(this,ol)}get useNewAltTextWhenAddingImage(){return l(this,ga)}get hcmFilter(){return st(this,"hcmFilter",l(this,Gr)?l(this,al).addHCMFilter(l(this,Gr).foreground,l(this,Gr).background):"none")}get direction(){return st(this,"direction",getComputedStyle(l(this,$i)).direction)}get highlightColors(){return st(this,"highlightColors",l(this,pa)?new Map(l(this,pa).split(",").map(t=>t.split("=").map(e=>e.trim()))):null)}get highlightColorNames(){return st(this,"highlightColorNames",this.highlightColors?new Map(Array.from(this.highlightColors,t=>t.reverse())):null)}setCurrentDrawingSession(t){t?(this.unselectAll(),this.disableUserSelect(!0)):this.disableUserSelect(!1),m(this,Nr,t)}setMainHighlightColorPicker(t){m(this,ll,t)}editAltText(t,e=!1){var s;(s=l(this,ua))==null||s.editAltText(this,t,e)}switchToMode(t,e){this._eventBus.on("annotationeditormodechanged",e,{once:!0,signal:this._signal}),this._eventBus.dispatch("showannotationeditorui",{source:this,mode:t})}setPreference(t,e){this._eventBus.dispatch("setpreference",{source:this,name:t,value:e})}onSetPreference({name:t,value:e}){switch(t){case"enableNewAltTextWhenAddingImage":m(this,ga,e);break}}onPageChanging({pageNumber:t}){m(this,fa,t-1)}focusMainContainer(){l(this,$i).focus()}findParent(t,e){for(const s of l(this,ae).values()){const{x:i,y:n,width:r,height:o}=s.div.getBoundingClientRect();if(t>=i&&t<=i+r&&e>=n&&e<=n+o)return s}return null}disableUserSelect(t=!1){l(this,fl).classList.toggle("noUserSelect",t)}addShouldRescale(t){l(this,Br).add(t)}removeShouldRescale(t){l(this,Br).delete(t)}onScaleChanging({scale:t}){var e;this.commitOrRemove(),this.viewParameters.realScale=t*Ln.PDF_TO_CSS_UNITS;for(const s of l(this,Br))s.onScaleChanging();(e=l(this,Nr))==null||e.onScaleChanging()}onRotationChanging({pagesRotation:t}){this.commitOrRemove(),this.viewParameters.rotation=t}highlightSelection(t=""){const e=document.getSelection();if(!e||e.isCollapsed)return;const{anchorNode:s,anchorOffset:i,focusNode:n,focusOffset:r}=e,o=e.toString(),c=w(this,I,Dd).call(this,e).closest(".textLayer"),u=this.getSelectionBoxes(c);if(!u)return;e.empty();const d=w(this,I,Jg).call(this,c),f=l(this,ee)===Z.NONE,g=()=>{d==null||d.createAndAddNewEditor({x:0,y:0},!1,{methodOfCreation:t,boxes:u,anchorNode:s,anchorOffset:i,focusNode:n,focusOffset:r,text:o}),f&&this.showAllEditors("highlight",!0,!0)};if(f){this.switchToMode(Z.HIGHLIGHT,g);return}g()}addToAnnotationStorage(t){!t.isEmpty()&&l(this,Ui)&&!l(this,Ui).has(t.id)&&l(this,Ui).setValue(t.id,t)}blur(){if(this.isShiftKeyDown=!1,l(this,Gn)&&(m(this,Gn,!1),w(this,I,Od).call(this,"main_toolbar")),!this.hasSelection)return;const{activeElement:t}=document;for(const e of l(this,pt))if(e.div.contains(t)){m(this,Hr,[e,t]),e._focusEventsAllowed=!1;break}}focus(){if(!l(this,Hr))return;const[t,e]=l(this,Hr);m(this,Hr,null),e.addEventListener("focusin",()=>{t._focusEventsAllowed=!0},{once:!0,signal:this._signal}),e.focus()}addEditListeners(){w(this,I,Zg).call(this),w(this,I,tp).call(this)}removeEditListeners(){w(this,I,hy).call(this),w(this,I,ep).call(this)}dragOver(t){for(const{type:e}of t.dataTransfer.items)for(const s of l(this,Vs))if(s.isHandlingMimeForPasting(e)){t.dataTransfer.dropEffect="copy",t.preventDefault();return}}drop(t){for(const e of t.dataTransfer.items)for(const s of l(this,Vs))if(s.isHandlingMimeForPasting(e.type)){s.paste(e,this.currentLayer),t.preventDefault();return}}copy(t){var s;if(t.preventDefault(),(s=l(this,ss))==null||s.commitOrRemove(),!this.hasSelection)return;const e=[];for(const i of l(this,pt)){const n=i.serialize(!0);n&&e.push(n)}e.length!==0&&t.clipboardData.setData("application/pdfjs",JSON.stringify(e))}cut(t){this.copy(t),this.delete()}async paste(t){t.preventDefault();const{clipboardData:e}=t;for(const n of e.items)for(const r of l(this,Vs))if(r.isHandlingMimeForPasting(n.type)){r.paste(n,this.currentLayer);return}let s=e.getData("application/pdfjs");if(!s)return;try{s=JSON.parse(s)}catch(n){tt(`paste: "${n.message}".`);return}if(!Array.isArray(s))return;this.unselectAll();const i=this.currentLayer;try{const n=[];for(const h of s){const c=await i.deserialize(h);if(!c)return;n.push(c)}const r=()=>{for(const h of n)w(this,I,sp).call(this,h);w(this,I,ip).call(this,n)},o=()=>{for(const h of n)h.remove()};this.addCommands({cmd:r,undo:o,mustExec:!0})}catch(n){tt(`paste: "${n.message}".`)}}keydown(t){!this.isShiftKeyDown&&t.key==="Shift"&&(this.isShiftKeyDown=!0),l(this,ee)!==Z.NONE&&!this.isEditorHandlingKeyboard&&ma._keyboardManager.exec(this,t)}keyup(t){this.isShiftKeyDown&&t.key==="Shift"&&(this.isShiftKeyDown=!1,l(this,Gn)&&(m(this,Gn,!1),w(this,I,Od).call(this,"main_toolbar")))}onEditingAction({name:t}){switch(t){case"undo":case"redo":case"delete":case"selectAll":this[t]();break;case"highlightSelection":this.highlightSelection("context_menu");break}}setEditingState(t){t?(w(this,I,oy).call(this),w(this,I,tp).call(this),w(this,I,ze).call(this,{isEditing:l(this,ee)!==Z.NONE,isEmpty:w(this,I,Ac).call(this),hasSomethingToUndo:l(this,ws).hasSomethingToUndo(),hasSomethingToRedo:l(this,ws).hasSomethingToRedo(),hasSelectedEditor:!1})):(w(this,I,ay).call(this),w(this,I,ep).call(this),w(this,I,ze).call(this,{isEditing:!1}),this.disableUserSelect(!1))}registerEditorTypes(t){if(!l(this,Vs)){m(this,Vs,t);for(const e of l(this,Vs))w(this,I,xn).call(this,e.defaultPropertiesToUpdate)}}getId(){return l(this,dd).id}get currentLayer(){return l(this,ae).get(l(this,fa))}getLayer(t){return l(this,ae).get(t)}get currentPageIndex(){return l(this,fa)}addLayer(t){l(this,ae).set(t.pageIndex,t),l(this,zn)?t.enable():t.disable()}removeLayer(t){l(this,ae).delete(t.pageIndex)}async updateMode(t,e=null,s=!1){var i;if(l(this,ee)!==t&&!(l(this,xs)&&(await l(this,xs).promise,!l(this,xs)))){if(m(this,xs,Promise.withResolvers()),m(this,ee,t),t===Z.NONE){this.setEditingState(!1),w(this,I,uy).call(this),(i=this._editorUndoBar)==null||i.hide(),l(this,xs).resolve();return}this.setEditingState(!0),await w(this,I,cy).call(this),this.unselectAll();for(const n of l(this,ae).values())n.updateMode(t);if(!e){s&&this.addNewEditorFromKeyboard(),l(this,xs).resolve();return}for(const n of l(this,Kt).values())n.annotationElementId===e?(this.setSelected(n),n.enterInEditMode()):n.unselect();l(this,xs).resolve()}}addNewEditorFromKeyboard(){this.currentLayer.canCreateNewEmptyEditor()&&this.currentLayer.addNewEditor()}updateToolbar(t){t!==l(this,ee)&&this._eventBus.dispatch("switchannotationeditormode",{source:this,mode:t})}updateParams(t,e){var s;if(l(this,Vs)){switch(t){case ot.CREATE:this.currentLayer.addNewEditor();return;case ot.HIGHLIGHT_DEFAULT_COLOR:(s=l(this,ll))==null||s.updateColor(e);break;case ot.HIGHLIGHT_SHOW_ALL:this._eventBus.dispatch("reporttelemetry",{source:this,details:{type:"editing",data:{type:"highlight",action:"toggle_visibility"}}}),(l(this,ul)||m(this,ul,new Map)).set(t,e),this.showAllEditors("highlight",e);break}for(const i of l(this,pt))i.updateParams(t,e);for(const i of l(this,Vs))i.updateDefaultParams(t,e)}}showAllEditors(t,e,s=!1){var n;for(const r of l(this,Kt).values())r.editorType===t&&r.show(e);(((n=l(this,ul))==null?void 0:n.get(ot.HIGHLIGHT_SHOW_ALL))??!0)!==e&&w(this,I,xn).call(this,[[ot.HIGHLIGHT_SHOW_ALL,e]])}enableWaiting(t=!1){if(l(this,hl)!==t){m(this,hl,t);for(const e of l(this,ae).values())t?e.disableClick():e.enableClick(),e.div.classList.toggle("waiting",t)}}getEditors(t){const e=[];for(const s of l(this,Kt).values())s.pageIndex===t&&e.push(s);return e}getEditor(t){return l(this,Kt).get(t)}addEditor(t){l(this,Kt).set(t.id,t)}removeEditor(t){var e;t.div.contains(document.activeElement)&&(l(this,di)&&clearTimeout(l(this,di)),m(this,di,setTimeout(()=>{this.focusMainContainer(),m(this,di,null)},0))),l(this,Kt).delete(t.id),this.unselect(t),(!t.annotationElementId||!l(this,jr).has(t.annotationElementId))&&((e=l(this,Ui))==null||e.remove(t.id))}addDeletedAnnotationElement(t){l(this,jr).add(t.annotationElementId),this.addChangedExistingAnnotation(t),t.deleted=!0}isDeletedAnnotationElement(t){return l(this,jr).has(t)}removeDeletedAnnotationElement(t){l(this,jr).delete(t.annotationElementId),this.removeChangedExistingAnnotation(t),t.deleted=!1}setActiveEditor(t){l(this,ss)!==t&&(m(this,ss,t),t&&w(this,I,xn).call(this,t.propertiesToUpdate))}updateUI(t){l(this,I,dy)===t&&w(this,I,xn).call(this,t.propertiesToUpdate)}updateUIForDefaultProperties(t){w(this,I,xn).call(this,t.defaultPropertiesToUpdate)}toggleSelected(t){if(l(this,pt).has(t)){l(this,pt).delete(t),t.unselect(),w(this,I,ze).call(this,{hasSelectedEditor:this.hasSelection});return}l(this,pt).add(t),t.select(),w(this,I,xn).call(this,t.propertiesToUpdate),w(this,I,ze).call(this,{hasSelectedEditor:!0})}setSelected(t){var e;(e=l(this,Nr))==null||e.commitOrRemove();for(const s of l(this,pt))s!==t&&s.unselect();l(this,pt).clear(),l(this,pt).add(t),t.select(),w(this,I,xn).call(this,t.propertiesToUpdate),w(this,I,ze).call(this,{hasSelectedEditor:!0})}isSelected(t){return l(this,pt).has(t)}get firstSelectedEditor(){return l(this,pt).values().next().value}unselect(t){t.unselect(),l(this,pt).delete(t),w(this,I,ze).call(this,{hasSelectedEditor:this.hasSelection})}get hasSelection(){return l(this,pt).size!==0}get isEnterHandled(){return l(this,pt).size===1&&this.firstSelectedEditor.isEnterHandled}undo(){var t;l(this,ws).undo(),w(this,I,ze).call(this,{hasSomethingToUndo:l(this,ws).hasSomethingToUndo(),hasSomethingToRedo:!0,isEmpty:w(this,I,Ac).call(this)}),(t=this._editorUndoBar)==null||t.hide()}redo(){l(this,ws).redo(),w(this,I,ze).call(this,{hasSomethingToUndo:!0,hasSomethingToRedo:l(this,ws).hasSomethingToRedo(),isEmpty:w(this,I,Ac).call(this)})}addCommands(t){l(this,ws).add(t),w(this,I,ze).call(this,{hasSomethingToUndo:!0,hasSomethingToRedo:!1,isEmpty:w(this,I,Ac).call(this)})}cleanUndoStack(t){l(this,ws).cleanType(t)}delete(){var n;this.commitOrRemove();const t=(n=this.currentLayer)==null?void 0:n.endDrawingSession(!0);if(!this.hasSelection&&!t)return;const e=t?[t]:[...l(this,pt)],s=()=>{var r;(r=this._editorUndoBar)==null||r.show(i,e.length===1?e[0].editorType:e.length);for(const o of e)o.remove()},i=()=>{for(const r of e)w(this,I,sp).call(this,r)};this.addCommands({cmd:s,undo:i,mustExec:!0})}commitOrRemove(){var t;(t=l(this,ss))==null||t.commitOrRemove()}hasSomethingToControl(){return l(this,ss)||this.hasSelection}selectAll(){for(const t of l(this,pt))t.commit();w(this,I,ip).call(this,l(this,Kt).values())}unselectAll(){var t;if(!(l(this,ss)&&(l(this,ss).commitOrRemove(),l(this,ee)!==Z.NONE))&&!((t=l(this,Nr))!=null&&t.commitOrRemove())&&this.hasSelection){for(const e of l(this,pt))e.unselect();l(this,pt).clear(),w(this,I,ze).call(this,{hasSelectedEditor:!1})}}translateSelectedEditors(t,e,s=!1){if(s||this.commitOrRemove(),!this.hasSelection)return;l(this,Xn)[0]+=t,l(this,Xn)[1]+=e;const[i,n]=l(this,Xn),r=[...l(this,pt)],o=1e3;l(this,gi)&&clearTimeout(l(this,gi)),m(this,gi,setTimeout(()=>{m(this,gi,null),l(this,Xn)[0]=l(this,Xn)[1]=0,this.addCommands({cmd:()=>{for(const h of r)l(this,Kt).has(h.id)&&h.translateInPage(i,n)},undo:()=>{for(const h of r)l(this,Kt).has(h.id)&&h.translateInPage(-i,-n)},mustExec:!1})},o));for(const h of r)h.translateInPage(t,e)}setUpDragSession(){if(this.hasSelection){this.disableUserSelect(!0),m(this,ui,new Map);for(const t of l(this,pt))l(this,ui).set(t,{savedX:t.x,savedY:t.y,savedPageIndex:t.pageIndex,newX:0,newY:0,newPageIndex:-1})}}endDragSession(){if(!l(this,ui))return!1;this.disableUserSelect(!1);const t=l(this,ui);m(this,ui,null);let e=!1;for(const[{x:i,y:n,pageIndex:r},o]of t)o.newX=i,o.newY=n,o.newPageIndex=r,e||(e=i!==o.savedX||n!==o.savedY||r!==o.savedPageIndex);if(!e)return!1;const s=(i,n,r,o)=>{if(l(this,Kt).has(i.id)){const h=l(this,ae).get(o);h?i._setParentAndPosition(h,n,r):(i.pageIndex=o,i.x=n,i.y=r)}};return this.addCommands({cmd:()=>{for(const[i,{newX:n,newY:r,newPageIndex:o}]of t)s(i,n,r,o)},undo:()=>{for(const[i,{savedX:n,savedY:r,savedPageIndex:o}]of t)s(i,n,r,o)},mustExec:!0}),!0}dragSelectedEditors(t,e){if(l(this,ui))for(const s of l(this,ui).keys())s.drag(t,e)}rebuild(t){if(t.parent===null){const e=this.getLayer(t.pageIndex);e?(e.changeParent(t),e.addOrRebuild(t)):(this.addEditor(t),this.addToAnnotationStorage(t),t.rebuild())}else t.parent.addOrRebuild(t)}get isEditorHandlingKeyboard(){var t;return((t=this.getActive())==null?void 0:t.shouldGetKeyboardEvents())||l(this,pt).size===1&&this.firstSelectedEditor.shouldGetKeyboardEvents()}isActive(t){return l(this,ss)===t}getActive(){return l(this,ss)}getMode(){return l(this,ee)}get imageManager(){return st(this,"imageManager",new vg)}getSelectionBoxes(t){if(!t)return null;const e=document.getSelection();for(let c=0,u=e.rangeCount;c<u;c++)if(!t.contains(e.getRangeAt(c).commonAncestorContainer))return null;const{x:s,y:i,width:n,height:r}=t.getBoundingClientRect();let o;switch(t.getAttribute("data-main-rotation")){case"90":o=(c,u,d,f)=>({x:(u-i)/r,y:1-(c+d-s)/n,width:f/r,height:d/n});break;case"180":o=(c,u,d,f)=>({x:1-(c+d-s)/n,y:1-(u+f-i)/r,width:d/n,height:f/r});break;case"270":o=(c,u,d,f)=>({x:1-(u+f-i)/r,y:(c-s)/n,width:f/r,height:d/n});break;default:o=(c,u,d,f)=>({x:(c-s)/n,y:(u-i)/r,width:d/n,height:f/r});break}const h=[];for(let c=0,u=e.rangeCount;c<u;c++){const d=e.getRangeAt(c);if(!d.collapsed)for(const{x:f,y:g,width:p,height:b}of d.getClientRects())p===0||b===0||h.push(o(f,g,p,b))}return h.length===0?null:h}addChangedExistingAnnotation({annotationElementId:t,id:e}){(l(this,da)||m(this,da,new Map)).set(t,e)}removeChangedExistingAnnotation({annotationElementId:t}){var e;(e=l(this,da))==null||e.delete(t)}renderAnnotationElement(t){var i;const e=(i=l(this,da))==null?void 0:i.get(t.data.id);if(!e)return;const s=l(this,Ui).getRawValue(e);s&&(l(this,ee)===Z.NONE&&!s.hasBeenModified||s.renderAnnotationElement(t))}};ca=new WeakMap,ss=new WeakMap,Kt=new WeakMap,ae=new WeakMap,ua=new WeakMap,Ui=new WeakMap,da=new WeakMap,ws=new WeakMap,Bn=new WeakMap,Nr=new WeakMap,fa=new WeakMap,jr=new WeakMap,ui=new WeakMap,Vs=new WeakMap,Br=new WeakMap,rl=new WeakMap,ol=new WeakMap,ga=new WeakMap,al=new WeakMap,di=new WeakMap,Hn=new WeakMap,pa=new WeakMap,Gn=new WeakMap,fi=new WeakMap,dd=new WeakMap,zn=new WeakMap,hl=new WeakMap,Vn=new WeakMap,Hr=new WeakMap,ll=new WeakMap,cl=new WeakMap,ee=new WeakMap,pt=new WeakMap,Yi=new WeakMap,Gr=new WeakMap,ul=new WeakMap,dl=new WeakMap,Xn=new WeakMap,gi=new WeakMap,$i=new WeakMap,fl=new WeakMap,xs=new WeakMap,I=new WeakSet,Dd=function({anchorNode:t}){return t.nodeType===Node.TEXT_NODE?t.parentElement:t},Jg=function(t){const{currentLayer:e}=this;if(e.hasTextLayer(t))return e;for(const s of l(this,ae).values())if(s.hasTextLayer(t))return s;return null},iy=function(){const t=document.getSelection();if(!t||t.isCollapsed)return;const s=w(this,I,Dd).call(this,t).closest(".textLayer"),i=this.getSelectionBoxes(s);i&&(l(this,fi)||m(this,fi,new gx(this)),l(this,fi).show(s,i,this.direction==="ltr"))},ny=function(){var n,r,o;const t=document.getSelection();if(!t||t.isCollapsed){l(this,Yi)&&((n=l(this,fi))==null||n.hide(),m(this,Yi,null),w(this,I,ze).call(this,{hasSelectedText:!1}));return}const{anchorNode:e}=t;if(e===l(this,Yi))return;const i=w(this,I,Dd).call(this,t).closest(".textLayer");if(!i){l(this,Yi)&&((r=l(this,fi))==null||r.hide(),m(this,Yi,null),w(this,I,ze).call(this,{hasSelectedText:!1}));return}if((o=l(this,fi))==null||o.hide(),m(this,Yi,e),w(this,I,ze).call(this,{hasSelectedText:!0}),!(l(this,ee)!==Z.HIGHLIGHT&&l(this,ee)!==Z.NONE)&&(l(this,ee)===Z.HIGHLIGHT&&this.showAllEditors("highlight",!0,!0),m(this,Gn,this.isShiftKeyDown),!this.isShiftKeyDown)){const h=l(this,ee)===Z.HIGHLIGHT?w(this,I,Jg).call(this,i):null;h==null||h.toggleDrawing();const c=new AbortController,u=this.combinedSignal(c),d=f=>{f.type==="pointerup"&&f.button!==0||(c.abort(),h==null||h.toggleDrawing(!0),f.type==="pointerup"&&w(this,I,Od).call(this,"main_toolbar"))};window.addEventListener("pointerup",d,{signal:u}),window.addEventListener("blur",d,{signal:u})}},Od=function(t=""){l(this,ee)===Z.HIGHLIGHT?this.highlightSelection(t):l(this,rl)&&w(this,I,iy).call(this)},ry=function(){document.addEventListener("selectionchange",w(this,I,ny).bind(this),{signal:this._signal})},oy=function(){if(l(this,Hn))return;m(this,Hn,new AbortController);const t=this.combinedSignal(l(this,Hn));window.addEventListener("focus",this.focus.bind(this),{signal:t}),window.addEventListener("blur",this.blur.bind(this),{signal:t})},ay=function(){var t;(t=l(this,Hn))==null||t.abort(),m(this,Hn,null)},Zg=function(){if(l(this,Vn))return;m(this,Vn,new AbortController);const t=this.combinedSignal(l(this,Vn));window.addEventListener("keydown",this.keydown.bind(this),{signal:t}),window.addEventListener("keyup",this.keyup.bind(this),{signal:t})},hy=function(){var t;(t=l(this,Vn))==null||t.abort(),m(this,Vn,null)},tp=function(){if(l(this,Bn))return;m(this,Bn,new AbortController);const t=this.combinedSignal(l(this,Bn));document.addEventListener("copy",this.copy.bind(this),{signal:t}),document.addEventListener("cut",this.cut.bind(this),{signal:t}),document.addEventListener("paste",this.paste.bind(this),{signal:t})},ep=function(){var t;(t=l(this,Bn))==null||t.abort(),m(this,Bn,null)},ly=function(){const t=this._signal;document.addEventListener("dragover",this.dragOver.bind(this),{signal:t}),document.addEventListener("drop",this.drop.bind(this),{signal:t})},ze=function(t){Object.entries(t).some(([s,i])=>l(this,dl)[s]!==i)&&(this._eventBus.dispatch("annotationeditorstateschanged",{source:this,details:Object.assign(l(this,dl),t)}),l(this,ee)===Z.HIGHLIGHT&&t.hasSelectedEditor===!1&&w(this,I,xn).call(this,[[ot.HIGHLIGHT_FREE,!0]]))},xn=function(t){this._eventBus.dispatch("annotationeditorparamschanged",{source:this,details:t})},cy=async function(){if(!l(this,zn)){m(this,zn,!0);const t=[];for(const e of l(this,ae).values())t.push(e.enable());await Promise.all(t);for(const e of l(this,Kt).values())e.enable()}},uy=function(){if(this.unselectAll(),l(this,zn)){m(this,zn,!1);for(const t of l(this,ae).values())t.disable();for(const t of l(this,Kt).values())t.disable()}},sp=function(t){const e=l(this,ae).get(t.pageIndex);e?e.addOrRebuild(t):(this.addEditor(t),this.addToAnnotationStorage(t))},dy=function(){let t=null;for(t of l(this,pt));return t},Ac=function(){if(l(this,Kt).size===0)return!0;if(l(this,Kt).size===1)for(const t of l(this,Kt).values())return t.isEmpty();return!1},ip=function(t){for(const e of l(this,pt))e.unselect();l(this,pt).clear();for(const e of t)e.isEmpty()||(l(this,pt).add(e),e.select());w(this,I,ze).call(this,{hasSelectedEditor:this.hasSelection})},$(ma,"TRANSLATE_SMALL",1),$(ma,"TRANSLATE_BIG",10);let Mr=ma;const Fe=class Fe{constructor(t){y(this,Ws);y(this,se,null);y(this,pi,!1);y(this,Xs,null);y(this,ba,null);y(this,mi,null);y(this,is,null);y(this,ya,!1);y(this,bi,null);y(this,$e,null);y(this,qi,null);y(this,zr,null);y(this,yi,!1);m(this,$e,t),m(this,yi,t._uiManager.useNewAltTextFlow),l(Fe,Wn)||m(Fe,Wn,Object.freeze({added:"pdfjs-editor-new-alt-text-added-button","added-label":"pdfjs-editor-new-alt-text-added-button-label",missing:"pdfjs-editor-new-alt-text-missing-button","missing-label":"pdfjs-editor-new-alt-text-missing-button-label",review:"pdfjs-editor-new-alt-text-to-review-button","review-label":"pdfjs-editor-new-alt-text-to-review-button-label"}))}static initialize(t){Fe._l10n??(Fe._l10n=t)}async render(){const t=m(this,Xs,document.createElement("button"));t.className="altText",t.tabIndex="0";const e=m(this,ba,document.createElement("span"));t.append(e),l(this,yi)?(t.classList.add("new"),t.setAttribute("data-l10n-id",l(Fe,Wn).missing),e.setAttribute("data-l10n-id",l(Fe,Wn)["missing-label"])):(t.setAttribute("data-l10n-id","pdfjs-editor-alt-text-button"),e.setAttribute("data-l10n-id","pdfjs-editor-alt-text-button-label"));const s=l(this,$e)._uiManager._signal;t.addEventListener("contextmenu",Gs,{signal:s}),t.addEventListener("pointerdown",n=>n.stopPropagation(),{signal:s});const i=n=>{n.preventDefault(),l(this,$e)._uiManager.editAltText(l(this,$e)),l(this,yi)&&l(this,$e)._reportTelemetry({action:"pdfjs.image.alt_text.image_status_label_clicked",data:{label:l(this,Ws,Tc)}})};return t.addEventListener("click",i,{capture:!0,signal:s}),t.addEventListener("keydown",n=>{n.target===t&&n.key==="Enter"&&(m(this,ya,!0),i(n))},{signal:s}),await w(this,Ws,Rd).call(this),t}finish(){l(this,Xs)&&(l(this,Xs).focus({focusVisible:l(this,ya)}),m(this,ya,!1))}isEmpty(){return l(this,yi)?l(this,se)===null:!l(this,se)&&!l(this,pi)}hasData(){return l(this,yi)?l(this,se)!==null||!!l(this,qi):this.isEmpty()}get guessedText(){return l(this,qi)}async setGuessedText(t){l(this,se)===null&&(m(this,qi,t),m(this,zr,await Fe._l10n.get("pdfjs-editor-new-alt-text-generated-alt-text-with-disclaimer",{generatedAltText:t})),w(this,Ws,Rd).call(this))}toggleAltTextBadge(t=!1){var e;if(!l(this,yi)||l(this,se)){(e=l(this,bi))==null||e.remove(),m(this,bi,null);return}if(!l(this,bi)){const s=m(this,bi,document.createElement("div"));s.className="noAltTextBadge",l(this,$e).div.append(s)}l(this,bi).classList.toggle("hidden",!t)}serialize(t){let e=l(this,se);return!t&&l(this,qi)===e&&(e=l(this,zr)),{altText:e,decorative:l(this,pi),guessedText:l(this,qi),textWithDisclaimer:l(this,zr)}}get data(){return{altText:l(this,se),decorative:l(this,pi)}}set data({altText:t,decorative:e,guessedText:s,textWithDisclaimer:i,cancel:n=!1}){s&&(m(this,qi,s),m(this,zr,i)),!(l(this,se)===t&&l(this,pi)===e)&&(n||(m(this,se,t),m(this,pi,e)),w(this,Ws,Rd).call(this))}toggle(t=!1){l(this,Xs)&&(!t&&l(this,is)&&(clearTimeout(l(this,is)),m(this,is,null)),l(this,Xs).disabled=!t)}shown(){l(this,$e)._reportTelemetry({action:"pdfjs.image.alt_text.image_status_label_displayed",data:{label:l(this,Ws,Tc)}})}destroy(){var t,e;(t=l(this,Xs))==null||t.remove(),m(this,Xs,null),m(this,ba,null),m(this,mi,null),(e=l(this,bi))==null||e.remove(),m(this,bi,null)}};se=new WeakMap,pi=new WeakMap,Xs=new WeakMap,ba=new WeakMap,mi=new WeakMap,is=new WeakMap,ya=new WeakMap,bi=new WeakMap,$e=new WeakMap,qi=new WeakMap,zr=new WeakMap,yi=new WeakMap,Wn=new WeakMap,Ws=new WeakSet,Tc=function(){return l(this,se)&&"added"||l(this,se)===null&&this.guessedText&&"review"||"missing"},Rd=async function(){var i,n,r;const t=l(this,Xs);if(!t)return;if(l(this,yi)){if(t.classList.toggle("done",!!l(this,se)),t.setAttribute("data-l10n-id",l(Fe,Wn)[l(this,Ws,Tc)]),(i=l(this,ba))==null||i.setAttribute("data-l10n-id",l(Fe,Wn)[`${l(this,Ws,Tc)}-label`]),!l(this,se)){(n=l(this,mi))==null||n.remove();return}}else{if(!l(this,se)&&!l(this,pi)){t.classList.remove("done"),(r=l(this,mi))==null||r.remove();return}t.classList.add("done"),t.setAttribute("data-l10n-id","pdfjs-editor-alt-text-edit-button")}let e=l(this,mi);if(!e){m(this,mi,e=document.createElement("span")),e.className="tooltip",e.setAttribute("role","tooltip"),e.id=`alt-text-tooltip-${l(this,$e).id}`;const o=100,h=l(this,$e)._uiManager._signal;h.addEventListener("abort",()=>{clearTimeout(l(this,is)),m(this,is,null)},{once:!0}),t.addEventListener("mouseenter",()=>{m(this,is,setTimeout(()=>{m(this,is,null),l(this,mi).classList.add("show"),l(this,$e)._reportTelemetry({action:"alt_text_tooltip"})},o))},{signal:h}),t.addEventListener("mouseleave",()=>{var c;l(this,is)&&(clearTimeout(l(this,is)),m(this,is,null)),(c=l(this,mi))==null||c.classList.remove("show")},{signal:h})}l(this,pi)?e.setAttribute("data-l10n-id","pdfjs-editor-alt-text-decorative-tooltip"):(e.removeAttribute("data-l10n-id"),e.textContent=l(this,se)),e.parentNode||t.append(e);const s=l(this,$e).getImageForAltText();s==null||s.setAttribute("aria-describedby",e.id)},y(Fe,Wn,null),$(Fe,"_l10n",null);let Ku=Fe;const Xg=class Xg{constructor({container:t,isPinchingDisabled:e=null,isPinchingStopped:s=null,onPinchStart:i=null,onPinching:n=null,onPinchEnd:r=null,signal:o}){y(this,Qi);y(this,gl);y(this,Vr,!1);y(this,pl,null);y(this,ml);y(this,bl);y(this,yl);y(this,vl);y(this,va);y(this,Ki,null);y(this,Xr);y(this,Un,null);m(this,gl,t),m(this,pl,s),m(this,ml,e),m(this,bl,i),m(this,yl,n),m(this,vl,r),m(this,Xr,new AbortController),m(this,va,AbortSignal.any([o,l(this,Xr).signal])),t.addEventListener("touchstart",w(this,Qi,fy).bind(this),{passive:!1,signal:l(this,va)})}get MIN_TOUCH_DISTANCE_TO_PINCH(){return st(this,"MIN_TOUCH_DISTANCE_TO_PINCH",35/(window.devicePixelRatio||1))}destroy(){var t;(t=l(this,Xr))==null||t.abort(),m(this,Xr,null)}};gl=new WeakMap,Vr=new WeakMap,pl=new WeakMap,ml=new WeakMap,bl=new WeakMap,yl=new WeakMap,vl=new WeakMap,va=new WeakMap,Ki=new WeakMap,Xr=new WeakMap,Un=new WeakMap,Qi=new WeakSet,fy=function(t){var i,n,r;if((i=l(this,ml))!=null&&i.call(this)||t.touches.length<2)return;if(!l(this,Un)){m(this,Un,new AbortController);const o=AbortSignal.any([l(this,va),l(this,Un).signal]),h=l(this,gl),c={signal:o,passive:!1};h.addEventListener("touchmove",w(this,Qi,gy).bind(this),c),h.addEventListener("touchend",w(this,Qi,np).bind(this),c),h.addEventListener("touchcancel",w(this,Qi,np).bind(this),c),(n=l(this,bl))==null||n.call(this)}if(es(t),t.touches.length!==2||(r=l(this,pl))!=null&&r.call(this)){m(this,Ki,null);return}let[e,s]=t.touches;e.identifier>s.identifier&&([e,s]=[s,e]),m(this,Ki,{touch0X:e.screenX,touch0Y:e.screenY,touch1X:s.screenX,touch1Y:s.screenY})},gy=function(t){var S;if(!l(this,Ki)||t.touches.length!==2)return;let[e,s]=t.touches;e.identifier>s.identifier&&([e,s]=[s,e]);const{screenX:i,screenY:n}=e,{screenX:r,screenY:o}=s,h=l(this,Ki),{touch0X:c,touch0Y:u,touch1X:d,touch1Y:f}=h,g=d-c,p=f-u,b=r-i,_=o-n,v=Math.hypot(b,_)||1,x=Math.hypot(g,p)||1;if(!l(this,Vr)&&Math.abs(x-v)<=Xg.MIN_TOUCH_DISTANCE_TO_PINCH)return;if(h.touch0X=i,h.touch0Y=n,h.touch1X=r,h.touch1Y=o,t.preventDefault(),!l(this,Vr)){m(this,Vr,!0);return}const C=[(i+r)/2,(n+o)/2];(S=l(this,yl))==null||S.call(this,C,x,v)},np=function(t){var e;l(this,Un).abort(),m(this,Un,null),(e=l(this,vl))==null||e.call(this),l(this,Ki)&&(t.preventDefault(),m(this,Ki,null),m(this,Vr,!1))};let Qu=Xg;const et=class et{constructor(t){y(this,Y);y(this,Wr,null);y(this,Us,null);y(this,xt,null);y(this,_a,!1);y(this,Yn,null);y(this,_l,"");y(this,Ur,!1);y(this,he,null);y(this,Yr,null);y(this,Ji,null);y(this,$n,null);y(this,wl,"");y(this,$r,!1);y(this,ns,null);y(this,xl,!1);y(this,qr,!1);y(this,Zi,!1);y(this,vi,null);y(this,wa,0);y(this,xa,0);y(this,Ss,null);y(this,Kr,null);$(this,"_editToolbar",null);$(this,"_initialOptions",Object.create(null));$(this,"_initialData",null);$(this,"_isVisible",!0);$(this,"_uiManager",null);$(this,"_focusEventsAllowed",!0);y(this,Sl,!1);y(this,fd,et._zIndex++);this.parent=t.parent,this.id=t.id,this.width=this.height=null,this.pageIndex=t.parent.pageIndex,this.name=t.name,this.div=null,this._uiManager=t.uiManager,this.annotationElementId=null,this._willKeepAspectRatio=!1,this._initialOptions.isCentered=t.isCentered,this._structTreeParentId=null;const{rotation:e,rawDims:{pageWidth:s,pageHeight:i,pageX:n,pageY:r}}=this.parent.viewport;this.rotation=e,this.pageRotation=(360+e-this._uiManager.viewParameters.rotation)%360,this.pageDimensions=[s,i],this.pageTranslation=[n,r];const[o,h]=this.parentDimensions;this.x=t.x/o,this.y=t.y/h,this.isAttachedToDOM=!1,this.deleted=!1}static get _resizerKeyboardManager(){const t=et.prototype._resizeWithKeyboard,e=Mr.TRANSLATE_SMALL,s=Mr.TRANSLATE_BIG;return st(this,"_resizerKeyboardManager",new Xh([[["ArrowLeft","mac+ArrowLeft"],t,{args:[-e,0]}],[["ctrl+ArrowLeft","mac+shift+ArrowLeft"],t,{args:[-s,0]}],[["ArrowRight","mac+ArrowRight"],t,{args:[e,0]}],[["ctrl+ArrowRight","mac+shift+ArrowRight"],t,{args:[s,0]}],[["ArrowUp","mac+ArrowUp"],t,{args:[0,-e]}],[["ctrl+ArrowUp","mac+shift+ArrowUp"],t,{args:[0,-s]}],[["ArrowDown","mac+ArrowDown"],t,{args:[0,e]}],[["ctrl+ArrowDown","mac+shift+ArrowDown"],t,{args:[0,s]}],[["Escape","mac+Escape"],et.prototype._stopResizingWithKeyboard]]))}get editorType(){return Object.getPrototypeOf(this).constructor._type}static get isDrawer(){return!1}static get _defaultLineColor(){return st(this,"_defaultLineColor",this._colorManager.getHexCode("CanvasText"))}static deleteAnnotationElement(t){const e=new bx({id:t.parent.getNextId(),parent:t.parent,uiManager:t._uiManager});e.annotationElementId=t.annotationElementId,e.deleted=!0,e._uiManager.addToAnnotationStorage(e)}static initialize(t,e){if(et._l10n??(et._l10n=t),et._l10nResizer||(et._l10nResizer=Object.freeze({topLeft:"pdfjs-editor-resizer-top-left",topMiddle:"pdfjs-editor-resizer-top-middle",topRight:"pdfjs-editor-resizer-top-right",middleRight:"pdfjs-editor-resizer-middle-right",bottomRight:"pdfjs-editor-resizer-bottom-right",bottomMiddle:"pdfjs-editor-resizer-bottom-middle",bottomLeft:"pdfjs-editor-resizer-bottom-left",middleLeft:"pdfjs-editor-resizer-middle-left"})),et._borderLineWidth!==-1)return;const s=getComputedStyle(document.documentElement);et._borderLineWidth=parseFloat(s.getPropertyValue("--outline-width"))||0}static updateDefaultParams(t,e){}static get defaultPropertiesToUpdate(){return[]}static isHandlingMimeForPasting(t){return!1}static paste(t,e){vt("Not implemented")}get propertiesToUpdate(){return[]}get _isDraggable(){return l(this,Sl)}set _isDraggable(t){var e;m(this,Sl,t),(e=this.div)==null||e.classList.toggle("draggable",t)}get isEnterHandled(){return!0}center(){const[t,e]=this.pageDimensions;switch(this.parentRotation){case 90:this.x-=this.height*e/(t*2),this.y+=this.width*t/(e*2);break;case 180:this.x+=this.width/2,this.y+=this.height/2;break;case 270:this.x+=this.height*e/(t*2),this.y-=this.width*t/(e*2);break;default:this.x-=this.width/2,this.y-=this.height/2;break}this.fixAndSetPosition()}addCommands(t){this._uiManager.addCommands(t)}get currentLayer(){return this._uiManager.currentLayer}setInBackground(){this.div.style.zIndex=0}setInForeground(){this.div.style.zIndex=l(this,fd)}setParent(t){t!==null?(this.pageIndex=t.pageIndex,this.pageDimensions=t.pageDimensions):w(this,Y,Ec).call(this),this.parent=t}focusin(t){this._focusEventsAllowed&&(l(this,$r)?m(this,$r,!1):this.parent.setSelected(this))}focusout(t){var s;if(!this._focusEventsAllowed||!this.isAttachedToDOM)return;const e=t.relatedTarget;e!=null&&e.closest(`#${this.id}`)||(t.preventDefault(),(s=this.parent)!=null&&s.isMultipleSelection||this.commitOrRemove())}commitOrRemove(){this.isEmpty()?this.remove():this.commit()}commit(){this.addToAnnotationStorage()}addToAnnotationStorage(){this._uiManager.addToAnnotationStorage(this)}setAt(t,e,s,i){const[n,r]=this.parentDimensions;[s,i]=this.screenToPageTranslation(s,i),this.x=(t+s)/n,this.y=(e+i)/r,this.fixAndSetPosition()}translate(t,e){w(this,Y,rp).call(this,this.parentDimensions,t,e)}translateInPage(t,e){l(this,ns)||m(this,ns,[this.x,this.y,this.width,this.height]),w(this,Y,rp).call(this,this.pageDimensions,t,e),this.div.scrollIntoView({block:"nearest"})}drag(t,e){l(this,ns)||m(this,ns,[this.x,this.y,this.width,this.height]);const{div:s,parentDimensions:[i,n]}=this;if(this.x+=t/i,this.y+=e/n,this.parent&&(this.x<0||this.x>1||this.y<0||this.y>1)){const{x:d,y:f}=this.div.getBoundingClientRect();this.parent.findNewParent(this,d,f)&&(this.x-=Math.floor(this.x),this.y-=Math.floor(this.y))}let{x:r,y:o}=this;const[h,c]=this.getBaseTranslation();r+=h,o+=c;const{style:u}=s;u.left=`${(100*r).toFixed(2)}%`,u.top=`${(100*o).toFixed(2)}%`,this._onTranslating(r,o),s.scrollIntoView({block:"nearest"})}_onTranslating(t,e){}_onTranslated(t,e){}get _hasBeenMoved(){return!!l(this,ns)&&(l(this,ns)[0]!==this.x||l(this,ns)[1]!==this.y)}get _hasBeenResized(){return!!l(this,ns)&&(l(this,ns)[2]!==this.width||l(this,ns)[3]!==this.height)}getBaseTranslation(){const[t,e]=this.parentDimensions,{_borderLineWidth:s}=et,i=s/t,n=s/e;switch(this.rotation){case 90:return[-i,n];case 180:return[i,n];case 270:return[i,-n];default:return[-i,-n]}}get _mustFixPosition(){return!0}fixAndSetPosition(t=this.rotation){const{div:{style:e},pageDimensions:[s,i]}=this;let{x:n,y:r,width:o,height:h}=this;if(o*=s,h*=i,n*=s,r*=i,this._mustFixPosition)switch(t){case 0:n=Math.max(0,Math.min(s-o,n)),r=Math.max(0,Math.min(i-h,r));break;case 90:n=Math.max(0,Math.min(s-h,n)),r=Math.min(i,Math.max(o,r));break;case 180:n=Math.min(s,Math.max(o,n)),r=Math.min(i,Math.max(h,r));break;case 270:n=Math.min(s,Math.max(h,n)),r=Math.max(0,Math.min(i-o,r));break}this.x=n/=s,this.y=r/=i;const[c,u]=this.getBaseTranslation();n+=c,r+=u,e.left=`${(100*n).toFixed(2)}%`,e.top=`${(100*r).toFixed(2)}%`,this.moveInDOM()}screenToPageTranslation(t,e){var s;return w(s=et,Cl,op).call(s,t,e,this.parentRotation)}pageTranslationToScreen(t,e){var s;return w(s=et,Cl,op).call(s,t,e,360-this.parentRotation)}get parentScale(){return this._uiManager.viewParameters.realScale}get parentRotation(){return(this._uiManager.viewParameters.rotation+this.pageRotation)%360}get parentDimensions(){const{parentScale:t,pageDimensions:[e,s]}=this;return[e*t,s*t]}setDims(t,e){const[s,i]=this.parentDimensions,{style:n}=this.div;n.width=`${(100*t/s).toFixed(2)}%`,l(this,Ur)||(n.height=`${(100*e/i).toFixed(2)}%`)}fixDims(){const{style:t}=this.div,{height:e,width:s}=t,i=s.endsWith("%"),n=!l(this,Ur)&&e.endsWith("%");if(i&&n)return;const[r,o]=this.parentDimensions;i||(t.width=`${(100*parseFloat(s)/r).toFixed(2)}%`),!l(this,Ur)&&!n&&(t.height=`${(100*parseFloat(e)/o).toFixed(2)}%`)}getInitialTranslation(){return[0,0]}_onResized(){}static _round(t){return Math.round(t*1e4)/1e4}_onResizing(){}altTextFinish(){var t;(t=l(this,xt))==null||t.finish()}async addEditToolbar(){return this._editToolbar||l(this,qr)?this._editToolbar:(this._editToolbar=new yg(this),this.div.append(this._editToolbar.render()),l(this,xt)&&await this._editToolbar.addAltText(l(this,xt)),this._editToolbar)}removeEditToolbar(){var t;this._editToolbar&&(this._editToolbar.remove(),this._editToolbar=null,(t=l(this,xt))==null||t.destroy())}addContainer(t){var s;const e=(s=this._editToolbar)==null?void 0:s.div;e?e.before(t):this.div.append(t)}getClientDimensions(){return this.div.getBoundingClientRect()}async addAltTextButton(){l(this,xt)||(Ku.initialize(et._l10n),m(this,xt,new Ku(this)),l(this,Wr)&&(l(this,xt).data=l(this,Wr),m(this,Wr,null)),await this.addEditToolbar())}get altTextData(){var t;return(t=l(this,xt))==null?void 0:t.data}set altTextData(t){l(this,xt)&&(l(this,xt).data=t)}get guessedAltText(){var t;return(t=l(this,xt))==null?void 0:t.guessedText}async setGuessedAltText(t){var e;await((e=l(this,xt))==null?void 0:e.setGuessedText(t))}serializeAltText(t){var e;return(e=l(this,xt))==null?void 0:e.serialize(t)}hasAltText(){return!!l(this,xt)&&!l(this,xt).isEmpty()}hasAltTextData(){var t;return((t=l(this,xt))==null?void 0:t.hasData())??!1}render(){var n;this.div=document.createElement("div"),this.div.setAttribute("data-editor-rotation",(360-this.rotation)%360),this.div.className=this.name,this.div.setAttribute("id",this.id),this.div.tabIndex=l(this,_a)?-1:0,this._isVisible||this.div.classList.add("hidden"),this.setInForeground(),w(this,Y,cp).call(this);const[t,e]=this.parentDimensions;this.parentRotation%180!==0&&(this.div.style.maxWidth=`${(100*e/t).toFixed(2)}%`,this.div.style.maxHeight=`${(100*t/e).toFixed(2)}%`);const[s,i]=this.getInitialTranslation();return this.translate(s,i),qu(this,this.div,["pointerdown"]),this.isResizable&&this._uiManager._supportsPinchToZoom&&(l(this,Kr)||m(this,Kr,new Qu({container:this.div,isPinchingDisabled:()=>!this.isSelected,onPinchStart:w(this,Y,by).bind(this),onPinching:w(this,Y,yy).bind(this),onPinchEnd:w(this,Y,vy).bind(this),signal:this._uiManager._signal}))),(n=this._uiManager._editorUndoBar)==null||n.hide(),this.div}pointerdown(t){const{isMac:e}=Re.platform;if(t.button!==0||t.ctrlKey&&e){t.preventDefault();return}if(m(this,$r,!0),this._isDraggable){w(this,Y,_y).call(this,t);return}w(this,Y,lp).call(this,t)}get isSelected(){return this._uiManager.isSelected(this)}_onStartDragging(){}_onStopDragging(){}moveInDOM(){l(this,vi)&&clearTimeout(l(this,vi)),m(this,vi,setTimeout(()=>{var t;m(this,vi,null),(t=this.parent)==null||t.moveEditorInDOM(this)},0))}_setParentAndPosition(t,e,s){t.changeParent(this),this.x=e,this.y=s,this.fixAndSetPosition(),this._onTranslated()}getRect(t,e,s=this.rotation){const i=this.parentScale,[n,r]=this.pageDimensions,[o,h]=this.pageTranslation,c=t/i,u=e/i,d=this.x*n,f=this.y*r,g=this.width*n,p=this.height*r;switch(s){case 0:return[d+c+o,r-f-u-p+h,d+c+g+o,r-f-u+h];case 90:return[d+u+o,r-f+c+h,d+u+p+o,r-f+c+g+h];case 180:return[d-c-g+o,r-f+u+h,d-c+o,r-f+u+p+h];case 270:return[d-u-p+o,r-f-c-g+h,d-u+o,r-f-c+h];default:throw new Error("Invalid rotation")}}getRectInCurrentCoords(t,e){const[s,i,n,r]=t,o=n-s,h=r-i;switch(this.rotation){case 0:return[s,e-r,o,h];case 90:return[s,e-i,h,o];case 180:return[n,e-i,o,h];case 270:return[n,e-r,h,o];default:throw new Error("Invalid rotation")}}onceAdded(t){}isEmpty(){return!1}enableEditMode(){m(this,qr,!0)}disableEditMode(){m(this,qr,!1)}isInEditMode(){return l(this,qr)}shouldGetKeyboardEvents(){return l(this,Zi)}needsToBeRebuilt(){return this.div&&!this.isAttachedToDOM}get isOnScreen(){const{top:t,left:e,bottom:s,right:i}=this.getClientDimensions(),{innerHeight:n,innerWidth:r}=window;return e<r&&i>0&&t<n&&s>0}rebuild(){w(this,Y,cp).call(this)}rotate(t){}resize(){}serializeDeleted(){var t;return{id:this.annotationElementId,deleted:!0,pageIndex:this.pageIndex,popupRef:((t=this._initialData)==null?void 0:t.popupRef)||""}}serialize(t=!1,e=null){vt("An editor must be serializable")}static async deserialize(t,e,s){const i=new this.prototype.constructor({parent:e,id:e.getNextId(),uiManager:s});i.rotation=t.rotation,m(i,Wr,t.accessibilityData);const[n,r]=i.pageDimensions,[o,h,c,u]=i.getRectInCurrentCoords(t.rect,r);return i.x=o/n,i.y=h/r,i.width=c/n,i.height=u/r,i}get hasBeenModified(){return!!this.annotationElementId&&(this.deleted||this.serialize()!==null)}remove(){var t,e;if((t=l(this,$n))==null||t.abort(),m(this,$n,null),this.isEmpty()||this.commit(),this.parent?this.parent.remove(this):this._uiManager.removeEditor(this),l(this,vi)&&(clearTimeout(l(this,vi)),m(this,vi,null)),w(this,Y,Ec).call(this),this.removeEditToolbar(),l(this,Ss)){for(const s of l(this,Ss).values())clearTimeout(s);m(this,Ss,null)}this.parent=null,(e=l(this,Kr))==null||e.destroy(),m(this,Kr,null)}get isResizable(){return!1}makeResizable(){this.isResizable&&(w(this,Y,py).call(this),l(this,he).classList.remove("hidden"),qu(this,this.div,["keydown"]))}get toolbarPosition(){return null}keydown(t){if(!this.isResizable||t.target!==this.div||t.key!=="Enter")return;this._uiManager.setSelected(this),m(this,Ji,{savedX:this.x,savedY:this.y,savedWidth:this.width,savedHeight:this.height});const e=l(this,he).children;if(!l(this,Us)){m(this,Us,Array.from(e));const r=w(this,Y,wy).bind(this),o=w(this,Y,xy).bind(this),h=this._uiManager._signal;for(const c of l(this,Us)){const u=c.getAttribute("data-resizer-name");c.setAttribute("role","spinbutton"),c.addEventListener("keydown",r,{signal:h}),c.addEventListener("blur",o,{signal:h}),c.addEventListener("focus",w(this,Y,Sy).bind(this,u),{signal:h}),c.setAttribute("data-l10n-id",et._l10nResizer[u])}}const s=l(this,Us)[0];let i=0;for(const r of e){if(r===s)break;i++}const n=(360-this.rotation+this.parentRotation)%360/90*(l(this,Us).length/4);if(n!==i){if(n<i)for(let o=0;o<i-n;o++)l(this,he).append(l(this,he).firstChild);else if(n>i)for(let o=0;o<n-i;o++)l(this,he).firstChild.before(l(this,he).lastChild);let r=0;for(const o of e){const c=l(this,Us)[r++].getAttribute("data-resizer-name");o.setAttribute("data-l10n-id",et._l10nResizer[c])}}w(this,Y,up).call(this,0),m(this,Zi,!0),l(this,he).firstChild.focus({focusVisible:!0}),t.preventDefault(),t.stopImmediatePropagation()}_resizeWithKeyboard(t,e){l(this,Zi)&&w(this,Y,hp).call(this,l(this,wl),{deltaX:t,deltaY:e,fromKeyboard:!0})}_stopResizingWithKeyboard(){w(this,Y,Ec).call(this),this.div.focus()}select(){var t,e,s;if(this.makeResizable(),(t=this.div)==null||t.classList.add("selectedEditor"),!this._editToolbar){this.addEditToolbar().then(()=>{var i,n;(i=this.div)!=null&&i.classList.contains("selectedEditor")&&((n=this._editToolbar)==null||n.show())});return}(e=this._editToolbar)==null||e.show(),(s=l(this,xt))==null||s.toggleAltTextBadge(!1)}unselect(){var t,e,s,i,n;(t=l(this,he))==null||t.classList.add("hidden"),(e=this.div)==null||e.classList.remove("selectedEditor"),(s=this.div)!=null&&s.contains(document.activeElement)&&this._uiManager.currentLayer.div.focus({preventScroll:!0}),(i=this._editToolbar)==null||i.hide(),(n=l(this,xt))==null||n.toggleAltTextBadge(!0)}updateParams(t,e){}disableEditing(){}enableEditing(){}enterInEditMode(){}getImageForAltText(){return null}get contentDiv(){return this.div}get isEditing(){return l(this,xl)}set isEditing(t){m(this,xl,t),this.parent&&(t?(this.parent.setSelected(this),this.parent.setActiveEditor(this)):this.parent.setActiveEditor(null))}setAspectRatio(t,e){m(this,Ur,!0);const s=t/e,{style:i}=this.div;i.aspectRatio=s,i.height="auto"}static get MIN_SIZE(){return 16}static canCreateNewEmptyEditor(){return!0}get telemetryInitialData(){return{action:"added"}}get telemetryFinalData(){return null}_reportTelemetry(t,e=!1){if(e){l(this,Ss)||m(this,Ss,new Map);const{action:s}=t;let i=l(this,Ss).get(s);i&&clearTimeout(i),i=setTimeout(()=>{this._reportTelemetry(t),l(this,Ss).delete(s),l(this,Ss).size===0&&m(this,Ss,null)},et._telemetryTimeout),l(this,Ss).set(s,i);return}t.type||(t.type=this.editorType),this._uiManager._eventBus.dispatch("reporttelemetry",{source:this,details:{type:"editing",data:t}})}show(t=this._isVisible){this.div.classList.toggle("hidden",!t),this._isVisible=t}enable(){this.div&&(this.div.tabIndex=0),m(this,_a,!1)}disable(){this.div&&(this.div.tabIndex=-1),m(this,_a,!0)}renderAnnotationElement(t){let e=t.container.querySelector(".annotationContent");if(!e)e=document.createElement("div"),e.classList.add("annotationContent",this.editorType),t.container.prepend(e);else if(e.nodeName==="CANVAS"){const s=e;e=document.createElement("div"),e.classList.add("annotationContent",this.editorType),s.before(e)}return e}resetAnnotationElement(t){const{firstChild:e}=t.container;(e==null?void 0:e.nodeName)==="DIV"&&e.classList.contains("annotationContent")&&e.remove()}};Wr=new WeakMap,Us=new WeakMap,xt=new WeakMap,_a=new WeakMap,Yn=new WeakMap,_l=new WeakMap,Ur=new WeakMap,he=new WeakMap,Yr=new WeakMap,Ji=new WeakMap,$n=new WeakMap,wl=new WeakMap,$r=new WeakMap,ns=new WeakMap,xl=new WeakMap,qr=new WeakMap,Zi=new WeakMap,vi=new WeakMap,wa=new WeakMap,xa=new WeakMap,Ss=new WeakMap,Kr=new WeakMap,Sl=new WeakMap,fd=new WeakMap,Y=new WeakSet,rp=function([t,e],s,i){[s,i]=this.screenToPageTranslation(s,i),this.x+=s/t,this.y+=i/e,this._onTranslating(this.x,this.y),this.fixAndSetPosition()},Cl=new WeakSet,op=function(t,e,s){switch(s){case 90:return[e,-t];case 180:return[-t,-e];case 270:return[-e,t];default:return[t,e]}},Ld=function(t){switch(t){case 90:{const[e,s]=this.pageDimensions;return[0,-e/s,s/e,0]}case 180:return[-1,0,0,-1];case 270:{const[e,s]=this.pageDimensions;return[0,e/s,-s/e,0]}default:return[1,0,0,1]}},py=function(){if(l(this,he))return;m(this,he,document.createElement("div")),l(this,he).classList.add("resizers");const t=this._willKeepAspectRatio?["topLeft","topRight","bottomRight","bottomLeft"]:["topLeft","topMiddle","topRight","middleRight","bottomRight","bottomMiddle","bottomLeft","middleLeft"],e=this._uiManager._signal;for(const s of t){const i=document.createElement("div");l(this,he).append(i),i.classList.add("resizer",s),i.setAttribute("data-resizer-name",s),i.addEventListener("pointerdown",w(this,Y,my).bind(this,s),{signal:e}),i.addEventListener("contextmenu",Gs,{signal:e}),i.tabIndex=-1}this.div.prepend(l(this,he))},my=function(t,e){var u;e.preventDefault();const{isMac:s}=Re.platform;if(e.button!==0||e.ctrlKey&&s)return;(u=l(this,xt))==null||u.toggle(!1);const i=this._isDraggable;this._isDraggable=!1,m(this,Yr,[e.screenX,e.screenY]);const n=new AbortController,r=this._uiManager.combinedSignal(n);this.parent.togglePointerEvents(!1),window.addEventListener("pointermove",w(this,Y,hp).bind(this,t),{passive:!0,capture:!0,signal:r}),window.addEventListener("touchmove",es,{passive:!1,signal:r}),window.addEventListener("contextmenu",Gs,{signal:r}),m(this,Ji,{savedX:this.x,savedY:this.y,savedWidth:this.width,savedHeight:this.height});const o=this.parent.div.style.cursor,h=this.div.style.cursor;this.div.style.cursor=this.parent.div.style.cursor=window.getComputedStyle(e.target).cursor;const c=()=>{var d;n.abort(),this.parent.togglePointerEvents(!0),(d=l(this,xt))==null||d.toggle(!0),this._isDraggable=i,this.parent.div.style.cursor=o,this.div.style.cursor=h,w(this,Y,Fd).call(this)};window.addEventListener("pointerup",c,{signal:r}),window.addEventListener("blur",c,{signal:r})},ap=function(t,e,s,i){this.width=s,this.height=i,this.x=t,this.y=e;const[n,r]=this.parentDimensions;this.setDims(n*s,r*i),this.fixAndSetPosition(),this._onResized()},Fd=function(){if(!l(this,Ji))return;const{savedX:t,savedY:e,savedWidth:s,savedHeight:i}=l(this,Ji);m(this,Ji,null);const n=this.x,r=this.y,o=this.width,h=this.height;n===t&&r===e&&o===s&&h===i||this.addCommands({cmd:w(this,Y,ap).bind(this,n,r,o,h),undo:w(this,Y,ap).bind(this,t,e,s,i),mustExec:!0})},hp=function(t,e){const[s,i]=this.parentDimensions,n=this.x,r=this.y,o=this.width,h=this.height,c=et.MIN_SIZE/s,u=et.MIN_SIZE/i,d=w(this,Y,Ld).call(this,this.rotation),f=(F,G)=>[d[0]*F+d[2]*G,d[1]*F+d[3]*G],g=w(this,Y,Ld).call(this,360-this.rotation),p=(F,G)=>[g[0]*F+g[2]*G,g[1]*F+g[3]*G];let b,_,v=!1,x=!1;switch(t){case"topLeft":v=!0,b=(F,G)=>[0,0],_=(F,G)=>[F,G];break;case"topMiddle":b=(F,G)=>[F/2,0],_=(F,G)=>[F/2,G];break;case"topRight":v=!0,b=(F,G)=>[F,0],_=(F,G)=>[0,G];break;case"middleRight":x=!0,b=(F,G)=>[F,G/2],_=(F,G)=>[0,G/2];break;case"bottomRight":v=!0,b=(F,G)=>[F,G],_=(F,G)=>[0,0];break;case"bottomMiddle":b=(F,G)=>[F/2,G],_=(F,G)=>[F/2,0];break;case"bottomLeft":v=!0,b=(F,G)=>[0,G],_=(F,G)=>[F,0];break;case"middleLeft":x=!0,b=(F,G)=>[0,G/2],_=(F,G)=>[F,G/2];break}const C=b(o,h),S=_(o,h);let k=f(...S);const M=et._round(n+k[0]),E=et._round(r+k[1]);let P=1,O=1,L,R;if(e.fromKeyboard)({deltaX:L,deltaY:R}=e);else{const{screenX:F,screenY:G}=e,[rt,Gt]=l(this,Yr);[L,R]=this.screenToPageTranslation(F-rt,G-Gt),l(this,Yr)[0]=F,l(this,Yr)[1]=G}if([L,R]=p(L/s,R/i),v){const F=Math.hypot(o,h);P=O=Math.max(Math.min(Math.hypot(S[0]-C[0]-L,S[1]-C[1]-R)/F,1/o,1/h),c/o,u/h)}else x?P=Math.max(c,Math.min(1,Math.abs(S[0]-C[0]-L)))/o:O=Math.max(u,Math.min(1,Math.abs(S[1]-C[1]-R)))/h;const U=et._round(o*P),z=et._round(h*O);k=f(..._(U,z));const V=M-k[0],at=E-k[1];l(this,ns)||m(this,ns,[this.x,this.y,this.width,this.height]),this.width=U,this.height=z,this.x=V,this.y=at,this.setDims(s*U,i*z),this.fixAndSetPosition(),this._onResizing()},by=function(){var t;m(this,Ji,{savedX:this.x,savedY:this.y,savedWidth:this.width,savedHeight:this.height}),(t=l(this,xt))==null||t.toggle(!1),this.parent.togglePointerEvents(!1)},yy=function(t,e,s){let n=.7*(s/e)+1-.7;if(n===1)return;const r=w(this,Y,Ld).call(this,this.rotation),o=(M,E)=>[r[0]*M+r[2]*E,r[1]*M+r[3]*E],[h,c]=this.parentDimensions,u=this.x,d=this.y,f=this.width,g=this.height,p=et.MIN_SIZE/h,b=et.MIN_SIZE/c;n=Math.max(Math.min(n,1/f,1/g),p/f,b/g);const _=et._round(f*n),v=et._round(g*n);if(_===f&&v===g)return;l(this,ns)||m(this,ns,[u,d,f,g]);const x=o(f/2,g/2),C=et._round(u+x[0]),S=et._round(d+x[1]),k=o(_/2,v/2);this.x=C-k[0],this.y=S-k[1],this.width=_,this.height=v,this.setDims(h*_,c*v),this.fixAndSetPosition(),this._onResizing()},vy=function(){var t;(t=l(this,xt))==null||t.toggle(!0),this.parent.togglePointerEvents(!0),w(this,Y,Fd).call(this)},lp=function(t){const{isMac:e}=Re.platform;t.ctrlKey&&!e||t.shiftKey||t.metaKey&&e?this.parent.toggleSelected(this):this.parent.setSelected(this)},_y=function(t){const{isSelected:e}=this;this._uiManager.setUpDragSession();let s=!1;const i=new AbortController,n=this._uiManager.combinedSignal(i),r={capture:!0,passive:!1,signal:n},o=c=>{i.abort(),m(this,Yn,null),m(this,$r,!1),this._uiManager.endDragSession()||w(this,Y,lp).call(this,c),s&&this._onStopDragging()};e&&(m(this,wa,t.clientX),m(this,xa,t.clientY),m(this,Yn,t.pointerId),m(this,_l,t.pointerType),window.addEventListener("pointermove",c=>{s||(s=!0,this._onStartDragging());const{clientX:u,clientY:d,pointerId:f}=c;if(f!==l(this,Yn)){es(c);return}const[g,p]=this.screenToPageTranslation(u-l(this,wa),d-l(this,xa));m(this,wa,u),m(this,xa,d),this._uiManager.dragSelectedEditors(g,p)},r),window.addEventListener("touchmove",es,r),window.addEventListener("pointerdown",c=>{c.pointerType===l(this,_l)&&(l(this,Kr)||c.isPrimary)&&o(c),es(c)},r));const h=c=>{if(!l(this,Yn)||l(this,Yn)===c.pointerId){o(c);return}es(c)};window.addEventListener("pointerup",h,{signal:n}),window.addEventListener("blur",h,{signal:n})},cp=function(){if(l(this,$n)||!this.div)return;m(this,$n,new AbortController);const t=this._uiManager.combinedSignal(l(this,$n));this.div.addEventListener("focusin",this.focusin.bind(this),{signal:t}),this.div.addEventListener("focusout",this.focusout.bind(this),{signal:t})},wy=function(t){et._resizerKeyboardManager.exec(this,t)},xy=function(t){var e;l(this,Zi)&&((e=t.relatedTarget)==null?void 0:e.parentNode)!==l(this,he)&&w(this,Y,Ec).call(this)},Sy=function(t){m(this,wl,l(this,Zi)?t:"")},up=function(t){if(l(this,Us))for(const e of l(this,Us))e.tabIndex=t},Ec=function(){m(this,Zi,!1),w(this,Y,up).call(this,-1),w(this,Y,Fd).call(this)},y(et,Cl),$(et,"_l10n",null),$(et,"_l10nResizer",null),$(et,"_borderLineWidth",-1),$(et,"_colorManager",new _g),$(et,"_zIndex",1),$(et,"_telemetryTimeout",1e3);let Pt=et;class bx extends Pt{constructor(t){super(t),this.annotationElementId=t.annotationElementId,this.deleted=!0}serialize(){return this.serializeDeleted()}}const J0=3285377520,vs=4294901760,ci=65535;class Z0{constructor(t){this.h1=t?t&4294967295:J0,this.h2=t?t&4294967295:J0}update(t){let e,s;if(typeof t=="string"){e=new Uint8Array(t.length*2),s=0;for(let b=0,_=t.length;b<_;b++){const v=t.charCodeAt(b);v<=255?e[s++]=v:(e[s++]=v>>>8,e[s++]=v&255)}}else if(ArrayBuffer.isView(t))e=t.slice(),s=e.byteLength;else throw new Error("Invalid data format, must be a string or TypedArray.");const i=s>>2,n=s-i*4,r=new Uint32Array(e.buffer,0,i);let o=0,h=0,c=this.h1,u=this.h2;const d=3432918353,f=461845907,g=d&ci,p=f&ci;for(let b=0;b<i;b++)b&1?(o=r[b],o=o*d&vs|o*g&ci,o=o<<15|o>>>17,o=o*f&vs|o*p&ci,c^=o,c=c<<13|c>>>19,c=c*5+3864292196):(h=r[b],h=h*d&vs|h*g&ci,h=h<<15|h>>>17,h=h*f&vs|h*p&ci,u^=h,u=u<<13|u>>>19,u=u*5+3864292196);switch(o=0,n){case 3:o^=e[i*4+2]<<16;case 2:o^=e[i*4+1]<<8;case 1:o^=e[i*4],o=o*d&vs|o*g&ci,o=o<<15|o>>>17,o=o*f&vs|o*p&ci,i&1?c^=o:u^=o}this.h1=c,this.h2=u}hexdigest(){let t=this.h1,e=this.h2;return t^=e>>>1,t=t*3981806797&vs|t*36045&ci,e=e*4283543511&vs|((e<<16|t>>>16)*2950163797&vs)>>>16,t^=e>>>1,t=t*444984403&vs|t*60499&ci,e=e*3301882366&vs|((e<<16|t>>>16)*3120437893&vs)>>>16,t^=e>>>1,(t>>>0).toString(16).padStart(8,"0")+(e>>>0).toString(16).padStart(8,"0")}}const wg=Object.freeze({map:null,hash:"",transfer:void 0});class xg{constructor(){y(this,gd);y(this,Qr,!1);y(this,Jr,null);y(this,ie,new Map);this.onSetModified=null,this.onResetModified=null,this.onAnnotationEditor=null}getValue(t,e){const s=l(this,ie).get(t);return s===void 0?e:Object.assign(e,s)}getRawValue(t){return l(this,ie).get(t)}remove(t){if(l(this,ie).delete(t),l(this,ie).size===0&&this.resetModified(),typeof this.onAnnotationEditor=="function"){for(const e of l(this,ie).values())if(e instanceof Pt)return;this.onAnnotationEditor(null)}}setValue(t,e){const s=l(this,ie).get(t);let i=!1;if(s!==void 0)for(const[n,r]of Object.entries(e))s[n]!==r&&(i=!0,s[n]=r);else i=!0,l(this,ie).set(t,e);i&&w(this,gd,Cy).call(this),e instanceof Pt&&typeof this.onAnnotationEditor=="function"&&this.onAnnotationEditor(e.constructor._type)}has(t){return l(this,ie).has(t)}getAll(){return l(this,ie).size>0?lg(l(this,ie)):null}setAll(t){for(const[e,s]of Object.entries(t))this.setValue(e,s)}get size(){return l(this,ie).size}resetModified(){l(this,Qr)&&(m(this,Qr,!1),typeof this.onResetModified=="function"&&this.onResetModified())}get print(){return new tb(this)}get serializable(){if(l(this,ie).size===0)return wg;const t=new Map,e=new Z0,s=[],i=Object.create(null);let n=!1;for(const[r,o]of l(this,ie)){const h=o instanceof Pt?o.serialize(!1,i):o;h&&(t.set(r,h),e.update(`${r}:${JSON.stringify(h)}`),n||(n=!!h.bitmap))}if(n)for(const r of t.values())r.bitmap&&s.push(r.bitmap);return t.size>0?{map:t,hash:e.hexdigest(),transfer:s}:wg}get editorStats(){let t=null;const e=new Map;for(const s of l(this,ie).values()){if(!(s instanceof Pt))continue;const i=s.telemetryFinalData;if(!i)continue;const{type:n}=i;e.has(n)||e.set(n,Object.getPrototypeOf(s).constructor),t||(t=Object.create(null));const r=t[n]||(t[n]=new Map);for(const[o,h]of Object.entries(i)){if(o==="type")continue;let c=r.get(o);c||(c=new Map,r.set(o,c));const u=c.get(h)??0;c.set(h,u+1)}}for(const[s,i]of e)t[s]=i.computeTelemetryFinalData(t[s]);return t}resetModifiedIds(){m(this,Jr,null)}get modifiedIds(){if(l(this,Jr))return l(this,Jr);const t=[];for(const e of l(this,ie).values())!(e instanceof Pt)||!e.annotationElementId||!e.serialize()||t.push(e.annotationElementId);return m(this,Jr,{ids:new Set(t),hash:t.join(",")})}}Qr=new WeakMap,Jr=new WeakMap,ie=new WeakMap,gd=new WeakSet,Cy=function(){l(this,Qr)||(m(this,Qr,!0),typeof this.onSetModified=="function"&&this.onSetModified())};class tb extends xg{constructor(e){super();y(this,Al);const{map:s,hash:i,transfer:n}=e.serializable,r=structuredClone(s,n?{transfer:n}:null);m(this,Al,{map:r,hash:i,transfer:n})}get print(){vt("Should not call PrintAnnotationStorage.print")}get serializable(){return l(this,Al)}get modifiedIds(){return st(this,"modifiedIds",{ids:new Set,hash:""})}}Al=new WeakMap;class yx{constructor({ownerDocument:t=globalThis.document,styleElement:e=null}){y(this,Sa,new Set);this._document=t,this.nativeFontFaces=new Set,this.styleElement=null,this.loadingRequests=[],this.loadTestFontId=0}addNativeFontFace(t){this.nativeFontFaces.add(t),this._document.fonts.add(t)}removeNativeFontFace(t){this.nativeFontFaces.delete(t),this._document.fonts.delete(t)}insertRule(t){this.styleElement||(this.styleElement=this._document.createElement("style"),this._document.documentElement.getElementsByTagName("head")[0].append(this.styleElement));const e=this.styleElement.sheet;e.insertRule(t,e.cssRules.length)}clear(){for(const t of this.nativeFontFaces)this._document.fonts.delete(t);this.nativeFontFaces.clear(),l(this,Sa).clear(),this.styleElement&&(this.styleElement.remove(),this.styleElement=null)}async loadSystemFont({systemFontInfo:t,_inspectFont:e}){if(!(!t||l(this,Sa).has(t.loadedName))){if(Xt(!this.disableFontFace,"loadSystemFont shouldn't be called when `disableFontFace` is set."),this.isFontLoadingAPISupported){const{loadedName:s,src:i,style:n}=t,r=new FontFace(s,i,n);this.addNativeFontFace(r);try{await r.load(),l(this,Sa).add(s),e==null||e(t)}catch{tt(`Cannot load system font: ${t.baseFontName}, installing it could help to improve PDF rendering.`),this.removeNativeFontFace(r)}return}vt("Not implemented: loadSystemFont without the Font Loading API.")}}async bind(t){if(t.attached||t.missingFile&&!t.systemFontInfo)return;if(t.attached=!0,t.systemFontInfo){await this.loadSystemFont(t);return}if(this.isFontLoadingAPISupported){const s=t.createNativeFontFace();if(s){this.addNativeFontFace(s);try{await s.loaded}catch(i){throw tt(`Failed to load font '${s.family}': '${i}'.`),t.disableFontFace=!0,i}}return}const e=t.createFontFaceRule();if(e){if(this.insertRule(e),this.isSyncFontLoadingSupported)return;await new Promise(s=>{const i=this._queueLoadingCallback(s);this._prepareFontLoadEvent(t,i)})}}get isFontLoadingAPISupported(){var e;const t=!!((e=this._document)!=null&&e.fonts);return st(this,"isFontLoadingAPISupported",t)}get isSyncFontLoadingSupported(){let t=!1;return(ye||typeof navigator<"u"&&typeof(navigator==null?void 0:navigator.userAgent)=="string"&&/Mozilla\/5.0.*?rv:\d+.*? Gecko/.test(navigator.userAgent))&&(t=!0),st(this,"isSyncFontLoadingSupported",t)}_queueLoadingCallback(t){function e(){for(Xt(!i.done,"completeRequest() cannot be called twice."),i.done=!0;s.length>0&&s[0].done;){const n=s.shift();setTimeout(n.callback,0)}}const{loadingRequests:s}=this,i={done:!1,complete:e,callback:t};return s.push(i),i}get _loadTestFont(){const t=atob("T1RUTwALAIAAAwAwQ0ZGIDHtZg4AAAOYAAAAgUZGVE1lkzZwAAAEHAAAABxHREVGABQAFQAABDgAAAAeT1MvMlYNYwkAAAEgAAAAYGNtYXABDQLUAAACNAAAAUJoZWFk/xVFDQAAALwAAAA2aGhlYQdkA+oAAAD0AAAAJGhtdHgD6AAAAAAEWAAAAAZtYXhwAAJQAAAAARgAAAAGbmFtZVjmdH4AAAGAAAAAsXBvc3T/hgAzAAADeAAAACAAAQAAAAEAALZRFsRfDzz1AAsD6AAAAADOBOTLAAAAAM4KHDwAAAAAA+gDIQAAAAgAAgAAAAAAAAABAAADIQAAAFoD6AAAAAAD6AABAAAAAAAAAAAAAAAAAAAAAQAAUAAAAgAAAAQD6AH0AAUAAAKKArwAAACMAooCvAAAAeAAMQECAAACAAYJAAAAAAAAAAAAAQAAAAAAAAAAAAAAAFBmRWQAwAAuAC4DIP84AFoDIQAAAAAAAQAAAAAAAAAAACAAIAABAAAADgCuAAEAAAAAAAAAAQAAAAEAAAAAAAEAAQAAAAEAAAAAAAIAAQAAAAEAAAAAAAMAAQAAAAEAAAAAAAQAAQAAAAEAAAAAAAUAAQAAAAEAAAAAAAYAAQAAAAMAAQQJAAAAAgABAAMAAQQJAAEAAgABAAMAAQQJAAIAAgABAAMAAQQJAAMAAgABAAMAAQQJAAQAAgABAAMAAQQJAAUAAgABAAMAAQQJAAYAAgABWABYAAAAAAAAAwAAAAMAAAAcAAEAAAAAADwAAwABAAAAHAAEACAAAAAEAAQAAQAAAC7//wAAAC7////TAAEAAAAAAAABBgAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMAAAAAAAD/gwAyAAAAAQAAAAAAAAAAAAAAAAAAAAABAAQEAAEBAQJYAAEBASH4DwD4GwHEAvgcA/gXBIwMAYuL+nz5tQXkD5j3CBLnEQACAQEBIVhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYAAABAQAADwACAQEEE/t3Dov6fAH6fAT+fPp8+nwHDosMCvm1Cvm1DAz6fBQAAAAAAAABAAAAAMmJbzEAAAAAzgTjFQAAAADOBOQpAAEAAAAAAAAADAAUAAQAAAABAAAAAgABAAAAAAAAAAAD6AAAAAAAAA==");return st(this,"_loadTestFont",t)}_prepareFontLoadEvent(t,e){function s(S,k){return S.charCodeAt(k)<<24|S.charCodeAt(k+1)<<16|S.charCodeAt(k+2)<<8|S.charCodeAt(k+3)&255}function i(S,k,M,E){const P=S.substring(0,k),O=S.substring(k+M);return P+E+O}let n,r;const o=this._document.createElement("canvas");o.width=1,o.height=1;const h=o.getContext("2d");let c=0;function u(S,k){if(++c>30){tt("Load test font never loaded."),k();return}if(h.font="30px "+S,h.fillText(".",0,20),h.getImageData(0,0,1,1).data[3]>0){k();return}setTimeout(u.bind(null,S,k))}const d=`lt${Date.now()}${this.loadTestFontId++}`;let f=this._loadTestFont;f=i(f,976,d.length,d);const p=16,b=1482184792;let _=s(f,p);for(n=0,r=d.length-3;n<r;n+=4)_=_-b+s(d,n)|0;n<d.length&&(_=_-b+s(d+"XXX",n)|0),f=i(f,p,4,ix(_));const v=`url(data:font/opentype;base64,${btoa(f)});`,x=`@font-face {font-family:"${d}";src:${v}}`;this.insertRule(x);const C=this._document.createElement("div");C.style.visibility="hidden",C.style.width=C.style.height="10px",C.style.position="absolute",C.style.top=C.style.left="0px";for(const S of[t.loadedName,d]){const k=this._document.createElement("span");k.textContent="Hi",k.style.fontFamily=S,C.append(k)}this._document.body.append(C),u(d,()=>{C.remove(),e.complete()})}}Sa=new WeakMap;class vx{constructor(t,{disableFontFace:e=!1,fontExtraProperties:s=!1,inspectFont:i=null}){this.compiledGlyphs=Object.create(null);for(const n in t)this[n]=t[n];this.disableFontFace=e===!0,this.fontExtraProperties=s===!0,this._inspectFont=i}createNativeFontFace(){var e;if(!this.data||this.disableFontFace)return null;let t;if(!this.cssFontInfo)t=new FontFace(this.loadedName,this.data,{});else{const s={weight:this.cssFontInfo.fontWeight};this.cssFontInfo.italicAngle&&(s.style=`oblique ${this.cssFontInfo.italicAngle}deg`),t=new FontFace(this.cssFontInfo.fontFamily,this.data,s)}return(e=this._inspectFont)==null||e.call(this,this),t}createFontFaceRule(){var s;if(!this.data||this.disableFontFace)return null;const t=`url(data:${this.mimetype};base64,${lx(this.data)});`;let e;if(!this.cssFontInfo)e=`@font-face {font-family:"${this.loadedName}";src:${t}}`;else{let i=`font-weight: ${this.cssFontInfo.fontWeight};`;this.cssFontInfo.italicAngle&&(i+=`font-style: oblique ${this.cssFontInfo.italicAngle}deg;`),e=`@font-face {font-family:"${this.cssFontInfo.fontFamily}";${i}src:${t}}`}return(s=this._inspectFont)==null||s.call(this,this,t),e}getPathGenerator(t,e){if(this.compiledGlyphs[e]!==void 0)return this.compiledGlyphs[e];const s=this.loadedName+"_path_"+e;let i;try{i=t.get(s)}catch(r){tt(`getPathGenerator - ignoring character: "${r}".`)}const n=new Path2D(i||"");return this.fontExtraProperties||t.delete(s),this.compiledGlyphs[e]=n}}const Ju={DATA:1,ERROR:2},Wt={CANCEL:1,CANCEL_COMPLETE:2,CLOSE:3,ENQUEUE:4,ERROR:5,PULL:6,PULL_COMPLETE:7,START_COMPLETE:8};function eb(){}function We(a){if(a instanceof Rn||a instanceof hg||a instanceof Gh||a instanceof $0||a instanceof Wu||a instanceof ag)return a;switch(a instanceof Error||typeof a=="object"&&a!==null||vt('wrapReason: Expected "reason" to be a (possibly cloned) Error.'),a.name){case"AbortException":return new Rn(a.message);case"InvalidPDFException":return new hg(a.message);case"MissingPDFException":return new Gh(a.message);case"PasswordException":return new $0(a.message,a.code);case"UnexpectedResponseException":return new Wu(a.message,a.status);case"UnknownErrorException":return new ag(a.message,a.details)}return new ag(a.message,a.toString())}class Wh{constructor(t,e,s){y(this,Cs);y(this,Ca,new AbortController);this.sourceName=t,this.targetName=e,this.comObj=s,this.callbackId=1,this.streamId=1,this.streamSinks=Object.create(null),this.streamControllers=Object.create(null),this.callbackCapabilities=Object.create(null),this.actionHandler=Object.create(null),s.addEventListener("message",w(this,Cs,Ay).bind(this),{signal:l(this,Ca).signal})}on(t,e){const s=this.actionHandler;if(s[t])throw new Error(`There is already an actionName called "${t}"`);s[t]=e}send(t,e,s){this.comObj.postMessage({sourceName:this.sourceName,targetName:this.targetName,action:t,data:e},s)}sendWithPromise(t,e,s){const i=this.callbackId++,n=Promise.withResolvers();this.callbackCapabilities[i]=n;try{this.comObj.postMessage({sourceName:this.sourceName,targetName:this.targetName,action:t,callbackId:i,data:e},s)}catch(r){n.reject(r)}return n.promise}sendWithStream(t,e,s,i){const n=this.streamId++,r=this.sourceName,o=this.targetName,h=this.comObj;return new ReadableStream({start:c=>{const u=Promise.withResolvers();return this.streamControllers[n]={controller:c,startCall:u,pullCall:null,cancelCall:null,isClosed:!1},h.postMessage({sourceName:r,targetName:o,action:t,streamId:n,data:e,desiredSize:c.desiredSize},i),u.promise},pull:c=>{const u=Promise.withResolvers();return this.streamControllers[n].pullCall=u,h.postMessage({sourceName:r,targetName:o,stream:Wt.PULL,streamId:n,desiredSize:c.desiredSize}),u.promise},cancel:c=>{Xt(c instanceof Error,"cancel must have a valid reason");const u=Promise.withResolvers();return this.streamControllers[n].cancelCall=u,this.streamControllers[n].isClosed=!0,h.postMessage({sourceName:r,targetName:o,stream:Wt.CANCEL,streamId:n,reason:We(c)}),u.promise}},s)}destroy(){var t;(t=l(this,Ca))==null||t.abort(),m(this,Ca,null)}}Ca=new WeakMap,Cs=new WeakSet,Ay=function({data:t}){if(t.targetName!==this.sourceName)return;if(t.stream){w(this,Cs,Ey).call(this,t);return}if(t.callback){const s=t.callbackId,i=this.callbackCapabilities[s];if(!i)throw new Error(`Cannot resolve callback ${s}`);if(delete this.callbackCapabilities[s],t.callback===Ju.DATA)i.resolve(t.data);else if(t.callback===Ju.ERROR)i.reject(We(t.reason));else throw new Error("Unexpected callback case");return}const e=this.actionHandler[t.action];if(!e)throw new Error(`Unknown action from worker: ${t.action}`);if(t.callbackId){const s=this.sourceName,i=t.sourceName,n=this.comObj;Promise.try(e,t.data).then(function(r){n.postMessage({sourceName:s,targetName:i,callback:Ju.DATA,callbackId:t.callbackId,data:r})},function(r){n.postMessage({sourceName:s,targetName:i,callback:Ju.ERROR,callbackId:t.callbackId,reason:We(r)})});return}if(t.streamId){w(this,Cs,Ty).call(this,t);return}e(t.data)},Ty=function(t){const e=t.streamId,s=this.sourceName,i=t.sourceName,n=this.comObj,r=this,o=this.actionHandler[t.action],h={enqueue(c,u=1,d){if(this.isCancelled)return;const f=this.desiredSize;this.desiredSize-=u,f>0&&this.desiredSize<=0&&(this.sinkCapability=Promise.withResolvers(),this.ready=this.sinkCapability.promise),n.postMessage({sourceName:s,targetName:i,stream:Wt.ENQUEUE,streamId:e,chunk:c},d)},close(){this.isCancelled||(this.isCancelled=!0,n.postMessage({sourceName:s,targetName:i,stream:Wt.CLOSE,streamId:e}),delete r.streamSinks[e])},error(c){Xt(c instanceof Error,"error must have a valid reason"),!this.isCancelled&&(this.isCancelled=!0,n.postMessage({sourceName:s,targetName:i,stream:Wt.ERROR,streamId:e,reason:We(c)}))},sinkCapability:Promise.withResolvers(),onPull:null,onCancel:null,isCancelled:!1,desiredSize:t.desiredSize,ready:null};h.sinkCapability.resolve(),h.ready=h.sinkCapability.promise,this.streamSinks[e]=h,Promise.try(o,t.data,h).then(function(){n.postMessage({sourceName:s,targetName:i,stream:Wt.START_COMPLETE,streamId:e,success:!0})},function(c){n.postMessage({sourceName:s,targetName:i,stream:Wt.START_COMPLETE,streamId:e,reason:We(c)})})},Ey=function(t){const e=t.streamId,s=this.sourceName,i=t.sourceName,n=this.comObj,r=this.streamControllers[e],o=this.streamSinks[e];switch(t.stream){case Wt.START_COMPLETE:t.success?r.startCall.resolve():r.startCall.reject(We(t.reason));break;case Wt.PULL_COMPLETE:t.success?r.pullCall.resolve():r.pullCall.reject(We(t.reason));break;case Wt.PULL:if(!o){n.postMessage({sourceName:s,targetName:i,stream:Wt.PULL_COMPLETE,streamId:e,success:!0});break}o.desiredSize<=0&&t.desiredSize>0&&o.sinkCapability.resolve(),o.desiredSize=t.desiredSize,Promise.try(o.onPull||eb).then(function(){n.postMessage({sourceName:s,targetName:i,stream:Wt.PULL_COMPLETE,streamId:e,success:!0})},function(c){n.postMessage({sourceName:s,targetName:i,stream:Wt.PULL_COMPLETE,streamId:e,reason:We(c)})});break;case Wt.ENQUEUE:if(Xt(r,"enqueue should have stream controller"),r.isClosed)break;r.controller.enqueue(t.chunk);break;case Wt.CLOSE:if(Xt(r,"close should have stream controller"),r.isClosed)break;r.isClosed=!0,r.controller.close(),w(this,Cs,Id).call(this,r,e);break;case Wt.ERROR:Xt(r,"error should have stream controller"),r.controller.error(We(t.reason)),w(this,Cs,Id).call(this,r,e);break;case Wt.CANCEL_COMPLETE:t.success?r.cancelCall.resolve():r.cancelCall.reject(We(t.reason)),w(this,Cs,Id).call(this,r,e);break;case Wt.CANCEL:if(!o)break;const h=We(t.reason);Promise.try(o.onCancel||eb,h).then(function(){n.postMessage({sourceName:s,targetName:i,stream:Wt.CANCEL_COMPLETE,streamId:e,success:!0})},function(c){n.postMessage({sourceName:s,targetName:i,stream:Wt.CANCEL_COMPLETE,streamId:e,reason:We(c)})}),o.sinkCapability.reject(h),o.isCancelled=!0,delete this.streamSinks[e];break;default:throw new Error("Unexpected stream case")}},Id=async function(t,e){var s,i,n;await Promise.allSettled([(s=t.startCall)==null?void 0:s.promise,(i=t.pullCall)==null?void 0:i.promise,(n=t.cancelCall)==null?void 0:n.promise]),delete this.streamControllers[e]};class sb{constructor({enableHWA:t=!1}){y(this,Tl,!1);m(this,Tl,t)}create(t,e){if(t<=0||e<=0)throw new Error("Invalid canvas size");const s=this._createCanvas(t,e);return{canvas:s,context:s.getContext("2d",{willReadFrequently:!l(this,Tl)})}}reset(t,e,s){if(!t.canvas)throw new Error("Canvas is not specified");if(e<=0||s<=0)throw new Error("Invalid canvas size");t.canvas.width=e,t.canvas.height=s}destroy(t){if(!t.canvas)throw new Error("Canvas is not specified");t.canvas.width=0,t.canvas.height=0,t.canvas=null,t.context=null}_createCanvas(t,e){vt("Abstract method `_createCanvas` called.")}}Tl=new WeakMap;class _x extends sb{constructor({ownerDocument:t=globalThis.document,enableHWA:e=!1}){super({enableHWA:e}),this._document=t}_createCanvas(t,e){const s=this._document.createElement("canvas");return s.width=t,s.height=e,s}}class ib{constructor({baseUrl:t=null,isCompressed:e=!0}){this.baseUrl=t,this.isCompressed=e}async fetch({name:t}){if(!this.baseUrl)throw new Error("Ensure that the `cMapUrl` and `cMapPacked` API parameters are provided.");if(!t)throw new Error("CMap name must be specified.");const e=this.baseUrl+t+(this.isCompressed?".bcmap":"");return this._fetch(e).then(s=>({cMapData:s,isCompressed:this.isCompressed})).catch(s=>{throw new Error(`Unable to load ${this.isCompressed?"binary ":""}CMap at: ${e}`)})}async _fetch(t){vt("Abstract method `_fetch` called.")}}class nb extends ib{async _fetch(t){const e=await Yu(t,this.isCompressed?"arraybuffer":"text");return e instanceof ArrayBuffer?new Uint8Array(e):Uu(e)}}class rb{addFilter(t){return"none"}addHCMFilter(t,e){return"none"}addAlphaFilter(t){return"none"}addLuminosityFilter(t){return"none"}addHighlightHCMFilter(t,e,s,i,n){return"none"}destroy(t=!1){}}class wx extends rb{constructor({docId:e,ownerDocument:s=globalThis.document}){super();y(this,j);y(this,Zr);y(this,Aa);y(this,tn);y(this,en);y(this,xe);y(this,to);y(this,eo,0);m(this,en,e),m(this,xe,s)}addFilter(e){if(!e)return"none";let s=l(this,j,Te).get(e);if(s)return s;const[i,n,r]=w(this,j,Nd).call(this,e),o=e.length===1?i:`${i}${n}${r}`;if(s=l(this,j,Te).get(o),s)return l(this,j,Te).set(e,s),s;const h=`g_${l(this,en)}_transfer_map_${Ge(this,eo)._++}`,c=w(this,j,bh).call(this,h);l(this,j,Te).set(e,c),l(this,j,Te).set(o,c);const u=w(this,j,yh).call(this,h);return w(this,j,Pc).call(this,i,n,r,u),c}addHCMFilter(e,s){var p;const i=`${e}-${s}`,n="base";let r=l(this,j,kc).get(n);if((r==null?void 0:r.key)===i||(r?((p=r.filter)==null||p.remove(),r.key=i,r.url="none",r.filter=null):(r={key:i,url:"none",filter:null},l(this,j,kc).set(n,r)),!e||!s))return r.url;const o=w(this,j,Dc).call(this,e);e=W.makeHexColor(...o);const h=w(this,j,Dc).call(this,s);if(s=W.makeHexColor(...h),l(this,j,mh).style.color="",e==="#000000"&&s==="#ffffff"||e===s)return r.url;const c=new Array(256);for(let b=0;b<=255;b++){const _=b/255;c[b]=_<=.03928?_/12.92:((_+.055)/1.055)**2.4}const u=c.join(","),d=`g_${l(this,en)}_hcm_filter`,f=r.filter=w(this,j,yh).call(this,d);w(this,j,Pc).call(this,u,u,u,f),w(this,j,dp).call(this,f);const g=(b,_)=>{const v=o[b]/255,x=h[b]/255,C=new Array(_+1);for(let S=0;S<=_;S++)C[S]=v+S/_*(x-v);return C.join(",")};return w(this,j,Pc).call(this,g(0,5),g(1,5),g(2,5),f),r.url=w(this,j,bh).call(this,d),r.url}addAlphaFilter(e){let s=l(this,j,Te).get(e);if(s)return s;const[i]=w(this,j,Nd).call(this,[e]),n=`alpha_${i}`;if(s=l(this,j,Te).get(n),s)return l(this,j,Te).set(e,s),s;const r=`g_${l(this,en)}_alpha_map_${Ge(this,eo)._++}`,o=w(this,j,bh).call(this,r);l(this,j,Te).set(e,o),l(this,j,Te).set(n,o);const h=w(this,j,yh).call(this,r);return w(this,j,fp).call(this,i,h),o}addLuminosityFilter(e){let s=l(this,j,Te).get(e||"luminosity");if(s)return s;let i,n;if(e?([i]=w(this,j,Nd).call(this,[e]),n=`luminosity_${i}`):n="luminosity",s=l(this,j,Te).get(n),s)return l(this,j,Te).set(e,s),s;const r=`g_${l(this,en)}_luminosity_map_${Ge(this,eo)._++}`,o=w(this,j,bh).call(this,r);l(this,j,Te).set(e,o),l(this,j,Te).set(n,o);const h=w(this,j,yh).call(this,r);return w(this,j,ky).call(this,h),e&&w(this,j,fp).call(this,i,h),o}addHighlightHCMFilter(e,s,i,n,r){var x;const o=`${s}-${i}-${n}-${r}`;let h=l(this,j,kc).get(e);if((h==null?void 0:h.key)===o||(h?((x=h.filter)==null||x.remove(),h.key=o,h.url="none",h.filter=null):(h={key:o,url:"none",filter:null},l(this,j,kc).set(e,h)),!s||!i))return h.url;const[c,u]=[s,i].map(w(this,j,Dc).bind(this));let d=Math.round(.2126*c[0]+.7152*c[1]+.0722*c[2]),f=Math.round(.2126*u[0]+.7152*u[1]+.0722*u[2]),[g,p]=[n,r].map(w(this,j,Dc).bind(this));f<d&&([d,f,g,p]=[f,d,p,g]),l(this,j,mh).style.color="";const b=(C,S,k)=>{const M=new Array(256),E=(f-d)/k,P=C/255,O=(S-C)/(255*k);let L=0;for(let R=0;R<=k;R++){const U=Math.round(d+R*E),z=P+R*O;for(let V=L;V<=U;V++)M[V]=z;L=U+1}for(let R=L;R<256;R++)M[R]=M[L-1];return M.join(",")},_=`g_${l(this,en)}_hcm_${e}_filter`,v=h.filter=w(this,j,yh).call(this,_);return w(this,j,dp).call(this,v),w(this,j,Pc).call(this,b(g[0],p[0],5),b(g[1],p[1],5),b(g[2],p[2],5),v),h.url=w(this,j,bh).call(this,_),h.url}destroy(e=!1){var s,i,n,r;e&&((s=l(this,to))!=null&&s.size)||((i=l(this,tn))==null||i.parentNode.parentNode.remove(),m(this,tn,null),(n=l(this,Aa))==null||n.clear(),m(this,Aa,null),(r=l(this,to))==null||r.clear(),m(this,to,null),m(this,eo,0))}}Zr=new WeakMap,Aa=new WeakMap,tn=new WeakMap,en=new WeakMap,xe=new WeakMap,to=new WeakMap,eo=new WeakMap,j=new WeakSet,Te=function(){return l(this,Aa)||m(this,Aa,new Map)},kc=function(){return l(this,to)||m(this,to,new Map)},mh=function(){if(!l(this,tn)){const e=l(this,xe).createElement("div"),{style:s}=e;s.visibility="hidden",s.contain="strict",s.width=s.height=0,s.position="absolute",s.top=s.left=0,s.zIndex=-1;const i=l(this,xe).createElementNS(zi,"svg");i.setAttribute("width",0),i.setAttribute("height",0),m(this,tn,l(this,xe).createElementNS(zi,"defs")),e.append(i),i.append(l(this,tn)),l(this,xe).body.append(e)}return l(this,tn)},Nd=function(e){if(e.length===1){const c=e[0],u=new Array(256);for(let f=0;f<256;f++)u[f]=c[f]/255;const d=u.join(",");return[d,d,d]}const[s,i,n]=e,r=new Array(256),o=new Array(256),h=new Array(256);for(let c=0;c<256;c++)r[c]=s[c]/255,o[c]=i[c]/255,h[c]=n[c]/255;return[r.join(","),o.join(","),h.join(",")]},bh=function(e){if(l(this,Zr)===void 0){m(this,Zr,"");const s=l(this,xe).URL;s!==l(this,xe).baseURI&&($u(s)?tt('#createUrl: ignore "data:"-URL for performance reasons.'):m(this,Zr,s.split("#",1)[0]))}return`url(${l(this,Zr)}#${e})`},ky=function(e){const s=l(this,xe).createElementNS(zi,"feColorMatrix");s.setAttribute("type","matrix"),s.setAttribute("values","0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.3 0.59 0.11 0 0"),e.append(s)},dp=function(e){const s=l(this,xe).createElementNS(zi,"feColorMatrix");s.setAttribute("type","matrix"),s.setAttribute("values","0.2126 0.7152 0.0722 0 0 0.2126 0.7152 0.0722 0 0 0.2126 0.7152 0.0722 0 0 0 0 0 1 0"),e.append(s)},yh=function(e){const s=l(this,xe).createElementNS(zi,"filter");return s.setAttribute("color-interpolation-filters","sRGB"),s.setAttribute("id",e),l(this,j,mh).append(s),s},Mc=function(e,s,i){const n=l(this,xe).createElementNS(zi,s);n.setAttribute("type","discrete"),n.setAttribute("tableValues",i),e.append(n)},Pc=function(e,s,i,n){const r=l(this,xe).createElementNS(zi,"feComponentTransfer");n.append(r),w(this,j,Mc).call(this,r,"feFuncR",e),w(this,j,Mc).call(this,r,"feFuncG",s),w(this,j,Mc).call(this,r,"feFuncB",i)},fp=function(e,s){const i=l(this,xe).createElementNS(zi,"feComponentTransfer");s.append(i),w(this,j,Mc).call(this,i,"feFuncA",e)},Dc=function(e){return l(this,j,mh).style.color=e,mg(getComputedStyle(l(this,j,mh)).getPropertyValue("color"))};class ob{constructor({baseUrl:t=null}){this.baseUrl=t}async fetch({filename:t}){if(!this.baseUrl)throw new Error("Ensure that the `standardFontDataUrl` API parameter is provided.");if(!t)throw new Error("Font filename must be specified.");const e=`${this.baseUrl}${t}`;return this._fetch(e).catch(s=>{throw new Error(`Unable to load font data at: ${e}`)})}async _fetch(t){vt("Abstract method `_fetch` called.")}}class ab extends ob{async _fetch(t){const e=await Yu(t,"arraybuffer");return new Uint8Array(e)}}ye&&tt("Please use the `legacy` build in Node.js environments.");async function hb(a){const e=await process.getBuiltinModule("fs").promises.readFile(a);return new Uint8Array(e)}class xx extends rb{}class Sx extends sb{_createCanvas(t,e){return process.getBuiltinModule("module").createRequire(typeof document>"u"&&typeof location>"u"?require("url").pathToFileURL(__filename).href:typeof document>"u"?location.href:_t&&_t.tagName.toUpperCase()==="SCRIPT"&&_t.src||new URL("pdf-canvas.umd.js",document.baseURI).href)("@napi-rs/canvas").createCanvas(t,e)}}class Cx extends ib{async _fetch(t){return hb(t)}}class Ax extends ob{async _fetch(t){return hb(t)}}const _e={FILL:"Fill",STROKE:"Stroke",SHADING:"Shading"};function Sg(a,t){if(!t)return;const e=t[2]-t[0],s=t[3]-t[1],i=new Path2D;i.rect(t[0],t[1],e,s),a.clip(i)}class Cg{getPattern(){vt("Abstract method `getPattern` called.")}}class Tx extends Cg{constructor(t){super(),this._type=t[1],this._bbox=t[2],this._colorStops=t[3],this._p0=t[4],this._p1=t[5],this._r0=t[6],this._r1=t[7],this.matrix=null}_createGradient(t){let e;this._type==="axial"?e=t.createLinearGradient(this._p0[0],this._p0[1],this._p1[0],this._p1[1]):this._type==="radial"&&(e=t.createRadialGradient(this._p0[0],this._p0[1],this._r0,this._p1[0],this._p1[1],this._r1));for(const s of this._colorStops)e.addColorStop(s[0],s[1]);return e}getPattern(t,e,s,i){let n;if(i===_e.STROKE||i===_e.FILL){const r=e.current.getClippedPathBoundingBox(i,Tt(t))||[0,0,0,0],o=Math.ceil(r[2]-r[0])||1,h=Math.ceil(r[3]-r[1])||1,c=e.cachedCanvases.getCanvas("pattern",o,h),u=c.context;u.clearRect(0,0,u.canvas.width,u.canvas.height),u.beginPath(),u.rect(0,0,u.canvas.width,u.canvas.height),u.translate(-r[0],-r[1]),s=W.transform(s,[1,0,0,1,r[0],r[1]]),u.transform(...e.baseTransform),this.matrix&&u.transform(...this.matrix),Sg(u,this._bbox),u.fillStyle=this._createGradient(u),u.fill(),n=t.createPattern(c.canvas,"no-repeat");const d=new DOMMatrix(s);n.setTransform(d)}else Sg(t,this._bbox),n=this._createGradient(t);return n}}function Ag(a,t,e,s,i,n,r,o){const h=t.coords,c=t.colors,u=a.data,d=a.width*4;let f;h[e+1]>h[s+1]&&(f=e,e=s,s=f,f=n,n=r,r=f),h[s+1]>h[i+1]&&(f=s,s=i,i=f,f=r,r=o,o=f),h[e+1]>h[s+1]&&(f=e,e=s,s=f,f=n,n=r,r=f);const g=(h[e]+t.offsetX)*t.scaleX,p=(h[e+1]+t.offsetY)*t.scaleY,b=(h[s]+t.offsetX)*t.scaleX,_=(h[s+1]+t.offsetY)*t.scaleY,v=(h[i]+t.offsetX)*t.scaleX,x=(h[i+1]+t.offsetY)*t.scaleY;if(p>=x)return;const C=c[n],S=c[n+1],k=c[n+2],M=c[r],E=c[r+1],P=c[r+2],O=c[o],L=c[o+1],R=c[o+2],U=Math.round(p),z=Math.round(x);let V,at,F,G,rt,Gt,te,fe;for(let Yt=U;Yt<=z;Yt++){if(Yt<_){const ft=Yt<p?0:(p-Yt)/(p-_);V=g-(g-b)*ft,at=C-(C-M)*ft,F=S-(S-E)*ft,G=k-(k-P)*ft}else{let ft;Yt>x?ft=1:_===x?ft=0:ft=(_-Yt)/(_-x),V=b-(b-v)*ft,at=M-(M-O)*ft,F=E-(E-L)*ft,G=P-(P-R)*ft}let St;Yt<p?St=0:Yt>x?St=1:St=(p-Yt)/(p-x),rt=g-(g-v)*St,Gt=C-(C-O)*St,te=S-(S-L)*St,fe=k-(k-R)*St;const He=Math.round(Math.min(V,rt)),Mi=Math.round(Math.max(V,rt));let Ft=d*Yt+He*4;for(let ft=He;ft<=Mi;ft++)St=(V-ft)/(V-rt),St<0?St=0:St>1&&(St=1),u[Ft++]=at-(at-Gt)*St|0,u[Ft++]=F-(F-te)*St|0,u[Ft++]=G-(G-fe)*St|0,u[Ft++]=255}}function Ex(a,t,e){const s=t.coords,i=t.colors;let n,r;switch(t.type){case"lattice":const o=t.verticesPerRow,h=Math.floor(s.length/o)-1,c=o-1;for(n=0;n<h;n++){let u=n*o;for(let d=0;d<c;d++,u++)Ag(a,e,s[u],s[u+1],s[u+o],i[u],i[u+1],i[u+o]),Ag(a,e,s[u+o+1],s[u+1],s[u+o],i[u+o+1],i[u+1],i[u+o])}break;case"triangles":for(n=0,r=s.length;n<r;n+=3)Ag(a,e,s[n],s[n+1],s[n+2],i[n],i[n+1],i[n+2]);break;default:throw new Error("illegal figure")}}class kx extends Cg{constructor(t){super(),this._coords=t[2],this._colors=t[3],this._figures=t[4],this._bounds=t[5],this._bbox=t[7],this._background=t[8],this.matrix=null}_createMeshCanvas(t,e,s){const o=Math.floor(this._bounds[0]),h=Math.floor(this._bounds[1]),c=Math.ceil(this._bounds[2])-o,u=Math.ceil(this._bounds[3])-h,d=Math.min(Math.ceil(Math.abs(c*t[0]*1.1)),3e3),f=Math.min(Math.ceil(Math.abs(u*t[1]*1.1)),3e3),g=c/d,p=u/f,b={coords:this._coords,colors:this._colors,offsetX:-o,offsetY:-h,scaleX:1/g,scaleY:1/p},_=d+2*2,v=f+2*2,x=s.getCanvas("mesh",_,v),C=x.context,S=C.createImageData(d,f);if(e){const M=S.data;for(let E=0,P=M.length;E<P;E+=4)M[E]=e[0],M[E+1]=e[1],M[E+2]=e[2],M[E+3]=255}for(const M of this._figures)Ex(S,M,b);return C.putImageData(S,2,2),{canvas:x.canvas,offsetX:o-2*g,offsetY:h-2*p,scaleX:g,scaleY:p}}getPattern(t,e,s,i){Sg(t,this._bbox);let n;if(i===_e.SHADING)n=W.singularValueDecompose2dScale(Tt(t));else if(n=W.singularValueDecompose2dScale(e.baseTransform),this.matrix){const o=W.singularValueDecompose2dScale(this.matrix);n=[n[0]*o[0],n[1]*o[1]]}const r=this._createMeshCanvas(n,i===_e.SHADING?null:this._background,e.cachedCanvases);return i!==_e.SHADING&&(t.setTransform(...e.baseTransform),this.matrix&&t.transform(...this.matrix)),t.translate(r.offsetX,r.offsetY),t.scale(r.scaleX,r.scaleY),t.createPattern(r.canvas,"no-repeat")}}class Mx extends Cg{getPattern(){return"hotpink"}}function Px(a){switch(a[0]){case"RadialAxial":return new Tx(a);case"Mesh":return new kx(a);case"Dummy":return new Mx}throw new Error(`Unknown IR type: ${a[0]}`)}const lb={COLORED:1,UNCOLORED:2},pd=class pd{constructor(t,e,s,i,n){this.operatorList=t[2],this.matrix=t[3],this.bbox=t[4],this.xstep=t[5],this.ystep=t[6],this.paintType=t[7],this.tilingType=t[8],this.color=e,this.ctx=s,this.canvasGraphicsFactory=i,this.baseTransform=n}createPatternCanvas(t){const{bbox:e,operatorList:s,paintType:i,tilingType:n,color:r,canvasGraphicsFactory:o}=this;let{xstep:h,ystep:c}=this;h=Math.abs(h),c=Math.abs(c),Xu("TilingType: "+n);const u=e[0],d=e[1],f=e[2],g=e[3],p=f-u,b=g-d,_=W.singularValueDecompose2dScale(this.matrix),v=W.singularValueDecompose2dScale(this.baseTransform),x=_[0]*v[0],C=_[1]*v[1];let S=p,k=b,M=!1,E=!1;const P=Math.ceil(h*x),O=Math.ceil(c*C),L=Math.ceil(p*x),R=Math.ceil(b*C);P>=L?S=h:M=!0,O>=R?k=c:E=!0;const U=this.getSizeAndScale(S,this.ctx.canvas.width,x),z=this.getSizeAndScale(k,this.ctx.canvas.height,C),V=t.cachedCanvases.getCanvas("pattern",U.size,z.size),at=V.context,F=o.createCanvasGraphics(at);if(F.groupLevel=t.groupLevel,this.setFillAndStrokeStyleToContext(F,i,r),at.translate(-U.scale*u,-z.scale*d),F.transform(U.scale,0,0,z.scale,0,0),at.save(),this.clipBbox(F,u,d,f,g),F.baseTransform=Tt(F.ctx),F.executeOperatorList(s),F.endDrawing(),at.restore(),M||E){const G=V.canvas;M&&(S=h),E&&(k=c);const rt=this.getSizeAndScale(S,this.ctx.canvas.width,x),Gt=this.getSizeAndScale(k,this.ctx.canvas.height,C),te=rt.size,fe=Gt.size,Yt=t.cachedCanvases.getCanvas("pattern-workaround",te,fe),St=Yt.context,He=M?Math.floor(p/h):0,Mi=E?Math.floor(b/c):0;for(let Ft=0;Ft<=He;Ft++)for(let ft=0;ft<=Mi;ft++)St.drawImage(G,te*Ft,fe*ft,te,fe,0,0,te,fe);return{canvas:Yt.canvas,scaleX:rt.scale,scaleY:Gt.scale,offsetX:u,offsetY:d}}return{canvas:V.canvas,scaleX:U.scale,scaleY:z.scale,offsetX:u,offsetY:d}}getSizeAndScale(t,e,s){const i=Math.max(pd.MAX_PATTERN_SIZE,e);let n=Math.ceil(t*s);return n>=i?n=i:s=n/t,{scale:s,size:n}}clipBbox(t,e,s,i,n){const r=i-e,o=n-s;t.ctx.rect(e,s,r,o),t.current.updateRectMinMax(Tt(t.ctx),[e,s,i,n]),t.clip(),t.endPath()}setFillAndStrokeStyleToContext(t,e,s){const i=t.ctx,n=t.current;switch(e){case lb.COLORED:const r=this.ctx;i.fillStyle=r.fillStyle,i.strokeStyle=r.strokeStyle,n.fillColor=r.fillStyle,n.strokeColor=r.strokeStyle;break;case lb.UNCOLORED:const o=W.makeHexColor(s[0],s[1],s[2]);i.fillStyle=o,i.strokeStyle=o,n.fillColor=o,n.strokeColor=o;break;default:throw new sx(`Unsupported paint type: ${e}`)}}getPattern(t,e,s,i){let n=s;i!==_e.SHADING&&(n=W.transform(n,e.baseTransform),this.matrix&&(n=W.transform(n,this.matrix)));const r=this.createPatternCanvas(e);let o=new DOMMatrix(n);o=o.translate(r.offsetX,r.offsetY),o=o.scale(1/r.scaleX,1/r.scaleY);const h=t.createPattern(r.canvas,"repeat");return h.setTransform(o),h}};$(pd,"MAX_PATTERN_SIZE",3e3);let Tg=pd;function Dx({src:a,srcPos:t=0,dest:e,width:s,height:i,nonBlackColor:n=4294967295,inverseDecode:r=!1}){const o=Re.isLittleEndian?4278190080:255,[h,c]=r?[n,o]:[o,n],u=s>>3,d=s&7,f=a.length;e=new Uint32Array(e.buffer);let g=0;for(let p=0;p<i;p++){for(const _=t+u;t<_;t++){const v=t<f?a[t]:255;e[g++]=v&128?c:h,e[g++]=v&64?c:h,e[g++]=v&32?c:h,e[g++]=v&16?c:h,e[g++]=v&8?c:h,e[g++]=v&4?c:h,e[g++]=v&2?c:h,e[g++]=v&1?c:h}if(d===0)continue;const b=t<f?a[t++]:255;for(let _=0;_<d;_++)e[g++]=b&1<<7-_?c:h}return{srcPos:t,destPos:g}}const cb=16,ub=100,Ox=15,db=10,fb=1e3,Ue=16;function Rx(a,t){if(a._removeMirroring)throw new Error("Context is already forwarding operations.");a.__originalSave=a.save,a.__originalRestore=a.restore,a.__originalRotate=a.rotate,a.__originalScale=a.scale,a.__originalTranslate=a.translate,a.__originalTransform=a.transform,a.__originalSetTransform=a.setTransform,a.__originalResetTransform=a.resetTransform,a.__originalClip=a.clip,a.__originalMoveTo=a.moveTo,a.__originalLineTo=a.lineTo,a.__originalBezierCurveTo=a.bezierCurveTo,a.__originalRect=a.rect,a.__originalClosePath=a.closePath,a.__originalBeginPath=a.beginPath,a._removeMirroring=()=>{a.save=a.__originalSave,a.restore=a.__originalRestore,a.rotate=a.__originalRotate,a.scale=a.__originalScale,a.translate=a.__originalTranslate,a.transform=a.__originalTransform,a.setTransform=a.__originalSetTransform,a.resetTransform=a.__originalResetTransform,a.clip=a.__originalClip,a.moveTo=a.__originalMoveTo,a.lineTo=a.__originalLineTo,a.bezierCurveTo=a.__originalBezierCurveTo,a.rect=a.__originalRect,a.closePath=a.__originalClosePath,a.beginPath=a.__originalBeginPath,delete a._removeMirroring},a.save=function(){t.save(),this.__originalSave()},a.restore=function(){t.restore(),this.__originalRestore()},a.translate=function(s,i){t.translate(s,i),this.__originalTranslate(s,i)},a.scale=function(s,i){t.scale(s,i),this.__originalScale(s,i)},a.transform=function(s,i,n,r,o,h){t.transform(s,i,n,r,o,h),this.__originalTransform(s,i,n,r,o,h)},a.setTransform=function(s,i,n,r,o,h){t.setTransform(s,i,n,r,o,h),this.__originalSetTransform(s,i,n,r,o,h)},a.resetTransform=function(){t.resetTransform(),this.__originalResetTransform()},a.rotate=function(s){t.rotate(s),this.__originalRotate(s)},a.clip=function(s){t.clip(s),this.__originalClip(s)},a.moveTo=function(e,s){t.moveTo(e,s),this.__originalMoveTo(e,s)},a.lineTo=function(e,s){t.lineTo(e,s),this.__originalLineTo(e,s)},a.bezierCurveTo=function(e,s,i,n,r,o){t.bezierCurveTo(e,s,i,n,r,o),this.__originalBezierCurveTo(e,s,i,n,r,o)},a.rect=function(e,s,i,n){t.rect(e,s,i,n),this.__originalRect(e,s,i,n)},a.closePath=function(){t.closePath(),this.__originalClosePath()},a.beginPath=function(){t.beginPath(),this.__originalBeginPath()}}class Lx{constructor(t){this.canvasFactory=t,this.cache=Object.create(null)}getCanvas(t,e,s){let i;return this.cache[t]!==void 0?(i=this.cache[t],this.canvasFactory.reset(i,e,s)):(i=this.canvasFactory.create(e,s),this.cache[t]=i),i}delete(t){delete this.cache[t]}clear(){for(const t in this.cache){const e=this.cache[t];this.canvasFactory.destroy(e),delete this.cache[t]}}}function Zu(a,t,e,s,i,n,r,o,h,c){const[u,d,f,g,p,b]=Tt(a);if(d===0&&f===0){const x=r*u+p,C=Math.round(x),S=o*g+b,k=Math.round(S),M=(r+h)*u+p,E=Math.abs(Math.round(M)-C)||1,P=(o+c)*g+b,O=Math.abs(Math.round(P)-k)||1;return a.setTransform(Math.sign(u),0,0,Math.sign(g),C,k),a.drawImage(t,e,s,i,n,0,0,E,O),a.setTransform(u,d,f,g,p,b),[E,O]}if(u===0&&g===0){const x=o*f+p,C=Math.round(x),S=r*d+b,k=Math.round(S),M=(o+c)*f+p,E=Math.abs(Math.round(M)-C)||1,P=(r+h)*d+b,O=Math.abs(Math.round(P)-k)||1;return a.setTransform(0,Math.sign(d),Math.sign(f),0,C,k),a.drawImage(t,e,s,i,n,0,0,O,E),a.setTransform(u,d,f,g,p,b),[O,E]}a.drawImage(t,e,s,i,n,r,o,h,c);const _=Math.hypot(u,d),v=Math.hypot(f,g);return[_*h,v*c]}function Fx(a){const{width:t,height:e}=a;if(t>fb||e>fb)return null;const s=1e3,i=new Uint8Array([0,2,4,0,1,0,5,4,8,10,0,8,0,2,1,0]),n=t+1;let r=new Uint8Array(n*(e+1)),o,h,c;const u=t+7&-8;let d=new Uint8Array(u*e),f=0;for(const v of a.data){let x=128;for(;x>0;)d[f++]=v&x?0:255,x>>=1}let g=0;for(f=0,d[f]!==0&&(r[0]=1,++g),h=1;h<t;h++)d[f]!==d[f+1]&&(r[h]=d[f]?2:1,++g),f++;for(d[f]!==0&&(r[h]=2,++g),o=1;o<e;o++){f=o*u,c=o*n,d[f-u]!==d[f]&&(r[c]=d[f]?1:8,++g);let v=(d[f]?4:0)+(d[f-u]?8:0);for(h=1;h<t;h++)v=(v>>2)+(d[f+1]?4:0)+(d[f-u+1]?8:0),i[v]&&(r[c+h]=i[v],++g),f++;if(d[f-u]!==d[f]&&(r[c+h]=d[f]?2:4,++g),g>s)return null}for(f=u*(e-1),c=o*n,d[f]!==0&&(r[c]=8,++g),h=1;h<t;h++)d[f]!==d[f+1]&&(r[c+h]=d[f]?4:8,++g),f++;if(d[f]!==0&&(r[c+h]=4,++g),g>s)return null;const p=new Int32Array([0,n,-1,0,-n,0,0,0,1]),b=new Path2D;for(o=0;g&&o<=e;o++){let v=o*n;const x=v+t;for(;v<x&&!r[v];)v++;if(v===x)continue;b.moveTo(v%n,o);const C=v;let S=r[v];do{const k=p[S];do v+=k;while(!r[v]);const M=r[v];M!==5&&M!==10?(S=M,r[v]=0):(S=M&51*S>>4,r[v]&=S>>2|S<<2),b.lineTo(v%n,v/n|0),r[v]||--g}while(C!==v);--o}return d=null,r=null,function(v){v.save(),v.scale(1/t,-1/e),v.translate(0,-e),v.fill(b),v.beginPath(),v.restore()}}class gb{constructor(t,e){this.alphaIsShape=!1,this.fontSize=0,this.fontSizeScale=1,this.textMatrix=Y0,this.textMatrixScale=1,this.fontMatrix=rg,this.leading=0,this.x=0,this.y=0,this.lineX=0,this.lineY=0,this.charSpacing=0,this.wordSpacing=0,this.textHScale=1,this.textRenderingMode=ve.FILL,this.textRise=0,this.fillColor="#000000",this.strokeColor="#000000",this.patternFill=!1,this.patternStroke=!1,this.fillAlpha=1,this.strokeAlpha=1,this.lineWidth=1,this.activeSMask=null,this.transferMaps="none",this.startNewPathAndClipBox([0,0,t,e])}clone(){const t=Object.create(this);return t.clipBox=this.clipBox.slice(),t}setCurrentPoint(t,e){this.x=t,this.y=e}updatePathMinMax(t,e,s){[e,s]=W.applyTransform([e,s],t),this.minX=Math.min(this.minX,e),this.minY=Math.min(this.minY,s),this.maxX=Math.max(this.maxX,e),this.maxY=Math.max(this.maxY,s)}updateRectMinMax(t,e){const s=W.applyTransform(e,t),i=W.applyTransform(e.slice(2),t),n=W.applyTransform([e[0],e[3]],t),r=W.applyTransform([e[2],e[1]],t);this.minX=Math.min(this.minX,s[0],i[0],n[0],r[0]),this.minY=Math.min(this.minY,s[1],i[1],n[1],r[1]),this.maxX=Math.max(this.maxX,s[0],i[0],n[0],r[0]),this.maxY=Math.max(this.maxY,s[1],i[1],n[1],r[1])}updateScalingPathMinMax(t,e){W.scaleMinMax(t,e),this.minX=Math.min(this.minX,e[0]),this.minY=Math.min(this.minY,e[1]),this.maxX=Math.max(this.maxX,e[2]),this.maxY=Math.max(this.maxY,e[3])}updateCurvePathMinMax(t,e,s,i,n,r,o,h,c,u){const d=W.bezierBoundingBox(e,s,i,n,r,o,h,c,u);u||this.updateRectMinMax(t,d)}getPathBoundingBox(t=_e.FILL,e=null){const s=[this.minX,this.minY,this.maxX,this.maxY];if(t===_e.STROKE){e||vt("Stroke bounding box must include transform.");const i=W.singularValueDecompose2dScale(e),n=i[0]*this.lineWidth/2,r=i[1]*this.lineWidth/2;s[0]-=n,s[1]-=r,s[2]+=n,s[3]+=r}return s}updateClipFromPath(){const t=W.intersect(this.clipBox,this.getPathBoundingBox());this.startNewPathAndClipBox(t||[0,0,0,0])}isEmptyClip(){return this.minX===1/0}startNewPathAndClipBox(t){this.clipBox=t,this.minX=1/0,this.minY=1/0,this.maxX=0,this.maxY=0}getClippedPathBoundingBox(t=_e.FILL,e=null){return W.intersect(this.clipBox,this.getPathBoundingBox(t,e))}}function pb(a,t){if(t instanceof ImageData){a.putImageData(t,0,0);return}const e=t.height,s=t.width,i=e%Ue,n=(e-i)/Ue,r=i===0?n:n+1,o=a.createImageData(s,Ue);let h=0,c;const u=t.data,d=o.data;let f,g,p,b;if(t.kind===Gu.GRAYSCALE_1BPP){const _=u.byteLength,v=new Uint32Array(d.buffer,0,d.byteLength>>2),x=v.length,C=s+7>>3,S=4294967295,k=Re.isLittleEndian?4278190080:255;for(f=0;f<r;f++){for(p=f<n?Ue:i,c=0,g=0;g<p;g++){const M=_-h;let E=0;const P=M>C?s:M*8-7,O=P&-8;let L=0,R=0;for(;E<O;E+=8)R=u[h++],v[c++]=R&128?S:k,v[c++]=R&64?S:k,v[c++]=R&32?S:k,v[c++]=R&16?S:k,v[c++]=R&8?S:k,v[c++]=R&4?S:k,v[c++]=R&2?S:k,v[c++]=R&1?S:k;for(;E<P;E++)L===0&&(R=u[h++],L=128),v[c++]=R&L?S:k,L>>=1}for(;c<x;)v[c++]=0;a.putImageData(o,0,f*Ue)}}else if(t.kind===Gu.RGBA_32BPP){for(g=0,b=s*Ue*4,f=0;f<n;f++)d.set(u.subarray(h,h+b)),h+=b,a.putImageData(o,0,g),g+=Ue;f<r&&(b=s*i*4,d.set(u.subarray(h,h+b)),a.putImageData(o,0,g))}else if(t.kind===Gu.RGB_24BPP)for(p=Ue,b=s*p,f=0;f<r;f++){for(f>=n&&(p=i,b=s*p),c=0,g=b;g--;)d[c++]=u[h++],d[c++]=u[h++],d[c++]=u[h++],d[c++]=255;a.putImageData(o,0,f*Ue)}else throw new Error(`bad image kind: ${t.kind}`)}function mb(a,t){if(t.bitmap){a.drawImage(t.bitmap,0,0);return}const e=t.height,s=t.width,i=e%Ue,n=(e-i)/Ue,r=i===0?n:n+1,o=a.createImageData(s,Ue);let h=0;const c=t.data,u=o.data;for(let d=0;d<r;d++){const f=d<n?Ue:i;({srcPos:h}=Dx({src:c,srcPos:h,dest:u,width:s,height:f,nonBlackColor:0})),a.putImageData(o,0,d*Ue)}}function Uh(a,t){const e=["strokeStyle","fillStyle","fillRule","globalAlpha","lineWidth","lineCap","lineJoin","miterLimit","globalCompositeOperation","font","filter"];for(const s of e)a[s]!==void 0&&(t[s]=a[s]);a.setLineDash!==void 0&&(t.setLineDash(a.getLineDash()),t.lineDashOffset=a.lineDashOffset)}function td(a){if(a.strokeStyle=a.fillStyle="#000000",a.fillRule="nonzero",a.globalAlpha=1,a.lineWidth=1,a.lineCap="butt",a.lineJoin="miter",a.miterLimit=10,a.globalCompositeOperation="source-over",a.font="10px sans-serif",a.setLineDash!==void 0&&(a.setLineDash([]),a.lineDashOffset=0),!ye){const{filter:t}=a;t!=="none"&&t!==""&&(a.filter="none")}}function bb(a,t){if(t)return!0;const e=W.singularValueDecompose2dScale(a);e[0]=Math.fround(e[0]),e[1]=Math.fround(e[1]);const s=Math.fround((globalThis.devicePixelRatio||1)*Ln.PDF_TO_CSS_UNITS);return e[0]<=s&&e[1]<=s}const Ix=["butt","round","square"],Nx=["miter","round","bevel"],jx={},yb={},Wg=class Wg{constructor(t,e,s,i,n,{optionalContentConfig:r,markedContentStack:o=null},h,c){y(this,Ys);this.ctx=t,this.current=new gb(this.ctx.canvas.width,this.ctx.canvas.height),this.stateStack=[],this.pendingClip=null,this.pendingEOFill=!1,this.res=null,this.xobjs=null,this.commonObjs=e,this.objs=s,this.canvasFactory=i,this.filterFactory=n,this.groupStack=[],this.processingType3=null,this.baseTransform=null,this.baseTransformStack=[],this.groupLevel=0,this.smaskStack=[],this.smaskCounter=0,this.tempSMask=null,this.suspendedCtx=null,this.contentVisible=!0,this.markedContentStack=o||[],this.optionalContentConfig=r,this.cachedCanvases=new Lx(this.canvasFactory),this.cachedPatterns=new Map,this.annotationCanvasMap=h,this.viewportScale=1,this.outputScaleX=1,this.outputScaleY=1,this.pageColors=c,this._cachedScaleForStroking=[-1,0],this._cachedGetSinglePixelWidth=null,this._cachedBitmapsMap=new Map}getObject(t,e=null){return typeof t=="string"?t.startsWith("g_")?this.commonObjs.get(t):this.objs.get(t):e}beginDrawing({transform:t,viewport:e,transparency:s=!1,background:i=null}){const n=this.ctx.canvas.width,r=this.ctx.canvas.height,o=this.ctx.fillStyle;if(this.ctx.fillStyle=i||"#ffffff",this.ctx.fillRect(0,0,n,r),this.ctx.fillStyle=o,s){const h=this.cachedCanvases.getCanvas("transparent",n,r);this.compositeCtx=this.ctx,this.transparentCanvas=h.canvas,this.ctx=h.context,this.ctx.save(),this.ctx.transform(...Tt(this.compositeCtx))}this.ctx.save(),td(this.ctx),t&&(this.ctx.transform(...t),this.outputScaleX=t[0],this.outputScaleY=t[0]),this.ctx.transform(...e.transform),this.viewportScale=e.scale,this.baseTransform=Tt(this.ctx)}executeOperatorList(t,e,s,i){const n=t.argsArray,r=t.fnArray;let o=e||0;const h=n.length;if(h===o)return o;const c=h-o>db&&typeof s=="function",u=c?Date.now()+Ox:0;let d=0;const f=this.commonObjs,g=this.objs;let p;for(;;){if(i!==void 0&&o===i.nextBreakPoint)return i.breakIt(o,s),o;if(p=r[o],p!==Hs.dependency)this[p].apply(this,n[o]);else for(const b of n[o]){const _=b.startsWith("g_")?f:g;if(!_.has(b))return _.get(b,s),o}if(o++,o===h)return o;if(c&&++d>db){if(Date.now()>u)return s(),o;d=0}}}endDrawing(){w(this,Ys,gp).call(this),this.cachedCanvases.clear(),this.cachedPatterns.clear();for(const t of this._cachedBitmapsMap.values()){for(const e of t.values())typeof HTMLCanvasElement<"u"&&e instanceof HTMLCanvasElement&&(e.width=e.height=0);t.clear()}this._cachedBitmapsMap.clear(),w(this,Ys,pp).call(this)}_scaleImage(t,e){const s=t.width??t.displayWidth,i=t.height??t.displayHeight;let n=Math.max(Math.hypot(e[0],e[1]),1),r=Math.max(Math.hypot(e[2],e[3]),1),o=s,h=i,c="prescale1",u,d;for(;n>2&&o>1||r>2&&h>1;){let f=o,g=h;n>2&&o>1&&(f=o>=16384?Math.floor(o/2)-1||1:Math.ceil(o/2),n/=o/f),r>2&&h>1&&(g=h>=16384?Math.floor(h/2)-1||1:Math.ceil(h)/2,r/=h/g),u=this.cachedCanvases.getCanvas(c,f,g),d=u.context,d.clearRect(0,0,f,g),d.drawImage(t,0,0,o,h,0,0,f,g),t=u.canvas,o=f,h=g,c=c==="prescale1"?"prescale2":"prescale1"}return{img:t,paintWidth:o,paintHeight:h}}_createMaskCanvas(t){const e=this.ctx,{width:s,height:i}=t,n=this.current.fillColor,r=this.current.patternFill,o=Tt(e);let h,c,u,d;if((t.bitmap||t.data)&&t.count>1){const P=t.bitmap||t.data.buffer;c=JSON.stringify(r?o:[o.slice(0,4),n]),h=this._cachedBitmapsMap.get(P),h||(h=new Map,this._cachedBitmapsMap.set(P,h));const O=h.get(c);if(O&&!r){const L=Math.round(Math.min(o[0],o[2])+o[4]),R=Math.round(Math.min(o[1],o[3])+o[5]);return{canvas:O,offsetX:L,offsetY:R}}u=O}u||(d=this.cachedCanvases.getCanvas("maskCanvas",s,i),mb(d.context,t));let f=W.transform(o,[1/s,0,0,-1/i,0,0]);f=W.transform(f,[1,0,0,1,0,-i]);const[g,p,b,_]=W.getAxialAlignedBoundingBox([0,0,s,i],f),v=Math.round(b-g)||1,x=Math.round(_-p)||1,C=this.cachedCanvases.getCanvas("fillCanvas",v,x),S=C.context,k=g,M=p;S.translate(-k,-M),S.transform(...f),u||(u=this._scaleImage(d.canvas,li(S)),u=u.img,h&&r&&h.set(c,u)),S.imageSmoothingEnabled=bb(Tt(S),t.interpolate),Zu(S,u,0,0,u.width,u.height,0,0,s,i),S.globalCompositeOperation="source-in";const E=W.transform(li(S),[1,0,0,1,-k,-M]);return S.fillStyle=r?n.getPattern(e,this,E,_e.FILL):n,S.fillRect(0,0,s,i),h&&!r&&(this.cachedCanvases.delete("fillCanvas"),h.set(c,C.canvas)),{canvas:C.canvas,offsetX:Math.round(k),offsetY:Math.round(M)}}setLineWidth(t){t!==this.current.lineWidth&&(this._cachedScaleForStroking[0]=-1),this.current.lineWidth=t,this.ctx.lineWidth=t}setLineCap(t){this.ctx.lineCap=Ix[t]}setLineJoin(t){this.ctx.lineJoin=Nx[t]}setMiterLimit(t){this.ctx.miterLimit=t}setDash(t,e){const s=this.ctx;s.setLineDash!==void 0&&(s.setLineDash(t),s.lineDashOffset=e)}setRenderingIntent(t){}setFlatness(t){}setGState(t){for(const[e,s]of t)switch(e){case"LW":this.setLineWidth(s);break;case"LC":this.setLineCap(s);break;case"LJ":this.setLineJoin(s);break;case"ML":this.setMiterLimit(s);break;case"D":this.setDash(s[0],s[1]);break;case"RI":this.setRenderingIntent(s);break;case"FL":this.setFlatness(s);break;case"Font":this.setFont(s[0],s[1]);break;case"CA":this.current.strokeAlpha=s;break;case"ca":this.current.fillAlpha=s,this.ctx.globalAlpha=s;break;case"BM":this.ctx.globalCompositeOperation=s;break;case"SMask":this.current.activeSMask=s?this.tempSMask:null,this.tempSMask=null,this.checkSMaskState();break;case"TR":this.ctx.filter=this.current.transferMaps=this.filterFactory.addFilter(s);break}}get inSMaskMode(){return!!this.suspendedCtx}checkSMaskState(){const t=this.inSMaskMode;this.current.activeSMask&&!t?this.beginSMaskMode():!this.current.activeSMask&&t&&this.endSMaskMode()}beginSMaskMode(){if(this.inSMaskMode)throw new Error("beginSMaskMode called while already in smask mode");const t=this.ctx.canvas.width,e=this.ctx.canvas.height,s="smaskGroupAt"+this.groupLevel,i=this.cachedCanvases.getCanvas(s,t,e);this.suspendedCtx=this.ctx,this.ctx=i.context;const n=this.ctx;n.setTransform(...Tt(this.suspendedCtx)),Uh(this.suspendedCtx,n),Rx(n,this.suspendedCtx),this.setGState([["BM","source-over"],["ca",1],["CA",1]])}endSMaskMode(){if(!this.inSMaskMode)throw new Error("endSMaskMode called while not in smask mode");this.ctx._removeMirroring(),Uh(this.ctx,this.suspendedCtx),this.ctx=this.suspendedCtx,this.suspendedCtx=null}compose(t){if(!this.current.activeSMask)return;t?(t[0]=Math.floor(t[0]),t[1]=Math.floor(t[1]),t[2]=Math.ceil(t[2]),t[3]=Math.ceil(t[3])):t=[0,0,this.ctx.canvas.width,this.ctx.canvas.height];const e=this.current.activeSMask,s=this.suspendedCtx;this.composeSMask(s,e,this.ctx,t),this.ctx.save(),this.ctx.setTransform(1,0,0,1,0,0),this.ctx.clearRect(0,0,this.ctx.canvas.width,this.ctx.canvas.height),this.ctx.restore()}composeSMask(t,e,s,i){const n=i[0],r=i[1],o=i[2]-n,h=i[3]-r;o===0||h===0||(this.genericComposeSMask(e.context,s,o,h,e.subtype,e.backdrop,e.transferMap,n,r,e.offsetX,e.offsetY),t.save(),t.globalAlpha=1,t.globalCompositeOperation="source-over",t.setTransform(1,0,0,1,0,0),t.drawImage(s.canvas,0,0),t.restore())}genericComposeSMask(t,e,s,i,n,r,o,h,c,u,d){let f=t.canvas,g=h-u,p=c-d;if(r){const _=W.makeHexColor(...r);if(g<0||p<0||g+s>f.width||p+i>f.height){const v=this.cachedCanvases.getCanvas("maskExtension",s,i),x=v.context;x.drawImage(f,-g,-p),x.globalCompositeOperation="destination-atop",x.fillStyle=_,x.fillRect(0,0,s,i),x.globalCompositeOperation="source-over",f=v.canvas,g=p=0}else{t.save(),t.globalAlpha=1,t.setTransform(1,0,0,1,0,0);const v=new Path2D;v.rect(g,p,s,i),t.clip(v),t.globalCompositeOperation="destination-atop",t.fillStyle=_,t.fillRect(g,p,s,i),t.restore()}}e.save(),e.globalAlpha=1,e.setTransform(1,0,0,1,0,0),n==="Alpha"&&o?e.filter=this.filterFactory.addAlphaFilter(o):n==="Luminosity"&&(e.filter=this.filterFactory.addLuminosityFilter(o));const b=new Path2D;b.rect(h,c,s,i),e.clip(b),e.globalCompositeOperation="destination-in",e.drawImage(f,g,p,s,i,h,c,s,i),e.restore()}save(){this.inSMaskMode?(Uh(this.ctx,this.suspendedCtx),this.suspendedCtx.save()):this.ctx.save();const t=this.current;this.stateStack.push(t),this.current=t.clone()}restore(){this.stateStack.length===0&&this.inSMaskMode&&this.endSMaskMode(),this.stateStack.length!==0&&(this.current=this.stateStack.pop(),this.inSMaskMode?(this.suspendedCtx.restore(),Uh(this.suspendedCtx,this.ctx)):this.ctx.restore(),this.checkSMaskState(),this.pendingClip=null,this._cachedScaleForStroking[0]=-1,this._cachedGetSinglePixelWidth=null)}transform(t,e,s,i,n,r){this.ctx.transform(t,e,s,i,n,r),this._cachedScaleForStroking[0]=-1,this._cachedGetSinglePixelWidth=null}constructPath(t,e,s){const i=this.ctx,n=this.current;let r=n.x,o=n.y,h,c;const u=Tt(i),d=u[0]===0&&u[3]===0||u[1]===0&&u[2]===0,f=d?s.slice(0):null;for(let g=0,p=0,b=t.length;g<b;g++)switch(t[g]|0){case Hs.rectangle:r=e[p++],o=e[p++];const _=e[p++],v=e[p++],x=r+_,C=o+v;i.moveTo(r,o),_===0||v===0?i.lineTo(x,C):(i.lineTo(x,o),i.lineTo(x,C),i.lineTo(r,C)),d||n.updateRectMinMax(u,[r,o,x,C]),i.closePath();break;case Hs.moveTo:r=e[p++],o=e[p++],i.moveTo(r,o),d||n.updatePathMinMax(u,r,o);break;case Hs.lineTo:r=e[p++],o=e[p++],i.lineTo(r,o),d||n.updatePathMinMax(u,r,o);break;case Hs.curveTo:h=r,c=o,r=e[p+4],o=e[p+5],i.bezierCurveTo(e[p],e[p+1],e[p+2],e[p+3],r,o),n.updateCurvePathMinMax(u,h,c,e[p],e[p+1],e[p+2],e[p+3],r,o,f),p+=6;break;case Hs.curveTo2:h=r,c=o,i.bezierCurveTo(r,o,e[p],e[p+1],e[p+2],e[p+3]),n.updateCurvePathMinMax(u,h,c,r,o,e[p],e[p+1],e[p+2],e[p+3],f),r=e[p+2],o=e[p+3],p+=4;break;case Hs.curveTo3:h=r,c=o,r=e[p+2],o=e[p+3],i.bezierCurveTo(e[p],e[p+1],r,o,r,o),n.updateCurvePathMinMax(u,h,c,e[p],e[p+1],r,o,r,o,f),p+=4;break;case Hs.closePath:i.closePath();break}d&&n.updateScalingPathMinMax(u,f),n.setCurrentPoint(r,o)}closePath(){this.ctx.closePath()}stroke(t=!0){const e=this.ctx,s=this.current.strokeColor;e.globalAlpha=this.current.strokeAlpha,this.contentVisible&&(typeof s=="object"&&(s!=null&&s.getPattern)?(e.save(),e.strokeStyle=s.getPattern(e,this,li(e),_e.STROKE),this.rescaleAndStroke(!1),e.restore()):this.rescaleAndStroke(!0)),t&&this.consumePath(this.current.getClippedPathBoundingBox()),e.globalAlpha=this.current.fillAlpha}closeStroke(){this.closePath(),this.stroke()}fill(t=!0){const e=this.ctx,s=this.current.fillColor,i=this.current.patternFill;let n=!1;i&&(e.save(),e.fillStyle=s.getPattern(e,this,li(e),_e.FILL),n=!0);const r=this.current.getClippedPathBoundingBox();this.contentVisible&&r!==null&&(this.pendingEOFill?(e.fill("evenodd"),this.pendingEOFill=!1):e.fill()),n&&e.restore(),t&&this.consumePath(r)}eoFill(){this.pendingEOFill=!0,this.fill()}fillStroke(){this.fill(!1),this.stroke(!1),this.consumePath()}eoFillStroke(){this.pendingEOFill=!0,this.fillStroke()}closeFillStroke(){this.closePath(),this.fillStroke()}closeEOFillStroke(){this.pendingEOFill=!0,this.closePath(),this.fillStroke()}endPath(){this.consumePath()}clip(){this.pendingClip=jx}eoClip(){this.pendingClip=yb}beginText(){this.current.textMatrix=Y0,this.current.textMatrixScale=1,this.current.x=this.current.lineX=0,this.current.y=this.current.lineY=0}endText(){const t=this.pendingTextPaths,e=this.ctx;if(t===void 0){e.beginPath();return}const s=new Path2D,i=e.getTransform().invertSelf();for(const{transform:n,x:r,y:o,fontSize:h,path:c}of t)s.addPath(c,new DOMMatrix(n).preMultiplySelf(i).translate(r,o).scale(h,-h));e.clip(s),e.beginPath(),delete this.pendingTextPaths}setCharSpacing(t){this.current.charSpacing=t}setWordSpacing(t){this.current.wordSpacing=t}setHScale(t){this.current.textHScale=t/100}setLeading(t){this.current.leading=-t}setFont(t,e){var u;const s=this.commonObjs.get(t),i=this.current;if(!s)throw new Error(`Can't find font for ${t}`);if(i.fontMatrix=s.fontMatrix||rg,(i.fontMatrix[0]===0||i.fontMatrix[3]===0)&&tt("Invalid font matrix for font "+t),e<0?(e=-e,i.fontDirection=-1):i.fontDirection=1,this.current.font=s,this.current.fontSize=e,s.isType3Font)return;const n=s.loadedName||"sans-serif",r=((u=s.systemFontInfo)==null?void 0:u.css)||`"${n}", ${s.fallbackName}`;let o="normal";s.black?o="900":s.bold&&(o="bold");const h=s.italic?"italic":"normal";let c=e;e<cb?c=cb:e>ub&&(c=ub),this.current.fontSizeScale=e/c,this.ctx.font=`${h} ${o} ${c}px ${r}`}setTextRenderingMode(t){this.current.textRenderingMode=t}setTextRise(t){this.current.textRise=t}moveText(t,e){this.current.x=this.current.lineX+=t,this.current.y=this.current.lineY+=e}setLeadingMoveText(t,e){this.setLeading(-e),this.moveText(t,e)}setTextMatrix(t,e,s,i,n,r){this.current.textMatrix=[t,e,s,i,n,r],this.current.textMatrixScale=Math.hypot(t,e),this.current.x=this.current.lineX=0,this.current.y=this.current.lineY=0}nextLine(){this.moveText(0,this.current.leading)}paintChar(t,e,s,i,n){const r=this.ctx,o=this.current,h=o.font,c=o.textRenderingMode,u=o.fontSize/o.fontSizeScale,d=c&ve.FILL_STROKE_MASK,f=!!(c&ve.ADD_TO_PATH_FLAG),g=o.patternFill&&!h.missingFile,p=o.patternStroke&&!h.missingFile;let b;if((h.disableFontFace||f||g||p)&&(b=h.getPathGenerator(this.commonObjs,t)),h.disableFontFace||g||p){if(r.save(),r.translate(e,s),r.scale(u,-u),d===ve.FILL||d===ve.FILL_STROKE)if(i){const _=r.getTransform();r.setTransform(...i),r.fill(w(this,Ys,mp).call(this,b,_,i))}else r.fill(b);if(d===ve.STROKE||d===ve.FILL_STROKE)if(n){const _=r.getTransform();r.setTransform(...n),r.stroke(w(this,Ys,mp).call(this,b,_,n))}else r.lineWidth/=u,r.stroke(b);r.restore()}else(d===ve.FILL||d===ve.FILL_STROKE)&&r.fillText(t,e,s),(d===ve.STROKE||d===ve.FILL_STROKE)&&r.strokeText(t,e,s);f&&(this.pendingTextPaths||(this.pendingTextPaths=[])).push({transform:Tt(r),x:e,y:s,fontSize:u,path:b})}get isFontSubpixelAAEnabled(){const{context:t}=this.cachedCanvases.getCanvas("isFontSubpixelAAEnabled",10,10);t.scale(1.5,1),t.fillText("I",0,10);const e=t.getImageData(0,0,10,10).data;let s=!1;for(let i=3;i<e.length;i+=4)if(e[i]>0&&e[i]<255){s=!0;break}return st(this,"isFontSubpixelAAEnabled",s)}showText(t){const e=this.current,s=e.font;if(s.isType3Font)return this.showType3Text(t);const i=e.fontSize;if(i===0)return;const n=this.ctx,r=e.fontSizeScale,o=e.charSpacing,h=e.wordSpacing,c=e.fontDirection,u=e.textHScale*c,d=t.length,f=s.vertical,g=f?1:-1,p=s.defaultVMetrics,b=i*e.fontMatrix[0],_=e.textRenderingMode===ve.FILL&&!s.disableFontFace&&!e.patternFill;n.save(),n.transform(...e.textMatrix),n.translate(e.x,e.y+e.textRise),c>0?n.scale(u,-1):n.scale(u,1);let v,x;if(e.patternFill){n.save();const E=e.fillColor.getPattern(n,this,li(n),_e.FILL);v=Tt(n),n.restore(),n.fillStyle=E}if(e.patternStroke){n.save();const E=e.strokeColor.getPattern(n,this,li(n),_e.STROKE);x=Tt(n),n.restore(),n.strokeStyle=E}let C=e.lineWidth;const S=e.textMatrixScale;if(S===0||C===0){const E=e.textRenderingMode&ve.FILL_STROKE_MASK;(E===ve.STROKE||E===ve.FILL_STROKE)&&(C=this.getSinglePixelWidth())}else C/=S;if(r!==1&&(n.scale(r,r),C/=r),n.lineWidth=C,s.isInvalidPDFjsFont){const E=[];let P=0;for(const O of t)E.push(O.unicode),P+=O.width;n.fillText(E.join(""),0,0),e.x+=P*b*u,n.restore(),this.compose();return}let k=0,M;for(M=0;M<d;++M){const E=t[M];if(typeof E=="number"){k+=g*E*i/1e3;continue}let P=!1;const O=(E.isSpace?h:0)+o,L=E.fontChar,R=E.accent;let U,z,V=E.width;if(f){const F=E.vmetric||p,G=-(E.vmetric?F[1]:V*.5)*b,rt=F[2]*b;V=F?-F[0]:V,U=G/r,z=(k+rt)/r}else U=k/r,z=0;if(s.remeasure&&V>0){const F=n.measureText(L).width*1e3/i*r;if(V<F&&this.isFontSubpixelAAEnabled){const G=V/F;P=!0,n.save(),n.scale(G,1),U/=G}else V!==F&&(U+=(V-F)/2e3*i/r)}if(this.contentVisible&&(E.isInFont||s.missingFile)){if(_&&!R)n.fillText(L,U,z);else if(this.paintChar(L,U,z,v,x),R){const F=U+i*R.offset.x/r,G=z-i*R.offset.y/r;this.paintChar(R.fontChar,F,G,v,x)}}const at=f?V*b-O*c:V*b+O*c;k+=at,P&&n.restore()}f?e.y-=k:e.x+=k*u,n.restore(),this.compose()}showType3Text(t){const e=this.ctx,s=this.current,i=s.font,n=s.fontSize,r=s.fontDirection,o=i.vertical?1:-1,h=s.charSpacing,c=s.wordSpacing,u=s.textHScale*r,d=s.fontMatrix||rg,f=t.length,g=s.textRenderingMode===ve.INVISIBLE;let p,b,_,v;if(!(g||n===0)){for(this._cachedScaleForStroking[0]=-1,this._cachedGetSinglePixelWidth=null,e.save(),e.transform(...s.textMatrix),e.translate(s.x,s.y),e.scale(u,r),p=0;p<f;++p){if(b=t[p],typeof b=="number"){v=o*b*n/1e3,this.ctx.translate(v,0),s.x+=v*u;continue}const x=(b.isSpace?c:0)+h,C=i.charProcOperatorList[b.operatorListId];if(!C){tt(`Type3 character "${b.operatorListId}" is not available.`);continue}this.contentVisible&&(this.processingType3=b,this.save(),e.scale(n,n),e.transform(...d),this.executeOperatorList(C),this.restore()),_=W.applyTransform([b.width,0],d)[0]*n+x,e.translate(_,0),s.x+=_*u}e.restore(),this.processingType3=null}}setCharWidth(t,e){}setCharWidthAndBounds(t,e,s,i,n,r){this.ctx.rect(s,i,n-s,r-i),this.ctx.clip(),this.endPath()}getColorN_Pattern(t){let e;if(t[0]==="TilingPattern"){const s=t[1],i=this.baseTransform||Tt(this.ctx),n={createCanvasGraphics:r=>new Wg(r,this.commonObjs,this.objs,this.canvasFactory,this.filterFactory,{optionalContentConfig:this.optionalContentConfig,markedContentStack:this.markedContentStack})};e=new Tg(t,s,this.ctx,n,i)}else e=this._getPattern(t[1],t[2]);return e}setStrokeColorN(){this.current.strokeColor=this.getColorN_Pattern(arguments),this.current.patternStroke=!0}setFillColorN(){this.current.fillColor=this.getColorN_Pattern(arguments),this.current.patternFill=!0}setStrokeRGBColor(t,e,s){this.ctx.strokeStyle=this.current.strokeColor=W.makeHexColor(t,e,s),this.current.patternStroke=!1}setStrokeTransparent(){this.ctx.strokeStyle=this.current.strokeColor="transparent",this.current.patternStroke=!1}setFillRGBColor(t,e,s){this.ctx.fillStyle=this.current.fillColor=W.makeHexColor(t,e,s),this.current.patternFill=!1}setFillTransparent(){this.ctx.fillStyle=this.current.fillColor="transparent",this.current.patternFill=!1}_getPattern(t,e=null){let s;return this.cachedPatterns.has(t)?s=this.cachedPatterns.get(t):(s=Px(this.getObject(t)),this.cachedPatterns.set(t,s)),e&&(s.matrix=e),s}shadingFill(t){if(!this.contentVisible)return;const e=this.ctx;this.save();const s=this._getPattern(t);e.fillStyle=s.getPattern(e,this,li(e),_e.SHADING);const i=li(e);if(i){const{width:n,height:r}=e.canvas,[o,h,c,u]=W.getAxialAlignedBoundingBox([0,0,n,r],i);this.ctx.fillRect(o,h,c-o,u-h)}else this.ctx.fillRect(-1e10,-1e10,2e10,2e10);this.compose(this.current.getClippedPathBoundingBox()),this.restore()}beginInlineImage(){vt("Should not call beginInlineImage")}beginImageData(){vt("Should not call beginImageData")}paintFormXObjectBegin(t,e){if(this.contentVisible&&(this.save(),this.baseTransformStack.push(this.baseTransform),t&&this.transform(...t),this.baseTransform=Tt(this.ctx),e)){const s=e[2]-e[0],i=e[3]-e[1];this.ctx.rect(e[0],e[1],s,i),this.current.updateRectMinMax(Tt(this.ctx),e),this.clip(),this.endPath()}}paintFormXObjectEnd(){this.contentVisible&&(this.restore(),this.baseTransform=this.baseTransformStack.pop())}beginGroup(t){if(!this.contentVisible)return;this.save(),this.inSMaskMode&&(this.endSMaskMode(),this.current.activeSMask=null);const e=this.ctx;t.isolated||Xu("TODO: Support non-isolated groups."),t.knockout&&tt("Knockout groups not supported.");const s=Tt(e);if(t.matrix&&e.transform(...t.matrix),!t.bbox)throw new Error("Bounding box is required.");let i=W.getAxialAlignedBoundingBox(t.bbox,Tt(e));const n=[0,0,e.canvas.width,e.canvas.height];i=W.intersect(i,n)||[0,0,0,0];const r=Math.floor(i[0]),o=Math.floor(i[1]),h=Math.max(Math.ceil(i[2])-r,1),c=Math.max(Math.ceil(i[3])-o,1);this.current.startNewPathAndClipBox([0,0,h,c]);let u="groupAt"+this.groupLevel;t.smask&&(u+="_smask_"+this.smaskCounter++%2);const d=this.cachedCanvases.getCanvas(u,h,c),f=d.context;f.translate(-r,-o),f.transform(...s),t.smask?this.smaskStack.push({canvas:d.canvas,context:f,offsetX:r,offsetY:o,subtype:t.smask.subtype,backdrop:t.smask.backdrop,transferMap:t.smask.transferMap||null,startTransformInverse:null}):(e.setTransform(1,0,0,1,0,0),e.translate(r,o),e.save()),Uh(e,f),this.ctx=f,this.setGState([["BM","source-over"],["ca",1],["CA",1]]),this.groupStack.push(e),this.groupLevel++}endGroup(t){if(!this.contentVisible)return;this.groupLevel--;const e=this.ctx,s=this.groupStack.pop();if(this.ctx=s,this.ctx.imageSmoothingEnabled=!1,t.smask)this.tempSMask=this.smaskStack.pop(),this.restore();else{this.ctx.restore();const i=Tt(this.ctx);this.restore(),this.ctx.save(),this.ctx.setTransform(...i);const n=W.getAxialAlignedBoundingBox([0,0,e.canvas.width,e.canvas.height],i);this.ctx.drawImage(e.canvas,0,0),this.ctx.restore(),this.compose(n)}}beginAnnotation(t,e,s,i,n){if(w(this,Ys,gp).call(this),td(this.ctx),this.ctx.save(),this.save(),this.baseTransform&&this.ctx.setTransform(...this.baseTransform),e){const r=e[2]-e[0],o=e[3]-e[1];if(n&&this.annotationCanvasMap){s=s.slice(),s[4]-=e[0],s[5]-=e[1],e=e.slice(),e[0]=e[1]=0,e[2]=r,e[3]=o;const[h,c]=W.singularValueDecompose2dScale(Tt(this.ctx)),{viewportScale:u}=this,d=Math.ceil(r*this.outputScaleX*u),f=Math.ceil(o*this.outputScaleY*u);this.annotationCanvas=this.canvasFactory.create(d,f);const{canvas:g,context:p}=this.annotationCanvas;this.annotationCanvasMap.set(t,g),this.annotationCanvas.savedCtx=this.ctx,this.ctx=p,this.ctx.save(),this.ctx.setTransform(h,0,0,-c,0,o*c),td(this.ctx)}else td(this.ctx),this.endPath(),this.ctx.rect(e[0],e[1],r,o),this.ctx.clip(),this.ctx.beginPath()}this.current=new gb(this.ctx.canvas.width,this.ctx.canvas.height),this.transform(...s),this.transform(...i)}endAnnotation(){this.annotationCanvas&&(this.ctx.restore(),w(this,Ys,pp).call(this),this.ctx=this.annotationCanvas.savedCtx,delete this.annotationCanvas.savedCtx,delete this.annotationCanvas)}paintImageMaskXObject(t){if(!this.contentVisible)return;const e=t.count;t=this.getObject(t.data,t),t.count=e;const s=this.ctx,i=this.processingType3;if(i&&(i.compiled===void 0&&(i.compiled=Fx(t)),i.compiled)){i.compiled(s);return}const n=this._createMaskCanvas(t),r=n.canvas;s.save(),s.setTransform(1,0,0,1,0,0),s.drawImage(r,n.offsetX,n.offsetY),s.restore(),this.compose()}paintImageMaskXObjectRepeat(t,e,s=0,i=0,n,r){if(!this.contentVisible)return;t=this.getObject(t.data,t);const o=this.ctx;o.save();const h=Tt(o);o.transform(e,s,i,n,0,0);const c=this._createMaskCanvas(t);o.setTransform(1,0,0,1,c.offsetX-h[4],c.offsetY-h[5]);for(let u=0,d=r.length;u<d;u+=2){const f=W.transform(h,[e,s,i,n,r[u],r[u+1]]),[g,p]=W.applyTransform([0,0],f);o.drawImage(c.canvas,g,p)}o.restore(),this.compose()}paintImageMaskXObjectGroup(t){if(!this.contentVisible)return;const e=this.ctx,s=this.current.fillColor,i=this.current.patternFill;for(const n of t){const{data:r,width:o,height:h,transform:c}=n,u=this.cachedCanvases.getCanvas("maskCanvas",o,h),d=u.context;d.save();const f=this.getObject(r,n);mb(d,f),d.globalCompositeOperation="source-in",d.fillStyle=i?s.getPattern(d,this,li(e),_e.FILL):s,d.fillRect(0,0,o,h),d.restore(),e.save(),e.transform(...c),e.scale(1,-1),Zu(e,u.canvas,0,0,o,h,0,-1,1,1),e.restore()}this.compose()}paintImageXObject(t){if(!this.contentVisible)return;const e=this.getObject(t);if(!e){tt("Dependent image isn't ready yet");return}this.paintInlineImageXObject(e)}paintImageXObjectRepeat(t,e,s,i){if(!this.contentVisible)return;const n=this.getObject(t);if(!n){tt("Dependent image isn't ready yet");return}const r=n.width,o=n.height,h=[];for(let c=0,u=i.length;c<u;c+=2)h.push({transform:[e,0,0,s,i[c],i[c+1]],x:0,y:0,w:r,h:o});this.paintInlineImageXObjectGroup(n,h)}applyTransferMapsToCanvas(t){return this.current.transferMaps!=="none"&&(t.filter=this.current.transferMaps,t.drawImage(t.canvas,0,0),t.filter="none"),t.canvas}applyTransferMapsToBitmap(t){if(this.current.transferMaps==="none")return t.bitmap;const{bitmap:e,width:s,height:i}=t,n=this.cachedCanvases.getCanvas("inlineImage",s,i),r=n.context;return r.filter=this.current.transferMaps,r.drawImage(e,0,0),r.filter="none",n.canvas}paintInlineImageXObject(t){if(!this.contentVisible)return;const e=t.width,s=t.height,i=this.ctx;if(this.save(),!ye){const{filter:o}=i;o!=="none"&&o!==""&&(i.filter="none")}i.scale(1/e,-1/s);let n;if(t.bitmap)n=this.applyTransferMapsToBitmap(t);else if(typeof HTMLElement=="function"&&t instanceof HTMLElement||!t.data)n=t;else{const h=this.cachedCanvases.getCanvas("inlineImage",e,s).context;pb(h,t),n=this.applyTransferMapsToCanvas(h)}const r=this._scaleImage(n,li(i));i.imageSmoothingEnabled=bb(Tt(i),t.interpolate),Zu(i,r.img,0,0,r.paintWidth,r.paintHeight,0,-s,e,s),this.compose(),this.restore()}paintInlineImageXObjectGroup(t,e){if(!this.contentVisible)return;const s=this.ctx;let i;if(t.bitmap)i=t.bitmap;else{const n=t.width,r=t.height,h=this.cachedCanvases.getCanvas("inlineImage",n,r).context;pb(h,t),i=this.applyTransferMapsToCanvas(h)}for(const n of e)s.save(),s.transform(...n.transform),s.scale(1,-1),Zu(s,i,n.x,n.y,n.w,n.h,0,-1,1,1),s.restore();this.compose()}paintSolidColorImageMask(){this.contentVisible&&(this.ctx.fillRect(0,0,1,1),this.compose())}markPoint(t){}markPointProps(t,e){}beginMarkedContent(t){this.markedContentStack.push({visible:!0})}beginMarkedContentProps(t,e){t==="OC"?this.markedContentStack.push({visible:this.optionalContentConfig.isVisible(e)}):this.markedContentStack.push({visible:!0}),this.contentVisible=this.isContentVisible()}endMarkedContent(){this.markedContentStack.pop(),this.contentVisible=this.isContentVisible()}beginCompat(){}endCompat(){}consumePath(t){const e=this.current.isEmptyClip();this.pendingClip&&this.current.updateClipFromPath(),this.pendingClip||this.compose(t);const s=this.ctx;this.pendingClip&&(e||(this.pendingClip===yb?s.clip("evenodd"):s.clip()),this.pendingClip=null),this.current.startNewPathAndClipBox(this.current.clipBox),s.beginPath()}getSinglePixelWidth(){if(!this._cachedGetSinglePixelWidth){const t=Tt(this.ctx);if(t[1]===0&&t[2]===0)this._cachedGetSinglePixelWidth=1/Math.min(Math.abs(t[0]),Math.abs(t[3]));else{const e=Math.abs(t[0]*t[3]-t[2]*t[1]),s=Math.hypot(t[0],t[2]),i=Math.hypot(t[1],t[3]);this._cachedGetSinglePixelWidth=Math.max(s,i)/e}}return this._cachedGetSinglePixelWidth}getScaleForStroking(){if(this._cachedScaleForStroking[0]===-1){const{lineWidth:t}=this.current,{a:e,b:s,c:i,d:n}=this.ctx.getTransform();let r,o;if(s===0&&i===0){const h=Math.abs(e),c=Math.abs(n);if(h===c)if(t===0)r=o=1/h;else{const u=h*t;r=o=u<1?1/u:1}else if(t===0)r=1/h,o=1/c;else{const u=h*t,d=c*t;r=u<1?1/u:1,o=d<1?1/d:1}}else{const h=Math.abs(e*n-s*i),c=Math.hypot(e,s),u=Math.hypot(i,n);if(t===0)r=u/h,o=c/h;else{const d=t*h;r=u>d?u/d:1,o=c>d?c/d:1}}this._cachedScaleForStroking[0]=r,this._cachedScaleForStroking[1]=o}return this._cachedScaleForStroking}rescaleAndStroke(t){const{ctx:e}=this,{lineWidth:s}=this.current,[i,n]=this.getScaleForStroking();if(e.lineWidth=s||1,i===1&&n===1){e.stroke();return}const r=e.getLineDash();if(t&&e.save(),e.scale(i,n),r.length>0){const o=Math.max(i,n);e.setLineDash(r.map(h=>h/o)),e.lineDashOffset/=o}e.stroke(),t&&e.restore()}isContentVisible(){for(let t=this.markedContentStack.length-1;t>=0;t--)if(!this.markedContentStack[t].visible)return!1;return!0}};Ys=new WeakSet,gp=function(){for(;this.stateStack.length||this.inSMaskMode;)this.restore();this.current.activeSMask=null,this.ctx.restore(),this.transparentCanvas&&(this.ctx=this.compositeCtx,this.ctx.save(),this.ctx.setTransform(1,0,0,1,0,0),this.ctx.drawImage(this.transparentCanvas,0,0),this.ctx.restore(),this.transparentCanvas=null)},pp=function(){if(this.pageColors){const t=this.filterFactory.addHCMFilter(this.pageColors.foreground,this.pageColors.background);if(t!=="none"){const e=this.ctx.filter;this.ctx.filter=t,this.ctx.drawImage(this.ctx.canvas,0,0),this.ctx.filter=e}}},mp=function(t,e,s){const i=new Path2D;return i.addPath(t,new DOMMatrix(s).invertSelf().multiplySelf(e)),i};let ra=Wg;for(const a in Hs)ra.prototype[a]!==void 0&&(ra.prototype[Hs[a]]=ra.prototype[a]);class Vi{static get workerPort(){return l(this,El)}static set workerPort(t){if(!(typeof Worker<"u"&&t instanceof Worker)&&t!==null)throw new Error("Invalid `workerPort` type.");m(this,El,t)}static get workerSrc(){return l(this,kl)}static set workerSrc(t){if(typeof t!="string")throw new Error("Invalid `workerSrc` type.");m(this,kl,t)}}El=new WeakMap,kl=new WeakMap,y(Vi,El,null),y(Vi,kl,"");class Bx{constructor({parsedData:t,rawData:e}){y(this,so);y(this,Ml);m(this,so,t),m(this,Ml,e)}getRaw(){return l(this,Ml)}get(t){return l(this,so).get(t)??null}getAll(){return lg(l(this,so))}has(t){return l(this,so).has(t)}}so=new WeakMap,Ml=new WeakMap;const oa=Symbol("INTERNAL");class Hx{constructor(t,{name:e,intent:s,usage:i,rbGroups:n}){y(this,Pl,!1);y(this,Dl,!1);y(this,Ol,!1);y(this,Ta,!0);m(this,Pl,!!(t&ts.DISPLAY)),m(this,Dl,!!(t&ts.PRINT)),this.name=e,this.intent=s,this.usage=i,this.rbGroups=n}get visible(){if(l(this,Ol))return l(this,Ta);if(!l(this,Ta))return!1;const{print:t,view:e}=this.usage;return l(this,Pl)?(e==null?void 0:e.viewState)!=="OFF":l(this,Dl)?(t==null?void 0:t.printState)!=="OFF":!0}_setVisible(t,e,s=!1){t!==oa&&vt("Internal method `_setVisible` called."),m(this,Ol,s),m(this,Ta,e)}}Pl=new WeakMap,Dl=new WeakMap,Ol=new WeakMap,Ta=new WeakMap;class Gx{constructor(t,e=ts.DISPLAY){y(this,Rl);y(this,qn,null);y(this,mt,new Map);y(this,Ea,null);y(this,ka,null);if(this.renderingIntent=e,this.name=null,this.creator=null,t!==null){this.name=t.name,this.creator=t.creator,m(this,ka,t.order);for(const s of t.groups)l(this,mt).set(s.id,new Hx(e,s));if(t.baseState==="OFF")for(const s of l(this,mt).values())s._setVisible(oa,!1);for(const s of t.on)l(this,mt).get(s)._setVisible(oa,!0);for(const s of t.off)l(this,mt).get(s)._setVisible(oa,!1);m(this,Ea,this.getHash())}}isVisible(t){if(l(this,mt).size===0)return!0;if(!t)return Xu("Optional content group not defined."),!0;if(t.type==="OCG")return l(this,mt).has(t.id)?l(this,mt).get(t.id).visible:(tt(`Optional content group not found: ${t.id}`),!0);if(t.type==="OCMD"){if(t.expression)return w(this,Rl,bp).call(this,t.expression);if(!t.policy||t.policy==="AnyOn"){for(const e of t.ids){if(!l(this,mt).has(e))return tt(`Optional content group not found: ${e}`),!0;if(l(this,mt).get(e).visible)return!0}return!1}else if(t.policy==="AllOn"){for(const e of t.ids){if(!l(this,mt).has(e))return tt(`Optional content group not found: ${e}`),!0;if(!l(this,mt).get(e).visible)return!1}return!0}else if(t.policy==="AnyOff"){for(const e of t.ids){if(!l(this,mt).has(e))return tt(`Optional content group not found: ${e}`),!0;if(!l(this,mt).get(e).visible)return!0}return!1}else if(t.policy==="AllOff"){for(const e of t.ids){if(!l(this,mt).has(e))return tt(`Optional content group not found: ${e}`),!0;if(l(this,mt).get(e).visible)return!1}return!0}return tt(`Unknown optional content policy ${t.policy}.`),!0}return tt(`Unknown group type ${t.type}.`),!0}setVisibility(t,e=!0,s=!0){var n;const i=l(this,mt).get(t);if(!i){tt(`Optional content group not found: ${t}`);return}if(s&&e&&i.rbGroups.length)for(const r of i.rbGroups)for(const o of r)o!==t&&((n=l(this,mt).get(o))==null||n._setVisible(oa,!1,!0));i._setVisible(oa,!!e,!0),m(this,qn,null)}setOCGState({state:t,preserveRB:e}){let s;for(const i of t){switch(i){case"ON":case"OFF":case"Toggle":s=i;continue}const n=l(this,mt).get(i);if(n)switch(s){case"ON":this.setVisibility(i,!0,e);break;case"OFF":this.setVisibility(i,!1,e);break;case"Toggle":this.setVisibility(i,!n.visible,e);break}}m(this,qn,null)}get hasInitialVisibility(){return l(this,Ea)===null||this.getHash()===l(this,Ea)}getOrder(){return l(this,mt).size?l(this,ka)?l(this,ka).slice():[...l(this,mt).keys()]:null}getGroups(){return l(this,mt).size>0?lg(l(this,mt)):null}getGroup(t){return l(this,mt).get(t)||null}getHash(){if(l(this,qn)!==null)return l(this,qn);const t=new Z0;for(const[e,s]of l(this,mt))t.update(`${e}:${s.visible}`);return m(this,qn,t.hexdigest())}}qn=new WeakMap,mt=new WeakMap,Ea=new WeakMap,ka=new WeakMap,Rl=new WeakSet,bp=function(t){const e=t.length;if(e<2)return!0;const s=t[0];for(let i=1;i<e;i++){const n=t[i];let r;if(Array.isArray(n))r=w(this,Rl,bp).call(this,n);else if(l(this,mt).has(n))r=l(this,mt).get(n).visible;else return tt(`Optional content group not found: ${n}`),!0;switch(s){case"And":if(!r)return!1;break;case"Or":if(r)return!0;break;case"Not":return!r;default:return!0}}return s==="And"};class zx{constructor(t,{disableRange:e=!1,disableStream:s=!1}){Xt(t,'PDFDataTransportStream - missing required "pdfDataRangeTransport" argument.');const{length:i,initialData:n,progressiveDone:r,contentDispositionFilename:o}=t;if(this._queuedChunks=[],this._progressiveDone=r,this._contentDispositionFilename=o,(n==null?void 0:n.length)>0){const h=n instanceof Uint8Array&&n.byteLength===n.buffer.byteLength?n.buffer:new Uint8Array(n).buffer;this._queuedChunks.push(h)}this._pdfDataRangeTransport=t,this._isStreamingSupported=!s,this._isRangeSupported=!e,this._contentLength=i,this._fullRequestReader=null,this._rangeReaders=[],t.addRangeListener((h,c)=>{this._onReceiveData({begin:h,chunk:c})}),t.addProgressListener((h,c)=>{this._onProgress({loaded:h,total:c})}),t.addProgressiveReadListener(h=>{this._onReceiveData({chunk:h})}),t.addProgressiveDoneListener(()=>{this._onProgressiveDone()}),t.transportReady()}_onReceiveData({begin:t,chunk:e}){const s=e instanceof Uint8Array&&e.byteLength===e.buffer.byteLength?e.buffer:new Uint8Array(e).buffer;if(t===void 0)this._fullRequestReader?this._fullRequestReader._enqueue(s):this._queuedChunks.push(s);else{const i=this._rangeReaders.some(function(n){return n._begin!==t?!1:(n._enqueue(s),!0)});Xt(i,"_onReceiveData - no `PDFDataTransportStreamRangeReader` instance found.")}}get _progressiveDataLength(){var t;return((t=this._fullRequestReader)==null?void 0:t._loaded)??0}_onProgress(t){var e,s,i,n;t.total===void 0?(s=(e=this._rangeReaders[0])==null?void 0:e.onProgress)==null||s.call(e,{loaded:t.loaded}):(n=(i=this._fullRequestReader)==null?void 0:i.onProgress)==null||n.call(i,{loaded:t.loaded,total:t.total})}_onProgressiveDone(){var t;(t=this._fullRequestReader)==null||t.progressiveDone(),this._progressiveDone=!0}_removeRangeReader(t){const e=this._rangeReaders.indexOf(t);e>=0&&this._rangeReaders.splice(e,1)}getFullReader(){Xt(!this._fullRequestReader,"PDFDataTransportStream.getFullReader can only be called once.");const t=this._queuedChunks;return this._queuedChunks=null,new Vx(this,t,this._progressiveDone,this._contentDispositionFilename)}getRangeReader(t,e){if(e<=this._progressiveDataLength)return null;const s=new Xx(this,t,e);return this._pdfDataRangeTransport.requestDataRange(t,e),this._rangeReaders.push(s),s}cancelAllRequests(t){var e;(e=this._fullRequestReader)==null||e.cancel(t);for(const s of this._rangeReaders.slice(0))s.cancel(t);this._pdfDataRangeTransport.abort()}}class Vx{constructor(t,e,s=!1,i=null){this._stream=t,this._done=s||!1,this._filename=gg(i)?i:null,this._queuedChunks=e||[],this._loaded=0;for(const n of this._queuedChunks)this._loaded+=n.byteLength;this._requests=[],this._headersReady=Promise.resolve(),t._fullRequestReader=this,this.onProgress=null}_enqueue(t){this._done||(this._requests.length>0?this._requests.shift().resolve({value:t,done:!1}):this._queuedChunks.push(t),this._loaded+=t.byteLength)}get headersReady(){return this._headersReady}get filename(){return this._filename}get isRangeSupported(){return this._stream._isRangeSupported}get isStreamingSupported(){return this._stream._isStreamingSupported}get contentLength(){return this._stream._contentLength}async read(){if(this._queuedChunks.length>0)return{value:this._queuedChunks.shift(),done:!1};if(this._done)return{value:void 0,done:!0};const t=Promise.withResolvers();return this._requests.push(t),t.promise}cancel(t){this._done=!0;for(const e of this._requests)e.resolve({value:void 0,done:!0});this._requests.length=0}progressiveDone(){this._done||(this._done=!0)}}class Xx{constructor(t,e,s){this._stream=t,this._begin=e,this._end=s,this._queuedChunk=null,this._requests=[],this._done=!1,this.onProgress=null}_enqueue(t){if(!this._done){if(this._requests.length===0)this._queuedChunk=t;else{this._requests.shift().resolve({value:t,done:!1});for(const s of this._requests)s.resolve({value:void 0,done:!0});this._requests.length=0}this._done=!0,this._stream._removeRangeReader(this)}}get isStreamingSupported(){return!1}async read(){if(this._queuedChunk){const e=this._queuedChunk;return this._queuedChunk=null,{value:e,done:!1}}if(this._done)return{value:void 0,done:!0};const t=Promise.withResolvers();return this._requests.push(t),t.promise}cancel(t){this._done=!0;for(const e of this._requests)e.resolve({value:void 0,done:!0});this._requests.length=0,this._stream._removeRangeReader(this)}}function Wx(a){let t=!0,e=s("filename\\*","i").exec(a);if(e){e=e[1];let u=o(e);return u=unescape(u),u=h(u),u=c(u),n(u)}if(e=r(a),e){const u=c(e);return n(u)}if(e=s("filename","i").exec(a),e){e=e[1];let u=o(e);return u=c(u),n(u)}function s(u,d){return new RegExp("(?:^|;)\\s*"+u+'\\s*=\\s*([^";\\s][^;\\s]*|"(?:[^"\\\\]|\\\\"?)+"?)',d)}function i(u,d){if(u){if(!/^[\x00-\xFF]+$/.test(d))return d;try{const f=new TextDecoder(u,{fatal:!0}),g=Uu(d);d=f.decode(g),t=!1}catch{}}return d}function n(u){return t&&/[\x80-\xff]/.test(u)&&(u=i("utf-8",u),t&&(u=i("iso-8859-1",u))),u}function r(u){const d=[];let f;const g=s("filename\\*((?!0\\d)\\d+)(\\*?)","ig");for(;(f=g.exec(u))!==null;){let[,b,_,v]=f;if(b=parseInt(b,10),b in d){if(b===0)break;continue}d[b]=[_,v]}const p=[];for(let b=0;b<d.length&&b in d;++b){let[_,v]=d[b];v=o(v),_&&(v=unescape(v),b===0&&(v=h(v))),p.push(v)}return p.join("")}function o(u){if(u.startsWith('"')){const d=u.slice(1).split('\\"');for(let f=0;f<d.length;++f){const g=d[f].indexOf('"');g!==-1&&(d[f]=d[f].slice(0,g),d.length=f+1),d[f]=d[f].replaceAll(/\\(.)/g,"$1")}u=d.join('"')}return u}function h(u){const d=u.indexOf("'");if(d===-1)return u;const f=u.slice(0,d),p=u.slice(d+1).replace(/^[^']*'/,"");return i(f,p)}function c(u){return!u.startsWith("=?")||/[\x00-\x19\x80-\xff]/.test(u)?u:u.replaceAll(/=\?([\w-]*)\?([QqBb])\?((?:[^?]|\?(?!=))*)\?=/g,function(d,f,g,p){if(g==="q"||g==="Q")return p=p.replaceAll("_"," "),p=p.replaceAll(/=([0-9a-fA-F]{2})/g,function(b,_){return String.fromCharCode(parseInt(_,16))}),i(f,p);try{p=atob(p)}catch{}return i(f,p)})}return""}function vb(a,t){const e=new Headers;if(!a||!t||typeof t!="object")return e;for(const s in t){const i=t[s];i!==void 0&&e.append(s,i)}return e}function ed(a){try{return new URL(a).origin}catch{}return null}function _b({responseHeaders:a,isHttp:t,rangeChunkSize:e,disableRange:s}){const i={allowRangeRequests:!1,suggestedLength:void 0},n=parseInt(a.get("Content-Length"),10);return!Number.isInteger(n)||(i.suggestedLength=n,n<=2*e)||s||!t||a.get("Accept-Ranges")!=="bytes"||(a.get("Content-Encoding")||"identity")!=="identity"||(i.allowRangeRequests=!0),i}function wb(a){const t=a.get("Content-Disposition");if(t){let e=Wx(t);if(e.includes("%"))try{e=decodeURIComponent(e)}catch{}if(gg(e))return e}return null}function sd(a,t){return a===404||a===0&&t.startsWith("file:")?new Gh('Missing PDF "'+t+'".'):new Wu(`Unexpected server response (${a}) while retrieving PDF "${t}".`,a)}function xb(a){return a===200||a===206}function Sb(a,t,e){return{method:"GET",headers:a,signal:e.signal,mode:"cors",credentials:t?"include":"same-origin",redirect:"follow"}}function Cb(a){return a instanceof Uint8Array?a.buffer:a instanceof ArrayBuffer?a:(tt(`getArrayBuffer - unexpected data format: ${a}`),new Uint8Array(a).buffer)}class Ab{constructor(t){$(this,"_responseOrigin",null);this.source=t,this.isHttp=/^https?:/i.test(t.url),this.headers=vb(this.isHttp,t.httpHeaders),this._fullRequestReader=null,this._rangeRequestReaders=[]}get _progressiveDataLength(){var t;return((t=this._fullRequestReader)==null?void 0:t._loaded)??0}getFullReader(){return Xt(!this._fullRequestReader,"PDFFetchStream.getFullReader can only be called once."),this._fullRequestReader=new Ux(this),this._fullRequestReader}getRangeReader(t,e){if(e<=this._progressiveDataLength)return null;const s=new Yx(this,t,e);return this._rangeRequestReaders.push(s),s}cancelAllRequests(t){var e;(e=this._fullRequestReader)==null||e.cancel(t);for(const s of this._rangeRequestReaders.slice(0))s.cancel(t)}}class Ux{constructor(t){this._stream=t,this._reader=null,this._loaded=0,this._filename=null;const e=t.source;this._withCredentials=e.withCredentials||!1,this._contentLength=e.length,this._headersCapability=Promise.withResolvers(),this._disableRange=e.disableRange||!1,this._rangeChunkSize=e.rangeChunkSize,!this._rangeChunkSize&&!this._disableRange&&(this._disableRange=!0),this._abortController=new AbortController,this._isStreamingSupported=!e.disableStream,this._isRangeSupported=!e.disableRange;const s=new Headers(t.headers),i=e.url;fetch(i,Sb(s,this._withCredentials,this._abortController)).then(n=>{if(t._responseOrigin=ed(n.url),!xb(n.status))throw sd(n.status,i);this._reader=n.body.getReader(),this._headersCapability.resolve();const r=n.headers,{allowRangeRequests:o,suggestedLength:h}=_b({responseHeaders:r,isHttp:t.isHttp,rangeChunkSize:this._rangeChunkSize,disableRange:this._disableRange});this._isRangeSupported=o,this._contentLength=h||this._contentLength,this._filename=wb(r),!this._isStreamingSupported&&this._isRangeSupported&&this.cancel(new Rn("Streaming is disabled."))}).catch(this._headersCapability.reject),this.onProgress=null}get headersReady(){return this._headersCapability.promise}get filename(){return this._filename}get contentLength(){return this._contentLength}get isRangeSupported(){return this._isRangeSupported}get isStreamingSupported(){return this._isStreamingSupported}async read(){var s;await this._headersCapability.promise;const{value:t,done:e}=await this._reader.read();return e?{value:t,done:e}:(this._loaded+=t.byteLength,(s=this.onProgress)==null||s.call(this,{loaded:this._loaded,total:this._contentLength}),{value:Cb(t),done:!1})}cancel(t){var e;(e=this._reader)==null||e.cancel(t),this._abortController.abort()}}class Yx{constructor(t,e,s){this._stream=t,this._reader=null,this._loaded=0;const i=t.source;this._withCredentials=i.withCredentials||!1,this._readCapability=Promise.withResolvers(),this._isStreamingSupported=!i.disableStream,this._abortController=new AbortController;const n=new Headers(t.headers);n.append("Range",`bytes=${e}-${s-1}`);const r=i.url;fetch(r,Sb(n,this._withCredentials,this._abortController)).then(o=>{const h=ed(o.url);if(h!==t._responseOrigin)throw new Error(`Expected range response-origin "${h}" to match "${t._responseOrigin}".`);if(!xb(o.status))throw sd(o.status,r);this._readCapability.resolve(),this._reader=o.body.getReader()}).catch(this._readCapability.reject),this.onProgress=null}get isStreamingSupported(){return this._isStreamingSupported}async read(){var s;await this._readCapability.promise;const{value:t,done:e}=await this._reader.read();return e?{value:t,done:e}:(this._loaded+=t.byteLength,(s=this.onProgress)==null||s.call(this,{loaded:this._loaded}),{value:Cb(t),done:!1})}cancel(t){var e;(e=this._reader)==null||e.cancel(t),this._abortController.abort()}}const Eg=200,kg=206;function $x(a){const t=a.response;return typeof t!="string"?t:Uu(t).buffer}class qx{constructor({url:t,httpHeaders:e,withCredentials:s}){$(this,"_responseOrigin",null);this.url=t,this.isHttp=/^https?:/i.test(t),this.headers=vb(this.isHttp,e),this.withCredentials=s||!1,this.currXhrId=0,this.pendingRequests=Object.create(null)}request(t){const e=new XMLHttpRequest,s=this.currXhrId++,i=this.pendingRequests[s]={xhr:e};e.open("GET",this.url),e.withCredentials=this.withCredentials;for(const[n,r]of this.headers)e.setRequestHeader(n,r);return this.isHttp&&"begin"in t&&"end"in t?(e.setRequestHeader("Range",`bytes=${t.begin}-${t.end-1}`),i.expectedStatus=kg):i.expectedStatus=Eg,e.responseType="arraybuffer",Xt(t.onError,"Expected `onError` callback to be provided."),e.onerror=()=>{t.onError(e.status)},e.onreadystatechange=this.onStateChange.bind(this,s),e.onprogress=this.onProgress.bind(this,s),i.onHeadersReceived=t.onHeadersReceived,i.onDone=t.onDone,i.onError=t.onError,i.onProgress=t.onProgress,e.send(null),s}onProgress(t,e){var i;const s=this.pendingRequests[t];s&&((i=s.onProgress)==null||i.call(s,e))}onStateChange(t,e){const s=this.pendingRequests[t];if(!s)return;const i=s.xhr;if(i.readyState>=2&&s.onHeadersReceived&&(s.onHeadersReceived(),delete s.onHeadersReceived),i.readyState!==4||!(t in this.pendingRequests))return;if(delete this.pendingRequests[t],i.status===0&&this.isHttp){s.onError(i.status);return}const n=i.status||Eg;if(!(n===Eg&&s.expectedStatus===kg)&&n!==s.expectedStatus){s.onError(i.status);return}const o=$x(i);if(n===kg){const h=i.getResponseHeader("Content-Range"),c=/bytes (\d+)-(\d+)\/(\d+)/.exec(h);c?s.onDone({begin:parseInt(c[1],10),chunk:o}):(tt('Missing or invalid "Content-Range" header.'),s.onError(0))}else o?s.onDone({begin:0,chunk:o}):s.onError(i.status)}getRequestXhr(t){return this.pendingRequests[t].xhr}isPendingRequest(t){return t in this.pendingRequests}abortRequest(t){const e=this.pendingRequests[t].xhr;delete this.pendingRequests[t],e.abort()}}class Kx{constructor(t){this._source=t,this._manager=new qx(t),this._rangeChunkSize=t.rangeChunkSize,this._fullRequestReader=null,this._rangeRequestReaders=[]}_onRangeRequestReaderClosed(t){const e=this._rangeRequestReaders.indexOf(t);e>=0&&this._rangeRequestReaders.splice(e,1)}getFullReader(){return Xt(!this._fullRequestReader,"PDFNetworkStream.getFullReader can only be called once."),this._fullRequestReader=new Qx(this._manager,this._source),this._fullRequestReader}getRangeReader(t,e){const s=new Jx(this._manager,t,e);return s.onClosed=this._onRangeRequestReaderClosed.bind(this),this._rangeRequestReaders.push(s),s}cancelAllRequests(t){var e;(e=this._fullRequestReader)==null||e.cancel(t);for(const s of this._rangeRequestReaders.slice(0))s.cancel(t)}}class Qx{constructor(t,e){this._manager=t,this._url=e.url,this._fullRequestId=t.request({onHeadersReceived:this._onHeadersReceived.bind(this),onDone:this._onDone.bind(this),onError:this._onError.bind(this),onProgress:this._onProgress.bind(this)}),this._headersCapability=Promise.withResolvers(),this._disableRange=e.disableRange||!1,this._contentLength=e.length,this._rangeChunkSize=e.rangeChunkSize,!this._rangeChunkSize&&!this._disableRange&&(this._disableRange=!0),this._isStreamingSupported=!1,this._isRangeSupported=!1,this._cachedChunks=[],this._requests=[],this._done=!1,this._storedError=void 0,this._filename=null,this.onProgress=null}_onHeadersReceived(){const t=this._fullRequestId,e=this._manager.getRequestXhr(t);this._manager._responseOrigin=ed(e.responseURL);const s=e.getAllResponseHeaders(),i=new Headers(s?s.trimStart().replace(/[^\S ]+$/,"").split(/[\r\n]+/).map(o=>{const[h,...c]=o.split(": ");return[h,c.join(": ")]}):[]),{allowRangeRequests:n,suggestedLength:r}=_b({responseHeaders:i,isHttp:this._manager.isHttp,rangeChunkSize:this._rangeChunkSize,disableRange:this._disableRange});n&&(this._isRangeSupported=!0),this._contentLength=r||this._contentLength,this._filename=wb(i),this._isRangeSupported&&this._manager.abortRequest(t),this._headersCapability.resolve()}_onDone(t){if(t&&(this._requests.length>0?this._requests.shift().resolve({value:t.chunk,done:!1}):this._cachedChunks.push(t.chunk)),this._done=!0,!(this._cachedChunks.length>0)){for(const e of this._requests)e.resolve({value:void 0,done:!0});this._requests.length=0}}_onError(t){this._storedError=sd(t,this._url),this._headersCapability.reject(this._storedError);for(const e of this._requests)e.reject(this._storedError);this._requests.length=0,this._cachedChunks.length=0}_onProgress(t){var e;(e=this.onProgress)==null||e.call(this,{loaded:t.loaded,total:t.lengthComputable?t.total:this._contentLength})}get filename(){return this._filename}get isRangeSupported(){return this._isRangeSupported}get isStreamingSupported(){return this._isStreamingSupported}get contentLength(){return this._contentLength}get headersReady(){return this._headersCapability.promise}async read(){if(await this._headersCapability.promise,this._storedError)throw this._storedError;if(this._cachedChunks.length>0)return{value:this._cachedChunks.shift(),done:!1};if(this._done)return{value:void 0,done:!0};const t=Promise.withResolvers();return this._requests.push(t),t.promise}cancel(t){this._done=!0,this._headersCapability.reject(t);for(const e of this._requests)e.resolve({value:void 0,done:!0});this._requests.length=0,this._manager.isPendingRequest(this._fullRequestId)&&this._manager.abortRequest(this._fullRequestId),this._fullRequestReader=null}}class Jx{constructor(t,e,s){this._manager=t,this._url=t.url,this._requestId=t.request({begin:e,end:s,onHeadersReceived:this._onHeadersReceived.bind(this),onDone:this._onDone.bind(this),onError:this._onError.bind(this),onProgress:this._onProgress.bind(this)}),this._requests=[],this._queuedChunk=null,this._done=!1,this._storedError=void 0,this.onProgress=null,this.onClosed=null}_onHeadersReceived(){var e;const t=ed((e=this._manager.getRequestXhr(this._requestId))==null?void 0:e.responseURL);t!==this._manager._responseOrigin&&(this._storedError=new Error(`Expected range response-origin "${t}" to match "${this._manager._responseOrigin}".`),this._onError(0))}_close(){var t;(t=this.onClosed)==null||t.call(this,this)}_onDone(t){const e=t.chunk;this._requests.length>0?this._requests.shift().resolve({value:e,done:!1}):this._queuedChunk=e,this._done=!0;for(const s of this._requests)s.resolve({value:void 0,done:!0});this._requests.length=0,this._close()}_onError(t){this._storedError??(this._storedError=sd(t,this._url));for(const e of this._requests)e.reject(this._storedError);this._requests.length=0,this._queuedChunk=null}_onProgress(t){var e;this.isStreamingSupported||(e=this.onProgress)==null||e.call(this,{loaded:t.loaded})}get isStreamingSupported(){return!1}async read(){if(this._storedError)throw this._storedError;if(this._queuedChunk!==null){const e=this._queuedChunk;return this._queuedChunk=null,{value:e,done:!1}}if(this._done)return{value:void 0,done:!0};const t=Promise.withResolvers();return this._requests.push(t),t.promise}cancel(t){this._done=!0;for(const e of this._requests)e.resolve({value:void 0,done:!0});this._requests.length=0,this._manager.isPendingRequest(this._requestId)&&this._manager.abortRequest(this._requestId),this._close()}}const Zx=/^[a-z][a-z0-9\-+.]+:/i;function tS(a){if(Zx.test(a))return new URL(a);const t=process.getBuiltinModule("url");return new URL(t.pathToFileURL(a))}class eS{constructor(t){this.source=t,this.url=tS(t.url),Xt(this.url.protocol==="file:","PDFNodeStream only supports file:// URLs."),this._fullRequestReader=null,this._rangeRequestReaders=[]}get _progressiveDataLength(){var t;return((t=this._fullRequestReader)==null?void 0:t._loaded)??0}getFullReader(){return Xt(!this._fullRequestReader,"PDFNodeStream.getFullReader can only be called once."),this._fullRequestReader=new sS(this),this._fullRequestReader}getRangeReader(t,e){if(e<=this._progressiveDataLength)return null;const s=new iS(this,t,e);return this._rangeRequestReaders.push(s),s}cancelAllRequests(t){var e;(e=this._fullRequestReader)==null||e.cancel(t);for(const s of this._rangeRequestReaders.slice(0))s.cancel(t)}}class sS{constructor(t){this._url=t.url,this._done=!1,this._storedError=null,this.onProgress=null;const e=t.source;this._contentLength=e.length,this._loaded=0,this._filename=null,this._disableRange=e.disableRange||!1,this._rangeChunkSize=e.rangeChunkSize,!this._rangeChunkSize&&!this._disableRange&&(this._disableRange=!0),this._isStreamingSupported=!e.disableStream,this._isRangeSupported=!e.disableRange,this._readableStream=null,this._readCapability=Promise.withResolvers(),this._headersCapability=Promise.withResolvers();const s=process.getBuiltinModule("fs");s.promises.lstat(this._url).then(i=>{this._contentLength=i.size,this._setReadableStream(s.createReadStream(this._url)),this._headersCapability.resolve()},i=>{i.code==="ENOENT"&&(i=new Gh(`Missing PDF "${this._url}".`)),this._storedError=i,this._headersCapability.reject(i)})}get headersReady(){return this._headersCapability.promise}get filename(){return this._filename}get contentLength(){return this._contentLength}get isRangeSupported(){return this._isRangeSupported}get isStreamingSupported(){return this._isStreamingSupported}async read(){var s;if(await this._readCapability.promise,this._done)return{value:void 0,done:!0};if(this._storedError)throw this._storedError;const t=this._readableStream.read();return t===null?(this._readCapability=Promise.withResolvers(),this.read()):(this._loaded+=t.length,(s=this.onProgress)==null||s.call(this,{loaded:this._loaded,total:this._contentLength}),{value:new Uint8Array(t).buffer,done:!1})}cancel(t){if(!this._readableStream){this._error(t);return}this._readableStream.destroy(t)}_error(t){this._storedError=t,this._readCapability.resolve()}_setReadableStream(t){this._readableStream=t,t.on("readable",()=>{this._readCapability.resolve()}),t.on("end",()=>{t.destroy(),this._done=!0,this._readCapability.resolve()}),t.on("error",e=>{this._error(e)}),!this._isStreamingSupported&&this._isRangeSupported&&this._error(new Rn("streaming is disabled")),this._storedError&&this._readableStream.destroy(this._storedError)}}class iS{constructor(t,e,s){this._url=t.url,this._done=!1,this._storedError=null,this.onProgress=null,this._loaded=0,this._readableStream=null,this._readCapability=Promise.withResolvers();const i=t.source;this._isStreamingSupported=!i.disableStream;const n=process.getBuiltinModule("fs");this._setReadableStream(n.createReadStream(this._url,{start:e,end:s-1}))}get isStreamingSupported(){return this._isStreamingSupported}async read(){var s;if(await this._readCapability.promise,this._done)return{value:void 0,done:!0};if(this._storedError)throw this._storedError;const t=this._readableStream.read();return t===null?(this._readCapability=Promise.withResolvers(),this.read()):(this._loaded+=t.length,(s=this.onProgress)==null||s.call(this,{loaded:this._loaded}),{value:new Uint8Array(t).buffer,done:!1})}cancel(t){if(!this._readableStream){this._error(t);return}this._readableStream.destroy(t)}_error(t){this._storedError=t,this._readCapability.resolve()}_setReadableStream(t){this._readableStream=t,t.on("readable",()=>{this._readCapability.resolve()}),t.on("end",()=>{t.destroy(),this._done=!0,this._readCapability.resolve()}),t.on("error",e=>{this._error(e)}),this._storedError&&this._readableStream.destroy(this._storedError)}}const nS=1e5,Ye=30,rS=.8,Qt=class Qt{constructor({textContentSource:t,container:e,viewport:s}){y(this,nn);y(this,Kn,Promise.withResolvers());y(this,qe,null);y(this,Ll,!1);y(this,Fl,!!((Yb=globalThis.FontInspector)!=null&&Yb.enabled));y(this,io,null);y(this,sn,null);y(this,Il,0);y(this,Nl,0);y(this,no,null);y(this,Ma,null);y(this,Pa,0);y(this,Qn,0);y(this,Da,Object.create(null));y(this,jl,[]);y(this,Oa,null);y(this,ro,[]);y(this,Bl,new WeakMap);y(this,Hl,null);var h;if(t instanceof ReadableStream)m(this,Oa,t);else if(typeof t=="object")m(this,Oa,new ReadableStream({start(c){c.enqueue(t),c.close()}}));else throw new Error('No "textContentSource" parameter specified.');m(this,qe,m(this,Ma,e)),m(this,Qn,s.scale*(globalThis.devicePixelRatio||1)),m(this,Pa,s.rotation),m(this,sn,{div:null,properties:null,ctx:null});const{pageWidth:i,pageHeight:n,pageX:r,pageY:o}=s.rawDims;m(this,Hl,[1,0,0,-1,-r,o+n]),m(this,Nl,i),m(this,Il,n),w(h=Qt,rs,Dy).call(h),kr(e,s),l(this,Kn).promise.finally(()=>{l(Qt,Ra).delete(this),m(this,sn,null),m(this,Da,null)}).catch(()=>{})}static get fontFamilyMap(){const{isWindows:t,isFirefox:e}=Re.platform;return st(this,"fontFamilyMap",new Map([["sans-serif",`${t&&e?"Calibri, ":""}sans-serif`],["monospace",`${t&&e?"Lucida Console, ":""}monospace`]]))}render(){const t=()=>{l(this,no).read().then(({value:e,done:s})=>{if(s){l(this,Kn).resolve();return}l(this,io)??m(this,io,e.lang),Object.assign(l(this,Da),e.styles),w(this,nn,My).call(this,e.items),t()},l(this,Kn).reject)};return m(this,no,l(this,Oa).getReader()),l(Qt,Ra).add(this),t(),l(this,Kn).promise}update({viewport:t,onBefore:e=null}){var n;const s=t.scale*(globalThis.devicePixelRatio||1),i=t.rotation;if(i!==l(this,Pa)&&(e==null||e(),m(this,Pa,i),kr(l(this,Ma),{rotation:i})),s!==l(this,Qn)){e==null||e(),m(this,Qn,s);const r={div:null,properties:null,ctx:w(n=Qt,rs,jd).call(n,l(this,io))};for(const o of l(this,ro))r.properties=l(this,Bl).get(o),r.div=o,w(this,nn,yp).call(this,r)}}cancel(){var e;const t=new Rn("TextLayer task cancelled.");(e=l(this,no))==null||e.cancel(t).catch(()=>{}),m(this,no,null),l(this,Kn).reject(t)}get textDivs(){return l(this,ro)}get textContentItemsStr(){return l(this,jl)}static cleanup(){if(!(l(this,Ra).size>0)){l(this,oo).clear();for(const{canvas:t}of l(this,ao).values())t.remove();l(this,ao).clear()}}};Kn=new WeakMap,qe=new WeakMap,Ll=new WeakMap,Fl=new WeakMap,io=new WeakMap,sn=new WeakMap,Il=new WeakMap,Nl=new WeakMap,no=new WeakMap,Ma=new WeakMap,Pa=new WeakMap,Qn=new WeakMap,Da=new WeakMap,jl=new WeakMap,Oa=new WeakMap,ro=new WeakMap,Bl=new WeakMap,Hl=new WeakMap,oo=new WeakMap,ao=new WeakMap,Gl=new WeakMap,Jn=new WeakMap,Ra=new WeakMap,nn=new WeakSet,My=function(t){var i,n;if(l(this,Ll))return;(n=l(this,sn)).ctx??(n.ctx=w(i=Qt,rs,jd).call(i,l(this,io)));const e=l(this,ro),s=l(this,jl);for(const r of t){if(e.length>nS){tt("Ignoring additional textDivs for performance reasons."),m(this,Ll,!0);return}if(r.str===void 0){if(r.type==="beginMarkedContentProps"||r.type==="beginMarkedContent"){const o=l(this,qe);m(this,qe,document.createElement("span")),l(this,qe).classList.add("markedContent"),r.id!==null&&l(this,qe).setAttribute("id",`${r.id}`),o.append(l(this,qe))}else r.type==="endMarkedContent"&&m(this,qe,l(this,qe).parentNode);continue}s.push(r.str),w(this,nn,Py).call(this,r)}},Py=function(t){var b;const e=document.createElement("span"),s={angle:0,canvasWidth:0,hasText:t.str!=="",hasEOL:t.hasEOL,fontSize:0};l(this,ro).push(e);const i=W.transform(l(this,Hl),t.transform);let n=Math.atan2(i[1],i[0]);const r=l(this,Da)[t.fontName];r.vertical&&(n+=Math.PI/2);let o=l(this,Fl)&&r.fontSubstitution||r.fontFamily;o=Qt.fontFamilyMap.get(o)||o;const h=Math.hypot(i[2],i[3]),c=h*w(b=Qt,rs,Oy).call(b,o,l(this,io));let u,d;n===0?(u=i[4],d=i[5]-c):(u=i[4]+c*Math.sin(n),d=i[5]-c*Math.cos(n));const f="calc(var(--scale-factor)*",g=e.style;l(this,qe)===l(this,Ma)?(g.left=`${(100*u/l(this,Nl)).toFixed(2)}%`,g.top=`${(100*d/l(this,Il)).toFixed(2)}%`):(g.left=`${f}${u.toFixed(2)}px)`,g.top=`${f}${d.toFixed(2)}px)`),g.fontSize=`${f}${(l(Qt,Jn)*h).toFixed(2)}px)`,g.fontFamily=o,s.fontSize=h,e.setAttribute("role","presentation"),e.textContent=t.str,e.dir=t.dir,l(this,Fl)&&(e.dataset.fontName=r.fontSubstitutionLoadedName||t.fontName),n!==0&&(s.angle=n*(180/Math.PI));let p=!1;if(t.str.length>1)p=!0;else if(t.str!==" "&&t.transform[0]!==t.transform[3]){const _=Math.abs(t.transform[0]),v=Math.abs(t.transform[3]);_!==v&&Math.max(_,v)/Math.min(_,v)>1.5&&(p=!0)}if(p&&(s.canvasWidth=r.vertical?t.height:t.width),l(this,Bl).set(e,s),l(this,sn).div=e,l(this,sn).properties=s,w(this,nn,yp).call(this,l(this,sn)),s.hasText&&l(this,qe).append(e),s.hasEOL){const _=document.createElement("br");_.setAttribute("role","presentation"),l(this,qe).append(_)}},yp=function(t){var o;const{div:e,properties:s,ctx:i}=t,{style:n}=e;let r="";if(l(Qt,Jn)>1&&(r=`scale(${1/l(Qt,Jn)})`),s.canvasWidth!==0&&s.hasText){const{fontFamily:h}=n,{canvasWidth:c,fontSize:u}=s;w(o=Qt,rs,vp).call(o,i,u*l(this,Qn),h);const{width:d}=i.measureText(e.textContent);d>0&&(r=`scaleX(${c*l(this,Qn)/d}) ${r}`)}s.angle!==0&&(r=`rotate(${s.angle}deg) ${r}`),r.length>0&&(n.transform=r)},rs=new WeakSet,jd=function(t=null){let e=l(this,ao).get(t||(t=""));if(!e){const s=document.createElement("canvas");s.className="hiddenCanvasElement",s.lang=t,document.body.append(s),e=s.getContext("2d",{alpha:!1,willReadFrequently:!0}),l(this,ao).set(t,e),l(this,Gl).set(e,{size:0,family:""})}return e},vp=function(t,e,s){const i=l(this,Gl).get(t);e===i.size&&s===i.family||(t.font=`${e}px ${s}`,i.size=e,i.family=s)},Dy=function(){if(l(this,Jn)!==null)return;const t=document.createElement("div");t.style.opacity=0,t.style.lineHeight=1,t.style.fontSize="1px",t.style.position="absolute",t.textContent="X",document.body.append(t),m(this,Jn,t.getBoundingClientRect().height),t.remove()},Oy=function(t,e){const s=l(this,oo).get(t);if(s)return s;const i=w(this,rs,jd).call(this,e);i.canvas.width=i.canvas.height=Ye,w(this,rs,vp).call(this,i,Ye,t);const n=i.measureText("");let r=n.fontBoundingBoxAscent,o=Math.abs(n.fontBoundingBoxDescent);if(r){const u=r/(r+o);return l(this,oo).set(t,u),i.canvas.width=i.canvas.height=0,u}i.strokeStyle="red",i.clearRect(0,0,Ye,Ye),i.strokeText("g",0,0);let h=i.getImageData(0,0,Ye,Ye).data;o=0;for(let u=h.length-1-3;u>=0;u-=4)if(h[u]>0){o=Math.ceil(u/4/Ye);break}i.clearRect(0,0,Ye,Ye),i.strokeText("A",0,Ye),h=i.getImageData(0,0,Ye,Ye).data,r=0;for(let u=0,d=h.length;u<d;u+=4)if(h[u]>0){r=Ye-Math.floor(u/4/Ye);break}i.canvas.width=i.canvas.height=0;const c=r?r/(r+o):rS;return l(this,oo).set(t,c),c},y(Qt,rs),y(Qt,oo,new Map),y(Qt,ao,new Map),y(Qt,Gl,new WeakMap),y(Qt,Jn,null),y(Qt,Ra,new Set);let Yh=Qt;class $h{static textContent(t){const e=[],s={items:e,styles:Object.create(null)};function i(n){var h;if(!n)return;let r=null;const o=n.name;if(o==="#text")r=n.value;else if($h.shouldBuildText(o))(h=n==null?void 0:n.attributes)!=null&&h.textContent?r=n.attributes.textContent:n.value&&(r=n.value);else return;if(r!==null&&e.push({str:r}),!!n.children)for(const c of n.children)i(c)}return i(t),s}static shouldBuildText(t){return!(t==="textarea"||t==="input"||t==="option"||t==="select")}}const oS=65536,aS=100,hS=5e3,lS=ye?Sx:_x,cS=ye?Cx:nb,uS=ye?xx:wx,dS=ye?Ax:ab;function fS(a={}){typeof a=="string"||a instanceof URL?a={url:a}:(a instanceof ArrayBuffer||ArrayBuffer.isView(a))&&(a={data:a});const t=new Mg,{docId:e}=t,s=a.url?gS(a.url):null,i=a.data?pS(a.data):null,n=a.httpHeaders||null,r=a.withCredentials===!0,o=a.password??null,h=a.range instanceof Eb?a.range:null,c=Number.isInteger(a.rangeChunkSize)&&a.rangeChunkSize>0?a.rangeChunkSize:oS;let u=a.worker instanceof aa?a.worker:null;const d=a.verbosity,f=typeof a.docBaseUrl=="string"&&!$u(a.docBaseUrl)?a.docBaseUrl:null,g=typeof a.cMapUrl=="string"?a.cMapUrl:null,p=a.cMapPacked!==!1,b=a.CMapReaderFactory||cS,_=typeof a.standardFontDataUrl=="string"?a.standardFontDataUrl:null,v=a.StandardFontDataFactory||dS,x=a.stopAtErrors!==!0,C=Number.isInteger(a.maxImageSize)&&a.maxImageSize>-1?a.maxImageSize:-1,S=a.isEvalSupported!==!1,k=typeof a.isOffscreenCanvasSupported=="boolean"?a.isOffscreenCanvasSupported:!ye,M=typeof a.isImageDecoderSupported=="boolean"?a.isImageDecoderSupported:!ye&&(Re.platform.isFirefox||!globalThis.chrome),E=Number.isInteger(a.canvasMaxAreaInBytes)?a.canvasMaxAreaInBytes:-1,P=typeof a.disableFontFace=="boolean"?a.disableFontFace:ye,O=a.fontExtraProperties===!0,L=a.enableXfa===!0,R=a.ownerDocument||globalThis.document,U=a.disableRange===!0,z=a.disableStream===!0,V=a.disableAutoFetch===!0,at=a.pdfBug===!0,F=a.CanvasFactory||lS,G=a.FilterFactory||uS,rt=a.enableHWA===!0,Gt=h?h.length:a.length??NaN,te=typeof a.useSystemFonts=="boolean"?a.useSystemFonts:!ye&&!P,fe=typeof a.useWorkerFetch=="boolean"?a.useWorkerFetch:b===nb&&v===ab&&g&&_&&Vh(g,document.baseURI)&&Vh(_,document.baseURI),Yt=null;Jw(d);const St={canvasFactory:new F({ownerDocument:R,enableHWA:rt}),filterFactory:new G({docId:e,ownerDocument:R}),cMapReaderFactory:fe?null:new b({baseUrl:g,isCompressed:p}),standardFontDataFactory:fe?null:new v({baseUrl:_})};if(!u){const Ft={verbosity:d,port:Vi.workerPort};u=Ft.port?aa.fromPort(Ft):new aa(Ft),t._worker=u}const He={docId:e,apiVersion:"4.10.38",data:i,password:o,disableAutoFetch:V,rangeChunkSize:c,length:Gt,docBaseUrl:f,enableXfa:L,evaluatorOptions:{maxImageSize:C,disableFontFace:P,ignoreErrors:x,isEvalSupported:S,isOffscreenCanvasSupported:k,isImageDecoderSupported:M,canvasMaxAreaInBytes:E,fontExtraProperties:O,useSystemFonts:te,cMapUrl:fe?g:null,standardFontDataUrl:fe?_:null}},Mi={disableFontFace:P,fontExtraProperties:O,ownerDocument:R,pdfBug:at,styleElement:Yt,loadingParams:{disableAutoFetch:V,enableXfa:L}};return u.promise.then(function(){if(t.destroyed)throw new Error("Loading aborted");if(u.destroyed)throw new Error("Worker was destroyed");const Ft=u.messageHandler.sendWithPromise("GetDocRequest",He,i?[i.buffer]:null);let ft;if(h)ft=new zx(h,{disableRange:U,disableStream:z});else if(!i){if(!s)throw new Error("getDocument - no `url` parameter provided.");let fr;if(ye)if(Vh(s)){if(typeof fetch>"u"||typeof Response>"u"||!("body"in Response.prototype))throw new Error("getDocument - the Fetch API was disabled in Node.js, see `--no-experimental-fetch`.");fr=Ab}else fr=eS;else fr=Vh(s)?Ab:Kx;ft=new fr({url:s,length:Gt,httpHeaders:n,withCredentials:r,rangeChunkSize:c,disableRange:U,disableStream:z})}return Ft.then(fr=>{if(t.destroyed)throw new Error("Loading aborted");if(u.destroyed)throw new Error("Worker was destroyed");const ph=new Wh(e,fr,u.port),Pi=new vS(ph,t,ft,Mi,St);t._transport=Pi,ph.send("Ready",null)})}).catch(t._capability.reject),t}function gS(a){if(a instanceof URL)return a.href;try{return new URL(a,window.location).href}catch{if(ye&&typeof a=="string")return a}throw new Error("Invalid PDF url data: either string or URL-object is expected in the url property.")}function pS(a){if(ye&&typeof Buffer<"u"&&a instanceof Buffer)throw new Error("Please provide binary data as `Uint8Array`, rather than `Buffer`.");if(a instanceof Uint8Array&&a.byteLength===a.buffer.byteLength)return a;if(typeof a=="string")return Uu(a);if(a instanceof ArrayBuffer||ArrayBuffer.isView(a)||typeof a=="object"&&!isNaN(a==null?void 0:a.length))return new Uint8Array(a);throw new Error("Invalid PDF binary data: either TypedArray, string, or array-like object is expected in the data property.")}function Tb(a){return typeof a=="object"&&Number.isInteger(a==null?void 0:a.num)&&a.num>=0&&Number.isInteger(a==null?void 0:a.gen)&&a.gen>=0}const bd=class bd{constructor(){this._capability=Promise.withResolvers(),this._transport=null,this._worker=null,this.docId=`d${Ge(bd,md)._++}`,this.destroyed=!1,this.onPassword=null,this.onProgress=null}get promise(){return this._capability.promise}async destroy(){var t,e,s,i;this.destroyed=!0;try{(t=this._worker)!=null&&t.port&&(this._worker._pendingDestroy=!0),await((e=this._transport)==null?void 0:e.destroy())}catch(n){throw(s=this._worker)!=null&&s.port&&delete this._worker._pendingDestroy,n}this._transport=null,(i=this._worker)==null||i.destroy(),this._worker=null}};md=new WeakMap,y(bd,md,0);let Mg=bd;class Eb{constructor(t,e,s=!1,i=null){this.length=t,this.initialData=e,this.progressiveDone=s,this.contentDispositionFilename=i,this._rangeListeners=[],this._progressListeners=[],this._progressiveReadListeners=[],this._progressiveDoneListeners=[],this._readyCapability=Promise.withResolvers()}addRangeListener(t){this._rangeListeners.push(t)}addProgressListener(t){this._progressListeners.push(t)}addProgressiveReadListener(t){this._progressiveReadListeners.push(t)}addProgressiveDoneListener(t){this._progressiveDoneListeners.push(t)}onDataRange(t,e){for(const s of this._rangeListeners)s(t,e)}onDataProgress(t,e){this._readyCapability.promise.then(()=>{for(const s of this._progressListeners)s(t,e)})}onDataProgressiveRead(t){this._readyCapability.promise.then(()=>{for(const e of this._progressiveReadListeners)e(t)})}onDataProgressiveDone(){this._readyCapability.promise.then(()=>{for(const t of this._progressiveDoneListeners)t()})}transportReady(){this._readyCapability.resolve()}requestDataRange(t,e){vt("Abstract method PDFDataRangeTransport.requestDataRange")}abort(){}}class mS{constructor(t,e){this._pdfInfo=t,this._transport=e}get annotationStorage(){return this._transport.annotationStorage}get canvasFactory(){return this._transport.canvasFactory}get filterFactory(){return this._transport.filterFactory}get numPages(){return this._pdfInfo.numPages}get fingerprints(){return this._pdfInfo.fingerprints}get isPureXfa(){return st(this,"isPureXfa",!!this._transport._htmlForXfa)}get allXfaHtml(){return this._transport._htmlForXfa}getPage(t){return this._transport.getPage(t)}getPageIndex(t){return this._transport.getPageIndex(t)}getDestinations(){return this._transport.getDestinations()}getDestination(t){return this._transport.getDestination(t)}getPageLabels(){return this._transport.getPageLabels()}getPageLayout(){return this._transport.getPageLayout()}getPageMode(){return this._transport.getPageMode()}getViewerPreferences(){return this._transport.getViewerPreferences()}getOpenAction(){return this._transport.getOpenAction()}getAttachments(){return this._transport.getAttachments()}getJSActions(){return this._transport.getDocJSActions()}getOutline(){return this._transport.getOutline()}getOptionalContentConfig({intent:t="display"}={}){const{renderingIntent:e}=this._transport.getRenderingIntent(t);return this._transport.getOptionalContentConfig(e)}getPermissions(){return this._transport.getPermissions()}getMetadata(){return this._transport.getMetadata()}getMarkInfo(){return this._transport.getMarkInfo()}getData(){return this._transport.getData()}saveDocument(){return this._transport.saveDocument()}getDownloadInfo(){return this._transport.downloadInfoCapability.promise}cleanup(t=!1){return this._transport.startCleanup(t||this.isPureXfa)}destroy(){return this.loadingTask.destroy()}cachedPageNumber(t){return this._transport.cachedPageNumber(t)}get loadingParams(){return this._transport.loadingParams}get loadingTask(){return this._transport.loadingTask}getFieldObjects(){return this._transport.getFieldObjects()}hasJSActions(){return this._transport.hasJSActions()}getCalculationOrderIds(){return this._transport.getCalculationOrderIds()}}class bS{constructor(t,e,s,i=!1){y(this,As);y(this,Zn,null);y(this,rn,!1);this._pageIndex=t,this._pageInfo=e,this._transport=s,this._stats=i?new Q0:null,this._pdfBug=i,this.commonObjs=s.commonObjs,this.objs=new kb,this._maybeCleanupAfterRender=!1,this._intentStates=new Map,this.destroyed=!1}get pageNumber(){return this._pageIndex+1}get rotate(){return this._pageInfo.rotate}get ref(){return this._pageInfo.ref}get userUnit(){return this._pageInfo.userUnit}get view(){return this._pageInfo.view}getViewport({scale:t,rotation:e=this.rotate,offsetX:s=0,offsetY:i=0,dontFlip:n=!1}={}){return new zh({viewBox:this.view,userUnit:this.userUnit,scale:t,rotation:e,offsetX:s,offsetY:i,dontFlip:n})}getAnnotations({intent:t="display"}={}){const{renderingIntent:e}=this._transport.getRenderingIntent(t);return this._transport.getAnnotations(this._pageIndex,e)}getJSActions(){return this._transport.getPageJSActions(this._pageIndex)}get filterFactory(){return this._transport.filterFactory}get isPureXfa(){return st(this,"isPureXfa",!!this._transport._htmlForXfa)}async getXfa(){var t;return((t=this._transport._htmlForXfa)==null?void 0:t.children[this._pageIndex])||null}render({canvasContext:t,viewport:e,intent:s="display",annotationMode:i=Dn.ENABLE,transform:n=null,background:r=null,optionalContentConfigPromise:o=null,annotationCanvasMap:h=null,pageColors:c=null,printAnnotationStorage:u=null,isEditing:d=!1}){var S,k;(S=this._stats)==null||S.time("Overall");const f=this._transport.getRenderingIntent(s,i,u,d),{renderingIntent:g,cacheKey:p}=f;m(this,rn,!1),w(this,As,Bd).call(this),o||(o=this._transport.getOptionalContentConfig(g));let b=this._intentStates.get(p);b||(b=Object.create(null),this._intentStates.set(p,b)),b.streamReaderCancelTimeout&&(clearTimeout(b.streamReaderCancelTimeout),b.streamReaderCancelTimeout=null);const _=!!(g&ts.PRINT);b.displayReadyCapability||(b.displayReadyCapability=Promise.withResolvers(),b.operatorList={fnArray:[],argsArray:[],lastChunk:!1,separateAnnots:null},(k=this._stats)==null||k.time("Page Request"),this._pumpOperatorList(f));const v=M=>{var E;b.renderTasks.delete(x),(this._maybeCleanupAfterRender||_)&&m(this,rn,!0),w(this,As,vh).call(this,!_),M?(x.capability.reject(M),this._abortOperatorList({intentState:b,reason:M instanceof Error?M:new Error(M)})):x.capability.resolve(),this._stats&&(this._stats.timeEnd("Rendering"),this._stats.timeEnd("Overall"),(E=globalThis.Stats)!=null&&E.enabled&&globalThis.Stats.add(this.pageNumber,this._stats))},x=new Pg({callback:v,params:{canvasContext:t,viewport:e,transform:n,background:r},objs:this.objs,commonObjs:this.commonObjs,annotationCanvasMap:h,operatorList:b.operatorList,pageIndex:this._pageIndex,canvasFactory:this._transport.canvasFactory,filterFactory:this._transport.filterFactory,useRequestAnimationFrame:!_,pdfBug:this._pdfBug,pageColors:c});(b.renderTasks||(b.renderTasks=new Set)).add(x);const C=x.task;return Promise.all([b.displayReadyCapability.promise,o]).then(([M,E])=>{var P;if(this.destroyed){v();return}if((P=this._stats)==null||P.time("Rendering"),!(E.renderingIntent&g))throw new Error("Must use the same `intent`-argument when calling the `PDFPageProxy.render` and `PDFDocumentProxy.getOptionalContentConfig` methods.");x.initializeGraphics({transparency:M,optionalContentConfig:E}),x.operatorListChanged()}).catch(v),C}getOperatorList({intent:t="display",annotationMode:e=Dn.ENABLE,printAnnotationStorage:s=null,isEditing:i=!1}={}){var c;function n(){o.operatorList.lastChunk&&(o.opListReadCapability.resolve(o.operatorList),o.renderTasks.delete(h))}const r=this._transport.getRenderingIntent(t,e,s,i,!0);let o=this._intentStates.get(r.cacheKey);o||(o=Object.create(null),this._intentStates.set(r.cacheKey,o));let h;return o.opListReadCapability||(h=Object.create(null),h.operatorListChanged=n,o.opListReadCapability=Promise.withResolvers(),(o.renderTasks||(o.renderTasks=new Set)).add(h),o.operatorList={fnArray:[],argsArray:[],lastChunk:!1,separateAnnots:null},(c=this._stats)==null||c.time("Page Request"),this._pumpOperatorList(r)),o.opListReadCapability.promise}streamTextContent({includeMarkedContent:t=!1,disableNormalization:e=!1}={}){return this._transport.messageHandler.sendWithStream("GetTextContent",{pageIndex:this._pageIndex,includeMarkedContent:t===!0,disableNormalization:e===!0},{highWaterMark:100,size(i){return i.items.length}})}getTextContent(t={}){if(this._transport._htmlForXfa)return this.getXfa().then(s=>$h.textContent(s));const e=this.streamTextContent(t);return new Promise(function(s,i){function n(){r.read().then(function({value:h,done:c}){if(c){s(o);return}o.lang??(o.lang=h.lang),Object.assign(o.styles,h.styles),o.items.push(...h.items),n()},i)}const r=e.getReader(),o={items:[],styles:Object.create(null),lang:null};n()})}getStructTree(){return this._transport.getStructTree(this._pageIndex)}_destroy(){this.destroyed=!0;const t=[];for(const e of this._intentStates.values())if(this._abortOperatorList({intentState:e,reason:new Error("Page was destroyed."),force:!0}),!e.opListReadCapability)for(const s of e.renderTasks)t.push(s.completed),s.cancel();return this.objs.clear(),m(this,rn,!1),w(this,As,Bd).call(this),Promise.all(t)}cleanup(t=!1){m(this,rn,!0);const e=w(this,As,vh).call(this,!1);return t&&e&&this._stats&&(this._stats=new Q0),e}_startRenderPage(t,e){var i,n;const s=this._intentStates.get(e);s&&((i=this._stats)==null||i.timeEnd("Page Request"),(n=s.displayReadyCapability)==null||n.resolve(t))}_renderPageChunk(t,e){for(let s=0,i=t.length;s<i;s++)e.operatorList.fnArray.push(t.fnArray[s]),e.operatorList.argsArray.push(t.argsArray[s]);e.operatorList.lastChunk=t.lastChunk,e.operatorList.separateAnnots=t.separateAnnots;for(const s of e.renderTasks)s.operatorListChanged();t.lastChunk&&w(this,As,vh).call(this,!0)}_pumpOperatorList({renderingIntent:t,cacheKey:e,annotationStorageSerializable:s,modifiedIds:i}){const{map:n,transfer:r}=s,h=this._transport.messageHandler.sendWithStream("GetOperatorList",{pageIndex:this._pageIndex,intent:t,cacheKey:e,annotationStorage:n,modifiedIds:i},r).getReader(),c=this._intentStates.get(e);c.streamReader=h;const u=()=>{h.read().then(({value:d,done:f})=>{if(f){c.streamReader=null;return}this._transport.destroyed||(this._renderPageChunk(d,c),u())},d=>{if(c.streamReader=null,!this._transport.destroyed){if(c.operatorList){c.operatorList.lastChunk=!0;for(const f of c.renderTasks)f.operatorListChanged();w(this,As,vh).call(this,!0)}if(c.displayReadyCapability)c.displayReadyCapability.reject(d);else if(c.opListReadCapability)c.opListReadCapability.reject(d);else throw d}})};u()}_abortOperatorList({intentState:t,reason:e,force:s=!1}){if(t.streamReader){if(t.streamReaderCancelTimeout&&(clearTimeout(t.streamReaderCancelTimeout),t.streamReaderCancelTimeout=null),!s){if(t.renderTasks.size>0)return;if(e instanceof fg){let i=aS;e.extraDelay>0&&e.extraDelay<1e3&&(i+=e.extraDelay),t.streamReaderCancelTimeout=setTimeout(()=>{t.streamReaderCancelTimeout=null,this._abortOperatorList({intentState:t,reason:e,force:!0})},i);return}}if(t.streamReader.cancel(new Rn(e.message)).catch(()=>{}),t.streamReader=null,!this._transport.destroyed){for(const[i,n]of this._intentStates)if(n===t){this._intentStates.delete(i);break}this.cleanup()}}}get stats(){return this._stats}}Zn=new WeakMap,rn=new WeakMap,As=new WeakSet,vh=function(t=!1){if(w(this,As,Bd).call(this),!l(this,rn)||this.destroyed)return!1;if(t)return m(this,Zn,setTimeout(()=>{m(this,Zn,null),w(this,As,vh).call(this,!1)},hS)),!1;for(const{renderTasks:e,operatorList:s}of this._intentStates.values())if(e.size>0||!s.lastChunk)return!1;return this._intentStates.clear(),this.objs.clear(),m(this,rn,!1),!0},Bd=function(){l(this,Zn)&&(clearTimeout(l(this,Zn)),m(this,Zn,null))};class yS{constructor(){y(this,on,new Map);y(this,yd,Promise.resolve())}postMessage(t,e){const s={data:structuredClone(t,e?{transfer:e}:null)};l(this,yd).then(()=>{for(const[i]of l(this,on))i.call(this,s)})}addEventListener(t,e,s=null){let i=null;if((s==null?void 0:s.signal)instanceof AbortSignal){const{signal:n}=s;if(n.aborted){tt("LoopbackPort - cannot use an `aborted` signal.");return}const r=()=>this.removeEventListener(t,e);i=()=>n.removeEventListener("abort",r),n.addEventListener("abort",r)}l(this,on).set(e,i)}removeEventListener(t,e){const s=l(this,on).get(e);s==null||s(),l(this,on).delete(e)}terminate(){for(const[,t]of l(this,on))t==null||t();l(this,on).clear()}}on=new WeakMap,yd=new WeakMap;const Et=class Et{constructor({name:t=null,port:e=null,verbosity:s=Zw()}={}){y(this,La);var i;if(this.name=t,this.destroyed=!1,this.verbosity=s,this._readyCapability=Promise.withResolvers(),this._port=null,this._webWorker=null,this._messageHandler=null,e){if((i=l(Et,lo))!=null&&i.has(e))throw new Error("Cannot use more than one PDFWorker per port.");(l(Et,lo)||m(Et,lo,new WeakMap)).set(e,this),this._initializeFromPort(e);return}this._initialize()}get promise(){return this._readyCapability.promise}get port(){return this._port}get messageHandler(){return this._messageHandler}_initializeFromPort(t){this._port=t,this._messageHandler=new Wh("main","worker",t),this._messageHandler.on("ready",function(){}),w(this,La,Hd).call(this)}_initialize(){if(l(Et,ho)||l(Et,Fa,Gd)){this._setupFakeWorker();return}let{workerSrc:t}=Et;try{Et._isSameOrigin(window.location.href,t)||(t=Et._createCDNWrapper(new URL(t,window.location).href));const e=new Worker(t,{type:"module"}),s=new Wh("main","worker",e),i=()=>{n.abort(),s.destroy(),e.terminate(),this.destroyed?this._readyCapability.reject(new Error("Worker was destroyed")):this._setupFakeWorker()},n=new AbortController;e.addEventListener("error",()=>{this._webWorker||i()},{signal:n.signal}),s.on("test",o=>{if(n.abort(),this.destroyed||!o){i();return}this._messageHandler=s,this._port=e,this._webWorker=e,w(this,La,Hd).call(this)}),s.on("ready",o=>{if(n.abort(),this.destroyed){i();return}try{r()}catch{this._setupFakeWorker()}});const r=()=>{const o=new Uint8Array;s.send("test",o,[o.buffer])};r();return}catch{Xu("The worker has been disabled.")}this._setupFakeWorker()}_setupFakeWorker(){l(Et,ho)||(tt("Setting up fake worker."),m(Et,ho,!0)),Et._setupFakeWorkerGlobal.then(t=>{if(this.destroyed){this._readyCapability.reject(new Error("Worker was destroyed"));return}const e=new yS;this._port=e;const s=`fake${Ge(Et,vd)._++}`,i=new Wh(s+"_worker",s,e);t.setup(i,e),this._messageHandler=new Wh(s,s+"_worker",e),w(this,La,Hd).call(this)}).catch(t=>{this._readyCapability.reject(new Error(`Setting up fake worker failed: "${t.message}".`))})}destroy(){var t,e,s;this.destroyed=!0,(t=this._webWorker)==null||t.terminate(),this._webWorker=null,(e=l(Et,lo))==null||e.delete(this._port),this._port=null,(s=this._messageHandler)==null||s.destroy(),this._messageHandler=null}static fromPort(t){var s;if(!(t!=null&&t.port))throw new Error("PDFWorker.fromPort - invalid method signature.");const e=(s=l(this,lo))==null?void 0:s.get(t.port);if(e){if(e._pendingDestroy)throw new Error("PDFWorker.fromPort - the worker is being destroyed.\nPlease remember to await `PDFDocumentLoadingTask.destroy()`-calls.");return e}return new Et(t)}static get workerSrc(){if(Vi.workerSrc)return Vi.workerSrc;throw new Error('No "GlobalWorkerOptions.workerSrc" specified.')}static get _setupFakeWorkerGlobal(){return st(this,"_setupFakeWorkerGlobal",(async()=>l(this,Fa,Gd)?l(this,Fa,Gd):(await import(this.workerSrc)).WorkerMessageHandler)())}};vd=new WeakMap,ho=new WeakMap,lo=new WeakMap,La=new WeakSet,Hd=function(){this._readyCapability.resolve(),this._messageHandler.send("configure",{verbosity:this.verbosity})},Fa=new WeakSet,Gd=function(){var t;try{return((t=globalThis.pdfjsWorker)==null?void 0:t.WorkerMessageHandler)||null}catch{return null}},y(Et,Fa),y(Et,vd,0),y(Et,ho,!1),y(Et,lo),ye&&(m(Et,ho,!0),Vi.workerSrc||(Vi.workerSrc="./pdf.worker.mjs")),Et._isSameOrigin=(t,e)=>{let s;try{if(s=new URL(t),!s.origin||s.origin==="null")return!1}catch{return!1}const i=new URL(e,s);return s.origin===i.origin},Et._createCDNWrapper=t=>{const e=`await import("${t}");`;return URL.createObjectURL(new Blob([e],{type:"text/javascript"}))};let aa=Et;class vS{constructor(t,e,s,i,n){y(this,co);y(this,an,new Map);y(this,_i,new Map);y(this,Ia,new Map);y(this,Na,new Map);y(this,hn,null);this.messageHandler=t,this.loadingTask=e,this.commonObjs=new kb,this.fontLoader=new yx({ownerDocument:i.ownerDocument,styleElement:i.styleElement}),this.loadingParams=i.loadingParams,this._params=i,this.canvasFactory=n.canvasFactory,this.filterFactory=n.filterFactory,this.cMapReaderFactory=n.cMapReaderFactory,this.standardFontDataFactory=n.standardFontDataFactory,this.destroyed=!1,this.destroyCapability=null,this._networkStream=s,this._fullReader=null,this._lastProgress=null,this.downloadInfoCapability=Promise.withResolvers(),this.setupMessageHandler()}get annotationStorage(){return st(this,"annotationStorage",new xg)}getRenderingIntent(t,e=Dn.ENABLE,s=null,i=!1,n=!1){let r=ts.DISPLAY,o=wg;switch(t){case"any":r=ts.ANY;break;case"display":break;case"print":r=ts.PRINT;break;default:tt(`getRenderingIntent - invalid intent: ${t}`)}const h=r&ts.PRINT&&s instanceof tb?s:this.annotationStorage;switch(e){case Dn.DISABLE:r+=ts.ANNOTATIONS_DISABLE;break;case Dn.ENABLE:break;case Dn.ENABLE_FORMS:r+=ts.ANNOTATIONS_FORMS;break;case Dn.ENABLE_STORAGE:r+=ts.ANNOTATIONS_STORAGE,o=h.serializable;break;default:tt(`getRenderingIntent - invalid annotationMode: ${e}`)}i&&(r+=ts.IS_EDITING),n&&(r+=ts.OPLIST);const{ids:c,hash:u}=h.modifiedIds,d=[r,o.hash,u];return{renderingIntent:r,cacheKey:d.join("_"),annotationStorageSerializable:o,modifiedIds:c}}destroy(){var s;if(this.destroyCapability)return this.destroyCapability.promise;this.destroyed=!0,this.destroyCapability=Promise.withResolvers(),(s=l(this,hn))==null||s.reject(new Error("Worker was destroyed during onPassword callback"));const t=[];for(const i of l(this,_i).values())t.push(i._destroy());l(this,_i).clear(),l(this,Ia).clear(),l(this,Na).clear(),this.hasOwnProperty("annotationStorage")&&this.annotationStorage.resetModified();const e=this.messageHandler.sendWithPromise("Terminate",null);return t.push(e),Promise.all(t).then(()=>{var i,n;this.commonObjs.clear(),this.fontLoader.clear(),l(this,an).clear(),this.filterFactory.destroy(),Yh.cleanup(),(i=this._networkStream)==null||i.cancelAllRequests(new Rn("Worker was terminated.")),(n=this.messageHandler)==null||n.destroy(),this.messageHandler=null,this.destroyCapability.resolve()},this.destroyCapability.reject),this.destroyCapability.promise}setupMessageHandler(){const{messageHandler:t,loadingTask:e}=this;t.on("GetReader",(s,i)=>{Xt(this._networkStream,"GetReader - no `IPDFStream` instance available."),this._fullReader=this._networkStream.getFullReader(),this._fullReader.onProgress=n=>{this._lastProgress={loaded:n.loaded,total:n.total}},i.onPull=()=>{this._fullReader.read().then(function({value:n,done:r}){if(r){i.close();return}Xt(n instanceof ArrayBuffer,"GetReader - expected an ArrayBuffer."),i.enqueue(new Uint8Array(n),1,[n])}).catch(n=>{i.error(n)})},i.onCancel=n=>{this._fullReader.cancel(n),i.ready.catch(r=>{if(!this.destroyed)throw r})}}),t.on("ReaderHeadersReady",async s=>{var o;await this._fullReader.headersReady;const{isStreamingSupported:i,isRangeSupported:n,contentLength:r}=this._fullReader;return(!i||!n)&&(this._lastProgress&&((o=e.onProgress)==null||o.call(e,this._lastProgress)),this._fullReader.onProgress=h=>{var c;(c=e.onProgress)==null||c.call(e,{loaded:h.loaded,total:h.total})}),{isStreamingSupported:i,isRangeSupported:n,contentLength:r}}),t.on("GetRangeReader",(s,i)=>{Xt(this._networkStream,"GetRangeReader - no `IPDFStream` instance available.");const n=this._networkStream.getRangeReader(s.begin,s.end);if(!n){i.close();return}i.onPull=()=>{n.read().then(function({value:r,done:o}){if(o){i.close();return}Xt(r instanceof ArrayBuffer,"GetRangeReader - expected an ArrayBuffer."),i.enqueue(new Uint8Array(r),1,[r])}).catch(r=>{i.error(r)})},i.onCancel=r=>{n.cancel(r),i.ready.catch(o=>{if(!this.destroyed)throw o})}}),t.on("GetDoc",({pdfInfo:s})=>{this._numPages=s.numPages,this._htmlForXfa=s.htmlForXfa,delete s.htmlForXfa,e._capability.resolve(new mS(s,this))}),t.on("DocException",s=>{e._capability.reject(We(s))}),t.on("PasswordRequest",s=>{m(this,hn,Promise.withResolvers());try{if(!e.onPassword)throw We(s);const i=n=>{n instanceof Error?l(this,hn).reject(n):l(this,hn).resolve({password:n})};e.onPassword(i,s.code)}catch(i){l(this,hn).reject(i)}return l(this,hn).promise}),t.on("DataLoaded",s=>{var i;(i=e.onProgress)==null||i.call(e,{loaded:s.length,total:s.length}),this.downloadInfoCapability.resolve(s)}),t.on("StartRenderPage",s=>{if(this.destroyed)return;l(this,_i).get(s.pageIndex)._startRenderPage(s.transparency,s.cacheKey)}),t.on("commonobj",([s,i,n])=>{var r;if(this.destroyed||this.commonObjs.has(s))return null;switch(i){case"Font":const{disableFontFace:o,fontExtraProperties:h,pdfBug:c}=this._params;if("error"in n){const g=n.error;tt(`Error during font loading: ${g}`),this.commonObjs.resolve(s,g);break}const u=c&&((r=globalThis.FontInspector)!=null&&r.enabled)?(g,p)=>globalThis.FontInspector.fontAdded(g,p):null,d=new vx(n,{disableFontFace:o,fontExtraProperties:h,inspectFont:u});this.fontLoader.bind(d).catch(()=>t.sendWithPromise("FontFallback",{id:s})).finally(()=>{!h&&d.data&&(d.data=null),this.commonObjs.resolve(s,d)});break;case"CopyLocalImage":const{imageRef:f}=n;Xt(f,"The imageRef must be defined.");for(const g of l(this,_i).values())for(const[,p]of g.objs)if((p==null?void 0:p.ref)===f)return p.dataLen?(this.commonObjs.resolve(s,structuredClone(p)),p.dataLen):null;break;case"FontPath":case"Image":case"Pattern":this.commonObjs.resolve(s,n);break;default:throw new Error(`Got unknown common object type ${i}`)}return null}),t.on("obj",([s,i,n,r])=>{var h;if(this.destroyed)return;const o=l(this,_i).get(i);if(!o.objs.has(s)){if(o._intentStates.size===0){(h=r==null?void 0:r.bitmap)==null||h.close();return}switch(n){case"Image":o.objs.resolve(s,r),(r==null?void 0:r.dataLen)>$w&&(o._maybeCleanupAfterRender=!0);break;case"Pattern":o.objs.resolve(s,r);break;default:throw new Error(`Got unknown object type ${n}`)}}}),t.on("DocProgress",s=>{var i;this.destroyed||(i=e.onProgress)==null||i.call(e,{loaded:s.loaded,total:s.total})}),t.on("FetchBuiltInCMap",async s=>{if(this.destroyed)throw new Error("Worker was destroyed.");if(!this.cMapReaderFactory)throw new Error("CMapReaderFactory not initialized, see the `useWorkerFetch` parameter.");return this.cMapReaderFactory.fetch(s)}),t.on("FetchStandardFontData",async s=>{if(this.destroyed)throw new Error("Worker was destroyed.");if(!this.standardFontDataFactory)throw new Error("StandardFontDataFactory not initialized, see the `useWorkerFetch` parameter.");return this.standardFontDataFactory.fetch(s)})}getData(){return this.messageHandler.sendWithPromise("GetData",null)}saveDocument(){var s;this.annotationStorage.size<=0&&tt("saveDocument called while `annotationStorage` is empty, please use the getData-method instead.");const{map:t,transfer:e}=this.annotationStorage.serializable;return this.messageHandler.sendWithPromise("SaveDocument",{isPureXfa:!!this._htmlForXfa,numPages:this._numPages,annotationStorage:t,filename:((s=this._fullReader)==null?void 0:s.filename)??null},e).finally(()=>{this.annotationStorage.resetModified()})}getPage(t){if(!Number.isInteger(t)||t<=0||t>this._numPages)return Promise.reject(new Error("Invalid page request."));const e=t-1,s=l(this,Ia).get(e);if(s)return s;const i=this.messageHandler.sendWithPromise("GetPage",{pageIndex:e}).then(n=>{if(this.destroyed)throw new Error("Transport destroyed");n.refStr&&l(this,Na).set(n.refStr,t);const r=new bS(e,n,this,this._params.pdfBug);return l(this,_i).set(e,r),r});return l(this,Ia).set(e,i),i}getPageIndex(t){return Tb(t)?this.messageHandler.sendWithPromise("GetPageIndex",{num:t.num,gen:t.gen}):Promise.reject(new Error("Invalid pageIndex request."))}getAnnotations(t,e){return this.messageHandler.sendWithPromise("GetAnnotations",{pageIndex:t,intent:e})}getFieldObjects(){return w(this,co,Oc).call(this,"GetFieldObjects")}hasJSActions(){return w(this,co,Oc).call(this,"HasJSActions")}getCalculationOrderIds(){return this.messageHandler.sendWithPromise("GetCalculationOrderIds",null)}getDestinations(){return this.messageHandler.sendWithPromise("GetDestinations",null)}getDestination(t){return typeof t!="string"?Promise.reject(new Error("Invalid destination request.")):this.messageHandler.sendWithPromise("GetDestination",{id:t})}getPageLabels(){return this.messageHandler.sendWithPromise("GetPageLabels",null)}getPageLayout(){return this.messageHandler.sendWithPromise("GetPageLayout",null)}getPageMode(){return this.messageHandler.sendWithPromise("GetPageMode",null)}getViewerPreferences(){return this.messageHandler.sendWithPromise("GetViewerPreferences",null)}getOpenAction(){return this.messageHandler.sendWithPromise("GetOpenAction",null)}getAttachments(){return this.messageHandler.sendWithPromise("GetAttachments",null)}getDocJSActions(){return w(this,co,Oc).call(this,"GetDocJSActions")}getPageJSActions(t){return this.messageHandler.sendWithPromise("GetPageJSActions",{pageIndex:t})}getStructTree(t){return this.messageHandler.sendWithPromise("GetStructTree",{pageIndex:t})}getOutline(){return this.messageHandler.sendWithPromise("GetOutline",null)}getOptionalContentConfig(t){return w(this,co,Oc).call(this,"GetOptionalContentConfig").then(e=>new Gx(e,t))}getPermissions(){return this.messageHandler.sendWithPromise("GetPermissions",null)}getMetadata(){const t="GetMetadata",e=l(this,an).get(t);if(e)return e;const s=this.messageHandler.sendWithPromise(t,null).then(i=>{var n,r;return{info:i[0],metadata:i[1]?new Bx(i[1]):null,contentDispositionFilename:((n=this._fullReader)==null?void 0:n.filename)??null,contentLength:((r=this._fullReader)==null?void 0:r.contentLength)??null}});return l(this,an).set(t,s),s}getMarkInfo(){return this.messageHandler.sendWithPromise("GetMarkInfo",null)}async startCleanup(t=!1){if(!this.destroyed){await this.messageHandler.sendWithPromise("Cleanup",null);for(const e of l(this,_i).values())if(!e.cleanup())throw new Error(`startCleanup: Page ${e.pageNumber} is currently rendering.`);this.commonObjs.clear(),t||this.fontLoader.clear(),l(this,an).clear(),this.filterFactory.destroy(!0),Yh.cleanup()}}cachedPageNumber(t){if(!Tb(t))return null;const e=t.gen===0?`${t.num}R`:`${t.num}R${t.gen}`;return l(this,Na).get(e)??null}}an=new WeakMap,_i=new WeakMap,Ia=new WeakMap,Na=new WeakMap,hn=new WeakMap,co=new WeakSet,Oc=function(t,e=null){const s=l(this,an).get(t);if(s)return s;const i=this.messageHandler.sendWithPromise(t,e);return l(this,an).set(t,i),i};const qh=Symbol("INITIAL_DATA");class kb{constructor(){y(this,zl);y(this,os,Object.create(null))}get(t,e=null){if(e){const i=w(this,zl,_p).call(this,t);return i.promise.then(()=>e(i.data)),null}const s=l(this,os)[t];if(!s||s.data===qh)throw new Error(`Requesting object that isn't resolved yet ${t}.`);return s.data}has(t){const e=l(this,os)[t];return!!e&&e.data!==qh}delete(t){const e=l(this,os)[t];return!e||e.data===qh?!1:(delete l(this,os)[t],!0)}resolve(t,e=null){const s=w(this,zl,_p).call(this,t);s.data=e,s.resolve()}clear(){var t;for(const e in l(this,os)){const{data:s}=l(this,os)[e];(t=s==null?void 0:s.bitmap)==null||t.close()}m(this,os,Object.create(null))}*[Symbol.iterator](){for(const t in l(this,os)){const{data:e}=l(this,os)[t];e!==qh&&(yield[t,e])}}}os=new WeakMap,zl=new WeakSet,_p=function(t){var e;return(e=l(this,os))[t]||(e[t]={...Promise.withResolvers(),data:qh})};class _S{constructor(t){y(this,tr,null);m(this,tr,t),this.onContinue=null}get promise(){return l(this,tr).capability.promise}cancel(t=0){l(this,tr).cancel(null,t)}get separateAnnots(){const{separateAnnots:t}=l(this,tr).operatorList;if(!t)return!1;const{annotationCanvasMap:e}=l(this,tr);return t.form||t.canvas&&(e==null?void 0:e.size)>0}}tr=new WeakMap;const fo=class fo{constructor({callback:t,params:e,objs:s,commonObjs:i,annotationCanvasMap:n,operatorList:r,pageIndex:o,canvasFactory:h,filterFactory:c,useRequestAnimationFrame:u=!1,pdfBug:d=!1,pageColors:f=null}){y(this,er,null);this.callback=t,this.params=e,this.objs=s,this.commonObjs=i,this.annotationCanvasMap=n,this.operatorListIdx=null,this.operatorList=r,this._pageIndex=o,this.canvasFactory=h,this.filterFactory=c,this._pdfBug=d,this.pageColors=f,this.running=!1,this.graphicsReadyCallback=null,this.graphicsReady=!1,this._useRequestAnimationFrame=u===!0&&typeof window<"u",this.cancelled=!1,this.capability=Promise.withResolvers(),this.task=new _S(this),this._cancelBound=this.cancel.bind(this),this._continueBound=this._continue.bind(this),this._scheduleNextBound=this._scheduleNext.bind(this),this._nextBound=this._next.bind(this),this._canvas=e.canvasContext.canvas}get completed(){return this.capability.promise.catch(function(){})}initializeGraphics({transparency:t=!1,optionalContentConfig:e}){var o,h;if(this.cancelled)return;if(this._canvas){if(l(fo,uo).has(this._canvas))throw new Error("Cannot use the same canvas during multiple render() operations. Use different canvas or ensure previous operations were cancelled or completed.");l(fo,uo).add(this._canvas)}this._pdfBug&&((o=globalThis.StepperManager)!=null&&o.enabled)&&(this.stepper=globalThis.StepperManager.create(this._pageIndex),this.stepper.init(this.operatorList),this.stepper.nextBreakPoint=this.stepper.getNextBreakPoint());const{canvasContext:s,viewport:i,transform:n,background:r}=this.params;this.gfx=new ra(s,this.commonObjs,this.objs,this.canvasFactory,this.filterFactory,{optionalContentConfig:e},this.annotationCanvasMap,this.pageColors),this.gfx.beginDrawing({transform:n,viewport:i,transparency:t,background:r}),this.operatorListIdx=0,this.graphicsReady=!0,(h=this.graphicsReadyCallback)==null||h.call(this)}cancel(t=null,e=0){var s;this.running=!1,this.cancelled=!0,(s=this.gfx)==null||s.endDrawing(),l(this,er)&&(window.cancelAnimationFrame(l(this,er)),m(this,er,null)),l(fo,uo).delete(this._canvas),this.callback(t||new fg(`Rendering cancelled, page ${this._pageIndex+1}`,e))}operatorListChanged(){var t;if(!this.graphicsReady){this.graphicsReadyCallback||(this.graphicsReadyCallback=this._continueBound);return}(t=this.stepper)==null||t.updateOperatorList(this.operatorList),!this.running&&this._continue()}_continue(){this.running=!0,!this.cancelled&&(this.task.onContinue?this.task.onContinue(this._scheduleNextBound):this._scheduleNext())}_scheduleNext(){this._useRequestAnimationFrame?m(this,er,window.requestAnimationFrame(()=>{m(this,er,null),this._nextBound().catch(this._cancelBound)})):Promise.resolve().then(this._nextBound).catch(this._cancelBound)}async _next(){this.cancelled||(this.operatorListIdx=this.gfx.executeOperatorList(this.operatorList,this.operatorListIdx,this._continueBound,this.stepper),this.operatorListIdx===this.operatorList.argsArray.length&&(this.running=!1,this.operatorList.lastChunk&&(this.gfx.endDrawing(),l(fo,uo).delete(this._canvas),this.callback())))}};er=new WeakMap,uo=new WeakMap,y(fo,uo,new WeakSet);let Pg=fo;const wS="4.10.38",xS="f9bea397f";function Mb(a){return Math.floor(Math.max(0,Math.min(1,a))*255).toString(16).padStart(2,"0")}function Kh(a){return Math.max(0,Math.min(255,255*a))}class Pb{static CMYK_G([t,e,s,i]){return["G",1-Math.min(1,.3*t+.59*s+.11*e+i)]}static G_CMYK([t]){return["CMYK",0,0,0,1-t]}static G_RGB([t]){return["RGB",t,t,t]}static G_rgb([t]){return t=Kh(t),[t,t,t]}static G_HTML([t]){const e=Mb(t);return`#${e}${e}${e}`}static RGB_G([t,e,s]){return["G",.3*t+.59*e+.11*s]}static RGB_rgb(t){return t.map(Kh)}static RGB_HTML(t){return`#${t.map(Mb).join("")}`}static T_HTML(){return"#00000000"}static T_rgb(){return[null]}static CMYK_RGB([t,e,s,i]){return["RGB",1-Math.min(1,t+i),1-Math.min(1,s+i),1-Math.min(1,e+i)]}static CMYK_rgb([t,e,s,i]){return[Kh(1-Math.min(1,t+i)),Kh(1-Math.min(1,s+i)),Kh(1-Math.min(1,e+i))]}static CMYK_HTML(t){const e=this.CMYK_RGB(t).slice(1);return this.RGB_HTML(e)}static RGB_CMYK([t,e,s]){const i=1-t,n=1-e,r=1-s,o=Math.min(i,n,r);return["CMYK",i,n,r,o]}}class SS{create(t,e,s=!1){if(t<=0||e<=0)throw new Error("Invalid SVG dimensions");const i=this._createSVG("svg:svg");return i.setAttribute("version","1.1"),s||(i.setAttribute("width",`${t}px`),i.setAttribute("height",`${e}px`)),i.setAttribute("preserveAspectRatio","none"),i.setAttribute("viewBox",`0 0 ${t} ${e}`),i}createElement(t){if(typeof t!="string")throw new Error("Invalid SVG element type");return this._createSVG(t)}_createSVG(t){vt("Abstract method `_createSVG` called.")}}class Dg extends SS{_createSVG(t){return document.createElementNS(zi,t)}}class Db{static setupStorage(t,e,s,i,n){const r=i.getValue(e,{value:null});switch(s.name){case"textarea":if(r.value!==null&&(t.textContent=r.value),n==="print")break;t.addEventListener("input",o=>{i.setValue(e,{value:o.target.value})});break;case"input":if(s.attributes.type==="radio"||s.attributes.type==="checkbox"){if(r.value===s.attributes.xfaOn?t.setAttribute("checked",!0):r.value===s.attributes.xfaOff&&t.removeAttribute("checked"),n==="print")break;t.addEventListener("change",o=>{i.setValue(e,{value:o.target.checked?o.target.getAttribute("xfaOn"):o.target.getAttribute("xfaOff")})})}else{if(r.value!==null&&t.setAttribute("value",r.value),n==="print")break;t.addEventListener("input",o=>{i.setValue(e,{value:o.target.value})})}break;case"select":if(r.value!==null){t.setAttribute("value",r.value);for(const o of s.children)o.attributes.value===r.value?o.attributes.selected=!0:o.attributes.hasOwnProperty("selected")&&delete o.attributes.selected}t.addEventListener("input",o=>{const h=o.target.options,c=h.selectedIndex===-1?"":h[h.selectedIndex].value;i.setValue(e,{value:c})});break}}static setAttributes({html:t,element:e,storage:s=null,intent:i,linkService:n}){const{attributes:r}=e,o=t instanceof HTMLAnchorElement;r.type==="radio"&&(r.name=`${r.name}-${i}`);for(const[h,c]of Object.entries(r))if(c!=null)switch(h){case"class":c.length&&t.setAttribute(h,c.join(" "));break;case"dataId":break;case"id":t.setAttribute("data-element-id",c);break;case"style":Object.assign(t.style,c);break;case"textContent":t.textContent=c;break;default:(!o||h!=="href"&&h!=="newWindow")&&t.setAttribute(h,c)}o&&n.addLinkAttributes(t,r.href,r.newWindow),s&&r.dataId&&this.setupStorage(t,r.dataId,e,s)}static render(t){var d,f;const e=t.annotationStorage,s=t.linkService,i=t.xfaHtml,n=t.intent||"display",r=document.createElement(i.name);i.attributes&&this.setAttributes({html:r,element:i,intent:n,linkService:s});const o=n!=="richText",h=t.div;if(h.append(r),t.viewport){const g=`matrix(${t.viewport.transform.join(",")})`;h.style.transform=g}o&&h.setAttribute("class","xfaLayer xfaFont");const c=[];if(i.children.length===0){if(i.value){const g=document.createTextNode(i.value);r.append(g),o&&$h.shouldBuildText(i.name)&&c.push(g)}return{textDivs:c}}const u=[[i,-1,r]];for(;u.length>0;){const[g,p,b]=u.at(-1);if(p+1===g.children.length){u.pop();continue}const _=g.children[++u.at(-1)[1]];if(_===null)continue;const{name:v}=_;if(v==="#text"){const C=document.createTextNode(_.value);c.push(C),b.append(C);continue}const x=(d=_==null?void 0:_.attributes)!=null&&d.xmlns?document.createElementNS(_.attributes.xmlns,v):document.createElement(v);if(b.append(x),_.attributes&&this.setAttributes({html:x,element:_,storage:e,intent:n,linkService:s}),((f=_.children)==null?void 0:f.length)>0)u.push([_,-1,x]);else if(_.value){const C=document.createTextNode(_.value);o&&$h.shouldBuildText(v)&&c.push(C),x.append(C)}}for(const g of h.querySelectorAll(".xfaNonInteractive input, .xfaNonInteractive textarea"))g.setAttribute("readOnly",!0);return{textDivs:c}}static update(t){const e=`matrix(${t.viewport.transform.join(",")})`;t.div.style.transform=e,t.div.hidden=!1}}const Qh=1e3,CS=9,Pr=new WeakSet;function Fn(a){return{width:a[2]-a[0],height:a[3]-a[1]}}class AS{static create(t){switch(t.data.annotationType){case qt.LINK:return new Ob(t);case qt.TEXT:return new TS(t);case qt.WIDGET:switch(t.data.fieldType){case"Tx":return new ES(t);case"Btn":return t.data.radioButton?new Rb(t):t.data.checkBox?new MS(t):new PS(t);case"Ch":return new DS(t);case"Sig":return new kS(t)}return new Dr(t);case qt.POPUP:return new Og(t);case qt.FREETEXT:return new Lb(t);case qt.LINE:return new RS(t);case qt.SQUARE:return new LS(t);case qt.CIRCLE:return new FS(t);case qt.POLYLINE:return new Fb(t);case qt.CARET:return new NS(t);case qt.INK:return new Rg(t);case qt.POLYGON:return new IS(t);case qt.HIGHLIGHT:return new Ib(t);case qt.UNDERLINE:return new jS(t);case qt.SQUIGGLY:return new BS(t);case qt.STRIKEOUT:return new HS(t);case qt.STAMP:return new Nb(t);case qt.FILEATTACHMENT:return new GS(t);default:return new jt(t)}}}const Ug=class Ug{constructor(t,{isRenderable:e=!1,ignoreBorder:s=!1,createQuadrilaterals:i=!1}={}){y(this,Vl);y(this,go,null);y(this,ja,!1);y(this,Ba,null);this.isRenderable=e,this.data=t.data,this.layer=t.layer,this.linkService=t.linkService,this.downloadManager=t.downloadManager,this.imageResourcesPath=t.imageResourcesPath,this.renderForms=t.renderForms,this.svgFactory=t.svgFactory,this.annotationStorage=t.annotationStorage,this.enableScripting=t.enableScripting,this.hasJSActions=t.hasJSActions,this._fieldObjects=t.fieldObjects,this.parent=t.parent,e&&(this.container=this._createContainer(s)),i&&this._createQuadrilaterals()}static _hasPopupData({titleObj:t,contentsObj:e,richText:s}){return!!(t!=null&&t.str||e!=null&&e.str||s!=null&&s.str)}get _isEditable(){return this.data.isEditable}get hasPopupData(){return Ug._hasPopupData(this.data)}updateEdited(t){var s;if(!this.container)return;l(this,go)||m(this,go,{rect:this.data.rect.slice(0)});const{rect:e}=t;e&&w(this,Vl,wp).call(this,e),(s=l(this,Ba))==null||s.popup.updateEdited(t)}resetEdited(){var t;l(this,go)&&(w(this,Vl,wp).call(this,l(this,go).rect),(t=l(this,Ba))==null||t.popup.resetEdited(),m(this,go,null))}_createContainer(t){const{data:e,parent:{page:s,viewport:i}}=this,n=document.createElement("section");n.setAttribute("data-annotation-id",e.id),this instanceof Dr||(n.tabIndex=Qh);const{style:r}=n;if(r.zIndex=this.parent.zIndex++,e.alternativeText&&(n.title=e.alternativeText),e.noRotate&&n.classList.add("norotate"),!e.rect||this instanceof Og){const{rotation:b}=e;return!e.hasOwnCanvas&&b!==0&&this.setRotation(b,n),n}const{width:o,height:h}=Fn(e.rect);if(!t&&e.borderStyle.width>0){r.borderWidth=`${e.borderStyle.width}px`;const b=e.borderStyle.horizontalCornerRadius,_=e.borderStyle.verticalCornerRadius;if(b>0||_>0){const x=`calc(${b}px * var(--scale-factor)) / calc(${_}px * var(--scale-factor))`;r.borderRadius=x}else if(this instanceof Rb){const x=`calc(${o}px * var(--scale-factor)) / calc(${h}px * var(--scale-factor))`;r.borderRadius=x}switch(e.borderStyle.style){case Hh.SOLID:r.borderStyle="solid";break;case Hh.DASHED:r.borderStyle="dashed";break;case Hh.BEVELED:tt("Unimplemented border style: beveled");break;case Hh.INSET:tt("Unimplemented border style: inset");break;case Hh.UNDERLINE:r.borderBottomStyle="solid";break}const v=e.borderColor||null;v?(m(this,ja,!0),r.borderColor=W.makeHexColor(v[0]|0,v[1]|0,v[2]|0)):r.borderWidth=0}const c=W.normalizeRect([e.rect[0],s.view[3]-e.rect[1]+s.view[1],e.rect[2],s.view[3]-e.rect[3]+s.view[1]]),{pageWidth:u,pageHeight:d,pageX:f,pageY:g}=i.rawDims;r.left=`${100*(c[0]-f)/u}%`,r.top=`${100*(c[1]-g)/d}%`;const{rotation:p}=e;return e.hasOwnCanvas||p===0?(r.width=`${100*o/u}%`,r.height=`${100*h/d}%`):this.setRotation(p,n),n}setRotation(t,e=this.container){if(!this.data.rect)return;const{pageWidth:s,pageHeight:i}=this.parent.viewport.rawDims,{width:n,height:r}=Fn(this.data.rect);let o,h;t%180===0?(o=100*n/s,h=100*r/i):(o=100*r/s,h=100*n/i),e.style.width=`${o}%`,e.style.height=`${h}%`,e.setAttribute("data-main-rotation",(360-t)%360)}get _commonActions(){const t=(e,s,i)=>{const n=i.detail[e],r=n[0],o=n.slice(1);i.target.style[s]=Pb[`${r}_HTML`](o),this.annotationStorage.setValue(this.data.id,{[s]:Pb[`${r}_rgb`](o)})};return st(this,"_commonActions",{display:e=>{const{display:s}=e.detail,i=s%2===1;this.container.style.visibility=i?"hidden":"visible",this.annotationStorage.setValue(this.data.id,{noView:i,noPrint:s===1||s===2})},print:e=>{this.annotationStorage.setValue(this.data.id,{noPrint:!e.detail.print})},hidden:e=>{const{hidden:s}=e.detail;this.container.style.visibility=s?"hidden":"visible",this.annotationStorage.setValue(this.data.id,{noPrint:s,noView:s})},focus:e=>{setTimeout(()=>e.target.focus({preventScroll:!1}),0)},userName:e=>{e.target.title=e.detail.userName},readonly:e=>{e.target.disabled=e.detail.readonly},required:e=>{this._setRequired(e.target,e.detail.required)},bgColor:e=>{t("bgColor","backgroundColor",e)},fillColor:e=>{t("fillColor","backgroundColor",e)},fgColor:e=>{t("fgColor","color",e)},textColor:e=>{t("textColor","color",e)},borderColor:e=>{t("borderColor","borderColor",e)},strokeColor:e=>{t("strokeColor","borderColor",e)},rotation:e=>{const s=e.detail.rotation;this.setRotation(s),this.annotationStorage.setValue(this.data.id,{rotation:s})}})}_dispatchEventFromSandbox(t,e){const s=this._commonActions;for(const i of Object.keys(e.detail)){const n=t[i]||s[i];n==null||n(e)}}_setDefaultPropertiesFromJS(t){if(!this.enableScripting)return;const e=this.annotationStorage.getRawValue(this.data.id);if(!e)return;const s=this._commonActions;for(const[i,n]of Object.entries(e)){const r=s[i];if(r){const o={detail:{[i]:n},target:t};r(o),delete e[i]}}}_createQuadrilaterals(){if(!this.container)return;const{quadPoints:t}=this.data;if(!t)return;const[e,s,i,n]=this.data.rect.map(b=>Math.fround(b));if(t.length===8){const[b,_,v,x]=t.subarray(2,6);if(i===b&&n===_&&e===v&&s===x)return}const{style:r}=this.container;let o;if(l(this,ja)){const{borderColor:b,borderWidth:_}=r;r.borderWidth=0,o=["url('data:image/svg+xml;utf8,",'<svg xmlns="http://www.w3.org/2000/svg"',' preserveAspectRatio="none" viewBox="0 0 1 1">',`<g fill="transparent" stroke="${b}" stroke-width="${_}">`],this.container.classList.add("hasBorder")}const h=i-e,c=n-s,{svgFactory:u}=this,d=u.createElement("svg");d.classList.add("quadrilateralsContainer"),d.setAttribute("width",0),d.setAttribute("height",0);const f=u.createElement("defs");d.append(f);const g=u.createElement("clipPath"),p=`clippath_${this.data.id}`;g.setAttribute("id",p),g.setAttribute("clipPathUnits","objectBoundingBox"),f.append(g);for(let b=2,_=t.length;b<_;b+=8){const v=t[b],x=t[b+1],C=t[b+2],S=t[b+3],k=u.createElement("rect"),M=(C-e)/h,E=(n-x)/c,P=(v-C)/h,O=(x-S)/c;k.setAttribute("x",M),k.setAttribute("y",E),k.setAttribute("width",P),k.setAttribute("height",O),g.append(k),o==null||o.push(`<rect vector-effect="non-scaling-stroke" x="${M}" y="${E}" width="${P}" height="${O}"/>`)}l(this,ja)&&(o.push("</g></svg>')"),r.backgroundImage=o.join("")),this.container.append(d),this.container.style.clipPath=`url(#${p})`}_createPopup(){const{data:t}=this,e=m(this,Ba,new Og({data:{color:t.color,titleObj:t.titleObj,modificationDate:t.modificationDate,contentsObj:t.contentsObj,richText:t.richText,parentRect:t.rect,borderStyle:0,id:`popup_${t.id}`,rotation:t.rotation},parent:this.parent,elements:[this]}));this.parent.div.append(e.render())}render(){vt("Abstract method `AnnotationElement.render` called")}_getElementsByName(t,e=null){const s=[];if(this._fieldObjects){const i=this._fieldObjects[t];if(i)for(const{page:n,id:r,exportValues:o}of i){if(n===-1||r===e)continue;const h=typeof o=="string"?o:null,c=document.querySelector(`[data-element-id="${r}"]`);if(c&&!Pr.has(c)){tt(`_getElementsByName - element not allowed: ${r}`);continue}s.push({id:r,exportValue:h,domElement:c})}return s}for(const i of document.getElementsByName(t)){const{exportValue:n}=i,r=i.getAttribute("data-element-id");r!==e&&Pr.has(i)&&s.push({id:r,exportValue:n,domElement:i})}return s}show(){var t;this.container&&(this.container.hidden=!1),(t=this.popup)==null||t.maybeShow()}hide(){var t;this.container&&(this.container.hidden=!0),(t=this.popup)==null||t.forceHide()}getElementsToTriggerPopup(){return this.container}addHighlightArea(){const t=this.getElementsToTriggerPopup();if(Array.isArray(t))for(const e of t)e.classList.add("highlightArea");else t.classList.add("highlightArea")}_editOnDoubleClick(){if(!this._isEditable)return;const{annotationEditorType:t,data:{id:e}}=this;this.container.addEventListener("dblclick",()=>{var s;(s=this.linkService.eventBus)==null||s.dispatch("switchannotationeditormode",{source:this,mode:t,editId:e})})}};go=new WeakMap,ja=new WeakMap,Ba=new WeakMap,Vl=new WeakSet,wp=function(t){const{container:{style:e},data:{rect:s,rotation:i},parent:{viewport:{rawDims:{pageWidth:n,pageHeight:r,pageX:o,pageY:h}}}}=this;s==null||s.splice(0,4,...t);const{width:c,height:u}=Fn(t);e.left=`${100*(t[0]-o)/n}%`,e.top=`${100*(r-t[3]+h)/r}%`,i===0?(e.width=`${100*c/n}%`,e.height=`${100*u/r}%`):this.setRotation(i)};let jt=Ug;class Ob extends jt{constructor(e,s=null){super(e,{isRenderable:!0,ignoreBorder:!!(s!=null&&s.ignoreBorder),createQuadrilaterals:!0});y(this,as);this.isTooltipOnly=e.data.isTooltipOnly}render(){const{data:e,linkService:s}=this,i=document.createElement("a");i.setAttribute("data-element-id",e.id);let n=!1;return e.url?(s.addLinkAttributes(i,e.url,e.newWindow),n=!0):e.action?(this._bindNamedAction(i,e.action),n=!0):e.attachment?(w(this,as,Ry).call(this,i,e.attachment,e.attachmentDest),n=!0):e.setOCGState?(w(this,as,Ly).call(this,i,e.setOCGState),n=!0):e.dest?(this._bindLink(i,e.dest),n=!0):(e.actions&&(e.actions.Action||e.actions["Mouse Up"]||e.actions["Mouse Down"])&&this.enableScripting&&this.hasJSActions&&(this._bindJSAction(i,e),n=!0),e.resetForm?(this._bindResetFormAction(i,e.resetForm),n=!0):this.isTooltipOnly&&!n&&(this._bindLink(i,""),n=!0)),this.container.classList.add("linkAnnotation"),n&&this.container.append(i),this.container}_bindLink(e,s){e.href=this.linkService.getDestinationHash(s),e.onclick=()=>(s&&this.linkService.goToDestination(s),!1),(s||s==="")&&w(this,as,Ho).call(this)}_bindNamedAction(e,s){e.href=this.linkService.getAnchorUrl(""),e.onclick=()=>(this.linkService.executeNamedAction(s),!1),w(this,as,Ho).call(this)}_bindJSAction(e,s){e.href=this.linkService.getAnchorUrl("");const i=new Map([["Action","onclick"],["Mouse Up","onmouseup"],["Mouse Down","onmousedown"]]);for(const n of Object.keys(s.actions)){const r=i.get(n);r&&(e[r]=()=>{var o;return(o=this.linkService.eventBus)==null||o.dispatch("dispatcheventinsandbox",{source:this,detail:{id:s.id,name:n}}),!1})}e.onclick||(e.onclick=()=>!1),w(this,as,Ho).call(this)}_bindResetFormAction(e,s){const i=e.onclick;if(i||(e.href=this.linkService.getAnchorUrl("")),w(this,as,Ho).call(this),!this._fieldObjects){tt('_bindResetFormAction - "resetForm" action not supported, ensure that the `fieldObjects` parameter is provided.'),i||(e.onclick=()=>!1);return}e.onclick=()=>{var d;i==null||i();const{fields:n,refs:r,include:o}=s,h=[];if(n.length!==0||r.length!==0){const f=new Set(r);for(const g of n){const p=this._fieldObjects[g]||[];for(const{id:b}of p)f.add(b)}for(const g of Object.values(this._fieldObjects))for(const p of g)f.has(p.id)===o&&h.push(p)}else for(const f of Object.values(this._fieldObjects))h.push(...f);const c=this.annotationStorage,u=[];for(const f of h){const{id:g}=f;switch(u.push(g),f.type){case"text":{const b=f.defaultValue||"";c.setValue(g,{value:b});break}case"checkbox":case"radiobutton":{const b=f.defaultValue===f.exportValues;c.setValue(g,{value:b});break}case"combobox":case"listbox":{const b=f.defaultValue||"";c.setValue(g,{value:b});break}default:continue}const p=document.querySelector(`[data-element-id="${g}"]`);if(p){if(!Pr.has(p)){tt(`_bindResetFormAction - element not allowed: ${g}`);continue}}else continue;p.dispatchEvent(new Event("resetform"))}return this.enableScripting&&((d=this.linkService.eventBus)==null||d.dispatch("dispatcheventinsandbox",{source:this,detail:{id:"app",ids:u,name:"ResetForm"}})),!1}}}as=new WeakSet,Ho=function(){this.container.setAttribute("data-internal-link","")},Ry=function(e,s,i=null){e.href=this.linkService.getAnchorUrl(""),s.description&&(e.title=s.description),e.onclick=()=>{var n;return(n=this.downloadManager)==null||n.openOrDownloadData(s.content,s.filename,i),!1},w(this,as,Ho).call(this)},Ly=function(e,s){e.href=this.linkService.getAnchorUrl(""),e.onclick=()=>(this.linkService.executeSetOCGState(s),!1),w(this,as,Ho).call(this)};class TS extends jt{constructor(t){super(t,{isRenderable:!0})}render(){this.container.classList.add("textAnnotation");const t=document.createElement("img");return t.src=this.imageResourcesPath+"annotation-"+this.data.name.toLowerCase()+".svg",t.setAttribute("data-l10n-id","pdfjs-text-annotation-type"),t.setAttribute("data-l10n-args",JSON.stringify({type:this.data.name})),!this.data.popupRef&&this.hasPopupData&&this._createPopup(),this.container.append(t),this.container}}class Dr extends jt{render(){return this.container}showElementAndHideCanvas(t){var e;this.data.hasOwnCanvas&&(((e=t.previousSibling)==null?void 0:e.nodeName)==="CANVAS"&&(t.previousSibling.hidden=!0),t.hidden=!1)}_getKeyModifier(t){return Re.platform.isMac?t.metaKey:t.ctrlKey}_setEventListener(t,e,s,i,n){s.includes("mouse")?t.addEventListener(s,r=>{var o;(o=this.linkService.eventBus)==null||o.dispatch("dispatcheventinsandbox",{source:this,detail:{id:this.data.id,name:i,value:n(r),shift:r.shiftKey,modifier:this._getKeyModifier(r)}})}):t.addEventListener(s,r=>{var o;if(s==="blur"){if(!e.focused||!r.relatedTarget)return;e.focused=!1}else if(s==="focus"){if(e.focused)return;e.focused=!0}n&&((o=this.linkService.eventBus)==null||o.dispatch("dispatcheventinsandbox",{source:this,detail:{id:this.data.id,name:i,value:n(r)}}))})}_setEventListeners(t,e,s,i){var n,r,o;for(const[h,c]of s)(c==="Action"||(n=this.data.actions)!=null&&n[c])&&((c==="Focus"||c==="Blur")&&(e||(e={focused:!1})),this._setEventListener(t,e,h,c,i),c==="Focus"&&!((r=this.data.actions)!=null&&r.Blur)?this._setEventListener(t,e,"blur","Blur",null):c==="Blur"&&!((o=this.data.actions)!=null&&o.Focus)&&this._setEventListener(t,e,"focus","Focus",null))}_setBackgroundColor(t){const e=this.data.backgroundColor||null;t.style.backgroundColor=e===null?"transparent":W.makeHexColor(e[0],e[1],e[2])}_setTextStyle(t){const e=["left","center","right"],{fontColor:s}=this.data.defaultAppearanceData,i=this.data.defaultAppearanceData.fontSize||CS,n=t.style;let r;const o=2,h=c=>Math.round(10*c)/10;if(this.data.multiLine){const c=Math.abs(this.data.rect[3]-this.data.rect[1]-o),u=Math.round(c/(og*i))||1,d=c/u;r=Math.min(i,h(d/og))}else{const c=Math.abs(this.data.rect[3]-this.data.rect[1]-o);r=Math.min(i,h(c/og))}n.fontSize=`calc(${r}px * var(--scale-factor))`,n.color=W.makeHexColor(s[0],s[1],s[2]),this.data.textAlignment!==null&&(n.textAlign=e[this.data.textAlignment])}_setRequired(t,e){e?t.setAttribute("required",!0):t.removeAttribute("required"),t.setAttribute("aria-required",e)}}class ES extends Dr{constructor(t){const e=t.renderForms||t.data.hasOwnCanvas||!t.data.hasAppearance&&!!t.data.fieldValue;super(t,{isRenderable:e})}setPropertyOnSiblings(t,e,s,i){const n=this.annotationStorage;for(const r of this._getElementsByName(t.name,t.id))r.domElement&&(r.domElement[e]=s),n.setValue(r.id,{[i]:s})}render(){var i,n;const t=this.annotationStorage,e=this.data.id;this.container.classList.add("textWidgetAnnotation");let s=null;if(this.renderForms){const r=t.getValue(e,{value:this.data.fieldValue});let o=r.value||"";const h=t.getValue(e,{charLimit:this.data.maxLen}).charLimit;h&&o.length>h&&(o=o.slice(0,h));let c=r.formattedValue||((i=this.data.textContent)==null?void 0:i.join(`
|
|
500
|
+
`))||null;c&&this.data.comb&&(c=c.replaceAll(/\s+/g,""));const u={userValue:o,formattedValue:c,lastCommittedValue:null,commitKey:1,focused:!1};this.data.multiLine?(s=document.createElement("textarea"),s.textContent=c??o,this.data.doNotScroll&&(s.style.overflowY="hidden")):(s=document.createElement("input"),s.type="text",s.setAttribute("value",c??o),this.data.doNotScroll&&(s.style.overflowX="hidden")),this.data.hasOwnCanvas&&(s.hidden=!0),Pr.add(s),s.setAttribute("data-element-id",e),s.disabled=this.data.readOnly,s.name=this.data.fieldName,s.tabIndex=Qh,this._setRequired(s,this.data.required),h&&(s.maxLength=h),s.addEventListener("input",f=>{t.setValue(e,{value:f.target.value}),this.setPropertyOnSiblings(s,"value",f.target.value,"value"),u.formattedValue=null}),s.addEventListener("resetform",f=>{const g=this.data.defaultFieldValue??"";s.value=u.userValue=g,u.formattedValue=null});let d=f=>{const{formattedValue:g}=u;g!=null&&(f.target.value=g),f.target.scrollLeft=0};if(this.enableScripting&&this.hasJSActions){s.addEventListener("focus",g=>{var b;if(u.focused)return;const{target:p}=g;u.userValue&&(p.value=u.userValue),u.lastCommittedValue=p.value,u.commitKey=1,(b=this.data.actions)!=null&&b.Focus||(u.focused=!0)}),s.addEventListener("updatefromsandbox",g=>{this.showElementAndHideCanvas(g.target);const p={value(b){u.userValue=b.detail.value??"",t.setValue(e,{value:u.userValue.toString()}),b.target.value=u.userValue},formattedValue(b){const{formattedValue:_}=b.detail;u.formattedValue=_,_!=null&&b.target!==document.activeElement&&(b.target.value=_),t.setValue(e,{formattedValue:_})},selRange(b){b.target.setSelectionRange(...b.detail.selRange)},charLimit:b=>{var C;const{charLimit:_}=b.detail,{target:v}=b;if(_===0){v.removeAttribute("maxLength");return}v.setAttribute("maxLength",_);let x=u.userValue;!x||x.length<=_||(x=x.slice(0,_),v.value=u.userValue=x,t.setValue(e,{value:x}),(C=this.linkService.eventBus)==null||C.dispatch("dispatcheventinsandbox",{source:this,detail:{id:e,name:"Keystroke",value:x,willCommit:!0,commitKey:1,selStart:v.selectionStart,selEnd:v.selectionEnd}}))}};this._dispatchEventFromSandbox(p,g)}),s.addEventListener("keydown",g=>{var _;u.commitKey=1;let p=-1;if(g.key==="Escape"?p=0:g.key==="Enter"&&!this.data.multiLine?p=2:g.key==="Tab"&&(u.commitKey=3),p===-1)return;const{value:b}=g.target;u.lastCommittedValue!==b&&(u.lastCommittedValue=b,u.userValue=b,(_=this.linkService.eventBus)==null||_.dispatch("dispatcheventinsandbox",{source:this,detail:{id:e,name:"Keystroke",value:b,willCommit:!0,commitKey:p,selStart:g.target.selectionStart,selEnd:g.target.selectionEnd}}))});const f=d;d=null,s.addEventListener("blur",g=>{var b,_;if(!u.focused||!g.relatedTarget)return;(b=this.data.actions)!=null&&b.Blur||(u.focused=!1);const{value:p}=g.target;u.userValue=p,u.lastCommittedValue!==p&&((_=this.linkService.eventBus)==null||_.dispatch("dispatcheventinsandbox",{source:this,detail:{id:e,name:"Keystroke",value:p,willCommit:!0,commitKey:u.commitKey,selStart:g.target.selectionStart,selEnd:g.target.selectionEnd}})),f(g)}),(n=this.data.actions)!=null&&n.Keystroke&&s.addEventListener("beforeinput",g=>{var k;u.lastCommittedValue=null;const{data:p,target:b}=g,{value:_,selectionStart:v,selectionEnd:x}=b;let C=v,S=x;switch(g.inputType){case"deleteWordBackward":{const M=_.substring(0,v).match(/\w*[^\w]*$/);M&&(C-=M[0].length);break}case"deleteWordForward":{const M=_.substring(v).match(/^[^\w]*\w*/);M&&(S+=M[0].length);break}case"deleteContentBackward":v===x&&(C-=1);break;case"deleteContentForward":v===x&&(S+=1);break}g.preventDefault(),(k=this.linkService.eventBus)==null||k.dispatch("dispatcheventinsandbox",{source:this,detail:{id:e,name:"Keystroke",value:_,change:p||"",willCommit:!1,selStart:C,selEnd:S}})}),this._setEventListeners(s,u,[["focus","Focus"],["blur","Blur"],["mousedown","Mouse Down"],["mouseenter","Mouse Enter"],["mouseleave","Mouse Exit"],["mouseup","Mouse Up"]],g=>g.target.value)}if(d&&s.addEventListener("blur",d),this.data.comb){const g=(this.data.rect[2]-this.data.rect[0])/h;s.classList.add("comb"),s.style.letterSpacing=`calc(${g}px * var(--scale-factor) - 1ch)`}}else s=document.createElement("div"),s.textContent=this.data.fieldValue,s.style.verticalAlign="middle",s.style.display="table-cell",this.data.hasOwnCanvas&&(s.hidden=!0);return this._setTextStyle(s),this._setBackgroundColor(s),this._setDefaultPropertiesFromJS(s),this.container.append(s),this.container}}class kS extends Dr{constructor(t){super(t,{isRenderable:!!t.data.hasOwnCanvas})}}class MS extends Dr{constructor(t){super(t,{isRenderable:t.renderForms})}render(){const t=this.annotationStorage,e=this.data,s=e.id;let i=t.getValue(s,{value:e.exportValue===e.fieldValue}).value;typeof i=="string"&&(i=i!=="Off",t.setValue(s,{value:i})),this.container.classList.add("buttonWidgetAnnotation","checkBox");const n=document.createElement("input");return Pr.add(n),n.setAttribute("data-element-id",s),n.disabled=e.readOnly,this._setRequired(n,this.data.required),n.type="checkbox",n.name=e.fieldName,i&&n.setAttribute("checked",!0),n.setAttribute("exportValue",e.exportValue),n.tabIndex=Qh,n.addEventListener("change",r=>{const{name:o,checked:h}=r.target;for(const c of this._getElementsByName(o,s)){const u=h&&c.exportValue===e.exportValue;c.domElement&&(c.domElement.checked=u),t.setValue(c.id,{value:u})}t.setValue(s,{value:h})}),n.addEventListener("resetform",r=>{const o=e.defaultFieldValue||"Off";r.target.checked=o===e.exportValue}),this.enableScripting&&this.hasJSActions&&(n.addEventListener("updatefromsandbox",r=>{const o={value(h){h.target.checked=h.detail.value!=="Off",t.setValue(s,{value:h.target.checked})}};this._dispatchEventFromSandbox(o,r)}),this._setEventListeners(n,null,[["change","Validate"],["change","Action"],["focus","Focus"],["blur","Blur"],["mousedown","Mouse Down"],["mouseenter","Mouse Enter"],["mouseleave","Mouse Exit"],["mouseup","Mouse Up"]],r=>r.target.checked)),this._setBackgroundColor(n),this._setDefaultPropertiesFromJS(n),this.container.append(n),this.container}}class Rb extends Dr{constructor(t){super(t,{isRenderable:t.renderForms})}render(){this.container.classList.add("buttonWidgetAnnotation","radioButton");const t=this.annotationStorage,e=this.data,s=e.id;let i=t.getValue(s,{value:e.fieldValue===e.buttonValue}).value;if(typeof i=="string"&&(i=i!==e.buttonValue,t.setValue(s,{value:i})),i)for(const r of this._getElementsByName(e.fieldName,s))t.setValue(r.id,{value:!1});const n=document.createElement("input");if(Pr.add(n),n.setAttribute("data-element-id",s),n.disabled=e.readOnly,this._setRequired(n,this.data.required),n.type="radio",n.name=e.fieldName,i&&n.setAttribute("checked",!0),n.tabIndex=Qh,n.addEventListener("change",r=>{const{name:o,checked:h}=r.target;for(const c of this._getElementsByName(o,s))t.setValue(c.id,{value:!1});t.setValue(s,{value:h})}),n.addEventListener("resetform",r=>{const o=e.defaultFieldValue;r.target.checked=o!=null&&o===e.buttonValue}),this.enableScripting&&this.hasJSActions){const r=e.buttonValue;n.addEventListener("updatefromsandbox",o=>{const h={value:c=>{const u=r===c.detail.value;for(const d of this._getElementsByName(c.target.name)){const f=u&&d.id===s;d.domElement&&(d.domElement.checked=f),t.setValue(d.id,{value:f})}}};this._dispatchEventFromSandbox(h,o)}),this._setEventListeners(n,null,[["change","Validate"],["change","Action"],["focus","Focus"],["blur","Blur"],["mousedown","Mouse Down"],["mouseenter","Mouse Enter"],["mouseleave","Mouse Exit"],["mouseup","Mouse Up"]],o=>o.target.checked)}return this._setBackgroundColor(n),this._setDefaultPropertiesFromJS(n),this.container.append(n),this.container}}class PS extends Ob{constructor(t){super(t,{ignoreBorder:t.data.hasAppearance})}render(){const t=super.render();t.classList.add("buttonWidgetAnnotation","pushButton");const e=t.lastChild;return this.enableScripting&&this.hasJSActions&&e&&(this._setDefaultPropertiesFromJS(e),e.addEventListener("updatefromsandbox",s=>{this._dispatchEventFromSandbox({},s)})),t}}class DS extends Dr{constructor(t){super(t,{isRenderable:t.renderForms})}render(){this.container.classList.add("choiceWidgetAnnotation");const t=this.annotationStorage,e=this.data.id,s=t.getValue(e,{value:this.data.fieldValue}),i=document.createElement("select");Pr.add(i),i.setAttribute("data-element-id",e),i.disabled=this.data.readOnly,this._setRequired(i,this.data.required),i.name=this.data.fieldName,i.tabIndex=Qh;let n=this.data.combo&&this.data.options.length>0;this.data.combo||(i.size=this.data.options.length,this.data.multiSelect&&(i.multiple=!0)),i.addEventListener("resetform",u=>{const d=this.data.defaultFieldValue;for(const f of i.options)f.selected=f.value===d});for(const u of this.data.options){const d=document.createElement("option");d.textContent=u.displayValue,d.value=u.exportValue,s.value.includes(u.exportValue)&&(d.setAttribute("selected",!0),n=!1),i.append(d)}let r=null;if(n){const u=document.createElement("option");u.value=" ",u.setAttribute("hidden",!0),u.setAttribute("selected",!0),i.prepend(u),r=()=>{u.remove(),i.removeEventListener("input",r),r=null},i.addEventListener("input",r)}const o=u=>{const d=u?"value":"textContent",{options:f,multiple:g}=i;return g?Array.prototype.filter.call(f,p=>p.selected).map(p=>p[d]):f.selectedIndex===-1?null:f[f.selectedIndex][d]};let h=o(!1);const c=u=>{const d=u.target.options;return Array.prototype.map.call(d,f=>({displayValue:f.textContent,exportValue:f.value}))};return this.enableScripting&&this.hasJSActions?(i.addEventListener("updatefromsandbox",u=>{const d={value(f){r==null||r();const g=f.detail.value,p=new Set(Array.isArray(g)?g:[g]);for(const b of i.options)b.selected=p.has(b.value);t.setValue(e,{value:o(!0)}),h=o(!1)},multipleSelection(f){i.multiple=!0},remove(f){const g=i.options,p=f.detail.remove;g[p].selected=!1,i.remove(p),g.length>0&&Array.prototype.findIndex.call(g,_=>_.selected)===-1&&(g[0].selected=!0),t.setValue(e,{value:o(!0),items:c(f)}),h=o(!1)},clear(f){for(;i.length!==0;)i.remove(0);t.setValue(e,{value:null,items:[]}),h=o(!1)},insert(f){const{index:g,displayValue:p,exportValue:b}=f.detail.insert,_=i.children[g],v=document.createElement("option");v.textContent=p,v.value=b,_?_.before(v):i.append(v),t.setValue(e,{value:o(!0),items:c(f)}),h=o(!1)},items(f){const{items:g}=f.detail;for(;i.length!==0;)i.remove(0);for(const p of g){const{displayValue:b,exportValue:_}=p,v=document.createElement("option");v.textContent=b,v.value=_,i.append(v)}i.options.length>0&&(i.options[0].selected=!0),t.setValue(e,{value:o(!0),items:c(f)}),h=o(!1)},indices(f){const g=new Set(f.detail.indices);for(const p of f.target.options)p.selected=g.has(p.index);t.setValue(e,{value:o(!0)}),h=o(!1)},editable(f){f.target.disabled=!f.detail.editable}};this._dispatchEventFromSandbox(d,u)}),i.addEventListener("input",u=>{var g;const d=o(!0),f=o(!1);t.setValue(e,{value:d}),u.preventDefault(),(g=this.linkService.eventBus)==null||g.dispatch("dispatcheventinsandbox",{source:this,detail:{id:e,name:"Keystroke",value:h,change:f,changeEx:d,willCommit:!1,commitKey:1,keyDown:!1}})}),this._setEventListeners(i,null,[["focus","Focus"],["blur","Blur"],["mousedown","Mouse Down"],["mouseenter","Mouse Enter"],["mouseleave","Mouse Exit"],["mouseup","Mouse Up"],["input","Action"],["input","Validate"]],u=>u.target.value)):i.addEventListener("input",function(u){t.setValue(e,{value:o(!0)})}),this.data.combo&&this._setTextStyle(i),this._setBackgroundColor(i),this._setDefaultPropertiesFromJS(i),this.container.append(i),this.container}}class Og extends jt{constructor(t){const{data:e,elements:s}=t;super(t,{isRenderable:jt._hasPopupData(e)}),this.elements=s,this.popup=null}render(){this.container.classList.add("popupAnnotation");const t=this.popup=new OS({container:this.container,color:this.data.color,titleObj:this.data.titleObj,modificationDate:this.data.modificationDate,contentsObj:this.data.contentsObj,richText:this.data.richText,rect:this.data.rect,parentRect:this.data.parentRect||null,parent:this.parent,elements:this.elements,open:this.data.open}),e=[];for(const s of this.elements)s.popup=t,s.container.ariaHasPopup="dialog",e.push(s.data.id),s.addHighlightArea();return this.container.setAttribute("aria-controls",e.map(s=>`${dg}${s}`).join(",")),this.container}}class OS{constructor({container:t,color:e,elements:s,titleObj:i,modificationDate:n,contentsObj:r,richText:o,parent:h,rect:c,parentRect:u,open:d}){y(this,bt);y(this,Ha,w(this,bt,Ny).bind(this));y(this,_d,w(this,bt,Sp).bind(this));y(this,wd,w(this,bt,Xd).bind(this));y(this,Ga,w(this,bt,Vd).bind(this));y(this,po,null);y(this,Lt,null);y(this,ln,null);y(this,za,null);y(this,Xl,null);y(this,Wl,null);y(this,Va,null);y(this,cn,!1);y(this,$s,null);y(this,un,null);y(this,Ul,null);y(this,dn,null);y(this,Yl,null);y(this,mo,null);y(this,bo,!1);var f;m(this,Lt,t),m(this,Yl,i),m(this,ln,r),m(this,dn,o),m(this,Wl,h),m(this,po,e),m(this,Ul,c),m(this,Va,u),m(this,Xl,s),m(this,za,pg.toDateObject(n)),this.trigger=s.flatMap(g=>g.getElementsToTriggerPopup());for(const g of this.trigger)g.addEventListener("click",l(this,Ga)),g.addEventListener("mouseenter",l(this,wd)),g.addEventListener("mouseleave",l(this,_d)),g.classList.add("popupTriggerArea");for(const g of s)(f=g.container)==null||f.addEventListener("keydown",l(this,Ha));l(this,Lt).hidden=!0,d&&w(this,bt,Vd).call(this)}render(){if(l(this,$s))return;const t=m(this,$s,document.createElement("div"));if(t.className="popup",l(this,po)){const n=t.style.outlineColor=W.makeHexColor(...l(this,po));CSS.supports("background-color","color-mix(in srgb, red 30%, white)")?t.style.backgroundColor=`color-mix(in srgb, ${n} 30%, white)`:t.style.backgroundColor=W.makeHexColor(...l(this,po).map(o=>Math.floor(.7*(255-o)+o)))}const e=document.createElement("span");e.className="header";const s=document.createElement("h1");if(e.append(s),{dir:s.dir,str:s.textContent}=l(this,Yl),t.append(e),l(this,za)){const n=document.createElement("span");n.classList.add("popupDate"),n.setAttribute("data-l10n-id","pdfjs-annotation-date-time-string"),n.setAttribute("data-l10n-args",JSON.stringify({dateObj:l(this,za).valueOf()})),e.append(n)}const i=l(this,bt,zd);if(i)Db.render({xfaHtml:i,intent:"richText",div:t}),t.lastChild.classList.add("richText","popupContent");else{const n=this._formatContents(l(this,ln));t.append(n)}l(this,Lt).append(t)}_formatContents({str:t,dir:e}){const s=document.createElement("p");s.classList.add("popupContent"),s.dir=e;const i=t.split(/(?:\r\n?|\n)/);for(let n=0,r=i.length;n<r;++n){const o=i[n];s.append(document.createTextNode(o)),n<r-1&&s.append(document.createElement("br"))}return s}updateEdited({rect:t,popupContent:e}){var s;l(this,mo)||m(this,mo,{contentsObj:l(this,ln),richText:l(this,dn)}),t&&m(this,un,null),e&&(m(this,dn,w(this,bt,Iy).call(this,e)),m(this,ln,null)),(s=l(this,$s))==null||s.remove(),m(this,$s,null)}resetEdited(){var t;l(this,mo)&&({contentsObj:Ge(this,ln)._,richText:Ge(this,dn)._}=l(this,mo),m(this,mo,null),(t=l(this,$s))==null||t.remove(),m(this,$s,null),m(this,un,null))}forceHide(){m(this,bo,this.isVisible),l(this,bo)&&(l(this,Lt).hidden=!0)}maybeShow(){l(this,bo)&&(l(this,$s)||w(this,bt,Xd).call(this),m(this,bo,!1),l(this,Lt).hidden=!1)}get isVisible(){return l(this,Lt).hidden===!1}}Ha=new WeakMap,_d=new WeakMap,wd=new WeakMap,Ga=new WeakMap,po=new WeakMap,Lt=new WeakMap,ln=new WeakMap,za=new WeakMap,Xl=new WeakMap,Wl=new WeakMap,Va=new WeakMap,cn=new WeakMap,$s=new WeakMap,un=new WeakMap,Ul=new WeakMap,dn=new WeakMap,Yl=new WeakMap,mo=new WeakMap,bo=new WeakMap,bt=new WeakSet,zd=function(){const t=l(this,dn),e=l(this,ln);return t!=null&&t.str&&(!(e!=null&&e.str)||e.str===t.str)&&l(this,dn).html||null},xp=function(){var t,e,s;return((s=(e=(t=l(this,bt,zd))==null?void 0:t.attributes)==null?void 0:e.style)==null?void 0:s.fontSize)||0},Fy=function(){var t,e,s;return((s=(e=(t=l(this,bt,zd))==null?void 0:t.attributes)==null?void 0:e.style)==null?void 0:s.color)||null},Iy=function(t){const e=[],s={str:t,html:{name:"div",attributes:{dir:"auto"},children:[{name:"p",children:e}]}},i={style:{color:l(this,bt,Fy),fontSize:l(this,bt,xp)?`calc(${l(this,bt,xp)}px * var(--scale-factor))`:""}};for(const n of t.split(`
|
|
501
|
+
`))e.push({name:"span",value:n,attributes:i});return s},Ny=function(t){t.altKey||t.shiftKey||t.ctrlKey||t.metaKey||(t.key==="Enter"||t.key==="Escape"&&l(this,cn))&&w(this,bt,Vd).call(this)},jy=function(){if(l(this,un)!==null)return;const{page:{view:t},viewport:{rawDims:{pageWidth:e,pageHeight:s,pageX:i,pageY:n}}}=l(this,Wl);let r=!!l(this,Va),o=r?l(this,Va):l(this,Ul);for(const p of l(this,Xl))if(!o||W.intersect(p.data.rect,o)!==null){o=p.data.rect,r=!0;break}const h=W.normalizeRect([o[0],t[3]-o[1]+t[1],o[2],t[3]-o[3]+t[1]]),u=r?o[2]-o[0]+5:0,d=h[0]+u,f=h[1];m(this,un,[100*(d-i)/e,100*(f-n)/s]);const{style:g}=l(this,Lt);g.left=`${l(this,un)[0]}%`,g.top=`${l(this,un)[1]}%`},Vd=function(){m(this,cn,!l(this,cn)),l(this,cn)?(w(this,bt,Xd).call(this),l(this,Lt).addEventListener("click",l(this,Ga)),l(this,Lt).addEventListener("keydown",l(this,Ha))):(w(this,bt,Sp).call(this),l(this,Lt).removeEventListener("click",l(this,Ga)),l(this,Lt).removeEventListener("keydown",l(this,Ha)))},Xd=function(){l(this,$s)||this.render(),this.isVisible?l(this,cn)&&l(this,Lt).classList.add("focused"):(w(this,bt,jy).call(this),l(this,Lt).hidden=!1,l(this,Lt).style.zIndex=parseInt(l(this,Lt).style.zIndex)+1e3)},Sp=function(){l(this,Lt).classList.remove("focused"),!(l(this,cn)||!this.isVisible)&&(l(this,Lt).hidden=!0,l(this,Lt).style.zIndex=parseInt(l(this,Lt).style.zIndex)-1e3)};class Lb extends jt{constructor(t){super(t,{isRenderable:!0,ignoreBorder:!0}),this.textContent=t.data.textContent,this.textPosition=t.data.textPosition,this.annotationEditorType=Z.FREETEXT}render(){if(this.container.classList.add("freeTextAnnotation"),this.textContent){const t=document.createElement("div");t.classList.add("annotationTextContent"),t.setAttribute("role","comment");for(const e of this.textContent){const s=document.createElement("span");s.textContent=e,t.append(s)}this.container.append(t)}return!this.data.popupRef&&this.hasPopupData&&this._createPopup(),this._editOnDoubleClick(),this.container}}class RS extends jt{constructor(e){super(e,{isRenderable:!0,ignoreBorder:!0});y(this,$l,null)}render(){this.container.classList.add("lineAnnotation");const e=this.data,{width:s,height:i}=Fn(e.rect),n=this.svgFactory.create(s,i,!0),r=m(this,$l,this.svgFactory.createElement("svg:line"));return r.setAttribute("x1",e.rect[2]-e.lineCoordinates[0]),r.setAttribute("y1",e.rect[3]-e.lineCoordinates[1]),r.setAttribute("x2",e.rect[2]-e.lineCoordinates[2]),r.setAttribute("y2",e.rect[3]-e.lineCoordinates[3]),r.setAttribute("stroke-width",e.borderStyle.width||1),r.setAttribute("stroke","transparent"),r.setAttribute("fill","transparent"),n.append(r),this.container.append(n),!e.popupRef&&this.hasPopupData&&this._createPopup(),this.container}getElementsToTriggerPopup(){return l(this,$l)}addHighlightArea(){this.container.classList.add("highlightArea")}}$l=new WeakMap;class LS extends jt{constructor(e){super(e,{isRenderable:!0,ignoreBorder:!0});y(this,ql,null)}render(){this.container.classList.add("squareAnnotation");const e=this.data,{width:s,height:i}=Fn(e.rect),n=this.svgFactory.create(s,i,!0),r=e.borderStyle.width,o=m(this,ql,this.svgFactory.createElement("svg:rect"));return o.setAttribute("x",r/2),o.setAttribute("y",r/2),o.setAttribute("width",s-r),o.setAttribute("height",i-r),o.setAttribute("stroke-width",r||1),o.setAttribute("stroke","transparent"),o.setAttribute("fill","transparent"),n.append(o),this.container.append(n),!e.popupRef&&this.hasPopupData&&this._createPopup(),this.container}getElementsToTriggerPopup(){return l(this,ql)}addHighlightArea(){this.container.classList.add("highlightArea")}}ql=new WeakMap;class FS extends jt{constructor(e){super(e,{isRenderable:!0,ignoreBorder:!0});y(this,Kl,null)}render(){this.container.classList.add("circleAnnotation");const e=this.data,{width:s,height:i}=Fn(e.rect),n=this.svgFactory.create(s,i,!0),r=e.borderStyle.width,o=m(this,Kl,this.svgFactory.createElement("svg:ellipse"));return o.setAttribute("cx",s/2),o.setAttribute("cy",i/2),o.setAttribute("rx",s/2-r/2),o.setAttribute("ry",i/2-r/2),o.setAttribute("stroke-width",r||1),o.setAttribute("stroke","transparent"),o.setAttribute("fill","transparent"),n.append(o),this.container.append(n),!e.popupRef&&this.hasPopupData&&this._createPopup(),this.container}getElementsToTriggerPopup(){return l(this,Kl)}addHighlightArea(){this.container.classList.add("highlightArea")}}Kl=new WeakMap;class Fb extends jt{constructor(e){super(e,{isRenderable:!0,ignoreBorder:!0});y(this,Ql,null);this.containerClassName="polylineAnnotation",this.svgElementName="svg:polyline"}render(){this.container.classList.add(this.containerClassName);const{data:{rect:e,vertices:s,borderStyle:i,popupRef:n}}=this;if(!s)return this.container;const{width:r,height:o}=Fn(e),h=this.svgFactory.create(r,o,!0);let c=[];for(let d=0,f=s.length;d<f;d+=2){const g=s[d]-e[0],p=e[3]-s[d+1];c.push(`${g},${p}`)}c=c.join(" ");const u=m(this,Ql,this.svgFactory.createElement(this.svgElementName));return u.setAttribute("points",c),u.setAttribute("stroke-width",i.width||1),u.setAttribute("stroke","transparent"),u.setAttribute("fill","transparent"),h.append(u),this.container.append(h),!n&&this.hasPopupData&&this._createPopup(),this.container}getElementsToTriggerPopup(){return l(this,Ql)}addHighlightArea(){this.container.classList.add("highlightArea")}}Ql=new WeakMap;class IS extends Fb{constructor(t){super(t),this.containerClassName="polygonAnnotation",this.svgElementName="svg:polygon"}}class NS extends jt{constructor(t){super(t,{isRenderable:!0,ignoreBorder:!0})}render(){return this.container.classList.add("caretAnnotation"),!this.data.popupRef&&this.hasPopupData&&this._createPopup(),this.container}}class Rg extends jt{constructor(e){super(e,{isRenderable:!0,ignoreBorder:!0});y(this,Zl);y(this,Jl,null);y(this,yo,[]);this.containerClassName="inkAnnotation",this.svgElementName="svg:polyline",this.annotationEditorType=this.data.it==="InkHighlight"?Z.HIGHLIGHT:Z.INK}render(){this.container.classList.add(this.containerClassName);const{data:{rect:e,rotation:s,inkLists:i,borderStyle:n,popupRef:r}}=this,{transform:o,width:h,height:c}=w(this,Zl,Cp).call(this,s,e),u=this.svgFactory.create(h,c,!0),d=m(this,Jl,this.svgFactory.createElement("svg:g"));u.append(d),d.setAttribute("stroke-width",n.width||1),d.setAttribute("stroke-linecap","round"),d.setAttribute("stroke-linejoin","round"),d.setAttribute("stroke-miterlimit",10),d.setAttribute("stroke","transparent"),d.setAttribute("fill","transparent"),d.setAttribute("transform",o);for(let f=0,g=i.length;f<g;f++){const p=this.svgFactory.createElement(this.svgElementName);l(this,yo).push(p),p.setAttribute("points",i[f].join(",")),d.append(p)}return!r&&this.hasPopupData&&this._createPopup(),this.container.append(u),this._editOnDoubleClick(),this.container}updateEdited(e){super.updateEdited(e);const{thickness:s,points:i,rect:n}=e,r=l(this,Jl);if(s>=0&&r.setAttribute("stroke-width",s||1),i)for(let o=0,h=l(this,yo).length;o<h;o++)l(this,yo)[o].setAttribute("points",i[o].join(","));if(n){const{transform:o,width:h,height:c}=w(this,Zl,Cp).call(this,this.data.rotation,n);r.parentElement.setAttribute("viewBox",`0 0 ${h} ${c}`),r.setAttribute("transform",o)}}getElementsToTriggerPopup(){return l(this,yo)}addHighlightArea(){this.container.classList.add("highlightArea")}}Jl=new WeakMap,yo=new WeakMap,Zl=new WeakSet,Cp=function(e,s){switch(e){case 90:return{transform:`rotate(90) translate(${-s[0]},${s[1]}) scale(1,-1)`,width:s[3]-s[1],height:s[2]-s[0]};case 180:return{transform:`rotate(180) translate(${-s[2]},${s[1]}) scale(1,-1)`,width:s[2]-s[0],height:s[3]-s[1]};case 270:return{transform:`rotate(270) translate(${-s[2]},${s[3]}) scale(1,-1)`,width:s[3]-s[1],height:s[2]-s[0]};default:return{transform:`translate(${-s[0]},${s[3]}) scale(1,-1)`,width:s[2]-s[0],height:s[3]-s[1]}}};class Ib extends jt{constructor(t){super(t,{isRenderable:!0,ignoreBorder:!0,createQuadrilaterals:!0}),this.annotationEditorType=Z.HIGHLIGHT}render(){return!this.data.popupRef&&this.hasPopupData&&this._createPopup(),this.container.classList.add("highlightAnnotation"),this._editOnDoubleClick(),this.container}}class jS extends jt{constructor(t){super(t,{isRenderable:!0,ignoreBorder:!0,createQuadrilaterals:!0})}render(){return!this.data.popupRef&&this.hasPopupData&&this._createPopup(),this.container.classList.add("underlineAnnotation"),this.container}}class BS extends jt{constructor(t){super(t,{isRenderable:!0,ignoreBorder:!0,createQuadrilaterals:!0})}render(){return!this.data.popupRef&&this.hasPopupData&&this._createPopup(),this.container.classList.add("squigglyAnnotation"),this.container}}class HS extends jt{constructor(t){super(t,{isRenderable:!0,ignoreBorder:!0,createQuadrilaterals:!0})}render(){return!this.data.popupRef&&this.hasPopupData&&this._createPopup(),this.container.classList.add("strikeoutAnnotation"),this.container}}class Nb extends jt{constructor(t){super(t,{isRenderable:!0,ignoreBorder:!0}),this.annotationEditorType=Z.STAMP}render(){return this.container.classList.add("stampAnnotation"),this.container.setAttribute("role","img"),!this.data.popupRef&&this.hasPopupData&&this._createPopup(),this._editOnDoubleClick(),this.container}}class GS extends jt{constructor(e){var i;super(e,{isRenderable:!0});y(this,ec);y(this,tc,null);const{file:s}=this.data;this.filename=s.filename,this.content=s.content,(i=this.linkService.eventBus)==null||i.dispatch("fileattachmentannotation",{source:this,...s})}render(){this.container.classList.add("fileAttachmentAnnotation");const{container:e,data:s}=this;let i;s.hasAppearance||s.fillAlpha===0?i=document.createElement("div"):(i=document.createElement("img"),i.src=`${this.imageResourcesPath}annotation-${/paperclip/i.test(s.name)?"paperclip":"pushpin"}.svg`,s.fillAlpha&&s.fillAlpha<1&&(i.style=`filter: opacity(${Math.round(s.fillAlpha*100)}%);`)),i.addEventListener("dblclick",w(this,ec,Ap).bind(this)),m(this,tc,i);const{isMac:n}=Re.platform;return e.addEventListener("keydown",r=>{r.key==="Enter"&&(n?r.metaKey:r.ctrlKey)&&w(this,ec,Ap).call(this)}),!s.popupRef&&this.hasPopupData?this._createPopup():i.classList.add("popupTriggerArea"),e.append(i),e}getElementsToTriggerPopup(){return l(this,tc)}addHighlightArea(){this.container.classList.add("highlightArea")}}tc=new WeakMap,ec=new WeakSet,Ap=function(){var e;(e=this.downloadManager)==null||e.openOrDownloadData(this.content,this.filename)};class zS{constructor({div:t,accessibilityManager:e,annotationCanvasMap:s,annotationEditorUIManager:i,page:n,viewport:r,structTreeLayer:o}){y(this,wo);y(this,sc,null);y(this,vo,null);y(this,_o,new Map);y(this,ic,null);this.div=t,m(this,sc,e),m(this,vo,s),m(this,ic,o||null),this.page=n,this.viewport=r,this.zIndex=0,this._annotationEditorUIManager=i}hasEditableAnnotations(){return l(this,_o).size>0}async render(t){var r;const{annotations:e}=t,s=this.div;kr(s,this.viewport);const i=new Map,n={data:null,layer:s,linkService:t.linkService,downloadManager:t.downloadManager,imageResourcesPath:t.imageResourcesPath||"",renderForms:t.renderForms!==!1,svgFactory:new Dg,annotationStorage:t.annotationStorage||new xg,enableScripting:t.enableScripting===!0,hasJSActions:t.hasJSActions,fieldObjects:t.fieldObjects,parent:this,elements:null};for(const o of e){if(o.noHTML)continue;const h=o.annotationType===qt.POPUP;if(h){const d=i.get(o.id);if(!d)continue;n.elements=d}else{const{width:d,height:f}=Fn(o.rect);if(d<=0||f<=0)continue}n.data=o;const c=AS.create(n);if(!c.isRenderable)continue;if(!h&&o.popupRef){const d=i.get(o.popupRef);d?d.push(c):i.set(o.popupRef,[c])}const u=c.render();o.hidden&&(u.style.visibility="hidden"),await w(this,wo,By).call(this,u,o.id),c._isEditable&&(l(this,_o).set(c.data.id,c),(r=this._annotationEditorUIManager)==null||r.renderAnnotationElement(c))}w(this,wo,Tp).call(this)}update({viewport:t}){const e=this.div;this.viewport=t,kr(e,{rotation:t.rotation}),w(this,wo,Tp).call(this),e.hidden=!1}getEditableAnnotations(){return Array.from(l(this,_o).values())}getEditableAnnotation(t){return l(this,_o).get(t)}}sc=new WeakMap,vo=new WeakMap,_o=new WeakMap,ic=new WeakMap,wo=new WeakSet,By=async function(t,e){var r,o;const s=t.firstChild||t,i=s.id=`${dg}${e}`,n=await((r=l(this,ic))==null?void 0:r.getAriaAttributes(i));if(n)for(const[h,c]of n)s.setAttribute(h,c);this.div.append(t),(o=l(this,sc))==null||o.moveElementInDOM(this.div,t,s,!1)},Tp=function(){if(!l(this,vo))return;const t=this.div;for(const[e,s]of l(this,vo)){const i=t.querySelector(`[data-annotation-id="${e}"]`);if(!i)continue;s.className="annotationContent";const{firstChild:n}=i;n?n.nodeName==="CANVAS"?n.replaceWith(s):n.classList.contains("annotationContent")?n.after(s):n.before(s):i.append(s)}l(this,vo).clear()};const id=/\r\n?|\n/g,wt=class wt extends Pt{constructor(e){super({...e,name:"freeTextEditor"});y(this,Ut);y(this,qs);y(this,hs,"");y(this,nc,`${this.id}-editor`);y(this,xo,null);y(this,ls);m(this,qs,e.color||wt._defaultColor||Pt._defaultLineColor),m(this,ls,e.fontSize||wt._defaultFontSize)}static get _keyboardManager(){const e=wt.prototype,s=r=>r.isEmpty(),i=Mr.TRANSLATE_SMALL,n=Mr.TRANSLATE_BIG;return st(this,"_keyboardManager",new Xh([[["ctrl+s","mac+meta+s","ctrl+p","mac+meta+p"],e.commitOrRemove,{bubbles:!0}],[["ctrl+Enter","mac+meta+Enter","Escape","mac+Escape"],e.commitOrRemove],[["ArrowLeft","mac+ArrowLeft"],e._translateEmpty,{args:[-i,0],checker:s}],[["ctrl+ArrowLeft","mac+shift+ArrowLeft"],e._translateEmpty,{args:[-n,0],checker:s}],[["ArrowRight","mac+ArrowRight"],e._translateEmpty,{args:[i,0],checker:s}],[["ctrl+ArrowRight","mac+shift+ArrowRight"],e._translateEmpty,{args:[n,0],checker:s}],[["ArrowUp","mac+ArrowUp"],e._translateEmpty,{args:[0,-i],checker:s}],[["ctrl+ArrowUp","mac+shift+ArrowUp"],e._translateEmpty,{args:[0,-n],checker:s}],[["ArrowDown","mac+ArrowDown"],e._translateEmpty,{args:[0,i],checker:s}],[["ctrl+ArrowDown","mac+shift+ArrowDown"],e._translateEmpty,{args:[0,n],checker:s}]]))}static initialize(e,s){Pt.initialize(e,s);const i=getComputedStyle(document.documentElement);this._internalPadding=parseFloat(i.getPropertyValue("--freetext-padding"))}static updateDefaultParams(e,s){switch(e){case ot.FREETEXT_SIZE:wt._defaultFontSize=s;break;case ot.FREETEXT_COLOR:wt._defaultColor=s;break}}updateParams(e,s){switch(e){case ot.FREETEXT_SIZE:w(this,Ut,Hy).call(this,s);break;case ot.FREETEXT_COLOR:w(this,Ut,Gy).call(this,s);break}}static get defaultPropertiesToUpdate(){return[[ot.FREETEXT_SIZE,wt._defaultFontSize],[ot.FREETEXT_COLOR,wt._defaultColor||Pt._defaultLineColor]]}get propertiesToUpdate(){return[[ot.FREETEXT_SIZE,l(this,ls)],[ot.FREETEXT_COLOR,l(this,qs)]]}_translateEmpty(e,s){this._uiManager.translateSelectedEditors(e,s,!0)}getInitialTranslation(){const e=this.parentScale;return[-wt._internalPadding*e,-(wt._internalPadding+l(this,ls))*e]}rebuild(){this.parent&&(super.rebuild(),this.div!==null&&(this.isAttachedToDOM||this.parent.add(this)))}enableEditMode(){if(this.isInEditMode())return;this.parent.setEditingState(!1),this.parent.updateToolbar(Z.FREETEXT),super.enableEditMode(),this.overlayDiv.classList.remove("enabled"),this.editorDiv.contentEditable=!0,this._isDraggable=!1,this.div.removeAttribute("aria-activedescendant"),m(this,xo,new AbortController);const e=this._uiManager.combinedSignal(l(this,xo));this.editorDiv.addEventListener("keydown",this.editorDivKeydown.bind(this),{signal:e}),this.editorDiv.addEventListener("focus",this.editorDivFocus.bind(this),{signal:e}),this.editorDiv.addEventListener("blur",this.editorDivBlur.bind(this),{signal:e}),this.editorDiv.addEventListener("input",this.editorDivInput.bind(this),{signal:e}),this.editorDiv.addEventListener("paste",this.editorDivPaste.bind(this),{signal:e})}disableEditMode(){var e;this.isInEditMode()&&(this.parent.setEditingState(!0),super.disableEditMode(),this.overlayDiv.classList.add("enabled"),this.editorDiv.contentEditable=!1,this.div.setAttribute("aria-activedescendant",l(this,nc)),this._isDraggable=!0,(e=l(this,xo))==null||e.abort(),m(this,xo,null),this.div.focus({preventScroll:!0}),this.isEditing=!1,this.parent.div.classList.add("freetextEditing"))}focusin(e){this._focusEventsAllowed&&(super.focusin(e),e.target!==this.editorDiv&&this.editorDiv.focus())}onceAdded(e){var s;this.width||(this.enableEditMode(),e&&this.editorDiv.focus(),(s=this._initialOptions)!=null&&s.isCentered&&this.center(),this._initialOptions=null)}isEmpty(){return!this.editorDiv||this.editorDiv.innerText.trim()===""}remove(){this.isEditing=!1,this.parent&&(this.parent.setEditingState(!0),this.parent.div.classList.add("freetextEditing")),super.remove()}commit(){if(!this.isInEditMode())return;super.commit(),this.disableEditMode();const e=l(this,hs),s=m(this,hs,w(this,Ut,zy).call(this).trimEnd());if(e===s)return;const i=n=>{if(m(this,hs,n),!n){this.remove();return}w(this,Ut,Yd).call(this),this._uiManager.rebuild(this),w(this,Ut,Wd).call(this)};this.addCommands({cmd:()=>{i(s)},undo:()=>{i(e)},mustExec:!1}),w(this,Ut,Wd).call(this)}shouldGetKeyboardEvents(){return this.isInEditMode()}enterInEditMode(){this.enableEditMode(),this.editorDiv.focus()}dblclick(e){this.enterInEditMode()}keydown(e){e.target===this.div&&e.key==="Enter"&&(this.enterInEditMode(),e.preventDefault())}editorDivKeydown(e){wt._keyboardManager.exec(this,e)}editorDivFocus(e){this.isEditing=!0}editorDivBlur(e){this.isEditing=!1}editorDivInput(e){this.parent.div.classList.toggle("freetextEditing",this.isEmpty())}disableEditing(){this.editorDiv.setAttribute("role","comment"),this.editorDiv.removeAttribute("aria-multiline")}enableEditing(){this.editorDiv.setAttribute("role","textbox"),this.editorDiv.setAttribute("aria-multiline",!0)}render(){if(this.div)return this.div;let e,s;this.width&&(e=this.x,s=this.y),super.render(),this.editorDiv=document.createElement("div"),this.editorDiv.className="internal",this.editorDiv.setAttribute("id",l(this,nc)),this.editorDiv.setAttribute("data-l10n-id","pdfjs-free-text2"),this.editorDiv.setAttribute("data-l10n-attrs","default-content"),this.enableEditing(),this.editorDiv.contentEditable=!0;const{style:i}=this.editorDiv;if(i.fontSize=`calc(${l(this,ls)}px * var(--scale-factor))`,i.color=l(this,qs),this.div.append(this.editorDiv),this.overlayDiv=document.createElement("div"),this.overlayDiv.classList.add("overlay","enabled"),this.div.append(this.overlayDiv),qu(this,this.div,["dblclick","keydown"]),this.width){const[n,r]=this.parentDimensions;if(this.annotationElementId){const{position:o}=this._initialData;let[h,c]=this.getInitialTranslation();[h,c]=this.pageTranslationToScreen(h,c);const[u,d]=this.pageDimensions,[f,g]=this.pageTranslation;let p,b;switch(this.rotation){case 0:p=e+(o[0]-f)/u,b=s+this.height-(o[1]-g)/d;break;case 90:p=e+(o[0]-f)/u,b=s-(o[1]-g)/d,[h,c]=[c,-h];break;case 180:p=e-this.width+(o[0]-f)/u,b=s-(o[1]-g)/d,[h,c]=[-h,-c];break;case 270:p=e+(o[0]-f-this.height*d)/u,b=s+(o[1]-g-this.width*u)/d,[h,c]=[-c,h];break}this.setAt(p*n,b*r,h,c)}else this.setAt(e*n,s*r,this.width*n,this.height*r);w(this,Ut,Yd).call(this),this._isDraggable=!0,this.editorDiv.contentEditable=!1}else this._isDraggable=!1,this.editorDiv.contentEditable=!0;return this.div}editorDivPaste(e){var p,b,_;const s=e.clipboardData||window.clipboardData,{types:i}=s;if(i.length===1&&i[0]==="text/plain")return;e.preventDefault();const n=w(p=wt,fn,Ep).call(p,s.getData("text")||"").replaceAll(id,`
|
|
502
502
|
`);if(!n)return;const r=window.getSelection();if(!r.rangeCount)return;this.editorDiv.normalize(),r.deleteFromDocument();const o=r.getRangeAt(0);if(!n.includes(`
|
|
503
503
|
`)){o.insertNode(document.createTextNode(n)),this.editorDiv.normalize(),r.collapseToStart();return}const{startContainer:h,startOffset:c}=o,u=[],d=[];if(h.nodeType===Node.TEXT_NODE){const v=h.parentElement;if(d.push(h.nodeValue.slice(c).replaceAll(id,"")),v!==this.editorDiv){let x=u;for(const C of this.editorDiv.childNodes){if(C===v){x=d;continue}x.push(w(b=wt,fn,Ud).call(b,C))}}u.push(h.nodeValue.slice(0,c).replaceAll(id,""))}else if(h===this.editorDiv){let v=u,x=0;for(const C of this.editorDiv.childNodes)x++===c&&(v=d),v.push(w(_=wt,fn,Ud).call(_,C))}m(this,hs,`${u.join(`
|
|
504
504
|
`)}${n}${d.join(`
|
|
505
|
-
`)}`),w(this,Ut,Yd).call(this);const f=new Range;let g=u.reduce((v,x)=>v+x.length,0);for(const{firstChild:v}of this.editorDiv.childNodes)if(v.nodeType===Node.TEXT_NODE){const x=v.nodeValue.length;if(g<=x){f.setStart(v,g),f.setEnd(v,g);break}g-=x}r.removeAllRanges(),r.addRange(f)}get contentDiv(){return this.editorDiv}static async deserialize(e,s,i){var o;let n=null;if(e instanceof
|
|
506
|
-
`),position:b,pageIndex:_-1,rect:u.slice(0),rotation:d,id:f,deleted:!1,popupRef:g}}const r=await super.deserialize(e,s,i);return m(r,ls,e.fontSize),m(r,qs,
|
|
507
|
-
`)){const o=document.createElement("div");o.append(r?document.createTextNode(r):document.createElement("br")),s.append(o)}const n=wt._internalPadding*this.parentScale;return e.updateEdited({rect:this.getRect(n,n),popupContent:l(this,hs)}),s}resetAnnotationElement(e){super.resetAnnotationElement(e),e.resetEdited()}};qs=new WeakMap,hs=new WeakMap,nc=new WeakMap,xo=new WeakMap,ls=new WeakMap,Ut=new WeakSet,
|
|
505
|
+
`)}`),w(this,Ut,Yd).call(this);const f=new Range;let g=u.reduce((v,x)=>v+x.length,0);for(const{firstChild:v}of this.editorDiv.childNodes)if(v.nodeType===Node.TEXT_NODE){const x=v.nodeValue.length;if(g<=x){f.setStart(v,g),f.setEnd(v,g);break}g-=x}r.removeAllRanges(),r.addRange(f)}get contentDiv(){return this.editorDiv}static async deserialize(e,s,i){var o;let n=null;if(e instanceof Lb){const{data:{defaultAppearanceData:{fontSize:h,fontColor:c},rect:u,rotation:d,id:f,popupRef:g},textContent:p,textPosition:b,parent:{page:{pageNumber:_}}}=e;if(!p||p.length===0)return null;n=e={annotationType:Z.FREETEXT,color:Array.from(c),fontSize:h,value:p.join(`
|
|
506
|
+
`),position:b,pageIndex:_-1,rect:u.slice(0),rotation:d,id:f,deleted:!1,popupRef:g}}const r=await super.deserialize(e,s,i);return m(r,ls,e.fontSize),m(r,qs,W.makeHexColor(...e.color)),m(r,hs,w(o=wt,fn,Ep).call(o,e.value)),r.annotationElementId=e.id||null,r._initialData=n,r}serialize(e=!1){if(this.isEmpty())return null;if(this.deleted)return this.serializeDeleted();const s=wt._internalPadding*this.parentScale,i=this.getRect(s,s),n=Pt._colorManager.convert(this.isAttachedToDOM?getComputedStyle(this.editorDiv).color:l(this,qs)),r={annotationType:Z.FREETEXT,color:n,fontSize:l(this,ls),value:w(this,Ut,Vy).call(this),pageIndex:this.pageIndex,rect:i,rotation:this.rotation,structTreeParentId:this._structTreeParentId};return e?r:this.annotationElementId&&!w(this,Ut,Xy).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(${l(this,ls)}px * var(--scale-factor))`,i.color=l(this,qs),s.replaceChildren();for(const r of l(this,hs).split(`
|
|
507
|
+
`)){const o=document.createElement("div");o.append(r?document.createTextNode(r):document.createElement("br")),s.append(o)}const n=wt._internalPadding*this.parentScale;return e.updateEdited({rect:this.getRect(n,n),popupContent:l(this,hs)}),s}resetAnnotationElement(e){super.resetAnnotationElement(e),e.resetEdited()}};qs=new WeakMap,hs=new WeakMap,nc=new WeakMap,xo=new WeakMap,ls=new WeakMap,Ut=new WeakSet,Hy=function(e){const s=n=>{this.editorDiv.style.fontSize=`calc(${n}px * var(--scale-factor))`,this.translate(0,-(n-l(this,ls))*this.parentScale),m(this,ls,n),w(this,Ut,Wd).call(this)},i=l(this,ls);this.addCommands({cmd:s.bind(this,e),undo:s.bind(this,i),post:this._uiManager.updateUI.bind(this._uiManager,this),mustExec:!0,type:ot.FREETEXT_SIZE,overwriteIfSameType:!0,keepUndo:!0})},Gy=function(e){const s=n=>{m(this,qs,this.editorDiv.style.color=n)},i=l(this,qs);this.addCommands({cmd:s.bind(this,e),undo:s.bind(this,i),post:this._uiManager.updateUI.bind(this._uiManager,this),mustExec:!0,type:ot.FREETEXT_COLOR,overwriteIfSameType:!0,keepUndo:!0})},zy=function(){var i;const e=[];this.editorDiv.normalize();let s=null;for(const n of this.editorDiv.childNodes)(s==null?void 0:s.nodeType)===Node.TEXT_NODE&&n.nodeName==="BR"||(e.push(w(i=wt,fn,Ud).call(i,n)),s=n);return e.join(`
|
|
508
508
|
`)},Wd=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()},fn=new WeakSet,Ud=function(e){return(e.nodeType===Node.TEXT_NODE?e.nodeValue:e.innerText).replaceAll(id,"")},Yd=function(){if(this.editorDiv.replaceChildren(),!!l(this,hs))for(const e of l(this,hs).split(`
|
|
509
|
-
`)){const s=document.createElement("div");s.append(e?document.createTextNode(e):document.createElement("br")),this.editorDiv.append(s)}},Hy=function(){return l(this,hs).replaceAll(" "," ")},Ep=function(e){return e.replaceAll(" "," ")},Gy=function(e){const{value:s,fontSize:i,color:n,pageIndex:r}=this._initialData;return this._hasBeenMoved||e.value!==s||e.fontSize!==i||e.color.some((o,h)=>o!==n[h])||e.pageIndex!==r},y(wt,fn),q(wt,"_freeTextDefaultContent",""),q(wt,"_internalPadding",0),q(wt,"_defaultColor",null),q(wt,"_defaultFontSize",10),q(wt,"_type","freetext"),q(wt,"_editorType",tt.FREETEXT);let Lg=wt;class z{toSVGPath(){vt("Abstract method `toSVGPath` must be implemented.")}get box(){vt("Abstract getter `box` must be implemented.")}serialize(t,e){vt("Abstract method `serialize` must be implemented.")}static _rescale(t,e,s,i,n,r){r||(r=new Float32Array(t.length));for(let o=0,h=t.length;o<h;o+=2)r[o]=e+t[o]*i,r[o+1]=s+t[o+1]*n;return r}static _rescaleAndSwap(t,e,s,i,n,r){r||(r=new Float32Array(t.length));for(let o=0,h=t.length;o<h;o+=2)r[o]=e+t[o+1]*i,r[o+1]=s+t[o]*n;return r}static _translate(t,e,s,i){i||(i=new Float32Array(t.length));for(let n=0,r=t.length;n<r;n+=2)i[n]=e+t[n],i[n+1]=s+t[n+1];return i}static svgRound(t){return Math.round(t*1e4)}static _normalizePoint(t,e,s,i,n){switch(n){case 90:return[1-e/s,t/i];case 180:return[1-t/s,1-e/i];case 270:return[e/s,1-t/i];default:return[t/s,e/i]}}static _normalizePagePoint(t,e,s){switch(s){case 90:return[1-e,t];case 180:return[1-t,1-e];case 270:return[e,1-t];default:return[t,e]}}static createBezierPoints(t,e,s,i,n,r){return[(t+5*s)/6,(e+5*i)/6,(5*s+n)/6,(5*i+r)/6,(s+n)/2,(i+r)/2]}}q(z,"PRECISION",1e-4);const gn=class gn{constructor({x:t,y:e},s,i,n,r,o=0){y(this,Jt);y(this,cs);y(this,Ks,[]);y(this,Xa);y(this,Wa);y(this,wi,[]);y(this,nt,new Float32Array(18));y(this,So);y(this,Co);y(this,rc);y(this,oc);y(this,Ua);y(this,Ya);y(this,sr,[]);m(this,cs,s),m(this,Ya,n*i),m(this,Wa,r),l(this,nt).set([NaN,NaN,NaN,NaN,t,e],6),m(this,Xa,o),m(this,oc,l(gn,ac)*i),m(this,rc,l(gn,Sd)*i),m(this,Ua,i),l(this,sr).push(t,e)}isEmpty(){return isNaN(l(this,nt)[8])}add({x:t,y:e}){var R;m(this,So,t),m(this,Co,e);const[s,i,n,r]=l(this,cs);let[o,h,c,u]=l(this,nt).subarray(8,12);const d=t-c,f=e-u,g=Math.hypot(d,f);if(g<l(this,rc))return!1;const p=g-l(this,oc),b=p/g,_=b*d,v=b*f;let x=o,C=h;o=c,h=u,c+=_,u+=v,(R=l(this,sr))==null||R.push(t,e);const S=-v/p,E=_/p,k=S*l(this,Ya),M=E*l(this,Ya);return l(this,nt).set(l(this,nt).subarray(2,8),0),l(this,nt).set([c+k,u+M],4),l(this,nt).set(l(this,nt).subarray(14,18),12),l(this,nt).set([c-k,u-M],16),isNaN(l(this,nt)[6])?(l(this,wi).length===0&&(l(this,nt).set([o+k,h+M],2),l(this,wi).push(NaN,NaN,NaN,NaN,(o+k-s)/n,(h+M-i)/r),l(this,nt).set([o-k,h-M],14),l(this,Ks).push(NaN,NaN,NaN,NaN,(o-k-s)/n,(h-M-i)/r)),l(this,nt).set([x,C,o,h,c,u],6),!this.isEmpty()):(l(this,nt).set([x,C,o,h,c,u],6),Math.abs(Math.atan2(C-h,x-o)-Math.atan2(v,_))<Math.PI/2?([o,h,c,u]=l(this,nt).subarray(2,6),l(this,wi).push(NaN,NaN,NaN,NaN,((o+c)/2-s)/n,((h+u)/2-i)/r),[o,h,x,C]=l(this,nt).subarray(14,18),l(this,Ks).push(NaN,NaN,NaN,NaN,((x+o)/2-s)/n,((C+h)/2-i)/r),!0):([x,C,o,h,c,u]=l(this,nt).subarray(0,6),l(this,wi).push(((x+5*o)/6-s)/n,((C+5*h)/6-i)/r,((5*o+c)/6-s)/n,((5*h+u)/6-i)/r,((o+c)/2-s)/n,((h+u)/2-i)/r),[c,u,o,h,x,C]=l(this,nt).subarray(12,18),l(this,Ks).push(((x+5*o)/6-s)/n,((C+5*h)/6-i)/r,((5*o+c)/6-s)/n,((5*h+u)/6-i)/r,((o+c)/2-s)/n,((h+u)/2-i)/r),!0))}toSVGPath(){if(this.isEmpty())return"";const t=l(this,wi),e=l(this,Ks);if(isNaN(l(this,nt)[6])&&!this.isEmpty())return w(this,Jt,zy).call(this);const s=[];s.push(`M${t[4]} ${t[5]}`);for(let i=6;i<t.length;i+=6)isNaN(t[i])?s.push(`L${t[i+4]} ${t[i+5]}`):s.push(`C${t[i]} ${t[i+1]} ${t[i+2]} ${t[i+3]} ${t[i+4]} ${t[i+5]}`);w(this,Jt,Xy).call(this,s);for(let i=e.length-6;i>=6;i-=6)isNaN(e[i])?s.push(`L${e[i+4]} ${e[i+5]}`):s.push(`C${e[i]} ${e[i+1]} ${e[i+2]} ${e[i+3]} ${e[i+4]} ${e[i+5]}`);return w(this,Jt,Vy).call(this,s),s.join(" ")}newFreeDrawOutline(t,e,s,i,n,r){return new zb(t,e,s,i,n,r)}getOutlines(){var d;const t=l(this,wi),e=l(this,Ks),s=l(this,nt),[i,n,r,o]=l(this,cs),h=new Float32Array((((d=l(this,sr))==null?void 0:d.length)??0)+2);for(let f=0,g=h.length-2;f<g;f+=2)h[f]=(l(this,sr)[f]-i)/r,h[f+1]=(l(this,sr)[f+1]-n)/o;if(h[h.length-2]=(l(this,So)-i)/r,h[h.length-1]=(l(this,Co)-n)/o,isNaN(s[6])&&!this.isEmpty())return w(this,Jt,Wy).call(this,h);const c=new Float32Array(l(this,wi).length+24+l(this,Ks).length);let u=t.length;for(let f=0;f<u;f+=2){if(isNaN(t[f])){c[f]=c[f+1]=NaN;continue}c[f]=t[f],c[f+1]=t[f+1]}u=w(this,Jt,Yy).call(this,c,u);for(let f=e.length-6;f>=6;f-=6)for(let g=0;g<6;g+=2){if(isNaN(e[f+g])){c[u]=c[u+1]=NaN,u+=2;continue}c[u]=e[f+g],c[u+1]=e[f+g+1],u+=2}return w(this,Jt,Uy).call(this,c,u),this.newFreeDrawOutline(c,h,l(this,cs),l(this,Ua),l(this,Xa),l(this,Wa))}};cs=new WeakMap,Ks=new WeakMap,Xa=new WeakMap,Wa=new WeakMap,wi=new WeakMap,nt=new WeakMap,So=new WeakMap,Co=new WeakMap,rc=new WeakMap,oc=new WeakMap,Ua=new WeakMap,Ya=new WeakMap,sr=new WeakMap,ac=new WeakMap,xd=new WeakMap,Sd=new WeakMap,Jt=new WeakSet,Rc=function(){const t=l(this,nt).subarray(4,6),e=l(this,nt).subarray(16,18),[s,i,n,r]=l(this,cs);return[(l(this,So)+(t[0]-e[0])/2-s)/n,(l(this,Co)+(t[1]-e[1])/2-i)/r,(l(this,So)+(e[0]-t[0])/2-s)/n,(l(this,Co)+(e[1]-t[1])/2-i)/r]},zy=function(){const[t,e,s,i]=l(this,cs),[n,r,o,h]=w(this,Jt,Rc).call(this);return`M${(l(this,nt)[2]-t)/s} ${(l(this,nt)[3]-e)/i} L${(l(this,nt)[4]-t)/s} ${(l(this,nt)[5]-e)/i} L${n} ${r} L${o} ${h} L${(l(this,nt)[16]-t)/s} ${(l(this,nt)[17]-e)/i} L${(l(this,nt)[14]-t)/s} ${(l(this,nt)[15]-e)/i} Z`},Vy=function(t){const e=l(this,Ks);t.push(`L${e[4]} ${e[5]} Z`)},Xy=function(t){const[e,s,i,n]=l(this,cs),r=l(this,nt).subarray(4,6),o=l(this,nt).subarray(16,18),[h,c,u,d]=w(this,Jt,Rc).call(this);t.push(`L${(r[0]-e)/i} ${(r[1]-s)/n} L${h} ${c} L${u} ${d} L${(o[0]-e)/i} ${(o[1]-s)/n}`)},Wy=function(t){const e=l(this,nt),[s,i,n,r]=l(this,cs),[o,h,c,u]=w(this,Jt,Rc).call(this),d=new Float32Array(36);return d.set([NaN,NaN,NaN,NaN,(e[2]-s)/n,(e[3]-i)/r,NaN,NaN,NaN,NaN,(e[4]-s)/n,(e[5]-i)/r,NaN,NaN,NaN,NaN,o,h,NaN,NaN,NaN,NaN,c,u,NaN,NaN,NaN,NaN,(e[16]-s)/n,(e[17]-i)/r,NaN,NaN,NaN,NaN,(e[14]-s)/n,(e[15]-i)/r],0),this.newFreeDrawOutline(d,t,l(this,cs),l(this,Ua),l(this,Xa),l(this,Wa))},Uy=function(t,e){const s=l(this,Ks);return t.set([NaN,NaN,NaN,NaN,s[4],s[5]],e),e+=6},Yy=function(t,e){const s=l(this,nt).subarray(4,6),i=l(this,nt).subarray(16,18),[n,r,o,h]=l(this,cs),[c,u,d,f]=w(this,Jt,Rc).call(this);return t.set([NaN,NaN,NaN,NaN,(s[0]-n)/o,(s[1]-r)/h,NaN,NaN,NaN,NaN,c,u,NaN,NaN,NaN,NaN,d,f,NaN,NaN,NaN,NaN,(i[0]-n)/o,(i[1]-r)/h],e),e+=24},y(gn,ac,8),y(gn,xd,2),y(gn,Sd,l(gn,ac)+l(gn,xd));let nd=gn;class zb extends z{constructor(e,s,i,n,r,o){super();y(this,Cd);y(this,$a);y(this,Ao,new Float32Array(4));y(this,pn);y(this,hc);y(this,us);y(this,lc);y(this,Ht);m(this,Ht,e),m(this,us,s),m(this,$a,i),m(this,lc,n),m(this,pn,r),m(this,hc,o),this.lastPoint=[NaN,NaN],w(this,Cd,$y).call(this,o);const[h,c,u,d]=l(this,Ao);for(let f=0,g=e.length;f<g;f+=2)e[f]=(e[f]-h)/u,e[f+1]=(e[f+1]-c)/d;for(let f=0,g=s.length;f<g;f+=2)s[f]=(s[f]-h)/u,s[f+1]=(s[f+1]-c)/d}toSVGPath(){const e=[`M${l(this,Ht)[4]} ${l(this,Ht)[5]}`];for(let s=6,i=l(this,Ht).length;s<i;s+=6){if(isNaN(l(this,Ht)[s])){e.push(`L${l(this,Ht)[s+4]} ${l(this,Ht)[s+5]}`);continue}e.push(`C${l(this,Ht)[s]} ${l(this,Ht)[s+1]} ${l(this,Ht)[s+2]} ${l(this,Ht)[s+3]} ${l(this,Ht)[s+4]} ${l(this,Ht)[s+5]}`)}return e.push("Z"),e.join(" ")}serialize([e,s,i,n],r){const o=i-e,h=n-s;let c,u;switch(r){case 0:c=z._rescale(l(this,Ht),e,n,o,-h),u=z._rescale(l(this,us),e,n,o,-h);break;case 90:c=z._rescaleAndSwap(l(this,Ht),e,s,o,h),u=z._rescaleAndSwap(l(this,us),e,s,o,h);break;case 180:c=z._rescale(l(this,Ht),i,s,-o,h),u=z._rescale(l(this,us),i,s,-o,h);break;case 270:c=z._rescaleAndSwap(l(this,Ht),i,n,-o,-h),u=z._rescaleAndSwap(l(this,us),i,n,-o,-h);break}return{outline:Array.from(c),points:[Array.from(u)]}}get box(){return l(this,Ao)}newOutliner(e,s,i,n,r,o=0){return new nd(e,s,i,n,r,o)}getNewOutline(e,s){const[i,n,r,o]=l(this,Ao),[h,c,u,d]=l(this,$a),f=r*u,g=o*d,p=i*u+h,b=n*d+c,_=this.newOutliner({x:l(this,us)[0]*f+p,y:l(this,us)[1]*g+b},l(this,$a),l(this,lc),e,l(this,hc),s??l(this,pn));for(let v=2;v<l(this,us).length;v+=2)_.add({x:l(this,us)[v]*f+p,y:l(this,us)[v+1]*g+b});return _.getOutlines()}}$a=new WeakMap,Ao=new WeakMap,pn=new WeakMap,hc=new WeakMap,us=new WeakMap,lc=new WeakMap,Ht=new WeakMap,Cd=new WeakSet,$y=function(e){const s=l(this,Ht);let i=s[4],n=s[5],r=i,o=n,h=i,c=n,u=i,d=n;const f=e?Math.max:Math.min;for(let p=6,b=s.length;p<b;p+=6){if(isNaN(s[p]))r=Math.min(r,s[p+4]),o=Math.min(o,s[p+5]),h=Math.max(h,s[p+4]),c=Math.max(c,s[p+5]),d<s[p+5]?(u=s[p+4],d=s[p+5]):d===s[p+5]&&(u=f(u,s[p+4]));else{const _=U.bezierBoundingBox(i,n,...s.slice(p,p+6));r=Math.min(r,_[0]),o=Math.min(o,_[1]),h=Math.max(h,_[2]),c=Math.max(c,_[3]),d<_[3]?(u=_[2],d=_[3]):d===_[3]&&(u=f(u,_[2]))}i=s[p+4],n=s[p+5]}const g=l(this,Ao);g[0]=r-l(this,pn),g[1]=o-l(this,pn),g[2]=h-r+2*l(this,pn),g[3]=c-o+2*l(this,pn),this.lastPoint=[u,d]};class Fg{constructor(t,e=0,s=0,i=!0){y(this,Ie);y(this,cc);y(this,uc);y(this,ir,[]);y(this,Qs,[]);let n=1/0,r=-1/0,o=1/0,h=-1/0;const c=10**-4;for(const{x:_,y:v,width:x,height:C}of t){const S=Math.floor((_-e)/c)*c,E=Math.ceil((_+x+e)/c)*c,k=Math.floor((v-e)/c)*c,M=Math.ceil((v+C+e)/c)*c,D=[S,k,M,!0],R=[E,k,M,!1];l(this,ir).push(D,R),n=Math.min(n,S),r=Math.max(r,E),o=Math.min(o,k),h=Math.max(h,M)}const u=r-n+2*s,d=h-o+2*s,f=n-s,g=o-s,p=l(this,ir).at(i?-1:-2),b=[p[0],p[2]];for(const _ of l(this,ir)){const[v,x,C]=_;_[0]=(v-f)/u,_[1]=(x-g)/d,_[2]=(C-g)/d}m(this,cc,new Float32Array([f,g,u,d])),m(this,uc,b)}getOutlines(){l(this,ir).sort((e,s)=>e[0]-s[0]||e[1]-s[1]||e[2]-s[2]);const t=[];for(const e of l(this,ir))e[3]?(t.push(...w(this,Ie,kp).call(this,e)),w(this,Ie,Ky).call(this,e)):(w(this,Ie,Qy).call(this,e),t.push(...w(this,Ie,kp).call(this,e)));return w(this,Ie,qy).call(this,t)}}cc=new WeakMap,uc=new WeakMap,ir=new WeakMap,Qs=new WeakMap,Ie=new WeakSet,qy=function(t){const e=[],s=new Set;for(const r of t){const[o,h,c]=r;e.push([o,h,r],[o,c,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],c=e[r+1][2];h.push(c),c.push(h),s.add(h),s.add(c)}const i=[];let n;for(;s.size>0;){const r=s.values().next().value;let[o,h,c,u,d]=r;s.delete(r);let f=o,g=h;for(n=[o,c],i.push(n);;){let p;if(s.has(u))p=u;else if(s.has(d))p=d;else break;s.delete(p),[o,h,c,u,d]=p,f!==o&&(n.push(f,g,o,g===h?h:c),f=o),g=g===h?c:h}n.push(f,g)}return new nC(i,l(this,cc),l(this,uc))},$d=function(t){const e=l(this,Qs);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},Ky=function([,t,e]){const s=w(this,Ie,$d).call(this,t);l(this,Qs).splice(s,0,[t,e])},Qy=function([,t,e]){const s=w(this,Ie,$d).call(this,t);for(let i=s;i<l(this,Qs).length;i++){const[n,r]=l(this,Qs)[i];if(n!==t)break;if(n===t&&r===e){l(this,Qs).splice(i,1);return}}for(let i=s-1;i>=0;i--){const[n,r]=l(this,Qs)[i];if(n!==t)break;if(n===t&&r===e){l(this,Qs).splice(i,1);return}}},kp=function(t){const[e,s,i]=t,n=[[e,s,i]],r=w(this,Ie,$d).call(this,i);for(let o=0;o<r;o++){const[h,c]=l(this,Qs)[o];for(let u=0,d=n.length;u<d;u++){const[,f,g]=n[u];if(!(c<=f||g<=h)){if(f>=h){if(g>c)n[u][1]=c;else{if(d===1)return[];n.splice(u,1),u--,d--}continue}n[u][2]=h,g>c&&n.push([e,c,g])}}}return n};class nC extends z{constructor(e,s,i){super();y(this,dc);y(this,qa);m(this,qa,e),m(this,dc,s),this.lastPoint=i}toSVGPath(){const e=[];for(const s of l(this,qa)){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,c=n-s;for(const u of l(this,qa)){const d=new Array(u.length);for(let f=0;f<u.length;f+=2)d[f]=e+u[f]*h,d[f+1]=n-u[f+1]*c;o.push(d)}return o}get box(){return l(this,dc)}get classNamesForOutlining(){return["highlightOutline"]}}dc=new WeakMap,qa=new WeakMap;class Ig extends nd{newFreeDrawOutline(t,e,s,i,n,r){return new rC(t,e,s,i,n,r)}}class rC extends zb{newOutliner(t,e,s,i,n,r=0){return new Ig(t,e,s,i,n,r)}}const Ke=class Ke{constructor({editor:t=null,uiManager:e=null}){y(this,yt);y(this,Js,null);y(this,To,null);y(this,Ka);y(this,Zt,null);y(this,fc,!1);y(this,Qa,!1);y(this,gc,null);y(this,pc);y(this,nr,null);y(this,Zs,null);y(this,Ja);var s;t?(m(this,Qa,!1),m(this,Ja,at.HIGHLIGHT_COLOR),m(this,gc,t)):(m(this,Qa,!0),m(this,Ja,at.HIGHLIGHT_DEFAULT_COLOR)),m(this,Zs,(t==null?void 0:t._uiManager)||e),m(this,pc,l(this,Zs)._eventBus),m(this,Ka,(t==null?void 0:t.color)||((s=l(this,Zs))==null?void 0:s.highlightColors.values().next().value)||"#FFFF98"),l(Ke,mc)||m(Ke,mc,Object.freeze({blue:"pdfjs-editor-colorpicker-blue",green:"pdfjs-editor-colorpicker-green",pink:"pdfjs-editor-colorpicker-pink",red:"pdfjs-editor-colorpicker-red",yellow:"pdfjs-editor-colorpicker-yellow"}))}static get _keyboardManager(){return it(this,"_keyboardManager",new Wh([[["Escape","mac+Escape"],Ke.prototype._hideDropdownFromKeyboard],[[" ","mac+ "],Ke.prototype._colorSelectFromKeyboard],[["ArrowDown","ArrowRight","mac+ArrowDown","mac+ArrowRight"],Ke.prototype._moveToNext],[["ArrowUp","ArrowLeft","mac+ArrowUp","mac+ArrowLeft"],Ke.prototype._moveToPrevious],[["Home","mac+Home"],Ke.prototype._moveToBeginning],[["End","mac+End"],Ke.prototype._moveToEnd]]))}renderButton(){const t=m(this,Js,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=l(this,Zs)._signal;t.addEventListener("click",w(this,yt,Go).bind(this),{signal:e}),t.addEventListener("keydown",w(this,yt,Dp).bind(this),{signal:e});const s=m(this,To,document.createElement("span"));return s.className="swatch",s.setAttribute("aria-hidden",!0),s.style.backgroundColor=l(this,Ka),t.append(s),t}renderMainDropdown(){const t=m(this,Zt,w(this,yt,Mp).call(this));return t.setAttribute("aria-orientation","horizontal"),t.setAttribute("aria-labelledby","highlightColorPickerLabel"),t}_colorSelectFromKeyboard(t){if(t.target===l(this,Js)){w(this,yt,Go).call(this,t);return}const e=t.target.getAttribute("data-color");e&&w(this,yt,Pp).call(this,e,t)}_moveToNext(t){var e,s;if(!l(this,yt,gr)){w(this,yt,Go).call(this,t);return}if(t.target===l(this,Js)){(e=l(this,Zt).firstChild)==null||e.focus();return}(s=t.target.nextSibling)==null||s.focus()}_moveToPrevious(t){var e,s;if(t.target===((e=l(this,Zt))==null?void 0:e.firstChild)||t.target===l(this,Js)){l(this,yt,gr)&&this._hideDropdownFromKeyboard();return}l(this,yt,gr)||w(this,yt,Go).call(this,t),(s=t.target.previousSibling)==null||s.focus()}_moveToBeginning(t){var e;if(!l(this,yt,gr)){w(this,yt,Go).call(this,t);return}(e=l(this,Zt).firstChild)==null||e.focus()}_moveToEnd(t){var e;if(!l(this,yt,gr)){w(this,yt,Go).call(this,t);return}(e=l(this,Zt).lastChild)==null||e.focus()}hideDropdown(){var t,e;(t=l(this,Zt))==null||t.classList.add("hidden"),(e=l(this,nr))==null||e.abort(),m(this,nr,null)}_hideDropdownFromKeyboard(){var t;if(!l(this,Qa)){if(!l(this,yt,gr)){(t=l(this,gc))==null||t.unselect();return}this.hideDropdown(),l(this,Js).focus({preventScroll:!0,focusVisible:l(this,fc)})}}updateColor(t){if(l(this,To)&&(l(this,To).style.backgroundColor=t),!l(this,Zt))return;const e=l(this,Zs).highlightColors.values();for(const s of l(this,Zt).children)s.setAttribute("aria-selected",e.next().value===t)}destroy(){var t,e;(t=l(this,Js))==null||t.remove(),m(this,Js,null),m(this,To,null),(e=l(this,Zt))==null||e.remove(),m(this,Zt,null)}};Js=new WeakMap,To=new WeakMap,Ka=new WeakMap,Zt=new WeakMap,fc=new WeakMap,Qa=new WeakMap,gc=new WeakMap,pc=new WeakMap,nr=new WeakMap,Zs=new WeakMap,Ja=new WeakMap,mc=new WeakMap,yt=new WeakSet,Mp=function(){const t=document.createElement("div"),e=l(this,Zs)._signal;t.addEventListener("contextmenu",Gs,{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 l(this,Zs).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",l(Ke,mc)[s]);const r=document.createElement("span");n.append(r),r.className="swatch",r.style.backgroundColor=i,n.setAttribute("aria-selected",i===l(this,Ka)),n.addEventListener("click",w(this,yt,Pp).bind(this,i),{signal:e}),t.append(n)}return t.addEventListener("keydown",w(this,yt,Dp).bind(this),{signal:e}),t},Pp=function(t,e){e.stopPropagation(),l(this,pc).dispatch("switchannotationeditorparams",{source:this,type:l(this,Ja),value:t})},Dp=function(t){Ke._keyboardManager.exec(this,t)},Go=function(t){if(l(this,yt,gr)){this.hideDropdown();return}if(m(this,fc,t.detail===0),l(this,nr)||(m(this,nr,new AbortController),window.addEventListener("pointerdown",w(this,yt,Jy).bind(this),{signal:l(this,Zs).combinedSignal(l(this,nr))})),l(this,Zt)){l(this,Zt).classList.remove("hidden");return}const e=m(this,Zt,w(this,yt,Mp).call(this));l(this,Js).append(e)},Jy=function(t){var e;(e=l(this,Zt))!=null&&e.contains(t.target)||this.hideDropdown()},gr=function(){return l(this,Zt)&&!l(this,Zt).classList.contains("hidden")},y(Ke,mc,null);let rd=Ke;const ut=class ut extends Pt{constructor(e){super({...e,name:"highlightEditor"});y(this,Z);y(this,Za,null);y(this,bc,0);y(this,mn);y(this,Eo,null);y(this,th,null);y(this,Qe,null);y(this,yc,null);y(this,vc,0);y(this,ko,null);y(this,Ts,null);y(this,ds,null);y(this,le,!1);y(this,eh,null);y(this,bn);y(this,Se,null);y(this,sh,"");y(this,Es);y(this,_c,"");this.color=e.color||ut._defaultColor,m(this,Es,e.thickness||ut._defaultThickness),m(this,bn,e.opacity||ut._defaultOpacity),m(this,mn,e.boxes||null),m(this,_c,e.methodOfCreation||""),m(this,sh,e.text||""),this._isDraggable=!1,e.highlightId>-1?(m(this,le,!0),w(this,Z,qd).call(this,e),w(this,Z,zo).call(this)):l(this,mn)&&(m(this,Za,e.anchorNode),m(this,bc,e.anchorOffset),m(this,yc,e.focusNode),m(this,vc,e.focusOffset),w(this,Z,Op).call(this),w(this,Z,zo).call(this),this.rotate(this.rotation))}static get _keyboardManager(){const e=ut.prototype;return it(this,"_keyboardManager",new Wh([[["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:l(this,le)?"free_highlight":"highlight",color:this._uiManager.highlightColorNames.get(this.color),thickness:l(this,Es),methodOfCreation:l(this,_c)}}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;Pt.initialize(e,s),ut._defaultColor||(ut._defaultColor=((i=s.highlightColors)==null?void 0:i.values().next().value)||"#fff066")}static updateDefaultParams(e,s){switch(e){case at.HIGHLIGHT_DEFAULT_COLOR:ut._defaultColor=s;break;case at.HIGHLIGHT_THICKNESS:ut._defaultThickness=s;break}}translateInPage(e,s){}get toolbarPosition(){return l(this,eh)}updateParams(e,s){switch(e){case at.HIGHLIGHT_COLOR:w(this,Z,Zy).call(this,s);break;case at.HIGHLIGHT_THICKNESS:w(this,Z,tv).call(this,s);break}}static get defaultPropertiesToUpdate(){return[[at.HIGHLIGHT_DEFAULT_COLOR,ut._defaultColor],[at.HIGHLIGHT_THICKNESS,ut._defaultThickness]]}get propertiesToUpdate(){return[[at.HIGHLIGHT_COLOR,this.color||ut._defaultColor],[at.HIGHLIGHT_THICKNESS,l(this,Es)||ut._defaultThickness],[at.HIGHLIGHT_FREE,l(this,le)]]}async addEditToolbar(){const e=await super.addEditToolbar();return e?(this._uiManager.highlightColors&&(m(this,th,new rd({editor:this})),e.addColorPicker(l(this,th))),e):null}disableEditing(){super.disableEditing(),this.div.classList.toggle("disabled",!0)}enableEditing(){super.enableEditing(),this.div.classList.toggle("disabled",!1)}fixAndSetPosition(){return super.fixAndSetPosition(w(this,Z,Lc).call(this))}getBaseTranslation(){return[0,0]}getRect(e,s){return super.getRect(e,s,w(this,Z,Lc).call(this))}onceAdded(e){this.annotationElementId||this.parent.addUndoableEditor(this),e&&this.div.focus()}remove(){w(this,Z,Rp).call(this),this._reportTelemetry({action:"deleted"}),super.remove()}rebuild(){this.parent&&(super.rebuild(),this.div!==null&&(w(this,Z,zo).call(this),this.isAttachedToDOM||this.parent.add(this)))}setParent(e){var i;let s=!1;this.parent&&!e?w(this,Z,Rp).call(this):e&&(w(this,Z,zo).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;l(this,le)?(e=(e-this.rotation+360)%360,i=w(n=ut,ks,_h).call(n,l(this,Ts).box,e)):i=w(r=ut,ks,_h).call(r,[this.x,this.y,this.width,this.height],e),s.updateProperties(l(this,ds),{bbox:i,root:{"data-main-rotation":e}}),s.updateProperties(l(this,Se),{bbox:w(o=ut,ks,_h).call(o,l(this,Qe).box,e),root:{"data-main-rotation":e}})}render(){if(this.div)return this.div;const e=super.render();l(this,sh)&&(e.setAttribute("aria-label",l(this,sh)),e.setAttribute("role","mark")),l(this,le)?e.classList.add("free"):this.div.addEventListener("keydown",w(this,Z,sv).bind(this),{signal:this._uiManager._signal});const s=m(this,ko,document.createElement("div"));e.append(s),s.setAttribute("aria-hidden","true"),s.className="internal",s.style.clipPath=l(this,Eo);const[i,n]=this.parentDimensions;return this.setDims(this.width*i,this.height*n),qu(this,l(this,ko),["pointerover","pointerleave"]),this.enableEditing(),e}pointerover(){var e;this.isSelected||(e=this.parent)==null||e.drawLayer.updateProperties(l(this,Se),{rootClass:{hovered:!0}})}pointerleave(){var e;this.isSelected||(e=this.parent)==null||e.drawLayer.updateProperties(l(this,Se),{rootClass:{hovered:!1}})}_moveCaret(e){switch(this.parent.unselect(this),e){case 0:case 2:w(this,Z,Kd).call(this,!0);break;case 1:case 3:w(this,Z,Kd).call(this,!1);break}}select(){var e;super.select(),l(this,Se)&&((e=this.parent)==null||e.drawLayer.updateProperties(l(this,Se),{rootClass:{hovered:!1,selected:!0}}))}unselect(){var e;super.unselect(),l(this,Se)&&((e=this.parent)==null||e.drawLayer.updateProperties(l(this,Se),{rootClass:{selected:!1}}),l(this,le)||w(this,Z,Kd).call(this,!1))}get _mustFixPosition(){return!l(this,le)}show(e=this._isVisible){super.show(e),this.parent&&(this.parent.drawLayer.updateProperties(l(this,ds),{rootClass:{hidden:!e}}),this.parent.drawLayer.updateProperties(l(this,Se),{rootClass:{hidden:!e}}))}static startHighlighting(e,s,{target:i,x:n,y:r}){const{x:o,y:h,width:c,height:u}=i.getBoundingClientRect(),d=new AbortController,f=e.combinedSignal(d),g=p=>{d.abort(),w(this,ks,ov).call(this,e,p)};window.addEventListener("blur",g,{signal:f}),window.addEventListener("pointerup",g,{signal:f}),window.addEventListener("pointerdown",es,{capture:!0,passive:!1,signal:f}),window.addEventListener("contextmenu",Gs,{signal:f}),i.addEventListener("pointermove",w(this,ks,rv).bind(this,e),{signal:f}),this._freeHighlight=new Ig({x:n,y:r},[o,h,c,u],e.scale,this._defaultThickness/2,s,.001),{id:this._freeHighlightId,clipPathId:this._freeHighlightClipId}=e.drawLayer.draw({bbox:[0,0,1,1],root:{viewBox:"0 0 1 1",fill:this._defaultColor,"fill-opacity":this._defaultOpacity},rootClass:{highlight:!0,free:!0},path:{d:this._freeHighlight.toSVGPath()}},!0,!0)}static async deserialize(e,s,i){var b,_,v,x;let n=null;if(e instanceof Hb){const{data:{quadPoints:C,rect:S,rotation:E,id:k,color:M,opacity:D,popupRef:R},parent:{page:{pageNumber:B}}}=e;n=e={annotationType:tt.HIGHLIGHT,color:Array.from(M),opacity:D,quadPoints:C,boxes:null,pageIndex:B-1,rect:S.slice(0),rotation:E,id:k,deleted:!1,popupRef:R}}else if(e instanceof Rg){const{data:{inkLists:C,rect:S,rotation:E,id:k,color:M,borderStyle:{rawWidth:D},popupRef:R},parent:{page:{pageNumber:B}}}=e;n=e={annotationType:tt.HIGHLIGHT,color:Array.from(M),thickness:D,inkLists:C,boxes:null,pageIndex:B-1,rect:S.slice(0),rotation:E,id:k,deleted:!1,popupRef:R}}const{color:r,quadPoints:o,inkLists:h,opacity:c}=e,u=await super.deserialize(e,s,i);u.color=U.makeHexColor(...r),m(u,bn,c||1),h&&m(u,Es,e.thickness),u.annotationElementId=e.id||null,u._initialData=n;const[d,f]=u.pageDimensions,[g,p]=u.pageTranslation;if(o){const C=m(u,mn,[]);for(let S=0;S<o.length;S+=8)C.push({x:(o[S]-g)/d,y:1-(o[S+1]-p)/f,width:(o[S+2]-o[S])/d,height:(o[S+1]-o[S+5])/f});w(b=u,Z,Op).call(b),w(_=u,Z,zo).call(_),u.rotate(u.rotation)}else if(h){m(u,le,!0);const C=h[0],S={x:C[0]-g,y:f-(C[1]-p)},E=new Ig(S,[0,0,d,f],1,l(u,Es)/2,!0,.001);for(let D=0,R=C.length;D<R;D+=2)S.x=C[D]-g,S.y=f-(C[D+1]-p),E.add(S);const{id:k,clipPathId:M}=s.drawLayer.draw({bbox:[0,0,1,1],root:{viewBox:"0 0 1 1",fill:u.color,"fill-opacity":u._defaultOpacity},rootClass:{highlight:!0,free:!0},path:{d:E.toSVGPath()}},!0,!0);w(v=u,Z,qd).call(v,{highlightOutlines:E.getOutlines(),highlightId:k,clipPathId:M}),w(x=u,Z,zo).call(x)}return u}serialize(e=!1){if(this.isEmpty()||e)return null;if(this.deleted)return this.serializeDeleted();const s=this.getRect(0,0),i=Pt._colorManager.convert(this.color),n={annotationType:tt.HIGHLIGHT,color:i,opacity:l(this,bn),thickness:l(this,Es),quadPoints:w(this,Z,iv).call(this),outlines:w(this,Z,nv).call(this,s),pageIndex:this.pageIndex,rect:s,rotation:w(this,Z,Lc).call(this),structTreeParentId:this._structTreeParentId};return this.annotationElementId&&!w(this,Z,av).call(this,n)?null:(n.id=this.annotationElementId,n)}renderAnnotationElement(e){return e.updateEdited({rect:this.getRect(0,0)}),null}static canCreateNewEmptyEditor(){return!1}};Za=new WeakMap,bc=new WeakMap,mn=new WeakMap,Eo=new WeakMap,th=new WeakMap,Qe=new WeakMap,yc=new WeakMap,vc=new WeakMap,ko=new WeakMap,Ts=new WeakMap,ds=new WeakMap,le=new WeakMap,eh=new WeakMap,bn=new WeakMap,Se=new WeakMap,sh=new WeakMap,Es=new WeakMap,_c=new WeakMap,Z=new WeakSet,Op=function(){const e=new Fg(l(this,mn),.001);m(this,Ts,e.getOutlines()),[this.x,this.y,this.width,this.height]=l(this,Ts).box;const s=new Fg(l(this,mn),.0025,.001,this._uiManager.direction==="ltr");m(this,Qe,s.getOutlines());const{lastPoint:i}=l(this,Qe);m(this,eh,[(i[0]-this.x)/this.width,(i[1]-this.y)/this.height])},qd=function({highlightOutlines:e,highlightId:s,clipPathId:i}){var d,f;if(m(this,Ts,e),m(this,Qe,e.getNewOutline(l(this,Es)/2+1.5,.0025)),s>=0)m(this,ds,s),m(this,Eo,i),this.parent.drawLayer.finalizeDraw(s,{bbox:e.box,path:{d:e.toSVGPath()}}),m(this,Se,this.parent.drawLayer.drawOutline({rootClass:{highlightOutline:!0,free:!0},bbox:l(this,Qe).box,path:{d:l(this,Qe).toSVGPath()}},!0));else if(this.parent){const g=this.parent.viewport.rotation;this.parent.drawLayer.updateProperties(l(this,ds),{bbox:w(d=ut,ks,_h).call(d,l(this,Ts).box,(g-this.rotation+360)%360),path:{d:e.toSVGPath()}}),this.parent.drawLayer.updateProperties(l(this,Se),{bbox:w(f=ut,ks,_h).call(f,l(this,Qe).box,g),path:{d:l(this,Qe).toSVGPath()}})}const[r,o,h,c]=e.box;switch(this.rotation){case 0:this.x=r,this.y=o,this.width=h,this.height=c;break;case 90:{const[g,p]=this.parentDimensions;this.x=o,this.y=1-r,this.width=h*p/g,this.height=c*g/p;break}case 180:this.x=1-r,this.y=1-o,this.width=h,this.height=c;break;case 270:{const[g,p]=this.parentDimensions;this.x=1-o,this.y=r,this.width=h*p/g,this.height=c*g/p;break}}const{lastPoint:u}=l(this,Qe);m(this,eh,[(u[0]-r)/h,(u[1]-o)/c])},Zy=function(e){const s=(r,o)=>{var h,c;this.color=r,m(this,bn,o),(h=this.parent)==null||h.drawLayer.updateProperties(l(this,ds),{root:{fill:r,"fill-opacity":o}}),(c=l(this,th))==null||c.updateColor(r)},i=this.color,n=l(this,bn);this.addCommands({cmd:s.bind(this,e,ut._defaultOpacity),undo:s.bind(this,i,n),post:this._uiManager.updateUI.bind(this._uiManager,this),mustExec:!0,type:at.HIGHLIGHT_COLOR,overwriteIfSameType:!0,keepUndo:!0}),this._reportTelemetry({action:"color_changed",color:this._uiManager.highlightColorNames.get(e)},!0)},tv=function(e){const s=l(this,Es),i=n=>{m(this,Es,n),w(this,Z,ev).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:at.INK_THICKNESS,overwriteIfSameType:!0,keepUndo:!0}),this._reportTelemetry({action:"thickness_changed",thickness:e},!0)},ev=function(e){if(!l(this,le))return;w(this,Z,qd).call(this,{highlightOutlines:l(this,Ts).getNewOutline(e/2)}),this.fixAndSetPosition();const[s,i]=this.parentDimensions;this.setDims(this.width*s,this.height*i)},Rp=function(){l(this,ds)===null||!this.parent||(this.parent.drawLayer.remove(l(this,ds)),m(this,ds,null),this.parent.drawLayer.remove(l(this,Se)),m(this,Se,null))},zo=function(e=this.parent){l(this,ds)===null&&({id:Ge(this,ds)._,clipPathId:Ge(this,Eo)._}=e.drawLayer.draw({bbox:l(this,Ts).box,root:{viewBox:"0 0 1 1",fill:this.color,"fill-opacity":l(this,bn)},rootClass:{highlight:!0,free:l(this,le)},path:{d:l(this,Ts).toSVGPath()}},!1,!0),m(this,Se,e.drawLayer.drawOutline({rootClass:{highlightOutline:!0,free:l(this,le)},bbox:l(this,Qe).box,path:{d:l(this,Qe).toSVGPath()}},l(this,le))),l(this,ko)&&(l(this,ko).style.clipPath=l(this,Eo)))},ks=new WeakSet,_h=function([e,s,i,n],r){switch(r){case 90:return[1-s-n,e,n,i];case 180:return[1-e-i,1-s-n,i,n];case 270:return[s,1-e-i,n,i]}return[e,s,i,n]},sv=function(e){ut._keyboardManager.exec(this,e)},Kd=function(e){if(!l(this,Za))return;const s=window.getSelection();e?s.setPosition(l(this,Za),l(this,bc)):s.setPosition(l(this,yc),l(this,vc))},Lc=function(){return l(this,le)?this.rotation:0},iv=function(){if(l(this,le))return null;const[e,s]=this.pageDimensions,[i,n]=this.pageTranslation,r=l(this,mn),o=new Float32Array(r.length*8);let h=0;for(const{x:c,y:u,width:d,height:f}of r){const g=c*e+i,p=(1-u)*s+n;o[h]=o[h+4]=g,o[h+1]=o[h+3]=p,o[h+2]=o[h+6]=g+d*e,o[h+5]=o[h+7]=p-f*s,h+=8}return o},nv=function(e){return l(this,Ts).serialize(e,w(this,Z,Lc).call(this))},rv=function(e,s){this._freeHighlight.add(s)&&e.drawLayer.updateProperties(this._freeHighlightId,{path:{d:this._freeHighlight.toSVGPath()}})},ov=function(e,s){this._freeHighlight.isEmpty()?e.drawLayer.remove(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=""},av=function(e){const{color:s}=this._initialData;return e.color.some((i,n)=>i!==s[n])},y(ut,ks),q(ut,"_defaultColor",null),q(ut,"_defaultOpacity",1),q(ut,"_defaultThickness",12),q(ut,"_type","highlight"),q(ut,"_editorType",tt.HIGHLIGHT),q(ut,"_freeHighlightId",-1),q(ut,"_freeHighlight",null),q(ut,"_freeHighlightClipId","");let od=ut;class oC{constructor(){y(this,Mo,Object.create(null))}updateProperty(t,e){this[t]=e,this.updateSVGProperty(t,e)}updateProperties(t){if(t)for(const[e,s]of Object.entries(t))this.updateProperty(e,s)}updateSVGProperty(t,e){l(this,Mo)[t]=e}toSVGProperties(){const t=l(this,Mo);return m(this,Mo,Object.create(null)),{root:t}}reset(){m(this,Mo,Object.create(null))}updateAll(t=this){this.updateProperties(t)}clone(){vt("Not implemented")}}Mo=new WeakMap;const V=class V extends Pt{constructor(e){super(e);y(this,lt);y(this,fs,null);y(this,ih);q(this,"_drawId",null);m(this,ih,e.mustBeCommitted||!1),e.drawOutlines&&(w(this,lt,Lp).call(this,e),w(this,lt,Fc).call(this))}static _mergeSVGProperties(e,s){const i=new Set(Object.keys(e));for(const[n,r]of Object.entries(s))i.has(n)?Object.assign(e[n],r):e[n]=r;return e}static getDefaultDrawingOptions(e){vt("Not implemented")}static get typesMap(){vt("Not implemented")}static get isDrawer(){return!0}static get supportMultipleDrawings(){return!1}static updateDefaultParams(e,s){const i=this.typesMap.get(e);i&&this._defaultDrawingOptions.updateProperty(i,s),this._currentParent&&(l(V,ne).updateProperty(i,s),this._currentParent.drawLayer.updateProperties(this._currentDrawId,this._defaultDrawingOptions.toSVGProperties()))}updateParams(e,s){const i=this.constructor.typesMap.get(e);i&&this._updateProperty(e,i,s)}static get defaultPropertiesToUpdate(){const e=[],s=this._defaultDrawingOptions;for(const[i,n]of this.typesMap)e.push([i,s[n]]);return e}get propertiesToUpdate(){const e=[],{_drawingOptions:s}=this;for(const[i,n]of this.constructor.typesMap)e.push([i,s[n]]);return e}_updateProperty(e,s,i){const n=this._drawingOptions,r=n[s],o=h=>{var u;n.updateProperty(s,h);const c=l(this,fs).updateProperty(s,h);c&&w(this,lt,Ic).call(this,c),(u=this.parent)==null||u.drawLayer.updateProperties(this._drawId,n.toSVGProperties())};this.addCommands({cmd:o.bind(this,i),undo:o.bind(this,r),post:this._uiManager.updateUI.bind(this._uiManager,this),mustExec:!0,type:e,overwriteIfSameType:!0,keepUndo:!0})}_onResizing(){var e;(e=this.parent)==null||e.drawLayer.updateProperties(this._drawId,V._mergeSVGProperties(l(this,fs).getPathResizingSVGProperties(w(this,lt,Qd).call(this)),{bbox:w(this,lt,wh).call(this)}))}_onResized(){var e;(e=this.parent)==null||e.drawLayer.updateProperties(this._drawId,V._mergeSVGProperties(l(this,fs).getPathResizedSVGProperties(w(this,lt,Qd).call(this)),{bbox:w(this,lt,wh).call(this)}))}_onTranslating(e,s){var i;(i=this.parent)==null||i.drawLayer.updateProperties(this._drawId,{bbox:w(this,lt,wh).call(this,e,s)})}_onTranslated(){var e;(e=this.parent)==null||e.drawLayer.updateProperties(this._drawId,V._mergeSVGProperties(l(this,fs).getPathTranslatedSVGProperties(w(this,lt,Qd).call(this),this.parentDimensions),{bbox:w(this,lt,wh).call(this)}))}_onStartDragging(){var e;(e=this.parent)==null||e.drawLayer.updateProperties(this._drawId,{rootClass:{moving:!0}})}_onStopDragging(){var e;(e=this.parent)==null||e.drawLayer.updateProperties(this._drawId,{rootClass:{moving:!1}})}commit(){super.commit(),this.disableEditMode(),this.disableEditing()}disableEditing(){super.disableEditing(),this.div.classList.toggle("disabled",!0)}enableEditing(){super.enableEditing(),this.div.classList.toggle("disabled",!1)}getBaseTranslation(){return[0,0]}get isResizable(){return!0}onceAdded(e){this.annotationElementId||this.parent.addUndoableEditor(this),this._isDraggable=!0,l(this,ih)&&(m(this,ih,!1),this.commit(),this.parent.setSelected(this),e&&this.isOnScreen&&this.div.focus())}remove(){w(this,lt,Ip).call(this),super.remove()}rebuild(){this.parent&&(super.rebuild(),this.div!==null&&(w(this,lt,Fc).call(this),w(this,lt,Ic).call(this,l(this,fs).box),this.isAttachedToDOM||this.parent.add(this)))}setParent(e){var i;let s=!1;this.parent&&!e?(this._uiManager.removeShouldRescale(this),w(this,lt,Ip).call(this)):e&&(this._uiManager.addShouldRescale(this),w(this,lt,Fc).call(this,e),s=!this.parent&&((i=this.div)==null?void 0:i.classList.contains("selectedEditor"))),super.setParent(e),s&&this.select()}rotate(){this.parent&&this.parent.drawLayer.updateProperties(this._drawId,V._mergeSVGProperties({bbox:w(this,lt,wh).call(this)},l(this,fs).updateRotation((this.parentRotation-this.rotation+360)%360)))}onScaleChanging(){this.parent&&w(this,lt,Ic).call(this,l(this,fs).updateParentDimensions(this.parentDimensions,this.parent.scale))}static onScaleChangingWhenDrawing(){}render(){if(this.div)return this.div;const e=super.render();e.classList.add("draw");const s=document.createElement("div");e.append(s),s.setAttribute("aria-hidden","true"),s.className="internal";const[i,n]=this.parentDimensions;return this.setDims(this.width*i,this.height*n),this._uiManager.addShouldRescale(this),this.disableEditing(),e}static createDrawerInstance(e,s,i,n,r){vt("Not implemented")}static startDrawing(e,s,i,n){var _;const{target:r,offsetX:o,offsetY:h,pointerId:c,pointerType:u}=n;if(l(V,or)&&l(V,or)!==u)return;const{viewport:{rotation:d}}=e,{width:f,height:g}=r.getBoundingClientRect(),p=m(V,Po,new AbortController),b=e.combinedSignal(p);if(l(V,rr)||m(V,rr,c),l(V,or)??m(V,or,u),window.addEventListener("pointerup",v=>{var x;l(V,rr)===v.pointerId?this._endDraw(v):(x=l(V,ar))==null||x.delete(v.pointerId)},{signal:b}),window.addEventListener("pointercancel",v=>{var x;l(V,rr)===v.pointerId?this._currentParent.endDrawingSession():(x=l(V,ar))==null||x.delete(v.pointerId)},{signal:b}),window.addEventListener("pointerdown",v=>{l(V,or)===v.pointerType&&((l(V,ar)||m(V,ar,new Set)).add(v.pointerId),l(V,ne).isCancellable()&&(l(V,ne).removeLastElement(),l(V,ne).isEmpty()?this._currentParent.endDrawingSession(!0):this._endDraw(null)))},{capture:!0,passive:!1,signal:b}),window.addEventListener("contextmenu",Gs,{signal:b}),r.addEventListener("pointermove",this._drawMove.bind(this),{signal:b}),r.addEventListener("touchmove",v=>{v.timeStamp===l(V,Oo)&&es(v)},{signal:b}),e.toggleDrawing(),(_=s._editorUndoBar)==null||_.hide(),l(V,ne)){e.drawLayer.updateProperties(this._currentDrawId,l(V,ne).startNew(o,h,f,g,d));return}s.updateUIForDefaultProperties(this),m(V,ne,this.createDrawerInstance(o,h,f,g,d)),m(V,Do,this.getDefaultDrawingOptions()),this._currentParent=e,{id:this._currentDrawId}=e.drawLayer.draw(this._mergeSVGProperties(l(V,Do).toSVGProperties(),l(V,ne).defaultSVGProperties),!0,!1)}static _drawMove(e){var r;if(m(V,Oo,-1),!l(V,ne))return;const{offsetX:s,offsetY:i,pointerId:n}=e;if(l(V,rr)===n){if(((r=l(V,ar))==null?void 0:r.size)>=1){this._endDraw(e);return}this._currentParent.drawLayer.updateProperties(this._currentDrawId,l(V,ne).add(s,i)),m(V,Oo,e.timeStamp),es(e)}}static _cleanup(e){e&&(this._currentDrawId=-1,this._currentParent=null,m(V,ne,null),m(V,Do,null),m(V,or,null),m(V,Oo,NaN)),l(V,Po)&&(l(V,Po).abort(),m(V,Po,null),m(V,rr,NaN),m(V,ar,null))}static _endDraw(e){const s=this._currentParent;if(s){if(s.toggleDrawing(!0),this._cleanup(!1),e&&s.drawLayer.updateProperties(this._currentDrawId,l(V,ne).end(e.offsetX,e.offsetY)),this.supportMultipleDrawings){const i=l(V,ne),n=this._currentDrawId,r=i.getLastElement();s.addCommands({cmd:()=>{s.drawLayer.updateProperties(n,i.setLastElement(r))},undo:()=>{s.drawLayer.updateProperties(n,i.removeLastElement())},mustExec:!1,type:at.DRAW_STEP});return}this.endDrawing(!1)}}static endDrawing(e){const s=this._currentParent;if(!s)return null;if(s.toggleDrawing(!0),s.cleanUndoStack(at.DRAW_STEP),!l(V,ne).isEmpty()){const{pageDimensions:[i,n],scale:r}=s,o=s.createAndAddNewEditor({offsetX:0,offsetY:0},!1,{drawId:this._currentDrawId,drawOutlines:l(V,ne).getOutlines(i*r,n*r,r,this._INNER_MARGIN),drawingOptions:l(V,Do),mustBeCommitted:!e});return this._cleanup(!0),o}return s.drawLayer.remove(this._currentDrawId),this._cleanup(!0),null}createDrawingOptions(e){}static deserializeDraw(e,s,i,n,r,o){vt("Not implemented")}static async deserialize(e,s,i){var d,f;const{rawDims:{pageWidth:n,pageHeight:r,pageX:o,pageY:h}}=s.viewport,c=this.deserializeDraw(o,h,n,r,this._INNER_MARGIN,e),u=await super.deserialize(e,s,i);return u.createDrawingOptions(e),w(d=u,lt,Lp).call(d,{drawOutlines:c}),w(f=u,lt,Fc).call(f),u.onScaleChanging(),u.rotate(),u}serializeDraw(e){const[s,i]=this.pageTranslation,[n,r]=this.pageDimensions;return l(this,fs).serialize([s,i,n,r],e)}renderAnnotationElement(e){return e.updateEdited({rect:this.getRect(0,0)}),null}static canCreateNewEmptyEditor(){return!1}};fs=new WeakMap,ih=new WeakMap,ne=new WeakMap,Po=new WeakMap,Do=new WeakMap,rr=new WeakMap,or=new WeakMap,ar=new WeakMap,Oo=new WeakMap,lt=new WeakSet,Lp=function({drawOutlines:e,drawId:s,drawingOptions:i}){m(this,fs,e),this._drawingOptions||(this._drawingOptions=i),s>=0?(this._drawId=s,this.parent.drawLayer.finalizeDraw(s,e.defaultProperties)):this._drawId=w(this,lt,Fp).call(this,e,this.parent),w(this,lt,Ic).call(this,e.box)},Fp=function(e,s){const{id:i}=s.drawLayer.draw(V._mergeSVGProperties(this._drawingOptions.toSVGProperties(),e.defaultSVGProperties),!1,!1);return i},Ip=function(){this._drawId===null||!this.parent||(this.parent.drawLayer.remove(this._drawId),this._drawId=null,this._drawingOptions.reset())},Fc=function(e=this.parent){if(!(this._drawId!==null&&this.parent===e)){if(this._drawId!==null){this.parent.drawLayer.updateParent(this._drawId,e.drawLayer);return}this._drawingOptions.updateAll(),this._drawId=w(this,lt,Fp).call(this,l(this,fs),e)}},hv=function([e,s,i,n]){const{parentDimensions:[r,o],rotation:h}=this;switch(h){case 90:return[s,1-e,i*(o/r),n*(r/o)];case 180:return[1-e,1-s,i,n];case 270:return[1-s,e,i*(o/r),n*(r/o)];default:return[e,s,i,n]}},Qd=function(){const{x:e,y:s,width:i,height:n,parentDimensions:[r,o],rotation:h}=this;switch(h){case 90:return[1-s,e,i*(r/o),n*(o/r)];case 180:return[1-e,1-s,i,n];case 270:return[s,1-e,i*(r/o),n*(o/r)];default:return[e,s,i,n]}},Ic=function(e){if([this.x,this.y,this.width,this.height]=w(this,lt,hv).call(this,e),this.div){this.fixAndSetPosition();const[s,i]=this.parentDimensions;this.setDims(this.width*s,this.height*i)}this._onResized()},wh=function(){const{x:e,y:s,width:i,height:n,rotation:r,parentRotation:o,parentDimensions:[h,c]}=this;switch((r*4+o)/90){case 1:return[1-s-n,e,n,i];case 2:return[1-e-i,1-s-n,i,n];case 3:return[s,1-e-i,n,i];case 4:return[e,s-i*(h/c),n*(c/h),i*(h/c)];case 5:return[1-s,e,i*(h/c),n*(c/h)];case 6:return[1-e-n*(c/h),1-s,n*(c/h),i*(h/c)];case 7:return[s-i*(h/c),1-e-n*(c/h),i*(h/c),n*(c/h)];case 8:return[e-i,s-n,i,n];case 9:return[1-s,e-i,n,i];case 10:return[1-e,1-s,i,n];case 11:return[s-n,1-e,n,i];case 12:return[e-n*(c/h),s,n*(c/h),i*(h/c)];case 13:return[1-s-i*(h/c),e-n*(c/h),i*(h/c),n*(c/h)];case 14:return[1-e,1-s-i*(h/c),n*(c/h),i*(h/c)];case 15:return[s,1-e,i*(h/c),n*(c/h)];default:return[e,s,i,n]}},q(V,"_currentDrawId",-1),q(V,"_currentParent",null),y(V,ne,null),y(V,Po,null),y(V,Do,null),y(V,rr,NaN),y(V,or,null),y(V,ar,null),y(V,Oo,NaN),q(V,"_INNER_MARGIN",3);let Ng=V;class aC{constructor(t,e,s,i,n,r){y(this,rh);y(this,xi,new Float64Array(6));y(this,re);y(this,oe);y(this,Ro);y(this,nh);y(this,Ne);y(this,ce,"");y(this,Ms,0);y(this,Lo,new ad);y(this,Fo);y(this,Io);m(this,Fo,s),m(this,Io,i),m(this,Ro,n),m(this,nh,r),[t,e]=w(this,rh,Jd).call(this,t,e);const o=m(this,re,[NaN,NaN,NaN,NaN,t,e]);m(this,Ne,[t,e]),m(this,oe,[{line:o,points:l(this,Ne)}]),l(this,xi).set(o,0)}updateProperty(t,e){t==="stroke-width"&&m(this,nh,e)}isEmpty(){return!l(this,oe)||l(this,oe).length===0}isCancellable(){return l(this,Ne).length<=10}add(t,e){[t,e]=w(this,rh,Jd).call(this,t,e);const[s,i,n,r]=l(this,xi).subarray(2,6),o=t-n,h=e-r;return Math.hypot(l(this,Fo)*o,l(this,Io)*h)<=2?null:(l(this,Ne).push(t,e),isNaN(s)?(l(this,xi).set([n,r,t,e],2),l(this,re).push(NaN,NaN,NaN,NaN,t,e),{path:{d:this.toSVGPath()}}):(isNaN(l(this,xi)[0])&&l(this,re).splice(6,6),l(this,xi).set([s,i,n,r,t,e],0),l(this,re).push(...z.createBezierPoints(s,i,n,r,t,e)),{path:{d:this.toSVGPath()}}))}end(t,e){const s=this.add(t,e);return s||(l(this,Ne).length===2?{path:{d:this.toSVGPath()}}:null)}startNew(t,e,s,i,n){m(this,Fo,s),m(this,Io,i),m(this,Ro,n),[t,e]=w(this,rh,Jd).call(this,t,e);const r=m(this,re,[NaN,NaN,NaN,NaN,t,e]);m(this,Ne,[t,e]);const o=l(this,oe).at(-1);return o&&(o.line=new Float32Array(o.line),o.points=new Float32Array(o.points)),l(this,oe).push({line:r,points:l(this,Ne)}),l(this,xi).set(r,0),m(this,Ms,0),this.toSVGPath(),null}getLastElement(){return l(this,oe).at(-1)}setLastElement(t){return l(this,oe)?(l(this,oe).push(t),m(this,re,t.line),m(this,Ne,t.points),m(this,Ms,0),{path:{d:this.toSVGPath()}}):l(this,Lo).setLastElement(t)}removeLastElement(){if(!l(this,oe))return l(this,Lo).removeLastElement();l(this,oe).pop(),m(this,ce,"");for(let t=0,e=l(this,oe).length;t<e;t++){const{line:s,points:i}=l(this,oe)[t];m(this,re,s),m(this,Ne,i),m(this,Ms,0),this.toSVGPath()}return{path:{d:l(this,ce)}}}toSVGPath(){const t=z.svgRound(l(this,re)[4]),e=z.svgRound(l(this,re)[5]);if(l(this,Ne).length===2)return m(this,ce,`${l(this,ce)} M ${t} ${e} Z`),l(this,ce);if(l(this,Ne).length<=6){const i=l(this,ce).lastIndexOf("M");m(this,ce,`${l(this,ce).slice(0,i)} M ${t} ${e}`),m(this,Ms,6)}if(l(this,Ne).length===4){const i=z.svgRound(l(this,re)[10]),n=z.svgRound(l(this,re)[11]);return m(this,ce,`${l(this,ce)} L ${i} ${n}`),m(this,Ms,12),l(this,ce)}const s=[];l(this,Ms)===0&&(s.push(`M ${t} ${e}`),m(this,Ms,6));for(let i=l(this,Ms),n=l(this,re).length;i<n;i+=6){const[r,o,h,c,u,d]=l(this,re).slice(i,i+6).map(z.svgRound);s.push(`C${r} ${o} ${h} ${c} ${u} ${d}`)}return m(this,ce,l(this,ce)+s.join(" ")),m(this,Ms,l(this,re).length),l(this,ce)}getOutlines(t,e,s,i){const n=l(this,oe).at(-1);return n.line=new Float32Array(n.line),n.points=new Float32Array(n.points),l(this,Lo).build(l(this,oe),t,e,s,l(this,Ro),l(this,nh),i),m(this,xi,null),m(this,re,null),m(this,oe,null),m(this,ce,null),l(this,Lo)}get defaultSVGProperties(){return{root:{viewBox:"0 0 10000 10000"},rootClass:{draw:!0},bbox:[0,0,1,1]}}}xi=new WeakMap,re=new WeakMap,oe=new WeakMap,Ro=new WeakMap,nh=new WeakMap,Ne=new WeakMap,ce=new WeakMap,Ms=new WeakMap,Lo=new WeakMap,Fo=new WeakMap,Io=new WeakMap,rh=new WeakSet,Jd=function(t,e){return z._normalizePoint(t,e,l(this,Fo),l(this,Io),l(this,Ro))};const Yg=class Yg extends z{constructor(){super(...arguments);y(this,ue);y(this,je);y(this,wc,0);y(this,xc);y(this,gs);y(this,Si);y(this,Ci);y(this,oh);y(this,ah);y(this,hh)}build(e,s,i,n,r,o,h){m(this,Si,s),m(this,Ci,i),m(this,oh,n),m(this,ah,r),m(this,hh,o),m(this,xc,h??0),m(this,gs,e),w(this,ue,cv).call(this)}setLastElement(e){return l(this,gs).push(e),{path:{d:this.toSVGPath()}}}removeLastElement(){return l(this,gs).pop(),{path:{d:this.toSVGPath()}}}toSVGPath(){const e=[];for(const{line:s}of l(this,gs)){if(e.push(`M${z.svgRound(s[4])} ${z.svgRound(s[5])}`),s.length===6){e.push("Z");continue}if(s.length===12){e.push(`L${z.svgRound(s[10])} ${z.svgRound(s[11])}`);continue}for(let i=6,n=s.length;i<n;i+=6){const[r,o,h,c,u,d]=s.subarray(i,i+6).map(z.svgRound);e.push(`C${r} ${o} ${h} ${c} ${u} ${d}`)}}return e.join("")}serialize([e,s,i,n],r){const o=[],h=[],[c,u,d,f]=w(this,ue,lv).call(this);let g,p,b,_,v,x,C,S,E;switch(l(this,ah)){case 0:E=z._rescale,g=e,p=s+n,b=i,_=-n,v=e+c*i,x=s+(1-u-f)*n,C=e+(c+d)*i,S=s+(1-u)*n;break;case 90:E=z._rescaleAndSwap,g=e,p=s,b=i,_=n,v=e+u*i,x=s+c*n,C=e+(u+f)*i,S=s+(c+d)*n;break;case 180:E=z._rescale,g=e+i,p=s,b=-i,_=n,v=e+(1-c-d)*i,x=s+u*n,C=e+(1-c)*i,S=s+(u+f)*n;break;case 270:E=z._rescaleAndSwap,g=e+i,p=s+n,b=-i,_=-n,v=e+(1-u-f)*i,x=s+(1-c-d)*n,C=e+(1-u)*i,S=s+(1-c)*n;break}for(const{line:k,points:M}of l(this,gs))o.push(E(k,g,p,b,_,r?new Array(k.length):null)),h.push(E(M,g,p,b,_,r?new Array(M.length):null));return{lines:o,points:h,rect:[v,x,C,S]}}static deserialize(e,s,i,n,r,{paths:{lines:o,points:h},rotation:c,thickness:u}){const d=[];let f,g,p,b,_;switch(c){case 0:_=z._rescale,f=-e/i,g=s/n+1,p=1/i,b=-1/n;break;case 90:_=z._rescaleAndSwap,f=-s/n,g=-e/i,p=1/n,b=1/i;break;case 180:_=z._rescale,f=e/i+1,g=-s/n,p=-1/i,b=1/n;break;case 270:_=z._rescaleAndSwap,f=s/n+1,g=e/i+1,p=-1/n,b=-1/i;break}if(!o){o=[];for(const x of h){const C=x.length;if(C===2){o.push(new Float32Array([NaN,NaN,NaN,NaN,x[0],x[1]]));continue}if(C===4){o.push(new Float32Array([NaN,NaN,NaN,NaN,x[0],x[1],NaN,NaN,NaN,NaN,x[2],x[3]]));continue}const S=new Float32Array(3*(C-2));o.push(S);let[E,k,M,D]=x.subarray(0,4);S.set([NaN,NaN,NaN,NaN,E,k],0);for(let R=4;R<C;R+=2){const B=x[R],O=x[R+1];S.set(z.createBezierPoints(E,k,M,D,B,O),(R-2)*3),[E,k,M,D]=[M,D,B,O]}}}for(let x=0,C=o.length;x<C;x++)d.push({line:_(o[x].map(S=>S??NaN),f,g,p,b),points:_(h[x].map(S=>S??NaN),f,g,p,b)});const v=new Yg;return v.build(d,i,n,1,c,u,r),v}get box(){return l(this,je)}updateProperty(e,s){return e==="stroke-width"?w(this,ue,uv).call(this,s):null}updateParentDimensions([e,s],i){const[n,r]=w(this,ue,Sn).call(this);m(this,Si,e),m(this,Ci,s),m(this,oh,i);const[o,h]=w(this,ue,Sn).call(this),c=o-n,u=h-r,d=l(this,je);return d[0]-=c,d[1]-=u,d[2]+=2*c,d[3]+=2*u,d}updateRotation(e){return m(this,wc,e),{path:{transform:this.rotationTransform}}}get viewBox(){return l(this,je).map(z.svgRound).join(" ")}get defaultProperties(){const[e,s]=l(this,je);return{root:{viewBox:this.viewBox},path:{"transform-origin":`${z.svgRound(e)} ${z.svgRound(s)}`}}}get rotationTransform(){const[,,e,s]=l(this,je);let i=0,n=0,r=0,o=0,h=0,c=0;switch(l(this,wc)){case 90:n=s/e,r=-e/s,h=e;break;case 180:i=-1,o=-1,h=e,c=s;break;case 270:n=-s/e,r=e/s,c=s;break;default:return""}return`matrix(${i} ${n} ${r} ${o} ${z.svgRound(h)} ${z.svgRound(c)})`}getPathResizingSVGProperties([e,s,i,n]){const[r,o]=w(this,ue,Sn).call(this),[h,c,u,d]=l(this,je);if(Math.abs(u-r)<=z.PRECISION||Math.abs(d-o)<=z.PRECISION){const _=e+i/2-(h+u/2),v=s+n/2-(c+d/2);return{path:{"transform-origin":`${z.svgRound(e)} ${z.svgRound(s)}`,transform:`${this.rotationTransform} translate(${_} ${v})`}}}const f=(i-2*r)/(u-2*r),g=(n-2*o)/(d-2*o),p=u/i,b=d/n;return{path:{"transform-origin":`${z.svgRound(h)} ${z.svgRound(c)}`,transform:`${this.rotationTransform} scale(${p} ${b}) translate(${z.svgRound(r)} ${z.svgRound(o)}) scale(${f} ${g}) translate(${z.svgRound(-r)} ${z.svgRound(-o)})`}}}getPathResizedSVGProperties([e,s,i,n]){const[r,o]=w(this,ue,Sn).call(this),h=l(this,je),[c,u,d,f]=h;if(h[0]=e,h[1]=s,h[2]=i,h[3]=n,Math.abs(d-r)<=z.PRECISION||Math.abs(f-o)<=z.PRECISION){const v=e+i/2-(c+d/2),x=s+n/2-(u+f/2);for(const{line:C,points:S}of l(this,gs))z._translate(C,v,x,C),z._translate(S,v,x,S);return{root:{viewBox:this.viewBox},path:{"transform-origin":`${z.svgRound(e)} ${z.svgRound(s)}`,transform:this.rotationTransform||null,d:this.toSVGPath()}}}const g=(i-2*r)/(d-2*r),p=(n-2*o)/(f-2*o),b=-g*(c+r)+e+r,_=-p*(u+o)+s+o;if(g!==1||p!==1||b!==0||_!==0)for(const{line:v,points:x}of l(this,gs))z._rescale(v,b,_,g,p,v),z._rescale(x,b,_,g,p,x);return{root:{viewBox:this.viewBox},path:{"transform-origin":`${z.svgRound(e)} ${z.svgRound(s)}`,transform:this.rotationTransform||null,d:this.toSVGPath()}}}getPathTranslatedSVGProperties([e,s],i){const[n,r]=i,o=l(this,je),h=e-o[0],c=s-o[1];if(l(this,Si)===n&&l(this,Ci)===r)for(const{line:u,points:d}of l(this,gs))z._translate(u,h,c,u),z._translate(d,h,c,d);else{const u=l(this,Si)/n,d=l(this,Ci)/r;m(this,Si,n),m(this,Ci,r);for(const{line:f,points:g}of l(this,gs))z._rescale(f,h,c,u,d,f),z._rescale(g,h,c,u,d,g);o[2]*=u,o[3]*=d}return o[0]=e,o[1]=s,{root:{viewBox:this.viewBox},path:{d:this.toSVGPath(),"transform-origin":`${z.svgRound(e)} ${z.svgRound(s)}`}}}get defaultSVGProperties(){const e=l(this,je);return{root:{viewBox:this.viewBox},rootClass:{draw:!0},path:{d:this.toSVGPath(),"transform-origin":`${z.svgRound(e[0])} ${z.svgRound(e[1])}`,transform:this.rotationTransform||null},bbox:e}}};je=new WeakMap,wc=new WeakMap,xc=new WeakMap,gs=new WeakMap,Si=new WeakMap,Ci=new WeakMap,oh=new WeakMap,ah=new WeakMap,hh=new WeakMap,ue=new WeakSet,Sn=function(e=l(this,hh)){const s=l(this,xc)+e/2*l(this,oh);return l(this,ah)%180===0?[s/l(this,Si),s/l(this,Ci)]:[s/l(this,Ci),s/l(this,Si)]},lv=function(){const[e,s,i,n]=l(this,je),[r,o]=w(this,ue,Sn).call(this,0);return[e+r,s+o,i-2*r,n-2*o]},cv=function(){const e=m(this,je,new Float32Array([1/0,1/0,-1/0,-1/0]));for(const{line:n}of l(this,gs)){if(n.length<=12){for(let h=4,c=n.length;h<c;h+=6){const[u,d]=n.subarray(h,h+2);e[0]=Math.min(e[0],u),e[1]=Math.min(e[1],d),e[2]=Math.max(e[2],u),e[3]=Math.max(e[3],d)}continue}let r=n[4],o=n[5];for(let h=6,c=n.length;h<c;h+=6){const[u,d,f,g,p,b]=n.subarray(h,h+6);U.bezierBoundingBox(r,o,u,d,f,g,p,b,e),r=p,o=b}}const[s,i]=w(this,ue,Sn).call(this);e[0]=Math.min(1,Math.max(0,e[0]-s)),e[1]=Math.min(1,Math.max(0,e[1]-i)),e[2]=Math.min(1,Math.max(0,e[2]+s)),e[3]=Math.min(1,Math.max(0,e[3]+i)),e[2]-=e[0],e[3]-=e[1]},uv=function(e){const[s,i]=w(this,ue,Sn).call(this);m(this,hh,e);const[n,r]=w(this,ue,Sn).call(this),[o,h]=[n-s,r-i],c=l(this,je);return c[0]-=o,c[1]-=h,c[2]+=2*o,c[3]+=2*h,c};let ad=Yg;const $g=class $g extends oC{constructor(e){super();y(this,lh);m(this,lh,e),super.updateProperties({fill:"none",stroke:Pt._defaultLineColor,"stroke-opacity":1,"stroke-width":1,"stroke-linecap":"round","stroke-linejoin":"round","stroke-miterlimit":10})}updateSVGProperty(e,s){e==="stroke-width"&&(s??(s=this["stroke-width"]),s*=l(this,lh).realScale),super.updateSVGProperty(e,s)}clone(){const e=new $g(l(this,lh));return e.updateAll(this),e}};lh=new WeakMap;let jg=$g;const ch=class ch extends Ng{constructor(e){super({...e,name:"inkEditor"});y(this,Ad);this._willKeepAspectRatio=!0}static initialize(e,s){Pt.initialize(e,s),this._defaultDrawingOptions=new jg(s.viewParameters)}static getDefaultDrawingOptions(e){const s=this._defaultDrawingOptions.clone();return s.updateProperties(e),s}static get supportMultipleDrawings(){return!0}static get typesMap(){return it(this,"typesMap",new Map([[at.INK_THICKNESS,"stroke-width"],[at.INK_COLOR,"stroke"],[at.INK_OPACITY,"stroke-opacity"]]))}static createDrawerInstance(e,s,i,n,r){return new aC(e,s,i,n,r,this._defaultDrawingOptions["stroke-width"])}static deserializeDraw(e,s,i,n,r,o){return ad.deserialize(e,s,i,n,r,o)}static async deserialize(e,s,i){let n=null;if(e instanceof Rg){const{data:{inkLists:o,rect:h,rotation:c,id:u,color:d,opacity:f,borderStyle:{rawWidth:g},popupRef:p},parent:{page:{pageNumber:b}}}=e;n=e={annotationType:tt.INK,color:Array.from(d),thickness:g,opacity:f,paths:{points:o},boxes:null,pageIndex:b-1,rect:h.slice(0),rotation:c,id:u,deleted:!1,popupRef:p}}const r=await super.deserialize(e,s,i);return r.annotationElementId=e.id||null,r._initialData=n,r}onScaleChanging(){if(!this.parent)return;super.onScaleChanging();const{_drawId:e,_drawingOptions:s,parent:i}=this;s.updateSVGProperty("stroke-width"),i.drawLayer.updateProperties(e,s.toSVGProperties())}static onScaleChangingWhenDrawing(){const e=this._currentParent;e&&(super.onScaleChangingWhenDrawing(),this._defaultDrawingOptions.updateSVGProperty("stroke-width"),e.drawLayer.updateProperties(this._currentDrawId,this._defaultDrawingOptions.toSVGProperties()))}createDrawingOptions({color:e,thickness:s,opacity:i}){this._drawingOptions=ch.getDefaultDrawingOptions({stroke:U.makeHexColor(...e),"stroke-width":s,"stroke-opacity":i})}serialize(e=!1){if(this.isEmpty())return null;if(this.deleted)return this.serializeDeleted();const{lines:s,points:i,rect:n}=this.serializeDraw(e),{_drawingOptions:{stroke:r,"stroke-opacity":o,"stroke-width":h}}=this,c={annotationType:tt.INK,color:Pt._colorManager.convert(r),opacity:o,thickness:h,paths:{lines:s,points:i},pageIndex:this.pageIndex,rect:n,rotation:this.rotation,structTreeParentId:this._structTreeParentId};return e?c:this.annotationElementId&&!w(this,Ad,dv).call(this,c)?null:(c.id=this.annotationElementId,c)}renderAnnotationElement(e){const{points:s,rect:i}=this.serializeDraw(!1);return e.updateEdited({rect:i,thickness:this._drawingOptions["stroke-width"],points:s}),null}};Ad=new WeakSet,dv=function(e){const{color:s,thickness:i,opacity:n,pageIndex:r}=this._initialData;return this._hasBeenMoved||this._hasBeenResized||e.color.some((o,h)=>o!==s[h])||e.thickness!==i||e.opacity!==n||e.pageIndex!==r},q(ch,"_type","ink"),q(ch,"_editorType",tt.INK),q(ch,"_defaultDrawingOptions",null);let Bg=ch;const Sc=class Sc extends Pt{constructor(e){super({...e,name:"stampEditor"});y(this,ct);y(this,Ot,null);y(this,de,null);y(this,hr,null);y(this,yn,null);y(this,lr,null);y(this,uh,"");y(this,Ai,null);y(this,Ti,null);y(this,ps,!1);y(this,dh,!1);m(this,yn,e.bitmapUrl),m(this,lr,e.bitmapFile)}static initialize(e,s){Pt.initialize(e,s)}static get supportedTypes(){return it(this,"supportedTypes",["apng","avif","bmp","gif","jpeg","png","svg+xml","webp","x-icon"].map(s=>`image/${s}`))}static get supportedTypesStr(){return it(this,"supportedTypesStr",this.supportedTypes.join(","))}static isHandlingMimeForPasting(e){return this.supportedTypes.includes(e)}static paste(e,s){s.pasteEditor(tt.STAMP,{bitmapFile:e.getAsFile()})}altTextFinish(){this._uiManager.useNewAltTextFlow&&(this.div.hidden=!1),super.altTextFinish()}get telemetryFinalData(){var e;return{type:"stamp",hasAltText:!!((e=this.altTextData)!=null&&e.altText)}}static computeTelemetryFinalData(e){const s=e.get("hasAltText");return{hasAltText:s.get(!0)??0,hasNoAltText:s.get(!1)??0}}async mlGuessAltText(e=null,s=!0){if(this.hasAltTextData())return null;const{mlManager:i}=this._uiManager;if(!i)throw new Error("No ML.");if(!await i.isEnabledFor("altText"))throw new Error("ML isn't enabled for alt text.");const{data:n,width:r,height:o}=e||this.copyCanvas(null,null,!0).imageData,h=await i.guess({name:"altText",request:{data:n,width:r,height:o,channels:n.length/(r*o)}});if(!h)throw new Error("No response from the AI service.");if(h.error)throw new Error("Error from the AI service.");if(h.cancel)return null;if(!h.output)throw new Error("No valid response from the AI service.");const c=h.output;return await this.setGuessedAltText(c),s&&!this.hasAltTextData()&&(this.altTextData={alt:c,decorative:!1}),c}remove(){var e;l(this,de)&&(m(this,Ot,null),this._uiManager.imageManager.deleteId(l(this,de)),(e=l(this,Ai))==null||e.remove(),m(this,Ai,null),l(this,Ti)&&(clearTimeout(l(this,Ti)),m(this,Ti,null))),super.remove()}rebuild(){if(!this.parent){l(this,de)&&w(this,ct,Zd).call(this);return}super.rebuild(),this.div!==null&&(l(this,de)&&l(this,Ai)===null&&w(this,ct,Zd).call(this),this.isAttachedToDOM||this.parent.add(this))}onceAdded(e){this._isDraggable=!0,e&&this.div.focus()}isEmpty(){return!(l(this,hr)||l(this,Ot)||l(this,yn)||l(this,lr)||l(this,de))}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.div.setAttribute("role","figure"),this.addAltTextButton(),l(this,Ot)?w(this,ct,Np).call(this):w(this,ct,Zd).call(this),this.width&&!this.annotationElementId){const[i,n]=this.parentDimensions;this.setAt(e*i,s*n,this.width*i,this.height*n)}return this._uiManager.addShouldRescale(this),this.div}_onResized(){this.onScaleChanging()}onScaleChanging(){if(!this.parent)return;l(this,Ti)!==null&&clearTimeout(l(this,Ti)),m(this,Ti,setTimeout(()=>{m(this,Ti,null),w(this,ct,jp).call(this)},200))}copyCanvas(e,s,i=!1){var g;e||(e=224);const{width:n,height:r}=l(this,Ot),o=new bg;let h=l(this,Ot),c=n,u=r,d=null;if(s){if(n>s||r>s){const D=Math.min(s/n,s/r);c=Math.floor(n*D),u=Math.floor(r*D)}d=document.createElement("canvas");const p=d.width=Math.ceil(c*o.sx),b=d.height=Math.ceil(u*o.sy);l(this,ps)||(h=w(this,ct,tf).call(this,p,b));const _=d.getContext("2d");_.filter=this._uiManager.hcmFilter;let v="white",x="#cfcfd8";this._uiManager.hcmFilter!=="none"?x="black":(g=window.matchMedia)!=null&&g.call(window,"(prefers-color-scheme: dark)").matches&&(v="#8f8f9d",x="#42414d");const C=15,S=C*o.sx,E=C*o.sy,k=new OffscreenCanvas(S*2,E*2),M=k.getContext("2d");M.fillStyle=v,M.fillRect(0,0,S*2,E*2),M.fillStyle=x,M.fillRect(0,0,S,E),M.fillRect(S,E,S,E),_.fillStyle=_.createPattern(k,"repeat"),_.fillRect(0,0,p,b),_.drawImage(h,0,0,h.width,h.height,0,0,p,b)}let f=null;if(i){let p,b;if(o.symmetric&&h.width<e&&h.height<e)p=h.width,b=h.height;else if(h=l(this,Ot),n>e||r>e){const x=Math.min(e/n,e/r);p=Math.floor(n*x),b=Math.floor(r*x),l(this,ps)||(h=w(this,ct,tf).call(this,p,b))}const v=new OffscreenCanvas(p,b).getContext("2d",{willReadFrequently:!0});v.drawImage(h,0,0,h.width,h.height,0,0,p,b),f={width:p,height:b,data:v.getImageData(0,0,p,b).data}}return{canvas:d,width:c,height:u,imageData:f}}getImageForAltText(){return l(this,Ai)}static async deserialize(e,s,i){var b;let n=null;if(e instanceof Gb){const{data:{rect:_,rotation:v,id:x,structParent:C,popupRef:S},container:E,parent:{page:{pageNumber:k}}}=e,M=E.querySelector("canvas"),D=i.imageManager.getFromCanvas(E.id,M);M.remove();const R=((b=await s._structTree.getAriaAttributes(`${dg}${x}`))==null?void 0:b.get("aria-label"))||"";n=e={annotationType:tt.STAMP,bitmapId:D.id,bitmap:D.bitmap,pageIndex:k-1,rect:_.slice(0),rotation:v,id:x,deleted:!1,accessibilityData:{decorative:!1,altText:R},isSvg:!1,structParent:C,popupRef:S}}const r=await super.deserialize(e,s,i),{rect:o,bitmap:h,bitmapUrl:c,bitmapId:u,isSvg:d,accessibilityData:f}=e;u&&i.imageManager.isValidId(u)?(m(r,de,u),h&&m(r,Ot,h)):m(r,yn,c),m(r,ps,d);const[g,p]=r.pageDimensions;return r.width=(o[2]-o[0])/g,r.height=(o[3]-o[1])/p,r.annotationElementId=e.id||null,f&&(r.altTextData=f),r._initialData=n,m(r,dh,!!n),r}serialize(e=!1,s=null){if(this.isEmpty())return null;if(this.deleted)return this.serializeDeleted();const i={annotationType:tt.STAMP,bitmapId:l(this,de),pageIndex:this.pageIndex,rect:this.getRect(0,0),rotation:this.rotation,isSvg:l(this,ps),structTreeParentId:this._structTreeParentId};if(e)return i.bitmapUrl=w(this,ct,ef).call(this,!0),i.accessibilityData=this.serializeAltText(!0),i;const{decorative:n,altText:r}=this.serializeAltText(!1);if(!n&&r&&(i.accessibilityData={type:"Figure",alt:r}),this.annotationElementId){const h=w(this,ct,fv).call(this,i);if(h.isSame)return null;h.isSameAltText?delete i.accessibilityData:i.accessibilityData.structParent=this._initialData.structParent??-1}if(i.id=this.annotationElementId,s===null)return i;s.stamps||(s.stamps=new Map);const o=l(this,ps)?(i.rect[2]-i.rect[0])*(i.rect[3]-i.rect[1]):null;if(!s.stamps.has(l(this,de)))s.stamps.set(l(this,de),{area:o,serialized:i}),i.bitmap=w(this,ct,ef).call(this,!1);else if(l(this,ps)){const h=s.stamps.get(l(this,de));o>h.area&&(h.area=o,h.serialized.bitmap.close(),h.serialized.bitmap=w(this,ct,ef).call(this,!1))}return i}renderAnnotationElement(e){return e.updateEdited({rect:this.getRect(0,0)}),null}};Ot=new WeakMap,de=new WeakMap,hr=new WeakMap,yn=new WeakMap,lr=new WeakMap,uh=new WeakMap,Ai=new WeakMap,Ti=new WeakMap,ps=new WeakMap,dh=new WeakMap,ct=new WeakSet,Nc=function(e,s=!1){if(!e){this.remove();return}m(this,Ot,e.bitmap),s||(m(this,de,e.id),m(this,ps,e.isSvg)),e.file&&m(this,uh,e.file.name),w(this,ct,Np).call(this)},jc=function(){if(m(this,hr,null),this._uiManager.enableWaiting(!1),!!l(this,Ai)){if(this._uiManager.useNewAltTextWhenAddingImage&&this._uiManager.useNewAltTextFlow&&l(this,Ot)){this._editToolbar.hide(),this._uiManager.editAltText(this,!0);return}if(!this._uiManager.useNewAltTextWhenAddingImage&&this._uiManager.useNewAltTextFlow&&l(this,Ot)){this._reportTelemetry({action:"pdfjs.image.image_added",data:{alt_text_modal:!1,alt_text_type:"empty"}});try{this.mlGuessAltText()}catch{}}this.div.focus()}},Zd=function(){if(l(this,de)){this._uiManager.enableWaiting(!0),this._uiManager.imageManager.getFromId(l(this,de)).then(i=>w(this,ct,Nc).call(this,i,!0)).finally(()=>w(this,ct,jc).call(this));return}if(l(this,yn)){const i=l(this,yn);m(this,yn,null),this._uiManager.enableWaiting(!0),m(this,hr,this._uiManager.imageManager.getFromUrl(i).then(n=>w(this,ct,Nc).call(this,n)).finally(()=>w(this,ct,jc).call(this)));return}if(l(this,lr)){const i=l(this,lr);m(this,lr,null),this._uiManager.enableWaiting(!0),m(this,hr,this._uiManager.imageManager.getFromFile(i).then(n=>w(this,ct,Nc).call(this,n)).finally(()=>w(this,ct,jc).call(this)));return}const e=document.createElement("input");e.type="file",e.accept=Sc.supportedTypesStr;const s=this._uiManager._signal;m(this,hr,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]);this._reportTelemetry({action:"pdfjs.image.image_selected",data:{alt_text_modal:this._uiManager.useNewAltTextFlow}}),w(this,ct,Nc).call(this,n)}i()},{signal:s}),e.addEventListener("cancel",()=>{this.remove(),i()},{signal:s})}).finally(()=>w(this,ct,jc).call(this))),e.click()},Np=function(){var d;const{div:e}=this;let{width:s,height:i}=l(this,Ot);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 f=Math.min(o*n/s,o*r/i);s*=f,i*=f}const[h,c]=this.parentDimensions;this.setDims(s*h/n,i*c/r),this._uiManager.enableWaiting(!1);const u=m(this,Ai,document.createElement("canvas"));u.setAttribute("role","img"),this.addContainer(u),this.width=s/n,this.height=i/r,(d=this._initialOptions)!=null&&d.isCentered?this.center():this.fixAndSetPosition(),this._initialOptions=null,(!this._uiManager.useNewAltTextWhenAddingImage||!this._uiManager.useNewAltTextFlow||this.annotationElementId)&&(e.hidden=!1),w(this,ct,jp).call(this),l(this,dh)||(this.parent.addUndoableEditor(this),m(this,dh,!0)),this._reportTelemetry({action:"inserted_image"}),l(this,uh)&&u.setAttribute("aria-label",l(this,uh))},tf=function(e,s){const{width:i,height:n}=l(this,Ot);let r=i,o=n,h=l(this,Ot);for(;r>2*e||o>2*s;){const c=r,u=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 d=new OffscreenCanvas(r,o);d.getContext("2d").drawImage(h,0,0,c,u,0,0,r,o),h=d.transferToImageBitmap()}return h},jp=function(){const[e,s]=this.parentDimensions,{width:i,height:n}=this,r=new bg,o=Math.ceil(i*e*r.sx),h=Math.ceil(n*s*r.sy),c=l(this,Ai);if(!c||c.width===o&&c.height===h)return;c.width=o,c.height=h;const u=l(this,ps)?l(this,Ot):w(this,ct,tf).call(this,o,h),d=c.getContext("2d");d.filter=this._uiManager.hcmFilter,d.drawImage(u,0,0,u.width,u.height,0,0,o,h)},ef=function(e){if(e){if(l(this,ps)){const n=this._uiManager.imageManager.getSvgUrl(l(this,de));if(n)return n}const s=document.createElement("canvas");return{width:s.width,height:s.height}=l(this,Ot),s.getContext("2d").drawImage(l(this,Ot),0,0),s.toDataURL()}if(l(this,ps)){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(l(this,Ot),0,0,l(this,Ot).width,l(this,Ot).height,0,0,n,r),o.transferToImageBitmap()}return structuredClone(l(this,Ot))},fv=function(e){var o;const{pageIndex:s,accessibilityData:{altText:i}}=this._initialData,n=e.pageIndex===s,r=(((o=e.accessibilityData)==null?void 0:o.alt)||"")===i;return{isSame:!this._hasBeenMoved&&!this._hasBeenResized&&n&&r,isSameAltText:r}},q(Sc,"_type","stamp"),q(Sc,"_editorType",tt.STAMP);let Hg=Sc;const ei=class ei{constructor({uiManager:t,pageIndex:e,div:s,structTreeLayer:i,accessibilityManager:n,annotationLayer:r,drawLayer:o,textLayer:h,viewport:c,l10n:u}){y(this,kt);y(this,No);y(this,fh,!1);y(this,Ei,null);y(this,cr,null);y(this,vn,null);y(this,Ps,new Map);y(this,ur,!1);y(this,gh,!1);y(this,jo,!1);y(this,ti,null);y(this,_n,null);y(this,Ce,null);y(this,wn,null);y(this,W);const d=[...l(ei,dr).values()];if(!ei._initialized){ei._initialized=!0;for(const f of d)f.initialize(u,t)}t.registerEditorTypes(d),m(this,W,t),this.pageIndex=e,this.div=s,m(this,No,n),m(this,Ei,r),this.viewport=c,m(this,Ce,h),this.drawLayer=o,this._structTree=i,l(this,W).addLayer(this)}get isEmpty(){return l(this,Ps).size===0}get isInvisible(){return this.isEmpty&&l(this,W).getMode()===tt.NONE}updateToolbar(t){l(this,W).updateToolbar(t)}updateMode(t=l(this,W).getMode()){switch(w(this,kt,sf).call(this),t){case tt.NONE:this.disableTextSelection(),this.togglePointerEvents(!1),this.toggleAnnotationLayerPointerEvents(!0),this.disableClick();return;case tt.INK:this.disableTextSelection(),this.togglePointerEvents(!0),this.enableClick();break;case tt.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 l(ei,dr).values())e.toggle(`${s._type}Editing`,t===s._editorType);this.div.hidden=!1}hasTextLayer(t){var e;return t===((e=l(this,Ce))==null?void 0:e.div)}setEditingState(t){l(this,W).setEditingState(t)}addCommands(t){l(this,W).addCommands(t)}cleanUndoStack(t){l(this,W).cleanUndoStack(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=l(this,Ei))==null||e.div.classList.toggle("disabled",!t)}async enable(){m(this,jo,!0),this.div.tabIndex=0,this.togglePointerEvents(!0);const t=new Set;for(const s of l(this,Ps).values())s.enableEditing(),s.show(!0),s.annotationElementId&&(l(this,W).removeChangedExistingAnnotation(s),t.add(s.annotationElementId));if(!l(this,Ei)){m(this,jo,!1);return}const e=l(this,Ei).getEditableAnnotations();for(const s of e){if(s.hide(),l(this,W).isDeletedAnnotationElement(s.data.id)||t.has(s.data.id))continue;const i=await this.deserialize(s);i&&(this.addOrRebuild(i),i.enableEditing())}m(this,jo,!1)}disable(){var i;m(this,gh,!0),this.div.tabIndex=-1,this.togglePointerEvents(!1);const t=new Map,e=new Map;for(const n of l(this,Ps).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(l(this,Ei)){const n=l(this,Ei).getEditableAnnotations();for(const r of n){const{id:o}=r.data;if(l(this,W).isDeletedAnnotationElement(o))continue;let h=e.get(o);if(h){h.resetAnnotationElement(r),h.show(!1),r.show();continue}h=t.get(o),h&&(l(this,W).addChangedExistingAnnotation(h),h.renderAnnotationElement(r)&&h.show(!1)),r.show()}}w(this,kt,sf).call(this),this.isEmpty&&(this.div.hidden=!0);const{classList:s}=this.div;for(const n of l(ei,dr).values())s.remove(`${n._type}Editing`);this.disableTextSelection(),this.toggleAnnotationLayerPointerEvents(!0),m(this,gh,!1)}getEditableAnnotation(t){var e;return((e=l(this,Ei))==null?void 0:e.getEditableAnnotation(t))||null}setActiveEditor(t){l(this,W).getActive()!==t&&l(this,W).setActiveEditor(t)}enableTextSelection(){var t;if(this.div.tabIndex=-1,(t=l(this,Ce))!=null&&t.div&&!l(this,wn)){m(this,wn,new AbortController);const e=l(this,W).combinedSignal(l(this,wn));l(this,Ce).div.addEventListener("pointerdown",w(this,kt,gv).bind(this),{signal:e}),l(this,Ce).div.classList.add("highlighting")}}disableTextSelection(){var t;this.div.tabIndex=0,(t=l(this,Ce))!=null&&t.div&&l(this,wn)&&(l(this,wn).abort(),m(this,wn,null),l(this,Ce).div.classList.remove("highlighting"))}enableClick(){if(l(this,cr))return;m(this,cr,new AbortController);const t=l(this,W).combinedSignal(l(this,cr));this.div.addEventListener("pointerdown",this.pointerdown.bind(this),{signal:t});const e=this.pointerup.bind(this);this.div.addEventListener("pointerup",e,{signal:t}),this.div.addEventListener("pointercancel",e,{signal:t})}disableClick(){var t;(t=l(this,cr))==null||t.abort(),m(this,cr,null)}attach(t){l(this,Ps).set(t.id,t);const{annotationElementId:e}=t;e&&l(this,W).isDeletedAnnotationElement(e)&&l(this,W).removeDeletedAnnotationElement(t)}detach(t){var e;l(this,Ps).delete(t.id),(e=l(this,No))==null||e.removePointerInTextLayer(t.contentDiv),!l(this,gh)&&t.annotationElementId&&l(this,W).addDeletedAnnotationElement(t)}remove(t){this.detach(t),l(this,W).removeEditor(t),t.div.remove(),t.isAttachedToDOM=!1}changeParent(t){var e;t.parent!==this&&(t.parent&&t.annotationElementId&&(l(this,W).addDeletedAnnotationElement(t.annotationElementId),Pt.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),l(this,W).addEditor(t),this.attach(t),!t.isAttachedToDOM){const e=t.render();this.div.append(e),t.isAttachedToDOM=!0}t.fixAndSetPosition(),t.onceAdded(!l(this,jo)),l(this,W).addToAnnotationStorage(t),t._reportTelemetry(t.telemetryInitialData)}}moveEditorInDOM(t){var s;if(!t.isAttachedToDOM)return;const{activeElement:e}=document;t.div.contains(e)&&!l(this,vn)&&(t._focusEventsAllowed=!1,m(this,vn,setTimeout(()=>{m(this,vn,null),t.div.contains(document.activeElement)?t._focusEventsAllowed=!0:(t.div.addEventListener("focusin",()=>{t._focusEventsAllowed=!0},{once:!0,signal:l(this,W)._signal}),e.focus())},0))),t._structTreeParentId=(s=l(this,No))==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 l(this,W).getId()}combinedSignal(t){return l(this,W).combinedSignal(t)}canCreateNewEmptyEditor(){var t;return(t=l(this,kt,Di))==null?void 0:t.canCreateNewEmptyEditor()}pasteEditor(t,e){l(this,W).updateToolbar(t),l(this,W).updateMode(t);const{offsetX:s,offsetY:i}=w(this,kt,Hp).call(this),n=this.getNextId(),r=w(this,kt,Bp).call(this,{parent:this,id:n,x:s,y:i,uiManager:l(this,W),isCentered:!0,...e});r&&this.add(r)}async deserialize(t){var e;return await((e=l(ei,dr).get(t.annotationType??t.annotationEditorType))==null?void 0:e.deserialize(t,this,l(this,W)))||null}createAndAddNewEditor(t,e,s={}){const i=this.getNextId(),n=w(this,kt,Bp).call(this,{parent:this,id:i,x:t.offsetX,y:t.offsetY,uiManager:l(this,W),isCentered:e,...s});return n&&this.add(n),n}addNewEditor(){this.createAndAddNewEditor(w(this,kt,Hp).call(this),!0)}setSelected(t){l(this,W).setSelected(t)}toggleSelected(t){l(this,W).toggleSelected(t)}unselect(t){l(this,W).unselect(t)}pointerup(t){var s;const{isMac:e}=Re.platform;if(!(t.button!==0||t.ctrlKey&&e)&&t.target===this.div&&l(this,ur)&&(m(this,ur,!1),!((s=l(this,kt,Di))!=null&&s.isDrawer&&l(this,kt,Di).supportMultipleDrawings))){if(!l(this,fh)){m(this,fh,!0);return}if(l(this,W).getMode()===tt.STAMP){l(this,W).unselectAll();return}this.createAndAddNewEditor(t,!1)}}pointerdown(t){var i;if(l(this,W).getMode()===tt.HIGHLIGHT&&this.enableTextSelection(),l(this,ur)){m(this,ur,!1);return}const{isMac:e}=Re.platform;if(t.button!==0||t.ctrlKey&&e||t.target!==this.div)return;if(m(this,ur,!0),(i=l(this,kt,Di))!=null&&i.isDrawer){this.startDrawingSession(t);return}const s=l(this,W).getActive();m(this,fh,!s||s.isEmpty())}startDrawingSession(t){if(this.div.focus(),l(this,ti)){l(this,kt,Di).startDrawing(this,l(this,W),!1,t);return}l(this,W).setCurrentDrawingSession(this),m(this,ti,new AbortController);const e=l(this,W).combinedSignal(l(this,ti));this.div.addEventListener("blur",({relatedTarget:s})=>{s&&!this.div.contains(s)&&(m(this,_n,null),this.commitOrRemove())},{signal:e}),l(this,kt,Di).startDrawing(this,l(this,W),!1,t)}pause(t){if(t){const{activeElement:e}=document;this.div.contains(e)&&m(this,_n,e);return}l(this,_n)&&setTimeout(()=>{var e;(e=l(this,_n))==null||e.focus(),m(this,_n,null)},0)}endDrawingSession(t=!1){return l(this,ti)?(l(this,W).setCurrentDrawingSession(null),l(this,ti).abort(),m(this,ti,null),m(this,_n,null),l(this,kt,Di).endDrawing(t)):null}findNewParent(t,e,s){const i=l(this,W).findParent(e,s);return i===null||i===this?!1:(i.changeParent(t),!0)}commitOrRemove(){return l(this,ti)?(this.endDrawingSession(),!0):!1}onScaleChanging(){l(this,ti)&&l(this,kt,Di).onScaleChangingWhenDrawing(this)}destroy(){var t,e;this.commitOrRemove(),((t=l(this,W).getActive())==null?void 0:t.parent)===this&&(l(this,W).commitOrRemove(),l(this,W).setActiveEditor(null)),l(this,vn)&&(clearTimeout(l(this,vn)),m(this,vn,null));for(const s of l(this,Ps).values())(e=l(this,No))==null||e.removePointerInTextLayer(s.contentDiv),s.setParent(null),s.isAttachedToDOM=!1,s.div.remove();this.div=null,l(this,Ps).clear(),l(this,W).removeLayer(this)}render({viewport:t}){this.viewport=t,kr(this.div,t);for(const e of l(this,W).getEditors(this.pageIndex))this.add(e),e.rebuild();this.updateMode()}update({viewport:t}){l(this,W).commitOrRemove(),w(this,kt,sf).call(this);const e=this.viewport.rotation,s=t.rotation;if(this.viewport=t,kr(this.div,{rotation:s}),e!==s)for(const i of l(this,Ps).values())i.rotate(s)}get pageDimensions(){const{pageWidth:t,pageHeight:e}=this.viewport.rawDims;return[t,e]}get scale(){return l(this,W).viewParameters.realScale}};No=new WeakMap,fh=new WeakMap,Ei=new WeakMap,cr=new WeakMap,vn=new WeakMap,Ps=new WeakMap,ur=new WeakMap,gh=new WeakMap,jo=new WeakMap,ti=new WeakMap,_n=new WeakMap,Ce=new WeakMap,wn=new WeakMap,W=new WeakMap,dr=new WeakMap,kt=new WeakSet,gv=function(t){l(this,W).unselectAll();const{target:e}=t;if(e===l(this,Ce).div||(e.getAttribute("role")==="img"||e.classList.contains("endOfContent"))&&l(this,Ce).div.contains(e)){const{isMac:s}=Re.platform;if(t.button!==0||t.ctrlKey&&s)return;l(this,W).showAllEditors("highlight",!0,!0),l(this,Ce).div.classList.add("free"),this.toggleDrawing(),od.startHighlighting(this,l(this,W).direction==="ltr",{target:l(this,Ce).div,x:t.x,y:t.y}),l(this,Ce).div.addEventListener("pointerup",()=>{l(this,Ce).div.classList.remove("free"),this.toggleDrawing(!0)},{once:!0,signal:l(this,W)._signal}),t.preventDefault()}},Di=function(){return l(ei,dr).get(l(this,W).getMode())},Bp=function(t){const e=l(this,kt,Di);return e?new e.prototype.constructor(t):null},Hp=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),c=(n+o)/2-t,u=(r+h)/2-e,[d,f]=this.viewport.rotation%180===0?[c,u]:[u,c];return{offsetX:d,offsetY:f}},sf=function(){for(const t of l(this,Ps).values())t.isEmpty()&&t.remove()},q(ei,"_initialized",!1),y(ei,dr,new Map([Lg,Bg,Hg,od].map(t=>[t._editorType,t])));let Gg=ei;const Ae=class Ae{constructor({pageIndex:t}){y(this,ki);y(this,si,null);y(this,Cc,0);y(this,Be,new Map);y(this,Bo,new Map);this.pageIndex=t}setParent(t){if(!l(this,si)){m(this,si,t);return}if(l(this,si)!==t){if(l(this,Be).size>0)for(const e of l(this,Be).values())e.remove(),t.append(e);m(this,si,t)}}static get _svgFactory(){return it(this,"_svgFactory",new Dg)}draw(t,e=!1,s=!1){const i=Ge(this,Cc)._++,n=w(this,ki,Gp).call(this),r=Ae._svgFactory.createElement("defs");n.append(r);const o=Ae._svgFactory.createElement("path");r.append(o);const h=`path_p${this.pageIndex}_${i}`;o.setAttribute("id",h),o.setAttribute("vector-effect","non-scaling-stroke"),e&&l(this,Bo).set(i,o);const c=s?w(this,ki,mv).call(this,r,h):null,u=Ae._svgFactory.createElement("use");return n.append(u),u.setAttribute("href",`#${h}`),this.updateProperties(n,t),l(this,Be).set(i,n),{id:i,clipPathId:`url(#${c})`}}drawOutline(t,e){const s=Ge(this,Cc)._++,i=w(this,ki,Gp).call(this),n=Ae._svgFactory.createElement("defs");i.append(n);const r=Ae._svgFactory.createElement("path");n.append(r);const o=`path_p${this.pageIndex}_${s}`;r.setAttribute("id",o),r.setAttribute("vector-effect","non-scaling-stroke");let h;if(e){const d=Ae._svgFactory.createElement("mask");n.append(d),h=`mask_p${this.pageIndex}_${s}`,d.setAttribute("id",h),d.setAttribute("maskUnits","objectBoundingBox");const f=Ae._svgFactory.createElement("rect");d.append(f),f.setAttribute("width","1"),f.setAttribute("height","1"),f.setAttribute("fill","white");const g=Ae._svgFactory.createElement("use");d.append(g),g.setAttribute("href",`#${o}`),g.setAttribute("stroke","none"),g.setAttribute("fill","black"),g.setAttribute("fill-rule","nonzero"),g.classList.add("mask")}const c=Ae._svgFactory.createElement("use");i.append(c),c.setAttribute("href",`#${o}`),h&&c.setAttribute("mask",`url(#${h})`);const u=c.cloneNode();return i.append(u),c.classList.add("mainOutline"),u.classList.add("secondaryOutline"),this.updateProperties(i,t),l(this,Be).set(s,i),s}finalizeDraw(t,e){l(this,Bo).delete(t),this.updateProperties(t,e)}updateProperties(t,e){var h;if(!e)return;const{root:s,bbox:i,rootClass:n,path:r}=e,o=typeof t=="number"?l(this,Be).get(t):t;if(o){if(s&&w(this,ki,zp).call(this,o,s),i&&w(h=Ae,Td,pv).call(h,o,i),n){const{classList:c}=o;for(const[u,d]of Object.entries(n))c.toggle(u,d)}if(r){const u=o.firstChild.firstChild;w(this,ki,zp).call(this,u,r)}}}updateParent(t,e){if(e===this)return;const s=l(this,Be).get(t);s&&(l(e,si).append(s),l(this,Be).delete(t),l(e,Be).set(t,s))}remove(t){l(this,Bo).delete(t),l(this,si)!==null&&(l(this,Be).get(t).remove(),l(this,Be).delete(t))}destroy(){m(this,si,null);for(const t of l(this,Be).values())t.remove();l(this,Be).clear(),l(this,Bo).clear()}};si=new WeakMap,Cc=new WeakMap,Be=new WeakMap,Bo=new WeakMap,Td=new WeakSet,pv=function(t,[e,s,i,n]){const{style:r}=t;r.top=`${100*s}%`,r.left=`${100*e}%`,r.width=`${100*i}%`,r.height=`${100*n}%`},ki=new WeakSet,Gp=function(){const t=Ae._svgFactory.create(1,1,!0);return l(this,si).append(t),t.setAttribute("aria-hidden",!0),t},mv=function(t,e){const s=Ae._svgFactory.createElement("clipPath");t.append(s);const i=`clip_${e}`;s.setAttribute("id",i),s.setAttribute("clipPathUnits","objectBoundingBox");const n=Ae._svgFactory.createElement("use");return s.append(n),n.setAttribute("href",`#${e}`),n.classList.add("clip"),i},zp=function(t,e){for(const[s,i]of Object.entries(e))i===null?t.removeAttribute(s):t.setAttribute(s,i)},y(Ae,Td);let zg=Ae;globalThis.pdfjsTestingUtils={HighlightOutliner:Fg},Q.AbortException,Q.AnnotationEditorLayer,Q.AnnotationEditorParamsType,Q.AnnotationEditorType,Q.AnnotationEditorUIManager,Q.AnnotationLayer,Q.AnnotationMode,Q.ColorPicker,Q.DOMSVGFactory,Q.DrawLayer,Q.FeatureTest;var hC=Q.GlobalWorkerOptions;Q.ImageKind,Q.InvalidPDFException,Q.MissingPDFException,Q.OPS,Q.OutputScale,Q.PDFDataRangeTransport,Q.PDFDateString,Q.PDFWorker,Q.PasswordResponses,Q.PermissionFlag,Q.PixelsPerInch,Q.RenderingCancelledException,Q.TextLayer,Q.TouchManager,Q.UnexpectedResponseException,Q.Util,Q.VerbosityLevel,Q.XfaLayer,Q.build,Q.createValidAbsoluteUrl,Q.fetchData;var lC=Q.getDocument;Q.getFilenameFromUrl,Q.getPdfFilenameFromUrl,Q.getXfaPageViewport,Q.isDataScheme,Q.isPdfFile,Q.noContextMenu,Q.normalizeUnicode,Q.setLayerDimensions,Q.shadow,Q.stopEvent,Q.version;const cC={"pdfjs-dist":"4.10.38"};function uC(a){return new Promise((t,e)=>{const s=new FileReader;s.addEventListener("load",()=>t(s.result)),s.addEventListener("error",e),s.readAsDataURL(a)})}const dC=cC["pdfjs-dist"].replace("^","");hC.workerSrc=`https://cdnjs.cloudflare.com/ajax/libs/pdf.js/${dC}/pdf.worker.min.mjs`;async function fC(a){const t="data:application/pdf;base64,",e=await uC(a);if(typeof e=="string")return window.atob(e.slice(t.length))}function gC(a,t){return lC({data:a,password:t}).promise}const pC={top:100,left:50,scaleX:.5,scaleY:.5,borderColor:"black",cornerStrokeColor:"black",cornerSize:8,selectionBackgroundColor:"rgba(245, 245, 245, 0.8)"},mC={top:100,left:50,fontFamily:"helvetica",borderColor:"black",cornerStrokeColor:"black",scaleX:.7,scaleY:.7,cornerSize:8,selectionBackgroundColor:"rgba(245, 245, 245, 0.8)"},bC={stroke:"#000",hoverStroke:"#B7EC5D",src:""};function Vb(a){const{id:t="",pointerDown:e,pointerMove:s,pointerUp:i}=a||{};let n=0,r=null,o=null,h=1,c={...bC};function u(){if(!t||vs.has(t))return;const O=Jw(t);return O.on("selection:cleared",()=>D(O)),e&&O.on("mouse:down",e),s&&O.on("mouse:move",s),i&&O.on("mouse:up",i),O}function d(O,F){var Y;const L=O.type,N={"application/pdf":f,"image/png":b,"image/jpeg":b};return((Y=N[L])==null?void 0:Y.call(N,O,F))??Promise.reject(new Error(`Unsupported ${L} file type.`))}async function f(O,F){const L=await fC(O);if(!L)return;const N=Zw(O,L);try{return await g({page:1,PDFBase64:L,scale:.8,password:F}),{...N,pages:n}}catch(Y){return Promise.reject(Y)}}async function g({page:O,PDFBase64:F,scale:L,password:N}){try{const Y=await gC(F,N),I=await K.toRaw(Y).getPage(O),{renderTask:X,canvas:rt}=tx(I,L);return n=Y.numPages,X.promise.then(()=>p(rt))}catch(Y){return Promise.reject(Y)}}function p(O){sx(t,O)}async function b(O){return await ix(t,O)}async function _({url:O,scale:F=.5}){await $0(t,{url:O,scale:F})}async function v(O,F,L){const N=vs.get(t);if(!N)return;const Y=await be.fromURL(O,{},{...pC,...F});K0(Y,L),N.add(Y),C(N,Y),N.setActiveObject(Y)}function x(O,F,L){const N=vs.get(t);if(!N)return;const Y=new me(O,{...mC,...F});K0(Y,L),N.add(Y),C(N,Y),N.setActiveObject(Y)}function C(O,F){F.on("selected",L=>S({canvas:O,target:L.target})),F.on("modified",L=>Bh(L.target,r)),F.on("scaling",L=>Bh(L.transform.target,r)),F.on("moving",L=>Bh(L.transform.target,r)),F.on("rotating",L=>Bh(L.transform.target,r))}async function S({canvas:O,target:F,stroke:L=c.stroke,uuid:N=Date.now()}){if((r==null?void 0:r.stroke)===`${L}-${N}`)return;const Y=await ex(c.src,L,N);D(O),r=Y,o=F,E(O,F,N),k(h,!0),O.add(Y)}function E(O,F,L){r&&(r.on("selected",()=>{O.remove(F),D(O)}),r.on("mouseover",()=>{S({canvas:O,target:F,stroke:c.hoverStroke,uuid:L})}),r.on("mouseout",()=>{S({canvas:O,target:F,stroke:c.stroke,uuid:L})}))}function k(O,F=!1){const L=vs.get(t);h=O,L&&(rx(o,O,c),nx(o,O,r),!F&&L.renderAll())}function M(O){if(!O)return;c={...c,...O};const F=vs.get(t);!r||!o||!F||S({target:o,canvas:F})}function D(O){r&&(O.remove(r),r=o=null)}function R(){ox(t)}function B(){ax(t)}return{createCanvas:u,loadFile:d,specifyPage:g,renderImage:_,addFabric:v,addTextFabric:x,clearActive:R,deleteCanvas:B,scaleFabric:k,setCloseSvgOptions:M}}function yC(a){let t=0;const e=Qw(()=>{t!==window.innerWidth&&(t=window.innerWidth,a())});K.onMounted(()=>{window.addEventListener("resize",e)}),K.onBeforeUnmount(()=>{window.removeEventListener("resize",e)})}const vC=K.defineComponent({__name:"pdf-canvas",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:{},onDestroy:{type:Function,default:K.onBeforeUnmount}},emits:["loaded","pointerDown","pointerMove","pointerUp"],setup(a,{expose:t,emit:e}){const s=a,i=e,{onDestroy:n}=s,r=K.ref(null),o=`${s.canvasId}-${s.page-1}`,h=K.computed(()=>s.fileZoom*s.canvasScale),{createCanvas:c,specifyPage:u,addFabric:d,addTextFabric:f,renderImage:g,clearActive:p,deleteCanvas:b,scaleFabric:_,setCloseSvgOptions:v}=Vb({id:o,pointerDown:k=>i("pointerDown",k),pointerMove:k=>i("pointerMove",k),pointerUp:k=>i("pointerUp",k)});x(),yC(x);async function x(){const{file:k,page:M,fileScale:D}=s;window.requestAnimationFrame(async()=>{if(await K.nextTick(),c(),k.PDFBase64.startsWith("data:image")||k.canvas){const{canvas:R}=k,B=R?7:3,O=R!=null&&R.length?R[M-1]:k.PDFBase64;g({url:O,scale:D/B}),i("loaded");return}await u({page:M,PDFBase64:k.PDFBase64,scale:D,password:s.password}),i("loaded")})}function C(k){if(!s.isDrop||!k.dataTransfer)return;const{dataTransfer:M,offsetX:D,offsetY:R}=k,B=M.getData("text/plain"),O=M.getData("text/uri-list"),F=M.getData("custom/offset"),L=F?JSON.parse(F):null,N={top:R,left:D},Y={x:(L==null?void 0:L.offsetX)??0,y:(L==null?void 0:L.offsetY)??0};O?S(O,N,Y):B&&E(B,N,Y)}function S(k,M,D){d(k,{...s.dropImageOptions,...M},D)}function E(k,M,D){f(k,{...s.dropTextOptions,...M},D)}return K.watch([()=>s.fileScale,()=>s.page,()=>s.file,()=>s.password],x),K.watch(h,k=>_(k),{immediate:!0}),K.watch(()=>s.closeSvgOptions,v,{immediate:!0}),n(b),t({addImage:S,addText:E,clearActive:p,deleteCanvas:b,canvasRef:r}),(k,M)=>(K.openBlock(),K.createElementBlock("div",{style:K.normalizeStyle({transform:`scale(${h.value})`}),onDragover:M[0]||(M[0]=K.withModifiers(()=>{},["stop","prevent"])),onDragenter:M[1]||(M[1]=K.withModifiers(()=>{},["stop","prevent"])),onDrop:K.withModifiers(C,["stop","prevent"])},[K.createElementVNode("canvas",{id:o,ref_key:"canvasRef",ref:r,class:K.normalizeClass(k.canvasClass)},null,2)],36))}});ot.default=vC,ot.useFabric=Vb,Object.defineProperties(ot,{__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)}},Vy=function(){return l(this,hs).replaceAll(" "," ")},Ep=function(e){return e.replaceAll(" "," ")},Xy=function(e){const{value:s,fontSize:i,color:n,pageIndex:r}=this._initialData;return this._hasBeenMoved||e.value!==s||e.fontSize!==i||e.color.some((o,h)=>o!==n[h])||e.pageIndex!==r},y(wt,fn),$(wt,"_freeTextDefaultContent",""),$(wt,"_internalPadding",0),$(wt,"_defaultColor",null),$(wt,"_defaultFontSize",10),$(wt,"_type","freetext"),$(wt,"_editorType",Z.FREETEXT);let Lg=wt;class B{toSVGPath(){vt("Abstract method `toSVGPath` must be implemented.")}get box(){vt("Abstract getter `box` must be implemented.")}serialize(t,e){vt("Abstract method `serialize` must be implemented.")}static _rescale(t,e,s,i,n,r){r||(r=new Float32Array(t.length));for(let o=0,h=t.length;o<h;o+=2)r[o]=e+t[o]*i,r[o+1]=s+t[o+1]*n;return r}static _rescaleAndSwap(t,e,s,i,n,r){r||(r=new Float32Array(t.length));for(let o=0,h=t.length;o<h;o+=2)r[o]=e+t[o+1]*i,r[o+1]=s+t[o]*n;return r}static _translate(t,e,s,i){i||(i=new Float32Array(t.length));for(let n=0,r=t.length;n<r;n+=2)i[n]=e+t[n],i[n+1]=s+t[n+1];return i}static svgRound(t){return Math.round(t*1e4)}static _normalizePoint(t,e,s,i,n){switch(n){case 90:return[1-e/s,t/i];case 180:return[1-t/s,1-e/i];case 270:return[e/s,1-t/i];default:return[t/s,e/i]}}static _normalizePagePoint(t,e,s){switch(s){case 90:return[1-e,t];case 180:return[1-t,1-e];case 270:return[e,1-t];default:return[t,e]}}static createBezierPoints(t,e,s,i,n,r){return[(t+5*s)/6,(e+5*i)/6,(5*s+n)/6,(5*i+r)/6,(s+n)/2,(i+r)/2]}}$(B,"PRECISION",1e-4);const gn=class gn{constructor({x:t,y:e},s,i,n,r,o=0){y(this,Jt);y(this,cs);y(this,Ks,[]);y(this,Xa);y(this,Wa);y(this,wi,[]);y(this,it,new Float32Array(18));y(this,So);y(this,Co);y(this,rc);y(this,oc);y(this,Ua);y(this,Ya);y(this,sr,[]);m(this,cs,s),m(this,Ya,n*i),m(this,Wa,r),l(this,it).set([NaN,NaN,NaN,NaN,t,e],6),m(this,Xa,o),m(this,oc,l(gn,ac)*i),m(this,rc,l(gn,Sd)*i),m(this,Ua,i),l(this,sr).push(t,e)}isEmpty(){return isNaN(l(this,it)[8])}add({x:t,y:e}){var O;m(this,So,t),m(this,Co,e);const[s,i,n,r]=l(this,cs);let[o,h,c,u]=l(this,it).subarray(8,12);const d=t-c,f=e-u,g=Math.hypot(d,f);if(g<l(this,rc))return!1;const p=g-l(this,oc),b=p/g,_=b*d,v=b*f;let x=o,C=h;o=c,h=u,c+=_,u+=v,(O=l(this,sr))==null||O.push(t,e);const S=-v/p,k=_/p,M=S*l(this,Ya),E=k*l(this,Ya);return l(this,it).set(l(this,it).subarray(2,8),0),l(this,it).set([c+M,u+E],4),l(this,it).set(l(this,it).subarray(14,18),12),l(this,it).set([c-M,u-E],16),isNaN(l(this,it)[6])?(l(this,wi).length===0&&(l(this,it).set([o+M,h+E],2),l(this,wi).push(NaN,NaN,NaN,NaN,(o+M-s)/n,(h+E-i)/r),l(this,it).set([o-M,h-E],14),l(this,Ks).push(NaN,NaN,NaN,NaN,(o-M-s)/n,(h-E-i)/r)),l(this,it).set([x,C,o,h,c,u],6),!this.isEmpty()):(l(this,it).set([x,C,o,h,c,u],6),Math.abs(Math.atan2(C-h,x-o)-Math.atan2(v,_))<Math.PI/2?([o,h,c,u]=l(this,it).subarray(2,6),l(this,wi).push(NaN,NaN,NaN,NaN,((o+c)/2-s)/n,((h+u)/2-i)/r),[o,h,x,C]=l(this,it).subarray(14,18),l(this,Ks).push(NaN,NaN,NaN,NaN,((x+o)/2-s)/n,((C+h)/2-i)/r),!0):([x,C,o,h,c,u]=l(this,it).subarray(0,6),l(this,wi).push(((x+5*o)/6-s)/n,((C+5*h)/6-i)/r,((5*o+c)/6-s)/n,((5*h+u)/6-i)/r,((o+c)/2-s)/n,((h+u)/2-i)/r),[c,u,o,h,x,C]=l(this,it).subarray(12,18),l(this,Ks).push(((x+5*o)/6-s)/n,((C+5*h)/6-i)/r,((5*o+c)/6-s)/n,((5*h+u)/6-i)/r,((o+c)/2-s)/n,((h+u)/2-i)/r),!0))}toSVGPath(){if(this.isEmpty())return"";const t=l(this,wi),e=l(this,Ks);if(isNaN(l(this,it)[6])&&!this.isEmpty())return w(this,Jt,Wy).call(this);const s=[];s.push(`M${t[4]} ${t[5]}`);for(let i=6;i<t.length;i+=6)isNaN(t[i])?s.push(`L${t[i+4]} ${t[i+5]}`):s.push(`C${t[i]} ${t[i+1]} ${t[i+2]} ${t[i+3]} ${t[i+4]} ${t[i+5]}`);w(this,Jt,Yy).call(this,s);for(let i=e.length-6;i>=6;i-=6)isNaN(e[i])?s.push(`L${e[i+4]} ${e[i+5]}`):s.push(`C${e[i]} ${e[i+1]} ${e[i+2]} ${e[i+3]} ${e[i+4]} ${e[i+5]}`);return w(this,Jt,Uy).call(this,s),s.join(" ")}newFreeDrawOutline(t,e,s,i,n,r){return new jb(t,e,s,i,n,r)}getOutlines(){var d;const t=l(this,wi),e=l(this,Ks),s=l(this,it),[i,n,r,o]=l(this,cs),h=new Float32Array((((d=l(this,sr))==null?void 0:d.length)??0)+2);for(let f=0,g=h.length-2;f<g;f+=2)h[f]=(l(this,sr)[f]-i)/r,h[f+1]=(l(this,sr)[f+1]-n)/o;if(h[h.length-2]=(l(this,So)-i)/r,h[h.length-1]=(l(this,Co)-n)/o,isNaN(s[6])&&!this.isEmpty())return w(this,Jt,$y).call(this,h);const c=new Float32Array(l(this,wi).length+24+l(this,Ks).length);let u=t.length;for(let f=0;f<u;f+=2){if(isNaN(t[f])){c[f]=c[f+1]=NaN;continue}c[f]=t[f],c[f+1]=t[f+1]}u=w(this,Jt,Ky).call(this,c,u);for(let f=e.length-6;f>=6;f-=6)for(let g=0;g<6;g+=2){if(isNaN(e[f+g])){c[u]=c[u+1]=NaN,u+=2;continue}c[u]=e[f+g],c[u+1]=e[f+g+1],u+=2}return w(this,Jt,qy).call(this,c,u),this.newFreeDrawOutline(c,h,l(this,cs),l(this,Ua),l(this,Xa),l(this,Wa))}};cs=new WeakMap,Ks=new WeakMap,Xa=new WeakMap,Wa=new WeakMap,wi=new WeakMap,it=new WeakMap,So=new WeakMap,Co=new WeakMap,rc=new WeakMap,oc=new WeakMap,Ua=new WeakMap,Ya=new WeakMap,sr=new WeakMap,ac=new WeakMap,xd=new WeakMap,Sd=new WeakMap,Jt=new WeakSet,Rc=function(){const t=l(this,it).subarray(4,6),e=l(this,it).subarray(16,18),[s,i,n,r]=l(this,cs);return[(l(this,So)+(t[0]-e[0])/2-s)/n,(l(this,Co)+(t[1]-e[1])/2-i)/r,(l(this,So)+(e[0]-t[0])/2-s)/n,(l(this,Co)+(e[1]-t[1])/2-i)/r]},Wy=function(){const[t,e,s,i]=l(this,cs),[n,r,o,h]=w(this,Jt,Rc).call(this);return`M${(l(this,it)[2]-t)/s} ${(l(this,it)[3]-e)/i} L${(l(this,it)[4]-t)/s} ${(l(this,it)[5]-e)/i} L${n} ${r} L${o} ${h} L${(l(this,it)[16]-t)/s} ${(l(this,it)[17]-e)/i} L${(l(this,it)[14]-t)/s} ${(l(this,it)[15]-e)/i} Z`},Uy=function(t){const e=l(this,Ks);t.push(`L${e[4]} ${e[5]} Z`)},Yy=function(t){const[e,s,i,n]=l(this,cs),r=l(this,it).subarray(4,6),o=l(this,it).subarray(16,18),[h,c,u,d]=w(this,Jt,Rc).call(this);t.push(`L${(r[0]-e)/i} ${(r[1]-s)/n} L${h} ${c} L${u} ${d} L${(o[0]-e)/i} ${(o[1]-s)/n}`)},$y=function(t){const e=l(this,it),[s,i,n,r]=l(this,cs),[o,h,c,u]=w(this,Jt,Rc).call(this),d=new Float32Array(36);return d.set([NaN,NaN,NaN,NaN,(e[2]-s)/n,(e[3]-i)/r,NaN,NaN,NaN,NaN,(e[4]-s)/n,(e[5]-i)/r,NaN,NaN,NaN,NaN,o,h,NaN,NaN,NaN,NaN,c,u,NaN,NaN,NaN,NaN,(e[16]-s)/n,(e[17]-i)/r,NaN,NaN,NaN,NaN,(e[14]-s)/n,(e[15]-i)/r],0),this.newFreeDrawOutline(d,t,l(this,cs),l(this,Ua),l(this,Xa),l(this,Wa))},qy=function(t,e){const s=l(this,Ks);return t.set([NaN,NaN,NaN,NaN,s[4],s[5]],e),e+=6},Ky=function(t,e){const s=l(this,it).subarray(4,6),i=l(this,it).subarray(16,18),[n,r,o,h]=l(this,cs),[c,u,d,f]=w(this,Jt,Rc).call(this);return t.set([NaN,NaN,NaN,NaN,(s[0]-n)/o,(s[1]-r)/h,NaN,NaN,NaN,NaN,c,u,NaN,NaN,NaN,NaN,d,f,NaN,NaN,NaN,NaN,(i[0]-n)/o,(i[1]-r)/h],e),e+=24},y(gn,ac,8),y(gn,xd,2),y(gn,Sd,l(gn,ac)+l(gn,xd));let nd=gn;class jb extends B{constructor(e,s,i,n,r,o){super();y(this,Cd);y(this,$a);y(this,Ao,new Float32Array(4));y(this,pn);y(this,hc);y(this,us);y(this,lc);y(this,Ht);m(this,Ht,e),m(this,us,s),m(this,$a,i),m(this,lc,n),m(this,pn,r),m(this,hc,o),this.lastPoint=[NaN,NaN],w(this,Cd,Qy).call(this,o);const[h,c,u,d]=l(this,Ao);for(let f=0,g=e.length;f<g;f+=2)e[f]=(e[f]-h)/u,e[f+1]=(e[f+1]-c)/d;for(let f=0,g=s.length;f<g;f+=2)s[f]=(s[f]-h)/u,s[f+1]=(s[f+1]-c)/d}toSVGPath(){const e=[`M${l(this,Ht)[4]} ${l(this,Ht)[5]}`];for(let s=6,i=l(this,Ht).length;s<i;s+=6){if(isNaN(l(this,Ht)[s])){e.push(`L${l(this,Ht)[s+4]} ${l(this,Ht)[s+5]}`);continue}e.push(`C${l(this,Ht)[s]} ${l(this,Ht)[s+1]} ${l(this,Ht)[s+2]} ${l(this,Ht)[s+3]} ${l(this,Ht)[s+4]} ${l(this,Ht)[s+5]}`)}return e.push("Z"),e.join(" ")}serialize([e,s,i,n],r){const o=i-e,h=n-s;let c,u;switch(r){case 0:c=B._rescale(l(this,Ht),e,n,o,-h),u=B._rescale(l(this,us),e,n,o,-h);break;case 90:c=B._rescaleAndSwap(l(this,Ht),e,s,o,h),u=B._rescaleAndSwap(l(this,us),e,s,o,h);break;case 180:c=B._rescale(l(this,Ht),i,s,-o,h),u=B._rescale(l(this,us),i,s,-o,h);break;case 270:c=B._rescaleAndSwap(l(this,Ht),i,n,-o,-h),u=B._rescaleAndSwap(l(this,us),i,n,-o,-h);break}return{outline:Array.from(c),points:[Array.from(u)]}}get box(){return l(this,Ao)}newOutliner(e,s,i,n,r,o=0){return new nd(e,s,i,n,r,o)}getNewOutline(e,s){const[i,n,r,o]=l(this,Ao),[h,c,u,d]=l(this,$a),f=r*u,g=o*d,p=i*u+h,b=n*d+c,_=this.newOutliner({x:l(this,us)[0]*f+p,y:l(this,us)[1]*g+b},l(this,$a),l(this,lc),e,l(this,hc),s??l(this,pn));for(let v=2;v<l(this,us).length;v+=2)_.add({x:l(this,us)[v]*f+p,y:l(this,us)[v+1]*g+b});return _.getOutlines()}}$a=new WeakMap,Ao=new WeakMap,pn=new WeakMap,hc=new WeakMap,us=new WeakMap,lc=new WeakMap,Ht=new WeakMap,Cd=new WeakSet,Qy=function(e){const s=l(this,Ht);let i=s[4],n=s[5],r=i,o=n,h=i,c=n,u=i,d=n;const f=e?Math.max:Math.min;for(let p=6,b=s.length;p<b;p+=6){if(isNaN(s[p]))r=Math.min(r,s[p+4]),o=Math.min(o,s[p+5]),h=Math.max(h,s[p+4]),c=Math.max(c,s[p+5]),d<s[p+5]?(u=s[p+4],d=s[p+5]):d===s[p+5]&&(u=f(u,s[p+4]));else{const _=W.bezierBoundingBox(i,n,...s.slice(p,p+6));r=Math.min(r,_[0]),o=Math.min(o,_[1]),h=Math.max(h,_[2]),c=Math.max(c,_[3]),d<_[3]?(u=_[2],d=_[3]):d===_[3]&&(u=f(u,_[2]))}i=s[p+4],n=s[p+5]}const g=l(this,Ao);g[0]=r-l(this,pn),g[1]=o-l(this,pn),g[2]=h-r+2*l(this,pn),g[3]=c-o+2*l(this,pn),this.lastPoint=[u,d]};class Fg{constructor(t,e=0,s=0,i=!0){y(this,Ie);y(this,cc);y(this,uc);y(this,ir,[]);y(this,Qs,[]);let n=1/0,r=-1/0,o=1/0,h=-1/0;const c=10**-4;for(const{x:_,y:v,width:x,height:C}of t){const S=Math.floor((_-e)/c)*c,k=Math.ceil((_+x+e)/c)*c,M=Math.floor((v-e)/c)*c,E=Math.ceil((v+C+e)/c)*c,P=[S,M,E,!0],O=[k,M,E,!1];l(this,ir).push(P,O),n=Math.min(n,S),r=Math.max(r,k),o=Math.min(o,M),h=Math.max(h,E)}const u=r-n+2*s,d=h-o+2*s,f=n-s,g=o-s,p=l(this,ir).at(i?-1:-2),b=[p[0],p[2]];for(const _ of l(this,ir)){const[v,x,C]=_;_[0]=(v-f)/u,_[1]=(x-g)/d,_[2]=(C-g)/d}m(this,cc,new Float32Array([f,g,u,d])),m(this,uc,b)}getOutlines(){l(this,ir).sort((e,s)=>e[0]-s[0]||e[1]-s[1]||e[2]-s[2]);const t=[];for(const e of l(this,ir))e[3]?(t.push(...w(this,Ie,kp).call(this,e)),w(this,Ie,Zy).call(this,e)):(w(this,Ie,tv).call(this,e),t.push(...w(this,Ie,kp).call(this,e)));return w(this,Ie,Jy).call(this,t)}}cc=new WeakMap,uc=new WeakMap,ir=new WeakMap,Qs=new WeakMap,Ie=new WeakSet,Jy=function(t){const e=[],s=new Set;for(const r of t){const[o,h,c]=r;e.push([o,h,r],[o,c,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],c=e[r+1][2];h.push(c),c.push(h),s.add(h),s.add(c)}const i=[];let n;for(;s.size>0;){const r=s.values().next().value;let[o,h,c,u,d]=r;s.delete(r);let f=o,g=h;for(n=[o,c],i.push(n);;){let p;if(s.has(u))p=u;else if(s.has(d))p=d;else break;s.delete(p),[o,h,c,u,d]=p,f!==o&&(n.push(f,g,o,g===h?h:c),f=o),g=g===h?c:h}n.push(f,g)}return new VS(i,l(this,cc),l(this,uc))},$d=function(t){const e=l(this,Qs);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},Zy=function([,t,e]){const s=w(this,Ie,$d).call(this,t);l(this,Qs).splice(s,0,[t,e])},tv=function([,t,e]){const s=w(this,Ie,$d).call(this,t);for(let i=s;i<l(this,Qs).length;i++){const[n,r]=l(this,Qs)[i];if(n!==t)break;if(n===t&&r===e){l(this,Qs).splice(i,1);return}}for(let i=s-1;i>=0;i--){const[n,r]=l(this,Qs)[i];if(n!==t)break;if(n===t&&r===e){l(this,Qs).splice(i,1);return}}},kp=function(t){const[e,s,i]=t,n=[[e,s,i]],r=w(this,Ie,$d).call(this,i);for(let o=0;o<r;o++){const[h,c]=l(this,Qs)[o];for(let u=0,d=n.length;u<d;u++){const[,f,g]=n[u];if(!(c<=f||g<=h)){if(f>=h){if(g>c)n[u][1]=c;else{if(d===1)return[];n.splice(u,1),u--,d--}continue}n[u][2]=h,g>c&&n.push([e,c,g])}}}return n};class VS extends B{constructor(e,s,i){super();y(this,dc);y(this,qa);m(this,qa,e),m(this,dc,s),this.lastPoint=i}toSVGPath(){const e=[];for(const s of l(this,qa)){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,c=n-s;for(const u of l(this,qa)){const d=new Array(u.length);for(let f=0;f<u.length;f+=2)d[f]=e+u[f]*h,d[f+1]=n-u[f+1]*c;o.push(d)}return o}get box(){return l(this,dc)}get classNamesForOutlining(){return["highlightOutline"]}}dc=new WeakMap,qa=new WeakMap;class Ig extends nd{newFreeDrawOutline(t,e,s,i,n,r){return new XS(t,e,s,i,n,r)}}class XS extends jb{newOutliner(t,e,s,i,n,r=0){return new Ig(t,e,s,i,n,r)}}const Ke=class Ke{constructor({editor:t=null,uiManager:e=null}){y(this,yt);y(this,Js,null);y(this,To,null);y(this,Ka);y(this,Zt,null);y(this,fc,!1);y(this,Qa,!1);y(this,gc,null);y(this,pc);y(this,nr,null);y(this,Zs,null);y(this,Ja);var s;t?(m(this,Qa,!1),m(this,Ja,ot.HIGHLIGHT_COLOR),m(this,gc,t)):(m(this,Qa,!0),m(this,Ja,ot.HIGHLIGHT_DEFAULT_COLOR)),m(this,Zs,(t==null?void 0:t._uiManager)||e),m(this,pc,l(this,Zs)._eventBus),m(this,Ka,(t==null?void 0:t.color)||((s=l(this,Zs))==null?void 0:s.highlightColors.values().next().value)||"#FFFF98"),l(Ke,mc)||m(Ke,mc,Object.freeze({blue:"pdfjs-editor-colorpicker-blue",green:"pdfjs-editor-colorpicker-green",pink:"pdfjs-editor-colorpicker-pink",red:"pdfjs-editor-colorpicker-red",yellow:"pdfjs-editor-colorpicker-yellow"}))}static get _keyboardManager(){return st(this,"_keyboardManager",new Xh([[["Escape","mac+Escape"],Ke.prototype._hideDropdownFromKeyboard],[[" ","mac+ "],Ke.prototype._colorSelectFromKeyboard],[["ArrowDown","ArrowRight","mac+ArrowDown","mac+ArrowRight"],Ke.prototype._moveToNext],[["ArrowUp","ArrowLeft","mac+ArrowUp","mac+ArrowLeft"],Ke.prototype._moveToPrevious],[["Home","mac+Home"],Ke.prototype._moveToBeginning],[["End","mac+End"],Ke.prototype._moveToEnd]]))}renderButton(){const t=m(this,Js,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=l(this,Zs)._signal;t.addEventListener("click",w(this,yt,Go).bind(this),{signal:e}),t.addEventListener("keydown",w(this,yt,Dp).bind(this),{signal:e});const s=m(this,To,document.createElement("span"));return s.className="swatch",s.setAttribute("aria-hidden",!0),s.style.backgroundColor=l(this,Ka),t.append(s),t}renderMainDropdown(){const t=m(this,Zt,w(this,yt,Mp).call(this));return t.setAttribute("aria-orientation","horizontal"),t.setAttribute("aria-labelledby","highlightColorPickerLabel"),t}_colorSelectFromKeyboard(t){if(t.target===l(this,Js)){w(this,yt,Go).call(this,t);return}const e=t.target.getAttribute("data-color");e&&w(this,yt,Pp).call(this,e,t)}_moveToNext(t){var e,s;if(!l(this,yt,gr)){w(this,yt,Go).call(this,t);return}if(t.target===l(this,Js)){(e=l(this,Zt).firstChild)==null||e.focus();return}(s=t.target.nextSibling)==null||s.focus()}_moveToPrevious(t){var e,s;if(t.target===((e=l(this,Zt))==null?void 0:e.firstChild)||t.target===l(this,Js)){l(this,yt,gr)&&this._hideDropdownFromKeyboard();return}l(this,yt,gr)||w(this,yt,Go).call(this,t),(s=t.target.previousSibling)==null||s.focus()}_moveToBeginning(t){var e;if(!l(this,yt,gr)){w(this,yt,Go).call(this,t);return}(e=l(this,Zt).firstChild)==null||e.focus()}_moveToEnd(t){var e;if(!l(this,yt,gr)){w(this,yt,Go).call(this,t);return}(e=l(this,Zt).lastChild)==null||e.focus()}hideDropdown(){var t,e;(t=l(this,Zt))==null||t.classList.add("hidden"),(e=l(this,nr))==null||e.abort(),m(this,nr,null)}_hideDropdownFromKeyboard(){var t;if(!l(this,Qa)){if(!l(this,yt,gr)){(t=l(this,gc))==null||t.unselect();return}this.hideDropdown(),l(this,Js).focus({preventScroll:!0,focusVisible:l(this,fc)})}}updateColor(t){if(l(this,To)&&(l(this,To).style.backgroundColor=t),!l(this,Zt))return;const e=l(this,Zs).highlightColors.values();for(const s of l(this,Zt).children)s.setAttribute("aria-selected",e.next().value===t)}destroy(){var t,e;(t=l(this,Js))==null||t.remove(),m(this,Js,null),m(this,To,null),(e=l(this,Zt))==null||e.remove(),m(this,Zt,null)}};Js=new WeakMap,To=new WeakMap,Ka=new WeakMap,Zt=new WeakMap,fc=new WeakMap,Qa=new WeakMap,gc=new WeakMap,pc=new WeakMap,nr=new WeakMap,Zs=new WeakMap,Ja=new WeakMap,mc=new WeakMap,yt=new WeakSet,Mp=function(){const t=document.createElement("div"),e=l(this,Zs)._signal;t.addEventListener("contextmenu",Gs,{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 l(this,Zs).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",l(Ke,mc)[s]);const r=document.createElement("span");n.append(r),r.className="swatch",r.style.backgroundColor=i,n.setAttribute("aria-selected",i===l(this,Ka)),n.addEventListener("click",w(this,yt,Pp).bind(this,i),{signal:e}),t.append(n)}return t.addEventListener("keydown",w(this,yt,Dp).bind(this),{signal:e}),t},Pp=function(t,e){e.stopPropagation(),l(this,pc).dispatch("switchannotationeditorparams",{source:this,type:l(this,Ja),value:t})},Dp=function(t){Ke._keyboardManager.exec(this,t)},Go=function(t){if(l(this,yt,gr)){this.hideDropdown();return}if(m(this,fc,t.detail===0),l(this,nr)||(m(this,nr,new AbortController),window.addEventListener("pointerdown",w(this,yt,ev).bind(this),{signal:l(this,Zs).combinedSignal(l(this,nr))})),l(this,Zt)){l(this,Zt).classList.remove("hidden");return}const e=m(this,Zt,w(this,yt,Mp).call(this));l(this,Js).append(e)},ev=function(t){var e;(e=l(this,Zt))!=null&&e.contains(t.target)||this.hideDropdown()},gr=function(){return l(this,Zt)&&!l(this,Zt).classList.contains("hidden")},y(Ke,mc,null);let rd=Ke;const ut=class ut extends Pt{constructor(e){super({...e,name:"highlightEditor"});y(this,J);y(this,Za,null);y(this,bc,0);y(this,mn);y(this,Eo,null);y(this,th,null);y(this,Qe,null);y(this,yc,null);y(this,vc,0);y(this,ko,null);y(this,Ts,null);y(this,ds,null);y(this,le,!1);y(this,eh,null);y(this,bn);y(this,Se,null);y(this,sh,"");y(this,Es);y(this,_c,"");this.color=e.color||ut._defaultColor,m(this,Es,e.thickness||ut._defaultThickness),m(this,bn,e.opacity||ut._defaultOpacity),m(this,mn,e.boxes||null),m(this,_c,e.methodOfCreation||""),m(this,sh,e.text||""),this._isDraggable=!1,e.highlightId>-1?(m(this,le,!0),w(this,J,qd).call(this,e),w(this,J,zo).call(this)):l(this,mn)&&(m(this,Za,e.anchorNode),m(this,bc,e.anchorOffset),m(this,yc,e.focusNode),m(this,vc,e.focusOffset),w(this,J,Op).call(this),w(this,J,zo).call(this),this.rotate(this.rotation))}static get _keyboardManager(){const e=ut.prototype;return st(this,"_keyboardManager",new Xh([[["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:l(this,le)?"free_highlight":"highlight",color:this._uiManager.highlightColorNames.get(this.color),thickness:l(this,Es),methodOfCreation:l(this,_c)}}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;Pt.initialize(e,s),ut._defaultColor||(ut._defaultColor=((i=s.highlightColors)==null?void 0:i.values().next().value)||"#fff066")}static updateDefaultParams(e,s){switch(e){case ot.HIGHLIGHT_DEFAULT_COLOR:ut._defaultColor=s;break;case ot.HIGHLIGHT_THICKNESS:ut._defaultThickness=s;break}}translateInPage(e,s){}get toolbarPosition(){return l(this,eh)}updateParams(e,s){switch(e){case ot.HIGHLIGHT_COLOR:w(this,J,sv).call(this,s);break;case ot.HIGHLIGHT_THICKNESS:w(this,J,iv).call(this,s);break}}static get defaultPropertiesToUpdate(){return[[ot.HIGHLIGHT_DEFAULT_COLOR,ut._defaultColor],[ot.HIGHLIGHT_THICKNESS,ut._defaultThickness]]}get propertiesToUpdate(){return[[ot.HIGHLIGHT_COLOR,this.color||ut._defaultColor],[ot.HIGHLIGHT_THICKNESS,l(this,Es)||ut._defaultThickness],[ot.HIGHLIGHT_FREE,l(this,le)]]}async addEditToolbar(){const e=await super.addEditToolbar();return e?(this._uiManager.highlightColors&&(m(this,th,new rd({editor:this})),e.addColorPicker(l(this,th))),e):null}disableEditing(){super.disableEditing(),this.div.classList.toggle("disabled",!0)}enableEditing(){super.enableEditing(),this.div.classList.toggle("disabled",!1)}fixAndSetPosition(){return super.fixAndSetPosition(w(this,J,Lc).call(this))}getBaseTranslation(){return[0,0]}getRect(e,s){return super.getRect(e,s,w(this,J,Lc).call(this))}onceAdded(e){this.annotationElementId||this.parent.addUndoableEditor(this),e&&this.div.focus()}remove(){w(this,J,Rp).call(this),this._reportTelemetry({action:"deleted"}),super.remove()}rebuild(){this.parent&&(super.rebuild(),this.div!==null&&(w(this,J,zo).call(this),this.isAttachedToDOM||this.parent.add(this)))}setParent(e){var i;let s=!1;this.parent&&!e?w(this,J,Rp).call(this):e&&(w(this,J,zo).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;l(this,le)?(e=(e-this.rotation+360)%360,i=w(n=ut,ks,_h).call(n,l(this,Ts).box,e)):i=w(r=ut,ks,_h).call(r,[this.x,this.y,this.width,this.height],e),s.updateProperties(l(this,ds),{bbox:i,root:{"data-main-rotation":e}}),s.updateProperties(l(this,Se),{bbox:w(o=ut,ks,_h).call(o,l(this,Qe).box,e),root:{"data-main-rotation":e}})}render(){if(this.div)return this.div;const e=super.render();l(this,sh)&&(e.setAttribute("aria-label",l(this,sh)),e.setAttribute("role","mark")),l(this,le)?e.classList.add("free"):this.div.addEventListener("keydown",w(this,J,rv).bind(this),{signal:this._uiManager._signal});const s=m(this,ko,document.createElement("div"));e.append(s),s.setAttribute("aria-hidden","true"),s.className="internal",s.style.clipPath=l(this,Eo);const[i,n]=this.parentDimensions;return this.setDims(this.width*i,this.height*n),qu(this,l(this,ko),["pointerover","pointerleave"]),this.enableEditing(),e}pointerover(){var e;this.isSelected||(e=this.parent)==null||e.drawLayer.updateProperties(l(this,Se),{rootClass:{hovered:!0}})}pointerleave(){var e;this.isSelected||(e=this.parent)==null||e.drawLayer.updateProperties(l(this,Se),{rootClass:{hovered:!1}})}_moveCaret(e){switch(this.parent.unselect(this),e){case 0:case 2:w(this,J,Kd).call(this,!0);break;case 1:case 3:w(this,J,Kd).call(this,!1);break}}select(){var e;super.select(),l(this,Se)&&((e=this.parent)==null||e.drawLayer.updateProperties(l(this,Se),{rootClass:{hovered:!1,selected:!0}}))}unselect(){var e;super.unselect(),l(this,Se)&&((e=this.parent)==null||e.drawLayer.updateProperties(l(this,Se),{rootClass:{selected:!1}}),l(this,le)||w(this,J,Kd).call(this,!1))}get _mustFixPosition(){return!l(this,le)}show(e=this._isVisible){super.show(e),this.parent&&(this.parent.drawLayer.updateProperties(l(this,ds),{rootClass:{hidden:!e}}),this.parent.drawLayer.updateProperties(l(this,Se),{rootClass:{hidden:!e}}))}static startHighlighting(e,s,{target:i,x:n,y:r}){const{x:o,y:h,width:c,height:u}=i.getBoundingClientRect(),d=new AbortController,f=e.combinedSignal(d),g=p=>{d.abort(),w(this,ks,lv).call(this,e,p)};window.addEventListener("blur",g,{signal:f}),window.addEventListener("pointerup",g,{signal:f}),window.addEventListener("pointerdown",es,{capture:!0,passive:!1,signal:f}),window.addEventListener("contextmenu",Gs,{signal:f}),i.addEventListener("pointermove",w(this,ks,hv).bind(this,e),{signal:f}),this._freeHighlight=new Ig({x:n,y:r},[o,h,c,u],e.scale,this._defaultThickness/2,s,.001),{id:this._freeHighlightId,clipPathId:this._freeHighlightClipId}=e.drawLayer.draw({bbox:[0,0,1,1],root:{viewBox:"0 0 1 1",fill:this._defaultColor,"fill-opacity":this._defaultOpacity},rootClass:{highlight:!0,free:!0},path:{d:this._freeHighlight.toSVGPath()}},!0,!0)}static async deserialize(e,s,i){var b,_,v,x;let n=null;if(e instanceof Ib){const{data:{quadPoints:C,rect:S,rotation:k,id:M,color:E,opacity:P,popupRef:O},parent:{page:{pageNumber:L}}}=e;n=e={annotationType:Z.HIGHLIGHT,color:Array.from(E),opacity:P,quadPoints:C,boxes:null,pageIndex:L-1,rect:S.slice(0),rotation:k,id:M,deleted:!1,popupRef:O}}else if(e instanceof Rg){const{data:{inkLists:C,rect:S,rotation:k,id:M,color:E,borderStyle:{rawWidth:P},popupRef:O},parent:{page:{pageNumber:L}}}=e;n=e={annotationType:Z.HIGHLIGHT,color:Array.from(E),thickness:P,inkLists:C,boxes:null,pageIndex:L-1,rect:S.slice(0),rotation:k,id:M,deleted:!1,popupRef:O}}const{color:r,quadPoints:o,inkLists:h,opacity:c}=e,u=await super.deserialize(e,s,i);u.color=W.makeHexColor(...r),m(u,bn,c||1),h&&m(u,Es,e.thickness),u.annotationElementId=e.id||null,u._initialData=n;const[d,f]=u.pageDimensions,[g,p]=u.pageTranslation;if(o){const C=m(u,mn,[]);for(let S=0;S<o.length;S+=8)C.push({x:(o[S]-g)/d,y:1-(o[S+1]-p)/f,width:(o[S+2]-o[S])/d,height:(o[S+1]-o[S+5])/f});w(b=u,J,Op).call(b),w(_=u,J,zo).call(_),u.rotate(u.rotation)}else if(h){m(u,le,!0);const C=h[0],S={x:C[0]-g,y:f-(C[1]-p)},k=new Ig(S,[0,0,d,f],1,l(u,Es)/2,!0,.001);for(let P=0,O=C.length;P<O;P+=2)S.x=C[P]-g,S.y=f-(C[P+1]-p),k.add(S);const{id:M,clipPathId:E}=s.drawLayer.draw({bbox:[0,0,1,1],root:{viewBox:"0 0 1 1",fill:u.color,"fill-opacity":u._defaultOpacity},rootClass:{highlight:!0,free:!0},path:{d:k.toSVGPath()}},!0,!0);w(v=u,J,qd).call(v,{highlightOutlines:k.getOutlines(),highlightId:M,clipPathId:E}),w(x=u,J,zo).call(x)}return u}serialize(e=!1){if(this.isEmpty()||e)return null;if(this.deleted)return this.serializeDeleted();const s=this.getRect(0,0),i=Pt._colorManager.convert(this.color),n={annotationType:Z.HIGHLIGHT,color:i,opacity:l(this,bn),thickness:l(this,Es),quadPoints:w(this,J,ov).call(this),outlines:w(this,J,av).call(this,s),pageIndex:this.pageIndex,rect:s,rotation:w(this,J,Lc).call(this),structTreeParentId:this._structTreeParentId};return this.annotationElementId&&!w(this,J,cv).call(this,n)?null:(n.id=this.annotationElementId,n)}renderAnnotationElement(e){return e.updateEdited({rect:this.getRect(0,0)}),null}static canCreateNewEmptyEditor(){return!1}};Za=new WeakMap,bc=new WeakMap,mn=new WeakMap,Eo=new WeakMap,th=new WeakMap,Qe=new WeakMap,yc=new WeakMap,vc=new WeakMap,ko=new WeakMap,Ts=new WeakMap,ds=new WeakMap,le=new WeakMap,eh=new WeakMap,bn=new WeakMap,Se=new WeakMap,sh=new WeakMap,Es=new WeakMap,_c=new WeakMap,J=new WeakSet,Op=function(){const e=new Fg(l(this,mn),.001);m(this,Ts,e.getOutlines()),[this.x,this.y,this.width,this.height]=l(this,Ts).box;const s=new Fg(l(this,mn),.0025,.001,this._uiManager.direction==="ltr");m(this,Qe,s.getOutlines());const{lastPoint:i}=l(this,Qe);m(this,eh,[(i[0]-this.x)/this.width,(i[1]-this.y)/this.height])},qd=function({highlightOutlines:e,highlightId:s,clipPathId:i}){var d,f;if(m(this,Ts,e),m(this,Qe,e.getNewOutline(l(this,Es)/2+1.5,.0025)),s>=0)m(this,ds,s),m(this,Eo,i),this.parent.drawLayer.finalizeDraw(s,{bbox:e.box,path:{d:e.toSVGPath()}}),m(this,Se,this.parent.drawLayer.drawOutline({rootClass:{highlightOutline:!0,free:!0},bbox:l(this,Qe).box,path:{d:l(this,Qe).toSVGPath()}},!0));else if(this.parent){const g=this.parent.viewport.rotation;this.parent.drawLayer.updateProperties(l(this,ds),{bbox:w(d=ut,ks,_h).call(d,l(this,Ts).box,(g-this.rotation+360)%360),path:{d:e.toSVGPath()}}),this.parent.drawLayer.updateProperties(l(this,Se),{bbox:w(f=ut,ks,_h).call(f,l(this,Qe).box,g),path:{d:l(this,Qe).toSVGPath()}})}const[r,o,h,c]=e.box;switch(this.rotation){case 0:this.x=r,this.y=o,this.width=h,this.height=c;break;case 90:{const[g,p]=this.parentDimensions;this.x=o,this.y=1-r,this.width=h*p/g,this.height=c*g/p;break}case 180:this.x=1-r,this.y=1-o,this.width=h,this.height=c;break;case 270:{const[g,p]=this.parentDimensions;this.x=1-o,this.y=r,this.width=h*p/g,this.height=c*g/p;break}}const{lastPoint:u}=l(this,Qe);m(this,eh,[(u[0]-r)/h,(u[1]-o)/c])},sv=function(e){const s=(r,o)=>{var h,c;this.color=r,m(this,bn,o),(h=this.parent)==null||h.drawLayer.updateProperties(l(this,ds),{root:{fill:r,"fill-opacity":o}}),(c=l(this,th))==null||c.updateColor(r)},i=this.color,n=l(this,bn);this.addCommands({cmd:s.bind(this,e,ut._defaultOpacity),undo:s.bind(this,i,n),post:this._uiManager.updateUI.bind(this._uiManager,this),mustExec:!0,type:ot.HIGHLIGHT_COLOR,overwriteIfSameType:!0,keepUndo:!0}),this._reportTelemetry({action:"color_changed",color:this._uiManager.highlightColorNames.get(e)},!0)},iv=function(e){const s=l(this,Es),i=n=>{m(this,Es,n),w(this,J,nv).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:ot.INK_THICKNESS,overwriteIfSameType:!0,keepUndo:!0}),this._reportTelemetry({action:"thickness_changed",thickness:e},!0)},nv=function(e){if(!l(this,le))return;w(this,J,qd).call(this,{highlightOutlines:l(this,Ts).getNewOutline(e/2)}),this.fixAndSetPosition();const[s,i]=this.parentDimensions;this.setDims(this.width*s,this.height*i)},Rp=function(){l(this,ds)===null||!this.parent||(this.parent.drawLayer.remove(l(this,ds)),m(this,ds,null),this.parent.drawLayer.remove(l(this,Se)),m(this,Se,null))},zo=function(e=this.parent){l(this,ds)===null&&({id:Ge(this,ds)._,clipPathId:Ge(this,Eo)._}=e.drawLayer.draw({bbox:l(this,Ts).box,root:{viewBox:"0 0 1 1",fill:this.color,"fill-opacity":l(this,bn)},rootClass:{highlight:!0,free:l(this,le)},path:{d:l(this,Ts).toSVGPath()}},!1,!0),m(this,Se,e.drawLayer.drawOutline({rootClass:{highlightOutline:!0,free:l(this,le)},bbox:l(this,Qe).box,path:{d:l(this,Qe).toSVGPath()}},l(this,le))),l(this,ko)&&(l(this,ko).style.clipPath=l(this,Eo)))},ks=new WeakSet,_h=function([e,s,i,n],r){switch(r){case 90:return[1-s-n,e,n,i];case 180:return[1-e-i,1-s-n,i,n];case 270:return[s,1-e-i,n,i]}return[e,s,i,n]},rv=function(e){ut._keyboardManager.exec(this,e)},Kd=function(e){if(!l(this,Za))return;const s=window.getSelection();e?s.setPosition(l(this,Za),l(this,bc)):s.setPosition(l(this,yc),l(this,vc))},Lc=function(){return l(this,le)?this.rotation:0},ov=function(){if(l(this,le))return null;const[e,s]=this.pageDimensions,[i,n]=this.pageTranslation,r=l(this,mn),o=new Float32Array(r.length*8);let h=0;for(const{x:c,y:u,width:d,height:f}of r){const g=c*e+i,p=(1-u)*s+n;o[h]=o[h+4]=g,o[h+1]=o[h+3]=p,o[h+2]=o[h+6]=g+d*e,o[h+5]=o[h+7]=p-f*s,h+=8}return o},av=function(e){return l(this,Ts).serialize(e,w(this,J,Lc).call(this))},hv=function(e,s){this._freeHighlight.add(s)&&e.drawLayer.updateProperties(this._freeHighlightId,{path:{d:this._freeHighlight.toSVGPath()}})},lv=function(e,s){this._freeHighlight.isEmpty()?e.drawLayer.remove(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=""},cv=function(e){const{color:s}=this._initialData;return e.color.some((i,n)=>i!==s[n])},y(ut,ks),$(ut,"_defaultColor",null),$(ut,"_defaultOpacity",1),$(ut,"_defaultThickness",12),$(ut,"_type","highlight"),$(ut,"_editorType",Z.HIGHLIGHT),$(ut,"_freeHighlightId",-1),$(ut,"_freeHighlight",null),$(ut,"_freeHighlightClipId","");let od=ut;class WS{constructor(){y(this,Mo,Object.create(null))}updateProperty(t,e){this[t]=e,this.updateSVGProperty(t,e)}updateProperties(t){if(t)for(const[e,s]of Object.entries(t))this.updateProperty(e,s)}updateSVGProperty(t,e){l(this,Mo)[t]=e}toSVGProperties(){const t=l(this,Mo);return m(this,Mo,Object.create(null)),{root:t}}reset(){m(this,Mo,Object.create(null))}updateAll(t=this){this.updateProperties(t)}clone(){vt("Not implemented")}}Mo=new WeakMap;const H=class H extends Pt{constructor(e){super(e);y(this,lt);y(this,fs,null);y(this,ih);$(this,"_drawId",null);m(this,ih,e.mustBeCommitted||!1),e.drawOutlines&&(w(this,lt,Lp).call(this,e),w(this,lt,Fc).call(this))}static _mergeSVGProperties(e,s){const i=new Set(Object.keys(e));for(const[n,r]of Object.entries(s))i.has(n)?Object.assign(e[n],r):e[n]=r;return e}static getDefaultDrawingOptions(e){vt("Not implemented")}static get typesMap(){vt("Not implemented")}static get isDrawer(){return!0}static get supportMultipleDrawings(){return!1}static updateDefaultParams(e,s){const i=this.typesMap.get(e);i&&this._defaultDrawingOptions.updateProperty(i,s),this._currentParent&&(l(H,ne).updateProperty(i,s),this._currentParent.drawLayer.updateProperties(this._currentDrawId,this._defaultDrawingOptions.toSVGProperties()))}updateParams(e,s){const i=this.constructor.typesMap.get(e);i&&this._updateProperty(e,i,s)}static get defaultPropertiesToUpdate(){const e=[],s=this._defaultDrawingOptions;for(const[i,n]of this.typesMap)e.push([i,s[n]]);return e}get propertiesToUpdate(){const e=[],{_drawingOptions:s}=this;for(const[i,n]of this.constructor.typesMap)e.push([i,s[n]]);return e}_updateProperty(e,s,i){const n=this._drawingOptions,r=n[s],o=h=>{var u;n.updateProperty(s,h);const c=l(this,fs).updateProperty(s,h);c&&w(this,lt,Ic).call(this,c),(u=this.parent)==null||u.drawLayer.updateProperties(this._drawId,n.toSVGProperties())};this.addCommands({cmd:o.bind(this,i),undo:o.bind(this,r),post:this._uiManager.updateUI.bind(this._uiManager,this),mustExec:!0,type:e,overwriteIfSameType:!0,keepUndo:!0})}_onResizing(){var e;(e=this.parent)==null||e.drawLayer.updateProperties(this._drawId,H._mergeSVGProperties(l(this,fs).getPathResizingSVGProperties(w(this,lt,Qd).call(this)),{bbox:w(this,lt,wh).call(this)}))}_onResized(){var e;(e=this.parent)==null||e.drawLayer.updateProperties(this._drawId,H._mergeSVGProperties(l(this,fs).getPathResizedSVGProperties(w(this,lt,Qd).call(this)),{bbox:w(this,lt,wh).call(this)}))}_onTranslating(e,s){var i;(i=this.parent)==null||i.drawLayer.updateProperties(this._drawId,{bbox:w(this,lt,wh).call(this,e,s)})}_onTranslated(){var e;(e=this.parent)==null||e.drawLayer.updateProperties(this._drawId,H._mergeSVGProperties(l(this,fs).getPathTranslatedSVGProperties(w(this,lt,Qd).call(this),this.parentDimensions),{bbox:w(this,lt,wh).call(this)}))}_onStartDragging(){var e;(e=this.parent)==null||e.drawLayer.updateProperties(this._drawId,{rootClass:{moving:!0}})}_onStopDragging(){var e;(e=this.parent)==null||e.drawLayer.updateProperties(this._drawId,{rootClass:{moving:!1}})}commit(){super.commit(),this.disableEditMode(),this.disableEditing()}disableEditing(){super.disableEditing(),this.div.classList.toggle("disabled",!0)}enableEditing(){super.enableEditing(),this.div.classList.toggle("disabled",!1)}getBaseTranslation(){return[0,0]}get isResizable(){return!0}onceAdded(e){this.annotationElementId||this.parent.addUndoableEditor(this),this._isDraggable=!0,l(this,ih)&&(m(this,ih,!1),this.commit(),this.parent.setSelected(this),e&&this.isOnScreen&&this.div.focus())}remove(){w(this,lt,Ip).call(this),super.remove()}rebuild(){this.parent&&(super.rebuild(),this.div!==null&&(w(this,lt,Fc).call(this),w(this,lt,Ic).call(this,l(this,fs).box),this.isAttachedToDOM||this.parent.add(this)))}setParent(e){var i;let s=!1;this.parent&&!e?(this._uiManager.removeShouldRescale(this),w(this,lt,Ip).call(this)):e&&(this._uiManager.addShouldRescale(this),w(this,lt,Fc).call(this,e),s=!this.parent&&((i=this.div)==null?void 0:i.classList.contains("selectedEditor"))),super.setParent(e),s&&this.select()}rotate(){this.parent&&this.parent.drawLayer.updateProperties(this._drawId,H._mergeSVGProperties({bbox:w(this,lt,wh).call(this)},l(this,fs).updateRotation((this.parentRotation-this.rotation+360)%360)))}onScaleChanging(){this.parent&&w(this,lt,Ic).call(this,l(this,fs).updateParentDimensions(this.parentDimensions,this.parent.scale))}static onScaleChangingWhenDrawing(){}render(){if(this.div)return this.div;const e=super.render();e.classList.add("draw");const s=document.createElement("div");e.append(s),s.setAttribute("aria-hidden","true"),s.className="internal";const[i,n]=this.parentDimensions;return this.setDims(this.width*i,this.height*n),this._uiManager.addShouldRescale(this),this.disableEditing(),e}static createDrawerInstance(e,s,i,n,r){vt("Not implemented")}static startDrawing(e,s,i,n){var _;const{target:r,offsetX:o,offsetY:h,pointerId:c,pointerType:u}=n;if(l(H,or)&&l(H,or)!==u)return;const{viewport:{rotation:d}}=e,{width:f,height:g}=r.getBoundingClientRect(),p=m(H,Po,new AbortController),b=e.combinedSignal(p);if(l(H,rr)||m(H,rr,c),l(H,or)??m(H,or,u),window.addEventListener("pointerup",v=>{var x;l(H,rr)===v.pointerId?this._endDraw(v):(x=l(H,ar))==null||x.delete(v.pointerId)},{signal:b}),window.addEventListener("pointercancel",v=>{var x;l(H,rr)===v.pointerId?this._currentParent.endDrawingSession():(x=l(H,ar))==null||x.delete(v.pointerId)},{signal:b}),window.addEventListener("pointerdown",v=>{l(H,or)===v.pointerType&&((l(H,ar)||m(H,ar,new Set)).add(v.pointerId),l(H,ne).isCancellable()&&(l(H,ne).removeLastElement(),l(H,ne).isEmpty()?this._currentParent.endDrawingSession(!0):this._endDraw(null)))},{capture:!0,passive:!1,signal:b}),window.addEventListener("contextmenu",Gs,{signal:b}),r.addEventListener("pointermove",this._drawMove.bind(this),{signal:b}),r.addEventListener("touchmove",v=>{v.timeStamp===l(H,Oo)&&es(v)},{signal:b}),e.toggleDrawing(),(_=s._editorUndoBar)==null||_.hide(),l(H,ne)){e.drawLayer.updateProperties(this._currentDrawId,l(H,ne).startNew(o,h,f,g,d));return}s.updateUIForDefaultProperties(this),m(H,ne,this.createDrawerInstance(o,h,f,g,d)),m(H,Do,this.getDefaultDrawingOptions()),this._currentParent=e,{id:this._currentDrawId}=e.drawLayer.draw(this._mergeSVGProperties(l(H,Do).toSVGProperties(),l(H,ne).defaultSVGProperties),!0,!1)}static _drawMove(e){var r;if(m(H,Oo,-1),!l(H,ne))return;const{offsetX:s,offsetY:i,pointerId:n}=e;if(l(H,rr)===n){if(((r=l(H,ar))==null?void 0:r.size)>=1){this._endDraw(e);return}this._currentParent.drawLayer.updateProperties(this._currentDrawId,l(H,ne).add(s,i)),m(H,Oo,e.timeStamp),es(e)}}static _cleanup(e){e&&(this._currentDrawId=-1,this._currentParent=null,m(H,ne,null),m(H,Do,null),m(H,or,null),m(H,Oo,NaN)),l(H,Po)&&(l(H,Po).abort(),m(H,Po,null),m(H,rr,NaN),m(H,ar,null))}static _endDraw(e){const s=this._currentParent;if(s){if(s.toggleDrawing(!0),this._cleanup(!1),e&&s.drawLayer.updateProperties(this._currentDrawId,l(H,ne).end(e.offsetX,e.offsetY)),this.supportMultipleDrawings){const i=l(H,ne),n=this._currentDrawId,r=i.getLastElement();s.addCommands({cmd:()=>{s.drawLayer.updateProperties(n,i.setLastElement(r))},undo:()=>{s.drawLayer.updateProperties(n,i.removeLastElement())},mustExec:!1,type:ot.DRAW_STEP});return}this.endDrawing(!1)}}static endDrawing(e){const s=this._currentParent;if(!s)return null;if(s.toggleDrawing(!0),s.cleanUndoStack(ot.DRAW_STEP),!l(H,ne).isEmpty()){const{pageDimensions:[i,n],scale:r}=s,o=s.createAndAddNewEditor({offsetX:0,offsetY:0},!1,{drawId:this._currentDrawId,drawOutlines:l(H,ne).getOutlines(i*r,n*r,r,this._INNER_MARGIN),drawingOptions:l(H,Do),mustBeCommitted:!e});return this._cleanup(!0),o}return s.drawLayer.remove(this._currentDrawId),this._cleanup(!0),null}createDrawingOptions(e){}static deserializeDraw(e,s,i,n,r,o){vt("Not implemented")}static async deserialize(e,s,i){var d,f;const{rawDims:{pageWidth:n,pageHeight:r,pageX:o,pageY:h}}=s.viewport,c=this.deserializeDraw(o,h,n,r,this._INNER_MARGIN,e),u=await super.deserialize(e,s,i);return u.createDrawingOptions(e),w(d=u,lt,Lp).call(d,{drawOutlines:c}),w(f=u,lt,Fc).call(f),u.onScaleChanging(),u.rotate(),u}serializeDraw(e){const[s,i]=this.pageTranslation,[n,r]=this.pageDimensions;return l(this,fs).serialize([s,i,n,r],e)}renderAnnotationElement(e){return e.updateEdited({rect:this.getRect(0,0)}),null}static canCreateNewEmptyEditor(){return!1}};fs=new WeakMap,ih=new WeakMap,ne=new WeakMap,Po=new WeakMap,Do=new WeakMap,rr=new WeakMap,or=new WeakMap,ar=new WeakMap,Oo=new WeakMap,lt=new WeakSet,Lp=function({drawOutlines:e,drawId:s,drawingOptions:i}){m(this,fs,e),this._drawingOptions||(this._drawingOptions=i),s>=0?(this._drawId=s,this.parent.drawLayer.finalizeDraw(s,e.defaultProperties)):this._drawId=w(this,lt,Fp).call(this,e,this.parent),w(this,lt,Ic).call(this,e.box)},Fp=function(e,s){const{id:i}=s.drawLayer.draw(H._mergeSVGProperties(this._drawingOptions.toSVGProperties(),e.defaultSVGProperties),!1,!1);return i},Ip=function(){this._drawId===null||!this.parent||(this.parent.drawLayer.remove(this._drawId),this._drawId=null,this._drawingOptions.reset())},Fc=function(e=this.parent){if(!(this._drawId!==null&&this.parent===e)){if(this._drawId!==null){this.parent.drawLayer.updateParent(this._drawId,e.drawLayer);return}this._drawingOptions.updateAll(),this._drawId=w(this,lt,Fp).call(this,l(this,fs),e)}},uv=function([e,s,i,n]){const{parentDimensions:[r,o],rotation:h}=this;switch(h){case 90:return[s,1-e,i*(o/r),n*(r/o)];case 180:return[1-e,1-s,i,n];case 270:return[1-s,e,i*(o/r),n*(r/o)];default:return[e,s,i,n]}},Qd=function(){const{x:e,y:s,width:i,height:n,parentDimensions:[r,o],rotation:h}=this;switch(h){case 90:return[1-s,e,i*(r/o),n*(o/r)];case 180:return[1-e,1-s,i,n];case 270:return[s,1-e,i*(r/o),n*(o/r)];default:return[e,s,i,n]}},Ic=function(e){if([this.x,this.y,this.width,this.height]=w(this,lt,uv).call(this,e),this.div){this.fixAndSetPosition();const[s,i]=this.parentDimensions;this.setDims(this.width*s,this.height*i)}this._onResized()},wh=function(){const{x:e,y:s,width:i,height:n,rotation:r,parentRotation:o,parentDimensions:[h,c]}=this;switch((r*4+o)/90){case 1:return[1-s-n,e,n,i];case 2:return[1-e-i,1-s-n,i,n];case 3:return[s,1-e-i,n,i];case 4:return[e,s-i*(h/c),n*(c/h),i*(h/c)];case 5:return[1-s,e,i*(h/c),n*(c/h)];case 6:return[1-e-n*(c/h),1-s,n*(c/h),i*(h/c)];case 7:return[s-i*(h/c),1-e-n*(c/h),i*(h/c),n*(c/h)];case 8:return[e-i,s-n,i,n];case 9:return[1-s,e-i,n,i];case 10:return[1-e,1-s,i,n];case 11:return[s-n,1-e,n,i];case 12:return[e-n*(c/h),s,n*(c/h),i*(h/c)];case 13:return[1-s-i*(h/c),e-n*(c/h),i*(h/c),n*(c/h)];case 14:return[1-e,1-s-i*(h/c),n*(c/h),i*(h/c)];case 15:return[s,1-e,i*(h/c),n*(c/h)];default:return[e,s,i,n]}},$(H,"_currentDrawId",-1),$(H,"_currentParent",null),y(H,ne,null),y(H,Po,null),y(H,Do,null),y(H,rr,NaN),y(H,or,null),y(H,ar,null),y(H,Oo,NaN),$(H,"_INNER_MARGIN",3);let Ng=H;class US{constructor(t,e,s,i,n,r){y(this,rh);y(this,xi,new Float64Array(6));y(this,re);y(this,oe);y(this,Ro);y(this,nh);y(this,Ne);y(this,ce,"");y(this,Ms,0);y(this,Lo,new ad);y(this,Fo);y(this,Io);m(this,Fo,s),m(this,Io,i),m(this,Ro,n),m(this,nh,r),[t,e]=w(this,rh,Jd).call(this,t,e);const o=m(this,re,[NaN,NaN,NaN,NaN,t,e]);m(this,Ne,[t,e]),m(this,oe,[{line:o,points:l(this,Ne)}]),l(this,xi).set(o,0)}updateProperty(t,e){t==="stroke-width"&&m(this,nh,e)}isEmpty(){return!l(this,oe)||l(this,oe).length===0}isCancellable(){return l(this,Ne).length<=10}add(t,e){[t,e]=w(this,rh,Jd).call(this,t,e);const[s,i,n,r]=l(this,xi).subarray(2,6),o=t-n,h=e-r;return Math.hypot(l(this,Fo)*o,l(this,Io)*h)<=2?null:(l(this,Ne).push(t,e),isNaN(s)?(l(this,xi).set([n,r,t,e],2),l(this,re).push(NaN,NaN,NaN,NaN,t,e),{path:{d:this.toSVGPath()}}):(isNaN(l(this,xi)[0])&&l(this,re).splice(6,6),l(this,xi).set([s,i,n,r,t,e],0),l(this,re).push(...B.createBezierPoints(s,i,n,r,t,e)),{path:{d:this.toSVGPath()}}))}end(t,e){const s=this.add(t,e);return s||(l(this,Ne).length===2?{path:{d:this.toSVGPath()}}:null)}startNew(t,e,s,i,n){m(this,Fo,s),m(this,Io,i),m(this,Ro,n),[t,e]=w(this,rh,Jd).call(this,t,e);const r=m(this,re,[NaN,NaN,NaN,NaN,t,e]);m(this,Ne,[t,e]);const o=l(this,oe).at(-1);return o&&(o.line=new Float32Array(o.line),o.points=new Float32Array(o.points)),l(this,oe).push({line:r,points:l(this,Ne)}),l(this,xi).set(r,0),m(this,Ms,0),this.toSVGPath(),null}getLastElement(){return l(this,oe).at(-1)}setLastElement(t){return l(this,oe)?(l(this,oe).push(t),m(this,re,t.line),m(this,Ne,t.points),m(this,Ms,0),{path:{d:this.toSVGPath()}}):l(this,Lo).setLastElement(t)}removeLastElement(){if(!l(this,oe))return l(this,Lo).removeLastElement();l(this,oe).pop(),m(this,ce,"");for(let t=0,e=l(this,oe).length;t<e;t++){const{line:s,points:i}=l(this,oe)[t];m(this,re,s),m(this,Ne,i),m(this,Ms,0),this.toSVGPath()}return{path:{d:l(this,ce)}}}toSVGPath(){const t=B.svgRound(l(this,re)[4]),e=B.svgRound(l(this,re)[5]);if(l(this,Ne).length===2)return m(this,ce,`${l(this,ce)} M ${t} ${e} Z`),l(this,ce);if(l(this,Ne).length<=6){const i=l(this,ce).lastIndexOf("M");m(this,ce,`${l(this,ce).slice(0,i)} M ${t} ${e}`),m(this,Ms,6)}if(l(this,Ne).length===4){const i=B.svgRound(l(this,re)[10]),n=B.svgRound(l(this,re)[11]);return m(this,ce,`${l(this,ce)} L ${i} ${n}`),m(this,Ms,12),l(this,ce)}const s=[];l(this,Ms)===0&&(s.push(`M ${t} ${e}`),m(this,Ms,6));for(let i=l(this,Ms),n=l(this,re).length;i<n;i+=6){const[r,o,h,c,u,d]=l(this,re).slice(i,i+6).map(B.svgRound);s.push(`C${r} ${o} ${h} ${c} ${u} ${d}`)}return m(this,ce,l(this,ce)+s.join(" ")),m(this,Ms,l(this,re).length),l(this,ce)}getOutlines(t,e,s,i){const n=l(this,oe).at(-1);return n.line=new Float32Array(n.line),n.points=new Float32Array(n.points),l(this,Lo).build(l(this,oe),t,e,s,l(this,Ro),l(this,nh),i),m(this,xi,null),m(this,re,null),m(this,oe,null),m(this,ce,null),l(this,Lo)}get defaultSVGProperties(){return{root:{viewBox:"0 0 10000 10000"},rootClass:{draw:!0},bbox:[0,0,1,1]}}}xi=new WeakMap,re=new WeakMap,oe=new WeakMap,Ro=new WeakMap,nh=new WeakMap,Ne=new WeakMap,ce=new WeakMap,Ms=new WeakMap,Lo=new WeakMap,Fo=new WeakMap,Io=new WeakMap,rh=new WeakSet,Jd=function(t,e){return B._normalizePoint(t,e,l(this,Fo),l(this,Io),l(this,Ro))};const Yg=class Yg extends B{constructor(){super(...arguments);y(this,ue);y(this,je);y(this,wc,0);y(this,xc);y(this,gs);y(this,Si);y(this,Ci);y(this,oh);y(this,ah);y(this,hh)}build(e,s,i,n,r,o,h){m(this,Si,s),m(this,Ci,i),m(this,oh,n),m(this,ah,r),m(this,hh,o),m(this,xc,h??0),m(this,gs,e),w(this,ue,fv).call(this)}setLastElement(e){return l(this,gs).push(e),{path:{d:this.toSVGPath()}}}removeLastElement(){return l(this,gs).pop(),{path:{d:this.toSVGPath()}}}toSVGPath(){const e=[];for(const{line:s}of l(this,gs)){if(e.push(`M${B.svgRound(s[4])} ${B.svgRound(s[5])}`),s.length===6){e.push("Z");continue}if(s.length===12){e.push(`L${B.svgRound(s[10])} ${B.svgRound(s[11])}`);continue}for(let i=6,n=s.length;i<n;i+=6){const[r,o,h,c,u,d]=s.subarray(i,i+6).map(B.svgRound);e.push(`C${r} ${o} ${h} ${c} ${u} ${d}`)}}return e.join("")}serialize([e,s,i,n],r){const o=[],h=[],[c,u,d,f]=w(this,ue,dv).call(this);let g,p,b,_,v,x,C,S,k;switch(l(this,ah)){case 0:k=B._rescale,g=e,p=s+n,b=i,_=-n,v=e+c*i,x=s+(1-u-f)*n,C=e+(c+d)*i,S=s+(1-u)*n;break;case 90:k=B._rescaleAndSwap,g=e,p=s,b=i,_=n,v=e+u*i,x=s+c*n,C=e+(u+f)*i,S=s+(c+d)*n;break;case 180:k=B._rescale,g=e+i,p=s,b=-i,_=n,v=e+(1-c-d)*i,x=s+u*n,C=e+(1-c)*i,S=s+(u+f)*n;break;case 270:k=B._rescaleAndSwap,g=e+i,p=s+n,b=-i,_=-n,v=e+(1-u-f)*i,x=s+(1-c-d)*n,C=e+(1-u)*i,S=s+(1-c)*n;break}for(const{line:M,points:E}of l(this,gs))o.push(k(M,g,p,b,_,r?new Array(M.length):null)),h.push(k(E,g,p,b,_,r?new Array(E.length):null));return{lines:o,points:h,rect:[v,x,C,S]}}static deserialize(e,s,i,n,r,{paths:{lines:o,points:h},rotation:c,thickness:u}){const d=[];let f,g,p,b,_;switch(c){case 0:_=B._rescale,f=-e/i,g=s/n+1,p=1/i,b=-1/n;break;case 90:_=B._rescaleAndSwap,f=-s/n,g=-e/i,p=1/n,b=1/i;break;case 180:_=B._rescale,f=e/i+1,g=-s/n,p=-1/i,b=1/n;break;case 270:_=B._rescaleAndSwap,f=s/n+1,g=e/i+1,p=-1/n,b=-1/i;break}if(!o){o=[];for(const x of h){const C=x.length;if(C===2){o.push(new Float32Array([NaN,NaN,NaN,NaN,x[0],x[1]]));continue}if(C===4){o.push(new Float32Array([NaN,NaN,NaN,NaN,x[0],x[1],NaN,NaN,NaN,NaN,x[2],x[3]]));continue}const S=new Float32Array(3*(C-2));o.push(S);let[k,M,E,P]=x.subarray(0,4);S.set([NaN,NaN,NaN,NaN,k,M],0);for(let O=4;O<C;O+=2){const L=x[O],R=x[O+1];S.set(B.createBezierPoints(k,M,E,P,L,R),(O-2)*3),[k,M,E,P]=[E,P,L,R]}}}for(let x=0,C=o.length;x<C;x++)d.push({line:_(o[x].map(S=>S??NaN),f,g,p,b),points:_(h[x].map(S=>S??NaN),f,g,p,b)});const v=new Yg;return v.build(d,i,n,1,c,u,r),v}get box(){return l(this,je)}updateProperty(e,s){return e==="stroke-width"?w(this,ue,gv).call(this,s):null}updateParentDimensions([e,s],i){const[n,r]=w(this,ue,Sn).call(this);m(this,Si,e),m(this,Ci,s),m(this,oh,i);const[o,h]=w(this,ue,Sn).call(this),c=o-n,u=h-r,d=l(this,je);return d[0]-=c,d[1]-=u,d[2]+=2*c,d[3]+=2*u,d}updateRotation(e){return m(this,wc,e),{path:{transform:this.rotationTransform}}}get viewBox(){return l(this,je).map(B.svgRound).join(" ")}get defaultProperties(){const[e,s]=l(this,je);return{root:{viewBox:this.viewBox},path:{"transform-origin":`${B.svgRound(e)} ${B.svgRound(s)}`}}}get rotationTransform(){const[,,e,s]=l(this,je);let i=0,n=0,r=0,o=0,h=0,c=0;switch(l(this,wc)){case 90:n=s/e,r=-e/s,h=e;break;case 180:i=-1,o=-1,h=e,c=s;break;case 270:n=-s/e,r=e/s,c=s;break;default:return""}return`matrix(${i} ${n} ${r} ${o} ${B.svgRound(h)} ${B.svgRound(c)})`}getPathResizingSVGProperties([e,s,i,n]){const[r,o]=w(this,ue,Sn).call(this),[h,c,u,d]=l(this,je);if(Math.abs(u-r)<=B.PRECISION||Math.abs(d-o)<=B.PRECISION){const _=e+i/2-(h+u/2),v=s+n/2-(c+d/2);return{path:{"transform-origin":`${B.svgRound(e)} ${B.svgRound(s)}`,transform:`${this.rotationTransform} translate(${_} ${v})`}}}const f=(i-2*r)/(u-2*r),g=(n-2*o)/(d-2*o),p=u/i,b=d/n;return{path:{"transform-origin":`${B.svgRound(h)} ${B.svgRound(c)}`,transform:`${this.rotationTransform} scale(${p} ${b}) translate(${B.svgRound(r)} ${B.svgRound(o)}) scale(${f} ${g}) translate(${B.svgRound(-r)} ${B.svgRound(-o)})`}}}getPathResizedSVGProperties([e,s,i,n]){const[r,o]=w(this,ue,Sn).call(this),h=l(this,je),[c,u,d,f]=h;if(h[0]=e,h[1]=s,h[2]=i,h[3]=n,Math.abs(d-r)<=B.PRECISION||Math.abs(f-o)<=B.PRECISION){const v=e+i/2-(c+d/2),x=s+n/2-(u+f/2);for(const{line:C,points:S}of l(this,gs))B._translate(C,v,x,C),B._translate(S,v,x,S);return{root:{viewBox:this.viewBox},path:{"transform-origin":`${B.svgRound(e)} ${B.svgRound(s)}`,transform:this.rotationTransform||null,d:this.toSVGPath()}}}const g=(i-2*r)/(d-2*r),p=(n-2*o)/(f-2*o),b=-g*(c+r)+e+r,_=-p*(u+o)+s+o;if(g!==1||p!==1||b!==0||_!==0)for(const{line:v,points:x}of l(this,gs))B._rescale(v,b,_,g,p,v),B._rescale(x,b,_,g,p,x);return{root:{viewBox:this.viewBox},path:{"transform-origin":`${B.svgRound(e)} ${B.svgRound(s)}`,transform:this.rotationTransform||null,d:this.toSVGPath()}}}getPathTranslatedSVGProperties([e,s],i){const[n,r]=i,o=l(this,je),h=e-o[0],c=s-o[1];if(l(this,Si)===n&&l(this,Ci)===r)for(const{line:u,points:d}of l(this,gs))B._translate(u,h,c,u),B._translate(d,h,c,d);else{const u=l(this,Si)/n,d=l(this,Ci)/r;m(this,Si,n),m(this,Ci,r);for(const{line:f,points:g}of l(this,gs))B._rescale(f,h,c,u,d,f),B._rescale(g,h,c,u,d,g);o[2]*=u,o[3]*=d}return o[0]=e,o[1]=s,{root:{viewBox:this.viewBox},path:{d:this.toSVGPath(),"transform-origin":`${B.svgRound(e)} ${B.svgRound(s)}`}}}get defaultSVGProperties(){const e=l(this,je);return{root:{viewBox:this.viewBox},rootClass:{draw:!0},path:{d:this.toSVGPath(),"transform-origin":`${B.svgRound(e[0])} ${B.svgRound(e[1])}`,transform:this.rotationTransform||null},bbox:e}}};je=new WeakMap,wc=new WeakMap,xc=new WeakMap,gs=new WeakMap,Si=new WeakMap,Ci=new WeakMap,oh=new WeakMap,ah=new WeakMap,hh=new WeakMap,ue=new WeakSet,Sn=function(e=l(this,hh)){const s=l(this,xc)+e/2*l(this,oh);return l(this,ah)%180===0?[s/l(this,Si),s/l(this,Ci)]:[s/l(this,Ci),s/l(this,Si)]},dv=function(){const[e,s,i,n]=l(this,je),[r,o]=w(this,ue,Sn).call(this,0);return[e+r,s+o,i-2*r,n-2*o]},fv=function(){const e=m(this,je,new Float32Array([1/0,1/0,-1/0,-1/0]));for(const{line:n}of l(this,gs)){if(n.length<=12){for(let h=4,c=n.length;h<c;h+=6){const[u,d]=n.subarray(h,h+2);e[0]=Math.min(e[0],u),e[1]=Math.min(e[1],d),e[2]=Math.max(e[2],u),e[3]=Math.max(e[3],d)}continue}let r=n[4],o=n[5];for(let h=6,c=n.length;h<c;h+=6){const[u,d,f,g,p,b]=n.subarray(h,h+6);W.bezierBoundingBox(r,o,u,d,f,g,p,b,e),r=p,o=b}}const[s,i]=w(this,ue,Sn).call(this);e[0]=Math.min(1,Math.max(0,e[0]-s)),e[1]=Math.min(1,Math.max(0,e[1]-i)),e[2]=Math.min(1,Math.max(0,e[2]+s)),e[3]=Math.min(1,Math.max(0,e[3]+i)),e[2]-=e[0],e[3]-=e[1]},gv=function(e){const[s,i]=w(this,ue,Sn).call(this);m(this,hh,e);const[n,r]=w(this,ue,Sn).call(this),[o,h]=[n-s,r-i],c=l(this,je);return c[0]-=o,c[1]-=h,c[2]+=2*o,c[3]+=2*h,c};let ad=Yg;const $g=class $g extends WS{constructor(e){super();y(this,lh);m(this,lh,e),super.updateProperties({fill:"none",stroke:Pt._defaultLineColor,"stroke-opacity":1,"stroke-width":1,"stroke-linecap":"round","stroke-linejoin":"round","stroke-miterlimit":10})}updateSVGProperty(e,s){e==="stroke-width"&&(s??(s=this["stroke-width"]),s*=l(this,lh).realScale),super.updateSVGProperty(e,s)}clone(){const e=new $g(l(this,lh));return e.updateAll(this),e}};lh=new WeakMap;let jg=$g;const ch=class ch extends Ng{constructor(e){super({...e,name:"inkEditor"});y(this,Ad);this._willKeepAspectRatio=!0}static initialize(e,s){Pt.initialize(e,s),this._defaultDrawingOptions=new jg(s.viewParameters)}static getDefaultDrawingOptions(e){const s=this._defaultDrawingOptions.clone();return s.updateProperties(e),s}static get supportMultipleDrawings(){return!0}static get typesMap(){return st(this,"typesMap",new Map([[ot.INK_THICKNESS,"stroke-width"],[ot.INK_COLOR,"stroke"],[ot.INK_OPACITY,"stroke-opacity"]]))}static createDrawerInstance(e,s,i,n,r){return new US(e,s,i,n,r,this._defaultDrawingOptions["stroke-width"])}static deserializeDraw(e,s,i,n,r,o){return ad.deserialize(e,s,i,n,r,o)}static async deserialize(e,s,i){let n=null;if(e instanceof Rg){const{data:{inkLists:o,rect:h,rotation:c,id:u,color:d,opacity:f,borderStyle:{rawWidth:g},popupRef:p},parent:{page:{pageNumber:b}}}=e;n=e={annotationType:Z.INK,color:Array.from(d),thickness:g,opacity:f,paths:{points:o},boxes:null,pageIndex:b-1,rect:h.slice(0),rotation:c,id:u,deleted:!1,popupRef:p}}const r=await super.deserialize(e,s,i);return r.annotationElementId=e.id||null,r._initialData=n,r}onScaleChanging(){if(!this.parent)return;super.onScaleChanging();const{_drawId:e,_drawingOptions:s,parent:i}=this;s.updateSVGProperty("stroke-width"),i.drawLayer.updateProperties(e,s.toSVGProperties())}static onScaleChangingWhenDrawing(){const e=this._currentParent;e&&(super.onScaleChangingWhenDrawing(),this._defaultDrawingOptions.updateSVGProperty("stroke-width"),e.drawLayer.updateProperties(this._currentDrawId,this._defaultDrawingOptions.toSVGProperties()))}createDrawingOptions({color:e,thickness:s,opacity:i}){this._drawingOptions=ch.getDefaultDrawingOptions({stroke:W.makeHexColor(...e),"stroke-width":s,"stroke-opacity":i})}serialize(e=!1){if(this.isEmpty())return null;if(this.deleted)return this.serializeDeleted();const{lines:s,points:i,rect:n}=this.serializeDraw(e),{_drawingOptions:{stroke:r,"stroke-opacity":o,"stroke-width":h}}=this,c={annotationType:Z.INK,color:Pt._colorManager.convert(r),opacity:o,thickness:h,paths:{lines:s,points:i},pageIndex:this.pageIndex,rect:n,rotation:this.rotation,structTreeParentId:this._structTreeParentId};return e?c:this.annotationElementId&&!w(this,Ad,pv).call(this,c)?null:(c.id=this.annotationElementId,c)}renderAnnotationElement(e){const{points:s,rect:i}=this.serializeDraw(!1);return e.updateEdited({rect:i,thickness:this._drawingOptions["stroke-width"],points:s}),null}};Ad=new WeakSet,pv=function(e){const{color:s,thickness:i,opacity:n,pageIndex:r}=this._initialData;return this._hasBeenMoved||this._hasBeenResized||e.color.some((o,h)=>o!==s[h])||e.thickness!==i||e.opacity!==n||e.pageIndex!==r},$(ch,"_type","ink"),$(ch,"_editorType",Z.INK),$(ch,"_defaultDrawingOptions",null);let Bg=ch;const Sc=class Sc extends Pt{constructor(e){super({...e,name:"stampEditor"});y(this,ct);y(this,Ot,null);y(this,de,null);y(this,hr,null);y(this,yn,null);y(this,lr,null);y(this,uh,"");y(this,Ai,null);y(this,Ti,null);y(this,ps,!1);y(this,dh,!1);m(this,yn,e.bitmapUrl),m(this,lr,e.bitmapFile)}static initialize(e,s){Pt.initialize(e,s)}static get supportedTypes(){return st(this,"supportedTypes",["apng","avif","bmp","gif","jpeg","png","svg+xml","webp","x-icon"].map(s=>`image/${s}`))}static get supportedTypesStr(){return st(this,"supportedTypesStr",this.supportedTypes.join(","))}static isHandlingMimeForPasting(e){return this.supportedTypes.includes(e)}static paste(e,s){s.pasteEditor(Z.STAMP,{bitmapFile:e.getAsFile()})}altTextFinish(){this._uiManager.useNewAltTextFlow&&(this.div.hidden=!1),super.altTextFinish()}get telemetryFinalData(){var e;return{type:"stamp",hasAltText:!!((e=this.altTextData)!=null&&e.altText)}}static computeTelemetryFinalData(e){const s=e.get("hasAltText");return{hasAltText:s.get(!0)??0,hasNoAltText:s.get(!1)??0}}async mlGuessAltText(e=null,s=!0){if(this.hasAltTextData())return null;const{mlManager:i}=this._uiManager;if(!i)throw new Error("No ML.");if(!await i.isEnabledFor("altText"))throw new Error("ML isn't enabled for alt text.");const{data:n,width:r,height:o}=e||this.copyCanvas(null,null,!0).imageData,h=await i.guess({name:"altText",request:{data:n,width:r,height:o,channels:n.length/(r*o)}});if(!h)throw new Error("No response from the AI service.");if(h.error)throw new Error("Error from the AI service.");if(h.cancel)return null;if(!h.output)throw new Error("No valid response from the AI service.");const c=h.output;return await this.setGuessedAltText(c),s&&!this.hasAltTextData()&&(this.altTextData={alt:c,decorative:!1}),c}remove(){var e;l(this,de)&&(m(this,Ot,null),this._uiManager.imageManager.deleteId(l(this,de)),(e=l(this,Ai))==null||e.remove(),m(this,Ai,null),l(this,Ti)&&(clearTimeout(l(this,Ti)),m(this,Ti,null))),super.remove()}rebuild(){if(!this.parent){l(this,de)&&w(this,ct,Zd).call(this);return}super.rebuild(),this.div!==null&&(l(this,de)&&l(this,Ai)===null&&w(this,ct,Zd).call(this),this.isAttachedToDOM||this.parent.add(this))}onceAdded(e){this._isDraggable=!0,e&&this.div.focus()}isEmpty(){return!(l(this,hr)||l(this,Ot)||l(this,yn)||l(this,lr)||l(this,de))}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.div.setAttribute("role","figure"),this.addAltTextButton(),l(this,Ot)?w(this,ct,Np).call(this):w(this,ct,Zd).call(this),this.width&&!this.annotationElementId){const[i,n]=this.parentDimensions;this.setAt(e*i,s*n,this.width*i,this.height*n)}return this._uiManager.addShouldRescale(this),this.div}_onResized(){this.onScaleChanging()}onScaleChanging(){if(!this.parent)return;l(this,Ti)!==null&&clearTimeout(l(this,Ti)),m(this,Ti,setTimeout(()=>{m(this,Ti,null),w(this,ct,jp).call(this)},200))}copyCanvas(e,s,i=!1){var g;e||(e=224);const{width:n,height:r}=l(this,Ot),o=new bg;let h=l(this,Ot),c=n,u=r,d=null;if(s){if(n>s||r>s){const P=Math.min(s/n,s/r);c=Math.floor(n*P),u=Math.floor(r*P)}d=document.createElement("canvas");const p=d.width=Math.ceil(c*o.sx),b=d.height=Math.ceil(u*o.sy);l(this,ps)||(h=w(this,ct,tf).call(this,p,b));const _=d.getContext("2d");_.filter=this._uiManager.hcmFilter;let v="white",x="#cfcfd8";this._uiManager.hcmFilter!=="none"?x="black":(g=window.matchMedia)!=null&&g.call(window,"(prefers-color-scheme: dark)").matches&&(v="#8f8f9d",x="#42414d");const C=15,S=C*o.sx,k=C*o.sy,M=new OffscreenCanvas(S*2,k*2),E=M.getContext("2d");E.fillStyle=v,E.fillRect(0,0,S*2,k*2),E.fillStyle=x,E.fillRect(0,0,S,k),E.fillRect(S,k,S,k),_.fillStyle=_.createPattern(M,"repeat"),_.fillRect(0,0,p,b),_.drawImage(h,0,0,h.width,h.height,0,0,p,b)}let f=null;if(i){let p,b;if(o.symmetric&&h.width<e&&h.height<e)p=h.width,b=h.height;else if(h=l(this,Ot),n>e||r>e){const x=Math.min(e/n,e/r);p=Math.floor(n*x),b=Math.floor(r*x),l(this,ps)||(h=w(this,ct,tf).call(this,p,b))}const v=new OffscreenCanvas(p,b).getContext("2d",{willReadFrequently:!0});v.drawImage(h,0,0,h.width,h.height,0,0,p,b),f={width:p,height:b,data:v.getImageData(0,0,p,b).data}}return{canvas:d,width:c,height:u,imageData:f}}getImageForAltText(){return l(this,Ai)}static async deserialize(e,s,i){var b;let n=null;if(e instanceof Nb){const{data:{rect:_,rotation:v,id:x,structParent:C,popupRef:S},container:k,parent:{page:{pageNumber:M}}}=e,E=k.querySelector("canvas"),P=i.imageManager.getFromCanvas(k.id,E);E.remove();const O=((b=await s._structTree.getAriaAttributes(`${dg}${x}`))==null?void 0:b.get("aria-label"))||"";n=e={annotationType:Z.STAMP,bitmapId:P.id,bitmap:P.bitmap,pageIndex:M-1,rect:_.slice(0),rotation:v,id:x,deleted:!1,accessibilityData:{decorative:!1,altText:O},isSvg:!1,structParent:C,popupRef:S}}const r=await super.deserialize(e,s,i),{rect:o,bitmap:h,bitmapUrl:c,bitmapId:u,isSvg:d,accessibilityData:f}=e;u&&i.imageManager.isValidId(u)?(m(r,de,u),h&&m(r,Ot,h)):m(r,yn,c),m(r,ps,d);const[g,p]=r.pageDimensions;return r.width=(o[2]-o[0])/g,r.height=(o[3]-o[1])/p,r.annotationElementId=e.id||null,f&&(r.altTextData=f),r._initialData=n,m(r,dh,!!n),r}serialize(e=!1,s=null){if(this.isEmpty())return null;if(this.deleted)return this.serializeDeleted();const i={annotationType:Z.STAMP,bitmapId:l(this,de),pageIndex:this.pageIndex,rect:this.getRect(0,0),rotation:this.rotation,isSvg:l(this,ps),structTreeParentId:this._structTreeParentId};if(e)return i.bitmapUrl=w(this,ct,ef).call(this,!0),i.accessibilityData=this.serializeAltText(!0),i;const{decorative:n,altText:r}=this.serializeAltText(!1);if(!n&&r&&(i.accessibilityData={type:"Figure",alt:r}),this.annotationElementId){const h=w(this,ct,mv).call(this,i);if(h.isSame)return null;h.isSameAltText?delete i.accessibilityData:i.accessibilityData.structParent=this._initialData.structParent??-1}if(i.id=this.annotationElementId,s===null)return i;s.stamps||(s.stamps=new Map);const o=l(this,ps)?(i.rect[2]-i.rect[0])*(i.rect[3]-i.rect[1]):null;if(!s.stamps.has(l(this,de)))s.stamps.set(l(this,de),{area:o,serialized:i}),i.bitmap=w(this,ct,ef).call(this,!1);else if(l(this,ps)){const h=s.stamps.get(l(this,de));o>h.area&&(h.area=o,h.serialized.bitmap.close(),h.serialized.bitmap=w(this,ct,ef).call(this,!1))}return i}renderAnnotationElement(e){return e.updateEdited({rect:this.getRect(0,0)}),null}};Ot=new WeakMap,de=new WeakMap,hr=new WeakMap,yn=new WeakMap,lr=new WeakMap,uh=new WeakMap,Ai=new WeakMap,Ti=new WeakMap,ps=new WeakMap,dh=new WeakMap,ct=new WeakSet,Nc=function(e,s=!1){if(!e){this.remove();return}m(this,Ot,e.bitmap),s||(m(this,de,e.id),m(this,ps,e.isSvg)),e.file&&m(this,uh,e.file.name),w(this,ct,Np).call(this)},jc=function(){if(m(this,hr,null),this._uiManager.enableWaiting(!1),!!l(this,Ai)){if(this._uiManager.useNewAltTextWhenAddingImage&&this._uiManager.useNewAltTextFlow&&l(this,Ot)){this._editToolbar.hide(),this._uiManager.editAltText(this,!0);return}if(!this._uiManager.useNewAltTextWhenAddingImage&&this._uiManager.useNewAltTextFlow&&l(this,Ot)){this._reportTelemetry({action:"pdfjs.image.image_added",data:{alt_text_modal:!1,alt_text_type:"empty"}});try{this.mlGuessAltText()}catch{}}this.div.focus()}},Zd=function(){if(l(this,de)){this._uiManager.enableWaiting(!0),this._uiManager.imageManager.getFromId(l(this,de)).then(i=>w(this,ct,Nc).call(this,i,!0)).finally(()=>w(this,ct,jc).call(this));return}if(l(this,yn)){const i=l(this,yn);m(this,yn,null),this._uiManager.enableWaiting(!0),m(this,hr,this._uiManager.imageManager.getFromUrl(i).then(n=>w(this,ct,Nc).call(this,n)).finally(()=>w(this,ct,jc).call(this)));return}if(l(this,lr)){const i=l(this,lr);m(this,lr,null),this._uiManager.enableWaiting(!0),m(this,hr,this._uiManager.imageManager.getFromFile(i).then(n=>w(this,ct,Nc).call(this,n)).finally(()=>w(this,ct,jc).call(this)));return}const e=document.createElement("input");e.type="file",e.accept=Sc.supportedTypesStr;const s=this._uiManager._signal;m(this,hr,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]);this._reportTelemetry({action:"pdfjs.image.image_selected",data:{alt_text_modal:this._uiManager.useNewAltTextFlow}}),w(this,ct,Nc).call(this,n)}i()},{signal:s}),e.addEventListener("cancel",()=>{this.remove(),i()},{signal:s})}).finally(()=>w(this,ct,jc).call(this))),e.click()},Np=function(){var d;const{div:e}=this;let{width:s,height:i}=l(this,Ot);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 f=Math.min(o*n/s,o*r/i);s*=f,i*=f}const[h,c]=this.parentDimensions;this.setDims(s*h/n,i*c/r),this._uiManager.enableWaiting(!1);const u=m(this,Ai,document.createElement("canvas"));u.setAttribute("role","img"),this.addContainer(u),this.width=s/n,this.height=i/r,(d=this._initialOptions)!=null&&d.isCentered?this.center():this.fixAndSetPosition(),this._initialOptions=null,(!this._uiManager.useNewAltTextWhenAddingImage||!this._uiManager.useNewAltTextFlow||this.annotationElementId)&&(e.hidden=!1),w(this,ct,jp).call(this),l(this,dh)||(this.parent.addUndoableEditor(this),m(this,dh,!0)),this._reportTelemetry({action:"inserted_image"}),l(this,uh)&&u.setAttribute("aria-label",l(this,uh))},tf=function(e,s){const{width:i,height:n}=l(this,Ot);let r=i,o=n,h=l(this,Ot);for(;r>2*e||o>2*s;){const c=r,u=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 d=new OffscreenCanvas(r,o);d.getContext("2d").drawImage(h,0,0,c,u,0,0,r,o),h=d.transferToImageBitmap()}return h},jp=function(){const[e,s]=this.parentDimensions,{width:i,height:n}=this,r=new bg,o=Math.ceil(i*e*r.sx),h=Math.ceil(n*s*r.sy),c=l(this,Ai);if(!c||c.width===o&&c.height===h)return;c.width=o,c.height=h;const u=l(this,ps)?l(this,Ot):w(this,ct,tf).call(this,o,h),d=c.getContext("2d");d.filter=this._uiManager.hcmFilter,d.drawImage(u,0,0,u.width,u.height,0,0,o,h)},ef=function(e){if(e){if(l(this,ps)){const n=this._uiManager.imageManager.getSvgUrl(l(this,de));if(n)return n}const s=document.createElement("canvas");return{width:s.width,height:s.height}=l(this,Ot),s.getContext("2d").drawImage(l(this,Ot),0,0),s.toDataURL()}if(l(this,ps)){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(l(this,Ot),0,0,l(this,Ot).width,l(this,Ot).height,0,0,n,r),o.transferToImageBitmap()}return structuredClone(l(this,Ot))},mv=function(e){var o;const{pageIndex:s,accessibilityData:{altText:i}}=this._initialData,n=e.pageIndex===s,r=(((o=e.accessibilityData)==null?void 0:o.alt)||"")===i;return{isSame:!this._hasBeenMoved&&!this._hasBeenResized&&n&&r,isSameAltText:r}},$(Sc,"_type","stamp"),$(Sc,"_editorType",Z.STAMP);let Hg=Sc;const ei=class ei{constructor({uiManager:t,pageIndex:e,div:s,structTreeLayer:i,accessibilityManager:n,annotationLayer:r,drawLayer:o,textLayer:h,viewport:c,l10n:u}){y(this,kt);y(this,No);y(this,fh,!1);y(this,Ei,null);y(this,cr,null);y(this,vn,null);y(this,Ps,new Map);y(this,ur,!1);y(this,gh,!1);y(this,jo,!1);y(this,ti,null);y(this,_n,null);y(this,Ce,null);y(this,wn,null);y(this,X);const d=[...l(ei,dr).values()];if(!ei._initialized){ei._initialized=!0;for(const f of d)f.initialize(u,t)}t.registerEditorTypes(d),m(this,X,t),this.pageIndex=e,this.div=s,m(this,No,n),m(this,Ei,r),this.viewport=c,m(this,Ce,h),this.drawLayer=o,this._structTree=i,l(this,X).addLayer(this)}get isEmpty(){return l(this,Ps).size===0}get isInvisible(){return this.isEmpty&&l(this,X).getMode()===Z.NONE}updateToolbar(t){l(this,X).updateToolbar(t)}updateMode(t=l(this,X).getMode()){switch(w(this,kt,sf).call(this),t){case Z.NONE:this.disableTextSelection(),this.togglePointerEvents(!1),this.toggleAnnotationLayerPointerEvents(!0),this.disableClick();return;case Z.INK:this.disableTextSelection(),this.togglePointerEvents(!0),this.enableClick();break;case Z.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 l(ei,dr).values())e.toggle(`${s._type}Editing`,t===s._editorType);this.div.hidden=!1}hasTextLayer(t){var e;return t===((e=l(this,Ce))==null?void 0:e.div)}setEditingState(t){l(this,X).setEditingState(t)}addCommands(t){l(this,X).addCommands(t)}cleanUndoStack(t){l(this,X).cleanUndoStack(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=l(this,Ei))==null||e.div.classList.toggle("disabled",!t)}async enable(){m(this,jo,!0),this.div.tabIndex=0,this.togglePointerEvents(!0);const t=new Set;for(const s of l(this,Ps).values())s.enableEditing(),s.show(!0),s.annotationElementId&&(l(this,X).removeChangedExistingAnnotation(s),t.add(s.annotationElementId));if(!l(this,Ei)){m(this,jo,!1);return}const e=l(this,Ei).getEditableAnnotations();for(const s of e){if(s.hide(),l(this,X).isDeletedAnnotationElement(s.data.id)||t.has(s.data.id))continue;const i=await this.deserialize(s);i&&(this.addOrRebuild(i),i.enableEditing())}m(this,jo,!1)}disable(){var i;m(this,gh,!0),this.div.tabIndex=-1,this.togglePointerEvents(!1);const t=new Map,e=new Map;for(const n of l(this,Ps).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(l(this,Ei)){const n=l(this,Ei).getEditableAnnotations();for(const r of n){const{id:o}=r.data;if(l(this,X).isDeletedAnnotationElement(o))continue;let h=e.get(o);if(h){h.resetAnnotationElement(r),h.show(!1),r.show();continue}h=t.get(o),h&&(l(this,X).addChangedExistingAnnotation(h),h.renderAnnotationElement(r)&&h.show(!1)),r.show()}}w(this,kt,sf).call(this),this.isEmpty&&(this.div.hidden=!0);const{classList:s}=this.div;for(const n of l(ei,dr).values())s.remove(`${n._type}Editing`);this.disableTextSelection(),this.toggleAnnotationLayerPointerEvents(!0),m(this,gh,!1)}getEditableAnnotation(t){var e;return((e=l(this,Ei))==null?void 0:e.getEditableAnnotation(t))||null}setActiveEditor(t){l(this,X).getActive()!==t&&l(this,X).setActiveEditor(t)}enableTextSelection(){var t;if(this.div.tabIndex=-1,(t=l(this,Ce))!=null&&t.div&&!l(this,wn)){m(this,wn,new AbortController);const e=l(this,X).combinedSignal(l(this,wn));l(this,Ce).div.addEventListener("pointerdown",w(this,kt,bv).bind(this),{signal:e}),l(this,Ce).div.classList.add("highlighting")}}disableTextSelection(){var t;this.div.tabIndex=0,(t=l(this,Ce))!=null&&t.div&&l(this,wn)&&(l(this,wn).abort(),m(this,wn,null),l(this,Ce).div.classList.remove("highlighting"))}enableClick(){if(l(this,cr))return;m(this,cr,new AbortController);const t=l(this,X).combinedSignal(l(this,cr));this.div.addEventListener("pointerdown",this.pointerdown.bind(this),{signal:t});const e=this.pointerup.bind(this);this.div.addEventListener("pointerup",e,{signal:t}),this.div.addEventListener("pointercancel",e,{signal:t})}disableClick(){var t;(t=l(this,cr))==null||t.abort(),m(this,cr,null)}attach(t){l(this,Ps).set(t.id,t);const{annotationElementId:e}=t;e&&l(this,X).isDeletedAnnotationElement(e)&&l(this,X).removeDeletedAnnotationElement(t)}detach(t){var e;l(this,Ps).delete(t.id),(e=l(this,No))==null||e.removePointerInTextLayer(t.contentDiv),!l(this,gh)&&t.annotationElementId&&l(this,X).addDeletedAnnotationElement(t)}remove(t){this.detach(t),l(this,X).removeEditor(t),t.div.remove(),t.isAttachedToDOM=!1}changeParent(t){var e;t.parent!==this&&(t.parent&&t.annotationElementId&&(l(this,X).addDeletedAnnotationElement(t.annotationElementId),Pt.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),l(this,X).addEditor(t),this.attach(t),!t.isAttachedToDOM){const e=t.render();this.div.append(e),t.isAttachedToDOM=!0}t.fixAndSetPosition(),t.onceAdded(!l(this,jo)),l(this,X).addToAnnotationStorage(t),t._reportTelemetry(t.telemetryInitialData)}}moveEditorInDOM(t){var s;if(!t.isAttachedToDOM)return;const{activeElement:e}=document;t.div.contains(e)&&!l(this,vn)&&(t._focusEventsAllowed=!1,m(this,vn,setTimeout(()=>{m(this,vn,null),t.div.contains(document.activeElement)?t._focusEventsAllowed=!0:(t.div.addEventListener("focusin",()=>{t._focusEventsAllowed=!0},{once:!0,signal:l(this,X)._signal}),e.focus())},0))),t._structTreeParentId=(s=l(this,No))==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 l(this,X).getId()}combinedSignal(t){return l(this,X).combinedSignal(t)}canCreateNewEmptyEditor(){var t;return(t=l(this,kt,Di))==null?void 0:t.canCreateNewEmptyEditor()}pasteEditor(t,e){l(this,X).updateToolbar(t),l(this,X).updateMode(t);const{offsetX:s,offsetY:i}=w(this,kt,Hp).call(this),n=this.getNextId(),r=w(this,kt,Bp).call(this,{parent:this,id:n,x:s,y:i,uiManager:l(this,X),isCentered:!0,...e});r&&this.add(r)}async deserialize(t){var e;return await((e=l(ei,dr).get(t.annotationType??t.annotationEditorType))==null?void 0:e.deserialize(t,this,l(this,X)))||null}createAndAddNewEditor(t,e,s={}){const i=this.getNextId(),n=w(this,kt,Bp).call(this,{parent:this,id:i,x:t.offsetX,y:t.offsetY,uiManager:l(this,X),isCentered:e,...s});return n&&this.add(n),n}addNewEditor(){this.createAndAddNewEditor(w(this,kt,Hp).call(this),!0)}setSelected(t){l(this,X).setSelected(t)}toggleSelected(t){l(this,X).toggleSelected(t)}unselect(t){l(this,X).unselect(t)}pointerup(t){var s;const{isMac:e}=Re.platform;if(!(t.button!==0||t.ctrlKey&&e)&&t.target===this.div&&l(this,ur)&&(m(this,ur,!1),!((s=l(this,kt,Di))!=null&&s.isDrawer&&l(this,kt,Di).supportMultipleDrawings))){if(!l(this,fh)){m(this,fh,!0);return}if(l(this,X).getMode()===Z.STAMP){l(this,X).unselectAll();return}this.createAndAddNewEditor(t,!1)}}pointerdown(t){var i;if(l(this,X).getMode()===Z.HIGHLIGHT&&this.enableTextSelection(),l(this,ur)){m(this,ur,!1);return}const{isMac:e}=Re.platform;if(t.button!==0||t.ctrlKey&&e||t.target!==this.div)return;if(m(this,ur,!0),(i=l(this,kt,Di))!=null&&i.isDrawer){this.startDrawingSession(t);return}const s=l(this,X).getActive();m(this,fh,!s||s.isEmpty())}startDrawingSession(t){if(this.div.focus(),l(this,ti)){l(this,kt,Di).startDrawing(this,l(this,X),!1,t);return}l(this,X).setCurrentDrawingSession(this),m(this,ti,new AbortController);const e=l(this,X).combinedSignal(l(this,ti));this.div.addEventListener("blur",({relatedTarget:s})=>{s&&!this.div.contains(s)&&(m(this,_n,null),this.commitOrRemove())},{signal:e}),l(this,kt,Di).startDrawing(this,l(this,X),!1,t)}pause(t){if(t){const{activeElement:e}=document;this.div.contains(e)&&m(this,_n,e);return}l(this,_n)&&setTimeout(()=>{var e;(e=l(this,_n))==null||e.focus(),m(this,_n,null)},0)}endDrawingSession(t=!1){return l(this,ti)?(l(this,X).setCurrentDrawingSession(null),l(this,ti).abort(),m(this,ti,null),m(this,_n,null),l(this,kt,Di).endDrawing(t)):null}findNewParent(t,e,s){const i=l(this,X).findParent(e,s);return i===null||i===this?!1:(i.changeParent(t),!0)}commitOrRemove(){return l(this,ti)?(this.endDrawingSession(),!0):!1}onScaleChanging(){l(this,ti)&&l(this,kt,Di).onScaleChangingWhenDrawing(this)}destroy(){var t,e;this.commitOrRemove(),((t=l(this,X).getActive())==null?void 0:t.parent)===this&&(l(this,X).commitOrRemove(),l(this,X).setActiveEditor(null)),l(this,vn)&&(clearTimeout(l(this,vn)),m(this,vn,null));for(const s of l(this,Ps).values())(e=l(this,No))==null||e.removePointerInTextLayer(s.contentDiv),s.setParent(null),s.isAttachedToDOM=!1,s.div.remove();this.div=null,l(this,Ps).clear(),l(this,X).removeLayer(this)}render({viewport:t}){this.viewport=t,kr(this.div,t);for(const e of l(this,X).getEditors(this.pageIndex))this.add(e),e.rebuild();this.updateMode()}update({viewport:t}){l(this,X).commitOrRemove(),w(this,kt,sf).call(this);const e=this.viewport.rotation,s=t.rotation;if(this.viewport=t,kr(this.div,{rotation:s}),e!==s)for(const i of l(this,Ps).values())i.rotate(s)}get pageDimensions(){const{pageWidth:t,pageHeight:e}=this.viewport.rawDims;return[t,e]}get scale(){return l(this,X).viewParameters.realScale}};No=new WeakMap,fh=new WeakMap,Ei=new WeakMap,cr=new WeakMap,vn=new WeakMap,Ps=new WeakMap,ur=new WeakMap,gh=new WeakMap,jo=new WeakMap,ti=new WeakMap,_n=new WeakMap,Ce=new WeakMap,wn=new WeakMap,X=new WeakMap,dr=new WeakMap,kt=new WeakSet,bv=function(t){l(this,X).unselectAll();const{target:e}=t;if(e===l(this,Ce).div||(e.getAttribute("role")==="img"||e.classList.contains("endOfContent"))&&l(this,Ce).div.contains(e)){const{isMac:s}=Re.platform;if(t.button!==0||t.ctrlKey&&s)return;l(this,X).showAllEditors("highlight",!0,!0),l(this,Ce).div.classList.add("free"),this.toggleDrawing(),od.startHighlighting(this,l(this,X).direction==="ltr",{target:l(this,Ce).div,x:t.x,y:t.y}),l(this,Ce).div.addEventListener("pointerup",()=>{l(this,Ce).div.classList.remove("free"),this.toggleDrawing(!0)},{once:!0,signal:l(this,X)._signal}),t.preventDefault()}},Di=function(){return l(ei,dr).get(l(this,X).getMode())},Bp=function(t){const e=l(this,kt,Di);return e?new e.prototype.constructor(t):null},Hp=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),c=(n+o)/2-t,u=(r+h)/2-e,[d,f]=this.viewport.rotation%180===0?[c,u]:[u,c];return{offsetX:d,offsetY:f}},sf=function(){for(const t of l(this,Ps).values())t.isEmpty()&&t.remove()},$(ei,"_initialized",!1),y(ei,dr,new Map([Lg,Bg,Hg,od].map(t=>[t._editorType,t])));let Gg=ei;const Ae=class Ae{constructor({pageIndex:t}){y(this,ki);y(this,si,null);y(this,Cc,0);y(this,Be,new Map);y(this,Bo,new Map);this.pageIndex=t}setParent(t){if(!l(this,si)){m(this,si,t);return}if(l(this,si)!==t){if(l(this,Be).size>0)for(const e of l(this,Be).values())e.remove(),t.append(e);m(this,si,t)}}static get _svgFactory(){return st(this,"_svgFactory",new Dg)}draw(t,e=!1,s=!1){const i=Ge(this,Cc)._++,n=w(this,ki,Gp).call(this),r=Ae._svgFactory.createElement("defs");n.append(r);const o=Ae._svgFactory.createElement("path");r.append(o);const h=`path_p${this.pageIndex}_${i}`;o.setAttribute("id",h),o.setAttribute("vector-effect","non-scaling-stroke"),e&&l(this,Bo).set(i,o);const c=s?w(this,ki,vv).call(this,r,h):null,u=Ae._svgFactory.createElement("use");return n.append(u),u.setAttribute("href",`#${h}`),this.updateProperties(n,t),l(this,Be).set(i,n),{id:i,clipPathId:`url(#${c})`}}drawOutline(t,e){const s=Ge(this,Cc)._++,i=w(this,ki,Gp).call(this),n=Ae._svgFactory.createElement("defs");i.append(n);const r=Ae._svgFactory.createElement("path");n.append(r);const o=`path_p${this.pageIndex}_${s}`;r.setAttribute("id",o),r.setAttribute("vector-effect","non-scaling-stroke");let h;if(e){const d=Ae._svgFactory.createElement("mask");n.append(d),h=`mask_p${this.pageIndex}_${s}`,d.setAttribute("id",h),d.setAttribute("maskUnits","objectBoundingBox");const f=Ae._svgFactory.createElement("rect");d.append(f),f.setAttribute("width","1"),f.setAttribute("height","1"),f.setAttribute("fill","white");const g=Ae._svgFactory.createElement("use");d.append(g),g.setAttribute("href",`#${o}`),g.setAttribute("stroke","none"),g.setAttribute("fill","black"),g.setAttribute("fill-rule","nonzero"),g.classList.add("mask")}const c=Ae._svgFactory.createElement("use");i.append(c),c.setAttribute("href",`#${o}`),h&&c.setAttribute("mask",`url(#${h})`);const u=c.cloneNode();return i.append(u),c.classList.add("mainOutline"),u.classList.add("secondaryOutline"),this.updateProperties(i,t),l(this,Be).set(s,i),s}finalizeDraw(t,e){l(this,Bo).delete(t),this.updateProperties(t,e)}updateProperties(t,e){var h;if(!e)return;const{root:s,bbox:i,rootClass:n,path:r}=e,o=typeof t=="number"?l(this,Be).get(t):t;if(o){if(s&&w(this,ki,zp).call(this,o,s),i&&w(h=Ae,Td,yv).call(h,o,i),n){const{classList:c}=o;for(const[u,d]of Object.entries(n))c.toggle(u,d)}if(r){const u=o.firstChild.firstChild;w(this,ki,zp).call(this,u,r)}}}updateParent(t,e){if(e===this)return;const s=l(this,Be).get(t);s&&(l(e,si).append(s),l(this,Be).delete(t),l(e,Be).set(t,s))}remove(t){l(this,Bo).delete(t),l(this,si)!==null&&(l(this,Be).get(t).remove(),l(this,Be).delete(t))}destroy(){m(this,si,null);for(const t of l(this,Be).values())t.remove();l(this,Be).clear(),l(this,Bo).clear()}};si=new WeakMap,Cc=new WeakMap,Be=new WeakMap,Bo=new WeakMap,Td=new WeakSet,yv=function(t,[e,s,i,n]){const{style:r}=t;r.top=`${100*s}%`,r.left=`${100*e}%`,r.width=`${100*i}%`,r.height=`${100*n}%`},ki=new WeakSet,Gp=function(){const t=Ae._svgFactory.create(1,1,!0);return l(this,si).append(t),t.setAttribute("aria-hidden",!0),t},vv=function(t,e){const s=Ae._svgFactory.createElement("clipPath");t.append(s);const i=`clip_${e}`;s.setAttribute("id",i),s.setAttribute("clipPathUnits","objectBoundingBox");const n=Ae._svgFactory.createElement("use");return s.append(n),n.setAttribute("href",`#${e}`),n.classList.add("clip"),i},zp=function(t,e){for(const[s,i]of Object.entries(e))i===null?t.removeAttribute(s):t.setAttribute(s,i)},y(Ae,Td);let zg=Ae;globalThis.pdfjsTestingUtils={HighlightOutliner:Fg},K.AbortException,K.AnnotationEditorLayer,K.AnnotationEditorParamsType,K.AnnotationEditorType,K.AnnotationEditorUIManager,K.AnnotationLayer,K.AnnotationMode,K.ColorPicker,K.DOMSVGFactory,K.DrawLayer,K.FeatureTest;var YS=K.GlobalWorkerOptions;K.ImageKind,K.InvalidPDFException,K.MissingPDFException,K.OPS,K.OutputScale,K.PDFDataRangeTransport,K.PDFDateString,K.PDFWorker,K.PasswordResponses,K.PermissionFlag,K.PixelsPerInch,K.RenderingCancelledException,K.TextLayer,K.TouchManager,K.UnexpectedResponseException,K.Util,K.VerbosityLevel,K.XfaLayer,K.build,K.createValidAbsoluteUrl,K.fetchData;var $S=K.getDocument;K.getFilenameFromUrl,K.getPdfFilenameFromUrl,K.getXfaPageViewport,K.isDataScheme,K.isPdfFile,K.noContextMenu,K.normalizeUnicode,K.setLayerDimensions,K.shadow,K.stopEvent,K.version;const qS={"pdfjs-dist":"4.10.38"};function KS(a){return new Promise((t,e)=>{const s=new FileReader;s.addEventListener("load",()=>t(s.result)),s.addEventListener("error",e),s.readAsDataURL(a)})}const QS=qS["pdfjs-dist"].replace("^","");YS.workerSrc=`https://cdnjs.cloudflare.com/ajax/libs/pdf.js/${QS}/pdf.worker.min.mjs`;async function JS(a){const t="data:application/pdf;base64,",e=await KS(a);if(typeof e=="string")return window.atob(e.slice(t.length))}function ZS(a,t){return $S({data:a,password:t}).promise}const tC="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 eC(a){return new URL(Object.assign({"../assets/close.svg":tC})[`../assets/${a}`],typeof document>"u"&&typeof location>"u"?require("url").pathToFileURL(__filename).href:typeof document>"u"?location.href:_t&&_t.tagName.toUpperCase()==="SCRIPT"&&_t.src||new URL("pdf-canvas.umd.js",document.baseURI).href).href}function sC(a){return new Promise((t,e)=>{const s=window.URL.createObjectURL(a),i=new Image;i.src=s,i.addEventListener("load",async()=>{window.URL.revokeObjectURL(s),t(await iC(i))}),i.addEventListener("error",n=>{window.URL.revokeObjectURL(s),e(n)})})}function iC(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 Bb=null;function nC(){const a=document.createElement("div");a.style.width="1in",document.body.append(a);const t=a.offsetWidth;return a.remove(),t}function rC(){const a=Bb??nC();return Bb=a,a/72}function oC(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=new Map;function aC(a){const t=new Uf(a);return _s.set(a,t),t}function hC(a,t){const e=Date.now();return{PDFId:`${a.name}-${e}`,name:a.name.replace(/.pdf/,""),updateDate:e,PDFBase64:t}}function lC(a,t){const e=a.getViewport({scale:t}),s=document.createElement("canvas"),i=s.getContext("2d"),n=rC()/window.devicePixelRatio;s.width=Math.floor(e.width*n),s.height=Math.floor(e.height*n);const r={canvasContext:i,viewport:e,transform:[n,0,0,n,0,0]},o=a.render(r);return{canvas:s,renderTask:o}}async function cC(a,t,e){const s=a||eC("close.svg"),{objects:i,options:n}=await Nw(s),r=i.filter(h=>h!==null),o=Q_.groupSVGElements(r,n);return r.forEach(h=>{h.stroke=t}),o.hoverCursor="pointer",o.stroke=`${t}-${e}`,o}function uC(a,t){if(!_s.get(a))return;const s=1/3,i=bC(t,s);Gb(a,i,s)}async function dC(a,t){const e=await sC(t),s=Date.now(),n={PDFId:`${t.name}${s}`,name:t.name.replace(/.png|.jpg|.jpeg/,""),updateDate:s,PDFBase64:e};return Hb(a,{url:e}),{...n,pages:1}}async function Hb(a,{url:t,scale:e=.5}){if(!_s.get(a))return;const i=await be.fromURL(t);i.scale(e),Gb(a,i,e)}function Gb(a,t,e){const s=_s.get(a);s&&(s.setWidth(t.width*e),s.setHeight(t.height*e),s.backgroundImage=t,s.renderAll())}function Jh(a,t){if(!t)return;const{oCoords:e}=a;if(!e)return;const{x:s,y:i}=e.tl.touchCorner.tl,{height:n,width:r,scaleY:o,scaleX:h}=t;t.top=i-n*o/2,t.left=s-r*h/2,t.setCoords()}function fC(a,t,e){!e||!a||(e.scale(1/t),Jh(a,e))}function gC(a,t,e){a&&(a.borderScaleFactor=1/t,a.cornerSize=6*(1/t),a.touchCornerSize=24*(1/t),a.cornerStrokeColor=e.stroke,a.setCoords())}function pC(a){const t=_s.get(a);t&&(t.discardActiveObject(),t.renderAll())}function mC(a){const t=_s.get(a);t&&(t.clear(),_s.delete(a))}function bC(a,t){return new be(a,{scaleX:t,scaleY:t})}function zb(a,t){if(!t)return;const{left:e,top:s,scaleX:i,scaleY:n,width:r,height:o}=a,h=t.x*r*i,c=t.y*o*n;a.set({left:e-h,top:s-c})}function Vb(a,t,e){var n;const s=a.type,i={"application/pdf":yC,"image/png":Wb,"image/jpeg":Wb};return((n=i[s])==null?void 0:n.call(i,a,t,e))??Promise.reject(new Error(`Unsupported ${s} file type.`))}async function yC(a,t){const e=await JS(a);if(!e)return;const s=hC(a,e);try{const i=await Xb({page:1,PDFBase64:e,scale:.8,password:t});return{...s,pages:i}}catch(i){return Promise.reject(i)}}async function Xb({page:a,PDFBase64:t,scale:e,password:s},i){try{const n=await ZS(t,s),r=await n.getPage(a),{renderTask:o,canvas:h}=lC(r,e);return o.promise.then(()=>(i&&uC(i,h),n.numPages))}catch(n){return Promise.reject(n)}}async function Wb(a,t,e){if(e)return await dC(e,a)}const vC={top:100,left:50,scaleX:.5,scaleY:.5,borderColor:"black",cornerStrokeColor:"black",cornerSize:8,selectionBackgroundColor:"rgba(245, 245, 245, 0.8)"},_C={top:100,left:50,fontFamily:"helvetica",borderColor:"black",cornerStrokeColor:"black",scaleX:.7,scaleY:.7,cornerSize:8,selectionBackgroundColor:"rgba(245, 245, 245, 0.8)"},wC={stroke:"#000",hoverStroke:"#B7EC5D",src:""};function Ub(a){const{id:t="",pointerDown:e,pointerMove:s,pointerUp:i}=a||{};let n=null,r=null,o=1,h={...wC};function c(){if(!t||_s.has(t))return;const E=aC(t);return E.on("selection:cleared",()=>S(E)),e&&E.on("mouse:down",e),s&&E.on("mouse:move",s),i&&E.on("mouse:up",i),E}function u(E,P){return Vb(E,P,t)}function d(E){Xb(E,t)}async function f({url:E,scale:P=.5}){await Hb(t,{url:E,scale:P})}async function g(E,P,O){const L=_s.get(t);if(!L)return;const R=await be.fromURL(E,{},{...vC,...P});zb(R,O),L.add(R),b(L,R),L.setActiveObject(R)}function p(E,P,O){const L=_s.get(t);if(!L)return;const R=new me(E,{..._C,...P});zb(R,O),L.add(R),b(L,R),L.setActiveObject(R)}function b(E,P){P.on("selected",O=>_({canvas:E,target:O.target})),P.on("modified",O=>Jh(O.target,n)),P.on("scaling",O=>Jh(O.transform.target,n)),P.on("moving",O=>Jh(O.transform.target,n)),P.on("rotating",O=>Jh(O.transform.target,n))}async function _({canvas:E,target:P,stroke:O=h.stroke,uuid:L=Date.now()}){if((n==null?void 0:n.stroke)===`${O}-${L}`)return;const R=await cC(h.src,O,L);S(E),n=R,r=P,v(E,P,L),x(o,!0),E.add(R)}function v(E,P,O){n&&(n.on("selected",()=>{E.remove(P),S(E)}),n.on("mouseover",()=>{_({canvas:E,target:P,stroke:h.hoverStroke,uuid:O})}),n.on("mouseout",()=>{_({canvas:E,target:P,stroke:h.stroke,uuid:O})}))}function x(E,P=!1){const O=_s.get(t);o=E,O&&(gC(r,E,h),fC(r,E,n),!P&&O.renderAll())}function C(E){if(!E)return;h={...h,...E};const P=_s.get(t);!n||!r||!P||_({target:r,canvas:P})}function S(E){n&&(E.remove(n),n=r=null)}function k(){pC(t)}function M(){mC(t)}return{createCanvas:c,loadFile:u,specifyPage:d,renderImage:f,addFabric:g,addTextFabric:p,clearActive:k,deleteCanvas:M,scaleFabric:x,setCloseSvgOptions:C}}function xC(a){let t=0;const e=oC(()=>{t!==window.innerWidth&&(t=window.innerWidth,a())});q.onMounted(()=>{window.addEventListener("resize",e)}),q.onBeforeUnmount(()=>{window.removeEventListener("resize",e)})}const SC=q.defineComponent({__name:"pdf-canvas",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:{},onDestroy:{type:Function,default:q.onBeforeUnmount}},emits:["loaded","pointerDown","pointerMove","pointerUp"],setup(a,{expose:t,emit:e}){const s=a,i=e,{onDestroy:n}=s,r=q.ref(null),o=`${s.canvasId}-${s.page-1}`,h=q.computed(()=>s.fileZoom*s.canvasScale),{createCanvas:c,specifyPage:u,addFabric:d,addTextFabric:f,renderImage:g,clearActive:p,deleteCanvas:b,scaleFabric:_,setCloseSvgOptions:v}=Ub({id:o,pointerDown:M=>i("pointerDown",M),pointerMove:M=>i("pointerMove",M),pointerUp:M=>i("pointerUp",M)});x(),xC(x);async function x(){const{file:M,page:E,fileScale:P}=s;window.requestAnimationFrame(async()=>{if(await q.nextTick(),c(),M.PDFBase64.startsWith("data:image")||M.canvas){const{canvas:O}=M,L=O?7:3,R=O!=null&&O.length?O[E-1]:M.PDFBase64;g({url:R,scale:P/L}),i("loaded");return}await u({page:E,PDFBase64:M.PDFBase64,scale:P,password:s.password}),i("loaded")})}function C(M){if(!s.isDrop||!M.dataTransfer)return;const{dataTransfer:E,offsetX:P,offsetY:O}=M,L=E.getData("text/plain"),R=E.getData("text/uri-list"),U=E.getData("custom/offset"),z=U?JSON.parse(U):null,V={top:O,left:P},at={x:(z==null?void 0:z.offsetX)??0,y:(z==null?void 0:z.offsetY)??0};R?S(R,V,at):L&&k(L,V,at)}function S(M,E,P){d(M,{...s.dropImageOptions,...E},P)}function k(M,E,P){f(M,{...s.dropTextOptions,...E},P)}return q.watch([()=>s.fileScale,()=>s.page,()=>s.file,()=>s.password],x),q.watch(h,M=>_(M),{immediate:!0}),q.watch(()=>s.closeSvgOptions,v,{immediate:!0}),n(b),t({addImage:S,addText:k,clearActive:p,deleteCanvas:b,canvasRef:r}),(M,E)=>(q.openBlock(),q.createElementBlock("div",{style:q.normalizeStyle({transform:`scale(${h.value})`}),onDragover:E[0]||(E[0]=q.withModifiers(()=>{},["stop","prevent"])),onDragenter:E[1]||(E[1]=q.withModifiers(()=>{},["stop","prevent"])),onDrop:q.withModifiers(C,["stop","prevent"])},[q.createElementVNode("canvas",{id:o,ref_key:"canvasRef",ref:r,class:q.normalizeClass(M.canvasClass)},null,2)],36))}});nt.default=SC,nt.loadFile=Vb,nt.useFabric=Ub,Object.defineProperties(nt,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
|