@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.
@@ -0,0 +1,766 @@
1
+ /**
2
+ * Core type definitions for dom-swarm.
3
+ * Zero external dependencies.
4
+ */
5
+ interface Vector2D {
6
+ x: number;
7
+ y: number;
8
+ }
9
+ type AgentState = 'IDLE_FLOCKING' | 'MOVING_TO_TARGET' | 'CONSTRUCTING_ELEMENT' | 'RETURNING_TO_SWARM' | 'CONVERGING_TO_USER' | 'VANISHED';
10
+ type AgentType = 'pointer' | 'pen' | 'frame' | 'media' | 'button' | 'code' | 'ibeam' | 'hand' | 'duplicate';
11
+ type ElementCategory = 'text' | 'container' | 'media' | 'button' | 'code' | 'input';
12
+ type BoundingBoxType = 'blue' | 'red';
13
+ type BuildOrder = 'top-to-bottom' | 'random' | 'viewport';
14
+ type BorderRole = 'top' | 'right' | 'bottom' | 'left' | 'center';
15
+ type TaskPhase = 'MOVING' | 'CLONING' | 'EXPANDING' | 'BUILDING' | 'DONE';
16
+ interface SwarmConfig {
17
+ /**
18
+ * Total number of autonomous cursor agents in the swarm.
19
+ * @default 18
20
+ */
21
+ agentCount?: number;
22
+ /**
23
+ * Number of agents assigned to each construction team.
24
+ * @default 4
25
+ */
26
+ teamSize?: number;
27
+ /**
28
+ * When multiple elements/containers share the same dimensions,
29
+ * animate a Figma-style copy-paste duplication and live editing sequence.
30
+ * @default true
31
+ */
32
+ copyPasteDuplicates?: boolean;
33
+ /**
34
+ * Vibrant color palette for the cursor agents and wireframes.
35
+ * @default ['#FF5722', '#00BCD4', '#8BC34A', '#9C27B0', '#FFC107', '#E91E63', '#2196F3']
36
+ */
37
+ colors?: string[];
38
+ /**
39
+ * CSS selector matching DOM elements to reverse-engineer and construct.
40
+ * @default 'nav, header, h1, h2, h3, h4, h5, h6, p, button, a, img, pre, code, .swarm-item, .price-card, .interactive-card, .metric-card'
41
+ */
42
+ selector?: string;
43
+ /**
44
+ * CSS selector to exclude elements from swarm construction.
45
+ * @default '[data-no-swarm], script, style, noscript, dom-swarm-overlay, .swarm-hud'
46
+ */
47
+ ignoreSelector?: string;
48
+ /**
49
+ * Whether to initially hide all detected elements on page load, keeping the native background intact,
50
+ * so the swarm builds the whole page from a blank canvas.
51
+ * @default true
52
+ */
53
+ hideOnStart?: boolean;
54
+ /**
55
+ * Number of elements being constructed simultaneously in parallel by teams.
56
+ * @default 4
57
+ */
58
+ concurrency?: number;
59
+ /**
60
+ * Order in which detected elements are constructed.
61
+ * @default 'top-to-bottom'
62
+ */
63
+ buildOrder?: BuildOrder;
64
+ /**
65
+ * Once all page elements are constructed, all cursors converge to the user's cursor and vanish.
66
+ * @default true
67
+ */
68
+ vanishAtCursor?: boolean;
69
+ /**
70
+ * Automatically detect SPA client-side route changes (Next.js, React Router, Vue Router, Nuxt, SvelteKit, Turbo)
71
+ * and reconstruct elements on every visited page.
72
+ * @default true
73
+ */
74
+ rebuildOnRouteChange?: boolean;
75
+ /**
76
+ * Whether to construct elements automatically when they enter the viewport via scrolling.
77
+ * @default true
78
+ */
79
+ buildOnScroll?: boolean;
80
+ /**
81
+ * Simulate a fast typewriter reveal effect for text nodes (p, h1-h6, code, etc.).
82
+ * @default true
83
+ */
84
+ typewriterEffect?: boolean;
85
+ /**
86
+ * Show Figma-style full-screen horizontal and vertical alignment guides during construction.
87
+ * @default true
88
+ */
89
+ showGuides?: boolean;
90
+ /**
91
+ * Show dimensional pixel badge (e.g., "380 × 48") on selection bounding boxes.
92
+ * @default true
93
+ */
94
+ showDimensions?: boolean;
95
+ /**
96
+ * Whether cursor agents flock around and follow the user's active cursor/touch when idle.
97
+ * @default true
98
+ */
99
+ followMouse?: boolean;
100
+ /**
101
+ * Maximum movement velocity of agents in pixels per frame.
102
+ * @default 9.5
103
+ */
104
+ maxSpeed?: number;
105
+ /**
106
+ * Maximum steering force applied to agents.
107
+ * @default 0.4
108
+ */
109
+ maxForce?: number;
110
+ /**
111
+ * Duration in milliseconds spent constructing each element before moving to the next.
112
+ * @default 550
113
+ */
114
+ buildDuration?: number;
115
+ /**
116
+ * Radius in pixels within which agents recognize flockmates for alignment and cohesion.
117
+ * @default 85
118
+ */
119
+ flockRadius?: number;
120
+ /**
121
+ * Minimum distance agents maintain to avoid crowding each other.
122
+ * @default 32
123
+ */
124
+ separateDistance?: number;
125
+ /**
126
+ * Radius around the user's mouse within which flocking agents feel gravitational attraction.
127
+ * @default 220
128
+ */
129
+ mouseAttractRadius?: number;
130
+ /**
131
+ * Gravitational strength pulling idle agents toward the user's cursor.
132
+ * @default 0.45
133
+ */
134
+ mouseAttractForce?: number;
135
+ /**
136
+ * Minimum delay between character reveals during typewriter effect (ms).
137
+ * @default 16
138
+ */
139
+ typewriterSpeed?: number;
140
+ /**
141
+ * Mount container for the Shadow DOM overlay. Defaults to `document.body`.
142
+ */
143
+ container?: HTMLElement;
144
+ /**
145
+ * Enable diagnostic console logging.
146
+ * @default false
147
+ */
148
+ debug?: boolean;
149
+ /**
150
+ * Callback fired when an agent transitions between lifecycle states.
151
+ */
152
+ onAgentStateChange?: (agentId: number, state: AgentState) => void;
153
+ /**
154
+ * Callback fired when a DOM element has finished construction.
155
+ */
156
+ onElementConstructed?: (element: HTMLElement) => void;
157
+ /**
158
+ * Callback fired when all detected page elements have been constructed.
159
+ */
160
+ onAllElementsConstructed?: () => void;
161
+ /**
162
+ * Callback fired when the swarm has converged onto the user cursor and completely vanished.
163
+ */
164
+ onSwarmVanished?: () => void;
165
+ }
166
+ type ResolvedSwarmConfig = Required<Omit<SwarmConfig, 'container' | 'onAgentStateChange' | 'onElementConstructed' | 'onAllElementsConstructed' | 'onSwarmVanished'>> & {
167
+ container?: HTMLElement;
168
+ onAgentStateChange?: (agentId: number, state: AgentState) => void;
169
+ onElementConstructed?: (element: HTMLElement) => void;
170
+ onAllElementsConstructed?: () => void;
171
+ onSwarmVanished?: () => void;
172
+ };
173
+ interface ConstructionTask {
174
+ id: string;
175
+ element: HTMLElement;
176
+ rect: DOMRect;
177
+ boxType: BoundingBoxType;
178
+ assignedAgents: number[];
179
+ borderRoles: BorderRole[];
180
+ phase: TaskPhase;
181
+ isCopyPaste: boolean;
182
+ sourceRect?: DOMRect;
183
+ startTime: number;
184
+ expandStartTime: number;
185
+ expandDuration: number;
186
+ duration: number;
187
+ isText: boolean;
188
+ category?: ElementCategory;
189
+ cursorType?: AgentType;
190
+ boxElement?: HTMLElement;
191
+ cloneElement?: HTMLElement;
192
+ completed: boolean;
193
+ cancelEffect?: () => void;
194
+ }
195
+ interface SwarmMetrics {
196
+ fps: number;
197
+ totalAgents: number;
198
+ idleAgents: number;
199
+ constructingAgents: number;
200
+ convergingAgents: number;
201
+ vanishedAgents: number;
202
+ elementsConstructed: number;
203
+ elementsPending: number;
204
+ isFinished: boolean;
205
+ }
206
+ interface DomSwarmInstance {
207
+ destroy(): void;
208
+ pause(): void;
209
+ resume(): void;
210
+ replay(): void;
211
+ handlePageNavigation(): void;
212
+ buildElement(element: HTMLElement): Promise<void>;
213
+ getConfig(): Readonly<ResolvedSwarmConfig>;
214
+ updateConfig(newConfig: Partial<SwarmConfig>): void;
215
+ isPaused(): boolean;
216
+ isFinished(): boolean;
217
+ getActiveAgentCount(): number;
218
+ getMetrics(): SwarmMetrics;
219
+ }
220
+
221
+ /**
222
+ * Main orchestrator of dom-swarm:
223
+ * divides 18 agents into 4-agent teams, dispatches them to the 4 borders of elements,
224
+ * and converges all agents to the user's cursor to vanish upon completion.
225
+ */
226
+ declare class SwarmEngine implements DomSwarmInstance {
227
+ private config;
228
+ private overlayManager;
229
+ private builderEffects;
230
+ private domScanner;
231
+ private agents;
232
+ private tasks;
233
+ private buildQueue;
234
+ private activeBoxTypeToggle;
235
+ private mousePos;
236
+ private lastMouseMoveTime;
237
+ private isMouseActive;
238
+ private animFrameId;
239
+ private lastTime;
240
+ private paused;
241
+ private destroyed;
242
+ private isFinishedState;
243
+ private isConverging;
244
+ private frameCount;
245
+ private lastFpsUpdate;
246
+ private currentFps;
247
+ private constructedCount;
248
+ private constructedTemplates;
249
+ private lastUrl;
250
+ private unbindRouteListeners;
251
+ private routeChangeDebounce;
252
+ constructor(userConfig?: SwarmConfig);
253
+ /**
254
+ * Initializes overlay, agents, input listeners, and starts the construction sequence.
255
+ */
256
+ private init;
257
+ /**
258
+ * Spawns 18 agents divided randomly into 4-agent teams.
259
+ */
260
+ private spawnAgents;
261
+ /**
262
+ * Binds pointer and touch listeners for interactive flocking and convergence target.
263
+ */
264
+ private bindEvents;
265
+ private onMouseMove;
266
+ private onTouchMove;
267
+ private onScroll;
268
+ private onResize;
269
+ /**
270
+ * Main simulation and animation loop running on requestAnimationFrame.
271
+ */
272
+ private renderLoop;
273
+ /**
274
+ * Continuously processes elements from the queue using parallel 4-agent teams.
275
+ */
276
+ private processBuildQueue;
277
+ /**
278
+ * Checks if an element has matching dimensions to an already constructed element
279
+ * to enable Figma-style copy/paste duplicate animation.
280
+ */
281
+ private findMatchingTemplate;
282
+ /**
283
+ * Initiates live construction of an element by dispatching a team of 4 agents
284
+ * to the 4 borders of the bounding box.
285
+ */
286
+ private constructElement;
287
+ /**
288
+ * Completes a task, removes overlays, releases agents, and triggers the next queue item.
289
+ */
290
+ private completeTask;
291
+ /**
292
+ * Triggers the grand finale: all 18 cursors accelerate towards the user's cursor, swirl, and vanish.
293
+ */
294
+ private triggerConvergenceFinale;
295
+ /**
296
+ * Binds SPA client-side route change listeners for Next.js, React Router, Vue, Nuxt, SvelteKit, Turbo, etc.
297
+ */
298
+ private setupRouteListeners;
299
+ private handleRouteChange;
300
+ /**
301
+ * Public API: Reinitializes and launches the swarm construction sequence for a newly navigated page.
302
+ * Cancels in-flight tasks, clears templates, scans the new page's DOM,
303
+ * applies initial blank canvas hiding, respawns the 18 agents, and begins live construction.
304
+ */
305
+ handlePageNavigation(): void;
306
+ /**
307
+ * Adds an element to the queue dynamically.
308
+ */
309
+ private enqueueElement;
310
+ /**
311
+ * Synchronizes active bounding boxes, alignment guides, and agent border targets
312
+ * during live scrolling or resizing.
313
+ */
314
+ private syncActiveBoundingBoxes;
315
+ /**
316
+ * Selects a team of 4 available agents closest to the element.
317
+ */
318
+ private pickTeamAgents;
319
+ /**
320
+ * Public API: Replays the whole swarm construction from the beginning.
321
+ */
322
+ replay(): void;
323
+ /**
324
+ * Public API: Manually trigger construction on an element immediately.
325
+ */
326
+ buildElement(element: HTMLElement): Promise<void>;
327
+ pause(): void;
328
+ resume(): void;
329
+ isPaused(): boolean;
330
+ isFinished(): boolean;
331
+ getConfig(): Readonly<ResolvedSwarmConfig>;
332
+ updateConfig(newConfig: Partial<SwarmConfig>): void;
333
+ getActiveAgentCount(): number;
334
+ getMetrics(): SwarmMetrics;
335
+ destroy(): void;
336
+ }
337
+
338
+ /**
339
+ * Manages the open Shadow DOM overlay container, scoped CSS styles,
340
+ * SVG cursor rendering, Figma selection boxes, and alignment guides.
341
+ */
342
+ declare class OverlayManager {
343
+ private container;
344
+ private hostElement;
345
+ private shadowRoot;
346
+ private agentsLayer;
347
+ private overlaysLayer;
348
+ private guidesLayer;
349
+ private mounted;
350
+ constructor(container?: HTMLElement);
351
+ /**
352
+ * Mounts the full-screen Shadow DOM overlay.
353
+ */
354
+ mount(): boolean;
355
+ /**
356
+ * Creates an agent cursor element with crisp SVG icon (no text badges).
357
+ */
358
+ createAgentElement(id: number, color: string): {
359
+ element: HTMLElement;
360
+ iconContainer: HTMLElement;
361
+ };
362
+ /**
363
+ * Updates hardware-accelerated transform of an agent cursor.
364
+ */
365
+ updateAgentTransform(el: HTMLElement, x: number, y: number, angleDeg: number, scale?: number): void;
366
+ /**
367
+ * Morphs/switches an agent icon to match the contextual tool category
368
+ * (e.g. pen for text, frame for containers, media for images, button for clicks, duplicate for clones).
369
+ */
370
+ setAgentIcon(iconContainer: HTMLElement, type: AgentType, color: string): void;
371
+ /**
372
+ * Creates an animated selection bounding box overlay drawn by the swarm.
373
+ */
374
+ createBoundingBox(id: string, rect: DOMRect, type: BoundingBoxType, showDimensions?: boolean, showGuides?: boolean, initialGeometry?: {
375
+ left: number;
376
+ top: number;
377
+ width: number;
378
+ height: number;
379
+ opacity?: number;
380
+ }): HTMLElement;
381
+ /**
382
+ * Creates a ghost wireframe clone for Figma-style copy/paste duplicate animations.
383
+ */
384
+ createGhostClone(id: string, rect: DOMRect): HTMLElement;
385
+ /**
386
+ * Updates coordinates of the ghost clone as it glides from source to destination.
387
+ */
388
+ updateGhostClone(cloneEl: HTMLElement, x: number, y: number, width: number, height: number, opacity?: number): void;
389
+ /**
390
+ * Removes a ghost clone element.
391
+ */
392
+ removeGhostClone(cloneEl: HTMLElement): void;
393
+ /**
394
+ * Smoothly updates bounding box geometry as the swarm cursors drag/expand it.
395
+ */
396
+ updateBoxGeometry(boxEl: HTMLElement, rect: {
397
+ left: number;
398
+ top: number;
399
+ width: number;
400
+ height: number;
401
+ }, opacity?: number, id?: string): void;
402
+ /**
403
+ * Creates full-screen red alignment guide lines.
404
+ */
405
+ private createAlignmentGuides;
406
+ /**
407
+ * Updates coordinates of an existing bounding box and its alignment guides during scrolling/resizing.
408
+ */
409
+ updateBoundingBox(boxEl: HTMLElement, rect: DOMRect, id?: string): void;
410
+ /**
411
+ * Removes a bounding box overlay and any attached guide lines.
412
+ */
413
+ removeBoundingBox(boxEl: HTMLElement, id?: string): void;
414
+ /**
415
+ * Standard Pointer SVG icon string.
416
+ */
417
+ private getPointerSvg;
418
+ /**
419
+ * Pencil / Pen tool SVG for text drafting and editing.
420
+ * Sharp tip aligned at (2, 2) matching cursor transform-origin.
421
+ */
422
+ private getPenSvg;
423
+ /**
424
+ * Figma Frame / Container tool SVG with "#" layout badge.
425
+ */
426
+ private getFrameSvg;
427
+ /**
428
+ * Media / Image tool SVG with landscape photo placement badge.
429
+ */
430
+ private getMediaSvg;
431
+ /**
432
+ * Button / Interactive tool SVG with rounded button pill badge.
433
+ */
434
+ private getButtonSvg;
435
+ /**
436
+ * Code / Terminal tool SVG with code brackets badge.
437
+ */
438
+ private getCodeSvg;
439
+ /**
440
+ * I-Beam text insertion SVG icon string.
441
+ */
442
+ private getIBeamSvg;
443
+ /**
444
+ * Hand dragging tool SVG for copy-pasting elements.
445
+ * Classic Figma / OS open dragging hand anchored at top fingertip.
446
+ */
447
+ private getHandSvg;
448
+ /**
449
+ * Spawns a glowing expanding ripple when a cursor converges and vanishes into the user pointer.
450
+ */
451
+ createVanishRipple(x: number, y: number, color: string): void;
452
+ /**
453
+ * Scoped CSS styles injected directly into Shadow DOM.
454
+ */
455
+ private getScopedStyles;
456
+ /**
457
+ * Destroys and cleans up the overlay.
458
+ */
459
+ destroy(): void;
460
+ }
461
+
462
+ /**
463
+ * Individual cursor agent entity with autonomous Boids state machine,
464
+ * collaborative 4-team border construction, and convergence/vanishing finale.
465
+ */
466
+ declare class Agent {
467
+ id: number;
468
+ color: string;
469
+ teamId: number;
470
+ state: AgentState;
471
+ type: AgentType;
472
+ position: Vector2D;
473
+ velocity: Vector2D;
474
+ acceleration: Vector2D;
475
+ maxSpeed: number;
476
+ maxForce: number;
477
+ targetPosition: Vector2D | null;
478
+ targetElement: HTMLElement | null;
479
+ assignedTaskId: string | null;
480
+ borderRole: BorderRole | null;
481
+ targetRect: DOMRect | null;
482
+ private borderProgress;
483
+ element: HTMLElement;
484
+ iconContainer: HTMLElement;
485
+ private headingAngle;
486
+ private targetScale;
487
+ private currentScale;
488
+ private currentOpacity;
489
+ constructor(id: number, color: string, teamId: number, initialPos: Vector2D, overlayManager: OverlayManager, maxSpeed?: number, maxForce?: number);
490
+ /**
491
+ * Applies an external steering or acceleration force to the agent.
492
+ */
493
+ applyForce(force: Vector2D): void;
494
+ /**
495
+ * Advances the agent's physics simulation and visual presentation by delta time.
496
+ */
497
+ update(dt: number, overlayManager: OverlayManager): void;
498
+ /**
499
+ * Switches cursor avatar between arrow pointer and I-beam text tool.
500
+ */
501
+ morphIcon(newType: AgentType, overlayManager: OverlayManager): void;
502
+ /**
503
+ * Dispatches agent to navigate to a target DOM element coordinate on its border,
504
+ * switching to the element's contextual tool icon (e.g. pencil/pen for text, frame for boxes).
505
+ */
506
+ assignTarget(targetPos: Vector2D, element: HTMLElement, taskId: string, borderRole: BorderRole, rect: DOMRect, toolType: AgentType, overlayManager: OverlayManager): void;
507
+ /**
508
+ * Puts agent into element construction mode along its assigned border.
509
+ */
510
+ setConstructing(): void;
511
+ /**
512
+ * Marks construction complete and initiates return to swarm flock.
513
+ */
514
+ returnToSwarm(overlayManager: OverlayManager): void;
515
+ /**
516
+ * Directs the agent to accelerate and converge into the user's cursor, then vanish.
517
+ */
518
+ convergeTo(userPos: Vector2D, overlayManager: OverlayManager): void;
519
+ /**
520
+ * Restores agent to idle Boids flocking state.
521
+ */
522
+ setIdle(): void;
523
+ /**
524
+ * Resets agent position, visibility, and state for replaying.
525
+ */
526
+ reset(pos: Vector2D, overlayManager: OverlayManager): void;
527
+ /**
528
+ * Removes agent element from DOM.
529
+ */
530
+ destroy(): void;
531
+ }
532
+
533
+ /**
534
+ * Reynolds Boids algorithm implementation with dynamic mouse attraction
535
+ * and viewport boundary repulsion.
536
+ */
537
+ declare class BoidsPhysics {
538
+ /**
539
+ * Computes the combined flocking force for an agent in IDLE_FLOCKING or RETURNING_TO_SWARM state.
540
+ */
541
+ static calculateFlockingForces(agent: Agent, allAgents: Agent[], mousePos: Vector2D | null, config: ResolvedSwarmConfig, viewport: {
542
+ width: number;
543
+ height: number;
544
+ }): Vector2D;
545
+ /**
546
+ * Separation: steer to avoid colliding with nearby flockmates.
547
+ */
548
+ static separate(agent: Agent, agents: Agent[], desiredSeparation: number): Vector2D;
549
+ /**
550
+ * Alignment: steer towards the average velocity of nearby flockmates.
551
+ */
552
+ static align(agent: Agent, agents: Agent[], neighborDist: number): Vector2D;
553
+ /**
554
+ * Cohesion: steer to move toward the average position of nearby flockmates.
555
+ */
556
+ static cohere(agent: Agent, agents: Agent[], neighborDist: number): Vector2D;
557
+ /**
558
+ * Mouse Attraction: draws agents toward live cursor coordinates with dynamic swirling orbit.
559
+ */
560
+ static attractToMouse(agent: Agent, mousePos: Vector2D, radius: number, forceStrength: number): Vector2D;
561
+ /**
562
+ * Steer toward a specific target coordinate with arrival slowing.
563
+ */
564
+ static seek(agent: Agent, target: Vector2D, slowingRadius?: number): Vector2D;
565
+ /**
566
+ * Smooth boundary repulsion from viewport edges so agents stay visible.
567
+ */
568
+ static boundEdges(agent: Agent, viewport: {
569
+ width: number;
570
+ height: number;
571
+ }, margin?: number): Vector2D;
572
+ }
573
+
574
+ /**
575
+ * Non-destructive DOM construction visual effects:
576
+ * initial blank canvas hiding, typewriter text reveals, block scale-ins,
577
+ * and safe style restoration failsafes.
578
+ */
579
+ declare class BuilderEffects {
580
+ private activeRestorations;
581
+ private modifiedElements;
582
+ /**
583
+ * Identifies the design/semantic category of an element to pick the appropriate cursor tool
584
+ * (e.g. pencil/pen for text, frame for containers, image tool for media, button tool for clicks).
585
+ */
586
+ static getElementCategory(element: HTMLElement): ElementCategory;
587
+ /**
588
+ * Checks whether an element is suitable for a typewriter text reveal.
589
+ */
590
+ static isTextElement(element: HTMLElement): boolean;
591
+ /**
592
+ * Immediately hides an element while preserving its native document layout and background.
593
+ */
594
+ hideElement(element: HTMLElement): void;
595
+ /**
596
+ * Executes element construction reveal (typewriter for text, scale/opacity for blocks).
597
+ */
598
+ executeReveal(element: HTMLElement, isText: boolean, enableTypewriter: boolean, durationMs: number, onComplete: () => void): () => void;
599
+ /**
600
+ * Cleans up temporary inline styles applied during animation.
601
+ */
602
+ private cleanupElement;
603
+ /**
604
+ * Failsafe cleanup restoring all modified host DOM elements back to pristine native state.
605
+ */
606
+ restoreAll(): void;
607
+ }
608
+
609
+ interface DomScannerOptions {
610
+ selector: string;
611
+ ignoreSelector: string;
612
+ hideOnStart: boolean;
613
+ buildOrder: BuildOrder;
614
+ builderEffects: BuilderEffects;
615
+ onElementDiscovered?: (element: HTMLElement) => void;
616
+ }
617
+ /**
618
+ * Scans, indexes, and prepares host DOM elements for live swarm construction,
619
+ * sorting elements in natural visual sequence (top-to-bottom).
620
+ */
621
+ declare class DomScanner {
622
+ private options;
623
+ private intersectionObserver;
624
+ private mutationObserver;
625
+ private indexedElements;
626
+ private observedElements;
627
+ private mutationTimeout;
628
+ constructor(options: DomScannerOptions);
629
+ /**
630
+ * Initializes DOM scanning, initial element hiding, and observers.
631
+ */
632
+ init(): HTMLElement[];
633
+ /**
634
+ * Scans document for eligible elements, applies initial blank state if enabled,
635
+ * and returns elements sorted by buildOrder.
636
+ */
637
+ scanAndIndex(): HTMLElement[];
638
+ /**
639
+ * Intersection observer to trigger scroll-based builds if configured.
640
+ */
641
+ private setupIntersectionObserver;
642
+ /**
643
+ * Monitors dynamic component mounting for SPA client-side route changes.
644
+ */
645
+ private setupMutationObserver;
646
+ /**
647
+ * Evaluates if element matches ignore selectors or is structurally hidden.
648
+ */
649
+ private shouldIgnoreElement;
650
+ /**
651
+ * Destroys observers.
652
+ */
653
+ destroy(): void;
654
+ }
655
+
656
+ /**
657
+ * Creates a 2D vector.
658
+ */
659
+ declare function vec(x?: number, y?: number): Vector2D;
660
+ /**
661
+ * Adds two vectors.
662
+ */
663
+ declare function add(v1: Vector2D, v2: Vector2D): Vector2D;
664
+ /**
665
+ * Subtracts v2 from v1.
666
+ */
667
+ declare function sub(v1: Vector2D, v2: Vector2D): Vector2D;
668
+ /**
669
+ * Multiplies vector by scalar.
670
+ */
671
+ declare function mult(v: Vector2D, n: number): Vector2D;
672
+ /**
673
+ * Divides vector by scalar.
674
+ */
675
+ declare function div(v: Vector2D, n: number): Vector2D;
676
+ /**
677
+ * Squared magnitude of a vector.
678
+ */
679
+ declare function magSq(v: Vector2D): number;
680
+ /**
681
+ * Magnitude (length) of a vector.
682
+ */
683
+ declare function mag(v: Vector2D): number;
684
+ /**
685
+ * Squared Euclidean distance between two points.
686
+ */
687
+ declare function distSq(v1: Vector2D, v2: Vector2D): number;
688
+ /**
689
+ * Euclidean distance between two points.
690
+ */
691
+ declare function dist(v1: Vector2D, v2: Vector2D): number;
692
+ /**
693
+ * Normalizes vector to unit length (length = 1).
694
+ */
695
+ declare function normalize(v: Vector2D): Vector2D;
696
+ /**
697
+ * Sets magnitude of a vector to specified length.
698
+ */
699
+ declare function setMag(v: Vector2D, n: number): Vector2D;
700
+ /**
701
+ * Limits magnitude of vector to max value.
702
+ */
703
+ declare function limit(v: Vector2D, maxVal: number): Vector2D;
704
+ /**
705
+ * Calculates heading angle in radians (-PI to PI).
706
+ */
707
+ declare function heading(v: Vector2D): number;
708
+ /**
709
+ * Calculates heading angle in degrees (0 to 360 or -180 to 180).
710
+ */
711
+ declare function headingDeg(v: Vector2D): number;
712
+ /**
713
+ * Linear interpolation between two values.
714
+ */
715
+ declare function lerp(start: number, end: number, amt: number): number;
716
+ /**
717
+ * Clamps a number between min and max bounds.
718
+ */
719
+ declare function clamp(val: number, min: number, max: number): number;
720
+ /**
721
+ * Generates random float between min and max.
722
+ */
723
+ declare function randomRange(min: number, max: number): number;
724
+ /**
725
+ * Selects a random element from an array.
726
+ */
727
+ declare function randomChoice<T>(items: T[]): T;
728
+ /**
729
+ * Computes dot product of two vectors.
730
+ */
731
+ declare function dot(v1: Vector2D, v2: Vector2D): number;
732
+
733
+ /**
734
+ * Public class implementation of Swarm66 / DomSwarm.
735
+ */
736
+ declare class Swarm66 extends SwarmEngine {
737
+ constructor(config?: SwarmConfig);
738
+ }
739
+ declare class DomSwarm extends Swarm66 {
740
+ }
741
+ /**
742
+ * Convenience alias for swarm66 initialization.
743
+ */
744
+ declare const swarm66: typeof enableSwarm;
745
+ /**
746
+ * Convenience factory to mount and enable the DomSwarm visual engine on any page.
747
+ * Safe for Server-Side Rendering (SSR) environments.
748
+ *
749
+ * @param config Optional configuration options to customize swarm behaviors and visuals.
750
+ * @returns An active DomSwarmInstance controlling the swarm.
751
+ *
752
+ * @example
753
+ * ```ts
754
+ * import { enableSwarm } from 'dom-swarm';
755
+ *
756
+ * const swarm = enableSwarm({
757
+ * agentCount: 20,
758
+ * hideOnStart: true,
759
+ * vanishAtCursor: true,
760
+ * typewriterEffect: true,
761
+ * });
762
+ * ```
763
+ */
764
+ declare function enableSwarm(config?: SwarmConfig): DomSwarmInstance;
765
+
766
+ export { Agent, type AgentState, type AgentType, BoidsPhysics, type BorderRole, type BoundingBoxType, type BuildOrder, BuilderEffects, type ConstructionTask, DomScanner, DomSwarm, type DomSwarmInstance, type ElementCategory, OverlayManager, type ResolvedSwarmConfig, Swarm66, type SwarmConfig, SwarmEngine, type SwarmMetrics, type TaskPhase, type Vector2D, add, clamp, enableSwarm as default, dist, distSq, div, dot, enableSwarm, heading, headingDeg, lerp, limit, mag, magSq, mult, normalize, randomChoice, randomRange, setMag, sub, swarm66, vec };