-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
639 lines (597 loc) · 47.3 KB
/
Copy pathindex.html
File metadata and controls
639 lines (597 loc) · 47.3 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
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>SwiftGG · 公众号编辑器</title>
<style>
@font-face{font-family:'Dongle';font-style:normal;font-weight:300;font-display:swap;src:url('./assets/fonts/dongle-300.woff2') format('woff2');}
@font-face{font-family:'Dongle';font-style:normal;font-weight:400;font-display:swap;src:url('./assets/fonts/dongle-400.woff2') format('woff2');}
@font-face{font-family:'Dongle';font-style:normal;font-weight:700;font-display:swap;src:url('./assets/fonts/dongle-700.woff2') format('woff2');}
:root{
--blue:#2782FB; --orange:#FB6131; --ink:#0B0B0F; --paper:#fcfcfc;
--bg:#e7e9ed; --panel:#fafbfc; --border:#e4e7ec; --line:#eceef1;
--text:#1d1d1f; --muted:#86868b; --muted2:#a1a1a6;
--font:-apple-system,BlinkMacSystemFont,'SF Pro Display','PingFang SC','Hiragino Sans GB','Microsoft YaHei',sans-serif;
--logo:'Dongle',var(--font);
--shadow:0 12px 50px rgba(11,11,15,.10);
}
*{margin:0;padding:0;box-sizing:border-box;}
html,body{height:100%;}
body{font-family:var(--font);background:var(--bg);color:var(--text);-webkit-font-smoothing:antialiased;display:flex;flex-direction:column;overflow:hidden;}
/* ============ 顶部栏 ============ */
.topbar{position:sticky;top:0;z-index:60;display:flex;align-items:center;gap:10px;height:56px;padding:0 18px;background:rgba(255,255,255,.82);backdrop-filter:saturate(180%) blur(16px);-webkit-backdrop-filter:saturate(180%) blur(16px);border-bottom:1px solid var(--border);flex-shrink:0;}
.brand{display:flex;align-items:center;gap:9px;margin-right:auto;}
.brand .mark{width:26px;height:25px;display:block;}
.brand .name{font-family:var(--logo);font-weight:700;font-size:27px;line-height:1;color:var(--ink);transform:translateY(1px);}
.brand .tag{font-size:12px;color:var(--muted);border-left:1px solid var(--border);padding-left:10px;margin-left:2px;}
.tb-group{display:flex;align-items:center;gap:6px;}
.tbtn{height:34px;padding:0 13px;border:1px solid var(--border);border-radius:9px;background:#fff;cursor:pointer;font-size:13px;color:var(--text);display:inline-flex;align-items:center;gap:6px;font-family:var(--font);white-space:nowrap;transition:all .14s;}
.tbtn:hover{background:#f5f6f8;border-color:#d6dae0;}
.tbtn.primary{background:var(--ink);color:#fff;border-color:var(--ink);font-weight:600;}
.tbtn.primary:hover{opacity:.92;transform:translateY(-1px);}
.tbtn .ic{font-size:14px;}
.tbtn.icon-only{width:34px;justify-content:center;padding:0;}
/* ============ 工作区(左列表 · 中编辑 · 右预览) ============ */
.workspace{display:flex;flex:1;min-height:0;overflow:hidden;}
/* 左侧:macOS Finder · 圆角悬浮侧栏 */
.rail{flex:0 0 304px;overflow-y:auto;margin:16px 0 16px 16px;border-radius:18px;background:rgba(250,251,252,.78);backdrop-filter:saturate(180%) blur(22px);-webkit-backdrop-filter:saturate(180%) blur(22px);border:1px solid rgba(20,10,40,.06);box-shadow:var(--shadow);padding:16px 14px 22px;}
.canvas::-webkit-scrollbar{width:8px;}
.canvas::-webkit-scrollbar-thumb{background:#d4d8de;border-radius:5px;}
.rail{scrollbar-width:none;-ms-overflow-style:none;}
.rail::-webkit-scrollbar{width:0;height:0;display:none;}
.rail-h{font-size:11px;letter-spacing:1.2px;color:var(--muted);text-transform:uppercase;font-weight:700;padding:6px 8px 10px;}
.ri{display:block;width:100%;text-align:left;border:1px solid var(--border);background:#fff;border-radius:13px;padding:8px;margin-bottom:10px;cursor:pointer;transition:border .14s,box-shadow .14s,transform .14s;}
.ri:hover{border-color:#cdd3db;box-shadow:0 6px 18px rgba(11,11,15,.07);transform:translateY(-1px);}
.ri .prev{height:104px;overflow:hidden;border-radius:9px;background:#fff;border:1px solid var(--line);position:relative;}
.ri .prev .scale{width:600px;transform:scale(.41);transform-origin:top left;padding:16px 16px;}
.ri .prev .scale>*:first-child{margin-top:0!important;}
.ri .lbl{display:flex;align-items:center;gap:7px;padding:8px 4px 2px;font-size:12.5px;font-weight:600;color:var(--text);}
.ri .lbl .em{font-size:15px;}
.ri .lbl .ds{font-weight:400;color:var(--muted);font-size:11px;margin-left:auto;}
.ri.img .prev{display:flex;align-items:center;justify-content:center;background:linear-gradient(135deg,#eef4ff,#fdeee9);}
.ri.img .prev .ph{font-size:30px;}
/* 中间:编辑画布 */
.canvas{flex:1;overflow-y:auto;padding:32px 24px 90px;}
.page{max-width:700px;margin:0 auto;background:var(--paper);border-radius:24px;box-shadow:var(--shadow);overflow:hidden;border:1px solid #e6e8ec;}
/* 页眉:灰 logo 居中,无分割线 */
.page-head{display:flex;align-items:center;justify-content:center;gap:9px;padding:36px 40px 14px;}
.page-head .mark{width:23px;height:22px;}
.page-head .name{font-family:var(--logo);font-weight:700;font-size:26px;line-height:1;color:var(--muted);transform:translateY(1px);}
/* 正文(Tiptap) */
.page-body{padding:20px 40px 16px;}
.ProseMirror{outline:none;font-size:16px;line-height:1.85;color:#3a3d46;letter-spacing:.2px;min-height:300px;}
.ProseMirror>*:first-child{margin-top:0;}
.ProseMirror h1{font-size:30px;line-height:1.18;font-weight:800;letter-spacing:-.8px;color:#1d1d1f;margin:1.2em 0 .5em;text-align:center;}
.ProseMirror h2{font-size:23px;line-height:1.25;font-weight:700;letter-spacing:-.4px;color:#1d1d1f;margin:1.4em 0 .55em;}
.ProseMirror h3{font-size:18px;line-height:1.35;font-weight:700;color:#1d1d1f;margin:1.2em 0 .4em;}
.ProseMirror p{margin:.75em 0;color:#3a3d46;}
.ProseMirror strong{font-weight:700;color:#1d1d1f;}
.ProseMirror em{font-style:italic;}
.ProseMirror s{color:#a1a1a6;}
.ProseMirror a{color:var(--blue);text-decoration:none;font-weight:500;border-bottom:1px solid rgba(39,130,251,.28);}
.ProseMirror ul,.ProseMirror ol{padding-left:1.4em;margin:.7em 0;}
.ProseMirror li{margin:.32em 0;}
.ProseMirror li p{margin:.2em 0;}
.ProseMirror blockquote{margin:1.15em 0;padding:14px 20px;background:#f5f5f7;border-radius:14px;color:#6e6e73;font-size:15.5px;line-height:1.7;}
.ProseMirror blockquote p{margin:.2em 0;color:inherit;}
.ProseMirror code{font-family:'SF Mono',Menlo,Monaco,monospace;font-size:.86em;background:#f0f0f3;padding:2px 6px;border-radius:6px;color:#bf4080;letter-spacing:0;}
.ProseMirror pre{background:#f5f5f7;color:#1d1d1f;border:1px solid #ececef;padding:16px 18px;border-radius:14px;overflow-x:auto;margin:1.15em 0;font-size:13.5px;line-height:1.7;}
.ProseMirror pre code{background:none;color:inherit;padding:0;font-size:inherit;}
/* 代码高亮(浅色主题) */
.ProseMirror pre .hljs-comment,.ProseMirror pre .hljs-quote{color:#8a919b;font-style:italic;}
.ProseMirror pre .hljs-keyword,.ProseMirror pre .hljs-selector-tag,.ProseMirror pre .hljs-literal,.ProseMirror pre .hljs-doctag{color:#cf222e;}
.ProseMirror pre .hljs-string,.ProseMirror pre .hljs-regexp,.ProseMirror pre .hljs-addition,.ProseMirror pre .hljs-meta-string{color:#0a7d22;}
.ProseMirror pre .hljs-number,.ProseMirror pre .hljs-built_in,.ProseMirror pre .hljs-type,.ProseMirror pre .hljs-symbol,.ProseMirror pre .hljs-bullet,.ProseMirror pre .hljs-meta{color:#0550ae;}
.ProseMirror pre .hljs-title,.ProseMirror pre .hljs-section,.ProseMirror pre .hljs-name,.ProseMirror pre .hljs-selector-id,.ProseMirror pre .hljs-selector-class{color:#6639ba;}
.ProseMirror pre .hljs-attr,.ProseMirror pre .hljs-attribute,.ProseMirror pre .hljs-variable,.ProseMirror pre .hljs-template-variable{color:#953800;}
.ProseMirror pre .hljs-tag{color:#116329;}
.ProseMirror pre .hljs-deletion{color:#cf222e;}
.ProseMirror pre .hljs-emphasis{font-style:italic;}.ProseMirror pre .hljs-strong{font-weight:700;}
.ProseMirror img{max-width:100%;height:auto;border-radius:16px;display:block;margin:1.1em auto;box-shadow:0 6px 22px rgba(20,10,40,.08);}
.ProseMirror hr{border:none;height:0;border-top:1px solid var(--line);margin:1.6em 0;position:relative;}
.ProseMirror hr::after{content:'';position:absolute;left:50%;top:-4px;transform:translateX(-50%);width:6px;height:6px;border-radius:50%;background:#dcdfe4;}
.ProseMirror ::selection{background:rgba(39,130,251,.18);}
.ProseMirror p.is-editor-empty:first-child::before{content:attr(data-placeholder);float:left;color:#c2c6cd;pointer-events:none;height:0;}
/* 表格 */
.ProseMirror table{border-collapse:collapse;table-layout:fixed;width:100%;max-width:100%;margin:1.15em 0;}
.ProseMirror td,.ProseMirror th{border:1px solid #e4e7ec;padding:9px 12px;vertical-align:top;position:relative;font-size:15px;line-height:1.6;box-sizing:border-box;min-width:0;word-break:break-word;overflow-wrap:anywhere;}
.ProseMirror th{background:#f5f6f8;font-weight:700;text-align:left;color:#1d1d1f;}
.ProseMirror td p,.ProseMirror th p{margin:0;}
.ProseMirror .selectedCell:after{content:'';position:absolute;inset:0;background:rgba(39,130,251,.12);pointer-events:none;}
.ProseMirror .column-resize-handle{position:absolute;right:-1px;top:0;bottom:0;width:3px;background:#2782FB;pointer-events:none;}
.ProseMirror.resize-cursor{cursor:col-resize;}
.scale table{border-collapse:collapse;width:100%;font-size:15px;}
.scale th{background:#f5f6f8;font-weight:700;border:1px solid #e4e7ec;padding:8px 12px;text-align:left;}
.scale td{border:1px solid #e4e7ec;padding:8px 12px;color:#3a3d46;}
/* 卡片块(编辑区 + 列表预览共用) */
[data-card]{margin:1.3em 0;border-radius:22px;padding:26px;}
[data-card][data-tone="light"]{background:#faf9ff;border:1px solid rgba(20,10,40,.06);}
[data-card][data-tone="blue"]{background:linear-gradient(135deg,#eef4ff,#fdeee9);border:1px solid rgba(39,130,251,.12);}
[data-card][data-tone="dark"]{background:#1d1d1f;}
[data-card][data-tone="dark"] h2,[data-card][data-tone="dark"] h3{color:#f5f5f7;text-align:center;}
[data-card][data-tone="dark"] p{color:#a1a1a6;text-align:center;}
[data-card][data-tone="dark"] strong{color:#fff;}
[data-card]>*:first-child{margin-top:0;}
[data-card]>*:last-child{margin-bottom:0;}
/* 列表预览里的基础排版(卡片之外的裸 p/h/quote) */
.scale h2{font-size:23px;font-weight:700;color:#1d1d1f;margin:.4em 0;}
.scale h3{font-size:18px;font-weight:700;color:#1d1d1f;margin:.3em 0;}
.scale p{font-size:16px;line-height:1.8;color:#3a3d46;margin:.5em 0;}
.scale blockquote{background:#f5f5f7;border-radius:14px;padding:14px 20px;color:#6e6e73;}
.scale strong{font-weight:700;color:#1d1d1f;}
.scale hr{border:none;border-top:1px solid #e6e8ec;margin:14px 0;}
/* 页脚分割线(通栏细线 + 1px 发丝阴影)+ 浅灰 logo */
.page-fold{height:1px;background:var(--line);margin:24px 0 0;box-shadow:0 1px 1px rgba(20,10,40,.05);}
.page-foot{padding:26px 40px 38px;text-align:center;}
.page-foot .mark{width:23px;height:22px;margin:0 auto 8px;}
.page-foot .nm{font-family:var(--logo);font-weight:700;font-size:23px;line-height:1;color:#b9bdc4;margin-bottom:12px;}
.page-foot .cc{font-size:12.5px;color:#b9bdc4;letter-spacing:.2px;}
/* ============ Bubble / Floating(自建,可点) ============ */
.bubble{position:fixed;z-index:90;display:none;align-items:center;gap:2px;background:var(--ink);border-radius:11px;padding:5px;box-shadow:0 12px 34px rgba(11,11,15,.34);}
.bubble.show{display:flex;}
.bubble button{height:30px;min-width:30px;padding:0 8px;border:none;background:transparent;color:#e9eaec;cursor:pointer;border-radius:7px;font-size:13.5px;font-family:var(--font);display:inline-flex;align-items:center;justify-content:center;transition:background .12s,color .12s;}
.bubble button:hover{background:rgba(255,255,255,.13);}
.bubble button.active{background:#fff;color:var(--ink);}
.bubble .sep{width:1px;height:18px;background:rgba(255,255,255,.16);margin:0 3px;}
.bubble b{font-weight:800;}.bubble i{font-style:italic;}.bubble s{text-decoration:line-through;}
.floating{position:fixed;z-index:90;display:none;flex-direction:column;background:#fff;border:1px solid var(--border);border-radius:13px;box-shadow:var(--shadow);padding:6px;width:200px;}
.floating.show{display:flex;}
.floating button{display:flex;align-items:center;gap:9px;height:32px;padding:0 9px;border:none;background:transparent;cursor:pointer;border-radius:8px;font-size:13px;color:var(--text);font-family:var(--font);text-align:left;transition:background .12s;}
.floating button:hover{background:#f3f4f6;}
.floating button .k{width:20px;text-align:center;color:var(--muted);font-size:14px;}
/* 表格工具条 */
.tablebar{position:fixed;z-index:90;display:none;align-items:center;gap:2px;background:#fff;border:1px solid var(--border);border-radius:11px;box-shadow:var(--shadow);padding:5px;}
.tablebar.show{display:flex;}
.tablebar button{height:28px;padding:0 10px;border:none;background:transparent;cursor:pointer;border-radius:7px;font-size:12.5px;color:var(--text);font-family:var(--font);display:inline-flex;align-items:center;white-space:nowrap;transition:background .12s,color .12s;}
.tablebar button:hover{background:#f3f4f6;}
.tablebar button.danger:hover{background:#fdecec;color:#e5484d;}
.tablebar .sep{width:1px;height:16px;background:var(--border);margin:0 3px;}
/* 代码块语言选择 */
.codebar{position:fixed;z-index:90;display:none;background:rgba(255,255,255,.92);backdrop-filter:blur(8px);border:1px solid var(--border);border-radius:9px;box-shadow:0 6px 20px rgba(11,11,15,.12);padding:3px;}
.codebar.show{display:block;}
.codebar select{border:none;background:transparent;font-family:var(--font);font-size:12px;color:var(--muted);cursor:pointer;outline:none;padding:3px 6px;border-radius:6px;max-width:140px;}
.codebar select:hover{background:#f3f4f6;}
/* ============ 弹窗 / Toast ============ */
.overlay{position:fixed;inset:0;background:rgba(11,11,15,.42);display:none;align-items:center;justify-content:center;z-index:120;backdrop-filter:blur(3px);}
.overlay.open{display:flex;}
.dialog{background:#fff;border-radius:18px;box-shadow:0 24px 70px rgba(11,11,15,.3);width:460px;max-width:92vw;overflow:hidden;}
.dialog h3{font-size:17px;padding:22px 24px 4px;display:flex;align-items:center;gap:8px;}
.dialog .sub{font-size:13px;color:var(--muted);padding:0 24px 16px;line-height:1.65;}
.dialog .field{padding:0 24px 14px;}
.dialog label{display:block;font-size:12px;color:var(--muted);margin-bottom:6px;font-weight:600;}
.dialog input{width:100%;padding:11px 13px;border:1px solid var(--border);border-radius:10px;font-size:14px;font-family:var(--font);outline:none;transition:border .15s;}
.dialog input:focus{border-color:var(--blue);box-shadow:0 0 0 3px rgba(39,130,251,.12);}
.dialog .actions{display:flex;gap:10px;justify-content:flex-end;padding:6px 24px 22px;}
.toast{position:fixed;top:22px;left:50%;transform:translateX(-50%);background:var(--ink);color:#fff;padding:11px 24px;border-radius:11px;font-size:14px;z-index:200;opacity:0;transition:opacity .3s;pointer-events:none;max-width:92vw;text-align:center;box-shadow:0 10px 30px rgba(11,11,15,.25);}
.toast.show{opacity:1;}
/* 加载 / 错误 */
#bootMsg{position:fixed;left:50%;top:120px;transform:translateX(-50%);z-index:300;background:#fff;border:1px solid var(--border);border-radius:12px;padding:14px 20px;font-size:14px;color:var(--muted);box-shadow:var(--shadow);}
#bootErr{display:none;position:fixed;left:50%;top:120px;transform:translateX(-50%);z-index:300;max-width:680px;width:92%;background:#fff;border:1px solid #f3b4b4;border-left:4px solid #e5484d;border-radius:12px;padding:16px 18px;box-shadow:0 12px 40px rgba(0,0,0,.18);}
#bootErr pre{white-space:pre-wrap;font-size:12px;color:#555;max-height:220px;overflow:auto;margin:8px 0 0;}
/* ============ 桌面端专用提示 ============ */
.desktop-only{display:none;}
@media (max-width:1180px),(pointer:coarse){
.topbar,.workspace,.bubble,.floating,#bootMsg{display:none!important;}
.desktop-only{display:flex;flex-direction:column;align-items:center;justify-content:center;gap:18px;position:fixed;inset:0;padding:40px;text-align:center;background:var(--bg);z-index:500;}
.desktop-only .mark{width:54px;height:52px;}
.desktop-only .name{font-family:var(--logo);font-weight:700;font-size:40px;color:var(--ink);line-height:1;}
.desktop-only h2{font-size:20px;font-weight:700;color:var(--text);}
.desktop-only p{font-size:14px;color:var(--muted);line-height:1.7;max-width:300px;}
}
</style>
</head>
<body>
<div class="toast" id="toast"></div>
<div id="bootMsg">⏳ 正在加载编辑器内核…</div>
<div id="bootErr"><div style="font-weight:700;color:#e5484d;">编辑器加载失败</div><pre></pre><div style="font-size:12px;color:#888;margin-top:8px;">把红框文字发我即可定位。</div></div>
<!-- 桌面端专用 -->
<div class="desktop-only">
<svg class="mark" viewBox="0 0 38 36" id="dtMark" aria-hidden="true"></svg>
<div class="name">SwiftGG</div>
<h2>请在桌面端使用</h2>
<p>公众号编辑器需要更大的屏幕来同时编辑与预览,请用电脑浏览器打开 🙏</p>
</div>
<!-- 顶部栏:仅 撤销 / 重做 / 复制 -->
<div class="topbar">
<div class="brand">
<svg class="mark" viewBox="0 0 38 36" id="brandMark" aria-hidden="true"></svg>
<span class="name">SwiftGG</span><span class="tag">公众号编辑器</span>
</div>
<div class="tb-group">
<button class="tbtn icon-only" id="undoBtn" title="撤销 ⌘Z"><svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M3 7v6h6"/><path d="M21 17a9 9 0 0 0-9-9 8.6 8.6 0 0 0-6 2.4L3 13"/></svg></button>
<button class="tbtn icon-only" id="redoBtn" title="重做 ⌘⇧Z"><svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M21 7v6h-6"/><path d="M3 17a9 9 0 0 1 9-9 8.6 8.6 0 0 1 6 2.4L21 13"/></svg></button>
</div>
<button class="tbtn primary" id="copyBtn"><span class="ic">📋</span>复制到公众号</button>
</div>
<!-- 工作区 -->
<div class="workspace">
<aside class="rail"><div class="rail-h">插入区块</div><div id="railList"></div></aside>
<main class="canvas">
<article class="page" id="page">
<header class="page-head">
<svg class="mark" viewBox="0 0 38 36" id="headMark" aria-hidden="true"></svg>
<span class="name">SwiftGG</span>
</header>
<div class="page-body"><div id="editor"></div></div>
<div class="page-fold"></div>
<footer class="page-foot">
<svg class="mark" viewBox="0 0 38 36" id="footMark" aria-hidden="true"></svg>
<div class="nm">SwiftGG</div>
<div class="cc">© 2026 SwiftGG · 保留所有权利</div>
</footer>
</article>
</main>
</div>
<!-- Bubble / Floating -->
<div class="bubble" id="bubble">
<button data-act="bold" title="加粗"><b>B</b></button>
<button data-act="italic" title="斜体"><i>I</i></button>
<button data-act="strike" title="删除线"><s>S</s></button>
<button data-act="code" title="行内代码"></></button>
<button data-act="link" title="链接">🔗</button>
<span class="sep"></span>
<button data-act="h1">H1</button>
<button data-act="h2">H2</button>
<button data-act="h3">H3</button>
<button data-act="quote">❝</button>
<button data-act="bullet">• 列</button>
</div>
<div class="floating" id="floating">
<button data-act="h1"><span class="k">H1</span>大标题</button>
<button data-act="h2"><span class="k">H2</span>小标题</button>
<button data-act="quote"><span class="k">❝</span>引用</button>
<button data-act="bullet"><span class="k">•</span>无序列表</button>
<button data-act="ordered"><span class="k">1.</span>有序列表</button>
<button data-act="codeblock"><span class="k">{}</span>代码块</button>
<button data-act="hr"><span class="k">—</span>分隔线</button>
</div>
<div class="tablebar" id="tablebar">
<button data-tact="colBefore" title="左侧插入列">+列左</button>
<button data-tact="colAfter" title="右侧插入列">+列右</button>
<button data-tact="colDel" title="删除当前列">-列</button>
<span class="sep"></span>
<button data-tact="rowBefore" title="上方插入行">+行上</button>
<button data-tact="rowAfter" title="下方插入行">+行下</button>
<button data-tact="rowDel" title="删除当前行">-行</button>
<span class="sep"></span>
<button data-tact="header" title="切换表头行">表头</button>
<button data-tact="del" class="danger" title="删除整个表格">删表</button>
</div>
<div class="codebar" id="codebar"><select id="cbLang" title="选择高亮语言"></select></div>
<!-- 图片弹窗 -->
<div class="overlay" id="imgOverlay">
<div class="dialog">
<h3>🖼️ 插入图片</h3>
<div class="sub">粘贴图片的网络地址。复制到公众号后,微信会自动把外链图片转存为本地图,正常显示。</div>
<div class="field"><label>图片 URL</label><input id="imgUrl" placeholder="https://… .png / .jpg / .webp"></div>
<div class="field"><label>替代文字(可选)</label><input id="imgAlt" placeholder="例如:Lanyard 产品图"></div>
<div class="actions"><button class="tbtn" data-close>取消</button><button class="tbtn primary" id="imgOk">插入</button></div>
</div>
</div>
<script>
/* 灰色小鸟图标 */
const MARK_PATHS=[
'M7.44735 27.9065C7.31528 28.1316 7.15585 28.3368 6.995 28.5417C6.51988 29.147 5.87192 29.5224 5.20452 29.8602C4.9764 29.9757 4.74803 30.0649 4.71226 30.3386C4.6724 30.6434 4.92838 30.7455 5.1391 30.8672C5.16619 30.8828 5.19743 30.8912 5.22662 30.9032C6.93253 31.6036 8.69729 32.1024 10.5047 32.4613C12.4666 32.8508 14.4464 33.0785 16.4445 33.1471C17.6758 33.1894 18.9057 33.1612 20.1342 33.0565C21.5884 32.9325 23.0026 32.6521 24.3588 32.0907C25.9932 31.414 27.4202 30.4482 28.6387 29.1638C30.3134 27.3984 31.433 25.3245 32.1008 22.9977C32.646 21.0982 32.8345 19.1621 32.6815 17.1897C32.584 15.9325 32.3646 14.698 31.9599 13.5077C31.4676 12.0597 30.838 10.6715 30.0587 9.34789C29.0948 7.71061 27.8095 6.39045 26.239 5.34754C23.6379 3.62019 20.7532 2.78744 17.6424 2.7383C15.7225 2.70798 13.8581 3.0177 12.0782 3.76951C11.7301 3.91654 11.3609 4.01411 11.0147 4.16471C9.3082 4.90683 7.8945 6.0248 6.77729 7.51337C5.72694 8.91283 5.06688 10.4873 4.71889 12.1948C4.42158 13.6536 4.4229 15.1234 4.56447 16.6008C4.63306 17.3162 4.88424 17.9763 5.08367 18.6537C5.1244 19.1013 5.35236 19.4922 5.51005 19.8957C5.76843 20.5568 6.06467 21.1987 6.27692 21.8827C6.46758 22.4971 6.77214 23.0801 7.06399 23.658C7.3854 24.2945 7.6524 24.9432 7.69251 25.6613C7.72716 26.2813 7.77488 26.904 7.58024 27.5138C7.53819 27.6456 7.41933 27.7521 7.44735 27.9065ZM16.9108 35.3626C14.7648 35.3474 12.0176 35.0507 9.30305 34.4488C7.52012 34.0535 5.77527 33.5393 4.1014 32.8043C2.84692 32.2535 1.65301 31.5983 0.662465 30.6298C0.308809 30.284 0.113711 29.8645 0.296153 29.3655C0.497068 28.8161 0.885631 28.4691 1.47705 28.3603C1.9712 28.2695 2.47101 28.2172 2.94546 28.0178C3.76127 27.6749 4.22332 27.0782 4.44071 26.2274C4.6055 25.5825 4.46562 24.9821 4.28001 24.3921C3.96106 23.3783 3.61455 22.3726 3.2689 21.3669C2.73873 19.8244 2.20635 18.2783 1.9936 16.6496C1.89097 15.864 1.88817 15.0702 1.98467 14.2868C2.10985 13.2703 2.24141 12.2524 2.52362 11.2615C2.80104 10.2875 3.16934 9.35513 3.64139 8.4565C4.12329 7.53919 4.63785 6.64699 5.29046 5.84067C6.67849 4.12567 8.40482 2.87011 10.436 2.01011C12.6738 1.06269 14.9919 0.539303 17.4274 0.544967C18.862 0.548284 20.2756 0.703882 21.6724 1.03156C24.1979 1.62405 26.4969 2.6913 28.5311 4.30622C30.0046 5.47609 31.2363 6.86158 32.1067 8.53846C32.3568 9.02026 32.5997 9.50609 32.8561 9.98513C32.9342 10.131 33.0332 10.1998 33.1919 10.2416C34.3509 10.5463 35.5108 10.8488 36.6538 11.2108C36.9405 11.3016 37.2166 11.416 37.4325 11.6409C37.8297 12.0547 37.8182 12.5926 37.3947 12.9794C37.3078 13.0587 37.2099 13.1275 37.1111 13.1922C36.5112 13.585 35.9063 13.9703 35.3105 14.3694C35.1352 14.4868 34.9817 14.6376 34.823 14.7785C34.6625 14.921 34.6185 15.0932 34.6587 15.3106C34.9879 17.0861 35.0253 18.875 34.8118 20.6625C34.5418 22.923 33.8951 25.0737 32.8182 27.0891C31.9903 28.6385 30.9557 30.0298 29.6835 31.2415C28.6722 32.2046 27.5239 32.9726 26.3036 33.6482C24.9561 34.3941 23.499 34.7724 21.9998 35.0263C20.5255 35.276 19.0377 35.3634 16.9108 35.3626Z',
'M5.07812 18.6549C5.20142 17.9623 5.56845 17.4046 6.03366 16.8953C6.74408 16.1174 7.55443 15.4624 8.53114 15.0696C9.7596 14.5755 11.0342 14.2376 12.3804 14.3556C14.6484 14.5544 16.5017 15.5243 17.892 17.3478C18.4238 18.0453 18.8216 18.8135 19.0701 19.6489C19.4788 21.0229 19.509 22.4085 19.1337 23.8024C18.7325 25.2929 17.9469 26.5462 16.7868 27.5452C15.7804 28.4118 14.61 28.9758 13.2917 29.2228C11.9402 29.476 10.6198 29.3652 9.33057 28.9113C8.69868 28.6889 8.1017 28.3834 7.56158 27.9783C7.52447 27.9506 7.48099 27.9314 7.44114 27.9079C7.41379 27.7534 7.53264 27.6468 7.57469 27.515C7.76933 26.9052 7.72161 26.2826 7.68696 25.6625C7.64685 24.9444 7.3799 24.2958 7.05845 23.6592C6.76664 23.0813 6.46203 22.4983 6.27137 21.884C6.05912 21.1999 5.76293 20.558 5.5045 19.8969C5.34681 19.4935 5.11885 19.1025 5.07812 18.6549Z',
'M21.6179 12.4282C21.5936 10.86 22.8255 9.92341 24.0155 9.90265C25.2555 9.88106 26.3796 11.1108 26.3462 12.3791C26.3111 13.7122 25.1708 14.7914 23.8191 14.7704C22.5904 14.7514 21.5925 13.6895 21.6179 12.4282Z'];
function markSVG(el,color){if(el)el.innerHTML=MARK_PATHS.map(d=>`<path d="${d}" fill="${color}"/>`).join('');}
// 给导出用:返回与文字同色的内联 SVG 标志(保证 logo 与 logotype 颜色一致)
window.sgMarkSVG=(color,w)=>`<svg width="${w}" height="${(w*35/38).toFixed(1)}" viewBox="0 0 38 36" xmlns="http://www.w3.org/2000/svg" style="display:inline-block;vertical-align:middle;">`+MARK_PATHS.map(d=>`<path d="${d}" fill="${color}"/>`).join('')+`</svg>`;
markSVG(document.getElementById('brandMark'),'#0B0B0F');
markSVG(document.getElementById('headMark'),'#86868b');
markSVG(document.getElementById('footMark'),'#b9bdc4');
markSVG(document.getElementById('dtMark'),'#86868b');
</script>
<script type="module">
const bootErrBox=document.getElementById('bootErr'), bootMsg=document.getElementById('bootMsg');
function showBootError(err){console.error(err);if(bootMsg)bootMsg.style.display='none';if(bootErrBox){bootErrBox.style.display='block';bootErrBox.querySelector('pre').textContent=(err&&err.stack)||String(err);}}
window.addEventListener('error',e=>showBootError(e.error||e.message));
window.addEventListener('unhandledrejection',e=>showBootError(e.reason));
(async()=>{ try{
const { Editor, Node, mergeAttributes, StarterKit, Image, Link, Placeholder, Table, TableRow, TableHeader, TableCell, CodeBlockLowlight, createLowlight, lowlightCommon } = await import('./assets/esm/tiptap.js');
if(bootMsg)bootMsg.style.display='none';
const lowlight=createLowlight(lowlightCommon);
function escapeHtml(t){const m={'&':'&','<':'<','>':'>','"':'"',"'":'''};return String(t).replace(/[&<>"']/g,c=>m[c]);}
const $=id=>document.getElementById(id);
function toast(m){const t=$('toast');t.textContent=m;t.classList.add('show');clearTimeout(t._t);t._t=setTimeout(()=>t.classList.remove('show'),2800);}
/* ---- 卡片节点 ---- */
const Card=Node.create({
name:'card', group:'block', content:'block+', defining:true,
addAttributes(){return{tone:{default:'light'}};},
parseHTML(){return[{tag:'section[data-card]',getAttrs:el=>({tone:el.getAttribute('data-tone')||'light'})}];},
renderHTML({node,HTMLAttributes}){return['section',mergeAttributes({'data-card':'','data-tone':node.attrs.tone},HTMLAttributes),0];},
});
/* ---- 编辑器 ---- */
const editor=new Editor({
element:$('editor'),
extensions:[
StarterKit.configure({heading:{levels:[1,2,3]},codeBlock:false}),
CodeBlockLowlight.configure({lowlight,defaultLanguage:'plaintext'}),
Image.configure({inline:false,allowBase64:true}),
Link.configure({openOnClick:false,autolink:true,HTMLAttributes:{rel:'noopener',target:'_blank'}}),
Placeholder.configure({placeholder:({node})=>node.type.name==='heading'?'标题…':"开始写作 —— “## ” 变标题,“- ” 列表,“> ” 引用;空行出现 + 菜单,左侧可插入区块/图片"}),
Card,
Table.configure({resizable:false}), TableRow, TableHeader, TableCell,
],
content:DEFAULT_DOC(),
autofocus:'end',
});
window.__editor=editor;
function DEFAULT_DOC(){return `
<h1>欢迎使用 SwiftGG 公众号编辑器</h1>
<p>这是一个<strong>所见即所得</strong>的编辑器:你看到的样子,就是公众号里的样子。像 Notion 一样写作——输入 <code>##</code> 加空格变小标题,<code>-</code> 变列表,<code>></code> 变引用。</p>
<p>选中文字会弹出<strong>格式条</strong>;空行行首出现 <strong>+ 菜单</strong>。左侧可插入 <strong>SwiftGG 区块</strong>、<strong>表格</strong>与<strong>图片</strong>。</p>
<blockquote>页眉页脚已内置 SwiftGG 标志(Dongle 字体),写完点右上角「复制到公众号」即可粘贴。</blockquote>
<h2>试试这些</h2>
<ul><li>在左侧点一张卡片或表格插入</li><li>选中这句话,把它加粗</li><li>用「## 」快速生成小标题</li></ul>
<hr>
<pre><code class="language-swift">import SwiftGG
@resultBuilder
enum Blessing {
static func buildBlock(_ parts: String...) -> String { parts.joined() }
}
@Blessing func wish() -> String {
"祝你"
"写出漂亮的推文"
" ✨"
}
print(wish()) // 祝你写出漂亮的推文 ✨</code></pre>`;}
/* ===================== 格式动作 ===================== */
function runAct(act){
const c=editor.chain().focus();
switch(act){
case'bold':c.toggleBold().run();break;
case'italic':c.toggleItalic().run();break;
case'strike':c.toggleStrike().run();break;
case'code':c.toggleCode().run();break;
case'h1':c.toggleHeading({level:1}).run();break;
case'h2':c.toggleHeading({level:2}).run();break;
case'h3':c.toggleHeading({level:3}).run();break;
case'quote':c.toggleBlockquote().run();break;
case'bullet':c.toggleBulletList().run();break;
case'ordered':c.toggleOrderedList().run();break;
case'hr':c.setHorizontalRule().run();break;
case'codeblock':c.toggleCodeBlock().run();break;
case'link':setLink();break;
}
syncBubble();
}
function setLink(){
const prev=editor.getAttributes('link').href||'';
const url=window.prompt('链接地址:',prev);
if(url===null)return;
if(url==='')editor.chain().focus().extendMarkRange('link').unsetLink().run();
else editor.chain().focus().extendMarkRange('link').setLink({href:url}).run();
}
/* ===================== 自建 Bubble 菜单 ===================== */
const bubble=$('bubble'), floating=$('floating'), tablebar=$('tablebar');
document.querySelectorAll('#bubble button').forEach(b=>b.addEventListener('mousedown',e=>{e.preventDefault();runAct(b.dataset.act);}));
document.querySelectorAll('#floating button').forEach(b=>b.addEventListener('mousedown',e=>{e.preventDefault();runAct(b.dataset.act);hideFloating();}));
document.querySelectorAll('#tablebar button').forEach(b=>b.addEventListener('mousedown',e=>{e.preventDefault();runTable(b.dataset.tact);}));
function runTable(act){
const c=editor.chain().focus();
({colBefore:()=>c.addColumnBefore().run(),colAfter:()=>c.addColumnAfter().run(),colDel:()=>c.deleteColumn().run(),
rowBefore:()=>c.addRowBefore().run(),rowAfter:()=>c.addRowAfter().run(),rowDel:()=>c.deleteRow().run(),
header:()=>c.toggleHeaderRow().run(),del:()=>c.deleteTable().run()})[act]?.();
setTimeout(refreshMenus,0);
}
function positionTable(){
if(!editor.isFocused||!editor.isActive('table')){tablebar.classList.remove('show');return;}
let dom=editor.view.domAtPos(editor.state.selection.from).node;
if(dom.nodeType===3)dom=dom.parentElement;
const table=dom&&dom.closest?dom.closest('table'):null;
if(!table){tablebar.classList.remove('show');return;}
tablebar.classList.add('show');
const r=table.getBoundingClientRect(), bw=tablebar.offsetWidth, bh=tablebar.offsetHeight;
let left=Math.max(10,Math.min(r.left,window.innerWidth-bw-10));
let top=r.top-bh-8; if(top<64)top=r.bottom+8;
tablebar.style.left=left+'px'; tablebar.style.top=top+'px';
}
/* 代码块语言选择 */
const codebar=$('codebar'), cbLang=$('cbLang');
(function(){
const langs=lowlight.listLanguages().sort();
cbLang.appendChild(new Option('纯文本','plaintext'));
langs.forEach(l=>cbLang.appendChild(new Option(l,l)));
})();
cbLang.addEventListener('change',()=>{editor.chain().focus().updateAttributes('codeBlock',{language:cbLang.value}).run();setTimeout(refreshMenus,0);});
function positionCode(){
const onbar=codebar.contains(document.activeElement);
if(!editor.isActive('codeBlock')||(!editor.isFocused&&!onbar)){codebar.classList.remove('show');return;}
let dom=editor.view.domAtPos(editor.state.selection.from).node;
if(dom.nodeType===3)dom=dom.parentElement;
const pre=dom&&dom.closest?dom.closest('pre'):null;
if(!pre){codebar.classList.remove('show');return;}
codebar.classList.add('show');
if(!onbar)cbLang.value=editor.getAttributes('codeBlock').language||'plaintext';
const r=pre.getBoundingClientRect(), bw=codebar.offsetWidth;
let left=Math.max(10,Math.min(r.right-bw-8,window.innerWidth-bw-10)), top=Math.max(64,r.top+8);
codebar.style.left=left+'px'; codebar.style.top=top+'px';
}
function syncBubble(){
const map={bold:'bold',italic:'italic',strike:'strike',code:'code',h1:['heading',{level:1}],h2:['heading',{level:2}],h3:['heading',{level:3}],quote:'blockquote',bullet:'bulletList'};
document.querySelectorAll('#bubble button').forEach(b=>{
const m=map[b.dataset.act];if(!m)return;
b.classList.toggle('active',Array.isArray(m)?editor.isActive(m[0],m[1]):editor.isActive(m));
});
}
function positionBubble(){
const {state,view}=editor, {from,to,empty}=state.selection;
if(empty||!editor.isFocused){bubble.classList.remove('show');return;}
bubble.classList.add('show');
const a=view.coordsAtPos(from), b=view.coordsAtPos(to);
const cx=(a.left+b.left)/2, top=Math.min(a.top,b.top);
const bw=bubble.offsetWidth, bh=bubble.offsetHeight;
let left=cx-bw/2; left=Math.max(10,Math.min(left,window.innerWidth-bw-10));
let y=top-bh-9; if(y<64)y=Math.max(a.bottom,b.bottom)+9;
bubble.style.left=left+'px'; bubble.style.top=y+'px';
syncBubble();
}
function positionFloating(){
const {state,view}=editor, {selection}=state, {empty,$from}=selection;
const node=$from.parent;
if(empty&&editor.isFocused&&node.type.name==='paragraph'&&node.content.size===0&&!editor.isActive('table')){
floating.classList.add('show');
const c=view.coordsAtPos($from.pos);
let left=c.left+10, top=c.top-4;
if(left+floating.offsetWidth>window.innerWidth-12)left=c.left-floating.offsetWidth-10;
if(top+floating.offsetHeight>window.innerHeight-12)top=window.innerHeight-floating.offsetHeight-12;
floating.style.left=left+'px'; floating.style.top=top+'px';
}else floating.classList.remove('show');
}
function hideFloating(){floating.classList.remove('show');}
function refreshMenus(){positionBubble();positionFloating();positionTable();positionCode();}
editor.on('selectionUpdate',refreshMenus);
editor.on('focus',refreshMenus);
editor.on('blur',()=>setTimeout(()=>{if(!editor.isFocused&&!codebar.contains(document.activeElement)){bubble.classList.remove('show');hideFloating();tablebar.classList.remove('show');codebar.classList.remove('show');}},150));
editor.on('update',()=>{syncBubble();positionFloating();positionTable();positionCode();});
$('editor').addEventListener('scroll',refreshMenus,true);
document.querySelector('.canvas').addEventListener('scroll',()=>{bubble.classList.remove('show');hideFloating();positionTable();positionCode();});
/* ===================== 撤销/重做 ===================== */
$('undoBtn').addEventListener('click',()=>editor.chain().focus().undo().run());
$('redoBtn').addEventListener('click',()=>editor.chain().focus().redo().run());
/* ===================== 导出 / 复制(内联样式) ===================== */
/* 代码高亮 → 内联样式(导出时重新高亮,微信不支持 class) */
const HLJS={comment:'#8a919b',quote:'#8a919b',keyword:'#cf222e','selector-tag':'#cf222e',literal:'#cf222e',doctag:'#cf222e',string:'#0a7d22',regexp:'#0a7d22',addition:'#0a7d22','meta-string':'#0a7d22',number:'#0550ae',built_in:'#0550ae',type:'#0550ae',symbol:'#0550ae',bullet:'#0550ae',meta:'#0550ae',title:'#6639ba',section:'#6639ba',name:'#6639ba','selector-id':'#6639ba','selector-class':'#6639ba',attr:'#953800',attribute:'#953800',variable:'#953800','template-variable':'#953800',tag:'#116329',deletion:'#cf222e'};
const LANGSET=new Set(lowlight.listLanguages());
function hastToHTML(n){
if(n.type==='text')return escapeHtml(n.value);
if(n.type==='element'){
const cn=(n.properties&&n.properties.className)||[];
const cls=(Array.isArray(cn)?cn:[cn]).find(c=>typeof c==='string'&&c.indexOf('hljs-')===0);
const inner=(n.children||[]).map(hastToHTML).join('');
const col=cls?HLJS[cls.slice(5)]:null;
return col?`<span style="color:${col};">${inner}</span>`:inner;
}
return (n.children||[]).map(hastToHTML).join('');
}
function highlightCode(code,lang){
try{
const tree=(lang&&lang!=='plaintext'&&LANGSET.has(lang))?lowlight.highlight(lang,code):lowlight.highlightAuto(code);
return (tree.children||[]).map(hastToHTML).join('')||escapeHtml(code);
}catch(_){return escapeHtml(code);}
}
const TH={
h1:'font-size:30px;line-height:1.18;font-weight:800;letter-spacing:-.8px;color:#1d1d1f;margin:1.2em 0 .5em;text-align:center;',
h2:'font-size:23px;line-height:1.25;font-weight:700;letter-spacing:-.4px;color:#1d1d1f;margin:1.4em 0 .55em;',
h3:'font-size:18px;line-height:1.35;font-weight:700;color:#1d1d1f;margin:1.2em 0 .4em;',
p:'font-size:16px;line-height:1.85;color:#3a3d46;letter-spacing:.2px;margin:.75em 0;',
strong:'font-weight:700;color:#1d1d1f;',
a:'color:#2782FB;text-decoration:none;font-weight:500;',
blockquote:'margin:1.15em 0;padding:14px 20px;background:#f5f5f7;border-radius:14px;color:#6e6e73;font-size:15.5px;line-height:1.7;',
code:'font-family:SF Mono,Menlo,Monaco,monospace;font-size:.86em;background:#f0f0f3;padding:2px 6px;border-radius:6px;color:#bf4080;letter-spacing:0;',
pre:'background:#f5f5f7;color:#1d1d1f;border:1px solid #ececef;padding:16px 18px;border-radius:14px;overflow-x:auto;margin:1.15em 0;font-size:13.5px;line-height:1.7;font-family:SF Mono,Menlo,Monaco,monospace;',
img:'max-width:100%;height:auto;border-radius:16px;display:block;margin:1.1em auto;',
hr:'border:none;border-top:1px solid #eceef1;margin:1.6em 0;',
ul:'padding-left:1.4em;margin:.7em 0;',ol:'padding-left:1.4em;margin:.7em 0;',
li:'margin:.32em 0;color:#3a3d46;font-size:16px;line-height:1.85;',
table:'border-collapse:collapse;table-layout:fixed;width:100%;margin:1.15em 0;font-size:15px;',
th:'border:1px solid #e4e7ec;padding:9px 12px;background:#f5f6f8;font-weight:700;text-align:left;color:#1d1d1f;word-break:break-word;',
td:'border:1px solid #e4e7ec;padding:9px 12px;color:#3a3d46;vertical-align:top;word-break:break-word;',
};
const CARD={
light:'margin:1.3em 0;border-radius:22px;padding:26px;background:#faf9ff;border:1px solid rgba(20,10,40,.06);',
blue:'margin:1.3em 0;border-radius:22px;padding:26px;background:linear-gradient(135deg,#eef4ff,#fdeee9);border:1px solid rgba(39,130,251,.12);',
dark:'margin:1.3em 0;border-radius:22px;padding:30px 26px;background:#1d1d1f;',
};
function inlineStyle(root){
root.querySelectorAll('h1').forEach(e=>e.setAttribute('style',TH.h1));
root.querySelectorAll('h2').forEach(e=>{const d=e.closest('[data-card][data-tone="dark"]');e.setAttribute('style',TH.h2+(d?'color:#f5f5f7;text-align:center;':''));});
root.querySelectorAll('h3').forEach(e=>{const d=e.closest('[data-card][data-tone="dark"]');e.setAttribute('style',TH.h3+(d?'color:#f5f5f7;text-align:center;':''));});
root.querySelectorAll('p').forEach(e=>{const d=e.closest('[data-card][data-tone="dark"]');e.setAttribute('style',(e.getAttribute('style')||'')+';'+TH.p+(d?'color:#a1a1a6;text-align:center;':''));});
root.querySelectorAll('strong,b').forEach(e=>{const d=e.closest('[data-card][data-tone="dark"]');e.setAttribute('style',TH.strong+(d?'color:#fff;':''));});
root.querySelectorAll('em,i').forEach(e=>e.setAttribute('style','font-style:italic;'));
root.querySelectorAll('s,del').forEach(e=>e.setAttribute('style','text-decoration:line-through;color:#a1a1a6;'));
root.querySelectorAll('a').forEach(e=>e.setAttribute('style',TH.a));
root.querySelectorAll('blockquote').forEach(e=>e.setAttribute('style',TH.blockquote));
root.querySelectorAll('pre code').forEach(e=>{const m=(e.className||'').match(/language-([\w-]+)/);e.innerHTML=highlightCode(e.textContent,m?m[1]:'');});
root.querySelectorAll('pre').forEach(e=>e.setAttribute('style',TH.pre));
root.querySelectorAll('code').forEach(e=>{if(e.parentElement&&e.parentElement.tagName==='PRE')return;e.setAttribute('style',TH.code);});
root.querySelectorAll('img').forEach(e=>e.setAttribute('style',TH.img));
root.querySelectorAll('hr').forEach(e=>e.setAttribute('style',TH.hr));
root.querySelectorAll('ul').forEach(e=>e.setAttribute('style',TH.ul));
root.querySelectorAll('ol').forEach(e=>e.setAttribute('style',TH.ol));
root.querySelectorAll('li').forEach(e=>e.setAttribute('style',TH.li));
root.querySelectorAll('table').forEach(e=>e.setAttribute('style',TH.table));
root.querySelectorAll('th').forEach(e=>e.setAttribute('style',TH.th));
root.querySelectorAll('td').forEach(e=>e.setAttribute('style',TH.td));
root.querySelectorAll('section[data-card]').forEach(e=>{const t=e.getAttribute('data-tone')||'light';e.setAttribute('style',CARD[t]||CARD.light);});
}
function articleHTML(){
const wrap=document.createElement('div'); wrap.innerHTML=editor.getHTML(); inlineStyle(wrap);
const head=`<section style="text-align:center;padding:32px 26px 14px;"><span style="margin-right:8px;">${window.sgMarkSVG('#86868b',20)}</span><span style="font-size:18px;font-weight:600;color:#86868b;letter-spacing:.3px;vertical-align:middle;">SwiftGG</span></section>`;
const body=`<section style="padding:18px 26px 4px;">${wrap.innerHTML}</section>`;
const fold=`<section style="height:1px;background:#eceef1;margin:24px 0 0;box-shadow:0 1px 1px rgba(20,10,40,.05);"></section>`;
const foot=`<section style="text-align:center;padding:24px 26px 32px;"><div style="margin-bottom:8px;">${window.sgMarkSVG('#b9bdc4',23)}</div><p style="margin:0;font-size:12.5px;color:#b9bdc4;letter-spacing:.2px;">© 2026 SwiftGG · 保留所有权利</p></section>`;
const card=`<section style="background:#fcfcfc;border:1px solid #e6e8ec;border-radius:24px;overflow:hidden;">${head}${body}${fold}${foot}</section>`;
return `<section style="max-width:677px;margin:0 auto;padding:14px 12px;font-family:-apple-system,'PingFang SC','Helvetica Neue',Arial,sans-serif;color:#1d1d1f;-webkit-font-smoothing:antialiased;">${card}</section>`;
}
async function copyToWeChat(){
const html=articleHTML();
try{
await navigator.clipboard.write([new ClipboardItem({'text/html':new Blob([html],{type:'text/html'}),'text/plain':new Blob([editor.getText()],{type:'text/plain'})})]);
toast('✅ 已复制!打开公众号编辑器 ⌘/Ctrl+V 粘贴即可');
}catch(_){
const c=document.createElement('div');c.innerHTML=html;c.style.cssText='position:fixed;left:-9999px;top:0;';
document.body.appendChild(c);const r=document.createRange();r.selectNodeContents(c);
const s=window.getSelection();s.removeAllRanges();s.addRange(r);document.execCommand('copy');
document.body.removeChild(c);s.removeAllRanges();toast('✅ 已复制(降级模式)!到公众号 Ctrl+V 粘贴');
}
}
$('copyBtn').addEventListener('click',copyToWeChat);
/* ===================== 左侧插入列表(滚动 + 预览 + 点击插入) ===================== */
const BLOCKS=[
{em:'📝',nm:'导语段',content:`<p>在这里写第一段导语,用一句引语或一个真实场景切入,制造代入感。</p><p>第二段把痛点说透,让读者点头。</p><p><strong>所以我们做了 XXX —— 一句话点题。</strong></p>`},
{em:'🃏',nm:'浅色卡片',content:`<section data-card data-tone="light"><h3>功能标题 · 一句卖点</h3><p>描述这个功能解决了什么问题、怎么用、带来什么好处。</p></section>`},
{em:'🟦',nm:'品牌渐变卡',content:`<section data-card data-tone="blue"><h3>重点亮点</h3><p>用品牌渐变卡突出最想让读者记住的一句话。</p></section>`},
{em:'⬛',nm:'黑色理念区',content:`<section data-card data-tone="dark"><h2>一句有态度的设计主张</h2><p>用两三行把理念讲清楚,<strong>最后一句加重。</strong></p></section>`},
{em:'🧱',nm:'三连功能卡',content:`<section data-card data-tone="light"><h3>📲 功能一</h3><p>一句话描述。</p></section><section data-card data-tone="light"><h3>📇 功能二</h3><p>一句话描述。</p></section><section data-card data-tone="light"><h3>🤝 功能三</h3><p>一句话描述。</p></section>`},
{em:'❝',nm:'引用金句',content:`<blockquote>把最有力的一句话放这里,让它单独成段。</blockquote>`},
{em:'📲',nm:'行动号召',content:`<section data-card data-tone="light"><h2>现在就开始</h2><p>App Store 搜索 <strong>产品名</strong>,或扫码直达。用左侧「图片」插入二维码。</p></section>`},
{em:'🔚',nm:'结语署名',content:`<hr><p style="text-align:center"><strong>收尾金句,呼应主题。</strong></p><p style="text-align:center">SwiftGG 出品</p>`},
];
function previewMarkup(content){const w=document.createElement('div');w.innerHTML=content;inlineStyle(w);return w.innerHTML;}
const railList=$('railList');
// 图片项
(function(){
const el=document.createElement('button'); el.className='ri img';
el.innerHTML=`<div class="prev"><div class="ph">🖼️</div></div><div class="lbl"><span class="em">🖼️</span>插入图片<span class="ds">URL</span></div>`;
el.addEventListener('click',openImg); railList.appendChild(el);
})();
// 表格项
(function(){
const tp=`<table><tr><th>表头一</th><th>表头二</th></tr><tr><td>内容</td><td>内容</td></tr><tr><td>内容</td><td>内容</td></tr></table>`;
const el=document.createElement('button'); el.className='ri';
el.innerHTML=`<div class="prev"><div class="scale">${tp}</div></div><div class="lbl"><span class="em">▦</span>表格<span class="ds">点击插入</span></div>`;
el.addEventListener('click',()=>{editor.chain().focus().insertTable({rows:3,cols:3,withHeaderRow:true}).run();toast('▦ 已插入表格');});
railList.appendChild(el);
})();
// 区块项
BLOCKS.forEach(b=>{
const el=document.createElement('button'); el.className='ri';
el.innerHTML=`<div class="prev"><div class="scale">${previewMarkup(b.content)}</div></div><div class="lbl"><span class="em">${b.em}</span>${b.nm}<span class="ds">点击插入</span></div>`;
el.addEventListener('click',()=>{editor.chain().focus().insertContent(b.content).run();toast('🧩 已插入:'+b.nm);});
railList.appendChild(el);
});
/* ===================== 图片弹窗 ===================== */
function openImg(){$('imgUrl').value='';$('imgAlt').value='';$('imgOverlay').classList.add('open');setTimeout(()=>$('imgUrl').focus(),50);}
$('imgOk').addEventListener('click',()=>{
const url=$('imgUrl').value.trim();if(!url){toast('⚠️ 请填写图片 URL');return;}
editor.chain().focus().setImage({src:url,alt:$('imgAlt').value.trim()}).run();
$('imgOverlay').classList.remove('open');toast('🖼️ 已插入图片');
});
document.querySelectorAll('[data-close]').forEach(b=>b.addEventListener('click',()=>document.querySelectorAll('.overlay').forEach(o=>o.classList.remove('open'))));
document.querySelectorAll('.overlay').forEach(o=>o.addEventListener('mousedown',e=>{if(e.target===o)o.classList.remove('open');}));
/* ===================== 快捷键 ===================== */
document.addEventListener('keydown',e=>{
if((e.metaKey||e.ctrlKey)&&e.key==='Enter'){e.preventDefault();copyToWeChat();}
if(e.key==='Escape')document.querySelectorAll('.overlay').forEach(o=>o.classList.remove('open'));
});
syncBubble();
console.log('✅ SwiftGG 公众号编辑器(Tiptap)已就绪');
}catch(err){ showBootError(err); }
})();
</script>
</body>
</html>