forked from ZenUml/core
-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathindex.html
More file actions
232 lines (212 loc) · 6.81 KB
/
index.html
File metadata and controls
232 lines (212 loc) · 6.81 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
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<!-- <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin /> -->
<!-- <link
rel="preload stylesheet"
as="style"
href="https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800&family=JetBrains+Mono:wght@400;500&display=swap"
/> -->
<style id="zenumlstyle">
/* Custom styles for the diagram */
</style>
<link
rel="stylesheet"
href="/vendor/highlightjs/github-dark.min.css"
/>
<script src="/vendor/codemirror/codemirror.min.js"></script>
<link
rel="stylesheet"
href="/vendor/codemirror/codemirror.min.css"
/>
<link
rel="stylesheet"
href="/vendor/codemirror/material-darker.min.css"
/>
<title>ZenUML - Local Development</title>
<style>
* {
font-family:
"Inter",
-apple-system,
BlinkMacSystemFont,
"Segoe UI",
"Roboto",
sans-serif;
}
code,
.CodeMirror {
font-family: "JetBrains Mono", "Monaco", "Consolas", monospace;
}
.CodeMirror {
font-size: 14px;
height: 100%;
overflow: hidden;
}
.CodeMirror-scroll {
padding: 1rem;
}
.zenuml .CodeMirror .CodeMirror-cursor {
border-color: #fff;
border-left-width: 2px;
}
.gradient-text {
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
background-clip: text;
}
.editor-shadow {
box-shadow:
0 20px 25px -5px rgba(0, 0, 0, 0.1),
0 10px 10px -5px rgba(0, 0, 0, 0.04);
}
</style>
<script src="/vendor/tailwindcss/tailwindcss.js"></script>
</head>
<body class="bg-gray-50">
<!-- Main Editor Section -->
<div class="w-full h-screen p-4">
<div class="grid grid-cols-3 gap-4 h-full" id="diagram1">
<!-- Editor Panel -->
<div
class="bg-white rounded-lg shadow-lg editor-shadow overflow-hidden h-full"
>
<div
class="bg-gray-800 text-white px-4 py-3 flex items-center justify-between"
>
<h3 class="font-medium">Editor</h3>
<div class="flex space-x-2">
<button
onclick="loadExample('basic')"
class="text-sm bg-gray-700 hover:bg-gray-600 px-3 py-1 rounded transition-colors"
>
Basic
</button>
<button
onclick="loadExample('advanced')"
class="text-sm bg-gray-700 hover:bg-gray-600 px-3 py-1 rounded transition-colors"
>
Advanced
</button>
<button
onclick="clearEditor()"
class="text-sm bg-gray-700 hover:bg-gray-600 px-3 py-1 rounded transition-colors"
>
Clear
</button>
<button
onclick="exportDiagram()"
class="text-sm bg-blue-600 hover:bg-blue-700 px-3 py-1 rounded transition-colors"
>
Export PNG
</button>
</div>
</div>
<div style="height: calc(100% - 52px)">
<textarea id="text" style="display: none"></textarea>
</div>
</div>
<!-- Preview Panel -->
<div
class="bg-white rounded-lg shadow-lg editor-shadow overflow-hidden h-full col-span-2"
>
<div class="bg-gray-800 text-white px-4 py-3">
<h3 class="font-medium">Preview</h3>
</div>
<div style="height: calc(100% - 52px); overflow: auto" class="p-4">
<pre class="zenuml" style="margin: 0"></pre>
</div>
</div>
</div>
</div>
<script type="module">
import { waitUntil, debounce } from "./src/utils.ts";
import { createConfig } from "./src/config.ts";
import { toPng } from "html-to-image";
const editor = CodeMirror.fromTextArea(document.getElementById("text"), {
lineNumbers: true,
singleCursorHeightPerLine: false,
theme: "material-darker",
mode: "text/plain",
autofocus: true,
});
const updateDiagram = debounce((content) => {
const config = createConfig({
onContentChange: (code) => editor.setValue(code),
});
window.zenUml.render(content, config).then((r) => {
window.parentLogger
.child({ name: "index.html" })
.debug("render resolved", r);
});
}, 500);
editor.on("change", function (cm) {
waitUntil(
() => window.zenUml,
() => {
updateDiagram(cm.getValue());
// Save to localStorage
localStorage.setItem("zenuml-cm-code", cm.getValue());
},
);
});
// Example data
const examples = {
basic: `Alice -> Bob: Hello Bob!
Bob -> Alice: Hello Alice!`,
advanced: `title Online Shopping
participant Customer
participant WebApp
participant PaymentService
participant Database
Customer -> WebApp: Browse products
WebApp -> Database: Query products
Database --> WebApp: Return products
WebApp --> Customer: Display products
Customer -> WebApp: Add to cart
WebApp -> Database: Update cart
Database --> WebApp: Cart updated
WebApp --> Customer: Show cart
Customer -> WebApp: Checkout
WebApp -> PaymentService: Process payment
PaymentService --> WebApp: Payment confirmed
WebApp -> Database: Create order
Database --> WebApp: Order created
WebApp --> Customer: Order confirmation`,
};
// Global functions
window.loadExample = function (type) {
editor.setValue(examples[type] || examples.basic);
};
window.clearEditor = function () {
editor.setValue("");
};
window.exportDiagram = async function () {
const element = document.querySelector(".zenuml");
if (element) {
try {
const dataUrl = await toPng(element);
const link = document.createElement("a");
link.download = "sequence-diagram.png";
link.href = dataUrl;
link.click();
} catch (error) {
console.error("Failed to export diagram:", error);
}
}
};
// Load saved code from localStorage or default example
const savedCode = localStorage.getItem("zenuml-cm-code");
if (savedCode) {
editor.setValue(savedCode);
} else {
editor.setValue(examples.basic);
}
</script>
<script type="module" src="/src/main.tsx"></script>
</body>
</html>