squiffy-compiler 6.0.0-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (54) hide show
  1. package/README.md +3 -0
  2. package/dist/compiler.d.ts +51 -0
  3. package/dist/compiler.js +542 -0
  4. package/dist/compiler.test.d.ts +1 -0
  5. package/dist/compiler.test.js +73 -0
  6. package/dist/external-files.d.ts +5 -0
  7. package/dist/external-files.js +21 -0
  8. package/dist/index.template.html +39 -0
  9. package/dist/packager.d.ts +1 -0
  10. package/dist/packager.js +78 -0
  11. package/dist/server.d.ts +1 -0
  12. package/dist/server.js +15 -0
  13. package/dist/squiffy.d.ts +1 -0
  14. package/dist/squiffy.js +29 -0
  15. package/dist/squiffy.runtime.d.ts +34 -0
  16. package/dist/squiffy.template.d.ts +29 -0
  17. package/dist/squiffy.template.js +598 -0
  18. package/dist/style.template.css +52 -0
  19. package/dist/version.d.ts +1 -0
  20. package/dist/version.js +1 -0
  21. package/examples/attributes/attributes.squiffy +81 -0
  22. package/examples/clearscreen/clearscreen.squiffy +15 -0
  23. package/examples/continue/continue.squiffy +18 -0
  24. package/examples/helloworld/helloworld.squiffy +1 -0
  25. package/examples/import/file2.squiffy +8 -0
  26. package/examples/import/test.js +3 -0
  27. package/examples/import/test.squiffy +5 -0
  28. package/examples/input/input.squiffy +22 -0
  29. package/examples/last/last.squiffy +32 -0
  30. package/examples/master/master.squiffy +35 -0
  31. package/examples/replace/replace.squiffy +27 -0
  32. package/examples/rotate/rotate.squiffy +25 -0
  33. package/examples/sectiontrack/sectiontrack.squiffy +16 -0
  34. package/examples/start/start.squiffy +7 -0
  35. package/examples/test/example.squiffy +52 -0
  36. package/examples/textprocessor/textprocessor.squiffy +21 -0
  37. package/examples/transitions/transitions.squiffy +53 -0
  38. package/examples/turncount/turncount.squiffy +41 -0
  39. package/examples/warnings/warnings.squiffy +23 -0
  40. package/examples/warnings/warnings2.squiffy +3 -0
  41. package/package.json +46 -0
  42. package/src/__snapshots__/compiler.test.ts.snap +716 -0
  43. package/src/compiler.test.ts +86 -0
  44. package/src/compiler.ts +546 -0
  45. package/src/external-files.ts +22 -0
  46. package/src/index.template.html +39 -0
  47. package/src/packager.ts +97 -0
  48. package/src/server.ts +19 -0
  49. package/src/squiffy.runtime.ts +670 -0
  50. package/src/squiffy.ts +36 -0
  51. package/src/style.template.css +52 -0
  52. package/src/version.ts +1 -0
  53. package/tsconfig.json +22 -0
  54. package/tsconfig.runtime.json +12 -0
