wirepulse 0.0.0-stage → 0.1.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/CHANGELOG.md +13 -0
- package/LICENSE +21 -0
- package/README.md +163 -2
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +263 -0
- package/dist/icons.d.ts +7 -0
- package/dist/icons.js +41 -0
- package/dist/index.d.ts +21 -0
- package/dist/index.js +23 -0
- package/dist/layout.d.ts +6 -0
- package/dist/layout.js +387 -0
- package/dist/parser.d.ts +10 -0
- package/dist/parser.js +401 -0
- package/dist/renderer.d.ts +6 -0
- package/dist/renderer.js +330 -0
- package/dist/studio-html.d.ts +7 -0
- package/dist/studio-html.js +852 -0
- package/dist/studio.d.ts +14 -0
- package/dist/studio.js +155 -0
- package/dist/templates.d.ts +8 -0
- package/dist/templates.js +167 -0
- package/dist/themes.d.ts +47 -0
- package/dist/themes.js +208 -0
- package/dist/types.d.ts +109 -0
- package/dist/types.js +1 -0
- package/dist/validator.d.ts +10 -0
- package/dist/validator.js +84 -0
- package/package.json +58 -4
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to `wirepulse` will be documented in this file.
|
|
4
|
+
|
|
5
|
+
## [0.1.0] - 2026-12-04
|
|
6
|
+
|
|
7
|
+
### Added
|
|
8
|
+
- Human-friendly `.wp` Diagram-as-Code DSL parser and JSON spec parser with line-numbered diagnostics.
|
|
9
|
+
- Hybrid automatic topological layered layout engine (cycle-safe, barycenter crossing reduction) with explicit `col`/`row` overrides and group/cluster bounding boxes.
|
|
10
|
+
- Pure zero-JS animated SVG compiler supporting flowing packets (`<animateMotion>`), animated dashes, pulse waves, bidirectional traffic, glowing active node LEDs, floating metric badges, 30 inline vector icons, 6 themes (`auto`, `midnight`, `linear`, `blueprint`, `terminal`, `paper`), automatic GitHub Dark/Light mode (`prefers-color-scheme`), and `prefers-reduced-motion` support.
|
|
11
|
+
- Local-first interactive **Visual Studio** (`npx wirepulse studio`) with live editor, drag-and-drop grid snapping, GitHub Light/Dark preview switcher, 6 real-world templates, shareable hash URLs, and 1-click SVG, 2x PNG, and animated WebM export.
|
|
12
|
+
- GitHub README / Camo CSP validator (`wirepulse validate`) and CLI workflow (`init`, `build`, `build --light-dark`, `watch`, `studio`, `templates`).
|
|
13
|
+
- Zero runtime dependencies and full TypeScript programmatic SDK.
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Rynia
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,164 @@
|
|
|
1
|
-
#
|
|
1
|
+
# wirepulse
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
> **Pure zero-JS animated architecture SVGs from a human-friendly DSL or local Visual Studio — built natively for GitHub `README.md`.**
|
|
4
|
+
|
|
5
|
+
[](https://github.com/Rynia/wirepulse/actions/workflows/ci.yml)
|
|
6
|
+
[](LICENSE)
|
|
7
|
+
[](https://nodejs.org)
|
|
8
|
+
[](#why-wirepulse)
|
|
9
|
+
[-22d3ee.svg)](#github-readme-csp-safety)
|
|
10
|
+
|
|
11
|
+

|
|
12
|
+
|
|
13
|
+
*(The diagram above is a **21 KB pure SVG** compiled by `wirepulse` — zero JavaScript, zero external assets, auto-adapts to GitHub Light & Dark mode, and degrades gracefully for `prefers-reduced-motion`.)*
|
|
14
|
+
|
|
15
|
+
---
|
|
16
|
+
|
|
17
|
+
## Why `wirepulse`?
|
|
18
|
+
|
|
19
|
+
Static Mermaid/Excalidraw boxes work fine, until you want your README or docs to actually **show data moving through your architecture** like Stripe, Linear, or Vercel docs.
|
|
20
|
+
|
|
21
|
+
Existing animated diagram tools rely on **JavaScript (GSAP / React)** — which GitHub's Camo proxy strips and blocks inside `README.md`.
|
|
22
|
+
|
|
23
|
+
**`wirepulse`** compiles a clean Diagram-as-Code DSL (`.wp` or `.json`) — or edits from its built-in drag-and-drop **Visual Studio** — into **100% self-contained, zero-JS animated SVGs**:
|
|
24
|
+
|
|
25
|
+
| Feature | `wirepulse` | Mermaid / D2 | GSAP / HTML Diagram Tools |
|
|
26
|
+
| --- | :---: | :---: | :---: |
|
|
27
|
+
| **Live Animated Data Packets & Flows** | ✅ | ❌ | ✅ |
|
|
28
|
+
| **Works Natively Inside GitHub `README.md` (Zero JS)** | ✅ | ✅ | ❌ *(blocked by CSP)* |
|
|
29
|
+
| **Auto GitHub Light & Dark Mode (`prefers-color-scheme`)** | ✅ | ⚠️ | ❌ |
|
|
30
|
+
| **Built-In Drag-and-Drop Local Visual Studio** | ✅ | ❌ | ⚠️ |
|
|
31
|
+
| **1-Click Export to SVG, 2x PNG & Animated WebM** | ✅ | ❌ | ❌ |
|
|
32
|
+
| **Zero Runtime Dependencies (`npx` Cold Start < 1s)** | ✅ | ❌ | ❌ |
|
|
33
|
+
|
|
34
|
+
---
|
|
35
|
+
|
|
36
|
+
## Visual Studio (`npx wirepulse studio`)
|
|
37
|
+
|
|
38
|
+
Launch the local-first Visual Studio in one command — no account, no cloud server, no build step:
|
|
39
|
+
|
|
40
|
+
```bash
|
|
41
|
+
npx wirepulse studio
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+

|
|
45
|
+
|
|
46
|
+
- **Live Split-Pane Editor** with real-time syntax diagnostics and **6 built-in architecture templates**
|
|
47
|
+
- **Drag-and-Drop Node Repositioning** right on the SVG canvas (snaps cleanly to grid and updates your `.wp` code!)
|
|
48
|
+
- **GitHub Light / Dark Mode Live Preview** to inspect `theme: auto` before committing
|
|
49
|
+
- **1-Click Exports:** Pure Animated `.svg`, GitHub `<picture>` Light+Dark Markdown snippet, **2x Retina `.png`**, **Animated `.webm` video** (for X/Twitter, LinkedIn & slides), and **Shareable URLs**
|
|
50
|
+
- **Live Disk Sync:** Pass `--file architecture.wp` and hit `Ctrl+S` to save directly back to your repository!
|
|
51
|
+
|
|
52
|
+
---
|
|
53
|
+
|
|
54
|
+
## Quick Start (CLI)
|
|
55
|
+
|
|
56
|
+
### 1. Scaffold a Starter Diagram
|
|
57
|
+
```bash
|
|
58
|
+
npx wirepulse init architecture.wp --template microservices-kafka
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
### 2. Compile to a GitHub-Safe Animated SVG
|
|
62
|
+
```bash
|
|
63
|
+
npx wirepulse build architecture.wp -o docs/architecture.svg
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
### 3. Or Emit Explicit Light + Dark SVGs with `<picture>` Snippet
|
|
67
|
+
```bash
|
|
68
|
+
npx wirepulse build architecture.wp -o docs/architecture.svg --light-dark
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
### 4. Validate Any SVG for GitHub README / Camo Safety
|
|
72
|
+
```bash
|
|
73
|
+
npx wirepulse validate docs/architecture.svg
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
### 5. Watch Mode (Rebuild on Every Save)
|
|
77
|
+
```bash
|
|
78
|
+
npx wirepulse watch architecture.wp -o docs/architecture.svg
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
---
|
|
82
|
+
|
|
83
|
+
## Showcase (All Generated by `wirepulse`)
|
|
84
|
+
|
|
85
|
+
### Microservices + Kafka (`theme: midnight`)
|
|
86
|
+

|
|
87
|
+
|
|
88
|
+
### Hybrid RAG & Vector Search (`theme: blueprint`)
|
|
89
|
+

|
|
90
|
+
|
|
91
|
+
---
|
|
92
|
+
|
|
93
|
+
## DSL Syntax (`.wp`)
|
|
94
|
+
|
|
95
|
+
```yaml
|
|
96
|
+
title: AI Coding Agent & MCP Runtime
|
|
97
|
+
subtitle: Pure zero-JS animated SVG — auto-adapts to GitHub Light & Dark mode
|
|
98
|
+
theme: auto # auto | midnight | linear | blueprint | terminal | paper
|
|
99
|
+
direction: LR # LR | TB
|
|
100
|
+
speed: normal # slow | normal | fast
|
|
101
|
+
|
|
102
|
+
group client "Developer" color=cyan
|
|
103
|
+
group runtime "Agent Harness" color=violet
|
|
104
|
+
group tools "MCP Servers" color=emerald
|
|
105
|
+
|
|
106
|
+
node ide "IDE / Terminal" sub="Claude Code · Cursor" icon=terminal color=cyan group=client pulse=true
|
|
107
|
+
node agent "Agent Loop" sub="200k Context" icon=sparkles color=violet badge="LLM" group=runtime pulse=true
|
|
108
|
+
node router "MCP Router" sub="JSON-RPC 2.0" icon=cpu color=blue group=runtime
|
|
109
|
+
node repo "Codebase" sub="AST + Git Diffs" icon=git color=emerald group=tools
|
|
110
|
+
node vec "Vector Index" sub="pgvector" icon=database color=amber group=tools
|
|
111
|
+
node web "Web Grounding" sub="Live Docs" icon=globe color=rose group=tools
|
|
112
|
+
|
|
113
|
+
ide -> agent "prompt" flow=packet color=cyan speed=fast
|
|
114
|
+
agent <-> router "tools/call" flow=packet color=violet packets=2
|
|
115
|
+
router <-> repo "read / edit" flow=dash color=emerald
|
|
116
|
+
router -> vec "semantic search" flow=packet color=amber
|
|
117
|
+
router -> web "fetch url" flow=pulse color=rose
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
### Layout, Styling & Animation Reference
|
|
121
|
+
|
|
122
|
+
- **Automatic Layered Layout:** Omit coordinates and `wirepulse` computes a clean topological layout with barycenter crossing minimization. Override any node with `col=1 row=2` (or drag it in Studio!).
|
|
123
|
+
- **Flow Types:** `flow=packet` (glowing moving data packets), `flow=dash` (flowing dashed wire), `flow=pulse` (traveling light wave), `flow=solid` (clean static wire).
|
|
124
|
+
- **Bidirectional Wires:** Use `<->` (or `bidir=true`) for two-way arrowheads and reverse-direction return packets.
|
|
125
|
+
- **Themes:** `auto` (adapts seamlessly to GitHub Light & Dark via `@media (prefers-color-scheme: dark)`), `midnight`, `linear`, `blueprint`, `terminal`, `paper`.
|
|
126
|
+
- **Accents:** `cyan`, `violet`, `emerald`, `amber`, `rose`, `blue`, `orange`, `slate`.
|
|
127
|
+
- **30 Built-In Inline Vector Icons:** `browser`, `terminal`, `server`, `database`, `bolt`, `cache`, `queue`, `shield`, `sparkles`, `ai`, `cpu`, `git`, `globe`, `cloud`, `box`, `user`, `mobile`, `code`, `lock`, `plug`, `layers`, `storage`, `chart`, `mail`, `clock`, `key`, `search`, `check`, `api`, `lambda`.
|
|
128
|
+
|
|
129
|
+
---
|
|
130
|
+
|
|
131
|
+
## Programmatic TypeScript / Node.js API
|
|
132
|
+
|
|
133
|
+
```ts
|
|
134
|
+
import { compileDiagram } from "wirepulse";
|
|
135
|
+
|
|
136
|
+
const { svg, errors, validation } = compileDiagram(`
|
|
137
|
+
title: Payment Flow
|
|
138
|
+
theme: auto
|
|
139
|
+
node web "Checkout" icon=browser color=cyan pulse=true
|
|
140
|
+
node api "Stripe API" icon=shield color=violet badge="TLS 1.3"
|
|
141
|
+
web -> api "charge" flow=packet color=cyan packets=2
|
|
142
|
+
`);
|
|
143
|
+
|
|
144
|
+
console.log(validation.githubSafe); // true
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
---
|
|
148
|
+
|
|
149
|
+
## GitHub README CSP Safety
|
|
150
|
+
|
|
151
|
+
Every SVG compiled by `wirepulse` is verified against strict rules:
|
|
152
|
+
- **Zero `<script>` tags** and **zero `on*=` event handlers**
|
|
153
|
+
- **Zero external URLs** (all 30 icons and CSS styles are strictly inline)
|
|
154
|
+
- **Frame-0 & `prefers-reduced-motion` safe** (every node, wire, arrow, and label is fully drawn at `t = 0` so static previews, PDFs, and reduced-motion browsers look razor sharp)
|
|
155
|
+
|
|
156
|
+
---
|
|
157
|
+
|
|
158
|
+
## Contributing
|
|
159
|
+
|
|
160
|
+
Contributions are warmly welcomed! See [CONTRIBUTING.md](CONTRIBUTING.md) for ideas like new icons, theme presets, sequence diagram layouts, and Mermaid importers.
|
|
161
|
+
|
|
162
|
+
## License
|
|
163
|
+
|
|
164
|
+
[MIT](LICENSE)
|
package/dist/cli.d.ts
ADDED
package/dist/cli.js
ADDED
|
@@ -0,0 +1,263 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { spawn } from "node:child_process";
|
|
3
|
+
import fs from "node:fs";
|
|
4
|
+
import path from "node:path";
|
|
5
|
+
import { parseArgs } from "node:util";
|
|
6
|
+
import { compileDiagram, VERSION } from "./index.js";
|
|
7
|
+
import { startStudioServer } from "./studio.js";
|
|
8
|
+
import { getTemplateById, TEMPLATES } from "./templates.js";
|
|
9
|
+
import { THEME_NAMES } from "./themes.js";
|
|
10
|
+
import { validateSvg } from "./validator.js";
|
|
11
|
+
const useColor = process.env.NO_COLOR === undefined &&
|
|
12
|
+
(process.env.FORCE_COLOR !== undefined || Boolean(process.stdout.isTTY));
|
|
13
|
+
const fmt = (code, s) => (useColor ? `\x1b[${code}m${s}\x1b[0m` : s);
|
|
14
|
+
const HELP = `
|
|
15
|
+
${fmt("1;36", "wirepulse")} ${fmt("2", `v${VERSION}`)} — Pure zero-JS animated architecture SVGs for GitHub READMEs
|
|
16
|
+
|
|
17
|
+
${fmt("1", "USAGE")}
|
|
18
|
+
wirepulse <command> [options]
|
|
19
|
+
|
|
20
|
+
${fmt("1", "COMMANDS")}
|
|
21
|
+
build <file> Compile a .wp or .json diagram into an animated .svg
|
|
22
|
+
watch <file> Watch a diagram file and rebuild automatically on save
|
|
23
|
+
studio Launch the local interactive Visual Studio in your browser
|
|
24
|
+
validate <svg> Verify GitHub README / Camo CSP safety of an SVG file
|
|
25
|
+
init [file] Scaffold a starter architecture.wp diagram
|
|
26
|
+
templates List all built-in architecture templates
|
|
27
|
+
|
|
28
|
+
${fmt("1", "OPTIONS")}
|
|
29
|
+
-o, --out <path> Output SVG path (default: <input>.svg)
|
|
30
|
+
-t, --theme <name> Override theme (${THEME_NAMES.join(", ")})
|
|
31
|
+
--light-dark Emit both -light.svg and -dark.svg + print <picture> Markdown
|
|
32
|
+
--speed <num> Animation speed multiplier (e.g. 0.5, 1, 1.5, 2)
|
|
33
|
+
--no-grid Hide background dot grid
|
|
34
|
+
--no-watermark Hide subtle corner watermark
|
|
35
|
+
-p, --port <num> Studio HTTP port (default: 4173)
|
|
36
|
+
-f, --file <path> Attach a .wp file to Studio for live Ctrl+S saving
|
|
37
|
+
--no-open Do not auto-open browser when starting Studio
|
|
38
|
+
--template <id> Template id for \`init\` (default: ai-agent-mcp)
|
|
39
|
+
-v, --version Show version
|
|
40
|
+
-h, --help Show this help
|
|
41
|
+
|
|
42
|
+
${fmt("1", "EXAMPLES")}
|
|
43
|
+
npx wirepulse studio
|
|
44
|
+
npx wirepulse init architecture.wp --template microservices-kafka
|
|
45
|
+
npx wirepulse build architecture.wp -o docs/architecture.svg
|
|
46
|
+
npx wirepulse build architecture.wp --light-dark
|
|
47
|
+
npx wirepulse validate docs/architecture.svg
|
|
48
|
+
`;
|
|
49
|
+
function openBrowser(url) {
|
|
50
|
+
const cmd = process.platform === "win32"
|
|
51
|
+
? "cmd"
|
|
52
|
+
: process.platform === "darwin"
|
|
53
|
+
? "open"
|
|
54
|
+
: "xdg-open";
|
|
55
|
+
const args = process.platform === "win32" ? ["/c", "start", "", url] : [url];
|
|
56
|
+
try {
|
|
57
|
+
const child = spawn(cmd, args, { detached: true, stdio: "ignore" });
|
|
58
|
+
child.unref();
|
|
59
|
+
}
|
|
60
|
+
catch {
|
|
61
|
+
// non-fatal if headless
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
function defaultOutPath(inputPath) {
|
|
65
|
+
const parsed = path.parse(inputPath);
|
|
66
|
+
return path.join(parsed.dir, `${parsed.name}.svg`);
|
|
67
|
+
}
|
|
68
|
+
function buildOnce(inputPath, outPath, themeOverride, speedMul, showGrid, includeWatermark, lightDark) {
|
|
69
|
+
if (!fs.existsSync(inputPath)) {
|
|
70
|
+
console.error(`${fmt("31", "Error:")} Input file not found: ${inputPath}`);
|
|
71
|
+
return false;
|
|
72
|
+
}
|
|
73
|
+
const source = fs.readFileSync(inputPath, "utf8");
|
|
74
|
+
const outDir = path.dirname(outPath);
|
|
75
|
+
if (outDir && !fs.existsSync(outDir)) {
|
|
76
|
+
fs.mkdirSync(outDir, { recursive: true });
|
|
77
|
+
}
|
|
78
|
+
if (lightDark) {
|
|
79
|
+
const parsed = path.parse(outPath);
|
|
80
|
+
const lightPath = path.join(parsed.dir, `${parsed.name}-light.svg`);
|
|
81
|
+
const darkPath = path.join(parsed.dir, `${parsed.name}-dark.svg`);
|
|
82
|
+
const lightRes = compileDiagram(source, {
|
|
83
|
+
theme: "paper",
|
|
84
|
+
speedMultiplier: speedMul,
|
|
85
|
+
showGrid,
|
|
86
|
+
includeWatermark,
|
|
87
|
+
});
|
|
88
|
+
const darkRes = compileDiagram(source, {
|
|
89
|
+
theme: "midnight",
|
|
90
|
+
speedMultiplier: speedMul,
|
|
91
|
+
showGrid,
|
|
92
|
+
includeWatermark,
|
|
93
|
+
});
|
|
94
|
+
for (const err of lightRes.errors) {
|
|
95
|
+
console.error(`${fmt("33", `Warn (line ${err.line}):`)} ${err.message}`);
|
|
96
|
+
}
|
|
97
|
+
fs.writeFileSync(lightPath, lightRes.svg, "utf8");
|
|
98
|
+
fs.writeFileSync(darkPath, darkRes.svg, "utf8");
|
|
99
|
+
console.log(`${fmt("32", "✔")} Built light (${(lightRes.validation.bytes / 1024).toFixed(1)} KB) → ${fmt("36", lightPath)}`);
|
|
100
|
+
console.log(`${fmt("32", "✔")} Built dark (${(darkRes.validation.bytes / 1024).toFixed(1)} KB) → ${fmt("36", darkPath)}`);
|
|
101
|
+
console.log(`\n${fmt("1", "GitHub README.md snippet:")}`);
|
|
102
|
+
console.log(`<picture>`);
|
|
103
|
+
console.log(` <source media="(prefers-color-scheme: dark)" srcset="${path.basename(darkPath)}" />`);
|
|
104
|
+
console.log(` <source media="(prefers-color-scheme: light)" srcset="${path.basename(lightPath)}" />`);
|
|
105
|
+
console.log(` <img alt="Architecture Diagram" src="${path.basename(darkPath)}" />`);
|
|
106
|
+
console.log(`</picture>`);
|
|
107
|
+
return lightRes.validation.githubSafe && darkRes.validation.githubSafe;
|
|
108
|
+
}
|
|
109
|
+
const res = compileDiagram(source, {
|
|
110
|
+
theme: themeOverride,
|
|
111
|
+
speedMultiplier: speedMul,
|
|
112
|
+
showGrid,
|
|
113
|
+
includeWatermark,
|
|
114
|
+
});
|
|
115
|
+
for (const err of res.errors) {
|
|
116
|
+
console.error(`${fmt("33", `Warn (line ${err.line}):`)} ${err.message}`);
|
|
117
|
+
}
|
|
118
|
+
fs.writeFileSync(outPath, res.svg, "utf8");
|
|
119
|
+
const statusTag = res.validation.githubSafe
|
|
120
|
+
? fmt("32", "GitHub CSP Safe")
|
|
121
|
+
: fmt("31", "CSP Issues");
|
|
122
|
+
console.log(`${fmt("32", "✔")} Built ${fmt("36", outPath)} (${(res.validation.bytes / 1024).toFixed(1)} KB · ${statusTag})`);
|
|
123
|
+
return res.validation.githubSafe;
|
|
124
|
+
}
|
|
125
|
+
async function main() {
|
|
126
|
+
let parsed;
|
|
127
|
+
try {
|
|
128
|
+
parsed = parseArgs({
|
|
129
|
+
allowPositionals: true,
|
|
130
|
+
options: {
|
|
131
|
+
out: { type: "string", short: "o" },
|
|
132
|
+
theme: { type: "string", short: "t" },
|
|
133
|
+
"light-dark": { type: "boolean", default: false },
|
|
134
|
+
speed: { type: "string" },
|
|
135
|
+
"no-grid": { type: "boolean", default: false },
|
|
136
|
+
"no-watermark": { type: "boolean", default: false },
|
|
137
|
+
port: { type: "string", short: "p" },
|
|
138
|
+
file: { type: "string", short: "f" },
|
|
139
|
+
"no-open": { type: "boolean", default: false },
|
|
140
|
+
template: { type: "string" },
|
|
141
|
+
version: { type: "boolean", short: "v", default: false },
|
|
142
|
+
help: { type: "boolean", short: "h", default: false },
|
|
143
|
+
},
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
catch (err) {
|
|
147
|
+
console.error(`${fmt("31", "Error:")} ${err instanceof Error ? err.message : String(err)}`);
|
|
148
|
+
process.exit(2);
|
|
149
|
+
}
|
|
150
|
+
const { values, positionals } = parsed;
|
|
151
|
+
if (values.help || positionals.length === 0) {
|
|
152
|
+
console.log(HELP);
|
|
153
|
+
return;
|
|
154
|
+
}
|
|
155
|
+
if (values.version) {
|
|
156
|
+
console.log(VERSION);
|
|
157
|
+
return;
|
|
158
|
+
}
|
|
159
|
+
const cmd = positionals[0].toLowerCase();
|
|
160
|
+
const themeOverride = values.theme ? values.theme.toLowerCase() : undefined;
|
|
161
|
+
const speedMul = values.speed ? Number(values.speed) : 1;
|
|
162
|
+
const showGrid = !values["no-grid"];
|
|
163
|
+
const includeWatermark = !values["no-watermark"];
|
|
164
|
+
if (cmd === "templates") {
|
|
165
|
+
console.log(`\n${fmt("1;36", "Built-in wirepulse templates:")}\n`);
|
|
166
|
+
for (const t of TEMPLATES) {
|
|
167
|
+
console.log(` ${fmt("1", t.id.padEnd(22))} ${t.description}`);
|
|
168
|
+
}
|
|
169
|
+
console.log(`\nRun ${fmt("36", "wirepulse init architecture.wp --template <id>")} to scaffold one.\n`);
|
|
170
|
+
return;
|
|
171
|
+
}
|
|
172
|
+
if (cmd === "init") {
|
|
173
|
+
const target = path.resolve(positionals[1] || "architecture.wp");
|
|
174
|
+
const tplId = values.template || "ai-agent-mcp";
|
|
175
|
+
const tpl = getTemplateById(tplId);
|
|
176
|
+
if (!tpl) {
|
|
177
|
+
console.error(`${fmt("31", "Error:")} Unknown template "${tplId}". Run \`wirepulse templates\`.`);
|
|
178
|
+
process.exit(1);
|
|
179
|
+
}
|
|
180
|
+
if (fs.existsSync(target)) {
|
|
181
|
+
console.error(`${fmt("31", "Error:")} File already exists: ${target}`);
|
|
182
|
+
process.exit(1);
|
|
183
|
+
}
|
|
184
|
+
fs.writeFileSync(target, tpl.source, "utf8");
|
|
185
|
+
console.log(`${fmt("32", "✔")} Created ${fmt("36", target)} using template "${tpl.name}".`);
|
|
186
|
+
console.log(` Next: ${fmt("36", `wirepulse build ${path.basename(target)}`)} or ${fmt("36", `wirepulse studio --file ${path.basename(target)}`)}`);
|
|
187
|
+
return;
|
|
188
|
+
}
|
|
189
|
+
if (cmd === "validate") {
|
|
190
|
+
const target = positionals[1];
|
|
191
|
+
if (!target || !fs.existsSync(target)) {
|
|
192
|
+
console.error(`${fmt("31", "Error:")} Please provide an existing SVG file path.`);
|
|
193
|
+
process.exit(1);
|
|
194
|
+
}
|
|
195
|
+
const content = fs.readFileSync(target, "utf8");
|
|
196
|
+
const res = validateSvg(content);
|
|
197
|
+
console.log(`${res.githubSafe ? fmt("32", "✔ PASS") : fmt("31", "✖ FAIL")} ${target} (${(res.bytes / 1024).toFixed(1)} KB)`);
|
|
198
|
+
for (const issue of res.issues) {
|
|
199
|
+
const color = issue.severity === "error" ? "31" : "33";
|
|
200
|
+
console.log(` ${fmt(color, issue.severity.toUpperCase())} [${issue.code}] ${issue.message}`);
|
|
201
|
+
}
|
|
202
|
+
if (!res.githubSafe)
|
|
203
|
+
process.exit(1);
|
|
204
|
+
return;
|
|
205
|
+
}
|
|
206
|
+
if (cmd === "build") {
|
|
207
|
+
const input = positionals[1];
|
|
208
|
+
if (!input) {
|
|
209
|
+
console.error(`${fmt("31", "Error:")} Missing input file. Usage: wirepulse build <file.wp>`);
|
|
210
|
+
process.exit(2);
|
|
211
|
+
}
|
|
212
|
+
const outPath = path.resolve(values.out || defaultOutPath(input));
|
|
213
|
+
const ok = buildOnce(path.resolve(input), outPath, themeOverride, speedMul, showGrid, includeWatermark, Boolean(values["light-dark"]));
|
|
214
|
+
if (!ok)
|
|
215
|
+
process.exit(1);
|
|
216
|
+
return;
|
|
217
|
+
}
|
|
218
|
+
if (cmd === "watch") {
|
|
219
|
+
const input = positionals[1];
|
|
220
|
+
if (!input) {
|
|
221
|
+
console.error(`${fmt("31", "Error:")} Missing input file. Usage: wirepulse watch <file.wp>`);
|
|
222
|
+
process.exit(2);
|
|
223
|
+
}
|
|
224
|
+
const resolvedInput = path.resolve(input);
|
|
225
|
+
const outPath = path.resolve(values.out || defaultOutPath(input));
|
|
226
|
+
buildOnce(resolvedInput, outPath, themeOverride, speedMul, showGrid, includeWatermark, Boolean(values["light-dark"]));
|
|
227
|
+
console.log(`${fmt("36", "Watching")} ${resolvedInput} for changes… (Ctrl+C to stop)`);
|
|
228
|
+
let debounce;
|
|
229
|
+
fs.watch(resolvedInput, () => {
|
|
230
|
+
clearTimeout(debounce);
|
|
231
|
+
debounce = setTimeout(() => {
|
|
232
|
+
buildOnce(resolvedInput, outPath, themeOverride, speedMul, showGrid, includeWatermark, Boolean(values["light-dark"]));
|
|
233
|
+
}, 100);
|
|
234
|
+
});
|
|
235
|
+
return;
|
|
236
|
+
}
|
|
237
|
+
if (cmd === "studio") {
|
|
238
|
+
const port = values.port ? Number.parseInt(values.port, 10) : 4173;
|
|
239
|
+
const filePath = values.file || positionals[1];
|
|
240
|
+
const running = await startStudioServer({
|
|
241
|
+
port: Number.isNaN(port) ? 4173 : port,
|
|
242
|
+
filePath,
|
|
243
|
+
outSvgPath: values.out,
|
|
244
|
+
version: VERSION,
|
|
245
|
+
});
|
|
246
|
+
console.log(`\n ${fmt("1;36", "wirepulse studio")} ${fmt("2", `v${VERSION}`)} running at ${fmt("1;32", running.url)}`);
|
|
247
|
+
if (filePath) {
|
|
248
|
+
console.log(` Attached file: ${fmt("36", path.resolve(filePath))} (Ctrl+S saves to disk)`);
|
|
249
|
+
}
|
|
250
|
+
console.log(` Press Ctrl+C to stop.\n`);
|
|
251
|
+
if (!values["no-open"]) {
|
|
252
|
+
openBrowser(running.url);
|
|
253
|
+
}
|
|
254
|
+
return;
|
|
255
|
+
}
|
|
256
|
+
console.error(`${fmt("31", "Unknown command:")} ${cmd}`);
|
|
257
|
+
console.log(HELP);
|
|
258
|
+
process.exit(2);
|
|
259
|
+
}
|
|
260
|
+
main().catch((err) => {
|
|
261
|
+
console.error(`${fmt("31", "Fatal:")} ${err instanceof Error ? err.message : String(err)}`);
|
|
262
|
+
process.exit(1);
|
|
263
|
+
});
|
package/dist/icons.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 28 crisp 24x24 inline vector icons (stroke-based, zero external CDN links)
|
|
3
|
+
* so every generated SVG works 100% offline and passes GitHub Camo proxy cleanly.
|
|
4
|
+
*/
|
|
5
|
+
export declare const ICONS: Record<string, string>;
|
|
6
|
+
export declare const ICON_NAMES: string[];
|
|
7
|
+
export declare function getIconMarkup(name: string): string;
|
package/dist/icons.js
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 28 crisp 24x24 inline vector icons (stroke-based, zero external CDN links)
|
|
3
|
+
* so every generated SVG works 100% offline and passes GitHub Camo proxy cleanly.
|
|
4
|
+
*/
|
|
5
|
+
export const ICONS = {
|
|
6
|
+
browser: '<rect x="3" y="4" width="18" height="16" rx="2"/><line x1="3" y1="9" x2="21" y2="9"/><circle cx="7" cy="6.5" r="0.8" fill="currentColor"/><circle cx="10" cy="6.5" r="0.8" fill="currentColor"/>',
|
|
7
|
+
terminal: '<rect x="3" y="4" width="18" height="16" rx="2"/><polyline points="7 10 10 13 7 16"/><line x1="12" y1="16" x2="17" y2="16"/>',
|
|
8
|
+
server: '<rect x="3" y="4" width="18" height="6" rx="1.5"/><rect x="3" y="14" width="18" height="6" rx="1.5"/><circle cx="7" cy="7" r="0.8" fill="currentColor"/><circle cx="7" cy="17" r="0.8" fill="currentColor"/><line x1="12" y1="7" x2="17" y2="7"/><line x1="12" y1="17" x2="17" y2="17"/>',
|
|
9
|
+
database: '<ellipse cx="12" cy="6" rx="8" ry="3"/><path d="M4 6v6c0 1.66 3.58 3 8 3s8-1.34 8-3V6"/><path d="M4 12v6c0 1.66 3.58 3 8 3s8-1.34 8-3v-6"/>',
|
|
10
|
+
bolt: '<polygon points="13 2 4 14 12 14 11 22 20 10 12 10 13 2"/>',
|
|
11
|
+
cache: '<polygon points="13 2 4 14 12 14 11 22 20 10 12 10 13 2"/>',
|
|
12
|
+
queue: '<rect x="3" y="5" width="4" height="14" rx="1"/><rect x="10" y="5" width="4" height="14" rx="1"/><rect x="17" y="5" width="4" height="14" rx="1"/>',
|
|
13
|
+
shield: '<path d="M12 3l7 3v5c0 4.5-3 8.5-7 10-4-1.5-7-5.5-7-10V6l7-3z"/><polyline points="9 12 11 14 15 10"/>',
|
|
14
|
+
sparkles: '<path d="M12 3l1.8 4.8L18.5 9.5l-4.7 1.7L12 16l-1.8-4.8L5.5 9.5l4.7-1.7L12 3z"/><path d="M18.5 15.5l.8 2.2 2.2.8-2.2.8-.8 2.2-.8-2.2-2.2-.8 2.2-.8.8-2.2z"/>',
|
|
15
|
+
ai: '<path d="M12 3l1.8 4.8L18.5 9.5l-4.7 1.7L12 16l-1.8-4.8L5.5 9.5l4.7-1.7L12 3z"/><path d="M18.5 15.5l.8 2.2 2.2.8-2.2.8-.8 2.2-.8-2.2-2.2-.8 2.2-.8.8-2.2z"/>',
|
|
16
|
+
cpu: '<rect x="6" y="6" width="12" height="12" rx="2"/><rect x="9" y="9" width="6" height="6"/><line x1="9" y1="2" x2="9" y2="6"/><line x1="15" y1="2" x2="15" y2="6"/><line x1="9" y1="18" x2="9" y2="22"/><line x1="15" y1="18" x2="15" y2="22"/><line x1="2" y1="9" x2="6" y2="9"/><line x1="2" y1="15" x2="6" y2="15"/><line x1="18" y1="9" x2="22" y2="9"/><line x1="18" y1="15" x2="22" y2="15"/>',
|
|
17
|
+
git: '<circle cx="6" cy="6" r="2.5"/><circle cx="18" cy="6" r="2.5"/><circle cx="6" cy="18" r="2.5"/><line x1="6" y1="8.5" x2="6" y2="15.5"/><path d="M18 8.5c0 4-3 5.5-12 5.5"/>',
|
|
18
|
+
globe: '<circle cx="12" cy="12" r="9"/><line x1="3" y1="12" x2="21" y2="12"/><path d="M12 3a14 14 0 0 1 0 18 14 14 0 0 1 0-18z"/>',
|
|
19
|
+
cloud: '<path d="M17.5 19H7a4.5 4.5 0 0 1-.5-8.97A6 6 0 0 1 18 9a4 4 0 0 1-.5 10z"/>',
|
|
20
|
+
box: '<path d="M21 8l-9-5-9 5v8l9 5 9-5V8z"/><polyline points="3.3 8 12 13 20.7 8"/><line x1="12" y1="13" x2="12" y2="21"/>',
|
|
21
|
+
user: '<circle cx="12" cy="8" r="4"/><path d="M4 20c0-4 3.6-6 8-6s8 2 8 6"/>',
|
|
22
|
+
mobile: '<rect x="6" y="2" width="12" height="20" rx="2"/><line x1="11" y1="18" x2="13" y2="18"/>',
|
|
23
|
+
code: '<polyline points="8 7 3 12 8 17"/><polyline points="16 7 21 12 16 17"/><line x1="14" y1="5" x2="10" y2="19"/>',
|
|
24
|
+
lock: '<rect x="5" y="11" width="14" height="10" rx="2"/><path d="M8 11V7a4 4 0 0 1 8 0v4"/>',
|
|
25
|
+
plug: '<path d="M12 22v-5"/><path d="M9 8V3"/><path d="M15 8V3"/><path d="M6 8h12v4a6 6 0 0 1-12 0V8z"/>',
|
|
26
|
+
layers: '<polygon points="12 3 2 8 12 13 22 8 12 3"/><polyline points="2 13 12 18 22 13"/><polyline points="2 17 12 22 22 17"/>',
|
|
27
|
+
storage: '<path d="M4 7h16v11a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2V7z"/><path d="M4 7l2-3h12l2 3"/><line x1="9" y1="12" x2="15" y2="12"/>',
|
|
28
|
+
chart: '<line x1="4" y1="20" x2="20" y2="20"/><rect x="6" y="12" width="3" height="8" rx="0.5"/><rect x="11" y="7" width="3" height="13" rx="0.5"/><rect x="16" y="4" width="3" height="16" rx="0.5"/>',
|
|
29
|
+
mail: '<rect x="3" y="5" width="18" height="14" rx="2"/><polyline points="3 7 12 13 21 7"/>',
|
|
30
|
+
clock: '<circle cx="12" cy="12" r="9"/><polyline points="12 7 12 12 15.5 14"/>',
|
|
31
|
+
key: '<circle cx="8" cy="12" r="4"/><line x1="12" y1="12" x2="21" y2="12"/><line x1="18" y1="12" x2="18" y2="15"/><line x1="15" y1="12" x2="15" y2="14"/>',
|
|
32
|
+
search: '<circle cx="10.5" cy="10.5" r="6.5"/><line x1="15.5" y1="15.5" x2="21" y2="21"/>',
|
|
33
|
+
check: '<circle cx="12" cy="12" r="9"/><polyline points="8.5 12.5 11 15 16 9.5"/>',
|
|
34
|
+
api: '<circle cx="6" cy="12" r="2.5"/><circle cx="18" cy="7" r="2.5"/><circle cx="18" cy="17" r="2.5"/><line x1="8.3" y1="11" x2="15.7" y2="8"/><line x1="8.3" y1="13" x2="15.7" y2="16"/>',
|
|
35
|
+
lambda: '<path d="M5 19l6-14h2l6 14"/><path d="M11 11l-4 8"/>',
|
|
36
|
+
};
|
|
37
|
+
export const ICON_NAMES = Object.keys(ICONS);
|
|
38
|
+
export function getIconMarkup(name) {
|
|
39
|
+
const key = (name || "box").toLowerCase().trim();
|
|
40
|
+
return ICONS[key] ?? ICONS.box;
|
|
41
|
+
}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { ParseError, RenderOptions, ValidationResult } from "./types.js";
|
|
2
|
+
export declare const VERSION = "0.1.0";
|
|
3
|
+
export interface CompileResult {
|
|
4
|
+
svg: string;
|
|
5
|
+
errors: ParseError[];
|
|
6
|
+
validation: ValidationResult;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Convenience one-shot helper: parse `.wp` DSL (or JSON), render a pure zero-JS
|
|
10
|
+
* animated SVG, and validate GitHub README CSP compliance.
|
|
11
|
+
*/
|
|
12
|
+
export declare function compileDiagram(source: string, options?: RenderOptions): CompileResult;
|
|
13
|
+
export * from "./types.js";
|
|
14
|
+
export { ICONS, ICON_NAMES, getIconMarkup } from "./icons.js";
|
|
15
|
+
export { THEMES, THEME_NAMES, ACCENTS, ACCENT_NAMES, buildThemeCss } from "./themes.js";
|
|
16
|
+
export { parseDiagram, updateNodeGridInSource } from "./parser.js";
|
|
17
|
+
export { layoutDiagram } from "./layout.js";
|
|
18
|
+
export { renderSvg } from "./renderer.js";
|
|
19
|
+
export { validateSvg } from "./validator.js";
|
|
20
|
+
export { TEMPLATES, getTemplateById } from "./templates.js";
|
|
21
|
+
export { startStudioServer } from "./studio.js";
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { parseDiagram } from "./parser.js";
|
|
2
|
+
import { renderSvg } from "./renderer.js";
|
|
3
|
+
import { validateSvg } from "./validator.js";
|
|
4
|
+
export const VERSION = "0.1.0";
|
|
5
|
+
/**
|
|
6
|
+
* Convenience one-shot helper: parse `.wp` DSL (or JSON), render a pure zero-JS
|
|
7
|
+
* animated SVG, and validate GitHub README CSP compliance.
|
|
8
|
+
*/
|
|
9
|
+
export function compileDiagram(source, options = {}) {
|
|
10
|
+
const { spec, errors } = parseDiagram(source);
|
|
11
|
+
const svg = renderSvg(spec, options);
|
|
12
|
+
const validation = validateSvg(svg);
|
|
13
|
+
return { svg, errors, validation };
|
|
14
|
+
}
|
|
15
|
+
export * from "./types.js";
|
|
16
|
+
export { ICONS, ICON_NAMES, getIconMarkup } from "./icons.js";
|
|
17
|
+
export { THEMES, THEME_NAMES, ACCENTS, ACCENT_NAMES, buildThemeCss } from "./themes.js";
|
|
18
|
+
export { parseDiagram, updateNodeGridInSource } from "./parser.js";
|
|
19
|
+
export { layoutDiagram } from "./layout.js";
|
|
20
|
+
export { renderSvg } from "./renderer.js";
|
|
21
|
+
export { validateSvg } from "./validator.js";
|
|
22
|
+
export { TEMPLATES, getTemplateById } from "./templates.js";
|
|
23
|
+
export { startStudioServer } from "./studio.js";
|
package/dist/layout.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { DiagramSpec, LayoutResult } from "./types.js";
|
|
2
|
+
/**
|
|
3
|
+
* Compute automatic topological columns (layers) and balanced rows
|
|
4
|
+
* while respecting any explicit `col`/`row` or `x`/`y` coordinates on nodes.
|
|
5
|
+
*/
|
|
6
|
+
export declare function layoutDiagram(spec: DiagramSpec): LayoutResult;
|