wirepulse 0.0.0-stage → 0.2.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 ADDED
@@ -0,0 +1,20 @@
1
+ # Changelog
2
+
3
+ All notable changes to `wirepulse` will be documented in this file.
4
+
5
+ ## [0.2.0] - 2026-12-04
6
+
7
+ ### Added
8
+ - **Mermaid Flowchart Importer:** Convert existing Mermaid `flowchart`/`graph` diagrams into animated `wirepulse` `.wp` DSL or directly into animated SVGs (`wirepulse import <file.mmd>`, `wirepulse build <file.mmd>`, plus **"✨ Import Mermaid"** modal in Visual Studio) with automatic semantic icon and accent color inference.
9
+ - **Standalone Zero-Backend Web Studio for GitHub Pages (`docs/index.html`):** Full client-side studio compiled to native ES modules (`npm run build:pages`) with automated GitHub Pages deployment workflow (`.github/workflows/pages.yml`).
10
+ - Browser-compatible `TextEncoder` byte sizing in `validateSvg` so the entire core compiler runs identically in browsers and Node.js.
11
+
12
+ ## [0.1.0] - 2026-12-04
13
+
14
+ ### Added
15
+ - Human-friendly `.wp` Diagram-as-Code DSL parser and JSON spec parser with line-numbered diagnostics.
16
+ - Hybrid automatic topological layered layout engine (cycle-safe, barycenter crossing reduction) with explicit `col`/`row` overrides and group/cluster bounding boxes.
17
+ - 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.
18
+ - 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.
19
+ - GitHub README / Camo CSP validator (`wirepulse validate`) and CLI workflow (`init`, `build`, `build --light-dark`, `watch`, `studio`, `templates`).
20
+ - 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,184 @@
1
- # Temporary Holding Version
1
+ # wirepulse
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ > **Pure zero-JS animated architecture SVGs from a human-friendly DSL or local Visual Studio — built natively for GitHub `README.md`.**
4
+
5
+ [![Live Studio](https://img.shields.io/badge/▶%20Try%20Live%20Studio-rynia.github.io%2Fwirepulse-22d3ee?style=for-the-badge)](https://rynia.github.io/wirepulse/)
6
+
7
+ [![npm version](https://img.shields.io/npm/v/wirepulse.svg)](https://www.npmjs.com/package/wirepulse)
8
+ [![CI](https://github.com/Rynia/wirepulse/actions/workflows/ci.yml/badge.svg)](https://github.com/Rynia/wirepulse/actions/workflows/ci.yml)
9
+ [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](LICENSE)
10
+ [![Node.js >= 20](https://img.shields.io/badge/node-%3E%3D20-brightgreen.svg)](https://nodejs.org)
11
+ [![Zero Dependencies](https://img.shields.io/badge/dependencies-0-success.svg)](#why-wirepulse)
12
+ [![GitHub CSP Safe](https://img.shields.io/badge/GitHub%20CSP-Safe%20(0%20scripts)-22d3ee.svg)](#github-readme-csp-safety)
13
+
14
+ ![AI Coding Agent & MCP Runtime — generated with wirepulse](./examples/ai-agent-mcp.svg)
15
+
16
+ *(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`.)*
17
+
18
+ ---
19
+
20
+ ## Why `wirepulse`?
21
+
22
+ 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.
23
+
24
+ Existing animated diagram tools rely on **JavaScript (GSAP / React)** — which GitHub's Camo proxy strips and blocks inside `README.md`.
25
+
26
+ **`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**:
27
+
28
+ | Feature | `wirepulse` | Mermaid / D2 | GSAP / HTML Diagram Tools |
29
+ | --- | :---: | :---: | :---: |
30
+ | **Live Animated Data Packets & Flows** | ✅ | ❌ | ✅ |
31
+ | **Works Natively Inside GitHub `README.md` (Zero JS)** | ✅ | ✅ | ❌ *(blocked by CSP)* |
32
+ | **Auto GitHub Light & Dark Mode (`prefers-color-scheme`)** | ✅ | ⚠️ | ❌ |
33
+ | **1-Click Mermaid Flowchart Import & Auto-Icons** | ✅ | — | ❌ |
34
+ | **Built-In Drag-and-Drop Visual Studio (Web + Local)** | ✅ | ❌ | ⚠️ |
35
+ | **1-Click Export to SVG, 2x PNG & Animated WebM** | ✅ | ❌ | ❌ |
36
+ | **Zero Runtime Dependencies (`npx` Cold Start < 1s)** | ✅ | ❌ | ❌ |
37
+
38
+ ---
39
+
40
+ ## ✨ Already Have a Mermaid Diagram? Upgrade It in 1 Command
41
+
42
+ Paste any existing Mermaid `flowchart` into the [**Live Web Studio**](https://rynia.github.io/wirepulse/) (`✨ Import Mermaid`) — or convert it right from your terminal:
43
+
44
+ ```bash
45
+ # Convert Mermaid (.mmd) → editable .wp with auto-inferred icons & colors
46
+ npx wirepulse import architecture.mmd -o architecture.wp
47
+
48
+ # Or compile a Mermaid file straight into an animated zero-JS SVG!
49
+ npx wirepulse build architecture.mmd -o docs/architecture.svg
50
+ ```
51
+
52
+ `wirepulse` automatically recognizes databases, caches, queues, API gateways, AI agents, browsers, and clusters — assigning crisp inline vector icons, semantic colors, and animated packet flows out of the box.
53
+
54
+ ---
55
+
56
+ ## Visual Studio ([Try Online](https://rynia.github.io/wirepulse/) or `npx wirepulse studio`)
57
+
58
+ Try it immediately in your browser at **[rynia.github.io/wirepulse](https://rynia.github.io/wirepulse/)** — or launch it locally with live disk saving (`Ctrl+S`):
59
+
60
+ ```bash
61
+ npx wirepulse studio
62
+ ```
63
+
64
+ ![wirepulse Visual Studio](./docs/studio-preview.png)
65
+
66
+ - **Live Split-Pane Editor** with real-time syntax diagnostics and **6 built-in architecture templates**
67
+ - **Drag-and-Drop Node Repositioning** right on the SVG canvas (snaps cleanly to grid and updates your `.wp` code!)
68
+ - **GitHub Light / Dark Mode Live Preview** to inspect `theme: auto` before committing
69
+ - **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**
70
+ - **Live Disk Sync:** Pass `--file architecture.wp` and hit `Ctrl+S` to save directly back to your repository!
71
+
72
+ ---
73
+
74
+ ## Quick Start (CLI)
75
+
76
+ ### 1. Scaffold a Starter Diagram
77
+ ```bash
78
+ npx wirepulse init architecture.wp --template microservices-kafka
79
+ ```
80
+
81
+ ### 2. Compile to a GitHub-Safe Animated SVG
82
+ ```bash
83
+ npx wirepulse build architecture.wp -o docs/architecture.svg
84
+ ```
85
+
86
+ ### 3. Or Emit Explicit Light + Dark SVGs with `<picture>` Snippet
87
+ ```bash
88
+ npx wirepulse build architecture.wp -o docs/architecture.svg --light-dark
89
+ ```
90
+
91
+ ### 4. Validate Any SVG for GitHub README / Camo Safety
92
+ ```bash
93
+ npx wirepulse validate docs/architecture.svg
94
+ ```
95
+
96
+ ### 5. Watch Mode (Rebuild on Every Save)
97
+ ```bash
98
+ npx wirepulse watch architecture.wp -o docs/architecture.svg
99
+ ```
100
+
101
+ ---
102
+
103
+ ## Showcase (All Generated by `wirepulse`)
104
+
105
+ ### Microservices + Kafka (`theme: midnight`)
106
+ ![Microservices + Kafka](./examples/microservices-kafka.svg)
107
+
108
+ ### Hybrid RAG & Vector Search (`theme: blueprint`)
109
+ ![Hybrid RAG Retrieval Engine](./examples/rag-pipeline.svg)
110
+
111
+ ---
112
+
113
+ ## DSL Syntax (`.wp`)
114
+
115
+ ```yaml
116
+ title: AI Coding Agent & MCP Runtime
117
+ subtitle: Pure zero-JS animated SVG — auto-adapts to GitHub Light & Dark mode
118
+ theme: auto # auto | midnight | linear | blueprint | terminal | paper
119
+ direction: LR # LR | TB
120
+ speed: normal # slow | normal | fast
121
+
122
+ group client "Developer" color=cyan
123
+ group runtime "Agent Harness" color=violet
124
+ group tools "MCP Servers" color=emerald
125
+
126
+ node ide "IDE / Terminal" sub="Claude Code · Cursor" icon=terminal color=cyan group=client pulse=true
127
+ node agent "Agent Loop" sub="200k Context" icon=sparkles color=violet badge="LLM" group=runtime pulse=true
128
+ node router "MCP Router" sub="JSON-RPC 2.0" icon=cpu color=blue group=runtime
129
+ node repo "Codebase" sub="AST + Git Diffs" icon=git color=emerald group=tools
130
+ node vec "Vector Index" sub="pgvector" icon=database color=amber group=tools
131
+ node web "Web Grounding" sub="Live Docs" icon=globe color=rose group=tools
132
+
133
+ ide -> agent "prompt" flow=packet color=cyan speed=fast
134
+ agent <-> router "tools/call" flow=packet color=violet packets=2
135
+ router <-> repo "read / edit" flow=dash color=emerald
136
+ router -> vec "semantic search" flow=packet color=amber
137
+ router -> web "fetch url" flow=pulse color=rose
138
+ ```
139
+
140
+ ### Layout, Styling & Animation Reference
141
+
142
+ - **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!).
143
+ - **Flow Types:** `flow=packet` (glowing moving data packets), `flow=dash` (flowing dashed wire), `flow=pulse` (traveling light wave), `flow=solid` (clean static wire).
144
+ - **Bidirectional Wires:** Use `<->` (or `bidir=true`) for two-way arrowheads and reverse-direction return packets.
145
+ - **Themes:** `auto` (adapts seamlessly to GitHub Light & Dark via `@media (prefers-color-scheme: dark)`), `midnight`, `linear`, `blueprint`, `terminal`, `paper`.
146
+ - **Accents:** `cyan`, `violet`, `emerald`, `amber`, `rose`, `blue`, `orange`, `slate`.
147
+ - **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`.
148
+
149
+ ---
150
+
151
+ ## Programmatic TypeScript / Node.js API
152
+
153
+ ```ts
154
+ import { compileDiagram } from "wirepulse";
155
+
156
+ const { svg, errors, validation } = compileDiagram(`
157
+ title: Payment Flow
158
+ theme: auto
159
+ node web "Checkout" icon=browser color=cyan pulse=true
160
+ node api "Stripe API" icon=shield color=violet badge="TLS 1.3"
161
+ web -> api "charge" flow=packet color=cyan packets=2
162
+ `);
163
+
164
+ console.log(validation.githubSafe); // true
165
+ ```
166
+
167
+ ---
168
+
169
+ ## GitHub README CSP Safety
170
+
171
+ Every SVG compiled by `wirepulse` is verified against strict rules:
172
+ - **Zero `<script>` tags** and **zero `on*=` event handlers**
173
+ - **Zero external URLs** (all 30 icons and CSS styles are strictly inline)
174
+ - **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)
175
+
176
+ ---
177
+
178
+ ## Contributing
179
+
180
+ Contributions are warmly welcomed! See [CONTRIBUTING.md](CONTRIBUTING.md) for ideas like new icons, theme presets, sequence diagram layouts, and Mermaid importers.
181
+
182
+ ## License
183
+
184
+ [MIT](LICENSE)
@@ -0,0 +1,8 @@
1
+ export { ICON_NAMES } from "./icons.js";
2
+ export { layoutDiagram } from "./layout.js";
3
+ export { convertMermaidToWirepulse, isMermaidSource } from "./mermaid.js";
4
+ export { parseDiagram, updateNodeGridInSource } from "./parser.js";
5
+ export { renderSvg } from "./renderer.js";
6
+ export { TEMPLATES } from "./templates.js";
7
+ export { THEME_NAMES } from "./themes.js";
8
+ export { validateSvg } from "./validator.js";
@@ -0,0 +1,8 @@
1
+ export { ICON_NAMES } from "./icons.js";
2
+ export { layoutDiagram } from "./layout.js";
3
+ export { convertMermaidToWirepulse, isMermaidSource } from "./mermaid.js";
4
+ export { parseDiagram, updateNodeGridInSource } from "./parser.js";
5
+ export { renderSvg } from "./renderer.js";
6
+ export { TEMPLATES } from "./templates.js";
7
+ export { THEME_NAMES } from "./themes.js";
8
+ export { validateSvg } from "./validator.js";
package/dist/cli.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ export {};
package/dist/cli.js ADDED
@@ -0,0 +1,285 @@
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, convertMermaidToWirepulse, 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, .mmd (Mermaid), or .json diagram into an animated .svg
22
+ import <mmd> Convert a Mermaid flowchart (.mmd) into an animated .wp diagram
23
+ watch <file> Watch a diagram file and rebuild automatically on save
24
+ studio Launch the local interactive Visual Studio in your browser
25
+ validate <svg> Verify GitHub README / Camo CSP safety of an SVG file
26
+ init [file] Scaffold a starter architecture.wp diagram
27
+ templates List all built-in architecture templates
28
+
29
+ ${fmt("1", "OPTIONS")}
30
+ -o, --out <path> Output SVG path (default: <input>.svg)
31
+ -t, --theme <name> Override theme (${THEME_NAMES.join(", ")})
32
+ --light-dark Emit both -light.svg and -dark.svg + print <picture> Markdown
33
+ --speed <num> Animation speed multiplier (e.g. 0.5, 1, 1.5, 2)
34
+ --no-grid Hide background dot grid
35
+ --no-watermark Hide subtle corner watermark
36
+ -p, --port <num> Studio HTTP port (default: 4173)
37
+ -f, --file <path> Attach a .wp file to Studio for live Ctrl+S saving
38
+ --no-open Do not auto-open browser when starting Studio
39
+ --template <id> Template id for \`init\` (default: ai-agent-mcp)
40
+ -v, --version Show version
41
+ -h, --help Show this help
42
+
43
+ ${fmt("1", "EXAMPLES")}
44
+ npx wirepulse studio
45
+ npx wirepulse init architecture.wp --template microservices-kafka
46
+ npx wirepulse build architecture.wp -o docs/architecture.svg
47
+ npx wirepulse build architecture.wp --light-dark
48
+ npx wirepulse validate docs/architecture.svg
49
+ `;
50
+ function openBrowser(url) {
51
+ const cmd = process.platform === "win32"
52
+ ? "cmd"
53
+ : process.platform === "darwin"
54
+ ? "open"
55
+ : "xdg-open";
56
+ const args = process.platform === "win32" ? ["/c", "start", "", url] : [url];
57
+ try {
58
+ const child = spawn(cmd, args, { detached: true, stdio: "ignore" });
59
+ child.unref();
60
+ }
61
+ catch {
62
+ // non-fatal if headless
63
+ }
64
+ }
65
+ function defaultOutPath(inputPath) {
66
+ const parsed = path.parse(inputPath);
67
+ return path.join(parsed.dir, `${parsed.name}.svg`);
68
+ }
69
+ function buildOnce(inputPath, outPath, themeOverride, speedMul, showGrid, includeWatermark, lightDark) {
70
+ if (!fs.existsSync(inputPath)) {
71
+ console.error(`${fmt("31", "Error:")} Input file not found: ${inputPath}`);
72
+ return false;
73
+ }
74
+ const source = fs.readFileSync(inputPath, "utf8");
75
+ const outDir = path.dirname(outPath);
76
+ if (outDir && !fs.existsSync(outDir)) {
77
+ fs.mkdirSync(outDir, { recursive: true });
78
+ }
79
+ if (lightDark) {
80
+ const parsed = path.parse(outPath);
81
+ const lightPath = path.join(parsed.dir, `${parsed.name}-light.svg`);
82
+ const darkPath = path.join(parsed.dir, `${parsed.name}-dark.svg`);
83
+ const lightRes = compileDiagram(source, {
84
+ theme: "paper",
85
+ speedMultiplier: speedMul,
86
+ showGrid,
87
+ includeWatermark,
88
+ });
89
+ const darkRes = compileDiagram(source, {
90
+ theme: "midnight",
91
+ speedMultiplier: speedMul,
92
+ showGrid,
93
+ includeWatermark,
94
+ });
95
+ for (const err of lightRes.errors) {
96
+ console.error(`${fmt("33", `Warn (line ${err.line}):`)} ${err.message}`);
97
+ }
98
+ fs.writeFileSync(lightPath, lightRes.svg, "utf8");
99
+ fs.writeFileSync(darkPath, darkRes.svg, "utf8");
100
+ console.log(`${fmt("32", "✔")} Built light (${(lightRes.validation.bytes / 1024).toFixed(1)} KB) → ${fmt("36", lightPath)}`);
101
+ console.log(`${fmt("32", "✔")} Built dark (${(darkRes.validation.bytes / 1024).toFixed(1)} KB) → ${fmt("36", darkPath)}`);
102
+ console.log(`\n${fmt("1", "GitHub README.md snippet:")}`);
103
+ console.log(`<picture>`);
104
+ console.log(` <source media="(prefers-color-scheme: dark)" srcset="${path.basename(darkPath)}" />`);
105
+ console.log(` <source media="(prefers-color-scheme: light)" srcset="${path.basename(lightPath)}" />`);
106
+ console.log(` <img alt="Architecture Diagram" src="${path.basename(darkPath)}" />`);
107
+ console.log(`</picture>`);
108
+ return lightRes.validation.githubSafe && darkRes.validation.githubSafe;
109
+ }
110
+ const res = compileDiagram(source, {
111
+ theme: themeOverride,
112
+ speedMultiplier: speedMul,
113
+ showGrid,
114
+ includeWatermark,
115
+ });
116
+ for (const err of res.errors) {
117
+ console.error(`${fmt("33", `Warn (line ${err.line}):`)} ${err.message}`);
118
+ }
119
+ fs.writeFileSync(outPath, res.svg, "utf8");
120
+ const statusTag = res.validation.githubSafe
121
+ ? fmt("32", "GitHub CSP Safe")
122
+ : fmt("31", "CSP Issues");
123
+ console.log(`${fmt("32", "✔")} Built ${fmt("36", outPath)} (${(res.validation.bytes / 1024).toFixed(1)} KB · ${statusTag})`);
124
+ return res.validation.githubSafe;
125
+ }
126
+ async function main() {
127
+ let parsed;
128
+ try {
129
+ parsed = parseArgs({
130
+ allowPositionals: true,
131
+ options: {
132
+ out: { type: "string", short: "o" },
133
+ theme: { type: "string", short: "t" },
134
+ "light-dark": { type: "boolean", default: false },
135
+ speed: { type: "string" },
136
+ "no-grid": { type: "boolean", default: false },
137
+ "no-watermark": { type: "boolean", default: false },
138
+ port: { type: "string", short: "p" },
139
+ file: { type: "string", short: "f" },
140
+ "no-open": { type: "boolean", default: false },
141
+ template: { type: "string" },
142
+ version: { type: "boolean", short: "v", default: false },
143
+ help: { type: "boolean", short: "h", default: false },
144
+ },
145
+ });
146
+ }
147
+ catch (err) {
148
+ console.error(`${fmt("31", "Error:")} ${err instanceof Error ? err.message : String(err)}`);
149
+ process.exit(2);
150
+ }
151
+ const { values, positionals } = parsed;
152
+ if (values.help || positionals.length === 0) {
153
+ console.log(HELP);
154
+ return;
155
+ }
156
+ if (values.version) {
157
+ console.log(VERSION);
158
+ return;
159
+ }
160
+ const cmd = positionals[0].toLowerCase();
161
+ const themeOverride = values.theme ? values.theme.toLowerCase() : undefined;
162
+ const speedMul = values.speed ? Number(values.speed) : 1;
163
+ const showGrid = !values["no-grid"];
164
+ const includeWatermark = !values["no-watermark"];
165
+ if (cmd === "templates") {
166
+ console.log(`\n${fmt("1;36", "Built-in wirepulse templates:")}\n`);
167
+ for (const t of TEMPLATES) {
168
+ console.log(` ${fmt("1", t.id.padEnd(22))} ${t.description}`);
169
+ }
170
+ console.log(`\nRun ${fmt("36", "wirepulse init architecture.wp --template <id>")} to scaffold one.\n`);
171
+ return;
172
+ }
173
+ if (cmd === "init") {
174
+ const target = path.resolve(positionals[1] || "architecture.wp");
175
+ const tplId = values.template || "ai-agent-mcp";
176
+ const tpl = getTemplateById(tplId);
177
+ if (!tpl) {
178
+ console.error(`${fmt("31", "Error:")} Unknown template "${tplId}". Run \`wirepulse templates\`.`);
179
+ process.exit(1);
180
+ }
181
+ if (fs.existsSync(target)) {
182
+ console.error(`${fmt("31", "Error:")} File already exists: ${target}`);
183
+ process.exit(1);
184
+ }
185
+ fs.writeFileSync(target, tpl.source, "utf8");
186
+ console.log(`${fmt("32", "✔")} Created ${fmt("36", target)} using template "${tpl.name}".`);
187
+ console.log(` Next: ${fmt("36", `wirepulse build ${path.basename(target)}`)} or ${fmt("36", `wirepulse studio --file ${path.basename(target)}`)}`);
188
+ return;
189
+ }
190
+ if (cmd === "validate") {
191
+ const target = positionals[1];
192
+ if (!target || !fs.existsSync(target)) {
193
+ console.error(`${fmt("31", "Error:")} Please provide an existing SVG file path.`);
194
+ process.exit(1);
195
+ }
196
+ const content = fs.readFileSync(target, "utf8");
197
+ const res = validateSvg(content);
198
+ console.log(`${res.githubSafe ? fmt("32", "✔ PASS") : fmt("31", "✖ FAIL")} ${target} (${(res.bytes / 1024).toFixed(1)} KB)`);
199
+ for (const issue of res.issues) {
200
+ const color = issue.severity === "error" ? "31" : "33";
201
+ console.log(` ${fmt(color, issue.severity.toUpperCase())} [${issue.code}] ${issue.message}`);
202
+ }
203
+ if (!res.githubSafe)
204
+ process.exit(1);
205
+ return;
206
+ }
207
+ if (cmd === "import") {
208
+ const input = positionals[1];
209
+ if (!input || !fs.existsSync(input)) {
210
+ console.error(`${fmt("31", "Error:")} Missing Mermaid input file. Usage: wirepulse import <diagram.mmd> [-o out.wp]`);
211
+ process.exit(2);
212
+ }
213
+ const resolvedInput = path.resolve(input);
214
+ const parsedName = path.parse(resolvedInput);
215
+ const outWp = path.resolve(values.out || path.join(parsedName.dir, `${parsedName.name}.wp`));
216
+ const mermaidRaw = fs.readFileSync(resolvedInput, "utf8");
217
+ const wpSource = convertMermaidToWirepulse(mermaidRaw, {
218
+ title: parsedName.name.replace(/[-_]+/g, " "),
219
+ });
220
+ const outDir = path.dirname(outWp);
221
+ if (outDir && !fs.existsSync(outDir))
222
+ fs.mkdirSync(outDir, { recursive: true });
223
+ fs.writeFileSync(outWp, wpSource, "utf8");
224
+ console.log(`${fmt("32", "✔")} Converted Mermaid → ${fmt("36", outWp)}`);
225
+ console.log(` Next: ${fmt("36", `wirepulse build ${path.basename(outWp)}`)} or ${fmt("36", `wirepulse studio --file ${path.basename(outWp)}`)}`);
226
+ return;
227
+ }
228
+ if (cmd === "build") {
229
+ const input = positionals[1];
230
+ if (!input) {
231
+ console.error(`${fmt("31", "Error:")} Missing input file. Usage: wirepulse build <file.wp>`);
232
+ process.exit(2);
233
+ }
234
+ const outPath = path.resolve(values.out || defaultOutPath(input));
235
+ const ok = buildOnce(path.resolve(input), outPath, themeOverride, speedMul, showGrid, includeWatermark, Boolean(values["light-dark"]));
236
+ if (!ok)
237
+ process.exit(1);
238
+ return;
239
+ }
240
+ if (cmd === "watch") {
241
+ const input = positionals[1];
242
+ if (!input) {
243
+ console.error(`${fmt("31", "Error:")} Missing input file. Usage: wirepulse watch <file.wp>`);
244
+ process.exit(2);
245
+ }
246
+ const resolvedInput = path.resolve(input);
247
+ const outPath = path.resolve(values.out || defaultOutPath(input));
248
+ buildOnce(resolvedInput, outPath, themeOverride, speedMul, showGrid, includeWatermark, Boolean(values["light-dark"]));
249
+ console.log(`${fmt("36", "Watching")} ${resolvedInput} for changes… (Ctrl+C to stop)`);
250
+ let debounce;
251
+ fs.watch(resolvedInput, () => {
252
+ clearTimeout(debounce);
253
+ debounce = setTimeout(() => {
254
+ buildOnce(resolvedInput, outPath, themeOverride, speedMul, showGrid, includeWatermark, Boolean(values["light-dark"]));
255
+ }, 100);
256
+ });
257
+ return;
258
+ }
259
+ if (cmd === "studio") {
260
+ const port = values.port ? Number.parseInt(values.port, 10) : 4173;
261
+ const filePath = values.file || positionals[1];
262
+ const running = await startStudioServer({
263
+ port: Number.isNaN(port) ? 4173 : port,
264
+ filePath,
265
+ outSvgPath: values.out,
266
+ version: VERSION,
267
+ });
268
+ console.log(`\n ${fmt("1;36", "wirepulse studio")} ${fmt("2", `v${VERSION}`)} running at ${fmt("1;32", running.url)}`);
269
+ if (filePath) {
270
+ console.log(` Attached file: ${fmt("36", path.resolve(filePath))} (Ctrl+S saves to disk)`);
271
+ }
272
+ console.log(` Press Ctrl+C to stop.\n`);
273
+ if (!values["no-open"]) {
274
+ openBrowser(running.url);
275
+ }
276
+ return;
277
+ }
278
+ console.error(`${fmt("31", "Unknown command:")} ${cmd}`);
279
+ console.log(HELP);
280
+ process.exit(2);
281
+ }
282
+ main().catch((err) => {
283
+ console.error(`${fmt("31", "Fatal:")} ${err instanceof Error ? err.message : String(err)}`);
284
+ process.exit(1);
285
+ });
@@ -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
+ }
@@ -0,0 +1,23 @@
1
+ import type { ParseError, RenderOptions, ValidationResult } from "./types.js";
2
+ export declare const VERSION = "0.2.0";
3
+ export interface CompileResult {
4
+ svg: string;
5
+ errors: ParseError[];
6
+ validation: ValidationResult;
7
+ }
8
+ /**
9
+ * Convenience one-shot helper: parse `.wp` DSL, JSON, or Mermaid flowchart,
10
+ * render a pure zero-JS 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 { convertMermaidToWirepulse, isMermaidSource } from "./mermaid.js";
18
+ export { layoutDiagram } from "./layout.js";
19
+ export { renderSvg } from "./renderer.js";
20
+ export { validateSvg } from "./validator.js";
21
+ export { TEMPLATES, getTemplateById } from "./templates.js";
22
+ export { startStudioServer } from "./studio.js";
23
+ export { buildStudioHtml } from "./studio-html.js";
package/dist/index.js ADDED
@@ -0,0 +1,29 @@
1
+ import { convertMermaidToWirepulse, isMermaidSource } from "./mermaid.js";
2
+ import { parseDiagram } from "./parser.js";
3
+ import { renderSvg } from "./renderer.js";
4
+ import { validateSvg } from "./validator.js";
5
+ export const VERSION = "0.2.0";
6
+ /**
7
+ * Convenience one-shot helper: parse `.wp` DSL, JSON, or Mermaid flowchart,
8
+ * render a pure zero-JS animated SVG, and validate GitHub README CSP compliance.
9
+ */
10
+ export function compileDiagram(source, options = {}) {
11
+ const normalized = isMermaidSource(source)
12
+ ? convertMermaidToWirepulse(source)
13
+ : source;
14
+ const { spec, errors } = parseDiagram(normalized);
15
+ const svg = renderSvg(spec, options);
16
+ const validation = validateSvg(svg);
17
+ return { svg, errors, validation };
18
+ }
19
+ export * from "./types.js";
20
+ export { ICONS, ICON_NAMES, getIconMarkup } from "./icons.js";
21
+ export { THEMES, THEME_NAMES, ACCENTS, ACCENT_NAMES, buildThemeCss } from "./themes.js";
22
+ export { parseDiagram, updateNodeGridInSource } from "./parser.js";
23
+ export { convertMermaidToWirepulse, isMermaidSource } from "./mermaid.js";
24
+ export { layoutDiagram } from "./layout.js";
25
+ export { renderSvg } from "./renderer.js";
26
+ export { validateSvg } from "./validator.js";
27
+ export { TEMPLATES, getTemplateById } from "./templates.js";
28
+ export { startStudioServer } from "./studio.js";
29
+ export { buildStudioHtml } from "./studio-html.js";