-
Notifications
You must be signed in to change notification settings - Fork 16
/
exolve-m.js
9454 lines (8993 loc) · 310 KB
/
exolve-m.js
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
/*
MIT License
Copyright (c) 2019 Viresh Ratnakar
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
The latest code and documentation for Exolve can be found at:
https://github.com/viresh-ratnakar/exolve
*/
/**
* The Exolve code creates only the following names at global scope:
*
* - Exolve
* - createExolve
* - createPuzzle (deprecated).
* - exolvePuzzles
*
* - The most generic way to create a puzzle is with "new Exolve(...)".
* - The createExolve() function is a covenient wrapper.
* - The createExolve() function looks for and calls the function
* customizeExolve() if it exists (passing it the created puzzle).
* - The createPuzzle() function is similar to createExolve(), and
* is deprecated (as the name may conflict with some other code).
* - All HTML ids/class names begin with "xlv"
*/
/**
* This is the global object in which *all* Exolve puzzles rendered on a single
* web page are stored as properties, with the puzzle IDs being the keys.
*/
var exolvePuzzles;
/**
* Constructor to create an Exolve puzzle.
*
* puzzleSpec is a string that contains the puzzle specs in the Exolve plain
* text format.
* containerId is the optional HTML id of the container element in which you
* want to create this puzzle. If empty, the puzzle is created inside
* the element with id "exolve" if it exists (and its id is changed to
* exolve<N> in that case, where <N> is the index of this puzzle among
* all the pages on the page). If containerId is empty and there is no
* element with id "exolve", the puzzle is created at the end of the
* web page.
* customizer is an optional function that will get called after the puzzle
* is set up. The Exolve object will be passed to the function.
* provideStateUrl should be set to true if you also want to provide a URL
* that includes the current state and can be bookmarked or shared. Note
* that the puzzle state is always attempted to be saved in local storage.
* visTop should be set to the height of any sticky/fixed position elements
* at the top of the page (normally just 0).
* maxDim If non-zero, use this as the suggested max size of the container
* in px.
* notTemp If false, state is not saved in local storage and some event
* listeners are not created. Useful for creating temporary/preview puzzles.
* Note that if you create a normal (notTemp=true) puzzle and your web page
* is going to destroy it for some reason during its normal course
* (ExolvePlayer does this, for example), then you should call destroy() on
* the puzzle object before removing all references to it. This will remove
* listeners for 'resize' and printing events, for example.
*/
function Exolve(puzzleSpec,
containerId='',
customizer=null,
provideStateUrl=true,
visTop=0,
maxDim=0,
notTemp=true) {
this.VERSION = 'Exolve v1.59 December 22, 2024';
this.id = '';
this.puzzleText = puzzleSpec;
this.containerId = containerId;
this.customizer = customizer;
this.provideStateUrl = provideStateUrl;
this.notTemp = notTemp;
this.gridWidth = 0;
this.gridHeight = 0;
this.layers3d = 1;
this.h3dLayer = 0;
this.angle3d = 55;
this.skew3d = `skewX(${this.angle3d - 90}deg)`;
this.offset3d = 0;
this.ratio3d = 0.75;
this.cellW = 0;
this.cellH = 0;
this.squareDim = 0;
this.topClueClearance = 0;
this.credits = [];
this.questionTexts = [];
/**
* exolve-options that will fix any warnings that get triggered
* for this puzzle.
*/
this.optionsForWarningFixes = [];
this.NINA_COLORS = [
'blue',
'green',
'aqua',
'fuchsia',
'yellow',
'crimson',
'limegreen',
'royalblue',
'mediumturquoise',
'mediumorchid',
'goldenrod',
'red',
];
// Each nina will be object with props: colour and list (an array containing
// location [i,j] pairs and/or span class names).
this.ninas = [];
// For span-class-specified ninas, ninaClassElements[] stores the elements
// along with the colours to apply to them when showing the ninas.
this.ninaClassElements = []
this.forcedSeps = {
'force-hyphen-right': [],
'force-hyphen-below': [],
'force-bar-right': [],
'force-bar-below': [],
}
this.colourfuls = [];
this.ninaLines = [];
this.colourLines = [];
this.grid = [];
this.clues = {};
this.title = null;
this.setter = null;
this.email = null;
this.notes = {
'clues': {},
'solved': {},
'counter': 0,
};
this.submitURL = null;
this.submitKeys = [];
this.hasDgmlessCells = false;
this.hasUnsolvedCells = false;
this.hasReveals = false;
this.hasAcrossClues = false;
this.hasDownClues = false;
this.hasZ3dClues = false;
this.hasNodirClues = false;
this.reversals = {};
this.usedReversals = {};
// Clues labeled non-numerically (like [A] a clue...) use this to create a
// unique clueIndex.
this.nextNonNumId = 1;
this.offNumClueIndices = {};
// Objects with keys being JSON arrays of cells, mapping to orphan clues
// they belong to, for revealing.
this.cellsToOrphan = {};
this.szCellsToOrphan = 0;
this.visTop = visTop;
this.maxDim = maxDim;
this.cluesBoxWidth = 0;
this.MAX_GRID_SIZE = 100;
this.GRIDLINE = 1;
this.BAR_WIDTH = 3;
this.BAR_WIDTH_BY2 = 2;
this.SEP_WIDTH = 2;
this.SEP_WIDTH_BY2 = 1.5;
this.NUMBER_START_X = 2;
this.MAX_REBUS_SIZE = 20;
this.answersList = [];
this.revelationList = [];
this.inClueAnnoReveals = {};
// State of navigation
this.currRow = -1;
this.currCol = -1;
this.currDir = 'A';
this.currClueIndex = null;
this.usingGnav = false;
this.lastOrphan = null;
this.activeCells = [];
this.activeClues = [];
this.showingNinas = false;
// Couple of vars to get long click on check/reveal to use just a cell.
this.cellLightToggleTimer = null;
this.cellNotLight = false;
/**
* Multi-char-entry related vars:
*/
this.multiLetter = false;
this.multiLetterCellRow = -1;
this.multiLetterCellCol = -1;
this.lastKeyHadShift = false;
/**
* If exolve-alternatives groups are present, this object captures the
* alternative groups. The altsSpecs array is used during the first
* parse to remember all the exolve-alternatives lines (need to know
* dimensions and grid structure before they can be parsed and checked).
*/
this.alts = null;
this.altsSpecs = [];
this.numCellsToFill = 0;
this.numCellsFilled = 0;
this.numCellsPrefilled = 0;
this.knownCorrect = false;
this.knownIncorrect = false;
this.allClueIndices = [];
this.PLACEHOLDER_BLANK_LEN = 15;
this.BLOCK_CHAR = '⬛';
// If someone wants to use 0/1/./? using allow-chars, we cannot use them in
// the state char space as they have special meanings there. Use unprintable
// characters:
this.SPECIAL_STATE_CHARS = {
'0': String.fromCharCode(1),
'1': String.fromCharCode(2),
'.': String.fromCharCode(3),
'?': String.fromCharCode(4)
};
this.SPECIAL_DISPLAY_CHARS = {};
for (let x in this.SPECIAL_STATE_CHARS) {
this.SPECIAL_DISPLAY_CHARS[this.SPECIAL_STATE_CHARS[x]] = x;
};
this.scriptRE = null;
this.scriptLowerCaseRE = null;
/**
* Font details for clues text.
* If fontFamily/fontSize are not set, the CSS rule sets them to serif/16px.
*/
this.fontFamily = '';
this.fontSize = '';
this.smartColoring = true;
this.lightColorScheme = {
'active': 'mistyrose',
'active-clue': 'mistyrose',
'anno': 'darkgreen',
'hint': 'dodgerblue',
'hint-bulb': 'dodgerblue',
'arrow': 'white',
'background': 'black',
'button': '#4caf50',
'button-hover': 'darkgreen',
'button-text': 'white',
'caret': 'gray',
'cell': 'white',
'circle': 'gray',
'circle-input': 'gray',
'currclue': 'white',
'def-underline': '#3eb0ff',
'imp-text': 'darkgreen',
'input': '#ffb6b4',
'light-label': 'black',
'light-label-input': 'black',
'light-text': 'black',
'light-text-input': 'black',
'orphan': 'linen',
'overwritten-end': '#bb00bb',
'overwritten-start': '#ff00ff',
'prefill': 'blue',
'separator': 'blue',
'small-button': 'inherit',
'small-button-hover': 'lightpink',
'small-button-text': 'darkgreen',
'solution': 'dodgerblue',
'solved': 'dodgerblue',
};
this.darkColorScheme = {
...this.lightColorScheme,
'currclue': 'black',
'active-clue': '#663366',
'orphan': '#663300',
'anno': 'lightgreen',
'imp-text': 'lightgreen',
'small-button-hover': '#330066',
'small-button-text': 'lightgreen',
}
this.colorScheme = this.lightColorScheme;
this.nextLine = 0;
this.sectionLines = {};
this.STATE_SEP = 'xlv';
this.STATES_SEP = 'xxllvv'; // xxllvv<id1>......xxllvv<id2>.....
this.textLabels = {
'clear': 'Clear this',
'clear.hover': 'Clear highlighted clues and squares. Clear crossers ' +
'from full clues with a second click. Shortcut: Ctrl-q.',
'clear-all': 'Clear all!',
'clear-all.hover': 'Clear everything! A second click clears all ' +
'placeholder entries in clues without known cells. Shortcut: Ctrl-Q.',
'check': 'Check this',
'check.hover': 'Erase mistakes in highlighted cells. Long-click to ' +
'check just the current cell.',
'checkcell': 'Check cell',
'checkcell.hover': 'Erase the current cell if it\'s incorrect.',
'check-all': 'Check all!',
'check-all.hover': 'Erase all mistakes. Reveal any available annos if ' +
'no mistakes.',
'copy-notes': 'Copy notes',
'copy-notes.hover': 'Copy these notes to the clipboard, including any formatting.',
'email-notes': 'Email notes',
'email-notes.hover': 'Compose an email containing these notes as plain text. ' +
'You can edit the draft before sending.',
'email-notes-recipients.hover': ' Draft recipient(s): ',
'reveal': 'Reveal this',
'reveal.hover': 'Reveal highlighted clue/cells. Long-click to reveal ' +
'just the current cell.',
'revealcell': 'Reveal cell',
'revealcell.hover': 'Reveal the solution letter in the current cell.',
'show-ninas': 'Show ninas',
'show-ninas.hover': 'Show ninas hidden in the grid/clues.',
'hide-ninas': 'Hide ninas',
'hide-ninas.hover': 'Hide ninas shown in the grid/clues.',
'reveal-all': 'Reveal all!',
'reveal-all.hover': 'Reveal all solutions, available annos, answers, ' +
'notes!',
'hint-bulb.hover': 'Click to see a hint.',
'hint-bulb-another.hover': 'Click to see another hint.',
'hint.hover': 'Click to hide hints.',
'hint': 'Hint',
'hint-bulb': '💡',
'submit': 'Submit',
'submit.hover': 'Submit the solution!',
'setter-by': 'By',
'curr-clue-prev': '‹',
'curr-clue-prev.hover': 'Previous clue.',
'curr-clue-next': '›',
'curr-clue-next.hover': 'Next clue.',
'squares-filled': 'Squares filled',
'across-label': 'Across',
'down-label': 'Down',
'3d-ac-label': 'Across & Back',
'3d-aw-label': 'Away & Towards',
'3d-dn-label': 'Down & Up',
'nodir-label': 'Other',
'tools-link': 'Exolve',
'tools-link.hover': 'Crossword software: ' +
this.VERSION + ': Show/hide panel with info/help and links to report ' +
'a bug, manage storage, etc.',
'tools-msg': `
<p>Control keys:</p>
<ul>
<li><b>Tab/Shift-Tab:</b>
Jump to the next/previous clue.</li>
<li><b>Enter, Click/Tap:</b> Toggle current direction.</li>
<li><b>Arrow keys:</b>
Move to the nearest light square in that direction.</li>
<li><b>Ctrl-q:</b> Clear this, <b>Ctrl-Q:</b> Clear All!,
<b>Ctrl-B:</b> Print crossword, <b>Ctrl-/:</b> Jump to/back-from
notes, <b>Ctrl-*:</b> Mark clue as fave in notes, adding a *
prefix.</li>
<li><b>Delete:</b>
Clear the contents of the current square.</li>
<li><b>Spacebar:</b>
Place block in the current square if it's diagramless.</li>
<li><b>Double-click or Shift+Letter:</b>
If the puzzle has rebus cells, this is the way to enter
multiple letters into a single cell.</li>
</ul>
<p>
Overwritten letters will briefly be coloured like
<b style="background:white;color:${this.colorScheme['overwritten-start']}">this</b>
(before fading back to
<b style="background:white;color:${this.colorScheme['light-text']}">this</b>)
just to draw your attention so that you can fix any accidental
typing errors.
</p>`,
'alts.hover': 'This is an alternative solution to the clue. Clicking on it ' +
'will set any currently visible letters in it to this variant. If ' +
'the setter has created an alternative solution group with more than one ' +
'cell (group numbers are shown in superscripts of solution variants) ' +
'then clicking will set all revealed visible letters in the group to ' +
'reflect this variant. ',
'crossword-id': 'Crossword ID',
'notes': 'Notes',
'notes.hover': 'Show/hide notes panel.',
'notes-help': '<li>Ctrl-/ takes you to the current clue\'s notes ' +
'(or overall notes) and back (if already there).</li><li>Ctrl-* ' +
'adds a * prefix to the current clue\'s notes.</li><li>Hovering ' +
'over a clue\'s notes shows the clue as a tooltip.</li>',
'jotter': 'Jotter',
'jotter.hover': 'Show/hide a jotting pad that also lets you try out anagrams and subtractions.',
'jotter-text.hover': 'You can shuffle letters by clicking above. If you enter something like [Alphabet - betas =] then it will be replaced by [lpha - s] (subtraction of common letters).',
'maker-info': 'Exolve-maker info',
'manage-storage': 'Manage local storage',
'manage-storage.hover': 'View puzzle Ids for which state has been saved. ' +
'Delete old saved states to free up local storage space if needed.',
'manage-storage-close': 'Close (local storage)',
'manage-storage-close.hover': 'Close the local storage management panel.',
'exolve-link': 'Exolve-on-GitHub',
'exolve-link.hover': 'Visit the Exolve open-source repository on GitHub, with a ' +
'detailed user guide.',
'report-bug': 'Report-Bug',
'report-bug.hover': 'Report a bug on the GitHub page for Exolve',
'exolve-exet-etc': 'Community',
'exolve-exet-etc.hover': 'Exolve-Exet-Etc: a Google Group to get release updates, discuss usage and features for Exolve, Exet, etc.',
'webifi': 'Webifi',
'webifi.hover': 'Toggle Webifi, the interactive-fictionesque text/audio interface.',
'saving-msg': 'Your entries are auto-saved in the browser\'s local ' +
'storage.',
'saving-bookmark': 'You can share the state using this link:',
'saving-url': 'URL',
'shuffle': 'Jotting pad: (click here to shuffle)',
'shuffle.hover': 'Shuffle selected text (or all text, if none selected).',
'across-letter': 'a',
'back-letter': 'b',
'down-letter': 'd',
'up-letter': 'u',
'3d-ac': 'ac',
'3d-ba': 'ba',
'3d-aw': 'aw',
'3d-to': 'to',
'3d-dn': 'dn',
'3d-up': 'up',
'mark-clue.hover': 'Click to forcibly mark/unmark as solved.',
'curr-clue-prev': '‹',
'curr-clue-prev.hover': 'Previous clue.',
'curr-clue-next': '›',
'curr-clue-next.hover': 'Next clue.',
'placeholder.hover': 'You can record your solution here before copying ' +
'to squares.',
'placeholder-copy': '⇲',
'placeholder-copy.hover': 'Copy into currently highlighted squares.',
'confirm-clear-all': 'Are you sure you want to clear every entry!?',
'confirm-clear-all-orphans1': 'Are you sure you want to clear every ' +
'entry!? (The placeholder entries will not be cleared. To clear ' +
'the placeholders, click on clear-all again after clearing the grid.)',
'confirm-clear-all-orphans2': 'Are you sure you want to clear every ' +
'entry including all the placeholder entries!?',
'confirm-check-all': 'Are you sure you want to clear mistakes everywhere!?',
'confirm-mismatched-copy': 'Are you sure you want to do this mismatched ' +
'copy (#letters-from : #squares-to)? ',
'confirm-show-ninas': 'Are you sure you want to reveal the nina(s)!?',
'confirm-reveal-all': 'Are you sure you want to reveal the whole ' +
'solution!?',
'confirm-submit': 'Are you sure you are ready to submit!?',
'confirm-incomplete-submit': 'Are you sure you want to submit an ' +
'INCOMPLETE solution!?',
'confirm-delete-id': 'Delete puzzle state for puzzle id',
'confirm-delete-older': 'Delete all puzzle states saved before',
'confirm-state-override': 'Do you want to override the state saved in ' +
'this device with the state found in the URL?',
'warnings-label': 'Please fix, or use "ignore-unclued" / ' +
'"ignore-enum-mismatch" <a href="https://github.com/viresh-ratnakar/' +
'exolve/blob/master/README.md#exolve-option">options</a>:',
'warnings.hover': 'Issues detected: click on [×] to dismiss.',
'print': 'Print',
'print.hover': 'Show/hide panel for printing or creating PDFs.',
'print-heading': 'Print or create a PDF:',
'print-size': 'Page size:',
'print-only-grid': 'Only grid',
'print-only-clues': 'Only clues',
'print-all': 'Grid and clues',
'print-margin': 'Margin (inches, up to 4 numbers):',
'print-margin.hover': 'The numbers are in inches, and are for top, right, bottom, ' +
'left. Missing numbers are taken from symmetry or last available values.',
'print-font': 'Font size:',
'print-font-normal': 'Normal',
'print-font-large': 'Large',
'print-font-xlarge': 'Extra Large',
'print-font-small': 'Small',
'print-font-other': 'Other',
'print-crossword': 'Print crossword',
'print-crossword.hover': 'Print just this crossword, hiding any content outside it (Ctrl-B).',
'print-page': 'Print page',
'print-page.hover': 'Print the whole page (Ctrl-p or Cmd-p).',
'print-page-wysiwyg': 'Print wysiwyg',
'print-page-wysiwyg.hover': 'Print the whole page without reformatting the crossword.',
'print-title': 'Title',
'print-setter': 'Setter',
'print-preamble': 'Preamble',
'print-explanations': 'Explanations',
'print-copyright': 'Copyright',
'print-questions': 'Questions',
'print-header': 'Extra header',
'print-header.hover': 'Any HTML you provide here will be inserted in the beginning of the puzzle frame before printing',
'print-footer': 'Extra footer',
'print-footer.hover': 'Any HTML you provide here will be inserted at the end of the puzzle frame before printing',
'print-grid-scale': 'Force grid scale to:',
'print-grid-scale.hover': 'Instead of figuring out a good grid-scale factor (from width/height/etc.), force it to this value.',
'print-inksaver': 'Inksaver',
'print-url-qrcodes': 'Convert Explanations URLs to QR codes',
'print-url-qrcodes-heading': 'Links',
'print-qrcode': 'Add QR code for this puzzle\'s URL',
'print-qrcode-details': 'The QR code (rendered to the right) will be printed to the ',
'print-qrcode-in-botleft': 'bottom-left of the page',
'print-qrcode-in-botright': 'bottom-right of the page',
'print-qrcode-cta-label': 'Call to action',
'print-qrcode-cta': 'Online version',
'print-qrcode-size': 'QR code size:',
'show-notes-seq': 'Show clue-solving sequence:',
'show-notes-entries': 'Show entered solutions:',
'show-notes-times': 'Show clue-solving times:',
};
/**
* The URL prefix for loading scripts. Either is empty, or ends with '/'.
*/
this.scriptUrlBase = '';
const scriptTags = document.getElementsByTagName('script');
for (let i = 0; i < scriptTags.length; i++) {
const src = scriptTags[i].src;
const loc = src.lastIndexOf('/exolve-m.js');
if (loc >= 0) {
this.scriptUrlBase = src.substring(0, loc + 1);
break;
}
}
/** Printing-related */
this.printingChanges = null;
this.printAsIs = false;
this.printOnlyCrossword = false;
// Variables set by exolve-option
this.extractionSlots = 0;
this.hideInferredNumbers = false;
this.cluesPanelLines = -1;
this.allowChars = null;
this.hideCopyPlaceholders = false;
this.addSolutionToAnno = true;
this.offsetLeft = 0;
this.offsetTop = 0;
this.language = '';
this.languageScript = '';
this.langMaxCharCodes = 1;
this.hasRebusCells = false;
this.ignoreUnclued = false;
this.ignoreEnumMismatch = false;
this.showCellLevelButtons = false;
this.printCompleted3Cols = false;
this.printIncomplete2Cols = false;
this.noNinaButton = false;
this.useWebifi = false;
this.hltOverwrittenMillis = 5000;
this.colourOnlyCellBottom = false;
this.createPuzzle();
}
/**
* Do clean-up: remove from exolvePuzzles[], remove window listeners.
* This only needs to be called if you have a web page from which
* you destroy and create new Exolve puzzles repeatedly (such as
* ExolvePlayer).
*/
Exolve.prototype.destroy = function() {
if (this.frame) {
this.frame.innerHTML = '';
this.frame = null;
}
if (exolvePuzzles && this.id && exolvePuzzles[this.id]) {
delete exolvePuzzles[this.id];
}
if (this.windowListeners) {
for (let e in this.windowListeners) {
window.removeEventListener(e, this.windowListeners[e]);
}
this.windowListeners = {};
}
}
/**
* Create the basic HTML structure.
* Set up globals, version number and user agent in bug link.
*/
Exolve.prototype.init = function() {
this.parseOverall();
this.parseRelabel();
this.computeGridSize(this.maxDim);
const SPECIAL_ID = '42xlvIndex42';
if (this.id && this.id == SPECIAL_ID) {
this.throwErr('Puzzle id cannot be: ' + this.id);
}
if (!exolvePuzzles) {
exolvePuzzles = {};
exolvePuzzles[SPECIAL_ID] = 1;
}
this.index = exolvePuzzles[SPECIAL_ID]++;
this.prefix = 'xlv' + this.index;
const basicHTML = `
<div class="xlv-frame xlv-flex-col" tabindex="-1" id="${this.prefix}-frame">
<h2 id="${this.prefix}-title" class="xlv-title"></h2>
<div id="${this.prefix}-setter" class="xlv-setter"></div>
<div id="${this.prefix}-preamble" class="xlv-preamble"></div>
<div id="${this.prefix}-clear-area" class="xlv-clear-area"></div>
<div id="${this.prefix}-grid-and-clues" class="xlv-grid-and-clues-flex">
<div id="${this.prefix}-grid-panel" class="xlv-grid-panel">
<div id="${this.prefix}-grid-parent-centerer"
class="xlv-grid-parent-centerer">
<div id="${this.prefix}-curr-clue" class="xlv-curr-clue"
style="display:none">
<div id="${this.prefix}-curr-clue-inner"
class="xlv-curr-clue-inner">
</div>
</div>
<div id="${this.prefix}-grid-parent" class="xlv-grid-parent">
<svg id="${this.prefix}-grid" class="xlv-grid"
zoomAndPan="disable"></svg>
<div id="${this.prefix}-grid-input-wrapper"
class="xlv-grid-input-wrapper"
style="display:none;left:0;top:0"><input
id="${this.prefix}-grid-input" type="text"
autocomplete="off" spellcheck="false"
class="xlv-grid-input xlv-cell-text"/></div>
<div id="${this.prefix}-nina-group"
style="display:none;left:0;top:0"></div>
<div id="${this.prefix}-colour-group"
style="display:none;left:0;top:0"></div>
</div> <!-- xlv-grid-parent -->
</div> <!-- xlv-grid-parent-centerer -->
<div id="${this.prefix}-controls-etc" class="xlv-controls-etc">
<div id="${this.prefix}-controls" class="xlv-controls xlv-wide-box">
<div id="${this.prefix}-button-row-1" class="xlv-controls-row">
<button id="${this.prefix}-clear"
class="xlv-button">${this.textLabels['clear']}</button>
<button id="${this.prefix}-clear-all"
class="xlv-button">${this.textLabels['clear-all']}</button>
<button id="${this.prefix}-check" class="xlv-button"
style="display:none">${this.textLabels['check']}</button>
<button id="${this.prefix}-check-all" class="xlv-button"
style="display:none">${this.textLabels['check-all']}</button>
</div> <!-- xlv-button-row-1 -->
<div id="${this.prefix}-buttons-extra-row" class="xlv-controls-row"
style="display:none">
<button id="${this.prefix}-checkcell" class="xlv-button"
style="display:none">${this.textLabels['checkcell']}</button>
<button id="${this.prefix}-revealcell" class="xlv-button"
style="display:none">${this.textLabels['revealcell']}</button>
</div>
<div id="${this.prefix}-button-row-2" class="xlv-controls-row">
<button id="${this.prefix}-reveal" class="xlv-button"
style="display:none">${this.textLabels['reveal']}</button>
<button id="${this.prefix}-ninas" class="xlv-button"
style="display:none">${this.textLabels['show-ninas']}</button>
<button id="${this.prefix}-reveal-all" class="xlv-button"
style="display:none">${this.textLabels['reveal-all']}</button>
</div> <!-- xlv-button-row-2 -->
</div> <!-- xlv-controls -->
<div id="${this.prefix}-errors" class="xlv-errors"></div>
<div id="${this.prefix}-status" class="xlv-status">
<span id="${this.prefix}-squares-filled"
>${this.textLabels['squares-filled']}</span>:
<span id="${this.prefix}-status-num-filled">0</span>/<span
id="${this.prefix}-status-num-total"></span>
</div> <!-- xlv-status -->
<div id="${this.prefix}-small-print"
class="xlv-wide-box xlv-small-print">
<a id="${this.prefix}-tools-link" href="" class="xlv-link"
title="${this.textLabels['tools-link.hover']}"
>${this.textLabels['tools-link']}</a>
<a id="${this.prefix}-print" href="" class="xlv-link"
title="${this.textLabels['print.hover']}"
>${this.textLabels['print']}</a>
<a id="${this.prefix}-notes" href="" class="xlv-link"
title="${this.textLabels['notes.hover']}"
>${this.textLabels['notes']}</a>
<a id="${this.prefix}-jotter" href="" class="xlv-link"
title="${this.textLabels['jotter.hover']}"
>${this.textLabels['jotter']}</a>
<a id="${this.prefix}-webifi" href="" class="xlv-link"
title="${this.textLabels['webifi.hover']}"
>${this.textLabels['webifi']}</a>
<span class="xlv-copyright" id="${this.prefix}-copyright"></span>
<div id="${this.prefix}-tools" class="xlv-toggleable"
style="display:none">
<p id="${this.prefix}-id" class="xlv-metadata">
<b>${this.textLabels['crossword-id']}:
<span id="${this.prefix}-id-span"><span></b>
</p>
<p id="${this.prefix}-metadata" class="xlv-metadata">
${this.VERSION}
<a id="${this.prefix}-report-bug" class="xlv-link"
title="${this.textLabels['report-bug.hover']}"
href="https://github.com/viresh-ratnakar/exolve/issues/new"
>${this.textLabels['report-bug']}</a>
<a id="${this.prefix}-exolve-link" class="xlv-link"
title="${this.textLabels['exolve-link.hover']}"
href="https://github.com/viresh-ratnakar/exolve"
>${this.textLabels['exolve-link']}</a>
<a id="${this.prefix}-community-link" class="xlv-link"
title="${this.textLabels['exolve-exet-etc.hover']}"
href="https://groups.google.com/g/exolve-exet-etc"
>${this.textLabels['exolve-exet-etc']}</a>
</p>
<p>
<button id="${this.prefix}-manage-storage"
class="xlv-small-button"
title="${this.textLabels['manage-storage.hover']}">
${this.textLabels['manage-storage']}
</button>
<div id="${this.prefix}-storage-list"
class="xlv-storage-list"
style="display:none">
</div>
</p>
<div id="${this.prefix}-tools-msg">
${this.textLabels['tools-msg']}
</div>
<p id="${this.prefix}-saving" class="xlv-saving">
<span id="${this.prefix}-saving-msg">
${this.notTemp ? this.textLabels['saving-msg'] : ''}
</span>
</p>
</div>
<div id="${this.prefix}-print-settings"
class="xlv-print-settings xlv-toggleable" style="display:none">
<p>
<b>${this.textLabels['print-heading']}</b>
<select name="${this.prefix}-print-scope" id="${this.prefix}-print-scope">
<option value="all">${this.textLabels['print-all']}</option>
<option value="only-grid">${this.textLabels['print-only-grid']}</option>
<option value="only-clues">${this.textLabels['print-only-clues']}</option>
</select>
<input id="${this.prefix}-print-inksaver" type="checkbox">
</input>
${this.textLabels['print-inksaver']}
</p>
<p>
<div>
${this.textLabels['print-font']}
<select name="${this.prefix}-print-font" id="${this.prefix}-print-font">
<option value="18px">${this.textLabels['print-font-normal']}</option>
<option value="22px">${this.textLabels['print-font-large']}</option>
<option value="26px">${this.textLabels['print-font-xlarge']}</option>
<option value="14px">${this.textLabels['print-font-small']}</option>
<option value="other">${this.textLabels['print-font-other']}</option>
</select>
<input class="xlv-input" id="${this.prefix}-print-font-inp"
name="${this.prefix}-print-font-inp" size="5" value="18px">
</input>
</div>
<div>
${this.textLabels['print-size']}
<select name="${this.prefix}-page-size" id="${this.prefix}-page-size">
<option value="letter">Letter: 8.5in x 11in</option>
<option value="A4">A4: 210mm x 297mm</option>
<option value="A3">A3: 297mm x 420mm</option>
<option value="A5">A5: 148mm x 210mm</option>
<option value="B4">B4: 250mm x 353mm</option>
<option value="B5">B5: 176mm x 250mm</option>
<option value="6in 9in">Book: 6in x 9in</option>
<option value="legal">Legal: 8.5in x 14in</option>
<option value="ledger">Ledger: 11in x 17in</option>
</select>
</div>
<div title="${this.textLabels['print-margin.hover']}">
${this.textLabels['print-margin']}
<input class="xlv-input" id="${this.prefix}-page-margins"
name="${this.prefix}-page-margins" size="25" value="0.5 0.5 0.5 0.5">
</input>
</div>
<div>
Include if visible:
<table>
<tr>
<td>
<input id="${this.prefix}-print-title"
checked=true type="checkbox">
</input>
${this.textLabels['print-title']}
</td>
<td>
<input id="${this.prefix}-print-setter"
checked=true type="checkbox">
</input>
${this.textLabels['print-setter']}
</td>
<td>
<input id="${this.prefix}-print-preamble"
checked=true type="checkbox">
</input>
${this.textLabels['print-preamble']}
</td>
</tr>
<tr>
<td>
<input id="${this.prefix}-print-explanations"
checked=true type="checkbox">
</input>
${this.textLabels['print-explanations']}
</td>
<td>
<input id="${this.prefix}-print-copyright"
checked=true type="checkbox">
</input>
${this.textLabels['print-copyright']}
</td>
<td>
<input id="${this.prefix}-print-questions"
checked=true type="checkbox">
</input>
${this.textLabels['print-questions']}
</td>
</tr>
</table>
</div>
<div>
<table>
<tr>
<td title="${this.textLabels['print-header.hover']}">
${this.textLabels['print-header']}:<br>
<textarea id="${this.prefix}-print-header"
name="${this.prefix}-print-header" rows="2">
</textarea>
</td>
<td title="${this.textLabels['print-footer.hover']}">
${this.textLabels['print-footer']}:<br>
<textarea id="${this.prefix}-print-footer"
name="${this.prefix}-print-footer" rows="2">
</textarea>
</td>
</tr>
<tr>
<td colspan="2" title="${this.textLabels['print-grid-scale.hover']}">
${this.textLabels['print-grid-scale']}
<input class="xlv-input" id="${this.prefix}-print-grid-scale"
name="${this.prefix}-grid-scale" size="5" value="">
</input>
</td>
</tr>
</table>
</div>
<div>
<input id="${this.prefix}-print-qrcode" type="checkbox">
</input>
${this.textLabels['print-qrcode']}
<div id="${this.prefix}-qrcode-panel"
class="xlv-qrcode-panel" style="display:none">
<table>
<tr>
<td colspan="2">
<input class="xlv-input" id="${this.prefix}-qrcode-data"
size="60">
</input>
<br>
${this.textLabels['print-qrcode-cta-label']}:
<input class="xlv-input" id="${this.prefix}-qrcode-cta-input"
value="${this.textLabels['print-qrcode-cta']}" size="20">
</input>
</td>
</tr>
<tr>
<td>
<p>
${this.textLabels['print-qrcode-details']}
<select id="${this.prefix}-qrcode-location">
<option value="bottom-right">${this.textLabels['print-qrcode-in-botright']}</option>
<option value="bottom-left">${this.textLabels['print-qrcode-in-botleft']}</option>
</select>.
</p>
<p>
${this.textLabels['print-qrcode-size']}
<select id="${this.prefix}-qrcode-size">
<option value="96">96</option>
<option value="128">128</option>
<option value="160">160</option>
</select>.
</p>
</td>
<td>
<table id="${this.prefix}-qrcode-table"
class="xlv-qrcode-table">
<tr><td>
<img id="${this.prefix}-qrcode" class="xlv-qrcode">
</td></tr>
<tr><td id="${this.prefix}-qrcode-cta"
class="xlv-qrcode-cta">
</td></tr>
</table>
</td>
</tr>
</table>
</div>
</div>
<div id="${this.prefix}-print-url-qrcodes-div"
style="display:none">
<input id="${this.prefix}-print-url-qrcodes" type="checkbox">
</input>
${this.textLabels['print-url-qrcodes']}
<div id="${this.prefix}-url-qrcodes-panel" style="display:none">
<table id="${this.prefix}-url-qrcodes-table"
class="xlv-url-qrcodes-table">
</table>
</div>
</div>
<div>
<button id="${this.prefix}-print-crossword"
class="xlv-small-button"
title="${this.textLabels['print-crossword.hover']}">
${this.textLabels['print-crossword']}
</button>
<button id="${this.prefix}-print-page"
class="xlv-small-button"
title="${this.textLabels['print-page.hover']}">
${this.textLabels['print-page']}
</button>
<button id="${this.prefix}-print-wysiwyg"
class="xlv-small-button"
title="${this.textLabels['print-page-wysiwyg.hover']}">
${this.textLabels['print-page-wysiwyg']}
</button>
</div>
</p>
</div>
<div id="${this.prefix}-notes-panel"
class="xlv-notes-panel xlv-toggleable" style="display:none">
</div>
<div id="${this.prefix}-jotter-panel"
class="xlv-toggleable" style="display:none">
<p>
<span id="${this.prefix}-shuffle" class="xlv-shuffle"
title="${this.textLabels['shuffle.hover']}"
>${this.textLabels['shuffle']}</span>
<textarea
id="${this.prefix}-scratchpad"
title="${this.textLabels['jotter-text.hover']}"
class="xlv-textarea xlv-scratchpad"
spellcheck="false" rows="2"></textarea>
</p>
</div>
</div> <!-- xlv-small-print -->
<div id="${this.prefix}-questions"
class="xlv-wide-box xlv-questions"></div>
<div id="${this.prefix}-submit-parent" class="xlv-submit">
<button id="${this.prefix}-submit"
class="xlv-button" style="display:none"
>${this.textLabels['submit']}</button>
</div> <!-- submit-parent -->
<div id="${this.prefix}-explanations" class="xlv-wide-box
xlv-explanations" style="display:none"></div>
</div> <!-- xlv-controls-etc -->
</div> <!-- xlv-grid-panel -->
<div id="${this.prefix}-clues" class="xlv-clues xlv-clues-flex">
<div class="xlv-clues-panel" style="display:none">
<div id="${this.prefix}-across-label"
class="xlv-clues-box xlv-clues-label">
<hr/>
${this.layers3d > 1 ? this.textLabels['3d-ac-label'] :
this.textLabels['across-label']}
</div>
<div id="${this.prefix}-across-clues-panel" class="xlv-clues-box">
<table id="${this.prefix}-across" class="xlv-clues-table"></table>
</div>
</div>
<div class="xlv-clues-panel" style="display:none">
<div id="${this.prefix}-down-label"
class="xlv-clues-box xlv-clues-label">
<hr/>
${this.layers3d > 1 ? this.textLabels['3d-aw-label'] :
this.textLabels['down-label']}
</div>
<div id="${this.prefix}-down-clues-panel" class="xlv-clues-box">
<table id="${this.prefix}-down" class="xlv-clues-table"></table>
</div>
</div>
<div class="xlv-clues-panel" style="display:none">
<div id="${this.prefix}-z3d-label"
class="xlv-clues-box xlv-clues-label">
<hr/>
${this.textLabels['3d-dn-label']}
</div>
<div id="${this.prefix}-z3d-clues-panel" class="xlv-clues-box">
<table id="${this.prefix}-z3d" class="xlv-clues-table"></table>