fabric-texture
Version:
This JavaScript library enables fast and efficient image distortion transformations using Canvas 2D.
3 lines • 71.5 kB
JavaScript
import{fabric as e}from"fabric";function r(t,e,r,n){return new(r||(r=Promise))((function(i,o){function s(t){try{c(n.next(t))}catch(t){o(t)}}function a(t){try{c(n.throw(t))}catch(t){o(t)}}function c(t){var e;t.done?i(t.value):(e=t.value,e instanceof r?e:new r((function(t){t(e)}))).then(s,a)}c((n=n.apply(t,e||[])).next())}))}"function"==typeof SuppressedError&&SuppressedError;const{abs:n,cos:i,sin:o,acos:s,atan2:a,sqrt:c,pow:h}=Math;function u(t){return t<0?-h(-t,1/3):h(t,1/3)}const l=Math.PI,p=2*l,f=l/2,d=Number.MAX_SAFE_INTEGER||9007199254740991,y=Number.MIN_SAFE_INTEGER||-9007199254740991,x={x:0,y:0,z:0},g={Tvalues:[-.06405689286260563,.06405689286260563,-.1911188674736163,.1911188674736163,-.3150426796961634,.3150426796961634,-.4337935076260451,.4337935076260451,-.5454214713888396,.5454214713888396,-.6480936519369755,.6480936519369755,-.7401241915785544,.7401241915785544,-.820001985973903,.820001985973903,-.8864155270044011,.8864155270044011,-.9382745520027328,.9382745520027328,-.9747285559713095,.9747285559713095,-.9951872199970213,.9951872199970213],Cvalues:[.12793819534675216,.12793819534675216,.1258374563468283,.1258374563468283,.12167047292780339,.12167047292780339,.1155056680537256,.1155056680537256,.10744427011596563,.10744427011596563,.09761865210411388,.09761865210411388,.08619016153195327,.08619016153195327,.0733464814110803,.0733464814110803,.05929858491543678,.05929858491543678,.04427743881741981,.04427743881741981,.028531388628933663,.028531388628933663,.0123412297999872,.0123412297999872],arcfn:function(t,e){const r=e(t);let n=r.x*r.x+r.y*r.y;return void 0!==r.z&&(n+=r.z*r.z),c(n)},compute:function(t,e,r){if(0===t)return e[0].t=0,e[0];const n=e.length-1;if(1===t)return e[n].t=1,e[n];const i=1-t;let o=e;if(0===n)return e[0].t=t,e[0];if(1===n){const e={x:i*o[0].x+t*o[1].x,y:i*o[0].y+t*o[1].y,t:t};return r&&(e.z=i*o[0].z+t*o[1].z),e}if(n<4){let e,s,a,c=i*i,h=t*t,u=0;2===n?(o=[o[0],o[1],o[2],x],e=c,s=i*t*2,a=h):3===n&&(e=c*i,s=c*t*3,a=i*h*3,u=t*h);const l={x:e*o[0].x+s*o[1].x+a*o[2].x+u*o[3].x,y:e*o[0].y+s*o[1].y+a*o[2].y+u*o[3].y,t:t};return r&&(l.z=e*o[0].z+s*o[1].z+a*o[2].z+u*o[3].z),l}const s=JSON.parse(JSON.stringify(e));for(;s.length>1;){for(let e=0;e<s.length-1;e++)s[e]={x:s[e].x+(s[e+1].x-s[e].x)*t,y:s[e].y+(s[e+1].y-s[e].y)*t},void 0!==s[e].z&&(s[e].z=s[e].z+(s[e+1].z-s[e].z)*t);s.splice(s.length-1,1)}return s[0].t=t,s[0]},computeWithRatios:function(t,e,r,n){const i=1-t,o=r,s=e;let a,c=o[0],h=o[1],u=o[2],l=o[3];return c*=i,h*=t,2===s.length?(a=c+h,{x:(c*s[0].x+h*s[1].x)/a,y:(c*s[0].y+h*s[1].y)/a,z:!!n&&(c*s[0].z+h*s[1].z)/a,t:t}):(c*=i,h*=2*i,u*=t*t,3===s.length?(a=c+h+u,{x:(c*s[0].x+h*s[1].x+u*s[2].x)/a,y:(c*s[0].y+h*s[1].y+u*s[2].y)/a,z:!!n&&(c*s[0].z+h*s[1].z+u*s[2].z)/a,t:t}):(c*=i,h*=1.5*i,u*=3*i,l*=t*t*t,4===s.length?(a=c+h+u+l,{x:(c*s[0].x+h*s[1].x+u*s[2].x+l*s[3].x)/a,y:(c*s[0].y+h*s[1].y+u*s[2].y+l*s[3].y)/a,z:!!n&&(c*s[0].z+h*s[1].z+u*s[2].z+l*s[3].z)/a,t:t}):void 0))},derive:function(t,e){const r=[];for(let n=t,i=n.length,o=i-1;i>1;i--,o--){const t=[];for(let r,i=0;i<o;i++)r={x:o*(n[i+1].x-n[i].x),y:o*(n[i+1].y-n[i].y)},e&&(r.z=o*(n[i+1].z-n[i].z)),t.push(r);r.push(t),n=t}return r},between:function(t,e,r){return e<=t&&t<=r||g.approximately(t,e)||g.approximately(t,r)},approximately:function(t,e,r){return n(t-e)<=(r||1e-6)},length:function(t){const e=g.Tvalues.length;let r=0;for(let n,i=0;i<e;i++)n=.5*g.Tvalues[i]+.5,r+=g.Cvalues[i]*g.arcfn(n,t);return.5*r},map:function(t,e,r,n,i){return n+(i-n)*((t-e)/(r-e))},lerp:function(t,e,r){const n={x:e.x+t*(r.x-e.x),y:e.y+t*(r.y-e.y)};return void 0!==e.z&&void 0!==r.z&&(n.z=e.z+t*(r.z-e.z)),n},pointToString:function(t){let e=t.x+"/"+t.y;return void 0!==t.z&&(e+="/"+t.z),e},pointsToString:function(t){return"["+t.map(g.pointToString).join(", ")+"]"},copy:function(t){return JSON.parse(JSON.stringify(t))},angle:function(t,e,r){const n=e.x-t.x,i=e.y-t.y,o=r.x-t.x,s=r.y-t.y;return a(n*s-i*o,n*o+i*s)},round:function(t,e){const r=""+t,n=r.indexOf(".");return parseFloat(r.substring(0,n+1+e))},dist:function(t,e){const r=t.x-e.x,n=t.y-e.y;return c(r*r+n*n)},closest:function(t,e){let r,n,i=h(2,63);return t.forEach((function(t,o){n=g.dist(e,t),n<i&&(i=n,r=o)})),{mdist:i,mpos:r}},abcratio:function(t,e){if(2!==e&&3!==e)return!1;if(void 0===t)t=.5;else if(0===t||1===t)return t;const r=h(t,e)+h(1-t,e);return n((r-1)/r)},projectionratio:function(t,e){if(2!==e&&3!==e)return!1;if(void 0===t)t=.5;else if(0===t||1===t)return t;const r=h(1-t,e);return r/(h(t,e)+r)},lli8:function(t,e,r,n,i,o,s,a){const c=(t-r)*(o-a)-(e-n)*(i-s);return 0!=c&&{x:((t*n-e*r)*(i-s)-(t-r)*(i*a-o*s))/c,y:((t*n-e*r)*(o-a)-(e-n)*(i*a-o*s))/c}},lli4:function(t,e,r,n){const i=t.x,o=t.y,s=e.x,a=e.y,c=r.x,h=r.y,u=n.x,l=n.y;return g.lli8(i,o,s,a,c,h,u,l)},lli:function(t,e){return g.lli4(t,t.c,e,e.c)},makeline:function(t,e){return new O(t.x,t.y,(t.x+e.x)/2,(t.y+e.y)/2,e.x,e.y)},findbbox:function(t){let e=d,r=d,n=y,i=y;return t.forEach((function(t){const o=t.bbox();e>o.x.min&&(e=o.x.min),r>o.y.min&&(r=o.y.min),n<o.x.max&&(n=o.x.max),i<o.y.max&&(i=o.y.max)})),{x:{min:e,mid:(e+n)/2,max:n,size:n-e},y:{min:r,mid:(r+i)/2,max:i,size:i-r}}},shapeintersections:function(t,e,r,n,i){if(!g.bboxoverlap(e,n))return[];const o=[],s=[t.startcap,t.forward,t.back,t.endcap],a=[r.startcap,r.forward,r.back,r.endcap];return s.forEach((function(e){e.virtual||a.forEach((function(n){if(n.virtual)return;const s=e.intersects(n,i);s.length>0&&(s.c1=e,s.c2=n,s.s1=t,s.s2=r,o.push(s))}))})),o},makeshape:function(t,e,r){const n=e.points.length,i=t.points.length,o=g.makeline(e.points[n-1],t.points[0]),s=g.makeline(t.points[i-1],e.points[0]),a={startcap:o,forward:t,back:e,endcap:s,bbox:g.findbbox([o,t,e,s]),intersections:function(t){return g.shapeintersections(a,a.bbox,t,t.bbox,r)}};return a},getminmax:function(t,e,r){if(!r)return{min:0,max:0};let n,i,o=d,s=y;-1===r.indexOf(0)&&(r=[0].concat(r)),-1===r.indexOf(1)&&r.push(1);for(let a=0,c=r.length;a<c;a++)n=r[a],i=t.get(n),i[e]<o&&(o=i[e]),i[e]>s&&(s=i[e]);return{min:o,mid:(o+s)/2,max:s,size:s-o}},align:function(t,e){const r=e.p1.x,n=e.p1.y,s=-a(e.p2.y-n,e.p2.x-r);return t.map((function(t){return{x:(t.x-r)*i(s)-(t.y-n)*o(s),y:(t.x-r)*o(s)+(t.y-n)*i(s)}}))},roots:function(t,e){e=e||{p1:{x:0,y:0},p2:{x:1,y:0}};const r=t.length-1,n=g.align(t,e),o=function(t){return 0<=t&&t<=1};if(2===r){const t=n[0].y,e=n[1].y,r=n[2].y,i=t-2*e+r;if(0!==i){const n=-c(e*e-t*r),s=-t+e;return[-(n+s)/i,-(-n+s)/i].filter(o)}return e!==r&&0===i?[(2*e-r)/(2*e-2*r)].filter(o):[]}const a=n[0].y,h=n[1].y,l=n[2].y;let f=3*h-a-3*l+n[3].y,d=3*a-6*h+3*l,y=-3*a+3*h,x=a;if(g.approximately(f,0)){if(g.approximately(d,0))return g.approximately(y,0)?[]:[-x/y].filter(o);const t=c(y*y-4*d*x),e=2*d;return[(t-y)/e,(-y-t)/e].filter(o)}d/=f,y/=f,x/=f;const m=(3*y-d*d)/3,v=m/3,b=(2*d*d*d-9*d*y+27*x)/27,_=b/2,w=_*_+v*v*v;let T,E,z,S,O;if(w<0){const t=-m/3,e=c(t*t*t),r=-b/(2*e),n=s(r<-1?-1:r>1?1:r),a=2*u(e);return z=a*i(n/3)-d/3,S=a*i((n+p)/3)-d/3,O=a*i((n+2*p)/3)-d/3,[z,S,O].filter(o)}if(0===w)return T=_<0?u(-_):-u(_),z=2*T-d/3,S=-T-d/3,[z,S].filter(o);{const t=c(w);return T=u(-_+t),E=u(_+t),[T-E-d/3].filter(o)}},droots:function(t){if(3===t.length){const e=t[0],r=t[1],n=t[2],i=e-2*r+n;if(0!==i){const t=-c(r*r-e*n),o=-e+r;return[-(t+o)/i,-(-t+o)/i]}return r!==n&&0===i?[(2*r-n)/(2*(r-n))]:[]}if(2===t.length){const e=t[0],r=t[1];return e!==r?[e/(e-r)]:[]}return[]},curvature:function(t,e,r,i,o){let s,a,u,l,p=0,f=0;const d=g.compute(t,e),y=g.compute(t,r),x=d.x*d.x+d.y*d.y;if(i?(s=c(h(d.y*y.z-y.y*d.z,2)+h(d.z*y.x-y.z*d.x,2)+h(d.x*y.y-y.x*d.y,2)),a=h(x+d.z*d.z,1.5)):(s=d.x*y.y-d.y*y.x,a=h(x,1.5)),0===s||0===a)return{k:0,r:0};if(p=s/a,f=a/s,!o){const o=g.curvature(t-.001,e,r,i,!0).k,s=g.curvature(t+.001,e,r,i,!0).k;l=(s-p+(p-o))/2,u=(n(s-p)+n(p-o))/2}return{k:p,r:f,dk:l,adk:u}},inflections:function(t){if(t.length<4)return[];const e=g.align(t,{p1:t[0],p2:t.slice(-1)[0]}),r=e[2].x*e[1].y,n=e[3].x*e[1].y,i=e[1].x*e[2].y,o=18*(-3*r+2*n+3*i-e[3].x*e[2].y),s=18*(3*r-n-3*i),a=18*(i-r);if(g.approximately(o,0)){if(!g.approximately(s,0)){let t=-a/s;if(0<=t&&t<=1)return[t]}return[]}const c=2*o;if(g.approximately(c,0))return[];const h=s*s-4*o*a;if(h<0)return[];const u=Math.sqrt(h);return[(u-s)/c,-(s+u)/c].filter((function(t){return 0<=t&&t<=1}))},bboxoverlap:function(t,e){const r=["x","y"],i=r.length;for(let o,s,a,c,h=0;h<i;h++)if(o=r[h],s=t[o].mid,a=e[o].mid,c=(t[o].size+e[o].size)/2,n(s-a)>=c)return!1;return!0},expandbox:function(t,e){e.x.min<t.x.min&&(t.x.min=e.x.min),e.y.min<t.y.min&&(t.y.min=e.y.min),e.z&&e.z.min<t.z.min&&(t.z.min=e.z.min),e.x.max>t.x.max&&(t.x.max=e.x.max),e.y.max>t.y.max&&(t.y.max=e.y.max),e.z&&e.z.max>t.z.max&&(t.z.max=e.z.max),t.x.mid=(t.x.min+t.x.max)/2,t.y.mid=(t.y.min+t.y.max)/2,t.z&&(t.z.mid=(t.z.min+t.z.max)/2),t.x.size=t.x.max-t.x.min,t.y.size=t.y.max-t.y.min,t.z&&(t.z.size=t.z.max-t.z.min)},pairiteration:function(t,e,r){const n=t.bbox(),i=e.bbox(),o=1e5,s=r||.5;if(n.x.size+n.y.size<s&&i.x.size+i.y.size<s)return[(o*(t._t1+t._t2)/2|0)/o+"/"+(o*(e._t1+e._t2)/2|0)/o];let a=t.split(.5),c=e.split(.5),h=[{left:a.left,right:c.left},{left:a.left,right:c.right},{left:a.right,right:c.right},{left:a.right,right:c.left}];h=h.filter((function(t){return g.bboxoverlap(t.left.bbox(),t.right.bbox())}));let u=[];return 0===h.length||(h.forEach((function(t){u=u.concat(g.pairiteration(t.left,t.right,s))})),u=u.filter((function(t,e){return u.indexOf(t)===e}))),u},getccenter:function(t,e,r){const n=e.x-t.x,s=e.y-t.y,c=r.x-e.x,h=r.y-e.y,u=n*i(f)-s*o(f),l=n*o(f)+s*i(f),d=c*i(f)-h*o(f),y=c*o(f)+h*i(f),x=(t.x+e.x)/2,m=(t.y+e.y)/2,v=(e.x+r.x)/2,b=(e.y+r.y)/2,_=x+u,w=m+l,T=v+d,E=b+y,z=g.lli8(x,m,_,w,v,b,T,E),S=g.dist(z,t);let O,C=a(t.y-z.y,t.x-z.x),A=a(e.y-z.y,e.x-z.x),P=a(r.y-z.y,r.x-z.x);return C<P?((C>A||A>P)&&(C+=p),C>P&&(O=P,P=C,C=O)):P<A&&A<C?(O=P,P=C,C=O):P+=p,z.s=C,z.e=P,z.r=S,z},numberSort:function(t,e){return t-e}};class m{constructor(t){this.curves=[],this._3d=!1,t&&(this.curves=t,this._3d=this.curves[0]._3d)}valueOf(){return this.toString()}toString(){return"["+this.curves.map((function(t){return g.pointsToString(t.points)})).join(", ")+"]"}addCurve(t){this.curves.push(t),this._3d=this._3d||t._3d}length(){return this.curves.map((function(t){return t.length()})).reduce((function(t,e){return t+e}))}curve(t){return this.curves[t]}bbox(){const t=this.curves;for(var e=t[0].bbox(),r=1;r<t.length;r++)g.expandbox(e,t[r].bbox());return e}offset(t){const e=[];return this.curves.forEach((function(r){e.push(...r.offset(t))})),new m(e)}}const{abs:v,min:b,max:_,cos:w,sin:T,acos:E,sqrt:z}=Math,S=Math.PI;class O{constructor(t){let e=t&&t.forEach?t:Array.from(arguments).slice(),r=!1;if("object"==typeof e[0]){r=e.length;const t=[];e.forEach((function(e){["x","y","z"].forEach((function(r){void 0!==e[r]&&t.push(e[r])}))})),e=t}let n=!1;const i=e.length;if(r){if(r>4){if(1!==arguments.length)throw new Error("Only new Bezier(point[]) is accepted for 4th and higher order curves");n=!0}}else if(6!==i&&8!==i&&9!==i&&12!==i&&1!==arguments.length)throw new Error("Only new Bezier(point[]) is accepted for 4th and higher order curves");const o=this._3d=!n&&(9===i||12===i)||t&&t[0]&&void 0!==t[0].z,s=this.points=[];for(let t=0,r=o?3:2;t<i;t+=r){var a={x:e[t],y:e[t+1]};o&&(a.z=e[t+2]),s.push(a)}const c=this.order=s.length-1,h=this.dims=["x","y"];o&&h.push("z"),this.dimlen=h.length;const u=g.align(s,{p1:s[0],p2:s[c]}),l=g.dist(s[0],s[c]);this._linear=u.reduce(((t,e)=>t+v(e.y)),0)<l/50,this._lut=[],this._t1=0,this._t2=1,this.update()}static quadraticFromPoints(t,e,r,n){if(void 0===n&&(n=.5),0===n)return new O(e,e,r);if(1===n)return new O(t,e,e);const i=O.getABC(2,t,e,r,n);return new O(t,i.A,r)}static cubicFromPoints(t,e,r,n,i){void 0===n&&(n=.5);const o=O.getABC(3,t,e,r,n);void 0===i&&(i=g.dist(e,o.C));const s=i*(1-n)/n,a=g.dist(t,r),c=(r.x-t.x)/a,h=(r.y-t.y)/a,u=i*c,l=i*h,p=s*c,f=s*h,d=e.x-u,y=e.y-l,x=e.x+p,m=e.y+f,v=o.A,b=v.x+(d-v.x)/(1-n),_=v.y+(y-v.y)/(1-n),w=v.x+(x-v.x)/n,T=v.y+(m-v.y)/n,E={x:t.x+(b-t.x)/n,y:t.y+(_-t.y)/n},z={x:r.x+(w-r.x)/(1-n),y:r.y+(T-r.y)/(1-n)};return new O(t,E,z,r)}static getUtils(){return g}getUtils(){return O.getUtils()}static get PolyBezier(){return m}valueOf(){return this.toString()}toString(){return g.pointsToString(this.points)}toSVG(){if(this._3d)return!1;const t=this.points,e=["M",t[0].x,t[0].y,2===this.order?"Q":"C"];for(let r=1,n=t.length;r<n;r++)e.push(t[r].x),e.push(t[r].y);return e.join(" ")}setRatios(t){if(t.length!==this.points.length)throw new Error("incorrect number of ratio values");this.ratios=t,this._lut=[]}verify(){const t=this.coordDigest();t!==this._print&&(this._print=t,this.update())}coordDigest(){return this.points.map((function(t,e){return""+e+t.x+t.y+(t.z?t.z:0)})).join("")}update(){this._lut=[],this.dpoints=g.derive(this.points,this._3d),this.computedirection()}computedirection(){const t=this.points,e=g.angle(t[0],t[this.order],t[1]);this.clockwise=e>0}length(){return g.length(this.derivative.bind(this))}static getABC(t=2,e,r,n,i=.5){const o=g.projectionratio(i,t),s=1-o,a={x:o*e.x+s*n.x,y:o*e.y+s*n.y},c=g.abcratio(i,t);return{A:{x:r.x+(r.x-a.x)/c,y:r.y+(r.y-a.y)/c},B:r,C:a,S:e,E:n}}getABC(t,e){e=e||this.get(t);let r=this.points[0],n=this.points[this.order];return O.getABC(this.order,r,e,n,t)}getLUT(t){if(this.verify(),t=t||100,this._lut.length===t+1)return this._lut;this._lut=[],t++,this._lut=[];for(let e,r,n=0;n<t;n++)r=n/(t-1),e=this.compute(r),e.t=r,this._lut.push(e);return this._lut}on(e,r){r=r||5;const n=this.getLUT(),i=[];for(let t,o=0,s=0;o<n.length;o++)t=n[o],g.dist(t,e)<r&&(i.push(t),s+=o/n.length);return!!i.length&&(t/=i.length)}project(t){const e=this.getLUT(),r=e.length-1,n=g.closest(e,t),i=n.mpos,o=(i-1)/r,s=(i+1)/r,a=.1/r;let c,h=n.mdist,u=o,l=u;h+=1;for(let e;u<s+a;u+=a)c=this.compute(u),e=g.dist(t,c),e<h&&(h=e,l=u);return l=l<0?0:l>1?1:l,c=this.compute(l),c.t=l,c.d=h,c}get(t){return this.compute(t)}point(t){return this.points[t]}compute(t){return this.ratios?g.computeWithRatios(t,this.points,this.ratios,this._3d):g.compute(t,this.points,this._3d,this.ratios)}raise(){const t=this.points,e=[t[0]],r=t.length;for(let n,i,o=1;o<r;o++)n=t[o],i=t[o-1],e[o]={x:(r-o)/r*n.x+o/r*i.x,y:(r-o)/r*n.y+o/r*i.y};return e[r]=t[r-1],new O(e)}derivative(t){return g.compute(t,this.dpoints[0],this._3d)}dderivative(t){return g.compute(t,this.dpoints[1],this._3d)}align(){let t=this.points;return new O(g.align(t,{p1:t[0],p2:t[t.length-1]}))}curvature(t){return g.curvature(t,this.dpoints[0],this.dpoints[1],this._3d)}inflections(){return g.inflections(this.points)}normal(t){return this._3d?this.__normal3(t):this.__normal2(t)}__normal2(t){const e=this.derivative(t),r=z(e.x*e.x+e.y*e.y);return{t:t,x:-e.y/r,y:e.x/r}}__normal3(t){const e=this.derivative(t),r=this.derivative(t+.01),n=z(e.x*e.x+e.y*e.y+e.z*e.z),i=z(r.x*r.x+r.y*r.y+r.z*r.z);e.x/=n,e.y/=n,e.z/=n,r.x/=i,r.y/=i,r.z/=i;const o={x:r.y*e.z-r.z*e.y,y:r.z*e.x-r.x*e.z,z:r.x*e.y-r.y*e.x},s=z(o.x*o.x+o.y*o.y+o.z*o.z);o.x/=s,o.y/=s,o.z/=s;const a=[o.x*o.x,o.x*o.y-o.z,o.x*o.z+o.y,o.x*o.y+o.z,o.y*o.y,o.y*o.z-o.x,o.x*o.z-o.y,o.y*o.z+o.x,o.z*o.z];return{t:t,x:a[0]*e.x+a[1]*e.y+a[2]*e.z,y:a[3]*e.x+a[4]*e.y+a[5]*e.z,z:a[6]*e.x+a[7]*e.y+a[8]*e.z}}hull(t){let e=this.points,r=[],n=[],i=0;for(n[i++]=e[0],n[i++]=e[1],n[i++]=e[2],3===this.order&&(n[i++]=e[3]);e.length>1;){r=[];for(let o,s=0,a=e.length-1;s<a;s++)o=g.lerp(t,e[s],e[s+1]),n[i++]=o,r.push(o);e=r}return n}split(t,e){if(0===t&&e)return this.split(e).left;if(1===e)return this.split(t).right;const r=this.hull(t),n={left:2===this.order?new O([r[0],r[3],r[5]]):new O([r[0],r[4],r[7],r[9]]),right:2===this.order?new O([r[5],r[4],r[2]]):new O([r[9],r[8],r[6],r[3]]),span:r};return n.left._t1=g.map(0,0,1,this._t1,this._t2),n.left._t2=g.map(t,0,1,this._t1,this._t2),n.right._t1=g.map(t,0,1,this._t1,this._t2),n.right._t2=g.map(1,0,1,this._t1,this._t2),e?(e=g.map(e,t,1,0,1),n.right.split(e).left):n}extrema(){const t={};let e=[];return this.dims.forEach(function(r){let n=function(t){return t[r]},i=this.dpoints[0].map(n);t[r]=g.droots(i),3===this.order&&(i=this.dpoints[1].map(n),t[r]=t[r].concat(g.droots(i))),t[r]=t[r].filter((function(t){return t>=0&&t<=1})),e=e.concat(t[r].sort(g.numberSort))}.bind(this)),t.values=e.sort(g.numberSort).filter((function(t,r){return e.indexOf(t)===r})),t}bbox(){const t=this.extrema(),e={};return this.dims.forEach(function(r){e[r]=g.getminmax(this,r,t[r])}.bind(this)),e}overlaps(t){const e=this.bbox(),r=t.bbox();return g.bboxoverlap(e,r)}offset(t,e){if(void 0!==e){const r=this.get(t),n=this.normal(t),i={c:r,n:n,x:r.x+n.x*e,y:r.y+n.y*e};return this._3d&&(i.z=r.z+n.z*e),i}if(this._linear){const e=this.normal(0),r=this.points.map((function(r){const n={x:r.x+t*e.x,y:r.y+t*e.y};return r.z&&e.z&&(n.z=r.z+t*e.z),n}));return[new O(r)]}return this.reduce().map((function(e){return e._linear?e.offset(t)[0]:e.scale(t)}))}simple(){if(3===this.order){const t=g.angle(this.points[0],this.points[3],this.points[1]),e=g.angle(this.points[0],this.points[3],this.points[2]);if(t>0&&e<0||t<0&&e>0)return!1}const t=this.normal(0),e=this.normal(1);let r=t.x*e.x+t.y*e.y;return this._3d&&(r+=t.z*e.z),v(E(r))<S/3}reduce(){let t,e,r=0,n=0,i=.01,o=[],s=[],a=this.extrema().values;for(-1===a.indexOf(0)&&(a=[0].concat(a)),-1===a.indexOf(1)&&a.push(1),r=a[0],t=1;t<a.length;t++)n=a[t],e=this.split(r,n),e._t1=r,e._t2=n,o.push(e),r=n;return o.forEach((function(t){for(r=0,n=0;n<=1;)for(n=r+i;n<=1.01;n+=i)if(e=t.split(r,n),!e.simple()){if(n-=i,v(r-n)<i)return[];e=t.split(r,n),e._t1=g.map(r,0,1,t._t1,t._t2),e._t2=g.map(n,0,1,t._t1,t._t2),s.push(e),r=n;break}r<1&&(e=t.split(r,1),e._t1=g.map(r,0,1,t._t1,t._t2),e._t2=t._t2,s.push(e))})),s}translate(t,e,r){r="number"==typeof r?r:e;const n=this.order;let i=this.points.map(((t,i)=>(1-i/n)*e+i/n*r));return new O(this.points.map(((e,r)=>({x:e.x+t.x*i[r],y:e.y+t.y*i[r]}))))}scale(t){const e=this.order;let r=!1;if("function"==typeof t&&(r=t),r&&2===e)return this.raise().scale(r);const n=this.clockwise,i=this.points;if(this._linear)return this.translate(this.normal(0),r?r(0):t,r?r(1):t);const o=r?r(0):t,s=r?r(1):t,a=[this.offset(0,10),this.offset(1,10)],c=[],h=g.lli4(a[0],a[0].c,a[1],a[1].c);if(!h)throw new Error("cannot scale this curve. Try reducing it first.");return[0,1].forEach((function(t){const r=c[t*e]=g.copy(i[t*e]);r.x+=(t?s:o)*a[t].n.x,r.y+=(t?s:o)*a[t].n.y})),r?([0,1].forEach((function(o){if(2!==e||!o){var s=i[o+1],a={x:s.x-h.x,y:s.y-h.y},u=r?r((o+1)/e):t;r&&!n&&(u=-u);var l=z(a.x*a.x+a.y*a.y);a.x/=l,a.y/=l,c[o+1]={x:s.x+u*a.x,y:s.y+u*a.y}}})),new O(c)):([0,1].forEach((t=>{if(2===e&&t)return;const r=c[t*e],n=this.derivative(t),o={x:r.x+n.x,y:r.y+n.y};c[t+1]=g.lli4(r,o,h,i[t+1])})),new O(c))}outline(t,e,r,n){if(e=void 0===e?t:e,this._linear){const i=this.normal(0),o=this.points[0],s=this.points[this.points.length-1];let a,c,h;void 0===r&&(r=t,n=e),a={x:o.x+i.x*t,y:o.y+i.y*t},h={x:s.x+i.x*r,y:s.y+i.y*r},c={x:(a.x+h.x)/2,y:(a.y+h.y)/2};const u=[a,c,h];a={x:o.x-i.x*e,y:o.y-i.y*e},h={x:s.x-i.x*n,y:s.y-i.y*n},c={x:(a.x+h.x)/2,y:(a.y+h.y)/2};const l=[h,c,a],p=g.makeline(l[2],u[0]),f=g.makeline(u[2],l[0]),d=[p,new O(u),f,new O(l)];return new m(d)}const i=this.reduce(),o=i.length,s=[];let a,c=[],h=0,u=this.length();const l=void 0!==r&&void 0!==n;function p(t,e,r,n,i){return function(o){const s=n/r,a=(n+i)/r,c=e-t;return g.map(o,0,1,t+s*c,t+a*c)}}i.forEach((function(i){const o=i.length();l?(s.push(i.scale(p(t,r,u,h,o))),c.push(i.scale(p(-e,-n,u,h,o)))):(s.push(i.scale(t)),c.push(i.scale(-e))),h+=o})),c=c.map((function(t){return a=t.points,a[3]?t.points=[a[3],a[2],a[1],a[0]]:t.points=[a[2],a[1],a[0]],t})).reverse();const f=s[0].points[0],d=s[o-1].points[s[o-1].points.length-1],y=c[o-1].points[c[o-1].points.length-1],x=c[0].points[0],v=g.makeline(y,f),b=g.makeline(d,x),_=[v].concat(s).concat([b]).concat(c);return new m(_)}outlineshapes(t,e,r){e=e||t;const n=this.outline(t,e).curves,i=[];for(let t=1,e=n.length;t<e/2;t++){const o=g.makeshape(n[t],n[e-t],r);o.startcap.virtual=t>1,o.endcap.virtual=t<e/2-1,i.push(o)}return i}intersects(t,e){return t?t.p1&&t.p2?this.lineIntersects(t):(t instanceof O&&(t=t.reduce()),this.curveintersects(this.reduce(),t,e)):this.selfintersects(e)}lineIntersects(t){const e=b(t.p1.x,t.p2.x),r=b(t.p1.y,t.p2.y),n=_(t.p1.x,t.p2.x),i=_(t.p1.y,t.p2.y);return g.roots(this.points,t).filter((t=>{var o=this.get(t);return g.between(o.x,e,n)&&g.between(o.y,r,i)}))}selfintersects(t){const e=this.reduce(),r=e.length-2,n=[];for(let i,o,s,a=0;a<r;a++)o=e.slice(a,a+1),s=e.slice(a+2),i=this.curveintersects(o,s,t),n.push(...i);return n}curveintersects(t,e,r){const n=[];t.forEach((function(t){e.forEach((function(e){t.overlaps(e)&&n.push({left:t,right:e})}))}));let i=[];return n.forEach((function(t){const e=g.pairiteration(t.left,t.right,r);e.length>0&&(i=i.concat(e))})),i}arcs(t){return t=t||.5,this._iterate(t,[])}_error(t,e,r,n){const i=(n-r)/4,o=this.get(r+i),s=this.get(n-i),a=g.dist(t,e),c=g.dist(t,o),h=g.dist(t,s);return v(c-a)+v(h-a)}_iterate(t,e){let r,n=0,i=1;do{r=0,i=1;let o,s,a,c,h,u=this.get(n),l=!1,p=!1,f=i,d=1;do{if(p=l,c=a,f=(n+i)/2,o=this.get(f),s=this.get(i),a=g.getccenter(u,o,s),a.interval={start:n,end:i},l=this._error(a,u,n,i)<=t,h=p&&!l,h||(d=i),l){if(i>=1){if(a.interval.end=d=1,c=a,i>1){let t={x:a.x+a.r*w(a.e),y:a.y+a.r*T(a.e)};a.e+=g.angle({x:a.x,y:a.y},t,this.get(1))}break}i+=(i-n)/2}else i=f}while(!h&&r++<100);if(r>=100)break;c=c||a,e.push(c),n=d}while(i<1);return e}}const C=(t,e,r)=>{if(t.x===e.x)return{x:t.x,y:r.y};if(t.y===e.y)return{x:r.x,y:t.y};const n=(e.y-t.y)/(e.x-t.x),i=-1/n,o=(-n*t.x+t.y+i*r.x-r.y)/(i-n);return{x:o,y:n*(o-t.x)+t.y}},A=(t,e)=>Math.sqrt(Math.pow(e.x-t.x,2)+Math.pow(e.y-t.y,2)),P=(t,e,r)=>{const n=Math.min(t.x,e.x,r.x),i=Math.max(t.x,e.x,r.x),o=Math.min(t.y,e.y,r.y);return{width:i-n,height:Math.max(t.y,e.y,r.y)-o}},j=(t,e,r)=>{const n=Object.assign({},t),i={x:e.x-t.x,y:e.y-t.y};if(0===i.x&&0===i.y)return n;if(0===i.x)n.y+=r*Math.sign(i.y);else if(0===i.y)n.x+=r*Math.sign(i.x);else{const t=Math.sqrt(Math.pow(i.x,2)+Math.pow(i.y,2));n.x+=i.x*(r/t),n.y+=i.y*(r/t)}return n},M=(t,e)=>{const[r,n,i]=t,[o,s,a]=e,c=.1/Math.abs([...t,...e].reduce(((t,e)=>Math.min(t,e.x,e.y)),-1)),h=(t,e,r)=>{const[n,i,o,s]=t.map(Number),[a,c,h,u]=e.map(Number),[l,p,f,d]=r.map(Number),y=o-i*h/c,x=h-c*f/p,g=u-c*d/p,m=a-c*l/p,v=(y/x*g-(s-i*u/c))/(y/x*m-(n-i*a/c)),b=(g-m*v)/x;return{x:v,y:(s-n*v-o*b)/i,z:b}},u=[o.x+c,o.y+c,1,r.x+c],l=[s.x+c,s.y+c,1,n.x+c],p=[a.x+c,a.y+c,1,i.x+c],f=h(u,l,p);u[3]=r.y+c,l[3]=n.y+c,p[3]=i.y+c;const d=h(u,l,p),y=f.x,x=f.y,g=f.z;return[y,d.x,x,d.y,g,d.z]},R=(t,e,r,n,i=.1)=>{const o=(t,e,r)=>Math.abs(t.x*(e.y-r.y)+e.x*(r.y-t.y)+r.x*(t.y-e.y))/2,s=o(e,r,n);return o(e,r,t)+o(r,n,t)+o(n,e,t)<=s+i};var B=Object.freeze({__proto__:null,calcBoundingBox:P,calcCoordDistance:A,calcExpandCoord:(t,e,r,n=1)=>{const i=C(e,r,t),o=A(t,i),s=j(t,i,o+n);return{x:s.x-i.x+e.x,y:s.y-i.y+e.y}},calcFabricCanvasCoord:(t,r)=>{var n;const i=null!==(n=t.viewportTransform)&&void 0!==n?n:[1,0,0,1,0,0];return e.util.transformPoint(new e.Point(r.x,r.y),e.util.invertTransform(i))},calcFabricRelativeCoord:(t,r)=>{const{left:n=0,top:i=0}=t;if("path"===r.type){const t=r,o=t.calcOwnMatrix(),s=e.util.transformPoint(t.pathOffset,o,!0);return e.util.transformPoint(new e.Point(n+s.x,i+s.y),e.util.invertTransform(o))}const o=r.calcOwnMatrix();return e.util.transformPoint(new e.Point(n,i),e.util.invertTransform(o))},calcIntersection:(t,e,r,n)=>{const i=(t,e)=>Math.abs(t-e)<Math.pow(.1,12);if(i(t.x,e.x)&&i(r.x,n.x))return null;if(i(t.y,e.y)&&i(r.y,n.y))return null;const o=1e4*(e.y-t.y)/Math.round(1e4*(e.x-t.x)),s=1e4*(n.y-r.y)/Math.round(1e4*(n.x-r.x)),a=t.y-o*t.x,c=r.y-s*r.x;if(Math.abs(o)===1/0)return{x:t.x,y:s*t.x+c};if(Math.abs(s)===1/0)return{x:r.x,y:o*r.x+a};const h=(c-a)/(o-s);return{x:h,y:o*h+a}},calcMatrix:M,calcPerpendicularIntersection:C,calcRelativeCoord:j,isTriangleContainsPoint:R});const I=(t,e,r,n,i)=>{var o;const{x:s,y:a,sourceScale:c=1,destinationScale:h=1}=n,{color:u={r:255,g:0,b:0,a:1},showTexture:l=!0,showGrid:p=!1,showGridDot:f=!1}=null!==(o=t.renderOptions)&&void 0!==o?o:{},{calcBoundingBox:d,calcPerpendicularIntersection:y,calcCoordDistance:x,calcRelativeCoord:g,calcMatrix:m}=i,v=(t,e,r,n=1)=>{const i=y(e,r,t),o=x(t,i),s=g(t,i,o+n);return{x:s.x-i.x+e.x,y:s.y-i.y+e.y}},b=r.getContext("2d");b.clearRect(0,0,r.width,r.height);const _=Math.ceil(1/(c*h));b.save(),b.transform(c*h,0,0,c*h,s*c*h,a*c*h);const w=(t,r,n,i,o,s,a)=>{const h=[t,n,o],y=new Path2D;for(let t=0;t<3;t++){const e=h[t],r=h[(t+1)%3],n=h[(t+2)%3],i=v(e,r,n,_),o=v(e,n,r,_);y.lineTo(i.x,i.y),y.lineTo(o.x,o.y)}if(l){b.save(),b.clip(y);const h=m([t,n,o],[r,i,s]);b.transform(...h);const u=d(r,i,s),l=(a.x-1)*c,p=(a.y-1)*c,f=(u.width+2)*c,x=(u.height+2)*c,g=a.x-1/c,v=a.y-1/c,_=u.width+2/c,w=u.height+2/c;b.drawImage(e,l,p,f,x,g,v,_,w),b.restore()}if(f){const e=Math.floor(2/c);b.fillStyle=`rgba(${u.r}, ${u.g}, ${u.b}, ${u.a})`,b.fillRect(t.x-e/2,t.y-e/2,e,e)}if(p){const t=Math.floor(1/c);b.lineWidth=t,b.strokeStyle="rgba(255, 0, 0, 0.5)",b.stroke(y)}};return t.meshPoints.forEach(((e,r)=>{e.forEach(((e,n)=>{const i=e,o=t.mesh[r][n].vertical.length-1;i.forEach(((e,s)=>{const a=i[s],c=i[s+1],h=i[s+o+2],u=i[s+o+1],l=t.initialMeshPoints[r][n][s],p=t.initialMeshPoints[r][n][s+1],f=t.initialMeshPoints[r][n][s+o+2],d=t.initialMeshPoints[r][n][s+o+1];c&&h&&s%(o+1)<o&&(w(a,l,c,p,u,d,l),w(h,f,c,p,u,d,l))}))}))})),b.restore(),r},F=(t,e,r,n)=>{const{width:i,height:o,sourceScale:s=1,destinationScale:a=1}=n;(r=null!=r?r:document.createElement("canvas")).width=i*a*s,r.height=o*a*s;return I(t,e,r,n,{calcBoundingBox:P,calcPerpendicularIntersection:C,calcCoordDistance:A,calcRelativeCoord:j,calcMatrix:M})},L=(t,e,r,n)=>{var i;const{x:o,y:s,width:a,height:c,sourceScale:h=1}=n,{antialias:u=!0,color:l={r:255,g:0,b:0,a:1},showTexture:p=!0,showGrid:f=!1,showGridDot:d=!1}=null!==(i=t.renderOptions)&&void 0!==i?i:{},{width:y,height:x}=e,g=r.getContext("webgl",{antialias:u});if(!g)throw Error("[Fabric-Texture Error] Failed to initialize WebGL. Your browser or device may not support it.");const m={before:[],after:[]};t.meshPoints.forEach(((e,r)=>{e.forEach(((e,n)=>{const i=e,o=t.mesh[r][n].vertical.length-1;i.forEach(((e,s)=>{const a=i[s],c=i[s+1],h=i[s+o+2],u=i[s+o+1],l=t.initialMeshPoints[r][n][s],p=t.initialMeshPoints[r][n][s+1],f=t.initialMeshPoints[r][n][s+o+2],d=t.initialMeshPoints[r][n][s+o+1];c&&h&&s%(o+1)<o&&(m.before.push(l,p,d,f,p,d),m.after.push(a,c,u,h,c,u))}))}))}));const v="\n attribute vec4 aVertexPosition;\n attribute vec2 aTextureCoord;\n varying highp vec2 vTextureCoord;\n void main(void) {\n gl_Position = aVertexPosition;\n gl_PointSize = 2.0;\n vTextureCoord = aTextureCoord;\n }\n ",b=(t,e)=>{const r=g.createShader(t);return r?(g.shaderSource(r,e),g.compileShader(r),g.getShaderParameter(r,g.COMPILE_STATUS)?r:(console.error("Shader compilation error:",g.getShaderInfoLog(r)),g.deleteShader(r),null)):(console.error("Failed to create shader."),null)},_=(t,e)=>{const r=b(g.VERTEX_SHADER,t);if(!r)return console.error("Failed to initialize vertex shader."),null;const n=b(g.FRAGMENT_SHADER,e);if(!n)return console.error("Failed to initialize fragment shader."),null;const i=g.createProgram();return i?(g.attachShader(i,r),g.attachShader(i,n),g.linkProgram(i),g.getProgramParameter(i,g.LINK_STATUS)?i:(console.error("Shader program linking error:",g.getProgramInfoLog(i)),null)):(console.error("Failed to create shader program."),null)},w=t=>!(t&t-1),T=_(v,"\n varying highp vec2 vTextureCoord;\n uniform sampler2D uSampler;\n void main(void) {\n gl_FragColor = texture2D(uSampler, vTextureCoord);\n }\n ");if(!T)throw Error("[Fabric-Texture Error] Failed to initialize shader program.");const E={program:T,attribLocations:{vertexPosition:g.getAttribLocation(T,"aVertexPosition"),textureCoord:g.getAttribLocation(T,"aTextureCoord")},uniformLocations:{uSampler:g.getUniformLocation(T,"uSampler")}},z=g.createTexture();if(!z)throw Error("[Fabric-Texture Error] Failed to create WebGL texture object.");g.bindTexture(g.TEXTURE_2D,z),g.texImage2D(g.TEXTURE_2D,0,g.RGBA,g.RGBA,g.UNSIGNED_BYTE,e),w(e.width)&&w(e.height)&&g.generateMipmap(g.TEXTURE_2D),g.enable(g.BLEND),g.blendFunc(g.SRC_ALPHA,g.ONE_MINUS_SRC_ALPHA),g.texParameteri(g.TEXTURE_2D,g.TEXTURE_WRAP_S,g.CLAMP_TO_EDGE),g.texParameteri(g.TEXTURE_2D,g.TEXTURE_WRAP_T,g.CLAMP_TO_EDGE),g.texParameteri(g.TEXTURE_2D,g.TEXTURE_MIN_FILTER,g.LINEAR),g.viewport(0,0,r.width,r.height);return((t,e,r)=>{g.clearColor(0,0,0,0),g.clear(g.COLOR_BUFFER_BIT);const n=g.FLOAT,i=!1,o=4*Float32Array.BYTES_PER_ELEMENT;g.bindBuffer(g.ARRAY_BUFFER,e.position),g.vertexAttribPointer(t.attribLocations.vertexPosition,2,n,i,o,0),g.enableVertexAttribArray(t.attribLocations.vertexPosition),g.bindBuffer(g.ARRAY_BUFFER,e.textureCoord),g.vertexAttribPointer(t.attribLocations.textureCoord,2,n,i,o,0),g.enableVertexAttribArray(t.attribLocations.textureCoord),g.useProgram(t.program),g.activeTexture(g.TEXTURE0),g.bindTexture(g.TEXTURE_2D,r),g.uniform1i(t.uniformLocations.uSampler,0),p&&g.drawArrays(g.TRIANGLES,0,m.before.length);const{r:s,g:a,b:c,a:h}=l,u=`${(s/255).toFixed(1)}, ${(a/255).toFixed(1)}, ${(c/255).toFixed(1)}, ${h.toFixed(1)}`,y=_(v,`\n void main(void) {\n gl_FragColor = vec4(${u});\n }\n `);if(!y)throw Error("[Fabric-Texture Error] Failed to initialize outline shader program.");g.bindBuffer(g.ARRAY_BUFFER,e.position),g.vertexAttribPointer(g.getAttribLocation(y,"aVertexPosition"),2,n,i,0,0),g.enableVertexAttribArray(g.getAttribLocation(y,"aVertexPosition")),g.bindBuffer(g.ARRAY_BUFFER,e.textureCoord),g.vertexAttribPointer(g.getAttribLocation(y,"aTextureCoord"),2,n,i,0,0),g.enableVertexAttribArray(g.getAttribLocation(y,"aTextureCoord")),g.useProgram(y),f&&g.drawArrays(g.LINES,0,2*m.before.length),d&&g.drawArrays(g.POINTS,0,2*m.before.length)})(E,(()=>{const t=g.createBuffer();g.bindBuffer(g.ARRAY_BUFFER,t);const e=m.before.map(((t,e)=>{const r=[t.x/(y/h),t.y/(x/h)];return(e+1)%3==0?r.push(m.before[e-2].x/(y/h),m.before[e-2].y/(x/h)):r.push(m.before[e+1].x/(y/h),m.before[e+1].y/(x/h)),r})).flat(1);g.bufferData(g.ARRAY_BUFFER,new Float32Array(e),g.STATIC_DRAW);const r=g.createBuffer();g.bindBuffer(g.ARRAY_BUFFER,r);const n=m.after.map(((t,e)=>{const r=[(t.x+o)/(a/2)-1,-((t.y+s)/(c/2)-1)];return(e+1)%3==0?r.push((m.after[e-2].x+o)/(a/2)-1,-((m.after[e-2].y+s)/(c/2)-1)):r.push((m.after[e+1].x+o)/(a/2)-1,-((m.after[e+1].y+s)/(c/2)-1)),r})).flat(1);return g.bufferData(g.ARRAY_BUFFER,new Float32Array(n),g.STATIC_DRAW),{position:r,textureCoord:t}})(),z),r},D=(t,e,r,n)=>{const{width:i,height:o,sourceScale:s=1,destinationScale:a=1}=n;(r=null!=r?r:document.createElement("canvas")).width=i*a*s,r.height=o*a*s;return L(t,e,r,n)},k="WORKER_MESSAGE",U="JOB_RESULT",G=t=>t instanceof ArrayBuffer||t instanceof MessagePort||self.ImageBitmap&&t instanceof ImageBitmap,N=()=>{const t=[];let e,r=new Map;const n={collect:t=>{for(let e in t)r.set(e,t[e]);return n},onMessage:t=>(e=t,n),create:n=>{const i=n.toString(),o=`\n // 将收集到的变量声明和定义加入脚本字符串,后面函数执行的时候便不会出现not defined的错误了\n $collections = {};\n ${Object.entries(Object.fromEntries(r)).reduce(((t,[e,r])=>t+`$collections['${e}']=`+("function"==typeof r?`${r};`:`JSON.parse(\`${JSON.stringify(r)}\`);`)),"")}\n \n // 声明定义用于判断是否是可转移对象的函数\n $isTransferables = ${G}\n \n // 在脚本中声明并定义一个包含工作流程的函数体\n $job=${i};\n \n // 给worker线程添加消息监听,等待主线程的发号施令\n onmessage=e=>{\n const { index, args } = e.data;\n \n Promise.resolve(\n $job.apply($job, args.concat([{\n collections: $collections,\n postMessage: (message) => postMessage({ type: '${k}', message }),\n close: self.close,\n }]))\n ).then(result => {\n postMessage({ type: '${U}', message: { index, result } }, [result].filter($isTransferables))\n }).catch(error => {\n postMessage({ type: '${U}', message: { index, error } })\n })\n }\n `,s=URL.createObjectURL(new Blob([o],{type:"text/javascript"})),a=new Worker(s);return a.onmessage=function(r){const n=r.data;if(n.type===k&&e&&e.call(e,n.message),n.type===U){const{index:e,result:r,error:i}=n.message,{done:o}=t[e];o(i,r)}},{run:(...e)=>new Promise(((r,n)=>{const i=t.length;t.push({done:(t,e)=>{t?n(t):r(e)}}),a.postMessage({index:i,args:e},e.filter(G))})),terminate:()=>{a.terminate(),URL.revokeObjectURL(s),t.length=0,r.clear(),e=void 0}}}};return n},$=(t,e,n,i)=>r(void 0,void 0,void 0,(function*(){const{meshPoints:r,renderOptions:o,mesh:s,initialMeshPoints:a}=t,c={renderOptions:o,mesh:s.map((t=>t.map((t=>({horizontal:{length:t.horizontal.length},vertical:{length:t.vertical.length}}))))),meshPoints:r,initialMeshPoints:a},h=N().collect({texture:c,options:i,createCanvas2DTexture:I,calcBoundingBox:P,calcPerpendicularIntersection:C,calcCoordDistance:A,calcRelativeCoord:j,calcMatrix:M}).create(((t,{collections:e})=>{const{options:r,texture:n,createCanvas2DTexture:i,calcBoundingBox:o,calcPerpendicularIntersection:s,calcCoordDistance:a,calcRelativeCoord:c,calcMatrix:h}=e,{width:u,height:l,sourceScale:p=1,destinationScale:f=1}=r,d=new OffscreenCanvas(u*f*p,l*f*p),y=new OffscreenCanvas(t.width,t.height),x=y.getContext("2d");null==x||x.putImageData(t,0,0);return i(n,y,d,r,{calcBoundingBox:o,calcPerpendicularIntersection:s,calcCoordDistance:a,calcRelativeCoord:c,calcMatrix:h}).transferToImageBitmap()})),u=yield h.run(e);return h.terminate(),(n=null!=n?n:document.createElement("canvas")).width=u.width,n.height=u.height,n.getContext("2d").drawImage(u,0,0),n})),X=(t,e,n,i)=>r(void 0,void 0,void 0,(function*(){const{meshPoints:r,renderOptions:o,mesh:s,initialMeshPoints:a}=t,c={renderOptions:o,mesh:s.map((t=>t.map((t=>({horizontal:{length:t.horizontal.length},vertical:{length:t.vertical.length}}))))),meshPoints:r,initialMeshPoints:a},h=N().collect({texture:c,options:i,createWebGLTexture:L}).create(((t,{collections:e})=>{const{options:r,texture:n,createWebGLTexture:i}=e,{width:o,height:s,sourceScale:a=1,destinationScale:c=1}=r;return i(n,t,new OffscreenCanvas(o*c*a,s*c*a),r).transferToImageBitmap()})),u=yield h.run(e);return h.terminate(),(n=null!=n?n:document.createElement("canvas")).width=u.width,n.height=u.height,n.getContext("2d").drawImage(u,0,0),n}));var Y;!function(t){t.TOP_LEFT="tl",t.TOP_RIGHT="tr",t.BOTTOM_LEFT="bl",t.BOTTOM_RIGHT="br"}(Y||(Y={}));class H{constructor(t,e=1,r=1){if(this.splitRatioPoints=[],this.initialSplitAreas=[],this.initialMeshPoints=[],this.areaBoundCurves=[],this.mesh=[],this.meshPoints=[],this.splitUnit=.05,this.splitStrategy={name:"default",execute:H.strategy},this.renderEngine="webgl",this.renderOptions={padding:0,antialias:!0,safe:!0,showTexture:!0,showGrid:!1,showGridDot:!1,color:{r:255,g:0,b:0,a:1}},this._cacheSourceSize=null,this._cacheSourceImageData=null,this._cacheInputCanvas=null,this._cacheOutputCanvas=null,this._inputLimitScale=1,this._outputLimitScale=1,!(t instanceof HTMLCanvasElement||t instanceof HTMLImageElement))throw new TypeError("[Fabric-Texture Error] source must be either HTMLCanvasElement or HTMLImageElement!");if(t instanceof HTMLImageElement){const e=document.createElement("canvas"),r=e.getContext("2d");if(!r)throw new Error("Failed to get 2D rendering context for canvas");e.width=t.naturalWidth,e.height=t.naturalHeight,r.drawImage(t,0,0),this.source=e}else this.source=t;this.splitRatioPoints=this._initializeGridPoints(e,r),this.setTransformData(this.splitRatioPoints)}get maxSplitUnitPixel(){return this.splitUnit*this.source.width}get scale(){return{x:this._inputLimitScale*this._outputLimitScale,y:this._inputLimitScale*this._outputLimitScale}}static strategy(t){if(!t.mesh)return[];const e=[];return t.areaBoundCurves.forEach(((r,n)=>{const i=[];r.forEach(((e,r)=>{const o=[],{vertical:s,horizontal:a}=t.mesh[n][r];for(let t=0;t<a.length;t++)for(let e=0;e<s.length;e++){const r=s[e].get(t/(a.length-1)),n=a[t].get(e/(s.length-1));o.push({x:(r.x+n.x)/2,y:(r.y+n.y)/2})}i.push(o)})),e.push(i)})),e}static compressTransformData(t){const{splitRatioPoints:e,areaBound:r}=t,n=[e.length,r.length,r[0].length];e.forEach((t=>{n.push(t.x,t.y)}));const i=["top","right","bottom","left"];r.forEach((t=>t.forEach((t=>[i.forEach((e=>t[e].forEach((t=>{n.push(t.x,t.y)}))))]))));const o=new Float32Array(n),s=new Uint8Array(o.buffer);return btoa(String.fromCharCode.apply(null,s))}static decompressTransformData(t){const e=atob(t),r=new Uint8Array(e.length);for(let t=0;t<e.length;t++)r[t]=e.charCodeAt(t);const n=new Float32Array(r.buffer),i=Array.from(n),o=["top","right","bottom","left"],s=i[0],a=i[1],c=i[2];let h=3;const u=[];for(let t=0;t<s;t++)u.push({x:i[h],y:i[h+1]}),h+=2;const l=[];for(let t=0;t<a;t++){const t=[];for(let e=0;e<c;e++){const e={};for(const t of o){e[t]=[];for(let r=0;r<4;r++)e[t].push({x:i[h],y:i[h+1]}),h+=2}t.push(e)}l.push(t)}return{splitRatioPoints:u,areaBound:l}}_initializeGridPoints(t=1,e=1){const r=Math.max(Math.floor(t),1),n=Math.max(Math.floor(e),1),i=[];for(let o=1;o<r;o++)for(let r=1;r<n;r++)o===r&&i.push({x:r/e,y:o/t});return i}_initializeGridAreas(){const{width:t,height:e}=this.source;let r=[],n=[];this.splitRatioPoints.forEach((t=>{t.x<0||t.x>1||t.y<0||t.y>1||(r.push(t.x),n.push(t.y))})),r=[...new Set([0,...r,1])],n=[...new Set([0,...n,1])],r.sort(((t,e)=>t-e)),n.sort(((t,e)=>t-e));const i=[];for(let o=0;o<n.length-1;o++){i.push([]);for(let s=0;s<r.length-1;s++)i[i.length-1].push({tl:{x:r[s]*t,y:n[o]*e},tr:{x:r[s+1]*t,y:n[o]*e},bl:{x:r[s]*t,y:n[o+1]*e},br:{x:r[s+1]*t,y:n[o+1]*e}})}return this._cacheSourceSize={width:t,height:e},i}_calculateSamplingPoints(t){const e=t.tr.x-t.tl.x,r=t.bl.y-t.tl.y,n=Math.max(Math.ceil(e/this.maxSplitUnitPixel),1)+1,i=Math.max(Math.ceil(r/this.maxSplitUnitPixel),1)+1;return{hts:Array.from({length:n}).map(((t,e)=>e/(n-1))),vts:Array.from({length:i}).map(((t,e)=>e/(i-1)))}}_initializeGridMeshPoints(){return this.initialSplitAreas.map((t=>t.map((t=>{const{hts:e,vts:r}=this._calculateSamplingPoints(t),n=[],{tl:i,tr:o,bl:s}=t,a=o.x-i.x,c=s.y-i.y;for(let t=0;t<r.length;t++)for(let o=0;o<e.length;o++)n.push({x:i.x+a*e[o],y:i.y+c*r[t]});return n}))))}_initializeBoundaryControlPoints(t){const e=[];return t.forEach((t=>{e.push([]),t.forEach((t=>{const r=t,{tl:n,tr:i,br:o,bl:s}=r,a={top:[n,i],bottom:[s,o],left:[n,s],right:[i,o]},c={};for(const t in a){const[e,r]=a[t];c[t]=[e,{x:e.x+1*(r.x-e.x)/3,y:e.y+1*(r.y-e.y)/3},{x:r.x-1*(r.x-e.x)/3,y:r.y-1*(r.y-e.y)/3},r]}e[e.length-1].push(c)}))})),e}_generateAreaMeshCurves(t,e,r){const n={horizontal:[],vertical:[]};return e.forEach((e=>{if(0===e)return void n.vertical.push(t.left);if(1===e)return void n.vertical.push(t.right);const r=t.top.get(e),i=t.bottom.get(e),o=new O([r,{x:r.x+((t.left.points[1].x-t.left.points[0].x)*(1-e)+(t.right.points[1].x-t.right.points[0].x)*e),y:r.y+((t.left.points[1].y-t.left.points[0].y)*(1-e)+(t.right.points[1].y-t.right.points[0].y)*e)},{x:i.x+((t.left.points[2].x-t.left.points[3].x)*(1-e)+(t.right.points[2].x-t.right.points[3].x)*e),y:i.y+((t.left.points[2].y-t.left.points[3].y)*(1-e)+(t.right.points[2].y-t.right.points[3].y)*e)},i]);n.vertical.push(o)})),r.forEach((e=>{if(0===e)return void n.horizontal.push(t.top);if(1===e)return void n.horizontal.push(t.bottom);const r=t.left.get(e),i=t.right.get(e),o=new O([r,{x:r.x+((t.top.points[1].x-t.top.points[0].x)*(1-e)+(t.bottom.points[1].x-t.bottom.points[0].x)*e),y:r.y+((t.top.points[1].y-t.top.points[0].y)*(1-e)+(t.bottom.points[1].y-t.bottom.points[0].y)*e)},{x:i.x+((t.top.points[2].x-t.top.points[3].x)*(1-e)+(t.bottom.points[2].x-t.bottom.points[3].x)*e),y:i.y+((t.top.points[2].y-t.top.points[3].y)*(1-e)+(t.bottom.points[2].y-t.bottom.points[3].y)*e)},i]);n.horizontal.push(o)})),n}_generateMeshCurves(t){const e=[];return t.forEach(((t,r)=>{const n=[];e.push(n),t.forEach(((t,e)=>{const i=t,o=this.initialSplitAreas[r][e],{hts:s,vts:a}=this._calculateSamplingPoints(o);n.push(this._generateAreaMeshCurves(i,s,a))}))})),e}setSplitUnit(t){return this.splitUnit=t<=0?1:Math.min(1,t),this.initialMeshPoints=this._initializeGridMeshPoints(),this}setSplitStrategy(t){return this.splitStrategy=t,this}setInputLimitSize(t){return this._inputLimitSize=t,t||(this._inputLimitScale=1,this._cacheInputCanvas=null),this._cacheSourceImageData=null,this}setOutputLimitSize(t){return this._outputLimitSize=t,t||(this._outputLimitScale=1),this}useCanvasRender(){return this.renderEngine="canvas",this}useWebGLRender(){return this.renderEngine="webgl",this}useInstanceCanvas(t=null){return this._cacheOutputCanvas=null!=t?t:document.createElement("canvas"),this}setRenderOptions(t){return this.renderOptions=Object.assign(Object.assign({},this.renderOptions),t),this}getBoundingBoxInfo(){const{padding:t}=this.renderOptions,e=this.mesh.length,r=this.mesh[0].length,n={left:1/0,right:-1/0,top:1/0,bottom:-1/0};for(let t=0;t<e;t++)for(let e=0;e<r;e++){const r=this.mesh[t][e];Object.values(r).forEach((t=>{const e=t.length;for(let r=0;r<e;r++){const e=t[r].bbox();n.left=Math.min(n.left,e.x.min),n.right=Math.max(n.right,e.x.max),n.top=Math.min(n.top,e.y.min),n.bottom=Math.max(n.bottom,e.y.max)}}))}return{offsetX:-n.left+t,offsetY:-n.top+t,width:n.right-n.left+2*t,height:n.bottom-n.top+2*t}}_createLinearBezier(t,e){return[t,{x:t.x+1*(e.x-t.x)/3,y:t.y+1*(e.y-t.y)/3},{x:e.x-1*(e.x-t.x)/3,y:e.y-1*(e.y-t.y)/3},e]}_mergeBezierCurves(t,e){const r=(t,e,r)=>{const{x:n,y:i}=e,{x:o,y:s}=r,a=Math.atan2(i,n),c=Math.atan2(s,o)-a,h=Math.sqrt(Math.pow(o,2)+Math.pow(s,2))*Math.cos(c),u=h*Math.cos(a),l=h*Math.sin(a);return{x:t.x+u,y:t.y+l}},n=r(t[1],{x:t[1].x-t[0].x,y:t[1].y-t[0].y},{x:e[1].x-e[0].x,y:e[1].y-e[0].y}),i=r(e[2],{x:e[2].x-e[3].x,y:e[2].y-e[3].y},{x:t[2].x-t[3].x,y:t[2].y-t[3].y});return[t[0],n,i,e[3]]}_findConnectedVertex(t,e){const r={top:[["left",0],["right",0]],bottom:[["left",3],["right",3]],left:[["top",0],["bottom",0]],right:[["top",3],["bottom",3]]}[t];if(!r||!["first","last"].includes(e))throw TypeError(`[Fabric-Texture Error] Invalid vertex connection parameters: direction="${t}", position="${e}"\nExpected values:\n- direction: "top" | "bottom" | "left" | "right"\n- position: "first" | "last"`);const n=r[{first:0,last:1}[e]];return{direction:n[0],position:{0:"first",3:"last"}[n[1]]}}_setSingleAreaVertexCoord(t,e,r,n,i=!0){const o=(r,n,o)=>{var s,a;const c=null===(a=null===(s=this.areaBoundCurves[t])||void 0===s?void 0:s[e])||void 0===a?void 0:a[r];if(!c)return;const h="first"===n?o:c.points[0],u="last"===n?o:c.points[3];c.points.forEach(((t,e)=>{if(!i&&[1,2].includes(e))return;const r=this._createLinearBezier(h,u)[e];t.x=r.x,t.y=r.y}))},[s,a]={[Y.TOP_LEFT]:["top","first"],[Y.TOP_RIGHT]:["top","last"],[Y.BOTTOM_LEFT]:["bottom","first"],[Y.BOTTOM_RIGHT]:["bottom","last"]}[r];o(s,a,n);const c=this._findConnectedVertex(s,a);o(c.direction,c.position,n)}setVertexCoord(t,e,r,n,i=!0){this._setSingleAreaVertexCoord(t,e,r,n,i);return{[Y.TOP_LEFT]:[{row:t-1,col:e-1,type:Y.BOTTOM_RIGHT},{row:t-1,col:e,type:Y.BOTTOM_LEFT},{row:t,col:e-1,type:Y.TOP_RIGHT}],[Y.TOP_RIGHT]:[{row:t-1,col:e+1,type:Y.BOTTOM_LEFT},{row:t,col:e+1,type:Y.TOP_LEFT},{row:t-1,col:e,type:Y.BOTTOM_RIGHT}],[Y.BOTTOM_LEFT]:[{row:t,col:e-1,type:Y.BOTTOM_RIGHT},{row:t+1,col:e,type:Y.TOP_LEFT},{row:t+1,col:e-1,type:Y.TOP_RIGHT}],[Y.BOTTOM_RIGHT]:[{row:t,col:e+1,type:Y.BOTTOM_LEFT},{row:t+1,col:e,type:Y.TOP_RIGHT},{row:t+1,col:e+1,type:Y.TOP_LEFT}]}[r].forEach((({row:t,col:e,type:r})=>{this._setSingleAreaVertexCoord(t,e,r,n,i)})),this}setBoundCoords(t,e,r,n){return this.areaBoundCurves=this._initializeAreaBoundCurves(this.getAreaBoundCoords(((i,o,s,a)=>i===t&&o===e&&r===s?n:a.points.map((t=>({x:t.x,y:t.y})))))),this.setVertexCoord(t,e,{top:Y.TOP_LEFT,right:Y.TOP_RIGHT,bottom:Y.BOTTOM_LEFT,left:Y.TOP_LEFT}[r],n[0],!1),this.setVertexCoord(t,e,{top:Y.TOP_RIGHT,right:Y.BOTTOM_RIGHT,bottom:Y.BOTTOM_RIGHT,left:Y.BOTTOM_LEFT}[r],n[3],!1),this}getAreaBoundCoords(t=((t,e,r,n)=>n.points)){const e=[];return this.areaBoundCurves.forEach(((r,n)=>{e.push([]),r.forEach(((r,i)=>{e[e.length-1].push(["top","right","left","bottom"].reduce(((e,o)=>(e[o]=t(n,i,o,r[o]),e)),{}))}))})),e}_initializeAreaBoundCurves(t){const e=[];return t.forEach(((t,r)=>{e.push([]),t.forEach(((t,n)=>{var i,o,s,a;const c={};for(const h in t){switch(h){case"top":{const t=null===(o=null===(i=e[r-1])||void 0===i?void 0:i[n])||void 0===o?void 0:o.bottom;t&&(c[h]=t);break}case"left":{const t=null===(a=null===(s=e[r])||void 0===s?void 0:s[n-1])||void 0===a?void 0:a.right;t&&(c[h]=t);break}}if(!c[h]){const e=t[h];c[h]=new O(e[0].x,e[0].y,e[1].x,e[1].y,e[2].x,e[2].y,e[3].x,e[3].y)}}e[e.length-1].push(c)}))})),e}getTransformData(){const t=this.getAreaBoundCoords();return{splitRatioPoints:this.splitRatioPoints,areaBound:t}}setTransformData(t,e=null){if(this.splitRatioPoints=t,this.initialSplitAreas=this._initializeGridAreas(),this.initialMeshPoints=this._initializeGridMeshPoints(),e)this.areaBoundCurves=this._initializeAreaBoundCurves(e);else{const t=this._initializeBoundaryControlPoints(this.initialSplitAreas);this.areaBoundCurves=this._initializeAreaBoundCurves(t)}return this}resetTransformData(t=1,e=1){return this.splitRatioPoints=this._initializeGridPoints(t,e),this.setTransformData(this.splitRatioPoints)}isNoneTransform(){const t=this.getAreaBoundCoords(((t,e,r,n)=>n.points.map((t=>({x:t.x/this.source.width,y:t.y/this.source.height})))));return 0===this.splitRatioPoints.length&&Object.entries(t[0][0]).every((([t,e])=>{const r=["right","bottom"].includes(t)?1:0,n={top:"y",bottom:"y",left:"x",right:"x"}[t],i={top:"x",bottom:"x",left:"y",right:"y"}[t];return e.every((t=>t[n]===r))&&0===e[0][i]&&Math.abs(e[1][i]-1/3)<Number.EPSILON&&Math.abs(e[2][i]-2/3)<Number.EPSILON&&1===e[3][i]}))}containsPoint(t){let e=null;try{this.forEachSplitArea((([r,n,i,o],s,a,c,h,u)=>{const l=R(t,r,n,o),p=R(t,i,n,o);if(l||p)throw e={rowIndex:h,colIndex:u,row:a,col:c,after:[r,n,i,o],before:s,clickPart:l?0:1},Error()}))}catch(t){}return e}addSplitPoint(t,e,r,n=.05){const{tl:i,tr:o,bl:s}=this.initialSplitAreas[t][e];let a=(r.x-i.x)/(o.x-i.x),c=(r.y-i.y)/(s.y-i.y);a<n&&(a=0),a>1-n&&(a=1),c<n&&(c=0),c>1-n&&(c=1);const h=[];this.areaBoundCurves.forEach(((e,r)=>{if(r!==t||0===c||1===c)return void h.push(e.map((t=>{const e={};for(const r in t)e[r]=t[r].points;return e})));const n=[],i=[];e.forEach((t=>{const{horizontal:e,vertical:r}=this._generateAreaMeshCurves(t,[0,1],[0,c,1]),{left:o,right:s}=r[0].split(c),{left:a,right:h}=r[1].split(c);n.push({left:o.points,right:a.points,top:e[0].points,bottom:e[1].points}),i.push({left:s.points,right:h.points,top:e[1].points,bottom:e[2].points})})),h.push(n,i)})),0!==a&&1!==a&&h.forEach(((t,r)=>{const{horizontal:n,vertical:i}=this._generateAreaMeshCurves({left:new O(t[e].left),right:new O(t[e].right),top:new O(t[e].top),bottom:new O(t[e].bottom)},[0,a,1],[0,1]),{left:o,right:s}=n[0].split(a),{left:c,right:u}=n[1].split(a);h[r].splice(e,1,{left:i[0].points,right:i[1].points,top:o.points,bottom:c.points},{left:i[1].points,right:i[2].points,top:s.points,bottom:u.points})})),this.setTransformData([...this.splitRatioPoints,{x:(0===a?i.x:1===a?o.x:r.x)/this.source.width,y:(0===c?i.y:1===c?s.y:r.y)/this.source.height}],h)}removeSplitPoints(t){const e=[],{width:r,height:n}=this.source,i=(i,o,s)=>{t.some((t=>t[0]===o||t[1]===s))||0===o&&0===s||o===this.initialSplitAreas.length&&0===s||0===o&&s===this.initialSplitAreas[0].length||o===this.initialSplitAreas.length&&s===this.initialSplitAreas[0].length||e.some((t=>t.x===i.x||0===s||s===this.initialSplitAreas[0].length))&&e.some((t=>t.y===i.y||0===o||o===this.initialSplitAreas.length))||e.push({x:i.x/r,y:i.y/n})};this.initialSplitAreas.forEach(((t,e)=>{t.forEach(((r,n)=>{const{tl:o,tr:s,bl:a,br:c}=r;i(o,e,n),n===t.length-1&&i(s,e,n+1),e===this.initialSplitAreas.length-1&&(i(a,e+1,n),n===t.length-1&&i(c,e+1,n+1))}))}));const o=this.getAreaBoundCoords(),s=[...new Set(t.map((t=>t[0])))];s.sort(((t,e)=>e-t)),s.forEach((t=>{const e=o[t],r=o[t-1];e&&r&&o.splice(t-1,2,r.map(((t,r)=>({top:t.top,left:this._mergeBezierCurves(t.left,e[r].left),right:this._mergeBezierCurves(t.right,e[r].right),bottom:e[r].bottom}))))}));const a=[...new Set(t.map((t=>t[1])))];a.sort(((t,e)=>e-t)),a.forEach((t=>{o.forEach((e=>{const r=e[t],n=e[t-1];r&&n&&e.splice(t-1,2,{top:this._mergeBezierCurves(n.top,r.top),left:n.left,right:r.right,bottom:this._mergeBezierCurves(n.bottom,r.bottom)})}))})),this.setTransformData(e,o)}forEachSplitArea(t){this.meshPoints.forEach(((e,r)=>{e.forEach(((e,n)=>{const i=e,o=this.mesh[r][n].vertical.length-1;i.forEach(((e,s)=>{const a=Math.floor(s/(o+1)),c=s%(o+1),h=i[s],u=i[s+1],l=i[s+o+2],p=i[s+o+1],f=this.initialMeshPoints[r][n][s],d=this.initialMeshPoints[r][n][s+1],y=this.initialMeshPoints[r][n][s+o+2],x=this.initialMeshPoints[r][n][s+o+1];u&&l&&s%(o+1)<o&&t([h,u,l,p],[f,d,y,x],a,c,r,n)}))}))}))}_generateCreateOptions(){var t,e;!this._cacheSourceSize||this._cacheSourceSize.width===this.source.width&&this._cacheSourceSize.height===this.source.height||this.setTransformData(this.splitRatioPoints),this.mesh=this._generateMeshCurves(this.areaBoundCurves),this.meshPoints=this.splitStrategy.execute(this);const{offsetX:r,offsetY:n,width:i,height:o}=this.getBoundingBoxInfo();if(this._inputLimitSize&&!this._cacheInputCanvas){const t=this._inputLimitSize,{width:e,height:r}=this.source,n={width:t.width?Math.min(1,t.width/e):0,height:t.height?Math.min(1,t.height/r):0};n.width=n.width||n.height,n.height=n.height||n.width;const i=Math.min(n.width,n.height),o=document.createElement("canvas");o.width=Math.ceil(e*i),o.height=Math.ceil(r*i);const s=o.getContext("2d");null==s||s.drawImage(this.source,0,0,o.width,o.height),this._inputLimitScale=i,this._cacheInputCanvas=o}if(this._outputLimitSize){let t=1;this._outputLimitSize.width&&(t=Math.min(t,this._outputLimitSize.width/i)),this._outputLimitSize.height&&(t=Math.min(t,this._outputLimitSize.height/o)),this._outputLimitScale=t}return{inputCanvas:null!==(t=this._cacheInputCanvas)&&void 0!==t?t:this.source,outputCanvas:null!==(e=this._cacheOutputCanvas)&&void 0!==e?e:null,options:{x:r,y:n,width:i,height:o,sourceScale:this._inputLimitScale,destinationScale:this._outputLimitScale}}}_getInputCanvasImageData(){var t;if(this._cacheSourceImageData)return this._cacheSourceImageData;const e=null!==(t=this._cacheInputCanvas)&&void 0!==t?t:this.source,r=e.getContext("2d");if(!r)throw new Error("[Fabric-Texture Error] Failed to get 2D rendering context. Please ensure that:\n1. The inputCanvas is a valid <canvas> element\n2. The browser supports Canvas API\n3. The canvas has not been tainted by cross-origin content");const n=r.getImageData(0,0,e.width,e.height);return this._cacheSourceImageData=n,n}create(){const{inputCanvas:t,outputCanvas:e,options:r}=this._generateCreateOptions(),n={canvas:F,webgl:D}[this.renderEngine];try{return n(this,t,e,r)}catch(n){if(this.renderOptions.safe&&"webgl"===this.renderEngine)return F(this,t,e,r);throw n}}createWithWorker(){return r(this,void 0,void 0,(function*(){const{outputCanvas:t,options:e}=this._generateCreateOptions(),r=this._getInputCanvasImageData(),n={canvas:$,webgl:X}[this.renderEngine];try{return n(this,r,t,e)}catch(n){if(this.renderOptions.safe&&"webgl"===this.renderEngine)return X(this,r,t,e);throw n}}))}destroy(){this._cacheInputCanvas&&(this._cacheInputCanvas.width=0,this._cacheInputCanvas.height=0,this._cacheInputCanvas=null),this._cacheOutputCanvas&&(this._cacheOutputCanvas.width=0,this._cacheOutputCanvas.height=0,this._cacheOutputCanvas=null),this._cacheSourceImageData=null,this._cacheSourceSize=null,this.splitRatioPoints=[],this.initialSplitAreas=[],this.initialMeshPoints=[],this.areaBoundCurves=[],this.mesh=[],this.meshPoints=[]}}function W(t,e){return t===e||t!=t&&e!=e}function V(t,e){for(var r=t.length;r--;)if(W(t[r][0],e))return r;return-1}var q=Array.prototype.splice;function J(t){var e=-1,r=null==t?0:t.length;for(this.clear();++e<r;){var n=t[e];this.set(n[0],n[1])}}J.prototype.clear=function(){this.__data__=[],this.size=0},J.prototype.delete=function(t){var e=this.__data__,r=V(e,t);return!(r<0)&&(r==e.length-1?e.pop():q.call(e,r,1),--this.size,!0)},J.prototype.get=function(t){var e=this.__data__,r=V(e,t);return r<0?void 0:e[r][1]},J.prototype.has=function(t){return V(this.__data__,t)>-1},J.prototype.set=function(t,e){var r=this.__data__,n=V(r,t);return n<0?(++this.size,r.push([t,e])):r[n][1]=e,this};var K="object"==typeof global&&global&&global.Object===Object&&global,Q="object"==typeof self&&self&&self.Object===Object&&self,Z=K||Q||Function("return this")(),tt=Z.Symbol,et=Object.prototype,rt=et.hasOwnProperty,nt=et.toString,it=tt?tt.toStringTag:void 0;var ot=Object.prototype.toString;var st="[object Null]",at="[object Undefined]",ct=tt?tt.toStringTag:void 0;function ht(t){return null==t?void 0===t?at:st:ct&&ct in Object(t)?function(t){var e=rt.call(t,it),r=t[it];try{t[it]=void 0;var n=!0}catch(t){}var i=nt.call(t);return n&&(e?t[it]=r:delete t[it]),i}(t):function(t){return ot.call(t)}(t)}function ut(t){var e=typeof t;return null!=t&&("object"==e||"function"==e)}var lt="[object AsyncFunction]",pt="[object Function]",ft="[object GeneratorFunction]",dt="[object Proxy]";function yt(t){if(!ut(t))return!1;var e=ht(t);return e==pt||e==ft||e==lt||e==dt}var xt,gt=Z["__core-js_shared__"],mt=(xt=/[^.]+$/.exec(gt&>.keys&>.keys.IE_PROTO||""))?"Symbol(src)_1."+xt:"";var vt=Function.prototype.toString;function bt(t){if(null!=t){try{return vt.call(t)}catch(t){}try{return t+""}catch(t){}}return""}var _t=/^\[object .+?Constructor\]$/,wt=Function.prototype,Tt=Object.prototype,Et=wt.toString,zt=Tt.hasOwnProperty,St=RegExp("^"+Et.call(zt).replace(/[\\^$.*+?()[\]{}|]/g,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$");function Ot(t){return!(!ut(t)||(e=t,mt&&mt in e))&&(yt(t)?St:_t).test(bt(t));var e}function Ct(t,e){var r=function(t,e){return null==t?void 0:t[e]}(t,e);return Ot(r)?r:void 0}var At=Ct(Z,"Map"),Pt=Ct(Object,"create");var jt=Object.prototype.hasOwnProperty;var Mt=Object.prototype.hasOwnProperty;function Rt(t){var e=-1,r=null==t?0:t.length;for(this.clear();++e<r;){var n=t[e];this.set(n[0],n[1])}}function Bt(t,e){var r,n,i=t.__data__;return("string"==(n=typeof(r=e))||"number"==n||"symbol"==n||"boolean"==n?"__proto__"!==r:null===r)?i["string"==typeof e?"string":"hash"]:i.map}function It(t){var e=-1,r=null==t?0:t.length;for(this.clear();++e<r;){var n=t[e];this.set(n[0],n[1])}}Rt.prototype.clear=function(){this.__data__=Pt?Pt(null):{},this.size=0},Rt.prototype.delete=function(t){var e=this.has(t)&&delete this.__data__[t];return this.size-=e?1:0,e},Rt.prototype.get=function(t){var e=this.__data__;if(Pt){var r=e[t];return"__lodash_hash_undefined__"===r?void 0:r}return jt.call(e,t)?e[t]:void 0},Rt.prototype.has=function(t){var e=this.__data__;return Pt?void 0!==e[t]:Mt.call(e,t)},Rt.prototype.set=function(t,e){var r=this.__data__;return this.size+=this.has(t)?0:1,r[t]=Pt&&void 0===e?"__lodash_hash_undefined__":e,this},It.prototype.clear=function(){this.size=0,this.__data__={hash:new Rt,map:new(At||J),string:new Rt}},It.prototype.delete=function(t){var e=Bt(this,t).delete(t);return this.size-=e?1:0,e},It.prototype.get=function(t){return Bt(this,t).get(t)},It.prototype.has=function(t){return Bt(this,t).has(t)},It.prototype.set=function(t,e){var r=Bt(this,t),n=r.size;return r.set(t,e),this.size+=r.size==n?0:1,this};function Ft(t){var e=this.__data__=new J(t);this.size=e.size}Ft.prototype.clear=function(){this.__data__=new J,this.size=0},Ft.prototype.delete=function(t){var e=this.__data__,r=e.delete(t);return this.size=e.size,r},Ft.prototype.get=function(t){return this.__data__.get(t)},Ft.prototype.has=function(t){return this.__data__.has(t)},Ft.prototype.set=function(t,e){var r=this.__data__;if(r instanceof J){var n=r.__data__;if(!At||n.length<199)return n.push([t,e]),this.size=++r.size,this;r=this.__data__=new It(n)}return r.set(t,e),this.size=r.size,this};var Lt=function(){try{var t=Ct(Object,"defineProperty");return t({},"",{}),t}catch(t){}}();function Dt(t,e,r){"__proto__"==e&&Lt?Lt(t,e,{configurable:!0,enumerable:!0,value:r,writable:!0}):t[e]=r}var kt=Object.prototype.hasOwnProperty;function Ut(t,e,r){var n=t[e];kt.call(t,e)&&W(n,r)&&(void 0!==r||e in t)||Dt(t,e,r)}function Gt(t,e,r,n){var i=!r;r||(r={});for(var o=-1,s=e.length;++o<s;){var a=e[o],c=n?n(r[a],t[a],a,r,t):void 0;void 0===c&&(c=t[a]),i?Dt(r,a,c):Ut(r,a,c)}return r}function Nt(t){return null!=t&&"object"==typeof t}function $t(t){return Nt(t)&&"[object Arguments]"==ht(t)}var Xt=Object.prototype,Yt=Xt.hasOwnProperty,Ht=Xt.propertyIsEnumerable,Wt=$t(function(){return arguments}())?$t:function(t){return Nt(t)&&Yt.call(t,"callee")&&!Ht.call(t,"callee")},Vt=Array.isArray;var qt="object"==typeof exports&&exports&&!exports.nodeType&&exports,Jt=qt&&"object"==typeof module&&module&&!module.nodeType&&module,Kt=Jt&&Jt.exports===qt?Z.Buffer:void 0,Qt=(Kt?Kt.isBuffer:void 0)||function(){return!1},Zt=9007199254740991,te=/^(?:0|[1-9]\d*)$/;function ee(t,e){var r=typeof t;return!!(e=null==e?Zt:e)&&("number"==r||"symbol"!=r&&te.test(t))&&t>-1&&t%1==0&&t<e}var re=9007199254740991;function ne(t){return"number"==typeof t&&t>-1&&t%1==0&&t<=re}var ie={};function oe(t){return function(e){return t(e)}}ie["[object Float32Array]"]=ie["[object Float64Array]"]=ie["[object Int8Array]"]=ie["[object Int16Array]"]=ie["[object Int32Array]"]=ie["[object Uint8Array]"]=ie["[object Uint8ClampedArray]"]=ie["[object Uint16Array]"]=ie["[object Uint32Array]"]=!0,ie["[object Arguments]"]=ie["[object Array]"]=ie["[object ArrayBuffer]"]=ie["[object Boolean]"]=ie["[object DataView]"]=ie["[object Date]"]=ie["[object Error]"]=ie["[object Function]"]=ie["[object Map]"]=ie["[object Number]"]=ie["[object Object]"]=ie["[object RegExp]"]=ie["[object Set]"]=ie["[object String]"]=ie["[object WeakMap]"]=!1;var se="object"==typeof exports&&exports&&!exports.nodeType&&exports,ae=se&&"object"==typeof module&&module&&!module.nodeType&&module,ce=ae&&ae.exports===se&&K.process,he=function(){try{var t=ae&&ae.require&&ae.require("util").types;return t||ce&&ce.binding&&ce.binding("util")}catch(t){}}(),ue=he&&he.isTypedArray,le=ue?oe(ue):function(t){return Nt(t)&&ne(t.length)&&!!ie[ht(t)]},pe=Object.prototype.hasOwnProperty;function fe(t,e){var r=Vt(t),n=!r&&Wt(t),i=!r&&!n&&Qt(t),o=!r&&!n&&!i&&le(t),s=r||n||i||o,a=s?function(t,e){for(var r=-1,n=Array(t);++r<t;)n[r]=e(r);return n}(t.length,String):[],c=a.length;for(var h in t)!e&&!pe.call(t,h)||s&&("length"==h||i&&("offset"==h||"parent"==h)||o&&("buffer"==h||"byteLength"==h||"byteOffset"==h)||ee(h,c))||a.push(h);return a}var de=Object.prototype;function ye(t){var e=t&&t.constructor;return t===("function"==typeof e&&e.prototype||de)}function xe(t,e){return function(r){return t(e(r))}}var ge=xe(Object.keys,Object),me=Object.prototype.hasOwnProperty;function ve(t){return null!=t&&ne(t.length)&&!yt(t)}function be(t){return ve(t)?fe(t):function(t){if(!ye(t))return ge(t);var e=[];for(var r in Object(t))me.call(t,r)&&"constructor"!=r&&e.push(r);return e}(t)}var _e=Object.prototype.hasOwnProperty;function we(t){if(!ut(t))return function(t){var e=[];if(null!=t)for(var r in Object(t))e.push(r);return e}(t);var e=ye(t),r=[];for(var n in t)("constructor"!=n||!e&&_e.call(t,n))&&r.push(n);return r}function Te(t){return ve(t)?fe(t,!0):we(t)}var Ee="object"==typeof exports&&exports&&!exports.nodeType&&exports,ze=Ee&&"object"==typeof module&&module&&!module.nodeType&&module,Se=ze&&ze.exports===Ee?Z.Buffer:void 0,Oe=Se?Se.allocUnsafe:void 0;function Ce(){return[]}var Ae=Object.prototype.propertyIsEnumerable,Pe=Object.getOwnPropertySymbols,je=Pe?function(t){return null==t?[]:(t=Object(t),function(t,e){for(var r=-1,n=null==t?0:t.length,i=0,o=[];++r<n;){var s=t[r];e(s,r,t)&&(o[i++]=s)}return o}(Pe(t),(function(e){return Ae.call(t,e)})))}:Ce;function Me(t,e){for(var r=-1,n=e.length,i=t.length;++r<n;)t[i+r]=e[r];return t}var Re=xe(Object.getPrototypeOf,Object),Be=Object.getOwnPropertySymbols?function(t){for(var e=[];t;)Me(e,je(t)),t=Re(t);return e}:Ce;function Ie(t,e,r){var n=e(t);return Vt(t)?n:Me(n,r(t))}function Fe(t){return Ie(t,be,je)}function Le(t){return Ie(t,Te,Be)}var De=Ct(Z,"DataView"),ke=Ct(Z,"Promise"),Ue=Ct(Z,"Set"),Ge=Ct(Z,"WeakMap"),Ne="[object Map]",$e="[object Promise]",Xe="[object Set]",Ye="[object WeakMap]",He="[object DataView]",We=bt(De),Ve=bt(At),qe=bt(ke),Je=bt(Ue),Ke=bt(Ge),Qe=ht;(De&&Qe(new De(new ArrayBuffer(1)))!=He||At&&Qe(new At)!=Ne||ke&&Qe(ke.resolve())!=$e||Ue&&Qe(new Ue)!=Xe||Ge&&Qe(new Ge)!=Ye)&&(Qe=function(t){var e=ht(t),r="[object Object]"==e?t.constructor:void 0,n=r?bt(r):"";if(n)switch(n){case We:return He;case Ve:return Ne;case qe:return $e;case Je:return Xe;case Ke:return Ye}return e});var Ze=Qe,tr=Object.prototype.hasOwnProperty;var er=Z.Uint8Array;function rr(t){var e=new t.constructor(t.byteLength);return new er(e).set(new er(t)),e}var nr=/\w*$/;var ir=tt?tt.prototype:void 0,or=ir?ir.valueOf:void 0;var sr="[object Boolean]",ar="[object Date]",cr="[object Map]",hr="[object Number]",ur="[object RegExp]",lr="[object Set]",pr="[object String]",fr="[object Symbol]",dr="[object ArrayBuffer]",yr="[object DataView]",xr="[object Float32Array]",gr="[object Float64Array]",mr="[object Int8Array]",vr="[object Int16Array]",br="[object Int32Array]",_r="[object Uint8Array]",wr="[object Uint8ClampedArray]",Tr="[object Uint16Array]",Er="[object Uint32Array]";function zr(t,e,r){var n,i,o,s=t.constructor;switch(e){case dr:return rr(t);case sr:case ar:return new s(+t);case yr:return function(t,e){var r=e?rr(t.buffer):t.buffer;return new t.constructor(r,t.byteOffset,t.byteLength)}(t,r);case xr:case gr:case mr:case vr:case br:case _r:case wr:case Tr:case Er:return function(t,e){var r=e?rr(t.buffer):t.buffer;return new t.constructor(r,t.byteOffset,t.length)}(t,r);case cr:return new s;case hr:case pr:return new s(t);case ur:return(o=new(i=t).constructor(i.source,nr.exec(i))).lastIndex=i.lastIndex,o;case lr:return new s;case fr:return n=t,or?Object(or.call(n)):{}}}var Sr=Object.create,Or=function(){function t(){}return function(e){if(!ut(e))return{};if(Sr)return Sr(e);t.prototype=e;var r=new t;return t.prototype=void 0,r}}();var Cr=he&&he.isMap,Ar=Cr?oe(Cr):function(t){return Nt(t)&&"[object Map]"==Ze(t)};var Pr=he&&he.isSet,jr=Pr?oe(Pr):function(t){return Nt(t)&&"[object Set]"==Ze(t)},Mr=1,Rr=2,Br=4,Ir="[object Arguments]",Fr="[object Function]",Lr="[object GeneratorFunction]",Dr="[object Object]",kr={};function Ur(t,e,r,n,i,o){var s,a=e&Mr,c=e&Rr,h=e&Br;if(r&&(s=i?r(t,n,i,o):r(t)),void 0!==s)return s;if(!ut(t))return t;var u=Vt(t);if(u){if(s=function(t){var e=t.length,r=new t.constructor(e);return e&&"string"==typeof t[0]&&tr.call(t,"index")&&(r.index=t.index,r.input=t.input),r}(t),!a)return function(t,e){var r=-1,n=t.length;for(e||(e=Array(n));++r<n;)e[r]=t[r];return e}(t,s)}else{var l=Ze(t),p=l==Fr||l==Lr;if(Qt(t))return function(t,e){if(e)return t.slice();var r=t.length,n=Oe?Oe(r):new t.constructor(r);return t.copy(n),n}(t,a);if(l==Dr||l==Ir||p&&!i){if(s=c||p?{}:function(t){return"function"!=typeof t.constructor||ye(t)?{}:Or(Re(t))}(t),!a)return c?function(t,e){return Gt(t,Be(t),e)}(t,function(t,e){return t&&Gt(e,Te(e),t)}(s,t)):function(t,e){return Gt(t,je(t),e)}(t,function(t,e){return t&&Gt(e,be(e),t)}(s,t))}else{if(!kr[l])return i?t:{};s=zr(t,l,a)}}o||(o=new Ft);var f=o.get(t);if(f)return f;o.set(t,s),jr(t)?t.forEach((function(n){s.add(Ur(n,e,r,n,t,o))})):Ar(t)&&t.forEach((function(n,i){s.set(i,Ur(n,e,r,i,t,o))}));var d=u?void 0:(h?c?Le:Fe:c?Te:be)(t);return function(t,e){for(var r=-1,n=null==t?0:t.length;++r<n&&!1!==e(t[r],r,t););}(d||t,(function(n,i){d&&(n=t[i=n]),Ut(s,i,Ur(n,e,r,i,t,o))})),s}kr[Ir]=kr["[object Array]"]=kr["[object ArrayBuffer]"]=kr["[object DataView]"]=kr["[object Boolean]"]=kr["[object Date]"]=kr["[object Float32Array]"]=kr["[object Float64Array]"]=kr["[object Int8Array]"]=kr["[object Int16Array]"]=kr["[object Int32Array]"]=kr["[object Map]"]=kr["[object Number]"]=kr[Dr]=kr["[object RegExp]"]=kr["[object Set]"]=kr["[object String]"]=kr["[object Symbol]"]=kr["[object Uint8Array]"]=kr["[object Uint8ClampedArray]"]=kr["[object Uint16Array]"]=kr["[object Uint32Array]"]=!0,kr["[object Error]"]=kr[Fr]=kr["[object WeakMap]"]=!1;function Gr(t){return t}var Nr=Math.max;var $r=Lt?function(t,e){return Lt(t,"toString",{configurable:!0,enumerable:!1,value:(r=e,function(){return r}),writable:!0});var r}:Gr,Xr=$r,Yr=Date.now;var Hr,Wr,Vr,qr=(Hr=Xr,Wr=0,Vr=0,function(){var t=Yr(),e=16-(t-Vr);if(Vr=t,e>0){if(++Wr>=800)return arguments[0]}else Wr=0;return Hr.apply(void 0,arguments)});var Jr=Object.prototype,Kr=Jr.hasOwnProperty,Qr=function(t,e){return qr(function(t,e,r){return e=Nr(void 0===e?t.length-1:e,0),function(){for(var n=arguments,i=-1,o=Nr(n.length-e,0),s=Array(o);++i<o;)s[i]=n[e+i];i=-1;for(var a=Array(e+1);++i<e;)a[i]=n[i];return a[e]=r(s),function(t,e,r){switch(r.length){case 0:return t.call(e);case 1:return t.call(e,r[0]);case 2:return t.call(e,r[0],r[1]);case 3:return t.call(e,r[0],r[1],r[2])}return t.apply(e,r)}(t,this,a)}}(t,e,Gr),t+"")}((function(t,e){t=Object(t);var r=-1,n=e.length,i=n>2?e[2]:void 0;for(i&&function(t,e,r){if(!ut(r))return!1;var n=typeof e;return!!("number"==n?ve(r)&&ee(e,r.length):"string"==n&&e in r)&&W(r[e],t)}(e[0],e[1],i)&&(n=1);++r<n;)for(var o=e[r],s=Te(o),a=-1,c=s.length;++a<c;){var h=s[a],u=t[h];(void 0===u||W(u,Jr[h])&&!Kr.call(t,h))&&(t[h]=o[h])}return t}));class Zr{constructor(t,r={}){if(this.mode=null,this.texture=null,this.target=null,this.targetCanvas=null,this.textureScaleX=1,this.textureScaleY=1,this.curvePathMap=new WeakMap,this.pathCurveMap=new WeakMap,this.records={undo:[],redo:[]},void 0===e)throw new Error("[Fabric-Texture Error] fabric.js is required for FabricTexture class.\nPlease install and import fabric.js first.");if(!(t instanceof e.Canvas))throw new Error("[Fabric-Texture Error] Invalid canvas parameter.\nPlease provide a valid fabric.Canvas instance.");this.canvas=t,this.options=Qr(r,{history:!1,onHistoryChange:()=>{}})}render(t=!0,r={}){var n,i;if(!this.texture)return;if(!this.target)return;const o=this.canvas;if(!o)return;const s=this.target;if(!s)return;o.renderOnAddRemove=!1,t&&this._dirtyRenderReturnCallback&&(this._dirtyRenderReturnCallback(),this._dirtyRenderReturnCallback=void 0),this._renderReturnCallback&&(this._renderReturnCallback(),this._renderReturnCallback=void 0);const a=this.texture.create();r.withoutRecord||this.record();const c=[],h=new WeakMap,u=new WeakMap,l=this.texture.mesh.length,p=this.texture.mesh[0].length;for(let t=0;t<l;t++)for(let r=0;r<p;r++){const n=this.texture.mesh[t][r];Object.values(n).forEach((t=>{const r=t.length;for(let n=0;n<r;n++){const r=t[n];if(h.has(r))continue;const i=new e.Path(r.toSVG());c.push(i),h.set(r,i),u.set(i,r)}}))}const f=new e.Group(c),{width:d=0,height:y=0}=f,{left:x=0,top:g=0}=f,m={left:x,right:x+d,top:g,bottom:g+y};this.textureBoundary||(this.textureBoundary=m,this.textureScaleX=this.targetCanvas.width/a.width*this.texture.scale.x,this.textureScaleY=this.targetCanvas.height/a.height*this.texture.scale.y);const v=this.textureBoundary?{x:(m.right+m.left)/2-(this.textureBoundary.right+this.textureBoundary.left)/2,y:(m.bottom+m.top)/2-(this.textureBoundary.bottom+this.textureBoundary.top)/2}:{x:0,y:0},b=e.util.transformPoint(new e.Point(v.x*this.textureScaleX,v.y*this.textureScaleY),s.calcOwnMatrix(),!0),_=s.getCenterPoint(),w={left:_.x+b.x,top:_.y+b.y,angle:s.angle,scaleX:s.scaleX*this.textureScaleX,scaleY:s.scaleY*this.textureScaleY,flipX:s.flipX,flipY:s.flipY,originX:"center",originY:"center"};f.set(w),f.destroy();const T=Object.assign(Object.assign({},w),{opacity:s.opacity,globalCompositeOperation:s.globalCompositeOperation,scaleX:w.scaleX/(a.width/d),scaleY:w.scaleY/(a.height/y),selectable:!1});let E=this.textureObject;E?E.setElement(a,T):E=new e.Image(a,T),this.textureObject=E,this.paths=c,this.pathCurveMap=u,this.curvePathMap=h,this._renderReturnCallback=null===(n=this.mode)||void 0===n?void 0:n.render(this),t&&(this._dirtyRenderReturnCallback=null===(i=this.mode)||void 0===i?void 0:i.dirtyRender(this)),o.renderOnAddRemove=!0,o.requestRenderAll()}requestRender(t=!0,e,r={}){this._nextFrameRender&&window.cancelAnimationFrame(this._nextFrameRender),this._nextFrameRender=window.requestAnimationFrame((()=>{this.render(t,r),e&&e(),this._nextFrameRender=void 0}))}serialize(){const t=this.texture;if(!t)return null;const e=t.getTransformData();return{data:e,compressedData:H.compressTransformData(e)}}enterEditing(t,e,r,n){if(!this.canvas)return;if(this.target)throw Error("[Fabric-Texture Error] You must continue editing after completing the previous task.");this.target=t,this.mode=r,this.canvas.discardActiveObject();const{opacity:i,visible:o,angle:s,flipX:a,flipY:c,scaleX:h,scaleY:u}=this.target.toJSON();this.target.set({opacity:1,visible:!0,angle:0,scaleX:1,scaleY:1,flipX:!1,flipY:!1}),this.targetCanvas=this.target.toCanvasElement(),this.target.set({opacity:i,visible:o,angle:s,flipX:a,flipY:c,scaleX:h,scaleY:u});const l=null!=e?e:this.targetCanvas,p=new H(l);p.setInputLimitSize({width:2e3,height:2e3}).useInstanceCanvas().setSplitStrategy({name:this.mode.name,execute:this.mode.execute.bind(this.mode)}),this.texture=p,null==n||n(p),this.render()}leaveEditing(){if(!this.target)return;const t=this.canvas;t&&(t.renderOnAddRemove=!1,this._dirtyRenderReturnCallback&&(this._dirtyRenderReturnCallback(),this._dirtyRenderReturnCallback=void 0),this._renderReturnCallback&&(this._renderReturnCallback(),this._renderReturnCallback=void 0),t.renderOnAddRemove=!0,t.requestRenderAll(),this.target=null,this.texture=null,this.textureBoundary=void 0,this.textureScaleX=1,this.textureScaleY=1,this.textureObject=void 0,this.paths=void 0,this.pathCurveMap=new WeakMap,this.curvePathMap=new WeakMap,this.mode=null,this.records.undo.length=0,this.records.redo.length=0)}record(){this.texture&&(this.options.history&&(this.records.redo.length=0,this.records.undo.push(Ur(this.texture.getTransformData(),5)),this.options.onHistoryChange(this.records)))}undo(){if(!this.texture)return;const t=this.records.undo.length;if(t<=1)return;this.records.redo.unshift(this.records.undo.pop());const e=this.records.undo[t-2];this.texture.setTransformData(e.splitRatioPoints,e.areaBound),this.render(!0,{withoutRecord:!0}),this.options.onHistoryChange(this.records)}redo(){if(!this.texture)return;const t=this.records.redo.shift();t&&(this.records.undo.push(t),this.texture.setTransformData(t.splitRatioPoints,t.areaBound),this.render(!0,{withoutRecord:!0}),this.options.onHistoryChange(this.records))}reset(t=!0){const e=this.texture;if(e)if(t){if(e.isNoneTransform())return;e.resetTransformData(),this.render(!0)}else{const t=this.records.undo.length;for(let e=1;e<t;e++){const t=this.records.undo.pop();this.records.redo.unshift(t)}const r=this.records.undo[0];r&&(e.setTransformData(r.splitRatioPoints,r.areaBound),this.render(!0,{withoutRecord:!0})),this.options.onHistoryChange(this.records)}}}class tn{execute(t){return t.splitStrategy.execute(t)}render(t){const e=t.canvas;if(!e)return;const{textureObject:r}=t;return r&&e.add(r),()=>{r&&e.remove(r)}}dirtyRender(t){}}export{tn as AbstractMode,Zr as FabricTexture,H as Texture,B as utils};
//# sourceMappingURL=index.esm.js.map