-
Notifications
You must be signed in to change notification settings - Fork 56
Expand file tree
/
Copy pathtemplate.html
More file actions
500 lines (477 loc) · 30.7 KB
/
Copy pathtemplate.html
File metadata and controls
500 lines (477 loc) · 30.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>__TITLE__</title>
<script>try{const t=localStorage.getItem('theme');if(t==='light'||t==='dark')document.documentElement.dataset.theme=t;}catch(e){}</script>
<style>
/* "Big Tech docs" style · 2-pane app layout: LEFT diagram always FIT-TO-VIEW (whole system
visible at once) with zoom/pan · RIGHT sidebar with explainer cards. Light/dark follows the
OS (light-dark()). Inside the SVG ALWAYS write LIGHT-palette hex — the "color mapping" block
below remaps it per theme automatically. */
:root {
color-scheme: light dark;
--bg: light-dark(#f6f8fa, #0f141c); --panel: light-dark(#ffffff, #151c29);
--line: light-dark(#d1d5db, #394456); --line-soft: light-dark(#e5e7eb, #273143);
--text: light-dark(#1f2937, #e2e8f0); --text2: light-dark(#374151, #cbd5e1);
--muted: light-dark(#6b7280, #94a3b8); --dim: light-dark(#9ca3af, #64748b);
--di: light-dark(#2563eb, #60a5fa); /* OUT direction (request), solid line */
--ve: light-dark(#059669, #34d399); /* RETURN direction (response), ALWAYS dashed */
--sec: light-dark(#dc2626, #f87171); /* auth checkpoint / security */
--script: light-dark(#7c3aed, #a78bfa); /* scheduled / batch flow */
--pipe: light-dark(#d97706, #fbbf24); /* data pipeline */
--sky: light-dark(#0284c7, #38bdf8); /* data store / API */
--fx: light-dark(#c026d3, #e879f9); /* content generation */
--tint-di: light-dark(#eff6ff, #1a2740); --tint-sec: light-dark(#fef2f2, #321b24);
--tint-sky: light-dark(#f0f9ff, #14293a); --hl: light-dark(#fef9c3, #423c14);
}
:root[data-theme=light] { color-scheme: light; }
:root[data-theme=dark] { color-scheme: dark; }
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text);
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, "Helvetica Neue", Arial, sans-serif; }
.app { height: 100vh; display: flex; flex-direction: column; gap: 10px; padding: 16px clamp(14px, 2vw, 36px); }
.head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; }
h1 { font-size: 19px; font-weight: 650; letter-spacing: -0.01em; margin: 0 0 4px; }
.sub { color: var(--muted); font-size: 12.5px; line-height: 1.55; }
.theme-btn { flex: none; display: inline-flex; align-items: center; justify-content: center;
width: 34px; height: 34px; padding: 0; border-radius: 10px; color: var(--text);
background: var(--panel); border: 1px solid var(--line-soft); cursor: pointer; }
.theme-btn svg { width: 16px; height: 16px; }
.theme-btn:hover { border-color: var(--line); }
.edit-btn { flex: none; font-size: 12.5px; line-height: 1; padding: 8px 12px; border-radius: 10px;
background: var(--panel); color: var(--text); border: 1px solid var(--line-soft); cursor: pointer; }
.edit-btn:hover { border-color: var(--line); }
.edit-btn.on { border-color: var(--di); color: var(--di); box-shadow: 0 0 0 1px var(--di) inset; }
/* Rearrange mode: boxes get a "move" cursor, traveling dots hidden while active (their path only
needs to refresh once the drag ends) */
svg.edit-mode g[data-flows] { cursor: move; }
svg.edit-mode .flow-dot { display: none; }
/* Chips = color legend + flow-select buttons */
.chips { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.chip { display: inline-flex; align-items: center; gap: 7px; padding: 6px 12px; font-size: 12.5px;
background: var(--panel); color: var(--text); border: 1px solid var(--line-soft);
border-radius: 999px; cursor: pointer; font-family: inherit; transition: all .15s; }
.chip:hover { border-color: var(--line); box-shadow: 0 1px 3px rgba(0,0,0,.08); }
.chip.on { border-color: currentColor; box-shadow: 0 0 0 1px currentColor inset; }
.chip .dot { width: 9px; height: 9px; border-radius: 50%; background: currentColor; }
.chip span { color: var(--text); }
.hint { font-size: 12px; color: var(--muted); margin-left: 4px; }
/* 2 panes: left = diagram (fit-to-view + zoom/pan), right = info sidebar */
.split { flex: 1; min-height: 0; display: flex; gap: 14px; }
.board { flex: 1; min-width: 0; position: relative; background: var(--panel);
border: 1px solid var(--line-soft); border-radius: 14px; box-shadow: 0 1px 3px rgba(16,24,40,.06); }
.canvas { position: absolute; inset: 0; overflow: auto; border-radius: 14px; display: flex; cursor: grab; }
.canvas.panning { cursor: grabbing; user-select: none; }
.canvas svg { margin: auto; display: block; flex: none; }
.zoombar { position: absolute; top: 10px; right: 18px; z-index: 5; display: flex; align-items: center; gap: 2px;
background: var(--panel); border: 1px solid var(--line-soft); border-radius: 10px;
padding: 3px 5px; box-shadow: 0 2px 8px rgba(0,0,0,.12); }
.zoombar button { border: 0; background: none; color: var(--text); font-size: 14px; width: 26px; height: 24px;
border-radius: 7px; cursor: pointer; }
.zoombar button:hover { background: var(--line-soft); }
.zoombar .pct { font-size: 11px; color: var(--muted); min-width: 42px; text-align: center; }
.side { width: min(380px, 34vw); flex: none; overflow: auto; }
/* Halo behind every label in the SVG — a line can pass close to text and the text stays legible */
svg text { paint-order: stroke; stroke: var(--panel); stroke-width: 3px; stroke-linejoin: round; }
/* SVG color remap per theme: markup always writes LIGHT-palette hex, CSS wins over the
presentation attribute. NEVER write var() inside an attribute, never invent a hex outside
this table. */
svg [stroke="#2563eb"] { stroke: var(--di); } svg [fill="#2563eb"] { fill: var(--di); }
svg [stroke="#059669"] { stroke: var(--ve); } svg [fill="#059669"] { fill: var(--ve); }
svg [stroke="#dc2626"] { stroke: var(--sec); } svg [fill="#dc2626"] { fill: var(--sec); }
svg [stroke="#7c3aed"] { stroke: var(--script); } svg [fill="#7c3aed"] { fill: var(--script); }
svg [stroke="#d97706"] { stroke: var(--pipe); } svg [fill="#d97706"] { fill: var(--pipe); }
svg [stroke="#0284c7"] { stroke: var(--sky); } svg [fill="#0284c7"] { fill: var(--sky); }
svg [stroke="#c026d3"] { stroke: var(--fx); } svg [fill="#c026d3"] { fill: var(--fx); }
svg [stroke="#d1d5db"] { stroke: var(--line); } svg [stroke="#e5e7eb"] { stroke: var(--line-soft); }
svg [fill="#ffffff"] { fill: var(--panel); } svg [fill="#eff6ff"] { fill: var(--tint-di); }
svg [fill="#fef2f2"] { fill: var(--tint-sec); } svg [fill="#f0f9ff"] { fill: var(--tint-sky); }
svg [fill="#1f2937"] { fill: var(--text); } svg [fill="#374151"] { fill: var(--text2); }
svg [fill="#6b7280"] { fill: var(--muted); }
/* Interaction: selecting a flow dims everything else, the arrows "flow" in their direction */
svg [data-flow] { cursor: pointer; }
svg :is(line, path)[data-flow]:hover { stroke-width: 3; }
svg .dim { opacity: .1; transition: opacity .25s; }
/* Traveling dot along the line (Kiali/Istio traffic-map convention — a dot moving on the edge,
not a fake "marching ants" dashed line) — only visible once its own flow is selected. See the
"Traveling dots" section below. */
svg .flow-dot { opacity: 0; transition: opacity .25s; }
svg .flow-dot.flowing { opacity: 1; }
@keyframes flow-ping { 0% { transform: scale(1); opacity: .35; } 65% { transform: scale(1.05); opacity: 0; } 100% { transform: scale(1.05); opacity: 0; } }
svg .flow-ping-ring { transform-box: fill-box; transform-origin: center; animation: flow-ping 2.6s ease-out infinite; pointer-events: none; }
svg .flow-ping { opacity: 0; }
svg .flow-ping.flowing { opacity: 1; }
@media (prefers-reduced-motion: reduce) { svg .flow-dot { display: none; }
svg .flow-ping { display: none; } }
/* Sidebar explainer cards — selecting a flow leaves only that flow's card visible */
.cols { display: flex; flex-direction: column; gap: 12px; }
.card { background: var(--panel); border: 1px solid var(--line-soft); border-radius: 12px;
padding: 15px 17px; font-size: 12.5px; line-height: 1.75; box-shadow: 0 1px 2px rgba(16,24,40,.05); }
.card.hidden { display: none; }
.card li.hl { background: var(--hl); border-radius: 4px; color: var(--text2); }
.card h3 { margin: 0 0 8px; font-size: 13.5px; font-weight: 650; display: flex; align-items: center; gap: 8px; }
.card .dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; flex: none; }
.card ol, .card ul { margin: 0; padding-left: 18px; color: var(--muted); }
.card li { margin-bottom: 3px; }
.card b { color: var(--text); font-weight: 600; }
.n1 { color: var(--di); font-weight: 700; }
.n2 { color: var(--ve); font-weight: 700; }
.n3 { color: var(--script); font-weight: 700; }
.n4 { color: var(--pipe); font-weight: 700; }
.n5 { color: var(--sec); font-weight: 700; }
@media screen and (max-width: 900px) {
.app { height: auto; }
.split { flex-direction: column; }
.board { flex: none; height: 62vh; }
.side { width: auto; }
}
@media print {
.hint, .theme-btn, .zoombar { display: none; }
:root, :root[data-theme=dark] { color-scheme: light; }
svg .dim { opacity: 1; }
svg .flow-dot { display: none; }
.app { height: auto; }
.split { display: block; }
.board { position: static; box-shadow: none; }
.canvas { position: static; overflow: visible; }
.canvas svg { width: 100% !important; height: auto !important; }
.side { width: auto; overflow: visible; }
.card { break-inside: avoid; margin-top: 10px; }
.card.hidden { display: block; }
}
</style>
</head>
<body>
<div class="app">
<div class="head">
<div>
<h1>__DIAGRAM TITLE__</h1>
<div class="sub">__subtitle · date__ · solid blue = OUT direction · dashed green = RETURN direction</div>
</div>
<div style="display:flex; gap:8px;">
<button id="edit-toggle" class="edit-btn" title="Toggle drag-to-rearrange mode">✥ Rearrange</button>
<button id="theme-toggle" class="theme-btn" aria-label="Toggle light/dark mode"></button>
</div>
</div>
<!-- Chips: one per flow, style="color: var(--<flow color>)" — legend AND button in one -->
<div class="chips">
<button class="chip" data-flow="qa" style="color: var(--di)"><i class="dot"></i><span>Q&A (1→n)</span></button>
<button class="chip" data-flow="s" style="color: var(--script)"><i class="dot"></i><span>Scheduled job (S)</span></button>
<span class="hint">Click a flow to see it run end to end · Esc to clear · scroll to zoom · drag to pan</span>
</div>
<div class="split">
<section class="board">
<div class="zoombar">
<button data-z="out" title="Zoom out">−</button>
<span class="pct">100%</span>
<button data-z="in" title="Zoom in">+</button>
<button data-z="fit" title="Fit to view — see the whole system">⤢</button>
</div>
<div class="canvas" id="canvas">
<svg viewBox="0 0 1240 560" xmlns="http://www.w3.org/2000/svg" font-family="inherit">
<!-- LAYOUT PLAN: columns x=60/360/700…, rows y=90/260…, vertical corridors x=…, crossing points: … -->
<defs>
<marker id="m-di" markerWidth="9" markerHeight="9" refX="7.5" refY="4.5" orient="auto"><path d="M1,1 L8,4.5 L1,8" fill="none" stroke="#2563eb" stroke-width="1.6"/></marker>
<marker id="m-ve" markerWidth="9" markerHeight="9" refX="7.5" refY="4.5" orient="auto"><path d="M1,1 L8,4.5 L1,8" fill="none" stroke="#059669" stroke-width="1.6"/></marker>
<marker id="m-sec" markerWidth="9" markerHeight="9" refX="7.5" refY="4.5" orient="auto"><path d="M1,1 L8,4.5 L1,8" fill="none" stroke="#dc2626" stroke-width="1.6"/></marker>
<marker id="m-sc" markerWidth="9" markerHeight="9" refX="7.5" refY="4.5" orient="auto"><path d="M1,1 L8,4.5 L1,8" fill="none" stroke="#7c3aed" stroke-width="1.6"/></marker>
<marker id="m-pi" markerWidth="9" markerHeight="9" refX="7.5" refY="4.5" orient="auto"><path d="M1,1 L8,4.5 L1,8" fill="none" stroke="#d97706" stroke-width="1.6"/></marker>
<!-- Brand logos: copy the <symbol> you need from assets/icons-library.html (Simple Icons, CC0)
in here, then place it inside the box's g: <use href="#ic-mongodb" x="boxX+12" y="boxY+(h-16)/2" width="16" height="16"/> -->
</defs>
<!-- ===== 1. ARROWS (drawn FIRST — boxes painted later cover the overrun) · every line gets data-flow =====
Every arrow with marker-end is immediately followed by 1 <g class="flow-dot" data-flow="...">
containing 2 small <circle> (r≈3.4, fill = SAME hex as the stroke) each carrying an
<animateMotion> that runs along that exact arrow's path (path="M x1,y1 L x2,y2" for a
<line>, or copy the `d` attribute verbatim for a <path>). The 2 dots are phase-offset
(begin=0s and begin=dur/2) so the flow feels continuous, no gap between loops. Duration
dur (seconds) ≈ line length / 260, clamped to [0.6, 2.2]s so short and long lines all look
like they move at the same speed. Do NOT hand-type this for many arrows — generate it with
a script (see the process). Dots are hidden by default (opacity 0); JS reveals them only
when their flow is selected. -->
<line data-flow="qa" x1="230" y1="120" x2="352" y2="120" stroke="#2563eb" stroke-width="1.8" marker-end="url(#m-di)"/><g class="flow-dot" data-flow="qa"><circle r="3.4" fill="#2563eb"><animateMotion dur="1.20s" begin="0.00s" repeatCount="indefinite" path="M230,120 L352,120"/></circle><circle r="3.4" fill="#2563eb"><animateMotion dur="1.20s" begin="0.60s" repeatCount="indefinite" path="M230,120 L352,120"/></circle></g>
<line data-flow="qa" x1="360" y1="150" x2="238" y2="150" stroke="#059669" stroke-width="1.6" stroke-dasharray="6 4" marker-end="url(#m-ve)"/><g class="flow-dot" data-flow="qa"><circle r="3.4" fill="#059669"><animateMotion dur="1.20s" begin="0.00s" repeatCount="indefinite" path="M360,150 L238,150"/></circle><circle r="3.4" fill="#059669"><animateMotion dur="1.20s" begin="0.60s" repeatCount="indefinite" path="M360,150 L238,150"/></circle></g>
<!-- Hop where two lines must cross: curving RIGHT uses A8,8 0 0 1 · curving LEFT uses A8,8 0 0 0 -->
<path data-flow="s" d="M430,300 L552,300 A8,8 0 0 1 568,300 L620,300" fill="none" stroke="#7c3aed" stroke-width="1.6" marker-end="url(#m-sc)"/><g class="flow-dot" data-flow="s"><circle r="3.4" fill="#7c3aed"><animateMotion dur="1.46s" begin="0.00s" repeatCount="indefinite" path="M430,300 L552,300 A8,8 0 0 1 568,300 L620,300"/></circle><circle r="3.4" fill="#7c3aed"><animateMotion dur="1.46s" begin="0.73s" repeatCount="indefinite" path="M430,300 L552,300 A8,8 0 0 1 568,300 L620,300"/></circle></g>
<!-- ===== 2. REGION (dashed group frame) ===== -->
<rect x="40" y="220" width="760" height="240" rx="10" fill="none" stroke="#d97706" stroke-width="1.2" stroke-dasharray="7 5" opacity="0.55"/>
<text x="56" y="244" fill="#d97706" font-size="11" font-weight="700">REGION NAME · SYSTEM GROUP</text>
<!-- ===== 3. BOXES: wrap in g[data-flows="flows passing through"] so dimming works when a flow is selected ===== -->
<g data-flows="qa">
<rect x="60" y="90" width="170" height="64" rx="10" fill="#ffffff" stroke="#d1d5db" stroke-width="1.3"/>
<text x="145" y="116" fill="#1f2937" font-size="12" font-weight="650" text-anchor="middle">BOX A</text>
<text x="145" y="134" fill="#6b7280" font-size="9.5" text-anchor="middle">secondary caption</text>
<g class="flow-ping" data-flow="qa"><rect class="flow-ping-ring" x="60" y="90" width="170" height="64" rx="10" fill="none" stroke="#d1d5db" stroke-width="1.5"/></g></g>
<g data-flows="qa s">
<rect x="360" y="90" width="190" height="64" rx="10" fill="#eff6ff" stroke="#2563eb" stroke-width="1.6"/>
<text x="455" y="116" fill="#1f2937" font-size="12" font-weight="650" text-anchor="middle">BOX B (focal point)</text>
<text x="455" y="134" fill="#6b7280" font-size="9.5" text-anchor="middle">tinted fill + bold border</text>
<g class="flow-ping" data-flow="qa"><rect class="flow-ping-ring" x="360" y="90" width="190" height="64" rx="10" fill="none" stroke="#2563eb" stroke-width="1.5"/></g></g>
<g data-flows="s">
<rect x="628" y="270" width="150" height="60" rx="10" fill="#ffffff" stroke="#d1d5db" stroke-width="1.3"/>
<text x="703" y="296" fill="#1f2937" font-size="11" font-weight="650" text-anchor="middle">BOX C</text>
<text x="703" y="313" fill="#6b7280" font-size="9.5" text-anchor="middle">destination of flow s</text>
<g class="flow-ping" data-flow="s"><rect class="flow-ping-ring" x="628" y="270" width="150" height="60" rx="10" fill="none" stroke="#d1d5db" stroke-width="1.5"/></g></g>
<!-- Security: fill #fef2f2 border #dc2626 · data store: fill #f0f9ff border #0284c7 · secondary: border #e5e7eb -->
<!-- ===== 4. STEP-NUMBER BADGES: g[data-flow][data-step] — panel background, border+text in the flow color ===== -->
<g font-size="9" font-weight="700">
<g data-flow="qa" data-step="1"><circle cx="290" cy="120" r="9" fill="#ffffff" stroke="#2563eb"/><text x="290" y="123.5" fill="#2563eb" text-anchor="middle">1</text></g>
<text data-flow="qa" x="290" y="104" fill="#2563eb" font-size="8.5" text-anchor="middle" font-weight="400">short label</text>
<g data-flow="qa" data-step="2"><circle cx="296" cy="150" r="9" fill="#ffffff" stroke="#059669"/><text x="296" y="153.5" fill="#059669" text-anchor="middle">2</text></g>
<g data-flow="s" data-step="S1"><rect x="587" y="291" width="26" height="17" rx="8.5" fill="#ffffff" stroke="#7c3aed"/><text x="600" y="303" fill="#7c3aed" text-anchor="middle">S1</text></g>
</g>
</svg>
</div>
</section>
<!-- ===== Sidebar: explainer cards — 1 card per flow, data-flow matches the chips/lines ===== -->
<aside class="side">
<div class="cols">
<div class="card" data-flow="qa">
<h3><span class="dot" style="background:var(--di)"></span>Q&A (1→n)</h3>
<ol>
<li><span class="n1">1</span> Box A sends a request to Box B… <span class="n2">2</span> Box B returns the result…</li>
</ol>
</div>
<div class="card" data-flow="s">
<h3><span class="dot" style="background:var(--script)"></span>Scheduled job (S)</h3>
<ul><li><span class="n3">S1</span> Cron fires…</li></ul>
</div>
</div>
</aside>
</div>
</div>
<script>
// Flow-select interaction + zoom/pan + theme — vanilla JS, self-contained.
(() => {
const svg = document.querySelector('svg');
const canvas = document.getElementById('canvas');
const chips = [...document.querySelectorAll('.chip[data-flow]')];
const flowEls = [...svg.querySelectorAll('[data-flow]')];
const nodeEls = [...svg.querySelectorAll('[data-flows]')];
const cards = [...document.querySelectorAll('.side .card')];
const side = document.querySelector('.side');
let cur = null;
function focus(f) {
cur = f;
flowEls.forEach(e => {
const mine = e.dataset.flow === f;
e.classList.toggle('dim', !!f && !mine);
if (e.matches('line, path') || e.classList.contains('flow-dot') || e.classList.contains('flow-ping')) e.classList.toggle('flowing', !!f && mine);
});
nodeEls.forEach(n => n.classList.toggle('dim', !!f && !n.dataset.flows.split(' ').includes(f)));
chips.forEach(c => c.classList.toggle('on', c.dataset.flow === f));
cards.forEach(card => {
card.classList.toggle('hidden', !!f && card.dataset.flow !== f);
card.querySelectorAll('li.hl').forEach(li => li.classList.remove('hl'));
});
side.scrollTop = 0;
}
chips.forEach(c => c.addEventListener('click', () => focus(cur === c.dataset.flow ? null : c.dataset.flow)));
// Zoom & pan: defaults to FIT TO VIEW (whole system visible); +/- or Ctrl+scroll to zoom in; drag to pan
const [,, vbW, vbH] = svg.getAttribute('viewBox').split(/\s+/).map(Number);
const pctEl = document.querySelector('.zoombar .pct');
let fitW = 0, zoom = 1;
const apply = () => {
svg.style.width = (fitW * zoom) + 'px';
svg.style.height = (fitW * zoom * vbH / vbW) + 'px';
pctEl.textContent = Math.round(zoom * 100) + '%';
};
const refit = () => {
const r = canvas.getBoundingClientRect();
fitW = Math.max(120, Math.min(r.width - 20, (r.height - 20) * vbW / vbH));
apply();
};
const setZoom = (z, clientX, clientY) => {
z = Math.min(8, Math.max(1, z));
if (z === zoom) return;
// Anchor by the RATIO of the cursor position inside the SVG — the SVG is centered via
// margin:auto so the margin has to be recomputed after zooming, not derived from the old
// scrollLeft (which is clamped to 0 while the content doesn't yet overflow the viewport).
const cb = canvas.getBoundingClientRect(), sb = svg.getBoundingClientRect();
const ax = clientX ?? cb.left + canvas.clientWidth / 2, ay = clientY ?? cb.top + canvas.clientHeight / 2;
const fx = (ax - sb.left) / sb.width, fy = (ay - sb.top) / sb.height;
zoom = z; apply();
const w = fitW * zoom, h = w * vbH / vbW;
canvas.scrollLeft = Math.max(0, (canvas.clientWidth - w) / 2) + fx * w - (ax - cb.left);
canvas.scrollTop = Math.max(0, (canvas.clientHeight - h) / 2) + fy * h - (ay - cb.top);
};
document.querySelector('.zoombar [data-z="in"]').addEventListener('click', () => setZoom(zoom * 1.25));
document.querySelector('.zoombar [data-z="out"]').addEventListener('click', () => setZoom(zoom / 1.25));
document.querySelector('.zoombar [data-z="fit"]').addEventListener('click', () => { zoom = 1; refit(); canvas.scrollTo(0, 0); });
canvas.addEventListener('wheel', e => {
e.preventDefault(); // scroll = zoom at the cursor (map-style) — trackpad pinch lands here too
setZoom(zoom * (e.deltaY < 0 ? 1.15 : 1 / 1.15), e.clientX, e.clientY);
}, { passive: false });
addEventListener('resize', refit);
refit();
// Drag to pan — distinguished from clicking to select a flow (only counts as a drag past 5px)
let drag = null, moved = false;
canvas.addEventListener('pointerdown', e => {
if (e.button !== 0) return; // left click only — right click opens a context menu that eats pointerup, leaving state stuck
drag = { x: e.clientX, y: e.clientY, sl: canvas.scrollLeft, st: canvas.scrollTop }; moved = false;
});
addEventListener('pointermove', e => {
if (!drag) return;
const dx = e.clientX - drag.x, dy = e.clientY - drag.y;
if (Math.abs(dx) + Math.abs(dy) > 5) { moved = true; canvas.classList.add('panning'); }
if (moved) { canvas.scrollLeft = drag.sl - dx; canvas.scrollTop = drag.st - dy; }
});
const endPan = () => { drag = null; canvas.classList.remove('panning'); };
addEventListener('pointerup', endPan);
addEventListener('pointercancel', endPan);
svg.addEventListener('click', e => {
if (moved) return;
const el = e.target.closest('[data-flow]');
if (!el) { focus(null); return; }
focus(el.dataset.flow);
const step = el.dataset.step; // clicking a badge highlights the matching line in the sidebar
if (step) {
// "5→7" in a card = steps 5, 6, 7 · a merged badge "3·11" = steps 3 and 11
const toks = t => t.trim().split(/[·\/]/).flatMap(p => {
const m = p.match(/^(\d+)→(\d+)$/);
return m ? Array.from({ length: +m[2] - +m[1] + 1 }, (_, i) => String(+m[1] + i)) : p.split('→');
});
const st = toks(step);
const card = document.querySelector(`.side .card[data-flow="${el.dataset.flow}"]`);
if (card) [...card.querySelectorAll('li')].forEach(li =>
li.classList.toggle('hl', [...li.querySelectorAll('span')].some(s => toks(s.textContent).some(x => st.includes(x)))));
}
});
canvas.addEventListener('click', e => { if (!moved && e.target === canvas) focus(null); });
document.addEventListener('keydown', e => { if (e.key === 'Escape') focus(null); });
addEventListener('beforeprint', () => focus(null)); // printing always shows the full, undimmed diagram
// Theme: defaults to the OS setting; the button overrides it and persists to localStorage
const tbtn = document.getElementById('theme-toggle');
const sysDark = matchMedia('(prefers-color-scheme: dark)');
const effTheme = () => document.documentElement.dataset.theme || (sysDark.matches ? 'dark' : 'light');
// Thin-line SVG icon (stroke="currentColor" — recolors with the theme just like text, no
// dependency on the OS's emoji font)
const ICON_SUN = '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round"><circle cx="12" cy="12" r="4"/><path d="M12 2v2M12 20v2M4.93 4.93l1.41 1.41M17.66 17.66l1.41 1.41M2 12h2M20 12h2M6.34 17.66l-1.41 1.41M19.07 4.93l-1.41 1.41"/></svg>';
const ICON_MOON = '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M21 12.79A9 9 0 1 1 11.21 3 7 7 0 0 0 21 12.79Z"/></svg>';
const paintBtn = () => { tbtn.innerHTML = effTheme() === 'dark' ? ICON_SUN : ICON_MOON;
tbtn.title = effTheme() === 'dark' ? 'Switch to light mode' : 'Switch to dark mode'; };
tbtn.addEventListener('click', () => { const n = effTheme() === 'dark' ? 'light' : 'dark';
document.documentElement.dataset.theme = n; try { localStorage.setItem('theme', n); } catch (e) {} paintBtn(); });
sysDark.addEventListener('change', paintBtn);
paintBtn();
// === Drag boxes to rearrange (the "✥ Rearrange" mode, OFF by default) ===
// v1: translates the whole box only; arrows anchored to that box (endpoint within 14 units of
// its edge at load time — matching the skill's "~8px gap" convention) stretch to follow, while
// the corridor waypoints in between STAY PUT (only the final segment touching the dragged box
// stretches — the rest of the route isn't redrawn).
// KNOWN LIMITS: badges/labels on a line do NOT follow along; a dashed region frame does NOT
// grow to keep containing a box dragged out of it — recenter it by eye if that happens.
// Traveling dots (.flow-dot) are hidden while rearranging; each dot's path is refreshed the
// moment the drag ends, so turning rearrange mode back off and reselecting the flow shows the
// dots running along the new position.
const editBtn = document.getElementById('edit-toggle');
const boxGs = [...svg.querySelectorAll('g[data-flows]')];
const arrowEls = [...svg.querySelectorAll('line[data-flow][marker-end], path[data-flow][marker-end]')];
const EDGE_THRESH = 14;
boxGs.forEach(g => {
const r = g.querySelector('rect');
if (!r) return;
g.__box0 = { x: +r.getAttribute('x'), y: +r.getAttribute('y'), w: +r.getAttribute('width'), h: +r.getAttribute('height') };
g.__dx = 0; g.__dy = 0;
});
const edgeGap = (b, px, py) => {
const dx = Math.max(b.x - px, px - (b.x + b.w), 0), dy = Math.max(b.y - py, py - (b.y + b.h), 0);
return Math.hypot(dx, dy);
};
// Read & cache each line's ORIGINAL 2 endpoints once (idempotent) — every later update is
// recomputed from that origin + the box's current delta, never accumulated frame over frame
// (which would drift after several drags).
function endpointsOf(el) {
if (el.__ep0) return el.__ep0;
if (el.tagName === 'line') {
el.__ep0 = [{ x: +el.getAttribute('x1'), y: +el.getAttribute('y1') }, { x: +el.getAttribute('x2'), y: +el.getAttribute('y2') }];
el.__set = (i, nx, ny) => { el.setAttribute(i === 0 ? 'x1' : 'x2', nx); el.setAttribute(i === 0 ? 'y1' : 'y2', ny); };
} else {
const toks0 = el.getAttribute('d').match(/[MLA][^MLA]*/g);
const first = toks0[0].slice(1).trim().split(/[\s,]+/).map(Number);
const lastN = toks0[toks0.length - 1].slice(1).trim().split(/[\s,]+/).map(Number);
el.__ep0 = [{ x: first[0], y: first[1] }, { x: lastN[lastN.length - 2], y: lastN[lastN.length - 1] }];
el.__set = (i, nx, ny) => {
const t = [...toks0];
if (i === 0) { t[0] = `M${nx},${ny}`; }
else {
const last = t[t.length - 1], cmd = last[0];
const n = last.slice(1).trim().split(/[\s,]+/).map(Number);
n[n.length - 2] = nx; n[n.length - 1] = ny;
t[t.length - 1] = cmd + n.join(',');
}
el.setAttribute('d', t.join(' '));
};
}
return el.__ep0;
}
// For each arrow, work out which box (if any) sits close enough to each endpoint — computed once
// at load time from the ORIGINAL coordinates (before anyone drags anything), so dragging never
// shifts this initial assignment.
const arrowAssoc = arrowEls.map(el => {
const eps = endpointsOf(el);
const assoc = eps.map(ep => {
let best = null, bestGap = EDGE_THRESH;
for (const g of boxGs) {
if (!g.__box0) continue;
const gap = edgeGap(g.__box0, ep.x, ep.y);
if (gap < bestGap) { bestGap = gap; best = g; }
}
return best;
});
const dotWrap = el.nextElementSibling && el.nextElementSibling.classList.contains('flow-dot') ? el.nextElementSibling : null;
return { el, assoc, dotWrap };
});
function pathDOf(el) {
if (el.tagName === 'line') return `M${el.getAttribute('x1')},${el.getAttribute('y1')} L${el.getAttribute('x2')},${el.getAttribute('y2')}`;
return el.getAttribute('d');
}
function refreshDots(dotWrap, d) {
if (!dotWrap) return;
dotWrap.querySelectorAll('animateMotion').forEach(am => am.setAttribute('path', d));
}
function moveArrowsFor(g) {
for (const { el, assoc, dotWrap } of arrowAssoc) {
const eps = endpointsOf(el);
let touched = false;
assoc.forEach((box, i) => {
if (box !== g) return;
touched = true;
el.__set(i, eps[i].x + g.__dx, eps[i].y + g.__dy);
});
if (touched) refreshDots(dotWrap, pathDOf(el));
}
}
let editMode = false;
editBtn.addEventListener('click', () => {
editMode = !editMode;
editBtn.classList.toggle('on', editMode);
svg.classList.toggle('edit-mode', editMode);
if (editMode) focus(null); // entering rearrange mode clears the current flow selection to avoid clutter
});
boxGs.forEach(g => {
let dragging = null;
g.addEventListener('pointerdown', e => {
if (!editMode || e.button !== 0 || !g.__box0) return;
e.stopPropagation(); // stop the canvas's own pan handler from also engaging while dragging a box
dragging = { x: e.clientX, y: e.clientY, dx0: g.__dx, dy0: g.__dy };
g.setPointerCapture(e.pointerId);
});
g.addEventListener('pointermove', e => {
if (!dragging) return;
const scale = vbW / (fitW * zoom); // screen px → viewBox units, scaled by the current zoom
g.__dx = dragging.dx0 + (e.clientX - dragging.x) * scale;
g.__dy = dragging.dy0 + (e.clientY - dragging.y) * scale;
g.setAttribute('transform', `translate(${g.__dx},${g.__dy})`);
moveArrowsFor(g);
});
const endDrag = () => { dragging = null; };
g.addEventListener('pointerup', endDrag);
g.addEventListener('pointercancel', endDrag);
});
})();
</script>
</body>
</html>