UNPKG

fabric-warpvas

Version:

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

1 lines 71.7 kB
!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).fabricWarpvas={},t.fabric)}(this,(function(e,r){"use strict";function n(t,e){return t===e||t!=t&&e!=e}function i(t,e){for(var r=t.length;r--;)if(n(t[r][0],e))return r;return-1}var o=Array.prototype.splice;function s(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])}}s.prototype.clear=function(){this.__data__=[],this.size=0},s.prototype.delete=function(t){var e=this.__data__,r=i(e,t);return!(r<0)&&(r==e.length-1?e.pop():o.call(e,r,1),--this.size,!0)},s.prototype.get=function(t){var e=this.__data__,r=i(e,t);return r<0?void 0:e[r][1]},s.prototype.has=function(t){return i(this.__data__,t)>-1},s.prototype.set=function(t,e){var r=this.__data__,n=i(r,t);return n<0?(++this.size,r.push([t,e])):r[n][1]=e,this};var a="object"==typeof global&&global&&global.Object===Object&&global,c="object"==typeof self&&self&&self.Object===Object&&self,h=a||c||Function("return this")(),l=h.Symbol,u=Object.prototype,p=u.hasOwnProperty,f=u.toString,g=l?l.toStringTag:void 0;var d=Object.prototype.toString;var y="[object Null]",x="[object Undefined]",v=l?l.toStringTag:void 0;function m(t){return null==t?void 0===t?x:y:v&&v in Object(t)?function(t){var e=p.call(t,g),r=t[g];try{t[g]=void 0;var n=!0}catch(t){}var i=f.call(t);return n&&(e?t[g]=r:delete t[g]),i}(t):function(t){return d.call(t)}(t)}function b(t){var e=typeof t;return null!=t&&("object"==e||"function"==e)}var _="[object AsyncFunction]",w="[object Function]",C="[object GeneratorFunction]",R="[object Proxy]";function E(t){if(!b(t))return!1;var e=m(t);return e==w||e==C||e==_||e==R}var S,z=h["__core-js_shared__"],T=(S=/[^.]+$/.exec(z&&z.keys&&z.keys.IE_PROTO||""))?"Symbol(src)_1."+S:"";var O=Function.prototype.toString;function j(t){if(null!=t){try{return O.call(t)}catch(t){}try{return t+""}catch(t){}}return""}var P=/^\[object .+?Constructor\]$/,A=Function.prototype,M=Object.prototype,B=A.toString,I=M.hasOwnProperty,L=RegExp("^"+B.call(I).replace(/[\\^$.*+?()[\]{}|]/g,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$");function F(t){return!(!b(t)||(e=t,T&&T in e))&&(E(t)?L:P).test(j(t));var e}function k(t,e){var r=function(t,e){return null==t?void 0:t[e]}(t,e);return F(r)?r:void 0}var W=k(h,"Map"),U=k(Object,"create");var D=Object.prototype.hasOwnProperty;var G=Object.prototype.hasOwnProperty;function H(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 N(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 $(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])}}H.prototype.clear=function(){this.__data__=U?U(null):{},this.size=0},H.prototype.delete=function(t){var e=this.has(t)&&delete this.__data__[t];return this.size-=e?1:0,e},H.prototype.get=function(t){var e=this.__data__;if(U){var r=e[t];return"__lodash_hash_undefined__"===r?void 0:r}return D.call(e,t)?e[t]:void 0},H.prototype.has=function(t){var e=this.__data__;return U?void 0!==e[t]:G.call(e,t)},H.prototype.set=function(t,e){var r=this.__data__;return this.size+=this.has(t)?0:1,r[t]=U&&void 0===e?"__lodash_hash_undefined__":e,this},$.prototype.clear=function(){this.size=0,this.__data__={hash:new H,map:new(W||s),string:new H}},$.prototype.delete=function(t){var e=N(this,t).delete(t);return this.size-=e?1:0,e},$.prototype.get=function(t){return N(this,t).get(t)},$.prototype.has=function(t){return N(this,t).has(t)},$.prototype.set=function(t,e){var r=N(this,t),n=r.size;return r.set(t,e),this.size+=r.size==n?0:1,this};function X(t){var e=this.__data__=new s(t);this.size=e.size}X.prototype.clear=function(){this.__data__=new s,this.size=0},X.prototype.delete=function(t){var e=this.__data__,r=e.delete(t);return this.size=e.size,r},X.prototype.get=function(t){return this.__data__.get(t)},X.prototype.has=function(t){return this.__data__.has(t)},X.prototype.set=function(t,e){var r=this.__data__;if(r instanceof s){var n=r.__data__;if(!W||n.length<199)return n.push([t,e]),this.size=++r.size,this;r=this.__data__=new $(n)}return r.set(t,e),this.size=r.size,this};var Y=function(){try{var t=k(Object,"defineProperty");return t({},"",{}),t}catch(t){}}();function V(t,e,r){"__proto__"==e&&Y?Y(t,e,{configurable:!0,enumerable:!0,value:r,writable:!0}):t[e]=r}var q=Object.prototype.hasOwnProperty;function J(t,e,r){var i=t[e];q.call(t,e)&&n(i,r)&&(void 0!==r||e in t)||V(t,e,r)}function K(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?V(r,a,c):J(r,a,c)}return r}function Q(t){return null!=t&&"object"==typeof t}function Z(t){return Q(t)&&"[object Arguments]"==m(t)}var tt=Object.prototype,et=tt.hasOwnProperty,rt=tt.propertyIsEnumerable,nt=Z(function(){return arguments}())?Z:function(t){return Q(t)&&et.call(t,"callee")&&!rt.call(t,"callee")},it=Array.isArray;var ot="object"==typeof e&&e&&!e.nodeType&&e,st=ot&&"object"==typeof module&&module&&!module.nodeType&&module,at=st&&st.exports===ot?h.Buffer:void 0,ct=(at?at.isBuffer:void 0)||function(){return!1},ht=9007199254740991,lt=/^(?:0|[1-9]\d*)$/;function ut(t,e){var r=typeof t;return!!(e=null==e?ht:e)&&("number"==r||"symbol"!=r&&lt.test(t))&&t>-1&&t%1==0&&t<e}var pt=9007199254740991;function ft(t){return"number"==typeof t&&t>-1&&t%1==0&&t<=pt}var gt={};function dt(t){return function(e){return t(e)}}gt["[object Float32Array]"]=gt["[object Float64Array]"]=gt["[object Int8Array]"]=gt["[object Int16Array]"]=gt["[object Int32Array]"]=gt["[object Uint8Array]"]=gt["[object Uint8ClampedArray]"]=gt["[object Uint16Array]"]=gt["[object Uint32Array]"]=!0,gt["[object Arguments]"]=gt["[object Array]"]=gt["[object ArrayBuffer]"]=gt["[object Boolean]"]=gt["[object DataView]"]=gt["[object Date]"]=gt["[object Error]"]=gt["[object Function]"]=gt["[object Map]"]=gt["[object Number]"]=gt["[object Object]"]=gt["[object RegExp]"]=gt["[object Set]"]=gt["[object String]"]=gt["[object WeakMap]"]=!1;var yt="object"==typeof e&&e&&!e.nodeType&&e,xt=yt&&"object"==typeof module&&module&&!module.nodeType&&module,vt=xt&&xt.exports===yt&&a.process,mt=function(){try{var t=xt&&xt.require&&xt.require("util").types;return t||vt&&vt.binding&&vt.binding("util")}catch(t){}}(),bt=mt&&mt.isTypedArray,_t=bt?dt(bt):function(t){return Q(t)&&ft(t.length)&&!!gt[m(t)]},wt=Object.prototype.hasOwnProperty;function Ct(t,e){var r=it(t),n=!r&&nt(t),i=!r&&!n&&ct(t),o=!r&&!n&&!i&&_t(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&&!wt.call(t,h)||s&&("length"==h||i&&("offset"==h||"parent"==h)||o&&("buffer"==h||"byteLength"==h||"byteOffset"==h)||ut(h,c))||a.push(h);return a}var Rt=Object.prototype;function Et(t){var e=t&&t.constructor;return t===("function"==typeof e&&e.prototype||Rt)}function St(t,e){return function(r){return t(e(r))}}var zt=St(Object.keys,Object),Tt=Object.prototype.hasOwnProperty;function Ot(t){return null!=t&&ft(t.length)&&!E(t)}function jt(t){return Ot(t)?Ct(t):function(t){if(!Et(t))return zt(t);var e=[];for(var r in Object(t))Tt.call(t,r)&&"constructor"!=r&&e.push(r);return e}(t)}var Pt=Object.prototype.hasOwnProperty;function At(t){if(!b(t))return function(t){var e=[];if(null!=t)for(var r in Object(t))e.push(r);return e}(t);var e=Et(t),r=[];for(var n in t)("constructor"!=n||!e&&Pt.call(t,n))&&r.push(n);return r}function Mt(t){return Ot(t)?Ct(t,!0):At(t)}var Bt="object"==typeof e&&e&&!e.nodeType&&e,It=Bt&&"object"==typeof module&&module&&!module.nodeType&&module,Lt=It&&It.exports===Bt?h.Buffer:void 0,Ft=Lt?Lt.allocUnsafe:void 0;function kt(){return[]}var Wt=Object.prototype.propertyIsEnumerable,Ut=Object.getOwnPropertySymbols,Dt=Ut?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}(Ut(t),(function(e){return Wt.call(t,e)})))}:kt;function Gt(t,e){for(var r=-1,n=e.length,i=t.length;++r<n;)t[i+r]=e[r];return t}var Ht=St(Object.getPrototypeOf,Object),Nt=Object.getOwnPropertySymbols?function(t){for(var e=[];t;)Gt(e,Dt(t)),t=Ht(t);return e}:kt;function $t(t,e,r){var n=e(t);return it(t)?n:Gt(n,r(t))}function Xt(t){return $t(t,jt,Dt)}function Yt(t){return $t(t,Mt,Nt)}var Vt=k(h,"DataView"),qt=k(h,"Promise"),Jt=k(h,"Set"),Kt=k(h,"WeakMap"),Qt="[object Map]",Zt="[object Promise]",te="[object Set]",ee="[object WeakMap]",re="[object DataView]",ne=j(Vt),ie=j(W),oe=j(qt),se=j(Jt),ae=j(Kt),ce=m;(Vt&&ce(new Vt(new ArrayBuffer(1)))!=re||W&&ce(new W)!=Qt||qt&&ce(qt.resolve())!=Zt||Jt&&ce(new Jt)!=te||Kt&&ce(new Kt)!=ee)&&(ce=function(t){var e=m(t),r="[object Object]"==e?t.constructor:void 0,n=r?j(r):"";if(n)switch(n){case ne:return re;case ie:return Qt;case oe:return Zt;case se:return te;case ae:return ee}return e});var he=ce,le=Object.prototype.hasOwnProperty;var ue=h.Uint8Array;function pe(t){var e=new t.constructor(t.byteLength);return new ue(e).set(new ue(t)),e}var fe=/\w*$/;var ge=l?l.prototype:void 0,de=ge?ge.valueOf:void 0;var ye="[object Boolean]",xe="[object Date]",ve="[object Map]",me="[object Number]",be="[object RegExp]",_e="[object Set]",we="[object String]",Ce="[object Symbol]",Re="[object ArrayBuffer]",Ee="[object DataView]",Se="[object Float32Array]",ze="[object Float64Array]",Te="[object Int8Array]",Oe="[object Int16Array]",je="[object Int32Array]",Pe="[object Uint8Array]",Ae="[object Uint8ClampedArray]",Me="[object Uint16Array]",Be="[object Uint32Array]";function Ie(t,e,r){var n,i,o,s=t.constructor;switch(e){case Re:return pe(t);case ye:case xe:return new s(+t);case Ee:return function(t,e){var r=e?pe(t.buffer):t.buffer;return new t.constructor(r,t.byteOffset,t.byteLength)}(t,r);case Se:case ze:case Te:case Oe:case je:case Pe:case Ae:case Me:case Be:return function(t,e){var r=e?pe(t.buffer):t.buffer;return new t.constructor(r,t.byteOffset,t.length)}(t,r);case ve:return new s;case me:case we:return new s(t);case be:return(o=new(i=t).constructor(i.source,fe.exec(i))).lastIndex=i.lastIndex,o;case _e:return new s;case Ce:return n=t,de?Object(de.call(n)):{}}}var Le=Object.create,Fe=function(){function t(){}return function(e){if(!b(e))return{};if(Le)return Le(e);t.prototype=e;var r=new t;return t.prototype=void 0,r}}();var ke=mt&&mt.isMap,We=ke?dt(ke):function(t){return Q(t)&&"[object Map]"==he(t)};var Ue=mt&&mt.isSet,De=Ue?dt(Ue):function(t){return Q(t)&&"[object Set]"==he(t)},Ge=1,He=2,Ne=4,$e="[object Arguments]",Xe="[object Function]",Ye="[object GeneratorFunction]",Ve="[object Object]",qe={};function Je(t,e,r,n,i,o){var s,a=e&Ge,c=e&He,h=e&Ne;if(r&&(s=i?r(t,n,i,o):r(t)),void 0!==s)return s;if(!b(t))return t;var l=it(t);if(l){if(s=function(t){var e=t.length,r=new t.constructor(e);return e&&"string"==typeof t[0]&&le.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=he(t),p=u==Xe||u==Ye;if(ct(t))return function(t,e){if(e)return t.slice();var r=t.length,n=Ft?Ft(r):new t.constructor(r);return t.copy(n),n}(t,a);if(u==Ve||u==$e||p&&!i){if(s=c||p?{}:function(t){return"function"!=typeof t.constructor||Et(t)?{}:Fe(Ht(t))}(t),!a)return c?function(t,e){return K(t,Nt(t),e)}(t,function(t,e){return t&&K(e,Mt(e),t)}(s,t)):function(t,e){return K(t,Dt(t),e)}(t,function(t,e){return t&&K(e,jt(e),t)}(s,t))}else{if(!qe[u])return i?t:{};s=Ie(t,u,a)}}o||(o=new X);var f=o.get(t);if(f)return f;o.set(t,s),De(t)?t.forEach((function(n){s.add(Je(n,e,r,n,t,o))})):We(t)&&t.forEach((function(n,i){s.set(i,Je(n,e,r,i,t,o))}));var g=l?void 0:(h?c?Yt:Xt:c?Mt:jt)(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]),J(s,i,Je(n,e,r,i,t,o))})),s}qe[$e]=qe["[object Array]"]=qe["[object ArrayBuffer]"]=qe["[object DataView]"]=qe["[object Boolean]"]=qe["[object Date]"]=qe["[object Float32Array]"]=qe["[object Float64Array]"]=qe["[object Int8Array]"]=qe["[object Int16Array]"]=qe["[object Int32Array]"]=qe["[object Map]"]=qe["[object Number]"]=qe[Ve]=qe["[object RegExp]"]=qe["[object Set]"]=qe["[object String]"]=qe["[object Symbol]"]=qe["[object Uint8Array]"]=qe["[object Uint8ClampedArray]"]=qe["[object Uint16Array]"]=qe["[object Uint32Array]"]=!0,qe["[object Error]"]=qe[Xe]=qe["[object WeakMap]"]=!1;function Ke(t){return t}var Qe=Math.max;var Ze=Y?function(t,e){return Y(t,"toString",{configurable:!0,enumerable:!1,value:(r=e,function(){return r}),writable:!0});var r}:Ke,tr=Ze,er=Date.now;var rr,nr,ir,or=(rr=tr,nr=0,ir=0,function(){var t=er(),e=16-(t-ir);if(ir=t,e>0){if(++nr>=800)return arguments[0]}else nr=0;return rr.apply(void 0,arguments)});var sr=Object.prototype,ar=sr.hasOwnProperty,cr=function(t,e){return or(function(t,e,r){return e=Qe(void 0===e?t.length-1:e,0),function(){for(var n=arguments,i=-1,o=Qe(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,Ke),t+"")}((function(t,e){t=Object(t);var r=-1,i=e.length,o=i>2?e[2]:void 0;for(o&&function(t,e,r){if(!b(r))return!1;var i=typeof e;return!!("number"==i?Ot(r)&&ut(e,r.length):"string"==i&&e in r)&&n(r[e],t)}(e[0],e[1],o)&&(i=1);++r<i;)for(var s=e[r],a=Mt(s),c=-1,h=a.length;++c<h;){var l=a[c],u=t[l];(void 0===u||n(u,sr[l])&&!ar.call(t,l))&&(t[l]=s[l])}return t}));function hr(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:lr,cos:ur,sin:pr,acos:fr,atan2:gr,sqrt:dr,pow:yr}=Math;function xr(t){return t<0?-yr(-t,1/3):yr(t,1/3)}const vr=Math.PI,mr=2*vr,br=vr/2,_r=Number.MAX_SAFE_INTEGER||9007199254740991,wr=Number.MIN_SAFE_INTEGER||-9007199254740991,Cr={x:0,y:0,z:0},Rr={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),dr(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],Cr],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||Rr.approximately(t,e)||Rr.approximately(t,r)},approximately:function(t,e,r){return lr(t-e)<=(r||1e-6)},length:function(t){const e=Rr.Tvalues.length;let r=0;for(let n,i=0;i<e;i++)n=.5*Rr.Tvalues[i]+.5,r+=Rr.Cvalues[i]*Rr.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(Rr.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 gr(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 dr(r*r+n*n)},closest:function(t,e){let r,n,i=yr(2,63);return t.forEach((function(t,o){n=Rr.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=yr(t,e)+yr(1-t,e);return lr((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=yr(1-t,e);return r/(yr(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 Rr.lli8(i,o,s,a,c,h,l,u)},lli:function(t,e){return Rr.lli4(t,t.c,e,e.c)},makeline:function(t,e){return new Br(t.x,t.y,(t.x+e.x)/2,(t.y+e.y)/2,e.x,e.y)},findbbox:function(t){let e=_r,r=_r,n=wr,i=wr;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(!Rr.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=Rr.makeline(e.points[n-1],t.points[0]),s=Rr.makeline(t.points[i-1],e.points[0]),a={startcap:o,forward:t,back:e,endcap:s,bbox:Rr.findbbox([o,t,e,s]),intersections:function(t){return Rr.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=_r,s=wr;-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=-gr(e.p2.y-n,e.p2.x-r);return t.map((function(t){return{x:(t.x-r)*ur(i)-(t.y-n)*pr(i),y:(t.x-r)*pr(i)+(t.y-n)*ur(i)}}))},roots:function(t,e){e=e||{p1:{x:0,y:0},p2:{x:1,y:0}};const r=t.length-1,n=Rr.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=-dr(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(Rr.approximately(c,0)){if(Rr.approximately(h,0))return Rr.approximately(l,0)?[]:[-u/l].filter(i);const t=dr(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=dr(t*t*t),r=-g/(2*e),n=fr(r<-1?-1:r>1?1:r),o=2*xr(e);return m=o*ur(n/3)-h/3,b=o*ur((n+mr)/3)-h/3,_=o*ur((n+2*mr)/3)-h/3,[m,b,_].filter(i)}if(0===y)return x=d<0?xr(-d):-xr(d),m=2*x-h/3,b=-x-h/3,[m,b].filter(i);{const t=dr(y);return x=xr(-d+t),v=xr(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=-dr(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=Rr.compute(t,e),p=Rr.compute(t,r),f=u.x*u.x+u.y*u.y;if(n?(o=dr(yr(u.y*p.z-p.y*u.z,2)+yr(u.z*p.x-p.z*u.x,2)+yr(u.x*p.y-p.x*u.y,2)),s=yr(f+u.z*u.z,1.5)):(o=u.x*p.y-u.y*p.x,s=yr(f,1.5)),0===o||0===s)return{k:0,r:0};if(h=o/s,l=s/o,!i){const i=Rr.curvature(t-.001,e,r,n,!0).k,o=Rr.curvature(t+.001,e,r,n,!0).k;c=(o-h+(h-i))/2,a=(lr(o-h)+lr(h-i))/2}return{k:h,r:l,dk:c,adk:a}},inflections:function(t){if(t.length<4)return[];const e=Rr.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(Rr.approximately(o,0)){if(!Rr.approximately(s,0)){let t=-a/s;if(0<=t&&t<=1)return[t]}return[]}const c=2*o;if(Rr.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,lr(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 Rr.bboxoverlap(t.left.bbox(),t.right.bbox())}));let l=[];return 0===h.length||(h.forEach((function(t){l=l.concat(Rr.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*ur(br)-i*pr(br),c=n*pr(br)+i*ur(br),h=o*ur(br)-s*pr(br),l=o*pr(br)+s*ur(br),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=Rr.lli8(u,p,d,y,f,g,x,v),b=Rr.dist(m,t);let _,w=gr(t.y-m.y,t.x-m.x),C=gr(e.y-m.y,e.x-m.x),R=gr(r.y-m.y,r.x-m.x);return w<R?((w>C||C>R)&&(w+=mr),w>R&&(_=R,R=w,w=_)):R<C&&C<w?(_=R,R=w,w=_):R+=mr,m.s=w,m.e=R,m.r=b,m},numberSort:function(t,e){return t-e}};class Er{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 Rr.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++)Rr.expandbox(e,t[r].bbox());return e}offset(t){const e=[];return this.curves.forEach((function(r){e.push(...r.offset(t))})),new Er(e)}}const{abs:Sr,min:zr,max:Tr,cos:Or,sin:jr,acos:Pr,sqrt:Ar}=Math,Mr=Math.PI;class Br{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=Rr.align(s,{p1:s[0],p2:s[c]}),u=Rr.dist(s[0],s[c]);this._linear=l.reduce(((t,e)=>t+Sr(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 Br(e,e,r);if(1===n)return new Br(t,e,e);const i=Br.getABC(2,t,e,r,n);return new Br(t,i.A,r)}static cubicFromPoints(t,e,r,n,i){void 0===n&&(n=.5);const o=Br.getABC(3,t,e,r,n);void 0===i&&(i=Rr.dist(e,o.C));const s=i*(1-n)/n,a=Rr.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 Br(t,C,R,r)}static getUtils(){return Rr}getUtils(){return Br.getUtils()}static get PolyBezier(){return Er}valueOf(){return this.toString()}toString(){return Rr.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=Rr.derive(this.points,this._3d),this.computedirection()}computedirection(){const t=this.points,e=Rr.angle(t[0],t[this.order],t[1]);this.clockwise=e>0}length(){return Rr.length(this.derivative.bind(this))}static getABC(t=2,e,r,n,i=.5){const o=Rr.projectionratio(i,t),s=1-o,a={x:o*e.x+s*n.x,y:o*e.y+s*n.y},c=Rr.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 Br.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],Rr.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=Rr.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=Rr.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?Rr.computeWithRatios(t,this.points,this.ratios,this._3d):Rr.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 Br(e)}derivative(t){return Rr.compute(t,this.dpoints[0],this._3d)}dderivative(t){return Rr.compute(t,this.dpoints[1],this._3d)}align(){let t=this.points;return new Br(Rr.align(t,{p1:t[0],p2:t[t.length-1]}))}curvature(t){return Rr.curvature(t,this.dpoints[0],this.dpoints[1],this._3d)}inflections(){return Rr.inflections(this.points)}normal(t){return this._3d?this.__normal3(t):this.__normal2(t)}__normal2(t){const e=this.derivative(t),r=Ar(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=Ar(e.x*e.x+e.y*e.y+e.z*e.z),i=Ar(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=Ar(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=Rr.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 Br([r[0],r[3],r[5]]):new Br([r[0],r[4],r[7],r[9]]),right:2===this.order?new Br([r[5],r[4],r[2]]):new Br([r[9],r[8],r[6],r[3]]),span:r};return n.left._t1=Rr.map(0,0,1,this._t1,this._t2),n.left._t2=Rr.map(t,0,1,this._t1,this._t2),n.right._t1=Rr.map(t,0,1,this._t1,this._t2),n.right._t2=Rr.map(1,0,1,this._t1,this._t2),e?(e=Rr.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]=Rr.droots(i),3===this.order&&(i=this.dpoints[1].map(n),t[r]=t[r].concat(Rr.droots(i))),t[r]=t[r].filter((function(t){return t>=0&&t<=1})),e=e.concat(t[r].sort(Rr.numberSort))}.bind(this)),t.values=e.sort(Rr.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]=Rr.getminmax(this,r,t[r])}.bind(this)),e}overlaps(t){const e=this.bbox(),r=t.bbox();return Rr.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 Br(r)]}return this.reduce().map((function(e){return e._linear?e.offset(t)[0]:e.scale(t)}))}simple(){if(3===this.order){const t=Rr.angle(this.points[0],this.points[3],this.points[1]),e=Rr.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),Sr(Pr(r))<Mr/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,Sr(r-n)<i)return[];e=t.split(r,n),e._t1=Rr.map(r,0,1,t._t1,t._t2),e._t2=Rr.map(n,0,1,t._t1,t._t2),s.push(e),r=n;break}r<1&&(e=t.split(r,1),e._t1=Rr.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 Br(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=Rr.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]=Rr.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=Ar(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 Br(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]=Rr.lli4(r,o,h,i[t+1])})),new Br(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=Rr.makeline(u[2],l[0]),f=Rr.makeline(l[2],u[0]),g=[p,new Br(l),f,new Br(u)];return new Er(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 Rr.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=Rr.makeline(d,f),v=Rr.makeline(g,y),m=[x].concat(s).concat([v]).concat(c);return new Er(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=Rr.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 Br&&(t=t.reduce()),this.curveintersects(this.reduce(),t,e)):this.selfintersects(e)}lineIntersects(t){const e=zr(t.p1.x,t.p2.x),r=zr(t.p1.y,t.p2.y),n=Tr(t.p1.x,t.p2.x),i=Tr(t.p1.y,t.p2.y);return Rr.roots(this.points,t).filter((t=>{var o=this.get(t);return Rr.between(o.x,e,n)&&Rr.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=Rr.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=Rr.dist(t,e),c=Rr.dist(t,o),h=Rr.dist(t,s);return Sr(c-a)+Sr(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=Rr.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*Or(a.e),y:a.y+a.r*jr(a.e)};a.e+=Rr.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 Ir=(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}},Lr=(t,e)=>Math.sqrt(Math.pow(e.x-t.x,2)+Math.pow(e.y-t.y,2)),Fr=(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}},kr=(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},Wr=(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]},Ur=(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},Dr=(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},Gr=(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,Dr(t,e,r,n,{calcBoundingBox:Fr,calcPerpendicularIntersection:Ir,calcCoordDistance:Lr,calcRelativeCoord:kr,calcMatrix:Wr})},Hr=(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},Nr=(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,Hr(t,e,r,n)},$r="WORKER_MESSAGE",Xr="JOB_RESULT",Yr=t=>t instanceof ArrayBuffer||t instanceof MessagePort||self.ImageBitmap&&t instanceof ImageBitmap,Vr=()=>{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 = ${Yr}\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: '${$r}', message }),\n close: self.close,\n }]))\n ).then(result => {\n postMessage({ type: '${Xr}', message: { index, result } }, [result].filter($isTransferables))\n }).catch(error => {\n postMessage({ type: '${Xr}', 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===$r&&e&&e.call(e,n.message),n.type===Xr){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(Yr))})),terminate:()=>{a.terminate(),URL.revokeObjectURL(s),t.length=0,r.clear(),e=void 0}}}};return n},qr=(t,e,r,n)=>hr(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=Vr().collect({warpvas:c,options:n,createWarpedCanvas:Dr,calcBoundingBox:Fr,calcPerpendicularIntersection:Ir,calcCoordDistance:Lr,calcRelativeCoord:kr,calcMatrix:Wr}).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})),Jr=(t,e,r,n)=>hr(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=Vr().collect({warpvas:c,options:n,createWarpedCanvas:Hr}).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 Kr,Qr;!function(t){t.TOP_LEFT="tl",t.TOP_RIGHT="tr",t.BOTTOM_LEFT="bl",t.BOTTOM_RIGHT="br"}(Kr||(Kr={})),function(t){t.TOP="top",t.BOTTOM="bottom",t.LEFT="left",t.RIGHT="right"}(Qr||(Qr={}));class Zr{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:Zr.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(