squiffy-runtime 7.0.0-beta.1 → 7.0.0-beta.11

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 (111) hide show
  1. package/dist/assets.d.ts +1 -0
  2. package/dist/classes.test.d.ts +1 -0
  3. package/dist/confirmDialog.d.ts +8 -0
  4. package/dist/events.d.ts +12 -0
  5. package/dist/every.d.ts +12 -0
  6. package/dist/every.test.d.ts +1 -0
  7. package/dist/helpers.test.d.ts +1 -0
  8. package/dist/numbers.d.ts +3 -0
  9. package/dist/panels.d.ts +14 -0
  10. package/dist/panels.test.d.ts +1 -0
  11. package/dist/paths.d.ts +15 -0
  12. package/dist/paths.test.d.ts +1 -0
  13. package/dist/persistent.test.d.ts +1 -0
  14. package/dist/playerSettings.d.ts +17 -0
  15. package/dist/preview-host.d.ts +7 -3
  16. package/dist/preview-host.js +47 -5
  17. package/dist/preview-host.js.map +2 -2
  18. package/dist/preview-html.js +1 -1
  19. package/dist/preview-protocol.d.ts +16 -0
  20. package/dist/preview.d.ts +1 -0
  21. package/dist/saveSlots.d.ts +16 -0
  22. package/dist/saves.test.d.ts +1 -0
  23. package/dist/savesDialog.d.ts +43 -0
  24. package/dist/savesDialog.test.d.ts +1 -0
  25. package/dist/scripts.test.d.ts +1 -0
  26. package/dist/settings.test.d.ts +1 -0
  27. package/dist/settingsDialog.d.ts +17 -0
  28. package/dist/skill.test.d.ts +1 -0
  29. package/dist/sound.d.ts +35 -0
  30. package/dist/sound.test.d.ts +1 -0
  31. package/dist/squiffy.page.css +155 -0
  32. package/dist/squiffy.preview.html +1469 -136
  33. package/dist/squiffy.runtime.css +1123 -20
  34. package/dist/squiffy.runtime.d.ts +13 -1
  35. package/dist/squiffy.runtime.global.js +144 -79
  36. package/dist/squiffy.runtime.global.js.map +1 -1
  37. package/dist/squiffy.runtime.js +6771 -4424
  38. package/dist/squiffy.runtime.js.map +1 -1
  39. package/dist/state.d.ts +17 -0
  40. package/dist/storyLists.d.ts +4 -0
  41. package/dist/storyLists.test.d.ts +1 -0
  42. package/dist/style.test.d.ts +1 -0
  43. package/dist/textProcessor.d.ts +27 -0
  44. package/dist/transitions.test.d.ts +1 -0
  45. package/dist/types.d.ts +125 -0
  46. package/dist/types.plugins.d.ts +1 -0
  47. package/dist/uiLinks.test.d.ts +1 -0
  48. package/dist/utils.d.ts +2 -1
  49. package/dist/utils.test.d.ts +1 -0
  50. package/package.json +11 -6
  51. package/src/__snapshots__/squiffy.runtime.test.ts.snap +22 -22
  52. package/src/animation.test.ts +44 -0
  53. package/src/animation.ts +9 -5
  54. package/src/assets.test.ts +1 -3
  55. package/src/assets.ts +1 -1
  56. package/src/classes.test.ts +201 -0
  57. package/src/confirmDialog.ts +66 -0
  58. package/src/events.ts +19 -0
  59. package/src/every.test.ts +25 -0
  60. package/src/every.ts +94 -0
  61. package/src/helpers.test.ts +34 -0
  62. package/src/numbers.ts +21 -0
  63. package/src/panels.test.ts +225 -0
  64. package/src/panels.ts +187 -0
  65. package/src/paths.test.ts +66 -0
  66. package/src/paths.ts +155 -0
  67. package/src/persistent.test.ts +155 -0
  68. package/src/playerSettings.ts +128 -0
  69. package/src/pluginManager.ts +1 -0
  70. package/src/plugins/animate.ts +28 -4
  71. package/src/plugins/live.ts +18 -5
  72. package/src/plugins/plugins.test.ts +93 -6
  73. package/src/plugins/replaceLabel.ts +7 -3
  74. package/src/preview-host.test.ts +97 -1
  75. package/src/preview-host.ts +71 -10
  76. package/src/preview-protocol.ts +25 -3
  77. package/src/preview.main.ts +1 -0
  78. package/src/preview.test.ts +203 -4
  79. package/src/preview.ts +178 -12
  80. package/src/saveSlots.ts +159 -0
  81. package/src/saves.test.ts +199 -0
  82. package/src/savesDialog.test.ts +290 -0
  83. package/src/savesDialog.ts +499 -0
  84. package/src/scripts.test.ts +130 -0
  85. package/src/settings.test.ts +233 -0
  86. package/src/settingsDialog.ts +160 -0
  87. package/src/skill.test.ts +67 -0
  88. package/src/sound.test.ts +273 -0
  89. package/src/sound.ts +207 -0
  90. package/src/squiffy.page.css +155 -0
  91. package/src/squiffy.runtime.css +1123 -20
  92. package/src/squiffy.runtime.test.ts +2806 -44
  93. package/src/squiffy.runtime.ts +1111 -64
  94. package/src/state.ts +172 -11
  95. package/src/storyLists.test.ts +134 -0
  96. package/src/storyLists.ts +57 -0
  97. package/src/style.test.ts +89 -0
  98. package/src/textProcessor.ts +739 -58
  99. package/src/transitions.test.ts +343 -0
  100. package/src/types.plugins.ts +3 -0
  101. package/src/types.ts +209 -1
  102. package/src/uiLinks.test.ts +156 -0
  103. package/src/updater.ts +26 -8
  104. package/src/utils.test.ts +60 -0
  105. package/src/utils.ts +46 -14
  106. package/vite.config.ts +3 -4
  107. package/vite.preview.config.ts +16 -5
  108. package/dist/infixExpressions.d.ts +0 -2
  109. package/src/infixExpressions.test.ts +0 -187
  110. package/src/infixExpressions.ts +0 -323
  111. /package/dist/{infixExpressions.test.d.ts → animation.test.d.ts} +0 -0
