squiffy-runtime 7.0.0-beta.7 → 7.0.0-beta.8

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 (56) hide show
  1. package/dist/confirmDialog.d.ts +8 -0
  2. package/dist/events.d.ts +10 -0
  3. package/dist/every.d.ts +12 -0
  4. package/dist/every.test.d.ts +1 -0
  5. package/dist/playerSettings.d.ts +17 -0
  6. package/dist/preview-html.js +1 -1
  7. package/dist/settings.test.d.ts +1 -0
  8. package/dist/settingsDialog.d.ts +17 -0
  9. package/dist/squiffy.page.css +4 -1
  10. package/dist/squiffy.preview.html +673 -83
  11. package/dist/squiffy.runtime.css +531 -1
  12. package/dist/squiffy.runtime.d.ts +5 -1
  13. package/dist/squiffy.runtime.global.js +106 -85
  14. package/dist/squiffy.runtime.global.js.map +1 -1
  15. package/dist/squiffy.runtime.js +4743 -4157
  16. package/dist/squiffy.runtime.js.map +1 -1
  17. package/dist/state.d.ts +1 -0
  18. package/dist/style.test.d.ts +1 -0
  19. package/dist/textProcessor.d.ts +8 -0
  20. package/dist/transitions.test.d.ts +1 -0
  21. package/dist/types.d.ts +43 -0
  22. package/dist/uiLinks.test.d.ts +1 -0
  23. package/dist/utils.d.ts +1 -0
  24. package/dist/utils.test.d.ts +1 -0
  25. package/package.json +3 -3
  26. package/src/animation.test.ts +44 -0
  27. package/src/animation.ts +7 -3
  28. package/src/confirmDialog.ts +66 -0
  29. package/src/events.ts +17 -0
  30. package/src/every.test.ts +25 -0
  31. package/src/every.ts +94 -0
  32. package/src/panels.test.ts +24 -0
  33. package/src/playerSettings.ts +128 -0
  34. package/src/plugins/animate.ts +9 -0
  35. package/src/plugins/live.ts +3 -1
  36. package/src/plugins/plugins.test.ts +17 -0
  37. package/src/preview.test.ts +53 -3
  38. package/src/preview.ts +60 -1
  39. package/src/settings.test.ts +233 -0
  40. package/src/settingsDialog.ts +160 -0
  41. package/src/squiffy.page.css +4 -1
  42. package/src/squiffy.runtime.css +531 -1
  43. package/src/squiffy.runtime.test.ts +613 -16
  44. package/src/squiffy.runtime.ts +372 -19
  45. package/src/state.ts +16 -1
  46. package/src/style.test.ts +89 -0
  47. package/src/textProcessor.ts +141 -6
  48. package/src/transitions.test.ts +302 -0
  49. package/src/types.ts +56 -0
  50. package/src/uiLinks.test.ts +156 -0
  51. package/src/utils.test.ts +60 -0
  52. package/src/utils.ts +44 -14
  53. package/dist/infixExpressions.d.ts +0 -7
  54. package/src/infixExpressions.test.ts +0 -516
  55. package/src/infixExpressions.ts +0 -672
  56. /package/dist/{infixExpressions.test.d.ts → animation.test.d.ts} +0 -0
