-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfullscreen.html
More file actions
686 lines (597 loc) · 23 KB
/
Copy pathfullscreen.html
File metadata and controls
686 lines (597 loc) · 23 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
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
<!DOCTYPE html>
<html lang="zh-TW">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>TeamSync 圖表全螢幕檢視</title>
<script src="https://cdn.jsdelivr.net/npm/mermaid@10/dist/mermaid.min.js"></script>
<style>
body {
margin: 0;
padding: 0;
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
background: #ffffff;
overflow: hidden;
height: 100vh;
display: flex;
flex-direction: column;
}
.header {
background: white;
padding: 1rem 2rem;
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
display: flex;
justify-content: space-between;
align-items: center;
z-index: 100;
}
.title {
font-size: 1.5rem;
font-weight: 600;
color: #2d3748;
}
.close-button {
background: #f7fafc;
border: none;
width: 48px;
height: 48px;
border-radius: 12px;
display: flex;
align-items: center;
justify-content: center;
font-size: 1.5rem;
cursor: pointer;
transition: all 0.3s ease;
}
.close-button:hover {
background: #e2e8f0;
transform: rotate(90deg);
}
.diagram-container {
flex: 1;
background: #f5f5f5;
overflow: auto;
position: relative;
cursor: grab;
}
.diagram-container:active {
cursor: grabbing;
}
.diagram-scroll-area {
position: relative;
width: 300vw;
height: 300vh;
display: flex;
justify-content: center;
align-items: center;
background-image:
linear-gradient(rgba(0,0,0,0.03) 1px, transparent 1px),
linear-gradient(90deg, rgba(0,0,0,0.03) 1px, transparent 1px);
background-size: 50px 50px;
}
#diagram-wrapper {
transform-origin: center center;
transition: transform 0.3s ease;
display: inline-flex;
justify-content: center;
align-items: center;
position: relative;
background: white;
padding: 2rem;
border-radius: 8px;
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}
.mermaid {
background: white !important;
}
.mermaid svg {
background: white !important;
max-width: none !important;
height: auto !important;
}
.zoom-controls {
position: fixed;
bottom: 2rem;
left: 2rem;
display: flex;
gap: 0.5rem;
background: rgba(255, 255, 255, 0.95);
backdrop-filter: blur(10px);
padding: 0.5rem;
border-radius: 12px;
box-shadow: 0 4px 20px rgba(0, 0, 0, 0.2);
border: 1px solid rgba(255, 255, 255, 0.8);
z-index: 100;
}
.zoom-btn {
width: 40px;
height: 40px;
border: none;
background: #f7fafc;
border-radius: 8px;
cursor: pointer;
font-size: 1.25rem;
display: flex;
align-items: center;
justify-content: center;
transition: all 0.2s ease;
}
.zoom-btn:hover {
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
color: white;
transform: scale(1.1);
}
.loading {
color: #667eea;
font-size: 1.5rem;
}
/* 響應式設計 - 平板 */
@media (max-width: 1024px) {
.header {
padding: 1rem 1.5rem;
}
.zoom-controls {
bottom: 1.5rem;
left: 1.5rem;
}
.hint {
bottom: 1.5rem;
right: 1.5rem;
}
}
/* 響應式設計 - 手機 */
@media (max-width: 768px) {
.header {
padding: 0.75rem 1rem;
}
.title {
font-size: 1.25rem;
}
.close-button {
width: 40px;
height: 40px;
border-radius: 10px;
font-size: 1.25rem;
}
.diagram-container {
overflow: auto;
-webkit-overflow-scrolling: touch;
}
#diagram-wrapper {
padding: 1rem;
}
.zoom-controls {
bottom: 1rem;
left: 1rem;
flex-direction: column;
gap: 0.375rem;
padding: 0.375rem;
border-radius: 10px;
}
.zoom-btn {
width: 36px;
height: 36px;
font-size: 1.125rem;
border-radius: 6px;
}
.hint {
bottom: 1rem;
right: 1rem;
padding: 0.5rem 0.875rem;
font-size: 0.75rem;
max-width: 180px;
text-align: center;
line-height: 1.4;
}
/* 手機上隱藏網格背景 */
.diagram-scroll-area {
background-image: none;
background-color: #f5f5f5;
}
}
/* 超小螢幕 */
@media (max-width: 480px) {
.header {
padding: 0.5rem 0.75rem;
}
.title {
font-size: 1.125rem;
}
.close-button {
width: 36px;
height: 36px;
font-size: 1.125rem;
}
.zoom-controls {
bottom: 0.75rem;
left: 0.75rem;
gap: 0.25rem;
padding: 0.25rem;
}
.zoom-btn {
width: 32px;
height: 32px;
font-size: 1rem;
}
.hint {
display: none; /* 在超小螢幕隱藏提示 */
}
#diagram-wrapper {
padding: 0.5rem;
box-shadow: 0 1px 5px rgba(0, 0, 0, 0.1);
}
}
/* 觸控設備優化 */
@media (hover: none) and (pointer: coarse) {
.close-button:active {
transform: scale(0.95);
background: #cbd5e0;
}
.zoom-btn:active {
transform: scale(0.9);
}
/* 觸控設備的提示文字 */
.hint {
content: "雙指縮放 | 滑動查看";
}
}
/* 橫向模式優化 */
@media (max-width: 768px) and (orientation: landscape) {
.header {
padding: 0.5rem 1rem;
}
.zoom-controls {
flex-direction: row;
bottom: 0.5rem;
left: 0.5rem;
}
.hint {
bottom: 0.5rem;
right: 0.5rem;
}
}
.hint {
position: fixed;
bottom: 2rem;
right: 2rem;
background: rgba(255, 255, 255, 0.95);
backdrop-filter: blur(10px);
padding: 0.75rem 1.25rem;
border-radius: 8px;
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
color: #4a5568;
font-size: 0.875rem;
z-index: 100;
}
</style>
</head>
<body>
<div class="header">
<h1 class="title" id="diagram-title">圖表檢視</h1>
<button class="close-button" onclick="closeWindow()">✕</button>
</div>
<div class="diagram-container">
<div class="diagram-scroll-area">
<div id="diagram-wrapper">
<div class="loading">載入中...</div>
</div>
</div>
<div class="zoom-controls">
<button class="zoom-btn" onclick="zoomDiagram('in')" title="放大">➕</button>
<button class="zoom-btn" onclick="zoomDiagram('out')" title="縮小">➖</button>
<button class="zoom-btn" onclick="zoomDiagram('reset')" title="重置">🔄</button>
<button class="zoom-btn" onclick="zoomDiagram('fit')" title="適應螢幕">📐</button>
</div>
<div class="hint">
💡 提示:拖曳移動圖表 | Ctrl/Cmd + 滾輪縮放
</div>
</div>
<script>
let currentZoom = 1;
// 初始化 Mermaid
mermaid.initialize({
startOnLoad: false,
theme: 'default',
securityLevel: 'loose',
themeVariables: {
primaryColor: '#e8f4ff',
primaryBorderColor: '#667eea',
primaryTextColor: '#000000',
lineColor: '#4a5568',
background: '#ffffff',
mainBkg: '#e8f4ff',
nodeBkg: '#e8f4ff',
nodeTextColor: '#000000',
edgeLabelBackground: '#ffffff',
clusterBkg: '#f7fafc',
clusterBorder: '#667eea',
// 確保所有文字和線條都清晰可見
labelTextColor: '#000000',
actorTextColor: '#000000',
signalTextColor: '#000000',
noteBkgColor: '#fffacd',
noteTextColor: '#000000'
},
flowchart: {
useMaxWidth: false,
htmlLabels: true,
nodeSpacing: 50,
rankSpacing: 50
}
});
// 從 localStorage 獲取圖表資料
let diagramData = null;
try {
const storedData = localStorage.getItem('fullscreen-diagram');
if (storedData) {
diagramData = JSON.parse(storedData);
// 清理超過 5 分鐘的數據
if (Date.now() - diagramData.timestamp > 5 * 60 * 1000) {
localStorage.removeItem('fullscreen-diagram');
diagramData = null;
}
}
} catch (error) {
console.error('讀取 localStorage 失敗:', error);
}
// 如果沒有 localStorage 數據,嘗試從 URL 參數讀取(向後兼容)
if (!diagramData) {
const params = new URLSearchParams(window.location.search);
const code = params.get('code');
const title = params.get('title');
if (code) {
diagramData = {
code: decodeURIComponent(code),
title: title ? decodeURIComponent(title) : '圖表檢視'
};
}
}
// 設置標題
if (diagramData && diagramData.title) {
document.getElementById('diagram-title').textContent = diagramData.title;
}
// 渲染圖表
async function renderDiagram() {
if (!diagramData || !diagramData.code) {
document.getElementById('diagram-wrapper').innerHTML =
'<div style="color: #e53e3e;">無法載入圖表資料</div>';
return;
}
try {
const wrapper = document.getElementById('diagram-wrapper');
wrapper.innerHTML = '<pre class="mermaid" id="mermaid-diagram"></pre>';
const element = document.getElementById('mermaid-diagram');
element.textContent = diagramData.code;
await mermaid.run({
nodes: [element]
});
// 自動適應螢幕並啟用拖曳
setTimeout(() => {
// 確保 SVG 完全渲染後再計算
const svg = wrapper.querySelector('svg');
if (svg) {
// 設置 SVG 初始樣式
svg.style.maxWidth = 'none';
svg.style.height = 'auto';
// 給予一些額外時間確保佈局完成
setTimeout(() => {
enableDragToScroll();
zoomDiagram('fit');
}, 200);
}
}, 100);
} catch (error) {
console.error('渲染錯誤:', error);
document.getElementById('diagram-wrapper').innerHTML =
'<div style="color: #e53e3e;">圖表渲染失敗: ' + error.message + '</div>';
}
}
// 關閉窗口
function closeWindow() {
localStorage.removeItem('fullscreen-diagram');
window.close();
// 如果 window.close() 不起作用(某些瀏覽器的限制),顯示提示
setTimeout(() => {
document.body.innerHTML = '<div style="display: flex; justify-content: center; align-items: center; height: 100vh; font-size: 1.5rem; color: #666;">請手動關閉此窗口</div>';
}, 100);
}
// 縮放功能
function zoomDiagram(action) {
const wrapper = document.getElementById('diagram-wrapper');
const svg = wrapper.querySelector('svg');
if (!svg) return;
const container = document.querySelector('.diagram-container');
switch(action) {
case 'in':
currentZoom = Math.min(currentZoom * 1.2, 5);
break;
case 'out':
currentZoom = Math.max(currentZoom * 0.8, 0.2);
break;
case 'reset':
currentZoom = 1;
break;
case 'fit':
// 取得 SVG 的實際尺寸
const viewBox = svg.getAttribute('viewBox');
let svgWidth, svgHeight;
if (viewBox) {
// 如果有 viewBox,使用 viewBox 的尺寸
const [x, y, width, height] = viewBox.split(' ').map(Number);
svgWidth = width;
svgHeight = height;
} else {
// 否則使用 getBoundingClientRect
const rect = svg.getBoundingClientRect();
svgWidth = rect.width / currentZoom;
svgHeight = rect.height / currentZoom;
}
const containerRect = container.getBoundingClientRect();
const containerWidth = containerRect.width - 100; // 留一些邊距
const containerHeight = containerRect.height - 100;
const scaleX = containerWidth / svgWidth;
const scaleY = containerHeight / svgHeight;
// 選擇較小的縮放比例,確保整個圖表都能顯示
// 設定合理的縮放範圍
const optimalScale = Math.min(scaleX, scaleY);
// 如果計算出的縮放太小(< 0.5),使用 0.8 作為初始值
// 如果太大(> 2),限制在 2
if (optimalScale < 0.5) {
currentZoom = 0.8;
} else if (optimalScale > 2) {
currentZoom = 2;
} else {
currentZoom = optimalScale;
}
// 應用縮放並重置滾動位置到中心
wrapper.style.transform = `scale(${currentZoom})`;
setTimeout(() => {
// 確保滾動到中心位置
const scrollArea = document.querySelector('.diagram-scroll-area');
const containerRect = container.getBoundingClientRect();
const wrapperRect = wrapper.getBoundingClientRect();
// 計算需要滾動的位置,使圖表居中顯示
const scrollLeft = (scrollArea.scrollWidth - containerRect.width) / 2;
const scrollTop = (scrollArea.scrollHeight - containerRect.height) / 2;
container.scrollLeft = scrollLeft;
container.scrollTop = scrollTop;
}, 50);
break;
}
// 更新 transform
wrapper.style.transform = `scale(${currentZoom})`;
}
// 添加拖曳功能
function enableDragToScroll() {
const container = document.querySelector('.diagram-container');
let isDown = false;
let startX;
let startY;
let scrollLeft;
let scrollTop;
container.addEventListener('mousedown', (e) => {
// 避免在點擊按鈕時觸發拖曳
if (e.target.closest('.zoom-controls')) return;
isDown = true;
container.style.cursor = 'grabbing';
startX = e.pageX - container.offsetLeft;
startY = e.pageY - container.offsetTop;
scrollLeft = container.scrollLeft;
scrollTop = container.scrollTop;
e.preventDefault();
});
container.addEventListener('mouseleave', () => {
isDown = false;
container.style.cursor = 'grab';
});
container.addEventListener('mouseup', () => {
isDown = false;
container.style.cursor = 'grab';
});
container.addEventListener('mousemove', (e) => {
if (!isDown) return;
e.preventDefault();
const x = e.pageX - container.offsetLeft;
const y = e.pageY - container.offsetTop;
const walkX = (x - startX) * 1.5; // 增加拖曳靈敏度
const walkY = (y - startY) * 1.5;
container.scrollLeft = scrollLeft - walkX;
container.scrollTop = scrollTop - walkY;
});
// 滑鼠滾輪縮放
container.addEventListener('wheel', (e) => {
if (e.ctrlKey || e.metaKey) {
e.preventDefault();
// 執行縮放
if (e.deltaY < 0) {
zoomDiagram('in');
} else {
zoomDiagram('out');
}
}
});
}
// 添加觸控手勢支援
function enableTouchGestures() {
const container = document.querySelector('.diagram-container');
const wrapper = document.getElementById('diagram-wrapper');
let initialDistance = 0;
let initialScale = 1;
let isPinching = false;
// 計算兩個觸點之間的距離
function getDistance(touches) {
const dx = touches[0].clientX - touches[1].clientX;
const dy = touches[0].clientY - touches[1].clientY;
return Math.sqrt(dx * dx + dy * dy);
}
container.addEventListener('touchstart', (e) => {
if (e.touches.length === 2) {
e.preventDefault();
isPinching = true;
initialDistance = getDistance(e.touches);
initialScale = currentZoom;
}
}, { passive: false });
container.addEventListener('touchmove', (e) => {
if (isPinching && e.touches.length === 2) {
e.preventDefault();
const currentDistance = getDistance(e.touches);
const scale = (currentDistance / initialDistance) * initialScale;
// 限制縮放範圍
currentZoom = Math.max(0.2, Math.min(5, scale));
wrapper.style.transform = `scale(${currentZoom})`;
}
}, { passive: false });
container.addEventListener('touchend', (e) => {
if (e.touches.length < 2) {
isPinching = false;
}
});
// 雙擊放大/縮小
let lastTouchTime = 0;
container.addEventListener('touchend', (e) => {
const currentTime = new Date().getTime();
const tapLength = currentTime - lastTouchTime;
if (tapLength < 300 && tapLength > 0) {
e.preventDefault();
// 雙擊時在放大和適應螢幕之間切換
if (currentZoom > 1.1) {
zoomDiagram('fit');
} else {
currentZoom = 2;
wrapper.style.transform = `scale(${currentZoom})`;
}
}
lastTouchTime = currentTime;
});
}
// 檢測是否為觸控設備
function isTouchDevice() {
return 'ontouchstart' in window || navigator.maxTouchPoints > 0;
}
// 更新提示文字
function updateHintText() {
const hintElement = document.querySelector('.hint');
if (hintElement) {
if (isTouchDevice()) {
hintElement.innerHTML = '💡 提示:雙指縮放 | 滑動查看 | 雙擊放大';
} else {
hintElement.innerHTML = '💡 提示:拖曳移動圖表 | Ctrl/Cmd + 滾輪縮放';
}
}
}
// 載入時渲染圖表
renderDiagram();
// 初始化觸控手勢(如果是觸控設備)
if (isTouchDevice()) {
enableTouchGestures();
}
// 更新提示文字
updateHintText();
// 窗口關閉時清理 localStorage
window.addEventListener('beforeunload', () => {
localStorage.removeItem('fullscreen-diagram');
});
</script>
</body>
</html>