-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
1289 lines (1097 loc) · 58.4 KB
/
index.html
File metadata and controls
1289 lines (1097 loc) · 58.4 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
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>AI Editorial Studio | Powered by Pollinations</title>
<script src="https://cdn.tailwindcss.com"></script>
<!-- Ultra-Premium Typography: Cormorant (Serif) & Montserrat (Sans) -->
<link
href="https://fonts.googleapis.com/css2?family=Cormorant+Garamond:ital,wght@0,300;0,400;0,600;1,400&family=Montserrat:wght@200;300;400;500&display=swap"
rel="stylesheet">
<script>
tailwind.config = {
theme: {
extend: {
fontFamily: {
sans: ['Montserrat', 'sans-serif'],
serif: ['Cormorant Garamond', 'serif'],
},
colors: {
cream: '#F9F9F6',
ink: '#0A0A0A',
}
}
}
}
</script>
<style>
/* Base Resets & Smoothness */
html {
scroll-behavior: smooth;
}
body {
background-color: #050505;
color: #ffffff;
overflow-x: hidden;
}
/* The $200k Video Background Technique */
.video-bg {
position: fixed;
right: 0;
bottom: 0;
min-width: 100%;
min-height: 100%;
width: auto;
height: auto;
z-index: -2;
object-fit: cover;
opacity: 0.5;
filter: grayscale(30%) contrast(120%);
}
.video-overlay {
position: fixed;
top: 0;
left: 0;
width: 100vw;
height: 100vh;
z-index: -1;
background: linear-gradient(180deg, rgba(5, 5, 5, 0.4) 0%, rgba(5, 5, 5, 0.95) 100%);
}
/* Swiss Luxury Inputs */
.luxury-input {
background: transparent;
border: none;
border-bottom: 1px solid rgba(255, 255, 255, 0.2);
color: #ffffff;
font-family: 'Cormorant Garamond', serif;
font-size: 2.5rem;
width: 100%;
padding: 0.5rem 0;
transition: all 0.4s ease;
border-radius: 0;
}
.luxury-input:focus {
outline: none;
border-bottom: 1px solid rgba(255, 255, 255, 1);
background: transparent;
}
.luxury-input::placeholder {
color: rgba(255, 255, 255, 0.15);
}
/* The Output: Print Magazine Styling */
.magazine-wrapper {
background: #F9F9F6;
color: #0A0A0A;
}
.magazine-page {
page-break-after: always;
padding: 6rem 4rem;
max-width: 1200px;
margin: 0 auto;
min-height: 100vh;
}
.formatted-content {
column-count: 2;
column-gap: 4rem;
text-align: justify;
}
.formatted-content p {
font-family: 'Montserrat', sans-serif;
font-size: 0.95rem;
line-height: 2;
margin-bottom: 1.5rem;
font-weight: 300;
color: #222;
}
/* Massive Drop Cap for the first paragraph */
.formatted-content>p:first-of-type::first-letter {
float: left;
font-size: 6.5rem;
line-height: 0.7;
padding-top: 8px;
padding-right: 12px;
font-family: 'Cormorant Garamond', serif;
font-weight: 400;
color: #0A0A0A;
}
.formatted-content h3 {
font-family: 'Cormorant Garamond', serif;
font-size: 2rem;
font-weight: 400;
color: #000;
margin-top: 2rem;
margin-bottom: 1rem;
border-bottom: 1px solid #ddd;
padding-bottom: 0.5rem;
column-span: all;
}
.formatted-content ul,
.formatted-content ol {
font-family: 'Montserrat', sans-serif;
margin-left: 1rem;
margin-bottom: 2rem;
color: #333;
font-size: 0.95rem;
line-height: 2;
font-weight: 300;
}
.formatted-content li {
margin-bottom: 0.5rem;
}
.formatted-content strong {
font-weight: 500;
color: #000;
}
/* Split Screen Animation */
#workspace-container {
display: flex;
width: 100%;
transition: all 0.7s cubic-bezier(0.4, 0, 0.2, 1);
}
#book-container {
transition: width 0.7s cubic-bezier(0.4, 0, 0.2, 1);
}
#critique-panel {
transition: width 0.7s cubic-bezier(0.4, 0, 0.2, 1);
}
/* Custom minimal scrollbar */
::-webkit-scrollbar {
width: 4px;
}
::-webkit-scrollbar-track {
background: #050505;
}
::-webkit-scrollbar-thumb {
background: #333;
}
@media print {
.no-print,
.video-bg,
.video-overlay,
#critique-panel {
display: none !important;
}
body,
.magazine-wrapper {
background: white !important;
color: black !important;
}
.magazine-page {
padding: 0;
max-width: 100%;
margin: 0;
}
.formatted-content {
column-count: 2;
column-gap: 3rem;
}
#book-container {
width: 100% !important;
}
}
/* Glitch/Pulse animation for loading states */
.pulse-text {
animation: pulseOpacity 2s infinite;
}
@keyframes pulseOpacity {
0%,
100% {
opacity: 1;
}
50% {
opacity: 0.4;
}
}
</style>
</head>
<body class="antialiased min-h-screen relative selection:bg-white selection:text-black">
<!-- Cinematic Video Background (Abstract Dark Fluid) -->
<video autoplay loop muted playsinline class="video-bg no-print">
<source src="https://cdn.coverr.co/videos/coverr-dark-abstract-waves-2641/1080p.mp4" type="video/mp4">
</video>
<div class="video-overlay no-print"></div>
<!-- Audiobook Player (Floating) -->
<div id="audio-player-container" class="hidden fixed bottom-8 left-1/2 -translate-x-1/2 z-[100] flex flex-col items-center gap-2 bg-ink/90 backdrop-blur-md border border-white/20 p-4 rounded-3xl shadow-2xl transition-all duration-500 transform translate-y-10 opacity-0 min-w-[160px] no-print">
<button id="audio-close-btn" class="absolute top-2 right-3 text-white/50 hover:text-white transition-colors text-lg focus:outline-none">×</button>
<button id="audio-play-btn" class="w-16 h-16 rounded-full border border-white/30 flex items-center justify-center text-white text-[2rem] hover:bg-white/10 transition-all outline-none leading-none">
⏸️
</button>
<div id="audio-time-display" class="text-[0.65rem] font-sans tracking-[0.2em] text-white/70 uppercase">00:00 / 00:00</div>
</div>
<!-- Terms of Service Modal -->
<div id="tos-modal"
class="hidden fixed inset-0 z-[100] bg-black/90 flex justify-center items-center backdrop-blur-sm p-4">
<div class="bg-ink border border-white/20 max-w-2xl w-full p-12 relative max-h-[90vh] overflow-y-auto">
<button id="close-tos"
class="absolute top-6 right-6 text-white text-3xl hover:text-white/60 transition-colors">×</button>
<h2 class="text-3xl font-serif mb-6 uppercase tracking-widest text-center text-white">Terms of Service &
Usage Guidance</h2>
<div class="font-sans text-sm font-light leading-loose text-white/80 space-y-6">
<p>Welcome to the AI Editorial Studio. By utilizing this platform, you interact with parameters of
luxury editorial generation, powered seamlessly by Pollinations AI.</p>
<h3 class="text-lg text-white tracking-widest border-b border-white/20 pb-2 uppercase">Platform
Mechanics</h3>
<p>Every generation, translation, critique, and targeted regeneration consumes <em>Pollen</em>. This
abstract currency ensures the ecosystem operates at peak performance.</p>
<h3 class="text-lg text-white tracking-widest border-b border-white/20 pb-2 uppercase">Tier Guidance
</h3>
<div class="p-6 bg-white/5 border border-white/10">
<p class="mb-2 uppercase tracking-widest text-white"><strong
class="font-semibold text-green-400">RECOMMENDED: SEED Tier</strong></p>
<p class="mb-6">We highly recommend upgrading to the SEED tier for the ultimate experience. This
provides full access to premium features, high-fidelity synthesis, and an unrestricted creative
canvas.</p>
<p class="mb-2 uppercase tracking-widest text-white"><strong
class="font-semibold text-gray-400">SPORE Tier</strong></p>
<p>The SPORE tier is heavily limited. It serves only as a basic introduction; usage is restricted
and you may frequently encounter pollen exhaustion.</p>
</div>
<h3 class="text-lg text-white tracking-widest border-b border-white/20 pb-2 uppercase">AI-Generated
Content</h3>
<p>The content synthesized by our dual-agent pipeline is algorithmic. While we strive for high-end
fidelity, variations, hallucinations, and abstract interpretations represent the inherent nature of
generative art.</p>
</div>
</div>
</div>
<!-- Error Toast Container -->
<div id="toast-container" class="fixed top-8 left-1/2 -translate-x-1/2 z-[9999] flex flex-col gap-2"></div>
<!-- Transparent, Ultra-Minimal Nav -->
<nav
class="w-full flex flex-col md:flex-row justify-between items-center p-8 md:px-16 no-print z-50 fixed top-0 left-0 mix-blend-difference gap-4">
<div class="flex flex-col items-center md:items-start">
<h1 class="text-sm font-sans tracking-[0.3em] uppercase text-white font-light flex items-center gap-3">
<img src="https://raw.githubusercontent.com/pollinations/pollinations/main/assets/logo.svg"
alt="Pollinations Logo" class="w-6 h-6 invert">
E-Book Studio
</h1>
<p class="text-[0.6rem] font-sans tracking-[0.2em] uppercase text-white/50 mt-1">Engine Powered by
Pollinations AI</p>
<button id="open-tos"
class="mt-2 text-[0.6rem] tracking-[0.2em] uppercase text-white/50 border-b border-white/20 hover:text-white transition-colors">Terms
of Service</button>
</div>
<a id="auth-btn"
class="text-xs font-sans tracking-[0.2em] uppercase text-white border-b border-white/30 pb-1 hover:border-white transition-all cursor-pointer hidden">
Authenticate Node
</a>
<div id="user-status" class="hidden flex items-center space-x-6">
<span id="tier-badge"
class="text-[0.6rem] font-sans tracking-[0.3em] uppercase text-white border border-white/20 px-3 py-1 bg-white/10">SPORE</span>
<span class="text-xs font-sans tracking-[0.2em] uppercase text-white">
POLLEN: <span id="pollen-balance" class="font-medium text-white shadow-sm">...</span>
</span>
</div>
</nav>
<!-- Main Studio Interface -->
<main class="relative z-10 w-full min-h-screen flex flex-col items-center justify-center px-6 pt-32 pb-20 no-print"
id="main-view">
<!-- Auth Warning State -->
<div id="auth-warning" class="text-center mb-16 hidden">
<h2 class="text-4xl md:text-6xl font-serif text-white mb-6 tracking-tight">Access Restricted</h2>
<p
class="text-xs font-sans tracking-[0.2em] uppercase text-white/60 max-w-lg mx-auto leading-loose border border-white/10 p-6 backdrop-blur-sm">
Authentication required. Connect your Pollinations node to utilize the multi-modal generation engine at
zero platform cost.
</p>
<div class="mt-8 flex flex-col items-center gap-4">
<div class="flex items-center gap-3">
<input type="checkbox" id="tos-agree"
class="w-4 h-4 accent-white bg-transparent border border-white/30 rounded-none cursor-pointer">
<label for="tos-agree"
class="text-[0.6rem] font-sans tracking-[0.2em] uppercase text-white/60 cursor-pointer">
I AGREE TO THE <a href="#" id="open-tos-initial"
class="text-white border-b border-white/30 hover:border-white transition-colors">TERMS OF
SERVICE</a>
</label>
</div>
</div>
</div>
<!-- The Studio Form (Brutalist Luxury) -->
<div id="app-wrapper" class="hidden w-full max-w-4xl mx-auto mt-12">
<div id="limits-dashboard" class="mb-20 flex justify-between items-end border-b border-white/10 pb-4">
<p class="text-xs font-sans tracking-[0.2em] uppercase text-white/40">Allocated Bandwidth</p>
<p class="text-sm font-sans tracking-[0.2em] text-white"><span id="max-pages-display"
class="font-medium text-lg text-white">0</span> MAX PAGES</p>
</div>
<div class="space-y-16">
<!-- Input 1 -->
<div class="group">
<label
class="block text-xs font-sans tracking-[0.2em] text-white/40 mb-2 uppercase transition-colors group-focus-within:text-white">01
— Subject Matter</label>
<input type="text" id="topic" placeholder="e.g. The Architecture of Minimalist Sound"
class="luxury-input">
</div>
<!-- Input 2 -->
<div class="group">
<label
class="block text-xs font-sans tracking-[0.2em] text-white/40 mb-2 uppercase transition-colors group-focus-within:text-white">02
— Art Direction & Tone</label>
<input type="text" id="style" placeholder="e.g. Bauhaus, High-Contrast, Melancholic"
class="luxury-input">
</div>
<!-- Input 3 (Custom Instructions) -->
<div class="group">
<label
class="block text-xs font-sans tracking-[0.2em] text-white/40 mb-2 uppercase transition-colors group-focus-within:text-white flex items-center justify-between">
<span>03 — Custom Instructions</span>
<span
class="text-[0.6rem] tracking-widest text-white/50 border border-white/20 px-2 py-0.5 ml-3 bg-white/5 inline-block">PREMIUM
PARAMETER</span>
</label>
<input type="text" id="custom-instructions"
placeholder="e.g. Speak like a 19th-century poet, extreme minimalism..."
class="luxury-input text-lg">
</div>
<!-- Input 4 -->
<div class="group">
<label
class="block text-xs font-sans tracking-[0.2em] text-white/40 mb-2 uppercase transition-colors group-focus-within:text-white">04
— Page Count</label>
<input type="number" id="pages-count" value="4" min="1" class="luxury-input w-32">
<p id="page-warning"
class="text-[0.65rem] font-sans tracking-widest text-red-500 mt-4 hidden uppercase">Insufficient
Pollen Balance for this request</p>
</div>
<!-- Input 5 (Cover Art) -->
<div class="group">
<label
class="block text-xs font-sans tracking-[0.2em] text-white/40 mb-2 uppercase transition-colors group-focus-within:text-white flex items-center justify-between">
<span>05 — Cover Art Concept</span>
<span class="text-[0.6rem] tracking-widest text-white/50 border border-white/20 px-2 py-0.5 ml-3 bg-white/5 inline-block">OPTIONAL</span>
</label>
<input type="text" id="cover-concept" placeholder="e.g. A minimalist geometric shape in deep red"
class="luxury-input">
</div>
</div>
<!-- Generate Action -->
<div class="mt-24 pt-10 text-center flex flex-col items-center">
<button id="generate-btn"
class="text-sm font-sans tracking-[0.3em] uppercase text-ink bg-white border border-white px-16 py-6 hover:bg-transparent hover:text-white transition-all duration-700 w-full md:w-auto shadow-[0_0_40px_rgba(255,255,255,0.1)] hover:shadow-none">
Initialize Dual-Agent Pipeline
</button>
<div id="status-container" class="mt-12 h-8 hidden">
<p id="status-text" class="text-xs font-sans tracking-[0.2em] uppercase text-white pulse-text"></p>
</div>
</div>
</div>
</main>
<!-- Rendered Workspace (Split Screen Architecture) -->
<div id="workspace-container" class="hidden h-screen bg-cream z-20 relative pt-24 overflow-hidden">
<!-- Generated Book Area -->
<div id="book-container"
class="w-full h-full overflow-y-auto bg-cream transition-all duration-700 hidden-scrollbar border-r border-gray-300">
<!-- Toolbar -->
<div
class="text-center py-4 bg-ink no-print sticky top-0 z-30 flex justify-between items-center px-4 md:px-8 border-b border-white/10 shadow-xl flex-wrap gap-4">
<div class="flex items-center gap-4">
<button id="back-btn"
class="text-xs font-sans tracking-[0.2em] text-white/50 hover:text-white transition-colors uppercase">←
Back</button>
<p
class="text-[0.65rem] font-sans tracking-[0.3em] uppercase text-white/50 border-l border-white/20 pl-4 hidden md:block">
Rendered via Pollinations AI</p>
</div>
<div class="flex items-center gap-2">
<!-- Translate System -->
<div class="flex items-center border border-white/20 focus-within:border-white transition-colors">
<input type="text" id="target-language" placeholder="Language"
class="bg-transparent text-[0.65rem] text-white px-3 py-2 outline-none w-20 md:w-24 tracking-widest uppercase placeholder-white/40">
<button id="translate-btn"
class="text-[0.65rem] font-sans tracking-[0.2em] uppercase text-white hover:bg-white hover:text-ink transition-colors px-3 py-2 border-l border-white/20">
Translate
</button>
</div>
<button id="tts-btn"
class="text-[0.65rem] font-sans tracking-[0.2em] uppercase text-white hover:bg-white hover:text-ink transition-colors border border-white/20 px-4 py-2 flex items-center gap-2">
<span>AUDIOBOOK</span>
</button>
<button id="critique-btn"
class="text-[0.65rem] font-sans tracking-[0.2em] uppercase text-white hover:bg-white hover:text-ink transition-colors border border-white/20 px-4 py-2">
Critique
</button>
<button onclick="window.print()"
class="text-[0.65rem] font-sans tracking-[0.2em] uppercase text-white hover:bg-white hover:text-ink transition-colors border border-white/20 px-4 py-2 hidden md:block">
PDF
</button>
</div>
</div>
<div class="magazine-wrapper" id="book-content">
<!-- AI Content Injected Here -->
</div>
<!-- Enhanced Footer Logo (Branding) -->
<div class="text-center py-20 bg-cream border-t border-gray-200">
<div class="flex justify-center items-center gap-4 mb-4 text-ink">
<img src="https://raw.githubusercontent.com/pollinations/pollinations/main/assets/logo.svg"
alt="Pollinations Logo" class="w-7 h-7">
<p class="text-lg font-sans tracking-[0.3em] uppercase font-light">Pollinations AI</p>
</div>
<p class="text-[0.65rem] font-sans tracking-[0.3em] uppercase text-gray-500 mb-4">Concept to Reality</p>
<div class="w-16 h-[1px] bg-gray-300 mx-auto mb-4"></div>
<p class="text-sm font-serif italic text-gray-700 px-8 max-w-sm mx-auto leading-relaxed">Our profound
gratitude to Pollinations for empowering this generation engine flawlessly.</p>
</div>
</div>
<!-- Sidebar Panel for Critique -->
<div id="critique-panel"
class="w-0 bg-ink flex-shrink-0 h-full overflow-y-auto hidden-scrollbar relative no-print shadow-[-10px_0_30px_rgba(0,0,0,0.5)]">
<button id="close-critique"
class="absolute top-6 right-8 text-white text-3xl hover:text-white/60 transition-colors">×</button>
<div class="p-10 w-full md:w-96 max-w-full">
<div class="mb-10 border-b border-white/20 pb-6">
<h3 class="text-4xl font-serif text-white tracking-widest leading-tight">Editor-in<br>Chief</h3>
<p class="text-[0.65rem] tracking-[0.4em] text-green-400 uppercase mt-2">Vogue Persona Active</p>
</div>
<div id="critique-content" class="text-white space-y-8">
<!-- Critique injected here -->
</div>
</div>
</div>
</div>
<script>
// Balance validation framework
let currentBalance = 0;
// Abstract application state
window.currentManuscript = null;
window.currentImages = [];
window.currentCoverImage = null;
window.currentTopic = "";
window.currentStyle = "";
window.currentCustom = "";
// Audiobook State
let globalAudio = null;
let audioUpdateInterval = null;
function formatTime(seconds) {
if (isNaN(seconds) || !isFinite(seconds)) return "00:00";
const m = Math.floor(seconds / 60).toString().padStart(2, '0');
const s = Math.floor(seconds % 60).toString().padStart(2, '0');
return `${m}:${s}`;
}
function cleanupAudio() {
if (globalAudio) {
globalAudio.pause();
globalAudio.currentTime = 0;
URL.revokeObjectURL(globalAudio.src);
globalAudio = null;
}
if (audioUpdateInterval) {
clearInterval(audioUpdateInterval);
audioUpdateInterval = null;
}
}
function hideAudioPlayer() {
cleanupAudio();
const container = document.getElementById('audio-player-container');
container.classList.add('translate-y-10', 'opacity-0', 'pointer-events-none');
setTimeout(() => {
container.classList.add('hidden');
container.classList.remove('pointer-events-none');
}, 500);
}
function initAudioPlayer(audioUrl) {
cleanupAudio();
globalAudio = new Audio(audioUrl);
const container = document.getElementById('audio-player-container');
const playBtn = document.getElementById('audio-play-btn');
const timeDisplay = document.getElementById('audio-time-display');
container.classList.remove('hidden');
// trigger reflow
void container.offsetWidth;
container.classList.remove('translate-y-10', 'opacity-0');
playBtn.innerText = "⏸️";
timeDisplay.innerText = "00:00 / 00:00";
globalAudio.play();
playBtn.onclick = () => {
if (globalAudio.paused) {
globalAudio.play();
playBtn.innerText = "⏸️";
} else {
globalAudio.pause();
playBtn.innerText = "▶️";
}
};
globalAudio.onloadedmetadata = () => {
timeDisplay.innerText = formatTime(globalAudio.currentTime) + " / " + formatTime(globalAudio.duration);
};
globalAudio.onended = () => {
playBtn.innerText = "▶️";
globalAudio.currentTime = 0;
timeDisplay.innerText = "00:00 / " + formatTime(globalAudio.duration);
};
audioUpdateInterval = setInterval(() => {
if (globalAudio && !globalAudio.paused && !isNaN(globalAudio.duration)) {
timeDisplay.innerText = formatTime(globalAudio.currentTime) + " / " + formatTime(globalAudio.duration);
}
}, 500);
}
document.getElementById('audio-close-btn').onclick = hideAudioPlayer;
const authBtn = document.getElementById('auth-btn');
const authWarning = document.getElementById('auth-warning');
const appWrapper = document.getElementById('app-wrapper');
const userStatus = document.getElementById('user-status');
const limitsDashboard = document.getElementById('limits-dashboard');
const maxPagesDisplay = document.getElementById('max-pages-display');
const pagesInput = document.getElementById('pages-count');
const pageWarning = document.getElementById('page-warning');
const pollenBalanceEl = document.getElementById('pollen-balance');
const tierBadgeEl = document.getElementById('tier-badge');
// Element selections
const toastContainer = document.getElementById('toast-container');
const generateBtn = document.getElementById('generate-btn');
const statusContainer = document.getElementById('status-container');
const statusText = document.getElementById('status-text');
const mainView = document.getElementById('main-view');
const workspaceContainer = document.getElementById('workspace-container');
const bookContainer = document.getElementById('book-container');
const bookContent = document.getElementById('book-content');
const critiquePanel = document.getElementById('critique-panel');
const critiqueContent = document.getElementById('critique-content');
// Feature: Terms of Service Modal
document.getElementById('open-tos').onclick = () => document.getElementById('tos-modal').classList.remove('hidden');
document.getElementById('close-tos').onclick = () => document.getElementById('tos-modal').classList.add('hidden');
// Feature: Back to setup
document.getElementById('back-btn').onclick = () => {
hideAudioPlayer();
workspaceContainer.classList.add('hidden');
mainView.classList.remove('hidden');
};
let maxAllowedPages = 0;
const urlHash = new URLSearchParams(location.hash.slice(1));
let apiKey = urlHash.get('api_key');
if (window.location.hash) {
window.history.replaceState(null, null, location.pathname);
}
// Cost logic map
const actionCosts = {
'generate_base': 0.0011, // Approximately 1 text generation + 1 flux image
'translate': 0.0005,
'critique': 0.0002,
'regenerate': 0.0002,
'audiobook': 0.0001
};
function showGlobalError(msg) {
const errDiv = document.createElement('div');
errDiv.className = "bg-red-600/90 text-white font-sans text-[0.65rem] tracking-[0.2em] uppercase px-8 py-4 shadow-2xl transition-all duration-500 border border-red-400 backdrop-blur-sm opacity-0 transform translate-y-[-20px]";
errDiv.innerHTML = msg;
toastContainer.appendChild(errDiv);
requestAnimationFrame(() => {
errDiv.style.opacity = '1';
errDiv.style.transform = 'translate-y-0';
});
setTimeout(() => {
errDiv.style.opacity = '0';
errDiv.style.transform = 'translate-y-[-20px]';
setTimeout(() => errDiv.remove(), 500);
}, 4000);
}
// Feature 6: Central Validation Check
function checkBalance(action, amountMultiplier = 1) {
const cost = (actionCosts[action] || 0) * amountMultiplier;
if (currentBalance < cost) {
showGlobalError("Insufficient pollen. Please refill to continue.");
return false;
}
return true;
}
if (apiKey) {
authBtn.classList.add('hidden');
authWarning.classList.add('hidden');
appWrapper.classList.remove('hidden');
userStatus.classList.remove('hidden');
fetchAccountData();
} else {
authWarning.classList.remove('hidden');
const tosAgree = document.getElementById('tos-agree');
const openTosInitial = document.getElementById('open-tos-initial');
if (openTosInitial) {
openTosInitial.onclick = (e) => {
e.preventDefault();
document.getElementById('tos-modal').classList.remove('hidden');
};
}
if (window.location.protocol === 'about:' || window.location.protocol === 'blob:') {
authWarning.innerHTML += `
<p class="text-xs font-sans tracking-widest uppercase text-red-500 mt-8 border border-red-500/30 p-4 bg-red-500/10">
SYSTEM ERROR: PREVIEW SANDBOX DETECTED.<br>RUN LOCALLY (.html file) OR DEPLOY TO GITHUB PAGES TO PROCEED.
</p>
`;
} else {
authBtn.classList.remove('hidden');
authBtn.classList.add('opacity-30', 'pointer-events-none'); // default disabled
const params = new URLSearchParams({
redirect_url: window.location.href.split('#')[0],
permissions: 'profile,balance'
});
authBtn.href = `https://enter.pollinations.ai/authorize?${params}`;
authBtn.target = "_top";
if (tosAgree) {
tosAgree.addEventListener('change', (e) => {
if (e.target.checked) {
authBtn.classList.remove('opacity-30', 'pointer-events-none');
} else {
authBtn.classList.add('opacity-30', 'pointer-events-none');
}
});
}
}
}
async function fetchAccountData() {
try {
const balRes = await fetch('https://gen.pollinations.ai/account/balance', {
headers: { 'Authorization': `Bearer ${apiKey}` }
});
const balData = await balRes.json();
const balance = balData.balance !== undefined ? parseFloat(balData.balance) : parseFloat(balData);
currentBalance = isNaN(balance) ? 0 : balance;
pollenBalanceEl.innerText = currentBalance.toFixed(3);
maxAllowedPages = Math.floor(currentBalance / actionCosts.generate_base);
maxPagesDisplay.innerText = maxAllowedPages;
pagesInput.max = maxAllowedPages;
const profRes = await fetch('https://gen.pollinations.ai/account/profile', {
headers: { 'Authorization': `Bearer ${apiKey}` }
});
if (profRes.ok) {
const profData = await profRes.json();
if (profData.tier) {
tierBadgeEl.innerText = profData.tier.toUpperCase();
}
}
pagesInput.addEventListener('input', (e) => {
const requestedPages = parseInt(e.target.value);
if (requestedPages > maxAllowedPages) {
pageWarning.classList.remove('hidden');
generateBtn.disabled = true;
generateBtn.classList.add('opacity-30', 'pointer-events-none');
} else {
pageWarning.classList.add('hidden');
generateBtn.disabled = false;
generateBtn.classList.remove('opacity-30', 'pointer-events-none');
}
});
} catch (err) {
console.error(err);
}
}
function parseAIJson(rawStr) {
try {
let cleaned = rawStr.replace(/\`\`\`json/g, '').replace(/\`\`\`/g, '').trim();
const firstBrace = cleaned.indexOf('{');
const lastBrace = cleaned.lastIndexOf('}');
if (firstBrace !== -1 && lastBrace !== -1) {
cleaned = cleaned.slice(firstBrace, lastBrace + 1);
}
return JSON.parse(cleaned);
} catch (err) {
console.error("Failed parsing AI JSON: ", rawStr);
throw new Error("Invalid format received from Generator");
}
}
// Core Rendering Function
function renderBookView() {
if (!window.currentManuscript) return;
const coverHtml = window.currentCoverImage ? `<img src="${window.currentCoverImage}" alt="Cover Art" class="w-full max-w-2xl h-auto mb-16 shadow-[0_20px_50px_rgba(0,0,0,0.15)] rounded-sm">` : '';
let html = `
<div class="magazine-page flex flex-col justify-center items-center text-center px-4">
<p class="text-[0.65rem] font-sans tracking-[0.4em] uppercase text-gray-500 mb-8 border-b border-gray-300 pb-2 font-semibold">Pollinations AI Exclusive</p>
<h1 class="text-6xl md:text-[8rem] font-serif text-ink mb-12 leading-[0.85] tracking-tighter uppercase px-4 break-words hyphens-auto w-full">${window.currentManuscript.title}</h1>
<div class="w-24 h-[1px] bg-ink mb-12"></div>
${coverHtml}
<p class="text-lg md:text-2xl font-sans font-light text-gray-600 max-w-2xl mx-auto leading-relaxed px-4 md:px-8">${window.currentManuscript.introduction}</p>
</div>
`;
for (let i = 0; i < window.currentManuscript.pages.length; i++) {
const page = window.currentManuscript.pages[i];
const imgUrl = window.currentImages[i] || 'https://via.placeholder.com/1280x720';
html += `
<div class="magazine-page relative transition-opacity duration-500" id="page-wrapper-${i}">
<div class="mb-16">
<p class="text-[0.6rem] md:text-xs font-sans tracking-[0.3em] uppercase text-gray-400 mb-4 border-b border-gray-200 pb-4 flex justify-between">
<span>Section 0${i + 1} — ${window.currentManuscript.title}</span>
</p>
<h2 id="page-title-${i}" class="text-4xl md:text-6xl lg:text-7xl font-serif text-ink mb-12 tracking-tight leading-none break-words">${page.page_title}</h2>
<img src="${imgUrl}" alt="Editorial Concept" class="w-full h-[50vh] md:h-[60vh] object-cover bg-gray-100 grayscale-[15%] contrast-[1.15] shadow-sm transition-all hover:grayscale-0">
</div>
<div id="page-content-${i}" class="formatted-content px-4 md:px-0">
${page.content}
</div>
<!-- Feature 3: Per-Page Regeneration Button -->
<div class="mt-16 pt-10 border-t border-gray-200 text-center no-print">
<button onclick="regeneratePage(${i})" class="text-[0.65rem] font-sans tracking-[0.2em] uppercase text-ink/70 border border-ink/20 px-8 py-3 hover:bg-ink hover:text-white transition-all transform hover:-translate-y-0.5" id="regen-btn-${i}">
Regenerate Section
</button>
</div>
</div>
`;
}
bookContent.innerHTML = html;
bookContainer.scrollTop = 0;
}
generateBtn.onclick = async () => {
const topic = document.getElementById('topic').value;
const style = document.getElementById('style').value;
const customInstr = document.getElementById('custom-instructions').value;
const coverConcept = document.getElementById('cover-concept').value;
const pagesCount = parseInt(document.getElementById('pages-count').value);
if (!topic || !style) {
showGlobalError("Subject Matter and Art Direction are required.");
return;
}
let totalPagesCost = pagesCount;
if (coverConcept) totalPagesCost += 1;
if (!checkBalance('generate_base', totalPagesCost)) return;
try {
generateBtn.disabled = true;
generateBtn.innerText = "PIPELINE ACTIVE";
generateBtn.classList.add('bg-transparent', 'text-white', 'pointer-events-none');
statusContainer.classList.remove('hidden');
window.currentTopic = topic;
window.currentStyle = style;
window.currentCustom = customInstr; // Store for per-page regeneration Feature 4
// Feature 4 Integration: Inject custom instructions directly into generation prompt
const instructionsInjection = customInstr ? `\n\nCRITICAL PARAMETER (CUSTOM INSTRUCTIONS): ${customInstr}\nYou MUST respect these instructions exactly.` : '';
statusText.innerText = "[ AGENT 01 ] ARCHITECTING MANUSCRIPT & EDITORIAL COPY...";
const authorPrompt = `You are a visionary Editor-in-Chief for a high-end magazine.
Write a profound, highly sophisticated editorial piece about "${topic}".
It must be exactly ${pagesCount} pages long.${instructionsInjection}
FORMATTING RULES:
1. Write high-value, insightful, and beautifully paced paragraphs.
2. Format the "content" field in HTML: Use <p> for paragraphs, <h3> for sub-headers, and <ul> for lists. No markdown wrapping.
Return ONLY a valid JSON object:
{
"title": "A profound, elegant title",
"introduction": "A sophisticated preamble/hook.",
"pages":[
{
"page_title": "Chapter Heading",
"content": "<p>Content...</p>"
}
]
}`;
const authorRes = await fetch('https://gen.pollinations.ai/v1/chat/completions', {
method: 'POST',
headers: { 'Authorization': `Bearer ${apiKey}`, 'Content-Type': 'application/json' },
body: JSON.stringify({
model: 'openai',
messages: [{ role: 'user', content: authorPrompt }],
response_format: { type: "json_object" },
temperature: 0.5
})
});
if (!authorRes.ok) throw new Error("AGENT 01 FAILED");
const authorData = await authorRes.json();
const manuscript = parseAIJson(authorData.choices[0].message.content);
window.currentManuscript = manuscript;
statusText.innerText = "[ AGENT 02 ] ANALYZING TEXT & DIRECTING VISUAL CONCEPTS...";
const artDirectorPrompt = `You are an Elite Art Director & Photography Expert.
I will give you a ${pagesCount}-page manuscript.
For EACH page, read the title and content, and design a breathtaking, award-winning photography prompt for an AI image generator (FLUX).
The global visual aesthetic must be: "${style}".
RULES FOR IMAGE PROMPTS:
1. Describe the subject, the lighting (e.g., volumetric, cinematic, chiaroscuro), the camera lens, and the exact environment.
2. End every prompt with: "masterpiece, 8k resolution, highly detailed, high-end editorial photography".
3. CRITICAL: NO TEXT, NO LETTERS, NO TYPOGRAPHY IN THE IMAGE.
MANUSCRIPT:
${JSON.stringify(manuscript.pages)}
Return ONLY a valid JSON object containing exactly ${pagesCount} strings:
{
"image_prompts": [
"Prompt for page 1...",
"Prompt for page 2..."
]
}`;
const artRes = await fetch('https://gen.pollinations.ai/v1/chat/completions', {
method: 'POST',
headers: { 'Authorization': `Bearer ${apiKey}`, 'Content-Type': 'application/json' },
body: JSON.stringify({
model: 'openai',
messages: [{ role: 'user', content: artDirectorPrompt }],
response_format: { type: "json_object" },
temperature: 0.7
})
});
if (!artRes.ok) throw new Error("AGENT 02 FAILED");
const artData = await artRes.json();
const artDirection = parseAIJson(artData.choices[0].message.content);
window.currentImages = [];
for (let i = 0; i < manuscript.pages.length; i++) {
const visualConcept = artDirection.image_prompts[i] || `${topic}, ${style}, masterpiece, 8k`;
statusText.innerText = `[ RENDERER ] SYNTHESIZING VISUALS: PAGE 0${i + 1} OF 0${manuscript.pages.length}...`;
const imgRes = await fetch(`https://gen.pollinations.ai/image/${encodeURIComponent(visualConcept)}?model=flux&width=1280&height=720`, {
headers: { 'Authorization': `Bearer ${apiKey}` }
});
if (!imgRes.ok) throw new Error("RENDERER FAILED ON PAGE " + (i + 1));
window.currentImages.push(URL.createObjectURL(await imgRes.blob()));
}
if (coverConcept) {
statusText.innerText = "[ RENDERER ] SYNTHESIZING COVER ART...";
const coverPrompt = `${coverConcept}, ${style}, minimalist abstract book cover, high-end editorial graphic design, masterpiece, 8k`;
const coverRes = await fetch(`https://gen.pollinations.ai/image/${encodeURIComponent(coverPrompt)}?model=flux&width=1024&height=1024`, {
headers: { 'Authorization': `Bearer ${apiKey}` }
});
if (coverRes.ok) {
window.currentCoverImage = URL.createObjectURL(await coverRes.blob());
} else {
window.currentCoverImage = null;
showGlobalError("Cover Art synthesis failed. Proceeding without cover.");
}
} else {
window.currentCoverImage = null;
}
statusText.innerText = "PIPELINE COMPLETE. TRANSITIONING VIEWPORT.";
// Switch view
mainView.classList.add('hidden');
workspaceContainer.classList.remove('hidden');
renderBookView();
setTimeout(fetchAccountData, 3000);
} catch (err) {
console.error(err);
showGlobalError(`SYSTEM HALTED: ${err.message}`);
} finally {
generateBtn.innerText = "INITIALIZE NEW SEQUENCE";
generateBtn.classList.remove('bg-transparent', 'text-white', 'pointer-events-none');
generateBtn.classList.add('bg-white', 'text-ink');
generateBtn.disabled = false;
statusText.classList.remove('pulse-text');
}
};