squiffy-runtime 7.0.0-beta.4 → 7.0.0-beta.6

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 (47) hide show
  1. package/dist/events.d.ts +1 -0
  2. package/dist/panels.d.ts +14 -0
  3. package/dist/panels.test.d.ts +1 -0
  4. package/dist/preview-host.d.ts +2 -1
  5. package/dist/preview-host.js +4 -1
  6. package/dist/preview-host.js.map +2 -2
  7. package/dist/preview-html.js +1 -1
  8. package/dist/preview-protocol.d.ts +4 -0
  9. package/dist/saveSlots.d.ts +16 -0
  10. package/dist/saves.test.d.ts +1 -0
  11. package/dist/savesDialog.d.ts +43 -0
  12. package/dist/savesDialog.test.d.ts +1 -0
  13. package/dist/squiffy.page.css +46 -22
  14. package/dist/squiffy.preview.html +612 -109
  15. package/dist/squiffy.runtime.css +476 -9
  16. package/dist/squiffy.runtime.d.ts +9 -1
  17. package/dist/squiffy.runtime.global.js +113 -72
  18. package/dist/squiffy.runtime.global.js.map +1 -1
  19. package/dist/squiffy.runtime.js +4146 -3460
  20. package/dist/squiffy.runtime.js.map +1 -1
  21. package/dist/state.d.ts +4 -0
  22. package/dist/textProcessor.d.ts +5 -0
  23. package/dist/types.d.ts +32 -0
  24. package/package.json +3 -3
  25. package/src/__snapshots__/squiffy.runtime.test.ts.snap +21 -21
  26. package/src/events.ts +1 -0
  27. package/src/panels.test.ts +201 -0
  28. package/src/panels.ts +187 -0
  29. package/src/plugins/plugins.test.ts +42 -0
  30. package/src/plugins/replaceLabel.ts +6 -2
  31. package/src/preview-host.test.ts +5 -1
  32. package/src/preview-host.ts +9 -3
  33. package/src/preview-protocol.ts +6 -2
  34. package/src/preview.test.ts +71 -3
  35. package/src/preview.ts +74 -13
  36. package/src/saveSlots.ts +159 -0
  37. package/src/saves.test.ts +199 -0
  38. package/src/savesDialog.test.ts +290 -0
  39. package/src/savesDialog.ts +499 -0
  40. package/src/squiffy.page.css +46 -22
  41. package/src/squiffy.runtime.css +476 -9
  42. package/src/squiffy.runtime.test.ts +890 -4
  43. package/src/squiffy.runtime.ts +322 -17
  44. package/src/state.ts +34 -4
  45. package/src/textProcessor.ts +76 -9
  46. package/src/types.ts +57 -1
  47. package/vite.preview.config.ts +7 -0
