-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
890 lines (837 loc) · 60.7 KB
/
Copy pathindex.html
File metadata and controls
890 lines (837 loc) · 60.7 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
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<script src="./support.js"></script>
</head>
<body>
<x-dc>
<helmet>
<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=Noto+Sans+SC:wght@300;400;500;700;900&family=Noto+Serif+SC:wght@400;600;700;900&family=ZCOOL+XiaoWei&family=ZCOOL+QingKe+HuangYou&family=ZCOOL+KuaiLe&family=Ma+Shan+Zheng&family=Long+Cang&family=Zhi+Mang+Xing&family=Liu+Jian+Mao+Cao&display=swap" rel="stylesheet">
<script src="https://cdnjs.cloudflare.com/ajax/libs/html2canvas/1.4.1/html2canvas.min.js"></script>
<style>
*{box-sizing:border-box;}
html,body{margin:0;}
textarea,input,button,label{font-family:'Noto Sans SC',sans-serif;}
textarea:focus,input:focus{outline:none;border-color:#C26B2E;}
::-webkit-scrollbar{height:8px;width:8px;}
::-webkit-scrollbar-thumb{background:#cbbb9d;border-radius:6px;}
::-webkit-scrollbar-track{background:transparent;}
</style>
</helmet>
<div style="min-height:100vh;background:#E9E3D6;font-family:'Noto Sans SC',sans-serif;color:#2c2823;padding:42px 26px 72px;">
<div style="max-width:1200px;margin:0 auto;">
<header style="text-align:center;margin-bottom:38px;">
<div style="font-size:13px;letter-spacing:8px;color:#9b9081;font-weight:500;margin-bottom:15px;padding-left:8px;">图 文 笔 记 生 成 器</div>
<h1 style="font-size:40px;font-weight:900;letter-spacing:1px;margin:0 0 12px;line-height:1.2;">小红书 · 精致图文生成</h1>
<p style="font-size:15px;color:#8a8073;margin:0;letter-spacing:1px;">粘贴长文,自动排版成封面 + 内容长图,一键导出 {{dimText}} 高清图片</p>
</header>
<div style="display:flex;gap:32px;flex-wrap:wrap;align-items:flex-start;">
<!-- EDITOR -->
<section style="flex:1 1 360px;max-width:438px;background:#F5F1E8;border:1px solid #DBD0BC;border-radius:18px;padding:28px;box-shadow:0 12px 34px rgba(74,58,36,0.08);">
<div style="display:flex;justify-content:space-between;align-items:baseline;margin-bottom:12px;">
<label style="font-size:12px;letter-spacing:4px;color:#9b9081;font-weight:700;">正 文</label>
<span style="display:flex;gap:16px;font-size:13px;">
<span onClick="{{loadSample}}" style="color:#C26B2E;cursor:pointer;font-weight:500;">示例</span>
<span onClick="{{clearText}}" style="color:#b0a89a;cursor:pointer;">清空</span>
</span>
</div>
<textarea value="{{raw}}" onChange="{{onRaw}}" placeholder="第一行作标题。正文换行分段,「一、」「1.」识别小标题,「- 」识别要点,**关键词** 或 【关键词】 高亮强调。" style="width:100%;height:264px;resize:vertical;background:#FCFAF4;border:1px solid #D8CDB9;border-radius:12px;padding:16px 17px;font-size:15px;line-height:1.75;color:#33302a;letter-spacing:0.3px;"></textarea>
<div style="margin-top:20px;">
<label style="display:block;font-size:12px;letter-spacing:4px;color:#9b9081;font-weight:700;margin-bottom:10px;">封面配图(可选)</label>
<div style="display:flex;gap:12px;align-items:center;">
<label style="flex:1;text-align:center;padding:13px;background:#FCFAF4;border:1.5px dashed #cdb795;border-radius:11px;font-size:14px;color:#8a7355;cursor:pointer;letter-spacing:1px;">
<input type="file" accept="image/*" onChange="{{onHero}}" style="display:none;">{{heroLabel}}
</label>
<sc-if value="{{hasHero}}" hint-placeholder-val="{{false}}">
<span onClick="{{clearHero}}" style="font-size:13px;color:#b0a89a;cursor:pointer;padding:0 4px;">移除</span>
</sc-if>
</div>
<div style="margin-top:12px;font-size:11px;color:#a89f90;letter-spacing:1px;margin-bottom:9px;">科技风图库 · 点击套用</div>
<div style="display:grid;grid-template-columns:repeat(5,1fr);gap:8px;">
<sc-for list="{{covers}}" as="cov" hint-placeholder-count="10">
<div onClick="{{cov.pick}}" style="height:44px;border-radius:8px;overflow:hidden;cursor:pointer;border:2px solid {{cov.ring}};box-shadow:0 2px 6px rgba(40,30,18,0.18);">{{cov.thumbEl}}</div>
</sc-for>
</div>
</div>
<div style="margin-top:20px;">
<label style="display:block;font-size:12px;letter-spacing:3px;color:#9b9081;font-weight:700;margin-bottom:10px;">封面版式</label>
<div style="display:flex;gap:10px;flex-wrap:wrap;">
<sc-for list="{{coverLayouts}}" as="cl" hint-placeholder-count="3">
<div onClick="{{cl.pick}}" style="padding:9px 20px;border-radius:11px;border:2px solid {{cl.ring}};background:{{cl.bg}};color:{{cl.col}};font-size:15px;cursor:pointer;">{{cl.name}}</div>
</sc-for>
</div>
</div>
<div style="margin-top:20px;">
<label style="display:block;font-size:12px;letter-spacing:3px;color:#9b9081;font-weight:700;margin-bottom:8px;">署名</label>
<input value="{{signature}}" onChange="{{onSig}}" placeholder="AgentOPC" style="width:100%;background:#FCFAF4;border:1px solid #D8CDB9;border-radius:10px;padding:11px 13px;font-size:15px;color:#33302a;">
</div>
<div style="display:flex;justify-content:space-between;align-items:center;margin-top:22px;">
<label style="font-size:12px;letter-spacing:3px;color:#9b9081;font-weight:700;">图片张数</label>
<div style="display:flex;align-items:center;border:1px solid #D8CDB9;border-radius:10px;overflow:hidden;background:#FCFAF4;">
<button onClick="{{decPages}}" style="width:40px;height:40px;border:none;background:transparent;font-size:22px;color:#8a8073;cursor:pointer;line-height:1;">−</button>
<span style="width:42px;text-align:center;font-size:18px;font-weight:700;color:#33302a;">{{targetPages}}</span>
<button onClick="{{incPages}}" style="width:40px;height:40px;border:none;background:transparent;font-size:20px;color:#8a8073;cursor:pointer;line-height:1;">+</button>
</div>
</div>
<div style="margin-top:20px;">
<label style="display:block;font-size:12px;letter-spacing:3px;color:#9b9081;font-weight:700;margin-bottom:10px;">图片比例</label>
<div style="display:flex;gap:10px;flex-wrap:wrap;">
<sc-for list="{{ratios}}" as="rt" hint-placeholder-count="2">
<div onClick="{{rt.pick}}" style="padding:9px 20px;border-radius:11px;border:2px solid {{rt.ring}};background:{{rt.bg}};color:{{rt.col}};font-size:15px;cursor:pointer;">{{rt.name}}</div>
</sc-for>
</div>
</div>
<div style="margin-top:22px;">
<div style="display:flex;justify-content:space-between;align-items:center;">
<label style="font-size:12px;letter-spacing:3px;color:#9b9081;font-weight:700;">结尾寄语页</label>
<div onClick="{{toggleClosing}}" style="width:62px;height:32px;border-radius:16px;background:{{closingBg}};position:relative;cursor:pointer;">
<div style="position:absolute;top:3px;left:{{closingKnob}};width:26px;height:26px;border-radius:50%;background:#fff;box-shadow:0 2px 5px rgba(0,0,0,0.22);"></div>
</div>
</div>
<sc-if value="{{closingOn}}" hint-placeholder-val="{{true}}">
<input value="{{dedication}}" onChange="{{onDedication}}" placeholder="自定义寄语 · 留空则取正文最后一句" style="width:100%;margin-top:12px;background:#FCFAF4;border:1px solid #D8CDB9;border-radius:10px;padding:11px 13px;font-size:14px;color:#33302a;">
</sc-if>
</div>
<div style="margin-top:24px;">
<label style="display:block;font-size:12px;letter-spacing:3px;color:#9b9081;font-weight:700;margin-bottom:14px;">主题配色</label>
<div style="display:flex;gap:13px;flex-wrap:wrap;">
<sc-for list="{{themes}}" as="sw" hint-placeholder-count="5">
<div onClick="{{sw.pick}}" style="cursor:pointer;display:flex;flex-direction:column;align-items:center;gap:7px;">
<div style="width:46px;height:46px;border-radius:13px;background:linear-gradient(150deg,{{sw.bg}},{{sw.bg2}});border:2px solid {{sw.ringColor}};display:flex;align-items:center;justify-content:center;box-shadow:0 3px 8px rgba(74,58,36,0.12);">
<div style="width:20px;height:20px;border-radius:7px;background:{{sw.title}};"></div>
</div>
<span style="font-size:11px;color:{{sw.labelColor}};letter-spacing:0.5px;">{{sw.name}}</span>
</div>
</sc-for>
<label style="cursor:pointer;display:flex;flex-direction:column;align-items:center;gap:7px;">
<div style="width:46px;height:46px;border-radius:13px;background:conic-gradient(from 90deg,#fdf6ec,#e7d9c2,#cfe0d8,#d3def0,#efd9e2,#e4dcef,#fdf6ec);border:2px solid {{customBgRing}};position:relative;overflow:hidden;box-shadow:0 3px 8px rgba(74,58,36,0.12);">
<input type="color" onChange="{{onCustomBg}}" style="position:absolute;inset:-6px;opacity:0;cursor:pointer;">
</div>
<span style="font-size:11px;color:{{customBgLabel}};letter-spacing:0.5px;">自定</span>
</label>
</div>
</div>
<div style="margin-top:24px;">
<label style="display:block;font-size:12px;letter-spacing:3px;color:#9b9081;font-weight:700;margin-bottom:14px;">主色</label>
<div style="display:flex;gap:10px;flex-wrap:wrap;align-items:center;">
<div onClick="{{resetColor}}" style="height:30px;padding:0 13px;border-radius:15px;border:2px solid {{resetRing}};display:flex;align-items:center;font-size:12px;color:#8a8073;cursor:pointer;">跟随主题</div>
<sc-for list="{{palette}}" as="pc" hint-placeholder-count="16">
<div onClick="{{pc.pick}}" style="width:30px;height:30px;border-radius:50%;background:{{pc.c}};border:2px solid {{pc.ring}};cursor:pointer;box-shadow:0 2px 5px rgba(40,30,18,0.18);"></div>
</sc-for>
<label style="width:30px;height:30px;border-radius:50%;background:conic-gradient(from 90deg,#e2483d,#e8a13c,#4caf6e,#3e8fd0,#7b5bd0,#d05a8c,#e2483d);cursor:pointer;border:2px solid #fff;box-shadow:0 0 0 1px #d8cdb9,0 2px 5px rgba(40,30,18,0.18);position:relative;overflow:hidden;">
<input type="color" onChange="{{onCustomColor}}" style="position:absolute;inset:-6px;opacity:0;cursor:pointer;">
</label>
</div>
</div>
<div style="margin-top:24px;">
<label style="display:block;font-size:12px;letter-spacing:3px;color:#9b9081;font-weight:700;margin-bottom:14px;">底纹</label>
<div style="display:flex;gap:10px;flex-wrap:wrap;">
<sc-for list="{{patterns}}" as="pt" hint-placeholder-count="11">
<div onClick="{{pt.pick}}" style="padding:9px 17px;border-radius:11px;border:2px solid {{pt.ring}};background:{{pt.bg}};color:{{pt.col}};font-size:15px;cursor:pointer;">{{pt.name}}</div>
</sc-for>
</div>
</div>
<div style="margin-top:24px;">
<label style="display:block;font-size:12px;letter-spacing:3px;color:#9b9081;font-weight:700;margin-bottom:14px;">标题字体</label>
<div style="display:flex;gap:10px;flex-wrap:wrap;">
<sc-for list="{{titleFonts}}" as="ft" hint-placeholder-count="10">
<div onClick="{{ft.pick}}" style="padding:9px 16px;border-radius:11px;border:2px solid {{ft.ring}};background:{{ft.bg}};color:{{ft.col}};font-size:18px;cursor:pointer;font-family:{{ft.family}};">{{ft.name}}</div>
</sc-for>
</div>
</div>
<div style="margin-top:24px;">
<label style="display:block;font-size:12px;letter-spacing:3px;color:#9b9081;font-weight:700;margin-bottom:14px;">正文字体</label>
<div style="display:flex;gap:10px;flex-wrap:wrap;">
<sc-for list="{{bodyFonts}}" as="ft" hint-placeholder-count="10">
<div onClick="{{ft.pick}}" style="padding:9px 16px;border-radius:11px;border:2px solid {{ft.ring}};background:{{ft.bg}};color:{{ft.col}};font-size:18px;cursor:pointer;font-family:{{ft.family}};">{{ft.name}}</div>
</sc-for>
</div>
</div>
<button onClick="{{generate}}" style="width:100%;margin-top:28px;padding:16px;background:#C26B2E;color:#fff;border:none;border-radius:13px;font-size:16px;font-weight:700;letter-spacing:5px;cursor:pointer;box-shadow:0 8px 18px rgba(194,107,46,0.32);">重 新 排 版</button>
</section>
<!-- PREVIEW -->
<section style="flex:2 1 580px;min-width:300px;">
<div style="display:flex;justify-content:space-between;align-items:center;margin-bottom:22px;padding:0 2px;">
<div style="display:flex;align-items:baseline;gap:12px;">
<span style="font-size:20px;font-weight:900;letter-spacing:1px;">成图预览</span>
<span style="font-size:14px;color:#9b9081;">共 {{pageCount}} 张 · {{dimLabel}}</span>
</div>
<button onClick="{{exportAll}}" style="padding:11px 24px;background:#fff;color:#7a5a36;border:1.5px solid #c4a981;border-radius:11px;font-size:14px;font-weight:700;letter-spacing:3px;cursor:pointer;">保 存 全 部</button>
</div>
<div style="display:flex;flex-wrap:wrap;gap:30px;">
<sc-for list="{{pages}}" as="page" hint-placeholder-count="5">
<div style="display:flex;flex-direction:column;align-items:center;gap:13px;">
<div style="width:300px;height:{{page.previewH}}px;overflow:hidden;border-radius:{{cardRadius}};box-shadow:0 16px 38px rgba(60,46,28,0.2);position:relative;background:{{page.t.bg}};">
<!-- COVER -->
<sc-if value="{{page.isCover}}" hint-placeholder-val="{{true}}">
<sc-if value="{{page.isCard}}" hint-placeholder-val="{{true}}">
<div ref="{{page.cardRef}}" style="position:relative;width:1080px;height:{{page.cardH}}px;transform:scale(0.277778);transform-origin:top left;background:linear-gradient(165deg,{{page.t.bg}},{{page.t.bg2}});color:{{page.t.ink}};font-family:{{page.fontBody}};display:flex;flex-direction:column;overflow:hidden;"><div style="position:absolute;inset:0;background-image:{{page.gridBg}};background-size:{{page.gridSize}};opacity:{{page.gridOpacity}};pointer-events:none;"></div>
<div style="display:flex;align-items:center;gap:16px;background:{{page.t.band}};padding:38px 92px;font-size:30px;color:{{page.t.title}};font-weight:500;letter-spacing:1px;">
<svg width="36" height="36" viewBox="0 0 36 36" fill="none"><circle cx="18" cy="18" r="14" stroke="{{page.t.title}}" stroke-width="2.4"/><path d="M18 10 V18 L24 22" stroke="{{page.t.title}}" stroke-width="2.4" stroke-linecap="round"/></svg>
<span>全文 {{page.wordCount}} 字 · 阅读约 {{page.readMin}} 分钟</span>
</div>
<div style="flex:1;display:flex;flex-direction:column;padding:64px 92px 78px;">
<div style="width:100%;height:{{page.heroCardH}}px;border-radius:26px;overflow:hidden;position:relative;background:{{page.t.soft}};flex:none;">
<sc-if value="{{page.hasHero}}" hint-placeholder-val="{{false}}">{{page.heroEl}}</sc-if>
<sc-if value="{{page.noHero}}" hint-placeholder-val="{{true}}">
<div style="width:100%;height:100%;display:flex;flex-direction:column;align-items:center;justify-content:center;gap:26px;border:2px dashed {{page.t.line}};border-radius:26px;">
<svg width="120" height="92" viewBox="0 0 120 92" fill="none"><rect x="6" y="6" width="108" height="80" rx="10" stroke="{{page.t.sub}}" stroke-width="2.4"/><circle cx="38" cy="34" r="11" stroke="{{page.t.sub}}" stroke-width="2.4"/><path d="M14 78 L46 48 L70 68 L88 52 L106 70" stroke="{{page.t.sub}}" stroke-width="2.4" stroke-linecap="round" stroke-linejoin="round"/></svg>
<span style="font-size:30px;color:{{page.t.sub}};letter-spacing:3px;">封面配图</span>
</div>
</sc-if>
</div>
<div style="position:relative;margin-top:22px;height:18px;border-top:2px solid {{page.t.line}};background-image:linear-gradient(90deg,{{page.t.line}} 2px,transparent 2px);background-size:32px 18px;opacity:0.6;"></div>
<div style="position:relative;margin-top:46px;font-size:118px;line-height:1.18;font-weight:{{page.titleWeight}};letter-spacing:1px;color:{{page.t.title}};font-family:{{page.fontTitle}};text-wrap:balance;">
<sc-for list="{{page.titleRuns}}" as="r" hint-placeholder-count="2"><span style="color:{{r.color}};">{{r.t}}</span></sc-for>
</div>
<div style="margin-top:40px;display:flex;gap:26px;align-items:stretch;">
<div style="width:9px;border-radius:5px;background:{{page.t.accent}};flex:none;"></div>
<div style="font-size:42px;line-height:1.6;color:{{page.t.sub}};font-weight:500;">{{page.teaser}}</div>
</div>
<div style="flex:1;"></div>
<div style="display:flex;justify-content:flex-end;align-items:center;padding-top:34px;border-top:2px solid {{page.t.line}};font-size:30px;color:{{page.t.sub}};letter-spacing:1px;">
<sc-if value="{{page.hasSig}}" hint-placeholder-val="{{true}}"><span style="display:flex;align-items:center;gap:14px;"><span style="width:36px;height:3px;border-radius:2px;background:{{page.t.accent}};"></span>@{{page.signature}}</span></sc-if>
</div>
</div>
</div>
</sc-if>
<sc-if value="{{page.isFull}}" hint-placeholder-val="{{false}}">
<div ref="{{page.cardRef}}" style="position:relative;width:1080px;height:{{page.cardH}}px;transform:scale(0.277778);transform-origin:top left;background:{{page.t.bg}};color:#fff;font-family:{{page.fontBody}};overflow:hidden;">
<sc-if value="{{page.hasHero}}" hint-placeholder-val="{{false}}"><div style="position:absolute;inset:0;">{{page.heroEl}}</div></sc-if>
<sc-if value="{{page.noHero}}" hint-placeholder-val="{{true}}"><div style="position:absolute;inset:0;background:linear-gradient(160deg,#3b3b46,#16161c);"></div></sc-if>
<div style="position:absolute;inset:0;background:linear-gradient(to bottom,rgba(8,6,4,0.40) 0%,rgba(8,6,4,0.05) 26%,rgba(8,6,4,0.32) 60%,rgba(8,6,4,0.84) 100%);"></div>
<div style="position:relative;height:100%;display:flex;flex-direction:column;padding:92px;box-sizing:border-box;">
<div style="display:flex;align-items:center;gap:16px;font-size:30px;color:rgba(255,255,255,0.92);font-weight:500;letter-spacing:1px;">
<svg width="36" height="36" viewBox="0 0 36 36" fill="none"><circle cx="18" cy="18" r="14" stroke="#ffffff" stroke-width="2.4"/><path d="M18 10 V18 L24 22" stroke="#ffffff" stroke-width="2.4" stroke-linecap="round"/></svg>
<span>全文 {{page.wordCount}} 字 · 阅读约 {{page.readMin}} 分钟</span>
</div>
<div style="flex:1;"></div>
<div style="font-size:124px;line-height:1.16;font-weight:{{page.titleWeight}};letter-spacing:1px;color:#fff;font-family:{{page.fontTitle}};text-shadow:0 2px 34px rgba(0,0,0,0.45);text-wrap:balance;">
<sc-for list="{{page.titleRuns}}" as="r" hint-placeholder-count="2"><span style="color:{{r.fullColor}};">{{r.t}}</span></sc-for>
</div>
<div style="margin-top:40px;display:flex;gap:26px;align-items:stretch;">
<div style="width:9px;border-radius:5px;background:{{page.t.accent}};flex:none;"></div>
<div style="font-size:42px;line-height:1.6;color:rgba(255,255,255,0.9);font-weight:500;">{{page.teaser}}</div>
</div>
<div style="margin-top:54px;display:flex;justify-content:flex-end;align-items:center;padding-top:34px;border-top:2px solid rgba(255,255,255,0.32);font-size:30px;color:rgba(255,255,255,0.9);letter-spacing:1px;">
<sc-if value="{{page.hasSig}}" hint-placeholder-val="{{true}}"><span style="display:flex;align-items:center;gap:14px;"><span style="width:36px;height:3px;border-radius:2px;background:{{page.t.accent}};"></span>@{{page.signature}}</span></sc-if>
</div>
</div>
</div>
</sc-if>
<sc-if value="{{page.isBlend}}" hint-placeholder-val="{{false}}">
<div ref="{{page.cardRef}}" style="position:relative;width:1080px;height:{{page.cardH}}px;transform:scale(0.277778);transform-origin:top left;background:linear-gradient(165deg,{{page.t.bg}},{{page.t.bg2}});color:{{page.t.ink}};font-family:{{page.fontBody}};display:flex;flex-direction:column;overflow:hidden;">
<div style="position:absolute;inset:0;background-image:{{page.gridBg}};background-size:{{page.gridSize}};opacity:{{page.gridOpacity}};pointer-events:none;"></div>
<div style="position:relative;height:{{page.heroBlendH}}px;flex:none;overflow:hidden;">
<sc-if value="{{page.hasHero}}" hint-placeholder-val="{{false}}">{{page.heroEl}}</sc-if>
<sc-if value="{{page.noHero}}" hint-placeholder-val="{{true}}"><div style="width:100%;height:100%;background:{{page.t.soft}};display:flex;align-items:center;justify-content:center;color:{{page.t.sub}};font-size:30px;letter-spacing:3px;">封面配图</div></sc-if>
<div style="position:absolute;left:0;right:0;bottom:0;height:340px;background:linear-gradient(to bottom,rgba(0,0,0,0) 0%,{{page.t.bg2}} 100%);"></div>
<div style="position:absolute;left:0;right:0;top:0;height:150px;background:linear-gradient(to bottom,{{page.t.bg}} 0%,rgba(0,0,0,0) 100%);"></div>
</div>
<div style="position:relative;flex:1;display:flex;flex-direction:column;padding:0 92px 78px;margin-top:-30px;">
<div style="font-size:118px;line-height:1.18;font-weight:{{page.titleWeight}};letter-spacing:1px;color:{{page.t.title}};font-family:{{page.fontTitle}};text-wrap:balance;">
<sc-for list="{{page.titleRuns}}" as="r" hint-placeholder-count="2"><span style="color:{{r.color}};">{{r.t}}</span></sc-for>
</div>
<div style="margin-top:36px;display:flex;gap:26px;align-items:stretch;">
<div style="width:9px;border-radius:5px;background:{{page.t.accent}};flex:none;"></div>
<div style="font-size:42px;line-height:1.6;color:{{page.t.sub}};font-weight:500;">{{page.teaser}}</div>
</div>
<div style="flex:1;"></div>
<div style="display:flex;justify-content:space-between;align-items:center;padding-top:30px;border-top:2px solid {{page.t.line}};font-size:28px;color:{{page.t.sub}};letter-spacing:1px;">
<span>全文 {{page.wordCount}} 字 · 约 {{page.readMin}} 分钟</span>
<sc-if value="{{page.hasSig}}" hint-placeholder-val="{{true}}"><span>@{{page.signature}}</span></sc-if>
</div>
</div>
</div>
</sc-if>
</sc-if>
<!-- CONTENT -->
<sc-if value="{{page.isContent}}" hint-placeholder-val="{{false}}">
<div ref="{{page.cardRef}}" style="position:relative;width:1080px;height:{{page.cardH}}px;transform:scale(0.277778);transform-origin:top left;background:linear-gradient(165deg,{{page.t.bg}},{{page.t.bg2}});color:{{page.t.ink}};font-family:{{page.fontBody}};display:flex;flex-direction:column;padding:88px 88px 80px;overflow:hidden;"><div style="position:absolute;inset:0;background-image:{{page.gridBg}};background-size:{{page.gridSize}};opacity:{{page.gridOpacity}};pointer-events:none;"></div>
<div style="position:absolute;top:30px;right:60px;font-size:340px;font-weight:900;line-height:1;color:{{page.t.title}};opacity:0.06;font-family:'Noto Serif SC',serif;">{{page.num}}</div>
<div style="position:relative;display:flex;justify-content:space-between;align-items:center;gap:20px;font-size:28px;color:{{page.t.sub}};letter-spacing:3px;">
<span style="display:flex;align-items:center;gap:15px;min-width:0;flex:1;"><span style="width:34px;height:3px;border-radius:2px;background:{{page.t.accent}};display:inline-block;flex:none;"></span><span style="overflow:hidden;text-overflow:ellipsis;white-space:nowrap;">{{page.brand}}</span></span>
<span style="flex:none;">{{page.num}}</span>
</div>
<div style="position:relative;flex:1;min-height:0;overflow:hidden;padding-top:64px;">
<sc-for list="{{page.blocks}}" as="b" hint-placeholder-count="3">
<div style="margin-top:{{b.mt}}px;margin-bottom:{{b.mb}}px;">
<sc-if value="{{b.isHeading}}" hint-placeholder-val="{{false}}">
<div style="display:flex;align-items:center;gap:24px;">
<sc-if value="{{b.hasBadge}}" hint-placeholder-val="{{false}}">
<span style="flex:none;width:74px;height:74px;border-radius:20px;background:{{page.t.accent}};color:#fff;font-size:42px;font-weight:900;display:flex;align-items:center;justify-content:center;box-shadow:0 8px 16px {{page.t.shadow}};">{{b.badge}}</span>
</sc-if>
<sc-if value="{{b.barOnly}}" hint-placeholder-val="{{true}}">
<span style="flex:none;width:10px;height:54px;border-radius:5px;background:{{page.t.accent}};"></span>
</sc-if>
<span style="font-size:60px;font-weight:{{page.titleWeight}};line-height:1.28;letter-spacing:0.5px;color:{{page.t.title}};font-family:{{page.fontTitle}};">{{b.rest}}</span>
</div>
</sc-if>
<sc-if value="{{b.isPara}}" hint-placeholder-val="{{true}}">
<div style="font-size:41px;line-height:1.86;color:{{page.t.ink}};letter-spacing:0.4px;text-wrap:pretty;">
<sc-for list="{{b.runs}}" as="r" hint-placeholder-count="1"><span style="color:{{r.color}};font-weight:{{r.weight}};">{{r.t}}</span></sc-for>
</div>
</sc-if>
<sc-if value="{{b.isImage}}" hint-placeholder-val="{{false}}">
<div style="width:100%;height:{{b.boxH}}px;border-radius:22px;overflow:hidden;background:#ffffff;background-image:{{b.imgUrl}};background-size:contain;background-position:center;background-repeat:no-repeat;box-shadow:0 8px 26px rgba(0,0,0,0.14);"></div>
<sc-if value="{{b.hasCaption}}" hint-placeholder-val="{{false}}"><div style="margin-top:16px;text-align:center;font-size:26px;color:{{page.t.sub}};letter-spacing:0.5px;">{{b.caption}}</div></sc-if>
</sc-if>
<sc-if value="{{b.isBullets}}" hint-placeholder-val="{{false}}">
<div style="background:{{page.t.soft}};border-radius:24px;padding:42px 44px;display:flex;flex-direction:column;gap:30px;border:1px solid {{page.t.line}};">
<sc-for list="{{b.items}}" as="it" hint-placeholder-count="3">
<div style="display:flex;gap:22px;align-items:flex-start;">
<sc-if value="{{it.hasNum}}" hint-placeholder-val="{{false}}"><span style="flex:none;min-width:46px;height:46px;padding:0 6px;border-radius:14px;background:{{page.t.accent}};color:#fff;font-size:26px;font-weight:900;display:flex;align-items:center;justify-content:center;margin-top:4px;">{{it.num}}</span></sc-if>
<sc-if value="{{it.noNum}}" hint-placeholder-val="{{true}}"><span style="flex:none;width:18px;height:18px;border-radius:50%;margin-top:18px;background:{{page.t.accent}};"></span></sc-if>
<div style="font-size:39px;line-height:1.6;color:{{page.t.ink}};padding-top:2px;">
<sc-for list="{{it.runs}}" as="r" hint-placeholder-count="1"><span style="color:{{r.color}};font-weight:{{r.weight}};">{{r.t}}</span></sc-for>
</div>
</div>
</sc-for>
</div>
</sc-if>
<sc-if value="{{b.isClosing}}" hint-placeholder-val="{{false}}">
<div style="display:flex;flex-direction:column;align-items:center;text-align:center;gap:36px;padding:40px 0;">
<svg width="76" height="60" viewBox="0 0 76 60" fill="none"><path d="M30 8 C 14 14, 8 30, 10 52 L 30 52 L 30 30 L 18 30 C 18 20, 24 14, 32 12 Z M66 8 C 50 14, 44 30, 46 52 L 66 52 L 66 30 L 54 30 C 54 20, 60 14, 68 12 Z" fill="{{page.t.accent}}" opacity="0.85"/></svg>
<div style="font-size:56px;line-height:1.62;font-weight:700;color:{{page.t.title}};font-family:{{page.fontTitle}};max-width:840px;">
<sc-for list="{{b.runs}}" as="r" hint-placeholder-count="1"><span style="color:{{r.color}};">{{r.t}}</span></sc-for>
</div>
</div>
</sc-if>
</div>
</sc-for>
</div>
<div style="position:relative;padding-top:30px;">
<div style="height:6px;border-radius:3px;background:{{page.t.line}};overflow:hidden;margin-bottom:24px;">
<div style="height:100%;width:{{page.progress}};background:{{page.t.accent}};border-radius:3px;"></div>
</div>
<div style="display:flex;justify-content:space-between;align-items:center;font-size:27px;color:{{page.t.sub}};letter-spacing:1px;">
<sc-if value="{{page.hasSig}}" hint-placeholder-val="{{true}}"><span>@{{page.signature}}</span></sc-if>
<sc-if value="{{page.noSig}}" hint-placeholder-val="{{false}}"><span></span></sc-if>
<span>{{page.num}} / {{page.totalStr}}</span>
</div>
</div>
</div>
</sc-if>
</div>
<button onClick="{{page.exportSelf}}" style="padding:9px 22px;background:#fff;color:#8a7355;border:1px solid #cdb795;border-radius:9px;font-size:13px;letter-spacing:2px;cursor:pointer;white-space:nowrap;">保存第 {{page.num}} 张</button>
</div>
</sc-for>
</div>
</section>
</div>
</div>
</div>
</x-dc>
<script type="text/x-dc" data-dc-script data-props="{"$preview":{"width":1200,"height":980},"cardCorners":{"editor":"enum","options":["直角","微圆角"],"default":"直角","tsType":"string"},"defaultTheme":{"editor":"enum","options":["鸿蒙橙","奶油棕","松墨绿","黛蓝","莓粉"],"default":"墨白","tsType":"string"}}">
class Component extends DCLogic {
SAMPLE = `把生活过成喜欢的样子
这两年我慢慢明白,所谓**松弛感**,不是什么都不做,而是把注意力收回到自己身上。下面是我坚持了很久、真正有用的几件小事。
一、早晨留给自己
不要一睁眼就看手机。先喝一杯温水,拉开窗帘,让光线照进来。哪怕只有十分钟,安静地坐一会儿,一整天的节奏都会不一样。
二、给情绪留出口
把情绪憋着只会越积越重,要学会温柔地把它放出来。
- 把烦心事写下来,写完往往就轻了一半
- 散步是最便宜的疗愈,走着走着答案就来了
- 允许自己难过,但不允许自己一直停在原地
三、减少不必要的拥有
房间空一点,心也会跟着空一点。每个季度清理一次,只留下真正喜欢、真正会用的东西。你拥有的越少,被打扰的就越少。
愿你也能在平淡的日子里,慢慢把生活过成自己喜欢的样子。`;
_refs = {};
state = {
raw: this.SAMPLE,
signature: 'AgentOPC',
themeIndex: 0,
targetPages: 5,
heroImg: null,
closingOn: true,
dedication: '',
fontIndex: 0,
titleFontIndex: 0,
bodyFontIndex: 0,
customColor: null,
customBg: null,
ratioIndex: 0,
patternIndex: 1,
coverLayout: 0,
pages: [],
};
getThemes() {
// compact spec [name, bg, bg2, ink, sub, accent]; title/soft/line/band/shadow derived
const spec = [
['鸿蒙橙', '#FBF5EC', '#F3E6D4', '#2B2620', '#94816a', '#C26B2E'],
['奶油棕', '#F6F1E7', '#ECE0CE', '#33302A', '#8B8273', '#B5764A'],
['松墨绿', '#EFF2EA', '#E0E7D9', '#28302A', '#7c857a', '#3E7A5E'],
['黛蓝', '#EEF1F5', '#DFE7F0', '#262C33', '#79828d', '#3E6FA0'],
['莓粉', '#FBF1EF', '#F4E0DC', '#332A2C', '#917b7e', '#C25E70'],
['米白', '#FAF7F0', '#EFEADD', '#2D2A24', '#8c8576', '#A8763E'],
['浅杏', '#FCF3E8', '#F6E6CF', '#322B22', '#988465', '#D98E3D'],
['雾霾蓝', '#EDF0F2', '#DDE4E8', '#272D31', '#7b8389', '#3E6F84'],
['薄荷绿', '#EAF3EE', '#D7E8DD', '#27302B', '#7a857e', '#2F8F6B'],
['青瓷', '#ECF2F1', '#D9E6E3', '#26302E', '#788581', '#2F8F86'],
['藕荷', '#F6EFF4', '#E9DAE6', '#2F2A2E', '#8a7d87', '#9E5A8C'],
['浅紫', '#F1EFF6', '#E2DCEE', '#2A2730', '#807a8d', '#6E5AA8'],
['豆沙', '#F7EFEC', '#EDDCD4', '#322A26', '#90817a', '#B0573A'],
['暖灰', '#F2F1EE', '#E3E1DA', '#2C2A26', '#86837b', '#7A6A55'],
['墨黑', '#23211E', '#2D2A26', '#EDE7DB', '#a39a8a', '#D98E3D'],
['靛夜', '#1E2430', '#28303E', '#E3E8F0', '#94a0b3', '#5B8FD0'],
];
return spec.map(([name, bg, bg2, ink, sub, accent]) => ({
name, bg, bg2, ink, sub, accent,
title: this.mix(accent, '#000000', 0.12),
soft: this.mix(accent, bg, 0.86),
line: this.mix(accent, bg, 0.66),
band: this.mix(accent, bg, 0.84),
shadow: 'rgba(' + this.hex2rgb(accent).join(',') + ',0.3)',
}));
}
getRatios() {
return [
{ name: '标准 3:4', w: 1080, h: 1440 },
{ name: '长文 3:5', w: 1080, h: 1800 },
];
}
// 内联图片的高宽比(h/w)。首次遇到先用默认值,加载完真实尺寸后重新分页。
getImgRatio(src) {
if (!this._imgDims) { this._imgDims = {}; this._imgLoading = {}; }
if (this._imgDims[src]) return this._imgDims[src];
if (!this._imgLoading[src]) {
this._imgLoading[src] = true;
const img = new Image();
img.onload = () => { this._imgDims[src] = img.naturalHeight / img.naturalWidth; this.regen(); };
img.onerror = () => { this._imgDims[src] = 0.95; this.regen(); };
img.src = src;
}
return 0.95;
}
pad(n) { return n < 10 ? '0' + n : '' + n; }
cnToNum(s) {
if (/^[0-9]+$/.test(s)) return s;
const map = { 一: 1, 二: 2, 三: 3, 四: 4, 五: 5, 六: 6, 七: 7, 八: 8, 九: 9, 十: 10 };
if (s.length === 1 && map[s]) return '' + map[s];
if (s === '十一') return '11';
if (s === '十二') return '12';
if (/^十[一二三四五六七八九]$/.test(s)) return '' + (10 + map[s[1]]);
return map[s[0]] ? '' + map[s[0]] : s;
}
getPalette() { return ['#C26B2E', '#D98E3D', '#B5764A', '#9E5A26', '#C2683F', '#B0433A', '#9E3F54', '#C25E70', '#6E5AA8', '#3E6FA0', '#2C4A6B', '#2F8F6B', '#3E7A5E', '#5A6B52', '#7A6A55', '#2A2620']; }
hex2rgb(h) { h = h.replace('#', ''); if (h.length === 3) h = h.split('').map(x => x + x).join(''); return [parseInt(h.slice(0, 2), 16), parseInt(h.slice(2, 4), 16), parseInt(h.slice(4, 6), 16)]; }
rgb2hex(a) { return '#' + a.map(v => Math.max(0, Math.min(255, Math.round(v))).toString(16).padStart(2, '0')).join(''); }
mix(a, b, t) { const A = this.hex2rgb(a), B = this.hex2rgb(b); return this.rgb2hex([A[0] + (B[0] - A[0]) * t, A[1] + (B[1] - A[1]) * t, A[2] + (B[2] - A[2]) * t]); }
luminance(h) { const a = this.hex2rgb(h); return (0.299 * a[0] + 0.587 * a[1] + 0.114 * a[2]) / 255; }
curTheme() {
let base = this.getThemes()[this.state.themeIndex] || this.getThemes()[0];
const bgC = this.state.customBg;
if (bgC) {
const dark = this.luminance(bgC) < 0.45;
const tone = dark ? '#ffffff' : '#000000';
base = Object.assign({}, base, {
bg: bgC,
bg2: this.mix(bgC, tone, 0.08),
ink: this.mix(bgC, dark ? '#ffffff' : '#000000', dark ? 0.88 : 0.86),
sub: this.mix(bgC, dark ? '#ffffff' : '#000000', dark ? 0.55 : 0.48),
soft: this.mix(bgC, tone, 0.06),
line: this.mix(bgC, tone, 0.16),
band: this.mix(bgC, tone, 0.05),
});
}
const c = this.state.customColor;
if (!c) return base;
const rgb = this.hex2rgb(c);
return Object.assign({}, base, {
title: this.mix(c, '#000000', 0.10),
accent: c,
soft: this.mix(c, base.bg, 0.86),
line: this.mix(c, base.bg, 0.62),
band: this.mix(c, base.bg, 0.84),
shadow: 'rgba(' + rgb[0] + ',' + rgb[1] + ',' + rgb[2] + ',0.3)',
});
}
getFonts() {
return [
{ name: '黑体', family: "'Noto Sans SC',sans-serif" },
{ name: '细黑', family: "'Noto Sans SC',sans-serif", tw: 300 },
{ name: '宋体', family: "'Noto Serif SC',serif" },
{ name: '雅宋', family: "'ZCOOL XiaoWei',serif" },
{ name: '海报', family: "'ZCOOL QingKe HuangYou',sans-serif" },
{ name: '圆体', family: "'ZCOOL KuaiLe',sans-serif" },
{ name: '手写', family: "'Ma Shan Zheng',cursive" },
{ name: '龙藏', family: "'Long Cang',cursive" },
{ name: '志莽', family: "'Zhi Mang Xing',cursive" },
{ name: '毛笔', family: "'Liu Jian Mao Cao',cursive" },
];
}
curFont() {
const fs = this.getFonts();
const t = fs[this.state.titleFontIndex] || fs[0];
const b = fs[this.state.bodyFontIndex] || fs[0];
return { title: t.family, body: b.family, titleWeight: t.tw || 900 };
}
sciPattern(inner, tile, line) {
const body = inner.replace(/@/g, line);
const svg = '<svg xmlns="http://www.w3.org/2000/svg" width="' + tile + '" height="' + tile + '" viewBox="0 0 ' + tile + ' ' + tile + '">' + body + '</svg>';
return 'url("data:image/svg+xml,' + encodeURIComponent(svg) + '")';
}
patternStyle(idx, line) {
switch (idx) {
case 0: return { img: 'none', size: 'auto', op: 0 };
case 1: return { img: 'linear-gradient(' + line + ' 1px,transparent 1px),linear-gradient(90deg,' + line + ' 1px,transparent 1px)', size: '64px 64px', op: 0.32 };
case 2: return { img: 'radial-gradient(' + line + ' 1.6px,transparent 1.7px)', size: '34px 34px', op: 0.42 };
case 3: return { img: 'repeating-linear-gradient(45deg,' + line + ' 0,' + line + ' 1.4px,transparent 1.4px,transparent 18px)', size: 'auto', op: 0.34 };
case 4: return { img: 'linear-gradient(90deg,' + line + ' 1px,transparent 1px)', size: '44px 44px', op: 0.3 };
case 5: return { img: 'linear-gradient(' + line + ' 1px,transparent 1px)', size: '44px 44px', op: 0.3 };
case 6: return { img: 'url(covers/pattern-math.png)', size: 'cover', op: 0.16 };
// 数学(矢量):积分/求和/几何/方程
case 7: return { img: this.sciPattern('<g fill="none" stroke="@" stroke-width="2.2"><circle cx="62" cy="64" r="30"/><path d="M40 150 l44 0 l-44 56 l44 0"/><path d="M150 36 q40 30 0 60"/></g><g fill="@" font-family="Georgia,serif" font-size="30"><text x="150" y="64">∫</text><text x="186" y="120">∑</text><text x="34" y="120">π</text><text x="150" y="170">E=mc²</text><text x="34" y="246">a²+b²=c²</text><text x="190" y="220">√</text></g>', 270, line), size: '270px 270px', op: 0.5 };
// 物理:原子轨道/波/矢量/公式
case 8: return { img: this.sciPattern('<g fill="none" stroke="@" stroke-width="2.2"><ellipse cx="64" cy="62" rx="44" ry="16"/><ellipse cx="64" cy="62" rx="44" ry="16" transform="rotate(60 64 62)"/><ellipse cx="64" cy="62" rx="44" ry="16" transform="rotate(120 64 62)"/><circle cx="64" cy="62" r="5" fill="@"/><path d="M150 50 q14 -22 28 0 t28 0 t28 0"/><path d="M30 210 l46 0 m-12 -8 l12 8 l-12 8"/></g><g fill="@" font-family="Georgia,serif" font-size="27"><text x="150" y="140">F=ma</text><text x="34" y="150">E=hν</text><text x="160" y="220">λ=v/f</text></g>', 270, line), size: '270px 270px', op: 0.5 };
// 化学:苯环/分子键/烧瓶/分子式
case 9: return { img: this.sciPattern('<g fill="none" stroke="@" stroke-width="2.2"><path d="M62 28 l28 16 l0 32 l-28 16 l-28 -16 l0 -32 z"/><circle cx="62" cy="60" r="17"/><path d="M180 40 l16 9 l16 -9 m-16 9 l0 20"/><path d="M44 156 l0 30 l-16 30 l50 0 l-16 -30 l0 -30 z"/></g><g fill="@" font-family="Georgia,serif" font-size="25"><text x="150" y="160">H₂O</text><text x="160" y="216">CO₂</text><text x="28" y="120">OH⁻</text></g>', 270, line), size: '270px 270px', op: 0.5 };
// 计算机:二进制/代码/芯片
case 10: return { img: this.sciPattern('<g fill="none" stroke="@" stroke-width="2.2"><rect x="158" y="40" width="60" height="60" rx="7"/><path d="M158 56 l-12 0 M158 76 l-12 0 M158 96 l-12 0 M218 56 l12 0 M218 76 l12 0 M218 96 l12 0"/></g><g fill="@" font-family="monospace" font-size="25"><text x="20" y="52">01001011</text><text x="28" y="120"></></text><text x="120" y="158">{ }</text><text x="30" y="206">fn()</text><text x="158" y="216">>_</text><text x="20" y="246">1010 0110</text></g>', 270, line), size: '270px 270px', op: 0.5 };
default: return { img: 'none', size: 'auto', op: 0 };
}
}
themeFromProp() {
const idx = this.getThemes().map(t => t.name).indexOf(this.props.defaultTheme);
return idx < 0 ? 0 : idx;
}
componentDidMount() {
// headless bridge: when window.RT_CONFIG is injected (e.g. by the export pipeline),
// apply it as initial state and expose programmatic export hooks. Zero effect in normal use.
const cfg = (typeof window !== 'undefined' && window.RT_CONFIG) ? window.RT_CONFIG : null;
const init = { themeIndex: this.themeFromProp() };
if (cfg) Object.assign(init, cfg);
this.setState(init, () => {
this.setState({ pages: this.buildPages() }, () => {
if (typeof window !== 'undefined') {
window.RT_PAGE_COUNT = () => (this.state.pages || []).length;
window.RT_EXPORT_DATAURL = async (i) => { const c = await this.renderCanvas(i); return c ? c.toDataURL('image/png') : null; };
window.RT_READY = true;
}
});
});
if (document.fonts && document.fonts.ready) document.fonts.ready.then(() => this.regen());
}
regen() { this.setState({ pages: this.buildPages() }); }
toRuns(text, accent) {
const re = /(\*\*[^*]+\*\*|【[^】]+】|\*[^*\n]+\*)/g;
const runs = []; let last = 0; let m;
while ((m = re.exec(text))) {
if (m.index > last) runs.push({ t: text.slice(last, m.index), hi: false });
const inner = m[0].replace(/^\*\*|\*\*$/g, '').replace(/^【|】$/g, '').replace(/^\*|\*$/g, '');
runs.push({ t: inner, hi: true });
last = m.index + m[0].length;
}
if (last < text.length) runs.push({ t: text.slice(last), hi: false });
if (!runs.length) runs.push({ t: text, hi: false });
return runs.map(r => ({ t: r.t, color: r.hi ? accent : 'inherit', weight: r.hi ? '700' : '400' }));
}
buildPages() {
const S = this.state;
const theme = this.curTheme();
const raw = (S.raw || '').replace(/\r/g, '');
const lines = raw.split('\n');
const stripMd = (s) => s.replace(/^#{1,6}\s*/, '').replace(/^>\s*/, '').replace(/#+$/, '').trim();
const isHeading = (t) => {
if (/^#{1,6}\s/.test(t)) return true;
if (/^【.+】$/.test(t)) return true;
if (/^[0-9]{1,2}、\s*\S/.test(t) && t.length <= 24) return true;
if (/^[一二三四五六七八九十]+[、.,)]\s*\S/.test(t) && t.length <= 24) return true;
if (/^第[0-9一二三四五六七八九十]+[条点步章节]/.test(t) && t.length <= 24) return true;
return false;
};
// markdown bullets: -, *, +, •, ordered "1." / "1)" / "(1)"
const parseBullet = (t) => {
let m;
if ((m = t.match(/^(\d{1,2})[\.\)]\s+([\s\S]+)$/))) return { text: m[2].trim(), num: m[1] };
if ((m = t.match(/^[((]\s*(\d{1,2})\s*[))]\s*([\s\S]+)$/))) return { text: m[2].trim(), num: m[1] };
if (/^[-*+•·▪◦‣]\s+/.test(t)) return { text: t.replace(/^[-*+•·▪◦‣]\s+/, '').trim(), num: '' };
return null;
};
let i = 0;
while (i < lines.length && !lines[i].trim()) i++;
let title = i < lines.length ? stripMd(lines[i].trim()).replace(/\*\*/g, '').replace(/[【】]/g, '') : '';
let rawTitle = i < lines.length ? stripMd(lines[i].trim()) : '';
if (i < lines.length) i++;
if (!title) { title = '我的小红书笔记'; rawTitle = title; }
const blocks = [];
let buf = [];
const flush = () => { if (buf.length) { blocks.push({ kind: 'para', text: buf.join('') }); buf = []; } };
for (; i < lines.length; i++) {
const t = lines[i].trim();
if (!t) { flush(); continue; }
const im = t.match(/^!\[([^\]]*)\]\(([^)]+)\)$/);
if (im) { flush(); blocks.push({ kind: 'image', src: im[2].trim(), caption: im[1].trim() }); continue; }
if (isHeading(t)) { flush(); blocks.push({ kind: 'heading', text: stripMd(t) }); continue; }
const bl = parseBullet(t);
if (bl) { flush(); blocks.push({ kind: 'bullet', text: bl.text, num: bl.num }); continue; }
buf.push(t.replace(/^>\s*/, ''));
}
flush();
// word count + reading time
const wordCount = raw.replace(/\s/g, '').replace(/[*#>【】]/g, '').length;
const readMin = Math.max(1, Math.ceil(wordCount / 300));
// teaser
let teaser = '';
const fp = blocks.find(b => b.kind === 'para');
if (fp) { const m = fp.text.replace(/[*【】]/g, '').split(/(?<=[。!?!?])/); teaser = (m[0] || fp.text).slice(0, 48); }
// closing / dedication page (optional)
let closing = null;
if (S.closingOn) {
const ded = (S.dedication || '').trim();
if (ded) { closing = { text: ded }; }
else if (blocks.length > 2) {
const lastB = blocks[blocks.length - 1];
if (lastB.kind === 'para' && lastB.text.replace(/[*【】]/g, '').length <= 80) { closing = blocks.pop(); }
}
}
// density — measure each block's REAL rendered height (px) in a hidden node
// at the true 1080px scale, so pages fill evenly with no overflow / dead space.
const font = this.curFont();
const cardH = (this.getRatios()[S.ratioIndex] || this.getRatios()[0]).h;
const AVAIL = cardH - 370; // usable vertical space for blocks, between header & footer
const esc = (s) => (s || '').replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>');
const MT = { heading: 14, bullets: 6, para: 0 };
const MB = { heading: 28, bullets: 34, para: 34 };
const blockHTML = (b) => {
if (b.kind === 'heading') {
const m = b.text.match(/^([0-9一二三四五六七八九十]+)[、.\))]\s*([\s\S]*)$/);
const rest = esc((m ? m[2] : b.text.replace(/^【|】$/g, '')).replace(/\*\*/g, ''));
const lead = m
? '<span style="flex:none;width:74px;height:74px;font-size:42px;font-weight:900;"></span>'
: '<span style="flex:none;width:10px;height:54px;"></span>';
return '<div style="display:flex;align-items:center;gap:24px;">' + lead +
'<span style="font-size:60px;font-weight:' + font.titleWeight + ';line-height:1.28;letter-spacing:0.5px;font-family:' + font.title + ';">' + rest + '</span></div>';
}
if (b.kind === 'bullets') {
const items = b.items.map((it) => {
const dot = it.num
? '<span style="flex:none;min-width:46px;height:46px;padding:0 6px;margin-top:4px;"></span>'
: '<span style="flex:none;width:18px;height:18px;margin-top:18px;"></span>';
return '<div style="display:flex;gap:22px;align-items:flex-start;"><span style="flex:none;width:22px;"></span>' + dot +
'<div style="font-size:39px;line-height:1.6;padding-top:2px;">' + esc(it.text) + '</div></div>';
}).join('');
return '<div style="border-radius:24px;padding:42px 44px;display:flex;flex-direction:column;gap:30px;border:1px solid transparent;box-sizing:border-box;">' + items + '</div>';
}
return '<div style="font-size:41px;line-height:1.86;letter-spacing:0.4px;">' + esc(b.text) + '</div>';
};
const host = document.createElement('div');
host.setAttribute('aria-hidden', 'true');
host.style.cssText = 'position:absolute;left:-99999px;top:0;width:904px;visibility:hidden;pointer-events:none;box-sizing:border-box;font-family:' + font.body + ';';
document.body.appendChild(host);
const CONTENT_W = 904; // 1080 - 88*2
const imgBoxH = (src) => Math.round(Math.min(CONTENT_W * this.getImgRatio(src), AVAIL - 24));
const measure = (b) => {
if (b.kind === 'image') return imgBoxH(b.src) + 8 + 28;
host.innerHTML = blockHTML(b);
const el = host.firstElementChild;
const h = el ? el.getBoundingClientRect().height : 0;
return h + (MT[b.kind] || 0) + (MB[b.kind] || 0);
};
const target = Math.max(1, (S.targetPages || 5) - 1 - (closing ? 1 : 0));
const totalH = blocks.reduce((s, b) => s + measure(b), 0);
// spread evenly over the requested page count, but never pack past what fits
const budget = Math.min(AVAIL, Math.max(400, Math.ceil(totalH / target)));
// split paragraphs taller than the budget into sentence-sized chunks
const expanded = [];
for (const b of blocks) {
if (b.kind === 'para' && measure(b) > budget) {
const parts = b.text.split(/(?<=[。!?!?;;])/);
let cur = '';
for (const s of parts) {
if (cur && measure({ kind: 'para', text: cur + s }) > budget) { expanded.push({ kind: 'para', text: cur }); cur = s; }
else cur += s;
}
if (cur) expanded.push({ kind: 'para', text: cur });
} else expanded.push(b);
}
// group consecutive bullets
const grouped = [];
let bg = null;
for (const b of expanded) {
if (b.kind === 'bullet') { if (!bg) { bg = { kind: 'bullets', items: [] }; grouped.push(bg); } bg.items.push({ text: b.text, num: b.num || '' }); }
else { bg = null; grouped.push(b); }
}
const cards = [];
let cur = null, w = 0;
const nc = () => { cur = { blocks: [] }; cards.push(cur); w = 0; };
for (const b of grouped) {
const bw = measure(b);
if (cur && w + bw > budget && cur.blocks.length) {
let carried = null;
const last = cur.blocks[cur.blocks.length - 1];
if (last.kind === 'heading' && cur.blocks.length > 1) carried = cur.blocks.pop();
nc();
if (carried) { cur.blocks.push(carried); w += measure(carried); }
}
if (!cur) nc();
cur.blocks.push(b); w += bw;
}
document.body.removeChild(host);
const decorate = (b) => {
if (b.kind === 'heading') {
const m = b.text.match(/^([0-9一二三四五六七八九十]+)[、.\))]\s*([\s\S]*)$/);
if (m) return { isHeading: true, hasBadge: true, barOnly: false, badge: this.cnToNum(m[1]), rest: m[2].replace(/\*\*/g, ''), mt: 14, mb: 28 };
return { isHeading: true, hasBadge: false, barOnly: true, badge: '', rest: b.text.replace(/^【|】$/g, '').replace(/\*\*/g, ''), mt: 14, mb: 28 };
}
if (b.kind === 'bullets') return { isBullets: true, items: b.items.map(it => ({ runs: this.toRuns(it.text, theme.accent), num: it.num, hasNum: !!it.num, noNum: !it.num })), mt: 6, mb: 34 };
if (b.kind === 'image') return { isImage: true, imgUrl: 'url("' + b.src + '")', boxH: imgBoxH(b.src), caption: b.caption || '', hasCaption: !!b.caption, mt: 8, mb: 28 };
return { isPara: true, runs: this.toRuns(b.text, theme.accent), mt: 0, mb: 34 };
};
const hasSig = !!(S.signature && S.signature.trim());
let contentCount = cards.length + (closing ? 1 : 0);
const total = 1 + contentCount;
const pages = [];
pages.push({
type: 'cover', isCover: true, isContent: false, rawTitle,
titleRuns: this.toRuns(rawTitle, theme.accent).map(r => ({ t: r.t, hi: r.color !== 'inherit' })),
teaser, signature: S.signature || '', hasSig, noSig: !hasSig,
wordCount, readMin, num: this.pad(1), totalStr: this.pad(total),
});
let idx = 2;
cards.forEach((c) => {
pages.push({ type: 'content', isCover: false, isContent: true, brand: title.slice(0, 40), blocks: c.blocks.map(decorate), signature: S.signature || '', hasSig, noSig: !hasSig, num: this.pad(idx), totalStr: this.pad(total), progress: Math.round(idx / total * 100) + '%' });
idx++;
});
if (closing) {
pages.push({ type: 'content', isCover: false, isContent: true, brand: title.slice(0, 40), blocks: [{ isClosing: true, runs: this.toRuns(closing.text, theme.accent), mt: 0, mb: 0 }], signature: S.signature || '', hasSig, noSig: !hasSig, num: this.pad(idx), totalStr: this.pad(total), progress: '100%' });
}
return pages;
}
async renderCanvas(idx) {
const node = this._refs[idx];
if (!node || !window.html2canvas) return null;
if (document.fonts && document.fonts.ready) await document.fonts.ready;
const holder = document.createElement('div');
holder.style.cssText = 'position:fixed;left:-14000px;top:0;z-index:-1;';
const clone = node.cloneNode(true);
clone.style.transform = 'none';
clone.style.margin = '0';
holder.appendChild(clone);
document.body.appendChild(holder);
try {
const ch = (this.getRatios()[this.state.ratioIndex] || this.getRatios()[0]).h;
return await window.html2canvas(clone, { width: 1080, height: ch, scale: 2, backgroundColor: this.curTheme().bg, useCORS: true, logging: false });
} finally { holder.remove(); }
}
async exportCard(idx) {
const canvas = await this.renderCanvas(idx);
if (!canvas) return;
const url = canvas.toDataURL('image/png');
const a = document.createElement('a');
a.href = url; a.download = 'xiaohongshu-' + this.pad(idx + 1) + '.png';
document.body.appendChild(a); a.click(); a.remove();
}
async exportAll() {
for (let i = 0; i < (this.state.pages || []).length; i++) {
await this.exportCard(i);
await new Promise(r => setTimeout(r, 300));
}
}
renderVals() {
const theme = this.curTheme();
const font = this.curFont();
const S = this.state;
const hero = S.heroImg;
const pat = this.patternStyle(S.patternIndex, theme.line);
const ratio = this.getRatios()[S.ratioIndex] || this.getRatios()[0];
const cardH = ratio.h, previewH = Math.round(ratio.h * 0.277778), heroCardH = Math.round(ratio.h * 0.366), heroBlendH = Math.round(ratio.h * 0.5556);
const pages = (S.pages || []).map((p, i) => {
const o = { ...p, t: theme, fontTitle: font.title, fontBody: font.body, titleWeight: font.titleWeight, cardH, previewH, heroCardH, heroBlendH, gridBg: pat.img, gridSize: pat.size, gridOpacity: pat.op, _idx: i, cardRef: (el) => { this._refs[i] = el; }, exportSelf: () => this.exportCard(i) };
if (o.isCover) { o.hero = hero; o.hasHero = !!hero; o.noHero = !hero; o.heroEl = hero ? React.createElement('div', { style: { width: '100%', height: '100%', backgroundImage: 'url("' + hero + '")', backgroundSize: 'cover', backgroundPosition: 'center', backgroundRepeat: 'no-repeat' } }) : null; o.isCard = S.coverLayout === 0; o.isFull = S.coverLayout === 1; o.isBlend = S.coverLayout === 2; o.titleRuns = (p.titleRuns || []).map(r => ({ t: r.t, color: r.hi ? theme.accent : theme.title, fullColor: r.hi ? theme.accent : '#ffffff' })); }
return o;
});
const themes = this.getThemes().map((t, i) => ({
...t, i,
ringColor: (!S.customBg && i === S.themeIndex) ? t.title : 'rgba(0,0,0,0.08)',
labelColor: (!S.customBg && i === S.themeIndex) ? '#7a5a36' : '#a89f90',
pick: () => this.setState({ themeIndex: i, customColor: null, customBg: null }, () => this.regen()),
}));
const mkFonts = (sel, key) => this.getFonts().map((f, i) => ({
name: f.name, family: f.family, i,
ring: i === sel ? theme.title : 'rgba(0,0,0,0.12)',
bg: i === sel ? theme.soft : '#FCFAF4',
col: i === sel ? '#7a5a36' : '#8a8073',
pick: () => this.setState({ [key]: i }, () => this.regen()),
}));
const titleFonts = mkFonts(S.titleFontIndex, 'titleFontIndex');
const bodyFonts = mkFonts(S.bodyFontIndex, 'bodyFontIndex');
const pal = this.getPalette().map((c) => ({
c, ring: S.customColor === c ? '#2c2823' : 'rgba(0,0,0,0.12)',
pick: () => this.setState({ customColor: c }, () => this.regen()),
}));
const patterns = ['无', '网格', '圆点', '斜纹', '竖线', '横线', '公式', '数学', '物理', '化学', '计算机'].map((name, i) => ({
name, i,
ring: i === S.patternIndex ? theme.title : 'rgba(0,0,0,0.12)',
bg: i === S.patternIndex ? theme.soft : '#FCFAF4',
col: i === S.patternIndex ? '#7a5a36' : '#8a8073',
pick: () => this.setState({ patternIndex: i }, () => this.regen()),
}));
const coverLayouts = ['卡片', '全屏', '融入'].map((name, i) => ({
name, i,
ring: i === S.coverLayout ? theme.title : 'rgba(0,0,0,0.12)',
bg: i === S.coverLayout ? theme.soft : '#FCFAF4',
col: i === S.coverLayout ? '#7a5a36' : '#8a8073',
pick: () => this.setState({ coverLayout: i }, () => this.regen()),
}));
const ratios = this.getRatios().map((r, i) => ({
name: r.name, i,
ring: i === S.ratioIndex ? theme.title : 'rgba(0,0,0,0.12)',
bg: i === S.ratioIndex ? theme.soft : '#FCFAF4',
col: i === S.ratioIndex ? '#7a5a36' : '#8a8073',
pick: () => this.setState({ ratioIndex: i }, () => this.regen()),
}));
const rounded = this.props.cardCorners === '微圆角';
const covers = [];
for (let n = 1; n <= 20; n++) {
const src = 'covers/photo-' + this.pad(n) + '.jpg';
covers.push({
src,
ring: hero === src ? theme.accent : 'rgba(0,0,0,0)',
thumbEl: React.createElement('img', { src, style: { width: '100%', height: '100%', objectFit: 'cover', display: 'block' } }),
pick: () => this.setState({ heroImg: src }),
});
}
return {
covers,
raw: S.raw, signature: S.signature, targetPages: S.targetPages,
closingOn: S.closingOn, dedication: S.dedication,
closingBg: S.closingOn ? '#C26B2E' : '#D8CDB9',
closingKnob: S.closingOn ? '33px' : '3px',
toggleClosing: () => this.setState({ closingOn: !S.closingOn }, () => this.regen()),
onDedication: (e) => this.setState({ dedication: e.target.value }, () => this.regen()),
heroLabel: S.heroImg ? '已选择 · 点击更换' : '点击上传封面图',
hasHero: !!S.heroImg,
onRaw: (e) => this.setState({ raw: e.target.value }),
onSig: (e) => this.setState({ signature: e.target.value }, () => this.regen()),
onHero: (e) => { const f = e.target.files && e.target.files[0]; if (!f) return; const r = new FileReader(); r.onload = () => this.setState({ heroImg: r.result }); r.readAsDataURL(f); },
clearHero: () => this.setState({ heroImg: null }),
incPages: () => this.setState({ targetPages: Math.min(9, S.targetPages + 1) }, () => this.regen()),
decPages: () => this.setState({ targetPages: Math.max(3, S.targetPages - 1) }, () => this.regen()),
generate: () => this.regen(),
loadSample: () => this.setState({ raw: this.SAMPLE }, () => this.regen()),
clearText: () => this.setState({ raw: '' }, () => this.regen()),
exportAll: () => this.exportAll(),
theme, themes, titleFonts, bodyFonts, patterns, coverLayouts, pages,
palette: pal,
resetRing: S.customColor ? 'rgba(0,0,0,0.12)' : theme.title,
resetColor: () => this.setState({ customColor: null }, () => this.regen()),
onCustomColor: (e) => this.setState({ customColor: e.target.value }, () => this.regen()),
customBgRing: S.customBg ? theme.title : 'rgba(0,0,0,0.08)',
customBgLabel: S.customBg ? '#7a5a36' : '#a89f90',
onCustomBg: (e) => this.setState({ customBg: e.target.value }, () => this.regen()),
pageCount: pages.length,
ratios,
dimLabel: ratio.w + '×' + ratio.h,
dimText: ratio.w + ' × ' + ratio.h,
cardRadius: rounded ? '18px' : '0px',
};
}
}
</script>
</body>
</html>