@shumoku/renderer 0.2.1 → 0.2.4
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/dist/html/index.d.ts +25 -0
- package/dist/html/index.d.ts.map +1 -1
- package/dist/html/index.js +742 -158
- package/dist/html/index.js.map +1 -1
- package/dist/html/navigation.d.ts +54 -0
- package/dist/html/navigation.d.ts.map +1 -0
- package/dist/html/navigation.js +210 -0
- package/dist/html/navigation.js.map +1 -0
- package/dist/html/runtime.d.ts +2 -1
- package/dist/html/runtime.d.ts.map +1 -1
- package/dist/html/runtime.js +245 -482
- package/dist/html/runtime.js.map +1 -1
- package/dist/html/spotlight.d.ts +9 -0
- package/dist/html/spotlight.d.ts.map +1 -0
- package/dist/html/spotlight.js +119 -0
- package/dist/html/spotlight.js.map +1 -0
- package/dist/html/tooltip.d.ts +14 -0
- package/dist/html/tooltip.d.ts.map +1 -0
- package/dist/html/tooltip.js +133 -0
- package/dist/html/tooltip.js.map +1 -0
- package/dist/html/viewbox.d.ts +14 -0
- package/dist/html/viewbox.d.ts.map +1 -0
- package/dist/html/viewbox.js +21 -0
- package/dist/html/viewbox.js.map +1 -0
- package/dist/iife-string.d.ts +2 -0
- package/dist/iife-string.js +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/shumoku-interactive.iife.js +25 -20
- package/dist/svg.d.ts +27 -0
- package/dist/svg.d.ts.map +1 -1
- package/dist/svg.js +202 -101
- package/dist/svg.js.map +1 -1
- package/dist/types.d.ts +2 -0
- package/dist/types.d.ts.map +1 -1
- package/package.json +5 -2
- package/src/build-iife-string.ts +26 -19
- package/src/html/index.ts +880 -226
- package/src/html/navigation.ts +256 -0
- package/src/html/runtime.ts +412 -654
- package/src/html/spotlight.ts +135 -0
- package/src/html/tooltip.ts +141 -0
- package/src/html/viewbox.ts +28 -0
- package/src/index.ts +25 -22
- package/src/svg.ts +1640 -1502
- package/src/types.ts +127 -125
package/dist/html/index.js
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
* Generates standalone interactive HTML pages from NetworkGraph
|
|
4
4
|
*/
|
|
5
5
|
import { SVGRenderer } from '../svg.js';
|
|
6
|
+
import { generateNavigationToolbar, getNavigationScript, getNavigationStyles, } from './navigation.js';
|
|
6
7
|
// Re-export runtime for direct usage
|
|
7
8
|
export { initInteractive } from './runtime.js';
|
|
8
9
|
// IIFE content - will be set by consumer
|
|
@@ -22,181 +23,432 @@ export function getIIFE() {
|
|
|
22
23
|
const DEFAULT_OPTIONS = {
|
|
23
24
|
branding: true,
|
|
24
25
|
toolbar: true,
|
|
26
|
+
hierarchical: false,
|
|
25
27
|
};
|
|
26
28
|
/**
|
|
27
29
|
* Render a complete standalone HTML page from NetworkGraph
|
|
28
30
|
*/
|
|
29
31
|
export function render(graph, layout, options) {
|
|
30
32
|
const opts = { ...DEFAULT_OPTIONS, ...options };
|
|
33
|
+
// Auto-detect hierarchical mode if not explicitly set
|
|
34
|
+
if (options?.hierarchical === undefined) {
|
|
35
|
+
opts.hierarchical = hasHierarchicalContent(graph);
|
|
36
|
+
}
|
|
31
37
|
const svgRenderer = new SVGRenderer({ renderMode: 'interactive' });
|
|
32
38
|
const svg = svgRenderer.render(graph, layout);
|
|
33
39
|
const title = options?.title || graph.name || 'Network Diagram';
|
|
34
|
-
|
|
40
|
+
// Build navigation state if hierarchical
|
|
41
|
+
let navigation = options?.navigation;
|
|
42
|
+
if (!navigation && opts.hierarchical && isHierarchicalGraph(graph)) {
|
|
43
|
+
navigation = buildNavigationState(graph, opts.currentSheet);
|
|
44
|
+
}
|
|
45
|
+
return generateHtml(svg, title, { ...opts, navigation });
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Render a hierarchical HTML page with multiple embedded sheets
|
|
49
|
+
*/
|
|
50
|
+
export function renderHierarchical(sheets, options) {
|
|
51
|
+
const opts = { ...DEFAULT_OPTIONS, ...options, hierarchical: true };
|
|
52
|
+
const sheetSvgs = new Map();
|
|
53
|
+
const sheetInfos = new Map();
|
|
54
|
+
const rootSheet = sheets.get('root');
|
|
55
|
+
// Render child sheets for navigation (detail view when clicking subgraphs)
|
|
56
|
+
for (const [sheetId, data] of sheets) {
|
|
57
|
+
if (sheetId === 'root')
|
|
58
|
+
continue; // Skip root for now
|
|
59
|
+
// Render child sheet
|
|
60
|
+
const svgRenderer = new SVGRenderer({ renderMode: 'interactive', sheetId });
|
|
61
|
+
const svg = svgRenderer.render(data.graph, data.layout);
|
|
62
|
+
sheetSvgs.set(sheetId, svg);
|
|
63
|
+
sheetInfos.set(sheetId, {
|
|
64
|
+
id: sheetId,
|
|
65
|
+
label: data.graph.name || sheetId,
|
|
66
|
+
parentId: 'root',
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
// Render root sheet (ELK handles hierarchical layout natively, no embedding needed)
|
|
70
|
+
if (rootSheet) {
|
|
71
|
+
const rootRenderer = new SVGRenderer({
|
|
72
|
+
renderMode: 'interactive',
|
|
73
|
+
sheetId: 'root',
|
|
74
|
+
});
|
|
75
|
+
const rootSvg = rootRenderer.render(rootSheet.graph, rootSheet.layout);
|
|
76
|
+
sheetSvgs.set('root', rootSvg);
|
|
77
|
+
sheetInfos.set('root', {
|
|
78
|
+
id: 'root',
|
|
79
|
+
label: rootSheet.graph.name || 'root',
|
|
80
|
+
parentId: undefined,
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
// Get title from root sheet
|
|
84
|
+
const title = options?.title || rootSheet?.graph.name || 'Network Diagram';
|
|
85
|
+
// Build navigation state
|
|
86
|
+
const navigation = {
|
|
87
|
+
currentSheet: 'root',
|
|
88
|
+
breadcrumb: ['root'],
|
|
89
|
+
sheets: sheetInfos,
|
|
90
|
+
};
|
|
91
|
+
return generateHierarchicalHtml(sheetSvgs, title, { ...opts, navigation });
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Check if graph is a hierarchical graph
|
|
95
|
+
*/
|
|
96
|
+
function isHierarchicalGraph(graph) {
|
|
97
|
+
return 'sheets' in graph || 'breadcrumb' in graph;
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Check if graph has hierarchical content (subgraphs with file/pins)
|
|
101
|
+
*/
|
|
102
|
+
function hasHierarchicalContent(graph) {
|
|
103
|
+
if (isHierarchicalGraph(graph))
|
|
104
|
+
return true;
|
|
105
|
+
if (!graph.subgraphs)
|
|
106
|
+
return false;
|
|
107
|
+
return graph.subgraphs.some((sg) => sg.file || (sg.pins && sg.pins.length > 0));
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Build navigation state from hierarchical graph
|
|
111
|
+
*/
|
|
112
|
+
function buildNavigationState(graph, currentSheet) {
|
|
113
|
+
const sheets = new Map();
|
|
114
|
+
// Add root
|
|
115
|
+
sheets.set('root', {
|
|
116
|
+
id: 'root',
|
|
117
|
+
label: graph.name || 'Overview',
|
|
118
|
+
});
|
|
119
|
+
// Add sheets from subgraphs
|
|
120
|
+
if (graph.subgraphs) {
|
|
121
|
+
for (const subgraph of graph.subgraphs) {
|
|
122
|
+
if (subgraph.file) {
|
|
123
|
+
sheets.set(subgraph.id, {
|
|
124
|
+
id: subgraph.id,
|
|
125
|
+
label: subgraph.label,
|
|
126
|
+
parentId: 'root',
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
// Add nested sheets
|
|
132
|
+
if (graph.sheets) {
|
|
133
|
+
for (const [id, sheet] of graph.sheets) {
|
|
134
|
+
if (!sheets.has(id)) {
|
|
135
|
+
sheets.set(id, {
|
|
136
|
+
id,
|
|
137
|
+
label: sheet.name || id,
|
|
138
|
+
parentId: graph.parentSheet,
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
// Build breadcrumb
|
|
144
|
+
const breadcrumb = graph.breadcrumb || ['root'];
|
|
145
|
+
if (currentSheet && !breadcrumb.includes(currentSheet)) {
|
|
146
|
+
breadcrumb.push(currentSheet);
|
|
147
|
+
}
|
|
148
|
+
return {
|
|
149
|
+
currentSheet,
|
|
150
|
+
breadcrumb,
|
|
151
|
+
sheets,
|
|
152
|
+
};
|
|
35
153
|
}
|
|
36
154
|
function generateHtml(svg, title, options) {
|
|
37
155
|
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>
|
|
156
|
+
? `<a class="branding" href="https://shumoku.packof.me" target="_blank" rel="noopener">
|
|
157
|
+
<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>
|
|
158
|
+
<span>Made with Shumoku</span>
|
|
41
159
|
</a>`
|
|
42
160
|
: '';
|
|
43
161
|
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>
|
|
162
|
+
? `<div class="toolbar">
|
|
163
|
+
<span class="toolbar-title">${escapeHtml(title)}</span>
|
|
164
|
+
<div class="toolbar-buttons">
|
|
165
|
+
<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>
|
|
166
|
+
<span class="zoom-text" id="zoom">100%</span>
|
|
167
|
+
<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>
|
|
168
|
+
<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>
|
|
169
|
+
<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>
|
|
170
|
+
</div>
|
|
53
171
|
</div>`
|
|
54
172
|
: '';
|
|
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
|
-
function
|
|
144
|
-
var
|
|
145
|
-
var
|
|
146
|
-
var scale = origVb.w /
|
|
147
|
-
|
|
148
|
-
vb.
|
|
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
|
-
var
|
|
185
|
-
var
|
|
186
|
-
|
|
187
|
-
vb.
|
|
188
|
-
updateViewBox();
|
|
189
|
-
});
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
173
|
+
// Navigation toolbar for hierarchical diagrams
|
|
174
|
+
const navToolbarHtml = options.hierarchical && options.navigation ? generateNavigationToolbar(options.navigation) : '';
|
|
175
|
+
// Navigation styles
|
|
176
|
+
const navStyles = options.hierarchical ? getNavigationStyles() : '';
|
|
177
|
+
// Navigation scripts
|
|
178
|
+
const navScript = options.hierarchical ? getNavigationScript() : '';
|
|
179
|
+
// Calculate container height based on toolbar presence
|
|
180
|
+
const headerHeight = options.toolbar ? 45 : 0;
|
|
181
|
+
const navHeight = options.hierarchical && options.navigation ? 60 : 0;
|
|
182
|
+
const totalHeaderHeight = headerHeight + navHeight;
|
|
183
|
+
const containerHeight = totalHeaderHeight > 0 ? `calc(100vh - ${totalHeaderHeight}px)` : '100vh';
|
|
184
|
+
return `<!DOCTYPE html>
|
|
185
|
+
<html>
|
|
186
|
+
<head>
|
|
187
|
+
<meta charset="UTF-8">
|
|
188
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
189
|
+
<title>${escapeHtml(title)}</title>
|
|
190
|
+
<style>
|
|
191
|
+
* { margin: 0; padding: 0; box-sizing: border-box; }
|
|
192
|
+
body { background: #f5f5f5; min-height: 100vh; font-family: system-ui, -apple-system, sans-serif; }
|
|
193
|
+
.toolbar { display: flex; align-items: center; justify-content: space-between; padding: 8px 16px; background: white; border-bottom: 1px solid #e5e5e5; }
|
|
194
|
+
.toolbar-title { font-size: 14px; color: #666; }
|
|
195
|
+
.toolbar-buttons { display: flex; gap: 4px; align-items: center; }
|
|
196
|
+
.toolbar button { padding: 6px; border: none; background: none; cursor: pointer; border-radius: 4px; color: #666; }
|
|
197
|
+
.toolbar button:hover { background: #f0f0f0; }
|
|
198
|
+
.zoom-text { min-width: 50px; text-align: center; font-size: 13px; color: #666; }
|
|
199
|
+
.container { position: relative; width: 100%; height: ${containerHeight}; overflow: hidden; cursor: grab; background: repeating-conic-gradient(#f8f8f8 0% 25%, transparent 0% 50%) 50% / 20px 20px; }
|
|
200
|
+
.container.dragging { cursor: grabbing; }
|
|
201
|
+
.container > svg { width: 100%; height: 100%; }
|
|
202
|
+
.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; }
|
|
203
|
+
.branding:hover { color: #222; box-shadow: 0 4px 12px rgba(0,0,0,0.15); }
|
|
204
|
+
.branding-icon { width: 16px; height: 16px; border-radius: 3px; flex-shrink: 0; }
|
|
205
|
+
/* SVG interactive styles */
|
|
206
|
+
.node { cursor: pointer; }
|
|
207
|
+
.node:hover rect, .node:hover circle, .node:hover polygon { filter: brightness(0.95); }
|
|
208
|
+
.port { cursor: pointer; }
|
|
209
|
+
.link-hit-area { cursor: pointer; }
|
|
210
|
+
/* Subgraph click for hierarchical navigation */
|
|
211
|
+
.subgraph[data-has-sheet] { cursor: pointer; }
|
|
212
|
+
.subgraph[data-has-sheet]:hover > rect { filter: brightness(0.95); }
|
|
213
|
+
${navStyles}
|
|
214
|
+
</style>
|
|
215
|
+
</head>
|
|
216
|
+
<body>
|
|
217
|
+
${toolbarHtml}
|
|
218
|
+
${navToolbarHtml}
|
|
219
|
+
<div class="container" id="container">
|
|
220
|
+
${svg}
|
|
221
|
+
${brandingHtml}
|
|
222
|
+
</div>
|
|
223
|
+
<script>${INTERACTIVE_IIFE}</script>
|
|
224
|
+
<script>
|
|
225
|
+
(function() {
|
|
226
|
+
var svg = document.querySelector('#container > svg');
|
|
227
|
+
var container = document.getElementById('container');
|
|
228
|
+
if (!svg || !container) { console.error('SVG or container not found'); return; }
|
|
229
|
+
|
|
230
|
+
var vb = { x: 0, y: 0, w: 0, h: 0 };
|
|
231
|
+
var origVb = { x: 0, y: 0, w: 0, h: 0 };
|
|
232
|
+
var drag = { active: false, x: 0, y: 0, vx: 0, vy: 0 };
|
|
233
|
+
|
|
234
|
+
function init() {
|
|
235
|
+
var w = parseFloat(svg.getAttribute('width')) || 800;
|
|
236
|
+
var h = parseFloat(svg.getAttribute('height')) || 600;
|
|
237
|
+
var existing = svg.getAttribute('viewBox');
|
|
238
|
+
if (existing) {
|
|
239
|
+
var p = existing.split(/\\s+|,/).map(Number);
|
|
240
|
+
origVb = { x: p[0] || 0, y: p[1] || 0, w: p[2] || w, h: p[3] || h };
|
|
241
|
+
} else {
|
|
242
|
+
origVb = { x: 0, y: 0, w: w, h: h };
|
|
243
|
+
}
|
|
244
|
+
svg.removeAttribute('width');
|
|
245
|
+
svg.removeAttribute('height');
|
|
246
|
+
svg.style.width = '100%';
|
|
247
|
+
svg.style.height = '100%';
|
|
248
|
+
fitView();
|
|
249
|
+
|
|
250
|
+
if (window.ShumokuInteractive) {
|
|
251
|
+
window.ShumokuInteractive.initInteractive({ target: svg, modal: { enabled: true }, tooltip: { enabled: true }, panZoom: { enabled: false } });
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
function updateViewBox() {
|
|
256
|
+
svg.setAttribute('viewBox', vb.x + ' ' + vb.y + ' ' + vb.w + ' ' + vb.h);
|
|
257
|
+
var zoomEl = document.getElementById('zoom');
|
|
258
|
+
if (zoomEl) zoomEl.textContent = Math.round(origVb.w / vb.w * 100) + '%';
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
function fitView() {
|
|
262
|
+
var cw = container.clientWidth || 800;
|
|
263
|
+
var ch = container.clientHeight || 600;
|
|
264
|
+
var scale = Math.min(cw / origVb.w, ch / origVb.h) * 0.9;
|
|
265
|
+
vb.w = cw / scale;
|
|
266
|
+
vb.h = ch / scale;
|
|
267
|
+
vb.x = origVb.x + (origVb.w - vb.w) / 2;
|
|
268
|
+
vb.y = origVb.y + (origVb.h - vb.h) / 2;
|
|
269
|
+
updateViewBox();
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
function resetView() {
|
|
273
|
+
vb.x = origVb.x; vb.y = origVb.y; vb.w = origVb.w; vb.h = origVb.h;
|
|
274
|
+
updateViewBox();
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
function zoom(f) {
|
|
278
|
+
var cx = vb.x + vb.w / 2, cy = vb.y + vb.h / 2;
|
|
279
|
+
var nw = vb.w / f, nh = vb.h / f;
|
|
280
|
+
var scale = origVb.w / nw;
|
|
281
|
+
if (scale < 0.1 || scale > 10) return;
|
|
282
|
+
vb.w = nw; vb.h = nh; vb.x = cx - nw / 2; vb.y = cy - nh / 2;
|
|
283
|
+
updateViewBox();
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
var btnIn = document.getElementById('btn-in');
|
|
287
|
+
var btnOut = document.getElementById('btn-out');
|
|
288
|
+
var btnFit = document.getElementById('btn-fit');
|
|
289
|
+
var btnReset = document.getElementById('btn-reset');
|
|
290
|
+
if (btnIn) btnIn.addEventListener('click', function() { zoom(1.2); });
|
|
291
|
+
if (btnOut) btnOut.addEventListener('click', function() { zoom(1/1.2); });
|
|
292
|
+
if (btnFit) btnFit.addEventListener('click', fitView);
|
|
293
|
+
if (btnReset) btnReset.addEventListener('click', resetView);
|
|
294
|
+
|
|
295
|
+
container.addEventListener('wheel', function(e) {
|
|
296
|
+
e.preventDefault();
|
|
297
|
+
var rect = container.getBoundingClientRect();
|
|
298
|
+
var mx = (e.clientX - rect.left) / rect.width;
|
|
299
|
+
var my = (e.clientY - rect.top) / rect.height;
|
|
300
|
+
var px = vb.x + vb.w * mx, py = vb.y + vb.h * my;
|
|
301
|
+
var f = e.deltaY > 0 ? 1/1.2 : 1.2;
|
|
302
|
+
var nw = vb.w / f, nh = vb.h / f;
|
|
303
|
+
var scale = origVb.w / nw;
|
|
304
|
+
if (scale < 0.1 || scale > 10) return;
|
|
305
|
+
vb.w = nw; vb.h = nh; vb.x = px - nw * mx; vb.y = py - nh * my;
|
|
306
|
+
updateViewBox();
|
|
307
|
+
}, { passive: false });
|
|
308
|
+
|
|
309
|
+
container.addEventListener('mousedown', function(e) {
|
|
310
|
+
if (e.button === 0) {
|
|
311
|
+
drag = { active: true, x: e.clientX, y: e.clientY, vx: vb.x, vy: vb.y };
|
|
312
|
+
container.classList.add('dragging');
|
|
313
|
+
}
|
|
314
|
+
});
|
|
315
|
+
|
|
316
|
+
document.addEventListener('mousemove', function(e) {
|
|
317
|
+
if (!drag.active) return;
|
|
318
|
+
var sx = vb.w / container.clientWidth;
|
|
319
|
+
var sy = vb.h / container.clientHeight;
|
|
320
|
+
vb.x = drag.vx - (e.clientX - drag.x) * sx;
|
|
321
|
+
vb.y = drag.vy - (e.clientY - drag.y) * sy;
|
|
322
|
+
updateViewBox();
|
|
323
|
+
});
|
|
324
|
+
|
|
325
|
+
document.addEventListener('mouseup', function() {
|
|
326
|
+
drag.active = false;
|
|
327
|
+
container.classList.remove('dragging');
|
|
328
|
+
});
|
|
329
|
+
|
|
330
|
+
// Touch events for pan/zoom
|
|
331
|
+
var pinch = null;
|
|
332
|
+
var touch1 = null;
|
|
333
|
+
var hasMoved = false;
|
|
334
|
+
var DRAG_THRESHOLD = 8;
|
|
335
|
+
|
|
336
|
+
function getTouchDist(t) {
|
|
337
|
+
if (t.length < 2) return 0;
|
|
338
|
+
return Math.hypot(t[1].clientX - t[0].clientX, t[1].clientY - t[0].clientY);
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
function getTouchCenter(t) {
|
|
342
|
+
return { x: (t[0].clientX + t[1].clientX) / 2, y: (t[0].clientY + t[1].clientY) / 2 };
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
container.addEventListener('touchstart', function(e) {
|
|
346
|
+
// Skip if touching branding link
|
|
347
|
+
if (e.target.closest && e.target.closest('.branding')) return;
|
|
348
|
+
|
|
349
|
+
if (e.touches.length === 1) {
|
|
350
|
+
// Single finger - potential pan or tap
|
|
351
|
+
touch1 = { x: e.touches[0].clientX, y: e.touches[0].clientY, vx: vb.x, vy: vb.y };
|
|
352
|
+
hasMoved = false;
|
|
353
|
+
} else if (e.touches.length >= 2) {
|
|
354
|
+
// Two fingers - pinch zoom
|
|
355
|
+
e.preventDefault();
|
|
356
|
+
touch1 = null;
|
|
357
|
+
hasMoved = true;
|
|
358
|
+
var dist = getTouchDist(e.touches);
|
|
359
|
+
var center = getTouchCenter(e.touches);
|
|
360
|
+
var rect = container.getBoundingClientRect();
|
|
361
|
+
pinch = {
|
|
362
|
+
dist: dist,
|
|
363
|
+
vb: { x: vb.x, y: vb.y, w: vb.w, h: vb.h },
|
|
364
|
+
cx: vb.x + vb.w * ((center.x - rect.left) / rect.width),
|
|
365
|
+
cy: vb.y + vb.h * ((center.y - rect.top) / rect.height),
|
|
366
|
+
lastCenter: center
|
|
367
|
+
};
|
|
368
|
+
}
|
|
369
|
+
}, { passive: false });
|
|
370
|
+
|
|
371
|
+
container.addEventListener('touchmove', function(e) {
|
|
372
|
+
// Skip if touching branding link
|
|
373
|
+
if (e.target.closest && e.target.closest('.branding')) return;
|
|
374
|
+
|
|
375
|
+
if (e.touches.length === 1 && touch1) {
|
|
376
|
+
var dx = e.touches[0].clientX - touch1.x;
|
|
377
|
+
var dy = e.touches[0].clientY - touch1.y;
|
|
378
|
+
|
|
379
|
+
// Check if moved beyond threshold
|
|
380
|
+
if (!hasMoved && Math.hypot(dx, dy) > DRAG_THRESHOLD) {
|
|
381
|
+
hasMoved = true;
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
if (hasMoved) {
|
|
385
|
+
e.preventDefault();
|
|
386
|
+
var sx = vb.w / container.clientWidth;
|
|
387
|
+
var sy = vb.h / container.clientHeight;
|
|
388
|
+
vb.x = touch1.vx - dx * sx;
|
|
389
|
+
vb.y = touch1.vy - dy * sy;
|
|
390
|
+
updateViewBox();
|
|
391
|
+
}
|
|
392
|
+
} else if (e.touches.length >= 2 && pinch) {
|
|
393
|
+
e.preventDefault();
|
|
394
|
+
var dist = getTouchDist(e.touches);
|
|
395
|
+
var center = getTouchCenter(e.touches);
|
|
396
|
+
if (dist === 0 || pinch.dist === 0) return;
|
|
397
|
+
|
|
398
|
+
var scale = dist / pinch.dist;
|
|
399
|
+
var nw = pinch.vb.w / scale;
|
|
400
|
+
var nh = pinch.vb.h / scale;
|
|
401
|
+
var newScale = origVb.w / nw;
|
|
402
|
+
if (newScale < 0.1 || newScale > 10) return;
|
|
403
|
+
|
|
404
|
+
var rect = container.getBoundingClientRect();
|
|
405
|
+
var sx = nw / rect.width;
|
|
406
|
+
var sy = nh / rect.height;
|
|
407
|
+
var panX = (center.x - pinch.lastCenter.x) * sx;
|
|
408
|
+
var panY = (center.y - pinch.lastCenter.y) * sy;
|
|
409
|
+
|
|
410
|
+
var mx = (center.x - rect.left) / rect.width;
|
|
411
|
+
var my = (center.y - rect.top) / rect.height;
|
|
412
|
+
vb.x = pinch.cx - nw * mx - panX;
|
|
413
|
+
vb.y = pinch.cy - nh * my - panY;
|
|
414
|
+
vb.w = nw;
|
|
415
|
+
vb.h = nh;
|
|
416
|
+
updateViewBox();
|
|
417
|
+
}
|
|
418
|
+
}, { passive: false });
|
|
419
|
+
|
|
420
|
+
container.addEventListener('touchend', function(e) {
|
|
421
|
+
if (e.touches.length === 0) {
|
|
422
|
+
touch1 = null;
|
|
423
|
+
pinch = null;
|
|
424
|
+
hasMoved = false;
|
|
425
|
+
} else if (e.touches.length === 1) {
|
|
426
|
+
pinch = null;
|
|
427
|
+
touch1 = { x: e.touches[0].clientX, y: e.touches[0].clientY, vx: vb.x, vy: vb.y };
|
|
428
|
+
hasMoved = true; // Already moving
|
|
429
|
+
}
|
|
430
|
+
});
|
|
431
|
+
|
|
432
|
+
container.addEventListener('touchcancel', function() {
|
|
433
|
+
touch1 = null;
|
|
434
|
+
pinch = null;
|
|
435
|
+
hasMoved = false;
|
|
436
|
+
});
|
|
437
|
+
|
|
438
|
+
// Listen for hierarchical navigation events
|
|
439
|
+
document.addEventListener('shumoku:navigate', function(e) {
|
|
440
|
+
var sheetId = e.detail && e.detail.sheetId;
|
|
441
|
+
if (sheetId) {
|
|
442
|
+
console.log('[Shumoku] Navigate to sheet:', sheetId);
|
|
443
|
+
alert('Navigate to: ' + sheetId + '\\n\\nThis sheet would show the detailed view of this subgraph.');
|
|
444
|
+
}
|
|
445
|
+
});
|
|
446
|
+
|
|
447
|
+
init();
|
|
448
|
+
})();
|
|
449
|
+
</script>
|
|
450
|
+
<script>${navScript}</script>
|
|
451
|
+
</body>
|
|
200
452
|
</html>`;
|
|
201
453
|
}
|
|
202
454
|
function escapeHtml(str) {
|
|
@@ -207,4 +459,336 @@ function escapeHtml(str) {
|
|
|
207
459
|
.replace(/"/g, '"')
|
|
208
460
|
.replace(/'/g, ''');
|
|
209
461
|
}
|
|
462
|
+
/**
|
|
463
|
+
* Generate HTML with multiple embedded sheets for hierarchical navigation
|
|
464
|
+
*/
|
|
465
|
+
function generateHierarchicalHtml(sheetSvgs, title, options) {
|
|
466
|
+
const brandingHtml = options.branding
|
|
467
|
+
? `<a class="branding" href="https://shumoku.packof.me" target="_blank" rel="noopener">
|
|
468
|
+
<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>
|
|
469
|
+
<span>Made with Shumoku</span>
|
|
470
|
+
</a>`
|
|
471
|
+
: '';
|
|
472
|
+
const toolbarHtml = options.toolbar
|
|
473
|
+
? `<div class="toolbar">
|
|
474
|
+
<span class="toolbar-title" id="sheet-title">${escapeHtml(title)}</span>
|
|
475
|
+
<div class="toolbar-buttons">
|
|
476
|
+
<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>
|
|
477
|
+
<span class="zoom-text" id="zoom">100%</span>
|
|
478
|
+
<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>
|
|
479
|
+
<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>
|
|
480
|
+
<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>
|
|
481
|
+
</div>
|
|
482
|
+
</div>`
|
|
483
|
+
: '';
|
|
484
|
+
// Build sheet containers
|
|
485
|
+
const sheetContainers = [];
|
|
486
|
+
for (const [sheetId, svg] of sheetSvgs) {
|
|
487
|
+
const isRoot = sheetId === 'root';
|
|
488
|
+
const display = isRoot ? 'block' : 'none';
|
|
489
|
+
sheetContainers.push(`<div class="sheet-container" data-sheet-id="${escapeHtml(sheetId)}" style="display: ${display};">
|
|
490
|
+
${svg}
|
|
491
|
+
</div>`);
|
|
492
|
+
}
|
|
493
|
+
// Build sheet info JSON for JavaScript
|
|
494
|
+
const sheetInfoJson = {};
|
|
495
|
+
for (const [id, info] of options.navigation?.sheets || []) {
|
|
496
|
+
sheetInfoJson[id] = { label: info.label, parentId: info.parentId };
|
|
497
|
+
}
|
|
498
|
+
const headerHeight = options.toolbar ? 45 : 0;
|
|
499
|
+
const containerHeight = headerHeight > 0 ? `calc(100vh - ${headerHeight}px)` : '100vh';
|
|
500
|
+
return `<!DOCTYPE html>
|
|
501
|
+
<html>
|
|
502
|
+
<head>
|
|
503
|
+
<meta charset="UTF-8">
|
|
504
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
505
|
+
<title>${escapeHtml(title)}</title>
|
|
506
|
+
<style>
|
|
507
|
+
* { margin: 0; padding: 0; box-sizing: border-box; }
|
|
508
|
+
body { background: #f5f5f5; min-height: 100vh; font-family: system-ui, -apple-system, sans-serif; }
|
|
509
|
+
.toolbar { display: flex; align-items: center; justify-content: space-between; padding: 8px 16px; background: white; border-bottom: 1px solid #e5e5e5; }
|
|
510
|
+
.toolbar-title { font-size: 14px; color: #666; display: flex; align-items: center; gap: 8px; }
|
|
511
|
+
.toolbar-buttons { display: flex; gap: 4px; align-items: center; }
|
|
512
|
+
.toolbar button { padding: 6px; border: none; background: none; cursor: pointer; border-radius: 4px; color: #666; }
|
|
513
|
+
.toolbar button:hover { background: #f0f0f0; }
|
|
514
|
+
.zoom-text { min-width: 50px; text-align: center; font-size: 13px; color: #666; }
|
|
515
|
+
.back-btn { display: inline-flex; align-items: center; gap: 4px; padding: 4px 8px; border: 1px solid #ddd; background: white; border-radius: 4px; cursor: pointer; font-size: 13px; color: #555; }
|
|
516
|
+
.back-btn:hover { background: #f5f5f5; }
|
|
517
|
+
.back-btn svg { width: 14px; height: 14px; }
|
|
518
|
+
.container { position: relative; width: 100%; height: ${containerHeight}; overflow: hidden; cursor: grab; background: repeating-conic-gradient(#f8f8f8 0% 25%, transparent 0% 50%) 50% / 20px 20px; }
|
|
519
|
+
.container.dragging { cursor: grabbing; }
|
|
520
|
+
.sheet-container { width: 100%; height: 100%; }
|
|
521
|
+
.sheet-container > svg { width: 100%; height: 100%; }
|
|
522
|
+
.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; }
|
|
523
|
+
.branding:hover { color: #222; box-shadow: 0 4px 12px rgba(0,0,0,0.15); }
|
|
524
|
+
.branding-icon { width: 16px; height: 16px; border-radius: 3px; flex-shrink: 0; }
|
|
525
|
+
.node { cursor: pointer; }
|
|
526
|
+
.node:hover rect, .node:hover circle, .node:hover polygon { filter: brightness(0.95); }
|
|
527
|
+
.port { cursor: pointer; }
|
|
528
|
+
.link-hit-area { cursor: pointer; }
|
|
529
|
+
.subgraph[data-has-sheet] { cursor: pointer; }
|
|
530
|
+
.subgraph[data-has-sheet]:hover > rect { filter: brightness(0.95); }
|
|
531
|
+
</style>
|
|
532
|
+
</head>
|
|
533
|
+
<body>
|
|
534
|
+
${toolbarHtml}
|
|
535
|
+
<div class="container" id="container">
|
|
536
|
+
${sheetContainers.join('\n ')}
|
|
537
|
+
${brandingHtml}
|
|
538
|
+
</div>
|
|
539
|
+
<script>${INTERACTIVE_IIFE}</script>
|
|
540
|
+
<script>
|
|
541
|
+
(function() {
|
|
542
|
+
var sheetInfo = ${JSON.stringify(sheetInfoJson)};
|
|
543
|
+
var currentSheet = 'root';
|
|
544
|
+
var breadcrumb = ['root'];
|
|
545
|
+
var sheetViewBoxes = {};
|
|
546
|
+
var container = document.getElementById('container');
|
|
547
|
+
|
|
548
|
+
function getActiveSheet() {
|
|
549
|
+
return container.querySelector('.sheet-container[data-sheet-id="' + currentSheet + '"]');
|
|
550
|
+
}
|
|
551
|
+
|
|
552
|
+
function getActiveSvg() {
|
|
553
|
+
var sheet = getActiveSheet();
|
|
554
|
+
return sheet ? sheet.querySelector('svg') : null;
|
|
555
|
+
}
|
|
556
|
+
|
|
557
|
+
function initSheet(sheetId) {
|
|
558
|
+
var sheet = container.querySelector('.sheet-container[data-sheet-id="' + sheetId + '"]');
|
|
559
|
+
if (!sheet) return;
|
|
560
|
+
var svg = sheet.querySelector('svg');
|
|
561
|
+
if (!svg) return;
|
|
562
|
+
|
|
563
|
+
var w = parseFloat(svg.getAttribute('width')) || 800;
|
|
564
|
+
var h = parseFloat(svg.getAttribute('height')) || 600;
|
|
565
|
+
var existing = svg.getAttribute('viewBox');
|
|
566
|
+
var vb;
|
|
567
|
+
if (existing) {
|
|
568
|
+
var p = existing.split(/\\s+|,/).map(Number);
|
|
569
|
+
vb = { x: p[0] || 0, y: p[1] || 0, w: p[2] || w, h: p[3] || h, origX: p[0] || 0, origY: p[1] || 0, origW: p[2] || w, origH: p[3] || h };
|
|
570
|
+
} else {
|
|
571
|
+
vb = { x: 0, y: 0, w: w, h: h, origX: 0, origY: 0, origW: w, origH: h };
|
|
572
|
+
}
|
|
573
|
+
sheetViewBoxes[sheetId] = vb;
|
|
574
|
+
|
|
575
|
+
svg.removeAttribute('width');
|
|
576
|
+
svg.removeAttribute('height');
|
|
577
|
+
svg.style.width = '100%';
|
|
578
|
+
svg.style.height = '100%';
|
|
579
|
+
|
|
580
|
+
// Fit view
|
|
581
|
+
var cw = container.clientWidth || 800;
|
|
582
|
+
var ch = container.clientHeight || 600;
|
|
583
|
+
var scale = Math.min(cw / vb.origW, ch / vb.origH) * 0.9;
|
|
584
|
+
vb.w = cw / scale;
|
|
585
|
+
vb.h = ch / scale;
|
|
586
|
+
vb.x = vb.origX + (vb.origW - vb.w) / 2;
|
|
587
|
+
vb.y = vb.origY + (vb.origH - vb.h) / 2;
|
|
588
|
+
svg.setAttribute('viewBox', vb.x + ' ' + vb.y + ' ' + vb.w + ' ' + vb.h);
|
|
589
|
+
|
|
590
|
+
if (window.ShumokuInteractive) {
|
|
591
|
+
window.ShumokuInteractive.initInteractive({ target: svg, modal: { enabled: true }, tooltip: { enabled: true }, panZoom: { enabled: false } });
|
|
592
|
+
}
|
|
593
|
+
}
|
|
594
|
+
|
|
595
|
+
function updateViewBox() {
|
|
596
|
+
var svg = getActiveSvg();
|
|
597
|
+
var vb = sheetViewBoxes[currentSheet];
|
|
598
|
+
if (!svg || !vb) return;
|
|
599
|
+
svg.setAttribute('viewBox', vb.x + ' ' + vb.y + ' ' + vb.w + ' ' + vb.h);
|
|
600
|
+
var zoomEl = document.getElementById('zoom');
|
|
601
|
+
if (zoomEl) zoomEl.textContent = Math.round(vb.origW / vb.w * 100) + '%';
|
|
602
|
+
}
|
|
603
|
+
|
|
604
|
+
function updateTitle() {
|
|
605
|
+
var titleEl = document.getElementById('sheet-title');
|
|
606
|
+
if (!titleEl) return;
|
|
607
|
+
var info = sheetInfo[currentSheet];
|
|
608
|
+
var label = info ? info.label : currentSheet;
|
|
609
|
+
|
|
610
|
+
if (currentSheet === 'root') {
|
|
611
|
+
titleEl.innerHTML = label;
|
|
612
|
+
} else {
|
|
613
|
+
titleEl.innerHTML = '<button class="back-btn" id="back-btn"><svg fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15 19l-7-7 7-7"/></svg></button>' + label;
|
|
614
|
+
document.getElementById('back-btn').addEventListener('click', function() {
|
|
615
|
+
navigateToSheet('root');
|
|
616
|
+
});
|
|
617
|
+
}
|
|
618
|
+
}
|
|
619
|
+
|
|
620
|
+
function navigateToSheet(sheetId) {
|
|
621
|
+
if (sheetId === currentSheet) return;
|
|
622
|
+
if (!container.querySelector('.sheet-container[data-sheet-id="' + sheetId + '"]')) {
|
|
623
|
+
console.warn('[Shumoku] Sheet not found:', sheetId);
|
|
624
|
+
return;
|
|
625
|
+
}
|
|
626
|
+
|
|
627
|
+
// Hide current
|
|
628
|
+
var current = getActiveSheet();
|
|
629
|
+
if (current) current.style.display = 'none';
|
|
630
|
+
|
|
631
|
+
// Show new
|
|
632
|
+
currentSheet = sheetId;
|
|
633
|
+
var newSheet = getActiveSheet();
|
|
634
|
+
if (newSheet) {
|
|
635
|
+
newSheet.style.display = 'block';
|
|
636
|
+
if (!sheetViewBoxes[sheetId]) {
|
|
637
|
+
initSheet(sheetId);
|
|
638
|
+
}
|
|
639
|
+
}
|
|
640
|
+
|
|
641
|
+
// Update breadcrumb
|
|
642
|
+
if (sheetId === 'root') {
|
|
643
|
+
breadcrumb = ['root'];
|
|
644
|
+
} else {
|
|
645
|
+
breadcrumb = ['root', sheetId];
|
|
646
|
+
}
|
|
647
|
+
|
|
648
|
+
updateTitle();
|
|
649
|
+
updateViewBox();
|
|
650
|
+
}
|
|
651
|
+
|
|
652
|
+
// Zoom functions
|
|
653
|
+
function zoom(f) {
|
|
654
|
+
var vb = sheetViewBoxes[currentSheet];
|
|
655
|
+
if (!vb) return;
|
|
656
|
+
var cx = vb.x + vb.w / 2, cy = vb.y + vb.h / 2;
|
|
657
|
+
var nw = vb.w / f, nh = vb.h / f;
|
|
658
|
+
var scale = vb.origW / nw;
|
|
659
|
+
if (scale < 0.1 || scale > 10) return;
|
|
660
|
+
vb.w = nw; vb.h = nh; vb.x = cx - nw / 2; vb.y = cy - nh / 2;
|
|
661
|
+
updateViewBox();
|
|
662
|
+
}
|
|
663
|
+
|
|
664
|
+
function fitView() {
|
|
665
|
+
var vb = sheetViewBoxes[currentSheet];
|
|
666
|
+
if (!vb) return;
|
|
667
|
+
var cw = container.clientWidth || 800;
|
|
668
|
+
var ch = container.clientHeight || 600;
|
|
669
|
+
var scale = Math.min(cw / vb.origW, ch / vb.origH) * 0.9;
|
|
670
|
+
vb.w = cw / scale;
|
|
671
|
+
vb.h = ch / scale;
|
|
672
|
+
vb.x = vb.origX + (vb.origW - vb.w) / 2;
|
|
673
|
+
vb.y = vb.origY + (vb.origH - vb.h) / 2;
|
|
674
|
+
updateViewBox();
|
|
675
|
+
}
|
|
676
|
+
|
|
677
|
+
function resetView() {
|
|
678
|
+
var vb = sheetViewBoxes[currentSheet];
|
|
679
|
+
if (!vb) return;
|
|
680
|
+
vb.x = vb.origX; vb.y = vb.origY; vb.w = vb.origW; vb.h = vb.origH;
|
|
681
|
+
updateViewBox();
|
|
682
|
+
}
|
|
683
|
+
|
|
684
|
+
// Toolbar buttons
|
|
685
|
+
var btnIn = document.getElementById('btn-in');
|
|
686
|
+
var btnOut = document.getElementById('btn-out');
|
|
687
|
+
var btnFit = document.getElementById('btn-fit');
|
|
688
|
+
var btnReset = document.getElementById('btn-reset');
|
|
689
|
+
if (btnIn) btnIn.addEventListener('click', function() { zoom(1.2); });
|
|
690
|
+
if (btnOut) btnOut.addEventListener('click', function() { zoom(1/1.2); });
|
|
691
|
+
if (btnFit) btnFit.addEventListener('click', fitView);
|
|
692
|
+
if (btnReset) btnReset.addEventListener('click', resetView);
|
|
693
|
+
|
|
694
|
+
// Mouse drag
|
|
695
|
+
var drag = { active: false, x: 0, y: 0 };
|
|
696
|
+
|
|
697
|
+
container.addEventListener('mousedown', function(e) {
|
|
698
|
+
if (e.button === 0) {
|
|
699
|
+
var vb = sheetViewBoxes[currentSheet];
|
|
700
|
+
if (!vb) return;
|
|
701
|
+
drag = { active: true, x: e.clientX, y: e.clientY, vx: vb.x, vy: vb.y };
|
|
702
|
+
container.classList.add('dragging');
|
|
703
|
+
}
|
|
704
|
+
});
|
|
705
|
+
|
|
706
|
+
document.addEventListener('mousemove', function(e) {
|
|
707
|
+
if (!drag.active) return;
|
|
708
|
+
var vb = sheetViewBoxes[currentSheet];
|
|
709
|
+
if (!vb) return;
|
|
710
|
+
var sx = vb.w / container.clientWidth;
|
|
711
|
+
var sy = vb.h / container.clientHeight;
|
|
712
|
+
vb.x = drag.vx - (e.clientX - drag.x) * sx;
|
|
713
|
+
vb.y = drag.vy - (e.clientY - drag.y) * sy;
|
|
714
|
+
updateViewBox();
|
|
715
|
+
});
|
|
716
|
+
|
|
717
|
+
document.addEventListener('mouseup', function() {
|
|
718
|
+
drag.active = false;
|
|
719
|
+
container.classList.remove('dragging');
|
|
720
|
+
});
|
|
721
|
+
|
|
722
|
+
// Wheel zoom
|
|
723
|
+
container.addEventListener('wheel', function(e) {
|
|
724
|
+
e.preventDefault();
|
|
725
|
+
var vb = sheetViewBoxes[currentSheet];
|
|
726
|
+
if (!vb) return;
|
|
727
|
+
var rect = container.getBoundingClientRect();
|
|
728
|
+
var mx = (e.clientX - rect.left) / rect.width;
|
|
729
|
+
var my = (e.clientY - rect.top) / rect.height;
|
|
730
|
+
var px = vb.x + vb.w * mx, py = vb.y + vb.h * my;
|
|
731
|
+
var f = e.deltaY > 0 ? 1/1.2 : 1.2;
|
|
732
|
+
var nw = vb.w / f, nh = vb.h / f;
|
|
733
|
+
var scale = vb.origW / nw;
|
|
734
|
+
if (scale < 0.1 || scale > 10) return;
|
|
735
|
+
vb.w = nw; vb.h = nh; vb.x = px - nw * mx; vb.y = py - nh * my;
|
|
736
|
+
updateViewBox();
|
|
737
|
+
}, { passive: false });
|
|
738
|
+
|
|
739
|
+
// Navigation event listener
|
|
740
|
+
document.addEventListener('shumoku:navigate', function(e) {
|
|
741
|
+
var sheetId = e.detail && e.detail.sheetId;
|
|
742
|
+
if (sheetId) {
|
|
743
|
+
navigateToSheet(sheetId);
|
|
744
|
+
}
|
|
745
|
+
});
|
|
746
|
+
|
|
747
|
+
// Touch support (simplified)
|
|
748
|
+
var touch1 = null;
|
|
749
|
+
var hasMoved = false;
|
|
750
|
+
|
|
751
|
+
container.addEventListener('touchstart', function(e) {
|
|
752
|
+
if (e.target.closest && e.target.closest('.branding')) return;
|
|
753
|
+
if (e.touches.length === 1) {
|
|
754
|
+
var vb = sheetViewBoxes[currentSheet];
|
|
755
|
+
if (vb) {
|
|
756
|
+
touch1 = { x: e.touches[0].clientX, y: e.touches[0].clientY, vx: vb.x, vy: vb.y };
|
|
757
|
+
hasMoved = false;
|
|
758
|
+
}
|
|
759
|
+
}
|
|
760
|
+
}, { passive: false });
|
|
761
|
+
|
|
762
|
+
container.addEventListener('touchmove', function(e) {
|
|
763
|
+
if (e.target.closest && e.target.closest('.branding')) return;
|
|
764
|
+
if (e.touches.length === 1 && touch1) {
|
|
765
|
+
var vb = sheetViewBoxes[currentSheet];
|
|
766
|
+
if (!vb) return;
|
|
767
|
+
var dx = e.touches[0].clientX - touch1.x;
|
|
768
|
+
var dy = e.touches[0].clientY - touch1.y;
|
|
769
|
+
if (!hasMoved && Math.hypot(dx, dy) > 8) hasMoved = true;
|
|
770
|
+
if (hasMoved) {
|
|
771
|
+
e.preventDefault();
|
|
772
|
+
var sx = vb.w / container.clientWidth;
|
|
773
|
+
var sy = vb.h / container.clientHeight;
|
|
774
|
+
vb.x = touch1.vx - dx * sx;
|
|
775
|
+
vb.y = touch1.vy - dy * sy;
|
|
776
|
+
updateViewBox();
|
|
777
|
+
}
|
|
778
|
+
}
|
|
779
|
+
}, { passive: false });
|
|
780
|
+
|
|
781
|
+
container.addEventListener('touchend', function() {
|
|
782
|
+
touch1 = null;
|
|
783
|
+
hasMoved = false;
|
|
784
|
+
});
|
|
785
|
+
|
|
786
|
+
// Initialize root sheet
|
|
787
|
+
initSheet('root');
|
|
788
|
+
updateTitle();
|
|
789
|
+
})();
|
|
790
|
+
</script>
|
|
791
|
+
</body>
|
|
792
|
+
</html>`;
|
|
793
|
+
}
|
|
210
794
|
//# sourceMappingURL=index.js.map
|