@@ -0,0 +1,598 @@
1
+ export const squiffy = {
2
+ init: null,
3
+ story: {},
4
+ set: function (attribute, value) {
5
+ if (typeof value === 'undefined')
6
+ value = true;
7
+ if (squiffy.ui.settings.persist && window.localStorage) {
8
+ localStorage[squiffy.story.id + '-' + attribute] = JSON.stringify(value);
9
+ }
10
+ else {
11
+ squiffy.storageFallback[attribute] = JSON.stringify(value);
12
+ }
13
+ squiffy.ui.settings.onSet(attribute, value);
14
+ },
15
+ get: function (attribute) {
16
+ var result;
17
+ if (squiffy.ui.settings.persist && window.localStorage) {
18
+ result = localStorage[squiffy.story.id + '-' + attribute];
19
+ }
20
+ else {
21
+ result = squiffy.storageFallback[attribute];
22
+ }
23
+ if (!result)
24
+ return null;
25
+ return JSON.parse(result);
26
+ },
27
+ ui: {
28
+ output: null,
29
+ settings: null,
30
+ processText: null,
31
+ write: null,
32
+ clearScreen: null,
33
+ scrollToEnd: null,
34
+ transition: null,
35
+ },
36
+ storageFallback: {}
37
+ };
38
+ var initLinkHandler = function () {
39
+ var handleLink = function (link) {
40
+ if (link.classList.contains('disabled'))
41
+ return;
42
+ var passage = link.getAttribute('data-passage');
43
+ var section = link.getAttribute('data-section');
44
+ var rotateAttr = link.getAttribute('data-rotate');
45
+ var sequenceAttr = link.getAttribute('data-sequence');
46
+ var rotateOrSequenceAttr = rotateAttr || sequenceAttr;
47
+ if (passage) {
48
+ disableLink(link);
49
+ squiffy.set('_turncount', squiffy.get('_turncount') + 1);
50
+ passage = processLink(passage);
51
+ if (passage) {
52
+ currentSection?.appendChild(document.createElement('hr'));
53
+ squiffy.story.passage(passage);
54
+ }
55
+ var turnPassage = '@' + squiffy.get('_turncount');
56
+ if (turnPassage in squiffy.story.section.passages) {
57
+ squiffy.story.passage(turnPassage);
58
+ }
59
+ if ('@last' in squiffy.story.section.passages && squiffy.get('_turncount') >= squiffy.story.section.passageCount) {
60
+ squiffy.story.passage('@last');
61
+ }
62
+ }
63
+ else if (section) {
64
+ currentSection?.appendChild(document.createElement('hr'));
65
+ disableLink(link);
66
+ section = processLink(section);
67
+ squiffy.story.go(section);
68
+ }
69
+ else if (rotateOrSequenceAttr) {
70
+ var result = rotate(rotateOrSequenceAttr, rotateAttr ? link.innerText : '');
71
+ link.innerHTML = result[0].replace(/"/g, '"').replace(/'/g, '\'');
72
+ var dataAttribute = rotateAttr ? 'data-rotate' : 'data-sequence';
73
+ link.setAttribute(dataAttribute, result[1] || '');
74
+ if (!result[1]) {
75
+ disableLink(link);
76
+ }
77
+ const attribute = link.getAttribute('data-attribute');
78
+ if (attribute) {
79
+ squiffy.set(attribute, result[0]);
80
+ }
81
+ squiffy.story.save();
82
+ }
83
+ };
84
+ const handleClick = (event) => {
85
+ var target = event.target;
86
+ if (target.classList.contains('squiffy-link')) {
87
+ handleLink(target);
88
+ }
89
+ };
90
+ document.addEventListener('click', handleClick);
91
+ document.addEventListener('keypress', function (event) {
92
+ if (event.key !== "Enter")
93
+ return;
94
+ handleClick(event);
95
+ });
96
+ };
97
+ const disableLink = function (link) {
98
+ link.classList.add('disabled');
99
+ link.setAttribute('tabindex', '-1');
100
+ };
101
+ const disableLinks = function (links) {
102
+ links.forEach(disableLink);
103
+ };
104
+ squiffy.story.begin = function () {
105
+ if (!squiffy.story.load()) {
106
+ squiffy.story.go(squiffy.story.start);
107
+ }
108
+ };
109
+ var processLink = function (link) {
110
+ var sections = link.split(',');
111
+ var first = true;
112
+ var target = null;
113
+ sections.forEach(function (section) {
114
+ section = section.trim();
115
+ if (startsWith(section, '@replace ')) {
116
+ replaceLabel(section.substring(9));
117
+ }
118
+ else {
119
+ if (first) {
120
+ target = section;
121
+ }
122
+ else {
123
+ setAttribute(section);
124
+ }
125
+ }
126
+ first = false;
127
+ });
128
+ return target;
129
+ };
130
+ var setAttribute = function (expr) {
131
+ expr = expr.replace(/^(\w*\s*):=(.*)$/, (_, name, value) => (name + "=" + squiffy.ui.processText(value)));
132
+ var lhs, rhs, op, value;
133
+ var setRegex = /^([\w]*)\s*=\s*(.*)$/;
134
+ var setMatch = setRegex.exec(expr);
135
+ if (setMatch) {
136
+ lhs = setMatch[1];
137
+ rhs = setMatch[2];
138
+ if (isNaN(rhs)) {
139
+ if (startsWith(rhs, "@"))
140
+ rhs = squiffy.get(rhs.substring(1));
141
+ squiffy.set(lhs, rhs);
142
+ }
143
+ else {
144
+ squiffy.set(lhs, parseFloat(rhs));
145
+ }
146
+ }
147
+ else {
148
+ var incDecRegex = /^([\w]*)\s*([\+\-\*\/])=\s*(.*)$/;
149
+ var incDecMatch = incDecRegex.exec(expr);
150
+ if (incDecMatch) {
151
+ lhs = incDecMatch[1];
152
+ op = incDecMatch[2];
153
+ rhs = incDecMatch[3];
154
+ if (startsWith(rhs, "@"))
155
+ rhs = squiffy.get(rhs.substring(1));
156
+ rhs = parseFloat(rhs);
157
+ value = squiffy.get(lhs);
158
+ if (value === null)
159
+ value = 0;
160
+ if (op == '+') {
161
+ value += rhs;
162
+ }
163
+ if (op == '-') {
164
+ value -= rhs;
165
+ }
166
+ if (op == '*') {
167
+ value *= rhs;
168
+ }
169
+ if (op == '/') {
170
+ value /= rhs;
171
+ }
172
+ squiffy.set(lhs, value);
173
+ }
174
+ else {
175
+ value = true;
176
+ if (startsWith(expr, 'not ')) {
177
+ expr = expr.substring(4);
178
+ value = false;
179
+ }
180
+ squiffy.set(expr, value);
181
+ }
182
+ }
183
+ };
184
+ var replaceLabel = function (expr) {
185
+ var regex = /^([\w]*)\s*=\s*(.*)$/;
186
+ var match = regex.exec(expr);
187
+ if (!match)
188
+ return;
189
+ var label = match[1];
190
+ var text = match[2];
191
+ if (text in squiffy.story.section.passages) {
192
+ text = squiffy.story.section.passages[text].text;
193
+ }
194
+ else if (text in squiffy.story.sections) {
195
+ text = squiffy.story.sections[text].text;
196
+ }
197
+ var stripParags = /^<p>(.*)<\/p>$/;
198
+ var stripParagsMatch = stripParags.exec(text);
199
+ if (stripParagsMatch) {
200
+ text = stripParagsMatch[1];
201
+ }
202
+ const labelElement = squiffy.ui.output.querySelector('.squiffy-label-' + label);
203
+ if (!labelElement)
204
+ return;
205
+ labelElement.addEventListener('transitionend', function () {
206
+ labelElement.innerHTML = squiffy.ui.processText(text);
207
+ labelElement.addEventListener('transitionend', function () {
208
+ squiffy.story.save();
209
+ }, { once: true });
210
+ labelElement.classList.remove('fade-out');
211
+ labelElement.classList.add('fade-in');
212
+ }, { once: true });
213
+ labelElement.classList.add('fade-out');
214
+ };
215
+ squiffy.story.go = function (section) {
216
+ squiffy.set('_transition', null);
217
+ newSection();
218
+ squiffy.story.section = squiffy.story.sections[section];
219
+ if (!squiffy.story.section)
220
+ return;
221
+ squiffy.set('_section', section);
222
+ setSeen(section);
223
+ var master = squiffy.story.sections[''];
224
+ if (master) {
225
+ squiffy.story.run(master);
226
+ squiffy.ui.write(master.text);
227
+ }
228
+ squiffy.story.run(squiffy.story.section);
229
+ // The JS might have changed which section we're in
230
+ if (squiffy.get('_section') == section) {
231
+ squiffy.set('_turncount', 0);
232
+ squiffy.ui.write(squiffy.story.section.text);
233
+ squiffy.story.save();
234
+ }
235
+ };
236
+ squiffy.story.run = function (section) {
237
+ if (section.clear) {
238
+ squiffy.ui.clearScreen();
239
+ }
240
+ if (section.attributes) {
241
+ processAttributes(section.attributes.map(line => line.replace(/^random\s*:\s*(\w+)\s*=\s*(.+)/i, (line, attr, options) => (options = options.split("|")) ? attr + " = " + options[Math.floor(Math.random() * options.length)] : line)));
242
+ }
243
+ if (section.jsIndex !== undefined) {
244
+ squiffy.story.js[section.jsIndex]();
245
+ }
246
+ };
247
+ squiffy.story.passage = function (passageName) {
248
+ var passage = squiffy.story.section.passages[passageName];
249
+ var masterSection = squiffy.story.sections[''];
250
+ if (!passage && masterSection)
251
+ passage = masterSection.passages[passageName];
252
+ if (!passage)
253
+ return;
254
+ setSeen(passageName);
255
+ if (masterSection) {
256
+ var masterPassage = masterSection.passages[''];
257
+ if (masterPassage) {
258
+ squiffy.story.run(masterPassage);
259
+ squiffy.ui.write(masterPassage.text);
260
+ }
261
+ }
262
+ var master = squiffy.story.section.passages[''];
263
+ if (master) {
264
+ squiffy.story.run(master);
265
+ squiffy.ui.write(master.text);
266
+ }
267
+ squiffy.story.run(passage);
268
+ squiffy.ui.write(passage.text);
269
+ squiffy.story.save();
270
+ };
271
+ var processAttributes = function (attributes) {
272
+ attributes.forEach(function (attribute) {
273
+ if (startsWith(attribute, '@replace ')) {
274
+ replaceLabel(attribute.substring(9));
275
+ }
276
+ else {
277
+ setAttribute(attribute);
278
+ }
279
+ });
280
+ };
281
+ squiffy.story.restart = function () {
282
+ if (squiffy.ui.settings.persist && window.localStorage) {
283
+ var keys = Object.keys(localStorage);
284
+ keys.forEach(key => {
285
+ if (startsWith(key, squiffy.story.id)) {
286
+ localStorage.removeItem(key);
287
+ }
288
+ });
289
+ }
290
+ else {
291
+ squiffy.storageFallback = {};
292
+ }
293
+ if (squiffy.ui.settings.scroll === 'element') {
294
+ squiffy.ui.output.innerHTML = '';
295
+ squiffy.story.begin();
296
+ }
297
+ else {
298
+ location.reload();
299
+ }
300
+ };
301
+ squiffy.story.save = function () {
302
+ squiffy.set('_output', squiffy.ui.output.innerHTML);
303
+ };
304
+ squiffy.story.load = function () {
305
+ var output = squiffy.get('_output');
306
+ if (!output)
307
+ return false;
308
+ squiffy.ui.output.innerHTML = output;
309
+ currentSection = document.getElementById(squiffy.get('_output-section'));
310
+ squiffy.story.section = squiffy.story.sections[squiffy.get('_section')];
311
+ var transition = squiffy.get('_transition');
312
+ if (transition) {
313
+ eval('(' + transition + ')()');
314
+ }
315
+ return true;
316
+ };
317
+ var setSeen = function (sectionName) {
318
+ var seenSections = squiffy.get('_seen_sections');
319
+ if (!seenSections)
320
+ seenSections = [];
321
+ if (seenSections.indexOf(sectionName) == -1) {
322
+ seenSections.push(sectionName);
323
+ squiffy.set('_seen_sections', seenSections);
324
+ }
325
+ };
326
+ squiffy.story.seen = function (sectionName) {
327
+ var seenSections = squiffy.get('_seen_sections');
328
+ if (!seenSections)
329
+ return false;
330
+ return (seenSections.indexOf(sectionName) > -1);
331
+ };
332
+ var currentSection = null;
333
+ var scrollPosition = 0;
334
+ var newSection = function () {
335
+ if (currentSection) {
336
+ disableLinks(currentSection.querySelectorAll('.squiffy-link'));
337
+ currentSection.querySelectorAll('input').forEach(el => {
338
+ const attribute = el.getAttribute('data-attribute') || el.id;
339
+ if (attribute)
340
+ squiffy.set(attribute, el.value);
341
+ el.disabled = true;
342
+ });
343
+ currentSection.querySelectorAll("[contenteditable]").forEach(el => {
344
+ const attribute = el.getAttribute('data-attribute') || el.id;
345
+ if (attribute)
346
+ squiffy.set(attribute, el.innerHTML);
347
+ el.contentEditable = 'false';
348
+ });
349
+ currentSection.querySelectorAll('textarea').forEach(el => {
350
+ const attribute = el.getAttribute('data-attribute') || el.id;
351
+ if (attribute)
352
+ squiffy.set(attribute, el.value);
353
+ el.disabled = true;
354
+ });
355
+ }
356
+ var sectionCount = squiffy.get('_section-count') + 1;
357
+ squiffy.set('_section-count', sectionCount);
358
+ var id = 'squiffy-section-' + sectionCount;
359
+ currentSection = document.createElement('div');
360
+ currentSection.id = id;
361
+ squiffy.ui.output.appendChild(currentSection);
362
+ squiffy.set('_output-section', id);
363
+ };
364
+ squiffy.ui.write = function (text) {
365
+ if (!currentSection)
366
+ return;
367
+ scrollPosition = squiffy.ui.output.scrollHeight;
368
+ const div = document.createElement('div');
369
+ currentSection.appendChild(div);
370
+ div.innerHTML = squiffy.ui.processText(text);
371
+ squiffy.ui.scrollToEnd();
372
+ };
373
+ squiffy.ui.clearScreen = function () {
374
+ squiffy.ui.output.innerHTML = '';
375
+ newSection();
376
+ };
377
+ squiffy.ui.scrollToEnd = function () {
378
+ if (squiffy.ui.settings.scroll === 'element') {
379
+ const scrollTo = squiffy.ui.output.scrollHeight - squiffy.ui.output.clientHeight;
380
+ const currentScrollTop = squiffy.ui.output.scrollTop;
381
+ if (scrollTo > (currentScrollTop || 0)) {
382
+ squiffy.ui.output.scrollTo({ top: scrollTo, behavior: 'smooth' });
383
+ }
384
+ }
385
+ else {
386
+ let scrollTo = scrollPosition;
387
+ const currentScrollTop = Math.max(document.body.scrollTop, document.documentElement.scrollTop);
388
+ if (scrollTo > currentScrollTop) {
389
+ var maxScrollTop = document.documentElement.scrollHeight - window.innerHeight;
390
+ if (scrollTo > maxScrollTop)
391
+ scrollTo = maxScrollTop;
392
+ window.scrollTo({ top: scrollTo, behavior: 'smooth' });
393
+ }
394
+ }
395
+ };
396
+ squiffy.ui.processText = function (text) {
397
+ function process(text, data) {
398
+ var containsUnprocessedSection = false;
399
+ var open = text.indexOf('{');
400
+ var close;
401
+ if (open > -1) {
402
+ var nestCount = 1;
403
+ var searchStart = open + 1;
404
+ var finished = false;
405
+ while (!finished) {
406
+ var nextOpen = text.indexOf('{', searchStart);
407
+ var nextClose = text.indexOf('}', searchStart);
408
+ if (nextClose > -1) {
409
+ if (nextOpen > -1 && nextOpen < nextClose) {
410
+ nestCount++;
411
+ searchStart = nextOpen + 1;
412
+ }
413
+ else {
414
+ nestCount--;
415
+ searchStart = nextClose + 1;
416
+ if (nestCount === 0) {
417
+ close = nextClose;
418
+ containsUnprocessedSection = true;
419
+ finished = true;
420
+ }
421
+ }
422
+ }
423
+ else {
424
+ finished = true;
425
+ }
426
+ }
427
+ }
428
+ if (containsUnprocessedSection) {
429
+ var section = text.substring(open + 1, close);
430
+ var value = processTextCommand(section, data);
431
+ text = text.substring(0, open) + value + process(text.substring(close + 1), data);
432
+ }
433
+ return (text);
434
+ }
435
+ function processTextCommand(text, data) {
436
+ if (startsWith(text, 'if ')) {
437
+ return processTextCommand_If(text, data);
438
+ }
439
+ else if (startsWith(text, 'else:')) {
440
+ return processTextCommand_Else(text, data);
441
+ }
442
+ else if (startsWith(text, 'label:')) {
443
+ return processTextCommand_Label(text, data);
444
+ }
445
+ else if (/^rotate[: ]/.test(text)) {
446
+ return processTextCommand_Rotate('rotate', text);
447
+ }
448
+ else if (/^sequence[: ]/.test(text)) {
449
+ return processTextCommand_Rotate('sequence', text);
450
+ }
451
+ else if (squiffy.story.section.passages && text in squiffy.story.section.passages) {
452
+ return process(squiffy.story.section.passages[text].text, data);
453
+ }
454
+ else if (text in squiffy.story.sections) {
455
+ return process(squiffy.story.sections[text].text, data);
456
+ }
457
+ else if (startsWith(text, '@') && !startsWith(text, '@replace')) {
458
+ processAttributes(text.substring(1).split(","));
459
+ return "";
460
+ }
461
+ return squiffy.get(text);
462
+ }
463
+ function processTextCommand_If(section, data) {
464
+ var command = section.substring(3);
465
+ var colon = command.indexOf(':');
466
+ if (colon == -1) {
467
+ return ('{if ' + command + '}');
468
+ }
469
+ var text = command.substring(colon + 1);
470
+ var condition = command.substring(0, colon);
471
+ condition = condition.replace("<", "&lt;");
472
+ var operatorRegex = /([\w ]*)(=|&lt;=|&gt;=|&lt;&gt;|&lt;|&gt;)(.*)/;
473
+ var match = operatorRegex.exec(condition);
474
+ var result = false;
475
+ if (match) {
476
+ var lhs = squiffy.get(match[1]);
477
+ var op = match[2];
478
+ var rhs = match[3];
479
+ if (startsWith(rhs, '@'))
480
+ rhs = squiffy.get(rhs.substring(1));
481
+ if (op == '=' && lhs == rhs)
482
+ result = true;
483
+ if (op == '&lt;&gt;' && lhs != rhs)
484
+ result = true;
485
+ if (op == '&gt;' && lhs > rhs)
486
+ result = true;
487
+ if (op == '&lt;' && lhs < rhs)
488
+ result = true;
489
+ if (op == '&gt;=' && lhs >= rhs)
490
+ result = true;
491
+ if (op == '&lt;=' && lhs <= rhs)
492
+ result = true;
493
+ }
494
+ else {
495
+ var checkValue = true;
496
+ if (startsWith(condition, 'not ')) {
497
+ condition = condition.substring(4);
498
+ checkValue = false;
499
+ }
500
+ if (startsWith(condition, 'seen ')) {
501
+ result = (squiffy.story.seen(condition.substring(5)) == checkValue);
502
+ }
503
+ else {
504
+ var value = squiffy.get(condition);
505
+ if (value === null)
506
+ value = false;
507
+ result = (value == checkValue);
508
+ }
509
+ }
510
+ var textResult = result ? process(text, data) : '';
511
+ data.lastIf = result;
512
+ return textResult;
513
+ }
514
+ function processTextCommand_Else(section, data) {
515
+ if (!('lastIf' in data) || data.lastIf)
516
+ return '';
517
+ var text = section.substring(5);
518
+ return process(text, data);
519
+ }
520
+ function processTextCommand_Label(section, data) {
521
+ var command = section.substring(6);
522
+ var eq = command.indexOf('=');
523
+ if (eq == -1) {
524
+ return ('{label:' + command + '}');
525
+ }
526
+ var text = command.substring(eq + 1);
527
+ var label = command.substring(0, eq);
528
+ return '<span class="squiffy-label-' + label + '">' + process(text, data) + '</span>';
529
+ }
530
+ function processTextCommand_Rotate(type, section) {
531
+ var options;
532
+ var attribute = '';
533
+ if (section.substring(type.length, type.length + 1) == ' ') {
534
+ var colon = section.indexOf(':');
535
+ if (colon == -1) {
536
+ return '{' + section + '}';
537
+ }
538
+ options = section.substring(colon + 1);
539
+ attribute = section.substring(type.length + 1, colon);
540
+ }
541
+ else {
542
+ options = section.substring(type.length + 1);
543
+ }
544
+ // TODO: Check - previously there was no second parameter here
545
+ var rotation = rotate(options.replace(/"/g, '&quot;').replace(/'/g, '&#39;'), null);
546
+ if (attribute) {
547
+ squiffy.set(attribute, rotation[0]);
548
+ }
549
+ return '<a class="squiffy-link" data-' + type + '="' + rotation[1] + '" data-attribute="' + attribute + '" role="link">' + rotation[0] + '</a>';
550
+ }
551
+ var data = {
552
+ fulltext: text
553
+ };
554
+ return process(text, data);
555
+ };
556
+ squiffy.ui.transition = function (f) {
557
+ squiffy.set('_transition', f.toString());
558
+ f();
559
+ };
560
+ squiffy.storageFallback = {};
561
+ var startsWith = function (string, prefix) {
562
+ return string.substring(0, prefix.length) === prefix;
563
+ };
564
+ var rotate = function (options, current) {
565
+ var colon = options.indexOf(':');
566
+ if (colon == -1) {
567
+ return [options, current];
568
+ }
569
+ var next = options.substring(0, colon);
570
+ var remaining = options.substring(colon + 1);
571
+ if (current)
572
+ remaining += ':' + current;
573
+ return [next, remaining];
574
+ };
575
+ squiffy.init = function (options) {
576
+ const settings = {
577
+ scroll: 'body',
578
+ persist: true,
579
+ restartPrompt: true,
580
+ onSet: function () { }
581
+ };
582
+ squiffy.ui.output = options.element;
583
+ squiffy.ui.settings = settings;
584
+ if (settings.scroll === 'element') {
585
+ squiffy.ui.output.style.overflowY = 'auto';
586
+ }
587
+ initLinkHandler();
588
+ squiffy.story.begin();
589
+ return {
590
+ askRestart: function () {
591
+ if (!squiffy.ui.settings.restartPrompt || confirm('Are you sure you want to restart?')) {
592
+ squiffy.story.restart();
593
+ }
594
+ }
595
+ };
596
+ };
597
+ export const get = squiffy.get;
598
+ export const set = squiffy.set;
@@ -0,0 +1,52 @@
1
+ a.squiffy-link
2
+ {
3
+ text-decoration: underline;
4
+ color: Blue;
5
+ cursor: pointer;
6
+ }
7
+ a.squiffy-link.disabled
8
+ {
9
+ text-decoration: inherit;
10
+ color: inherit !important;
11
+ cursor: inherit;
12
+ }
13
+ button.squiffy-header-button
14
+ {
15
+ text-decoration: underline;
16
+ color: Blue;
17
+ cursor: pointer;
18
+ background: none;
19
+ border: none;
20
+ font-family: inherit;
21
+ }
22
+ div#squiffy-container
23
+ {
24
+ max-width: 700px;
25
+ margin-left: auto;
26
+ margin-right: auto;
27
+ font-family: Georgia, serif;
28
+ }
29
+ div#squiffy-header
30
+ {
31
+ font-size: 14px;
32
+ text-align: right;
33
+ }
34
+ div#squiffy
35
+ {
36
+ font-size: 18px;
37
+ }
38
+ hr {
39
+ border: 0;
40
+ height: 0;
41
+ border-top: 1px solid rgba(0, 0, 0, 0.1);
42
+ border-bottom: 1px solid rgba(255, 255, 255, 0.3);
43
+ margin-top: 16px; margin-bottom: 16px;
44
+ }
45
+ .fade-out {
46
+ opacity: 0;
47
+ transition: opacity 1000ms;
48
+ }
49
+ .fade-in {
50
+ opacity: 1;
51
+ transition: opacity 1000ms;
52
+ }
@@ -0,0 +1 @@
1
+ export declare const SQUIFFY_VERSION = "6.0.0-alpha.0";
@@ -0,0 +1 @@
1
+ export const SQUIFFY_VERSION = '6.0.0-alpha.0';