How tahash/swapy works
Project type and purpose
• From the README (“A framework-agnostic tool that converts any layout into a drag-to-swap one…”) and the file tree, this is a front-end JavaScript/TypeScript library (not a full-stack web app).
• It’s meant to be built once (via Vite/Rollup) and then published (npm dist/ files) and consumed by any framework (React, Vue, Svelte, vanilla, etc.).
File structure
• Top-level build/config files:
• package.json / pnpm-lock.yaml
• tsconfig.json / tsconfig.build.json
• vite.config.ts
• /src: Core library modules (animators.ts, draggable.ts, flip.ts, utils.ts, view.ts, etc.)
• /dist: Compiled output (swapy.js, swapy.d.ts)
• /examples: Demo consumer apps in various frameworks, each with its own index.html + main.ts(x)
README for additional insights
a. Main components
1. Source modules (in /src):
– Core logic sub-components:
• Drag & drop logic (draggable.ts)
• Animation routines (animators.ts, easings.ts)
• Layout utilities (math.ts, rect.ts, vector.ts)
• Flip transition engine (flip.ts)
• API entry point (index.ts)
2. Build toolchain:
– Vite (build orchestrator)
– TypeScript compiler
– Output bundler (Rollup under the hood)
3. Published package:
– Dist artifact (swapy.js + swapy.d.ts) pushed to npm
4. Consumer applications (examples):
– React, Vue, Svelte, vanilla demos that import swapy.js
5. Optional external services:
– Documentation site (swapy.tahazsh.com)
b. Relationships & data flow
– “Source modules” → (via TS compile & Rollup/Vite) → “Dist bundle”
– “Dist bundle” → (npm publish) → “Consumer apps”
– “Consumer apps” → at runtime → interact with DOM/layout and call into the library API
– (Optionally) “Consumer” authors visit the documentation site for usage guidance
c. Architectural patterns & design principles
– Modular single-responsibility modules in /src (e.g., separate math, DOM view, animation, swapping logic)
– Build-time separation (source vs. dist)
– Framework-agnostic public API (index.ts) that decouples from any UI framework
– Demo sandbox pattern under /examples to validate cross-framework compatibility
d. Key technologies
– TypeScript for type-safe source
– Vite as the build orchestrator (leveraging ES modules & Rollup)
– PNPM as the package manager
– Framework examples: React, Vue, Svelte, vanilla