wirepulse 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +13 -0
- package/LICENSE +21 -0
- package/README.md +163 -2
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +263 -0
- package/dist/icons.d.ts +7 -0
- package/dist/icons.js +41 -0
- package/dist/index.d.ts +21 -0
- package/dist/index.js +23 -0
- package/dist/layout.d.ts +6 -0
- package/dist/layout.js +387 -0
- package/dist/parser.d.ts +10 -0
- package/dist/parser.js +401 -0
- package/dist/renderer.d.ts +6 -0
- package/dist/renderer.js +330 -0
- package/dist/studio-html.d.ts +7 -0
- package/dist/studio-html.js +852 -0
- package/dist/studio.d.ts +14 -0
- package/dist/studio.js +155 -0
- package/dist/templates.d.ts +8 -0
- package/dist/templates.js +167 -0
- package/dist/themes.d.ts +47 -0
- package/dist/themes.js +208 -0
- package/dist/types.d.ts +109 -0
- package/dist/types.js +1 -0
- package/dist/validator.d.ts +10 -0
- package/dist/validator.js +84 -0
- package/package.json +58 -4
|
@@ -0,0 +1,852 @@
|
|
|
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
|
+
export function buildStudioHtml(opts) {
|
|
8
|
+
const bootstrap = safeJsonForScript({
|
|
9
|
+
initialSource: opts.initialSource,
|
|
10
|
+
fileName: opts.fileName ?? null,
|
|
11
|
+
canSaveToDisk: opts.canSaveToDisk,
|
|
12
|
+
version: opts.version,
|
|
13
|
+
templates: TEMPLATES,
|
|
14
|
+
themes: THEME_NAMES,
|
|
15
|
+
icons: ICON_NAMES,
|
|
16
|
+
});
|
|
17
|
+
return `<!DOCTYPE html>
|
|
18
|
+
<html lang="en">
|
|
19
|
+
<head>
|
|
20
|
+
<meta charset="UTF-8" />
|
|
21
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
22
|
+
<title>wirepulse studio — Animated Architecture SVGs for GitHub READMEs</title>
|
|
23
|
+
<style>
|
|
24
|
+
:root {
|
|
25
|
+
--bg: #090c14;
|
|
26
|
+
--panel: #0f1422;
|
|
27
|
+
--panel-2: #151c2e;
|
|
28
|
+
--border: #232d45;
|
|
29
|
+
--text: #e2e8f0;
|
|
30
|
+
--muted: #94a3b8;
|
|
31
|
+
--accent: #22d3ee;
|
|
32
|
+
--accent-soft: rgba(34, 211, 238, 0.14);
|
|
33
|
+
--emerald: #34d399;
|
|
34
|
+
--rose: #fb7185;
|
|
35
|
+
--amber: #fbbf24;
|
|
36
|
+
--mono: ui-monospace, SFMono-Regular, 'SF Mono', Menlo, Consolas, monospace;
|
|
37
|
+
--sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', Inter, Roboto, sans-serif;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
* { box-sizing: border-box; margin: 0; padding: 0; }
|
|
41
|
+
html, body { height: 100%; background: var(--bg); color: var(--text); font-family: var(--sans); overflow: hidden; }
|
|
42
|
+
|
|
43
|
+
.app {
|
|
44
|
+
display: grid;
|
|
45
|
+
grid-template-rows: 54px 1fr 32px;
|
|
46
|
+
height: 100vh;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/* Top Bar */
|
|
50
|
+
.topbar {
|
|
51
|
+
display: flex;
|
|
52
|
+
align-items: center;
|
|
53
|
+
justify-content: space-between;
|
|
54
|
+
padding: 0 16px;
|
|
55
|
+
background: var(--panel);
|
|
56
|
+
border-bottom: 1px solid var(--border);
|
|
57
|
+
gap: 12px;
|
|
58
|
+
z-index: 20;
|
|
59
|
+
}
|
|
60
|
+
.brand {
|
|
61
|
+
display: flex;
|
|
62
|
+
align-items: center;
|
|
63
|
+
gap: 9px;
|
|
64
|
+
font-weight: 700;
|
|
65
|
+
font-size: 15px;
|
|
66
|
+
letter-spacing: -0.02em;
|
|
67
|
+
white-space: nowrap;
|
|
68
|
+
}
|
|
69
|
+
.brand-dot {
|
|
70
|
+
width: 9px;
|
|
71
|
+
height: 9px;
|
|
72
|
+
border-radius: 50%;
|
|
73
|
+
background: var(--accent);
|
|
74
|
+
box-shadow: 0 0 10px var(--accent);
|
|
75
|
+
animation: pulseDot 2s ease-in-out infinite;
|
|
76
|
+
}
|
|
77
|
+
@keyframes pulseDot {
|
|
78
|
+
0%, 100% { opacity: 1; transform: scale(1); }
|
|
79
|
+
50% { opacity: 0.45; transform: scale(0.85); }
|
|
80
|
+
}
|
|
81
|
+
.brand-tag {
|
|
82
|
+
font-family: var(--mono);
|
|
83
|
+
font-size: 10px;
|
|
84
|
+
color: var(--accent);
|
|
85
|
+
background: var(--accent-soft);
|
|
86
|
+
border: 1px solid rgba(34, 211, 238, 0.3);
|
|
87
|
+
padding: 2px 6px;
|
|
88
|
+
border-radius: 5px;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
.toolbar-group {
|
|
92
|
+
display: flex;
|
|
93
|
+
align-items: center;
|
|
94
|
+
gap: 8px;
|
|
95
|
+
flex-wrap: nowrap;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
select, button {
|
|
99
|
+
font-family: var(--sans);
|
|
100
|
+
font-size: 12.5px;
|
|
101
|
+
color: var(--text);
|
|
102
|
+
background: var(--panel-2);
|
|
103
|
+
border: 1px solid var(--border);
|
|
104
|
+
border-radius: 7px;
|
|
105
|
+
padding: 6px 10px;
|
|
106
|
+
cursor: pointer;
|
|
107
|
+
transition: border-color 0.15s, background 0.15s, transform 0.1s;
|
|
108
|
+
white-space: nowrap;
|
|
109
|
+
}
|
|
110
|
+
select:hover, button:hover {
|
|
111
|
+
border-color: #3b4b70;
|
|
112
|
+
background: #1b243a;
|
|
113
|
+
}
|
|
114
|
+
button:active { transform: translateY(0.5px); }
|
|
115
|
+
button.primary {
|
|
116
|
+
background: linear-gradient(135deg, #0891b2, #2563eb);
|
|
117
|
+
border-color: #38bdf8;
|
|
118
|
+
color: #ffffff;
|
|
119
|
+
font-weight: 600;
|
|
120
|
+
}
|
|
121
|
+
button.primary:hover {
|
|
122
|
+
background: linear-gradient(135deg, #06b6d4, #3b82f6);
|
|
123
|
+
}
|
|
124
|
+
button.active {
|
|
125
|
+
border-color: var(--accent);
|
|
126
|
+
color: var(--accent);
|
|
127
|
+
background: var(--accent-soft);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/* Main Split Workspace */
|
|
131
|
+
.workspace {
|
|
132
|
+
display: grid;
|
|
133
|
+
grid-template-columns: 430px 1fr;
|
|
134
|
+
min-height: 0;
|
|
135
|
+
overflow: hidden;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/* Left Editor Pane */
|
|
139
|
+
.editor-pane {
|
|
140
|
+
display: flex;
|
|
141
|
+
flex-direction: column;
|
|
142
|
+
background: var(--panel);
|
|
143
|
+
border-right: 1px solid var(--border);
|
|
144
|
+
min-height: 0;
|
|
145
|
+
}
|
|
146
|
+
.pane-header {
|
|
147
|
+
display: flex;
|
|
148
|
+
align-items: center;
|
|
149
|
+
justify-content: space-between;
|
|
150
|
+
padding: 8px 12px;
|
|
151
|
+
border-bottom: 1px solid var(--border);
|
|
152
|
+
font-size: 11.5px;
|
|
153
|
+
color: var(--muted);
|
|
154
|
+
gap: 8px;
|
|
155
|
+
}
|
|
156
|
+
.quick-bar {
|
|
157
|
+
display: flex;
|
|
158
|
+
gap: 6px;
|
|
159
|
+
flex-wrap: wrap;
|
|
160
|
+
}
|
|
161
|
+
.quick-btn {
|
|
162
|
+
font-family: var(--mono);
|
|
163
|
+
font-size: 11px;
|
|
164
|
+
padding: 3px 8px;
|
|
165
|
+
border-radius: 5px;
|
|
166
|
+
background: #131a2c;
|
|
167
|
+
color: #cbd5e1;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
textarea#dsl-editor {
|
|
171
|
+
flex: 1;
|
|
172
|
+
width: 100%;
|
|
173
|
+
resize: none;
|
|
174
|
+
border: none;
|
|
175
|
+
outline: none;
|
|
176
|
+
padding: 14px;
|
|
177
|
+
background: #0b0f1a;
|
|
178
|
+
color: #e2e8f0;
|
|
179
|
+
font-family: var(--mono);
|
|
180
|
+
font-size: 12.5px;
|
|
181
|
+
line-height: 1.62;
|
|
182
|
+
tab-size: 2;
|
|
183
|
+
white-space: pre;
|
|
184
|
+
overflow: auto;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
.errors-panel {
|
|
188
|
+
max-height: 110px;
|
|
189
|
+
overflow-y: auto;
|
|
190
|
+
background: rgba(251, 113, 133, 0.10);
|
|
191
|
+
border-top: 1px solid rgba(251, 113, 133, 0.35);
|
|
192
|
+
padding: 8px 12px;
|
|
193
|
+
font-family: var(--mono);
|
|
194
|
+
font-size: 11.5px;
|
|
195
|
+
color: #fda4af;
|
|
196
|
+
display: none;
|
|
197
|
+
}
|
|
198
|
+
.errors-panel.visible { display: block; }
|
|
199
|
+
|
|
200
|
+
/* Right Preview Canvas Pane */
|
|
201
|
+
.preview-pane {
|
|
202
|
+
display: flex;
|
|
203
|
+
flex-direction: column;
|
|
204
|
+
min-height: 0;
|
|
205
|
+
background: #070a12;
|
|
206
|
+
position: relative;
|
|
207
|
+
}
|
|
208
|
+
.preview-controls {
|
|
209
|
+
display: flex;
|
|
210
|
+
align-items: center;
|
|
211
|
+
justify-content: space-between;
|
|
212
|
+
padding: 8px 14px;
|
|
213
|
+
background: var(--panel);
|
|
214
|
+
border-bottom: 1px solid var(--border);
|
|
215
|
+
gap: 10px;
|
|
216
|
+
flex-wrap: wrap;
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
.canvas-stage {
|
|
220
|
+
flex: 1;
|
|
221
|
+
overflow: auto;
|
|
222
|
+
display: flex;
|
|
223
|
+
align-items: center;
|
|
224
|
+
justify-content: center;
|
|
225
|
+
padding: 28px;
|
|
226
|
+
transition: background 0.2s ease;
|
|
227
|
+
background: #0d1117;
|
|
228
|
+
}
|
|
229
|
+
.canvas-stage.gh-light {
|
|
230
|
+
background: #ffffff;
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
.readme-card {
|
|
234
|
+
border-radius: 12px;
|
|
235
|
+
padding: 16px;
|
|
236
|
+
transition: background 0.2s, border-color 0.2s;
|
|
237
|
+
border: 1px solid #30363d;
|
|
238
|
+
background: #0d1117;
|
|
239
|
+
max-width: 100%;
|
|
240
|
+
}
|
|
241
|
+
.canvas-stage.gh-light .readme-card {
|
|
242
|
+
border-color: #d0d7de;
|
|
243
|
+
background: #ffffff;
|
|
244
|
+
}
|
|
245
|
+
.readme-label {
|
|
246
|
+
font-family: var(--mono);
|
|
247
|
+
font-size: 11px;
|
|
248
|
+
color: #8b949e;
|
|
249
|
+
margin-bottom: 10px;
|
|
250
|
+
display: flex;
|
|
251
|
+
align-items: center;
|
|
252
|
+
justify-content: space-between;
|
|
253
|
+
}
|
|
254
|
+
.canvas-stage.gh-light .readme-label { color: #57606a; }
|
|
255
|
+
|
|
256
|
+
#svg-container {
|
|
257
|
+
transform-origin: center center;
|
|
258
|
+
transition: transform 0.15s ease;
|
|
259
|
+
user-select: none;
|
|
260
|
+
}
|
|
261
|
+
#svg-container svg {
|
|
262
|
+
display: block;
|
|
263
|
+
max-width: 100%;
|
|
264
|
+
height: auto;
|
|
265
|
+
}
|
|
266
|
+
#svg-container g.wp-node {
|
|
267
|
+
cursor: grab;
|
|
268
|
+
}
|
|
269
|
+
#svg-container g.wp-node:active {
|
|
270
|
+
cursor: grabbing;
|
|
271
|
+
}
|
|
272
|
+
#svg-container g.wp-node:hover .wp-node-card {
|
|
273
|
+
stroke: var(--accent);
|
|
274
|
+
stroke-width: 1.75;
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
/* Icon Reference Drawer */
|
|
278
|
+
.icon-drawer {
|
|
279
|
+
display: none;
|
|
280
|
+
position: absolute;
|
|
281
|
+
top: 48px;
|
|
282
|
+
left: 14px;
|
|
283
|
+
right: 14px;
|
|
284
|
+
max-height: 220px;
|
|
285
|
+
overflow-y: auto;
|
|
286
|
+
background: var(--panel);
|
|
287
|
+
border: 1px solid var(--border);
|
|
288
|
+
border-radius: 10px;
|
|
289
|
+
padding: 12px;
|
|
290
|
+
z-index: 30;
|
|
291
|
+
box-shadow: 0 18px 40px rgba(0,0,0,0.6);
|
|
292
|
+
}
|
|
293
|
+
.icon-drawer.open { display: block; }
|
|
294
|
+
.icon-grid {
|
|
295
|
+
display: flex;
|
|
296
|
+
flex-wrap: wrap;
|
|
297
|
+
gap: 6px;
|
|
298
|
+
margin-top: 8px;
|
|
299
|
+
}
|
|
300
|
+
.icon-chip {
|
|
301
|
+
font-family: var(--mono);
|
|
302
|
+
font-size: 11px;
|
|
303
|
+
padding: 4px 8px;
|
|
304
|
+
background: var(--panel-2);
|
|
305
|
+
border: 1px solid var(--border);
|
|
306
|
+
border-radius: 6px;
|
|
307
|
+
cursor: pointer;
|
|
308
|
+
}
|
|
309
|
+
.icon-chip:hover { border-color: var(--accent); color: var(--accent); }
|
|
310
|
+
|
|
311
|
+
/* Status Bar */
|
|
312
|
+
.statusbar {
|
|
313
|
+
display: flex;
|
|
314
|
+
align-items: center;
|
|
315
|
+
justify-content: space-between;
|
|
316
|
+
padding: 0 14px;
|
|
317
|
+
background: var(--panel);
|
|
318
|
+
border-top: 1px solid var(--border);
|
|
319
|
+
font-family: var(--mono);
|
|
320
|
+
font-size: 11px;
|
|
321
|
+
color: var(--muted);
|
|
322
|
+
}
|
|
323
|
+
.status-items { display: flex; align-items: center; gap: 14px; }
|
|
324
|
+
.badge-ok { color: var(--emerald); }
|
|
325
|
+
.badge-err { color: var(--rose); }
|
|
326
|
+
|
|
327
|
+
/* Toast */
|
|
328
|
+
.toast {
|
|
329
|
+
position: fixed;
|
|
330
|
+
bottom: 44px;
|
|
331
|
+
right: 20px;
|
|
332
|
+
background: #111827;
|
|
333
|
+
border: 1px solid var(--accent);
|
|
334
|
+
color: #f8fafc;
|
|
335
|
+
padding: 10px 14px;
|
|
336
|
+
border-radius: 8px;
|
|
337
|
+
font-size: 12.5px;
|
|
338
|
+
box-shadow: 0 12px 30px rgba(0,0,0,0.5);
|
|
339
|
+
opacity: 0;
|
|
340
|
+
pointer-events: none;
|
|
341
|
+
transform: translateY(8px);
|
|
342
|
+
transition: opacity 0.2s, transform 0.2s;
|
|
343
|
+
z-index: 100;
|
|
344
|
+
}
|
|
345
|
+
.toast.show { opacity: 1; transform: translateY(0); }
|
|
346
|
+
|
|
347
|
+
@media (max-width: 960px) {
|
|
348
|
+
.workspace { grid-template-columns: 1fr; grid-template-rows: 42% 58%; }
|
|
349
|
+
.editor-pane { border-right: none; border-bottom: 1px solid var(--border); }
|
|
350
|
+
}
|
|
351
|
+
</style>
|
|
352
|
+
</head>
|
|
353
|
+
<body>
|
|
354
|
+
<div class="app">
|
|
355
|
+
<header class="topbar">
|
|
356
|
+
<div class="brand">
|
|
357
|
+
<span class="brand-dot"></span>
|
|
358
|
+
<span>wirepulse</span>
|
|
359
|
+
<span class="brand-tag" id="version-tag">studio</span>
|
|
360
|
+
</div>
|
|
361
|
+
|
|
362
|
+
<div class="toolbar-group">
|
|
363
|
+
<select id="template-select" title="Load a starter architecture template"></select>
|
|
364
|
+
<select id="theme-select" title="Override diagram theme"></select>
|
|
365
|
+
<button id="btn-play" title="Pause or resume SVG animations">⏸ Pause</button>
|
|
366
|
+
<select id="speed-select" title="Animation speed multiplier">
|
|
367
|
+
<option value="0.5">0.5x</option>
|
|
368
|
+
<option value="1" selected>1.0x</option>
|
|
369
|
+
<option value="1.5">1.5x</option>
|
|
370
|
+
<option value="2">2.0x</option>
|
|
371
|
+
</select>
|
|
372
|
+
</div>
|
|
373
|
+
|
|
374
|
+
<div class="toolbar-group">
|
|
375
|
+
<button id="btn-save" style="display:none;" title="Save to disk (Ctrl+S)">💾 Save</button>
|
|
376
|
+
<button id="btn-copy-md" title="Copy GitHub README Light+Dark Markdown snippet">Copy README</button>
|
|
377
|
+
<button id="btn-export-png" title="Export crisp 2x Retina PNG">PNG</button>
|
|
378
|
+
<button id="btn-export-webm" title="Record 3.5s animated WebM video">WebM</button>
|
|
379
|
+
<button id="btn-export-svg" class="primary" title="Download pure zero-JS animated SVG">⬇ Download SVG</button>
|
|
380
|
+
</div>
|
|
381
|
+
</header>
|
|
382
|
+
|
|
383
|
+
<main class="workspace">
|
|
384
|
+
<section class="editor-pane">
|
|
385
|
+
<div class="pane-header">
|
|
386
|
+
<span id="editor-filename">diagram.wp</span>
|
|
387
|
+
<div class="quick-bar">
|
|
388
|
+
<button class="quick-btn" id="btn-add-node">+ Node</button>
|
|
389
|
+
<button class="quick-btn" id="btn-add-edge">+ Edge</button>
|
|
390
|
+
<button class="quick-btn" id="btn-add-group">+ Group</button>
|
|
391
|
+
<button class="quick-btn" id="btn-icons">Icons</button>
|
|
392
|
+
</div>
|
|
393
|
+
</div>
|
|
394
|
+
<textarea id="dsl-editor" spellcheck="false" aria-label="Wirepulse Diagram DSL Editor"></textarea>
|
|
395
|
+
<div id="errors-panel" class="errors-panel"></div>
|
|
396
|
+
</section>
|
|
397
|
+
|
|
398
|
+
<section class="preview-pane">
|
|
399
|
+
<div class="preview-controls">
|
|
400
|
+
<div class="toolbar-group">
|
|
401
|
+
<button id="btn-gh-dark" class="active">GitHub Dark</button>
|
|
402
|
+
<button id="btn-gh-light">GitHub Light</button>
|
|
403
|
+
<button id="btn-share">Share URL</button>
|
|
404
|
+
</div>
|
|
405
|
+
<div class="toolbar-group">
|
|
406
|
+
<button id="btn-zoom-out">−</button>
|
|
407
|
+
<span id="zoom-label" style="font-family: var(--mono); font-size: 11.5px; color: var(--muted); min-width: 42px; text-align: center;">100%</span>
|
|
408
|
+
<button id="btn-zoom-in">+</button>
|
|
409
|
+
<button id="btn-zoom-reset">Fit</button>
|
|
410
|
+
</div>
|
|
411
|
+
</div>
|
|
412
|
+
|
|
413
|
+
<div id="icon-drawer" class="icon-drawer">
|
|
414
|
+
<div style="display:flex; justify-content:space-between; align-items:center;">
|
|
415
|
+
<strong style="font-size:12px;">Built-in Inline Vector Icons (click to copy)</strong>
|
|
416
|
+
<button class="quick-btn" id="btn-close-icons">Close</button>
|
|
417
|
+
</div>
|
|
418
|
+
<div id="icon-grid" class="icon-grid"></div>
|
|
419
|
+
</div>
|
|
420
|
+
|
|
421
|
+
<div id="canvas-stage" class="canvas-stage">
|
|
422
|
+
<div class="readme-card">
|
|
423
|
+
<div class="readme-label">
|
|
424
|
+
<span>README.md preview</span>
|
|
425
|
+
<span id="preview-hint">Drag any node to snap to grid</span>
|
|
426
|
+
</div>
|
|
427
|
+
<div id="svg-container"></div>
|
|
428
|
+
</div>
|
|
429
|
+
</div>
|
|
430
|
+
</section>
|
|
431
|
+
</main>
|
|
432
|
+
|
|
433
|
+
<footer class="statusbar">
|
|
434
|
+
<div class="status-items">
|
|
435
|
+
<span id="csp-status" class="badge-ok">✔ GitHub CSP Safe (0 scripts)</span>
|
|
436
|
+
<span id="size-status">0.0 KB</span>
|
|
437
|
+
<span id="counts-status">0 nodes · 0 edges</span>
|
|
438
|
+
</div>
|
|
439
|
+
<div>wirepulse · 100% local · zero-JS SVG</div>
|
|
440
|
+
</footer>
|
|
441
|
+
</div>
|
|
442
|
+
|
|
443
|
+
<div id="toast" class="toast"></div>
|
|
444
|
+
|
|
445
|
+
<script>
|
|
446
|
+
const BOOT = ${bootstrap};
|
|
447
|
+
|
|
448
|
+
const editor = document.getElementById('dsl-editor');
|
|
449
|
+
const svgContainer = document.getElementById('svg-container');
|
|
450
|
+
const errorsPanel = document.getElementById('errors-panel');
|
|
451
|
+
const templateSelect = document.getElementById('template-select');
|
|
452
|
+
const themeSelect = document.getElementById('theme-select');
|
|
453
|
+
const speedSelect = document.getElementById('speed-select');
|
|
454
|
+
const canvasStage = document.getElementById('canvas-stage');
|
|
455
|
+
const cspStatus = document.getElementById('csp-status');
|
|
456
|
+
const sizeStatus = document.getElementById('size-status');
|
|
457
|
+
const countsStatus = document.getElementById('counts-status');
|
|
458
|
+
const zoomLabel = document.getElementById('zoom-label');
|
|
459
|
+
const toastEl = document.getElementById('toast');
|
|
460
|
+
const iconDrawer = document.getElementById('icon-drawer');
|
|
461
|
+
const iconGrid = document.getElementById('icon-grid');
|
|
462
|
+
const btnPlay = document.getElementById('btn-play');
|
|
463
|
+
const btnSave = document.getElementById('btn-save');
|
|
464
|
+
const btnGhDark = document.getElementById('btn-gh-dark');
|
|
465
|
+
const btnGhLight = document.getElementById('btn-gh-light');
|
|
466
|
+
|
|
467
|
+
let currentSvg = '';
|
|
468
|
+
let isPaused = false;
|
|
469
|
+
let zoom = 1;
|
|
470
|
+
let renderTimer = null;
|
|
471
|
+
let ghPreviewMode = 'dark';
|
|
472
|
+
|
|
473
|
+
document.getElementById('version-tag').textContent = 'v' + BOOT.version;
|
|
474
|
+
if (BOOT.fileName) {
|
|
475
|
+
document.getElementById('editor-filename').textContent = BOOT.fileName;
|
|
476
|
+
}
|
|
477
|
+
if (BOOT.canSaveToDisk) {
|
|
478
|
+
btnSave.style.display = 'inline-block';
|
|
479
|
+
}
|
|
480
|
+
|
|
481
|
+
function showToast(msg) {
|
|
482
|
+
toastEl.textContent = msg;
|
|
483
|
+
toastEl.classList.add('show');
|
|
484
|
+
clearTimeout(toastEl._t);
|
|
485
|
+
toastEl._t = setTimeout(() => toastEl.classList.remove('show'), 2600);
|
|
486
|
+
}
|
|
487
|
+
|
|
488
|
+
// Populate Templates
|
|
489
|
+
const defaultOpt = document.createElement('option');
|
|
490
|
+
defaultOpt.value = '';
|
|
491
|
+
defaultOpt.textContent = 'Templates…';
|
|
492
|
+
templateSelect.appendChild(defaultOpt);
|
|
493
|
+
for (const tpl of BOOT.templates) {
|
|
494
|
+
const opt = document.createElement('option');
|
|
495
|
+
opt.value = tpl.id;
|
|
496
|
+
opt.textContent = tpl.name;
|
|
497
|
+
templateSelect.appendChild(opt);
|
|
498
|
+
}
|
|
499
|
+
|
|
500
|
+
// Populate Themes
|
|
501
|
+
const themeAuto = document.createElement('option');
|
|
502
|
+
themeAuto.value = '';
|
|
503
|
+
themeAuto.textContent = 'Theme: From DSL';
|
|
504
|
+
themeSelect.appendChild(themeAuto);
|
|
505
|
+
for (const th of BOOT.themes) {
|
|
506
|
+
const opt = document.createElement('option');
|
|
507
|
+
opt.value = th;
|
|
508
|
+
opt.textContent = 'Theme: ' + th;
|
|
509
|
+
themeSelect.appendChild(opt);
|
|
510
|
+
}
|
|
511
|
+
|
|
512
|
+
// Populate Icons Drawer
|
|
513
|
+
for (const iconName of BOOT.icons) {
|
|
514
|
+
const chip = document.createElement('button');
|
|
515
|
+
chip.className = 'icon-chip';
|
|
516
|
+
chip.textContent = iconName;
|
|
517
|
+
chip.onclick = () => {
|
|
518
|
+
navigator.clipboard?.writeText('icon=' + iconName);
|
|
519
|
+
showToast('Copied icon=' + iconName);
|
|
520
|
+
};
|
|
521
|
+
iconGrid.appendChild(chip);
|
|
522
|
+
}
|
|
523
|
+
|
|
524
|
+
// Load initial source (or URL hash share if present)
|
|
525
|
+
function loadInitialSource() {
|
|
526
|
+
const hash = window.location.hash;
|
|
527
|
+
if (hash.startsWith('#wp=')) {
|
|
528
|
+
try {
|
|
529
|
+
const decoded = decodeURIComponent(escape(atob(hash.slice(4))));
|
|
530
|
+
if (decoded.trim()) return decoded;
|
|
531
|
+
} catch {}
|
|
532
|
+
}
|
|
533
|
+
return BOOT.initialSource;
|
|
534
|
+
}
|
|
535
|
+
editor.value = loadInitialSource();
|
|
536
|
+
|
|
537
|
+
async function renderNow() {
|
|
538
|
+
const payload = {
|
|
539
|
+
source: editor.value,
|
|
540
|
+
theme: themeSelect.value || undefined,
|
|
541
|
+
speedMultiplier: Number(speedSelect.value) || 1,
|
|
542
|
+
paused: isPaused,
|
|
543
|
+
previewMode: ghPreviewMode,
|
|
544
|
+
};
|
|
545
|
+
try {
|
|
546
|
+
const res = await fetch('/api/render', {
|
|
547
|
+
method: 'POST',
|
|
548
|
+
headers: { 'Content-Type': 'application/json' },
|
|
549
|
+
body: JSON.stringify(payload),
|
|
550
|
+
});
|
|
551
|
+
const data = await res.json();
|
|
552
|
+
currentSvg = data.svg || '';
|
|
553
|
+
svgContainer.innerHTML = data.previewSvg || currentSvg;
|
|
554
|
+
attachNodeDragHandlers();
|
|
555
|
+
|
|
556
|
+
// Update error panel
|
|
557
|
+
if (data.errors && data.errors.length > 0) {
|
|
558
|
+
errorsPanel.innerHTML = data.errors
|
|
559
|
+
.map((e) => 'Line ' + e.line + ': ' + e.message)
|
|
560
|
+
.join('<br/>');
|
|
561
|
+
errorsPanel.classList.add('visible');
|
|
562
|
+
} else {
|
|
563
|
+
errorsPanel.classList.remove('visible');
|
|
564
|
+
}
|
|
565
|
+
|
|
566
|
+
// Update status bar
|
|
567
|
+
const val = data.validation;
|
|
568
|
+
if (val && val.githubSafe) {
|
|
569
|
+
cspStatus.textContent = '✔ GitHub CSP Safe (0 scripts)';
|
|
570
|
+
cspStatus.className = 'badge-ok';
|
|
571
|
+
} else {
|
|
572
|
+
cspStatus.textContent = '✖ CSP Issue Detected';
|
|
573
|
+
cspStatus.className = 'badge-err';
|
|
574
|
+
}
|
|
575
|
+
sizeStatus.textContent = ((val?.bytes || currentSvg.length) / 1024).toFixed(1) + ' KB';
|
|
576
|
+
countsStatus.textContent =
|
|
577
|
+
(data.nodeCount || 0) + ' nodes · ' + (data.edgeCount || 0) + ' edges';
|
|
578
|
+
} catch (err) {
|
|
579
|
+
showToast('Render error: ' + err.message);
|
|
580
|
+
}
|
|
581
|
+
}
|
|
582
|
+
|
|
583
|
+
function scheduleRender() {
|
|
584
|
+
clearTimeout(renderTimer);
|
|
585
|
+
renderTimer = setTimeout(renderNow, 120);
|
|
586
|
+
}
|
|
587
|
+
|
|
588
|
+
// Drag-and-drop node repositioning -> snaps to grid & updates DSL col/row
|
|
589
|
+
function attachNodeDragHandlers() {
|
|
590
|
+
const svgEl = svgContainer.querySelector('svg');
|
|
591
|
+
if (!svgEl) return;
|
|
592
|
+
const nodes = svgEl.querySelectorAll('g.wp-node');
|
|
593
|
+
|
|
594
|
+
nodes.forEach((g) => {
|
|
595
|
+
g.addEventListener('pointerdown', (ev) => {
|
|
596
|
+
ev.preventDefault();
|
|
597
|
+
const nodeId = g.getAttribute('data-node-id');
|
|
598
|
+
const origCol = Number(g.getAttribute('data-col') || 0);
|
|
599
|
+
const origRow = Number(g.getAttribute('data-row') || 0);
|
|
600
|
+
const startX = ev.clientX;
|
|
601
|
+
const startY = ev.clientY;
|
|
602
|
+
let dx = 0;
|
|
603
|
+
let dy = 0;
|
|
604
|
+
|
|
605
|
+
const onMove = (moveEv) => {
|
|
606
|
+
dx = (moveEv.clientX - startX) / zoom;
|
|
607
|
+
dy = (moveEv.clientY - startY) / zoom;
|
|
608
|
+
g.setAttribute('transform', 'translate(' + Math.round(dx) + ',' + Math.round(dy) + ')');
|
|
609
|
+
};
|
|
610
|
+
|
|
611
|
+
const onUp = async () => {
|
|
612
|
+
window.removeEventListener('pointermove', onMove);
|
|
613
|
+
window.removeEventListener('pointerup', onUp);
|
|
614
|
+
g.removeAttribute('transform');
|
|
615
|
+
|
|
616
|
+
if (Math.abs(dx) < 35 && Math.abs(dy) < 25) return;
|
|
617
|
+
|
|
618
|
+
const deltaCol = Math.round(dx / 292);
|
|
619
|
+
const deltaRow = Math.round(dy / 122);
|
|
620
|
+
if (deltaCol === 0 && deltaRow === 0) return;
|
|
621
|
+
|
|
622
|
+
const nextCol = Math.max(0, origCol + deltaCol);
|
|
623
|
+
const nextRow = Math.max(0, origRow + deltaRow);
|
|
624
|
+
|
|
625
|
+
const resp = await fetch('/api/move-node', {
|
|
626
|
+
method: 'POST',
|
|
627
|
+
headers: { 'Content-Type': 'application/json' },
|
|
628
|
+
body: JSON.stringify({
|
|
629
|
+
source: editor.value,
|
|
630
|
+
nodeId,
|
|
631
|
+
col: nextCol,
|
|
632
|
+
row: nextRow,
|
|
633
|
+
}),
|
|
634
|
+
});
|
|
635
|
+
const updated = await resp.json();
|
|
636
|
+
if (updated.source) {
|
|
637
|
+
editor.value = updated.source;
|
|
638
|
+
showToast('Moved "' + nodeId + '" → col=' + nextCol + ' row=' + nextRow);
|
|
639
|
+
renderNow();
|
|
640
|
+
}
|
|
641
|
+
};
|
|
642
|
+
|
|
643
|
+
window.addEventListener('pointermove', onMove);
|
|
644
|
+
window.addEventListener('pointerup', onUp);
|
|
645
|
+
});
|
|
646
|
+
});
|
|
647
|
+
}
|
|
648
|
+
|
|
649
|
+
// Event listeners
|
|
650
|
+
editor.addEventListener('input', scheduleRender);
|
|
651
|
+
themeSelect.addEventListener('change', renderNow);
|
|
652
|
+
speedSelect.addEventListener('change', renderNow);
|
|
653
|
+
|
|
654
|
+
templateSelect.addEventListener('change', () => {
|
|
655
|
+
const tpl = BOOT.templates.find((t) => t.id === templateSelect.value);
|
|
656
|
+
if (tpl) {
|
|
657
|
+
editor.value = tpl.source;
|
|
658
|
+
themeSelect.value = '';
|
|
659
|
+
renderNow();
|
|
660
|
+
showToast('Loaded template: ' + tpl.name);
|
|
661
|
+
}
|
|
662
|
+
templateSelect.value = '';
|
|
663
|
+
});
|
|
664
|
+
|
|
665
|
+
btnPlay.addEventListener('click', () => {
|
|
666
|
+
isPaused = !isPaused;
|
|
667
|
+
btnPlay.textContent = isPaused ? '▶ Play' : '⏸ Pause';
|
|
668
|
+
btnPlay.classList.toggle('active', isPaused);
|
|
669
|
+
renderNow();
|
|
670
|
+
});
|
|
671
|
+
|
|
672
|
+
btnGhDark.addEventListener('click', () => {
|
|
673
|
+
ghPreviewMode = 'dark';
|
|
674
|
+
canvasStage.classList.remove('gh-light');
|
|
675
|
+
btnGhDark.classList.add('active');
|
|
676
|
+
btnGhLight.classList.remove('active');
|
|
677
|
+
renderNow();
|
|
678
|
+
});
|
|
679
|
+
|
|
680
|
+
btnGhLight.addEventListener('click', () => {
|
|
681
|
+
ghPreviewMode = 'light';
|
|
682
|
+
canvasStage.classList.add('gh-light');
|
|
683
|
+
btnGhLight.classList.add('active');
|
|
684
|
+
btnGhDark.classList.remove('active');
|
|
685
|
+
renderNow();
|
|
686
|
+
});
|
|
687
|
+
|
|
688
|
+
// Zoom controls
|
|
689
|
+
function applyZoom() {
|
|
690
|
+
svgContainer.style.transform = 'scale(' + zoom.toFixed(2) + ')';
|
|
691
|
+
zoomLabel.textContent = Math.round(zoom * 100) + '%';
|
|
692
|
+
}
|
|
693
|
+
document.getElementById('btn-zoom-in').onclick = () => { zoom = Math.min(2, zoom + 0.15); applyZoom(); };
|
|
694
|
+
document.getElementById('btn-zoom-out').onclick = () => { zoom = Math.max(0.4, zoom - 0.15); applyZoom(); };
|
|
695
|
+
document.getElementById('btn-zoom-reset').onclick = () => { zoom = 1; applyZoom(); };
|
|
696
|
+
|
|
697
|
+
// Quick inserts
|
|
698
|
+
let quickCounter = 1;
|
|
699
|
+
document.getElementById('btn-add-node').onclick = () => {
|
|
700
|
+
const id = 'svc' + quickCounter++;
|
|
701
|
+
editor.value = editor.value.trimEnd() + '\\nnode ' + id + ' "New Service" sub="Worker" icon=server color=cyan\\n';
|
|
702
|
+
renderNow();
|
|
703
|
+
};
|
|
704
|
+
document.getElementById('btn-add-edge').onclick = () => {
|
|
705
|
+
editor.value = editor.value.trimEnd() + '\\nnodeA -> nodeB "request" flow=packet color=violet\\n';
|
|
706
|
+
renderNow();
|
|
707
|
+
};
|
|
708
|
+
document.getElementById('btn-add-group').onclick = () => {
|
|
709
|
+
editor.value = editor.value.trimEnd() + '\\ngroup cluster1 "Cluster" color=emerald\\n';
|
|
710
|
+
renderNow();
|
|
711
|
+
};
|
|
712
|
+
document.getElementById('btn-icons').onclick = () => iconDrawer.classList.toggle('open');
|
|
713
|
+
document.getElementById('btn-close-icons').onclick = () => iconDrawer.classList.remove('open');
|
|
714
|
+
|
|
715
|
+
// Share URL
|
|
716
|
+
document.getElementById('btn-share').onclick = () => {
|
|
717
|
+
const encoded = btoa(unescape(encodeURIComponent(editor.value)));
|
|
718
|
+
const url = window.location.origin + window.location.pathname + '#wp=' + encoded;
|
|
719
|
+
window.history.replaceState(null, '', '#wp=' + encoded);
|
|
720
|
+
navigator.clipboard?.writeText(url);
|
|
721
|
+
showToast('Shareable URL copied to clipboard!');
|
|
722
|
+
};
|
|
723
|
+
|
|
724
|
+
// Download pure animated SVG
|
|
725
|
+
document.getElementById('btn-export-svg').onclick = () => {
|
|
726
|
+
if (!currentSvg) return;
|
|
727
|
+
const blob = new Blob([currentSvg], { type: 'image/svg+xml;charset=utf-8' });
|
|
728
|
+
const a = document.createElement('a');
|
|
729
|
+
a.href = URL.createObjectURL(blob);
|
|
730
|
+
a.download = 'architecture.svg';
|
|
731
|
+
a.click();
|
|
732
|
+
URL.revokeObjectURL(a.href);
|
|
733
|
+
showToast('Downloaded pure zero-JS architecture.svg!');
|
|
734
|
+
};
|
|
735
|
+
|
|
736
|
+
// Copy GitHub README snippet
|
|
737
|
+
document.getElementById('btn-copy-md').onclick = () => {
|
|
738
|
+
const snippet = [
|
|
739
|
+
'<picture>',
|
|
740
|
+
' <source media="(prefers-color-scheme: dark)" srcset="./docs/architecture-dark.svg" />',
|
|
741
|
+
' <source media="(prefers-color-scheme: light)" srcset="./docs/architecture-light.svg" />',
|
|
742
|
+
' <img alt="Architecture Diagram" src="./docs/architecture.svg" />',
|
|
743
|
+
'</picture>',
|
|
744
|
+
].join('\\n');
|
|
745
|
+
navigator.clipboard?.writeText(snippet);
|
|
746
|
+
showToast('Copied GitHub README <picture> snippet!');
|
|
747
|
+
};
|
|
748
|
+
|
|
749
|
+
// Export 2x Retina PNG
|
|
750
|
+
document.getElementById('btn-export-png').onclick = async () => {
|
|
751
|
+
if (!currentSvg) return;
|
|
752
|
+
const svgEl = svgContainer.querySelector('svg');
|
|
753
|
+
const w = Number(svgEl?.getAttribute('width') || 900);
|
|
754
|
+
const h = Number(svgEl?.getAttribute('height') || 450);
|
|
755
|
+
const scale = 2;
|
|
756
|
+
const canvas = document.createElement('canvas');
|
|
757
|
+
canvas.width = w * scale;
|
|
758
|
+
canvas.height = h * scale;
|
|
759
|
+
const ctx = canvas.getContext('2d');
|
|
760
|
+
const img = new Image();
|
|
761
|
+
const blob = new Blob([svgEl.outerHTML], { type: 'image/svg+xml;charset=utf-8' });
|
|
762
|
+
const url = URL.createObjectURL(blob);
|
|
763
|
+
img.onload = () => {
|
|
764
|
+
ctx.scale(scale, scale);
|
|
765
|
+
ctx.drawImage(img, 0, 0, w, h);
|
|
766
|
+
URL.revokeObjectURL(url);
|
|
767
|
+
const a = document.createElement('a');
|
|
768
|
+
a.href = canvas.toDataURL('image/png');
|
|
769
|
+
a.download = 'architecture-2x.png';
|
|
770
|
+
a.click();
|
|
771
|
+
showToast('Exported 2x Retina PNG!');
|
|
772
|
+
};
|
|
773
|
+
img.src = url;
|
|
774
|
+
};
|
|
775
|
+
|
|
776
|
+
// Export Animated WebM Video (3.5s capture via Canvas + MediaRecorder)
|
|
777
|
+
document.getElementById('btn-export-webm').onclick = async () => {
|
|
778
|
+
const svgEl = svgContainer.querySelector('svg');
|
|
779
|
+
if (!svgEl || typeof MediaRecorder === 'undefined') {
|
|
780
|
+
showToast('WebM recording is not supported in this browser.');
|
|
781
|
+
return;
|
|
782
|
+
}
|
|
783
|
+
showToast('Recording 3.5s animated WebM…');
|
|
784
|
+
const w = Number(svgEl.getAttribute('width') || 900);
|
|
785
|
+
const h = Number(svgEl.getAttribute('height') || 450);
|
|
786
|
+
const canvas = document.createElement('canvas');
|
|
787
|
+
canvas.width = w;
|
|
788
|
+
canvas.height = h;
|
|
789
|
+
const ctx = canvas.getContext('2d');
|
|
790
|
+
const stream = canvas.captureStream(30);
|
|
791
|
+
const recorder = new MediaRecorder(stream, { mimeType: 'video/webm' });
|
|
792
|
+
const chunks = [];
|
|
793
|
+
recorder.ondataavailable = (e) => { if (e.data.size > 0) chunks.push(e.data); };
|
|
794
|
+
recorder.onstop = () => {
|
|
795
|
+
const outBlob = new Blob(chunks, { type: 'video/webm' });
|
|
796
|
+
const a = document.createElement('a');
|
|
797
|
+
a.href = URL.createObjectURL(outBlob);
|
|
798
|
+
a.download = 'architecture.webm';
|
|
799
|
+
a.click();
|
|
800
|
+
showToast('Exported animated architecture.webm!');
|
|
801
|
+
};
|
|
802
|
+
|
|
803
|
+
const blob = new Blob([svgEl.outerHTML], { type: 'image/svg+xml;charset=utf-8' });
|
|
804
|
+
const url = URL.createObjectURL(blob);
|
|
805
|
+
const img = new Image();
|
|
806
|
+
img.onload = () => {
|
|
807
|
+
recorder.start();
|
|
808
|
+
const start = performance.now();
|
|
809
|
+
function frame(now) {
|
|
810
|
+
ctx.clearRect(0, 0, w, h);
|
|
811
|
+
ctx.drawImage(img, 0, 0, w, h);
|
|
812
|
+
if (now - start < 3500) {
|
|
813
|
+
requestAnimationFrame(frame);
|
|
814
|
+
} else {
|
|
815
|
+
recorder.stop();
|
|
816
|
+
URL.revokeObjectURL(url);
|
|
817
|
+
}
|
|
818
|
+
}
|
|
819
|
+
requestAnimationFrame(frame);
|
|
820
|
+
};
|
|
821
|
+
img.src = url;
|
|
822
|
+
};
|
|
823
|
+
|
|
824
|
+
// Save to disk (when opened with --file)
|
|
825
|
+
async function saveToDisk() {
|
|
826
|
+
if (!BOOT.canSaveToDisk) return;
|
|
827
|
+
const res = await fetch('/api/save', {
|
|
828
|
+
method: 'POST',
|
|
829
|
+
headers: { 'Content-Type': 'application/json' },
|
|
830
|
+
body: JSON.stringify({ source: editor.value, svg: currentSvg }),
|
|
831
|
+
});
|
|
832
|
+
if (res.ok) {
|
|
833
|
+
showToast('Saved ' + (BOOT.fileName || 'file') + ' to disk!');
|
|
834
|
+
} else {
|
|
835
|
+
showToast('Failed to save file.');
|
|
836
|
+
}
|
|
837
|
+
}
|
|
838
|
+
btnSave.addEventListener('click', saveToDisk);
|
|
839
|
+
window.addEventListener('keydown', (e) => {
|
|
840
|
+
if ((e.ctrlKey || e.metaKey) && e.key.toLowerCase() === 's') {
|
|
841
|
+
e.preventDefault();
|
|
842
|
+
if (BOOT.canSaveToDisk) saveToDisk();
|
|
843
|
+
else document.getElementById('btn-export-svg').click();
|
|
844
|
+
}
|
|
845
|
+
});
|
|
846
|
+
|
|
847
|
+
// Initial render
|
|
848
|
+
renderNow();
|
|
849
|
+
</script>
|
|
850
|
+
</body>
|
|
851
|
+
</html>`;
|
|
852
|
+
}
|