@component-hook/pdf-canvas 1.3.2-alpha.0 → 1.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
React keys must be passed directly to JSX without using spread:
|
|
5
5
|
let props = %s;
|
|
6
6
|
<%s key={someKey} {...props} />`,Q,N,ft,N),dt[N+Q]=!0)}if(N=null,V!==void 0&&(e(V),N=""+V),r(H)&&(e(H.key),N=""+H.key),"key"in H){V={};for(var kt in H)kt!=="key"&&(V[kt]=H[kt])}else V=H;return N&&o(V,typeof E=="function"?E.displayName||E.name||"Unknown":E),l(E,N,V,i(),Mt,rt)}function u(E){d(E)?E._store&&(E._store.validated=1):typeof E=="object"&&E!==null&&E.$$typeof===P&&(E._payload.status==="fulfilled"?d(E._payload.value)&&E._payload.value._store&&(E._payload.value._store.validated=1):E._store&&(E._store.validated=1))}function d(E){return typeof E=="object"&&E!==null&&E.$$typeof===g}var f=J,g=Symbol.for("react.transitional.element"),p=Symbol.for("react.portal"),b=Symbol.for("react.fragment"),m=Symbol.for("react.strict_mode"),v=Symbol.for("react.profiler"),y=Symbol.for("react.consumer"),_=Symbol.for("react.context"),S=Symbol.for("react.forward_ref"),A=Symbol.for("react.suspense"),T=Symbol.for("react.suspense_list"),k=Symbol.for("react.memo"),P=Symbol.for("react.lazy"),B=Symbol.for("react.activity"),F=Symbol.for("react.client.reference"),I=f.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,O=Object.prototype.hasOwnProperty,D=Array.isArray,z=console.createTask?console.createTask:function(){return null};f={react_stack_bottom_frame:function(E){return E()}};var M,R={},U=f.react_stack_bottom_frame.bind(f,n)(),ht=z(s(n)),dt={};Us.Fragment=b,Us.jsx=function(E,H,V){var Q=1e4>I.recentlyCreatedOwnerStacks++;return c(E,H,V,!1,Q?Error("react-stack-top-frame"):U,Q?z(s(E)):ht)},Us.jsxs=function(E,H,V){var Q=1e4>I.recentlyCreatedOwnerStacks++;return c(E,H,V,!0,Q?Error("react-stack-top-frame"):U,Q?z(s(E)):ht)}})()),Us}var Do;function ec(){return Do||(Do=1,process.env.NODE_ENV==="production"?Oe.exports=Ql():Oe.exports=tc()),Oe.exports}var Ro=ec();const sc="data:image/svg+xml,%3csvg%20width='24'%20height='24'%20viewBox='0%200%2040%2040'%20fill='none'%20xmlns='http://www.w3.org/2000/svg'%3e%3ccircle%20cx='20'%20cy='20'%20r='10.75'%20stroke='currentColor'%20stroke-width='2.5'/%3e%3cpath%20d='M16%2024L23.7782%2016.2218'%20stroke='currentColor'%20stroke-width='2.5'%20stroke-linecap='round'/%3e%3cpath%20d='M24%2024L16.2218%2016.2218'%20stroke='currentColor'%20stroke-width='2.5'%20stroke-linecap='round'/%3e%3c/svg%3e",ic={top:100,left:50,scaleX:.5,scaleY:.5,borderColor:"black",cornerStrokeColor:"black",cornerSize:6,selectionBackgroundColor:"rgba(245, 245, 245, 0.8)"},nc={top:100,left:50,fontFamily:"helvetica",borderColor:"black",cornerStrokeColor:"black",scaleX:.7,scaleY:.7,cornerSize:6,selectionBackgroundColor:"rgba(245, 245, 245, 0.8)"},rc={borderColor:"black",cornerStrokeColor:"black",cornerSize:8,selectionBackgroundColor:"rgba(245, 245, 245, 0.8)"},oc={stroke:"#000",hoverStroke:"#B7EC5D",src:sc},ac=["borderColor","cornerStrokeColor","cornerSize","_cornerSize","selectionBackgroundColor"];function x(a,t,e){return(t=(function(s){var i=(function(n,r){if(typeof n!="object"||!n)return n;var o=n[Symbol.toPrimitive];if(o!==void 0){var h=o.call(n,r);if(typeof h!="object")return h;throw new TypeError("@@toPrimitive must return a primitive value.")}return(r==="string"?String:Number)(n)})(s,"string");return typeof i=="symbol"?i:i+""})(t))in a?Object.defineProperty(a,t,{value:e,enumerable:!0,configurable:!0,writable:!0}):a[t]=e,a}function Lo(a,t){var e=Object.keys(a);if(Object.getOwnPropertySymbols){var s=Object.getOwnPropertySymbols(a);t&&(s=s.filter((function(i){return Object.getOwnPropertyDescriptor(a,i).enumerable}))),e.push.apply(e,s)}return e}function w(a){for(var t=1;t<arguments.length;t++){var e=arguments[t]!=null?arguments[t]:{};t%2?Lo(Object(e),!0).forEach((function(s){x(a,s,e[s])})):Object.getOwnPropertyDescriptors?Object.defineProperties(a,Object.getOwnPropertyDescriptors(e)):Lo(Object(e)).forEach((function(s){Object.defineProperty(a,s,Object.getOwnPropertyDescriptor(e,s))}))}return a}function lt(a,t){if(a==null)return{};var e,s,i=(function(r,o){if(r==null)return{};var h={};for(var l in r)if({}.hasOwnProperty.call(r,l)){if(o.indexOf(l)>=0)continue;h[l]=r[l]}return h})(a,t);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(a);for(s=0;s<n.length;s++)e=n[s],t.indexOf(e)>=0||{}.propertyIsEnumerable.call(a,e)&&(i[e]=a[e])}return i}function _e(a,t){return t||(t=a.slice(0)),Object.freeze(Object.defineProperties(a,{raw:{value:Object.freeze(t)}}))}class Fo{constructor(){x(this,"browserShadowBlurConstant",1),x(this,"DPI",96),x(this,"devicePixelRatio",typeof window<"u"?window.devicePixelRatio:1),x(this,"perfLimitSizeTotal",2097152),x(this,"maxCacheSideLimit",4096),x(this,"minCacheSideLimit",256),x(this,"disableStyleCopyPaste",!1),x(this,"enableGLFiltering",!0),x(this,"textureSize",4096),x(this,"forceGLPutImageData",!1),x(this,"cachesBoundsOfCurve",!1),x(this,"fontPaths",{}),x(this,"NUM_FRACTION_DIGITS",4)}}const et=new class extends Fo{constructor(a){super(),this.configure(a)}configure(){let a=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};Object.assign(this,a)}addFonts(){let a=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};this.fontPaths=w(w({},this.fontPaths),a)}removeFonts(){(arguments.length>0&&arguments[0]!==void 0?arguments[0]:[]).forEach((a=>{delete this.fontPaths[a]}))}clearFonts(){this.fontPaths={}}restoreDefaults(a){const t=new Fo,e=a?.reduce(((s,i)=>(s[i]=t[i],s)),{})||t;this.configure(e)}},De=function(a){for(var t=arguments.length,e=new Array(t>1?t-1:0),s=1;s<t;s++)e[s-1]=arguments[s];return console[a]("fabric",...e)};class we extends Error{constructor(t,e){super("fabric: ".concat(t),e)}}class Kn extends we{constructor(t){super("".concat(t," 'options.signal' is in 'aborted' state"))}}class hc{}class lc extends hc{testPrecision(t,e){const s="precision ".concat(e,` float;
|
|
7
|
-
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(),De("log","WebGL: max texture size ".concat(this.maxTextureSize)))}isSupported(t){return!!this.maxTextureSize&&this.maxTextureSize>=t}}const cc={};let Io;const xe=()=>Io||(Io={document,window,isTouchSupported:"ontouchstart"in window||"ontouchstart"in document||window&&window.navigator&&window.navigator.maxTouchPoints>0,WebGLProbe:new lc,dispose(){},copyPasteData:cc}),xs=()=>xe().document,Ys=()=>xe().window,No=()=>{var a;return Math.max((a=et.devicePixelRatio)!==null&&a!==void 0?a:Ys().devicePixelRatio,1)},$s=new class{constructor(){x(this,"boundsOfCurveCache",{}),this.charWidthsCache=new Map}getFontCache(a){let{fontFamily:t,fontStyle:e,fontWeight:s}=a;t=t.toLowerCase();const i=this.charWidthsCache;i.has(t)||i.set(t,new Map);const n=i.get(t),r="".concat(e.toLowerCase(),"_").concat((s+"").toLowerCase());return n.has(r)||n.set(r,new Map),n.get(r)}clearFontCache(a){a?this.charWidthsCache.delete((a||"").toLowerCase()):this.charWidthsCache=new Map}limitDimsByArea(a){const{perfLimitSizeTotal:t}=et,e=Math.sqrt(t*a);return[Math.floor(e),Math.floor(t/e)]}},Jn="6.9.0";function es(){}const We=Math.PI/2,Re=2*Math.PI,Zn=Math.PI/180,Nt=Object.freeze([1,0,0,1,0,0]),Qn=16,Xe=.4477152502,$="center",it="left",Yt="top",tr="bottom",bt="right",jt="none",er=/\r?\n/,jo="moving",Ti="scaling",Bo="rotating",sr="rotate",Ho="skewing",qs="resizing",uc="modifyPoly",dc="modifyPath",Ei="changed",ki="scale",Bt="scaleX",Qt="scaleY",Ss="skewX",Cs="skewY",wt="fill",Ht="stroke",Mi="modified",As="json",ir="svg",L=new class{constructor(){this[As]=new Map,this[ir]=new Map}has(a){return this[As].has(a)}getClass(a){const t=this[As].get(a);if(!t)throw new we("No class registered for ".concat(a));return t}setClass(a,t){t?this[As].set(t,a):(this[As].set(a.type,a),this[As].set(a.type.toLowerCase(),a))}getSVGClass(a){return this[ir].get(a)}setSVGClass(a,t){this[ir].set(t??a.type.toLowerCase(),a)}},Pi=new class extends Array{remove(a){const t=this.indexOf(a);t>-1&&this.splice(t,1)}cancelAll(){const a=this.splice(0);return a.forEach((t=>t.abort())),a}cancelByCanvas(a){if(!a)return[];const t=this.filter((e=>{var s;return e.target===a||typeof e.target=="object"&&((s=e.target)===null||s===void 0?void 0:s.canvas)===a}));return t.forEach((e=>e.abort())),t}cancelByTarget(a){if(!a)return[];const t=this.filter((e=>e.target===a));return t.forEach((e=>e.abort())),t}};class fc{constructor(){x(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 ss=(a,t)=>{const e=a.indexOf(t);return e!==-1&&a.splice(e,1),a},le=a=>{if(a===0)return 1;switch(Math.abs(a)/We){case 1:case 3:return 0;case 2:return-1}return Math.cos(a)},ce=a=>{if(a===0)return 0;const t=a/We,e=Math.sign(a);switch(t){case 1:return e;case 2:return 0;case 3:return-e}return Math.sin(a)};class C{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 C(this.x+t.x,this.y+t.y)}addEquals(t){return this.x+=t.x,this.y+=t.y,this}scalarAdd(t){return new C(this.x+t,this.y+t)}scalarAddEquals(t){return this.x+=t,this.y+=t,this}subtract(t){return new C(this.x-t.x,this.y-t.y)}subtractEquals(t){return this.x-=t.x,this.y-=t.y,this}scalarSubtract(t){return new C(this.x-t,this.y-t)}scalarSubtractEquals(t){return this.x-=t,this.y-=t,this}multiply(t){return new C(this.x*t.x,this.y*t.y)}scalarMultiply(t){return new C(this.x*t,this.y*t)}scalarMultiplyEquals(t){return this.x*=t,this.y*=t,this}divide(t){return new C(this.x/t.x,this.y/t.y)}scalarDivide(t){return new C(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 C(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 C(Math.min(this.x,t.x),Math.min(this.y,t.y))}max(t){return new C(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 C(this.x,this.y)}rotate(t){let e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:nr;const s=ce(t),i=le(t),n=this.subtract(e);return new C(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 C(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 nr=new C(0,0),Oi=a=>!!a&&Array.isArray(a._objects);function zo(a){class t extends a{constructor(){super(...arguments),x(this,"_objects",[])}_onObjectAdded(s){}_onObjectRemoved(s){}_onStackOrderChanged(s){}add(){for(var s=arguments.length,i=new Array(s),n=0;n<s;n++)i[n]=arguments[n];const r=this._objects.push(...i);return i.forEach((o=>this._onObjectAdded(o))),r}insertAt(s){for(var i=arguments.length,n=new Array(i>1?i-1:0),r=1;r<i;r++)n[r-1]=arguments[r];return this._objects.splice(s,0,...n),n.forEach((o=>this._onObjectAdded(o))),this._objects.length}remove(){const s=this._objects,i=[];for(var n=arguments.length,r=new Array(n),o=0;o<n;o++)r[o]=arguments[o];return r.forEach((h=>{const l=s.indexOf(h);l!==-1&&(s.splice(l,1),i.push(h),this._onObjectRemoved(h))})),i}forEachObject(s){this.getObjects().forEach(((i,n,r)=>s(i,n,r)))}getObjects(){for(var s=arguments.length,i=new Array(s),n=0;n<s;n++)i[n]=arguments[n];return i.length===0?[...this._objects]:this._objects.filter((r=>r.isType(...i)))}item(s){return this._objects[s]}isEmpty(){return this._objects.length===0}size(){return this._objects.length}contains(s,i){return!!this._objects.includes(s)||!!i&&this._objects.some((n=>n instanceof t&&n.contains(s,!0)))}complexity(){return this._objects.reduce(((s,i)=>s+=i.complexity?i.complexity():0),0)}sendObjectToBack(s){return!(!s||s===this._objects[0])&&(ss(this._objects,s),this._objects.unshift(s),this._onStackOrderChanged(s),!0)}bringObjectToFront(s){return!(!s||s===this._objects[this._objects.length-1])&&(ss(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 ss(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 ss(this._objects,s),this._objects.splice(r,0,s),this._onStackOrderChanged(s),!0}return!1}moveObjectTo(s,i){return s!==this._objects[i]&&(ss(this._objects,s),this._objects.splice(i,0,s),this._onStackOrderChanged(s),!0)}findNewLowerIndex(s,i,n){let r;if(n){r=i;for(let o=i-1;o>=0;--o)if(s.isOverlapping(this._objects[o])){r=o;break}}else r=i-1;return r}findNewUpperIndex(s,i,n){let r;if(n){r=i;for(let o=i+1;o<this._objects.length;++o)if(s.isOverlapping(this._objects[o])){r=o;break}}else r=i+1;return r}collectObjects(s){let{left:i,top:n,width:r,height:o}=s,{includeIntersecting:h=!0}=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};const l=[],c=new C(i,n),u=c.add(new C(r,o));for(let d=this._objects.length-1;d>=0;d--){const f=this._objects[d];f.selectable&&f.visible&&(h&&f.intersectsWithRect(c,u)||f.isContainedWithinRect(c,u)||h&&f.containsPoint(c)||h&&f.containsPoint(u))&&l.push(f)}return l}}return t}class Go extends fc{_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 Ks(a){return Ys().requestAnimationFrame(a)}function Vo(a){return Ys().cancelAnimationFrame(a)}let gc=0;const Ue=()=>gc++,Se=()=>{const a=xs().createElement("canvas");if(!a||a.getContext===void 0)throw new we("Failed to create `canvas` element");return a},Wo=()=>xs().createElement("img"),te=a=>{const t=Se();return t.width=a.width,t.height=a.height,t},rr=(a,t,e)=>a.toDataURL("image/".concat(t),e),or=(a,t,e)=>new Promise(((s,i)=>{a.toBlob(s,"image/".concat(t),e)})),pt=a=>a*Zn,Ce=a=>a/Zn,Xo=a=>a.every(((t,e)=>t===Nt[e])),Pt=(a,t,e)=>new C(a).transform(t,e),$t=a=>{const t=1/(a[0]*a[3]-a[1]*a[2]),e=[t*a[3],-t*a[1],-t*a[2],t*a[0],0,0],{x:s,y:i}=new C(a[4],a[5]).transform(e,!0);return e[4]=-s,e[5]=-i,e},vt=(a,t,e)=>[a[0]*t[0]+a[2]*t[1],a[1]*t[0]+a[3]*t[1],a[0]*t[2]+a[2]*t[3],a[1]*t[2]+a[3]*t[3],e?0:a[0]*t[4]+a[2]*t[5]+a[4],e?0:a[1]*t[4]+a[3]*t[5]+a[5]],Di=(a,t)=>a.reduceRight(((e,s)=>s&&e?vt(s,e,t):s||e),void 0)||Nt.concat(),Uo=a=>{let[t,e]=a;return Math.atan2(e,t)},is=a=>{const t=Uo(a),e=Math.pow(a[0],2)+Math.pow(a[1],2),s=Math.sqrt(e),i=(a[0]*a[3]-a[2]*a[1])/s,n=Math.atan2(a[0]*a[2]+a[1]*a[3],e);return{angle:Ce(t),scaleX:s,scaleY:i,skewX:Ce(n),skewY:0,translateX:a[4]||0,translateY:a[5]||0}},Ts=function(a){return[1,0,0,1,a,arguments.length>1&&arguments[1]!==void 0?arguments[1]:0]};function ns(){let{angle:a=0}=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},{x:t=0,y:e=0}=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};const s=pt(a),i=le(s),n=ce(s);return[i,n,-n,i,t?t-(i*t-n*e):0,e?e-(n*t+i*e):0]}const Ri=function(a){return[a,0,0,arguments.length>1&&arguments[1]!==void 0?arguments[1]:a,0,0]},Yo=a=>Math.tan(pt(a)),ar=a=>[1,0,Yo(a),1,0,0],hr=a=>[1,Yo(a),0,1,0,0],Js=a=>{let{scaleX:t=1,scaleY:e=1,flipX:s=!1,flipY:i=!1,skewX:n=0,skewY:r=0}=a,o=Ri(s?-t:t,i?-e:e);return n&&(o=vt(o,ar(n),!0)),r&&(o=vt(o,hr(r),!0)),o},$o=a=>{const{translateX:t=0,translateY:e=0,angle:s=0}=a;let i=Ts(t,e);s&&(i=vt(i,ns({angle:s})));const n=Js(a);return Xo(n)||(i=vt(i,n)),i},Zs=function(a){let{signal:t,crossOrigin:e=null}=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};return new Promise((function(s,i){if(t&&t.aborted)return i(new Kn("loadImage"));const n=Wo();let r;t&&(r=function(h){n.src="",i(h)},t.addEventListener("abort",r,{once:!0}));const o=function(){n.onload=n.onerror=null,r&&t?.removeEventListener("abort",r),s(n)};a?(n.onload=o,n.onerror=function(){r&&t?.removeEventListener("abort",r),i(new we("Error loading ".concat(n.src)))},e&&(n.crossOrigin=e),n.src=a):o()}))},Es=function(a){let{signal:t,reviver:e=es}=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};return new Promise(((s,i)=>{const n=[];t&&t.addEventListener("abort",i,{once:!0}),Promise.all(a.map((r=>L.getClass(r.type).fromObject(r,{signal:t}).then((o=>(e(r,o),n.push(o),o)))))).then(s).catch((r=>{n.forEach((o=>{o.dispose&&o.dispose()})),i(r)})).finally((()=>{t&&t.removeEventListener("abort",i)}))}))},Qs=function(a){let{signal:t}=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};return new Promise(((e,s)=>{const i=[];t&&t.addEventListener("abort",s,{once:!0});const n=Object.values(a).map((o=>o&&o.type&&L.has(o.type)?Es([o],{signal:t}).then((h=>{let[l]=h;return i.push(l),l})):o)),r=Object.keys(a);Promise.all(n).then((o=>o.reduce(((h,l,c)=>(h[r[c]]=l,h)),{}))).then(e).catch((o=>{i.forEach((h=>{h.dispose&&h.dispose()})),s(o)})).finally((()=>{t&&t.removeEventListener("abort",s)}))}))},rs=function(a){return(arguments.length>1&&arguments[1]!==void 0?arguments[1]:[]).reduce(((t,e)=>(e in a&&(t[e]=a[e]),t)),{})},lr=(a,t)=>Object.keys(a).reduce(((e,s)=>(t(a[s],s,a)&&(e[s]=a[s]),e)),{}),ot=(a,t)=>parseFloat(Number(a).toFixed(t)),ks=a=>"matrix("+a.map((t=>ot(t,et.NUM_FRACTION_DIGITS))).join(" ")+")",re=a=>!!a&&a.toLive!==void 0,qo=a=>!!a&&typeof a.toObject=="function",Ko=a=>!!a&&a.offsetX!==void 0&&"source"in a,os=a=>!!a&&"multiSelectionStacking"in a;function Jo(a){const t=a&&ue(a);let e=0,s=0;if(!a||!t)return{left:e,top:s};let i=a;const n=t.documentElement,r=t.body||{scrollLeft:0,scrollTop:0};for(;i&&(i.parentNode||i.host)&&(i=i.parentNode||i.host,i===t?(e=r.scrollLeft||n.scrollLeft||0,s=r.scrollTop||n.scrollTop||0):(e+=i.scrollLeft||0,s+=i.scrollTop||0),i.nodeType!==1||i.style.position!=="fixed"););return{left:e,top:s}}const ue=a=>a.ownerDocument||null,Zo=a=>{var t;return((t=a.ownerDocument)===null||t===void 0?void 0:t.defaultView)||null},Qo=function(a,t,e){let{width:s,height:i}=e,n=arguments.length>3&&arguments[3]!==void 0?arguments[3]:1;a.width=s,a.height=i,n>1&&(a.setAttribute("width",(s*n).toString()),a.setAttribute("height",(i*n).toString()),t.scale(n,n))},cr=(a,t)=>{let{width:e,height:s}=t;e&&(a.style.width=typeof e=="number"?"".concat(e,"px"):e),s&&(a.style.height=typeof s=="number"?"".concat(s,"px"):s)};function ta(a){return a.onselectstart!==void 0&&(a.onselectstart=()=>!1),a.style.userSelect=jt,a}class ea{constructor(t){x(this,"_originalCanvasStyle",void 0),x(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&&xs().getElementById(t)||Se();var s;if(e.hasAttribute("data-fabric"))throw new we("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;Qo(s,i,t,e)}setCSSDimensions(t){cr(this.lower.el,t)}calcOffset(){return(function(t){var e;const s=t&&ue(t),i={left:0,top:0};if(!s)return i;const n=((e=Zo(t))===null||e===void 0?void 0:e.getComputedStyle(t,null))||{};i.left+=parseInt(n.borderLeftWidth,10)||0,i.top+=parseInt(n.borderTopWidth,10)||0,i.left+=parseInt(n.paddingLeft,10)||0,i.top+=parseInt(n.paddingTop,10)||0;let r={left:0,top:0};const o=s.documentElement;t.getBoundingClientRect!==void 0&&(r=t.getBoundingClientRect());const h=Jo(t);return{left:r.left+h.left-(o.clientLeft||0)+i.left,top:r.top+h.top-(o.clientTop||0)+i.top}})(this.lower.el)}dispose(){xe().dispose(this.lower.el),delete this.lower}}const pc={backgroundVpt:!0,backgroundColor:"",overlayVpt:!0,overlayColor:"",includeDefaultValues:!0,svgViewportTransformation:!0,renderOnAddRemove:!0,skipOffscreen:!0,enableRetinaScaling:!0,imageSmoothingEnabled:!0,controlsAboveOverlay:!1,allowTouchScrolling:!1,viewportTransform:[...Nt]},mc=["objects"];class ti extends zo(Go){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 ti.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 ea(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&&(De("warn",`Canvas is trying to add an object that belongs to a different canvas.
|
|
7
|
+
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(),De("log","WebGL: max texture size ".concat(this.maxTextureSize)))}isSupported(t){return!!this.maxTextureSize&&this.maxTextureSize>=t}}const cc={};let Io;const xe=()=>Io||(Io={document,window,isTouchSupported:"ontouchstart"in window||"ontouchstart"in document||window&&window.navigator&&window.navigator.maxTouchPoints>0,WebGLProbe:new lc,dispose(){},copyPasteData:cc}),xs=()=>xe().document,Ys=()=>xe().window,No=()=>{var a;return Math.max((a=et.devicePixelRatio)!==null&&a!==void 0?a:Ys().devicePixelRatio,1)},$s=new class{constructor(){x(this,"boundsOfCurveCache",{}),this.charWidthsCache=new Map}getFontCache(a){let{fontFamily:t,fontStyle:e,fontWeight:s}=a;t=t.toLowerCase();const i=this.charWidthsCache;i.has(t)||i.set(t,new Map);const n=i.get(t),r="".concat(e.toLowerCase(),"_").concat((s+"").toLowerCase());return n.has(r)||n.set(r,new Map),n.get(r)}clearFontCache(a){a?this.charWidthsCache.delete((a||"").toLowerCase()):this.charWidthsCache=new Map}limitDimsByArea(a){const{perfLimitSizeTotal:t}=et,e=Math.sqrt(t*a);return[Math.floor(e),Math.floor(t/e)]}},Jn="6.9.1";function es(){}const We=Math.PI/2,Re=2*Math.PI,Zn=Math.PI/180,Nt=Object.freeze([1,0,0,1,0,0]),Qn=16,Xe=.4477152502,$="center",it="left",Yt="top",tr="bottom",bt="right",jt="none",er=/\r?\n/,jo="moving",Ti="scaling",Bo="rotating",sr="rotate",Ho="skewing",qs="resizing",uc="modifyPoly",dc="modifyPath",Ei="changed",ki="scale",Bt="scaleX",Qt="scaleY",Ss="skewX",Cs="skewY",wt="fill",Ht="stroke",Mi="modified",As="json",ir="svg",L=new class{constructor(){this[As]=new Map,this[ir]=new Map}has(a){return this[As].has(a)}getClass(a){const t=this[As].get(a);if(!t)throw new we("No class registered for ".concat(a));return t}setClass(a,t){t?this[As].set(t,a):(this[As].set(a.type,a),this[As].set(a.type.toLowerCase(),a))}getSVGClass(a){return this[ir].get(a)}setSVGClass(a,t){this[ir].set(t??a.type.toLowerCase(),a)}},Pi=new class extends Array{remove(a){const t=this.indexOf(a);t>-1&&this.splice(t,1)}cancelAll(){const a=this.splice(0);return a.forEach((t=>t.abort())),a}cancelByCanvas(a){if(!a)return[];const t=this.filter((e=>{var s;return e.target===a||typeof e.target=="object"&&((s=e.target)===null||s===void 0?void 0:s.canvas)===a}));return t.forEach((e=>e.abort())),t}cancelByTarget(a){if(!a)return[];const t=this.filter((e=>e.target===a));return t.forEach((e=>e.abort())),t}};class fc{constructor(){x(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 ss=(a,t)=>{const e=a.indexOf(t);return e!==-1&&a.splice(e,1),a},le=a=>{if(a===0)return 1;switch(Math.abs(a)/We){case 1:case 3:return 0;case 2:return-1}return Math.cos(a)},ce=a=>{if(a===0)return 0;const t=a/We,e=Math.sign(a);switch(t){case 1:return e;case 2:return 0;case 3:return-e}return Math.sin(a)};class C{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 C(this.x+t.x,this.y+t.y)}addEquals(t){return this.x+=t.x,this.y+=t.y,this}scalarAdd(t){return new C(this.x+t,this.y+t)}scalarAddEquals(t){return this.x+=t,this.y+=t,this}subtract(t){return new C(this.x-t.x,this.y-t.y)}subtractEquals(t){return this.x-=t.x,this.y-=t.y,this}scalarSubtract(t){return new C(this.x-t,this.y-t)}scalarSubtractEquals(t){return this.x-=t,this.y-=t,this}multiply(t){return new C(this.x*t.x,this.y*t.y)}scalarMultiply(t){return new C(this.x*t,this.y*t)}scalarMultiplyEquals(t){return this.x*=t,this.y*=t,this}divide(t){return new C(this.x/t.x,this.y/t.y)}scalarDivide(t){return new C(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 C(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 C(Math.min(this.x,t.x),Math.min(this.y,t.y))}max(t){return new C(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 C(this.x,this.y)}rotate(t){let e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:nr;const s=ce(t),i=le(t),n=this.subtract(e);return new C(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 C(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 nr=new C(0,0),Oi=a=>!!a&&Array.isArray(a._objects);function zo(a){class t extends a{constructor(){super(...arguments),x(this,"_objects",[])}_onObjectAdded(s){}_onObjectRemoved(s){}_onStackOrderChanged(s){}add(){for(var s=arguments.length,i=new Array(s),n=0;n<s;n++)i[n]=arguments[n];const r=this._objects.push(...i);return i.forEach((o=>this._onObjectAdded(o))),r}insertAt(s){for(var i=arguments.length,n=new Array(i>1?i-1:0),r=1;r<i;r++)n[r-1]=arguments[r];return this._objects.splice(s,0,...n),n.forEach((o=>this._onObjectAdded(o))),this._objects.length}remove(){const s=this._objects,i=[];for(var n=arguments.length,r=new Array(n),o=0;o<n;o++)r[o]=arguments[o];return r.forEach((h=>{const l=s.indexOf(h);l!==-1&&(s.splice(l,1),i.push(h),this._onObjectRemoved(h))})),i}forEachObject(s){this.getObjects().forEach(((i,n,r)=>s(i,n,r)))}getObjects(){for(var s=arguments.length,i=new Array(s),n=0;n<s;n++)i[n]=arguments[n];return i.length===0?[...this._objects]:this._objects.filter((r=>r.isType(...i)))}item(s){return this._objects[s]}isEmpty(){return this._objects.length===0}size(){return this._objects.length}contains(s,i){return!!this._objects.includes(s)||!!i&&this._objects.some((n=>n instanceof t&&n.contains(s,!0)))}complexity(){return this._objects.reduce(((s,i)=>s+=i.complexity?i.complexity():0),0)}sendObjectToBack(s){return!(!s||s===this._objects[0])&&(ss(this._objects,s),this._objects.unshift(s),this._onStackOrderChanged(s),!0)}bringObjectToFront(s){return!(!s||s===this._objects[this._objects.length-1])&&(ss(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 ss(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 ss(this._objects,s),this._objects.splice(r,0,s),this._onStackOrderChanged(s),!0}return!1}moveObjectTo(s,i){return s!==this._objects[i]&&(ss(this._objects,s),this._objects.splice(i,0,s),this._onStackOrderChanged(s),!0)}findNewLowerIndex(s,i,n){let r;if(n){r=i;for(let o=i-1;o>=0;--o)if(s.isOverlapping(this._objects[o])){r=o;break}}else r=i-1;return r}findNewUpperIndex(s,i,n){let r;if(n){r=i;for(let o=i+1;o<this._objects.length;++o)if(s.isOverlapping(this._objects[o])){r=o;break}}else r=i+1;return r}collectObjects(s){let{left:i,top:n,width:r,height:o}=s,{includeIntersecting:h=!0}=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};const l=[],c=new C(i,n),u=c.add(new C(r,o));for(let d=this._objects.length-1;d>=0;d--){const f=this._objects[d];f.selectable&&f.visible&&(h&&f.intersectsWithRect(c,u)||f.isContainedWithinRect(c,u)||h&&f.containsPoint(c)||h&&f.containsPoint(u))&&l.push(f)}return l}}return t}class Go extends fc{_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 Ks(a){return Ys().requestAnimationFrame(a)}function Vo(a){return Ys().cancelAnimationFrame(a)}let gc=0;const Ue=()=>gc++,Se=()=>{const a=xs().createElement("canvas");if(!a||a.getContext===void 0)throw new we("Failed to create `canvas` element");return a},Wo=()=>xs().createElement("img"),te=a=>{const t=Se();return t.width=a.width,t.height=a.height,t},rr=(a,t,e)=>a.toDataURL("image/".concat(t),e),or=(a,t,e)=>new Promise(((s,i)=>{a.toBlob(s,"image/".concat(t),e)})),pt=a=>a*Zn,Ce=a=>a/Zn,Xo=a=>a.every(((t,e)=>t===Nt[e])),Pt=(a,t,e)=>new C(a).transform(t,e),$t=a=>{const t=1/(a[0]*a[3]-a[1]*a[2]),e=[t*a[3],-t*a[1],-t*a[2],t*a[0],0,0],{x:s,y:i}=new C(a[4],a[5]).transform(e,!0);return e[4]=-s,e[5]=-i,e},vt=(a,t,e)=>[a[0]*t[0]+a[2]*t[1],a[1]*t[0]+a[3]*t[1],a[0]*t[2]+a[2]*t[3],a[1]*t[2]+a[3]*t[3],e?0:a[0]*t[4]+a[2]*t[5]+a[4],e?0:a[1]*t[4]+a[3]*t[5]+a[5]],Di=(a,t)=>a.reduceRight(((e,s)=>s&&e?vt(s,e,t):s||e),void 0)||Nt.concat(),Uo=a=>{let[t,e]=a;return Math.atan2(e,t)},is=a=>{const t=Uo(a),e=Math.pow(a[0],2)+Math.pow(a[1],2),s=Math.sqrt(e),i=(a[0]*a[3]-a[2]*a[1])/s,n=Math.atan2(a[0]*a[2]+a[1]*a[3],e);return{angle:Ce(t),scaleX:s,scaleY:i,skewX:Ce(n),skewY:0,translateX:a[4]||0,translateY:a[5]||0}},Ts=function(a){return[1,0,0,1,a,arguments.length>1&&arguments[1]!==void 0?arguments[1]:0]};function ns(){let{angle:a=0}=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},{x:t=0,y:e=0}=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};const s=pt(a),i=le(s),n=ce(s);return[i,n,-n,i,t?t-(i*t-n*e):0,e?e-(n*t+i*e):0]}const Ri=function(a){return[a,0,0,arguments.length>1&&arguments[1]!==void 0?arguments[1]:a,0,0]},Yo=a=>Math.tan(pt(a)),ar=a=>[1,0,Yo(a),1,0,0],hr=a=>[1,Yo(a),0,1,0,0],Js=a=>{let{scaleX:t=1,scaleY:e=1,flipX:s=!1,flipY:i=!1,skewX:n=0,skewY:r=0}=a,o=Ri(s?-t:t,i?-e:e);return n&&(o=vt(o,ar(n),!0)),r&&(o=vt(o,hr(r),!0)),o},$o=a=>{const{translateX:t=0,translateY:e=0,angle:s=0}=a;let i=Ts(t,e);s&&(i=vt(i,ns({angle:s})));const n=Js(a);return Xo(n)||(i=vt(i,n)),i},Zs=function(a){let{signal:t,crossOrigin:e=null}=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};return new Promise((function(s,i){if(t&&t.aborted)return i(new Kn("loadImage"));const n=Wo();let r;t&&(r=function(h){n.src="",i(h)},t.addEventListener("abort",r,{once:!0}));const o=function(){n.onload=n.onerror=null,r&&t?.removeEventListener("abort",r),s(n)};a?(n.onload=o,n.onerror=function(){r&&t?.removeEventListener("abort",r),i(new we("Error loading ".concat(n.src)))},e&&(n.crossOrigin=e),n.src=a):o()}))},Es=function(a){let{signal:t,reviver:e=es}=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};return new Promise(((s,i)=>{const n=[];t&&t.addEventListener("abort",i,{once:!0}),Promise.all(a.map((r=>L.getClass(r.type).fromObject(r,{signal:t}).then((o=>(e(r,o),n.push(o),o)))))).then(s).catch((r=>{n.forEach((o=>{o.dispose&&o.dispose()})),i(r)})).finally((()=>{t&&t.removeEventListener("abort",i)}))}))},Qs=function(a){let{signal:t}=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};return new Promise(((e,s)=>{const i=[];t&&t.addEventListener("abort",s,{once:!0});const n=Object.values(a).map((o=>o&&o.type&&L.has(o.type)?Es([o],{signal:t}).then((h=>{let[l]=h;return i.push(l),l})):o)),r=Object.keys(a);Promise.all(n).then((o=>o.reduce(((h,l,c)=>(h[r[c]]=l,h)),{}))).then(e).catch((o=>{i.forEach((h=>{h.dispose&&h.dispose()})),s(o)})).finally((()=>{t&&t.removeEventListener("abort",s)}))}))},rs=function(a){return(arguments.length>1&&arguments[1]!==void 0?arguments[1]:[]).reduce(((t,e)=>(e in a&&(t[e]=a[e]),t)),{})},lr=(a,t)=>Object.keys(a).reduce(((e,s)=>(t(a[s],s,a)&&(e[s]=a[s]),e)),{}),ot=(a,t)=>parseFloat(Number(a).toFixed(t)),ks=a=>"matrix("+a.map((t=>ot(t,et.NUM_FRACTION_DIGITS))).join(" ")+")",re=a=>!!a&&a.toLive!==void 0,qo=a=>!!a&&typeof a.toObject=="function",Ko=a=>!!a&&a.offsetX!==void 0&&"source"in a,os=a=>!!a&&"multiSelectionStacking"in a;function Jo(a){const t=a&&ue(a);let e=0,s=0;if(!a||!t)return{left:e,top:s};let i=a;const n=t.documentElement,r=t.body||{scrollLeft:0,scrollTop:0};for(;i&&(i.parentNode||i.host)&&(i=i.parentNode||i.host,i===t?(e=r.scrollLeft||n.scrollLeft||0,s=r.scrollTop||n.scrollTop||0):(e+=i.scrollLeft||0,s+=i.scrollTop||0),i.nodeType!==1||i.style.position!=="fixed"););return{left:e,top:s}}const ue=a=>a.ownerDocument||null,Zo=a=>{var t;return((t=a.ownerDocument)===null||t===void 0?void 0:t.defaultView)||null},Qo=function(a,t,e){let{width:s,height:i}=e,n=arguments.length>3&&arguments[3]!==void 0?arguments[3]:1;a.width=s,a.height=i,n>1&&(a.setAttribute("width",(s*n).toString()),a.setAttribute("height",(i*n).toString()),t.scale(n,n))},cr=(a,t)=>{let{width:e,height:s}=t;e&&(a.style.width=typeof e=="number"?"".concat(e,"px"):e),s&&(a.style.height=typeof s=="number"?"".concat(s,"px"):s)};function ta(a){return a.onselectstart!==void 0&&(a.onselectstart=()=>!1),a.style.userSelect=jt,a}class ea{constructor(t){x(this,"_originalCanvasStyle",void 0),x(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&&xs().getElementById(t)||Se();var s;if(e.hasAttribute("data-fabric"))throw new we("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;Qo(s,i,t,e)}setCSSDimensions(t){cr(this.lower.el,t)}calcOffset(){return(function(t){var e;const s=t&&ue(t),i={left:0,top:0};if(!s)return i;const n=((e=Zo(t))===null||e===void 0?void 0:e.getComputedStyle(t,null))||{};i.left+=parseInt(n.borderLeftWidth,10)||0,i.top+=parseInt(n.borderTopWidth,10)||0,i.left+=parseInt(n.paddingLeft,10)||0,i.top+=parseInt(n.paddingTop,10)||0;let r={left:0,top:0};const o=s.documentElement;t.getBoundingClientRect!==void 0&&(r=t.getBoundingClientRect());const h=Jo(t);return{left:r.left+h.left-(o.clientLeft||0)+i.left,top:r.top+h.top-(o.clientTop||0)+i.top}})(this.lower.el)}dispose(){xe().dispose(this.lower.el),delete this.lower}}const pc={backgroundVpt:!0,backgroundColor:"",overlayVpt:!0,overlayColor:"",includeDefaultValues:!0,svgViewportTransformation:!0,renderOnAddRemove:!0,skipOffscreen:!0,enableRetinaScaling:!0,imageSmoothingEnabled:!0,controlsAboveOverlay:!1,allowTouchScrolling:!1,viewportTransform:[...Nt]},mc=["objects"];class ti extends zo(Go){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 ti.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 ea(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&&(De("warn",`Canvas is trying to add an object that belongs to a different canvas.
|
|
8
8
|
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?No():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=w({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=Pt(t,$t(i));i[0]=e,i[3]=e;const r=Pt(n,i);i[4]+=s.x-r.x,i[5]+=s.y-r.y,this.setViewportTransform(i)}setZoom(t){this.zoomToPoint(new C(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 C(-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=Ks((()=>this.renderAndReset())))}calcViewportBoundaries(){const t=this.width,e=this.height,s=$t(this.viewportTransform),i=Pt({x:0,y:0},s),n=Pt({x:t,y:e},s),r=i.min(n),o=i.max(n);return this.vptCoords={tl:r,tr:new C(o.x,r.y),bl:new C(r.x,o.y),br:o}}cancelRequestedRender(){this.nextRenderHandle&&(Vo(this.nextRenderHandle),this.nextRenderHandle=0)}drawControls(t){}renderCanvas(t,e){if(this.destroyed)return;const s=this.viewportTransform,i=this.clipPath;this.calcViewportBoundaries(),this.clearContext(t),t.imageSmoothingEnabled=this.imageSmoothingEnabled,t.patternQuality="best",this.fire("before:render",{ctx:t}),this._renderBackground(t),t.save(),t.transform(s[0],s[1],s[2],s[3],s[4],s[5]),this._renderObjects(t,e),t.restore(),this.controlsAboveOverlay||this.skipControlsDrawing||this.drawControls(t),i&&(i._set("canvas",this),i.shouldCache(),i._transformDone=!0,i.renderCache({forClipping:!0}),this.drawClipPathOnCanvas(t,i)),this._renderOverlay(t),this.controlsAboveOverlay&&!this.skipControlsDrawing&&this.drawControls(t),this.fire("after:render",{ctx:t}),this.__cleanupTask&&(this.__cleanupTask(),this.__cleanupTask=void 0)}drawClipPathOnCanvas(t,e){const s=this.viewportTransform;t.save(),t.transform(...s),t.globalCompositeOperation="destination-in",e.transform(t),t.scale(1/e.zoomX,1/e.zoomY),t.drawImage(e._cacheCanvas,-e.cacheTranslationX,-e.cacheTranslationY),t.restore()}_renderObjects(t,e){for(let s=0,i=e.length;s<i;++s)e[s]&&e[s].render(t)}_renderBackgroundOrOverlay(t,e){const s=this["".concat(e,"Color")],i=this["".concat(e,"Image")],n=this.viewportTransform,r=this["".concat(e,"Vpt")];if(!s&&!i)return;const o=re(s);if(s){if(t.save(),t.beginPath(),t.moveTo(0,0),t.lineTo(this.width,0),t.lineTo(this.width,this.height),t.lineTo(0,this.height),t.closePath(),t.fillStyle=o?s.toLive(t):s,r&&t.transform(...n),o){t.transform(1,0,0,1,s.offsetX||0,s.offsetY||0);const h=s.gradientTransform||s.patternTransform;h&&t.transform(...h)}t.fill(),t.restore()}if(i){t.save();const{skipOffscreen:h}=this;this.skipOffscreen=r,r&&t.transform(...n),i.render(t),this.skipOffscreen=h,t.restore()}}_renderBackground(t){this._renderBackgroundOrOverlay(t,"background")}_renderOverlay(t){this._renderBackgroundOrOverlay(t,"overlay")}getCenter(){return{top:this.height/2,left:this.width/2}}getCenterPoint(){return new C(this.width/2,this.height/2)}centerObjectH(t){return this._centerObject(t,new C(this.getCenterPoint().x,t.getCenterPoint().y))}centerObjectV(t){return this._centerObject(t,new C(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 C(this.getVpCenter().x,t.getCenterPoint().y))}viewportCenterObjectV(t){return this._centerObject(t,new C(t.getCenterPoint().x,this.getVpCenter().y))}getVpCenter(){return Pt(this.getCenterPoint(),$t(this.viewportTransform))}_centerObject(t,e){t.setXY(e,$,$),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 w(w(w({version:Jn},rs(this,e)),{},{objects:this._objects.filter((n=>!n.excludeFromExport)).map((n=>this._toObject(n,t,e)))},this.__serializeBgOverlay(t,e)),i?{clipPath:i}:null)}_toObject(t,e,s){let i;this.includeDefaultValues||(i=t.includeDefaultValues,t.includeDefaultValues=!1);const n=t[e](s);return this.includeDefaultValues||(t.includeDefaultValues=!!i),n}__serializeBgOverlay(t,e){const s={},i=this.backgroundImage,n=this.overlayImage,r=this.backgroundColor,o=this.overlayColor;return re(r)?r.excludeFromExport||(s.background=r.toObject(e)):r&&(s.background=r),re(o)?o.excludeFromExport||(s.overlay=o.toObject(e)):o&&(s.overlay=o),i&&!i.excludeFromExport&&(s.backgroundImage=this._toObject(i,t,e)),n&&!n.excludeFromExport&&(s.overlayImage=this._toObject(n,t,e)),s}toSVG(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},e=arguments.length>1?arguments[1]:void 0;t.reviver=e;const s=[];return this._setSVGPreamble(s,t),this._setSVGHeader(s,t),this.clipPath&&s.push('<g clip-path="url(#'.concat(this.clipPath.clipPathId,`)" >
|
|
9
9
|
`)),this._setSVGBgOverlayColor(s,"background"),this._setSVGBgOverlayImage(s,"backgroundImage",e),this._setSVGObjects(s,e),this.clipPath&&s.push(`</g>
|
|
10
10
|
`),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" ?>
|
|
@@ -43,7 +43,7 @@ Resulting to default behavior: removing object from previous canvas and adding t
|
|
|
43
43
|
`),s=[];let i=-1,n={};a=Pr(a);for(let r=0;r<e.length;r++){const o=$i(e[r]);if(a[r])for(let h=0;h<o.length;h++){i++;const l=a[r][h];l&&Object.keys(l).length>0&&(qi(n,l,!0)?s.push({start:i,end:i+1,style:l}):s[s.length-1].end++),n=l||{}}else i+=o.length,n={}}return s},qa=(a,t)=>{if(!Array.isArray(a))return Pr(a);const e=t.split(er),s={};let i=-1,n=0;for(let r=0;r<e.length;r++){const o=$i(e[r]);for(let h=0;h<o.length;h++)i++,a[n]&&a[n].start<=i&&i<a[n].end&&(s[r]=s[r]||{},s[r][h]=w({},a[n].style),i===a[n].end-1&&n++)}return s},Ye=["display","transform",wt,"fill-opacity","fill-rule","opacity",Ht,"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 Ka(a,t){const e=a.nodeName,s=a.getAttribute("class"),i=a.getAttribute("id"),n="(?![a-zA-Z\\-]+)";let r;if(r=new RegExp("^"+e,"i"),t=t.replace(r,""),i&&t.length&&(r=new RegExp("#"+i+n,"i"),t=t.replace(r,"")),s&&t.length){const o=s.split(" ");for(let h=o.length;h--;)r=new RegExp("\\."+o[h]+n,"i"),t=t.replace(r,"")}return t.length===0}function ou(a,t){let e=!0;const s=Ka(a,t.pop());return s&&t.length&&(e=(function(i,n){let r,o=!0;for(;i.parentElement&&i.parentElement.nodeType===1&&n.length;)o&&(r=n.pop()),o=Ka(i=i.parentElement,r);return n.length===0})(a,t)),s&&e&&t.length===0}const au=a=>{var t;return(t=Cc[a])!==null&&t!==void 0?t:a},hu=new RegExp("(".concat(fe,")"),"gi"),lu=a=>Ni(a.replace(hu," $1 ").replace(/,/gi," "));var Ja,Za,Qa,th,eh,sh,ih;const Gt="(".concat(fe,")"),cu=String.raw(Ja||(Ja=_e(["(skewX)(",")"],["(skewX)\\(","\\)"])),Gt),uu=String.raw(Za||(Za=_e(["(skewY)(",")"],["(skewY)\\(","\\)"])),Gt),du=String.raw(Qa||(Qa=_e(["(rotate)(","(?: "," ",")?)"],["(rotate)\\(","(?: "," ",")?\\)"])),Gt,Gt,Gt),fu=String.raw(th||(th=_e(["(scale)(","(?: ",")?)"],["(scale)\\(","(?: ",")?\\)"])),Gt,Gt),gu=String.raw(eh||(eh=_e(["(translate)(","(?: ",")?)"],["(translate)\\(","(?: ",")?\\)"])),Gt,Gt),pu=String.raw(sh||(sh=_e(["(matrix)("," "," "," "," "," ",")"],["(matrix)\\("," "," "," "," "," ","\\)"])),Gt,Gt,Gt,Gt,Gt,Gt),Or="(?:".concat(pu,"|").concat(gu,"|").concat(du,"|").concat(fu,"|").concat(cu,"|").concat(uu,")"),mu="(?:".concat(Or,"*)"),bu=String.raw(ih||(ih=_e(["^s*(?:","?)s*$"],["^\\s*(?:","?)\\s*$"])),mu),vu=new RegExp(bu),yu=new RegExp(Or),_u=new RegExp(Or,"g");function Ki(a){const t=[];if(!(a=lu(a).replace(/\s*([()])\s*/gi,"$1"))||a&&!vu.test(a))return[...Nt];for(const e of a.matchAll(_u)){const s=yu.exec(e[0]);if(!s)continue;let i=Nt;const n=s.filter((g=>!!g)),[,r,...o]=n,[h,l,c,u,d,f]=o.map((g=>parseFloat(g)));switch(r){case"translate":i=Ts(h,l);break;case sr:i=ns({angle:h},{x:l,y:c});break;case ki:i=Ri(h,l);break;case Ss:i=ar(h);break;case Cs:i=hr(h);break;case"matrix":i=[h,l,c,u,d,f]}t.push(i)}return Di(t)}function wu(a,t,e,s){const i=Array.isArray(t);let n,r=t;if(a!==wt&&a!==Ht||t!==jt){if(a==="strokeUniform")return t==="non-scaling-stroke";if(a==="strokeDashArray")r=t===jt?null:t.replace(/,/g," ").split(/\s+/).map(parseFloat);else if(a==="transformMatrix")r=e&&e.transformMatrix?vt(e.transformMatrix,Ki(t)):Ki(t);else if(a==="visible")r=t!==jt&&t!=="hidden",e&&e.visible===!1&&(r=!1);else if(a==="opacity")r=parseFloat(t),e&&e.opacity!==void 0&&(r*=e.opacity);else if(a==="textAnchor")r=t==="start"?it:t==="end"?bt:$;else if(a==="charSpacing"||a===hs)n=zt(t,s)/s*1e3;else if(a==="paintFirst"){const o=t.indexOf(wt),h=t.indexOf(Ht);r=wt,(o>-1&&h>-1&&h<o||o===-1&&h>-1)&&(r=Ht)}else{if(a==="href"||a==="xlink:href"||a==="font"||a==="id")return t;if(a==="imageSmoothing")return t==="optimizeQuality";n=i?t.map(zt):zt(t,s)}}else r="";return!i&&isNaN(n)?r:n}function xu(a,t){const e=a.match(Sc);if(!e)return;const s=e[1],i=e[3],n=e[4],r=e[5],o=e[6];s&&(t.fontStyle=s),i&&(t.fontWeight=isNaN(parseFloat(i))?i:parseFloat(i)),n&&(t.fontSize=zt(n)),o&&(t.fontFamily=o),r&&(t.lineHeight=r==="normal"?1:r)}function Dr(a,t){a.replace(/;\s*$/,"").split(";").forEach((e=>{if(!e)return;const[s,i]=e.split(":");t[s.trim().toLowerCase()]=i.trim()}))}function Su(a){const t={},e=a.getAttribute("style");return e&&(typeof e=="string"?Dr(e,t):(function(s,i){Object.entries(s).forEach((n=>{let[r,o]=n;o!==void 0&&(i[r.toLowerCase()]=o)}))})(e,t)),t}const Cu={stroke:"strokeOpacity",fill:"fillOpacity"};function Ne(a,t,e){if(!a)return{};let s,i={},n=Qn;a.parentNode&&Ca.test(a.parentNode.nodeName)&&(i=Ne(a.parentElement,t,e),i.fontSize&&(s=n=zt(i.fontSize)));const r=w(w(w({},t.reduce(((l,c)=>{const u=a.getAttribute(c);return u&&(l[c]=u),l}),{})),(function(l){let c=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},u={};for(const d in c)ou(l,d.split(" "))&&(u=w(w({},u),c[d]));return u})(a,e)),Su(a));r[yr]&&a.setAttribute(yr,r[yr]),r[vr]&&(s=zt(r[vr],n),r[vr]="".concat(s));const o={};for(const l in r){const c=au(l),u=wu(c,r[l],i,s);o[c]=u}o&&o.font&&xu(o.font,o);const h=w(w({},i),o);return Ca.test(a.nodeName)?h:(function(l){const c=Ot.getDefaults();return Object.entries(Cu).forEach((u=>{let[d,f]=u;if(l[f]===void 0||l[d]==="")return;if(l[d]===void 0){if(!c[d])return;l[d]=c[d]}if(l[d].indexOf("url(")===0)return;const g=new nt(l[d]);l[d]=g.setAlpha(ot(g.getAlpha()*l[f],2)).toRgba()})),l})(h)}const Au=["left","top","width","height","visible"],nh=["rx","ry"];class Ee extends Ot{static getDefaults(){return w(w({},super.getDefaults()),Ee.ownDefaults)}constructor(t){super(),Object.assign(this,Ee.ownDefaults),this.setOptions(t),this._initRxRy()}_initRxRy(){const{rx:t,ry:e}=this;t&&!e?this.ry=t:e&&!t&&(this.rx=e)}_render(t){const{width:e,height:s}=this,i=-e/2,n=-s/2,r=this.rx?Math.min(this.rx,e/2):0,o=this.ry?Math.min(this.ry,s/2):0,h=r!==0||o!==0;t.beginPath(),t.moveTo(i+r,n),t.lineTo(i+e-r,n),h&&t.bezierCurveTo(i+e-Xe*r,n,i+e,n+Xe*o,i+e,n+o),t.lineTo(i+e,n+s-o),h&&t.bezierCurveTo(i+e,n+s-Xe*o,i+e-Xe*r,n+s,i+e-r,n+s),t.lineTo(i+r,n+s),h&&t.bezierCurveTo(i+Xe*r,n+s,i,n+s-Xe*o,i,n+s-o),t.lineTo(i,n+o),h&&t.bezierCurveTo(i,n+Xe*o,i+Xe*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([...nh,...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,`" />
|
|
44
44
|
`)]}static async fromElement(t,e,s){const i=Ne(t,this.ATTRIBUTE_NAMES,s),{left:n=0,top:r=0,width:o=0,height:h=0,visible:l=!0}=i,c=lt(i,Au);return new this(w(w(w({},e),c),{},{left:n,top:r,width:o,height:h,visible:!!(l&&o&&h)}))}}x(Ee,"type","Rect"),x(Ee,"cacheProperties",[...Fe,...nh]),x(Ee,"ownDefaults",{rx:0,ry:0}),x(Ee,"ATTRIBUTE_NAMES",[...Ye,"x","y","rx","ry","width","height"]),L.setClass(Ee),L.setSVGClass(Ee);const je="initialization",Ji="added",Rr="removed",Zi="imperative",rh=(a,t)=>{const{strokeUniform:e,strokeWidth:s,width:i,height:n,group:r}=t,o=r&&r!==a?ei(r.calcTransformMatrix(),a.calcTransformMatrix()):null,h=o?t.getRelativeCenterPoint().transform(o):t.getRelativeCenterPoint(),l=!t.isStrokeAccountedForInDimensions(),c=e&&l?oa(new C(s,s),void 0,a.calcTransformMatrix()):nr,u=!e&&l?s:0,d=Fi(i+u,n+u,Di([o,t.calcOwnMatrix()],!0)).add(c).scalarDivide(2);return[h.subtract(d),h.add(d)]};class Qi{calcLayoutResult(t,e){if(this.shouldPerformLayout(t))return this.calcBoundingBox(e,t)}shouldPerformLayout(t){let{type:e,prevStrategy:s,strategy:i}=t;return e===je||e===Zi||!!s&&i!==s}shouldLayoutClipPath(t){let{type:e,target:{clipPath:s}}=t;return e!==je&&s&&!s.absolutePositioned}getInitialSize(t,e){return e.size}calcBoundingBox(t,e){const{type:s,target:i}=e;if(s===Zi&&e.overrides)return e.overrides;if(t.length===0)return;const{left:n,top:r,width:o,height:h}=Ae(t.map((u=>rh(i,u))).reduce(((u,d)=>u.concat(d)),[])),l=new C(o,h),c=new C(n,r).add(l.scalarDivide(2));if(s===je){const u=this.getInitialSize(e,{size:l,center:c});return{center:c,relativeCorrection:new C(0,0),size:u}}return{center:c.transform(i.calcOwnMatrix()),size:l}}}x(Qi,"type","strategy");class Lr extends Qi{shouldPerformLayout(t){return!0}}x(Lr,"type","fit-content"),L.setClass(Lr);const Tu=["strategy"],Eu=["target","strategy","bubbles","prevStrategy"],oh="layoutManager";class hi{constructor(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:new Lr;x(this,"strategy",void 0),this.strategy=t,this._subscriptions=new Map}performLayout(t){const e=w(w({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[Mi,jo,qs,Bo,Ti,Ho,Ei,uc,dc].map((i=>t.on(i,(n=>this.performLayout(i===Mi?{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===je||s===Ji?this.subscribeTargets(t):s===Rr&&this.unsubscribeTargets(t),e.fire("layout:before",{context:t}),i&&i.fire("object:layout:before",{target:e,context:t}),s===Zi&&t.deep){const n=lt(t,Tu);e.forEachObject((r=>r.layoutManager&&r.layoutManager.performLayout(w(w({},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===je?new C:e.getRelativeCenterPoint(),{center:o,correction:h=new C,relativeCorrection:l=new C}=n,c=r.subtract(o).add(h).transform(i===je?Nt:$t(e.calcOwnMatrix()),!0).add(l);return{result:n,prevCenter:r,nextCenter:o,offset:c}}commitLayout(t,e){const{target:s}=t,{result:{size:i},nextCenter:n}=e;var r,o;s.set({width:i.x,height:i.y}),this.layoutObjects(t,e),t.type===je?s.set({left:(r=t.x)!==null&&r!==void 0?r:n.x+i.x*xt(s.originX),top:(o=t.y)!==null&&o!==void 0?o:n.y+i.y*xt(s.originY)}):(s.setPositionByOrigin(n,$,$),s.setCoords(),s.set("dirty",!0))}layoutObjects(t,e){const{target:s}=t;s.forEachObject((i=>{i.group===s&&this.layoutObject(t,e,i)})),t.strategy.shouldLayoutClipPath(t)&&this.layoutObject(t,e,s.clipPath)}layoutObject(t,e,s){let{offset:i}=e;s.set({left:s.left+i.x,top:s.top+i.y})}onAfterLayout(t,e){const{target:s,strategy:i,bubbles:n,prevStrategy:r}=t,o=lt(t,Eu),{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&&((o.path||(o.path=[])).push(s),l.layoutManager.performLayout(w(w({},o),{},{target:l}))),s.set("dirty",!0)}dispose(){const{_subscriptions:t}=this;t.forEach((e=>e.forEach((s=>s())))),t.clear()}toObject(){return{type:oh,strategy:this.strategy.constructor.type}}toJSON(){return this.toObject()}}L.setClass(hi,oh);const ku=["type","objects","layoutManager"];class Mu extends hi{performLayout(){}}class ee extends zo(Ot){static getDefaults(){return w(w({},super.getDefaults()),ee.ownDefaults)}constructor(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:[],e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};super(),x(this,"_activeObjects",[]),x(this,"__objectSelectionTracker",void 0),x(this,"__objectSelectionDisposer",void 0),Object.assign(this,ee.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 hi,this.layoutManager.performLayout({type:je,target:this,targets:[...t],x:e.left,y:e.top})}canEnterGroup(t){return t===this||this.isDescendantOf(t)?(De("error","Group: circular object trees are not supported, this call has no effect"),!1):this._objects.indexOf(t)===-1||(De("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(Ji,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(Ji,n),r}remove(){const t=super.remove(...arguments);return this._onAfterObjectsChange(Rr,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&&Ms(t,vt($t(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||(Ms(t,vt(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=Ot.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(...$t(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(w({target:this,type:Zi},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 w(w(w({},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=Ee.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",` >
|
|
45
45
|
`],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>
|
|
46
|
-
`),e}getSvgStyles(){const t=this.opacity!==void 0&&this.opacity!==1?"opacity: ".concat(this.opacity,";"):"",e=this.visible?"":" visibility: hidden;";return[t,this.getSvgFilter(),e].join("")}toClipPathSVG(t){const e=[],s=this._createSVGBgRect(t);s&&e.push(" ",s);for(let i=0;i<this._objects.length;i++)e.push(" ",this._objects[i].toClipPathSVG(t));return this._createBaseClipPathSVGMarkup(e,{reviver:t})}static fromObject(t,e){let{type:s,objects:i=[],layoutManager:n}=t,r=lt(t,ku);return Promise.all([Es(i,e),Qs(r,e)]).then((o=>{let[h,l]=o;const c=new this(h,w(w(w({},r),l),{},{layoutManager:new Mu}));if(n){const u=L.getClass(n.type),d=L.getClass(n.strategy);c.layoutManager=new u(new d)}else c.layoutManager=new hi;return c.layoutManager.subscribeTargets({type:je,target:c,targets:c.getObjects()}),c.setCoords(),c}))}}x(ee,"type","Group"),x(ee,"ownDefaults",{strokeWidth:0,subTargetCheck:!1,interactive:!1}),L.setClass(ee);const ah=(a,t)=>Math.min(t.width/a.width,t.height/a.height),hh=(a,t)=>Math.max(t.width/a.width,t.height/a.height),Fr="\\s*,?\\s*",li="".concat(Fr,"(").concat(fe,")"),Pu="".concat(li).concat(li).concat(li).concat(Fr,"([01])").concat(Fr,"([01])").concat(li).concat(li),Ou={m:"l",M:"L"},Du=(a,t,e,s,i,n,r,o,h,l,c)=>{const u=le(a),d=ce(a),f=le(t),g=ce(t),p=e*i*f-s*n*g+r,b=s*i*f+e*n*g+o;return["C",l+h*(-e*i*d-s*n*u),c+h*(-s*i*d+e*n*u),p+h*(e*i*g+s*n*f),b+h*(s*i*g-e*n*f),p,b]},lh=(a,t,e,s)=>{const i=Math.atan2(t,a),n=Math.atan2(s,e);return n>=i?n-i:2*Math.PI-(i-n)};function Ir(a,t,e,s,i,n,r,o){let h;if(et.cachesBoundsOfCurve&&(h=[...arguments].join(),$s.boundsOfCurveCache[h]))return $s.boundsOfCurveCache[h];const l=Math.sqrt,c=Math.abs,u=[],d=[[0,0],[0,0]];let f=6*a-12*e+6*i,g=-3*a+9*e-9*i+3*r,p=3*e-3*a;for(let _=0;_<2;++_){if(_>0&&(f=6*t-12*s+6*n,g=-3*t+9*s-9*n+3*o,p=3*s-3*t),c(g)<1e-12){if(c(f)<1e-12)continue;const P=-p/f;0<P&&P<1&&u.push(P);continue}const S=f*f-4*p*g;if(S<0)continue;const A=l(S),T=(-f+A)/(2*g);0<T&&T<1&&u.push(T);const k=(-f-A)/(2*g);0<k&&k<1&&u.push(k)}let b=u.length;const m=b,v=uh(a,t,e,s,i,n,r,o);for(;b--;){const{x:_,y:S}=v(u[b]);d[0][b]=_,d[1][b]=S}d[0][m]=a,d[1][m]=t,d[0][m+1]=r,d[1][m+1]=o;const y=[new C(Math.min(...d[0]),Math.min(...d[1])),new C(Math.max(...d[0]),Math.max(...d[1]))];return et.cachesBoundsOfCurve&&($s.boundsOfCurveCache[h]=y),y}const Ru=(a,t,e)=>{let[s,i,n,r,o,h,l,c]=e;const u=((d,f,g,p,b,m,v)=>{if(g===0||p===0)return[];let y=0,_=0,S=0;const A=Math.PI,T=v*Zn,k=ce(T),P=le(T),B=.5*(-P*d-k*f),F=.5*(-P*f+k*d),I=g**2,O=p**2,D=F**2,z=B**2,M=I*O-I*D-O*z;let R=Math.abs(g),U=Math.abs(p);if(M<0){const Zt=Math.sqrt(1-M/(I*O));R*=Zt,U*=Zt}else S=(b===m?-1:1)*Math.sqrt(M/(I*D+O*z));const ht=S*R*F/U,dt=-S*U*B/R,E=P*ht-k*dt+.5*d,H=k*ht+P*dt+.5*f;let V=lh(1,0,(B-ht)/R,(F-dt)/U),Q=lh((B-ht)/R,(F-dt)/U,(-B-ht)/R,(-F-dt)/U);m===0&&Q>0?Q-=2*A:m===1&&Q<0&&(Q+=2*A);const Mt=Math.ceil(Math.abs(Q/A*2)),rt=[],N=Q/Mt,ft=8/3*Math.sin(N/4)*Math.sin(N/4)/Math.sin(N/2);let kt=V+N;for(let Zt=0;Zt<Mt;Zt++)rt[Zt]=Du(V,kt,P,k,R,U,E,H,ft,y,_),y=rt[Zt][5],_=rt[Zt][6],V=kt,kt+=N;return rt})(l-a,c-t,i,n,o,h,r);for(let d=0,f=u.length;d<f;d++)u[d][1]+=a,u[d][2]+=t,u[d][3]+=a,u[d][4]+=t,u[d][5]+=a,u[d][6]+=t;return u},ch=a=>{let t=0,e=0,s=0,i=0;const n=[];let r,o=0,h=0;for(const l of a){const c=[...l];let u;switch(c[0]){case"l":c[1]+=t,c[2]+=e;case"L":t=c[1],e=c[2],u=["L",t,e];break;case"h":c[1]+=t;case"H":t=c[1],u=["L",t,e];break;case"v":c[1]+=e;case"V":e=c[1],u=["L",t,e];break;case"m":c[1]+=t,c[2]+=e;case"M":t=c[1],e=c[2],s=c[1],i=c[2],u=["M",t,e];break;case"c":c[1]+=t,c[2]+=e,c[3]+=t,c[4]+=e,c[5]+=t,c[6]+=e;case"C":o=c[3],h=c[4],t=c[5],e=c[6],u=["C",c[1],c[2],o,h,t,e];break;case"s":c[1]+=t,c[2]+=e,c[3]+=t,c[4]+=e;case"S":r==="C"?(o=2*t-o,h=2*e-h):(o=t,h=e),t=c[3],e=c[4],u=["C",o,h,c[1],c[2],t,e],o=u[3],h=u[4];break;case"q":c[1]+=t,c[2]+=e,c[3]+=t,c[4]+=e;case"Q":o=c[1],h=c[2],t=c[3],e=c[4],u=["Q",o,h,t,e];break;case"t":c[1]+=t,c[2]+=e;case"T":r==="Q"?(o=2*t-o,h=2*e-h):(o=t,h=e),t=c[1],e=c[2],u=["Q",o,h,t,e];break;case"a":c[6]+=t,c[7]+=e;case"A":Ru(t,e,c).forEach((d=>n.push(d))),t=c[6],e=c[7];break;case"z":case"Z":t=s,e=i,u=["Z"]}u?(n.push(u),r=u[0]):r=""}return n},tn=(a,t,e,s)=>Math.sqrt((e-a)**2+(s-t)**2),uh=(a,t,e,s,i,n,r,o)=>h=>{const l=h**3,c=(f=>3*f**2*(1-f))(h),u=(f=>3*f*(1-f)**2)(h),d=(f=>(1-f)**3)(h);return new C(r*l+i*c+e*u+a*d,o*l+n*c+s*u+t*d)},dh=a=>a**2,fh=a=>2*a*(1-a),gh=a=>(1-a)**2,Lu=(a,t,e,s,i,n,r,o)=>h=>{const l=dh(h),c=fh(h),u=gh(h),d=3*(u*(e-a)+c*(i-e)+l*(r-i)),f=3*(u*(s-t)+c*(n-s)+l*(o-n));return Math.atan2(f,d)},Fu=(a,t,e,s,i,n)=>r=>{const o=dh(r),h=fh(r),l=gh(r);return new C(i*o+e*h+a*l,n*o+s*h+t*l)},Iu=(a,t,e,s,i,n)=>r=>{const o=1-r,h=2*(o*(e-a)+r*(i-e)),l=2*(o*(s-t)+r*(n-s));return Math.atan2(l,h)},ph=(a,t,e)=>{let s=new C(t,e),i=0;for(let n=1;n<=100;n+=1){const r=a(n/100);i+=tn(s.x,s.y,r.x,r.y),s=r}return i},Nu=(a,t)=>{let e,s=0,i=0,n={x:a.x,y:a.y},r=w({},n),o=.01,h=0;const l=a.iterator,c=a.angleFinder;for(;i<t&&o>1e-4;)r=l(s),h=s,e=tn(n.x,n.y,r.x,r.y),e+i>t?(s-=o,o/=2):(n=r,s+=o,i+=e);return w(w({},r),{},{angle:c(h)})},Nr=a=>{let t,e,s=0,i=0,n=0,r=0,o=0;const h=[];for(const l of a){const c={x:i,y:n,command:l[0],length:0};switch(l[0]){case"M":e=c,e.x=r=i=l[1],e.y=o=n=l[2];break;case"L":e=c,e.length=tn(i,n,l[1],l[2]),i=l[1],n=l[2];break;case"C":t=uh(i,n,l[1],l[2],l[3],l[4],l[5],l[6]),e=c,e.iterator=t,e.angleFinder=Lu(i,n,l[1],l[2],l[3],l[4],l[5],l[6]),e.length=ph(t,i,n),i=l[5],n=l[6];break;case"Q":t=Fu(i,n,l[1],l[2],l[3],l[4]),e=c,e.iterator=t,e.angleFinder=Iu(i,n,l[1],l[2],l[3],l[4]),e.length=ph(t,i,n),i=l[3],n=l[4];break;case"Z":e=c,e.destX=r,e.destY=o,e.length=tn(i,n,r,o),i=r,n=o}s+=e.length,h.push(e)}return h.push({length:s,x:i,y:n}),h},mh=function(a,t){let e=arguments.length>2&&arguments[2]!==void 0?arguments[2]:Nr(a),s=0;for(;t-e[s].length>0&&s<e.length-2;)t-=e[s].length,s++;const i=e[s],n=t/i.length,r=a[s];switch(i.command){case"M":return{x:i.x,y:i.y,angle:0};case"Z":return w(w({},new C(i.x,i.y).lerp(new C(i.destX,i.destY),n)),{},{angle:Math.atan2(i.destY-i.y,i.destX-i.x)});case"L":return w(w({},new C(i.x,i.y).lerp(new C(r[1],r[2]),n)),{},{angle:Math.atan2(r[2]-i.y,r[1]-i.x)});case"C":case"Q":return Nu(i,t)}},ju=new RegExp("[mzlhvcsqta][^mzlhvcsqta]*","gi"),bh=new RegExp(Pu,"g"),Bu=new RegExp(fe,"gi"),Hu={m:2,l:2,h:1,v:1,c:6,s:4,q:4,t:2,a:7},vh=a=>{var t;const e=[],s=(t=a.match(ju))!==null&&t!==void 0?t:[];for(const i of s){const n=i[0];if(n==="z"||n==="Z"){e.push([n]);continue}const r=Hu[n.toLowerCase()];let o=[];if(n==="a"||n==="A"){bh.lastIndex=0;for(let h=null;h=bh.exec(i);)o.push(...h.slice(1))}else o=i.match(Bu)||[];for(let h=0;h<o.length;h+=r){const l=new Array(r),c=Ou[n];l[0]=h>0&&c?c:n;for(let u=0;u<r;u++)l[u+1]=parseFloat(o[h+u]);e.push(l)}}return e},zu=function(a){let t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:0,e=new C(a[0]),s=new C(a[1]),i=1,n=0;const r=[],o=a.length,h=o>2;let l;for(h&&(i=a[2].x<s.x?-1:a[2].x===s.x?0:1,n=a[2].y<s.y?-1:a[2].y===s.y?0:1),r.push(["M",e.x-i*t,e.y-n*t]),l=1;l<o;l++){if(!e.eq(s)){const c=e.midPointFrom(s);r.push(["Q",e.x,e.y,c.x,c.y])}e=a[l],l+1<a.length&&(s=a[l+1])}return h&&(i=e.x>a[l-2].x?1:e.x===a[l-2].x?0:-1,n=e.y>a[l-2].y?1:e.y===a[l-2].y?0:-1),r.push(["L",e.x+i*t,e.y+n*t]),r},yh=(a,t)=>a.map((e=>e.map(((s,i)=>i===0||t===void 0?s:ot(s,t))).join(" "))).join(" ");function en(a,t){const e=a.style;e&&t&&(typeof t=="string"?e.cssText+=";"+t:Object.entries(t).forEach((s=>{let[i,n]=s;return e.setProperty(i,n)})))}const Gu=(a,t)=>Math.floor(Math.random()*(t-a+1))+a;function _h(a){let t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};const e=t.onComplete||es,s=new(Ys()).XMLHttpRequest,i=t.signal,n=function(){s.abort()},r=function(){i&&i.removeEventListener("abort",n),s.onerror=s.ontimeout=es};if(i&&i.aborted)throw new Kn("request");return i&&i.addEventListener("abort",n,{once:!0}),s.onreadystatechange=function(){s.readyState===4&&(r(),e(s),s.onreadystatechange=es)},s.onerror=s.ontimeout=r,s.open("get",a,!0),s.send(),s}const sn=(a,t)=>{let e=a._findCenterFromElement();a.transformMatrix&&((s=>{if(s.transformMatrix){const{scaleX:i,scaleY:n,angle:r,skewX:o}=is(s.transformMatrix);s.flipX=!1,s.flipY=!1,s.set(Bt,i),s.set(Qt,n),s.angle=r,s.skewX=o,s.skewY=0}})(a),e=e.transform(a.transformMatrix)),delete a.transformMatrix,t&&(a.scaleX*=t.scaleX,a.scaleY*=t.scaleY,a.cropX=t.cropX,a.cropY=t.cropY,e.x+=t.offsetLeft,e.y+=t.offsetTop,a.width=t.width,a.height=t.height),a.setPositionByOrigin(e,$,$)};var Vu=Object.freeze({__proto__:null,addTransformToObject:na,animate:Er,animateColor:La,applyTransformToObject:Ms,calcAngleBetweenVectors:Vi,calcDimensionsMatrix:Js,calcPlaneChangeMatrix:ei,calcVectorRotation:Ea,cancelAnimFrame:Vo,capValue:ls,composeMatrix:$o,copyCanvasElement:a=>{var t;const e=te(a);return(t=e.getContext("2d"))===null||t===void 0||t.drawImage(a,0,0),e},cos:le,createCanvasElement:Se,createImage:Wo,createRotateMatrix:ns,createScaleMatrix:Ri,createSkewXMatrix:ar,createSkewYMatrix:hr,createTranslateMatrix:Ts,createVector:zi,crossProduct:Ps,degreesToRadians:pt,dotProduct:ka,ease:Pc,enlivenObjectEnlivables:Qs,enlivenObjects:Es,findScaleToCover:hh,findScaleToFit:ah,getBoundsOfCurve:Ir,getOrthonormalVector:wr,getPathSegmentsInfo:Nr,getPointOnPath:mh,getPointer:sa,getRandomInt:Gu,getRegularPolygonPath:(a,t)=>{const e=2*Math.PI/a;let s=-We;a%2==0&&(s+=e/2);const i=new Array(a+1);for(let n=0;n<a;n++){const r=n*e+s,{x:o,y:h}=new C(le(r),ce(r)).scalarMultiply(t);i[n]=[n===0?"M":"L",o,h]}return i[a]=["Z"],i},getSmoothPathFromPoints:zu,getSvgAttributes:a=>{const t=["instantiated_by_use","style","id","class"];switch(a){case"linearGradient":return t.concat(["x1","y1","x2","y2","gradientUnits","gradientTransform"]);case"radialGradient":return t.concat(["gradientUnits","gradientTransform","cx","cy","r","fx","fy","fr"]);case"stop":return t.concat(["offset","stop-color","stop-opacity"])}return t},getUnitVector:Wi,groupSVGElements:(a,t)=>a&&a.length===1?a[0]:new ee(a,t),hasStyleChanged:qi,invertTransform:$t,isBetweenVectors:xr,isIdentityMatrix:Xo,isTouchEvent:Li,isTransparent:Va,joinPath:yh,loadImage:Zs,magnitude:Gi,makeBoundingBoxFromPoints:Ae,makePathSimpler:ch,matrixToSVG:ks,mergeClipPaths:(a,t)=>{var e;let s=a,i=t;s.inverted&&!i.inverted&&(s=t,i=a),dr(i,(e=i.group)===null||e===void 0?void 0:e.calcTransformMatrix(),s.calcTransformMatrix());const n=s.inverted&&i.inverted;return n&&(s.inverted=i.inverted=!1),new ee([s],{clipPath:i,inverted:n})},multiplyTransformMatrices:vt,multiplyTransformMatrixArray:Di,parsePath:vh,parsePreserveAspectRatioAttribute:pr,parseUnit:zt,pick:rs,projectStrokeOnPoints:Ua,qrDecompose:is,radiansToDegrees:Ce,removeFromArray:ss,removeTransformFromObject:(a,t)=>{const e=$t(t),s=vt(e,a.calcOwnMatrix());Ms(a,s)},removeTransformMatrixForSvgParsing:sn,request:_h,requestAnimFrame:Ks,resetObjectTransform:ra,rotatePoint:(a,t,e)=>a.rotate(e,t),rotateVector:_r,saveObjectTransform:ur,sendObjectToPlane:dr,sendPointToPlane:as,sendVectorToPlane:oa,setStyle:en,sin:ce,sizeAfterTransform:Fi,string:ru,stylesFromArray:qa,stylesToArray:$a,toBlob:or,toDataURL:rr,toFixed:ot,transformPath:(a,t,e)=>(e&&(t=vt(t,[1,0,0,1,-e.x,-e.y])),a.map((s=>{const i=[...s];for(let n=1;n<s.length-1;n+=2){const{x:r,y:o}=Pt({x:s[n],y:s[n+1]},t);i[n]=r,i[n+1]=o}return i}))),transformPoint:Pt});class Wu extends ea{constructor(t){let{allowTouchScrolling:e=!1,containerClass:s=""}=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};super(t),x(this,"upper",void 0),x(this,"container",void 0);const{el:i}=this.lower,n=this.createUpperCanvas();this.upper={el:n,ctx:n.getContext("2d")},this.applyCanvasStyle(i,{allowTouchScrolling:e}),this.applyCanvasStyle(n,{allowTouchScrolling:e,styles:{position:"absolute",left:"0",top:"0"}});const r=this.createContainerElement();r.classList.add(s),i.parentNode&&i.parentNode.replaceChild(r,i),r.append(i,n),this.container=r}createUpperCanvas(){const{el:t}=this.lower,e=Se();return e.className=t.className,e.classList.remove("lower-canvas"),e.classList.add("upper-canvas"),e.setAttribute("data-fabric","top"),e.style.cssText=t.style.cssText,e.setAttribute("draggable","true"),e}createContainerElement(){const t=xs().createElement("div");return t.setAttribute("data-fabric","wrapper"),en(t,{position:"relative"}),ta(t),t}applyCanvasStyle(t,e){const{styles:s,allowTouchScrolling:i}=e;en(t,w(w({},s),{},{"touch-action":i?"manipulation":jt})),ta(t)}setDimensions(t,e){super.setDimensions(t,e);const{el:s,ctx:i}=this.upper;Qo(s,i,t,e)}setCSSDimensions(t){super.setCSSDimensions(t),cr(this.upper.el,t),cr(this.container,t)}cleanupDOM(t){const e=this.container,{el:s}=this.lower,{el:i}=this.upper;super.cleanupDOM(t),e.removeChild(i),e.removeChild(s),e.parentNode&&e.parentNode.replaceChild(s,e)}dispose(){super.dispose(),xe().dispose(this.upper.el),delete this.upper,delete this.container}}class nn extends ti{constructor(){super(...arguments),x(this,"targets",[]),x(this,"_hoveredTargets",[]),x(this,"_currentTransform",null),x(this,"_groupSelector",null),x(this,"contextTopDirty",!1)}static getDefaults(){return w(w({},super.getDefaults()),nn.ownDefaults)}get upperCanvasEl(){var t;return(t=this.elements.upper)===null||t===void 0?void 0:t.el}get contextTop(){var t;return(t=this.elements.upper)===null||t===void 0?void 0:t.ctx}get wrapperEl(){return this.elements.container}initElements(t){this.elements=new Wu(t,{allowTouchScrolling:this.allowTouchScrolling,containerClass:this.containerClass}),this._createCacheCanvas()}_onObjectAdded(t){this._objectsToRender=void 0,super._onObjectAdded(t)}_onObjectRemoved(t){this._objectsToRender=void 0,t===this._activeObject&&(this.fire("before:selection:cleared",{deselected:[t]}),this._discardActiveObject(),this.fire("selection:cleared",{deselected:[t]}),t.fire("deselected",{target:t})),t===this._hoveredTarget&&(this._hoveredTarget=void 0,this._hoveredTargets=[]),super._onObjectRemoved(t)}_onStackOrderChanged(){this._objectsToRender=void 0,super._onStackOrderChanged()}_chooseObjectsToRender(){const t=this._activeObject;return!this.preserveObjectStacking&&t?this._objects.filter((e=>!e.group&&e!==t)).concat(t):this._objects}renderAll(){this.cancelRequestedRender(),this.destroyed||(!this.contextTopDirty||this._groupSelector||this.isDrawingMode||(this.clearContext(this.contextTop),this.contextTopDirty=!1),this.hasLostContext&&(this.renderTopLayer(this.contextTop),this.hasLostContext=!1),!this._objectsToRender&&(this._objectsToRender=this._chooseObjectsToRender()),this.renderCanvas(this.getContext(),this._objectsToRender))}renderTopLayer(t){t.save(),this.isDrawingMode&&this._isCurrentlyDrawing&&(this.freeDrawingBrush&&this.freeDrawingBrush._render(),this.contextTopDirty=!0),this.selection&&this._groupSelector&&(this._drawSelection(t),this.contextTopDirty=!0),t.restore()}renderTop(){const t=this.contextTop;this.clearContext(t),this.renderTopLayer(t),this.fire("after:render",{ctx:t})}setTargetFindTolerance(t){t=Math.round(t),this.targetFindTolerance=t;const e=this.getRetinaScaling(),s=Math.ceil((2*t+1)*e);this.pixelFindCanvasEl.width=this.pixelFindCanvasEl.height=s,this.pixelFindContext.scale(e,e)}isTargetTransparent(t,e,s){const i=this.targetFindTolerance,n=this.pixelFindContext;this.clearContext(n),n.save(),n.translate(-e+i,-s+i),n.transform(...this.viewportTransform);const r=t.selectionBackgroundColor;t.selectionBackgroundColor="",t.render(n),t.selectionBackgroundColor=r,n.restore();const o=Math.round(i*this.getRetinaScaling());return Va(n,o,o,o)}_isSelectionKeyPressed(t){const e=this.selectionKey;return!!e&&(Array.isArray(e)?!!e.find((s=>!!s&&t[s]===!0)):t[e])}_shouldClearSelection(t,e){const s=this.getActiveObjects(),i=this._activeObject;return!!(!e||e&&i&&s.length>1&&s.indexOf(e)===-1&&i!==e&&!this._isSelectionKeyPressed(t)||e&&!e.evented||e&&!e.selectable&&i&&i!==e)}_shouldCenterTransform(t,e,s){if(!t)return;let i;return e===ki||e===Bt||e===Qt||e===qs?i=this.centeredScaling||t.centeredScaling:e===sr&&(i=this.centeredRotation||t.centeredRotation),i?!s:s}_getOriginFromCorner(t,e){const s={x:t.originX,y:t.originY};return e&&(["ml","tl","bl"].includes(e)?s.x=bt:["mr","tr","br"].includes(e)&&(s.x=it),["tl","mt","tr"].includes(e)?s.y=tr:["bl","mb","br"].includes(e)&&(s.y=Yt)),s}_setupCurrentTransform(t,e,s){var i;const n=e.group?as(this.getScenePoint(t),void 0,e.group.calcTransformMatrix()):this.getScenePoint(t),{key:r="",control:o}=e.getActiveControl()||{},h=s&&o?(i=o.getActionHandler(t,e,o))===null||i===void 0?void 0:i.bind(o):_c,l=((f,g,p,b)=>{if(!g||!f)return"drag";const m=b.controls[g];return m.getActionName(p,m,b)})(s,r,t,e),c=t[this.centeredKey],u=this._shouldCenterTransform(e,l,c)?{x:$,y:$}:this._getOriginFromCorner(e,r),d={target:e,action:l,actionHandler:h,actionPerformed:!1,corner:r,scaleX:e.scaleX,scaleY:e.scaleY,skewX:e.skewX,skewY:e.skewY,offsetX:n.x-e.left,offsetY:n.y-e.top,originX:u.x,originY:u.y,ex:n.x,ey:n.y,lastX:n.x,lastY:n.y,theta:pt(e.angle),width:e.width,height:e.height,shiftKey:t.shiftKey,altKey:c,original:w(w({},ur(e)),{},{originX:u.x,originY:u.y})};this._currentTransform=d,this.fire("before:transform",{e:t,transform:d})}setCursor(t){this.upperCanvasEl.style.cursor=t}_drawSelection(t){const{x:e,y:s,deltaX:i,deltaY:n}=this._groupSelector,r=new C(e,s).transform(this.viewportTransform),o=new C(e+i,s+n).transform(this.viewportTransform),h=this.selectionLineWidth/2;let l=Math.min(r.x,o.x),c=Math.min(r.y,o.y),u=Math.max(r.x,o.x),d=Math.max(r.y,o.y);this.selectionColor&&(t.fillStyle=this.selectionColor,t.fillRect(l,c,u-l,d-c)),this.selectionLineWidth&&this.selectionBorderColor&&(t.lineWidth=this.selectionLineWidth,t.strokeStyle=this.selectionBorderColor,l+=h,c+=h,u-=h,d-=h,Ot.prototype._setLineDash.call(this,t,this.selectionDashArray),t.strokeRect(l,c,u-l,d-c))}findTarget(t){if(this.skipTargetFind)return;const e=this.getViewportPoint(t),s=this._activeObject,i=this.getActiveObjects();if(this.targets=[],s&&i.length>=1){if(s.findControl(e,Li(t))||i.length>1&&this.searchPossibleTargets([s],e))return s;if(s===this.searchPossibleTargets([s],e)){if(this.preserveObjectStacking){const n=this.targets;this.targets=[];const r=this.searchPossibleTargets(this._objects,e);return t[this.altSelectionKey]&&r&&r!==s?(this.targets=n,s):r}return s}}return this.searchPossibleTargets(this._objects,e)}_pointIsInObjectSelectionArea(t,e){let s=t.getCoords();const i=this.getZoom(),n=t.padding/i;if(n){const[r,o,h,l]=s,c=Math.atan2(o.y-r.y,o.x-r.x),u=le(c)*n,d=ce(c)*n,f=u+d,g=u-d;s=[new C(r.x-g,r.y-f),new C(o.x+f,o.y-g),new C(h.x+g,h.y+f),new C(l.x-f,l.y+g)]}return gt.isPointInPolygon(e,s)}_checkTarget(t,e){return!!(t&&t.visible&&t.evented&&this._pointIsInObjectSelectionArea(t,as(e,void 0,this.viewportTransform))&&(!this.perPixelTargetFind&&!t.perPixelTargetFind||t.isEditing||!this.isTargetTransparent(t,e.x,e.y)))}_searchPossibleTargets(t,e){let s=t.length;for(;s--;){const i=t[s];if(this._checkTarget(i,e)){if(Oi(i)&&i.subTargetCheck){const n=this._searchPossibleTargets(i._objects,e);n&&this.targets.push(n)}return i}}}searchPossibleTargets(t,e){const s=this._searchPossibleTargets(t,e);if(s&&Oi(s)&&s.interactive&&this.targets[0]){const i=this.targets;for(let n=i.length-1;n>0;n--){const r=i[n];if(!Oi(r)||!r.interactive)return r}return i[0]}return s}getViewportPoint(t){return this._pointer?this._pointer:this.getPointer(t,!0)}getScenePoint(t){return this._absolutePointer?this._absolutePointer:this.getPointer(t)}getPointer(t){let e=arguments.length>1&&arguments[1]!==void 0&&arguments[1];const s=this.upperCanvasEl,i=s.getBoundingClientRect();let n=sa(t),r=i.width||0,o=i.height||0;r&&o||(Yt in i&&tr in i&&(o=Math.abs(i.top-i.bottom)),bt in i&&it in i&&(r=Math.abs(i.right-i.left))),this.calcOffset(),n.x=n.x-this._offset.left,n.y=n.y-this._offset.top,e||(n=as(n,void 0,this.viewportTransform));const h=this.getRetinaScaling();h!==1&&(n.x/=h,n.y/=h);const l=r===0||o===0?new C(1,1):new C(s.width/r,s.height/o);return n.multiply(l)}_setDimensionsImpl(t,e){this._resetTransformEventData(),super._setDimensionsImpl(t,e),this._isCurrentlyDrawing&&this.freeDrawingBrush&&this.freeDrawingBrush._setBrushStyles(this.contextTop)}_createCacheCanvas(){this.pixelFindCanvasEl=Se(),this.pixelFindContext=this.pixelFindCanvasEl.getContext("2d",{willReadFrequently:!0}),this.setTargetFindTolerance(this.targetFindTolerance)}getTopContext(){return this.elements.upper.ctx}getSelectionContext(){return this.elements.upper.ctx}getSelectionElement(){return this.elements.upper.el}getActiveObject(){return this._activeObject}getActiveObjects(){const t=this._activeObject;return os(t)?t.getObjects():t?[t]:[]}_fireSelectionEvents(t,e){let s=!1,i=!1;const n=this.getActiveObjects(),r=[],o=[];t.forEach((h=>{n.includes(h)||(s=!0,h.fire("deselected",{e,target:h}),o.push(h))})),n.forEach((h=>{t.includes(h)||(s=!0,h.fire("selected",{e,target:h}),r.push(h))})),t.length>0&&n.length>0?(i=!0,s&&this.fire("selection:updated",{e,selected:r,deselected:o})):n.length>0?(i=!0,this.fire("selection:created",{e,selected:r})):t.length>0&&(i=!0,this.fire("selection:cleared",{e,deselected:o})),i&&(this._objectsToRender=void 0)}setActiveObject(t,e){const s=this.getActiveObjects(),i=this._setActiveObject(t,e);return this._fireSelectionEvents(s,e),i}_setActiveObject(t,e){const s=this._activeObject;return s!==t&&!(!this._discardActiveObject(e,t)&&this._activeObject)&&!t.onSelect({e})&&(this._activeObject=t,os(t)&&s!==t&&t.set("canvas",this),t.setCoords(),!0)}_discardActiveObject(t,e){const s=this._activeObject;return!!s&&!s.onDeselect({e:t,object:e})&&(this._currentTransform&&this._currentTransform.target===s&&this.endCurrentTransform(t),os(s)&&s===this._hoveredTarget&&(this._hoveredTarget=void 0),this._activeObject=void 0,!0)}discardActiveObject(t){const e=this.getActiveObjects(),s=this.getActiveObject();e.length&&this.fire("before:selection:cleared",{e:t,deselected:[s]});const i=this._discardActiveObject(t);return this._fireSelectionEvents(e,t),i}endCurrentTransform(t){const e=this._currentTransform;this._finalizeCurrentTransform(t),e&&e.target&&(e.target.isMoving=!1),this._currentTransform=null}_finalizeCurrentTransform(t){const e=this._currentTransform,s=e.target,i={e:t,target:s,transform:e,action:e.action};s._scaling&&(s._scaling=!1),s.setCoords(),e.actionPerformed&&(this.fire("object:modified",i),s.fire(Mi,i))}setViewportTransform(t){super.setViewportTransform(t);const e=this._activeObject;e&&e.setCoords()}destroy(){const t=this._activeObject;os(t)&&(t.removeAll(),t.dispose()),delete this._activeObject,super.destroy(),this.pixelFindContext=null,this.pixelFindCanvasEl=void 0}clear(){this.discardActiveObject(),this._activeObject=void 0,this.clearContext(this.contextTop),super.clear()}drawControls(t){const e=this._activeObject;e&&e._renderControls(t)}_toObject(t,e,s){const i=this._realizeGroupTransformOnObject(t),n=super._toObject(t,e,s);return t.set(i),n}_realizeGroupTransformOnObject(t){const{group:e}=t;if(e&&os(e)&&this._activeObject===e){const s=rs(t,["angle","flipX","flipY",it,Bt,Qt,Ss,Cs,Yt]);return na(t,e.calcOwnMatrix()),s}return{}}_setSVGObject(t,e,s){const i=this._realizeGroupTransformOnObject(e);super._setSVGObject(t,e,s),e.set(i)}}x(nn,"ownDefaults",{uniformScaling:!0,uniScaleKey:"shiftKey",centeredScaling:!1,centeredRotation:!1,centeredKey:"altKey",altActionKey:"shiftKey",selection:!0,selectionKey:"shiftKey",selectionColor:"rgba(100, 100, 255, 0.3)",selectionDashArray:[],selectionBorderColor:"rgba(255, 255, 255, 0.3)",selectionLineWidth:1,selectionFullyContained:!1,hoverCursor:"move",moveCursor:"move",defaultCursor:"default",freeDrawingCursor:"crosshair",notAllowedCursor:"not-allowed",perPixelTargetFind:!1,targetFindTolerance:0,skipTargetFind:!1,stopContextMenu:!1,fireRightClick:!1,fireMiddleClick:!1,enablePointerEvents:!1,containerClass:"canvas-container",preserveObjectStacking:!1});class Xu{constructor(t){x(this,"targets",[]),x(this,"__disposer",void 0);const e=()=>{const{hiddenTextarea:i}=t.getActiveObject()||{};i&&i.focus()},s=t.upperCanvasEl;s.addEventListener("click",e),this.__disposer=()=>s.removeEventListener("click",e)}exitTextEditing(){this.target=void 0,this.targets.forEach((t=>{t.isEditing&&t.exitEditing()}))}add(t){this.targets.push(t)}remove(t){this.unregister(t),ss(this.targets,t)}register(t){this.target=t}unregister(t){t===this.target&&(this.target=void 0)}onMouseMove(t){var e;!((e=this.target)===null||e===void 0)&&e.isEditing&&this.target.updateSelectionOnMouseMove(t)}clear(){this.targets=[],this.target=void 0}dispose(){this.clear(),this.__disposer(),delete this.__disposer}}const Uu=["target","oldTarget","fireCanvas","e"],se={passive:!1},Fs=(a,t)=>{const e=a.getViewportPoint(t),s=a.getScenePoint(t);return{viewportPoint:e,scenePoint:s,pointer:e,absolutePointer:s}},$e=function(a){for(var t=arguments.length,e=new Array(t>1?t-1:0),s=1;s<t;s++)e[s-1]=arguments[s];return a.addEventListener(...e)},oe=function(a){for(var t=arguments.length,e=new Array(t>1?t-1:0),s=1;s<t;s++)e[s-1]=arguments[s];return a.removeEventListener(...e)},Yu={mouse:{in:"over",out:"out",targetIn:"mouseover",targetOut:"mouseout",canvasIn:"mouse:over",canvasOut:"mouse:out"},drag:{in:"enter",out:"leave",targetIn:"dragenter",targetOut:"dragleave",canvasIn:"drag:enter",canvasOut:"drag:leave"}};class jr extends nn{constructor(t){super(t,arguments.length>1&&arguments[1]!==void 0?arguments[1]:{}),x(this,"_isClick",void 0),x(this,"textEditingManager",new Xu(this)),["_onMouseDown","_onTouchStart","_onMouseMove","_onMouseUp","_onTouchEnd","_onResize","_onMouseWheel","_onMouseOut","_onMouseEnter","_onContextMenu","_onClick","_onDragStart","_onDragEnd","_onDragProgress","_onDragOver","_onDragEnter","_onDragLeave","_onDrop"].forEach((e=>{this[e]=this[e].bind(this)})),this.addOrRemove($e,"add")}_getEventPrefix(){return this.enablePointerEvents?"pointer":"mouse"}addOrRemove(t,e){const s=this.upperCanvasEl,i=this._getEventPrefix();t(Zo(s),"resize",this._onResize),t(s,i+"down",this._onMouseDown),t(s,"".concat(i,"move"),this._onMouseMove,se),t(s,"".concat(i,"out"),this._onMouseOut),t(s,"".concat(i,"enter"),this._onMouseEnter),t(s,"wheel",this._onMouseWheel,{passive:!1}),t(s,"contextmenu",this._onContextMenu),t(s,"click",this._onClick),t(s,"dblclick",this._onClick),t(s,"dragstart",this._onDragStart),t(s,"dragend",this._onDragEnd),t(s,"dragover",this._onDragOver),t(s,"dragenter",this._onDragEnter),t(s,"dragleave",this._onDragLeave),t(s,"drop",this._onDrop),this.enablePointerEvents||t(s,"touchstart",this._onTouchStart,se)}removeListeners(){this.addOrRemove(oe,"remove");const t=this._getEventPrefix(),e=ue(this.upperCanvasEl);oe(e,"".concat(t,"up"),this._onMouseUp),oe(e,"touchend",this._onTouchEnd,se),oe(e,"".concat(t,"move"),this._onMouseMove,se),oe(e,"touchmove",this._onMouseMove,se),clearTimeout(this._willAddMouseDown)}_onMouseWheel(t){this.__onMouseWheel(t)}_onMouseOut(t){const e=this._hoveredTarget,s=w({e:t},Fs(this,t));this.fire("mouse:out",w(w({},s),{},{target:e})),this._hoveredTarget=void 0,e&&e.fire("mouseout",w({},s)),this._hoveredTargets.forEach((i=>{this.fire("mouse:out",w(w({},s),{},{target:i})),i&&i.fire("mouseout",w({},s))})),this._hoveredTargets=[]}_onMouseEnter(t){this._currentTransform||this.findTarget(t)||(this.fire("mouse:over",w({e:t},Fs(this,t))),this._hoveredTarget=void 0,this._hoveredTargets=[])}_onDragStart(t){this._isClick=!1;const e=this.getActiveObject();if(e&&e.onDragStart(t)){this._dragSource=e;const s={e:t,target:e};return this.fire("dragstart",s),e.fire("dragstart",s),void $e(this.upperCanvasEl,"drag",this._onDragProgress)}ia(t)}_renderDragEffects(t,e,s){let i=!1;const n=this._dropTarget;n&&n!==e&&n!==s&&(n.clearContextTop(),i=!0),e?.clearContextTop(),s!==e&&s?.clearContextTop();const r=this.contextTop;r.save(),r.transform(...this.viewportTransform),e&&(r.save(),e.transform(r),e.renderDragSourceEffect(t),r.restore(),i=!0),s&&(r.save(),s.transform(r),s.renderDropTargetEffect(t),r.restore(),i=!0),r.restore(),i&&(this.contextTopDirty=!0)}_onDragEnd(t){const e=!!t.dataTransfer&&t.dataTransfer.dropEffect!==jt,s=e?this._activeObject:void 0,i={e:t,target:this._dragSource,subTargets:this.targets,dragSource:this._dragSource,didDrop:e,dropTarget:s};oe(this.upperCanvasEl,"drag",this._onDragProgress),this.fire("dragend",i),this._dragSource&&this._dragSource.fire("dragend",i),delete this._dragSource,this._onMouseUp(t)}_onDragProgress(t){const e={e:t,target:this._dragSource,dragSource:this._dragSource,dropTarget:this._draggedoverTarget};this.fire("drag",e),this._dragSource&&this._dragSource.fire("drag",e)}findDragTargets(t){return this.targets=[],{target:this._searchPossibleTargets(this._objects,this.getViewportPoint(t)),targets:[...this.targets]}}_onDragOver(t){const e="dragover",{target:s,targets:i}=this.findDragTargets(t),n=this._dragSource,r={e:t,target:s,subTargets:i,dragSource:n,canDrop:!1,dropTarget:void 0};let o;this.fire(e,r),this._fireEnterLeaveEvents(s,r),s&&(s.canDrop(t)&&(o=s),s.fire(e,r));for(let h=0;h<i.length;h++){const l=i[h];l.canDrop(t)&&(o=l),l.fire(e,r)}this._renderDragEffects(t,n,o),this._dropTarget=o}_onDragEnter(t){const{target:e,targets:s}=this.findDragTargets(t),i={e:t,target:e,subTargets:s,dragSource:this._dragSource};this.fire("dragenter",i),this._fireEnterLeaveEvents(e,i)}_onDragLeave(t){const e={e:t,target:this._draggedoverTarget,subTargets:this.targets,dragSource:this._dragSource};this.fire("dragleave",e),this._fireEnterLeaveEvents(void 0,e),this._renderDragEffects(t,this._dragSource),this._dropTarget=void 0,this.targets=[],this._hoveredTargets=[]}_onDrop(t){const{target:e,targets:s}=this.findDragTargets(t),i=this._basicEventHandler("drop:before",w({e:t,target:e,subTargets:s,dragSource:this._dragSource},Fs(this,t)));i.didDrop=!1,i.dropTarget=void 0,this._basicEventHandler("drop",i),this.fire("drop:after",i)}_onContextMenu(t){const e=this.findTarget(t),s=this.targets||[],i=this._basicEventHandler("contextmenu:before",{e:t,target:e,subTargets:s});return this.stopContextMenu&&ia(t),this._basicEventHandler("contextmenu",i),!1}_onClick(t){const e=t.detail;e>3||e<2||(this._cacheTransformEventData(t),e==2&&t.type==="dblclick"&&this._handleEvent(t,"dblclick"),e==3&&this._handleEvent(t,"tripleclick"),this._resetTransformEventData())}getPointerId(t){const e=t.changedTouches;return e?e[0]&&e[0].identifier:this.enablePointerEvents?t.pointerId:-1}_isMainEvent(t){return t.isPrimary===!0||t.isPrimary!==!1&&(t.type==="touchend"&&t.touches.length===0||!t.changedTouches||t.changedTouches[0].identifier===this.mainTouchId)}_onTouchStart(t){let e=!this.allowTouchScrolling;const s=this._activeObject;this.mainTouchId===void 0&&(this.mainTouchId=this.getPointerId(t)),this.__onMouseDown(t),(this.isDrawingMode||s&&this._target===s)&&(e=!0),e&&t.preventDefault(),this._resetTransformEventData();const i=this.upperCanvasEl,n=this._getEventPrefix(),r=ue(i);$e(r,"touchend",this._onTouchEnd,se),e&&$e(r,"touchmove",this._onMouseMove,se),oe(i,"".concat(n,"down"),this._onMouseDown)}_onMouseDown(t){this.__onMouseDown(t),this._resetTransformEventData();const e=this.upperCanvasEl,s=this._getEventPrefix();oe(e,"".concat(s,"move"),this._onMouseMove,se);const i=ue(e);$e(i,"".concat(s,"up"),this._onMouseUp),$e(i,"".concat(s,"move"),this._onMouseMove,se)}_onTouchEnd(t){if(t.touches.length>0)return;this.__onMouseUp(t),this._resetTransformEventData(),delete this.mainTouchId;const e=this._getEventPrefix(),s=ue(this.upperCanvasEl);oe(s,"touchend",this._onTouchEnd,se),oe(s,"touchmove",this._onMouseMove,se),this._willAddMouseDown&&clearTimeout(this._willAddMouseDown),this._willAddMouseDown=setTimeout((()=>{$e(this.upperCanvasEl,"".concat(e,"down"),this._onMouseDown),this._willAddMouseDown=0}),400)}_onMouseUp(t){this.__onMouseUp(t),this._resetTransformEventData();const e=this.upperCanvasEl,s=this._getEventPrefix();if(this._isMainEvent(t)){const i=ue(this.upperCanvasEl);oe(i,"".concat(s,"up"),this._onMouseUp),oe(i,"".concat(s,"move"),this._onMouseMove,se),$e(e,"".concat(s,"move"),this._onMouseMove,se)}}_onMouseMove(t){const e=this.getActiveObject();!this.allowTouchScrolling&&(!e||!e.shouldStartDragging(t))&&t.preventDefault&&t.preventDefault(),this.__onMouseMove(t)}_onResize(){this.calcOffset(),this._resetTransformEventData()}_shouldRender(t){const e=this.getActiveObject();return!!e!=!!t||e&&t&&e!==t}__onMouseUp(t){var e;this._cacheTransformEventData(t),this._handleEvent(t,"up:before");const s=this._currentTransform,i=this._isClick,n=this._target,{button:r}=t;if(r)return(this.fireMiddleClick&&r===1||this.fireRightClick&&r===2)&&this._handleEvent(t,"up"),void this._resetTransformEventData();if(this.isDrawingMode&&this._isCurrentlyDrawing)return void this._onMouseUpInDrawingMode(t);if(!this._isMainEvent(t))return;let o,h,l=!1;if(s&&(this._finalizeCurrentTransform(t),l=s.actionPerformed),!i){const c=n===this._activeObject;this.handleSelection(t),l||(l=this._shouldRender(n)||!c&&n===this._activeObject)}if(n){const c=n.findControl(this.getViewportPoint(t),Li(t)),{key:u,control:d}=c||{};if(h=u,n.selectable&&n!==this._activeObject&&n.activeOn==="up")this.setActiveObject(n,t),l=!0;else if(d){const f=d.getMouseUpHandler(t,n,d);f&&(o=this.getScenePoint(t),f.call(d,t,s,o.x,o.y))}n.isMoving=!1}if(s&&(s.target!==n||s.corner!==h)){const c=s.target&&s.target.controls[s.corner],u=c&&c.getMouseUpHandler(t,s.target,c);o=o||this.getScenePoint(t),u&&u.call(c,t,s,o.x,o.y)}this._setCursorFromEvent(t,n),this._handleEvent(t,"up"),this._groupSelector=null,this._currentTransform=null,n&&(n.__corner=void 0),l?this.requestRenderAll():i||(e=this._activeObject)!==null&&e!==void 0&&e.isEditing||this.renderTop()}_basicEventHandler(t,e){const{target:s,subTargets:i=[]}=e;this.fire(t,e),s&&s.fire(t,e);for(let n=0;n<i.length;n++)i[n]!==s&&i[n].fire(t,e);return e}_handleEvent(t,e,s){const i=this._target,n=this.targets||[],r=w(w(w({e:t,target:i,subTargets:n},Fs(this,t)),{},{transform:this._currentTransform},e==="up:before"||e==="up"?{isClick:this._isClick,currentTarget:this.findTarget(t),currentSubTargets:this.targets}:{}),e==="down:before"||e==="down"?s:{});this.fire("mouse:".concat(e),r),i&&i.fire("mouse".concat(e),r);for(let o=0;o<n.length;o++)n[o]!==i&&n[o].fire("mouse".concat(e),r)}_onMouseDownInDrawingMode(t){this._isCurrentlyDrawing=!0,this.getActiveObject()&&(this.discardActiveObject(t),this.requestRenderAll());const e=this.getScenePoint(t);this.freeDrawingBrush&&this.freeDrawingBrush.onMouseDown(e,{e:t,pointer:e}),this._handleEvent(t,"down",{alreadySelected:!1})}_onMouseMoveInDrawingMode(t){if(this._isCurrentlyDrawing){const e=this.getScenePoint(t);this.freeDrawingBrush&&this.freeDrawingBrush.onMouseMove(e,{e:t,pointer:e})}this.setCursor(this.freeDrawingCursor),this._handleEvent(t,"move")}_onMouseUpInDrawingMode(t){const e=this.getScenePoint(t);this.freeDrawingBrush?this._isCurrentlyDrawing=!!this.freeDrawingBrush.onMouseUp({e:t,pointer:e}):this._isCurrentlyDrawing=!1,this._handleEvent(t,"up")}__onMouseDown(t){this._isClick=!0,this._cacheTransformEventData(t),this._handleEvent(t,"down:before");let e=this._target,s=!!e&&e===this._activeObject;const{button:i}=t;if(i)return(this.fireMiddleClick&&i===1||this.fireRightClick&&i===2)&&this._handleEvent(t,"down",{alreadySelected:s}),void this._resetTransformEventData();if(this.isDrawingMode)return void this._onMouseDownInDrawingMode(t);if(!this._isMainEvent(t)||this._currentTransform)return;let n=this._shouldRender(e),r=!1;if(this.handleMultiSelection(t,e)?(e=this._activeObject,r=!0,n=!0):this._shouldClearSelection(t,e)&&this.discardActiveObject(t),this.selection&&(!e||!e.selectable&&!e.isEditing&&e!==this._activeObject)){const o=this.getScenePoint(t);this._groupSelector={x:o.x,y:o.y,deltaY:0,deltaX:0}}if(s=!!e&&e===this._activeObject,e){e.selectable&&e.activeOn==="down"&&this.setActiveObject(e,t);const o=e.findControl(this.getViewportPoint(t),Li(t));if(e===this._activeObject&&(o||!r)){this._setupCurrentTransform(t,e,s);const h=o?o.control:void 0,l=this.getScenePoint(t),c=h&&h.getMouseDownHandler(t,e,h);c&&c.call(h,t,this._currentTransform,l.x,l.y)}}n&&(this._objectsToRender=void 0),this._handleEvent(t,"down",{alreadySelected:s}),n&&this.requestRenderAll()}_resetTransformEventData(){this._target=this._pointer=this._absolutePointer=void 0}_cacheTransformEventData(t){this._resetTransformEventData(),this._pointer=this.getViewportPoint(t),this._absolutePointer=as(this._pointer,void 0,this.viewportTransform),this._target=this._currentTransform?this._currentTransform.target:this.findTarget(t)}__onMouseMove(t){if(this._isClick=!1,this._cacheTransformEventData(t),this._handleEvent(t,"move:before"),this.isDrawingMode)return void this._onMouseMoveInDrawingMode(t);if(!this._isMainEvent(t))return;const e=this._groupSelector;if(e){const s=this.getScenePoint(t);e.deltaX=s.x-e.x,e.deltaY=s.y-e.y,this.renderTop()}else if(this._currentTransform)this._transformObject(t);else{const s=this.findTarget(t);this._setCursorFromEvent(t,s),this._fireOverOutEvents(t,s)}this.textEditingManager.onMouseMove(t),this._handleEvent(t,"move"),this._resetTransformEventData()}_fireOverOutEvents(t,e){const s=this._hoveredTarget,i=this._hoveredTargets,n=this.targets,r=Math.max(i.length,n.length);this.fireSyntheticInOutEvents("mouse",{e:t,target:e,oldTarget:s,fireCanvas:!0});for(let o=0;o<r;o++)n[o]===e||i[o]&&i[o]===s||this.fireSyntheticInOutEvents("mouse",{e:t,target:n[o],oldTarget:i[o]});this._hoveredTarget=e,this._hoveredTargets=this.targets.concat()}_fireEnterLeaveEvents(t,e){const s=this._draggedoverTarget,i=this._hoveredTargets,n=this.targets,r=Math.max(i.length,n.length);this.fireSyntheticInOutEvents("drag",w(w({},e),{},{target:t,oldTarget:s,fireCanvas:!0}));for(let o=0;o<r;o++)this.fireSyntheticInOutEvents("drag",w(w({},e),{},{target:n[o],oldTarget:i[o]}));this._draggedoverTarget=t}fireSyntheticInOutEvents(t,e){let{target:s,oldTarget:i,fireCanvas:n,e:r}=e,o=lt(e,Uu);const{targetIn:h,targetOut:l,canvasIn:c,canvasOut:u}=Yu[t],d=i!==s;if(i&&d){const f=w(w({},o),{},{e:r,target:i,nextTarget:s},Fs(this,r));n&&this.fire(u,f),i.fire(l,f)}if(s&&d){const f=w(w({},o),{},{e:r,target:s,previousTarget:i},Fs(this,r));n&&this.fire(c,f),s.fire(h,f)}}__onMouseWheel(t){this._cacheTransformEventData(t),this._handleEvent(t,"wheel"),this._resetTransformEventData()}_transformObject(t){const e=this.getScenePoint(t),s=this._currentTransform,i=s.target,n=i.group?as(e,void 0,i.group.calcTransformMatrix()):e;s.shiftKey=t.shiftKey,s.altKey=!!this.centeredKey&&t[this.centeredKey],this._performTransformAction(t,s,n),s.actionPerformed&&this.requestRenderAll()}_performTransformAction(t,e,s){const{action:i,actionHandler:n,target:r}=e,o=!!n&&n(t,e,s.x,s.y);o&&r.setCoords(),i==="drag"&&o&&(e.target.isMoving=!0,this.setCursor(e.target.moveCursor||this.moveCursor)),e.actionPerformed=e.actionPerformed||o}_setCursorFromEvent(t,e){if(!e)return void this.setCursor(this.defaultCursor);let s=e.hoverCursor||this.hoverCursor;const i=os(this._activeObject)?this._activeObject:null,n=(!i||e.group!==i)&&e.findControl(this.getViewportPoint(t));if(n){const r=n.control;this.setCursor(r.cursorStyleHandler(t,r,e))}else e.subTargetCheck&&this.targets.concat().reverse().map((r=>{s=r.hoverCursor||s})),this.setCursor(s)}handleMultiSelection(t,e){const s=this._activeObject,i=os(s);if(s&&this._isSelectionKeyPressed(t)&&this.selection&&e&&e.selectable&&(s!==e||i)&&(i||!e.isDescendantOf(s)&&!s.isDescendantOf(e))&&!e.onSelect({e:t})&&!s.getActiveControl()){if(i){const n=s.getObjects();if(e===s){const r=this.getViewportPoint(t);if(!(e=this.searchPossibleTargets(n,r)||this.searchPossibleTargets(this._objects,r))||!e.selectable)return!1}e.group===s?(s.remove(e),this._hoveredTarget=e,this._hoveredTargets=[...this.targets],s.size()===1&&this._setActiveObject(s.item(0),t)):(s.multiSelectAdd(e),this._hoveredTarget=s,this._hoveredTargets=[...this.targets]),this._fireSelectionEvents(n,t)}else{s.isEditing&&s.exitEditing();const n=new(L.getClass("ActiveSelection"))([],{canvas:this});n.multiSelectAdd(s,e),this._hoveredTarget=n,this._setActiveObject(n,t),this._fireSelectionEvents([s],t)}return!0}return!1}handleSelection(t){if(!this.selection||!this._groupSelector)return!1;const{x:e,y:s,deltaX:i,deltaY:n}=this._groupSelector,r=new C(e,s),o=r.add(new C(i,n)),h=r.min(o),l=r.max(o).subtract(h),c=this.collectObjects({left:h.x,top:h.y,width:l.x,height:l.y},{includeIntersecting:!this.selectionFullyContained}),u=r.eq(o)?c[0]?[c[0]]:[]:c.length>1?c.filter((d=>!d.onSelect({e:t}))).reverse():c;if(u.length===1)this.setActiveObject(u[0],t);else if(u.length>1){const d=L.getClass("ActiveSelection");this.setActiveObject(new d(u,{canvas:this}),t)}return this._groupSelector=null,!0}clear(){this.textEditingManager.clear(),super.clear()}destroy(){this.removeListeners(),this.textEditingManager.dispose(),super.destroy()}}const wh={x1:0,y1:0,x2:0,y2:0},$u=w(w({},wh),{},{r1:0,r2:0}),Is=(a,t)=>isNaN(a)&&typeof t=="number"?t:a;function xh(a){return a&&/%$/.test(a)&&Number.isFinite(parseFloat(a))}function Sh(a,t){const e=typeof a=="number"?a:typeof a=="string"?parseFloat(a)/(xh(a)?100:1):NaN;return ls(0,Is(e,t),1)}const qu=/\s*;\s*/,Ku=/\s*:\s*/;function Ju(a,t){let e,s;const i=a.getAttribute("style");if(i){const r=i.split(qu);r[r.length-1]===""&&r.pop();for(let o=r.length;o--;){const[h,l]=r[o].split(Ku).map((c=>c.trim()));h==="stop-color"?e=l:h==="stop-opacity"&&(s=l)}}const n=new nt(e||a.getAttribute("stop-color")||"rgb(0,0,0)");return{offset:Sh(a.getAttribute("offset"),0),color:n.toRgb(),opacity:Is(parseFloat(s||a.getAttribute("stop-opacity")||""),1)*n.getAlpha()*t}}function Zu(a,t){const e=[],s=a.getElementsByTagName("stop"),i=Sh(t,1);for(let n=s.length;n--;)e.push(Ju(s[n],i));return e}function Ch(a){return a.nodeName==="linearGradient"||a.nodeName==="LINEARGRADIENT"?"linear":"radial"}function Ah(a){return a.getAttribute("gradientUnits")==="userSpaceOnUse"?"pixels":"percentage"}function pe(a,t){return a.getAttribute(t)}function Qu(a,t){return(function(e,s){let i,{width:n,height:r,gradientUnits:o}=s;return Object.entries(e).reduce(((h,l)=>{let[c,u]=l;if(u==="Infinity")i=1;else if(u==="-Infinity")i=0;else{const d=typeof u=="string";i=d?parseFloat(u):u,d&&xh(u)&&(i*=.01,o==="pixels"&&(c!=="x1"&&c!=="x2"&&c!=="r2"||(i*=n),c!=="y1"&&c!=="y2"||(i*=r)))}return h[c]=i,h}),{})})(Ch(a)==="linear"?(function(e){return{x1:pe(e,"x1")||0,y1:pe(e,"y1")||0,x2:pe(e,"x2")||"100%",y2:pe(e,"y2")||0}})(a):(function(e){return{x1:pe(e,"fx")||pe(e,"cx")||"50%",y1:pe(e,"fy")||pe(e,"cy")||"50%",r1:0,x2:pe(e,"cx")||"50%",y2:pe(e,"cy")||"50%",r2:pe(e,"r")||"50%"}})(a),w(w({},t),{},{gradientUnits:Ah(a)}))}class ci{constructor(t){const{type:e="linear",gradientUnits:s="pixels",coords:i={},colorStops:n=[],offsetX:r=0,offsetY:o=0,gradientTransform:h,id:l}=t||{};Object.assign(this,{type:e,gradientUnits:s,coords:w(w({},e==="radial"?$u:wh),i),colorStops:n,offsetX:r,offsetY:o,gradientTransform:h,id:l?"".concat(l,"_").concat(Ue()):Ue()})}addColorStop(t){for(const e in t){const s=new nt(t[e]);this.colorStops.push({offset:parseFloat(e),color:s.toRgb(),opacity:s.getAlpha()})}return this}toObject(t){return w(w({},rs(this,t)),{},{type:this.type,coords:w({},this.coords),colorStops:this.colorStops.map((e=>w({},e))),offsetX:this.offsetX,offsetY:this.offsetY,gradientUnits:this.gradientUnits,gradientTransform:this.gradientTransform?[...this.gradientTransform]:void 0})}toSVG(t){let{additionalTransform:e}=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};const s=[],i=this.gradientTransform?this.gradientTransform.concat():Nt.concat(),n=this.gradientUnits==="pixels"?"userSpaceOnUse":"objectBoundingBox",r=this.colorStops.map((u=>w({},u))).sort(((u,d)=>u.offset-d.offset));let o=-this.offsetX,h=-this.offsetY;var l;n==="objectBoundingBox"?(o/=t.width,h/=t.height):(o+=t.width/2,h+=t.height/2),(l=t)&&typeof l._renderPathCommands=="function"&&this.gradientUnits!=="percentage"&&(o-=t.pathOffset.x,h-=t.pathOffset.y),i[4]-=o,i[5]-=h;const c=['id="SVGID_'.concat(this.id,'"'),'gradientUnits="'.concat(n,'"'),'gradientTransform="'.concat(e?e+" ":"").concat(ks(i),'"'),""].join(" ");if(this.type==="linear"){const{x1:u,y1:d,x2:f,y2:g}=this.coords;s.push("<linearGradient ",c,' x1="',u,'" y1="',d,'" x2="',f,'" y2="',g,`">
|
|
46
|
+
`),e}getSvgStyles(){const t=this.opacity!==void 0&&this.opacity!==1?"opacity: ".concat(this.opacity,";"):"",e=this.visible?"":" visibility: hidden;";return[t,this.getSvgFilter(),e].join("")}toClipPathSVG(t){const e=[],s=this._createSVGBgRect(t);s&&e.push(" ",s);for(let i=0;i<this._objects.length;i++)e.push(" ",this._objects[i].toClipPathSVG(t));return this._createBaseClipPathSVGMarkup(e,{reviver:t})}static fromObject(t,e){let{type:s,objects:i=[],layoutManager:n}=t,r=lt(t,ku);return Promise.all([Es(i,e),Qs(r,e)]).then((o=>{let[h,l]=o;const c=new this(h,w(w(w({},r),l),{},{layoutManager:new Mu}));if(n){const u=L.getClass(n.type),d=L.getClass(n.strategy);c.layoutManager=new u(new d)}else c.layoutManager=new hi;return c.layoutManager.subscribeTargets({type:je,target:c,targets:c.getObjects()}),c.setCoords(),c}))}}x(ee,"type","Group"),x(ee,"ownDefaults",{strokeWidth:0,subTargetCheck:!1,interactive:!1}),L.setClass(ee);const ah=(a,t)=>Math.min(t.width/a.width,t.height/a.height),hh=(a,t)=>Math.max(t.width/a.width,t.height/a.height),Fr="\\s*,?\\s*",li="".concat(Fr,"(").concat(fe,")"),Pu="".concat(li).concat(li).concat(li).concat(Fr,"([01])").concat(Fr,"([01])").concat(li).concat(li),Ou={m:"l",M:"L"},Du=(a,t,e,s,i,n,r,o,h,l,c)=>{const u=le(a),d=ce(a),f=le(t),g=ce(t),p=e*i*f-s*n*g+r,b=s*i*f+e*n*g+o;return["C",l+h*(-e*i*d-s*n*u),c+h*(-s*i*d+e*n*u),p+h*(e*i*g+s*n*f),b+h*(s*i*g-e*n*f),p,b]},lh=(a,t,e,s)=>{const i=Math.atan2(t,a),n=Math.atan2(s,e);return n>=i?n-i:2*Math.PI-(i-n)};function Ir(a,t,e,s,i,n,r,o){let h;if(et.cachesBoundsOfCurve&&(h=[...arguments].join(),$s.boundsOfCurveCache[h]))return $s.boundsOfCurveCache[h];const l=Math.sqrt,c=Math.abs,u=[],d=[[0,0],[0,0]];let f=6*a-12*e+6*i,g=-3*a+9*e-9*i+3*r,p=3*e-3*a;for(let _=0;_<2;++_){if(_>0&&(f=6*t-12*s+6*n,g=-3*t+9*s-9*n+3*o,p=3*s-3*t),c(g)<1e-12){if(c(f)<1e-12)continue;const P=-p/f;0<P&&P<1&&u.push(P);continue}const S=f*f-4*p*g;if(S<0)continue;const A=l(S),T=(-f+A)/(2*g);0<T&&T<1&&u.push(T);const k=(-f-A)/(2*g);0<k&&k<1&&u.push(k)}let b=u.length;const m=b,v=uh(a,t,e,s,i,n,r,o);for(;b--;){const{x:_,y:S}=v(u[b]);d[0][b]=_,d[1][b]=S}d[0][m]=a,d[1][m]=t,d[0][m+1]=r,d[1][m+1]=o;const y=[new C(Math.min(...d[0]),Math.min(...d[1])),new C(Math.max(...d[0]),Math.max(...d[1]))];return et.cachesBoundsOfCurve&&($s.boundsOfCurveCache[h]=y),y}const Ru=(a,t,e)=>{let[s,i,n,r,o,h,l,c]=e;const u=((d,f,g,p,b,m,v)=>{if(g===0||p===0)return[];let y=0,_=0,S=0;const A=Math.PI,T=v*Zn,k=ce(T),P=le(T),B=.5*(-P*d-k*f),F=.5*(-P*f+k*d),I=g**2,O=p**2,D=F**2,z=B**2,M=I*O-I*D-O*z;let R=Math.abs(g),U=Math.abs(p);if(M<0){const Zt=Math.sqrt(1-M/(I*O));R*=Zt,U*=Zt}else S=(b===m?-1:1)*Math.sqrt(M/(I*D+O*z));const ht=S*R*F/U,dt=-S*U*B/R,E=P*ht-k*dt+.5*d,H=k*ht+P*dt+.5*f;let V=lh(1,0,(B-ht)/R,(F-dt)/U),Q=lh((B-ht)/R,(F-dt)/U,(-B-ht)/R,(-F-dt)/U);m===0&&Q>0?Q-=2*A:m===1&&Q<0&&(Q+=2*A);const Mt=Math.ceil(Math.abs(Q/A*2)),rt=[],N=Q/Mt,ft=8/3*Math.sin(N/4)*Math.sin(N/4)/Math.sin(N/2);let kt=V+N;for(let Zt=0;Zt<Mt;Zt++)rt[Zt]=Du(V,kt,P,k,R,U,E,H,ft,y,_),y=rt[Zt][5],_=rt[Zt][6],V=kt,kt+=N;return rt})(l-a,c-t,i,n,o,h,r);for(let d=0,f=u.length;d<f;d++)u[d][1]+=a,u[d][2]+=t,u[d][3]+=a,u[d][4]+=t,u[d][5]+=a,u[d][6]+=t;return u},ch=a=>{let t=0,e=0,s=0,i=0;const n=[];let r,o=0,h=0;for(const l of a){const c=[...l];let u;switch(c[0]){case"l":c[1]+=t,c[2]+=e;case"L":t=c[1],e=c[2],u=["L",t,e];break;case"h":c[1]+=t;case"H":t=c[1],u=["L",t,e];break;case"v":c[1]+=e;case"V":e=c[1],u=["L",t,e];break;case"m":c[1]+=t,c[2]+=e;case"M":t=c[1],e=c[2],s=c[1],i=c[2],u=["M",t,e];break;case"c":c[1]+=t,c[2]+=e,c[3]+=t,c[4]+=e,c[5]+=t,c[6]+=e;case"C":o=c[3],h=c[4],t=c[5],e=c[6],u=["C",c[1],c[2],o,h,t,e];break;case"s":c[1]+=t,c[2]+=e,c[3]+=t,c[4]+=e;case"S":r==="C"?(o=2*t-o,h=2*e-h):(o=t,h=e),t=c[3],e=c[4],u=["C",o,h,c[1],c[2],t,e],o=u[3],h=u[4];break;case"q":c[1]+=t,c[2]+=e,c[3]+=t,c[4]+=e;case"Q":o=c[1],h=c[2],t=c[3],e=c[4],u=["Q",o,h,t,e];break;case"t":c[1]+=t,c[2]+=e;case"T":r==="Q"?(o=2*t-o,h=2*e-h):(o=t,h=e),t=c[1],e=c[2],u=["Q",o,h,t,e];break;case"a":c[6]+=t,c[7]+=e;case"A":Ru(t,e,c).forEach((d=>n.push(d))),t=c[6],e=c[7];break;case"z":case"Z":t=s,e=i,u=["Z"]}u?(n.push(u),r=u[0]):r=""}return n},tn=(a,t,e,s)=>Math.sqrt((e-a)**2+(s-t)**2),uh=(a,t,e,s,i,n,r,o)=>h=>{const l=h**3,c=(f=>3*f**2*(1-f))(h),u=(f=>3*f*(1-f)**2)(h),d=(f=>(1-f)**3)(h);return new C(r*l+i*c+e*u+a*d,o*l+n*c+s*u+t*d)},dh=a=>a**2,fh=a=>2*a*(1-a),gh=a=>(1-a)**2,Lu=(a,t,e,s,i,n,r,o)=>h=>{const l=dh(h),c=fh(h),u=gh(h),d=3*(u*(e-a)+c*(i-e)+l*(r-i)),f=3*(u*(s-t)+c*(n-s)+l*(o-n));return Math.atan2(f,d)},Fu=(a,t,e,s,i,n)=>r=>{const o=dh(r),h=fh(r),l=gh(r);return new C(i*o+e*h+a*l,n*o+s*h+t*l)},Iu=(a,t,e,s,i,n)=>r=>{const o=1-r,h=2*(o*(e-a)+r*(i-e)),l=2*(o*(s-t)+r*(n-s));return Math.atan2(l,h)},ph=(a,t,e)=>{let s=new C(t,e),i=0;for(let n=1;n<=100;n+=1){const r=a(n/100);i+=tn(s.x,s.y,r.x,r.y),s=r}return i},Nu=(a,t)=>{let e,s=0,i=0,n={x:a.x,y:a.y},r=w({},n),o=.01,h=0;const l=a.iterator,c=a.angleFinder;for(;i<t&&o>1e-4;)r=l(s),h=s,e=tn(n.x,n.y,r.x,r.y),e+i>t?(s-=o,o/=2):(n=r,s+=o,i+=e);return w(w({},r),{},{angle:c(h)})},Nr=a=>{let t,e,s=0,i=0,n=0,r=0,o=0;const h=[];for(const l of a){const c={x:i,y:n,command:l[0],length:0};switch(l[0]){case"M":e=c,e.x=r=i=l[1],e.y=o=n=l[2];break;case"L":e=c,e.length=tn(i,n,l[1],l[2]),i=l[1],n=l[2];break;case"C":t=uh(i,n,l[1],l[2],l[3],l[4],l[5],l[6]),e=c,e.iterator=t,e.angleFinder=Lu(i,n,l[1],l[2],l[3],l[4],l[5],l[6]),e.length=ph(t,i,n),i=l[5],n=l[6];break;case"Q":t=Fu(i,n,l[1],l[2],l[3],l[4]),e=c,e.iterator=t,e.angleFinder=Iu(i,n,l[1],l[2],l[3],l[4]),e.length=ph(t,i,n),i=l[3],n=l[4];break;case"Z":e=c,e.destX=r,e.destY=o,e.length=tn(i,n,r,o),i=r,n=o}s+=e.length,h.push(e)}return h.push({length:s,x:i,y:n}),h},mh=function(a,t){let e=arguments.length>2&&arguments[2]!==void 0?arguments[2]:Nr(a),s=0;for(;t-e[s].length>0&&s<e.length-2;)t-=e[s].length,s++;const i=e[s],n=t/i.length,r=a[s];switch(i.command){case"M":return{x:i.x,y:i.y,angle:0};case"Z":return w(w({},new C(i.x,i.y).lerp(new C(i.destX,i.destY),n)),{},{angle:Math.atan2(i.destY-i.y,i.destX-i.x)});case"L":return w(w({},new C(i.x,i.y).lerp(new C(r[1],r[2]),n)),{},{angle:Math.atan2(r[2]-i.y,r[1]-i.x)});case"C":case"Q":return Nu(i,t)}},ju=new RegExp("[mzlhvcsqta][^mzlhvcsqta]*","gi"),bh=new RegExp(Pu,"g"),Bu=new RegExp(fe,"gi"),Hu={m:2,l:2,h:1,v:1,c:6,s:4,q:4,t:2,a:7},vh=a=>{var t;const e=[],s=(t=a.match(ju))!==null&&t!==void 0?t:[];for(const i of s){const n=i[0];if(n==="z"||n==="Z"){e.push([n]);continue}const r=Hu[n.toLowerCase()];let o=[];if(n==="a"||n==="A"){bh.lastIndex=0;for(let h=null;h=bh.exec(i);)o.push(...h.slice(1))}else o=i.match(Bu)||[];for(let h=0;h<o.length;h+=r){const l=new Array(r),c=Ou[n];l[0]=h>0&&c?c:n;for(let u=0;u<r;u++)l[u+1]=parseFloat(o[h+u]);e.push(l)}}return e},zu=function(a){let t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:0,e=new C(a[0]),s=new C(a[1]),i=1,n=0;const r=[],o=a.length,h=o>2;let l;for(h&&(i=a[2].x<s.x?-1:a[2].x===s.x?0:1,n=a[2].y<s.y?-1:a[2].y===s.y?0:1),r.push(["M",e.x-i*t,e.y-n*t]),l=1;l<o;l++){if(!e.eq(s)){const c=e.midPointFrom(s);r.push(["Q",e.x,e.y,c.x,c.y])}e=a[l],l+1<a.length&&(s=a[l+1])}return h&&(i=e.x>a[l-2].x?1:e.x===a[l-2].x?0:-1,n=e.y>a[l-2].y?1:e.y===a[l-2].y?0:-1),r.push(["L",e.x+i*t,e.y+n*t]),r},yh=(a,t)=>a.map((e=>e.map(((s,i)=>i===0||t===void 0?s:ot(s,t))).join(" "))).join(" ");function en(a,t){const e=a.style;e&&t&&(typeof t=="string"?e.cssText+=";"+t:Object.entries(t).forEach((s=>{let[i,n]=s;return e.setProperty(i,n)})))}const Gu=(a,t)=>Math.floor(Math.random()*(t-a+1))+a;function _h(a){let t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};const e=t.onComplete||es,s=new(Ys()).XMLHttpRequest,i=t.signal,n=function(){s.abort()},r=function(){i&&i.removeEventListener("abort",n),s.onerror=s.ontimeout=es};if(i&&i.aborted)throw new Kn("request");return i&&i.addEventListener("abort",n,{once:!0}),s.onreadystatechange=function(){s.readyState===4&&(r(),e(s),s.onreadystatechange=es)},s.onerror=s.ontimeout=r,s.open("get",a,!0),s.send(),s}const sn=(a,t)=>{let e=a._findCenterFromElement();a.transformMatrix&&((s=>{if(s.transformMatrix){const{scaleX:i,scaleY:n,angle:r,skewX:o}=is(s.transformMatrix);s.flipX=!1,s.flipY=!1,s.set(Bt,i),s.set(Qt,n),s.angle=r,s.skewX=o,s.skewY=0}})(a),e=e.transform(a.transformMatrix)),delete a.transformMatrix,t&&(a.scaleX*=t.scaleX,a.scaleY*=t.scaleY,a.cropX=t.cropX,a.cropY=t.cropY,e.x+=t.offsetLeft,e.y+=t.offsetTop,a.width=t.width,a.height=t.height),a.setPositionByOrigin(e,$,$)};var Vu=Object.freeze({__proto__:null,addTransformToObject:na,animate:Er,animateColor:La,applyTransformToObject:Ms,calcAngleBetweenVectors:Vi,calcDimensionsMatrix:Js,calcPlaneChangeMatrix:ei,calcVectorRotation:Ea,cancelAnimFrame:Vo,capValue:ls,composeMatrix:$o,copyCanvasElement:a=>{var t;const e=te(a);return(t=e.getContext("2d"))===null||t===void 0||t.drawImage(a,0,0),e},cos:le,createCanvasElement:Se,createImage:Wo,createRotateMatrix:ns,createScaleMatrix:Ri,createSkewXMatrix:ar,createSkewYMatrix:hr,createTranslateMatrix:Ts,createVector:zi,crossProduct:Ps,degreesToRadians:pt,dotProduct:ka,ease:Pc,enlivenObjectEnlivables:Qs,enlivenObjects:Es,findScaleToCover:hh,findScaleToFit:ah,getBoundsOfCurve:Ir,getOrthonormalVector:wr,getPathSegmentsInfo:Nr,getPointOnPath:mh,getPointer:sa,getRandomInt:Gu,getRegularPolygonPath:(a,t)=>{const e=2*Math.PI/a;let s=-We;a%2==0&&(s+=e/2);const i=new Array(a+1);for(let n=0;n<a;n++){const r=n*e+s,{x:o,y:h}=new C(le(r),ce(r)).scalarMultiply(t);i[n]=[n===0?"M":"L",o,h]}return i[a]=["Z"],i},getSmoothPathFromPoints:zu,getSvgAttributes:a=>{const t=["instantiated_by_use","style","id","class"];switch(a){case"linearGradient":return t.concat(["x1","y1","x2","y2","gradientUnits","gradientTransform"]);case"radialGradient":return t.concat(["gradientUnits","gradientTransform","cx","cy","r","fx","fy","fr"]);case"stop":return t.concat(["offset","stop-color","stop-opacity"])}return t},getUnitVector:Wi,groupSVGElements:(a,t)=>a&&a.length===1?a[0]:new ee(a,t),hasStyleChanged:qi,invertTransform:$t,isBetweenVectors:xr,isIdentityMatrix:Xo,isTouchEvent:Li,isTransparent:Va,joinPath:yh,loadImage:Zs,magnitude:Gi,makeBoundingBoxFromPoints:Ae,makePathSimpler:ch,matrixToSVG:ks,mergeClipPaths:(a,t)=>{var e;let s=a,i=t;s.inverted&&!i.inverted&&(s=t,i=a),dr(i,(e=i.group)===null||e===void 0?void 0:e.calcTransformMatrix(),s.calcTransformMatrix());const n=s.inverted&&i.inverted;return n&&(s.inverted=i.inverted=!1),new ee([s],{clipPath:i,inverted:n})},multiplyTransformMatrices:vt,multiplyTransformMatrixArray:Di,parsePath:vh,parsePreserveAspectRatioAttribute:pr,parseUnit:zt,pick:rs,projectStrokeOnPoints:Ua,qrDecompose:is,radiansToDegrees:Ce,removeFromArray:ss,removeTransformFromObject:(a,t)=>{const e=$t(t),s=vt(e,a.calcOwnMatrix());Ms(a,s)},removeTransformMatrixForSvgParsing:sn,request:_h,requestAnimFrame:Ks,resetObjectTransform:ra,rotatePoint:(a,t,e)=>a.rotate(e,t),rotateVector:_r,saveObjectTransform:ur,sendObjectToPlane:dr,sendPointToPlane:as,sendVectorToPlane:oa,setStyle:en,sin:ce,sizeAfterTransform:Fi,string:ru,stylesFromArray:qa,stylesToArray:$a,toBlob:or,toDataURL:rr,toFixed:ot,transformPath:(a,t,e)=>(e&&(t=vt(t,[1,0,0,1,-e.x,-e.y])),a.map((s=>{const i=[...s];for(let n=1;n<s.length-1;n+=2){const{x:r,y:o}=Pt({x:s[n],y:s[n+1]},t);i[n]=r,i[n+1]=o}return i}))),transformPoint:Pt});class Wu extends ea{constructor(t){let{allowTouchScrolling:e=!1,containerClass:s=""}=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};super(t),x(this,"upper",void 0),x(this,"container",void 0);const{el:i}=this.lower,n=this.createUpperCanvas();this.upper={el:n,ctx:n.getContext("2d")},this.applyCanvasStyle(i,{allowTouchScrolling:e}),this.applyCanvasStyle(n,{allowTouchScrolling:e,styles:{position:"absolute",left:"0",top:"0"}});const r=this.createContainerElement();r.classList.add(s),i.parentNode&&i.parentNode.replaceChild(r,i),r.append(i,n),this.container=r}createUpperCanvas(){const{el:t}=this.lower,e=Se();return e.className=t.className,e.classList.remove("lower-canvas"),e.classList.add("upper-canvas"),e.setAttribute("data-fabric","top"),e.style.cssText=t.style.cssText,e.setAttribute("draggable","true"),e}createContainerElement(){const t=xs().createElement("div");return t.setAttribute("data-fabric","wrapper"),en(t,{position:"relative"}),ta(t),t}applyCanvasStyle(t,e){const{styles:s,allowTouchScrolling:i}=e;en(t,w(w({},s),{},{"touch-action":i?"manipulation":jt})),ta(t)}setDimensions(t,e){super.setDimensions(t,e);const{el:s,ctx:i}=this.upper;Qo(s,i,t,e)}setCSSDimensions(t){super.setCSSDimensions(t),cr(this.upper.el,t),cr(this.container,t)}cleanupDOM(t){const e=this.container,{el:s}=this.lower,{el:i}=this.upper;super.cleanupDOM(t),e.removeChild(i),e.removeChild(s),e.parentNode&&e.parentNode.replaceChild(s,e)}dispose(){super.dispose(),xe().dispose(this.upper.el),delete this.upper,delete this.container}}class nn extends ti{constructor(){super(...arguments),x(this,"targets",[]),x(this,"_hoveredTargets",[]),x(this,"_currentTransform",null),x(this,"_groupSelector",null),x(this,"contextTopDirty",!1)}static getDefaults(){return w(w({},super.getDefaults()),nn.ownDefaults)}get upperCanvasEl(){var t;return(t=this.elements.upper)===null||t===void 0?void 0:t.el}get contextTop(){var t;return(t=this.elements.upper)===null||t===void 0?void 0:t.ctx}get wrapperEl(){return this.elements.container}initElements(t){this.elements=new Wu(t,{allowTouchScrolling:this.allowTouchScrolling,containerClass:this.containerClass}),this._createCacheCanvas()}_onObjectAdded(t){this._objectsToRender=void 0,super._onObjectAdded(t)}_onObjectRemoved(t){this._objectsToRender=void 0,t===this._activeObject&&(this.fire("before:selection:cleared",{deselected:[t]}),this._discardActiveObject(),this.fire("selection:cleared",{deselected:[t]}),t.fire("deselected",{target:t})),t===this._hoveredTarget&&(this._hoveredTarget=void 0,this._hoveredTargets=[]),super._onObjectRemoved(t)}_onStackOrderChanged(){this._objectsToRender=void 0,super._onStackOrderChanged()}_chooseObjectsToRender(){const t=this._activeObject;return!this.preserveObjectStacking&&t?this._objects.filter((e=>!e.group&&e!==t)).concat(t):this._objects}renderAll(){this.cancelRequestedRender(),this.destroyed||(!this.contextTopDirty||this._groupSelector||this.isDrawingMode||(this.clearContext(this.contextTop),this.contextTopDirty=!1),this.hasLostContext&&(this.renderTopLayer(this.contextTop),this.hasLostContext=!1),!this._objectsToRender&&(this._objectsToRender=this._chooseObjectsToRender()),this.renderCanvas(this.getContext(),this._objectsToRender))}renderTopLayer(t){t.save(),this.isDrawingMode&&this._isCurrentlyDrawing&&(this.freeDrawingBrush&&this.freeDrawingBrush._render(),this.contextTopDirty=!0),this.selection&&this._groupSelector&&(this._drawSelection(t),this.contextTopDirty=!0),t.restore()}renderTop(){const t=this.contextTop;this.clearContext(t),this.renderTopLayer(t),this.fire("after:render",{ctx:t})}setTargetFindTolerance(t){t=Math.round(t),this.targetFindTolerance=t;const e=this.getRetinaScaling(),s=Math.ceil((2*t+1)*e);this.pixelFindCanvasEl.width=this.pixelFindCanvasEl.height=s,this.pixelFindContext.scale(e,e)}isTargetTransparent(t,e,s){const i=this.targetFindTolerance,n=this.pixelFindContext;this.clearContext(n),n.save(),n.translate(-e+i,-s+i),n.transform(...this.viewportTransform);const r=t.selectionBackgroundColor;t.selectionBackgroundColor="",t.render(n),t.selectionBackgroundColor=r,n.restore();const o=Math.round(i*this.getRetinaScaling());return Va(n,o,o,o)}_isSelectionKeyPressed(t){const e=this.selectionKey;return!!e&&(Array.isArray(e)?!!e.find((s=>!!s&&t[s]===!0)):t[e])}_shouldClearSelection(t,e){const s=this.getActiveObjects(),i=this._activeObject;return!!(!e||e&&i&&s.length>1&&s.indexOf(e)===-1&&i!==e&&!this._isSelectionKeyPressed(t)||e&&!e.evented||e&&!e.selectable&&i&&i!==e)}_shouldCenterTransform(t,e,s){if(!t)return;let i;return e===ki||e===Bt||e===Qt||e===qs?i=this.centeredScaling||t.centeredScaling:e===sr&&(i=this.centeredRotation||t.centeredRotation),i?!s:s}_getOriginFromCorner(t,e){const s={x:t.originX,y:t.originY};return e&&(["ml","tl","bl"].includes(e)?s.x=bt:["mr","tr","br"].includes(e)&&(s.x=it),["tl","mt","tr"].includes(e)?s.y=tr:["bl","mb","br"].includes(e)&&(s.y=Yt)),s}_setupCurrentTransform(t,e,s){var i;const n=e.group?as(this.getScenePoint(t),void 0,e.group.calcTransformMatrix()):this.getScenePoint(t),{key:r="",control:o}=e.getActiveControl()||{},h=s&&o?(i=o.getActionHandler(t,e,o))===null||i===void 0?void 0:i.bind(o):_c,l=((f,g,p,b)=>{if(!g||!f)return"drag";const m=b.controls[g];return m.getActionName(p,m,b)})(s,r,t,e),c=t[this.centeredKey],u=this._shouldCenterTransform(e,l,c)?{x:$,y:$}:this._getOriginFromCorner(e,r),d={target:e,action:l,actionHandler:h,actionPerformed:!1,corner:r,scaleX:e.scaleX,scaleY:e.scaleY,skewX:e.skewX,skewY:e.skewY,offsetX:n.x-e.left,offsetY:n.y-e.top,originX:u.x,originY:u.y,ex:n.x,ey:n.y,lastX:n.x,lastY:n.y,theta:pt(e.angle),width:e.width,height:e.height,shiftKey:t.shiftKey,altKey:c,original:w(w({},ur(e)),{},{originX:u.x,originY:u.y})};this._currentTransform=d,this.fire("before:transform",{e:t,transform:d})}setCursor(t){this.upperCanvasEl.style.cursor=t}_drawSelection(t){const{x:e,y:s,deltaX:i,deltaY:n}=this._groupSelector,r=new C(e,s).transform(this.viewportTransform),o=new C(e+i,s+n).transform(this.viewportTransform),h=this.selectionLineWidth/2;let l=Math.min(r.x,o.x),c=Math.min(r.y,o.y),u=Math.max(r.x,o.x),d=Math.max(r.y,o.y);this.selectionColor&&(t.fillStyle=this.selectionColor,t.fillRect(l,c,u-l,d-c)),this.selectionLineWidth&&this.selectionBorderColor&&(t.lineWidth=this.selectionLineWidth,t.strokeStyle=this.selectionBorderColor,l+=h,c+=h,u-=h,d-=h,Ot.prototype._setLineDash.call(this,t,this.selectionDashArray),t.strokeRect(l,c,u-l,d-c))}findTarget(t){if(this.skipTargetFind)return;const e=this.getViewportPoint(t),s=this._activeObject,i=this.getActiveObjects();if(this.targets=[],s&&i.length>=1){if(s.findControl(e,Li(t))||i.length>1&&this.searchPossibleTargets([s],e))return s;if(s===this.searchPossibleTargets([s],e)){if(this.preserveObjectStacking){const n=this.targets;this.targets=[];const r=this.searchPossibleTargets(this._objects,e);return t[this.altSelectionKey]&&r&&r!==s?(this.targets=n,s):r}return s}}return this.searchPossibleTargets(this._objects,e)}_pointIsInObjectSelectionArea(t,e){let s=t.getCoords();const i=this.getZoom(),n=t.padding/i;if(n){const[r,o,h,l]=s,c=Math.atan2(o.y-r.y,o.x-r.x),u=le(c)*n,d=ce(c)*n,f=u+d,g=u-d;s=[new C(r.x-g,r.y-f),new C(o.x+f,o.y-g),new C(h.x+g,h.y+f),new C(l.x-f,l.y+g)]}return gt.isPointInPolygon(e,s)}_checkTarget(t,e){return!!(t&&t.visible&&t.evented&&this._pointIsInObjectSelectionArea(t,as(e,void 0,this.viewportTransform))&&(!this.perPixelTargetFind&&!t.perPixelTargetFind||t.isEditing||!this.isTargetTransparent(t,e.x,e.y)))}_searchPossibleTargets(t,e){let s=t.length;for(;s--;){const i=t[s];if(this._checkTarget(i,e)){if(Oi(i)&&i.subTargetCheck){const n=this._searchPossibleTargets(i._objects,e);n&&this.targets.push(n)}return i}}}searchPossibleTargets(t,e){const s=this._searchPossibleTargets(t,e);if(s&&Oi(s)&&s.interactive&&this.targets[0]){const i=this.targets;for(let n=i.length-1;n>0;n--){const r=i[n];if(!Oi(r)||!r.interactive)return r}return i[0]}return s}getViewportPoint(t){return this._pointer?this._pointer:this.getPointer(t,!0)}getScenePoint(t){return this._absolutePointer?this._absolutePointer:this.getPointer(t)}getPointer(t){let e=arguments.length>1&&arguments[1]!==void 0&&arguments[1];const s=this.upperCanvasEl,i=s.getBoundingClientRect();let n=sa(t),r=i.width||0,o=i.height||0;r&&o||(Yt in i&&tr in i&&(o=Math.abs(i.top-i.bottom)),bt in i&&it in i&&(r=Math.abs(i.right-i.left))),this.calcOffset(),n.x=n.x-this._offset.left,n.y=n.y-this._offset.top,e||(n=as(n,void 0,this.viewportTransform));const h=this.getRetinaScaling();h!==1&&(n.x/=h,n.y/=h);const l=r===0||o===0?new C(1,1):new C(s.width/r,s.height/o);return n.multiply(l)}_setDimensionsImpl(t,e){this._resetTransformEventData(),super._setDimensionsImpl(t,e),this._isCurrentlyDrawing&&this.freeDrawingBrush&&this.freeDrawingBrush._setBrushStyles(this.contextTop)}_createCacheCanvas(){this.pixelFindCanvasEl=Se(),this.pixelFindContext=this.pixelFindCanvasEl.getContext("2d",{willReadFrequently:!0}),this.setTargetFindTolerance(this.targetFindTolerance)}getTopContext(){return this.elements.upper.ctx}getSelectionContext(){return this.elements.upper.ctx}getSelectionElement(){return this.elements.upper.el}getActiveObject(){return this._activeObject}getActiveObjects(){const t=this._activeObject;return os(t)?t.getObjects():t?[t]:[]}_fireSelectionEvents(t,e){let s=!1,i=!1;const n=this.getActiveObjects(),r=[],o=[];t.forEach((h=>{n.includes(h)||(s=!0,h.fire("deselected",{e,target:h}),o.push(h))})),n.forEach((h=>{t.includes(h)||(s=!0,h.fire("selected",{e,target:h}),r.push(h))})),t.length>0&&n.length>0?(i=!0,s&&this.fire("selection:updated",{e,selected:r,deselected:o})):n.length>0?(i=!0,this.fire("selection:created",{e,selected:r})):t.length>0&&(i=!0,this.fire("selection:cleared",{e,deselected:o})),i&&(this._objectsToRender=void 0)}setActiveObject(t,e){const s=this.getActiveObjects(),i=this._setActiveObject(t,e);return this._fireSelectionEvents(s,e),i}_setActiveObject(t,e){const s=this._activeObject;return s!==t&&!(!this._discardActiveObject(e,t)&&this._activeObject)&&!t.onSelect({e})&&(this._activeObject=t,os(t)&&s!==t&&t.set("canvas",this),t.setCoords(),!0)}_discardActiveObject(t,e){const s=this._activeObject;return!!s&&!s.onDeselect({e:t,object:e})&&(this._currentTransform&&this._currentTransform.target===s&&this.endCurrentTransform(t),os(s)&&s===this._hoveredTarget&&(this._hoveredTarget=void 0),this._activeObject=void 0,!0)}discardActiveObject(t){const e=this.getActiveObjects(),s=this.getActiveObject();e.length&&this.fire("before:selection:cleared",{e:t,deselected:[s]});const i=this._discardActiveObject(t);return this._fireSelectionEvents(e,t),i}endCurrentTransform(t){const e=this._currentTransform;this._finalizeCurrentTransform(t),e&&e.target&&(e.target.isMoving=!1),this._currentTransform=null}_finalizeCurrentTransform(t){const e=this._currentTransform,s=e.target,i={e:t,target:s,transform:e,action:e.action};s._scaling&&(s._scaling=!1),s.setCoords(),e.actionPerformed&&(this.fire("object:modified",i),s.fire(Mi,i))}setViewportTransform(t){super.setViewportTransform(t);const e=this._activeObject;e&&e.setCoords()}destroy(){const t=this._activeObject;os(t)&&(t.removeAll(),t.dispose()),delete this._activeObject,super.destroy(),this.pixelFindContext=null,this.pixelFindCanvasEl=void 0}clear(){this.discardActiveObject(),this._activeObject=void 0,this.clearContext(this.contextTop),super.clear()}drawControls(t){const e=this._activeObject;e&&e._renderControls(t)}_toObject(t,e,s){const i=this._realizeGroupTransformOnObject(t),n=super._toObject(t,e,s);return t.set(i),n}_realizeGroupTransformOnObject(t){const{group:e}=t;if(e&&os(e)&&this._activeObject===e){const s=rs(t,["angle","flipX","flipY",it,Bt,Qt,Ss,Cs,Yt]);return na(t,e.calcOwnMatrix()),s}return{}}_setSVGObject(t,e,s){const i=this._realizeGroupTransformOnObject(e);super._setSVGObject(t,e,s),e.set(i)}}x(nn,"ownDefaults",{uniformScaling:!0,uniScaleKey:"shiftKey",centeredScaling:!1,centeredRotation:!1,centeredKey:"altKey",altActionKey:"shiftKey",selection:!0,selectionKey:"shiftKey",selectionColor:"rgba(100, 100, 255, 0.3)",selectionDashArray:[],selectionBorderColor:"rgba(255, 255, 255, 0.3)",selectionLineWidth:1,selectionFullyContained:!1,hoverCursor:"move",moveCursor:"move",defaultCursor:"default",freeDrawingCursor:"crosshair",notAllowedCursor:"not-allowed",perPixelTargetFind:!1,targetFindTolerance:0,skipTargetFind:!1,stopContextMenu:!1,fireRightClick:!1,fireMiddleClick:!1,enablePointerEvents:!1,containerClass:"canvas-container",preserveObjectStacking:!1});class Xu{constructor(t){x(this,"targets",[]),x(this,"__disposer",void 0);const e=()=>{const{hiddenTextarea:i}=t.getActiveObject()||{};i&&i.focus()},s=t.upperCanvasEl;s.addEventListener("click",e),this.__disposer=()=>s.removeEventListener("click",e)}exitTextEditing(){this.target=void 0,this.targets.forEach((t=>{t.isEditing&&t.exitEditing()}))}add(t){this.targets.push(t)}remove(t){this.unregister(t),ss(this.targets,t)}register(t){this.target=t}unregister(t){t===this.target&&(this.target=void 0)}onMouseMove(t){var e;!((e=this.target)===null||e===void 0)&&e.isEditing&&this.target.updateSelectionOnMouseMove(t)}clear(){this.targets=[],this.target=void 0}dispose(){this.clear(),this.__disposer(),delete this.__disposer}}const Uu=["target","oldTarget","fireCanvas","e"],se={passive:!1},Fs=(a,t)=>{const e=a.getViewportPoint(t),s=a.getScenePoint(t);return{viewportPoint:e,scenePoint:s,pointer:e,absolutePointer:s}},$e=function(a){for(var t=arguments.length,e=new Array(t>1?t-1:0),s=1;s<t;s++)e[s-1]=arguments[s];return a.addEventListener(...e)},oe=function(a){for(var t=arguments.length,e=new Array(t>1?t-1:0),s=1;s<t;s++)e[s-1]=arguments[s];return a.removeEventListener(...e)},Yu={mouse:{in:"over",out:"out",targetIn:"mouseover",targetOut:"mouseout",canvasIn:"mouse:over",canvasOut:"mouse:out"},drag:{in:"enter",out:"leave",targetIn:"dragenter",targetOut:"dragleave",canvasIn:"drag:enter",canvasOut:"drag:leave"}};class jr extends nn{constructor(t){super(t,arguments.length>1&&arguments[1]!==void 0?arguments[1]:{}),x(this,"_isClick",void 0),x(this,"textEditingManager",new Xu(this)),["_onMouseDown","_onTouchStart","_onMouseMove","_onMouseUp","_onTouchEnd","_onResize","_onMouseWheel","_onMouseOut","_onMouseEnter","_onContextMenu","_onClick","_onDragStart","_onDragEnd","_onDragProgress","_onDragOver","_onDragEnter","_onDragLeave","_onDrop"].forEach((e=>{this[e]=this[e].bind(this)})),this.addOrRemove($e,"add")}_getEventPrefix(){return this.enablePointerEvents?"pointer":"mouse"}addOrRemove(t,e){const s=this.upperCanvasEl,i=this._getEventPrefix();t(Zo(s),"resize",this._onResize),t(s,i+"down",this._onMouseDown),t(s,"".concat(i,"move"),this._onMouseMove,se),t(s,"".concat(i,"out"),this._onMouseOut),t(s,"".concat(i,"enter"),this._onMouseEnter),t(s,"wheel",this._onMouseWheel,{passive:!1}),t(s,"contextmenu",this._onContextMenu),t(s,"click",this._onClick),t(s,"dblclick",this._onClick),t(s,"dragstart",this._onDragStart),t(s,"dragend",this._onDragEnd),t(s,"dragover",this._onDragOver),t(s,"dragenter",this._onDragEnter),t(s,"dragleave",this._onDragLeave),t(s,"drop",this._onDrop),this.enablePointerEvents||t(s,"touchstart",this._onTouchStart,se)}removeListeners(){this.addOrRemove(oe,"remove");const t=this._getEventPrefix(),e=ue(this.upperCanvasEl);oe(e,"".concat(t,"up"),this._onMouseUp),oe(e,"touchend",this._onTouchEnd,se),oe(e,"".concat(t,"move"),this._onMouseMove,se),oe(e,"touchmove",this._onMouseMove,se),clearTimeout(this._willAddMouseDown)}_onMouseWheel(t){this.__onMouseWheel(t)}_onMouseOut(t){const e=this._hoveredTarget,s=w({e:t},Fs(this,t));this.fire("mouse:out",w(w({},s),{},{target:e})),this._hoveredTarget=void 0,e&&e.fire("mouseout",w({},s)),this._hoveredTargets.forEach((i=>{this.fire("mouse:out",w(w({},s),{},{target:i})),i&&i.fire("mouseout",w({},s))})),this._hoveredTargets=[]}_onMouseEnter(t){this._currentTransform||this.findTarget(t)||(this.fire("mouse:over",w({e:t},Fs(this,t))),this._hoveredTarget=void 0,this._hoveredTargets=[])}_onDragStart(t){this._isClick=!1;const e=this.getActiveObject();if(e&&e.onDragStart(t)){this._dragSource=e;const s={e:t,target:e};return this.fire("dragstart",s),e.fire("dragstart",s),void $e(this.upperCanvasEl,"drag",this._onDragProgress)}ia(t)}_renderDragEffects(t,e,s){let i=!1;const n=this._dropTarget;n&&n!==e&&n!==s&&(n.clearContextTop(),i=!0),e?.clearContextTop(),s!==e&&s?.clearContextTop();const r=this.contextTop;r.save(),r.transform(...this.viewportTransform),e&&(r.save(),e.transform(r),e.renderDragSourceEffect(t),r.restore(),i=!0),s&&(r.save(),s.transform(r),s.renderDropTargetEffect(t),r.restore(),i=!0),r.restore(),i&&(this.contextTopDirty=!0)}_onDragEnd(t){const e=!!t.dataTransfer&&t.dataTransfer.dropEffect!==jt,s=e?this._activeObject:void 0,i={e:t,target:this._dragSource,subTargets:this.targets,dragSource:this._dragSource,didDrop:e,dropTarget:s};oe(this.upperCanvasEl,"drag",this._onDragProgress),this.fire("dragend",i),this._dragSource&&this._dragSource.fire("dragend",i),delete this._dragSource,this._onMouseUp(t)}_onDragProgress(t){const e={e:t,target:this._dragSource,dragSource:this._dragSource,dropTarget:this._draggedoverTarget};this.fire("drag",e),this._dragSource&&this._dragSource.fire("drag",e)}findDragTargets(t){return this.targets=[],{target:this._searchPossibleTargets(this._objects,this.getViewportPoint(t)),targets:[...this.targets]}}_onDragOver(t){const e="dragover",{target:s,targets:i}=this.findDragTargets(t),n=this._dragSource,r={e:t,target:s,subTargets:i,dragSource:n,canDrop:!1,dropTarget:void 0};let o;this.fire(e,r),this._fireEnterLeaveEvents(s,r),s&&(s.canDrop(t)&&(o=s),s.fire(e,r));for(let h=0;h<i.length;h++){const l=i[h];l.canDrop(t)&&(o=l),l.fire(e,r)}this._renderDragEffects(t,n,o),this._dropTarget=o}_onDragEnter(t){const{target:e,targets:s}=this.findDragTargets(t),i={e:t,target:e,subTargets:s,dragSource:this._dragSource};this.fire("dragenter",i),this._fireEnterLeaveEvents(e,i)}_onDragLeave(t){const e={e:t,target:this._draggedoverTarget,subTargets:this.targets,dragSource:this._dragSource};this.fire("dragleave",e),this._fireEnterLeaveEvents(void 0,e),this._renderDragEffects(t,this._dragSource),this._dropTarget=void 0,this.targets=[],this._hoveredTargets=[]}_onDrop(t){const{target:e,targets:s}=this.findDragTargets(t),i=this._basicEventHandler("drop:before",w({e:t,target:e,subTargets:s,dragSource:this._dragSource},Fs(this,t)));i.didDrop=!1,i.dropTarget=void 0,this._basicEventHandler("drop",i),this.fire("drop:after",i)}_onContextMenu(t){const e=this.findTarget(t),s=this.targets||[],i=this._basicEventHandler("contextmenu:before",{e:t,target:e,subTargets:s});return this.stopContextMenu&&ia(t),this._basicEventHandler("contextmenu",i),!1}_onClick(t){const e=t.detail;e>3||e<2||(this._cacheTransformEventData(t),e==2&&t.type==="dblclick"&&this._handleEvent(t,"dblclick"),e==3&&this._handleEvent(t,"tripleclick"),this._resetTransformEventData())}getPointerId(t){const e=t.changedTouches;return e?e[0]&&e[0].identifier:this.enablePointerEvents?t.pointerId:-1}_isMainEvent(t){return t.isPrimary===!0||t.isPrimary!==!1&&(t.type==="touchend"&&t.touches.length===0||!t.changedTouches||t.changedTouches[0].identifier===this.mainTouchId)}_onTouchStart(t){let e=!this.allowTouchScrolling;const s=this._activeObject;this.mainTouchId===void 0&&(this.mainTouchId=this.getPointerId(t)),this.__onMouseDown(t),(this.isDrawingMode||s&&this._target===s)&&(e=!0),e&&t.preventDefault(),this._resetTransformEventData();const i=this.upperCanvasEl,n=this._getEventPrefix(),r=ue(i);$e(r,"touchend",this._onTouchEnd,se),e&&$e(r,"touchmove",this._onMouseMove,se),oe(i,"".concat(n,"down"),this._onMouseDown)}_onMouseDown(t){this.__onMouseDown(t),this._resetTransformEventData();const e=this.upperCanvasEl,s=this._getEventPrefix();oe(e,"".concat(s,"move"),this._onMouseMove,se);const i=ue(e);$e(i,"".concat(s,"up"),this._onMouseUp),$e(i,"".concat(s,"move"),this._onMouseMove,se)}_onTouchEnd(t){if(t.touches.length>0)return;this.__onMouseUp(t),this._resetTransformEventData(),delete this.mainTouchId;const e=this._getEventPrefix(),s=ue(this.upperCanvasEl);oe(s,"touchend",this._onTouchEnd,se),oe(s,"touchmove",this._onMouseMove,se),this._willAddMouseDown&&clearTimeout(this._willAddMouseDown),this._willAddMouseDown=setTimeout((()=>{$e(this.upperCanvasEl,"".concat(e,"down"),this._onMouseDown),this._willAddMouseDown=0}),400)}_onMouseUp(t){this.__onMouseUp(t),this._resetTransformEventData();const e=this.upperCanvasEl,s=this._getEventPrefix();if(this._isMainEvent(t)){const i=ue(this.upperCanvasEl);oe(i,"".concat(s,"up"),this._onMouseUp),oe(i,"".concat(s,"move"),this._onMouseMove,se),$e(e,"".concat(s,"move"),this._onMouseMove,se)}}_onMouseMove(t){const e=this.getActiveObject();!this.allowTouchScrolling&&(!e||!e.shouldStartDragging(t))&&t.preventDefault&&t.preventDefault(),this.__onMouseMove(t)}_onResize(){this.calcOffset(),this._resetTransformEventData()}_shouldRender(t){const e=this.getActiveObject();return!!e!=!!t||e&&t&&e!==t}__onMouseUp(t){var e;this._cacheTransformEventData(t),this._handleEvent(t,"up:before");const s=this._currentTransform,i=this._isClick,n=this._target,{button:r}=t;if(r)return(this.fireMiddleClick&&r===1||this.fireRightClick&&r===2)&&this._handleEvent(t,"up"),void this._resetTransformEventData();if(this.isDrawingMode&&this._isCurrentlyDrawing)return void this._onMouseUpInDrawingMode(t);if(!this._isMainEvent(t))return;let o,h,l=!1;if(s&&(this._finalizeCurrentTransform(t),l=s.actionPerformed),!i){const c=n===this._activeObject;this.handleSelection(t),l||(l=this._shouldRender(n)||!c&&n===this._activeObject)}if(n){const c=n.findControl(this.getViewportPoint(t),Li(t)),{key:u,control:d}=c||{};if(h=u,n.selectable&&n!==this._activeObject&&n.activeOn==="up")this.setActiveObject(n,t),l=!0;else if(d){const f=d.getMouseUpHandler(t,n,d);f&&(o=this.getScenePoint(t),f.call(d,t,s,o.x,o.y))}n.isMoving=!1}if(s&&(s.target!==n||s.corner!==h)){const c=s.target&&s.target.controls[s.corner],u=c&&c.getMouseUpHandler(t,s.target,c);o=o||this.getScenePoint(t),u&&u.call(c,t,s,o.x,o.y)}this._setCursorFromEvent(t,n),this._handleEvent(t,"up"),this._groupSelector=null,this._currentTransform=null,n&&(n.__corner=void 0),l?this.requestRenderAll():i||(e=this._activeObject)!==null&&e!==void 0&&e.isEditing||this.renderTop()}_basicEventHandler(t,e){const{target:s,subTargets:i=[]}=e;this.fire(t,e),s&&s.fire(t,e);for(let n=0;n<i.length;n++)i[n]!==s&&i[n].fire(t,e);return e}_handleEvent(t,e,s){const i=this._target,n=this.targets||[],r=w(w(w({e:t,target:i,subTargets:n},Fs(this,t)),{},{transform:this._currentTransform},e==="up:before"||e==="up"?{isClick:this._isClick,currentTarget:this.findTarget(t),currentSubTargets:this.targets}:{}),e==="down:before"||e==="down"?s:{});this.fire("mouse:".concat(e),r),i&&i.fire("mouse".concat(e),r);for(let o=0;o<n.length;o++)n[o]!==i&&n[o].fire("mouse".concat(e),r)}_onMouseDownInDrawingMode(t){this._isCurrentlyDrawing=!0,this.getActiveObject()&&(this.discardActiveObject(t),this.requestRenderAll());const e=this.getScenePoint(t);this.freeDrawingBrush&&this.freeDrawingBrush.onMouseDown(e,{e:t,pointer:e}),this._handleEvent(t,"down",{alreadySelected:!1})}_onMouseMoveInDrawingMode(t){if(this._isCurrentlyDrawing){const e=this.getScenePoint(t);this.freeDrawingBrush&&this.freeDrawingBrush.onMouseMove(e,{e:t,pointer:e})}this.setCursor(this.freeDrawingCursor),this._handleEvent(t,"move")}_onMouseUpInDrawingMode(t){const e=this.getScenePoint(t);this.freeDrawingBrush?this._isCurrentlyDrawing=!!this.freeDrawingBrush.onMouseUp({e:t,pointer:e}):this._isCurrentlyDrawing=!1,this._handleEvent(t,"up")}__onMouseDown(t){this._isClick=!0,this._cacheTransformEventData(t),this._handleEvent(t,"down:before");let e=this._target,s=!!e&&e===this._activeObject;const{button:i}=t;if(i)return(this.fireMiddleClick&&i===1||this.fireRightClick&&i===2)&&this._handleEvent(t,"down",{alreadySelected:s}),void this._resetTransformEventData();if(this.isDrawingMode)return void this._onMouseDownInDrawingMode(t);if(!this._isMainEvent(t)||this._currentTransform)return;let n=this._shouldRender(e),r=!1;if(this.handleMultiSelection(t,e)?(e=this._activeObject,r=!0,n=!0):this._shouldClearSelection(t,e)&&this.discardActiveObject(t),this.selection&&(!e||!e.selectable&&!e.isEditing&&e!==this._activeObject)){const o=this.getScenePoint(t);this._groupSelector={x:o.x,y:o.y,deltaY:0,deltaX:0}}if(s=!!e&&e===this._activeObject,e){e.selectable&&e.activeOn==="down"&&this.setActiveObject(e,t);const o=e.findControl(this.getViewportPoint(t),Li(t));if(e===this._activeObject&&(o||!r)){this._setupCurrentTransform(t,e,s);const h=o?o.control:void 0,l=this.getScenePoint(t),c=h&&h.getMouseDownHandler(t,e,h);c&&c.call(h,t,this._currentTransform,l.x,l.y)}}n&&(this._objectsToRender=void 0),this._handleEvent(t,"down",{alreadySelected:s}),n&&this.requestRenderAll()}_resetTransformEventData(){this._target=this._pointer=this._absolutePointer=void 0}_cacheTransformEventData(t){this._resetTransformEventData(),this._pointer=this.getViewportPoint(t),this._absolutePointer=as(this._pointer,void 0,this.viewportTransform),this._target=this._currentTransform?this._currentTransform.target:this.findTarget(t)}__onMouseMove(t){if(this._isClick=!1,this._cacheTransformEventData(t),this._handleEvent(t,"move:before"),this.isDrawingMode)return void this._onMouseMoveInDrawingMode(t);if(!this._isMainEvent(t))return;const e=this._groupSelector;if(e){const s=this.getScenePoint(t);e.deltaX=s.x-e.x,e.deltaY=s.y-e.y,this.renderTop()}else if(this._currentTransform)this._transformObject(t);else{const s=this.findTarget(t);this._setCursorFromEvent(t,s),this._fireOverOutEvents(t,s)}this.textEditingManager.onMouseMove(t),this._handleEvent(t,"move"),this._resetTransformEventData()}_fireOverOutEvents(t,e){const s=this._hoveredTarget,i=this._hoveredTargets,n=this.targets,r=Math.max(i.length,n.length);this.fireSyntheticInOutEvents("mouse",{e:t,target:e,oldTarget:s,fireCanvas:!0});for(let o=0;o<r;o++)n[o]===e||i[o]&&i[o]===s||this.fireSyntheticInOutEvents("mouse",{e:t,target:n[o],oldTarget:i[o]});this._hoveredTarget=e,this._hoveredTargets=this.targets.concat()}_fireEnterLeaveEvents(t,e){const s=this._draggedoverTarget,i=this._hoveredTargets,n=this.targets,r=Math.max(i.length,n.length);this.fireSyntheticInOutEvents("drag",w(w({},e),{},{target:t,oldTarget:s,fireCanvas:!0}));for(let o=0;o<r;o++)this.fireSyntheticInOutEvents("drag",w(w({},e),{},{target:n[o],oldTarget:i[o]}));this._draggedoverTarget=t}fireSyntheticInOutEvents(t,e){let{target:s,oldTarget:i,fireCanvas:n,e:r}=e,o=lt(e,Uu);const{targetIn:h,targetOut:l,canvasIn:c,canvasOut:u}=Yu[t],d=i!==s;if(i&&d){const f=w(w({},o),{},{e:r,target:i,nextTarget:s},Fs(this,r));n&&this.fire(u,f),i.fire(l,f)}if(s&&d){const f=w(w({},o),{},{e:r,target:s,previousTarget:i},Fs(this,r));n&&this.fire(c,f),s.fire(h,f)}}__onMouseWheel(t){this._cacheTransformEventData(t),this._handleEvent(t,"wheel"),this._resetTransformEventData()}_transformObject(t){const e=this.getScenePoint(t),s=this._currentTransform,i=s.target,n=i.group?as(e,void 0,i.group.calcTransformMatrix()):e;s.shiftKey=t.shiftKey,s.altKey=!!this.centeredKey&&t[this.centeredKey],this._performTransformAction(t,s,n),s.actionPerformed&&this.requestRenderAll()}_performTransformAction(t,e,s){const{action:i,actionHandler:n,target:r}=e,o=!!n&&n(t,e,s.x,s.y);o&&r.setCoords(),i==="drag"&&o&&(e.target.isMoving=!0,this.setCursor(e.target.moveCursor||this.moveCursor)),e.actionPerformed=e.actionPerformed||o}_setCursorFromEvent(t,e){if(!e)return void this.setCursor(this.defaultCursor);let s=e.hoverCursor||this.hoverCursor;const i=os(this._activeObject)?this._activeObject:null,n=(!i||e.group!==i)&&e.findControl(this.getViewportPoint(t));if(n){const r=n.control;this.setCursor(r.cursorStyleHandler(t,r,e))}else e.subTargetCheck&&this.targets.concat().reverse().map((r=>{s=r.hoverCursor||s})),this.setCursor(s)}handleMultiSelection(t,e){const s=this._activeObject,i=os(s);if(s&&this._isSelectionKeyPressed(t)&&this.selection&&e&&e.selectable&&(s!==e||i)&&(i||!e.isDescendantOf(s)&&!s.isDescendantOf(e))&&!e.onSelect({e:t})&&!s.getActiveControl()){if(i){const n=s.getObjects();if(e===s){const r=this.getViewportPoint(t);if(!(e=this.searchPossibleTargets(n,r)||this.searchPossibleTargets(this._objects,r))||!e.selectable)return!1}e.group===s?(s.remove(e),this._hoveredTarget=e,this._hoveredTargets=[...this.targets],s.size()===1&&this._setActiveObject(s.item(0),t)):(s.multiSelectAdd(e),this._hoveredTarget=s,this._hoveredTargets=[...this.targets]),this._fireSelectionEvents(n,t)}else{s.isEditing&&s.exitEditing();const n=new(L.getClass("ActiveSelection"))([],{canvas:this});n.multiSelectAdd(s,e),this._hoveredTarget=n,this._setActiveObject(n,t),this._fireSelectionEvents([s],t)}return!0}return!1}handleSelection(t){if(!this.selection||!this._groupSelector)return!1;const{x:e,y:s,deltaX:i,deltaY:n}=this._groupSelector,r=new C(e,s),o=r.add(new C(i,n)),h=r.min(o),l=r.max(o).subtract(h),c=this.collectObjects({left:h.x,top:h.y,width:l.x,height:l.y},{includeIntersecting:!this.selectionFullyContained}),u=r.eq(o)?c[0]?[c[0]]:[]:c.length>1?c.filter((d=>!d.onSelect({e:t}))).reverse():c;if(u.length===1)this.setActiveObject(u[0],t);else if(u.length>1){const d=L.getClass("ActiveSelection");this.setActiveObject(new d(u,{canvas:this}),t)}return this._groupSelector=null,!0}toCanvasElement(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:1,e=arguments.length>1?arguments[1]:void 0;const{upper:s}=this.elements;s.ctx=void 0;const i=super.toCanvasElement(t,e);return s.ctx=s.el.getContext("2d"),i}clear(){this.textEditingManager.clear(),super.clear()}destroy(){this.removeListeners(),this.textEditingManager.dispose(),super.destroy()}}const wh={x1:0,y1:0,x2:0,y2:0},$u=w(w({},wh),{},{r1:0,r2:0}),Is=(a,t)=>isNaN(a)&&typeof t=="number"?t:a;function xh(a){return a&&/%$/.test(a)&&Number.isFinite(parseFloat(a))}function Sh(a,t){const e=typeof a=="number"?a:typeof a=="string"?parseFloat(a)/(xh(a)?100:1):NaN;return ls(0,Is(e,t),1)}const qu=/\s*;\s*/,Ku=/\s*:\s*/;function Ju(a,t){let e,s;const i=a.getAttribute("style");if(i){const r=i.split(qu);r[r.length-1]===""&&r.pop();for(let o=r.length;o--;){const[h,l]=r[o].split(Ku).map((c=>c.trim()));h==="stop-color"?e=l:h==="stop-opacity"&&(s=l)}}const n=new nt(e||a.getAttribute("stop-color")||"rgb(0,0,0)");return{offset:Sh(a.getAttribute("offset"),0),color:n.toRgb(),opacity:Is(parseFloat(s||a.getAttribute("stop-opacity")||""),1)*n.getAlpha()*t}}function Zu(a,t){const e=[],s=a.getElementsByTagName("stop"),i=Sh(t,1);for(let n=s.length;n--;)e.push(Ju(s[n],i));return e}function Ch(a){return a.nodeName==="linearGradient"||a.nodeName==="LINEARGRADIENT"?"linear":"radial"}function Ah(a){return a.getAttribute("gradientUnits")==="userSpaceOnUse"?"pixels":"percentage"}function pe(a,t){return a.getAttribute(t)}function Qu(a,t){return(function(e,s){let i,{width:n,height:r,gradientUnits:o}=s;return Object.entries(e).reduce(((h,l)=>{let[c,u]=l;if(u==="Infinity")i=1;else if(u==="-Infinity")i=0;else{const d=typeof u=="string";i=d?parseFloat(u):u,d&&xh(u)&&(i*=.01,o==="pixels"&&(c!=="x1"&&c!=="x2"&&c!=="r2"||(i*=n),c!=="y1"&&c!=="y2"||(i*=r)))}return h[c]=i,h}),{})})(Ch(a)==="linear"?(function(e){return{x1:pe(e,"x1")||0,y1:pe(e,"y1")||0,x2:pe(e,"x2")||"100%",y2:pe(e,"y2")||0}})(a):(function(e){return{x1:pe(e,"fx")||pe(e,"cx")||"50%",y1:pe(e,"fy")||pe(e,"cy")||"50%",r1:0,x2:pe(e,"cx")||"50%",y2:pe(e,"cy")||"50%",r2:pe(e,"r")||"50%"}})(a),w(w({},t),{},{gradientUnits:Ah(a)}))}class ci{constructor(t){const{type:e="linear",gradientUnits:s="pixels",coords:i={},colorStops:n=[],offsetX:r=0,offsetY:o=0,gradientTransform:h,id:l}=t||{};Object.assign(this,{type:e,gradientUnits:s,coords:w(w({},e==="radial"?$u:wh),i),colorStops:n,offsetX:r,offsetY:o,gradientTransform:h,id:l?"".concat(l,"_").concat(Ue()):Ue()})}addColorStop(t){for(const e in t){const s=new nt(t[e]);this.colorStops.push({offset:parseFloat(e),color:s.toRgb(),opacity:s.getAlpha()})}return this}toObject(t){return w(w({},rs(this,t)),{},{type:this.type,coords:w({},this.coords),colorStops:this.colorStops.map((e=>w({},e))),offsetX:this.offsetX,offsetY:this.offsetY,gradientUnits:this.gradientUnits,gradientTransform:this.gradientTransform?[...this.gradientTransform]:void 0})}toSVG(t){let{additionalTransform:e}=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};const s=[],i=this.gradientTransform?this.gradientTransform.concat():Nt.concat(),n=this.gradientUnits==="pixels"?"userSpaceOnUse":"objectBoundingBox",r=this.colorStops.map((u=>w({},u))).sort(((u,d)=>u.offset-d.offset));let o=-this.offsetX,h=-this.offsetY;var l;n==="objectBoundingBox"?(o/=t.width,h/=t.height):(o+=t.width/2,h+=t.height/2),(l=t)&&typeof l._renderPathCommands=="function"&&this.gradientUnits!=="percentage"&&(o-=t.pathOffset.x,h-=t.pathOffset.y),i[4]-=o,i[5]-=h;const c=['id="SVGID_'.concat(this.id,'"'),'gradientUnits="'.concat(n,'"'),'gradientTransform="'.concat(e?e+" ":"").concat(ks(i),'"'),""].join(" ");if(this.type==="linear"){const{x1:u,y1:d,x2:f,y2:g}=this.coords;s.push("<linearGradient ",c,' x1="',u,'" y1="',d,'" x2="',f,'" y2="',g,`">
|
|
47
47
|
`)}else if(this.type==="radial"){const{x1:u,y1:d,x2:f,y2:g,r1:p,r2:b}=this.coords,m=p>b;s.push("<radialGradient ",c,' cx="',m?u:f,'" cy="',m?d:g,'" r="',m?p:b,'" fx="',m?f:u,'" fy="',m?g:d,`">
|
|
48
48
|
`),m&&(r.reverse(),r.forEach((y=>{y.offset=1-y.offset})));const v=Math.min(p,b);if(v>0){const y=v/Math.max(p,b);r.forEach((_=>{_.offset+=y*(1-_.offset)}))}}return r.forEach((u=>{let{color:d,offset:f,opacity:g}=u;s.push("<stop ",'offset="',100*f+"%",'" style="stop-color:',d,g!==void 0?";stop-opacity: "+g:";",`"/>
|
|
49
49
|
`)})),s.push(this.type==="linear"?"</linearGradient>":"</radialGradient>",`
|
|
@@ -55,7 +55,7 @@ Resulting to default behavior: removing object from previous canvas and adding t
|
|
|
55
55
|
`)]}static async fromElement(t,e,s){const i=Ne(t,this.ATTRIBUTE_NAMES,s),{x1:n=0,y1:r=0,x2:o=0,y2:h=0}=i;return new this([n,r,o,h],lt(i,nd))}static fromObject(t){let{x1:e,y1:s,x2:i,y2:n}=t,r=lt(t,rd);return this._fromObject(w(w({},r),{},{points:[e,s,i,n]}),{extraParam:"points"})}}x(us,"type","Line"),x(us,"cacheProperties",[...Fe,...Hr]),x(us,"ATTRIBUTE_NAMES",Ye.concat(Hr)),L.setClass(us),L.setSVGClass(us);class ds extends Ot{static getDefaults(){return w(w({},super.getDefaults()),ds.ownDefaults)}constructor(t){super(),Object.assign(this,ds.ownDefaults),this.setOptions(t)}_render(t){const e=this.width/2,s=this.height/2;t.beginPath(),t.moveTo(-e,s),t.lineTo(0,-s),t.lineTo(e,s),t.closePath(),this._renderPaintInOrder(t)}_toSVG(){const t=this.width/2,e=this.height/2;return["<polygon ","COMMON_PARTS",'points="',"".concat(-t," ").concat(e,",0 ").concat(-e,",").concat(t," ").concat(e),'" />']}}x(ds,"type","Triangle"),x(ds,"ownDefaults",{width:100,height:100}),L.setClass(ds),L.setSVGClass(ds);const Eh=["rx","ry"];class He extends Ot{static getDefaults(){return w(w({},super.getDefaults()),He.ownDefaults)}constructor(t){super(),Object.assign(this,He.ownDefaults),this.setOptions(t)}_set(t,e){switch(super._set(t,e),t){case"rx":this.rx=e,this.set("width",2*e);break;case"ry":this.ry=e,this.set("height",2*e)}return this}getRx(){return this.get("rx")*this.get(Bt)}getRy(){return this.get("ry")*this.get(Qt)}toObject(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:[];return super.toObject([...Eh,...t])}_toSVG(){return["<ellipse ","COMMON_PARTS",'cx="0" cy="0" rx="'.concat(this.rx,'" ry="').concat(this.ry,`" />
|
|
56
56
|
`)]}_render(t){t.beginPath(),t.save(),t.transform(1,0,0,this.ry/this.rx,0,0),t.arc(0,0,this.rx,0,Re,!1),t.restore(),this._renderPaintInOrder(t)}static async fromElement(t,e,s){const i=Ne(t,this.ATTRIBUTE_NAMES,s);return i.left=(i.left||0)-i.rx,i.top=(i.top||0)-i.ry,new this(i)}}function od(a){if(!a)return[];const t=a.replace(/,/g," ").trim().split(/\s+/),e=[];for(let s=0;s<t.length;s+=2)e.push({x:parseFloat(t[s]),y:parseFloat(t[s+1])});return e}x(He,"type","Ellipse"),x(He,"cacheProperties",[...Fe,...Eh]),x(He,"ownDefaults",{rx:0,ry:0}),x(He,"ATTRIBUTE_NAMES",[...Ye,"cx","cy","rx","ry"]),L.setClass(He),L.setSVGClass(He);const ad=["left","top"],kh={exactBoundingBox:!1};class me extends Ot{static getDefaults(){return w(w({},super.getDefaults()),me.ownDefaults)}constructor(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:[],e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};super(),x(this,"strokeDiff",void 0),Object.assign(this,me.ownDefaults),this.setOptions(e),this.points=t;const{left:s,top:i}=e;this.initialized=!0,this.setBoundingBox(!0),typeof s=="number"&&this.set(it,s),typeof i=="number"&&this.set(Yt,i)}isOpen(){return!0}_projectStrokeOnPoints(t){return Ua(this.points,t,this.isOpen())}_calcDimensions(t){t=w({scaleX:this.scaleX,scaleY:this.scaleY,skewX:this.skewX,skewY:this.skewY,strokeLineCap:this.strokeLineCap,strokeLineJoin:this.strokeLineJoin,strokeMiterLimit:this.strokeMiterLimit,strokeUniform:this.strokeUniform,strokeWidth:this.strokeWidth},t||{});const e=this.exactBoundingBox?this._projectStrokeOnPoints(t).map((l=>l.projectedPoint)):this.points;if(e.length===0)return{left:0,top:0,width:0,height:0,pathOffset:new C,strokeOffset:new C,strokeDiff:new C};const s=Ae(e),i=Js(w(w({},t),{},{scaleX:1,scaleY:1})),n=Ae(this.points.map((l=>Pt(l,i,!0)))),r=new C(this.scaleX,this.scaleY);let o=s.left+s.width/2,h=s.top+s.height/2;return this.exactBoundingBox&&(o-=h*Math.tan(pt(this.skewX)),h-=o*Math.tan(pt(this.skewY))),w(w({},s),{},{pathOffset:new C(o,h),strokeOffset:new C(n.left,n.top).subtract(new C(s.left,s.top)).multiply(r),strokeDiff:new C(s.width,s.height).subtract(new C(n.width,n.height)).multiply(r)})}_findCenterFromElement(){const t=Ae(this.points);return new C(t.left+t.width/2,t.top+t.height/2)}setDimensions(){this.setBoundingBox()}setBoundingBox(t){const{left:e,top:s,width:i,height:n,pathOffset:r,strokeOffset:o,strokeDiff:h}=this._calcDimensions();this.set({width:i,height:n,pathOffset:r,strokeOffset:o,strokeDiff:h}),t&&this.setPositionByOrigin(new C(e+i/2,s+n/2),$,$)}isStrokeAccountedForInDimensions(){return this.exactBoundingBox}_getNonTransformedDimensions(){return this.exactBoundingBox?new C(this.width,this.height):super._getNonTransformedDimensions()}_getTransformedDimensions(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};if(this.exactBoundingBox){let r;if(Object.keys(t).some((o=>this.strokeUniform||this.constructor.layoutProperties.includes(o)))){var e,s;const{width:o,height:h}=this._calcDimensions(t);r=new C((e=t.width)!==null&&e!==void 0?e:o,(s=t.height)!==null&&s!==void 0?s:h)}else{var i,n;r=new C((i=t.width)!==null&&i!==void 0?i:this.width,(n=t.height)!==null&&n!==void 0?n:this.height)}return r.multiply(new C(t.scaleX||this.scaleX,t.scaleY||this.scaleY))}return super._getTransformedDimensions(t)}_set(t,e){const s=this.initialized&&this[t]!==e,i=super._set(t,e);return this.exactBoundingBox&&s&&((t===Bt||t===Qt)&&this.strokeUniform&&this.constructor.layoutProperties.includes("strokeUniform")||this.constructor.layoutProperties.includes(t))&&this.setDimensions(),i}toObject(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:[];return w(w({},super.toObject(t)),{},{points:this.points.map((e=>{let{x:s,y:i}=e;return{x:s,y:i}}))})}_toSVG(){const t=[],e=this.pathOffset.x,s=this.pathOffset.y,i=et.NUM_FRACTION_DIGITS;for(let n=0,r=this.points.length;n<r;n++)t.push(ot(this.points[n].x-e,i),",",ot(this.points[n].y-s,i)," ");return["<".concat(this.constructor.type.toLowerCase()," "),"COMMON_PARTS",'points="'.concat(t.join(""),`" />
|
|
57
57
|
`)]}_render(t){const e=this.points.length,s=this.pathOffset.x,i=this.pathOffset.y;if(e&&!isNaN(this.points[e-1].y)){t.beginPath(),t.moveTo(this.points[0].x-s,this.points[0].y-i);for(let n=0;n<e;n++){const r=this.points[n];t.lineTo(r.x-s,r.y-i)}!this.isOpen()&&t.closePath(),this._renderPaintInOrder(t)}}complexity(){return this.points.length}static async fromElement(t,e,s){return new this(od(t.getAttribute("points")),w(w({},lt(Ne(t,this.ATTRIBUTE_NAMES,s),ad)),e))}static fromObject(t){return this._fromObject(t,{extraParam:"points"})}}x(me,"ownDefaults",kh),x(me,"type","Polyline"),x(me,"layoutProperties",[Ss,Cs,"strokeLineCap","strokeLineJoin","strokeMiterLimit","strokeWidth","strokeUniform","points"]),x(me,"cacheProperties",[...Fe,"points"]),x(me,"ATTRIBUTE_NAMES",[...Ye]),L.setClass(me),L.setSVGClass(me);class rn extends me{isOpen(){return!1}}x(rn,"ownDefaults",kh),x(rn,"type","Polygon"),L.setClass(rn),L.setSVGClass(rn);class Mh extends Ot{isEmptyStyles(t){if(!this.styles||t!==void 0&&!this.styles[t])return!0;const e=t===void 0?this.styles:{line:this.styles[t]};for(const s in e)for(const i in e[s])for(const n in e[s][i])return!1;return!0}styleHas(t,e){if(!this.styles||e!==void 0&&!this.styles[e])return!1;const s=e===void 0?this.styles:{0:this.styles[e]};for(const i in s)for(const n in s[i])if(s[i][n][t]!==void 0)return!0;return!1}cleanStyle(t){if(!this.styles)return!1;const e=this.styles;let s,i,n=0,r=!0,o=0;for(const h in e){s=0;for(const l in e[h]){const c=e[h][l]||{};n++,c[t]!==void 0?(i?c[t]!==i&&(r=!1):i=c[t],c[t]===this[t]&&delete c[t]):r=!1,Object.keys(c).length!==0?s++:delete e[h][l]}s===0&&delete e[h]}for(let h=0;h<this._textLines.length;h++)o+=this._textLines[h].length;r&&n===o&&(this[t]=i,this.removeStyle(t))}removeStyle(t){if(!this.styles)return;const e=this.styles;let s,i,n;for(i in e){for(n in s=e[i],s)delete s[n][t],Object.keys(s[n]).length===0&&delete s[n];Object.keys(s).length===0&&delete e[i]}}_extendStyles(t,e){const{lineIndex:s,charIndex:i}=this.get2DCursorLocation(t);this._getLineStyle(s)||this._setLineStyle(s);const n=lr(w(w({},this._getStyleDeclaration(s,i)),e),(r=>r!==void 0));this._setStyleDeclaration(s,i,n)}getSelectionStyles(t,e,s){const i=[];for(let n=t;n<(e||t);n++)i.push(this.getStyleAtPosition(n,s));return i}getStyleAtPosition(t,e){const{lineIndex:s,charIndex:i}=this.get2DCursorLocation(t);return e?this.getCompleteStyleDeclaration(s,i):this._getStyleDeclaration(s,i)}setSelectionStyles(t,e,s){for(let i=e;i<(s||e);i++)this._extendStyles(i,t);this._forceClearCache=!0}_getStyleDeclaration(t,e){var s;const i=this.styles&&this.styles[t];return i&&(s=i[e])!==null&&s!==void 0?s:{}}getCompleteStyleDeclaration(t,e){return w(w({},rs(this,this.constructor._styleProperties)),this._getStyleDeclaration(t,e))}_setStyleDeclaration(t,e,s){this.styles[t][e]=s}_deleteStyleDeclaration(t,e){delete this.styles[t][e]}_getLineStyle(t){return!!this.styles[t]}_setLineStyle(t){this.styles[t]={}}_deleteLineStyle(t){delete this.styles[t]}}x(Mh,"_styleProperties",wc);const hd=/ +/g,ld=/"/g;function zr(a,t,e,s,i){return" ".concat((function(n,r){let{left:o,top:h,width:l,height:c}=r,u=arguments.length>2&&arguments[2]!==void 0?arguments[2]:et.NUM_FRACTION_DIGITS;const d=si(wt,n,!1),[f,g,p,b]=[o,h,l,c].map((m=>ot(m,u)));return"<rect ".concat(d,' x="').concat(f,'" y="').concat(g,'" width="').concat(p,'" height="').concat(b,'"></rect>')})(a,{left:t,top:e,width:s,height:i}),`
|
|
58
|
-
`)}const cd=["textAnchor","textDecoration","dx","dy","top","left","fontSize","strokeWidth"];let Gr;class Dt extends Mh{static getDefaults(){return w(w({},super.getDefaults()),Dt.ownDefaults)}constructor(t,e){super(),x(this,"__charBounds",[]),Object.assign(this,Dt.ownDefaults),this.setOptions(e),this.styles||(this.styles={}),this.text=t,this.initialized=!0,this.path&&this.setPathInfo(),this.initDimensions(),this.setCoords()}setPathInfo(){const t=this.path;t&&(t.segmentsInfo=Nr(t.path))}_splitText(){const t=this._splitTextIntoLines(this.text);return this.textLines=t.lines,this._textLines=t.graphemeLines,this._unwrappedTextLines=t._unwrappedLines,this._text=t.graphemeText,t}initDimensions(){this._splitText(),this._clearCache(),this.dirty=!0,this.path?(this.width=this.path.width,this.height=this.path.height):(this.width=this.calcTextWidth()||this.cursorWidth||this.MIN_TEXT_WIDTH,this.height=this.calcTextHeight()),this.textAlign.includes(Te)&&this.enlargeSpaces()}enlargeSpaces(){let t,e,s,i,n,r,o;for(let h=0,l=this._textLines.length;h<l;h++)if((this.textAlign===Te||h!==l-1&&!this.isEndOfWrapping(h))&&(i=0,n=this._textLines[h],e=this.getLineWidth(h),e<this.width&&(o=this.textLines[h].match(this._reSpacesAndTabs)))){s=o.length,t=(this.width-e)/s;for(let c=0;c<=n.length;c++)r=this.__charBounds[h][c],this._reSpaceAndTab.test(n[c])?(r.width+=t,r.kernedWidth+=t,r.left+=i,i+=t):r.left+=i}}isEndOfWrapping(t){return t===this._textLines.length-1}missingNewlineOffset(t){return 1}get2DCursorLocation(t,e){const s=e?this._unwrappedTextLines:this._textLines;let i;for(i=0;i<s.length;i++){if(t<=s[i].length)return{lineIndex:i,charIndex:t};t-=s[i].length+this.missingNewlineOffset(i,e)}return{lineIndex:i-1,charIndex:s[i-1].length<t?s[i-1].length:t}}toString(){return"#<Text (".concat(this.complexity(),'): { "text": "').concat(this.text,'", "fontFamily": "').concat(this.fontFamily,'" }>')}_getCacheCanvasDimensions(){const t=super._getCacheCanvasDimensions(),e=this.fontSize;return t.width+=e*t.zoomX,t.height+=e*t.zoomY,t}_render(t){const e=this.path;e&&!e.isNotVisible()&&e._render(t),this._setTextStyles(t),this._renderTextLinesBackground(t),this._renderTextDecoration(t,"underline"),this._renderText(t),this._renderTextDecoration(t,"overline"),this._renderTextDecoration(t,"linethrough")}_renderText(t){this.paintFirst===Ht?(this._renderTextStroke(t),this._renderTextFill(t)):(this._renderTextFill(t),this._renderTextStroke(t))}_setTextStyles(t,e,s){if(t.textBaseline="alphabetic",this.path)switch(this.pathAlign){case $:t.textBaseline="middle";break;case"ascender":t.textBaseline=Yt;break;case"descender":t.textBaseline=tr}t.font=this._getFontDeclaration(e,s)}calcTextWidth(){let t=this.getLineWidth(0);for(let e=1,s=this._textLines.length;e<s;e++){const i=this.getLineWidth(e);i>t&&(t=i)}return t}_renderTextLine(t,e,s,i,n,r){this._renderChars(t,e,s,i,n,r)}_renderTextLinesBackground(t){if(!this.textBackgroundColor&&!this.styleHas("textBackgroundColor"))return;const e=t.fillStyle,s=this._getLeftOffset();let i=this._getTopOffset();for(let n=0,r=this._textLines.length;n<r;n++){const o=this.getHeightOfLine(n);if(!this.textBackgroundColor&&!this.styleHas("textBackgroundColor",n)){i+=o;continue}const h=this._textLines[n].length,l=this._getLineLeftOffset(n);let c,u,d=0,f=0,g=this.getValueOfPropertyAt(n,0,"textBackgroundColor");const p=this.getHeightOfLineImpl(n);for(let b=0;b<h;b++){const m=this.__charBounds[n][b];u=this.getValueOfPropertyAt(n,b,"textBackgroundColor"),this.path?(t.save(),t.translate(m.renderLeft,m.renderTop),t.rotate(m.angle),t.fillStyle=u,u&&t.fillRect(-m.width/2,-p*(1-this._fontSizeFraction),m.width,p),t.restore()):u!==g?(c=s+l+f,this.direction==="rtl"&&(c=this.width-c-d),t.fillStyle=g,g&&t.fillRect(c,i,d,p),f=m.left,d=m.width,g=u):d+=m.kernedWidth}u&&!this.path&&(c=s+l+f,this.direction==="rtl"&&(c=this.width-c-d),t.fillStyle=u,t.fillRect(c,i,d,p)),i+=o}t.fillStyle=e,this._removeShadow(t)}_measureChar(t,e,s,i){const n=$s.getFontCache(e),r=this._getFontDeclaration(e),o=s+t,h=s&&r===this._getFontDeclaration(i),l=e.fontSize/this.CACHE_FONT_SIZE;let c,u,d,f;if(s&&n.has(s)&&(d=n.get(s)),n.has(t)&&(f=c=n.get(t)),h&&n.has(o)&&(u=n.get(o),f=u-d),c===void 0||d===void 0||u===void 0){const g=(function(){return Gr||(Gr=te({width:0,height:0}).getContext("2d")),Gr})();this._setTextStyles(g,e,!0),c===void 0&&(f=c=g.measureText(t).width,n.set(t,c)),d===void 0&&h&&s&&(d=g.measureText(s).width,n.set(s,d)),h&&u===void 0&&(u=g.measureText(o).width,n.set(o,u),f=u-d)}return{width:c*l,kernedWidth:f*l}}getHeightOfChar(t,e){return this.getValueOfPropertyAt(t,e,"fontSize")}measureLine(t){const e=this._measureLine(t);return this.charSpacing!==0&&(e.width-=this._getWidthOfCharSpacing()),e.width<0&&(e.width=0),e}_measureLine(t){let e,s,i=0;const n=this.pathSide===bt,r=this.path,o=this._textLines[t],h=o.length,l=new Array(h);this.__charBounds[t]=l;for(let c=0;c<h;c++){const u=o[c];s=this._getGraphemeBox(u,t,c,e),l[c]=s,i+=s.kernedWidth,e=u}if(l[h]={left:s?s.left+s.width:0,width:0,kernedWidth:0,height:this.fontSize,deltaY:0},r&&r.segmentsInfo){let c=0;const u=r.segmentsInfo[r.segmentsInfo.length-1].length;switch(this.textAlign){case it:c=n?u-i:0;break;case $:c=(u-i)/2;break;case bt:c=n?0:u-i}c+=this.pathStartOffset*(n?-1:1);for(let d=n?h-1:0;n?d>=0:d<h;n?d--:d++)s=l[d],c>u?c%=u:c<0&&(c+=u),this._setGraphemeOnPath(c,s),c+=s.kernedWidth}return{width:i,numOfSpaces:0}}_setGraphemeOnPath(t,e){const s=t+e.kernedWidth/2,i=this.path,n=mh(i.path,s,i.segmentsInfo);e.renderLeft=n.x-i.pathOffset.x,e.renderTop=n.y-i.pathOffset.y,e.angle=n.angle+(this.pathSide===bt?Math.PI:0)}_getGraphemeBox(t,e,s,i,n){const r=this.getCompleteStyleDeclaration(e,s),o=i?this.getCompleteStyleDeclaration(e,s-1):{},h=this._measureChar(t,r,i,o);let l,c=h.kernedWidth,u=h.width;this.charSpacing!==0&&(l=this._getWidthOfCharSpacing(),u+=l,c+=l);const d={width:u,left:0,height:r.fontSize,kernedWidth:c,deltaY:r.deltaY};if(s>0&&!n){const f=this.__charBounds[e][s-1];d.left=f.left+f.width+h.kernedWidth-h.width}return d}getHeightOfLineImpl(t){const e=this.__lineHeights;if(e[t])return e[t];let s=this.getHeightOfChar(t,0);for(let i=1,n=this._textLines[t].length;i<n;i++)s=Math.max(this.getHeightOfChar(t,i),s);return e[t]=s*this._fontSizeMult}getHeightOfLine(t){return this.getHeightOfLineImpl(t)*this.lineHeight}calcTextHeight(){let t=0;for(let e=0,s=this._textLines.length;e<s;e++)t+=e===s-1?this.getHeightOfLineImpl(e):this.getHeightOfLine(e);return t}_getLeftOffset(){return this.direction==="ltr"?-this.width/2:this.width/2}_getTopOffset(){return-this.height/2}_renderTextCommon(t,e){t.save();let s=0;const i=this._getLeftOffset(),n=this._getTopOffset();for(let r=0,o=this._textLines.length;r<o;r++)this._renderTextLine(e,t,this._textLines[r],i+this._getLineLeftOffset(r),n+s+this.getHeightOfLineImpl(r),r),s+=this.getHeightOfLine(r);t.restore()}_renderTextFill(t){(this.fill||this.styleHas(wt))&&this._renderTextCommon(t,"fillText")}_renderTextStroke(t){(this.stroke&&this.strokeWidth!==0||!this.isEmptyStyles())&&(this.shadow&&!this.shadow.affectStroke&&this._removeShadow(t),t.save(),this._setLineDash(t,this.strokeDashArray),t.beginPath(),this._renderTextCommon(t,"strokeText"),t.closePath(),t.restore())}_renderChars(t,e,s,i,n,r){const o=this.textAlign.includes(Te),h=this.path,l=!o&&this.charSpacing===0&&this.isEmptyStyles(r)&&!h,c=this.direction==="ltr",u=this.direction==="ltr"?1:-1,d=e.direction;let f,g,p,b,m,v="",y=0;if(e.save(),d!==this.direction&&(e.canvas.setAttribute("dir",c?"ltr":"rtl"),e.direction=c?"ltr":"rtl",e.textAlign=c?it:bt),n-=this.getHeightOfLineImpl(r)*this._fontSizeFraction,l)return this._renderChar(t,e,r,0,s.join(""),i,n),void e.restore();for(let _=0,S=s.length-1;_<=S;_++)b=_===S||this.charSpacing||h,v+=s[_],p=this.__charBounds[r][_],y===0?(i+=u*(p.kernedWidth-p.width),y+=p.width):y+=p.kernedWidth,o&&!b&&this._reSpaceAndTab.test(s[_])&&(b=!0),b||(f=f||this.getCompleteStyleDeclaration(r,_),g=this.getCompleteStyleDeclaration(r,_+1),b=qi(f,g,!1)),b&&(h?(e.save(),e.translate(p.renderLeft,p.renderTop),e.rotate(p.angle),this._renderChar(t,e,r,_,v,-y/2,0),e.restore()):(m=i,this._renderChar(t,e,r,_,v,m,n)),v="",f=g,i+=u*y,y=0);e.restore()}_applyPatternGradientTransformText(t){const e=this.width+this.strokeWidth,s=this.height+this.strokeWidth,i=te({width:e,height:s}),n=i.getContext("2d");return i.width=e,i.height=s,n.beginPath(),n.moveTo(0,0),n.lineTo(e,0),n.lineTo(e,s),n.lineTo(0,s),n.closePath(),n.translate(e/2,s/2),n.fillStyle=t.toLive(n),this._applyPatternGradientTransform(n,t),n.fill(),n.createPattern(i,"no-repeat")}handleFiller(t,e,s){let i,n;return re(s)?s.gradientUnits==="percentage"||s.gradientTransform||s.patternTransform?(i=-this.width/2,n=-this.height/2,t.translate(i,n),t[e]=this._applyPatternGradientTransformText(s),{offsetX:i,offsetY:n}):(t[e]=s.toLive(t),this._applyPatternGradientTransform(t,s)):(t[e]=s,{offsetX:0,offsetY:0})}_setStrokeStyles(t,e){let{stroke:s,strokeWidth:i}=e;return t.lineWidth=i,t.lineCap=this.strokeLineCap,t.lineDashOffset=this.strokeDashOffset,t.lineJoin=this.strokeLineJoin,t.miterLimit=this.strokeMiterLimit,this.handleFiller(t,"strokeStyle",s)}_setFillStyles(t,e){let{fill:s}=e;return this.handleFiller(t,"fillStyle",s)}_renderChar(t,e,s,i,n,r,o){const h=this._getStyleDeclaration(s,i),l=this.getCompleteStyleDeclaration(s,i),c=t==="fillText"&&l.fill,u=t==="strokeText"&&l.stroke&&l.strokeWidth;if(u||c){if(e.save(),e.font=this._getFontDeclaration(l),h.textBackgroundColor&&this._removeShadow(e),h.deltaY&&(o+=h.deltaY),c){const d=this._setFillStyles(e,l);e.fillText(n,r-d.offsetX,o-d.offsetY)}if(u){const d=this._setStrokeStyles(e,l);e.strokeText(n,r-d.offsetX,o-d.offsetY)}e.restore()}}setSuperscript(t,e){this._setScript(t,e,this.superscript)}setSubscript(t,e){this._setScript(t,e,this.subscript)}_setScript(t,e,s){const i=this.get2DCursorLocation(t,!0),n=this.getValueOfPropertyAt(i.lineIndex,i.charIndex,"fontSize"),r=this.getValueOfPropertyAt(i.lineIndex,i.charIndex,"deltaY"),o={fontSize:n*s.size,deltaY:r+n*s.baseline};this.setSelectionStyles(o,t,e)}_getLineLeftOffset(t){const e=this.getLineWidth(t),s=this.width-e,i=this.textAlign,n=this.direction,r=this.isEndOfWrapping(t);let o=0;return i===Te||i===ni&&!r||i===ii&&!r||i===Hi&&!r?0:(i===$&&(o=s/2),i===bt&&(o=s),i===ni&&(o=s/2),i===ii&&(o=s),n==="rtl"&&(i===bt||i===Te||i===ii?o=0:i===it||i===Hi?o=-s:i!==$&&i!==ni||(o=-s/2)),o)}_clearCache(){this._forceClearCache=!1,this.__lineWidths=[],this.__lineHeights=[],this.__charBounds=[]}getLineWidth(t){if(this.__lineWidths[t]!==void 0)return this.__lineWidths[t];const{width:e}=this.measureLine(t);return this.__lineWidths[t]=e,e}_getWidthOfCharSpacing(){return this.charSpacing!==0?this.fontSize*this.charSpacing/1e3:0}getValueOfPropertyAt(t,e,s){var i;return(i=this._getStyleDeclaration(t,e)[s])!==null&&i!==void 0?i:this[s]}_renderTextDecoration(t,e){if(!this[e]&&!this.styleHas(e))return;let s=this._getTopOffset();const i=this._getLeftOffset(),n=this.path,r=this._getWidthOfCharSpacing(),o=e==="linethrough"?.5:e==="overline"?1:0,h=this.offsets[e];for(let l=0,c=this._textLines.length;l<c;l++){const u=this.getHeightOfLine(l);if(!this[e]&&!this.styleHas(e,l)){s+=u;continue}const d=this._textLines[l],f=u/this.lineHeight,g=this._getLineLeftOffset(l);let p=0,b=0,m=this.getValueOfPropertyAt(l,0,e),v=this.getValueOfPropertyAt(l,0,wt),y=this.getValueOfPropertyAt(l,0,hs),_=m,S=v,A=y;const T=s+f*(1-this._fontSizeFraction);let k=this.getHeightOfChar(l,0),P=this.getValueOfPropertyAt(l,0,"deltaY");for(let I=0,O=d.length;I<O;I++){const D=this.__charBounds[l][I];_=this.getValueOfPropertyAt(l,I,e),S=this.getValueOfPropertyAt(l,I,wt),A=this.getValueOfPropertyAt(l,I,hs);const z=this.getHeightOfChar(l,I),M=this.getValueOfPropertyAt(l,I,"deltaY");if(n&&_&&S){const R=this.fontSize*A/1e3;t.save(),t.fillStyle=v,t.translate(D.renderLeft,D.renderTop),t.rotate(D.angle),t.fillRect(-D.kernedWidth/2,h*z+M-o*R,D.kernedWidth,R),t.restore()}else if((_!==m||S!==v||z!==k||A!==y||M!==P)&&b>0){const R=this.fontSize*y/1e3;let U=i+g+p;this.direction==="rtl"&&(U=this.width-U-b),m&&v&&y&&(t.fillStyle=v,t.fillRect(U,T+h*k+P-o*R,b,R)),p=D.left,b=D.width,m=_,y=A,v=S,k=z,P=M}else b+=D.kernedWidth}let B=i+g+p;this.direction==="rtl"&&(B=this.width-B-b),t.fillStyle=S;const F=this.fontSize*A/1e3;_&&S&&A&&t.fillRect(B,T+h*k+P-o*F,b-r,F),s+=u}this._removeShadow(t)}_getFontDeclaration(){let{fontFamily:t=this.fontFamily,fontStyle:e=this.fontStyle,fontWeight:s=this.fontWeight,fontSize:i=this.fontSize}=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},n=arguments.length>1?arguments[1]:void 0;const r=t.includes("'")||t.includes('"')||t.includes(",")||Dt.genericFonts.includes(t.toLowerCase())?t:'"'.concat(t,'"');return[e,s,"".concat(n?this.CACHE_FONT_SIZE:i,"px"),r].join(" ")}render(t){this.visible&&(this.canvas&&this.canvas.skipOffscreen&&!this.group&&!this.isOnScreen()||(this._forceClearCache&&this.initDimensions(),super.render(t)))}graphemeSplit(t){return $i(t)}_splitTextIntoLines(t){const e=t.split(this._reNewline),s=new Array(e.length),i=[`
|
|
58
|
+
`)}const cd=["textAnchor","textDecoration","dx","dy","top","left","fontSize","strokeWidth"];let Gr;class Dt extends Mh{static getDefaults(){return w(w({},super.getDefaults()),Dt.ownDefaults)}constructor(t,e){super(),x(this,"__charBounds",[]),Object.assign(this,Dt.ownDefaults),this.setOptions(e),this.styles||(this.styles={}),this.text=t,this.initialized=!0,this.path&&this.setPathInfo(),this.initDimensions(),this.setCoords()}setPathInfo(){const t=this.path;t&&(t.segmentsInfo=Nr(t.path))}_splitText(){const t=this._splitTextIntoLines(this.text);return this.textLines=t.lines,this._textLines=t.graphemeLines,this._unwrappedTextLines=t._unwrappedLines,this._text=t.graphemeText,t}initDimensions(){this._splitText(),this._clearCache(),this.dirty=!0,this.path?(this.width=this.path.width,this.height=this.path.height):(this.width=this.calcTextWidth()||this.cursorWidth||this.MIN_TEXT_WIDTH,this.height=this.calcTextHeight()),this.textAlign.includes(Te)&&this.enlargeSpaces()}enlargeSpaces(){let t,e,s,i,n,r,o;for(let h=0,l=this._textLines.length;h<l;h++)if((this.textAlign===Te||h!==l-1&&!this.isEndOfWrapping(h))&&(i=0,n=this._textLines[h],e=this.getLineWidth(h),e<this.width&&(o=this.textLines[h].match(this._reSpacesAndTabs)))){s=o.length,t=(this.width-e)/s;for(let c=0;c<=n.length;c++)r=this.__charBounds[h][c],this._reSpaceAndTab.test(n[c])?(r.width+=t,r.kernedWidth+=t,r.left+=i,i+=t):r.left+=i}}isEndOfWrapping(t){return t===this._textLines.length-1}missingNewlineOffset(t){return 1}get2DCursorLocation(t,e){const s=e?this._unwrappedTextLines:this._textLines;let i;for(i=0;i<s.length;i++){if(t<=s[i].length)return{lineIndex:i,charIndex:t};t-=s[i].length+this.missingNewlineOffset(i,e)}return{lineIndex:i-1,charIndex:s[i-1].length<t?s[i-1].length:t}}toString(){return"#<Text (".concat(this.complexity(),'): { "text": "').concat(this.text,'", "fontFamily": "').concat(this.fontFamily,'" }>')}_getCacheCanvasDimensions(){const t=super._getCacheCanvasDimensions(),e=this.fontSize;return t.width+=e*t.zoomX,t.height+=e*t.zoomY,t}_render(t){const e=this.path;e&&!e.isNotVisible()&&e._render(t),this._setTextStyles(t),this._renderTextLinesBackground(t),this._renderTextDecoration(t,"underline"),this._renderText(t),this._renderTextDecoration(t,"overline"),this._renderTextDecoration(t,"linethrough")}_renderText(t){this.paintFirst===Ht?(this._renderTextStroke(t),this._renderTextFill(t)):(this._renderTextFill(t),this._renderTextStroke(t))}_setTextStyles(t,e,s){if(t.textBaseline="alphabetic",this.path)switch(this.pathAlign){case $:t.textBaseline="middle";break;case"ascender":t.textBaseline=Yt;break;case"descender":t.textBaseline=tr}t.font=this._getFontDeclaration(e,s)}calcTextWidth(){let t=this.getLineWidth(0);for(let e=1,s=this._textLines.length;e<s;e++){const i=this.getLineWidth(e);i>t&&(t=i)}return t}_renderTextLine(t,e,s,i,n,r){this._renderChars(t,e,s,i,n,r)}_renderTextLinesBackground(t){if(!this.textBackgroundColor&&!this.styleHas("textBackgroundColor"))return;const e=t.fillStyle,s=this._getLeftOffset();let i=this._getTopOffset();for(let n=0,r=this._textLines.length;n<r;n++){const o=this.getHeightOfLine(n);if(!this.textBackgroundColor&&!this.styleHas("textBackgroundColor",n)){i+=o;continue}const h=this._textLines[n].length,l=this._getLineLeftOffset(n);let c,u,d=0,f=0,g=this.getValueOfPropertyAt(n,0,"textBackgroundColor");const p=this.getHeightOfLineImpl(n);for(let b=0;b<h;b++){const m=this.__charBounds[n][b];u=this.getValueOfPropertyAt(n,b,"textBackgroundColor"),this.path?(t.save(),t.translate(m.renderLeft,m.renderTop),t.rotate(m.angle),t.fillStyle=u,u&&t.fillRect(-m.width/2,-p*(1-this._fontSizeFraction),m.width,p),t.restore()):u!==g?(c=s+l+f,this.direction==="rtl"&&(c=this.width-c-d),t.fillStyle=g,g&&t.fillRect(c,i,d,p),f=m.left,d=m.width,g=u):d+=m.kernedWidth}u&&!this.path&&(c=s+l+f,this.direction==="rtl"&&(c=this.width-c-d),t.fillStyle=u,t.fillRect(c,i,d,p)),i+=o}t.fillStyle=e,this._removeShadow(t)}_measureChar(t,e,s,i){const n=$s.getFontCache(e),r=this._getFontDeclaration(e),o=s?s+t:t,h=s&&r===this._getFontDeclaration(i),l=e.fontSize/this.CACHE_FONT_SIZE;let c,u,d,f;if(s&&n.has(s)&&(d=n.get(s)),n.has(t)&&(f=c=n.get(t)),h&&n.has(o)&&(u=n.get(o),f=u-d),c===void 0||d===void 0||u===void 0){const g=(function(){return Gr||(Gr=te({width:0,height:0}).getContext("2d")),Gr})();this._setTextStyles(g,e,!0),c===void 0&&(f=c=g.measureText(t).width,n.set(t,c)),d===void 0&&h&&s&&(d=g.measureText(s).width,n.set(s,d)),h&&u===void 0&&(u=g.measureText(o).width,n.set(o,u),f=u-d)}return{width:c*l,kernedWidth:f*l}}getHeightOfChar(t,e){return this.getValueOfPropertyAt(t,e,"fontSize")}measureLine(t){const e=this._measureLine(t);return this.charSpacing!==0&&(e.width-=this._getWidthOfCharSpacing()),e.width<0&&(e.width=0),e}_measureLine(t){let e,s,i=0;const n=this.pathSide===bt,r=this.path,o=this._textLines[t],h=o.length,l=new Array(h);this.__charBounds[t]=l;for(let c=0;c<h;c++){const u=o[c];s=this._getGraphemeBox(u,t,c,e),l[c]=s,i+=s.kernedWidth,e=u}if(l[h]={left:s?s.left+s.width:0,width:0,kernedWidth:0,height:this.fontSize,deltaY:0},r&&r.segmentsInfo){let c=0;const u=r.segmentsInfo[r.segmentsInfo.length-1].length;switch(this.textAlign){case it:c=n?u-i:0;break;case $:c=(u-i)/2;break;case bt:c=n?0:u-i}c+=this.pathStartOffset*(n?-1:1);for(let d=n?h-1:0;n?d>=0:d<h;n?d--:d++)s=l[d],c>u?c%=u:c<0&&(c+=u),this._setGraphemeOnPath(c,s),c+=s.kernedWidth}return{width:i,numOfSpaces:0}}_setGraphemeOnPath(t,e){const s=t+e.kernedWidth/2,i=this.path,n=mh(i.path,s,i.segmentsInfo);e.renderLeft=n.x-i.pathOffset.x,e.renderTop=n.y-i.pathOffset.y,e.angle=n.angle+(this.pathSide===bt?Math.PI:0)}_getGraphemeBox(t,e,s,i,n){const r=this.getCompleteStyleDeclaration(e,s),o=i?this.getCompleteStyleDeclaration(e,s-1):{},h=this._measureChar(t,r,i,o);let l,c=h.kernedWidth,u=h.width;this.charSpacing!==0&&(l=this._getWidthOfCharSpacing(),u+=l,c+=l);const d={width:u,left:0,height:r.fontSize,kernedWidth:c,deltaY:r.deltaY};if(s>0&&!n){const f=this.__charBounds[e][s-1];d.left=f.left+f.width+h.kernedWidth-h.width}return d}getHeightOfLineImpl(t){const e=this.__lineHeights;if(e[t])return e[t];let s=this.getHeightOfChar(t,0);for(let i=1,n=this._textLines[t].length;i<n;i++)s=Math.max(this.getHeightOfChar(t,i),s);return e[t]=s*this._fontSizeMult}getHeightOfLine(t){return this.getHeightOfLineImpl(t)*this.lineHeight}calcTextHeight(){let t=0;for(let e=0,s=this._textLines.length;e<s;e++)t+=e===s-1?this.getHeightOfLineImpl(e):this.getHeightOfLine(e);return t}_getLeftOffset(){return this.direction==="ltr"?-this.width/2:this.width/2}_getTopOffset(){return-this.height/2}_renderTextCommon(t,e){t.save();let s=0;const i=this._getLeftOffset(),n=this._getTopOffset();for(let r=0,o=this._textLines.length;r<o;r++)this._renderTextLine(e,t,this._textLines[r],i+this._getLineLeftOffset(r),n+s+this.getHeightOfLineImpl(r),r),s+=this.getHeightOfLine(r);t.restore()}_renderTextFill(t){(this.fill||this.styleHas(wt))&&this._renderTextCommon(t,"fillText")}_renderTextStroke(t){(this.stroke&&this.strokeWidth!==0||!this.isEmptyStyles())&&(this.shadow&&!this.shadow.affectStroke&&this._removeShadow(t),t.save(),this._setLineDash(t,this.strokeDashArray),t.beginPath(),this._renderTextCommon(t,"strokeText"),t.closePath(),t.restore())}_renderChars(t,e,s,i,n,r){const o=this.textAlign.includes(Te),h=this.path,l=!o&&this.charSpacing===0&&this.isEmptyStyles(r)&&!h,c=this.direction==="ltr",u=this.direction==="ltr"?1:-1,d=e.direction;let f,g,p,b,m,v="",y=0;if(e.save(),d!==this.direction&&(e.canvas.setAttribute("dir",c?"ltr":"rtl"),e.direction=c?"ltr":"rtl",e.textAlign=c?it:bt),n-=this.getHeightOfLineImpl(r)*this._fontSizeFraction,l)return this._renderChar(t,e,r,0,s.join(""),i,n),void e.restore();for(let _=0,S=s.length-1;_<=S;_++)b=_===S||this.charSpacing||h,v+=s[_],p=this.__charBounds[r][_],y===0?(i+=u*(p.kernedWidth-p.width),y+=p.width):y+=p.kernedWidth,o&&!b&&this._reSpaceAndTab.test(s[_])&&(b=!0),b||(f=f||this.getCompleteStyleDeclaration(r,_),g=this.getCompleteStyleDeclaration(r,_+1),b=qi(f,g,!1)),b&&(h?(e.save(),e.translate(p.renderLeft,p.renderTop),e.rotate(p.angle),this._renderChar(t,e,r,_,v,-y/2,0),e.restore()):(m=i,this._renderChar(t,e,r,_,v,m,n)),v="",f=g,i+=u*y,y=0);e.restore()}_applyPatternGradientTransformText(t){const e=this.width+this.strokeWidth,s=this.height+this.strokeWidth,i=te({width:e,height:s}),n=i.getContext("2d");return i.width=e,i.height=s,n.beginPath(),n.moveTo(0,0),n.lineTo(e,0),n.lineTo(e,s),n.lineTo(0,s),n.closePath(),n.translate(e/2,s/2),n.fillStyle=t.toLive(n),this._applyPatternGradientTransform(n,t),n.fill(),n.createPattern(i,"no-repeat")}handleFiller(t,e,s){let i,n;return re(s)?s.gradientUnits==="percentage"||s.gradientTransform||s.patternTransform?(i=-this.width/2,n=-this.height/2,t.translate(i,n),t[e]=this._applyPatternGradientTransformText(s),{offsetX:i,offsetY:n}):(t[e]=s.toLive(t),this._applyPatternGradientTransform(t,s)):(t[e]=s,{offsetX:0,offsetY:0})}_setStrokeStyles(t,e){let{stroke:s,strokeWidth:i}=e;return t.lineWidth=i,t.lineCap=this.strokeLineCap,t.lineDashOffset=this.strokeDashOffset,t.lineJoin=this.strokeLineJoin,t.miterLimit=this.strokeMiterLimit,this.handleFiller(t,"strokeStyle",s)}_setFillStyles(t,e){let{fill:s}=e;return this.handleFiller(t,"fillStyle",s)}_renderChar(t,e,s,i,n,r,o){const h=this._getStyleDeclaration(s,i),l=this.getCompleteStyleDeclaration(s,i),c=t==="fillText"&&l.fill,u=t==="strokeText"&&l.stroke&&l.strokeWidth;if(u||c){if(e.save(),e.font=this._getFontDeclaration(l),h.textBackgroundColor&&this._removeShadow(e),h.deltaY&&(o+=h.deltaY),c){const d=this._setFillStyles(e,l);e.fillText(n,r-d.offsetX,o-d.offsetY)}if(u){const d=this._setStrokeStyles(e,l);e.strokeText(n,r-d.offsetX,o-d.offsetY)}e.restore()}}setSuperscript(t,e){this._setScript(t,e,this.superscript)}setSubscript(t,e){this._setScript(t,e,this.subscript)}_setScript(t,e,s){const i=this.get2DCursorLocation(t,!0),n=this.getValueOfPropertyAt(i.lineIndex,i.charIndex,"fontSize"),r=this.getValueOfPropertyAt(i.lineIndex,i.charIndex,"deltaY"),o={fontSize:n*s.size,deltaY:r+n*s.baseline};this.setSelectionStyles(o,t,e)}_getLineLeftOffset(t){const e=this.getLineWidth(t),s=this.width-e,i=this.textAlign,n=this.direction,r=this.isEndOfWrapping(t);let o=0;return i===Te||i===ni&&!r||i===ii&&!r||i===Hi&&!r?0:(i===$&&(o=s/2),i===bt&&(o=s),i===ni&&(o=s/2),i===ii&&(o=s),n==="rtl"&&(i===bt||i===Te||i===ii?o=0:i===it||i===Hi?o=-s:i!==$&&i!==ni||(o=-s/2)),o)}_clearCache(){this._forceClearCache=!1,this.__lineWidths=[],this.__lineHeights=[],this.__charBounds=[]}getLineWidth(t){if(this.__lineWidths[t]!==void 0)return this.__lineWidths[t];const{width:e}=this.measureLine(t);return this.__lineWidths[t]=e,e}_getWidthOfCharSpacing(){return this.charSpacing!==0?this.fontSize*this.charSpacing/1e3:0}getValueOfPropertyAt(t,e,s){var i;return(i=this._getStyleDeclaration(t,e)[s])!==null&&i!==void 0?i:this[s]}_renderTextDecoration(t,e){if(!this[e]&&!this.styleHas(e))return;let s=this._getTopOffset();const i=this._getLeftOffset(),n=this.path,r=this._getWidthOfCharSpacing(),o=e==="linethrough"?.5:e==="overline"?1:0,h=this.offsets[e];for(let l=0,c=this._textLines.length;l<c;l++){const u=this.getHeightOfLine(l);if(!this[e]&&!this.styleHas(e,l)){s+=u;continue}const d=this._textLines[l],f=u/this.lineHeight,g=this._getLineLeftOffset(l);let p=0,b=0,m=this.getValueOfPropertyAt(l,0,e),v=this.getValueOfPropertyAt(l,0,wt),y=this.getValueOfPropertyAt(l,0,hs),_=m,S=v,A=y;const T=s+f*(1-this._fontSizeFraction);let k=this.getHeightOfChar(l,0),P=this.getValueOfPropertyAt(l,0,"deltaY");for(let I=0,O=d.length;I<O;I++){const D=this.__charBounds[l][I];_=this.getValueOfPropertyAt(l,I,e),S=this.getValueOfPropertyAt(l,I,wt),A=this.getValueOfPropertyAt(l,I,hs);const z=this.getHeightOfChar(l,I),M=this.getValueOfPropertyAt(l,I,"deltaY");if(n&&_&&S){const R=this.fontSize*A/1e3;t.save(),t.fillStyle=v,t.translate(D.renderLeft,D.renderTop),t.rotate(D.angle),t.fillRect(-D.kernedWidth/2,h*z+M-o*R,D.kernedWidth,R),t.restore()}else if((_!==m||S!==v||z!==k||A!==y||M!==P)&&b>0){const R=this.fontSize*y/1e3;let U=i+g+p;this.direction==="rtl"&&(U=this.width-U-b),m&&v&&y&&(t.fillStyle=v,t.fillRect(U,T+h*k+P-o*R,b,R)),p=D.left,b=D.width,m=_,y=A,v=S,k=z,P=M}else b+=D.kernedWidth}let B=i+g+p;this.direction==="rtl"&&(B=this.width-B-b),t.fillStyle=S;const F=this.fontSize*A/1e3;_&&S&&A&&t.fillRect(B,T+h*k+P-o*F,b-r,F),s+=u}this._removeShadow(t)}_getFontDeclaration(){let{fontFamily:t=this.fontFamily,fontStyle:e=this.fontStyle,fontWeight:s=this.fontWeight,fontSize:i=this.fontSize}=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},n=arguments.length>1?arguments[1]:void 0;const r=t.includes("'")||t.includes('"')||t.includes(",")||Dt.genericFonts.includes(t.toLowerCase())?t:'"'.concat(t,'"');return[e,s,"".concat(n?this.CACHE_FONT_SIZE:i,"px"),r].join(" ")}render(t){this.visible&&(this.canvas&&this.canvas.skipOffscreen&&!this.group&&!this.isOnScreen()||(this._forceClearCache&&this.initDimensions(),super.render(t)))}graphemeSplit(t){return $i(t)}_splitTextIntoLines(t){const e=t.split(this._reNewline),s=new Array(e.length),i=[`
|
|
59
59
|
`];let n=[];for(let r=0;r<e.length;r++)s[r]=this.graphemeSplit(e[r]),n=n.concat(s[r],i);return n.pop(),{_unwrappedLines:s,lines:e,graphemeText:n,graphemeLines:s}}toObject(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:[];return w(w({},super.toObject([..._a,...t])),{},{styles:$a(this.styles,this.text)},this.path?{path:this.path.toObject()}:{})}set(t,e){const{textLayoutProperties:s}=this.constructor;super.set(t,e);let i=!1,n=!1;if(typeof t=="object")for(const r in t)r==="path"&&this.setPathInfo(),i=i||s.includes(r),n=n||r==="path";else i=s.includes(t),n=t==="path";return n&&this.setPathInfo(),i&&this.initialized&&(this.initDimensions(),this.setCoords()),this}complexity(){return 1}static async fromElement(t,e,s){const i=Ne(t,Dt.ATTRIBUTE_NAMES,s),n=w(w({},e),i),{textAnchor:r=it,textDecoration:o="",dx:h=0,dy:l=0,top:c=0,left:u=0,fontSize:d=Qn,strokeWidth:f=1}=n,g=lt(n,cd),p=new this(Ni(t.textContent||"").trim(),w({left:u+h,top:c+l,underline:o.includes("underline"),overline:o.includes("overline"),linethrough:o.includes("line-through"),strokeWidth:0,fontSize:d},g)),b=p.getScaledHeight()/p.height,m=((p.height+p.strokeWidth)*p.lineHeight-p.height)*b,v=p.getScaledHeight()+m;let y=0;return r===$&&(y=p.getScaledWidth()/2),r===bt&&(y=p.getScaledWidth()),p.set({left:p.left-y,top:p.top-(v-p.fontSize*(.07+p._fontSizeFraction))/p.lineHeight,strokeWidth:f}),p}static fromObject(t){return this._fromObject(w(w({},t),{},{styles:qa(t.styles||{},t.text)}),{extraParam:"text"})}}x(Dt,"textLayoutProperties",ya),x(Dt,"cacheProperties",[...Fe,..._a]),x(Dt,"ownDefaults",xc),x(Dt,"type","Text"),x(Dt,"genericFonts",["serif","sans-serif","monospace","cursive","fantasy","system-ui","ui-serif","ui-sans-serif","ui-monospace","ui-rounded","math","emoji","fangsong"]),x(Dt,"ATTRIBUTE_NAMES",Ye.concat("x","y","dx","dy","font-family","font-style","font-weight","font-size","letter-spacing","text-decoration","text-anchor")),Ga(Dt,[class extends ma{_toSVG(){const a=this._getSVGLeftTopOffsets(),t=this._getSVGTextAndBg(a.textTop,a.textLeft);return this._wrapSVGTextAndBg(t)}toSVG(a){const t=this._createBaseSVGMarkup(this._toSVG(),{reviver:a,noStyle:!0,withShadow:!0}),e=this.path;return e?t+e._createBaseSVGMarkup(e._toSVG(),{reviver:a,withShadow:!0,additionalTransform:ks(this.calcOwnMatrix())}):t}_getSVGLeftTopOffsets(){return{textLeft:-this.width/2,textTop:-this.height/2,lineTop:this.getHeightOfLine(0)}}_wrapSVGTextAndBg(a){let{textBgRects:t,textSpans:e}=a;const s=this.getSvgTextDecoration(this);return[t.join(""),' <text xml:space="preserve" ','font-family="'.concat(this.fontFamily.replace(ld,"'"),'" '),'font-size="'.concat(this.fontSize,'" '),this.fontStyle?'font-style="'.concat(this.fontStyle,'" '):"",this.fontWeight?'font-weight="'.concat(this.fontWeight,'" '):"",s?'text-decoration="'.concat(s,'" '):"",this.direction==="rtl"?'direction="'.concat(this.direction,'" '):"",'style="',this.getSvgStyles(!0),'"',this.addPaintOrder()," >",e.join(""),`</text>
|
|
60
60
|
`]}_getSVGTextAndBg(a,t){const e=[],s=[];let i,n=a;this.backgroundColor&&s.push(...zr(this.backgroundColor,-this.width/2,-this.height/2,this.width,this.height));for(let r=0,o=this._textLines.length;r<o;r++)i=this._getLineLeftOffset(r),this.direction==="rtl"&&(i+=this.width),(this.textBackgroundColor||this.styleHas("textBackgroundColor",r))&&this._setSVGTextLineBg(s,r,t+i,n),this._setSVGTextLineText(e,r,t+i,n),n+=this.getHeightOfLine(r);return{textSpans:e,textBgRects:s}}_createTextCharSpan(a,t,e,s,i){const n=et.NUM_FRACTION_DIGITS,r=this.getSvgSpanStyles(t,a!==a.trim()||!!a.match(hd)),o=r?'style="'.concat(r,'"'):"",h=t.deltaY,l=h?' dy="'.concat(ot(h,n),'" '):"",{angle:c,renderLeft:u,renderTop:d,width:f}=i;let g="";if(u!==void 0){const p=f/2;c&&(g=' rotate="'.concat(ot(Ce(c),n),'"'));const b=ns({angle:Ce(c)});b[4]=u,b[5]=d;const m=new C(-p,0).transform(b);e=m.x,s=m.y}return'<tspan x="'.concat(ot(e,n),'" y="').concat(ot(s,n),'" ').concat(l).concat(g).concat(o,">").concat(Ya(a),"</tspan>")}_setSVGTextLineText(a,t,e,s){const i=this.getHeightOfLine(t),n=this.textAlign.includes(Te),r=this._textLines[t];let o,h,l,c,u,d="",f=0;s+=i*(1-this._fontSizeFraction)/this.lineHeight;for(let g=0,p=r.length-1;g<=p;g++)u=g===p||this.charSpacing||this.path,d+=r[g],l=this.__charBounds[t][g],f===0?(e+=l.kernedWidth-l.width,f+=l.width):f+=l.kernedWidth,n&&!u&&this._reSpaceAndTab.test(r[g])&&(u=!0),u||(o=o||this.getCompleteStyleDeclaration(t,g),h=this.getCompleteStyleDeclaration(t,g+1),u=qi(o,h,!0)),u&&(c=this._getStyleDeclaration(t,g),a.push(this._createTextCharSpan(d,c,e,s,l)),d="",o=h,this.direction==="rtl"?e-=f:e+=f,f=0)}_setSVGTextLineBg(a,t,e,s){const i=this._textLines[t],n=this.getHeightOfLine(t)/this.lineHeight;let r,o=0,h=0,l=this.getValueOfPropertyAt(t,0,"textBackgroundColor");for(let c=0;c<i.length;c++){const{left:u,width:d,kernedWidth:f}=this.__charBounds[t][c];r=this.getValueOfPropertyAt(t,c,"textBackgroundColor"),r!==l?(l&&a.push(...zr(l,e+h,s,o,n)),h=u,o=d,l=r):o+=f}r&&a.push(...zr(l,e+h,s,o,n))}_getSVGLineTopOffset(a){let t,e=0;for(t=0;t<a;t++)e+=this.getHeightOfLine(t);const s=this.getHeightOfLine(t);return{lineTop:e,offset:(this._fontSizeMult-this._fontSizeFraction)*s/(this.lineHeight*this._fontSizeMult)}}getSvgStyles(a){return"".concat(super.getSvgStyles(a)," text-decoration-thickness: ").concat(ot(this.textDecorationThickness*this.getObjectScaling().y/10,et.NUM_FRACTION_DIGITS),"%; white-space: pre;")}getSvgSpanStyles(a,t){const{fontFamily:e,strokeWidth:s,stroke:i,fill:n,fontSize:r,fontStyle:o,fontWeight:h,deltaY:l,textDecorationThickness:c,linethrough:u,overline:d,underline:f}=a,g=this.getSvgTextDecoration({underline:f??this.underline,overline:d??this.overline,linethrough:u??this.linethrough}),p=c||this.textDecorationThickness;return[i?si(Ht,i):"",s?"stroke-width: ".concat(s,"; "):"",e?"font-family: ".concat(e.includes("'")||e.includes('"')?e:"'".concat(e,"'"),"; "):"",r?"font-size: ".concat(r,"px; "):"",o?"font-style: ".concat(o,"; "):"",h?"font-weight: ".concat(h,"; "):"",g?"text-decoration: ".concat(g,"; text-decoration-thickness: ").concat(ot(p*this.getObjectScaling().y/10,et.NUM_FRACTION_DIGITS),"%; "):"",n?si(wt,n):"",l?"baseline-shift: ".concat(-l,"; "):"",t?"white-space: pre; ":""].join("")}getSvgTextDecoration(a){return["overline","underline","line-through"].filter((t=>a[t.replace("-","")])).join(" ")}}]),L.setClass(Dt),L.setSVGClass(Dt);class ud{constructor(t){x(this,"target",void 0),x(this,"__mouseDownInPlace",!1),x(this,"__dragStartFired",!1),x(this,"__isDraggingOver",!1),x(this,"__dragStartSelection",void 0),x(this,"__dragImageDisposer",void 0),x(this,"_dispose",void 0),this.target=t;const e=[this.target.on("dragenter",this.dragEnterHandler.bind(this)),this.target.on("dragover",this.dragOverHandler.bind(this)),this.target.on("dragleave",this.dragLeaveHandler.bind(this)),this.target.on("dragend",this.dragEndHandler.bind(this)),this.target.on("drop",this.dropHandler.bind(this))];this._dispose=()=>{e.forEach((s=>s())),this._dispose=void 0}}isPointerOverSelection(t){const e=this.target,s=e.getSelectionStartFromPointer(t);return e.isEditing&&s>=e.selectionStart&&s<=e.selectionEnd&&e.selectionStart<e.selectionEnd}start(t){return this.__mouseDownInPlace=this.isPointerOverSelection(t)}isActive(){return this.__mouseDownInPlace}end(t){const e=this.isActive();return e&&!this.__dragStartFired&&(this.target.setCursorByClick(t),this.target.initDelayedCursor(!0)),this.__mouseDownInPlace=!1,this.__dragStartFired=!1,this.__isDraggingOver=!1,e}getDragStartSelection(){return this.__dragStartSelection}setDragImage(t,e){var s;let{selectionStart:i,selectionEnd:n}=e;const r=this.target,o=r.canvas,h=new C(r.flipX?-1:1,r.flipY?-1:1),l=r._getCursorBoundaries(i),c=new C(l.left+l.leftOffset,l.top+l.topOffset).multiply(h).transform(r.calcTransformMatrix()),u=o.getScenePoint(t).subtract(c),d=r.getCanvasRetinaScaling(),f=r.getBoundingRect(),g=c.subtract(new C(f.left,f.top)),p=o.viewportTransform,b=g.add(u).transform(p,!0),m=r.backgroundColor,v=Pr(r.styles);r.backgroundColor="";const y={stroke:"transparent",fill:"transparent",textBackgroundColor:"transparent"};r.setSelectionStyles(y,0,i),r.setSelectionStyles(y,n,r.text.length),r.dirty=!0;const _=r.toCanvasElement({enableRetinaScaling:o.enableRetinaScaling,viewportTransform:!0});r.backgroundColor=m,r.styles=v,r.dirty=!0,en(_,{position:"fixed",left:"".concat(-_.width,"px"),border:jt,width:"".concat(_.width/d,"px"),height:"".concat(_.height/d,"px")}),this.__dragImageDisposer&&this.__dragImageDisposer(),this.__dragImageDisposer=()=>{_.remove()},ue(t.target||this.target.hiddenTextarea).body.appendChild(_),(s=t.dataTransfer)===null||s===void 0||s.setDragImage(_,b.x,b.y)}onDragStart(t){this.__dragStartFired=!0;const e=this.target,s=this.isActive();if(s&&t.dataTransfer){const i=this.__dragStartSelection={selectionStart:e.selectionStart,selectionEnd:e.selectionEnd},n=e._text.slice(i.selectionStart,i.selectionEnd).join(""),r=w({text:e.text,value:n},i);t.dataTransfer.setData("text/plain",n),t.dataTransfer.setData("application/fabric",JSON.stringify({value:n,styles:e.getSelectionStyles(i.selectionStart,i.selectionEnd,!0)})),t.dataTransfer.effectAllowed="copyMove",this.setDragImage(t,r)}return e.abortCursorAnimation(),s}canDrop(t){if(this.target.editable&&!this.target.getActiveControl()&&!t.defaultPrevented){if(this.isActive()&&this.__dragStartSelection){const e=this.target.getSelectionStartFromPointer(t),s=this.__dragStartSelection;return e<s.selectionStart||e>s.selectionEnd}return!0}return!1}targetCanDrop(t){return this.target.canDrop(t)}dragEnterHandler(t){let{e}=t;const s=this.targetCanDrop(e);!this.__isDraggingOver&&s&&(this.__isDraggingOver=!0)}dragOverHandler(t){const{e}=t,s=this.targetCanDrop(e);!this.__isDraggingOver&&s?this.__isDraggingOver=!0:this.__isDraggingOver&&!s&&(this.__isDraggingOver=!1),this.__isDraggingOver&&(e.preventDefault(),t.canDrop=!0,t.dropTarget=this.target)}dragLeaveHandler(){(this.__isDraggingOver||this.isActive())&&(this.__isDraggingOver=!1)}dropHandler(t){var e;const{e:s}=t,i=s.defaultPrevented;this.__isDraggingOver=!1,s.preventDefault();let n=(e=s.dataTransfer)===null||e===void 0?void 0:e.getData("text/plain");if(n&&!i){const r=this.target,o=r.canvas;let h=r.getSelectionStartFromPointer(s);const{styles:l}=s.dataTransfer.types.includes("application/fabric")?JSON.parse(s.dataTransfer.getData("application/fabric")):{},c=n[Math.max(0,n.length-1)],u=0;if(this.__dragStartSelection){const d=this.__dragStartSelection.selectionStart,f=this.__dragStartSelection.selectionEnd;h>d&&h<=f?h=d:h>f&&(h-=f-d),r.removeChars(d,f),delete this.__dragStartSelection}r._reNewline.test(c)&&(r._reNewline.test(r._text[h])||h===r._text.length)&&(n=n.trimEnd()),t.didDrop=!0,t.dropTarget=r,r.insertChars(n,l,h),o.setActiveObject(r),r.enterEditing(s),r.selectionStart=Math.min(h+u,r._text.length),r.selectionEnd=Math.min(r.selectionStart+n.length,r._text.length),r.hiddenTextarea.value=r.text,r._updateTextarea(),r.hiddenTextarea.focus(),r.fire(Ei,{index:h+u,action:"drop"}),o.fire("text:changed",{target:r}),o.contextTopDirty=!0,o.requestRenderAll()}}dragEndHandler(t){let{e}=t;if(this.isActive()&&this.__dragStartFired&&this.__dragStartSelection){var s;const i=this.target,n=this.target.canvas,{selectionStart:r,selectionEnd:o}=this.__dragStartSelection,h=((s=e.dataTransfer)===null||s===void 0?void 0:s.dropEffect)||jt;h===jt?(i.selectionStart=r,i.selectionEnd=o,i._updateTextarea(),i.hiddenTextarea.focus()):(i.clearContextTop(),h==="move"&&(i.removeChars(r,o),i.selectionStart=i.selectionEnd=r,i.hiddenTextarea&&(i.hiddenTextarea.value=i.text),i._updateTextarea(),i.fire(Ei,{index:r,action:"dragend"}),n.fire("text:changed",{target:i}),n.requestRenderAll()),i.exitEditing())}this.__dragImageDisposer&&this.__dragImageDisposer(),delete this.__dragImageDisposer,delete this.__dragStartSelection,this.__isDraggingOver=!1}dispose(){this._dispose&&this._dispose()}}const Ph=/[ \n\.,;!\?\-]/;class dd extends Dt{constructor(){super(...arguments),x(this,"_currentCursorOpacity",1)}initBehavior(){this._tick=this._tick.bind(this),this._onTickComplete=this._onTickComplete.bind(this),this.updateSelectionOnMouseMove=this.updateSelectionOnMouseMove.bind(this)}onDeselect(t){return this.isEditing&&this.exitEditing(),this.selected=!1,super.onDeselect(t)}_animateCursor(t){let{toValue:e,duration:s,delay:i,onComplete:n}=t;return Er({startValue:this._currentCursorOpacity,endValue:e,duration:s,delay:i,onComplete:n,abort:()=>!this.canvas||this.selectionStart!==this.selectionEnd,onChange:r=>{this._currentCursorOpacity=r,this.renderCursorOrSelection()}})}_tick(t){this._currentTickState=this._animateCursor({toValue:0,duration:this.cursorDuration/2,delay:Math.max(t||0,100),onComplete:this._onTickComplete})}_onTickComplete(){var t;(t=this._currentTickCompleteState)===null||t===void 0||t.abort(),this._currentTickCompleteState=this._animateCursor({toValue:1,duration:this.cursorDuration,onComplete:this._tick})}initDelayedCursor(t){this.abortCursorAnimation(),this._tick(t?0:this.cursorDelay)}abortCursorAnimation(){let t=!1;[this._currentTickState,this._currentTickCompleteState].forEach((e=>{e&&!e.isDone()&&(t=!0,e.abort())})),this._currentCursorOpacity=1,t&&this.clearContextTop()}restartCursorIfNeeded(){[this._currentTickState,this._currentTickCompleteState].some((t=>!t||t.isDone()))&&this.initDelayedCursor()}selectAll(){return this.selectionStart=0,this.selectionEnd=this._text.length,this._fireSelectionChanged(),this._updateTextarea(),this}cmdAll(){this.selectAll(),this.renderCursorOrSelection()}getSelectedText(){return this._text.slice(this.selectionStart,this.selectionEnd).join("")}findWordBoundaryLeft(t){let e=0,s=t-1;if(this._reSpace.test(this._text[s]))for(;this._reSpace.test(this._text[s]);)e++,s--;for(;/\S/.test(this._text[s])&&s>-1;)e++,s--;return t-e}findWordBoundaryRight(t){let e=0,s=t;if(this._reSpace.test(this._text[s]))for(;this._reSpace.test(this._text[s]);)e++,s++;for(;/\S/.test(this._text[s])&&s<this._text.length;)e++,s++;return t+e}findLineBoundaryLeft(t){let e=0,s=t-1;for(;!/\n/.test(this._text[s])&&s>-1;)e++,s--;return t-e}findLineBoundaryRight(t){let e=0,s=t;for(;!/\n/.test(this._text[s])&&s<this._text.length;)e++,s++;return t+e}searchWordBoundary(t,e){const s=this._text;let i=t>0&&this._reSpace.test(s[t])&&(e===-1||!er.test(s[t-1]))?t-1:t,n=s[i];for(;i>0&&i<s.length&&!Ph.test(n);)i+=e,n=s[i];return e===-1&&Ph.test(n)&&i++,i}selectWord(t){var e;t=(e=t)!==null&&e!==void 0?e:this.selectionStart;const s=this.searchWordBoundary(t,-1),i=Math.max(s,this.searchWordBoundary(t,1));this.selectionStart=s,this.selectionEnd=i,this._fireSelectionChanged(),this._updateTextarea(),this.renderCursorOrSelection()}selectLine(t){var e;t=(e=t)!==null&&e!==void 0?e:this.selectionStart;const s=this.findLineBoundaryLeft(t),i=this.findLineBoundaryRight(t);this.selectionStart=s,this.selectionEnd=i,this._fireSelectionChanged(),this._updateTextarea()}enterEditing(t){!this.isEditing&&this.editable&&(this.enterEditingImpl(),this.fire("editing:entered",t?{e:t}:void 0),this._fireSelectionChanged(),this.canvas&&(this.canvas.fire("text:editing:entered",{target:this,e:t}),this.canvas.requestRenderAll()))}enterEditingImpl(){this.canvas&&(this.canvas.calcOffset(),this.canvas.textEditingManager.exitTextEditing()),this.isEditing=!0,this.initHiddenTextarea(),this.hiddenTextarea.focus(),this.hiddenTextarea.value=this.text,this._updateTextarea(),this._saveEditingProps(),this._setEditingProps(),this._textBeforeEdit=this.text,this._tick()}updateSelectionOnMouseMove(t){if(this.getActiveControl())return;const e=this.hiddenTextarea;ue(e).activeElement!==e&&e.focus();const s=this.getSelectionStartFromPointer(t),i=this.selectionStart,n=this.selectionEnd;(s===this.__selectionStartOnMouseDown&&i!==n||i!==s&&n!==s)&&(s>this.__selectionStartOnMouseDown?(this.selectionStart=this.__selectionStartOnMouseDown,this.selectionEnd=s):(this.selectionStart=s,this.selectionEnd=this.__selectionStartOnMouseDown),this.selectionStart===i&&this.selectionEnd===n||(this._fireSelectionChanged(),this._updateTextarea(),this.renderCursorOrSelection()))}_setEditingProps(){this.hoverCursor="text",this.canvas&&(this.canvas.defaultCursor=this.canvas.moveCursor="text"),this.borderColor=this.editingBorderColor,this.hasControls=this.selectable=!1,this.lockMovementX=this.lockMovementY=!0}fromStringToGraphemeSelection(t,e,s){const i=s.slice(0,t),n=this.graphemeSplit(i).length;if(t===e)return{selectionStart:n,selectionEnd:n};const r=s.slice(t,e);return{selectionStart:n,selectionEnd:n+this.graphemeSplit(r).length}}fromGraphemeToStringSelection(t,e,s){const i=s.slice(0,t).join("").length;return t===e?{selectionStart:i,selectionEnd:i}:{selectionStart:i,selectionEnd:i+s.slice(t,e).join("").length}}_updateTextarea(){if(this.cursorOffsetCache={},this.hiddenTextarea){if(!this.inCompositionMode){const t=this.fromGraphemeToStringSelection(this.selectionStart,this.selectionEnd,this._text);this.hiddenTextarea.selectionStart=t.selectionStart,this.hiddenTextarea.selectionEnd=t.selectionEnd}this.updateTextareaPosition()}}updateFromTextArea(){if(!this.hiddenTextarea)return;this.cursorOffsetCache={};const t=this.hiddenTextarea;this.text=t.value,this.set("dirty",!0),this.initDimensions(),this.setCoords();const e=this.fromStringToGraphemeSelection(t.selectionStart,t.selectionEnd,t.value);this.selectionEnd=this.selectionStart=e.selectionEnd,this.inCompositionMode||(this.selectionStart=e.selectionStart),this.updateTextareaPosition()}updateTextareaPosition(){if(this.selectionStart===this.selectionEnd){const t=this._calcTextareaPosition();this.hiddenTextarea.style.left=t.left,this.hiddenTextarea.style.top=t.top}}_calcTextareaPosition(){if(!this.canvas)return{left:"1px",top:"1px"};const t=this.inCompositionMode?this.compositionStart:this.selectionStart,e=this._getCursorBoundaries(t),s=this.get2DCursorLocation(t),i=s.lineIndex,n=s.charIndex,r=this.getValueOfPropertyAt(i,n,"fontSize")*this.lineHeight,o=e.leftOffset,h=this.getCanvasRetinaScaling(),l=this.canvas.upperCanvasEl,c=l.width/h,u=l.height/h,d=c-r,f=u-r,g=new C(e.left+o,e.top+e.topOffset+r).transform(this.calcTransformMatrix()).transform(this.canvas.viewportTransform).multiply(new C(l.clientWidth/c,l.clientHeight/u));return g.x<0&&(g.x=0),g.x>d&&(g.x=d),g.y<0&&(g.y=0),g.y>f&&(g.y=f),g.x+=this.canvas._offset.left,g.y+=this.canvas._offset.top,{left:"".concat(g.x,"px"),top:"".concat(g.y,"px"),fontSize:"".concat(r,"px"),charHeight:r}}_saveEditingProps(){this._savedProps={hasControls:this.hasControls,borderColor:this.borderColor,lockMovementX:this.lockMovementX,lockMovementY:this.lockMovementY,hoverCursor:this.hoverCursor,selectable:this.selectable,defaultCursor:this.canvas&&this.canvas.defaultCursor,moveCursor:this.canvas&&this.canvas.moveCursor}}_restoreEditingProps(){this._savedProps&&(this.hoverCursor=this._savedProps.hoverCursor,this.hasControls=this._savedProps.hasControls,this.borderColor=this._savedProps.borderColor,this.selectable=this._savedProps.selectable,this.lockMovementX=this._savedProps.lockMovementX,this.lockMovementY=this._savedProps.lockMovementY,this.canvas&&(this.canvas.defaultCursor=this._savedProps.defaultCursor||this.canvas.defaultCursor,this.canvas.moveCursor=this._savedProps.moveCursor||this.canvas.moveCursor),delete this._savedProps)}_exitEditing(){const t=this.hiddenTextarea;this.selected=!1,this.isEditing=!1,t&&(t.blur&&t.blur(),t.parentNode&&t.parentNode.removeChild(t)),this.hiddenTextarea=null,this.abortCursorAnimation(),this.selectionStart!==this.selectionEnd&&this.clearContextTop()}exitEditingImpl(){this._exitEditing(),this.selectionEnd=this.selectionStart,this._restoreEditingProps(),this._forceClearCache&&(this.initDimensions(),this.setCoords())}exitEditing(){const t=this._textBeforeEdit!==this.text;return this.exitEditingImpl(),this.fire("editing:exited"),t&&this.fire(Mi),this.canvas&&(this.canvas.fire("text:editing:exited",{target:this}),t&&this.canvas.fire("object:modified",{target:this})),this}_removeExtraneousStyles(){for(const t in this.styles)this._textLines[t]||delete this.styles[t]}removeStyleFromTo(t,e){const{lineIndex:s,charIndex:i}=this.get2DCursorLocation(t,!0),{lineIndex:n,charIndex:r}=this.get2DCursorLocation(e,!0);if(s!==n){if(this.styles[s])for(let o=i;o<this._unwrappedTextLines[s].length;o++)delete this.styles[s][o];if(this.styles[n])for(let o=r;o<this._unwrappedTextLines[n].length;o++){const h=this.styles[n][o];h&&(this.styles[s]||(this.styles[s]={}),this.styles[s][i+o-r]=h)}for(let o=s+1;o<=n;o++)delete this.styles[o];this.shiftLineStyles(n,s-n)}else if(this.styles[s]){const o=this.styles[s],h=r-i;for(let l=i;l<r;l++)delete o[l];for(const l in this.styles[s]){const c=parseInt(l,10);c>=r&&(o[c-h]=o[l],delete o[l])}}}shiftLineStyles(t,e){const s=Object.assign({},this.styles);for(const i in this.styles){const n=parseInt(i,10);n>t&&(this.styles[n+e]=s[n],s[n-e]||delete this.styles[n])}}insertNewlineStyleObject(t,e,s,i){const n={},r=this._unwrappedTextLines[t].length,o=r===e;let h=!1;s||(s=1),this.shiftLineStyles(t,s);const l=this.styles[t]?this.styles[t][e===0?e:e-1]:void 0;for(const u in this.styles[t]){const d=parseInt(u,10);d>=e&&(h=!0,n[d-e]=this.styles[t][u],o&&e===0||delete this.styles[t][u])}let c=!1;for(h&&!o&&(this.styles[t+s]=n,c=!0),(c||r>e)&&s--;s>0;)i&&i[s-1]?this.styles[t+s]={0:w({},i[s-1])}:l?this.styles[t+s]={0:w({},l)}:delete this.styles[t+s],s--;this._forceClearCache=!0}insertCharStyleObject(t,e,s,i){this.styles||(this.styles={});const n=this.styles[t],r=n?w({},n):{};s||(s=1);for(const h in r){const l=parseInt(h,10);l>=e&&(n[l+s]=r[l],r[l-s]||delete n[l])}if(this._forceClearCache=!0,i){for(;s--;)Object.keys(i[s]).length&&(this.styles[t]||(this.styles[t]={}),this.styles[t][e+s]=w({},i[s]));return}if(!n)return;const o=n[e?e-1:1];for(;o&&s--;)this.styles[t][e+s]=w({},o)}insertNewStyleBlock(t,e,s){const i=this.get2DCursorLocation(e,!0),n=[0];let r,o=0;for(let h=0;h<t.length;h++)t[h]===`
|
|
61
61
|
`?(o++,n[o]=0):n[o]++;for(n[0]>0&&(this.insertCharStyleObject(i.lineIndex,i.charIndex,n[0],s),s=s&&s.slice(n[0]+1)),o&&this.insertNewlineStyleObject(i.lineIndex,i.charIndex+n[0],o),r=1;r<o;r++)n[r]>0?this.insertCharStyleObject(i.lineIndex+r,0,n[r],s):s&&this.styles[i.lineIndex+r]&&s[0]&&(this.styles[i.lineIndex+r][0]=s[0]),s=s&&s.slice(n[r]+1);n[r]>0&&this.insertCharStyleObject(i.lineIndex+r,0,n[r],s)}removeChars(t){let e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:t+1;this.removeStyleFromTo(t,e),this._text.splice(t,e-t),this.text=this._text.join(""),this.set("dirty",!0),this.initDimensions(),this.setCoords(),this._removeExtraneousStyles()}insertChars(t,e,s){let i=arguments.length>3&&arguments[3]!==void 0?arguments[3]:s;i>s&&this.removeStyleFromTo(s,i);const n=this.graphemeSplit(t);this.insertNewStyleBlock(n,s,e),this._text=[...this._text.slice(0,s),...n,...this._text.slice(i)],this.text=this._text.join(""),this.set("dirty",!0),this.initDimensions(),this.setCoords(),this._removeExtraneousStyles()}setSelectionStartEndWithShift(t,e,s){s<=t?(e===t?this._selectionDirection=it:this._selectionDirection===bt&&(this._selectionDirection=it,this.selectionEnd=t),this.selectionStart=s):s>t&&s<e?this._selectionDirection===bt?this.selectionEnd=s:this.selectionStart=s:(e===t?this._selectionDirection=bt:this._selectionDirection===it&&(this._selectionDirection=bt,this.selectionStart=e),this.selectionEnd=s)}}class fd extends dd{initHiddenTextarea(){const t=this.canvas&&ue(this.canvas.getElement())||xs(),e=t.createElement("textarea");Object.entries({autocapitalize:"off",autocorrect:"off",autocomplete:"off",spellcheck:"false","data-fabric":"textarea",wrap:"off",name:"fabricTextarea"}).map((r=>{let[o,h]=r;return e.setAttribute(o,h)}));const{top:s,left:i,fontSize:n}=this._calcTextareaPosition();e.style.cssText="position: absolute; top: ".concat(s,"; left: ").concat(i,"; z-index: -999; opacity: 0; width: 1px; height: 1px; font-size: 1px; padding-top: ").concat(n,";"),(this.hiddenTextareaContainer||t.body).appendChild(e),Object.entries({blur:"blur",keydown:"onKeyDown",keyup:"onKeyUp",input:"onInput",copy:"copy",cut:"copy",paste:"paste",compositionstart:"onCompositionStart",compositionupdate:"onCompositionUpdate",compositionend:"onCompositionEnd"}).map((r=>{let[o,h]=r;return e.addEventListener(o,this[h].bind(this))})),this.hiddenTextarea=e}blur(){this.abortCursorAnimation()}onKeyDown(t){if(!this.isEditing)return;const e=this.direction==="rtl"?this.keysMapRtl:this.keysMap;if(t.keyCode in e)this[e[t.keyCode]](t);else{if(!(t.keyCode in this.ctrlKeysMapDown)||!t.ctrlKey&&!t.metaKey)return;this[this.ctrlKeysMapDown[t.keyCode]](t)}t.stopImmediatePropagation(),t.preventDefault(),t.keyCode>=33&&t.keyCode<=40?(this.inCompositionMode=!1,this.clearContextTop(),this.renderCursorOrSelection()):this.canvas&&this.canvas.requestRenderAll()}onKeyUp(t){!this.isEditing||this._copyDone||this.inCompositionMode?this._copyDone=!1:t.keyCode in this.ctrlKeysMapUp&&(t.ctrlKey||t.metaKey)&&(this[this.ctrlKeysMapUp[t.keyCode]](t),t.stopImmediatePropagation(),t.preventDefault(),this.canvas&&this.canvas.requestRenderAll())}onInput(t){const e=this.fromPaste,{value:s,selectionStart:i,selectionEnd:n}=this.hiddenTextarea;if(this.fromPaste=!1,t&&t.stopPropagation(),!this.isEditing)return;const r=()=>{this.updateFromTextArea(),this.fire(Ei),this.canvas&&(this.canvas.fire("text:changed",{target:this}),this.canvas.requestRenderAll())};if(this.hiddenTextarea.value==="")return this.styles={},void r();const o=this._splitTextIntoLines(s).graphemeText,h=this._text.length,l=o.length,c=this.selectionStart,u=this.selectionEnd,d=c!==u;let f,g,p,b,m=l-h;const v=this.fromStringToGraphemeSelection(i,n,s),y=c>v.selectionStart;d?(g=this._text.slice(c,u),m+=u-c):l<h&&(g=y?this._text.slice(u+m,u):this._text.slice(c,c-m));const _=o.slice(v.selectionEnd-m,v.selectionEnd);if(g&&g.length&&(_.length&&(f=this.getSelectionStyles(c,c+1,!1),f=_.map((()=>f[0]))),d?(p=c,b=u):y?(p=u-g.length,b=u):(p=u,b=u+g.length),this.removeStyleFromTo(p,b)),_.length){const{copyPasteData:S}=xe();e&&_.join("")===S.copiedText&&!et.disableStyleCopyPaste&&(f=S.copiedTextStyle),this.insertNewStyleBlock(_,c,f)}r()}onCompositionStart(){this.inCompositionMode=!0}onCompositionEnd(){this.inCompositionMode=!1}onCompositionUpdate(t){let{target:e}=t;const{selectionStart:s,selectionEnd:i}=e;this.compositionStart=s,this.compositionEnd=i,this.updateTextareaPosition()}copy(){if(this.selectionStart===this.selectionEnd)return;const{copyPasteData:t}=xe();t.copiedText=this.getSelectedText(),et.disableStyleCopyPaste?t.copiedTextStyle=void 0:t.copiedTextStyle=this.getSelectionStyles(this.selectionStart,this.selectionEnd,!0),this._copyDone=!0}paste(){this.fromPaste=!0}_getWidthBeforeCursor(t,e){let s,i=this._getLineLeftOffset(t);return e>0&&(s=this.__charBounds[t][e-1],i+=s.left+s.width),i}getDownCursorOffset(t,e){const s=this._getSelectionForOffset(t,e),i=this.get2DCursorLocation(s),n=i.lineIndex;if(n===this._textLines.length-1||t.metaKey||t.keyCode===34)return this._text.length-s;const r=i.charIndex,o=this._getWidthBeforeCursor(n,r),h=this._getIndexOnLine(n+1,o);return this._textLines[n].slice(r).length+h+1+this.missingNewlineOffset(n)}_getSelectionForOffset(t,e){return t.shiftKey&&this.selectionStart!==this.selectionEnd&&e?this.selectionEnd:this.selectionStart}getUpCursorOffset(t,e){const s=this._getSelectionForOffset(t,e),i=this.get2DCursorLocation(s),n=i.lineIndex;if(n===0||t.metaKey||t.keyCode===33)return-s;const r=i.charIndex,o=this._getWidthBeforeCursor(n,r),h=this._getIndexOnLine(n-1,o),l=this._textLines[n].slice(0,r),c=this.missingNewlineOffset(n-1);return-this._textLines[n-1].length+h-l.length+(1-c)}_getIndexOnLine(t,e){const s=this._textLines[t];let i,n,r=this._getLineLeftOffset(t),o=0;for(let h=0,l=s.length;h<l;h++)if(i=this.__charBounds[t][h].width,r+=i,r>e){n=!0;const c=r-i,u=r,d=Math.abs(c-e);o=Math.abs(u-e)<d?h:h-1;break}return n||(o=s.length-1),o}moveCursorDown(t){this.selectionStart>=this._text.length&&this.selectionEnd>=this._text.length||this._moveCursorUpOrDown("Down",t)}moveCursorUp(t){this.selectionStart===0&&this.selectionEnd===0||this._moveCursorUpOrDown("Up",t)}_moveCursorUpOrDown(t,e){const s=this["get".concat(t,"CursorOffset")](e,this._selectionDirection===bt);if(e.shiftKey?this.moveCursorWithShift(s):this.moveCursorWithoutShift(s),s!==0){const i=this.text.length;this.selectionStart=ls(0,this.selectionStart,i),this.selectionEnd=ls(0,this.selectionEnd,i),this.abortCursorAnimation(),this.initDelayedCursor(),this._fireSelectionChanged(),this._updateTextarea()}}moveCursorWithShift(t){const e=this._selectionDirection===it?this.selectionStart+t:this.selectionEnd+t;return this.setSelectionStartEndWithShift(this.selectionStart,this.selectionEnd,e),t!==0}moveCursorWithoutShift(t){return t<0?(this.selectionStart+=t,this.selectionEnd=this.selectionStart):(this.selectionEnd+=t,this.selectionStart=this.selectionEnd),t!==0}moveCursorLeft(t){this.selectionStart===0&&this.selectionEnd===0||this._moveCursorLeftOrRight("Left",t)}_move(t,e,s){let i;if(t.altKey)i=this["findWordBoundary".concat(s)](this[e]);else{if(!t.metaKey&&t.keyCode!==35&&t.keyCode!==36)return this[e]+=s==="Left"?-1:1,!0;i=this["findLineBoundary".concat(s)](this[e])}return i!==void 0&&this[e]!==i&&(this[e]=i,!0)}_moveLeft(t,e){return this._move(t,e,"Left")}_moveRight(t,e){return this._move(t,e,"Right")}moveCursorLeftWithoutShift(t){let e=!0;return this._selectionDirection=it,this.selectionEnd===this.selectionStart&&this.selectionStart!==0&&(e=this._moveLeft(t,"selectionStart")),this.selectionEnd=this.selectionStart,e}moveCursorLeftWithShift(t){return this._selectionDirection===bt&&this.selectionStart!==this.selectionEnd?this._moveLeft(t,"selectionEnd"):this.selectionStart!==0?(this._selectionDirection=it,this._moveLeft(t,"selectionStart")):void 0}moveCursorRight(t){this.selectionStart>=this._text.length&&this.selectionEnd>=this._text.length||this._moveCursorLeftOrRight("Right",t)}_moveCursorLeftOrRight(t,e){const s="moveCursor".concat(t).concat(e.shiftKey?"WithShift":"WithoutShift");this._currentCursorOpacity=1,this[s](e)&&(this.abortCursorAnimation(),this.initDelayedCursor(),this._fireSelectionChanged(),this._updateTextarea())}moveCursorRightWithShift(t){return this._selectionDirection===it&&this.selectionStart!==this.selectionEnd?this._moveRight(t,"selectionStart"):this.selectionEnd!==this._text.length?(this._selectionDirection=bt,this._moveRight(t,"selectionEnd")):void 0}moveCursorRightWithoutShift(t){let e=!0;return this._selectionDirection=bt,this.selectionStart===this.selectionEnd?(e=this._moveRight(t,"selectionStart"),this.selectionEnd=this.selectionStart):this.selectionStart=this.selectionEnd,e}}const Oh=a=>!!a.button;class gd extends fd{constructor(){super(...arguments),x(this,"draggableTextDelegate",void 0)}initBehavior(){this.on("mousedown",this._mouseDownHandler),this.on("mouseup",this.mouseUpHandler),this.on("mousedblclick",this.doubleClickHandler),this.on("mousetripleclick",this.tripleClickHandler),this.draggableTextDelegate=new ud(this),super.initBehavior()}shouldStartDragging(){return this.draggableTextDelegate.isActive()}onDragStart(t){return this.draggableTextDelegate.onDragStart(t)}canDrop(t){return this.draggableTextDelegate.canDrop(t)}doubleClickHandler(t){this.isEditing&&(this.selectWord(this.getSelectionStartFromPointer(t.e)),this.renderCursorOrSelection())}tripleClickHandler(t){this.isEditing&&(this.selectLine(this.getSelectionStartFromPointer(t.e)),this.renderCursorOrSelection())}_mouseDownHandler(t){let{e,alreadySelected:s}=t;this.canvas&&this.editable&&!Oh(e)&&!this.getActiveControl()&&(this.draggableTextDelegate.start(e)||(this.canvas.textEditingManager.register(this),s&&(this.inCompositionMode=!1,this.setCursorByClick(e)),this.isEditing&&(this.__selectionStartOnMouseDown=this.selectionStart,this.selectionStart===this.selectionEnd&&this.abortCursorAnimation(),this.renderCursorOrSelection()),this.selected||(this.selected=s||this.isEditing)))}mouseUpHandler(t){let{e,transform:s}=t;const i=this.draggableTextDelegate.end(e);if(this.canvas){this.canvas.textEditingManager.unregister(this);const n=this.canvas._activeObject;if(n&&n!==this)return}!this.editable||this.group&&!this.group.interactive||s&&s.actionPerformed||Oh(e)||i||this.selected&&!this.getActiveControl()&&(this.enterEditing(e),this.selectionStart===this.selectionEnd?this.initDelayedCursor(!0):this.renderCursorOrSelection())}setCursorByClick(t){const e=this.getSelectionStartFromPointer(t),s=this.selectionStart,i=this.selectionEnd;t.shiftKey?this.setSelectionStartEndWithShift(s,i,e):(this.selectionStart=e,this.selectionEnd=e),this.isEditing&&(this._fireSelectionChanged(),this._updateTextarea())}getSelectionStartFromPointer(t){const e=this.canvas.getScenePoint(t).transform($t(this.calcTransformMatrix())).add(new C(-this._getLeftOffset(),-this._getTopOffset()));let s=0,i=0,n=0;for(let l=0;l<this._textLines.length&&s<=e.y;l++)s+=this.getHeightOfLine(l),n=l,l>0&&(i+=this._textLines[l-1].length+this.missingNewlineOffset(l-1));let r=Math.abs(this._getLineLeftOffset(n));const o=this._textLines[n].length,h=this.__charBounds[n];for(let l=0;l<o;l++){const c=r+h[l].kernedWidth;if(e.x<=c){Math.abs(e.x-c)<=Math.abs(e.x-r)&&i++;break}r=c,i++}return Math.min(this.flipX?o-i:i,this._text.length)}}const on="moveCursorUp",an="moveCursorDown",hn="moveCursorLeft",ln="moveCursorRight",cn="exitEditing",Dh=(a,t)=>{const e=t.getRetinaScaling();a.setTransform(e,0,0,e,0,0);const s=t.viewportTransform;a.transform(s[0],s[1],s[2],s[3],s[4],s[5])},pd=w({selectionStart:0,selectionEnd:0,selectionColor:"rgba(17,119,255,0.3)",isEditing:!1,editable:!0,editingBorderColor:"rgba(102,153,255,0.25)",cursorWidth:2,cursorColor:"",cursorDelay:1e3,cursorDuration:600,caching:!0,hiddenTextareaContainer:null,keysMap:{9:cn,27:cn,33:on,34:an,35:ln,36:hn,37:hn,38:on,39:ln,40:an},keysMapRtl:{9:cn,27:cn,33:on,34:an,35:hn,36:ln,37:ln,38:on,39:hn,40:an},ctrlKeysMapDown:{65:"cmdAll"},ctrlKeysMapUp:{67:"copy",88:"cut"}},{_selectionDirection:null,_reSpace:/\s|\r?\n/,inCompositionMode:!1});class ze extends gd{static getDefaults(){return w(w({},super.getDefaults()),ze.ownDefaults)}get type(){const t=super.type;return t==="itext"?"i-text":t}constructor(t,e){super(t,w(w({},ze.ownDefaults),e)),this.initBehavior()}_set(t,e){return this.isEditing&&this._savedProps&&t in this._savedProps?(this._savedProps[t]=e,this):(t==="canvas"&&(this.canvas instanceof jr&&this.canvas.textEditingManager.remove(this),e instanceof jr&&e.textEditingManager.add(this)),super._set(t,e))}setSelectionStart(t){t=Math.max(t,0),this._updateAndFire("selectionStart",t)}setSelectionEnd(t){t=Math.min(t,this.text.length),this._updateAndFire("selectionEnd",t)}_updateAndFire(t,e){this[t]!==e&&(this._fireSelectionChanged(),this[t]=e),this._updateTextarea()}_fireSelectionChanged(){this.fire("selection:changed"),this.canvas&&this.canvas.fire("text:selection:changed",{target:this})}initDimensions(){this.isEditing&&this.initDelayedCursor(),super.initDimensions()}getSelectionStyles(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:this.selectionStart||0,e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:this.selectionEnd,s=arguments.length>2?arguments[2]:void 0;return super.getSelectionStyles(t,e,s)}setSelectionStyles(t){let e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:this.selectionStart||0,s=arguments.length>2&&arguments[2]!==void 0?arguments[2]:this.selectionEnd;return super.setSelectionStyles(t,e,s)}get2DCursorLocation(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:this.selectionStart,e=arguments.length>1?arguments[1]:void 0;return super.get2DCursorLocation(t,e)}render(t){super.render(t),this.cursorOffsetCache={},this.renderCursorOrSelection()}toCanvasElement(t){const e=this.isEditing;this.isEditing=!1;const s=super.toCanvasElement(t);return this.isEditing=e,s}renderCursorOrSelection(){if(!this.isEditing||!this.canvas)return;const t=this.clearContextTop(!0);if(!t)return;const e=this._getCursorBoundaries(),s=this.findAncestorsWithClipPath(),i=s.length>0;let n,r=t;if(i){n=te(t.canvas),r=n.getContext("2d"),Dh(r,this.canvas);const o=this.calcTransformMatrix();r.transform(o[0],o[1],o[2],o[3],o[4],o[5])}if(this.selectionStart!==this.selectionEnd||this.inCompositionMode?this.renderSelection(r,e):this.renderCursor(r,e),i)for(const o of s){const h=o.clipPath,l=te(t.canvas),c=l.getContext("2d");if(Dh(c,this.canvas),!h.absolutePositioned){const u=o.calcTransformMatrix();c.transform(u[0],u[1],u[2],u[3],u[4],u[5])}h.transform(c),h.drawObject(c,!0,{}),this.drawClipPathOnCache(r,h,l)}i&&(t.setTransform(1,0,0,1,0,0),t.drawImage(n,0,0)),this.canvas.contextTopDirty=!0,t.restore()}findAncestorsWithClipPath(){const t=[];let e=this;for(;e;)e.clipPath&&t.push(e),e=e.parent;return t}_getCursorBoundaries(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:this.selectionStart,e=arguments.length>1?arguments[1]:void 0;const s=this._getLeftOffset(),i=this._getTopOffset(),n=this._getCursorBoundariesOffsets(t,e);return{left:s,top:i,leftOffset:n.left,topOffset:n.top}}_getCursorBoundariesOffsets(t,e){return e?this.__getCursorBoundariesOffsets(t):this.cursorOffsetCache&&"top"in this.cursorOffsetCache?this.cursorOffsetCache:this.cursorOffsetCache=this.__getCursorBoundariesOffsets(t)}__getCursorBoundariesOffsets(t){let e=0,s=0;const{charIndex:i,lineIndex:n}=this.get2DCursorLocation(t);for(let l=0;l<n;l++)e+=this.getHeightOfLine(l);const r=this._getLineLeftOffset(n),o=this.__charBounds[n][i];o&&(s=o.left),this.charSpacing!==0&&i===this._textLines[n].length&&(s-=this._getWidthOfCharSpacing());const h={top:e,left:r+(s>0?s:0)};return this.direction==="rtl"&&(this.textAlign===bt||this.textAlign===Te||this.textAlign===ii?h.left*=-1:this.textAlign===it||this.textAlign===Hi?h.left=r-(s>0?s:0):this.textAlign!==$&&this.textAlign!==ni||(h.left=r-(s>0?s:0))),h}renderCursorAt(t){this._renderCursor(this.canvas.contextTop,this._getCursorBoundaries(t,!0),t)}renderCursor(t,e){this._renderCursor(t,e,this.selectionStart)}getCursorRenderingData(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:this.selectionStart,e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:this._getCursorBoundaries(t);const s=this.get2DCursorLocation(t),i=s.lineIndex,n=s.charIndex>0?s.charIndex-1:0,r=this.getValueOfPropertyAt(i,n,"fontSize"),o=this.getObjectScaling().x*this.canvas.getZoom(),h=this.cursorWidth/o,l=this.getValueOfPropertyAt(i,n,"deltaY"),c=e.topOffset+(1-this._fontSizeFraction)*this.getHeightOfLine(i)/this.lineHeight-r*(1-this._fontSizeFraction);return{color:this.cursorColor||this.getValueOfPropertyAt(i,n,"fill"),opacity:this._currentCursorOpacity,left:e.left+e.leftOffset-h/2,top:c+e.top+l,width:h,height:r}}_renderCursor(t,e,s){const{color:i,opacity:n,left:r,top:o,width:h,height:l}=this.getCursorRenderingData(s,e);t.fillStyle=i,t.globalAlpha=n,t.fillRect(r,o,h,l)}renderSelection(t,e){const s={selectionStart:this.inCompositionMode?this.hiddenTextarea.selectionStart:this.selectionStart,selectionEnd:this.inCompositionMode?this.hiddenTextarea.selectionEnd:this.selectionEnd};this._renderSelection(t,s,e)}renderDragSourceEffect(){const t=this.draggableTextDelegate.getDragStartSelection();this._renderSelection(this.canvas.contextTop,t,this._getCursorBoundaries(t.selectionStart,!0))}renderDropTargetEffect(t){const e=this.getSelectionStartFromPointer(t);this.renderCursorAt(e)}_renderSelection(t,e,s){const i=e.selectionStart,n=e.selectionEnd,r=this.textAlign.includes(Te),o=this.get2DCursorLocation(i),h=this.get2DCursorLocation(n),l=o.lineIndex,c=h.lineIndex,u=o.charIndex<0?0:o.charIndex,d=h.charIndex<0?0:h.charIndex;for(let f=l;f<=c;f++){const g=this._getLineLeftOffset(f)||0;let p=this.getHeightOfLine(f),b=0,m=0,v=0;if(f===l&&(m=this.__charBounds[l][u].left),f>=l&&f<c)v=r&&!this.isEndOfWrapping(f)?this.width:this.getLineWidth(f)||5;else if(f===c)if(d===0)v=this.__charBounds[c][d].left;else{const T=this._getWidthOfCharSpacing();v=this.__charBounds[c][d-1].left+this.__charBounds[c][d-1].width-T}b=p,(this.lineHeight<1||f===c&&this.lineHeight>1)&&(p/=this.lineHeight);let y=s.left+g+m,_=p,S=0;const A=v-m;this.inCompositionMode?(t.fillStyle=this.compositionColor||"black",_=1,S=p):t.fillStyle=this.selectionColor,this.direction==="rtl"&&(this.textAlign===bt||this.textAlign===Te||this.textAlign===ii?y=this.width-y-A:this.textAlign===it||this.textAlign===Hi?y=s.left+g-v:this.textAlign!==$&&this.textAlign!==ni||(y=s.left+g-v)),t.fillRect(y,s.top+s.topOffset+S,A,_),s.topOffset+=b}}getCurrentCharFontSize(){const t=this._getCurrentCharIndex();return this.getValueOfPropertyAt(t.l,t.c,"fontSize")}getCurrentCharColor(){const t=this._getCurrentCharIndex();return this.getValueOfPropertyAt(t.l,t.c,wt)}_getCurrentCharIndex(){const t=this.get2DCursorLocation(this.selectionStart,!0),e=t.charIndex>0?t.charIndex-1:0;return{l:t.lineIndex,c:e}}dispose(){this.exitEditingImpl(),this.draggableTextDelegate.dispose(),super.dispose()}}x(ze,"ownDefaults",pd),x(ze,"type","IText"),L.setClass(ze),L.setClass(ze,"i-text");class fs extends ze{static getDefaults(){return w(w({},super.getDefaults()),fs.ownDefaults)}constructor(t,e){super(t,w(w({},fs.ownDefaults),e))}static createControls(){return{controls:eu()}}initDimensions(){this.initialized&&(this.isEditing&&this.initDelayedCursor(),this._clearCache(),this.dynamicMinWidth=0,this._styleMap=this._generateStyleMap(this._splitText()),this.dynamicMinWidth>this.width&&this._set("width",this.dynamicMinWidth),this.textAlign.includes(Te)&&this.enlargeSpaces(),this.height=this.calcTextHeight())}_generateStyleMap(t){let e=0,s=0,i=0;const n={};for(let r=0;r<t.graphemeLines.length;r++)t.graphemeText[i]===`
|
|
@@ -517,4 +517,4 @@ void main() {
|
|
|
517
517
|
`)}`,this.#d();const u=new Range;let d=l.reduce((f,g)=>f+g.length,0);for(const{firstChild:f}of this.editorDiv.childNodes)if(f.nodeType===Node.TEXT_NODE){const g=f.nodeValue.length;if(d<=g){u.setStart(f,d),u.setEnd(f,d);break}d-=g}n.removeAllRanges(),n.addRange(u)}#d(){if(this.editorDiv.replaceChildren(),!!this.#e)for(const t of this.#e.split(`
|
|
518
518
|
`)){const e=document.createElement("div");e.append(t?document.createTextNode(t):document.createElement("br")),this.editorDiv.append(e)}}#u(){return this.#e.replaceAll(" "," ")}static#f(t){return t.replaceAll(" "," ")}get contentDiv(){return this.editorDiv}static async deserialize(t,e,s){let i=null;if(t instanceof Dl){const{data:{defaultAppearanceData:{fontSize:r,fontColor:o},rect:h,rotation:l,id:c,popupRef:u},textContent:d,textPosition:f,parent:{page:{pageNumber:g}}}=t;if(!d||d.length===0)return null;i=t={annotationType:q.FREETEXT,color:Array.from(o),fontSize:r,value:d.join(`
|
|
519
519
|
`),position:f,pageIndex:g-1,rect:h.slice(0),rotation:l,id:c,deleted:!1,popupRef:u}}const n=await super.deserialize(t,e,s);return n.#r=t.fontSize,n.#t=G.makeHexColor(...t.color),n.#e=Et.#f(t.value),n.annotationElementId=t.id||null,n._initialData=i,n}serialize(t=!1){if(this.isEmpty())return null;if(this.deleted)return this.serializeDeleted();const e=Et._internalPadding*this.parentScale,s=this.getRect(e,e),i=W._colorManager.convert(this.isAttachedToDOM?getComputedStyle(this.editorDiv).color:this.#t),n={annotationType:q.FREETEXT,color:i,fontSize:this.#r,value:this.#u(),pageIndex:this.pageIndex,rect:s,rotation:this.rotation,structTreeParentId:this._structTreeParentId};return t?n:this.annotationElementId&&!this.#o(n)?null:(n.id=this.annotationElementId,n)}#o(t){const{value:e,fontSize:s,color:i,pageIndex:n}=this._initialData;return this._hasBeenMoved||t.value!==e||t.fontSize!==s||t.color.some((r,o)=>r!==i[o])||t.pageIndex!==n}renderAnnotationElement(t){const e=super.renderAnnotationElement(t);if(this.deleted)return e;const{style:s}=e;s.fontSize=`calc(${this.#r}px * var(--scale-factor))`,s.color=this.#t,e.replaceChildren();for(const n of this.#e.split(`
|
|
520
|
-
`)){const r=document.createElement("div");r.append(n?document.createTextNode(n):document.createElement("br")),e.append(r)}const i=Et._internalPadding*this.parentScale;return t.updateEdited({rect:this.getRect(i,i),popupContent:this.#e}),e}resetAnnotationElement(t){super.resetAnnotationElement(t),t.resetEdited()}}class j{static PRECISION=1e-4;toSVGPath(){at("Abstract method `toSVGPath` must be implemented.")}get box(){at("Abstract getter `box` must be implemented.")}serialize(t,e){at("Abstract method `serialize` must be implemented.")}static _rescale(t,e,s,i,n,r){r||=new Float32Array(t.length);for(let o=0,h=t.length;o<h;o+=2)r[o]=e+t[o]*i,r[o+1]=s+t[o+1]*n;return r}static _rescaleAndSwap(t,e,s,i,n,r){r||=new Float32Array(t.length);for(let o=0,h=t.length;o<h;o+=2)r[o]=e+t[o+1]*i,r[o+1]=s+t[o]*n;return r}static _translate(t,e,s,i){i||=new Float32Array(t.length);for(let n=0,r=t.length;n<r;n+=2)i[n]=e+t[n],i[n+1]=s+t[n+1];return i}static svgRound(t){return Math.round(t*1e4)}static _normalizePoint(t,e,s,i,n){switch(n){case 90:return[1-e/s,t/i];case 180:return[1-t/s,1-e/i];case 270:return[e/s,1-t/i];default:return[t/s,e/i]}}static _normalizePagePoint(t,e,s){switch(s){case 90:return[1-e,t];case 180:return[1-t,1-e];case 270:return[e,1-t];default:return[t,e]}}static createBezierPoints(t,e,s,i,n,r){return[(t+5*s)/6,(e+5*i)/6,(5*s+n)/6,(5*i+r)/6,(s+n)/2,(i+r)/2]}}class ys{#t;#e=[];#s;#i;#r=[];#n=new Float32Array(18);#h;#a;#c;#l;#d;#u;#f=[];static#o=8;static#g=2;static#m=ys.#o+ys.#g;constructor({x:t,y:e},s,i,n,r,o=0){this.#t=s,this.#u=n*i,this.#i=r,this.#n.set([NaN,NaN,NaN,NaN,t,e],6),this.#s=o,this.#l=ys.#o*i,this.#c=ys.#m*i,this.#d=i,this.#f.push(t,e)}isEmpty(){return isNaN(this.#n[8])}#p(){const t=this.#n.subarray(4,6),e=this.#n.subarray(16,18),[s,i,n,r]=this.#t;return[(this.#h+(t[0]-e[0])/2-s)/n,(this.#a+(t[1]-e[1])/2-i)/r,(this.#h+(e[0]-t[0])/2-s)/n,(this.#a+(e[1]-t[1])/2-i)/r]}add({x:t,y:e}){this.#h=t,this.#a=e;const[s,i,n,r]=this.#t;let[o,h,l,c]=this.#n.subarray(8,12);const u=t-l,d=e-c,f=Math.hypot(u,d);if(f<this.#c)return!1;const g=f-this.#l,p=g/f,b=p*u,m=p*d;let v=o,y=h;o=l,h=c,l+=b,c+=m,this.#f?.push(t,e);const _=-m/g,S=b/g,A=_*this.#u,T=S*this.#u;return this.#n.set(this.#n.subarray(2,8),0),this.#n.set([l+A,c+T],4),this.#n.set(this.#n.subarray(14,18),12),this.#n.set([l-A,c-T],16),isNaN(this.#n[6])?(this.#r.length===0&&(this.#n.set([o+A,h+T],2),this.#r.push(NaN,NaN,NaN,NaN,(o+A-s)/n,(h+T-i)/r),this.#n.set([o-A,h-T],14),this.#e.push(NaN,NaN,NaN,NaN,(o-A-s)/n,(h-T-i)/r)),this.#n.set([v,y,o,h,l,c],6),!this.isEmpty()):(this.#n.set([v,y,o,h,l,c],6),Math.abs(Math.atan2(y-h,v-o)-Math.atan2(m,b))<Math.PI/2?([o,h,l,c]=this.#n.subarray(2,6),this.#r.push(NaN,NaN,NaN,NaN,((o+l)/2-s)/n,((h+c)/2-i)/r),[o,h,v,y]=this.#n.subarray(14,18),this.#e.push(NaN,NaN,NaN,NaN,((v+o)/2-s)/n,((y+h)/2-i)/r),!0):([v,y,o,h,l,c]=this.#n.subarray(0,6),this.#r.push(((v+5*o)/6-s)/n,((y+5*h)/6-i)/r,((5*o+l)/6-s)/n,((5*h+c)/6-i)/r,((o+l)/2-s)/n,((h+c)/2-i)/r),[l,c,o,h,v,y]=this.#n.subarray(12,18),this.#e.push(((v+5*o)/6-s)/n,((y+5*h)/6-i)/r,((5*o+l)/6-s)/n,((5*h+c)/6-i)/r,((o+l)/2-s)/n,((h+c)/2-i)/r),!0))}toSVGPath(){if(this.isEmpty())return"";const t=this.#r,e=this.#e;if(isNaN(this.#n[6])&&!this.isEmpty())return this.#b();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]}`);this.#v(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 this.#_(s),s.join(" ")}#b(){const[t,e,s,i]=this.#t,[n,r,o,h]=this.#p();return`M${(this.#n[2]-t)/s} ${(this.#n[3]-e)/i} L${(this.#n[4]-t)/s} ${(this.#n[5]-e)/i} L${n} ${r} L${o} ${h} L${(this.#n[16]-t)/s} ${(this.#n[17]-e)/i} L${(this.#n[14]-t)/s} ${(this.#n[15]-e)/i} Z`}#_(t){const e=this.#e;t.push(`L${e[4]} ${e[5]} Z`)}#v(t){const[e,s,i,n]=this.#t,r=this.#n.subarray(4,6),o=this.#n.subarray(16,18),[h,l,c,u]=this.#p();t.push(`L${(r[0]-e)/i} ${(r[1]-s)/n} L${h} ${l} L${c} ${u} L${(o[0]-e)/i} ${(o[1]-s)/n}`)}newFreeDrawOutline(t,e,s,i,n,r){return new Il(t,e,s,i,n,r)}getOutlines(){const t=this.#r,e=this.#e,s=this.#n,[i,n,r,o]=this.#t,h=new Float32Array((this.#f?.length??0)+2);for(let u=0,d=h.length-2;u<d;u+=2)h[u]=(this.#f[u]-i)/r,h[u+1]=(this.#f[u+1]-n)/o;if(h[h.length-2]=(this.#h-i)/r,h[h.length-1]=(this.#a-n)/o,isNaN(s[6])&&!this.isEmpty())return this.#w(h);const l=new Float32Array(this.#r.length+24+this.#e.length);let c=t.length;for(let u=0;u<c;u+=2){if(isNaN(t[u])){l[u]=l[u+1]=NaN;continue}l[u]=t[u],l[u+1]=t[u+1]}c=this.#A(l,c);for(let u=e.length-6;u>=6;u-=6)for(let d=0;d<6;d+=2){if(isNaN(e[u+d])){l[c]=l[c+1]=NaN,c+=2;continue}l[c]=e[u+d],l[c+1]=e[u+d+1],c+=2}return this.#S(l,c),this.newFreeDrawOutline(l,h,this.#t,this.#d,this.#s,this.#i)}#w(t){const e=this.#n,[s,i,n,r]=this.#t,[o,h,l,c]=this.#p(),u=new Float32Array(36);return u.set([NaN,NaN,NaN,NaN,(e[2]-s)/n,(e[3]-i)/r,NaN,NaN,NaN,NaN,(e[4]-s)/n,(e[5]-i)/r,NaN,NaN,NaN,NaN,o,h,NaN,NaN,NaN,NaN,l,c,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(u,t,this.#t,this.#d,this.#s,this.#i)}#S(t,e){const s=this.#e;return t.set([NaN,NaN,NaN,NaN,s[4],s[5]],e),e+=6}#A(t,e){const s=this.#n.subarray(4,6),i=this.#n.subarray(16,18),[n,r,o,h]=this.#t,[l,c,u,d]=this.#p();return t.set([NaN,NaN,NaN,NaN,(s[0]-n)/o,(s[1]-r)/h,NaN,NaN,NaN,NaN,l,c,NaN,NaN,NaN,NaN,u,d,NaN,NaN,NaN,NaN,(i[0]-n)/o,(i[1]-r)/h],e),e+=24}}class Il extends j{#t;#e=new Float32Array(4);#s;#i;#r;#n;#h;constructor(t,e,s,i,n,r){super(),this.#h=t,this.#r=e,this.#t=s,this.#n=i,this.#s=n,this.#i=r,this.lastPoint=[NaN,NaN],this.#a(r);const[o,h,l,c]=this.#e;for(let u=0,d=t.length;u<d;u+=2)t[u]=(t[u]-o)/l,t[u+1]=(t[u+1]-h)/c;for(let u=0,d=e.length;u<d;u+=2)e[u]=(e[u]-o)/l,e[u+1]=(e[u+1]-h)/c}toSVGPath(){const t=[`M${this.#h[4]} ${this.#h[5]}`];for(let e=6,s=this.#h.length;e<s;e+=6){if(isNaN(this.#h[e])){t.push(`L${this.#h[e+4]} ${this.#h[e+5]}`);continue}t.push(`C${this.#h[e]} ${this.#h[e+1]} ${this.#h[e+2]} ${this.#h[e+3]} ${this.#h[e+4]} ${this.#h[e+5]}`)}return t.push("Z"),t.join(" ")}serialize([t,e,s,i],n){const r=s-t,o=i-e;let h,l;switch(n){case 0:h=j._rescale(this.#h,t,i,r,-o),l=j._rescale(this.#r,t,i,r,-o);break;case 90:h=j._rescaleAndSwap(this.#h,t,e,r,o),l=j._rescaleAndSwap(this.#r,t,e,r,o);break;case 180:h=j._rescale(this.#h,s,e,-r,o),l=j._rescale(this.#r,s,e,-r,o);break;case 270:h=j._rescaleAndSwap(this.#h,s,i,-r,-o),l=j._rescaleAndSwap(this.#r,s,i,-r,-o);break}return{outline:Array.from(h),points:[Array.from(l)]}}#a(t){const e=this.#h;let s=e[4],i=e[5],n=s,r=i,o=s,h=i,l=s,c=i;const u=t?Math.max:Math.min;for(let f=6,g=e.length;f<g;f+=6){if(isNaN(e[f]))n=Math.min(n,e[f+4]),r=Math.min(r,e[f+5]),o=Math.max(o,e[f+4]),h=Math.max(h,e[f+5]),c<e[f+5]?(l=e[f+4],c=e[f+5]):c===e[f+5]&&(l=u(l,e[f+4]));else{const p=G.bezierBoundingBox(s,i,...e.slice(f,f+6));n=Math.min(n,p[0]),r=Math.min(r,p[1]),o=Math.max(o,p[2]),h=Math.max(h,p[3]),c<p[3]?(l=p[2],c=p[3]):c===p[3]&&(l=u(l,p[2]))}s=e[f+4],i=e[f+5]}const d=this.#e;d[0]=n-this.#s,d[1]=r-this.#s,d[2]=o-n+2*this.#s,d[3]=h-r+2*this.#s,this.lastPoint=[l,c]}get box(){return this.#e}newOutliner(t,e,s,i,n,r=0){return new ys(t,e,s,i,n,r)}getNewOutline(t,e){const[s,i,n,r]=this.#e,[o,h,l,c]=this.#t,u=n*l,d=r*c,f=s*l+o,g=i*c+h,p=this.newOutliner({x:this.#r[0]*u+f,y:this.#r[1]*d+g},this.#t,this.#n,t,this.#i,e??this.#s);for(let b=2;b<this.#r.length;b+=2)p.add({x:this.#r[b]*u+f,y:this.#r[b+1]*d+g});return p.getOutlines()}}class So{#t;#e;#s=[];#i=[];constructor(t,e=0,s=0,i=!0){let n=1/0,r=-1/0,o=1/0,h=-1/0;const l=10**-4;for(const{x:b,y:m,width:v,height:y}of t){const _=Math.floor((b-e)/l)*l,S=Math.ceil((b+v+e)/l)*l,A=Math.floor((m-e)/l)*l,T=Math.ceil((m+y+e)/l)*l,k=[_,A,T,!0],P=[S,A,T,!1];this.#s.push(k,P),n=Math.min(n,_),r=Math.max(r,S),o=Math.min(o,A),h=Math.max(h,T)}const c=r-n+2*s,u=h-o+2*s,d=n-s,f=o-s,g=this.#s.at(i?-1:-2),p=[g[0],g[2]];for(const b of this.#s){const[m,v,y]=b;b[0]=(m-d)/c,b[1]=(v-f)/u,b[2]=(y-f)/u}this.#t=new Float32Array([d,f,c,u]),this.#e=p}getOutlines(){this.#s.sort((e,s)=>e[0]-s[0]||e[1]-s[1]||e[2]-s[2]);const t=[];for(const e of this.#s)e[3]?(t.push(...this.#c(e)),this.#h(e)):(this.#a(e),t.push(...this.#c(e)));return this.#r(t)}#r(t){const e=[],s=new Set;for(const r of t){const[o,h,l]=r;e.push([o,h,r],[o,l,r])}e.sort((r,o)=>r[1]-o[1]||r[0]-o[0]);for(let r=0,o=e.length;r<o;r+=2){const h=e[r][2],l=e[r+1][2];h.push(l),l.push(h),s.add(h),s.add(l)}const i=[];let n;for(;s.size>0;){const r=s.values().next().value;let[o,h,l,c,u]=r;s.delete(r);let d=o,f=h;for(n=[o,l],i.push(n);;){let g;if(s.has(c))g=c;else if(s.has(u))g=u;else break;s.delete(g),[o,h,l,c,u]=g,d!==o&&(n.push(d,f,o,f===h?h:l),d=o),f=f===h?l:h}n.push(d,f)}return new Rg(i,this.#t,this.#e)}#n(t){const e=this.#i;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}#h([,t,e]){const s=this.#n(t);this.#i.splice(s,0,[t,e])}#a([,t,e]){const s=this.#n(t);for(let i=s;i<this.#i.length;i++){const[n,r]=this.#i[i];if(n!==t)break;if(n===t&&r===e){this.#i.splice(i,1);return}}for(let i=s-1;i>=0;i--){const[n,r]=this.#i[i];if(n!==t)break;if(n===t&&r===e){this.#i.splice(i,1);return}}}#c(t){const[e,s,i]=t,n=[[e,s,i]],r=this.#n(i);for(let o=0;o<r;o++){const[h,l]=this.#i[o];for(let c=0,u=n.length;c<u;c++){const[,d,f]=n[c];if(!(l<=d||f<=h)){if(d>=h){if(f>l)n[c][1]=l;else{if(u===1)return[];n.splice(c,1),c--,u--}continue}n[c][2]=h,f>l&&n.push([e,l,f])}}}return n}}class Rg extends j{#t;#e;constructor(t,e,s){super(),this.#e=t,this.#t=e,this.lastPoint=s}toSVGPath(){const t=[];for(const e of this.#e){let[s,i]=e;t.push(`M${s} ${i}`);for(let n=2;n<e.length;n+=2){const r=e[n],o=e[n+1];r===s?(t.push(`V${o}`),i=o):o===i&&(t.push(`H${r}`),s=r)}t.push("Z")}return t.join(" ")}serialize([t,e,s,i],n){const r=[],o=s-t,h=i-e;for(const l of this.#e){const c=new Array(l.length);for(let u=0;u<l.length;u+=2)c[u]=t+l[u]*o,c[u+1]=i-l[u+1]*h;r.push(c)}return r}get box(){return this.#t}get classNamesForOutlining(){return["highlightOutline"]}}class Co extends ys{newFreeDrawOutline(t,e,s,i,n,r){return new Lg(t,e,s,i,n,r)}}class Lg extends Il{newOutliner(t,e,s,i,n,r=0){return new Co(t,e,s,i,n,r)}}class he{#t=null;#e=null;#s;#i=null;#r=!1;#n=!1;#h=null;#a;#c=null;#l=null;#d;static#u=null;static get _keyboardManager(){return Z(this,"_keyboardManager",new bi([[["Escape","mac+Escape"],he.prototype._hideDropdownFromKeyboard],[[" ","mac+ "],he.prototype._colorSelectFromKeyboard],[["ArrowDown","ArrowRight","mac+ArrowDown","mac+ArrowRight"],he.prototype._moveToNext],[["ArrowUp","ArrowLeft","mac+ArrowUp","mac+ArrowLeft"],he.prototype._moveToPrevious],[["Home","mac+Home"],he.prototype._moveToBeginning],[["End","mac+End"],he.prototype._moveToEnd]]))}constructor({editor:t=null,uiManager:e=null}){t?(this.#n=!1,this.#d=tt.HIGHLIGHT_COLOR,this.#h=t):(this.#n=!0,this.#d=tt.HIGHLIGHT_DEFAULT_COLOR),this.#l=t?._uiManager||e,this.#a=this.#l._eventBus,this.#s=t?.color||this.#l?.highlightColors.values().next().value||"#FFFF98",he.#u||=Object.freeze({blue:"pdfjs-editor-colorpicker-blue",green:"pdfjs-editor-colorpicker-green",pink:"pdfjs-editor-colorpicker-pink",red:"pdfjs-editor-colorpicker-red",yellow:"pdfjs-editor-colorpicker-yellow"})}renderButton(){const t=this.#t=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=this.#l._signal;t.addEventListener("click",this.#m.bind(this),{signal:e}),t.addEventListener("keydown",this.#g.bind(this),{signal:e});const s=this.#e=document.createElement("span");return s.className="swatch",s.setAttribute("aria-hidden",!0),s.style.backgroundColor=this.#s,t.append(s),t}renderMainDropdown(){const t=this.#i=this.#f();return t.setAttribute("aria-orientation","horizontal"),t.setAttribute("aria-labelledby","highlightColorPickerLabel"),t}#f(){const t=document.createElement("div"),e=this.#l._signal;t.addEventListener("contextmenu",ve,{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 this.#l.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",he.#u[s]);const r=document.createElement("span");n.append(r),r.className="swatch",r.style.backgroundColor=i,n.setAttribute("aria-selected",i===this.#s),n.addEventListener("click",this.#o.bind(this,i),{signal:e}),t.append(n)}return t.addEventListener("keydown",this.#g.bind(this),{signal:e}),t}#o(t,e){e.stopPropagation(),this.#a.dispatch("switchannotationeditorparams",{source:this,type:this.#d,value:t})}_colorSelectFromKeyboard(t){if(t.target===this.#t){this.#m(t);return}const e=t.target.getAttribute("data-color");e&&this.#o(e,t)}_moveToNext(t){if(!this.#b){this.#m(t);return}if(t.target===this.#t){this.#i.firstChild?.focus();return}t.target.nextSibling?.focus()}_moveToPrevious(t){if(t.target===this.#i?.firstChild||t.target===this.#t){this.#b&&this._hideDropdownFromKeyboard();return}this.#b||this.#m(t),t.target.previousSibling?.focus()}_moveToBeginning(t){if(!this.#b){this.#m(t);return}this.#i.firstChild?.focus()}_moveToEnd(t){if(!this.#b){this.#m(t);return}this.#i.lastChild?.focus()}#g(t){he._keyboardManager.exec(this,t)}#m(t){if(this.#b){this.hideDropdown();return}if(this.#r=t.detail===0,this.#c||(this.#c=new AbortController,window.addEventListener("pointerdown",this.#p.bind(this),{signal:this.#l.combinedSignal(this.#c)})),this.#i){this.#i.classList.remove("hidden");return}const e=this.#i=this.#f();this.#t.append(e)}#p(t){this.#i?.contains(t.target)||this.hideDropdown()}hideDropdown(){this.#i?.classList.add("hidden"),this.#c?.abort(),this.#c=null}get#b(){return this.#i&&!this.#i.classList.contains("hidden")}_hideDropdownFromKeyboard(){if(!this.#n){if(!this.#b){this.#h?.unselect();return}this.hideDropdown(),this.#t.focus({preventScroll:!0,focusVisible:this.#r})}}updateColor(t){if(this.#e&&(this.#e.style.backgroundColor=t),!this.#i)return;const e=this.#l.highlightColors.values();for(const s of this.#i.children)s.setAttribute("aria-selected",e.next().value===t)}destroy(){this.#t?.remove(),this.#t=null,this.#e=null,this.#i?.remove(),this.#i=null}}class _t extends W{#t=null;#e=0;#s;#i=null;#r=null;#n=null;#h=null;#a=0;#c=null;#l=null;#d=null;#u=!1;#f=null;#o;#g=null;#m="";#p;#b="";static _defaultColor=null;static _defaultOpacity=1;static _defaultThickness=12;static _type="highlight";static _editorType=q.HIGHLIGHT;static _freeHighlightId=-1;static _freeHighlight=null;static _freeHighlightClipId="";static get _keyboardManager(){const t=_t.prototype;return Z(this,"_keyboardManager",new bi([[["ArrowLeft","mac+ArrowLeft"],t._moveCaret,{args:[0]}],[["ArrowRight","mac+ArrowRight"],t._moveCaret,{args:[1]}],[["ArrowUp","mac+ArrowUp"],t._moveCaret,{args:[2]}],[["ArrowDown","mac+ArrowDown"],t._moveCaret,{args:[3]}]]))}constructor(t){super({...t,name:"highlightEditor"}),this.color=t.color||_t._defaultColor,this.#p=t.thickness||_t._defaultThickness,this.#o=t.opacity||_t._defaultOpacity,this.#s=t.boxes||null,this.#b=t.methodOfCreation||"",this.#m=t.text||"",this._isDraggable=!1,t.highlightId>-1?(this.#u=!0,this.#v(t),this.#M()):this.#s&&(this.#t=t.anchorNode,this.#e=t.anchorOffset,this.#h=t.focusNode,this.#a=t.focusOffset,this.#_(),this.#M(),this.rotate(this.rotation))}get telemetryInitialData(){return{action:"added",type:this.#u?"free_highlight":"highlight",color:this._uiManager.highlightColorNames.get(this.color),thickness:this.#p,methodOfCreation:this.#b}}get telemetryFinalData(){return{type:"highlight",color:this._uiManager.highlightColorNames.get(this.color)}}static computeTelemetryFinalData(t){return{numberOfColors:t.get("color").size}}#_(){const t=new So(this.#s,.001);this.#l=t.getOutlines(),[this.x,this.y,this.width,this.height]=this.#l.box;const e=new So(this.#s,.0025,.001,this._uiManager.direction==="ltr");this.#n=e.getOutlines();const{lastPoint:s}=this.#n;this.#f=[(s[0]-this.x)/this.width,(s[1]-this.y)/this.height]}#v({highlightOutlines:t,highlightId:e,clipPathId:s}){this.#l=t;const i=1.5;if(this.#n=t.getNewOutline(this.#p/2+i,.0025),e>=0)this.#d=e,this.#i=s,this.parent.drawLayer.finalizeDraw(e,{bbox:t.box,path:{d:t.toSVGPath()}}),this.#g=this.parent.drawLayer.drawOutline({rootClass:{highlightOutline:!0,free:!0},bbox:this.#n.box,path:{d:this.#n.toSVGPath()}},!0);else if(this.parent){const c=this.parent.viewport.rotation;this.parent.drawLayer.updateProperties(this.#d,{bbox:_t.#x(this.#l.box,(c-this.rotation+360)%360),path:{d:t.toSVGPath()}}),this.parent.drawLayer.updateProperties(this.#g,{bbox:_t.#x(this.#n.box,c),path:{d:this.#n.toSVGPath()}})}const[n,r,o,h]=t.box;switch(this.rotation){case 0:this.x=n,this.y=r,this.width=o,this.height=h;break;case 90:{const[c,u]=this.parentDimensions;this.x=r,this.y=1-n,this.width=o*u/c,this.height=h*c/u;break}case 180:this.x=1-n,this.y=1-r,this.width=o,this.height=h;break;case 270:{const[c,u]=this.parentDimensions;this.x=1-r,this.y=n,this.width=o*u/c,this.height=h*c/u;break}}const{lastPoint:l}=this.#n;this.#f=[(l[0]-n)/o,(l[1]-r)/h]}static initialize(t,e){W.initialize(t,e),_t._defaultColor||=e.highlightColors?.values().next().value||"#fff066"}static updateDefaultParams(t,e){switch(t){case tt.HIGHLIGHT_DEFAULT_COLOR:_t._defaultColor=e;break;case tt.HIGHLIGHT_THICKNESS:_t._defaultThickness=e;break}}translateInPage(t,e){}get toolbarPosition(){return this.#f}updateParams(t,e){switch(t){case tt.HIGHLIGHT_COLOR:this.#w(e);break;case tt.HIGHLIGHT_THICKNESS:this.#S(e);break}}static get defaultPropertiesToUpdate(){return[[tt.HIGHLIGHT_DEFAULT_COLOR,_t._defaultColor],[tt.HIGHLIGHT_THICKNESS,_t._defaultThickness]]}get propertiesToUpdate(){return[[tt.HIGHLIGHT_COLOR,this.color||_t._defaultColor],[tt.HIGHLIGHT_THICKNESS,this.#p||_t._defaultThickness],[tt.HIGHLIGHT_FREE,this.#u]]}#w(t){const e=(n,r)=>{this.color=n,this.#o=r,this.parent?.drawLayer.updateProperties(this.#d,{root:{fill:n,"fill-opacity":r}}),this.#r?.updateColor(n)},s=this.color,i=this.#o;this.addCommands({cmd:e.bind(this,t,_t._defaultOpacity),undo:e.bind(this,s,i),post:this._uiManager.updateUI.bind(this._uiManager,this),mustExec:!0,type:tt.HIGHLIGHT_COLOR,overwriteIfSameType:!0,keepUndo:!0}),this._reportTelemetry({action:"color_changed",color:this._uiManager.highlightColorNames.get(t)},!0)}#S(t){const e=this.#p,s=i=>{this.#p=i,this.#A(i)};this.addCommands({cmd:s.bind(this,t),undo:s.bind(this,e),post:this._uiManager.updateUI.bind(this._uiManager,this),mustExec:!0,type:tt.INK_THICKNESS,overwriteIfSameType:!0,keepUndo:!0}),this._reportTelemetry({action:"thickness_changed",thickness:t},!0)}async addEditToolbar(){const t=await super.addEditToolbar();return t?(this._uiManager.highlightColors&&(this.#r=new he({editor:this}),t.addColorPicker(this.#r)),t):null}disableEditing(){super.disableEditing(),this.div.classList.toggle("disabled",!0)}enableEditing(){super.enableEditing(),this.div.classList.toggle("disabled",!1)}fixAndSetPosition(){return super.fixAndSetPosition(this.#O())}getBaseTranslation(){return[0,0]}getRect(t,e){return super.getRect(t,e,this.#O())}onceAdded(t){this.annotationElementId||this.parent.addUndoableEditor(this),t&&this.div.focus()}remove(){this.#E(),this._reportTelemetry({action:"deleted"}),super.remove()}rebuild(){this.parent&&(super.rebuild(),this.div!==null&&(this.#M(),this.isAttachedToDOM||this.parent.add(this)))}setParent(t){let e=!1;this.parent&&!t?this.#E():t&&(this.#M(t),e=!this.parent&&this.div?.classList.contains("selectedEditor")),super.setParent(t),this.show(this._isVisible),e&&this.select()}#A(t){if(!this.#u)return;this.#v({highlightOutlines:this.#l.getNewOutline(t/2)}),this.fixAndSetPosition();const[e,s]=this.parentDimensions;this.setDims(this.width*e,this.height*s)}#E(){this.#d===null||!this.parent||(this.parent.drawLayer.remove(this.#d),this.#d=null,this.parent.drawLayer.remove(this.#g),this.#g=null)}#M(t=this.parent){this.#d===null&&({id:this.#d,clipPathId:this.#i}=t.drawLayer.draw({bbox:this.#l.box,root:{viewBox:"0 0 1 1",fill:this.color,"fill-opacity":this.#o},rootClass:{highlight:!0,free:this.#u},path:{d:this.#l.toSVGPath()}},!1,!0),this.#g=t.drawLayer.drawOutline({rootClass:{highlightOutline:!0,free:this.#u},bbox:this.#n.box,path:{d:this.#n.toSVGPath()}},this.#u),this.#c&&(this.#c.style.clipPath=this.#i))}static#x([t,e,s,i],n){switch(n){case 90:return[1-e-i,t,i,s];case 180:return[1-t-s,1-e-i,s,i];case 270:return[e,1-t-s,i,s]}return[t,e,s,i]}rotate(t){const{drawLayer:e}=this.parent;let s;this.#u?(t=(t-this.rotation+360)%360,s=_t.#x(this.#l.box,t)):s=_t.#x([this.x,this.y,this.width,this.height],t),e.updateProperties(this.#d,{bbox:s,root:{"data-main-rotation":t}}),e.updateProperties(this.#g,{bbox:_t.#x(this.#n.box,t),root:{"data-main-rotation":t}})}render(){if(this.div)return this.div;const t=super.render();this.#m&&(t.setAttribute("aria-label",this.#m),t.setAttribute("role","mark")),this.#u?t.classList.add("free"):this.div.addEventListener("keydown",this.#k.bind(this),{signal:this._uiManager._signal});const e=this.#c=document.createElement("div");t.append(e),e.setAttribute("aria-hidden","true"),e.className="internal",e.style.clipPath=this.#i;const[s,i]=this.parentDimensions;return this.setDims(this.width*s,this.height*i),In(this,this.#c,["pointerover","pointerleave"]),this.enableEditing(),t}pointerover(){this.isSelected||this.parent?.drawLayer.updateProperties(this.#g,{rootClass:{hovered:!0}})}pointerleave(){this.isSelected||this.parent?.drawLayer.updateProperties(this.#g,{rootClass:{hovered:!1}})}#k(t){_t._keyboardManager.exec(this,t)}_moveCaret(t){switch(this.parent.unselect(this),t){case 0:case 2:this.#T(!0);break;case 1:case 3:this.#T(!1);break}}#T(t){if(!this.#t)return;const e=window.getSelection();t?e.setPosition(this.#t,this.#e):e.setPosition(this.#h,this.#a)}select(){super.select(),this.#g&&this.parent?.drawLayer.updateProperties(this.#g,{rootClass:{hovered:!1,selected:!0}})}unselect(){super.unselect(),this.#g&&(this.parent?.drawLayer.updateProperties(this.#g,{rootClass:{selected:!1}}),this.#u||this.#T(!1))}get _mustFixPosition(){return!this.#u}show(t=this._isVisible){super.show(t),this.parent&&(this.parent.drawLayer.updateProperties(this.#d,{rootClass:{hidden:!t}}),this.parent.drawLayer.updateProperties(this.#g,{rootClass:{hidden:!t}}))}#O(){return this.#u?this.rotation:0}#L(){if(this.#u)return null;const[t,e]=this.pageDimensions,[s,i]=this.pageTranslation,n=this.#s,r=new Float32Array(n.length*8);let o=0;for(const{x:h,y:l,width:c,height:u}of n){const d=h*t+s,f=(1-l)*e+i;r[o]=r[o+4]=d,r[o+1]=r[o+3]=f,r[o+2]=r[o+6]=d+c*t,r[o+5]=r[o+7]=f-u*e,o+=8}return r}#I(t){return this.#l.serialize(t,this.#O())}static startHighlighting(t,e,{target:s,x:i,y:n}){const{x:r,y:o,width:h,height:l}=s.getBoundingClientRect(),c=new AbortController,u=t.combinedSignal(c),d=f=>{c.abort(),this.#y(t,f)};window.addEventListener("blur",d,{signal:u}),window.addEventListener("pointerup",d,{signal:u}),window.addEventListener("pointerdown",ne,{capture:!0,passive:!1,signal:u}),window.addEventListener("contextmenu",ve,{signal:u}),s.addEventListener("pointermove",this.#C.bind(this,t),{signal:u}),this._freeHighlight=new Co({x:i,y:n},[r,o,h,l],t.scale,this._defaultThickness/2,e,.001),{id:this._freeHighlightId,clipPathId:this._freeHighlightClipId}=t.drawLayer.draw({bbox:[0,0,1,1],root:{viewBox:"0 0 1 1",fill:this._defaultColor,"fill-opacity":this._defaultOpacity},rootClass:{highlight:!0,free:!0},path:{d:this._freeHighlight.toSVGPath()}},!0,!0)}static#C(t,e){this._freeHighlight.add(e)&&t.drawLayer.updateProperties(this._freeHighlightId,{path:{d:this._freeHighlight.toSVGPath()}})}static#y(t,e){this._freeHighlight.isEmpty()?t.drawLayer.remove(this._freeHighlightId):t.createAndAddNewEditor(e,!1,{highlightId:this._freeHighlightId,highlightOutlines:this._freeHighlight.getOutlines(),clipPathId:this._freeHighlightClipId,methodOfCreation:"main_toolbar"}),this._freeHighlightId=-1,this._freeHighlight=null,this._freeHighlightClipId=""}static async deserialize(t,e,s){let i=null;if(t instanceof Ll){const{data:{quadPoints:g,rect:p,rotation:b,id:m,color:v,opacity:y,popupRef:_},parent:{page:{pageNumber:S}}}=t;i=t={annotationType:q.HIGHLIGHT,color:Array.from(v),opacity:y,quadPoints:g,boxes:null,pageIndex:S-1,rect:p.slice(0),rotation:b,id:m,deleted:!1,popupRef:_}}else if(t instanceof xo){const{data:{inkLists:g,rect:p,rotation:b,id:m,color:v,borderStyle:{rawWidth:y},popupRef:_},parent:{page:{pageNumber:S}}}=t;i=t={annotationType:q.HIGHLIGHT,color:Array.from(v),thickness:y,inkLists:g,boxes:null,pageIndex:S-1,rect:p.slice(0),rotation:b,id:m,deleted:!1,popupRef:_}}const{color:n,quadPoints:r,inkLists:o,opacity:h}=t,l=await super.deserialize(t,e,s);l.color=G.makeHexColor(...n),l.#o=h||1,o&&(l.#p=t.thickness),l.annotationElementId=t.id||null,l._initialData=i;const[c,u]=l.pageDimensions,[d,f]=l.pageTranslation;if(r){const g=l.#s=[];for(let p=0;p<r.length;p+=8)g.push({x:(r[p]-d)/c,y:1-(r[p+1]-f)/u,width:(r[p+2]-r[p])/c,height:(r[p+1]-r[p+5])/u});l.#_(),l.#M(),l.rotate(l.rotation)}else if(o){l.#u=!0;const g=o[0],p={x:g[0]-d,y:u-(g[1]-f)},b=new Co(p,[0,0,c,u],1,l.#p/2,!0,.001);for(let y=0,_=g.length;y<_;y+=2)p.x=g[y]-d,p.y=u-(g[y+1]-f),b.add(p);const{id:m,clipPathId:v}=e.drawLayer.draw({bbox:[0,0,1,1],root:{viewBox:"0 0 1 1",fill:l.color,"fill-opacity":l._defaultOpacity},rootClass:{highlight:!0,free:!0},path:{d:b.toSVGPath()}},!0,!0);l.#v({highlightOutlines:b.getOutlines(),highlightId:m,clipPathId:v}),l.#M()}return l}serialize(t=!1){if(this.isEmpty()||t)return null;if(this.deleted)return this.serializeDeleted();const e=this.getRect(0,0),s=W._colorManager.convert(this.color),i={annotationType:q.HIGHLIGHT,color:s,opacity:this.#o,thickness:this.#p,quadPoints:this.#L(),outlines:this.#I(e),pageIndex:this.pageIndex,rect:e,rotation:this.#O(),structTreeParentId:this._structTreeParentId};return this.annotationElementId&&!this.#R(i)?null:(i.id=this.annotationElementId,i)}#R(t){const{color:e}=this._initialData;return t.color.some((s,i)=>s!==e[i])}renderAnnotationElement(t){return t.updateEdited({rect:this.getRect(0,0)}),null}static canCreateNewEmptyEditor(){return!1}}class Fg{#t=Object.create(null);updateProperty(t,e){this[t]=e,this.updateSVGProperty(t,e)}updateProperties(t){if(t)for(const[e,s]of Object.entries(t))this.updateProperty(e,s)}updateSVGProperty(t,e){this.#t[t]=e}toSVGProperties(){const t=this.#t;return this.#t=Object.create(null),{root:t}}reset(){this.#t=Object.create(null)}updateAll(t=this){this.updateProperties(t)}clone(){at("Not implemented")}}class X extends W{#t=null;#e;_drawId=null;static _currentDrawId=-1;static _currentParent=null;static#s=null;static#i=null;static#r=null;static#n=NaN;static#h=null;static#a=null;static#c=NaN;static _INNER_MARGIN=3;constructor(t){super(t),this.#e=t.mustBeCommitted||!1,t.drawOutlines&&(this.#l(t),this.#f())}#l({drawOutlines:t,drawId:e,drawingOptions:s}){this.#t=t,this._drawingOptions||=s,e>=0?(this._drawId=e,this.parent.drawLayer.finalizeDraw(e,t.defaultProperties)):this._drawId=this.#d(t,this.parent),this.#m(t.box)}#d(t,e){const{id:s}=e.drawLayer.draw(X._mergeSVGProperties(this._drawingOptions.toSVGProperties(),t.defaultSVGProperties),!1,!1);return s}static _mergeSVGProperties(t,e){const s=new Set(Object.keys(t));for(const[i,n]of Object.entries(e))s.has(i)?Object.assign(t[i],n):t[i]=n;return t}static getDefaultDrawingOptions(t){at("Not implemented")}static get typesMap(){at("Not implemented")}static get isDrawer(){return!0}static get supportMultipleDrawings(){return!1}static updateDefaultParams(t,e){const s=this.typesMap.get(t);s&&this._defaultDrawingOptions.updateProperty(s,e),this._currentParent&&(X.#s.updateProperty(s,e),this._currentParent.drawLayer.updateProperties(this._currentDrawId,this._defaultDrawingOptions.toSVGProperties()))}updateParams(t,e){const s=this.constructor.typesMap.get(t);s&&this._updateProperty(t,s,e)}static get defaultPropertiesToUpdate(){const t=[],e=this._defaultDrawingOptions;for(const[s,i]of this.typesMap)t.push([s,e[i]]);return t}get propertiesToUpdate(){const t=[],{_drawingOptions:e}=this;for(const[s,i]of this.constructor.typesMap)t.push([s,e[i]]);return t}_updateProperty(t,e,s){const i=this._drawingOptions,n=i[e],r=o=>{i.updateProperty(e,o);const h=this.#t.updateProperty(e,o);h&&this.#m(h),this.parent?.drawLayer.updateProperties(this._drawId,i.toSVGProperties())};this.addCommands({cmd:r.bind(this,s),undo:r.bind(this,n),post:this._uiManager.updateUI.bind(this._uiManager,this),mustExec:!0,type:t,overwriteIfSameType:!0,keepUndo:!0})}_onResizing(){this.parent?.drawLayer.updateProperties(this._drawId,X._mergeSVGProperties(this.#t.getPathResizingSVGProperties(this.#g()),{bbox:this.#p()}))}_onResized(){this.parent?.drawLayer.updateProperties(this._drawId,X._mergeSVGProperties(this.#t.getPathResizedSVGProperties(this.#g()),{bbox:this.#p()}))}_onTranslating(t,e){this.parent?.drawLayer.updateProperties(this._drawId,{bbox:this.#p(t,e)})}_onTranslated(){this.parent?.drawLayer.updateProperties(this._drawId,X._mergeSVGProperties(this.#t.getPathTranslatedSVGProperties(this.#g(),this.parentDimensions),{bbox:this.#p()}))}_onStartDragging(){this.parent?.drawLayer.updateProperties(this._drawId,{rootClass:{moving:!0}})}_onStopDragging(){this.parent?.drawLayer.updateProperties(this._drawId,{rootClass:{moving:!1}})}commit(){super.commit(),this.disableEditMode(),this.disableEditing()}disableEditing(){super.disableEditing(),this.div.classList.toggle("disabled",!0)}enableEditing(){super.enableEditing(),this.div.classList.toggle("disabled",!1)}getBaseTranslation(){return[0,0]}get isResizable(){return!0}onceAdded(t){this.annotationElementId||this.parent.addUndoableEditor(this),this._isDraggable=!0,this.#e&&(this.#e=!1,this.commit(),this.parent.setSelected(this),t&&this.isOnScreen&&this.div.focus())}remove(){this.#u(),super.remove()}rebuild(){this.parent&&(super.rebuild(),this.div!==null&&(this.#f(),this.#m(this.#t.box),this.isAttachedToDOM||this.parent.add(this)))}setParent(t){let e=!1;this.parent&&!t?(this._uiManager.removeShouldRescale(this),this.#u()):t&&(this._uiManager.addShouldRescale(this),this.#f(t),e=!this.parent&&this.div?.classList.contains("selectedEditor")),super.setParent(t),e&&this.select()}#u(){this._drawId===null||!this.parent||(this.parent.drawLayer.remove(this._drawId),this._drawId=null,this._drawingOptions.reset())}#f(t=this.parent){if(!(this._drawId!==null&&this.parent===t)){if(this._drawId!==null){this.parent.drawLayer.updateParent(this._drawId,t.drawLayer);return}this._drawingOptions.updateAll(),this._drawId=this.#d(this.#t,t)}}#o([t,e,s,i]){const{parentDimensions:[n,r],rotation:o}=this;switch(o){case 90:return[e,1-t,s*(r/n),i*(n/r)];case 180:return[1-t,1-e,s,i];case 270:return[1-e,t,s*(r/n),i*(n/r)];default:return[t,e,s,i]}}#g(){const{x:t,y:e,width:s,height:i,parentDimensions:[n,r],rotation:o}=this;switch(o){case 90:return[1-e,t,s*(n/r),i*(r/n)];case 180:return[1-t,1-e,s,i];case 270:return[e,1-t,s*(n/r),i*(r/n)];default:return[t,e,s,i]}}#m(t){if([this.x,this.y,this.width,this.height]=this.#o(t),this.div){this.fixAndSetPosition();const[e,s]=this.parentDimensions;this.setDims(this.width*e,this.height*s)}this._onResized()}#p(){const{x:t,y:e,width:s,height:i,rotation:n,parentRotation:r,parentDimensions:[o,h]}=this;switch((n*4+r)/90){case 1:return[1-e-i,t,i,s];case 2:return[1-t-s,1-e-i,s,i];case 3:return[e,1-t-s,i,s];case 4:return[t,e-s*(o/h),i*(h/o),s*(o/h)];case 5:return[1-e,t,s*(o/h),i*(h/o)];case 6:return[1-t-i*(h/o),1-e,i*(h/o),s*(o/h)];case 7:return[e-s*(o/h),1-t-i*(h/o),s*(o/h),i*(h/o)];case 8:return[t-s,e-i,s,i];case 9:return[1-e,t-s,i,s];case 10:return[1-t,1-e,s,i];case 11:return[e-i,1-t,i,s];case 12:return[t-i*(h/o),e,i*(h/o),s*(o/h)];case 13:return[1-e-s*(o/h),t-i*(h/o),s*(o/h),i*(h/o)];case 14:return[1-t,1-e-s*(o/h),i*(h/o),s*(o/h)];case 15:return[e,1-t,s*(o/h),i*(h/o)];default:return[t,e,s,i]}}rotate(){this.parent&&this.parent.drawLayer.updateProperties(this._drawId,X._mergeSVGProperties({bbox:this.#p()},this.#t.updateRotation((this.parentRotation-this.rotation+360)%360)))}onScaleChanging(){this.parent&&this.#m(this.#t.updateParentDimensions(this.parentDimensions,this.parent.scale))}static onScaleChangingWhenDrawing(){}render(){if(this.div)return this.div;const t=super.render();t.classList.add("draw");const e=document.createElement("div");t.append(e),e.setAttribute("aria-hidden","true"),e.className="internal";const[s,i]=this.parentDimensions;return this.setDims(this.width*s,this.height*i),this._uiManager.addShouldRescale(this),this.disableEditing(),t}static createDrawerInstance(t,e,s,i,n){at("Not implemented")}static startDrawing(t,e,s,i){const{target:n,offsetX:r,offsetY:o,pointerId:h,pointerType:l}=i;if(X.#h&&X.#h!==l)return;const{viewport:{rotation:c}}=t,{width:u,height:d}=n.getBoundingClientRect(),f=X.#i=new AbortController,g=t.combinedSignal(f);if(X.#n||=h,X.#h??=l,window.addEventListener("pointerup",p=>{X.#n===p.pointerId?this._endDraw(p):X.#a?.delete(p.pointerId)},{signal:g}),window.addEventListener("pointercancel",p=>{X.#n===p.pointerId?this._currentParent.endDrawingSession():X.#a?.delete(p.pointerId)},{signal:g}),window.addEventListener("pointerdown",p=>{X.#h===p.pointerType&&((X.#a||=new Set).add(p.pointerId),X.#s.isCancellable()&&(X.#s.removeLastElement(),X.#s.isEmpty()?this._currentParent.endDrawingSession(!0):this._endDraw(null)))},{capture:!0,passive:!1,signal:g}),window.addEventListener("contextmenu",ve,{signal:g}),n.addEventListener("pointermove",this._drawMove.bind(this),{signal:g}),n.addEventListener("touchmove",p=>{p.timeStamp===X.#c&&ne(p)},{signal:g}),t.toggleDrawing(),e._editorUndoBar?.hide(),X.#s){t.drawLayer.updateProperties(this._currentDrawId,X.#s.startNew(r,o,u,d,c));return}e.updateUIForDefaultProperties(this),X.#s=this.createDrawerInstance(r,o,u,d,c),X.#r=this.getDefaultDrawingOptions(),this._currentParent=t,{id:this._currentDrawId}=t.drawLayer.draw(this._mergeSVGProperties(X.#r.toSVGProperties(),X.#s.defaultSVGProperties),!0,!1)}static _drawMove(t){if(X.#c=-1,!X.#s)return;const{offsetX:e,offsetY:s,pointerId:i}=t;if(X.#n===i){if(X.#a?.size>=1){this._endDraw(t);return}this._currentParent.drawLayer.updateProperties(this._currentDrawId,X.#s.add(e,s)),X.#c=t.timeStamp,ne(t)}}static _cleanup(t){t&&(this._currentDrawId=-1,this._currentParent=null,X.#s=null,X.#r=null,X.#h=null,X.#c=NaN),X.#i&&(X.#i.abort(),X.#i=null,X.#n=NaN,X.#a=null)}static _endDraw(t){const e=this._currentParent;if(e){if(e.toggleDrawing(!0),this._cleanup(!1),t&&e.drawLayer.updateProperties(this._currentDrawId,X.#s.end(t.offsetX,t.offsetY)),this.supportMultipleDrawings){const s=X.#s,i=this._currentDrawId,n=s.getLastElement();e.addCommands({cmd:()=>{e.drawLayer.updateProperties(i,s.setLastElement(n))},undo:()=>{e.drawLayer.updateProperties(i,s.removeLastElement())},mustExec:!1,type:tt.DRAW_STEP});return}this.endDrawing(!1)}}static endDrawing(t){const e=this._currentParent;if(!e)return null;if(e.toggleDrawing(!0),e.cleanUndoStack(tt.DRAW_STEP),!X.#s.isEmpty()){const{pageDimensions:[s,i],scale:n}=e,r=e.createAndAddNewEditor({offsetX:0,offsetY:0},!1,{drawId:this._currentDrawId,drawOutlines:X.#s.getOutlines(s*n,i*n,n,this._INNER_MARGIN),drawingOptions:X.#r,mustBeCommitted:!t});return this._cleanup(!0),r}return e.drawLayer.remove(this._currentDrawId),this._cleanup(!0),null}createDrawingOptions(t){}static deserializeDraw(t,e,s,i,n,r){at("Not implemented")}static async deserialize(t,e,s){const{rawDims:{pageWidth:i,pageHeight:n,pageX:r,pageY:o}}=e.viewport,h=this.deserializeDraw(r,o,i,n,this._INNER_MARGIN,t),l=await super.deserialize(t,e,s);return l.createDrawingOptions(t),l.#l({drawOutlines:h}),l.#f(),l.onScaleChanging(),l.rotate(),l}serializeDraw(t){const[e,s]=this.pageTranslation,[i,n]=this.pageDimensions;return this.#t.serialize([e,s,i,n],t)}renderAnnotationElement(t){return t.updateEdited({rect:this.getRect(0,0)}),null}static canCreateNewEmptyEditor(){return!1}}class Ig{#t=new Float64Array(6);#e;#s;#i;#r;#n;#h="";#a=0;#c=new Wn;#l;#d;constructor(t,e,s,i,n,r){this.#l=s,this.#d=i,this.#i=n,this.#r=r,[t,e]=this.#u(t,e);const o=this.#e=[NaN,NaN,NaN,NaN,t,e];this.#n=[t,e],this.#s=[{line:o,points:this.#n}],this.#t.set(o,0)}updateProperty(t,e){t==="stroke-width"&&(this.#r=e)}#u(t,e){return j._normalizePoint(t,e,this.#l,this.#d,this.#i)}isEmpty(){return!this.#s||this.#s.length===0}isCancellable(){return this.#n.length<=10}add(t,e){[t,e]=this.#u(t,e);const[s,i,n,r]=this.#t.subarray(2,6),o=t-n,h=e-r;return Math.hypot(this.#l*o,this.#d*h)<=2?null:(this.#n.push(t,e),isNaN(s)?(this.#t.set([n,r,t,e],2),this.#e.push(NaN,NaN,NaN,NaN,t,e),{path:{d:this.toSVGPath()}}):(isNaN(this.#t[0])&&this.#e.splice(6,6),this.#t.set([s,i,n,r,t,e],0),this.#e.push(...j.createBezierPoints(s,i,n,r,t,e)),{path:{d:this.toSVGPath()}}))}end(t,e){const s=this.add(t,e);return s||(this.#n.length===2?{path:{d:this.toSVGPath()}}:null)}startNew(t,e,s,i,n){this.#l=s,this.#d=i,this.#i=n,[t,e]=this.#u(t,e);const r=this.#e=[NaN,NaN,NaN,NaN,t,e];this.#n=[t,e];const o=this.#s.at(-1);return o&&(o.line=new Float32Array(o.line),o.points=new Float32Array(o.points)),this.#s.push({line:r,points:this.#n}),this.#t.set(r,0),this.#a=0,this.toSVGPath(),null}getLastElement(){return this.#s.at(-1)}setLastElement(t){return this.#s?(this.#s.push(t),this.#e=t.line,this.#n=t.points,this.#a=0,{path:{d:this.toSVGPath()}}):this.#c.setLastElement(t)}removeLastElement(){if(!this.#s)return this.#c.removeLastElement();this.#s.pop(),this.#h="";for(let t=0,e=this.#s.length;t<e;t++){const{line:s,points:i}=this.#s[t];this.#e=s,this.#n=i,this.#a=0,this.toSVGPath()}return{path:{d:this.#h}}}toSVGPath(){const t=j.svgRound(this.#e[4]),e=j.svgRound(this.#e[5]);if(this.#n.length===2)return this.#h=`${this.#h} M ${t} ${e} Z`,this.#h;if(this.#n.length<=6){const i=this.#h.lastIndexOf("M");this.#h=`${this.#h.slice(0,i)} M ${t} ${e}`,this.#a=6}if(this.#n.length===4){const i=j.svgRound(this.#e[10]),n=j.svgRound(this.#e[11]);return this.#h=`${this.#h} L ${i} ${n}`,this.#a=12,this.#h}const s=[];this.#a===0&&(s.push(`M ${t} ${e}`),this.#a=6);for(let i=this.#a,n=this.#e.length;i<n;i+=6){const[r,o,h,l,c,u]=this.#e.slice(i,i+6).map(j.svgRound);s.push(`C${r} ${o} ${h} ${l} ${c} ${u}`)}return this.#h+=s.join(" "),this.#a=this.#e.length,this.#h}getOutlines(t,e,s,i){const n=this.#s.at(-1);return n.line=new Float32Array(n.line),n.points=new Float32Array(n.points),this.#c.build(this.#s,t,e,s,this.#i,this.#r,i),this.#t=null,this.#e=null,this.#s=null,this.#h=null,this.#c}get defaultSVGProperties(){return{root:{viewBox:"0 0 10000 10000"},rootClass:{draw:!0},bbox:[0,0,1,1]}}}class Wn extends j{#t;#e=0;#s;#i;#r;#n;#h;#a;#c;build(t,e,s,i,n,r,o){this.#r=e,this.#n=s,this.#h=i,this.#a=n,this.#c=r,this.#s=o??0,this.#i=t,this.#u()}setLastElement(t){return this.#i.push(t),{path:{d:this.toSVGPath()}}}removeLastElement(){return this.#i.pop(),{path:{d:this.toSVGPath()}}}toSVGPath(){const t=[];for(const{line:e}of this.#i){if(t.push(`M${j.svgRound(e[4])} ${j.svgRound(e[5])}`),e.length===6){t.push("Z");continue}if(e.length===12){t.push(`L${j.svgRound(e[10])} ${j.svgRound(e[11])}`);continue}for(let s=6,i=e.length;s<i;s+=6){const[n,r,o,h,l,c]=e.subarray(s,s+6).map(j.svgRound);t.push(`C${n} ${r} ${o} ${h} ${l} ${c}`)}}return t.join("")}serialize([t,e,s,i],n){const r=[],o=[],[h,l,c,u]=this.#d();let d,f,g,p,b,m,v,y,_;switch(this.#a){case 0:_=j._rescale,d=t,f=e+i,g=s,p=-i,b=t+h*s,m=e+(1-l-u)*i,v=t+(h+c)*s,y=e+(1-l)*i;break;case 90:_=j._rescaleAndSwap,d=t,f=e,g=s,p=i,b=t+l*s,m=e+h*i,v=t+(l+u)*s,y=e+(h+c)*i;break;case 180:_=j._rescale,d=t+s,f=e,g=-s,p=i,b=t+(1-h-c)*s,m=e+l*i,v=t+(1-h)*s,y=e+(l+u)*i;break;case 270:_=j._rescaleAndSwap,d=t+s,f=e+i,g=-s,p=-i,b=t+(1-l-u)*s,m=e+(1-h-c)*i,v=t+(1-l)*s,y=e+(1-h)*i;break}for(const{line:S,points:A}of this.#i)r.push(_(S,d,f,g,p,n?new Array(S.length):null)),o.push(_(A,d,f,g,p,n?new Array(A.length):null));return{lines:r,points:o,rect:[b,m,v,y]}}static deserialize(t,e,s,i,n,{paths:{lines:r,points:o},rotation:h,thickness:l}){const c=[];let u,d,f,g,p;switch(h){case 0:p=j._rescale,u=-t/s,d=e/i+1,f=1/s,g=-1/i;break;case 90:p=j._rescaleAndSwap,u=-e/i,d=-t/s,f=1/i,g=1/s;break;case 180:p=j._rescale,u=t/s+1,d=-e/i,f=-1/s,g=1/i;break;case 270:p=j._rescaleAndSwap,u=e/i+1,d=t/s+1,f=-1/i,g=-1/s;break}if(!r){r=[];for(const m of o){const v=m.length;if(v===2){r.push(new Float32Array([NaN,NaN,NaN,NaN,m[0],m[1]]));continue}if(v===4){r.push(new Float32Array([NaN,NaN,NaN,NaN,m[0],m[1],NaN,NaN,NaN,NaN,m[2],m[3]]));continue}const y=new Float32Array(3*(v-2));r.push(y);let[_,S,A,T]=m.subarray(0,4);y.set([NaN,NaN,NaN,NaN,_,S],0);for(let k=4;k<v;k+=2){const P=m[k],B=m[k+1];y.set(j.createBezierPoints(_,S,A,T,P,B),(k-2)*3),[_,S,A,T]=[A,T,P,B]}}}for(let m=0,v=r.length;m<v;m++)c.push({line:p(r[m].map(y=>y??NaN),u,d,f,g),points:p(o[m].map(y=>y??NaN),u,d,f,g)});const b=new Wn;return b.build(c,s,i,1,h,l,n),b}#l(t=this.#c){const e=this.#s+t/2*this.#h;return this.#a%180===0?[e/this.#r,e/this.#n]:[e/this.#n,e/this.#r]}#d(){const[t,e,s,i]=this.#t,[n,r]=this.#l(0);return[t+n,e+r,s-2*n,i-2*r]}#u(){const t=this.#t=new Float32Array([1/0,1/0,-1/0,-1/0]);for(const{line:i}of this.#i){if(i.length<=12){for(let o=4,h=i.length;o<h;o+=6){const[l,c]=i.subarray(o,o+2);t[0]=Math.min(t[0],l),t[1]=Math.min(t[1],c),t[2]=Math.max(t[2],l),t[3]=Math.max(t[3],c)}continue}let n=i[4],r=i[5];for(let o=6,h=i.length;o<h;o+=6){const[l,c,u,d,f,g]=i.subarray(o,o+6);G.bezierBoundingBox(n,r,l,c,u,d,f,g,t),n=f,r=g}}const[e,s]=this.#l();t[0]=Math.min(1,Math.max(0,t[0]-e)),t[1]=Math.min(1,Math.max(0,t[1]-s)),t[2]=Math.min(1,Math.max(0,t[2]+e)),t[3]=Math.min(1,Math.max(0,t[3]+s)),t[2]-=t[0],t[3]-=t[1]}get box(){return this.#t}updateProperty(t,e){return t==="stroke-width"?this.#f(e):null}#f(t){const[e,s]=this.#l();this.#c=t;const[i,n]=this.#l(),[r,o]=[i-e,n-s],h=this.#t;return h[0]-=r,h[1]-=o,h[2]+=2*r,h[3]+=2*o,h}updateParentDimensions([t,e],s){const[i,n]=this.#l();this.#r=t,this.#n=e,this.#h=s;const[r,o]=this.#l(),h=r-i,l=o-n,c=this.#t;return c[0]-=h,c[1]-=l,c[2]+=2*h,c[3]+=2*l,c}updateRotation(t){return this.#e=t,{path:{transform:this.rotationTransform}}}get viewBox(){return this.#t.map(j.svgRound).join(" ")}get defaultProperties(){const[t,e]=this.#t;return{root:{viewBox:this.viewBox},path:{"transform-origin":`${j.svgRound(t)} ${j.svgRound(e)}`}}}get rotationTransform(){const[,,t,e]=this.#t;let s=0,i=0,n=0,r=0,o=0,h=0;switch(this.#e){case 90:i=e/t,n=-t/e,o=t;break;case 180:s=-1,r=-1,o=t,h=e;break;case 270:i=-e/t,n=t/e,h=e;break;default:return""}return`matrix(${s} ${i} ${n} ${r} ${j.svgRound(o)} ${j.svgRound(h)})`}getPathResizingSVGProperties([t,e,s,i]){const[n,r]=this.#l(),[o,h,l,c]=this.#t;if(Math.abs(l-n)<=j.PRECISION||Math.abs(c-r)<=j.PRECISION){const p=t+s/2-(o+l/2),b=e+i/2-(h+c/2);return{path:{"transform-origin":`${j.svgRound(t)} ${j.svgRound(e)}`,transform:`${this.rotationTransform} translate(${p} ${b})`}}}const u=(s-2*n)/(l-2*n),d=(i-2*r)/(c-2*r),f=l/s,g=c/i;return{path:{"transform-origin":`${j.svgRound(o)} ${j.svgRound(h)}`,transform:`${this.rotationTransform} scale(${f} ${g}) translate(${j.svgRound(n)} ${j.svgRound(r)}) scale(${u} ${d}) translate(${j.svgRound(-n)} ${j.svgRound(-r)})`}}}getPathResizedSVGProperties([t,e,s,i]){const[n,r]=this.#l(),o=this.#t,[h,l,c,u]=o;if(o[0]=t,o[1]=e,o[2]=s,o[3]=i,Math.abs(c-n)<=j.PRECISION||Math.abs(u-r)<=j.PRECISION){const b=t+s/2-(h+c/2),m=e+i/2-(l+u/2);for(const{line:v,points:y}of this.#i)j._translate(v,b,m,v),j._translate(y,b,m,y);return{root:{viewBox:this.viewBox},path:{"transform-origin":`${j.svgRound(t)} ${j.svgRound(e)}`,transform:this.rotationTransform||null,d:this.toSVGPath()}}}const d=(s-2*n)/(c-2*n),f=(i-2*r)/(u-2*r),g=-d*(h+n)+t+n,p=-f*(l+r)+e+r;if(d!==1||f!==1||g!==0||p!==0)for(const{line:b,points:m}of this.#i)j._rescale(b,g,p,d,f,b),j._rescale(m,g,p,d,f,m);return{root:{viewBox:this.viewBox},path:{"transform-origin":`${j.svgRound(t)} ${j.svgRound(e)}`,transform:this.rotationTransform||null,d:this.toSVGPath()}}}getPathTranslatedSVGProperties([t,e],s){const[i,n]=s,r=this.#t,o=t-r[0],h=e-r[1];if(this.#r===i&&this.#n===n)for(const{line:l,points:c}of this.#i)j._translate(l,o,h,l),j._translate(c,o,h,c);else{const l=this.#r/i,c=this.#n/n;this.#r=i,this.#n=n;for(const{line:u,points:d}of this.#i)j._rescale(u,o,h,l,c,u),j._rescale(d,o,h,l,c,d);r[2]*=l,r[3]*=c}return r[0]=t,r[1]=e,{root:{viewBox:this.viewBox},path:{d:this.toSVGPath(),"transform-origin":`${j.svgRound(t)} ${j.svgRound(e)}`}}}get defaultSVGProperties(){const t=this.#t;return{root:{viewBox:this.viewBox},rootClass:{draw:!0},path:{d:this.toSVGPath(),"transform-origin":`${j.svgRound(t[0])} ${j.svgRound(t[1])}`,transform:this.rotationTransform||null},bbox:t}}}class Ao extends Fg{#t;constructor(t){super(),this.#t=t,super.updateProperties({fill:"none",stroke:W._defaultLineColor,"stroke-opacity":1,"stroke-width":1,"stroke-linecap":"round","stroke-linejoin":"round","stroke-miterlimit":10})}updateSVGProperty(t,e){t==="stroke-width"&&(e??=this["stroke-width"],e*=this.#t.realScale),super.updateSVGProperty(t,e)}clone(){const t=new Ao(this.#t);return t.updateAll(this),t}}class To extends X{static _type="ink";static _editorType=q.INK;static _defaultDrawingOptions=null;constructor(t){super({...t,name:"inkEditor"}),this._willKeepAspectRatio=!0}static initialize(t,e){W.initialize(t,e),this._defaultDrawingOptions=new Ao(e.viewParameters)}static getDefaultDrawingOptions(t){const e=this._defaultDrawingOptions.clone();return e.updateProperties(t),e}static get supportMultipleDrawings(){return!0}static get typesMap(){return Z(this,"typesMap",new Map([[tt.INK_THICKNESS,"stroke-width"],[tt.INK_COLOR,"stroke"],[tt.INK_OPACITY,"stroke-opacity"]]))}static createDrawerInstance(t,e,s,i,n){return new Ig(t,e,s,i,n,this._defaultDrawingOptions["stroke-width"])}static deserializeDraw(t,e,s,i,n,r){return Wn.deserialize(t,e,s,i,n,r)}static async deserialize(t,e,s){let i=null;if(t instanceof xo){const{data:{inkLists:r,rect:o,rotation:h,id:l,color:c,opacity:u,borderStyle:{rawWidth:d},popupRef:f},parent:{page:{pageNumber:g}}}=t;i=t={annotationType:q.INK,color:Array.from(c),thickness:d,opacity:u,paths:{points:r},boxes:null,pageIndex:g-1,rect:o.slice(0),rotation:h,id:l,deleted:!1,popupRef:f}}const n=await super.deserialize(t,e,s);return n.annotationElementId=t.id||null,n._initialData=i,n}onScaleChanging(){if(!this.parent)return;super.onScaleChanging();const{_drawId:t,_drawingOptions:e,parent:s}=this;e.updateSVGProperty("stroke-width"),s.drawLayer.updateProperties(t,e.toSVGProperties())}static onScaleChangingWhenDrawing(){const t=this._currentParent;t&&(super.onScaleChangingWhenDrawing(),this._defaultDrawingOptions.updateSVGProperty("stroke-width"),t.drawLayer.updateProperties(this._currentDrawId,this._defaultDrawingOptions.toSVGProperties()))}createDrawingOptions({color:t,thickness:e,opacity:s}){this._drawingOptions=To.getDefaultDrawingOptions({stroke:G.makeHexColor(...t),"stroke-width":e,"stroke-opacity":s})}serialize(t=!1){if(this.isEmpty())return null;if(this.deleted)return this.serializeDeleted();const{lines:e,points:s,rect:i}=this.serializeDraw(t),{_drawingOptions:{stroke:n,"stroke-opacity":r,"stroke-width":o}}=this,h={annotationType:q.INK,color:W._colorManager.convert(n),opacity:r,thickness:o,paths:{lines:e,points:s},pageIndex:this.pageIndex,rect:i,rotation:this.rotation,structTreeParentId:this._structTreeParentId};return t?h:this.annotationElementId&&!this.#t(h)?null:(h.id=this.annotationElementId,h)}#t(t){const{color:e,thickness:s,opacity:i,pageIndex:n}=this._initialData;return this._hasBeenMoved||this._hasBeenResized||t.color.some((r,o)=>r!==e[o])||t.thickness!==s||t.opacity!==i||t.pageIndex!==n}renderAnnotationElement(t){const{points:e,rect:s}=this.serializeDraw(!1);return t.updateEdited({rect:s,thickness:this._drawingOptions["stroke-width"],points:e}),null}}class Eo extends W{#t=null;#e=null;#s=null;#i=null;#r=null;#n="";#h=null;#a=null;#c=!1;#l=!1;static _type="stamp";static _editorType=q.STAMP;constructor(t){super({...t,name:"stampEditor"}),this.#i=t.bitmapUrl,this.#r=t.bitmapFile}static initialize(t,e){W.initialize(t,e)}static get supportedTypes(){return Z(this,"supportedTypes",["apng","avif","bmp","gif","jpeg","png","svg+xml","webp","x-icon"].map(e=>`image/${e}`))}static get supportedTypesStr(){return Z(this,"supportedTypesStr",this.supportedTypes.join(","))}static isHandlingMimeForPasting(t){return this.supportedTypes.includes(t)}static paste(t,e){e.pasteEditor(q.STAMP,{bitmapFile:t.getAsFile()})}altTextFinish(){this._uiManager.useNewAltTextFlow&&(this.div.hidden=!1),super.altTextFinish()}get telemetryFinalData(){return{type:"stamp",hasAltText:!!this.altTextData?.altText}}static computeTelemetryFinalData(t){const e=t.get("hasAltText");return{hasAltText:e.get(!0)??0,hasNoAltText:e.get(!1)??0}}#d(t,e=!1){if(!t){this.remove();return}this.#t=t.bitmap,e||(this.#e=t.id,this.#c=t.isSvg),t.file&&(this.#n=t.file.name),this.#o()}#u(){if(this.#s=null,this._uiManager.enableWaiting(!1),!!this.#h){if(this._uiManager.useNewAltTextWhenAddingImage&&this._uiManager.useNewAltTextFlow&&this.#t){this._editToolbar.hide(),this._uiManager.editAltText(this,!0);return}if(!this._uiManager.useNewAltTextWhenAddingImage&&this._uiManager.useNewAltTextFlow&&this.#t){this._reportTelemetry({action:"pdfjs.image.image_added",data:{alt_text_modal:!1,alt_text_type:"empty"}});try{this.mlGuessAltText()}catch{}}this.div.focus()}}async mlGuessAltText(t=null,e=!0){if(this.hasAltTextData())return null;const{mlManager:s}=this._uiManager;if(!s)throw new Error("No ML.");if(!await s.isEnabledFor("altText"))throw new Error("ML isn't enabled for alt text.");const{data:i,width:n,height:r}=t||this.copyCanvas(null,null,!0).imageData,o=await s.guess({name:"altText",request:{data:i,width:n,height:r,channels:i.length/(n*r)}});if(!o)throw new Error("No response from the AI service.");if(o.error)throw new Error("Error from the AI service.");if(o.cancel)return null;if(!o.output)throw new Error("No valid response from the AI service.");const h=o.output;return await this.setGuessedAltText(h),e&&!this.hasAltTextData()&&(this.altTextData={alt:h,decorative:!1}),h}#f(){if(this.#e){this._uiManager.enableWaiting(!0),this._uiManager.imageManager.getFromId(this.#e).then(s=>this.#d(s,!0)).finally(()=>this.#u());return}if(this.#i){const s=this.#i;this.#i=null,this._uiManager.enableWaiting(!0),this.#s=this._uiManager.imageManager.getFromUrl(s).then(i=>this.#d(i)).finally(()=>this.#u());return}if(this.#r){const s=this.#r;this.#r=null,this._uiManager.enableWaiting(!0),this.#s=this._uiManager.imageManager.getFromFile(s).then(i=>this.#d(i)).finally(()=>this.#u());return}const t=document.createElement("input");t.type="file",t.accept=Eo.supportedTypesStr;const e=this._uiManager._signal;this.#s=new Promise(s=>{t.addEventListener("change",async()=>{if(!t.files||t.files.length===0)this.remove();else{this._uiManager.enableWaiting(!0);const i=await this._uiManager.imageManager.getFromFile(t.files[0]);this._reportTelemetry({action:"pdfjs.image.image_selected",data:{alt_text_modal:this._uiManager.useNewAltTextFlow}}),this.#d(i)}s()},{signal:e}),t.addEventListener("cancel",()=>{this.remove(),s()},{signal:e})}).finally(()=>this.#u()),t.click()}remove(){this.#e&&(this.#t=null,this._uiManager.imageManager.deleteId(this.#e),this.#h?.remove(),this.#h=null,this.#a&&(clearTimeout(this.#a),this.#a=null)),super.remove()}rebuild(){if(!this.parent){this.#e&&this.#f();return}super.rebuild(),this.div!==null&&(this.#e&&this.#h===null&&this.#f(),this.isAttachedToDOM||this.parent.add(this))}onceAdded(t){this._isDraggable=!0,t&&this.div.focus()}isEmpty(){return!(this.#s||this.#t||this.#i||this.#r||this.#e)}get isResizable(){return!0}render(){if(this.div)return this.div;let t,e;if(this.width&&(t=this.x,e=this.y),super.render(),this.div.hidden=!0,this.div.setAttribute("role","figure"),this.addAltTextButton(),this.#t?this.#o():this.#f(),this.width&&!this.annotationElementId){const[s,i]=this.parentDimensions;this.setAt(t*s,e*i,this.width*s,this.height*i)}return this._uiManager.addShouldRescale(this),this.div}_onResized(){this.onScaleChanging()}onScaleChanging(){if(!this.parent)return;this.#a!==null&&clearTimeout(this.#a);const t=200;this.#a=setTimeout(()=>{this.#a=null,this.#m()},t)}#o(){const{div:t}=this;let{width:e,height:s}=this.#t;const[i,n]=this.pageDimensions,r=.75;if(this.width)e=this.width*i,s=this.height*n;else if(e>r*i||s>r*n){const c=Math.min(r*i/e,r*n/s);e*=c,s*=c}const[o,h]=this.parentDimensions;this.setDims(e*o/i,s*h/n),this._uiManager.enableWaiting(!1);const l=this.#h=document.createElement("canvas");l.setAttribute("role","img"),this.addContainer(l),this.width=e/i,this.height=s/n,this._initialOptions?.isCentered?this.center():this.fixAndSetPosition(),this._initialOptions=null,(!this._uiManager.useNewAltTextWhenAddingImage||!this._uiManager.useNewAltTextFlow||this.annotationElementId)&&(t.hidden=!1),this.#m(),this.#l||(this.parent.addUndoableEditor(this),this.#l=!0),this._reportTelemetry({action:"inserted_image"}),this.#n&&l.setAttribute("aria-label",this.#n)}copyCanvas(t,e,s=!1){t||(t=224);const{width:i,height:n}=this.#t,r=new ao;let o=this.#t,h=i,l=n,c=null;if(e){if(i>e||n>e){const A=Math.min(e/i,e/n);h=Math.floor(i*A),l=Math.floor(n*A)}c=document.createElement("canvas");const d=c.width=Math.ceil(h*r.sx),f=c.height=Math.ceil(l*r.sy);this.#c||(o=this.#g(d,f));const g=c.getContext("2d");g.filter=this._uiManager.hcmFilter;let p="white",b="#cfcfd8";this._uiManager.hcmFilter!=="none"?b="black":window.matchMedia?.("(prefers-color-scheme: dark)").matches&&(p="#8f8f9d",b="#42414d");const m=15,v=m*r.sx,y=m*r.sy,_=new OffscreenCanvas(v*2,y*2),S=_.getContext("2d");S.fillStyle=p,S.fillRect(0,0,v*2,y*2),S.fillStyle=b,S.fillRect(0,0,v,y),S.fillRect(v,y,v,y),g.fillStyle=g.createPattern(_,"repeat"),g.fillRect(0,0,d,f),g.drawImage(o,0,0,o.width,o.height,0,0,d,f)}let u=null;if(s){let d,f;if(r.symmetric&&o.width<t&&o.height<t)d=o.width,f=o.height;else if(o=this.#t,i>t||n>t){const b=Math.min(t/i,t/n);d=Math.floor(i*b),f=Math.floor(n*b),this.#c||(o=this.#g(d,f))}const p=new OffscreenCanvas(d,f).getContext("2d",{willReadFrequently:!0});p.drawImage(o,0,0,o.width,o.height,0,0,d,f),u={width:d,height:f,data:p.getImageData(0,0,d,f).data}}return{canvas:c,width:h,height:l,imageData:u}}#g(t,e){const{width:s,height:i}=this.#t;let n=s,r=i,o=this.#t;for(;n>2*t||r>2*e;){const h=n,l=r;n>2*t&&(n=n>=16384?Math.floor(n/2)-1:Math.ceil(n/2)),r>2*e&&(r=r>=16384?Math.floor(r/2)-1:Math.ceil(r/2));const c=new OffscreenCanvas(n,r);c.getContext("2d").drawImage(o,0,0,h,l,0,0,n,r),o=c.transferToImageBitmap()}return o}#m(){const[t,e]=this.parentDimensions,{width:s,height:i}=this,n=new ao,r=Math.ceil(s*t*n.sx),o=Math.ceil(i*e*n.sy),h=this.#h;if(!h||h.width===r&&h.height===o)return;h.width=r,h.height=o;const l=this.#c?this.#t:this.#g(r,o),c=h.getContext("2d");c.filter=this._uiManager.hcmFilter,c.drawImage(l,0,0,l.width,l.height,0,0,r,o)}getImageForAltText(){return this.#h}#p(t){if(t){if(this.#c){const i=this._uiManager.imageManager.getSvgUrl(this.#e);if(i)return i}const e=document.createElement("canvas");return{width:e.width,height:e.height}=this.#t,e.getContext("2d").drawImage(this.#t,0,0),e.toDataURL()}if(this.#c){const[e,s]=this.pageDimensions,i=Math.round(this.width*e*js.PDF_TO_CSS_UNITS),n=Math.round(this.height*s*js.PDF_TO_CSS_UNITS),r=new OffscreenCanvas(i,n);return r.getContext("2d").drawImage(this.#t,0,0,this.#t.width,this.#t.height,0,0,i,n),r.transferToImageBitmap()}return structuredClone(this.#t)}static async deserialize(t,e,s){let i=null;if(t instanceof Fl){const{data:{rect:g,rotation:p,id:b,structParent:m,popupRef:v},container:y,parent:{page:{pageNumber:_}}}=t,S=y.querySelector("canvas"),A=s.imageManager.getFromCanvas(y.id,S);S.remove();const T=(await e._structTree.getAriaAttributes(`${io}${b}`))?.get("aria-label")||"";i=t={annotationType:q.STAMP,bitmapId:A.id,bitmap:A.bitmap,pageIndex:_-1,rect:g.slice(0),rotation:p,id:b,deleted:!1,accessibilityData:{decorative:!1,altText:T},isSvg:!1,structParent:m,popupRef:v}}const n=await super.deserialize(t,e,s),{rect:r,bitmap:o,bitmapUrl:h,bitmapId:l,isSvg:c,accessibilityData:u}=t;l&&s.imageManager.isValidId(l)?(n.#e=l,o&&(n.#t=o)):n.#i=h,n.#c=c;const[d,f]=n.pageDimensions;return n.width=(r[2]-r[0])/d,n.height=(r[3]-r[1])/f,n.annotationElementId=t.id||null,u&&(n.altTextData=u),n._initialData=i,n.#l=!!i,n}serialize(t=!1,e=null){if(this.isEmpty())return null;if(this.deleted)return this.serializeDeleted();const s={annotationType:q.STAMP,bitmapId:this.#e,pageIndex:this.pageIndex,rect:this.getRect(0,0),rotation:this.rotation,isSvg:this.#c,structTreeParentId:this._structTreeParentId};if(t)return s.bitmapUrl=this.#p(!0),s.accessibilityData=this.serializeAltText(!0),s;const{decorative:i,altText:n}=this.serializeAltText(!1);if(!i&&n&&(s.accessibilityData={type:"Figure",alt:n}),this.annotationElementId){const o=this.#b(s);if(o.isSame)return null;o.isSameAltText?delete s.accessibilityData:s.accessibilityData.structParent=this._initialData.structParent??-1}if(s.id=this.annotationElementId,e===null)return s;e.stamps||=new Map;const r=this.#c?(s.rect[2]-s.rect[0])*(s.rect[3]-s.rect[1]):null;if(!e.stamps.has(this.#e))e.stamps.set(this.#e,{area:r,serialized:s}),s.bitmap=this.#p(!1);else if(this.#c){const o=e.stamps.get(this.#e);r>o.area&&(o.area=r,o.serialized.bitmap.close(),o.serialized.bitmap=this.#p(!1))}return s}#b(t){const{pageIndex:e,accessibilityData:{altText:s}}=this._initialData,i=t.pageIndex===e,n=(t.accessibilityData?.alt||"")===s;return{isSame:!this._hasBeenMoved&&!this._hasBeenResized&&i&&n,isSameAltText:n}}renderAnnotationElement(t){return t.updateEdited({rect:this.getRect(0,0)}),null}}class Ve{#t;#e=!1;#s=null;#i=null;#r=null;#n=new Map;#h=!1;#a=!1;#c=!1;#l=null;#d=null;#u=null;#f=null;#o;static _initialized=!1;static#g=new Map([Et,To,Eo,_t].map(t=>[t._editorType,t]));constructor({uiManager:t,pageIndex:e,div:s,structTreeLayer:i,accessibilityManager:n,annotationLayer:r,drawLayer:o,textLayer:h,viewport:l,l10n:c}){const u=[...Ve.#g.values()];if(!Ve._initialized){Ve._initialized=!0;for(const d of u)d.initialize(c,t)}t.registerEditorTypes(u),this.#o=t,this.pageIndex=e,this.div=s,this.#t=n,this.#s=r,this.viewport=l,this.#u=h,this.drawLayer=o,this._structTree=i,this.#o.addLayer(this)}get isEmpty(){return this.#n.size===0}get isInvisible(){return this.isEmpty&&this.#o.getMode()===q.NONE}updateToolbar(t){this.#o.updateToolbar(t)}updateMode(t=this.#o.getMode()){switch(this.#v(),t){case q.NONE:this.disableTextSelection(),this.togglePointerEvents(!1),this.toggleAnnotationLayerPointerEvents(!0),this.disableClick();return;case q.INK:this.disableTextSelection(),this.togglePointerEvents(!0),this.enableClick();break;case q.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 Ve.#g.values())e.toggle(`${s._type}Editing`,t===s._editorType);this.div.hidden=!1}hasTextLayer(t){return t===this.#u?.div}setEditingState(t){this.#o.setEditingState(t)}addCommands(t){this.#o.addCommands(t)}cleanUndoStack(t){this.#o.cleanUndoStack(t)}toggleDrawing(t=!1){this.div.classList.toggle("drawing",!t)}togglePointerEvents(t=!1){this.div.classList.toggle("disabled",!t)}toggleAnnotationLayerPointerEvents(t=!1){this.#s?.div.classList.toggle("disabled",!t)}async enable(){this.#c=!0,this.div.tabIndex=0,this.togglePointerEvents(!0);const t=new Set;for(const s of this.#n.values())s.enableEditing(),s.show(!0),s.annotationElementId&&(this.#o.removeChangedExistingAnnotation(s),t.add(s.annotationElementId));if(!this.#s){this.#c=!1;return}const e=this.#s.getEditableAnnotations();for(const s of e){if(s.hide(),this.#o.isDeletedAnnotationElement(s.data.id)||t.has(s.data.id))continue;const i=await this.deserialize(s);i&&(this.addOrRebuild(i),i.enableEditing())}this.#c=!1}disable(){this.#a=!0,this.div.tabIndex=-1,this.togglePointerEvents(!1);const t=new Map,e=new Map;for(const i of this.#n.values())if(i.disableEditing(),!!i.annotationElementId){if(i.serialize()!==null){t.set(i.annotationElementId,i);continue}else e.set(i.annotationElementId,i);this.getEditableAnnotation(i.annotationElementId)?.show(),i.remove()}if(this.#s){const i=this.#s.getEditableAnnotations();for(const n of i){const{id:r}=n.data;if(this.#o.isDeletedAnnotationElement(r))continue;let o=e.get(r);if(o){o.resetAnnotationElement(n),o.show(!1),n.show();continue}o=t.get(r),o&&(this.#o.addChangedExistingAnnotation(o),o.renderAnnotationElement(n)&&o.show(!1)),n.show()}}this.#v(),this.isEmpty&&(this.div.hidden=!0);const{classList:s}=this.div;for(const i of Ve.#g.values())s.remove(`${i._type}Editing`);this.disableTextSelection(),this.toggleAnnotationLayerPointerEvents(!0),this.#a=!1}getEditableAnnotation(t){return this.#s?.getEditableAnnotation(t)||null}setActiveEditor(t){this.#o.getActive()!==t&&this.#o.setActiveEditor(t)}enableTextSelection(){if(this.div.tabIndex=-1,this.#u?.div&&!this.#f){this.#f=new AbortController;const t=this.#o.combinedSignal(this.#f);this.#u.div.addEventListener("pointerdown",this.#m.bind(this),{signal:t}),this.#u.div.classList.add("highlighting")}}disableTextSelection(){this.div.tabIndex=0,this.#u?.div&&this.#f&&(this.#f.abort(),this.#f=null,this.#u.div.classList.remove("highlighting"))}#m(t){this.#o.unselectAll();const{target:e}=t;if(e===this.#u.div||(e.getAttribute("role")==="img"||e.classList.contains("endOfContent"))&&this.#u.div.contains(e)){const{isMac:s}=Vt.platform;if(t.button!==0||t.ctrlKey&&s)return;this.#o.showAllEditors("highlight",!0,!0),this.#u.div.classList.add("free"),this.toggleDrawing(),_t.startHighlighting(this,this.#o.direction==="ltr",{target:this.#u.div,x:t.x,y:t.y}),this.#u.div.addEventListener("pointerup",()=>{this.#u.div.classList.remove("free"),this.toggleDrawing(!0)},{once:!0,signal:this.#o._signal}),t.preventDefault()}}enableClick(){if(this.#i)return;this.#i=new AbortController;const t=this.#o.combinedSignal(this.#i);this.div.addEventListener("pointerdown",this.pointerdown.bind(this),{signal:t});const e=this.pointerup.bind(this);this.div.addEventListener("pointerup",e,{signal:t}),this.div.addEventListener("pointercancel",e,{signal:t})}disableClick(){this.#i?.abort(),this.#i=null}attach(t){this.#n.set(t.id,t);const{annotationElementId:e}=t;e&&this.#o.isDeletedAnnotationElement(e)&&this.#o.removeDeletedAnnotationElement(t)}detach(t){this.#n.delete(t.id),this.#t?.removePointerInTextLayer(t.contentDiv),!this.#a&&t.annotationElementId&&this.#o.addDeletedAnnotationElement(t)}remove(t){this.detach(t),this.#o.removeEditor(t),t.div.remove(),t.isAttachedToDOM=!1}changeParent(t){t.parent!==this&&(t.parent&&t.annotationElementId&&(this.#o.addDeletedAnnotationElement(t.annotationElementId),W.deleteAnnotationElement(t),t.annotationElementId=null),this.attach(t),t.parent?.detach(t),t.setParent(this),t.div&&t.isAttachedToDOM&&(t.div.remove(),this.div.append(t.div)))}add(t){if(!(t.parent===this&&t.isAttachedToDOM)){if(this.changeParent(t),this.#o.addEditor(t),this.attach(t),!t.isAttachedToDOM){const e=t.render();this.div.append(e),t.isAttachedToDOM=!0}t.fixAndSetPosition(),t.onceAdded(!this.#c),this.#o.addToAnnotationStorage(t),t._reportTelemetry(t.telemetryInitialData)}}moveEditorInDOM(t){if(!t.isAttachedToDOM)return;const{activeElement:e}=document;t.div.contains(e)&&!this.#r&&(t._focusEventsAllowed=!1,this.#r=setTimeout(()=>{this.#r=null,t.div.contains(document.activeElement)?t._focusEventsAllowed=!0:(t.div.addEventListener("focusin",()=>{t._focusEventsAllowed=!0},{once:!0,signal:this.#o._signal}),e.focus())},0)),t._structTreeParentId=this.#t?.moveElementInDOM(this.div,t.div,t.contentDiv,!0)}addOrRebuild(t){t.needsToBeRebuilt()?(t.parent||=this,t.rebuild(),t.show()):this.add(t)}addUndoableEditor(t){const e=()=>t._uiManager.rebuild(t),s=()=>{t.remove()};this.addCommands({cmd:e,undo:s,mustExec:!1})}getNextId(){return this.#o.getId()}get#p(){return Ve.#g.get(this.#o.getMode())}combinedSignal(t){return this.#o.combinedSignal(t)}#b(t){const e=this.#p;return e?new e.prototype.constructor(t):null}canCreateNewEmptyEditor(){return this.#p?.canCreateNewEmptyEditor()}pasteEditor(t,e){this.#o.updateToolbar(t),this.#o.updateMode(t);const{offsetX:s,offsetY:i}=this.#_(),n=this.getNextId(),r=this.#b({parent:this,id:n,x:s,y:i,uiManager:this.#o,isCentered:!0,...e});r&&this.add(r)}async deserialize(t){return await Ve.#g.get(t.annotationType??t.annotationEditorType)?.deserialize(t,this,this.#o)||null}createAndAddNewEditor(t,e,s={}){const i=this.getNextId(),n=this.#b({parent:this,id:i,x:t.offsetX,y:t.offsetY,uiManager:this.#o,isCentered:e,...s});return n&&this.add(n),n}#_(){const{x:t,y:e,width:s,height:i}=this.div.getBoundingClientRect(),n=Math.max(0,t),r=Math.max(0,e),o=Math.min(window.innerWidth,t+s),h=Math.min(window.innerHeight,e+i),l=(n+o)/2-t,c=(r+h)/2-e,[u,d]=this.viewport.rotation%180===0?[l,c]:[c,l];return{offsetX:u,offsetY:d}}addNewEditor(){this.createAndAddNewEditor(this.#_(),!0)}setSelected(t){this.#o.setSelected(t)}toggleSelected(t){this.#o.toggleSelected(t)}unselect(t){this.#o.unselect(t)}pointerup(t){const{isMac:e}=Vt.platform;if(!(t.button!==0||t.ctrlKey&&e)&&t.target===this.div&&this.#h&&(this.#h=!1,!(this.#p?.isDrawer&&this.#p.supportMultipleDrawings))){if(!this.#e){this.#e=!0;return}if(this.#o.getMode()===q.STAMP){this.#o.unselectAll();return}this.createAndAddNewEditor(t,!1)}}pointerdown(t){if(this.#o.getMode()===q.HIGHLIGHT&&this.enableTextSelection(),this.#h){this.#h=!1;return}const{isMac:e}=Vt.platform;if(t.button!==0||t.ctrlKey&&e||t.target!==this.div)return;if(this.#h=!0,this.#p?.isDrawer){this.startDrawingSession(t);return}const s=this.#o.getActive();this.#e=!s||s.isEmpty()}startDrawingSession(t){if(this.div.focus(),this.#l){this.#p.startDrawing(this,this.#o,!1,t);return}this.#o.setCurrentDrawingSession(this),this.#l=new AbortController;const e=this.#o.combinedSignal(this.#l);this.div.addEventListener("blur",({relatedTarget:s})=>{s&&!this.div.contains(s)&&(this.#d=null,this.commitOrRemove())},{signal:e}),this.#p.startDrawing(this,this.#o,!1,t)}pause(t){if(t){const{activeElement:e}=document;this.div.contains(e)&&(this.#d=e);return}this.#d&&setTimeout(()=>{this.#d?.focus(),this.#d=null},0)}endDrawingSession(t=!1){return this.#l?(this.#o.setCurrentDrawingSession(null),this.#l.abort(),this.#l=null,this.#d=null,this.#p.endDrawing(t)):null}findNewParent(t,e,s){const i=this.#o.findParent(e,s);return i===null||i===this?!1:(i.changeParent(t),!0)}commitOrRemove(){return this.#l?(this.endDrawingSession(),!0):!1}onScaleChanging(){this.#l&&this.#p.onScaleChangingWhenDrawing(this)}destroy(){this.commitOrRemove(),this.#o.getActive()?.parent===this&&(this.#o.commitOrRemove(),this.#o.setActiveEditor(null)),this.#r&&(clearTimeout(this.#r),this.#r=null);for(const t of this.#n.values())this.#t?.removePointerInTextLayer(t.contentDiv),t.setParent(null),t.isAttachedToDOM=!1,t.div.remove();this.div=null,this.#n.clear(),this.#o.removeLayer(this)}#v(){for(const t of this.#n.values())t.isEmpty()&&t.remove()}render({viewport:t}){this.viewport=t,ms(this.div,t);for(const e of this.#o.getEditors(this.pageIndex))this.add(e),e.rebuild();this.updateMode()}update({viewport:t}){this.#o.commitOrRemove(),this.#v();const e=this.viewport.rotation,s=t.rotation;if(this.viewport=t,ms(this.div,{rotation:s}),e!==s)for(const i of this.#n.values())i.rotate(s)}get pageDimensions(){const{pageWidth:t,pageHeight:e}=this.viewport.rawDims;return[t,e]}get scale(){return this.#o.viewParameters.realScale}}class Xt{#t=null;#e=0;#s=new Map;#i=new Map;constructor({pageIndex:t}){this.pageIndex=t}setParent(t){if(!this.#t){this.#t=t;return}if(this.#t!==t){if(this.#s.size>0)for(const e of this.#s.values())e.remove(),t.append(e);this.#t=t}}static get _svgFactory(){return Z(this,"_svgFactory",new _o)}static#r(t,[e,s,i,n]){const{style:r}=t;r.top=`${100*s}%`,r.left=`${100*e}%`,r.width=`${100*i}%`,r.height=`${100*n}%`}#n(){const t=Xt._svgFactory.create(1,1,!0);return this.#t.append(t),t.setAttribute("aria-hidden",!0),t}#h(t,e){const s=Xt._svgFactory.createElement("clipPath");t.append(s);const i=`clip_${e}`;s.setAttribute("id",i),s.setAttribute("clipPathUnits","objectBoundingBox");const n=Xt._svgFactory.createElement("use");return s.append(n),n.setAttribute("href",`#${e}`),n.classList.add("clip"),i}#a(t,e){for(const[s,i]of Object.entries(e))i===null?t.removeAttribute(s):t.setAttribute(s,i)}draw(t,e=!1,s=!1){const i=this.#e++,n=this.#n(),r=Xt._svgFactory.createElement("defs");n.append(r);const o=Xt._svgFactory.createElement("path");r.append(o);const h=`path_p${this.pageIndex}_${i}`;o.setAttribute("id",h),o.setAttribute("vector-effect","non-scaling-stroke"),e&&this.#i.set(i,o);const l=s?this.#h(r,h):null,c=Xt._svgFactory.createElement("use");return n.append(c),c.setAttribute("href",`#${h}`),this.updateProperties(n,t),this.#s.set(i,n),{id:i,clipPathId:`url(#${l})`}}drawOutline(t,e){const s=this.#e++,i=this.#n(),n=Xt._svgFactory.createElement("defs");i.append(n);const r=Xt._svgFactory.createElement("path");n.append(r);const o=`path_p${this.pageIndex}_${s}`;r.setAttribute("id",o),r.setAttribute("vector-effect","non-scaling-stroke");let h;if(e){const u=Xt._svgFactory.createElement("mask");n.append(u),h=`mask_p${this.pageIndex}_${s}`,u.setAttribute("id",h),u.setAttribute("maskUnits","objectBoundingBox");const d=Xt._svgFactory.createElement("rect");u.append(d),d.setAttribute("width","1"),d.setAttribute("height","1"),d.setAttribute("fill","white");const f=Xt._svgFactory.createElement("use");u.append(f),f.setAttribute("href",`#${o}`),f.setAttribute("stroke","none"),f.setAttribute("fill","black"),f.setAttribute("fill-rule","nonzero"),f.classList.add("mask")}const l=Xt._svgFactory.createElement("use");i.append(l),l.setAttribute("href",`#${o}`),h&&l.setAttribute("mask",`url(#${h})`);const c=l.cloneNode();return i.append(c),l.classList.add("mainOutline"),c.classList.add("secondaryOutline"),this.updateProperties(i,t),this.#s.set(s,i),s}finalizeDraw(t,e){this.#i.delete(t),this.updateProperties(t,e)}updateProperties(t,e){if(!e)return;const{root:s,bbox:i,rootClass:n,path:r}=e,o=typeof t=="number"?this.#s.get(t):t;if(o){if(s&&this.#a(o,s),i&&Xt.#r(o,i),n){const{classList:h}=o;for(const[l,c]of Object.entries(n))h.toggle(l,c)}if(r){const l=o.firstChild.firstChild;this.#a(l,r)}}}updateParent(t,e){if(e===this)return;const s=this.#s.get(t);s&&(e.#t.append(s),this.#s.delete(t),e.#s.set(t,s))}remove(t){this.#i.delete(t),this.#t!==null&&(this.#s.get(t).remove(),this.#s.delete(t))}destroy(){this.#t=null;for(const t of this.#s.values())t.remove();this.#s.clear(),this.#i.clear()}}globalThis.pdfjsTestingUtils={HighlightOutliner:So},Y.AbortException,Y.AnnotationEditorLayer,Y.AnnotationEditorParamsType,Y.AnnotationEditorType,Y.AnnotationEditorUIManager,Y.AnnotationLayer,Y.AnnotationMode,Y.ColorPicker,Y.DOMSVGFactory,Y.DrawLayer,Y.FeatureTest;var Ng=Y.GlobalWorkerOptions;Y.ImageKind,Y.InvalidPDFException,Y.MissingPDFException,Y.OPS,Y.OutputScale,Y.PDFDataRangeTransport,Y.PDFDateString,Y.PDFWorker,Y.PasswordResponses,Y.PermissionFlag,Y.PixelsPerInch,Y.RenderingCancelledException,Y.TextLayer,Y.TouchManager,Y.UnexpectedResponseException,Y.Util,Y.VerbosityLevel,Y.XfaLayer,Y.build,Y.createValidAbsoluteUrl,Y.fetchData;var jg=Y.getDocument;Y.getFilenameFromUrl,Y.getPdfFilenameFromUrl,Y.getXfaPageViewport,Y.isDataScheme,Y.isPdfFile,Y.noContextMenu,Y.normalizeUnicode,Y.setLayerDimensions,Y.shadow,Y.stopEvent;var Bg=Y.version;let Nl=null;function Hg(){const a=document.createElement("div");a.style.width="1in",document.body.append(a);const t=a.offsetWidth;return a.remove(),t}function zg(){const a=Nl??Hg();return Nl=a,a/72}function Gg(a,t=500){if(typeof a!="function")throw new TypeError("The first argument is not a function.");let e=null;return function(...s){e&&clearTimeout(e),e=setTimeout(()=>{e=null,a.apply(this,s)},t)}}function Vg(a){return a.arrayBuffer?a.arrayBuffer():new Promise((t,e)=>{const s=new FileReader;s.addEventListener("load",()=>{const i=s.result;if(!(i instanceof ArrayBuffer)){e(new Error("Failed to read file as ArrayBuffer."));return}t(i)}),s.addEventListener("error",e),s.readAsArrayBuffer(a)})}jl()||(Ng.workerSrc=`https://cdnjs.cloudflare.com/ajax/libs/pdf.js/${Bg}/pdf.worker.min.mjs`);function jl(){try{return typeof OffscreenCanvas<"u"&&typeof HTMLCanvasElement<"u"&&typeof HTMLCanvasElement.prototype.transferControlToOffscreen=="function"&&globalThis.self===window.top}catch{return!1}}async function Wg({page:a,data:t,scale:e,password:s},i){const n=zg()/window.devicePixelRatio;if(jl()){const r=new Worker(new URL(""+(typeof document>"u"&&typeof location>"u"?require("url").pathToFileURL(__dirname+"/assets/pdfjs.worker-DuXj-zBo.js").href:new URL("assets/pdfjs.worker-DuXj-zBo.js",typeof document>"u"?location.href:document.currentScript&&document.currentScript.tagName.toUpperCase()==="SCRIPT"&&document.currentScript.src||document.baseURI).href),typeof document>"u"&&typeof location>"u"?require("url").pathToFileURL(__filename).href:typeof document>"u"?location.href:mt&&mt.tagName.toUpperCase()==="SCRIPT"&&mt.src||new URL("pdf-canvas.umd.js",document.baseURI).href),{type:"module"});return r.postMessage({data:t,password:s,id:i,page:a,units:n,scale:e}),await new Promise(h=>{r.addEventListener("message",l=>{if(l.data.status!=="success")return;const{bitmap:c,width:u,height:d,pages:f}=l.data;if(c){const g=document.createElement("canvas"),p=g.getContext("bitmaprenderer");g.width=u,g.height=d,p?.transferFromImageBitmap(c),h({pages:f,canvas:g})}else h({pages:f,canvas:null})})})}else{const r=await Vg(t),o=await jg({data:r,password:s}).promise,h=o.numPages;if(!i)return{canvas:null,pages:h};const l=await o.getPage(a),c=l.getViewport({scale:e}),u=document.createElement("canvas"),f={canvasContext:u.getContext("2d"),viewport:c,transform:[n,0,0,n,0,0]};return u.width=Math.floor(c.width*n),u.height=Math.floor(c.height*n),l.render(f).promise.then(()=>({canvas:u,pages:h}))}}const Ut=new Map;function Xg(a){const t=new jr(a);return Ut.set(a,t),t}function Ug(a){const t=Date.now();return{PDFId:`${a.name}-${t}`,name:a.name.replace(/.pdf/,""),updateDate:t,data:a}}async function Yg({src:a},t,e){if(!a||!e)return null;const{objects:s,options:i}=await Td(a),n=s.filter(o=>o!==null),r=Vu.groupSVGElements(n,i);return n.forEach(o=>{o.stroke=e}),r.hoverCursor="pointer",r.stroke=`${e}-${t}`,r}function $g(a,t){if(!Ut.get(a))return;const s=1/3,i=ep(t,s);Hl(a,i,s)}async function qg(a,t){const e=Date.now(),i={PDFId:`${a.name}-${e}`,name:a.name.replace(/.png|.jpg|.jpeg/,""),updateDate:e,data:a};return t&&Bl(t,{data:a}),{...i,pages:1}}async function Bl(a,{data:t,scale:e=.5}){if(!Ut.get(a))return;const i=URL.createObjectURL(t),n=await Rt.fromURL(i);n.scale(e),Hl(a,n,e),URL.revokeObjectURL(i)}function Hl(a,t,e){const s=Ut.get(a);s&&(s.setWidth(t.width*e),s.setHeight(t.height*e),s.backgroundImage=t,s.renderAll())}function Kg(a,t){if(!t)return;const{oCoords:e}=a;if(!e)return;const{x:s,y:i}=e.tl.touchCorner.tl,{height:n,width:r,scaleY:o,scaleX:h}=t;t.top=i-n*o/2,t.left=s-r*h/2,t.setCoords()}function Jg(a,t,e){!e||!a||(e.scale(1/t),Kg(a,e))}function Zg(a,t){if(!a)return;const e=a._cornerSize||6;a.borderScaleFactor=1/t,a.cornerSize=e*(1/t),a.touchCornerSize=e*4*(1/t),a.setCoords()}function Qg(a){const t=Ut.get(a);t&&(t.discardActiveObject(),t.renderAll())}function tp(a){const t=Ut.get(a);t&&(t.clear(),Ut.delete(a))}function ep(a,t){return new Rt(a,{scaleX:t,scaleY:t})}function ko(a,t){if(!t)return;const{left:e,top:s,scaleX:i,scaleY:n,width:r,height:o}=a,h=t.x*r*i,l=t.y*o*n;a.set({left:e-h,top:s-l})}function zl(a,t,e){const s=a.type;return{"application/pdf":sp,"image/png":Vl,"image/jpeg":Vl}[s]?.(a,t,e)??Promise.reject(new Error(`Unsupported ${s} file type.`))}async function sp(a,t,e){const s=Ug(a),i=await Gl({page:1,data:a,scale:.8,password:t},e);return{...s,pages:i}}function Gl(a,t){return Wg(a,t).then(({canvas:e,pages:s})=>(e&&t&&$g(t,e),s))}async function Vl(a,t,e){return await qg(a,e)}function ip(a,t){const e=Ut.get(a);if(!e)return;const s=e.getActiveObject();s&&(s instanceof ee?s.forEachObject(i=>{i.set(t)}):s.set(t),e.renderAll())}async function np(a,t){const e=Ut.get(a);if(!e)return;const s=e?.getActiveObject();if(!s)return;const i=await s.clone(ac);i instanceof ee?i.forEachObject(n=>{e.add(n),t(e,n)}):(e.add(i),t(e,i)),ko(i,{x:-.1,y:-.1}),e.setActiveObject(i)}function rp(a){const t=Ut.get(a);if(!t)return;const e=t.getActiveObject();e&&(e instanceof ee?(e.forEachObject(s=>{t.remove(s)}),t.discardActiveObject()):t.remove(e))}function Wl(a){const{id:t="",selectionOptions:e,pointerDown:s,pointerMove:i,pointerUp:n,selectionCreated:r,selectionCleared:o}=a||{},h=J.useRef(null),l=J.useRef(null),c=J.useRef(1),u=J.useRef({...oc});function d(){if(!t||Ut.has(t))return;const O=Xg(t);return O.on("selection:created",D=>{if(r?.(D),D.selected.length<=1)return;const z=O.getActiveObject();z&&(l.current=z,e?.value&&l.current.set(e.value),l.current._cornerSize=l.current.cornerSize,S(c.current))}),O.on("selection:cleared",D=>{o?.(D),T(O)}),s&&O.on("mouse:down",s),i&&O.on("mouse:move",i),n&&O.on("mouse:up",n),O}function f(O,D){return zl(O,D,t)}function g(O){return Gl(O,t)}function p({data:O,scale:D=.5}){return Bl(t,{data:O,scale:D})}async function b(O,D,z){const M=Ut.get(t);if(!M)return;const R=await Rt.fromURL(O,{},{...ic,...D});ko(R,z),M.add(R),v(M,R),M.setActiveObject(R)}function m(O,D,z){const M=Ut.get(t);if(!M)return;const R=new Dt(O,{...nc,...D});ko(R,z),M.add(R),v(M,R),M.setActiveObject(R)}function v(O,D){D.on("selected",z=>y({canvas:O,target:z.target})),D.on("modified",z=>y({canvas:O,target:z.target})),D.on("scaling",()=>T(O)),D.on("moving",()=>T(O)),D.on("rotating",()=>T(O)),D._cornerSize=D._cornerSize??D.cornerSize}async function y({canvas:O,target:D,stroke:z=u.current.stroke,uuid:M=Date.now()}){if(O.getActiveObjects().length>1||h.current?.stroke===`${z}-${M}`)return;const U=await Yg(u.current,M,z);T(O),h.current=U,l.current=D,_(O,D,M),S(c.current,!0),U&&O.add(U)}function _(O,D,z){h.current&&(h.current.on("selected",()=>{O.remove(D),T(O)}),h.current.on("mouseover",()=>{y({canvas:O,target:D,stroke:u.current.hoverStroke,uuid:z})}),h.current.on("mouseout",()=>{y({canvas:O,target:D,stroke:u.current.stroke,uuid:z})}))}function S(O,D=!1){const z=Ut.get(t);c.current=O,z&&(Zg(l.current,O),Jg(l.current,O,h.current),!D&&z.renderAll())}function A(O){if(!O)return;u.current={...u.current,...O};const D=Ut.get(t);!h||!l.current||!D||y({target:l.current,canvas:D})}function T(O){l.current=null,h.current&&(O.remove(h.current),h.current=null)}function k(){Qg(t)}function P(){tp(t)}function B(O){ip(t,O)}function F(){return np(t,v)}function I(){rp(t)}return{createCanvas:d,loadFile:f,specifyPage:g,renderImage:p,addFabric:b,addTextFabric:m,clearActive:k,deleteCanvas:P,scaleFabric:S,setCloseSvgOptions:A,setActiveFabric:B,copyActiveFabric:F,deleteActiveFabric:I}}function op(a){const t=J.useRef(0),e=Gg(()=>{t.current!==window.innerWidth&&(t.current=window.innerWidth,a())});J.useEffect(()=>(window.addEventListener("resize",e),()=>window.removeEventListener("resize",e)),[])}const ap=J.forwardRef(hp);function hp({file:a,page:t=1,canvasId:e="PDF-canvas",fileZoom:s=1,fileScale:i=1,canvasScale:n=1,canvasClass:r="",isDrop:o=!1,password:h,dropTextOptions:l,dropImageOptions:c,closeSvgOptions:u,selectionOptions:d,manualReload:f,onLoaded:g,onReload:p,onPointerDown:b,onPointerMove:m,onPointerUp:v,onSelectionCreated:y,onSelectionCleared:_},S){const A=J.useRef(null),T=`${e}-${t-1}`,k=J.useMemo(()=>s*n,[s,n]),P=J.useMemo(()=>({...rc,...d}),[d]),{createCanvas:B,specifyPage:F,addFabric:I,addTextFabric:O,renderImage:D,clearActive:z,deleteCanvas:M,scaleFabric:R,setActiveFabric:U,setCloseSvgOptions:ht,copyActiveFabric:dt,deleteActiveFabric:E}=Wl({id:T,selectionOptions:P,pointerDown:b,pointerMove:m,pointerUp:v,selectionCreated:y,selectionCleared:_});op(rt);async function H(){globalThis.requestAnimationFrame(async()=>{if(B(),a.data?.type.startsWith("image/")){const kt=a.data;kt&&D({data:kt,scale:i/3}),g?.();return}const N=a.data;N&&await F({page:t,data:N,scale:i,password:h}),g?.()})}function V(N){if(N.preventDefault(),N.stopPropagation(),!o||!N.dataTransfer)return;const{dataTransfer:ft,nativeEvent:kt}=N,{offsetX:Zt,offsetY:lp}=kt,Xl=ft.getData("text/plain"),Ul=ft.getData("text/uri-list"),Yl=ft.getData("custom/offset"),$l=Yl?JSON.parse(Yl):null,ql={top:lp,left:Zt},Kl={x:$l?.offsetX??0,y:$l?.offsetY??0};Ul?Q(Ul,ql,Kl):Xl&&Mt(Xl,ql,Kl)}function Q(N,ft,kt){I(N,{...c,...ft},kt)}function Mt(N,ft,kt){O(N,{...l,...ft},kt)}function rt(){f||H(),p?.()}return J.useImperativeHandle(S,()=>({reload:H,addImage:Q,addText:Mt,clearActive:z,deleteCanvas:M,setActiveFabric:U,copyActiveFabric:dt,deleteActiveFabric:E,canvasRef:A})),J.useEffect(()=>{rt()},[i,t,a,h]),J.useEffect(()=>{R(k)},[k]),J.useEffect(()=>{ht(u)},[u]),J.useEffect(()=>()=>M(),[]),Ro.jsx("div",{style:{transform:`scale(${k})`},onDragOver:N=>N.preventDefault(),onDragEnter:N=>N.preventDefault(),onDrop:V,children:Ro.jsx("canvas",{id:T,ref:A,className:r})})}st.default=ap,st.loadFile=zl,st.useFabric=Wl,Object.defineProperties(st,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}));
|
|
520
|
+
`)){const r=document.createElement("div");r.append(n?document.createTextNode(n):document.createElement("br")),e.append(r)}const i=Et._internalPadding*this.parentScale;return t.updateEdited({rect:this.getRect(i,i),popupContent:this.#e}),e}resetAnnotationElement(t){super.resetAnnotationElement(t),t.resetEdited()}}class j{static PRECISION=1e-4;toSVGPath(){at("Abstract method `toSVGPath` must be implemented.")}get box(){at("Abstract getter `box` must be implemented.")}serialize(t,e){at("Abstract method `serialize` must be implemented.")}static _rescale(t,e,s,i,n,r){r||=new Float32Array(t.length);for(let o=0,h=t.length;o<h;o+=2)r[o]=e+t[o]*i,r[o+1]=s+t[o+1]*n;return r}static _rescaleAndSwap(t,e,s,i,n,r){r||=new Float32Array(t.length);for(let o=0,h=t.length;o<h;o+=2)r[o]=e+t[o+1]*i,r[o+1]=s+t[o]*n;return r}static _translate(t,e,s,i){i||=new Float32Array(t.length);for(let n=0,r=t.length;n<r;n+=2)i[n]=e+t[n],i[n+1]=s+t[n+1];return i}static svgRound(t){return Math.round(t*1e4)}static _normalizePoint(t,e,s,i,n){switch(n){case 90:return[1-e/s,t/i];case 180:return[1-t/s,1-e/i];case 270:return[e/s,1-t/i];default:return[t/s,e/i]}}static _normalizePagePoint(t,e,s){switch(s){case 90:return[1-e,t];case 180:return[1-t,1-e];case 270:return[e,1-t];default:return[t,e]}}static createBezierPoints(t,e,s,i,n,r){return[(t+5*s)/6,(e+5*i)/6,(5*s+n)/6,(5*i+r)/6,(s+n)/2,(i+r)/2]}}class ys{#t;#e=[];#s;#i;#r=[];#n=new Float32Array(18);#h;#a;#c;#l;#d;#u;#f=[];static#o=8;static#g=2;static#m=ys.#o+ys.#g;constructor({x:t,y:e},s,i,n,r,o=0){this.#t=s,this.#u=n*i,this.#i=r,this.#n.set([NaN,NaN,NaN,NaN,t,e],6),this.#s=o,this.#l=ys.#o*i,this.#c=ys.#m*i,this.#d=i,this.#f.push(t,e)}isEmpty(){return isNaN(this.#n[8])}#p(){const t=this.#n.subarray(4,6),e=this.#n.subarray(16,18),[s,i,n,r]=this.#t;return[(this.#h+(t[0]-e[0])/2-s)/n,(this.#a+(t[1]-e[1])/2-i)/r,(this.#h+(e[0]-t[0])/2-s)/n,(this.#a+(e[1]-t[1])/2-i)/r]}add({x:t,y:e}){this.#h=t,this.#a=e;const[s,i,n,r]=this.#t;let[o,h,l,c]=this.#n.subarray(8,12);const u=t-l,d=e-c,f=Math.hypot(u,d);if(f<this.#c)return!1;const g=f-this.#l,p=g/f,b=p*u,m=p*d;let v=o,y=h;o=l,h=c,l+=b,c+=m,this.#f?.push(t,e);const _=-m/g,S=b/g,A=_*this.#u,T=S*this.#u;return this.#n.set(this.#n.subarray(2,8),0),this.#n.set([l+A,c+T],4),this.#n.set(this.#n.subarray(14,18),12),this.#n.set([l-A,c-T],16),isNaN(this.#n[6])?(this.#r.length===0&&(this.#n.set([o+A,h+T],2),this.#r.push(NaN,NaN,NaN,NaN,(o+A-s)/n,(h+T-i)/r),this.#n.set([o-A,h-T],14),this.#e.push(NaN,NaN,NaN,NaN,(o-A-s)/n,(h-T-i)/r)),this.#n.set([v,y,o,h,l,c],6),!this.isEmpty()):(this.#n.set([v,y,o,h,l,c],6),Math.abs(Math.atan2(y-h,v-o)-Math.atan2(m,b))<Math.PI/2?([o,h,l,c]=this.#n.subarray(2,6),this.#r.push(NaN,NaN,NaN,NaN,((o+l)/2-s)/n,((h+c)/2-i)/r),[o,h,v,y]=this.#n.subarray(14,18),this.#e.push(NaN,NaN,NaN,NaN,((v+o)/2-s)/n,((y+h)/2-i)/r),!0):([v,y,o,h,l,c]=this.#n.subarray(0,6),this.#r.push(((v+5*o)/6-s)/n,((y+5*h)/6-i)/r,((5*o+l)/6-s)/n,((5*h+c)/6-i)/r,((o+l)/2-s)/n,((h+c)/2-i)/r),[l,c,o,h,v,y]=this.#n.subarray(12,18),this.#e.push(((v+5*o)/6-s)/n,((y+5*h)/6-i)/r,((5*o+l)/6-s)/n,((5*h+c)/6-i)/r,((o+l)/2-s)/n,((h+c)/2-i)/r),!0))}toSVGPath(){if(this.isEmpty())return"";const t=this.#r,e=this.#e;if(isNaN(this.#n[6])&&!this.isEmpty())return this.#b();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]}`);this.#v(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 this.#_(s),s.join(" ")}#b(){const[t,e,s,i]=this.#t,[n,r,o,h]=this.#p();return`M${(this.#n[2]-t)/s} ${(this.#n[3]-e)/i} L${(this.#n[4]-t)/s} ${(this.#n[5]-e)/i} L${n} ${r} L${o} ${h} L${(this.#n[16]-t)/s} ${(this.#n[17]-e)/i} L${(this.#n[14]-t)/s} ${(this.#n[15]-e)/i} Z`}#_(t){const e=this.#e;t.push(`L${e[4]} ${e[5]} Z`)}#v(t){const[e,s,i,n]=this.#t,r=this.#n.subarray(4,6),o=this.#n.subarray(16,18),[h,l,c,u]=this.#p();t.push(`L${(r[0]-e)/i} ${(r[1]-s)/n} L${h} ${l} L${c} ${u} L${(o[0]-e)/i} ${(o[1]-s)/n}`)}newFreeDrawOutline(t,e,s,i,n,r){return new Il(t,e,s,i,n,r)}getOutlines(){const t=this.#r,e=this.#e,s=this.#n,[i,n,r,o]=this.#t,h=new Float32Array((this.#f?.length??0)+2);for(let u=0,d=h.length-2;u<d;u+=2)h[u]=(this.#f[u]-i)/r,h[u+1]=(this.#f[u+1]-n)/o;if(h[h.length-2]=(this.#h-i)/r,h[h.length-1]=(this.#a-n)/o,isNaN(s[6])&&!this.isEmpty())return this.#w(h);const l=new Float32Array(this.#r.length+24+this.#e.length);let c=t.length;for(let u=0;u<c;u+=2){if(isNaN(t[u])){l[u]=l[u+1]=NaN;continue}l[u]=t[u],l[u+1]=t[u+1]}c=this.#A(l,c);for(let u=e.length-6;u>=6;u-=6)for(let d=0;d<6;d+=2){if(isNaN(e[u+d])){l[c]=l[c+1]=NaN,c+=2;continue}l[c]=e[u+d],l[c+1]=e[u+d+1],c+=2}return this.#S(l,c),this.newFreeDrawOutline(l,h,this.#t,this.#d,this.#s,this.#i)}#w(t){const e=this.#n,[s,i,n,r]=this.#t,[o,h,l,c]=this.#p(),u=new Float32Array(36);return u.set([NaN,NaN,NaN,NaN,(e[2]-s)/n,(e[3]-i)/r,NaN,NaN,NaN,NaN,(e[4]-s)/n,(e[5]-i)/r,NaN,NaN,NaN,NaN,o,h,NaN,NaN,NaN,NaN,l,c,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(u,t,this.#t,this.#d,this.#s,this.#i)}#S(t,e){const s=this.#e;return t.set([NaN,NaN,NaN,NaN,s[4],s[5]],e),e+=6}#A(t,e){const s=this.#n.subarray(4,6),i=this.#n.subarray(16,18),[n,r,o,h]=this.#t,[l,c,u,d]=this.#p();return t.set([NaN,NaN,NaN,NaN,(s[0]-n)/o,(s[1]-r)/h,NaN,NaN,NaN,NaN,l,c,NaN,NaN,NaN,NaN,u,d,NaN,NaN,NaN,NaN,(i[0]-n)/o,(i[1]-r)/h],e),e+=24}}class Il extends j{#t;#e=new Float32Array(4);#s;#i;#r;#n;#h;constructor(t,e,s,i,n,r){super(),this.#h=t,this.#r=e,this.#t=s,this.#n=i,this.#s=n,this.#i=r,this.lastPoint=[NaN,NaN],this.#a(r);const[o,h,l,c]=this.#e;for(let u=0,d=t.length;u<d;u+=2)t[u]=(t[u]-o)/l,t[u+1]=(t[u+1]-h)/c;for(let u=0,d=e.length;u<d;u+=2)e[u]=(e[u]-o)/l,e[u+1]=(e[u+1]-h)/c}toSVGPath(){const t=[`M${this.#h[4]} ${this.#h[5]}`];for(let e=6,s=this.#h.length;e<s;e+=6){if(isNaN(this.#h[e])){t.push(`L${this.#h[e+4]} ${this.#h[e+5]}`);continue}t.push(`C${this.#h[e]} ${this.#h[e+1]} ${this.#h[e+2]} ${this.#h[e+3]} ${this.#h[e+4]} ${this.#h[e+5]}`)}return t.push("Z"),t.join(" ")}serialize([t,e,s,i],n){const r=s-t,o=i-e;let h,l;switch(n){case 0:h=j._rescale(this.#h,t,i,r,-o),l=j._rescale(this.#r,t,i,r,-o);break;case 90:h=j._rescaleAndSwap(this.#h,t,e,r,o),l=j._rescaleAndSwap(this.#r,t,e,r,o);break;case 180:h=j._rescale(this.#h,s,e,-r,o),l=j._rescale(this.#r,s,e,-r,o);break;case 270:h=j._rescaleAndSwap(this.#h,s,i,-r,-o),l=j._rescaleAndSwap(this.#r,s,i,-r,-o);break}return{outline:Array.from(h),points:[Array.from(l)]}}#a(t){const e=this.#h;let s=e[4],i=e[5],n=s,r=i,o=s,h=i,l=s,c=i;const u=t?Math.max:Math.min;for(let f=6,g=e.length;f<g;f+=6){if(isNaN(e[f]))n=Math.min(n,e[f+4]),r=Math.min(r,e[f+5]),o=Math.max(o,e[f+4]),h=Math.max(h,e[f+5]),c<e[f+5]?(l=e[f+4],c=e[f+5]):c===e[f+5]&&(l=u(l,e[f+4]));else{const p=G.bezierBoundingBox(s,i,...e.slice(f,f+6));n=Math.min(n,p[0]),r=Math.min(r,p[1]),o=Math.max(o,p[2]),h=Math.max(h,p[3]),c<p[3]?(l=p[2],c=p[3]):c===p[3]&&(l=u(l,p[2]))}s=e[f+4],i=e[f+5]}const d=this.#e;d[0]=n-this.#s,d[1]=r-this.#s,d[2]=o-n+2*this.#s,d[3]=h-r+2*this.#s,this.lastPoint=[l,c]}get box(){return this.#e}newOutliner(t,e,s,i,n,r=0){return new ys(t,e,s,i,n,r)}getNewOutline(t,e){const[s,i,n,r]=this.#e,[o,h,l,c]=this.#t,u=n*l,d=r*c,f=s*l+o,g=i*c+h,p=this.newOutliner({x:this.#r[0]*u+f,y:this.#r[1]*d+g},this.#t,this.#n,t,this.#i,e??this.#s);for(let b=2;b<this.#r.length;b+=2)p.add({x:this.#r[b]*u+f,y:this.#r[b+1]*d+g});return p.getOutlines()}}class So{#t;#e;#s=[];#i=[];constructor(t,e=0,s=0,i=!0){let n=1/0,r=-1/0,o=1/0,h=-1/0;const l=10**-4;for(const{x:b,y:m,width:v,height:y}of t){const _=Math.floor((b-e)/l)*l,S=Math.ceil((b+v+e)/l)*l,A=Math.floor((m-e)/l)*l,T=Math.ceil((m+y+e)/l)*l,k=[_,A,T,!0],P=[S,A,T,!1];this.#s.push(k,P),n=Math.min(n,_),r=Math.max(r,S),o=Math.min(o,A),h=Math.max(h,T)}const c=r-n+2*s,u=h-o+2*s,d=n-s,f=o-s,g=this.#s.at(i?-1:-2),p=[g[0],g[2]];for(const b of this.#s){const[m,v,y]=b;b[0]=(m-d)/c,b[1]=(v-f)/u,b[2]=(y-f)/u}this.#t=new Float32Array([d,f,c,u]),this.#e=p}getOutlines(){this.#s.sort((e,s)=>e[0]-s[0]||e[1]-s[1]||e[2]-s[2]);const t=[];for(const e of this.#s)e[3]?(t.push(...this.#c(e)),this.#h(e)):(this.#a(e),t.push(...this.#c(e)));return this.#r(t)}#r(t){const e=[],s=new Set;for(const r of t){const[o,h,l]=r;e.push([o,h,r],[o,l,r])}e.sort((r,o)=>r[1]-o[1]||r[0]-o[0]);for(let r=0,o=e.length;r<o;r+=2){const h=e[r][2],l=e[r+1][2];h.push(l),l.push(h),s.add(h),s.add(l)}const i=[];let n;for(;s.size>0;){const r=s.values().next().value;let[o,h,l,c,u]=r;s.delete(r);let d=o,f=h;for(n=[o,l],i.push(n);;){let g;if(s.has(c))g=c;else if(s.has(u))g=u;else break;s.delete(g),[o,h,l,c,u]=g,d!==o&&(n.push(d,f,o,f===h?h:l),d=o),f=f===h?l:h}n.push(d,f)}return new Rg(i,this.#t,this.#e)}#n(t){const e=this.#i;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}#h([,t,e]){const s=this.#n(t);this.#i.splice(s,0,[t,e])}#a([,t,e]){const s=this.#n(t);for(let i=s;i<this.#i.length;i++){const[n,r]=this.#i[i];if(n!==t)break;if(n===t&&r===e){this.#i.splice(i,1);return}}for(let i=s-1;i>=0;i--){const[n,r]=this.#i[i];if(n!==t)break;if(n===t&&r===e){this.#i.splice(i,1);return}}}#c(t){const[e,s,i]=t,n=[[e,s,i]],r=this.#n(i);for(let o=0;o<r;o++){const[h,l]=this.#i[o];for(let c=0,u=n.length;c<u;c++){const[,d,f]=n[c];if(!(l<=d||f<=h)){if(d>=h){if(f>l)n[c][1]=l;else{if(u===1)return[];n.splice(c,1),c--,u--}continue}n[c][2]=h,f>l&&n.push([e,l,f])}}}return n}}class Rg extends j{#t;#e;constructor(t,e,s){super(),this.#e=t,this.#t=e,this.lastPoint=s}toSVGPath(){const t=[];for(const e of this.#e){let[s,i]=e;t.push(`M${s} ${i}`);for(let n=2;n<e.length;n+=2){const r=e[n],o=e[n+1];r===s?(t.push(`V${o}`),i=o):o===i&&(t.push(`H${r}`),s=r)}t.push("Z")}return t.join(" ")}serialize([t,e,s,i],n){const r=[],o=s-t,h=i-e;for(const l of this.#e){const c=new Array(l.length);for(let u=0;u<l.length;u+=2)c[u]=t+l[u]*o,c[u+1]=i-l[u+1]*h;r.push(c)}return r}get box(){return this.#t}get classNamesForOutlining(){return["highlightOutline"]}}class Co extends ys{newFreeDrawOutline(t,e,s,i,n,r){return new Lg(t,e,s,i,n,r)}}class Lg extends Il{newOutliner(t,e,s,i,n,r=0){return new Co(t,e,s,i,n,r)}}class he{#t=null;#e=null;#s;#i=null;#r=!1;#n=!1;#h=null;#a;#c=null;#l=null;#d;static#u=null;static get _keyboardManager(){return Z(this,"_keyboardManager",new bi([[["Escape","mac+Escape"],he.prototype._hideDropdownFromKeyboard],[[" ","mac+ "],he.prototype._colorSelectFromKeyboard],[["ArrowDown","ArrowRight","mac+ArrowDown","mac+ArrowRight"],he.prototype._moveToNext],[["ArrowUp","ArrowLeft","mac+ArrowUp","mac+ArrowLeft"],he.prototype._moveToPrevious],[["Home","mac+Home"],he.prototype._moveToBeginning],[["End","mac+End"],he.prototype._moveToEnd]]))}constructor({editor:t=null,uiManager:e=null}){t?(this.#n=!1,this.#d=tt.HIGHLIGHT_COLOR,this.#h=t):(this.#n=!0,this.#d=tt.HIGHLIGHT_DEFAULT_COLOR),this.#l=t?._uiManager||e,this.#a=this.#l._eventBus,this.#s=t?.color||this.#l?.highlightColors.values().next().value||"#FFFF98",he.#u||=Object.freeze({blue:"pdfjs-editor-colorpicker-blue",green:"pdfjs-editor-colorpicker-green",pink:"pdfjs-editor-colorpicker-pink",red:"pdfjs-editor-colorpicker-red",yellow:"pdfjs-editor-colorpicker-yellow"})}renderButton(){const t=this.#t=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=this.#l._signal;t.addEventListener("click",this.#m.bind(this),{signal:e}),t.addEventListener("keydown",this.#g.bind(this),{signal:e});const s=this.#e=document.createElement("span");return s.className="swatch",s.setAttribute("aria-hidden",!0),s.style.backgroundColor=this.#s,t.append(s),t}renderMainDropdown(){const t=this.#i=this.#f();return t.setAttribute("aria-orientation","horizontal"),t.setAttribute("aria-labelledby","highlightColorPickerLabel"),t}#f(){const t=document.createElement("div"),e=this.#l._signal;t.addEventListener("contextmenu",ve,{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 this.#l.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",he.#u[s]);const r=document.createElement("span");n.append(r),r.className="swatch",r.style.backgroundColor=i,n.setAttribute("aria-selected",i===this.#s),n.addEventListener("click",this.#o.bind(this,i),{signal:e}),t.append(n)}return t.addEventListener("keydown",this.#g.bind(this),{signal:e}),t}#o(t,e){e.stopPropagation(),this.#a.dispatch("switchannotationeditorparams",{source:this,type:this.#d,value:t})}_colorSelectFromKeyboard(t){if(t.target===this.#t){this.#m(t);return}const e=t.target.getAttribute("data-color");e&&this.#o(e,t)}_moveToNext(t){if(!this.#b){this.#m(t);return}if(t.target===this.#t){this.#i.firstChild?.focus();return}t.target.nextSibling?.focus()}_moveToPrevious(t){if(t.target===this.#i?.firstChild||t.target===this.#t){this.#b&&this._hideDropdownFromKeyboard();return}this.#b||this.#m(t),t.target.previousSibling?.focus()}_moveToBeginning(t){if(!this.#b){this.#m(t);return}this.#i.firstChild?.focus()}_moveToEnd(t){if(!this.#b){this.#m(t);return}this.#i.lastChild?.focus()}#g(t){he._keyboardManager.exec(this,t)}#m(t){if(this.#b){this.hideDropdown();return}if(this.#r=t.detail===0,this.#c||(this.#c=new AbortController,window.addEventListener("pointerdown",this.#p.bind(this),{signal:this.#l.combinedSignal(this.#c)})),this.#i){this.#i.classList.remove("hidden");return}const e=this.#i=this.#f();this.#t.append(e)}#p(t){this.#i?.contains(t.target)||this.hideDropdown()}hideDropdown(){this.#i?.classList.add("hidden"),this.#c?.abort(),this.#c=null}get#b(){return this.#i&&!this.#i.classList.contains("hidden")}_hideDropdownFromKeyboard(){if(!this.#n){if(!this.#b){this.#h?.unselect();return}this.hideDropdown(),this.#t.focus({preventScroll:!0,focusVisible:this.#r})}}updateColor(t){if(this.#e&&(this.#e.style.backgroundColor=t),!this.#i)return;const e=this.#l.highlightColors.values();for(const s of this.#i.children)s.setAttribute("aria-selected",e.next().value===t)}destroy(){this.#t?.remove(),this.#t=null,this.#e=null,this.#i?.remove(),this.#i=null}}class _t extends W{#t=null;#e=0;#s;#i=null;#r=null;#n=null;#h=null;#a=0;#c=null;#l=null;#d=null;#u=!1;#f=null;#o;#g=null;#m="";#p;#b="";static _defaultColor=null;static _defaultOpacity=1;static _defaultThickness=12;static _type="highlight";static _editorType=q.HIGHLIGHT;static _freeHighlightId=-1;static _freeHighlight=null;static _freeHighlightClipId="";static get _keyboardManager(){const t=_t.prototype;return Z(this,"_keyboardManager",new bi([[["ArrowLeft","mac+ArrowLeft"],t._moveCaret,{args:[0]}],[["ArrowRight","mac+ArrowRight"],t._moveCaret,{args:[1]}],[["ArrowUp","mac+ArrowUp"],t._moveCaret,{args:[2]}],[["ArrowDown","mac+ArrowDown"],t._moveCaret,{args:[3]}]]))}constructor(t){super({...t,name:"highlightEditor"}),this.color=t.color||_t._defaultColor,this.#p=t.thickness||_t._defaultThickness,this.#o=t.opacity||_t._defaultOpacity,this.#s=t.boxes||null,this.#b=t.methodOfCreation||"",this.#m=t.text||"",this._isDraggable=!1,t.highlightId>-1?(this.#u=!0,this.#v(t),this.#M()):this.#s&&(this.#t=t.anchorNode,this.#e=t.anchorOffset,this.#h=t.focusNode,this.#a=t.focusOffset,this.#_(),this.#M(),this.rotate(this.rotation))}get telemetryInitialData(){return{action:"added",type:this.#u?"free_highlight":"highlight",color:this._uiManager.highlightColorNames.get(this.color),thickness:this.#p,methodOfCreation:this.#b}}get telemetryFinalData(){return{type:"highlight",color:this._uiManager.highlightColorNames.get(this.color)}}static computeTelemetryFinalData(t){return{numberOfColors:t.get("color").size}}#_(){const t=new So(this.#s,.001);this.#l=t.getOutlines(),[this.x,this.y,this.width,this.height]=this.#l.box;const e=new So(this.#s,.0025,.001,this._uiManager.direction==="ltr");this.#n=e.getOutlines();const{lastPoint:s}=this.#n;this.#f=[(s[0]-this.x)/this.width,(s[1]-this.y)/this.height]}#v({highlightOutlines:t,highlightId:e,clipPathId:s}){this.#l=t;const i=1.5;if(this.#n=t.getNewOutline(this.#p/2+i,.0025),e>=0)this.#d=e,this.#i=s,this.parent.drawLayer.finalizeDraw(e,{bbox:t.box,path:{d:t.toSVGPath()}}),this.#g=this.parent.drawLayer.drawOutline({rootClass:{highlightOutline:!0,free:!0},bbox:this.#n.box,path:{d:this.#n.toSVGPath()}},!0);else if(this.parent){const c=this.parent.viewport.rotation;this.parent.drawLayer.updateProperties(this.#d,{bbox:_t.#x(this.#l.box,(c-this.rotation+360)%360),path:{d:t.toSVGPath()}}),this.parent.drawLayer.updateProperties(this.#g,{bbox:_t.#x(this.#n.box,c),path:{d:this.#n.toSVGPath()}})}const[n,r,o,h]=t.box;switch(this.rotation){case 0:this.x=n,this.y=r,this.width=o,this.height=h;break;case 90:{const[c,u]=this.parentDimensions;this.x=r,this.y=1-n,this.width=o*u/c,this.height=h*c/u;break}case 180:this.x=1-n,this.y=1-r,this.width=o,this.height=h;break;case 270:{const[c,u]=this.parentDimensions;this.x=1-r,this.y=n,this.width=o*u/c,this.height=h*c/u;break}}const{lastPoint:l}=this.#n;this.#f=[(l[0]-n)/o,(l[1]-r)/h]}static initialize(t,e){W.initialize(t,e),_t._defaultColor||=e.highlightColors?.values().next().value||"#fff066"}static updateDefaultParams(t,e){switch(t){case tt.HIGHLIGHT_DEFAULT_COLOR:_t._defaultColor=e;break;case tt.HIGHLIGHT_THICKNESS:_t._defaultThickness=e;break}}translateInPage(t,e){}get toolbarPosition(){return this.#f}updateParams(t,e){switch(t){case tt.HIGHLIGHT_COLOR:this.#w(e);break;case tt.HIGHLIGHT_THICKNESS:this.#S(e);break}}static get defaultPropertiesToUpdate(){return[[tt.HIGHLIGHT_DEFAULT_COLOR,_t._defaultColor],[tt.HIGHLIGHT_THICKNESS,_t._defaultThickness]]}get propertiesToUpdate(){return[[tt.HIGHLIGHT_COLOR,this.color||_t._defaultColor],[tt.HIGHLIGHT_THICKNESS,this.#p||_t._defaultThickness],[tt.HIGHLIGHT_FREE,this.#u]]}#w(t){const e=(n,r)=>{this.color=n,this.#o=r,this.parent?.drawLayer.updateProperties(this.#d,{root:{fill:n,"fill-opacity":r}}),this.#r?.updateColor(n)},s=this.color,i=this.#o;this.addCommands({cmd:e.bind(this,t,_t._defaultOpacity),undo:e.bind(this,s,i),post:this._uiManager.updateUI.bind(this._uiManager,this),mustExec:!0,type:tt.HIGHLIGHT_COLOR,overwriteIfSameType:!0,keepUndo:!0}),this._reportTelemetry({action:"color_changed",color:this._uiManager.highlightColorNames.get(t)},!0)}#S(t){const e=this.#p,s=i=>{this.#p=i,this.#A(i)};this.addCommands({cmd:s.bind(this,t),undo:s.bind(this,e),post:this._uiManager.updateUI.bind(this._uiManager,this),mustExec:!0,type:tt.INK_THICKNESS,overwriteIfSameType:!0,keepUndo:!0}),this._reportTelemetry({action:"thickness_changed",thickness:t},!0)}async addEditToolbar(){const t=await super.addEditToolbar();return t?(this._uiManager.highlightColors&&(this.#r=new he({editor:this}),t.addColorPicker(this.#r)),t):null}disableEditing(){super.disableEditing(),this.div.classList.toggle("disabled",!0)}enableEditing(){super.enableEditing(),this.div.classList.toggle("disabled",!1)}fixAndSetPosition(){return super.fixAndSetPosition(this.#O())}getBaseTranslation(){return[0,0]}getRect(t,e){return super.getRect(t,e,this.#O())}onceAdded(t){this.annotationElementId||this.parent.addUndoableEditor(this),t&&this.div.focus()}remove(){this.#E(),this._reportTelemetry({action:"deleted"}),super.remove()}rebuild(){this.parent&&(super.rebuild(),this.div!==null&&(this.#M(),this.isAttachedToDOM||this.parent.add(this)))}setParent(t){let e=!1;this.parent&&!t?this.#E():t&&(this.#M(t),e=!this.parent&&this.div?.classList.contains("selectedEditor")),super.setParent(t),this.show(this._isVisible),e&&this.select()}#A(t){if(!this.#u)return;this.#v({highlightOutlines:this.#l.getNewOutline(t/2)}),this.fixAndSetPosition();const[e,s]=this.parentDimensions;this.setDims(this.width*e,this.height*s)}#E(){this.#d===null||!this.parent||(this.parent.drawLayer.remove(this.#d),this.#d=null,this.parent.drawLayer.remove(this.#g),this.#g=null)}#M(t=this.parent){this.#d===null&&({id:this.#d,clipPathId:this.#i}=t.drawLayer.draw({bbox:this.#l.box,root:{viewBox:"0 0 1 1",fill:this.color,"fill-opacity":this.#o},rootClass:{highlight:!0,free:this.#u},path:{d:this.#l.toSVGPath()}},!1,!0),this.#g=t.drawLayer.drawOutline({rootClass:{highlightOutline:!0,free:this.#u},bbox:this.#n.box,path:{d:this.#n.toSVGPath()}},this.#u),this.#c&&(this.#c.style.clipPath=this.#i))}static#x([t,e,s,i],n){switch(n){case 90:return[1-e-i,t,i,s];case 180:return[1-t-s,1-e-i,s,i];case 270:return[e,1-t-s,i,s]}return[t,e,s,i]}rotate(t){const{drawLayer:e}=this.parent;let s;this.#u?(t=(t-this.rotation+360)%360,s=_t.#x(this.#l.box,t)):s=_t.#x([this.x,this.y,this.width,this.height],t),e.updateProperties(this.#d,{bbox:s,root:{"data-main-rotation":t}}),e.updateProperties(this.#g,{bbox:_t.#x(this.#n.box,t),root:{"data-main-rotation":t}})}render(){if(this.div)return this.div;const t=super.render();this.#m&&(t.setAttribute("aria-label",this.#m),t.setAttribute("role","mark")),this.#u?t.classList.add("free"):this.div.addEventListener("keydown",this.#k.bind(this),{signal:this._uiManager._signal});const e=this.#c=document.createElement("div");t.append(e),e.setAttribute("aria-hidden","true"),e.className="internal",e.style.clipPath=this.#i;const[s,i]=this.parentDimensions;return this.setDims(this.width*s,this.height*i),In(this,this.#c,["pointerover","pointerleave"]),this.enableEditing(),t}pointerover(){this.isSelected||this.parent?.drawLayer.updateProperties(this.#g,{rootClass:{hovered:!0}})}pointerleave(){this.isSelected||this.parent?.drawLayer.updateProperties(this.#g,{rootClass:{hovered:!1}})}#k(t){_t._keyboardManager.exec(this,t)}_moveCaret(t){switch(this.parent.unselect(this),t){case 0:case 2:this.#T(!0);break;case 1:case 3:this.#T(!1);break}}#T(t){if(!this.#t)return;const e=window.getSelection();t?e.setPosition(this.#t,this.#e):e.setPosition(this.#h,this.#a)}select(){super.select(),this.#g&&this.parent?.drawLayer.updateProperties(this.#g,{rootClass:{hovered:!1,selected:!0}})}unselect(){super.unselect(),this.#g&&(this.parent?.drawLayer.updateProperties(this.#g,{rootClass:{selected:!1}}),this.#u||this.#T(!1))}get _mustFixPosition(){return!this.#u}show(t=this._isVisible){super.show(t),this.parent&&(this.parent.drawLayer.updateProperties(this.#d,{rootClass:{hidden:!t}}),this.parent.drawLayer.updateProperties(this.#g,{rootClass:{hidden:!t}}))}#O(){return this.#u?this.rotation:0}#L(){if(this.#u)return null;const[t,e]=this.pageDimensions,[s,i]=this.pageTranslation,n=this.#s,r=new Float32Array(n.length*8);let o=0;for(const{x:h,y:l,width:c,height:u}of n){const d=h*t+s,f=(1-l)*e+i;r[o]=r[o+4]=d,r[o+1]=r[o+3]=f,r[o+2]=r[o+6]=d+c*t,r[o+5]=r[o+7]=f-u*e,o+=8}return r}#I(t){return this.#l.serialize(t,this.#O())}static startHighlighting(t,e,{target:s,x:i,y:n}){const{x:r,y:o,width:h,height:l}=s.getBoundingClientRect(),c=new AbortController,u=t.combinedSignal(c),d=f=>{c.abort(),this.#y(t,f)};window.addEventListener("blur",d,{signal:u}),window.addEventListener("pointerup",d,{signal:u}),window.addEventListener("pointerdown",ne,{capture:!0,passive:!1,signal:u}),window.addEventListener("contextmenu",ve,{signal:u}),s.addEventListener("pointermove",this.#C.bind(this,t),{signal:u}),this._freeHighlight=new Co({x:i,y:n},[r,o,h,l],t.scale,this._defaultThickness/2,e,.001),{id:this._freeHighlightId,clipPathId:this._freeHighlightClipId}=t.drawLayer.draw({bbox:[0,0,1,1],root:{viewBox:"0 0 1 1",fill:this._defaultColor,"fill-opacity":this._defaultOpacity},rootClass:{highlight:!0,free:!0},path:{d:this._freeHighlight.toSVGPath()}},!0,!0)}static#C(t,e){this._freeHighlight.add(e)&&t.drawLayer.updateProperties(this._freeHighlightId,{path:{d:this._freeHighlight.toSVGPath()}})}static#y(t,e){this._freeHighlight.isEmpty()?t.drawLayer.remove(this._freeHighlightId):t.createAndAddNewEditor(e,!1,{highlightId:this._freeHighlightId,highlightOutlines:this._freeHighlight.getOutlines(),clipPathId:this._freeHighlightClipId,methodOfCreation:"main_toolbar"}),this._freeHighlightId=-1,this._freeHighlight=null,this._freeHighlightClipId=""}static async deserialize(t,e,s){let i=null;if(t instanceof Ll){const{data:{quadPoints:g,rect:p,rotation:b,id:m,color:v,opacity:y,popupRef:_},parent:{page:{pageNumber:S}}}=t;i=t={annotationType:q.HIGHLIGHT,color:Array.from(v),opacity:y,quadPoints:g,boxes:null,pageIndex:S-1,rect:p.slice(0),rotation:b,id:m,deleted:!1,popupRef:_}}else if(t instanceof xo){const{data:{inkLists:g,rect:p,rotation:b,id:m,color:v,borderStyle:{rawWidth:y},popupRef:_},parent:{page:{pageNumber:S}}}=t;i=t={annotationType:q.HIGHLIGHT,color:Array.from(v),thickness:y,inkLists:g,boxes:null,pageIndex:S-1,rect:p.slice(0),rotation:b,id:m,deleted:!1,popupRef:_}}const{color:n,quadPoints:r,inkLists:o,opacity:h}=t,l=await super.deserialize(t,e,s);l.color=G.makeHexColor(...n),l.#o=h||1,o&&(l.#p=t.thickness),l.annotationElementId=t.id||null,l._initialData=i;const[c,u]=l.pageDimensions,[d,f]=l.pageTranslation;if(r){const g=l.#s=[];for(let p=0;p<r.length;p+=8)g.push({x:(r[p]-d)/c,y:1-(r[p+1]-f)/u,width:(r[p+2]-r[p])/c,height:(r[p+1]-r[p+5])/u});l.#_(),l.#M(),l.rotate(l.rotation)}else if(o){l.#u=!0;const g=o[0],p={x:g[0]-d,y:u-(g[1]-f)},b=new Co(p,[0,0,c,u],1,l.#p/2,!0,.001);for(let y=0,_=g.length;y<_;y+=2)p.x=g[y]-d,p.y=u-(g[y+1]-f),b.add(p);const{id:m,clipPathId:v}=e.drawLayer.draw({bbox:[0,0,1,1],root:{viewBox:"0 0 1 1",fill:l.color,"fill-opacity":l._defaultOpacity},rootClass:{highlight:!0,free:!0},path:{d:b.toSVGPath()}},!0,!0);l.#v({highlightOutlines:b.getOutlines(),highlightId:m,clipPathId:v}),l.#M()}return l}serialize(t=!1){if(this.isEmpty()||t)return null;if(this.deleted)return this.serializeDeleted();const e=this.getRect(0,0),s=W._colorManager.convert(this.color),i={annotationType:q.HIGHLIGHT,color:s,opacity:this.#o,thickness:this.#p,quadPoints:this.#L(),outlines:this.#I(e),pageIndex:this.pageIndex,rect:e,rotation:this.#O(),structTreeParentId:this._structTreeParentId};return this.annotationElementId&&!this.#R(i)?null:(i.id=this.annotationElementId,i)}#R(t){const{color:e}=this._initialData;return t.color.some((s,i)=>s!==e[i])}renderAnnotationElement(t){return t.updateEdited({rect:this.getRect(0,0)}),null}static canCreateNewEmptyEditor(){return!1}}class Fg{#t=Object.create(null);updateProperty(t,e){this[t]=e,this.updateSVGProperty(t,e)}updateProperties(t){if(t)for(const[e,s]of Object.entries(t))this.updateProperty(e,s)}updateSVGProperty(t,e){this.#t[t]=e}toSVGProperties(){const t=this.#t;return this.#t=Object.create(null),{root:t}}reset(){this.#t=Object.create(null)}updateAll(t=this){this.updateProperties(t)}clone(){at("Not implemented")}}class X extends W{#t=null;#e;_drawId=null;static _currentDrawId=-1;static _currentParent=null;static#s=null;static#i=null;static#r=null;static#n=NaN;static#h=null;static#a=null;static#c=NaN;static _INNER_MARGIN=3;constructor(t){super(t),this.#e=t.mustBeCommitted||!1,t.drawOutlines&&(this.#l(t),this.#f())}#l({drawOutlines:t,drawId:e,drawingOptions:s}){this.#t=t,this._drawingOptions||=s,e>=0?(this._drawId=e,this.parent.drawLayer.finalizeDraw(e,t.defaultProperties)):this._drawId=this.#d(t,this.parent),this.#m(t.box)}#d(t,e){const{id:s}=e.drawLayer.draw(X._mergeSVGProperties(this._drawingOptions.toSVGProperties(),t.defaultSVGProperties),!1,!1);return s}static _mergeSVGProperties(t,e){const s=new Set(Object.keys(t));for(const[i,n]of Object.entries(e))s.has(i)?Object.assign(t[i],n):t[i]=n;return t}static getDefaultDrawingOptions(t){at("Not implemented")}static get typesMap(){at("Not implemented")}static get isDrawer(){return!0}static get supportMultipleDrawings(){return!1}static updateDefaultParams(t,e){const s=this.typesMap.get(t);s&&this._defaultDrawingOptions.updateProperty(s,e),this._currentParent&&(X.#s.updateProperty(s,e),this._currentParent.drawLayer.updateProperties(this._currentDrawId,this._defaultDrawingOptions.toSVGProperties()))}updateParams(t,e){const s=this.constructor.typesMap.get(t);s&&this._updateProperty(t,s,e)}static get defaultPropertiesToUpdate(){const t=[],e=this._defaultDrawingOptions;for(const[s,i]of this.typesMap)t.push([s,e[i]]);return t}get propertiesToUpdate(){const t=[],{_drawingOptions:e}=this;for(const[s,i]of this.constructor.typesMap)t.push([s,e[i]]);return t}_updateProperty(t,e,s){const i=this._drawingOptions,n=i[e],r=o=>{i.updateProperty(e,o);const h=this.#t.updateProperty(e,o);h&&this.#m(h),this.parent?.drawLayer.updateProperties(this._drawId,i.toSVGProperties())};this.addCommands({cmd:r.bind(this,s),undo:r.bind(this,n),post:this._uiManager.updateUI.bind(this._uiManager,this),mustExec:!0,type:t,overwriteIfSameType:!0,keepUndo:!0})}_onResizing(){this.parent?.drawLayer.updateProperties(this._drawId,X._mergeSVGProperties(this.#t.getPathResizingSVGProperties(this.#g()),{bbox:this.#p()}))}_onResized(){this.parent?.drawLayer.updateProperties(this._drawId,X._mergeSVGProperties(this.#t.getPathResizedSVGProperties(this.#g()),{bbox:this.#p()}))}_onTranslating(t,e){this.parent?.drawLayer.updateProperties(this._drawId,{bbox:this.#p(t,e)})}_onTranslated(){this.parent?.drawLayer.updateProperties(this._drawId,X._mergeSVGProperties(this.#t.getPathTranslatedSVGProperties(this.#g(),this.parentDimensions),{bbox:this.#p()}))}_onStartDragging(){this.parent?.drawLayer.updateProperties(this._drawId,{rootClass:{moving:!0}})}_onStopDragging(){this.parent?.drawLayer.updateProperties(this._drawId,{rootClass:{moving:!1}})}commit(){super.commit(),this.disableEditMode(),this.disableEditing()}disableEditing(){super.disableEditing(),this.div.classList.toggle("disabled",!0)}enableEditing(){super.enableEditing(),this.div.classList.toggle("disabled",!1)}getBaseTranslation(){return[0,0]}get isResizable(){return!0}onceAdded(t){this.annotationElementId||this.parent.addUndoableEditor(this),this._isDraggable=!0,this.#e&&(this.#e=!1,this.commit(),this.parent.setSelected(this),t&&this.isOnScreen&&this.div.focus())}remove(){this.#u(),super.remove()}rebuild(){this.parent&&(super.rebuild(),this.div!==null&&(this.#f(),this.#m(this.#t.box),this.isAttachedToDOM||this.parent.add(this)))}setParent(t){let e=!1;this.parent&&!t?(this._uiManager.removeShouldRescale(this),this.#u()):t&&(this._uiManager.addShouldRescale(this),this.#f(t),e=!this.parent&&this.div?.classList.contains("selectedEditor")),super.setParent(t),e&&this.select()}#u(){this._drawId===null||!this.parent||(this.parent.drawLayer.remove(this._drawId),this._drawId=null,this._drawingOptions.reset())}#f(t=this.parent){if(!(this._drawId!==null&&this.parent===t)){if(this._drawId!==null){this.parent.drawLayer.updateParent(this._drawId,t.drawLayer);return}this._drawingOptions.updateAll(),this._drawId=this.#d(this.#t,t)}}#o([t,e,s,i]){const{parentDimensions:[n,r],rotation:o}=this;switch(o){case 90:return[e,1-t,s*(r/n),i*(n/r)];case 180:return[1-t,1-e,s,i];case 270:return[1-e,t,s*(r/n),i*(n/r)];default:return[t,e,s,i]}}#g(){const{x:t,y:e,width:s,height:i,parentDimensions:[n,r],rotation:o}=this;switch(o){case 90:return[1-e,t,s*(n/r),i*(r/n)];case 180:return[1-t,1-e,s,i];case 270:return[e,1-t,s*(n/r),i*(r/n)];default:return[t,e,s,i]}}#m(t){if([this.x,this.y,this.width,this.height]=this.#o(t),this.div){this.fixAndSetPosition();const[e,s]=this.parentDimensions;this.setDims(this.width*e,this.height*s)}this._onResized()}#p(){const{x:t,y:e,width:s,height:i,rotation:n,parentRotation:r,parentDimensions:[o,h]}=this;switch((n*4+r)/90){case 1:return[1-e-i,t,i,s];case 2:return[1-t-s,1-e-i,s,i];case 3:return[e,1-t-s,i,s];case 4:return[t,e-s*(o/h),i*(h/o),s*(o/h)];case 5:return[1-e,t,s*(o/h),i*(h/o)];case 6:return[1-t-i*(h/o),1-e,i*(h/o),s*(o/h)];case 7:return[e-s*(o/h),1-t-i*(h/o),s*(o/h),i*(h/o)];case 8:return[t-s,e-i,s,i];case 9:return[1-e,t-s,i,s];case 10:return[1-t,1-e,s,i];case 11:return[e-i,1-t,i,s];case 12:return[t-i*(h/o),e,i*(h/o),s*(o/h)];case 13:return[1-e-s*(o/h),t-i*(h/o),s*(o/h),i*(h/o)];case 14:return[1-t,1-e-s*(o/h),i*(h/o),s*(o/h)];case 15:return[e,1-t,s*(o/h),i*(h/o)];default:return[t,e,s,i]}}rotate(){this.parent&&this.parent.drawLayer.updateProperties(this._drawId,X._mergeSVGProperties({bbox:this.#p()},this.#t.updateRotation((this.parentRotation-this.rotation+360)%360)))}onScaleChanging(){this.parent&&this.#m(this.#t.updateParentDimensions(this.parentDimensions,this.parent.scale))}static onScaleChangingWhenDrawing(){}render(){if(this.div)return this.div;const t=super.render();t.classList.add("draw");const e=document.createElement("div");t.append(e),e.setAttribute("aria-hidden","true"),e.className="internal";const[s,i]=this.parentDimensions;return this.setDims(this.width*s,this.height*i),this._uiManager.addShouldRescale(this),this.disableEditing(),t}static createDrawerInstance(t,e,s,i,n){at("Not implemented")}static startDrawing(t,e,s,i){const{target:n,offsetX:r,offsetY:o,pointerId:h,pointerType:l}=i;if(X.#h&&X.#h!==l)return;const{viewport:{rotation:c}}=t,{width:u,height:d}=n.getBoundingClientRect(),f=X.#i=new AbortController,g=t.combinedSignal(f);if(X.#n||=h,X.#h??=l,window.addEventListener("pointerup",p=>{X.#n===p.pointerId?this._endDraw(p):X.#a?.delete(p.pointerId)},{signal:g}),window.addEventListener("pointercancel",p=>{X.#n===p.pointerId?this._currentParent.endDrawingSession():X.#a?.delete(p.pointerId)},{signal:g}),window.addEventListener("pointerdown",p=>{X.#h===p.pointerType&&((X.#a||=new Set).add(p.pointerId),X.#s.isCancellable()&&(X.#s.removeLastElement(),X.#s.isEmpty()?this._currentParent.endDrawingSession(!0):this._endDraw(null)))},{capture:!0,passive:!1,signal:g}),window.addEventListener("contextmenu",ve,{signal:g}),n.addEventListener("pointermove",this._drawMove.bind(this),{signal:g}),n.addEventListener("touchmove",p=>{p.timeStamp===X.#c&&ne(p)},{signal:g}),t.toggleDrawing(),e._editorUndoBar?.hide(),X.#s){t.drawLayer.updateProperties(this._currentDrawId,X.#s.startNew(r,o,u,d,c));return}e.updateUIForDefaultProperties(this),X.#s=this.createDrawerInstance(r,o,u,d,c),X.#r=this.getDefaultDrawingOptions(),this._currentParent=t,{id:this._currentDrawId}=t.drawLayer.draw(this._mergeSVGProperties(X.#r.toSVGProperties(),X.#s.defaultSVGProperties),!0,!1)}static _drawMove(t){if(X.#c=-1,!X.#s)return;const{offsetX:e,offsetY:s,pointerId:i}=t;if(X.#n===i){if(X.#a?.size>=1){this._endDraw(t);return}this._currentParent.drawLayer.updateProperties(this._currentDrawId,X.#s.add(e,s)),X.#c=t.timeStamp,ne(t)}}static _cleanup(t){t&&(this._currentDrawId=-1,this._currentParent=null,X.#s=null,X.#r=null,X.#h=null,X.#c=NaN),X.#i&&(X.#i.abort(),X.#i=null,X.#n=NaN,X.#a=null)}static _endDraw(t){const e=this._currentParent;if(e){if(e.toggleDrawing(!0),this._cleanup(!1),t&&e.drawLayer.updateProperties(this._currentDrawId,X.#s.end(t.offsetX,t.offsetY)),this.supportMultipleDrawings){const s=X.#s,i=this._currentDrawId,n=s.getLastElement();e.addCommands({cmd:()=>{e.drawLayer.updateProperties(i,s.setLastElement(n))},undo:()=>{e.drawLayer.updateProperties(i,s.removeLastElement())},mustExec:!1,type:tt.DRAW_STEP});return}this.endDrawing(!1)}}static endDrawing(t){const e=this._currentParent;if(!e)return null;if(e.toggleDrawing(!0),e.cleanUndoStack(tt.DRAW_STEP),!X.#s.isEmpty()){const{pageDimensions:[s,i],scale:n}=e,r=e.createAndAddNewEditor({offsetX:0,offsetY:0},!1,{drawId:this._currentDrawId,drawOutlines:X.#s.getOutlines(s*n,i*n,n,this._INNER_MARGIN),drawingOptions:X.#r,mustBeCommitted:!t});return this._cleanup(!0),r}return e.drawLayer.remove(this._currentDrawId),this._cleanup(!0),null}createDrawingOptions(t){}static deserializeDraw(t,e,s,i,n,r){at("Not implemented")}static async deserialize(t,e,s){const{rawDims:{pageWidth:i,pageHeight:n,pageX:r,pageY:o}}=e.viewport,h=this.deserializeDraw(r,o,i,n,this._INNER_MARGIN,t),l=await super.deserialize(t,e,s);return l.createDrawingOptions(t),l.#l({drawOutlines:h}),l.#f(),l.onScaleChanging(),l.rotate(),l}serializeDraw(t){const[e,s]=this.pageTranslation,[i,n]=this.pageDimensions;return this.#t.serialize([e,s,i,n],t)}renderAnnotationElement(t){return t.updateEdited({rect:this.getRect(0,0)}),null}static canCreateNewEmptyEditor(){return!1}}class Ig{#t=new Float64Array(6);#e;#s;#i;#r;#n;#h="";#a=0;#c=new Wn;#l;#d;constructor(t,e,s,i,n,r){this.#l=s,this.#d=i,this.#i=n,this.#r=r,[t,e]=this.#u(t,e);const o=this.#e=[NaN,NaN,NaN,NaN,t,e];this.#n=[t,e],this.#s=[{line:o,points:this.#n}],this.#t.set(o,0)}updateProperty(t,e){t==="stroke-width"&&(this.#r=e)}#u(t,e){return j._normalizePoint(t,e,this.#l,this.#d,this.#i)}isEmpty(){return!this.#s||this.#s.length===0}isCancellable(){return this.#n.length<=10}add(t,e){[t,e]=this.#u(t,e);const[s,i,n,r]=this.#t.subarray(2,6),o=t-n,h=e-r;return Math.hypot(this.#l*o,this.#d*h)<=2?null:(this.#n.push(t,e),isNaN(s)?(this.#t.set([n,r,t,e],2),this.#e.push(NaN,NaN,NaN,NaN,t,e),{path:{d:this.toSVGPath()}}):(isNaN(this.#t[0])&&this.#e.splice(6,6),this.#t.set([s,i,n,r,t,e],0),this.#e.push(...j.createBezierPoints(s,i,n,r,t,e)),{path:{d:this.toSVGPath()}}))}end(t,e){const s=this.add(t,e);return s||(this.#n.length===2?{path:{d:this.toSVGPath()}}:null)}startNew(t,e,s,i,n){this.#l=s,this.#d=i,this.#i=n,[t,e]=this.#u(t,e);const r=this.#e=[NaN,NaN,NaN,NaN,t,e];this.#n=[t,e];const o=this.#s.at(-1);return o&&(o.line=new Float32Array(o.line),o.points=new Float32Array(o.points)),this.#s.push({line:r,points:this.#n}),this.#t.set(r,0),this.#a=0,this.toSVGPath(),null}getLastElement(){return this.#s.at(-1)}setLastElement(t){return this.#s?(this.#s.push(t),this.#e=t.line,this.#n=t.points,this.#a=0,{path:{d:this.toSVGPath()}}):this.#c.setLastElement(t)}removeLastElement(){if(!this.#s)return this.#c.removeLastElement();this.#s.pop(),this.#h="";for(let t=0,e=this.#s.length;t<e;t++){const{line:s,points:i}=this.#s[t];this.#e=s,this.#n=i,this.#a=0,this.toSVGPath()}return{path:{d:this.#h}}}toSVGPath(){const t=j.svgRound(this.#e[4]),e=j.svgRound(this.#e[5]);if(this.#n.length===2)return this.#h=`${this.#h} M ${t} ${e} Z`,this.#h;if(this.#n.length<=6){const i=this.#h.lastIndexOf("M");this.#h=`${this.#h.slice(0,i)} M ${t} ${e}`,this.#a=6}if(this.#n.length===4){const i=j.svgRound(this.#e[10]),n=j.svgRound(this.#e[11]);return this.#h=`${this.#h} L ${i} ${n}`,this.#a=12,this.#h}const s=[];this.#a===0&&(s.push(`M ${t} ${e}`),this.#a=6);for(let i=this.#a,n=this.#e.length;i<n;i+=6){const[r,o,h,l,c,u]=this.#e.slice(i,i+6).map(j.svgRound);s.push(`C${r} ${o} ${h} ${l} ${c} ${u}`)}return this.#h+=s.join(" "),this.#a=this.#e.length,this.#h}getOutlines(t,e,s,i){const n=this.#s.at(-1);return n.line=new Float32Array(n.line),n.points=new Float32Array(n.points),this.#c.build(this.#s,t,e,s,this.#i,this.#r,i),this.#t=null,this.#e=null,this.#s=null,this.#h=null,this.#c}get defaultSVGProperties(){return{root:{viewBox:"0 0 10000 10000"},rootClass:{draw:!0},bbox:[0,0,1,1]}}}class Wn extends j{#t;#e=0;#s;#i;#r;#n;#h;#a;#c;build(t,e,s,i,n,r,o){this.#r=e,this.#n=s,this.#h=i,this.#a=n,this.#c=r,this.#s=o??0,this.#i=t,this.#u()}setLastElement(t){return this.#i.push(t),{path:{d:this.toSVGPath()}}}removeLastElement(){return this.#i.pop(),{path:{d:this.toSVGPath()}}}toSVGPath(){const t=[];for(const{line:e}of this.#i){if(t.push(`M${j.svgRound(e[4])} ${j.svgRound(e[5])}`),e.length===6){t.push("Z");continue}if(e.length===12){t.push(`L${j.svgRound(e[10])} ${j.svgRound(e[11])}`);continue}for(let s=6,i=e.length;s<i;s+=6){const[n,r,o,h,l,c]=e.subarray(s,s+6).map(j.svgRound);t.push(`C${n} ${r} ${o} ${h} ${l} ${c}`)}}return t.join("")}serialize([t,e,s,i],n){const r=[],o=[],[h,l,c,u]=this.#d();let d,f,g,p,b,m,v,y,_;switch(this.#a){case 0:_=j._rescale,d=t,f=e+i,g=s,p=-i,b=t+h*s,m=e+(1-l-u)*i,v=t+(h+c)*s,y=e+(1-l)*i;break;case 90:_=j._rescaleAndSwap,d=t,f=e,g=s,p=i,b=t+l*s,m=e+h*i,v=t+(l+u)*s,y=e+(h+c)*i;break;case 180:_=j._rescale,d=t+s,f=e,g=-s,p=i,b=t+(1-h-c)*s,m=e+l*i,v=t+(1-h)*s,y=e+(l+u)*i;break;case 270:_=j._rescaleAndSwap,d=t+s,f=e+i,g=-s,p=-i,b=t+(1-l-u)*s,m=e+(1-h-c)*i,v=t+(1-l)*s,y=e+(1-h)*i;break}for(const{line:S,points:A}of this.#i)r.push(_(S,d,f,g,p,n?new Array(S.length):null)),o.push(_(A,d,f,g,p,n?new Array(A.length):null));return{lines:r,points:o,rect:[b,m,v,y]}}static deserialize(t,e,s,i,n,{paths:{lines:r,points:o},rotation:h,thickness:l}){const c=[];let u,d,f,g,p;switch(h){case 0:p=j._rescale,u=-t/s,d=e/i+1,f=1/s,g=-1/i;break;case 90:p=j._rescaleAndSwap,u=-e/i,d=-t/s,f=1/i,g=1/s;break;case 180:p=j._rescale,u=t/s+1,d=-e/i,f=-1/s,g=1/i;break;case 270:p=j._rescaleAndSwap,u=e/i+1,d=t/s+1,f=-1/i,g=-1/s;break}if(!r){r=[];for(const m of o){const v=m.length;if(v===2){r.push(new Float32Array([NaN,NaN,NaN,NaN,m[0],m[1]]));continue}if(v===4){r.push(new Float32Array([NaN,NaN,NaN,NaN,m[0],m[1],NaN,NaN,NaN,NaN,m[2],m[3]]));continue}const y=new Float32Array(3*(v-2));r.push(y);let[_,S,A,T]=m.subarray(0,4);y.set([NaN,NaN,NaN,NaN,_,S],0);for(let k=4;k<v;k+=2){const P=m[k],B=m[k+1];y.set(j.createBezierPoints(_,S,A,T,P,B),(k-2)*3),[_,S,A,T]=[A,T,P,B]}}}for(let m=0,v=r.length;m<v;m++)c.push({line:p(r[m].map(y=>y??NaN),u,d,f,g),points:p(o[m].map(y=>y??NaN),u,d,f,g)});const b=new Wn;return b.build(c,s,i,1,h,l,n),b}#l(t=this.#c){const e=this.#s+t/2*this.#h;return this.#a%180===0?[e/this.#r,e/this.#n]:[e/this.#n,e/this.#r]}#d(){const[t,e,s,i]=this.#t,[n,r]=this.#l(0);return[t+n,e+r,s-2*n,i-2*r]}#u(){const t=this.#t=new Float32Array([1/0,1/0,-1/0,-1/0]);for(const{line:i}of this.#i){if(i.length<=12){for(let o=4,h=i.length;o<h;o+=6){const[l,c]=i.subarray(o,o+2);t[0]=Math.min(t[0],l),t[1]=Math.min(t[1],c),t[2]=Math.max(t[2],l),t[3]=Math.max(t[3],c)}continue}let n=i[4],r=i[5];for(let o=6,h=i.length;o<h;o+=6){const[l,c,u,d,f,g]=i.subarray(o,o+6);G.bezierBoundingBox(n,r,l,c,u,d,f,g,t),n=f,r=g}}const[e,s]=this.#l();t[0]=Math.min(1,Math.max(0,t[0]-e)),t[1]=Math.min(1,Math.max(0,t[1]-s)),t[2]=Math.min(1,Math.max(0,t[2]+e)),t[3]=Math.min(1,Math.max(0,t[3]+s)),t[2]-=t[0],t[3]-=t[1]}get box(){return this.#t}updateProperty(t,e){return t==="stroke-width"?this.#f(e):null}#f(t){const[e,s]=this.#l();this.#c=t;const[i,n]=this.#l(),[r,o]=[i-e,n-s],h=this.#t;return h[0]-=r,h[1]-=o,h[2]+=2*r,h[3]+=2*o,h}updateParentDimensions([t,e],s){const[i,n]=this.#l();this.#r=t,this.#n=e,this.#h=s;const[r,o]=this.#l(),h=r-i,l=o-n,c=this.#t;return c[0]-=h,c[1]-=l,c[2]+=2*h,c[3]+=2*l,c}updateRotation(t){return this.#e=t,{path:{transform:this.rotationTransform}}}get viewBox(){return this.#t.map(j.svgRound).join(" ")}get defaultProperties(){const[t,e]=this.#t;return{root:{viewBox:this.viewBox},path:{"transform-origin":`${j.svgRound(t)} ${j.svgRound(e)}`}}}get rotationTransform(){const[,,t,e]=this.#t;let s=0,i=0,n=0,r=0,o=0,h=0;switch(this.#e){case 90:i=e/t,n=-t/e,o=t;break;case 180:s=-1,r=-1,o=t,h=e;break;case 270:i=-e/t,n=t/e,h=e;break;default:return""}return`matrix(${s} ${i} ${n} ${r} ${j.svgRound(o)} ${j.svgRound(h)})`}getPathResizingSVGProperties([t,e,s,i]){const[n,r]=this.#l(),[o,h,l,c]=this.#t;if(Math.abs(l-n)<=j.PRECISION||Math.abs(c-r)<=j.PRECISION){const p=t+s/2-(o+l/2),b=e+i/2-(h+c/2);return{path:{"transform-origin":`${j.svgRound(t)} ${j.svgRound(e)}`,transform:`${this.rotationTransform} translate(${p} ${b})`}}}const u=(s-2*n)/(l-2*n),d=(i-2*r)/(c-2*r),f=l/s,g=c/i;return{path:{"transform-origin":`${j.svgRound(o)} ${j.svgRound(h)}`,transform:`${this.rotationTransform} scale(${f} ${g}) translate(${j.svgRound(n)} ${j.svgRound(r)}) scale(${u} ${d}) translate(${j.svgRound(-n)} ${j.svgRound(-r)})`}}}getPathResizedSVGProperties([t,e,s,i]){const[n,r]=this.#l(),o=this.#t,[h,l,c,u]=o;if(o[0]=t,o[1]=e,o[2]=s,o[3]=i,Math.abs(c-n)<=j.PRECISION||Math.abs(u-r)<=j.PRECISION){const b=t+s/2-(h+c/2),m=e+i/2-(l+u/2);for(const{line:v,points:y}of this.#i)j._translate(v,b,m,v),j._translate(y,b,m,y);return{root:{viewBox:this.viewBox},path:{"transform-origin":`${j.svgRound(t)} ${j.svgRound(e)}`,transform:this.rotationTransform||null,d:this.toSVGPath()}}}const d=(s-2*n)/(c-2*n),f=(i-2*r)/(u-2*r),g=-d*(h+n)+t+n,p=-f*(l+r)+e+r;if(d!==1||f!==1||g!==0||p!==0)for(const{line:b,points:m}of this.#i)j._rescale(b,g,p,d,f,b),j._rescale(m,g,p,d,f,m);return{root:{viewBox:this.viewBox},path:{"transform-origin":`${j.svgRound(t)} ${j.svgRound(e)}`,transform:this.rotationTransform||null,d:this.toSVGPath()}}}getPathTranslatedSVGProperties([t,e],s){const[i,n]=s,r=this.#t,o=t-r[0],h=e-r[1];if(this.#r===i&&this.#n===n)for(const{line:l,points:c}of this.#i)j._translate(l,o,h,l),j._translate(c,o,h,c);else{const l=this.#r/i,c=this.#n/n;this.#r=i,this.#n=n;for(const{line:u,points:d}of this.#i)j._rescale(u,o,h,l,c,u),j._rescale(d,o,h,l,c,d);r[2]*=l,r[3]*=c}return r[0]=t,r[1]=e,{root:{viewBox:this.viewBox},path:{d:this.toSVGPath(),"transform-origin":`${j.svgRound(t)} ${j.svgRound(e)}`}}}get defaultSVGProperties(){const t=this.#t;return{root:{viewBox:this.viewBox},rootClass:{draw:!0},path:{d:this.toSVGPath(),"transform-origin":`${j.svgRound(t[0])} ${j.svgRound(t[1])}`,transform:this.rotationTransform||null},bbox:t}}}class Ao extends Fg{#t;constructor(t){super(),this.#t=t,super.updateProperties({fill:"none",stroke:W._defaultLineColor,"stroke-opacity":1,"stroke-width":1,"stroke-linecap":"round","stroke-linejoin":"round","stroke-miterlimit":10})}updateSVGProperty(t,e){t==="stroke-width"&&(e??=this["stroke-width"],e*=this.#t.realScale),super.updateSVGProperty(t,e)}clone(){const t=new Ao(this.#t);return t.updateAll(this),t}}class To extends X{static _type="ink";static _editorType=q.INK;static _defaultDrawingOptions=null;constructor(t){super({...t,name:"inkEditor"}),this._willKeepAspectRatio=!0}static initialize(t,e){W.initialize(t,e),this._defaultDrawingOptions=new Ao(e.viewParameters)}static getDefaultDrawingOptions(t){const e=this._defaultDrawingOptions.clone();return e.updateProperties(t),e}static get supportMultipleDrawings(){return!0}static get typesMap(){return Z(this,"typesMap",new Map([[tt.INK_THICKNESS,"stroke-width"],[tt.INK_COLOR,"stroke"],[tt.INK_OPACITY,"stroke-opacity"]]))}static createDrawerInstance(t,e,s,i,n){return new Ig(t,e,s,i,n,this._defaultDrawingOptions["stroke-width"])}static deserializeDraw(t,e,s,i,n,r){return Wn.deserialize(t,e,s,i,n,r)}static async deserialize(t,e,s){let i=null;if(t instanceof xo){const{data:{inkLists:r,rect:o,rotation:h,id:l,color:c,opacity:u,borderStyle:{rawWidth:d},popupRef:f},parent:{page:{pageNumber:g}}}=t;i=t={annotationType:q.INK,color:Array.from(c),thickness:d,opacity:u,paths:{points:r},boxes:null,pageIndex:g-1,rect:o.slice(0),rotation:h,id:l,deleted:!1,popupRef:f}}const n=await super.deserialize(t,e,s);return n.annotationElementId=t.id||null,n._initialData=i,n}onScaleChanging(){if(!this.parent)return;super.onScaleChanging();const{_drawId:t,_drawingOptions:e,parent:s}=this;e.updateSVGProperty("stroke-width"),s.drawLayer.updateProperties(t,e.toSVGProperties())}static onScaleChangingWhenDrawing(){const t=this._currentParent;t&&(super.onScaleChangingWhenDrawing(),this._defaultDrawingOptions.updateSVGProperty("stroke-width"),t.drawLayer.updateProperties(this._currentDrawId,this._defaultDrawingOptions.toSVGProperties()))}createDrawingOptions({color:t,thickness:e,opacity:s}){this._drawingOptions=To.getDefaultDrawingOptions({stroke:G.makeHexColor(...t),"stroke-width":e,"stroke-opacity":s})}serialize(t=!1){if(this.isEmpty())return null;if(this.deleted)return this.serializeDeleted();const{lines:e,points:s,rect:i}=this.serializeDraw(t),{_drawingOptions:{stroke:n,"stroke-opacity":r,"stroke-width":o}}=this,h={annotationType:q.INK,color:W._colorManager.convert(n),opacity:r,thickness:o,paths:{lines:e,points:s},pageIndex:this.pageIndex,rect:i,rotation:this.rotation,structTreeParentId:this._structTreeParentId};return t?h:this.annotationElementId&&!this.#t(h)?null:(h.id=this.annotationElementId,h)}#t(t){const{color:e,thickness:s,opacity:i,pageIndex:n}=this._initialData;return this._hasBeenMoved||this._hasBeenResized||t.color.some((r,o)=>r!==e[o])||t.thickness!==s||t.opacity!==i||t.pageIndex!==n}renderAnnotationElement(t){const{points:e,rect:s}=this.serializeDraw(!1);return t.updateEdited({rect:s,thickness:this._drawingOptions["stroke-width"],points:e}),null}}class Eo extends W{#t=null;#e=null;#s=null;#i=null;#r=null;#n="";#h=null;#a=null;#c=!1;#l=!1;static _type="stamp";static _editorType=q.STAMP;constructor(t){super({...t,name:"stampEditor"}),this.#i=t.bitmapUrl,this.#r=t.bitmapFile}static initialize(t,e){W.initialize(t,e)}static get supportedTypes(){return Z(this,"supportedTypes",["apng","avif","bmp","gif","jpeg","png","svg+xml","webp","x-icon"].map(e=>`image/${e}`))}static get supportedTypesStr(){return Z(this,"supportedTypesStr",this.supportedTypes.join(","))}static isHandlingMimeForPasting(t){return this.supportedTypes.includes(t)}static paste(t,e){e.pasteEditor(q.STAMP,{bitmapFile:t.getAsFile()})}altTextFinish(){this._uiManager.useNewAltTextFlow&&(this.div.hidden=!1),super.altTextFinish()}get telemetryFinalData(){return{type:"stamp",hasAltText:!!this.altTextData?.altText}}static computeTelemetryFinalData(t){const e=t.get("hasAltText");return{hasAltText:e.get(!0)??0,hasNoAltText:e.get(!1)??0}}#d(t,e=!1){if(!t){this.remove();return}this.#t=t.bitmap,e||(this.#e=t.id,this.#c=t.isSvg),t.file&&(this.#n=t.file.name),this.#o()}#u(){if(this.#s=null,this._uiManager.enableWaiting(!1),!!this.#h){if(this._uiManager.useNewAltTextWhenAddingImage&&this._uiManager.useNewAltTextFlow&&this.#t){this._editToolbar.hide(),this._uiManager.editAltText(this,!0);return}if(!this._uiManager.useNewAltTextWhenAddingImage&&this._uiManager.useNewAltTextFlow&&this.#t){this._reportTelemetry({action:"pdfjs.image.image_added",data:{alt_text_modal:!1,alt_text_type:"empty"}});try{this.mlGuessAltText()}catch{}}this.div.focus()}}async mlGuessAltText(t=null,e=!0){if(this.hasAltTextData())return null;const{mlManager:s}=this._uiManager;if(!s)throw new Error("No ML.");if(!await s.isEnabledFor("altText"))throw new Error("ML isn't enabled for alt text.");const{data:i,width:n,height:r}=t||this.copyCanvas(null,null,!0).imageData,o=await s.guess({name:"altText",request:{data:i,width:n,height:r,channels:i.length/(n*r)}});if(!o)throw new Error("No response from the AI service.");if(o.error)throw new Error("Error from the AI service.");if(o.cancel)return null;if(!o.output)throw new Error("No valid response from the AI service.");const h=o.output;return await this.setGuessedAltText(h),e&&!this.hasAltTextData()&&(this.altTextData={alt:h,decorative:!1}),h}#f(){if(this.#e){this._uiManager.enableWaiting(!0),this._uiManager.imageManager.getFromId(this.#e).then(s=>this.#d(s,!0)).finally(()=>this.#u());return}if(this.#i){const s=this.#i;this.#i=null,this._uiManager.enableWaiting(!0),this.#s=this._uiManager.imageManager.getFromUrl(s).then(i=>this.#d(i)).finally(()=>this.#u());return}if(this.#r){const s=this.#r;this.#r=null,this._uiManager.enableWaiting(!0),this.#s=this._uiManager.imageManager.getFromFile(s).then(i=>this.#d(i)).finally(()=>this.#u());return}const t=document.createElement("input");t.type="file",t.accept=Eo.supportedTypesStr;const e=this._uiManager._signal;this.#s=new Promise(s=>{t.addEventListener("change",async()=>{if(!t.files||t.files.length===0)this.remove();else{this._uiManager.enableWaiting(!0);const i=await this._uiManager.imageManager.getFromFile(t.files[0]);this._reportTelemetry({action:"pdfjs.image.image_selected",data:{alt_text_modal:this._uiManager.useNewAltTextFlow}}),this.#d(i)}s()},{signal:e}),t.addEventListener("cancel",()=>{this.remove(),s()},{signal:e})}).finally(()=>this.#u()),t.click()}remove(){this.#e&&(this.#t=null,this._uiManager.imageManager.deleteId(this.#e),this.#h?.remove(),this.#h=null,this.#a&&(clearTimeout(this.#a),this.#a=null)),super.remove()}rebuild(){if(!this.parent){this.#e&&this.#f();return}super.rebuild(),this.div!==null&&(this.#e&&this.#h===null&&this.#f(),this.isAttachedToDOM||this.parent.add(this))}onceAdded(t){this._isDraggable=!0,t&&this.div.focus()}isEmpty(){return!(this.#s||this.#t||this.#i||this.#r||this.#e)}get isResizable(){return!0}render(){if(this.div)return this.div;let t,e;if(this.width&&(t=this.x,e=this.y),super.render(),this.div.hidden=!0,this.div.setAttribute("role","figure"),this.addAltTextButton(),this.#t?this.#o():this.#f(),this.width&&!this.annotationElementId){const[s,i]=this.parentDimensions;this.setAt(t*s,e*i,this.width*s,this.height*i)}return this._uiManager.addShouldRescale(this),this.div}_onResized(){this.onScaleChanging()}onScaleChanging(){if(!this.parent)return;this.#a!==null&&clearTimeout(this.#a);const t=200;this.#a=setTimeout(()=>{this.#a=null,this.#m()},t)}#o(){const{div:t}=this;let{width:e,height:s}=this.#t;const[i,n]=this.pageDimensions,r=.75;if(this.width)e=this.width*i,s=this.height*n;else if(e>r*i||s>r*n){const c=Math.min(r*i/e,r*n/s);e*=c,s*=c}const[o,h]=this.parentDimensions;this.setDims(e*o/i,s*h/n),this._uiManager.enableWaiting(!1);const l=this.#h=document.createElement("canvas");l.setAttribute("role","img"),this.addContainer(l),this.width=e/i,this.height=s/n,this._initialOptions?.isCentered?this.center():this.fixAndSetPosition(),this._initialOptions=null,(!this._uiManager.useNewAltTextWhenAddingImage||!this._uiManager.useNewAltTextFlow||this.annotationElementId)&&(t.hidden=!1),this.#m(),this.#l||(this.parent.addUndoableEditor(this),this.#l=!0),this._reportTelemetry({action:"inserted_image"}),this.#n&&l.setAttribute("aria-label",this.#n)}copyCanvas(t,e,s=!1){t||(t=224);const{width:i,height:n}=this.#t,r=new ao;let o=this.#t,h=i,l=n,c=null;if(e){if(i>e||n>e){const A=Math.min(e/i,e/n);h=Math.floor(i*A),l=Math.floor(n*A)}c=document.createElement("canvas");const d=c.width=Math.ceil(h*r.sx),f=c.height=Math.ceil(l*r.sy);this.#c||(o=this.#g(d,f));const g=c.getContext("2d");g.filter=this._uiManager.hcmFilter;let p="white",b="#cfcfd8";this._uiManager.hcmFilter!=="none"?b="black":window.matchMedia?.("(prefers-color-scheme: dark)").matches&&(p="#8f8f9d",b="#42414d");const m=15,v=m*r.sx,y=m*r.sy,_=new OffscreenCanvas(v*2,y*2),S=_.getContext("2d");S.fillStyle=p,S.fillRect(0,0,v*2,y*2),S.fillStyle=b,S.fillRect(0,0,v,y),S.fillRect(v,y,v,y),g.fillStyle=g.createPattern(_,"repeat"),g.fillRect(0,0,d,f),g.drawImage(o,0,0,o.width,o.height,0,0,d,f)}let u=null;if(s){let d,f;if(r.symmetric&&o.width<t&&o.height<t)d=o.width,f=o.height;else if(o=this.#t,i>t||n>t){const b=Math.min(t/i,t/n);d=Math.floor(i*b),f=Math.floor(n*b),this.#c||(o=this.#g(d,f))}const p=new OffscreenCanvas(d,f).getContext("2d",{willReadFrequently:!0});p.drawImage(o,0,0,o.width,o.height,0,0,d,f),u={width:d,height:f,data:p.getImageData(0,0,d,f).data}}return{canvas:c,width:h,height:l,imageData:u}}#g(t,e){const{width:s,height:i}=this.#t;let n=s,r=i,o=this.#t;for(;n>2*t||r>2*e;){const h=n,l=r;n>2*t&&(n=n>=16384?Math.floor(n/2)-1:Math.ceil(n/2)),r>2*e&&(r=r>=16384?Math.floor(r/2)-1:Math.ceil(r/2));const c=new OffscreenCanvas(n,r);c.getContext("2d").drawImage(o,0,0,h,l,0,0,n,r),o=c.transferToImageBitmap()}return o}#m(){const[t,e]=this.parentDimensions,{width:s,height:i}=this,n=new ao,r=Math.ceil(s*t*n.sx),o=Math.ceil(i*e*n.sy),h=this.#h;if(!h||h.width===r&&h.height===o)return;h.width=r,h.height=o;const l=this.#c?this.#t:this.#g(r,o),c=h.getContext("2d");c.filter=this._uiManager.hcmFilter,c.drawImage(l,0,0,l.width,l.height,0,0,r,o)}getImageForAltText(){return this.#h}#p(t){if(t){if(this.#c){const i=this._uiManager.imageManager.getSvgUrl(this.#e);if(i)return i}const e=document.createElement("canvas");return{width:e.width,height:e.height}=this.#t,e.getContext("2d").drawImage(this.#t,0,0),e.toDataURL()}if(this.#c){const[e,s]=this.pageDimensions,i=Math.round(this.width*e*js.PDF_TO_CSS_UNITS),n=Math.round(this.height*s*js.PDF_TO_CSS_UNITS),r=new OffscreenCanvas(i,n);return r.getContext("2d").drawImage(this.#t,0,0,this.#t.width,this.#t.height,0,0,i,n),r.transferToImageBitmap()}return structuredClone(this.#t)}static async deserialize(t,e,s){let i=null;if(t instanceof Fl){const{data:{rect:g,rotation:p,id:b,structParent:m,popupRef:v},container:y,parent:{page:{pageNumber:_}}}=t,S=y.querySelector("canvas"),A=s.imageManager.getFromCanvas(y.id,S);S.remove();const T=(await e._structTree.getAriaAttributes(`${io}${b}`))?.get("aria-label")||"";i=t={annotationType:q.STAMP,bitmapId:A.id,bitmap:A.bitmap,pageIndex:_-1,rect:g.slice(0),rotation:p,id:b,deleted:!1,accessibilityData:{decorative:!1,altText:T},isSvg:!1,structParent:m,popupRef:v}}const n=await super.deserialize(t,e,s),{rect:r,bitmap:o,bitmapUrl:h,bitmapId:l,isSvg:c,accessibilityData:u}=t;l&&s.imageManager.isValidId(l)?(n.#e=l,o&&(n.#t=o)):n.#i=h,n.#c=c;const[d,f]=n.pageDimensions;return n.width=(r[2]-r[0])/d,n.height=(r[3]-r[1])/f,n.annotationElementId=t.id||null,u&&(n.altTextData=u),n._initialData=i,n.#l=!!i,n}serialize(t=!1,e=null){if(this.isEmpty())return null;if(this.deleted)return this.serializeDeleted();const s={annotationType:q.STAMP,bitmapId:this.#e,pageIndex:this.pageIndex,rect:this.getRect(0,0),rotation:this.rotation,isSvg:this.#c,structTreeParentId:this._structTreeParentId};if(t)return s.bitmapUrl=this.#p(!0),s.accessibilityData=this.serializeAltText(!0),s;const{decorative:i,altText:n}=this.serializeAltText(!1);if(!i&&n&&(s.accessibilityData={type:"Figure",alt:n}),this.annotationElementId){const o=this.#b(s);if(o.isSame)return null;o.isSameAltText?delete s.accessibilityData:s.accessibilityData.structParent=this._initialData.structParent??-1}if(s.id=this.annotationElementId,e===null)return s;e.stamps||=new Map;const r=this.#c?(s.rect[2]-s.rect[0])*(s.rect[3]-s.rect[1]):null;if(!e.stamps.has(this.#e))e.stamps.set(this.#e,{area:r,serialized:s}),s.bitmap=this.#p(!1);else if(this.#c){const o=e.stamps.get(this.#e);r>o.area&&(o.area=r,o.serialized.bitmap.close(),o.serialized.bitmap=this.#p(!1))}return s}#b(t){const{pageIndex:e,accessibilityData:{altText:s}}=this._initialData,i=t.pageIndex===e,n=(t.accessibilityData?.alt||"")===s;return{isSame:!this._hasBeenMoved&&!this._hasBeenResized&&i&&n,isSameAltText:n}}renderAnnotationElement(t){return t.updateEdited({rect:this.getRect(0,0)}),null}}class Ve{#t;#e=!1;#s=null;#i=null;#r=null;#n=new Map;#h=!1;#a=!1;#c=!1;#l=null;#d=null;#u=null;#f=null;#o;static _initialized=!1;static#g=new Map([Et,To,Eo,_t].map(t=>[t._editorType,t]));constructor({uiManager:t,pageIndex:e,div:s,structTreeLayer:i,accessibilityManager:n,annotationLayer:r,drawLayer:o,textLayer:h,viewport:l,l10n:c}){const u=[...Ve.#g.values()];if(!Ve._initialized){Ve._initialized=!0;for(const d of u)d.initialize(c,t)}t.registerEditorTypes(u),this.#o=t,this.pageIndex=e,this.div=s,this.#t=n,this.#s=r,this.viewport=l,this.#u=h,this.drawLayer=o,this._structTree=i,this.#o.addLayer(this)}get isEmpty(){return this.#n.size===0}get isInvisible(){return this.isEmpty&&this.#o.getMode()===q.NONE}updateToolbar(t){this.#o.updateToolbar(t)}updateMode(t=this.#o.getMode()){switch(this.#v(),t){case q.NONE:this.disableTextSelection(),this.togglePointerEvents(!1),this.toggleAnnotationLayerPointerEvents(!0),this.disableClick();return;case q.INK:this.disableTextSelection(),this.togglePointerEvents(!0),this.enableClick();break;case q.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 Ve.#g.values())e.toggle(`${s._type}Editing`,t===s._editorType);this.div.hidden=!1}hasTextLayer(t){return t===this.#u?.div}setEditingState(t){this.#o.setEditingState(t)}addCommands(t){this.#o.addCommands(t)}cleanUndoStack(t){this.#o.cleanUndoStack(t)}toggleDrawing(t=!1){this.div.classList.toggle("drawing",!t)}togglePointerEvents(t=!1){this.div.classList.toggle("disabled",!t)}toggleAnnotationLayerPointerEvents(t=!1){this.#s?.div.classList.toggle("disabled",!t)}async enable(){this.#c=!0,this.div.tabIndex=0,this.togglePointerEvents(!0);const t=new Set;for(const s of this.#n.values())s.enableEditing(),s.show(!0),s.annotationElementId&&(this.#o.removeChangedExistingAnnotation(s),t.add(s.annotationElementId));if(!this.#s){this.#c=!1;return}const e=this.#s.getEditableAnnotations();for(const s of e){if(s.hide(),this.#o.isDeletedAnnotationElement(s.data.id)||t.has(s.data.id))continue;const i=await this.deserialize(s);i&&(this.addOrRebuild(i),i.enableEditing())}this.#c=!1}disable(){this.#a=!0,this.div.tabIndex=-1,this.togglePointerEvents(!1);const t=new Map,e=new Map;for(const i of this.#n.values())if(i.disableEditing(),!!i.annotationElementId){if(i.serialize()!==null){t.set(i.annotationElementId,i);continue}else e.set(i.annotationElementId,i);this.getEditableAnnotation(i.annotationElementId)?.show(),i.remove()}if(this.#s){const i=this.#s.getEditableAnnotations();for(const n of i){const{id:r}=n.data;if(this.#o.isDeletedAnnotationElement(r))continue;let o=e.get(r);if(o){o.resetAnnotationElement(n),o.show(!1),n.show();continue}o=t.get(r),o&&(this.#o.addChangedExistingAnnotation(o),o.renderAnnotationElement(n)&&o.show(!1)),n.show()}}this.#v(),this.isEmpty&&(this.div.hidden=!0);const{classList:s}=this.div;for(const i of Ve.#g.values())s.remove(`${i._type}Editing`);this.disableTextSelection(),this.toggleAnnotationLayerPointerEvents(!0),this.#a=!1}getEditableAnnotation(t){return this.#s?.getEditableAnnotation(t)||null}setActiveEditor(t){this.#o.getActive()!==t&&this.#o.setActiveEditor(t)}enableTextSelection(){if(this.div.tabIndex=-1,this.#u?.div&&!this.#f){this.#f=new AbortController;const t=this.#o.combinedSignal(this.#f);this.#u.div.addEventListener("pointerdown",this.#m.bind(this),{signal:t}),this.#u.div.classList.add("highlighting")}}disableTextSelection(){this.div.tabIndex=0,this.#u?.div&&this.#f&&(this.#f.abort(),this.#f=null,this.#u.div.classList.remove("highlighting"))}#m(t){this.#o.unselectAll();const{target:e}=t;if(e===this.#u.div||(e.getAttribute("role")==="img"||e.classList.contains("endOfContent"))&&this.#u.div.contains(e)){const{isMac:s}=Vt.platform;if(t.button!==0||t.ctrlKey&&s)return;this.#o.showAllEditors("highlight",!0,!0),this.#u.div.classList.add("free"),this.toggleDrawing(),_t.startHighlighting(this,this.#o.direction==="ltr",{target:this.#u.div,x:t.x,y:t.y}),this.#u.div.addEventListener("pointerup",()=>{this.#u.div.classList.remove("free"),this.toggleDrawing(!0)},{once:!0,signal:this.#o._signal}),t.preventDefault()}}enableClick(){if(this.#i)return;this.#i=new AbortController;const t=this.#o.combinedSignal(this.#i);this.div.addEventListener("pointerdown",this.pointerdown.bind(this),{signal:t});const e=this.pointerup.bind(this);this.div.addEventListener("pointerup",e,{signal:t}),this.div.addEventListener("pointercancel",e,{signal:t})}disableClick(){this.#i?.abort(),this.#i=null}attach(t){this.#n.set(t.id,t);const{annotationElementId:e}=t;e&&this.#o.isDeletedAnnotationElement(e)&&this.#o.removeDeletedAnnotationElement(t)}detach(t){this.#n.delete(t.id),this.#t?.removePointerInTextLayer(t.contentDiv),!this.#a&&t.annotationElementId&&this.#o.addDeletedAnnotationElement(t)}remove(t){this.detach(t),this.#o.removeEditor(t),t.div.remove(),t.isAttachedToDOM=!1}changeParent(t){t.parent!==this&&(t.parent&&t.annotationElementId&&(this.#o.addDeletedAnnotationElement(t.annotationElementId),W.deleteAnnotationElement(t),t.annotationElementId=null),this.attach(t),t.parent?.detach(t),t.setParent(this),t.div&&t.isAttachedToDOM&&(t.div.remove(),this.div.append(t.div)))}add(t){if(!(t.parent===this&&t.isAttachedToDOM)){if(this.changeParent(t),this.#o.addEditor(t),this.attach(t),!t.isAttachedToDOM){const e=t.render();this.div.append(e),t.isAttachedToDOM=!0}t.fixAndSetPosition(),t.onceAdded(!this.#c),this.#o.addToAnnotationStorage(t),t._reportTelemetry(t.telemetryInitialData)}}moveEditorInDOM(t){if(!t.isAttachedToDOM)return;const{activeElement:e}=document;t.div.contains(e)&&!this.#r&&(t._focusEventsAllowed=!1,this.#r=setTimeout(()=>{this.#r=null,t.div.contains(document.activeElement)?t._focusEventsAllowed=!0:(t.div.addEventListener("focusin",()=>{t._focusEventsAllowed=!0},{once:!0,signal:this.#o._signal}),e.focus())},0)),t._structTreeParentId=this.#t?.moveElementInDOM(this.div,t.div,t.contentDiv,!0)}addOrRebuild(t){t.needsToBeRebuilt()?(t.parent||=this,t.rebuild(),t.show()):this.add(t)}addUndoableEditor(t){const e=()=>t._uiManager.rebuild(t),s=()=>{t.remove()};this.addCommands({cmd:e,undo:s,mustExec:!1})}getNextId(){return this.#o.getId()}get#p(){return Ve.#g.get(this.#o.getMode())}combinedSignal(t){return this.#o.combinedSignal(t)}#b(t){const e=this.#p;return e?new e.prototype.constructor(t):null}canCreateNewEmptyEditor(){return this.#p?.canCreateNewEmptyEditor()}pasteEditor(t,e){this.#o.updateToolbar(t),this.#o.updateMode(t);const{offsetX:s,offsetY:i}=this.#_(),n=this.getNextId(),r=this.#b({parent:this,id:n,x:s,y:i,uiManager:this.#o,isCentered:!0,...e});r&&this.add(r)}async deserialize(t){return await Ve.#g.get(t.annotationType??t.annotationEditorType)?.deserialize(t,this,this.#o)||null}createAndAddNewEditor(t,e,s={}){const i=this.getNextId(),n=this.#b({parent:this,id:i,x:t.offsetX,y:t.offsetY,uiManager:this.#o,isCentered:e,...s});return n&&this.add(n),n}#_(){const{x:t,y:e,width:s,height:i}=this.div.getBoundingClientRect(),n=Math.max(0,t),r=Math.max(0,e),o=Math.min(window.innerWidth,t+s),h=Math.min(window.innerHeight,e+i),l=(n+o)/2-t,c=(r+h)/2-e,[u,d]=this.viewport.rotation%180===0?[l,c]:[c,l];return{offsetX:u,offsetY:d}}addNewEditor(){this.createAndAddNewEditor(this.#_(),!0)}setSelected(t){this.#o.setSelected(t)}toggleSelected(t){this.#o.toggleSelected(t)}unselect(t){this.#o.unselect(t)}pointerup(t){const{isMac:e}=Vt.platform;if(!(t.button!==0||t.ctrlKey&&e)&&t.target===this.div&&this.#h&&(this.#h=!1,!(this.#p?.isDrawer&&this.#p.supportMultipleDrawings))){if(!this.#e){this.#e=!0;return}if(this.#o.getMode()===q.STAMP){this.#o.unselectAll();return}this.createAndAddNewEditor(t,!1)}}pointerdown(t){if(this.#o.getMode()===q.HIGHLIGHT&&this.enableTextSelection(),this.#h){this.#h=!1;return}const{isMac:e}=Vt.platform;if(t.button!==0||t.ctrlKey&&e||t.target!==this.div)return;if(this.#h=!0,this.#p?.isDrawer){this.startDrawingSession(t);return}const s=this.#o.getActive();this.#e=!s||s.isEmpty()}startDrawingSession(t){if(this.div.focus(),this.#l){this.#p.startDrawing(this,this.#o,!1,t);return}this.#o.setCurrentDrawingSession(this),this.#l=new AbortController;const e=this.#o.combinedSignal(this.#l);this.div.addEventListener("blur",({relatedTarget:s})=>{s&&!this.div.contains(s)&&(this.#d=null,this.commitOrRemove())},{signal:e}),this.#p.startDrawing(this,this.#o,!1,t)}pause(t){if(t){const{activeElement:e}=document;this.div.contains(e)&&(this.#d=e);return}this.#d&&setTimeout(()=>{this.#d?.focus(),this.#d=null},0)}endDrawingSession(t=!1){return this.#l?(this.#o.setCurrentDrawingSession(null),this.#l.abort(),this.#l=null,this.#d=null,this.#p.endDrawing(t)):null}findNewParent(t,e,s){const i=this.#o.findParent(e,s);return i===null||i===this?!1:(i.changeParent(t),!0)}commitOrRemove(){return this.#l?(this.endDrawingSession(),!0):!1}onScaleChanging(){this.#l&&this.#p.onScaleChangingWhenDrawing(this)}destroy(){this.commitOrRemove(),this.#o.getActive()?.parent===this&&(this.#o.commitOrRemove(),this.#o.setActiveEditor(null)),this.#r&&(clearTimeout(this.#r),this.#r=null);for(const t of this.#n.values())this.#t?.removePointerInTextLayer(t.contentDiv),t.setParent(null),t.isAttachedToDOM=!1,t.div.remove();this.div=null,this.#n.clear(),this.#o.removeLayer(this)}#v(){for(const t of this.#n.values())t.isEmpty()&&t.remove()}render({viewport:t}){this.viewport=t,ms(this.div,t);for(const e of this.#o.getEditors(this.pageIndex))this.add(e),e.rebuild();this.updateMode()}update({viewport:t}){this.#o.commitOrRemove(),this.#v();const e=this.viewport.rotation,s=t.rotation;if(this.viewport=t,ms(this.div,{rotation:s}),e!==s)for(const i of this.#n.values())i.rotate(s)}get pageDimensions(){const{pageWidth:t,pageHeight:e}=this.viewport.rawDims;return[t,e]}get scale(){return this.#o.viewParameters.realScale}}class Xt{#t=null;#e=0;#s=new Map;#i=new Map;constructor({pageIndex:t}){this.pageIndex=t}setParent(t){if(!this.#t){this.#t=t;return}if(this.#t!==t){if(this.#s.size>0)for(const e of this.#s.values())e.remove(),t.append(e);this.#t=t}}static get _svgFactory(){return Z(this,"_svgFactory",new _o)}static#r(t,[e,s,i,n]){const{style:r}=t;r.top=`${100*s}%`,r.left=`${100*e}%`,r.width=`${100*i}%`,r.height=`${100*n}%`}#n(){const t=Xt._svgFactory.create(1,1,!0);return this.#t.append(t),t.setAttribute("aria-hidden",!0),t}#h(t,e){const s=Xt._svgFactory.createElement("clipPath");t.append(s);const i=`clip_${e}`;s.setAttribute("id",i),s.setAttribute("clipPathUnits","objectBoundingBox");const n=Xt._svgFactory.createElement("use");return s.append(n),n.setAttribute("href",`#${e}`),n.classList.add("clip"),i}#a(t,e){for(const[s,i]of Object.entries(e))i===null?t.removeAttribute(s):t.setAttribute(s,i)}draw(t,e=!1,s=!1){const i=this.#e++,n=this.#n(),r=Xt._svgFactory.createElement("defs");n.append(r);const o=Xt._svgFactory.createElement("path");r.append(o);const h=`path_p${this.pageIndex}_${i}`;o.setAttribute("id",h),o.setAttribute("vector-effect","non-scaling-stroke"),e&&this.#i.set(i,o);const l=s?this.#h(r,h):null,c=Xt._svgFactory.createElement("use");return n.append(c),c.setAttribute("href",`#${h}`),this.updateProperties(n,t),this.#s.set(i,n),{id:i,clipPathId:`url(#${l})`}}drawOutline(t,e){const s=this.#e++,i=this.#n(),n=Xt._svgFactory.createElement("defs");i.append(n);const r=Xt._svgFactory.createElement("path");n.append(r);const o=`path_p${this.pageIndex}_${s}`;r.setAttribute("id",o),r.setAttribute("vector-effect","non-scaling-stroke");let h;if(e){const u=Xt._svgFactory.createElement("mask");n.append(u),h=`mask_p${this.pageIndex}_${s}`,u.setAttribute("id",h),u.setAttribute("maskUnits","objectBoundingBox");const d=Xt._svgFactory.createElement("rect");u.append(d),d.setAttribute("width","1"),d.setAttribute("height","1"),d.setAttribute("fill","white");const f=Xt._svgFactory.createElement("use");u.append(f),f.setAttribute("href",`#${o}`),f.setAttribute("stroke","none"),f.setAttribute("fill","black"),f.setAttribute("fill-rule","nonzero"),f.classList.add("mask")}const l=Xt._svgFactory.createElement("use");i.append(l),l.setAttribute("href",`#${o}`),h&&l.setAttribute("mask",`url(#${h})`);const c=l.cloneNode();return i.append(c),l.classList.add("mainOutline"),c.classList.add("secondaryOutline"),this.updateProperties(i,t),this.#s.set(s,i),s}finalizeDraw(t,e){this.#i.delete(t),this.updateProperties(t,e)}updateProperties(t,e){if(!e)return;const{root:s,bbox:i,rootClass:n,path:r}=e,o=typeof t=="number"?this.#s.get(t):t;if(o){if(s&&this.#a(o,s),i&&Xt.#r(o,i),n){const{classList:h}=o;for(const[l,c]of Object.entries(n))h.toggle(l,c)}if(r){const l=o.firstChild.firstChild;this.#a(l,r)}}}updateParent(t,e){if(e===this)return;const s=this.#s.get(t);s&&(e.#t.append(s),this.#s.delete(t),e.#s.set(t,s))}remove(t){this.#i.delete(t),this.#t!==null&&(this.#s.get(t).remove(),this.#s.delete(t))}destroy(){this.#t=null;for(const t of this.#s.values())t.remove();this.#s.clear(),this.#i.clear()}}globalThis.pdfjsTestingUtils={HighlightOutliner:So},Y.AbortException,Y.AnnotationEditorLayer,Y.AnnotationEditorParamsType,Y.AnnotationEditorType,Y.AnnotationEditorUIManager,Y.AnnotationLayer,Y.AnnotationMode,Y.ColorPicker,Y.DOMSVGFactory,Y.DrawLayer,Y.FeatureTest;var Ng=Y.GlobalWorkerOptions;Y.ImageKind,Y.InvalidPDFException,Y.MissingPDFException,Y.OPS,Y.OutputScale,Y.PDFDataRangeTransport,Y.PDFDateString,Y.PDFWorker,Y.PasswordResponses,Y.PermissionFlag,Y.PixelsPerInch,Y.RenderingCancelledException,Y.TextLayer,Y.TouchManager,Y.UnexpectedResponseException,Y.Util,Y.VerbosityLevel,Y.XfaLayer,Y.build,Y.createValidAbsoluteUrl,Y.fetchData;var jg=Y.getDocument;Y.getFilenameFromUrl,Y.getPdfFilenameFromUrl,Y.getXfaPageViewport,Y.isDataScheme,Y.isPdfFile,Y.noContextMenu,Y.normalizeUnicode,Y.setLayerDimensions,Y.shadow,Y.stopEvent;var Bg=Y.version;let Nl=null;function Hg(){const a=document.createElement("div");a.style.width="1in",document.body.append(a);const t=a.offsetWidth;return a.remove(),t}function zg(){const a=Nl??Hg();return Nl=a,a/72}function Gg(a,t=500){if(typeof a!="function")throw new TypeError("The first argument is not a function.");let e=null;return function(...s){e&&clearTimeout(e),e=setTimeout(()=>{e=null,a.apply(this,s)},t)}}function Vg(a){return a.arrayBuffer?a.arrayBuffer():new Promise((t,e)=>{const s=new FileReader;s.addEventListener("load",()=>{const i=s.result;if(!(i instanceof ArrayBuffer)){e(new Error("Failed to read file as ArrayBuffer."));return}t(i)}),s.addEventListener("error",e),s.readAsArrayBuffer(a)})}jl()||(Ng.workerSrc=`https://cdnjs.cloudflare.com/ajax/libs/pdf.js/${Bg}/pdf.worker.min.mjs`);function jl(){try{return typeof OffscreenCanvas<"u"&&typeof HTMLCanvasElement<"u"&&typeof HTMLCanvasElement.prototype.transferControlToOffscreen=="function"&&globalThis.self===window.top}catch{return!1}}async function Wg({page:a,data:t,scale:e,password:s},i){const n=zg()/window.devicePixelRatio;if(jl()){const r=new Worker(new URL(""+(typeof document>"u"&&typeof location>"u"?require("url").pathToFileURL(__dirname+"/assets/pdfjs.worker-DuXj-zBo.js").href:new URL("assets/pdfjs.worker-DuXj-zBo.js",typeof document>"u"?location.href:document.currentScript&&document.currentScript.tagName.toUpperCase()==="SCRIPT"&&document.currentScript.src||document.baseURI).href),typeof document>"u"&&typeof location>"u"?require("url").pathToFileURL(__filename).href:typeof document>"u"?location.href:mt&&mt.tagName.toUpperCase()==="SCRIPT"&&mt.src||new URL("pdf-canvas.umd.js",document.baseURI).href),{type:"module"});return r.postMessage({data:t,password:s,id:i,page:a,units:n,scale:e}),await new Promise(h=>{r.addEventListener("message",l=>{if(l.data.status!=="success")return;const{bitmap:c,width:u,height:d,pages:f}=l.data;if(c){const g=document.createElement("canvas"),p=g.getContext("bitmaprenderer");g.width=u,g.height=d,p?.transferFromImageBitmap(c),h({pages:f,canvas:g})}else h({pages:f,canvas:null})})})}else{const r=await Vg(t),o=await jg({data:r,password:s}).promise,h=o.numPages;if(!i)return{canvas:null,pages:h};const l=await o.getPage(a),c=l.getViewport({scale:e}),u=document.createElement("canvas"),f={canvasContext:u.getContext("2d"),viewport:c,transform:[n,0,0,n,0,0]};return u.width=Math.floor(c.width*n),u.height=Math.floor(c.height*n),l.render(f).promise.then(()=>({canvas:u,pages:h}))}}const Ut=new Map;function Xg(a){const t=new jr(a);return Ut.set(a,t),t}function Ug(a){const t=Date.now();return{PDFId:`${a.name}-${t}`,name:a.name.replace(/.pdf/,""),updateDate:t,data:a}}async function Yg({src:a},t,e){if(!a||!e)return null;const{objects:s,options:i}=await Td(a),n=s.filter(o=>o!==null),r=Vu.groupSVGElements(n,i);return n.forEach(o=>{o.stroke=e}),r.hoverCursor="pointer",r.stroke=`${e}-${t}`,r}function $g(a,t){if(!Ut.get(a))return;const s=1/3,i=ep(t,s);Hl(a,i,s)}async function qg(a,t){const e=Date.now(),i={PDFId:`${a.name}-${e}`,name:a.name.replace(/.png|.jpg|.jpeg/,""),updateDate:e,data:a};return t&&Bl(t,{data:a}),{...i,pages:1}}async function Bl(a,{data:t,scale:e=.5}){if(!Ut.get(a))return;const i=URL.createObjectURL(t),n=await Rt.fromURL(i);n.scale(e),Hl(a,n,e),URL.revokeObjectURL(i)}function Hl(a,t,e){const s=Ut.get(a);s&&(s.setWidth(t.width*e),s.setHeight(t.height*e),s.backgroundImage=t,s.renderAll())}function Kg(a,t){if(!t)return;const{oCoords:e}=a;if(!e)return;const{x:s,y:i}=e.tl.touchCorner.tl,{height:n,width:r,scaleY:o,scaleX:h}=t;t.top=i-n*o/2,t.left=s-r*h/2,t.setCoords()}function Jg(a,t,e){!e||!a||(e.scale(1/t),Kg(a,e))}function Zg(a,t){if(!a)return;const e=a._cornerSize||6;a.borderScaleFactor=1/t,a.cornerSize=e*(1/t),a.touchCornerSize=e*4*(1/t),a.setCoords()}function Qg(a){const t=Ut.get(a);t&&(t.discardActiveObject(),t.renderAll())}function tp(a){const t=Ut.get(a);t&&(t.clear(),Ut.delete(a))}function ep(a,t){return new Rt(a,{scaleX:t,scaleY:t})}function ko(a,t){if(!t)return;const{left:e,top:s,scaleX:i,scaleY:n,width:r,height:o}=a,h=t.x*r*i,l=t.y*o*n;a.set({left:e-h,top:s-l})}function zl(a,t,e){const s=a.type;return{"application/pdf":sp,"image/png":Vl,"image/jpeg":Vl}[s]?.(a,t,e)??Promise.reject(new Error(`Unsupported ${s} file type.`))}async function sp(a,t,e){const s=Ug(a),i=await Gl({page:1,data:a,scale:.8,password:t},e);return{...s,pages:i}}function Gl(a,t){return Wg(a,t).then(({canvas:e,pages:s})=>(e&&t&&$g(t,e),s))}async function Vl(a,t,e){return await qg(a,e)}function ip(a,t){const e=Ut.get(a);if(!e)return;const s=e.getActiveObject();s&&(s instanceof ee?s.forEachObject(i=>{i.set(t)}):s.set(t),e.renderAll())}async function np(a,t){const e=Ut.get(a);if(!e)return;const s=e?.getActiveObject();if(!s)return;const i=await s.clone(ac);i instanceof ee?i.forEachObject(n=>{e.add(n),t(e,n)}):(e.add(i),t(e,i)),ko(i,{x:-.1,y:-.1}),e.setActiveObject(i)}function rp(a){const t=Ut.get(a);if(!t)return;const e=t.getActiveObject();e&&(e instanceof ee?(e.forEachObject(s=>{t.remove(s)}),t.discardActiveObject()):t.remove(e))}function Wl(a){const{id:t="",selectionOptions:e,pointerDown:s,pointerMove:i,pointerUp:n,selectionCreated:r,selectionCleared:o}=a||{},h=J.useRef(null),l=J.useRef(null),c=J.useRef(1),u=J.useRef({...oc});function d(){if(!t||Ut.has(t))return;const O=Xg(t);return O.on("selection:created",D=>{if(r?.(D),D.selected.length<=1)return;const z=O.getActiveObject();z&&(l.current=z,e?.value&&l.current.set(e.value),l.current._cornerSize=l.current.cornerSize,S(c.current))}),O.on("selection:cleared",D=>{o?.(D),T(O)}),s&&O.on("mouse:down",s),i&&O.on("mouse:move",i),n&&O.on("mouse:up",n),O}function f(O,D){return zl(O,D,t)}function g(O){return Gl(O,t)}function p({data:O,scale:D=.5}){return Bl(t,{data:O,scale:D})}async function b(O,D,z){const M=Ut.get(t);if(!M)return;const R=await Rt.fromURL(O,{},{...ic,...D});ko(R,z),M.add(R),v(M,R),M.setActiveObject(R)}function m(O,D,z){const M=Ut.get(t);if(!M)return;const R=new Dt(O,{...nc,...D});ko(R,z),M.add(R),v(M,R),M.setActiveObject(R)}function v(O,D){D.on("selected",z=>y({canvas:O,target:z.target})),D.on("modified",z=>y({canvas:O,target:z.target})),D.on("scaling",()=>T(O)),D.on("moving",()=>T(O)),D.on("rotating",()=>T(O)),D._cornerSize=D._cornerSize??D.cornerSize}async function y({canvas:O,target:D,stroke:z=u.current.stroke,uuid:M=Date.now()}){if(O.getActiveObjects().length>1||h.current?.stroke===`${z}-${M}`)return;const U=await Yg(u.current,M,z);T(O),h.current=U,l.current=D,_(O,D,M),S(c.current,!0),U&&O.add(U)}function _(O,D,z){h.current&&(h.current.on("selected",()=>{O.remove(D),T(O)}),h.current.on("mouseover",()=>{y({canvas:O,target:D,stroke:u.current.hoverStroke,uuid:z})}),h.current.on("mouseout",()=>{y({canvas:O,target:D,stroke:u.current.stroke,uuid:z})}))}function S(O,D=!1){const z=Ut.get(t);c.current=O,z&&(Zg(l.current,O),Jg(l.current,O,h.current),!D&&z.renderAll())}function A(O){if(!O)return;u.current={...u.current,...O};const D=Ut.get(t);!h||!l.current||!D||y({target:l.current,canvas:D})}function T(O){l.current=null,h.current&&(O.remove(h.current),h.current=null)}function k(){Qg(t)}function P(){tp(t)}function B(O){ip(t,O)}function F(){return np(t,v)}function I(){rp(t)}return{createCanvas:d,loadFile:f,specifyPage:g,renderImage:p,addFabric:b,addTextFabric:m,clearActive:k,deleteCanvas:P,scaleFabric:S,setCloseSvgOptions:A,setActiveFabric:B,copyActiveFabric:F,deleteActiveFabric:I}}function op(a){const t=J.useRef(0);return J.useEffect(()=>{const e=Gg(()=>{const{innerWidth:s}=globalThis;s!==t.current&&(t.current=s,a())});return t.current=window.innerWidth,window.addEventListener("resize",e),()=>window.removeEventListener("resize",e)},[]),null}const ap=J.forwardRef(hp);function hp({file:a,page:t=1,canvasId:e="PDF-canvas",fileZoom:s=1,fileScale:i=1,canvasScale:n=1,canvasClass:r="",isDrop:o=!1,password:h,dropTextOptions:l,dropImageOptions:c,closeSvgOptions:u,selectionOptions:d,manualReload:f,onLoaded:g,onReload:p,onPointerDown:b,onPointerMove:m,onPointerUp:v,onSelectionCreated:y,onSelectionCleared:_},S){const A=J.useRef(null),T=`${e}-${t-1}`,k=J.useMemo(()=>s*n,[s,n]),P=J.useMemo(()=>({...rc,...d}),[d]),{createCanvas:B,specifyPage:F,addFabric:I,addTextFabric:O,renderImage:D,clearActive:z,deleteCanvas:M,scaleFabric:R,setActiveFabric:U,setCloseSvgOptions:ht,copyActiveFabric:dt,deleteActiveFabric:E}=Wl({id:T,selectionOptions:P,pointerDown:b,pointerMove:m,pointerUp:v,selectionCreated:y,selectionCleared:_});op(rt);async function H(){globalThis.requestAnimationFrame(async()=>{if(B(),a.data?.type.startsWith("image/")){const kt=a.data;kt&&D({data:kt,scale:i/3}),g?.();return}const N=a.data;N&&await F({page:t,data:N,scale:i,password:h}),g?.()})}function V(N){if(N.preventDefault(),N.stopPropagation(),!o||!N.dataTransfer)return;const{dataTransfer:ft,nativeEvent:kt}=N,{offsetX:Zt,offsetY:lp}=kt,Xl=ft.getData("text/plain"),Ul=ft.getData("text/uri-list"),Yl=ft.getData("custom/offset"),$l=Yl?JSON.parse(Yl):null,ql={top:lp,left:Zt},Kl={x:$l?.offsetX??0,y:$l?.offsetY??0};Ul?Q(Ul,ql,Kl):Xl&&Mt(Xl,ql,Kl)}function Q(N,ft,kt){I(N,{...c,...ft},kt)}function Mt(N,ft,kt){O(N,{...l,...ft},kt)}function rt(){f||H(),p?.()}return J.useImperativeHandle(S,()=>({reload:H,addImage:Q,addText:Mt,clearActive:z,deleteCanvas:M,setActiveFabric:U,copyActiveFabric:dt,deleteActiveFabric:E,canvasRef:A})),J.useEffect(()=>{rt()},[i,t,a,h]),J.useEffect(()=>{R(k)},[k]),J.useEffect(()=>{ht(u)},[u]),J.useEffect(()=>()=>M(),[]),Ro.jsx("div",{style:{transform:`scale(${k})`},onDragOver:N=>N.preventDefault(),onDragEnter:N=>N.preventDefault(),onDrop:V,children:Ro.jsx("canvas",{id:T,ref:A,className:r})})}st.default=ap,st.loadFile=zl,st.useFabric=Wl,Object.defineProperties(st,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}));
|