svg-morpheus-ts
Version:
ESM TypeScript library enabling SVG icons to morph from one to the other. It implements Material Design's Delightful Details transitions. Refactored with modern TypeScript + Vite + pnpm stack. Supports both Chinese and English documentation.
7 lines (6 loc) • 32.9 kB
JavaScript
(function($,F){typeof exports=="object"&&typeof module<"u"?F(exports):typeof define=="function"&&define.amd?define(["exports"],F):($=typeof globalThis<"u"?globalThis:$||self,F($.SVGMorpheus={}))})(this,function($){"use strict";const F=window,pt=F.requestAnimationFrame||F.mozRequestAnimationFrame||F.webkitRequestAnimationFrame||F.oRequestAnimationFrame,Et=F.cancelAnimationFrame||F.mozCancelAnimationFrame||F.webkitCancelAnimationFrame||F.oCancelAnimationFrame;function rt(t,s,e){const n={};for(const r in t){const o=r;switch(o){case"fill":case"stroke":if(t[o]&&s[o]){const i=t[o],a=s[o];if(typeof i=="string"||typeof a=="string")n[o]=e<.5?i:a;else{const f=i,l=a;n[o]=j(f),n[o].r=f.r+(l.r-f.r)*e,n[o].g=f.g+(l.g-f.g)*e,n[o].b=f.b+(l.b-f.b)*e,n[o].opacity=f.opacity+(l.opacity-f.opacity)*e}}break;case"opacity":case"fill-opacity":case"stroke-opacity":case"stroke-width":typeof t[o]=="number"&&typeof s[o]=="number"&&(n[o]=t[o]+(s[o]-t[o])*e);break}}return n}function R(t){const s={};for(const e in t){const n=e;switch(n){case"fill":case"stroke":if(t[n]){const r=t[n];typeof r=="string"?s[n]=r:s[n]=Dt(r)}break;case"opacity":case"fill-opacity":case"stroke-opacity":case"stroke-width":typeof t[n]=="number"&&(s[n]=t[n]);break}}return s}function it(t,s){const e=[{},{}],n=r=>typeof r=="string"&&r.trim().startsWith("url(#");for(const r in t){const o=r;switch(o){case"fill":case"stroke":t[o]&&(n(t[o])?(e[0][o]=t[o],s[o]===void 0&&(e[1][o]=t[o])):(e[0][o]=U(t[o]),s[o]===void 0&&(e[1][o]=U(t[o]),e[1][o].opacity=0)));break;case"opacity":case"fill-opacity":case"stroke-opacity":case"stroke-width":t[o]&&(e[0][o]=t[o],s[o]===void 0&&(e[1][o]=1));break}}for(const r in s){const o=r;switch(o){case"fill":case"stroke":s[o]&&(n(s[o])?(e[1][o]=s[o],t[o]===void 0&&(e[0][o]=s[o])):(e[1][o]=U(s[o]),t[o]===void 0&&(e[0][o]=U(s[o]),e[0][o].opacity=0)));break;case"opacity":case"fill-opacity":case"stroke-opacity":case"stroke-width":s[o]&&(e[1][o]=s[o],t[o]===void 0&&(e[0][o]=1));break}}return e}function It(t,s,e){const n={};for(const r in t){const o=r;switch(o){case"rotate":if(t[o]&&s[o]){n[o]=[0,0,0];for(let i=0;i<3;i++){const a=t[o][i],f=s[o][i];isFinite(a)&&isFinite(f)&&isFinite(e)?n[o][i]=a+(f-a)*e:n[o][i]=isFinite(a)?a:0}}break}}return n}function _t(t){let s="";if(t.rotate&&t.rotate.length===3){const[e,n,r]=t.rotate;isFinite(e)&&isFinite(n)&&isFinite(r)?s+="rotate("+t.rotate.join(" ")+")":s+="rotate(0 0 0)"}return s}function bt(t,s,e){const n=[];for(let r=0,o=t.length;r<o;r++){if(n.push([t[r][0]]),!s[r]){for(let i=1,a=t[r].length;i<a;i++)n[r].push(t[r][i]);continue}for(let i=1,a=t[r].length;i<a;i++){const f=t[r][i],l=s[r]&&s[r][i]!==void 0?s[r][i]:f;n[r].push(f+(l-f)*e)}}return n}function j(t){let s;if(t instanceof Array){s=[];for(let e=0,n=t.length;e<n;e++)s[e]=j(t[e]);return s}if(t instanceof Object){s={};for(const e in t)t.hasOwnProperty(e)&&(s[e]=j(t[e]));return s}return t}const vt=`
\v\f\r \u2028\u2029`,St={hs:1,rg:1},Nt="hasOwnProperty",Ft=/^\s*((#[a-f\d]{6})|(#[a-f\d]{3})|rgba?\(\s*([\d\.]+%?\s*,\s*[\d\.]+%?\s*,\s*[\d\.]+%?(?:\s*,\s*[\d\.]+%?)?)\s*\)|hsba?\(\s*([\d\.]+(?:deg|\xb0|%)?\s*,\s*[\d\.]+%?\s*,\s*[\d\.]+(?:%?\s*,\s*[\d\.]+)?%?)\s*\)|hsla?\(\s*([\d\.]+(?:deg|\xb0|%)?\s*,\s*[\d\.]+%?\s*,\s*[\d\.]+(?:%?\s*,\s*[\d\.]+)?%?)\s*\))\s*$/i,at=new RegExp("["+vt+"]*,["+vt+"]*"),Dt=function(t){const s=Math.round;return"rgba("+[s(t.r),s(t.g),s(t.b),+t.opacity.toFixed(2)]+")"},qt=function(t){const s=window.document.getElementsByTagName("head")[0]||window.document.getElementsByTagName("svg")[0],e="rgb(255, 0, 0)";return function(r){var i;if(r.toLowerCase()==="red")return e;s.style.color=e,s.style.color=r;const o=(i=window.document.defaultView)==null?void 0:i.getComputedStyle(s,"").getPropertyValue("color");return o===e?null:o||null}(t)},yt=function(t,s,e,n){const r=Math.round(t*255),o=Math.round(s*255),i=Math.round(e*255);return{r,g:o,b:i,opacity:isFinite(n)?n:1}},Gt=function(t,s,e,n){typeof t=="object"&&"h"in t&&"s"in t&&"b"in t&&(e=t.b,s=t.s,n=t.o,t=t.h);const r=t*360;let o,i,a,f,l;const u=r%360/60;l=e*s,f=l*(1-Math.abs(u%2-1)),o=i=a=e-l;const m=~~u;return o+=[l,f,0,0,f,l][m],i+=[f,l,l,f,0,0][m],a+=[0,0,f,l,l,f][m],yt(o,i,a,n)},Pt=function(t,s,e,n){typeof t=="object"&&"h"in t&&"s"in t&&"l"in t&&(e=t.l,s=t.s,n=t.o,t=t.h);let r=t,o=s,i=e;(r>1||o>1||i>1)&&(r/=360,o/=100,i/=100),r*=360;let a,f,l,u,m;const I=r%360/60;m=2*o*(i<.5?i:1-i),u=m*(1-Math.abs(I%2-1)),a=f=l=i-m/2;const c=~~I;return a+=[m,u,0,0,u,m][c],f+=[u,m,m,u,0,0][c],l+=[0,0,u,m,m,u][c],yt(a,f,l,n)},U=function(t){if(!t||(t=String(t)).indexOf("-")+1)return{r:-1,g:-1,b:-1,opacity:-1,error:1};if(t==="none")return{r:-1,g:-1,b:-1,opacity:-1};if(St[Nt](t.toLowerCase().substring(0,2))||t.charAt(0)==="#"||(t=qt(t)||""),!t)return{r:-1,g:-1,b:-1,opacity:-1,error:1};let s=0,e=0,n=0,r=1,o,i;const a=t.match(Ft);return a?(a[2]&&(n=parseInt(a[2].substring(5),16),e=parseInt(a[2].substring(3,5),16),s=parseInt(a[2].substring(1,3),16)),a[3]&&(n=parseInt((o=a[3].charAt(3))+o,16),e=parseInt((o=a[3].charAt(2))+o,16),s=parseInt((o=a[3].charAt(1))+o,16)),a[4]&&(i=a[4].split(at),s=parseFloat(i[0]),i[0].slice(-1)==="%"&&(s*=2.55),e=parseFloat(i[1]),i[1].slice(-1)==="%"&&(e*=2.55),n=parseFloat(i[2]),i[2].slice(-1)==="%"&&(n*=2.55),a[1].toLowerCase().slice(0,4)==="rgba"&&(r=parseFloat(i[3])),i[3]&&i[3].slice(-1)==="%"&&(r/=100)),a[5]?(i=a[5].split(at),s=parseFloat(i[0]),i[0].slice(-1)==="%"&&(s/=100),e=parseFloat(i[1]),i[1].slice(-1)==="%"&&(e/=100),n=parseFloat(i[2]),i[2].slice(-1)==="%"&&(n/=100),(i[0].slice(-3)==="deg"||i[0].slice(-1)==="°")&&(s/=360),a[1].toLowerCase().slice(0,4)==="hsba"&&(r=parseFloat(i[3])),i[3]&&i[3].slice(-1)==="%"&&(r/=100),Gt(s,e,n,r)):a[6]?(i=a[6].split(at),s=parseFloat(i[0]),i[0].slice(-1)==="%"&&(s/=100),e=parseFloat(i[1]),i[1].slice(-1)==="%"&&(e/=100),n=parseFloat(i[2]),i[2].slice(-1)==="%"&&(n/=100),(i[0].slice(-3)==="deg"||i[0].slice(-1)==="°")&&(s/=360),a[1].toLowerCase().slice(0,4)==="hsla"&&(r=parseFloat(i[3])),i[3]&&i[3].slice(-1)==="%"&&(r/=100),Pt(s,e,n,r)):(s=Math.min(Math.round(s),255),e=Math.min(Math.round(e),255),n=Math.min(Math.round(n),255),r=Math.min(Math.max(r,0),1),{r:s,g:e,b:n,opacity:isFinite(r)?r:1})):{r:-1,g:-1,b:-1,opacity:-1,error:1}};async function wt(t,s){const e=[];for(const[a,f]of Object.entries(t)){let l;if(jt(f))l=f;else try{const d=await fetch(f);if(!d.ok){console.warn(`Failed to load SVG from ${f}`);continue}l=await d.text()}catch(d){console.warn(`Error loading SVG from ${f}:`,d);continue}const u=Mt(l),m=ct(l),c=lt(l).fill;let h=Bt(l);c&&["path","polygon","rect","circle","ellipse","line","polyline"].forEach(g=>{const v=new RegExp(`<${g}(\\s[^>]*)?>`,"gi");h=h.replace(v,p=>/fill\s*=\s*['"][^'"]*['"]/i.test(p)?p:p.endsWith("/>")?p.replace(new RegExp(`<${g}(\\s*)`),`<${g}$1 fill="${c}" `):p.replace(new RegExp(`<${g}(\\s*)`),`<${g}$1 fill="${c}" `))});let _=`id="${a}"`;u&&(_+=` data-original-viewbox="${u.original}"`),(Object.keys(m.gradients).length>0||Object.keys(m.patterns).length>0)&&(_+=' data-has-defs="true"');const b=`<g ${_}>${h}</g>`;e.push(b)}const r={...{xmlns:"http://www.w3.org/2000/svg",style:"display:none;"},...s};return`<svg ${Object.entries(r).map(([a,f])=>`${a}="${f}"`).join(" ")}>
${e.join(`
`)}
</svg>`}async function Vt(t,s){const e=await wt(t,s),n=new Blob([e],{type:"image/svg+xml"});return URL.createObjectURL(n)}async function Rt(t,s){return wt(t,s)}function jt(t){const s=t.trim();return s.startsWith("<?xml")?s.includes("<svg"):!!(s.startsWith("<svg")||s.startsWith("<!DOCTYPE svg"))}function Bt(t){let s=t.trim();s=s.replace(/<\?xml[^?]*\?>\s*/gi,""),s=s.replace(/<!DOCTYPE[^>]*>\s*/gi,""),s=s.replace(/<\?[^?]*\?>\s*/gi,""),s=s.trim();const e=s.match(/<svg[^>]*>([\s\S]*?)<\/svg>/i);if(e&&e[1])return e[1].trim();if(s.startsWith("<svg")){const n=s.indexOf(">");if(n!==-1){const r=s.substring(n+1),o=r.lastIndexOf("</svg>");if(o!==-1)return r.substring(0,o).trim()}}return s}function Mt(t){const s=t.match(/<svg[^>]*>/i);if(!s)return null;const n=s[0].match(/viewBox\s*=\s*["']([^"']+)["']/i);if(!n)return null;const r=n[1],o=r.trim().split(/\s+/).map(Number);return o.length!==4?null:{values:[o[0],o[1],o[2],o[3]],original:r}}function ct(t){const s={gradients:{},patterns:{},others:{},raw:void 0},e=t.match(/<defs[^>]*>([\s\S]*?)<\/defs>/i);if(!e)return s;s.raw=e[0];const n=e[1],r=n.match(/<linearGradient[^>]*>[\s\S]*?<\/linearGradient>/gi);r&&r.forEach(f=>{const l=f.match(/id\s*=\s*["']([^"']+)["']/i);l&&(s.gradients[l[1]]=f)});const o=n.match(/<radialGradient[^>]*>[\s\S]*?<\/radialGradient>/gi);o&&o.forEach(f=>{const l=f.match(/id\s*=\s*["']([^"']+)["']/i);l&&(s.gradients[l[1]]=f)});const i=n.match(/<pattern[^>]*>[\s\S]*?<\/pattern>/gi);i&&i.forEach(f=>{const l=f.match(/id\s*=\s*["']([^"']+)["']/i);l&&(s.patterns[l[1]]=f)});const a=n.match(/<(?!linearGradient|radialGradient|pattern)[^>]+>[\s\S]*?<\/[^>]+>/gi);return a&&a.forEach(f=>{const l=f.match(/id\s*=\s*["']([^"']+)["']/i);l&&(s.others[l[1]]=f)}),s}function lt(t){const s=t.match(/<svg([^>]*)>/i);if(!s)return{};const e={},r=s[1].match(/(\w+)\s*=\s*["']([^"']*)["']/g);return r&&r.forEach(o=>{const[,i,a]=o.match(/(\w+)\s*=\s*["']([^"']*)["']/)||[];i&&a&&(e[i]=a)}),e}const x={};x["circ-in"]=function(t){return-1*(Math.sqrt(1-t*t)-1)},x["circ-out"]=function(t){return Math.sqrt(1-(t=t-1)*t)},x["circ-in-out"]=function(t){return(t/=1/2)<1?-1/2*(Math.sqrt(1-t*t)-1):1/2*(Math.sqrt(1-(t-=2)*t)+1)},x["cubic-in"]=function(t){return t*t*t},x["cubic-out"]=function(t){return--t*t*t+1},x["cubic-in-out"]=function(t){return t<.5?4*t*t*t:(t-1)*(2*t-2)*(2*t-2)+1},x["elastic-in"]=function(t){var n=1.70158,s=0,e=1;if(t==0)return 0;if(t==1)return 1;if(s||(s=.3),e<Math.abs(1)){e=1;var n=s/4}else var n=s/(2*Math.PI)*Math.asin(1/e);return-(e*Math.pow(2,10*(t-=1))*Math.sin((t-n)*(2*Math.PI)/s))},x["elastic-out"]=function(t){var n=1.70158,s=0,e=1;if(t==0)return 0;if(t==1)return 1;if(s||(s=.3),e<Math.abs(1)){e=1;var n=s/4}else var n=s/(2*Math.PI)*Math.asin(1/e);return e*Math.pow(2,-10*t)*Math.sin((t-n)*(2*Math.PI)/s)+1},x["elastic-in-out"]=function(t){var n=1.70158,s=0,e=1;if(t==0)return 0;if((t/=1/2)==2)return 1;if(s||(s=1*(.3*1.5)),e<Math.abs(1)){e=1;var n=s/4}else var n=s/(2*Math.PI)*Math.asin(1/e);return t<1?-.5*(e*Math.pow(2,10*(t-=1))*Math.sin((t-n)*(2*Math.PI)/s)):e*Math.pow(2,-10*(t-=1))*Math.sin((t-n)*(2*Math.PI)/s)*.5+1},x["expo-in"]=function(t){return t==0?0:Math.pow(2,10*(t-1))},x["expo-out"]=function(t){return t==1?1:1-Math.pow(2,-10*t)},x["expo-in-out"]=function(t){return t==0?0:t==1?1:(t/=1/2)<1?1/2*Math.pow(2,10*(t-1)):1/2*(-Math.pow(2,-10*--t)+2)},x.linear=function(t){return t},x["quad-in"]=function(t){return t*t},x["quad-out"]=function(t){return t*(2-t)},x["quad-in-out"]=function(t){return t<.5?2*t*t:-1+(4-2*t)*t},x["quart-in"]=function(t){return t*t*t*t},x["quart-out"]=function(t){return 1- --t*t*t*t},x["quart-in-out"]=function(t){return t<.5?8*t*t*t*t:1-8*--t*t*t*t},x["quint-in"]=function(t){return t*t*t*t*t},x["quint-out"]=function(t){return 1+--t*t*t*t*t},x["quint-in-out"]=function(t){return t<.5?16*t*t*t*t*t:1+16*--t*t*t*t*t},x["sine-in"]=function(t){return 1-Math.cos(t*(Math.PI/2))},x["sine-out"]=function(t){return Math.sin(t*(Math.PI/2))},x["sine-in-out"]=function(t){return 1/2*(1-Math.cos(Math.PI*t))};const X=`
\v\f\r \u2028\u2029`,Ot=new RegExp("([a-z])["+X+",]*((-?\\d*\\.?\\d*(?:e[\\-+]?\\d+)?["+X+"]*,?["+X+"]*)+)","ig"),Tt=new RegExp("(-?\\d*\\.?\\d*(?:e[\\-+]?\\d+)?)["+X+"]*,?["+X+"]*","ig");function ut(t){if(!t)return null;if(Array.isArray(t))return t;{const s={a:7,c:6,o:2,h:1,l:2,m:2,r:4,q:4,s:4,t:2,v:1,u:3,z:0},e=[];return String(t).replace(Ot,function(n,r,o){const i=[];let a=r.toLowerCase();if(o.replace(Tt,function(f,l){return l&&i.push(+l),""}),a==="m"&&i.length>2&&(e.push([r.charCodeAt(0)].concat(i.splice(0,2))),a="l",r=r==="m"?"l":"L"),a==="o"&&i.length===1&&e.push([r.charCodeAt(0),i[0]]),a==="r")e.push([r.charCodeAt(0)].concat(i));else for(;i.length>=s[a]&&(e.push([r.charCodeAt(0)].concat(i.splice(0,s[a]))),!!s[a]););return""}),e}}function Q(t){const s=ut(t);if(!s||!s.length)return[["M",0,0]];const e=[];let n=0,r=0,o=0,i=0,a=0;s[0][0]===77&&(n=+s[0][1],r=+s[0][2],o=n,i=r,a++,e[0]=["M",n,r]);for(let f=a,l=s.length;f<l;f++){const u=[],m=s[f],I=m[0],c=String.fromCharCode(I);if(c!==c.toUpperCase())switch(u[0]=c.toUpperCase(),u[0]){case"A":u[1]=m[1],u[2]=m[2],u[3]=m[3],u[4]=m[4],u[5]=m[5],u[6]=+m[6]+n,u[7]=+m[7]+r;break;case"V":u[1]=+m[1]+r;break;case"H":u[1]=+m[1]+n;break;case"M":o=+m[1]+n,i=+m[2]+r;default:for(let h=1,_=m.length;h<_;h++)u[h]=+m[h]+(h%2?n:r);break}else{u[0]=c;for(let h=1,_=m.length;h<_;h++)u[h]=m[h]}switch(u[0]){case"Z":n=o,r=i;break;case"H":n=u[1];break;case"V":r=u[1];break;case"M":o=u[1],i=u[2],n=u[1],r=u[2];break;default:n=u[u.length-2],r=u[u.length-1]}e.push(u)}return e}function Z(t,s){const e=Q(t),n=s&&Q(s),r={x:0,y:0,bx:0,by:0,X:0,Y:0,qx:null,qy:null},o={x:0,y:0,bx:0,by:0,X:0,Y:0,qx:null,qy:null},i=function(c,h,_){let b,d;if(!c)return["C",h.x,h.y,h.x,h.y,h.x,h.y];switch(!(c[0]in{T:1,Q:1})&&(h.qx=h.qy=null),c[0]){case"M":h.X=c[1],h.Y=c[2];break;case"A":c=["C"].concat(kt.apply(0,[h.x,h.y].concat(c.slice(1))));break;case"S":_=="C"||_=="S"?(b=h.x*2-h.bx,d=h.y*2-h.by):(b=h.x,d=h.y),c=["C",b,d].concat(c.slice(1));break;case"T":_=="Q"||_=="T"?(h.qx=h.x*2-h.qx,h.qy=h.y*2-h.qy):(h.qx=h.x,h.qy=h.y),c=["C"].concat(xt(h.x,h.y,h.qx,h.qy,c[1],c[2]));break;case"Q":h.qx=c[1],h.qy=c[2],c=["C"].concat(xt(h.x,h.y,c[1],c[2],c[3],c[4]));break;case"L":c=["C"].concat(J(h.x,h.y,c[1],c[2]));break;case"H":c=["C"].concat(J(h.x,h.y,c[1],h.y));break;case"V":c=["C"].concat(J(h.x,h.y,h.x,c[1]));break;case"Z":c=["C"].concat(J(h.x,h.y,h.X,h.Y));break}return c},a=function(c,h){if(c[h].length>7){c[h].shift();const _=c[h];for(;_.length;)l[h]="A",n&&(u[h]="A"),c.splice(h++,0,["C"].concat(_.splice(0,6)));c.splice(h,1)}},f=function(c,h,_,b,d){c&&h&&c[d][0]=="M"&&h[d][0]!="M"&&(h.splice(d,0,["M",b.x,b.y]),_.bx=0,_.by=0,_.x=c[d][1],_.y=c[d][2])},l=[],u=[];let m="",I="";for(let c=0,h=Math.max(e.length,n&&n.length||0);c<h;c++){e[c]&&(m=e[c][0]),m!="C"&&(l[c]=m,c&&(I=l[c-1])),e[c]=i(e[c],r,I),l[c]!="A"&&m=="C"&&(l[c]="C"),a(e,c),n&&(n[c]&&(m=n[c][0]),m!="C"&&(u[c]=m,c&&(I=u[c-1])),n[c]=i(n[c],o,I),u[c]!="A"&&m=="C"&&(u[c]="C"),a(n,c)),f(e,n,r,o,c),f(n,e,o,r,c);const _=e[c],b=n&&n[c],d=_.length,g=n&&b.length;r.x=_[d-2],r.y=_[d-1],r.bx=parseFloat(_[d-4])||r.x,r.by=parseFloat(_[d-3])||r.y,o.bx=n&&(parseFloat(b[g-4])||o.x),o.by=n&&(parseFloat(b[g-3])||o.y),o.x=n&&b[g-2],o.y=n&&b[g-1]}return n?[e,n]:e}const J=function(t,s,e,n){return[t,s,e,n,e,n]},xt=function(t,s,e,n,r,o){var i=.3333333333333333,a=2/3;return[i*t+a*e,i*s+a*n,i*r+a*e,i*o+a*n,r,o]},kt=function(t,s,e,n,r,o,i,a,f,l){var u=Math.PI*120/180,m=Math.PI/180*(+r||0),I=[],c,h=function(nt,ot,Y){var gt=nt*Math.cos(Y)-ot*Math.sin(Y),L=nt*Math.sin(Y)+ot*Math.cos(Y);return{x:gt,y:L}};if(l)w=l[0],M=l[1],y=l[2],C=l[3];else{c=h(t,s,-m),t=c.x,s=c.y,c=h(a,f,-m),a=c.x,f=c.y;var _=(t-a)/2,b=(s-f)/2,d=_*_/(e*e)+b*b/(n*n);d>1&&(d=Math.sqrt(d),e=d*e,n=d*n);var g=e*e,v=n*n,p=(o==i?-1:1)*Math.sqrt(Math.abs((g*v-g*b*b-v*_*_)/(g*b*b+v*_*_))),y=p*e*b/n+(t+a)/2,C=p*-n*_/e+(s+f)/2,w=Math.asin(+((s-C)/n).toFixed(9)),M=Math.asin(+((f-C)/n).toFixed(9));w=t<y?Math.PI-w:w,M=a<y?Math.PI-M:M,w<0&&(w=Math.PI*2+w),M<0&&(M=Math.PI*2+M),i&&w>M&&(w=w-Math.PI*2),!i&&M>w&&(M=M-Math.PI*2)}var k=M-w;if(Math.abs(k)>u){var S=M,D=a,P=f;M=w+u*(i&&M>w?1:-1),a=y+e*Math.cos(M),f=C+n*Math.sin(M),I=kt(a,f,e,n,r,0,i,D,P,[M,S,y,C])}k=M-w;var N=Math.cos(w),et=Math.sin(w),V=Math.cos(M),st=Math.sin(M),z=Math.tan(k/4),B=4/3*e*z,O=4/3*n*z,E=[t,s],A=[t+B*et,s-O*N],mt=[a+B*st,f-O*V],dt=[a,f];if(A[0]=2*E[0]-A[0],A[1]=2*E[1]-A[1],l)return[A,mt,dt].concat(I);I=[A,mt,dt].concat(I).join().split(",");for(var W=[],q=0,T=I.length;q<T;q++)W[q]=q%2?h(I[q-1],I[q],m).y:h(I[q],I[q+1],m).x;return W},Yt=/,?([a-z]),?/gi;function ft(t){return t.join(",").replace(Yt,"$1")}function H(t){if(!t||!Array.isArray(t)||t.length===0)return K(0,0,0,0);let s=0,e=0;const n=[],r=[];let o;for(let u=0,m=t.length;u<m;u++)if(o=t[u],o[0]=="M")s=isFinite(o[1])?o[1]:0,e=isFinite(o[2])?o[2]:0,n.push(s),r.push(e);else{const I=s,c=e,h=isFinite(o[1])?o[1]:0,_=isFinite(o[2])?o[2]:0,b=isFinite(o[3])?o[3]:0,d=isFinite(o[4])?o[4]:0,g=isFinite(o[5])?o[5]:0,v=isFinite(o[6])?o[6]:0,p=Lt(I,c,h,_,b,d,g,v);isFinite(p.min.x)&&isFinite(p.max.x)&&isFinite(p.min.y)&&isFinite(p.max.y)&&(n.push(p.min.x,p.max.x),r.push(p.min.y,p.max.y)),s=g,e=v}if(n.length===0||r.length===0)return K(0,0,0,0);const i=Math.min(...n),a=Math.min(...r),f=Math.max(...n),l=Math.max(...r);return!isFinite(i)||!isFinite(a)||!isFinite(f)||!isFinite(l)?K(0,0,0,0):K(i,a,f-i,l-a)}const K=function(t,s,e,n){return t=isFinite(t)?t:0,s=isFinite(s)?s:0,e=isFinite(e)?e:0,n=isFinite(n)?n:0,{x:t,y:s,w:e,h:n,cx:t+e/2,cy:s+n/2}},Lt=function(t,s,e,n,r,o,i,a){for(var f=[],l=[[],[]],u,m,I,c,h,_,b,d,g=0;g<2;++g){if(g==0?(m=6*t-12*e+6*r,u=-3*t+9*e-9*r+3*i,I=3*e-3*t):(m=6*s-12*n+6*o,u=-3*s+9*n-9*o+3*a,I=3*n-3*s),Math.abs(u)<1e-12){if(Math.abs(m)<1e-12)continue;c=-I/m,0<c&&c<1&&f.push(c);continue}b=m*m-4*I*u,d=Math.sqrt(b),!(b<0)&&(h=(-m+d)/(2*u),0<h&&h<1&&f.push(h),_=(-m-d)/(2*u),0<_&&_<1&&f.push(_))}for(var v=f.length,p=v,y;v--;)c=f[v],y=1-c,l[0][v]=y*y*y*t+3*y*y*c*e+3*y*c*c*r+c*c*c*i,l[1][v]=y*y*y*s+3*y*y*c*n+3*y*c*c*o+c*c*c*a;return l[0][p]=t,l[1][p]=s,l[0][p+1]=i,l[1][p+1]=a,l[0].length=l[1].length=p+2,{min:{x:Math.min.apply(0,l[0]),y:Math.min.apply(0,l[1])},max:{x:Math.max.apply(0,l[0]),y:Math.max.apply(0,l[1])}}};function $t(t,s){const[e,n,r,o]=t.values,[i,a,f,l]=s.values,u=f/r,m=l/o,I=i-e*u,c=a-n*m;return{scaleX:u,scaleY:m,translateX:I,translateY:c}}function G(t,s,e){return[t*e.scaleX+e.translateX,s*e.scaleY+e.translateY]}function Xt(t,s){if(!t||!t.trim())return t;try{const e=ut(t),r=Q(e).map(o=>{const i=o[0],a=o.slice(1),f=[i];switch(i){case"M":case"L":if(a.length>=2){const[l,u]=G(a[0],a[1],s);f.push(l,u);for(let m=2;m<a.length;m+=2)if(m+1<a.length){const[I,c]=G(a[m],a[m+1],s);f.push(I,c)}}break;case"C":if(a.length>=6){for(let l=0;l<a.length;l+=2)if(l+1<a.length){const[u,m]=G(a[l],a[l+1],s);f.push(u,m)}}break;case"Q":if(a.length>=4){for(let l=0;l<a.length;l+=2)if(l+1<a.length){const[u,m]=G(a[l],a[l+1],s);f.push(u,m)}}break;case"A":if(a.length>=7){const l=a[0]*s.scaleX,u=a[1]*s.scaleY,[m,I]=G(a[5],a[6],s);f.push(l,u,a[2],a[3],a[4],m,I)}break;case"H":if(a.length>=1){const[l]=G(a[0],0,s);f.push(l)}break;case"V":if(a.length>=1){const[,l]=G(0,a[0],s);f.push(l)}break;case"Z":case"z":break;default:for(let l=0;l<a.length;l+=2)if(l+1<a.length){const[u,m]=G(a[l],a[l+1],s);f.push(u,m)}else f.push(a[l])}return f});return ft(r)}catch(e){return console.warn("Path transformation failed:",e),t}}function Ct(t,s="",e){const n={gradients:{},patterns:{},others:{}};for(const[r,o]of Object.entries(t.gradients)){const i=s+r;let a=o;a=a.replace(new RegExp(`id="${r}"`,"g"),`id="${i}"`),a=a.replace(new RegExp(`id='${r}'`,"g"),`id='${i}'`),e&&(a=Ht(a,e)),n.gradients[i]=a}for(const[r,o]of Object.entries(t.patterns)){const i=s+r;let a=o;a=a.replace(new RegExp(`id="${r}"`,"g"),`id="${i}"`),a=a.replace(new RegExp(`id='${r}'`,"g"),`id='${i}'`),e&&(a=zt(a,e)),n.patterns[i]=a}for(const[r,o]of Object.entries(t.others)){const i=s+r;let a=o;a=a.replace(new RegExp(`id="${r}"`,"g"),`id="${i}"`),a=a.replace(new RegExp(`id='${r}'`,"g"),`id='${i}'`),n.others[i]=a}return n}function Ht(t,s){let e=t;return t.includes("linearGradient")&&(e=e.replace(/\b(x1|y1|x2|y2)=["']([^"']+)["']/g,(n,r,o)=>{const i=ht(r,o,s);return`${r}="${i}"`})),t.includes("radialGradient")&&(e=e.replace(/\b(cx|cy|fx|fy|r)=["']([^"']+)["']/g,(n,r,o)=>{const i=ht(r,o,s);return`${r}="${i}"`})),e}function zt(t,s){let e=t;return e=e.replace(/\b(x|y|width|height)=["']([^"']+)["']/g,(n,r,o)=>{const i=ht(r,o,s);return`${r}="${i}"`}),e}function ht(t,s,e){if(s.endsWith("%"))return s;const n=parseFloat(s);if(isNaN(n))return s;let r;switch(t){case"x1":case"x2":case"cx":case"fx":case"x":r=n*e.scaleX+e.translateX;break;case"y1":case"y2":case"cy":case"fy":case"y":r=n*e.scaleY+e.translateY;break;case"r":r=n*Math.sqrt(e.scaleX*e.scaleY);break;case"width":r=n*e.scaleX;break;case"height":r=n*e.scaleY;break;default:r=n}return r.toFixed(3)}function tt(t,s,e){let n={...s};for(const[r,o]of Object.entries(n))if(typeof o=="string"&&o.startsWith("url(#")){const i=o.match(/url\(#([^)]+)\)/);i&&e[i[1]]&&(n[r]=`url(#${e[i[1]]})`)}return{pathData:t,attrs:n}}class At{constructor(s,e,n){if(this._icons={},this._curIconId="",this._toIconId="",this._curIconItems=[],this._fromIconItems=[],this._toIconItems=[],this._morphNodes=[],this._morphG=null,this._svgDoc=null,!s)throw new Error('SVGMorpheus > "element" is required');let r;if(typeof s=="string"){const i=document.querySelector(s);if(!i)throw new Error('SVGMorpheus > "element" query is not related to an existing DOM node');r=i}else r=s;if(e&&typeof e!="object")throw new Error('SVGMorpheus > "options" parameter must be an object');if(e=e||{},n&&typeof n!="function")throw new Error('SVGMorpheus > "callback" parameter must be a function');const o=this;this._icons={},this._curIconId=e.iconId||"",this._toIconId="",this._curIconItems=[],this._fromIconItems=[],this._toIconItems=[],this._morphNodes=[],this._morphG=null,this._startTime=void 0,this._defDuration=e.duration||750,this._defEasing=e.easing||"quad-in-out",this._defRotation=e.rotation||"clock",this._defCallback=n||function(){},this._duration=this._defDuration,this._easing=this._defEasing,this._rotation=this._defRotation,this._callback=this._defCallback,this._rafid=void 0,this._fnTick=function(i){o._startTime||(o._startTime=i);const a=Math.min((i-o._startTime)/o._duration,1);o._updateAnimationProgress(a),a<1?o._rafid=pt(o._fnTick):o._toIconId!==""&&o._animationEnd()},r.nodeName.toUpperCase()==="SVG"?this._svgDoc=r:this._svgDoc=r.getSVGDocument(),this._svgDoc?o._init():r.addEventListener("load",function(){o._svgDoc=r.getSVGDocument(),o._init()},!1)}_init(){if(this._svgDoc){if(this._svgDoc.nodeName.toUpperCase()!=="SVG"){const s=this._svgDoc.getElementsByTagName("svg");this._svgDoc=s[0]}if(this._svgDoc){let s="";const e=this._svgDoc.outerHTML,n=Mt(e),r=ct(e),o=lt(e);for(let a=this._svgDoc.childNodes.length-1;a>=0;a--){const f=this._svgDoc.childNodes[a];if(f.nodeName.toUpperCase()==="G"){const l=f,u=l.getAttribute("id");if(u){const m=[];let I=n||void 0,c=r,h=o;const _=l.getAttribute("data-original-viewbox");if(_){const g=_.trim().split(/\s+/).map(Number);g.length===4&&(I={values:[g[0],g[1],g[2],g[3]],original:_})}const b=l.outerHTML,d=ct(b);c={gradients:{...r.gradients,...d.gradients},patterns:{...r.patterns,...d.patterns},others:{...r.others,...d.others},raw:d.raw||r.raw},h={...o,...lt(b)};for(let g=0,v=l.childNodes.length;g<v;g++){const p=l.childNodes[g],y={path:"",attrs:{},style:{}};switch(p.nodeName.toUpperCase()){case"PATH":y.path=p.getAttribute("d")||"";break;case"CIRCLE":const C=p,w=parseFloat(C.getAttribute("cx")||"0"),M=parseFloat(C.getAttribute("cy")||"0"),k=parseFloat(C.getAttribute("r")||"0");y.path=`M${w-k},${M}a${k},${k} 0 1,0 ${k*2},0a${k},${k} 0 1,0 -${k*2},0z`;break;case"ELLIPSE":const S=p,D=parseFloat(S.getAttribute("cx")||"0"),P=parseFloat(S.getAttribute("cy")||"0"),N=parseFloat(S.getAttribute("rx")||"0"),et=parseFloat(S.getAttribute("ry")||"0");y.path=`M${D-N},${P}a${N},${et} 0 1,0 ${N*2},0a${N},${et} 0 1,0 -${N*2},0z`;break;case"RECT":const V=p,st=parseFloat(V.getAttribute("x")||"0"),z=parseFloat(V.getAttribute("y")||"0"),B=parseFloat(V.getAttribute("width")||"0"),O=parseFloat(V.getAttribute("height")||"0"),E=parseFloat(V.getAttribute("rx")||"0"),A=parseFloat(V.getAttribute("ry")||"0");!E&&!A?y.path=`M${st},${z}l${B},0l0,${O}l-${B},0z`:y.path=`M${st+E},${z}l${B-E*2},0a${E},${A} 0 0,1 ${E},${A}l0,${O-A*2}a${E},${A} 0 0,1 -${E},${A}l${E*2-B},0a${E},${A} 0 0,1 -${E},-${A}l0,${A*2-O}a${E},${A} 0 0,1 ${E},-${A}z`;break;case"POLYGON":const W=(p.getAttribute("points")||"").split(/\s+/);let q="";for(let L=0,Wt=W.length;L<Wt;L++)q+=(L&&"L"||"M")+W[L];y.path=q+"z";break;case"LINE":const T=p,nt=parseFloat(T.getAttribute("x1")||"0"),ot=parseFloat(T.getAttribute("y1")||"0"),Y=parseFloat(T.getAttribute("x2")||"0"),gt=parseFloat(T.getAttribute("y2")||"0");y.path=`M${nt},${ot}L${Y},${gt}z`;break}if(y.path!==""){for(let w=0,M=p.attributes.length;w<M;w++){const k=p.attributes[w];if(k.specified){const S=k.name.toLowerCase();switch(S){case"fill":case"fill-opacity":case"opacity":case"stroke":case"stroke-opacity":case"stroke-width":y.attrs[S]=k.value}}}const C=p.style;for(let w=0,M=C.length;w<M;w++){const k=C[w];switch(k){case"fill":case"fill-opacity":case"opacity":case"stroke":case"stroke-opacity":case"stroke-width":y.style[k]=C[k]}}m.push(y)}}if(m.length>0){const g={id:u,items:m,viewBox:I,defs:c,rootAttrs:h};this._icons[u]=g}this._morphG?this._svgDoc.removeChild(f):(s=u,this._morphG=document.createElementNS("http://www.w3.org/2000/svg","g"),this._svgDoc.replaceChild(this._morphG,f))}}}const i=this._curIconId||s;i!==""&&(this._setupAnimation(i),this._updateAnimationProgress(1),this._animationEnd())}}}_setupAnimation(s){var e,n,r,o,i,a,f,l;if(s&&this._icons[s]){this._toIconId=s,this._startTime=void 0;let u,m;this._fromIconItems=j(this._curIconItems),this._toIconItems=j(this._icons[s].items);const I=this._icons[this._curIconId],c=this._icons[s],h=c.viewBox||(I==null?void 0:I.viewBox)||{values:[0,0,24,24],original:"0 0 24 24"};if(this._svgDoc&&this._svgDoc.setAttribute("viewBox",h.original),I&&I.viewBox&&c.viewBox){const d=$t(I.viewBox,h),g=`from_${this._curIconId}_`,v={};I.defs&&(Object.keys(I.defs.gradients).forEach(p=>{v[p]=g+p}),Object.keys(I.defs.patterns).forEach(p=>{v[p]=g+p}),Object.keys(I.defs.others).forEach(p=>{v[p]=g+p})),this._fromIconItems=this._fromIconItems.map(p=>{const y=Xt(p.path,d),C=tt(y,p.attrs,v),w=tt(y,p.style,v);return{...p,path:y,attrs:C.attrs,style:w.attrs}})}if(c.defs){const d=`to_${s}_`,g={};Object.keys(c.defs.gradients).forEach(v=>{g[v]=d+v}),Object.keys(c.defs.patterns).forEach(v=>{g[v]=d+v}),Object.keys(c.defs.others).forEach(v=>{g[v]=d+v}),this._toIconItems=this._toIconItems.map(v=>{const p=tt(v.path,v.attrs,g),y=tt(v.path,v.style,g);return{...v,attrs:p.attrs,style:y.attrs}}),this._injectTransformedDefs(I,c)}for(u=0,m=this._morphNodes.length;u<m;u++){const d=this._morphNodes[u];d.fromIconItemIdx=u,d.toIconItemIdx=u}const _=Math.max(this._fromIconItems.length,this._toIconItems.length);let b;for(u=0;u<_;u++)if(this._fromIconItems[u]||(this._toIconItems[u]?(b=H(Z(this._toIconItems[u].path)),this._fromIconItems.push({path:"M"+b.cx+","+b.cy+"l0,0",attrs:{},style:{},trans:{rotate:[0,b.cx,b.cy]}})):this._fromIconItems.push({path:"M0,0l0,0",attrs:{},style:{},trans:{rotate:[0,0,0]}})),this._toIconItems[u]||(this._fromIconItems[u]?(b=H(Z(this._fromIconItems[u].path)),this._toIconItems.push({path:"M"+b.cx+","+b.cy+"l0,0",attrs:{},style:{},trans:{rotate:[0,b.cx,b.cy]}})):this._toIconItems.push({path:"M0,0l0,0",attrs:{},style:{},trans:{rotate:[0,0,0]}})),!this._morphNodes[u]&&this._morphG){const d=document.createElementNS("http://www.w3.org/2000/svg","path");this._morphG.appendChild(d),this._morphNodes.push({node:d,fromIconItemIdx:u,toIconItemIdx:u})}for(u=0;u<_;u++){const d=this._fromIconItems[u],g=this._toIconItems[u],v=Z(this._fromIconItems[u].path,this._toIconItems[u].path);d.curve=v[0],g.curve=v[1];const p=it(this._fromIconItems[u].attrs,this._toIconItems[u].attrs);d.attrsNorm=p[0],g.attrsNorm=p[1],d.attrs=R(d.attrsNorm),g.attrs=R(g.attrsNorm);const y=it(this._fromIconItems[u].style,this._toIconItems[u].style);d.styleNorm=y[0],g.styleNorm=y[1],d.style=R(d.styleNorm),g.style=R(g.styleNorm),b=H(g.curve);let C=0,w=0,M=0;for(let P=0;P<this._toIconItems.length;P++)if(this._toIconItems[P].curve){const N=H(this._toIconItems[P].curve);N&&!isNaN(N.cx)&&!isNaN(N.cy)&&(C+=N.cx,w+=N.cy,M++)}const k=M>0?{x:C/M,y:w/M}:{x:12,y:12};g.trans={rotate:[0,k.x,k.y]},d.trans?d.trans.rotate&&(d.trans.rotate[0]=0,d.trans.rotate[1]=k.x,d.trans.rotate[2]=k.y):d.trans={rotate:[0,k.x,k.y]};let S=this._rotation,D;switch(S==="random"&&(S=Math.random()<.5?"counterclock":"clock"),S){case"none":(e=d.trans)!=null&&e.rotate&&((n=g.trans)!=null&&n.rotate)&&(g.trans.rotate[0]=d.trans.rotate[0]);break;case"counterclock":(r=d.trans)!=null&&r.rotate&&((o=g.trans)!=null&&o.rotate)?(g.trans.rotate[0]=d.trans.rotate[0]-360,D=-d.trans.rotate[0]%360,g.trans.rotate[0]+=D<180?D:D-360):(i=g.trans)!=null&&i.rotate&&(g.trans.rotate[0]=-360);break;default:(a=d.trans)!=null&&a.rotate&&((f=g.trans)!=null&&f.rotate)?(g.trans.rotate[0]=d.trans.rotate[0]+360,D=d.trans.rotate[0]%360,g.trans.rotate[0]+=D<180?-D:360-D):(l=g.trans)!=null&&l.rotate&&(g.trans.rotate[0]=360);break}}this._curIconItems=j(this._fromIconItems)}}_updateAnimationProgress(s){s=x[this._easing](s);let e,n,r,o;for(e=0,o=this._curIconItems.length;e<o;e++)this._fromIconItems[e].curve&&this._toIconItems[e].curve&&(this._curIconItems[e].curve=bt(this._fromIconItems[e].curve,this._toIconItems[e].curve,s),this._curIconItems[e].path=ft(this._curIconItems[e].curve)),this._fromIconItems[e].attrsNorm&&this._toIconItems[e].attrsNorm&&(this._curIconItems[e].attrsNorm=rt(this._fromIconItems[e].attrsNorm,this._toIconItems[e].attrsNorm,s),this._curIconItems[e].attrs=R(this._curIconItems[e].attrsNorm)),this._fromIconItems[e].styleNorm&&this._toIconItems[e].styleNorm&&(this._curIconItems[e].styleNorm=rt(this._fromIconItems[e].styleNorm,this._toIconItems[e].styleNorm,s),this._curIconItems[e].style=R(this._curIconItems[e].styleNorm)),this._fromIconItems[e].trans&&this._toIconItems[e].trans&&(this._curIconItems[e].trans=It(this._fromIconItems[e].trans,this._toIconItems[e].trans,s),this._curIconItems[e].transStr=_t(this._curIconItems[e].trans));for(e=0,o=this._morphNodes.length;e<o;e++){const i=this._morphNodes[e];i.node.setAttribute("d",this._curIconItems[e].path);const a=this._curIconItems[e].attrs;for(n in a)i.node.setAttribute(n,a[n]);const f=this._curIconItems[e].style;for(r in f)i.node.style[r]=f[r];i.node.setAttribute("transform",this._curIconItems[e].transStr||"")}}_animationEnd(){for(let s=this._morphNodes.length-1;s>=0;s--){const e=this._morphNodes[s];if(this._toIconItems[s]){e.node.setAttribute("d",this._toIconItems[s].path);const n=this._toIconItems[s].attrs;for(const i in n)e.node.setAttribute(i,n[i]);const r=this._toIconItems[s].style;for(const i in r)e.node.style[i]=r[i];const o=this._toIconItems[s].transStr||"";e.node.setAttribute("transform",o)}else e.node.parentNode&&e.node.parentNode.removeChild(e.node),this._morphNodes.splice(s,1)}this._curIconId=this._toIconId,this._toIconId="",this._callback()}to(s,e,n){if(s!==this._toIconId){if(e&&typeof e!="object")throw new Error('SVGMorpheus.to() > "options" parameter must be an object');if(e=e||{},n&&typeof n!="function")throw new Error('SVGMorpheus.to() > "callback" parameter must be a function');this._rafid&&Et(this._rafid),this._duration=e.duration||this._defDuration,this._easing=e.easing||this._defEasing,this._rotation=e.rotation||this._defRotation,this._callback=n||this._defCallback,this._setupAnimation(s),this._rafid=pt(this._fnTick)}}registerEasing(s,e){x[s]=e}_injectTransformedDefs(s,e){if(!this._svgDoc)return;let n=this._svgDoc.querySelector("defs");if(n||(n=document.createElementNS("http://www.w3.org/2000/svg","defs"),this._svgDoc.insertBefore(n,this._svgDoc.firstChild)),s&&s.defs&&s.viewBox){const r=`from_${this._curIconId}_`,o=e.viewBox||{values:[0,0,24,24]},i=$t(s.viewBox,o),a=Ct(s.defs,r,i);this._insertDefsContent(n,a)}if(e.defs){const r=`to_${e.id}_`,o=Ct(e.defs,r);this._insertDefsContent(n,o)}}_insertDefsContent(s,e){const n=new DOMParser;Object.values(e.gradients).forEach(r=>{try{const i=n.parseFromString(`<svg xmlns="http://www.w3.org/2000/svg">${r}</svg>`,"image/svg+xml").documentElement.firstElementChild;if(i){const a=document.importNode(i,!0);s.appendChild(a)}}catch(o){console.warn("Failed to parse gradient:",r,o)}}),Object.values(e.patterns).forEach(r=>{try{const i=n.parseFromString(`<svg xmlns="http://www.w3.org/2000/svg">${r}</svg>`,"image/svg+xml").documentElement.firstElementChild;if(i){const a=document.importNode(i,!0);s.appendChild(a)}}catch(o){console.warn("Failed to parse pattern:",r,o)}}),Object.values(e.others).forEach(r=>{try{const i=n.parseFromString(`<svg xmlns="http://www.w3.org/2000/svg">${r}</svg>`,"image/svg+xml").documentElement.firstElementChild;if(i){const a=document.importNode(i,!0);s.appendChild(a)}}catch(o){console.warn("Failed to parse other def:",r,o)}})}}$.SVGMorpheus=At,$.bundleSvgs=Vt,$.bundleSvgsString=Rt,$.clone=j,$.curveCalc=bt,$.curvePathBBox=H,$.default=At,$.easings=x,$.parsePathString=ut,$.path2curve=Z,$.path2string=ft,$.pathToAbsolute=Q,$.styleNormCalc=rt,$.styleNormToString=R,$.styleToNorm=it,$.trans2string=_t,$.transCalc=It,Object.defineProperties($,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});