@@ -10,6 +10,7 @@ export interface PreviewAssets {
10
10
  files?: Record<string, Blob | ArrayBuffer | Uint8Array>;
11
11
  urls?: Record<string, string>;
12
12
  }
13
+ export type PreviewTheme = "light" | "dark" | "system";
13
14
  export type HostMessage = {
14
15
  type: "load";
15
16
  story: PreviewStory;
@@ -17,6 +18,7 @@ export type HostMessage = {
17
18
  } | {
18
19
  type: "update";
19
20
  js: string;
21
+ css?: string[];
20
22
  } | {
21
23
  type: "restart";
22
24
  } | {
@@ -24,11 +26,22 @@ export type HostMessage = {
24
26
  } | {
25
27
  type: "assets";
26
28
  assets: PreviewAssets;
29
+ } | {
30
+ type: "theme";
31
+ theme: PreviewTheme;
32
+ } | {
33
+ type: "muted";
34
+ muted: boolean;
35
+ } | {
36
+ type: "reload";
27
37
  };
28
38
  export type PreviewMessage = {
29
39
  type: "ready";
30
40
  } | {
31
41
  type: "loaded";
42
+ } | {
43
+ type: "themeFixed";
44
+ fixed: boolean;
32
45
  } | {
33
46
  type: "attributeSet";
34
47
  name: string;
@@ -36,6 +49,9 @@ export type PreviewMessage = {
36
49
  } | {
37
50
  type: "canGoBackChanged";
38
51
  canGoBack: boolean;
52
+ } | {
53
+ type: "usesSound";
54
+ usesSound: boolean;
39
55
  } | {
40
56
  type: "navigated";
41
57
  section: string;
package/dist/preview.d.ts CHANGED
@@ -6,6 +6,7 @@ export interface PreviewOptions {
6
6
  loadModule?(js: string): Promise<{
7
7
  story: Story;
8
8
  }>;
9
+ reload?(): void;
9
10
  }
10
11
  declare function errorMessage(error: unknown): PreviewMessage;
11
12
  export declare function createPreview(options: PreviewOptions): {
@@ -0,0 +1,16 @@
1
+ import { SavedGame } from './types.js';
2
+ export interface SaveSlot {
3
+ id: number;
4
+ name: string | null;
5
+ save: SavedGame;
6
+ }
7
+ export interface SaveSlots {
8
+ list(): Promise<SaveSlot[]>;
9
+ get(id: number): Promise<SaveSlot | null>;
10
+ add(save: SavedGame, name: string | null): Promise<SaveSlot>;
11
+ overwrite(id: number, save: SavedGame): Promise<void>;
12
+ rename(id: number, name: string | null): Promise<void>;
13
+ delete(id: number): Promise<void>;
14
+ }
15
+ export declare function indexedDbSaveSlots(key: string): SaveSlots;
16
+ export declare function memorySaveSlots(): SaveSlots;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,43 @@
1
+ import { SquiffyApi } from './types.js';
2
+ import { SaveSlots } from './saveSlots.js';
3
+ export declare const SAVES_STRINGS: {
4
+ saves: string;
5
+ saveName: string;
6
+ save: string;
7
+ noSaves: string;
8
+ savedGame: string;
9
+ savedToday: string;
10
+ savedYesterday: string;
11
+ load: string;
12
+ loadConfirm: string;
13
+ saveOptions: string;
14
+ overwrite: string;
15
+ overwriteConfirm: string;
16
+ rename: string;
17
+ newName: string;
18
+ saveToFile: string;
19
+ loadFromFile: string;
20
+ delete: string;
21
+ deleteConfirm: string;
22
+ cancel: string;
23
+ close: string;
24
+ wrongStory: string;
25
+ notASave: string;
26
+ cantSave: string;
27
+ };
28
+ export type SavesStringName = keyof typeof SAVES_STRINGS;
29
+ export interface SavesDialogOptions {
30
+ slots?: SaveSlots;
31
+ key?: string;
32
+ strings?: Partial<Record<string, string>>;
33
+ fileName?: string;
34
+ container?: HTMLElement;
35
+ }
36
+ export interface SavesDialog {
37
+ element: HTMLDialogElement;
38
+ open: () => Promise<void>;
39
+ close: () => void;
40
+ }
41
+ export declare const SAVE_FILE_EXTENSION = ".squiffy-save";
42
+ export declare function formatSaveTime(savedAt: string, strings?: Record<SavesStringName, string>, now?: Date): string;
43
+ export declare function createSavesDialog(api: SquiffyApi, options?: SavesDialogOptions): SavesDialog;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,17 @@
1
+ import { SquiffyApi } from './types.js';
2
+ export declare const SETTINGS_STRINGS: {
3
+ settings: string;
4
+ resetSettings: string;
5
+ close: string;
6
+ };
7
+ export interface SettingsDialogOptions {
8
+ strings?: Partial<Record<string, string>>;
9
+ container?: HTMLElement;
10
+ }
11
+ export interface SettingsDialog {
12
+ element: HTMLDialogElement;
13
+ open: () => void;
14
+ close: () => void;
15
+ }
16
+ export declare const SETTINGS_ICON = "<svg viewBox=\"0 0 24 24\" aria-hidden=\"true\"><path d=\"M12.22 2h-.44a2 2 0 0 0-2 2v.18a2 2 0 0 1-1 1.73l-.43.25a2 2 0 0 1-2 0l-.15-.08a2 2 0 0 0-2.73.73l-.22.38a2 2 0 0 0 .73 2.73l.15.1a2 2 0 0 1 1 1.72v.51a2 2 0 0 1-1 1.74l-.15.09a2 2 0 0 0-.73 2.73l.22.38a2 2 0 0 0 2.73.73l.15-.08a2 2 0 0 1 2 0l.43.25a2 2 0 0 1 1 1.73V20a2 2 0 0 0 2 2h.44a2 2 0 0 0 2-2v-.18a2 2 0 0 1 1-1.73l.43-.25a2 2 0 0 1 2 0l.15.08a2 2 0 0 0 2.73-.73l.22-.39a2 2 0 0 0-.73-2.73l-.15-.08a2 2 0 0 1-1-1.74v-.5a2 2 0 0 1 1-1.74l.15-.09a2 2 0 0 0 .73-2.73l-.22-.38a2 2 0 0 0-2.73-.73l-.15.08a2 2 0 0 1-2 0l-.43-.25a2 2 0 0 1-1-1.73V4a2 2 0 0 0-2-2z\"/><circle cx=\"12\" cy=\"12\" r=\"3\"/></svg>";
17
+ export declare function createSettingsDialog(api: SquiffyApi, options?: SettingsDialogOptions): SettingsDialog;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,35 @@
1
+ export type AudioUrlResolver = (path: string) => string;
2
+ export interface SoundOptions {
3
+ resolveUrl: AudioUrlResolver;
4
+ getMusic: () => string | null;
5
+ mutedKey?: string;
6
+ onPlay?: () => void;
7
+ }
8
+ export declare const DEFAULT_FADE = 1;
9
+ export declare class Sound {
10
+ private options;
11
+ private music;
12
+ private effects;
13
+ private preloaded;
14
+ private muted;
15
+ private waitingForGesture;
16
+ private disposed;
17
+ constructor(options: SoundOptions);
18
+ preload(files: string[]): void;
19
+ sync(fade?: number): void;
20
+ play(file: string, volume?: number): void;
21
+ stopSounds(): void;
22
+ isMuted(): boolean;
23
+ setMuted(muted: boolean): void;
24
+ dispose(): void;
25
+ private newAudio;
26
+ private startMusic;
27
+ private playTrack;
28
+ private stopMusic;
29
+ private fade;
30
+ private readonly onGesture;
31
+ private waitForGesture;
32
+ private removeGestureListeners;
33
+ private readMuted;
34
+ private writeMuted;
35
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,155 @@
1
+ /* Page layout styles for an exported story. See https://squiffystory.com/styling/ for how to customise these. */
2
+
3
+ :root
4
+ {
5
+ /* The width of the story text */
6
+ --squiffy-max-width: 42rem;
7
+ /* The story's font. Charter, or Georgia if the reader doesn't have it */
8
+ --squiffy-font-family: Charter, "Bitstream Charter", Georgia, serif;
9
+ /* The size of the story text. The header's buttons are smaller, and don't change with it */
10
+ --squiffy-font-size: 1.125rem;
11
+ /* The space between lines of text */
12
+ --squiffy-line-height: 1.6;
13
+ }
14
+
15
+ /* Follow the reader's light or dark system setting, or what they chose with the theme button.
16
+ To keep a story light (or dark) whatever the setting, set ":root { color-scheme: light; }"
17
+ (or dark). These rules use :where() so that a :root rule like that overrides them, and the
18
+ theme button is hidden. */
19
+ :where(:root)
20
+ {
21
+ color-scheme: light dark;
22
+ }
23
+
24
+ :where(:root[data-squiffy-theme="light"])
25
+ {
26
+ color-scheme: light;
27
+ }
28
+
29
+ :where(:root[data-squiffy-theme="dark"])
30
+ {
31
+ color-scheme: dark;
32
+ }
33
+
34
+ body
35
+ {
36
+ margin: 0;
37
+ background-color: var(--squiffy-background);
38
+ color: var(--squiffy-text);
39
+ }
40
+
41
+ /* Wraps the header and the story: sets the page width and font */
42
+ div#squiffy-container
43
+ {
44
+ max-width: var(--squiffy-max-width);
45
+ margin-left: auto;
46
+ margin-right: auto;
47
+ padding: 0 1.25rem 3rem;
48
+ font-family: var(--squiffy-font-family);
49
+ line-height: var(--squiffy-line-height);
50
+ }
51
+
52
+ /* The bar above the story containing the Back, Restart and light/dark buttons. It stays at the
53
+ top of the window as the story scrolls under it. */
54
+ div#squiffy-header
55
+ {
56
+ position: sticky;
57
+ top: 0;
58
+ z-index: 1;
59
+ padding: 0.5rem 0;
60
+ background-color: var(--squiffy-background);
61
+ font-size: 0.875rem;
62
+ text-align: right;
63
+ white-space: nowrap;
64
+ }
65
+
66
+ /* A short fade under the header, so the story scrolls under it rather than being cut off */
67
+ div#squiffy-header::after
68
+ {
69
+ content: "";
70
+ position: absolute;
71
+ left: 0;
72
+ right: 0;
73
+ top: 100%;
74
+ height: 0.75rem;
75
+ background: linear-gradient(var(--squiffy-background), transparent);
76
+ pointer-events: none;
77
+ }
78
+
79
+ /* Space between the Back, Restart and light/dark buttons */
80
+ button.squiffy-header-button + button.squiffy-header-button
81
+ {
82
+ margin-left: 0.25em;
83
+ }
84
+
85
+ /* The button that switches between light and dark mode. It shows a moon in light mode and a sun
86
+ in dark mode. */
87
+ button#squiffy-theme:not([data-next="light"]) .squiffy-icon-light,
88
+ button#squiffy-theme[data-next="light"] .squiffy-icon-dark
89
+ {
90
+ display: none;
91
+ }
92
+
93
+ /* The mute button (#444), for a story with music or sounds. It shows a speaker, crossed out
94
+ when the story is muted. */
95
+ button#squiffy-mute.squiffy-muted .squiffy-icon-sound,
96
+ button#squiffy-mute:not(.squiffy-muted) .squiffy-icon-muted
97
+ {
98
+ display: none;
99
+ }
100
+
101
+ /* With a side panel (squiffy.json's "panels"), the page is wider, with the panel to the right of
102
+ the story. It stays in view as the story scrolls, under the header. On a narrower screen, it's a
103
+ button in the header instead. */
104
+ @media (min-width: 64rem)
105
+ {
106
+ div#squiffy-container.squiffy-has-side
107
+ {
108
+ display: grid;
109
+ grid-template-columns: minmax(0, 1fr) var(--squiffy-side-width);
110
+ column-gap: 2.5rem;
111
+ align-items: start;
112
+ max-width: calc(var(--squiffy-max-width) + var(--squiffy-side-width) + 2.5rem);
113
+ }
114
+
115
+ div#squiffy-container.squiffy-has-side > div#squiffy-header
116
+ {
117
+ grid-column: 1 / -1;
118
+ }
119
+
120
+ /* :where() takes the container's id out of the selector's specificity, so a story's own
121
+ aside.squiffy-panels-side { ... } rule, which comes after this, changes the border and the
122
+ padding too */
123
+ :where(div#squiffy-container.squiffy-has-side) > aside.squiffy-panels-side
124
+ {
125
+ position: sticky;
126
+ top: 3.5rem;
127
+ padding-left: 1.25rem;
128
+ border-left: 1px solid var(--squiffy-border);
129
+ max-height: calc(100vh - 4.5rem);
130
+ overflow-y: auto;
131
+ }
132
+ }
133
+
134
+ /* The story text */
135
+ div#squiffy
136
+ {
137
+ font-size: var(--squiffy-font-size);
138
+ }
139
+
140
+ div#squiffy :is(h1, h2, h3, h4, h5, h6)
141
+ {
142
+ line-height: 1.25;
143
+ }
144
+
145
+ div#squiffy p
146
+ {
147
+ text-wrap: pretty;
148
+ }
149
+
150
+ /* Stop images overflowing the page */
151
+ div#squiffy img
152
+ {
153
+ max-width: 100%;
154
+ height: auto;
155
+ }