@shumoku/renderer 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.
@@ -0,0 +1,9 @@
1
+ /**
2
+ * IIFE entry point - exposes API to window.ShumokuInteractive
3
+ */
4
+ import { initInteractive } from './runtime.js';
5
+ declare const ShumokuInteractive: {
6
+ initInteractive: typeof initInteractive;
7
+ };
8
+ export { ShumokuInteractive };
9
+ //# sourceMappingURL=iife-entry.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"iife-entry.d.ts","sourceRoot":"","sources":["../../src/html/iife-entry.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAA;AAE9C,QAAA,MAAM,kBAAkB;;CAAsB,CAE7C;AAGD,OAAO,EAAE,kBAAkB,EAAE,CAAA"}
@@ -0,0 +1,9 @@
1
+ /**
2
+ * IIFE entry point - exposes API to window.ShumokuInteractive
3
+ */
4
+ import { initInteractive } from './runtime.js';
5
+ const ShumokuInteractive = { initInteractive };
6
+ window.ShumokuInteractive =
7
+ ShumokuInteractive;
8
+ export { ShumokuInteractive };
9
+ //# sourceMappingURL=iife-entry.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"iife-entry.js","sourceRoot":"","sources":["../../src/html/iife-entry.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAA;AAE9C,MAAM,kBAAkB,GAAG,EAAE,eAAe,EAAE,CAE7C;AAAC,MAAuE,CAAC,kBAAkB;IAC1F,kBAAkB,CAAA;AAEpB,OAAO,EAAE,kBAAkB,EAAE,CAAA"}
@@ -0,0 +1,23 @@
1
+ /**
2
+ * HTML Renderer
3
+ * Generates standalone interactive HTML pages from NetworkGraph
4
+ */
5
+ import type { LayoutResult, NetworkGraph } from '@shumoku/core';
6
+ import type { HTMLRendererOptions } from '../types.js';
7
+ export type { InteractiveInstance, InteractiveOptions } from '../types.js';
8
+ export { initInteractive } from './runtime.js';
9
+ /**
10
+ * Set the IIFE content for standalone HTML pages
11
+ */
12
+ export declare function setIIFE(iife: string): void;
13
+ /**
14
+ * Get the current IIFE content
15
+ */
16
+ export declare function getIIFE(): string;
17
+ export interface RenderOptions extends HTMLRendererOptions {
18
+ }
19
+ /**
20
+ * Render a complete standalone HTML page from NetworkGraph
21
+ */
22
+ export declare function render(graph: NetworkGraph, layout: LayoutResult, options?: RenderOptions): string;
23
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/html/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,eAAe,CAAA;AAE/D,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAA;AAEtD,YAAY,EAAE,mBAAmB,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAA;AAE1E,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAA;AAK9C;;GAEG;AACH,wBAAgB,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAE1C;AAED;;GAEG;AACH,wBAAgB,OAAO,IAAI,MAAM,CAEhC;AAED,MAAM,WAAW,aAAc,SAAQ,mBAAmB;CAAG;AAO7D;;GAEG;AACH,wBAAgB,MAAM,CAAC,KAAK,EAAE,YAAY,EAAE,MAAM,EAAE,YAAY,EAAE,OAAO,CAAC,EAAE,aAAa,GAAG,MAAM,CAOjG"}
@@ -0,0 +1,210 @@
1
+ /**
2
+ * HTML Renderer
3
+ * Generates standalone interactive HTML pages from NetworkGraph
4
+ */
5
+ import { SVGRenderer } from '../svg.js';
6
+ // Re-export runtime for direct usage
7
+ export { initInteractive } from './runtime.js';
8
+ // IIFE content - will be set by consumer
9
+ let INTERACTIVE_IIFE = '';
10
+ /**
11
+ * Set the IIFE content for standalone HTML pages
12
+ */
13
+ export function setIIFE(iife) {
14
+ INTERACTIVE_IIFE = iife;
15
+ }
16
+ /**
17
+ * Get the current IIFE content
18
+ */
19
+ export function getIIFE() {
20
+ return INTERACTIVE_IIFE;
21
+ }
22
+ const DEFAULT_OPTIONS = {
23
+ branding: true,
24
+ toolbar: true,
25
+ };
26
+ /**
27
+ * Render a complete standalone HTML page from NetworkGraph
28
+ */
29
+ export function render(graph, layout, options) {
30
+ const opts = { ...DEFAULT_OPTIONS, ...options };
31
+ const svgRenderer = new SVGRenderer({ renderMode: 'interactive' });
32
+ const svg = svgRenderer.render(graph, layout);
33
+ const title = options?.title || graph.name || 'Network Diagram';
34
+ return generateHtml(svg, title, opts);
35
+ }
36
+ function generateHtml(svg, title, options) {
37
+ const brandingHtml = options.branding
38
+ ? `<a class="branding" href="https://shumoku.packof.me" target="_blank" rel="noopener">
39
+ <svg class="branding-icon" viewBox="0 0 1024 1024" fill="none"><rect x="64" y="64" width="896" height="896" rx="200" fill="#7FE4C1"/><g transform="translate(90,40) scale(1.25)"><path fill="#1F2328" d="M380 340H450V505H700V555H510V645H450V645H380Z"/></g></svg>
40
+ <span>Made with Shumoku</span>
41
+ </a>`
42
+ : '';
43
+ const toolbarHtml = options.toolbar
44
+ ? `<div class="toolbar">
45
+ <span class="toolbar-title">${escapeHtml(title)}</span>
46
+ <div class="toolbar-buttons">
47
+ <button id="btn-out" title="Zoom Out"><svg width="20" height="20" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-width="2" d="M20 12H4"/></svg></button>
48
+ <span class="zoom-text" id="zoom">100%</span>
49
+ <button id="btn-in" title="Zoom In"><svg width="20" height="20" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-width="2" d="M12 4v16m8-8H4"/></svg></button>
50
+ <button id="btn-fit" title="Fit"><svg width="20" height="20" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-width="2" d="M4 8V4m0 0h4M4 4l5 5m11-1V4m0 0h-4m4 0l-5 5M4 16v4m0 0h4m-4 0l5-5m11 5l-5-5m5 5v-4m0 4h-4"/></svg></button>
51
+ <button id="btn-reset" title="Reset"><svg width="20" height="20" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-width="2" d="M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15"/></svg></button>
52
+ </div>
53
+ </div>`
54
+ : '';
55
+ return `<!DOCTYPE html>
56
+ <html>
57
+ <head>
58
+ <meta charset="UTF-8">
59
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
60
+ <title>${escapeHtml(title)}</title>
61
+ <style>
62
+ * { margin: 0; padding: 0; box-sizing: border-box; }
63
+ body { background: #f5f5f5; min-height: 100vh; }
64
+ .toolbar { display: flex; align-items: center; justify-content: space-between; padding: 8px 16px; background: white; border-bottom: 1px solid #e5e5e5; }
65
+ .toolbar-title { font-size: 14px; color: #666; }
66
+ .toolbar-buttons { display: flex; gap: 4px; align-items: center; }
67
+ .toolbar button { padding: 6px; border: none; background: none; cursor: pointer; border-radius: 4px; color: #666; }
68
+ .toolbar button:hover { background: #f0f0f0; }
69
+ .zoom-text { min-width: 50px; text-align: center; font-size: 13px; color: #666; }
70
+ .container { position: relative; width: 100%; height: ${options.toolbar ? 'calc(100vh - 45px)' : '100vh'}; overflow: hidden; cursor: grab; background: repeating-conic-gradient(#f8f8f8 0% 25%, transparent 0% 50%) 50% / 20px 20px; }
71
+ .container.dragging { cursor: grabbing; }
72
+ .container > svg { width: 100%; height: 100%; }
73
+ .branding { position: absolute; bottom: 16px; right: 16px; display: flex; align-items: center; gap: 8px; padding: 8px 12px; background: rgba(255,255,255,0.95); backdrop-filter: blur(8px); border: 1px solid rgba(0,0,0,0.1); border-radius: 8px; font-size: 13px; font-family: system-ui, sans-serif; color: #555; text-decoration: none; transition: all 0.2s; box-shadow: 0 2px 8px rgba(0,0,0,0.1); z-index: 100; }
74
+ .branding:hover { color: #222; box-shadow: 0 4px 12px rgba(0,0,0,0.15); }
75
+ .branding-icon { width: 16px; height: 16px; border-radius: 3px; flex-shrink: 0; }
76
+ /* SVG interactive styles */
77
+ .node { cursor: pointer; }
78
+ .node:hover rect, .node:hover circle, .node:hover polygon { filter: brightness(0.95); }
79
+ .port { cursor: pointer; }
80
+ .link-hit-area { cursor: pointer; }
81
+ </style>
82
+ </head>
83
+ <body>
84
+ ${toolbarHtml}
85
+ <div class="container" id="container">
86
+ ${svg}
87
+ ${brandingHtml}
88
+ </div>
89
+ <script>${INTERACTIVE_IIFE}</script>
90
+ <script>
91
+ (function() {
92
+ var svg = document.querySelector('#container > svg');
93
+ var container = document.getElementById('container');
94
+ if (!svg || !container) { console.error('SVG or container not found'); return; }
95
+
96
+ var vb = { x: 0, y: 0, w: 0, h: 0 };
97
+ var origVb = { x: 0, y: 0, w: 0, h: 0 };
98
+ var drag = { active: false, x: 0, y: 0, vx: 0, vy: 0 };
99
+
100
+ function init() {
101
+ var w = parseFloat(svg.getAttribute('width')) || 800;
102
+ var h = parseFloat(svg.getAttribute('height')) || 600;
103
+ var existing = svg.getAttribute('viewBox');
104
+ if (existing) {
105
+ var p = existing.split(/\\s+|,/).map(Number);
106
+ origVb = { x: p[0] || 0, y: p[1] || 0, w: p[2] || w, h: p[3] || h };
107
+ } else {
108
+ origVb = { x: 0, y: 0, w: w, h: h };
109
+ }
110
+ svg.removeAttribute('width');
111
+ svg.removeAttribute('height');
112
+ svg.style.width = '100%';
113
+ svg.style.height = '100%';
114
+ fitView();
115
+
116
+ if (window.ShumokuInteractive) {
117
+ window.ShumokuInteractive.initInteractive({ target: svg, modal: { enabled: true }, tooltip: { enabled: true }, panZoom: { enabled: false } });
118
+ }
119
+ }
120
+
121
+ function updateViewBox() {
122
+ svg.setAttribute('viewBox', vb.x + ' ' + vb.y + ' ' + vb.w + ' ' + vb.h);
123
+ var zoomEl = document.getElementById('zoom');
124
+ if (zoomEl) zoomEl.textContent = Math.round(origVb.w / vb.w * 100) + '%';
125
+ }
126
+
127
+ function fitView() {
128
+ var cw = container.clientWidth || 800;
129
+ var ch = container.clientHeight || 600;
130
+ var scale = Math.min(cw / origVb.w, ch / origVb.h) * 0.9;
131
+ vb.w = cw / scale;
132
+ vb.h = ch / scale;
133
+ vb.x = origVb.x + (origVb.w - vb.w) / 2;
134
+ vb.y = origVb.y + (origVb.h - vb.h) / 2;
135
+ updateViewBox();
136
+ }
137
+
138
+ function resetView() {
139
+ vb.x = origVb.x; vb.y = origVb.y; vb.w = origVb.w; vb.h = origVb.h;
140
+ updateViewBox();
141
+ }
142
+
143
+ function zoom(f) {
144
+ var cx = vb.x + vb.w / 2, cy = vb.y + vb.h / 2;
145
+ var nw = vb.w / f, nh = vb.h / f;
146
+ var scale = origVb.w / nw;
147
+ if (scale < 0.1 || scale > 10) return;
148
+ vb.w = nw; vb.h = nh; vb.x = cx - nw / 2; vb.y = cy - nh / 2;
149
+ updateViewBox();
150
+ }
151
+
152
+ var btnIn = document.getElementById('btn-in');
153
+ var btnOut = document.getElementById('btn-out');
154
+ var btnFit = document.getElementById('btn-fit');
155
+ var btnReset = document.getElementById('btn-reset');
156
+ if (btnIn) btnIn.addEventListener('click', function() { zoom(1.2); });
157
+ if (btnOut) btnOut.addEventListener('click', function() { zoom(1/1.2); });
158
+ if (btnFit) btnFit.addEventListener('click', fitView);
159
+ if (btnReset) btnReset.addEventListener('click', resetView);
160
+
161
+ container.addEventListener('wheel', function(e) {
162
+ e.preventDefault();
163
+ var rect = container.getBoundingClientRect();
164
+ var mx = (e.clientX - rect.left) / rect.width;
165
+ var my = (e.clientY - rect.top) / rect.height;
166
+ var px = vb.x + vb.w * mx, py = vb.y + vb.h * my;
167
+ var f = e.deltaY > 0 ? 1/1.2 : 1.2;
168
+ var nw = vb.w / f, nh = vb.h / f;
169
+ var scale = origVb.w / nw;
170
+ if (scale < 0.1 || scale > 10) return;
171
+ vb.w = nw; vb.h = nh; vb.x = px - nw * mx; vb.y = py - nh * my;
172
+ updateViewBox();
173
+ }, { passive: false });
174
+
175
+ container.addEventListener('mousedown', function(e) {
176
+ if (e.button === 0) {
177
+ drag = { active: true, x: e.clientX, y: e.clientY, vx: vb.x, vy: vb.y };
178
+ container.classList.add('dragging');
179
+ }
180
+ });
181
+
182
+ document.addEventListener('mousemove', function(e) {
183
+ if (!drag.active) return;
184
+ var sx = vb.w / container.clientWidth;
185
+ var sy = vb.h / container.clientHeight;
186
+ vb.x = drag.vx - (e.clientX - drag.x) * sx;
187
+ vb.y = drag.vy - (e.clientY - drag.y) * sy;
188
+ updateViewBox();
189
+ });
190
+
191
+ document.addEventListener('mouseup', function() {
192
+ drag.active = false;
193
+ container.classList.remove('dragging');
194
+ });
195
+
196
+ init();
197
+ })();
198
+ </script>
199
+ </body>
200
+ </html>`;
201
+ }
202
+ function escapeHtml(str) {
203
+ return str
204
+ .replace(/&/g, '&amp;')
205
+ .replace(/</g, '&lt;')
206
+ .replace(/>/g, '&gt;')
207
+ .replace(/"/g, '&quot;')
208
+ .replace(/'/g, '&#39;');
209
+ }
210
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/html/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAE,WAAW,EAAE,MAAM,WAAW,CAAA;AAIvC,qCAAqC;AACrC,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAA;AAE9C,yCAAyC;AACzC,IAAI,gBAAgB,GAAG,EAAE,CAAA;AAEzB;;GAEG;AACH,MAAM,UAAU,OAAO,CAAC,IAAY;IAClC,gBAAgB,GAAG,IAAI,CAAA;AACzB,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,OAAO;IACrB,OAAO,gBAAgB,CAAA;AACzB,CAAC;AAID,MAAM,eAAe,GAAG;IACtB,QAAQ,EAAE,IAAI;IACd,OAAO,EAAE,IAAI;CACd,CAAA;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AAC,IAAI,EAAE,MAAM,CAAC;SACrB,OAAO,CAAC,IAAI,EAAE,MAAM,CAAC;SACrB,OAAO,CAAC,IAAI,EAAE,QAAQ,CAAC;SACvB,OAAO,CAAC,IAAI,EAAE,OAAO,CAAC,CAAA;AAC3B,CAAC"}
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Interactive Runtime - Hover tooltip with touch support and pan/zoom
3
+ */
4
+ import type { InteractiveInstance, InteractiveOptions } from '../types.js';
5
+ export declare function initInteractive(options: InteractiveOptions): InteractiveInstance;
6
+ //# sourceMappingURL=runtime.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"runtime.d.ts","sourceRoot":"","sources":["../../src/html/runtime.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,mBAAmB,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAA;AAsQ1E,wBAAgB,eAAe,CAAC,OAAO,EAAE,kBAAkB,GAAG,mBAAmB,CAmYhF"}