fabric-texture
Version:
This JavaScript library enables fast and efficient image distortion transformations using Canvas 2D.
3 lines • 71.8 kB
JavaScript
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("fabric")):"function"==typeof define&&define.amd?define(["exports","fabric"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).FabricTexture={},t.fabric)}(this,(function(e,r){"use strict";function n(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:i,cos:o,sin:s,acos:a,atan2:c,sqrt:h,pow:u}=Math;function l(t){return t<0?-u(-t,1/3):u(t,1/3)}const f=Math.PI,p=2*f,d=f/2,y=Number.MAX_SAFE_INTEGER||9007199254740991,x=Number.MIN_SAFE_INTEGER||-9007199254740991,g={x:0,y:0,z:0},m={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),h(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],g],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||m.approximately(t,e)||m.approximately(t,r)},approximately:function(t,e,r){return i(t-e)<=(r||1e-6)},length:function(t){const e=m.Tvalues.length;let r=0;for(let n,i=0;i<e;i++)n=.5*m.Tvalues[i]+.5,r+=m.Cvalues[i]*m.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(m.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 c(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 h(r*r+n*n)},closest:function(t,e){let r,n,i=u(2,63);return t.forEach((function(t,o){n=m.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=u(t,e)+u(1-t,e);return i((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=u(1-t,e);return r/(u(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 m.lli8(i,o,s,a,c,h,u,l)},lli:function(t,e){return m.lli4(t,t.c,e,e.c)},makeline:function(t,e){return new C(t.x,t.y,(t.x+e.x)/2,(t.y+e.y)/2,e.x,e.y)},findbbox:function(t){let e=y,r=y,n=x,i=x;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(!m.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=m.makeline(e.points[n-1],t.points[0]),s=m.makeline(t.points[i-1],e.points[0]),a={startcap:o,forward:t,back:e,endcap:s,bbox:m.findbbox([o,t,e,s]),intersections:function(t){return m.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=y,s=x;-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,i=-c(e.p2.y-n,e.p2.x-r);return t.map((function(t){return{x:(t.x-r)*o(i)-(t.y-n)*s(i),y:(t.x-r)*s(i)+(t.y-n)*o(i)}}))},roots:function(t,e){e=e||{p1:{x:0,y:0},p2:{x:1,y:0}};const r=t.length-1,n=m.align(t,e),i=function(t){return 0<=t&&t<=1};if(2===r){const t=n[0].y,e=n[1].y,r=n[2].y,o=t-2*e+r;if(0!==o){const n=-h(e*e-t*r),s=-t+e;return[-(n+s)/o,-(-n+s)/o].filter(i)}return e!==r&&0===o?[(2*e-r)/(2*e-2*r)].filter(i):[]}const s=n[0].y,c=n[1].y,u=n[2].y;let f=3*c-s-3*u+n[3].y,d=3*s-6*c+3*u,y=-3*s+3*c,x=s;if(m.approximately(f,0)){if(m.approximately(d,0))return m.approximately(y,0)?[]:[-x/y].filter(i);const t=h(y*y-4*d*x),e=2*d;return[(t-y)/e,(-y-t)/e].filter(i)}d/=f,y/=f,x/=f;const g=(3*y-d*d)/3,b=g/3,v=(2*d*d*d-9*d*y+27*x)/27,_=v/2,w=_*_+b*b*b;let T,E,z,S,O;if(w<0){const t=-g/3,e=h(t*t*t),r=-v/(2*e),n=a(r<-1?-1:r>1?1:r),s=2*l(e);return z=s*o(n/3)-d/3,S=s*o((n+p)/3)-d/3,O=s*o((n+2*p)/3)-d/3,[z,S,O].filter(i)}if(0===w)return T=_<0?l(-_):-l(_),z=2*T-d/3,S=-T-d/3,[z,S].filter(i);{const t=h(w);return T=l(-_+t),E=l(_+t),[T-E-d/3].filter(i)}},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=-h(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,n,o){let s,a,c,l,f=0,p=0;const d=m.compute(t,e),y=m.compute(t,r),x=d.x*d.x+d.y*d.y;if(n?(s=h(u(d.y*y.z-y.y*d.z,2)+u(d.z*y.x-y.z*d.x,2)+u(d.x*y.y-y.x*d.y,2)),a=u(x+d.z*d.z,1.5)):(s=d.x*y.y-d.y*y.x,a=u(x,1.5)),0===s||0===a)return{k:0,r:0};if(f=s/a,p=a/s,!o){const o=m.curvature(t-.001,e,r,n,!0).k,s=m.curvature(t+.001,e,r,n,!0).k;l=(s-f+(f-o))/2,c=(i(s-f)+i(f-o))/2}return{k:f,r:p,dk:l,adk:c}},inflections:function(t){if(t.length<4)return[];const e=m.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(m.approximately(o,0)){if(!m.approximately(s,0)){let t=-a/s;if(0<=t&&t<=1)return[t]}return[]}const c=2*o;if(m.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"],n=r.length;for(let o,s,a,c,h=0;h<n;h++)if(o=r[h],s=t[o].mid,a=e[o].mid,c=(t[o].size+e[o].size)/2,i(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 m.bboxoverlap(t.left.bbox(),t.right.bbox())}));let u=[];return 0===h.length||(h.forEach((function(t){u=u.concat(m.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,i=e.y-t.y,a=r.x-e.x,h=r.y-e.y,u=n*o(d)-i*s(d),l=n*s(d)+i*o(d),f=a*o(d)-h*s(d),y=a*s(d)+h*o(d),x=(t.x+e.x)/2,g=(t.y+e.y)/2,b=(e.x+r.x)/2,v=(e.y+r.y)/2,_=x+u,w=g+l,T=b+f,E=v+y,z=m.lli8(x,g,_,w,b,v,T,E),S=m.dist(z,t);let O,C=c(t.y-z.y,t.x-z.x),A=c(e.y-z.y,e.x-z.x),P=c(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 b{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 m.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++)m.expandbox(e,t[r].bbox());return e}offset(t){const e=[];return this.curves.forEach((function(r){e.push(...r.offset(t))})),new b(e)}}const{abs:v,min:_,max:w,cos:T,sin:E,acos:z,sqrt:S}=Math,O=Math.PI;class C{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=m.align(s,{p1:s[0],p2:s[c]}),l=m.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 C(e,e,r);if(1===n)return new C(t,e,e);const i=C.getABC(2,t,e,r,n);return new C(t,i.A,r)}static cubicFromPoints(t,e,r,n,i){void 0===n&&(n=.5);const o=C.getABC(3,t,e,r,n);void 0===i&&(i=m.dist(e,o.C));const s=i*(1-n)/n,a=m.dist(t,r),c=(r.x-t.x)/a,h=(r.y-t.y)/a,u=i*c,l=i*h,f=s*c,p=s*h,d=e.x-u,y=e.y-l,x=e.x+f,g=e.y+p,b=o.A,v=b.x+(d-b.x)/(1-n),_=b.y+(y-b.y)/(1-n),w=b.x+(x-b.x)/n,T=b.y+(g-b.y)/n,E={x:t.x+(v-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 C(t,E,z,r)}static getUtils(){return m}getUtils(){return C.getUtils()}static get PolyBezier(){return b}valueOf(){return this.toString()}toString(){return m.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=m.derive(this.points,this._3d),this.computedirection()}computedirection(){const t=this.points,e=m.angle(t[0],t[this.order],t[1]);this.clockwise=e>0}length(){return m.length(this.derivative.bind(this))}static getABC(t=2,e,r,n,i=.5){const o=m.projectionratio(i,t),s=1-o,a={x:o*e.x+s*n.x,y:o*e.y+s*n.y},c=m.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 C.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],m.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=m.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=m.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?m.computeWithRatios(t,this.points,this.ratios,this._3d):m.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 C(e)}derivative(t){return m.compute(t,this.dpoints[0],this._3d)}dderivative(t){return m.compute(t,this.dpoints[1],this._3d)}align(){let t=this.points;return new C(m.align(t,{p1:t[0],p2:t[t.length-1]}))}curvature(t){return m.curvature(t,this.dpoints[0],this.dpoints[1],this._3d)}inflections(){return m.inflections(this.points)}normal(t){return this._3d?this.__normal3(t):this.__normal2(t)}__normal2(t){const e=this.derivative(t),r=S(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=S(e.x*e.x+e.y*e.y+e.z*e.z),i=S(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=S(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=m.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 C([r[0],r[3],r[5]]):new C([r[0],r[4],r[7],r[9]]),right:2===this.order?new C([r[5],r[4],r[2]]):new C([r[9],r[8],r[6],r[3]]),span:r};return n.left._t1=m.map(0,0,1,this._t1,this._t2),n.left._t2=m.map(t,0,1,this._t1,this._t2),n.right._t1=m.map(t,0,1,this._t1,this._t2),n.right._t2=m.map(1,0,1,this._t1,this._t2),e?(e=m.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]=m.droots(i),3===this.order&&(i=this.dpoints[1].map(n),t[r]=t[r].concat(m.droots(i))),t[r]=t[r].filter((function(t){return t>=0&&t<=1})),e=e.concat(t[r].sort(m.numberSort))}.bind(this)),t.values=e.sort(m.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]=m.getminmax(this,r,t[r])}.bind(this)),e}overlaps(t){const e=this.bbox(),r=t.bbox();return m.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 C(r)]}return this.reduce().map((function(e){return e._linear?e.offset(t)[0]:e.scale(t)}))}simple(){if(3===this.order){const t=m.angle(this.points[0],this.points[3],this.points[1]),e=m.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(z(r))<O/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=m.map(r,0,1,t._t1,t._t2),e._t2=m.map(n,0,1,t._t1,t._t2),s.push(e),r=n;break}r<1&&(e=t.split(r,1),e._t1=m.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 C(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=m.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]=m.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=S(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 C(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]=m.lli4(r,o,h,i[t+1])})),new C(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],f=m.makeline(l[2],u[0]),p=m.makeline(u[2],l[0]),d=[f,new C(u),p,new C(l)];return new b(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 f(t,e,r,n,i){return function(o){const s=n/r,a=(n+i)/r,c=e-t;return m.map(o,0,1,t+s*c,t+a*c)}}i.forEach((function(i){const o=i.length();l?(s.push(i.scale(f(t,r,u,h,o))),c.push(i.scale(f(-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 p=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],g=m.makeline(y,p),v=m.makeline(d,x),_=[g].concat(s).concat([v]).concat(c);return new b(_)}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=m.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 C&&(t=t.reduce()),this.curveintersects(this.reduce(),t,e)):this.selfintersects(e)}lineIntersects(t){const e=_(t.p1.x,t.p2.x),r=_(t.p1.y,t.p2.y),n=w(t.p1.x,t.p2.x),i=w(t.p1.y,t.p2.y);return m.roots(this.points,t).filter((t=>{var o=this.get(t);return m.between(o.x,e,n)&&m.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=m.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=m.dist(t,e),c=m.dist(t,o),h=m.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,f=!1,p=i,d=1;do{if(f=l,c=a,p=(n+i)/2,o=this.get(p),s=this.get(i),a=m.getccenter(u,o,s),a.interval={start:n,end:i},l=this._error(a,u,n,i)<=t,h=f&&!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*T(a.e),y:a.y+a.r*E(a.e)};a.e+=m.angle({x:a.x,y:a.y},t,this.get(1))}break}i+=(i-n)/2}else i=p}while(!h&&r++<100);if(r>=100)break;c=c||a,e.push(c),n=d}while(i<1);return e}}const A=(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}},P=(t,e)=>Math.sqrt(Math.pow(e.x-t.x,2)+Math.pow(e.y-t.y,2)),j=(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}},M=(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},R=(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,f,p,d]=r.map(Number),y=o-i*h/c,x=h-c*p/f,g=u-c*d/f,m=a-c*l/f,b=(y/x*g-(s-i*u/c))/(y/x*m-(n-i*a/c)),v=(g-m*b)/x;return{x:b,y:(s-n*b-o*v)/i,z:v}},u=[o.x+c,o.y+c,1,r.x+c],l=[s.x+c,s.y+c,1,n.x+c],f=[a.x+c,a.y+c,1,i.x+c],p=h(u,l,f);u[3]=r.y+c,l[3]=n.y+c,f[3]=i.y+c;const d=h(u,l,f),y=p.x,x=p.y,g=p.z;return[y,d.x,x,d.y,g,d.z]},B=(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 I=Object.freeze({__proto__:null,calcBoundingBox:j,calcCoordDistance:P,calcExpandCoord:(t,e,r,n=1)=>{const i=A(e,r,t),o=P(t,i),s=M(t,i,o+n);return{x:s.x-i.x+e.x,y:s.y-i.y+e.y}},calcFabricCanvasCoord:(t,e)=>{var n;const i=null!==(n=t.viewportTransform)&&void 0!==n?n:[1,0,0,1,0,0];return r.fabric.util.transformPoint(new r.fabric.Point(e.x,e.y),r.fabric.util.invertTransform(i))},calcFabricRelativeCoord:(t,e)=>{const{left:n=0,top:i=0}=t;if("path"===e.type){const t=e,o=t.calcOwnMatrix(),s=r.fabric.util.transformPoint(t.pathOffset,o,!0);return r.fabric.util.transformPoint(new r.fabric.Point(n+s.x,i+s.y),r.fabric.util.invertTransform(o))}const o=e.calcOwnMatrix();return r.fabric.util.transformPoint(new r.fabric.Point(n,i),r.fabric.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:R,calcPerpendicularIntersection:A,calcRelativeCoord:M,isTriangleContainsPoint:B});const F=(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:f=!1,showGridDot:p=!1}=null!==(o=t.renderOptions)&&void 0!==o?o:{},{calcBoundingBox:d,calcPerpendicularIntersection:y,calcCoordDistance:x,calcRelativeCoord:g,calcMatrix:m}=i,b=(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}},v=r.getContext("2d");v.clearRect(0,0,r.width,r.height);const _=Math.ceil(1/(c*h));v.save(),v.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=b(e,r,n,_),o=b(e,n,r,_);y.lineTo(i.x,i.y),y.lineTo(o.x,o.y)}if(l){v.save(),v.clip(y);const h=m([t,n,o],[r,i,s]);v.transform(...h);const u=d(r,i,s),l=(a.x-1)*c,f=(a.y-1)*c,p=(u.width+2)*c,x=(u.height+2)*c,g=a.x-1/c,b=a.y-1/c,_=u.width+2/c,w=u.height+2/c;v.drawImage(e,l,f,p,x,g,b,_,w),v.restore()}if(p){const e=Math.floor(2/c);v.fillStyle=`rgba(${u.r}, ${u.g}, ${u.b}, ${u.a})`,v.fillRect(t.x-e/2,t.y-e/2,e,e)}if(f){const t=Math.floor(1/c);v.lineWidth=t,v.strokeStyle="rgba(255, 0, 0, 0.5)",v.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],f=t.initialMeshPoints[r][n][s+1],p=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,f,u,d,l),w(h,p,c,f,u,d,l))}))}))})),v.restore(),r},L=(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 F(t,e,r,n,{calcBoundingBox:j,calcPerpendicularIntersection:A,calcCoordDistance:P,calcRelativeCoord:M,calcMatrix:R})},D=(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:f=!0,showGrid:p=!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],f=t.initialMeshPoints[r][n][s+1],p=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,f,d,p,f,d),m.after.push(a,c,u,h,c,u))}))}))}));const b="\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 ",v=(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=v(g.VERTEX_SHADER,t);if(!r)return console.error("Failed to initialize vertex shader."),null;const n=v(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=_(b,"\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),f&&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=_(b,`\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),p&&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},k=(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 D(t,e,r,n)},U="WORKER_MESSAGE",G="JOB_RESULT",N=t=>t instanceof ArrayBuffer||t instanceof MessagePort||self.ImageBitmap&&t instanceof ImageBitmap,$=()=>{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 = ${N}\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: '${U}', message }),\n close: self.close,\n }]))\n ).then(result => {\n postMessage({ type: '${G}', message: { index, result } }, [result].filter($isTransferables))\n }).catch(error => {\n postMessage({ type: '${G}', 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===U&&e&&e.call(e,n.message),n.type===G){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(N))})),terminate:()=>{a.terminate(),URL.revokeObjectURL(s),t.length=0,r.clear(),e=void 0}}}};return n},X=(t,e,r,i)=>n(void 0,void 0,void 0,(function*(){const{meshPoints:n,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:n,initialMeshPoints:a},h=$().collect({texture:c,options:i,createCanvas2DTexture:F,calcBoundingBox:j,calcPerpendicularIntersection:A,calcCoordDistance:P,calcRelativeCoord:M,calcMatrix:R}).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:f=1,destinationScale:p=1}=r,d=new OffscreenCanvas(u*p*f,l*p*f),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(),(r=null!=r?r:document.createElement("canvas")).width=u.width,r.height=u.height,r.getContext("2d").drawImage(u,0,0),r})),Y=(t,e,r,i)=>n(void 0,void 0,void 0,(function*(){const{meshPoints:n,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:n,initialMeshPoints:a},h=$().collect({texture:c,options:i,createWebGLTexture:D}).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(),(r=null!=r?r:document.createElement("canvas")).width=u.width,r.height=u.height,r.getContext("2d").drawImage(u,0,0),r}));var H;!function(t){t.TOP_LEFT="tl",t.TOP_RIGHT="tr",t.BOTTOM_LEFT="bl",t.BOTTOM_RIGHT="br"}(H||(H={}));class W{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:W.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 C([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 C([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]={[H.TOP_LEFT]:["top","first"],[H.TOP_RIGHT]:["top","last"],[H.BOTTOM_LEFT]:["bottom","first"],[H.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{[H.TOP_LEFT]:[{row:t-1,col:e-1,type:H.BOTTOM_RIGHT},{row:t-1,col:e,type:H.BOTTOM_LEFT},{row:t,col:e-1,type:H.TOP_RIGHT}],[H.TOP_RIGHT]:[{row:t-1,col:e+1,type:H.BOTTOM_LEFT},{row:t,col:e+1,type:H.TOP_LEFT},{row:t-1,col:e,type:H.BOTTOM_RIGHT}],[H.BOTTOM_LEFT]:[{row:t,col:e-1,type:H.BOTTOM_RIGHT},{row:t+1,col:e,type:H.TOP_LEFT},{row:t+1,col:e-1,type:H.TOP_RIGHT}],[H.BOTTOM_RIGHT]:[{row:t,col:e+1,type:H.BOTTOM_LEFT},{row:t+1,col:e,type:H.TOP_RIGHT},{row:t+1,col:e+1,type:H.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:H.TOP_LEFT,right:H.TOP_RIGHT,bottom:H.BOTTOM_LEFT,left:H.TOP_LEFT}[r],n[0],!1),this.setVertexCoord(t,e,{top:H.TOP_RIGHT,right:H.BOTTOM_RIGHT,bottom:H.BOTTOM_RIGHT,left:H.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 C(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=B(t,r,n,o),f=B(t,i,n,o);if(l||f)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 C(t[e].left),right:new C(t[e].right),top:new C(t[e].top),bottom:new C(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],f=i[s+o+1],p=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,f],[p,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:L,webgl:k}[this.renderEngine];try{return n(this,t,e,r)}catch(n){if(this.renderOptions.safe&&"webgl"===this.renderEngine)return L(this,t,e,r);throw n}}createWithWorker(){return n(this,void 0,void 0,(function*(){const{outputCanvas:t,options:e}=this._generateCreateOptions(),r=this._getInputCanvasImageData(),n={canvas:X,webgl:Y}[this.renderEngine];try{return n(this,r,t,e)}catch(n){if(this.renderOptions.safe&&"webgl"===this.renderEngine)return Y(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 V(t,e){return t===e||t!=t&&e!=e}function q(t,e){for(var r=t.length;r--;)if(V(t[r][0],e))return r;return-1}var J=Array.prototype.splice;function K(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])}}K.prototype.clear=function(){this.__data__=[],this.size=0},K.prototype.delete=function(t){var e=this.__data__,r=q(e,t);return!(r<0)&&(r==e.length-1?e.pop():J.call(e,r,1),--this.size,!0)},K.prototype.get=function(t){var e=this.__data__,r=q(e,t);return r<0?void 0:e[r][1]},K.prototype.has=function(t){return q(this.__data__,t)>-1},K.prototype.set=function(t,e){var r=this.__data__,n=q(r,t);return n<0?(++this.size,r.push([t,e])):r[n][1]=e,this};var Q="object"==typeof global&&global&&global.Object===Object&&global,Z="object"==typeof self&&self&&self.Object===Object&&self,tt=Q||Z||Function("return this")(),et=tt.Symbol,rt=Object.prototype,nt=rt.hasOwnProperty,it=rt.toString,ot=et?et.toStringTag:void 0;var st=Object.prototype.toString;var at="[object Null]",ct="[object Undefined]",ht=et?et.toStringTag:void 0;function ut(t){return null==t?void 0===t?ct:at:ht&&ht in Object(t)?function(t){var e=nt.call(t,ot),r=t[ot];try{t[ot]=void 0;var n=!0}catch(t){}var i=it.call(t);return n&&(e?t[ot]=r:delete t[ot]),i}(t):function(t){return st.call(t)}(t)}function lt(t){var e=typeof t;return null!=t&&("object"==e||"function"==e)}var ft="[object AsyncFunction]",pt="[object Function]",dt="[object GeneratorFunction]",yt="[object Proxy]";function xt(t){if(!lt(t))return!1;var e=ut(t);return e==pt||e==dt||e==ft||e==yt}var gt,mt=tt["__core-js_shared__"],bt=(gt=/[^.]+$/.exec(mt&&mt.keys&&mt.keys.IE_PROTO||""))?"Symbol(src)_1."+gt:"";var vt=Function.prototype.toString;function _t(t){if(null!=t){try{return vt.call(t)}catch(t){}try{return t+""}catch(t){}}return""}var wt=/^\[object .+?Constructor\]$/,Tt=Function.prototype,Et=Object.prototype,zt=Tt.toString,St=Et.hasOwnProperty,Ot=RegExp("^"+zt.call(St).replace(/[\\^$.*+?()[\]{}|]/g,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$");function Ct(t){return!(!lt(t)||(e=t,bt&&bt in e))&&(xt(t)?Ot:wt).test(_t(t));var e}function At(t,e){var r=function(t,e){return null==t?void 0:t[e]}(t,e);return Ct(r)?r:void 0}var Pt=At(tt,"Map"),jt=At(Object,"create");var Mt=Object.prototype.hasOwnProperty;var Rt=Object.prototype.hasOwnProperty;function Bt(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 It(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 Ft(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])}}Bt.prototype.clear=function(){this.__data__=jt?jt(null):{},this.size=0},Bt.prototype.delete=function(t){var e=this.has(t)&&delete this.__data__[t];return this.size-=e?1:0,e},Bt.prototype.get=function(t){var e=this.__data__;if(jt){var r=e[t];return"__lodash_hash_undefined__"===r?void 0:r}return Mt.call(e,t)?e[t]:void 0},Bt.prototype.has=function(t){var e=this.__data__;return jt?void 0!==e[t]:Rt.call(e,t)},Bt.prototype.set=function(t,e){var r=this.__data__;return this.size+=this.has(t)?0:1,r[t]=jt&&void 0===e?"__lodash_hash_undefined__":e,this},Ft.prototype.clear=function(){this.size=0,this.__data__={hash:new Bt,map:new(Pt||K),string:new Bt}},Ft.prototype.delete=function(t){var e=It(this,t).delete(t);return this.size-=e?1:0,e},Ft.prototype.get=function(t){return It(this,t).get(t)},Ft.prototype.has=function(t){return It(this,t).has(t)},Ft.prototype.set=function(t,e){var r=It(this,t),n=r.size;return r.set(t,e),this.size+=r.size==n?0:1,this};function Lt(t){var e=this.__data__=new K(t);this.size=e.size}Lt.prototype.clear=function(){this.__data__=new K,this.size=0},Lt.prototype.delete=function(t){var e=this.__data__,r=e.delete(t);return this.size=e.size,r},Lt.prototype.get=function(t){return this.__data__.get(t)},Lt.prototype.has=function(t){return this.__data__.has(t)},Lt.prototype.set=function(t,e){var r=this.__data__;if(r instanceof K){var n=r.__data__;if(!Pt||n.length<199)return n.push([t,e]),this.size=++r.size,this;r=this.__data__=new Ft(n)}return r.set(t,e),this.size=r.size,this};var Dt=function(){try{var t=At(Object,"defineProperty");return t({},"",{}),t}catch(t){}}();function kt(t,e,r){"__proto__"==e&&Dt?Dt(t,e,{configurable:!0,enumerable:!0,value:r,writable:!0}):t[e]=r}var Ut=Object.prototype.hasOwnProperty;function Gt(t,e,r){var n=t[e];Ut.call(t,e)&&V(n,r)&&(void 0!==r||e in t)||kt(t,e,r)}function Nt(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?kt(r,a,c):Gt(r,a,c)}return r}function $t(t){return null!=t&&"object"==typeof t}function Xt(t){return $t(t)&&"[object Arguments]"==ut(t)}var Yt=Object.prototype,Ht=Yt.hasOwnProperty,Wt=Yt.propertyIsEnumerable,Vt=Xt(function(){return arguments}())?Xt:function(t){return $t(t)&&Ht.call(t,"callee")&&!Wt.call(t,"callee")},qt=Array.isArray;var Jt="object"==typeof e&&e&&!e.nodeType&&e,Kt=Jt&&"object"==typeof module&&module&&!module.nodeType&&module,Qt=Kt&&Kt.exports===Jt?tt.Buffer:void 0,Zt=(Qt?Qt.isBuffer:void 0)||function(){return!1},te=9007199254740991,ee=/^(?:0|[1-9]\d*)$/;function re(t,e){var r=typeof t;return!!(e=null==e?te:e)&&("number"==r||"symbol"!=r&&ee.test(t))&&t>-1&&t%1==0&&t<e}var ne=9007199254740991;function ie(t){return"number"==typeof t&&t>-1&&t%1==0&&t<=ne}var oe={};function se(t){return function(e){return t(e)}}oe["[object Float32Array]"]=oe["[object Float64Array]"]=oe["[object Int8Array]"]=oe["[object Int16Array]"]=oe["[object Int32Array]"]=oe["[object Uint8Array]"]=oe["[object Uint8ClampedArray]"]=oe["[object Uint16Array]"]=oe["[object Uint32Array]"]=!0,oe["[object Arguments]"]=oe["[object Array]"]=oe["[object ArrayBuffer]"]=oe["[object Boolean]"]=oe["[object DataView]"]=oe["[object Date]"]=oe["[object Error]"]=oe["[object Function]"]=oe["[object Map]"]=oe["[object Number]"]=oe["[object Object]"]=oe["[object RegExp]"]=oe["[object Set]"]=oe["[object String]"]=oe["[object WeakMap]"]=!1;var ae="object"==typeof e&&e&&!e.nodeType&&e,ce=ae&&"object"==typeof module&&module&&!module.nodeType&&module,he=ce&&ce.exports===ae&&Q.process,ue=function(){try{var t=ce&&ce.require&&ce.require("util").types;return t||he&&he.binding&&he.binding("util")}catch(t){}}(),le=ue&&ue.isTypedArray,fe=le?se(le):function(t){return $t(t)&&ie(t.length)&&!!oe[ut(t)]},pe=Object.prototype.hasOwnProperty;function de(t,e){var r=qt(t),n=!r&&Vt(t),i=!r&&!n&&Zt(t),o=!r&&!n&&!i&&fe(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)||re(h,c))||a.push(h);return a}var ye=Object.prototype;function xe(t){var e=t&&t.constructor;return t===("function"==typeof e&&e.prototype||ye)}function ge(t,e){return function(r){return t(e(r))}}var me=ge(Object.keys,Object),be=Object.prototype.hasOwnProperty;function ve(t){return null!=t&&ie(t.length)&&!xt(t)}function _e(t){return ve(t)?de(t):function(t){if(!xe(t))return me(t);var e=[];for(var r in Object(t))be.call(t,r)&&"constructor"!=r&&e.push(r);return e}(t)}var we=Object.prototype.hasOwnProperty;function Te(t){if(!lt(t))return function(t){var e=[];if(null!=t)for(var r in Object(t))e.push(r);return e}(t);var e=xe(t),r=[];for(var n in t)("constructor"!=n||!e&&we.call(t,n))&&r.push(n);return r}function Ee(t){return ve(t)?de(t,!0):Te(t)}var ze="object"==typeof e&&e&&!e.nodeType&&e,Se=ze&&"object"==typeof module&&module&&!module.nodeType&&module,Oe=Se&&Se.exports===ze?tt.Buffer:void 0,Ce=Oe?Oe.allocUnsafe:void 0;function Ae(){return[]}var Pe=Object.prototype.propertyIsEnumerable,je=Object.getOwnPropertySymbols,Me=je?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}(je(t),(function(e){return Pe.call(t,e)})))}:Ae;function Re(t,e){for(var r=-1,n=e.length,i=t.length;++r<n;)t[i+r]=e[r];return t}var Be=ge(Object.getPrototypeOf,Object),Ie=Object.getOwnPropertySymbols?function(t){for(var e=[];t;)Re(e,Me(t)),t=Be(t);return e}:Ae;function Fe(t,e,r){var n=e(t);return qt(t)?n:Re(n,r(t))}function Le(t){return Fe(t,_e,Me)}function De(t){return Fe(t,Ee,Ie)}var ke=At(tt,"DataView"),Ue=At(tt,"Promise"),Ge=At(tt,"Set"),Ne=At(tt,"WeakMap"),$e="[object Map]",Xe="[object Promise]",Ye="[object Set]",He="[object WeakMap]",We="[object DataView]",Ve=_t(ke),qe=_t(Pt),Je=_t(Ue),Ke=_t(Ge),Qe=_t(Ne),Ze=ut;(ke&&Ze(new ke(new ArrayBuffer(1)))!=We||Pt&&Ze(new Pt)!=$e||Ue&&Ze(Ue.resolve())!=Xe||Ge&&Ze(new Ge)!=Ye||Ne&&Ze(new Ne)!=He)&&(Ze=function(t){var e=ut(t),r="[object Object]"==e?t.constructor:void 0,n=r?_t(r):"";if(n)switch(n){case Ve:return We;case qe:return $e;case Je:return Xe;case Ke:return Ye;case Qe:return He}return e});var tr=Ze,er=Object.prototype.hasOwnProperty;var rr=tt.Uint8Array;function nr(t){var e=new t.constructor(t.byteLength);return new rr(e).set(new rr(t)),e}var ir=/\w*$/;var or=et?et.prototype:void 0,sr=or?or.valueOf:void 0;var ar="[object Boolean]",cr="[object Date]",hr="[object Map]",ur="[object Number]",lr="[object RegExp]",fr="[object Set]",pr="[object String]",dr="[object Symbol]",yr="[object ArrayBuffer]",xr="[object DataView]",gr="[object Float32Array]",mr="[object Float64Array]",br="[object Int8Array]",vr="[object Int16Array]",_r="[object Int32Array]",wr="[object Uint8Array]",Tr="[object Uint8ClampedArray]",Er="[object Uint16Array]",zr="[object Uint32Array]";function Sr(t,e,r){var n,i,o,s=t.constructor;switch(e){case yr:return nr(t);case ar:case cr:return new s(+t);case xr:return function(t,e){var r=e?nr(t.buffer):t.buffer;return new t.constructor(r,t.byteOffset,t.byteLength)}(t,r);case gr:case mr:case br:case vr:case _r:case wr:case Tr:case Er:case zr:return function(t,e){var r=e?nr(t.buffer):t.buffer;return new t.constructor(r,t.byteOffset,t.length)}(t,r);case hr:return new s;case ur:case pr:return new s(t);case lr:return(o=new(i=t).constructor(i.source,ir.exec(i))).lastIndex=i.lastIndex,o;case fr:return new s;case dr:return n=t,sr?Object(sr.call(n)):{}}}var Or=Object.create,Cr=function(){function t(){}return function(e){if(!lt(e))return{};if(Or)return Or(e);t.prototype=e;var r=new t;return t.prototype=void 0,r}}();var Ar=ue&&ue.isMap,Pr=Ar?se(Ar):function(t){return $t(t)&&"[object Map]"==tr(t)};var jr=ue&&ue.isSet,Mr=jr?se(jr):function(t){return $t(t)&&"[object Set]"==tr(t)},Rr=1,Br=2,Ir=4,Fr="[object Arguments]",Lr="[object Function]",Dr="[object GeneratorFunction]",kr="[object Object]",Ur={};function Gr(t,e,r,n,i,o){var s,a=e&Rr,c=e&Br,h=e&Ir;if(r&&(s=i?r(t,n,i,o):r(t)),void 0!==s)return s;if(!lt(t))return t;var u=qt(t);if(u){if(s=function(t){var e=t.length,r=new t.constructor(e);return e&&"string"==typeof t[0]&&er.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=tr(t),f=l==Lr||l==Dr;if(Zt(t))return function(t,e){if(e)return t.slice();var r=t.length,n=Ce?Ce(r):new t.constructor(r);return t.copy(n),n}(t,a);if(l==kr||l==Fr||f&&!i){if(s=c||f?{}:function(t){return"function"!=typeof t.constructor||xe(t)?{}:Cr(Be(t))}(t),!a)return c?function(t,e){return Nt(t,Ie(t),e)}(t,function(t,e){return t&&Nt(e,Ee(e),t)}(s,t)):function(t,e){return Nt(t,Me(t),e)}(t,function(t,e){return t&&Nt(e,_e(e),t)}(s,t))}else{if(!Ur[l])return i?t:{};s=Sr(t,l,a)}}o||(o=new Lt);var p=o.get(t);if(p)return p;o.set(t,s),Mr(t)?t.forEach((function(n){s.add(Gr(n,e,r,n,t,o))})):Pr(t)&&t.forEach((function(n,i){s.set(i,Gr(n,e,r,i,t,o))}));var d=u?void 0:(h?c?De:Le:c?Ee:_e)(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]),Gt(s,i,Gr(n,e,r,i,t,o))})),s}Ur[Fr]=Ur["[object Array]"]=Ur["[object ArrayBuffer]"]=Ur["[object DataView]"]=Ur["[object Boolean]"]=Ur["[object Date]"]=Ur["[object Float32Array]"]=Ur["[object Float64Array]"]=Ur["[object Int8Array]"]=Ur["[object Int16Array]"]=Ur["[object Int32Array]"]=Ur["[object Map]"]=Ur["[object Number]"]=Ur[kr]=Ur["[object RegExp]"]=Ur["[object Set]"]=Ur["[object String]"]=Ur["[object Symbol]"]=Ur["[object Uint8Array]"]=Ur["[object Uint8ClampedArray]"]=Ur["[object Uint16Array]"]=Ur["[object Uint32Array]"]=!0,Ur["[object Error]"]=Ur[Lr]=Ur["[object WeakMap]"]=!1;function Nr(t){return t}var $r=Math.max;var Xr=Dt?function(t,e){return Dt(t,"toString",{configurable:!0,enumerable:!1,value:(r=e,function(){return r}),writable:!0});var r}:Nr,Yr=Xr,Hr=Date.now;var Wr,Vr,qr,Jr=(Wr=Yr,Vr=0,qr=0,function(){var t=Hr(),e=16-(t-qr);if(qr=t,e>0){if(++Vr>=800)return arguments[0]}else Vr=0;return Wr.apply(void 0,arguments)});var Kr=Object.prototype,Qr=Kr.hasOwnProperty,Zr=function(t,e){return Jr(function(t,e,r){return e=$r(void 0===e?t.length-1:e,0),function(){for(var n=arguments,i=-1,o=$r(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,Nr),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(!lt(r))return!1;var n=typeof e;return!!("number"==n?ve(r)&&re(e,r.length):"string"==n&&e in r)&&V(r[e],t)}(e[0],e[1],i)&&(n=1);++r<n;)for(var o=e[r],s=Ee(o),a=-1,c=s.length;++a<c;){var h=s[a],u=t[h];(void 0===u||V(u,Kr[h])&&!Qr.call(t,h))&&(t[h]=o[h])}return t}));e.AbstractMode=class{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){}},e.FabricTexture=class{constructor(t,e={}){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===r.fabric)throw new Error("[Fabric-Texture Error] fabric.js is required for FabricTexture class.\nPlease install and import fabric.js first.");if(!(t instanceof r.fabric.Canvas))throw new Error("[Fabric-Texture Error] Invalid canvas parameter.\nPlease provide a valid fabric.Canvas instance.");this.canvas=t,this.options=Zr(e,{history:!1,onHistoryChange:()=>{}})}render(t=!0,e={}){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();e.withoutRecord||this.record();const c=[],h=new WeakMap,u=new WeakMap,l=this.texture.mesh.length,f=this.texture.mesh[0].length;for(let t=0;t<l;t++)for(let e=0;e<f;e++){const n=this.texture.mesh[t][e];Object.values(n).forEach((t=>{const e=t.length;for(let n=0;n<e;n++){const e=t[n];if(h.has(e))continue;const i=new r.fabric.Path(e.toSVG());c.push(i),h.set(e,i),u.set(i,e)}}))}const p=new r.fabric.Group(c),{width:d=0,height:y=0}=p,{left:x=0,top:g=0}=p,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 b=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},v=r.fabric.util.transformPoint(new r.fabric.Point(b.x*this.textureScaleX,b.y*this.textureScaleY),s.calcOwnMatrix(),!0),_=s.getCenterPoint(),w={left:_.x+v.x,top:_.y+v.y,angle:s.angle,scaleX:s.scaleX*this.textureScaleX,scaleY:s.scaleY*this.textureScaleY,flipX:s.flipX,flipY:s.flipY,originX:"center",originY:"center"};p.set(w),p.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 r.fabric.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:W.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,f=new W(l);f.setInputLimitSize({width:2e3,height:2e3}).useInstanceCanvas().setSplitStrategy({name:this.mode.name,execute:this.mode.execute.bind(this.mode)}),this.texture=f,null==n||n(f),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(Gr(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)}}},e.Texture=W,e.utils=I}));
//# sourceMappingURL=index.min.js.map