-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
704 lines (654 loc) · 40.1 KB
/
Copy pathindex.html
File metadata and controls
704 lines (654 loc) · 40.1 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
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
<!DOCTYPE html>
<html lang="zh-TW">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>描線工坊 VectorLine - 雷切線條生成器 (開源免費/本地運算)</title>
<!-- Workshop Vector Favicon (amber mono) -->
<link rel="icon" type="image/svg+xml" href="data:image/svg+xml,<svg xmlns=%22http://www.w3.org/2000/svg%22 viewBox=%220 0 100 100%22><linearGradient id=%22g%22 x1=%220%25%22 y1=%220%25%22 x2=%22100%25%22 y2=%22100%25%22><stop offset=%220%25%22 stop-color=%22%23f59e0b%22/><stop offset=%22100%25%22 stop-color=%22%23b45309%22/></linearGradient><circle cx=%2250%22 cy=%2250%22 r=%2240%22 fill=%22none%22 stroke=%22url(%23g)%22 stroke-width=%2212%22/><path d=%22M30 50 L70 50 M50 30 L50 70%22 stroke=%22%23b45309%22 stroke-width=%2210%22 stroke-linecap=%22round%22/></svg>">
<!-- Google Fonts -->
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&family=Archivo:wght@500;600;700;800;900&display=swap" rel="stylesheet">
<!-- CSS Stylesheet -->
<link rel="stylesheet" href="/src/style.css">
</head>
<body>
<!-- Loading Screen for OpenCV.js compilation -->
<div id="loading-screen" class="loading-screen">
<div class="loader-container">
<div class="glow-ring"></div>
<div class="loader-spinner"></div>
<h2>描線工坊</h2>
<p id="loading-text">正在載入 OpenCV.js 影像處理引擎...</p>
<div class="progress-bar-container">
<div class="progress-bar-fill"></div>
</div>
</div>
</div>
<div class="app-container is-empty">
<!-- Header -->
<header class="app-header">
<div class="header-left">
<div class="logo-area">
<svg class="logo-svg" viewBox="0 0 100 100" xmlns="http://www.w3.org/2000/svg">
<linearGradient id="g-logo" x1="0%" y1="0%" x2="100%" y2="100%">
<stop offset="0%" stop-color="#f59e0b" />
<stop offset="100%" stop-color="#b45309" />
</linearGradient>
<circle cx="50" cy="50" r="40" fill="none" stroke="url(#g-logo)" stroke-width="12" />
<path d="M30 50 L70 50 M50 30 L50 70" stroke="url(#g-logo)" stroke-width="10" stroke-linecap="round" />
</svg>
<h1>描線工坊<span class="brand-latin">VectorLine</span></h1>
<span class="badge">開源網頁版</span>
</div>
<p class="subtitle">完全開源、免費、瀏覽器本地運算,一鍵將圖片轉換為雷雕/雷切專用 SVG 線條路徑</p>
</div>
<div class="header-right">
<button id="btn-help" class="btn-help" title="使用技巧與參數說明">
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
<circle cx="12" cy="12" r="10"></circle>
<path d="M9.09 9a3 3 0 0 1 5.83 1c0 2-3 3-3 3"></path>
<line x1="12" y1="17" x2="12.01" y2="17"></line>
</svg>
<span>使用技巧</span>
</button>
<button id="btn-theme-toggle" class="btn-theme-toggle" title="切換深淺色模式">
<!-- Sun icon -->
<svg class="sun-icon hidden" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
<circle cx="12" cy="12" r="5"></circle>
<line x1="12" y1="1" x2="12" y2="3"></line>
<line x1="12" y1="21" x2="12" y2="23"></line>
<line x1="4.22" y1="4.22" x2="5.64" y2="5.64"></line>
<line x1="18.36" y1="18.36" x2="19.78" y2="19.78"></line>
<line x1="1" y1="12" x2="3" y2="12"></line>
<line x1="21" y1="12" x2="23" y2="12"></line>
<line x1="4.22" y1="19.78" x2="5.64" y2="18.36"></line>
<line x1="18.36" y1="5.64" x2="19.78" y2="4.22"></line>
</svg>
<!-- Moon icon -->
<svg class="moon-icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
<path d="M21 12.79A9 9 0 1 1 11.21 3 7 7 0 0 0 21 12.79z"></path>
</svg>
</button>
</div>
</header>
<!-- Main Workspace -->
<main class="app-main">
<!-- Sidebar Panel: Controls & Settings -->
<aside class="app-sidebar">
<!-- Step 1: Upload Section -->
<div class="upload-section card">
<div class="group-label">
1. 上傳圖片
<span class="info-icon tooltip-right" data-tooltip="支援格式:PNG, JPG, WebP, AVIF, BMP, GIF 等">
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round">
<circle cx="12" cy="12" r="10"></circle>
<line x1="12" y1="16" x2="12" y2="12"></line>
<line x1="12" y1="8" x2="12.01" y2="8"></line>
</svg>
</span>
</div>
<div id="drop-zone" class="drop-zone">
<input type="file" id="file-input" accept="image/*" class="file-input">
<div class="drop-zone-content">
<svg class="upload-icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
<path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4M17 8l-5-5-5 5M12 3v12"/>
</svg>
<p class="primary-text">拖曳圖案至此或<span>點擊瀏覽</span></p>
<p class="secondary-text">支援 PNG, JPG, WebP 格式</p>
</div>
<div id="upload-preview-container" class="upload-preview-container hidden">
<img id="upload-preview" alt="上傳的圖片">
<button id="btn-remove-image" class="btn-remove" title="移除圖片">
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
<line x1="18" y1="6" x2="6" y2="18"></line>
<line x1="6" y1="6" x2="18" y2="18"></line>
</svg>
</button>
</div>
</div>
<!-- Sample Images (only shown in onboarding/empty state) -->
<div class="onboarding-samples">
<p class="samples-title">無可用檔案?點擊快速試用樣品:</p>
<div class="samples-grid">
<button class="sample-card" id="btn-sample-1" type="button">
<div class="sample-icon">✍️</div>
<div class="sample-info">
<span class="sample-name">手繪線稿</span>
<span class="sample-desc">測試雙邊去噪與對比度</span>
</div>
</button>
<button class="sample-card" id="btn-sample-2" type="button">
<div class="sample-icon">🤖</div>
<div class="sample-info">
<span class="sample-name">電子線條</span>
<span class="sample-desc">測試乾淨的二值提取</span>
</div>
</button>
</div>
</div>
</div>
<!-- Controls panel (disabled when no image is uploaded) -->
<div id="settings-group" class="disabled-controls settings-scroller">
<!-- Presets and Reset -->
<div class="settings-card card">
<div class="card-header-static">快速參數預設</div>
<div class="preset-buttons-group">
<button id="btn-preset-photo" class="btn-preset">手繪相片最佳化</button>
<button id="btn-preset-digital" class="btn-preset">電子圖檔最佳化</button>
<button id="btn-reset-defaults" class="btn-reset" title="重設為預設值">
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" style="width:16px;height:16px;">
<path d="M23 4v6h-6M1 20v-6h6"/>
<path d="M3.51 9a9 9 0 0 1 14.85-3.36L23 10M1 14l4.64 4.36A9 9 0 0 0 20.49 15"/>
</svg>
</button>
</div>
</div>
<!-- Main Settings Card with Tabs -->
<div class="settings-card-tabs card">
<div class="settings-tabs-bar">
<button type="button" class="tab-trigger active" data-tab="tab-filters">濾波預處理</button>
<button type="button" class="tab-trigger" data-tab="tab-binarize">二值化</button>
<button type="button" class="tab-trigger" data-tab="tab-vector">向量優化</button>
<button type="button" class="tab-trigger" data-tab="tab-export">輸出規格</button>
</div>
<div class="tab-contents-container">
<!-- Tab 1: Filters & Preprocessing -->
<div id="tab-filters" class="settings-tab-content active">
<div class="slider-wrapper">
<div class="slider-header">
<span class="label-with-tooltip">
雙邊濾波強度 (Denoise)
<span class="info-icon" data-tooltip="去除背景雜訊與紙張紋理,保留主線條邊緣。建議手繪相片設為 5~8,電子圖檔設為 0。">
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><circle cx="12" cy="12" r="10"></circle><line x1="12" y1="16" x2="12" y2="12"></line><line x1="12" y1="8" x2="12.01" y2="8"></line></svg>
</span>
</span>
<span id="val-denoise" class="slider-val">5</span>
</div>
<input type="range" id="slider-denoise" min="0" max="15" step="1" value="5">
</div>
<div class="slider-wrapper">
<div class="slider-header">
<span class="label-with-tooltip">
影像亮度 (Brightness)
<span class="info-icon" data-tooltip="調高亮度有助於去除陰影、紙張摺痕與背光產生的灰暗雜點;調低可增強灰暗或過淡的線條。">
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><circle cx="12" cy="12" r="10"></circle><line x1="12" y1="16" x2="12" y2="12"></line><line x1="12" y1="8" x2="12.01" y2="8"></line></svg>
</span>
</span>
<span id="val-brightness" class="slider-val">0</span>
</div>
<input type="range" id="slider-brightness" min="-100" max="100" step="5" value="0">
</div>
<div class="slider-wrapper">
<div class="slider-header">
<span class="label-with-tooltip">
影像對比 (Contrast)
<span class="info-icon" data-tooltip="增強線條與背景對比度,拉大黑白分界,有助於分離模糊的手繪鉛筆線條。">
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><circle cx="12" cy="12" r="10"></circle><line x1="12" y1="16" x2="12" y2="12"></line><line x1="12" y1="8" x2="12.01" y2="8"></line></svg>
</span>
</span>
<span id="val-contrast" class="slider-val">0</span>
</div>
<input type="range" id="slider-contrast" min="-100" max="100" step="5" value="0">
</div>
<div class="slider-wrapper">
<div class="slider-header">
<span class="label-with-tooltip">
亮部去背 (White Cutoff)
<span class="info-icon" data-tooltip="把亮度高於此值的區域直接壓成純白,快速清除淺色紙張紋理、陰影與背景雜點。數值越低清得越多;255 為關閉。適合淺色/白底圖片。">
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><circle cx="12" cy="12" r="10"></circle><line x1="12" y1="16" x2="12" y2="12"></line><line x1="12" y1="8" x2="12.01" y2="8"></line></svg>
</span>
</span>
<span id="val-white-cutoff" class="slider-val">關閉</span>
</div>
<input type="range" id="slider-white-cutoff" min="150" max="255" step="5" value="255">
</div>
<div class="checkbox-wrapper">
<label class="checkbox-label">
<input type="checkbox" id="checkbox-invert-binary">
<span class="label-with-tooltip">
反轉黑白顏色 (Invert Colors)
<span class="info-icon" data-tooltip="適用於黑底白字或深色背景圖片。勾選可對調影像的黑白提取邏輯。">
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><circle cx="12" cy="12" r="10"></circle><line x1="12" y1="16" x2="12" y2="12"></line><line x1="12" y1="8" x2="12.01" y2="8"></line></svg>
</span>
</span>
</label>
</div>
</div>
<!-- Tab 2: Binarization -->
<div id="tab-binarize" class="settings-tab-content">
<div class="slider-wrapper">
<div class="slider-header">
<span class="label-with-tooltip">
線條細緻度 (Block Size)
<span class="info-icon" data-tooltip="自適應二值化的局部區域大小。數值越小線條越細,越大線條越粗(適用於實心色塊)。">
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><circle cx="12" cy="12" r="10"></circle><line x1="12" y1="16" x2="12" y2="12"></line><line x1="12" y1="8" x2="12.01" y2="8"></line></svg>
</span>
</span>
<span id="val-blocksize" class="slider-val">11</span>
</div>
<input type="range" id="slider-blocksize" min="3" max="51" step="2" value="11">
</div>
<div class="slider-wrapper">
<div class="slider-header">
<span class="label-with-tooltip">
臨界分界偏置 (C Constant)
<span class="info-icon" data-tooltip="微調線條粗細與周圍背景干擾。數值越大線條越細、雜訊越少;數值越小線條越粗、細節越多。">
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><circle cx="12" cy="12" r="10"></circle><line x1="12" y1="16" x2="12" y2="12"></line><line x1="12" y1="8" x2="12.01" y2="8"></line></svg>
</span>
</span>
<span id="val-c-constant" class="slider-val">2</span>
</div>
<input type="range" id="slider-c-constant" min="-10" max="15" step="1" value="2">
</div>
<div class="slider-wrapper">
<div class="slider-header">
<span class="label-with-tooltip">
形態學去雜點 (Morphology)
<span class="info-icon" data-tooltip="透過膨脹/侵蝕運算去除細小椒鹽噪點,並填補主線條間的微小斷裂。0 表示關閉。">
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><circle cx="12" cy="12" r="10"></circle><line x1="12" y1="16" x2="12" y2="12"></line><line x1="12" y1="8" x2="12.01" y2="8"></line></svg>
</span>
</span>
<span id="val-morph-clean" class="slider-val">0</span>
</div>
<input type="range" id="slider-morph-clean" min="0" max="5" step="1" value="0">
</div>
</div>
<!-- Tab 3: Vector Optimization -->
<div id="tab-vector" class="settings-tab-content">
<div class="control-subgroup">
<span class="subgroup-label label-with-tooltip">
雷切切割模式 (Cut Mode)
<span class="info-icon" data-tooltip="【輪廓模式】追蹤邊緣雙描邊,適合實心色塊雕刻;【單線模式】將線條細線化並追蹤為單一中心線,適合雷射沿中線切割(省時);【邊緣模式】Canny 演算,適合照片提取。">
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><circle cx="12" cy="12" r="10"></circle><line x1="12" y1="16" x2="12" y2="12"></line><line x1="12" y1="8" x2="12.01" y2="8"></line></svg>
</span>
</span>
<div class="segmented-control mode-3-cols">
<label class="segment-tab">
<input type="radio" name="cut-mode" value="outline" checked>
<span class="segment-label">輪廓 (Outline)</span>
</label>
<label class="segment-tab">
<input type="radio" name="cut-mode" value="centerline">
<span class="segment-label">單線 (Centerline)</span>
</label>
<label class="segment-tab">
<input type="radio" name="cut-mode" value="canny">
<span class="segment-label">邊緣 (Canny)</span>
</label>
</div>
</div>
<div class="slider-wrapper" style="margin-top: 8px;">
<div class="slider-header">
<span class="label-with-tooltip">
節點簡化程度 (Simplify)
<span class="info-icon" data-tooltip="路徑節點簡化容差。數值越大產出的 SVG 節點越少、檔案越小,但細節越少;0 為忠實還原。超小圖片建議設為 0.1~0.3。">
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><circle cx="12" cy="12" r="10"></circle><line x1="12" y1="16" x2="12" y2="12"></line><line x1="12" y1="8" x2="12.01" y2="8"></line></svg>
</span>
</span>
<span id="val-simplify" class="slider-val">1.0 px</span>
</div>
<input type="range" id="slider-simplify" min="0" max="5.0" step="0.1" value="1.0">
</div>
<div class="slider-wrapper">
<div class="slider-header">
<span class="label-with-tooltip">
過濾雜點面積 (Min Area)
<span class="info-icon" data-tooltip="過濾掉小於此面積的孤立雜訊碎塊。數值越大越乾淨,但微小細節會消失。超小圖片建議設為 0~5。">
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><circle cx="12" cy="12" r="10"></circle><line x1="12" y1="16" x2="12" y2="12"></line><line x1="12" y1="8" x2="12.01" y2="8"></line></svg>
</span>
</span>
<span id="val-min-area" class="slider-val">15 px</span>
</div>
<input type="range" id="slider-min-area" min="0" max="500" step="5" value="15">
</div>
<div class="checkbox-wrapper">
<label class="checkbox-label">
<input type="checkbox" id="checkbox-smooth">
<span class="label-with-tooltip">
曲線平滑 (Smooth Curves)
<span class="info-icon" data-tooltip="將折線節點轉為貝茲曲線,使線條極為平順,雷切切割時機器更不易產生抖動。">
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><circle cx="12" cy="12" r="10"></circle><line x1="12" y1="16" x2="12" y2="12"></line><line x1="12" y1="8" x2="12.01" y2="8"></line></svg>
</span>
</span>
</label>
</div>
</div>
<!-- Tab 4: Export Configuration -->
<div id="tab-export" class="settings-tab-content">
<div class="control-subgroup">
<span class="subgroup-label label-with-tooltip">
匯出樣式 (Render Mode)
<span class="info-icon" data-tooltip="【描邊】僅繪製線條路徑(細線),用於雷射切割;【填色】填充路徑閉合區塊,外觀接近黑白圖,用於雷射雕刻。">
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><circle cx="12" cy="12" r="10"></circle><line x1="12" y1="16" x2="12" y2="12"></line><line x1="12" y1="8" x2="12.01" y2="8"></line></svg>
</span>
</span>
<div class="segmented-control mode-2-cols">
<label class="segment-tab">
<input type="radio" name="render-mode" value="stroke" checked>
<span class="segment-label">描邊 (Stroke)</span>
</label>
<label class="segment-tab">
<input type="radio" name="render-mode" value="fill">
<span class="segment-label">填色 (Fill)</span>
</label>
</div>
</div>
<div class="control-subgroup">
<span class="subgroup-label label-with-tooltip">
匯出顏色 (Color)
<span class="info-icon" data-tooltip="SVG 路徑顏色。雷切機通常識別紅色作為「切割」路徑。">
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><circle cx="12" cy="12" r="10"></circle><line x1="12" y1="16" x2="12" y2="12"></line><line x1="12" y1="8" x2="12.01" y2="8"></line></svg>
</span>
</span>
<div class="segmented-control mode-2-cols">
<label class="segment-tab">
<input type="radio" name="svg-color" value="#ff0000" checked>
<span class="segment-label color-label-red">紅色 (預設切割)</span>
</label>
<label class="segment-tab">
<input type="radio" name="svg-color" value="#000000">
<span class="segment-label color-label-black">黑色</span>
</label>
</div>
</div>
<div class="control-subgroup">
<span class="subgroup-label label-with-tooltip">
圖層模式 (Layer Mode)
<span class="info-icon" data-tooltip="【單一顏色】所有軌跡為選定色;【自動分層】最外圈線條為紅色(切割),內部孔洞細節為黑色/選定色(雕刻/標記)。適用於輪廓與邊緣模式。">
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><circle cx="12" cy="12" r="10"></circle><line x1="12" y1="16" x2="12" y2="12"></line><line x1="12" y1="8" x2="12.01" y2="8"></line></svg>
</span>
</span>
<div class="segmented-control mode-2-cols">
<label class="segment-tab">
<input type="radio" name="layer-mode" value="single" checked>
<span class="segment-label">單一顏色</span>
</label>
<label class="segment-tab">
<input type="radio" name="layer-mode" value="auto-layer">
<span class="segment-label">自動分層</span>
</label>
</div>
</div>
<div class="size-scaler-container" style="margin-top: 8px;">
<label class="checkbox-label">
<input type="checkbox" id="checkbox-enable-size" checked>
<span class="label-with-tooltip">
啟用實體尺寸標記 (毫米/mm)
<span class="info-icon" data-tooltip="勾選後,匯出的 SVG 將帶有毫米物理尺寸(以等比例縮放),匯入 Beam Studio 等軟體時不需手動重新縮放比例。">
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><circle cx="12" cy="12" r="10"></circle><line x1="12" y1="16" x2="12" y2="12"></line><line x1="12" y1="8" x2="12.01" y2="8"></line></svg>
</span>
</span>
</label>
<div id="size-inputs-wrapper" class="size-inputs-wrapper">
<div class="size-input-field">
<span class="input-label">寬度 (Width)</span>
<div class="input-with-unit">
<input type="number" id="input-phys-width" min="1" max="2000" value="150">
<span class="unit-label">mm</span>
</div>
</div>
<div class="size-input-field">
<span class="input-label">高度 (Height)</span>
<div class="input-with-unit readonly-field">
<input type="text" id="input-phys-height" readonly value="-">
<span class="unit-label">mm</span>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<!-- Sticky Sidebar Download Actions -->
<div class="sidebar-action-buttons">
<button id="btn-download-svg" class="btn btn-primary">
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" class="btn-icon">
<path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4M7 10l5 5 5-5M12 15V3"/>
</svg>
下載 SVG 向量檔
</button>
<div class="download-row-split">
<button id="btn-download-dxf" class="btn btn-secondary">
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" class="btn-icon">
<polygon points="12 2 2 7 12 12 22 7 12 2"></polygon>
<polyline points="2 17 12 22 22 17"></polyline>
</svg>
下載 DXF
</button>
<button id="btn-download-png" class="btn btn-secondary">
下載 PNG
</button>
</div>
</div>
</aside>
<!-- Right Panel: Live Preview Workspace -->
<section class="app-workspace">
<!-- Floating Workspace Header -->
<div class="workspace-header">
<div class="workspace-title">
<svg class="workspace-icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
<rect x="3" y="3" width="18" height="18" rx="2" ry="2"></rect>
<line x1="9" y1="3" x2="9" y2="21"></line>
</svg>
<h2>即時預覽工作區</h2>
</div>
<!-- Info Board (Stats) -->
<div class="stats-panel-compact">
<div class="stat-item">
<span class="stat-label">圖片尺寸</span>
<span id="stat-resolution" class="stat-value">-</span>
</div>
<div class="stat-divider"></div>
<div class="stat-item">
<span class="stat-label">偵測到路徑數</span>
<span id="stat-contours" class="stat-value">-</span>
</div>
<div class="stat-divider"></div>
<div class="stat-item">
<span class="stat-label">SVG 節點數</span>
<span id="stat-nodes" class="stat-value">-</span>
</div>
</div>
</div>
<!-- Previews Workspace -->
<div class="preview-panel card">
<div class="preview-grid">
<!-- Canvas Preview -->
<div class="preview-pane">
<div class="pane-header label-with-tooltip">
<span>1. 點陣黑白圖 (PNG)</span>
<span class="info-icon tooltip-right" data-tooltip="「點陣點點圖」由像素點組成,放大會有鋸齒馬賽克。適合雷射機進行點陣掃描,儲存對應為「下載 PNG 線條圖」。">
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><circle cx="12" cy="12" r="10"></circle><line x1="12" y1="16" x2="12" y2="12"></line><line x1="12" y1="8" x2="12.01" y2="8"></line></svg>
</span>
<button id="btn-magic-toggle" class="btn-pane-tool" type="button" title="魔術棒去背:點擊背景區域即可清除" disabled>
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
<path d="M15 4V2M15 16v-2M8 9h2M20 9h2M17.8 11.8L19 13M15 9h.01M17.8 6.2L19 5M3 21l9-9M12.2 6.2L11 5"></path>
</svg>
<span>魔術棒去背</span>
</button>
<button id="btn-compare-toggle" class="btn-pane-tool" type="button" title="與原圖對比" disabled>
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
<rect x="3" y="4" width="18" height="16" rx="2"></rect>
<line x1="12" y1="2" x2="12" y2="22"></line>
</svg>
<span>原圖對比</span>
</button>
</div>
<div class="canvas-container checkerboard">
<div id="canvas-preview-wrapper" class="preview-wrapper">
<canvas id="output-canvas"></canvas>
</div>
<!-- Magic-wand background removal overlay -->
<div id="magic-layer" class="magic-layer hidden">
<div class="magic-canvas-wrap">
<canvas id="magic-canvas"></canvas>
</div>
<div class="magic-toolbar">
<span class="magic-hint">🪄 點擊要清除的背景區域</span>
<div class="magic-tol">
<span>容差</span>
<input type="range" id="slider-magic-tol" min="5" max="120" step="5" value="35">
<span id="val-magic-tol">35</span>
</div>
<div class="magic-actions">
<button id="btn-magic-step-undo" class="magic-btn" type="button" title="上一步 (Undo)" disabled>
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polyline points="9 14 4 9 9 4"></polyline><path d="M20 20v-7a4 4 0 0 0-4-4H4"></path></svg>
上一步
</button>
<button id="btn-magic-step-redo" class="magic-btn" type="button" title="下一步 (Redo)" disabled>
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polyline points="15 14 20 9 15 4"></polyline><path d="M4 20v-7a4 4 0 0 1 4-4h12"></path></svg>
下一步
</button>
<button id="btn-magic-undo" class="magic-btn" type="button">全部清除</button>
<button id="btn-magic-done" class="magic-btn magic-btn-primary" type="button">完成</button>
</div>
</div>
</div>
<!-- Before / After comparison overlay -->
<div id="compare-layer" class="compare-layer hidden">
<div id="compare-frame" class="compare-frame">
<img id="compare-after" class="compare-after" alt="處理後線條圖">
<img id="compare-before" class="compare-before" alt="原始圖片">
<div id="compare-divider" class="compare-divider">
<div class="compare-handle">
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5"><polyline points="15 18 9 12 15 6"></polyline></svg>
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5"><polyline points="9 18 15 12 9 6"></polyline></svg>
</div>
</div>
<span class="compare-tag compare-tag-before">原圖</span>
<span class="compare-tag compare-tag-after">處理後</span>
</div>
</div>
<div id="empty-state-canvas" class="empty-state">
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" class="empty-state-icon">
<rect x="3" y="3" width="18" height="18" rx="2" ry="2"></rect>
<circle cx="8.5" cy="8.5" r="1.5"></circle>
<polyline points="21 15 16 10 5 21"></polyline>
</svg>
<p>工作區已就緒,請上傳圖片以開始</p>
</div>
</div>
</div>
<!-- SVG Vector Preview -->
<div class="preview-pane">
<div class="pane-header label-with-tooltip">
<span>2. 向量路徑圖 (SVG)</span>
<span class="info-icon tooltip-right" data-tooltip="「向量軌跡」由數學線段與曲線組成,放大無限倍仍平滑。可用於雷射切割或向量雕刻,儲存對應為「下載 SVG 向量檔」。">
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><circle cx="12" cy="12" r="10"></circle><line x1="12" y1="16" x2="12" y2="12"></line><line x1="12" y1="8" x2="12.01" y2="8"></line></svg>
</span>
</div>
<div class="svg-container checkerboard">
<div id="svg-preview-wrapper" class="preview-wrapper">
<img id="svg-preview" class="hidden" alt="SVG 向量預覽">
</div>
<div id="svg-zoom-indicator" class="zoom-indicator hidden">
<span>🖱️ 滾輪縮放 / 拖曳平移 | 雙擊重設</span>
</div>
<div id="empty-state-svg" class="empty-state">
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" class="empty-state-icon">
<polygon points="12 2 2 7 12 12 22 7 12 2"></polygon>
<polyline points="2 17 12 22 22 17"></polyline>
<polyline points="2 12 12 17 22 12"></polyline>
</svg>
<p>向量路徑生成後將在此顯示</p>
</div>
</div>
</div>
</div>
</div>
</section>
</main>
<!-- Footer -->
<footer class="app-footer">
<p>© 2026 <a href="https://begin0808.github.io/studio0808/" target="_blank" class="footer-link">Studio0808 智造實驗室</a>. All rights reserved. <a href="mailto:begin0808@gmail.com" class="footer-link">✉ 寫信給我</a></p>
</footer>
</div>
<!-- Help / Tips Modal -->
<div id="help-modal" class="help-modal hidden">
<div class="help-backdrop" id="help-backdrop"></div>
<div class="help-dialog" role="dialog" aria-modal="true" aria-labelledby="help-title">
<div class="help-header">
<h2 id="help-title">🛠️ 使用技巧與疑難排解</h2>
<button id="btn-help-close" class="help-close" title="關閉">
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><line x1="18" y1="6" x2="6" y2="18"></line><line x1="6" y1="6" x2="18" y2="18"></line></svg>
</button>
</div>
<div class="help-body">
<p class="help-intro">下面是常見情況的處理方法。本工具是<strong>參數式</strong>調整,搭配<strong>魔術棒去背</strong>即可解決大多數問題,不需另外開修圖軟體。</p>
<div class="help-card">
<div class="help-card-title">🔴 畫面有很多黑點/雜訊</div>
<p>常見於深色漸層背景、掃描紙張紋理或陰影。依序嘗試:</p>
<ul>
<li><b>先按「手繪相片最佳化」預設</b>,多半一鍵改善。</li>
<li><b>魔術棒去背</b>(預覽區左上):直接點背景區域整片清除,最適合單一色背景。</li>
<li><b>亮部去背</b>(濾波預處理):淺色背景往下拉即可壓白。</li>
<li><b>影像亮度 +30~+60</b>:把暗背景洗白,從源頭消除雜點。</li>
<li><b>形態學去雜點 1~2</b>(二值化):擦掉細小點,連點陣圖也變乾淨。</li>
<li><b>過濾雜點面積 100~300</b>(向量優化):丟掉小碎塊,<i>只清 SVG 向量</i>。</li>
</ul>
<p class="help-warn">⚠️ 這幾項調太大會連小字筆畫一起吃掉,請小幅遞增。</p>
</div>
<div class="help-card">
<div class="help-card-title">✏️ 手繪鉛筆線太淡、抓不到線</div>
<ul>
<li><b>影像對比 +30~+60</b>:拉大黑白分界。</li>
<li><b>影像亮度 −10~−30</b>:加深過淡的線條。</li>
<li><b>臨界分界偏置 (C) 調低</b>:線變粗、細節變多。</li>
</ul>
</div>
<div class="help-card">
<div class="help-card-title">〰️ 線條斷斷續續、有缺口</div>
<ul>
<li><b>形態學去雜點 1~2</b>:填補主線微小斷裂。</li>
<li><b>雙邊濾波強度</b>調低,避免線被糊掉。</li>
<li>切割用途建議搭配<b>單線 (Centerline)</b> 模式沿中線切。</li>
</ul>
</div>
<div class="help-card">
<div class="help-card-title">📦 SVG 檔太大、節點太多、雷切機跑很慢</div>
<ul>
<li><b>節點簡化程度</b>調高(1.5~3):節點變少、檔案更小。</li>
<li><b>曲線平滑</b>打開:折線轉貝茲曲線,機器更順。</li>
<li><b>過濾雜點面積</b>調高:去掉大量小碎塊。</li>
</ul>
</div>
<div class="help-card">
<div class="help-card-title">🌓 黑底白字/深色背景圖</div>
<ul>
<li>勾選<b>反轉黑白顏色 (Invert Colors)</b>。</li>
<li>再視情況用<b>魔術棒去背</b>清掉背景。</li>
</ul>
</div>
<div class="help-card">
<div class="help-card-title">✂️ 只要外框切割、內部當雕刻</div>
<ul>
<li><b>圖層模式 → 自動分層</b>:最外圈紅色(切割)、內部黑色(雕刻)。</li>
<li>匯出 <b>DXF</b> 會自動分成 <code>CUT</code> / <code>ENGRAVE</code> 兩圖層。</li>
</ul>
</div>
<div class="help-card">
<div class="help-card-title">🪄 魔術棒去背怎麼用?</div>
<ul>
<li>點預覽區左上「<b>魔術棒去背</b>」→ 左側會顯示原圖。</li>
<li><b>點一下背景</b>,相近顏色的整片區域會被清除(標成紅色)。</li>
<li>拉「<b>容差</b>」控制一次清除的顏色範圍;可連續點多處累加。</li>
<li><b>還原</b>清空選取、<b>完成</b>離開(清除結果會保留並套用)。</li>
</ul>
</div>
<div class="help-card">
<div class="help-card-title">📐 想要正確的實體尺寸</div>
<ul>
<li>在<b>輸出規格</b>勾選「啟用實體尺寸標記」,填入寬度(mm),高度自動等比。</li>
<li>SVG/DXF 都會帶 mm 尺寸,匯入 Beam Studio / LightBurn 免重縮。</li>
</ul>
</div>
</div>
</div>
</div>
<!-- Main JavaScript App -->
<script type="module" src="/src/main.js"></script>
</body>
</html>