-
Notifications
You must be signed in to change notification settings - Fork 2
/
poem-editor.html
1249 lines (1117 loc) · 50.6 KB
/
poem-editor.html
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>
<head>
<title>Subliminal</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
<link rel="stylesheet" href="./styles.css">
<script src="./account.js"></script>
<script src="./polyfill.js"></script>
<script src="./editor-document.js"></script>
<script src="./Other/component-registrar.js"></script>
<script src="./Other/notification-template.js"></script>
<script src="./Other/server.js"></script>
<style>
#main {
position: relative;
box-shadow: gray 0px 0px 2px;
border-radius: 4px;
background-color: var(--background-opaque);
}
#editorCanvas {
display: block;
width: 100%;
height: 100%;
cursor: text;
}
#editorCanvas:focus {
outline: none;
}
.tool {
margin: 1px;
height: 24px;
max-width: 100%;
}
.text-tools {
position: fixed;
top: 146px;
left: 16px;
width: 160px;
padding: 8px;
border-radius: 8px;
background-color: var(--button-transparent);
backdrop-filter: blur(5px);
z-index: 1;
transition: height .5s;
}
.tools-collapsed {
text-align: right;
position: absolute;
right: 16px;
rotate: 180deg;
transform: translateY(4px);
}
.tools-collapsed > svg {
fill: var(--text-colour);
}
.text-tools[collapsed="true"] {
height: 36px;
overflow: hidden;
}
.text-tools[collapsed="true"] .tools-collapsed {
rotate: 0deg;
}
#formattingToolbar {
display: flex;
padding-left: 8px;
padding-right: 8px;
padding-top: 1px;
padding-bottom: 1px;
column-gap: 8px;
max-width: 100%;
overflow-x: visible;
}
#formattingToolbar > div {
height: 32px;
width: 32px;
min-width: 32px;
line-height: 32px;
text-align: center;
border-radius: 4px;
user-select: none;
padding: 1px;
transition: 50ms transform;
}
#formattingToolbar > div:active{
transform: scale(0.98);
}
#formattingToolbar > div > div {
background-color: var(--button-transparent);
border-radius: 4px;
pointer-events: none;
}
.separator {
background: transparent;
width: 1px !important;
min-width: 1px !important;
border-radius: 0px !important;
opacity: 0.1;
margin-left: 8px;
margin-right: 8px;
flex-grow: 1;
}
#poem-tags button {
border-radius: 4px;
margin: 2px;
}
#signCanvas {
background: var(--button-opaque);
width:50%;
height:50%;
border-radius:4px
}
.sign-container {
display:flex;
flex-direction:column;
justify-content:center;
align-content:center;
row-gap:4px;
align-items:center;
user-select:none;
}
.sign-buttons {
display:flex;
column-gap:8px;
width:50%;
}
.sign-buttons > div {
flex-grow: 1;
}
#side {
position: fixed;
top: 130px;
right: 0px;
width: max(16%, 250px);
padding: 8px;
background-color: var(--button-transparent);
backdrop-filter: blur(5px);
box-shadow: 0px 0px 8px grey;
z-index: 2;
height: calc(100% - 146px);
overflow-y: scroll;
transition: .2s width, .2s padding-left, .2s padding-right, .2s box-shadow, .2s height;
}
#side[collapsed] {
width: 0px;
padding-left: 48px;
padding-right: 0px;
overflow: hidden;
box-shadow: none;
border-left: 2px solid gray;
cursor: pointer;
backdrop-filter: blur(5px);
background: transparent;
z-index: 0;
}
#side[collapsed] .side-close-button {
display: none;
}
#side > :not(div[close]) {
display: none;
}
#side[mode="upload"] > div[upload], #side[mode="rhyme"] > div[rhyme], #side[mode="coauthor"] > div[coauthor] {
display: flex;
}
.side-content {
display: flex;
flex-direction: column;
row-gap: 8px;
}
.side-close-button {
width: 80%;
height: 48px;
border: 1px solid gray;
position: relative;
border-radius: 64px;
align-self: center;
margin-top: 32px;
transition: .2s transform;
cursor: pointer;
display: block !important;
}
.side-close-button > svg {
height: calc(100% - 16px);
left: 50%;
position: relative;
transform: translateX(-50%);
fill: gray;
top: 8px;
}
.side-close-button:hover {
transform: scale(1.1);
}
#sideRhymeMatches {
display: flex;
flex-direction: column;
row-gap: 8px;
}
.management-button {
position: relative;
height: 32px;
width: 100%;
margin-top: 8px;
}
.button-tooltip {
left: calc(-100% - 32px) !important;
}
.content-ghost {
position: absolute;
z-index: -1;
opacity: 0.2;
user-select: none;
margin: 0px;
opacity: 0.6;
top: 28px;
left: 10px;
}
/* patches for if the poem is in centre style */
.centre > .content-ghost {
width: 100%;
margin-top: -18px;
}
.tool-header {
background-color: var(--button-opaque);
width: calc(100% - 16px);
display: block;
padding: 8px;
border-radius: 4px;
margin-bottom: 4px;
}
#loadedContainer {
display: flex;
flex-direction: column;
row-gap: 5px;
max-height: 512px;
overflow-y: scroll;
height: 512px;
margin-bottom: 8px;
}
#summaryArea {
min-height: 50px;
width: calc(100% - 16px);
height: 254px;
resize: none;
background: var(--button-opaque);
border: none;
outline: none;
border-radius: 8px;
font-family: Arial, Helvetica, sans-serif;
padding: 8px;
transition: .2s box-shadow;
}
#tagContainer {
background: var(--button-opaque);
border-radius: 8px;
display: grid;
grid-template-columns: 33% 33% 33%;
padding: 8px;
grid-template-rows: auto auto;
grid-gap: 2px;
}
#tagContainer > div {
border-radius: 4px;
height:64px;
background: lightgrey;
padding: 4px;
text-align: center;
transition: .2s color;
}
#tagContainer > div:hover {
background: linear-gradient(45deg, #b92a2a, #e914149c);
color: white;
}
#tagContainer > div[add]:hover {
background: linear-gradient(45deg, #2ab936, #26e9149c);
color: white;
}
#tagContainer, #cWarningContainer, #summaryArea {
transition: .2s box-shadow;
}
#summaryArea:hover, #tagContainer:hover, #cWarningContainer:hover {
box-shadow: 0px 0px 8px darkgray;
}
#builtinFreePopup img {
border-radius: 4px;
max-width: 100%;
}
.background-grid {
display: grid;
grid-template-columns: auto auto auto;
grid-gap: 4px;
}
.background-grid > div {
position: relative;
overflow: hidden;
}
.background-grid > div:hover > div {
top: 50%;
}
.background-grid > div > div {
position: absolute;
top: 100%;
width: 100%;
height: 50%;
overflow: hidden;
transition: .2s top;
background-color: var(--button-opaque);
user-select: none;
pointer-events: none;
}
.suggestions {
width: 192px;
position: absolute;
background: #bdbdbd;
z-index: 3;
border-radius: 4px;
top: 0px;
display: flex;
background-color: var(--button-transparent);
flex-direction: column;
border: 1px solid gray;
overflow: clip;
overflow-y: scroll;
}
.suggestions-item {
padding: 8px;
display: flex;
}
.suggestions-item > span:nth-child(1) {
flex-grow: 1;
}
.suggestions-item > span:nth-child(2) {
font-size: 10px;
opacity: 0.6;
}
.online-editors {
position: fixed;
left: 16px;
display: flex;
flex-direction: column;
}
@media screen and (orientation:portrait) {
#main {
margin-bottom: 48px;
}
.text-tools {
position: inherit !important;
width: calc(100% - 12px);
}
#side {
width: calc(100% - 12px);
height: 60%;
bottom: 0px;
top: inherit;
padding-top: 0px;
}
#side[collapsed] {
height: 0px;
padding-top: 48px;
width: 100%;
padding-left: 0px;
padding-right: 0px;
border-top: 2px solid gray;
border-left: none;
left: 0px;
z-index: 0;
cursor: pointer;
overflow: clip;
}
.side-close-button {
width: 60%;
}
#signCanvas {
width: 100%;
}
.sign-buttons {
width: 100%;
}
#formattingToolbar {
overflow-x: scroll;
}
#loadedContainer {
height: calc(100% - 96px);
max-height: calc(100% - 96px);
}
.separator {
background: var(--text-colour);
}
.background-grid {
grid-template-columns: auto auto;
}
.online-editors {
bottom: 8px;
right: 8px;
left: unset;
z-index: 2;
}
}
</style>
</head>
<body style="max-width: 100%; overflow-x: hidden; overflow-y: scroll;">
<div id="licenseAgreePopup" class="popup" style="display: none;">
<h2>License agreement:</h2>
<p>All content on this site must be licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0, in order to make open source contribution easy, with the underlying source code used to format and display that content licensed under the GNU GPL-3 license. Summaries of these licenses are available at CC BY-NC-SA and GPL-3.</p>
<p>By uploading your work to this site, you give consent for your poem to be licensed under Creative Commons Attribution-NonCommercial-ShareAlike 4.0.</p>
<p>You also agree to allow us permission to store and process your work. We can also accept no responsibility, if you write something that gets you in trouble with people you know, an institution, or local government, you agree that you WILLINGLY chose to upload it here. We accept no responsibility how your work is interpreted, and what consequences may or may not come as a result of it.</p>
<p>You will always be the lone copyright owner of your work, we will never, ever take ownership of what you made from you, and we will always comply if you ask for your poem to be modified, and or taken down from this site.</p>
<p>If you want to, you can <strong>sign</strong> your poem off below.</p>
<div class="sign-container">
<canvas height="96" width="256" id="signCanvas" onmousedown="signCanvasDown(event)" onmousemove="signCanvasDrag(event)" onmouseup="signCanvasUp(event)" ontouchstart="signCanvasDown(event)" ontouchmove="signCanvasDrag(event)" ontouchend="signCanvasUp(event)"></canvas>
<div class="sign-buttons">
<div class="popup-button" style="pointer-events: none; opacity: 0.2;">Smooth</div>
<div class="popup-button" onclick="signContext.clearRect(0, 0, signCanvas.width, signCanvas.height);">Clear</div>
<div class="popup-button" onclick="licenseAgreePopup.style.display = 'none'; signContext.clearRect(0, 0, signCanvas.width, signCanvas.height); uploadCurrent();">Submit</div>
</div>
</div>
<p style="opacity:0.6;"><em>Please don't use a real signature you use on legal documents here. By pressing submit, you agree to all the terms stated above.</em></p>
</div>
<div id="builtinFreePopup" class="popup" style="display: none;">
<h2>Built-in backgrounds:</h2>
<p>These backgrounds are free for you to use to jazz up your poem's look! Drawn and shot by members of the subliminal team.</p>
<div class="background-grid" onclick="
if (event.target == this)
return
applyBuiltinBackground(event.target)
builtinFreePopup.style.display = 'none'
">
<div><img loading="lazy" src="./Resources/Backgrounds/ChilternsWalk.jpg"><div>Taken somewhere in the Chilterns, UK.</div></div>
<div><img loading="lazy" src="./Resources/Backgrounds/FinlandIntersection.jpg"><div>Taken at an intersection somewhere between Uusikaupunki and Helsinki, Finland.</div></div>
<div><img loading="lazy" src="./Resources/Backgrounds/IsoBoy.jpg"><div>A fish that mysteriously disappeared the next day, Island near Uusikaupunki, Finland.</div></div>
<div><img loading="lazy" src="./Resources/Backgrounds/LondonCity.jpg"><div>A bridge to the Tate, London, UK.</div></div>
<div><img loading="lazy" src="./Resources/Backgrounds/LondonStreets.jpg"><div>A day in the city, near Farringdon, London, UK.</div></div>
<div><img loading="lazy" src="./Resources/Backgrounds/Portheleven.jpg"><div>It took standing on a rock in the middle of the sea to get this, Portheleven, UK.</div></div>
<div><img loading="lazy" src="./Resources/Backgrounds/FalmouthShellCave.jpg"><div>A really old shell cave, in Gyllyngdune Gardens, Falmouth, UK.</div></div>
<div><img loading="lazy" src="./Resources/Backgrounds/SnowdoniaPath.jpg"><div>A long path to mount Snowdon (maybe), Wales, UK.</div></div>
<div><img loading="lazy" src="./Resources/Backgrounds/SnowdoniaQuarry.jpg"><div>A spooky snap of quarry taken from a moving vehicle, Snowdonia, Wales, UK.</div></div>
<div><img loading="lazy" src="./Resources/Backgrounds/SnowdoniaQuarry2.jpg"><div>A sunnier view of the massive quarry, Snowdonia, Wales, UK.</div></div>
<div><img loading="lazy" src="./Resources/Backgrounds/SnowdoniaQuarry3.jpg"><div>An atmospheric pee(a)k (punny) of a quarry, Snowdonia, Wales, UK.</div></div>
<div><img loading="lazy" src="./Resources/Backgrounds/UusikaupunkiHorsepower.jpg"><div>This boat certainly has more than 5 horsepower, Island near Uusikaupunki, Finland.</div></div>
<div><img loading="lazy" src="./Resources/Backgrounds/YorkshireMoorRoad.jpg"><div>A long, long road, past field and moor, Yorkshire, UK.</div></div>
<div><img loading="lazy" src="./Resources/Backgrounds/ChaosDrawing.png"><div>Chaos, for those who want to have a bit of zazz around their stuff.</div></div>
<div><img loading="lazy" src="./Resources/Backgrounds/AbbstraktBird.png"><div>Is it a bird? Dog? A secret message of text? All we know is that this mascot is iconic.</div></div>
</div>
</div>
<div id="loadPoemPopup" class="popup" style="display: none/*block;*/">
<h2>Load poem:</h2>
<input type="file" multiple="true" id="poemImportInput" accept=".json, .txt" style="display: none" />
<div id="loadedContainer"></div>
<div class="popup-button" style="margin-bottom: 8px;" onclick="
poemImportInput.click() // TODO: Use new filesystem access API
for (let file of poemImportInput.files) {
let guid = newGuid()
let reader = new FileReader()
reader.onload = () => {
if (file.name.endsWith('.txt')) {
// TODO: Do a simple \n to our format replacement
let poemData = {
summary: '', //meta description
tags: '', //meta keywords
cWarning: false, //content warning
cWarningAdditions: '', //content warning additional notes
poemName: file.name.split('.txt')[0],
poemAuthor: 'Unknown', //poem header title
poemContent: reader.result, //poem html
pageStyle: 'poem-centre', //poem visual format
pageBackground: '' //poem background image
}
localStorage.setItem(guid, JSON.stringify(poemData))
loadKey(guid)
}
else if (file.name.endsWith('.json')) {
localStorage.setItem(guid, reader.result)
loadKey(guid)
}
else {
console.error('Uploaded poem was not a text (.txt) or JSON (.json) file, can not import!')
}
fetchStorage()
loadPoemPopup.style.display = 'none'
}
reader.readAsText(file)
}
">Import from local file</div>
<div class="popup-button" style="margin-top: 8px;" onclick="loadPoemPopup.style.display = 'none';">Done</div>
</div>
<div class="title-blur" style="z-index: 3;">
<div style="display: flex;">
<h2 id="poemName" onpaste="event.preventDefault()" onkeydown="
if(event.key === 'Enter') {
event.preventDefault()
return false
}
" style="display: inline;flex-grow: 1;text-align: right;" contenteditable="true">Click On Me to Start Editing</h2>
<h2 class="centre" style="display: inline;"> - By </h2>
<h2 id="poemAuthor" onpaste="event.preventDefault()" onkeydown="
if(event.key === 'Enter') {
event.preventDefault()
return false
}
" style="display: inline;flex-grow: 1;text-align: left;" contenteditable="true">Click On Me to Start Editing</h2>
</div>
<hr>
<div id="formattingToolbar">
<div class="options-parent" style="width: 72px; min-width: 72px;" onclick="this.children[1].style.display = this.children[1].style.display == 'block' ? 'none' : 'block'" onblur="this.children[1].style.display = 'none'">
<div>File ⯆</div>
<div class="options" style="width: 140px;">
<div onclick="
params.delete('edit')
params.delete('append')
location.href = location.origin + '/poem-editor/' + params.toString()
">Open new</div>
<div onclick="
downloadCurrent()
document.body.appendChild(createFromData('subliminal-notification', { message: 'Successfully downloaded poem data.' }))
">Download poem</div>
<div onclick="
saveCurrent()
document.body.appendChild(createFromData('subliminal-notification', { message: 'Successfully saved poem' }))
">Save poem</div>
<div onclick="loadPoemPopup.style.display = 'block'">Open another</div>
<div onclick="
if (!side.getAttribute('collapsed') && side.getAttribute('mode') == 'upload') {
licenseAgreePopup.style.display = 'block'
}
else {
side.setAttribute('mode', 'upload')
side.removeAttribute('collapsed')
}
">Upload to site</div>
</div>
</div>
<div onclick="format('undo', null)" style="width: 72px; min-width: 72px;"><div>↩ undo</div></div>
<div onclick="format('redo', null)" style="width: 72px; min-width: 72px;"><div>redo ↪</div></div>
<div onclick="editor.addStyle(styleCodes.bold)"><div style="font-weight: bold;">B</div></div>
<div onclick="editor.addStyle(styleCodes.italic)"><div style="font-style: italic;">I</div></div>
<div onclick="editor.addStyle(styleCodes.monospace)"><div style="font-family: monospace;">C</div></div>
<div onclick="editor.addStyle(styleCodes.superscript)"><div>Sup</div></div>
<div onclick="editor.addStyle(styleCodes.subscript)"><div>Sub</div></div>
<div style="position: relative;">
<input class="tool" oninput="
editor.addStyle(styleCodes.colour, parseInt(this.value.slice(1), '16'))
formattingColourRect.style.background = this.value" value="#000000"
style="opacity: 0; position: absolute; left: 0px; top: 0px; width: 100%; height: 100%;" type="color">
<div id="formattingColourRect" style="background-color: black; width: calc(100% - 2px); height: calc(100% - 2px); margin: 1px;border-radius: 4px;"></div>
</div>
<div><div>🖼️</div></div>
<div class="separator"></div>
<div class="options-parent" style="width: 112px; min-width: 112px;" onclick="this.children[1].style.display = this.children[1].style.display == 'block' ? 'none' : 'block'" onblur="this.children[1].style.display = 'none'">
<div>Page layout ⯆</div>
<div class="options">
<div onclick="changePageStyle('poem-centre')">Poem centre</div>
<div onclick="changePageStyle('poem-centre-wide')">Poem wide</div>
<div onclick="changePageStyle('centre')">Centre</div>
</div>
</div>
<div class="options-parent" style="width: 112px; min-width: 112px;" onclick="this.children[1].style.display = this.children[1].style.display == 'block' ? 'none' : 'block'" onblur="this.children[1].style.display = 'none'">
<div>Background ⯆</div>
<div class="options">
<div onclick="document.body.style.background = ''">None</div>
<div onclick="document.body.style.background = `url(\'${prompt('Enter the background image URL')}\')`">From link</div>
<div style="opacity: 0.6;">Upload file</div>
<div onclick="builtinFreePopup.style.display = 'block';">Built-in free</div>
</div>
</div>
<div onclick="
side.removeAttribute('collapsed')
side.setAttribute('mode', 'rhyme')
" style="width: 132px; min-width: 132px;"><div>Rhyme finder ➕</div></div>
<div onclick="
side.removeAttribute('collapsed')
side.setAttribute('mode', 'coauthor')
" style="width: 132px; min-width: 132px;"><div>AI coauthor ➕</div></div>
</div>
<hr>
</div>
<div id="editorsPopup" class="popup" style="display: none;">
<h2>Find someone to invite</h2>
<input type="text" placeholder="Search for user by username">
<div id="editorsResults" style="height: 500px;"></div>
</div>
<div class="online-editors">
Online editors:
<div style="position: relative;margin-bottom: -16px; display: flex;">
<img src="https://t3.ftcdn.net/jpg/03/64/62/36/360_F_364623623_ERzQYfO4HHHyawYkJ16tREsizLyvcaeg.jpg" style="border-radius: 100%;" width="64" height="64">
<div style="padding: 4px;border-radius: 8px;background: linear-gradient(lightblue, blue);color: white;height: 16px;position: relative;align-self: center;">You</div>
</div>
<a href style="margin-top: 24px;" onclick="">+ Invite editor</a>
</div>
<div id="main" class="poem-centre">
<div id="suggestions" class="suggestions" style="display: none;"><!--Rhyme suggestions--></div>
<textarea id="editorInputCatcher" style="position: absolute; left: -10000px; top: -10000px; z-index: -1; opacity: 0; pointer-events: none;" hidden>
<!--I am a hack to allow for mobile virtual keyboard and input because the virtual
keyboard API has stupid restrictions on where you can use .show(). I LoVe BROWSERS!!!!! 🥲🔫🔫🔫:)))-->
</textarea>
<canvas id="editorCanvas" tabindex="-1" virtualkeyboardpolicy="manual" onmousedown="
this['pressed'] = true
editor.clearSelection()
editor.position = editor.realToTextPosition(event.offsetX, event.offsetY, this)
editor.renderCanvasData(this)
editorInputCatcher.focus()
// TODO: handle virtkeyboard geometry in scrolldown
//navigator.virtualKeyboard?.overlaysContent = true
navigator.virtualKeyboard?.show()
" onmousemove="
if (this['pressed']) {
let endPosition = editor.realToTextPosition(event.offsetX, event.offsetY, this)
editor.selection.position = editor.position > endPosition ? endPosition : editor.position
editor.selection.end = editor.position > endPosition ? editor.position : endPosition
editor.renderCanvasData(this)
}
" onmouseup="this['pressed'] = false" onkeydown="
if (event.key == 'Backspace') {
editor.deleteText()
}
else if (event.key == 'Delete') {
editor.deleteText(-1)
}
else if (event.key == 'Enter') {
editor.addNewLine()
// TODO: only scroll down if cursor becomes off the screen
setTimeout(() => window.scrollTo(0, 1e5), 10)
}
else if (event.key == 'Shift' || event.key.length > 1) {
return
}
else if (event.ctrlKey && event.key.toLowerCase() == 'a') {
editor.selectAll()
}
else {
editor.addText(event.key)
}
editor.renderCanvasData(this)
event.preventDefault()
" onblur="editor.renderCanvasData(this, false)" onfocus="editor.renderCanvasData(this)"></canvas>
</div>
<div id="side" class="document-tools" collapsed="false" mode="upload" onclick="
if (side.getAttribute('collapsed'))
side.removeAttribute('collapsed')
">
<div class="side-content" upload>
<div>
<div style="display: flex;flex-direction: row;height: 48px;">
<p style="margin: 0px; align-self: center;">Poem summary:</p>
</div>
<textarea id="summaryArea" type="text" maxlength="160"></textarea>
</div>
<div>
<div style="display: flex;flex-direction: row;height: 48px;">
<p style="margin: 0px; align-self: center;">Poem tags:</p>
</div>
<div id="tagContainer">
<div add="true" style="line-height: 64px;" onclick="addPoemTag(window.prompt('Enter tag you would like to add'))">+</div>
</div>
</div>
<div>
<div style="display: flex;flex-direction: row;height: 48px;">
<p style="margin: 0px; align-self: center;">Content Warning:</p>
</div>
<div id="cWarningContainer" style="background: var(--button-opaque);border-radius: 8px; padding: 8px;">
<input type="checkbox" id="cWarningCheckbox" onclick="cWarningNotesInput.disabled = this.checked ? false : true">
<label for="cWarningCheckbox"> Enabled</label>
<input type="text" id="cWarningNotesInput" class="popup-input" placeholder="Additional warning notes" style="width: calc(100% - 16px); height: 24px;" disabled="">
</div>
</div>
<div class="popup-button" style="flex-grow: inherit;" onclick="
licenseAgreePopup.style.display = 'block'
">Upload to site</div>
</div>
<div class="side-content" rhyme>
<p>Poem Rhyme finder:</p>
<input id="rhymeFinderInput" style="font-size: 16px; " type="text" class="popup-input" placeholder="Enter word">
<p style="opacity: 0.6; font-size: 10px;">Use * to match any word ending, or ?? to match anything within a word, for example pai* (paint, pain), p???t (paint, print)</p>
<div class="options-parent" onclick="this.children[1].style.display = this.children[1].style.display == 'block' ? 'none' : 'block'" onblur="this.children[1].style.display = 'none'">
<div>Word search type ⯆</div>
<div class="options" style="display: none;" onclick="
this.querySelector('[selected]')?.removeAttribute('selected')
if (event.target == this || !rhymeFinderInput.value)
return
event.target.setAttribute('selected', true)
rhymeFinderFind(rhymeFinderInput.value, event.target.dataset.api)
">
<div data-api="ml">Similar meaning</div>
<div data-api="sl">Sound like</div>
<div data-api="sp">Spelled similarly</div>
<div data-api="rel_jjb">Adjectives used to describe</div>
<div data-api="rel_jja">Nouns described by</div>
<div data-api="rel_rhy">Perfect rhymes</div>
<div data-api="rel_nry">Half rhymes</div>
<div data-api="rel_nry">Homophones</div>
<div data-api="rel_ant">Antonyms</div>
<div data-api="rel_nry">Matching consonant</div>
</div>
</div>
<div id="sideRhymeMatches"><!--Container for side rhyme match elements--></div>
<p style="opacity: 0.6; font-size: 10px;">Credits to datamuse for their fantastic API. https://www.datamuse.com/</p>
</div>
<div class="side-content" coauthor>
<p>Poem AI coauthor:</p>
<span style="opacity: 0.6;">Use the subliminal poem writing AI to help cowrite your work!</span>
<div>
Base the AI's results off of:
<div id="sideAiBasisOptions" class="options-parent" style="display: inline;" onclick="this.children[1].style.display = this.children[1].style.display == 'block' ? 'none' : 'block'" onblur="this.children[1].style.display = 'none'">
<div>... ⯆</div>
<div class="options" style="display: none;" onclick="
if (event.target == this)
return
this.parentElement.children[0].innerText = event.target.innerText + ' ⯆'
this.parentElement.setAttribute('basis', event.target.dataset.basis)
">
<div data-basis="my">My work so far</div>
<div data-basis="subliminal">Subliminal poems</div>
</div>
</div>
</div>
<div class="popup-button" style="flex-grow: inherit;" onclick="alert('An error occurred - please try again later')">Start coauthor</div>
</div>
<div class="side-content" close>
<div class="side-close-button" onclick="
side.setAttribute('collapsed', true)
side.setAttribute('mode', 'upload')
event.stopPropagation()
">
<svg xmlns="http://www.w3.org/2000/svg" data-name="icons final" viewBox="0 0 20 20">
<path d="M18.442 2.442l-.884-.884L10 9.116 2.442 1.558l-.884.884L9.116 10l-7.558 7.558.884.884L10 10.884l7.558 7.558.884-.884L10.884 10l7.558-7.558z"></path>
</svg>
</div>
</div>
</div>
<a href="../contents" style="z-index: 1;" class="back"> <- Back</a>
</body>
<script>
const signContext = signCanvas.getContext("2d", { willReadFrequently: true })
const params = new URLSearchParams(document.location.search)
const edit = params.get("edit")
const amend = params.get("amend")
const decoder = new TextDecoder()
const editorScale = 1.5
const editor = new EditorDocument("Click On Me to Start Editing", editorScale, 18)
let currentGuid = ""
let poemTags = []
let network = null
// Make user confirm that they want to leave the page.
window.onbeforeunload = () => true
// format title to subliminal title format, used in poem download files, remove all non-fs friendly chars
let formatDash = (text) => text.trim().toLowerCase()
.replaceAll(" ", "-").replaceAll(/(^\.|[<>:"/\|?*])/g, "")
// Save poem with a unique GUID so that we do not encounter overlaps
let newGuid = () => ([1e7]+-1e3+-4e3+-8e3+-1e11).replace(/[018]/g, char =>
(char ^ crypto.getRandomValues(new Uint8Array(1))[0] & 15 >> char / 4).toString(16))
let pageToHtml = (text) => {
let htmlObject = document.createElement('body')
htmlObject.innerHTML = text
return htmlObject
}
async function fetchStorage() {
// Clear anything that may already be in the laoded container
while (loadedContainer.firstChild) {
loadedContainer.removeChild(loadedContainer.firstChild)
}
// Fetch poems in localstorage
for (let i = 0; i < localStorage.length; i++) {
if (localStorage.key(i).length != 36) {
console.log(`Could not identify localStorage poem with key ${localStorage.key(i)} as a poem.`)
continue
}
let current = JSON.parse(localStorage.getItem(localStorage.key(i)))
let cardEl = document.createElement("div")
cardEl.className = "poem-card"
cardEl.onclick = () => {
loadKey(localStorage.key(i))
loadPoemPopup.style.display= "none"
}
let cardTitle = document.createElement("h4")
cardTitle.textContent = current.poemName
cardEl.appendChild(cardTitle)
let cardPreview = document.createElement("p")
cardPreview.className = "poem-preview"
let pContent
try {
pContent = current.poemContent
}
catch (e) {
continue
}
cardPreview.textContent = pContent
cardEl.appendChild(cardPreview)
loadedContainer.appendChild(cardEl)
}
// If logged in, try to fetch poems from the subliminal cloud
if (localStorage.code) {
let draftPoemIds = await getAccountData().draftPoemIds
for (let id of draftPoemIds) {
let draft = await executeAccountAction(actionType.GetDraft, id).json()
let cardEl = document.createElement("div")
cardEl.className = "poem-card"
cardEl.onclick = async () => {
load(await executeAccountAction(actionType.GetDraft, id).json())
loadPoemPopup.style.display= "none"
}
let cardTitle = document.createElement("h4")
cardTitle.textContent = draft.poemName
cardEl.appendChild(cardTitle)
let cardPreview = document.createElement("p")
cardPreview.className = "poem-preview"
cardPreview.textContent = draft.poemContent
}
}
}
function saveCurrent() {
let saveData = {
summary: summaryArea.value, //meta description
tags: poemTags.toString(), //meta keywords
cWarning: cWarningCheckbox.checked, //content warning
cWarningAdditions: cWarningNotesInput.value, //content warning additional notes
poemName: poemName.innerText,
poemAuthor: poemAuthor.innerText, //poem header title
poemContent: editor.data, //poem html
pageStyle: main.className, //poem visual format
pageBackground: document.body.style.background //poem background image
}
currentGuid ||= newGuid()
localStorage.setItem(currentGuid, JSON.stringify(saveData))
//Refresh load box with latest poem.
fetchStorage()
}
function loadKey(key) {
currentGuid = key
let poemJson = JSON.parse(localStorage.getItem(key))
load(poemJson)
}
function load(poemJson) {
poemTags = []
while (!tagContainer.lastElementChild.getAttribute("add")) {
tagContainer.removeChild(tagContainer.lastElementChild)
}
if (poemJson.tags) {
for(let tag of poemJson.tags?.split(",")) {
addPoemTag(tag)
}
}
summaryArea.value = poemJson.summary ?? ""
cWarningCheckbox.checked = poemJson.cWarning ?? ""
cWarningNotesInput.disabled = !poemJson.cWarning
cWarningNotesInput.value = poemJson.cWarningAdditions ?? ""
poemName.innerText = poemJson.poemName ?? "undefined"
poemAuthor.innerText = poemJson.poemAuthor?? "undefined"
editor.data = poemJson.poemContent ?? "undefined"
document.body.style.background = poemJson.pageBackground ?? ""
changePageStyle(poemJson.pageStyle ?? "poem-centre")
editor.renderCanvasData(editorCanvas)
}
//This itelf is just the poem-editor, content will be moved from here to a new template file, and then downloaded
function downloadCurrent() {
saveCurrent()
let el = document.createElement("a")
el.setAttribute("href", "data:text/html;charset=UTF-8," + encodeURIComponent(localStorage.getItem(currentGuid)))
el.setAttribute('download', formatDash(poemName.innerText) + ".json")
el.style.display = "none"
document.body.appendChild(el)
el.click()
document.body.removeChild(el)
}
// let number = 255
// let gen = number
// let shift = 0
// gen ^= 1 << (7 - shift)
// We pad the leading number because JS numbers can't have leading zeros
// console.log(number.toString(2).padStart(8, 0) + " : " + gen.toString(2).padStart(8, 0) + " -> " + gen)
function getSignCanvasBits() {
let bufWidth = signCanvas.width / 8, bufHeight = signCanvas.height
let buffer = new Uint8Array(bufWidth * bufHeight).fill(255) //11111111
let data = signContext.getImageData(0, 0, signCanvas.width, signCanvas.height, { colorSpace: "srgb" }).data
for (let h = 0; h < signCanvas.height; h++) {
for (let w = 0; w < signCanvas.width; w++) {
let byteI = Math.floor((signCanvas.width * h + w) / 8)
let shiftI = w % 8
// We use 4n (n = pixel iteration we are looking at) - 1 to get where 255 (for black) would be.
// We set the bit to zero if the color at this position is not black
if (data[4 * (signCanvas.width * h + w) + 3] == 0) buffer[byteI] ^= 1 << (7 - shiftI)
}
}
return buffer
}
async function uploadCurrent() {
saveCurrent()
let loadObject = JSON.parse(localStorage.getItem(currentGuid))
//Only apply if they actually used the signature
let signBits = getSignCanvasBits()
if (!signBits.every(item => item === 0)) {
loadObject.signature = window.btoa(String.fromCharCode(...new Uint8Array(signBits)))
}
await upload(loadObject)
}
async function upload(poemJson) {
if (await isLoggedIn()) {
poemJson.code = localStorage.accountCode
}
fetch(serverBaseAddress + "/PurgatoryUpload", {
method: "POST",
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(poemJson)
})
.then(res => {
if (!res.ok) {
console.error("Cricical error in uploading" + res)