/
index.html
598 lines (542 loc) · 15.7 KB
/
index.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
<html>
<title>FountainDiffer</title>
<style>
div,
span,
form,
input {
padding: 0;
margin: 0;
}
body {
font-family: Helvetica, sans-serif;
font-size: 30px;
padding: 0;
margin: 0;
text-align: center;
}
#fountain-content {
text-align: left;
margin: 0 auto;
font-family: 'Courier Final Draft', 'Courier Screenplay', Courier;
font-size: 12pt;
width: 68ch;
max-width: 100vw;
}
#fountain-content ol {
list-style: none;
counter-reset: li;
}
#fountain-content li {
counter-increment: li;
}
#fountain-content li::before {
content: counter(li);
color: #cccccc;
display: inline-block;
width: 6em;
margin-left: -6em;
padding-left: 10px;
position: absolute;
cursor: pointer;
}
#fountain-content li,
#fountain-content p {
margin: 0;
padding: 0;
white-space: pre-wrap;
text-indent: -0.6em;
}
/* make sure to render empty lines */
#fountain-content li span:empty::before {
content: " ";
}
.diff-summary {
color: rgb(111, 66, 193);
opacity: 0.50;
}
.diff-add {
background-color: rgb(240, 255, 244);
color: rgb(34, 134, 58);
}
.diff-delete {
background-color: rgb(255, 238, 240);
color: rgb(179, 29, 40);
text-decoration: line-through;
}
.heading {
font-weight: bold;
color: rgb(111, 66, 193);
}
.synopsis {
opacity: 0.50;
}
.mini-slug {
font-weight: bold;
}
.scene-slug {
font-weight: bold;
}
.character {
padding-left: 19ch;
font-weight: bold;
}
.dialog {
padding-left: 10ch;
width: 34ch;
display: inline-block;
}
.parenthetical {
padding-left: 14ch;
}
.anchor-selected, li.anchor-selected::before {
border-top: 1px solid #fff100;
background: rgb(255, 251, 221);
border-bottom: 1px solid #fff100;
}
#menu {
color: #ccc;
padding: none;
padding: 5px 30px 5px 30px;
font-size: 12px;
border-bottom: 1px solid #efefef;
}
#menu-controls {
display: flex;
flex-direction: row;
align-items: center;
}
/* flex spacing */
#help-icon,
#url-input,
input[type='submit'] {
margin-right: 10px;
}
#menu-controls form {
flex-grow: 1; /* everything else is 0 */
}
#help-icon {
height: 12px;
width: 12px;
font-size: 12px;
line-height: 12px;
border-style: 1px solid #ccc;
border-radius: 50%;
padding: 1px;
text-align: center;
border-radius: 50%;
display: inline-block;
color: #ccc;
font-weight: 100;
border: 1px solid #ccc;
display: inline-block;
cursor: pointer;
}
#help-info {
font-size: medium;
}
img {
max-width: 100%;
}
form {
border: none;
margin: 0;
padding: 0;
display: flex;
}
input {
border: 1px solid #ccc;
background-color: #fff;
padding: none;
margin: none;
font-size: 12px;
color: #ccc;
padding: 2px 4px;
display: inline-block;
}
#url-input {
color: #bbb;
flex-grow: 1;
}
#slide-index {
font-size: 12px;
}
</style>
<script src="http://mattdaly.github.io/Fountain.js/assets/js/fountain.min.js"></script>
<!--
<script src="https://gist.githubusercontent.com/kortina/dbdf78ceb6f2a9e0673235b0e1a4f594/raw/e4524d50020e51b38c781e47faff1295c7432203/jsfountain.js"></script>
-->
<script>
/* globals commonmark */
/*
http://localhost:8000/?url=https%3A%2F%2Fgist.githubusercontent.com%2Fkortina%2F8f7413dbeb4e674666e94b8ee6331f71%2Fraw%2F8320c9a6b42fc87e4257d0203fa8372d8e5a6066%2Ftech-support-DRAFT.fountain.diff
*/
function loadMarkdown(url) {}
class FountainDiffer {
static responseCache = {};
static TEST_RAW = `
diff --git a/tech-support-DRAFT-RAW-2021-04-06.fountain b/tech-support-DRAFT-RAW-2021-04-08.fountain
index d30173f..8414f48 100644
--- a/tech-support-DRAFT-RAW-2021-04-06.fountain
+++ b/tech-support-DRAFT-RAW-2021-04-08.fountain
@@ -1,1196 +1,1402 @@
Title: Tech Support / DRAFT
Credit: written by Andrew Kortina
Draft Date: 26 Mar 2021
# Act I
EXT. OAKLAND - NIGHT
= A biker rides the streets of Oakland.
A BIKER (30s, wearing a FedEx jacket and has a big olive army duffle on her back) rides the streets of Oakland -- alone -- in the pitiless glow of the moon.
+[[TODO: she rides home first, then collects her stuff from her apt, loads her duffle, drops key in box, leaves]]
EXT. ELLIE'S FRONT PORCH - NIGHT
= The biker, Robin, shows up with a duffle.
The biker is at the front porch of a modest little West Oakland house. The door opens.
It's Ellie's roommate, PAUL (about 65, you would have said a Berkeley type 30 years ago but in 2021 his OD jacket and faded Levi's say he wouldn't live there if he could afford it).
IN THE DOORWAY MINI SLUG
PAUL
Well, well, well, look who it is...
/* boneyard */
He eyes the bulging army duffle.
PAUL (CONT'D)
Lotta' deliveries tonight, Robin?
`;
constructor(raw) {
this.raw = raw;
this.lines = [];
}
static qsURL() {
var p = new URLSearchParams(document.location.search);
return p.get('url');
}
static useTestRaw() {
return (this.qsURL() == "TEST");
}
static initURL() {
var u = this.qsURL();
var el = document.getElementById('url-input');
if (u && !el.value) {
el.value = u;
}
}
static formSubmit() {
var url = this.formValue();
if (`${url}` != "") {
var qsURL = this.qsURL();
if (qsURL == url) {
console.warning(`url already loaded`);
} else {
var l = document.location;
var e = encodeURIComponent(url);
var n = `${l.protocol}//${l.host}${l.pathname}?url=${e}`;
console.log(n);
document.location = n;
}
}
return false;
}
static formValue() {
var el = document.getElementById('url-input');
if (el) {
return el.value;
}
}
static fetchRaw() {
this.fetchRawFromURL(this.formValue());
}
static isValidURL(url) {
return /^(https?)\:\/\/[\w\.\-\:]+/i.test(url);
}
static fetchRawFromURL(url) {
var raw = (this.useTestRaw()) ? this.TEST_RAW : this.responseCache[url];
if (raw) {
this.onFetch(raw);
} else if (this.isValidURL(url)) {
fetch(url)
.then((response) => response.text())
.then((result) => {
this.responseCache[url] = result;
this.onFetch(result);
});
} else {
toggleHelp();
}
}
static onFetch(result) {
window.DIFFER = new FountainDiffer(result);
window.DIFFER.parseAndRender(result);
}
parseRaw(raw) {
window.RAW = raw;
var that = this;
(raw || "").split(/\n/).map((line) => {
that.lines.push(line);
});
}
parseAndRender(raw) {
this.parseRaw(raw);
this.render();
}
static stripDiffPrefix(line) {
if (line) {
return line.replace(/^[\s\-\+]+/, "");
}
return line;
}
static lineIsBlank(line) {
line = this.stripDiffPrefix(line);
return typeof(line) == "string" && line.match(/^\s*$/);
}
static classDiffSummary(line) {
return (
line.match(/^(diff|index|\@\@) /)
) ? 'diff-summary' : null;
}
static classDiffAdd(line) {
return line.match(/^\+/) ? 'diff-add' : null;
}
static classDiffDelete(line) {
return line.match(/^-/) ? 'diff-delete' : null;
}
static classHeading(line) {
line = this.stripDiffPrefix(line);
return line.match(/^\s*#/) ? 'heading' : null;
}
static classSynopsis(line) {
line = this.stripDiffPrefix(line);
return line.match(/^\s*\=/) ? 'synopsis' : null;
}
static classSceneSlug(line) {
line = this.stripDiffPrefix(line);
return line.match(/^\s*(INT|EXT)\./) ? 'scene-slug' : null;
}
static classMiniSlug(line) {
line = this.stripDiffPrefix(line);
return !line.match(/[a-z]/) && line.match(/[A-Z]/) ? 'mini-slug' : null;
}
static classCharacter(line, nextLine) {
line = this.stripDiffPrefix(line);
nextLine = this.stripDiffPrefix(nextLine);
// for some reason this expression is true for:
// PAUL (CONT'D)
// but this method returns null....
return (
!this.classSceneSlug(line)
&& line.match(/[A-Z]/)
&& !line.match(/[a-z]/)
&& !this.lineIsBlank(nextLine)
) ? 'character' : null;
}
static classDialog(line, prevClasses) {
line = this.stripDiffPrefix(line);
return (
line.match(/[a-zA-Z]/) &&
(
prevClasses.includes('character')
|| prevClasses.includes('parenthetical')
|| prevClasses.includes('dialog')
)
) ? 'dialog' : null;
}
static classParenthetical(line) {
line = this.stripDiffPrefix(line);
return (
// prevLine
// && this.classCharacter(prevLine, line)
// &&
line
&& line.match(/^\s*\(.*\)/)
) ? 'parenthetical' : null;
}
static computeClasses(line, prevLine, nextLine, prevClasses) {
var classes = [
this.classDiffSummary(line),
this.classDiffAdd(line),
this.classDiffDelete(line),
this.classHeading(line),
this.classSynopsis(line),
this.classMiniSlug(line),
this.classSceneSlug(line),
this.classCharacter(line, nextLine),
this.classDialog(line, prevClasses),
this.classParenthetical(line)
].filter(c => !!c);
// if (line.includes("BEDROOM - MORNING")) {
// debugger;
// }
// if (line.match(/CONT/)) {
// debugger;
// }
return classes;
}
static onClickRow(e) {
/* see:
https://stackoverflow.com/a/23243996/382912
console.log(`onClickRow`);
console.log(e);
*/
if (e.offsetX < 0 && e.target.id) {
document.location.hash = `#${e.target.id}`;
}
}
render() {
var d = document.createElement("ol");
var prevLine = null;
var prevClasses = [];
this.lines.map((line, i) => {
var nextLine = null;
if (i < this.lines.length - 1) {
nextLine = this.lines[i+1];
}
var e = document.createElement("li");
e.addEventListener('click', FountainDiffer.onClickRow);
e.id = `L${i}`;
var s = document.createElement("span");
var classes = FountainDiffer.computeClasses(line, prevLine, nextLine, prevClasses);
prevClasses = classes;
s.className = classes.join(" ");
s.append(document.createTextNode(line));
e.appendChild(s);
d.appendChild(e);
// console.log(`render: ${line}`);
prevLine = line;
});
var fc = document.getElementById("fountain-content");
fc.innerHTML = '';
fc.appendChild(d);
FountainDiffer.scrollToLineForAnchor();
}
prefetchImage(node, event) {
if (event.entering && node.type == 'image' && node.destination) {
var img = new Image();
img.src = node.destination;
}
}
static scrollToLineForAnchor() {
var h = document.location.hash || "";
var m = h.match(/(L\d+)/);
if (m) {
var el = document.getElementById(m[1]);
if (el) {
el.scrollIntoView(true);
addClass(el, "anchor-selected");
}
}
}
static elementFromURLString(urlString) {
var url = new URL(urlString);
if (url && url.hash) {
return document.getElementById(url.hash.substring(1));
}
}
static onHashChange(e) {
// un-highlight the previously highlighted row
var el;
el = FountainDiffer.elementFromURLString(e.oldURL)
if (el) {
removeClass(el, "anchor-selected");
}
el = FountainDiffer.elementFromURLString(e.newURL);
if (el) {
addClass(el, "anchor-selected");
}
}
}
/***************************************************
* end FountainDiffer
****************************************************/
function hasClass(ele, cls) {
return !!ele.className.match(new RegExp('(\\s|^)' + cls + '(\\s|$)'));
}
function addClass(ele, cls) {
if (!hasClass(ele, cls)) ele.className += " " + cls;
}
function removeClass(ele, cls) {
if (hasClass(ele, cls)) {
var reg = new RegExp('(\\s|^)' + cls + '(\\s|$)');
ele.className = ele.className.replace(reg, ' ');
}
}
function onDocReady(fn) {
// see if DOM is already available
if (document.readyState === 'complete' || document.readyState === 'interactive') {
// call on next available tick
setTimeout(fn, 1);
} else {
document.addEventListener('DOMContentLoaded', fn);
}
}
function onKey(e) {
if (e.target.nodeName == 'INPUT') {
return;
}
switch (e.code) {
case 'KeyM':
captureEvent(e);
return toggleMenu();
case 'Slash':
if (e.key == '?') {
captureEvent(e);
return toggleHelp();
}
default:
break;
// console.log(`code: ${e.code}`);
}
}
function captureEvent(e) {
if (e.target.nodeName == 'BODY') {
e.preventDefault();
}
}
function toggleMenu() {
toggleElementWithId('menu');
}
function toggleHelp() {
toggleElementWithId('help-info');
}
function toggleElementWithId(id) {
var el = document.getElementById(id);
var d = ['', 'none', null, undefined].includes(el.style.display) ? 'block' : 'none';
el.style.display = d;
}
onDocReady(function () {
window.addEventListener('hashchange', FountainDiffer.onHashChange, false);
FountainDiffer.initURL();
FountainDiffer.fetchRaw();
document.addEventListener('keydown', onKey); // keyup resulted in arrows still working
document.getElementById('help-icon').addEventListener('click', toggleHelp);
});
</script>
<body>
<div id="menu" style="display: block">
<div id="menu-controls">
<div id="help-icon" title="help">?</div>
<form onsubmit="return FountainDiffer.formSubmit();">
<input id="url-input" type="text" />
<input type="submit" value="Load" />
</form>
<div id="slide-index"></div>
</div>
<div id="help-info" style="display: none">
<pre>
Enter the raw URL for a GitHub gist that
contains the diff for 2 fountain files.
For more help, see README at
<a
href="https://github.com/kortina/fountain-differ">https://github.com/kortina/fountain-differ</a>.
Load test:
<a href="?url=TEST">test</a>.
Load example diff:
<a href="https://kortina.nyc/fountain-differ/?url=https%3A%2F%2Fraw.githubusercontent.com%2Fkortina%2Ffountain-differ%2Fmaster%2Fexamples%2Fexample.diff#L22">live demo</a>.
--------------------
Keyboard Shortcuts
--------------------
m show / hide menu
? show / hide help
</pre
>
</div>
</div>
<div id="fountain-content"></div>
</body>
</html>