@arantic/bugpin-widget 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/widget.cjs.js +586 -0
- package/dist/widget.cjs.js.map +1 -0
- package/dist/widget.esm.js +10172 -0
- package/dist/widget.esm.js.map +1 -0
- package/dist/widget.js +586 -0
- package/dist/widget.js.map +1 -0
- package/package.json +40 -0
package/dist/widget.js
ADDED
|
@@ -0,0 +1,586 @@
|
|
|
1
|
+
var BugPin=function(Ne){"use strict";var Ei=typeof document<"u"?document.currentScript:null,mr,K,Gs,me,Ns,$s,qs,Ks,Pi,Ai,ji,$e={},Zs=[],Ua=/acit|ex(?:s|g|n|p|$)|rph|grid|ows|mnc|ntw|ine[ch]|zoo|^ord|itera/i,qe=Array.isArray;function Kt(n,t){for(var e in t)n[e]=t[e];return n}function Li(n){n&&n.parentNode&&n.parentNode.removeChild(n)}function Ke(n,t,e){var r,i,s,o={};for(s in t)s=="key"?r=t[s]:s=="ref"?i=t[s]:o[s]=t[s];if(arguments.length>2&&(o.children=arguments.length>3?mr.call(arguments,2):e),typeof n=="function"&&n.defaultProps!=null)for(s in n.defaultProps)o[s]===void 0&&(o[s]=n.defaultProps[s]);return vr(n,o,r,i,null)}function vr(n,t,e,r,i){var s={type:n,props:t,key:e,ref:r,__k:null,__:null,__b:0,__e:null,__c:null,constructor:void 0,__v:i??++Gs,__i:-1,__u:0};return i==null&&K.vnode!=null&&K.vnode(s),s}function Ze(n){return n.children}function br(n,t){this.props=n,this.context=t}function Te(n,t){if(t==null)return n.__?Te(n.__,n.__i+1):null;for(var e;t<n.__k.length;t++)if((e=n.__k[t])!=null&&e.__e!=null)return e.__e;return typeof n.type=="function"?Te(n):null}function Js(n){var t,e;if((n=n.__)!=null&&n.__c!=null){for(n.__e=n.__c.base=null,t=0;t<n.__k.length;t++)if((e=n.__k[t])!=null&&e.__e!=null){n.__e=n.__c.base=e.__e;break}return Js(n)}}function Qs(n){(!n.__d&&(n.__d=!0)&&me.push(n)&&!yr.__r++||Ns!=K.debounceRendering)&&((Ns=K.debounceRendering)||$s)(yr)}function yr(){for(var n,t,e,r,i,s,o,a=1;me.length;)me.length>a&&me.sort(qs),n=me.shift(),a=me.length,n.__d&&(e=void 0,r=void 0,i=(r=(t=n).__v).__e,s=[],o=[],t.__P&&((e=Kt({},r)).__v=r.__v+1,K.vnode&&K.vnode(e),Fi(t.__P,e,r,t.__n,t.__P.namespaceURI,32&r.__u?[i]:null,s,i??Te(r),!!(32&r.__u),o),e.__v=r.__v,e.__.__k[e.__i]=e,on(s,e,o),r.__e=r.__=null,e.__e!=i&&Js(e)));yr.__r=0}function tn(n,t,e,r,i,s,o,a,l,c,h){var u,d,g,f,m,b,y,w=r&&r.__k||Zs,O=t.length;for(l=Ga(e,t,w,l,O),u=0;u<O;u++)(g=e.__k[u])!=null&&(d=g.__i==-1?$e:w[g.__i]||$e,g.__i=u,b=Fi(n,g,d,i,s,o,a,l,c,h),f=g.__e,g.ref&&d.ref!=g.ref&&(d.ref&&Bi(d.ref,null,g),h.push(g.ref,g.__c||f,g)),m==null&&f!=null&&(m=f),(y=!!(4&g.__u))||d.__k===g.__k?l=en(g,l,n,y):typeof g.type=="function"&&b!==void 0?l=b:f&&(l=f.nextSibling),g.__u&=-7);return e.__e=m,l}function Ga(n,t,e,r,i){var s,o,a,l,c,h=e.length,u=h,d=0;for(n.__k=new Array(i),s=0;s<i;s++)(o=t[s])!=null&&typeof o!="boolean"&&typeof o!="function"?(typeof o=="string"||typeof o=="number"||typeof o=="bigint"||o.constructor==String?o=n.__k[s]=vr(null,o,null,null,null):qe(o)?o=n.__k[s]=vr(Ze,{children:o},null,null,null):o.constructor==null&&o.__b>0?o=n.__k[s]=vr(o.type,o.props,o.key,o.ref?o.ref:null,o.__v):n.__k[s]=o,l=s+d,o.__=n,o.__b=n.__b+1,a=null,(c=o.__i=Na(o,e,l,u))!=-1&&(u--,(a=e[c])&&(a.__u|=2)),a==null||a.__v==null?(c==-1&&(i>h?d--:i<h&&d++),typeof o.type!="function"&&(o.__u|=4)):c!=l&&(c==l-1?d--:c==l+1?d++:(c>l?d--:d++,o.__u|=4))):n.__k[s]=null;if(u)for(s=0;s<h;s++)(a=e[s])!=null&&!(2&a.__u)&&(a.__e==r&&(r=Te(a)),ln(a,a));return r}function en(n,t,e,r){var i,s;if(typeof n.type=="function"){for(i=n.__k,s=0;i&&s<i.length;s++)i[s]&&(i[s].__=n,t=en(i[s],t,e,r));return t}n.__e!=t&&(r&&(t&&n.type&&!t.parentNode&&(t=Te(n)),e.insertBefore(n.__e,t||null)),t=n.__e);do t=t&&t.nextSibling;while(t!=null&&t.nodeType==8);return t}function rn(n,t){return t=t||[],n==null||typeof n=="boolean"||(qe(n)?n.some(function(e){rn(e,t)}):t.push(n)),t}function Na(n,t,e,r){var i,s,o,a=n.key,l=n.type,c=t[e],h=c!=null&&(2&c.__u)==0;if(c===null&&a==null||h&&a==c.key&&l==c.type)return e;if(r>(h?1:0)){for(i=e-1,s=e+1;i>=0||s<t.length;)if((c=t[o=i>=0?i--:s++])!=null&&!(2&c.__u)&&a==c.key&&l==c.type)return o}return-1}function sn(n,t,e){t[0]=="-"?n.setProperty(t,e??""):n[t]=e==null?"":typeof e!="number"||Ua.test(t)?e:e+"px"}function _r(n,t,e,r,i){var s,o;t:if(t=="style")if(typeof e=="string")n.style.cssText=e;else{if(typeof r=="string"&&(n.style.cssText=r=""),r)for(t in r)e&&t in e||sn(n.style,t,"");if(e)for(t in e)r&&e[t]==r[t]||sn(n.style,t,e[t])}else if(t[0]=="o"&&t[1]=="n")s=t!=(t=t.replace(Ks,"$1")),o=t.toLowerCase(),t=o in n||t=="onFocusOut"||t=="onFocusIn"?o.slice(2):t.slice(2),n.l||(n.l={}),n.l[t+s]=e,e?r?e.u=r.u:(e.u=Pi,n.addEventListener(t,s?ji:Ai,s)):n.removeEventListener(t,s?ji:Ai,s);else{if(i=="http://www.w3.org/2000/svg")t=t.replace(/xlink(H|:h)/,"h").replace(/sName$/,"s");else if(t!="width"&&t!="height"&&t!="href"&&t!="list"&&t!="form"&&t!="tabIndex"&&t!="download"&&t!="rowSpan"&&t!="colSpan"&&t!="role"&&t!="popover"&&t in n)try{n[t]=e??"";break t}catch{}typeof e=="function"||(e==null||e===!1&&t[4]!="-"?n.removeAttribute(t):n.setAttribute(t,t=="popover"&&e==1?"":e))}}function nn(n){return function(t){if(this.l){var e=this.l[t.type+n];if(t.t==null)t.t=Pi++;else if(t.t<e.u)return;return e(K.event?K.event(t):t)}}}function Fi(n,t,e,r,i,s,o,a,l,c){var h,u,d,g,f,m,b,y,w,O,k,S,C,A,D,L,R,H=t.type;if(t.constructor!=null)return null;128&e.__u&&(l=!!(32&e.__u),s=[a=t.__e=e.__e]),(h=K.__b)&&h(t);t:if(typeof H=="function")try{if(y=t.props,w="prototype"in H&&H.prototype.render,O=(h=H.contextType)&&r[h.__c],k=h?O?O.props.value:h.__:r,e.__c?b=(u=t.__c=e.__c).__=u.__E:(w?t.__c=u=new H(y,k):(t.__c=u=new br(y,k),u.constructor=H,u.render=qa),O&&O.sub(u),u.state||(u.state={}),u.__n=r,d=u.__d=!0,u.__h=[],u._sb=[]),w&&u.__s==null&&(u.__s=u.state),w&&H.getDerivedStateFromProps!=null&&(u.__s==u.state&&(u.__s=Kt({},u.__s)),Kt(u.__s,H.getDerivedStateFromProps(y,u.__s))),g=u.props,f=u.state,u.__v=t,d)w&&H.getDerivedStateFromProps==null&&u.componentWillMount!=null&&u.componentWillMount(),w&&u.componentDidMount!=null&&u.__h.push(u.componentDidMount);else{if(w&&H.getDerivedStateFromProps==null&&y!==g&&u.componentWillReceiveProps!=null&&u.componentWillReceiveProps(y,k),t.__v==e.__v||!u.__e&&u.shouldComponentUpdate!=null&&u.shouldComponentUpdate(y,u.__s,k)===!1){for(t.__v!=e.__v&&(u.props=y,u.state=u.__s,u.__d=!1),t.__e=e.__e,t.__k=e.__k,t.__k.some(function(I){I&&(I.__=t)}),S=0;S<u._sb.length;S++)u.__h.push(u._sb[S]);u._sb=[],u.__h.length&&o.push(u);break t}u.componentWillUpdate!=null&&u.componentWillUpdate(y,u.__s,k),w&&u.componentDidUpdate!=null&&u.__h.push(function(){u.componentDidUpdate(g,f,m)})}if(u.context=k,u.props=y,u.__P=n,u.__e=!1,C=K.__r,A=0,w){for(u.state=u.__s,u.__d=!1,C&&C(t),h=u.render(u.props,u.state,u.context),D=0;D<u._sb.length;D++)u.__h.push(u._sb[D]);u._sb=[]}else do u.__d=!1,C&&C(t),h=u.render(u.props,u.state,u.context),u.state=u.__s;while(u.__d&&++A<25);u.state=u.__s,u.getChildContext!=null&&(r=Kt(Kt({},r),u.getChildContext())),w&&!d&&u.getSnapshotBeforeUpdate!=null&&(m=u.getSnapshotBeforeUpdate(g,f)),L=h,h!=null&&h.type===Ze&&h.key==null&&(L=an(h.props.children)),a=tn(n,qe(L)?L:[L],t,e,r,i,s,o,a,l,c),u.base=t.__e,t.__u&=-161,u.__h.length&&o.push(u),b&&(u.__E=u.__=null)}catch(I){if(t.__v=null,l||s!=null)if(I.then){for(t.__u|=l?160:128;a&&a.nodeType==8&&a.nextSibling;)a=a.nextSibling;s[s.indexOf(a)]=null,t.__e=a}else{for(R=s.length;R--;)Li(s[R]);Ri(t)}else t.__e=e.__e,t.__k=e.__k,I.then||Ri(t);K.__e(I,t,e)}else s==null&&t.__v==e.__v?(t.__k=e.__k,t.__e=e.__e):a=t.__e=$a(e.__e,t,e,r,i,s,o,l,c);return(h=K.diffed)&&h(t),128&t.__u?void 0:a}function Ri(n){n&&n.__c&&(n.__c.__e=!0),n&&n.__k&&n.__k.forEach(Ri)}function on(n,t,e){for(var r=0;r<e.length;r++)Bi(e[r],e[++r],e[++r]);K.__c&&K.__c(t,n),n.some(function(i){try{n=i.__h,i.__h=[],n.some(function(s){s.call(i)})}catch(s){K.__e(s,i.__v)}})}function an(n){return typeof n!="object"||n==null||n.__b&&n.__b>0?n:qe(n)?n.map(an):Kt({},n)}function $a(n,t,e,r,i,s,o,a,l){var c,h,u,d,g,f,m,b=e.props||$e,y=t.props,w=t.type;if(w=="svg"?i="http://www.w3.org/2000/svg":w=="math"?i="http://www.w3.org/1998/Math/MathML":i||(i="http://www.w3.org/1999/xhtml"),s!=null){for(c=0;c<s.length;c++)if((g=s[c])&&"setAttribute"in g==!!w&&(w?g.localName==w:g.nodeType==3)){n=g,s[c]=null;break}}if(n==null){if(w==null)return document.createTextNode(y);n=document.createElementNS(i,w,y.is&&y),a&&(K.__m&&K.__m(t,s),a=!1),s=null}if(w==null)b===y||a&&n.data==y||(n.data=y);else{if(s=s&&mr.call(n.childNodes),!a&&s!=null)for(b={},c=0;c<n.attributes.length;c++)b[(g=n.attributes[c]).name]=g.value;for(c in b)if(g=b[c],c!="children"){if(c=="dangerouslySetInnerHTML")u=g;else if(!(c in y)){if(c=="value"&&"defaultValue"in y||c=="checked"&&"defaultChecked"in y)continue;_r(n,c,null,g,i)}}for(c in y)g=y[c],c=="children"?d=g:c=="dangerouslySetInnerHTML"?h=g:c=="value"?f=g:c=="checked"?m=g:a&&typeof g!="function"||b[c]===g||_r(n,c,g,b[c],i);if(h)a||u&&(h.__html==u.__html||h.__html==n.innerHTML)||(n.innerHTML=h.__html),t.__k=[];else if(u&&(n.innerHTML=""),tn(t.type=="template"?n.content:n,qe(d)?d:[d],t,e,r,w=="foreignObject"?"http://www.w3.org/1999/xhtml":i,s,o,s?s[0]:e.__k&&Te(e,0),a,l),s!=null)for(c=s.length;c--;)Li(s[c]);a||(c="value",w=="progress"&&f==null?n.removeAttribute("value"):f!=null&&(f!==n[c]||w=="progress"&&!f||w=="option"&&f!=b[c])&&_r(n,c,f,b[c],i),c="checked",m!=null&&m!=n[c]&&_r(n,c,m,b[c],i))}return n}function Bi(n,t,e){try{if(typeof n=="function"){var r=typeof n.__u=="function";r&&n.__u(),r&&t==null||(n.__u=n(t))}else n.current=t}catch(i){K.__e(i,e)}}function ln(n,t,e){var r,i;if(K.unmount&&K.unmount(n),(r=n.ref)&&(r.current&&r.current!=n.__e||Bi(r,null,t)),(r=n.__c)!=null){if(r.componentWillUnmount)try{r.componentWillUnmount()}catch(s){K.__e(s,t)}r.base=r.__P=null}if(r=n.__k)for(i=0;i<r.length;i++)r[i]&&ln(r[i],t,e||typeof n.type!="function");e||Li(n.__e),n.__c=n.__=n.__e=void 0}function qa(n,t,e){return this.constructor(n,e)}function Ka(n,t,e){var r,i,s,o;t==document&&(t=document.documentElement),K.__&&K.__(n,t),i=(r=!1)?null:t.__k,s=[],o=[],Fi(t,n=t.__k=Ke(Ze,null,[n]),i||$e,$e,t.namespaceURI,i?null:t.firstChild?mr.call(t.childNodes):null,s,i?i.__e:t.firstChild,r,o),on(s,n,o)}mr=Zs.slice,K={__e:function(n,t,e,r){for(var i,s,o;t=t.__;)if((i=t.__c)&&!i.__)try{if((s=i.constructor)&&s.getDerivedStateFromError!=null&&(i.setState(s.getDerivedStateFromError(n)),o=i.__d),i.componentDidCatch!=null&&(i.componentDidCatch(n,r||{}),o=i.__d),o)return i.__E=i}catch(a){n=a}throw n}},Gs=0,br.prototype.setState=function(n,t){var e;e=this.__s!=null&&this.__s!=this.state?this.__s:this.__s=Kt({},this.state),typeof n=="function"&&(n=n(Kt({},e),this.props)),n&&Kt(e,n),n!=null&&this.__v&&(t&&this._sb.push(t),Qs(this))},br.prototype.forceUpdate=function(n){this.__v&&(this.__e=!0,n&&this.__h.push(n),Qs(this))},br.prototype.render=Ze,me=[],$s=typeof Promise=="function"?Promise.prototype.then.bind(Promise.resolve()):setTimeout,qs=function(n,t){return n.__v.__b-t.__v.__b},yr.__r=0,Ks=/(PointerCapture)$|Capture$/i,Pi=0,Ai=nn(!1),ji=nn(!0);var Za=0;function _(n,t,e,r,i,s){t||(t={});var o,a,l=t;if("ref"in l)for(a in l={},t)a=="ref"?o=t[a]:l[a]=t[a];var c={type:n,props:l,key:e,ref:o,__k:null,__:null,__b:0,__e:null,__c:null,constructor:void 0,__v:--Za,__i:-1,__u:0,__source:i,__self:s};if(typeof n=="function"&&(o=n.defaultProps))for(a in o)l[a]===void 0&&(l[a]=o[a]);return K.vnode&&K.vnode(c),c}var Je,et,Ii,cn,Qe=0,hn=[],nt=K,un=nt.__b,dn=nt.__r,gn=nt.diffed,fn=nt.__c,pn=nt.unmount,mn=nt.__;function Hi(n,t){nt.__h&&nt.__h(et,n,Qe||t),Qe=0;var e=et.__H||(et.__H={__:[],__h:[]});return n>=e.__.length&&e.__.push({}),e.__[n]}function rt(n){return Qe=1,Ja(_n,n)}function Ja(n,t,e){var r=Hi(Je++,2);if(r.t=n,!r.__c&&(r.__=[_n(void 0,t),function(a){var l=r.__N?r.__N[0]:r.__[0],c=r.t(l,a);l!==c&&(r.__N=[c,r.__[1]],r.__c.setState({}))}],r.__c=et,!et.__f)){var i=function(a,l,c){if(!r.__c.__H)return!0;var h=r.__c.__H.__.filter(function(d){return!!d.__c});if(h.every(function(d){return!d.__N}))return!s||s.call(this,a,l,c);var u=r.__c.props!==a;return h.forEach(function(d){if(d.__N){var g=d.__[0];d.__=d.__N,d.__N=void 0,g!==d.__[0]&&(u=!0)}}),s&&s.call(this,a,l,c)||u};et.__f=!0;var s=et.shouldComponentUpdate,o=et.componentWillUpdate;et.componentWillUpdate=function(a,l,c){if(this.__e){var h=s;s=void 0,i(a,l,c),s=h}o&&o.call(this,a,l,c)},et.shouldComponentUpdate=i}return r.__N||r.__}function Ft(n,t){var e=Hi(Je++,3);!nt.__s&&yn(e.__H,t)&&(e.__=n,e.u=t,et.__H.__h.push(e))}function St(n){return Qe=5,vn(function(){return{current:n}},[])}function vn(n,t){var e=Hi(Je++,7);return yn(e.__H,t)&&(e.__=n(),e.__H=t,e.__h=n),e.__}function Y(n,t){return Qe=8,vn(function(){return n},t)}function Qa(){for(var n;n=hn.shift();)if(n.__P&&n.__H)try{n.__H.__h.forEach(xr),n.__H.__h.forEach(zi),n.__H.__h=[]}catch(t){n.__H.__h=[],nt.__e(t,n.__v)}}nt.__b=function(n){et=null,un&&un(n)},nt.__=function(n,t){n&&t.__k&&t.__k.__m&&(n.__m=t.__k.__m),mn&&mn(n,t)},nt.__r=function(n){dn&&dn(n),Je=0;var t=(et=n.__c).__H;t&&(Ii===et?(t.__h=[],et.__h=[],t.__.forEach(function(e){e.__N&&(e.__=e.__N),e.u=e.__N=void 0})):(t.__h.forEach(xr),t.__h.forEach(zi),t.__h=[],Je=0)),Ii=et},nt.diffed=function(n){gn&&gn(n);var t=n.__c;t&&t.__H&&(t.__H.__h.length&&(hn.push(t)!==1&&cn===nt.requestAnimationFrame||((cn=nt.requestAnimationFrame)||tl)(Qa)),t.__H.__.forEach(function(e){e.u&&(e.__H=e.u),e.u=void 0})),Ii=et=null},nt.__c=function(n,t){t.some(function(e){try{e.__h.forEach(xr),e.__h=e.__h.filter(function(r){return!r.__||zi(r)})}catch(r){t.some(function(i){i.__h&&(i.__h=[])}),t=[],nt.__e(r,e.__v)}}),fn&&fn(n,t)},nt.unmount=function(n){pn&&pn(n);var t,e=n.__c;e&&e.__H&&(e.__H.__.forEach(function(r){try{xr(r)}catch(i){t=i}}),e.__H=void 0,t&&nt.__e(t,e.__v))};var bn=typeof requestAnimationFrame=="function";function tl(n){var t,e=function(){clearTimeout(r),bn&&cancelAnimationFrame(t),setTimeout(n)},r=setTimeout(e,35);bn&&(t=requestAnimationFrame(e))}function xr(n){var t=et,e=n.__c;typeof e=="function"&&(n.__c=void 0,e()),et=t}function zi(n){var t=et;n.__c=n.__(),et=t}function yn(n,t){return!n||n.length!==t.length||t.some(function(e,r){return e!==n[r]})}function _n(n,t){return typeof t=="function"?t(n):t}/**
|
|
2
|
+
* @license lucide-preact v0.460.0 - ISC
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the ISC license.
|
|
5
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/const el=n=>n.replace(/([a-z0-9])([A-Z])/g,"$1-$2").toLowerCase(),rl=(...n)=>n.filter((t,e,r)=>!!t&&t.trim()!==""&&r.indexOf(t)===e).join(" ").trim();/**
|
|
7
|
+
* @license lucide-preact v0.460.0 - ISC
|
|
8
|
+
*
|
|
9
|
+
* This source code is licensed under the ISC license.
|
|
10
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
11
|
+
*/var il={xmlns:"http://www.w3.org/2000/svg",width:24,height:24,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round"};/**
|
|
12
|
+
* @license lucide-preact v0.460.0 - ISC
|
|
13
|
+
*
|
|
14
|
+
* This source code is licensed under the ISC license.
|
|
15
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
16
|
+
*/const sl=({color:n="currentColor",size:t=24,strokeWidth:e=2,absoluteStrokeWidth:r,children:i,iconNode:s,class:o="",...a})=>Ke("svg",{...il,width:String(t),height:t,stroke:n,"stroke-width":r?Number(e)*24/Number(t):e,class:["lucide",o].join(" "),...a},[...s.map(([l,c])=>Ke(l,c)),...rn(i)]);/**
|
|
17
|
+
* @license lucide-preact v0.460.0 - ISC
|
|
18
|
+
*
|
|
19
|
+
* This source code is licensed under the ISC license.
|
|
20
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
21
|
+
*/const Et=(n,t)=>{const e=({class:r="",children:i,...s})=>Ke(sl,{...s,iconNode:t,class:rl(`lucide-${el(n)}`,r)},i);return e.displayName=`${n}`,e};/**
|
|
22
|
+
* @license lucide-preact v0.460.0 - ISC
|
|
23
|
+
*
|
|
24
|
+
* This source code is licensed under the ISC license.
|
|
25
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
26
|
+
*/const nl=Et("Bug",[["path",{d:"m8 2 1.88 1.88",key:"fmnt4t"}],["path",{d:"M14.12 3.88 16 2",key:"qol33r"}],["path",{d:"M9 7.13v-1a3.003 3.003 0 1 1 6 0v1",key:"d7y7pr"}],["path",{d:"M12 20c-3.3 0-6-2.7-6-6v-3a4 4 0 0 1 4-4h4a4 4 0 0 1 4 4v3c0 3.3-2.7 6-6 6",key:"xs1cw7"}],["path",{d:"M12 20v-9",key:"1qisl0"}],["path",{d:"M6.53 9C4.6 8.8 3 7.1 3 5",key:"32zzws"}],["path",{d:"M6 13H2",key:"82j7cp"}],["path",{d:"M3 21c0-2.1 1.7-3.9 3.8-4",key:"4p0ekp"}],["path",{d:"M20.97 5c0 2.1-1.6 3.8-3.5 4",key:"18gb23"}],["path",{d:"M22 13h-4",key:"1jl80f"}],["path",{d:"M17.2 17c2.1.1 3.8 1.9 3.8 4",key:"k3fwyw"}]]);/**
|
|
27
|
+
* @license lucide-preact v0.460.0 - ISC
|
|
28
|
+
*
|
|
29
|
+
* This source code is licensed under the ISC license.
|
|
30
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
31
|
+
*/const ol=Et("CircleAlert",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["line",{x1:"12",x2:"12",y1:"8",y2:"12",key:"1pkeuh"}],["line",{x1:"12",x2:"12.01",y1:"16",y2:"16",key:"4dfq90"}]]);/**
|
|
32
|
+
* @license lucide-preact v0.460.0 - ISC
|
|
33
|
+
*
|
|
34
|
+
* This source code is licensed under the ISC license.
|
|
35
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
36
|
+
*/const al=Et("CircleHelp",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"M9.09 9a3 3 0 0 1 5.83 1c0 2-3 3-3 3",key:"1u773s"}],["path",{d:"M12 17h.01",key:"p32p05"}]]);/**
|
|
37
|
+
* @license lucide-preact v0.460.0 - ISC
|
|
38
|
+
*
|
|
39
|
+
* This source code is licensed under the ISC license.
|
|
40
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
41
|
+
*/const ll=Et("Flag",[["path",{d:"M4 15s1-1 4-1 5 2 8 2 4-1 4-1V3s-1 1-4 1-5-2-8-2-4 1-4 1z",key:"i9b6wo"}],["line",{x1:"4",x2:"4",y1:"22",y2:"15",key:"1cm3nv"}]]);/**
|
|
42
|
+
* @license lucide-preact v0.460.0 - ISC
|
|
43
|
+
*
|
|
44
|
+
* This source code is licensed under the ISC license.
|
|
45
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
46
|
+
*/const cl=Et("Heart",[["path",{d:"M19 14c1.49-1.46 3-3.21 3-5.5A5.5 5.5 0 0 0 16.5 3c-1.76 0-3 .5-4.5 2-1.5-1.5-2.74-2-4.5-2A5.5 5.5 0 0 0 2 8.5c0 2.3 1.5 4.05 3 5.5l7 7Z",key:"c3ymky"}]]);/**
|
|
47
|
+
* @license lucide-preact v0.460.0 - ISC
|
|
48
|
+
*
|
|
49
|
+
* This source code is licensed under the ISC license.
|
|
50
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
51
|
+
*/const hl=Et("Info",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"M12 16v-4",key:"1dtifu"}],["path",{d:"M12 8h.01",key:"e9boi3"}]]);/**
|
|
52
|
+
* @license lucide-preact v0.460.0 - ISC
|
|
53
|
+
*
|
|
54
|
+
* This source code is licensed under the ISC license.
|
|
55
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
56
|
+
*/const ul=Et("Mail",[["rect",{width:"20",height:"16",x:"2",y:"4",rx:"2",key:"18n3k1"}],["path",{d:"m22 7-8.97 5.7a1.94 1.94 0 0 1-2.06 0L2 7",key:"1ocrg3"}]]);/**
|
|
57
|
+
* @license lucide-preact v0.460.0 - ISC
|
|
58
|
+
*
|
|
59
|
+
* This source code is licensed under the ISC license.
|
|
60
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
61
|
+
*/const dl=Et("MessageSquare",[["path",{d:"M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z",key:"1lielz"}]]);/**
|
|
62
|
+
* @license lucide-preact v0.460.0 - ISC
|
|
63
|
+
*
|
|
64
|
+
* This source code is licensed under the ISC license.
|
|
65
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
66
|
+
*/const gl=Et("Send",[["path",{d:"M14.536 21.686a.5.5 0 0 0 .937-.024l6.5-19a.496.496 0 0 0-.635-.635l-19 6.5a.5.5 0 0 0-.024.937l7.93 3.18a2 2 0 0 1 1.112 1.11z",key:"1ffxy3"}],["path",{d:"m21.854 2.147-10.94 10.939",key:"12cjpa"}]]);/**
|
|
67
|
+
* @license lucide-preact v0.460.0 - ISC
|
|
68
|
+
*
|
|
69
|
+
* This source code is licensed under the ISC license.
|
|
70
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
71
|
+
*/const fl=Et("Settings",[["path",{d:"M12.22 2h-.44a2 2 0 0 0-2 2v.18a2 2 0 0 1-1 1.73l-.43.25a2 2 0 0 1-2 0l-.15-.08a2 2 0 0 0-2.73.73l-.22.38a2 2 0 0 0 .73 2.73l.15.1a2 2 0 0 1 1 1.72v.51a2 2 0 0 1-1 1.74l-.15.09a2 2 0 0 0-.73 2.73l.22.38a2 2 0 0 0 2.73.73l.15-.08a2 2 0 0 1 2 0l.43.25a2 2 0 0 1 1 1.73V20a2 2 0 0 0 2 2h.44a2 2 0 0 0 2-2v-.18a2 2 0 0 1 1-1.73l.43-.25a2 2 0 0 1 2 0l.15.08a2 2 0 0 0 2.73-.73l.22-.39a2 2 0 0 0-.73-2.73l-.15-.08a2 2 0 0 1-1-1.74v-.5a2 2 0 0 1 1-1.74l.15-.09a2 2 0 0 0 .73-2.73l-.22-.38a2 2 0 0 0-2.73-.73l-.15.08a2 2 0 0 1-2 0l-.43-.25a2 2 0 0 1-1-1.73V4a2 2 0 0 0-2-2z",key:"1qme2f"}],["circle",{cx:"12",cy:"12",r:"3",key:"1v7zrd"}]]);/**
|
|
72
|
+
* @license lucide-preact v0.460.0 - ISC
|
|
73
|
+
*
|
|
74
|
+
* This source code is licensed under the ISC license.
|
|
75
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
76
|
+
*/const pl=Et("Star",[["path",{d:"M11.525 2.295a.53.53 0 0 1 .95 0l2.31 4.679a2.123 2.123 0 0 0 1.595 1.16l5.166.756a.53.53 0 0 1 .294.904l-3.736 3.638a2.123 2.123 0 0 0-.611 1.878l.882 5.14a.53.53 0 0 1-.771.56l-4.618-2.428a2.122 2.122 0 0 0-1.973 0L6.396 21.01a.53.53 0 0 1-.77-.56l.881-5.139a2.122 2.122 0 0 0-.611-1.879L2.16 9.795a.53.53 0 0 1 .294-.906l5.165-.755a2.122 2.122 0 0 0 1.597-1.16z",key:"r04s7s"}]]);/**
|
|
77
|
+
* @license lucide-preact v0.460.0 - ISC
|
|
78
|
+
*
|
|
79
|
+
* This source code is licensed under the ISC license.
|
|
80
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
81
|
+
*/const ml=Et("Zap",[["path",{d:"M4 14a1 1 0 0 1-.78-1.63l9.9-10.2a.5.5 0 0 1 .86.46l-1.92 6.02A1 1 0 0 0 13 10h7a1 1 0 0 1 .78 1.63l-9.9 10.2a.5.5 0 0 1-.86-.46l1.92-6.02A1 1 0 0 0 11 14z",key:"1xq2db"}]]),vl={bug:nl,"message-square":dl,"alert-circle":ol,"help-circle":al,mail:ul,send:gl,flag:ll,star:pl,zap:ml,heart:cl,info:hl,settings:fl},bl=({name:n,class:t,size:e=18,strokeWidth:r=2})=>{const i=vl[n];return i?_(i,{class:t,size:e,strokeWidth:r}):null},yl=({position:n,buttonText:t,buttonShape:e,buttonIcon:r,buttonIconSize:i,buttonIconStroke:s,theme:o,lightButtonColor:a,lightTextColor:l,lightButtonHoverColor:c,lightTextHoverColor:h,darkButtonColor:u,darkTextColor:d,darkButtonHoverColor:g,darkTextHoverColor:f,enableHoverScaleEffect:m,tooltipEnabled:b,tooltipText:y,onClick:w})=>{const[O,k]=rt(!1),[S,C]=rt(!1),[A,D]=rt({left:"50%",transform:"translateX(-50%)",arrowLeft:"50%"}),L=St(null),R=St(null);Ft(()=>{if(o==="dark"){C(!0);return}else if(o==="light"){C(!1);return}const ct=window.matchMedia("(prefers-color-scheme: dark)");C(ct.matches);const T=F=>C(F.matches);return ct.addEventListener("change",T),()=>ct.removeEventListener("change",T)},[o]),Ft(()=>{if(O&&L.current&&R.current){const ct=L.current,T=R.current;requestAnimationFrame(()=>{const F=ct.getBoundingClientRect(),P=T.getBoundingClientRect(),B=window.innerWidth,$=4,q=P.left+P.width/2,mt=F.width/2;let le=0;const dt=q-mt;dt<$?le=$-dt:dt+F.width>B-$&&(le=B-$-(dt+F.width)),D({left:"50%",transform:`translateX(-50%) translateX(${le}px)`,arrowLeft:"50%"})})}},[O,y]);const H=S?O?g:u:O?c:a,I=S?O?f:d:O?h:l,M=S?u:a,j=S?d:l,z=e==="round"?"50%":"8px",V=t||"Report Bug",tt=e==="round"?`${i/2}px`:"12px 20px",N=`bugpin-launcher-button${m?" hover-scale":""}`,Ct={position:"absolute",bottom:"100%",marginBottom:"8px",padding:"6px 12px",backgroundColor:M,color:j,fontSize:"12px",borderRadius:"4px",whiteSpace:"nowrap",pointerEvents:"none",zIndex:"2147483647",opacity:"0",animation:"bugpin-tooltip-fade-in 0.2s ease-in-out forwards",boxShadow:"0 2px 8px rgba(0, 0, 0, 0.2)",left:A.left,transform:A.transform},Mt={position:"absolute",top:"100%",left:A.arrowLeft,transform:"translateX(-50%)",marginTop:"-4px",borderWidth:"4px",borderStyle:"solid",borderColor:`${M} transparent transparent transparent`};return _("div",{class:`bugpin-launcher-button-container ${n}`,style:{position:"fixed",zIndex:"2147483647"},children:[_("button",{ref:R,class:N,style:{position:"relative",backgroundColor:H,color:I,borderRadius:z,padding:tt,transition:"background-color 0.2s ease, color 0.2s ease"},onClick:w,onMouseEnter:()=>k(!0),onMouseLeave:()=>k(!1),"aria-label":V,children:[r&&_(bl,{name:r,size:i,strokeWidth:s}),t&&_("span",{children:t})]}),b&&y&&O&&_("div",{ref:L,class:"bugpin-tooltip",style:Ct,children:[y,_("div",{style:Mt})]})]})},_l=({tabs:n,activeTab:t,onTabChange:e})=>_("div",{class:"bugpin-tabs",children:n.map(r=>_("button",{type:"button",class:`bugpin-tab ${t===r.id?"active":""}`,onClick:()=>e(r.id),children:[r.icon&&_("span",{class:"bugpin-tab-icon",children:r.icon}),r.label]},r.id))}),xl=10*1024*1024,wl=50*1024*1024,Cl=["image/png","image/jpeg","image/gif","image/webp"],Sl=["video/mp4","video/webm","video/quicktime","video/x-msvideo"],Tl=({media:n,onCapture:t,onUpload:e,onRemove:r,onAnnotate:i,isCapturing:s,enableAnnotation:o})=>{const[a,l]=rt(!1),[c,h]=rt(null),u=St(null),d=C=>C.startsWith("video/"),g=C=>C.startsWith("image/"),f=Y(C=>{if(g(C.type)){if(!Cl.includes(C.type))return`Unsupported image format: ${C.type}`;if(C.size>xl)return"Image too large. Maximum size is 10MB."}else if(d(C.type)){if(!Sl.includes(C.type))return`Unsupported video format: ${C.type}`;if(C.size>wl)return"Video too large. Maximum size is 50MB."}else return`Unsupported file type: ${C.type}`;return null},[]),m=Y(async C=>{const A=f(C);if(A){h(A);return}h(null);const D=new FileReader;D.onload=()=>{const L=D.result;if(g(C.type)){const R=new Image;R.onload=()=>{const H={id:`upload-${Date.now()}-${Math.random().toString(36).slice(2,9)}`,dataUrl:L,timestamp:new Date,annotated:!1,mimeType:C.type,width:R.width,height:R.height};e(H)},R.src=L}else if(d(C.type)){const R=document.createElement("video");R.onloadedmetadata=()=>{const H={id:`upload-${Date.now()}-${Math.random().toString(36).slice(2,9)}`,dataUrl:L,timestamp:new Date,annotated:!1,mimeType:C.type,width:R.videoWidth,height:R.videoHeight};e(H)},R.src=L}},D.readAsDataURL(C)},[f,e]),b=Y(C=>{C.preventDefault(),C.stopPropagation(),l(!0)},[]),y=Y(C=>{C.preventDefault(),C.stopPropagation(),l(!1)},[]),w=Y(async C=>{var D;C.preventDefault(),C.stopPropagation(),l(!1);const A=(D=C.dataTransfer)==null?void 0:D.files;if(A)for(let L=0;L<A.length;L++)await m(A[L])},[m]),O=Y(async C=>{const A=C.target,D=A.files;if(D)for(let L=0;L<D.length;L++)await m(D[L]);A.value=""},[m]),k=Y(()=>{var C;(C=u.current)==null||C.click()},[]),S=C=>C.toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"});return _("div",{class:"bugpin-screenshot-manager",children:[_("div",{class:"bugpin-media-actions",children:[_("button",{type:"button",class:"bugpin-btn-action",onClick:t,disabled:s,children:[_("svg",{viewBox:"0 0 24 24",xmlns:"http://www.w3.org/2000/svg",children:_("path",{d:"M12 15.2c1.77 0 3.2-1.43 3.2-3.2S13.77 8.8 12 8.8 8.8 10.23 8.8 12s1.43 3.2 3.2 3.2zM9 2L7.17 4H4c-1.1 0-2 .9-2 2v12c0 1.1.9 2 2 2h16c1.1 0 2-.9 2-2V6c0-1.1-.9-2-2-2h-3.17L15 2H9zm3 15c-2.76 0-5-2.24-5-5s2.24-5 5-5 5 2.24 5 5-2.24 5-5 5z",fill:"currentColor"})}),s?"Capturing...":"Capture Screenshot"]}),_("button",{type:"button",class:"bugpin-btn-action bugpin-btn-action-secondary",onClick:k,children:[_("svg",{viewBox:"0 0 24 24",xmlns:"http://www.w3.org/2000/svg",children:_("path",{d:"M19.35 10.04C18.67 6.59 15.64 4 12 4 9.11 4 6.6 5.64 5.35 8.04 2.34 8.36 0 10.91 0 14c0 3.31 2.69 6 6 6h13c2.76 0 5-2.24 5-5 0-2.64-2.05-4.78-4.65-4.96zM14 13v4h-4v-4H7l5-5 5 5h-3z",fill:"currentColor"})}),"Upload File"]}),_("input",{ref:u,type:"file",accept:"image/*,video/*",multiple:!0,style:{display:"none"},onChange:O})]}),c&&_("div",{class:"bugpin-upload-error",children:[_("svg",{viewBox:"0 0 24 24",xmlns:"http://www.w3.org/2000/svg",children:_("path",{d:"M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm1 15h-2v-2h2v2zm0-4h-2V7h2v6z",fill:"currentColor"})}),c]}),_("div",{class:`bugpin-drop-zone ${a?"dragging":""} ${n.length>0?"has-media":""}`,onDragOver:b,onDragLeave:y,onDrop:w,children:n.length===0?_("div",{class:"bugpin-drop-placeholder",children:[_("svg",{viewBox:"0 0 24 24",xmlns:"http://www.w3.org/2000/svg",children:_("path",{d:"M21 19V5c0-1.1-.9-2-2-2H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2zM8.5 13.5l2.5 3.01L14.5 12l4.5 6H5l3.5-4.5z",fill:"currentColor"})}),_("p",{children:"Drag and drop images or videos here"}),_("span",{children:"or use the buttons above"})]}):_(Ze,{children:[_("div",{class:"bugpin-media-grid",children:n.map(C=>_("div",{class:"bugpin-media-card",children:[_("div",{class:"bugpin-media-preview",children:[d(C.mimeType)?_("video",{src:C.dataUrl,muted:!0}):_("img",{src:C.dataUrl,alt:"Screenshot"}),_("div",{class:"bugpin-media-badges",children:[C.annotated&&_("span",{class:"bugpin-badge annotated",children:"Annotated"}),d(C.mimeType)&&_("span",{class:"bugpin-badge video",children:"Video"})]})]}),_("div",{class:"bugpin-media-info",children:[_("span",{class:"bugpin-media-time",children:S(C.timestamp)}),C.width&&C.height&&_("span",{class:"bugpin-media-dimensions",children:[C.width," × ",C.height]})]}),_("div",{class:"bugpin-media-item-actions",children:[o&&g(C.mimeType)&&_("button",{type:"button",class:"bugpin-btn-icon",onClick:()=>i(C.id),title:"Annotate",children:_("svg",{viewBox:"0 0 24 24",xmlns:"http://www.w3.org/2000/svg",children:_("path",{d:"M3 17.25V21h3.75L17.81 9.94l-3.75-3.75L3 17.25zM20.71 7.04a.996.996 0 000-1.41l-2.34-2.34a.996.996 0 00-1.41 0l-1.83 1.83 3.75 3.75 1.83-1.83z",fill:"currentColor"})})}),_("button",{type:"button",class:"bugpin-btn-icon bugpin-btn-icon-danger",onClick:()=>r(C.id),title:"Remove",children:_("svg",{viewBox:"0 0 24 24",xmlns:"http://www.w3.org/2000/svg",children:_("path",{d:"M6 19c0 1.1.9 2 2 2h8c1.1 0 2-.9 2-2V7H6v12zM19 4h-3.5l-1-1h-5l-1 1H5v2h14V4z",fill:"currentColor"})})})]})]},C.id))}),_("div",{class:"bugpin-drop-more",children:_("span",{children:"Drop more files here"})})]})}),_("p",{class:"bugpin-helper-text",children:"Supported: PNG, JPG, GIF, WebP (max 10MB) • MP4, WebM, MOV, AVI (max 50MB)"})]})},kl=[{id:"details",label:"Details",icon:_("svg",{viewBox:"0 0 24 24",xmlns:"http://www.w3.org/2000/svg",children:_("path",{d:"M14 2H6c-1.1 0-1.99.9-1.99 2L4 20c0 1.1.89 2 1.99 2H18c1.1 0 2-.9 2-2V8l-6-6zm2 16H8v-2h8v2zm0-4H8v-2h8v2zm-3-5V3.5L18.5 9H13z",fill:"currentColor"})})},{id:"media",label:"Screenshots",icon:_("svg",{viewBox:"0 0 24 24",xmlns:"http://www.w3.org/2000/svg",children:_("path",{d:"M21 19V5c0-1.1-.9-2-2-2H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2zM8.5 13.5l2.5 3.01L14.5 12l4.5 6H5l3.5-4.5z",fill:"currentColor"})})}],Ol=({onClose:n,onSubmit:t,onCaptureScreenshot:e,onAnnotateMedia:r,media:i,onAddMedia:s,onRemoveMedia:o,isSubmitting:a,isCapturing:l,enableAnnotation:c,activeTab:h,onActiveTabChange:u,formData:d,onFormDataChange:g})=>{const[f,m]=rt({}),b=Y((S,C)=>{g({...d,[S]:C}),f[S]&&m(A=>({...A,[S]:void 0}))},[d,g,f]),y=Y(()=>{const S={};return d.title.trim()?d.title.trim().length<4&&(S.title="Title must be at least 4 characters"):S.title="Title is required",d.reporterEmail&&!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(d.reporterEmail)&&(S.reporterEmail="Invalid email address"),m(S),Object.keys(S).length===0},[d]),w=Y(S=>{if(S.preventDefault(),!y()){u("details");return}t(d,i)},[d,i,y,t,u]),O=Y(S=>{S.target.classList.contains("bugpin-overlay")&&n()},[n]),k=i.length;return _("div",{class:"bugpin-overlay",onClick:O,children:_("div",{class:"bugpin-dialog bugpin-dialog-tabbed",role:"dialog","aria-modal":"true","aria-labelledby":"bugpin-title",children:[_("div",{class:"bugpin-header",children:[_("h2",{id:"bugpin-title",children:"Report a Bug"}),_("button",{class:"bugpin-close",onClick:n,"aria-label":"Close",children:_("svg",{viewBox:"0 0 24 24",xmlns:"http://www.w3.org/2000/svg",children:_("path",{d:"M19 6.41L17.59 5 12 10.59 6.41 5 5 6.41 10.59 12 5 17.59 6.41 19 12 13.41 17.59 19 19 17.59 13.41 12z",fill:"currentColor"})})})]}),_("div",{class:"bugpin-tabs-container",children:_(_l,{tabs:kl.map(S=>({...S,label:S.id==="media"&&k>0?`${S.label} (${k})`:S.label})),activeTab:h,onTabChange:u})}),_("div",{class:"bugpin-body",children:[h==="details"&&_("form",{class:"bugpin-form",onSubmit:w,children:[_("div",{class:"bugpin-field",children:[_("label",{class:"bugpin-label required",for:"bugpin-title-input",children:"Title"}),_("input",{id:"bugpin-title-input",class:"bugpin-input",type:"text",placeholder:"Brief description of the issue",value:d.title,onInput:S=>b("title",S.target.value),maxLength:200}),f.title&&_("span",{class:"bugpin-error",children:f.title})]}),_("div",{class:"bugpin-field",children:[_("label",{class:"bugpin-label",for:"bugpin-description",children:"Description"}),_("textarea",{id:"bugpin-description",class:"bugpin-textarea",placeholder:"Steps to reproduce, expected behavior, etc.",value:d.description,onInput:S=>b("description",S.target.value)})]}),_("div",{class:"bugpin-field",children:[_("label",{class:"bugpin-label",for:"bugpin-priority",children:"Priority"}),_("select",{id:"bugpin-priority",class:"bugpin-select",value:d.priority,onChange:S=>b("priority",S.target.value),children:[_("option",{value:"lowest",children:"Lowest"}),_("option",{value:"low",children:"Low"}),_("option",{value:"medium",children:"Medium"}),_("option",{value:"high",children:"High"}),_("option",{value:"highest",children:"Highest"})]})]}),_("div",{class:"bugpin-field",children:[_("label",{class:"bugpin-label",for:"bugpin-email",children:"Email (optional)"}),_("input",{id:"bugpin-email",class:"bugpin-input",type:"email",placeholder:"your@email.com",value:d.reporterEmail,onInput:S=>b("reporterEmail",S.target.value)}),f.reporterEmail&&_("span",{class:"bugpin-error",children:f.reporterEmail})]}),_("div",{class:"bugpin-field",children:[_("label",{class:"bugpin-label",for:"bugpin-name",children:"Name (optional)"}),_("input",{id:"bugpin-name",class:"bugpin-input",type:"text",placeholder:"Your name",value:d.reporterName,onInput:S=>b("reporterName",S.target.value)})]})]}),h==="media"&&_(Tl,{media:i,onCapture:e,onUpload:s,onRemove:o,onAnnotate:r,isCapturing:l,enableAnnotation:c})]}),_("div",{class:"bugpin-footer",children:[_("button",{type:"button",class:"bugpin-btn-cancel",onClick:n,disabled:a,children:"Cancel"}),_("button",{type:"submit",class:"bugpin-btn-submit",onClick:w,disabled:a,children:a?_("span",{class:"bugpin-spinner"}):"Submit Report"})]})]})})},Dl=({message:n,type:t,onClose:e,duration:r=5e3})=>(Ft(()=>{const i=setTimeout(e,r);return()=>clearTimeout(i)},[e,r]),_("div",{class:`bugpin-toast ${t}`,role:"alert",children:[t==="success"&&_("svg",{viewBox:"0 0 24 24",xmlns:"http://www.w3.org/2000/svg",children:_("path",{d:"M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm-2 15l-5-5 1.41-1.41L10 14.17l7.59-7.59L19 8l-9 9z",fill:"currentColor"})}),t==="error"&&_("svg",{viewBox:"0 0 24 24",xmlns:"http://www.w3.org/2000/svg",children:_("path",{d:"M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm1 15h-2v-2h2v2zm0-4h-2V7h2v6z",fill:"currentColor"})}),_("span",{children:n})]}));function p(n,t,e){return(t=function(r){var i=function(s,o){if(typeof s!="object"||!s)return s;var a=s[Symbol.toPrimitive];if(a!==void 0){var l=a.call(s,o);if(typeof l!="object")return l;throw new TypeError("@@toPrimitive must return a primitive value.")}return(o==="string"?String:Number)(s)}(r,"string");return typeof i=="symbol"?i:i+""}(t))in n?Object.defineProperty(n,t,{value:e,enumerable:!0,configurable:!0,writable:!0}):n[t]=e,n}function xn(n,t){var e=Object.keys(n);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(n);t&&(r=r.filter(function(i){return Object.getOwnPropertyDescriptor(n,i).enumerable})),e.push.apply(e,r)}return e}function v(n){for(var t=1;t<arguments.length;t++){var e=arguments[t]!=null?arguments[t]:{};t%2?xn(Object(e),!0).forEach(function(r){p(n,r,e[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(n,Object.getOwnPropertyDescriptors(e)):xn(Object(e)).forEach(function(r){Object.defineProperty(n,r,Object.getOwnPropertyDescriptor(e,r))})}return n}function J(n,t){if(n==null)return{};var e,r,i=function(o,a){if(o==null)return{};var l={};for(var c in o)if({}.hasOwnProperty.call(o,c)){if(a.indexOf(c)>=0)continue;l[c]=o[c]}return l}(n,t);if(Object.getOwnPropertySymbols){var s=Object.getOwnPropertySymbols(n);for(r=0;r<s.length;r++)e=s[r],t.indexOf(e)>=0||{}.propertyIsEnumerable.call(n,e)&&(i[e]=n[e])}return i}function Yt(n,t){return t||(t=n.slice(0)),Object.freeze(Object.defineProperties(n,{raw:{value:Object.freeze(t)}}))}class wn{constructor(){p(this,"browserShadowBlurConstant",1),p(this,"DPI",96),p(this,"devicePixelRatio",typeof window<"u"?window.devicePixelRatio:1),p(this,"perfLimitSizeTotal",2097152),p(this,"maxCacheSideLimit",4096),p(this,"minCacheSideLimit",256),p(this,"disableStyleCopyPaste",!1),p(this,"enableGLFiltering",!0),p(this,"textureSize",4096),p(this,"forceGLPutImageData",!1),p(this,"cachesBoundsOfCurve",!1),p(this,"fontPaths",{}),p(this,"NUM_FRACTION_DIGITS",4)}}const X=new class extends wn{constructor(n){super(),this.configure(n)}configure(){let n=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};Object.assign(this,n)}addFonts(){let n=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};this.fontPaths=v(v({},this.fontPaths),n)}removeFonts(){(arguments.length>0&&arguments[0]!==void 0?arguments[0]:[]).forEach(n=>{delete this.fontPaths[n]})}clearFonts(){this.fontPaths={}}restoreDefaults(n){const t=new wn,e=(n==null?void 0:n.reduce((r,i)=>(r[i]=t[i],r),{}))||t;this.configure(e)}},ce=function(n){for(var t=arguments.length,e=new Array(t>1?t-1:0),r=1;r<t;r++)e[r-1]=arguments[r];return console[n]("fabric",...e)};class Ut extends Error{constructor(t,e){super("fabric: ".concat(t),e)}}class Ml extends Ut{constructor(t){super("".concat(t," 'options.signal' is in 'aborted' state"))}}class El{}class Pl extends El{testPrecision(t,e){const r="precision ".concat(e,` float;
|
|
82
|
+
void main(){}`),i=t.createShader(t.FRAGMENT_SHADER);return!!i&&(t.shaderSource(i,r),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(r=>this.testPrecision(e,r)),e.getExtension("WEBGL_lose_context").loseContext(),ce("log","WebGL: max texture size ".concat(this.maxTextureSize)))}isSupported(t){return!!this.maxTextureSize&&this.maxTextureSize>=t}}const Al={};let Cn;const Gt=()=>Cn||(Cn={document,window,isTouchSupported:"ontouchstart"in window||"ontouchstart"in document||window&&window.navigator&&window.navigator.maxTouchPoints>0,WebGLProbe:new Pl,dispose(){},copyPasteData:Al}),ke=()=>Gt().document,wr=()=>Gt().window,Sn=()=>{var n;return Math.max((n=X.devicePixelRatio)!==null&&n!==void 0?n:wr().devicePixelRatio,1)},tr=new class{constructor(){p(this,"boundsOfCurveCache",{}),this.charWidthsCache=new Map}getFontCache(n){let{fontFamily:t,fontStyle:e,fontWeight:r}=n;t=t.toLowerCase();const i=this.charWidthsCache;i.has(t)||i.set(t,new Map);const s=i.get(t),o="".concat(e.toLowerCase(),"_").concat((r+"").toLowerCase());return s.has(o)||s.set(o,new Map),s.get(o)}clearFontCache(n){n?this.charWidthsCache.delete((n||"").toLowerCase()):this.charWidthsCache=new Map}limitDimsByArea(n){const{perfLimitSizeTotal:t}=X,e=Math.sqrt(t*n);return[Math.floor(e),Math.floor(t/e)]}},Wi="6.9.1";function Cr(){}const er=Math.PI/2,Sr=2*Math.PI,Vi=Math.PI/180,gt=Object.freeze([1,0,0,1,0,0]),Xi=16,he=.4477152502,W="center",U="left",vt="top",Yi="bottom",it="right",bt="none",Ui=/\r?\n/,Tn="moving",Tr="scaling",kn="rotating",Gi="rotate",On="skewing",rr="resizing",jl="modifyPoly",Ll="modifyPath",kr="changed",Or="scale",yt="scaleX",Pt="scaleY",Oe="skewX",De="skewY",at="fill",_t="stroke",Dr="modified",Me="json",Ni="svg",E=new class{constructor(){this[Me]=new Map,this[Ni]=new Map}has(n){return this[Me].has(n)}getClass(n){const t=this[Me].get(n);if(!t)throw new Ut("No class registered for ".concat(n));return t}setClass(n,t){t?this[Me].set(t,n):(this[Me].set(n.type,n),this[Me].set(n.type.toLowerCase(),n))}getSVGClass(n){return this[Ni].get(n)}setSVGClass(n,t){this[Ni].set(t??n.type.toLowerCase(),n)}},Mr=new class extends Array{remove(n){const t=this.indexOf(n);t>-1&&this.splice(t,1)}cancelAll(){const n=this.splice(0);return n.forEach(t=>t.abort()),n}cancelByCanvas(n){if(!n)return[];const t=this.filter(e=>{var r;return e.target===n||typeof e.target=="object"&&((r=e.target)===null||r===void 0?void 0:r.canvas)===n});return t.forEach(e=>e.abort()),t}cancelByTarget(n){if(!n)return[];const t=this.filter(e=>e.target===n);return t.forEach(e=>e.abort()),t}};class Fl{constructor(){p(this,"__eventListeners",{})}on(t,e){if(this.__eventListeners||(this.__eventListeners={}),typeof t=="object")return Object.entries(t).forEach(r=>{let[i,s]=r;this.on(i,s)}),()=>this.off(t);if(e){const r=t;return this.__eventListeners[r]||(this.__eventListeners[r]=[]),this.__eventListeners[r].push(e),()=>this.off(r,e)}return()=>!1}once(t,e){if(typeof t=="object"){const r=[];return Object.entries(t).forEach(i=>{let[s,o]=i;r.push(this.once(s,o))}),()=>r.forEach(i=>i())}if(e){const r=this.on(t,function(){for(var i=arguments.length,s=new Array(i),o=0;o<i;o++)s[o]=arguments[o];e.call(this,...s),r()});return r}return()=>!1}_removeEventListener(t,e){if(this.__eventListeners[t])if(e){const r=this.__eventListeners[t],i=r.indexOf(e);i>-1&&r.splice(i,1)}else this.__eventListeners[t]=[]}off(t,e){if(this.__eventListeners)if(t===void 0)for(const r in this.__eventListeners)this._removeEventListener(r);else typeof t=="object"?Object.entries(t).forEach(r=>{let[i,s]=r;this._removeEventListener(i,s)}):this._removeEventListener(t,e)}fire(t,e){var r;if(!this.__eventListeners)return;const i=(r=this.__eventListeners[t])===null||r===void 0?void 0:r.concat();if(i)for(let s=0;s<i.length;s++)i[s].call(this,e||{})}}const Ee=(n,t)=>{const e=n.indexOf(t);return e!==-1&&n.splice(e,1),n},Zt=n=>{if(n===0)return 1;switch(Math.abs(n)/er){case 1:case 3:return 0;case 2:return-1}return Math.cos(n)},Jt=n=>{if(n===0)return 0;const t=n/er,e=Math.sign(n);switch(t){case 1:return e;case 2:return 0;case 3:return-e}return Math.sin(n)};class x{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 x(this.x+t.x,this.y+t.y)}addEquals(t){return this.x+=t.x,this.y+=t.y,this}scalarAdd(t){return new x(this.x+t,this.y+t)}scalarAddEquals(t){return this.x+=t,this.y+=t,this}subtract(t){return new x(this.x-t.x,this.y-t.y)}subtractEquals(t){return this.x-=t.x,this.y-=t.y,this}scalarSubtract(t){return new x(this.x-t,this.y-t)}scalarSubtractEquals(t){return this.x-=t,this.y-=t,this}multiply(t){return new x(this.x*t.x,this.y*t.y)}scalarMultiply(t){return new x(this.x*t,this.y*t)}scalarMultiplyEquals(t){return this.x*=t,this.y*=t,this}divide(t){return new x(this.x/t.x,this.y/t.y)}scalarDivide(t){return new x(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 x(this.x+(t.x-this.x)*e,this.y+(t.y-this.y)*e)}distanceFrom(t){const e=this.x-t.x,r=this.y-t.y;return Math.sqrt(e*e+r*r)}midPointFrom(t){return this.lerp(t)}min(t){return new x(Math.min(this.x,t.x),Math.min(this.y,t.y))}max(t){return new x(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,r=this.y;this.x=t.x,this.y=t.y,t.x=e,t.y=r}clone(){return new x(this.x,this.y)}rotate(t){let e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:$i;const r=Jt(t),i=Zt(t),s=this.subtract(e);return new x(s.x*i-s.y*r,s.x*r+s.y*i).add(e)}transform(t){let e=arguments.length>1&&arguments[1]!==void 0&&arguments[1];return new x(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 $i=new x(0,0),Er=n=>!!n&&Array.isArray(n._objects);function Dn(n){class t extends n{constructor(){super(...arguments),p(this,"_objects",[])}_onObjectAdded(r){}_onObjectRemoved(r){}_onStackOrderChanged(r){}add(){for(var r=arguments.length,i=new Array(r),s=0;s<r;s++)i[s]=arguments[s];const o=this._objects.push(...i);return i.forEach(a=>this._onObjectAdded(a)),o}insertAt(r){for(var i=arguments.length,s=new Array(i>1?i-1:0),o=1;o<i;o++)s[o-1]=arguments[o];return this._objects.splice(r,0,...s),s.forEach(a=>this._onObjectAdded(a)),this._objects.length}remove(){const r=this._objects,i=[];for(var s=arguments.length,o=new Array(s),a=0;a<s;a++)o[a]=arguments[a];return o.forEach(l=>{const c=r.indexOf(l);c!==-1&&(r.splice(c,1),i.push(l),this._onObjectRemoved(l))}),i}forEachObject(r){this.getObjects().forEach((i,s,o)=>r(i,s,o))}getObjects(){for(var r=arguments.length,i=new Array(r),s=0;s<r;s++)i[s]=arguments[s];return i.length===0?[...this._objects]:this._objects.filter(o=>o.isType(...i))}item(r){return this._objects[r]}isEmpty(){return this._objects.length===0}size(){return this._objects.length}contains(r,i){return!!this._objects.includes(r)||!!i&&this._objects.some(s=>s instanceof t&&s.contains(r,!0))}complexity(){return this._objects.reduce((r,i)=>r+=i.complexity?i.complexity():0,0)}sendObjectToBack(r){return!(!r||r===this._objects[0])&&(Ee(this._objects,r),this._objects.unshift(r),this._onStackOrderChanged(r),!0)}bringObjectToFront(r){return!(!r||r===this._objects[this._objects.length-1])&&(Ee(this._objects,r),this._objects.push(r),this._onStackOrderChanged(r),!0)}sendObjectBackwards(r,i){if(!r)return!1;const s=this._objects.indexOf(r);if(s!==0){const o=this.findNewLowerIndex(r,s,i);return Ee(this._objects,r),this._objects.splice(o,0,r),this._onStackOrderChanged(r),!0}return!1}bringObjectForward(r,i){if(!r)return!1;const s=this._objects.indexOf(r);if(s!==this._objects.length-1){const o=this.findNewUpperIndex(r,s,i);return Ee(this._objects,r),this._objects.splice(o,0,r),this._onStackOrderChanged(r),!0}return!1}moveObjectTo(r,i){return r!==this._objects[i]&&(Ee(this._objects,r),this._objects.splice(i,0,r),this._onStackOrderChanged(r),!0)}findNewLowerIndex(r,i,s){let o;if(s){o=i;for(let a=i-1;a>=0;--a)if(r.isOverlapping(this._objects[a])){o=a;break}}else o=i-1;return o}findNewUpperIndex(r,i,s){let o;if(s){o=i;for(let a=i+1;a<this._objects.length;++a)if(r.isOverlapping(this._objects[a])){o=a;break}}else o=i+1;return o}collectObjects(r){let{left:i,top:s,width:o,height:a}=r,{includeIntersecting:l=!0}=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};const c=[],h=new x(i,s),u=h.add(new x(o,a));for(let d=this._objects.length-1;d>=0;d--){const g=this._objects[d];g.selectable&&g.visible&&(l&&g.intersectsWithRect(h,u)||g.isContainedWithinRect(h,u)||l&&g.containsPoint(h)||l&&g.containsPoint(u))&&c.push(g)}return c}}return t}class Mn extends Fl{_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 Pr(n){return wr().requestAnimationFrame(n)}function Rl(n){return wr().cancelAnimationFrame(n)}let Bl=0;const ue=()=>Bl++,Qt=()=>{const n=ke().createElement("canvas");if(!n||n.getContext===void 0)throw new Ut("Failed to create `canvas` element");return n},Il=()=>ke().createElement("img"),At=n=>{const t=Qt();return t.width=n.width,t.height=n.height,t},En=(n,t,e)=>n.toDataURL("image/".concat(t),e),Pn=(n,t,e)=>new Promise((r,i)=>{n.toBlob(r,"image/".concat(t),e)}),st=n=>n*Vi,te=n=>n/Vi,Hl=n=>n.every((t,e)=>t===gt[e]),xt=(n,t,e)=>new x(n).transform(t,e),Rt=n=>{const t=1/(n[0]*n[3]-n[1]*n[2]),e=[t*n[3],-t*n[1],-t*n[2],t*n[0],0,0],{x:r,y:i}=new x(n[4],n[5]).transform(e,!0);return e[4]=-r,e[5]=-i,e},ht=(n,t,e)=>[n[0]*t[0]+n[2]*t[1],n[1]*t[0]+n[3]*t[1],n[0]*t[2]+n[2]*t[3],n[1]*t[2]+n[3]*t[3],e?0:n[0]*t[4]+n[2]*t[5]+n[4],e?0:n[1]*t[4]+n[3]*t[5]+n[5]],qi=(n,t)=>n.reduceRight((e,r)=>r&&e?ht(r,e,t):r||e,void 0)||gt.concat(),An=n=>{let[t,e]=n;return Math.atan2(e,t)},Ar=n=>{const t=An(n),e=Math.pow(n[0],2)+Math.pow(n[1],2),r=Math.sqrt(e),i=(n[0]*n[3]-n[2]*n[1])/r,s=Math.atan2(n[0]*n[2]+n[1]*n[3],e);return{angle:te(t),scaleX:r,scaleY:i,skewX:te(s),skewY:0,translateX:n[4]||0,translateY:n[5]||0}},ir=function(n){return[1,0,0,1,n,arguments.length>1&&arguments[1]!==void 0?arguments[1]:0]};function Pe(){let{angle:n=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 r=st(n),i=Zt(r),s=Jt(r);return[i,s,-s,i,t?t-(i*t-s*e):0,e?e-(s*t+i*e):0]}const Ki=function(n){return[n,0,0,arguments.length>1&&arguments[1]!==void 0?arguments[1]:n,0,0]},jn=n=>Math.tan(st(n)),Ln=n=>[1,0,jn(n),1,0,0],Fn=n=>[1,jn(n),0,1,0,0],jr=n=>{let{scaleX:t=1,scaleY:e=1,flipX:r=!1,flipY:i=!1,skewX:s=0,skewY:o=0}=n,a=Ki(r?-t:t,i?-e:e);return s&&(a=ht(a,Ln(s),!0)),o&&(a=ht(a,Fn(o),!0)),a},zl=n=>{const{translateX:t=0,translateY:e=0,angle:r=0}=n;let i=ir(t,e);r&&(i=ht(i,Pe({angle:r})));const s=jr(n);return Hl(s)||(i=ht(i,s)),i},Lr=function(n){let{signal:t,crossOrigin:e=null}=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};return new Promise(function(r,i){if(t&&t.aborted)return i(new Ml("loadImage"));const s=Il();let o;t&&(o=function(l){s.src="",i(l)},t.addEventListener("abort",o,{once:!0}));const a=function(){s.onload=s.onerror=null,o&&(t==null||t.removeEventListener("abort",o)),r(s)};n?(s.onload=a,s.onerror=function(){o&&(t==null||t.removeEventListener("abort",o)),i(new Ut("Error loading ".concat(s.src)))},e&&(s.crossOrigin=e),s.src=n):a()})},sr=function(n){let{signal:t,reviver:e=Cr}=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};return new Promise((r,i)=>{const s=[];t&&t.addEventListener("abort",i,{once:!0}),Promise.all(n.map(o=>E.getClass(o.type).fromObject(o,{signal:t}).then(a=>(e(o,a),s.push(a),a)))).then(r).catch(o=>{s.forEach(a=>{a.dispose&&a.dispose()}),i(o)}).finally(()=>{t&&t.removeEventListener("abort",i)})})},Fr=function(n){let{signal:t}=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};return new Promise((e,r)=>{const i=[];t&&t.addEventListener("abort",r,{once:!0});const s=Object.values(n).map(a=>a&&a.type&&E.has(a.type)?sr([a],{signal:t}).then(l=>{let[c]=l;return i.push(c),c}):a),o=Object.keys(n);Promise.all(s).then(a=>a.reduce((l,c,h)=>(l[o[h]]=c,l),{})).then(e).catch(a=>{i.forEach(l=>{l.dispose&&l.dispose()}),r(a)}).finally(()=>{t&&t.removeEventListener("abort",r)})})},Ae=function(n){return(arguments.length>1&&arguments[1]!==void 0?arguments[1]:[]).reduce((t,e)=>(e in n&&(t[e]=n[e]),t),{})},Zi=(n,t)=>Object.keys(n).reduce((e,r)=>(t(n[r],r,n)&&(e[r]=n[r]),e),{}),Z=(n,t)=>parseFloat(Number(n).toFixed(t)),nr=n=>"matrix("+n.map(t=>Z(t,X.NUM_FRACTION_DIGITS)).join(" ")+")",jt=n=>!!n&&n.toLive!==void 0,Rn=n=>!!n&&typeof n.toObject=="function",Bn=n=>!!n&&n.offsetX!==void 0&&"source"in n,ve=n=>!!n&&"multiSelectionStacking"in n;function In(n){const t=n&&Bt(n);let e=0,r=0;if(!n||!t)return{left:e,top:r};let i=n;const s=t.documentElement,o=t.body||{scrollLeft:0,scrollTop:0};for(;i&&(i.parentNode||i.host)&&(i=i.parentNode||i.host,i===t?(e=o.scrollLeft||s.scrollLeft||0,r=o.scrollTop||s.scrollTop||0):(e+=i.scrollLeft||0,r+=i.scrollTop||0),i.nodeType!==1||i.style.position!=="fixed"););return{left:e,top:r}}const Bt=n=>n.ownerDocument||null,Hn=n=>{var t;return((t=n.ownerDocument)===null||t===void 0?void 0:t.defaultView)||null},zn=function(n,t,e){let{width:r,height:i}=e,s=arguments.length>3&&arguments[3]!==void 0?arguments[3]:1;n.width=r,n.height=i,s>1&&(n.setAttribute("width",(r*s).toString()),n.setAttribute("height",(i*s).toString()),t.scale(s,s))},Ji=(n,t)=>{let{width:e,height:r}=t;e&&(n.style.width=typeof e=="number"?"".concat(e,"px"):e),r&&(n.style.height=typeof r=="number"?"".concat(r,"px"):r)};function Wn(n){return n.onselectstart!==void 0&&(n.onselectstart=()=>!1),n.style.userSelect=bt,n}class Vn{constructor(t){p(this,"_originalCanvasStyle",void 0),p(this,"lower",void 0);const e=this.createLowerCanvas(t);this.lower={el:e,ctx:e.getContext("2d")}}createLowerCanvas(t){const e=(r=t)&&r.getContext!==void 0?t:t&&ke().getElementById(t)||Qt();var r;if(e.hasAttribute("data-fabric"))throw new Ut("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:r}=t;const{el:i}=this.lower;i.classList.remove("lower-canvas"),i.removeAttribute("data-fabric"),i.setAttribute("width","".concat(e)),i.setAttribute("height","".concat(r)),i.style.cssText=this._originalCanvasStyle||"",this._originalCanvasStyle=void 0}setDimensions(t,e){const{el:r,ctx:i}=this.lower;zn(r,i,t,e)}setCSSDimensions(t){Ji(this.lower.el,t)}calcOffset(){return function(t){var e;const r=t&&Bt(t),i={left:0,top:0};if(!r)return i;const s=((e=Hn(t))===null||e===void 0?void 0:e.getComputedStyle(t,null))||{};i.left+=parseInt(s.borderLeftWidth,10)||0,i.top+=parseInt(s.borderTopWidth,10)||0,i.left+=parseInt(s.paddingLeft,10)||0,i.top+=parseInt(s.paddingTop,10)||0;let o={left:0,top:0};const a=r.documentElement;t.getBoundingClientRect!==void 0&&(o=t.getBoundingClientRect());const l=In(t);return{left:o.left+l.left-(a.clientLeft||0)+i.left,top:o.top+l.top-(a.clientTop||0)+i.top}}(this.lower.el)}dispose(){Gt().dispose(this.lower.el),delete this.lower}}const Wl={backgroundVpt:!0,backgroundColor:"",overlayVpt:!0,overlayColor:"",includeDefaultValues:!0,svgViewportTransformation:!0,renderOnAddRemove:!0,skipOffscreen:!0,enableRetinaScaling:!0,imageSmoothingEnabled:!0,controlsAboveOverlay:!1,allowTouchScrolling:!1,viewportTransform:[...gt]},Vl=["objects"];class or extends Dn(Mn){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 or.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 Vn(t)}add(){const t=super.add(...arguments);return arguments.length>0&&this.renderOnAddRemove&&this.requestRenderAll(),t}insertAt(t){for(var e=arguments.length,r=new Array(e>1?e-1:0),i=1;i<e;i++)r[i-1]=arguments[i];const s=super.insertAt(t,...r);return r.length>0&&this.renderOnAddRemove&&this.requestRenderAll(),s}remove(){const t=super.remove(...arguments);return t.length>0&&this.renderOnAddRemove&&this.requestRenderAll(),t}_onObjectAdded(t){t.canvas&&t.canvas!==this&&(ce("warn",`Canvas is trying to add an object that belongs to a different canvas.
|
|
83
|
+
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?Sn():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:r=!1}=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};if(!e){const i=v({width:this.width,height:this.height},t);this.elements.setDimensions(i,this.getRetinaScaling()),this.hasLostContext=!0,this.width=i.width,this.height=i.height}r||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 r=t,i=[...this.viewportTransform],s=xt(t,Rt(i));i[0]=e,i[3]=e;const o=xt(s,i);i[4]+=r.x-o.x,i[5]+=r.y-o.y,this.setViewportTransform(i)}setZoom(t){this.zoomToPoint(new x(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 x(-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=Pr(()=>this.renderAndReset()))}calcViewportBoundaries(){const t=this.width,e=this.height,r=Rt(this.viewportTransform),i=xt({x:0,y:0},r),s=xt({x:t,y:e},r),o=i.min(s),a=i.max(s);return this.vptCoords={tl:o,tr:new x(a.x,o.y),bl:new x(o.x,a.y),br:a}}cancelRequestedRender(){this.nextRenderHandle&&(Rl(this.nextRenderHandle),this.nextRenderHandle=0)}drawControls(t){}renderCanvas(t,e){if(this.destroyed)return;const r=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(r[0],r[1],r[2],r[3],r[4],r[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 r=this.viewportTransform;t.save(),t.transform(...r),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 r=0,i=e.length;r<i;++r)e[r]&&e[r].render(t)}_renderBackgroundOrOverlay(t,e){const r=this["".concat(e,"Color")],i=this["".concat(e,"Image")],s=this.viewportTransform,o=this["".concat(e,"Vpt")];if(!r&&!i)return;const a=jt(r);if(r){if(t.save(),t.beginPath(),t.moveTo(0,0),t.lineTo(this.width,0),t.lineTo(this.width,this.height),t.lineTo(0,this.height),t.closePath(),t.fillStyle=a?r.toLive(t):r,o&&t.transform(...s),a){t.transform(1,0,0,1,r.offsetX||0,r.offsetY||0);const l=r.gradientTransform||r.patternTransform;l&&t.transform(...l)}t.fill(),t.restore()}if(i){t.save();const{skipOffscreen:l}=this;this.skipOffscreen=o,o&&t.transform(...s),i.render(t),this.skipOffscreen=l,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 x(this.width/2,this.height/2)}centerObjectH(t){return this._centerObject(t,new x(this.getCenterPoint().x,t.getCenterPoint().y))}centerObjectV(t){return this._centerObject(t,new x(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 x(this.getVpCenter().x,t.getCenterPoint().y))}viewportCenterObjectV(t){return this._centerObject(t,new x(t.getCenterPoint().x,this.getVpCenter().y))}getVpCenter(){return xt(this.getCenterPoint(),Rt(this.viewportTransform))}_centerObject(t,e){t.setXY(e,W,W),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 r=this.clipPath,i=r&&!r.excludeFromExport?this._toObject(r,t,e):null;return v(v(v({version:Wi},Ae(this,e)),{},{objects:this._objects.filter(s=>!s.excludeFromExport).map(s=>this._toObject(s,t,e))},this.__serializeBgOverlay(t,e)),i?{clipPath:i}:null)}_toObject(t,e,r){let i;this.includeDefaultValues||(i=t.includeDefaultValues,t.includeDefaultValues=!1);const s=t[e](r);return this.includeDefaultValues||(t.includeDefaultValues=!!i),s}__serializeBgOverlay(t,e){const r={},i=this.backgroundImage,s=this.overlayImage,o=this.backgroundColor,a=this.overlayColor;return jt(o)?o.excludeFromExport||(r.background=o.toObject(e)):o&&(r.background=o),jt(a)?a.excludeFromExport||(r.overlay=a.toObject(e)):a&&(r.overlay=a),i&&!i.excludeFromExport&&(r.backgroundImage=this._toObject(i,t,e)),s&&!s.excludeFromExport&&(r.overlayImage=this._toObject(s,t,e)),r}toSVG(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},e=arguments.length>1?arguments[1]:void 0;t.reviver=e;const r=[];return this._setSVGPreamble(r,t),this._setSVGHeader(r,t),this.clipPath&&r.push('<g clip-path="url(#'.concat(this.clipPath.clipPathId,`)" >
|
|
84
|
+
`)),this._setSVGBgOverlayColor(r,"background"),this._setSVGBgOverlayImage(r,"backgroundImage",e),this._setSVGObjects(r,e),this.clipPath&&r.push(`</g>
|
|
85
|
+
`),this._setSVGBgOverlayColor(r,"overlay"),this._setSVGBgOverlayImage(r,"overlayImage",e),r.push("</svg>"),r.join("")}_setSVGPreamble(t,e){e.suppressPreamble||t.push('<?xml version="1.0" encoding="',e.encoding||"UTF-8",`" standalone="no" ?>
|
|
86
|
+
`,'<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" ',`"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
|
|
87
|
+
`)}_setSVGHeader(t,e){const r=e.width||"".concat(this.width),i=e.height||"".concat(this.height),s=X.NUM_FRACTION_DIGITS,o=e.viewBox;let a;if(o)a='viewBox="'.concat(o.x," ").concat(o.y," ").concat(o.width," ").concat(o.height,'" ');else if(this.svgViewportTransformation){const l=this.viewportTransform;a='viewBox="'.concat(Z(-l[4]/l[0],s)," ").concat(Z(-l[5]/l[3],s)," ").concat(Z(this.width/l[0],s)," ").concat(Z(this.height/l[3],s),'" ')}else a='viewBox="0 0 '.concat(this.width," ").concat(this.height,'" ');t.push("<svg ",'xmlns="http://www.w3.org/2000/svg" ','xmlns:xlink="http://www.w3.org/1999/xlink" ','version="1.1" ','width="',r,'" ','height="',i,'" ',a,`xml:space="preserve">
|
|
88
|
+
`,"<desc>Created with Fabric.js ",Wi,`</desc>
|
|
89
|
+
`,`<defs>
|
|
90
|
+
`,this.createSVGFontFacesMarkup(),this.createSVGRefElementsMarkup(),this.createSVGClipPathMarkup(e),`</defs>
|
|
91
|
+
`)}createSVGClipPathMarkup(t){const e=this.clipPath;return e?(e.clipPathId="CLIPPATH_".concat(ue()),'<clipPath id="'.concat(e.clipPathId,`" >
|
|
92
|
+
`).concat(e.toClipPathSVG(t.reviver),`</clipPath>
|
|
93
|
+
`)):""}createSVGRefElementsMarkup(){return["background","overlay"].map(t=>{const e=this["".concat(t,"Color")];if(jt(e)){const r=this["".concat(t,"Vpt")],i=this.viewportTransform,s={isType:()=>!1,width:this.width/(r?i[0]:1),height:this.height/(r?i[3]:1)};return e.toSVG(s,{additionalTransform:r?nr(i):""})}}).join("")}createSVGFontFacesMarkup(){const t=[],e={},r=X.fontPaths;this._objects.forEach(function s(o){t.push(o),Er(o)&&o._objects.forEach(s)}),t.forEach(s=>{if(!(o=s)||typeof o._renderText!="function")return;var o;const{styles:a,fontFamily:l}=s;!e[l]&&r[l]&&(e[l]=!0,a&&Object.values(a).forEach(c=>{Object.values(c).forEach(h=>{let{fontFamily:u=""}=h;!e[u]&&r[u]&&(e[u]=!0)})}))});const i=Object.keys(e).map(s=>` @font-face {
|
|
94
|
+
font-family: '`.concat(s,`';
|
|
95
|
+
src: url('`).concat(r[s],`');
|
|
96
|
+
}
|
|
97
|
+
`)).join("");return i?` <style type="text/css"><![CDATA[
|
|
98
|
+
`.concat(i,`]]></style>
|
|
99
|
+
`):""}_setSVGObjects(t,e){this.forEachObject(r=>{r.excludeFromExport||this._setSVGObject(t,r,e)})}_setSVGObject(t,e,r){t.push(e.toSVG(r))}_setSVGBgOverlayImage(t,e,r){const i=this[e];i&&!i.excludeFromExport&&i.toSVG&&t.push(i.toSVG(r))}_setSVGBgOverlayColor(t,e){const r=this["".concat(e,"Color")];if(r)if(jt(r)){const i=r.repeat||"",s=this.width,o=this.height,a=this["".concat(e,"Vpt")]?nr(Rt(this.viewportTransform)):"";t.push('<rect transform="'.concat(a," translate(").concat(s/2,",").concat(o/2,')" x="').concat(r.offsetX-s/2,'" y="').concat(r.offsetY-o/2,'" width="').concat(i!=="repeat-y"&&i!=="no-repeat"||!Bn(r)?s:r.source.width,'" height="').concat(i!=="repeat-x"&&i!=="no-repeat"||!Bn(r)?o:r.source.height,'" fill="url(#SVGID_').concat(r.id,`)"></rect>
|
|
100
|
+
`))}else t.push('<rect x="0" y="0" width="100%" height="100%" ','fill="',r,'"',`></rect>
|
|
101
|
+
`)}loadFromJSON(t,e){let{signal:r}=arguments.length>2&&arguments[2]!==void 0?arguments[2]:{};if(!t)return Promise.reject(new Ut("`json` is undefined"));const i=typeof t=="string"?JSON.parse(t):t,{objects:s=[]}=i,o=J(i,Vl),{backgroundImage:a,background:l,overlayImage:c,overlay:h,clipPath:u}=o,d=this.renderOnAddRemove;return this.renderOnAddRemove=!1,Promise.all([sr(s,{reviver:e,signal:r}),Fr({backgroundImage:a,backgroundColor:l,overlayImage:c,overlayColor:h,clipPath:u},{signal:r})]).then(g=>{let[f,m]=g;return this.clear(),this.add(...f),this.set(o),this.set(m),this.renderOnAddRemove=d,this})}clone(t){const e=this.toObject(t);return this.cloneWithoutData().loadFromJSON(e)}cloneWithoutData(){const t=At(this);return new this.constructor(t)}toDataURL(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};const{format:e="png",quality:r=1,multiplier:i=1,enableRetinaScaling:s=!1}=t,o=i*(s?this.getRetinaScaling():1);return En(this.toCanvasElement(o,t),e,r)}toBlob(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};const{format:e="png",quality:r=1,multiplier:i=1,enableRetinaScaling:s=!1}=t,o=i*(s?this.getRetinaScaling():1);return Pn(this.toCanvasElement(o,t),e,r)}toCanvasElement(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:1,{width:e,height:r,left:i,top:s,filter:o}=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};const a=(e||this.width)*t,l=(r||this.height)*t,c=this.getZoom(),h=this.width,u=this.height,d=this.skipControlsDrawing,g=c*t,f=this.viewportTransform,m=[g,0,0,g,(f[4]-(i||0))*t,(f[5]-(s||0))*t],b=this.enableRetinaScaling,y=At({width:a,height:l}),w=o?this._objects.filter(O=>o(O)):this._objects;return this.enableRetinaScaling=!1,this.viewportTransform=m,this.width=a,this.height=l,this.skipControlsDrawing=!0,this.calcViewportBoundaries(),this.renderCanvas(y.getContext("2d"),w),this.viewportTransform=f,this.width=h,this.height=u,this.calcViewportBoundaries(),this.enableRetinaScaling=b,this.skipControlsDrawing=d,y}dispose(){return!this.disposed&&this.elements.cleanupDOM({width:this.width,height:this.height}),Mr.cancelByCanvas(this),this.disposed=!0,new Promise((t,e)=>{const r=()=>{this.destroy(),t(!0)};r.kill=e,this.__cleanupTask&&this.__cleanupTask.kill("aborted"),this.destroyed?t(!1):this.nextRenderHandle?this.__cleanupTask=r:r()})}destroy(){this.destroyed=!0,this.cancelRequestedRender(),this.forEachObject(t=>t.dispose()),this._objects=[],this.backgroundImage&&this.backgroundImage.dispose(),this.backgroundImage=void 0,this.overlayImage&&this.overlayImage.dispose(),this.overlayImage=void 0,this.elements.dispose()}toString(){return"#<Canvas (".concat(this.complexity(),"): { objects: ").concat(this._objects.length," }>")}}p(or,"ownDefaults",Wl);const Xl=["touchstart","touchmove","touchend"],Yl=n=>{const t=In(n.target),e=function(r){const i=r.changedTouches;return i&&i[0]?i[0]:r}(n);return new x(e.clientX+t.left,e.clientY+t.top)},Qi=n=>Xl.includes(n.type)||n.pointerType==="touch",Xn=n=>{n.preventDefault(),n.stopPropagation()},ee=n=>{let t=0,e=0,r=0,i=0;for(let s=0,o=n.length;s<o;s++){const{x:a,y:l}=n[s];(a>r||!s)&&(r=a),(a<t||!s)&&(t=a),(l>i||!s)&&(i=l),(l<e||!s)&&(e=l)}return{left:t,top:e,width:r-t,height:i-e}},Ul=["translateX","translateY","scaleX","scaleY"],Gl=(n,t)=>Rr(n,ht(t,n.calcOwnMatrix())),Rr=(n,t)=>{const e=Ar(t),{translateX:r,translateY:i,scaleX:s,scaleY:o}=e,a=J(e,Ul),l=new x(r,i);n.flipX=!1,n.flipY=!1,Object.assign(n,a),n.set({scaleX:s,scaleY:o}),n.setPositionByOrigin(l,W,W)},Nl=n=>{n.scaleX=1,n.scaleY=1,n.skewX=0,n.skewY=0,n.flipX=!1,n.flipY=!1,n.rotate(0)},Yn=n=>({scaleX:n.scaleX,scaleY:n.scaleY,skewX:n.skewX,skewY:n.skewY,angle:n.angle,left:n.left,flipX:n.flipX,flipY:n.flipY,top:n.top}),ts=(n,t,e)=>{const r=n/2,i=t/2,s=[new x(-r,-i),new x(r,-i),new x(-r,i),new x(r,i)].map(a=>a.transform(e)),o=ee(s);return new x(o.width,o.height)},Br=function(){let n=arguments.length>0&&arguments[0]!==void 0?arguments[0]:gt;return ht(Rt(arguments.length>1&&arguments[1]!==void 0?arguments[1]:gt),n)},je=function(n){let t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:gt,e=arguments.length>2&&arguments[2]!==void 0?arguments[2]:gt;return n.transform(Br(t,e))},$l=function(n){let t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:gt,e=arguments.length>2&&arguments[2]!==void 0?arguments[2]:gt;return n.transform(Br(t,e),!0)},ql=(n,t,e)=>{const r=Br(t,e);return Rr(n,ht(r,n.calcOwnMatrix())),r},Un=(n,t)=>{var e;const{transform:{target:r}}=t;(e=r.canvas)===null||e===void 0||e.fire("object:".concat(n),v(v({},t),{},{target:r})),r.fire(n,t)},Kl={left:-.5,top:-.5,center:0,bottom:.5,right:.5},ot=n=>typeof n=="string"?Kl[n]:n-.5,Ir="not-allowed";function Gn(n){return ot(n.originX)===ot(W)&&ot(n.originY)===ot(W)}function Nn(n){return .5-ot(n)}const It=(n,t)=>n[t],$n=(n,t,e,r)=>({e:n,transform:t,pointer:new x(e,r)});function qn(n,t){const e=n.getTotalAngle()+te(Math.atan2(t.y,t.x))+360;return Math.round(e%360/45)}function es(n,t,e,r,i){var s;let{target:o,corner:a}=n;const l=o.controls[a],c=((s=o.canvas)===null||s===void 0?void 0:s.getZoom())||1,h=o.padding/c,u=function(d,g,f,m){const b=d.getRelativeCenterPoint(),y=f!==void 0&&m!==void 0?d.translateToGivenOrigin(b,W,W,f,m):new x(d.left,d.top);return(d.angle?g.rotate(-st(d.angle),b):g).subtract(y)}(o,new x(r,i),t,e);return u.x>=h&&(u.x-=h),u.x<=-h&&(u.x+=h),u.y>=h&&(u.y-=h),u.y<=h&&(u.y+=h),u.x-=l.offsetX,u.y-=l.offsetY,u}const Zl=(n,t,e,r)=>{const{target:i,offsetX:s,offsetY:o}=t,a=e-s,l=r-o,c=!It(i,"lockMovementX")&&i.left!==a,h=!It(i,"lockMovementY")&&i.top!==l;return c&&i.set(U,a),h&&i.set(vt,l),(c||h)&&Un(Tn,$n(n,t,e,r)),c||h},Hr=n=>n.replace(/\s+/g," "),Kn={aliceblue:"#F0F8FF",antiquewhite:"#FAEBD7",aqua:"#0FF",aquamarine:"#7FFFD4",azure:"#F0FFFF",beige:"#F5F5DC",bisque:"#FFE4C4",black:"#000",blanchedalmond:"#FFEBCD",blue:"#00F",blueviolet:"#8A2BE2",brown:"#A52A2A",burlywood:"#DEB887",cadetblue:"#5F9EA0",chartreuse:"#7FFF00",chocolate:"#D2691E",coral:"#FF7F50",cornflowerblue:"#6495ED",cornsilk:"#FFF8DC",crimson:"#DC143C",cyan:"#0FF",darkblue:"#00008B",darkcyan:"#008B8B",darkgoldenrod:"#B8860B",darkgray:"#A9A9A9",darkgrey:"#A9A9A9",darkgreen:"#006400",darkkhaki:"#BDB76B",darkmagenta:"#8B008B",darkolivegreen:"#556B2F",darkorange:"#FF8C00",darkorchid:"#9932CC",darkred:"#8B0000",darksalmon:"#E9967A",darkseagreen:"#8FBC8F",darkslateblue:"#483D8B",darkslategray:"#2F4F4F",darkslategrey:"#2F4F4F",darkturquoise:"#00CED1",darkviolet:"#9400D3",deeppink:"#FF1493",deepskyblue:"#00BFFF",dimgray:"#696969",dimgrey:"#696969",dodgerblue:"#1E90FF",firebrick:"#B22222",floralwhite:"#FFFAF0",forestgreen:"#228B22",fuchsia:"#F0F",gainsboro:"#DCDCDC",ghostwhite:"#F8F8FF",gold:"#FFD700",goldenrod:"#DAA520",gray:"#808080",grey:"#808080",green:"#008000",greenyellow:"#ADFF2F",honeydew:"#F0FFF0",hotpink:"#FF69B4",indianred:"#CD5C5C",indigo:"#4B0082",ivory:"#FFFFF0",khaki:"#F0E68C",lavender:"#E6E6FA",lavenderblush:"#FFF0F5",lawngreen:"#7CFC00",lemonchiffon:"#FFFACD",lightblue:"#ADD8E6",lightcoral:"#F08080",lightcyan:"#E0FFFF",lightgoldenrodyellow:"#FAFAD2",lightgray:"#D3D3D3",lightgrey:"#D3D3D3",lightgreen:"#90EE90",lightpink:"#FFB6C1",lightsalmon:"#FFA07A",lightseagreen:"#20B2AA",lightskyblue:"#87CEFA",lightslategray:"#789",lightslategrey:"#789",lightsteelblue:"#B0C4DE",lightyellow:"#FFFFE0",lime:"#0F0",limegreen:"#32CD32",linen:"#FAF0E6",magenta:"#F0F",maroon:"#800000",mediumaquamarine:"#66CDAA",mediumblue:"#0000CD",mediumorchid:"#BA55D3",mediumpurple:"#9370DB",mediumseagreen:"#3CB371",mediumslateblue:"#7B68EE",mediumspringgreen:"#00FA9A",mediumturquoise:"#48D1CC",mediumvioletred:"#C71585",midnightblue:"#191970",mintcream:"#F5FFFA",mistyrose:"#FFE4E1",moccasin:"#FFE4B5",navajowhite:"#FFDEAD",navy:"#000080",oldlace:"#FDF5E6",olive:"#808000",olivedrab:"#6B8E23",orange:"#FFA500",orangered:"#FF4500",orchid:"#DA70D6",palegoldenrod:"#EEE8AA",palegreen:"#98FB98",paleturquoise:"#AFEEEE",palevioletred:"#DB7093",papayawhip:"#FFEFD5",peachpuff:"#FFDAB9",peru:"#CD853F",pink:"#FFC0CB",plum:"#DDA0DD",powderblue:"#B0E0E6",purple:"#800080",rebeccapurple:"#639",red:"#F00",rosybrown:"#BC8F8F",royalblue:"#4169E1",saddlebrown:"#8B4513",salmon:"#FA8072",sandybrown:"#F4A460",seagreen:"#2E8B57",seashell:"#FFF5EE",sienna:"#A0522D",silver:"#C0C0C0",skyblue:"#87CEEB",slateblue:"#6A5ACD",slategray:"#708090",slategrey:"#708090",snow:"#FFFAFA",springgreen:"#00FF7F",steelblue:"#4682B4",tan:"#D2B48C",teal:"#008080",thistle:"#D8BFD8",tomato:"#FF6347",turquoise:"#40E0D0",violet:"#EE82EE",wheat:"#F5DEB3",white:"#FFF",whitesmoke:"#F5F5F5",yellow:"#FF0",yellowgreen:"#9ACD32"},rs=(n,t,e)=>(e<0&&(e+=1),e>1&&(e-=1),e<1/6?n+6*(t-n)*e:e<.5?t:e<2/3?n+(t-n)*(2/3-e)*6:n),Zn=(n,t,e,r)=>{n/=255,t/=255,e/=255;const i=Math.max(n,t,e),s=Math.min(n,t,e);let o,a;const l=(i+s)/2;if(i===s)o=a=0;else{const c=i-s;switch(a=l>.5?c/(2-i-s):c/(i+s),i){case n:o=(t-e)/c+(t<e?6:0);break;case t:o=(e-n)/c+2;break;case e:o=(n-t)/c+4}o/=6}return[Math.round(360*o),Math.round(100*a),Math.round(100*l),r]},Jn=function(){let n=arguments.length>0&&arguments[0]!==void 0?arguments[0]:"1";return parseFloat(n)/(n.endsWith("%")?100:1)},zr=n=>Math.min(Math.round(n),255).toString(16).toUpperCase().padStart(2,"0"),Qn=n=>{let[t,e,r,i=1]=n;const s=Math.round(.3*t+.59*e+.11*r);return[s,s,s,i]};class G{constructor(t){if(p(this,"isUnrecognised",!1),t)if(t instanceof G)this.setSource([...t._source]);else if(Array.isArray(t)){const[e,r,i,s=1]=t;this.setSource([e,r,i,s])}else this.setSource(this._tryParsingColor(t));else this.setSource([0,0,0,1])}_tryParsingColor(t){return(t=t.toLowerCase())in Kn&&(t=Kn[t]),t==="transparent"?[255,255,255,0]:G.sourceFromHex(t)||G.sourceFromRgb(t)||G.sourceFromHsl(t)||(this.isUnrecognised=!0)&&[0,0,0,1]}getSource(){return this._source}setSource(t){this._source=t}toRgb(){const[t,e,r]=this.getSource();return"rgb(".concat(t,",").concat(e,",").concat(r,")")}toRgba(){return"rgba(".concat(this.getSource().join(","),")")}toHsl(){const[t,e,r]=Zn(...this.getSource());return"hsl(".concat(t,",").concat(e,"%,").concat(r,"%)")}toHsla(){const[t,e,r,i]=Zn(...this.getSource());return"hsla(".concat(t,",").concat(e,"%,").concat(r,"%,").concat(i,")")}toHex(){return this.toHexa().slice(0,6)}toHexa(){const[t,e,r,i]=this.getSource();return"".concat(zr(t)).concat(zr(e)).concat(zr(r)).concat(zr(Math.round(255*i)))}getAlpha(){return this.getSource()[3]}setAlpha(t){return this._source[3]=t,this}toGrayscale(){return this.setSource(Qn(this.getSource())),this}toBlackWhite(t){const[e,,,r]=Qn(this.getSource()),i=e<(t||127)?0:255;return this.setSource([i,i,i,r]),this}overlayWith(t){t instanceof G||(t=new G(t));const e=this.getSource(),r=t.getSource(),[i,s,o]=e.map((a,l)=>Math.round(.5*a+.5*r[l]));return this.setSource([i,s,o,e[3]]),this}static fromRgb(t){return G.fromRgba(t)}static fromRgba(t){return new G(G.sourceFromRgb(t))}static sourceFromRgb(t){const e=Hr(t).match(/^rgba?\(\s?(\d{0,3}(?:\.\d+)?%?)\s?[\s|,]\s?(\d{0,3}(?:\.\d+)?%?)\s?[\s|,]\s?(\d{0,3}(?:\.\d+)?%?)\s?(?:\s?[,/]\s?(\d{0,3}(?:\.\d+)?%?)\s?)?\)$/i);if(e){const[r,i,s]=e.slice(1,4).map(o=>{const a=parseFloat(o);return o.endsWith("%")?Math.round(2.55*a):a});return[r,i,s,Jn(e[4])]}}static fromHsl(t){return G.fromHsla(t)}static fromHsla(t){return new G(G.sourceFromHsl(t))}static sourceFromHsl(t){const e=Hr(t).match(/^hsla?\(\s?([+-]?\d{0,3}(?:\.\d+)?(?:deg|turn|rad)?)\s?[\s|,]\s?(\d{0,3}(?:\.\d+)?%?)\s?[\s|,]\s?(\d{0,3}(?:\.\d+)?%?)\s?(?:\s?[,/]\s?(\d*(?:\.\d+)?%?)\s?)?\)$/i);if(!e)return;const r=(G.parseAngletoDegrees(e[1])%360+360)%360/360,i=parseFloat(e[2])/100,s=parseFloat(e[3])/100;let o,a,l;if(i===0)o=a=l=s;else{const c=s<=.5?s*(i+1):s+i-s*i,h=2*s-c;o=rs(h,c,r+.3333333333333333),a=rs(h,c,r),l=rs(h,c,r-.3333333333333333)}return[Math.round(255*o),Math.round(255*a),Math.round(255*l),Jn(e[4])]}static fromHex(t){return new G(G.sourceFromHex(t))}static sourceFromHex(t){if(t.match(/^#?(([0-9a-f]){3,4}|([0-9a-f]{2}){3,4})$/i)){const e=t.slice(t.indexOf("#")+1);let r;r=e.length<=4?e.split("").map(l=>l+l):e.match(/.{2}/g);const[i,s,o,a=255]=r.map(l=>parseInt(l,16));return[i,s,o,a/255]}}static parseAngletoDegrees(t){const e=t.toLowerCase(),r=parseFloat(e);return e.includes("rad")?te(r):e.includes("turn")?360*r:r}}const Le=function(n){let t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:Xi;const e=/\D{0,2}$/.exec(n),r=parseFloat(n),i=X.DPI;switch(e==null?void 0:e[0]){case"mm":return r*i/25.4;case"cm":return r*i/2.54;case"in":return r*i;case"pt":return r*i/72;case"pc":return r*i/72*12;case"em":return r*t;default:return r}},Jl=n=>{const[t,e]=n.trim().split(" "),[r,i]=(s=t)&&s!==bt?[s.slice(1,4),s.slice(5,8)]:s===bt?[s,s]:["Mid","Mid"];var s;return{meetOrSlice:e||"meet",alignX:r,alignY:i}},ar=function(n,t){let e,r,i=!(arguments.length>2&&arguments[2]!==void 0)||arguments[2];if(t)if(t.toLive)e="url(#SVGID_".concat(t.id,")");else{const s=new G(t),o=s.getAlpha();e=s.toRgb(),o!==1&&(r=o.toString())}else e="none";return i?"".concat(n,": ").concat(e,"; ").concat(r?"".concat(n,"-opacity: ").concat(r,"; "):""):"".concat(n,'="').concat(e,'" ').concat(r?"".concat(n,'-opacity="').concat(r,'" '):"")};class to{getSvgStyles(t){const e=this.fillRule?this.fillRule:"nonzero",r=this.strokeWidth?this.strokeWidth:"0",i=this.strokeDashArray?this.strokeDashArray.join(" "):bt,s=this.strokeDashOffset?this.strokeDashOffset:"0",o=this.strokeLineCap?this.strokeLineCap:"butt",a=this.strokeLineJoin?this.strokeLineJoin:"miter",l=this.strokeMiterLimit?this.strokeMiterLimit:"4",c=this.opacity!==void 0?this.opacity:"1",h=this.visible?"":" visibility: hidden;",u=t?"":this.getSvgFilter(),d=ar(at,this.fill);return[ar(_t,this.stroke),"stroke-width: ",r,"; ","stroke-dasharray: ",i,"; ","stroke-linecap: ",o,"; ","stroke-dashoffset: ",s,"; ","stroke-linejoin: ",a,"; ","stroke-miterlimit: ",l,"; ",d,"fill-rule: ",e,"; ","opacity: ",c,";",u,h].join("")}getSvgFilter(){return this.shadow?"filter: url(#SVGID_".concat(this.shadow.id,");"):""}getSvgCommons(){return[this.id?'id="'.concat(this.id,'" '):"",this.clipPath?'clip-path="url(#'.concat(this.clipPath.clipPathId,')" '):""].join("")}getSvgTransform(t){let e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:"";const r=t?this.calcTransformMatrix():this.calcOwnMatrix(),i='transform="'.concat(nr(r));return"".concat(i).concat(e,'" ')}_toSVG(t){return[""]}toSVG(t){return this._createBaseSVGMarkup(this._toSVG(t),{reviver:t})}toClipPathSVG(t){return" "+this._createBaseClipPathSVGMarkup(this._toSVG(t),{reviver:t})}_createBaseClipPathSVGMarkup(t){let{reviver:e,additionalTransform:r=""}=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};const i=[this.getSvgTransform(!0,r),this.getSvgCommons()].join(""),s=t.indexOf("COMMON_PARTS");return t[s]=i,e?e(t.join("")):t.join("")}_createBaseSVGMarkup(t){let{noStyle:e,reviver:r,withShadow:i,additionalTransform:s}=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};const o=e?"":'style="'.concat(this.getSvgStyles(),'" '),a=i?'style="'.concat(this.getSvgFilter(),'" '):"",l=this.clipPath,c=this.strokeUniform?'vector-effect="non-scaling-stroke" ':"",h=l&&l.absolutePositioned,u=this.stroke,d=this.fill,g=this.shadow,f=[],m=t.indexOf("COMMON_PARTS");let b;l&&(l.clipPathId="CLIPPATH_".concat(ue()),b='<clipPath id="'.concat(l.clipPathId,`" >
|
|
102
|
+
`).concat(l.toClipPathSVG(r),`</clipPath>
|
|
103
|
+
`)),h&&f.push("<g ",a,this.getSvgCommons(),` >
|
|
104
|
+
`),f.push("<g ",this.getSvgTransform(!1),h?"":a+this.getSvgCommons(),` >
|
|
105
|
+
`);const y=[o,c,e?"":this.addPaintOrder()," ",s?'transform="'.concat(s,'" '):""].join("");return t[m]=y,jt(d)&&f.push(d.toSVG(this)),jt(u)&&f.push(u.toSVG(this)),g&&f.push(g.toSVG(this)),l&&f.push(b),f.push(t.join("")),f.push(`</g>
|
|
106
|
+
`),h&&f.push(`</g>
|
|
107
|
+
`),r?r(f.join("")):f.join("")}addPaintOrder(){return this.paintFirst!==at?' paint-order="'.concat(this.paintFirst,'" '):""}}function Wr(n){return new RegExp("^("+n.join("|")+")\\b","i")}const be="textDecorationThickness",eo=["fontSize","fontWeight","fontFamily","fontStyle"],ro=["underline","overline","linethrough"],io=[...eo,"lineHeight","text","charSpacing","textAlign","styles","path","pathStartOffset","pathSide","pathAlign"],so=[...io,...ro,"textBackgroundColor","direction",be],Ql=[...eo,...ro,_t,"strokeWidth",at,"deltaY","textBackgroundColor",be],tc={_reNewline:Ui,_reSpacesAndTabs:/[ \t\r]/g,_reSpaceAndTab:/[ \t\r]/,_reWords:/\S+/g,fontSize:40,fontWeight:"normal",fontFamily:"Times New Roman",underline:!1,overline:!1,linethrough:!1,textAlign:U,fontStyle:"normal",lineHeight:1.16,textBackgroundColor:"",stroke:null,shadow:null,path:void 0,pathStartOffset:0,pathSide:U,pathAlign:"baseline",charSpacing:0,deltaY:0,direction:"ltr",CACHE_FONT_SIZE:400,MIN_TEXT_WIDTH:2,superscript:{size:.6,baseline:-.35},subscript:{size:.6,baseline:.11},_fontSizeFraction:.222,offsets:{underline:.1,linethrough:-.28167,overline:-.81333},_fontSizeMult:1.13,[be]:66.667},Nt="justify",Vr="justify-left",lr="justify-right",cr="justify-center";var no,oo,ao;const Ht=String.raw(no||(no=Yt(["[-+]?(?:d*.d+|d+.?)(?:[eE][-+]?d+)?"],["[-+]?(?:\\d*\\.\\d+|\\d+\\.?)(?:[eE][-+]?\\d+)?"]))),is=String.raw(oo||(oo=Yt(["(?:s*,?s+|s*,s*)"],["(?:\\s*,?\\s+|\\s*,\\s*)"]))),ec=new RegExp("(normal|italic)?\\s*(normal|small-caps)?\\s*(normal|bold|bolder|lighter|100|200|300|400|500|600|700|800|900)?\\s*("+Ht+"(?:px|cm|mm|em|pt|pc|in)*)(?:\\/(normal|"+Ht+"))?\\s+(.*)"),rc={cx:U,x:U,r:"radius",cy:vt,y:vt,display:"visible",visibility:"visible",transform:"transformMatrix","fill-opacity":"fillOpacity","fill-rule":"fillRule","font-family":"fontFamily","font-size":"fontSize","font-style":"fontStyle","font-weight":"fontWeight","letter-spacing":"charSpacing","paint-order":"paintFirst","stroke-dasharray":"strokeDashArray","stroke-dashoffset":"strokeDashOffset","stroke-linecap":"strokeLineCap","stroke-linejoin":"strokeLineJoin","stroke-miterlimit":"strokeMiterLimit","stroke-opacity":"strokeOpacity","stroke-width":"strokeWidth","text-decoration":"textDecoration","text-anchor":"textAnchor",opacity:"opacity","clip-path":"clipPath","clip-rule":"clipRule","vector-effect":"strokeUniform","image-rendering":"imageSmoothing","text-decoration-thickness":be},ss="font-size",ns="clip-path";Wr(["path","circle","polygon","polyline","ellipse","rect","line","image","text"]),Wr(["symbol","image","marker","pattern","view","svg"]);const lo=Wr(["symbol","g","a","svg","clipPath","defs"]);new RegExp(String.raw(ao||(ao=Yt(["^s*(",")","(",")","(",")","(",")s*$"],["^\\s*(",")","(",")","(",")","(",")\\s*$"])),Ht,is,Ht,is,Ht,is,Ht));const ic=new x(1,0),co=new x,ho=(n,t)=>n.rotate(t),os=(n,t)=>new x(t).subtract(n),as=n=>n.distanceFrom(co),ls=(n,t)=>Math.atan2(hr(n,t),nc(n,t)),sc=n=>ls(ic,n),cs=n=>n.eq(co)?n:n.scalarDivide(as(n)),uo=function(n){let t=!(arguments.length>1&&arguments[1]!==void 0)||arguments[1];return cs(new x(-n.y,n.x).scalarMultiply(t?1:-1))},hr=(n,t)=>n.x*t.y-n.y*t.x,nc=(n,t)=>n.x*t.x+n.y*t.y,go=(n,t,e)=>{if(n.eq(t)||n.eq(e))return!0;const r=hr(t,e),i=hr(t,n),s=hr(e,n);return r>=0?i>=0&&s<=0:!(i<=0&&s>=0)},fo="(-?\\d+(?:\\.\\d*)?(?:px)?(?:\\s?|$))?",po=new RegExp("(?:\\s|^)"+fo+fo+"("+Ht+"?(?:px)?)?(?:\\s?|$)(?:$|\\s)");class $t{constructor(t){const e=typeof t=="string"?$t.parseShadow(t):t;Object.assign(this,$t.ownDefaults,e),this.id=ue()}static parseShadow(t){const e=t.trim(),[,r=0,i=0,s=0]=(po.exec(e)||[]).map(o=>parseFloat(o)||0);return{color:(e.replace(po,"")||"rgb(0,0,0)").trim(),offsetX:r,offsetY:i,blur:s}}toString(){return[this.offsetX,this.offsetY,this.blur,this.color].join("px ")}toSVG(t){const e=ho(new x(this.offsetX,this.offsetY),st(-t.angle)),r=new G(this.color);let i=40,s=40;return t.width&&t.height&&(i=100*Z((Math.abs(e.x)+this.blur)/t.width,X.NUM_FRACTION_DIGITS)+20,s=100*Z((Math.abs(e.y)+this.blur)/t.height,X.NUM_FRACTION_DIGITS)+20),t.flipX&&(e.x*=-1),t.flipY&&(e.y*=-1),'<filter id="SVGID_'.concat(this.id,'" y="-').concat(s,'%" height="').concat(100+2*s,'%" x="-').concat(i,'%" width="').concat(100+2*i,`%" >
|
|
108
|
+
<feGaussianBlur in="SourceAlpha" stdDeviation="`).concat(Z(this.blur?this.blur/2:0,X.NUM_FRACTION_DIGITS),`"></feGaussianBlur>
|
|
109
|
+
<feOffset dx="`).concat(Z(e.x,X.NUM_FRACTION_DIGITS),'" dy="').concat(Z(e.y,X.NUM_FRACTION_DIGITS),`" result="oBlur" ></feOffset>
|
|
110
|
+
<feFlood flood-color="`).concat(r.toRgb(),'" flood-opacity="').concat(r.getAlpha(),`"/>
|
|
111
|
+
<feComposite in2="oBlur" operator="in" />
|
|
112
|
+
<feMerge>
|
|
113
|
+
<feMergeNode></feMergeNode>
|
|
114
|
+
<feMergeNode in="SourceGraphic"></feMergeNode>
|
|
115
|
+
</feMerge>
|
|
116
|
+
</filter>
|
|
117
|
+
`)}toObject(){const t={color:this.color,blur:this.blur,offsetX:this.offsetX,offsetY:this.offsetY,affectStroke:this.affectStroke,nonScaling:this.nonScaling,type:this.constructor.type},e=$t.ownDefaults;return this.includeDefaultValues?t:Zi(t,(r,i)=>r!==e[i])}static async fromObject(t){return new this(t)}}p($t,"ownDefaults",{color:"rgb(0,0,0)",blur:0,offsetX:0,offsetY:0,affectStroke:!1,includeDefaultValues:!0,nonScaling:!1}),p($t,"type","shadow"),E.setClass($t,"shadow");const Fe=(n,t,e)=>Math.max(n,Math.min(t,e)),oc=[vt,U,yt,Pt,"flipX","flipY","originX","originY","angle","opacity","globalCompositeOperation","shadow","visible",Oe,De],re=[at,_t,"strokeWidth","strokeDashArray","width","height","paintFirst","strokeUniform","strokeLineCap","strokeDashOffset","strokeLineJoin","strokeMiterLimit","backgroundColor","clipPath"],ac={top:0,left:0,width:0,height:0,angle:0,flipX:!1,flipY:!1,scaleX:1,scaleY:1,minScaleLimit:0,skewX:0,skewY:0,originX:U,originY:vt,strokeWidth:1,strokeUniform:!1,padding:0,opacity:1,paintFirst:at,fill:"rgb(0,0,0)",fillRule:"nonzero",stroke:null,strokeDashArray:null,strokeDashOffset:0,strokeLineCap:"butt",strokeLineJoin:"miter",strokeMiterLimit:4,globalCompositeOperation:"source-over",backgroundColor:"",shadow:null,visible:!0,includeDefaultValues:!0,excludeFromExport:!1,objectCaching:!0,clipPath:void 0,inverted:!1,absolutePositioned:!1,centeredRotation:!0,centeredScaling:!1,dirty:!0},lc=(n,t,e,r)=>-e*Math.cos(n/r*er)+e+t,cc=()=>!1;class hs{constructor(t){let{startValue:e,byValue:r,duration:i=500,delay:s=0,easing:o=lc,onStart:a=Cr,onChange:l=Cr,onComplete:c=Cr,abort:h=cc,target:u}=t;p(this,"_state","pending"),p(this,"durationProgress",0),p(this,"valueProgress",0),this.tick=this.tick.bind(this),this.duration=i,this.delay=s,this.easing=o,this._onStart=a,this._onChange=l,this._onComplete=c,this._abort=h,this.target=u,this.startValue=e,this.byValue=r,this.value=this.startValue,this.endValue=Object.freeze(this.calculate(this.duration).value)}get state(){return this._state}isDone(){return this._state==="aborted"||this._state==="completed"}start(){const t=e=>{this._state==="pending"&&(this.startTime=e||+new Date,this._state="running",this._onStart(),this.tick(this.startTime))};this.register(),this.delay>0?setTimeout(()=>Pr(t),this.delay):Pr(t)}tick(t){const e=(t||+new Date)-this.startTime,r=Math.min(e,this.duration);this.durationProgress=r/this.duration;const{value:i,valueProgress:s}=this.calculate(r);this.value=Object.freeze(i),this.valueProgress=s,this._state!=="aborted"&&(this._abort(this.value,this.valueProgress,this.durationProgress)?(this._state="aborted",this.unregister()):e>=this.duration?(this.durationProgress=this.valueProgress=1,this._onChange(this.endValue,this.valueProgress,this.durationProgress),this._state="completed",this._onComplete(this.endValue,this.valueProgress,this.durationProgress),this.unregister()):(this._onChange(this.value,this.valueProgress,this.durationProgress),Pr(this.tick)))}register(){Mr.push(this)}unregister(){Mr.remove(this)}abort(){this._state="aborted",this.unregister()}}const hc=["startValue","endValue"];class uc extends hs{constructor(t){let{startValue:e=0,endValue:r=100}=t;super(v(v({},J(t,hc)),{},{startValue:e,byValue:r-e}))}calculate(t){const e=this.easing(t,this.startValue,this.byValue,this.duration);return{value:e,valueProgress:Math.abs((e-this.startValue)/this.byValue)}}}const dc=["startValue","endValue"];class gc extends hs{constructor(t){let{startValue:e=[0],endValue:r=[100]}=t;super(v(v({},J(t,dc)),{},{startValue:e,byValue:r.map((i,s)=>i-e[s])}))}calculate(t){const e=this.startValue.map((r,i)=>this.easing(t,r,this.byValue[i],this.duration,i));return{value:e,valueProgress:Math.abs((e[0]-this.startValue[0])/this.byValue[0])}}}const fc=["startValue","endValue","easing","onChange","onComplete","abort"],pc=(n,t,e,r)=>t+e*(1-Math.cos(n/r*er)),us=n=>n&&((t,e,r)=>n(new G(t).toRgba(),e,r));class mc extends hs{constructor(t){let{startValue:e,endValue:r,easing:i=pc,onChange:s,onComplete:o,abort:a}=t,l=J(t,fc);const c=new G(e).getSource(),h=new G(r).getSource();super(v(v({},l),{},{startValue:c,byValue:h.map((u,d)=>u-c[d]),easing:i,onChange:us(s),onComplete:us(o),abort:us(a)}))}calculate(t){const[e,r,i,s]=this.startValue.map((a,l)=>this.easing(t,a,this.byValue[l],this.duration,l)),o=[...[e,r,i].map(Math.round),Fe(0,s,1)];return{value:o,valueProgress:o.map((a,l)=>this.byValue[l]!==0?Math.abs((a-this.startValue[l])/this.byValue[l]):0).find(a=>a!==0)||0}}}function mo(n){const t=(e=>Array.isArray(e.startValue)||Array.isArray(e.endValue))(n)?new gc(n):new uc(n);return t.start(),t}function vc(n){const t=new mc(n);return t.start(),t}class Q{constructor(t){this.status=t,this.points=[]}includes(t){return this.points.some(e=>e.eq(t))}append(){for(var t=arguments.length,e=new Array(t),r=0;r<t;r++)e[r]=arguments[r];return this.points=this.points.concat(e.filter(i=>!this.includes(i))),this}static isPointContained(t,e,r){let i=arguments.length>3&&arguments[3]!==void 0&&arguments[3];if(e.eq(r))return t.eq(e);if(e.x===r.x)return t.x===e.x&&(i||t.y>=Math.min(e.y,r.y)&&t.y<=Math.max(e.y,r.y));if(e.y===r.y)return t.y===e.y&&(i||t.x>=Math.min(e.x,r.x)&&t.x<=Math.max(e.x,r.x));{const s=os(e,r),o=os(e,t).divide(s);return i?Math.abs(o.x)===Math.abs(o.y):o.x===o.y&&o.x>=0&&o.x<=1}}static isPointInPolygon(t,e){const r=new x(t).setX(Math.min(t.x-1,...e.map(s=>s.x)));let i=0;for(let s=0;s<e.length;s++){const o=this.intersectSegmentSegment(e[s],e[(s+1)%e.length],t,r);if(o.includes(t))return!0;i+=+(o.status==="Intersection")}return i%2==1}static intersectLineLine(t,e,r,i){let s=!(arguments.length>4&&arguments[4]!==void 0)||arguments[4],o=!(arguments.length>5&&arguments[5]!==void 0)||arguments[5];const a=e.x-t.x,l=e.y-t.y,c=i.x-r.x,h=i.y-r.y,u=t.x-r.x,d=t.y-r.y,g=c*d-h*u,f=a*d-l*u,m=h*a-c*l;if(m!==0){const b=g/m,y=f/m;return(s||0<=b&&b<=1)&&(o||0<=y&&y<=1)?new Q("Intersection").append(new x(t.x+b*a,t.y+b*l)):new Q}if(g===0||f===0){const b=s||o||Q.isPointContained(t,r,i)||Q.isPointContained(e,r,i)||Q.isPointContained(r,t,e)||Q.isPointContained(i,t,e);return new Q(b?"Coincident":void 0)}return new Q("Parallel")}static intersectSegmentLine(t,e,r,i){return Q.intersectLineLine(t,e,r,i,!1,!0)}static intersectSegmentSegment(t,e,r,i){return Q.intersectLineLine(t,e,r,i,!1,!1)}static intersectLinePolygon(t,e,r){let i=!(arguments.length>3&&arguments[3]!==void 0)||arguments[3];const s=new Q,o=r.length;for(let a,l,c,h=0;h<o;h++){if(a=r[h],l=r[(h+1)%o],c=Q.intersectLineLine(t,e,a,l,i,!1),c.status==="Coincident")return c;s.append(...c.points)}return s.points.length>0&&(s.status="Intersection"),s}static intersectSegmentPolygon(t,e,r){return Q.intersectLinePolygon(t,e,r,!1)}static intersectPolygonPolygon(t,e){const r=new Q,i=t.length,s=[];for(let o=0;o<i;o++){const a=t[o],l=t[(o+1)%i],c=Q.intersectSegmentPolygon(a,l,e);c.status==="Coincident"?(s.push(c),r.append(a,l)):r.append(...c.points)}return s.length>0&&s.length===t.length?new Q("Coincident"):(r.points.length>0&&(r.status="Intersection"),r)}static intersectPolygonRectangle(t,e,r){const i=e.min(r),s=e.max(r),o=new x(s.x,i.y),a=new x(i.x,s.y);return Q.intersectPolygonPolygon(t,[i,o,s,a])}}class bc extends Mn{getX(){return this.getXY().x}setX(t){this.setXY(this.getXY().setX(t))}getY(){return this.getXY().y}setY(t){this.setXY(this.getXY().setY(t))}getRelativeX(){return this.left}setRelativeX(t){this.left=t}getRelativeY(){return this.top}setRelativeY(t){this.top=t}getXY(){const t=this.getRelativeXY();return this.group?xt(t,this.group.calcTransformMatrix()):t}setXY(t,e,r){this.group&&(t=xt(t,Rt(this.group.calcTransformMatrix()))),this.setRelativeXY(t,e,r)}getRelativeXY(){return new x(this.left,this.top)}setRelativeXY(t){let e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:this.originX,r=arguments.length>2&&arguments[2]!==void 0?arguments[2]:this.originY;this.setPositionByOrigin(t,e,r)}isStrokeAccountedForInDimensions(){return!1}getCoords(){const{tl:t,tr:e,br:r,bl:i}=this.aCoords||(this.aCoords=this.calcACoords()),s=[t,e,r,i];if(this.group){const o=this.group.calcTransformMatrix();return s.map(a=>xt(a,o))}return s}intersectsWithRect(t,e){return Q.intersectPolygonRectangle(this.getCoords(),t,e).status==="Intersection"}intersectsWithObject(t){const e=Q.intersectPolygonPolygon(this.getCoords(),t.getCoords());return e.status==="Intersection"||e.status==="Coincident"||t.isContainedWithinObject(this)||this.isContainedWithinObject(t)}isContainedWithinObject(t){return this.getCoords().every(e=>t.containsPoint(e))}isContainedWithinRect(t,e){const{left:r,top:i,width:s,height:o}=this.getBoundingRect();return r>=t.x&&r+s<=e.x&&i>=t.y&&i+o<=e.y}isOverlapping(t){return this.intersectsWithObject(t)||this.isContainedWithinObject(t)||t.isContainedWithinObject(this)}containsPoint(t){return Q.isPointInPolygon(t,this.getCoords())}isOnScreen(){if(!this.canvas)return!1;const{tl:t,br:e}=this.canvas.vptCoords;return!!this.getCoords().some(r=>r.x<=e.x&&r.x>=t.x&&r.y<=e.y&&r.y>=t.y)||!!this.intersectsWithRect(t,e)||this.containsPoint(t.midPointFrom(e))}isPartiallyOnScreen(){if(!this.canvas)return!1;const{tl:t,br:e}=this.canvas.vptCoords;return this.intersectsWithRect(t,e)?!0:this.getCoords().every(r=>(r.x>=e.x||r.x<=t.x)&&(r.y>=e.y||r.y<=t.y))&&this.containsPoint(t.midPointFrom(e))}getBoundingRect(){return ee(this.getCoords())}getScaledWidth(){return this._getTransformedDimensions().x}getScaledHeight(){return this._getTransformedDimensions().y}scale(t){this._set(yt,t),this._set(Pt,t),this.setCoords()}scaleToWidth(t){const e=this.getBoundingRect().width/this.getScaledWidth();return this.scale(t/this.width/e)}scaleToHeight(t){const e=this.getBoundingRect().height/this.getScaledHeight();return this.scale(t/this.height/e)}getCanvasRetinaScaling(){var t;return((t=this.canvas)===null||t===void 0?void 0:t.getRetinaScaling())||1}getTotalAngle(){return this.group?te(An(this.calcTransformMatrix())):this.angle}getViewportTransform(){var t;return((t=this.canvas)===null||t===void 0?void 0:t.viewportTransform)||gt.concat()}calcACoords(){const t=Pe({angle:this.angle}),{x:e,y:r}=this.getRelativeCenterPoint(),i=ir(e,r),s=ht(i,t),o=this._getTransformedDimensions(),a=o.x/2,l=o.y/2;return{tl:xt({x:-a,y:-l},s),tr:xt({x:a,y:-l},s),bl:xt({x:-a,y:l},s),br:xt({x:a,y:l},s)}}setCoords(){this.aCoords=this.calcACoords()}transformMatrixKey(){let t=arguments.length>0&&arguments[0]!==void 0&&arguments[0],e=[];return!t&&this.group&&(e=this.group.transformMatrixKey(t)),e.push(this.top,this.left,this.width,this.height,this.scaleX,this.scaleY,this.angle,this.strokeWidth,this.skewX,this.skewY,+this.flipX,+this.flipY,ot(this.originX),ot(this.originY)),e}calcTransformMatrix(){let t=arguments.length>0&&arguments[0]!==void 0&&arguments[0],e=this.calcOwnMatrix();if(t||!this.group)return e;const r=this.transformMatrixKey(t),i=this.matrixCache;return i&&i.key.every((s,o)=>s===r[o])?i.value:(this.group&&(e=ht(this.group.calcTransformMatrix(!1),e)),this.matrixCache={key:r,value:e},e)}calcOwnMatrix(){const t=this.transformMatrixKey(!0),e=this.ownMatrixCache;if(e&&e.key===t)return e.value;const r=this.getRelativeCenterPoint(),i={angle:this.angle,translateX:r.x,translateY:r.y,scaleX:this.scaleX,scaleY:this.scaleY,skewX:this.skewX,skewY:this.skewY,flipX:this.flipX,flipY:this.flipY},s=zl(i);return this.ownMatrixCache={key:t,value:s},s}_getNonTransformedDimensions(){return new x(this.width,this.height).scalarAdd(this.strokeWidth)}_calculateCurrentDimensions(t){return this._getTransformedDimensions(t).transform(this.getViewportTransform(),!0).scalarAdd(2*this.padding)}_getTransformedDimensions(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};const e=v({scaleX:this.scaleX,scaleY:this.scaleY,skewX:this.skewX,skewY:this.skewY,width:this.width,height:this.height,strokeWidth:this.strokeWidth},t),r=e.strokeWidth;let i=r,s=0;this.strokeUniform&&(i=0,s=r);const o=e.width+i,a=e.height+i;let l;return l=e.skewX===0&&e.skewY===0?new x(o*e.scaleX,a*e.scaleY):ts(o,a,jr(e)),l.scalarAdd(s)}translateToGivenOrigin(t,e,r,i,s){let o=t.x,a=t.y;const l=ot(i)-ot(e),c=ot(s)-ot(r);if(l||c){const h=this._getTransformedDimensions();o+=l*h.x,a+=c*h.y}return new x(o,a)}translateToCenterPoint(t,e,r){if(e===W&&r===W)return t;const i=this.translateToGivenOrigin(t,e,r,W,W);return this.angle?i.rotate(st(this.angle),t):i}translateToOriginPoint(t,e,r){const i=this.translateToGivenOrigin(t,W,W,e,r);return this.angle?i.rotate(st(this.angle),t):i}getCenterPoint(){const t=this.getRelativeCenterPoint();return this.group?xt(t,this.group.calcTransformMatrix()):t}getRelativeCenterPoint(){return this.translateToCenterPoint(new x(this.left,this.top),this.originX,this.originY)}getPointByOrigin(t,e){return this.translateToOriginPoint(this.getRelativeCenterPoint(),t,e)}setPositionByOrigin(t,e,r){const i=this.translateToCenterPoint(t,e,r),s=this.translateToOriginPoint(i,this.originX,this.originY);this.set({left:s.x,top:s.y})}_getLeftTopCoords(){return this.translateToOriginPoint(this.getRelativeCenterPoint(),U,vt)}}const yc=["type"],_c=["extraParam"];let ie=class Mi extends bc{static getDefaults(){return Mi.ownDefaults}get type(){const t=this.constructor.type;return t==="FabricObject"?"object":t.toLowerCase()}set type(t){ce("warn","Setting type has no effect",t)}constructor(t){super(),p(this,"_cacheContext",null),Object.assign(this,Mi.ownDefaults),this.setOptions(t)}_createCacheCanvas(){this._cacheCanvas=Qt(),this._cacheContext=this._cacheCanvas.getContext("2d"),this._updateCacheCanvas(),this.dirty=!0}_limitCacheSize(t){const e=t.width,r=t.height,i=X.maxCacheSideLimit,s=X.minCacheSideLimit;if(e<=i&&r<=i&&e*r<=X.perfLimitSizeTotal)return e<s&&(t.width=s),r<s&&(t.height=s),t;const o=e/r,[a,l]=tr.limitDimsByArea(o),c=Fe(s,a,i),h=Fe(s,l,i);return e>c&&(t.zoomX/=e/c,t.width=c,t.capped=!0),r>h&&(t.zoomY/=r/h,t.height=h,t.capped=!0),t}_getCacheCanvasDimensions(){const t=this.getTotalObjectScaling(),e=this._getTransformedDimensions({skewX:0,skewY:0}),r=e.x*t.x/this.scaleX,i=e.y*t.y/this.scaleY;return{width:Math.ceil(r+2),height:Math.ceil(i+2),zoomX:t.x,zoomY:t.y,x:r,y:i}}_updateCacheCanvas(){const t=this._cacheCanvas,e=this._cacheContext,{width:r,height:i,zoomX:s,zoomY:o,x:a,y:l}=this._limitCacheSize(this._getCacheCanvasDimensions()),c=r!==t.width||i!==t.height,h=this.zoomX!==s||this.zoomY!==o;if(!t||!e)return!1;if(c||h){r!==t.width||i!==t.height?(t.width=r,t.height=i):(e.setTransform(1,0,0,1,0,0),e.clearRect(0,0,t.width,t.height));const u=a/2,d=l/2;return this.cacheTranslationX=Math.round(t.width/2-u)+u,this.cacheTranslationY=Math.round(t.height/2-d)+d,e.translate(this.cacheTranslationX,this.cacheTranslationY),e.scale(s,o),this.zoomX=s,this.zoomY=o,!0}return!1}setOptions(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};this._setOptions(t)}transform(t){const e=this.group&&!this.group._transformDone||this.group&&this.canvas&&t===this.canvas.contextTop,r=this.calcTransformMatrix(!e);t.transform(r[0],r[1],r[2],r[3],r[4],r[5])}getObjectScaling(){if(!this.group)return new x(Math.abs(this.scaleX),Math.abs(this.scaleY));const t=Ar(this.calcTransformMatrix());return new x(Math.abs(t.scaleX),Math.abs(t.scaleY))}getTotalObjectScaling(){const t=this.getObjectScaling();if(this.canvas){const e=this.canvas.getZoom(),r=this.getCanvasRetinaScaling();return t.scalarMultiply(e*r)}return t}getObjectOpacity(){let t=this.opacity;return this.group&&(t*=this.group.getObjectOpacity()),t}_constrainScale(t){return Math.abs(t)<this.minScaleLimit?t<0?-this.minScaleLimit:this.minScaleLimit:t===0?1e-4:t}_set(t,e){t!==yt&&t!==Pt||(e=this._constrainScale(e)),t===yt&&e<0?(this.flipX=!this.flipX,e*=-1):t==="scaleY"&&e<0?(this.flipY=!this.flipY,e*=-1):t!=="shadow"||!e||e instanceof $t||(e=new $t(e));const r=this[t]!==e;return this[t]=e,r&&this.constructor.cacheProperties.includes(t)&&(this.dirty=!0),this.parent&&(this.dirty||r&&this.constructor.stateProperties.includes(t))&&this.parent._set("dirty",!0),this}isNotVisible(){return this.opacity===0||!this.width&&!this.height&&this.strokeWidth===0||!this.visible}render(t){this.isNotVisible()||this.canvas&&this.canvas.skipOffscreen&&!this.group&&!this.isOnScreen()||(t.save(),this._setupCompositeOperation(t),this.drawSelectionBackground(t),this.transform(t),this._setOpacity(t),this._setShadow(t),this.shouldCache()?(this.renderCache(),this.drawCacheOnCanvas(t)):(this._removeCacheCanvas(),this.drawObject(t,!1,{}),this.dirty=!1),t.restore())}drawSelectionBackground(t){}renderCache(t){if(t=t||{},this._cacheCanvas&&this._cacheContext||this._createCacheCanvas(),this.isCacheDirty()&&this._cacheContext){const{zoomX:e,zoomY:r,cacheTranslationX:i,cacheTranslationY:s}=this,{width:o,height:a}=this._cacheCanvas;this.drawObject(this._cacheContext,t.forClipping,{zoomX:e,zoomY:r,cacheTranslationX:i,cacheTranslationY:s,width:o,height:a,parentClipPaths:[]}),this.dirty=!1}}_removeCacheCanvas(){this._cacheCanvas=void 0,this._cacheContext=null}hasStroke(){return this.stroke&&this.stroke!=="transparent"&&this.strokeWidth!==0}hasFill(){return this.fill&&this.fill!=="transparent"}needsItsOwnCache(){return!!(this.paintFirst===_t&&this.hasFill()&&this.hasStroke()&&this.shadow)||!!this.clipPath}shouldCache(){return this.ownCaching=this.objectCaching&&(!this.parent||!this.parent.isOnACache())||this.needsItsOwnCache(),this.ownCaching}willDrawShadow(){return!!this.shadow&&(this.shadow.offsetX!==0||this.shadow.offsetY!==0)}drawClipPathOnCache(t,e,r){t.save(),e.inverted?t.globalCompositeOperation="destination-out":t.globalCompositeOperation="destination-in",t.setTransform(1,0,0,1,0,0),t.drawImage(r,0,0),t.restore()}drawObject(t,e,r){const i=this.fill,s=this.stroke;e?(this.fill="black",this.stroke="",this._setClippingProperties(t)):this._renderBackground(t),this._render(t),this._drawClipPath(t,this.clipPath,r),this.fill=i,this.stroke=s}createClipPathLayer(t,e){const r=At(e),i=r.getContext("2d");if(i.translate(e.cacheTranslationX,e.cacheTranslationY),i.scale(e.zoomX,e.zoomY),t._cacheCanvas=r,e.parentClipPaths.forEach(s=>{s.transform(i)}),e.parentClipPaths.push(t),t.absolutePositioned){const s=Rt(this.calcTransformMatrix());i.transform(s[0],s[1],s[2],s[3],s[4],s[5])}return t.transform(i),t.drawObject(i,!0,e),r}_drawClipPath(t,e,r){if(!e)return;e._transformDone=!0;const i=this.createClipPathLayer(e,r);this.drawClipPathOnCache(t,e,i)}drawCacheOnCanvas(t){t.scale(1/this.zoomX,1/this.zoomY),t.drawImage(this._cacheCanvas,-this.cacheTranslationX,-this.cacheTranslationY)}isCacheDirty(){let t=arguments.length>0&&arguments[0]!==void 0&&arguments[0];if(this.isNotVisible())return!1;const e=this._cacheCanvas,r=this._cacheContext;return!(!e||!r||t||!this._updateCacheCanvas())||!!(this.dirty||this.clipPath&&this.clipPath.absolutePositioned)&&(e&&r&&!t&&(r.save(),r.setTransform(1,0,0,1,0,0),r.clearRect(0,0,e.width,e.height),r.restore()),!0)}_renderBackground(t){if(!this.backgroundColor)return;const e=this._getNonTransformedDimensions();t.fillStyle=this.backgroundColor,t.fillRect(-e.x/2,-e.y/2,e.x,e.y),this._removeShadow(t)}_setOpacity(t){this.group&&!this.group._transformDone?t.globalAlpha=this.getObjectOpacity():t.globalAlpha*=this.opacity}_setStrokeStyles(t,e){const r=e.stroke;r&&(t.lineWidth=e.strokeWidth,t.lineCap=e.strokeLineCap,t.lineDashOffset=e.strokeDashOffset,t.lineJoin=e.strokeLineJoin,t.miterLimit=e.strokeMiterLimit,jt(r)?r.gradientUnits==="percentage"||r.gradientTransform||r.patternTransform?this._applyPatternForTransformedGradient(t,r):(t.strokeStyle=r.toLive(t),this._applyPatternGradientTransform(t,r)):t.strokeStyle=e.stroke)}_setFillStyles(t,e){let{fill:r}=e;r&&(jt(r)?(t.fillStyle=r.toLive(t),this._applyPatternGradientTransform(t,r)):t.fillStyle=r)}_setClippingProperties(t){t.globalAlpha=1,t.strokeStyle="transparent",t.fillStyle="#000000"}_setLineDash(t,e){e&&e.length!==0&&t.setLineDash(e)}_setShadow(t){if(!this.shadow)return;const e=this.shadow,r=this.canvas,i=this.getCanvasRetinaScaling(),[s,,,o]=(r==null?void 0:r.viewportTransform)||gt,a=s*i,l=o*i,c=e.nonScaling?new x(1,1):this.getObjectScaling();t.shadowColor=e.color,t.shadowBlur=e.blur*X.browserShadowBlurConstant*(a+l)*(c.x+c.y)/4,t.shadowOffsetX=e.offsetX*a*c.x,t.shadowOffsetY=e.offsetY*l*c.y}_removeShadow(t){this.shadow&&(t.shadowColor="",t.shadowBlur=t.shadowOffsetX=t.shadowOffsetY=0)}_applyPatternGradientTransform(t,e){if(!jt(e))return{offsetX:0,offsetY:0};const r=e.gradientTransform||e.patternTransform,i=-this.width/2+e.offsetX||0,s=-this.height/2+e.offsetY||0;return e.gradientUnits==="percentage"?t.transform(this.width,0,0,this.height,i,s):t.transform(1,0,0,1,i,s),r&&t.transform(r[0],r[1],r[2],r[3],r[4],r[5]),{offsetX:i,offsetY:s}}_renderPaintInOrder(t){this.paintFirst===_t?(this._renderStroke(t),this._renderFill(t)):(this._renderFill(t),this._renderStroke(t))}_render(t){}_renderFill(t){this.fill&&(t.save(),this._setFillStyles(t,this),this.fillRule==="evenodd"?t.fill("evenodd"):t.fill(),t.restore())}_renderStroke(t){if(this.stroke&&this.strokeWidth!==0){if(this.shadow&&!this.shadow.affectStroke&&this._removeShadow(t),t.save(),this.strokeUniform){const e=this.getObjectScaling();t.scale(1/e.x,1/e.y)}this._setLineDash(t,this.strokeDashArray),this._setStrokeStyles(t,this),t.stroke(),t.restore()}}_applyPatternForTransformedGradient(t,e){var r;const i=this._limitCacheSize(this._getCacheCanvasDimensions()),s=this.getCanvasRetinaScaling(),o=i.x/this.scaleX/s,a=i.y/this.scaleY/s,l=At({width:Math.ceil(o),height:Math.ceil(a)}),c=l.getContext("2d");c&&(c.beginPath(),c.moveTo(0,0),c.lineTo(o,0),c.lineTo(o,a),c.lineTo(0,a),c.closePath(),c.translate(o/2,a/2),c.scale(i.zoomX/this.scaleX/s,i.zoomY/this.scaleY/s),this._applyPatternGradientTransform(c,e),c.fillStyle=e.toLive(t),c.fill(),t.translate(-this.width/2-this.strokeWidth/2,-this.height/2-this.strokeWidth/2),t.scale(s*this.scaleX/i.zoomX,s*this.scaleY/i.zoomY),t.strokeStyle=(r=c.createPattern(l,"no-repeat"))!==null&&r!==void 0?r:"")}_findCenterFromElement(){return new x(this.left+this.width/2,this.top+this.height/2)}clone(t){const e=this.toObject(t);return this.constructor.fromObject(e)}cloneAsImage(t){const e=this.toCanvasElement(t);return new(E.getClass("image"))(e)}toCanvasElement(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};const e=Yn(this),r=this.group,i=this.shadow,s=Math.abs,o=t.enableRetinaScaling?Sn():1,a=(t.multiplier||1)*o,l=t.canvasProvider||(w=>new or(w,{enableRetinaScaling:!1,renderOnAddRemove:!1,skipOffscreen:!1}));delete this.group,t.withoutTransform&&Nl(this),t.withoutShadow&&(this.shadow=null),t.viewportTransform&&ql(this,this.getViewportTransform()),this.setCoords();const c=Qt(),h=this.getBoundingRect(),u=this.shadow,d=new x;if(u){const w=u.blur,O=u.nonScaling?new x(1,1):this.getObjectScaling();d.x=2*Math.round(s(u.offsetX)+w)*s(O.x),d.y=2*Math.round(s(u.offsetY)+w)*s(O.y)}const g=h.width+d.x,f=h.height+d.y;c.width=Math.ceil(g),c.height=Math.ceil(f);const m=l(c);t.format==="jpeg"&&(m.backgroundColor="#fff"),this.setPositionByOrigin(new x(m.width/2,m.height/2),W,W);const b=this.canvas;m._objects=[this],this.set("canvas",m),this.setCoords();const y=m.toCanvasElement(a||1,t);return this.set("canvas",b),this.shadow=i,r&&(this.group=r),this.set(e),this.setCoords(),m._objects=[],m.destroy(),y}toDataURL(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};return En(this.toCanvasElement(t),t.format||"png",t.quality||1)}toBlob(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};return Pn(this.toCanvasElement(t),t.format||"png",t.quality||1)}isType(){for(var t=arguments.length,e=new Array(t),r=0;r<t;r++)e[r]=arguments[r];return e.includes(this.constructor.type)||e.includes(this.type)}complexity(){return 1}toJSON(){return this.toObject()}rotate(t){const{centeredRotation:e,originX:r,originY:i}=this;if(e){const{x:s,y:o}=this.getRelativeCenterPoint();this.originX=W,this.originY=W,this.left=s,this.top=o}if(this.set("angle",t),e){const{x:s,y:o}=this.translateToOriginPoint(this.getRelativeCenterPoint(),r,i);this.left=s,this.top=o,this.originX=r,this.originY=i}}setOnGroup(){}_setupCompositeOperation(t){this.globalCompositeOperation&&(t.globalCompositeOperation=this.globalCompositeOperation)}dispose(){Mr.cancelByTarget(this),this.off(),this._set("canvas",void 0),this._cacheCanvas&&Gt().dispose(this._cacheCanvas),this._cacheCanvas=void 0,this._cacheContext=null}animate(t,e){return Object.entries(t).reduce((r,i)=>{let[s,o]=i;return r[s]=this._animate(s,o,e),r},{})}_animate(t,e){let r=arguments.length>2&&arguments[2]!==void 0?arguments[2]:{};const i=t.split("."),s=this.constructor.colorProperties.includes(i[i.length-1]),{abort:o,startValue:a,onChange:l,onComplete:c}=r,h=v(v({},r),{},{target:this,startValue:a??i.reduce((u,d)=>u[d],this),endValue:e,abort:o==null?void 0:o.bind(this),onChange:(u,d,g)=>{i.reduce((f,m,b)=>(b===i.length-1&&(f[m]=u),f[m]),this),l&&l(u,d,g)},onComplete:(u,d,g)=>{this.setCoords(),c&&c(u,d,g)}});return s?vc(h):mo(h)}isDescendantOf(t){const{parent:e,group:r}=this;return e===t||r===t||!!e&&e.isDescendantOf(t)||!!r&&r!==e&&r.isDescendantOf(t)}getAncestors(){const t=[];let e=this;do e=e.parent,e&&t.push(e);while(e);return t}findCommonAncestors(t){if(this===t)return{fork:[],otherFork:[],common:[this,...this.getAncestors()]};const e=this.getAncestors(),r=t.getAncestors();if(e.length===0&&r.length>0&&this===r[r.length-1])return{fork:[],otherFork:[t,...r.slice(0,r.length-1)],common:[this]};for(let i,s=0;s<e.length;s++){if(i=e[s],i===t)return{fork:[this,...e.slice(0,s)],otherFork:[],common:e.slice(s)};for(let o=0;o<r.length;o++){if(this===r[o])return{fork:[],otherFork:[t,...r.slice(0,o)],common:[this,...e]};if(i===r[o])return{fork:[this,...e.slice(0,s)],otherFork:[t,...r.slice(0,o)],common:e.slice(s)}}}return{fork:[this,...e],otherFork:[t,...r],common:[]}}hasCommonAncestors(t){const e=this.findCommonAncestors(t);return e&&!!e.common.length}isInFrontOf(t){if(this===t)return;const e=this.findCommonAncestors(t);if(e.fork.includes(t))return!0;if(e.otherFork.includes(this))return!1;const r=e.common[0]||this.canvas;if(!r)return;const i=e.fork.pop(),s=e.otherFork.pop(),o=r._objects.indexOf(i),a=r._objects.indexOf(s);return o>-1&&o>a}toObject(){const t=(arguments.length>0&&arguments[0]!==void 0?arguments[0]:[]).concat(Mi.customProperties,this.constructor.customProperties||[]);let e;const r=X.NUM_FRACTION_DIGITS,{clipPath:i,fill:s,stroke:o,shadow:a,strokeDashArray:l,left:c,top:h,originX:u,originY:d,width:g,height:f,strokeWidth:m,strokeLineCap:b,strokeDashOffset:y,strokeLineJoin:w,strokeUniform:O,strokeMiterLimit:k,scaleX:S,scaleY:C,angle:A,flipX:D,flipY:L,opacity:R,visible:H,backgroundColor:I,fillRule:M,paintFirst:j,globalCompositeOperation:z,skewX:V,skewY:tt}=this;i&&!i.excludeFromExport&&(e=i.toObject(t.concat("inverted","absolutePositioned")));const N=Mt=>Z(Mt,r),Ct=v(v({},Ae(this,t)),{},{type:this.constructor.type,version:Wi,originX:u,originY:d,left:N(c),top:N(h),width:N(g),height:N(f),fill:Rn(s)?s.toObject():s,stroke:Rn(o)?o.toObject():o,strokeWidth:N(m),strokeDashArray:l&&l.concat(),strokeLineCap:b,strokeDashOffset:y,strokeLineJoin:w,strokeUniform:O,strokeMiterLimit:N(k),scaleX:N(S),scaleY:N(C),angle:N(A),flipX:D,flipY:L,opacity:N(R),shadow:a&&a.toObject(),visible:H,backgroundColor:I,fillRule:M,paintFirst:j,globalCompositeOperation:z,skewX:N(V),skewY:N(tt)},e?{clipPath:e}:null);return this.includeDefaultValues?Ct:this._removeDefaultValues(Ct)}toDatalessObject(t){return this.toObject(t)}_removeDefaultValues(t){const e=this.constructor.getDefaults(),r=Object.keys(e).length>0?e:Object.getPrototypeOf(this);return Zi(t,(i,s)=>{if(s===U||s===vt||s==="type")return!0;const o=r[s];return i!==o&&!(Array.isArray(i)&&Array.isArray(o)&&i.length===0&&o.length===0)})}toString(){return"#<".concat(this.constructor.type,">")}static _fromObject(t){let e=J(t,yc),r=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},{extraParam:i}=r,s=J(r,_c);return Fr(e,s).then(o=>i?(delete o[i],new this(e[i],o)):new this(o))}static fromObject(t,e){return this._fromObject(t,e)}};p(ie,"stateProperties",oc),p(ie,"cacheProperties",re),p(ie,"ownDefaults",ac),p(ie,"type","FabricObject"),p(ie,"colorProperties",[at,_t,"backgroundColor"]),p(ie,"customProperties",[]),E.setClass(ie),E.setClass(ie,"object");const Re=(n,t,e)=>(r,i,s,o)=>{const a=t(r,i,s,o);return a&&Un(n,v(v({},$n(r,i,s,o)),e)),a};function Be(n){return(t,e,r,i)=>{const{target:s,originX:o,originY:a}=e,l=s.getRelativeCenterPoint(),c=s.translateToOriginPoint(l,o,a),h=n(t,e,r,i);return s.setPositionByOrigin(c,e.originX,e.originY),h}}const vo=Re(rr,Be((n,t,e,r)=>{const i=es(t,t.originX,t.originY,e,r);if(ot(t.originX)===ot(W)||ot(t.originX)===ot(it)&&i.x<0||ot(t.originX)===ot(U)&&i.x>0){const{target:s}=t,o=s.strokeWidth/(s.strokeUniform?s.scaleX:1),a=Gn(t)?2:1,l=s.width,c=Math.abs(i.x*a/s.scaleX)-o;return s.set("width",Math.max(c,1)),l!==s.width}return!1}));function xc(n,t,e,r,i){r=r||{};const s=this.sizeX||r.cornerSize||i.cornerSize,o=this.sizeY||r.cornerSize||i.cornerSize,a=r.transparentCorners!==void 0?r.transparentCorners:i.transparentCorners,l=a?_t:at,c=!a&&(r.cornerStrokeColor||i.cornerStrokeColor);let h,u=t,d=e;n.save(),n.fillStyle=r.cornerColor||i.cornerColor||"",n.strokeStyle=r.cornerStrokeColor||i.cornerStrokeColor||"",s>o?(h=s,n.scale(1,o/s),d=e*s/o):o>s?(h=o,n.scale(s/o,1),u=t*o/s):h=s,n.beginPath(),n.arc(u,d,h/2,0,Sr,!1),n[l](),c&&n.stroke(),n.restore()}function wc(n,t,e,r,i){r=r||{};const s=this.sizeX||r.cornerSize||i.cornerSize,o=this.sizeY||r.cornerSize||i.cornerSize,a=r.transparentCorners!==void 0?r.transparentCorners:i.transparentCorners,l=a?_t:at,c=!a&&(r.cornerStrokeColor||i.cornerStrokeColor),h=s/2,u=o/2;n.save(),n.fillStyle=r.cornerColor||i.cornerColor||"",n.strokeStyle=r.cornerStrokeColor||i.cornerStrokeColor||"",n.translate(t,e);const d=i.getTotalAngle();n.rotate(st(d)),n["".concat(l,"Rect")](-h,-u,s,o),c&&n.strokeRect(-h,-u,s,o),n.restore()}class zt{constructor(t){p(this,"visible",!0),p(this,"actionName",Or),p(this,"angle",0),p(this,"x",0),p(this,"y",0),p(this,"offsetX",0),p(this,"offsetY",0),p(this,"sizeX",0),p(this,"sizeY",0),p(this,"touchSizeX",0),p(this,"touchSizeY",0),p(this,"cursorStyle","crosshair"),p(this,"withConnection",!1),Object.assign(this,t)}shouldActivate(t,e,r,i){var s;let{tl:o,tr:a,br:l,bl:c}=i;return((s=e.canvas)===null||s===void 0?void 0:s.getActiveObject())===e&&e.isControlVisible(t)&&Q.isPointInPolygon(r,[o,a,l,c])}getActionHandler(t,e,r){return this.actionHandler}getMouseDownHandler(t,e,r){return this.mouseDownHandler}getMouseUpHandler(t,e,r){return this.mouseUpHandler}cursorStyleHandler(t,e,r){return e.cursorStyle}getActionName(t,e,r){return e.actionName}getVisibility(t,e){var r,i;return(r=(i=t._controlsVisibility)===null||i===void 0?void 0:i[e])!==null&&r!==void 0?r:this.visible}setVisibility(t,e,r){this.visible=t}positionHandler(t,e,r,i){return new x(this.x*t.x+this.offsetX,this.y*t.y+this.offsetY).transform(e)}calcCornerCoords(t,e,r,i,s,o){const a=qi([ir(r,i),Pe({angle:t}),Ki((s?this.touchSizeX:this.sizeX)||e,(s?this.touchSizeY:this.sizeY)||e)]);return{tl:new x(-.5,-.5).transform(a),tr:new x(.5,-.5).transform(a),br:new x(.5,.5).transform(a),bl:new x(-.5,.5).transform(a)}}render(t,e,r,i,s){((i=i||{}).cornerStyle||s.cornerStyle)==="circle"?xc.call(this,t,e,r,i,s):wc.call(this,t,e,r,i,s)}}const Cc=(n,t,e)=>e.lockRotation?Ir:t.cursorStyle,Sc=Re(kn,Be((n,t,e,r)=>{let{target:i,ex:s,ey:o,theta:a,originX:l,originY:c}=t;const h=i.translateToOriginPoint(i.getRelativeCenterPoint(),l,c);if(It(i,"lockRotation"))return!1;const u=Math.atan2(o-h.y,s-h.x),d=Math.atan2(r-h.y,e-h.x);let g=te(d-u+a);if(i.snapAngle&&i.snapAngle>0){const m=i.snapAngle,b=i.snapThreshold||m,y=Math.ceil(g/m)*m,w=Math.floor(g/m)*m;Math.abs(g-w)<b?g=w:Math.abs(g-y)<b&&(g=y)}g<0&&(g=360+g),g%=360;const f=i.angle!==g;return i.angle=g,f}));function bo(n,t){const e=t.canvas,r=n[e.uniScaleKey];return e.uniformScaling&&!r||!e.uniformScaling&&r}function yo(n,t,e){const r=It(n,"lockScalingX"),i=It(n,"lockScalingY");if(r&&i||!t&&(r||i)&&e||r&&t==="x"||i&&t==="y")return!0;const{width:s,height:o,strokeWidth:a}=n;return s===0&&a===0&&t!=="y"||o===0&&a===0&&t!=="x"}const Tc=["e","se","s","sw","w","nw","n","ne","e"],ur=(n,t,e)=>{const r=bo(n,e);if(yo(e,t.x!==0&&t.y===0?"x":t.x===0&&t.y!==0?"y":"",r))return Ir;const i=qn(e,t);return"".concat(Tc[i],"-resize")};function ds(n,t,e,r){let i=arguments.length>4&&arguments[4]!==void 0?arguments[4]:{};const s=t.target,o=i.by,a=bo(n,s);let l,c,h,u,d,g;if(yo(s,o,a))return!1;if(t.gestureScale)c=t.scaleX*t.gestureScale,h=t.scaleY*t.gestureScale;else{if(l=es(t,t.originX,t.originY,e,r),d=o!=="y"?Math.sign(l.x||t.signX||1):1,g=o!=="x"?Math.sign(l.y||t.signY||1):1,t.signX||(t.signX=d),t.signY||(t.signY=g),It(s,"lockScalingFlip")&&(t.signX!==d||t.signY!==g))return!1;if(u=s._getTransformedDimensions(),a&&!o){const b=Math.abs(l.x)+Math.abs(l.y),{original:y}=t,w=b/(Math.abs(u.x*y.scaleX/s.scaleX)+Math.abs(u.y*y.scaleY/s.scaleY));c=y.scaleX*w,h=y.scaleY*w}else c=Math.abs(l.x*s.scaleX/u.x),h=Math.abs(l.y*s.scaleY/u.y);Gn(t)&&(c*=2,h*=2),t.signX!==d&&o!=="y"&&(t.originX=Nn(t.originX),c*=-1,t.signX=d),t.signY!==g&&o!=="x"&&(t.originY=Nn(t.originY),h*=-1,t.signY=g)}const f=s.scaleX,m=s.scaleY;return o?(o==="x"&&s.set(yt,c),o==="y"&&s.set(Pt,h)):(!It(s,"lockScalingX")&&s.set(yt,c),!It(s,"lockScalingY")&&s.set(Pt,h)),f!==s.scaleX||m!==s.scaleY}const Xr=Re(Tr,Be((n,t,e,r)=>ds(n,t,e,r))),kc=Re(Tr,Be((n,t,e,r)=>ds(n,t,e,r,{by:"x"}))),Oc=Re(Tr,Be((n,t,e,r)=>ds(n,t,e,r,{by:"y"}))),Dc=["target","ex","ey","skewingSide"],gs={x:{counterAxis:"y",scale:yt,skew:Oe,lockSkewing:"lockSkewingX",origin:"originX",flip:"flipX"},y:{counterAxis:"x",scale:Pt,skew:De,lockSkewing:"lockSkewingY",origin:"originY",flip:"flipY"}},Mc=["ns","nesw","ew","nwse"],Ec=(n,t,e)=>{if(t.x!==0&&It(e,"lockSkewingY")||t.y!==0&&It(e,"lockSkewingX"))return Ir;const r=qn(e,t)%4;return"".concat(Mc[r],"-resize")};function _o(n,t,e,r,i){const{target:s}=e,{counterAxis:o,origin:a,lockSkewing:l,skew:c,flip:h}=gs[n];if(It(s,l))return!1;const{origin:u,flip:d}=gs[o],g=ot(e[u])*(s[d]?-1:1),f=-Math.sign(g)*(s[h]?-1:1),m=.5*-((s[c]===0&&es(e,W,W,r,i)[n]>0||s[c]>0?1:-1)*f)+.5;return Re(On,Be((y,w,O,k)=>function(S,C,A){let{target:D,ex:L,ey:R,skewingSide:H}=C,I=J(C,Dc);const{skew:M}=gs[S],j=A.subtract(new x(L,R)).divide(new x(D.scaleX,D.scaleY))[S],z=D[M],V=I[M],tt=Math.tan(st(V)),N=S==="y"?D._getTransformedDimensions({scaleX:1,scaleY:1,skewX:0}).x:D._getTransformedDimensions({scaleX:1,scaleY:1}).y,Ct=2*j*H/Math.max(N,1)+tt,Mt=te(Math.atan(Ct));D.set(M,Mt);const ct=z!==D[M];if(ct&&S==="y"){const{skewX:T,scaleX:F}=D,P=D._getTransformedDimensions({skewY:z}),B=D._getTransformedDimensions(),$=T!==0?P.x/B.x:1;$!==1&&D.set(yt,$*F)}return ct}(n,w,new x(O,k))))(t,v(v({},e),{},{[a]:m,skewingSide:f}),r,i)}const Pc=(n,t,e,r)=>_o("x",n,t,e,r),Ac=(n,t,e,r)=>_o("y",n,t,e,r);function Yr(n,t){return n[t.canvas.altActionKey]}const Ur=(n,t,e)=>{const r=Yr(n,e);return t.x===0?r?Oe:Pt:t.y===0?r?De:yt:""},Ie=(n,t,e)=>Yr(n,e)?Ec(0,t,e):ur(n,t,e),xo=(n,t,e,r)=>Yr(n,t.target)?Ac(n,t,e,r):kc(n,t,e,r),wo=(n,t,e,r)=>Yr(n,t.target)?Pc(n,t,e,r):Oc(n,t,e,r),Co=()=>({ml:new zt({x:-.5,y:0,cursorStyleHandler:Ie,actionHandler:xo,getActionName:Ur}),mr:new zt({x:.5,y:0,cursorStyleHandler:Ie,actionHandler:xo,getActionName:Ur}),mb:new zt({x:0,y:.5,cursorStyleHandler:Ie,actionHandler:wo,getActionName:Ur}),mt:new zt({x:0,y:-.5,cursorStyleHandler:Ie,actionHandler:wo,getActionName:Ur}),tl:new zt({x:-.5,y:-.5,cursorStyleHandler:ur,actionHandler:Xr}),tr:new zt({x:.5,y:-.5,cursorStyleHandler:ur,actionHandler:Xr}),bl:new zt({x:-.5,y:.5,cursorStyleHandler:ur,actionHandler:Xr}),br:new zt({x:.5,y:.5,cursorStyleHandler:ur,actionHandler:Xr}),mtr:new zt({x:0,y:-.5,actionHandler:Sc,cursorStyleHandler:Cc,offsetY:-40,withConnection:!0,actionName:Gi})}),jc=()=>({mr:new zt({x:.5,y:0,actionHandler:vo,cursorStyleHandler:Ie,actionName:rr}),ml:new zt({x:-.5,y:0,actionHandler:vo,cursorStyleHandler:Ie,actionName:rr})}),Lc=()=>v(v({},Co()),jc());class dr extends ie{static getDefaults(){return v(v({},super.getDefaults()),dr.ownDefaults)}constructor(t){super(),Object.assign(this,this.constructor.createControls(),dr.ownDefaults),this.setOptions(t)}static createControls(){return{controls:Co()}}_updateCacheCanvas(){const t=this.canvas;if(this.noScaleCache&&t&&t._currentTransform){const e=t._currentTransform,r=e.target,i=e.action;if(this===r&&i&&i.startsWith(Or))return!1}return super._updateCacheCanvas()}getActiveControl(){const t=this.__corner;return t?{key:t,control:this.controls[t],coord:this.oCoords[t]}:void 0}findControl(t){let e=arguments.length>1&&arguments[1]!==void 0&&arguments[1];if(!this.hasControls||!this.canvas)return;this.__corner=void 0;const r=Object.entries(this.oCoords);for(let i=r.length-1;i>=0;i--){const[s,o]=r[i],a=this.controls[s];if(a.shouldActivate(s,this,t,e?o.touchCorner:o.corner))return this.__corner=s,{key:s,control:a,coord:this.oCoords[s]}}}calcOCoords(){const t=this.getViewportTransform(),e=this.getCenterPoint(),r=ir(e.x,e.y),i=Pe({angle:this.getTotalAngle()-(this.group&&this.flipX?180:0)}),s=ht(r,i),o=ht(t,s),a=ht(o,[1/t[0],0,0,1/t[3],0,0]),l=this.group?Ar(this.calcTransformMatrix()):void 0;l&&(l.scaleX=Math.abs(l.scaleX),l.scaleY=Math.abs(l.scaleY));const c=this._calculateCurrentDimensions(l),h={};return this.forEachControl((u,d)=>{const g=u.positionHandler(c,a,this,u);h[d]=Object.assign(g,this._calcCornerCoords(u,g))}),h}_calcCornerCoords(t,e){const r=this.getTotalAngle();return{corner:t.calcCornerCoords(r,this.cornerSize,e.x,e.y,!1,this),touchCorner:t.calcCornerCoords(r,this.touchCornerSize,e.x,e.y,!0,this)}}setCoords(){super.setCoords(),this.canvas&&(this.oCoords=this.calcOCoords())}forEachControl(t){for(const e in this.controls)t(this.controls[e],e,this)}drawSelectionBackground(t){if(!this.selectionBackgroundColor||this.canvas&&this.canvas._activeObject!==this)return;t.save();const e=this.getRelativeCenterPoint(),r=this._calculateCurrentDimensions(),i=this.getViewportTransform();t.translate(e.x,e.y),t.scale(1/i[0],1/i[3]),t.rotate(st(this.angle)),t.fillStyle=this.selectionBackgroundColor,t.fillRect(-r.x/2,-r.y/2,r.x,r.y),t.restore()}strokeBorders(t,e){t.strokeRect(-e.x/2,-e.y/2,e.x,e.y)}_drawBorders(t,e){let r=arguments.length>2&&arguments[2]!==void 0?arguments[2]:{};const i=v({hasControls:this.hasControls,borderColor:this.borderColor,borderDashArray:this.borderDashArray},r);t.save(),t.strokeStyle=i.borderColor,this._setLineDash(t,i.borderDashArray),this.strokeBorders(t,e),i.hasControls&&this.drawControlsConnectingLines(t,e),t.restore()}_renderControls(t){let e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};const{hasBorders:r,hasControls:i}=this,s=v({hasBorders:r,hasControls:i},e),o=this.getViewportTransform(),a=s.hasBorders,l=s.hasControls,c=ht(o,this.calcTransformMatrix()),h=Ar(c);t.save(),t.translate(h.translateX,h.translateY),t.lineWidth=this.borderScaleFactor,this.group===this.parent&&(t.globalAlpha=this.isMoving?this.borderOpacityWhenMoving:1),this.flipX&&(h.angle-=180),t.rotate(st(this.group?h.angle:this.angle)),a&&this.drawBorders(t,h,e),l&&this.drawControls(t,e),t.restore()}drawBorders(t,e,r){let i;if(r&&r.forActiveSelection||this.group){const s=ts(this.width,this.height,jr(e)),o=this.isStrokeAccountedForInDimensions()?$i:(this.strokeUniform?new x().scalarAdd(this.canvas?this.canvas.getZoom():1):new x(e.scaleX,e.scaleY)).scalarMultiply(this.strokeWidth);i=s.add(o).scalarAdd(this.borderScaleFactor).scalarAdd(2*this.padding)}else i=this._calculateCurrentDimensions().scalarAdd(this.borderScaleFactor);this._drawBorders(t,i,r)}drawControlsConnectingLines(t,e){let r=!1;t.beginPath(),this.forEachControl((i,s)=>{i.withConnection&&i.getVisibility(this,s)&&(r=!0,t.moveTo(i.x*e.x,i.y*e.y),t.lineTo(i.x*e.x+i.offsetX,i.y*e.y+i.offsetY))}),r&&t.stroke()}drawControls(t){let e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};t.save();const r=this.getCanvasRetinaScaling(),{cornerStrokeColor:i,cornerDashArray:s,cornerColor:o}=this,a=v({cornerStrokeColor:i,cornerDashArray:s,cornerColor:o},e);t.setTransform(r,0,0,r,0,0),t.strokeStyle=t.fillStyle=a.cornerColor,this.transparentCorners||(t.strokeStyle=a.cornerStrokeColor),this._setLineDash(t,a.cornerDashArray),this.forEachControl((l,c)=>{if(l.getVisibility(this,c)){const h=this.oCoords[c];l.render(t,h.x,h.y,a,this)}}),t.restore()}isControlVisible(t){return this.controls[t]&&this.controls[t].getVisibility(this,t)}setControlVisible(t,e){this._controlsVisibility||(this._controlsVisibility={}),this._controlsVisibility[t]=e}setControlsVisibility(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};Object.entries(t).forEach(e=>{let[r,i]=e;return this.setControlVisible(r,i)})}clearContextTop(t){if(!this.canvas)return;const e=this.canvas.contextTop;if(!e)return;const r=this.canvas.viewportTransform;e.save(),e.transform(r[0],r[1],r[2],r[3],r[4],r[5]),this.transform(e);const i=this.width+4,s=this.height+4;return e.clearRect(-i/2,-s/2,i,s),t||e.restore(),e}onDeselect(t){return!1}onSelect(t){return!1}shouldStartDragging(t){return!1}onDragStart(t){return!1}canDrop(t){return!1}renderDragSourceEffect(t){}renderDropTargetEffect(t){}}function So(n,t){return t.forEach(e=>{Object.getOwnPropertyNames(e.prototype).forEach(r=>{r!=="constructor"&&Object.defineProperty(n.prototype,r,Object.getOwnPropertyDescriptor(e.prototype,r)||Object.create(null))})}),n}p(dr,"ownDefaults",{noScaleCache:!0,lockMovementX:!1,lockMovementY:!1,lockRotation:!1,lockScalingX:!1,lockScalingY:!1,lockSkewingX:!1,lockSkewingY:!1,lockScalingFlip:!1,cornerSize:13,touchCornerSize:24,transparentCorners:!0,cornerColor:"rgb(178,204,255)",cornerStrokeColor:"",cornerStyle:"rect",cornerDashArray:null,hasControls:!0,borderColor:"rgb(178,204,255)",borderDashArray:null,borderOpacityWhenMoving:.4,borderScaleFactor:1,hasBorders:!0,selectionBackgroundColor:"",selectable:!0,evented:!0,perPixelTargetFind:!1,activeOn:"down",hoverCursor:null,moveCursor:null});class ut extends dr{}So(ut,[to]),E.setClass(ut),E.setClass(ut,"object");const Fc=(n,t,e,r)=>{const i=2*(r=Math.round(r))+1,{data:s}=n.getImageData(t-r,e-r,i,i);for(let o=3;o<s.length;o+=4)if(s[o]>0)return!1;return!0};class To{constructor(t){this.options=t,this.strokeProjectionMagnitude=this.options.strokeWidth/2,this.scale=new x(this.options.scaleX,this.options.scaleY),this.strokeUniformScalar=this.options.strokeUniform?new x(1/this.options.scaleX,1/this.options.scaleY):new x(1,1)}createSideVector(t,e){const r=os(t,e);return this.options.strokeUniform?r.multiply(this.scale):r}projectOrthogonally(t,e,r){return this.applySkew(t.add(this.calcOrthogonalProjection(t,e,r)))}isSkewed(){return this.options.skewX!==0||this.options.skewY!==0}applySkew(t){const e=new x(t);return e.y+=e.x*Math.tan(st(this.options.skewY)),e.x+=e.y*Math.tan(st(this.options.skewX)),e}scaleUnitVector(t,e){return t.multiply(this.strokeUniformScalar).scalarMultiply(e)}}const Rc=new x;class He extends To{static getOrthogonalRotationFactor(t,e){const r=e?ls(t,e):sc(t);return Math.abs(r)<er?-1:1}constructor(t,e,r,i){super(i),p(this,"AB",void 0),p(this,"AC",void 0),p(this,"alpha",void 0),p(this,"bisector",void 0),this.A=new x(t),this.B=new x(e),this.C=new x(r),this.AB=this.createSideVector(this.A,this.B),this.AC=this.createSideVector(this.A,this.C),this.alpha=ls(this.AB,this.AC),this.bisector=cs(ho(this.AB.eq(Rc)?this.AC:this.AB,this.alpha/2))}calcOrthogonalProjection(t,e){let r=arguments.length>2&&arguments[2]!==void 0?arguments[2]:this.strokeProjectionMagnitude;const i=this.createSideVector(t,e),s=uo(i),o=He.getOrthogonalRotationFactor(s,this.bisector);return this.scaleUnitVector(s,r*o)}projectBevel(){const t=[];return(this.alpha%Sr==0?[this.B]:[this.B,this.C]).forEach(e=>{t.push(this.projectOrthogonally(this.A,e)),t.push(this.projectOrthogonally(this.A,e,-this.strokeProjectionMagnitude))}),t}projectMiter(){const t=[],e=Math.abs(this.alpha),r=1/Math.sin(e/2),i=this.scaleUnitVector(this.bisector,-this.strokeProjectionMagnitude*r),s=this.options.strokeUniform?as(this.scaleUnitVector(this.bisector,this.options.strokeMiterLimit)):this.options.strokeMiterLimit;return as(i)/this.strokeProjectionMagnitude<=s&&t.push(this.applySkew(this.A.add(i))),t.push(...this.projectBevel()),t}projectRoundNoSkew(t,e){const r=[],i=new x(He.getOrthogonalRotationFactor(this.bisector),He.getOrthogonalRotationFactor(new x(this.bisector.y,this.bisector.x)));return[new x(1,0).scalarMultiply(this.strokeProjectionMagnitude).multiply(this.strokeUniformScalar).multiply(i),new x(0,1).scalarMultiply(this.strokeProjectionMagnitude).multiply(this.strokeUniformScalar).multiply(i)].forEach(s=>{go(s,t,e)&&r.push(this.A.add(s))}),r}projectRoundWithSkew(t,e){const r=[],{skewX:i,skewY:s,scaleX:o,scaleY:a,strokeUniform:l}=this.options,c=new x(Math.tan(st(i)),Math.tan(st(s))),h=this.strokeProjectionMagnitude,u=l?h/a/Math.sqrt(1/a**2+1/o**2*c.y**2):h/Math.sqrt(1+c.y**2),d=new x(Math.sqrt(Math.max(h**2-u**2,0)),u),g=l?h/Math.sqrt(1+c.x**2*(1/a)**2/(1/o+1/o*c.x*c.y)**2):h/Math.sqrt(1+c.x**2/(1+c.x*c.y)**2),f=new x(g,Math.sqrt(Math.max(h**2-g**2,0)));return[f,f.scalarMultiply(-1),d,d.scalarMultiply(-1)].map(m=>this.applySkew(l?m.multiply(this.strokeUniformScalar):m)).forEach(m=>{go(m,t,e)&&r.push(this.applySkew(this.A).add(m))}),r}projectRound(){const t=[];t.push(...this.projectBevel());const e=this.alpha%Sr==0,r=this.applySkew(this.A),i=t[e?0:2].subtract(r),s=t[e?1:0].subtract(r),o=e?this.applySkew(this.AB.scalarMultiply(-1)):this.applySkew(this.bisector.multiply(this.strokeUniformScalar).scalarMultiply(-1)),a=hr(i,o)>0,l=a?i:s,c=a?s:i;return this.isSkewed()?t.push(...this.projectRoundWithSkew(l,c)):t.push(...this.projectRoundNoSkew(l,c)),t}projectPoints(){switch(this.options.strokeLineJoin){case"miter":return this.projectMiter();case"round":return this.projectRound();default:return this.projectBevel()}}project(){return this.projectPoints().map(t=>({originPoint:this.A,projectedPoint:t,angle:this.alpha,bisector:this.bisector}))}}class ko extends To{constructor(t,e,r){super(r),this.A=new x(t),this.T=new x(e)}calcOrthogonalProjection(t,e){let r=arguments.length>2&&arguments[2]!==void 0?arguments[2]:this.strokeProjectionMagnitude;const i=this.createSideVector(t,e);return this.scaleUnitVector(uo(i),r)}projectButt(){return[this.projectOrthogonally(this.A,this.T,this.strokeProjectionMagnitude),this.projectOrthogonally(this.A,this.T,-this.strokeProjectionMagnitude)]}projectRound(){const t=[];if(!this.isSkewed()&&this.A.eq(this.T)){const e=new x(1,1).scalarMultiply(this.strokeProjectionMagnitude).multiply(this.strokeUniformScalar);t.push(this.applySkew(this.A.add(e)),this.applySkew(this.A.subtract(e)))}else t.push(...new He(this.A,this.T,this.T,this.options).projectRound());return t}projectSquare(){const t=[];if(this.A.eq(this.T)){const e=new x(1,1).scalarMultiply(this.strokeProjectionMagnitude).multiply(this.strokeUniformScalar);t.push(this.A.add(e),this.A.subtract(e))}else{const e=this.calcOrthogonalProjection(this.A,this.T,this.strokeProjectionMagnitude),r=this.scaleUnitVector(cs(this.createSideVector(this.A,this.T)),-this.strokeProjectionMagnitude),i=this.A.add(r);t.push(i.add(e),i.subtract(e))}return t.map(e=>this.applySkew(e))}projectPoints(){switch(this.options.strokeLineCap){case"round":return this.projectRound();case"square":return this.projectSquare();default:return this.projectButt()}}project(){return this.projectPoints().map(t=>({originPoint:this.A,projectedPoint:t}))}}const Bc=function(n,t){let e=arguments.length>2&&arguments[2]!==void 0&&arguments[2];const r=[];if(n.length===0)return r;const i=n.reduce((s,o)=>(s[s.length-1].eq(o)||s.push(new x(o)),s),[new x(n[0])]);if(i.length===1)e=!0;else if(!e){const s=i[0],o=((a,l)=>{for(let c=a.length-1;c>=0;c--)if(l(a[c],c,a))return c;return-1})(i,a=>!a.eq(s));i.splice(o+1)}return i.forEach((s,o,a)=>{let l,c;o===0?(c=a[1],l=e?s:a[a.length-1]):o===a.length-1?(l=a[o-1],c=e?s:a[0]):(l=a[o-1],c=a[o+1]),e&&a.length===1?r.push(...new ko(s,s,t).project()):!e||o!==0&&o!==a.length-1?r.push(...new He(s,l,c,t).project()):r.push(...new ko(s,o===0?c:l,t).project())}),r},fs=n=>{const t={};return Object.keys(n).forEach(e=>{t[e]={},Object.keys(n[e]).forEach(r=>{t[e][r]=v({},n[e][r])})}),t},Ic=n=>n.replace(/&/g,"&").replace(/"/g,""").replace(/'/g,"'").replace(/</g,"<").replace(/>/g,">");let gr;const ps=n=>{if(gr||gr||(gr="Intl"in wr()&&"Segmenter"in Intl&&new Intl.Segmenter(void 0,{granularity:"grapheme"})),gr){const t=gr.segment(n);return Array.from(t).map(e=>{let{segment:r}=e;return r})}return Hc(n)},Hc=n=>{const t=[];for(let e,r=0;r<n.length;r++)(e=zc(n,r))!==!1&&t.push(e);return t},zc=(n,t)=>{const e=n.charCodeAt(t);if(isNaN(e))return"";if(e<55296||e>57343)return n.charAt(t);if(55296<=e&&e<=56319){if(n.length<=t+1)throw"High surrogate without following low surrogate";const i=n.charCodeAt(t+1);if(56320>i||i>57343)throw"High surrogate without following low surrogate";return n.charAt(t)+n.charAt(t+1)}if(t===0)throw"Low surrogate without preceding high surrogate";const r=n.charCodeAt(t-1);if(55296>r||r>56319)throw"Low surrogate without preceding high surrogate";return!1},ms=function(n,t){let e=arguments.length>2&&arguments[2]!==void 0&&arguments[2];return n.fill!==t.fill||n.stroke!==t.stroke||n.strokeWidth!==t.strokeWidth||n.fontSize!==t.fontSize||n.fontFamily!==t.fontFamily||n.fontWeight!==t.fontWeight||n.fontStyle!==t.fontStyle||n.textDecorationThickness!==t.textDecorationThickness||n.textBackgroundColor!==t.textBackgroundColor||n.deltaY!==t.deltaY||e&&(n.overline!==t.overline||n.underline!==t.underline||n.linethrough!==t.linethrough)},Wc=(n,t)=>{const e=t.split(`
|
|
118
|
+
`),r=[];let i=-1,s={};n=fs(n);for(let o=0;o<e.length;o++){const a=ps(e[o]);if(n[o])for(let l=0;l<a.length;l++){i++;const c=n[o][l];c&&Object.keys(c).length>0&&(ms(s,c,!0)?r.push({start:i,end:i+1,style:c}):r[r.length-1].end++),s=c||{}}else i+=a.length,s={}}return r},Vc=(n,t)=>{if(!Array.isArray(n))return fs(n);const e=t.split(Ui),r={};let i=-1,s=0;for(let o=0;o<e.length;o++){const a=ps(e[o]);for(let l=0;l<a.length;l++)i++,n[s]&&n[s].start<=i&&i<n[s].end&&(r[o]=r[o]||{},r[o][l]=v({},n[s].style),i===n[s].end-1&&s++)}return r},de=["display","transform",at,"fill-opacity","fill-rule","opacity",_t,"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 Oo(n,t){const e=n.nodeName,r=n.getAttribute("class"),i=n.getAttribute("id"),s="(?![a-zA-Z\\-]+)";let o;if(o=new RegExp("^"+e,"i"),t=t.replace(o,""),i&&t.length&&(o=new RegExp("#"+i+s,"i"),t=t.replace(o,"")),r&&t.length){const a=r.split(" ");for(let l=a.length;l--;)o=new RegExp("\\."+a[l]+s,"i"),t=t.replace(o,"")}return t.length===0}function Xc(n,t){let e=!0;const r=Oo(n,t.pop());return r&&t.length&&(e=function(i,s){let o,a=!0;for(;i.parentElement&&i.parentElement.nodeType===1&&s.length;)a&&(o=s.pop()),a=Oo(i=i.parentElement,o);return s.length===0}(n,t)),r&&e&&t.length===0}const Yc=n=>{var t;return(t=rc[n])!==null&&t!==void 0?t:n},Uc=new RegExp("(".concat(Ht,")"),"gi"),Gc=n=>Hr(n.replace(Uc," $1 ").replace(/,/gi," "));var Do,Mo,Eo,Po,Ao,jo,Lo;const ft="(".concat(Ht,")"),Nc=String.raw(Do||(Do=Yt(["(skewX)(",")"],["(skewX)\\(","\\)"])),ft),$c=String.raw(Mo||(Mo=Yt(["(skewY)(",")"],["(skewY)\\(","\\)"])),ft),qc=String.raw(Eo||(Eo=Yt(["(rotate)(","(?: "," ",")?)"],["(rotate)\\(","(?: "," ",")?\\)"])),ft,ft,ft),Kc=String.raw(Po||(Po=Yt(["(scale)(","(?: ",")?)"],["(scale)\\(","(?: ",")?\\)"])),ft,ft),Zc=String.raw(Ao||(Ao=Yt(["(translate)(","(?: ",")?)"],["(translate)\\(","(?: ",")?\\)"])),ft,ft),Jc=String.raw(jo||(jo=Yt(["(matrix)("," "," "," "," "," ",")"],["(matrix)\\("," "," "," "," "," ","\\)"])),ft,ft,ft,ft,ft,ft),vs="(?:".concat(Jc,"|").concat(Zc,"|").concat(qc,"|").concat(Kc,"|").concat(Nc,"|").concat($c,")"),Qc="(?:".concat(vs,"*)"),th=String.raw(Lo||(Lo=Yt(["^s*(?:","?)s*$"],["^\\s*(?:","?)\\s*$"])),Qc),eh=new RegExp(th),rh=new RegExp(vs),ih=new RegExp(vs,"g");function bs(n){const t=[];if(!(n=Gc(n).replace(/\s*([()])\s*/gi,"$1"))||n&&!eh.test(n))return[...gt];for(const e of n.matchAll(ih)){const r=rh.exec(e[0]);if(!r)continue;let i=gt;const s=r.filter(f=>!!f),[,o,...a]=s,[l,c,h,u,d,g]=a.map(f=>parseFloat(f));switch(o){case"translate":i=ir(l,c);break;case Gi:i=Pe({angle:l},{x:c,y:h});break;case Or:i=Ki(l,c);break;case Oe:i=Ln(l);break;case De:i=Fn(l);break;case"matrix":i=[l,c,h,u,d,g]}t.push(i)}return qi(t)}function sh(n,t,e,r){const i=Array.isArray(t);let s,o=t;if(n!==at&&n!==_t||t!==bt){if(n==="strokeUniform")return t==="non-scaling-stroke";if(n==="strokeDashArray")o=t===bt?null:t.replace(/,/g," ").split(/\s+/).map(parseFloat);else if(n==="transformMatrix")o=e&&e.transformMatrix?ht(e.transformMatrix,bs(t)):bs(t);else if(n==="visible")o=t!==bt&&t!=="hidden",e&&e.visible===!1&&(o=!1);else if(n==="opacity")o=parseFloat(t),e&&e.opacity!==void 0&&(o*=e.opacity);else if(n==="textAnchor")o=t==="start"?U:t==="end"?it:W;else if(n==="charSpacing"||n===be)s=Le(t,r)/r*1e3;else if(n==="paintFirst"){const a=t.indexOf(at),l=t.indexOf(_t);o=at,(a>-1&&l>-1&&l<a||a===-1&&l>-1)&&(o=_t)}else{if(n==="href"||n==="xlink:href"||n==="font"||n==="id")return t;if(n==="imageSmoothing")return t==="optimizeQuality";s=i?t.map(Le):Le(t,r)}}else o="";return!i&&isNaN(s)?o:s}function nh(n,t){const e=n.match(ec);if(!e)return;const r=e[1],i=e[3],s=e[4],o=e[5],a=e[6];r&&(t.fontStyle=r),i&&(t.fontWeight=isNaN(parseFloat(i))?i:parseFloat(i)),s&&(t.fontSize=Le(s)),a&&(t.fontFamily=a),o&&(t.lineHeight=o==="normal"?1:o)}function oh(n,t){n.replace(/;\s*$/,"").split(";").forEach(e=>{if(!e)return;const[r,i]=e.split(":");t[r.trim().toLowerCase()]=i.trim()})}function ah(n){const t={},e=n.getAttribute("style");return e&&(typeof e=="string"?oh(e,t):function(r,i){Object.entries(r).forEach(s=>{let[o,a]=s;a!==void 0&&(i[o.toLowerCase()]=a)})}(e,t)),t}const lh={stroke:"strokeOpacity",fill:"fillOpacity"};function se(n,t,e){if(!n)return{};let r,i={},s=Xi;n.parentNode&&lo.test(n.parentNode.nodeName)&&(i=se(n.parentElement,t,e),i.fontSize&&(r=s=Le(i.fontSize)));const o=v(v(v({},t.reduce((c,h)=>{const u=n.getAttribute(h);return u&&(c[h]=u),c},{})),function(c){let h=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},u={};for(const d in h)Xc(c,d.split(" "))&&(u=v(v({},u),h[d]));return u}(n,e)),ah(n));o[ns]&&n.setAttribute(ns,o[ns]),o[ss]&&(r=Le(o[ss],s),o[ss]="".concat(r));const a={};for(const c in o){const h=Yc(c),u=sh(h,o[c],i,r);a[h]=u}a&&a.font&&nh(a.font,a);const l=v(v({},i),a);return lo.test(n.nodeName)?l:function(c){const h=ut.getDefaults();return Object.entries(lh).forEach(u=>{let[d,g]=u;if(c[g]===void 0||c[d]==="")return;if(c[d]===void 0){if(!h[d])return;c[d]=h[d]}if(c[d].indexOf("url(")===0)return;const f=new G(c[d]);c[d]=f.setAlpha(Z(f.getAlpha()*c[g],2)).toRgba()}),c}(l)}const ch=["left","top","width","height","visible"],Fo=["rx","ry"];class Tt extends ut{static getDefaults(){return v(v({},super.getDefaults()),Tt.ownDefaults)}constructor(t){super(),Object.assign(this,Tt.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:r}=this,i=-e/2,s=-r/2,o=this.rx?Math.min(this.rx,e/2):0,a=this.ry?Math.min(this.ry,r/2):0,l=o!==0||a!==0;t.beginPath(),t.moveTo(i+o,s),t.lineTo(i+e-o,s),l&&t.bezierCurveTo(i+e-he*o,s,i+e,s+he*a,i+e,s+a),t.lineTo(i+e,s+r-a),l&&t.bezierCurveTo(i+e,s+r-he*a,i+e-he*o,s+r,i+e-o,s+r),t.lineTo(i+o,s+r),l&&t.bezierCurveTo(i+he*o,s+r,i,s+r-he*a,i,s+r-a),t.lineTo(i,s+a),l&&t.bezierCurveTo(i,s+he*a,i+he*o,s,i+o,s),t.closePath(),this._renderPaintInOrder(t)}toObject(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:[];return super.toObject([...Fo,...t])}_toSVG(){const{width:t,height:e,rx:r,ry:i}=this;return["<rect ","COMMON_PARTS",'x="'.concat(-t/2,'" y="').concat(-e/2,'" rx="').concat(r,'" ry="').concat(i,'" width="').concat(t,'" height="').concat(e,`" />
|
|
119
|
+
`)]}static async fromElement(t,e,r){const i=se(t,this.ATTRIBUTE_NAMES,r),{left:s=0,top:o=0,width:a=0,height:l=0,visible:c=!0}=i,h=J(i,ch);return new this(v(v(v({},e),h),{},{left:s,top:o,width:a,height:l,visible:!!(c&&a&&l)}))}}p(Tt,"type","Rect"),p(Tt,"cacheProperties",[...re,...Fo]),p(Tt,"ownDefaults",{rx:0,ry:0}),p(Tt,"ATTRIBUTE_NAMES",[...de,"x","y","rx","ry","width","height"]),E.setClass(Tt),E.setSVGClass(Tt);const ne="initialization",Gr="added",ys="removed",Nr="imperative",Ro=(n,t)=>{const{strokeUniform:e,strokeWidth:r,width:i,height:s,group:o}=t,a=o&&o!==n?Br(o.calcTransformMatrix(),n.calcTransformMatrix()):null,l=a?t.getRelativeCenterPoint().transform(a):t.getRelativeCenterPoint(),c=!t.isStrokeAccountedForInDimensions(),h=e&&c?$l(new x(r,r),void 0,n.calcTransformMatrix()):$i,u=!e&&c?r:0,d=ts(i+u,s+u,qi([a,t.calcOwnMatrix()],!0)).add(h).scalarDivide(2);return[l.subtract(d),l.add(d)]};class $r{calcLayoutResult(t,e){if(this.shouldPerformLayout(t))return this.calcBoundingBox(e,t)}shouldPerformLayout(t){let{type:e,prevStrategy:r,strategy:i}=t;return e===ne||e===Nr||!!r&&i!==r}shouldLayoutClipPath(t){let{type:e,target:{clipPath:r}}=t;return e!==ne&&r&&!r.absolutePositioned}getInitialSize(t,e){return e.size}calcBoundingBox(t,e){const{type:r,target:i}=e;if(r===Nr&&e.overrides)return e.overrides;if(t.length===0)return;const{left:s,top:o,width:a,height:l}=ee(t.map(u=>Ro(i,u)).reduce((u,d)=>u.concat(d),[])),c=new x(a,l),h=new x(s,o).add(c.scalarDivide(2));if(r===ne){const u=this.getInitialSize(e,{size:c,center:h});return{center:h,relativeCorrection:new x(0,0),size:u}}return{center:h.transform(i.calcOwnMatrix()),size:c}}}p($r,"type","strategy");class _s extends $r{shouldPerformLayout(t){return!0}}p(_s,"type","fit-content"),E.setClass(_s);const hh=["strategy"],uh=["target","strategy","bubbles","prevStrategy"],Bo="layoutManager";class fr{constructor(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:new _s;p(this,"strategy",void 0),this.strategy=t,this._subscriptions=new Map}performLayout(t){const e=v(v({bubbles:!0,strategy:this.strategy},t),{},{prevStrategy:this._prevLayoutStrategy,stopPropagation(){this.bubbles=!1}});this.onBeforeLayout(e);const r=this.getLayoutResult(e);r&&this.commitLayout(e,r),this.onAfterLayout(e,r),this._prevLayoutStrategy=e.strategy}attachHandlers(t,e){const{target:r}=e;return[Dr,Tn,rr,kn,Tr,On,kr,jl,Ll].map(i=>t.on(i,s=>this.performLayout(i===Dr?{type:"object_modified",trigger:i,e:s,target:r}:{type:"object_modifying",trigger:i,e:s,target:r})))}subscribe(t,e){this.unsubscribe(t,e);const r=this.attachHandlers(t,e);this._subscriptions.set(t,r)}unsubscribe(t,e){(this._subscriptions.get(t)||[]).forEach(r=>r()),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:r}=t,{canvas:i}=e;if(r===ne||r===Gr?this.subscribeTargets(t):r===ys&&this.unsubscribeTargets(t),e.fire("layout:before",{context:t}),i&&i.fire("object:layout:before",{target:e,context:t}),r===Nr&&t.deep){const s=J(t,hh);e.forEachObject(o=>o.layoutManager&&o.layoutManager.performLayout(v(v({},s),{},{bubbles:!1,target:o})))}}getLayoutResult(t){const{target:e,strategy:r,type:i}=t,s=r.calcLayoutResult(t,e.getObjects());if(!s)return;const o=i===ne?new x:e.getRelativeCenterPoint(),{center:a,correction:l=new x,relativeCorrection:c=new x}=s,h=o.subtract(a).add(l).transform(i===ne?gt:Rt(e.calcOwnMatrix()),!0).add(c);return{result:s,prevCenter:o,nextCenter:a,offset:h}}commitLayout(t,e){const{target:r}=t,{result:{size:i},nextCenter:s}=e;var o,a;r.set({width:i.x,height:i.y}),this.layoutObjects(t,e),t.type===ne?r.set({left:(o=t.x)!==null&&o!==void 0?o:s.x+i.x*ot(r.originX),top:(a=t.y)!==null&&a!==void 0?a:s.y+i.y*ot(r.originY)}):(r.setPositionByOrigin(s,W,W),r.setCoords(),r.set("dirty",!0))}layoutObjects(t,e){const{target:r}=t;r.forEachObject(i=>{i.group===r&&this.layoutObject(t,e,i)}),t.strategy.shouldLayoutClipPath(t)&&this.layoutObject(t,e,r.clipPath)}layoutObject(t,e,r){let{offset:i}=e;r.set({left:r.left+i.x,top:r.top+i.y})}onAfterLayout(t,e){const{target:r,strategy:i,bubbles:s,prevStrategy:o}=t,a=J(t,uh),{canvas:l}=r;r.fire("layout:after",{context:t,result:e}),l&&l.fire("object:layout:after",{context:t,result:e,target:r});const c=r.parent;s&&c!=null&&c.layoutManager&&((a.path||(a.path=[])).push(r),c.layoutManager.performLayout(v(v({},a),{},{target:c}))),r.set("dirty",!0)}dispose(){const{_subscriptions:t}=this;t.forEach(e=>e.forEach(r=>r())),t.clear()}toObject(){return{type:Bo,strategy:this.strategy.constructor.type}}toJSON(){return this.toObject()}}E.setClass(fr,Bo);const dh=["type","objects","layoutManager"];class gh extends fr{performLayout(){}}class ye extends Dn(ut){static getDefaults(){return v(v({},super.getDefaults()),ye.ownDefaults)}constructor(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:[],e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};super(),p(this,"_activeObjects",[]),p(this,"__objectSelectionTracker",void 0),p(this,"__objectSelectionDisposer",void 0),Object.assign(this,ye.ownDefaults),this.setOptions(e),this.groupInit(t,e)}groupInit(t,e){var r;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=(r=e.layoutManager)!==null&&r!==void 0?r:new fr,this.layoutManager.performLayout({type:ne,target:this,targets:[...t],x:e.left,y:e.top})}canEnterGroup(t){return t===this||this.isDescendantOf(t)?(ce("error","Group: circular object trees are not supported, this call has no effect"),!1):this._objects.indexOf(t)===-1||(ce("error","Group: duplicate objects are not supported inside group, this call has no effect"),!1)}_filterObjectsBeforeEnteringGroup(t){return t.filter((e,r,i)=>this.canEnterGroup(e)&&i.indexOf(e)===r)}add(){for(var t=arguments.length,e=new Array(t),r=0;r<t;r++)e[r]=arguments[r];const i=this._filterObjectsBeforeEnteringGroup(e),s=super.add(...i);return this._onAfterObjectsChange(Gr,i),s}insertAt(t){for(var e=arguments.length,r=new Array(e>1?e-1:0),i=1;i<e;i++)r[i-1]=arguments[i];const s=this._filterObjectsBeforeEnteringGroup(r),o=super.insertAt(t,...s);return this._onAfterObjectsChange(Gr,s),o}remove(){const t=super.remove(...arguments);return this._onAfterObjectsChange(ys,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 r=this[t];return super._set(t,e),t==="canvas"&&r!==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:r}=e;const i=this._activeObjects;if(t)i.push(r),this._set("dirty",!0);else if(i.length>0){const s=i.indexOf(r);s>-1&&(i.splice(s,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&&Rr(t,ht(Rt(this.calcTransformMatrix()),t.calcTransformMatrix())),this._shouldSetNestedCoords()&&t.setCoords(),t._set("group",this),t._set("canvas",this.canvas),this._watchObject(!0,t);const r=this.canvas&&this.canvas.getActiveObject&&this.canvas.getActiveObject();r&&(r===t||t.isDescendantOf(r))&&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||(Rr(t,ht(this.calcTransformMatrix(),t.calcTransformMatrix())),t.setCoords()),this._watchObject(!1,t);const r=this._activeObjects.length>0?this._activeObjects.indexOf(t):-1;r>-1&&this._activeObjects.splice(r,1)}shouldCache(){const t=ut.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,r){this._renderBackground(t);for(let s=0;s<this._objects.length;s++){var i;const o=this._objects[s];(i=this.canvas)!==null&&i!==void 0&&i.preserveObjectStacking&&o.group!==this?(t.save(),t.transform(...Rt(this.calcTransformMatrix())),o.render(t),t.restore()):o.group===this&&o.render(t)}this._drawClipPath(t,this.clipPath,r)}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(v({target:this,type:Nr},t))}render(t){this._transformDone=!0,super.render(t),this._transformDone=!1}__serializeObjects(t,e){const r=this.includeDefaultValues;return this._objects.filter(function(i){return!i.excludeFromExport}).map(function(i){const s=i.includeDefaultValues;i.includeDefaultValues=r;const o=i[t||"toObject"](e);return i.includeDefaultValues=s,o})}toObject(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:[];const e=this.layoutManager.toObject();return v(v(v({},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=Tt.prototype._toSVG.call(this),r=e.indexOf("COMMON_PARTS");e[r]='for="group" ';const i=e.join("");return t?t(i):i}_toSVG(t){const e=["<g ","COMMON_PARTS",` >
|
|
120
|
+
`],r=this._createSVGBgRect(t);r&&e.push(" ",r);for(let i=0;i<this._objects.length;i++)e.push(" ",this._objects[i].toSVG(t));return e.push(`</g>
|
|
121
|
+
`),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=[],r=this._createSVGBgRect(t);r&&e.push(" ",r);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:r,objects:i=[],layoutManager:s}=t,o=J(t,dh);return Promise.all([sr(i,e),Fr(o,e)]).then(a=>{let[l,c]=a;const h=new this(l,v(v(v({},o),c),{},{layoutManager:new gh}));if(s){const u=E.getClass(s.type),d=E.getClass(s.strategy);h.layoutManager=new u(new d)}else h.layoutManager=new fr;return h.layoutManager.subscribeTargets({type:ne,target:h,targets:h.getObjects()}),h.setCoords(),h})}}p(ye,"type","Group"),p(ye,"ownDefaults",{strokeWidth:0,subTargetCheck:!1,interactive:!1}),E.setClass(ye);const fh=(n,t)=>Math.min(t.width/n.width,t.height/n.height),ph=(n,t)=>Math.max(t.width/n.width,t.height/n.height),xs="\\s*,?\\s*",pr="".concat(xs,"(").concat(Ht,")"),mh="".concat(pr).concat(pr).concat(pr).concat(xs,"([01])").concat(xs,"([01])").concat(pr).concat(pr),vh={m:"l",M:"L"},bh=(n,t,e,r,i,s,o,a,l,c,h)=>{const u=Zt(n),d=Jt(n),g=Zt(t),f=Jt(t),m=e*i*g-r*s*f+o,b=r*i*g+e*s*f+a;return["C",c+l*(-e*i*d-r*s*u),h+l*(-r*i*d+e*s*u),m+l*(e*i*f+r*s*g),b+l*(r*i*f-e*s*g),m,b]},Io=(n,t,e,r)=>{const i=Math.atan2(t,n),s=Math.atan2(r,e);return s>=i?s-i:2*Math.PI-(i-s)};function Ho(n,t,e,r,i,s,o,a){let l;if(X.cachesBoundsOfCurve&&(l=[...arguments].join(),tr.boundsOfCurveCache[l]))return tr.boundsOfCurveCache[l];const c=Math.sqrt,h=Math.abs,u=[],d=[[0,0],[0,0]];let g=6*n-12*e+6*i,f=-3*n+9*e-9*i+3*o,m=3*e-3*n;for(let k=0;k<2;++k){if(k>0&&(g=6*t-12*r+6*s,f=-3*t+9*r-9*s+3*a,m=3*r-3*t),h(f)<1e-12){if(h(g)<1e-12)continue;const L=-m/g;0<L&&L<1&&u.push(L);continue}const S=g*g-4*m*f;if(S<0)continue;const C=c(S),A=(-g+C)/(2*f);0<A&&A<1&&u.push(A);const D=(-g-C)/(2*f);0<D&&D<1&&u.push(D)}let b=u.length;const y=b,w=zo(n,t,e,r,i,s,o,a);for(;b--;){const{x:k,y:S}=w(u[b]);d[0][b]=k,d[1][b]=S}d[0][y]=n,d[1][y]=t,d[0][y+1]=o,d[1][y+1]=a;const O=[new x(Math.min(...d[0]),Math.min(...d[1])),new x(Math.max(...d[0]),Math.max(...d[1]))];return X.cachesBoundsOfCurve&&(tr.boundsOfCurveCache[l]=O),O}const yh=(n,t,e)=>{let[r,i,s,o,a,l,c,h]=e;const u=((d,g,f,m,b,y,w)=>{if(f===0||m===0)return[];let O=0,k=0,S=0;const C=Math.PI,A=w*Vi,D=Jt(A),L=Zt(A),R=.5*(-L*d-D*g),H=.5*(-L*g+D*d),I=f**2,M=m**2,j=H**2,z=R**2,V=I*M-I*j-M*z;let tt=Math.abs(f),N=Math.abs(m);if(V<0){const dt=Math.sqrt(1-V/(I*M));tt*=dt,N*=dt}else S=(b===y?-1:1)*Math.sqrt(V/(I*j+M*z));const Ct=S*tt*H/N,Mt=-S*N*R/tt,ct=L*Ct-D*Mt+.5*d,T=D*Ct+L*Mt+.5*g;let F=Io(1,0,(R-Ct)/tt,(H-Mt)/N),P=Io((R-Ct)/tt,(H-Mt)/N,(-R-Ct)/tt,(-H-Mt)/N);y===0&&P>0?P-=2*C:y===1&&P<0&&(P+=2*C);const B=Math.ceil(Math.abs(P/C*2)),$=[],q=P/B,mt=8/3*Math.sin(q/4)*Math.sin(q/4)/Math.sin(q/2);let le=F+q;for(let dt=0;dt<B;dt++)$[dt]=bh(F,le,L,D,tt,N,ct,T,mt,O,k),O=$[dt][5],k=$[dt][6],F=le,le+=q;return $})(c-n,h-t,i,s,a,l,o);for(let d=0,g=u.length;d<g;d++)u[d][1]+=n,u[d][2]+=t,u[d][3]+=n,u[d][4]+=t,u[d][5]+=n,u[d][6]+=t;return u},_h=n=>{let t=0,e=0,r=0,i=0;const s=[];let o,a=0,l=0;for(const c of n){const h=[...c];let u;switch(h[0]){case"l":h[1]+=t,h[2]+=e;case"L":t=h[1],e=h[2],u=["L",t,e];break;case"h":h[1]+=t;case"H":t=h[1],u=["L",t,e];break;case"v":h[1]+=e;case"V":e=h[1],u=["L",t,e];break;case"m":h[1]+=t,h[2]+=e;case"M":t=h[1],e=h[2],r=h[1],i=h[2],u=["M",t,e];break;case"c":h[1]+=t,h[2]+=e,h[3]+=t,h[4]+=e,h[5]+=t,h[6]+=e;case"C":a=h[3],l=h[4],t=h[5],e=h[6],u=["C",h[1],h[2],a,l,t,e];break;case"s":h[1]+=t,h[2]+=e,h[3]+=t,h[4]+=e;case"S":o==="C"?(a=2*t-a,l=2*e-l):(a=t,l=e),t=h[3],e=h[4],u=["C",a,l,h[1],h[2],t,e],a=u[3],l=u[4];break;case"q":h[1]+=t,h[2]+=e,h[3]+=t,h[4]+=e;case"Q":a=h[1],l=h[2],t=h[3],e=h[4],u=["Q",a,l,t,e];break;case"t":h[1]+=t,h[2]+=e;case"T":o==="Q"?(a=2*t-a,l=2*e-l):(a=t,l=e),t=h[1],e=h[2],u=["Q",a,l,t,e];break;case"a":h[6]+=t,h[7]+=e;case"A":yh(t,e,h).forEach(d=>s.push(d)),t=h[6],e=h[7];break;case"z":case"Z":t=r,e=i,u=["Z"]}u?(s.push(u),o=u[0]):o=""}return s},qr=(n,t,e,r)=>Math.sqrt((e-n)**2+(r-t)**2),zo=(n,t,e,r,i,s,o,a)=>l=>{const c=l**3,h=(g=>3*g**2*(1-g))(l),u=(g=>3*g*(1-g)**2)(l),d=(g=>(1-g)**3)(l);return new x(o*c+i*h+e*u+n*d,a*c+s*h+r*u+t*d)},Wo=n=>n**2,Vo=n=>2*n*(1-n),Xo=n=>(1-n)**2,xh=(n,t,e,r,i,s,o,a)=>l=>{const c=Wo(l),h=Vo(l),u=Xo(l),d=3*(u*(e-n)+h*(i-e)+c*(o-i)),g=3*(u*(r-t)+h*(s-r)+c*(a-s));return Math.atan2(g,d)},wh=(n,t,e,r,i,s)=>o=>{const a=Wo(o),l=Vo(o),c=Xo(o);return new x(i*a+e*l+n*c,s*a+r*l+t*c)},Ch=(n,t,e,r,i,s)=>o=>{const a=1-o,l=2*(a*(e-n)+o*(i-e)),c=2*(a*(r-t)+o*(s-r));return Math.atan2(c,l)},Yo=(n,t,e)=>{let r=new x(t,e),i=0;for(let s=1;s<=100;s+=1){const o=n(s/100);i+=qr(r.x,r.y,o.x,o.y),r=o}return i},Sh=(n,t)=>{let e,r=0,i=0,s={x:n.x,y:n.y},o=v({},s),a=.01,l=0;const c=n.iterator,h=n.angleFinder;for(;i<t&&a>1e-4;)o=c(r),l=r,e=qr(s.x,s.y,o.x,o.y),e+i>t?(r-=a,a/=2):(s=o,r+=a,i+=e);return v(v({},o),{},{angle:h(l)})},Uo=n=>{let t,e,r=0,i=0,s=0,o=0,a=0;const l=[];for(const c of n){const h={x:i,y:s,command:c[0],length:0};switch(c[0]){case"M":e=h,e.x=o=i=c[1],e.y=a=s=c[2];break;case"L":e=h,e.length=qr(i,s,c[1],c[2]),i=c[1],s=c[2];break;case"C":t=zo(i,s,c[1],c[2],c[3],c[4],c[5],c[6]),e=h,e.iterator=t,e.angleFinder=xh(i,s,c[1],c[2],c[3],c[4],c[5],c[6]),e.length=Yo(t,i,s),i=c[5],s=c[6];break;case"Q":t=wh(i,s,c[1],c[2],c[3],c[4]),e=h,e.iterator=t,e.angleFinder=Ch(i,s,c[1],c[2],c[3],c[4]),e.length=Yo(t,i,s),i=c[3],s=c[4];break;case"Z":e=h,e.destX=o,e.destY=a,e.length=qr(i,s,o,a),i=o,s=a}r+=e.length,l.push(e)}return l.push({length:r,x:i,y:s}),l},Th=function(n,t){let e=arguments.length>2&&arguments[2]!==void 0?arguments[2]:Uo(n),r=0;for(;t-e[r].length>0&&r<e.length-2;)t-=e[r].length,r++;const i=e[r],s=t/i.length,o=n[r];switch(i.command){case"M":return{x:i.x,y:i.y,angle:0};case"Z":return v(v({},new x(i.x,i.y).lerp(new x(i.destX,i.destY),s)),{},{angle:Math.atan2(i.destY-i.y,i.destX-i.x)});case"L":return v(v({},new x(i.x,i.y).lerp(new x(o[1],o[2]),s)),{},{angle:Math.atan2(o[2]-i.y,o[1]-i.x)});case"C":case"Q":return Sh(i,t)}},kh=new RegExp("[mzlhvcsqta][^mzlhvcsqta]*","gi"),Go=new RegExp(mh,"g"),Oh=new RegExp(Ht,"gi"),Dh={m:2,l:2,h:1,v:1,c:6,s:4,q:4,t:2,a:7},Mh=n=>{var t;const e=[],r=(t=n.match(kh))!==null&&t!==void 0?t:[];for(const i of r){const s=i[0];if(s==="z"||s==="Z"){e.push([s]);continue}const o=Dh[s.toLowerCase()];let a=[];if(s==="a"||s==="A"){Go.lastIndex=0;for(let l=null;l=Go.exec(i);)a.push(...l.slice(1))}else a=i.match(Oh)||[];for(let l=0;l<a.length;l+=o){const c=new Array(o),h=vh[s];c[0]=l>0&&h?h:s;for(let u=0;u<o;u++)c[u+1]=parseFloat(a[l+u]);e.push(c)}}return e},Eh=function(n){let t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:0,e=new x(n[0]),r=new x(n[1]),i=1,s=0;const o=[],a=n.length,l=a>2;let c;for(l&&(i=n[2].x<r.x?-1:n[2].x===r.x?0:1,s=n[2].y<r.y?-1:n[2].y===r.y?0:1),o.push(["M",e.x-i*t,e.y-s*t]),c=1;c<a;c++){if(!e.eq(r)){const h=e.midPointFrom(r);o.push(["Q",e.x,e.y,h.x,h.y])}e=n[c],c+1<n.length&&(r=n[c+1])}return l&&(i=e.x>n[c-2].x?1:e.x===n[c-2].x?0:-1,s=e.y>n[c-2].y?1:e.y===n[c-2].y?0:-1),o.push(["L",e.x+i*t,e.y+s*t]),o},No=(n,t)=>n.map(e=>e.map((r,i)=>i===0||t===void 0?r:Z(r,t)).join(" ")).join(" ");function ws(n,t){const e=n.style;e&&t&&(typeof t=="string"?e.cssText+=";"+t:Object.entries(t).forEach(r=>{let[i,s]=r;return e.setProperty(i,s)}))}class Ph extends Vn{constructor(t){let{allowTouchScrolling:e=!1,containerClass:r=""}=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};super(t),p(this,"upper",void 0),p(this,"container",void 0);const{el:i}=this.lower,s=this.createUpperCanvas();this.upper={el:s,ctx:s.getContext("2d")},this.applyCanvasStyle(i,{allowTouchScrolling:e}),this.applyCanvasStyle(s,{allowTouchScrolling:e,styles:{position:"absolute",left:"0",top:"0"}});const o=this.createContainerElement();o.classList.add(r),i.parentNode&&i.parentNode.replaceChild(o,i),o.append(i,s),this.container=o}createUpperCanvas(){const{el:t}=this.lower,e=Qt();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=ke().createElement("div");return t.setAttribute("data-fabric","wrapper"),ws(t,{position:"relative"}),Wn(t),t}applyCanvasStyle(t,e){const{styles:r,allowTouchScrolling:i}=e;ws(t,v(v({},r),{},{"touch-action":i?"manipulation":bt})),Wn(t)}setDimensions(t,e){super.setDimensions(t,e);const{el:r,ctx:i}=this.upper;zn(r,i,t,e)}setCSSDimensions(t){super.setCSSDimensions(t),Ji(this.upper.el,t),Ji(this.container,t)}cleanupDOM(t){const e=this.container,{el:r}=this.lower,{el:i}=this.upper;super.cleanupDOM(t),e.removeChild(i),e.removeChild(r),e.parentNode&&e.parentNode.replaceChild(r,e)}dispose(){super.dispose(),Gt().dispose(this.upper.el),delete this.upper,delete this.container}}class Kr extends or{constructor(){super(...arguments),p(this,"targets",[]),p(this,"_hoveredTargets",[]),p(this,"_currentTransform",null),p(this,"_groupSelector",null),p(this,"contextTopDirty",!1)}static getDefaults(){return v(v({},super.getDefaults()),Kr.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 Ph(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(),r=Math.ceil((2*t+1)*e);this.pixelFindCanvasEl.width=this.pixelFindCanvasEl.height=r,this.pixelFindContext.scale(e,e)}isTargetTransparent(t,e,r){const i=this.targetFindTolerance,s=this.pixelFindContext;this.clearContext(s),s.save(),s.translate(-e+i,-r+i),s.transform(...this.viewportTransform);const o=t.selectionBackgroundColor;t.selectionBackgroundColor="",t.render(s),t.selectionBackgroundColor=o,s.restore();const a=Math.round(i*this.getRetinaScaling());return Fc(s,a,a,a)}_isSelectionKeyPressed(t){const e=this.selectionKey;return!!e&&(Array.isArray(e)?!!e.find(r=>!!r&&t[r]===!0):t[e])}_shouldClearSelection(t,e){const r=this.getActiveObjects(),i=this._activeObject;return!!(!e||e&&i&&r.length>1&&r.indexOf(e)===-1&&i!==e&&!this._isSelectionKeyPressed(t)||e&&!e.evented||e&&!e.selectable&&i&&i!==e)}_shouldCenterTransform(t,e,r){if(!t)return;let i;return e===Or||e===yt||e===Pt||e===rr?i=this.centeredScaling||t.centeredScaling:e===Gi&&(i=this.centeredRotation||t.centeredRotation),i?!r:r}_getOriginFromCorner(t,e){const r={x:t.originX,y:t.originY};return e&&(["ml","tl","bl"].includes(e)?r.x=it:["mr","tr","br"].includes(e)&&(r.x=U),["tl","mt","tr"].includes(e)?r.y=Yi:["bl","mb","br"].includes(e)&&(r.y=vt)),r}_setupCurrentTransform(t,e,r){var i;const s=e.group?je(this.getScenePoint(t),void 0,e.group.calcTransformMatrix()):this.getScenePoint(t),{key:o="",control:a}=e.getActiveControl()||{},l=r&&a?(i=a.getActionHandler(t,e,a))===null||i===void 0?void 0:i.bind(a):Zl,c=((g,f,m,b)=>{if(!f||!g)return"drag";const y=b.controls[f];return y.getActionName(m,y,b)})(r,o,t,e),h=t[this.centeredKey],u=this._shouldCenterTransform(e,c,h)?{x:W,y:W}:this._getOriginFromCorner(e,o),d={target:e,action:c,actionHandler:l,actionPerformed:!1,corner:o,scaleX:e.scaleX,scaleY:e.scaleY,skewX:e.skewX,skewY:e.skewY,offsetX:s.x-e.left,offsetY:s.y-e.top,originX:u.x,originY:u.y,ex:s.x,ey:s.y,lastX:s.x,lastY:s.y,theta:st(e.angle),width:e.width,height:e.height,shiftKey:t.shiftKey,altKey:h,original:v(v({},Yn(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:r,deltaX:i,deltaY:s}=this._groupSelector,o=new x(e,r).transform(this.viewportTransform),a=new x(e+i,r+s).transform(this.viewportTransform),l=this.selectionLineWidth/2;let c=Math.min(o.x,a.x),h=Math.min(o.y,a.y),u=Math.max(o.x,a.x),d=Math.max(o.y,a.y);this.selectionColor&&(t.fillStyle=this.selectionColor,t.fillRect(c,h,u-c,d-h)),this.selectionLineWidth&&this.selectionBorderColor&&(t.lineWidth=this.selectionLineWidth,t.strokeStyle=this.selectionBorderColor,c+=l,h+=l,u-=l,d-=l,ut.prototype._setLineDash.call(this,t,this.selectionDashArray),t.strokeRect(c,h,u-c,d-h))}findTarget(t){if(this.skipTargetFind)return;const e=this.getViewportPoint(t),r=this._activeObject,i=this.getActiveObjects();if(this.targets=[],r&&i.length>=1){if(r.findControl(e,Qi(t))||i.length>1&&this.searchPossibleTargets([r],e))return r;if(r===this.searchPossibleTargets([r],e)){if(this.preserveObjectStacking){const s=this.targets;this.targets=[];const o=this.searchPossibleTargets(this._objects,e);return t[this.altSelectionKey]&&o&&o!==r?(this.targets=s,r):o}return r}}return this.searchPossibleTargets(this._objects,e)}_pointIsInObjectSelectionArea(t,e){let r=t.getCoords();const i=this.getZoom(),s=t.padding/i;if(s){const[o,a,l,c]=r,h=Math.atan2(a.y-o.y,a.x-o.x),u=Zt(h)*s,d=Jt(h)*s,g=u+d,f=u-d;r=[new x(o.x-f,o.y-g),new x(a.x+g,a.y-f),new x(l.x+f,l.y+g),new x(c.x-g,c.y+f)]}return Q.isPointInPolygon(e,r)}_checkTarget(t,e){return!!(t&&t.visible&&t.evented&&this._pointIsInObjectSelectionArea(t,je(e,void 0,this.viewportTransform))&&(!this.perPixelTargetFind&&!t.perPixelTargetFind||t.isEditing||!this.isTargetTransparent(t,e.x,e.y)))}_searchPossibleTargets(t,e){let r=t.length;for(;r--;){const i=t[r];if(this._checkTarget(i,e)){if(Er(i)&&i.subTargetCheck){const s=this._searchPossibleTargets(i._objects,e);s&&this.targets.push(s)}return i}}}searchPossibleTargets(t,e){const r=this._searchPossibleTargets(t,e);if(r&&Er(r)&&r.interactive&&this.targets[0]){const i=this.targets;for(let s=i.length-1;s>0;s--){const o=i[s];if(!Er(o)||!o.interactive)return o}return i[0]}return r}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 r=this.upperCanvasEl,i=r.getBoundingClientRect();let s=Yl(t),o=i.width||0,a=i.height||0;o&&a||(vt in i&&Yi in i&&(a=Math.abs(i.top-i.bottom)),it in i&&U in i&&(o=Math.abs(i.right-i.left))),this.calcOffset(),s.x=s.x-this._offset.left,s.y=s.y-this._offset.top,e||(s=je(s,void 0,this.viewportTransform));const l=this.getRetinaScaling();l!==1&&(s.x/=l,s.y/=l);const c=o===0||a===0?new x(1,1):new x(r.width/o,r.height/a);return s.multiply(c)}_setDimensionsImpl(t,e){this._resetTransformEventData(),super._setDimensionsImpl(t,e),this._isCurrentlyDrawing&&this.freeDrawingBrush&&this.freeDrawingBrush._setBrushStyles(this.contextTop)}_createCacheCanvas(){this.pixelFindCanvasEl=Qt(),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 ve(t)?t.getObjects():t?[t]:[]}_fireSelectionEvents(t,e){let r=!1,i=!1;const s=this.getActiveObjects(),o=[],a=[];t.forEach(l=>{s.includes(l)||(r=!0,l.fire("deselected",{e,target:l}),a.push(l))}),s.forEach(l=>{t.includes(l)||(r=!0,l.fire("selected",{e,target:l}),o.push(l))}),t.length>0&&s.length>0?(i=!0,r&&this.fire("selection:updated",{e,selected:o,deselected:a})):s.length>0?(i=!0,this.fire("selection:created",{e,selected:o})):t.length>0&&(i=!0,this.fire("selection:cleared",{e,deselected:a})),i&&(this._objectsToRender=void 0)}setActiveObject(t,e){const r=this.getActiveObjects(),i=this._setActiveObject(t,e);return this._fireSelectionEvents(r,e),i}_setActiveObject(t,e){const r=this._activeObject;return r!==t&&!(!this._discardActiveObject(e,t)&&this._activeObject)&&!t.onSelect({e})&&(this._activeObject=t,ve(t)&&r!==t&&t.set("canvas",this),t.setCoords(),!0)}_discardActiveObject(t,e){const r=this._activeObject;return!!r&&!r.onDeselect({e:t,object:e})&&(this._currentTransform&&this._currentTransform.target===r&&this.endCurrentTransform(t),ve(r)&&r===this._hoveredTarget&&(this._hoveredTarget=void 0),this._activeObject=void 0,!0)}discardActiveObject(t){const e=this.getActiveObjects(),r=this.getActiveObject();e.length&&this.fire("before:selection:cleared",{e:t,deselected:[r]});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,r=e.target,i={e:t,target:r,transform:e,action:e.action};r._scaling&&(r._scaling=!1),r.setCoords(),e.actionPerformed&&(this.fire("object:modified",i),r.fire(Dr,i))}setViewportTransform(t){super.setViewportTransform(t);const e=this._activeObject;e&&e.setCoords()}destroy(){const t=this._activeObject;ve(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,r){const i=this._realizeGroupTransformOnObject(t),s=super._toObject(t,e,r);return t.set(i),s}_realizeGroupTransformOnObject(t){const{group:e}=t;if(e&&ve(e)&&this._activeObject===e){const r=Ae(t,["angle","flipX","flipY",U,yt,Pt,Oe,De,vt]);return Gl(t,e.calcOwnMatrix()),r}return{}}_setSVGObject(t,e,r){const i=this._realizeGroupTransformOnObject(e);super._setSVGObject(t,e,r),e.set(i)}}p(Kr,"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 Ah{constructor(t){p(this,"targets",[]),p(this,"__disposer",void 0);const e=()=>{const{hiddenTextarea:i}=t.getActiveObject()||{};i&&i.focus()},r=t.upperCanvasEl;r.addEventListener("click",e),this.__disposer=()=>r.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),Ee(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 jh=["target","oldTarget","fireCanvas","e"],kt={passive:!1},ze=(n,t)=>{const e=n.getViewportPoint(t),r=n.getScenePoint(t);return{viewportPoint:e,scenePoint:r,pointer:e,absolutePointer:r}},ge=function(n){for(var t=arguments.length,e=new Array(t>1?t-1:0),r=1;r<t;r++)e[r-1]=arguments[r];return n.addEventListener(...e)},Lt=function(n){for(var t=arguments.length,e=new Array(t>1?t-1:0),r=1;r<t;r++)e[r-1]=arguments[r];return n.removeEventListener(...e)},Lh={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 Cs extends Kr{constructor(t){super(t,arguments.length>1&&arguments[1]!==void 0?arguments[1]:{}),p(this,"_isClick",void 0),p(this,"textEditingManager",new Ah(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(ge,"add")}_getEventPrefix(){return this.enablePointerEvents?"pointer":"mouse"}addOrRemove(t,e){const r=this.upperCanvasEl,i=this._getEventPrefix();t(Hn(r),"resize",this._onResize),t(r,i+"down",this._onMouseDown),t(r,"".concat(i,"move"),this._onMouseMove,kt),t(r,"".concat(i,"out"),this._onMouseOut),t(r,"".concat(i,"enter"),this._onMouseEnter),t(r,"wheel",this._onMouseWheel,{passive:!1}),t(r,"contextmenu",this._onContextMenu),t(r,"click",this._onClick),t(r,"dblclick",this._onClick),t(r,"dragstart",this._onDragStart),t(r,"dragend",this._onDragEnd),t(r,"dragover",this._onDragOver),t(r,"dragenter",this._onDragEnter),t(r,"dragleave",this._onDragLeave),t(r,"drop",this._onDrop),this.enablePointerEvents||t(r,"touchstart",this._onTouchStart,kt)}removeListeners(){this.addOrRemove(Lt,"remove");const t=this._getEventPrefix(),e=Bt(this.upperCanvasEl);Lt(e,"".concat(t,"up"),this._onMouseUp),Lt(e,"touchend",this._onTouchEnd,kt),Lt(e,"".concat(t,"move"),this._onMouseMove,kt),Lt(e,"touchmove",this._onMouseMove,kt),clearTimeout(this._willAddMouseDown)}_onMouseWheel(t){this.__onMouseWheel(t)}_onMouseOut(t){const e=this._hoveredTarget,r=v({e:t},ze(this,t));this.fire("mouse:out",v(v({},r),{},{target:e})),this._hoveredTarget=void 0,e&&e.fire("mouseout",v({},r)),this._hoveredTargets.forEach(i=>{this.fire("mouse:out",v(v({},r),{},{target:i})),i&&i.fire("mouseout",v({},r))}),this._hoveredTargets=[]}_onMouseEnter(t){this._currentTransform||this.findTarget(t)||(this.fire("mouse:over",v({e:t},ze(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 r={e:t,target:e};return this.fire("dragstart",r),e.fire("dragstart",r),void ge(this.upperCanvasEl,"drag",this._onDragProgress)}Xn(t)}_renderDragEffects(t,e,r){let i=!1;const s=this._dropTarget;s&&s!==e&&s!==r&&(s.clearContextTop(),i=!0),e==null||e.clearContextTop(),r!==e&&(r==null||r.clearContextTop());const o=this.contextTop;o.save(),o.transform(...this.viewportTransform),e&&(o.save(),e.transform(o),e.renderDragSourceEffect(t),o.restore(),i=!0),r&&(o.save(),r.transform(o),r.renderDropTargetEffect(t),o.restore(),i=!0),o.restore(),i&&(this.contextTopDirty=!0)}_onDragEnd(t){const e=!!t.dataTransfer&&t.dataTransfer.dropEffect!==bt,r=e?this._activeObject:void 0,i={e:t,target:this._dragSource,subTargets:this.targets,dragSource:this._dragSource,didDrop:e,dropTarget:r};Lt(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:r,targets:i}=this.findDragTargets(t),s=this._dragSource,o={e:t,target:r,subTargets:i,dragSource:s,canDrop:!1,dropTarget:void 0};let a;this.fire(e,o),this._fireEnterLeaveEvents(r,o),r&&(r.canDrop(t)&&(a=r),r.fire(e,o));for(let l=0;l<i.length;l++){const c=i[l];c.canDrop(t)&&(a=c),c.fire(e,o)}this._renderDragEffects(t,s,a),this._dropTarget=a}_onDragEnter(t){const{target:e,targets:r}=this.findDragTargets(t),i={e:t,target:e,subTargets:r,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:r}=this.findDragTargets(t),i=this._basicEventHandler("drop:before",v({e:t,target:e,subTargets:r,dragSource:this._dragSource},ze(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),r=this.targets||[],i=this._basicEventHandler("contextmenu:before",{e:t,target:e,subTargets:r});return this.stopContextMenu&&Xn(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 r=this._activeObject;this.mainTouchId===void 0&&(this.mainTouchId=this.getPointerId(t)),this.__onMouseDown(t),(this.isDrawingMode||r&&this._target===r)&&(e=!0),e&&t.preventDefault(),this._resetTransformEventData();const i=this.upperCanvasEl,s=this._getEventPrefix(),o=Bt(i);ge(o,"touchend",this._onTouchEnd,kt),e&&ge(o,"touchmove",this._onMouseMove,kt),Lt(i,"".concat(s,"down"),this._onMouseDown)}_onMouseDown(t){this.__onMouseDown(t),this._resetTransformEventData();const e=this.upperCanvasEl,r=this._getEventPrefix();Lt(e,"".concat(r,"move"),this._onMouseMove,kt);const i=Bt(e);ge(i,"".concat(r,"up"),this._onMouseUp),ge(i,"".concat(r,"move"),this._onMouseMove,kt)}_onTouchEnd(t){if(t.touches.length>0)return;this.__onMouseUp(t),this._resetTransformEventData(),delete this.mainTouchId;const e=this._getEventPrefix(),r=Bt(this.upperCanvasEl);Lt(r,"touchend",this._onTouchEnd,kt),Lt(r,"touchmove",this._onMouseMove,kt),this._willAddMouseDown&&clearTimeout(this._willAddMouseDown),this._willAddMouseDown=setTimeout(()=>{ge(this.upperCanvasEl,"".concat(e,"down"),this._onMouseDown),this._willAddMouseDown=0},400)}_onMouseUp(t){this.__onMouseUp(t),this._resetTransformEventData();const e=this.upperCanvasEl,r=this._getEventPrefix();if(this._isMainEvent(t)){const i=Bt(this.upperCanvasEl);Lt(i,"".concat(r,"up"),this._onMouseUp),Lt(i,"".concat(r,"move"),this._onMouseMove,kt),ge(e,"".concat(r,"move"),this._onMouseMove,kt)}}_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 r=this._currentTransform,i=this._isClick,s=this._target,{button:o}=t;if(o)return(this.fireMiddleClick&&o===1||this.fireRightClick&&o===2)&&this._handleEvent(t,"up"),void this._resetTransformEventData();if(this.isDrawingMode&&this._isCurrentlyDrawing)return void this._onMouseUpInDrawingMode(t);if(!this._isMainEvent(t))return;let a,l,c=!1;if(r&&(this._finalizeCurrentTransform(t),c=r.actionPerformed),!i){const h=s===this._activeObject;this.handleSelection(t),c||(c=this._shouldRender(s)||!h&&s===this._activeObject)}if(s){const h=s.findControl(this.getViewportPoint(t),Qi(t)),{key:u,control:d}=h||{};if(l=u,s.selectable&&s!==this._activeObject&&s.activeOn==="up")this.setActiveObject(s,t),c=!0;else if(d){const g=d.getMouseUpHandler(t,s,d);g&&(a=this.getScenePoint(t),g.call(d,t,r,a.x,a.y))}s.isMoving=!1}if(r&&(r.target!==s||r.corner!==l)){const h=r.target&&r.target.controls[r.corner],u=h&&h.getMouseUpHandler(t,r.target,h);a=a||this.getScenePoint(t),u&&u.call(h,t,r,a.x,a.y)}this._setCursorFromEvent(t,s),this._handleEvent(t,"up"),this._groupSelector=null,this._currentTransform=null,s&&(s.__corner=void 0),c?this.requestRenderAll():i||(e=this._activeObject)!==null&&e!==void 0&&e.isEditing||this.renderTop()}_basicEventHandler(t,e){const{target:r,subTargets:i=[]}=e;this.fire(t,e),r&&r.fire(t,e);for(let s=0;s<i.length;s++)i[s]!==r&&i[s].fire(t,e);return e}_handleEvent(t,e,r){const i=this._target,s=this.targets||[],o=v(v(v({e:t,target:i,subTargets:s},ze(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"?r:{});this.fire("mouse:".concat(e),o),i&&i.fire("mouse".concat(e),o);for(let a=0;a<s.length;a++)s[a]!==i&&s[a].fire("mouse".concat(e),o)}_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,r=!!e&&e===this._activeObject;const{button:i}=t;if(i)return(this.fireMiddleClick&&i===1||this.fireRightClick&&i===2)&&this._handleEvent(t,"down",{alreadySelected:r}),void this._resetTransformEventData();if(this.isDrawingMode)return void this._onMouseDownInDrawingMode(t);if(!this._isMainEvent(t)||this._currentTransform)return;let s=this._shouldRender(e),o=!1;if(this.handleMultiSelection(t,e)?(e=this._activeObject,o=!0,s=!0):this._shouldClearSelection(t,e)&&this.discardActiveObject(t),this.selection&&(!e||!e.selectable&&!e.isEditing&&e!==this._activeObject)){const a=this.getScenePoint(t);this._groupSelector={x:a.x,y:a.y,deltaY:0,deltaX:0}}if(r=!!e&&e===this._activeObject,e){e.selectable&&e.activeOn==="down"&&this.setActiveObject(e,t);const a=e.findControl(this.getViewportPoint(t),Qi(t));if(e===this._activeObject&&(a||!o)){this._setupCurrentTransform(t,e,r);const l=a?a.control:void 0,c=this.getScenePoint(t),h=l&&l.getMouseDownHandler(t,e,l);h&&h.call(l,t,this._currentTransform,c.x,c.y)}}s&&(this._objectsToRender=void 0),this._handleEvent(t,"down",{alreadySelected:r}),s&&this.requestRenderAll()}_resetTransformEventData(){this._target=this._pointer=this._absolutePointer=void 0}_cacheTransformEventData(t){this._resetTransformEventData(),this._pointer=this.getViewportPoint(t),this._absolutePointer=je(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 r=this.getScenePoint(t);e.deltaX=r.x-e.x,e.deltaY=r.y-e.y,this.renderTop()}else if(this._currentTransform)this._transformObject(t);else{const r=this.findTarget(t);this._setCursorFromEvent(t,r),this._fireOverOutEvents(t,r)}this.textEditingManager.onMouseMove(t),this._handleEvent(t,"move"),this._resetTransformEventData()}_fireOverOutEvents(t,e){const r=this._hoveredTarget,i=this._hoveredTargets,s=this.targets,o=Math.max(i.length,s.length);this.fireSyntheticInOutEvents("mouse",{e:t,target:e,oldTarget:r,fireCanvas:!0});for(let a=0;a<o;a++)s[a]===e||i[a]&&i[a]===r||this.fireSyntheticInOutEvents("mouse",{e:t,target:s[a],oldTarget:i[a]});this._hoveredTarget=e,this._hoveredTargets=this.targets.concat()}_fireEnterLeaveEvents(t,e){const r=this._draggedoverTarget,i=this._hoveredTargets,s=this.targets,o=Math.max(i.length,s.length);this.fireSyntheticInOutEvents("drag",v(v({},e),{},{target:t,oldTarget:r,fireCanvas:!0}));for(let a=0;a<o;a++)this.fireSyntheticInOutEvents("drag",v(v({},e),{},{target:s[a],oldTarget:i[a]}));this._draggedoverTarget=t}fireSyntheticInOutEvents(t,e){let{target:r,oldTarget:i,fireCanvas:s,e:o}=e,a=J(e,jh);const{targetIn:l,targetOut:c,canvasIn:h,canvasOut:u}=Lh[t],d=i!==r;if(i&&d){const g=v(v({},a),{},{e:o,target:i,nextTarget:r},ze(this,o));s&&this.fire(u,g),i.fire(c,g)}if(r&&d){const g=v(v({},a),{},{e:o,target:r,previousTarget:i},ze(this,o));s&&this.fire(h,g),r.fire(l,g)}}__onMouseWheel(t){this._cacheTransformEventData(t),this._handleEvent(t,"wheel"),this._resetTransformEventData()}_transformObject(t){const e=this.getScenePoint(t),r=this._currentTransform,i=r.target,s=i.group?je(e,void 0,i.group.calcTransformMatrix()):e;r.shiftKey=t.shiftKey,r.altKey=!!this.centeredKey&&t[this.centeredKey],this._performTransformAction(t,r,s),r.actionPerformed&&this.requestRenderAll()}_performTransformAction(t,e,r){const{action:i,actionHandler:s,target:o}=e,a=!!s&&s(t,e,r.x,r.y);a&&o.setCoords(),i==="drag"&&a&&(e.target.isMoving=!0,this.setCursor(e.target.moveCursor||this.moveCursor)),e.actionPerformed=e.actionPerformed||a}_setCursorFromEvent(t,e){if(!e)return void this.setCursor(this.defaultCursor);let r=e.hoverCursor||this.hoverCursor;const i=ve(this._activeObject)?this._activeObject:null,s=(!i||e.group!==i)&&e.findControl(this.getViewportPoint(t));if(s){const o=s.control;this.setCursor(o.cursorStyleHandler(t,o,e))}else e.subTargetCheck&&this.targets.concat().reverse().map(o=>{r=o.hoverCursor||r}),this.setCursor(r)}handleMultiSelection(t,e){const r=this._activeObject,i=ve(r);if(r&&this._isSelectionKeyPressed(t)&&this.selection&&e&&e.selectable&&(r!==e||i)&&(i||!e.isDescendantOf(r)&&!r.isDescendantOf(e))&&!e.onSelect({e:t})&&!r.getActiveControl()){if(i){const s=r.getObjects();if(e===r){const o=this.getViewportPoint(t);if(!(e=this.searchPossibleTargets(s,o)||this.searchPossibleTargets(this._objects,o))||!e.selectable)return!1}e.group===r?(r.remove(e),this._hoveredTarget=e,this._hoveredTargets=[...this.targets],r.size()===1&&this._setActiveObject(r.item(0),t)):(r.multiSelectAdd(e),this._hoveredTarget=r,this._hoveredTargets=[...this.targets]),this._fireSelectionEvents(s,t)}else{r.isEditing&&r.exitEditing();const s=new(E.getClass("ActiveSelection"))([],{canvas:this});s.multiSelectAdd(r,e),this._hoveredTarget=s,this._setActiveObject(s,t),this._fireSelectionEvents([r],t)}return!0}return!1}handleSelection(t){if(!this.selection||!this._groupSelector)return!1;const{x:e,y:r,deltaX:i,deltaY:s}=this._groupSelector,o=new x(e,r),a=o.add(new x(i,s)),l=o.min(a),c=o.max(a).subtract(l),h=this.collectObjects({left:l.x,top:l.y,width:c.x,height:c.y},{includeIntersecting:!this.selectionFullyContained}),u=o.eq(a)?h[0]?[h[0]]:[]:h.length>1?h.filter(d=>!d.onSelect({e:t})).reverse():h;if(u.length===1)this.setActiveObject(u[0],t);else if(u.length>1){const d=E.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:r}=this.elements;r.ctx=void 0;const i=super.toCanvasElement(t,e);return r.ctx=r.el.getContext("2d"),i}clear(){this.textEditingManager.clear(),super.clear()}destroy(){this.removeListeners(),this.textEditingManager.dispose(),super.destroy()}}const $o={x1:0,y1:0,x2:0,y2:0},Fh=v(v({},$o),{},{r1:0,r2:0}),We=(n,t)=>isNaN(n)&&typeof t=="number"?t:n;function qo(n){return n&&/%$/.test(n)&&Number.isFinite(parseFloat(n))}function Ko(n,t){const e=typeof n=="number"?n:typeof n=="string"?parseFloat(n)/(qo(n)?100:1):NaN;return Fe(0,We(e,t),1)}const Rh=/\s*;\s*/,Bh=/\s*:\s*/;function Ih(n,t){let e,r;const i=n.getAttribute("style");if(i){const o=i.split(Rh);o[o.length-1]===""&&o.pop();for(let a=o.length;a--;){const[l,c]=o[a].split(Bh).map(h=>h.trim());l==="stop-color"?e=c:l==="stop-opacity"&&(r=c)}}const s=new G(e||n.getAttribute("stop-color")||"rgb(0,0,0)");return{offset:Ko(n.getAttribute("offset"),0),color:s.toRgb(),opacity:We(parseFloat(r||n.getAttribute("stop-opacity")||""),1)*s.getAlpha()*t}}function Hh(n,t){const e=[],r=n.getElementsByTagName("stop"),i=Ko(t,1);for(let s=r.length;s--;)e.push(Ih(r[s],i));return e}function Zo(n){return n.nodeName==="linearGradient"||n.nodeName==="LINEARGRADIENT"?"linear":"radial"}function Jo(n){return n.getAttribute("gradientUnits")==="userSpaceOnUse"?"pixels":"percentage"}function Wt(n,t){return n.getAttribute(t)}function zh(n,t){return function(e,r){let i,{width:s,height:o,gradientUnits:a}=r;return Object.entries(e).reduce((l,c)=>{let[h,u]=c;if(u==="Infinity")i=1;else if(u==="-Infinity")i=0;else{const d=typeof u=="string";i=d?parseFloat(u):u,d&&qo(u)&&(i*=.01,a==="pixels"&&(h!=="x1"&&h!=="x2"&&h!=="r2"||(i*=s),h!=="y1"&&h!=="y2"||(i*=o)))}return l[h]=i,l},{})}(Zo(n)==="linear"?function(e){return{x1:Wt(e,"x1")||0,y1:Wt(e,"y1")||0,x2:Wt(e,"x2")||"100%",y2:Wt(e,"y2")||0}}(n):function(e){return{x1:Wt(e,"fx")||Wt(e,"cx")||"50%",y1:Wt(e,"fy")||Wt(e,"cy")||"50%",r1:0,x2:Wt(e,"cx")||"50%",y2:Wt(e,"cy")||"50%",r2:Wt(e,"r")||"50%"}}(n),v(v({},t),{},{gradientUnits:Jo(n)}))}class Zr{constructor(t){const{type:e="linear",gradientUnits:r="pixels",coords:i={},colorStops:s=[],offsetX:o=0,offsetY:a=0,gradientTransform:l,id:c}=t||{};Object.assign(this,{type:e,gradientUnits:r,coords:v(v({},e==="radial"?Fh:$o),i),colorStops:s,offsetX:o,offsetY:a,gradientTransform:l,id:c?"".concat(c,"_").concat(ue()):ue()})}addColorStop(t){for(const e in t){const r=new G(t[e]);this.colorStops.push({offset:parseFloat(e),color:r.toRgb(),opacity:r.getAlpha()})}return this}toObject(t){return v(v({},Ae(this,t)),{},{type:this.type,coords:v({},this.coords),colorStops:this.colorStops.map(e=>v({},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 r=[],i=this.gradientTransform?this.gradientTransform.concat():gt.concat(),s=this.gradientUnits==="pixels"?"userSpaceOnUse":"objectBoundingBox",o=this.colorStops.map(u=>v({},u)).sort((u,d)=>u.offset-d.offset);let a=-this.offsetX,l=-this.offsetY;var c;s==="objectBoundingBox"?(a/=t.width,l/=t.height):(a+=t.width/2,l+=t.height/2),(c=t)&&typeof c._renderPathCommands=="function"&&this.gradientUnits!=="percentage"&&(a-=t.pathOffset.x,l-=t.pathOffset.y),i[4]-=a,i[5]-=l;const h=['id="SVGID_'.concat(this.id,'"'),'gradientUnits="'.concat(s,'"'),'gradientTransform="'.concat(e?e+" ":"").concat(nr(i),'"'),""].join(" ");if(this.type==="linear"){const{x1:u,y1:d,x2:g,y2:f}=this.coords;r.push("<linearGradient ",h,' x1="',u,'" y1="',d,'" x2="',g,'" y2="',f,`">
|
|
122
|
+
`)}else if(this.type==="radial"){const{x1:u,y1:d,x2:g,y2:f,r1:m,r2:b}=this.coords,y=m>b;r.push("<radialGradient ",h,' cx="',y?u:g,'" cy="',y?d:f,'" r="',y?m:b,'" fx="',y?g:u,'" fy="',y?f:d,`">
|
|
123
|
+
`),y&&(o.reverse(),o.forEach(O=>{O.offset=1-O.offset}));const w=Math.min(m,b);if(w>0){const O=w/Math.max(m,b);o.forEach(k=>{k.offset+=O*(1-k.offset)})}}return o.forEach(u=>{let{color:d,offset:g,opacity:f}=u;r.push("<stop ",'offset="',100*g+"%",'" style="stop-color:',d,f!==void 0?";stop-opacity: "+f:";",`"/>
|
|
124
|
+
`)}),r.push(this.type==="linear"?"</linearGradient>":"</radialGradient>",`
|
|
125
|
+
`),r.join("")}toLive(t){const{x1:e,y1:r,x2:i,y2:s,r1:o,r2:a}=this.coords,l=this.type==="linear"?t.createLinearGradient(e,r,i,s):t.createRadialGradient(e,r,o,i,s,a);return this.colorStops.forEach(c=>{let{color:h,opacity:u,offset:d}=c;l.addColorStop(d,u!==void 0?new G(h).setAlpha(u).toRgba():h)}),l}static async fromObject(t){const{colorStops:e,gradientTransform:r}=t;return new this(v(v({},t),{},{colorStops:e?e.map(i=>v({},i)):void 0,gradientTransform:r?[...r]:void 0}))}static fromElement(t,e,r){const i=Jo(t),s=e._findCenterFromElement();return new this(v({id:t.getAttribute("id")||void 0,type:Zo(t),coords:zh(t,{width:r.viewBoxWidth||r.width,height:r.viewBoxHeight||r.height}),colorStops:Hh(t,r.opacity),gradientUnits:i,gradientTransform:bs(t.getAttribute("gradientTransform")||"")},i==="pixels"?{offsetX:e.width/2-s.x,offsetY:e.height/2-s.y}:{offsetX:0,offsetY:0}))}}p(Zr,"type","Gradient"),E.setClass(Zr,"gradient"),E.setClass(Zr,"linear"),E.setClass(Zr,"radial");const Wh=["type","source","patternTransform"];class Ss{get type(){return"pattern"}set type(t){ce("warn","Setting type has no effect",t)}constructor(t){p(this,"repeat","repeat"),p(this,"offsetX",0),p(this,"offsetY",0),p(this,"crossOrigin",""),this.id=ue(),Object.assign(this,t)}isImageSource(){return!!this.source&&typeof this.source.src=="string"}isCanvasSource(){return!!this.source&&!!this.source.toDataURL}sourceToString(){return this.isImageSource()?this.source.src:this.isCanvasSource()?this.source.toDataURL():""}toLive(t){return this.source&&(!this.isImageSource()||this.source.complete&&this.source.naturalWidth!==0&&this.source.naturalHeight!==0)?t.createPattern(this.source,this.repeat):null}toObject(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:[];const{repeat:e,crossOrigin:r}=this;return v(v({},Ae(this,t)),{},{type:"pattern",source:this.sourceToString(),repeat:e,crossOrigin:r,offsetX:Z(this.offsetX,X.NUM_FRACTION_DIGITS),offsetY:Z(this.offsetY,X.NUM_FRACTION_DIGITS),patternTransform:this.patternTransform?[...this.patternTransform]:null})}toSVG(t){let{width:e,height:r}=t;const{source:i,repeat:s,id:o}=this,a=We(this.offsetX/e,0),l=We(this.offsetY/r,0),c=s==="repeat-y"||s==="no-repeat"?1+Math.abs(a||0):We(i.width/e,0),h=s==="repeat-x"||s==="no-repeat"?1+Math.abs(l||0):We(i.height/r,0);return['<pattern id="SVGID_'.concat(o,'" x="').concat(a,'" y="').concat(l,'" width="').concat(c,'" height="').concat(h,'">'),'<image x="0" y="0" width="'.concat(i.width,'" height="').concat(i.height,'" xlink:href="').concat(this.sourceToString(),'"></image>'),"</pattern>",""].join(`
|
|
126
|
+
`)}static async fromObject(t,e){let{type:r,source:i,patternTransform:s}=t,o=J(t,Wh);const a=await Lr(i,v(v({},e),{},{crossOrigin:o.crossOrigin}));return new this(v(v({},o),{},{patternTransform:s&&s.slice(0),source:a}))}}p(Ss,"type","Pattern"),E.setClass(Ss),E.setClass(Ss,"pattern");class Vh{constructor(t){p(this,"color","rgb(0, 0, 0)"),p(this,"width",1),p(this,"shadow",null),p(this,"strokeLineCap","round"),p(this,"strokeLineJoin","round"),p(this,"strokeMiterLimit",10),p(this,"strokeDashArray",null),p(this,"limitedToCanvasSize",!1),this.canvas=t}_setBrushStyles(t){t.strokeStyle=this.color,t.lineWidth=this.width,t.lineCap=this.strokeLineCap,t.miterLimit=this.strokeMiterLimit,t.lineJoin=this.strokeLineJoin,t.setLineDash(this.strokeDashArray||[])}_saveAndTransform(t){const e=this.canvas.viewportTransform;t.save(),t.transform(e[0],e[1],e[2],e[3],e[4],e[5])}needsFullRender(){return new G(this.color).getAlpha()<1||!!this.shadow}_setShadow(){if(!this.shadow||!this.canvas)return;const t=this.canvas,e=this.shadow,r=t.contextTop,i=t.getZoom()*t.getRetinaScaling();r.shadowColor=e.color,r.shadowBlur=e.blur*i,r.shadowOffsetX=e.offsetX*i,r.shadowOffsetY=e.offsetY*i}_resetShadow(){const t=this.canvas.contextTop;t.shadowColor="",t.shadowBlur=t.shadowOffsetX=t.shadowOffsetY=0}_isOutSideCanvas(t){return t.x<0||t.x>this.canvas.getWidth()||t.y<0||t.y>this.canvas.getHeight()}}const Xh=["path","left","top"],Yh=["d"];class fe extends ut{constructor(t){let e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},{path:r,left:i,top:s}=e,o=J(e,Xh);super(),Object.assign(this,fe.ownDefaults),this.setOptions(o),this._setPath(t||[],!0),typeof i=="number"&&this.set(U,i),typeof s=="number"&&this.set(vt,s)}_setPath(t,e){this.path=_h(Array.isArray(t)?t:Mh(t)),this.setBoundingBox(e)}_findCenterFromElement(){const t=this._calcBoundsFromPath();return new x(t.left+t.width/2,t.top+t.height/2)}_renderPathCommands(t){const e=-this.pathOffset.x,r=-this.pathOffset.y;t.beginPath();for(const i of this.path)switch(i[0]){case"L":t.lineTo(i[1]+e,i[2]+r);break;case"M":t.moveTo(i[1]+e,i[2]+r);break;case"C":t.bezierCurveTo(i[1]+e,i[2]+r,i[3]+e,i[4]+r,i[5]+e,i[6]+r);break;case"Q":t.quadraticCurveTo(i[1]+e,i[2]+r,i[3]+e,i[4]+r);break;case"Z":t.closePath()}}_render(t){this._renderPathCommands(t),this._renderPaintInOrder(t)}toString(){return"#<Path (".concat(this.complexity(),'): { "top": ').concat(this.top,', "left": ').concat(this.left," }>")}toObject(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:[];return v(v({},super.toObject(t)),{},{path:this.path.map(e=>e.slice())})}toDatalessObject(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:[];const e=this.toObject(t);return this.sourcePath&&(delete e.path,e.sourcePath=this.sourcePath),e}_toSVG(){const t=No(this.path,X.NUM_FRACTION_DIGITS);return["<path ","COMMON_PARTS",'d="'.concat(t,`" stroke-linecap="round" />
|
|
127
|
+
`)]}_getOffsetTransform(){const t=X.NUM_FRACTION_DIGITS;return" translate(".concat(Z(-this.pathOffset.x,t),", ").concat(Z(-this.pathOffset.y,t),")")}toClipPathSVG(t){const e=this._getOffsetTransform();return" "+this._createBaseClipPathSVGMarkup(this._toSVG(),{reviver:t,additionalTransform:e})}toSVG(t){const e=this._getOffsetTransform();return this._createBaseSVGMarkup(this._toSVG(),{reviver:t,additionalTransform:e})}complexity(){return this.path.length}setDimensions(){this.setBoundingBox()}setBoundingBox(t){const{width:e,height:r,pathOffset:i}=this._calcDimensions();this.set({width:e,height:r,pathOffset:i}),t&&this.setPositionByOrigin(i,W,W)}_calcBoundsFromPath(){const t=[];let e=0,r=0,i=0,s=0;for(const o of this.path)switch(o[0]){case"L":i=o[1],s=o[2],t.push({x:e,y:r},{x:i,y:s});break;case"M":i=o[1],s=o[2],e=i,r=s;break;case"C":t.push(...Ho(i,s,o[1],o[2],o[3],o[4],o[5],o[6])),i=o[5],s=o[6];break;case"Q":t.push(...Ho(i,s,o[1],o[2],o[1],o[2],o[3],o[4])),i=o[3],s=o[4];break;case"Z":i=e,s=r}return ee(t)}_calcDimensions(){const t=this._calcBoundsFromPath();return v(v({},t),{},{pathOffset:new x(t.left+t.width/2,t.top+t.height/2)})}static fromObject(t){return this._fromObject(t,{extraParam:"path"})}static async fromElement(t,e,r){const i=se(t,this.ATTRIBUTE_NAMES,r),{d:s}=i;return new this(s,v(v(v({},J(i,Yh)),e),{},{left:void 0,top:void 0}))}}p(fe,"type","Path"),p(fe,"cacheProperties",[...re,"path","fillRule"]),p(fe,"ATTRIBUTE_NAMES",[...de,"d"]),E.setClass(fe),E.setSVGClass(fe);class Jr extends Vh{constructor(t){super(t),p(this,"decimate",.4),p(this,"drawStraightLine",!1),p(this,"straightLineKey","shiftKey"),this._points=[],this._hasStraightLine=!1}needsFullRender(){return super.needsFullRender()||this._hasStraightLine}static drawSegment(t,e,r){const i=e.midPointFrom(r);return t.quadraticCurveTo(e.x,e.y,i.x,i.y),i}onMouseDown(t,e){let{e:r}=e;this.canvas._isMainEvent(r)&&(this.drawStraightLine=!!this.straightLineKey&&r[this.straightLineKey],this._prepareForDrawing(t),this._addPoint(t),this._render())}onMouseMove(t,e){let{e:r}=e;if(this.canvas._isMainEvent(r)&&(this.drawStraightLine=!!this.straightLineKey&&r[this.straightLineKey],(this.limitedToCanvasSize!==!0||!this._isOutSideCanvas(t))&&this._addPoint(t)&&this._points.length>1))if(this.needsFullRender())this.canvas.clearContext(this.canvas.contextTop),this._render();else{const i=this._points,s=i.length,o=this.canvas.contextTop;this._saveAndTransform(o),this.oldEnd&&(o.beginPath(),o.moveTo(this.oldEnd.x,this.oldEnd.y)),this.oldEnd=Jr.drawSegment(o,i[s-2],i[s-1]),o.stroke(),o.restore()}}onMouseUp(t){let{e}=t;return!this.canvas._isMainEvent(e)||(this.drawStraightLine=!1,this.oldEnd=void 0,this._finalizeAndAddPath(),!1)}_prepareForDrawing(t){this._reset(),this._addPoint(t),this.canvas.contextTop.moveTo(t.x,t.y)}_addPoint(t){return!(this._points.length>1&&t.eq(this._points[this._points.length-1]))&&(this.drawStraightLine&&this._points.length>1&&(this._hasStraightLine=!0,this._points.pop()),this._points.push(t),!0)}_reset(){this._points=[],this._setBrushStyles(this.canvas.contextTop),this._setShadow(),this._hasStraightLine=!1}_render(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:this.canvas.contextTop,e=this._points[0],r=this._points[1];if(this._saveAndTransform(t),t.beginPath(),this._points.length===2&&e.x===r.x&&e.y===r.y){const i=this.width/1e3;e.x-=i,r.x+=i}t.moveTo(e.x,e.y);for(let i=1;i<this._points.length;i++)Jr.drawSegment(t,e,r),e=this._points[i],r=this._points[i+1];t.lineTo(e.x,e.y),t.stroke(),t.restore()}convertPointsToSVGPath(t){const e=this.width/1e3;return Eh(t,e)}createPath(t){const e=new fe(t,{fill:null,stroke:this.color,strokeWidth:this.width,strokeLineCap:this.strokeLineCap,strokeMiterLimit:this.strokeMiterLimit,strokeLineJoin:this.strokeLineJoin,strokeDashArray:this.strokeDashArray});return this.shadow&&(this.shadow.affectStroke=!0,e.shadow=new $t(this.shadow)),e}decimatePoints(t,e){if(t.length<=2)return t;let r,i=t[0];const s=this.canvas.getZoom(),o=Math.pow(e/s,2),a=t.length-1,l=[i];for(let c=1;c<a-1;c++)r=Math.pow(i.x-t[c].x,2)+Math.pow(i.y-t[c].y,2),r>=o&&(i=t[c],l.push(i));return l.push(t[a]),l}_finalizeAndAddPath(){this.canvas.contextTop.closePath(),this.decimate&&(this._points=this.decimatePoints(this._points,this.decimate));const t=this.convertPointsToSVGPath(this._points);if(function(r){return No(r)==="M 0 0 Q 0 0 0 0 L 0 0"}(t))return void this.canvas.requestRenderAll();const e=this.createPath(t);this.canvas.clearContext(this.canvas.contextTop),this.canvas.fire("before:path:created",{path:e}),this.canvas.add(e),this.canvas.requestRenderAll(),e.setCoords(),this._resetShadow(),this.canvas.fire("path:created",{path:e})}}const Uh=["left","top","radius"],Qo=["radius","startAngle","endAngle","counterClockwise"];class oe extends ut{static getDefaults(){return v(v({},super.getDefaults()),oe.ownDefaults)}constructor(t){super(),Object.assign(this,oe.ownDefaults),this.setOptions(t)}_set(t,e){return super._set(t,e),t==="radius"&&this.setRadius(e),this}_render(t){t.beginPath(),t.arc(0,0,this.radius,st(this.startAngle),st(this.endAngle),this.counterClockwise),this._renderPaintInOrder(t)}getRadiusX(){return this.get("radius")*this.get(yt)}getRadiusY(){return this.get("radius")*this.get(Pt)}setRadius(t){this.radius=t,this.set({width:2*t,height:2*t})}toObject(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:[];return super.toObject([...Qo,...t])}_toSVG(){const t=(this.endAngle-this.startAngle)%360;if(t===0)return["<circle ","COMMON_PARTS",'cx="0" cy="0" ','r="',"".concat(this.radius),`" />
|
|
128
|
+
`];{const{radius:e}=this,r=st(this.startAngle),i=st(this.endAngle),s=Zt(r)*e,o=Jt(r)*e,a=Zt(i)*e,l=Jt(i)*e,c=t>180?1:0,h=this.counterClockwise?0:1;return['<path d="M '.concat(s," ").concat(o," A ").concat(e," ").concat(e," 0 ").concat(c," ").concat(h," ").concat(a," ").concat(l,'" '),"COMMON_PARTS",` />
|
|
129
|
+
`]}}static async fromElement(t,e,r){const i=se(t,this.ATTRIBUTE_NAMES,r),{left:s=0,top:o=0,radius:a=0}=i;return new this(v(v({},J(i,Uh)),{},{radius:a,left:s-a,top:o-a}))}static fromObject(t){return super._fromObject(t)}}p(oe,"type","Circle"),p(oe,"cacheProperties",[...re,...Qo]),p(oe,"ownDefaults",{radius:0,startAngle:0,endAngle:360,counterClockwise:!1}),p(oe,"ATTRIBUTE_NAMES",["cx","cy","r",...de]),E.setClass(oe),E.setSVGClass(oe);const Gh=["x1","y1","x2","y2"],Nh=["x1","y1","x2","y2"],Ts=["x1","x2","y1","y2"];class ae extends ut{constructor(){let[t,e,r,i]=arguments.length>0&&arguments[0]!==void 0?arguments[0]:[0,0,0,0],s=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};super(),Object.assign(this,ae.ownDefaults),this.setOptions(s),this.x1=t,this.x2=r,this.y1=e,this.y2=i,this._setWidthHeight();const{left:o,top:a}=s;typeof o=="number"&&this.set(U,o),typeof a=="number"&&this.set(vt,a)}_setWidthHeight(){const{x1:t,y1:e,x2:r,y2:i}=this;this.width=Math.abs(r-t),this.height=Math.abs(i-e);const{left:s,top:o,width:a,height:l}=ee([{x:t,y:e},{x:r,y:i}]),c=new x(s+a/2,o+l/2);this.setPositionByOrigin(c,W,W)}_set(t,e){return super._set(t,e),Ts.includes(t)&&this._setWidthHeight(),this}_render(t){t.beginPath();const e=this.calcLinePoints();t.moveTo(e.x1,e.y1),t.lineTo(e.x2,e.y2),t.lineWidth=this.strokeWidth;const r=t.strokeStyle;var i;jt(this.stroke)?t.strokeStyle=this.stroke.toLive(t):t.strokeStyle=(i=this.stroke)!==null&&i!==void 0?i:t.fillStyle,this.stroke&&this._renderStroke(t),t.strokeStyle=r}_findCenterFromElement(){return new x((this.x1+this.x2)/2,(this.y1+this.y2)/2)}toObject(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:[];return v(v({},super.toObject(t)),this.calcLinePoints())}_getNonTransformedDimensions(){const t=super._getNonTransformedDimensions();return this.strokeLineCap==="butt"&&(this.width===0&&(t.y-=this.strokeWidth),this.height===0&&(t.x-=this.strokeWidth)),t}calcLinePoints(){const{x1:t,x2:e,y1:r,y2:i,width:s,height:o}=this,a=t<=e?-1:1,l=r<=i?-1:1;return{x1:a*s/2,x2:a*-s/2,y1:l*o/2,y2:l*-o/2}}_toSVG(){const{x1:t,x2:e,y1:r,y2:i}=this.calcLinePoints();return["<line ","COMMON_PARTS",'x1="'.concat(t,'" y1="').concat(r,'" x2="').concat(e,'" y2="').concat(i,`" />
|
|
130
|
+
`)]}static async fromElement(t,e,r){const i=se(t,this.ATTRIBUTE_NAMES,r),{x1:s=0,y1:o=0,x2:a=0,y2:l=0}=i;return new this([s,o,a,l],J(i,Gh))}static fromObject(t){let{x1:e,y1:r,x2:i,y2:s}=t,o=J(t,Nh);return this._fromObject(v(v({},o),{},{points:[e,r,i,s]}),{extraParam:"points"})}}p(ae,"type","Line"),p(ae,"cacheProperties",[...re,...Ts]),p(ae,"ATTRIBUTE_NAMES",de.concat(Ts)),E.setClass(ae),E.setSVGClass(ae);class _e extends ut{static getDefaults(){return v(v({},super.getDefaults()),_e.ownDefaults)}constructor(t){super(),Object.assign(this,_e.ownDefaults),this.setOptions(t)}_render(t){const e=this.width/2,r=this.height/2;t.beginPath(),t.moveTo(-e,r),t.lineTo(0,-r),t.lineTo(e,r),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),'" />']}}p(_e,"type","Triangle"),p(_e,"ownDefaults",{width:100,height:100}),E.setClass(_e),E.setSVGClass(_e);const ta=["rx","ry"];class Vt extends ut{static getDefaults(){return v(v({},super.getDefaults()),Vt.ownDefaults)}constructor(t){super(),Object.assign(this,Vt.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(yt)}getRy(){return this.get("ry")*this.get(Pt)}toObject(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:[];return super.toObject([...ta,...t])}_toSVG(){return["<ellipse ","COMMON_PARTS",'cx="0" cy="0" rx="'.concat(this.rx,'" ry="').concat(this.ry,`" />
|
|
131
|
+
`)]}_render(t){t.beginPath(),t.save(),t.transform(1,0,0,this.ry/this.rx,0,0),t.arc(0,0,this.rx,0,Sr,!1),t.restore(),this._renderPaintInOrder(t)}static async fromElement(t,e,r){const i=se(t,this.ATTRIBUTE_NAMES,r);return i.left=(i.left||0)-i.rx,i.top=(i.top||0)-i.ry,new this(i)}}function $h(n){if(!n)return[];const t=n.replace(/,/g," ").trim().split(/\s+/),e=[];for(let r=0;r<t.length;r+=2)e.push({x:parseFloat(t[r]),y:parseFloat(t[r+1])});return e}p(Vt,"type","Ellipse"),p(Vt,"cacheProperties",[...re,...ta]),p(Vt,"ownDefaults",{rx:0,ry:0}),p(Vt,"ATTRIBUTE_NAMES",[...de,"cx","cy","rx","ry"]),E.setClass(Vt),E.setSVGClass(Vt);const qh=["left","top"],ea={exactBoundingBox:!1};class Xt extends ut{static getDefaults(){return v(v({},super.getDefaults()),Xt.ownDefaults)}constructor(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:[],e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};super(),p(this,"strokeDiff",void 0),Object.assign(this,Xt.ownDefaults),this.setOptions(e),this.points=t;const{left:r,top:i}=e;this.initialized=!0,this.setBoundingBox(!0),typeof r=="number"&&this.set(U,r),typeof i=="number"&&this.set(vt,i)}isOpen(){return!0}_projectStrokeOnPoints(t){return Bc(this.points,t,this.isOpen())}_calcDimensions(t){t=v({scaleX:this.scaleX,scaleY:this.scaleY,skewX:this.skewX,skewY:this.skewY,strokeLineCap:this.strokeLineCap,strokeLineJoin:this.strokeLineJoin,strokeMiterLimit:this.strokeMiterLimit,strokeUniform:this.strokeUniform,strokeWidth:this.strokeWidth},t||{});const e=this.exactBoundingBox?this._projectStrokeOnPoints(t).map(c=>c.projectedPoint):this.points;if(e.length===0)return{left:0,top:0,width:0,height:0,pathOffset:new x,strokeOffset:new x,strokeDiff:new x};const r=ee(e),i=jr(v(v({},t),{},{scaleX:1,scaleY:1})),s=ee(this.points.map(c=>xt(c,i,!0))),o=new x(this.scaleX,this.scaleY);let a=r.left+r.width/2,l=r.top+r.height/2;return this.exactBoundingBox&&(a-=l*Math.tan(st(this.skewX)),l-=a*Math.tan(st(this.skewY))),v(v({},r),{},{pathOffset:new x(a,l),strokeOffset:new x(s.left,s.top).subtract(new x(r.left,r.top)).multiply(o),strokeDiff:new x(r.width,r.height).subtract(new x(s.width,s.height)).multiply(o)})}_findCenterFromElement(){const t=ee(this.points);return new x(t.left+t.width/2,t.top+t.height/2)}setDimensions(){this.setBoundingBox()}setBoundingBox(t){const{left:e,top:r,width:i,height:s,pathOffset:o,strokeOffset:a,strokeDiff:l}=this._calcDimensions();this.set({width:i,height:s,pathOffset:o,strokeOffset:a,strokeDiff:l}),t&&this.setPositionByOrigin(new x(e+i/2,r+s/2),W,W)}isStrokeAccountedForInDimensions(){return this.exactBoundingBox}_getNonTransformedDimensions(){return this.exactBoundingBox?new x(this.width,this.height):super._getNonTransformedDimensions()}_getTransformedDimensions(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};if(this.exactBoundingBox){let o;if(Object.keys(t).some(a=>this.strokeUniform||this.constructor.layoutProperties.includes(a))){var e,r;const{width:a,height:l}=this._calcDimensions(t);o=new x((e=t.width)!==null&&e!==void 0?e:a,(r=t.height)!==null&&r!==void 0?r:l)}else{var i,s;o=new x((i=t.width)!==null&&i!==void 0?i:this.width,(s=t.height)!==null&&s!==void 0?s:this.height)}return o.multiply(new x(t.scaleX||this.scaleX,t.scaleY||this.scaleY))}return super._getTransformedDimensions(t)}_set(t,e){const r=this.initialized&&this[t]!==e,i=super._set(t,e);return this.exactBoundingBox&&r&&((t===yt||t===Pt)&&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 v(v({},super.toObject(t)),{},{points:this.points.map(e=>{let{x:r,y:i}=e;return{x:r,y:i}})})}_toSVG(){const t=[],e=this.pathOffset.x,r=this.pathOffset.y,i=X.NUM_FRACTION_DIGITS;for(let s=0,o=this.points.length;s<o;s++)t.push(Z(this.points[s].x-e,i),",",Z(this.points[s].y-r,i)," ");return["<".concat(this.constructor.type.toLowerCase()," "),"COMMON_PARTS",'points="'.concat(t.join(""),`" />
|
|
132
|
+
`)]}_render(t){const e=this.points.length,r=this.pathOffset.x,i=this.pathOffset.y;if(e&&!isNaN(this.points[e-1].y)){t.beginPath(),t.moveTo(this.points[0].x-r,this.points[0].y-i);for(let s=0;s<e;s++){const o=this.points[s];t.lineTo(o.x-r,o.y-i)}!this.isOpen()&&t.closePath(),this._renderPaintInOrder(t)}}complexity(){return this.points.length}static async fromElement(t,e,r){return new this($h(t.getAttribute("points")),v(v({},J(se(t,this.ATTRIBUTE_NAMES,r),qh)),e))}static fromObject(t){return this._fromObject(t,{extraParam:"points"})}}p(Xt,"ownDefaults",ea),p(Xt,"type","Polyline"),p(Xt,"layoutProperties",[Oe,De,"strokeLineCap","strokeLineJoin","strokeMiterLimit","strokeWidth","strokeUniform","points"]),p(Xt,"cacheProperties",[...re,"points"]),p(Xt,"ATTRIBUTE_NAMES",[...de]),E.setClass(Xt),E.setSVGClass(Xt);class Qr extends Xt{isOpen(){return!1}}p(Qr,"ownDefaults",ea),p(Qr,"type","Polygon"),E.setClass(Qr),E.setSVGClass(Qr);class ra extends ut{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 r in e)for(const i in e[r])for(const s in e[r][i])return!1;return!0}styleHas(t,e){if(!this.styles||e!==void 0&&!this.styles[e])return!1;const r=e===void 0?this.styles:{0:this.styles[e]};for(const i in r)for(const s in r[i])if(r[i][s][t]!==void 0)return!0;return!1}cleanStyle(t){if(!this.styles)return!1;const e=this.styles;let r,i,s=0,o=!0,a=0;for(const l in e){r=0;for(const c in e[l]){const h=e[l][c]||{};s++,h[t]!==void 0?(i?h[t]!==i&&(o=!1):i=h[t],h[t]===this[t]&&delete h[t]):o=!1,Object.keys(h).length!==0?r++:delete e[l][c]}r===0&&delete e[l]}for(let l=0;l<this._textLines.length;l++)a+=this._textLines[l].length;o&&s===a&&(this[t]=i,this.removeStyle(t))}removeStyle(t){if(!this.styles)return;const e=this.styles;let r,i,s;for(i in e){for(s in r=e[i],r)delete r[s][t],Object.keys(r[s]).length===0&&delete r[s];Object.keys(r).length===0&&delete e[i]}}_extendStyles(t,e){const{lineIndex:r,charIndex:i}=this.get2DCursorLocation(t);this._getLineStyle(r)||this._setLineStyle(r);const s=Zi(v(v({},this._getStyleDeclaration(r,i)),e),o=>o!==void 0);this._setStyleDeclaration(r,i,s)}getSelectionStyles(t,e,r){const i=[];for(let s=t;s<(e||t);s++)i.push(this.getStyleAtPosition(s,r));return i}getStyleAtPosition(t,e){const{lineIndex:r,charIndex:i}=this.get2DCursorLocation(t);return e?this.getCompleteStyleDeclaration(r,i):this._getStyleDeclaration(r,i)}setSelectionStyles(t,e,r){for(let i=e;i<(r||e);i++)this._extendStyles(i,t);this._forceClearCache=!0}_getStyleDeclaration(t,e){var r;const i=this.styles&&this.styles[t];return i&&(r=i[e])!==null&&r!==void 0?r:{}}getCompleteStyleDeclaration(t,e){return v(v({},Ae(this,this.constructor._styleProperties)),this._getStyleDeclaration(t,e))}_setStyleDeclaration(t,e,r){this.styles[t][e]=r}_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]}}p(ra,"_styleProperties",Ql);const Kh=/ +/g,Zh=/"/g;function ks(n,t,e,r,i){return" ".concat(function(s,o){let{left:a,top:l,width:c,height:h}=o,u=arguments.length>2&&arguments[2]!==void 0?arguments[2]:X.NUM_FRACTION_DIGITS;const d=ar(at,s,!1),[g,f,m,b]=[a,l,c,h].map(y=>Z(y,u));return"<rect ".concat(d,' x="').concat(g,'" y="').concat(f,'" width="').concat(m,'" height="').concat(b,'"></rect>')}(n,{left:t,top:e,width:r,height:i}),`
|
|
133
|
+
`)}const Jh=["textAnchor","textDecoration","dx","dy","top","left","fontSize","strokeWidth"];let Os;class pt extends ra{static getDefaults(){return v(v({},super.getDefaults()),pt.ownDefaults)}constructor(t,e){super(),p(this,"__charBounds",[]),Object.assign(this,pt.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=Uo(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(Nt)&&this.enlargeSpaces()}enlargeSpaces(){let t,e,r,i,s,o,a;for(let l=0,c=this._textLines.length;l<c;l++)if((this.textAlign===Nt||l!==c-1&&!this.isEndOfWrapping(l))&&(i=0,s=this._textLines[l],e=this.getLineWidth(l),e<this.width&&(a=this.textLines[l].match(this._reSpacesAndTabs)))){r=a.length,t=(this.width-e)/r;for(let h=0;h<=s.length;h++)o=this.__charBounds[l][h],this._reSpaceAndTab.test(s[h])?(o.width+=t,o.kernedWidth+=t,o.left+=i,i+=t):o.left+=i}}isEndOfWrapping(t){return t===this._textLines.length-1}missingNewlineOffset(t){return 1}get2DCursorLocation(t,e){const r=e?this._unwrappedTextLines:this._textLines;let i;for(i=0;i<r.length;i++){if(t<=r[i].length)return{lineIndex:i,charIndex:t};t-=r[i].length+this.missingNewlineOffset(i,e)}return{lineIndex:i-1,charIndex:r[i-1].length<t?r[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===_t?(this._renderTextStroke(t),this._renderTextFill(t)):(this._renderTextFill(t),this._renderTextStroke(t))}_setTextStyles(t,e,r){if(t.textBaseline="alphabetic",this.path)switch(this.pathAlign){case W:t.textBaseline="middle";break;case"ascender":t.textBaseline=vt;break;case"descender":t.textBaseline=Yi}t.font=this._getFontDeclaration(e,r)}calcTextWidth(){let t=this.getLineWidth(0);for(let e=1,r=this._textLines.length;e<r;e++){const i=this.getLineWidth(e);i>t&&(t=i)}return t}_renderTextLine(t,e,r,i,s,o){this._renderChars(t,e,r,i,s,o)}_renderTextLinesBackground(t){if(!this.textBackgroundColor&&!this.styleHas("textBackgroundColor"))return;const e=t.fillStyle,r=this._getLeftOffset();let i=this._getTopOffset();for(let s=0,o=this._textLines.length;s<o;s++){const a=this.getHeightOfLine(s);if(!this.textBackgroundColor&&!this.styleHas("textBackgroundColor",s)){i+=a;continue}const l=this._textLines[s].length,c=this._getLineLeftOffset(s);let h,u,d=0,g=0,f=this.getValueOfPropertyAt(s,0,"textBackgroundColor");const m=this.getHeightOfLineImpl(s);for(let b=0;b<l;b++){const y=this.__charBounds[s][b];u=this.getValueOfPropertyAt(s,b,"textBackgroundColor"),this.path?(t.save(),t.translate(y.renderLeft,y.renderTop),t.rotate(y.angle),t.fillStyle=u,u&&t.fillRect(-y.width/2,-m*(1-this._fontSizeFraction),y.width,m),t.restore()):u!==f?(h=r+c+g,this.direction==="rtl"&&(h=this.width-h-d),t.fillStyle=f,f&&t.fillRect(h,i,d,m),g=y.left,d=y.width,f=u):d+=y.kernedWidth}u&&!this.path&&(h=r+c+g,this.direction==="rtl"&&(h=this.width-h-d),t.fillStyle=u,t.fillRect(h,i,d,m)),i+=a}t.fillStyle=e,this._removeShadow(t)}_measureChar(t,e,r,i){const s=tr.getFontCache(e),o=this._getFontDeclaration(e),a=r?r+t:t,l=r&&o===this._getFontDeclaration(i),c=e.fontSize/this.CACHE_FONT_SIZE;let h,u,d,g;if(r&&s.has(r)&&(d=s.get(r)),s.has(t)&&(g=h=s.get(t)),l&&s.has(a)&&(u=s.get(a),g=u-d),h===void 0||d===void 0||u===void 0){const f=function(){return Os||(Os=At({width:0,height:0}).getContext("2d")),Os}();this._setTextStyles(f,e,!0),h===void 0&&(g=h=f.measureText(t).width,s.set(t,h)),d===void 0&&l&&r&&(d=f.measureText(r).width,s.set(r,d)),l&&u===void 0&&(u=f.measureText(a).width,s.set(a,u),g=u-d)}return{width:h*c,kernedWidth:g*c}}getHeightOfChar(t,e){return this.getValueOfPropertyAt(t,e,"fontSize")}measureLine(t){const e=this._measureLine(t);return this.charSpacing!==0&&(e.width-=this._getWidthOfCharSpacing()),e.width<0&&(e.width=0),e}_measureLine(t){let e,r,i=0;const s=this.pathSide===it,o=this.path,a=this._textLines[t],l=a.length,c=new Array(l);this.__charBounds[t]=c;for(let h=0;h<l;h++){const u=a[h];r=this._getGraphemeBox(u,t,h,e),c[h]=r,i+=r.kernedWidth,e=u}if(c[l]={left:r?r.left+r.width:0,width:0,kernedWidth:0,height:this.fontSize,deltaY:0},o&&o.segmentsInfo){let h=0;const u=o.segmentsInfo[o.segmentsInfo.length-1].length;switch(this.textAlign){case U:h=s?u-i:0;break;case W:h=(u-i)/2;break;case it:h=s?0:u-i}h+=this.pathStartOffset*(s?-1:1);for(let d=s?l-1:0;s?d>=0:d<l;s?d--:d++)r=c[d],h>u?h%=u:h<0&&(h+=u),this._setGraphemeOnPath(h,r),h+=r.kernedWidth}return{width:i,numOfSpaces:0}}_setGraphemeOnPath(t,e){const r=t+e.kernedWidth/2,i=this.path,s=Th(i.path,r,i.segmentsInfo);e.renderLeft=s.x-i.pathOffset.x,e.renderTop=s.y-i.pathOffset.y,e.angle=s.angle+(this.pathSide===it?Math.PI:0)}_getGraphemeBox(t,e,r,i,s){const o=this.getCompleteStyleDeclaration(e,r),a=i?this.getCompleteStyleDeclaration(e,r-1):{},l=this._measureChar(t,o,i,a);let c,h=l.kernedWidth,u=l.width;this.charSpacing!==0&&(c=this._getWidthOfCharSpacing(),u+=c,h+=c);const d={width:u,left:0,height:o.fontSize,kernedWidth:h,deltaY:o.deltaY};if(r>0&&!s){const g=this.__charBounds[e][r-1];d.left=g.left+g.width+l.kernedWidth-l.width}return d}getHeightOfLineImpl(t){const e=this.__lineHeights;if(e[t])return e[t];let r=this.getHeightOfChar(t,0);for(let i=1,s=this._textLines[t].length;i<s;i++)r=Math.max(this.getHeightOfChar(t,i),r);return e[t]=r*this._fontSizeMult}getHeightOfLine(t){return this.getHeightOfLineImpl(t)*this.lineHeight}calcTextHeight(){let t=0;for(let e=0,r=this._textLines.length;e<r;e++)t+=e===r-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 r=0;const i=this._getLeftOffset(),s=this._getTopOffset();for(let o=0,a=this._textLines.length;o<a;o++)this._renderTextLine(e,t,this._textLines[o],i+this._getLineLeftOffset(o),s+r+this.getHeightOfLineImpl(o),o),r+=this.getHeightOfLine(o);t.restore()}_renderTextFill(t){(this.fill||this.styleHas(at))&&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,r,i,s,o){const a=this.textAlign.includes(Nt),l=this.path,c=!a&&this.charSpacing===0&&this.isEmptyStyles(o)&&!l,h=this.direction==="ltr",u=this.direction==="ltr"?1:-1,d=e.direction;let g,f,m,b,y,w="",O=0;if(e.save(),d!==this.direction&&(e.canvas.setAttribute("dir",h?"ltr":"rtl"),e.direction=h?"ltr":"rtl",e.textAlign=h?U:it),s-=this.getHeightOfLineImpl(o)*this._fontSizeFraction,c)return this._renderChar(t,e,o,0,r.join(""),i,s),void e.restore();for(let k=0,S=r.length-1;k<=S;k++)b=k===S||this.charSpacing||l,w+=r[k],m=this.__charBounds[o][k],O===0?(i+=u*(m.kernedWidth-m.width),O+=m.width):O+=m.kernedWidth,a&&!b&&this._reSpaceAndTab.test(r[k])&&(b=!0),b||(g=g||this.getCompleteStyleDeclaration(o,k),f=this.getCompleteStyleDeclaration(o,k+1),b=ms(g,f,!1)),b&&(l?(e.save(),e.translate(m.renderLeft,m.renderTop),e.rotate(m.angle),this._renderChar(t,e,o,k,w,-O/2,0),e.restore()):(y=i,this._renderChar(t,e,o,k,w,y,s)),w="",g=f,i+=u*O,O=0);e.restore()}_applyPatternGradientTransformText(t){const e=this.width+this.strokeWidth,r=this.height+this.strokeWidth,i=At({width:e,height:r}),s=i.getContext("2d");return i.width=e,i.height=r,s.beginPath(),s.moveTo(0,0),s.lineTo(e,0),s.lineTo(e,r),s.lineTo(0,r),s.closePath(),s.translate(e/2,r/2),s.fillStyle=t.toLive(s),this._applyPatternGradientTransform(s,t),s.fill(),s.createPattern(i,"no-repeat")}handleFiller(t,e,r){let i,s;return jt(r)?r.gradientUnits==="percentage"||r.gradientTransform||r.patternTransform?(i=-this.width/2,s=-this.height/2,t.translate(i,s),t[e]=this._applyPatternGradientTransformText(r),{offsetX:i,offsetY:s}):(t[e]=r.toLive(t),this._applyPatternGradientTransform(t,r)):(t[e]=r,{offsetX:0,offsetY:0})}_setStrokeStyles(t,e){let{stroke:r,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",r)}_setFillStyles(t,e){let{fill:r}=e;return this.handleFiller(t,"fillStyle",r)}_renderChar(t,e,r,i,s,o,a){const l=this._getStyleDeclaration(r,i),c=this.getCompleteStyleDeclaration(r,i),h=t==="fillText"&&c.fill,u=t==="strokeText"&&c.stroke&&c.strokeWidth;if(u||h){if(e.save(),e.font=this._getFontDeclaration(c),l.textBackgroundColor&&this._removeShadow(e),l.deltaY&&(a+=l.deltaY),h){const d=this._setFillStyles(e,c);e.fillText(s,o-d.offsetX,a-d.offsetY)}if(u){const d=this._setStrokeStyles(e,c);e.strokeText(s,o-d.offsetX,a-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,r){const i=this.get2DCursorLocation(t,!0),s=this.getValueOfPropertyAt(i.lineIndex,i.charIndex,"fontSize"),o=this.getValueOfPropertyAt(i.lineIndex,i.charIndex,"deltaY"),a={fontSize:s*r.size,deltaY:o+s*r.baseline};this.setSelectionStyles(a,t,e)}_getLineLeftOffset(t){const e=this.getLineWidth(t),r=this.width-e,i=this.textAlign,s=this.direction,o=this.isEndOfWrapping(t);let a=0;return i===Nt||i===cr&&!o||i===lr&&!o||i===Vr&&!o?0:(i===W&&(a=r/2),i===it&&(a=r),i===cr&&(a=r/2),i===lr&&(a=r),s==="rtl"&&(i===it||i===Nt||i===lr?a=0:i===U||i===Vr?a=-r:i!==W&&i!==cr||(a=-r/2)),a)}_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,r){var i;return(i=this._getStyleDeclaration(t,e)[r])!==null&&i!==void 0?i:this[r]}_renderTextDecoration(t,e){if(!this[e]&&!this.styleHas(e))return;let r=this._getTopOffset();const i=this._getLeftOffset(),s=this.path,o=this._getWidthOfCharSpacing(),a=e==="linethrough"?.5:e==="overline"?1:0,l=this.offsets[e];for(let c=0,h=this._textLines.length;c<h;c++){const u=this.getHeightOfLine(c);if(!this[e]&&!this.styleHas(e,c)){r+=u;continue}const d=this._textLines[c],g=u/this.lineHeight,f=this._getLineLeftOffset(c);let m=0,b=0,y=this.getValueOfPropertyAt(c,0,e),w=this.getValueOfPropertyAt(c,0,at),O=this.getValueOfPropertyAt(c,0,be),k=y,S=w,C=O;const A=r+g*(1-this._fontSizeFraction);let D=this.getHeightOfChar(c,0),L=this.getValueOfPropertyAt(c,0,"deltaY");for(let I=0,M=d.length;I<M;I++){const j=this.__charBounds[c][I];k=this.getValueOfPropertyAt(c,I,e),S=this.getValueOfPropertyAt(c,I,at),C=this.getValueOfPropertyAt(c,I,be);const z=this.getHeightOfChar(c,I),V=this.getValueOfPropertyAt(c,I,"deltaY");if(s&&k&&S){const tt=this.fontSize*C/1e3;t.save(),t.fillStyle=w,t.translate(j.renderLeft,j.renderTop),t.rotate(j.angle),t.fillRect(-j.kernedWidth/2,l*z+V-a*tt,j.kernedWidth,tt),t.restore()}else if((k!==y||S!==w||z!==D||C!==O||V!==L)&&b>0){const tt=this.fontSize*O/1e3;let N=i+f+m;this.direction==="rtl"&&(N=this.width-N-b),y&&w&&O&&(t.fillStyle=w,t.fillRect(N,A+l*D+L-a*tt,b,tt)),m=j.left,b=j.width,y=k,O=C,w=S,D=z,L=V}else b+=j.kernedWidth}let R=i+f+m;this.direction==="rtl"&&(R=this.width-R-b),t.fillStyle=S;const H=this.fontSize*C/1e3;k&&S&&C&&t.fillRect(R,A+l*D+L-a*H,b-o,H),r+=u}this._removeShadow(t)}_getFontDeclaration(){let{fontFamily:t=this.fontFamily,fontStyle:e=this.fontStyle,fontWeight:r=this.fontWeight,fontSize:i=this.fontSize}=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},s=arguments.length>1?arguments[1]:void 0;const o=t.includes("'")||t.includes('"')||t.includes(",")||pt.genericFonts.includes(t.toLowerCase())?t:'"'.concat(t,'"');return[e,r,"".concat(s?this.CACHE_FONT_SIZE:i,"px"),o].join(" ")}render(t){this.visible&&(this.canvas&&this.canvas.skipOffscreen&&!this.group&&!this.isOnScreen()||(this._forceClearCache&&this.initDimensions(),super.render(t)))}graphemeSplit(t){return ps(t)}_splitTextIntoLines(t){const e=t.split(this._reNewline),r=new Array(e.length),i=[`
|
|
134
|
+
`];let s=[];for(let o=0;o<e.length;o++)r[o]=this.graphemeSplit(e[o]),s=s.concat(r[o],i);return s.pop(),{_unwrappedLines:r,lines:e,graphemeText:s,graphemeLines:r}}toObject(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:[];return v(v({},super.toObject([...so,...t])),{},{styles:Wc(this.styles,this.text)},this.path?{path:this.path.toObject()}:{})}set(t,e){const{textLayoutProperties:r}=this.constructor;super.set(t,e);let i=!1,s=!1;if(typeof t=="object")for(const o in t)o==="path"&&this.setPathInfo(),i=i||r.includes(o),s=s||o==="path";else i=r.includes(t),s=t==="path";return s&&this.setPathInfo(),i&&this.initialized&&(this.initDimensions(),this.setCoords()),this}complexity(){return 1}static async fromElement(t,e,r){const i=se(t,pt.ATTRIBUTE_NAMES,r),s=v(v({},e),i),{textAnchor:o=U,textDecoration:a="",dx:l=0,dy:c=0,top:h=0,left:u=0,fontSize:d=Xi,strokeWidth:g=1}=s,f=J(s,Jh),m=new this(Hr(t.textContent||"").trim(),v({left:u+l,top:h+c,underline:a.includes("underline"),overline:a.includes("overline"),linethrough:a.includes("line-through"),strokeWidth:0,fontSize:d},f)),b=m.getScaledHeight()/m.height,y=((m.height+m.strokeWidth)*m.lineHeight-m.height)*b,w=m.getScaledHeight()+y;let O=0;return o===W&&(O=m.getScaledWidth()/2),o===it&&(O=m.getScaledWidth()),m.set({left:m.left-O,top:m.top-(w-m.fontSize*(.07+m._fontSizeFraction))/m.lineHeight,strokeWidth:g}),m}static fromObject(t){return this._fromObject(v(v({},t),{},{styles:Vc(t.styles||{},t.text)}),{extraParam:"text"})}}p(pt,"textLayoutProperties",io),p(pt,"cacheProperties",[...re,...so]),p(pt,"ownDefaults",tc),p(pt,"type","Text"),p(pt,"genericFonts",["serif","sans-serif","monospace","cursive","fantasy","system-ui","ui-serif","ui-sans-serif","ui-monospace","ui-rounded","math","emoji","fangsong"]),p(pt,"ATTRIBUTE_NAMES",de.concat("x","y","dx","dy","font-family","font-style","font-weight","font-size","letter-spacing","text-decoration","text-anchor")),So(pt,[class extends to{_toSVG(){const n=this._getSVGLeftTopOffsets(),t=this._getSVGTextAndBg(n.textTop,n.textLeft);return this._wrapSVGTextAndBg(t)}toSVG(n){const t=this._createBaseSVGMarkup(this._toSVG(),{reviver:n,noStyle:!0,withShadow:!0}),e=this.path;return e?t+e._createBaseSVGMarkup(e._toSVG(),{reviver:n,withShadow:!0,additionalTransform:nr(this.calcOwnMatrix())}):t}_getSVGLeftTopOffsets(){return{textLeft:-this.width/2,textTop:-this.height/2,lineTop:this.getHeightOfLine(0)}}_wrapSVGTextAndBg(n){let{textBgRects:t,textSpans:e}=n;const r=this.getSvgTextDecoration(this);return[t.join(""),' <text xml:space="preserve" ','font-family="'.concat(this.fontFamily.replace(Zh,"'"),'" '),'font-size="'.concat(this.fontSize,'" '),this.fontStyle?'font-style="'.concat(this.fontStyle,'" '):"",this.fontWeight?'font-weight="'.concat(this.fontWeight,'" '):"",r?'text-decoration="'.concat(r,'" '):"",this.direction==="rtl"?'direction="'.concat(this.direction,'" '):"",'style="',this.getSvgStyles(!0),'"',this.addPaintOrder()," >",e.join(""),`</text>
|
|
135
|
+
`]}_getSVGTextAndBg(n,t){const e=[],r=[];let i,s=n;this.backgroundColor&&r.push(...ks(this.backgroundColor,-this.width/2,-this.height/2,this.width,this.height));for(let o=0,a=this._textLines.length;o<a;o++)i=this._getLineLeftOffset(o),this.direction==="rtl"&&(i+=this.width),(this.textBackgroundColor||this.styleHas("textBackgroundColor",o))&&this._setSVGTextLineBg(r,o,t+i,s),this._setSVGTextLineText(e,o,t+i,s),s+=this.getHeightOfLine(o);return{textSpans:e,textBgRects:r}}_createTextCharSpan(n,t,e,r,i){const s=X.NUM_FRACTION_DIGITS,o=this.getSvgSpanStyles(t,n!==n.trim()||!!n.match(Kh)),a=o?'style="'.concat(o,'"'):"",l=t.deltaY,c=l?' dy="'.concat(Z(l,s),'" '):"",{angle:h,renderLeft:u,renderTop:d,width:g}=i;let f="";if(u!==void 0){const m=g/2;h&&(f=' rotate="'.concat(Z(te(h),s),'"'));const b=Pe({angle:te(h)});b[4]=u,b[5]=d;const y=new x(-m,0).transform(b);e=y.x,r=y.y}return'<tspan x="'.concat(Z(e,s),'" y="').concat(Z(r,s),'" ').concat(c).concat(f).concat(a,">").concat(Ic(n),"</tspan>")}_setSVGTextLineText(n,t,e,r){const i=this.getHeightOfLine(t),s=this.textAlign.includes(Nt),o=this._textLines[t];let a,l,c,h,u,d="",g=0;r+=i*(1-this._fontSizeFraction)/this.lineHeight;for(let f=0,m=o.length-1;f<=m;f++)u=f===m||this.charSpacing||this.path,d+=o[f],c=this.__charBounds[t][f],g===0?(e+=c.kernedWidth-c.width,g+=c.width):g+=c.kernedWidth,s&&!u&&this._reSpaceAndTab.test(o[f])&&(u=!0),u||(a=a||this.getCompleteStyleDeclaration(t,f),l=this.getCompleteStyleDeclaration(t,f+1),u=ms(a,l,!0)),u&&(h=this._getStyleDeclaration(t,f),n.push(this._createTextCharSpan(d,h,e,r,c)),d="",a=l,this.direction==="rtl"?e-=g:e+=g,g=0)}_setSVGTextLineBg(n,t,e,r){const i=this._textLines[t],s=this.getHeightOfLine(t)/this.lineHeight;let o,a=0,l=0,c=this.getValueOfPropertyAt(t,0,"textBackgroundColor");for(let h=0;h<i.length;h++){const{left:u,width:d,kernedWidth:g}=this.__charBounds[t][h];o=this.getValueOfPropertyAt(t,h,"textBackgroundColor"),o!==c?(c&&n.push(...ks(c,e+l,r,a,s)),l=u,a=d,c=o):a+=g}o&&n.push(...ks(c,e+l,r,a,s))}_getSVGLineTopOffset(n){let t,e=0;for(t=0;t<n;t++)e+=this.getHeightOfLine(t);const r=this.getHeightOfLine(t);return{lineTop:e,offset:(this._fontSizeMult-this._fontSizeFraction)*r/(this.lineHeight*this._fontSizeMult)}}getSvgStyles(n){return"".concat(super.getSvgStyles(n)," text-decoration-thickness: ").concat(Z(this.textDecorationThickness*this.getObjectScaling().y/10,X.NUM_FRACTION_DIGITS),"%; white-space: pre;")}getSvgSpanStyles(n,t){const{fontFamily:e,strokeWidth:r,stroke:i,fill:s,fontSize:o,fontStyle:a,fontWeight:l,deltaY:c,textDecorationThickness:h,linethrough:u,overline:d,underline:g}=n,f=this.getSvgTextDecoration({underline:g??this.underline,overline:d??this.overline,linethrough:u??this.linethrough}),m=h||this.textDecorationThickness;return[i?ar(_t,i):"",r?"stroke-width: ".concat(r,"; "):"",e?"font-family: ".concat(e.includes("'")||e.includes('"')?e:"'".concat(e,"'"),"; "):"",o?"font-size: ".concat(o,"px; "):"",a?"font-style: ".concat(a,"; "):"",l?"font-weight: ".concat(l,"; "):"",f?"text-decoration: ".concat(f,"; text-decoration-thickness: ").concat(Z(m*this.getObjectScaling().y/10,X.NUM_FRACTION_DIGITS),"%; "):"",s?ar(at,s):"",c?"baseline-shift: ".concat(-c,"; "):"",t?"white-space: pre; ":""].join("")}getSvgTextDecoration(n){return["overline","underline","line-through"].filter(t=>n[t.replace("-","")]).join(" ")}}]),E.setClass(pt),E.setSVGClass(pt);class Qh{constructor(t){p(this,"target",void 0),p(this,"__mouseDownInPlace",!1),p(this,"__dragStartFired",!1),p(this,"__isDraggingOver",!1),p(this,"__dragStartSelection",void 0),p(this,"__dragImageDisposer",void 0),p(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(r=>r()),this._dispose=void 0}}isPointerOverSelection(t){const e=this.target,r=e.getSelectionStartFromPointer(t);return e.isEditing&&r>=e.selectionStart&&r<=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 r;let{selectionStart:i,selectionEnd:s}=e;const o=this.target,a=o.canvas,l=new x(o.flipX?-1:1,o.flipY?-1:1),c=o._getCursorBoundaries(i),h=new x(c.left+c.leftOffset,c.top+c.topOffset).multiply(l).transform(o.calcTransformMatrix()),u=a.getScenePoint(t).subtract(h),d=o.getCanvasRetinaScaling(),g=o.getBoundingRect(),f=h.subtract(new x(g.left,g.top)),m=a.viewportTransform,b=f.add(u).transform(m,!0),y=o.backgroundColor,w=fs(o.styles);o.backgroundColor="";const O={stroke:"transparent",fill:"transparent",textBackgroundColor:"transparent"};o.setSelectionStyles(O,0,i),o.setSelectionStyles(O,s,o.text.length),o.dirty=!0;const k=o.toCanvasElement({enableRetinaScaling:a.enableRetinaScaling,viewportTransform:!0});o.backgroundColor=y,o.styles=w,o.dirty=!0,ws(k,{position:"fixed",left:"".concat(-k.width,"px"),border:bt,width:"".concat(k.width/d,"px"),height:"".concat(k.height/d,"px")}),this.__dragImageDisposer&&this.__dragImageDisposer(),this.__dragImageDisposer=()=>{k.remove()},Bt(t.target||this.target.hiddenTextarea).body.appendChild(k),(r=t.dataTransfer)===null||r===void 0||r.setDragImage(k,b.x,b.y)}onDragStart(t){this.__dragStartFired=!0;const e=this.target,r=this.isActive();if(r&&t.dataTransfer){const i=this.__dragStartSelection={selectionStart:e.selectionStart,selectionEnd:e.selectionEnd},s=e._text.slice(i.selectionStart,i.selectionEnd).join(""),o=v({text:e.text,value:s},i);t.dataTransfer.setData("text/plain",s),t.dataTransfer.setData("application/fabric",JSON.stringify({value:s,styles:e.getSelectionStyles(i.selectionStart,i.selectionEnd,!0)})),t.dataTransfer.effectAllowed="copyMove",this.setDragImage(t,o)}return e.abortCursorAnimation(),r}canDrop(t){if(this.target.editable&&!this.target.getActiveControl()&&!t.defaultPrevented){if(this.isActive()&&this.__dragStartSelection){const e=this.target.getSelectionStartFromPointer(t),r=this.__dragStartSelection;return e<r.selectionStart||e>r.selectionEnd}return!0}return!1}targetCanDrop(t){return this.target.canDrop(t)}dragEnterHandler(t){let{e}=t;const r=this.targetCanDrop(e);!this.__isDraggingOver&&r&&(this.__isDraggingOver=!0)}dragOverHandler(t){const{e}=t,r=this.targetCanDrop(e);!this.__isDraggingOver&&r?this.__isDraggingOver=!0:this.__isDraggingOver&&!r&&(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:r}=t,i=r.defaultPrevented;this.__isDraggingOver=!1,r.preventDefault();let s=(e=r.dataTransfer)===null||e===void 0?void 0:e.getData("text/plain");if(s&&!i){const o=this.target,a=o.canvas;let l=o.getSelectionStartFromPointer(r);const{styles:c}=r.dataTransfer.types.includes("application/fabric")?JSON.parse(r.dataTransfer.getData("application/fabric")):{},h=s[Math.max(0,s.length-1)],u=0;if(this.__dragStartSelection){const d=this.__dragStartSelection.selectionStart,g=this.__dragStartSelection.selectionEnd;l>d&&l<=g?l=d:l>g&&(l-=g-d),o.removeChars(d,g),delete this.__dragStartSelection}o._reNewline.test(h)&&(o._reNewline.test(o._text[l])||l===o._text.length)&&(s=s.trimEnd()),t.didDrop=!0,t.dropTarget=o,o.insertChars(s,c,l),a.setActiveObject(o),o.enterEditing(r),o.selectionStart=Math.min(l+u,o._text.length),o.selectionEnd=Math.min(o.selectionStart+s.length,o._text.length),o.hiddenTextarea.value=o.text,o._updateTextarea(),o.hiddenTextarea.focus(),o.fire(kr,{index:l+u,action:"drop"}),a.fire("text:changed",{target:o}),a.contextTopDirty=!0,a.requestRenderAll()}}dragEndHandler(t){let{e}=t;if(this.isActive()&&this.__dragStartFired&&this.__dragStartSelection){var r;const i=this.target,s=this.target.canvas,{selectionStart:o,selectionEnd:a}=this.__dragStartSelection,l=((r=e.dataTransfer)===null||r===void 0?void 0:r.dropEffect)||bt;l===bt?(i.selectionStart=o,i.selectionEnd=a,i._updateTextarea(),i.hiddenTextarea.focus()):(i.clearContextTop(),l==="move"&&(i.removeChars(o,a),i.selectionStart=i.selectionEnd=o,i.hiddenTextarea&&(i.hiddenTextarea.value=i.text),i._updateTextarea(),i.fire(kr,{index:o,action:"dragend"}),s.fire("text:changed",{target:i}),s.requestRenderAll()),i.exitEditing())}this.__dragImageDisposer&&this.__dragImageDisposer(),delete this.__dragImageDisposer,delete this.__dragStartSelection,this.__isDraggingOver=!1}dispose(){this._dispose&&this._dispose()}}const ia=/[ \n\.,;!\?\-]/;class tu extends pt{constructor(){super(...arguments),p(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:r,delay:i,onComplete:s}=t;return mo({startValue:this._currentCursorOpacity,endValue:e,duration:r,delay:i,onComplete:s,abort:()=>!this.canvas||this.selectionStart!==this.selectionEnd,onChange:o=>{this._currentCursorOpacity=o,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,r=t-1;if(this._reSpace.test(this._text[r]))for(;this._reSpace.test(this._text[r]);)e++,r--;for(;/\S/.test(this._text[r])&&r>-1;)e++,r--;return t-e}findWordBoundaryRight(t){let e=0,r=t;if(this._reSpace.test(this._text[r]))for(;this._reSpace.test(this._text[r]);)e++,r++;for(;/\S/.test(this._text[r])&&r<this._text.length;)e++,r++;return t+e}findLineBoundaryLeft(t){let e=0,r=t-1;for(;!/\n/.test(this._text[r])&&r>-1;)e++,r--;return t-e}findLineBoundaryRight(t){let e=0,r=t;for(;!/\n/.test(this._text[r])&&r<this._text.length;)e++,r++;return t+e}searchWordBoundary(t,e){const r=this._text;let i=t>0&&this._reSpace.test(r[t])&&(e===-1||!Ui.test(r[t-1]))?t-1:t,s=r[i];for(;i>0&&i<r.length&&!ia.test(s);)i+=e,s=r[i];return e===-1&&ia.test(s)&&i++,i}selectWord(t){var e;t=(e=t)!==null&&e!==void 0?e:this.selectionStart;const r=this.searchWordBoundary(t,-1),i=Math.max(r,this.searchWordBoundary(t,1));this.selectionStart=r,this.selectionEnd=i,this._fireSelectionChanged(),this._updateTextarea(),this.renderCursorOrSelection()}selectLine(t){var e;t=(e=t)!==null&&e!==void 0?e:this.selectionStart;const r=this.findLineBoundaryLeft(t),i=this.findLineBoundaryRight(t);this.selectionStart=r,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;Bt(e).activeElement!==e&&e.focus();const r=this.getSelectionStartFromPointer(t),i=this.selectionStart,s=this.selectionEnd;(r===this.__selectionStartOnMouseDown&&i!==s||i!==r&&s!==r)&&(r>this.__selectionStartOnMouseDown?(this.selectionStart=this.__selectionStartOnMouseDown,this.selectionEnd=r):(this.selectionStart=r,this.selectionEnd=this.__selectionStartOnMouseDown),this.selectionStart===i&&this.selectionEnd===s||(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,r){const i=r.slice(0,t),s=this.graphemeSplit(i).length;if(t===e)return{selectionStart:s,selectionEnd:s};const o=r.slice(t,e);return{selectionStart:s,selectionEnd:s+this.graphemeSplit(o).length}}fromGraphemeToStringSelection(t,e,r){const i=r.slice(0,t).join("").length;return t===e?{selectionStart:i,selectionEnd:i}:{selectionStart:i,selectionEnd:i+r.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),r=this.get2DCursorLocation(t),i=r.lineIndex,s=r.charIndex,o=this.getValueOfPropertyAt(i,s,"fontSize")*this.lineHeight,a=e.leftOffset,l=this.getCanvasRetinaScaling(),c=this.canvas.upperCanvasEl,h=c.width/l,u=c.height/l,d=h-o,g=u-o,f=new x(e.left+a,e.top+e.topOffset+o).transform(this.calcTransformMatrix()).transform(this.canvas.viewportTransform).multiply(new x(c.clientWidth/h,c.clientHeight/u));return f.x<0&&(f.x=0),f.x>d&&(f.x=d),f.y<0&&(f.y=0),f.y>g&&(f.y=g),f.x+=this.canvas._offset.left,f.y+=this.canvas._offset.top,{left:"".concat(f.x,"px"),top:"".concat(f.y,"px"),fontSize:"".concat(o,"px"),charHeight:o}}_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(Dr),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:r,charIndex:i}=this.get2DCursorLocation(t,!0),{lineIndex:s,charIndex:o}=this.get2DCursorLocation(e,!0);if(r!==s){if(this.styles[r])for(let a=i;a<this._unwrappedTextLines[r].length;a++)delete this.styles[r][a];if(this.styles[s])for(let a=o;a<this._unwrappedTextLines[s].length;a++){const l=this.styles[s][a];l&&(this.styles[r]||(this.styles[r]={}),this.styles[r][i+a-o]=l)}for(let a=r+1;a<=s;a++)delete this.styles[a];this.shiftLineStyles(s,r-s)}else if(this.styles[r]){const a=this.styles[r],l=o-i;for(let c=i;c<o;c++)delete a[c];for(const c in this.styles[r]){const h=parseInt(c,10);h>=o&&(a[h-l]=a[c],delete a[c])}}}shiftLineStyles(t,e){const r=Object.assign({},this.styles);for(const i in this.styles){const s=parseInt(i,10);s>t&&(this.styles[s+e]=r[s],r[s-e]||delete this.styles[s])}}insertNewlineStyleObject(t,e,r,i){const s={},o=this._unwrappedTextLines[t].length,a=o===e;let l=!1;r||(r=1),this.shiftLineStyles(t,r);const c=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&&(l=!0,s[d-e]=this.styles[t][u],a&&e===0||delete this.styles[t][u])}let h=!1;for(l&&!a&&(this.styles[t+r]=s,h=!0),(h||o>e)&&r--;r>0;)i&&i[r-1]?this.styles[t+r]={0:v({},i[r-1])}:c?this.styles[t+r]={0:v({},c)}:delete this.styles[t+r],r--;this._forceClearCache=!0}insertCharStyleObject(t,e,r,i){this.styles||(this.styles={});const s=this.styles[t],o=s?v({},s):{};r||(r=1);for(const l in o){const c=parseInt(l,10);c>=e&&(s[c+r]=o[c],o[c-r]||delete s[c])}if(this._forceClearCache=!0,i){for(;r--;)Object.keys(i[r]).length&&(this.styles[t]||(this.styles[t]={}),this.styles[t][e+r]=v({},i[r]));return}if(!s)return;const a=s[e?e-1:1];for(;a&&r--;)this.styles[t][e+r]=v({},a)}insertNewStyleBlock(t,e,r){const i=this.get2DCursorLocation(e,!0),s=[0];let o,a=0;for(let l=0;l<t.length;l++)t[l]===`
|
|
136
|
+
`?(a++,s[a]=0):s[a]++;for(s[0]>0&&(this.insertCharStyleObject(i.lineIndex,i.charIndex,s[0],r),r=r&&r.slice(s[0]+1)),a&&this.insertNewlineStyleObject(i.lineIndex,i.charIndex+s[0],a),o=1;o<a;o++)s[o]>0?this.insertCharStyleObject(i.lineIndex+o,0,s[o],r):r&&this.styles[i.lineIndex+o]&&r[0]&&(this.styles[i.lineIndex+o][0]=r[0]),r=r&&r.slice(s[o]+1);s[o]>0&&this.insertCharStyleObject(i.lineIndex+o,0,s[o],r)}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,r){let i=arguments.length>3&&arguments[3]!==void 0?arguments[3]:r;i>r&&this.removeStyleFromTo(r,i);const s=this.graphemeSplit(t);this.insertNewStyleBlock(s,r,e),this._text=[...this._text.slice(0,r),...s,...this._text.slice(i)],this.text=this._text.join(""),this.set("dirty",!0),this.initDimensions(),this.setCoords(),this._removeExtraneousStyles()}setSelectionStartEndWithShift(t,e,r){r<=t?(e===t?this._selectionDirection=U:this._selectionDirection===it&&(this._selectionDirection=U,this.selectionEnd=t),this.selectionStart=r):r>t&&r<e?this._selectionDirection===it?this.selectionEnd=r:this.selectionStart=r:(e===t?this._selectionDirection=it:this._selectionDirection===U&&(this._selectionDirection=it,this.selectionStart=e),this.selectionEnd=r)}}class eu extends tu{initHiddenTextarea(){const t=this.canvas&&Bt(this.canvas.getElement())||ke(),e=t.createElement("textarea");Object.entries({autocapitalize:"off",autocorrect:"off",autocomplete:"off",spellcheck:"false","data-fabric":"textarea",wrap:"off",name:"fabricTextarea"}).map(o=>{let[a,l]=o;return e.setAttribute(a,l)});const{top:r,left:i,fontSize:s}=this._calcTextareaPosition();e.style.cssText="position: absolute; top: ".concat(r,"; left: ").concat(i,"; z-index: -999; opacity: 0; width: 1px; height: 1px; font-size: 1px; padding-top: ").concat(s,";"),(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(o=>{let[a,l]=o;return e.addEventListener(a,this[l].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:r,selectionStart:i,selectionEnd:s}=this.hiddenTextarea;if(this.fromPaste=!1,t&&t.stopPropagation(),!this.isEditing)return;const o=()=>{this.updateFromTextArea(),this.fire(kr),this.canvas&&(this.canvas.fire("text:changed",{target:this}),this.canvas.requestRenderAll())};if(this.hiddenTextarea.value==="")return this.styles={},void o();const a=this._splitTextIntoLines(r).graphemeText,l=this._text.length,c=a.length,h=this.selectionStart,u=this.selectionEnd,d=h!==u;let g,f,m,b,y=c-l;const w=this.fromStringToGraphemeSelection(i,s,r),O=h>w.selectionStart;d?(f=this._text.slice(h,u),y+=u-h):c<l&&(f=O?this._text.slice(u+y,u):this._text.slice(h,h-y));const k=a.slice(w.selectionEnd-y,w.selectionEnd);if(f&&f.length&&(k.length&&(g=this.getSelectionStyles(h,h+1,!1),g=k.map(()=>g[0])),d?(m=h,b=u):O?(m=u-f.length,b=u):(m=u,b=u+f.length),this.removeStyleFromTo(m,b)),k.length){const{copyPasteData:S}=Gt();e&&k.join("")===S.copiedText&&!X.disableStyleCopyPaste&&(g=S.copiedTextStyle),this.insertNewStyleBlock(k,h,g)}o()}onCompositionStart(){this.inCompositionMode=!0}onCompositionEnd(){this.inCompositionMode=!1}onCompositionUpdate(t){let{target:e}=t;const{selectionStart:r,selectionEnd:i}=e;this.compositionStart=r,this.compositionEnd=i,this.updateTextareaPosition()}copy(){if(this.selectionStart===this.selectionEnd)return;const{copyPasteData:t}=Gt();t.copiedText=this.getSelectedText(),X.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 r,i=this._getLineLeftOffset(t);return e>0&&(r=this.__charBounds[t][e-1],i+=r.left+r.width),i}getDownCursorOffset(t,e){const r=this._getSelectionForOffset(t,e),i=this.get2DCursorLocation(r),s=i.lineIndex;if(s===this._textLines.length-1||t.metaKey||t.keyCode===34)return this._text.length-r;const o=i.charIndex,a=this._getWidthBeforeCursor(s,o),l=this._getIndexOnLine(s+1,a);return this._textLines[s].slice(o).length+l+1+this.missingNewlineOffset(s)}_getSelectionForOffset(t,e){return t.shiftKey&&this.selectionStart!==this.selectionEnd&&e?this.selectionEnd:this.selectionStart}getUpCursorOffset(t,e){const r=this._getSelectionForOffset(t,e),i=this.get2DCursorLocation(r),s=i.lineIndex;if(s===0||t.metaKey||t.keyCode===33)return-r;const o=i.charIndex,a=this._getWidthBeforeCursor(s,o),l=this._getIndexOnLine(s-1,a),c=this._textLines[s].slice(0,o),h=this.missingNewlineOffset(s-1);return-this._textLines[s-1].length+l-c.length+(1-h)}_getIndexOnLine(t,e){const r=this._textLines[t];let i,s,o=this._getLineLeftOffset(t),a=0;for(let l=0,c=r.length;l<c;l++)if(i=this.__charBounds[t][l].width,o+=i,o>e){s=!0;const h=o-i,u=o,d=Math.abs(h-e);a=Math.abs(u-e)<d?l:l-1;break}return s||(a=r.length-1),a}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 r=this["get".concat(t,"CursorOffset")](e,this._selectionDirection===it);if(e.shiftKey?this.moveCursorWithShift(r):this.moveCursorWithoutShift(r),r!==0){const i=this.text.length;this.selectionStart=Fe(0,this.selectionStart,i),this.selectionEnd=Fe(0,this.selectionEnd,i),this.abortCursorAnimation(),this.initDelayedCursor(),this._fireSelectionChanged(),this._updateTextarea()}}moveCursorWithShift(t){const e=this._selectionDirection===U?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,r){let i;if(t.altKey)i=this["findWordBoundary".concat(r)](this[e]);else{if(!t.metaKey&&t.keyCode!==35&&t.keyCode!==36)return this[e]+=r==="Left"?-1:1,!0;i=this["findLineBoundary".concat(r)](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=U,this.selectionEnd===this.selectionStart&&this.selectionStart!==0&&(e=this._moveLeft(t,"selectionStart")),this.selectionEnd=this.selectionStart,e}moveCursorLeftWithShift(t){return this._selectionDirection===it&&this.selectionStart!==this.selectionEnd?this._moveLeft(t,"selectionEnd"):this.selectionStart!==0?(this._selectionDirection=U,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 r="moveCursor".concat(t).concat(e.shiftKey?"WithShift":"WithoutShift");this._currentCursorOpacity=1,this[r](e)&&(this.abortCursorAnimation(),this.initDelayedCursor(),this._fireSelectionChanged(),this._updateTextarea())}moveCursorRightWithShift(t){return this._selectionDirection===U&&this.selectionStart!==this.selectionEnd?this._moveRight(t,"selectionStart"):this.selectionEnd!==this._text.length?(this._selectionDirection=it,this._moveRight(t,"selectionEnd")):void 0}moveCursorRightWithoutShift(t){let e=!0;return this._selectionDirection=it,this.selectionStart===this.selectionEnd?(e=this._moveRight(t,"selectionStart"),this.selectionEnd=this.selectionStart):this.selectionStart=this.selectionEnd,e}}const sa=n=>!!n.button;class ru extends eu{constructor(){super(...arguments),p(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 Qh(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:r}=t;this.canvas&&this.editable&&!sa(e)&&!this.getActiveControl()&&(this.draggableTextDelegate.start(e)||(this.canvas.textEditingManager.register(this),r&&(this.inCompositionMode=!1,this.setCursorByClick(e)),this.isEditing&&(this.__selectionStartOnMouseDown=this.selectionStart,this.selectionStart===this.selectionEnd&&this.abortCursorAnimation(),this.renderCursorOrSelection()),this.selected||(this.selected=r||this.isEditing)))}mouseUpHandler(t){let{e,transform:r}=t;const i=this.draggableTextDelegate.end(e);if(this.canvas){this.canvas.textEditingManager.unregister(this);const s=this.canvas._activeObject;if(s&&s!==this)return}!this.editable||this.group&&!this.group.interactive||r&&r.actionPerformed||sa(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),r=this.selectionStart,i=this.selectionEnd;t.shiftKey?this.setSelectionStartEndWithShift(r,i,e):(this.selectionStart=e,this.selectionEnd=e),this.isEditing&&(this._fireSelectionChanged(),this._updateTextarea())}getSelectionStartFromPointer(t){const e=this.canvas.getScenePoint(t).transform(Rt(this.calcTransformMatrix())).add(new x(-this._getLeftOffset(),-this._getTopOffset()));let r=0,i=0,s=0;for(let c=0;c<this._textLines.length&&r<=e.y;c++)r+=this.getHeightOfLine(c),s=c,c>0&&(i+=this._textLines[c-1].length+this.missingNewlineOffset(c-1));let o=Math.abs(this._getLineLeftOffset(s));const a=this._textLines[s].length,l=this.__charBounds[s];for(let c=0;c<a;c++){const h=o+l[c].kernedWidth;if(e.x<=h){Math.abs(e.x-h)<=Math.abs(e.x-o)&&i++;break}o=h,i++}return Math.min(this.flipX?a-i:i,this._text.length)}}const ti="moveCursorUp",ei="moveCursorDown",ri="moveCursorLeft",ii="moveCursorRight",si="exitEditing",na=(n,t)=>{const e=t.getRetinaScaling();n.setTransform(e,0,0,e,0,0);const r=t.viewportTransform;n.transform(r[0],r[1],r[2],r[3],r[4],r[5])},iu=v({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:si,27:si,33:ti,34:ei,35:ii,36:ri,37:ri,38:ti,39:ii,40:ei},keysMapRtl:{9:si,27:si,33:ti,34:ei,35:ri,36:ii,37:ii,38:ti,39:ri,40:ei},ctrlKeysMapDown:{65:"cmdAll"},ctrlKeysMapUp:{67:"copy",88:"cut"}},{_selectionDirection:null,_reSpace:/\s|\r?\n/,inCompositionMode:!1});class qt extends ru{static getDefaults(){return v(v({},super.getDefaults()),qt.ownDefaults)}get type(){const t=super.type;return t==="itext"?"i-text":t}constructor(t,e){super(t,v(v({},qt.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 Cs&&this.canvas.textEditingManager.remove(this),e instanceof Cs&&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,r=arguments.length>2?arguments[2]:void 0;return super.getSelectionStyles(t,e,r)}setSelectionStyles(t){let e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:this.selectionStart||0,r=arguments.length>2&&arguments[2]!==void 0?arguments[2]:this.selectionEnd;return super.setSelectionStyles(t,e,r)}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 r=super.toCanvasElement(t);return this.isEditing=e,r}renderCursorOrSelection(){if(!this.isEditing||!this.canvas)return;const t=this.clearContextTop(!0);if(!t)return;const e=this._getCursorBoundaries(),r=this.findAncestorsWithClipPath(),i=r.length>0;let s,o=t;if(i){s=At(t.canvas),o=s.getContext("2d"),na(o,this.canvas);const a=this.calcTransformMatrix();o.transform(a[0],a[1],a[2],a[3],a[4],a[5])}if(this.selectionStart!==this.selectionEnd||this.inCompositionMode?this.renderSelection(o,e):this.renderCursor(o,e),i)for(const a of r){const l=a.clipPath,c=At(t.canvas),h=c.getContext("2d");if(na(h,this.canvas),!l.absolutePositioned){const u=a.calcTransformMatrix();h.transform(u[0],u[1],u[2],u[3],u[4],u[5])}l.transform(h),l.drawObject(h,!0,{}),this.drawClipPathOnCache(o,l,c)}i&&(t.setTransform(1,0,0,1,0,0),t.drawImage(s,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 r=this._getLeftOffset(),i=this._getTopOffset(),s=this._getCursorBoundariesOffsets(t,e);return{left:r,top:i,leftOffset:s.left,topOffset:s.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,r=0;const{charIndex:i,lineIndex:s}=this.get2DCursorLocation(t);for(let c=0;c<s;c++)e+=this.getHeightOfLine(c);const o=this._getLineLeftOffset(s),a=this.__charBounds[s][i];a&&(r=a.left),this.charSpacing!==0&&i===this._textLines[s].length&&(r-=this._getWidthOfCharSpacing());const l={top:e,left:o+(r>0?r:0)};return this.direction==="rtl"&&(this.textAlign===it||this.textAlign===Nt||this.textAlign===lr?l.left*=-1:this.textAlign===U||this.textAlign===Vr?l.left=o-(r>0?r:0):this.textAlign!==W&&this.textAlign!==cr||(l.left=o-(r>0?r:0))),l}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 r=this.get2DCursorLocation(t),i=r.lineIndex,s=r.charIndex>0?r.charIndex-1:0,o=this.getValueOfPropertyAt(i,s,"fontSize"),a=this.getObjectScaling().x*this.canvas.getZoom(),l=this.cursorWidth/a,c=this.getValueOfPropertyAt(i,s,"deltaY"),h=e.topOffset+(1-this._fontSizeFraction)*this.getHeightOfLine(i)/this.lineHeight-o*(1-this._fontSizeFraction);return{color:this.cursorColor||this.getValueOfPropertyAt(i,s,"fill"),opacity:this._currentCursorOpacity,left:e.left+e.leftOffset-l/2,top:h+e.top+c,width:l,height:o}}_renderCursor(t,e,r){const{color:i,opacity:s,left:o,top:a,width:l,height:c}=this.getCursorRenderingData(r,e);t.fillStyle=i,t.globalAlpha=s,t.fillRect(o,a,l,c)}renderSelection(t,e){const r={selectionStart:this.inCompositionMode?this.hiddenTextarea.selectionStart:this.selectionStart,selectionEnd:this.inCompositionMode?this.hiddenTextarea.selectionEnd:this.selectionEnd};this._renderSelection(t,r,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,r){const i=e.selectionStart,s=e.selectionEnd,o=this.textAlign.includes(Nt),a=this.get2DCursorLocation(i),l=this.get2DCursorLocation(s),c=a.lineIndex,h=l.lineIndex,u=a.charIndex<0?0:a.charIndex,d=l.charIndex<0?0:l.charIndex;for(let g=c;g<=h;g++){const f=this._getLineLeftOffset(g)||0;let m=this.getHeightOfLine(g),b=0,y=0,w=0;if(g===c&&(y=this.__charBounds[c][u].left),g>=c&&g<h)w=o&&!this.isEndOfWrapping(g)?this.width:this.getLineWidth(g)||5;else if(g===h)if(d===0)w=this.__charBounds[h][d].left;else{const A=this._getWidthOfCharSpacing();w=this.__charBounds[h][d-1].left+this.__charBounds[h][d-1].width-A}b=m,(this.lineHeight<1||g===h&&this.lineHeight>1)&&(m/=this.lineHeight);let O=r.left+f+y,k=m,S=0;const C=w-y;this.inCompositionMode?(t.fillStyle=this.compositionColor||"black",k=1,S=m):t.fillStyle=this.selectionColor,this.direction==="rtl"&&(this.textAlign===it||this.textAlign===Nt||this.textAlign===lr?O=this.width-O-C:this.textAlign===U||this.textAlign===Vr?O=r.left+f-w:this.textAlign!==W&&this.textAlign!==cr||(O=r.left+f-w)),t.fillRect(O,r.top+r.topOffset+S,C,k),r.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,at)}_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()}}p(qt,"ownDefaults",iu),p(qt,"type","IText"),E.setClass(qt),E.setClass(qt,"i-text");class xe extends qt{static getDefaults(){return v(v({},super.getDefaults()),xe.ownDefaults)}constructor(t,e){super(t,v(v({},xe.ownDefaults),e))}static createControls(){return{controls:Lc()}}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(Nt)&&this.enlargeSpaces(),this.height=this.calcTextHeight())}_generateStyleMap(t){let e=0,r=0,i=0;const s={};for(let o=0;o<t.graphemeLines.length;o++)t.graphemeText[i]===`
|
|
137
|
+
`&&o>0?(r=0,i++,e++):!this.splitByGrapheme&&this._reSpaceAndTab.test(t.graphemeText[i])&&o>0&&(r++,i++),s[o]={line:e,offset:r},i+=t.graphemeLines[o].length,r+=t.graphemeLines[o].length;return s}styleHas(t,e){if(this._styleMap&&!this.isWrapping){const r=this._styleMap[e];r&&(e=r.line)}return super.styleHas(t,e)}isEmptyStyles(t){if(!this.styles)return!0;let e,r=0,i=t+1,s=!1;const o=this._styleMap[t],a=this._styleMap[t+1];o&&(t=o.line,r=o.offset),a&&(i=a.line,s=i===t,e=a.offset);const l=t===void 0?this.styles:{line:this.styles[t]};for(const c in l)for(const h in l[c]){const u=parseInt(h,10);if(u>=r&&(!s||u<e))for(const d in l[c][h])return!1}return!0}_getStyleDeclaration(t,e){if(this._styleMap&&!this.isWrapping){const r=this._styleMap[t];if(!r)return{};t=r.line,e=r.offset+e}return super._getStyleDeclaration(t,e)}_setStyleDeclaration(t,e,r){const i=this._styleMap[t];super._setStyleDeclaration(i.line,i.offset+e,r)}_deleteStyleDeclaration(t,e){const r=this._styleMap[t];super._deleteStyleDeclaration(r.line,r.offset+e)}_getLineStyle(t){const e=this._styleMap[t];return!!this.styles[e.line]}_setLineStyle(t){const e=this._styleMap[t];super._setLineStyle(e.line)}_wrapText(t,e){this.isWrapping=!0;const r=this.getGraphemeDataForRender(t),i=[];for(let s=0;s<r.wordsData.length;s++)i.push(...this._wrapLine(s,e,r));return this.isWrapping=!1,i}getGraphemeDataForRender(t){const e=this.splitByGrapheme,r=e?"":" ";let i=0;return{wordsData:t.map((s,o)=>{let a=0;const l=e?this.graphemeSplit(s):this.wordSplit(s);return l.length===0?[{word:[],width:0}]:l.map(c=>{const h=e?[c]:this.graphemeSplit(c),u=this._measureWord(h,o,a);return i=Math.max(u,i),a+=h.length+r.length,{word:h,width:u}})}),largestWordWidth:i}}_measureWord(t,e){let r,i=arguments.length>2&&arguments[2]!==void 0?arguments[2]:0,s=0;for(let o=0,a=t.length;o<a;o++)s+=this._getGraphemeBox(t[o],e,o+i,r,!0).kernedWidth,r=t[o];return s}wordSplit(t){return t.split(this._wordJoiners)}_wrapLine(t,e,r){let{largestWordWidth:i,wordsData:s}=r,o=arguments.length>3&&arguments[3]!==void 0?arguments[3]:0;const a=this._getWidthOfCharSpacing(),l=this.splitByGrapheme,c=[],h=l?"":" ";let u=0,d=[],g=0,f=0,m=!0;e-=o;const b=Math.max(e,i,this.dynamicMinWidth),y=s[t];let w;for(g=0,w=0;w<y.length;w++){const{word:O,width:k}=y[w];g+=O.length,u+=f+k-a,u>b&&!m?(c.push(d),d=[],u=k,m=!0):u+=a,m||l||d.push(h),d=d.concat(O),f=l?0:this._measureWord([h],t,g),g++,m=!1}return w&&c.push(d),i+o>this.dynamicMinWidth&&(this.dynamicMinWidth=i-a+o),c}isEndOfWrapping(t){return!this._styleMap[t+1]||this._styleMap[t+1].line!==this._styleMap[t].line}missingNewlineOffset(t,e){return this.splitByGrapheme&&!e?this.isEndOfWrapping(t)?1:0:1}_splitTextIntoLines(t){const e=super._splitTextIntoLines(t),r=this._wrapText(e.lines,this.width),i=new Array(r.length);for(let s=0;s<r.length;s++)i[s]=r[s].join("");return e.lines=i,e.graphemeLines=r,e}getMinWidth(){return Math.max(this.minWidth,this.dynamicMinWidth)}_removeExtraneousStyles(){const t=new Map;for(const e in this._styleMap){const r=parseInt(e,10);if(this._textLines[r]){const i=this._styleMap[e].line;t.set("".concat(i),!0)}}for(const e in this.styles)t.has(e)||delete this.styles[e]}toObject(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:[];return super.toObject(["minWidth","splitByGrapheme",...t])}}p(xe,"type","Textbox"),p(xe,"textLayoutProperties",[...qt.textLayoutProperties,"width"]),p(xe,"ownDefaults",{minWidth:20,dynamicMinWidth:2,lockScalingFlip:!0,noScaleCache:!1,_wordJoiners:/[ \t\r]/,splitByGrapheme:!1}),E.setClass(xe);class oa extends $r{shouldPerformLayout(t){return!!t.target.clipPath&&super.shouldPerformLayout(t)}shouldLayoutClipPath(){return!1}calcLayoutResult(t,e){const{target:r}=t,{clipPath:i,group:s}=r;if(!i||!this.shouldPerformLayout(t))return;const{width:o,height:a}=ee(Ro(r,i)),l=new x(o,a);if(i.absolutePositioned)return{center:je(i.getRelativeCenterPoint(),void 0,s?s.calcTransformMatrix():void 0),size:l};{const c=i.getRelativeCenterPoint().transform(r.calcOwnMatrix(),!0);if(this.shouldPerformLayout(t)){const{center:h=new x,correction:u=new x}=this.calcBoundingBox(e,t)||{};return{center:h.add(c),correction:u.subtract(c),size:l}}return{center:r.getRelativeCenterPoint().add(c),size:l}}}}p(oa,"type","clip-path"),E.setClass(oa);class aa extends $r{getInitialSize(t,e){let{target:r}=t,{size:i}=e;return new x(r.width||i.x,r.height||i.y)}}p(aa,"type","fixed"),E.setClass(aa);class su extends fr{subscribeTargets(t){const e=t.target;t.targets.reduce((r,i)=>(i.parent&&r.add(i.parent),r),new Set).forEach(r=>{r.layoutManager.subscribeTargets({target:r,targets:[e]})})}unsubscribeTargets(t){const e=t.target,r=e.getObjects();t.targets.reduce((i,s)=>(s.parent&&i.add(s.parent),i),new Set).forEach(i=>{!r.some(s=>s.parent===i)&&i.layoutManager.unsubscribeTargets({target:i,targets:[e]})})}}class we extends ye{static getDefaults(){return v(v({},super.getDefaults()),we.ownDefaults)}constructor(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:[],e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};super(),Object.assign(this,we.ownDefaults),this.setOptions(e);const{left:r,top:i,layoutManager:s}=e;this.groupInit(t,{left:r,top:i,layoutManager:s??new su})}_shouldSetNestedCoords(){return!0}__objectSelectionMonitor(){}multiSelectAdd(){for(var t=arguments.length,e=new Array(t),r=0;r<t;r++)e[r]=arguments[r];this.multiSelectionStacking==="selection-order"?this.add(...e):e.forEach(i=>{const s=this._objects.findIndex(a=>a.isInFrontOf(i)),o=s===-1?this.size():s;this.insertAt(o,i)})}canEnterGroup(t){return this.getObjects().some(e=>e.isDescendantOf(t)||t.isDescendantOf(e))?(ce("error","ActiveSelection: circular object trees are not supported, this call has no effect"),!1):super.canEnterGroup(t)}enterGroup(t,e){t.parent&&t.parent===t.group?t.parent._exitGroup(t):t.group&&t.parent!==t.group&&t.group.remove(t),this._enterGroup(t,e)}exitGroup(t,e){this._exitGroup(t,e),t.parent&&t.parent._enterGroup(t,!0)}_onAfterObjectsChange(t,e){super._onAfterObjectsChange(t,e);const r=new Set;e.forEach(i=>{const{parent:s}=i;s&&r.add(s)}),t===ys?r.forEach(i=>{i._onAfterObjectsChange(Gr,e)}):r.forEach(i=>{i._set("dirty",!0)})}onDeselect(){return this.removeAll(),!1}toString(){return"#<ActiveSelection: (".concat(this.complexity(),")>")}shouldCache(){return!1}isOnACache(){return!1}_renderControls(t,e,r){t.save(),t.globalAlpha=this.isMoving?this.borderOpacityWhenMoving:1;const i=v(v({hasControls:!1},r),{},{forActiveSelection:!0});for(let s=0;s<this._objects.length;s++)this._objects[s]._renderControls(t,i);super._renderControls(t,e),t.restore()}}p(we,"type","ActiveSelection"),p(we,"ownDefaults",{multiSelectionStacking:"canvas-stacking"}),E.setClass(we),E.setClass(we,"activeSelection");class nu{constructor(){p(this,"resources",{})}applyFilters(t,e,r,i,s){const o=s.getContext("2d");if(!o)return;o.drawImage(e,0,0,r,i);const a={sourceWidth:r,sourceHeight:i,imageData:o.getImageData(0,0,r,i),originalEl:e,originalImageData:o.getImageData(0,0,r,i),canvasEl:s,ctx:o,filterBackend:this};t.forEach(c=>{c.applyTo(a)});const{imageData:l}=a;return l.width===r&&l.height===i||(s.width=l.width,s.height=l.height),o.putImageData(l,0,0),a}}class la{constructor(){let{tileSize:t=X.textureSize}=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};p(this,"aPosition",new Float32Array([0,0,0,1,1,0,1,1])),p(this,"resources",{}),this.tileSize=t,this.setupGLContext(t,t),this.captureGPUInfo()}setupGLContext(t,e){this.dispose(),this.createWebGLCanvas(t,e)}createWebGLCanvas(t,e){const r=At({width:t,height:e}),i=r.getContext("webgl",{alpha:!0,premultipliedAlpha:!1,depth:!1,stencil:!1,antialias:!1});i&&(i.clearColor(0,0,0,0),this.canvas=r,this.gl=i)}applyFilters(t,e,r,i,s,o){const a=this.gl,l=s.getContext("2d");if(!a||!l)return;let c;o&&(c=this.getCachedTexture(o,e));const h={originalWidth:e.width||e.naturalWidth||0,originalHeight:e.height||e.naturalHeight||0,sourceWidth:r,sourceHeight:i,destinationWidth:r,destinationHeight:i,context:a,sourceTexture:this.createTexture(a,r,i,c?void 0:e),targetTexture:this.createTexture(a,r,i),originalTexture:c||this.createTexture(a,r,i,c?void 0:e),passes:t.length,webgl:!0,aPosition:this.aPosition,programCache:this.programCache,pass:0,filterBackend:this,targetCanvas:s},u=a.createFramebuffer();return a.bindFramebuffer(a.FRAMEBUFFER,u),t.forEach(d=>{d&&d.applyTo(h)}),function(d){const g=d.targetCanvas,f=g.width,m=g.height,b=d.destinationWidth,y=d.destinationHeight;f===b&&m===y||(g.width=b,g.height=y)}(h),this.copyGLTo2D(a,h),a.bindTexture(a.TEXTURE_2D,null),a.deleteTexture(h.sourceTexture),a.deleteTexture(h.targetTexture),a.deleteFramebuffer(u),l.setTransform(1,0,0,1,0,0),h}dispose(){this.canvas&&(this.canvas=null,this.gl=null),this.clearWebGLCaches()}clearWebGLCaches(){this.programCache={},this.textureCache={}}createTexture(t,e,r,i,s){const{NEAREST:o,TEXTURE_2D:a,RGBA:l,UNSIGNED_BYTE:c,CLAMP_TO_EDGE:h,TEXTURE_MAG_FILTER:u,TEXTURE_MIN_FILTER:d,TEXTURE_WRAP_S:g,TEXTURE_WRAP_T:f}=t,m=t.createTexture();return t.bindTexture(a,m),t.texParameteri(a,u,s||o),t.texParameteri(a,d,s||o),t.texParameteri(a,g,h),t.texParameteri(a,f,h),i?t.texImage2D(a,0,l,l,c,i):t.texImage2D(a,0,l,e,r,0,l,c,null),m}getCachedTexture(t,e,r){const{textureCache:i}=this;if(i[t])return i[t];{const s=this.createTexture(this.gl,e.width,e.height,e,r);return s&&(i[t]=s),s}}evictCachesForKey(t){this.textureCache[t]&&(this.gl.deleteTexture(this.textureCache[t]),delete this.textureCache[t])}copyGLTo2D(t,e){const r=t.canvas,i=e.targetCanvas,s=i.getContext("2d");if(!s)return;s.translate(0,i.height),s.scale(1,-1);const o=r.height-i.height;s.drawImage(r,0,o,i.width,i.height,0,0,i.width,i.height)}copyGLTo2DPutImageData(t,e){const r=e.targetCanvas.getContext("2d"),i=e.destinationWidth,s=e.destinationHeight,o=i*s*4;if(!r)return;const a=new Uint8Array(this.imageBuffer,0,o),l=new Uint8ClampedArray(this.imageBuffer,0,o);t.readPixels(0,0,i,s,t.RGBA,t.UNSIGNED_BYTE,a);const c=new ImageData(l,i,s);r.putImageData(c,0,0)}captureGPUInfo(){if(this.gpuInfo)return this.gpuInfo;const t=this.gl,e={renderer:"",vendor:""};if(!t)return e;const r=t.getExtension("WEBGL_debug_renderer_info");if(r){const i=t.getParameter(r.UNMASKED_RENDERER_WEBGL),s=t.getParameter(r.UNMASKED_VENDOR_WEBGL);i&&(e.renderer=i.toLowerCase()),s&&(e.vendor=s.toLowerCase())}return this.gpuInfo=e,e}}let Ds;function ou(){const{WebGLProbe:n}=Gt();return n.queryWebGL(Qt()),X.enableGLFiltering&&n.isSupported(X.textureSize)?new la({tileSize:X.textureSize}):new nu}function Ms(){return!Ds&&(!(arguments.length>0&&arguments[0]!==void 0)||arguments[0])&&(Ds=ou()),Ds}const au=["filters","resizeFilter","src","crossOrigin","type"],ca=["cropX","cropY"];class Ot extends ut{static getDefaults(){return v(v({},super.getDefaults()),Ot.ownDefaults)}constructor(t,e){super(),p(this,"_lastScaleX",1),p(this,"_lastScaleY",1),p(this,"_filterScalingX",1),p(this,"_filterScalingY",1),this.filters=[],Object.assign(this,Ot.ownDefaults),this.setOptions(e),this.cacheKey="texture".concat(ue()),this.setElement(typeof t=="string"?(this.canvas&&Bt(this.canvas.getElement())||ke()).getElementById(t):t,e)}getElement(){return this._element}setElement(t){var e;let r=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};this.removeTexture(this.cacheKey),this.removeTexture("".concat(this.cacheKey,"_filtered")),this._element=t,this._originalElement=t,this._setWidthHeight(r),(e=t.classList)===null||e===void 0||e.add(Ot.CSS_CANVAS),this.filters.length!==0&&this.applyFilters(),this.resizeFilter&&this.applyResizeFilters()}removeTexture(t){const e=Ms(!1);e instanceof la&&e.evictCachesForKey(t)}dispose(){super.dispose(),this.removeTexture(this.cacheKey),this.removeTexture("".concat(this.cacheKey,"_filtered")),this._cacheContext=null,["_originalElement","_element","_filteredEl","_cacheCanvas"].forEach(t=>{const e=this[t];e&&Gt().dispose(e),this[t]=void 0})}getCrossOrigin(){return this._originalElement&&(this._originalElement.crossOrigin||null)}getOriginalSize(){const t=this.getElement();return t?{width:t.naturalWidth||t.width,height:t.naturalHeight||t.height}:{width:0,height:0}}_stroke(t){if(!this.stroke||this.strokeWidth===0)return;const e=this.width/2,r=this.height/2;t.beginPath(),t.moveTo(-e,-r),t.lineTo(e,-r),t.lineTo(e,r),t.lineTo(-e,r),t.lineTo(-e,-r),t.closePath()}toObject(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:[];const e=[];return this.filters.forEach(r=>{r&&e.push(r.toObject())}),v(v({},super.toObject([...ca,...t])),{},{src:this.getSrc(),crossOrigin:this.getCrossOrigin(),filters:e},this.resizeFilter?{resizeFilter:this.resizeFilter.toObject()}:{})}hasCrop(){return!!this.cropX||!!this.cropY||this.width<this._element.width||this.height<this._element.height}_toSVG(){const t=[],e=this._element,r=-this.width/2,i=-this.height/2;let s=[],o=[],a="",l="";if(!e)return[];if(this.hasCrop()){const c=ue();s.push('<clipPath id="imageCrop_'+c+`">
|
|
138
|
+
`,' <rect x="'+r+'" y="'+i+'" width="'+this.width+'" height="'+this.height+`" />
|
|
139
|
+
`,`</clipPath>
|
|
140
|
+
`),a=' clip-path="url(#imageCrop_'+c+')" '}if(this.imageSmoothing||(l=' image-rendering="optimizeSpeed"'),t.push(" <image ","COMMON_PARTS",'xlink:href="'.concat(this.getSvgSrc(!0),'" x="').concat(r-this.cropX,'" y="').concat(i-this.cropY,'" width="').concat(e.width||e.naturalWidth,'" height="').concat(e.height||e.naturalHeight,'"').concat(l).concat(a,`></image>
|
|
141
|
+
`)),this.stroke||this.strokeDashArray){const c=this.fill;this.fill=null,o=[' <rect x="'.concat(r,'" y="').concat(i,'" width="').concat(this.width,'" height="').concat(this.height,'" style="').concat(this.getSvgStyles(),`" />
|
|
142
|
+
`)],this.fill=c}return s=this.paintFirst!==at?s.concat(o,t):s.concat(t,o),s}getSrc(t){const e=t?this._element:this._originalElement;return e?e.toDataURL?e.toDataURL():this.srcFromAttribute?e.getAttribute("src")||"":e.src:this.src||""}getSvgSrc(t){return this.getSrc(t)}setSrc(t){let{crossOrigin:e,signal:r}=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};return Lr(t,{crossOrigin:e,signal:r}).then(i=>{e!==void 0&&this.set({crossOrigin:e}),this.setElement(i)})}toString(){return'#<Image: { src: "'.concat(this.getSrc(),'" }>')}applyResizeFilters(){const t=this.resizeFilter,e=this.minimumScaleTrigger,r=this.getTotalObjectScaling(),i=r.x,s=r.y,o=this._filteredEl||this._originalElement;if(this.group&&this.set("dirty",!0),!t||i>e&&s>e)return this._element=o,this._filterScalingX=1,this._filterScalingY=1,this._lastScaleX=i,void(this._lastScaleY=s);const a=At(o),{width:l,height:c}=o;this._element=a,this._lastScaleX=t.scaleX=i,this._lastScaleY=t.scaleY=s,Ms().applyFilters([t],o,l,c,this._element),this._filterScalingX=a.width/this._originalElement.width,this._filterScalingY=a.height/this._originalElement.height}applyFilters(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:this.filters||[];if(t=t.filter(s=>s&&!s.isNeutralState()),this.set("dirty",!0),this.removeTexture("".concat(this.cacheKey,"_filtered")),t.length===0)return this._element=this._originalElement,this._filteredEl=void 0,this._filterScalingX=1,void(this._filterScalingY=1);const e=this._originalElement,r=e.naturalWidth||e.width,i=e.naturalHeight||e.height;if(this._element===this._originalElement){const s=At({width:r,height:i});this._element=s,this._filteredEl=s}else this._filteredEl&&(this._element=this._filteredEl,this._filteredEl.getContext("2d").clearRect(0,0,r,i),this._lastScaleX=1,this._lastScaleY=1);Ms().applyFilters(t,this._originalElement,r,i,this._element,this.cacheKey),this._originalElement.width===this._element.width&&this._originalElement.height===this._element.height||(this._filterScalingX=this._element.width/this._originalElement.width,this._filterScalingY=this._element.height/this._originalElement.height)}_render(t){t.imageSmoothingEnabled=this.imageSmoothing,this.isMoving!==!0&&this.resizeFilter&&this._needsResize()&&this.applyResizeFilters(),this._stroke(t),this._renderPaintInOrder(t)}drawCacheOnCanvas(t){t.imageSmoothingEnabled=this.imageSmoothing,super.drawCacheOnCanvas(t)}shouldCache(){return this.needsItsOwnCache()}_renderFill(t){const e=this._element;if(!e)return;const r=this._filterScalingX,i=this._filterScalingY,s=this.width,o=this.height,a=Math.max(this.cropX,0),l=Math.max(this.cropY,0),c=e.naturalWidth||e.width,h=e.naturalHeight||e.height,u=a*r,d=l*i,g=Math.min(s*r,c-u),f=Math.min(o*i,h-d),m=-s/2,b=-o/2,y=Math.min(s,c/r-a),w=Math.min(o,h/i-l);e&&t.drawImage(e,u,d,g,f,m,b,y,w)}_needsResize(){const t=this.getTotalObjectScaling();return t.x!==this._lastScaleX||t.y!==this._lastScaleY}_resetWidthHeight(){this.set(this.getOriginalSize())}_setWidthHeight(){let{width:t,height:e}=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};const r=this.getOriginalSize();this.width=t||r.width,this.height=e||r.height}parsePreserveAspectRatioAttribute(){const t=Jl(this.preserveAspectRatio||""),e=this.width,r=this.height,i={width:e,height:r};let s,o=this._element.width,a=this._element.height,l=1,c=1,h=0,u=0,d=0,g=0;return!t||t.alignX===bt&&t.alignY===bt?(l=e/o,c=r/a):(t.meetOrSlice==="meet"&&(l=c=fh(this._element,i),s=(e-o*l)/2,t.alignX==="Min"&&(h=-s),t.alignX==="Max"&&(h=s),s=(r-a*c)/2,t.alignY==="Min"&&(u=-s),t.alignY==="Max"&&(u=s)),t.meetOrSlice==="slice"&&(l=c=ph(this._element,i),s=o-e/l,t.alignX==="Mid"&&(d=s/2),t.alignX==="Max"&&(d=s),s=a-r/c,t.alignY==="Mid"&&(g=s/2),t.alignY==="Max"&&(g=s),o=e/l,a=r/c)),{width:o,height:a,scaleX:l,scaleY:c,offsetLeft:h,offsetTop:u,cropX:d,cropY:g}}static fromObject(t,e){let{filters:r,resizeFilter:i,src:s,crossOrigin:o,type:a}=t,l=J(t,au);return Promise.all([Lr(s,v(v({},e),{},{crossOrigin:o})),r&&sr(r,e),i&&sr([i],e),Fr(l,e)]).then(c=>{let[h,u=[],[d]=[],g={}]=c;return new this(h,v(v({},l),{},{src:s,filters:u,resizeFilter:d},g))})}static fromURL(t){let{crossOrigin:e=null,signal:r}=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},i=arguments.length>2?arguments[2]:void 0;return Lr(t,{crossOrigin:e,signal:r}).then(s=>new this(s,i))}static async fromElement(t){let e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},r=arguments.length>2?arguments[2]:void 0;const i=se(t,this.ATTRIBUTE_NAMES,r);return this.fromURL(i["xlink:href"]||i.href,e,i).catch(s=>(ce("log","Unable to parse Image",s),null))}}p(Ot,"type","Image"),p(Ot,"cacheProperties",[...re,...ca]),p(Ot,"ownDefaults",{strokeWidth:0,srcFromAttribute:!1,minimumScaleTrigger:.5,cropX:0,cropY:0,imageSmoothing:!0}),p(Ot,"CSS_CANVAS","canvas-img"),p(Ot,"ATTRIBUTE_NAMES",[...de,"x","y","width","height","preserveAspectRatio","xlink:href","href","crossOrigin","image-rendering"]),E.setClass(Ot),E.setSVGClass(Ot),Wr(["pattern","defs","symbol","metadata","clipPath","mask","desc"]);const ni=n=>n.webgl!==void 0,Es="precision highp float",lu=`
|
|
143
|
+
`.concat(Es,`;
|
|
144
|
+
varying vec2 vTexCoord;
|
|
145
|
+
uniform sampler2D uTexture;
|
|
146
|
+
void main() {
|
|
147
|
+
gl_FragColor = texture2D(uTexture, vTexCoord);
|
|
148
|
+
}`),cu=["type"],hu=["type"],uu=new RegExp(Es,"g");class lt{get type(){return this.constructor.type}constructor(){let t=J(arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},cu);Object.assign(this,this.constructor.defaults,t)}getFragmentSource(){return lu}getVertexSource(){return`
|
|
149
|
+
attribute vec2 aPosition;
|
|
150
|
+
varying vec2 vTexCoord;
|
|
151
|
+
void main() {
|
|
152
|
+
vTexCoord = aPosition;
|
|
153
|
+
gl_Position = vec4(aPosition * 2.0 - 1.0, 0.0, 1.0);
|
|
154
|
+
}`}createProgram(t){let e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:this.getFragmentSource(),r=arguments.length>2&&arguments[2]!==void 0?arguments[2]:this.getVertexSource();const{WebGLProbe:{GLPrecision:i="highp"}}=Gt();i!=="highp"&&(e=e.replace(uu,Es.replace("highp",i)));const s=t.createShader(t.VERTEX_SHADER),o=t.createShader(t.FRAGMENT_SHADER),a=t.createProgram();if(!s||!o||!a)throw new Ut("Vertex, fragment shader or program creation error");if(t.shaderSource(s,r),t.compileShader(s),!t.getShaderParameter(s,t.COMPILE_STATUS))throw new Ut("Vertex shader compile error for ".concat(this.type,": ").concat(t.getShaderInfoLog(s)));if(t.shaderSource(o,e),t.compileShader(o),!t.getShaderParameter(o,t.COMPILE_STATUS))throw new Ut("Fragment shader compile error for ".concat(this.type,": ").concat(t.getShaderInfoLog(o)));if(t.attachShader(a,s),t.attachShader(a,o),t.linkProgram(a),!t.getProgramParameter(a,t.LINK_STATUS))throw new Ut('Shader link error for "'.concat(this.type,'" ').concat(t.getProgramInfoLog(a)));const l=this.getUniformLocations(t,a)||{};return l.uStepW=t.getUniformLocation(a,"uStepW"),l.uStepH=t.getUniformLocation(a,"uStepH"),{program:a,attributeLocations:this.getAttributeLocations(t,a),uniformLocations:l}}getAttributeLocations(t,e){return{aPosition:t.getAttribLocation(e,"aPosition")}}getUniformLocations(t,e){const r=this.constructor.uniformLocations,i={};for(let s=0;s<r.length;s++)i[r[s]]=t.getUniformLocation(e,r[s]);return i}sendAttributeData(t,e,r){const i=e.aPosition,s=t.createBuffer();t.bindBuffer(t.ARRAY_BUFFER,s),t.enableVertexAttribArray(i),t.vertexAttribPointer(i,2,t.FLOAT,!1,0,0),t.bufferData(t.ARRAY_BUFFER,r,t.STATIC_DRAW)}_setupFrameBuffer(t){const e=t.context;if(t.passes>1){const r=t.destinationWidth,i=t.destinationHeight;t.sourceWidth===r&&t.sourceHeight===i||(e.deleteTexture(t.targetTexture),t.targetTexture=t.filterBackend.createTexture(e,r,i)),e.framebufferTexture2D(e.FRAMEBUFFER,e.COLOR_ATTACHMENT0,e.TEXTURE_2D,t.targetTexture,0)}else e.bindFramebuffer(e.FRAMEBUFFER,null),e.finish()}_swapTextures(t){t.passes--,t.pass++;const e=t.targetTexture;t.targetTexture=t.sourceTexture,t.sourceTexture=e}isNeutralState(t){return!1}applyTo(t){ni(t)?(this._setupFrameBuffer(t),this.applyToWebGL(t),this._swapTextures(t)):this.applyTo2d(t)}applyTo2d(t){}getCacheKey(){return this.type}retrieveShader(t){const e=this.getCacheKey();return t.programCache[e]||(t.programCache[e]=this.createProgram(t.context)),t.programCache[e]}applyToWebGL(t){const e=t.context,r=this.retrieveShader(t);t.pass===0&&t.originalTexture?e.bindTexture(e.TEXTURE_2D,t.originalTexture):e.bindTexture(e.TEXTURE_2D,t.sourceTexture),e.useProgram(r.program),this.sendAttributeData(e,r.attributeLocations,t.aPosition),e.uniform1f(r.uniformLocations.uStepW,1/t.sourceWidth),e.uniform1f(r.uniformLocations.uStepH,1/t.sourceHeight),this.sendUniformData(e,r.uniformLocations),e.viewport(0,0,t.destinationWidth,t.destinationHeight),e.drawArrays(e.TRIANGLE_STRIP,0,4)}bindAdditionalTexture(t,e,r){t.activeTexture(r),t.bindTexture(t.TEXTURE_2D,e),t.activeTexture(t.TEXTURE0)}unbindAdditionalTexture(t,e){t.activeTexture(e),t.bindTexture(t.TEXTURE_2D,null),t.activeTexture(t.TEXTURE0)}sendUniformData(t,e){}createHelpLayer(t){if(!t.helpLayer){const{sourceWidth:e,sourceHeight:r}=t,i=At({width:e,height:r});t.helpLayer=i}}toObject(){const t=Object.keys(this.constructor.defaults||{});return v({type:this.type},t.reduce((e,r)=>(e[r]=this[r],e),{}))}toJSON(){return this.toObject()}static async fromObject(t,e){return new this(J(t,hu))}}p(lt,"type","BaseFilter"),p(lt,"uniformLocations",[]);const du={multiply:`gl_FragColor.rgb *= uColor.rgb;
|
|
155
|
+
`,screen:`gl_FragColor.rgb = 1.0 - (1.0 - gl_FragColor.rgb) * (1.0 - uColor.rgb);
|
|
156
|
+
`,add:`gl_FragColor.rgb += uColor.rgb;
|
|
157
|
+
`,difference:`gl_FragColor.rgb = abs(gl_FragColor.rgb - uColor.rgb);
|
|
158
|
+
`,subtract:`gl_FragColor.rgb -= uColor.rgb;
|
|
159
|
+
`,lighten:`gl_FragColor.rgb = max(gl_FragColor.rgb, uColor.rgb);
|
|
160
|
+
`,darken:`gl_FragColor.rgb = min(gl_FragColor.rgb, uColor.rgb);
|
|
161
|
+
`,exclusion:`gl_FragColor.rgb += uColor.rgb - 2.0 * (uColor.rgb * gl_FragColor.rgb);
|
|
162
|
+
`,overlay:`
|
|
163
|
+
if (uColor.r < 0.5) {
|
|
164
|
+
gl_FragColor.r *= 2.0 * uColor.r;
|
|
165
|
+
} else {
|
|
166
|
+
gl_FragColor.r = 1.0 - 2.0 * (1.0 - gl_FragColor.r) * (1.0 - uColor.r);
|
|
167
|
+
}
|
|
168
|
+
if (uColor.g < 0.5) {
|
|
169
|
+
gl_FragColor.g *= 2.0 * uColor.g;
|
|
170
|
+
} else {
|
|
171
|
+
gl_FragColor.g = 1.0 - 2.0 * (1.0 - gl_FragColor.g) * (1.0 - uColor.g);
|
|
172
|
+
}
|
|
173
|
+
if (uColor.b < 0.5) {
|
|
174
|
+
gl_FragColor.b *= 2.0 * uColor.b;
|
|
175
|
+
} else {
|
|
176
|
+
gl_FragColor.b = 1.0 - 2.0 * (1.0 - gl_FragColor.b) * (1.0 - uColor.b);
|
|
177
|
+
}
|
|
178
|
+
`,tint:`
|
|
179
|
+
gl_FragColor.rgb *= (1.0 - uColor.a);
|
|
180
|
+
gl_FragColor.rgb += uColor.rgb;
|
|
181
|
+
`};class oi extends lt{getCacheKey(){return"".concat(this.type,"_").concat(this.mode)}getFragmentSource(){return`
|
|
182
|
+
precision highp float;
|
|
183
|
+
uniform sampler2D uTexture;
|
|
184
|
+
uniform vec4 uColor;
|
|
185
|
+
varying vec2 vTexCoord;
|
|
186
|
+
void main() {
|
|
187
|
+
vec4 color = texture2D(uTexture, vTexCoord);
|
|
188
|
+
gl_FragColor = color;
|
|
189
|
+
if (color.a > 0.0) {
|
|
190
|
+
`.concat(du[this.mode],`
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
`)}applyTo2d(t){let{imageData:{data:e}}=t;const r=new G(this.color).getSource(),i=this.alpha,s=r[0]*i,o=r[1]*i,a=r[2]*i,l=1-i;for(let c=0;c<e.length;c+=4){const h=e[c],u=e[c+1],d=e[c+2];let g,f,m;switch(this.mode){case"multiply":g=h*s/255,f=u*o/255,m=d*a/255;break;case"screen":g=255-(255-h)*(255-s)/255,f=255-(255-u)*(255-o)/255,m=255-(255-d)*(255-a)/255;break;case"add":g=h+s,f=u+o,m=d+a;break;case"difference":g=Math.abs(h-s),f=Math.abs(u-o),m=Math.abs(d-a);break;case"subtract":g=h-s,f=u-o,m=d-a;break;case"darken":g=Math.min(h,s),f=Math.min(u,o),m=Math.min(d,a);break;case"lighten":g=Math.max(h,s),f=Math.max(u,o),m=Math.max(d,a);break;case"overlay":g=s<128?2*h*s/255:255-2*(255-h)*(255-s)/255,f=o<128?2*u*o/255:255-2*(255-u)*(255-o)/255,m=a<128?2*d*a/255:255-2*(255-d)*(255-a)/255;break;case"exclusion":g=s+h-2*s*h/255,f=o+u-2*o*u/255,m=a+d-2*a*d/255;break;case"tint":g=s+h*l,f=o+u*l,m=a+d*l}e[c]=g,e[c+1]=f,e[c+2]=m}}sendUniformData(t,e){const r=new G(this.color).getSource();r[0]=this.alpha*r[0]/255,r[1]=this.alpha*r[1]/255,r[2]=this.alpha*r[2]/255,r[3]=this.alpha,t.uniform4fv(e.uColor,r)}}p(oi,"defaults",{color:"#F95C63",mode:"multiply",alpha:1}),p(oi,"type","BlendColor"),p(oi,"uniformLocations",["uColor"]),E.setClass(oi);const gu={multiply:`
|
|
194
|
+
precision highp float;
|
|
195
|
+
uniform sampler2D uTexture;
|
|
196
|
+
uniform sampler2D uImage;
|
|
197
|
+
uniform vec4 uColor;
|
|
198
|
+
varying vec2 vTexCoord;
|
|
199
|
+
varying vec2 vTexCoord2;
|
|
200
|
+
void main() {
|
|
201
|
+
vec4 color = texture2D(uTexture, vTexCoord);
|
|
202
|
+
vec4 color2 = texture2D(uImage, vTexCoord2);
|
|
203
|
+
color.rgba *= color2.rgba;
|
|
204
|
+
gl_FragColor = color;
|
|
205
|
+
}
|
|
206
|
+
`,mask:`
|
|
207
|
+
precision highp float;
|
|
208
|
+
uniform sampler2D uTexture;
|
|
209
|
+
uniform sampler2D uImage;
|
|
210
|
+
uniform vec4 uColor;
|
|
211
|
+
varying vec2 vTexCoord;
|
|
212
|
+
varying vec2 vTexCoord2;
|
|
213
|
+
void main() {
|
|
214
|
+
vec4 color = texture2D(uTexture, vTexCoord);
|
|
215
|
+
vec4 color2 = texture2D(uImage, vTexCoord2);
|
|
216
|
+
color.a = color2.a;
|
|
217
|
+
gl_FragColor = color;
|
|
218
|
+
}
|
|
219
|
+
`},fu=["type","image"];class ai extends lt{getCacheKey(){return"".concat(this.type,"_").concat(this.mode)}getFragmentSource(){return gu[this.mode]}getVertexSource(){return`
|
|
220
|
+
attribute vec2 aPosition;
|
|
221
|
+
varying vec2 vTexCoord;
|
|
222
|
+
varying vec2 vTexCoord2;
|
|
223
|
+
uniform mat3 uTransformMatrix;
|
|
224
|
+
void main() {
|
|
225
|
+
vTexCoord = aPosition;
|
|
226
|
+
vTexCoord2 = (uTransformMatrix * vec3(aPosition, 1.0)).xy;
|
|
227
|
+
gl_Position = vec4(aPosition * 2.0 - 1.0, 0.0, 1.0);
|
|
228
|
+
}
|
|
229
|
+
`}applyToWebGL(t){const e=t.context,r=this.createTexture(t.filterBackend,this.image);this.bindAdditionalTexture(e,r,e.TEXTURE1),super.applyToWebGL(t),this.unbindAdditionalTexture(e,e.TEXTURE1)}createTexture(t,e){return t.getCachedTexture(e.cacheKey,e.getElement())}calculateMatrix(){const t=this.image,{width:e,height:r}=t.getElement();return[1/t.scaleX,0,0,0,1/t.scaleY,0,-t.left/e,-t.top/r,1]}applyTo2d(t){let{imageData:{data:e,width:r,height:i},filterBackend:{resources:s}}=t;const o=this.image;s.blendImage||(s.blendImage=Qt());const a=s.blendImage,l=a.getContext("2d");a.width!==r||a.height!==i?(a.width=r,a.height=i):l.clearRect(0,0,r,i),l.setTransform(o.scaleX,0,0,o.scaleY,o.left,o.top),l.drawImage(o.getElement(),0,0,r,i);const c=l.getImageData(0,0,r,i).data;for(let h=0;h<e.length;h+=4){const u=e[h],d=e[h+1],g=e[h+2],f=e[h+3],m=c[h],b=c[h+1],y=c[h+2],w=c[h+3];switch(this.mode){case"multiply":e[h]=u*m/255,e[h+1]=d*b/255,e[h+2]=g*y/255,e[h+3]=f*w/255;break;case"mask":e[h+3]=w}}}sendUniformData(t,e){const r=this.calculateMatrix();t.uniform1i(e.uImage,1),t.uniformMatrix3fv(e.uTransformMatrix,!1,r)}toObject(){return v(v({},super.toObject()),{},{image:this.image&&this.image.toObject()})}static async fromObject(t,e){let{type:r,image:i}=t,s=J(t,fu);return Ot.fromObject(i,e).then(o=>new this(v(v({},s),{},{image:o})))}}p(ai,"type","BlendImage"),p(ai,"defaults",{mode:"multiply",alpha:1}),p(ai,"uniformLocations",["uTransformMatrix","uImage"]),E.setClass(ai);class li extends lt{getFragmentSource(){return`
|
|
230
|
+
precision highp float;
|
|
231
|
+
uniform sampler2D uTexture;
|
|
232
|
+
uniform vec2 uDelta;
|
|
233
|
+
varying vec2 vTexCoord;
|
|
234
|
+
const float nSamples = 15.0;
|
|
235
|
+
vec3 v3offset = vec3(12.9898, 78.233, 151.7182);
|
|
236
|
+
float random(vec3 scale) {
|
|
237
|
+
/* use the fragment position for a different seed per-pixel */
|
|
238
|
+
return fract(sin(dot(gl_FragCoord.xyz, scale)) * 43758.5453);
|
|
239
|
+
}
|
|
240
|
+
void main() {
|
|
241
|
+
vec4 color = vec4(0.0);
|
|
242
|
+
float totalC = 0.0;
|
|
243
|
+
float totalA = 0.0;
|
|
244
|
+
float offset = random(v3offset);
|
|
245
|
+
for (float t = -nSamples; t <= nSamples; t++) {
|
|
246
|
+
float percent = (t + offset - 0.5) / nSamples;
|
|
247
|
+
vec4 sample = texture2D(uTexture, vTexCoord + uDelta * percent);
|
|
248
|
+
float weight = 1.0 - abs(percent);
|
|
249
|
+
float alpha = weight * sample.a;
|
|
250
|
+
color.rgb += sample.rgb * alpha;
|
|
251
|
+
color.a += alpha;
|
|
252
|
+
totalA += weight;
|
|
253
|
+
totalC += alpha;
|
|
254
|
+
}
|
|
255
|
+
gl_FragColor.rgb = color.rgb / totalC;
|
|
256
|
+
gl_FragColor.a = color.a / totalA;
|
|
257
|
+
}
|
|
258
|
+
`}applyTo(t){ni(t)?(this.aspectRatio=t.sourceWidth/t.sourceHeight,t.passes++,this._setupFrameBuffer(t),this.horizontal=!0,this.applyToWebGL(t),this._swapTextures(t),this._setupFrameBuffer(t),this.horizontal=!1,this.applyToWebGL(t),this._swapTextures(t)):this.applyTo2d(t)}applyTo2d(t){let{imageData:{data:e,width:r,height:i}}=t;this.aspectRatio=r/i,this.horizontal=!0;let s=this.getBlurValue()*r;const o=new Uint8ClampedArray(e),a=15,l=4*r;for(let c=0;c<e.length;c+=4){let h=0,u=0,d=0,g=0,f=0;const m=c-c%l,b=m+l;for(let y=-14;y<a;y++){const w=y/a,O=4*Math.floor(s*w),k=1-Math.abs(w);let S=c+O;S<m?S=m:S>b&&(S=b);const C=e[S+3]*k;h+=e[S]*C,u+=e[S+1]*C,d+=e[S+2]*C,g+=C,f+=k}o[c]=h/g,o[c+1]=u/g,o[c+2]=d/g,o[c+3]=g/f}this.horizontal=!1,s=this.getBlurValue()*i;for(let c=0;c<o.length;c+=4){let h=0,u=0,d=0,g=0,f=0;const m=c%l,b=o.length-l+m;for(let y=-14;y<a;y++){const w=y/a,O=Math.floor(s*w)*l,k=1-Math.abs(w);let S=c+O;S<m?S=m:S>b&&(S=b);const C=o[S+3]*k;h+=o[S]*C,u+=o[S+1]*C,d+=o[S+2]*C,g+=C,f+=k}e[c]=h/g,e[c+1]=u/g,e[c+2]=d/g,e[c+3]=g/f}}sendUniformData(t,e){const r=this.chooseRightDelta();t.uniform2fv(e.uDelta,r)}isNeutralState(){return this.blur===0}getBlurValue(){let t=1;const{horizontal:e,aspectRatio:r}=this;return e?r>1&&(t=1/r):r<1&&(t=r),t*this.blur*.12}chooseRightDelta(){const t=this.getBlurValue();return this.horizontal?[t,0]:[0,t]}}p(li,"type","Blur"),p(li,"defaults",{blur:0}),p(li,"uniformLocations",["uDelta"]),E.setClass(li);class ci extends lt{getFragmentSource(){return`
|
|
259
|
+
precision highp float;
|
|
260
|
+
uniform sampler2D uTexture;
|
|
261
|
+
uniform float uBrightness;
|
|
262
|
+
varying vec2 vTexCoord;
|
|
263
|
+
void main() {
|
|
264
|
+
vec4 color = texture2D(uTexture, vTexCoord);
|
|
265
|
+
color.rgb += uBrightness;
|
|
266
|
+
gl_FragColor = color;
|
|
267
|
+
}
|
|
268
|
+
`}applyTo2d(t){let{imageData:{data:e}}=t;const r=Math.round(255*this.brightness);for(let i=0;i<e.length;i+=4)e[i]+=r,e[i+1]+=r,e[i+2]+=r}isNeutralState(){return this.brightness===0}sendUniformData(t,e){t.uniform1f(e.uBrightness,this.brightness)}}p(ci,"type","Brightness"),p(ci,"defaults",{brightness:0}),p(ci,"uniformLocations",["uBrightness"]),E.setClass(ci);const ha={matrix:[1,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,1,0],colorsOnly:!0};class Ve extends lt{getFragmentSource(){return`
|
|
269
|
+
precision highp float;
|
|
270
|
+
uniform sampler2D uTexture;
|
|
271
|
+
varying vec2 vTexCoord;
|
|
272
|
+
uniform mat4 uColorMatrix;
|
|
273
|
+
uniform vec4 uConstants;
|
|
274
|
+
void main() {
|
|
275
|
+
vec4 color = texture2D(uTexture, vTexCoord);
|
|
276
|
+
color *= uColorMatrix;
|
|
277
|
+
color += uConstants;
|
|
278
|
+
gl_FragColor = color;
|
|
279
|
+
}`}applyTo2d(t){const e=t.imageData.data,r=this.matrix,i=this.colorsOnly;for(let s=0;s<e.length;s+=4){const o=e[s],a=e[s+1],l=e[s+2];if(e[s]=o*r[0]+a*r[1]+l*r[2]+255*r[4],e[s+1]=o*r[5]+a*r[6]+l*r[7]+255*r[9],e[s+2]=o*r[10]+a*r[11]+l*r[12]+255*r[14],!i){const c=e[s+3];e[s]+=c*r[3],e[s+1]+=c*r[8],e[s+2]+=c*r[13],e[s+3]=o*r[15]+a*r[16]+l*r[17]+c*r[18]+255*r[19]}}}sendUniformData(t,e){const r=this.matrix,i=[r[0],r[1],r[2],r[3],r[5],r[6],r[7],r[8],r[10],r[11],r[12],r[13],r[15],r[16],r[17],r[18]],s=[r[4],r[9],r[14],r[19]];t.uniformMatrix4fv(e.uColorMatrix,!1,i),t.uniform4fv(e.uConstants,s)}toObject(){return v(v({},super.toObject()),{},{matrix:[...this.matrix]})}}function Ce(n,t){var e;const r=(p(e=class extends Ve{toObject(){return{type:this.type,colorsOnly:this.colorsOnly}}},"type",n),p(e,"defaults",{colorsOnly:!1,matrix:t}),e);return E.setClass(r,n),r}p(Ve,"type","ColorMatrix"),p(Ve,"defaults",ha),p(Ve,"uniformLocations",["uColorMatrix","uConstants"]),E.setClass(Ve),Ce("Brownie",[.5997,.34553,-.27082,0,.186,-.0377,.86095,.15059,0,-.1449,.24113,-.07441,.44972,0,-.02965,0,0,0,1,0]),Ce("Vintage",[.62793,.32021,-.03965,0,.03784,.02578,.64411,.03259,0,.02926,.0466,-.08512,.52416,0,.02023,0,0,0,1,0]),Ce("Kodachrome",[1.12855,-.39673,-.03992,0,.24991,-.16404,1.08352,-.05498,0,.09698,-.16786,-.56034,1.60148,0,.13972,0,0,0,1,0]),Ce("Technicolor",[1.91252,-.85453,-.09155,0,.04624,-.30878,1.76589,-.10601,0,-.27589,-.2311,-.75018,1.84759,0,.12137,0,0,0,1,0]),Ce("Polaroid",[1.438,-.062,-.062,0,0,-.122,1.378,-.122,0,0,-.016,-.016,1.483,0,0,0,0,0,1,0]),Ce("Sepia",[.393,.769,.189,0,0,.349,.686,.168,0,0,.272,.534,.131,0,0,0,0,0,1,0]),Ce("BlackWhite",[1.5,1.5,1.5,0,-1,1.5,1.5,1.5,0,-1,1.5,1.5,1.5,0,-1,0,0,0,1,0]);class ua extends lt{constructor(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};super(t),this.subFilters=t.subFilters||[]}applyTo(t){ni(t)&&(t.passes+=this.subFilters.length-1),this.subFilters.forEach(e=>{e.applyTo(t)})}toObject(){return{type:this.type,subFilters:this.subFilters.map(t=>t.toObject())}}isNeutralState(){return!this.subFilters.some(t=>!t.isNeutralState())}static fromObject(t,e){return Promise.all((t.subFilters||[]).map(r=>E.getClass(r.type).fromObject(r,e))).then(r=>new this({subFilters:r}))}}p(ua,"type","Composed"),E.setClass(ua);class hi extends lt{getFragmentSource(){return`
|
|
280
|
+
precision highp float;
|
|
281
|
+
uniform sampler2D uTexture;
|
|
282
|
+
uniform float uContrast;
|
|
283
|
+
varying vec2 vTexCoord;
|
|
284
|
+
void main() {
|
|
285
|
+
vec4 color = texture2D(uTexture, vTexCoord);
|
|
286
|
+
float contrastF = 1.015 * (uContrast + 1.0) / (1.0 * (1.015 - uContrast));
|
|
287
|
+
color.rgb = contrastF * (color.rgb - 0.5) + 0.5;
|
|
288
|
+
gl_FragColor = color;
|
|
289
|
+
}`}isNeutralState(){return this.contrast===0}applyTo2d(t){let{imageData:{data:e}}=t;const r=Math.floor(255*this.contrast),i=259*(r+255)/(255*(259-r));for(let s=0;s<e.length;s+=4)e[s]=i*(e[s]-128)+128,e[s+1]=i*(e[s+1]-128)+128,e[s+2]=i*(e[s+2]-128)+128}sendUniformData(t,e){t.uniform1f(e.uContrast,this.contrast)}}p(hi,"type","Contrast"),p(hi,"defaults",{contrast:0}),p(hi,"uniformLocations",["uContrast"]),E.setClass(hi);const pu={Convolute_3_1:`
|
|
290
|
+
precision highp float;
|
|
291
|
+
uniform sampler2D uTexture;
|
|
292
|
+
uniform float uMatrix[9];
|
|
293
|
+
uniform float uStepW;
|
|
294
|
+
uniform float uStepH;
|
|
295
|
+
varying vec2 vTexCoord;
|
|
296
|
+
void main() {
|
|
297
|
+
vec4 color = vec4(0, 0, 0, 0);
|
|
298
|
+
for (float h = 0.0; h < 3.0; h+=1.0) {
|
|
299
|
+
for (float w = 0.0; w < 3.0; w+=1.0) {
|
|
300
|
+
vec2 matrixPos = vec2(uStepW * (w - 1), uStepH * (h - 1));
|
|
301
|
+
color += texture2D(uTexture, vTexCoord + matrixPos) * uMatrix[int(h * 3.0 + w)];
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
gl_FragColor = color;
|
|
305
|
+
}
|
|
306
|
+
`,Convolute_3_0:`
|
|
307
|
+
precision highp float;
|
|
308
|
+
uniform sampler2D uTexture;
|
|
309
|
+
uniform float uMatrix[9];
|
|
310
|
+
uniform float uStepW;
|
|
311
|
+
uniform float uStepH;
|
|
312
|
+
varying vec2 vTexCoord;
|
|
313
|
+
void main() {
|
|
314
|
+
vec4 color = vec4(0, 0, 0, 1);
|
|
315
|
+
for (float h = 0.0; h < 3.0; h+=1.0) {
|
|
316
|
+
for (float w = 0.0; w < 3.0; w+=1.0) {
|
|
317
|
+
vec2 matrixPos = vec2(uStepW * (w - 1.0), uStepH * (h - 1.0));
|
|
318
|
+
color.rgb += texture2D(uTexture, vTexCoord + matrixPos).rgb * uMatrix[int(h * 3.0 + w)];
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
float alpha = texture2D(uTexture, vTexCoord).a;
|
|
322
|
+
gl_FragColor = color;
|
|
323
|
+
gl_FragColor.a = alpha;
|
|
324
|
+
}
|
|
325
|
+
`,Convolute_5_1:`
|
|
326
|
+
precision highp float;
|
|
327
|
+
uniform sampler2D uTexture;
|
|
328
|
+
uniform float uMatrix[25];
|
|
329
|
+
uniform float uStepW;
|
|
330
|
+
uniform float uStepH;
|
|
331
|
+
varying vec2 vTexCoord;
|
|
332
|
+
void main() {
|
|
333
|
+
vec4 color = vec4(0, 0, 0, 0);
|
|
334
|
+
for (float h = 0.0; h < 5.0; h+=1.0) {
|
|
335
|
+
for (float w = 0.0; w < 5.0; w+=1.0) {
|
|
336
|
+
vec2 matrixPos = vec2(uStepW * (w - 2.0), uStepH * (h - 2.0));
|
|
337
|
+
color += texture2D(uTexture, vTexCoord + matrixPos) * uMatrix[int(h * 5.0 + w)];
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
gl_FragColor = color;
|
|
341
|
+
}
|
|
342
|
+
`,Convolute_5_0:`
|
|
343
|
+
precision highp float;
|
|
344
|
+
uniform sampler2D uTexture;
|
|
345
|
+
uniform float uMatrix[25];
|
|
346
|
+
uniform float uStepW;
|
|
347
|
+
uniform float uStepH;
|
|
348
|
+
varying vec2 vTexCoord;
|
|
349
|
+
void main() {
|
|
350
|
+
vec4 color = vec4(0, 0, 0, 1);
|
|
351
|
+
for (float h = 0.0; h < 5.0; h+=1.0) {
|
|
352
|
+
for (float w = 0.0; w < 5.0; w+=1.0) {
|
|
353
|
+
vec2 matrixPos = vec2(uStepW * (w - 2.0), uStepH * (h - 2.0));
|
|
354
|
+
color.rgb += texture2D(uTexture, vTexCoord + matrixPos).rgb * uMatrix[int(h * 5.0 + w)];
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
float alpha = texture2D(uTexture, vTexCoord).a;
|
|
358
|
+
gl_FragColor = color;
|
|
359
|
+
gl_FragColor.a = alpha;
|
|
360
|
+
}
|
|
361
|
+
`,Convolute_7_1:`
|
|
362
|
+
precision highp float;
|
|
363
|
+
uniform sampler2D uTexture;
|
|
364
|
+
uniform float uMatrix[49];
|
|
365
|
+
uniform float uStepW;
|
|
366
|
+
uniform float uStepH;
|
|
367
|
+
varying vec2 vTexCoord;
|
|
368
|
+
void main() {
|
|
369
|
+
vec4 color = vec4(0, 0, 0, 0);
|
|
370
|
+
for (float h = 0.0; h < 7.0; h+=1.0) {
|
|
371
|
+
for (float w = 0.0; w < 7.0; w+=1.0) {
|
|
372
|
+
vec2 matrixPos = vec2(uStepW * (w - 3.0), uStepH * (h - 3.0));
|
|
373
|
+
color += texture2D(uTexture, vTexCoord + matrixPos) * uMatrix[int(h * 7.0 + w)];
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
gl_FragColor = color;
|
|
377
|
+
}
|
|
378
|
+
`,Convolute_7_0:`
|
|
379
|
+
precision highp float;
|
|
380
|
+
uniform sampler2D uTexture;
|
|
381
|
+
uniform float uMatrix[49];
|
|
382
|
+
uniform float uStepW;
|
|
383
|
+
uniform float uStepH;
|
|
384
|
+
varying vec2 vTexCoord;
|
|
385
|
+
void main() {
|
|
386
|
+
vec4 color = vec4(0, 0, 0, 1);
|
|
387
|
+
for (float h = 0.0; h < 7.0; h+=1.0) {
|
|
388
|
+
for (float w = 0.0; w < 7.0; w+=1.0) {
|
|
389
|
+
vec2 matrixPos = vec2(uStepW * (w - 3.0), uStepH * (h - 3.0));
|
|
390
|
+
color.rgb += texture2D(uTexture, vTexCoord + matrixPos).rgb * uMatrix[int(h * 7.0 + w)];
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
float alpha = texture2D(uTexture, vTexCoord).a;
|
|
394
|
+
gl_FragColor = color;
|
|
395
|
+
gl_FragColor.a = alpha;
|
|
396
|
+
}
|
|
397
|
+
`,Convolute_9_1:`
|
|
398
|
+
precision highp float;
|
|
399
|
+
uniform sampler2D uTexture;
|
|
400
|
+
uniform float uMatrix[81];
|
|
401
|
+
uniform float uStepW;
|
|
402
|
+
uniform float uStepH;
|
|
403
|
+
varying vec2 vTexCoord;
|
|
404
|
+
void main() {
|
|
405
|
+
vec4 color = vec4(0, 0, 0, 0);
|
|
406
|
+
for (float h = 0.0; h < 9.0; h+=1.0) {
|
|
407
|
+
for (float w = 0.0; w < 9.0; w+=1.0) {
|
|
408
|
+
vec2 matrixPos = vec2(uStepW * (w - 4.0), uStepH * (h - 4.0));
|
|
409
|
+
color += texture2D(uTexture, vTexCoord + matrixPos) * uMatrix[int(h * 9.0 + w)];
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
gl_FragColor = color;
|
|
413
|
+
}
|
|
414
|
+
`,Convolute_9_0:`
|
|
415
|
+
precision highp float;
|
|
416
|
+
uniform sampler2D uTexture;
|
|
417
|
+
uniform float uMatrix[81];
|
|
418
|
+
uniform float uStepW;
|
|
419
|
+
uniform float uStepH;
|
|
420
|
+
varying vec2 vTexCoord;
|
|
421
|
+
void main() {
|
|
422
|
+
vec4 color = vec4(0, 0, 0, 1);
|
|
423
|
+
for (float h = 0.0; h < 9.0; h+=1.0) {
|
|
424
|
+
for (float w = 0.0; w < 9.0; w+=1.0) {
|
|
425
|
+
vec2 matrixPos = vec2(uStepW * (w - 4.0), uStepH * (h - 4.0));
|
|
426
|
+
color.rgb += texture2D(uTexture, vTexCoord + matrixPos).rgb * uMatrix[int(h * 9.0 + w)];
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
float alpha = texture2D(uTexture, vTexCoord).a;
|
|
430
|
+
gl_FragColor = color;
|
|
431
|
+
gl_FragColor.a = alpha;
|
|
432
|
+
}
|
|
433
|
+
`};class ui extends lt{getCacheKey(){return"".concat(this.type,"_").concat(Math.sqrt(this.matrix.length),"_").concat(this.opaque?1:0)}getFragmentSource(){return pu[this.getCacheKey()]}applyTo2d(t){const e=t.imageData,r=e.data,i=this.matrix,s=Math.round(Math.sqrt(i.length)),o=Math.floor(s/2),a=e.width,l=e.height,c=t.ctx.createImageData(a,l),h=c.data,u=this.opaque?1:0;let d,g,f,m,b,y,w,O,k,S,C,A,D;for(C=0;C<l;C++)for(S=0;S<a;S++){for(b=4*(C*a+S),d=0,g=0,f=0,m=0,D=0;D<s;D++)for(A=0;A<s;A++)w=C+D-o,y=S+A-o,w<0||w>=l||y<0||y>=a||(O=4*(w*a+y),k=i[D*s+A],d+=r[O]*k,g+=r[O+1]*k,f+=r[O+2]*k,u||(m+=r[O+3]*k));h[b]=d,h[b+1]=g,h[b+2]=f,h[b+3]=u?r[b+3]:m}t.imageData=c}sendUniformData(t,e){t.uniform1fv(e.uMatrix,this.matrix)}toObject(){return v(v({},super.toObject()),{},{opaque:this.opaque,matrix:[...this.matrix]})}}p(ui,"type","Convolute"),p(ui,"defaults",{opaque:!1,matrix:[0,0,0,0,1,0,0,0,0]}),p(ui,"uniformLocations",["uMatrix","uOpaque","uHalfSize","uSize"]),E.setClass(ui);const da="Gamma";class di extends lt{getFragmentSource(){return`
|
|
434
|
+
precision highp float;
|
|
435
|
+
uniform sampler2D uTexture;
|
|
436
|
+
uniform vec3 uGamma;
|
|
437
|
+
varying vec2 vTexCoord;
|
|
438
|
+
void main() {
|
|
439
|
+
vec4 color = texture2D(uTexture, vTexCoord);
|
|
440
|
+
vec3 correction = (1.0 / uGamma);
|
|
441
|
+
color.r = pow(color.r, correction.r);
|
|
442
|
+
color.g = pow(color.g, correction.g);
|
|
443
|
+
color.b = pow(color.b, correction.b);
|
|
444
|
+
gl_FragColor = color;
|
|
445
|
+
gl_FragColor.rgb *= color.a;
|
|
446
|
+
}
|
|
447
|
+
`}constructor(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};super(t),this.gamma=t.gamma||this.constructor.defaults.gamma.concat()}applyTo2d(t){let{imageData:{data:e}}=t;const r=this.gamma,i=1/r[0],s=1/r[1],o=1/r[2];this.rgbValues||(this.rgbValues={r:new Uint8Array(256),g:new Uint8Array(256),b:new Uint8Array(256)});const a=this.rgbValues;for(let l=0;l<256;l++)a.r[l]=255*Math.pow(l/255,i),a.g[l]=255*Math.pow(l/255,s),a.b[l]=255*Math.pow(l/255,o);for(let l=0;l<e.length;l+=4)e[l]=a.r[e[l]],e[l+1]=a.g[e[l+1]],e[l+2]=a.b[e[l+2]]}sendUniformData(t,e){t.uniform3fv(e.uGamma,this.gamma)}isNeutralState(){const{gamma:t}=this;return t[0]===1&&t[1]===1&&t[2]===1}toObject(){return{type:da,gamma:this.gamma.concat()}}}p(di,"type",da),p(di,"defaults",{gamma:[1,1,1]}),p(di,"uniformLocations",["uGamma"]),E.setClass(di);const mu={average:`
|
|
448
|
+
precision highp float;
|
|
449
|
+
uniform sampler2D uTexture;
|
|
450
|
+
varying vec2 vTexCoord;
|
|
451
|
+
void main() {
|
|
452
|
+
vec4 color = texture2D(uTexture, vTexCoord);
|
|
453
|
+
float average = (color.r + color.b + color.g) / 3.0;
|
|
454
|
+
gl_FragColor = vec4(average, average, average, color.a);
|
|
455
|
+
}
|
|
456
|
+
`,lightness:`
|
|
457
|
+
precision highp float;
|
|
458
|
+
uniform sampler2D uTexture;
|
|
459
|
+
uniform int uMode;
|
|
460
|
+
varying vec2 vTexCoord;
|
|
461
|
+
void main() {
|
|
462
|
+
vec4 col = texture2D(uTexture, vTexCoord);
|
|
463
|
+
float average = (max(max(col.r, col.g),col.b) + min(min(col.r, col.g),col.b)) / 2.0;
|
|
464
|
+
gl_FragColor = vec4(average, average, average, col.a);
|
|
465
|
+
}
|
|
466
|
+
`,luminosity:`
|
|
467
|
+
precision highp float;
|
|
468
|
+
uniform sampler2D uTexture;
|
|
469
|
+
uniform int uMode;
|
|
470
|
+
varying vec2 vTexCoord;
|
|
471
|
+
void main() {
|
|
472
|
+
vec4 col = texture2D(uTexture, vTexCoord);
|
|
473
|
+
float average = 0.21 * col.r + 0.72 * col.g + 0.07 * col.b;
|
|
474
|
+
gl_FragColor = vec4(average, average, average, col.a);
|
|
475
|
+
}
|
|
476
|
+
`};class gi extends lt{applyTo2d(t){let{imageData:{data:e}}=t;for(let r,i=0;i<e.length;i+=4){const s=e[i],o=e[i+1],a=e[i+2];switch(this.mode){case"average":r=(s+o+a)/3;break;case"lightness":r=(Math.min(s,o,a)+Math.max(s,o,a))/2;break;case"luminosity":r=.21*s+.72*o+.07*a}e[i+2]=e[i+1]=e[i]=r}}getCacheKey(){return"".concat(this.type,"_").concat(this.mode)}getFragmentSource(){return mu[this.mode]}sendUniformData(t,e){t.uniform1i(e.uMode,1)}isNeutralState(){return!1}}p(gi,"type","Grayscale"),p(gi,"defaults",{mode:"average"}),p(gi,"uniformLocations",["uMode"]),E.setClass(gi);const vu=v(v({},ha),{},{rotation:0});class Ps extends Ve{calculateMatrix(){const t=this.rotation*Math.PI,e=Zt(t),r=Jt(t),i=1/3,s=Math.sqrt(i)*r,o=1-e;this.matrix=[e+o/3,i*o-s,i*o+s,0,0,i*o+s,e+i*o,i*o-s,0,0,i*o-s,i*o+s,e+i*o,0,0,0,0,0,1,0]}isNeutralState(){return this.rotation===0}applyTo(t){this.calculateMatrix(),super.applyTo(t)}toObject(){return{type:this.type,rotation:this.rotation}}}p(Ps,"type","HueRotation"),p(Ps,"defaults",vu),E.setClass(Ps);class fi extends lt{applyTo2d(t){let{imageData:{data:e}}=t;for(let r=0;r<e.length;r+=4)e[r]=255-e[r],e[r+1]=255-e[r+1],e[r+2]=255-e[r+2],this.alpha&&(e[r+3]=255-e[r+3])}getFragmentSource(){return`
|
|
477
|
+
precision highp float;
|
|
478
|
+
uniform sampler2D uTexture;
|
|
479
|
+
uniform int uInvert;
|
|
480
|
+
uniform int uAlpha;
|
|
481
|
+
varying vec2 vTexCoord;
|
|
482
|
+
void main() {
|
|
483
|
+
vec4 color = texture2D(uTexture, vTexCoord);
|
|
484
|
+
if (uInvert == 1) {
|
|
485
|
+
if (uAlpha == 1) {
|
|
486
|
+
gl_FragColor = vec4(1.0 - color.r,1.0 -color.g,1.0 -color.b,1.0 -color.a);
|
|
487
|
+
} else {
|
|
488
|
+
gl_FragColor = vec4(1.0 - color.r,1.0 -color.g,1.0 -color.b,color.a);
|
|
489
|
+
}
|
|
490
|
+
} else {
|
|
491
|
+
gl_FragColor = color;
|
|
492
|
+
}
|
|
493
|
+
}
|
|
494
|
+
`}isNeutralState(){return!this.invert}sendUniformData(t,e){t.uniform1i(e.uInvert,Number(this.invert)),t.uniform1i(e.uAlpha,Number(this.alpha))}}p(fi,"type","Invert"),p(fi,"defaults",{alpha:!1,invert:!0}),p(fi,"uniformLocations",["uInvert","uAlpha"]),E.setClass(fi);class pi extends lt{getFragmentSource(){return`
|
|
495
|
+
precision highp float;
|
|
496
|
+
uniform sampler2D uTexture;
|
|
497
|
+
uniform float uStepH;
|
|
498
|
+
uniform float uNoise;
|
|
499
|
+
uniform float uSeed;
|
|
500
|
+
varying vec2 vTexCoord;
|
|
501
|
+
float rand(vec2 co, float seed, float vScale) {
|
|
502
|
+
return fract(sin(dot(co.xy * vScale ,vec2(12.9898 , 78.233))) * 43758.5453 * (seed + 0.01) / 2.0);
|
|
503
|
+
}
|
|
504
|
+
void main() {
|
|
505
|
+
vec4 color = texture2D(uTexture, vTexCoord);
|
|
506
|
+
color.rgb += (0.5 - rand(vTexCoord, uSeed, 0.1 / uStepH)) * uNoise;
|
|
507
|
+
gl_FragColor = color;
|
|
508
|
+
}
|
|
509
|
+
`}applyTo2d(t){let{imageData:{data:e}}=t;const r=this.noise;for(let i=0;i<e.length;i+=4){const s=(.5-Math.random())*r;e[i]+=s,e[i+1]+=s,e[i+2]+=s}}sendUniformData(t,e){t.uniform1f(e.uNoise,this.noise/255),t.uniform1f(e.uSeed,Math.random())}isNeutralState(){return this.noise===0}}p(pi,"type","Noise"),p(pi,"defaults",{noise:0}),p(pi,"uniformLocations",["uNoise","uSeed"]),E.setClass(pi);class mi extends lt{applyTo2d(t){let{imageData:{data:e,width:r,height:i}}=t;for(let s=0;s<i;s+=this.blocksize)for(let o=0;o<r;o+=this.blocksize){const a=4*s*r+4*o,l=e[a],c=e[a+1],h=e[a+2],u=e[a+3];for(let d=s;d<Math.min(s+this.blocksize,i);d++)for(let g=o;g<Math.min(o+this.blocksize,r);g++){const f=4*d*r+4*g;e[f]=l,e[f+1]=c,e[f+2]=h,e[f+3]=u}}}isNeutralState(){return this.blocksize===1}getFragmentSource(){return`
|
|
510
|
+
precision highp float;
|
|
511
|
+
uniform sampler2D uTexture;
|
|
512
|
+
uniform float uBlocksize;
|
|
513
|
+
uniform float uStepW;
|
|
514
|
+
uniform float uStepH;
|
|
515
|
+
varying vec2 vTexCoord;
|
|
516
|
+
void main() {
|
|
517
|
+
float blockW = uBlocksize * uStepW;
|
|
518
|
+
float blockH = uBlocksize * uStepH;
|
|
519
|
+
int posX = int(vTexCoord.x / blockW);
|
|
520
|
+
int posY = int(vTexCoord.y / blockH);
|
|
521
|
+
float fposX = float(posX);
|
|
522
|
+
float fposY = float(posY);
|
|
523
|
+
vec2 squareCoords = vec2(fposX * blockW, fposY * blockH);
|
|
524
|
+
vec4 color = texture2D(uTexture, squareCoords);
|
|
525
|
+
gl_FragColor = color;
|
|
526
|
+
}
|
|
527
|
+
`}sendUniformData(t,e){t.uniform1f(e.uBlocksize,this.blocksize)}}p(mi,"type","Pixelate"),p(mi,"defaults",{blocksize:4}),p(mi,"uniformLocations",["uBlocksize"]),E.setClass(mi);class vi extends lt{getFragmentSource(){return`
|
|
528
|
+
precision highp float;
|
|
529
|
+
uniform sampler2D uTexture;
|
|
530
|
+
uniform vec4 uLow;
|
|
531
|
+
uniform vec4 uHigh;
|
|
532
|
+
varying vec2 vTexCoord;
|
|
533
|
+
void main() {
|
|
534
|
+
gl_FragColor = texture2D(uTexture, vTexCoord);
|
|
535
|
+
if(all(greaterThan(gl_FragColor.rgb,uLow.rgb)) && all(greaterThan(uHigh.rgb,gl_FragColor.rgb))) {
|
|
536
|
+
gl_FragColor.a = 0.0;
|
|
537
|
+
}
|
|
538
|
+
}
|
|
539
|
+
`}applyTo2d(t){let{imageData:{data:e}}=t;const r=255*this.distance,i=new G(this.color).getSource(),s=[i[0]-r,i[1]-r,i[2]-r],o=[i[0]+r,i[1]+r,i[2]+r];for(let a=0;a<e.length;a+=4){const l=e[a],c=e[a+1],h=e[a+2];l>s[0]&&c>s[1]&&h>s[2]&&l<o[0]&&c<o[1]&&h<o[2]&&(e[a+3]=0)}}sendUniformData(t,e){const r=new G(this.color).getSource(),i=this.distance,s=[0+r[0]/255-i,0+r[1]/255-i,0+r[2]/255-i,1],o=[r[0]/255+i,r[1]/255+i,r[2]/255+i,1];t.uniform4fv(e.uLow,s),t.uniform4fv(e.uHigh,o)}}p(vi,"type","RemoveColor"),p(vi,"defaults",{color:"#FFFFFF",distance:.02,useAlpha:!1}),p(vi,"uniformLocations",["uLow","uHigh"]),E.setClass(vi);class bi extends lt{sendUniformData(t,e){t.uniform2fv(e.uDelta,this.horizontal?[1/this.width,0]:[0,1/this.height]),t.uniform1fv(e.uTaps,this.taps)}getFilterWindow(){const t=this.tempScale;return Math.ceil(this.lanczosLobes/t)}getCacheKey(){const t=this.getFilterWindow();return"".concat(this.type,"_").concat(t)}getFragmentSource(){const t=this.getFilterWindow();return this.generateShader(t)}getTaps(){const t=this.lanczosCreate(this.lanczosLobes),e=this.tempScale,r=this.getFilterWindow(),i=new Array(r);for(let s=1;s<=r;s++)i[s-1]=t(s*e);return i}generateShader(t){const e=new Array(t);for(let r=1;r<=t;r++)e[r-1]="".concat(r,".0 * uDelta");return`
|
|
540
|
+
precision highp float;
|
|
541
|
+
uniform sampler2D uTexture;
|
|
542
|
+
uniform vec2 uDelta;
|
|
543
|
+
varying vec2 vTexCoord;
|
|
544
|
+
uniform float uTaps[`.concat(t,`];
|
|
545
|
+
void main() {
|
|
546
|
+
vec4 color = texture2D(uTexture, vTexCoord);
|
|
547
|
+
float sum = 1.0;
|
|
548
|
+
`).concat(e.map((r,i)=>`
|
|
549
|
+
color += texture2D(uTexture, vTexCoord + `.concat(r,") * uTaps[").concat(i,"] + texture2D(uTexture, vTexCoord - ").concat(r,") * uTaps[").concat(i,`];
|
|
550
|
+
sum += 2.0 * uTaps[`).concat(i,`];
|
|
551
|
+
`)).join(`
|
|
552
|
+
`),`
|
|
553
|
+
gl_FragColor = color / sum;
|
|
554
|
+
}
|
|
555
|
+
`)}applyToForWebgl(t){t.passes++,this.width=t.sourceWidth,this.horizontal=!0,this.dW=Math.round(this.width*this.scaleX),this.dH=t.sourceHeight,this.tempScale=this.dW/this.width,this.taps=this.getTaps(),t.destinationWidth=this.dW,super.applyTo(t),t.sourceWidth=t.destinationWidth,this.height=t.sourceHeight,this.horizontal=!1,this.dH=Math.round(this.height*this.scaleY),this.tempScale=this.dH/this.height,this.taps=this.getTaps(),t.destinationHeight=this.dH,super.applyTo(t),t.sourceHeight=t.destinationHeight}applyTo(t){ni(t)?this.applyToForWebgl(t):this.applyTo2d(t)}isNeutralState(){return this.scaleX===1&&this.scaleY===1}lanczosCreate(t){return e=>{if(e>=t||e<=-t)return 0;if(e<11920929e-14&&e>-11920929e-14)return 1;const r=(e*=Math.PI)/t;return Math.sin(e)/e*Math.sin(r)/r}}applyTo2d(t){const e=t.imageData,r=this.scaleX,i=this.scaleY;this.rcpScaleX=1/r,this.rcpScaleY=1/i;const s=e.width,o=e.height,a=Math.round(s*r),l=Math.round(o*i);let c;c=this.resizeType==="sliceHack"?this.sliceByTwo(t,s,o,a,l):this.resizeType==="hermite"?this.hermiteFastResize(t,s,o,a,l):this.resizeType==="bilinear"?this.bilinearFiltering(t,s,o,a,l):this.resizeType==="lanczos"?this.lanczosResize(t,s,o,a,l):new ImageData(a,l),t.imageData=c}sliceByTwo(t,e,r,i,s){const o=t.imageData,a=.5;let l=!1,c=!1,h=e*a,u=r*a;const d=t.filterBackend.resources;let g=0,f=0;const m=e;let b=0;d.sliceByTwo||(d.sliceByTwo=Qt());const y=d.sliceByTwo;(y.width<1.5*e||y.height<r)&&(y.width=1.5*e,y.height=r);const w=y.getContext("2d");for(w.clearRect(0,0,1.5*e,r),w.putImageData(o,0,0),i=Math.floor(i),s=Math.floor(s);!l||!c;)e=h,r=u,i<Math.floor(h*a)?h=Math.floor(h*a):(h=i,l=!0),s<Math.floor(u*a)?u=Math.floor(u*a):(u=s,c=!0),w.drawImage(y,g,f,e,r,m,b,h,u),g=m,f=b,b+=u;return w.getImageData(g,f,i,s)}lanczosResize(t,e,r,i,s){const o=t.imageData.data,a=t.ctx.createImageData(i,s),l=a.data,c=this.lanczosCreate(this.lanczosLobes),h=this.rcpScaleX,u=this.rcpScaleY,d=2/this.rcpScaleX,g=2/this.rcpScaleY,f=Math.ceil(h*this.lanczosLobes/2),m=Math.ceil(u*this.lanczosLobes/2),b={},y={x:0,y:0},w={x:0,y:0};return function O(k){let S,C,A,D,L,R,H,I,M,j,z;for(y.x=(k+.5)*h,w.x=Math.floor(y.x),S=0;S<s;S++){for(y.y=(S+.5)*u,w.y=Math.floor(y.y),L=0,R=0,H=0,I=0,M=0,C=w.x-f;C<=w.x+f;C++)if(!(C<0||C>=e)){j=Math.floor(1e3*Math.abs(C-y.x)),b[j]||(b[j]={});for(let V=w.y-m;V<=w.y+m;V++)V<0||V>=r||(z=Math.floor(1e3*Math.abs(V-y.y)),b[j][z]||(b[j][z]=c(Math.sqrt(Math.pow(j*d,2)+Math.pow(z*g,2))/1e3)),A=b[j][z],A>0&&(D=4*(V*e+C),L+=A,R+=A*o[D],H+=A*o[D+1],I+=A*o[D+2],M+=A*o[D+3]))}D=4*(S*i+k),l[D]=R/L,l[D+1]=H/L,l[D+2]=I/L,l[D+3]=M/L}return++k<i?O(k):a}(0)}bilinearFiltering(t,e,r,i,s){let o,a,l,c,h,u,d,g,f,m,b,y,w,O=0;const k=this.rcpScaleX,S=this.rcpScaleY,C=4*(e-1),A=t.imageData.data,D=t.ctx.createImageData(i,s),L=D.data;for(d=0;d<s;d++)for(g=0;g<i;g++)for(h=Math.floor(k*g),u=Math.floor(S*d),f=k*g-h,m=S*d-u,w=4*(u*e+h),b=0;b<4;b++)o=A[w+b],a=A[w+4+b],l=A[w+C+b],c=A[w+C+4+b],y=o*(1-f)*(1-m)+a*f*(1-m)+l*m*(1-f)+c*f*m,L[O++]=y;return D}hermiteFastResize(t,e,r,i,s){const o=this.rcpScaleX,a=this.rcpScaleY,l=Math.ceil(o/2),c=Math.ceil(a/2),h=t.imageData.data,u=t.ctx.createImageData(i,s),d=u.data;for(let g=0;g<s;g++)for(let f=0;f<i;f++){const m=4*(f+g*i);let b=0,y=0,w=0,O=0,k=0,S=0,C=0;const A=(g+.5)*a;for(let D=Math.floor(g*a);D<(g+1)*a;D++){const L=Math.abs(A-(D+.5))/c,R=(f+.5)*o,H=L*L;for(let I=Math.floor(f*o);I<(f+1)*o;I++){let M=Math.abs(R-(I+.5))/l;const j=Math.sqrt(H+M*M);j>1&&j<-1||(b=2*j*j*j-3*j*j+1,b>0&&(M=4*(I+D*e),C+=b*h[M+3],w+=b,h[M+3]<255&&(b=b*h[M+3]/250),O+=b*h[M],k+=b*h[M+1],S+=b*h[M+2],y+=b))}}d[m]=O/y,d[m+1]=k/y,d[m+2]=S/y,d[m+3]=C/w}return u}}p(bi,"type","Resize"),p(bi,"defaults",{resizeType:"hermite",scaleX:1,scaleY:1,lanczosLobes:3}),p(bi,"uniformLocations",["uDelta","uTaps"]),E.setClass(bi);class yi extends lt{getFragmentSource(){return`
|
|
556
|
+
precision highp float;
|
|
557
|
+
uniform sampler2D uTexture;
|
|
558
|
+
uniform float uSaturation;
|
|
559
|
+
varying vec2 vTexCoord;
|
|
560
|
+
void main() {
|
|
561
|
+
vec4 color = texture2D(uTexture, vTexCoord);
|
|
562
|
+
float rgMax = max(color.r, color.g);
|
|
563
|
+
float rgbMax = max(rgMax, color.b);
|
|
564
|
+
color.r += rgbMax != color.r ? (rgbMax - color.r) * uSaturation : 0.00;
|
|
565
|
+
color.g += rgbMax != color.g ? (rgbMax - color.g) * uSaturation : 0.00;
|
|
566
|
+
color.b += rgbMax != color.b ? (rgbMax - color.b) * uSaturation : 0.00;
|
|
567
|
+
gl_FragColor = color;
|
|
568
|
+
}
|
|
569
|
+
`}applyTo2d(t){let{imageData:{data:e}}=t;const r=-this.saturation;for(let i=0;i<e.length;i+=4){const s=e[i],o=e[i+1],a=e[i+2],l=Math.max(s,o,a);e[i]+=l!==s?(l-s)*r:0,e[i+1]+=l!==o?(l-o)*r:0,e[i+2]+=l!==a?(l-a)*r:0}}sendUniformData(t,e){t.uniform1f(e.uSaturation,-this.saturation)}isNeutralState(){return this.saturation===0}}p(yi,"type","Saturation"),p(yi,"defaults",{saturation:0}),p(yi,"uniformLocations",["uSaturation"]),E.setClass(yi);class _i extends lt{getFragmentSource(){return`
|
|
570
|
+
precision highp float;
|
|
571
|
+
uniform sampler2D uTexture;
|
|
572
|
+
uniform float uVibrance;
|
|
573
|
+
varying vec2 vTexCoord;
|
|
574
|
+
void main() {
|
|
575
|
+
vec4 color = texture2D(uTexture, vTexCoord);
|
|
576
|
+
float max = max(color.r, max(color.g, color.b));
|
|
577
|
+
float avg = (color.r + color.g + color.b) / 3.0;
|
|
578
|
+
float amt = (abs(max - avg) * 2.0) * uVibrance;
|
|
579
|
+
color.r += max != color.r ? (max - color.r) * amt : 0.00;
|
|
580
|
+
color.g += max != color.g ? (max - color.g) * amt : 0.00;
|
|
581
|
+
color.b += max != color.b ? (max - color.b) * amt : 0.00;
|
|
582
|
+
gl_FragColor = color;
|
|
583
|
+
}
|
|
584
|
+
`}applyTo2d(t){let{imageData:{data:e}}=t;const r=-this.vibrance;for(let i=0;i<e.length;i+=4){const s=e[i],o=e[i+1],a=e[i+2],l=Math.max(s,o,a),c=(s+o+a)/3,h=2*Math.abs(l-c)/255*r;e[i]+=l!==s?(l-s)*h:0,e[i+1]+=l!==o?(l-o)*h:0,e[i+2]+=l!==a?(l-a)*h:0}}sendUniformData(t,e){t.uniform1f(e.uVibrance,-this.vibrance)}isNeutralState(){return this.vibrance===0}}p(_i,"type","Vibrance"),p(_i,"defaults",{vibrance:0}),p(_i,"uniformLocations",["uVibrance"]),E.setClass(_i);const bu=["#ef4444","#f97316","#eab308","#22c55e","#3b82f6","#8b5cf6","#000000"],yu=[2,4,6,8],_u=({screenshot:n,onSave:t,onCancel:e})=>{const r=St(null),i=St(null),s=St(null),[o,a]=rt("select"),[l,c]=rt("#ef4444"),[h,u]=rt(4),[d,g]=rt(!1),[f,m]=rt(!1),[b,y]=rt(1),[w,O]=rt(!1),k=St([]),S=St(-1),C=St(!1),A=St(!1),D=St(null),L=St(null);Ft(()=>{if(!r.current)return;const T=new Cs(r.current,{isDrawingMode:!1,selection:!0});return s.current=T,Ot.fromURL(n).then(F=>{var mt;L.current={width:F.width||800,height:F.height||600};const P=(mt=i.current)==null?void 0:mt.getBoundingClientRect(),B=P?P.width-32:800,$=P?P.height-32:600,q=Math.min(B/(F.width||800),$/(F.height||600));T.setDimensions({width:(F.width||800)*q,height:(F.height||600)*q}),F.scaleToWidth(T.width),T.backgroundImage=F,T.renderAll(),R()}),T.freeDrawingBrush=new Jr(T),T.freeDrawingBrush.color=l,T.freeDrawingBrush.width=h,T.on("object:added",()=>{C.current||R()}),T.on("path:created",()=>{R()}),()=>{T.dispose()}},[n]),Ft(()=>{if(!s.current)return;const T=s.current;T.freeDrawingBrush&&(T.freeDrawingBrush.color=l,T.freeDrawingBrush.width=h)},[l,h]),Ft(()=>{if(!s.current)return;const T=s.current;T.isDrawingMode=o==="pen",T.selection=o==="select",o==="select"?T.defaultCursor="default":T.defaultCursor="crosshair"},[o]);const R=Y(()=>{if(!s.current)return;const T=JSON.stringify(s.current.toJSON());k.current=k.current.slice(0,S.current+1),k.current.push(T),S.current=k.current.length-1,g(S.current>0),m(!1)},[]),H=Y(()=>{if(!s.current||S.current<=0)return;S.current--;const T=k.current[S.current];s.current.loadFromJSON(JSON.parse(T)).then(()=>{var F;(F=s.current)==null||F.renderAll(),g(S.current>0),m(S.current<k.current.length-1)})},[]),I=Y(()=>{if(!s.current||S.current>=k.current.length-1)return;S.current++;const T=k.current[S.current];s.current.loadFromJSON(JSON.parse(T)).then(()=>{var F;(F=s.current)==null||F.renderAll(),g(S.current>0),m(S.current<k.current.length-1)})},[]),M=Y(T=>{if(!s.current||o==="pen"||o==="select")return;C.current=!0;const F=s.current,P=F.getViewportPoint(T.e);let B=null;switch(o){case"rectangle":B=new Tt({left:P.x,top:P.y,width:0,height:0,stroke:l,strokeWidth:h,fill:"transparent",selectable:!0});break;case"circle":B=new Vt({left:P.x,top:P.y,rx:0,ry:0,stroke:l,strokeWidth:h,fill:"transparent",selectable:!0});break;case"arrow":B=new ae([P.x,P.y,P.x,P.y],{stroke:l,strokeWidth:h,selectable:!0});break;case"text":B=new qt("Text",{left:P.x,top:P.y,fontSize:20,fill:l,selectable:!0,editable:!0}),F.add(B),F.setActiveObject(B),B.enterEditing(),C.current=!1;return;case"blur":B=new Tt({left:P.x,top:P.y,width:0,height:0,fill:"rgba(128, 128, 128, 0.8)",stroke:"#666",strokeWidth:1,selectable:!0});break}B&&(B._startPoint={x:P.x,y:P.y},F.add(B),F.setActiveObject(B))},[o,l,h]),j=Y(T=>{if(!s.current||!C.current)return;const F=s.current,P=F.getActiveObject();if(!P||!P._startPoint)return;const B=F.getViewportPoint(T.e),$=P._startPoint;if(P instanceof Tt){const q=B.x-$.x,mt=B.y-$.y;P.set({left:q>0?$.x:B.x,top:mt>0?$.y:B.y,width:Math.abs(q),height:Math.abs(mt)})}else if(P instanceof Vt){const q=Math.abs(B.x-$.x)/2,mt=Math.abs(B.y-$.y)/2;P.set({left:Math.min($.x,B.x),top:Math.min($.y,B.y),rx:q,ry:mt})}else P instanceof ae&&P.set({x2:B.x,y2:B.y});F.renderAll()},[]),z=Y(()=>{C.current&&(C.current=!1,R())},[R]);Ft(()=>{if(!s.current)return;const T=s.current;return T.on("mouse:down",M),T.on("mouse:move",j),T.on("mouse:up",z),()=>{T.off("mouse:down",M),T.off("mouse:move",j),T.off("mouse:up",z)}},[M,j,z]);const V=Y(()=>{var dt;if(!s.current)return;const T=s.current,F=T.getZoom(),P=((dt=T.viewportTransform)==null?void 0:dt.slice())||[1,0,0,1,0,0];T.setZoom(1),T.setViewportTransform([1,0,0,1,0,0]),T.renderAll();const B=L.current,$=B?B.width/(T.width||1):1,q=T.toDataURL({format:"png",quality:1,multiplier:$});T.setZoom(F),T.setViewportTransform(P),T.renderAll();const le=T.getObjects().map(Zd=>Zd.toObject());t(q,{objects:le})},[t]),tt=Y(()=>{if(!s.current)return;const T=s.current,F=T.getActiveObjects();F.length>0&&(F.forEach(P=>T.remove(P)),T.discardActiveObject(),T.renderAll(),R())},[R]),N=Y(()=>{if(!s.current)return;const T=s.current,F=Math.min(b*1.2,3),P=new x(T.width/2,T.height/2);T.zoomToPoint(P,F),y(F)},[b]),Ct=Y(()=>{if(!s.current)return;const T=s.current,F=Math.max(b/1.2,.5),P=new x(T.width/2,T.height/2);T.zoomToPoint(P,F),y(F)},[b]),Mt=Y(()=>{if(!s.current)return;const T=s.current;y(1),T.setZoom(1),T.setViewportTransform([1,0,0,1,0,0]),T.renderAll()},[]);Ft(()=>{if(!s.current)return;const T=s.current,F=$=>{const q=$.e;(q.buttons===2||q.buttons===1&&w)&&(q.preventDefault(),A.current=!0,T.selection=!1,D.current={x:q.clientX,y:q.clientY},T.setCursor("grabbing"))},P=$=>{if(A.current&&D.current){const q=$.e,mt=T.viewportTransform;mt[4]+=q.clientX-D.current.x,mt[5]+=q.clientY-D.current.y,T.requestRenderAll(),D.current={x:q.clientX,y:q.clientY}}},B=()=>{A.current&&(A.current=!1,D.current=null,T.setCursor(w?"grab":"default"))};return T.on("mouse:down",F),T.on("mouse:move",P),T.on("mouse:up",B),()=>{T.off("mouse:down",F),T.off("mouse:move",P),T.off("mouse:up",B)}},[w]),Ft(()=>{const T=P=>{if(P.key===" "&&!w&&(P.preventDefault(),O(!0),s.current&&s.current.setCursor("grab")),P.key==="Delete"||P.key==="Backspace"){const B=document.activeElement;(B==null?void 0:B.tagName)!=="INPUT"&&(B==null?void 0:B.tagName)!=="TEXTAREA"&&tt()}(P.ctrlKey||P.metaKey)&&P.key==="z"&&(P.preventDefault(),P.shiftKey?I():H())},F=P=>{P.key===" "&&w&&(O(!1),s.current&&s.current.setCursor("default"))};return window.addEventListener("keydown",T),window.addEventListener("keyup",F),()=>{window.removeEventListener("keydown",T),window.removeEventListener("keyup",F)}},[tt,H,I,w]);const ct=({tool:T,icon:F,label:P})=>_("button",{class:`bugpin-tool-btn ${o===T?"active":""}`,onClick:()=>a(T),title:P,children:_("span",{dangerouslySetInnerHTML:{__html:F}})});return _("div",{class:"bugpin-annotation-container",children:[_("div",{class:"bugpin-annotation-toolbar",children:[_("div",{class:"bugpin-tool-group",children:[_(ct,{tool:"select",label:"Select",icon:'<svg viewBox="0 0 24 24"><path d="M3 3l7.07 16.97 2.51-7.39 7.39-2.51L3 3z" fill="currentColor"/></svg>'}),_(ct,{tool:"pen",label:"Pen",icon:'<svg viewBox="0 0 24 24"><path d="M3 17.25V21h3.75L17.81 9.94l-3.75-3.75L3 17.25zM20.71 7.04a.996.996 0 000-1.41l-2.34-2.34a.996.996 0 00-1.41 0l-1.83 1.83 3.75 3.75 1.83-1.83z" fill="currentColor"/></svg>'}),_(ct,{tool:"arrow",label:"Arrow",icon:'<svg viewBox="0 0 24 24"><path d="M12 4l-1.41 1.41L16.17 11H4v2h12.17l-5.58 5.59L12 20l8-8z" fill="currentColor"/></svg>'}),_(ct,{tool:"rectangle",label:"Rectangle",icon:'<svg viewBox="0 0 24 24"><rect x="3" y="3" width="18" height="18" rx="2" fill="none" stroke="currentColor" stroke-width="2"/></svg>'}),_(ct,{tool:"circle",label:"Circle",icon:'<svg viewBox="0 0 24 24"><circle cx="12" cy="12" r="9" fill="none" stroke="currentColor" stroke-width="2"/></svg>'}),_(ct,{tool:"text",label:"Text",icon:'<svg viewBox="0 0 24 24"><path d="M5 4v3h5.5v12h3V7H19V4H5z" fill="currentColor"/></svg>'}),_(ct,{tool:"blur",label:"Blur/Mask",icon:'<svg viewBox="0 0 24 24"><path d="M12 17c1.1 0 2-.9 2-2s-.9-2-2-2-2 .9-2 2 .9 2 2 2zm6-9h-1V6c0-2.76-2.24-5-5-5S7 3.24 7 6v2H6c-1.1 0-2 .9-2 2v10c0 1.1.9 2 2 2h12c1.1 0 2-.9 2-2V10c0-1.1-.9-2-2-2zM8.9 6c0-1.71 1.39-3.1 3.1-3.1s3.1 1.39 3.1 3.1v2H8.9V6zM18 20H6V10h12v10z" fill="currentColor"/></svg>'})]}),_("div",{class:"bugpin-tool-divider"}),_("div",{class:"bugpin-color-picker",children:bu.map(T=>_("button",{class:`bugpin-color-btn ${l===T?"active":""}`,style:{backgroundColor:T},onClick:()=>c(T),title:T},T))}),_("div",{class:"bugpin-tool-divider"}),_("div",{class:"bugpin-stroke-picker",children:yu.map(T=>_("button",{class:`bugpin-stroke-btn ${h===T?"active":""}`,onClick:()=>u(T),title:`${T}px`,children:_("span",{style:{height:`${T}px`}})},T))}),_("div",{class:"bugpin-tool-divider"}),_("div",{class:"bugpin-tool-group",children:[_("button",{class:"bugpin-tool-btn",onClick:H,disabled:!d,title:"Undo (Ctrl+Z)",children:_("svg",{viewBox:"0 0 24 24",children:_("path",{d:"M12.5 8c-2.65 0-5.05.99-6.9 2.6L2 7v9h9l-3.62-3.62c1.39-1.16 3.16-1.88 5.12-1.88 3.54 0 6.55 2.31 7.6 5.5l2.37-.78C21.08 11.03 17.15 8 12.5 8z",fill:"currentColor"})})}),_("button",{class:"bugpin-tool-btn",onClick:I,disabled:!f,title:"Redo (Ctrl+Shift+Z)",children:_("svg",{viewBox:"0 0 24 24",children:_("path",{d:"M18.4 10.6C16.55 8.99 14.15 8 11.5 8c-4.65 0-8.58 3.03-9.96 7.22L3.9 16c1.05-3.19 4.05-5.5 7.6-5.5 1.95 0 3.73.72 5.12 1.88L13 16h9V7l-3.6 3.6z",fill:"currentColor"})})}),_("button",{class:"bugpin-tool-btn",onClick:tt,title:"Delete selected (Del)",children:_("svg",{viewBox:"0 0 24 24",children:_("path",{d:"M6 19c0 1.1.9 2 2 2h8c1.1 0 2-.9 2-2V7H6v12zM19 4h-3.5l-1-1h-5l-1 1H5v2h14V4z",fill:"currentColor"})})})]}),_("div",{class:"bugpin-tool-divider"}),_("div",{class:"bugpin-tool-group",children:[_("button",{class:"bugpin-tool-btn",onClick:Ct,disabled:b<=.5,title:"Zoom Out - Hold Space to pan when zoomed",children:_("svg",{viewBox:"0 0 24 24",children:_("path",{d:"M15.5 14h-.79l-.28-.27A6.471 6.471 0 0 0 16 9.5 6.5 6.5 0 1 0 9.5 16c1.61 0 3.09-.59 4.23-1.57l.27.28v.79l5 4.99L20.49 19l-4.99-5zm-6 0C7.01 14 5 11.99 5 9.5S7.01 5 9.5 5 14 7.01 14 9.5 11.99 14 9.5 14zM7 9h5v1H7z",fill:"currentColor"})})}),_("button",{class:"bugpin-tool-btn",onClick:Mt,title:`Reset Zoom (${Math.round(b*100)}%) - Hold Space to pan`,children:_("svg",{viewBox:"0 0 24 24",children:_("path",{d:"M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm0 18c-4.41 0-8-3.59-8-8s3.59-8 8-8 8 3.59 8 8-3.59 8-8 8zm-1-13h2v6h-2zm0 8h2v2h-2z",fill:"currentColor"})})}),_("button",{class:"bugpin-tool-btn",onClick:N,disabled:b>=3,title:"Zoom In - Hold Space to pan when zoomed",children:_("svg",{viewBox:"0 0 24 24",children:_("path",{d:"M15.5 14h-.79l-.28-.27A6.471 6.471 0 0 0 16 9.5 6.5 6.5 0 1 0 9.5 16c1.61 0 3.09-.59 4.23-1.57l.27.28v.79l5 4.99L20.49 19l-4.99-5zm-6 0C7.01 14 5 11.99 5 9.5S7.01 5 9.5 5 14 7.01 14 9.5 11.99 14 9.5 14zm.5-7H9v2H7v1h2v2h1v-2h2V9h-2z",fill:"currentColor"})})})]})]}),_("div",{class:"bugpin-canvas-wrapper",ref:i,children:_("canvas",{ref:r})}),_("div",{class:"bugpin-annotation-actions",children:[_("button",{class:"bugpin-btn-cancel",onClick:e,children:"Cancel"}),_("button",{class:"bugpin-btn-submit",onClick:V,children:"Done"})]})]})};function xu(n,t){if(n.match(/^[a-z]+:\/\//i))return n;if(n.match(/^\/\//))return window.location.protocol+n;if(n.match(/^[a-z]+:/i))return n;const e=document.implementation.createHTMLDocument(),r=e.createElement("base"),i=e.createElement("a");return e.head.appendChild(r),e.body.appendChild(i),t&&(r.href=t),i.href=n,i.href}const wu=(()=>{let n=0;const t=()=>`0000${(Math.random()*36**4<<0).toString(36)}`.slice(-4);return()=>(n+=1,`u${t()}${n}`)})();function pe(n){const t=[];for(let e=0,r=n.length;e<r;e++)t.push(n[e]);return t}let Xe=null;function ga(n={}){return Xe||(n.includeStyleProperties?(Xe=n.includeStyleProperties,Xe):(Xe=pe(window.getComputedStyle(document.documentElement)),Xe))}function xi(n,t){const r=(n.ownerDocument.defaultView||window).getComputedStyle(n).getPropertyValue(t);return r?parseFloat(r.replace("px","")):0}function Cu(n){const t=xi(n,"border-left-width"),e=xi(n,"border-right-width");return n.clientWidth+t+e}function Su(n){const t=xi(n,"border-top-width"),e=xi(n,"border-bottom-width");return n.clientHeight+t+e}function fa(n,t={}){const e=t.width||Cu(n),r=t.height||Su(n);return{width:e,height:r}}function Tu(){let n,t;try{t=process}catch{}const e=t&&t.env?t.env.devicePixelRatio:null;return e&&(n=parseInt(e,10),Number.isNaN(n)&&(n=1)),n||window.devicePixelRatio||1}const Dt=16384;function ku(n){(n.width>Dt||n.height>Dt)&&(n.width>Dt&&n.height>Dt?n.width>n.height?(n.height*=Dt/n.width,n.width=Dt):(n.width*=Dt/n.height,n.height=Dt):n.width>Dt?(n.height*=Dt/n.width,n.width=Dt):(n.width*=Dt/n.height,n.height=Dt))}function wi(n){return new Promise((t,e)=>{const r=new Image;r.onload=()=>{r.decode().then(()=>{requestAnimationFrame(()=>t(r))})},r.onerror=e,r.crossOrigin="anonymous",r.decoding="async",r.src=n})}async function Ou(n){return Promise.resolve().then(()=>new XMLSerializer().serializeToString(n)).then(encodeURIComponent).then(t=>`data:image/svg+xml;charset=utf-8,${t}`)}async function Du(n,t,e){const r="http://www.w3.org/2000/svg",i=document.createElementNS(r,"svg"),s=document.createElementNS(r,"foreignObject");return i.setAttribute("width",`${t}`),i.setAttribute("height",`${e}`),i.setAttribute("viewBox",`0 0 ${t} ${e}`),s.setAttribute("width","100%"),s.setAttribute("height","100%"),s.setAttribute("x","0"),s.setAttribute("y","0"),s.setAttribute("externalResourcesRequired","true"),i.appendChild(s),s.appendChild(n),Ou(i)}const wt=(n,t)=>{if(n instanceof t)return!0;const e=Object.getPrototypeOf(n);return e===null?!1:e.constructor.name===t.name||wt(e,t)};function Mu(n){const t=n.getPropertyValue("content");return`${n.cssText} content: '${t.replace(/'|"/g,"")}';`}function Eu(n,t){return ga(t).map(e=>{const r=n.getPropertyValue(e),i=n.getPropertyPriority(e);return`${e}: ${r}${i?" !important":""};`}).join(" ")}function Pu(n,t,e,r){const i=`.${n}:${t}`,s=e.cssText?Mu(e):Eu(e,r);return document.createTextNode(`${i}{${s}}`)}function pa(n,t,e,r){const i=window.getComputedStyle(n,e),s=i.getPropertyValue("content");if(s===""||s==="none")return;const o=wu();try{t.className=`${t.className} ${o}`}catch{return}const a=document.createElement("style");a.appendChild(Pu(o,e,i,r)),t.appendChild(a)}function Au(n,t,e){pa(n,t,":before",e),pa(n,t,":after",e)}const ma="application/font-woff",va="image/jpeg",ju={woff:ma,woff2:ma,ttf:"application/font-truetype",eot:"application/vnd.ms-fontobject",png:"image/png",jpg:va,jpeg:va,gif:"image/gif",tiff:"image/tiff",svg:"image/svg+xml",webp:"image/webp"};function Lu(n){const t=/\.([^./]*?)$/g.exec(n);return t?t[1]:""}function As(n){const t=Lu(n).toLowerCase();return ju[t]||""}function Fu(n){return n.split(/,/)[1]}function js(n){return n.search(/^(data:)/)!==-1}function Ru(n,t){return`data:${t};base64,${n}`}async function ba(n,t,e){const r=await fetch(n,t);if(r.status===404)throw new Error(`Resource "${r.url}" not found`);const i=await r.blob();return new Promise((s,o)=>{const a=new FileReader;a.onerror=o,a.onloadend=()=>{try{s(e({res:r,result:a.result}))}catch(l){o(l)}},a.readAsDataURL(i)})}const Ls={};function Bu(n,t,e){let r=n.replace(/\?.*/,"");return e&&(r=n),/ttf|otf|eot|woff2?/i.test(r)&&(r=r.replace(/.*\//,"")),t?`[${t}]${r}`:r}async function Fs(n,t,e){const r=Bu(n,t,e.includeQueryParams);if(Ls[r]!=null)return Ls[r];e.cacheBust&&(n+=(/\?/.test(n)?"&":"?")+new Date().getTime());let i;try{const s=await ba(n,e.fetchRequestInit,({res:o,result:a})=>(t||(t=o.headers.get("Content-Type")||""),Fu(a)));i=Ru(s,t)}catch(s){i=e.imagePlaceholder||"";let o=`Failed to fetch resource: ${n}`;s&&(o=typeof s=="string"?s:s.message),o&&console.warn(o)}return Ls[r]=i,i}async function Iu(n){const t=n.toDataURL();return t==="data:,"?n.cloneNode(!1):wi(t)}async function Hu(n,t){if(n.currentSrc){const s=document.createElement("canvas"),o=s.getContext("2d");s.width=n.clientWidth,s.height=n.clientHeight,o==null||o.drawImage(n,0,0,s.width,s.height);const a=s.toDataURL();return wi(a)}const e=n.poster,r=As(e),i=await Fs(e,r,t);return wi(i)}async function zu(n,t){var e;try{if(!((e=n==null?void 0:n.contentDocument)===null||e===void 0)&&e.body)return await Ci(n.contentDocument.body,t,!0)}catch{}return n.cloneNode(!1)}async function Wu(n,t){return wt(n,HTMLCanvasElement)?Iu(n):wt(n,HTMLVideoElement)?Hu(n,t):wt(n,HTMLIFrameElement)?zu(n,t):n.cloneNode(ya(n))}const Vu=n=>n.tagName!=null&&n.tagName.toUpperCase()==="SLOT",ya=n=>n.tagName!=null&&n.tagName.toUpperCase()==="SVG";async function Xu(n,t,e){var r,i;if(ya(t))return t;let s=[];return Vu(n)&&n.assignedNodes?s=pe(n.assignedNodes()):wt(n,HTMLIFrameElement)&&(!((r=n.contentDocument)===null||r===void 0)&&r.body)?s=pe(n.contentDocument.body.childNodes):s=pe(((i=n.shadowRoot)!==null&&i!==void 0?i:n).childNodes),s.length===0||wt(n,HTMLVideoElement)||await s.reduce((o,a)=>o.then(()=>Ci(a,e)).then(l=>{l&&t.appendChild(l)}),Promise.resolve()),t}function Yu(n,t,e){const r=t.style;if(!r)return;const i=window.getComputedStyle(n);i.cssText?(r.cssText=i.cssText,r.transformOrigin=i.transformOrigin):ga(e).forEach(s=>{let o=i.getPropertyValue(s);s==="font-size"&&o.endsWith("px")&&(o=`${Math.floor(parseFloat(o.substring(0,o.length-2)))-.1}px`),wt(n,HTMLIFrameElement)&&s==="display"&&o==="inline"&&(o="block"),s==="d"&&t.getAttribute("d")&&(o=`path(${t.getAttribute("d")})`),r.setProperty(s,o,i.getPropertyPriority(s))})}function Uu(n,t){wt(n,HTMLTextAreaElement)&&(t.innerHTML=n.value),wt(n,HTMLInputElement)&&t.setAttribute("value",n.value)}function Gu(n,t){if(wt(n,HTMLSelectElement)){const e=t,r=Array.from(e.children).find(i=>n.value===i.getAttribute("value"));r&&r.setAttribute("selected","")}}function Nu(n,t,e){return wt(t,Element)&&(Yu(n,t,e),Au(n,t,e),Uu(n,t),Gu(n,t)),t}async function $u(n,t){const e=n.querySelectorAll?n.querySelectorAll("use"):[];if(e.length===0)return n;const r={};for(let s=0;s<e.length;s++){const a=e[s].getAttribute("xlink:href");if(a){const l=n.querySelector(a),c=document.querySelector(a);!l&&c&&!r[a]&&(r[a]=await Ci(c,t,!0))}}const i=Object.values(r);if(i.length){const s="http://www.w3.org/1999/xhtml",o=document.createElementNS(s,"svg");o.setAttribute("xmlns",s),o.style.position="absolute",o.style.width="0",o.style.height="0",o.style.overflow="hidden",o.style.display="none";const a=document.createElementNS(s,"defs");o.appendChild(a);for(let l=0;l<i.length;l++)a.appendChild(i[l]);n.appendChild(o)}return n}async function Ci(n,t,e){return!e&&t.filter&&!t.filter(n)?null:Promise.resolve(n).then(r=>Wu(r,t)).then(r=>Xu(n,r,t)).then(r=>Nu(n,r,t)).then(r=>$u(r,t))}const _a=/url\((['"]?)([^'"]+?)\1\)/g,qu=/url\([^)]+\)\s*format\((["']?)([^"']+)\1\)/g,Ku=/src:\s*(?:url\([^)]+\)\s*format\([^)]+\)[,;]\s*)+/g;function Zu(n){const t=n.replace(/([.*+?^${}()|\[\]\/\\])/g,"\\$1");return new RegExp(`(url\\(['"]?)(${t})(['"]?\\))`,"g")}function Ju(n){const t=[];return n.replace(_a,(e,r,i)=>(t.push(i),e)),t.filter(e=>!js(e))}async function Qu(n,t,e,r,i){try{const s=e?xu(t,e):t,o=As(t);let a;return i||(a=await Fs(s,o,r)),n.replace(Zu(t),`$1${a}$3`)}catch{}return n}function td(n,{preferredFontFormat:t}){return t?n.replace(Ku,e=>{for(;;){const[r,,i]=qu.exec(e)||[];if(!i)return"";if(i===t)return`src: ${r};`}}):n}function xa(n){return n.search(_a)!==-1}async function wa(n,t,e){if(!xa(n))return n;const r=td(n,e);return Ju(r).reduce((s,o)=>s.then(a=>Qu(a,o,t,e)),Promise.resolve(r))}async function Ye(n,t,e){var r;const i=(r=t.style)===null||r===void 0?void 0:r.getPropertyValue(n);if(i){const s=await wa(i,null,e);return t.style.setProperty(n,s,t.style.getPropertyPriority(n)),!0}return!1}async function ed(n,t){await Ye("background",n,t)||await Ye("background-image",n,t),await Ye("mask",n,t)||await Ye("-webkit-mask",n,t)||await Ye("mask-image",n,t)||await Ye("-webkit-mask-image",n,t)}async function rd(n,t){const e=wt(n,HTMLImageElement);if(!(e&&!js(n.src))&&!(wt(n,SVGImageElement)&&!js(n.href.baseVal)))return;const r=e?n.src:n.href.baseVal,i=await Fs(r,As(r),t);await new Promise((s,o)=>{n.onload=s,n.onerror=t.onImageErrorHandler?(...l)=>{try{s(t.onImageErrorHandler(...l))}catch(c){o(c)}}:o;const a=n;a.decode&&(a.decode=s),a.loading==="lazy"&&(a.loading="eager"),e?(n.srcset="",n.src=i):n.href.baseVal=i})}async function id(n,t){const r=pe(n.childNodes).map(i=>Ca(i,t));await Promise.all(r).then(()=>n)}async function Ca(n,t){wt(n,Element)&&(await ed(n,t),await rd(n,t),await id(n,t))}function sd(n,t){const{style:e}=n;t.backgroundColor&&(e.backgroundColor=t.backgroundColor),t.width&&(e.width=`${t.width}px`),t.height&&(e.height=`${t.height}px`);const r=t.style;return r!=null&&Object.keys(r).forEach(i=>{e[i]=r[i]}),n}const Sa={};async function Ta(n){let t=Sa[n];if(t!=null)return t;const r=await(await fetch(n)).text();return t={url:n,cssText:r},Sa[n]=t,t}async function ka(n,t){let e=n.cssText;const r=/url\(["']?([^"')]+)["']?\)/g,s=(e.match(/url\([^)]+\)/g)||[]).map(async o=>{let a=o.replace(r,"$1");return a.startsWith("https://")||(a=new URL(a,n.url).href),ba(a,t.fetchRequestInit,({result:l})=>(e=e.replace(o,`url(${l})`),[o,l]))});return Promise.all(s).then(()=>e)}function Oa(n){if(n==null)return[];const t=[],e=/(\/\*[\s\S]*?\*\/)/gi;let r=n.replace(e,"");const i=new RegExp("((@.*?keyframes [\\s\\S]*?){([\\s\\S]*?}\\s*?)})","gi");for(;;){const l=i.exec(r);if(l===null)break;t.push(l[0])}r=r.replace(i,"");const s=/@import[\s\S]*?url\([^)]*\)[\s\S]*?;/gi,o="((\\s*?(?:\\/\\*[\\s\\S]*?\\*\\/)?\\s*?@media[\\s\\S]*?){([\\s\\S]*?)}\\s*?})|(([\\s\\S]*?){([\\s\\S]*?)})",a=new RegExp(o,"gi");for(;;){let l=s.exec(r);if(l===null){if(l=a.exec(r),l===null)break;s.lastIndex=a.lastIndex}else a.lastIndex=s.lastIndex;t.push(l[0])}return t}async function nd(n,t){const e=[],r=[];return n.forEach(i=>{if("cssRules"in i)try{pe(i.cssRules||[]).forEach((s,o)=>{if(s.type===CSSRule.IMPORT_RULE){let a=o+1;const l=s.href,c=Ta(l).then(h=>ka(h,t)).then(h=>Oa(h).forEach(u=>{try{i.insertRule(u,u.startsWith("@import")?a+=1:i.cssRules.length)}catch(d){console.error("Error inserting rule from remote css",{rule:u,error:d})}})).catch(h=>{console.error("Error loading remote css",h.toString())});r.push(c)}})}catch(s){const o=n.find(a=>a.href==null)||document.styleSheets[0];i.href!=null&&r.push(Ta(i.href).then(a=>ka(a,t)).then(a=>Oa(a).forEach(l=>{o.insertRule(l,o.cssRules.length)})).catch(a=>{console.error("Error loading remote stylesheet",a)})),console.error("Error inlining remote css file",s)}}),Promise.all(r).then(()=>(n.forEach(i=>{if("cssRules"in i)try{pe(i.cssRules||[]).forEach(s=>{e.push(s)})}catch(s){console.error(`Error while reading CSS rules from ${i.href}`,s)}}),e))}function od(n){return n.filter(t=>t.type===CSSRule.FONT_FACE_RULE).filter(t=>xa(t.style.getPropertyValue("src")))}async function ad(n,t){if(n.ownerDocument==null)throw new Error("Provided element is not within a Document");const e=pe(n.ownerDocument.styleSheets),r=await nd(e,t);return od(r)}function Da(n){return n.trim().replace(/["']/g,"")}function ld(n){const t=new Set;function e(r){(r.style.fontFamily||getComputedStyle(r).fontFamily).split(",").forEach(s=>{t.add(Da(s))}),Array.from(r.children).forEach(s=>{s instanceof HTMLElement&&e(s)})}return e(n),t}async function cd(n,t){const e=await ad(n,t),r=ld(n);return(await Promise.all(e.filter(s=>r.has(Da(s.style.fontFamily))).map(s=>{const o=s.parentStyleSheet?s.parentStyleSheet.href:null;return wa(s.cssText,o,t)}))).join(`
|
|
585
|
+
`)}async function hd(n,t){const e=t.fontEmbedCSS!=null?t.fontEmbedCSS:t.skipFonts?null:await cd(n,t);if(e){const r=document.createElement("style"),i=document.createTextNode(e);r.appendChild(i),n.firstChild?n.insertBefore(r,n.firstChild):n.appendChild(r)}}async function ud(n,t={}){const{width:e,height:r}=fa(n,t),i=await Ci(n,t,!0);return await hd(i,t),await Ca(i,t),sd(i,t),await Du(i,e,r)}async function dd(n,t={}){const{width:e,height:r}=fa(n,t),i=await ud(n,t),s=await wi(i),o=document.createElement("canvas"),a=o.getContext("2d"),l=t.pixelRatio||Tu(),c=t.canvasWidth||e,h=t.canvasHeight||r;return o.width=c*l,o.height=h*l,t.skipAutoScale||ku(o),o.style.width=`${c}`,o.style.height=`${h}`,t.backgroundColor&&(a.fillStyle=t.backgroundColor,a.fillRect(0,0,o.width,o.height)),a.drawImage(s,0,0,o.width,o.height),o}async function gd(){try{const n=await navigator.mediaDevices.getDisplayMedia({video:{displaySurface:"browser"},audio:!1}),t=document.createElement("video");t.srcObject=n,t.autoplay=!0,await new Promise(i=>{t.onloadedmetadata=()=>i()}),await new Promise(i=>setTimeout(i,100));const e=document.createElement("canvas");e.width=t.videoWidth,e.height=t.videoHeight;const r=e.getContext("2d");if(!r)throw new Error("Failed to get canvas context");return r.drawImage(t,0,0),n.getTracks().forEach(i=>i.stop()),e.toDataURL("image/png")}catch(n){throw n instanceof Error&&n.name==="NotAllowedError"?new Error("Screen capture permission denied"):n}}async function fd(n="visible",t,e=!1){if(e)return gd();let r;switch(n){case"element":throw new Error("Selector required for element capture");case"fullpage":r=document.documentElement;break;case"visible":default:r=document.documentElement;break}const i=document.getElementById("bugpin-widget");i&&(i.style.display="none");let s={};if(n==="visible"&&r===document.documentElement){const o=document.documentElement,a=window.getComputedStyle(document.body);s={background:o.style.background||void 0,minHeight:o.style.minHeight||void 0,minWidth:o.style.minWidth||void 0},o.style.minWidth="100vw",o.style.minHeight="100vh",o.style.background=a.backgroundColor||a.background||"#ffffff"}try{const a={cacheBust:!0,quality:1,pixelRatio:window.devicePixelRatio||1,skipAutoScale:!0,filter:c=>!(c instanceof HTMLElement&&(c.tagName==="SCRIPT"||c.id==="bugpin-widget"))};return n==="visible"&&(a.width=window.innerWidth,a.height=window.innerHeight,console.log("[BugPin] Capturing element:",r.tagName),console.log("[BugPin] Element dimensions:",{scrollWidth:r.scrollWidth,scrollHeight:r.scrollHeight,clientWidth:r.clientWidth,clientHeight:r.clientHeight}),console.log("[BugPin] Viewport dimensions:",{innerWidth:window.innerWidth,innerHeight:window.innerHeight}),console.log("[BugPin] Capture options:",a)),(await dd(r,a)).toDataURL("image/png")}finally{if(n==="visible"&&r===document.documentElement){const o=document.documentElement;s.background!==void 0?o.style.background=s.background:o.style.removeProperty("background"),s.minHeight!==void 0?o.style.minHeight=s.minHeight:o.style.removeProperty("min-height"),s.minWidth!==void 0?o.style.minWidth=s.minWidth:o.style.removeProperty("min-width")}i&&(i.style.display="")}}function Ma(n){const t=n.split(","),e=t[0].match(/:(.*?);/),r=e?e[1]:"image/png",i=atob(t[1]),s=new Uint8Array(i.length);for(let o=0;o<i.length;o++)s[o]=i.charCodeAt(o);return new Blob([s],{type:r})}function Ea(n){return n.startsWith("data:image/webp")?"webp":n.startsWith("data:image/jpeg")?"jpg":n.startsWith("data:image/gif")?"gif":"png"}const Ue=[];let Pa=!1;function pd(){if(Pa)return;Pa=!0;const n=console.error;console.error=(...r)=>{Ue.push({type:"error",message:r.map(i=>String(i)).join(" "),timestamp:new Date().toISOString()}),n.apply(console,r)};const t=console.warn;console.warn=(...r)=>{Ue.push({type:"warn",message:r.map(i=>String(i)).join(" "),timestamp:new Date().toISOString()}),t.apply(console,r)};const e=window.onerror;window.onerror=(r,i,s,o,a)=>(Ue.push({type:"error",message:String(r),source:i||void 0,line:s||void 0,timestamp:new Date().toISOString()}),e?e.apply(window,[r,i,s,o,a]):!1),window.addEventListener("unhandledrejection",r=>{Ue.push({type:"error",message:`Unhandled Promise Rejection: ${String(r.reason)}`,timestamp:new Date().toISOString()})})}function md(){var r,i,s,o,a;const n=navigator.userAgent;let t="Unknown",e="";return n.includes("Firefox/")?(t="Firefox",e=((r=n.match(/Firefox\/([\d.]+)/))==null?void 0:r[1])||""):n.includes("Edg/")?(t="Edge",e=((i=n.match(/Edg\/([\d.]+)/))==null?void 0:i[1])||""):n.includes("Chrome/")?(t="Chrome",e=((s=n.match(/Chrome\/([\d.]+)/))==null?void 0:s[1])||""):n.includes("Safari/")&&!n.includes("Chrome")?(t="Safari",e=((o=n.match(/Version\/([\d.]+)/))==null?void 0:o[1])||""):(n.includes("Opera/")||n.includes("OPR/"))&&(t="Opera",e=((a=n.match(/(?:Opera|OPR)\/([\d.]+)/))==null?void 0:a[1])||""),{name:t,version:e,userAgent:n}}function vd(){var i,s,o,a,l;const n=navigator.userAgent;let t="desktop",e="Unknown",r;if(/Mobi|Android|iPhone|iPad|iPod/i.test(n)&&(/iPad|Tablet/i.test(n)||window.innerWidth>=768&&/Android/i.test(n)?t="tablet":t="mobile"),n.includes("Windows")){e="Windows";const c=n.match(/Windows NT ([\d.]+)/);if(c){const h=c[1];r={"10.0":"10/11","6.3":"8.1","6.2":"8","6.1":"7","6.0":"Vista"}[h]||h}}else n.includes("Mac OS X")?(e="macOS",r=(s=(i=n.match(/Mac OS X ([\d._]+)/))==null?void 0:i[1])==null?void 0:s.replace(/_/g,".")):n.includes("Linux")?(e=n.includes("Android")?"Android":"Linux",e==="Android"&&(r=(o=n.match(/Android ([\d.]+)/))==null?void 0:o[1])):(n.includes("iPhone")||n.includes("iPad"))&&(e="iOS",r=(l=(a=n.match(/OS ([\d_]+)/))==null?void 0:a[1])==null?void 0:l.replace(/_/g,"."));return{type:t,os:e,osVersion:r}}function bd(){return{width:window.innerWidth,height:window.innerHeight,devicePixelRatio:window.devicePixelRatio,orientation:window.innerWidth>window.innerHeight?"landscape":"portrait"}}function yd(){try{const n=performance.getEntriesByType("navigation");if(n.length>0){const t=n[0];return Math.round(t.loadEventEnd-t.startTime)}}catch{}}function _d(){return{url:window.location.href,title:document.title||void 0,referrer:document.referrer||void 0,browser:md(),device:vd(),viewport:bd(),timestamp:new Date().toISOString(),timezone:Intl.DateTimeFormat().resolvedOptions().timeZone,pageLoadTime:yd(),consoleErrors:Ue.length>0?[...Ue]:void 0}}pd();const Rs=(n,t)=>t.some(e=>n instanceof e);let Aa,ja;function xd(){return Aa||(Aa=[IDBDatabase,IDBObjectStore,IDBIndex,IDBCursor,IDBTransaction])}function wd(){return ja||(ja=[IDBCursor.prototype.advance,IDBCursor.prototype.continue,IDBCursor.prototype.continuePrimaryKey])}const Bs=new WeakMap,Is=new WeakMap,Si=new WeakMap;function Cd(n){const t=new Promise((e,r)=>{const i=()=>{n.removeEventListener("success",s),n.removeEventListener("error",o)},s=()=>{e(Se(n.result)),i()},o=()=>{r(n.error),i()};n.addEventListener("success",s),n.addEventListener("error",o)});return Si.set(t,n),t}function Sd(n){if(Bs.has(n))return;const t=new Promise((e,r)=>{const i=()=>{n.removeEventListener("complete",s),n.removeEventListener("error",o),n.removeEventListener("abort",o)},s=()=>{e(),i()},o=()=>{r(n.error||new DOMException("AbortError","AbortError")),i()};n.addEventListener("complete",s),n.addEventListener("error",o),n.addEventListener("abort",o)});Bs.set(n,t)}let Hs={get(n,t,e){if(n instanceof IDBTransaction){if(t==="done")return Bs.get(n);if(t==="store")return e.objectStoreNames[1]?void 0:e.objectStore(e.objectStoreNames[0])}return Se(n[t])},set(n,t,e){return n[t]=e,!0},has(n,t){return n instanceof IDBTransaction&&(t==="done"||t==="store")?!0:t in n}};function La(n){Hs=n(Hs)}function Td(n){return wd().includes(n)?function(...t){return n.apply(zs(this),t),Se(this.request)}:function(...t){return Se(n.apply(zs(this),t))}}function kd(n){return typeof n=="function"?Td(n):(n instanceof IDBTransaction&&Sd(n),Rs(n,xd())?new Proxy(n,Hs):n)}function Se(n){if(n instanceof IDBRequest)return Cd(n);if(Is.has(n))return Is.get(n);const t=kd(n);return t!==n&&(Is.set(n,t),Si.set(t,n)),t}const zs=n=>Si.get(n);function Od(n,t,{blocked:e,upgrade:r,blocking:i,terminated:s}={}){const o=indexedDB.open(n,t),a=Se(o);return r&&o.addEventListener("upgradeneeded",l=>{r(Se(o.result),l.oldVersion,l.newVersion,Se(o.transaction),l)}),e&&o.addEventListener("blocked",l=>e(l.oldVersion,l.newVersion,l)),a.then(l=>{s&&l.addEventListener("close",()=>s()),i&&l.addEventListener("versionchange",c=>i(c.oldVersion,c.newVersion,c))}).catch(()=>{}),a}const Dd=["get","getKey","getAll","getAllKeys","count"],Md=["put","add","delete","clear"],Ws=new Map;function Fa(n,t){if(!(n instanceof IDBDatabase&&!(t in n)&&typeof t=="string"))return;if(Ws.get(t))return Ws.get(t);const e=t.replace(/FromIndex$/,""),r=t!==e,i=Md.includes(e);if(!(e in(r?IDBIndex:IDBObjectStore).prototype)||!(i||Dd.includes(e)))return;const s=async function(o,...a){const l=this.transaction(o,i?"readwrite":"readonly");let c=l.store;return r&&(c=c.index(a.shift())),(await Promise.all([c[e](...a),i&&l.done]))[0]};return Ws.set(t,s),s}La(n=>({...n,get:(t,e,r)=>Fa(t,e)||n.get(t,e,r),has:(t,e)=>!!Fa(t,e)||n.has(t,e)}));const Ed=["continue","continuePrimaryKey","advance"],Ra={},Vs=new WeakMap,Ba=new WeakMap,Pd={get(n,t){if(!Ed.includes(t))return n[t];let e=Ra[t];return e||(e=Ra[t]=function(...r){Vs.set(this,Ba.get(this)[t](...r))}),e}};async function*Ad(...n){let t=this;if(t instanceof IDBCursor||(t=await t.openCursor(...n)),!t)return;t=t;const e=new Proxy(t,Pd);for(Ba.set(e,t),Si.set(e,zs(t));t;)yield e,t=await(Vs.get(e)||t.continue()),Vs.delete(e)}function Ia(n,t){return t===Symbol.asyncIterator&&Rs(n,[IDBIndex,IDBObjectStore,IDBCursor])||t==="iterate"&&Rs(n,[IDBIndex,IDBObjectStore])}La(n=>({...n,get(t,e,r){return Ia(t,e)?Ad:n.get(t,e,r)},has(t,e){return Ia(t,e)||n.has(t,e)}}));const jd="bugpin-reports",Ld=2,Ge="pending-reports",Ha=5,Fd=5e3,Rd=3e5,Bd=2;let Ti=null,za=null;function Id(n){return{"image/png":"png","image/jpeg":"jpg","image/gif":"gif","image/webp":"webp","video/mp4":"mp4","video/webm":"webm","video/quicktime":"mov","video/x-msvideo":"avi"}[n]||"bin"}async function ki(){if(Ti)return Ti;try{return Ti=await Od(jd,Ld,{upgrade(n){n.objectStoreNames.contains(Ge)||n.createObjectStore(Ge,{keyPath:"id"}).createIndex("by-created","createdAt")}}),Ti}catch(n){throw console.error("[BugPin] Failed to initialize IndexedDB:",n),n}}function Hd(){return`${Date.now()}-${Math.random().toString(36).substring(2,11)}`}function Oi(){return navigator.onLine!==!1}function zd(n){const t=Fd*Math.pow(Bd,n);return Math.min(t,Rd)}async function Wa(n){const t=await ki(),e={...n,id:Hd(),createdAt:new Date().toISOString(),retryCount:0};return await t.put(Ge,e),console.log("[BugPin] Report buffered for later submission:",e.id),Oi()&&Di().catch(console.error),e.id}async function Wd(){try{return await(await ki()).getAllFromIndex(Ge,"by-created")}catch{return[]}}async function Va(n){try{await(await ki()).delete(Ge,n),console.log("[BugPin] Removed buffered report:",n)}catch(t){console.error("[BugPin] Failed to remove buffered report:",t)}}async function Vd(n){try{await(await ki()).put(Ge,n)}catch(t){console.error("[BugPin] Failed to update buffered report:",t)}}async function Xd(n){var t,e;try{const r=new URL("/api/widget/submit",n.serverUrl);r.searchParams.set("apiKey",n.apiKey);const i=new FormData;if(i.append("data",JSON.stringify({title:n.title,description:n.description,priority:n.priority,reporterEmail:n.reporterEmail,reporterName:n.reporterName,metadata:n.metadata,mediaCount:((t=n.media)==null?void 0:t.length)||0,mediaAnnotations:(e=n.media)==null?void 0:e.map(o=>o.annotations).filter(Boolean)})),n.media&&n.media.length>0)for(let o=0;o<n.media.length;o++){const a=n.media[o],l=Ma(a.dataUrl),c=Ea(a.dataUrl)||Id(a.mimeType),u=a.mimeType.startsWith("video/")?"video":"screenshot";i.append("media",l,`${u}-${o}.${c}`)}const s=await fetch(r.toString(),{method:"POST",body:i});if(!s.ok){const o=await s.json().catch(()=>({}));throw new Error(o.message||`HTTP ${s.status}`)}return!0}catch(r){throw console.error("[BugPin] Failed to submit buffered report:",r),r}}async function Di(){if(!Oi())return console.log("[BugPin] Offline, skipping sync"),{synced:0,failed:0};const n=await Wd();if(n.length===0)return{synced:0,failed:0};console.log(`[BugPin] Syncing ${n.length} pending reports...`);let t=0,e=0;for(const r of n){if(r.lastRetryAt){const s=new Date(r.lastRetryAt).getTime()+zd(r.retryCount);if(Date.now()<s)continue}try{await Xd(r),await Va(r.id),t++,console.log("[BugPin] Successfully synced report:",r.id)}catch(i){e++,r.retryCount++,r.lastRetryAt=new Date().toISOString(),r.error=i instanceof Error?i.message:"Unknown error",r.retryCount>=Ha?(console.error("[BugPin] Max retries exceeded, removing report:",r.id),await Va(r.id)):(await Vd(r),console.log(`[BugPin] Report retry scheduled (attempt ${r.retryCount}/${Ha}):`,r.id))}}return{synced:t,failed:e}}function Yd(){window.addEventListener("online",()=>{console.log("[BugPin] Back online, syncing pending reports..."),Di().catch(console.error)}),za||(za=setInterval(()=>{Oi()&&Di().catch(console.error)},3e4)),Oi()&&Di().catch(console.error)}Yd();function Ud(){return navigator.onLine!==!1}function Gd(n){return{"image/png":"png","image/jpeg":"jpg","image/gif":"gif","image/webp":"webp","video/mp4":"mp4","video/webm":"webm","video/quicktime":"mov","video/x-msvideo":"avi"}[n]||"bin"}async function Nd(n){const{apiKey:t,serverUrl:e,media:r,...i}=n;if(!Ud())return console.log("[BugPin] Offline, buffering report for later submission"),await Wa({apiKey:t,serverUrl:e,title:i.title,description:i.description,priority:i.priority,reporterEmail:i.reporterEmail,reporterName:i.reporterName,media:r,metadata:i.metadata}),{success:!0,message:"Report saved. It will be submitted when you're back online."};const s=new URL("/api/widget/submit",e);s.searchParams.set("apiKey",t);const o=new FormData;if(o.append("data",JSON.stringify({title:i.title,description:i.description,priority:i.priority,reporterEmail:i.reporterEmail,reporterName:i.reporterName,metadata:i.metadata,mediaCount:(r==null?void 0:r.length)||0,mediaAnnotations:r==null?void 0:r.map(a=>a.annotations).filter(Boolean)})),r&&r.length>0)for(let a=0;a<r.length;a++){const l=r[a],c=Ma(l.dataUrl),h=Ea(l.dataUrl)||Gd(l.mimeType),d=l.mimeType.startsWith("video/")?"video":"screenshot";console.log(`[BugPin] Media ${a}: dataUrl length=${l.dataUrl.length}, blob size=${c.size}, type=${c.type}`),o.append("media",c,`${d}-${a}.${h}`)}try{const a=await fetch(s.toString(),{method:"POST",body:o}),l=await a.json();if(!a.ok||!l.success)throw new Error(l.message||l.error||"Failed to submit report");return l}catch(a){if(a instanceof TypeError&&a.message.includes("fetch"))return console.log("[BugPin] Network error, buffering report for later submission"),await Wa({apiKey:t,serverUrl:e,title:i.title,description:i.description,priority:i.priority,reporterEmail:i.reporterEmail,reporterName:i.reporterName,media:r,metadata:i.metadata}),{success:!0,message:"Report saved. It will be submitted when the connection is restored."};throw a}}function $d(n){return n==="auto"?window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light":n}const Xa={title:"",description:"",priority:"medium",reporterEmail:"",reporterName:""},qd=({config:n})=>{const t=St(null),[e,r]=rt("closed"),[i,s]=rt(!1),[o,a]=rt(!1),[l,c]=rt([]),[h,u]=rt(null),[d,g]=rt(null),[f,m]=rt("details"),[b,y]=rt(Xa);Ft(()=>{const M=()=>w(),j=()=>O();return document.addEventListener("bugpin:open",M),document.addEventListener("bugpin:close",j),()=>{document.removeEventListener("bugpin:open",M),document.removeEventListener("bugpin:close",j)}},[]),Ft(()=>{const M=t.current;if(!M)return;const j=()=>{$d(n.theme)==="dark"?(M.style.setProperty("--button-color",n.dialogDarkButtonColor),M.style.setProperty("--button-text-color",n.dialogDarkTextColor),M.style.setProperty("--button-hover-color",n.dialogDarkButtonHoverColor),M.style.setProperty("--button-hover-text-color",n.dialogDarkTextHoverColor)):(M.style.setProperty("--button-color",n.dialogLightButtonColor),M.style.setProperty("--button-text-color",n.dialogLightTextColor),M.style.setProperty("--button-hover-color",n.dialogLightButtonHoverColor),M.style.setProperty("--button-hover-text-color",n.dialogLightTextHoverColor))};if(j(),n.theme==="auto"){const z=window.matchMedia("(prefers-color-scheme: dark)"),V=()=>j();return z.addEventListener("change",V),()=>z.removeEventListener("change",V)}},[n.theme,n.dialogLightButtonColor,n.dialogLightTextColor,n.dialogLightButtonHoverColor,n.dialogLightTextHoverColor,n.dialogDarkButtonColor,n.dialogDarkTextColor,n.dialogDarkButtonHoverColor,n.dialogDarkTextHoverColor]);const w=Y(()=>{r("form")},[]),O=Y(()=>{r("closed"),c([]),u(null),m("details"),y(Xa)},[]),k=Y(async()=>{if(n.enableScreenshot){a(!0),r("closed"),await new Promise(M=>setTimeout(M,100));try{const M=await fd(n.captureMethod,void 0,n.useScreenCaptureAPI),j=new Image;j.onload=()=>{console.log(`[BugPin] Captured screenshot: ${j.width}x${j.height}, dataUrl length=${M.length}`);const z={id:`capture-${Date.now()}-${Math.random().toString(36).slice(2,9)}`,dataUrl:M,timestamp:new Date,annotated:!1,mimeType:"image/png",width:j.width,height:j.height};c(V=>[...V,z]),a(!1),m("media"),r("form")},j.onerror=()=>{const z={id:`capture-${Date.now()}-${Math.random().toString(36).slice(2,9)}`,dataUrl:M,timestamp:new Date,annotated:!1,mimeType:"image/png"};c(V=>[...V,z]),a(!1),m("media"),r("form")},j.src=M}catch(M){console.error("[BugPin] Failed to capture screenshot:",M),a(!1),r("form"),g({message:"Failed to capture screenshot",type:"error"})}}},[n]),S=Y(M=>{c(j=>[...j,M])},[]),C=Y(M=>{c(j=>j.filter(z=>z.id!==M))},[]),A=Y(M=>{u(M),r("annotating")},[]),D=Y((M,j)=>{h&&c(z=>z.map(V=>V.id===h?{...V,dataUrl:M,annotated:!0,annotations:j}:V)),u(null),r("form")},[h]),L=Y(()=>{u(null),r("form")},[]),R=Y(async(M,j)=>{s(!0);try{const z=_d();await Nd({apiKey:n.apiKey,serverUrl:n.serverUrl,title:M.title,description:M.description,priority:M.priority,reporterEmail:M.reporterEmail||void 0,reporterName:M.reporterName||void 0,media:j.map(V=>({dataUrl:V.dataUrl,mimeType:V.mimeType,annotations:V.annotations})),metadata:z}),g({message:"Bug report submitted successfully!",type:"success"}),O()}catch(z){console.error("[BugPin] Failed to submit report:",z),g({message:z instanceof Error?z.message:"Failed to submit report",type:"error"})}finally{s(!1)}},[n,O]),H=Y(()=>{g(null)},[]),I=h?l.find(M=>M.id===h):null;return _("div",{ref:t,class:`bugpin-container bugpin-theme-${n.theme}`,children:[_(yl,{position:n.position,buttonText:n.buttonText,buttonShape:n.buttonShape,buttonIcon:n.buttonIcon,buttonIconSize:n.buttonIconSize,buttonIconStroke:n.buttonIconStroke,theme:n.theme,lightButtonColor:n.lightButtonColor,lightTextColor:n.lightTextColor,lightButtonHoverColor:n.lightButtonHoverColor,lightTextHoverColor:n.lightTextHoverColor,darkButtonColor:n.darkButtonColor,darkTextColor:n.darkTextColor,darkButtonHoverColor:n.darkButtonHoverColor,darkTextHoverColor:n.darkTextHoverColor,enableHoverScaleEffect:n.enableHoverScaleEffect,tooltipEnabled:n.tooltipEnabled,tooltipText:n.tooltipText,onClick:w}),e==="annotating"&&I&&_("div",{class:"bugpin-overlay",children:_("div",{class:"bugpin-annotation-modal",children:_(_u,{screenshot:I.dataUrl,onSave:D,onCancel:L})})}),e==="form"&&_(Ol,{onClose:O,onSubmit:R,onCaptureScreenshot:k,onAnnotateMedia:A,media:l,onAddMedia:S,onRemoveMedia:C,isSubmitting:i,isCapturing:o,enableAnnotation:n.enableAnnotation,activeTab:f,onActiveTabChange:m,formData:b,onFormDataChange:y}),d&&_(Dl,{message:d.message,type:d.type,onClose:H})]})},Xs={apiKey:"",serverUrl:window.location.origin,position:"bottom-right",buttonText:null,buttonShape:"rectangle",buttonIcon:"bug",buttonIconSize:18,buttonIconStroke:2,theme:"auto",lightButtonColor:"#6366f1",lightTextColor:"#ffffff",lightButtonHoverColor:"#4f46e5",lightTextHoverColor:"#ffffff",darkButtonColor:"#818cf8",darkTextColor:"#1e1b4b",darkButtonHoverColor:"#a5b4fc",darkTextHoverColor:"#1e1b4b",dialogLightButtonColor:"#ebebeb",dialogLightTextColor:"#575757",dialogLightButtonHoverColor:"#ebebeb",dialogLightTextHoverColor:"#575757",dialogDarkButtonColor:"#3c3c3c",dialogDarkTextColor:"#c3c3c3",dialogDarkButtonHoverColor:"#3c3c3c",dialogDarkTextHoverColor:"#c3c3c3",enableHoverScaleEffect:!0,tooltipEnabled:!1,tooltipText:null,enableScreenshot:!0,enableAnnotation:!0,enableConsoleCapture:!0,captureMethod:"visible",useScreenCaptureAPI:!1,maxScreenshotSize:5*1024*1024},Kd='*{box-sizing:border-box;margin:0;padding:0}#bugpin-root{font-family:-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Oxygen,Ubuntu,sans-serif;font-size:14px;line-height:1.5;--background: #ffffff;--foreground: #0a0a0a;--muted: #f5f5f5;--muted-foreground: #737373;--border: #e5e5e5;--input: #e5e5e5;--ring: #a3a3a3;--primary: var(--button-color, #18181b);--primary-foreground: var(--button-text-color, #fafafa);--primary-hover: var(--button-hover-color, #27272a);--primary-hover-foreground: var(--button-hover-text-color, #fafafa);--destructive: #ef4444;--destructive-foreground: #fafafa;--radius: .5rem;--shadow-sm: 0 1px 2px 0 rgb(0 0 0 / .05);--shadow: 0 1px 3px 0 rgb(0 0 0 / .1), 0 1px 2px -1px rgb(0 0 0 / .1);--shadow-lg: 0 10px 15px -3px rgb(0 0 0 / .1), 0 4px 6px -4px rgb(0 0 0 / .1);color:var(--foreground)}.bugpin-launcher-button{display:flex;align-items:center;justify-content:center;gap:8px;border:none;font-size:14px;font-weight:500;cursor:pointer;box-shadow:0 4px 12px #00000026}.bugpin-launcher-button.hover-scale{transition:transform .3s ease,box-shadow .3s ease}.bugpin-launcher-button.hover-scale:hover{transform:scale(1.1);box-shadow:0 8px 20px #00000040}.bugpin-launcher-button.hover-scale:active{transform:scale(1.05)}.bugpin-launcher-button-container.bottom-right{bottom:20px;right:20px}.bugpin-launcher-button-container.bottom-left{bottom:20px;left:20px}.bugpin-launcher-button-container.top-right{top:20px;right:20px}.bugpin-launcher-button-container.top-left{top:20px;left:20px}.bugpin-launcher-button svg{stroke:currentColor;fill:none}.bugpin-overlay{position:fixed;top:0;right:0;bottom:0;left:0;z-index:2147483646;background:#00000080;display:flex;align-items:center;justify-content:center;padding:20px;animation:fadeIn .2s ease-out}@keyframes fadeIn{0%{opacity:0}to{opacity:1}}.bugpin-dialog{position:relative;width:100%;max-width:480px;max-height:90vh;background:var(--background);border:1px solid var(--border);border-radius:var(--radius);box-shadow:var(--shadow-lg);overflow:hidden;display:flex;flex-direction:column;animation:slideUp .2s ease-out}@keyframes slideUp{0%{opacity:0;transform:translateY(20px)}to{opacity:1;transform:translateY(0)}}.bugpin-header{display:flex;align-items:center;justify-content:space-between;padding:1.5rem;border-bottom:1px solid var(--border)}.bugpin-header h2{font-size:1.125rem;font-weight:600;color:var(--foreground);letter-spacing:-.025em}.bugpin-close{display:flex;align-items:center;justify-content:center;width:2rem;height:2rem;border:none;border-radius:calc(var(--radius) - 4px);background:transparent;color:var(--muted-foreground);cursor:pointer;transition:background .15s,color .15s}.bugpin-close:hover{background:var(--muted);color:var(--foreground)}.bugpin-close svg{width:1.25rem;height:1.25rem}.bugpin-body{flex:1;overflow-y:auto;padding:1.5rem}.bugpin-form{display:flex;flex-direction:column;gap:16px}.bugpin-field{display:flex;flex-direction:column;gap:6px}.bugpin-label{font-size:.875rem;font-weight:500;color:var(--foreground)}.bugpin-label.required:after{content:" *";color:var(--destructive)}.bugpin-input,.bugpin-textarea{height:2.5rem;padding:.5rem .75rem;border:1px solid var(--input);border-radius:calc(var(--radius) - 2px);font-size:.875rem;font-family:inherit;color:var(--foreground);background:transparent;transition:border-color .15s,box-shadow .15s}.bugpin-input:focus,.bugpin-textarea:focus{outline:none;border-color:var(--ring);box-shadow:0 0 0 2px var(--background),0 0 0 4px var(--ring)}.bugpin-input::placeholder,.bugpin-textarea::placeholder{color:var(--muted-foreground)}.bugpin-textarea{height:auto;min-height:5rem;resize:vertical}.bugpin-select{height:2.5rem;padding:.5rem .75rem;border:1px solid var(--input);border-radius:calc(var(--radius) - 2px);font-size:.875rem;font-family:inherit;color:var(--foreground);background:transparent;cursor:pointer;transition:border-color .15s,box-shadow .15s}.bugpin-select:focus{outline:none;border-color:var(--ring);box-shadow:0 0 0 2px var(--background),0 0 0 4px var(--ring)}.bugpin-screenshot{margin-top:8px;border-radius:8px;overflow:hidden;background:#f9fafb;border:1px solid #e5e7eb}.bugpin-screenshot img{display:block;width:100%;height:auto;max-height:200px;object-fit:contain}.bugpin-screenshot-actions{display:flex;gap:8px;padding:8px;border-top:1px solid #e5e7eb}.bugpin-btn-secondary{flex:1;display:flex;align-items:center;justify-content:center;gap:6px;padding:8px 12px;border:1px solid #d1d5db;border-radius:6px;background:#fff;color:#374151;font-size:13px;font-weight:500;cursor:pointer;transition:background .15s,border-color .15s}.bugpin-btn-secondary:hover{background:#f9fafb;border-color:#9ca3af}.bugpin-btn-secondary svg{width:16px;height:16px}.bugpin-footer{display:flex;gap:.75rem;padding:1.5rem;border-top:1px solid var(--border);background:var(--muted)}.bugpin-btn-cancel{flex:1;height:2.5rem;padding:0 1rem;border:1px solid var(--input);border-radius:calc(var(--radius) - 2px);background:var(--background);color:var(--foreground);font-size:.875rem;font-weight:500;cursor:pointer;transition:background .15s}.bugpin-btn-cancel:hover{background:var(--muted)}.bugpin-btn-submit{flex:1;height:2.5rem;padding:0 1rem;border:none;border-radius:calc(var(--radius) - 2px);background:var(--primary);color:var(--primary-foreground);font-size:.875rem;font-weight:500;cursor:pointer;transition:background .15s,color .15s}.bugpin-btn-submit:hover{background:var(--primary-hover);color:var(--primary-hover-foreground)}.bugpin-btn-submit:disabled{opacity:.5;cursor:not-allowed}.bugpin-toast{position:fixed;bottom:80px;right:20px;z-index:2147483647;display:flex;align-items:center;gap:.75rem;padding:1rem;border:1px solid var(--border);border-radius:var(--radius);background:var(--background);color:var(--foreground);font-size:.875rem;box-shadow:var(--shadow-lg);animation:slideIn .3s ease-out}.bugpin-toast.success{border-color:#22c55e}.bugpin-toast.error{border-color:var(--destructive)}@keyframes slideIn{0%{opacity:0;transform:translate(20px)}to{opacity:1;transform:translate(0)}}.bugpin-toast svg{width:20px;height:20px;flex-shrink:0}.bugpin-spinner{width:18px;height:18px;border:2px solid rgba(255,255,255,.3);border-top-color:#fff;border-radius:50%;animation:spin .8s linear infinite}@keyframes spin{to{transform:rotate(360deg)}}.priority-lowest{color:#6b7280}.priority-low{color:#3b82f6}.priority-medium{color:#f59e0b}.priority-high{color:#ef4444}.priority-highest{color:#dc2626}.bugpin-theme-dark,.bugpin-container.bugpin-theme-dark{--background: #0a0a0a;--foreground: #fafafa;--muted: #262626;--muted-foreground: #a3a3a3;--border: #262626;--input: #262626;--ring: #d4d4d4}.bugpin-theme-dark .bugpin-dialog{background:var(--background);color:var(--foreground)}.bugpin-theme-dark .bugpin-header{border-color:var(--border)}.bugpin-theme-dark .bugpin-header h2{color:var(--foreground)}.bugpin-theme-dark .bugpin-close:hover{background:var(--muted);color:var(--foreground)}.bugpin-theme-dark .bugpin-label{color:var(--foreground)}.bugpin-theme-dark .bugpin-input,.bugpin-theme-dark .bugpin-textarea,.bugpin-theme-dark .bugpin-select{background:var(--muted);border-color:var(--input);color:var(--foreground)}.bugpin-theme-dark .bugpin-input::placeholder,.bugpin-theme-dark .bugpin-textarea::placeholder{color:var(--muted-foreground)}.bugpin-theme-dark .bugpin-screenshot{background:var(--muted);border-color:var(--border)}.bugpin-theme-dark .bugpin-screenshot-actions{border-color:var(--border)}.bugpin-theme-dark .bugpin-btn-secondary{background:var(--muted);border-color:var(--border);color:var(--foreground)}.bugpin-theme-dark .bugpin-btn-secondary:hover{background:#3f3f46}.bugpin-theme-dark .bugpin-footer{background:#171717;border-color:var(--border)}.bugpin-theme-dark .bugpin-btn-cancel{background:var(--muted);border-color:var(--border);color:var(--foreground)}.bugpin-theme-dark .bugpin-btn-cancel:hover{background:#3f3f46}.bugpin-error{color:var(--destructive);font-size:.75rem;margin-top:.25rem}.bugpin-annotation-container{display:flex;flex-direction:column;height:100%;background:#1f2937}.bugpin-annotation-toolbar{display:flex;align-items:center;gap:8px;padding:12px 16px;background:#111827;border-bottom:1px solid #374151;flex-wrap:wrap}.bugpin-tool-group{display:flex;gap:4px}.bugpin-tool-btn{display:flex;align-items:center;justify-content:center;width:36px;height:36px;border:none;border-radius:6px;background:transparent;color:#9ca3af;cursor:pointer;transition:background .15s,color .15s}.bugpin-tool-btn:hover{background:#374151;color:#f3f4f6}.bugpin-tool-btn.active{background:var(--button-color, #6366f1);color:var(--button-text-color, white)}.bugpin-tool-btn:disabled{opacity:.4;cursor:not-allowed}.bugpin-tool-btn svg{width:20px;height:20px}.bugpin-tool-divider{width:1px;height:24px;background:#374151;margin:0 4px}.bugpin-color-picker{display:flex;gap:4px}.bugpin-color-btn{width:24px;height:24px;border:2px solid transparent;border-radius:50%;cursor:pointer;transition:transform .15s,border-color .15s}.bugpin-color-btn:hover{transform:scale(1.1)}.bugpin-color-btn.active{border-color:#fff}.bugpin-stroke-picker{display:flex;gap:4px;align-items:center}.bugpin-stroke-btn{display:flex;align-items:center;justify-content:center;width:32px;height:32px;border:1px solid #4b5563;border-radius:6px;background:#374151;cursor:pointer;transition:border-color .15s}.bugpin-stroke-btn:hover{border-color:#6b7280}.bugpin-stroke-btn.active{border-color:var(--button-color, #6366f1);background:var(--button-color, #6366f1)}.bugpin-stroke-btn span{width:16px;background:#fff;border-radius:2px}.bugpin-canvas-wrapper{flex:1;display:flex;align-items:center;justify-content:center;padding:16px;overflow:auto}.bugpin-canvas-wrapper canvas{border-radius:4px;box-shadow:0 4px 12px #0000004d}.bugpin-annotation-actions{display:flex;gap:12px;padding:12px 16px;background:#111827;border-top:1px solid #374151}.bugpin-annotation-actions .bugpin-btn-cancel,.bugpin-annotation-actions .bugpin-btn-submit{flex:1}.bugpin-annotation-modal{width:90vw;max-width:900px;height:80vh;max-height:700px;background:#1f2937;border-radius:12px;overflow:hidden;box-shadow:0 20px 40px #0006;animation:slideUp .2s ease-out}.bugpin-tabs-container{padding:1rem 1.5rem 0;background:transparent}.bugpin-tabs{display:inline-flex;padding:.25rem;background:var(--muted);border-radius:var(--radius);gap:.25rem}.bugpin-tab{display:flex;align-items:center;gap:.5rem;padding:.375rem .75rem;border:none;border-radius:calc(var(--radius) - 4px);background:transparent;color:var(--muted-foreground);font-size:.875rem;font-weight:500;font-family:inherit;cursor:pointer;transition:background .15s,color .15s,box-shadow .15s}.bugpin-tab:hover{color:var(--foreground)}.bugpin-tab.active{background:var(--background);color:var(--foreground);box-shadow:var(--shadow-sm)}.bugpin-tab-icon{display:flex;align-items:center;justify-content:center}.bugpin-tab-icon svg{width:1rem;height:1rem}.bugpin-dialog-tabbed{max-width:560px}.bugpin-theme-dark .bugpin-tabs{background:var(--muted)}.bugpin-theme-dark .bugpin-tab{color:var(--muted-foreground)}.bugpin-theme-dark .bugpin-tab:hover{color:var(--foreground)}.bugpin-theme-dark .bugpin-tab.active{background:var(--background);color:var(--foreground)}.bugpin-screenshot-manager{display:flex;flex-direction:column;gap:16px}.bugpin-media-actions{display:flex;gap:8px}.bugpin-btn-action{flex:1;display:flex;align-items:center;justify-content:center;gap:.5rem;height:2.5rem;padding:0 1rem;border:none;border-radius:calc(var(--radius) - 2px);background:var(--primary);color:var(--primary-foreground);font-size:.875rem;font-weight:500;font-family:inherit;cursor:pointer;transition:background .15s,color .15s}.bugpin-btn-action:hover{background:var(--primary-hover);color:var(--primary-hover-foreground)}.bugpin-btn-action:disabled{opacity:.5;cursor:not-allowed}.bugpin-btn-action svg{width:1.125rem;height:1.125rem}.bugpin-btn-action-secondary{background:var(--background);color:var(--foreground);border:1px solid var(--input)}.bugpin-btn-action-secondary:hover{background:var(--muted)}.bugpin-upload-error{display:flex;align-items:center;gap:8px;padding:10px 12px;background:#fef2f2;border:1px solid #fecaca;border-radius:8px;color:#dc2626;font-size:13px}.bugpin-upload-error svg{width:18px;height:18px;flex-shrink:0}.bugpin-drop-zone{min-height:160px;border:2px dashed var(--border);border-radius:var(--radius);background:var(--muted);transition:border-color .15s,background .15s}.bugpin-drop-zone.dragging{border-color:var(--primary);background:color-mix(in srgb,var(--primary) 5%,transparent)}.bugpin-drop-zone.has-media{border-style:solid;border-color:var(--border);background:var(--background);min-height:auto}.bugpin-drop-placeholder{display:flex;flex-direction:column;align-items:center;justify-content:center;padding:32px 16px;color:#6b7280;text-align:center}.bugpin-drop-placeholder svg{width:48px;height:48px;margin-bottom:12px;color:#9ca3af}.bugpin-drop-placeholder p{font-size:14px;font-weight:500;margin-bottom:4px}.bugpin-drop-placeholder span{font-size:12px;color:#9ca3af}.bugpin-drop-more{display:flex;align-items:center;justify-content:center;padding:12px;margin:8px 12px 12px;border:2px dashed #d1d5db;border-radius:6px;background:#f9fafb;transition:border-color .15s,background .15s}.bugpin-drop-more span{font-size:12px;color:#9ca3af}.bugpin-drop-zone.dragging .bugpin-drop-more{border-color:var(--button-color, #6366f1);background:#6366f10d}.bugpin-media-grid{display:grid;grid-template-columns:repeat(2,1fr);gap:12px;padding:12px}.bugpin-media-card{position:relative;border-radius:var(--radius);overflow:hidden;background:var(--background);border:1px solid var(--border)}.bugpin-media-preview{position:relative;aspect-ratio:16/9;background:#1f2937}.bugpin-media-preview img,.bugpin-media-preview video{width:100%;height:100%;object-fit:contain}.bugpin-media-badges{position:absolute;top:6px;left:6px;display:flex;gap:4px}.bugpin-badge{padding:.125rem .5rem;border-radius:calc(var(--radius) - 4px);font-size:.625rem;font-weight:500;text-transform:uppercase;letter-spacing:.025em}.bugpin-badge.annotated{background:#dbeafe;color:#1d4ed8}.bugpin-badge.video{background:#e5e7eb;color:#374151}.bugpin-media-info{display:flex;justify-content:space-between;padding:6px 8px;font-size:11px;color:#6b7280;border-top:1px solid #e5e7eb}.bugpin-media-item-actions{display:flex;gap:4px;padding:6px 8px;border-top:1px solid #e5e7eb;background:#f9fafb}.bugpin-btn-icon{display:flex;align-items:center;justify-content:center;width:28px;height:28px;border:none;border-radius:6px;background:#fff;color:#6b7280;cursor:pointer;transition:background .15s,color .15s}.bugpin-btn-icon:hover{background:#e5e7eb;color:#374151}.bugpin-btn-icon svg{width:16px;height:16px}.bugpin-btn-icon-danger:hover{background:#fef2f2;color:#dc2626}.bugpin-helper-text{font-size:12px;color:#9ca3af;text-align:center}.bugpin-theme-dark .bugpin-btn-action-secondary{background:#374151;border-color:#4b5563;color:#d1d5db}.bugpin-theme-dark .bugpin-btn-action-secondary:hover{background:#4b5563}.bugpin-theme-dark .bugpin-upload-error{background:#450a0a;border-color:#7f1d1d;color:#fca5a5}.bugpin-theme-dark .bugpin-drop-zone{border-color:#4b5563;background:#374151}.bugpin-theme-dark .bugpin-drop-zone.dragging{background:#6366f11a}.bugpin-theme-dark .bugpin-drop-zone.has-media{border-color:#4b5563;background:#1f2937}.bugpin-theme-dark .bugpin-drop-placeholder{color:#9ca3af}.bugpin-theme-dark .bugpin-drop-placeholder svg{color:#6b7280}.bugpin-theme-dark .bugpin-drop-more{border-color:#4b5563;background:#374151}.bugpin-theme-dark .bugpin-drop-more span{color:#6b7280}.bugpin-theme-dark .bugpin-media-card{background:#374151;border-color:#4b5563}.bugpin-theme-dark .bugpin-media-info{border-color:#4b5563;color:#9ca3af}.bugpin-theme-dark .bugpin-media-item-actions{border-color:#4b5563;background:#374151}.bugpin-theme-dark .bugpin-btn-icon{background:#4b5563;color:#9ca3af}.bugpin-theme-dark .bugpin-btn-icon:hover{background:#6b7280;color:#f3f4f6}.bugpin-theme-dark .bugpin-btn-icon-danger:hover{background:#450a0a;color:#fca5a5}.bugpin-theme-dark .bugpin-badge.annotated{background:#1e3a8a;color:#93c5fd}.bugpin-theme-dark .bugpin-badge.video{background:#4b5563;color:#d1d5db}@keyframes bugpin-tooltip-fade-in{0%{opacity:0}to{opacity:1}}';async function Ya(){var o,a,l;const n=document.querySelectorAll('script[src*="widget.js"]'),t=n[n.length-1];if(!t){console.error("[BugPin] Could not find widget script tag");return}const e=t.getAttribute("data-api-key");if(!e){console.error("[BugPin] Missing data-api-key attribute");return}const r=t.getAttribute("data-server-url")||Xs.serverUrl;let i={};try{const c=await fetch(`${r}/api/widget/config/${e}`);if(c.ok){const h=await c.json();h.success&&h.config&&(i={buttonText:h.config.buttonText,buttonShape:h.config.buttonShape,buttonIcon:h.config.buttonIcon,buttonIconSize:h.config.buttonIconSize,buttonIconStroke:h.config.buttonIconStroke,position:h.config.position,theme:h.config.theme,lightButtonColor:h.config.lightButtonColor,lightTextColor:h.config.lightTextColor,lightButtonHoverColor:h.config.lightButtonHoverColor,lightTextHoverColor:h.config.lightTextHoverColor,darkButtonColor:h.config.darkButtonColor,darkTextColor:h.config.darkTextColor,darkButtonHoverColor:h.config.darkButtonHoverColor,darkTextHoverColor:h.config.darkTextHoverColor,dialogLightButtonColor:h.config.dialogLightButtonColor,dialogLightTextColor:h.config.dialogLightTextColor,dialogLightButtonHoverColor:h.config.dialogLightButtonHoverColor,dialogLightTextHoverColor:h.config.dialogLightTextHoverColor,dialogDarkButtonColor:h.config.dialogDarkButtonColor,dialogDarkTextColor:h.config.dialogDarkTextColor,dialogDarkButtonHoverColor:h.config.dialogDarkButtonHoverColor,dialogDarkTextHoverColor:h.config.dialogDarkTextHoverColor,enableHoverScaleEffect:h.config.enableHoverScaleEffect??!0,tooltipEnabled:h.config.tooltipEnabled??!1,tooltipText:h.config.tooltipText??null,enableScreenshot:((o=h.config.features)==null?void 0:o.screenshot)??!0,enableAnnotation:((a=h.config.features)==null?void 0:a.annotation)??!0,enableConsoleCapture:((l=h.config.features)==null?void 0:l.consoleCapture)??!0,captureMethod:h.config.captureMethod||"visible",useScreenCaptureAPI:h.config.useScreenCaptureAPI??!1})}}catch(c){console.warn("[BugPin] Failed to fetch widget config, using defaults",c)}const s={...Xs,...i,apiKey:e,serverUrl:r,...t.getAttribute("data-position")&&{position:t.getAttribute("data-position")},...t.getAttribute("data-button-text")&&{buttonText:t.getAttribute("data-button-text")},...t.getAttribute("data-theme")&&{theme:t.getAttribute("data-theme")}};Ys(s)}function Ys(n){const t=document.createElement("div");t.id="bugpin-widget";const e=t.attachShadow({mode:"open"}),r=document.createElement("style");r.textContent=Kd,e.appendChild(r);const i=document.createElement("div");i.id="bugpin-root",e.appendChild(i),document.body.appendChild(t),Ka(Ke(qd,{config:n}),i)}const Us={init:n=>{const t={...Xs,...n};Ys(t)},open:()=>{document.dispatchEvent(new CustomEvent("bugpin:open"))},close:()=>{document.dispatchEvent(new CustomEvent("bugpin:close"))}};return typeof window<"u"&&(window.BugPin=Us),typeof{url:Ei&&Ei.tagName.toUpperCase()==="SCRIPT"&&Ei.src||new URL("widget.js",document.baseURI).href}<"u"||(document.readyState==="loading"?document.addEventListener("DOMContentLoaded",Ya):Ya()),Ne.BugPin=Us,Ne.createWidget=Ys,Ne.default=Us,Object.defineProperties(Ne,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}}),Ne}({});
|
|
586
|
+
//# sourceMappingURL=widget.js.map
|