UNPKG

fabric-warpvas

Version:

This JavaScript library helps you efficiently build image warping tools on Fabric.js

1 lines 71.5 kB
import{fabric as e}from"fabric";function r(t,e){return t===e||t!=t&&e!=e}function n(t,e){for(var n=t.length;n--;)if(r(t[n][0],e))return n;return-1}var i=Array.prototype.splice;function o(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])}}o.prototype.clear=function(){this.__data__=[],this.size=0},o.prototype.delete=function(t){var e=this.__data__,r=n(e,t);return!(r<0)&&(r==e.length-1?e.pop():i.call(e,r,1),--this.size,!0)},o.prototype.get=function(t){var e=this.__data__,r=n(e,t);return r<0?void 0:e[r][1]},o.prototype.has=function(t){return n(this.__data__,t)>-1},o.prototype.set=function(t,e){var r=this.__data__,i=n(r,t);return i<0?(++this.size,r.push([t,e])):r[i][1]=e,this};var s="object"==typeof global&&global&&global.Object===Object&&global,a="object"==typeof self&&self&&self.Object===Object&&self,c=s||a||Function("return this")(),h=c.Symbol,l=Object.prototype,u=l.hasOwnProperty,p=l.toString,f=h?h.toStringTag:void 0;var g=Object.prototype.toString;var d="[object Null]",y="[object Undefined]",x=h?h.toStringTag:void 0;function v(t){return null==t?void 0===t?y:d:x&&x in Object(t)?function(t){var e=u.call(t,f),r=t[f];try{t[f]=void 0;var n=!0}catch(t){}var i=p.call(t);return n&&(e?t[f]=r:delete t[f]),i}(t):function(t){return g.call(t)}(t)}function m(t){var e=typeof t;return null!=t&&("object"==e||"function"==e)}var b="[object AsyncFunction]",_="[object Function]",w="[object GeneratorFunction]",C="[object Proxy]";function R(t){if(!m(t))return!1;var e=v(t);return e==_||e==w||e==b||e==C}var E,S=c["__core-js_shared__"],z=(E=/[^.]+$/.exec(S&&S.keys&&S.keys.IE_PROTO||""))?"Symbol(src)_1."+E:"";var T=Function.prototype.toString;function O(t){if(null!=t){try{return T.call(t)}catch(t){}try{return t+""}catch(t){}}return""}var j=/^\[object .+?Constructor\]$/,P=Function.prototype,A=Object.prototype,M=P.toString,B=A.hasOwnProperty,I=RegExp("^"+M.call(B).replace(/[\\^$.*+?()[\]{}|]/g,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$");function L(t){return!(!m(t)||(e=t,z&&z in e))&&(R(t)?I:j).test(O(t));var e}function F(t,e){var r=function(t,e){return null==t?void 0:t[e]}(t,e);return L(r)?r:void 0}var k=F(c,"Map"),W=F(Object,"create");var U=Object.prototype.hasOwnProperty;var D=Object.prototype.hasOwnProperty;function G(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 H(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 N(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])}}G.prototype.clear=function(){this.__data__=W?W(null):{},this.size=0},G.prototype.delete=function(t){var e=this.has(t)&&delete this.__data__[t];return this.size-=e?1:0,e},G.prototype.get=function(t){var e=this.__data__;if(W){var r=e[t];return"__lodash_hash_undefined__"===r?void 0:r}return U.call(e,t)?e[t]:void 0},G.prototype.has=function(t){var e=this.__data__;return W?void 0!==e[t]:D.call(e,t)},G.prototype.set=function(t,e){var r=this.__data__;return this.size+=this.has(t)?0:1,r[t]=W&&void 0===e?"__lodash_hash_undefined__":e,this},N.prototype.clear=function(){this.size=0,this.__data__={hash:new G,map:new(k||o),string:new G}},N.prototype.delete=function(t){var e=H(this,t).delete(t);return this.size-=e?1:0,e},N.prototype.get=function(t){return H(this,t).get(t)},N.prototype.has=function(t){return H(this,t).has(t)},N.prototype.set=function(t,e){var r=H(this,t),n=r.size;return r.set(t,e),this.size+=r.size==n?0:1,this};function $(t){var e=this.__data__=new o(t);this.size=e.size}$.prototype.clear=function(){this.__data__=new o,this.size=0},$.prototype.delete=function(t){var e=this.__data__,r=e.delete(t);return this.size=e.size,r},$.prototype.get=function(t){return this.__data__.get(t)},$.prototype.has=function(t){return this.__data__.has(t)},$.prototype.set=function(t,e){var r=this.__data__;if(r instanceof o){var n=r.__data__;if(!k||n.length<199)return n.push([t,e]),this.size=++r.size,this;r=this.__data__=new N(n)}return r.set(t,e),this.size=r.size,this};var X=function(){try{var t=F(Object,"defineProperty");return t({},"",{}),t}catch(t){}}();function Y(t,e,r){"__proto__"==e&&X?X(t,e,{configurable:!0,enumerable:!0,value:r,writable:!0}):t[e]=r}var V=Object.prototype.hasOwnProperty;function q(t,e,n){var i=t[e];V.call(t,e)&&r(i,n)&&(void 0!==n||e in t)||Y(t,e,n)}function J(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?Y(r,a,c):q(r,a,c)}return r}function K(t){return null!=t&&"object"==typeof t}function Q(t){return K(t)&&"[object Arguments]"==v(t)}var Z=Object.prototype,tt=Z.hasOwnProperty,et=Z.propertyIsEnumerable,rt=Q(function(){return arguments}())?Q:function(t){return K(t)&&tt.call(t,"callee")&&!et.call(t,"callee")},nt=Array.isArray;var it="object"==typeof exports&&exports&&!exports.nodeType&&exports,ot=it&&"object"==typeof module&&module&&!module.nodeType&&module,st=ot&&ot.exports===it?c.Buffer:void 0,at=(st?st.isBuffer:void 0)||function(){return!1},ct=9007199254740991,ht=/^(?:0|[1-9]\d*)$/;function lt(t,e){var r=typeof t;return!!(e=null==e?ct:e)&&("number"==r||"symbol"!=r&&ht.test(t))&&t>-1&&t%1==0&&t<e}var ut=9007199254740991;function pt(t){return"number"==typeof t&&t>-1&&t%1==0&&t<=ut}var ft={};function gt(t){return function(e){return t(e)}}ft["[object Float32Array]"]=ft["[object Float64Array]"]=ft["[object Int8Array]"]=ft["[object Int16Array]"]=ft["[object Int32Array]"]=ft["[object Uint8Array]"]=ft["[object Uint8ClampedArray]"]=ft["[object Uint16Array]"]=ft["[object Uint32Array]"]=!0,ft["[object Arguments]"]=ft["[object Array]"]=ft["[object ArrayBuffer]"]=ft["[object Boolean]"]=ft["[object DataView]"]=ft["[object Date]"]=ft["[object Error]"]=ft["[object Function]"]=ft["[object Map]"]=ft["[object Number]"]=ft["[object Object]"]=ft["[object RegExp]"]=ft["[object Set]"]=ft["[object String]"]=ft["[object WeakMap]"]=!1;var dt="object"==typeof exports&&exports&&!exports.nodeType&&exports,yt=dt&&"object"==typeof module&&module&&!module.nodeType&&module,xt=yt&&yt.exports===dt&&s.process,vt=function(){try{var t=yt&&yt.require&&yt.require("util").types;return t||xt&&xt.binding&&xt.binding("util")}catch(t){}}(),mt=vt&&vt.isTypedArray,bt=mt?gt(mt):function(t){return K(t)&&pt(t.length)&&!!ft[v(t)]},_t=Object.prototype.hasOwnProperty;function wt(t,e){var r=nt(t),n=!r&&rt(t),i=!r&&!n&&at(t),o=!r&&!n&&!i&&bt(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&&!_t.call(t,h)||s&&("length"==h||i&&("offset"==h||"parent"==h)||o&&("buffer"==h||"byteLength"==h||"byteOffset"==h)||lt(h,c))||a.push(h);return a}var Ct=Object.prototype;function Rt(t){var e=t&&t.constructor;return t===("function"==typeof e&&e.prototype||Ct)}function Et(t,e){return function(r){return t(e(r))}}var St=Et(Object.keys,Object),zt=Object.prototype.hasOwnProperty;function Tt(t){return null!=t&&pt(t.length)&&!R(t)}function Ot(t){return Tt(t)?wt(t):function(t){if(!Rt(t))return St(t);var e=[];for(var r in Object(t))zt.call(t,r)&&"constructor"!=r&&e.push(r);return e}(t)}var jt=Object.prototype.hasOwnProperty;function Pt(t){if(!m(t))return function(t){var e=[];if(null!=t)for(var r in Object(t))e.push(r);return e}(t);var e=Rt(t),r=[];for(var n in t)("constructor"!=n||!e&&jt.call(t,n))&&r.push(n);return r}function At(t){return Tt(t)?wt(t,!0):Pt(t)}var Mt="object"==typeof exports&&exports&&!exports.nodeType&&exports,Bt=Mt&&"object"==typeof module&&module&&!module.nodeType&&module,It=Bt&&Bt.exports===Mt?c.Buffer:void 0,Lt=It?It.allocUnsafe:void 0;function Ft(){return[]}var kt=Object.prototype.propertyIsEnumerable,Wt=Object.getOwnPropertySymbols,Ut=Wt?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}(Wt(t),(function(e){return kt.call(t,e)})))}:Ft;function Dt(t,e){for(var r=-1,n=e.length,i=t.length;++r<n;)t[i+r]=e[r];return t}var Gt=Et(Object.getPrototypeOf,Object),Ht=Object.getOwnPropertySymbols?function(t){for(var e=[];t;)Dt(e,Ut(t)),t=Gt(t);return e}:Ft;function Nt(t,e,r){var n=e(t);return nt(t)?n:Dt(n,r(t))}function $t(t){return Nt(t,Ot,Ut)}function Xt(t){return Nt(t,At,Ht)}var Yt=F(c,"DataView"),Vt=F(c,"Promise"),qt=F(c,"Set"),Jt=F(c,"WeakMap"),Kt="[object Map]",Qt="[object Promise]",Zt="[object Set]",te="[object WeakMap]",ee="[object DataView]",re=O(Yt),ne=O(k),ie=O(Vt),oe=O(qt),se=O(Jt),ae=v;(Yt&&ae(new Yt(new ArrayBuffer(1)))!=ee||k&&ae(new k)!=Kt||Vt&&ae(Vt.resolve())!=Qt||qt&&ae(new qt)!=Zt||Jt&&ae(new Jt)!=te)&&(ae=function(t){var e=v(t),r="[object Object]"==e?t.constructor:void 0,n=r?O(r):"";if(n)switch(n){case re:return ee;case ne:return Kt;case ie:return Qt;case oe:return Zt;case se:return te}return e});var ce=ae,he=Object.prototype.hasOwnProperty;var le=c.Uint8Array;function ue(t){var e=new t.constructor(t.byteLength);return new le(e).set(new le(t)),e}var pe=/\w*$/;var fe=h?h.prototype:void 0,ge=fe?fe.valueOf:void 0;var de="[object Boolean]",ye="[object Date]",xe="[object Map]",ve="[object Number]",me="[object RegExp]",be="[object Set]",_e="[object String]",we="[object Symbol]",Ce="[object ArrayBuffer]",Re="[object DataView]",Ee="[object Float32Array]",Se="[object Float64Array]",ze="[object Int8Array]",Te="[object Int16Array]",Oe="[object Int32Array]",je="[object Uint8Array]",Pe="[object Uint8ClampedArray]",Ae="[object Uint16Array]",Me="[object Uint32Array]";function Be(t,e,r){var n,i,o,s=t.constructor;switch(e){case Ce:return ue(t);case de:case ye:return new s(+t);case Re:return function(t,e){var r=e?ue(t.buffer):t.buffer;return new t.constructor(r,t.byteOffset,t.byteLength)}(t,r);case Ee:case Se:case ze:case Te:case Oe:case je:case Pe:case Ae:case Me:return function(t,e){var r=e?ue(t.buffer):t.buffer;return new t.constructor(r,t.byteOffset,t.length)}(t,r);case xe:return new s;case ve:case _e:return new s(t);case me:return(o=new(i=t).constructor(i.source,pe.exec(i))).lastIndex=i.lastIndex,o;case be:return new s;case we:return n=t,ge?Object(ge.call(n)):{}}}var Ie=Object.create,Le=function(){function t(){}return function(e){if(!m(e))return{};if(Ie)return Ie(e);t.prototype=e;var r=new t;return t.prototype=void 0,r}}();var Fe=vt&&vt.isMap,ke=Fe?gt(Fe):function(t){return K(t)&&"[object Map]"==ce(t)};var We=vt&&vt.isSet,Ue=We?gt(We):function(t){return K(t)&&"[object Set]"==ce(t)},De=1,Ge=2,He=4,Ne="[object Arguments]",$e="[object Function]",Xe="[object GeneratorFunction]",Ye="[object Object]",Ve={};function qe(t,e,r,n,i,o){var s,a=e&De,c=e&Ge,h=e&He;if(r&&(s=i?r(t,n,i,o):r(t)),void 0!==s)return s;if(!m(t))return t;var l=nt(t);if(l){if(s=function(t){var e=t.length,r=new t.constructor(e);return e&&"string"==typeof t[0]&&he.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 u=ce(t),p=u==$e||u==Xe;if(at(t))return function(t,e){if(e)return t.slice();var r=t.length,n=Lt?Lt(r):new t.constructor(r);return t.copy(n),n}(t,a);if(u==Ye||u==Ne||p&&!i){if(s=c||p?{}:function(t){return"function"!=typeof t.constructor||Rt(t)?{}:Le(Gt(t))}(t),!a)return c?function(t,e){return J(t,Ht(t),e)}(t,function(t,e){return t&&J(e,At(e),t)}(s,t)):function(t,e){return J(t,Ut(t),e)}(t,function(t,e){return t&&J(e,Ot(e),t)}(s,t))}else{if(!Ve[u])return i?t:{};s=Be(t,u,a)}}o||(o=new $);var f=o.get(t);if(f)return f;o.set(t,s),Ue(t)?t.forEach((function(n){s.add(qe(n,e,r,n,t,o))})):ke(t)&&t.forEach((function(n,i){s.set(i,qe(n,e,r,i,t,o))}));var g=l?void 0:(h?c?Xt:$t:c?At:Ot)(t);return function(t,e){for(var r=-1,n=null==t?0:t.length;++r<n&&!1!==e(t[r],r,t););}(g||t,(function(n,i){g&&(n=t[i=n]),q(s,i,qe(n,e,r,i,t,o))})),s}Ve[Ne]=Ve["[object Array]"]=Ve["[object ArrayBuffer]"]=Ve["[object DataView]"]=Ve["[object Boolean]"]=Ve["[object Date]"]=Ve["[object Float32Array]"]=Ve["[object Float64Array]"]=Ve["[object Int8Array]"]=Ve["[object Int16Array]"]=Ve["[object Int32Array]"]=Ve["[object Map]"]=Ve["[object Number]"]=Ve[Ye]=Ve["[object RegExp]"]=Ve["[object Set]"]=Ve["[object String]"]=Ve["[object Symbol]"]=Ve["[object Uint8Array]"]=Ve["[object Uint8ClampedArray]"]=Ve["[object Uint16Array]"]=Ve["[object Uint32Array]"]=!0,Ve["[object Error]"]=Ve[$e]=Ve["[object WeakMap]"]=!1;function Je(t){return t}var Ke=Math.max;var Qe=X?function(t,e){return X(t,"toString",{configurable:!0,enumerable:!1,value:(r=e,function(){return r}),writable:!0});var r}:Je,Ze=Qe,tr=Date.now;var er,rr,nr,ir=(er=Ze,rr=0,nr=0,function(){var t=tr(),e=16-(t-nr);if(nr=t,e>0){if(++rr>=800)return arguments[0]}else rr=0;return er.apply(void 0,arguments)});var or=Object.prototype,sr=or.hasOwnProperty,ar=function(t,e){return ir(function(t,e,r){return e=Ke(void 0===e?t.length-1:e,0),function(){for(var n=arguments,i=-1,o=Ke(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,Je),t+"")}((function(t,e){t=Object(t);var n=-1,i=e.length,o=i>2?e[2]:void 0;for(o&&function(t,e,n){if(!m(n))return!1;var i=typeof e;return!!("number"==i?Tt(n)&&lt(e,n.length):"string"==i&&e in n)&&r(n[e],t)}(e[0],e[1],o)&&(i=1);++n<i;)for(var s=e[n],a=At(s),c=-1,h=a.length;++c<h;){var l=a[c],u=t[l];(void 0===u||r(u,or[l])&&!sr.call(t,l))&&(t[l]=s[l])}return t}));function cr(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:hr,cos:lr,sin:ur,acos:pr,atan2:fr,sqrt:gr,pow:dr}=Math;function yr(t){return t<0?-dr(-t,1/3):dr(t,1/3)}const xr=Math.PI,vr=2*xr,mr=xr/2,br=Number.MAX_SAFE_INTEGER||9007199254740991,_r=Number.MIN_SAFE_INTEGER||-9007199254740991,wr={x:0,y:0,z:0},Cr={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),gr(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,l=0;2===n?(o=[o[0],o[1],o[2],wr],e=c,s=i*t*2,a=h):3===n&&(e=c*i,s=c*t*3,a=i*h*3,l=t*h);const u={x:e*o[0].x+s*o[1].x+a*o[2].x+l*o[3].x,y:e*o[0].y+s*o[1].y+a*o[2].y+l*o[3].y,t:t};return r&&(u.z=e*o[0].z+s*o[1].z+a*o[2].z+l*o[3].z),u}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],l=o[2],u=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,l*=t*t,3===s.length?(a=c+h+l,{x:(c*s[0].x+h*s[1].x+l*s[2].x)/a,y:(c*s[0].y+h*s[1].y+l*s[2].y)/a,z:!!n&&(c*s[0].z+h*s[1].z+l*s[2].z)/a,t:t}):(c*=i,h*=1.5*i,l*=3*i,u*=t*t*t,4===s.length?(a=c+h+l+u,{x:(c*s[0].x+h*s[1].x+l*s[2].x+u*s[3].x)/a,y:(c*s[0].y+h*s[1].y+l*s[2].y+u*s[3].y)/a,z:!!n&&(c*s[0].z+h*s[1].z+l*s[2].z+u*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||Cr.approximately(t,e)||Cr.approximately(t,r)},approximately:function(t,e,r){return hr(t-e)<=(r||1e-6)},length:function(t){const e=Cr.Tvalues.length;let r=0;for(let n,i=0;i<e;i++)n=.5*Cr.Tvalues[i]+.5,r+=Cr.Cvalues[i]*Cr.arcfn(n,t);return.5*r},map:function(t,e,r,n,i){return n+(t-e)/(r-e)*(i-n)},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(Cr.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 fr(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 gr(r*r+n*n)},closest:function(t,e){let r,n,i=dr(2,63);return t.forEach((function(t,o){n=Cr.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=dr(t,e)+dr(1-t,e);return hr((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=dr(1-t,e);return r/(dr(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,l=n.x,u=n.y;return Cr.lli8(i,o,s,a,c,h,l,u)},lli:function(t,e){return Cr.lli4(t,t.c,e,e.c)},makeline:function(t,e){return new Mr(t.x,t.y,(t.x+e.x)/2,(t.y+e.y)/2,e.x,e.y)},findbbox:function(t){let e=br,r=br,n=_r,i=_r;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(!Cr.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=Cr.makeline(e.points[n-1],t.points[0]),s=Cr.makeline(t.points[i-1],e.points[0]),a={startcap:o,forward:t,back:e,endcap:s,bbox:Cr.findbbox([o,t,e,s]),intersections:function(t){return Cr.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=br,s=_r;-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=-fr(e.p2.y-n,e.p2.x-r);return t.map((function(t){return{x:(t.x-r)*lr(i)-(t.y-n)*ur(i),y:(t.x-r)*ur(i)+(t.y-n)*lr(i)}}))},roots:function(t,e){e=e||{p1:{x:0,y:0},p2:{x:1,y:0}};const r=t.length-1,n=Cr.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=-gr(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 o=n[0].y,s=n[1].y,a=n[2].y;let c=3*s-o-3*a+n[3].y,h=3*o-6*s+3*a,l=-3*o+3*s,u=o;if(Cr.approximately(c,0)){if(Cr.approximately(h,0))return Cr.approximately(l,0)?[]:[-u/l].filter(i);const t=gr(l*l-4*h*u),e=2*h;return[(t-l)/e,(-l-t)/e].filter(i)}h/=c,l/=c,u/=c;const p=(3*l-h*h)/3,f=p/3,g=(2*h*h*h-9*h*l+27*u)/27,d=g/2,y=d*d+f*f*f;let x,v,m,b,_;if(y<0){const t=-p/3,e=gr(t*t*t),r=-g/(2*e),n=pr(r<-1?-1:r>1?1:r),o=2*yr(e);return m=o*lr(n/3)-h/3,b=o*lr((n+vr)/3)-h/3,_=o*lr((n+2*vr)/3)-h/3,[m,b,_].filter(i)}if(0===y)return x=d<0?yr(-d):-yr(d),m=2*x-h/3,b=-x-h/3,[m,b].filter(i);{const t=gr(y);return x=yr(-d+t),v=yr(d+t),[x-v-h/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=-gr(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,i){let o,s,a,c,h=0,l=0;const u=Cr.compute(t,e),p=Cr.compute(t,r),f=u.x*u.x+u.y*u.y;if(n?(o=gr(dr(u.y*p.z-p.y*u.z,2)+dr(u.z*p.x-p.z*u.x,2)+dr(u.x*p.y-p.x*u.y,2)),s=dr(f+u.z*u.z,1.5)):(o=u.x*p.y-u.y*p.x,s=dr(f,1.5)),0===o||0===s)return{k:0,r:0};if(h=o/s,l=s/o,!i){const i=Cr.curvature(t-.001,e,r,n,!0).k,o=Cr.curvature(t+.001,e,r,n,!0).k;c=(o-h+(h-i))/2,a=(hr(o-h)+hr(h-i))/2}return{k:h,r:l,dk:c,adk:a}},inflections:function(t){if(t.length<4)return[];const e=Cr.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(Cr.approximately(o,0)){if(!Cr.approximately(s,0)){let t=-a/s;if(0<=t&&t<=1)return[t]}return[]}const c=2*o;if(Cr.approximately(c,0))return[];const h=s*s-4*o*a;if(h<0)return[];const l=Math.sqrt(h);return[(l-s)/c,-(s+l)/c].filter((function(t){return 0<=t&&t<=1}))},bboxoverlap:function(t,e){const r=["x","y"],n=r.length;for(let i,o,s,a,c=0;c<n;c++)if(i=r[c],o=t[i].mid,s=e[i].mid,a=(t[i].size+e[i].size)/2,hr(o-s)>=a)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 Cr.bboxoverlap(t.left.bbox(),t.right.bbox())}));let l=[];return 0===h.length||(h.forEach((function(t){l=l.concat(Cr.pairiteration(t.left,t.right,s))})),l=l.filter((function(t,e){return l.indexOf(t)===e}))),l},getccenter:function(t,e,r){const n=e.x-t.x,i=e.y-t.y,o=r.x-e.x,s=r.y-e.y,a=n*lr(mr)-i*ur(mr),c=n*ur(mr)+i*lr(mr),h=o*lr(mr)-s*ur(mr),l=o*ur(mr)+s*lr(mr),u=(t.x+e.x)/2,p=(t.y+e.y)/2,f=(e.x+r.x)/2,g=(e.y+r.y)/2,d=u+a,y=p+c,x=f+h,v=g+l,m=Cr.lli8(u,p,d,y,f,g,x,v),b=Cr.dist(m,t);let _,w=fr(t.y-m.y,t.x-m.x),C=fr(e.y-m.y,e.x-m.x),R=fr(r.y-m.y,r.x-m.x);return w<R?((w>C||C>R)&&(w+=vr),w>R&&(_=R,R=w,w=_)):R<C&&C<w?(_=R,R=w,w=_):R+=vr,m.s=w,m.e=R,m.r=b,m},numberSort:function(t,e){return t-e}};class Rr{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 Cr.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++)Cr.expandbox(e,t[r].bbox());return e}offset(t){const e=[];return this.curves.forEach((function(r){e.push(...r.offset(t))})),new Rr(e)}}const{abs:Er,min:Sr,max:zr,cos:Tr,sin:Or,acos:jr,sqrt:Pr}=Math,Ar=Math.PI;class Mr{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 l=Cr.align(s,{p1:s[0],p2:s[c]}),u=Cr.dist(s[0],s[c]);this._linear=l.reduce(((t,e)=>t+Er(e.y)),0)<u/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 Mr(e,e,r);if(1===n)return new Mr(t,e,e);const i=Mr.getABC(2,t,e,r,n);return new Mr(t,i.A,r)}static cubicFromPoints(t,e,r,n,i){void 0===n&&(n=.5);const o=Mr.getABC(3,t,e,r,n);void 0===i&&(i=Cr.dist(e,o.C));const s=i*(1-n)/n,a=Cr.dist(t,r),c=(r.x-t.x)/a,h=(r.y-t.y)/a,l=i*c,u=i*h,p=s*c,f=s*h,g=e.x-l,d=e.y-u,y=e.x+p,x=e.y+f,v=o.A,m=v.x+(g-v.x)/(1-n),b=v.y+(d-v.y)/(1-n),_=v.x+(y-v.x)/n,w=v.y+(x-v.y)/n,C={x:t.x+(m-t.x)/n,y:t.y+(b-t.y)/n},R={x:r.x+(_-r.x)/(1-n),y:r.y+(w-r.y)/(1-n)};return new Mr(t,C,R,r)}static getUtils(){return Cr}getUtils(){return Mr.getUtils()}static get PolyBezier(){return Rr}valueOf(){return this.toString()}toString(){return Cr.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=Cr.derive(this.points,this._3d),this.computedirection()}computedirection(){const t=this.points,e=Cr.angle(t[0],t[this.order],t[1]);this.clockwise=e>0}length(){return Cr.length(this.derivative.bind(this))}static getABC(t=2,e,r,n,i=.5){const o=Cr.projectionratio(i,t),s=1-o,a={x:o*e.x+s*n.x,y:o*e.y+s*n.y},c=Cr.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 Mr.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],Cr.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=Cr.closest(e,t),i=n.mpos,o=(i-1)/r,s=(i+1)/r,a=.1/r;let c,h=n.mdist,l=o,u=l;h+=1;for(let e;l<s+a;l+=a)c=this.compute(l),e=Cr.dist(t,c),e<h&&(h=e,u=l);return u=u<0?0:u>1?1:u,c=this.compute(u),c.t=u,c.d=h,c}get(t){return this.compute(t)}point(t){return this.points[t]}compute(t){return this.ratios?Cr.computeWithRatios(t,this.points,this.ratios,this._3d):Cr.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 Mr(e)}derivative(t){return Cr.compute(t,this.dpoints[0],this._3d)}dderivative(t){return Cr.compute(t,this.dpoints[1],this._3d)}align(){let t=this.points;return new Mr(Cr.align(t,{p1:t[0],p2:t[t.length-1]}))}curvature(t){return Cr.curvature(t,this.dpoints[0],this.dpoints[1],this._3d)}inflections(){return Cr.inflections(this.points)}normal(t){return this._3d?this.__normal3(t):this.__normal2(t)}__normal2(t){const e=this.derivative(t),r=Pr(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=Pr(e.x*e.x+e.y*e.y+e.z*e.z),i=Pr(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=Pr(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=Cr.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 Mr([r[0],r[3],r[5]]):new Mr([r[0],r[4],r[7],r[9]]),right:2===this.order?new Mr([r[5],r[4],r[2]]):new Mr([r[9],r[8],r[6],r[3]]),span:r};return n.left._t1=Cr.map(0,0,1,this._t1,this._t2),n.left._t2=Cr.map(t,0,1,this._t1,this._t2),n.right._t1=Cr.map(t,0,1,this._t1,this._t2),n.right._t2=Cr.map(1,0,1,this._t1,this._t2),e?(e=Cr.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]=Cr.droots(i),3===this.order&&(i=this.dpoints[1].map(n),t[r]=t[r].concat(Cr.droots(i))),t[r]=t[r].filter((function(t){return t>=0&&t<=1})),e=e.concat(t[r].sort(Cr.numberSort))}.bind(this)),t.values=e.sort(Cr.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]=Cr.getminmax(this,r,t[r])}.bind(this)),e}overlaps(t){const e=this.bbox(),r=t.bbox();return Cr.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 Mr(r)]}return this.reduce().map((function(e){return e._linear?e.offset(t)[0]:e.scale(t)}))}simple(){if(3===this.order){const t=Cr.angle(this.points[0],this.points[3],this.points[1]),e=Cr.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),Er(jr(r))<Ar/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,Er(r-n)<i)return[];e=t.split(r,n),e._t1=Cr.map(r,0,1,t._t1,t._t2),e._t2=Cr.map(n,0,1,t._t1,t._t2),s.push(e),r=n;break}r<1&&(e=t.split(r,1),e._t1=Cr.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 Mr(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=Cr.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]=Cr.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},l=r?r((o+1)/e):t;r&&!n&&(l=-l);var u=Pr(a.x*a.x+a.y*a.y);a.x/=u,a.y/=u,c[o+1]={x:s.x+l*a.x,y:s.y+l*a.y}}})),new Mr(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]=Cr.lli4(r,o,h,i[t+1])})),new Mr(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 l=[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 u=[h,c,a],p=Cr.makeline(u[2],l[0]),f=Cr.makeline(l[2],u[0]),g=[p,new Mr(l),f,new Mr(u)];return new Rr(g)}const i=this.reduce(),o=i.length,s=[];let a,c=[],h=0,l=this.length();const u=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 Cr.map(o,0,1,t+s*c,t+a*c)}}i.forEach((function(i){const o=i.length();u?(s.push(i.scale(p(t,r,l,h,o))),c.push(i.scale(p(-e,-n,l,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],g=s[o-1].points[s[o-1].points.length-1],d=c[o-1].points[c[o-1].points.length-1],y=c[0].points[0],x=Cr.makeline(d,f),v=Cr.makeline(g,y),m=[x].concat(s).concat([v]).concat(c);return new Rr(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=Cr.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 Mr&&(t=t.reduce()),this.curveintersects(this.reduce(),t,e)):this.selfintersects(e)}lineIntersects(t){const e=Sr(t.p1.x,t.p2.x),r=Sr(t.p1.y,t.p2.y),n=zr(t.p1.x,t.p2.x),i=zr(t.p1.y,t.p2.y);return Cr.roots(this.points,t).filter((t=>{var o=this.get(t);return Cr.between(o.x,e,n)&&Cr.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=Cr.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=Cr.dist(t,e),c=Cr.dist(t,o),h=Cr.dist(t,s);return Er(c-a)+Er(h-a)}_iterate(t,e){let r,n=0,i=1;do{r=0,i=1;let o,s,a,c,h,l=this.get(n),u=!1,p=!1,f=i,g=1;do{if(p=u,c=a,f=(n+i)/2,o=this.get(f),s=this.get(i),a=Cr.getccenter(l,o,s),a.interval={start:n,end:i},u=this._error(a,l,n,i)<=t,h=p&&!u,h||(g=i),u){if(i>=1){if(a.interval.end=g=1,c=a,i>1){let t={x:a.x+a.r*Tr(a.e),y:a.y+a.r*Or(a.e)};a.e+=Cr.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=g}while(i<1);return e}}const Br=(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}},Ir=(t,e)=>Math.sqrt(Math.pow(e.x-t.x,2)+Math.pow(e.y-t.y,2)),Lr=(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}},Fr=(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},kr=(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,l]=e.map(Number),[u,p,f,g]=r.map(Number),d=o-i*h/c,y=h-c*f/p,x=l-c*g/p,v=a-c*u/p,m=(d/y*x-(s-i*l/c))/(d/y*v-(n-i*a/c)),b=(x-v*m)/y;return{x:m,y:(s-n*m-o*b)/i,z:b}},l=[o.x+c,o.y+c,1,r.x+c],u=[s.x+c,s.y+c,1,n.x+c],p=[a.x+c,a.y+c,1,i.x+c],f=h(l,u,p);l[3]=r.y+c,u[3]=n.y+c,p[3]=i.y+c;const g=h(l,u,p),d=f.x,y=f.y,x=f.z;return[d,g.x,y,g.y,x,g.z]},Wr=(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},Ur=(t,e,r,n,i)=>{var o;const{x:s,y:a,sourceScale:c=1,destinationScale:h=1}=n,{gridColor:l={r:255,g:0,b:0,a:1},enableContentDisplay:u=!0,enableGridDisplay:p=!1,enableGridVertexDisplay:f=!1}=null!==(o=t.renderingConfig)&&void 0!==o?o:{},{calcBoundingBox:g,calcPerpendicularIntersection:d,calcCoordDistance:y,calcRelativeCoord:x,calcMatrix:v}=i,m=(t,e,r,n=1)=>{const i=d(e,r,t),o=y(t,i),s=x(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],d=new Path2D;for(let t=0;t<3;t++){const e=h[t],r=h[(t+1)%3],n=h[(t+2)%3],i=m(e,r,n,_),o=m(e,n,r,_);d.lineTo(i.x,i.y),d.lineTo(o.x,o.y)}if(u){b.save(),b.clip(d);const h=v([t,n,o],[r,i,s]);b.transform(...h);const l=g(r,i,s),u=(a.x-1)*c,p=(a.y-1)*c,f=(l.width+2)*c,y=(l.height+2)*c,x=a.x-1/c,m=a.y-1/c,_=l.width+2/c,w=l.height+2/c;b.drawImage(e,u,p,f,y,x,m,_,w),b.restore()}if(f){const e=Math.floor(2/c);b.fillStyle=`rgba(${l.r}, ${l.g}, ${l.b}, ${l.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(d)}};return t.regionPoints.forEach(((e,r)=>{e.forEach(((e,n)=>{const i=e,o=t.regionCurves[r][n].vertical.length-1;i.forEach(((e,s)=>{const a=i[s],c=i[s+1],h=i[s+o+2],l=i[s+o+1],u=t.originalRegionPoints[r][n][s],p=t.originalRegionPoints[r][n][s+1],f=t.originalRegionPoints[r][n][s+o+2],g=t.originalRegionPoints[r][n][s+o+1];c&&h&&s%(o+1)<o&&(w(a,u,c,p,l,g,u),w(h,f,c,p,l,g,u))}))}))})),b.restore(),r},Dr=(t,e,r,n)=>{const{width:i,height:o,sourceScale:s=1,destinationScale:a=1}=n;return(r=null!=r?r:document.createElement("canvas")).width=i*a*s,r.height=o*a*s,Ur(t,e,r,n,{calcBoundingBox:Lr,calcPerpendicularIntersection:Br,calcCoordDistance:Ir,calcRelativeCoord:Fr,calcMatrix:kr})},Gr=(t,e,r,n)=>{var i;const{x:o,y:s,width:a,height:c,sourceScale:h=1}=n,{enableAntialias:l=!0,gridColor:u={r:255,g:0,b:0,a:1},enableContentDisplay:p=!0,enableGridDisplay:f=!1,enableGridVertexDisplay:g=!1}=null!==(i=t.renderingConfig)&&void 0!==i?i:{},{width:d,height:y}=e,x=r.getContext("webgl",{antialias:l});if(!x)throw Error("[Warpvas] Failed to initialize WebGL. Your browser or device may not support it.");const v={before:[],after:[]};t.regionPoints.forEach(((e,r)=>{e.forEach(((e,n)=>{const i=e,o=t.regionCurves[r][n].vertical.length-1;i.forEach(((e,s)=>{const a=i[s],c=i[s+1],h=i[s+o+2],l=i[s+o+1],u=t.originalRegionPoints[r][n][s],p=t.originalRegionPoints[r][n][s+1],f=t.originalRegionPoints[r][n][s+o+2],g=t.originalRegionPoints[r][n][s+o+1];c&&h&&s%(o+1)<o&&(v.before.push(u,p,g,f,p,g),v.after.push(a,c,l,h,c,l))}))}))}));const m="\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=x.createShader(t);return r?(x.shaderSource(r,e),x.compileShader(r),x.getShaderParameter(r,x.COMPILE_STATUS)?r:(console.error("[Warpvas] Shader compilation error:",x.getShaderInfoLog(r)),x.deleteShader(r),null)):(console.error("[Warpvas] Failed to create shader."),null)},_=(t,e)=>{const r=b(x.VERTEX_SHADER,t);if(!r)return console.error("[Warpvas] Failed to initialize vertex shader."),null;const n=b(x.FRAGMENT_SHADER,e);if(!n)return console.error("[Warpvas] Failed to initialize fragment shader."),null;const i=x.createProgram();return i?(x.attachShader(i,r),x.attachShader(i,n),x.linkProgram(i),x.getProgramParameter(i,x.LINK_STATUS)?i:(console.error("[Warpvas] Shader program linking error:",x.getProgramInfoLog(i)),null)):(console.error("[Warpvas] Failed to create shader program."),null)},w=t=>!(t&t-1),C=_(m,"\n varying highp vec2 vTextureCoord;\n uniform sampler2D uSampler;\n void main(void) {\n gl_FragColor = texture2D(uSampler, vTextureCoord);\n }\n ");if(!C)throw Error("[Warpvas] Failed to initialize shader program.");const R={program:C,attribLocations:{vertexPosition:x.getAttribLocation(C,"aVertexPosition"),textureCoord:x.getAttribLocation(C,"aTextureCoord")},uniformLocations:{uSampler:x.getUniformLocation(C,"uSampler")}},E=x.createTexture();if(!E)throw Error("[Warpvas] Failed to create WebGL texture object.");return x.bindTexture(x.TEXTURE_2D,E),x.texImage2D(x.TEXTURE_2D,0,x.RGBA,x.RGBA,x.UNSIGNED_BYTE,e),w(e.width)&&w(e.height)&&x.generateMipmap(x.TEXTURE_2D),x.enable(x.BLEND),x.blendFunc(x.SRC_ALPHA,x.ONE_MINUS_SRC_ALPHA),x.texParameteri(x.TEXTURE_2D,x.TEXTURE_WRAP_S,x.CLAMP_TO_EDGE),x.texParameteri(x.TEXTURE_2D,x.TEXTURE_WRAP_T,x.CLAMP_TO_EDGE),x.texParameteri(x.TEXTURE_2D,x.TEXTURE_MIN_FILTER,x.LINEAR),x.viewport(0,0,r.width,r.height),((t,e,r)=>{x.clearColor(0,0,0,0),x.clear(x.COLOR_BUFFER_BIT);const n=x.FLOAT,i=!1,o=4*Float32Array.BYTES_PER_ELEMENT;x.bindBuffer(x.ARRAY_BUFFER,e.position),x.vertexAttribPointer(t.attribLocations.vertexPosition,2,n,i,o,0),x.enableVertexAttribArray(t.attribLocations.vertexPosition),x.bindBuffer(x.ARRAY_BUFFER,e.textureCoord),x.vertexAttribPointer(t.attribLocations.textureCoord,2,n,i,o,0),x.enableVertexAttribArray(t.attribLocations.textureCoord),x.useProgram(t.program),x.activeTexture(x.TEXTURE0),x.bindTexture(x.TEXTURE_2D,r),x.uniform1i(t.uniformLocations.uSampler,0),p&&x.drawArrays(x.TRIANGLES,0,v.before.length);const{r:s,g:a,b:c,a:h}=u,l=`${(s/255).toFixed(1)}, ${(a/255).toFixed(1)}, ${(c/255).toFixed(1)}, ${h.toFixed(1)}`,d=_(m,`\n void main(void) {\n gl_FragColor = vec4(${l});\n }\n `);if(!d)throw Error("[Warpvas] Failed to initialize outline shader program.");x.bindBuffer(x.ARRAY_BUFFER,e.position),x.vertexAttribPointer(x.getAttribLocation(d,"aVertexPosition"),2,n,i,0,0),x.enableVertexAttribArray(x.getAttribLocation(d,"aVertexPosition")),x.bindBuffer(x.ARRAY_BUFFER,e.textureCoord),x.vertexAttribPointer(x.getAttribLocation(d,"aTextureCoord"),2,n,i,0,0),x.enableVertexAttribArray(x.getAttribLocation(d,"aTextureCoord")),x.useProgram(d),f&&x.drawArrays(x.LINES,0,2*v.before.length),g&&x.drawArrays(x.POINTS,0,2*v.before.length)})(R,(()=>{const t=x.createBuffer();x.bindBuffer(x.ARRAY_BUFFER,t);const e=v.before.map(((t,e)=>{const r=[t.x/(d/h),t.y/(y/h)];return(e+1)%3==0?r.push(v.before[e-2].x/(d/h),v.before[e-2].y/(y/h)):r.push(v.before[e+1].x/(d/h),v.before[e+1].y/(y/h)),r})).flat(1);x.bufferData(x.ARRAY_BUFFER,new Float32Array(e),x.STATIC_DRAW);const r=x.createBuffer();x.bindBuffer(x.ARRAY_BUFFER,r);const n=v.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((v.after[e-2].x+o)/(a/2)-1,-((v.after[e-2].y+s)/(c/2)-1)):r.push((v.after[e+1].x+o)/(a/2)-1,-((v.after[e+1].y+s)/(c/2)-1)),r})).flat(1);return x.bufferData(x.ARRAY_BUFFER,new Float32Array(n),x.STATIC_DRAW),{position:r,textureCoord:t}})(),E),r},Hr=(t,e,r,n)=>{const{width:i,height:o,sourceScale:s=1,destinationScale:a=1}=n;return(r=null!=r?r:document.createElement("canvas")).width=i*a*s,r.height=o*a*s,Gr(t,e,r,n)},Nr="WORKER_MESSAGE",$r="JOB_RESULT",Xr=t=>t instanceof ArrayBuffer||t instanceof MessagePort||self.ImageBitmap&&t instanceof ImageBitmap,Yr=()=>{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 = ${Xr}\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: '${Nr}', message }),\n close: self.close,\n }]))\n ).then(result => {\n postMessage({ type: '${$r}', message: { index, result } }, [result].filter($isTransferables))\n }).catch(error => {\n postMessage({ type: '${$r}', 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===Nr&&e&&e.call(e,n.message),n.type===$r){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(Xr))})),terminate:()=>{a.terminate(),URL.revokeObjectURL(s),t.length=0,r.clear(),e=void 0}}}};return n},Vr=(t,e,r,n)=>cr(void 0,void 0,void 0,(function*(){const{regionPoints:i,renderingConfig:o,regionCurves:s,originalRegionPoints:a}=t,c={renderingConfig:o,regionCurves:s.map((t=>t.map((t=>({horizontal:{length:t.horizontal.length},vertical:{length:t.vertical.length}}))))),regionPoints:i,originalRegionPoints:a},h=Yr().collect({warpvas:c,options:n,createWarpedCanvas:Ur,calcBoundingBox:Lr,calcPerpendicularIntersection:Br,calcCoordDistance:Ir,calcRelativeCoord:Fr,calcMatrix:kr}).create(((t,{collections:e})=>{const{options:r,warpvas:n,createWarpedCanvas:i,calcBoundingBox:o,calcPerpendicularIntersection:s,calcCoordDistance:a,calcRelativeCoord:c,calcMatrix:h}=e,{width:l,height:u,sourceScale:p=1,destinationScale:f=1}=r,g=new OffscreenCanvas(l*f*p,u*f*p),d=new OffscreenCanvas(t.width,t.height),y=d.getContext("2d");return null==y||y.putImageData(t,0,0),i(n,d,g,r,{calcBoundingBox:o,calcPerpendicularIntersection:s,calcCoordDistance:a,calcRelativeCoord:c,calcMatrix:h}).transferToImageBitmap()})),l=yield h.run(e);return h.terminate(),(r=null!=r?r:document.createElement("canvas")).width=l.width,r.height=l.height,r.getContext("2d").drawImage(l,0,0),r})),qr=(t,e,r,n)=>cr(void 0,void 0,void 0,(function*(){const{regionPoints:i,renderingConfig:o,regionCurves:s,originalRegionPoints:a}=t,c={renderingConfig:o,regionCurves:s.map((t=>t.map((t=>({horizontal:{length:t.horizontal.length},vertical:{length:t.vertical.length}}))))),regionPoints:i,originalRegionPoints:a},h=Yr().collect({warpvas:c,options:n,createWarpedCanvas:Gr}).create(((t,{collections:e})=>{const{options:r,warpvas:n,createWarpedCanvas: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()})),l=yield h.run(e);return h.terminate(),(r=null!=r?r:document.createElement("canvas")).width=l.width,r.height=l.height,r.getContext("2d").drawImage(l,0,0),r}));var Jr,Kr;!function(t){t.TOP_LEFT="tl",t.TOP_RIGHT="tr",t.BOTTOM_LEFT="bl",t.BOTTOM_RIGHT="br"}(Jr||(Jr={})),function(t){t.TOP="top",t.BOTTOM="bottom",t.LEFT="left",t.RIGHT="right"}(Kr||(Kr={}));class Qr{constructor(t,e=1,r=1){if(this.splitPoints=[],this.originalRegions=[],this.originalRegionPoints=[],this.regionBoundaryCurves=[],this.regionCurves=[],this.regionPoints=[],this.splitUnit=.05,this.splitStrategy={name:"default",execute:Qr.strategy},this.renderingContext="webgl",this.renderingConfig={padding:0,enableAntialias:!0,enableSafeRendering:!0,enableContentDisplay:!0,enableGridDisplay:!1,enableGridVertexDisplay:!1,gridColor:{r:255,g:0,b:0,a:1}},this._safeModeEnabled=!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("[Warpvas] 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.splitPoints=this._initializeSplitPoints(e,r),this.setWarpState(this.splitPoints)}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.regionCurves)return[];const e=[];return t.regionBoundaryCurves.forEach(((r,n)=>{const i=[];r.forEach(((e,r)=>{const o=[],{vertical:s,horizontal:a}=t.regionCurves[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 serializeWarpState(t){const{splitPoints:e,regionBounds: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 deserializeWarpState(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 l=[];for(let t=0;t<s;t++)l.push({x:i[h],y:i[h+1]}),h+=2;const u=[];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)}u.push(t)}return{splitPoints:l,regionBounds:u}}_initializeSplitP