@leozodiac/swarm66 0.0.0-stage → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/ARCHITECTURE.md +132 -0
- package/LICENSE +22 -0
- package/README.md +416 -2
- package/TASKS.md +127 -0
- package/dist/index.cjs +237 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.mts +766 -0
- package/dist/index.d.ts +766 -0
- package/dist/index.global.js +237 -0
- package/dist/index.global.js.map +1 -0
- package/dist/index.js +237 -0
- package/dist/index.js.map +1 -0
- package/package.json +69 -4
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
var Swarm66=(function(exports){'use strict';function u(a=0,e=0){return {x:a,y:e}}function y(a,e){return {x:a.x+e.x,y:a.y+e.y}}function x(a,e){return {x:a.x-e.x,y:a.y-e.y}}function f(a,e){return {x:a.x*e,y:a.y*e}}function D(a,e){return e===0?{x:0,y:0}:{x:a.x/e,y:a.y/e}}function P(a){return a.x*a.x+a.y*a.y}function q(a){return Math.sqrt(P(a))}function F(a,e){let t=a.x-e.x,i=a.y-e.y;return t*t+i*i}function T(a,e){return Math.sqrt(F(a,e))}function L(a){let e=q(a);return e===0?{x:0,y:0}:{x:a.x/e,y:a.y/e}}function G(a,e){return f(L(a),e)}function M(a,e){let t=P(a);return t>e*e?f(D(a,Math.sqrt(t)),e):{x:a.x,y:a.y}}function Q(a){return Math.atan2(a.y,a.x)}function W(a){return Math.atan2(a.y,a.x)*180/Math.PI}function j(a,e,t){return a+(e-a)*t}function Z(a,e,t){return Math.max(e,Math.min(t,a))}function v(a,e){return Math.random()*(e-a)+a}function Y(a){let e=Math.floor(Math.random()*a.length);return a[e]}function K(a,e){return a.x*e.x+a.y*e.y}var N=class{constructor(e,t,i,n,r,s=9.5,o=.4){this.teamId=0;this.state="IDLE_FLOCKING";this.type="pointer";this.targetPosition=null;this.targetElement=null;this.assignedTaskId=null;this.borderRole=null;this.targetRect=null;this.borderProgress=0;this.headingAngle=0;this.targetScale=1;this.currentScale=1;this.currentOpacity=1;this.id=e,this.color=t,this.teamId=i,this.position={...n},this.velocity=u(v(-2,2),v(-2,2)),this.acceleration=u(0,0),this.maxSpeed=s,this.maxForce=o,this.borderProgress=v(0,1);let l=r.createAgentElement(e,t);this.element=l.element,this.iconContainer=l.iconContainer,r.updateAgentTransform(this.element,this.position.x,this.position.y,0,1);}applyForce(e){this.acceleration=y(this.acceleration,e);}update(e,t){if(this.state==="VANISHED"){this.element.style.display="none";return}if(this.state==="CONSTRUCTING_ELEMENT"&&this.borderRole&&this.targetRect){let i=this.targetRect;this.borderProgress=(this.borderProgress+e*.016)%1;let n=(Math.sin(this.borderProgress*Math.PI*2)+1)*.5;this.borderRole==="top"?(this.position.x=i.left+i.width*n,this.position.y=i.top):this.borderRole==="right"?(this.position.x=i.right,this.position.y=i.top+i.height*n):this.borderRole==="bottom"?(this.position.x=i.right-i.width*n,this.position.y=i.bottom):this.borderRole==="left"?(this.position.x=i.left,this.position.y=i.bottom-i.height*n):(this.position.x=i.left+i.width*.5,this.position.y=i.top+i.height*.5),this.headingAngle=0,this.targetScale=1.05,this.currentOpacity=1;}else {let i=f(this.acceleration,e);this.velocity=M(y(this.velocity,i),this.maxSpeed);let n=f(this.velocity,e);if(this.position=y(this.position,n),this.acceleration=u(0,0),this.state==="CONVERGING_TO_USER"){if(this.targetPosition){let r=T(this.position,this.targetPosition),s=Math.min(Math.max(r/70,0),1);if(this.targetScale=s*1.05,this.currentOpacity=s,r<14){this.state="VANISHED",this.element.style.opacity="0",this.element.style.display="none",t.createVanishRipple(this.position.x,this.position.y,this.color);return}this.headingAngle=0;}}else this.headingAngle=0,this.targetScale=1,this.currentOpacity=1;}this.currentScale+=(this.targetScale-this.currentScale)*.2,this.element.style.opacity=this.currentOpacity.toFixed(3),t.updateAgentTransform(this.element,this.position.x,this.position.y,this.headingAngle,this.currentScale);}morphIcon(e,t){this.type!==e&&(this.type=e,t.setAgentIcon(this.iconContainer,e,this.color));}assignTarget(e,t,i,n,r,s,o){this.targetPosition={...e},this.targetElement=t,this.assignedTaskId=i,this.borderRole=n,this.targetRect=r,this.state="MOVING_TO_TARGET",this.morphIcon(s,o);}setConstructing(){this.state="CONSTRUCTING_ELEMENT",this.velocity=f(this.velocity,.2);}returnToSwarm(e){this.state="RETURNING_TO_SWARM",this.targetPosition=null,this.targetElement=null,this.assignedTaskId=null,this.borderRole=null,this.targetRect=null,this.morphIcon("pointer",e),this.velocity=u(v(-4,4),v(-4,4));}convergeTo(e,t){this.state="CONVERGING_TO_USER",this.targetPosition={...e},this.targetElement=null,this.assignedTaskId=null,this.borderRole=null,this.targetRect=null,this.morphIcon("pointer",t),this.maxSpeed=15;}setIdle(){this.state="IDLE_FLOCKING",this.targetPosition=null,this.targetElement=null,this.assignedTaskId=null,this.borderRole=null,this.targetRect=null;}reset(e,t){this.position={...e},this.velocity=u(v(-3,3),v(-3,3)),this.acceleration=u(0,0),this.state="IDLE_FLOCKING",this.type="pointer",this.targetPosition=null,this.targetElement=null,this.assignedTaskId=null,this.borderRole=null,this.targetRect=null,this.targetScale=1,this.currentScale=1,this.currentOpacity=1,this.element.style.display="block",this.element.style.opacity="1",t.setAgentIcon(this.iconContainer,"pointer",this.color),t.updateAgentTransform(this.element,this.position.x,this.position.y,0,1);}destroy(){this.element&&this.element.parentNode&&this.element.parentNode.removeChild(this.element);}};var I=class{static calculateFlockingForces(e,t,i,n,r){let s=this.separate(e,t,n.separateDistance),o=this.align(e,t,n.flockRadius),l=this.cohere(e,t,n.flockRadius),d=this.boundEdges(e,r,60),c=u(0,0);if(c=y(c,f(s,1.6)),c=y(c,f(o,1)),c=y(c,f(l,.9)),c=y(c,f(d,2.2)),n.followMouse&&i){let h=this.attractToMouse(e,i,n.mouseAttractRadius,n.mouseAttractForce);c=y(c,h);}return M(c,e.maxForce*2)}static separate(e,t,i){let n=u(0,0),r=0,s=i*i;for(let o=0;o<t.length;o++){let l=t[o];if(!l||l.id===e.id)continue;let d=F(e.position,l.position);if(d>0&&d<s){let c=Math.sqrt(d),h=x(e.position,l.position);h=L(h),h=D(h,Math.max(c,1)),n=y(n,h),r++;}}return r>0&&(n=D(n,r),F(n,u(0,0))>0&&(n=L(n),n=f(n,e.maxSpeed),n=x(n,e.velocity),n=M(n,e.maxForce*1.5))),n}static align(e,t,i){let n=u(0,0),r=0,s=i*i;for(let o=0;o<t.length;o++){let l=t[o];if(!l||l.id===e.id||l.state==="CONSTRUCTING_ELEMENT")continue;let d=F(e.position,l.position);d>0&&d<s&&(n=y(n,l.velocity),r++);}if(r>0){n=D(n,r),n=L(n),n=f(n,e.maxSpeed);let o=x(n,e.velocity);return o=M(o,e.maxForce),o}return u(0,0)}static cohere(e,t,i){let n=u(0,0),r=0,s=i*i;for(let o=0;o<t.length;o++){let l=t[o];if(!l||l.id===e.id||l.state==="CONSTRUCTING_ELEMENT")continue;let d=F(e.position,l.position);d>0&&d<s&&(n=y(n,l.position),r++);}return r>0?(n=D(n,r),this.seek(e,n)):u(0,0)}static attractToMouse(e,t,i,n){let r=T(e.position,t);if(r>i*2.5)return u(0,0);let s=this.seek(e,t,i*.8),o=x(t,e.position),l=L({x:-o.y,y:o.x}),d=(1-Math.min(r/i,1))*.8,c=f(l,d),h=y(f(s,n),c);return M(h,e.maxForce*1.8)}static seek(e,t,i=120){let n=x(t,e.position),r=T(t,e.position);if(r===0)return u(0,0);let s=e.maxSpeed;r<i&&(s=e.maxSpeed*(r/i));let o=G(n,s),l=x(o,e.velocity);return M(l,e.maxForce)}static boundEdges(e,t,i=60){let n=u(0,0);return e.position.x<i?n.x=(i-e.position.x)/i:e.position.x>t.width-i&&(n.x=(t.width-i-e.position.x)/i),e.position.y<i?n.y=(i-e.position.y)/i:e.position.y>t.height-i&&(n.y=(t.height-i-e.position.y)/i),F(n,u(0,0))>0&&(n=G(n,e.maxSpeed),n=x(n,e.velocity),n=M(n,e.maxForce*2)),n}};var O=class{constructor(e=typeof document<"u"?document.body:null){this.container=e;this.hostElement=null;this.shadowRoot=null;this.agentsLayer=null;this.overlaysLayer=null;this.guidesLayer=null;this.mounted=false;}mount(){if(this.mounted||typeof document>"u")return false;let e=document.createElement("dom-swarm-overlay");e.setAttribute("aria-hidden","true"),e.style.position="fixed",e.style.inset="0",e.style.width="100vw",e.style.height="100vh",e.style.pointerEvents="none",e.style.zIndex="2147483647",e.style.overflow="hidden";let t=e.attachShadow({mode:"open"}),i=document.createElement("style");i.textContent=this.getScopedStyles(),t.appendChild(i);let n=document.createElement("div");n.className="swarm-root";let r=document.createElement("div");r.className="swarm-guides-layer",n.appendChild(r);let s=document.createElement("div");s.className="swarm-overlays-layer",n.appendChild(s);let o=document.createElement("div");return o.className="swarm-agents-layer",n.appendChild(o),t.appendChild(n),(this.container||document.body).appendChild(e),this.hostElement=e,this.shadowRoot=t,this.guidesLayer=r,this.overlaysLayer=s,this.agentsLayer=o,this.mounted=true,true}createAgentElement(e,t){if(!this.agentsLayer)throw new Error("[dom-swarm] OverlayManager is not mounted.");let i=document.createElement("div");i.className="swarm-agent",i.dataset.agentId=e.toString();let n=document.createElement("div");return n.className="swarm-agent-icon",n.innerHTML=this.getPointerSvg(t),i.appendChild(n),this.agentsLayer.appendChild(i),{element:i,iconContainer:n}}updateAgentTransform(e,t,i,n,r=1){e.style.transform=`translate3d(${t}px, ${i}px, 0) rotate(${n}deg) scale(${r})`;}setAgentIcon(e,t,i){switch(e.className="swarm-agent-icon",t){case "pen":e.innerHTML=this.getPenSvg(i),e.classList.add("is-pen");break;case "frame":e.innerHTML=this.getFrameSvg(i),e.classList.add("is-frame");break;case "media":e.innerHTML=this.getMediaSvg(i),e.classList.add("is-media");break;case "button":e.innerHTML=this.getButtonSvg(i),e.classList.add("is-button");break;case "code":e.innerHTML=this.getCodeSvg(i),e.classList.add("is-code");break;case "ibeam":e.innerHTML=this.getIBeamSvg(i),e.classList.add("is-ibeam");break;case "hand":case "duplicate":e.innerHTML=this.getHandSvg(i),e.classList.add("is-hand");break;default:e.innerHTML=this.getPointerSvg(i);break}}createBoundingBox(e,t,i,n=true,r=true,s){if(!this.overlaysLayer)throw new Error("[dom-swarm] OverlayManager is not mounted.");let o=document.createElement("div");o.className=`swarm-bounding-box box-${i}`,o.id=`swarm-box-${e}`;let l=s||{left:t.left,top:t.top,width:Math.max(4,t.width),height:Math.max(4,t.height),opacity:1};if(o.style.transform=`translate3d(${l.left}px, ${l.top}px, 0)`,o.style.width=`${Math.max(0,l.width)}px`,o.style.height=`${Math.max(0,l.height)}px`,o.style.opacity=(l.opacity??1).toString(),["tl","tr","bl","br"].forEach(c=>{let h=document.createElement("div");h.className=`swarm-corner-handle handle-${c}`,o.appendChild(h);}),n){let c=document.createElement("div");c.className="swarm-dimension-badge",c.textContent=`${Math.round(l.width)} \xD7 ${Math.round(l.height)}`,o.appendChild(c);}return i==="red"&&r&&this.guidesLayer&&this.createAlignmentGuides(e,t),this.overlaysLayer.appendChild(o),o}createGhostClone(e,t){if(!this.overlaysLayer)throw new Error("[dom-swarm] OverlayManager is not mounted.");let i=document.createElement("div");i.className="swarm-ghost-clone",i.id=`swarm-clone-${e}`,i.style.transform=`translate3d(${t.left}px, ${t.top}px, 0)`,i.style.width=`${Math.max(4,t.width)}px`,i.style.height=`${Math.max(4,t.height)}px`;let n=document.createElement("div");return n.className="swarm-clone-badge",n.textContent="Duplicate \u2325Drag",i.appendChild(n),["tl","tr","bl","br"].forEach(s=>{let o=document.createElement("div");o.className=`swarm-corner-handle handle-${s}`,i.appendChild(o);}),this.overlaysLayer.appendChild(i),i}updateGhostClone(e,t,i,n,r,s=1){e.style.transform=`translate3d(${t}px, ${i}px, 0)`,e.style.width=`${Math.max(4,n)}px`,e.style.height=`${Math.max(4,r)}px`,e.style.opacity=s.toString();}removeGhostClone(e){e.parentNode&&e.parentNode.removeChild(e);}updateBoxGeometry(e,t,i=1,n){e.style.transform=`translate3d(${t.left}px, ${t.top}px, 0)`,e.style.width=`${Math.max(0,t.width)}px`,e.style.height=`${Math.max(0,t.height)}px`,e.style.opacity=i.toString();let r=e.querySelector(".swarm-dimension-badge");if(r&&(r.textContent=`${Math.round(t.width)} \xD7 ${Math.round(t.height)}`),n&&this.guidesLayer){let s=this.shadowRoot?.getElementById(`swarm-guides-${n}`);if(s){let o=s.querySelectorAll(".swarm-guide-h");o[0]&&(o[0].style.top=`${t.top}px`),o[1]&&(o[1].style.top=`${t.top+t.height}px`);let l=s.querySelectorAll(".swarm-guide-v");l[0]&&(l[0].style.left=`${t.left}px`),l[1]&&(l[1].style.left=`${t.left+t.width}px`);}}}createAlignmentGuides(e,t){if(!this.guidesLayer)return;let i=document.createElement("div");i.className="swarm-guides-group",i.id=`swarm-guides-${e}`;let n=document.createElement("div");n.className="swarm-guide swarm-guide-h",n.style.top=`${t.top}px`;let r=document.createElement("div");r.className="swarm-guide swarm-guide-h",r.style.top=`${t.bottom}px`;let s=document.createElement("div");s.className="swarm-guide swarm-guide-v",s.style.left=`${t.left}px`;let o=document.createElement("div");o.className="swarm-guide swarm-guide-v",o.style.left=`${t.right}px`,i.appendChild(n),i.appendChild(r),i.appendChild(s),i.appendChild(o),this.guidesLayer.appendChild(i);}updateBoundingBox(e,t,i){e.style.transform=`translate3d(${t.left}px, ${t.top}px, 0)`,e.style.width=`${Math.max(4,t.width)}px`,e.style.height=`${Math.max(4,t.height)}px`;let n=e.querySelector(".swarm-dimension-badge");if(n&&(n.textContent=`${Math.round(t.width)} \xD7 ${Math.round(t.height)}`),i&&this.guidesLayer){let r=this.shadowRoot?.getElementById(`swarm-guides-${i}`);if(r){let s=r.querySelectorAll(".swarm-guide-h");s[0]&&(s[0].style.top=`${t.top}px`),s[1]&&(s[1].style.top=`${t.bottom}px`);let o=r.querySelectorAll(".swarm-guide-v");o[0]&&(o[0].style.left=`${t.left}px`),o[1]&&(o[1].style.left=`${t.right}px`);}}}removeBoundingBox(e,t){if(e.parentNode&&e.parentNode.removeChild(e),t&&this.shadowRoot){let i=this.shadowRoot.getElementById(`swarm-guides-${t}`);i&&i.parentNode&&i.parentNode.removeChild(i);}}getPointerSvg(e){return `<svg width="22" height="22" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
2
|
+
<path d="M3 2L10 21L13.5 13.5L21 10L3 2Z" fill="${e}" stroke="#FFFFFF" stroke-width="1.8" stroke-linejoin="round"/>
|
|
3
|
+
</svg>`}getPenSvg(e){return `<svg width="22" height="22" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
4
|
+
<path d="M2 2L3.5 9L9 3.5L2 2Z" fill="#FFFFFF" stroke="#FFFFFF" stroke-width="1.2" stroke-linejoin="round"/>
|
|
5
|
+
<path d="M3.5 9L9 3.5L17.5 12L12 17.5L3.5 9Z" fill="${e}" stroke="#FFFFFF" stroke-width="1.8" stroke-linejoin="round"/>
|
|
6
|
+
<path d="M12 17.5L17.5 12L20 14.5C21 15.5 21 17 20 18L18 20C17 21 15.5 21 14.5 20L12 17.5Z" fill="${e}" stroke="#FFFFFF" stroke-width="1.8" stroke-linejoin="round"/>
|
|
7
|
+
<path d="M6.5 6.5L15 15" stroke="#FFFFFF" stroke-width="1.2" stroke-linecap="round"/>
|
|
8
|
+
<circle cx="2" cy="2" r="1.2" fill="#111827"/>
|
|
9
|
+
</svg>`}getFrameSvg(e){return `<svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
10
|
+
<path d="M2 2L8.5 19L11.5 12.5L18 9.5L2 2Z" fill="${e}" stroke="#FFFFFF" stroke-width="1.8" stroke-linejoin="round"/>
|
|
11
|
+
<path d="M14 12V21M18 12V21M11 15H21M11 18.5H21" stroke="#FFFFFF" stroke-width="2.6" stroke-linecap="round"/>
|
|
12
|
+
<path d="M14 12V21M18 12V21M11 15H21M11 18.5H21" stroke="${e}" stroke-width="1.5" stroke-linecap="round"/>
|
|
13
|
+
</svg>`}getMediaSvg(e){return `<svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
14
|
+
<path d="M2 2L8.5 19L11.5 12.5L18 9.5L2 2Z" fill="${e}" stroke="#FFFFFF" stroke-width="1.8" stroke-linejoin="round"/>
|
|
15
|
+
<rect x="12" y="12" width="10" height="9" rx="1.5" fill="#0F172A" stroke="#FFFFFF" stroke-width="1.5"/>
|
|
16
|
+
<circle cx="15" cy="15" r="1.2" fill="#FBBF24"/>
|
|
17
|
+
<path d="M13 19L16 15.5L18 17.5L20 15L21 16.5V19H13Z" fill="${e}"/>
|
|
18
|
+
</svg>`}getButtonSvg(e){return `<svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
19
|
+
<path d="M2 2L8.5 19L11.5 12.5L18 9.5L2 2Z" fill="${e}" stroke="#FFFFFF" stroke-width="1.8" stroke-linejoin="round"/>
|
|
20
|
+
<rect x="11.5" y="12.5" width="10.5" height="7.5" rx="3.75" fill="${e}" stroke="#FFFFFF" stroke-width="1.5"/>
|
|
21
|
+
<path d="M15 14.5L18.5 16.25L15 18V14.5Z" fill="#FFFFFF"/>
|
|
22
|
+
</svg>`}getCodeSvg(e){return `<svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
23
|
+
<path d="M2 2L8.5 19L11.5 12.5L18 9.5L2 2Z" fill="${e}" stroke="#FFFFFF" stroke-width="1.8" stroke-linejoin="round"/>
|
|
24
|
+
<rect x="11" y="12" width="12" height="9" rx="2" fill="#0F172A" stroke="#FFFFFF" stroke-width="1.5"/>
|
|
25
|
+
<path d="M14 15L12.5 16.5L14 18M18 15L19.5 16.5L18 18" stroke="#38BDF8" stroke-width="1.4" stroke-linecap="round" stroke-linejoin="round"/>
|
|
26
|
+
</svg>`}getIBeamSvg(e){return `<svg width="20" height="24" viewBox="0 0 20 24" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
27
|
+
<path d="M4 3H16M10 3V21M4 21H16" stroke="#FFFFFF" stroke-width="3" stroke-linecap="round"/>
|
|
28
|
+
<path d="M4 3H16M10 3V21M4 21H16" stroke="${e}" stroke-width="2" stroke-linecap="round"/>
|
|
29
|
+
</svg>`}getHandSvg(e){return `<svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
30
|
+
<path d="M8 3V11M8 11L6 9C5.2 8.2 3.8 8.2 3 9C2.2 9.8 2.2 11.2 3 12L8 17C9.3 18.3 11.1 19 13 19H16C18.8 19 21 16.8 21 14V10C21 8.9 20.1 8 19 8C18.7 8 18.4 8.1 18.2 8.2C17.9 7.2 17 6.5 16 6.5C15.6 6.5 15.3 6.6 15 6.8C14.6 6 13.8 5.5 13 5.5C12.6 5.5 12.3 5.6 12 5.8V3C12 1.9 11.1 1 10 1C8.9 1 8 1.9 8 3V11" fill="${e}" stroke="#FFFFFF" stroke-width="1.8" stroke-linejoin="round"/>
|
|
31
|
+
</svg>`}createVanishRipple(e,t,i){if(!this.overlaysLayer)return;let n=document.createElement("div");n.className="swarm-vanish-ripple",n.style.left=`${e}px`,n.style.top=`${t}px`,n.style.border=`2px solid ${i}`,n.style.boxShadow=`0 0 12px ${i}`,this.overlaysLayer.appendChild(n),setTimeout(()=>{n.parentNode&&n.parentNode.removeChild(n);},600);}getScopedStyles(){return `
|
|
32
|
+
:host {
|
|
33
|
+
all: initial;
|
|
34
|
+
pointer-events: none;
|
|
35
|
+
}
|
|
36
|
+
.swarm-root {
|
|
37
|
+
position: fixed;
|
|
38
|
+
inset: 0;
|
|
39
|
+
width: 100vw;
|
|
40
|
+
height: 100vh;
|
|
41
|
+
pointer-events: none;
|
|
42
|
+
overflow: hidden;
|
|
43
|
+
user-select: none;
|
|
44
|
+
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
|
|
45
|
+
}
|
|
46
|
+
.swarm-agents-layer,
|
|
47
|
+
.swarm-overlays-layer,
|
|
48
|
+
.swarm-guides-layer {
|
|
49
|
+
position: absolute;
|
|
50
|
+
inset: 0;
|
|
51
|
+
pointer-events: none;
|
|
52
|
+
}
|
|
53
|
+
.swarm-agent {
|
|
54
|
+
position: absolute;
|
|
55
|
+
top: 0;
|
|
56
|
+
left: 0;
|
|
57
|
+
pointer-events: none;
|
|
58
|
+
will-change: transform;
|
|
59
|
+
transform-origin: 3px 2px;
|
|
60
|
+
filter: drop-shadow(0 2px 5px rgba(0, 0, 0, 0.28));
|
|
61
|
+
transition: opacity 0.2s ease;
|
|
62
|
+
}
|
|
63
|
+
.swarm-agent-icon {
|
|
64
|
+
display: inline-block;
|
|
65
|
+
pointer-events: none;
|
|
66
|
+
transform-origin: 0 0;
|
|
67
|
+
transition: transform 0.15s ease;
|
|
68
|
+
}
|
|
69
|
+
.swarm-agent-icon.is-pen {
|
|
70
|
+
animation: swarm-pen-draw 0.35s infinite alternate ease-in-out;
|
|
71
|
+
}
|
|
72
|
+
@keyframes swarm-pen-draw {
|
|
73
|
+
0% { transform: translate(0, 0); }
|
|
74
|
+
100% { transform: translate(1.5px, -1.5px); }
|
|
75
|
+
}
|
|
76
|
+
.swarm-agent-icon.is-ibeam {
|
|
77
|
+
animation: swarm-ibeam-pulse 0.7s infinite alternate ease-in-out;
|
|
78
|
+
}
|
|
79
|
+
@keyframes swarm-ibeam-pulse {
|
|
80
|
+
0% { opacity: 0.6; transform: scale(0.95); }
|
|
81
|
+
100% { opacity: 1; transform: scale(1.05); }
|
|
82
|
+
}
|
|
83
|
+
.swarm-agent-icon.is-button {
|
|
84
|
+
animation: swarm-button-press 0.45s infinite alternate ease-in-out;
|
|
85
|
+
}
|
|
86
|
+
@keyframes swarm-button-press {
|
|
87
|
+
0% { transform: scale(1); }
|
|
88
|
+
100% { transform: scale(0.92); }
|
|
89
|
+
}
|
|
90
|
+
.swarm-agent-icon.is-hand,
|
|
91
|
+
.swarm-agent-icon.is-duplicate {
|
|
92
|
+
animation: swarm-dup-float 0.45s infinite alternate ease-in-out;
|
|
93
|
+
}
|
|
94
|
+
@keyframes swarm-dup-float {
|
|
95
|
+
0% { transform: translateY(0); }
|
|
96
|
+
100% { transform: translateY(-1.5px); }
|
|
97
|
+
}
|
|
98
|
+
.swarm-bounding-box {
|
|
99
|
+
position: absolute;
|
|
100
|
+
top: 0;
|
|
101
|
+
left: 0;
|
|
102
|
+
pointer-events: none;
|
|
103
|
+
will-change: transform, width, height;
|
|
104
|
+
box-sizing: border-box;
|
|
105
|
+
border-radius: 2px;
|
|
106
|
+
transition: opacity 0.2s ease;
|
|
107
|
+
}
|
|
108
|
+
.box-blue {
|
|
109
|
+
border: 1.5px solid #0d99ff;
|
|
110
|
+
background: rgba(13, 153, 255, 0.08);
|
|
111
|
+
box-shadow: 0 0 0 1px rgba(13, 153, 255, 0.2);
|
|
112
|
+
}
|
|
113
|
+
.box-red {
|
|
114
|
+
border: 1.5px solid #f24822;
|
|
115
|
+
background: rgba(242, 72, 34, 0.07);
|
|
116
|
+
box-shadow: 0 0 0 1px rgba(242, 72, 34, 0.2);
|
|
117
|
+
}
|
|
118
|
+
.swarm-ghost-clone {
|
|
119
|
+
position: absolute;
|
|
120
|
+
top: 0;
|
|
121
|
+
left: 0;
|
|
122
|
+
pointer-events: none;
|
|
123
|
+
will-change: transform;
|
|
124
|
+
box-sizing: border-box;
|
|
125
|
+
border: 1.5px dashed #0d99ff;
|
|
126
|
+
background: rgba(13, 153, 255, 0.12);
|
|
127
|
+
box-shadow: 0 4px 14px rgba(13, 153, 255, 0.22);
|
|
128
|
+
border-radius: 2px;
|
|
129
|
+
}
|
|
130
|
+
.swarm-clone-badge {
|
|
131
|
+
position: absolute;
|
|
132
|
+
top: -22px;
|
|
133
|
+
left: 0;
|
|
134
|
+
background: #0d99ff;
|
|
135
|
+
color: #ffffff;
|
|
136
|
+
font-size: 9px;
|
|
137
|
+
font-weight: 700;
|
|
138
|
+
font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, monospace;
|
|
139
|
+
padding: 2px 6px;
|
|
140
|
+
border-radius: 4px;
|
|
141
|
+
white-space: nowrap;
|
|
142
|
+
box-shadow: 0 2px 6px rgba(0, 0, 0, 0.25);
|
|
143
|
+
letter-spacing: 0.3px;
|
|
144
|
+
}
|
|
145
|
+
.swarm-corner-handle {
|
|
146
|
+
position: absolute;
|
|
147
|
+
width: 6px;
|
|
148
|
+
height: 6px;
|
|
149
|
+
background: #ffffff;
|
|
150
|
+
border: 1.5px solid #0d99ff;
|
|
151
|
+
border-radius: 1px;
|
|
152
|
+
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25);
|
|
153
|
+
}
|
|
154
|
+
.box-red .swarm-corner-handle {
|
|
155
|
+
border-color: #f24822;
|
|
156
|
+
}
|
|
157
|
+
.handle-tl { top: -4px; left: -4px; }
|
|
158
|
+
.handle-tr { top: -4px; right: -4px; }
|
|
159
|
+
.handle-bl { bottom: -4px; left: -4px; }
|
|
160
|
+
.handle-br { bottom: -4px; right: -4px; }
|
|
161
|
+
|
|
162
|
+
.swarm-dimension-badge {
|
|
163
|
+
position: absolute;
|
|
164
|
+
left: 50%;
|
|
165
|
+
bottom: -22px;
|
|
166
|
+
transform: translateX(-50%);
|
|
167
|
+
background: #0d99ff;
|
|
168
|
+
color: #ffffff;
|
|
169
|
+
font-size: 10px;
|
|
170
|
+
font-weight: 600;
|
|
171
|
+
font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
|
|
172
|
+
padding: 2px 6px;
|
|
173
|
+
border-radius: 4px;
|
|
174
|
+
white-space: nowrap;
|
|
175
|
+
box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
|
|
176
|
+
letter-spacing: 0.2px;
|
|
177
|
+
}
|
|
178
|
+
.box-red .swarm-dimension-badge {
|
|
179
|
+
background: #f24822;
|
|
180
|
+
}
|
|
181
|
+
.swarm-distance-badge {
|
|
182
|
+
position: absolute;
|
|
183
|
+
top: -18px;
|
|
184
|
+
left: 4px;
|
|
185
|
+
background: #f24822;
|
|
186
|
+
color: #ffffff;
|
|
187
|
+
font-size: 9px;
|
|
188
|
+
font-weight: 700;
|
|
189
|
+
font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
|
|
190
|
+
padding: 1px 5px;
|
|
191
|
+
border-radius: 3px;
|
|
192
|
+
white-space: nowrap;
|
|
193
|
+
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
|
|
194
|
+
}
|
|
195
|
+
.swarm-vanish-ripple {
|
|
196
|
+
position: absolute;
|
|
197
|
+
border-radius: 50%;
|
|
198
|
+
pointer-events: none;
|
|
199
|
+
transform: translate(-50%, -50%);
|
|
200
|
+
animation: swarm-ripple 0.55s cubic-bezier(0.1, 0.8, 0.2, 1) forwards;
|
|
201
|
+
}
|
|
202
|
+
@keyframes swarm-ripple {
|
|
203
|
+
0% {
|
|
204
|
+
width: 6px;
|
|
205
|
+
height: 6px;
|
|
206
|
+
opacity: 0.9;
|
|
207
|
+
transform: translate(-50%, -50%) scale(0.6);
|
|
208
|
+
}
|
|
209
|
+
100% {
|
|
210
|
+
width: 70px;
|
|
211
|
+
height: 70px;
|
|
212
|
+
opacity: 0;
|
|
213
|
+
transform: translate(-50%, -50%) scale(1.4);
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
.swarm-guide {
|
|
217
|
+
position: absolute;
|
|
218
|
+
pointer-events: none;
|
|
219
|
+
}
|
|
220
|
+
.swarm-guide-h {
|
|
221
|
+
left: 0;
|
|
222
|
+
right: 0;
|
|
223
|
+
width: 100vw;
|
|
224
|
+
height: 1px;
|
|
225
|
+
background: rgba(242, 72, 34, 0.45);
|
|
226
|
+
border-top: 1px dashed rgba(242, 72, 34, 0.6);
|
|
227
|
+
}
|
|
228
|
+
.swarm-guide-v {
|
|
229
|
+
top: 0;
|
|
230
|
+
bottom: 0;
|
|
231
|
+
height: 100vh;
|
|
232
|
+
width: 1px;
|
|
233
|
+
background: rgba(242, 72, 34, 0.45);
|
|
234
|
+
border-left: 1px dashed rgba(242, 72, 34, 0.6);
|
|
235
|
+
}
|
|
236
|
+
`}destroy(){this.hostElement&&this.hostElement.parentNode&&this.hostElement.parentNode.removeChild(this.hostElement),this.hostElement=null,this.shadowRoot=null,this.agentsLayer=null,this.overlaysLayer=null,this.guidesLayer=null,this.mounted=false;}};var C=class a{constructor(){this.activeRestorations=new Map;this.modifiedElements=new Set;}static getElementCategory(e){let t=e.tagName.toLowerCase();return t==="pre"||t==="code"||t==="kbd"||t==="samp"?"code":t==="input"||t==="textarea"||t==="select"?"input":t==="button"||e.getAttribute("role")==="button"||e.classList.contains("btn")||e.classList.contains("button")||t==="a"&&(e.classList.contains("btn")||e.classList.contains("btn-primary")||e.classList.contains("btn-secondary"))?"button":t==="img"||t==="svg"||t==="video"||t==="canvas"||t==="picture"||t==="figure"||e.classList.contains("avatar")||e.classList.contains("icon")?"media":["p","h1","h2","h3","h4","h5","h6","span","label","blockquote","strong","em","small","b","i","li","a"].includes(t)?"text":"container"}static isTextElement(e){let t=e.tagName.toLowerCase();if(!["p","h1","h2","h3","h4","h5","h6","code","pre","span","strong","em","blockquote","li"].includes(t))return false;let n=e.textContent?.trim()||"";return n.length>0&&n.length<350&&e.childElementCount<=1}hideElement(e){if(this.modifiedElements.has(e))return;let t=e.style.opacity,i=e.style.visibility,n=e.style.transform,r=e.style.transition,s=e.style.pointerEvents;e.style.opacity="0",e.style.transform="scale(0.96)",e.style.transition="none",e.style.pointerEvents="none",this.modifiedElements.add(e),this.activeRestorations.set(e,()=>{e.style.opacity=t,e.style.visibility=i,e.style.transform=n,e.style.transition=r,e.style.pointerEvents=s,this.modifiedElements.delete(e);});}executeReveal(e,t,i,n,r){let s=false,o=null;if(t&&i&&a.isTextElement(e)){let l=e.textContent||"";e.textContent="",e.style.opacity="1",e.style.transform="scale(1)",e.style.pointerEvents="";let d=Math.max(10,Math.floor(n*.75/Math.max(l.length,1))),c=0,h=()=>{s||(c<l.length?(e.textContent=l.slice(0,c+1),c++,o=setTimeout(h,d)):(e.textContent=l,this.cleanupElement(e),r()));};o=setTimeout(h,50);let g=()=>{s=true,o&&clearTimeout(o),e.textContent=l,this.cleanupElement(e);};return this.activeRestorations.set(e,g),g}else {e.style.transition=`opacity ${n*.75}ms cubic-bezier(0.16, 1, 0.3, 1), transform ${n*.75}ms cubic-bezier(0.16, 1, 0.3, 1)`,e.offsetHeight,e.style.opacity="1",e.style.transform="scale(1)",e.style.pointerEvents="",o=setTimeout(()=>{s||(this.cleanupElement(e),r());},n);let l=()=>{s=true,o&&clearTimeout(o),this.cleanupElement(e);};return this.activeRestorations.set(e,l),l}}cleanupElement(e){e.style.transition="",e.style.transform="",e.style.opacity="",e.style.pointerEvents="",this.activeRestorations.delete(e),this.modifiedElements.delete(e);}restoreAll(){this.activeRestorations.forEach(e=>{try{e();}catch{}}),this.activeRestorations.clear(),this.modifiedElements.clear();}};var B=class{constructor(e){this.options=e;this.intersectionObserver=null;this.mutationObserver=null;this.indexedElements=[];this.observedElements=new WeakSet;this.mutationTimeout=null;}init(){return typeof window>"u"||typeof document>"u"?[]:(this.scanAndIndex(),this.setupIntersectionObserver(),this.setupMutationObserver(),this.indexedElements)}scanAndIndex(){if(typeof document>"u")return [];try{let e=Array.from(document.querySelectorAll(this.options.selector)),t=[];for(let i=0;i<e.length;i++){let n=e[i];if(!n||this.shouldIgnoreElement(n))continue;let r=n.getBoundingClientRect();r.width<8||r.height<8||t.push(n);}if(this.options.buildOrder==="top-to-bottom"){let i=window.scrollY||window.pageYOffset||0;t.sort((n,r)=>{if(n.contains(r))return -1;if(r.contains(n))return 1;let s=n.getBoundingClientRect().top+i,o=r.getBoundingClientRect().top+i;return Math.abs(s-o)<15?n.getBoundingClientRect().left-r.getBoundingClientRect().left:s-o});}else this.options.buildOrder==="random"&&t.sort(()=>Math.random()-.5);return this.options.hideOnStart&&t.forEach(i=>{this.options.builderEffects.hideElement(i);}),this.indexedElements=t,t}catch(e){return console.warn("[dom-swarm] Selector query warning:",e),[]}}setupIntersectionObserver(){typeof IntersectionObserver>"u"||(this.intersectionObserver=new IntersectionObserver(e=>{e.forEach(t=>{if(t.isIntersecting){let i=t.target;this.observedElements.has(i)||(this.observedElements.add(i),this.options.onElementDiscovered?.(i));}});},{root:null,rootMargin:"0px 0px 50px 0px",threshold:.05}),this.indexedElements.forEach(e=>{this.intersectionObserver?.observe(e);}));}setupMutationObserver(){if(typeof MutationObserver>"u"||typeof document>"u")return;this.mutationObserver=new MutationObserver(t=>{let i=false;for(let n=0;n<t.length;n++){let r=t[n];if(r&&r.addedNodes.length>0)for(let s=0;s<r.addedNodes.length;s++){let o=r.addedNodes[s];if(o instanceof HTMLElement&&o.tagName.toLowerCase()!=="dom-swarm-overlay"){i=true;break}}if(i)break}i&&(this.mutationTimeout&&clearTimeout(this.mutationTimeout),this.mutationTimeout=setTimeout(()=>{this.scanAndIndex().forEach(r=>{this.intersectionObserver?.observe(r);});},120));});let e=document.body||document.documentElement;e&&this.mutationObserver.observe(e,{childList:true,subtree:true});}shouldIgnoreElement(e){if(e.closest("dom-swarm-overlay")||e.closest(".swarm-hud")||this.options.ignoreSelector&&e.matches(this.options.ignoreSelector))return true;let t=window.getComputedStyle(e);return t.display==="none"||t.visibility==="hidden"}destroy(){this.mutationTimeout&&(clearTimeout(this.mutationTimeout),this.mutationTimeout=null),this.intersectionObserver&&(this.intersectionObserver.disconnect(),this.intersectionObserver=null),this.mutationObserver&&(this.mutationObserver.disconnect(),this.mutationObserver=null),this.indexedElements=[];}};var z={agentCount:18,teamSize:4,copyPasteDuplicates:true,colors:["#FF5722","#00BCD4","#8BC34A","#9C27B0","#FFC107","#E91E63","#2196F3"],selector:"nav, header, h1, h2, h3, h4, h5, h6, p, button, a, img, pre, code, .swarm-item, .price-card, .interactive-card, .metric-card",ignoreSelector:"[data-no-swarm], script, style, noscript, dom-swarm-overlay, .swarm-hud",hideOnStart:true,concurrency:4,buildOrder:"top-to-bottom",vanishAtCursor:true,rebuildOnRouteChange:true,buildOnScroll:true,typewriterEffect:true,showGuides:true,showDimensions:true,followMouse:true,maxSpeed:9.5,maxForce:.4,buildDuration:550,flockRadius:85,separateDistance:32,mouseAttractRadius:220,mouseAttractForce:.45,typewriterSpeed:16,debug:false},H=class{constructor(e){this.agents=[];this.tasks=new Map;this.buildQueue=[];this.activeBoxTypeToggle=false;this.mousePos=null;this.lastMouseMoveTime=0;this.isMouseActive=false;this.animFrameId=null;this.lastTime=0;this.paused=false;this.destroyed=false;this.isFinishedState=false;this.isConverging=false;this.frameCount=0;this.lastFpsUpdate=0;this.currentFps=60;this.constructedCount=0;this.constructedTemplates=[];this.lastUrl=typeof window<"u"?window.location.href:"";this.unbindRouteListeners=null;this.routeChangeDebounce=null;this.onMouseMove=e=>{this.mousePos={x:e.clientX,y:e.clientY},this.lastMouseMoveTime=performance.now(),this.isMouseActive=true;};this.onTouchMove=e=>{e.touches&&e.touches[0]&&(this.mousePos={x:e.touches[0].clientX,y:e.touches[0].clientY},this.lastMouseMoveTime=performance.now(),this.isMouseActive=true);};this.onScroll=()=>{this.syncActiveBoundingBoxes();};this.onResize=()=>{this.syncActiveBoundingBoxes();};this.renderLoop=e=>{if(!this.destroyed){if(!this.paused){let t=(e-this.lastTime)/16.666,i=Math.min(Math.max(t,.1),3);this.lastTime=e,this.frameCount++,e-this.lastFpsUpdate>=1e3&&(this.currentFps=Math.round(this.frameCount*1e3/(e-this.lastFpsUpdate)),this.frameCount=0,this.lastFpsUpdate=e),this.isMouseActive&&e-this.lastMouseMoveTime>2500&&(this.isMouseActive=false);let n=this.mousePos||u((window.innerWidth||1024)/2,(window.innerHeight||768)/2),r={width:window.innerWidth||1024,height:window.innerHeight||768};this.isConverging&&!this.isFinishedState&&this.agents.filter(o=>o.state!=="VANISHED").length===0&&(this.isFinishedState=true,this.isConverging=false,this.config.onSwarmVanished?.());for(let s=0;s<this.agents.length;s++){let o=this.agents[s];if(!(!o||o.state==="VANISHED"||o.assignedTaskId)){if(o.state==="CONVERGING_TO_USER"){let l=I.seek(o,n,50);o.applyForce(l);let d=x(n,o.position),c=L({x:-d.y,y:d.x});o.applyForce(f(c,1.4));}else if(o.state==="IDLE_FLOCKING"||o.state==="RETURNING_TO_SWARM"){let l=I.calculateFlockingForces(o,this.agents,this.isMouseActive?this.mousePos:null,this.config,r);o.applyForce(l),o.state==="RETURNING_TO_SWARM"&&o.velocity.x*o.velocity.x+o.velocity.y*o.velocity.y<3&&(o.setIdle(),this.config.onAgentStateChange?.(o.id,"IDLE_FLOCKING"));}o.update(i,this.overlayManager);}}this.tasks.forEach(s=>{if(s.completed)return;let o=s.element.getBoundingClientRect();if(s.rect=o,s.phase==="CLONING"){let l=e-s.expandStartTime,d=Math.min(l/s.expandDuration,1),c=1-Math.pow(1-d,3),h=s.sourceRect||o,g=h.left+(o.left-h.left)*c,R=h.top+(o.top-h.top)*c,S=h.width+(o.width-h.width)*c,A=h.height+(o.height-h.height)*c;if(s.cloneElement&&this.overlayManager.updateGhostClone(s.cloneElement,g,R,S,A,.95),s.assignedAgents.forEach((b,E)=>{let p=this.agents.find(m=>m.id===b);p&&(E===0?(p.position.x=g+16,p.position.y=R,p.velocity=u(0,0),p.element.style.opacity="1",p.morphIcon("hand",this.overlayManager),this.overlayManager.updateAgentTransform(p.element,p.position.x,p.position.y,0,1.05)):(p.element.style.opacity="0",p.position.x=o.left+o.width/2,p.position.y=o.top+o.height/2,p.velocity=u(0,0)));}),d>=1){s.cloneElement&&(this.overlayManager.removeGhostClone(s.cloneElement),s.cloneElement=void 0),s.boxElement=this.overlayManager.createBoundingBox(s.id,o,s.boxType,this.config.showDimensions,this.config.showGuides),s.phase="BUILDING",s.assignedAgents.forEach((E,p)=>{let m=this.agents.find(w=>w.id===E);if(m){m.element.style.opacity="1",m.setConstructing(),m.targetRect=o;let w=p===0?"pen":"pointer";m.morphIcon(w,this.overlayManager),this.config.onAgentStateChange?.(m.id,"CONSTRUCTING_ELEMENT");}});let b=this.builderEffects.executeReveal(s.element,s.isText,this.config.typewriterEffect,s.duration,()=>{this.completeTask(s.id);});s.cancelEffect=b;}}else if(s.phase==="EXPANDING"){let l=e-s.expandStartTime,d=Math.min(l/s.expandDuration,1),c=1-Math.pow(1-d,3),h=o.left,g=o.top,R=Math.max(4,o.width*c),S=Math.max(4,o.height*c),A=Math.min(d*2.5,1);if(s.boxElement&&this.overlayManager.updateBoxGeometry(s.boxElement,{left:h,top:g,width:R,height:S},A,s.id),s.assignedAgents.forEach((b,E)=>{let p=this.agents.find(m=>m.id===b);p&&(E===0?(p.position.x=h+R,p.position.y=g+S,p.velocity=u(0,0),p.element.style.opacity="1",this.overlayManager.updateAgentTransform(p.element,p.position.x,p.position.y,0,1.05)):(p.element.style.opacity="0",p.position.x=o.left+o.width/2,p.position.y=o.top+o.height/2,p.velocity=u(0,0)));}),d>=1){s.phase="BUILDING",s.assignedAgents.forEach((E,p)=>{let m=this.agents.find(w=>w.id===E);if(m){m.element.style.opacity="1",m.setConstructing(),m.targetRect=o;let w=p===0&&s.isText?"pen":"pointer";m.morphIcon(w,this.overlayManager),this.config.onAgentStateChange?.(m.id,"CONSTRUCTING_ELEMENT");}});let b=this.builderEffects.executeReveal(s.element,s.isText,this.config.typewriterEffect,s.duration,()=>{this.completeTask(s.id);});s.cancelEffect=b;}}else s.phase==="BUILDING"&&(s.boxElement&&this.overlayManager.updateBoundingBox(s.boxElement,o,s.id),s.assignedAgents.forEach(l=>{let d=this.agents.find(c=>c.id===l);d&&d.assignedTaskId===s.id&&(d.targetRect=o,d.update(i,this.overlayManager));}));});}this.animFrameId=requestAnimationFrame(this.renderLoop);}};this.config={...z,...e,container:e?.container,onAgentStateChange:e?.onAgentStateChange,onElementConstructed:e?.onElementConstructed,onAllElementsConstructed:e?.onAllElementsConstructed,onSwarmVanished:e?.onSwarmVanished},this.overlayManager=new O(this.config.container),this.builderEffects=new C,this.domScanner=new B({selector:this.config.selector,ignoreSelector:this.config.ignoreSelector,hideOnStart:this.config.hideOnStart,buildOrder:this.config.buildOrder,builderEffects:this.builderEffects,onElementDiscovered:t=>this.enqueueElement(t)}),this.init();}init(){if(typeof window>"u"||typeof document>"u")return;this.overlayManager.mount(),this.spawnAgents(),this.bindEvents();let e=this.domScanner.init();this.buildQueue=[...e],this.lastTime=performance.now(),this.lastFpsUpdate=this.lastTime,this.animFrameId=requestAnimationFrame(this.renderLoop),setTimeout(()=>{this.processBuildQueue();},150);}spawnAgents(){let e=window.innerWidth||1024,t=window.innerHeight||768,i=[];for(let n=0;n<this.config.agentCount;n++)i.push(Math.floor(n/this.config.teamSize));i.sort(()=>Math.random()-.5);for(let n=0;n<this.config.agentCount;n++){let r=this.config.colors[n%this.config.colors.length]||"#FF5722",s=i[n]??0,o=u(v(e*.1,e*.9),v(t*.1,t*.9)),l=new N(n+1,r,s,o,this.overlayManager,this.config.maxSpeed,this.config.maxForce);this.agents.push(l);}}bindEvents(){window.addEventListener("mousemove",this.onMouseMove,{passive:true}),window.addEventListener("touchstart",this.onTouchMove,{passive:true}),window.addEventListener("touchmove",this.onTouchMove,{passive:true}),window.addEventListener("scroll",this.onScroll,{passive:true}),window.addEventListener("resize",this.onResize,{passive:true}),this.setupRouteListeners();}processBuildQueue(){if(!(this.destroyed||this.paused||this.isConverging)){for(;this.tasks.size<this.config.concurrency&&this.buildQueue.length>0;){let e=this.buildQueue.shift();e&&this.constructElement(e);}this.buildQueue.length===0&&this.tasks.size===0&&!this.isFinishedState&&(this.config.onAllElementsConstructed?.(),this.config.vanishAtCursor&&!this.isConverging&&this.triggerConvergenceFinale());}}findMatchingTemplate(e,t){if(!this.config.copyPasteDuplicates||e.width<30||e.height<20)return null;for(let i=this.constructedTemplates.length-1;i>=0;i--){let n=this.constructedTemplates[i];if(!n||n.element===t)continue;let r=Math.abs(n.rect.width-e.width),s=Math.abs(n.rect.height-e.height);if(r<=16&&s<=16&&typeof document<"u"&&document.body.contains(n.element)){let o=n.element.getBoundingClientRect();if(o.width>=10&&o.height>=10)return {element:n.element,rect:o}}}return null}constructElement(e){let t=`task-${Date.now()}-${Math.random().toString(36).substring(2,6)}`,i=e.getBoundingClientRect();if(i.width<5||i.height<5){this.builderEffects.executeReveal(e,false,false,50,()=>{this.constructedCount++,this.processBuildQueue();});return}let n=C.getElementCategory(e),r=n==="text"||C.isTextElement(e),s=this.activeBoxTypeToggle?"red":"blue";this.activeBoxTypeToggle=!this.activeBoxTypeToggle;let o=u(i.left+i.width/2,i.top+i.height/2),l=this.pickTeamAgents(o,this.config.teamSize);if(l.length===0){this.builderEffects.executeReveal(e,r,this.config.typewriterEffect,this.config.buildDuration,()=>{this.constructedCount++,this.config.onElementConstructed?.(e),this.processBuildQueue();});return}let d=["top","right","bottom","left"],c=this.findMatchingTemplate(i,e),h=c!==null,g=c?c.rect:void 0,S=h?"hand":r?"pen":"pointer",A,b;h&&g?b=this.overlayManager.createGhostClone(t,g):A=this.overlayManager.createBoundingBox(t,i,s,this.config.showDimensions,this.config.showGuides,{left:i.left,top:i.top,width:0,height:0,opacity:0});let E={id:t,element:e,rect:i,boxType:s,assignedAgents:l.map(m=>m.id),borderRoles:d,phase:h?"CLONING":"EXPANDING",isCopyPaste:h,category:n,cursorType:S,sourceRect:g,startTime:performance.now(),expandStartTime:performance.now(),expandDuration:h?320:280,duration:this.config.buildDuration,isText:r,boxElement:A,cloneElement:b,completed:false};this.tasks.set(t,E),this.constructedTemplates.push({element:e,rect:i}),this.constructedTemplates.length>50&&this.constructedTemplates.shift();let p=h&&g?u(g.left+g.width/2,g.top+g.height/2):u(i.left,i.top);l.forEach((m,w)=>{let _=d[w%d.length]||"top",U=w===0?S:"pointer";m.assignTarget(p,e,t,_,i,U,this.overlayManager),h||(w===0?(m.position.x=i.left,m.position.y=i.top,m.element.style.opacity="1"):(m.element.style.opacity="0",m.position.x=i.left+i.width/2,m.position.y=i.top+i.height/2)),this.config.onAgentStateChange?.(m.id,"MOVING_TO_TARGET");});}completeTask(e){let t=this.tasks.get(e);!t||t.completed||(t.completed=true,t.boxElement&&(this.overlayManager.removeBoundingBox(t.boxElement,t.id),t.boxElement=void 0),t.cloneElement&&(this.overlayManager.removeGhostClone(t.cloneElement),t.cloneElement=void 0),t.assignedAgents.forEach(i=>{let n=this.agents.find(r=>r.id===i);n&&n.assignedTaskId===e&&(n.returnToSwarm(this.overlayManager),this.config.onAgentStateChange?.(n.id,"RETURNING_TO_SWARM"));}),this.tasks.delete(e),this.constructedCount++,this.config.onElementConstructed?.(t.element),this.processBuildQueue());}triggerConvergenceFinale(){this.isConverging=true;let e=this.mousePos||u((window.innerWidth||1024)/2,(window.innerHeight||768)/2);this.agents.forEach(t=>{t.convergeTo(e,this.overlayManager),this.config.onAgentStateChange?.(t.id,"CONVERGING_TO_USER");}),setTimeout(()=>{this.isConverging&&(this.agents.forEach(t=>{t.state="VANISHED",t.element.style.display="none";}),this.isFinishedState=true,this.isConverging=false,this.config.onSwarmVanished?.());},2500);}setupRouteListeners(){if(typeof window>"u"||!this.config.rebuildOnRouteChange)return;this.lastUrl=window.location.href;let e=()=>this.handleRouteChange();window.addEventListener("popstate",e),window.addEventListener("hashchange",e),window.addEventListener("turbo:load",e),window.addEventListener("turbolinks:load",e),window.addEventListener("astro:page-load",e),window.addEventListener("pjax:end",e);let t=history.pushState,i=history.replaceState,n=this;history.pushState=function(...r){let s=t.apply(this,r);return n.handleRouteChange(),s},history.replaceState=function(...r){let s=i.apply(this,r);return n.handleRouteChange(),s},this.unbindRouteListeners=()=>{window.removeEventListener("popstate",e),window.removeEventListener("hashchange",e),window.removeEventListener("turbo:load",e),window.removeEventListener("turbolinks:load",e),window.removeEventListener("astro:page-load",e),window.removeEventListener("pjax:end",e),history.pushState=t,history.replaceState=i;};}handleRouteChange(){this.destroyed||!this.config.rebuildOnRouteChange||typeof window>"u"||(this.routeChangeDebounce&&clearTimeout(this.routeChangeDebounce),this.routeChangeDebounce=setTimeout(()=>{let e=window.location.href;e===this.lastUrl&&this.isFinishedState||(this.lastUrl=e,this.handlePageNavigation());},60));}handlePageNavigation(){this.destroyed||(this.tasks.forEach(e=>{e.cancelEffect?.(),e.boxElement&&this.overlayManager.removeBoundingBox(e.boxElement,e.id),e.cloneElement&&this.overlayManager.removeGhostClone(e.cloneElement);}),this.tasks.clear(),this.constructedTemplates=[],this.buildQueue=[],this.constructedCount=0,this.isFinishedState=false,this.isConverging=false,setTimeout(()=>{if(this.destroyed)return;let e=this.domScanner.scanAndIndex();this.buildQueue=[...e];let t=window.innerWidth||1024,i=window.innerHeight||768;this.agents.forEach(n=>{let r=u(v(t*.1,t*.9),v(i*.1,i*.9));n.reset(r,this.overlayManager);}),setTimeout(()=>{this.destroyed||this.processBuildQueue();},150);},80));}enqueueElement(e){if(!this.buildQueue.includes(e)){if(this.buildQueue.push(e),this.isFinishedState){this.isFinishedState=false,this.isConverging=false;let t=window.innerWidth||1024,i=window.innerHeight||768;this.agents.forEach(n=>{if(n.state==="VANISHED"){let r=u(v(t*.1,t*.9),v(i*.1,i*.9));n.reset(r,this.overlayManager);}});}this.processBuildQueue();}}syncActiveBoundingBoxes(){this.tasks.size!==0&&this.tasks.forEach(e=>{if(!e.boxElement||e.completed)return;let t=e.element.getBoundingClientRect();e.rect=t,e.phase==="BUILDING"&&this.overlayManager.updateBoundingBox(e.boxElement,t,e.id),e.assignedAgents.forEach(i=>{let n=this.agents.find(r=>r.id===i);n&&n.assignedTaskId===e.id&&(n.targetRect=t);});});}pickTeamAgents(e,t){let i=this.agents.filter(r=>r.state==="IDLE_FLOCKING"||r.state==="RETURNING_TO_SWARM"),n=new Map;i.forEach(r=>{let s=n.get(r.teamId)||[];s.push(r),n.set(r.teamId,s);});for(let[,r]of n.entries())if(r.length>=t)return r.slice(0,t);return i.sort((r,s)=>{let o=T(r.position,e),l=T(s.position,e);return o-l}),i.slice(0,t)}replay(){if(this.destroyed)return;this.tasks.forEach(n=>{n.cancelEffect?.(),n.boxElement&&this.overlayManager.removeBoundingBox(n.boxElement,n.id),n.cloneElement&&this.overlayManager.removeGhostClone(n.cloneElement);}),this.tasks.clear(),this.constructedTemplates=[];let e=this.domScanner.scanAndIndex();this.buildQueue=[...e],this.constructedCount=0,this.isFinishedState=false,this.isConverging=false;let t=window.innerWidth||1024,i=window.innerHeight||768;this.agents.forEach(n=>{let r=u(v(t*.1,t*.9),v(i*.1,i*.9));n.reset(r,this.overlayManager);}),setTimeout(()=>{this.processBuildQueue();},150);}async buildElement(e){if(!this.destroyed)return new Promise(t=>{let i=this.config.onElementConstructed,n=r=>{r===e&&t();};this.config.onElementConstructed=r=>{i?.(r),n(r);},this.constructElement(e);})}pause(){this.paused=true;}resume(){this.paused&&(this.paused=false,this.lastTime=performance.now(),this.processBuildQueue());}isPaused(){return this.paused}isFinished(){return this.isFinishedState}getConfig(){return {...this.config}}updateConfig(e){this.config={...this.config,...e},(e.maxSpeed!==void 0||e.maxForce!==void 0)&&this.agents.forEach(t=>{e.maxSpeed!==void 0&&(t.maxSpeed=e.maxSpeed),e.maxForce!==void 0&&(t.maxForce=e.maxForce);});}getActiveAgentCount(){return this.agents.filter(e=>e.state!=="VANISHED").length}getMetrics(){let e=0,t=0,i=0,n=0;for(let r=0;r<this.agents.length;r++){let s=this.agents[r];s&&(s.state==="VANISHED"?n++:s.state==="CONVERGING_TO_USER"?i++:s.state==="IDLE_FLOCKING"||s.state==="RETURNING_TO_SWARM"?e++:(s.state==="CONSTRUCTING_ELEMENT"||s.state==="MOVING_TO_TARGET")&&t++);}return {fps:this.currentFps,totalAgents:this.agents.length,idleAgents:e,constructingAgents:t,convergingAgents:i,vanishedAgents:n,elementsConstructed:this.constructedCount,elementsPending:this.buildQueue.length+this.tasks.size,isFinished:this.isFinishedState}}destroy(){this.destroyed||(this.destroyed=true,this.animFrameId!==null&&(cancelAnimationFrame(this.animFrameId),this.animFrameId=null),typeof window<"u"&&(window.removeEventListener("mousemove",this.onMouseMove),window.removeEventListener("touchstart",this.onTouchMove),window.removeEventListener("touchmove",this.onTouchMove),window.removeEventListener("scroll",this.onScroll),window.removeEventListener("resize",this.onResize)),this.unbindRouteListeners&&(this.unbindRouteListeners(),this.unbindRouteListeners=null),this.routeChangeDebounce&&(clearTimeout(this.routeChangeDebounce),this.routeChangeDebounce=null),this.domScanner.destroy(),this.tasks.forEach(e=>{e.cancelEffect?.(),e.boxElement&&this.overlayManager.removeBoundingBox(e.boxElement,e.id),e.cloneElement&&this.overlayManager.removeGhostClone(e.cloneElement);}),this.tasks.clear(),this.constructedTemplates=[],this.buildQueue=[],this.agents.forEach(e=>e.destroy()),this.agents=[],this.builderEffects.restoreAll(),this.overlayManager.destroy());}};var V=class extends H{constructor(e){super(e);}},$=class extends V{},me=k;function k(a){return typeof window>"u"?{destroy:()=>{},pause:()=>{},resume:()=>{},replay:()=>{},handlePageNavigation:()=>{},buildElement:async()=>{},getConfig:()=>({}),updateConfig:()=>{},isPaused:()=>true,isFinished:()=>true,getActiveAgentCount:()=>0,getMetrics:()=>({fps:0,totalAgents:0,idleAgents:0,constructingAgents:0,convergingAgents:0,vanishedAgents:0,elementsConstructed:0,elementsPending:0,isFinished:true})}:new $(a)}typeof window<"u"&&(window.enableSwarm=k,window.swarm66=k,window.Swarm66=V,window.DomSwarm=$);var ge=k;exports.Agent=N;exports.BoidsPhysics=I;exports.BuilderEffects=C;exports.DomScanner=B;exports.DomSwarm=$;exports.OverlayManager=O;exports.Swarm66=V;exports.SwarmEngine=H;exports.add=y;exports.clamp=Z;exports.default=ge;exports.dist=T;exports.distSq=F;exports.div=D;exports.dot=K;exports.enableSwarm=k;exports.heading=Q;exports.headingDeg=W;exports.lerp=j;exports.limit=M;exports.mag=q;exports.magSq=P;exports.mult=f;exports.normalize=L;exports.randomChoice=Y;exports.randomRange=v;exports.setMag=G;exports.sub=x;exports.swarm66=me;exports.vec=u;Object.defineProperty(exports,'__esModule',{value:true});return exports;})({});//# sourceMappingURL=index.global.js.map
|
|
237
|
+
//# sourceMappingURL=index.global.js.map
|