@component-hook/pdf-canvas 0.2.1 → 0.2.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -28,7 +28,7 @@ Check the top-level render call using <`+W+">.")}return F}}function Yv(C,F){{if(
|
|
|
28
28
|
React keys must be passed directly to JSX without using spread:
|
|
29
29
|
let props = %s;
|
|
30
30
|
<%s key={someKey} {...props} />`,Of,Da,eA,Da),qv[Da+Of]=!0}}return C===s?KC(ee):$C(ee),ee}}function JC(C,F,W){return $v(C,F,W,!0)}function QC(C,F,W){return $v(C,F,W,!1)}var ZC=QC,tA=JC;uh.Fragment=s,uh.jsx=ZC,uh.jsxs=tA}()),uh}process.env.NODE_ENV==="production"?Sn.exports=Ty():Sn.exports=Ey();var Pp=Sn.exports;function T(o,t,e){return(t=function(s){var i=function(n,r){if(typeof n!="object"||!n)return n;var a=n[Symbol.toPrimitive];if(a!==void 0){var h=a.call(n,r||"default");if(typeof h!="object")return h;throw new TypeError("@@toPrimitive must return a primitive value.")}return(r==="string"?String:Number)(n)}(s,"string");return typeof i=="symbol"?i:i+""}(t))in o?Object.defineProperty(o,t,{value:e,enumerable:!0,configurable:!0,writable:!0}):o[t]=e,o}function Dp(o,t){var e=Object.keys(o);if(Object.getOwnPropertySymbols){var s=Object.getOwnPropertySymbols(o);t&&(s=s.filter(function(i){return Object.getOwnPropertyDescriptor(o,i).enumerable})),e.push.apply(e,s)}return e}function E(o){for(var t=1;t<arguments.length;t++){var e=arguments[t]!=null?arguments[t]:{};t%2?Dp(Object(e),!0).forEach(function(s){T(o,s,e[s])}):Object.getOwnPropertyDescriptors?Object.defineProperties(o,Object.getOwnPropertyDescriptors(e)):Dp(Object(e)).forEach(function(s){Object.defineProperty(o,s,Object.getOwnPropertyDescriptor(e,s))})}return o}function Pt(o,t){if(o==null)return{};var e,s,i=function(r,a){if(r==null)return{};var h={};for(var l in r)if({}.hasOwnProperty.call(r,l)){if(a.indexOf(l)>=0)continue;h[l]=r[l]}return h}(o,t);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(o);for(s=0;s<n.length;s++)e=n[s],t.indexOf(e)>=0||{}.propertyIsEnumerable.call(o,e)&&(i[e]=o[e])}return i}function Cn(o,t){return t||(t=o.slice(0)),Object.freeze(Object.defineProperties(o,{raw:{value:Object.freeze(t)}}))}class Rp{constructor(){T(this,"browserShadowBlurConstant",1),T(this,"DPI",96),T(this,"devicePixelRatio",typeof window<"u"?window.devicePixelRatio:1),T(this,"perfLimitSizeTotal",2097152),T(this,"maxCacheSideLimit",4096),T(this,"minCacheSideLimit",256),T(this,"disableStyleCopyPaste",!1),T(this,"enableGLFiltering",!0),T(this,"textureSize",4096),T(this,"forceGLPutImageData",!1),T(this,"cachesBoundsOfCurve",!1),T(this,"fontPaths",{}),T(this,"NUM_FRACTION_DIGITS",4)}}const dt=new class extends Rp{constructor(o){super(),this.configure(o)}configure(){let o=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};Object.assign(this,o)}addFonts(){let o=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};this.fontPaths=E(E({},this.fontPaths),o)}removeFonts(){(arguments.length>0&&arguments[0]!==void 0?arguments[0]:[]).forEach(o=>{delete this.fontPaths[o]})}clearFonts(){this.fontPaths={}}restoreDefaults(o){const t=new Rp,e=(o==null?void 0:o.reduce((s,i)=>(s[i]=t[i],s),{}))||t;this.configure(e)}},Pi=function(o){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[o]("fabric",...e)};class ai extends Error{constructor(t,e){super("fabric: ".concat(t),e)}}class Id extends ai{constructor(t){super("".concat(t," 'options.signal' is in 'aborted' state"))}}class ky{}class My extends ky{testPrecision(t,e){const s="precision ".concat(e,` float;
|
|
31
|
-
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(),Pi("log","WebGL: max texture size ".concat(this.maxTextureSize)))}isSupported(t){return!!this.maxTextureSize&&this.maxTextureSize>=t}}const Oy={};let Fp;const oi=()=>Fp||(Fp={document,window,isTouchSupported:"ontouchstart"in window||"ontouchstart"in document||window&&window.navigator&&window.navigator.maxTouchPoints>0,WebGLProbe:new My,dispose(){},copyPasteData:Oy}),ja=()=>oi().document,_c=()=>oi().window,Lp=()=>{var o;return Math.max((o=dt.devicePixelRatio)!==null&&o!==void 0?o:_c().devicePixelRatio,1)},dh=new class{constructor(){T(this,"charWidthsCache",{}),T(this,"boundsOfCurveCache",{})}getFontCache(o){let{fontFamily:t,fontStyle:e,fontWeight:s}=o;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(o){(o=(o||"").toLowerCase())?this.charWidthsCache[o]&&delete this.charWidthsCache[o]:this.charWidthsCache={}}limitDimsByArea(o){const{perfLimitSizeTotal:t}=dt,e=Math.sqrt(t*o);return[Math.floor(e),Math.floor(t/e)]}},jd="6.5.0";function gr(){}const An=Math.PI/2,Di=2*Math.PI,Nd=Math.PI/180,De=Object.freeze([1,0,0,1,0,0]),Bd=16,Tn=.4477152502,st="center",mt="left",Ue="top",Hd="bottom",Vt="right",Re="none",Wd=/\r?\n/,Ip="moving",wc="scaling",jp="rotating",Xd="rotate",Np="skewing",gh="resizing",Py="modifyPoly",Dy="modifyPath",xc="changed",Sc="scale",Fe="scaleX",is="scaleY",Na="skewX",Ba="skewY",$t="fill",Le="stroke",Cc="modified",Ha="json",zd="svg",V=new class{constructor(){this[Ha]=new Map,this[zd]=new Map}has(o){return this[Ha].has(o)}getClass(o){const t=this[Ha].get(o);if(!t)throw new ai("No class registered for ".concat(o));return t}setClass(o,t){t?this[Ha].set(t,o):(this[Ha].set(o.type,o),this[Ha].set(o.type.toLowerCase(),o))}getSVGClass(o){return this[zd].get(o)}setSVGClass(o,t){this[zd].set(t??o.type.toLowerCase(),o)}},Ac=new class extends Array{remove(o){const t=this.indexOf(o);t>-1&&this.splice(t,1)}cancelAll(){const o=this.splice(0);return o.forEach(t=>t.abort()),o}cancelByCanvas(o){if(!o)return[];const t=this.filter(e=>{var s;return e.target===o||typeof e.target=="object"&&((s=e.target)===null||s===void 0?void 0:s.canvas)===o});return t.forEach(e=>e.abort()),t}cancelByTarget(o){if(!o)return[];const t=this.filter(e=>e.target===o);return t.forEach(e=>e.abort()),t}};class Ry{constructor(){T(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 fr=(o,t)=>{const e=o.indexOf(t);return e!==-1&&o.splice(e,1),o},Fs=o=>{if(o===0)return 1;switch(Math.abs(o)/An){case 1:case 3:return 0;case 2:return-1}return Math.cos(o)},Ls=o=>{if(o===0)return 0;const t=o/An,e=Math.sign(o);switch(t){case 1:return e;case 2:return 0;case 3:return-e}return Math.sin(o)};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]:Vd;const s=Ls(t),i=Fs(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 Vd=new D(0,0),Tc=o=>!!o&&Array.isArray(o._objects);function Bp(o){class t extends o{constructor(){super(...arguments),T(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(a=>this._onObjectAdded(a)),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(a=>this._onObjectAdded(a)),this._objects.length}remove(){const s=this._objects,i=[];for(var n=arguments.length,r=new Array(n),a=0;a<n;a++)r[a]=arguments[a];return r.forEach(h=>{const l=s.indexOf(h);l!==-1&&(s.splice(l,1),i.push(h),this._onObjectRemoved(h))}),i}forEachObject(s){this.getObjects().forEach((i,n,r)=>s(i,n,r))}getObjects(){for(var s=arguments.length,i=new Array(s),n=0;n<s;n++)i[n]=arguments[n];return i.length===0?[...this._objects]:this._objects.filter(r=>r.isType(...i))}item(s){return this._objects[s]}isEmpty(){return this._objects.length===0}size(){return this._objects.length}contains(s,i){return!!this._objects.includes(s)||!!i&&this._objects.some(n=>n instanceof t&&n.contains(s,!0))}complexity(){return this._objects.reduce((s,i)=>s+=i.complexity?i.complexity():0,0)}sendObjectToBack(s){return!(!s||s===this._objects[0])&&(fr(this._objects,s),this._objects.unshift(s),this._onStackOrderChanged(s),!0)}bringObjectToFront(s){return!(!s||s===this._objects[this._objects.length-1])&&(fr(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 fr(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 fr(this._objects,s),this._objects.splice(r,0,s),this._onStackOrderChanged(s),!0}return!1}moveObjectTo(s,i){return s!==this._objects[i]&&(fr(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 a=i-1;a>=0;--a)if(s.isOverlapping(this._objects[a])){r=a;break}}else r=i-1;return r}findNewUpperIndex(s,i,n){let r;if(n){r=i;for(let a=i+1;a<this._objects.length;++a)if(s.isOverlapping(this._objects[a])){r=a;break}}else r=i+1;return r}collectObjects(s){let{left:i,top:n,width:r,height:a}=s,{includeIntersecting:h=!0}=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};const l=[],u=new D(i,n),d=u.add(new D(r,a));for(let g=this._objects.length-1;g>=0;g--){const f=this._objects[g];f.selectable&&f.visible&&(h&&f.intersectsWithRect(u,d)||f.isContainedWithinRect(u,d)||h&&f.containsPoint(u)||h&&f.containsPoint(d))&&l.push(f)}return l}}return t}class Hp extends Ry{_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 fh(o){return _c().requestAnimationFrame(o)}function Wp(o){return _c().cancelAnimationFrame(o)}let Fy=0;const En=()=>Fy++,vs=()=>{const o=ja().createElement("canvas");if(!o||o.getContext===void 0)throw new ai("Failed to create `canvas` element");return o},Xp=()=>ja().createElement("img"),Is=o=>{const t=vs();return t.width=o.width,t.height=o.height,t},Gd=(o,t,e)=>o.toDataURL("image/".concat(t),e),Wt=o=>o*Nd,kn=o=>o/Nd,zp=o=>o.every((t,e)=>t===De[e]),we=(o,t,e)=>new D(o).transform(t,e),qe=o=>{const t=1/(o[0]*o[3]-o[1]*o[2]),e=[t*o[3],-t*o[1],-t*o[2],t*o[0],0,0],{x:s,y:i}=new D(o[4],o[5]).transform(e,!0);return e[4]=-s,e[5]=-i,e},Gt=(o,t,e)=>[o[0]*t[0]+o[2]*t[1],o[1]*t[0]+o[3]*t[1],o[0]*t[2]+o[2]*t[3],o[1]*t[2]+o[3]*t[3],e?0:o[0]*t[4]+o[2]*t[5]+o[4],e?0:o[1]*t[4]+o[3]*t[5]+o[5]],Ec=(o,t)=>o.reduceRight((e,s)=>s&&e?Gt(s,e,t):s||e,void 0)||De.concat(),Vp=o=>{let[t,e]=o;return Math.atan2(e,t)},pr=o=>{const t=Vp(o),e=Math.pow(o[0],2)+Math.pow(o[1],2),s=Math.sqrt(e),i=(o[0]*o[3]-o[2]*o[1])/s,n=Math.atan2(o[0]*o[2]+o[1]*o[3],e);return{angle:kn(t),scaleX:s,scaleY:i,skewX:kn(n),skewY:0,translateX:o[4]||0,translateY:o[5]||0}},Wa=function(o){return[1,0,0,1,o,arguments.length>1&&arguments[1]!==void 0?arguments[1]:0]};function Xa(){let{angle:o=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=Wt(o),i=Fs(s),n=Ls(s);return[i,n,-n,i,t?t-(i*t-n*e):0,e?e-(n*t+i*e):0]}const kc=function(o){return[o,0,0,arguments.length>1&&arguments[1]!==void 0?arguments[1]:o,0,0]},Gp=o=>Math.tan(Wt(o)),Yd=o=>[1,0,Gp(o),1,0,0],Ud=o=>[1,Gp(o),0,1,0,0],ph=o=>{let{scaleX:t=1,scaleY:e=1,flipX:s=!1,flipY:i=!1,skewX:n=0,skewY:r=0}=o,a=kc(s?-t:t,i?-e:e);return n&&(a=Gt(a,Yd(n),!0)),r&&(a=Gt(a,Ud(r),!0)),a},Yp=o=>{const{translateX:t=0,translateY:e=0,angle:s=0}=o;let i=Wa(t,e);s&&(i=Gt(i,Xa({angle:s})));const n=ph(o);return zp(n)||(i=Gt(i,n)),i},mh=function(o){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 Id("loadImage"));const n=Xp();let r;t&&(r=function(h){n.src="",i(h)},t.addEventListener("abort",r,{once:!0}));const a=function(){n.onload=n.onerror=null,r&&(t==null||t.removeEventListener("abort",r)),s(n)};o?(n.onload=a,n.onerror=function(){r&&(t==null||t.removeEventListener("abort",r)),i(new ai("Error loading ".concat(n.src)))},e&&(n.crossOrigin=e),n.src=o):a()})},za=function(o){let{signal:t,reviver:e=gr}=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(o.map(r=>V.getClass(r.type).fromObject(r,{signal:t}).then(a=>(e(r,a),n.push(a),a)))).then(s).catch(r=>{n.forEach(a=>{a.dispose&&a.dispose()}),i(r)}).finally(()=>{t&&t.removeEventListener("abort",i)})})},vh=function(o){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(o).map(a=>a&&a.type&&V.has(a.type)?za([a],{signal:t}).then(h=>{let[l]=h;return i.push(l),l}):a),r=Object.keys(o);Promise.all(n).then(a=>a.reduce((h,l,u)=>(h[r[u]]=l,h),{})).then(e).catch(a=>{i.forEach(h=>{h.dispose&&h.dispose()}),s(a)}).finally(()=>{t&&t.removeEventListener("abort",s)})})},mr=function(o){return(arguments.length>1&&arguments[1]!==void 0?arguments[1]:[]).reduce((t,e)=>(e in o&&(t[e]=o[e]),t),{})},qd=(o,t)=>Object.keys(o).reduce((e,s)=>(t(o[s],s,o)&&(e[s]=o[s]),e),{}),Up={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"},$d=(o,t,e)=>(e<0&&(e+=1),e>1&&(e-=1),e<1/6?o+6*(t-o)*e:e<.5?t:e<2/3?o+(t-o)*(2/3-e)*6:o),qp=(o,t,e,s)=>{o/=255,t/=255,e/=255;const i=Math.max(o,t,e),n=Math.min(o,t,e);let r,a;const h=(i+n)/2;if(i===n)r=a=0;else{const l=i-n;switch(a=h>.5?l/(2-i-n):l/(i+n),i){case o:r=(t-e)/l+(t<e?6:0);break;case t:r=(e-o)/l+2;break;case e:r=(o-t)/l+4}r/=6}return[Math.round(360*r),Math.round(100*a),Math.round(100*h),s]},$p=function(){let o=arguments.length>0&&arguments[0]!==void 0?arguments[0]:"1";return parseFloat(o)/(o.endsWith("%")?100:1)},Mc=o=>Math.min(Math.round(o),255).toString(16).toUpperCase().padStart(2,"0"),Kp=o=>{let[t,e,s,i=1]=o;const n=Math.round(.3*t+.59*e+.11*s);return[n,n,n,i]};class yt{constructor(t){if(T(this,"isUnrecognised",!1),t)if(t instanceof yt)this.setSource([...t._source]);else if(Array.isArray(t)){const[e,s,i,n=1]=t;this.setSource([e,s,i,n])}else this.setSource(this._tryParsingColor(t));else this.setSource([0,0,0,1])}_tryParsingColor(t){return t in Up&&(t=Up[t]),t==="transparent"?[255,255,255,0]:yt.sourceFromHex(t)||yt.sourceFromRgb(t)||yt.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]=qp(...this.getSource());return"hsl(".concat(t,",").concat(e,"%,").concat(s,"%)")}toHsla(){const[t,e,s,i]=qp(...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(Mc(t)).concat(Mc(e)).concat(Mc(s)).concat(Mc(Math.round(255*i)))}getAlpha(){return this.getSource()[3]}setAlpha(t){return this._source[3]=t,this}toGrayscale(){return this.setSource(Kp(this.getSource())),this}toBlackWhite(t){const[e,,,s]=Kp(this.getSource()),i=e<(t||127)?0:255;return this.setSource([i,i,i,s]),this}overlayWith(t){t instanceof yt||(t=new yt(t));const e=this.getSource(),s=t.getSource(),[i,n,r]=e.map((a,h)=>Math.round(.5*a+.5*s[h]));return this.setSource([i,n,r,e[3]]),this}static fromRgb(t){return yt.fromRgba(t)}static fromRgba(t){return new yt(yt.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 a=parseFloat(r);return r.endsWith("%")?Math.round(2.55*a):a});return[s,i,n,$p(e[4])]}}static fromHsl(t){return yt.fromHsla(t)}static fromHsla(t){return new yt(yt.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=(yt.parseAngletoDegrees(e[1])%360+360)%360/360,i=parseFloat(e[2])/100,n=parseFloat(e[3])/100;let r,a,h;if(i===0)r=a=h=n;else{const l=n<=.5?n*(i+1):n+i-n*i,u=2*n-l;r=$d(u,l,s+1/3),a=$d(u,l,s),h=$d(u,l,s-1/3)}return[Math.round(255*r),Math.round(255*a),Math.round(255*h),$p(e[4])]}static fromHex(t){return new yt(yt.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,a=255]=s.map(h=>parseInt(h,16));return[i,n,r,a/255]}}static parseAngletoDegrees(t){const e=t.toLowerCase(),s=parseFloat(e);return e.includes("rad")?kn(s):e.includes("turn")?360*s:s}}const Dt=(o,t)=>parseFloat(Number(o).toFixed(t)),Ie=function(o){let t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:Bd;const e=/\D{0,2}$/.exec(o),s=parseFloat(o),i=dt.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}},Kd=o=>{const[t,e]=o.trim().split(" "),[s,i]=(n=t)&&n!==Re?[n.slice(1,4),n.slice(5,8)]:n===Re?[n,n]:["Mid","Mid"];var n;return{meetOrSlice:e||"meet",alignX:s,alignY:i}},bh=o=>"matrix("+o.map(t=>Dt(t,dt.NUM_FRACTION_DIGITS)).join(" ")+")",yh=function(o,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 yt(t),r=n.getAlpha();e=n.toRgb(),r!==1&&(s=r.toString())}else e="none";return i?"".concat(o,": ").concat(e,"; ").concat(s?"".concat(o,"-opacity: ").concat(s,"; "):""):"".concat(o,'="').concat(e,'" ').concat(s?"".concat(o,'-opacity="').concat(s,'" '):"")},bs=o=>!!o&&o.toLive!==void 0,Jp=o=>!!o&&typeof o.toObject=="function",Qp=o=>!!o&&o.offsetX!==void 0&&"source"in o,Zp=o=>!!o&&typeof o._renderText=="function",vr=o=>!!o&&"multiSelectionStacking"in o;function tm(o){const t=o&&js(o);let e=0,s=0;if(!o||!t)return{left:e,top:s};let i=o;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 js=o=>o.ownerDocument||null,em=o=>{var t;return((t=o.ownerDocument)===null||t===void 0?void 0:t.defaultView)||null},sm=function(o,t,e){let{width:s,height:i}=e,n=arguments.length>3&&arguments[3]!==void 0?arguments[3]:1;o.width=s,o.height=i,n>1&&(o.setAttribute("width",(s*n).toString()),o.setAttribute("height",(i*n).toString()),t.scale(n,n))},Jd=(o,t)=>{let{width:e,height:s}=t;e&&(o.style.width=typeof e=="number"?"".concat(e,"px"):e),s&&(o.style.height=typeof s=="number"?"".concat(s,"px"):s)};function im(o){return o.onselectstart!==void 0&&(o.onselectstart=()=>!1),o.style.userSelect=Re,o}class nm{constructor(t){T(this,"_originalCanvasStyle",void 0),T(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&&ja().getElementById(t)||vs();var s;if(e.hasAttribute("data-fabric"))throw new ai("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;sm(s,i,t,e)}setCSSDimensions(t){Jd(this.lower.el,t)}calcOffset(){return function(t){var e;const s=t&&js(t),i={left:0,top:0};if(!s)return i;const n=((e=em(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 a=s.documentElement;t.getBoundingClientRect!==void 0&&(r=t.getBoundingClientRect());const h=tm(t);return{left:r.left+h.left-(a.clientLeft||0)+i.left,top:r.top+h.top-(a.clientTop||0)+i.top}}(this.lower.el)}dispose(){oi().dispose(this.lower.el),delete this.lower}}const Ly={backgroundVpt:!0,backgroundColor:"",overlayVpt:!0,overlayColor:"",includeDefaultValues:!0,svgViewportTransformation:!0,renderOnAddRemove:!0,skipOffscreen:!0,enableRetinaScaling:!0,imageSmoothingEnabled:!0,controlsAboveOverlay:!1,allowTouchScrolling:!1,viewportTransform:[...De]};class _h extends Bp(Hp){get lowerCanvasEl(){var t;return(t=this.elements.lower)===null||t===void 0?void 0:t.el}get contextContainer(){var t;return(t=this.elements.lower)===null||t===void 0?void 0:t.ctx}static getDefaults(){return _h.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 nm(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&&(Pi("warn",`Canvas is trying to add an object that belongs to a different canvas.
|
|
31
|
+
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(),Pi("log","WebGL: max texture size ".concat(this.maxTextureSize)))}isSupported(t){return!!this.maxTextureSize&&this.maxTextureSize>=t}}const Oy={};let Fp;const oi=()=>Fp||(Fp={document,window,isTouchSupported:"ontouchstart"in window||"ontouchstart"in document||window&&window.navigator&&window.navigator.maxTouchPoints>0,WebGLProbe:new My,dispose(){},copyPasteData:Oy}),ja=()=>oi().document,_c=()=>oi().window,Lp=()=>{var o;return Math.max((o=dt.devicePixelRatio)!==null&&o!==void 0?o:_c().devicePixelRatio,1)},dh=new class{constructor(){T(this,"charWidthsCache",{}),T(this,"boundsOfCurveCache",{})}getFontCache(o){let{fontFamily:t,fontStyle:e,fontWeight:s}=o;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(o){(o=(o||"").toLowerCase())?this.charWidthsCache[o]&&delete this.charWidthsCache[o]:this.charWidthsCache={}}limitDimsByArea(o){const{perfLimitSizeTotal:t}=dt,e=Math.sqrt(t*o);return[Math.floor(e),Math.floor(t/e)]}},jd="6.5.1";function gr(){}const An=Math.PI/2,Di=2*Math.PI,Nd=Math.PI/180,De=Object.freeze([1,0,0,1,0,0]),Bd=16,Tn=.4477152502,st="center",mt="left",Ue="top",Hd="bottom",Vt="right",Re="none",Wd=/\r?\n/,Ip="moving",wc="scaling",jp="rotating",Xd="rotate",Np="skewing",gh="resizing",Py="modifyPoly",Dy="modifyPath",xc="changed",Sc="scale",Fe="scaleX",is="scaleY",Na="skewX",Ba="skewY",$t="fill",Le="stroke",Cc="modified",Ha="json",zd="svg",V=new class{constructor(){this[Ha]=new Map,this[zd]=new Map}has(o){return this[Ha].has(o)}getClass(o){const t=this[Ha].get(o);if(!t)throw new ai("No class registered for ".concat(o));return t}setClass(o,t){t?this[Ha].set(t,o):(this[Ha].set(o.type,o),this[Ha].set(o.type.toLowerCase(),o))}getSVGClass(o){return this[zd].get(o)}setSVGClass(o,t){this[zd].set(t??o.type.toLowerCase(),o)}},Ac=new class extends Array{remove(o){const t=this.indexOf(o);t>-1&&this.splice(t,1)}cancelAll(){const o=this.splice(0);return o.forEach(t=>t.abort()),o}cancelByCanvas(o){if(!o)return[];const t=this.filter(e=>{var s;return e.target===o||typeof e.target=="object"&&((s=e.target)===null||s===void 0?void 0:s.canvas)===o});return t.forEach(e=>e.abort()),t}cancelByTarget(o){if(!o)return[];const t=this.filter(e=>e.target===o);return t.forEach(e=>e.abort()),t}};class Ry{constructor(){T(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 fr=(o,t)=>{const e=o.indexOf(t);return e!==-1&&o.splice(e,1),o},Fs=o=>{if(o===0)return 1;switch(Math.abs(o)/An){case 1:case 3:return 0;case 2:return-1}return Math.cos(o)},Ls=o=>{if(o===0)return 0;const t=o/An,e=Math.sign(o);switch(t){case 1:return e;case 2:return 0;case 3:return-e}return Math.sin(o)};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]:Vd;const s=Ls(t),i=Fs(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 Vd=new D(0,0),Tc=o=>!!o&&Array.isArray(o._objects);function Bp(o){class t extends o{constructor(){super(...arguments),T(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(a=>this._onObjectAdded(a)),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(a=>this._onObjectAdded(a)),this._objects.length}remove(){const s=this._objects,i=[];for(var n=arguments.length,r=new Array(n),a=0;a<n;a++)r[a]=arguments[a];return r.forEach(h=>{const l=s.indexOf(h);l!==-1&&(s.splice(l,1),i.push(h),this._onObjectRemoved(h))}),i}forEachObject(s){this.getObjects().forEach((i,n,r)=>s(i,n,r))}getObjects(){for(var s=arguments.length,i=new Array(s),n=0;n<s;n++)i[n]=arguments[n];return i.length===0?[...this._objects]:this._objects.filter(r=>r.isType(...i))}item(s){return this._objects[s]}isEmpty(){return this._objects.length===0}size(){return this._objects.length}contains(s,i){return!!this._objects.includes(s)||!!i&&this._objects.some(n=>n instanceof t&&n.contains(s,!0))}complexity(){return this._objects.reduce((s,i)=>s+=i.complexity?i.complexity():0,0)}sendObjectToBack(s){return!(!s||s===this._objects[0])&&(fr(this._objects,s),this._objects.unshift(s),this._onStackOrderChanged(s),!0)}bringObjectToFront(s){return!(!s||s===this._objects[this._objects.length-1])&&(fr(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 fr(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 fr(this._objects,s),this._objects.splice(r,0,s),this._onStackOrderChanged(s),!0}return!1}moveObjectTo(s,i){return s!==this._objects[i]&&(fr(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 a=i-1;a>=0;--a)if(s.isOverlapping(this._objects[a])){r=a;break}}else r=i-1;return r}findNewUpperIndex(s,i,n){let r;if(n){r=i;for(let a=i+1;a<this._objects.length;++a)if(s.isOverlapping(this._objects[a])){r=a;break}}else r=i+1;return r}collectObjects(s){let{left:i,top:n,width:r,height:a}=s,{includeIntersecting:h=!0}=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};const l=[],u=new D(i,n),d=u.add(new D(r,a));for(let g=this._objects.length-1;g>=0;g--){const f=this._objects[g];f.selectable&&f.visible&&(h&&f.intersectsWithRect(u,d)||f.isContainedWithinRect(u,d)||h&&f.containsPoint(u)||h&&f.containsPoint(d))&&l.push(f)}return l}}return t}class Hp extends Ry{_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 fh(o){return _c().requestAnimationFrame(o)}function Wp(o){return _c().cancelAnimationFrame(o)}let Fy=0;const En=()=>Fy++,vs=()=>{const o=ja().createElement("canvas");if(!o||o.getContext===void 0)throw new ai("Failed to create `canvas` element");return o},Xp=()=>ja().createElement("img"),Is=o=>{const t=vs();return t.width=o.width,t.height=o.height,t},Gd=(o,t,e)=>o.toDataURL("image/".concat(t),e),Wt=o=>o*Nd,kn=o=>o/Nd,zp=o=>o.every((t,e)=>t===De[e]),we=(o,t,e)=>new D(o).transform(t,e),qe=o=>{const t=1/(o[0]*o[3]-o[1]*o[2]),e=[t*o[3],-t*o[1],-t*o[2],t*o[0],0,0],{x:s,y:i}=new D(o[4],o[5]).transform(e,!0);return e[4]=-s,e[5]=-i,e},Gt=(o,t,e)=>[o[0]*t[0]+o[2]*t[1],o[1]*t[0]+o[3]*t[1],o[0]*t[2]+o[2]*t[3],o[1]*t[2]+o[3]*t[3],e?0:o[0]*t[4]+o[2]*t[5]+o[4],e?0:o[1]*t[4]+o[3]*t[5]+o[5]],Ec=(o,t)=>o.reduceRight((e,s)=>s&&e?Gt(s,e,t):s||e,void 0)||De.concat(),Vp=o=>{let[t,e]=o;return Math.atan2(e,t)},pr=o=>{const t=Vp(o),e=Math.pow(o[0],2)+Math.pow(o[1],2),s=Math.sqrt(e),i=(o[0]*o[3]-o[2]*o[1])/s,n=Math.atan2(o[0]*o[2]+o[1]*o[3],e);return{angle:kn(t),scaleX:s,scaleY:i,skewX:kn(n),skewY:0,translateX:o[4]||0,translateY:o[5]||0}},Wa=function(o){return[1,0,0,1,o,arguments.length>1&&arguments[1]!==void 0?arguments[1]:0]};function Xa(){let{angle:o=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=Wt(o),i=Fs(s),n=Ls(s);return[i,n,-n,i,t?t-(i*t-n*e):0,e?e-(n*t+i*e):0]}const kc=function(o){return[o,0,0,arguments.length>1&&arguments[1]!==void 0?arguments[1]:o,0,0]},Gp=o=>Math.tan(Wt(o)),Yd=o=>[1,0,Gp(o),1,0,0],Ud=o=>[1,Gp(o),0,1,0,0],ph=o=>{let{scaleX:t=1,scaleY:e=1,flipX:s=!1,flipY:i=!1,skewX:n=0,skewY:r=0}=o,a=kc(s?-t:t,i?-e:e);return n&&(a=Gt(a,Yd(n),!0)),r&&(a=Gt(a,Ud(r),!0)),a},Yp=o=>{const{translateX:t=0,translateY:e=0,angle:s=0}=o;let i=Wa(t,e);s&&(i=Gt(i,Xa({angle:s})));const n=ph(o);return zp(n)||(i=Gt(i,n)),i},mh=function(o){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 Id("loadImage"));const n=Xp();let r;t&&(r=function(h){n.src="",i(h)},t.addEventListener("abort",r,{once:!0}));const a=function(){n.onload=n.onerror=null,r&&(t==null||t.removeEventListener("abort",r)),s(n)};o?(n.onload=a,n.onerror=function(){r&&(t==null||t.removeEventListener("abort",r)),i(new ai("Error loading ".concat(n.src)))},e&&(n.crossOrigin=e),n.src=o):a()})},za=function(o){let{signal:t,reviver:e=gr}=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(o.map(r=>V.getClass(r.type).fromObject(r,{signal:t}).then(a=>(e(r,a),n.push(a),a)))).then(s).catch(r=>{n.forEach(a=>{a.dispose&&a.dispose()}),i(r)}).finally(()=>{t&&t.removeEventListener("abort",i)})})},vh=function(o){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(o).map(a=>a&&a.type&&V.has(a.type)?za([a],{signal:t}).then(h=>{let[l]=h;return i.push(l),l}):a),r=Object.keys(o);Promise.all(n).then(a=>a.reduce((h,l,u)=>(h[r[u]]=l,h),{})).then(e).catch(a=>{i.forEach(h=>{h.dispose&&h.dispose()}),s(a)}).finally(()=>{t&&t.removeEventListener("abort",s)})})},mr=function(o){return(arguments.length>1&&arguments[1]!==void 0?arguments[1]:[]).reduce((t,e)=>(e in o&&(t[e]=o[e]),t),{})},qd=(o,t)=>Object.keys(o).reduce((e,s)=>(t(o[s],s,o)&&(e[s]=o[s]),e),{}),Up={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"},$d=(o,t,e)=>(e<0&&(e+=1),e>1&&(e-=1),e<1/6?o+6*(t-o)*e:e<.5?t:e<2/3?o+(t-o)*(2/3-e)*6:o),qp=(o,t,e,s)=>{o/=255,t/=255,e/=255;const i=Math.max(o,t,e),n=Math.min(o,t,e);let r,a;const h=(i+n)/2;if(i===n)r=a=0;else{const l=i-n;switch(a=h>.5?l/(2-i-n):l/(i+n),i){case o:r=(t-e)/l+(t<e?6:0);break;case t:r=(e-o)/l+2;break;case e:r=(o-t)/l+4}r/=6}return[Math.round(360*r),Math.round(100*a),Math.round(100*h),s]},$p=function(){let o=arguments.length>0&&arguments[0]!==void 0?arguments[0]:"1";return parseFloat(o)/(o.endsWith("%")?100:1)},Mc=o=>Math.min(Math.round(o),255).toString(16).toUpperCase().padStart(2,"0"),Kp=o=>{let[t,e,s,i=1]=o;const n=Math.round(.3*t+.59*e+.11*s);return[n,n,n,i]};class yt{constructor(t){if(T(this,"isUnrecognised",!1),t)if(t instanceof yt)this.setSource([...t._source]);else if(Array.isArray(t)){const[e,s,i,n=1]=t;this.setSource([e,s,i,n])}else this.setSource(this._tryParsingColor(t));else this.setSource([0,0,0,1])}_tryParsingColor(t){return t in Up&&(t=Up[t]),t==="transparent"?[255,255,255,0]:yt.sourceFromHex(t)||yt.sourceFromRgb(t)||yt.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]=qp(...this.getSource());return"hsl(".concat(t,",").concat(e,"%,").concat(s,"%)")}toHsla(){const[t,e,s,i]=qp(...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(Mc(t)).concat(Mc(e)).concat(Mc(s)).concat(Mc(Math.round(255*i)))}getAlpha(){return this.getSource()[3]}setAlpha(t){return this._source[3]=t,this}toGrayscale(){return this.setSource(Kp(this.getSource())),this}toBlackWhite(t){const[e,,,s]=Kp(this.getSource()),i=e<(t||127)?0:255;return this.setSource([i,i,i,s]),this}overlayWith(t){t instanceof yt||(t=new yt(t));const e=this.getSource(),s=t.getSource(),[i,n,r]=e.map((a,h)=>Math.round(.5*a+.5*s[h]));return this.setSource([i,n,r,e[3]]),this}static fromRgb(t){return yt.fromRgba(t)}static fromRgba(t){return new yt(yt.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 a=parseFloat(r);return r.endsWith("%")?Math.round(2.55*a):a});return[s,i,n,$p(e[4])]}}static fromHsl(t){return yt.fromHsla(t)}static fromHsla(t){return new yt(yt.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=(yt.parseAngletoDegrees(e[1])%360+360)%360/360,i=parseFloat(e[2])/100,n=parseFloat(e[3])/100;let r,a,h;if(i===0)r=a=h=n;else{const l=n<=.5?n*(i+1):n+i-n*i,u=2*n-l;r=$d(u,l,s+1/3),a=$d(u,l,s),h=$d(u,l,s-1/3)}return[Math.round(255*r),Math.round(255*a),Math.round(255*h),$p(e[4])]}static fromHex(t){return new yt(yt.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,a=255]=s.map(h=>parseInt(h,16));return[i,n,r,a/255]}}static parseAngletoDegrees(t){const e=t.toLowerCase(),s=parseFloat(e);return e.includes("rad")?kn(s):e.includes("turn")?360*s:s}}const Dt=(o,t)=>parseFloat(Number(o).toFixed(t)),Ie=function(o){let t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:Bd;const e=/\D{0,2}$/.exec(o),s=parseFloat(o),i=dt.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}},Kd=o=>{const[t,e]=o.trim().split(" "),[s,i]=(n=t)&&n!==Re?[n.slice(1,4),n.slice(5,8)]:n===Re?[n,n]:["Mid","Mid"];var n;return{meetOrSlice:e||"meet",alignX:s,alignY:i}},bh=o=>"matrix("+o.map(t=>Dt(t,dt.NUM_FRACTION_DIGITS)).join(" ")+")",yh=function(o,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 yt(t),r=n.getAlpha();e=n.toRgb(),r!==1&&(s=r.toString())}else e="none";return i?"".concat(o,": ").concat(e,"; ").concat(s?"".concat(o,"-opacity: ").concat(s,"; "):""):"".concat(o,'="').concat(e,'" ').concat(s?"".concat(o,'-opacity="').concat(s,'" '):"")},bs=o=>!!o&&o.toLive!==void 0,Jp=o=>!!o&&typeof o.toObject=="function",Qp=o=>!!o&&o.offsetX!==void 0&&"source"in o,Zp=o=>!!o&&typeof o._renderText=="function",vr=o=>!!o&&"multiSelectionStacking"in o;function tm(o){const t=o&&js(o);let e=0,s=0;if(!o||!t)return{left:e,top:s};let i=o;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 js=o=>o.ownerDocument||null,em=o=>{var t;return((t=o.ownerDocument)===null||t===void 0?void 0:t.defaultView)||null},sm=function(o,t,e){let{width:s,height:i}=e,n=arguments.length>3&&arguments[3]!==void 0?arguments[3]:1;o.width=s,o.height=i,n>1&&(o.setAttribute("width",(s*n).toString()),o.setAttribute("height",(i*n).toString()),t.scale(n,n))},Jd=(o,t)=>{let{width:e,height:s}=t;e&&(o.style.width=typeof e=="number"?"".concat(e,"px"):e),s&&(o.style.height=typeof s=="number"?"".concat(s,"px"):s)};function im(o){return o.onselectstart!==void 0&&(o.onselectstart=()=>!1),o.style.userSelect=Re,o}class nm{constructor(t){T(this,"_originalCanvasStyle",void 0),T(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&&ja().getElementById(t)||vs();var s;if(e.hasAttribute("data-fabric"))throw new ai("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;sm(s,i,t,e)}setCSSDimensions(t){Jd(this.lower.el,t)}calcOffset(){return function(t){var e;const s=t&&js(t),i={left:0,top:0};if(!s)return i;const n=((e=em(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 a=s.documentElement;t.getBoundingClientRect!==void 0&&(r=t.getBoundingClientRect());const h=tm(t);return{left:r.left+h.left-(a.clientLeft||0)+i.left,top:r.top+h.top-(a.clientTop||0)+i.top}}(this.lower.el)}dispose(){oi().dispose(this.lower.el),delete this.lower}}const Ly={backgroundVpt:!0,backgroundColor:"",overlayVpt:!0,overlayColor:"",includeDefaultValues:!0,svgViewportTransformation:!0,renderOnAddRemove:!0,skipOffscreen:!0,enableRetinaScaling:!0,imageSmoothingEnabled:!0,controlsAboveOverlay:!1,allowTouchScrolling:!1,viewportTransform:[...De]};class _h extends Bp(Hp){get lowerCanvasEl(){var t;return(t=this.elements.lower)===null||t===void 0?void 0:t.el}get contextContainer(){var t;return(t=this.elements.lower)===null||t===void 0?void 0:t.ctx}static getDefaults(){return _h.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 nm(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&&(Pi("warn",`Canvas is trying to add an object that belongs to a different canvas.
|
|
32
32
|
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?Lp():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=E({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=we(t,qe(i));i[0]=e,i[3]=e;const r=we(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=fh(()=>this.renderAndReset()))}calcViewportBoundaries(){const t=this.width,e=this.height,s=qe(this.viewportTransform),i=we({x:0,y:0},s),n=we({x:t,y:e},s),r=i.min(n),a=i.max(n);return this.vptCoords={tl:r,tr:new D(a.x,r.y),bl:new D(r.x,a.y),br:a}}cancelRequestedRender(){this.nextRenderHandle&&(Wp(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 a=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=a?s.toLive(t):s,r&&t.transform(...n),a){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 we(this.getCenterPoint(),qe(this.viewportTransform))}_centerObject(t,e){t.setXY(e,st,st),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 E(E(E({version:jd},mr(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,a=this.overlayColor;return bs(r)?r.excludeFromExport||(s.background=r.toObject(e)):r&&(s.background=r),bs(a)?a.excludeFromExport||(s.overlay=a.toObject(e)):a&&(s.overlay=a),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,`)" >
|
|
33
33
|
`)),this._setSVGBgOverlayColor(s,"background"),this._setSVGBgOverlayImage(s,"backgroundImage",e),this._setSVGObjects(s,e),this.clipPath&&s.push(`</g>
|
|
34
34
|
`),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" ?>
|
|
@@ -63,7 +63,7 @@ Resulting to default behavior: removing object from previous canvas and adding t
|
|
|
63
63
|
<feMergeNode in="SourceGraphic"></feMergeNode>
|
|
64
64
|
</feMerge>
|
|
65
65
|
</filter>
|
|
66
|
-
`)}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=Ri.ownDefaults;return this.includeDefaultValues?t:qd(t,(s,i)=>s!==e[i])}static async fromObject(t){return new this(t)}}T(Ri,"ownDefaults",{color:"rgb(0,0,0)",blur:0,offsetX:0,offsetY:0,affectStroke:!1,includeDefaultValues:!0,nonScaling:!1}),T(Ri,"type","shadow"),V.setClass(Ri,"shadow");const yr=(o,t,e)=>Math.max(o,Math.min(t,e)),Gy=[Ue,mt,Fe,is,"flipX","flipY","originX","originY","angle","opacity","globalCompositeOperation","shadow","visible",Na,Ba],Fi=[$t,Le,"strokeWidth","strokeDashArray","width","height","paintFirst","strokeUniform","strokeLineCap","strokeDashOffset","strokeLineJoin","strokeMiterLimit","backgroundColor","clipPath"],Yy={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:mt,originY:Ue,strokeWidth:1,strokeUniform:!1,padding:0,opacity:1,paintFirst:$t,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},hg=(o,t,e,s)=>(o<Math.abs(t)?(o=t,s=e/4):s=t===0&&o===0?e/Di*Math.asin(1):e/Di*Math.asin(t/o),{a:o,c:t,p:e,s}),Sm=(o,t,e,s,i)=>o*Math.pow(2,10*(s-=1))*Math.sin((s*i-t)*Di/e),Cm=(o,t,e,s)=>-e*Math.cos(o/s*An)+e+t,lg=(o,t,e,s)=>(o/=s)<1/2.75?e*(7.5625*o*o)+t:o<2/2.75?e*(7.5625*(o-=1.5/2.75)*o+.75)+t:o<2.5/2.75?e*(7.5625*(o-=2.25/2.75)*o+.9375)+t:e*(7.5625*(o-=2.625/2.75)*o+.984375)+t,Am=(o,t,e,s)=>e-lg(s-o,0,e,s)+t;var Uy=Object.freeze({__proto__:null,defaultEasing:Cm,easeInBack:function(o,t,e,s){let i=arguments.length>4&&arguments[4]!==void 0?arguments[4]:1.70158;return e*(o/=s)*o*((i+1)*o-i)+t},easeInBounce:Am,easeInCirc:(o,t,e,s)=>-e*(Math.sqrt(1-(o/=s)*o)-1)+t,easeInCubic:(o,t,e,s)=>e*(o/s)**3+t,easeInElastic:(o,t,e,s)=>{const i=e;let n=0;if(o===0)return t;if((o/=s)===1)return t+e;n||(n=.3*s);const{a:r,s:a,p:h}=hg(i,e,n,1.70158);return-Sm(r,a,h,o,s)+t},easeInExpo:(o,t,e,s)=>o===0?t:e*2**(10*(o/s-1))+t,easeInOutBack:function(o,t,e,s){let i=arguments.length>4&&arguments[4]!==void 0?arguments[4]:1.70158;return(o/=s/2)<1?e/2*(o*o*((1+(i*=1.525))*o-i))+t:e/2*((o-=2)*o*((1+(i*=1.525))*o+i)+2)+t},easeInOutBounce:(o,t,e,s)=>o<s/2?.5*Am(2*o,0,e,s)+t:.5*lg(2*o-s,0,e,s)+.5*e+t,easeInOutCirc:(o,t,e,s)=>(o/=s/2)<1?-e/2*(Math.sqrt(1-o**2)-1)+t:e/2*(Math.sqrt(1-(o-=2)*o)+1)+t,easeInOutCubic:(o,t,e,s)=>(o/=s/2)<1?e/2*o**3+t:e/2*((o-2)**3+2)+t,easeInOutElastic:(o,t,e,s)=>{const i=e;let n=0;if(o===0)return t;if((o/=s/2)===2)return t+e;n||(n=s*(.3*1.5));const{a:r,s:a,p:h,c:l}=hg(i,e,n,1.70158);return o<1?-.5*Sm(r,a,h,o,s)+t:r*Math.pow(2,-10*(o-=1))*Math.sin((o*s-a)*Di/h)*.5+l+t},easeInOutExpo:(o,t,e,s)=>o===0?t:o===s?t+e:(o/=s/2)<1?e/2*2**(10*(o-1))+t:e/2*-(2**(-10*--o)+2)+t,easeInOutQuad:(o,t,e,s)=>(o/=s/2)<1?e/2*o**2+t:-e/2*(--o*(o-2)-1)+t,easeInOutQuart:(o,t,e,s)=>(o/=s/2)<1?e/2*o**4+t:-e/2*((o-=2)*o**3-2)+t,easeInOutQuint:(o,t,e,s)=>(o/=s/2)<1?e/2*o**5+t:e/2*((o-2)**5+2)+t,easeInOutSine:(o,t,e,s)=>-e/2*(Math.cos(Math.PI*o/s)-1)+t,easeInQuad:(o,t,e,s)=>e*(o/=s)*o+t,easeInQuart:(o,t,e,s)=>e*(o/=s)*o**3+t,easeInQuint:(o,t,e,s)=>e*(o/s)**5+t,easeInSine:(o,t,e,s)=>-e*Math.cos(o/s*An)+e+t,easeOutBack:function(o,t,e,s){let i=arguments.length>4&&arguments[4]!==void 0?arguments[4]:1.70158;return e*((o=o/s-1)*o*((i+1)*o+i)+1)+t},easeOutBounce:lg,easeOutCirc:(o,t,e,s)=>e*Math.sqrt(1-(o=o/s-1)*o)+t,easeOutCubic:(o,t,e,s)=>e*((o/s-1)**3+1)+t,easeOutElastic:(o,t,e,s)=>{const i=e;let n=0;if(o===0)return t;if((o/=s)===1)return t+e;n||(n=.3*s);const{a:r,s:a,p:h,c:l}=hg(i,e,n,1.70158);return r*2**(-10*o)*Math.sin((o*s-a)*Di/h)+l+t},easeOutExpo:(o,t,e,s)=>o===s?t+e:e*-(2**(-10*o/s)+1)+t,easeOutQuad:(o,t,e,s)=>-e*(o/=s)*(o-2)+t,easeOutQuart:(o,t,e,s)=>-e*((o=o/s-1)*o**3-1)+t,easeOutQuint:(o,t,e,s)=>e*((o/s-1)**5+1)+t,easeOutSine:(o,t,e,s)=>e*Math.sin(o/s*An)+t});const qy=()=>!1;class cg{constructor(t){let{startValue:e,byValue:s,duration:i=500,delay:n=0,easing:r=Cm,onStart:a=gr,onChange:h=gr,onComplete:l=gr,abort:u=qy,target:d}=t;T(this,"_state","pending"),T(this,"durationProgress",0),T(this,"valueProgress",0),this.tick=this.tick.bind(this),this.duration=i,this.delay=n,this.easing=r,this._onStart=a,this._onChange=h,this._onComplete=l,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(()=>fh(t),this.delay):fh(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),fh(this.tick)))}register(){Ac.push(this)}unregister(){Ac.remove(this)}abort(){this._state="aborted",this.unregister()}}const $y=["startValue","endValue"];class Ky extends cg{constructor(t){let{startValue:e=0,endValue:s=100}=t;super(E(E({},Pt(t,$y)),{},{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 Jy=["startValue","endValue"];class Qy extends cg{constructor(t){let{startValue:e=[0],endValue:s=[100]}=t;super(E(E({},Pt(t,Jy)),{},{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 Zy=["startValue","endValue","easing","onChange","onComplete","abort"],t_=(o,t,e,s)=>t+e*(1-Math.cos(o/s*An)),ug=o=>o&&((t,e,s)=>o(new yt(t).toRgba(),e,s));class e_ extends cg{constructor(t){let{startValue:e,endValue:s,easing:i=t_,onChange:n,onComplete:r,abort:a}=t,h=Pt(t,Zy);const l=new yt(e).getSource(),u=new yt(s).getSource();super(E(E({},h),{},{startValue:l,byValue:u.map((d,g)=>d-l[g]),easing:i,onChange:ug(n),onComplete:ug(r),abort:ug(a)}))}calculate(t){const[e,s,i,n]=this.startValue.map((a,h)=>this.easing(t,a,this.byValue[h],this.duration,h)),r=[...[e,s,i].map(Math.round),yr(0,n,1)];return{value:r,valueProgress:r.map((a,h)=>this.byValue[h]!==0?Math.abs((a-this.startValue[h])/this.byValue[h]):0).find(a=>a!==0)||0}}}function dg(o){const t=(e=>Array.isArray(e.startValue)||Array.isArray(e.endValue))(o)?new Qy(o):new Ky(o);return t.start(),t}function Tm(o){const t=new e_(o);return t.start(),t}class Lt{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=Fc(e,s),r=Fc(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 a=e.x-t.x,h=e.y-t.y,l=i.x-s.x,u=i.y-s.y,d=t.x-s.x,g=t.y-s.y,f=l*g-u*d,p=a*g-h*d,m=u*a-l*h;if(m!==0){const _=f/m,b=p/m;return(n||0<=_&&_<=1)&&(r||0<=b&&b<=1)?new Lt("Intersection").append(new D(t.x+_*a,t.y+_*h)):new Lt}if(f===0||p===0){const _=n||r||Lt.isPointContained(t,s,i)||Lt.isPointContained(e,s,i)||Lt.isPointContained(s,t,e)||Lt.isPointContained(i,t,e);return new Lt(_?"Coincident":void 0)}return new Lt("Parallel")}static intersectSegmentLine(t,e,s,i){return Lt.intersectLineLine(t,e,s,i,!1,!0)}static intersectSegmentSegment(t,e,s,i){return Lt.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 Lt,r=s.length;for(let a,h,l,u=0;u<r;u++){if(a=s[u],h=s[(u+1)%r],l=Lt.intersectLineLine(t,e,a,h,i,!1),l.status==="Coincident")return l;n.append(...l.points)}return n.points.length>0&&(n.status="Intersection"),n}static intersectSegmentPolygon(t,e,s){return Lt.intersectLinePolygon(t,e,s,!1)}static intersectPolygonPolygon(t,e){const s=new Lt,i=t.length,n=[];for(let r=0;r<i;r++){const a=t[r],h=t[(r+1)%i],l=Lt.intersectSegmentPolygon(a,h,e);l.status==="Coincident"?(n.push(l),s.append(a,h)):s.append(...l.points)}return n.length>0&&n.length===t.length?new Lt("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),a=new D(i.x,n.y);return Lt.intersectPolygonPolygon(t,[i,r,n,a])}}class s_ extends Hp{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?we(t,this.group.calcTransformMatrix()):t}setXY(t,e,s){this.group&&(t=we(t,qe(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(a=>we(a,r))}return n}intersectsWithRect(t,e){return Lt.intersectPolygonRectangle(this.getCoords(),t,e).status==="Intersection"}intersectsWithObject(t){const e=Lt.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 Lt.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 hi(this.getCoords())}getScaledWidth(){return this._getTransformedDimensions().x}getScaledHeight(){return this._getTransformedDimensions().y}scale(t){this._set(Fe,t),this._set(is,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(Vp(this.calcTransformMatrix())):this.angle}getViewportTransform(){var t;return((t=this.canvas)===null||t===void 0?void 0:t.viewportTransform)||De.concat()}calcACoords(){const t=Xa({angle:this.angle}),{x:e,y:s}=this.getRelativeCenterPoint(),i=Wa(e,s),n=Gt(i,t),r=this._getTransformedDimensions(),a=r.x/2,h=r.y/2;return{tl:we({x:-a,y:-h},n),tr:we({x:a,y:-h},n),bl:we({x:-a,y:h},n),br:we({x:a,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,Kt(this.originX),Kt(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=Gt(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=Yp(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=E({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,a=e.height+i;let h;return h=e.skewX===0&&e.skewY===0?new D(r*e.scaleX,a*e.scaleY):Pc(r,a,ph(e)),h.scalarAdd(n)}translateToGivenOrigin(t,e,s,i,n){let r=t.x,a=t.y;const h=Kt(i)-Kt(e),l=Kt(n)-Kt(s);if(h||l){const u=this._getTransformedDimensions();r+=h*u.x,a+=l*u.y}return new D(r,a)}translateToCenterPoint(t,e,s){if(e===st&&s===st)return t;const i=this.translateToGivenOrigin(t,e,s,st,st);return this.angle?i.rotate(Wt(this.angle),t):i}translateToOriginPoint(t,e,s){const i=this.translateToGivenOrigin(t,st,st,e,s);return this.angle?i.rotate(Wt(this.angle),t):i}getCenterPoint(){const t=this.getRelativeCenterPoint();return this.group?we(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(),mt,Ue)}}const i_=["type"],n_=["extraParam"];let Li=class ad extends s_{static getDefaults(){return ad.ownDefaults}get type(){const t=this.constructor.type;return t==="FabricObject"?"object":t.toLowerCase()}set type(t){Pi("warn","Setting type has no effect",t)}constructor(t){super(),T(this,"_cacheContext",null),Object.assign(this,ad.ownDefaults),this.setOptions(t)}_createCacheCanvas(){this._cacheCanvas=vs(),this._cacheContext=this._cacheCanvas.getContext("2d"),this._updateCacheCanvas(),this.dirty=!0}_limitCacheSize(t){const e=t.width,s=t.height,i=dt.maxCacheSideLimit,n=dt.minCacheSideLimit;if(e<=i&&s<=i&&e*s<=dt.perfLimitSizeTotal)return e<n&&(t.width=n),s<n&&(t.height=n),t;const r=e/s,[a,h]=dh.limitDimsByArea(r),l=yr(n,a,i),u=yr(n,h,i);return e>l&&(t.zoomX/=e/l,t.width=l,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:s+2,height:i+2,zoomX:t.x,zoomY:t.y,x:s,y:i}}_updateCacheCanvas(){const t=this._cacheCanvas,e=this._cacheContext,s=this._limitCacheSize(this._getCacheCanvasDimensions()),i=dt.minCacheSideLimit,n=s.width,r=s.height,a=s.zoomX,h=s.zoomY,l=n!==t.width||r!==t.height,u=this.zoomX!==a||this.zoomY!==h;if(!t||!e)return!1;let d,g,f=l||u,p=0,m=0,_=!1;if(l){const b=this._cacheCanvas.width,x=this._cacheCanvas.height,S=n>b||r>x;_=S||(n<.9*b||r<.9*x)&&b>i&&x>i,S&&!s.capped&&(n>i||r>i)&&(p=.1*n,m=.1*r)}return Zp(this)&&this.path&&(f=!0,_=!0,p+=this.getHeightOfLine(0)*this.zoomX,m+=this.getHeightOfLine(0)*this.zoomY),!!f&&(_?(t.width=Math.ceil(n+p),t.height=Math.ceil(r+m)):(e.setTransform(1,0,0,1,0,0),e.clearRect(0,0,t.width,t.height)),d=s.x/2,g=s.y/2,this.cacheTranslationX=Math.round(t.width/2-d)+d,this.cacheTranslationY=Math.round(t.height/2-g)+g,e.translate(this.cacheTranslationX,this.cacheTranslationY),e.scale(a,h),this.zoomX=a,this.zoomY=h,!0)}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=pr(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!==Fe&&t!==is||(e=this._constrainScale(e)),t===Fe&&e<0?(this.flipX=!this.flipX,e*=-1):t==="scaleY"&&e<0?(this.flipY=!this.flipY,e*=-1):t!=="shadow"||!e||e instanceof Ri||(e=new Ri(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:a}=this._cacheCanvas;this.drawObject(this._cacheContext,t.forClipping,{zoomX:e,zoomY:s,cacheTranslationX:i,cacheTranslationY:n,width:r,height:a,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===Le&&this.hasFill()&&this.hasStroke()&&this.shadow)||!!this.clipPath}shouldCache(){return this.ownCaching=this.needsItsOwnCache()||this.objectCaching&&(!this.parent||!this.parent.isOnACache()),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=Is(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=qe(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&&(1&e.length&&e.push(...e),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)||De,a=n*i,h=r*i,l=e.nonScaling?new D(1,1):this.getObjectScaling();t.shadowColor=e.color,t.shadowBlur=e.blur*dt.browserShadowBlurConstant*(a+h)*(l.x+l.y)/4,t.shadowOffsetX=e.offsetX*a*l.x,t.shadowOffsetY=e.offsetY*h*l.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===Le?(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,a=i.y/this.scaleY/n,h=Is({width:Math.ceil(r),height:Math.ceil(a)}),l=h.getContext("2d");l&&(l.beginPath(),l.moveTo(0,0),l.lineTo(r,0),l.lineTo(r,a),l.lineTo(0,a),l.closePath(),l.translate(r/2,a/2),l.scale(i.zoomX/this.scaleX/n,i.zoomY/this.scaleY/n),this._applyPatternGradientTransform(l,e),l.fillStyle=e.toLive(t),l.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=l.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(V.getClass("image"))(e)}toCanvasElement(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};const e=Zd(this),s=this.group,i=this.shadow,n=Math.abs,r=t.enableRetinaScaling?Lp():1,a=(t.multiplier||1)*r,h=t.canvasProvider||(x=>new _h(x,{enableRetinaScaling:!1,renderOnAddRemove:!1,skipOffscreen:!1}));delete this.group,t.withoutTransform&&om(this),t.withoutShadow&&(this.shadow=null),t.viewportTransform&&tg(this,this.getViewportTransform()),this.setCoords();const l=vs(),u=this.getBoundingRect(),d=this.shadow,g=new D;if(d){const x=d.blur,S=d.nonScaling?new D(1,1):this.getObjectScaling();g.x=2*Math.round(n(d.offsetX)+x)*n(S.x),g.y=2*Math.round(n(d.offsetY)+x)*n(S.y)}const f=u.width+g.x,p=u.height+g.y;l.width=Math.ceil(f),l.height=Math.ceil(p);const m=h(l);t.format==="jpeg"&&(m.backgroundColor="#fff"),this.setPositionByOrigin(new D(m.width/2,m.height/2),st,st);const _=this.canvas;m._objects=[this],this.set("canvas",m),this.setCoords();const b=m.toCanvasElement(a||1,t);return this.set("canvas",_),this.shadow=i,s&&(this.group=s),this.set(e),this.setCoords(),m._objects=[],m.destroy(),b}toDataURL(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};return Gd(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=st,this.originY=st,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(){Ac.cancelByTarget(this),this.off(),this._set("canvas",void 0),this._cacheCanvas&&oi().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:a,onChange:h,onComplete:l}=s,u=E(E({},s),{},{target:this,startValue:a??i.reduce((d,g)=>d[g],this),endValue:e,abort:r==null?void 0:r.bind(this),onChange:(d,g,f)=>{i.reduce((p,m,_)=>(_===i.length-1&&(p[m]=d),p[m]),this),h&&h(d,g,f)},onComplete:(d,g,f)=>{this.setCoords(),l&&l(d,g,f)}});return n?Tm(u):dg(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),a=s._objects.indexOf(n);return r>-1&&r>a}toObject(){const t=(arguments.length>0&&arguments[0]!==void 0?arguments[0]:[]).concat(ad.customProperties,this.constructor.customProperties||[]);let e;const s=dt.NUM_FRACTION_DIGITS,{clipPath:i,fill:n,stroke:r,shadow:a,strokeDashArray:h,left:l,top:u,originX:d,originY:g,width:f,height:p,strokeWidth:m,strokeLineCap:_,strokeDashOffset:b,strokeLineJoin:x,strokeUniform:S,strokeMiterLimit:A,scaleX:k,scaleY:P,angle:M,flipX:O,flipY:R,opacity:I,visible:j,backgroundColor:G,fillRule:L,paintFirst:H,globalCompositeOperation:$,skewX:J,skewY:Y}=this;i&&!i.excludeFromExport&&(e=i.toObject(t.concat("inverted","absolutePositioned")));const X=zt=>Dt(zt,s),Ot=E(E({},mr(this,t)),{},{type:this.constructor.type,version:jd,originX:d,originY:g,left:X(l),top:X(u),width:X(f),height:X(p),fill:Jp(n)?n.toObject():n,stroke:Jp(r)?r.toObject():r,strokeWidth:X(m),strokeDashArray:h&&h.concat(),strokeLineCap:_,strokeDashOffset:b,strokeLineJoin:x,strokeUniform:S,strokeMiterLimit:X(A),scaleX:X(k),scaleY:X(P),angle:X(M),flipX:O,flipY:R,opacity:X(I),shadow:a&&a.toObject(),visible:j,backgroundColor:G,fillRule:L,paintFirst:H,globalCompositeOperation:$,skewX:X(J),skewY:X(Y)},e?{clipPath:e}:null);return this.includeDefaultValues?Ot:this._removeDefaultValues(Ot)}toDatalessObject(t){return this.toObject(t)}_removeDefaultValues(t){const e=this.constructor.getDefaults(),s=Object.keys(e).length>0?e:Object.getPrototypeOf(this);return qd(t,(i,n)=>{if(n===mt||n===Ue||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=Pt(t,i_),s=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},{extraParam:i}=s,n=Pt(s,n_);return vh(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)}};T(Li,"stateProperties",Gy),T(Li,"cacheProperties",Fi),T(Li,"ownDefaults",Yy),T(Li,"type","FabricObject"),T(Li,"colorProperties",[$t,Le,"backgroundColor"]),T(Li,"customProperties",[]),V.setClass(Li),V.setClass(Li,"object");const Ya=(o,t,e)=>(s,i,n,r)=>{const a=t(s,i,n,r);return a&&lm(o,E(E({},dm(s,i,n,r)),e)),a};function Ua(o){return(t,e,s,i)=>{const{target:n,originX:r,originY:a}=e,h=n.getRelativeCenterPoint(),l=n.translateToOriginPoint(h,r,a),u=o(t,e,s,i);return n.setPositionByOrigin(l,e.originX,e.originY),u}}const Em=Ya(gh,Ua((o,t,e,s)=>{const i=eg(t,t.originX,t.originY,e,s);if(Kt(t.originX)===Kt(st)||Kt(t.originX)===Kt(Vt)&&i.x<0||Kt(t.originX)===Kt(mt)&&i.x>0){const{target:n}=t,r=n.strokeWidth/(n.strokeUniform?n.scaleX:1),a=cm(t)?2:1,h=n.width,l=Math.abs(i.x*a/n.scaleX)-r;return n.set("width",Math.max(l,1)),h!==n.width}return!1}));function r_(o,t,e,s,i){s=s||{};const n=this.sizeX||s.cornerSize||i.cornerSize,r=this.sizeY||s.cornerSize||i.cornerSize,a=s.transparentCorners!==void 0?s.transparentCorners:i.transparentCorners,h=a?Le:$t,l=!a&&(s.cornerStrokeColor||i.cornerStrokeColor);let u,d=t,g=e;o.save(),o.fillStyle=s.cornerColor||i.cornerColor||"",o.strokeStyle=s.cornerStrokeColor||i.cornerStrokeColor||"",n>r?(u=n,o.scale(1,r/n),g=e*n/r):r>n?(u=r,o.scale(n/r,1),d=t*r/n):u=n,o.lineWidth=1,o.beginPath(),o.arc(d,g,u/2,0,Di,!1),o[h](),l&&o.stroke(),o.restore()}function a_(o,t,e,s,i){s=s||{};const n=this.sizeX||s.cornerSize||i.cornerSize,r=this.sizeY||s.cornerSize||i.cornerSize,a=s.transparentCorners!==void 0?s.transparentCorners:i.transparentCorners,h=a?Le:$t,l=!a&&(s.cornerStrokeColor||i.cornerStrokeColor),u=n/2,d=r/2;o.save(),o.fillStyle=s.cornerColor||i.cornerColor||"",o.strokeStyle=s.cornerStrokeColor||i.cornerStrokeColor||"",o.lineWidth=1,o.translate(t,e);const g=i.getTotalAngle();o.rotate(Wt(g)),o["".concat(h,"Rect")](-u,-d,n,r),l&&o.strokeRect(-u,-d,n,r),o.restore()}class Hs{constructor(t){T(this,"visible",!0),T(this,"actionName",Sc),T(this,"angle",0),T(this,"x",0),T(this,"y",0),T(this,"offsetX",0),T(this,"offsetY",0),T(this,"sizeX",0),T(this,"sizeY",0),T(this,"touchSizeX",0),T(this,"touchSizeY",0),T(this,"cursorStyle","crosshair"),T(this,"withConnection",!1),Object.assign(this,t)}shouldActivate(t,e,s,i){var n;let{tl:r,tr:a,br:h,bl:l}=i;return((n=e.canvas)===null||n===void 0?void 0:n.getActiveObject())===e&&e.isControlVisible(t)&&Lt.isPointInPolygon(s,[r,a,h,l])}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 a=Ec([Wa(s,i),Xa({angle:t}),kc((n?this.touchSizeX:this.sizeX)||e,(n?this.touchSizeY:this.sizeY)||e)]);return{tl:new D(-.5,-.5).transform(a),tr:new D(.5,-.5).transform(a),br:new D(.5,.5).transform(a),bl:new D(-.5,.5).transform(a)}}render(t,e,s,i,n){((i=i||{}).cornerStyle||n.cornerStyle)==="circle"?r_.call(this,t,e,s,i,n):a_.call(this,t,e,s,i,n)}}const o_=(o,t,e)=>e.lockRotation?Dc:t.cursorStyle,h_=Ya(jp,Ua((o,t,e,s)=>{let{target:i,ex:n,ey:r,theta:a,originX:h,originY:l}=t;const u=i.translateToOriginPoint(i.getRelativeCenterPoint(),h,l);if(Ns(i,"lockRotation"))return!1;const d=Math.atan2(r-u.y,n-u.x),g=Math.atan2(s-u.y,e-u.x);let f=kn(g-d+a);if(i.snapAngle&&i.snapAngle>0){const m=i.snapAngle,_=i.snapThreshold||m,b=Math.ceil(f/m)*m,x=Math.floor(f/m)*m;Math.abs(f-x)<_?f=x:Math.abs(f-b)<_&&(f=b)}f<0&&(f=360+f),f%=360;const p=i.angle!==f;return i.angle=f,p}));function km(o,t){const e=t.canvas,s=o[e.uniScaleKey];return e.uniformScaling&&!s||!e.uniformScaling&&s}function Mm(o,t,e){const s=Ns(o,"lockScalingX"),i=Ns(o,"lockScalingY");if(s&&i||!t&&(s||i)&&e||s&&t==="x"||i&&t==="y")return!0;const{width:n,height:r,strokeWidth:a}=o;return n===0&&a===0&&t!=="y"||r===0&&a===0&&t!=="x"}const l_=["e","se","s","sw","w","nw","n","ne","e"],xh=(o,t,e)=>{const s=km(o,e);if(Mm(e,t.x!==0&&t.y===0?"x":t.x===0&&t.y!==0?"y":"",s))return Dc;const i=gm(e,t);return"".concat(l_[i],"-resize")};function gg(o,t,e,s){let i=arguments.length>4&&arguments[4]!==void 0?arguments[4]:{};const n=t.target,r=i.by,a=km(o,n);let h,l,u,d,g,f;if(Mm(n,r,a))return!1;if(t.gestureScale)l=t.scaleX*t.gestureScale,u=t.scaleY*t.gestureScale;else{if(h=eg(t,t.originX,t.originY,e,s),g=r!=="y"?Math.sign(h.x||t.signX||1):1,f=r!=="x"?Math.sign(h.y||t.signY||1):1,t.signX||(t.signX=g),t.signY||(t.signY=f),Ns(n,"lockScalingFlip")&&(t.signX!==g||t.signY!==f))return!1;if(d=n._getTransformedDimensions(),a&&!r){const _=Math.abs(h.x)+Math.abs(h.y),{original:b}=t,x=_/(Math.abs(d.x*b.scaleX/n.scaleX)+Math.abs(d.y*b.scaleY/n.scaleY));l=b.scaleX*x,u=b.scaleY*x}else l=Math.abs(h.x*n.scaleX/d.x),u=Math.abs(h.y*n.scaleY/d.y);cm(t)&&(l*=2,u*=2),t.signX!==g&&r!=="y"&&(t.originX=um(t.originX),l*=-1,t.signX=g),t.signY!==f&&r!=="x"&&(t.originY=um(t.originY),u*=-1,t.signY=f)}const p=n.scaleX,m=n.scaleY;return r?(r==="x"&&n.set(Fe,l),r==="y"&&n.set(is,u)):(!Ns(n,"lockScalingX")&&n.set(Fe,l),!Ns(n,"lockScalingY")&&n.set(is,u)),p!==n.scaleX||m!==n.scaleY}const Nc=Ya(wc,Ua((o,t,e,s)=>gg(o,t,e,s))),c_=Ya(wc,Ua((o,t,e,s)=>gg(o,t,e,s,{by:"x"}))),u_=Ya(wc,Ua((o,t,e,s)=>gg(o,t,e,s,{by:"y"}))),d_=["target","ex","ey","skewingSide"],fg={x:{counterAxis:"y",scale:Fe,skew:Na,lockSkewing:"lockSkewingX",origin:"originX",flip:"flipX"},y:{counterAxis:"x",scale:is,skew:Ba,lockSkewing:"lockSkewingY",origin:"originY",flip:"flipY"}},g_=["ns","nesw","ew","nwse"],f_=(o,t,e)=>{if(t.x!==0&&Ns(e,"lockSkewingY")||t.y!==0&&Ns(e,"lockSkewingX"))return Dc;const s=gm(e,t)%4;return"".concat(g_[s],"-resize")};function Om(o,t,e,s,i){const{target:n}=e,{counterAxis:r,origin:a,lockSkewing:h,skew:l,flip:u}=fg[o];if(Ns(n,h))return!1;const{origin:d,flip:g}=fg[r],f=Kt(e[d])*(n[g]?-1:1),p=-Math.sign(f)*(n[u]?-1:1),m=.5*-((n[l]===0&&eg(e,st,st,s,i)[o]>0||n[l]>0?1:-1)*p)+.5;return Ya(Np,Ua((b,x,S,A)=>function(k,P,M){let{target:O,ex:R,ey:I,skewingSide:j}=P,G=Pt(P,d_);const{skew:L}=fg[k],H=M.subtract(new D(R,I)).divide(new D(O.scaleX,O.scaleY))[k],$=O[L],J=G[L],Y=Math.tan(Wt(J)),X=k==="y"?O._getTransformedDimensions({scaleX:1,scaleY:1,skewX:0}).x:O._getTransformedDimensions({scaleX:1,scaleY:1}).y,Ot=2*H*j/Math.max(X,1)+Y,zt=kn(Math.atan(Ot));O.set(L,zt);const te=$!==O[L];if(te&&k==="y"){const{skewX:Ht,scaleX:At}=O,_e=O._getTransformedDimensions({skewY:$}),Ps=O._getTransformedDimensions(),kt=Ht!==0?_e.x/Ps.x:1;kt!==1&&O.set(Fe,kt*At)}return te}(o,x,new D(S,A))))(t,E(E({},e),{},{[a]:m,skewingSide:p}),s,i)}const p_=(o,t,e,s)=>Om("x",o,t,e,s),m_=(o,t,e,s)=>Om("y",o,t,e,s);function Bc(o,t){return o[t.canvas.altActionKey]}const Hc=(o,t,e)=>{const s=Bc(o,e);return t.x===0?s?Na:is:t.y===0?s?Ba:Fe:""},qa=(o,t,e)=>Bc(o,e)?f_(0,t,e):xh(o,t,e),Pm=(o,t,e,s)=>Bc(o,t.target)?m_(o,t,e,s):c_(o,t,e,s),Dm=(o,t,e,s)=>Bc(o,t.target)?p_(o,t,e,s):u_(o,t,e,s),Rm=()=>({ml:new Hs({x:-.5,y:0,cursorStyleHandler:qa,actionHandler:Pm,getActionName:Hc}),mr:new Hs({x:.5,y:0,cursorStyleHandler:qa,actionHandler:Pm,getActionName:Hc}),mb:new Hs({x:0,y:.5,cursorStyleHandler:qa,actionHandler:Dm,getActionName:Hc}),mt:new Hs({x:0,y:-.5,cursorStyleHandler:qa,actionHandler:Dm,getActionName:Hc}),tl:new Hs({x:-.5,y:-.5,cursorStyleHandler:xh,actionHandler:Nc}),tr:new Hs({x:.5,y:-.5,cursorStyleHandler:xh,actionHandler:Nc}),bl:new Hs({x:-.5,y:.5,cursorStyleHandler:xh,actionHandler:Nc}),br:new Hs({x:.5,y:.5,cursorStyleHandler:xh,actionHandler:Nc}),mtr:new Hs({x:0,y:-.5,actionHandler:h_,cursorStyleHandler:o_,offsetY:-40,withConnection:!0,actionName:Xd})}),v_=()=>({mr:new Hs({x:.5,y:0,actionHandler:Em,cursorStyleHandler:qa,actionName:gh}),ml:new Hs({x:-.5,y:0,actionHandler:Em,cursorStyleHandler:qa,actionName:gh})}),b_=()=>E(E({},Rm()),v_());class Sh extends Li{static getDefaults(){return E(E({},super.getDefaults()),Sh.ownDefaults)}constructor(t){super(),Object.assign(this,this.constructor.createControls(),Sh.ownDefaults),this.setOptions(t)}static createControls(){return{controls:Rm()}}_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(Sc))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],a=this.controls[n];if(a.shouldActivate(n,this,t,e?r.touchCorner:r.corner))return this.__corner=n,{key:n,control:a,coord:this.oCoords[n]}}}calcOCoords(){const t=this.getViewportTransform(),e=this.getCenterPoint(),s=Wa(e.x,e.y),i=Xa({angle:this.getTotalAngle()-(this.group&&this.flipX?180:0)}),n=Gt(s,i),r=Gt(t,n),a=Gt(r,[1/t[0],0,0,1/t[3],0,0]),h=this.group?pr(this.calcTransformMatrix()):void 0;h&&(h.scaleX=Math.abs(h.scaleX),h.scaleY=Math.abs(h.scaleY));const l=this._calculateCurrentDimensions(h),u={};return this.forEachControl((d,g)=>{const f=d.positionHandler(l,a,this,d);u[g]=Object.assign(f,this._calcCornerCoords(d,f))}),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(Wt(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=E({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=E({hasBorders:s,hasControls:i},e),r=this.getViewportTransform(),a=n.hasBorders,h=n.hasControls,l=Gt(r,this.calcTransformMatrix()),u=pr(l);t.save(),t.translate(u.translateX,u.translateY),t.lineWidth=1*this.borderScaleFactor,this.group===this.parent&&(t.globalAlpha=this.isMoving?this.borderOpacityWhenMoving:1),this.flipX&&(u.angle-=180),t.rotate(Wt(this.group?u.angle:this.angle)),a&&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=Pc(this.width,this.height,ph(e)),r=this.isStrokeAccountedForInDimensions()?Vd:(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,a=E({cornerStrokeColor:i,cornerDashArray:n,cornerColor:r},e);t.setTransform(s,0,0,s,0,0),t.strokeStyle=t.fillStyle=a.cornerColor,this.transparentCorners||(t.strokeStyle=a.cornerStrokeColor),this._setLineDash(t,a.cornerDashArray),this.forEachControl((h,l)=>{if(h.getVisibility(this,l)){const u=this.oCoords[l];h.render(t,u.x,u.y,a,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 Fm(o,t){return t.forEach(e=>{Object.getOwnPropertyNames(e.prototype).forEach(s=>{s!=="constructor"&&Object.defineProperty(o.prototype,s,Object.getOwnPropertyDescriptor(e.prototype,s)||Object.create(null))})}),o}T(Sh,"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 xe extends Sh{}Fm(xe,[fm]),V.setClass(xe),V.setClass(xe,"object");const Lm=(o,t,e,s)=>{const i=2*(s=Math.round(s))+1,{data:n}=o.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 Im{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=Fc(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(Wt(this.options.skewY)),e.x+=e.y*Math.tan(Wt(this.options.skewX)),e}scaleUnitVector(t,e){return t.multiply(this.strokeUniformScalar).scalarMultiply(e)}}const y_=new D;class $a extends Im{static getOrthogonalRotationFactor(t,e){const s=e?Ic(t,e):ym(t);return Math.abs(s)<An?-1:1}constructor(t,e,s,i){super(i),T(this,"AB",void 0),T(this,"AC",void 0),T(this,"alpha",void 0),T(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=Ic(this.AB,this.AC),this.bisector=jc(rg(this.AB.eq(y_)?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=ag(i),r=$a.getOrthogonalRotationFactor(n,this.bisector);return this.scaleUnitVector(n,s*r)}projectBevel(){const t=[];return(this.alpha%Di==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?Lc(this.scaleUnitVector(this.bisector,this.options.strokeMiterLimit)):this.options.strokeMiterLimit;return Lc(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($a.getOrthogonalRotationFactor(this.bisector),$a.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=>{og(n,t,e)&&s.push(this.A.add(n))}),s}projectRoundWithSkew(t,e){const s=[],{skewX:i,skewY:n,scaleX:r,scaleY:a,strokeUniform:h}=this.options,l=new D(Math.tan(Wt(i)),Math.tan(Wt(n))),u=this.strokeProjectionMagnitude,d=h?u/a/Math.sqrt(1/a**2+1/r**2*l.y**2):u/Math.sqrt(1+l.y**2),g=new D(Math.sqrt(Math.max(u**2-d**2,0)),d),f=h?u/Math.sqrt(1+l.x**2*(1/a)**2/(1/r+1/r*l.x*l.y)**2):u/Math.sqrt(1+l.x**2/(1+l.x*l.y)**2),p=new D(f,Math.sqrt(Math.max(u**2-f**2,0)));return[p,p.scalarMultiply(-1),g,g.scalarMultiply(-1)].map(m=>this.applySkew(h?m.multiply(this.strokeUniformScalar):m)).forEach(m=>{og(m,t,e)&&s.push(this.applySkew(this.A).add(m))}),s}projectRound(){const t=[];t.push(...this.projectBevel());const e=this.alpha%Di==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)),a=Ga(i,r)>0,h=a?i:n,l=a?n:i;return this.isSkewed()?t.push(...this.projectRoundWithSkew(h,l)):t.push(...this.projectRoundNoSkew(h,l)),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 jm extends Im{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(ag(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 $a(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(jc(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 Nm=function(o,t){let e=arguments.length>2&&arguments[2]!==void 0&&arguments[2];const s=[];if(o.length===0)return s;const i=o.reduce((n,r)=>(n[n.length-1].eq(r)||n.push(new D(r)),n),[new D(o[0])]);if(i.length===1)e=!0;else if(!e){const n=i[0],r=((a,h)=>{for(let l=a.length-1;l>=0;l--)if(h(a[l],l,a))return l;return-1})(i,a=>!a.eq(n));i.splice(r+1)}return i.forEach((n,r,a)=>{let h,l;r===0?(l=a[1],h=e?n:a[a.length-1]):r===a.length-1?(h=a[r-1],l=e?n:a[0]):(h=a[r-1],l=a[r+1]),e&&a.length===1?s.push(...new jm(n,n,t).project()):!e||r!==0&&r!==a.length-1?s.push(...new $a(n,h,l,t).project()):s.push(...new jm(n,r===0?l:h,t).project())}),s},pg=o=>{const t={};return Object.keys(o).forEach(e=>{t[e]={},Object.keys(o[e]).forEach(s=>{t[e][s]=E({},o[e][s])})}),t},Bm=o=>o.replace(/&/g,"&").replace(/"/g,""").replace(/'/g,"'").replace(/</g,"<").replace(/>/g,">"),Wc=o=>{const t=[];for(let e,s=0;s<o.length;s++)(e=__(o,s))!==!1&&t.push(e);return t},__=(o,t)=>{const e=o.charCodeAt(t);if(isNaN(e))return"";if(e<55296||e>57343)return o.charAt(t);if(55296<=e&&e<=56319){if(o.length<=t+1)throw"High surrogate without following low surrogate";const i=o.charCodeAt(t+1);if(56320>i||i>57343)throw"High surrogate without following low surrogate";return o.charAt(t)+o.charAt(t+1)}if(t===0)throw"Low surrogate without preceding high surrogate";const s=o.charCodeAt(t-1);if(55296>s||s>56319)throw"Low surrogate without preceding high surrogate";return!1};var w_=Object.freeze({__proto__:null,capitalize:function(o){let t=arguments.length>1&&arguments[1]!==void 0&&arguments[1];return"".concat(o.charAt(0).toUpperCase()).concat(t?o.slice(1):o.slice(1).toLowerCase())},escapeXml:Bm,graphemeSplit:Wc});const Xc=function(o,t){let e=arguments.length>2&&arguments[2]!==void 0&&arguments[2];return o.fill!==t.fill||o.stroke!==t.stroke||o.strokeWidth!==t.strokeWidth||o.fontSize!==t.fontSize||o.fontFamily!==t.fontFamily||o.fontWeight!==t.fontWeight||o.fontStyle!==t.fontStyle||o.textBackgroundColor!==t.textBackgroundColor||o.deltaY!==t.deltaY||e&&(o.overline!==t.overline||o.underline!==t.underline||o.linethrough!==t.linethrough)},Hm=(o,t)=>{const e=t.split(`
|
|
66
|
+
`)}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=Ri.ownDefaults;return this.includeDefaultValues?t:qd(t,(s,i)=>s!==e[i])}static async fromObject(t){return new this(t)}}T(Ri,"ownDefaults",{color:"rgb(0,0,0)",blur:0,offsetX:0,offsetY:0,affectStroke:!1,includeDefaultValues:!0,nonScaling:!1}),T(Ri,"type","shadow"),V.setClass(Ri,"shadow");const yr=(o,t,e)=>Math.max(o,Math.min(t,e)),Gy=[Ue,mt,Fe,is,"flipX","flipY","originX","originY","angle","opacity","globalCompositeOperation","shadow","visible",Na,Ba],Fi=[$t,Le,"strokeWidth","strokeDashArray","width","height","paintFirst","strokeUniform","strokeLineCap","strokeDashOffset","strokeLineJoin","strokeMiterLimit","backgroundColor","clipPath"],Yy={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:mt,originY:Ue,strokeWidth:1,strokeUniform:!1,padding:0,opacity:1,paintFirst:$t,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},hg=(o,t,e,s)=>(o<Math.abs(t)?(o=t,s=e/4):s=t===0&&o===0?e/Di*Math.asin(1):e/Di*Math.asin(t/o),{a:o,c:t,p:e,s}),Sm=(o,t,e,s,i)=>o*Math.pow(2,10*(s-=1))*Math.sin((s*i-t)*Di/e),Cm=(o,t,e,s)=>-e*Math.cos(o/s*An)+e+t,lg=(o,t,e,s)=>(o/=s)<1/2.75?e*(7.5625*o*o)+t:o<2/2.75?e*(7.5625*(o-=1.5/2.75)*o+.75)+t:o<2.5/2.75?e*(7.5625*(o-=2.25/2.75)*o+.9375)+t:e*(7.5625*(o-=2.625/2.75)*o+.984375)+t,Am=(o,t,e,s)=>e-lg(s-o,0,e,s)+t;var Uy=Object.freeze({__proto__:null,defaultEasing:Cm,easeInBack:function(o,t,e,s){let i=arguments.length>4&&arguments[4]!==void 0?arguments[4]:1.70158;return e*(o/=s)*o*((i+1)*o-i)+t},easeInBounce:Am,easeInCirc:(o,t,e,s)=>-e*(Math.sqrt(1-(o/=s)*o)-1)+t,easeInCubic:(o,t,e,s)=>e*(o/s)**3+t,easeInElastic:(o,t,e,s)=>{const i=e;let n=0;if(o===0)return t;if((o/=s)===1)return t+e;n||(n=.3*s);const{a:r,s:a,p:h}=hg(i,e,n,1.70158);return-Sm(r,a,h,o,s)+t},easeInExpo:(o,t,e,s)=>o===0?t:e*2**(10*(o/s-1))+t,easeInOutBack:function(o,t,e,s){let i=arguments.length>4&&arguments[4]!==void 0?arguments[4]:1.70158;return(o/=s/2)<1?e/2*(o*o*((1+(i*=1.525))*o-i))+t:e/2*((o-=2)*o*((1+(i*=1.525))*o+i)+2)+t},easeInOutBounce:(o,t,e,s)=>o<s/2?.5*Am(2*o,0,e,s)+t:.5*lg(2*o-s,0,e,s)+.5*e+t,easeInOutCirc:(o,t,e,s)=>(o/=s/2)<1?-e/2*(Math.sqrt(1-o**2)-1)+t:e/2*(Math.sqrt(1-(o-=2)*o)+1)+t,easeInOutCubic:(o,t,e,s)=>(o/=s/2)<1?e/2*o**3+t:e/2*((o-2)**3+2)+t,easeInOutElastic:(o,t,e,s)=>{const i=e;let n=0;if(o===0)return t;if((o/=s/2)===2)return t+e;n||(n=s*(.3*1.5));const{a:r,s:a,p:h,c:l}=hg(i,e,n,1.70158);return o<1?-.5*Sm(r,a,h,o,s)+t:r*Math.pow(2,-10*(o-=1))*Math.sin((o*s-a)*Di/h)*.5+l+t},easeInOutExpo:(o,t,e,s)=>o===0?t:o===s?t+e:(o/=s/2)<1?e/2*2**(10*(o-1))+t:e/2*-(2**(-10*--o)+2)+t,easeInOutQuad:(o,t,e,s)=>(o/=s/2)<1?e/2*o**2+t:-e/2*(--o*(o-2)-1)+t,easeInOutQuart:(o,t,e,s)=>(o/=s/2)<1?e/2*o**4+t:-e/2*((o-=2)*o**3-2)+t,easeInOutQuint:(o,t,e,s)=>(o/=s/2)<1?e/2*o**5+t:e/2*((o-2)**5+2)+t,easeInOutSine:(o,t,e,s)=>-e/2*(Math.cos(Math.PI*o/s)-1)+t,easeInQuad:(o,t,e,s)=>e*(o/=s)*o+t,easeInQuart:(o,t,e,s)=>e*(o/=s)*o**3+t,easeInQuint:(o,t,e,s)=>e*(o/s)**5+t,easeInSine:(o,t,e,s)=>-e*Math.cos(o/s*An)+e+t,easeOutBack:function(o,t,e,s){let i=arguments.length>4&&arguments[4]!==void 0?arguments[4]:1.70158;return e*((o=o/s-1)*o*((i+1)*o+i)+1)+t},easeOutBounce:lg,easeOutCirc:(o,t,e,s)=>e*Math.sqrt(1-(o=o/s-1)*o)+t,easeOutCubic:(o,t,e,s)=>e*((o/s-1)**3+1)+t,easeOutElastic:(o,t,e,s)=>{const i=e;let n=0;if(o===0)return t;if((o/=s)===1)return t+e;n||(n=.3*s);const{a:r,s:a,p:h,c:l}=hg(i,e,n,1.70158);return r*2**(-10*o)*Math.sin((o*s-a)*Di/h)+l+t},easeOutExpo:(o,t,e,s)=>o===s?t+e:e*-(2**(-10*o/s)+1)+t,easeOutQuad:(o,t,e,s)=>-e*(o/=s)*(o-2)+t,easeOutQuart:(o,t,e,s)=>-e*((o=o/s-1)*o**3-1)+t,easeOutQuint:(o,t,e,s)=>e*((o/s-1)**5+1)+t,easeOutSine:(o,t,e,s)=>e*Math.sin(o/s*An)+t});const qy=()=>!1;class cg{constructor(t){let{startValue:e,byValue:s,duration:i=500,delay:n=0,easing:r=Cm,onStart:a=gr,onChange:h=gr,onComplete:l=gr,abort:u=qy,target:d}=t;T(this,"_state","pending"),T(this,"durationProgress",0),T(this,"valueProgress",0),this.tick=this.tick.bind(this),this.duration=i,this.delay=n,this.easing=r,this._onStart=a,this._onChange=h,this._onComplete=l,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(()=>fh(t),this.delay):fh(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),fh(this.tick)))}register(){Ac.push(this)}unregister(){Ac.remove(this)}abort(){this._state="aborted",this.unregister()}}const $y=["startValue","endValue"];class Ky extends cg{constructor(t){let{startValue:e=0,endValue:s=100}=t;super(E(E({},Pt(t,$y)),{},{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 Jy=["startValue","endValue"];class Qy extends cg{constructor(t){let{startValue:e=[0],endValue:s=[100]}=t;super(E(E({},Pt(t,Jy)),{},{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 Zy=["startValue","endValue","easing","onChange","onComplete","abort"],t_=(o,t,e,s)=>t+e*(1-Math.cos(o/s*An)),ug=o=>o&&((t,e,s)=>o(new yt(t).toRgba(),e,s));class e_ extends cg{constructor(t){let{startValue:e,endValue:s,easing:i=t_,onChange:n,onComplete:r,abort:a}=t,h=Pt(t,Zy);const l=new yt(e).getSource(),u=new yt(s).getSource();super(E(E({},h),{},{startValue:l,byValue:u.map((d,g)=>d-l[g]),easing:i,onChange:ug(n),onComplete:ug(r),abort:ug(a)}))}calculate(t){const[e,s,i,n]=this.startValue.map((a,h)=>this.easing(t,a,this.byValue[h],this.duration,h)),r=[...[e,s,i].map(Math.round),yr(0,n,1)];return{value:r,valueProgress:r.map((a,h)=>this.byValue[h]!==0?Math.abs((a-this.startValue[h])/this.byValue[h]):0).find(a=>a!==0)||0}}}function dg(o){const t=(e=>Array.isArray(e.startValue)||Array.isArray(e.endValue))(o)?new Qy(o):new Ky(o);return t.start(),t}function Tm(o){const t=new e_(o);return t.start(),t}class Lt{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=Fc(e,s),r=Fc(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 a=e.x-t.x,h=e.y-t.y,l=i.x-s.x,u=i.y-s.y,d=t.x-s.x,g=t.y-s.y,f=l*g-u*d,p=a*g-h*d,m=u*a-l*h;if(m!==0){const _=f/m,b=p/m;return(n||0<=_&&_<=1)&&(r||0<=b&&b<=1)?new Lt("Intersection").append(new D(t.x+_*a,t.y+_*h)):new Lt}if(f===0||p===0){const _=n||r||Lt.isPointContained(t,s,i)||Lt.isPointContained(e,s,i)||Lt.isPointContained(s,t,e)||Lt.isPointContained(i,t,e);return new Lt(_?"Coincident":void 0)}return new Lt("Parallel")}static intersectSegmentLine(t,e,s,i){return Lt.intersectLineLine(t,e,s,i,!1,!0)}static intersectSegmentSegment(t,e,s,i){return Lt.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 Lt,r=s.length;for(let a,h,l,u=0;u<r;u++){if(a=s[u],h=s[(u+1)%r],l=Lt.intersectLineLine(t,e,a,h,i,!1),l.status==="Coincident")return l;n.append(...l.points)}return n.points.length>0&&(n.status="Intersection"),n}static intersectSegmentPolygon(t,e,s){return Lt.intersectLinePolygon(t,e,s,!1)}static intersectPolygonPolygon(t,e){const s=new Lt,i=t.length,n=[];for(let r=0;r<i;r++){const a=t[r],h=t[(r+1)%i],l=Lt.intersectSegmentPolygon(a,h,e);l.status==="Coincident"?(n.push(l),s.append(a,h)):s.append(...l.points)}return n.length>0&&n.length===t.length?new Lt("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),a=new D(i.x,n.y);return Lt.intersectPolygonPolygon(t,[i,r,n,a])}}class s_ extends Hp{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?we(t,this.group.calcTransformMatrix()):t}setXY(t,e,s){this.group&&(t=we(t,qe(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(a=>we(a,r))}return n}intersectsWithRect(t,e){return Lt.intersectPolygonRectangle(this.getCoords(),t,e).status==="Intersection"}intersectsWithObject(t){const e=Lt.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 Lt.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 hi(this.getCoords())}getScaledWidth(){return this._getTransformedDimensions().x}getScaledHeight(){return this._getTransformedDimensions().y}scale(t){this._set(Fe,t),this._set(is,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(Vp(this.calcTransformMatrix())):this.angle}getViewportTransform(){var t;return((t=this.canvas)===null||t===void 0?void 0:t.viewportTransform)||De.concat()}calcACoords(){const t=Xa({angle:this.angle}),{x:e,y:s}=this.getRelativeCenterPoint(),i=Wa(e,s),n=Gt(i,t),r=this._getTransformedDimensions(),a=r.x/2,h=r.y/2;return{tl:we({x:-a,y:-h},n),tr:we({x:a,y:-h},n),bl:we({x:-a,y:h},n),br:we({x:a,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,Kt(this.originX),Kt(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=Gt(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=Yp(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=E({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,a=e.height+i;let h;return h=e.skewX===0&&e.skewY===0?new D(r*e.scaleX,a*e.scaleY):Pc(r,a,ph(e)),h.scalarAdd(n)}translateToGivenOrigin(t,e,s,i,n){let r=t.x,a=t.y;const h=Kt(i)-Kt(e),l=Kt(n)-Kt(s);if(h||l){const u=this._getTransformedDimensions();r+=h*u.x,a+=l*u.y}return new D(r,a)}translateToCenterPoint(t,e,s){if(e===st&&s===st)return t;const i=this.translateToGivenOrigin(t,e,s,st,st);return this.angle?i.rotate(Wt(this.angle),t):i}translateToOriginPoint(t,e,s){const i=this.translateToGivenOrigin(t,st,st,e,s);return this.angle?i.rotate(Wt(this.angle),t):i}getCenterPoint(){const t=this.getRelativeCenterPoint();return this.group?we(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(),mt,Ue)}}const i_=["type"],n_=["extraParam"];let Li=class ad extends s_{static getDefaults(){return ad.ownDefaults}get type(){const t=this.constructor.type;return t==="FabricObject"?"object":t.toLowerCase()}set type(t){Pi("warn","Setting type has no effect",t)}constructor(t){super(),T(this,"_cacheContext",null),Object.assign(this,ad.ownDefaults),this.setOptions(t)}_createCacheCanvas(){this._cacheCanvas=vs(),this._cacheContext=this._cacheCanvas.getContext("2d"),this._updateCacheCanvas(),this.dirty=!0}_limitCacheSize(t){const e=t.width,s=t.height,i=dt.maxCacheSideLimit,n=dt.minCacheSideLimit;if(e<=i&&s<=i&&e*s<=dt.perfLimitSizeTotal)return e<n&&(t.width=n),s<n&&(t.height=n),t;const r=e/s,[a,h]=dh.limitDimsByArea(r),l=yr(n,a,i),u=yr(n,h,i);return e>l&&(t.zoomX/=e/l,t.width=l,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:s+2,height:i+2,zoomX:t.x,zoomY:t.y,x:s,y:i}}_updateCacheCanvas(){const t=this._cacheCanvas,e=this._cacheContext,s=this._limitCacheSize(this._getCacheCanvasDimensions()),i=dt.minCacheSideLimit,n=s.width,r=s.height,a=s.zoomX,h=s.zoomY,l=n!==t.width||r!==t.height,u=this.zoomX!==a||this.zoomY!==h;if(!t||!e)return!1;let d,g,f=l||u,p=0,m=0,_=!1;if(l){const b=this._cacheCanvas.width,x=this._cacheCanvas.height,S=n>b||r>x;_=S||(n<.9*b||r<.9*x)&&b>i&&x>i,S&&!s.capped&&(n>i||r>i)&&(p=.1*n,m=.1*r)}return Zp(this)&&this.path&&(f=!0,_=!0,p+=this.getHeightOfLine(0)*this.zoomX,m+=this.getHeightOfLine(0)*this.zoomY),!!f&&(_?(t.width=Math.ceil(n+p),t.height=Math.ceil(r+m)):(e.setTransform(1,0,0,1,0,0),e.clearRect(0,0,t.width,t.height)),d=s.x/2,g=s.y/2,this.cacheTranslationX=Math.round(t.width/2-d)+d,this.cacheTranslationY=Math.round(t.height/2-g)+g,e.translate(this.cacheTranslationX,this.cacheTranslationY),e.scale(a,h),this.zoomX=a,this.zoomY=h,!0)}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=pr(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!==Fe&&t!==is||(e=this._constrainScale(e)),t===Fe&&e<0?(this.flipX=!this.flipX,e*=-1):t==="scaleY"&&e<0?(this.flipY=!this.flipY,e*=-1):t!=="shadow"||!e||e instanceof Ri||(e=new Ri(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:a}=this._cacheCanvas;this.drawObject(this._cacheContext,t.forClipping,{zoomX:e,zoomY:s,cacheTranslationX:i,cacheTranslationY:n,width:r,height:a,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===Le&&this.hasFill()&&this.hasStroke()&&this.shadow)||!!this.clipPath}shouldCache(){return this.ownCaching=this.needsItsOwnCache()||this.objectCaching&&(!this.parent||!this.parent.isOnACache()),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=Is(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=qe(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&&(1&e.length&&e.push(...e),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)||De,a=n*i,h=r*i,l=e.nonScaling?new D(1,1):this.getObjectScaling();t.shadowColor=e.color,t.shadowBlur=e.blur*dt.browserShadowBlurConstant*(a+h)*(l.x+l.y)/4,t.shadowOffsetX=e.offsetX*a*l.x,t.shadowOffsetY=e.offsetY*h*l.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===Le?(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,a=i.y/this.scaleY/n,h=Is({width:Math.ceil(r),height:Math.ceil(a)}),l=h.getContext("2d");l&&(l.beginPath(),l.moveTo(0,0),l.lineTo(r,0),l.lineTo(r,a),l.lineTo(0,a),l.closePath(),l.translate(r/2,a/2),l.scale(i.zoomX/this.scaleX/n,i.zoomY/this.scaleY/n),this._applyPatternGradientTransform(l,e),l.fillStyle=e.toLive(t),l.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=l.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(V.getClass("image"))(e)}toCanvasElement(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};const e=Zd(this),s=this.group,i=this.shadow,n=Math.abs,r=t.enableRetinaScaling?Lp():1,a=(t.multiplier||1)*r,h=t.canvasProvider||(x=>new _h(x,{enableRetinaScaling:!1,renderOnAddRemove:!1,skipOffscreen:!1}));delete this.group,t.withoutTransform&&om(this),t.withoutShadow&&(this.shadow=null),t.viewportTransform&&tg(this,this.getViewportTransform()),this.setCoords();const l=vs(),u=this.getBoundingRect(),d=this.shadow,g=new D;if(d){const x=d.blur,S=d.nonScaling?new D(1,1):this.getObjectScaling();g.x=2*Math.round(n(d.offsetX)+x)*n(S.x),g.y=2*Math.round(n(d.offsetY)+x)*n(S.y)}const f=u.width+g.x,p=u.height+g.y;l.width=Math.ceil(f),l.height=Math.ceil(p);const m=h(l);t.format==="jpeg"&&(m.backgroundColor="#fff"),this.setPositionByOrigin(new D(m.width/2,m.height/2),st,st);const _=this.canvas;m._objects=[this],this.set("canvas",m),this.setCoords();const b=m.toCanvasElement(a||1,t);return this.set("canvas",_),this.shadow=i,s&&(this.group=s),this.set(e),this.setCoords(),m._objects=[],m.destroy(),b}toDataURL(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};return Gd(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=st,this.originY=st,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(){Ac.cancelByTarget(this),this.off(),this._set("canvas",void 0),this._cacheCanvas&&oi().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:a,onChange:h,onComplete:l}=s,u=E(E({},s),{},{target:this,startValue:a??i.reduce((d,g)=>d[g],this),endValue:e,abort:r==null?void 0:r.bind(this),onChange:(d,g,f)=>{i.reduce((p,m,_)=>(_===i.length-1&&(p[m]=d),p[m]),this),h&&h(d,g,f)},onComplete:(d,g,f)=>{this.setCoords(),l&&l(d,g,f)}});return n?Tm(u):dg(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),a=s._objects.indexOf(n);return r>-1&&r>a}toObject(){const t=(arguments.length>0&&arguments[0]!==void 0?arguments[0]:[]).concat(ad.customProperties,this.constructor.customProperties||[]);let e;const s=dt.NUM_FRACTION_DIGITS,{clipPath:i,fill:n,stroke:r,shadow:a,strokeDashArray:h,left:l,top:u,originX:d,originY:g,width:f,height:p,strokeWidth:m,strokeLineCap:_,strokeDashOffset:b,strokeLineJoin:x,strokeUniform:S,strokeMiterLimit:A,scaleX:k,scaleY:P,angle:M,flipX:O,flipY:R,opacity:I,visible:j,backgroundColor:G,fillRule:L,paintFirst:H,globalCompositeOperation:$,skewX:J,skewY:Y}=this;i&&!i.excludeFromExport&&(e=i.toObject(t.concat("inverted","absolutePositioned")));const X=zt=>Dt(zt,s),Ot=E(E({},mr(this,t)),{},{type:this.constructor.type,version:jd,originX:d,originY:g,left:X(l),top:X(u),width:X(f),height:X(p),fill:Jp(n)?n.toObject():n,stroke:Jp(r)?r.toObject():r,strokeWidth:X(m),strokeDashArray:h&&h.concat(),strokeLineCap:_,strokeDashOffset:b,strokeLineJoin:x,strokeUniform:S,strokeMiterLimit:X(A),scaleX:X(k),scaleY:X(P),angle:X(M),flipX:O,flipY:R,opacity:X(I),shadow:a&&a.toObject(),visible:j,backgroundColor:G,fillRule:L,paintFirst:H,globalCompositeOperation:$,skewX:X(J),skewY:X(Y)},e?{clipPath:e}:null);return this.includeDefaultValues?Ot:this._removeDefaultValues(Ot)}toDatalessObject(t){return this.toObject(t)}_removeDefaultValues(t){const e=this.constructor.getDefaults(),s=Object.keys(e).length>0?e:Object.getPrototypeOf(this);return qd(t,(i,n)=>{if(n===mt||n===Ue||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=Pt(t,i_),s=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},{extraParam:i}=s,n=Pt(s,n_);return vh(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)}};T(Li,"stateProperties",Gy),T(Li,"cacheProperties",Fi),T(Li,"ownDefaults",Yy),T(Li,"type","FabricObject"),T(Li,"colorProperties",[$t,Le,"backgroundColor"]),T(Li,"customProperties",[]),V.setClass(Li),V.setClass(Li,"object");const Ya=(o,t,e)=>(s,i,n,r)=>{const a=t(s,i,n,r);return a&&lm(o,E(E({},dm(s,i,n,r)),e)),a};function Ua(o){return(t,e,s,i)=>{const{target:n,originX:r,originY:a}=e,h=n.getRelativeCenterPoint(),l=n.translateToOriginPoint(h,r,a),u=o(t,e,s,i);return n.setPositionByOrigin(l,e.originX,e.originY),u}}const Em=Ya(gh,Ua((o,t,e,s)=>{const i=eg(t,t.originX,t.originY,e,s);if(Kt(t.originX)===Kt(st)||Kt(t.originX)===Kt(Vt)&&i.x<0||Kt(t.originX)===Kt(mt)&&i.x>0){const{target:n}=t,r=n.strokeWidth/(n.strokeUniform?n.scaleX:1),a=cm(t)?2:1,h=n.width,l=Math.abs(i.x*a/n.scaleX)-r;return n.set("width",Math.max(l,1)),h!==n.width}return!1}));function r_(o,t,e,s,i){s=s||{};const n=this.sizeX||s.cornerSize||i.cornerSize,r=this.sizeY||s.cornerSize||i.cornerSize,a=s.transparentCorners!==void 0?s.transparentCorners:i.transparentCorners,h=a?Le:$t,l=!a&&(s.cornerStrokeColor||i.cornerStrokeColor);let u,d=t,g=e;o.save(),o.fillStyle=s.cornerColor||i.cornerColor||"",o.strokeStyle=s.cornerStrokeColor||i.cornerStrokeColor||"",n>r?(u=n,o.scale(1,r/n),g=e*n/r):r>n?(u=r,o.scale(n/r,1),d=t*r/n):u=n,o.beginPath(),o.arc(d,g,u/2,0,Di,!1),o[h](),l&&o.stroke(),o.restore()}function a_(o,t,e,s,i){s=s||{};const n=this.sizeX||s.cornerSize||i.cornerSize,r=this.sizeY||s.cornerSize||i.cornerSize,a=s.transparentCorners!==void 0?s.transparentCorners:i.transparentCorners,h=a?Le:$t,l=!a&&(s.cornerStrokeColor||i.cornerStrokeColor),u=n/2,d=r/2;o.save(),o.fillStyle=s.cornerColor||i.cornerColor||"",o.strokeStyle=s.cornerStrokeColor||i.cornerStrokeColor||"",o.translate(t,e);const g=i.getTotalAngle();o.rotate(Wt(g)),o["".concat(h,"Rect")](-u,-d,n,r),l&&o.strokeRect(-u,-d,n,r),o.restore()}class Hs{constructor(t){T(this,"visible",!0),T(this,"actionName",Sc),T(this,"angle",0),T(this,"x",0),T(this,"y",0),T(this,"offsetX",0),T(this,"offsetY",0),T(this,"sizeX",0),T(this,"sizeY",0),T(this,"touchSizeX",0),T(this,"touchSizeY",0),T(this,"cursorStyle","crosshair"),T(this,"withConnection",!1),Object.assign(this,t)}shouldActivate(t,e,s,i){var n;let{tl:r,tr:a,br:h,bl:l}=i;return((n=e.canvas)===null||n===void 0?void 0:n.getActiveObject())===e&&e.isControlVisible(t)&&Lt.isPointInPolygon(s,[r,a,h,l])}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 a=Ec([Wa(s,i),Xa({angle:t}),kc((n?this.touchSizeX:this.sizeX)||e,(n?this.touchSizeY:this.sizeY)||e)]);return{tl:new D(-.5,-.5).transform(a),tr:new D(.5,-.5).transform(a),br:new D(.5,.5).transform(a),bl:new D(-.5,.5).transform(a)}}render(t,e,s,i,n){((i=i||{}).cornerStyle||n.cornerStyle)==="circle"?r_.call(this,t,e,s,i,n):a_.call(this,t,e,s,i,n)}}const o_=(o,t,e)=>e.lockRotation?Dc:t.cursorStyle,h_=Ya(jp,Ua((o,t,e,s)=>{let{target:i,ex:n,ey:r,theta:a,originX:h,originY:l}=t;const u=i.translateToOriginPoint(i.getRelativeCenterPoint(),h,l);if(Ns(i,"lockRotation"))return!1;const d=Math.atan2(r-u.y,n-u.x),g=Math.atan2(s-u.y,e-u.x);let f=kn(g-d+a);if(i.snapAngle&&i.snapAngle>0){const m=i.snapAngle,_=i.snapThreshold||m,b=Math.ceil(f/m)*m,x=Math.floor(f/m)*m;Math.abs(f-x)<_?f=x:Math.abs(f-b)<_&&(f=b)}f<0&&(f=360+f),f%=360;const p=i.angle!==f;return i.angle=f,p}));function km(o,t){const e=t.canvas,s=o[e.uniScaleKey];return e.uniformScaling&&!s||!e.uniformScaling&&s}function Mm(o,t,e){const s=Ns(o,"lockScalingX"),i=Ns(o,"lockScalingY");if(s&&i||!t&&(s||i)&&e||s&&t==="x"||i&&t==="y")return!0;const{width:n,height:r,strokeWidth:a}=o;return n===0&&a===0&&t!=="y"||r===0&&a===0&&t!=="x"}const l_=["e","se","s","sw","w","nw","n","ne","e"],xh=(o,t,e)=>{const s=km(o,e);if(Mm(e,t.x!==0&&t.y===0?"x":t.x===0&&t.y!==0?"y":"",s))return Dc;const i=gm(e,t);return"".concat(l_[i],"-resize")};function gg(o,t,e,s){let i=arguments.length>4&&arguments[4]!==void 0?arguments[4]:{};const n=t.target,r=i.by,a=km(o,n);let h,l,u,d,g,f;if(Mm(n,r,a))return!1;if(t.gestureScale)l=t.scaleX*t.gestureScale,u=t.scaleY*t.gestureScale;else{if(h=eg(t,t.originX,t.originY,e,s),g=r!=="y"?Math.sign(h.x||t.signX||1):1,f=r!=="x"?Math.sign(h.y||t.signY||1):1,t.signX||(t.signX=g),t.signY||(t.signY=f),Ns(n,"lockScalingFlip")&&(t.signX!==g||t.signY!==f))return!1;if(d=n._getTransformedDimensions(),a&&!r){const _=Math.abs(h.x)+Math.abs(h.y),{original:b}=t,x=_/(Math.abs(d.x*b.scaleX/n.scaleX)+Math.abs(d.y*b.scaleY/n.scaleY));l=b.scaleX*x,u=b.scaleY*x}else l=Math.abs(h.x*n.scaleX/d.x),u=Math.abs(h.y*n.scaleY/d.y);cm(t)&&(l*=2,u*=2),t.signX!==g&&r!=="y"&&(t.originX=um(t.originX),l*=-1,t.signX=g),t.signY!==f&&r!=="x"&&(t.originY=um(t.originY),u*=-1,t.signY=f)}const p=n.scaleX,m=n.scaleY;return r?(r==="x"&&n.set(Fe,l),r==="y"&&n.set(is,u)):(!Ns(n,"lockScalingX")&&n.set(Fe,l),!Ns(n,"lockScalingY")&&n.set(is,u)),p!==n.scaleX||m!==n.scaleY}const Nc=Ya(wc,Ua((o,t,e,s)=>gg(o,t,e,s))),c_=Ya(wc,Ua((o,t,e,s)=>gg(o,t,e,s,{by:"x"}))),u_=Ya(wc,Ua((o,t,e,s)=>gg(o,t,e,s,{by:"y"}))),d_=["target","ex","ey","skewingSide"],fg={x:{counterAxis:"y",scale:Fe,skew:Na,lockSkewing:"lockSkewingX",origin:"originX",flip:"flipX"},y:{counterAxis:"x",scale:is,skew:Ba,lockSkewing:"lockSkewingY",origin:"originY",flip:"flipY"}},g_=["ns","nesw","ew","nwse"],f_=(o,t,e)=>{if(t.x!==0&&Ns(e,"lockSkewingY")||t.y!==0&&Ns(e,"lockSkewingX"))return Dc;const s=gm(e,t)%4;return"".concat(g_[s],"-resize")};function Om(o,t,e,s,i){const{target:n}=e,{counterAxis:r,origin:a,lockSkewing:h,skew:l,flip:u}=fg[o];if(Ns(n,h))return!1;const{origin:d,flip:g}=fg[r],f=Kt(e[d])*(n[g]?-1:1),p=-Math.sign(f)*(n[u]?-1:1),m=.5*-((n[l]===0&&eg(e,st,st,s,i)[o]>0||n[l]>0?1:-1)*p)+.5;return Ya(Np,Ua((b,x,S,A)=>function(k,P,M){let{target:O,ex:R,ey:I,skewingSide:j}=P,G=Pt(P,d_);const{skew:L}=fg[k],H=M.subtract(new D(R,I)).divide(new D(O.scaleX,O.scaleY))[k],$=O[L],J=G[L],Y=Math.tan(Wt(J)),X=k==="y"?O._getTransformedDimensions({scaleX:1,scaleY:1,skewX:0}).x:O._getTransformedDimensions({scaleX:1,scaleY:1}).y,Ot=2*H*j/Math.max(X,1)+Y,zt=kn(Math.atan(Ot));O.set(L,zt);const te=$!==O[L];if(te&&k==="y"){const{skewX:Ht,scaleX:At}=O,_e=O._getTransformedDimensions({skewY:$}),Ps=O._getTransformedDimensions(),kt=Ht!==0?_e.x/Ps.x:1;kt!==1&&O.set(Fe,kt*At)}return te}(o,x,new D(S,A))))(t,E(E({},e),{},{[a]:m,skewingSide:p}),s,i)}const p_=(o,t,e,s)=>Om("x",o,t,e,s),m_=(o,t,e,s)=>Om("y",o,t,e,s);function Bc(o,t){return o[t.canvas.altActionKey]}const Hc=(o,t,e)=>{const s=Bc(o,e);return t.x===0?s?Na:is:t.y===0?s?Ba:Fe:""},qa=(o,t,e)=>Bc(o,e)?f_(0,t,e):xh(o,t,e),Pm=(o,t,e,s)=>Bc(o,t.target)?m_(o,t,e,s):c_(o,t,e,s),Dm=(o,t,e,s)=>Bc(o,t.target)?p_(o,t,e,s):u_(o,t,e,s),Rm=()=>({ml:new Hs({x:-.5,y:0,cursorStyleHandler:qa,actionHandler:Pm,getActionName:Hc}),mr:new Hs({x:.5,y:0,cursorStyleHandler:qa,actionHandler:Pm,getActionName:Hc}),mb:new Hs({x:0,y:.5,cursorStyleHandler:qa,actionHandler:Dm,getActionName:Hc}),mt:new Hs({x:0,y:-.5,cursorStyleHandler:qa,actionHandler:Dm,getActionName:Hc}),tl:new Hs({x:-.5,y:-.5,cursorStyleHandler:xh,actionHandler:Nc}),tr:new Hs({x:.5,y:-.5,cursorStyleHandler:xh,actionHandler:Nc}),bl:new Hs({x:-.5,y:.5,cursorStyleHandler:xh,actionHandler:Nc}),br:new Hs({x:.5,y:.5,cursorStyleHandler:xh,actionHandler:Nc}),mtr:new Hs({x:0,y:-.5,actionHandler:h_,cursorStyleHandler:o_,offsetY:-40,withConnection:!0,actionName:Xd})}),v_=()=>({mr:new Hs({x:.5,y:0,actionHandler:Em,cursorStyleHandler:qa,actionName:gh}),ml:new Hs({x:-.5,y:0,actionHandler:Em,cursorStyleHandler:qa,actionName:gh})}),b_=()=>E(E({},Rm()),v_());class Sh extends Li{static getDefaults(){return E(E({},super.getDefaults()),Sh.ownDefaults)}constructor(t){super(),Object.assign(this,this.constructor.createControls(),Sh.ownDefaults),this.setOptions(t)}static createControls(){return{controls:Rm()}}_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(Sc))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],a=this.controls[n];if(a.shouldActivate(n,this,t,e?r.touchCorner:r.corner))return this.__corner=n,{key:n,control:a,coord:this.oCoords[n]}}}calcOCoords(){const t=this.getViewportTransform(),e=this.getCenterPoint(),s=Wa(e.x,e.y),i=Xa({angle:this.getTotalAngle()-(this.group&&this.flipX?180:0)}),n=Gt(s,i),r=Gt(t,n),a=Gt(r,[1/t[0],0,0,1/t[3],0,0]),h=this.group?pr(this.calcTransformMatrix()):void 0;h&&(h.scaleX=Math.abs(h.scaleX),h.scaleY=Math.abs(h.scaleY));const l=this._calculateCurrentDimensions(h),u={};return this.forEachControl((d,g)=>{const f=d.positionHandler(l,a,this,d);u[g]=Object.assign(f,this._calcCornerCoords(d,f))}),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(Wt(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=E({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=E({hasBorders:s,hasControls:i},e),r=this.getViewportTransform(),a=n.hasBorders,h=n.hasControls,l=Gt(r,this.calcTransformMatrix()),u=pr(l);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(Wt(this.group?u.angle:this.angle)),a&&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=Pc(this.width,this.height,ph(e)),r=this.isStrokeAccountedForInDimensions()?Vd:(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,a=E({cornerStrokeColor:i,cornerDashArray:n,cornerColor:r},e);t.setTransform(s,0,0,s,0,0),t.strokeStyle=t.fillStyle=a.cornerColor,this.transparentCorners||(t.strokeStyle=a.cornerStrokeColor),this._setLineDash(t,a.cornerDashArray),this.forEachControl((h,l)=>{if(h.getVisibility(this,l)){const u=this.oCoords[l];h.render(t,u.x,u.y,a,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 Fm(o,t){return t.forEach(e=>{Object.getOwnPropertyNames(e.prototype).forEach(s=>{s!=="constructor"&&Object.defineProperty(o.prototype,s,Object.getOwnPropertyDescriptor(e.prototype,s)||Object.create(null))})}),o}T(Sh,"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 xe extends Sh{}Fm(xe,[fm]),V.setClass(xe),V.setClass(xe,"object");const Lm=(o,t,e,s)=>{const i=2*(s=Math.round(s))+1,{data:n}=o.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 Im{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=Fc(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(Wt(this.options.skewY)),e.x+=e.y*Math.tan(Wt(this.options.skewX)),e}scaleUnitVector(t,e){return t.multiply(this.strokeUniformScalar).scalarMultiply(e)}}const y_=new D;class $a extends Im{static getOrthogonalRotationFactor(t,e){const s=e?Ic(t,e):ym(t);return Math.abs(s)<An?-1:1}constructor(t,e,s,i){super(i),T(this,"AB",void 0),T(this,"AC",void 0),T(this,"alpha",void 0),T(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=Ic(this.AB,this.AC),this.bisector=jc(rg(this.AB.eq(y_)?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=ag(i),r=$a.getOrthogonalRotationFactor(n,this.bisector);return this.scaleUnitVector(n,s*r)}projectBevel(){const t=[];return(this.alpha%Di==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?Lc(this.scaleUnitVector(this.bisector,this.options.strokeMiterLimit)):this.options.strokeMiterLimit;return Lc(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($a.getOrthogonalRotationFactor(this.bisector),$a.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=>{og(n,t,e)&&s.push(this.A.add(n))}),s}projectRoundWithSkew(t,e){const s=[],{skewX:i,skewY:n,scaleX:r,scaleY:a,strokeUniform:h}=this.options,l=new D(Math.tan(Wt(i)),Math.tan(Wt(n))),u=this.strokeProjectionMagnitude,d=h?u/a/Math.sqrt(1/a**2+1/r**2*l.y**2):u/Math.sqrt(1+l.y**2),g=new D(Math.sqrt(Math.max(u**2-d**2,0)),d),f=h?u/Math.sqrt(1+l.x**2*(1/a)**2/(1/r+1/r*l.x*l.y)**2):u/Math.sqrt(1+l.x**2/(1+l.x*l.y)**2),p=new D(f,Math.sqrt(Math.max(u**2-f**2,0)));return[p,p.scalarMultiply(-1),g,g.scalarMultiply(-1)].map(m=>this.applySkew(h?m.multiply(this.strokeUniformScalar):m)).forEach(m=>{og(m,t,e)&&s.push(this.applySkew(this.A).add(m))}),s}projectRound(){const t=[];t.push(...this.projectBevel());const e=this.alpha%Di==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)),a=Ga(i,r)>0,h=a?i:n,l=a?n:i;return this.isSkewed()?t.push(...this.projectRoundWithSkew(h,l)):t.push(...this.projectRoundNoSkew(h,l)),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 jm extends Im{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(ag(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 $a(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(jc(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 Nm=function(o,t){let e=arguments.length>2&&arguments[2]!==void 0&&arguments[2];const s=[];if(o.length===0)return s;const i=o.reduce((n,r)=>(n[n.length-1].eq(r)||n.push(new D(r)),n),[new D(o[0])]);if(i.length===1)e=!0;else if(!e){const n=i[0],r=((a,h)=>{for(let l=a.length-1;l>=0;l--)if(h(a[l],l,a))return l;return-1})(i,a=>!a.eq(n));i.splice(r+1)}return i.forEach((n,r,a)=>{let h,l;r===0?(l=a[1],h=e?n:a[a.length-1]):r===a.length-1?(h=a[r-1],l=e?n:a[0]):(h=a[r-1],l=a[r+1]),e&&a.length===1?s.push(...new jm(n,n,t).project()):!e||r!==0&&r!==a.length-1?s.push(...new $a(n,h,l,t).project()):s.push(...new jm(n,r===0?l:h,t).project())}),s},pg=o=>{const t={};return Object.keys(o).forEach(e=>{t[e]={},Object.keys(o[e]).forEach(s=>{t[e][s]=E({},o[e][s])})}),t},Bm=o=>o.replace(/&/g,"&").replace(/"/g,""").replace(/'/g,"'").replace(/</g,"<").replace(/>/g,">"),Wc=o=>{const t=[];for(let e,s=0;s<o.length;s++)(e=__(o,s))!==!1&&t.push(e);return t},__=(o,t)=>{const e=o.charCodeAt(t);if(isNaN(e))return"";if(e<55296||e>57343)return o.charAt(t);if(55296<=e&&e<=56319){if(o.length<=t+1)throw"High surrogate without following low surrogate";const i=o.charCodeAt(t+1);if(56320>i||i>57343)throw"High surrogate without following low surrogate";return o.charAt(t)+o.charAt(t+1)}if(t===0)throw"Low surrogate without preceding high surrogate";const s=o.charCodeAt(t-1);if(55296>s||s>56319)throw"Low surrogate without preceding high surrogate";return!1};var w_=Object.freeze({__proto__:null,capitalize:function(o){let t=arguments.length>1&&arguments[1]!==void 0&&arguments[1];return"".concat(o.charAt(0).toUpperCase()).concat(t?o.slice(1):o.slice(1).toLowerCase())},escapeXml:Bm,graphemeSplit:Wc});const Xc=function(o,t){let e=arguments.length>2&&arguments[2]!==void 0&&arguments[2];return o.fill!==t.fill||o.stroke!==t.stroke||o.strokeWidth!==t.strokeWidth||o.fontSize!==t.fontSize||o.fontFamily!==t.fontFamily||o.fontWeight!==t.fontWeight||o.fontStyle!==t.fontStyle||o.textBackgroundColor!==t.textBackgroundColor||o.deltaY!==t.deltaY||e&&(o.overline!==t.overline||o.underline!==t.underline||o.linethrough!==t.linethrough)},Hm=(o,t)=>{const e=t.split(`
|
|
67
67
|
`),s=[];let i=-1,n={};o=pg(o);for(let r=0;r<e.length;r++){const a=Wc(e[r]);if(o[r])for(let h=0;h<a.length;h++){i++;const l=o[r][h];l&&Object.keys(l).length>0&&(Xc(n,l,!0)?s.push({start:i,end:i+1,style:l}):s[s.length-1].end++),n=l||{}}else i+=a.length,n={}}return s},Wm=(o,t)=>{if(!Array.isArray(o))return pg(o);const e=t.split(Wd),s={};let i=-1,n=0;for(let r=0;r<e.length;r++){const a=Wc(e[r]);for(let h=0;h<a.length;h++)i++,o[n]&&o[n].start<=i&&i<o[n].end&&(s[r]=s[r]||{},s[r][h]=E({},o[n].style),i===o[n].end-1&&n++)}return s},Mn=["display","transform",$t,"fill-opacity","fill-rule","opacity",Le,"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 Xm(o,t){const e=o.nodeName,s=o.getAttribute("class"),i=o.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 a=s.split(" ");for(let h=a.length;h--;)r=new RegExp("\\."+a[h]+n,"i"),t=t.replace(r,"")}return t.length===0}function x_(o,t){let e=!0;const s=Xm(o,t.pop());return s&&t.length&&(e=function(i,n){let r,a=!0;for(;i.parentElement&&i.parentElement.nodeType===1&&n.length;)a&&(r=n.pop()),a=Xm(i=i.parentElement,r);return n.length===0}(o,t)),s&&e&&t.length===0}const S_=o=>{var t;return(t=Wy[o])!==null&&t!==void 0?t:o},C_=new RegExp("(".concat(Bs,")"),"gi"),A_=o=>o.replace(C_," $1 ").replace(/,/gi," ").replace(/\s+/gi," ");var zm,Vm,Gm,Ym,Um,qm,$m;const je="(".concat(Bs,")"),T_=String.raw(zm||(zm=Cn(["(skewX)(",")"],["(skewX)\\(","\\)"])),je),E_=String.raw(Vm||(Vm=Cn(["(skewY)(",")"],["(skewY)\\(","\\)"])),je),k_=String.raw(Gm||(Gm=Cn(["(rotate)(","(?: "," ",")?)"],["(rotate)\\(","(?: "," ",")?\\)"])),je,je,je),M_=String.raw(Ym||(Ym=Cn(["(scale)(","(?: ",")?)"],["(scale)\\(","(?: ",")?\\)"])),je,je),O_=String.raw(Um||(Um=Cn(["(translate)(","(?: ",")?)"],["(translate)\\(","(?: ",")?\\)"])),je,je),P_=String.raw(qm||(qm=Cn(["(matrix)("," "," "," "," "," ",")"],["(matrix)\\("," "," "," "," "," ","\\)"])),je,je,je,je,je,je),mg="(?:".concat(P_,"|").concat(O_,"|").concat(k_,"|").concat(M_,"|").concat(T_,"|").concat(E_,")"),D_="(?:".concat(mg,"*)"),R_=String.raw($m||($m=Cn(["^s*(?:","?)s*$"],["^\\s*(?:","?)\\s*$"])),D_),F_=new RegExp(R_),L_=new RegExp(mg),I_=new RegExp(mg,"g");function zc(o){const t=[];if(!(o=A_(o).replace(/\s*([()])\s*/gi,"$1"))||o&&!F_.test(o))return[...De];for(const e of o.matchAll(I_)){const s=L_.exec(e[0]);if(!s)continue;let i=De;const n=s.filter(p=>!!p),[,r,...a]=n,[h,l,u,d,g,f]=a.map(p=>parseFloat(p));switch(r){case"translate":i=Wa(h,l);break;case Xd:i=Xa({angle:h},{x:l,y:u});break;case Sc:i=kc(h,l);break;case Na:i=Yd(h);break;case Ba:i=Ud(h);break;case"matrix":i=[h,l,u,d,g,f]}t.push(i)}return Ec(t)}function j_(o,t,e,s){const i=Array.isArray(t);let n,r=t;if(o!==$t&&o!==Le||t!==Re){if(o==="strokeUniform")return t==="non-scaling-stroke";if(o==="strokeDashArray")r=t===Re?null:t.replace(/,/g," ").split(/\s+/).map(parseFloat);else if(o==="transformMatrix")r=e&&e.transformMatrix?Gt(e.transformMatrix,zc(t)):zc(t);else if(o==="visible")r=t!==Re&&t!=="hidden",e&&e.visible===!1&&(r=!1);else if(o==="opacity")r=parseFloat(t),e&&e.opacity!==void 0&&(r*=e.opacity);else if(o==="textAnchor")r=t==="start"?mt:t==="end"?Vt:st;else if(o==="charSpacing")n=Ie(t,s)/s*1e3;else if(o==="paintFirst"){const a=t.indexOf($t),h=t.indexOf(Le);r=$t,(a>-1&&h>-1&&h<a||a===-1&&h>-1)&&(r=Le)}else{if(o==="href"||o==="xlink:href"||o==="font"||o==="id")return t;if(o==="imageSmoothing")return t==="optimizeQuality";n=i?t.map(Ie):Ie(t,s)}}else r="";return!i&&isNaN(n)?r:n}function N_(o,t){const e=o.match(Hy);if(!e)return;const s=e[1],i=e[3],n=e[4],r=e[5],a=e[6];s&&(t.fontStyle=s),i&&(t.fontWeight=isNaN(parseFloat(i))?i:parseFloat(i)),n&&(t.fontSize=Ie(n)),a&&(t.fontFamily=a),r&&(t.lineHeight=r==="normal"?1:r)}function vg(o,t){o.replace(/;\s*$/,"").split(";").forEach(e=>{if(!e)return;const[s,i]=e.split(":");t[s.trim().toLowerCase()]=i.trim()})}function B_(o){const t={},e=o.getAttribute("style");return e&&(typeof e=="string"?vg(e,t):function(s,i){Object.entries(s).forEach(n=>{let[r,a]=n;a!==void 0&&(i[r.toLowerCase()]=a)})}(e,t)),t}const H_={stroke:"strokeOpacity",fill:"fillOpacity"};function Ii(o,t,e){if(!o)return{};let s,i={},n=Bd;o.parentNode&&mm.test(o.parentNode.nodeName)&&(i=Ii(o.parentElement,t,e),i.fontSize&&(s=n=Ie(i.fontSize)));const r=E(E(E({},t.reduce((l,u)=>{const d=o.getAttribute(u);return d&&(l[u]=d),l},{})),function(l){let u=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},d={};for(const g in u)x_(l,g.split(" "))&&(d=E(E({},d),u[g]));return d}(o,e)),B_(o));r[ng]&&o.setAttribute(ng,r[ng]),r[ig]&&(s=Ie(r[ig],n),r[ig]="".concat(s));const a={};for(const l in r){const u=S_(l),d=j_(u,r[l],i,s);a[u]=d}a&&a.font&&N_(a.font,a);const h=E(E({},i),a);return mm.test(o.nodeName)?h:function(l){const u=xe.getDefaults();return Object.entries(H_).forEach(d=>{let[g,f]=d;if(l[f]===void 0||l[g]==="")return;if(l[g]===void 0){if(!u[g])return;l[g]=u[g]}if(l[g].indexOf("url(")===0)return;const p=new yt(l[g]);l[g]=p.setAlpha(Dt(p.getAlpha()*l[f],2)).toRgba()}),l}(h)}const W_=["left","top","width","height","visible"],Km=["rx","ry"];class li extends xe{static getDefaults(){return E(E({},super.getDefaults()),li.ownDefaults)}constructor(t){super(),Object.assign(this,li.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,a=this.ry?Math.min(this.ry,s/2):0,h=r!==0||a!==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*a,i+e,n+a),t.lineTo(i+e,n+s-a),h&&t.bezierCurveTo(i+e,n+s-Tn*a,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*a,i,n+s-a),t.lineTo(i,n+a),h&&t.bezierCurveTo(i,n+Tn*a,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([...Km,...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,`" />
|
|
68
68
|
`)]}static async fromElement(t,e,s){const i=Ii(t,this.ATTRIBUTE_NAMES,s),{left:n=0,top:r=0,width:a=0,height:h=0,visible:l=!0}=i,u=Pt(i,W_);return new this(E(E(E({},e),u),{},{left:n,top:r,width:a,height:h,visible:!!(l&&a&&h)}))}}T(li,"type","Rect"),T(li,"cacheProperties",[...Fi,...Km]),T(li,"ownDefaults",{rx:0,ry:0}),T(li,"ATTRIBUTE_NAMES",[...Mn,"x","y","rx","ry","width","height"]),V.setClass(li),V.setSVGClass(li);const ji="initialization",Vc="added",bg="removed",Gc="imperative",Jm=(o,t)=>{const{strokeUniform:e,strokeWidth:s,width:i,height:n,group:r}=t,a=r&&r!==o?wh(r.calcTransformMatrix(),o.calcTransformMatrix()):null,h=a?t.getRelativeCenterPoint().transform(a):t.getRelativeCenterPoint(),l=!t.isStrokeAccountedForInDimensions(),u=e&&l?hm(new D(s,s),void 0,o.calcTransformMatrix()):Vd,d=!e&&l?s:0,g=Pc(i+d,n+d,Ec([a,t.calcOwnMatrix()],!0)).add(u).scalarDivide(2);return[h.subtract(g),h.add(g)]};class Yc{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===Gc||!!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===Gc&&e.overrides)return e.overrides;if(t.length===0)return;const{left:n,top:r,width:a,height:h}=hi(t.map(d=>Jm(i,d)).reduce((d,g)=>d.concat(g),[])),l=new D(a,h),u=new D(n,r).add(l.scalarDivide(2));if(s===ji){const d=this.getInitialSize(e,{size:l,center:u});return{center:u,relativeCorrection:new D(0,0),size:d}}return{center:u.transform(i.calcOwnMatrix()),size:l}}}T(Yc,"type","strategy");class yg extends Yc{shouldPerformLayout(t){return!0}}T(yg,"type","fit-content"),V.setClass(yg);const X_=["strategy"],z_=["target","strategy","bubbles","prevStrategy"],Qm="layoutManager";class Ch{constructor(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:new yg;T(this,"strategy",void 0),this.strategy=t,this._subscriptions=new Map}performLayout(t){const e=E(E({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[Cc,Ip,gh,jp,wc,Np,xc,Py,Dy].map(i=>t.on(i,n=>this.performLayout(i===Cc?{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===Vc?this.subscribeTargets(t):s===bg&&this.unsubscribeTargets(t),e.fire("layout:before",{context:t}),i&&i.fire("object:layout:before",{target:e,context:t}),s===Gc&&t.deep){const n=Pt(t,X_);e.forEachObject(r=>r.layoutManager&&r.layoutManager.performLayout(E(E({},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:a,correction:h=new D,relativeCorrection:l=new D}=n,u=r.subtract(a).add(h).transform(i===ji?De:qe(e.calcOwnMatrix()),!0).add(l);return{result:n,prevCenter:r,nextCenter:a,offset:u}}commitLayout(t,e){const{target:s}=t,{result:{size:i},nextCenter:n}=e;var r,a;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*Kt(s.originX),top:(a=t.y)!==null&&a!==void 0?a:n.y+i.y*Kt(s.originY)}):(s.setPositionByOrigin(n,st,st),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,a=Pt(t,z_),{canvas:h}=s;s.fire("layout:after",{context:t,result:e}),h&&h.fire("object:layout:after",{context:t,result:e,target:s});const l=s.parent;n&&l!=null&&l.layoutManager&&((a.path||(a.path=[])).push(s),l.layoutManager.performLayout(E(E({},a),{},{target:l}))),s.set("dirty",!0)}dispose(){const{_subscriptions:t}=this;t.forEach(e=>e.forEach(s=>s())),t.clear()}toObject(){return{type:Qm,strategy:this.strategy.constructor.type}}toJSON(){return this.toObject()}}V.setClass(Ch,Qm);const V_=["type","objects","layoutManager"];class G_ extends Ch{performLayout(){}}class ci extends Bp(xe){static getDefaults(){return E(E({},super.getDefaults()),ci.ownDefaults)}constructor(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:[],e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};super(),T(this,"_activeObjects",[]),T(this,"__objectSelectionTracker",void 0),T(this,"__objectSelectionDisposer",void 0),Object.assign(this,ci.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 Ch,this.layoutManager.performLayout({type:ji,target:this,targets:[...t],x:e.left,y:e.top})}canEnterGroup(t){return t===this||this.isDescendantOf(t)?(Pi("error","Group: circular object trees are not supported, this call has no effect"),!1):this._objects.indexOf(t)===-1||(Pi("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(Vc,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(Vc,n),r}remove(){const t=super.remove(...arguments);return this._onAfterObjectsChange(bg,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&&Va(t,Gt(qe(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||(Va(t,Gt(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=xe.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(...qe(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(E({target:this,type:Gc},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 E(E(E({},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=li.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",` >
|
|
69
69
|
`],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>
|
|
@@ -535,4 +535,4 @@ void main() {
|
|
|
535
535
|
`),position:m,pageIndex:_-1,rect:u.slice(0),rotation:d,id:g,deleted:!1,popupRef:f}}const r=await super.deserialize(e,s,i);return v(r,ds,e.fontSize),v(r,Qs,U.makeHexColor(...e.color)),v(r,us,y(a=Et,cn,op).call(a,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=Et._internalPadding*this.parentScale,i=this.getRect(s,s),n=_t._colorManager.convert(this.isAttachedToDOM?getComputedStyle(this.editorDiv).color:c(this,Qs)),r={annotationType:nt.FREETEXT,color:n,fontSize:c(this,ds),value:y(this,Qt,Hb).call(this),pageIndex:this.pageIndex,rect:i,rotation:this.rotation,structTreeParentId:this._structTreeParentId};return e?r:this.annotationElementId&&!y(this,Qt,Wb).call(this,r)?null:(r.id=this.annotationElementId,r)}renderAnnotationElement(e){const s=super.renderAnnotationElement(e);if(this.deleted)return s;const{style:i}=s;i.fontSize=`calc(${c(this,ds)}px * var(--scale-factor))`,i.color=c(this,Qs),s.replaceChildren();for(const r of c(this,us).split(`
|
|
536
536
|
`)){const a=document.createElement("div");a.append(r?document.createTextNode(r):document.createElement("br")),s.append(a)}const n=Et._internalPadding*this.parentScale;return e.updateEdited({rect:this.getRect(n,n),popupContent:c(this,us)}),s}resetAnnotationElement(e){super.resetAnnotationElement(e),e.resetEdited()}};Qs=new WeakMap,us=new WeakMap,Bl=new WeakMap,ma=new WeakMap,ds=new WeakMap,Qt=new WeakSet,jb=function(e){const s=n=>{this.editorDiv.style.fontSize=`calc(${n}px * var(--scale-factor))`,this.translate(0,-(n-c(this,ds))*this.parentScale),v(this,ds,n),y(this,Qt,xd).call(this)},i=c(this,ds);this.addCommands({cmd:s.bind(this,e),undo:s.bind(this,i),post:this._uiManager.updateUI.bind(this._uiManager,this),mustExec:!0,type:Z.FREETEXT_SIZE,overwriteIfSameType:!0,keepUndo:!0})},Nb=function(e){const s=n=>{v(this,Qs,this.editorDiv.style.color=n)},i=c(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:Z.FREETEXT_COLOR,overwriteIfSameType:!0,keepUndo:!0})},Bb=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(y(i=Et,cn,Sd).call(i,n)),s=n);return e.join(`
|
|
537
537
|
`)},xd=function(){const[e,s]=this.parentDimensions;let i;if(this.isAttachedToDOM)i=this.div.getBoundingClientRect();else{const{currentLayer:n,div:r}=this,a=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=a,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()},cn=new WeakSet,Sd=function(e){return(e.nodeType===Node.TEXT_NODE?e.nodeValue:e.innerText).replaceAll(Iu,"")},Cd=function(){if(this.editorDiv.replaceChildren(),!!c(this,us))for(const e of c(this,us).split(`
|
|
538
|
-
`)){const s=document.createElement("div");s.append(e?document.createTextNode(e):document.createElement("br")),this.editorDiv.append(s)}},Hb=function(){return c(this,us).replaceAll(" "," ")},op=function(e){return e.replaceAll(" "," ")},Wb=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((a,h)=>a!==n[h])||e.pageIndex!==r},w(Et,cn),tt(Et,"_freeTextDefaultContent",""),tt(Et,"_internalPadding",0),tt(Et,"_defaultColor",null),tt(Et,"_defaultFontSize",10),tt(Et,"_type","freetext"),tt(Et,"_editorType",nt.FREETEXT);let mf=Et;class Pv{toSVGPath(){Mt("Abstract method `toSVGPath` must be implemented.")}get box(){Mt("Abstract getter `box` must be implemented.")}serialize(t,e){Mt("Abstract method `serialize` must be implemented.")}get classNamesForDrawing(){Mt("Abstract getter `classNamesForDrawing` must be implemented.")}get classNamesForOutlining(){Mt("Abstract getter `classNamesForOutlining` must be implemented.")}get mustRemoveSelfIntersections(){return!1}}const un=class un{constructor({x:t,y:e},s,i,n,r,a=0){w(this,oe);w(this,gs);w(this,Zs,[]);w(this,jo);w(this,No);w(this,Ai,[]);w(this,ot,new Float64Array(18));w(this,va);w(this,ba);w(this,Hl);w(this,Wl);w(this,Bo);w(this,Ho);w(this,er,[]);v(this,gs,s),v(this,Ho,n*i),v(this,No,r),c(this,ot).set([NaN,NaN,NaN,NaN,t,e],6),v(this,jo,a),v(this,Wl,c(un,Xl)*i),v(this,Hl,c(un,id)*i),v(this,Bo,i),c(this,er).push(t,e)}isEmpty(){return isNaN(c(this,ot)[8])}add({x:t,y:e}){var R;v(this,va,t),v(this,ba,e);const[s,i,n,r]=c(this,gs);let[a,h,l,u]=c(this,ot).subarray(8,12);const d=t-l,g=e-u,f=Math.hypot(d,g);if(f<c(this,Hl))return!1;const p=f-c(this,Wl),m=p/f,_=m*d,b=m*g;let x=a,S=h;a=l,h=u,l+=_,u+=b,(R=c(this,er))==null||R.push(t,e);const A=-b/p,k=_/p,P=A*c(this,Ho),M=k*c(this,Ho);return c(this,ot).set(c(this,ot).subarray(2,8),0),c(this,ot).set([l+P,u+M],4),c(this,ot).set(c(this,ot).subarray(14,18),12),c(this,ot).set([l-P,u-M],16),isNaN(c(this,ot)[6])?(c(this,Ai).length===0&&(c(this,ot).set([a+P,h+M],2),c(this,Ai).push(NaN,NaN,NaN,NaN,(a+P-s)/n,(h+M-i)/r),c(this,ot).set([a-P,h-M],14),c(this,Zs).push(NaN,NaN,NaN,NaN,(a-P-s)/n,(h-M-i)/r)),c(this,ot).set([x,S,a,h,l,u],6),!this.isEmpty()):(c(this,ot).set([x,S,a,h,l,u],6),Math.abs(Math.atan2(S-h,x-a)-Math.atan2(b,_))<Math.PI/2?([a,h,l,u]=c(this,ot).subarray(2,6),c(this,Ai).push(NaN,NaN,NaN,NaN,((a+l)/2-s)/n,((h+u)/2-i)/r),[a,h,x,S]=c(this,ot).subarray(14,18),c(this,Zs).push(NaN,NaN,NaN,NaN,((x+a)/2-s)/n,((S+h)/2-i)/r),!0):([x,S,a,h,l,u]=c(this,ot).subarray(0,6),c(this,Ai).push(((x+5*a)/6-s)/n,((S+5*h)/6-i)/r,((5*a+l)/6-s)/n,((5*h+u)/6-i)/r,((a+l)/2-s)/n,((h+u)/2-i)/r),[l,u,a,h,x,S]=c(this,ot).subarray(12,18),c(this,Zs).push(((x+5*a)/6-s)/n,((S+5*h)/6-i)/r,((5*a+l)/6-s)/n,((5*h+u)/6-i)/r,((a+l)/2-s)/n,((h+u)/2-i)/r),!0))}toSVGPath(){if(this.isEmpty())return"";const t=c(this,Ai),e=c(this,Zs);if(isNaN(c(this,ot)[6])&&!this.isEmpty())return y(this,oe,Xb).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]}`);y(this,oe,Vb).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 y(this,oe,zb).call(this,s),s.join(" ")}newFreeDrawOutline(t,e,s,i,n,r){return new Dv(t,e,s,i,n,r)}getOutlines(){var d;const t=c(this,Ai),e=c(this,Zs),s=c(this,ot),[i,n,r,a]=c(this,gs),h=new Float64Array((((d=c(this,er))==null?void 0:d.length)??0)+2);for(let g=0,f=h.length-2;g<f;g+=2)h[g]=(c(this,er)[g]-i)/r,h[g+1]=(c(this,er)[g+1]-n)/a;if(h[h.length-2]=(c(this,va)-i)/r,h[h.length-1]=(c(this,ba)-n)/a,isNaN(s[6])&&!this.isEmpty())return y(this,oe,Gb).call(this,h);const l=new Float64Array(c(this,Ai).length+24+c(this,Zs).length);let u=t.length;for(let g=0;g<u;g+=2){if(isNaN(t[g])){l[g]=l[g+1]=NaN;continue}l[g]=t[g],l[g+1]=t[g+1]}u=y(this,oe,Ub).call(this,l,u);for(let g=e.length-6;g>=6;g-=6)for(let f=0;f<6;f+=2){if(isNaN(e[g+f])){l[u]=l[u+1]=NaN,u+=2;continue}l[u]=e[g+f],l[u+1]=e[g+f+1],u+=2}return y(this,oe,Yb).call(this,l,u),this.newFreeDrawOutline(l,h,c(this,gs),c(this,Bo),c(this,jo),c(this,No))}};gs=new WeakMap,Zs=new WeakMap,jo=new WeakMap,No=new WeakMap,Ai=new WeakMap,ot=new WeakMap,va=new WeakMap,ba=new WeakMap,Hl=new WeakMap,Wl=new WeakMap,Bo=new WeakMap,Ho=new WeakMap,er=new WeakMap,Xl=new WeakMap,sd=new WeakMap,id=new WeakMap,oe=new WeakSet,gc=function(){const t=c(this,ot).subarray(4,6),e=c(this,ot).subarray(16,18),[s,i,n,r]=c(this,gs);return[(c(this,va)+(t[0]-e[0])/2-s)/n,(c(this,ba)+(t[1]-e[1])/2-i)/r,(c(this,va)+(e[0]-t[0])/2-s)/n,(c(this,ba)+(e[1]-t[1])/2-i)/r]},Xb=function(){const[t,e,s,i]=c(this,gs),[n,r,a,h]=y(this,oe,gc).call(this);return`M${(c(this,ot)[2]-t)/s} ${(c(this,ot)[3]-e)/i} L${(c(this,ot)[4]-t)/s} ${(c(this,ot)[5]-e)/i} L${n} ${r} L${a} ${h} L${(c(this,ot)[16]-t)/s} ${(c(this,ot)[17]-e)/i} L${(c(this,ot)[14]-t)/s} ${(c(this,ot)[15]-e)/i} Z`},zb=function(t){const e=c(this,Zs);t.push(`L${e[4]} ${e[5]} Z`)},Vb=function(t){const[e,s,i,n]=c(this,gs),r=c(this,ot).subarray(4,6),a=c(this,ot).subarray(16,18),[h,l,u,d]=y(this,oe,gc).call(this);t.push(`L${(r[0]-e)/i} ${(r[1]-s)/n} L${h} ${l} L${u} ${d} L${(a[0]-e)/i} ${(a[1]-s)/n}`)},Gb=function(t){const e=c(this,ot),[s,i,n,r]=c(this,gs),[a,h,l,u]=y(this,oe,gc).call(this),d=new Float64Array(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,a,h,NaN,NaN,NaN,NaN,l,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,c(this,gs),c(this,Bo),c(this,jo),c(this,No))},Yb=function(t,e){const s=c(this,Zs);return t.set([NaN,NaN,NaN,NaN,s[4],s[5]],e),e+=6},Ub=function(t,e){const s=c(this,ot).subarray(4,6),i=c(this,ot).subarray(16,18),[n,r,a,h]=c(this,gs),[l,u,d,g]=y(this,oe,gc).call(this);return t.set([NaN,NaN,NaN,NaN,(s[0]-n)/a,(s[1]-r)/h,NaN,NaN,NaN,NaN,l,u,NaN,NaN,NaN,NaN,d,g,NaN,NaN,NaN,NaN,(i[0]-n)/a,(i[1]-r)/h],e),e+=24},w(un,Xl,8),w(un,sd,2),w(un,id,c(un,Xl)+c(un,sd));let ju=un;class Dv extends Pv{constructor(e,s,i,n,r,a){super();w(this,Ze);w(this,Wo);w(this,ya,null);w(this,dn);w(this,zl);w(this,fs);w(this,Vl);w(this,Ut);v(this,Ut,e),v(this,fs,s),v(this,Wo,i),v(this,Vl,n),v(this,dn,r),v(this,zl,a),y(this,Ze,qb).call(this,a);const{x:h,y:l,width:u,height:d}=c(this,ya);for(let g=0,f=e.length;g<f;g+=2)e[g]=(e[g]-h)/u,e[g+1]=(e[g+1]-l)/d;for(let g=0,f=s.length;g<f;g+=2)s[g]=(s[g]-h)/u,s[g+1]=(s[g+1]-l)/d}toSVGPath(){const e=[`M${c(this,Ut)[4]} ${c(this,Ut)[5]}`];for(let s=6,i=c(this,Ut).length;s<i;s+=6){if(isNaN(c(this,Ut)[s])){e.push(`L${c(this,Ut)[s+4]} ${c(this,Ut)[s+5]}`);continue}e.push(`C${c(this,Ut)[s]} ${c(this,Ut)[s+1]} ${c(this,Ut)[s+2]} ${c(this,Ut)[s+3]} ${c(this,Ut)[s+4]} ${c(this,Ut)[s+5]}`)}return e.push("Z"),e.join(" ")}serialize([e,s,i,n],r){const a=i-e,h=n-s;let l,u;switch(r){case 0:l=y(this,Ze,fc).call(this,c(this,Ut),e,n,a,-h),u=y(this,Ze,fc).call(this,c(this,fs),e,n,a,-h);break;case 90:l=y(this,Ze,pc).call(this,c(this,Ut),e,s,a,h),u=y(this,Ze,pc).call(this,c(this,fs),e,s,a,h);break;case 180:l=y(this,Ze,fc).call(this,c(this,Ut),i,s,-a,h),u=y(this,Ze,fc).call(this,c(this,fs),i,s,-a,h);break;case 270:l=y(this,Ze,pc).call(this,c(this,Ut),i,n,-a,-h),u=y(this,Ze,pc).call(this,c(this,fs),i,n,-a,-h);break}return{outline:Array.from(l),points:[Array.from(u)]}}get box(){return c(this,ya)}newOutliner(e,s,i,n,r,a=0){return new ju(e,s,i,n,r,a)}getNewOutline(e,s){const{x:i,y:n,width:r,height:a}=c(this,ya),[h,l,u,d]=c(this,Wo),g=r*u,f=a*d,p=i*u+h,m=n*d+l,_=this.newOutliner({x:c(this,fs)[0]*g+p,y:c(this,fs)[1]*f+m},c(this,Wo),c(this,Vl),e,c(this,zl),s??c(this,dn));for(let b=2;b<c(this,fs).length;b+=2)_.add({x:c(this,fs)[b]*g+p,y:c(this,fs)[b+1]*f+m});return _.getOutlines()}get mustRemoveSelfIntersections(){return!0}}Wo=new WeakMap,ya=new WeakMap,dn=new WeakMap,zl=new WeakMap,fs=new WeakMap,Vl=new WeakMap,Ut=new WeakMap,Ze=new WeakSet,fc=function(e,s,i,n,r){const a=new Float64Array(e.length);for(let h=0,l=e.length;h<l;h+=2)a[h]=s+e[h]*n,a[h+1]=i+e[h+1]*r;return a},pc=function(e,s,i,n,r){const a=new Float64Array(e.length);for(let h=0,l=e.length;h<l;h+=2)a[h]=s+e[h+1]*n,a[h+1]=i+e[h]*r;return a},qb=function(e){const s=c(this,Ut);let i=s[4],n=s[5],r=i,a=n,h=i,l=n,u=i,d=n;const g=e?Math.max:Math.min;for(let b=6,x=s.length;b<x;b+=6){if(isNaN(s[b]))r=Math.min(r,s[b+4]),a=Math.min(a,s[b+5]),h=Math.max(h,s[b+4]),l=Math.max(l,s[b+5]),d<s[b+5]?(u=s[b+4],d=s[b+5]):d===s[b+5]&&(u=g(u,s[b+4]));else{const S=U.bezierBoundingBox(i,n,...s.slice(b,b+6));r=Math.min(r,S[0]),a=Math.min(a,S[1]),h=Math.max(h,S[2]),l=Math.max(l,S[3]),d<S[3]?(u=S[2],d=S[3]):d===S[3]&&(u=g(u,S[2]))}i=s[b+4],n=s[b+5]}const f=r-c(this,dn),p=a-c(this,dn),m=h-r+2*c(this,dn),_=l-a+2*c(this,dn);v(this,ya,{x:f,y:p,width:m,height:_,lastPoint:[u,d]})};class Rv{constructor(t,e=0,s=0,i=!0){w(this,Xe);w(this,Gl);w(this,sr,[]);w(this,ti,[]);let n=1/0,r=-1/0,a=1/0,h=-1/0;const u=10**-4;for(const{x:b,y:x,width:S,height:A}of t){const k=Math.floor((b-e)/u)*u,P=Math.ceil((b+S+e)/u)*u,M=Math.floor((x-e)/u)*u,O=Math.ceil((x+A+e)/u)*u,R=[k,M,O,!0],I=[P,M,O,!1];c(this,sr).push(R,I),n=Math.min(n,k),r=Math.max(r,P),a=Math.min(a,M),h=Math.max(h,O)}const d=r-n+2*s,g=h-a+2*s,f=n-s,p=a-s,m=c(this,sr).at(i?-1:-2),_=[m[0],m[2]];for(const b of c(this,sr)){const[x,S,A]=b;b[0]=(x-f)/d,b[1]=(S-p)/g,b[2]=(A-p)/g}v(this,Gl,{x:f,y:p,width:d,height:g,lastPoint:_})}getOutlines(){c(this,sr).sort((e,s)=>e[0]-s[0]||e[1]-s[1]||e[2]-s[2]);const t=[];for(const e of c(this,sr))e[3]?(t.push(...y(this,Xe,hp).call(this,e)),y(this,Xe,Kb).call(this,e)):(y(this,Xe,Jb).call(this,e),t.push(...y(this,Xe,hp).call(this,e)));return y(this,Xe,$b).call(this,t)}}Gl=new WeakMap,sr=new WeakMap,ti=new WeakMap,Xe=new WeakSet,$b=function(t){const e=[],s=new Set;for(const r of t){const[a,h,l]=r;e.push([a,h,r],[a,l,r])}e.sort((r,a)=>r[1]-a[1]||r[0]-a[0]);for(let r=0,a=e.length;r<a;r+=2){const h=e[r][2],l=e[r+1][2];h.push(l),l.push(h),s.add(h),s.add(l)}const i=[];let n;for(;s.size>0;){const r=s.values().next().value;let[a,h,l,u,d]=r;s.delete(r);let g=a,f=h;for(n=[a,l],i.push(n);;){let p;if(s.has(u))p=u;else if(s.has(d))p=d;else break;s.delete(p),[a,h,l,u,d]=p,g!==a&&(n.push(g,f,a,f===h?h:l),g=a),f=f===h?l:h}n.push(g,f)}return new vC(i,c(this,Gl))},Ad=function(t){const e=c(this,ti);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},Kb=function([,t,e]){const s=y(this,Xe,Ad).call(this,t);c(this,ti).splice(s,0,[t,e])},Jb=function([,t,e]){const s=y(this,Xe,Ad).call(this,t);for(let i=s;i<c(this,ti).length;i++){const[n,r]=c(this,ti)[i];if(n!==t)break;if(n===t&&r===e){c(this,ti).splice(i,1);return}}for(let i=s-1;i>=0;i--){const[n,r]=c(this,ti)[i];if(n!==t)break;if(n===t&&r===e){c(this,ti).splice(i,1);return}}},hp=function(t){const[e,s,i]=t,n=[[e,s,i]],r=y(this,Xe,Ad).call(this,i);for(let a=0;a<r;a++){const[h,l]=c(this,ti)[a];for(let u=0,d=n.length;u<d;u++){const[,g,f]=n[u];if(!(l<=g||f<=h)){if(g>=h){if(f>l)n[u][1]=l;else{if(d===1)return[];n.splice(u,1),u--,d--}continue}n[u][2]=h,f>l&&n.push([e,l,f])}}}return n};class vC extends Pv{constructor(e,s){super();w(this,Yl);w(this,Xo);v(this,Xo,e),v(this,Yl,s)}toSVGPath(){const e=[];for(const s of c(this,Xo)){let[i,n]=s;e.push(`M${i} ${n}`);for(let r=2;r<s.length;r+=2){const a=s[r],h=s[r+1];a===i?(e.push(`V${h}`),n=h):h===n&&(e.push(`H${a}`),i=a)}e.push("Z")}return e.join(" ")}serialize([e,s,i,n],r){const a=[],h=i-e,l=n-s;for(const u of c(this,Xo)){const d=new Array(u.length);for(let g=0;g<u.length;g+=2)d[g]=e+u[g]*h,d[g+1]=n-u[g+1]*l;a.push(d)}return a}get box(){return c(this,Yl)}get classNamesForDrawing(){return["highlight"]}get classNamesForOutlining(){return["highlightOutline"]}}Yl=new WeakMap,Xo=new WeakMap;class vf extends ju{newFreeDrawOutline(t,e,s,i,n,r){return new bC(t,e,s,i,n,r)}get classNamesForDrawing(){return["highlight","free"]}}class bC extends Dv{get classNamesForDrawing(){return["highlight","free"]}get classNamesForOutlining(){return["highlightOutline","free"]}newOutliner(t,e,s,i,n,r=0){return new vf(t,e,s,i,n,r)}}const ts=class ts{constructor({editor:t=null,uiManager:e=null}){w(this,Ct);w(this,ei,null);w(this,_a,null);w(this,zo);w(this,he,null);w(this,Ul,!1);w(this,Vo,!1);w(this,ql,null);w(this,$l);w(this,ir,null);w(this,si,null);w(this,Go);var s;t?(v(this,Vo,!1),v(this,Go,Z.HIGHLIGHT_COLOR),v(this,ql,t)):(v(this,Vo,!0),v(this,Go,Z.HIGHLIGHT_DEFAULT_COLOR)),v(this,si,(t==null?void 0:t._uiManager)||e),v(this,$l,c(this,si)._eventBus),v(this,zo,(t==null?void 0:t.color)||((s=c(this,si))==null?void 0:s.highlightColors.values().next().value)||"#FFFF98"),c(ts,Kl)||v(ts,Kl,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 ut(this,"_keyboardManager",new Fh([[["Escape","mac+Escape"],ts.prototype._hideDropdownFromKeyboard],[[" ","mac+ "],ts.prototype._colorSelectFromKeyboard],[["ArrowDown","ArrowRight","mac+ArrowDown","mac+ArrowRight"],ts.prototype._moveToNext],[["ArrowUp","ArrowLeft","mac+ArrowUp","mac+ArrowLeft"],ts.prototype._moveToPrevious],[["Home","mac+Home"],ts.prototype._moveToBeginning],[["End","mac+End"],ts.prototype._moveToEnd]]))}renderButton(){const t=v(this,ei,document.createElement("button"));t.className="colorPicker",t.tabIndex="0",t.setAttribute("data-l10n-id","pdfjs-editor-colorpicker-button"),t.setAttribute("aria-haspopup",!0);const e=c(this,si)._signal;t.addEventListener("click",y(this,Ct,Fa).bind(this),{signal:e}),t.addEventListener("keydown",y(this,Ct,up).bind(this),{signal:e});const s=v(this,_a,document.createElement("span"));return s.className="swatch",s.setAttribute("aria-hidden",!0),s.style.backgroundColor=c(this,zo),t.append(s),t}renderMainDropdown(){const t=v(this,he,y(this,Ct,lp).call(this));return t.setAttribute("aria-orientation","horizontal"),t.setAttribute("aria-labelledby","highlightColorPickerLabel"),t}_colorSelectFromKeyboard(t){if(t.target===c(this,ei)){y(this,Ct,Fa).call(this,t);return}const e=t.target.getAttribute("data-color");e&&y(this,Ct,cp).call(this,e,t)}_moveToNext(t){var e,s;if(!c(this,Ct,ur)){y(this,Ct,Fa).call(this,t);return}if(t.target===c(this,ei)){(e=c(this,he).firstChild)==null||e.focus();return}(s=t.target.nextSibling)==null||s.focus()}_moveToPrevious(t){var e,s;if(t.target===((e=c(this,he))==null?void 0:e.firstChild)||t.target===c(this,ei)){c(this,Ct,ur)&&this._hideDropdownFromKeyboard();return}c(this,Ct,ur)||y(this,Ct,Fa).call(this,t),(s=t.target.previousSibling)==null||s.focus()}_moveToBeginning(t){var e;if(!c(this,Ct,ur)){y(this,Ct,Fa).call(this,t);return}(e=c(this,he).firstChild)==null||e.focus()}_moveToEnd(t){var e;if(!c(this,Ct,ur)){y(this,Ct,Fa).call(this,t);return}(e=c(this,he).lastChild)==null||e.focus()}hideDropdown(){var t,e;(t=c(this,he))==null||t.classList.add("hidden"),(e=c(this,ir))==null||e.abort(),v(this,ir,null)}_hideDropdownFromKeyboard(){var t;if(!c(this,Vo)){if(!c(this,Ct,ur)){(t=c(this,ql))==null||t.unselect();return}this.hideDropdown(),c(this,ei).focus({preventScroll:!0,focusVisible:c(this,Ul)})}}updateColor(t){if(c(this,_a)&&(c(this,_a).style.backgroundColor=t),!c(this,he))return;const e=c(this,si).highlightColors.values();for(const s of c(this,he).children)s.setAttribute("aria-selected",e.next().value===t)}destroy(){var t,e;(t=c(this,ei))==null||t.remove(),v(this,ei,null),v(this,_a,null),(e=c(this,he))==null||e.remove(),v(this,he,null)}};ei=new WeakMap,_a=new WeakMap,zo=new WeakMap,he=new WeakMap,Ul=new WeakMap,Vo=new WeakMap,ql=new WeakMap,$l=new WeakMap,ir=new WeakMap,si=new WeakMap,Go=new WeakMap,Kl=new WeakMap,Ct=new WeakSet,lp=function(){const t=document.createElement("div"),e=c(this,si)._signal;t.addEventListener("contextmenu",ws,{signal:e}),t.className="dropdown",t.role="listbox",t.setAttribute("aria-multiselectable",!1),t.setAttribute("aria-orientation","vertical"),t.setAttribute("data-l10n-id","pdfjs-editor-colorpicker-dropdown");for(const[s,i]of c(this,si).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",c(ts,Kl)[s]);const r=document.createElement("span");n.append(r),r.className="swatch",r.style.backgroundColor=i,n.setAttribute("aria-selected",i===c(this,zo)),n.addEventListener("click",y(this,Ct,cp).bind(this,i),{signal:e}),t.append(n)}return t.addEventListener("keydown",y(this,Ct,up).bind(this),{signal:e}),t},cp=function(t,e){e.stopPropagation(),c(this,$l).dispatch("switchannotationeditorparams",{source:this,type:c(this,Go),value:t})},up=function(t){ts._keyboardManager.exec(this,t)},Fa=function(t){if(c(this,Ct,ur)){this.hideDropdown();return}if(v(this,Ul,t.detail===0),c(this,ir)||(v(this,ir,new AbortController),window.addEventListener("pointerdown",y(this,Ct,Qb).bind(this),{signal:c(this,si).combinedSignal(c(this,ir))})),c(this,he)){c(this,he).classList.remove("hidden");return}const e=v(this,he,y(this,Ct,lp).call(this));c(this,ei).append(e)},Qb=function(t){var e;(e=c(this,he))!=null&&e.contains(t.target)||this.hideDropdown()},ur=function(){return c(this,he)&&!c(this,he).classList.contains("hidden")},w(ts,Kl,null);let Nu=ts;const pt=class pt extends _t{constructor(e){super({...e,name:"highlightEditor"});w(this,it);w(this,Yo,null);w(this,Jl,0);w(this,gn);w(this,wa,null);w(this,Uo,null);w(this,Es,null);w(this,Ql,null);w(this,Zl,0);w(this,xa,null);w(this,ii,null);w(this,Me,null);w(this,es,!1);w(this,qo,null);w(this,fn);w(this,le,null);w(this,$o,"");w(this,ks);w(this,tc,"");this.color=e.color||pt._defaultColor,v(this,ks,e.thickness||pt._defaultThickness),v(this,fn,e.opacity||pt._defaultOpacity),v(this,gn,e.boxes||null),v(this,tc,e.methodOfCreation||""),v(this,$o,e.text||""),this._isDraggable=!1,e.highlightId>-1?(v(this,es,!0),y(this,it,Td).call(this,e),y(this,it,La).call(this)):c(this,gn)&&(v(this,Yo,e.anchorNode),v(this,Jl,e.anchorOffset),v(this,Ql,e.focusNode),v(this,Zl,e.focusOffset),y(this,it,dp).call(this),y(this,it,La).call(this),this.rotate(this.rotation))}static get _keyboardManager(){const e=pt.prototype;return ut(this,"_keyboardManager",new Fh([[["ArrowLeft","mac+ArrowLeft"],e._moveCaret,{args:[0]}],[["ArrowRight","mac+ArrowRight"],e._moveCaret,{args:[1]}],[["ArrowUp","mac+ArrowUp"],e._moveCaret,{args:[2]}],[["ArrowDown","mac+ArrowDown"],e._moveCaret,{args:[3]}]]))}get telemetryInitialData(){return{action:"added",type:c(this,es)?"free_highlight":"highlight",color:this._uiManager.highlightColorNames.get(this.color),thickness:c(this,ks),methodOfCreation:c(this,tc)}}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;_t.initialize(e,s),pt._defaultColor||(pt._defaultColor=((i=s.highlightColors)==null?void 0:i.values().next().value)||"#fff066")}static updateDefaultParams(e,s){switch(e){case Z.HIGHLIGHT_DEFAULT_COLOR:pt._defaultColor=s;break;case Z.HIGHLIGHT_THICKNESS:pt._defaultThickness=s;break}}translateInPage(e,s){}get toolbarPosition(){return c(this,qo)}updateParams(e,s){switch(e){case Z.HIGHLIGHT_COLOR:y(this,it,Zb).call(this,s);break;case Z.HIGHLIGHT_THICKNESS:y(this,it,ty).call(this,s);break}}static get defaultPropertiesToUpdate(){return[[Z.HIGHLIGHT_DEFAULT_COLOR,pt._defaultColor],[Z.HIGHLIGHT_THICKNESS,pt._defaultThickness]]}get propertiesToUpdate(){return[[Z.HIGHLIGHT_COLOR,this.color||pt._defaultColor],[Z.HIGHLIGHT_THICKNESS,c(this,ks)||pt._defaultThickness],[Z.HIGHLIGHT_FREE,c(this,es)]]}async addEditToolbar(){const e=await super.addEditToolbar();return e?(this._uiManager.highlightColors&&(v(this,Uo,new Nu({editor:this})),e.addColorPicker(c(this,Uo))),e):null}disableEditing(){super.disableEditing(),this.div.classList.toggle("disabled",!0)}enableEditing(){super.enableEditing(),this.div.classList.toggle("disabled",!1)}fixAndSetPosition(){return super.fixAndSetPosition(y(this,it,mc).call(this))}getBaseTranslation(){return[0,0]}getRect(e,s){return super.getRect(e,s,y(this,it,mc).call(this))}onceAdded(){this.annotationElementId||this.parent.addUndoableEditor(this),this.div.focus()}remove(){y(this,it,gp).call(this),this._reportTelemetry({action:"deleted"}),super.remove()}rebuild(){this.parent&&(super.rebuild(),this.div!==null&&(y(this,it,La).call(this),this.isAttachedToDOM||this.parent.add(this)))}setParent(e){var i;let s=!1;this.parent&&!e?y(this,it,gp).call(this):e&&(y(this,it,La).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,a;const{drawLayer:s}=this.parent;let i;c(this,es)?(e=(e-this.rotation+360)%360,i=y(n=pt,Ms,lh).call(n,c(this,ii).box,e)):i=y(r=pt,Ms,lh).call(r,this,e),s.rotate(c(this,Me),e),s.rotate(c(this,le),e),s.updateBox(c(this,Me),i),s.updateBox(c(this,le),y(a=pt,Ms,lh).call(a,c(this,Es).box,e))}render(){if(this.div)return this.div;const e=super.render();c(this,$o)&&(e.setAttribute("aria-label",c(this,$o)),e.setAttribute("role","mark")),c(this,es)?e.classList.add("free"):this.div.addEventListener("keydown",y(this,it,sy).bind(this),{signal:this._uiManager._signal});const s=v(this,xa,document.createElement("div"));e.append(s),s.setAttribute("aria-hidden","true"),s.className="internal",s.style.clipPath=c(this,wa);const[i,n]=this.parentDimensions;return this.setDims(this.width*i,this.height*n),Mu(this,c(this,xa),["pointerover","pointerleave"]),this.enableEditing(),e}pointerover(){this.isSelected||this.parent.drawLayer.addClass(c(this,le),"hovered")}pointerleave(){this.isSelected||this.parent.drawLayer.removeClass(c(this,le),"hovered")}_moveCaret(e){switch(this.parent.unselect(this),e){case 0:case 2:y(this,it,Ed).call(this,!0);break;case 1:case 3:y(this,it,Ed).call(this,!1);break}}select(){var e,s;super.select(),c(this,le)&&((e=this.parent)==null||e.drawLayer.removeClass(c(this,le),"hovered"),(s=this.parent)==null||s.drawLayer.addClass(c(this,le),"selected"))}unselect(){var e;super.unselect(),c(this,le)&&((e=this.parent)==null||e.drawLayer.removeClass(c(this,le),"selected"),c(this,es)||y(this,it,Ed).call(this,!1))}get _mustFixPosition(){return!c(this,es)}show(e=this._isVisible){super.show(e),this.parent&&(this.parent.drawLayer.show(c(this,Me),e),this.parent.drawLayer.show(c(this,le),e))}static startHighlighting(e,s,{target:i,x:n,y:r}){const{x:a,y:h,width:l,height:u}=i.getBoundingClientRect(),d=new AbortController,g=e.combinedSignal(d),f=m=>{m.preventDefault(),m.stopPropagation()},p=m=>{d.abort(),y(this,Ms,ay).call(this,e,m)};window.addEventListener("blur",p,{signal:g}),window.addEventListener("pointerup",p,{signal:g}),window.addEventListener("pointerdown",f,{capture:!0,passive:!1,signal:g}),window.addEventListener("contextmenu",ws,{signal:g}),i.addEventListener("pointermove",y(this,Ms,ry).bind(this,e),{signal:g}),this._freeHighlight=new vf({x:n,y:r},[a,h,l,u],e.scale,this._defaultThickness/2,s,.001),{id:this._freeHighlightId,clipPathId:this._freeHighlightClipId}=e.drawLayer.draw(this._freeHighlight,this._defaultColor,this._defaultOpacity,!0)}static async deserialize(e,s,i){var m,_,b,x;let n=null;if(e instanceof Mv){const{data:{quadPoints:S,rect:A,rotation:k,id:P,color:M,opacity:O,popupRef:R},parent:{page:{pageNumber:I}}}=e;n=e={annotationType:nt.HIGHLIGHT,color:Array.from(M),opacity:O,quadPoints:S,boxes:null,pageIndex:I-1,rect:A.slice(0),rotation:k,id:P,deleted:!1,popupRef:R}}else if(e instanceof pf){const{data:{inkLists:S,rect:A,rotation:k,id:P,color:M,borderStyle:{rawWidth:O},popupRef:R},parent:{page:{pageNumber:I}}}=e;n=e={annotationType:nt.HIGHLIGHT,color:Array.from(M),thickness:O,inkLists:S,boxes:null,pageIndex:I-1,rect:A.slice(0),rotation:k,id:P,deleted:!1,popupRef:R}}const{color:r,quadPoints:a,inkLists:h,opacity:l}=e,u=await super.deserialize(e,s,i);u.color=U.makeHexColor(...r),v(u,fn,l||1),h&&v(u,ks,e.thickness),u.annotationElementId=e.id||null,u._initialData=n;const[d,g]=u.pageDimensions,[f,p]=u.pageTranslation;if(a){const S=v(u,gn,[]);for(let A=0;A<a.length;A+=8)S.push({x:(a[A]-f)/d,y:1-(a[A+1]-p)/g,width:(a[A+2]-a[A])/d,height:(a[A+1]-a[A+5])/g});y(m=u,it,dp).call(m),y(_=u,it,La).call(_),u.rotate(u.rotation)}else if(h){v(u,es,!0);const S=h[0],A={x:S[0]-f,y:g-(S[1]-p)},k=new vf(A,[0,0,d,g],1,c(u,ks)/2,!0,.001);for(let O=0,R=S.length;O<R;O+=2)A.x=S[O]-f,A.y=g-(S[O+1]-p),k.add(A);const{id:P,clipPathId:M}=s.drawLayer.draw(k,u.color,u._defaultOpacity,!0);y(b=u,it,Td).call(b,{highlightOutlines:k.getOutlines(),highlightId:P,clipPathId:M}),y(x=u,it,La).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=_t._colorManager.convert(this.color),n={annotationType:nt.HIGHLIGHT,color:i,opacity:c(this,fn),thickness:c(this,ks),quadPoints:y(this,it,iy).call(this),outlines:y(this,it,ny).call(this,s),pageIndex:this.pageIndex,rect:s,rotation:y(this,it,mc).call(this),structTreeParentId:this._structTreeParentId};return this.annotationElementId&&!y(this,it,oy).call(this,n)?null:(n.id=this.annotationElementId,n)}renderAnnotationElement(e){return e.updateEdited({rect:this.getRect(0,0)}),null}static canCreateNewEmptyEditor(){return!1}};Yo=new WeakMap,Jl=new WeakMap,gn=new WeakMap,wa=new WeakMap,Uo=new WeakMap,Es=new WeakMap,Ql=new WeakMap,Zl=new WeakMap,xa=new WeakMap,ii=new WeakMap,Me=new WeakMap,es=new WeakMap,qo=new WeakMap,fn=new WeakMap,le=new WeakMap,$o=new WeakMap,ks=new WeakMap,tc=new WeakMap,it=new WeakSet,dp=function(){const e=new Rv(c(this,gn),.001);v(this,ii,e.getOutlines()),{x:this.x,y:this.y,width:this.width,height:this.height}=c(this,ii).box;const s=new Rv(c(this,gn),.0025,.001,this._uiManager.direction==="ltr");v(this,Es,s.getOutlines());const{lastPoint:i}=c(this,Es).box;v(this,qo,[(i[0]-this.x)/this.width,(i[1]-this.y)/this.height])},Td=function({highlightOutlines:e,highlightId:s,clipPathId:i}){var d,g;if(v(this,ii,e),v(this,Es,e.getNewOutline(c(this,ks)/2+1.5,.0025)),s>=0)v(this,Me,s),v(this,wa,i),this.parent.drawLayer.finalizeLine(s,e),v(this,le,this.parent.drawLayer.drawOutline(c(this,Es)));else if(this.parent){const f=this.parent.viewport.rotation;this.parent.drawLayer.updateLine(c(this,Me),e),this.parent.drawLayer.updateBox(c(this,Me),y(d=pt,Ms,lh).call(d,c(this,ii).box,(f-this.rotation+360)%360)),this.parent.drawLayer.updateLine(c(this,le),c(this,Es)),this.parent.drawLayer.updateBox(c(this,le),y(g=pt,Ms,lh).call(g,c(this,Es).box,f))}const{x:r,y:a,width:h,height:l}=e.box;switch(this.rotation){case 0:this.x=r,this.y=a,this.width=h,this.height=l;break;case 90:{const[f,p]=this.parentDimensions;this.x=a,this.y=1-r,this.width=h*p/f,this.height=l*f/p;break}case 180:this.x=1-r,this.y=1-a,this.width=h,this.height=l;break;case 270:{const[f,p]=this.parentDimensions;this.x=1-a,this.y=r,this.width=h*p/f,this.height=l*f/p;break}}const{lastPoint:u}=c(this,Es).box;v(this,qo,[(u[0]-r)/h,(u[1]-a)/l])},Zb=function(e){const s=(r,a)=>{var h,l,u;this.color=r,(h=this.parent)==null||h.drawLayer.changeColor(c(this,Me),r),(l=c(this,Uo))==null||l.updateColor(r),v(this,fn,a),(u=this.parent)==null||u.drawLayer.changeOpacity(c(this,Me),a)},i=this.color,n=c(this,fn);this.addCommands({cmd:s.bind(this,e,pt._defaultOpacity),undo:s.bind(this,i,n),post:this._uiManager.updateUI.bind(this._uiManager,this),mustExec:!0,type:Z.HIGHLIGHT_COLOR,overwriteIfSameType:!0,keepUndo:!0}),this._reportTelemetry({action:"color_changed",color:this._uiManager.highlightColorNames.get(e)},!0)},ty=function(e){const s=c(this,ks),i=n=>{v(this,ks,n),y(this,it,ey).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:Z.INK_THICKNESS,overwriteIfSameType:!0,keepUndo:!0}),this._reportTelemetry({action:"thickness_changed",thickness:e},!0)},ey=function(e){if(!c(this,es))return;y(this,it,Td).call(this,{highlightOutlines:c(this,ii).getNewOutline(e/2)}),this.fixAndSetPosition();const[s,i]=this.parentDimensions;this.setDims(this.width*s,this.height*i)},gp=function(){c(this,Me)===null||!this.parent||(this.parent.drawLayer.remove(c(this,Me)),v(this,Me,null),this.parent.drawLayer.remove(c(this,le)),v(this,le,null))},La=function(e=this.parent){c(this,Me)===null&&({id:Ge(this,Me)._,clipPathId:Ge(this,wa)._}=e.drawLayer.draw(c(this,ii),this.color,c(this,fn)),v(this,le,e.drawLayer.drawOutline(c(this,Es))),c(this,xa)&&(c(this,xa).style.clipPath=c(this,wa)))},Ms=new WeakSet,lh=function({x:e,y:s,width:i,height:n},r){switch(r){case 90:return{x:1-s-n,y:e,width:n,height:i};case 180:return{x:1-e-i,y:1-s-n,width:i,height:n};case 270:return{x:s,y:1-e-i,width:n,height:i}}return{x:e,y:s,width:i,height:n}},sy=function(e){pt._keyboardManager.exec(this,e)},Ed=function(e){if(!c(this,Yo))return;const s=window.getSelection();e?s.setPosition(c(this,Yo),c(this,Jl)):s.setPosition(c(this,Ql),c(this,Zl))},mc=function(){return c(this,es)?this.rotation:0},iy=function(){if(c(this,es))return null;const[e,s]=this.pageDimensions,[i,n]=this.pageTranslation,r=c(this,gn),a=new Float32Array(r.length*8);let h=0;for(const{x:l,y:u,width:d,height:g}of r){const f=l*e+i,p=(1-u-g)*s+n;a[h]=a[h+4]=f,a[h+1]=a[h+3]=p,a[h+2]=a[h+6]=f+d*e,a[h+5]=a[h+7]=p+g*s,h+=8}return a},ny=function(e){return c(this,ii).serialize(e,y(this,it,mc).call(this))},ry=function(e,s){this._freeHighlight.add(s)&&e.drawLayer.updatePath(this._freeHighlightId,this._freeHighlight)},ay=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=""},oy=function(e){const{color:s}=this._initialData;return e.color.some((i,n)=>i!==s[n])},w(pt,Ms),tt(pt,"_defaultColor",null),tt(pt,"_defaultOpacity",1),tt(pt,"_defaultThickness",12),tt(pt,"_type","highlight"),tt(pt,"_editorType",nt.HIGHLIGHT),tt(pt,"_freeHighlightId",-1),tt(pt,"_freeHighlight",null),tt(pt,"_freeHighlightClipId","");let Bu=pt;const Nt=class Nt extends _t{constructor(e){super({...e,name:"inkEditor"});w(this,N);w(this,Sa,0);w(this,Ca,0);w(this,Ti,null);w(this,pn,new Path2D);w(this,Os,!1);w(this,Aa,null);w(this,Ta,!1);w(this,Ea,!1);w(this,mn,null);w(this,Ko,null);w(this,ka,0);w(this,Ma,0);w(this,nr,null);this.color=e.color||null,this.thickness=e.thickness||null,this.opacity=e.opacity||null,this.paths=[],this.bezierPath2D=[],this.allRawPaths=[],this.currentPath=[],this.scaleFactor=1,this.translationX=this.translationY=0,this.x=0,this.y=0,this._willKeepAspectRatio=!0}static initialize(e,s){_t.initialize(e,s)}static updateDefaultParams(e,s){switch(e){case Z.INK_THICKNESS:Nt._defaultThickness=s;break;case Z.INK_COLOR:Nt._defaultColor=s;break;case Z.INK_OPACITY:Nt._defaultOpacity=s/100;break}}updateParams(e,s){switch(e){case Z.INK_THICKNESS:y(this,N,hy).call(this,s);break;case Z.INK_COLOR:y(this,N,ly).call(this,s);break;case Z.INK_OPACITY:y(this,N,cy).call(this,s);break}}static get defaultPropertiesToUpdate(){return[[Z.INK_THICKNESS,Nt._defaultThickness],[Z.INK_COLOR,Nt._defaultColor||_t._defaultLineColor],[Z.INK_OPACITY,Math.round(Nt._defaultOpacity*100)]]}get propertiesToUpdate(){return[[Z.INK_THICKNESS,this.thickness||Nt._defaultThickness],[Z.INK_COLOR,this.color||Nt._defaultColor||_t._defaultLineColor],[Z.INK_OPACITY,Math.round(100*(this.opacity??Nt._defaultOpacity))]]}rebuild(){this.parent&&(super.rebuild(),this.div!==null&&(this.canvas||(y(this,N,kd).call(this),y(this,N,Md).call(this)),this.isAttachedToDOM||(this.parent.add(this),y(this,N,ch).call(this)),y(this,N,vc).call(this)))}remove(){var e;this.canvas!==null&&(this.isEmpty()||this.commit(),this.canvas.width=this.canvas.height=0,this.canvas.remove(),this.canvas=null,c(this,Ti)&&(clearTimeout(c(this,Ti)),v(this,Ti,null)),(e=c(this,mn))==null||e.disconnect(),v(this,mn,null),super.remove())}setParent(e){!this.parent&&e?this._uiManager.removeShouldRescale(this):this.parent&&e===null&&this._uiManager.addShouldRescale(this),super.setParent(e)}onScaleChanging(){const[e,s]=this.parentDimensions,i=this.width*e,n=this.height*s;this.setDimensions(i,n)}enableEditMode(){c(this,Os)||this.canvas===null||(super.enableEditMode(),this._isDraggable=!1,y(this,N,mp).call(this))}disableEditMode(){!this.isInEditMode()||this.canvas===null||(super.disableEditMode(),this._isDraggable=!this.isEmpty(),this.div.classList.remove("editing"),y(this,N,vp).call(this))}onceAdded(){this._isDraggable=!this.isEmpty()}isEmpty(){return this.paths.length===0||this.paths.length===1&&this.paths[0].length===0}commit(){c(this,Os)||(super.commit(),this.isEditing=!1,this.disableEditMode(),this.setInForeground(),v(this,Os,!0),this.div.classList.add("disabled"),y(this,N,vc).call(this,!0),this.select(),this.parent.addInkEditorIfNeeded(!0),this.moveInDOM(),this.div.focus({preventScroll:!0}))}focusin(e){this._focusEventsAllowed&&(super.focusin(e),this.enableEditMode())}canvasPointerdown(e){e.button!==0||!this.isInEditMode()||c(this,Os)||(this.setInForeground(),e.preventDefault(),this.div.contains(document.activeElement)||this.div.focus({preventScroll:!0}),y(this,N,dy).call(this,e.offsetX,e.offsetY))}canvasPointermove(e){e.preventDefault(),y(this,N,pp).call(this,e.offsetX,e.offsetY)}canvasPointerup(e){e.preventDefault(),y(this,N,bp).call(this,e)}canvasPointerleave(e){y(this,N,bp).call(this,e)}get isResizable(){return!this.isEmpty()&&c(this,Os)}render(){if(this.div)return this.div;let e,s;this.width&&(e=this.x,s=this.y),super.render(),this.div.setAttribute("data-l10n-id","pdfjs-ink");const[i,n,r,a]=y(this,N,uy).call(this);if(this.setAt(i,n,0,0),this.setDims(r,a),y(this,N,kd).call(this),this.width){const[h,l]=this.parentDimensions;this.setAspectRatio(this.width*h,this.height*l),this.setAt(e*h,s*l,this.width*h,this.height*l),v(this,Ea,!0),y(this,N,ch).call(this),this.setDims(this.width*h,this.height*l),y(this,N,Ia).call(this),this.div.classList.add("disabled")}else this.div.classList.add("editing"),this.enableEditMode();return y(this,N,Md).call(this),this.div}setDimensions(e,s){const i=Math.round(e),n=Math.round(s);if(c(this,ka)===i&&c(this,Ma)===n)return;v(this,ka,i),v(this,Ma,n),this.canvas.style.visibility="hidden";const[r,a]=this.parentDimensions;this.width=e/r,this.height=s/a,this.fixAndSetPosition(),c(this,Os)&&y(this,N,yp).call(this,e,s),y(this,N,ch).call(this),y(this,N,Ia).call(this),this.canvas.style.visibility="visible",this.fixDims()}static async deserialize(e,s,i){var _,b,x;if(e instanceof pf)return null;const n=await super.deserialize(e,s,i);n.thickness=e.thickness,n.color=U.makeHexColor(...e.color),n.opacity=e.opacity;const[r,a]=n.pageDimensions,h=n.width*r,l=n.height*a,u=n.parentScale,d=e.thickness/2;v(n,Os,!0),v(n,ka,Math.round(h)),v(n,Ma,Math.round(l));const{paths:g,rect:f,rotation:p}=e;for(let{bezier:S}of g){S=y(_=Nt,vn,yy).call(_,S,f,p);const A=[];n.paths.push(A);let k=u*(S[0]-d),P=u*(S[1]-d);for(let O=2,R=S.length;O<R;O+=6){const I=u*(S[O]-d),j=u*(S[O+1]-d),G=u*(S[O+2]-d),L=u*(S[O+3]-d),H=u*(S[O+4]-d),$=u*(S[O+5]-d);A.push([[k,P],[I,j],[G,L],[H,$]]),k=H,P=$}const M=y(this,vn,by).call(this,A);n.bezierPath2D.push(M)}const m=y(b=n,N,wp).call(b);return v(n,Ca,Math.max(_t.MIN_SIZE,m[2]-m[0])),v(n,Sa,Math.max(_t.MIN_SIZE,m[3]-m[1])),y(x=n,N,yp).call(x,h,l),n}serialize(){if(this.isEmpty())return null;const e=this.getRect(0,0),s=_t._colorManager.convert(this.ctx.strokeStyle);return{annotationType:nt.INK,color:s,thickness:this.thickness,opacity:this.opacity,paths:y(this,N,_y).call(this,this.scaleFactor/this.parentScale,this.translationX,this.translationY,e),pageIndex:this.pageIndex,rect:e,rotation:this.rotation,structTreeParentId:this._structTreeParentId}}};Sa=new WeakMap,Ca=new WeakMap,Ti=new WeakMap,pn=new WeakMap,Os=new WeakMap,Aa=new WeakMap,Ta=new WeakMap,Ea=new WeakMap,mn=new WeakMap,Ko=new WeakMap,ka=new WeakMap,Ma=new WeakMap,nr=new WeakMap,N=new WeakSet,hy=function(e){const s=n=>{this.thickness=n,y(this,N,vc).call(this)},i=this.thickness;this.addCommands({cmd:s.bind(this,e),undo:s.bind(this,i),post:this._uiManager.updateUI.bind(this._uiManager,this),mustExec:!0,type:Z.INK_THICKNESS,overwriteIfSameType:!0,keepUndo:!0})},ly=function(e){const s=n=>{this.color=n,y(this,N,Ia).call(this)},i=this.color;this.addCommands({cmd:s.bind(this,e),undo:s.bind(this,i),post:this._uiManager.updateUI.bind(this._uiManager,this),mustExec:!0,type:Z.INK_COLOR,overwriteIfSameType:!0,keepUndo:!0})},cy=function(e){const s=n=>{this.opacity=n,y(this,N,Ia).call(this)};e/=100;const i=this.opacity;this.addCommands({cmd:s.bind(this,e),undo:s.bind(this,i),post:this._uiManager.updateUI.bind(this._uiManager,this),mustExec:!0,type:Z.INK_OPACITY,overwriteIfSameType:!0,keepUndo:!0})},uy=function(){const{parentRotation:e,parentDimensions:[s,i]}=this;switch(e){case 90:return[0,i,i,s];case 180:return[s,i,s,i];case 270:return[s,0,i,s];default:return[0,0,s,i]}},fp=function(){const{ctx:e,color:s,opacity:i,thickness:n,parentScale:r,scaleFactor:a}=this;e.lineWidth=n*r/a,e.lineCap="round",e.lineJoin="round",e.miterLimit=10,e.strokeStyle=`${s}${Hx(i)}`},dy=function(e,s){this.canvas.addEventListener("contextmenu",ws,{signal:this._uiManager._signal}),y(this,N,vp).call(this),v(this,Aa,new AbortController);const i=this._uiManager.combinedSignal(c(this,Aa));this.canvas.addEventListener("pointerleave",this.canvasPointerleave.bind(this),{signal:i}),this.canvas.addEventListener("pointermove",this.canvasPointermove.bind(this),{signal:i}),this.canvas.addEventListener("pointerup",this.canvasPointerup.bind(this),{signal:i}),this.isEditing=!0,c(this,Ea)||(v(this,Ea,!0),y(this,N,ch).call(this),this.thickness||(this.thickness=Nt._defaultThickness),this.color||(this.color=Nt._defaultColor||_t._defaultLineColor),this.opacity??(this.opacity=Nt._defaultOpacity)),this.currentPath.push([e,s]),v(this,Ta,!1),y(this,N,fp).call(this),v(this,nr,()=>{y(this,N,py).call(this),c(this,nr)&&window.requestAnimationFrame(c(this,nr))}),window.requestAnimationFrame(c(this,nr))},pp=function(e,s){const[i,n]=this.currentPath.at(-1);if(this.currentPath.length>1&&e===i&&s===n)return;const r=this.currentPath;let a=c(this,pn);if(r.push([e,s]),v(this,Ta,!0),r.length<=2){a.moveTo(...r[0]),a.lineTo(e,s);return}r.length===3&&(v(this,pn,a=new Path2D),a.moveTo(...r[0])),y(this,N,my).call(this,a,...r.at(-3),...r.at(-2),e,s)},gy=function(){if(this.currentPath.length===0)return;const e=this.currentPath.at(-1);c(this,pn).lineTo(...e)},fy=function(e,s){v(this,nr,null),e=Math.min(Math.max(e,0),this.canvas.width),s=Math.min(Math.max(s,0),this.canvas.height),y(this,N,pp).call(this,e,s),y(this,N,gy).call(this);let i;if(this.currentPath.length!==1)i=y(this,N,vy).call(this);else{const l=[e,s];i=[[l,l.slice(),l.slice(),l]]}const n=c(this,pn),r=this.currentPath;this.currentPath=[],v(this,pn,new Path2D);const a=()=>{this.allRawPaths.push(r),this.paths.push(i),this.bezierPath2D.push(n),this._uiManager.rebuild(this)},h=()=>{this.allRawPaths.pop(),this.paths.pop(),this.bezierPath2D.pop(),this.paths.length===0?this.remove():(this.canvas||(y(this,N,kd).call(this),y(this,N,Md).call(this)),y(this,N,vc).call(this))};this.addCommands({cmd:a,undo:h,mustExec:!0})},py=function(){if(!c(this,Ta))return;v(this,Ta,!1);const e=Math.ceil(this.thickness*this.parentScale),s=this.currentPath.slice(-3),i=s.map(a=>a[0]),n=s.map(a=>a[1]);Math.min(...i)-e,Math.max(...i)+e,Math.min(...n)-e,Math.max(...n)+e;const{ctx:r}=this;r.save(),r.clearRect(0,0,this.canvas.width,this.canvas.height);for(const a of this.bezierPath2D)r.stroke(a);r.stroke(c(this,pn)),r.restore()},my=function(e,s,i,n,r,a,h){const l=(s+n)/2,u=(i+r)/2,d=(n+a)/2,g=(r+h)/2;e.bezierCurveTo(l+2*(n-l)/3,u+2*(r-u)/3,d+2*(n-d)/3,g+2*(r-g)/3,d,g)},vy=function(){const e=this.currentPath;if(e.length<=2)return[[e[0],e[0],e.at(-1),e.at(-1)]];const s=[];let i,[n,r]=e[0];for(i=1;i<e.length-2;i++){const[f,p]=e[i],[m,_]=e[i+1],b=(f+m)/2,x=(p+_)/2,S=[n+2*(f-n)/3,r+2*(p-r)/3],A=[b+2*(f-b)/3,x+2*(p-x)/3];s.push([[n,r],S,A,[b,x]]),[n,r]=[b,x]}const[a,h]=e[i],[l,u]=e[i+1],d=[n+2*(a-n)/3,r+2*(h-r)/3],g=[l+2*(a-l)/3,u+2*(h-u)/3];return s.push([[n,r],d,g,[l,u]]),s},Ia=function(){if(this.isEmpty()){y(this,N,Od).call(this);return}y(this,N,fp).call(this);const{canvas:e,ctx:s}=this;s.setTransform(1,0,0,1,0,0),s.clearRect(0,0,e.width,e.height),y(this,N,Od).call(this);for(const i of this.bezierPath2D)s.stroke(i)},mp=function(){if(c(this,Ko))return;v(this,Ko,new AbortController);const e=this._uiManager.combinedSignal(c(this,Ko));this.canvas.addEventListener("pointerdown",this.canvasPointerdown.bind(this),{signal:e})},vp=function(){var e;(e=this.pointerdownAC)==null||e.abort(),this.pointerdownAC=null},bp=function(e){var s;(s=c(this,Aa))==null||s.abort(),v(this,Aa,null),y(this,N,mp).call(this),c(this,Ti)&&clearTimeout(c(this,Ti)),v(this,Ti,setTimeout(()=>{v(this,Ti,null),this.canvas.removeEventListener("contextmenu",ws)},10)),y(this,N,fy).call(this,e.offsetX,e.offsetY),this.addToAnnotationStorage(),this.setInBackground()},kd=function(){this.canvas=document.createElement("canvas"),this.canvas.width=this.canvas.height=0,this.canvas.className="inkEditorCanvas",this.canvas.setAttribute("data-l10n-id","pdfjs-ink-canvas"),this.div.append(this.canvas),this.ctx=this.canvas.getContext("2d")},Md=function(){v(this,mn,new ResizeObserver(e=>{const s=e[0].contentRect;s.width&&s.height&&this.setDimensions(s.width,s.height)})),c(this,mn).observe(this.div),this._uiManager._signal.addEventListener("abort",()=>{var e;(e=c(this,mn))==null||e.disconnect(),v(this,mn,null)},{once:!0})},ch=function(){if(!c(this,Ea))return;const[e,s]=this.parentDimensions;this.canvas.width=Math.ceil(this.width*e),this.canvas.height=Math.ceil(this.height*s),y(this,N,Od).call(this)},yp=function(e,s){const i=y(this,N,Pd).call(this),n=(e-i)/c(this,Ca),r=(s-i)/c(this,Sa);this.scaleFactor=Math.min(n,r)},Od=function(){const e=y(this,N,Pd).call(this)/2;this.ctx.setTransform(this.scaleFactor,0,0,this.scaleFactor,this.translationX*this.scaleFactor+e,this.translationY*this.scaleFactor+e)},vn=new WeakSet,by=function(e){const s=new Path2D;for(let i=0,n=e.length;i<n;i++){const[r,a,h,l]=e[i];i===0&&s.moveTo(...r),s.bezierCurveTo(a[0],a[1],h[0],h[1],l[0],l[1])}return s},_p=function(e,s,i){const[n,r,a,h]=s;switch(i){case 0:for(let l=0,u=e.length;l<u;l+=2)e[l]+=n,e[l+1]=h-e[l+1];break;case 90:for(let l=0,u=e.length;l<u;l+=2){const d=e[l];e[l]=e[l+1]+n,e[l+1]=d+r}break;case 180:for(let l=0,u=e.length;l<u;l+=2)e[l]=a-e[l],e[l+1]+=r;break;case 270:for(let l=0,u=e.length;l<u;l+=2){const d=e[l];e[l]=a-e[l+1],e[l+1]=h-d}break;default:throw new Error("Invalid rotation")}return e},yy=function(e,s,i){const[n,r,a,h]=s;switch(i){case 0:for(let l=0,u=e.length;l<u;l+=2)e[l]-=n,e[l+1]=h-e[l+1];break;case 90:for(let l=0,u=e.length;l<u;l+=2){const d=e[l];e[l]=e[l+1]-r,e[l+1]=d-n}break;case 180:for(let l=0,u=e.length;l<u;l+=2)e[l]=a-e[l],e[l+1]-=r;break;case 270:for(let l=0,u=e.length;l<u;l+=2){const d=e[l];e[l]=h-e[l+1],e[l+1]=a-d}break;default:throw new Error("Invalid rotation")}return e},_y=function(e,s,i,n){var u,d;const r=[],a=this.thickness/2,h=e*s+a,l=e*i+a;for(const g of this.paths){const f=[],p=[];for(let m=0,_=g.length;m<_;m++){const[b,x,S,A]=g[m];if(b[0]===A[0]&&b[1]===A[1]&&_===1){const L=e*b[0]+h,H=e*b[1]+l;f.push(L,H),p.push(L,H);break}const k=e*b[0]+h,P=e*b[1]+l,M=e*x[0]+h,O=e*x[1]+l,R=e*S[0]+h,I=e*S[1]+l,j=e*A[0]+h,G=e*A[1]+l;m===0&&(f.push(k,P),p.push(k,P)),f.push(M,O,R,I,j,G),p.push(M,O),m===_-1&&p.push(j,G)}r.push({bezier:y(u=Nt,vn,_p).call(u,f,n,this.rotation),points:y(d=Nt,vn,_p).call(d,p,n,this.rotation)})}return r},wp=function(){let e=1/0,s=-1/0,i=1/0,n=-1/0;for(const r of this.paths)for(const[a,h,l,u]of r){const d=U.bezierBoundingBox(...a,...h,...l,...u);e=Math.min(e,d[0]),i=Math.min(i,d[1]),s=Math.max(s,d[2]),n=Math.max(n,d[3])}return[e,i,s,n]},Pd=function(){return c(this,Os)?Math.ceil(this.thickness*this.parentScale):0},vc=function(e=!1){if(this.isEmpty())return;if(!c(this,Os)){y(this,N,Ia).call(this);return}const s=y(this,N,wp).call(this),i=y(this,N,Pd).call(this);v(this,Ca,Math.max(_t.MIN_SIZE,s[2]-s[0])),v(this,Sa,Math.max(_t.MIN_SIZE,s[3]-s[1]));const n=Math.ceil(i+c(this,Ca)*this.scaleFactor),r=Math.ceil(i+c(this,Sa)*this.scaleFactor),[a,h]=this.parentDimensions;this.width=n/a,this.height=r/h,this.setAspectRatio(n,r);const l=this.translationX,u=this.translationY;this.translationX=-s[0],this.translationY=-s[1],y(this,N,ch).call(this),y(this,N,Ia).call(this),v(this,ka,n),v(this,Ma,r),this.setDims(n,r);const d=e?i/this.scaleFactor/2:0;this.translate(l-this.translationX-d,u-this.translationY-d)},w(Nt,vn),tt(Nt,"_defaultColor",null),tt(Nt,"_defaultOpacity",1),tt(Nt,"_defaultThickness",1),tt(Nt,"_type","ink"),tt(Nt,"_editorType",nt.INK);let bf=Nt;const ec=class ec extends _t{constructor(e){super({...e,name:"stampEditor"});w(this,ht);w(this,Bt,null);w(this,ve,null);w(this,rr,null);w(this,bn,null);w(this,ar,null);w(this,Jo,"");w(this,Ei,null);w(this,yn,null);w(this,ki,null);w(this,ps,!1);w(this,Qo,!1);v(this,bn,e.bitmapUrl),v(this,ar,e.bitmapFile)}static initialize(e,s){_t.initialize(e,s)}static get supportedTypes(){return ut(this,"supportedTypes",["apng","avif","bmp","gif","jpeg","png","svg+xml","webp","x-icon"].map(s=>`image/${s}`))}static get supportedTypesStr(){return ut(this,"supportedTypesStr",this.supportedTypes.join(","))}static isHandlingMimeForPasting(e){return this.supportedTypes.includes(e)}static paste(e,s){s.pasteEditor(nt.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:a}=e||this.copyCanvas(null,null,!0).imageData,h=await i.guess({name:"altText",request:{data:n,width:r,height:a,channels:n.length/(r*a)}});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 l=h.output;return await this.setGuessedAltText(l),s&&!this.hasAltTextData()&&(this.altTextData={alt:l,decorative:!1}),l}remove(){var e,s;c(this,ve)&&(v(this,Bt,null),this._uiManager.imageManager.deleteId(c(this,ve)),(e=c(this,Ei))==null||e.remove(),v(this,Ei,null),(s=c(this,yn))==null||s.disconnect(),v(this,yn,null),c(this,ki)&&(clearTimeout(c(this,ki)),v(this,ki,null))),super.remove()}rebuild(){if(!this.parent){c(this,ve)&&y(this,ht,Dd).call(this);return}super.rebuild(),this.div!==null&&(c(this,ve)&&c(this,Ei)===null&&y(this,ht,Dd).call(this),this.isAttachedToDOM||this.parent.add(this))}onceAdded(){this._isDraggable=!0,this.div.focus()}isEmpty(){return!(c(this,rr)||c(this,Bt)||c(this,bn)||c(this,ar)||c(this,ve))}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(),c(this,Bt)?y(this,ht,xp).call(this):y(this,ht,Dd).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.div}copyCanvas(e,s,i=!1){var f;e||(e=224);const{width:n,height:r}=c(this,Bt),a=new qg;let h=c(this,Bt),l=n,u=r,d=null;if(s){if(n>s||r>s){const O=Math.min(s/n,s/r);l=Math.floor(n*O),u=Math.floor(r*O)}d=document.createElement("canvas");const p=d.width=Math.ceil(l*a.sx),m=d.height=Math.ceil(u*a.sy);c(this,ps)||(h=y(this,ht,Rd).call(this,p,m));const _=d.getContext("2d");_.filter=this._uiManager.hcmFilter;let b="white",x="#cfcfd8";this._uiManager.hcmFilter!=="none"?x="black":(f=window.matchMedia)!=null&&f.call(window,"(prefers-color-scheme: dark)").matches&&(b="#8f8f9d",x="#42414d");const S=15,A=S*a.sx,k=S*a.sy,P=new OffscreenCanvas(A*2,k*2),M=P.getContext("2d");M.fillStyle=b,M.fillRect(0,0,A*2,k*2),M.fillStyle=x,M.fillRect(0,0,A,k),M.fillRect(A,k,A,k),_.fillStyle=_.createPattern(P,"repeat"),_.fillRect(0,0,p,m),_.drawImage(h,0,0,h.width,h.height,0,0,p,m)}let g=null;if(i){let p,m;if(a.symmetric&&h.width<e&&h.height<e)p=h.width,m=h.height;else if(h=c(this,Bt),n>e||r>e){const x=Math.min(e/n,e/r);p=Math.floor(n*x),m=Math.floor(r*x),c(this,ps)||(h=y(this,ht,Rd).call(this,p,m))}const b=new OffscreenCanvas(p,m).getContext("2d",{willReadFrequently:!0});b.drawImage(h,0,0,h.width,h.height,0,0,p,m),g={width:p,height:m,data:b.getImageData(0,0,p,m).data}}return{canvas:d,width:l,height:u,imageData:g}}getImageForAltText(){return c(this,Ei)}static async deserialize(e,s,i){var m;let n=null;if(e instanceof Ov){const{data:{rect:_,rotation:b,id:x,structParent:S,popupRef:A},container:k,parent:{page:{pageNumber:P}}}=e,M=k.querySelector("canvas"),O=i.imageManager.getFromCanvas(k.id,M);M.remove();const R=((m=await s._structTree.getAriaAttributes(`${zg}${x}`))==null?void 0:m.get("aria-label"))||"";n=e={annotationType:nt.STAMP,bitmapId:O.id,bitmap:O.bitmap,pageIndex:P-1,rect:_.slice(0),rotation:b,id:x,deleted:!1,accessibilityData:{decorative:!1,altText:R},isSvg:!1,structParent:S,popupRef:A}}const r=await super.deserialize(e,s,i),{rect:a,bitmap:h,bitmapUrl:l,bitmapId:u,isSvg:d,accessibilityData:g}=e;u&&i.imageManager.isValidId(u)?(v(r,ve,u),h&&v(r,Bt,h)):v(r,bn,l),v(r,ps,d);const[f,p]=r.pageDimensions;return r.width=(a[2]-a[0])/f,r.height=(a[3]-a[1])/p,r.annotationElementId=e.id||null,g&&(r.altTextData=g),r._initialData=n,v(r,Qo,!!n),r}serialize(e=!1,s=null){if(this.isEmpty())return null;if(this.deleted)return this.serializeDeleted();const i={annotationType:nt.STAMP,bitmapId:c(this,ve),pageIndex:this.pageIndex,rect:this.getRect(0,0),rotation:this.rotation,isSvg:c(this,ps),structTreeParentId:this._structTreeParentId};if(e)return i.bitmapUrl=y(this,ht,Fd).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=y(this,ht,Sy).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 a=c(this,ps)?(i.rect[2]-i.rect[0])*(i.rect[3]-i.rect[1]):null;if(!s.stamps.has(c(this,ve)))s.stamps.set(c(this,ve),{area:a,serialized:i}),i.bitmap=y(this,ht,Fd).call(this,!1);else if(c(this,ps)){const h=s.stamps.get(c(this,ve));a>h.area&&(h.area=a,h.serialized.bitmap.close(),h.serialized.bitmap=y(this,ht,Fd).call(this,!1))}return i}renderAnnotationElement(e){return e.updateEdited({rect:this.getRect(0,0)}),null}};Bt=new WeakMap,ve=new WeakMap,rr=new WeakMap,bn=new WeakMap,ar=new WeakMap,Jo=new WeakMap,Ei=new WeakMap,yn=new WeakMap,ki=new WeakMap,ps=new WeakMap,Qo=new WeakMap,ht=new WeakSet,bc=function(e,s=!1){if(!e){this.remove();return}v(this,Bt,e.bitmap),s||(v(this,ve,e.id),v(this,ps,e.isSvg)),e.file&&v(this,Jo,e.file.name),y(this,ht,xp).call(this)},yc=function(){if(v(this,rr,null),this._uiManager.enableWaiting(!1),!!c(this,Ei)){if(this._uiManager.useNewAltTextWhenAddingImage&&this._uiManager.useNewAltTextFlow&&c(this,Bt)){this._editToolbar.hide(),this._uiManager.editAltText(this,!0);return}if(!this._uiManager.useNewAltTextWhenAddingImage&&this._uiManager.useNewAltTextFlow&&c(this,Bt)){this._reportTelemetry({action:"pdfjs.image.image_added",data:{alt_text_modal:!1,alt_text_type:"empty"}});try{this.mlGuessAltText()}catch{}}this.div.focus()}},Dd=function(){if(c(this,ve)){this._uiManager.enableWaiting(!0),this._uiManager.imageManager.getFromId(c(this,ve)).then(i=>y(this,ht,bc).call(this,i,!0)).finally(()=>y(this,ht,yc).call(this));return}if(c(this,bn)){const i=c(this,bn);v(this,bn,null),this._uiManager.enableWaiting(!0),v(this,rr,this._uiManager.imageManager.getFromUrl(i).then(n=>y(this,ht,bc).call(this,n)).finally(()=>y(this,ht,yc).call(this)));return}if(c(this,ar)){const i=c(this,ar);v(this,ar,null),this._uiManager.enableWaiting(!0),v(this,rr,this._uiManager.imageManager.getFromFile(i).then(n=>y(this,ht,bc).call(this,n)).finally(()=>y(this,ht,yc).call(this)));return}const e=document.createElement("input");e.type="file",e.accept=ec.supportedTypesStr;const s=this._uiManager._signal;v(this,rr,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}}),y(this,ht,bc).call(this,n)}i()},{signal:s}),e.addEventListener("cancel",()=>{this.remove(),i()},{signal:s})}).finally(()=>y(this,ht,yc).call(this))),e.click()},xp=function(){const{div:e}=this;let{width:s,height:i}=c(this,Bt);const[n,r]=this.pageDimensions,a=.75;if(this.width)s=this.width*n,i=this.height*r;else if(s>a*n||i>a*r){const d=Math.min(a*n/s,a*r/i);s*=d,i*=d}const[h,l]=this.parentDimensions;this.setDims(s*h/n,i*l/r),this._uiManager.enableWaiting(!1);const u=v(this,Ei,document.createElement("canvas"));u.setAttribute("role","img"),this.addContainer(u),(!this._uiManager.useNewAltTextWhenAddingImage||!this._uiManager.useNewAltTextFlow||this.annotationElementId)&&(e.hidden=!1),y(this,ht,Sp).call(this,s,i),y(this,ht,xy).call(this),c(this,Qo)||(this.parent.addUndoableEditor(this),v(this,Qo,!0)),this._reportTelemetry({action:"inserted_image"}),c(this,Jo)&&u.setAttribute("aria-label",c(this,Jo))},wy=function(e,s){var a;const[i,n]=this.parentDimensions;this.width=e/i,this.height=s/n,(a=this._initialOptions)!=null&&a.isCentered?this.center():this.fixAndSetPosition(),this._initialOptions=null,c(this,ki)!==null&&clearTimeout(c(this,ki)),v(this,ki,setTimeout(()=>{v(this,ki,null),y(this,ht,Sp).call(this,e,s)},200))},Rd=function(e,s){const{width:i,height:n}=c(this,Bt);let r=i,a=n,h=c(this,Bt);for(;r>2*e||a>2*s;){const l=r,u=a;r>2*e&&(r=r>=16384?Math.floor(r/2)-1:Math.ceil(r/2)),a>2*s&&(a=a>=16384?Math.floor(a/2)-1:Math.ceil(a/2));const d=new OffscreenCanvas(r,a);d.getContext("2d").drawImage(h,0,0,l,u,0,0,r,a),h=d.transferToImageBitmap()}return h},Sp=function(e,s){const i=new qg,n=Math.ceil(e*i.sx),r=Math.ceil(s*i.sy),a=c(this,Ei);if(!a||a.width===n&&a.height===r)return;a.width=n,a.height=r;const h=c(this,ps)?c(this,Bt):y(this,ht,Rd).call(this,n,r),l=a.getContext("2d");l.filter=this._uiManager.hcmFilter,l.drawImage(h,0,0,h.width,h.height,0,0,n,r)},Fd=function(e){if(e){if(c(this,ps)){const n=this._uiManager.imageManager.getSvgUrl(c(this,ve));if(n)return n}const s=document.createElement("canvas");return{width:s.width,height:s.height}=c(this,Bt),s.getContext("2d").drawImage(c(this,Bt),0,0),s.toDataURL()}if(c(this,ps)){const[s,i]=this.pageDimensions,n=Math.round(this.width*s*Rn.PDF_TO_CSS_UNITS),r=Math.round(this.height*i*Rn.PDF_TO_CSS_UNITS),a=new OffscreenCanvas(n,r);return a.getContext("2d").drawImage(c(this,Bt),0,0,c(this,Bt).width,c(this,Bt).height,0,0,n,r),a.transferToImageBitmap()}return structuredClone(c(this,Bt))},xy=function(){this._uiManager._signal&&(v(this,yn,new ResizeObserver(e=>{const s=e[0].contentRect;s.width&&s.height&&y(this,ht,wy).call(this,s.width,s.height)})),c(this,yn).observe(this.div),this._uiManager._signal.addEventListener("abort",()=>{var e;(e=c(this,yn))==null||e.disconnect(),v(this,yn,null)},{once:!0}))},Sy=function(e){var l;const{rect:s,pageIndex:i,accessibilityData:{altText:n}}=this._initialData,r=e.rect.every((u,d)=>Math.abs(u-s[d])<1),a=e.pageIndex===i,h=(((l=e.accessibilityData)==null?void 0:l.alt)||"")===n;return{isSame:r&&a&&h,isSameAltText:h}},tt(ec,"_type","stamp"),tt(ec,"_editorType",nt.STAMP);let yf=ec;const ni=class ni{constructor({uiManager:t,pageIndex:e,div:s,structTreeLayer:i,accessibilityManager:n,annotationLayer:r,drawLayer:a,textLayer:h,viewport:l,l10n:u}){w(this,be);w(this,Oa);w(this,Zo,!1);w(this,Mi,null);w(this,or,null);w(this,_n,null);w(this,ms,new Map);w(this,hr,!1);w(this,th,!1);w(this,eh,!1);w(this,Oe,null);w(this,wn,null);w(this,q);const d=[...c(ni,lr).values()];if(!ni._initialized){ni._initialized=!0;for(const g of d)g.initialize(u,t)}t.registerEditorTypes(d),v(this,q,t),this.pageIndex=e,this.div=s,v(this,Oa,n),v(this,Mi,r),this.viewport=l,v(this,Oe,h),this.drawLayer=a,this._structTree=i,c(this,q).addLayer(this)}get isEmpty(){return c(this,ms).size===0}get isInvisible(){return this.isEmpty&&c(this,q).getMode()===nt.NONE}updateToolbar(t){c(this,q).updateToolbar(t)}updateMode(t=c(this,q).getMode()){switch(y(this,be,Ld).call(this),t){case nt.NONE:this.disableTextSelection(),this.togglePointerEvents(!1),this.toggleAnnotationLayerPointerEvents(!0),this.disableClick();return;case nt.INK:this.addInkEditorIfNeeded(!1),this.disableTextSelection(),this.togglePointerEvents(!0),this.disableClick();break;case nt.HIGHLIGHT:this.enableTextSelection(),this.togglePointerEvents(!1),this.disableClick();break;default:this.disableTextSelection(),this.togglePointerEvents(!0),this.enableClick()}this.toggleAnnotationLayerPointerEvents(!1);const{classList:e}=this.div;for(const s of c(ni,lr).values())e.toggle(`${s._type}Editing`,t===s._editorType);this.div.hidden=!1}hasTextLayer(t){var e;return t===((e=c(this,Oe))==null?void 0:e.div)}addInkEditorIfNeeded(t){if(c(this,q).getMode()!==nt.INK)return;if(!t){for(const s of c(this,ms).values())if(s.isEmpty()){s.setInBackground();return}}this.createAndAddNewEditor({offsetX:0,offsetY:0},!1).setInBackground()}setEditingState(t){c(this,q).setEditingState(t)}addCommands(t){c(this,q).addCommands(t)}toggleDrawing(t=!1){this.div.classList.toggle("drawing",!t)}togglePointerEvents(t=!1){this.div.classList.toggle("disabled",!t)}toggleAnnotationLayerPointerEvents(t=!1){var e;(e=c(this,Mi))==null||e.div.classList.toggle("disabled",!t)}async enable(){this.div.tabIndex=0,this.togglePointerEvents(!0);const t=new Set;for(const s of c(this,ms).values())s.enableEditing(),s.show(!0),s.annotationElementId&&(c(this,q).removeChangedExistingAnnotation(s),t.add(s.annotationElementId));if(!c(this,Mi))return;const e=c(this,Mi).getEditableAnnotations();for(const s of e){if(s.hide(),c(this,q).isDeletedAnnotationElement(s.data.id)||t.has(s.data.id))continue;const i=await this.deserialize(s);i&&(this.addOrRebuild(i),i.enableEditing())}}disable(){var i;v(this,eh,!0),this.div.tabIndex=-1,this.togglePointerEvents(!1);const t=new Map,e=new Map;for(const n of c(this,ms).values())if(n.disableEditing(),!!n.annotationElementId){if(n.serialize()!==null){t.set(n.annotationElementId,n);continue}else e.set(n.annotationElementId,n);(i=this.getEditableAnnotation(n.annotationElementId))==null||i.show(),n.remove()}if(c(this,Mi)){const n=c(this,Mi).getEditableAnnotations();for(const r of n){const{id:a}=r.data;if(c(this,q).isDeletedAnnotationElement(a))continue;let h=e.get(a);if(h){h.resetAnnotationElement(r),h.show(!1),r.show();continue}h=t.get(a),h&&(c(this,q).addChangedExistingAnnotation(h),h.renderAnnotationElement(r)&&h.show(!1)),r.show()}}y(this,be,Ld).call(this),this.isEmpty&&(this.div.hidden=!0);const{classList:s}=this.div;for(const n of c(ni,lr).values())s.remove(`${n._type}Editing`);this.disableTextSelection(),this.toggleAnnotationLayerPointerEvents(!0),v(this,eh,!1)}getEditableAnnotation(t){var e;return((e=c(this,Mi))==null?void 0:e.getEditableAnnotation(t))||null}setActiveEditor(t){c(this,q).getActive()!==t&&c(this,q).setActiveEditor(t)}enableTextSelection(){var t;if(this.div.tabIndex=-1,(t=c(this,Oe))!=null&&t.div&&!c(this,wn)){v(this,wn,new AbortController);const e=c(this,q).combinedSignal(c(this,wn));c(this,Oe).div.addEventListener("pointerdown",y(this,be,Cy).bind(this),{signal:e}),c(this,Oe).div.classList.add("highlighting")}}disableTextSelection(){var t;this.div.tabIndex=0,(t=c(this,Oe))!=null&&t.div&&c(this,wn)&&(c(this,wn).abort(),v(this,wn,null),c(this,Oe).div.classList.remove("highlighting"))}enableClick(){if(c(this,or))return;v(this,or,new AbortController);const t=c(this,q).combinedSignal(c(this,or));this.div.addEventListener("pointerdown",this.pointerdown.bind(this),{signal:t}),this.div.addEventListener("pointerup",this.pointerup.bind(this),{signal:t})}disableClick(){var t;(t=c(this,or))==null||t.abort(),v(this,or,null)}attach(t){c(this,ms).set(t.id,t);const{annotationElementId:e}=t;e&&c(this,q).isDeletedAnnotationElement(e)&&c(this,q).removeDeletedAnnotationElement(t)}detach(t){var e;c(this,ms).delete(t.id),(e=c(this,Oa))==null||e.removePointerInTextLayer(t.contentDiv),!c(this,eh)&&t.annotationElementId&&c(this,q).addDeletedAnnotationElement(t)}remove(t){this.detach(t),c(this,q).removeEditor(t),t.div.remove(),t.isAttachedToDOM=!1,c(this,th)||this.addInkEditorIfNeeded(!1)}changeParent(t){var e;t.parent!==this&&(t.parent&&t.annotationElementId&&(c(this,q).addDeletedAnnotationElement(t.annotationElementId),_t.deleteAnnotationElement(t),t.annotationElementId=null),this.attach(t),(e=t.parent)==null||e.detach(t),t.setParent(this),t.div&&t.isAttachedToDOM&&(t.div.remove(),this.div.append(t.div)))}add(t){if(!(t.parent===this&&t.isAttachedToDOM)){if(this.changeParent(t),c(this,q).addEditor(t),this.attach(t),!t.isAttachedToDOM){const e=t.render();this.div.append(e),t.isAttachedToDOM=!0}t.fixAndSetPosition(),t.onceAdded(),c(this,q).addToAnnotationStorage(t),t._reportTelemetry(t.telemetryInitialData)}}moveEditorInDOM(t){var s;if(!t.isAttachedToDOM)return;const{activeElement:e}=document;t.div.contains(e)&&!c(this,_n)&&(t._focusEventsAllowed=!1,v(this,_n,setTimeout(()=>{v(this,_n,null),t.div.contains(document.activeElement)?t._focusEventsAllowed=!0:(t.div.addEventListener("focusin",()=>{t._focusEventsAllowed=!0},{once:!0,signal:c(this,q)._signal}),e.focus())},0))),t._structTreeParentId=(s=c(this,Oa))==null?void 0:s.moveElementInDOM(this.div,t.div,t.contentDiv,!0)}addOrRebuild(t){t.needsToBeRebuilt()?(t.parent||(t.parent=this),t.rebuild(),t.show()):this.add(t)}addUndoableEditor(t){const e=()=>t._uiManager.rebuild(t),s=()=>{t.remove()};this.addCommands({cmd:e,undo:s,mustExec:!1})}getNextId(){return c(this,q).getId()}combinedSignal(t){return c(this,q).combinedSignal(t)}canCreateNewEmptyEditor(){var t;return(t=c(this,be,Cp))==null?void 0:t.canCreateNewEmptyEditor()}pasteEditor(t,e){c(this,q).updateToolbar(t),c(this,q).updateMode(t);const{offsetX:s,offsetY:i}=y(this,be,Tp).call(this),n=this.getNextId(),r=y(this,be,Ap).call(this,{parent:this,id:n,x:s,y:i,uiManager:c(this,q),isCentered:!0,...e});r&&this.add(r)}async deserialize(t){var e;return await((e=c(ni,lr).get(t.annotationType??t.annotationEditorType))==null?void 0:e.deserialize(t,this,c(this,q)))||null}createAndAddNewEditor(t,e,s={}){const i=this.getNextId(),n=y(this,be,Ap).call(this,{parent:this,id:i,x:t.offsetX,y:t.offsetY,uiManager:c(this,q),isCentered:e,...s});return n&&this.add(n),n}addNewEditor(){this.createAndAddNewEditor(y(this,be,Tp).call(this),!0)}setSelected(t){c(this,q).setSelected(t)}toggleSelected(t){c(this,q).toggleSelected(t)}unselect(t){c(this,q).unselect(t)}pointerup(t){const{isMac:e}=Ne.platform;if(!(t.button!==0||t.ctrlKey&&e)&&t.target===this.div&&c(this,hr)){if(v(this,hr,!1),!c(this,Zo)){v(this,Zo,!0);return}if(c(this,q).getMode()===nt.STAMP){c(this,q).unselectAll();return}this.createAndAddNewEditor(t,!1)}}pointerdown(t){if(c(this,q).getMode()===nt.HIGHLIGHT&&this.enableTextSelection(),c(this,hr)){v(this,hr,!1);return}const{isMac:e}=Ne.platform;if(t.button!==0||t.ctrlKey&&e||t.target!==this.div)return;v(this,hr,!0);const s=c(this,q).getActive();v(this,Zo,!s||s.isEmpty())}findNewParent(t,e,s){const i=c(this,q).findParent(e,s);return i===null||i===this?!1:(i.changeParent(t),!0)}destroy(){var t,e;((t=c(this,q).getActive())==null?void 0:t.parent)===this&&(c(this,q).commitOrRemove(),c(this,q).setActiveEditor(null)),c(this,_n)&&(clearTimeout(c(this,_n)),v(this,_n,null));for(const s of c(this,ms).values())(e=c(this,Oa))==null||e.removePointerInTextLayer(s.contentDiv),s.setParent(null),s.isAttachedToDOM=!1,s.div.remove();this.div=null,c(this,ms).clear(),c(this,q).removeLayer(this)}render({viewport:t}){this.viewport=t,kr(this.div,t);for(const e of c(this,q).getEditors(this.pageIndex))this.add(e),e.rebuild();this.updateMode()}update({viewport:t}){c(this,q).commitOrRemove(),y(this,be,Ld).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 c(this,ms).values())i.rotate(s);this.addInkEditorIfNeeded(!1)}get pageDimensions(){const{pageWidth:t,pageHeight:e}=this.viewport.rawDims;return[t,e]}get scale(){return c(this,q).viewParameters.realScale}};Oa=new WeakMap,Zo=new WeakMap,Mi=new WeakMap,or=new WeakMap,_n=new WeakMap,ms=new WeakMap,hr=new WeakMap,th=new WeakMap,eh=new WeakMap,Oe=new WeakMap,wn=new WeakMap,q=new WeakMap,lr=new WeakMap,be=new WeakSet,Cy=function(t){c(this,q).unselectAll();const{target:e}=t;if(e===c(this,Oe).div||(e.getAttribute("role")==="img"||e.classList.contains("endOfContent"))&&c(this,Oe).div.contains(e)){const{isMac:s}=Ne.platform;if(t.button!==0||t.ctrlKey&&s)return;c(this,q).showAllEditors("highlight",!0,!0),c(this,Oe).div.classList.add("free"),this.toggleDrawing(),Bu.startHighlighting(this,c(this,q).direction==="ltr",{target:c(this,Oe).div,x:t.x,y:t.y}),c(this,Oe).div.addEventListener("pointerup",()=>{c(this,Oe).div.classList.remove("free"),this.toggleDrawing(!0)},{once:!0,signal:c(this,q)._signal}),t.preventDefault()}},Cp=function(){return c(ni,lr).get(c(this,q).getMode())},Ap=function(t){const e=c(this,be,Cp);return e?new e.prototype.constructor(t):null},Tp=function(){const{x:t,y:e,width:s,height:i}=this.div.getBoundingClientRect(),n=Math.max(0,t),r=Math.max(0,e),a=Math.min(window.innerWidth,t+s),h=Math.min(window.innerHeight,e+i),l=(n+a)/2-t,u=(r+h)/2-e,[d,g]=this.viewport.rotation%180===0?[l,u]:[u,l];return{offsetX:d,offsetY:g}},Ld=function(){v(this,th,!0);for(const t of c(this,ms).values())t.isEmpty()&&t.remove();v(this,th,!1)},tt(ni,"_initialized",!1),w(ni,lr,new Map([mf,bf,yf,Bu].map(t=>[t._editorType,t])));let _f=ni;const ye=class ye{constructor({pageIndex:t}){w(this,Pa);w(this,Oi,null);w(this,sc,0);w(this,Zt,new Map);w(this,xn,new Map);this.pageIndex=t}setParent(t){if(!c(this,Oi)){v(this,Oi,t);return}if(c(this,Oi)!==t){if(c(this,Zt).size>0)for(const e of c(this,Zt).values())e.remove(),t.append(e);v(this,Oi,t)}}static get _svgFactory(){return ut(this,"_svgFactory",new gf)}draw(t,e,s,i=!1){const n=Ge(this,sc)._++,r=y(this,Pa,kp).call(this,t.box);r.classList.add(...t.classNamesForDrawing);const a=ye._svgFactory.createElement("defs");r.append(a);const h=ye._svgFactory.createElement("path");a.append(h);const l=`path_p${this.pageIndex}_${n}`;h.setAttribute("id",l),h.setAttribute("d",t.toSVGPath()),i&&c(this,xn).set(n,h);const u=y(this,Pa,Ay).call(this,a,l),d=ye._svgFactory.createElement("use");return r.append(d),r.setAttribute("fill",e),r.setAttribute("fill-opacity",s),d.setAttribute("href",`#${l}`),c(this,Zt).set(n,r),{id:n,clipPathId:`url(#${u})`}}drawOutline(t){const e=Ge(this,sc)._++,s=y(this,Pa,kp).call(this,t.box);s.classList.add(...t.classNamesForOutlining);const i=ye._svgFactory.createElement("defs");s.append(i);const n=ye._svgFactory.createElement("path");i.append(n);const r=`path_p${this.pageIndex}_${e}`;n.setAttribute("id",r),n.setAttribute("d",t.toSVGPath()),n.setAttribute("vector-effect","non-scaling-stroke");let a;if(t.mustRemoveSelfIntersections){const u=ye._svgFactory.createElement("mask");i.append(u),a=`mask_p${this.pageIndex}_${e}`,u.setAttribute("id",a),u.setAttribute("maskUnits","objectBoundingBox");const d=ye._svgFactory.createElement("rect");u.append(d),d.setAttribute("width","1"),d.setAttribute("height","1"),d.setAttribute("fill","white");const g=ye._svgFactory.createElement("use");u.append(g),g.setAttribute("href",`#${r}`),g.setAttribute("stroke","none"),g.setAttribute("fill","black"),g.setAttribute("fill-rule","nonzero"),g.classList.add("mask")}const h=ye._svgFactory.createElement("use");s.append(h),h.setAttribute("href",`#${r}`),a&&h.setAttribute("mask",`url(#${a})`);const l=h.cloneNode();return s.append(l),h.classList.add("mainOutline"),l.classList.add("secondaryOutline"),c(this,Zt).set(e,s),e}finalizeLine(t,e){const s=c(this,xn).get(t);c(this,xn).delete(t),this.updateBox(t,e.box),s.setAttribute("d",e.toSVGPath())}updateLine(t,e){c(this,Zt).get(t).firstChild.firstChild.setAttribute("d",e.toSVGPath())}updatePath(t,e){c(this,xn).get(t).setAttribute("d",e.toSVGPath())}updateBox(t,e){var s;y(s=ye,ic,Ep).call(s,c(this,Zt).get(t),e)}show(t,e){c(this,Zt).get(t).classList.toggle("hidden",!e)}rotate(t,e){c(this,Zt).get(t).setAttribute("data-main-rotation",e)}changeColor(t,e){c(this,Zt).get(t).setAttribute("fill",e)}changeOpacity(t,e){c(this,Zt).get(t).setAttribute("fill-opacity",e)}addClass(t,e){c(this,Zt).get(t).classList.add(e)}removeClass(t,e){c(this,Zt).get(t).classList.remove(e)}getSVGRoot(t){return c(this,Zt).get(t)}remove(t){c(this,xn).delete(t),c(this,Oi)!==null&&(c(this,Zt).get(t).remove(),c(this,Zt).delete(t))}destroy(){v(this,Oi,null);for(const t of c(this,Zt).values())t.remove();c(this,Zt).clear(),c(this,xn).clear()}};Oi=new WeakMap,sc=new WeakMap,Zt=new WeakMap,xn=new WeakMap,ic=new WeakSet,Ep=function(t,{x:e=0,y:s=0,width:i=1,height:n=1}={}){const{style:r}=t;r.top=`${100*s}%`,r.left=`${100*e}%`,r.width=`${100*i}%`,r.height=`${100*n}%`},Pa=new WeakSet,kp=function(t){var s;const e=ye._svgFactory.create(1,1,!0);return c(this,Oi).append(e),e.setAttribute("aria-hidden",!0),y(s=ye,ic,Ep).call(s,e,t),e},Ay=function(t,e){const s=ye._svgFactory.createElement("clipPath");t.append(s);const i=`clip_${e}`;s.setAttribute("id",i),s.setAttribute("clipPathUnits","objectBoundingBox");const n=ye._svgFactory.createElement("use");return s.append(n),n.setAttribute("href",`#${e}`),n.classList.add("clip"),i},w(ye,ic);let wf=ye;et.AbortException,et.AnnotationEditorLayer,et.AnnotationEditorParamsType,et.AnnotationEditorType,et.AnnotationEditorUIManager,et.AnnotationLayer,et.AnnotationMode,et.ColorPicker,et.DOMSVGFactory,et.DrawLayer,et.FeatureTest;var yC=et.GlobalWorkerOptions;et.ImageKind,et.InvalidPDFException,et.MissingPDFException,et.OPS,et.OutputScale,et.PDFDataRangeTransport,et.PDFDateString,et.PDFWorker,et.PasswordResponses,et.PermissionFlag,et.PixelsPerInch,et.RenderingCancelledException,et.TextLayer,et.UnexpectedResponseException,et.Util,et.VerbosityLevel,et.XfaLayer,et.build,et.createValidAbsoluteUrl,et.fetchData;var _C=et.getDocument;et.getFilenameFromUrl,et.getPdfFilenameFromUrl,et.getXfaPageViewport,et.isDataScheme,et.isPdfFile,et.noContextMenu,et.normalizeUnicode,et.setLayerDimensions,et.shadow,et.version;const wC={fabric:"^6.5.0","pdfjs-dist":"^4.8.69"};function xC(o){return new Promise((t,e)=>{const s=new FileReader;s.addEventListener("load",()=>t(s.result)),s.addEventListener("error",e),s.readAsDataURL(o)})}const SC=wC["pdfjs-dist"].replace("^","");yC.workerSrc=`https://cdnjs.cloudflare.com/ajax/libs/pdf.js/${SC}/pdf.worker.min.mjs`;async function CC(o){const t="data:application/pdf;base64,",e=await xC(o);if(typeof e=="string")return window.atob(e.slice(t.length))}function AC(o,t){return _C({data:o,password:t}).promise}const TC={top:100,left:50,scaleX:.5,scaleY:.5,borderColor:"black",cornerStrokeColor:"black",cornerSize:8,selectionBackgroundColor:"rgba(245, 245, 245, 0.8)"},EC={top:100,left:50,fontFamily:"helvetica",borderColor:"black",cornerStrokeColor:"black",scaleX:.7,scaleY:.7,cornerSize:8,selectionBackgroundColor:"rgba(245, 245, 245, 0.8)"},kC={stroke:"#000",hoverStroke:"#B7EC5D",src:""};function Fv(o=""){const t=K.useRef(0),e=K.useRef(null),s=K.useRef(null),i=K.useRef(1),n=K.useRef({...kC});function r(){if(!o||_s.has(o))return;const M=hx(o);return M.on("selection:cleared",()=>A(M)),M}function a(M,O){var j;const R=M.type,I={"application/pdf":h,"image/png":d,"image/jpeg":d};return((j=I[R])==null?void 0:j.call(I,M,O))??Promise.reject(new Error(`Unsupported ${R} file type.`))}async function h(M,O){const R=await CC(M);if(!R)return;const I=lx(M,R);try{return await l({page:1,PDFBase64:R,scale:.8,password:O}),{...I,pages:t.current}}catch(j){return Promise.reject(j)}}async function l({page:M,PDFBase64:O,scale:R,password:I}){try{const j=await AC(O,I),G=await j.getPage(M),{renderTask:L,canvas:H}=cx(G,R);return t.current=j.numPages,L.promise.then(()=>u(H))}catch(j){return Promise.reject(j)}}function u(M){dx(o,M)}async function d(M){return await gx(o,M)}async function g({url:M,scale:O=.5}){await N0(o,{url:M,scale:O})}async function f(M,O){const R=_s.get(o);if(!R)return;const I=await Ce.fromURL(M,{},{...TC,...O});R.add(I),m(R,I)}function p(M,O){const R=_s.get(o);if(!R)return;const I=new Se(M,{...EC,...O});R.add(I),m(R,I)}function m(M,O){O.on("selected",R=>_({canvas:M,target:R.target})),O.on("modified",R=>Mh(R.target,e.current)),O.on("scaling",R=>Mh(R.transform.target,e.current)),O.on("moving",R=>Mh(R.transform.target,e.current)),O.on("rotating",R=>Mh(R.transform.target,e.current))}async function _({canvas:M,target:O,stroke:R=n.current.stroke,uuid:I=Date.now()}){var G;if(((G=e.current)==null?void 0:G.stroke)===`${R}-${I}`)return;const j=await ux(n.current.src,R,I);A(M),e.current=j,s.current=O,b(M,O,I),x(i.current,!0),M.add(j)}function b(M,O,R){e.current&&(e.current.on("selected",()=>{M.remove(O),A(M)}),e.current.on("mouseover",()=>{_({canvas:M,target:O,stroke:n.current.hoverStroke,uuid:R})}),e.current.on("mouseout",()=>{_({canvas:M,target:O,stroke:n.current.stroke,uuid:R})}))}function x(M,O=!1){const R=_s.get(o);i.current=M,R&&(px(s.current,M,n.current),fx(s.current,M,e.current),!O&&R.renderAll())}function S(M){if(!M)return;n.current={...n.current,...M};const O=_s.get(o);!e||!s.current||!O||_({target:s.current,canvas:O})}function A(M){e.current&&(M.remove(e.current),e.current=s.current=null)}function k(){mx(o)}function P(){vx(o)}return{createCanvas:r,loadFile:a,specifyPage:l,renderImage:g,addFabric:f,addTextFabric:p,clearActive:k,deleteCanvas:P,scaleFabric:x,setCloseSvgOptions:S}}function MC(o){let t=0;const e=ox(()=>{t!==window.innerWidth&&(t=window.innerWidth,o())});K.useEffect(()=>(window.addEventListener("resize",e),()=>window.removeEventListener("resize",e)),[])}const OC=K.forwardRef(PC);function PC({file:o,page:t=1,canvasId:e="PDF-canvas",fileZoom:s=1,fileScale:i=1,canvasScale:n=1,canvasClass:r="",isDrop:a=!1,password:h,dropTextOptions:l,dropImageOptions:u,closeSvgOptions:d},g){const f=K.useRef(null),p=`${e}-${t-1}`,m=K.useMemo(()=>s*n,[s,n]),{createCanvas:_,specifyPage:b,addFabric:x,addTextFabric:S,renderImage:A,clearActive:k,deleteCanvas:P,scaleFabric:M,setCloseSvgOptions:O}=Fv(p);MC(R);async function R(){window.requestAnimationFrame(async()=>{if(_(),o.PDFBase64.startsWith("data:image")||o.canvas){const{canvas:L}=o,H=L?7:3,$=L!=null&&L.length?L[t-1]:o.PDFBase64;A({url:$,scale:i/H});return}await b({page:t,PDFBase64:o.PDFBase64,scale:i,password:h})})}function I(L){if(L.preventDefault(),L.stopPropagation(),!a||!L.dataTransfer)return;const{dataTransfer:H,clientX:$,clientY:J}=L,Y=H.getData("text"),X=H.getData("image"),Ot={left:$-71,top:J-55};X&&j(X,Ot),Y&&G(Y,Ot)}function j(L,H){x(L,{...H,...u})}function G(L,H){S(L,{...H,...l})}return K.useImperativeHandle(g,()=>({addImage:j,addText:G,clearActive:k,deleteCanvas:P,canvasRef:f})),K.useEffect(()=>{R()},[i,t,o,h]),K.useEffect(()=>{M(m)},[m]),K.useEffect(()=>{O(d)},[d]),K.useEffect(()=>()=>P(),[]),Pp.jsx("div",{style:{transform:`scale(${m})`},onDragOver:L=>L.preventDefault(),onDragEnter:L=>L.preventDefault(),onDrop:I,children:Pp.jsx("canvas",{id:p,ref:f,className:r})})}const Hu=Object.freeze(Object.defineProperty({__proto__:null,default:{}},Symbol.toStringTag,{value:"Module"}));ct.default=OC,ct.useFabric=Fv,Object.defineProperties(ct,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
|
|
538
|
+
`)){const s=document.createElement("div");s.append(e?document.createTextNode(e):document.createElement("br")),this.editorDiv.append(s)}},Hb=function(){return c(this,us).replaceAll(" "," ")},op=function(e){return e.replaceAll(" "," ")},Wb=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((a,h)=>a!==n[h])||e.pageIndex!==r},w(Et,cn),tt(Et,"_freeTextDefaultContent",""),tt(Et,"_internalPadding",0),tt(Et,"_defaultColor",null),tt(Et,"_defaultFontSize",10),tt(Et,"_type","freetext"),tt(Et,"_editorType",nt.FREETEXT);let mf=Et;class Pv{toSVGPath(){Mt("Abstract method `toSVGPath` must be implemented.")}get box(){Mt("Abstract getter `box` must be implemented.")}serialize(t,e){Mt("Abstract method `serialize` must be implemented.")}get classNamesForDrawing(){Mt("Abstract getter `classNamesForDrawing` must be implemented.")}get classNamesForOutlining(){Mt("Abstract getter `classNamesForOutlining` must be implemented.")}get mustRemoveSelfIntersections(){return!1}}const un=class un{constructor({x:t,y:e},s,i,n,r,a=0){w(this,oe);w(this,gs);w(this,Zs,[]);w(this,jo);w(this,No);w(this,Ai,[]);w(this,ot,new Float64Array(18));w(this,va);w(this,ba);w(this,Hl);w(this,Wl);w(this,Bo);w(this,Ho);w(this,er,[]);v(this,gs,s),v(this,Ho,n*i),v(this,No,r),c(this,ot).set([NaN,NaN,NaN,NaN,t,e],6),v(this,jo,a),v(this,Wl,c(un,Xl)*i),v(this,Hl,c(un,id)*i),v(this,Bo,i),c(this,er).push(t,e)}isEmpty(){return isNaN(c(this,ot)[8])}add({x:t,y:e}){var R;v(this,va,t),v(this,ba,e);const[s,i,n,r]=c(this,gs);let[a,h,l,u]=c(this,ot).subarray(8,12);const d=t-l,g=e-u,f=Math.hypot(d,g);if(f<c(this,Hl))return!1;const p=f-c(this,Wl),m=p/f,_=m*d,b=m*g;let x=a,S=h;a=l,h=u,l+=_,u+=b,(R=c(this,er))==null||R.push(t,e);const A=-b/p,k=_/p,P=A*c(this,Ho),M=k*c(this,Ho);return c(this,ot).set(c(this,ot).subarray(2,8),0),c(this,ot).set([l+P,u+M],4),c(this,ot).set(c(this,ot).subarray(14,18),12),c(this,ot).set([l-P,u-M],16),isNaN(c(this,ot)[6])?(c(this,Ai).length===0&&(c(this,ot).set([a+P,h+M],2),c(this,Ai).push(NaN,NaN,NaN,NaN,(a+P-s)/n,(h+M-i)/r),c(this,ot).set([a-P,h-M],14),c(this,Zs).push(NaN,NaN,NaN,NaN,(a-P-s)/n,(h-M-i)/r)),c(this,ot).set([x,S,a,h,l,u],6),!this.isEmpty()):(c(this,ot).set([x,S,a,h,l,u],6),Math.abs(Math.atan2(S-h,x-a)-Math.atan2(b,_))<Math.PI/2?([a,h,l,u]=c(this,ot).subarray(2,6),c(this,Ai).push(NaN,NaN,NaN,NaN,((a+l)/2-s)/n,((h+u)/2-i)/r),[a,h,x,S]=c(this,ot).subarray(14,18),c(this,Zs).push(NaN,NaN,NaN,NaN,((x+a)/2-s)/n,((S+h)/2-i)/r),!0):([x,S,a,h,l,u]=c(this,ot).subarray(0,6),c(this,Ai).push(((x+5*a)/6-s)/n,((S+5*h)/6-i)/r,((5*a+l)/6-s)/n,((5*h+u)/6-i)/r,((a+l)/2-s)/n,((h+u)/2-i)/r),[l,u,a,h,x,S]=c(this,ot).subarray(12,18),c(this,Zs).push(((x+5*a)/6-s)/n,((S+5*h)/6-i)/r,((5*a+l)/6-s)/n,((5*h+u)/6-i)/r,((a+l)/2-s)/n,((h+u)/2-i)/r),!0))}toSVGPath(){if(this.isEmpty())return"";const t=c(this,Ai),e=c(this,Zs);if(isNaN(c(this,ot)[6])&&!this.isEmpty())return y(this,oe,Xb).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]}`);y(this,oe,Vb).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 y(this,oe,zb).call(this,s),s.join(" ")}newFreeDrawOutline(t,e,s,i,n,r){return new Dv(t,e,s,i,n,r)}getOutlines(){var d;const t=c(this,Ai),e=c(this,Zs),s=c(this,ot),[i,n,r,a]=c(this,gs),h=new Float64Array((((d=c(this,er))==null?void 0:d.length)??0)+2);for(let g=0,f=h.length-2;g<f;g+=2)h[g]=(c(this,er)[g]-i)/r,h[g+1]=(c(this,er)[g+1]-n)/a;if(h[h.length-2]=(c(this,va)-i)/r,h[h.length-1]=(c(this,ba)-n)/a,isNaN(s[6])&&!this.isEmpty())return y(this,oe,Gb).call(this,h);const l=new Float64Array(c(this,Ai).length+24+c(this,Zs).length);let u=t.length;for(let g=0;g<u;g+=2){if(isNaN(t[g])){l[g]=l[g+1]=NaN;continue}l[g]=t[g],l[g+1]=t[g+1]}u=y(this,oe,Ub).call(this,l,u);for(let g=e.length-6;g>=6;g-=6)for(let f=0;f<6;f+=2){if(isNaN(e[g+f])){l[u]=l[u+1]=NaN,u+=2;continue}l[u]=e[g+f],l[u+1]=e[g+f+1],u+=2}return y(this,oe,Yb).call(this,l,u),this.newFreeDrawOutline(l,h,c(this,gs),c(this,Bo),c(this,jo),c(this,No))}};gs=new WeakMap,Zs=new WeakMap,jo=new WeakMap,No=new WeakMap,Ai=new WeakMap,ot=new WeakMap,va=new WeakMap,ba=new WeakMap,Hl=new WeakMap,Wl=new WeakMap,Bo=new WeakMap,Ho=new WeakMap,er=new WeakMap,Xl=new WeakMap,sd=new WeakMap,id=new WeakMap,oe=new WeakSet,gc=function(){const t=c(this,ot).subarray(4,6),e=c(this,ot).subarray(16,18),[s,i,n,r]=c(this,gs);return[(c(this,va)+(t[0]-e[0])/2-s)/n,(c(this,ba)+(t[1]-e[1])/2-i)/r,(c(this,va)+(e[0]-t[0])/2-s)/n,(c(this,ba)+(e[1]-t[1])/2-i)/r]},Xb=function(){const[t,e,s,i]=c(this,gs),[n,r,a,h]=y(this,oe,gc).call(this);return`M${(c(this,ot)[2]-t)/s} ${(c(this,ot)[3]-e)/i} L${(c(this,ot)[4]-t)/s} ${(c(this,ot)[5]-e)/i} L${n} ${r} L${a} ${h} L${(c(this,ot)[16]-t)/s} ${(c(this,ot)[17]-e)/i} L${(c(this,ot)[14]-t)/s} ${(c(this,ot)[15]-e)/i} Z`},zb=function(t){const e=c(this,Zs);t.push(`L${e[4]} ${e[5]} Z`)},Vb=function(t){const[e,s,i,n]=c(this,gs),r=c(this,ot).subarray(4,6),a=c(this,ot).subarray(16,18),[h,l,u,d]=y(this,oe,gc).call(this);t.push(`L${(r[0]-e)/i} ${(r[1]-s)/n} L${h} ${l} L${u} ${d} L${(a[0]-e)/i} ${(a[1]-s)/n}`)},Gb=function(t){const e=c(this,ot),[s,i,n,r]=c(this,gs),[a,h,l,u]=y(this,oe,gc).call(this),d=new Float64Array(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,a,h,NaN,NaN,NaN,NaN,l,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,c(this,gs),c(this,Bo),c(this,jo),c(this,No))},Yb=function(t,e){const s=c(this,Zs);return t.set([NaN,NaN,NaN,NaN,s[4],s[5]],e),e+=6},Ub=function(t,e){const s=c(this,ot).subarray(4,6),i=c(this,ot).subarray(16,18),[n,r,a,h]=c(this,gs),[l,u,d,g]=y(this,oe,gc).call(this);return t.set([NaN,NaN,NaN,NaN,(s[0]-n)/a,(s[1]-r)/h,NaN,NaN,NaN,NaN,l,u,NaN,NaN,NaN,NaN,d,g,NaN,NaN,NaN,NaN,(i[0]-n)/a,(i[1]-r)/h],e),e+=24},w(un,Xl,8),w(un,sd,2),w(un,id,c(un,Xl)+c(un,sd));let ju=un;class Dv extends Pv{constructor(e,s,i,n,r,a){super();w(this,Ze);w(this,Wo);w(this,ya,null);w(this,dn);w(this,zl);w(this,fs);w(this,Vl);w(this,Ut);v(this,Ut,e),v(this,fs,s),v(this,Wo,i),v(this,Vl,n),v(this,dn,r),v(this,zl,a),y(this,Ze,qb).call(this,a);const{x:h,y:l,width:u,height:d}=c(this,ya);for(let g=0,f=e.length;g<f;g+=2)e[g]=(e[g]-h)/u,e[g+1]=(e[g+1]-l)/d;for(let g=0,f=s.length;g<f;g+=2)s[g]=(s[g]-h)/u,s[g+1]=(s[g+1]-l)/d}toSVGPath(){const e=[`M${c(this,Ut)[4]} ${c(this,Ut)[5]}`];for(let s=6,i=c(this,Ut).length;s<i;s+=6){if(isNaN(c(this,Ut)[s])){e.push(`L${c(this,Ut)[s+4]} ${c(this,Ut)[s+5]}`);continue}e.push(`C${c(this,Ut)[s]} ${c(this,Ut)[s+1]} ${c(this,Ut)[s+2]} ${c(this,Ut)[s+3]} ${c(this,Ut)[s+4]} ${c(this,Ut)[s+5]}`)}return e.push("Z"),e.join(" ")}serialize([e,s,i,n],r){const a=i-e,h=n-s;let l,u;switch(r){case 0:l=y(this,Ze,fc).call(this,c(this,Ut),e,n,a,-h),u=y(this,Ze,fc).call(this,c(this,fs),e,n,a,-h);break;case 90:l=y(this,Ze,pc).call(this,c(this,Ut),e,s,a,h),u=y(this,Ze,pc).call(this,c(this,fs),e,s,a,h);break;case 180:l=y(this,Ze,fc).call(this,c(this,Ut),i,s,-a,h),u=y(this,Ze,fc).call(this,c(this,fs),i,s,-a,h);break;case 270:l=y(this,Ze,pc).call(this,c(this,Ut),i,n,-a,-h),u=y(this,Ze,pc).call(this,c(this,fs),i,n,-a,-h);break}return{outline:Array.from(l),points:[Array.from(u)]}}get box(){return c(this,ya)}newOutliner(e,s,i,n,r,a=0){return new ju(e,s,i,n,r,a)}getNewOutline(e,s){const{x:i,y:n,width:r,height:a}=c(this,ya),[h,l,u,d]=c(this,Wo),g=r*u,f=a*d,p=i*u+h,m=n*d+l,_=this.newOutliner({x:c(this,fs)[0]*g+p,y:c(this,fs)[1]*f+m},c(this,Wo),c(this,Vl),e,c(this,zl),s??c(this,dn));for(let b=2;b<c(this,fs).length;b+=2)_.add({x:c(this,fs)[b]*g+p,y:c(this,fs)[b+1]*f+m});return _.getOutlines()}get mustRemoveSelfIntersections(){return!0}}Wo=new WeakMap,ya=new WeakMap,dn=new WeakMap,zl=new WeakMap,fs=new WeakMap,Vl=new WeakMap,Ut=new WeakMap,Ze=new WeakSet,fc=function(e,s,i,n,r){const a=new Float64Array(e.length);for(let h=0,l=e.length;h<l;h+=2)a[h]=s+e[h]*n,a[h+1]=i+e[h+1]*r;return a},pc=function(e,s,i,n,r){const a=new Float64Array(e.length);for(let h=0,l=e.length;h<l;h+=2)a[h]=s+e[h+1]*n,a[h+1]=i+e[h]*r;return a},qb=function(e){const s=c(this,Ut);let i=s[4],n=s[5],r=i,a=n,h=i,l=n,u=i,d=n;const g=e?Math.max:Math.min;for(let b=6,x=s.length;b<x;b+=6){if(isNaN(s[b]))r=Math.min(r,s[b+4]),a=Math.min(a,s[b+5]),h=Math.max(h,s[b+4]),l=Math.max(l,s[b+5]),d<s[b+5]?(u=s[b+4],d=s[b+5]):d===s[b+5]&&(u=g(u,s[b+4]));else{const S=U.bezierBoundingBox(i,n,...s.slice(b,b+6));r=Math.min(r,S[0]),a=Math.min(a,S[1]),h=Math.max(h,S[2]),l=Math.max(l,S[3]),d<S[3]?(u=S[2],d=S[3]):d===S[3]&&(u=g(u,S[2]))}i=s[b+4],n=s[b+5]}const f=r-c(this,dn),p=a-c(this,dn),m=h-r+2*c(this,dn),_=l-a+2*c(this,dn);v(this,ya,{x:f,y:p,width:m,height:_,lastPoint:[u,d]})};class Rv{constructor(t,e=0,s=0,i=!0){w(this,Xe);w(this,Gl);w(this,sr,[]);w(this,ti,[]);let n=1/0,r=-1/0,a=1/0,h=-1/0;const u=10**-4;for(const{x:b,y:x,width:S,height:A}of t){const k=Math.floor((b-e)/u)*u,P=Math.ceil((b+S+e)/u)*u,M=Math.floor((x-e)/u)*u,O=Math.ceil((x+A+e)/u)*u,R=[k,M,O,!0],I=[P,M,O,!1];c(this,sr).push(R,I),n=Math.min(n,k),r=Math.max(r,P),a=Math.min(a,M),h=Math.max(h,O)}const d=r-n+2*s,g=h-a+2*s,f=n-s,p=a-s,m=c(this,sr).at(i?-1:-2),_=[m[0],m[2]];for(const b of c(this,sr)){const[x,S,A]=b;b[0]=(x-f)/d,b[1]=(S-p)/g,b[2]=(A-p)/g}v(this,Gl,{x:f,y:p,width:d,height:g,lastPoint:_})}getOutlines(){c(this,sr).sort((e,s)=>e[0]-s[0]||e[1]-s[1]||e[2]-s[2]);const t=[];for(const e of c(this,sr))e[3]?(t.push(...y(this,Xe,hp).call(this,e)),y(this,Xe,Kb).call(this,e)):(y(this,Xe,Jb).call(this,e),t.push(...y(this,Xe,hp).call(this,e)));return y(this,Xe,$b).call(this,t)}}Gl=new WeakMap,sr=new WeakMap,ti=new WeakMap,Xe=new WeakSet,$b=function(t){const e=[],s=new Set;for(const r of t){const[a,h,l]=r;e.push([a,h,r],[a,l,r])}e.sort((r,a)=>r[1]-a[1]||r[0]-a[0]);for(let r=0,a=e.length;r<a;r+=2){const h=e[r][2],l=e[r+1][2];h.push(l),l.push(h),s.add(h),s.add(l)}const i=[];let n;for(;s.size>0;){const r=s.values().next().value;let[a,h,l,u,d]=r;s.delete(r);let g=a,f=h;for(n=[a,l],i.push(n);;){let p;if(s.has(u))p=u;else if(s.has(d))p=d;else break;s.delete(p),[a,h,l,u,d]=p,g!==a&&(n.push(g,f,a,f===h?h:l),g=a),f=f===h?l:h}n.push(g,f)}return new vC(i,c(this,Gl))},Ad=function(t){const e=c(this,ti);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},Kb=function([,t,e]){const s=y(this,Xe,Ad).call(this,t);c(this,ti).splice(s,0,[t,e])},Jb=function([,t,e]){const s=y(this,Xe,Ad).call(this,t);for(let i=s;i<c(this,ti).length;i++){const[n,r]=c(this,ti)[i];if(n!==t)break;if(n===t&&r===e){c(this,ti).splice(i,1);return}}for(let i=s-1;i>=0;i--){const[n,r]=c(this,ti)[i];if(n!==t)break;if(n===t&&r===e){c(this,ti).splice(i,1);return}}},hp=function(t){const[e,s,i]=t,n=[[e,s,i]],r=y(this,Xe,Ad).call(this,i);for(let a=0;a<r;a++){const[h,l]=c(this,ti)[a];for(let u=0,d=n.length;u<d;u++){const[,g,f]=n[u];if(!(l<=g||f<=h)){if(g>=h){if(f>l)n[u][1]=l;else{if(d===1)return[];n.splice(u,1),u--,d--}continue}n[u][2]=h,f>l&&n.push([e,l,f])}}}return n};class vC extends Pv{constructor(e,s){super();w(this,Yl);w(this,Xo);v(this,Xo,e),v(this,Yl,s)}toSVGPath(){const e=[];for(const s of c(this,Xo)){let[i,n]=s;e.push(`M${i} ${n}`);for(let r=2;r<s.length;r+=2){const a=s[r],h=s[r+1];a===i?(e.push(`V${h}`),n=h):h===n&&(e.push(`H${a}`),i=a)}e.push("Z")}return e.join(" ")}serialize([e,s,i,n],r){const a=[],h=i-e,l=n-s;for(const u of c(this,Xo)){const d=new Array(u.length);for(let g=0;g<u.length;g+=2)d[g]=e+u[g]*h,d[g+1]=n-u[g+1]*l;a.push(d)}return a}get box(){return c(this,Yl)}get classNamesForDrawing(){return["highlight"]}get classNamesForOutlining(){return["highlightOutline"]}}Yl=new WeakMap,Xo=new WeakMap;class vf extends ju{newFreeDrawOutline(t,e,s,i,n,r){return new bC(t,e,s,i,n,r)}get classNamesForDrawing(){return["highlight","free"]}}class bC extends Dv{get classNamesForDrawing(){return["highlight","free"]}get classNamesForOutlining(){return["highlightOutline","free"]}newOutliner(t,e,s,i,n,r=0){return new vf(t,e,s,i,n,r)}}const ts=class ts{constructor({editor:t=null,uiManager:e=null}){w(this,Ct);w(this,ei,null);w(this,_a,null);w(this,zo);w(this,he,null);w(this,Ul,!1);w(this,Vo,!1);w(this,ql,null);w(this,$l);w(this,ir,null);w(this,si,null);w(this,Go);var s;t?(v(this,Vo,!1),v(this,Go,Z.HIGHLIGHT_COLOR),v(this,ql,t)):(v(this,Vo,!0),v(this,Go,Z.HIGHLIGHT_DEFAULT_COLOR)),v(this,si,(t==null?void 0:t._uiManager)||e),v(this,$l,c(this,si)._eventBus),v(this,zo,(t==null?void 0:t.color)||((s=c(this,si))==null?void 0:s.highlightColors.values().next().value)||"#FFFF98"),c(ts,Kl)||v(ts,Kl,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 ut(this,"_keyboardManager",new Fh([[["Escape","mac+Escape"],ts.prototype._hideDropdownFromKeyboard],[[" ","mac+ "],ts.prototype._colorSelectFromKeyboard],[["ArrowDown","ArrowRight","mac+ArrowDown","mac+ArrowRight"],ts.prototype._moveToNext],[["ArrowUp","ArrowLeft","mac+ArrowUp","mac+ArrowLeft"],ts.prototype._moveToPrevious],[["Home","mac+Home"],ts.prototype._moveToBeginning],[["End","mac+End"],ts.prototype._moveToEnd]]))}renderButton(){const t=v(this,ei,document.createElement("button"));t.className="colorPicker",t.tabIndex="0",t.setAttribute("data-l10n-id","pdfjs-editor-colorpicker-button"),t.setAttribute("aria-haspopup",!0);const e=c(this,si)._signal;t.addEventListener("click",y(this,Ct,Fa).bind(this),{signal:e}),t.addEventListener("keydown",y(this,Ct,up).bind(this),{signal:e});const s=v(this,_a,document.createElement("span"));return s.className="swatch",s.setAttribute("aria-hidden",!0),s.style.backgroundColor=c(this,zo),t.append(s),t}renderMainDropdown(){const t=v(this,he,y(this,Ct,lp).call(this));return t.setAttribute("aria-orientation","horizontal"),t.setAttribute("aria-labelledby","highlightColorPickerLabel"),t}_colorSelectFromKeyboard(t){if(t.target===c(this,ei)){y(this,Ct,Fa).call(this,t);return}const e=t.target.getAttribute("data-color");e&&y(this,Ct,cp).call(this,e,t)}_moveToNext(t){var e,s;if(!c(this,Ct,ur)){y(this,Ct,Fa).call(this,t);return}if(t.target===c(this,ei)){(e=c(this,he).firstChild)==null||e.focus();return}(s=t.target.nextSibling)==null||s.focus()}_moveToPrevious(t){var e,s;if(t.target===((e=c(this,he))==null?void 0:e.firstChild)||t.target===c(this,ei)){c(this,Ct,ur)&&this._hideDropdownFromKeyboard();return}c(this,Ct,ur)||y(this,Ct,Fa).call(this,t),(s=t.target.previousSibling)==null||s.focus()}_moveToBeginning(t){var e;if(!c(this,Ct,ur)){y(this,Ct,Fa).call(this,t);return}(e=c(this,he).firstChild)==null||e.focus()}_moveToEnd(t){var e;if(!c(this,Ct,ur)){y(this,Ct,Fa).call(this,t);return}(e=c(this,he).lastChild)==null||e.focus()}hideDropdown(){var t,e;(t=c(this,he))==null||t.classList.add("hidden"),(e=c(this,ir))==null||e.abort(),v(this,ir,null)}_hideDropdownFromKeyboard(){var t;if(!c(this,Vo)){if(!c(this,Ct,ur)){(t=c(this,ql))==null||t.unselect();return}this.hideDropdown(),c(this,ei).focus({preventScroll:!0,focusVisible:c(this,Ul)})}}updateColor(t){if(c(this,_a)&&(c(this,_a).style.backgroundColor=t),!c(this,he))return;const e=c(this,si).highlightColors.values();for(const s of c(this,he).children)s.setAttribute("aria-selected",e.next().value===t)}destroy(){var t,e;(t=c(this,ei))==null||t.remove(),v(this,ei,null),v(this,_a,null),(e=c(this,he))==null||e.remove(),v(this,he,null)}};ei=new WeakMap,_a=new WeakMap,zo=new WeakMap,he=new WeakMap,Ul=new WeakMap,Vo=new WeakMap,ql=new WeakMap,$l=new WeakMap,ir=new WeakMap,si=new WeakMap,Go=new WeakMap,Kl=new WeakMap,Ct=new WeakSet,lp=function(){const t=document.createElement("div"),e=c(this,si)._signal;t.addEventListener("contextmenu",ws,{signal:e}),t.className="dropdown",t.role="listbox",t.setAttribute("aria-multiselectable",!1),t.setAttribute("aria-orientation","vertical"),t.setAttribute("data-l10n-id","pdfjs-editor-colorpicker-dropdown");for(const[s,i]of c(this,si).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",c(ts,Kl)[s]);const r=document.createElement("span");n.append(r),r.className="swatch",r.style.backgroundColor=i,n.setAttribute("aria-selected",i===c(this,zo)),n.addEventListener("click",y(this,Ct,cp).bind(this,i),{signal:e}),t.append(n)}return t.addEventListener("keydown",y(this,Ct,up).bind(this),{signal:e}),t},cp=function(t,e){e.stopPropagation(),c(this,$l).dispatch("switchannotationeditorparams",{source:this,type:c(this,Go),value:t})},up=function(t){ts._keyboardManager.exec(this,t)},Fa=function(t){if(c(this,Ct,ur)){this.hideDropdown();return}if(v(this,Ul,t.detail===0),c(this,ir)||(v(this,ir,new AbortController),window.addEventListener("pointerdown",y(this,Ct,Qb).bind(this),{signal:c(this,si).combinedSignal(c(this,ir))})),c(this,he)){c(this,he).classList.remove("hidden");return}const e=v(this,he,y(this,Ct,lp).call(this));c(this,ei).append(e)},Qb=function(t){var e;(e=c(this,he))!=null&&e.contains(t.target)||this.hideDropdown()},ur=function(){return c(this,he)&&!c(this,he).classList.contains("hidden")},w(ts,Kl,null);let Nu=ts;const pt=class pt extends _t{constructor(e){super({...e,name:"highlightEditor"});w(this,it);w(this,Yo,null);w(this,Jl,0);w(this,gn);w(this,wa,null);w(this,Uo,null);w(this,Es,null);w(this,Ql,null);w(this,Zl,0);w(this,xa,null);w(this,ii,null);w(this,Me,null);w(this,es,!1);w(this,qo,null);w(this,fn);w(this,le,null);w(this,$o,"");w(this,ks);w(this,tc,"");this.color=e.color||pt._defaultColor,v(this,ks,e.thickness||pt._defaultThickness),v(this,fn,e.opacity||pt._defaultOpacity),v(this,gn,e.boxes||null),v(this,tc,e.methodOfCreation||""),v(this,$o,e.text||""),this._isDraggable=!1,e.highlightId>-1?(v(this,es,!0),y(this,it,Td).call(this,e),y(this,it,La).call(this)):c(this,gn)&&(v(this,Yo,e.anchorNode),v(this,Jl,e.anchorOffset),v(this,Ql,e.focusNode),v(this,Zl,e.focusOffset),y(this,it,dp).call(this),y(this,it,La).call(this),this.rotate(this.rotation))}static get _keyboardManager(){const e=pt.prototype;return ut(this,"_keyboardManager",new Fh([[["ArrowLeft","mac+ArrowLeft"],e._moveCaret,{args:[0]}],[["ArrowRight","mac+ArrowRight"],e._moveCaret,{args:[1]}],[["ArrowUp","mac+ArrowUp"],e._moveCaret,{args:[2]}],[["ArrowDown","mac+ArrowDown"],e._moveCaret,{args:[3]}]]))}get telemetryInitialData(){return{action:"added",type:c(this,es)?"free_highlight":"highlight",color:this._uiManager.highlightColorNames.get(this.color),thickness:c(this,ks),methodOfCreation:c(this,tc)}}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;_t.initialize(e,s),pt._defaultColor||(pt._defaultColor=((i=s.highlightColors)==null?void 0:i.values().next().value)||"#fff066")}static updateDefaultParams(e,s){switch(e){case Z.HIGHLIGHT_DEFAULT_COLOR:pt._defaultColor=s;break;case Z.HIGHLIGHT_THICKNESS:pt._defaultThickness=s;break}}translateInPage(e,s){}get toolbarPosition(){return c(this,qo)}updateParams(e,s){switch(e){case Z.HIGHLIGHT_COLOR:y(this,it,Zb).call(this,s);break;case Z.HIGHLIGHT_THICKNESS:y(this,it,ty).call(this,s);break}}static get defaultPropertiesToUpdate(){return[[Z.HIGHLIGHT_DEFAULT_COLOR,pt._defaultColor],[Z.HIGHLIGHT_THICKNESS,pt._defaultThickness]]}get propertiesToUpdate(){return[[Z.HIGHLIGHT_COLOR,this.color||pt._defaultColor],[Z.HIGHLIGHT_THICKNESS,c(this,ks)||pt._defaultThickness],[Z.HIGHLIGHT_FREE,c(this,es)]]}async addEditToolbar(){const e=await super.addEditToolbar();return e?(this._uiManager.highlightColors&&(v(this,Uo,new Nu({editor:this})),e.addColorPicker(c(this,Uo))),e):null}disableEditing(){super.disableEditing(),this.div.classList.toggle("disabled",!0)}enableEditing(){super.enableEditing(),this.div.classList.toggle("disabled",!1)}fixAndSetPosition(){return super.fixAndSetPosition(y(this,it,mc).call(this))}getBaseTranslation(){return[0,0]}getRect(e,s){return super.getRect(e,s,y(this,it,mc).call(this))}onceAdded(){this.annotationElementId||this.parent.addUndoableEditor(this),this.div.focus()}remove(){y(this,it,gp).call(this),this._reportTelemetry({action:"deleted"}),super.remove()}rebuild(){this.parent&&(super.rebuild(),this.div!==null&&(y(this,it,La).call(this),this.isAttachedToDOM||this.parent.add(this)))}setParent(e){var i;let s=!1;this.parent&&!e?y(this,it,gp).call(this):e&&(y(this,it,La).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,a;const{drawLayer:s}=this.parent;let i;c(this,es)?(e=(e-this.rotation+360)%360,i=y(n=pt,Ms,lh).call(n,c(this,ii).box,e)):i=y(r=pt,Ms,lh).call(r,this,e),s.rotate(c(this,Me),e),s.rotate(c(this,le),e),s.updateBox(c(this,Me),i),s.updateBox(c(this,le),y(a=pt,Ms,lh).call(a,c(this,Es).box,e))}render(){if(this.div)return this.div;const e=super.render();c(this,$o)&&(e.setAttribute("aria-label",c(this,$o)),e.setAttribute("role","mark")),c(this,es)?e.classList.add("free"):this.div.addEventListener("keydown",y(this,it,sy).bind(this),{signal:this._uiManager._signal});const s=v(this,xa,document.createElement("div"));e.append(s),s.setAttribute("aria-hidden","true"),s.className="internal",s.style.clipPath=c(this,wa);const[i,n]=this.parentDimensions;return this.setDims(this.width*i,this.height*n),Mu(this,c(this,xa),["pointerover","pointerleave"]),this.enableEditing(),e}pointerover(){this.isSelected||this.parent.drawLayer.addClass(c(this,le),"hovered")}pointerleave(){this.isSelected||this.parent.drawLayer.removeClass(c(this,le),"hovered")}_moveCaret(e){switch(this.parent.unselect(this),e){case 0:case 2:y(this,it,Ed).call(this,!0);break;case 1:case 3:y(this,it,Ed).call(this,!1);break}}select(){var e,s;super.select(),c(this,le)&&((e=this.parent)==null||e.drawLayer.removeClass(c(this,le),"hovered"),(s=this.parent)==null||s.drawLayer.addClass(c(this,le),"selected"))}unselect(){var e;super.unselect(),c(this,le)&&((e=this.parent)==null||e.drawLayer.removeClass(c(this,le),"selected"),c(this,es)||y(this,it,Ed).call(this,!1))}get _mustFixPosition(){return!c(this,es)}show(e=this._isVisible){super.show(e),this.parent&&(this.parent.drawLayer.show(c(this,Me),e),this.parent.drawLayer.show(c(this,le),e))}static startHighlighting(e,s,{target:i,x:n,y:r}){const{x:a,y:h,width:l,height:u}=i.getBoundingClientRect(),d=new AbortController,g=e.combinedSignal(d),f=m=>{m.preventDefault(),m.stopPropagation()},p=m=>{d.abort(),y(this,Ms,ay).call(this,e,m)};window.addEventListener("blur",p,{signal:g}),window.addEventListener("pointerup",p,{signal:g}),window.addEventListener("pointerdown",f,{capture:!0,passive:!1,signal:g}),window.addEventListener("contextmenu",ws,{signal:g}),i.addEventListener("pointermove",y(this,Ms,ry).bind(this,e),{signal:g}),this._freeHighlight=new vf({x:n,y:r},[a,h,l,u],e.scale,this._defaultThickness/2,s,.001),{id:this._freeHighlightId,clipPathId:this._freeHighlightClipId}=e.drawLayer.draw(this._freeHighlight,this._defaultColor,this._defaultOpacity,!0)}static async deserialize(e,s,i){var m,_,b,x;let n=null;if(e instanceof Mv){const{data:{quadPoints:S,rect:A,rotation:k,id:P,color:M,opacity:O,popupRef:R},parent:{page:{pageNumber:I}}}=e;n=e={annotationType:nt.HIGHLIGHT,color:Array.from(M),opacity:O,quadPoints:S,boxes:null,pageIndex:I-1,rect:A.slice(0),rotation:k,id:P,deleted:!1,popupRef:R}}else if(e instanceof pf){const{data:{inkLists:S,rect:A,rotation:k,id:P,color:M,borderStyle:{rawWidth:O},popupRef:R},parent:{page:{pageNumber:I}}}=e;n=e={annotationType:nt.HIGHLIGHT,color:Array.from(M),thickness:O,inkLists:S,boxes:null,pageIndex:I-1,rect:A.slice(0),rotation:k,id:P,deleted:!1,popupRef:R}}const{color:r,quadPoints:a,inkLists:h,opacity:l}=e,u=await super.deserialize(e,s,i);u.color=U.makeHexColor(...r),v(u,fn,l||1),h&&v(u,ks,e.thickness),u.annotationElementId=e.id||null,u._initialData=n;const[d,g]=u.pageDimensions,[f,p]=u.pageTranslation;if(a){const S=v(u,gn,[]);for(let A=0;A<a.length;A+=8)S.push({x:(a[A]-f)/d,y:1-(a[A+1]-p)/g,width:(a[A+2]-a[A])/d,height:(a[A+1]-a[A+5])/g});y(m=u,it,dp).call(m),y(_=u,it,La).call(_),u.rotate(u.rotation)}else if(h){v(u,es,!0);const S=h[0],A={x:S[0]-f,y:g-(S[1]-p)},k=new vf(A,[0,0,d,g],1,c(u,ks)/2,!0,.001);for(let O=0,R=S.length;O<R;O+=2)A.x=S[O]-f,A.y=g-(S[O+1]-p),k.add(A);const{id:P,clipPathId:M}=s.drawLayer.draw(k,u.color,u._defaultOpacity,!0);y(b=u,it,Td).call(b,{highlightOutlines:k.getOutlines(),highlightId:P,clipPathId:M}),y(x=u,it,La).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=_t._colorManager.convert(this.color),n={annotationType:nt.HIGHLIGHT,color:i,opacity:c(this,fn),thickness:c(this,ks),quadPoints:y(this,it,iy).call(this),outlines:y(this,it,ny).call(this,s),pageIndex:this.pageIndex,rect:s,rotation:y(this,it,mc).call(this),structTreeParentId:this._structTreeParentId};return this.annotationElementId&&!y(this,it,oy).call(this,n)?null:(n.id=this.annotationElementId,n)}renderAnnotationElement(e){return e.updateEdited({rect:this.getRect(0,0)}),null}static canCreateNewEmptyEditor(){return!1}};Yo=new WeakMap,Jl=new WeakMap,gn=new WeakMap,wa=new WeakMap,Uo=new WeakMap,Es=new WeakMap,Ql=new WeakMap,Zl=new WeakMap,xa=new WeakMap,ii=new WeakMap,Me=new WeakMap,es=new WeakMap,qo=new WeakMap,fn=new WeakMap,le=new WeakMap,$o=new WeakMap,ks=new WeakMap,tc=new WeakMap,it=new WeakSet,dp=function(){const e=new Rv(c(this,gn),.001);v(this,ii,e.getOutlines()),{x:this.x,y:this.y,width:this.width,height:this.height}=c(this,ii).box;const s=new Rv(c(this,gn),.0025,.001,this._uiManager.direction==="ltr");v(this,Es,s.getOutlines());const{lastPoint:i}=c(this,Es).box;v(this,qo,[(i[0]-this.x)/this.width,(i[1]-this.y)/this.height])},Td=function({highlightOutlines:e,highlightId:s,clipPathId:i}){var d,g;if(v(this,ii,e),v(this,Es,e.getNewOutline(c(this,ks)/2+1.5,.0025)),s>=0)v(this,Me,s),v(this,wa,i),this.parent.drawLayer.finalizeLine(s,e),v(this,le,this.parent.drawLayer.drawOutline(c(this,Es)));else if(this.parent){const f=this.parent.viewport.rotation;this.parent.drawLayer.updateLine(c(this,Me),e),this.parent.drawLayer.updateBox(c(this,Me),y(d=pt,Ms,lh).call(d,c(this,ii).box,(f-this.rotation+360)%360)),this.parent.drawLayer.updateLine(c(this,le),c(this,Es)),this.parent.drawLayer.updateBox(c(this,le),y(g=pt,Ms,lh).call(g,c(this,Es).box,f))}const{x:r,y:a,width:h,height:l}=e.box;switch(this.rotation){case 0:this.x=r,this.y=a,this.width=h,this.height=l;break;case 90:{const[f,p]=this.parentDimensions;this.x=a,this.y=1-r,this.width=h*p/f,this.height=l*f/p;break}case 180:this.x=1-r,this.y=1-a,this.width=h,this.height=l;break;case 270:{const[f,p]=this.parentDimensions;this.x=1-a,this.y=r,this.width=h*p/f,this.height=l*f/p;break}}const{lastPoint:u}=c(this,Es).box;v(this,qo,[(u[0]-r)/h,(u[1]-a)/l])},Zb=function(e){const s=(r,a)=>{var h,l,u;this.color=r,(h=this.parent)==null||h.drawLayer.changeColor(c(this,Me),r),(l=c(this,Uo))==null||l.updateColor(r),v(this,fn,a),(u=this.parent)==null||u.drawLayer.changeOpacity(c(this,Me),a)},i=this.color,n=c(this,fn);this.addCommands({cmd:s.bind(this,e,pt._defaultOpacity),undo:s.bind(this,i,n),post:this._uiManager.updateUI.bind(this._uiManager,this),mustExec:!0,type:Z.HIGHLIGHT_COLOR,overwriteIfSameType:!0,keepUndo:!0}),this._reportTelemetry({action:"color_changed",color:this._uiManager.highlightColorNames.get(e)},!0)},ty=function(e){const s=c(this,ks),i=n=>{v(this,ks,n),y(this,it,ey).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:Z.INK_THICKNESS,overwriteIfSameType:!0,keepUndo:!0}),this._reportTelemetry({action:"thickness_changed",thickness:e},!0)},ey=function(e){if(!c(this,es))return;y(this,it,Td).call(this,{highlightOutlines:c(this,ii).getNewOutline(e/2)}),this.fixAndSetPosition();const[s,i]=this.parentDimensions;this.setDims(this.width*s,this.height*i)},gp=function(){c(this,Me)===null||!this.parent||(this.parent.drawLayer.remove(c(this,Me)),v(this,Me,null),this.parent.drawLayer.remove(c(this,le)),v(this,le,null))},La=function(e=this.parent){c(this,Me)===null&&({id:Ge(this,Me)._,clipPathId:Ge(this,wa)._}=e.drawLayer.draw(c(this,ii),this.color,c(this,fn)),v(this,le,e.drawLayer.drawOutline(c(this,Es))),c(this,xa)&&(c(this,xa).style.clipPath=c(this,wa)))},Ms=new WeakSet,lh=function({x:e,y:s,width:i,height:n},r){switch(r){case 90:return{x:1-s-n,y:e,width:n,height:i};case 180:return{x:1-e-i,y:1-s-n,width:i,height:n};case 270:return{x:s,y:1-e-i,width:n,height:i}}return{x:e,y:s,width:i,height:n}},sy=function(e){pt._keyboardManager.exec(this,e)},Ed=function(e){if(!c(this,Yo))return;const s=window.getSelection();e?s.setPosition(c(this,Yo),c(this,Jl)):s.setPosition(c(this,Ql),c(this,Zl))},mc=function(){return c(this,es)?this.rotation:0},iy=function(){if(c(this,es))return null;const[e,s]=this.pageDimensions,[i,n]=this.pageTranslation,r=c(this,gn),a=new Float32Array(r.length*8);let h=0;for(const{x:l,y:u,width:d,height:g}of r){const f=l*e+i,p=(1-u-g)*s+n;a[h]=a[h+4]=f,a[h+1]=a[h+3]=p,a[h+2]=a[h+6]=f+d*e,a[h+5]=a[h+7]=p+g*s,h+=8}return a},ny=function(e){return c(this,ii).serialize(e,y(this,it,mc).call(this))},ry=function(e,s){this._freeHighlight.add(s)&&e.drawLayer.updatePath(this._freeHighlightId,this._freeHighlight)},ay=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=""},oy=function(e){const{color:s}=this._initialData;return e.color.some((i,n)=>i!==s[n])},w(pt,Ms),tt(pt,"_defaultColor",null),tt(pt,"_defaultOpacity",1),tt(pt,"_defaultThickness",12),tt(pt,"_type","highlight"),tt(pt,"_editorType",nt.HIGHLIGHT),tt(pt,"_freeHighlightId",-1),tt(pt,"_freeHighlight",null),tt(pt,"_freeHighlightClipId","");let Bu=pt;const Nt=class Nt extends _t{constructor(e){super({...e,name:"inkEditor"});w(this,N);w(this,Sa,0);w(this,Ca,0);w(this,Ti,null);w(this,pn,new Path2D);w(this,Os,!1);w(this,Aa,null);w(this,Ta,!1);w(this,Ea,!1);w(this,mn,null);w(this,Ko,null);w(this,ka,0);w(this,Ma,0);w(this,nr,null);this.color=e.color||null,this.thickness=e.thickness||null,this.opacity=e.opacity||null,this.paths=[],this.bezierPath2D=[],this.allRawPaths=[],this.currentPath=[],this.scaleFactor=1,this.translationX=this.translationY=0,this.x=0,this.y=0,this._willKeepAspectRatio=!0}static initialize(e,s){_t.initialize(e,s)}static updateDefaultParams(e,s){switch(e){case Z.INK_THICKNESS:Nt._defaultThickness=s;break;case Z.INK_COLOR:Nt._defaultColor=s;break;case Z.INK_OPACITY:Nt._defaultOpacity=s/100;break}}updateParams(e,s){switch(e){case Z.INK_THICKNESS:y(this,N,hy).call(this,s);break;case Z.INK_COLOR:y(this,N,ly).call(this,s);break;case Z.INK_OPACITY:y(this,N,cy).call(this,s);break}}static get defaultPropertiesToUpdate(){return[[Z.INK_THICKNESS,Nt._defaultThickness],[Z.INK_COLOR,Nt._defaultColor||_t._defaultLineColor],[Z.INK_OPACITY,Math.round(Nt._defaultOpacity*100)]]}get propertiesToUpdate(){return[[Z.INK_THICKNESS,this.thickness||Nt._defaultThickness],[Z.INK_COLOR,this.color||Nt._defaultColor||_t._defaultLineColor],[Z.INK_OPACITY,Math.round(100*(this.opacity??Nt._defaultOpacity))]]}rebuild(){this.parent&&(super.rebuild(),this.div!==null&&(this.canvas||(y(this,N,kd).call(this),y(this,N,Md).call(this)),this.isAttachedToDOM||(this.parent.add(this),y(this,N,ch).call(this)),y(this,N,vc).call(this)))}remove(){var e;this.canvas!==null&&(this.isEmpty()||this.commit(),this.canvas.width=this.canvas.height=0,this.canvas.remove(),this.canvas=null,c(this,Ti)&&(clearTimeout(c(this,Ti)),v(this,Ti,null)),(e=c(this,mn))==null||e.disconnect(),v(this,mn,null),super.remove())}setParent(e){!this.parent&&e?this._uiManager.removeShouldRescale(this):this.parent&&e===null&&this._uiManager.addShouldRescale(this),super.setParent(e)}onScaleChanging(){const[e,s]=this.parentDimensions,i=this.width*e,n=this.height*s;this.setDimensions(i,n)}enableEditMode(){c(this,Os)||this.canvas===null||(super.enableEditMode(),this._isDraggable=!1,y(this,N,mp).call(this))}disableEditMode(){!this.isInEditMode()||this.canvas===null||(super.disableEditMode(),this._isDraggable=!this.isEmpty(),this.div.classList.remove("editing"),y(this,N,vp).call(this))}onceAdded(){this._isDraggable=!this.isEmpty()}isEmpty(){return this.paths.length===0||this.paths.length===1&&this.paths[0].length===0}commit(){c(this,Os)||(super.commit(),this.isEditing=!1,this.disableEditMode(),this.setInForeground(),v(this,Os,!0),this.div.classList.add("disabled"),y(this,N,vc).call(this,!0),this.select(),this.parent.addInkEditorIfNeeded(!0),this.moveInDOM(),this.div.focus({preventScroll:!0}))}focusin(e){this._focusEventsAllowed&&(super.focusin(e),this.enableEditMode())}canvasPointerdown(e){e.button!==0||!this.isInEditMode()||c(this,Os)||(this.setInForeground(),e.preventDefault(),this.div.contains(document.activeElement)||this.div.focus({preventScroll:!0}),y(this,N,dy).call(this,e.offsetX,e.offsetY))}canvasPointermove(e){e.preventDefault(),y(this,N,pp).call(this,e.offsetX,e.offsetY)}canvasPointerup(e){e.preventDefault(),y(this,N,bp).call(this,e)}canvasPointerleave(e){y(this,N,bp).call(this,e)}get isResizable(){return!this.isEmpty()&&c(this,Os)}render(){if(this.div)return this.div;let e,s;this.width&&(e=this.x,s=this.y),super.render(),this.div.setAttribute("data-l10n-id","pdfjs-ink");const[i,n,r,a]=y(this,N,uy).call(this);if(this.setAt(i,n,0,0),this.setDims(r,a),y(this,N,kd).call(this),this.width){const[h,l]=this.parentDimensions;this.setAspectRatio(this.width*h,this.height*l),this.setAt(e*h,s*l,this.width*h,this.height*l),v(this,Ea,!0),y(this,N,ch).call(this),this.setDims(this.width*h,this.height*l),y(this,N,Ia).call(this),this.div.classList.add("disabled")}else this.div.classList.add("editing"),this.enableEditMode();return y(this,N,Md).call(this),this.div}setDimensions(e,s){const i=Math.round(e),n=Math.round(s);if(c(this,ka)===i&&c(this,Ma)===n)return;v(this,ka,i),v(this,Ma,n),this.canvas.style.visibility="hidden";const[r,a]=this.parentDimensions;this.width=e/r,this.height=s/a,this.fixAndSetPosition(),c(this,Os)&&y(this,N,yp).call(this,e,s),y(this,N,ch).call(this),y(this,N,Ia).call(this),this.canvas.style.visibility="visible",this.fixDims()}static async deserialize(e,s,i){var _,b,x;if(e instanceof pf)return null;const n=await super.deserialize(e,s,i);n.thickness=e.thickness,n.color=U.makeHexColor(...e.color),n.opacity=e.opacity;const[r,a]=n.pageDimensions,h=n.width*r,l=n.height*a,u=n.parentScale,d=e.thickness/2;v(n,Os,!0),v(n,ka,Math.round(h)),v(n,Ma,Math.round(l));const{paths:g,rect:f,rotation:p}=e;for(let{bezier:S}of g){S=y(_=Nt,vn,yy).call(_,S,f,p);const A=[];n.paths.push(A);let k=u*(S[0]-d),P=u*(S[1]-d);for(let O=2,R=S.length;O<R;O+=6){const I=u*(S[O]-d),j=u*(S[O+1]-d),G=u*(S[O+2]-d),L=u*(S[O+3]-d),H=u*(S[O+4]-d),$=u*(S[O+5]-d);A.push([[k,P],[I,j],[G,L],[H,$]]),k=H,P=$}const M=y(this,vn,by).call(this,A);n.bezierPath2D.push(M)}const m=y(b=n,N,wp).call(b);return v(n,Ca,Math.max(_t.MIN_SIZE,m[2]-m[0])),v(n,Sa,Math.max(_t.MIN_SIZE,m[3]-m[1])),y(x=n,N,yp).call(x,h,l),n}serialize(){if(this.isEmpty())return null;const e=this.getRect(0,0),s=_t._colorManager.convert(this.ctx.strokeStyle);return{annotationType:nt.INK,color:s,thickness:this.thickness,opacity:this.opacity,paths:y(this,N,_y).call(this,this.scaleFactor/this.parentScale,this.translationX,this.translationY,e),pageIndex:this.pageIndex,rect:e,rotation:this.rotation,structTreeParentId:this._structTreeParentId}}};Sa=new WeakMap,Ca=new WeakMap,Ti=new WeakMap,pn=new WeakMap,Os=new WeakMap,Aa=new WeakMap,Ta=new WeakMap,Ea=new WeakMap,mn=new WeakMap,Ko=new WeakMap,ka=new WeakMap,Ma=new WeakMap,nr=new WeakMap,N=new WeakSet,hy=function(e){const s=n=>{this.thickness=n,y(this,N,vc).call(this)},i=this.thickness;this.addCommands({cmd:s.bind(this,e),undo:s.bind(this,i),post:this._uiManager.updateUI.bind(this._uiManager,this),mustExec:!0,type:Z.INK_THICKNESS,overwriteIfSameType:!0,keepUndo:!0})},ly=function(e){const s=n=>{this.color=n,y(this,N,Ia).call(this)},i=this.color;this.addCommands({cmd:s.bind(this,e),undo:s.bind(this,i),post:this._uiManager.updateUI.bind(this._uiManager,this),mustExec:!0,type:Z.INK_COLOR,overwriteIfSameType:!0,keepUndo:!0})},cy=function(e){const s=n=>{this.opacity=n,y(this,N,Ia).call(this)};e/=100;const i=this.opacity;this.addCommands({cmd:s.bind(this,e),undo:s.bind(this,i),post:this._uiManager.updateUI.bind(this._uiManager,this),mustExec:!0,type:Z.INK_OPACITY,overwriteIfSameType:!0,keepUndo:!0})},uy=function(){const{parentRotation:e,parentDimensions:[s,i]}=this;switch(e){case 90:return[0,i,i,s];case 180:return[s,i,s,i];case 270:return[s,0,i,s];default:return[0,0,s,i]}},fp=function(){const{ctx:e,color:s,opacity:i,thickness:n,parentScale:r,scaleFactor:a}=this;e.lineWidth=n*r/a,e.lineCap="round",e.lineJoin="round",e.miterLimit=10,e.strokeStyle=`${s}${Hx(i)}`},dy=function(e,s){this.canvas.addEventListener("contextmenu",ws,{signal:this._uiManager._signal}),y(this,N,vp).call(this),v(this,Aa,new AbortController);const i=this._uiManager.combinedSignal(c(this,Aa));this.canvas.addEventListener("pointerleave",this.canvasPointerleave.bind(this),{signal:i}),this.canvas.addEventListener("pointermove",this.canvasPointermove.bind(this),{signal:i}),this.canvas.addEventListener("pointerup",this.canvasPointerup.bind(this),{signal:i}),this.isEditing=!0,c(this,Ea)||(v(this,Ea,!0),y(this,N,ch).call(this),this.thickness||(this.thickness=Nt._defaultThickness),this.color||(this.color=Nt._defaultColor||_t._defaultLineColor),this.opacity??(this.opacity=Nt._defaultOpacity)),this.currentPath.push([e,s]),v(this,Ta,!1),y(this,N,fp).call(this),v(this,nr,()=>{y(this,N,py).call(this),c(this,nr)&&window.requestAnimationFrame(c(this,nr))}),window.requestAnimationFrame(c(this,nr))},pp=function(e,s){const[i,n]=this.currentPath.at(-1);if(this.currentPath.length>1&&e===i&&s===n)return;const r=this.currentPath;let a=c(this,pn);if(r.push([e,s]),v(this,Ta,!0),r.length<=2){a.moveTo(...r[0]),a.lineTo(e,s);return}r.length===3&&(v(this,pn,a=new Path2D),a.moveTo(...r[0])),y(this,N,my).call(this,a,...r.at(-3),...r.at(-2),e,s)},gy=function(){if(this.currentPath.length===0)return;const e=this.currentPath.at(-1);c(this,pn).lineTo(...e)},fy=function(e,s){v(this,nr,null),e=Math.min(Math.max(e,0),this.canvas.width),s=Math.min(Math.max(s,0),this.canvas.height),y(this,N,pp).call(this,e,s),y(this,N,gy).call(this);let i;if(this.currentPath.length!==1)i=y(this,N,vy).call(this);else{const l=[e,s];i=[[l,l.slice(),l.slice(),l]]}const n=c(this,pn),r=this.currentPath;this.currentPath=[],v(this,pn,new Path2D);const a=()=>{this.allRawPaths.push(r),this.paths.push(i),this.bezierPath2D.push(n),this._uiManager.rebuild(this)},h=()=>{this.allRawPaths.pop(),this.paths.pop(),this.bezierPath2D.pop(),this.paths.length===0?this.remove():(this.canvas||(y(this,N,kd).call(this),y(this,N,Md).call(this)),y(this,N,vc).call(this))};this.addCommands({cmd:a,undo:h,mustExec:!0})},py=function(){if(!c(this,Ta))return;v(this,Ta,!1);const e=Math.ceil(this.thickness*this.parentScale),s=this.currentPath.slice(-3),i=s.map(a=>a[0]),n=s.map(a=>a[1]);Math.min(...i)-e,Math.max(...i)+e,Math.min(...n)-e,Math.max(...n)+e;const{ctx:r}=this;r.save(),r.clearRect(0,0,this.canvas.width,this.canvas.height);for(const a of this.bezierPath2D)r.stroke(a);r.stroke(c(this,pn)),r.restore()},my=function(e,s,i,n,r,a,h){const l=(s+n)/2,u=(i+r)/2,d=(n+a)/2,g=(r+h)/2;e.bezierCurveTo(l+2*(n-l)/3,u+2*(r-u)/3,d+2*(n-d)/3,g+2*(r-g)/3,d,g)},vy=function(){const e=this.currentPath;if(e.length<=2)return[[e[0],e[0],e.at(-1),e.at(-1)]];const s=[];let i,[n,r]=e[0];for(i=1;i<e.length-2;i++){const[f,p]=e[i],[m,_]=e[i+1],b=(f+m)/2,x=(p+_)/2,S=[n+2*(f-n)/3,r+2*(p-r)/3],A=[b+2*(f-b)/3,x+2*(p-x)/3];s.push([[n,r],S,A,[b,x]]),[n,r]=[b,x]}const[a,h]=e[i],[l,u]=e[i+1],d=[n+2*(a-n)/3,r+2*(h-r)/3],g=[l+2*(a-l)/3,u+2*(h-u)/3];return s.push([[n,r],d,g,[l,u]]),s},Ia=function(){if(this.isEmpty()){y(this,N,Od).call(this);return}y(this,N,fp).call(this);const{canvas:e,ctx:s}=this;s.setTransform(1,0,0,1,0,0),s.clearRect(0,0,e.width,e.height),y(this,N,Od).call(this);for(const i of this.bezierPath2D)s.stroke(i)},mp=function(){if(c(this,Ko))return;v(this,Ko,new AbortController);const e=this._uiManager.combinedSignal(c(this,Ko));this.canvas.addEventListener("pointerdown",this.canvasPointerdown.bind(this),{signal:e})},vp=function(){var e;(e=this.pointerdownAC)==null||e.abort(),this.pointerdownAC=null},bp=function(e){var s;(s=c(this,Aa))==null||s.abort(),v(this,Aa,null),y(this,N,mp).call(this),c(this,Ti)&&clearTimeout(c(this,Ti)),v(this,Ti,setTimeout(()=>{v(this,Ti,null),this.canvas.removeEventListener("contextmenu",ws)},10)),y(this,N,fy).call(this,e.offsetX,e.offsetY),this.addToAnnotationStorage(),this.setInBackground()},kd=function(){this.canvas=document.createElement("canvas"),this.canvas.width=this.canvas.height=0,this.canvas.className="inkEditorCanvas",this.canvas.setAttribute("data-l10n-id","pdfjs-ink-canvas"),this.div.append(this.canvas),this.ctx=this.canvas.getContext("2d")},Md=function(){v(this,mn,new ResizeObserver(e=>{const s=e[0].contentRect;s.width&&s.height&&this.setDimensions(s.width,s.height)})),c(this,mn).observe(this.div),this._uiManager._signal.addEventListener("abort",()=>{var e;(e=c(this,mn))==null||e.disconnect(),v(this,mn,null)},{once:!0})},ch=function(){if(!c(this,Ea))return;const[e,s]=this.parentDimensions;this.canvas.width=Math.ceil(this.width*e),this.canvas.height=Math.ceil(this.height*s),y(this,N,Od).call(this)},yp=function(e,s){const i=y(this,N,Pd).call(this),n=(e-i)/c(this,Ca),r=(s-i)/c(this,Sa);this.scaleFactor=Math.min(n,r)},Od=function(){const e=y(this,N,Pd).call(this)/2;this.ctx.setTransform(this.scaleFactor,0,0,this.scaleFactor,this.translationX*this.scaleFactor+e,this.translationY*this.scaleFactor+e)},vn=new WeakSet,by=function(e){const s=new Path2D;for(let i=0,n=e.length;i<n;i++){const[r,a,h,l]=e[i];i===0&&s.moveTo(...r),s.bezierCurveTo(a[0],a[1],h[0],h[1],l[0],l[1])}return s},_p=function(e,s,i){const[n,r,a,h]=s;switch(i){case 0:for(let l=0,u=e.length;l<u;l+=2)e[l]+=n,e[l+1]=h-e[l+1];break;case 90:for(let l=0,u=e.length;l<u;l+=2){const d=e[l];e[l]=e[l+1]+n,e[l+1]=d+r}break;case 180:for(let l=0,u=e.length;l<u;l+=2)e[l]=a-e[l],e[l+1]+=r;break;case 270:for(let l=0,u=e.length;l<u;l+=2){const d=e[l];e[l]=a-e[l+1],e[l+1]=h-d}break;default:throw new Error("Invalid rotation")}return e},yy=function(e,s,i){const[n,r,a,h]=s;switch(i){case 0:for(let l=0,u=e.length;l<u;l+=2)e[l]-=n,e[l+1]=h-e[l+1];break;case 90:for(let l=0,u=e.length;l<u;l+=2){const d=e[l];e[l]=e[l+1]-r,e[l+1]=d-n}break;case 180:for(let l=0,u=e.length;l<u;l+=2)e[l]=a-e[l],e[l+1]-=r;break;case 270:for(let l=0,u=e.length;l<u;l+=2){const d=e[l];e[l]=h-e[l+1],e[l+1]=a-d}break;default:throw new Error("Invalid rotation")}return e},_y=function(e,s,i,n){var u,d;const r=[],a=this.thickness/2,h=e*s+a,l=e*i+a;for(const g of this.paths){const f=[],p=[];for(let m=0,_=g.length;m<_;m++){const[b,x,S,A]=g[m];if(b[0]===A[0]&&b[1]===A[1]&&_===1){const L=e*b[0]+h,H=e*b[1]+l;f.push(L,H),p.push(L,H);break}const k=e*b[0]+h,P=e*b[1]+l,M=e*x[0]+h,O=e*x[1]+l,R=e*S[0]+h,I=e*S[1]+l,j=e*A[0]+h,G=e*A[1]+l;m===0&&(f.push(k,P),p.push(k,P)),f.push(M,O,R,I,j,G),p.push(M,O),m===_-1&&p.push(j,G)}r.push({bezier:y(u=Nt,vn,_p).call(u,f,n,this.rotation),points:y(d=Nt,vn,_p).call(d,p,n,this.rotation)})}return r},wp=function(){let e=1/0,s=-1/0,i=1/0,n=-1/0;for(const r of this.paths)for(const[a,h,l,u]of r){const d=U.bezierBoundingBox(...a,...h,...l,...u);e=Math.min(e,d[0]),i=Math.min(i,d[1]),s=Math.max(s,d[2]),n=Math.max(n,d[3])}return[e,i,s,n]},Pd=function(){return c(this,Os)?Math.ceil(this.thickness*this.parentScale):0},vc=function(e=!1){if(this.isEmpty())return;if(!c(this,Os)){y(this,N,Ia).call(this);return}const s=y(this,N,wp).call(this),i=y(this,N,Pd).call(this);v(this,Ca,Math.max(_t.MIN_SIZE,s[2]-s[0])),v(this,Sa,Math.max(_t.MIN_SIZE,s[3]-s[1]));const n=Math.ceil(i+c(this,Ca)*this.scaleFactor),r=Math.ceil(i+c(this,Sa)*this.scaleFactor),[a,h]=this.parentDimensions;this.width=n/a,this.height=r/h,this.setAspectRatio(n,r);const l=this.translationX,u=this.translationY;this.translationX=-s[0],this.translationY=-s[1],y(this,N,ch).call(this),y(this,N,Ia).call(this),v(this,ka,n),v(this,Ma,r),this.setDims(n,r);const d=e?i/this.scaleFactor/2:0;this.translate(l-this.translationX-d,u-this.translationY-d)},w(Nt,vn),tt(Nt,"_defaultColor",null),tt(Nt,"_defaultOpacity",1),tt(Nt,"_defaultThickness",1),tt(Nt,"_type","ink"),tt(Nt,"_editorType",nt.INK);let bf=Nt;const ec=class ec extends _t{constructor(e){super({...e,name:"stampEditor"});w(this,ht);w(this,Bt,null);w(this,ve,null);w(this,rr,null);w(this,bn,null);w(this,ar,null);w(this,Jo,"");w(this,Ei,null);w(this,yn,null);w(this,ki,null);w(this,ps,!1);w(this,Qo,!1);v(this,bn,e.bitmapUrl),v(this,ar,e.bitmapFile)}static initialize(e,s){_t.initialize(e,s)}static get supportedTypes(){return ut(this,"supportedTypes",["apng","avif","bmp","gif","jpeg","png","svg+xml","webp","x-icon"].map(s=>`image/${s}`))}static get supportedTypesStr(){return ut(this,"supportedTypesStr",this.supportedTypes.join(","))}static isHandlingMimeForPasting(e){return this.supportedTypes.includes(e)}static paste(e,s){s.pasteEditor(nt.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:a}=e||this.copyCanvas(null,null,!0).imageData,h=await i.guess({name:"altText",request:{data:n,width:r,height:a,channels:n.length/(r*a)}});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 l=h.output;return await this.setGuessedAltText(l),s&&!this.hasAltTextData()&&(this.altTextData={alt:l,decorative:!1}),l}remove(){var e,s;c(this,ve)&&(v(this,Bt,null),this._uiManager.imageManager.deleteId(c(this,ve)),(e=c(this,Ei))==null||e.remove(),v(this,Ei,null),(s=c(this,yn))==null||s.disconnect(),v(this,yn,null),c(this,ki)&&(clearTimeout(c(this,ki)),v(this,ki,null))),super.remove()}rebuild(){if(!this.parent){c(this,ve)&&y(this,ht,Dd).call(this);return}super.rebuild(),this.div!==null&&(c(this,ve)&&c(this,Ei)===null&&y(this,ht,Dd).call(this),this.isAttachedToDOM||this.parent.add(this))}onceAdded(){this._isDraggable=!0,this.div.focus()}isEmpty(){return!(c(this,rr)||c(this,Bt)||c(this,bn)||c(this,ar)||c(this,ve))}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(),c(this,Bt)?y(this,ht,xp).call(this):y(this,ht,Dd).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.div}copyCanvas(e,s,i=!1){var f;e||(e=224);const{width:n,height:r}=c(this,Bt),a=new qg;let h=c(this,Bt),l=n,u=r,d=null;if(s){if(n>s||r>s){const O=Math.min(s/n,s/r);l=Math.floor(n*O),u=Math.floor(r*O)}d=document.createElement("canvas");const p=d.width=Math.ceil(l*a.sx),m=d.height=Math.ceil(u*a.sy);c(this,ps)||(h=y(this,ht,Rd).call(this,p,m));const _=d.getContext("2d");_.filter=this._uiManager.hcmFilter;let b="white",x="#cfcfd8";this._uiManager.hcmFilter!=="none"?x="black":(f=window.matchMedia)!=null&&f.call(window,"(prefers-color-scheme: dark)").matches&&(b="#8f8f9d",x="#42414d");const S=15,A=S*a.sx,k=S*a.sy,P=new OffscreenCanvas(A*2,k*2),M=P.getContext("2d");M.fillStyle=b,M.fillRect(0,0,A*2,k*2),M.fillStyle=x,M.fillRect(0,0,A,k),M.fillRect(A,k,A,k),_.fillStyle=_.createPattern(P,"repeat"),_.fillRect(0,0,p,m),_.drawImage(h,0,0,h.width,h.height,0,0,p,m)}let g=null;if(i){let p,m;if(a.symmetric&&h.width<e&&h.height<e)p=h.width,m=h.height;else if(h=c(this,Bt),n>e||r>e){const x=Math.min(e/n,e/r);p=Math.floor(n*x),m=Math.floor(r*x),c(this,ps)||(h=y(this,ht,Rd).call(this,p,m))}const b=new OffscreenCanvas(p,m).getContext("2d",{willReadFrequently:!0});b.drawImage(h,0,0,h.width,h.height,0,0,p,m),g={width:p,height:m,data:b.getImageData(0,0,p,m).data}}return{canvas:d,width:l,height:u,imageData:g}}getImageForAltText(){return c(this,Ei)}static async deserialize(e,s,i){var m;let n=null;if(e instanceof Ov){const{data:{rect:_,rotation:b,id:x,structParent:S,popupRef:A},container:k,parent:{page:{pageNumber:P}}}=e,M=k.querySelector("canvas"),O=i.imageManager.getFromCanvas(k.id,M);M.remove();const R=((m=await s._structTree.getAriaAttributes(`${zg}${x}`))==null?void 0:m.get("aria-label"))||"";n=e={annotationType:nt.STAMP,bitmapId:O.id,bitmap:O.bitmap,pageIndex:P-1,rect:_.slice(0),rotation:b,id:x,deleted:!1,accessibilityData:{decorative:!1,altText:R},isSvg:!1,structParent:S,popupRef:A}}const r=await super.deserialize(e,s,i),{rect:a,bitmap:h,bitmapUrl:l,bitmapId:u,isSvg:d,accessibilityData:g}=e;u&&i.imageManager.isValidId(u)?(v(r,ve,u),h&&v(r,Bt,h)):v(r,bn,l),v(r,ps,d);const[f,p]=r.pageDimensions;return r.width=(a[2]-a[0])/f,r.height=(a[3]-a[1])/p,r.annotationElementId=e.id||null,g&&(r.altTextData=g),r._initialData=n,v(r,Qo,!!n),r}serialize(e=!1,s=null){if(this.isEmpty())return null;if(this.deleted)return this.serializeDeleted();const i={annotationType:nt.STAMP,bitmapId:c(this,ve),pageIndex:this.pageIndex,rect:this.getRect(0,0),rotation:this.rotation,isSvg:c(this,ps),structTreeParentId:this._structTreeParentId};if(e)return i.bitmapUrl=y(this,ht,Fd).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=y(this,ht,Sy).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 a=c(this,ps)?(i.rect[2]-i.rect[0])*(i.rect[3]-i.rect[1]):null;if(!s.stamps.has(c(this,ve)))s.stamps.set(c(this,ve),{area:a,serialized:i}),i.bitmap=y(this,ht,Fd).call(this,!1);else if(c(this,ps)){const h=s.stamps.get(c(this,ve));a>h.area&&(h.area=a,h.serialized.bitmap.close(),h.serialized.bitmap=y(this,ht,Fd).call(this,!1))}return i}renderAnnotationElement(e){return e.updateEdited({rect:this.getRect(0,0)}),null}};Bt=new WeakMap,ve=new WeakMap,rr=new WeakMap,bn=new WeakMap,ar=new WeakMap,Jo=new WeakMap,Ei=new WeakMap,yn=new WeakMap,ki=new WeakMap,ps=new WeakMap,Qo=new WeakMap,ht=new WeakSet,bc=function(e,s=!1){if(!e){this.remove();return}v(this,Bt,e.bitmap),s||(v(this,ve,e.id),v(this,ps,e.isSvg)),e.file&&v(this,Jo,e.file.name),y(this,ht,xp).call(this)},yc=function(){if(v(this,rr,null),this._uiManager.enableWaiting(!1),!!c(this,Ei)){if(this._uiManager.useNewAltTextWhenAddingImage&&this._uiManager.useNewAltTextFlow&&c(this,Bt)){this._editToolbar.hide(),this._uiManager.editAltText(this,!0);return}if(!this._uiManager.useNewAltTextWhenAddingImage&&this._uiManager.useNewAltTextFlow&&c(this,Bt)){this._reportTelemetry({action:"pdfjs.image.image_added",data:{alt_text_modal:!1,alt_text_type:"empty"}});try{this.mlGuessAltText()}catch{}}this.div.focus()}},Dd=function(){if(c(this,ve)){this._uiManager.enableWaiting(!0),this._uiManager.imageManager.getFromId(c(this,ve)).then(i=>y(this,ht,bc).call(this,i,!0)).finally(()=>y(this,ht,yc).call(this));return}if(c(this,bn)){const i=c(this,bn);v(this,bn,null),this._uiManager.enableWaiting(!0),v(this,rr,this._uiManager.imageManager.getFromUrl(i).then(n=>y(this,ht,bc).call(this,n)).finally(()=>y(this,ht,yc).call(this)));return}if(c(this,ar)){const i=c(this,ar);v(this,ar,null),this._uiManager.enableWaiting(!0),v(this,rr,this._uiManager.imageManager.getFromFile(i).then(n=>y(this,ht,bc).call(this,n)).finally(()=>y(this,ht,yc).call(this)));return}const e=document.createElement("input");e.type="file",e.accept=ec.supportedTypesStr;const s=this._uiManager._signal;v(this,rr,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}}),y(this,ht,bc).call(this,n)}i()},{signal:s}),e.addEventListener("cancel",()=>{this.remove(),i()},{signal:s})}).finally(()=>y(this,ht,yc).call(this))),e.click()},xp=function(){const{div:e}=this;let{width:s,height:i}=c(this,Bt);const[n,r]=this.pageDimensions,a=.75;if(this.width)s=this.width*n,i=this.height*r;else if(s>a*n||i>a*r){const d=Math.min(a*n/s,a*r/i);s*=d,i*=d}const[h,l]=this.parentDimensions;this.setDims(s*h/n,i*l/r),this._uiManager.enableWaiting(!1);const u=v(this,Ei,document.createElement("canvas"));u.setAttribute("role","img"),this.addContainer(u),(!this._uiManager.useNewAltTextWhenAddingImage||!this._uiManager.useNewAltTextFlow||this.annotationElementId)&&(e.hidden=!1),y(this,ht,Sp).call(this,s,i),y(this,ht,xy).call(this),c(this,Qo)||(this.parent.addUndoableEditor(this),v(this,Qo,!0)),this._reportTelemetry({action:"inserted_image"}),c(this,Jo)&&u.setAttribute("aria-label",c(this,Jo))},wy=function(e,s){var a;const[i,n]=this.parentDimensions;this.width=e/i,this.height=s/n,(a=this._initialOptions)!=null&&a.isCentered?this.center():this.fixAndSetPosition(),this._initialOptions=null,c(this,ki)!==null&&clearTimeout(c(this,ki)),v(this,ki,setTimeout(()=>{v(this,ki,null),y(this,ht,Sp).call(this,e,s)},200))},Rd=function(e,s){const{width:i,height:n}=c(this,Bt);let r=i,a=n,h=c(this,Bt);for(;r>2*e||a>2*s;){const l=r,u=a;r>2*e&&(r=r>=16384?Math.floor(r/2)-1:Math.ceil(r/2)),a>2*s&&(a=a>=16384?Math.floor(a/2)-1:Math.ceil(a/2));const d=new OffscreenCanvas(r,a);d.getContext("2d").drawImage(h,0,0,l,u,0,0,r,a),h=d.transferToImageBitmap()}return h},Sp=function(e,s){const i=new qg,n=Math.ceil(e*i.sx),r=Math.ceil(s*i.sy),a=c(this,Ei);if(!a||a.width===n&&a.height===r)return;a.width=n,a.height=r;const h=c(this,ps)?c(this,Bt):y(this,ht,Rd).call(this,n,r),l=a.getContext("2d");l.filter=this._uiManager.hcmFilter,l.drawImage(h,0,0,h.width,h.height,0,0,n,r)},Fd=function(e){if(e){if(c(this,ps)){const n=this._uiManager.imageManager.getSvgUrl(c(this,ve));if(n)return n}const s=document.createElement("canvas");return{width:s.width,height:s.height}=c(this,Bt),s.getContext("2d").drawImage(c(this,Bt),0,0),s.toDataURL()}if(c(this,ps)){const[s,i]=this.pageDimensions,n=Math.round(this.width*s*Rn.PDF_TO_CSS_UNITS),r=Math.round(this.height*i*Rn.PDF_TO_CSS_UNITS),a=new OffscreenCanvas(n,r);return a.getContext("2d").drawImage(c(this,Bt),0,0,c(this,Bt).width,c(this,Bt).height,0,0,n,r),a.transferToImageBitmap()}return structuredClone(c(this,Bt))},xy=function(){this._uiManager._signal&&(v(this,yn,new ResizeObserver(e=>{const s=e[0].contentRect;s.width&&s.height&&y(this,ht,wy).call(this,s.width,s.height)})),c(this,yn).observe(this.div),this._uiManager._signal.addEventListener("abort",()=>{var e;(e=c(this,yn))==null||e.disconnect(),v(this,yn,null)},{once:!0}))},Sy=function(e){var l;const{rect:s,pageIndex:i,accessibilityData:{altText:n}}=this._initialData,r=e.rect.every((u,d)=>Math.abs(u-s[d])<1),a=e.pageIndex===i,h=(((l=e.accessibilityData)==null?void 0:l.alt)||"")===n;return{isSame:r&&a&&h,isSameAltText:h}},tt(ec,"_type","stamp"),tt(ec,"_editorType",nt.STAMP);let yf=ec;const ni=class ni{constructor({uiManager:t,pageIndex:e,div:s,structTreeLayer:i,accessibilityManager:n,annotationLayer:r,drawLayer:a,textLayer:h,viewport:l,l10n:u}){w(this,be);w(this,Oa);w(this,Zo,!1);w(this,Mi,null);w(this,or,null);w(this,_n,null);w(this,ms,new Map);w(this,hr,!1);w(this,th,!1);w(this,eh,!1);w(this,Oe,null);w(this,wn,null);w(this,q);const d=[...c(ni,lr).values()];if(!ni._initialized){ni._initialized=!0;for(const g of d)g.initialize(u,t)}t.registerEditorTypes(d),v(this,q,t),this.pageIndex=e,this.div=s,v(this,Oa,n),v(this,Mi,r),this.viewport=l,v(this,Oe,h),this.drawLayer=a,this._structTree=i,c(this,q).addLayer(this)}get isEmpty(){return c(this,ms).size===0}get isInvisible(){return this.isEmpty&&c(this,q).getMode()===nt.NONE}updateToolbar(t){c(this,q).updateToolbar(t)}updateMode(t=c(this,q).getMode()){switch(y(this,be,Ld).call(this),t){case nt.NONE:this.disableTextSelection(),this.togglePointerEvents(!1),this.toggleAnnotationLayerPointerEvents(!0),this.disableClick();return;case nt.INK:this.addInkEditorIfNeeded(!1),this.disableTextSelection(),this.togglePointerEvents(!0),this.disableClick();break;case nt.HIGHLIGHT:this.enableTextSelection(),this.togglePointerEvents(!1),this.disableClick();break;default:this.disableTextSelection(),this.togglePointerEvents(!0),this.enableClick()}this.toggleAnnotationLayerPointerEvents(!1);const{classList:e}=this.div;for(const s of c(ni,lr).values())e.toggle(`${s._type}Editing`,t===s._editorType);this.div.hidden=!1}hasTextLayer(t){var e;return t===((e=c(this,Oe))==null?void 0:e.div)}addInkEditorIfNeeded(t){if(c(this,q).getMode()!==nt.INK)return;if(!t){for(const s of c(this,ms).values())if(s.isEmpty()){s.setInBackground();return}}this.createAndAddNewEditor({offsetX:0,offsetY:0},!1).setInBackground()}setEditingState(t){c(this,q).setEditingState(t)}addCommands(t){c(this,q).addCommands(t)}toggleDrawing(t=!1){this.div.classList.toggle("drawing",!t)}togglePointerEvents(t=!1){this.div.classList.toggle("disabled",!t)}toggleAnnotationLayerPointerEvents(t=!1){var e;(e=c(this,Mi))==null||e.div.classList.toggle("disabled",!t)}async enable(){this.div.tabIndex=0,this.togglePointerEvents(!0);const t=new Set;for(const s of c(this,ms).values())s.enableEditing(),s.show(!0),s.annotationElementId&&(c(this,q).removeChangedExistingAnnotation(s),t.add(s.annotationElementId));if(!c(this,Mi))return;const e=c(this,Mi).getEditableAnnotations();for(const s of e){if(s.hide(),c(this,q).isDeletedAnnotationElement(s.data.id)||t.has(s.data.id))continue;const i=await this.deserialize(s);i&&(this.addOrRebuild(i),i.enableEditing())}}disable(){var i;v(this,eh,!0),this.div.tabIndex=-1,this.togglePointerEvents(!1);const t=new Map,e=new Map;for(const n of c(this,ms).values())if(n.disableEditing(),!!n.annotationElementId){if(n.serialize()!==null){t.set(n.annotationElementId,n);continue}else e.set(n.annotationElementId,n);(i=this.getEditableAnnotation(n.annotationElementId))==null||i.show(),n.remove()}if(c(this,Mi)){const n=c(this,Mi).getEditableAnnotations();for(const r of n){const{id:a}=r.data;if(c(this,q).isDeletedAnnotationElement(a))continue;let h=e.get(a);if(h){h.resetAnnotationElement(r),h.show(!1),r.show();continue}h=t.get(a),h&&(c(this,q).addChangedExistingAnnotation(h),h.renderAnnotationElement(r)&&h.show(!1)),r.show()}}y(this,be,Ld).call(this),this.isEmpty&&(this.div.hidden=!0);const{classList:s}=this.div;for(const n of c(ni,lr).values())s.remove(`${n._type}Editing`);this.disableTextSelection(),this.toggleAnnotationLayerPointerEvents(!0),v(this,eh,!1)}getEditableAnnotation(t){var e;return((e=c(this,Mi))==null?void 0:e.getEditableAnnotation(t))||null}setActiveEditor(t){c(this,q).getActive()!==t&&c(this,q).setActiveEditor(t)}enableTextSelection(){var t;if(this.div.tabIndex=-1,(t=c(this,Oe))!=null&&t.div&&!c(this,wn)){v(this,wn,new AbortController);const e=c(this,q).combinedSignal(c(this,wn));c(this,Oe).div.addEventListener("pointerdown",y(this,be,Cy).bind(this),{signal:e}),c(this,Oe).div.classList.add("highlighting")}}disableTextSelection(){var t;this.div.tabIndex=0,(t=c(this,Oe))!=null&&t.div&&c(this,wn)&&(c(this,wn).abort(),v(this,wn,null),c(this,Oe).div.classList.remove("highlighting"))}enableClick(){if(c(this,or))return;v(this,or,new AbortController);const t=c(this,q).combinedSignal(c(this,or));this.div.addEventListener("pointerdown",this.pointerdown.bind(this),{signal:t}),this.div.addEventListener("pointerup",this.pointerup.bind(this),{signal:t})}disableClick(){var t;(t=c(this,or))==null||t.abort(),v(this,or,null)}attach(t){c(this,ms).set(t.id,t);const{annotationElementId:e}=t;e&&c(this,q).isDeletedAnnotationElement(e)&&c(this,q).removeDeletedAnnotationElement(t)}detach(t){var e;c(this,ms).delete(t.id),(e=c(this,Oa))==null||e.removePointerInTextLayer(t.contentDiv),!c(this,eh)&&t.annotationElementId&&c(this,q).addDeletedAnnotationElement(t)}remove(t){this.detach(t),c(this,q).removeEditor(t),t.div.remove(),t.isAttachedToDOM=!1,c(this,th)||this.addInkEditorIfNeeded(!1)}changeParent(t){var e;t.parent!==this&&(t.parent&&t.annotationElementId&&(c(this,q).addDeletedAnnotationElement(t.annotationElementId),_t.deleteAnnotationElement(t),t.annotationElementId=null),this.attach(t),(e=t.parent)==null||e.detach(t),t.setParent(this),t.div&&t.isAttachedToDOM&&(t.div.remove(),this.div.append(t.div)))}add(t){if(!(t.parent===this&&t.isAttachedToDOM)){if(this.changeParent(t),c(this,q).addEditor(t),this.attach(t),!t.isAttachedToDOM){const e=t.render();this.div.append(e),t.isAttachedToDOM=!0}t.fixAndSetPosition(),t.onceAdded(),c(this,q).addToAnnotationStorage(t),t._reportTelemetry(t.telemetryInitialData)}}moveEditorInDOM(t){var s;if(!t.isAttachedToDOM)return;const{activeElement:e}=document;t.div.contains(e)&&!c(this,_n)&&(t._focusEventsAllowed=!1,v(this,_n,setTimeout(()=>{v(this,_n,null),t.div.contains(document.activeElement)?t._focusEventsAllowed=!0:(t.div.addEventListener("focusin",()=>{t._focusEventsAllowed=!0},{once:!0,signal:c(this,q)._signal}),e.focus())},0))),t._structTreeParentId=(s=c(this,Oa))==null?void 0:s.moveElementInDOM(this.div,t.div,t.contentDiv,!0)}addOrRebuild(t){t.needsToBeRebuilt()?(t.parent||(t.parent=this),t.rebuild(),t.show()):this.add(t)}addUndoableEditor(t){const e=()=>t._uiManager.rebuild(t),s=()=>{t.remove()};this.addCommands({cmd:e,undo:s,mustExec:!1})}getNextId(){return c(this,q).getId()}combinedSignal(t){return c(this,q).combinedSignal(t)}canCreateNewEmptyEditor(){var t;return(t=c(this,be,Cp))==null?void 0:t.canCreateNewEmptyEditor()}pasteEditor(t,e){c(this,q).updateToolbar(t),c(this,q).updateMode(t);const{offsetX:s,offsetY:i}=y(this,be,Tp).call(this),n=this.getNextId(),r=y(this,be,Ap).call(this,{parent:this,id:n,x:s,y:i,uiManager:c(this,q),isCentered:!0,...e});r&&this.add(r)}async deserialize(t){var e;return await((e=c(ni,lr).get(t.annotationType??t.annotationEditorType))==null?void 0:e.deserialize(t,this,c(this,q)))||null}createAndAddNewEditor(t,e,s={}){const i=this.getNextId(),n=y(this,be,Ap).call(this,{parent:this,id:i,x:t.offsetX,y:t.offsetY,uiManager:c(this,q),isCentered:e,...s});return n&&this.add(n),n}addNewEditor(){this.createAndAddNewEditor(y(this,be,Tp).call(this),!0)}setSelected(t){c(this,q).setSelected(t)}toggleSelected(t){c(this,q).toggleSelected(t)}unselect(t){c(this,q).unselect(t)}pointerup(t){const{isMac:e}=Ne.platform;if(!(t.button!==0||t.ctrlKey&&e)&&t.target===this.div&&c(this,hr)){if(v(this,hr,!1),!c(this,Zo)){v(this,Zo,!0);return}if(c(this,q).getMode()===nt.STAMP){c(this,q).unselectAll();return}this.createAndAddNewEditor(t,!1)}}pointerdown(t){if(c(this,q).getMode()===nt.HIGHLIGHT&&this.enableTextSelection(),c(this,hr)){v(this,hr,!1);return}const{isMac:e}=Ne.platform;if(t.button!==0||t.ctrlKey&&e||t.target!==this.div)return;v(this,hr,!0);const s=c(this,q).getActive();v(this,Zo,!s||s.isEmpty())}findNewParent(t,e,s){const i=c(this,q).findParent(e,s);return i===null||i===this?!1:(i.changeParent(t),!0)}destroy(){var t,e;((t=c(this,q).getActive())==null?void 0:t.parent)===this&&(c(this,q).commitOrRemove(),c(this,q).setActiveEditor(null)),c(this,_n)&&(clearTimeout(c(this,_n)),v(this,_n,null));for(const s of c(this,ms).values())(e=c(this,Oa))==null||e.removePointerInTextLayer(s.contentDiv),s.setParent(null),s.isAttachedToDOM=!1,s.div.remove();this.div=null,c(this,ms).clear(),c(this,q).removeLayer(this)}render({viewport:t}){this.viewport=t,kr(this.div,t);for(const e of c(this,q).getEditors(this.pageIndex))this.add(e),e.rebuild();this.updateMode()}update({viewport:t}){c(this,q).commitOrRemove(),y(this,be,Ld).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 c(this,ms).values())i.rotate(s);this.addInkEditorIfNeeded(!1)}get pageDimensions(){const{pageWidth:t,pageHeight:e}=this.viewport.rawDims;return[t,e]}get scale(){return c(this,q).viewParameters.realScale}};Oa=new WeakMap,Zo=new WeakMap,Mi=new WeakMap,or=new WeakMap,_n=new WeakMap,ms=new WeakMap,hr=new WeakMap,th=new WeakMap,eh=new WeakMap,Oe=new WeakMap,wn=new WeakMap,q=new WeakMap,lr=new WeakMap,be=new WeakSet,Cy=function(t){c(this,q).unselectAll();const{target:e}=t;if(e===c(this,Oe).div||(e.getAttribute("role")==="img"||e.classList.contains("endOfContent"))&&c(this,Oe).div.contains(e)){const{isMac:s}=Ne.platform;if(t.button!==0||t.ctrlKey&&s)return;c(this,q).showAllEditors("highlight",!0,!0),c(this,Oe).div.classList.add("free"),this.toggleDrawing(),Bu.startHighlighting(this,c(this,q).direction==="ltr",{target:c(this,Oe).div,x:t.x,y:t.y}),c(this,Oe).div.addEventListener("pointerup",()=>{c(this,Oe).div.classList.remove("free"),this.toggleDrawing(!0)},{once:!0,signal:c(this,q)._signal}),t.preventDefault()}},Cp=function(){return c(ni,lr).get(c(this,q).getMode())},Ap=function(t){const e=c(this,be,Cp);return e?new e.prototype.constructor(t):null},Tp=function(){const{x:t,y:e,width:s,height:i}=this.div.getBoundingClientRect(),n=Math.max(0,t),r=Math.max(0,e),a=Math.min(window.innerWidth,t+s),h=Math.min(window.innerHeight,e+i),l=(n+a)/2-t,u=(r+h)/2-e,[d,g]=this.viewport.rotation%180===0?[l,u]:[u,l];return{offsetX:d,offsetY:g}},Ld=function(){v(this,th,!0);for(const t of c(this,ms).values())t.isEmpty()&&t.remove();v(this,th,!1)},tt(ni,"_initialized",!1),w(ni,lr,new Map([mf,bf,yf,Bu].map(t=>[t._editorType,t])));let _f=ni;const ye=class ye{constructor({pageIndex:t}){w(this,Pa);w(this,Oi,null);w(this,sc,0);w(this,Zt,new Map);w(this,xn,new Map);this.pageIndex=t}setParent(t){if(!c(this,Oi)){v(this,Oi,t);return}if(c(this,Oi)!==t){if(c(this,Zt).size>0)for(const e of c(this,Zt).values())e.remove(),t.append(e);v(this,Oi,t)}}static get _svgFactory(){return ut(this,"_svgFactory",new gf)}draw(t,e,s,i=!1){const n=Ge(this,sc)._++,r=y(this,Pa,kp).call(this,t.box);r.classList.add(...t.classNamesForDrawing);const a=ye._svgFactory.createElement("defs");r.append(a);const h=ye._svgFactory.createElement("path");a.append(h);const l=`path_p${this.pageIndex}_${n}`;h.setAttribute("id",l),h.setAttribute("d",t.toSVGPath()),i&&c(this,xn).set(n,h);const u=y(this,Pa,Ay).call(this,a,l),d=ye._svgFactory.createElement("use");return r.append(d),r.setAttribute("fill",e),r.setAttribute("fill-opacity",s),d.setAttribute("href",`#${l}`),c(this,Zt).set(n,r),{id:n,clipPathId:`url(#${u})`}}drawOutline(t){const e=Ge(this,sc)._++,s=y(this,Pa,kp).call(this,t.box);s.classList.add(...t.classNamesForOutlining);const i=ye._svgFactory.createElement("defs");s.append(i);const n=ye._svgFactory.createElement("path");i.append(n);const r=`path_p${this.pageIndex}_${e}`;n.setAttribute("id",r),n.setAttribute("d",t.toSVGPath()),n.setAttribute("vector-effect","non-scaling-stroke");let a;if(t.mustRemoveSelfIntersections){const u=ye._svgFactory.createElement("mask");i.append(u),a=`mask_p${this.pageIndex}_${e}`,u.setAttribute("id",a),u.setAttribute("maskUnits","objectBoundingBox");const d=ye._svgFactory.createElement("rect");u.append(d),d.setAttribute("width","1"),d.setAttribute("height","1"),d.setAttribute("fill","white");const g=ye._svgFactory.createElement("use");u.append(g),g.setAttribute("href",`#${r}`),g.setAttribute("stroke","none"),g.setAttribute("fill","black"),g.setAttribute("fill-rule","nonzero"),g.classList.add("mask")}const h=ye._svgFactory.createElement("use");s.append(h),h.setAttribute("href",`#${r}`),a&&h.setAttribute("mask",`url(#${a})`);const l=h.cloneNode();return s.append(l),h.classList.add("mainOutline"),l.classList.add("secondaryOutline"),c(this,Zt).set(e,s),e}finalizeLine(t,e){const s=c(this,xn).get(t);c(this,xn).delete(t),this.updateBox(t,e.box),s.setAttribute("d",e.toSVGPath())}updateLine(t,e){c(this,Zt).get(t).firstChild.firstChild.setAttribute("d",e.toSVGPath())}updatePath(t,e){c(this,xn).get(t).setAttribute("d",e.toSVGPath())}updateBox(t,e){var s;y(s=ye,ic,Ep).call(s,c(this,Zt).get(t),e)}show(t,e){c(this,Zt).get(t).classList.toggle("hidden",!e)}rotate(t,e){c(this,Zt).get(t).setAttribute("data-main-rotation",e)}changeColor(t,e){c(this,Zt).get(t).setAttribute("fill",e)}changeOpacity(t,e){c(this,Zt).get(t).setAttribute("fill-opacity",e)}addClass(t,e){c(this,Zt).get(t).classList.add(e)}removeClass(t,e){c(this,Zt).get(t).classList.remove(e)}getSVGRoot(t){return c(this,Zt).get(t)}remove(t){c(this,xn).delete(t),c(this,Oi)!==null&&(c(this,Zt).get(t).remove(),c(this,Zt).delete(t))}destroy(){v(this,Oi,null);for(const t of c(this,Zt).values())t.remove();c(this,Zt).clear(),c(this,xn).clear()}};Oi=new WeakMap,sc=new WeakMap,Zt=new WeakMap,xn=new WeakMap,ic=new WeakSet,Ep=function(t,{x:e=0,y:s=0,width:i=1,height:n=1}={}){const{style:r}=t;r.top=`${100*s}%`,r.left=`${100*e}%`,r.width=`${100*i}%`,r.height=`${100*n}%`},Pa=new WeakSet,kp=function(t){var s;const e=ye._svgFactory.create(1,1,!0);return c(this,Oi).append(e),e.setAttribute("aria-hidden",!0),y(s=ye,ic,Ep).call(s,e,t),e},Ay=function(t,e){const s=ye._svgFactory.createElement("clipPath");t.append(s);const i=`clip_${e}`;s.setAttribute("id",i),s.setAttribute("clipPathUnits","objectBoundingBox");const n=ye._svgFactory.createElement("use");return s.append(n),n.setAttribute("href",`#${e}`),n.classList.add("clip"),i},w(ye,ic);let wf=ye;et.AbortException,et.AnnotationEditorLayer,et.AnnotationEditorParamsType,et.AnnotationEditorType,et.AnnotationEditorUIManager,et.AnnotationLayer,et.AnnotationMode,et.ColorPicker,et.DOMSVGFactory,et.DrawLayer,et.FeatureTest;var yC=et.GlobalWorkerOptions;et.ImageKind,et.InvalidPDFException,et.MissingPDFException,et.OPS,et.OutputScale,et.PDFDataRangeTransport,et.PDFDateString,et.PDFWorker,et.PasswordResponses,et.PermissionFlag,et.PixelsPerInch,et.RenderingCancelledException,et.TextLayer,et.UnexpectedResponseException,et.Util,et.VerbosityLevel,et.XfaLayer,et.build,et.createValidAbsoluteUrl,et.fetchData;var _C=et.getDocument;et.getFilenameFromUrl,et.getPdfFilenameFromUrl,et.getXfaPageViewport,et.isDataScheme,et.isPdfFile,et.noContextMenu,et.normalizeUnicode,et.setLayerDimensions,et.shadow,et.version;const wC={fabric:"^6.5.1","pdfjs-dist":"4.8.69"};function xC(o){return new Promise((t,e)=>{const s=new FileReader;s.addEventListener("load",()=>t(s.result)),s.addEventListener("error",e),s.readAsDataURL(o)})}const SC=wC["pdfjs-dist"].replace("^","");yC.workerSrc=`https://cdnjs.cloudflare.com/ajax/libs/pdf.js/${SC}/pdf.worker.min.mjs`;async function CC(o){const t="data:application/pdf;base64,",e=await xC(o);if(typeof e=="string")return window.atob(e.slice(t.length))}function AC(o,t){return _C({data:o,password:t}).promise}const TC={top:100,left:50,scaleX:.5,scaleY:.5,borderColor:"black",cornerStrokeColor:"black",cornerSize:8,selectionBackgroundColor:"rgba(245, 245, 245, 0.8)"},EC={top:100,left:50,fontFamily:"helvetica",borderColor:"black",cornerStrokeColor:"black",scaleX:.7,scaleY:.7,cornerSize:8,selectionBackgroundColor:"rgba(245, 245, 245, 0.8)"},kC={stroke:"#000",hoverStroke:"#B7EC5D",src:""};function Fv(o=""){const t=K.useRef(0),e=K.useRef(null),s=K.useRef(null),i=K.useRef(1),n=K.useRef({...kC});function r(){if(!o||_s.has(o))return;const M=hx(o);return M.on("selection:cleared",()=>A(M)),M}function a(M,O){var j;const R=M.type,I={"application/pdf":h,"image/png":d,"image/jpeg":d};return((j=I[R])==null?void 0:j.call(I,M,O))??Promise.reject(new Error(`Unsupported ${R} file type.`))}async function h(M,O){const R=await CC(M);if(!R)return;const I=lx(M,R);try{return await l({page:1,PDFBase64:R,scale:.8,password:O}),{...I,pages:t.current}}catch(j){return Promise.reject(j)}}async function l({page:M,PDFBase64:O,scale:R,password:I}){try{const j=await AC(O,I),G=await j.getPage(M),{renderTask:L,canvas:H}=cx(G,R);return t.current=j.numPages,L.promise.then(()=>u(H))}catch(j){return Promise.reject(j)}}function u(M){dx(o,M)}async function d(M){return await gx(o,M)}async function g({url:M,scale:O=.5}){await N0(o,{url:M,scale:O})}async function f(M,O){const R=_s.get(o);if(!R)return;const I=await Ce.fromURL(M,{},{...TC,...O});R.add(I),m(R,I)}function p(M,O){const R=_s.get(o);if(!R)return;const I=new Se(M,{...EC,...O});R.add(I),m(R,I)}function m(M,O){O.on("selected",R=>_({canvas:M,target:R.target})),O.on("modified",R=>Mh(R.target,e.current)),O.on("scaling",R=>Mh(R.transform.target,e.current)),O.on("moving",R=>Mh(R.transform.target,e.current)),O.on("rotating",R=>Mh(R.transform.target,e.current))}async function _({canvas:M,target:O,stroke:R=n.current.stroke,uuid:I=Date.now()}){var G;if(((G=e.current)==null?void 0:G.stroke)===`${R}-${I}`)return;const j=await ux(n.current.src,R,I);A(M),e.current=j,s.current=O,b(M,O,I),x(i.current,!0),M.add(j)}function b(M,O,R){e.current&&(e.current.on("selected",()=>{M.remove(O),A(M)}),e.current.on("mouseover",()=>{_({canvas:M,target:O,stroke:n.current.hoverStroke,uuid:R})}),e.current.on("mouseout",()=>{_({canvas:M,target:O,stroke:n.current.stroke,uuid:R})}))}function x(M,O=!1){const R=_s.get(o);i.current=M,R&&(px(s.current,M,n.current),fx(s.current,M,e.current),!O&&R.renderAll())}function S(M){if(!M)return;n.current={...n.current,...M};const O=_s.get(o);!e||!s.current||!O||_({target:s.current,canvas:O})}function A(M){e.current&&(M.remove(e.current),e.current=s.current=null)}function k(){mx(o)}function P(){vx(o)}return{createCanvas:r,loadFile:a,specifyPage:l,renderImage:g,addFabric:f,addTextFabric:p,clearActive:k,deleteCanvas:P,scaleFabric:x,setCloseSvgOptions:S}}function MC(o){let t=0;const e=ox(()=>{t!==window.innerWidth&&(t=window.innerWidth,o())});K.useEffect(()=>(window.addEventListener("resize",e),()=>window.removeEventListener("resize",e)),[])}const OC=K.forwardRef(PC);function PC({file:o,page:t=1,canvasId:e="PDF-canvas",fileZoom:s=1,fileScale:i=1,canvasScale:n=1,canvasClass:r="",isDrop:a=!1,password:h,dropTextOptions:l,dropImageOptions:u,closeSvgOptions:d},g){const f=K.useRef(null),p=`${e}-${t-1}`,m=K.useMemo(()=>s*n,[s,n]),{createCanvas:_,specifyPage:b,addFabric:x,addTextFabric:S,renderImage:A,clearActive:k,deleteCanvas:P,scaleFabric:M,setCloseSvgOptions:O}=Fv(p);MC(R);async function R(){window.requestAnimationFrame(async()=>{if(_(),o.PDFBase64.startsWith("data:image")||o.canvas){const{canvas:L}=o,H=L?7:3,$=L!=null&&L.length?L[t-1]:o.PDFBase64;A({url:$,scale:i/H});return}await b({page:t,PDFBase64:o.PDFBase64,scale:i,password:h})})}function I(L){if(L.preventDefault(),L.stopPropagation(),!a||!L.dataTransfer)return;const{dataTransfer:H,clientX:$,clientY:J}=L,Y=H.getData("text"),X=H.getData("image"),Ot={left:$-71,top:J-55};X&&j(X,Ot),Y&&G(Y,Ot)}function j(L,H){x(L,{...H,...u})}function G(L,H){S(L,{...H,...l})}return K.useImperativeHandle(g,()=>({addImage:j,addText:G,clearActive:k,deleteCanvas:P,canvasRef:f})),K.useEffect(()=>{R()},[i,t,o,h]),K.useEffect(()=>{M(m)},[m]),K.useEffect(()=>{O(d)},[d]),K.useEffect(()=>()=>P(),[]),Pp.jsx("div",{style:{transform:`scale(${m})`},onDragOver:L=>L.preventDefault(),onDragEnter:L=>L.preventDefault(),onDrop:I,children:Pp.jsx("canvas",{id:p,ref:f,className:r})})}const Hu=Object.freeze(Object.defineProperty({__proto__:null,default:{}},Symbol.toStringTag,{value:"Module"}));ct.default=OC,ct.useFabric=Fv,Object.defineProperties(ct,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
|