gun-avatar
Version:
Avatar generator for GUN public keys
461 lines (403 loc) • 31.2 kB
JavaScript
var It=Object.create;var tt=Object.defineProperty;var Ct=Object.getOwnPropertyDescriptor;var _t=Object.getOwnPropertyNames;var Dt=Object.getPrototypeOf,Ut=Object.prototype.hasOwnProperty;var F=(r,e)=>()=>(e||r((e={exports:{}}).exports,e),e.exports);var Bt=(r,e,n,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of _t(e))!Ut.call(r,o)&&o!==n&&tt(r,o,{get:()=>e[o],enumerable:!(i=Ct(e,o))||i.enumerable});return r};var J=(r,e,n)=>(n=r!=null?It(Dt(r)):{},Bt(e||!r||!r.__esModule?tt(n,"default",{value:r,enumerable:!0}):n,r));var V=F(j=>{var it;(function(r){typeof DO_NOT_EXPORT_CRC>"u"?typeof j=="object"?r(j):typeof define=="function"&&define.amd?define(function(){var e={};return r(e),e}):r(it={}):r(it={})})(function(r){r.version="0.3.0";function e(){for(var a=0,t=new Array(256),l=0;l!=256;++l)a=l,a=a&1?-306674912^a>>>1:a>>>1,a=a&1?-306674912^a>>>1:a>>>1,a=a&1?-306674912^a>>>1:a>>>1,a=a&1?-306674912^a>>>1:a>>>1,a=a&1?-306674912^a>>>1:a>>>1,a=a&1?-306674912^a>>>1:a>>>1,a=a&1?-306674912^a>>>1:a>>>1,a=a&1?-306674912^a>>>1:a>>>1,t[l]=a;return typeof Int32Array<"u"?new Int32Array(t):t}var n=e(),i=typeof Buffer<"u";function o(a){if(a.length>32768&&i)return f(new Buffer(a));for(var t=-1,l=a.length-1,p=0;p<l;)t=n[(t^a.charCodeAt(p++))&255]^t>>>8,t=n[(t^a.charCodeAt(p++))&255]^t>>>8;return p===l&&(t=t>>>8^n[(t^a.charCodeAt(p))&255]),t^-1}function s(a){if(a.length>1e4)return f(a);for(var t=-1,l=0,p=a.length-3;l<p;)t=t>>>8^n[(t^a[l++])&255],t=t>>>8^n[(t^a[l++])&255],t=t>>>8^n[(t^a[l++])&255],t=t>>>8^n[(t^a[l++])&255];for(;l<p+3;)t=t>>>8^n[(t^a[l++])&255];return t^-1}function f(a){for(var t=-1,l=0,p=a.length-7;l<p;)t=t>>>8^n[(t^a[l++])&255],t=t>>>8^n[(t^a[l++])&255],t=t>>>8^n[(t^a[l++])&255],t=t>>>8^n[(t^a[l++])&255],t=t>>>8^n[(t^a[l++])&255],t=t>>>8^n[(t^a[l++])&255],t=t>>>8^n[(t^a[l++])&255],t=t>>>8^n[(t^a[l++])&255];for(;l<p+7;)t=t>>>8^n[(t^a[l++])&255];return t^-1}function c(a){for(var t=-1,l=0,p=a.length,d,u;l<p;)d=a.charCodeAt(l++),d<128?t=t>>>8^n[(t^d)&255]:d<2048?(t=t>>>8^n[(t^(192|d>>6&31))&255],t=t>>>8^n[(t^(128|d&63))&255]):d>=55296&&d<57344?(d=(d&1023)+64,u=a.charCodeAt(l++)&1023,t=t>>>8^n[(t^(240|d>>8&7))&255],t=t>>>8^n[(t^(128|d>>2&63))&255],t=t>>>8^n[(t^(128|u>>6&15|d&3))&255],t=t>>>8^n[(t^(128|u&63))&255]):(t=t>>>8^n[(t^(224|d>>12&15))&255],t=t>>>8^n[(t^(128|d>>6&63))&255],t=t>>>8^n[(t^(128|d&63))&255]);return t^-1}r.table=n,r.bstr=o,r.buf=s,r.str=c})});var lt=F((oe,st)=>{var Lt=V();st.exports=Nt;var v=new Uint8Array(4),qt=new Int32Array(v.buffer),Pt=new Uint32Array(v.buffer);function Nt(r){if(r[0]!==137)throw new Error("Invalid .png file header");if(r[1]!==80)throw new Error("Invalid .png file header");if(r[2]!==78)throw new Error("Invalid .png file header");if(r[3]!==71)throw new Error("Invalid .png file header");if(r[4]!==13)throw new Error("Invalid .png file header: possibly caused by DOS-Unix line ending conversion?");if(r[5]!==10)throw new Error("Invalid .png file header: possibly caused by DOS-Unix line ending conversion?");if(r[6]!==26)throw new Error("Invalid .png file header");if(r[7]!==10)throw new Error("Invalid .png file header: possibly caused by DOS-Unix line ending conversion?");for(var e=!1,n=[],i=8;i<r.length;){v[3]=r[i++],v[2]=r[i++],v[1]=r[i++],v[0]=r[i++];var o=Pt[0]+4,s=new Uint8Array(o);s[0]=r[i++],s[1]=r[i++],s[2]=r[i++],s[3]=r[i++];var f=String.fromCharCode(s[0])+String.fromCharCode(s[1])+String.fromCharCode(s[2])+String.fromCharCode(s[3]);if(!n.length&&f!=="IHDR")throw new Error("IHDR header missing");if(f==="IEND"){e=!0,n.push({name:f,data:new Uint8Array(0)});break}for(var c=4;c<o;c++)s[c]=r[i++];v[3]=r[i++],v[2]=r[i++],v[1]=r[i++],v[0]=r[i++];var a=qt[0],t=Lt.buf(s);if(t!==a)throw new Error("CRC values for "+f+" header do not match, PNG file is likely corrupted");var l=new Uint8Array(s.buffer.slice(4));n.push({name:f,data:l})}if(!e)throw new Error(".png file ended prematurely: no IEND header was found");return n}});var ft=F((ie,ct)=>{ct.exports=function(r,e,n){var i=[],o=r.length;if(o===0)return i;var s=e<0?Math.max(0,e+o):e||0;for(n!==void 0&&(o=n<0?n+o:n);o-- >s;)i[o-s]=r[o];return i}});var pt=F((se,dt)=>{var Ot=ft(),Rt=V();dt.exports=Xt;var y=new Uint8Array(4),Gt=new Int32Array(y.buffer),Tt=new Uint32Array(y.buffer);function Xt(r){var e=8,n=e,i;for(i=0;i<r.length;i++)e+=r[i].data.length,e+=12;var o=new Uint8Array(e);for(o[0]=137,o[1]=80,o[2]=78,o[3]=71,o[4]=13,o[5]=10,o[6]=26,o[7]=10,i=0;i<r.length;i++){var s=r[i],f=s.name,c=s.data,a=c.length,t=[f.charCodeAt(0),f.charCodeAt(1),f.charCodeAt(2),f.charCodeAt(3)];Tt[0]=a,o[n++]=y[3],o[n++]=y[2],o[n++]=y[1],o[n++]=y[0],o[n++]=t[0],o[n++]=t[1],o[n++]=t[2],o[n++]=t[3];for(var l=0;l<a;)o[n++]=c[l++];var p=t.concat(Ot(c)),d=Rt.buf(p);Gt[0]=d,o[n++]=y[3],o[n++]=y[2],o[n++]=y[1],o[n++]=y[0]}return o}});var mt=F((le,ut)=>{ut.exports=Ht;function Ht(r,e){if(r=String(r),e=String(e),!/^[\x00-\xFF]+$/.test(r)||!/^[\x00-\xFF]+$/.test(e))throw new Error("Only Latin-1 characters are permitted in PNG tEXt chunks. You might want to consider base64 encoding and/or zEXt compression");if(r.length>=80)throw new Error('Keyword "'+r+'" is longer than the 79-character limit imposed by the PNG specification');for(var n=r.length+e.length+1,i=new Uint8Array(n),o=0,s,f=0;f<r.length;f++){if(!(s=r.charCodeAt(f)))throw new Error("0x00 character is not permitted in tEXt keywords");i[o++]=s}i[o++]=0;for(var c=0;c<e.length;c++){if(!(s=e.charCodeAt(c)))throw new Error("0x00 character is not permitted in tEXt content");i[o++]=s}return{name:"tEXt",data:i}}});var xt=F((ce,ht)=>{ht.exports=Jt;function Jt(r){r.data&&r.name&&(r=r.data);for(var e=!0,n="",i="",o=0;o<r.length;o++){var s=r[o];if(e)s?i+=String.fromCharCode(s):e=!1;else if(s)n+=String.fromCharCode(s);else throw new Error("Invalid NULL character found. 0x00 character is not permitted in tEXt content")}return{keyword:i,text:n}}});var gt=F(k=>{k.encode=mt();k.decode=xt()});var et=()=>{if(typeof window>"u"||typeof window.CanvasRenderingContext2D>"u"||!n())return;let r=CanvasRenderingContext2D.prototype,e=r.drawImage;if(!e){console.error("This script requires a basic implementation of drawImage");return}r.drawImage=function(c,a,t){if(!(arguments.length===9))return e.apply(this,[...arguments]);let p=i(...arguments);if(!o(p))return e.apply(this,p)};function n(){let f=document.createElement("canvas").getContext("2d");f.fillRect(0,0,40,40),f.drawImage(f.canvas,-40,-40,80,80,50,50,20,20);let c=f.getImageData(50,50,30,30),a=new Uint32Array(c.data.buffer),t=(d,u)=>a[u*c.width+d],l=[[9,9],[20,9],[9,20],[20,20]],p=[[10,10],[19,10],[10,19],[19,19]];return l.some(([d,u])=>t(d,u)!==0)||p.some(([d,u])=>t(d,u)===0)}function i(f,c,a,t,l,p,d,u,m){let{width:b,height:E}=s(f);t<0&&(c+=t,t=Math.abs(t)),l<0&&(a+=l,l=Math.abs(l)),u<0&&(p+=u,u=Math.abs(u)),m<0&&(d+=m,m=Math.abs(m));let x=Math.max(c,0),M=Math.min(c+t,b),g=Math.max(a,0),h=Math.min(a+l,E),A=u/t,w=m/l;return[f,x,g,M-x,h-g,c<0?p-c*A:p,a<0?d-a*w:d,(M-x)*A,(h-g)*w]}function o(f){return[3,4,7,8].some(c=>!f[c])}function s(f){let c=a=>{let t=globalThis[a];return t&&f instanceof t};if(c("HTMLImageElement"))return{width:f.naturalWidth,height:f.naturalHeight};if(c("HTMLVideoElement"))return{width:f.videoWidth,height:f.videoHeight};if(c("SVGImageElement"))throw new TypeError("SVGImageElement isn't yet supported as source image.","UnsupportedError");if(c("HTMLCanvasElement")||c("ImageBitmap"))return f}};var rt="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_";function nt(r){return r.split("").reduce((e,n)=>e*64+rt.indexOf(n),0)}function at(r){let e=rt.split(""),n=[],i=0;for(let o of r)n[i++]=e.indexOf(o)/64;return n}function ot(r){return r&&typeof r=="string"&&r.length===87&&r.split(".").length===2}function L(r){let e=r.split("."),n=e.map(c=>at(c)),i=n.map(c=>c[42]),o=n.map(c=>c.reduce((a,t)=>a+t)/c.length),s=e.map(c=>nt(c)%360),f=e.map((c,a)=>`hsl(${s[a]} ${i[a]*100}% ${o[a]*100}%)`);return{finals:i,decoded:n,angles:s,averages:o,colors:f}}function S(r,e=3){return[...Array(Math.ceil(r.length/e))].map(()=>r.splice(0,e))}var W=J(lt(),1),vt=J(pt(),1),Y=J(gt(),1);import{ref as jt}from"vue";var $=jt(null);function Vt(r){try{let e=r.toDataURL("image/png").split(",")[1],n=atob(e),i=new Uint8Array(n.length);for(let o=0;o<n.length;o++)i[o]=n.charCodeAt(o);return i}catch(e){return $.value="Failed to convert canvas to buffer: "+e.message,null}}function yt(r,e){try{let n=`<metadata>
<gun-data>${JSON.stringify(e)}</gun-data>
</metadata>`;return r.replace("</svg>",`${n}</svg>`)}catch(n){return $.value="Failed to embed data in SVG: "+n.message,null}}function kt(r){console.log(r);try{let e=r.match(/<metadata>\s*<gun-data>(.*?)<\/gun-data>\s*<\/metadata>/s);return!e||!e[1]?($.value="No embedded data found in SVG",null):JSON.parse(e[1])}catch(e){return $.value="Failed to extract data from SVG: "+e.message,null}}function bt(r,e){try{let n=Vt(r);if(!n)return null;let i=(0,W.default)(n);return i.splice(-1,0,Y.default.encode("message",JSON.stringify(e))),(0,vt.default)(i)}catch(n){return $.value="Failed to embed data: "+n.message,null}}function Wt(r,e="image/png"){if(e==="image/svg+xml"){let n=new TextDecoder().decode(r);return kt(n)}try{let o=(0,W.default)(r).filter(s=>s.name==="tEXt").map(s=>Y.default.decode(s.data)).find(s=>s.keyword==="message");return o?JSON.parse(o.text):null}catch(n){return $.value=n.message,null}}async function Yt(r){try{if(!(r instanceof File))throw new Error("Input must be a File object");let e=await r.arrayBuffer(),n=new Uint8Array(e);return await Wt(n,r.type)}catch(e){return $.value=e.message,null}}function At({pub:r,size:e,dark:n,draw:i,reflect:o,round:s,embed:f,p3:c}){let a=document.createElement("canvas");a.width=a.height=e;let t=a.getContext("2d"),{decoded:l,finals:p}=L(r);if(Zt({ctx:t,top:p[0],bottom:p[1],size:e,dark:n}),i=="squares"?(t.filter="blur(20px)",wt(l[0],t,e,c),t.filter="blur(0px)",t.globalCompositeOperation="color-burn",wt(l[1],t,e,c)):($t(l[0],t,e,.42*e,c),t.globalCompositeOperation="multiply",$t(l[1],t,e,.125*e,c)),o&&(t.globalCompositeOperation="source-over",t.scale(-1,1),t.translate(-e/2,0),t.drawImage(a,e/2,0,e,e,0,0,e,e),t.setTransform(1,0,0,1,0,0)),s){let u=t.getImageData(0,0,e,e);t.clearRect(0,0,e,e),t.fillStyle=n?"#cccccc":"#ffffff",t.fillRect(0,0,e,e),t.putImageData(u,0,0),t.globalCompositeOperation="destination-in",t.beginPath(),t.arc(e/2,e/2,e/2,0,Math.PI*2),t.closePath(),t.fill()}let d=a.toDataURL("image/png");if(f){let m=bt(a,{pub:r,content:f});if(m){let b=new Blob([m],{type:"image/png"});d=URL.createObjectURL(b)}}return d}function Zt({ctx:r,top:e=0,bottom:n=150,size:i=200,dark:o=!1}){let s=r.createLinearGradient(0,0,0,i),f=o?0:70;s.addColorStop(0,`hsl(0,0%,${f+e*30}%)`),s.addColorStop(1,`hsl(0,0%,${f+n*30}%)`),r.fillStyle=s,r.fillRect(0,0,i,i)}function wt(r,e,n,i){S(r,14).forEach(o=>{if(o.length===14){let[s,f,c,a,t,l,p,d,u,m,b,E,x,M]=o,g=n/8+c*n*(7/8),h=e.createLinearGradient(s*n+g*d,0,s*n+g*x,n);h.addColorStop(0,i?`color(display-p3 ${a} ${t} ${l} / ${p})`:`rgba(${a*255}, ${t*255}, ${l*255}, ${p})`),h.addColorStop(1,i?`color(display-p3 ${u} ${m} ${b} / ${E})`:`rgba(${u*255}, ${m*255}, ${b*255}, ${E})`),e.fillStyle=h,e.translate(s*n,f*n),e.rotate(M*Math.PI),e.fillRect(-g/2,-g/2,g,g),e.setTransform(1,0,0,1,0,0)}})}function $t(r,e,n,i,o){S(r,7).forEach(s=>{if(s.length===7){let[f,c,a,t,l,p,d]=s;e.beginPath(),e.arc(n/2+f*n/2,c*n,a*i,0,2*Math.PI),e.fillStyle=o?`color(display-p3 ${t} ${l} ${p} / ${d})`:`rgba(${t*255}, ${l*255}, ${p*255}, ${d})`,e.closePath(),e.fill()}})}function Ft({size:r=300,reflect:e=!0,follow:n=!0,finals:i=[.5,.5],averages:o=[.5,.5],breathVert:s=.03}={}){return`
<script type="text/javascript"><![CDATA[
// Compact state & precomputed constants
const s = {
e: [], // elements
p: { x: null, y: null, tx: null, ty: null, a: false, lt: 0, lit: 0 }, // pointer state
r: null, // rect
a: false, // pulse active
pt: 0, // pulse time
pv: 0, // pulse value
t: 0 // time
},
c = {
sz: ${r},
cx: ${r/2},
cy: ${r/2},
pz: ${r} * 1.2,
bz: ${r} * 0.4 * ${i[1]},
pr: ${r} * (0.5 + ${i[0]}/4),
mv: (0.1 + 0.05*${o[0]}) * Math.max(0.8, Math.min(4.4, 200/${r})),
bs: 0.1 * Math.max(0.8, Math.min(1.4, 200/${r})),
bv: ${s} * Math.max(0.8, Math.min(1.4, 200/${r})),
bd: 4500 + ${o[0]}*1000,
pa: 0.6 * Math.max(0.8, Math.min(1.4, 200/${r})),
pr: 200,
pf: 700,
rf: ${n},
d: 900,
td: 1500000,
pp: 0.5+ 0.5*${o[1]}
};
// Init using IIFE
(() => {
const svg = document.currentScript?.closest('svg');
if (!svg) return;
// Update rect and get element collections
const ur = () => s.r = svg.getBoundingClientRect();
ur();
// Cache elements for better performance
s.e = [
...Array.from(svg.querySelectorAll('.interactive-circle')).map(el => {
const x = +el.getAttribute('data-cx');
const y = +el.getAttribute('data-cy');
const r = +el.getAttribute('r');
const o = +el.getAttribute('data-opacity');
const m = Math.pow(r / (c.sz * 0.05), 0.7) * o;
const mr = el.nextElementSibling &&
el.nextElementSibling.getAttribute('cx') === (c.sz - x).toString() ?
el.nextElementSibling : null;
return {
el, t: 'c',
x, y, r,
cx: x, cy: y,
m, mr,
o: Math.random() * Math.PI * 2
};
}),
...Array.from(svg.querySelectorAll('.interactive-square')).map(el => {
const x = +el.getAttribute('data-cx');
const y = +el.getAttribute('data-cy');
const r = +el.getAttribute('data-r');
const o = +el.getAttribute('data-opacity');
const a = +el.getAttribute('data-angle') + (Math.random() * 20 - 10);
return {
el, t: 's',
x, y, z: c.bz, r: a,
cx: x, cy: y, cz: c.bz, cr: a, cs: 1,
m: Math.pow((r / c.sz), 1.5) * o,
o: Math.random() * Math.PI * 2
};
})
];
// Initial transform for squares
s.e.filter(el => el.t === 's').forEach(setTransform);
// Helper functions for event handling
const gc = e => ({ x: (e.touches?.[0] || e.changedTouches?.[0] || e).clientX,
y: (e.touches?.[0] || e.changedTouches?.[0] || e).clientY });
const inBounds = (x, y) => {
const { left, top, width, height } = s.r || {};
return x >= left && x <= left + width && y >= top && y <= top + height;
};
// Event handlers
const up = e => {
if (!s.r) ur();
const { left, top, width, height } = s.r;
const { x, y } = gc(e);
if (!inBounds(x, y) && !e.type.startsWith('touch')) {
if (s.p.a) pl(false);
return;
}
// Calculate relative position
const tx = ((x - left) / width) * c.sz;
const ty = ((y - top) / height) * c.sz;
// Init/update target position
if (s.p.tx === null) {
s.p.tx = tx;
s.p.ty = ty;
} else {
s.p.tx = tx;
s.p.ty = ty;
// Handle reappearance after inactivity
if (!s.p.a && performance.now() - s.p.lt > 100) {
s.p.x = tx;
s.p.y = ty;
}
}
// Initialize actual position if first interaction
if (s.p.x === null) {
s.p.x = s.p.tx;
s.p.y = s.p.ty;
}
s.p.a = true;
s.p.lt = performance.now();
};
const pd = e => {
up(e);
s.a = true;
s.pt = performance.now();
if (e.type === 'touchstart') e.preventDefault();
};
const pu = e => {
s.a = false;
s.pt = performance.now();
if (e.type === 'touchend' || e.type === 'touchcancel') {
pl(true);
}
};
const pl = (immediate = false) => {
s.p.a = false;
s.p.lit = performance.now();
s.a = false;
s.pt = s.p.lit;
if (immediate) {
s.p.tx = s.p.x = null;
s.p.ty = s.p.y = null;
}
};
// Event listeners
window.addEventListener('resize', ur, { passive: true });
svg.addEventListener('pointermove', up, { passive: true });
svg.addEventListener('pointerenter', up, { passive: true });
svg.addEventListener('pointerleave', pl, { passive: true });
svg.addEventListener('pointerdown', pd, { passive: false });
window.addEventListener('pointerup', pu, { passive: true });
window.addEventListener('pointercancel', pu, { passive: true });
// Start animation
requestAnimationFrame(animate);
// Setup auto-cleanup
if (document.currentScript?.parentNode) {
const cleanup = () => {
window.removeEventListener('resize', ur);
svg.removeEventListener('pointermove', up);
svg.removeEventListener('pointerenter', up);
svg.removeEventListener('pointerleave', pl);
svg.removeEventListener('pointerdown', pd);
window.removeEventListener('pointerup', pu);
window.removeEventListener('pointercancel', pu);
s.e = [];
};
new MutationObserver(mutations => {
mutations.forEach(m => {
if (m.removedNodes) {
m.removedNodes.forEach(n => {
if (n === document.currentScript) {
cleanup();
observer.disconnect();
}
});
}
});
}).observe(document.currentScript.parentNode, { childList: true });
}
})();
// Apply 3D transform to square elements
function setTransform(el) {
const ps = c.pz / (c.pz + el.cz);
const px = c.cx + (el.cx - c.cx) * ps;
const py = c.cy + (el.cy - c.cy) * ps;
el.el.setAttribute('transform',
'translate('+ px+' '+ py+') rotate('+ el.cr+ ') scale(' + ps * el.cs + ')'
);
}
// Calculate effects based on time and pulse
function fx(el, t, pv) {
const \u03B8 = (t % c.bd) / c.bd * Math.PI * 2 + el.o;
const w = Math.sin(\u03B8);
const mf = 1 - Math.min(0.8, el.m);
return {
s: (1 + w * c.bs * mf) * (1 + pv * c.pa * Math.pow(mf, 2)),
y: w * c.sz * c.bv * mf,
p: pv * c.pa * Math.pow(mf, 2)
};
}
// Animation loop
function animate(time) {
const dt = s.t ? time - s.t : 0;
s.t = time;
// Handle pointer inactivity
if (!s.p.a && s.p.x !== null && time - s.p.lit > c.td) {
s.p.x = s.p.y = s.p.tx = s.p.ty = null;
s.e.forEach(el => { if (el.ractive) el.ractive = false; });
}
// Smooth pointer movement
if (s.p.a && s.p.tx !== null && s.p.x !== null) {
const dx = s.p.tx - s.p.x;
const dy = s.p.ty - s.p.y;
const dist = Math.sqrt(dx*dx + dy*dy);
const factor = dist > c.sz * 0.3 ? 0.2 : c.pp;
s.p.x += dx * factor;
s.p.y += dy * factor;
}
// Update pulse
s.pv = s.a ?
s.pv + (1 - s.pv) * Math.min(1, (time - s.pt) / c.pr) :
s.pv * Math.max(0, 1 - (time - s.pt) / c.pf);
if (s.pv < 0.001) s.pv = 0;
// Process elements
const ps = Math.max(0.6, Math.min(1, c.sz / 150));
const active = s.p.x !== null;
s.e.forEach(el => {
const sm = Math.min(dt / c.d, 1) * (el.t === 's' ? 0.3 : 0.1);
const effect = fx(el, time, s.pv);
if (el.t === 'c') { // Circle
let tx = el.x;
let ty = el.y + effect.y;
if (active) {
const dx = s.p.x - el.x;
const dy = s.p.y - el.y;
const d = Math.sqrt(dx * dx + dy * dy);
const mv = c.sz * c.mv * (1 - Math.min(0.8, el.m));
const m = Math.min(d, mv) * ps;
if (d > 0.1) {
tx += m * (dx / d);
ty += m * (dy / d);
}
}
// Smooth interpolation
const cx_diff = tx - el.cx;
const cy_diff = ty - el.cy;
const c_dist = Math.sqrt(cx_diff*cx_diff + cy_diff*cy_diff);
const c_factor = c_dist > 20 ? 0.15 : 0.1;
el.cx += cx_diff * c_factor;
el.cy += cy_diff * c_factor;
// Apply changes
el.el.setAttribute('cx', el.cx);
el.el.setAttribute('cy', el.cy);
el.el.setAttribute('r', el.r * effect.s);
// Handle reflection
if (el.mr && ${e}) {
// Initialize reflection properties if needed
const reflectX = c.sz - el.x;
if (!el.rcx) {
el.rcx = reflectX;
el.rcy = el.y;
el.rtx = reflectX;
el.rty = el.y;
el.ractive = false;
el.rest = { x: reflectX, y: el.y };
}
// Update reflection activity state
if (active && !el.ractive && s.p.lt - s.p.lit > 100) {
el.ractive = true;
} else if (!active && el.ractive && s.p.lit - s.p.lt > 50) {
el.ractive = false;
}
// Set target position based on active state and mode
if (!active || !${n}) {
el.rtx = c.sz - el.cx;
el.rty = el.cy;
} else {
const rdx = s.p.x - reflectX;
const rdy = s.p.y - el.y;
const rd = Math.sqrt(rdx * rdx + rdy * rdy);
const rmv = c.sz * c.mv * (1 - Math.min(0.8, el.m));
const rm = Math.min(rd, rmv) * ps;
if (rd > 0.1) {
el.rtx = reflectX + rm * (rdx / rd);
el.rty = el.y + effect.y + rm * (rdy / rd);
} else {
el.rtx = reflectX;
el.rty = el.y + effect.y;
}
}
// Return to rest position when inactive
if (!active && !s.p.x) {
el.rtx = el.rest.x;
el.rty = el.rest.y + effect.y;
}
// Smooth interpolation for reflection
const rcx_diff = el.rtx - el.rcx;
const rcy_diff = el.rty - el.rcy;
const rc_dist = Math.sqrt(rcx_diff*rcx_diff + rcy_diff*rcy_diff);
const rc_factor = rc_dist > 30 ? 0.05 : (rc_dist > 10 ? 0.07 : 0.09);
el.rcx += rcx_diff * rc_factor;
el.rcy += rcy_diff * rc_factor;
// Apply reflection position
el.mr.setAttribute('cx', el.rcx);
el.mr.setAttribute('cy', el.rcy);
el.mr.setAttribute('r', el.r * effect.s);
}
} else if (el.t === 's') { // Square
let tx = el.x, ty = el.y + effect.y, tz = c.bz, tr = el.r, ts = 1;
if (active) {
const dx = s.p.x - el.x;
const dy = s.p.y - el.y;
const d = Math.sqrt(dx * dx + dy * dy);
const mf = 1 - Math.min(0.8, el.m);
const mv = c.sz * 0.1 * mf;
const m = Math.min(d, mv) * ps;
if (d > 0.1) {
tx += m * (dx / d);
ty += m * (dy / d);
}
// Apply depth & scale changes
const n = Math.min(d / c.pr, 1);
const zf = 1 - n * n;
tz -= c.bz * zf * mf;
ts += zf * 0.3 * mf;
tr += Math.sin(d / 100) * 5 * mf;
} else {
// Idle rotation
tr += Math.sin(time / 1500 + el.o) * 3 * (1 - Math.min(0.8, el.m));
}
// Apply pulse to Z depth
tz -= effect.p * c.bz * 0.7 * (1 - Math.min(0.8, el.m));
ts *= effect.s;
// Smoothing based on distance
const sx_diff = tx - el.cx;
const sy_diff = ty - el.cy;
const s_dist = Math.sqrt(sx_diff*sx_diff + sy_diff*sy_diff);
const s_factor = Math.min(1, s_dist > 20 ? sm * 1.5 : sm);
// Apply interpolation
el.cx += sx_diff * s_factor;
el.cy += sy_diff * s_factor;
el.cz += (tz - el.cz) * sm;
el.cr += (tr - el.cr) * sm;
el.cs += (ts - el.cs) * sm;
setTransform(el);
}
});
requestAnimationFrame(animate);
}
]]></script>
`}function Et({pub:r,size:e=200,dark:n=!1,draw:i="circles",reflect:o=!0,round:s=!0,embed:f=!0,svg:c}={}){let{decoded:a,finals:t,averages:l}=L(r),p=n?"#333":"#eee",d=`
<linearGradient id="bg" x1="0" y1="0" x2="0" y2="1">
<stop offset="0%" stop-color="hsla(0,0%,${(n?0:70)+t[0]*30}%)"/>
<stop offset="100%" stop-color="hsla(0,0%,${(n?0:70)+t[1]*30}%)"/>
</linearGradient>
`,u=(h,A=!1)=>S(h,14).map(w=>{if(w.length!==14)return"";let[I,P,T,X,N,O,C,_,D,U,R,H,St,Z]=w,B=e/8+T*e*(7/8),K=`gradient-${I}-${P}-${A?"2":"1"}`,Q=I*e,z=P*e,Mt=c==="interactive"?`class="interactive-square" data-cx="${Q}" data-cy="${z}" data-r="${B}" data-angle="${Z*180}" data-opacity="${(C+H)/2}"`:"";return`
<defs>
<linearGradient id="${K}" x1="${_}" y1="0" x2="${St}" y2="1">
<stop offset="0%" stop-color="color(display-p3 ${X} ${N} ${O} / ${C})"/>
<stop offset="100%" stop-color="color(display-p3 ${D} ${U} ${R} / ${H})"/>
</linearGradient>
</defs>
<g ${Mt} transform="translate(${Q} ${z}) rotate(${Z*180})">
<rect
x="${-B/2}" y="${-B/2}"
width="${B}" height="${B}"
fill="url(#${K})"
style="${A?"mix-blend-mode:color-burn;":"filter:blur(20px);"}"
/>
</g>
`}).join(""),m=(h,A,w=!1)=>S(h,7).map(I=>{if(I.length!==7)return"";let[P,T,X,N,O,C,_]=I,D=e/2+P*e/2,U=T*e,R=X*A;return`
<circle
${c==="interactive"?`class="interactive-circle" data-cx="${D}" data-cy="${U}" data-opacity="${_}"`:""}
cx="${D}" cy="${U}" r="${R}"
fill="color(display-p3 ${N} ${O} ${C} / ${_})"
style="${w?"mix-blend-mode:multiply;":""}"
/>
${o?`
<circle
cx="${e-D}" cy="${U}" r="${R}"
fill="color(display-p3 ${N} ${O} ${C} / ${_})"
style="${w?"mix-blend-mode:multiply;":""}"
/>`:""}
`}).join(""),b=s?`
<defs>
<clipPath id="circle-mask">
<circle cx="${e/2}" cy="${e/2}" r="${e/2}" />
</clipPath>
</defs>
`:"",E=c==="interactive"?Ft({size:e,reflect:o,finals:t,averages:l}):"",x=`
<svg
width="${e}" height="${e}"
viewBox="0 0 ${e} ${e}"
xmlns="http://www.w3.org/2000/svg"
style="overflow: visible;"
>
<defs>${d}</defs>
${b}
<g ${s?'clip-path="url(#circle-mask)"':""}>
<rect x="${-e}" width="${3*e}" y="${-e}" height="${3*e}" fill="url(#bg)"/>
${i==="squares"?`${u(a[0],!1)}
${u(a[1],!0)}`:`${m(a[0],.42*e)}
${m(a[1],.125*e,!0)}`}
</g>
${E}
</svg>
`;if(c==="interactive")return`data:image/svg+xml,${encodeURIComponent(x.trim())}`;if(f){let h={pub:r};f&&(h.content=f),x=yt(x,h)}return`data:image/svg+xml;base64,${typeof btoa=="function"?btoa(x):Buffer.from(x).toString("base64")}`}var q={};function G({pub:r,size:e=200,dark:n=!1,draw:i="circles",reflect:o=!0,round:s=!0,embed:f=!0,svg:c=!0,p3:a=!0}={}){let t=typeof window<"u"&&typeof document<"u";if(!ot(r))return"";if(c||!t)return Et({pub:r,size:e,dark:n,draw:i,reflect:o,round:s,embed:f,svg:c,p3:a});let l=JSON.stringify(arguments[0]);if(q!=null&&q[l])return q[l];let p=At({pub:r,size:e,dark:n,draw:i,reflect:o,round:s,embed:f,svg:c,p3:a});return q[l]=p,p}function Kt(r="gun-avatar"){document.addEventListener("DOMContentLoaded",()=>{let e=document.getElementsByClassName(r);for(let n in e){let i=e[n];i.dataset.round!=="false"&&(i.style.borderRadius="100%");let o=i.dataset.embed;if(i.dataset.embed!=="true")try{o=JSON.parse(i.dataset.embed)}catch{console.warn("Invalid content JSON in data-embed attribute")}i.src=G({pub:i.dataset.pub,size:Number(i.dataset.size),dark:!!i.dataset.dark,draw:i.dataset.draw,reflect:i.dataset.reflect!=="false",svg:i.dataset.svg,round:!!i.dataset.round,embed:o==="false"?!1:o||!0})}})}function Qt(r="gun-avatar"){let e=!1;if(e)return;class n extends HTMLElement{constructor(){super(),this.attachShadow({mode:"open"}),this.img=document.createElement("img"),this.shadowRoot.append(this.img)}render(){this.pub=this.getAttribute("pub")||"1234123455Ute2tFhdjDQgzR-1234lfSlZxgEZKuquI.2F-j1234434U1234Asj-5lxnECG5TDyuPD8gEiuI123",this.size=this.hasAttribute("size")?Number(this.getAttribute("size")):400,this.draw=this.getAttribute("draw")||"circles",this.reflect=this.hasAttribute("reflect")?this.getAttribute("reflect")!=="false":!0,this.round=this.hasAttribute("round")||this.getAttribute("round")==="",this.dark=this.hasAttribute("dark")?this.getAttribute("dark")!="":!1,this.embed=this.hasAttribute("embed")?this.getAttribute("embed")!=="false":!0,this.svg=this.hasAttribute("dark")&&this.getAttribute("dark"),this.p3=this.hasAttribute("p3")?this.getAttribute("p3")!=="false":!0;let o=this.getAttribute("embed");if(this.getAttribute("embed"))try{o=JSON.parse(this.getAttribute("embed"))}catch{console.warn("Invalid content JSON in embed attribute")}this.img.style.borderRadius=this.round?"100%":"0%",this.img.src=G({pub:this.pub,size:this.size,dark:this.dark,draw:this.draw,reflect:this.reflect,round:this.round,svg:this.svg,embed:o==="false"?!1:o||!0,p3:this.p3})}connectedCallback(){this.render()}static get observedAttributes(){return["pub","round","size","dark","draw","reflect","embed","p3"]}attributeChangedCallback(){this.render()}}customElements.define(r,n),e=!0}et();export{$ as error,Yt as extractFromFile,G as gunAvatar,Kt as mountClass,Qt as mountElement,L as parsePub};
//# sourceMappingURL=index.js.map