@@ -226,12 +226,261 @@ div.squiffy-output-section:not(:has(~ div.squiffy-output-section div.squiffy-out
226
226
  border-bottom: 1px solid currentColor;
227
227
  }
228
228
 
229
+ /* Text effects for {{#style}} (#453), e.g. {{#style "shudder"}}...{{/style}} */
230
+ span.squiffy-style:is(.shake, .shudder, .rumble, .sway, .buoy, .mirror, .upside-down) {
231
+ /* Transforms don't apply to inline elements */
232
+ display: inline-block;
233
+ }
234
+
235
+ .squiffy-style.shake {
236
+ animation: squiffy-shake 0.4s ease-in-out infinite;
237
+ }
238
+
239
+ @keyframes squiffy-shake {
240
+ 0%, 100% { transform: translateX(0); }
241
+ 25% { transform: translateX(-3px); }
242
+ 75% { transform: translateX(3px); }
243
+ }
244
+
245
+ .squiffy-style.shudder {
246
+ animation: squiffy-shudder 0.1s linear infinite alternate;
247
+ }
248
+
249
+ @keyframes squiffy-shudder {
250
+ from { transform: translateX(-1px); }
251
+ to { transform: translateX(1px); }
252
+ }
253
+
254
+ .squiffy-style.rumble {
255
+ animation: squiffy-rumble 0.1s linear infinite alternate;
256
+ }
257
+
258
+ @keyframes squiffy-rumble {
259
+ from { transform: translateY(-1px); }
260
+ to { transform: translateY(1px); }
261
+ }
262
+
263
+ .squiffy-style.sway {
264
+ animation: squiffy-sway 2.5s ease-in-out infinite;
265
+ }
266
+
267
+ @keyframes squiffy-sway {
268
+ 0%, 100% { transform: rotate(-3deg); }
269
+ 50% { transform: rotate(3deg); }
270
+ }
271
+
272
+ .squiffy-style.buoy {
273
+ animation: squiffy-buoy 2.5s ease-in-out infinite;
274
+ }
275
+
276
+ @keyframes squiffy-buoy {
277
+ 0%, 100% { transform: translateY(0); }
278
+ 50% { transform: translateY(-0.25em); }
279
+ }
280
+
281
+ .squiffy-style.pulse {
282
+ animation: squiffy-pulse 1.5s ease-in-out infinite;
283
+ }
284
+
285
+ .squiffy-style.fade-in-out {
286
+ animation: squiffy-fade-in-out 3s ease-in-out infinite;
287
+ }
288
+
289
+ @keyframes squiffy-fade-in-out {
290
+ 0%, 100% { opacity: 1; }
291
+ 50% { opacity: 0; }
292
+ }
293
+
294
+ .squiffy-style.blink {
295
+ animation: squiffy-blink 1s step-end infinite;
296
+ }
297
+
298
+ @keyframes squiffy-blink {
299
+ 50% { opacity: 0; }
300
+ }
301
+
302
+ .squiffy-style.flicker {
303
+ animation: squiffy-flicker 3s linear infinite;
304
+ }
305
+
306
+ @keyframes squiffy-flicker {
307
+ 0%, 19%, 21%, 23%, 54%, 56%, 100% { opacity: 1; }
308
+ 20%, 22%, 55% { opacity: 0.2; }
309
+ }
310
+
311
+ .squiffy-style.blur {
312
+ filter: blur(1px);
313
+ }
314
+
315
+ .squiffy-style.blurrier {
316
+ filter: blur(3px);
317
+ }
318
+
319
+ .squiffy-style.smear {
320
+ text-shadow: 0.15em 0 0.1em color-mix(in srgb, currentColor 50%, transparent), 0.3em 0 0.15em color-mix(in srgb, currentColor 25%, transparent);
321
+ }
322
+
323
+ .squiffy-style.mirror {
324
+ transform: scaleX(-1);
325
+ }
326
+
327
+ .squiffy-style.upside-down {
328
+ transform: scaleY(-1);
329
+ }
330
+
331
+ /* Transitions for how a section or passage appears (#489), from @transition. The element has
332
+ squiffy-transition and the transition's name as classes while it plays, and @transition's
333
+ time in --squiffy-transition-time. @leave plays them backwards, with squiffy-leave too, except
334
+ the slides, which leave the way they're named. A story's stylesheet can add its own, e.g.
335
+ .squiffy-transition.swirl { animation-name: swirl; } */
336
+ .squiffy-transition {
337
+ animation-duration: var(--squiffy-transition-time, 0.5s);
338
+ animation-timing-function: ease-out;
339
+ animation-fill-mode: both;
340
+ }
341
+
342
+ .squiffy-transition:is(.fade, .dissolve) {
343
+ animation-name: squiffy-transition-fade;
344
+ }
345
+
346
+ @keyframes squiffy-transition-fade {
347
+ from { opacity: 0; }
348
+ }
349
+
350
+ /* The slides move by --squiffy-slide-distance, e.g. 100% to slide all the way off and on */
351
+ @keyframes squiffy-transition-from-below {
352
+ from { opacity: 0; transform: translateY(var(--squiffy-slide-distance, 2em)); }
353
+ }
354
+
355
+ @keyframes squiffy-transition-from-above {
356
+ from { opacity: 0; transform: translateY(calc(-1 * var(--squiffy-slide-distance, 2em))); }
357
+ }
358
+
359
+ @keyframes squiffy-transition-from-right {
360
+ from { opacity: 0; transform: translateX(var(--squiffy-slide-distance, 3em)); }
361
+ }
362
+
363
+ @keyframes squiffy-transition-from-left {
364
+ from { opacity: 0; transform: translateX(calc(-1 * var(--squiffy-slide-distance, 3em))); }
365
+ }
366
+
367
+ /* A slide moves the way it's named: slide-left comes in from the right, and leaves to the left */
368
+ .squiffy-transition.slide-up {
369
+ animation-name: squiffy-transition-from-below;
370
+ }
371
+
372
+ .squiffy-transition.slide-down {
373
+ animation-name: squiffy-transition-from-above;
374
+ }
375
+
376
+ .squiffy-transition.slide-left {
377
+ animation-name: squiffy-transition-from-right;
378
+ }
379
+
380
+ .squiffy-transition.slide-right {
381
+ animation-name: squiffy-transition-from-left;
382
+ }
383
+
384
+ /* @leave plays the animations backwards, as the old text goes before the screen is cleared. So
385
+ that a slide leaves the way it's named, it plays the opposite slide backwards. */
386
+ .squiffy-transition.squiffy-leave {
387
+ animation-direction: reverse;
388
+ }
389
+
390
+ .squiffy-transition.squiffy-leave.slide-up {
391
+ animation-name: squiffy-transition-from-above;
392
+ }
393
+
394
+ .squiffy-transition.squiffy-leave.slide-down {
395
+ animation-name: squiffy-transition-from-below;
396
+ }
397
+
398
+ .squiffy-transition.squiffy-leave.slide-left {
399
+ animation-name: squiffy-transition-from-left;
400
+ }
401
+
402
+ .squiffy-transition.squiffy-leave.slide-right {
403
+ animation-name: squiffy-transition-from-right;
404
+ }
405
+
406
+ /* So a transition, a story's own too, doesn't make the page scroll sideways, or a slide make it
407
+ longer */
408
+ :has(> .squiffy-transition) {
409
+ overflow-x: clip;
410
+ }
411
+
412
+ :has(> .squiffy-transition:is(.slide-up, .slide-down)) {
413
+ overflow-y: clip;
414
+ }
415
+
416
+ .squiffy-transition.zoom {
417
+ animation-name: squiffy-transition-zoom;
418
+ }
419
+
420
+ @keyframes squiffy-transition-zoom {
421
+ from { opacity: 0; transform: scale(0.9); }
422
+ }
423
+
424
+ .squiffy-transition.blur {
425
+ animation-name: squiffy-transition-blur;
426
+ }
427
+
428
+ @keyframes squiffy-transition-blur {
429
+ from { opacity: 0; filter: blur(8px); }
430
+ }
431
+
432
+ .squiffy-transition.pulse {
433
+ animation-name: squiffy-transition-pulse;
434
+ }
435
+
436
+ @keyframes squiffy-transition-pulse {
437
+ from { opacity: 0; transform: scale(0.95); }
438
+ 60% { opacity: 1; transform: scale(1.02); }
439
+ }
440
+
441
+ .squiffy-transition.rumble {
442
+ animation-name: squiffy-transition-rumble;
443
+ }
444
+
445
+ @keyframes squiffy-transition-rumble {
446
+ from { opacity: 0; }
447
+ 10%, 30%, 50%, 70% { transform: translateY(-2px); }
448
+ 20%, 40%, 60%, 80% { transform: translateY(2px); }
449
+ 50% { opacity: 1; }
450
+ }
451
+
452
+ .squiffy-transition.shudder {
453
+ animation-name: squiffy-transition-shudder;
454
+ }
455
+
456
+ @keyframes squiffy-transition-shudder {
457
+ from { opacity: 0; }
458
+ 10%, 30%, 50%, 70% { transform: translateX(-2px); }
459
+ 20%, 40%, 60%, 80% { transform: translateX(2px); }
460
+ 50% { opacity: 1; }
461
+ }
462
+
463
+ .squiffy-transition.flicker {
464
+ animation-name: squiffy-transition-flicker;
465
+ }
466
+
467
+ @keyframes squiffy-transition-flicker {
468
+ from, 15%, 35%, 55% { opacity: 0; }
469
+ 10%, 25%, 45% { opacity: 0.6; }
470
+ }
471
+
229
472
  /* Respect the reader's reduced-motion setting */
230
473
  @media (prefers-reduced-motion: reduce)
231
474
  {
475
+ /* Every transition, a story's own too, is a plain fade */
476
+ .squiffy-transition {
477
+ animation-name: squiffy-transition-fade !important;
478
+ }
479
+
232
480
  .squiffy-continue-pulse,
233
481
  .squiffy-continue-glow,
234
- .squiffy-continue-bounce
482
+ .squiffy-continue-bounce,
483
+ .squiffy-style:is(.shake, .shudder, .rumble, .sway, .buoy, .pulse, .fade-in-out, .blink, .flicker)
235
484
  {
236
485
  animation: none;
237
486
  }
@@ -519,6 +768,287 @@ dialog.squiffy-saves svg
519
768
  text-decoration: underline;
520
769
  }
521
770
 
771
+ /* A question for the player, such as whether to restart, in place of the browser's confirm() */
772
+ dialog.squiffy-confirm
773
+ {
774
+ width: min(24rem, calc(100vw - 2rem));
775
+ box-sizing: border-box;
776
+ padding: 1.25rem;
777
+ border: 1px solid var(--squiffy-border);
778
+ border-radius: 0.75rem;
779
+ background-color: var(--squiffy-background);
780
+ color: var(--squiffy-text);
781
+ font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
782
+ font-size: 0.9375rem;
783
+ line-height: 1.4;
784
+ box-shadow: 0 1rem 3rem rgb(0 0 0 / 0.25);
785
+ }
786
+
787
+ dialog.squiffy-confirm::backdrop
788
+ {
789
+ background-color: rgb(0 0 0 / 0.4);
790
+ }
791
+
792
+ .squiffy-confirm p
793
+ {
794
+ margin: 0 0 1rem;
795
+ }
796
+
797
+ .squiffy-confirm-buttons
798
+ {
799
+ display: flex;
800
+ justify-content: flex-end;
801
+ gap: 0.5rem;
802
+ }
803
+
804
+ .squiffy-confirm-button
805
+ {
806
+ padding: 0.3em 0.8em;
807
+ border: 1px solid var(--squiffy-border);
808
+ border-radius: 0.375em;
809
+ background: none;
810
+ font: inherit;
811
+ color: inherit;
812
+ cursor: pointer;
813
+ }
814
+
815
+ .squiffy-confirm-button:hover
816
+ {
817
+ background-color: color-mix(in srgb, currentColor 8%, transparent);
818
+ }
819
+
820
+ .squiffy-confirm-button:focus-visible
821
+ {
822
+ outline: 2px solid var(--squiffy-link);
823
+ outline-offset: 2px;
824
+ }
825
+
826
+ .squiffy-confirm .squiffy-confirm-primary
827
+ {
828
+ border-color: var(--squiffy-link);
829
+ background-color: var(--squiffy-link);
830
+ color: var(--squiffy-background);
831
+ }
832
+
833
+ .squiffy-confirm .squiffy-confirm-danger
834
+ {
835
+ border-color: var(--squiffy-error);
836
+ background-color: var(--squiffy-error);
837
+ color: var(--squiffy-background);
838
+ }
839
+
840
+ .squiffy-confirm .squiffy-confirm-primary:hover,
841
+ .squiffy-confirm .squiffy-confirm-danger:hover
842
+ {
843
+ filter: brightness(1.1);
844
+ }
845
+
846
+ /* The Settings dialog (#452), for a story with "settings" in its squiffy.json */
847
+ dialog.squiffy-settings
848
+ {
849
+ width: min(28rem, calc(100vw - 2rem));
850
+ max-height: calc(100vh - 2rem);
851
+ box-sizing: border-box;
852
+ padding: 1rem 1.25rem 1.25rem;
853
+ border: 1px solid var(--squiffy-border);
854
+ border-radius: 0.75rem;
855
+ background-color: var(--squiffy-background);
856
+ color: var(--squiffy-text);
857
+ font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
858
+ font-size: 0.9375rem;
859
+ line-height: 1.4;
860
+ box-shadow: 0 1rem 3rem rgb(0 0 0 / 0.25);
861
+ }
862
+
863
+ dialog.squiffy-settings::backdrop
864
+ {
865
+ background-color: rgb(0 0 0 / 0.4);
866
+ }
867
+
868
+ .squiffy-settings-header
869
+ {
870
+ display: flex;
871
+ align-items: center;
872
+ justify-content: space-between;
873
+ margin-bottom: 0.5rem;
874
+ }
875
+
876
+ .squiffy-settings-header h2
877
+ {
878
+ margin: 0;
879
+ font-size: 1.125rem;
880
+ }
881
+
882
+ .squiffy-settings button,
883
+ .squiffy-settings select
884
+ {
885
+ font: inherit;
886
+ color: inherit;
887
+ cursor: pointer;
888
+ }
889
+
890
+ .squiffy-settings button:focus-visible,
891
+ .squiffy-settings input:focus-visible,
892
+ .squiffy-settings select:focus-visible
893
+ {
894
+ outline: 2px solid var(--squiffy-link);
895
+ outline-offset: 2px;
896
+ }
897
+
898
+ button.squiffy-settings-close
899
+ {
900
+ display: inline-flex;
901
+ padding: 0.25em;
902
+ border: none;
903
+ border-radius: 0.375em;
904
+ background: none;
905
+ color: var(--squiffy-muted);
906
+ }
907
+
908
+ button.squiffy-settings-close:hover
909
+ {
910
+ color: var(--squiffy-text);
911
+ background-color: color-mix(in srgb, currentColor 10%, transparent);
912
+ }
913
+
914
+ button.squiffy-settings-close svg
915
+ {
916
+ width: 1.25em;
917
+ height: 1.25em;
918
+ fill: none;
919
+ stroke: currentColor;
920
+ stroke-width: 2;
921
+ stroke-linecap: round;
922
+ stroke-linejoin: round;
923
+ }
924
+
925
+ .squiffy-setting
926
+ {
927
+ display: flex;
928
+ align-items: center;
929
+ justify-content: space-between;
930
+ gap: 1rem;
931
+ padding: 0.75rem 0;
932
+ border-bottom: 1px solid var(--squiffy-border);
933
+ }
934
+
935
+ .squiffy-setting-text
936
+ {
937
+ min-width: 0;
938
+ }
939
+
940
+ .squiffy-setting-text label
941
+ {
942
+ display: block;
943
+ }
944
+
945
+ .squiffy-setting-text p
946
+ {
947
+ margin: 0.125rem 0 0;
948
+ color: var(--squiffy-muted);
949
+ font-size: 0.875em;
950
+ }
951
+
952
+ .squiffy-setting select
953
+ {
954
+ flex: none;
955
+ max-width: 50%;
956
+ padding: 0.25em 0.5em;
957
+ border: 1px solid var(--squiffy-border);
958
+ border-radius: 0.375em;
959
+ background-color: var(--squiffy-background);
960
+ }
961
+
962
+ /* A toggle is a switch */
963
+ .squiffy-setting input[type=checkbox]
964
+ {
965
+ appearance: none;
966
+ flex: none;
967
+ position: relative;
968
+ width: 2.5em;
969
+ height: 1.5em;
970
+ margin: 0;
971
+ border-radius: 0.75em;
972
+ background-color: color-mix(in srgb, var(--squiffy-text) 25%, transparent);
973
+ cursor: pointer;
974
+ transition: background-color 0.15s;
975
+ }
976
+
977
+ .squiffy-setting input[type=checkbox]::before
978
+ {
979
+ content: "";
980
+ position: absolute;
981
+ top: 0.1875em;
982
+ left: 0.1875em;
983
+ width: 1.125em;
984
+ height: 1.125em;
985
+ border-radius: 50%;
986
+ background-color: var(--squiffy-background);
987
+ transition: transform 0.15s;
988
+ }
989
+
990
+ .squiffy-setting input[type=checkbox]:checked
991
+ {
992
+ background-color: var(--squiffy-link);
993
+ }
994
+
995
+ .squiffy-setting input[type=checkbox]:checked::before
996
+ {
997
+ transform: translateX(1em);
998
+ }
999
+
1000
+ .squiffy-setting-slider
1001
+ {
1002
+ display: flex;
1003
+ flex: none;
1004
+ align-items: center;
1005
+ gap: 0.5rem;
1006
+ width: 45%;
1007
+ }
1008
+
1009
+ .squiffy-setting-slider input
1010
+ {
1011
+ flex: 1;
1012
+ min-width: 0;
1013
+ accent-color: var(--squiffy-link);
1014
+ }
1015
+
1016
+ .squiffy-setting-slider output
1017
+ {
1018
+ min-width: 2ch;
1019
+ text-align: end;
1020
+ font-variant-numeric: tabular-nums;
1021
+ }
1022
+
1023
+ .squiffy-settings-footer
1024
+ {
1025
+ display: flex;
1026
+ justify-content: flex-end;
1027
+ margin-top: 1rem;
1028
+ }
1029
+
1030
+ button.squiffy-settings-reset
1031
+ {
1032
+ padding: 0.3em 0.8em;
1033
+ border: 1px solid var(--squiffy-border);
1034
+ border-radius: 0.375em;
1035
+ background: none;
1036
+ }
1037
+
1038
+ button.squiffy-settings-reset:hover
1039
+ {
1040
+ background-color: color-mix(in srgb, currentColor 8%, transparent);
1041
+ }
1042
+
1043
+ @media (prefers-reduced-motion: reduce)
1044
+ {
1045
+ .squiffy-setting input[type=checkbox],
1046
+ .squiffy-setting input[type=checkbox]::before
1047
+ {
1048
+ transition: none;
1049
+ }
1050
+ }
1051
+
522
1052
  /* Panels (squiffy.json's "panels"): passages always to hand, beside the story or in a dialog */
523
1053
  :root
524
1054
  {
@@ -1,8 +1,12 @@
1
1
  import { SquiffyApi, SquiffyInitOptions } from './types.js';
2
- export type { SquiffyApi, SavedGame, LoadSaveResult } from './types.js';
2
+ export type { SquiffyApi, SavedGame, LoadSaveResult, PlayerSetting, PlayerSettingOption, SettingValue } from './types.js';
3
3
  export type { SquiffyEventHandler, SquiffyEventMap } from './events.js';
4
4
  export { createSavesDialog, formatSaveTime, SAVES_STRINGS, SAVE_FILE_EXTENSION } from './savesDialog.js';
5
5
  export type { SavesDialog, SavesDialogOptions, SavesStringName } from './savesDialog.js';
6
+ export { confirmDialog } from './confirmDialog.js';
7
+ export { createSettingsDialog, SETTINGS_STRINGS } from './settingsDialog.js';
8
+ export type { SettingsDialog, SettingsDialogOptions } from './settingsDialog.js';
9
+ export type { ConfirmDialogOptions } from './confirmDialog.js';
6
10
  export { indexedDbSaveSlots, memorySaveSlots } from './saveSlots.js';
7
11
  export { createPanels } from './panels.js';
8
12
  export type { Panels, PanelsOptions } from './panels.js';