@@ -8,7 +8,7 @@
8
8
  {
9
9
  --squiffy-text: light-dark(#1f2328, #e4e4e7);
10
10
  --squiffy-background: light-dark(#ffffff, #18181b);
11
- /* Secondary text: the Restart button, and links waiting for valid input */
11
+ /* Secondary text: the header buttons, and links waiting for valid input */
12
12
  --squiffy-muted: light-dark(#6b6f76, #9a9ca3);
13
13
  /* The lines between sections */
14
14
  --squiffy-border: light-dark(#e2e2e6, #34343a);
@@ -99,25 +99,51 @@ select.squiffy-invalid:focus
99
99
  box-shadow: 0 0 0 0.2rem color-mix(in srgb, var(--squiffy-error) 50%, transparent);
100
100
  }
101
101
 
102
- /* Header button styles: the Restart button */
102
+ /* Header button styles: the Back, Restart and light/dark buttons, which are icons */
103
103
  button.squiffy-header-button
104
104
  {
105
+ display: inline-flex;
106
+ align-items: center;
107
+ justify-content: center;
105
108
  color: var(--squiffy-muted);
106
109
  cursor: pointer;
107
110
  background: none;
108
111
  border: none;
109
- padding: 0.25em 0;
112
+ border-radius: 0.375em;
113
+ padding: 0.375em;
110
114
  font: inherit;
111
- text-decoration: underline;
112
- text-decoration-color: transparent;
113
- text-underline-offset: 0.15em;
114
- transition: color 0.2s ease-in-out, text-decoration-color 0.2s ease-in-out;
115
+ vertical-align: middle;
116
+ transition: color 0.2s ease-in-out, background-color 0.2s ease-in-out;
115
117
  }
116
118
 
117
- button.squiffy-header-button:hover
119
+ button.squiffy-header-button:hover:not(:disabled)
118
120
  {
119
121
  color: var(--squiffy-text);
120
- text-decoration-color: currentColor;
122
+ background-color: color-mix(in srgb, currentColor 10%, transparent);
123
+ }
124
+
125
+ button.squiffy-header-button svg
126
+ {
127
+ width: 1.25em;
128
+ height: 1.25em;
129
+ fill: none;
130
+ stroke: currentColor;
131
+ stroke-width: 2;
132
+ stroke-linecap: round;
133
+ stroke-linejoin: round;
134
+ }
135
+
136
+ /* The light/dark button, when the story's CSS fixes the theme */
137
+ button.squiffy-header-button[hidden]
138
+ {
139
+ display: none;
140
+ }
141
+
142
+ /* The Back button, when there's nothing to go back to */
143
+ button.squiffy-header-button:disabled
144
+ {
145
+ cursor: default;
146
+ opacity: 0.5;
121
147
  }
122
148
 
123
149
  /* Output block spacing */
@@ -129,6 +155,19 @@ div.squiffy-output-section:not(:last-child)
129
155
  border-bottom: 1px solid var(--squiffy-border);
130
156
  }
131
157
 
158
+ /* ...but a block, passage or section that output no text (such as a passage that only does
159
+ {{replace}}) gets no line, and nor does one followed only by those, so they don't add extra lines */
160
+ div.squiffy-output-block:not(:has(> div:not(:empty))),
161
+ div.squiffy-output-block:not(:has(~ div.squiffy-output-block > div:not(:empty), ~ div.squiffy-output-passage > div.squiffy-output-block > div:not(:empty))),
162
+ div.squiffy-output-passage:not(:has(> div.squiffy-output-block > div:not(:empty))),
163
+ div.squiffy-output-passage:not(:has(~ div.squiffy-output-block > div:not(:empty), ~ div.squiffy-output-passage > div.squiffy-output-block > div:not(:empty))),
164
+ div.squiffy-output-section:not(:has(div.squiffy-output-block > div:not(:empty))),
165
+ div.squiffy-output-section:not(:has(~ div.squiffy-output-section div.squiffy-output-block > div:not(:empty)))
166
+ {
167
+ margin-bottom: 0;
168
+ border-bottom: none;
169
+ }
170
+
132
171
  /* Fade animations */
133
172
  .fade-out {
134
173
  opacity: 0;
@@ -197,3 +236,431 @@ div.squiffy-output-section:not(:last-child)
197
236
  animation: none;
198
237
  }
199
238
  }
239
+
240
+ /* The Saved games dialog, opened by the page's Save button */
241
+ dialog.squiffy-saves
242
+ {
243
+ width: min(28rem, calc(100vw - 2rem));
244
+ max-height: calc(100vh - 2rem);
245
+ box-sizing: border-box;
246
+ padding: 1rem 1.25rem 1.25rem;
247
+ border: 1px solid var(--squiffy-border);
248
+ border-radius: 0.75rem;
249
+ background-color: var(--squiffy-background);
250
+ color: var(--squiffy-text);
251
+ font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
252
+ font-size: 0.9375rem;
253
+ line-height: 1.4;
254
+ box-shadow: 0 1rem 3rem rgb(0 0 0 / 0.25);
255
+ }
256
+
257
+ dialog.squiffy-saves::backdrop
258
+ {
259
+ background-color: rgb(0 0 0 / 0.4);
260
+ }
261
+
262
+ dialog.squiffy-saves svg
263
+ {
264
+ width: 1.25em;
265
+ height: 1.25em;
266
+ flex: none;
267
+ fill: none;
268
+ stroke: currentColor;
269
+ stroke-width: 2;
270
+ stroke-linecap: round;
271
+ stroke-linejoin: round;
272
+ }
273
+
274
+ .squiffy-saves-header
275
+ {
276
+ display: flex;
277
+ align-items: center;
278
+ justify-content: space-between;
279
+ margin-bottom: 0.75rem;
280
+ }
281
+
282
+ .squiffy-saves-header h2
283
+ {
284
+ margin: 0;
285
+ font-size: 1.125rem;
286
+ }
287
+
288
+ .squiffy-saves button
289
+ {
290
+ font: inherit;
291
+ color: inherit;
292
+ cursor: pointer;
293
+ }
294
+
295
+ .squiffy-saves button:focus-visible,
296
+ .squiffy-saves input:focus-visible
297
+ {
298
+ outline: 2px solid var(--squiffy-link);
299
+ outline-offset: 2px;
300
+ }
301
+
302
+ .squiffy-saves-button
303
+ {
304
+ flex: none;
305
+ padding: 0.3em 0.8em;
306
+ border: 1px solid var(--squiffy-border);
307
+ border-radius: 0.375em;
308
+ background: none;
309
+ }
310
+
311
+ .squiffy-saves-button:hover
312
+ {
313
+ background-color: color-mix(in srgb, currentColor 8%, transparent);
314
+ }
315
+
316
+ .squiffy-saves .squiffy-saves-primary
317
+ {
318
+ border-color: var(--squiffy-link);
319
+ background-color: var(--squiffy-link);
320
+ color: var(--squiffy-background);
321
+ }
322
+
323
+ .squiffy-saves .squiffy-saves-danger-button
324
+ {
325
+ border-color: var(--squiffy-error);
326
+ background-color: var(--squiffy-error);
327
+ color: var(--squiffy-background);
328
+ }
329
+
330
+ .squiffy-saves-icon-button
331
+ {
332
+ display: inline-flex;
333
+ padding: 0.3em;
334
+ border: none;
335
+ border-radius: 0.375em;
336
+ background: none;
337
+ color: var(--squiffy-muted) !important;
338
+ }
339
+
340
+ .squiffy-saves-icon-button:hover,
341
+ .squiffy-saves-icon-button[aria-expanded="true"]
342
+ {
343
+ color: var(--squiffy-text) !important;
344
+ background-color: color-mix(in srgb, currentColor 10%, transparent);
345
+ }
346
+
347
+ .squiffy-saves-error
348
+ {
349
+ margin: 0 0 0.75rem;
350
+ color: var(--squiffy-error);
351
+ }
352
+
353
+ .squiffy-saves-new
354
+ {
355
+ display: flex;
356
+ gap: 0.5rem;
357
+ }
358
+
359
+ .squiffy-saves input[type="text"]
360
+ {
361
+ flex: 1;
362
+ min-width: 0;
363
+ padding: 0.3em 0.6em;
364
+ border: 1px solid var(--squiffy-border);
365
+ border-radius: 0.375em;
366
+ background-color: var(--squiffy-background);
367
+ color: inherit;
368
+ font: inherit;
369
+ }
370
+
371
+ .squiffy-saves-list
372
+ {
373
+ list-style: none;
374
+ margin: 0.75rem 0 0;
375
+ padding: 0;
376
+ max-height: 50vh;
377
+ overflow-y: auto;
378
+ }
379
+
380
+ .squiffy-saves-empty
381
+ {
382
+ padding: 0.75rem 0;
383
+ color: var(--squiffy-muted);
384
+ }
385
+
386
+ .squiffy-saves-row
387
+ {
388
+ padding: 0.5rem 0;
389
+ border-top: 1px solid var(--squiffy-border);
390
+ }
391
+
392
+ .squiffy-saves-line
393
+ {
394
+ display: flex;
395
+ align-items: center;
396
+ gap: 0.5rem;
397
+ }
398
+
399
+ .squiffy-saves-info
400
+ {
401
+ flex: 1;
402
+ min-width: 0;
403
+ }
404
+
405
+ .squiffy-saves-title
406
+ {
407
+ overflow: hidden;
408
+ text-overflow: ellipsis;
409
+ white-space: nowrap;
410
+ }
411
+
412
+ .squiffy-saves-meta
413
+ {
414
+ color: var(--squiffy-muted);
415
+ font-size: 0.8125rem;
416
+ }
417
+
418
+ .squiffy-saves-options
419
+ {
420
+ position: relative;
421
+ }
422
+
423
+ .squiffy-saves-menu
424
+ {
425
+ position: absolute;
426
+ right: 0;
427
+ top: 100%;
428
+ z-index: 1;
429
+ display: flex;
430
+ flex-direction: column;
431
+ min-width: 10rem;
432
+ margin-top: 0.25rem;
433
+ padding: 0.25rem;
434
+ border: 1px solid var(--squiffy-border);
435
+ border-radius: 0.5rem;
436
+ background-color: var(--squiffy-background);
437
+ box-shadow: 0 0.5rem 1.5rem rgb(0 0 0 / 0.2);
438
+ }
439
+
440
+ .squiffy-saves-menu[hidden]
441
+ {
442
+ display: none;
443
+ }
444
+
445
+ /* In the top layer, placed by the script */
446
+ .squiffy-saves-menu:popover-open
447
+ {
448
+ position: fixed;
449
+ right: auto;
450
+ bottom: auto;
451
+ margin: 0;
452
+ color: inherit;
453
+ }
454
+
455
+ .squiffy-saves-menu button
456
+ {
457
+ padding: 0.4em 0.75em;
458
+ border: none;
459
+ border-radius: 0.25em;
460
+ background: none;
461
+ text-align: left;
462
+ }
463
+
464
+ .squiffy-saves-menu button:hover,
465
+ .squiffy-saves-menu button:focus-visible
466
+ {
467
+ background-color: color-mix(in srgb, currentColor 10%, transparent);
468
+ }
469
+
470
+ .squiffy-saves .squiffy-saves-danger
471
+ {
472
+ color: var(--squiffy-error);
473
+ }
474
+
475
+ .squiffy-saves-confirm
476
+ {
477
+ margin-top: 0.5rem;
478
+ padding: 0.75rem;
479
+ border: 1px solid var(--squiffy-border);
480
+ border-radius: 0.5rem;
481
+ background-color: color-mix(in srgb, var(--squiffy-text) 5%, transparent);
482
+ }
483
+
484
+ .squiffy-saves-confirm p
485
+ {
486
+ margin: 0 0 0.5rem;
487
+ }
488
+
489
+ .squiffy-saves-confirm-buttons
490
+ {
491
+ display: flex;
492
+ justify-content: flex-end;
493
+ gap: 0.5rem;
494
+ }
495
+
496
+ .squiffy-saves-footer
497
+ {
498
+ display: flex;
499
+ flex-wrap: wrap;
500
+ gap: 0.5rem 1.25rem;
501
+ margin-top: 0.75rem;
502
+ padding-top: 0.75rem;
503
+ border-top: 1px solid var(--squiffy-border);
504
+ }
505
+
506
+ .squiffy-saves-link
507
+ {
508
+ display: inline-flex;
509
+ align-items: center;
510
+ gap: 0.375em;
511
+ padding: 0;
512
+ border: none;
513
+ background: none;
514
+ color: var(--squiffy-link) !important;
515
+ }
516
+
517
+ .squiffy-saves-link:hover
518
+ {
519
+ text-decoration: underline;
520
+ }
521
+
522
+ /* Panels (squiffy.json's "panels"): passages always to hand, beside the story or in a dialog */
523
+ :root
524
+ {
525
+ /* The width of a side panel */
526
+ --squiffy-side-width: 16rem;
527
+ }
528
+
529
+ /* A panel's button in the header, when it has a label rather than an icon */
530
+ button.squiffy-panel-text-button
531
+ {
532
+ padding: 0.375em 0.625em;
533
+ line-height: 1.25;
534
+ }
535
+
536
+ /* Space between the panels' buttons and the page's own */
537
+ button.squiffy-panel-button:not(:has(+ button.squiffy-panel-button))
538
+ {
539
+ margin-right: 0.5em;
540
+ }
541
+
542
+ /* The side panels. Like the header, they're smaller than the story text. */
543
+ aside.squiffy-panels-side
544
+ {
545
+ font-size: 0.9375rem;
546
+ line-height: 1.5;
547
+ }
548
+
549
+ aside.squiffy-panels-side[hidden],
550
+ aside.squiffy-panels-side > section.squiffy-panel[hidden]
551
+ {
552
+ display: none;
553
+ }
554
+
555
+ aside.squiffy-panels-side > section.squiffy-panel + section.squiffy-panel
556
+ {
557
+ margin-top: 1rem;
558
+ padding-top: 1rem;
559
+ border-top: 1px solid var(--squiffy-border);
560
+ }
561
+
562
+ .squiffy-panel > :first-child
563
+ {
564
+ margin-top: 0;
565
+ }
566
+
567
+ .squiffy-panel > :last-child
568
+ {
569
+ margin-bottom: 0;
570
+ }
571
+
572
+ .squiffy-panel img
573
+ {
574
+ max-width: 100%;
575
+ height: auto;
576
+ }
577
+
578
+ /* On a screen too narrow for the story and a side panel, the panel is a button in the header,
579
+ which shows it in a dialog */
580
+ @media (min-width: 64rem)
581
+ {
582
+ button.squiffy-panel-side-button
583
+ {
584
+ display: none;
585
+ }
586
+ }
587
+
588
+ @media (max-width: 63.99rem)
589
+ {
590
+ aside.squiffy-panels-side
591
+ {
592
+ display: none;
593
+ }
594
+ }
595
+
596
+ /* The dialog a panel's button opens */
597
+ dialog.squiffy-panel-dialog
598
+ {
599
+ width: min(28rem, calc(100vw - 2rem));
600
+ max-height: calc(100vh - 2rem);
601
+ box-sizing: border-box;
602
+ padding: 1rem 1.25rem 1.25rem;
603
+ border: 1px solid var(--squiffy-border);
604
+ border-radius: 0.75rem;
605
+ background-color: var(--squiffy-background);
606
+ color: var(--squiffy-text);
607
+ font-family: var(--squiffy-font-family, inherit);
608
+ font-size: var(--squiffy-font-size, 1rem);
609
+ line-height: var(--squiffy-line-height, 1.5);
610
+ box-shadow: 0 1rem 3rem rgb(0 0 0 / 0.25);
611
+ }
612
+
613
+ dialog.squiffy-panel-dialog::backdrop
614
+ {
615
+ background-color: rgb(0 0 0 / 0.4);
616
+ }
617
+
618
+ .squiffy-panel-dialog-header
619
+ {
620
+ display: flex;
621
+ align-items: center;
622
+ justify-content: space-between;
623
+ gap: 1rem;
624
+ margin-bottom: 0.75rem;
625
+ font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
626
+ }
627
+
628
+ .squiffy-panel-dialog-header h2
629
+ {
630
+ margin: 0;
631
+ font-size: 1.125rem;
632
+ }
633
+
634
+ button.squiffy-panel-dialog-close
635
+ {
636
+ display: inline-flex;
637
+ padding: 0.25em;
638
+ border: none;
639
+ border-radius: 0.375em;
640
+ background: none;
641
+ color: var(--squiffy-muted);
642
+ cursor: pointer;
643
+ }
644
+
645
+ button.squiffy-panel-dialog-close:hover
646
+ {
647
+ color: var(--squiffy-text);
648
+ background-color: color-mix(in srgb, currentColor 10%, transparent);
649
+ }
650
+
651
+ button.squiffy-panel-dialog-close:focus-visible
652
+ {
653
+ outline: 2px solid var(--squiffy-link);
654
+ outline-offset: 2px;
655
+ }
656
+
657
+ button.squiffy-panel-dialog-close svg
658
+ {
659
+ width: 1.25em;
660
+ height: 1.25em;
661
+ fill: none;
662
+ stroke: currentColor;
663
+ stroke-width: 2;
664
+ stroke-linecap: round;
665
+ stroke-linejoin: round;
666
+ }
@@ -1,4 +1,12 @@
1
1
  import { SquiffyApi, SquiffyInitOptions } from './types.js';
2
- export type { SquiffyApi } from './types.js';
2
+ export type { SquiffyApi, SavedGame, LoadSaveResult } from './types.js';
3
3
  export type { SquiffyEventHandler, SquiffyEventMap } from './events.js';
4
+ export { createSavesDialog, formatSaveTime, SAVES_STRINGS, SAVE_FILE_EXTENSION } from './savesDialog.js';
5
+ export type { SavesDialog, SavesDialogOptions, SavesStringName } from './savesDialog.js';
6
+ export { indexedDbSaveSlots, memorySaveSlots } from './saveSlots.js';
7
+ export { createPanels } from './panels.js';
8
+ export type { Panels, PanelsOptions } from './panels.js';
9
+ export { PANEL_ICONS } from './types.js';
10
+ export type { Panel, PanelIcon } from './types.js';
11
+ export type { SaveSlot, SaveSlots } from './saveSlots.js';
4
12
  export declare const init: (options: SquiffyInitOptions) => Promise<SquiffyApi>;