wirepulse 0.1.0 → 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 +7 -0
- package/README.md +23 -3
- package/dist/browser-core.d.ts +8 -0
- package/dist/browser-core.js +8 -0
- package/dist/cli.js +24 -2
- package/dist/index.d.ts +5 -3
- package/dist/index.js +10 -4
- package/dist/mermaid.d.ts +11 -0
- package/dist/mermaid.js +278 -0
- package/dist/studio-html.d.ts +3 -0
- package/dist/studio-html.js +225 -49
- package/dist/studio.js +15 -0
- package/dist/validator.js +1 -1
- package/package.json +3 -2
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,13 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to `wirepulse` will be documented in this file.
|
|
4
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
|
+
|
|
5
12
|
## [0.1.0] - 2026-12-04
|
|
6
13
|
|
|
7
14
|
### Added
|
package/README.md
CHANGED
|
@@ -2,6 +2,9 @@
|
|
|
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
4
|
|
|
5
|
+
[](https://rynia.github.io/wirepulse/)
|
|
6
|
+
|
|
7
|
+
[](https://www.npmjs.com/package/wirepulse)
|
|
5
8
|
[](https://github.com/Rynia/wirepulse/actions/workflows/ci.yml)
|
|
6
9
|
[](LICENSE)
|
|
7
10
|
[](https://nodejs.org)
|
|
@@ -27,15 +30,32 @@ Existing animated diagram tools rely on **JavaScript (GSAP / React)** — which
|
|
|
27
30
|
| **Live Animated Data Packets & Flows** | ✅ | ❌ | ✅ |
|
|
28
31
|
| **Works Natively Inside GitHub `README.md` (Zero JS)** | ✅ | ✅ | ❌ *(blocked by CSP)* |
|
|
29
32
|
| **Auto GitHub Light & Dark Mode (`prefers-color-scheme`)** | ✅ | ⚠️ | ❌ |
|
|
30
|
-
| **
|
|
33
|
+
| **1-Click Mermaid Flowchart Import & Auto-Icons** | ✅ | — | ❌ |
|
|
34
|
+
| **Built-In Drag-and-Drop Visual Studio (Web + Local)** | ✅ | ❌ | ⚠️ |
|
|
31
35
|
| **1-Click Export to SVG, 2x PNG & Animated WebM** | ✅ | ❌ | ❌ |
|
|
32
36
|
| **Zero Runtime Dependencies (`npx` Cold Start < 1s)** | ✅ | ❌ | ❌ |
|
|
33
37
|
|
|
34
38
|
---
|
|
35
39
|
|
|
36
|
-
##
|
|
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`)
|
|
37
57
|
|
|
38
|
-
|
|
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`):
|
|
39
59
|
|
|
40
60
|
```bash
|
|
41
61
|
npx wirepulse studio
|
|
@@ -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.js
CHANGED
|
@@ -3,7 +3,7 @@ import { spawn } from "node:child_process";
|
|
|
3
3
|
import fs from "node:fs";
|
|
4
4
|
import path from "node:path";
|
|
5
5
|
import { parseArgs } from "node:util";
|
|
6
|
-
import { compileDiagram, VERSION } from "./index.js";
|
|
6
|
+
import { compileDiagram, convertMermaidToWirepulse, VERSION } from "./index.js";
|
|
7
7
|
import { startStudioServer } from "./studio.js";
|
|
8
8
|
import { getTemplateById, TEMPLATES } from "./templates.js";
|
|
9
9
|
import { THEME_NAMES } from "./themes.js";
|
|
@@ -18,7 +18,8 @@ ${fmt("1", "USAGE")}
|
|
|
18
18
|
wirepulse <command> [options]
|
|
19
19
|
|
|
20
20
|
${fmt("1", "COMMANDS")}
|
|
21
|
-
build <file> Compile a .wp or .json diagram into an animated .svg
|
|
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
|
|
22
23
|
watch <file> Watch a diagram file and rebuild automatically on save
|
|
23
24
|
studio Launch the local interactive Visual Studio in your browser
|
|
24
25
|
validate <svg> Verify GitHub README / Camo CSP safety of an SVG file
|
|
@@ -203,6 +204,27 @@ async function main() {
|
|
|
203
204
|
process.exit(1);
|
|
204
205
|
return;
|
|
205
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
|
+
}
|
|
206
228
|
if (cmd === "build") {
|
|
207
229
|
const input = positionals[1];
|
|
208
230
|
if (!input) {
|
package/dist/index.d.ts
CHANGED
|
@@ -1,21 +1,23 @@
|
|
|
1
1
|
import type { ParseError, RenderOptions, ValidationResult } from "./types.js";
|
|
2
|
-
export declare const VERSION = "0.
|
|
2
|
+
export declare const VERSION = "0.2.0";
|
|
3
3
|
export interface CompileResult {
|
|
4
4
|
svg: string;
|
|
5
5
|
errors: ParseError[];
|
|
6
6
|
validation: ValidationResult;
|
|
7
7
|
}
|
|
8
8
|
/**
|
|
9
|
-
* Convenience one-shot helper: parse `.wp` DSL
|
|
10
|
-
* animated SVG, and validate GitHub README CSP compliance.
|
|
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
11
|
*/
|
|
12
12
|
export declare function compileDiagram(source: string, options?: RenderOptions): CompileResult;
|
|
13
13
|
export * from "./types.js";
|
|
14
14
|
export { ICONS, ICON_NAMES, getIconMarkup } from "./icons.js";
|
|
15
15
|
export { THEMES, THEME_NAMES, ACCENTS, ACCENT_NAMES, buildThemeCss } from "./themes.js";
|
|
16
16
|
export { parseDiagram, updateNodeGridInSource } from "./parser.js";
|
|
17
|
+
export { convertMermaidToWirepulse, isMermaidSource } from "./mermaid.js";
|
|
17
18
|
export { layoutDiagram } from "./layout.js";
|
|
18
19
|
export { renderSvg } from "./renderer.js";
|
|
19
20
|
export { validateSvg } from "./validator.js";
|
|
20
21
|
export { TEMPLATES, getTemplateById } from "./templates.js";
|
|
21
22
|
export { startStudioServer } from "./studio.js";
|
|
23
|
+
export { buildStudioHtml } from "./studio-html.js";
|
package/dist/index.js
CHANGED
|
@@ -1,13 +1,17 @@
|
|
|
1
|
+
import { convertMermaidToWirepulse, isMermaidSource } from "./mermaid.js";
|
|
1
2
|
import { parseDiagram } from "./parser.js";
|
|
2
3
|
import { renderSvg } from "./renderer.js";
|
|
3
4
|
import { validateSvg } from "./validator.js";
|
|
4
|
-
export const VERSION = "0.
|
|
5
|
+
export const VERSION = "0.2.0";
|
|
5
6
|
/**
|
|
6
|
-
* Convenience one-shot helper: parse `.wp` DSL
|
|
7
|
-
* animated SVG, and validate GitHub README CSP compliance.
|
|
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.
|
|
8
9
|
*/
|
|
9
10
|
export function compileDiagram(source, options = {}) {
|
|
10
|
-
const
|
|
11
|
+
const normalized = isMermaidSource(source)
|
|
12
|
+
? convertMermaidToWirepulse(source)
|
|
13
|
+
: source;
|
|
14
|
+
const { spec, errors } = parseDiagram(normalized);
|
|
11
15
|
const svg = renderSvg(spec, options);
|
|
12
16
|
const validation = validateSvg(svg);
|
|
13
17
|
return { svg, errors, validation };
|
|
@@ -16,8 +20,10 @@ export * from "./types.js";
|
|
|
16
20
|
export { ICONS, ICON_NAMES, getIconMarkup } from "./icons.js";
|
|
17
21
|
export { THEMES, THEME_NAMES, ACCENTS, ACCENT_NAMES, buildThemeCss } from "./themes.js";
|
|
18
22
|
export { parseDiagram, updateNodeGridInSource } from "./parser.js";
|
|
23
|
+
export { convertMermaidToWirepulse, isMermaidSource } from "./mermaid.js";
|
|
19
24
|
export { layoutDiagram } from "./layout.js";
|
|
20
25
|
export { renderSvg } from "./renderer.js";
|
|
21
26
|
export { validateSvg } from "./validator.js";
|
|
22
27
|
export { TEMPLATES, getTemplateById } from "./templates.js";
|
|
23
28
|
export { startStudioServer } from "./studio.js";
|
|
29
|
+
export { buildStudioHtml } from "./studio-html.js";
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Detect whether a text string looks like a Mermaid flowchart/graph definition.
|
|
3
|
+
*/
|
|
4
|
+
export declare function isMermaidSource(source: string): boolean;
|
|
5
|
+
/**
|
|
6
|
+
* Convert a Mermaid `flowchart` / `graph` diagram into clean, animated `wirepulse` `.wp` DSL
|
|
7
|
+
* with automatic semantic icon & color inference.
|
|
8
|
+
*/
|
|
9
|
+
export declare function convertMermaidToWirepulse(mermaidSource: string, options?: {
|
|
10
|
+
title?: string;
|
|
11
|
+
}): string;
|
package/dist/mermaid.js
ADDED
|
@@ -0,0 +1,278 @@
|
|
|
1
|
+
const GROUP_COLORS = ["cyan", "violet", "emerald", "amber", "blue", "rose"];
|
|
2
|
+
/**
|
|
3
|
+
* Infer a crisp semantic icon and accent color from a node's label/shape
|
|
4
|
+
* so converted Mermaid diagrams instantly look hand-crafted.
|
|
5
|
+
*/
|
|
6
|
+
function inferStyleFromLabel(label, shapeHint) {
|
|
7
|
+
const lower = label.toLowerCase();
|
|
8
|
+
if (/\b(redis|cache|memcached|cdn|fastly|cloudflare|edge)\b/.test(lower)) {
|
|
9
|
+
return { icon: "bolt", color: "amber" };
|
|
10
|
+
}
|
|
11
|
+
if (shapeHint === "db" || /\b(postgres|mysql|mongo|sqlite|sql|database|db|supabase|dynamo|vector|pgvector|qdrant|pinecone)\b/.test(lower)) {
|
|
12
|
+
return { icon: "database", color: "emerald" };
|
|
13
|
+
}
|
|
14
|
+
if (/\b(kafka|queue|sqs|rabbitmq|pubsub|event|stream|bus|broker)\b/.test(lower)) {
|
|
15
|
+
return { icon: "queue", color: "rose" };
|
|
16
|
+
}
|
|
17
|
+
if (/\b(auth|oauth|jwt|gateway|firewall|waf|guard|security|shield|proxy|nginx)\b/.test(lower)) {
|
|
18
|
+
return { icon: "shield", color: "violet", pulse: true };
|
|
19
|
+
}
|
|
20
|
+
if (/\b(ai|llm|agent|claude|gpt|gemini|model|openai|anthropic|rag|mcp|embed)\b/.test(lower)) {
|
|
21
|
+
return { icon: "sparkles", color: "violet", pulse: true };
|
|
22
|
+
}
|
|
23
|
+
if (/\b(browser|web|client|frontend|react|next|vue|ui|app|spa)\b/.test(lower)) {
|
|
24
|
+
return { icon: "browser", color: "cyan", pulse: true };
|
|
25
|
+
}
|
|
26
|
+
if (/\b(mobile|ios|android|phone)\b/.test(lower)) {
|
|
27
|
+
return { icon: "mobile", color: "cyan", pulse: true };
|
|
28
|
+
}
|
|
29
|
+
if (/\b(user|customer|dev|developer|admin)\b/.test(lower)) {
|
|
30
|
+
return { icon: "user", color: "cyan", pulse: true };
|
|
31
|
+
}
|
|
32
|
+
if (/\b(cli|terminal|shell|bash|ssh)\b/.test(lower)) {
|
|
33
|
+
return { icon: "terminal", color: "cyan", pulse: true };
|
|
34
|
+
}
|
|
35
|
+
if (/\b(git|github|repo|pr|branch|ci|cd|action|deploy)\b/.test(lower)) {
|
|
36
|
+
return { icon: "git", color: "blue" };
|
|
37
|
+
}
|
|
38
|
+
if (/\b(docker|container|k8s|kubernetes|pod|helm|build)\b/.test(lower)) {
|
|
39
|
+
return { icon: "box", color: "blue" };
|
|
40
|
+
}
|
|
41
|
+
if (/\b(s3|bucket|storage|blob|disk|file|cdn)\b/.test(lower)) {
|
|
42
|
+
return { icon: "storage", color: "amber" };
|
|
43
|
+
}
|
|
44
|
+
if (/\b(worker|lambda|function|cron|job|processor)\b/.test(lower)) {
|
|
45
|
+
return { icon: "lambda", color: "orange" };
|
|
46
|
+
}
|
|
47
|
+
if (/\b(api|service|server|backend|node|go|rust|python|micro)\b/.test(lower)) {
|
|
48
|
+
return { icon: "server", color: "blue" };
|
|
49
|
+
}
|
|
50
|
+
if (/\b(search|elastic|algolia|bm25|index)\b/.test(lower)) {
|
|
51
|
+
return { icon: "search", color: "amber" };
|
|
52
|
+
}
|
|
53
|
+
if (/\b(webhook|stripe|payment|billing|mail|email|notify)\b/.test(lower)) {
|
|
54
|
+
return { icon: "plug", color: "orange" };
|
|
55
|
+
}
|
|
56
|
+
if (/\b(cloud|aws|gcp|azure|internet|web)\b/.test(lower)) {
|
|
57
|
+
return { icon: "cloud", color: "cyan" };
|
|
58
|
+
}
|
|
59
|
+
if (shapeHint === "decision") {
|
|
60
|
+
return { icon: "layers", color: "amber" };
|
|
61
|
+
}
|
|
62
|
+
return { icon: "server", color: "blue" };
|
|
63
|
+
}
|
|
64
|
+
function sanitizeId(raw) {
|
|
65
|
+
const cleaned = raw.trim().replace(/[^a-zA-Z0-9_-]/g, "_");
|
|
66
|
+
return cleaned || "node";
|
|
67
|
+
}
|
|
68
|
+
function parseNodeToken(token) {
|
|
69
|
+
const trimmed = token.trim();
|
|
70
|
+
// Match shapes: id[(Label)], id([Label]), id((Label)), id{Label}, id[Label], id(Label)
|
|
71
|
+
const patterns = [
|
|
72
|
+
{ re: /^([a-zA-Z0-9_-]+)\[\((.+?)\)\]$/, hint: "db" },
|
|
73
|
+
{ re: /^([a-zA-Z0-9_-]+)\(\[(.+?)\]\)$/, hint: "default" },
|
|
74
|
+
{ re: /^([a-zA-Z0-9_-]+)\(\((.+?)\)\)$/, hint: "circle" },
|
|
75
|
+
{ re: /^([a-zA-Z0-9_-]+)\{\{(.+?)\}\}$/, hint: "decision" },
|
|
76
|
+
{ re: /^([a-zA-Z0-9_-]+)\{(.+?)\}$/, hint: "decision" },
|
|
77
|
+
{ re: /^([a-zA-Z0-9_-]+)\[(.+?)\]$/, hint: "default" },
|
|
78
|
+
{ re: /^([a-zA-Z0-9_-]+)\((.+?)\)$/, hint: "default" },
|
|
79
|
+
];
|
|
80
|
+
for (const { re, hint } of patterns) {
|
|
81
|
+
const m = re.exec(trimmed);
|
|
82
|
+
if (m) {
|
|
83
|
+
const id = sanitizeId(m[1]);
|
|
84
|
+
let rawLabel = m[2].trim().replace(/^["']|["']$/g, "");
|
|
85
|
+
// Split `<br/>` or `\n` into label + sublabel
|
|
86
|
+
const parts = rawLabel.split(/<br\s*\/?>|\\n/i).map((p) => p.trim()).filter(Boolean);
|
|
87
|
+
const label = parts[0] || id;
|
|
88
|
+
const sublabel = parts.length > 1 ? parts.slice(1).join(" · ") : undefined;
|
|
89
|
+
return { id, label, sublabel, shapeHint: hint };
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
return { id: sanitizeId(trimmed), shapeHint: "default" };
|
|
93
|
+
}
|
|
94
|
+
function escapeQuote(s) {
|
|
95
|
+
return s.replace(/"/g, '\\"');
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Detect whether a text string looks like a Mermaid flowchart/graph definition.
|
|
99
|
+
*/
|
|
100
|
+
export function isMermaidSource(source) {
|
|
101
|
+
return /^\s*(?:flowchart|graph)\s+(?:LR|RL|TD|TB|BT)\b/im.test(source);
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Convert a Mermaid `flowchart` / `graph` diagram into clean, animated `wirepulse` `.wp` DSL
|
|
105
|
+
* with automatic semantic icon & color inference.
|
|
106
|
+
*/
|
|
107
|
+
export function convertMermaidToWirepulse(mermaidSource, options = {}) {
|
|
108
|
+
const lines = mermaidSource.split(/\r?\n/);
|
|
109
|
+
let direction = "LR";
|
|
110
|
+
const groups = [];
|
|
111
|
+
const groupStack = [];
|
|
112
|
+
const nodes = new Map();
|
|
113
|
+
const edges = [];
|
|
114
|
+
const ensureNode = (rawToken, activeGroup) => {
|
|
115
|
+
const parsed = parseNodeToken(rawToken);
|
|
116
|
+
const existing = nodes.get(parsed.id);
|
|
117
|
+
if (existing) {
|
|
118
|
+
if (parsed.label && existing.label === existing.id) {
|
|
119
|
+
existing.label = parsed.label;
|
|
120
|
+
existing.sublabel = parsed.sublabel;
|
|
121
|
+
const style = inferStyleFromLabel(parsed.label, parsed.shapeHint);
|
|
122
|
+
existing.icon = style.icon;
|
|
123
|
+
existing.color = style.color;
|
|
124
|
+
existing.pulse = style.pulse;
|
|
125
|
+
}
|
|
126
|
+
if (activeGroup && !existing.group) {
|
|
127
|
+
existing.group = activeGroup;
|
|
128
|
+
}
|
|
129
|
+
return existing;
|
|
130
|
+
}
|
|
131
|
+
const label = parsed.label || parsed.id;
|
|
132
|
+
const style = inferStyleFromLabel(label, parsed.shapeHint);
|
|
133
|
+
const node = {
|
|
134
|
+
id: parsed.id,
|
|
135
|
+
label,
|
|
136
|
+
sublabel: parsed.sublabel,
|
|
137
|
+
icon: style.icon,
|
|
138
|
+
color: style.color,
|
|
139
|
+
pulse: style.pulse,
|
|
140
|
+
group: activeGroup,
|
|
141
|
+
};
|
|
142
|
+
nodes.set(parsed.id, node);
|
|
143
|
+
return node;
|
|
144
|
+
};
|
|
145
|
+
for (const rawLine of lines) {
|
|
146
|
+
const line = rawLine.replace(/%%.*$/, "").trim();
|
|
147
|
+
if (!line)
|
|
148
|
+
continue;
|
|
149
|
+
// Skip Mermaid styling / classDef directives
|
|
150
|
+
if (/^(?:classDef|class|style|linkStyle|click)\s+/i.test(line))
|
|
151
|
+
continue;
|
|
152
|
+
// Header: flowchart LR / graph TD
|
|
153
|
+
const dirMatch = /^(?:flowchart|graph)\s+(LR|RL|TD|TB|BT)\b/i.exec(line);
|
|
154
|
+
if (dirMatch) {
|
|
155
|
+
const dir = dirMatch[1].toUpperCase();
|
|
156
|
+
direction = dir === "TD" || dir === "TB" || dir === "BT" ? "TB" : "LR";
|
|
157
|
+
continue;
|
|
158
|
+
}
|
|
159
|
+
// Subgraph start
|
|
160
|
+
const subMatch = /^subgraph\s+([^\[\n]+?)(?:\s*\[(.+?)\])?$/i.exec(line);
|
|
161
|
+
if (subMatch) {
|
|
162
|
+
const rawHead = subMatch[1].trim().replace(/^["']|["']$/g, "");
|
|
163
|
+
const bracketLabel = subMatch[2]?.trim().replace(/^["']|["']$/g, "");
|
|
164
|
+
const id = sanitizeId(rawHead.split(/\s+/)[0]);
|
|
165
|
+
const label = bracketLabel || rawHead;
|
|
166
|
+
const color = GROUP_COLORS[groups.length % GROUP_COLORS.length];
|
|
167
|
+
groups.push({ id, label, color });
|
|
168
|
+
groupStack.push(id);
|
|
169
|
+
continue;
|
|
170
|
+
}
|
|
171
|
+
if (/^end$/i.test(line)) {
|
|
172
|
+
groupStack.pop();
|
|
173
|
+
continue;
|
|
174
|
+
}
|
|
175
|
+
const activeGroup = groupStack[groupStack.length - 1];
|
|
176
|
+
// Edge formats:
|
|
177
|
+
// 1) A -->|label| B or A -.->|label| B or A ==>|label| B or A <-->|label| B
|
|
178
|
+
// 2) A -- label --> B or A -. label .-> B or A == label ==> B
|
|
179
|
+
// 3) A --> B or A -.-> B or A ==> B or A <--> B
|
|
180
|
+
let matchedEdge = false;
|
|
181
|
+
const pipeEdgeRe = /^(.+?)\s+(<-->|<==>|<-.->|-->|--->|==>|-.->|---)\s*\|([^|]+)\|\s*(.+)$/;
|
|
182
|
+
const inlineLabelRe = /^(.+?)\s+(?:--\s+(.+?)\s+-->|-\.\s+(.+?)\s+\.->|==\s+(.+?)\s+==>)\s*(.+)$/;
|
|
183
|
+
const plainEdgeRe = /^(.+?)\s+(<-->|<==>|<-.->|-->|--->|==>|-.->|---)\s+(.+)$/;
|
|
184
|
+
let fromRaw = "";
|
|
185
|
+
let toRaw = "";
|
|
186
|
+
let edgeLabel;
|
|
187
|
+
let arrow = "-->";
|
|
188
|
+
const mPipe = pipeEdgeRe.exec(line);
|
|
189
|
+
const mInline = !mPipe ? inlineLabelRe.exec(line) : null;
|
|
190
|
+
const mPlain = !mPipe && !mInline ? plainEdgeRe.exec(line) : null;
|
|
191
|
+
if (mPipe) {
|
|
192
|
+
fromRaw = mPipe[1];
|
|
193
|
+
arrow = mPipe[2];
|
|
194
|
+
edgeLabel = mPipe[3].trim().replace(/^["']|["']$/g, "");
|
|
195
|
+
toRaw = mPipe[4];
|
|
196
|
+
matchedEdge = true;
|
|
197
|
+
}
|
|
198
|
+
else if (mInline) {
|
|
199
|
+
fromRaw = mInline[1];
|
|
200
|
+
edgeLabel = (mInline[2] || mInline[3] || mInline[4] || "").trim().replace(/^["']|["']$/g, "");
|
|
201
|
+
arrow = mInline[3] ? "-.->" : mInline[4] ? "==>" : "-->";
|
|
202
|
+
toRaw = mInline[5];
|
|
203
|
+
matchedEdge = true;
|
|
204
|
+
}
|
|
205
|
+
else if (mPlain) {
|
|
206
|
+
fromRaw = mPlain[1];
|
|
207
|
+
arrow = mPlain[2];
|
|
208
|
+
toRaw = mPlain[3];
|
|
209
|
+
matchedEdge = true;
|
|
210
|
+
}
|
|
211
|
+
if (matchedEdge) {
|
|
212
|
+
// Support chained `A & B --> C` splits
|
|
213
|
+
const fromParts = fromRaw.split(/\s*&\s*/).filter(Boolean);
|
|
214
|
+
const toParts = toRaw.split(/\s*&\s*/).filter(Boolean);
|
|
215
|
+
const bidir = arrow.startsWith("<");
|
|
216
|
+
const flow = arrow.includes(".") ? "dash" : arrow.includes("=") ? "pulse" : arrow === "---" ? "solid" : "packet";
|
|
217
|
+
for (const fp of fromParts) {
|
|
218
|
+
const src = ensureNode(fp, activeGroup);
|
|
219
|
+
for (const tp of toParts) {
|
|
220
|
+
const dst = ensureNode(tp, activeGroup);
|
|
221
|
+
edges.push({
|
|
222
|
+
from: src.id,
|
|
223
|
+
to: dst.id,
|
|
224
|
+
label: edgeLabel,
|
|
225
|
+
flow,
|
|
226
|
+
bidir,
|
|
227
|
+
color: src.color,
|
|
228
|
+
});
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
continue;
|
|
232
|
+
}
|
|
233
|
+
// Standalone node declaration inside or outside subgraph
|
|
234
|
+
if (/^[a-zA-Z0-9_-]+(?:\[|\(|\{)/.test(line) || /^[a-zA-Z0-9_-]+$/.test(line)) {
|
|
235
|
+
ensureNode(line, activeGroup);
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
// Serialize to clean `.wp` DSL
|
|
239
|
+
const out = [
|
|
240
|
+
`title: ${options.title || "Animated Architecture (Imported from Mermaid)"}`,
|
|
241
|
+
`subtitle: Zero-JS animated SVG — auto-adapts to GitHub Light & Dark mode`,
|
|
242
|
+
`theme: auto`,
|
|
243
|
+
`direction: ${direction}`,
|
|
244
|
+
`speed: normal`,
|
|
245
|
+
``,
|
|
246
|
+
];
|
|
247
|
+
if (groups.length > 0) {
|
|
248
|
+
for (const g of groups) {
|
|
249
|
+
out.push(`group ${g.id} "${escapeQuote(g.label)}" color=${g.color}`);
|
|
250
|
+
}
|
|
251
|
+
out.push("");
|
|
252
|
+
}
|
|
253
|
+
for (const n of nodes.values()) {
|
|
254
|
+
const parts = [`node ${n.id} "${escapeQuote(n.label)}"`];
|
|
255
|
+
if (n.sublabel)
|
|
256
|
+
parts.push(`sub="${escapeQuote(n.sublabel)}"`);
|
|
257
|
+
parts.push(`icon=${n.icon}`, `color=${n.color}`);
|
|
258
|
+
if (n.group)
|
|
259
|
+
parts.push(`group=${n.group}`);
|
|
260
|
+
if (n.pulse)
|
|
261
|
+
parts.push(`pulse=true`);
|
|
262
|
+
out.push(parts.join(" "));
|
|
263
|
+
}
|
|
264
|
+
if (edges.length > 0) {
|
|
265
|
+
out.push("");
|
|
266
|
+
for (const e of edges) {
|
|
267
|
+
const arrowSym = e.bidir ? "<->" : "->";
|
|
268
|
+
const parts = [`${e.from} ${arrowSym} ${e.to}`];
|
|
269
|
+
if (e.label)
|
|
270
|
+
parts.push(`"${escapeQuote(e.label)}"`);
|
|
271
|
+
parts.push(`flow=${e.flow}`);
|
|
272
|
+
if (e.color)
|
|
273
|
+
parts.push(`color=${e.color}`);
|
|
274
|
+
out.push(parts.join(" "));
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
return out.join("\n") + "\n";
|
|
278
|
+
}
|
package/dist/studio-html.d.ts
CHANGED
|
@@ -3,5 +3,8 @@ export interface StudioHtmlOptions {
|
|
|
3
3
|
fileName?: string;
|
|
4
4
|
canSaveToDisk: boolean;
|
|
5
5
|
version: string;
|
|
6
|
+
/** "server" calls /api/* on local Node server; "static" imports ./app/browser-core.js directly in browser (GitHub Pages). */
|
|
7
|
+
mode?: "server" | "static";
|
|
8
|
+
moduleImportPath?: string;
|
|
6
9
|
}
|
|
7
10
|
export declare function buildStudioHtml(opts: StudioHtmlOptions): string;
|
package/dist/studio-html.js
CHANGED
|
@@ -4,8 +4,29 @@ import { THEME_NAMES } from "./themes.js";
|
|
|
4
4
|
function safeJsonForScript(data) {
|
|
5
5
|
return JSON.stringify(data).replace(/</g, "\\u003c").replace(/>/g, "\\u003e");
|
|
6
6
|
}
|
|
7
|
+
const SAMPLE_MERMAID = `flowchart LR
|
|
8
|
+
subgraph Client
|
|
9
|
+
Web[Next.js Web App]
|
|
10
|
+
Mob[Mobile App]
|
|
11
|
+
end
|
|
12
|
+
subgraph Backend
|
|
13
|
+
GW[API Gateway]
|
|
14
|
+
API[Order Service]
|
|
15
|
+
Cache[(Redis Cache)]
|
|
16
|
+
DB[(PostgreSQL)]
|
|
17
|
+
Bus[Kafka Event Bus]
|
|
18
|
+
end
|
|
19
|
+
Web -->|HTTPS| GW
|
|
20
|
+
Mob -->|HTTPS| GW
|
|
21
|
+
GW --> API
|
|
22
|
+
API -.->|lookup| Cache
|
|
23
|
+
API -->|write| DB
|
|
24
|
+
API ==>|publish| Bus`;
|
|
7
25
|
export function buildStudioHtml(opts) {
|
|
26
|
+
const mode = opts.mode ?? "server";
|
|
27
|
+
const moduleImportPath = opts.moduleImportPath ?? "./app/browser-core.js";
|
|
8
28
|
const bootstrap = safeJsonForScript({
|
|
29
|
+
mode,
|
|
9
30
|
initialSource: opts.initialSource,
|
|
10
31
|
fileName: opts.fileName ?? null,
|
|
11
32
|
canSaveToDisk: opts.canSaveToDisk,
|
|
@@ -13,13 +34,75 @@ export function buildStudioHtml(opts) {
|
|
|
13
34
|
templates: TEMPLATES,
|
|
14
35
|
themes: THEME_NAMES,
|
|
15
36
|
icons: ICON_NAMES,
|
|
37
|
+
sampleMermaid: SAMPLE_MERMAID,
|
|
16
38
|
});
|
|
39
|
+
const engineSetupCode = mode === "static"
|
|
40
|
+
? `import * as WP from ${JSON.stringify(moduleImportPath)};
|
|
41
|
+
async function apiRender(payload) {
|
|
42
|
+
const { spec, errors } = WP.parseDiagram(payload.source || '');
|
|
43
|
+
const effectiveTheme = payload.theme || spec.theme;
|
|
44
|
+
const svg = WP.renderSvg(spec, {
|
|
45
|
+
theme: effectiveTheme,
|
|
46
|
+
speedMultiplier: payload.speedMultiplier || 1,
|
|
47
|
+
paused: Boolean(payload.paused),
|
|
48
|
+
});
|
|
49
|
+
const previewSvg =
|
|
50
|
+
effectiveTheme === 'auto'
|
|
51
|
+
? WP.renderSvg(spec, {
|
|
52
|
+
theme: payload.previewMode === 'light' ? 'paper' : 'midnight',
|
|
53
|
+
speedMultiplier: payload.speedMultiplier || 1,
|
|
54
|
+
paused: Boolean(payload.paused),
|
|
55
|
+
})
|
|
56
|
+
: svg;
|
|
57
|
+
const validation = WP.validateSvg(svg);
|
|
58
|
+
return {
|
|
59
|
+
svg,
|
|
60
|
+
previewSvg,
|
|
61
|
+
errors,
|
|
62
|
+
validation,
|
|
63
|
+
nodeCount: spec.nodes.length,
|
|
64
|
+
edgeCount: spec.edges.length,
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
async function apiMoveNode(payload) {
|
|
68
|
+
return {
|
|
69
|
+
source: WP.updateNodeGridInSource(payload.source, payload.nodeId, payload.col, payload.row),
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
async function apiImportMermaid(mermaidText) {
|
|
73
|
+
return { source: WP.convertMermaidToWirepulse(mermaidText) };
|
|
74
|
+
}`
|
|
75
|
+
: `async function apiRender(payload) {
|
|
76
|
+
const res = await fetch('/api/render', {
|
|
77
|
+
method: 'POST',
|
|
78
|
+
headers: { 'Content-Type': 'application/json' },
|
|
79
|
+
body: JSON.stringify(payload),
|
|
80
|
+
});
|
|
81
|
+
return await res.json();
|
|
82
|
+
}
|
|
83
|
+
async function apiMoveNode(payload) {
|
|
84
|
+
const res = await fetch('/api/move-node', {
|
|
85
|
+
method: 'POST',
|
|
86
|
+
headers: { 'Content-Type': 'application/json' },
|
|
87
|
+
body: JSON.stringify(payload),
|
|
88
|
+
});
|
|
89
|
+
return await res.json();
|
|
90
|
+
}
|
|
91
|
+
async function apiImportMermaid(mermaidText) {
|
|
92
|
+
const res = await fetch('/api/import-mermaid', {
|
|
93
|
+
method: 'POST',
|
|
94
|
+
headers: { 'Content-Type': 'application/json' },
|
|
95
|
+
body: JSON.stringify({ mermaid: mermaidText }),
|
|
96
|
+
});
|
|
97
|
+
return await res.json();
|
|
98
|
+
}`;
|
|
17
99
|
return `<!DOCTYPE html>
|
|
18
100
|
<html lang="en">
|
|
19
101
|
<head>
|
|
20
102
|
<meta charset="UTF-8" />
|
|
21
103
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
22
104
|
<title>wirepulse studio — Animated Architecture SVGs for GitHub READMEs</title>
|
|
105
|
+
<meta name="description" content="Free zero-JS animated architecture SVG compiler and visual studio built natively for GitHub READMEs. Import Mermaid diagrams or author clean .wp DSL." />
|
|
23
106
|
<style>
|
|
24
107
|
:root {
|
|
25
108
|
--bg: #090c14;
|
|
@@ -30,6 +113,8 @@ export function buildStudioHtml(opts) {
|
|
|
30
113
|
--muted: #94a3b8;
|
|
31
114
|
--accent: #22d3ee;
|
|
32
115
|
--accent-soft: rgba(34, 211, 238, 0.14);
|
|
116
|
+
--violet: #a78bfa;
|
|
117
|
+
--violet-soft: rgba(167, 139, 250, 0.15);
|
|
33
118
|
--emerald: #34d399;
|
|
34
119
|
--rose: #fb7185;
|
|
35
120
|
--amber: #fbbf24;
|
|
@@ -51,20 +136,23 @@ export function buildStudioHtml(opts) {
|
|
|
51
136
|
display: flex;
|
|
52
137
|
align-items: center;
|
|
53
138
|
justify-content: space-between;
|
|
54
|
-
padding: 0
|
|
139
|
+
padding: 0 14px;
|
|
55
140
|
background: var(--panel);
|
|
56
141
|
border-bottom: 1px solid var(--border);
|
|
57
|
-
gap:
|
|
142
|
+
gap: 10px;
|
|
58
143
|
z-index: 20;
|
|
144
|
+
overflow-x: auto;
|
|
59
145
|
}
|
|
60
146
|
.brand {
|
|
61
147
|
display: flex;
|
|
62
148
|
align-items: center;
|
|
63
|
-
gap:
|
|
149
|
+
gap: 8px;
|
|
64
150
|
font-weight: 700;
|
|
65
151
|
font-size: 15px;
|
|
66
152
|
letter-spacing: -0.02em;
|
|
67
153
|
white-space: nowrap;
|
|
154
|
+
text-decoration: none;
|
|
155
|
+
color: var(--text);
|
|
68
156
|
}
|
|
69
157
|
.brand-dot {
|
|
70
158
|
width: 9px;
|
|
@@ -91,11 +179,11 @@ export function buildStudioHtml(opts) {
|
|
|
91
179
|
.toolbar-group {
|
|
92
180
|
display: flex;
|
|
93
181
|
align-items: center;
|
|
94
|
-
gap:
|
|
182
|
+
gap: 7px;
|
|
95
183
|
flex-wrap: nowrap;
|
|
96
184
|
}
|
|
97
185
|
|
|
98
|
-
select, button {
|
|
186
|
+
select, button, a.btn-link {
|
|
99
187
|
font-family: var(--sans);
|
|
100
188
|
font-size: 12.5px;
|
|
101
189
|
color: var(--text);
|
|
@@ -106,8 +194,12 @@ export function buildStudioHtml(opts) {
|
|
|
106
194
|
cursor: pointer;
|
|
107
195
|
transition: border-color 0.15s, background 0.15s, transform 0.1s;
|
|
108
196
|
white-space: nowrap;
|
|
197
|
+
text-decoration: none;
|
|
198
|
+
display: inline-flex;
|
|
199
|
+
align-items: center;
|
|
200
|
+
gap: 5px;
|
|
109
201
|
}
|
|
110
|
-
select:hover, button:hover {
|
|
202
|
+
select:hover, button:hover, a.btn-link:hover {
|
|
111
203
|
border-color: #3b4b70;
|
|
112
204
|
background: #1b243a;
|
|
113
205
|
}
|
|
@@ -121,6 +213,26 @@ export function buildStudioHtml(opts) {
|
|
|
121
213
|
button.primary:hover {
|
|
122
214
|
background: linear-gradient(135deg, #06b6d4, #3b82f6);
|
|
123
215
|
}
|
|
216
|
+
button.mermaid-btn {
|
|
217
|
+
background: var(--violet-soft);
|
|
218
|
+
border-color: rgba(167, 139, 250, 0.45);
|
|
219
|
+
color: #ddd6fe;
|
|
220
|
+
font-weight: 600;
|
|
221
|
+
}
|
|
222
|
+
button.mermaid-btn:hover {
|
|
223
|
+
background: rgba(167, 139, 250, 0.25);
|
|
224
|
+
border-color: var(--violet);
|
|
225
|
+
}
|
|
226
|
+
a.star-btn {
|
|
227
|
+
background: rgba(251, 191, 36, 0.12);
|
|
228
|
+
border-color: rgba(251, 191, 36, 0.4);
|
|
229
|
+
color: #fde68a;
|
|
230
|
+
font-weight: 600;
|
|
231
|
+
}
|
|
232
|
+
a.star-btn:hover {
|
|
233
|
+
background: rgba(251, 191, 36, 0.22);
|
|
234
|
+
border-color: var(--amber);
|
|
235
|
+
}
|
|
124
236
|
button.active {
|
|
125
237
|
border-color: var(--accent);
|
|
126
238
|
color: var(--accent);
|
|
@@ -263,12 +375,8 @@ export function buildStudioHtml(opts) {
|
|
|
263
375
|
max-width: 100%;
|
|
264
376
|
height: auto;
|
|
265
377
|
}
|
|
266
|
-
#svg-container g.wp-node {
|
|
267
|
-
|
|
268
|
-
}
|
|
269
|
-
#svg-container g.wp-node:active {
|
|
270
|
-
cursor: grabbing;
|
|
271
|
-
}
|
|
378
|
+
#svg-container g.wp-node { cursor: grab; }
|
|
379
|
+
#svg-container g.wp-node:active { cursor: grabbing; }
|
|
272
380
|
#svg-container g.wp-node:hover .wp-node-card {
|
|
273
381
|
stroke: var(--accent);
|
|
274
382
|
stroke-width: 1.75;
|
|
@@ -308,6 +416,54 @@ export function buildStudioHtml(opts) {
|
|
|
308
416
|
}
|
|
309
417
|
.icon-chip:hover { border-color: var(--accent); color: var(--accent); }
|
|
310
418
|
|
|
419
|
+
/* Mermaid Import Modal */
|
|
420
|
+
.modal-backdrop {
|
|
421
|
+
display: none;
|
|
422
|
+
position: fixed;
|
|
423
|
+
inset: 0;
|
|
424
|
+
background: rgba(2, 6, 23, 0.78);
|
|
425
|
+
backdrop-filter: blur(4px);
|
|
426
|
+
z-index: 60;
|
|
427
|
+
align-items: center;
|
|
428
|
+
justify-content: center;
|
|
429
|
+
padding: 20px;
|
|
430
|
+
}
|
|
431
|
+
.modal-backdrop.open { display: flex; }
|
|
432
|
+
.modal-box {
|
|
433
|
+
width: 100%;
|
|
434
|
+
max-width: 620px;
|
|
435
|
+
background: var(--panel);
|
|
436
|
+
border: 1px solid var(--border);
|
|
437
|
+
border-radius: 14px;
|
|
438
|
+
padding: 20px;
|
|
439
|
+
box-shadow: 0 24px 60px rgba(0,0,0,0.65);
|
|
440
|
+
display: flex;
|
|
441
|
+
flex-direction: column;
|
|
442
|
+
gap: 12px;
|
|
443
|
+
}
|
|
444
|
+
.modal-box h2 { font-size: 16px; font-weight: 700; }
|
|
445
|
+
.modal-box p { font-size: 12.5px; color: var(--muted); line-height: 1.5; }
|
|
446
|
+
textarea#mermaid-input {
|
|
447
|
+
width: 100%;
|
|
448
|
+
height: 220px;
|
|
449
|
+
resize: vertical;
|
|
450
|
+
padding: 12px;
|
|
451
|
+
border-radius: 8px;
|
|
452
|
+
border: 1px solid var(--border);
|
|
453
|
+
background: #0b0f1a;
|
|
454
|
+
color: #e2e8f0;
|
|
455
|
+
font-family: var(--mono);
|
|
456
|
+
font-size: 12px;
|
|
457
|
+
line-height: 1.55;
|
|
458
|
+
outline: none;
|
|
459
|
+
}
|
|
460
|
+
textarea#mermaid-input:focus { border-color: var(--violet); }
|
|
461
|
+
.modal-actions {
|
|
462
|
+
display: flex;
|
|
463
|
+
justify-content: flex-end;
|
|
464
|
+
gap: 8px;
|
|
465
|
+
}
|
|
466
|
+
|
|
311
467
|
/* Status Bar */
|
|
312
468
|
.statusbar {
|
|
313
469
|
display: flex;
|
|
@@ -353,14 +509,15 @@ export function buildStudioHtml(opts) {
|
|
|
353
509
|
<body>
|
|
354
510
|
<div class="app">
|
|
355
511
|
<header class="topbar">
|
|
356
|
-
<
|
|
512
|
+
<a class="brand" href="https://github.com/Rynia/wirepulse" target="_blank" rel="noopener">
|
|
357
513
|
<span class="brand-dot"></span>
|
|
358
514
|
<span>wirepulse</span>
|
|
359
515
|
<span class="brand-tag" id="version-tag">studio</span>
|
|
360
|
-
</
|
|
516
|
+
</a>
|
|
361
517
|
|
|
362
518
|
<div class="toolbar-group">
|
|
363
519
|
<select id="template-select" title="Load a starter architecture template"></select>
|
|
520
|
+
<button id="btn-import-mermaid" class="mermaid-btn" title="Paste a static Mermaid flowchart and animate it instantly">✨ Import Mermaid</button>
|
|
364
521
|
<select id="theme-select" title="Override diagram theme"></select>
|
|
365
522
|
<button id="btn-play" title="Pause or resume SVG animations">⏸ Pause</button>
|
|
366
523
|
<select id="speed-select" title="Animation speed multiplier">
|
|
@@ -377,6 +534,7 @@ export function buildStudioHtml(opts) {
|
|
|
377
534
|
<button id="btn-export-png" title="Export crisp 2x Retina PNG">PNG</button>
|
|
378
535
|
<button id="btn-export-webm" title="Record 3.5s animated WebM video">WebM</button>
|
|
379
536
|
<button id="btn-export-svg" class="primary" title="Download pure zero-JS animated SVG">⬇ Download SVG</button>
|
|
537
|
+
<a class="btn-link star-btn" href="https://github.com/Rynia/wirepulse" target="_blank" rel="noopener">★ Star</a>
|
|
380
538
|
</div>
|
|
381
539
|
</header>
|
|
382
540
|
|
|
@@ -436,14 +594,28 @@ export function buildStudioHtml(opts) {
|
|
|
436
594
|
<span id="size-status">0.0 KB</span>
|
|
437
595
|
<span id="counts-status">0 nodes · 0 edges</span>
|
|
438
596
|
</div>
|
|
439
|
-
<div>wirepulse · 100%
|
|
597
|
+
<div>wirepulse · 100% client-side · zero-JS SVG</div>
|
|
440
598
|
</footer>
|
|
441
599
|
</div>
|
|
442
600
|
|
|
601
|
+
<!-- Mermaid Import Modal -->
|
|
602
|
+
<div id="mermaid-modal" class="modal-backdrop" role="dialog" aria-modal="true" aria-label="Import Mermaid Flowchart">
|
|
603
|
+
<div class="modal-box">
|
|
604
|
+
<h2>✨ Upgrade Mermaid Flowchart → Animated SVG</h2>
|
|
605
|
+
<p>Paste any Mermaid <code>flowchart</code> or <code>graph</code> below. wirepulse automatically infers developer icons, semantic colors, cluster groups, and animated packet flows.</p>
|
|
606
|
+
<textarea id="mermaid-input" spellcheck="false"></textarea>
|
|
607
|
+
<div class="modal-actions">
|
|
608
|
+
<button id="btn-mermaid-cancel">Cancel</button>
|
|
609
|
+
<button id="btn-mermaid-convert" class="primary">Convert & Animate</button>
|
|
610
|
+
</div>
|
|
611
|
+
</div>
|
|
612
|
+
</div>
|
|
613
|
+
|
|
443
614
|
<div id="toast" class="toast"></div>
|
|
444
615
|
|
|
445
|
-
<script>
|
|
616
|
+
<script type="module">
|
|
446
617
|
const BOOT = ${bootstrap};
|
|
618
|
+
${engineSetupCode}
|
|
447
619
|
|
|
448
620
|
const editor = document.getElementById('dsl-editor');
|
|
449
621
|
const svgContainer = document.getElementById('svg-container');
|
|
@@ -463,6 +635,8 @@ export function buildStudioHtml(opts) {
|
|
|
463
635
|
const btnSave = document.getElementById('btn-save');
|
|
464
636
|
const btnGhDark = document.getElementById('btn-gh-dark');
|
|
465
637
|
const btnGhLight = document.getElementById('btn-gh-light');
|
|
638
|
+
const mermaidModal = document.getElementById('mermaid-modal');
|
|
639
|
+
const mermaidInput = document.getElementById('mermaid-input');
|
|
466
640
|
|
|
467
641
|
let currentSvg = '';
|
|
468
642
|
let isPaused = false;
|
|
@@ -475,8 +649,9 @@ export function buildStudioHtml(opts) {
|
|
|
475
649
|
document.getElementById('editor-filename').textContent = BOOT.fileName;
|
|
476
650
|
}
|
|
477
651
|
if (BOOT.canSaveToDisk) {
|
|
478
|
-
btnSave.style.display = 'inline-
|
|
652
|
+
btnSave.style.display = 'inline-flex';
|
|
479
653
|
}
|
|
654
|
+
mermaidInput.value = BOOT.sampleMermaid;
|
|
480
655
|
|
|
481
656
|
function showToast(msg) {
|
|
482
657
|
toastEl.textContent = msg;
|
|
@@ -521,7 +696,6 @@ export function buildStudioHtml(opts) {
|
|
|
521
696
|
iconGrid.appendChild(chip);
|
|
522
697
|
}
|
|
523
698
|
|
|
524
|
-
// Load initial source (or URL hash share if present)
|
|
525
699
|
function loadInitialSource() {
|
|
526
700
|
const hash = window.location.hash;
|
|
527
701
|
if (hash.startsWith('#wp=')) {
|
|
@@ -543,17 +717,11 @@ export function buildStudioHtml(opts) {
|
|
|
543
717
|
previewMode: ghPreviewMode,
|
|
544
718
|
};
|
|
545
719
|
try {
|
|
546
|
-
const
|
|
547
|
-
method: 'POST',
|
|
548
|
-
headers: { 'Content-Type': 'application/json' },
|
|
549
|
-
body: JSON.stringify(payload),
|
|
550
|
-
});
|
|
551
|
-
const data = await res.json();
|
|
720
|
+
const data = await apiRender(payload);
|
|
552
721
|
currentSvg = data.svg || '';
|
|
553
722
|
svgContainer.innerHTML = data.previewSvg || currentSvg;
|
|
554
723
|
attachNodeDragHandlers();
|
|
555
724
|
|
|
556
|
-
// Update error panel
|
|
557
725
|
if (data.errors && data.errors.length > 0) {
|
|
558
726
|
errorsPanel.innerHTML = data.errors
|
|
559
727
|
.map((e) => 'Line ' + e.line + ': ' + e.message)
|
|
@@ -563,7 +731,6 @@ export function buildStudioHtml(opts) {
|
|
|
563
731
|
errorsPanel.classList.remove('visible');
|
|
564
732
|
}
|
|
565
733
|
|
|
566
|
-
// Update status bar
|
|
567
734
|
const val = data.validation;
|
|
568
735
|
if (val && val.githubSafe) {
|
|
569
736
|
cspStatus.textContent = '✔ GitHub CSP Safe (0 scripts)';
|
|
@@ -582,10 +749,9 @@ export function buildStudioHtml(opts) {
|
|
|
582
749
|
|
|
583
750
|
function scheduleRender() {
|
|
584
751
|
clearTimeout(renderTimer);
|
|
585
|
-
renderTimer = setTimeout(renderNow,
|
|
752
|
+
renderTimer = setTimeout(renderNow, 90);
|
|
586
753
|
}
|
|
587
754
|
|
|
588
|
-
// Drag-and-drop node repositioning -> snaps to grid & updates DSL col/row
|
|
589
755
|
function attachNodeDragHandlers() {
|
|
590
756
|
const svgEl = svgContainer.querySelector('svg');
|
|
591
757
|
if (!svgEl) return;
|
|
@@ -615,24 +781,19 @@ export function buildStudioHtml(opts) {
|
|
|
615
781
|
|
|
616
782
|
if (Math.abs(dx) < 35 && Math.abs(dy) < 25) return;
|
|
617
783
|
|
|
618
|
-
const deltaCol = Math.round(dx /
|
|
619
|
-
const deltaRow = Math.round(dy /
|
|
784
|
+
const deltaCol = Math.round(dx / 316);
|
|
785
|
+
const deltaRow = Math.round(dy / 128);
|
|
620
786
|
if (deltaCol === 0 && deltaRow === 0) return;
|
|
621
787
|
|
|
622
788
|
const nextCol = Math.max(0, origCol + deltaCol);
|
|
623
789
|
const nextRow = Math.max(0, origRow + deltaRow);
|
|
624
790
|
|
|
625
|
-
const
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
nodeId,
|
|
631
|
-
col: nextCol,
|
|
632
|
-
row: nextRow,
|
|
633
|
-
}),
|
|
791
|
+
const updated = await apiMoveNode({
|
|
792
|
+
source: editor.value,
|
|
793
|
+
nodeId,
|
|
794
|
+
col: nextCol,
|
|
795
|
+
row: nextRow,
|
|
634
796
|
});
|
|
635
|
-
const updated = await resp.json();
|
|
636
797
|
if (updated.source) {
|
|
637
798
|
editor.value = updated.source;
|
|
638
799
|
showToast('Moved "' + nodeId + '" → col=' + nextCol + ' row=' + nextRow);
|
|
@@ -662,6 +823,30 @@ export function buildStudioHtml(opts) {
|
|
|
662
823
|
templateSelect.value = '';
|
|
663
824
|
});
|
|
664
825
|
|
|
826
|
+
// Mermaid import modal
|
|
827
|
+
document.getElementById('btn-import-mermaid').onclick = () => {
|
|
828
|
+
mermaidModal.classList.add('open');
|
|
829
|
+
mermaidInput.focus();
|
|
830
|
+
};
|
|
831
|
+
document.getElementById('btn-mermaid-cancel').onclick = () => {
|
|
832
|
+
mermaidModal.classList.remove('open');
|
|
833
|
+
};
|
|
834
|
+
mermaidModal.addEventListener('click', (e) => {
|
|
835
|
+
if (e.target === mermaidModal) mermaidModal.classList.remove('open');
|
|
836
|
+
});
|
|
837
|
+
document.getElementById('btn-mermaid-convert').onclick = async () => {
|
|
838
|
+
const raw = mermaidInput.value.trim();
|
|
839
|
+
if (!raw) return;
|
|
840
|
+
const converted = await apiImportMermaid(raw);
|
|
841
|
+
if (converted.source) {
|
|
842
|
+
editor.value = converted.source;
|
|
843
|
+
themeSelect.value = '';
|
|
844
|
+
mermaidModal.classList.remove('open');
|
|
845
|
+
await renderNow();
|
|
846
|
+
showToast('Converted Mermaid → animated wirepulse SVG!');
|
|
847
|
+
}
|
|
848
|
+
};
|
|
849
|
+
|
|
665
850
|
btnPlay.addEventListener('click', () => {
|
|
666
851
|
isPaused = !isPaused;
|
|
667
852
|
btnPlay.textContent = isPaused ? '▶ Play' : '⏸ Pause';
|
|
@@ -685,7 +870,6 @@ export function buildStudioHtml(opts) {
|
|
|
685
870
|
renderNow();
|
|
686
871
|
});
|
|
687
872
|
|
|
688
|
-
// Zoom controls
|
|
689
873
|
function applyZoom() {
|
|
690
874
|
svgContainer.style.transform = 'scale(' + zoom.toFixed(2) + ')';
|
|
691
875
|
zoomLabel.textContent = Math.round(zoom * 100) + '%';
|
|
@@ -694,7 +878,6 @@ export function buildStudioHtml(opts) {
|
|
|
694
878
|
document.getElementById('btn-zoom-out').onclick = () => { zoom = Math.max(0.4, zoom - 0.15); applyZoom(); };
|
|
695
879
|
document.getElementById('btn-zoom-reset').onclick = () => { zoom = 1; applyZoom(); };
|
|
696
880
|
|
|
697
|
-
// Quick inserts
|
|
698
881
|
let quickCounter = 1;
|
|
699
882
|
document.getElementById('btn-add-node').onclick = () => {
|
|
700
883
|
const id = 'svc' + quickCounter++;
|
|
@@ -712,7 +895,6 @@ export function buildStudioHtml(opts) {
|
|
|
712
895
|
document.getElementById('btn-icons').onclick = () => iconDrawer.classList.toggle('open');
|
|
713
896
|
document.getElementById('btn-close-icons').onclick = () => iconDrawer.classList.remove('open');
|
|
714
897
|
|
|
715
|
-
// Share URL
|
|
716
898
|
document.getElementById('btn-share').onclick = () => {
|
|
717
899
|
const encoded = btoa(unescape(encodeURIComponent(editor.value)));
|
|
718
900
|
const url = window.location.origin + window.location.pathname + '#wp=' + encoded;
|
|
@@ -721,7 +903,6 @@ export function buildStudioHtml(opts) {
|
|
|
721
903
|
showToast('Shareable URL copied to clipboard!');
|
|
722
904
|
};
|
|
723
905
|
|
|
724
|
-
// Download pure animated SVG
|
|
725
906
|
document.getElementById('btn-export-svg').onclick = () => {
|
|
726
907
|
if (!currentSvg) return;
|
|
727
908
|
const blob = new Blob([currentSvg], { type: 'image/svg+xml;charset=utf-8' });
|
|
@@ -733,7 +914,6 @@ export function buildStudioHtml(opts) {
|
|
|
733
914
|
showToast('Downloaded pure zero-JS architecture.svg!');
|
|
734
915
|
};
|
|
735
916
|
|
|
736
|
-
// Copy GitHub README snippet
|
|
737
917
|
document.getElementById('btn-copy-md').onclick = () => {
|
|
738
918
|
const snippet = [
|
|
739
919
|
'<picture>',
|
|
@@ -746,7 +926,6 @@ export function buildStudioHtml(opts) {
|
|
|
746
926
|
showToast('Copied GitHub README <picture> snippet!');
|
|
747
927
|
};
|
|
748
928
|
|
|
749
|
-
// Export 2x Retina PNG
|
|
750
929
|
document.getElementById('btn-export-png').onclick = async () => {
|
|
751
930
|
if (!currentSvg) return;
|
|
752
931
|
const svgEl = svgContainer.querySelector('svg');
|
|
@@ -773,7 +952,6 @@ export function buildStudioHtml(opts) {
|
|
|
773
952
|
img.src = url;
|
|
774
953
|
};
|
|
775
954
|
|
|
776
|
-
// Export Animated WebM Video (3.5s capture via Canvas + MediaRecorder)
|
|
777
955
|
document.getElementById('btn-export-webm').onclick = async () => {
|
|
778
956
|
const svgEl = svgContainer.querySelector('svg');
|
|
779
957
|
if (!svgEl || typeof MediaRecorder === 'undefined') {
|
|
@@ -821,7 +999,6 @@ export function buildStudioHtml(opts) {
|
|
|
821
999
|
img.src = url;
|
|
822
1000
|
};
|
|
823
1001
|
|
|
824
|
-
// Save to disk (when opened with --file)
|
|
825
1002
|
async function saveToDisk() {
|
|
826
1003
|
if (!BOOT.canSaveToDisk) return;
|
|
827
1004
|
const res = await fetch('/api/save', {
|
|
@@ -844,7 +1021,6 @@ export function buildStudioHtml(opts) {
|
|
|
844
1021
|
}
|
|
845
1022
|
});
|
|
846
1023
|
|
|
847
|
-
// Initial render
|
|
848
1024
|
renderNow();
|
|
849
1025
|
</script>
|
|
850
1026
|
</body>
|
package/dist/studio.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import fs from "node:fs";
|
|
2
2
|
import http from "node:http";
|
|
3
3
|
import path from "node:path";
|
|
4
|
+
import { convertMermaidToWirepulse } from "./mermaid.js";
|
|
4
5
|
import { parseDiagram, updateNodeGridInSource } from "./parser.js";
|
|
5
6
|
import { renderSvg } from "./renderer.js";
|
|
6
7
|
import { buildStudioHtml } from "./studio-html.js";
|
|
@@ -112,6 +113,20 @@ export function startStudioServer(opts) {
|
|
|
112
113
|
}
|
|
113
114
|
return;
|
|
114
115
|
}
|
|
116
|
+
if (req.method === "POST" && reqUrl.pathname === "/api/import-mermaid") {
|
|
117
|
+
try {
|
|
118
|
+
const body = await readJsonBody(req);
|
|
119
|
+
const mermaid = typeof body.mermaid === "string" ? body.mermaid : "";
|
|
120
|
+
const converted = convertMermaidToWirepulse(mermaid);
|
|
121
|
+
res.writeHead(200, { "Content-Type": "application/json" });
|
|
122
|
+
res.end(JSON.stringify({ source: converted }));
|
|
123
|
+
}
|
|
124
|
+
catch (err) {
|
|
125
|
+
res.writeHead(400, { "Content-Type": "application/json" });
|
|
126
|
+
res.end(JSON.stringify({ error: err instanceof Error ? err.message : String(err) }));
|
|
127
|
+
}
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
115
130
|
if (req.method === "POST" && reqUrl.pathname === "/api/save") {
|
|
116
131
|
if (!resolvedFile) {
|
|
117
132
|
res.writeHead(400, { "Content-Type": "application/json" });
|
package/dist/validator.js
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
*/
|
|
9
9
|
export function validateSvg(svg) {
|
|
10
10
|
const issues = [];
|
|
11
|
-
const bytes =
|
|
11
|
+
const bytes = new TextEncoder().encode(svg).length;
|
|
12
12
|
const trimmed = svg.trim();
|
|
13
13
|
if (!trimmed.startsWith("<svg") || !trimmed.endsWith("</svg>")) {
|
|
14
14
|
issues.push({
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "wirepulse",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Zero-dependency Diagram-as-Code compiler and local Visual Studio for pure zero-JS animated architecture SVGs that work natively in GitHub READMEs.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"svg",
|
|
@@ -47,9 +47,10 @@
|
|
|
47
47
|
},
|
|
48
48
|
"scripts": {
|
|
49
49
|
"build": "tsc",
|
|
50
|
+
"build:pages": "npm run build && node scripts/build-pages.mjs",
|
|
50
51
|
"lint": "tsc --noEmit",
|
|
51
52
|
"test": "npm run build && npm run test:unit",
|
|
52
|
-
"test:unit": "tsc -p tsconfig.test.json && node
|
|
53
|
+
"test:unit": "tsc -p tsconfig.test.json && node scripts/run-tests.mjs",
|
|
53
54
|
"clean": "node -e \"import('node:fs').then(fs=>{fs.rmSync('dist',{recursive:true,force:true});fs.rmSync('dist-test',{recursive:true,force:true});})\"",
|
|
54
55
|
"prepublishOnly": "npm run clean && npm run build && npm run test:unit"
|
|
55
56
|
},
|