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 +20 -0
- package/LICENSE +21 -0
- package/README.md +183 -2
- package/dist/browser-core.d.ts +8 -0
- package/dist/browser-core.js +8 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +285 -0
- package/dist/icons.d.ts +7 -0
- package/dist/icons.js +41 -0
- package/dist/index.d.ts +23 -0
- package/dist/index.js +29 -0
- package/dist/layout.d.ts +6 -0
- package/dist/layout.js +387 -0
- package/dist/mermaid.d.ts +11 -0
- package/dist/mermaid.js +278 -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 +10 -0
- package/dist/studio-html.js +1028 -0
- package/dist/studio.d.ts +14 -0
- package/dist/studio.js +170 -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 +59 -4
|
@@ -0,0 +1,1028 @@
|
|
|
1
|
+
import { ICON_NAMES } from "./icons.js";
|
|
2
|
+
import { TEMPLATES } from "./templates.js";
|
|
3
|
+
import { THEME_NAMES } from "./themes.js";
|
|
4
|
+
function safeJsonForScript(data) {
|
|
5
|
+
return JSON.stringify(data).replace(/</g, "\\u003c").replace(/>/g, "\\u003e");
|
|
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`;
|
|
25
|
+
export function buildStudioHtml(opts) {
|
|
26
|
+
const mode = opts.mode ?? "server";
|
|
27
|
+
const moduleImportPath = opts.moduleImportPath ?? "./app/browser-core.js";
|
|
28
|
+
const bootstrap = safeJsonForScript({
|
|
29
|
+
mode,
|
|
30
|
+
initialSource: opts.initialSource,
|
|
31
|
+
fileName: opts.fileName ?? null,
|
|
32
|
+
canSaveToDisk: opts.canSaveToDisk,
|
|
33
|
+
version: opts.version,
|
|
34
|
+
templates: TEMPLATES,
|
|
35
|
+
themes: THEME_NAMES,
|
|
36
|
+
icons: ICON_NAMES,
|
|
37
|
+
sampleMermaid: SAMPLE_MERMAID,
|
|
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
|
+
}`;
|
|
99
|
+
return `<!DOCTYPE html>
|
|
100
|
+
<html lang="en">
|
|
101
|
+
<head>
|
|
102
|
+
<meta charset="UTF-8" />
|
|
103
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
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." />
|
|
106
|
+
<style>
|
|
107
|
+
:root {
|
|
108
|
+
--bg: #090c14;
|
|
109
|
+
--panel: #0f1422;
|
|
110
|
+
--panel-2: #151c2e;
|
|
111
|
+
--border: #232d45;
|
|
112
|
+
--text: #e2e8f0;
|
|
113
|
+
--muted: #94a3b8;
|
|
114
|
+
--accent: #22d3ee;
|
|
115
|
+
--accent-soft: rgba(34, 211, 238, 0.14);
|
|
116
|
+
--violet: #a78bfa;
|
|
117
|
+
--violet-soft: rgba(167, 139, 250, 0.15);
|
|
118
|
+
--emerald: #34d399;
|
|
119
|
+
--rose: #fb7185;
|
|
120
|
+
--amber: #fbbf24;
|
|
121
|
+
--mono: ui-monospace, SFMono-Regular, 'SF Mono', Menlo, Consolas, monospace;
|
|
122
|
+
--sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', Inter, Roboto, sans-serif;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
* { box-sizing: border-box; margin: 0; padding: 0; }
|
|
126
|
+
html, body { height: 100%; background: var(--bg); color: var(--text); font-family: var(--sans); overflow: hidden; }
|
|
127
|
+
|
|
128
|
+
.app {
|
|
129
|
+
display: grid;
|
|
130
|
+
grid-template-rows: 54px 1fr 32px;
|
|
131
|
+
height: 100vh;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/* Top Bar */
|
|
135
|
+
.topbar {
|
|
136
|
+
display: flex;
|
|
137
|
+
align-items: center;
|
|
138
|
+
justify-content: space-between;
|
|
139
|
+
padding: 0 14px;
|
|
140
|
+
background: var(--panel);
|
|
141
|
+
border-bottom: 1px solid var(--border);
|
|
142
|
+
gap: 10px;
|
|
143
|
+
z-index: 20;
|
|
144
|
+
overflow-x: auto;
|
|
145
|
+
}
|
|
146
|
+
.brand {
|
|
147
|
+
display: flex;
|
|
148
|
+
align-items: center;
|
|
149
|
+
gap: 8px;
|
|
150
|
+
font-weight: 700;
|
|
151
|
+
font-size: 15px;
|
|
152
|
+
letter-spacing: -0.02em;
|
|
153
|
+
white-space: nowrap;
|
|
154
|
+
text-decoration: none;
|
|
155
|
+
color: var(--text);
|
|
156
|
+
}
|
|
157
|
+
.brand-dot {
|
|
158
|
+
width: 9px;
|
|
159
|
+
height: 9px;
|
|
160
|
+
border-radius: 50%;
|
|
161
|
+
background: var(--accent);
|
|
162
|
+
box-shadow: 0 0 10px var(--accent);
|
|
163
|
+
animation: pulseDot 2s ease-in-out infinite;
|
|
164
|
+
}
|
|
165
|
+
@keyframes pulseDot {
|
|
166
|
+
0%, 100% { opacity: 1; transform: scale(1); }
|
|
167
|
+
50% { opacity: 0.45; transform: scale(0.85); }
|
|
168
|
+
}
|
|
169
|
+
.brand-tag {
|
|
170
|
+
font-family: var(--mono);
|
|
171
|
+
font-size: 10px;
|
|
172
|
+
color: var(--accent);
|
|
173
|
+
background: var(--accent-soft);
|
|
174
|
+
border: 1px solid rgba(34, 211, 238, 0.3);
|
|
175
|
+
padding: 2px 6px;
|
|
176
|
+
border-radius: 5px;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
.toolbar-group {
|
|
180
|
+
display: flex;
|
|
181
|
+
align-items: center;
|
|
182
|
+
gap: 7px;
|
|
183
|
+
flex-wrap: nowrap;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
select, button, a.btn-link {
|
|
187
|
+
font-family: var(--sans);
|
|
188
|
+
font-size: 12.5px;
|
|
189
|
+
color: var(--text);
|
|
190
|
+
background: var(--panel-2);
|
|
191
|
+
border: 1px solid var(--border);
|
|
192
|
+
border-radius: 7px;
|
|
193
|
+
padding: 6px 10px;
|
|
194
|
+
cursor: pointer;
|
|
195
|
+
transition: border-color 0.15s, background 0.15s, transform 0.1s;
|
|
196
|
+
white-space: nowrap;
|
|
197
|
+
text-decoration: none;
|
|
198
|
+
display: inline-flex;
|
|
199
|
+
align-items: center;
|
|
200
|
+
gap: 5px;
|
|
201
|
+
}
|
|
202
|
+
select:hover, button:hover, a.btn-link:hover {
|
|
203
|
+
border-color: #3b4b70;
|
|
204
|
+
background: #1b243a;
|
|
205
|
+
}
|
|
206
|
+
button:active { transform: translateY(0.5px); }
|
|
207
|
+
button.primary {
|
|
208
|
+
background: linear-gradient(135deg, #0891b2, #2563eb);
|
|
209
|
+
border-color: #38bdf8;
|
|
210
|
+
color: #ffffff;
|
|
211
|
+
font-weight: 600;
|
|
212
|
+
}
|
|
213
|
+
button.primary:hover {
|
|
214
|
+
background: linear-gradient(135deg, #06b6d4, #3b82f6);
|
|
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
|
+
}
|
|
236
|
+
button.active {
|
|
237
|
+
border-color: var(--accent);
|
|
238
|
+
color: var(--accent);
|
|
239
|
+
background: var(--accent-soft);
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
/* Main Split Workspace */
|
|
243
|
+
.workspace {
|
|
244
|
+
display: grid;
|
|
245
|
+
grid-template-columns: 430px 1fr;
|
|
246
|
+
min-height: 0;
|
|
247
|
+
overflow: hidden;
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
/* Left Editor Pane */
|
|
251
|
+
.editor-pane {
|
|
252
|
+
display: flex;
|
|
253
|
+
flex-direction: column;
|
|
254
|
+
background: var(--panel);
|
|
255
|
+
border-right: 1px solid var(--border);
|
|
256
|
+
min-height: 0;
|
|
257
|
+
}
|
|
258
|
+
.pane-header {
|
|
259
|
+
display: flex;
|
|
260
|
+
align-items: center;
|
|
261
|
+
justify-content: space-between;
|
|
262
|
+
padding: 8px 12px;
|
|
263
|
+
border-bottom: 1px solid var(--border);
|
|
264
|
+
font-size: 11.5px;
|
|
265
|
+
color: var(--muted);
|
|
266
|
+
gap: 8px;
|
|
267
|
+
}
|
|
268
|
+
.quick-bar {
|
|
269
|
+
display: flex;
|
|
270
|
+
gap: 6px;
|
|
271
|
+
flex-wrap: wrap;
|
|
272
|
+
}
|
|
273
|
+
.quick-btn {
|
|
274
|
+
font-family: var(--mono);
|
|
275
|
+
font-size: 11px;
|
|
276
|
+
padding: 3px 8px;
|
|
277
|
+
border-radius: 5px;
|
|
278
|
+
background: #131a2c;
|
|
279
|
+
color: #cbd5e1;
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
textarea#dsl-editor {
|
|
283
|
+
flex: 1;
|
|
284
|
+
width: 100%;
|
|
285
|
+
resize: none;
|
|
286
|
+
border: none;
|
|
287
|
+
outline: none;
|
|
288
|
+
padding: 14px;
|
|
289
|
+
background: #0b0f1a;
|
|
290
|
+
color: #e2e8f0;
|
|
291
|
+
font-family: var(--mono);
|
|
292
|
+
font-size: 12.5px;
|
|
293
|
+
line-height: 1.62;
|
|
294
|
+
tab-size: 2;
|
|
295
|
+
white-space: pre;
|
|
296
|
+
overflow: auto;
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
.errors-panel {
|
|
300
|
+
max-height: 110px;
|
|
301
|
+
overflow-y: auto;
|
|
302
|
+
background: rgba(251, 113, 133, 0.10);
|
|
303
|
+
border-top: 1px solid rgba(251, 113, 133, 0.35);
|
|
304
|
+
padding: 8px 12px;
|
|
305
|
+
font-family: var(--mono);
|
|
306
|
+
font-size: 11.5px;
|
|
307
|
+
color: #fda4af;
|
|
308
|
+
display: none;
|
|
309
|
+
}
|
|
310
|
+
.errors-panel.visible { display: block; }
|
|
311
|
+
|
|
312
|
+
/* Right Preview Canvas Pane */
|
|
313
|
+
.preview-pane {
|
|
314
|
+
display: flex;
|
|
315
|
+
flex-direction: column;
|
|
316
|
+
min-height: 0;
|
|
317
|
+
background: #070a12;
|
|
318
|
+
position: relative;
|
|
319
|
+
}
|
|
320
|
+
.preview-controls {
|
|
321
|
+
display: flex;
|
|
322
|
+
align-items: center;
|
|
323
|
+
justify-content: space-between;
|
|
324
|
+
padding: 8px 14px;
|
|
325
|
+
background: var(--panel);
|
|
326
|
+
border-bottom: 1px solid var(--border);
|
|
327
|
+
gap: 10px;
|
|
328
|
+
flex-wrap: wrap;
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
.canvas-stage {
|
|
332
|
+
flex: 1;
|
|
333
|
+
overflow: auto;
|
|
334
|
+
display: flex;
|
|
335
|
+
align-items: center;
|
|
336
|
+
justify-content: center;
|
|
337
|
+
padding: 28px;
|
|
338
|
+
transition: background 0.2s ease;
|
|
339
|
+
background: #0d1117;
|
|
340
|
+
}
|
|
341
|
+
.canvas-stage.gh-light {
|
|
342
|
+
background: #ffffff;
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
.readme-card {
|
|
346
|
+
border-radius: 12px;
|
|
347
|
+
padding: 16px;
|
|
348
|
+
transition: background 0.2s, border-color 0.2s;
|
|
349
|
+
border: 1px solid #30363d;
|
|
350
|
+
background: #0d1117;
|
|
351
|
+
max-width: 100%;
|
|
352
|
+
}
|
|
353
|
+
.canvas-stage.gh-light .readme-card {
|
|
354
|
+
border-color: #d0d7de;
|
|
355
|
+
background: #ffffff;
|
|
356
|
+
}
|
|
357
|
+
.readme-label {
|
|
358
|
+
font-family: var(--mono);
|
|
359
|
+
font-size: 11px;
|
|
360
|
+
color: #8b949e;
|
|
361
|
+
margin-bottom: 10px;
|
|
362
|
+
display: flex;
|
|
363
|
+
align-items: center;
|
|
364
|
+
justify-content: space-between;
|
|
365
|
+
}
|
|
366
|
+
.canvas-stage.gh-light .readme-label { color: #57606a; }
|
|
367
|
+
|
|
368
|
+
#svg-container {
|
|
369
|
+
transform-origin: center center;
|
|
370
|
+
transition: transform 0.15s ease;
|
|
371
|
+
user-select: none;
|
|
372
|
+
}
|
|
373
|
+
#svg-container svg {
|
|
374
|
+
display: block;
|
|
375
|
+
max-width: 100%;
|
|
376
|
+
height: auto;
|
|
377
|
+
}
|
|
378
|
+
#svg-container g.wp-node { cursor: grab; }
|
|
379
|
+
#svg-container g.wp-node:active { cursor: grabbing; }
|
|
380
|
+
#svg-container g.wp-node:hover .wp-node-card {
|
|
381
|
+
stroke: var(--accent);
|
|
382
|
+
stroke-width: 1.75;
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
/* Icon Reference Drawer */
|
|
386
|
+
.icon-drawer {
|
|
387
|
+
display: none;
|
|
388
|
+
position: absolute;
|
|
389
|
+
top: 48px;
|
|
390
|
+
left: 14px;
|
|
391
|
+
right: 14px;
|
|
392
|
+
max-height: 220px;
|
|
393
|
+
overflow-y: auto;
|
|
394
|
+
background: var(--panel);
|
|
395
|
+
border: 1px solid var(--border);
|
|
396
|
+
border-radius: 10px;
|
|
397
|
+
padding: 12px;
|
|
398
|
+
z-index: 30;
|
|
399
|
+
box-shadow: 0 18px 40px rgba(0,0,0,0.6);
|
|
400
|
+
}
|
|
401
|
+
.icon-drawer.open { display: block; }
|
|
402
|
+
.icon-grid {
|
|
403
|
+
display: flex;
|
|
404
|
+
flex-wrap: wrap;
|
|
405
|
+
gap: 6px;
|
|
406
|
+
margin-top: 8px;
|
|
407
|
+
}
|
|
408
|
+
.icon-chip {
|
|
409
|
+
font-family: var(--mono);
|
|
410
|
+
font-size: 11px;
|
|
411
|
+
padding: 4px 8px;
|
|
412
|
+
background: var(--panel-2);
|
|
413
|
+
border: 1px solid var(--border);
|
|
414
|
+
border-radius: 6px;
|
|
415
|
+
cursor: pointer;
|
|
416
|
+
}
|
|
417
|
+
.icon-chip:hover { border-color: var(--accent); color: var(--accent); }
|
|
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
|
+
|
|
467
|
+
/* Status Bar */
|
|
468
|
+
.statusbar {
|
|
469
|
+
display: flex;
|
|
470
|
+
align-items: center;
|
|
471
|
+
justify-content: space-between;
|
|
472
|
+
padding: 0 14px;
|
|
473
|
+
background: var(--panel);
|
|
474
|
+
border-top: 1px solid var(--border);
|
|
475
|
+
font-family: var(--mono);
|
|
476
|
+
font-size: 11px;
|
|
477
|
+
color: var(--muted);
|
|
478
|
+
}
|
|
479
|
+
.status-items { display: flex; align-items: center; gap: 14px; }
|
|
480
|
+
.badge-ok { color: var(--emerald); }
|
|
481
|
+
.badge-err { color: var(--rose); }
|
|
482
|
+
|
|
483
|
+
/* Toast */
|
|
484
|
+
.toast {
|
|
485
|
+
position: fixed;
|
|
486
|
+
bottom: 44px;
|
|
487
|
+
right: 20px;
|
|
488
|
+
background: #111827;
|
|
489
|
+
border: 1px solid var(--accent);
|
|
490
|
+
color: #f8fafc;
|
|
491
|
+
padding: 10px 14px;
|
|
492
|
+
border-radius: 8px;
|
|
493
|
+
font-size: 12.5px;
|
|
494
|
+
box-shadow: 0 12px 30px rgba(0,0,0,0.5);
|
|
495
|
+
opacity: 0;
|
|
496
|
+
pointer-events: none;
|
|
497
|
+
transform: translateY(8px);
|
|
498
|
+
transition: opacity 0.2s, transform 0.2s;
|
|
499
|
+
z-index: 100;
|
|
500
|
+
}
|
|
501
|
+
.toast.show { opacity: 1; transform: translateY(0); }
|
|
502
|
+
|
|
503
|
+
@media (max-width: 960px) {
|
|
504
|
+
.workspace { grid-template-columns: 1fr; grid-template-rows: 42% 58%; }
|
|
505
|
+
.editor-pane { border-right: none; border-bottom: 1px solid var(--border); }
|
|
506
|
+
}
|
|
507
|
+
</style>
|
|
508
|
+
</head>
|
|
509
|
+
<body>
|
|
510
|
+
<div class="app">
|
|
511
|
+
<header class="topbar">
|
|
512
|
+
<a class="brand" href="https://github.com/Rynia/wirepulse" target="_blank" rel="noopener">
|
|
513
|
+
<span class="brand-dot"></span>
|
|
514
|
+
<span>wirepulse</span>
|
|
515
|
+
<span class="brand-tag" id="version-tag">studio</span>
|
|
516
|
+
</a>
|
|
517
|
+
|
|
518
|
+
<div class="toolbar-group">
|
|
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>
|
|
521
|
+
<select id="theme-select" title="Override diagram theme"></select>
|
|
522
|
+
<button id="btn-play" title="Pause or resume SVG animations">⏸ Pause</button>
|
|
523
|
+
<select id="speed-select" title="Animation speed multiplier">
|
|
524
|
+
<option value="0.5">0.5x</option>
|
|
525
|
+
<option value="1" selected>1.0x</option>
|
|
526
|
+
<option value="1.5">1.5x</option>
|
|
527
|
+
<option value="2">2.0x</option>
|
|
528
|
+
</select>
|
|
529
|
+
</div>
|
|
530
|
+
|
|
531
|
+
<div class="toolbar-group">
|
|
532
|
+
<button id="btn-save" style="display:none;" title="Save to disk (Ctrl+S)">💾 Save</button>
|
|
533
|
+
<button id="btn-copy-md" title="Copy GitHub README Light+Dark Markdown snippet">Copy README</button>
|
|
534
|
+
<button id="btn-export-png" title="Export crisp 2x Retina PNG">PNG</button>
|
|
535
|
+
<button id="btn-export-webm" title="Record 3.5s animated WebM video">WebM</button>
|
|
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>
|
|
538
|
+
</div>
|
|
539
|
+
</header>
|
|
540
|
+
|
|
541
|
+
<main class="workspace">
|
|
542
|
+
<section class="editor-pane">
|
|
543
|
+
<div class="pane-header">
|
|
544
|
+
<span id="editor-filename">diagram.wp</span>
|
|
545
|
+
<div class="quick-bar">
|
|
546
|
+
<button class="quick-btn" id="btn-add-node">+ Node</button>
|
|
547
|
+
<button class="quick-btn" id="btn-add-edge">+ Edge</button>
|
|
548
|
+
<button class="quick-btn" id="btn-add-group">+ Group</button>
|
|
549
|
+
<button class="quick-btn" id="btn-icons">Icons</button>
|
|
550
|
+
</div>
|
|
551
|
+
</div>
|
|
552
|
+
<textarea id="dsl-editor" spellcheck="false" aria-label="Wirepulse Diagram DSL Editor"></textarea>
|
|
553
|
+
<div id="errors-panel" class="errors-panel"></div>
|
|
554
|
+
</section>
|
|
555
|
+
|
|
556
|
+
<section class="preview-pane">
|
|
557
|
+
<div class="preview-controls">
|
|
558
|
+
<div class="toolbar-group">
|
|
559
|
+
<button id="btn-gh-dark" class="active">GitHub Dark</button>
|
|
560
|
+
<button id="btn-gh-light">GitHub Light</button>
|
|
561
|
+
<button id="btn-share">Share URL</button>
|
|
562
|
+
</div>
|
|
563
|
+
<div class="toolbar-group">
|
|
564
|
+
<button id="btn-zoom-out">−</button>
|
|
565
|
+
<span id="zoom-label" style="font-family: var(--mono); font-size: 11.5px; color: var(--muted); min-width: 42px; text-align: center;">100%</span>
|
|
566
|
+
<button id="btn-zoom-in">+</button>
|
|
567
|
+
<button id="btn-zoom-reset">Fit</button>
|
|
568
|
+
</div>
|
|
569
|
+
</div>
|
|
570
|
+
|
|
571
|
+
<div id="icon-drawer" class="icon-drawer">
|
|
572
|
+
<div style="display:flex; justify-content:space-between; align-items:center;">
|
|
573
|
+
<strong style="font-size:12px;">Built-in Inline Vector Icons (click to copy)</strong>
|
|
574
|
+
<button class="quick-btn" id="btn-close-icons">Close</button>
|
|
575
|
+
</div>
|
|
576
|
+
<div id="icon-grid" class="icon-grid"></div>
|
|
577
|
+
</div>
|
|
578
|
+
|
|
579
|
+
<div id="canvas-stage" class="canvas-stage">
|
|
580
|
+
<div class="readme-card">
|
|
581
|
+
<div class="readme-label">
|
|
582
|
+
<span>README.md preview</span>
|
|
583
|
+
<span id="preview-hint">Drag any node to snap to grid</span>
|
|
584
|
+
</div>
|
|
585
|
+
<div id="svg-container"></div>
|
|
586
|
+
</div>
|
|
587
|
+
</div>
|
|
588
|
+
</section>
|
|
589
|
+
</main>
|
|
590
|
+
|
|
591
|
+
<footer class="statusbar">
|
|
592
|
+
<div class="status-items">
|
|
593
|
+
<span id="csp-status" class="badge-ok">✔ GitHub CSP Safe (0 scripts)</span>
|
|
594
|
+
<span id="size-status">0.0 KB</span>
|
|
595
|
+
<span id="counts-status">0 nodes · 0 edges</span>
|
|
596
|
+
</div>
|
|
597
|
+
<div>wirepulse · 100% client-side · zero-JS SVG</div>
|
|
598
|
+
</footer>
|
|
599
|
+
</div>
|
|
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
|
+
|
|
614
|
+
<div id="toast" class="toast"></div>
|
|
615
|
+
|
|
616
|
+
<script type="module">
|
|
617
|
+
const BOOT = ${bootstrap};
|
|
618
|
+
${engineSetupCode}
|
|
619
|
+
|
|
620
|
+
const editor = document.getElementById('dsl-editor');
|
|
621
|
+
const svgContainer = document.getElementById('svg-container');
|
|
622
|
+
const errorsPanel = document.getElementById('errors-panel');
|
|
623
|
+
const templateSelect = document.getElementById('template-select');
|
|
624
|
+
const themeSelect = document.getElementById('theme-select');
|
|
625
|
+
const speedSelect = document.getElementById('speed-select');
|
|
626
|
+
const canvasStage = document.getElementById('canvas-stage');
|
|
627
|
+
const cspStatus = document.getElementById('csp-status');
|
|
628
|
+
const sizeStatus = document.getElementById('size-status');
|
|
629
|
+
const countsStatus = document.getElementById('counts-status');
|
|
630
|
+
const zoomLabel = document.getElementById('zoom-label');
|
|
631
|
+
const toastEl = document.getElementById('toast');
|
|
632
|
+
const iconDrawer = document.getElementById('icon-drawer');
|
|
633
|
+
const iconGrid = document.getElementById('icon-grid');
|
|
634
|
+
const btnPlay = document.getElementById('btn-play');
|
|
635
|
+
const btnSave = document.getElementById('btn-save');
|
|
636
|
+
const btnGhDark = document.getElementById('btn-gh-dark');
|
|
637
|
+
const btnGhLight = document.getElementById('btn-gh-light');
|
|
638
|
+
const mermaidModal = document.getElementById('mermaid-modal');
|
|
639
|
+
const mermaidInput = document.getElementById('mermaid-input');
|
|
640
|
+
|
|
641
|
+
let currentSvg = '';
|
|
642
|
+
let isPaused = false;
|
|
643
|
+
let zoom = 1;
|
|
644
|
+
let renderTimer = null;
|
|
645
|
+
let ghPreviewMode = 'dark';
|
|
646
|
+
|
|
647
|
+
document.getElementById('version-tag').textContent = 'v' + BOOT.version;
|
|
648
|
+
if (BOOT.fileName) {
|
|
649
|
+
document.getElementById('editor-filename').textContent = BOOT.fileName;
|
|
650
|
+
}
|
|
651
|
+
if (BOOT.canSaveToDisk) {
|
|
652
|
+
btnSave.style.display = 'inline-flex';
|
|
653
|
+
}
|
|
654
|
+
mermaidInput.value = BOOT.sampleMermaid;
|
|
655
|
+
|
|
656
|
+
function showToast(msg) {
|
|
657
|
+
toastEl.textContent = msg;
|
|
658
|
+
toastEl.classList.add('show');
|
|
659
|
+
clearTimeout(toastEl._t);
|
|
660
|
+
toastEl._t = setTimeout(() => toastEl.classList.remove('show'), 2600);
|
|
661
|
+
}
|
|
662
|
+
|
|
663
|
+
// Populate Templates
|
|
664
|
+
const defaultOpt = document.createElement('option');
|
|
665
|
+
defaultOpt.value = '';
|
|
666
|
+
defaultOpt.textContent = 'Templates…';
|
|
667
|
+
templateSelect.appendChild(defaultOpt);
|
|
668
|
+
for (const tpl of BOOT.templates) {
|
|
669
|
+
const opt = document.createElement('option');
|
|
670
|
+
opt.value = tpl.id;
|
|
671
|
+
opt.textContent = tpl.name;
|
|
672
|
+
templateSelect.appendChild(opt);
|
|
673
|
+
}
|
|
674
|
+
|
|
675
|
+
// Populate Themes
|
|
676
|
+
const themeAuto = document.createElement('option');
|
|
677
|
+
themeAuto.value = '';
|
|
678
|
+
themeAuto.textContent = 'Theme: From DSL';
|
|
679
|
+
themeSelect.appendChild(themeAuto);
|
|
680
|
+
for (const th of BOOT.themes) {
|
|
681
|
+
const opt = document.createElement('option');
|
|
682
|
+
opt.value = th;
|
|
683
|
+
opt.textContent = 'Theme: ' + th;
|
|
684
|
+
themeSelect.appendChild(opt);
|
|
685
|
+
}
|
|
686
|
+
|
|
687
|
+
// Populate Icons Drawer
|
|
688
|
+
for (const iconName of BOOT.icons) {
|
|
689
|
+
const chip = document.createElement('button');
|
|
690
|
+
chip.className = 'icon-chip';
|
|
691
|
+
chip.textContent = iconName;
|
|
692
|
+
chip.onclick = () => {
|
|
693
|
+
navigator.clipboard?.writeText('icon=' + iconName);
|
|
694
|
+
showToast('Copied icon=' + iconName);
|
|
695
|
+
};
|
|
696
|
+
iconGrid.appendChild(chip);
|
|
697
|
+
}
|
|
698
|
+
|
|
699
|
+
function loadInitialSource() {
|
|
700
|
+
const hash = window.location.hash;
|
|
701
|
+
if (hash.startsWith('#wp=')) {
|
|
702
|
+
try {
|
|
703
|
+
const decoded = decodeURIComponent(escape(atob(hash.slice(4))));
|
|
704
|
+
if (decoded.trim()) return decoded;
|
|
705
|
+
} catch {}
|
|
706
|
+
}
|
|
707
|
+
return BOOT.initialSource;
|
|
708
|
+
}
|
|
709
|
+
editor.value = loadInitialSource();
|
|
710
|
+
|
|
711
|
+
async function renderNow() {
|
|
712
|
+
const payload = {
|
|
713
|
+
source: editor.value,
|
|
714
|
+
theme: themeSelect.value || undefined,
|
|
715
|
+
speedMultiplier: Number(speedSelect.value) || 1,
|
|
716
|
+
paused: isPaused,
|
|
717
|
+
previewMode: ghPreviewMode,
|
|
718
|
+
};
|
|
719
|
+
try {
|
|
720
|
+
const data = await apiRender(payload);
|
|
721
|
+
currentSvg = data.svg || '';
|
|
722
|
+
svgContainer.innerHTML = data.previewSvg || currentSvg;
|
|
723
|
+
attachNodeDragHandlers();
|
|
724
|
+
|
|
725
|
+
if (data.errors && data.errors.length > 0) {
|
|
726
|
+
errorsPanel.innerHTML = data.errors
|
|
727
|
+
.map((e) => 'Line ' + e.line + ': ' + e.message)
|
|
728
|
+
.join('<br/>');
|
|
729
|
+
errorsPanel.classList.add('visible');
|
|
730
|
+
} else {
|
|
731
|
+
errorsPanel.classList.remove('visible');
|
|
732
|
+
}
|
|
733
|
+
|
|
734
|
+
const val = data.validation;
|
|
735
|
+
if (val && val.githubSafe) {
|
|
736
|
+
cspStatus.textContent = '✔ GitHub CSP Safe (0 scripts)';
|
|
737
|
+
cspStatus.className = 'badge-ok';
|
|
738
|
+
} else {
|
|
739
|
+
cspStatus.textContent = '✖ CSP Issue Detected';
|
|
740
|
+
cspStatus.className = 'badge-err';
|
|
741
|
+
}
|
|
742
|
+
sizeStatus.textContent = ((val?.bytes || currentSvg.length) / 1024).toFixed(1) + ' KB';
|
|
743
|
+
countsStatus.textContent =
|
|
744
|
+
(data.nodeCount || 0) + ' nodes · ' + (data.edgeCount || 0) + ' edges';
|
|
745
|
+
} catch (err) {
|
|
746
|
+
showToast('Render error: ' + err.message);
|
|
747
|
+
}
|
|
748
|
+
}
|
|
749
|
+
|
|
750
|
+
function scheduleRender() {
|
|
751
|
+
clearTimeout(renderTimer);
|
|
752
|
+
renderTimer = setTimeout(renderNow, 90);
|
|
753
|
+
}
|
|
754
|
+
|
|
755
|
+
function attachNodeDragHandlers() {
|
|
756
|
+
const svgEl = svgContainer.querySelector('svg');
|
|
757
|
+
if (!svgEl) return;
|
|
758
|
+
const nodes = svgEl.querySelectorAll('g.wp-node');
|
|
759
|
+
|
|
760
|
+
nodes.forEach((g) => {
|
|
761
|
+
g.addEventListener('pointerdown', (ev) => {
|
|
762
|
+
ev.preventDefault();
|
|
763
|
+
const nodeId = g.getAttribute('data-node-id');
|
|
764
|
+
const origCol = Number(g.getAttribute('data-col') || 0);
|
|
765
|
+
const origRow = Number(g.getAttribute('data-row') || 0);
|
|
766
|
+
const startX = ev.clientX;
|
|
767
|
+
const startY = ev.clientY;
|
|
768
|
+
let dx = 0;
|
|
769
|
+
let dy = 0;
|
|
770
|
+
|
|
771
|
+
const onMove = (moveEv) => {
|
|
772
|
+
dx = (moveEv.clientX - startX) / zoom;
|
|
773
|
+
dy = (moveEv.clientY - startY) / zoom;
|
|
774
|
+
g.setAttribute('transform', 'translate(' + Math.round(dx) + ',' + Math.round(dy) + ')');
|
|
775
|
+
};
|
|
776
|
+
|
|
777
|
+
const onUp = async () => {
|
|
778
|
+
window.removeEventListener('pointermove', onMove);
|
|
779
|
+
window.removeEventListener('pointerup', onUp);
|
|
780
|
+
g.removeAttribute('transform');
|
|
781
|
+
|
|
782
|
+
if (Math.abs(dx) < 35 && Math.abs(dy) < 25) return;
|
|
783
|
+
|
|
784
|
+
const deltaCol = Math.round(dx / 316);
|
|
785
|
+
const deltaRow = Math.round(dy / 128);
|
|
786
|
+
if (deltaCol === 0 && deltaRow === 0) return;
|
|
787
|
+
|
|
788
|
+
const nextCol = Math.max(0, origCol + deltaCol);
|
|
789
|
+
const nextRow = Math.max(0, origRow + deltaRow);
|
|
790
|
+
|
|
791
|
+
const updated = await apiMoveNode({
|
|
792
|
+
source: editor.value,
|
|
793
|
+
nodeId,
|
|
794
|
+
col: nextCol,
|
|
795
|
+
row: nextRow,
|
|
796
|
+
});
|
|
797
|
+
if (updated.source) {
|
|
798
|
+
editor.value = updated.source;
|
|
799
|
+
showToast('Moved "' + nodeId + '" → col=' + nextCol + ' row=' + nextRow);
|
|
800
|
+
renderNow();
|
|
801
|
+
}
|
|
802
|
+
};
|
|
803
|
+
|
|
804
|
+
window.addEventListener('pointermove', onMove);
|
|
805
|
+
window.addEventListener('pointerup', onUp);
|
|
806
|
+
});
|
|
807
|
+
});
|
|
808
|
+
}
|
|
809
|
+
|
|
810
|
+
// Event listeners
|
|
811
|
+
editor.addEventListener('input', scheduleRender);
|
|
812
|
+
themeSelect.addEventListener('change', renderNow);
|
|
813
|
+
speedSelect.addEventListener('change', renderNow);
|
|
814
|
+
|
|
815
|
+
templateSelect.addEventListener('change', () => {
|
|
816
|
+
const tpl = BOOT.templates.find((t) => t.id === templateSelect.value);
|
|
817
|
+
if (tpl) {
|
|
818
|
+
editor.value = tpl.source;
|
|
819
|
+
themeSelect.value = '';
|
|
820
|
+
renderNow();
|
|
821
|
+
showToast('Loaded template: ' + tpl.name);
|
|
822
|
+
}
|
|
823
|
+
templateSelect.value = '';
|
|
824
|
+
});
|
|
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
|
+
|
|
850
|
+
btnPlay.addEventListener('click', () => {
|
|
851
|
+
isPaused = !isPaused;
|
|
852
|
+
btnPlay.textContent = isPaused ? '▶ Play' : '⏸ Pause';
|
|
853
|
+
btnPlay.classList.toggle('active', isPaused);
|
|
854
|
+
renderNow();
|
|
855
|
+
});
|
|
856
|
+
|
|
857
|
+
btnGhDark.addEventListener('click', () => {
|
|
858
|
+
ghPreviewMode = 'dark';
|
|
859
|
+
canvasStage.classList.remove('gh-light');
|
|
860
|
+
btnGhDark.classList.add('active');
|
|
861
|
+
btnGhLight.classList.remove('active');
|
|
862
|
+
renderNow();
|
|
863
|
+
});
|
|
864
|
+
|
|
865
|
+
btnGhLight.addEventListener('click', () => {
|
|
866
|
+
ghPreviewMode = 'light';
|
|
867
|
+
canvasStage.classList.add('gh-light');
|
|
868
|
+
btnGhLight.classList.add('active');
|
|
869
|
+
btnGhDark.classList.remove('active');
|
|
870
|
+
renderNow();
|
|
871
|
+
});
|
|
872
|
+
|
|
873
|
+
function applyZoom() {
|
|
874
|
+
svgContainer.style.transform = 'scale(' + zoom.toFixed(2) + ')';
|
|
875
|
+
zoomLabel.textContent = Math.round(zoom * 100) + '%';
|
|
876
|
+
}
|
|
877
|
+
document.getElementById('btn-zoom-in').onclick = () => { zoom = Math.min(2, zoom + 0.15); applyZoom(); };
|
|
878
|
+
document.getElementById('btn-zoom-out').onclick = () => { zoom = Math.max(0.4, zoom - 0.15); applyZoom(); };
|
|
879
|
+
document.getElementById('btn-zoom-reset').onclick = () => { zoom = 1; applyZoom(); };
|
|
880
|
+
|
|
881
|
+
let quickCounter = 1;
|
|
882
|
+
document.getElementById('btn-add-node').onclick = () => {
|
|
883
|
+
const id = 'svc' + quickCounter++;
|
|
884
|
+
editor.value = editor.value.trimEnd() + '\\nnode ' + id + ' "New Service" sub="Worker" icon=server color=cyan\\n';
|
|
885
|
+
renderNow();
|
|
886
|
+
};
|
|
887
|
+
document.getElementById('btn-add-edge').onclick = () => {
|
|
888
|
+
editor.value = editor.value.trimEnd() + '\\nnodeA -> nodeB "request" flow=packet color=violet\\n';
|
|
889
|
+
renderNow();
|
|
890
|
+
};
|
|
891
|
+
document.getElementById('btn-add-group').onclick = () => {
|
|
892
|
+
editor.value = editor.value.trimEnd() + '\\ngroup cluster1 "Cluster" color=emerald\\n';
|
|
893
|
+
renderNow();
|
|
894
|
+
};
|
|
895
|
+
document.getElementById('btn-icons').onclick = () => iconDrawer.classList.toggle('open');
|
|
896
|
+
document.getElementById('btn-close-icons').onclick = () => iconDrawer.classList.remove('open');
|
|
897
|
+
|
|
898
|
+
document.getElementById('btn-share').onclick = () => {
|
|
899
|
+
const encoded = btoa(unescape(encodeURIComponent(editor.value)));
|
|
900
|
+
const url = window.location.origin + window.location.pathname + '#wp=' + encoded;
|
|
901
|
+
window.history.replaceState(null, '', '#wp=' + encoded);
|
|
902
|
+
navigator.clipboard?.writeText(url);
|
|
903
|
+
showToast('Shareable URL copied to clipboard!');
|
|
904
|
+
};
|
|
905
|
+
|
|
906
|
+
document.getElementById('btn-export-svg').onclick = () => {
|
|
907
|
+
if (!currentSvg) return;
|
|
908
|
+
const blob = new Blob([currentSvg], { type: 'image/svg+xml;charset=utf-8' });
|
|
909
|
+
const a = document.createElement('a');
|
|
910
|
+
a.href = URL.createObjectURL(blob);
|
|
911
|
+
a.download = 'architecture.svg';
|
|
912
|
+
a.click();
|
|
913
|
+
URL.revokeObjectURL(a.href);
|
|
914
|
+
showToast('Downloaded pure zero-JS architecture.svg!');
|
|
915
|
+
};
|
|
916
|
+
|
|
917
|
+
document.getElementById('btn-copy-md').onclick = () => {
|
|
918
|
+
const snippet = [
|
|
919
|
+
'<picture>',
|
|
920
|
+
' <source media="(prefers-color-scheme: dark)" srcset="./docs/architecture-dark.svg" />',
|
|
921
|
+
' <source media="(prefers-color-scheme: light)" srcset="./docs/architecture-light.svg" />',
|
|
922
|
+
' <img alt="Architecture Diagram" src="./docs/architecture.svg" />',
|
|
923
|
+
'</picture>',
|
|
924
|
+
].join('\\n');
|
|
925
|
+
navigator.clipboard?.writeText(snippet);
|
|
926
|
+
showToast('Copied GitHub README <picture> snippet!');
|
|
927
|
+
};
|
|
928
|
+
|
|
929
|
+
document.getElementById('btn-export-png').onclick = async () => {
|
|
930
|
+
if (!currentSvg) return;
|
|
931
|
+
const svgEl = svgContainer.querySelector('svg');
|
|
932
|
+
const w = Number(svgEl?.getAttribute('width') || 900);
|
|
933
|
+
const h = Number(svgEl?.getAttribute('height') || 450);
|
|
934
|
+
const scale = 2;
|
|
935
|
+
const canvas = document.createElement('canvas');
|
|
936
|
+
canvas.width = w * scale;
|
|
937
|
+
canvas.height = h * scale;
|
|
938
|
+
const ctx = canvas.getContext('2d');
|
|
939
|
+
const img = new Image();
|
|
940
|
+
const blob = new Blob([svgEl.outerHTML], { type: 'image/svg+xml;charset=utf-8' });
|
|
941
|
+
const url = URL.createObjectURL(blob);
|
|
942
|
+
img.onload = () => {
|
|
943
|
+
ctx.scale(scale, scale);
|
|
944
|
+
ctx.drawImage(img, 0, 0, w, h);
|
|
945
|
+
URL.revokeObjectURL(url);
|
|
946
|
+
const a = document.createElement('a');
|
|
947
|
+
a.href = canvas.toDataURL('image/png');
|
|
948
|
+
a.download = 'architecture-2x.png';
|
|
949
|
+
a.click();
|
|
950
|
+
showToast('Exported 2x Retina PNG!');
|
|
951
|
+
};
|
|
952
|
+
img.src = url;
|
|
953
|
+
};
|
|
954
|
+
|
|
955
|
+
document.getElementById('btn-export-webm').onclick = async () => {
|
|
956
|
+
const svgEl = svgContainer.querySelector('svg');
|
|
957
|
+
if (!svgEl || typeof MediaRecorder === 'undefined') {
|
|
958
|
+
showToast('WebM recording is not supported in this browser.');
|
|
959
|
+
return;
|
|
960
|
+
}
|
|
961
|
+
showToast('Recording 3.5s animated WebM…');
|
|
962
|
+
const w = Number(svgEl.getAttribute('width') || 900);
|
|
963
|
+
const h = Number(svgEl.getAttribute('height') || 450);
|
|
964
|
+
const canvas = document.createElement('canvas');
|
|
965
|
+
canvas.width = w;
|
|
966
|
+
canvas.height = h;
|
|
967
|
+
const ctx = canvas.getContext('2d');
|
|
968
|
+
const stream = canvas.captureStream(30);
|
|
969
|
+
const recorder = new MediaRecorder(stream, { mimeType: 'video/webm' });
|
|
970
|
+
const chunks = [];
|
|
971
|
+
recorder.ondataavailable = (e) => { if (e.data.size > 0) chunks.push(e.data); };
|
|
972
|
+
recorder.onstop = () => {
|
|
973
|
+
const outBlob = new Blob(chunks, { type: 'video/webm' });
|
|
974
|
+
const a = document.createElement('a');
|
|
975
|
+
a.href = URL.createObjectURL(outBlob);
|
|
976
|
+
a.download = 'architecture.webm';
|
|
977
|
+
a.click();
|
|
978
|
+
showToast('Exported animated architecture.webm!');
|
|
979
|
+
};
|
|
980
|
+
|
|
981
|
+
const blob = new Blob([svgEl.outerHTML], { type: 'image/svg+xml;charset=utf-8' });
|
|
982
|
+
const url = URL.createObjectURL(blob);
|
|
983
|
+
const img = new Image();
|
|
984
|
+
img.onload = () => {
|
|
985
|
+
recorder.start();
|
|
986
|
+
const start = performance.now();
|
|
987
|
+
function frame(now) {
|
|
988
|
+
ctx.clearRect(0, 0, w, h);
|
|
989
|
+
ctx.drawImage(img, 0, 0, w, h);
|
|
990
|
+
if (now - start < 3500) {
|
|
991
|
+
requestAnimationFrame(frame);
|
|
992
|
+
} else {
|
|
993
|
+
recorder.stop();
|
|
994
|
+
URL.revokeObjectURL(url);
|
|
995
|
+
}
|
|
996
|
+
}
|
|
997
|
+
requestAnimationFrame(frame);
|
|
998
|
+
};
|
|
999
|
+
img.src = url;
|
|
1000
|
+
};
|
|
1001
|
+
|
|
1002
|
+
async function saveToDisk() {
|
|
1003
|
+
if (!BOOT.canSaveToDisk) return;
|
|
1004
|
+
const res = await fetch('/api/save', {
|
|
1005
|
+
method: 'POST',
|
|
1006
|
+
headers: { 'Content-Type': 'application/json' },
|
|
1007
|
+
body: JSON.stringify({ source: editor.value, svg: currentSvg }),
|
|
1008
|
+
});
|
|
1009
|
+
if (res.ok) {
|
|
1010
|
+
showToast('Saved ' + (BOOT.fileName || 'file') + ' to disk!');
|
|
1011
|
+
} else {
|
|
1012
|
+
showToast('Failed to save file.');
|
|
1013
|
+
}
|
|
1014
|
+
}
|
|
1015
|
+
btnSave.addEventListener('click', saveToDisk);
|
|
1016
|
+
window.addEventListener('keydown', (e) => {
|
|
1017
|
+
if ((e.ctrlKey || e.metaKey) && e.key.toLowerCase() === 's') {
|
|
1018
|
+
e.preventDefault();
|
|
1019
|
+
if (BOOT.canSaveToDisk) saveToDisk();
|
|
1020
|
+
else document.getElementById('btn-export-svg').click();
|
|
1021
|
+
}
|
|
1022
|
+
});
|
|
1023
|
+
|
|
1024
|
+
renderNow();
|
|
1025
|
+
</script>
|
|
1026
|
+
</body>
|
|
1027
|
+
</html>`;
|
|
1028
|
+
}
|