squiffy-runtime 6.0.0-alpha.14 → 6.0.0-alpha.17

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 (46) hide show
  1. package/LICENSE +22 -0
  2. package/dist/animation.d.ts +11 -0
  3. package/dist/events.d.ts +8 -3
  4. package/dist/import.d.ts +4 -0
  5. package/dist/linkHandler.d.ts +8 -0
  6. package/dist/pluginManager.d.ts +23 -0
  7. package/dist/squiffy.runtime.d.ts +2 -2
  8. package/dist/squiffy.runtime.global.js +126 -0
  9. package/dist/squiffy.runtime.global.js.map +1 -0
  10. package/dist/squiffy.runtime.js +8785 -487
  11. package/dist/squiffy.runtime.js.map +1 -0
  12. package/dist/state.d.ts +19 -0
  13. package/dist/textProcessor.d.ts +8 -13
  14. package/dist/types.d.ts +5 -2
  15. package/dist/types.plugins.d.ts +27 -0
  16. package/dist/updater.d.ts +2 -0
  17. package/dist/utils.d.ts +1 -2
  18. package/package.json +13 -5
  19. package/src/__snapshots__/squiffy.runtime.test.ts.snap +53 -19
  20. package/src/animation.ts +68 -0
  21. package/src/events.ts +9 -10
  22. package/src/import.ts +5 -0
  23. package/src/linkHandler.ts +18 -0
  24. package/src/pluginManager.ts +74 -0
  25. package/src/plugins/animate.ts +97 -0
  26. package/src/plugins/index.ts +13 -0
  27. package/src/plugins/live.ts +83 -0
  28. package/src/plugins/random.ts +22 -0
  29. package/src/plugins/replaceLabel.ts +22 -0
  30. package/src/plugins/rotateSequence.ts +61 -0
  31. package/src/squiffy.runtime.test.ts +306 -134
  32. package/src/squiffy.runtime.ts +460 -332
  33. package/src/state.ts +106 -0
  34. package/src/textProcessor.ts +61 -166
  35. package/src/types.plugins.ts +41 -0
  36. package/src/types.ts +5 -2
  37. package/src/updater.ts +77 -0
  38. package/src/utils.ts +15 -12
  39. package/vite.config.ts +36 -0
  40. package/vitest.config.ts +9 -0
  41. package/vitest.setup.ts +16 -0
  42. package/dist/events.js +0 -35
  43. package/dist/squiffy.runtime.test.js +0 -394
  44. package/dist/textProcessor.js +0 -168
  45. package/dist/types.js +0 -1
  46. package/dist/utils.js +0 -14
package/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2014-2024 Alex Warren, textadventures.co.uk and contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
22
+
@@ -0,0 +1,11 @@
1
+ export declare class Animation {
2
+ animations: {
3
+ [name: string]: (el: HTMLElement, params: Record<string, any>, onComplete: () => void, loop: boolean) => void;
4
+ };
5
+ linkAnimations: Map<HTMLElement, () => void>;
6
+ registerAnimation(name: string, handler: (el: HTMLElement, params: Record<string, any>, onComplete: () => void, loop: boolean) => void): void;
7
+ runAnimation(name: string, el: HTMLElement, params: Record<string, any>, onComplete: () => void, loop: boolean): void;
8
+ addLinkAnimation(link: HTMLElement, fn: () => void): void;
9
+ runLinkAnimation(link: HTMLElement): void;
10
+ constructor();
11
+ }
package/dist/events.d.ts CHANGED
@@ -1,7 +1,13 @@
1
- type LinkType = 'section' | 'passage' | 'rotate' | 'sequence';
2
1
  export type SquiffyEventMap = {
3
2
  linkClick: {
4
- linkType: LinkType;
3
+ linkType: string;
4
+ };
5
+ set: {
6
+ attribute: string;
7
+ value: any;
8
+ };
9
+ canGoBackChanged: {
10
+ canGoBack: boolean;
5
11
  };
6
12
  };
7
13
  export type SquiffyEventHandler<E extends keyof SquiffyEventMap> = (payload: SquiffyEventMap[E]) => void;
@@ -12,4 +18,3 @@ export declare class Emitter<Events extends Record<string, any>> {
12
18
  once<E extends keyof Events>(event: E, handler: (p: Events[E]) => void): () => void;
13
19
  emit<E extends keyof Events>(event: E, payload: Events[E]): void;
14
20
  }
15
- export {};
@@ -0,0 +1,4 @@
1
+ import * as animejs from "animejs";
2
+ export declare const imports: {
3
+ animejs: typeof animejs;
4
+ };
@@ -0,0 +1,8 @@
1
+ import { HandleLinkResult } from './types.plugins.js';
2
+ export declare class LinkHandler {
3
+ linkHandlers: {
4
+ [type: string]: (el: HTMLElement) => HandleLinkResult;
5
+ };
6
+ registerLinkHandler(type: string, handler: (el: HTMLElement) => HandleLinkResult): void;
7
+ handleLink(link: HTMLElement): [found: boolean, type: string, result: HandleLinkResult];
8
+ }
@@ -0,0 +1,23 @@
1
+ import { TextProcessor } from './textProcessor.js';
2
+ import { SquiffyPlugin } from './types.plugins.js';
3
+ import { State } from './state.js';
4
+ import { LinkHandler } from './linkHandler.js';
5
+ import { Emitter, SquiffyEventMap } from './events.js';
6
+ import { Animation } from './animation.js';
7
+ export declare class PluginManager {
8
+ outputElement: HTMLElement;
9
+ textProcessor: TextProcessor;
10
+ state: State;
11
+ linkHandler: LinkHandler;
12
+ getSectionText: (name: string) => string | null;
13
+ getPassageText: (name: string) => string | null;
14
+ processText: (text: string, inline: boolean) => string;
15
+ addTransition: (fn: () => Promise<void>) => void;
16
+ emitter: Emitter<SquiffyEventMap>;
17
+ plugins: SquiffyPlugin[];
18
+ animation: Animation;
19
+ constructor(outputElement: HTMLElement, textProcessor: TextProcessor, state: State, linkHandler: LinkHandler, getSectionText: (name: string) => string | null, getPassageText: (name: string) => string | null, processText: (text: string, inline: boolean) => string, addTransition: (fn: () => Promise<void>) => void, animation: Animation, emitter: Emitter<SquiffyEventMap>);
20
+ add(plugin: SquiffyPlugin): void | Promise<void>;
21
+ onWrite(el: HTMLElement): void;
22
+ onLoad(): void;
23
+ }
@@ -1,3 +1,3 @@
1
1
  import { SquiffyApi, SquiffyInitOptions } from './types.js';
2
- export type { SquiffyApi } from "./types.js";
3
- export declare const init: (options: SquiffyInitOptions) => SquiffyApi;
2
+ export type { SquiffyApi } from './types.js';
3
+ export declare const init: (options: SquiffyInitOptions) => Promise<SquiffyApi>;