@makefully/fancifully 0.0.0-stage → 0.1.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.
- package/CHANGELOG.md +12 -0
- package/LICENSE +21 -0
- package/README.md +147 -3
- package/dist/Storybook.d.ts +69 -0
- package/dist/Storybook.d.ts.map +1 -0
- package/dist/audio/AudioBus.d.ts +21 -0
- package/dist/audio/AudioBus.d.ts.map +1 -0
- package/dist/audio/ReadAloudPlayer.d.ts +30 -0
- package/dist/audio/ReadAloudPlayer.d.ts.map +1 -0
- package/dist/fancifully.css +1 -0
- package/dist/fancifully.iife.js +8 -0
- package/dist/fancifully.js +4364 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/interaction/Pointer.d.ts +6 -0
- package/dist/interaction/Pointer.d.ts.map +1 -0
- package/dist/load/loadEpub.d.ts +15 -0
- package/dist/load/loadEpub.d.ts.map +1 -0
- package/dist/load/loadFanci.d.ts +16 -0
- package/dist/load/loadFanci.d.ts.map +1 -0
- package/dist/load/loadFonts.d.ts +3 -0
- package/dist/load/loadFonts.d.ts.map +1 -0
- package/dist/load/loadStory.d.ts +38 -0
- package/dist/load/loadStory.d.ts.map +1 -0
- package/dist/load/packageTypes.d.ts +11 -0
- package/dist/load/packageTypes.d.ts.map +1 -0
- package/dist/load/resolveUrl.d.ts +3 -0
- package/dist/load/resolveUrl.d.ts.map +1 -0
- package/dist/load/zipArchive.d.ts +11 -0
- package/dist/load/zipArchive.d.ts.map +1 -0
- package/dist/nav/Pager.d.ts +40 -0
- package/dist/nav/Pager.d.ts.map +1 -0
- package/dist/nav/layoutMode.d.ts +21 -0
- package/dist/nav/layoutMode.d.ts.map +1 -0
- package/dist/render/PageView.d.ts +13 -0
- package/dist/render/PageView.d.ts.map +1 -0
- package/dist/render/SpreadView.d.ts +32 -0
- package/dist/render/SpreadView.d.ts.map +1 -0
- package/dist/render/blocks/HotspotBlock.d.ts +5 -0
- package/dist/render/blocks/HotspotBlock.d.ts.map +1 -0
- package/dist/render/blocks/ImageBlock.d.ts +5 -0
- package/dist/render/blocks/ImageBlock.d.ts.map +1 -0
- package/dist/render/blocks/TextBlock.d.ts +5 -0
- package/dist/render/blocks/TextBlock.d.ts.map +1 -0
- package/dist/render/layout.d.ts +10 -0
- package/dist/render/layout.d.ts.map +1 -0
- package/dist/schema/story.d.ts +1542 -0
- package/dist/schema/story.d.ts.map +1 -0
- package/dist/springroll/bindApplication.d.ts +52 -0
- package/dist/springroll/bindApplication.d.ts.map +1 -0
- package/dist/springroll/loading.d.ts +31 -0
- package/dist/springroll/loading.d.ts.map +1 -0
- package/dist/sync/CueTimeline.d.ts +16 -0
- package/dist/sync/CueTimeline.d.ts.map +1 -0
- package/dist/sync/parseVtt.d.ts +5 -0
- package/dist/sync/parseVtt.d.ts.map +1 -0
- package/package.json +74 -6
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file.
|
|
4
|
+
|
|
5
|
+
## [0.1.0]
|
|
6
|
+
|
|
7
|
+
### Added
|
|
8
|
+
|
|
9
|
+
- Initial `@makefully/fancifully` release: DOM storybook engine with JSON / `.fanci` / EPUB loading
|
|
10
|
+
- Unified two-leaf spread paging (single viewport uses blank offscreen mate)
|
|
11
|
+
- SpringRoll volume/pause/captions binding and load `progress` / `loading` / delayed `loaded`
|
|
12
|
+
- VO↔text sync via WebVTT or inline cues; text, image, and hotspot blocks
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Makefully Studios
|
|
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.
|
package/README.md
CHANGED
|
@@ -1,3 +1,147 @@
|
|
|
1
|
-
#
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
# @makefully/fancifully
|
|
2
|
+
|
|
3
|
+
DOM-based interactive storybook engine with SpringRoll-friendly audio buses, VO↔text cue sync, hotspots, and a unified two-leaf page flip (single-page mode keeps a blank leaf offscreen so turns animate the same way).
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @makefully/fancifully
|
|
9
|
+
# optional peer for host mute/volume/captions
|
|
10
|
+
npm install springroll
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Publishing (maintainers)
|
|
14
|
+
|
|
15
|
+
Releases match other Makefully packages (`@makefully/platypus`, `@makefully/notefully`):
|
|
16
|
+
|
|
17
|
+
1. Bump `version` in `package.json` and add a `## [x.y.z]` section in `CHANGELOG.md`.
|
|
18
|
+
2. Merge to `main` (or run the **Release** workflow manually).
|
|
19
|
+
3. GitHub Actions tests, builds, publishes to npm via **OIDC trusted publisher**, and creates a GitHub release.
|
|
20
|
+
|
|
21
|
+
One-time npm setup (org owner): on [npmjs.com](https://www.npmjs.com) → `@makefully` → **Trusted Publishers** → add GitHub Actions for repo `Makefully-Studios/fancifully`, workflow `release.yml`, environment blank / as configured.
|
|
22
|
+
|
|
23
|
+
Local dry-run: `npm run pack:check`
|
|
24
|
+
|
|
25
|
+
## Quick start (standalone)
|
|
26
|
+
|
|
27
|
+
```ts
|
|
28
|
+
import { Storybook } from '@makefully/fancifully';
|
|
29
|
+
import '@makefully/fancifully/fancifully.css';
|
|
30
|
+
|
|
31
|
+
const book = await Storybook.create(document.getElementById('app')!, {
|
|
32
|
+
story: './stories/demo/story.json', // or './book.fanci' / './book.epub' / File
|
|
33
|
+
baseUrl: './stories/demo/', // used for loose JSON + relative assets
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
book.next();
|
|
37
|
+
book.prev();
|
|
38
|
+
book.playReadAloud();
|
|
39
|
+
book.setLayoutMode('auto'); // 'single' | 'two-page' | 'auto'
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
## Embed with SpringRoll (Platypus-like)
|
|
43
|
+
|
|
44
|
+
```ts
|
|
45
|
+
import { Application } from 'springroll';
|
|
46
|
+
import { Storybook } from '@makefully/fancifully';
|
|
47
|
+
import '@makefully/fancifully/fancifully.css';
|
|
48
|
+
|
|
49
|
+
const app = new Application({
|
|
50
|
+
features: {
|
|
51
|
+
sound: true,
|
|
52
|
+
soundVolume: true,
|
|
53
|
+
vo: true,
|
|
54
|
+
voVolume: true,
|
|
55
|
+
sfx: true,
|
|
56
|
+
captions: true,
|
|
57
|
+
},
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
const book = await Storybook.create(container, {
|
|
61
|
+
story: myStoryObject, // or URL
|
|
62
|
+
baseUrl: '/books/hill/',
|
|
63
|
+
springroll: app,
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
book.on('pagechange', ({ pageIds, index, layoutMode }) => {
|
|
67
|
+
console.log(pageIds, index, layoutMode);
|
|
68
|
+
});
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
If `springroll` is omitted, Fancifully creates an `Application` (when the peer is available) and **holds SpringRoll `loaded` / `state.ready` until the story package is unpacked and assets are loaded** — same idea as Platypus waiting on preload before the container hides its loading UI.
|
|
72
|
+
|
|
73
|
+
While loading, Fancifully reports:
|
|
74
|
+
|
|
75
|
+
| Bellhop event | Payload |
|
|
76
|
+
|---------------|---------|
|
|
77
|
+
| `progress` | `number` 0–1 (classic Container loading bar) |
|
|
78
|
+
| `loading` | `{ stage, progress, count?, total?, detail? }` |
|
|
79
|
+
|
|
80
|
+
```ts
|
|
81
|
+
await Storybook.create(el, {
|
|
82
|
+
story: './book.fanci',
|
|
83
|
+
onProgress: ({ stage, progress }) => console.log(stage, progress),
|
|
84
|
+
});
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
## Story formats
|
|
88
|
+
|
|
89
|
+
| Input | Extension | Notes |
|
|
90
|
+
|-------|-----------|--------|
|
|
91
|
+
| Fancifully JSON | `.json` | Full fidelity; `baseUrl` resolves relative assets |
|
|
92
|
+
| Fancifully package | **`.fanci`** | ZIP of `story.json` + images/audio/vtt/fonts (relative paths). (`.fan` is already used by other software.) |
|
|
93
|
+
| EPUB | `.epub` | Import subset: spine pages, images, fonts/audio when present, Media Overlays → cues. No hotspots. |
|
|
94
|
+
|
|
95
|
+
```ts
|
|
96
|
+
// Packaged book
|
|
97
|
+
await Storybook.create(el, { story: './tales/hill.fanci' });
|
|
98
|
+
|
|
99
|
+
// EPUB (read-aloud if Media Overlays exist)
|
|
100
|
+
await Storybook.create(el, { story: fileInput.files[0], storyName: fileInput.files[0].name });
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
Pack a folder into `.fanci`:
|
|
104
|
+
|
|
105
|
+
```bash
|
|
106
|
+
npm run pack:fanci
|
|
107
|
+
# or: node scripts/pack-fanci.mjs path/to/story-dir out.fanci
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
## Story JSON
|
|
111
|
+
|
|
112
|
+
Stories are JSON packages (not a single HTML document). Text may embed HTML; images/audio/vtt are asset references.
|
|
113
|
+
|
|
114
|
+
| Field | Purpose |
|
|
115
|
+
|-------|---------|
|
|
116
|
+
| `pageSize` | Authoring pixel size per leaf |
|
|
117
|
+
| `layout.mode` | `single` \| `two-page` \| `auto` |
|
|
118
|
+
| `layout.singleBreakpoint` | Width where `auto` switches to two-page |
|
|
119
|
+
| `assets` | Map of image / audio / vtt / html |
|
|
120
|
+
| `pages[].blocks` | `text`, `image`, `hotspot` with `layout` boxes |
|
|
121
|
+
| `pages[].readAloud` | `{ audio, cues }` — cues are a VTT asset id or inline `{id,start,end}[]` |
|
|
122
|
+
|
|
123
|
+
### Layout modes
|
|
124
|
+
|
|
125
|
+
- **Always** a left+right spread under the hood.
|
|
126
|
+
- **`two-page`**: both leaves visible.
|
|
127
|
+
- **`single`**: leading blank leaf stays offscreen; same flip animation.
|
|
128
|
+
- **`auto`**: picks by container width.
|
|
129
|
+
|
|
130
|
+
Cover is blank+cover; interior pages pair; a final orphan gets a blank mate.
|
|
131
|
+
|
|
132
|
+
### VO ↔ text
|
|
133
|
+
|
|
134
|
+
Put stable `id`s on spans in text HTML. WebVTT cue identifiers should match those ids. While VO plays, matching spans get `is-active` / `is-read`. A separate captions line respects SpringRoll `captionsMuted`.
|
|
135
|
+
|
|
136
|
+
## Scripts
|
|
137
|
+
|
|
138
|
+
```bash
|
|
139
|
+
npm install
|
|
140
|
+
npm test
|
|
141
|
+
npm run dev # demo (Vite; default port 5174, or next free port)
|
|
142
|
+
npm run build # dist library + types
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
## License
|
|
146
|
+
|
|
147
|
+
MIT
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import type { StorySource } from './load/packageTypes.js';
|
|
2
|
+
import { type PagerEvents } from './nav/Pager.js';
|
|
3
|
+
import type { LayoutMode, Story } from './schema/story.js';
|
|
4
|
+
import { type SpringrollLike } from './springroll/bindApplication.js';
|
|
5
|
+
import { type LoadProgress } from './springroll/loading.js';
|
|
6
|
+
export type StorybookOptions = {
|
|
7
|
+
/** JSON URL/object, `.fanci` / `.epub` URL, or File/Blob/ArrayBuffer */
|
|
8
|
+
story: StorySource | Story;
|
|
9
|
+
baseUrl?: string;
|
|
10
|
+
/** Filename hint when `story` is raw bytes */
|
|
11
|
+
storyName?: string;
|
|
12
|
+
springroll?: SpringrollLike | null;
|
|
13
|
+
features?: Record<string, boolean>;
|
|
14
|
+
autoPlayReadAloud?: boolean;
|
|
15
|
+
/** Extra progress listener (SpringRoll Container also receives progress/loading). */
|
|
16
|
+
onProgress?: (progress: LoadProgress) => void;
|
|
17
|
+
};
|
|
18
|
+
type StorybookEvents = PagerEvents & {
|
|
19
|
+
ready: {
|
|
20
|
+
story: Story;
|
|
21
|
+
};
|
|
22
|
+
loading: LoadProgress;
|
|
23
|
+
};
|
|
24
|
+
type Listener<K extends keyof StorybookEvents> = (payload: StorybookEvents[K]) => void;
|
|
25
|
+
export declare class Storybook {
|
|
26
|
+
readonly element: HTMLElement;
|
|
27
|
+
private root;
|
|
28
|
+
private stage;
|
|
29
|
+
private chrome;
|
|
30
|
+
private captionsEl;
|
|
31
|
+
private loaded;
|
|
32
|
+
private spreadView;
|
|
33
|
+
private pager;
|
|
34
|
+
private bus;
|
|
35
|
+
private readAloud;
|
|
36
|
+
private springroll;
|
|
37
|
+
private bindings;
|
|
38
|
+
private sfxAudio;
|
|
39
|
+
private unbindSwipe;
|
|
40
|
+
private resizeObserver;
|
|
41
|
+
private listeners;
|
|
42
|
+
private destroyed;
|
|
43
|
+
private constructor();
|
|
44
|
+
static create(container: HTMLElement, options: StorybookOptions): Promise<Storybook>;
|
|
45
|
+
get story(): Story;
|
|
46
|
+
get layoutMode(): import("./schema/story.js").ResolvedLayoutMode;
|
|
47
|
+
get pageIds(): string[];
|
|
48
|
+
get spreadIndex(): number;
|
|
49
|
+
on<K extends keyof StorybookEvents>(event: K, fn: Listener<K>): () => void;
|
|
50
|
+
next(): Promise<void>;
|
|
51
|
+
prev(): Promise<void>;
|
|
52
|
+
goTo(pageId: string): Promise<void>;
|
|
53
|
+
setLayoutMode(mode: LayoutMode): void;
|
|
54
|
+
playReadAloud(): Promise<void>;
|
|
55
|
+
pause(): void;
|
|
56
|
+
resume(): void;
|
|
57
|
+
destroy(): void;
|
|
58
|
+
private wireChrome;
|
|
59
|
+
private wirePager;
|
|
60
|
+
private wireSpringroll;
|
|
61
|
+
private wireResize;
|
|
62
|
+
private layoutStage;
|
|
63
|
+
private buildReadAloudClips;
|
|
64
|
+
private resolveCues;
|
|
65
|
+
private handleTapActions;
|
|
66
|
+
private emit;
|
|
67
|
+
}
|
|
68
|
+
export {};
|
|
69
|
+
//# sourceMappingURL=Storybook.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Storybook.d.ts","sourceRoot":"","sources":["../src/Storybook.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAC1D,OAAO,EAAS,KAAK,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAEzD,OAAO,KAAK,EAAO,UAAU,EAAE,KAAK,EAAa,MAAM,mBAAmB,CAAC;AAC3E,OAAO,EAIL,KAAK,cAAc,EACpB,MAAM,iCAAiC,CAAC;AACzC,OAAO,EAEL,KAAK,YAAY,EAClB,MAAM,yBAAyB,CAAC;AAEjC,MAAM,MAAM,gBAAgB,GAAG;IAC7B,wEAAwE;IACxE,KAAK,EAAE,WAAW,GAAG,KAAK,CAAC;IAC3B,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,8CAA8C;IAC9C,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,UAAU,CAAC,EAAE,cAAc,GAAG,IAAI,CAAC;IACnC,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACnC,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAC5B,qFAAqF;IACrF,UAAU,CAAC,EAAE,CAAC,QAAQ,EAAE,YAAY,KAAK,IAAI,CAAC;CAC/C,CAAC;AAEF,KAAK,eAAe,GAAG,WAAW,GAAG;IACnC,KAAK,EAAE;QAAE,KAAK,EAAE,KAAK,CAAA;KAAE,CAAC;IACxB,OAAO,EAAE,YAAY,CAAC;CACvB,CAAC;AAEF,KAAK,QAAQ,CAAC,CAAC,SAAS,MAAM,eAAe,IAAI,CAAC,OAAO,EAAE,eAAe,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC;AAcvF,qBAAa,SAAS;IACpB,QAAQ,CAAC,OAAO,EAAE,WAAW,CAAC;IAC9B,OAAO,CAAC,IAAI,CAAc;IAC1B,OAAO,CAAC,KAAK,CAAc;IAC3B,OAAO,CAAC,MAAM,CAAc;IAC5B,OAAO,CAAC,UAAU,CAAc;IAChC,OAAO,CAAC,MAAM,CAAc;IAC5B,OAAO,CAAC,UAAU,CAAa;IAC/B,OAAO,CAAC,KAAK,CAAQ;IACrB,OAAO,CAAC,GAAG,CAAkB;IAC7B,OAAO,CAAC,SAAS,CAAkB;IACnC,OAAO,CAAC,UAAU,CAAwB;IAC1C,OAAO,CAAC,QAAQ,CAAmD;IACnE,OAAO,CAAC,QAAQ,CAAmB;IACnC,OAAO,CAAC,WAAW,CAA6B;IAChD,OAAO,CAAC,cAAc,CAA+B;IACrD,OAAO,CAAC,SAAS,CAA2D;IAC5E,OAAO,CAAC,SAAS,CAAS;IAE1B,OAAO;WAqEM,MAAM,CAAC,SAAS,EAAE,WAAW,EAAE,OAAO,EAAE,gBAAgB,GAAG,OAAO,CAAC,SAAS,CAAC;IAmD1F,IAAI,KAAK,IAAI,KAAK,CAEjB;IAED,IAAI,UAAU,mDAEb;IAED,IAAI,OAAO,IAAI,MAAM,EAAE,CAEtB;IAED,IAAI,WAAW,IAAI,MAAM,CAExB;IAED,EAAE,CAAC,CAAC,SAAS,MAAM,eAAe,EAAE,KAAK,EAAE,CAAC,EAAE,EAAE,EAAE,QAAQ,CAAC,CAAC,CAAC,GAAG,MAAM,IAAI;IAM1E,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;IAKrB,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;IAKrB,IAAI,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAKnC,aAAa,CAAC,IAAI,EAAE,UAAU,GAAG,IAAI;IAMrC,aAAa,IAAI,OAAO,CAAC,IAAI,CAAC;IAK9B,KAAK,IAAI,IAAI;IAKb,MAAM,IAAI,IAAI;IAKd,OAAO,IAAI,IAAI;IAcf,OAAO,CAAC,UAAU;IAMlB,OAAO,CAAC,SAAS;IAWjB,OAAO,CAAC,cAAc;IAUtB,OAAO,CAAC,UAAU;IAalB,OAAO,CAAC,WAAW;IAWnB,OAAO,CAAC,mBAAmB;IA+B3B,OAAO,CAAC,WAAW;IAMnB,OAAO,CAAC,gBAAgB;IAexB,OAAO,CAAC,IAAI;CAKb"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { AudioChannel } from '../schema/story.js';
|
|
2
|
+
export type VolumeState = {
|
|
3
|
+
sound: number;
|
|
4
|
+
vo: number;
|
|
5
|
+
sfx: number;
|
|
6
|
+
music: number;
|
|
7
|
+
};
|
|
8
|
+
export declare class AudioBus {
|
|
9
|
+
private volumes;
|
|
10
|
+
private elements;
|
|
11
|
+
private paused;
|
|
12
|
+
setVolume(channel: keyof VolumeState, value: number): void;
|
|
13
|
+
getVolume(channel: AudioChannel): number;
|
|
14
|
+
setPaused(paused: boolean): void;
|
|
15
|
+
get isPaused(): boolean;
|
|
16
|
+
register(el: HTMLAudioElement, channel: AudioChannel): void;
|
|
17
|
+
unregister(el: HTMLAudioElement): void;
|
|
18
|
+
applyTo(el: HTMLAudioElement, channel: AudioChannel): void;
|
|
19
|
+
private applyAll;
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=AudioBus.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AudioBus.d.ts","sourceRoot":"","sources":["../../src/audio/AudioBus.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAEvD,MAAM,MAAM,WAAW,GAAG;IACxB,KAAK,EAAE,MAAM,CAAC;IACd,EAAE,EAAE,MAAM,CAAC;IACX,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,EAAE,MAAM,CAAC;CACf,CAAC;AAEF,qBAAa,QAAQ;IACnB,OAAO,CAAC,OAAO,CAKb;IACF,OAAO,CAAC,QAAQ,CAA+B;IAC/C,OAAO,CAAC,MAAM,CAAS;IAEvB,SAAS,CAAC,OAAO,EAAE,MAAM,WAAW,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI;IAK1D,SAAS,CAAC,OAAO,EAAE,YAAY,GAAG,MAAM;IAIxC,SAAS,CAAC,MAAM,EAAE,OAAO,GAAG,IAAI;IAShC,IAAI,QAAQ,IAAI,OAAO,CAEtB;IAED,QAAQ,CAAC,EAAE,EAAE,gBAAgB,EAAE,OAAO,EAAE,YAAY,GAAG,IAAI;IAM3D,UAAU,CAAC,EAAE,EAAE,gBAAgB,GAAG,IAAI;IAItC,OAAO,CAAC,EAAE,EAAE,gBAAgB,EAAE,OAAO,EAAE,YAAY,GAAG,IAAI;IAI1D,OAAO,CAAC,QAAQ;CAMjB"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { Cue } from '../schema/story.js';
|
|
2
|
+
import type { AudioBus } from './AudioBus.js';
|
|
3
|
+
export type ReadAloudClip = {
|
|
4
|
+
url: string;
|
|
5
|
+
channel: 'vo' | 'sfx' | 'music';
|
|
6
|
+
cues: Cue[];
|
|
7
|
+
root: ParentNode | null;
|
|
8
|
+
};
|
|
9
|
+
export declare class ReadAloudPlayer {
|
|
10
|
+
private bus;
|
|
11
|
+
private audio;
|
|
12
|
+
private timeline;
|
|
13
|
+
private queue;
|
|
14
|
+
private raf;
|
|
15
|
+
private captionsMuted;
|
|
16
|
+
private onCaptionLine;
|
|
17
|
+
private playing;
|
|
18
|
+
constructor(bus: AudioBus);
|
|
19
|
+
setCaptionsMuted(muted: boolean): void;
|
|
20
|
+
onCaption(handler: (text: string | null) => void): void;
|
|
21
|
+
playSequence(clips: ReadAloudClip[]): Promise<void>;
|
|
22
|
+
pause(): void;
|
|
23
|
+
resume(): void;
|
|
24
|
+
stop(): void;
|
|
25
|
+
destroy(): void;
|
|
26
|
+
private playNext;
|
|
27
|
+
private startTick;
|
|
28
|
+
private cancelTick;
|
|
29
|
+
}
|
|
30
|
+
//# sourceMappingURL=ReadAloudPlayer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ReadAloudPlayer.d.ts","sourceRoot":"","sources":["../../src/audio/ReadAloudPlayer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,oBAAoB,CAAC;AAE9C,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAE9C,MAAM,MAAM,aAAa,GAAG;IAC1B,GAAG,EAAE,MAAM,CAAC;IACZ,OAAO,EAAE,IAAI,GAAG,KAAK,GAAG,OAAO,CAAC;IAChC,IAAI,EAAE,GAAG,EAAE,CAAC;IACZ,IAAI,EAAE,UAAU,GAAG,IAAI,CAAC;CACzB,CAAC;AAEF,qBAAa,eAAe;IAC1B,OAAO,CAAC,GAAG,CAAW;IACtB,OAAO,CAAC,KAAK,CAAmB;IAChC,OAAO,CAAC,QAAQ,CAAqB;IACrC,OAAO,CAAC,KAAK,CAAuB;IACpC,OAAO,CAAC,GAAG,CAAK;IAChB,OAAO,CAAC,aAAa,CAAS;IAC9B,OAAO,CAAC,aAAa,CAAgD;IACrE,OAAO,CAAC,OAAO,CAAS;gBAEZ,GAAG,EAAE,QAAQ;IAQzB,gBAAgB,CAAC,KAAK,EAAE,OAAO,GAAG,IAAI;IAOtC,SAAS,CAAC,OAAO,EAAE,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,KAAK,IAAI,GAAG,IAAI;IAIjD,YAAY,CAAC,KAAK,EAAE,aAAa,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IAQzD,KAAK,IAAI,IAAI;IAKb,MAAM,IAAI,IAAI;IAMd,IAAI,IAAI,IAAI;IAWZ,OAAO,IAAI,IAAI;YAKD,QAAQ;IAyBtB,OAAO,CAAC,SAAS;IAejB,OAAO,CAAC,UAAU;CAMnB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
.fc-root{--fc-bg: #e8e2d6;--fc-page-bg: #faf6ef;--fc-ink: #1f1a14;--fc-accent: #c45c26;--fc-cue-active-bg: rgba(196, 92, 38, .28);--fc-cue-read-bg: rgba(196, 92, 38, .12);--fc-chrome-bg: rgba(31, 26, 20, .88);--fc-chrome-fg: #faf6ef;box-sizing:border-box;position:relative;display:flex;flex-direction:column;width:100%;height:100%;min-height:360px;background:radial-gradient(ellipse at 20% 0%,rgba(255,255,255,.45),transparent 50%),linear-gradient(160deg,#f0e6d4 0%,var(--fc-bg) 45%,#d9cfc0 100%);color:var(--fc-ink);font-family:Georgia,Times New Roman,serif;outline:none;overflow:hidden}.fc-root *,.fc-root *:before,.fc-root *:after{box-sizing:border-box}.fc-stage{position:relative;flex:1;display:flex;align-items:center;justify-content:center;overflow:hidden;touch-action:pan-y}.fc-spread-viewport{position:relative;overflow:hidden}.fc-spread-viewport-single{overflow:hidden}.fc-spread{--fc-page-width: 768px;--fc-page-height: 1024px;position:relative;display:flex;flex-direction:row;transform-origin:center center;will-change:transform}.fc-leaf{position:relative;width:var(--fc-page-width);height:var(--fc-page-height);flex:0 0 auto;overflow:hidden;background:var(--fc-page-bg);box-shadow:inset 0 0 0 1px #1f1a1414}.fc-leaf-left{border-radius:4px 0 0 4px}.fc-leaf-right{border-radius:0 4px 4px 0;box-shadow:inset 0 0 0 1px #1f1a1414,-6px 0 18px #1f1a141f}.fc-page{position:relative;width:100%;height:100%;overflow:hidden}.fc-page-blank{background:transparent;box-shadow:none}.fc-block{position:absolute}.fc-block-text{z-index:2;line-height:1.35}.fc-block-image{z-index:1;overflow:hidden}.fc-block-image img{display:block;width:100%;height:100%;pointer-events:none;-webkit-user-select:none;user-select:none}.fc-block-hotspot{z-index:3;margin:0;padding:0;border:2px dashed transparent;background:transparent;cursor:pointer}.fc-block-hotspot:focus-visible{border-color:var(--fc-accent);outline:none}.fc-block-hotspot:hover{background:#c45c2614}.fc-cue.is-active{background:var(--fc-cue-active-bg);border-radius:.15em}.fc-cue.is-read:not(.is-active){background:var(--fc-cue-read-bg);border-radius:.15em}.fc-captions{position:absolute;left:50%;bottom:4.5rem;transform:translate(-50%);max-width:min(36rem,90%);padding:.4rem .75rem;border-radius:.35rem;background:#1f1a14d1;color:#fff;font-size:.95rem;text-align:center;pointer-events:none;z-index:5}.fc-captions:empty,.fc-captions[hidden]{display:none}.fc-chrome{display:flex;gap:.5rem;justify-content:center;align-items:center;padding:.65rem;background:var(--fc-chrome-bg);color:var(--fc-chrome-fg)}.fc-btn{-webkit-appearance:none;-moz-appearance:none;appearance:none;border:1px solid rgba(250,246,239,.35);background:transparent;color:inherit;font:inherit;font-size:.95rem;padding:.4rem .9rem;border-radius:.3rem;cursor:pointer}.fc-btn:hover,.fc-btn:focus-visible{background:#faf6ef1f;outline:none}.fc-btn-read{background:var(--fc-accent);border-color:transparent;color:#fff}.fc-spread.fc-turn-next .fc-leaf-right{animation:fc-flip-next .4s ease forwards;transform-origin:left center}.fc-spread.fc-turn-prev .fc-leaf-left{animation:fc-flip-prev .4s ease forwards;transform-origin:right center}@keyframes fc-flip-next{0%{transform:perspective(1200px) rotateY(0)}to{transform:perspective(1200px) rotateY(-90deg)}}@keyframes fc-flip-prev{0%{transform:perspective(1200px) rotateY(0)}to{transform:perspective(1200px) rotateY(90deg)}}.fc-block-image.lit{filter:brightness(1.15) saturate(1.1);box-shadow:0 0 24px #ffc85073}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
var Fancifully=(function(T){"use strict";var hr=Object.defineProperty;var pr=(T,Y,te)=>Y in T?hr(T,Y,{enumerable:!0,configurable:!0,writable:!0,value:te}):T[Y]=te;var g=(T,Y,te)=>pr(T,typeof Y!="symbol"?Y+"":Y,te);class Y{constructor(){g(this,"volumes",{sound:1,vo:1,sfx:1,music:1});g(this,"elements",new Set);g(this,"paused",!1)}setVolume(e,t){this.volumes[e]=te(t),this.applyAll()}getVolume(e){return te(this.volumes.sound)*te(this.volumes[e])}setPaused(e){this.paused=e;for(const t of this.elements)e&&t.pause()}get isPaused(){return this.paused}register(e,t){this.elements.add(e),e.volume=this.getVolume(t),e.dataset.fcChannel=t}unregister(e){this.elements.delete(e)}applyTo(e,t){e.volume=this.getVolume(t)}applyAll(){for(const e of this.elements){const t=e.dataset.fcChannel||"vo";e.volume=this.getVolume(t)}}}function te(s){return Number.isNaN(s)?0:Math.min(1,Math.max(0,s))}class Rt{constructor(e=[]){g(this,"cues");g(this,"root",null);g(this,"lastActiveId",null);g(this,"readIds",new Set);this.cues=[...e].sort((t,n)=>t.start-n.start)}setCues(e){this.cues=[...e].sort((t,n)=>t.start-n.start),this.reset()}attach(e){this.root=e,this.resetHighlight()}reset(){this.lastActiveId=null,this.readIds.clear(),this.resetHighlight()}update(e){const t=this.cues.find(n=>e>=n.start&&e<n.end)??null;return this.root&&(t?(this.readIds.add(t.id),t.id!==this.lastActiveId&&(this.applyHighlight(t.id),this.lastActiveId=t.id)):this.lastActiveId&&(this.clearActive(),this.lastActiveId=null)),t}applyHighlight(e){if(!this.root)return;this.root.querySelectorAll(".fc-cue.is-active").forEach(n=>n.classList.remove("is-active"));const t=this.root.querySelector(`#${Lt(e)}, [data-cue-id="${Mt(e)}"]`);t&&t.classList.add("fc-cue","is-active","is-read");for(const n of this.readIds){if(n===e)continue;const r=this.root.querySelector(`#${Lt(n)}, [data-cue-id="${Mt(n)}"]`);r==null||r.classList.add("fc-cue","is-read")}}clearActive(){var e;(e=this.root)==null||e.querySelectorAll(".fc-cue.is-active").forEach(t=>t.classList.remove("is-active"))}resetHighlight(){var e;(e=this.root)==null||e.querySelectorAll(".fc-cue").forEach(t=>{t.classList.remove("is-active","is-read")})}}function Lt(s){return typeof CSS<"u"&&typeof CSS.escape=="function"?CSS.escape(s):s.replace(/[^a-zA-Z0-9_-]/g,"\\$&")}function Mt(s){return s.replace(/\\/g,"\\\\").replace(/"/g,'\\"')}class Ns{constructor(e){g(this,"bus");g(this,"audio");g(this,"timeline",new Rt);g(this,"queue",[]);g(this,"raf",0);g(this,"captionsMuted",!1);g(this,"onCaptionLine",null);g(this,"playing",!1);this.bus=e,this.audio=new Audio,this.audio.preload="auto",this.bus.register(this.audio,"vo"),this.audio.addEventListener("ended",()=>this.playNext())}setCaptionsMuted(e){var t;this.captionsMuted=e,e&&((t=this.onCaptionLine)==null||t.call(this,null))}onCaption(e){this.onCaptionLine=e}async playSequence(e){this.stop(),this.queue=e.filter(t=>!!t.url),this.queue.length!==0&&(this.playing=!0,await this.playNext())}pause(){this.audio.pause(),this.cancelTick()}resume(){!this.playing||this.bus.isPaused||(this.audio.play().catch(()=>{}),this.startTick())}stop(){var e;this.playing=!1,this.queue=[],this.audio.pause(),this.audio.removeAttribute("src"),this.audio.load(),this.timeline.reset(),this.cancelTick(),(e=this.onCaptionLine)==null||e.call(this,null)}destroy(){this.stop(),this.bus.unregister(this.audio)}async playNext(){var t;this.cancelTick();const e=this.queue.shift();if(!e){this.playing=!1,this.timeline.reset(),(t=this.onCaptionLine)==null||t.call(this,null);return}this.timeline.setCues(e.cues),this.timeline.attach(e.root),this.bus.register(this.audio,e.channel),this.audio.src=e.url,this.bus.applyTo(this.audio,e.channel);try{await this.audio.play(),this.startTick()}catch{this.startTick()}}startTick(){this.cancelTick();const e=()=>{var t;if(this.playing){if(!this.bus.isPaused&&!this.audio.paused){const n=this.timeline.update(this.audio.currentTime);this.captionsMuted||(t=this.onCaptionLine)==null||t.call(this,(n==null?void 0:n.text)??(n==null?void 0:n.id)??null)}this.raf=requestAnimationFrame(e)}};this.raf=requestAnimationFrame(e)}cancelTick(){this.raf&&(cancelAnimationFrame(this.raf),this.raf=0)}}function Is(s,e){let t=0,n=0,r=!1;const i=c=>{c.button!=null&&c.button!==0||(r=!0,t=c.clientX,n=c.clientY)},a=c=>{var h,y;if(!r)return;r=!1;const l=c.clientX-t,d=c.clientY-n;Math.abs(l)<50||Math.abs(l)<Math.abs(d)||(l<0?(h=e.onSwipeLeft)==null||h.call(e):(y=e.onSwipeRight)==null||y.call(e))},o=()=>{r=!1};return s.addEventListener("pointerdown",i),s.addEventListener("pointerup",a),s.addEventListener("pointercancel",o),()=>{s.removeEventListener("pointerdown",i),s.removeEventListener("pointerup",a),s.removeEventListener("pointercancel",o)}}var x;(function(s){s.assertEqual=r=>{};function e(r){}s.assertIs=e;function t(r){throw new Error}s.assertNever=t,s.arrayToEnum=r=>{const i={};for(const a of r)i[a]=a;return i},s.getValidEnumValues=r=>{const i=s.objectKeys(r).filter(o=>typeof r[r[o]]!="number"),a={};for(const o of i)a[o]=r[o];return s.objectValues(a)},s.objectValues=r=>s.objectKeys(r).map(function(i){return r[i]}),s.objectKeys=typeof Object.keys=="function"?r=>Object.keys(r):r=>{const i=[];for(const a in r)Object.prototype.hasOwnProperty.call(r,a)&&i.push(a);return i},s.find=(r,i)=>{for(const a of r)if(i(a))return a},s.isInteger=typeof Number.isInteger=="function"?r=>Number.isInteger(r):r=>typeof r=="number"&&Number.isFinite(r)&&Math.floor(r)===r;function n(r,i=" | "){return r.map(a=>typeof a=="string"?`'${a}'`:a).join(i)}s.joinValues=n,s.jsonStringifyReplacer=(r,i)=>typeof i=="bigint"?i.toString():i})(x||(x={}));var Zt;(function(s){s.mergeShapes=(e,t)=>({...e,...t})})(Zt||(Zt={}));const p=x.arrayToEnum(["string","nan","number","integer","float","boolean","date","bigint","symbol","function","undefined","null","array","object","unknown","promise","void","never","map","set"]),se=s=>{switch(typeof s){case"undefined":return p.undefined;case"string":return p.string;case"number":return Number.isNaN(s)?p.nan:p.number;case"boolean":return p.boolean;case"function":return p.function;case"bigint":return p.bigint;case"symbol":return p.symbol;case"object":return Array.isArray(s)?p.array:s===null?p.null:s.then&&typeof s.then=="function"&&s.catch&&typeof s.catch=="function"?p.promise:typeof Map<"u"&&s instanceof Map?p.map:typeof Set<"u"&&s instanceof Set?p.set:typeof Date<"u"&&s instanceof Date?p.date:p.object;default:return p.unknown}},u=x.arrayToEnum(["invalid_type","invalid_literal","custom","invalid_union","invalid_union_discriminator","invalid_enum_value","unrecognized_keys","invalid_arguments","invalid_return_type","invalid_date","invalid_string","too_small","too_big","invalid_intersection_types","not_multiple_of","not_finite"]);class G extends Error{get errors(){return this.issues}constructor(e){super(),this.issues=[],this.addIssue=n=>{this.issues=[...this.issues,n]},this.addIssues=(n=[])=>{this.issues=[...this.issues,...n]};const t=new.target.prototype;Object.setPrototypeOf?Object.setPrototypeOf(this,t):this.__proto__=t,this.name="ZodError",this.issues=e}format(e){const t=e||function(i){return i.message},n={_errors:[]},r=i=>{for(const a of i.issues)if(a.code==="invalid_union")a.unionErrors.map(r);else if(a.code==="invalid_return_type")r(a.returnTypeError);else if(a.code==="invalid_arguments")r(a.argumentsError);else if(a.path.length===0)n._errors.push(t(a));else{let o=n,c=0;for(;c<a.path.length;){const l=a.path[c];c===a.path.length-1?(o[l]=o[l]||{_errors:[]},o[l]._errors.push(t(a))):o[l]=o[l]||{_errors:[]},o=o[l],c++}}};return r(this),n}static assert(e){if(!(e instanceof G))throw new Error(`Not a ZodError: ${e}`)}toString(){return this.message}get message(){return JSON.stringify(this.issues,x.jsonStringifyReplacer,2)}get isEmpty(){return this.issues.length===0}flatten(e=t=>t.message){const t={},n=[];for(const r of this.issues)if(r.path.length>0){const i=r.path[0];t[i]=t[i]||[],t[i].push(e(r))}else n.push(e(r));return{formErrors:n,fieldErrors:t}}get formErrors(){return this.flatten()}}G.create=s=>new G(s);const nt=(s,e)=>{let t;switch(s.code){case u.invalid_type:s.received===p.undefined?t="Required":t=`Expected ${s.expected}, received ${s.received}`;break;case u.invalid_literal:t=`Invalid literal value, expected ${JSON.stringify(s.expected,x.jsonStringifyReplacer)}`;break;case u.unrecognized_keys:t=`Unrecognized key(s) in object: ${x.joinValues(s.keys,", ")}`;break;case u.invalid_union:t="Invalid input";break;case u.invalid_union_discriminator:t=`Invalid discriminator value. Expected ${x.joinValues(s.options)}`;break;case u.invalid_enum_value:t=`Invalid enum value. Expected ${x.joinValues(s.options)}, received '${s.received}'`;break;case u.invalid_arguments:t="Invalid function arguments";break;case u.invalid_return_type:t="Invalid function return type";break;case u.invalid_date:t="Invalid date";break;case u.invalid_string:typeof s.validation=="object"?"includes"in s.validation?(t=`Invalid input: must include "${s.validation.includes}"`,typeof s.validation.position=="number"&&(t=`${t} at one or more positions greater than or equal to ${s.validation.position}`)):"startsWith"in s.validation?t=`Invalid input: must start with "${s.validation.startsWith}"`:"endsWith"in s.validation?t=`Invalid input: must end with "${s.validation.endsWith}"`:x.assertNever(s.validation):s.validation!=="regex"?t=`Invalid ${s.validation}`:t="Invalid";break;case u.too_small:s.type==="array"?t=`Array must contain ${s.exact?"exactly":s.inclusive?"at least":"more than"} ${s.minimum} element(s)`:s.type==="string"?t=`String must contain ${s.exact?"exactly":s.inclusive?"at least":"over"} ${s.minimum} character(s)`:s.type==="number"?t=`Number must be ${s.exact?"exactly equal to ":s.inclusive?"greater than or equal to ":"greater than "}${s.minimum}`:s.type==="bigint"?t=`Number must be ${s.exact?"exactly equal to ":s.inclusive?"greater than or equal to ":"greater than "}${s.minimum}`:s.type==="date"?t=`Date must be ${s.exact?"exactly equal to ":s.inclusive?"greater than or equal to ":"greater than "}${new Date(Number(s.minimum))}`:t="Invalid input";break;case u.too_big:s.type==="array"?t=`Array must contain ${s.exact?"exactly":s.inclusive?"at most":"less than"} ${s.maximum} element(s)`:s.type==="string"?t=`String must contain ${s.exact?"exactly":s.inclusive?"at most":"under"} ${s.maximum} character(s)`:s.type==="number"?t=`Number must be ${s.exact?"exactly":s.inclusive?"less than or equal to":"less than"} ${s.maximum}`:s.type==="bigint"?t=`BigInt must be ${s.exact?"exactly":s.inclusive?"less than or equal to":"less than"} ${s.maximum}`:s.type==="date"?t=`Date must be ${s.exact?"exactly":s.inclusive?"smaller than or equal to":"smaller than"} ${new Date(Number(s.maximum))}`:t="Invalid input";break;case u.custom:t="Invalid input";break;case u.invalid_intersection_types:t="Intersection results could not be merged";break;case u.not_multiple_of:t=`Number must be a multiple of ${s.multipleOf}`;break;case u.not_finite:t="Number must be finite";break;default:t=e.defaultError,x.assertNever(s)}return{message:t}};let $s=nt;function Ps(){return $s}const Os=s=>{const{data:e,path:t,errorMaps:n,issueData:r}=s,i=[...t,...r.path||[]],a={...r,path:i};if(r.message!==void 0)return{...r,path:i,message:r.message};let o="";const c=n.filter(l=>!!l).slice().reverse();for(const l of c)o=l(a,{data:e,defaultError:o}).message;return{...r,path:i,message:o}};function f(s,e){const t=Ps(),n=Os({issueData:e,data:s.data,path:s.path,errorMaps:[s.common.contextualErrorMap,s.schemaErrorMap,t,t===nt?void 0:nt].filter(r=>!!r)});s.common.issues.push(n)}class O{constructor(){this.value="valid"}dirty(){this.value==="valid"&&(this.value="dirty")}abort(){this.value!=="aborted"&&(this.value="aborted")}static mergeArray(e,t){const n=[];for(const r of t){if(r.status==="aborted")return v;r.status==="dirty"&&e.dirty(),n.push(r.value)}return{status:e.value,value:n}}static async mergeObjectAsync(e,t){const n=[];for(const r of t){const i=await r.key,a=await r.value;n.push({key:i,value:a})}return O.mergeObjectSync(e,n)}static mergeObjectSync(e,t){const n={};for(const r of t){const{key:i,value:a}=r;if(i.status==="aborted"||a.status==="aborted")return v;i.status==="dirty"&&e.dirty(),a.status==="dirty"&&e.dirty(),i.value!=="__proto__"&&(typeof a.value<"u"||r.alwaysSet)&&(n[i.value]=a.value)}return{status:e.value,value:n}}}const v=Object.freeze({status:"aborted"}),Ae=s=>({status:"dirty",value:s}),z=s=>({status:"valid",value:s}),jt=s=>s.status==="aborted",Vt=s=>s.status==="dirty",he=s=>s.status==="valid",ze=s=>typeof Promise<"u"&&s instanceof Promise;var m;(function(s){s.errToObj=e=>typeof e=="string"?{message:e}:e||{},s.toString=e=>typeof e=="string"?e:e==null?void 0:e.message})(m||(m={}));class D{constructor(e,t,n,r){this._cachedPath=[],this.parent=e,this.data=t,this._path=n,this._key=r}get path(){return this._cachedPath.length||(Array.isArray(this._key)?this._cachedPath.push(...this._path,...this._key):this._cachedPath.push(...this._path,this._key)),this._cachedPath}}const zt=(s,e)=>{if(he(e))return{success:!0,data:e.value};if(!s.common.issues.length)throw new Error("Validation failed but no issues detected.");return{success:!1,get error(){if(this._error)return this._error;const t=new G(s.common.issues);return this._error=t,this._error}}};function b(s){if(!s)return{};const{errorMap:e,invalid_type_error:t,required_error:n,description:r}=s;if(e&&(t||n))throw new Error(`Can't use "invalid_type_error" or "required_error" in conjunction with custom error map.`);return e?{errorMap:e,description:r}:{errorMap:(a,o)=>{const{message:c}=s;return a.code==="invalid_enum_value"?{message:c??o.defaultError}:typeof o.data>"u"?{message:c??n??o.defaultError}:a.code!=="invalid_type"?{message:o.defaultError}:{message:c??t??o.defaultError}},description:r}}class w{get description(){return this._def.description}_getType(e){return se(e.data)}_getOrReturnCtx(e,t){return t||{common:e.parent.common,data:e.data,parsedType:se(e.data),schemaErrorMap:this._def.errorMap,path:e.path,parent:e.parent}}_processInputParams(e){return{status:new O,ctx:{common:e.parent.common,data:e.data,parsedType:se(e.data),schemaErrorMap:this._def.errorMap,path:e.path,parent:e.parent}}}_parseSync(e){const t=this._parse(e);if(ze(t))throw new Error("Synchronous parse encountered promise.");return t}_parseAsync(e){const t=this._parse(e);return Promise.resolve(t)}parse(e,t){const n=this.safeParse(e,t);if(n.success)return n.data;throw n.error}safeParse(e,t){const n={common:{issues:[],async:(t==null?void 0:t.async)??!1,contextualErrorMap:t==null?void 0:t.errorMap},path:(t==null?void 0:t.path)||[],schemaErrorMap:this._def.errorMap,parent:null,data:e,parsedType:se(e)},r=this._parseSync({data:e,path:n.path,parent:n});return zt(n,r)}"~validate"(e){var n,r;const t={common:{issues:[],async:!!this["~standard"].async},path:[],schemaErrorMap:this._def.errorMap,parent:null,data:e,parsedType:se(e)};if(!this["~standard"].async)try{const i=this._parseSync({data:e,path:[],parent:t});return he(i)?{value:i.value}:{issues:t.common.issues}}catch(i){(r=(n=i==null?void 0:i.message)==null?void 0:n.toLowerCase())!=null&&r.includes("encountered")&&(this["~standard"].async=!0),t.common={issues:[],async:!0}}return this._parseAsync({data:e,path:[],parent:t}).then(i=>he(i)?{value:i.value}:{issues:t.common.issues})}async parseAsync(e,t){const n=await this.safeParseAsync(e,t);if(n.success)return n.data;throw n.error}async safeParseAsync(e,t){const n={common:{issues:[],contextualErrorMap:t==null?void 0:t.errorMap,async:!0},path:(t==null?void 0:t.path)||[],schemaErrorMap:this._def.errorMap,parent:null,data:e,parsedType:se(e)},r=this._parse({data:e,path:n.path,parent:n}),i=await(ze(r)?r:Promise.resolve(r));return zt(n,i)}refine(e,t){const n=r=>typeof t=="string"||typeof t>"u"?{message:t}:typeof t=="function"?t(r):t;return this._refinement((r,i)=>{const a=e(r),o=()=>i.addIssue({code:u.custom,...n(r)});return typeof Promise<"u"&&a instanceof Promise?a.then(c=>c?!0:(o(),!1)):a?!0:(o(),!1)})}refinement(e,t){return this._refinement((n,r)=>e(n)?!0:(r.addIssue(typeof t=="function"?t(n,r):t),!1))}_refinement(e){return new le({schema:this,typeName:_.ZodEffects,effect:{type:"refinement",refinement:e}})}superRefine(e){return this._refinement(e)}constructor(e){this.spa=this.safeParseAsync,this._def=e,this.parse=this.parse.bind(this),this.safeParse=this.safeParse.bind(this),this.parseAsync=this.parseAsync.bind(this),this.safeParseAsync=this.safeParseAsync.bind(this),this.spa=this.spa.bind(this),this.refine=this.refine.bind(this),this.refinement=this.refinement.bind(this),this.superRefine=this.superRefine.bind(this),this.optional=this.optional.bind(this),this.nullable=this.nullable.bind(this),this.nullish=this.nullish.bind(this),this.array=this.array.bind(this),this.promise=this.promise.bind(this),this.or=this.or.bind(this),this.and=this.and.bind(this),this.transform=this.transform.bind(this),this.brand=this.brand.bind(this),this.default=this.default.bind(this),this.catch=this.catch.bind(this),this.describe=this.describe.bind(this),this.pipe=this.pipe.bind(this),this.readonly=this.readonly.bind(this),this.isNullable=this.isNullable.bind(this),this.isOptional=this.isOptional.bind(this),this["~standard"]={version:1,vendor:"zod",validate:t=>this["~validate"](t)}}optional(){return ee.create(this,this._def)}nullable(){return ue.create(this,this._def)}nullish(){return this.nullable().optional()}array(){return W.create(this)}promise(){return qe.create(this,this._def)}or(e){return Fe.create([this,e],this._def)}and(e){return Ue.create(this,e,this._def)}transform(e){return new le({...b(this._def),schema:this,typeName:_.ZodEffects,effect:{type:"transform",transform:e}})}default(e){const t=typeof e=="function"?e:()=>e;return new He({...b(this._def),innerType:this,defaultValue:t,typeName:_.ZodDefault})}brand(){return new Gt({typeName:_.ZodBranded,type:this,...b(this._def)})}catch(e){const t=typeof e=="function"?e:()=>e;return new Je({...b(this._def),innerType:this,catchValue:t,typeName:_.ZodCatch})}describe(e){const t=this.constructor;return new t({...this._def,description:e})}pipe(e){return dt.create(this,e)}readonly(){return Xe.create(this)}isOptional(){return this.safeParse(void 0).success}isNullable(){return this.safeParse(null).success}}const Rs=/^c[^\s-]{8,}$/i,Ls=/^[0-9a-z]+$/,Ms=/^[0-9A-HJKMNP-TV-Z]{26}$/i,Zs=/^[0-9a-fA-F]{8}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{12}$/i,js=/^[a-z0-9_-]{21}$/i,Vs=/^[A-Za-z0-9-_]+\.[A-Za-z0-9-_]+\.[A-Za-z0-9-_]*$/,zs=/^[-+]?P(?!$)(?:(?:[-+]?\d+Y)|(?:[-+]?\d+[.,]\d+Y$))?(?:(?:[-+]?\d+M)|(?:[-+]?\d+[.,]\d+M$))?(?:(?:[-+]?\d+W)|(?:[-+]?\d+[.,]\d+W$))?(?:(?:[-+]?\d+D)|(?:[-+]?\d+[.,]\d+D$))?(?:T(?=[\d+-])(?:(?:[-+]?\d+H)|(?:[-+]?\d+[.,]\d+H$))?(?:(?:[-+]?\d+M)|(?:[-+]?\d+[.,]\d+M$))?(?:[-+]?\d+(?:[.,]\d+)?S)?)??$/,Bs=/^(?!\.)(?!.*\.\.)([A-Z0-9_'+\-\.]*)[A-Z0-9_+-]@([A-Z0-9][A-Z0-9\-]*\.)+[A-Z]{2,}$/i,Fs="^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$";let rt;const Us=/^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])$/,Ds=/^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\/(3[0-2]|[12]?[0-9])$/,Ws=/^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))$/,qs=/^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))\/(12[0-8]|1[01][0-9]|[1-9]?[0-9])$/,Hs=/^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/,Js=/^([0-9a-zA-Z-_]{4})*(([0-9a-zA-Z-_]{2}(==)?)|([0-9a-zA-Z-_]{3}(=)?))?$/,Bt="((\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-((0[13578]|1[02])-(0[1-9]|[12]\\d|3[01])|(0[469]|11)-(0[1-9]|[12]\\d|30)|(02)-(0[1-9]|1\\d|2[0-8])))",Xs=new RegExp(`^${Bt}$`);function Ft(s){let e="[0-5]\\d";s.precision?e=`${e}\\.\\d{${s.precision}}`:s.precision==null&&(e=`${e}(\\.\\d+)?`);const t=s.precision?"+":"?";return`([01]\\d|2[0-3]):[0-5]\\d(:${e})${t}`}function Ys(s){return new RegExp(`^${Ft(s)}$`)}function Gs(s){let e=`${Bt}T${Ft(s)}`;const t=[];return t.push(s.local?"Z?":"Z"),s.offset&&t.push("([+-]\\d{2}:?\\d{2})"),e=`${e}(${t.join("|")})`,new RegExp(`^${e}$`)}function Qs(s,e){return!!((e==="v4"||!e)&&Us.test(s)||(e==="v6"||!e)&&Ws.test(s))}function Ks(s,e){if(!Vs.test(s))return!1;try{const[t]=s.split(".");if(!t)return!1;const n=t.replace(/-/g,"+").replace(/_/g,"/").padEnd(t.length+(4-t.length%4)%4,"="),r=JSON.parse(atob(n));return!(typeof r!="object"||r===null||"typ"in r&&(r==null?void 0:r.typ)!=="JWT"||!r.alg||e&&r.alg!==e)}catch{return!1}}function en(s,e){return!!((e==="v4"||!e)&&Ds.test(s)||(e==="v6"||!e)&&qs.test(s))}class Q extends w{_parse(e){if(this._def.coerce&&(e.data=String(e.data)),this._getType(e)!==p.string){const i=this._getOrReturnCtx(e);return f(i,{code:u.invalid_type,expected:p.string,received:i.parsedType}),v}const n=new O;let r;for(const i of this._def.checks)if(i.kind==="min")e.data.length<i.value&&(r=this._getOrReturnCtx(e,r),f(r,{code:u.too_small,minimum:i.value,type:"string",inclusive:!0,exact:!1,message:i.message}),n.dirty());else if(i.kind==="max")e.data.length>i.value&&(r=this._getOrReturnCtx(e,r),f(r,{code:u.too_big,maximum:i.value,type:"string",inclusive:!0,exact:!1,message:i.message}),n.dirty());else if(i.kind==="length"){const a=e.data.length>i.value,o=e.data.length<i.value;(a||o)&&(r=this._getOrReturnCtx(e,r),a?f(r,{code:u.too_big,maximum:i.value,type:"string",inclusive:!0,exact:!0,message:i.message}):o&&f(r,{code:u.too_small,minimum:i.value,type:"string",inclusive:!0,exact:!0,message:i.message}),n.dirty())}else if(i.kind==="email")Bs.test(e.data)||(r=this._getOrReturnCtx(e,r),f(r,{validation:"email",code:u.invalid_string,message:i.message}),n.dirty());else if(i.kind==="emoji")rt||(rt=new RegExp(Fs,"u")),rt.test(e.data)||(r=this._getOrReturnCtx(e,r),f(r,{validation:"emoji",code:u.invalid_string,message:i.message}),n.dirty());else if(i.kind==="uuid")Zs.test(e.data)||(r=this._getOrReturnCtx(e,r),f(r,{validation:"uuid",code:u.invalid_string,message:i.message}),n.dirty());else if(i.kind==="nanoid")js.test(e.data)||(r=this._getOrReturnCtx(e,r),f(r,{validation:"nanoid",code:u.invalid_string,message:i.message}),n.dirty());else if(i.kind==="cuid")Rs.test(e.data)||(r=this._getOrReturnCtx(e,r),f(r,{validation:"cuid",code:u.invalid_string,message:i.message}),n.dirty());else if(i.kind==="cuid2")Ls.test(e.data)||(r=this._getOrReturnCtx(e,r),f(r,{validation:"cuid2",code:u.invalid_string,message:i.message}),n.dirty());else if(i.kind==="ulid")Ms.test(e.data)||(r=this._getOrReturnCtx(e,r),f(r,{validation:"ulid",code:u.invalid_string,message:i.message}),n.dirty());else if(i.kind==="url")try{new URL(e.data)}catch{r=this._getOrReturnCtx(e,r),f(r,{validation:"url",code:u.invalid_string,message:i.message}),n.dirty()}else i.kind==="regex"?(i.regex.lastIndex=0,i.regex.test(e.data)||(r=this._getOrReturnCtx(e,r),f(r,{validation:"regex",code:u.invalid_string,message:i.message}),n.dirty())):i.kind==="trim"?e.data=e.data.trim():i.kind==="includes"?e.data.includes(i.value,i.position)||(r=this._getOrReturnCtx(e,r),f(r,{code:u.invalid_string,validation:{includes:i.value,position:i.position},message:i.message}),n.dirty()):i.kind==="toLowerCase"?e.data=e.data.toLowerCase():i.kind==="toUpperCase"?e.data=e.data.toUpperCase():i.kind==="startsWith"?e.data.startsWith(i.value)||(r=this._getOrReturnCtx(e,r),f(r,{code:u.invalid_string,validation:{startsWith:i.value},message:i.message}),n.dirty()):i.kind==="endsWith"?e.data.endsWith(i.value)||(r=this._getOrReturnCtx(e,r),f(r,{code:u.invalid_string,validation:{endsWith:i.value},message:i.message}),n.dirty()):i.kind==="datetime"?Gs(i).test(e.data)||(r=this._getOrReturnCtx(e,r),f(r,{code:u.invalid_string,validation:"datetime",message:i.message}),n.dirty()):i.kind==="date"?Xs.test(e.data)||(r=this._getOrReturnCtx(e,r),f(r,{code:u.invalid_string,validation:"date",message:i.message}),n.dirty()):i.kind==="time"?Ys(i).test(e.data)||(r=this._getOrReturnCtx(e,r),f(r,{code:u.invalid_string,validation:"time",message:i.message}),n.dirty()):i.kind==="duration"?zs.test(e.data)||(r=this._getOrReturnCtx(e,r),f(r,{validation:"duration",code:u.invalid_string,message:i.message}),n.dirty()):i.kind==="ip"?Qs(e.data,i.version)||(r=this._getOrReturnCtx(e,r),f(r,{validation:"ip",code:u.invalid_string,message:i.message}),n.dirty()):i.kind==="jwt"?Ks(e.data,i.alg)||(r=this._getOrReturnCtx(e,r),f(r,{validation:"jwt",code:u.invalid_string,message:i.message}),n.dirty()):i.kind==="cidr"?en(e.data,i.version)||(r=this._getOrReturnCtx(e,r),f(r,{validation:"cidr",code:u.invalid_string,message:i.message}),n.dirty()):i.kind==="base64"?Hs.test(e.data)||(r=this._getOrReturnCtx(e,r),f(r,{validation:"base64",code:u.invalid_string,message:i.message}),n.dirty()):i.kind==="base64url"?Js.test(e.data)||(r=this._getOrReturnCtx(e,r),f(r,{validation:"base64url",code:u.invalid_string,message:i.message}),n.dirty()):x.assertNever(i);return{status:n.value,value:e.data}}_regex(e,t,n){return this.refinement(r=>e.test(r),{validation:t,code:u.invalid_string,...m.errToObj(n)})}_addCheck(e){return new Q({...this._def,checks:[...this._def.checks,e]})}email(e){return this._addCheck({kind:"email",...m.errToObj(e)})}url(e){return this._addCheck({kind:"url",...m.errToObj(e)})}emoji(e){return this._addCheck({kind:"emoji",...m.errToObj(e)})}uuid(e){return this._addCheck({kind:"uuid",...m.errToObj(e)})}nanoid(e){return this._addCheck({kind:"nanoid",...m.errToObj(e)})}cuid(e){return this._addCheck({kind:"cuid",...m.errToObj(e)})}cuid2(e){return this._addCheck({kind:"cuid2",...m.errToObj(e)})}ulid(e){return this._addCheck({kind:"ulid",...m.errToObj(e)})}base64(e){return this._addCheck({kind:"base64",...m.errToObj(e)})}base64url(e){return this._addCheck({kind:"base64url",...m.errToObj(e)})}jwt(e){return this._addCheck({kind:"jwt",...m.errToObj(e)})}ip(e){return this._addCheck({kind:"ip",...m.errToObj(e)})}cidr(e){return this._addCheck({kind:"cidr",...m.errToObj(e)})}datetime(e){return typeof e=="string"?this._addCheck({kind:"datetime",precision:null,offset:!1,local:!1,message:e}):this._addCheck({kind:"datetime",precision:typeof(e==null?void 0:e.precision)>"u"?null:e==null?void 0:e.precision,offset:(e==null?void 0:e.offset)??!1,local:(e==null?void 0:e.local)??!1,...m.errToObj(e==null?void 0:e.message)})}date(e){return this._addCheck({kind:"date",message:e})}time(e){return typeof e=="string"?this._addCheck({kind:"time",precision:null,message:e}):this._addCheck({kind:"time",precision:typeof(e==null?void 0:e.precision)>"u"?null:e==null?void 0:e.precision,...m.errToObj(e==null?void 0:e.message)})}duration(e){return this._addCheck({kind:"duration",...m.errToObj(e)})}regex(e,t){return this._addCheck({kind:"regex",regex:e,...m.errToObj(t)})}includes(e,t){return this._addCheck({kind:"includes",value:e,position:t==null?void 0:t.position,...m.errToObj(t==null?void 0:t.message)})}startsWith(e,t){return this._addCheck({kind:"startsWith",value:e,...m.errToObj(t)})}endsWith(e,t){return this._addCheck({kind:"endsWith",value:e,...m.errToObj(t)})}min(e,t){return this._addCheck({kind:"min",value:e,...m.errToObj(t)})}max(e,t){return this._addCheck({kind:"max",value:e,...m.errToObj(t)})}length(e,t){return this._addCheck({kind:"length",value:e,...m.errToObj(t)})}nonempty(e){return this.min(1,m.errToObj(e))}trim(){return new Q({...this._def,checks:[...this._def.checks,{kind:"trim"}]})}toLowerCase(){return new Q({...this._def,checks:[...this._def.checks,{kind:"toLowerCase"}]})}toUpperCase(){return new Q({...this._def,checks:[...this._def.checks,{kind:"toUpperCase"}]})}get isDatetime(){return!!this._def.checks.find(e=>e.kind==="datetime")}get isDate(){return!!this._def.checks.find(e=>e.kind==="date")}get isTime(){return!!this._def.checks.find(e=>e.kind==="time")}get isDuration(){return!!this._def.checks.find(e=>e.kind==="duration")}get isEmail(){return!!this._def.checks.find(e=>e.kind==="email")}get isURL(){return!!this._def.checks.find(e=>e.kind==="url")}get isEmoji(){return!!this._def.checks.find(e=>e.kind==="emoji")}get isUUID(){return!!this._def.checks.find(e=>e.kind==="uuid")}get isNANOID(){return!!this._def.checks.find(e=>e.kind==="nanoid")}get isCUID(){return!!this._def.checks.find(e=>e.kind==="cuid")}get isCUID2(){return!!this._def.checks.find(e=>e.kind==="cuid2")}get isULID(){return!!this._def.checks.find(e=>e.kind==="ulid")}get isIP(){return!!this._def.checks.find(e=>e.kind==="ip")}get isCIDR(){return!!this._def.checks.find(e=>e.kind==="cidr")}get isBase64(){return!!this._def.checks.find(e=>e.kind==="base64")}get isBase64url(){return!!this._def.checks.find(e=>e.kind==="base64url")}get minLength(){let e=null;for(const t of this._def.checks)t.kind==="min"&&(e===null||t.value>e)&&(e=t.value);return e}get maxLength(){let e=null;for(const t of this._def.checks)t.kind==="max"&&(e===null||t.value<e)&&(e=t.value);return e}}Q.create=s=>new Q({checks:[],typeName:_.ZodString,coerce:(s==null?void 0:s.coerce)??!1,...b(s)});function tn(s,e){const t=(s.toString().split(".")[1]||"").length,n=(e.toString().split(".")[1]||"").length,r=t>n?t:n,i=Number.parseInt(s.toFixed(r).replace(".","")),a=Number.parseInt(e.toFixed(r).replace(".",""));return i%a/10**r}class pe extends w{constructor(){super(...arguments),this.min=this.gte,this.max=this.lte,this.step=this.multipleOf}_parse(e){if(this._def.coerce&&(e.data=Number(e.data)),this._getType(e)!==p.number){const i=this._getOrReturnCtx(e);return f(i,{code:u.invalid_type,expected:p.number,received:i.parsedType}),v}let n;const r=new O;for(const i of this._def.checks)i.kind==="int"?x.isInteger(e.data)||(n=this._getOrReturnCtx(e,n),f(n,{code:u.invalid_type,expected:"integer",received:"float",message:i.message}),r.dirty()):i.kind==="min"?(i.inclusive?e.data<i.value:e.data<=i.value)&&(n=this._getOrReturnCtx(e,n),f(n,{code:u.too_small,minimum:i.value,type:"number",inclusive:i.inclusive,exact:!1,message:i.message}),r.dirty()):i.kind==="max"?(i.inclusive?e.data>i.value:e.data>=i.value)&&(n=this._getOrReturnCtx(e,n),f(n,{code:u.too_big,maximum:i.value,type:"number",inclusive:i.inclusive,exact:!1,message:i.message}),r.dirty()):i.kind==="multipleOf"?tn(e.data,i.value)!==0&&(n=this._getOrReturnCtx(e,n),f(n,{code:u.not_multiple_of,multipleOf:i.value,message:i.message}),r.dirty()):i.kind==="finite"?Number.isFinite(e.data)||(n=this._getOrReturnCtx(e,n),f(n,{code:u.not_finite,message:i.message}),r.dirty()):x.assertNever(i);return{status:r.value,value:e.data}}gte(e,t){return this.setLimit("min",e,!0,m.toString(t))}gt(e,t){return this.setLimit("min",e,!1,m.toString(t))}lte(e,t){return this.setLimit("max",e,!0,m.toString(t))}lt(e,t){return this.setLimit("max",e,!1,m.toString(t))}setLimit(e,t,n,r){return new pe({...this._def,checks:[...this._def.checks,{kind:e,value:t,inclusive:n,message:m.toString(r)}]})}_addCheck(e){return new pe({...this._def,checks:[...this._def.checks,e]})}int(e){return this._addCheck({kind:"int",message:m.toString(e)})}positive(e){return this._addCheck({kind:"min",value:0,inclusive:!1,message:m.toString(e)})}negative(e){return this._addCheck({kind:"max",value:0,inclusive:!1,message:m.toString(e)})}nonpositive(e){return this._addCheck({kind:"max",value:0,inclusive:!0,message:m.toString(e)})}nonnegative(e){return this._addCheck({kind:"min",value:0,inclusive:!0,message:m.toString(e)})}multipleOf(e,t){return this._addCheck({kind:"multipleOf",value:e,message:m.toString(t)})}finite(e){return this._addCheck({kind:"finite",message:m.toString(e)})}safe(e){return this._addCheck({kind:"min",inclusive:!0,value:Number.MIN_SAFE_INTEGER,message:m.toString(e)})._addCheck({kind:"max",inclusive:!0,value:Number.MAX_SAFE_INTEGER,message:m.toString(e)})}get minValue(){let e=null;for(const t of this._def.checks)t.kind==="min"&&(e===null||t.value>e)&&(e=t.value);return e}get maxValue(){let e=null;for(const t of this._def.checks)t.kind==="max"&&(e===null||t.value<e)&&(e=t.value);return e}get isInt(){return!!this._def.checks.find(e=>e.kind==="int"||e.kind==="multipleOf"&&x.isInteger(e.value))}get isFinite(){let e=null,t=null;for(const n of this._def.checks){if(n.kind==="finite"||n.kind==="int"||n.kind==="multipleOf")return!0;n.kind==="min"?(t===null||n.value>t)&&(t=n.value):n.kind==="max"&&(e===null||n.value<e)&&(e=n.value)}return Number.isFinite(t)&&Number.isFinite(e)}}pe.create=s=>new pe({checks:[],typeName:_.ZodNumber,coerce:(s==null?void 0:s.coerce)||!1,...b(s)});class Te extends w{constructor(){super(...arguments),this.min=this.gte,this.max=this.lte}_parse(e){if(this._def.coerce)try{e.data=BigInt(e.data)}catch{return this._getInvalidInput(e)}if(this._getType(e)!==p.bigint)return this._getInvalidInput(e);let n;const r=new O;for(const i of this._def.checks)i.kind==="min"?(i.inclusive?e.data<i.value:e.data<=i.value)&&(n=this._getOrReturnCtx(e,n),f(n,{code:u.too_small,type:"bigint",minimum:i.value,inclusive:i.inclusive,message:i.message}),r.dirty()):i.kind==="max"?(i.inclusive?e.data>i.value:e.data>=i.value)&&(n=this._getOrReturnCtx(e,n),f(n,{code:u.too_big,type:"bigint",maximum:i.value,inclusive:i.inclusive,message:i.message}),r.dirty()):i.kind==="multipleOf"?e.data%i.value!==BigInt(0)&&(n=this._getOrReturnCtx(e,n),f(n,{code:u.not_multiple_of,multipleOf:i.value,message:i.message}),r.dirty()):x.assertNever(i);return{status:r.value,value:e.data}}_getInvalidInput(e){const t=this._getOrReturnCtx(e);return f(t,{code:u.invalid_type,expected:p.bigint,received:t.parsedType}),v}gte(e,t){return this.setLimit("min",e,!0,m.toString(t))}gt(e,t){return this.setLimit("min",e,!1,m.toString(t))}lte(e,t){return this.setLimit("max",e,!0,m.toString(t))}lt(e,t){return this.setLimit("max",e,!1,m.toString(t))}setLimit(e,t,n,r){return new Te({...this._def,checks:[...this._def.checks,{kind:e,value:t,inclusive:n,message:m.toString(r)}]})}_addCheck(e){return new Te({...this._def,checks:[...this._def.checks,e]})}positive(e){return this._addCheck({kind:"min",value:BigInt(0),inclusive:!1,message:m.toString(e)})}negative(e){return this._addCheck({kind:"max",value:BigInt(0),inclusive:!1,message:m.toString(e)})}nonpositive(e){return this._addCheck({kind:"max",value:BigInt(0),inclusive:!0,message:m.toString(e)})}nonnegative(e){return this._addCheck({kind:"min",value:BigInt(0),inclusive:!0,message:m.toString(e)})}multipleOf(e,t){return this._addCheck({kind:"multipleOf",value:e,message:m.toString(t)})}get minValue(){let e=null;for(const t of this._def.checks)t.kind==="min"&&(e===null||t.value>e)&&(e=t.value);return e}get maxValue(){let e=null;for(const t of this._def.checks)t.kind==="max"&&(e===null||t.value<e)&&(e=t.value);return e}}Te.create=s=>new Te({checks:[],typeName:_.ZodBigInt,coerce:(s==null?void 0:s.coerce)??!1,...b(s)});class Ut extends w{_parse(e){if(this._def.coerce&&(e.data=!!e.data),this._getType(e)!==p.boolean){const n=this._getOrReturnCtx(e);return f(n,{code:u.invalid_type,expected:p.boolean,received:n.parsedType}),v}return z(e.data)}}Ut.create=s=>new Ut({typeName:_.ZodBoolean,coerce:(s==null?void 0:s.coerce)||!1,...b(s)});class Be extends w{_parse(e){if(this._def.coerce&&(e.data=new Date(e.data)),this._getType(e)!==p.date){const i=this._getOrReturnCtx(e);return f(i,{code:u.invalid_type,expected:p.date,received:i.parsedType}),v}if(Number.isNaN(e.data.getTime())){const i=this._getOrReturnCtx(e);return f(i,{code:u.invalid_date}),v}const n=new O;let r;for(const i of this._def.checks)i.kind==="min"?e.data.getTime()<i.value&&(r=this._getOrReturnCtx(e,r),f(r,{code:u.too_small,message:i.message,inclusive:!0,exact:!1,minimum:i.value,type:"date"}),n.dirty()):i.kind==="max"?e.data.getTime()>i.value&&(r=this._getOrReturnCtx(e,r),f(r,{code:u.too_big,message:i.message,inclusive:!0,exact:!1,maximum:i.value,type:"date"}),n.dirty()):x.assertNever(i);return{status:n.value,value:new Date(e.data.getTime())}}_addCheck(e){return new Be({...this._def,checks:[...this._def.checks,e]})}min(e,t){return this._addCheck({kind:"min",value:e.getTime(),message:m.toString(t)})}max(e,t){return this._addCheck({kind:"max",value:e.getTime(),message:m.toString(t)})}get minDate(){let e=null;for(const t of this._def.checks)t.kind==="min"&&(e===null||t.value>e)&&(e=t.value);return e!=null?new Date(e):null}get maxDate(){let e=null;for(const t of this._def.checks)t.kind==="max"&&(e===null||t.value<e)&&(e=t.value);return e!=null?new Date(e):null}}Be.create=s=>new Be({checks:[],coerce:(s==null?void 0:s.coerce)||!1,typeName:_.ZodDate,...b(s)});class Dt extends w{_parse(e){if(this._getType(e)!==p.symbol){const n=this._getOrReturnCtx(e);return f(n,{code:u.invalid_type,expected:p.symbol,received:n.parsedType}),v}return z(e.data)}}Dt.create=s=>new Dt({typeName:_.ZodSymbol,...b(s)});class it extends w{_parse(e){if(this._getType(e)!==p.undefined){const n=this._getOrReturnCtx(e);return f(n,{code:u.invalid_type,expected:p.undefined,received:n.parsedType}),v}return z(e.data)}}it.create=s=>new it({typeName:_.ZodUndefined,...b(s)});class at extends w{_parse(e){if(this._getType(e)!==p.null){const n=this._getOrReturnCtx(e);return f(n,{code:u.invalid_type,expected:p.null,received:n.parsedType}),v}return z(e.data)}}at.create=s=>new at({typeName:_.ZodNull,...b(s)});class Wt extends w{constructor(){super(...arguments),this._any=!0}_parse(e){return z(e.data)}}Wt.create=s=>new Wt({typeName:_.ZodAny,...b(s)});class qt extends w{constructor(){super(...arguments),this._unknown=!0}_parse(e){return z(e.data)}}qt.create=s=>new qt({typeName:_.ZodUnknown,...b(s)});class ne extends w{_parse(e){const t=this._getOrReturnCtx(e);return f(t,{code:u.invalid_type,expected:p.never,received:t.parsedType}),v}}ne.create=s=>new ne({typeName:_.ZodNever,...b(s)});class Ht extends w{_parse(e){if(this._getType(e)!==p.undefined){const n=this._getOrReturnCtx(e);return f(n,{code:u.invalid_type,expected:p.void,received:n.parsedType}),v}return z(e.data)}}Ht.create=s=>new Ht({typeName:_.ZodVoid,...b(s)});class W extends w{_parse(e){const{ctx:t,status:n}=this._processInputParams(e),r=this._def;if(t.parsedType!==p.array)return f(t,{code:u.invalid_type,expected:p.array,received:t.parsedType}),v;if(r.exactLength!==null){const a=t.data.length>r.exactLength.value,o=t.data.length<r.exactLength.value;(a||o)&&(f(t,{code:a?u.too_big:u.too_small,minimum:o?r.exactLength.value:void 0,maximum:a?r.exactLength.value:void 0,type:"array",inclusive:!0,exact:!0,message:r.exactLength.message}),n.dirty())}if(r.minLength!==null&&t.data.length<r.minLength.value&&(f(t,{code:u.too_small,minimum:r.minLength.value,type:"array",inclusive:!0,exact:!1,message:r.minLength.message}),n.dirty()),r.maxLength!==null&&t.data.length>r.maxLength.value&&(f(t,{code:u.too_big,maximum:r.maxLength.value,type:"array",inclusive:!0,exact:!1,message:r.maxLength.message}),n.dirty()),t.common.async)return Promise.all([...t.data].map((a,o)=>r.type._parseAsync(new D(t,a,t.path,o)))).then(a=>O.mergeArray(n,a));const i=[...t.data].map((a,o)=>r.type._parseSync(new D(t,a,t.path,o)));return O.mergeArray(n,i)}get element(){return this._def.type}min(e,t){return new W({...this._def,minLength:{value:e,message:m.toString(t)}})}max(e,t){return new W({...this._def,maxLength:{value:e,message:m.toString(t)}})}length(e,t){return new W({...this._def,exactLength:{value:e,message:m.toString(t)}})}nonempty(e){return this.min(1,e)}}W.create=(s,e)=>new W({type:s,minLength:null,maxLength:null,exactLength:null,typeName:_.ZodArray,...b(e)});function me(s){if(s instanceof N){const e={};for(const t in s.shape){const n=s.shape[t];e[t]=ee.create(me(n))}return new N({...s._def,shape:()=>e})}else return s instanceof W?new W({...s._def,type:me(s.element)}):s instanceof ee?ee.create(me(s.unwrap())):s instanceof ue?ue.create(me(s.unwrap())):s instanceof oe?oe.create(s.items.map(e=>me(e))):s}class N extends w{constructor(){super(...arguments),this._cached=null,this.nonstrict=this.passthrough,this.augment=this.extend}_getCached(){if(this._cached!==null)return this._cached;const e=this._def.shape(),t=x.objectKeys(e);return this._cached={shape:e,keys:t},this._cached}_parse(e){if(this._getType(e)!==p.object){const l=this._getOrReturnCtx(e);return f(l,{code:u.invalid_type,expected:p.object,received:l.parsedType}),v}const{status:n,ctx:r}=this._processInputParams(e),{shape:i,keys:a}=this._getCached(),o=[];if(!(this._def.catchall instanceof ne&&this._def.unknownKeys==="strip"))for(const l in r.data)a.includes(l)||o.push(l);const c=[];for(const l of a){const d=i[l],h=r.data[l];c.push({key:{status:"valid",value:l},value:d._parse(new D(r,h,r.path,l)),alwaysSet:l in r.data})}if(this._def.catchall instanceof ne){const l=this._def.unknownKeys;if(l==="passthrough")for(const d of o)c.push({key:{status:"valid",value:d},value:{status:"valid",value:r.data[d]}});else if(l==="strict")o.length>0&&(f(r,{code:u.unrecognized_keys,keys:o}),n.dirty());else if(l!=="strip")throw new Error("Internal ZodObject error: invalid unknownKeys value.")}else{const l=this._def.catchall;for(const d of o){const h=r.data[d];c.push({key:{status:"valid",value:d},value:l._parse(new D(r,h,r.path,d)),alwaysSet:d in r.data})}}return r.common.async?Promise.resolve().then(async()=>{const l=[];for(const d of c){const h=await d.key,y=await d.value;l.push({key:h,value:y,alwaysSet:d.alwaysSet})}return l}).then(l=>O.mergeObjectSync(n,l)):O.mergeObjectSync(n,c)}get shape(){return this._def.shape()}strict(e){return m.errToObj,new N({...this._def,unknownKeys:"strict",...e!==void 0?{errorMap:(t,n)=>{var i,a;const r=((a=(i=this._def).errorMap)==null?void 0:a.call(i,t,n).message)??n.defaultError;return t.code==="unrecognized_keys"?{message:m.errToObj(e).message??r}:{message:r}}}:{}})}strip(){return new N({...this._def,unknownKeys:"strip"})}passthrough(){return new N({...this._def,unknownKeys:"passthrough"})}extend(e){return new N({...this._def,shape:()=>({...this._def.shape(),...e})})}merge(e){return new N({unknownKeys:e._def.unknownKeys,catchall:e._def.catchall,shape:()=>({...this._def.shape(),...e._def.shape()}),typeName:_.ZodObject})}setKey(e,t){return this.augment({[e]:t})}catchall(e){return new N({...this._def,catchall:e})}pick(e){const t={};for(const n of x.objectKeys(e))e[n]&&this.shape[n]&&(t[n]=this.shape[n]);return new N({...this._def,shape:()=>t})}omit(e){const t={};for(const n of x.objectKeys(this.shape))e[n]||(t[n]=this.shape[n]);return new N({...this._def,shape:()=>t})}deepPartial(){return me(this)}partial(e){const t={};for(const n of x.objectKeys(this.shape)){const r=this.shape[n];e&&!e[n]?t[n]=r:t[n]=r.optional()}return new N({...this._def,shape:()=>t})}required(e){const t={};for(const n of x.objectKeys(this.shape))if(e&&!e[n])t[n]=this.shape[n];else{let i=this.shape[n];for(;i instanceof ee;)i=i._def.innerType;t[n]=i}return new N({...this._def,shape:()=>t})}keyof(){return Xt(x.objectKeys(this.shape))}}N.create=(s,e)=>new N({shape:()=>s,unknownKeys:"strip",catchall:ne.create(),typeName:_.ZodObject,...b(e)}),N.strictCreate=(s,e)=>new N({shape:()=>s,unknownKeys:"strict",catchall:ne.create(),typeName:_.ZodObject,...b(e)}),N.lazycreate=(s,e)=>new N({shape:s,unknownKeys:"strip",catchall:ne.create(),typeName:_.ZodObject,...b(e)});class Fe extends w{_parse(e){const{ctx:t}=this._processInputParams(e),n=this._def.options;function r(i){for(const o of i)if(o.result.status==="valid")return o.result;for(const o of i)if(o.result.status==="dirty")return t.common.issues.push(...o.ctx.common.issues),o.result;const a=i.map(o=>new G(o.ctx.common.issues));return f(t,{code:u.invalid_union,unionErrors:a}),v}if(t.common.async)return Promise.all(n.map(async i=>{const a={...t,common:{...t.common,issues:[]},parent:null};return{result:await i._parseAsync({data:t.data,path:t.path,parent:a}),ctx:a}})).then(r);{let i;const a=[];for(const c of n){const l={...t,common:{...t.common,issues:[]},parent:null},d=c._parseSync({data:t.data,path:t.path,parent:l});if(d.status==="valid")return d;d.status==="dirty"&&!i&&(i={result:d,ctx:l}),l.common.issues.length&&a.push(l.common.issues)}if(i)return t.common.issues.push(...i.ctx.common.issues),i.result;const o=a.map(c=>new G(c));return f(t,{code:u.invalid_union,unionErrors:o}),v}}get options(){return this._def.options}}Fe.create=(s,e)=>new Fe({options:s,typeName:_.ZodUnion,...b(e)});const K=s=>s instanceof lt?K(s.schema):s instanceof le?K(s.innerType()):s instanceof We?[s.value]:s instanceof ce?s.options:s instanceof ut?x.objectValues(s.enum):s instanceof He?K(s._def.innerType):s instanceof it?[void 0]:s instanceof at?[null]:s instanceof ee?[void 0,...K(s.unwrap())]:s instanceof ue?[null,...K(s.unwrap())]:s instanceof Gt||s instanceof Xe?K(s.unwrap()):s instanceof Je?K(s._def.innerType):[];class ot extends w{_parse(e){const{ctx:t}=this._processInputParams(e);if(t.parsedType!==p.object)return f(t,{code:u.invalid_type,expected:p.object,received:t.parsedType}),v;const n=this.discriminator,r=t.data[n],i=this.optionsMap.get(r);return i?t.common.async?i._parseAsync({data:t.data,path:t.path,parent:t}):i._parseSync({data:t.data,path:t.path,parent:t}):(f(t,{code:u.invalid_union_discriminator,options:Array.from(this.optionsMap.keys()),path:[n]}),v)}get discriminator(){return this._def.discriminator}get options(){return this._def.options}get optionsMap(){return this._def.optionsMap}static create(e,t,n){const r=new Map;for(const i of t){const a=K(i.shape[e]);if(!a.length)throw new Error(`A discriminator value for key \`${e}\` could not be extracted from all schema options`);for(const o of a){if(r.has(o))throw new Error(`Discriminator property ${String(e)} has duplicate value ${String(o)}`);r.set(o,i)}}return new ot({typeName:_.ZodDiscriminatedUnion,discriminator:e,options:t,optionsMap:r,...b(n)})}}function ct(s,e){const t=se(s),n=se(e);if(s===e)return{valid:!0,data:s};if(t===p.object&&n===p.object){const r=x.objectKeys(e),i=x.objectKeys(s).filter(o=>r.indexOf(o)!==-1),a={...s,...e};for(const o of i){const c=ct(s[o],e[o]);if(!c.valid)return{valid:!1};a[o]=c.data}return{valid:!0,data:a}}else if(t===p.array&&n===p.array){if(s.length!==e.length)return{valid:!1};const r=[];for(let i=0;i<s.length;i++){const a=s[i],o=e[i],c=ct(a,o);if(!c.valid)return{valid:!1};r.push(c.data)}return{valid:!0,data:r}}else return t===p.date&&n===p.date&&+s==+e?{valid:!0,data:s}:{valid:!1}}class Ue extends w{_parse(e){const{status:t,ctx:n}=this._processInputParams(e),r=(i,a)=>{if(jt(i)||jt(a))return v;const o=ct(i.value,a.value);return o.valid?((Vt(i)||Vt(a))&&t.dirty(),{status:t.value,value:o.data}):(f(n,{code:u.invalid_intersection_types}),v)};return n.common.async?Promise.all([this._def.left._parseAsync({data:n.data,path:n.path,parent:n}),this._def.right._parseAsync({data:n.data,path:n.path,parent:n})]).then(([i,a])=>r(i,a)):r(this._def.left._parseSync({data:n.data,path:n.path,parent:n}),this._def.right._parseSync({data:n.data,path:n.path,parent:n}))}}Ue.create=(s,e,t)=>new Ue({left:s,right:e,typeName:_.ZodIntersection,...b(t)});class oe extends w{_parse(e){const{status:t,ctx:n}=this._processInputParams(e);if(n.parsedType!==p.array)return f(n,{code:u.invalid_type,expected:p.array,received:n.parsedType}),v;if(n.data.length<this._def.items.length)return f(n,{code:u.too_small,minimum:this._def.items.length,inclusive:!0,exact:!1,type:"array"}),v;!this._def.rest&&n.data.length>this._def.items.length&&(f(n,{code:u.too_big,maximum:this._def.items.length,inclusive:!0,exact:!1,type:"array"}),t.dirty());const i=[...n.data].map((a,o)=>{const c=this._def.items[o]||this._def.rest;return c?c._parse(new D(n,a,n.path,o)):null}).filter(a=>!!a);return n.common.async?Promise.all(i).then(a=>O.mergeArray(t,a)):O.mergeArray(t,i)}get items(){return this._def.items}rest(e){return new oe({...this._def,rest:e})}}oe.create=(s,e)=>{if(!Array.isArray(s))throw new Error("You must pass an array of schemas to z.tuple([ ... ])");return new oe({items:s,typeName:_.ZodTuple,rest:null,...b(e)})};class De extends w{get keySchema(){return this._def.keyType}get valueSchema(){return this._def.valueType}_parse(e){const{status:t,ctx:n}=this._processInputParams(e);if(n.parsedType!==p.object)return f(n,{code:u.invalid_type,expected:p.object,received:n.parsedType}),v;const r=[],i=this._def.keyType,a=this._def.valueType;for(const o in n.data)r.push({key:i._parse(new D(n,o,n.path,o)),value:a._parse(new D(n,n.data[o],n.path,o)),alwaysSet:o in n.data});return n.common.async?O.mergeObjectAsync(t,r):O.mergeObjectSync(t,r)}get element(){return this._def.valueType}static create(e,t,n){return t instanceof w?new De({keyType:e,valueType:t,typeName:_.ZodRecord,...b(n)}):new De({keyType:Q.create(),valueType:e,typeName:_.ZodRecord,...b(t)})}}class Jt extends w{get keySchema(){return this._def.keyType}get valueSchema(){return this._def.valueType}_parse(e){const{status:t,ctx:n}=this._processInputParams(e);if(n.parsedType!==p.map)return f(n,{code:u.invalid_type,expected:p.map,received:n.parsedType}),v;const r=this._def.keyType,i=this._def.valueType,a=[...n.data.entries()].map(([o,c],l)=>({key:r._parse(new D(n,o,n.path,[l,"key"])),value:i._parse(new D(n,c,n.path,[l,"value"]))}));if(n.common.async){const o=new Map;return Promise.resolve().then(async()=>{for(const c of a){const l=await c.key,d=await c.value;if(l.status==="aborted"||d.status==="aborted")return v;(l.status==="dirty"||d.status==="dirty")&&t.dirty(),o.set(l.value,d.value)}return{status:t.value,value:o}})}else{const o=new Map;for(const c of a){const l=c.key,d=c.value;if(l.status==="aborted"||d.status==="aborted")return v;(l.status==="dirty"||d.status==="dirty")&&t.dirty(),o.set(l.value,d.value)}return{status:t.value,value:o}}}}Jt.create=(s,e,t)=>new Jt({valueType:e,keyType:s,typeName:_.ZodMap,...b(t)});class Ce extends w{_parse(e){const{status:t,ctx:n}=this._processInputParams(e);if(n.parsedType!==p.set)return f(n,{code:u.invalid_type,expected:p.set,received:n.parsedType}),v;const r=this._def;r.minSize!==null&&n.data.size<r.minSize.value&&(f(n,{code:u.too_small,minimum:r.minSize.value,type:"set",inclusive:!0,exact:!1,message:r.minSize.message}),t.dirty()),r.maxSize!==null&&n.data.size>r.maxSize.value&&(f(n,{code:u.too_big,maximum:r.maxSize.value,type:"set",inclusive:!0,exact:!1,message:r.maxSize.message}),t.dirty());const i=this._def.valueType;function a(c){const l=new Set;for(const d of c){if(d.status==="aborted")return v;d.status==="dirty"&&t.dirty(),l.add(d.value)}return{status:t.value,value:l}}const o=[...n.data.values()].map((c,l)=>i._parse(new D(n,c,n.path,l)));return n.common.async?Promise.all(o).then(c=>a(c)):a(o)}min(e,t){return new Ce({...this._def,minSize:{value:e,message:m.toString(t)}})}max(e,t){return new Ce({...this._def,maxSize:{value:e,message:m.toString(t)}})}size(e,t){return this.min(e,t).max(e,t)}nonempty(e){return this.min(1,e)}}Ce.create=(s,e)=>new Ce({valueType:s,minSize:null,maxSize:null,typeName:_.ZodSet,...b(e)});class lt extends w{get schema(){return this._def.getter()}_parse(e){const{ctx:t}=this._processInputParams(e);return this._def.getter()._parse({data:t.data,path:t.path,parent:t})}}lt.create=(s,e)=>new lt({getter:s,typeName:_.ZodLazy,...b(e)});class We extends w{_parse(e){if(e.data!==this._def.value){const t=this._getOrReturnCtx(e);return f(t,{received:t.data,code:u.invalid_literal,expected:this._def.value}),v}return{status:"valid",value:e.data}}get value(){return this._def.value}}We.create=(s,e)=>new We({value:s,typeName:_.ZodLiteral,...b(e)});function Xt(s,e){return new ce({values:s,typeName:_.ZodEnum,...b(e)})}class ce extends w{_parse(e){if(typeof e.data!="string"){const t=this._getOrReturnCtx(e),n=this._def.values;return f(t,{expected:x.joinValues(n),received:t.parsedType,code:u.invalid_type}),v}if(this._cache||(this._cache=new Set(this._def.values)),!this._cache.has(e.data)){const t=this._getOrReturnCtx(e),n=this._def.values;return f(t,{received:t.data,code:u.invalid_enum_value,options:n}),v}return z(e.data)}get options(){return this._def.values}get enum(){const e={};for(const t of this._def.values)e[t]=t;return e}get Values(){const e={};for(const t of this._def.values)e[t]=t;return e}get Enum(){const e={};for(const t of this._def.values)e[t]=t;return e}extract(e,t=this._def){return ce.create(e,{...this._def,...t})}exclude(e,t=this._def){return ce.create(this.options.filter(n=>!e.includes(n)),{...this._def,...t})}}ce.create=Xt;class ut extends w{_parse(e){const t=x.getValidEnumValues(this._def.values),n=this._getOrReturnCtx(e);if(n.parsedType!==p.string&&n.parsedType!==p.number){const r=x.objectValues(t);return f(n,{expected:x.joinValues(r),received:n.parsedType,code:u.invalid_type}),v}if(this._cache||(this._cache=new Set(x.getValidEnumValues(this._def.values))),!this._cache.has(e.data)){const r=x.objectValues(t);return f(n,{received:n.data,code:u.invalid_enum_value,options:r}),v}return z(e.data)}get enum(){return this._def.values}}ut.create=(s,e)=>new ut({values:s,typeName:_.ZodNativeEnum,...b(e)});class qe extends w{unwrap(){return this._def.type}_parse(e){const{ctx:t}=this._processInputParams(e);if(t.parsedType!==p.promise&&t.common.async===!1)return f(t,{code:u.invalid_type,expected:p.promise,received:t.parsedType}),v;const n=t.parsedType===p.promise?t.data:Promise.resolve(t.data);return z(n.then(r=>this._def.type.parseAsync(r,{path:t.path,errorMap:t.common.contextualErrorMap})))}}qe.create=(s,e)=>new qe({type:s,typeName:_.ZodPromise,...b(e)});class le extends w{innerType(){return this._def.schema}sourceType(){return this._def.schema._def.typeName===_.ZodEffects?this._def.schema.sourceType():this._def.schema}_parse(e){const{status:t,ctx:n}=this._processInputParams(e),r=this._def.effect||null,i={addIssue:a=>{f(n,a),a.fatal?t.abort():t.dirty()},get path(){return n.path}};if(i.addIssue=i.addIssue.bind(i),r.type==="preprocess"){const a=r.transform(n.data,i);if(n.common.async)return Promise.resolve(a).then(async o=>{if(t.value==="aborted")return v;const c=await this._def.schema._parseAsync({data:o,path:n.path,parent:n});return c.status==="aborted"?v:c.status==="dirty"||t.value==="dirty"?Ae(c.value):c});{if(t.value==="aborted")return v;const o=this._def.schema._parseSync({data:a,path:n.path,parent:n});return o.status==="aborted"?v:o.status==="dirty"||t.value==="dirty"?Ae(o.value):o}}if(r.type==="refinement"){const a=o=>{const c=r.refinement(o,i);if(n.common.async)return Promise.resolve(c);if(c instanceof Promise)throw new Error("Async refinement encountered during synchronous parse operation. Use .parseAsync instead.");return o};if(n.common.async===!1){const o=this._def.schema._parseSync({data:n.data,path:n.path,parent:n});return o.status==="aborted"?v:(o.status==="dirty"&&t.dirty(),a(o.value),{status:t.value,value:o.value})}else return this._def.schema._parseAsync({data:n.data,path:n.path,parent:n}).then(o=>o.status==="aborted"?v:(o.status==="dirty"&&t.dirty(),a(o.value).then(()=>({status:t.value,value:o.value}))))}if(r.type==="transform")if(n.common.async===!1){const a=this._def.schema._parseSync({data:n.data,path:n.path,parent:n});if(!he(a))return v;const o=r.transform(a.value,i);if(o instanceof Promise)throw new Error("Asynchronous transform encountered during synchronous parse operation. Use .parseAsync instead.");return{status:t.value,value:o}}else return this._def.schema._parseAsync({data:n.data,path:n.path,parent:n}).then(a=>he(a)?Promise.resolve(r.transform(a.value,i)).then(o=>({status:t.value,value:o})):v);x.assertNever(r)}}le.create=(s,e,t)=>new le({schema:s,typeName:_.ZodEffects,effect:e,...b(t)}),le.createWithPreprocess=(s,e,t)=>new le({schema:e,effect:{type:"preprocess",transform:s},typeName:_.ZodEffects,...b(t)});class ee extends w{_parse(e){return this._getType(e)===p.undefined?z(void 0):this._def.innerType._parse(e)}unwrap(){return this._def.innerType}}ee.create=(s,e)=>new ee({innerType:s,typeName:_.ZodOptional,...b(e)});class ue extends w{_parse(e){return this._getType(e)===p.null?z(null):this._def.innerType._parse(e)}unwrap(){return this._def.innerType}}ue.create=(s,e)=>new ue({innerType:s,typeName:_.ZodNullable,...b(e)});class He extends w{_parse(e){const{ctx:t}=this._processInputParams(e);let n=t.data;return t.parsedType===p.undefined&&(n=this._def.defaultValue()),this._def.innerType._parse({data:n,path:t.path,parent:t})}removeDefault(){return this._def.innerType}}He.create=(s,e)=>new He({innerType:s,typeName:_.ZodDefault,defaultValue:typeof e.default=="function"?e.default:()=>e.default,...b(e)});class Je extends w{_parse(e){const{ctx:t}=this._processInputParams(e),n={...t,common:{...t.common,issues:[]}},r=this._def.innerType._parse({data:n.data,path:n.path,parent:{...n}});return ze(r)?r.then(i=>({status:"valid",value:i.status==="valid"?i.value:this._def.catchValue({get error(){return new G(n.common.issues)},input:n.data})})):{status:"valid",value:r.status==="valid"?r.value:this._def.catchValue({get error(){return new G(n.common.issues)},input:n.data})}}removeCatch(){return this._def.innerType}}Je.create=(s,e)=>new Je({innerType:s,typeName:_.ZodCatch,catchValue:typeof e.catch=="function"?e.catch:()=>e.catch,...b(e)});class Yt extends w{_parse(e){if(this._getType(e)!==p.nan){const n=this._getOrReturnCtx(e);return f(n,{code:u.invalid_type,expected:p.nan,received:n.parsedType}),v}return{status:"valid",value:e.data}}}Yt.create=s=>new Yt({typeName:_.ZodNaN,...b(s)});class Gt extends w{_parse(e){const{ctx:t}=this._processInputParams(e),n=t.data;return this._def.type._parse({data:n,path:t.path,parent:t})}unwrap(){return this._def.type}}class dt extends w{_parse(e){const{status:t,ctx:n}=this._processInputParams(e);if(n.common.async)return(async()=>{const i=await this._def.in._parseAsync({data:n.data,path:n.path,parent:n});return i.status==="aborted"?v:i.status==="dirty"?(t.dirty(),Ae(i.value)):this._def.out._parseAsync({data:i.value,path:n.path,parent:n})})();{const r=this._def.in._parseSync({data:n.data,path:n.path,parent:n});return r.status==="aborted"?v:r.status==="dirty"?(t.dirty(),{status:"dirty",value:r.value}):this._def.out._parseSync({data:r.value,path:n.path,parent:n})}}static create(e,t){return new dt({in:e,out:t,typeName:_.ZodPipeline})}}class Xe extends w{_parse(e){const t=this._def.innerType._parse(e),n=r=>(he(r)&&(r.value=Object.freeze(r.value)),r);return ze(t)?t.then(r=>n(r)):n(t)}unwrap(){return this._def.innerType}}Xe.create=(s,e)=>new Xe({innerType:s,typeName:_.ZodReadonly,...b(e)});var _;(function(s){s.ZodString="ZodString",s.ZodNumber="ZodNumber",s.ZodNaN="ZodNaN",s.ZodBigInt="ZodBigInt",s.ZodBoolean="ZodBoolean",s.ZodDate="ZodDate",s.ZodSymbol="ZodSymbol",s.ZodUndefined="ZodUndefined",s.ZodNull="ZodNull",s.ZodAny="ZodAny",s.ZodUnknown="ZodUnknown",s.ZodNever="ZodNever",s.ZodVoid="ZodVoid",s.ZodArray="ZodArray",s.ZodObject="ZodObject",s.ZodUnion="ZodUnion",s.ZodDiscriminatedUnion="ZodDiscriminatedUnion",s.ZodIntersection="ZodIntersection",s.ZodTuple="ZodTuple",s.ZodRecord="ZodRecord",s.ZodMap="ZodMap",s.ZodSet="ZodSet",s.ZodFunction="ZodFunction",s.ZodLazy="ZodLazy",s.ZodLiteral="ZodLiteral",s.ZodEnum="ZodEnum",s.ZodEffects="ZodEffects",s.ZodNativeEnum="ZodNativeEnum",s.ZodOptional="ZodOptional",s.ZodNullable="ZodNullable",s.ZodDefault="ZodDefault",s.ZodCatch="ZodCatch",s.ZodPromise="ZodPromise",s.ZodBranded="ZodBranded",s.ZodPipeline="ZodPipeline",s.ZodReadonly="ZodReadonly"})(_||(_={}));const S=Q.create,re=pe.create;ne.create;const Ee=W.create,I=N.create,Ne=Fe.create,Qt=ot.create;Ue.create,oe.create;const sn=De.create,de=We.create,ge=ce.create;qe.create,ee.create,ue.create;const Ye=Ne([re(),S()]),ft=I({x:Ye.optional().default(0),y:Ye.optional().default(0),width:Ye.optional(),height:Ye.optional(),fit:ge(["contain","cover","fill","none"]).optional(),horizontalAlign:ge(["left","center","right"]).optional(),verticalAlign:ge(["top","center","bottom"]).optional()}),nn=I({id:S(),start:re(),end:re(),text:S().optional()}),rn=Qt("type",[I({type:de("image"),src:S()}),I({type:de("audio"),src:S(),channel:ge(["vo","sfx","music"]).optional().default("vo")}),I({type:de("vtt"),src:S()}),I({type:de("html"),src:S()})]),an=Ne([I({play:S()}),I({toggleClass:I({target:S(),className:S()})})]),on=I({id:S(),type:de("text"),layout:ft.optional().default({}),html:S().optional(),htmlSrc:S().optional(),style:I({fontFamily:S().optional(),fontSize:S().optional(),color:S().optional(),textAlign:ge(["left","center","right"]).optional(),lineHeight:Ne([S(),re()]).optional()}).optional()}),cn=I({id:S(),type:de("image"),asset:S(),layout:ft.optional().default({}),className:S().optional()}),ln=I({id:S(),type:de("hotspot"),layout:ft.optional().default({}),onTap:Ee(an).optional().default([]),ariaLabel:S().optional()}),un=Qt("type",[on,cn,ln]),dn=I({id:S(),background:I({asset:S().optional(),color:S().optional()}).optional(),readAloud:I({audio:S(),cues:Ne([S(),Ee(nn)]).optional()}).optional(),blocks:Ee(un).optional().default([])}),Kt=I({id:S(),title:S().optional(),pageSize:I({width:re().positive(),height:re().positive()}),layout:I({mode:ge(["single","two-page","auto"]).default("auto"),singleBreakpoint:re().positive().default(900)}).default({mode:"auto",singleBreakpoint:900}),fonts:Ee(I({family:S(),src:S(),weight:Ne([S(),re()]).optional(),style:S().optional()})).optional().default([]),assets:sn(rn).optional().default({}),pages:Ee(dn).min(1)});function ye(s){return Kt.parse(s)}function ht(s){const e=s.replace(/^\uFEFF/,"").replace(/\r\n/g,`
|
|
2
|
+
`).trim();if(!e.startsWith("WEBVTT"))throw new Error("Invalid WebVTT: missing WEBVTT header");const n=e.slice(e.indexOf(`
|
|
3
|
+
`)+1).split(/\n\n+/),r=[];let i=0;for(const a of n){const o=a.split(`
|
|
4
|
+
`).map(k=>k.trim()).filter(k=>k.length>0&&!k.startsWith("NOTE"));if(o.length===0)continue;const c=o.findIndex(k=>k.includes("-->"));if(c===-1)continue;const l=c>0?o[0]:void 0,d=o[c],h=o.slice(c+1),y=d.split("-->").map(k=>k.trim().split(/\s+/)[0]);if(y.length<2)continue;const $=es(y[0]),R=es(y[1]),C=h.join(" ").trim(),A=l||C||`cue-${i++}`;r.push({id:A,start:$,end:R,text:C||void 0})}return r}function es(s){const e=s.trim().split(":");if(e.length===3){const[t,n,r]=e;return Number(t)*3600+Number(n)*60+Number(r)}if(e.length===2){const[t,n]=e;return Number(t)*60+Number(n)}return Number(s)}function Ge(s,e){if(/^(?:[a-z]+:)?\/\//i.test(e)||e.startsWith("data:")||e.startsWith("blob:")||!s)return e;try{return new URL(e,pt(s)).href}catch{return`${pt(s)}${e.replace(/^\//,"")}`}}function pt(s){return s.endsWith("/")||s.includes("?")?s.endsWith("/")?s:`${s}/`:/\.[a-z0-9]+$/i.test(s.split("/").pop()??"")?s.replace(/[^/]+$/,""):`${s}/`}function fn(s){try{const e=new URL(s,typeof location<"u"?location.href:"http://local/");e.hash="";const t=e.pathname;return e.pathname=t.replace(/[^/]+$/,""),e.href}catch{return pt(s.replace(/[^/]+$/,""))}}async function Ie(s,e){typeof document>"u"||!("fonts"in document)||await Promise.all(s.fonts.map(async t=>{const n=Ge(e,t.src),i=await new FontFace(t.family,`url(${JSON.stringify(n)})`,{weight:t.weight!=null?String(t.weight):"normal",style:t.style??"normal"}).load();document.fonts.add(i)}))}var j=Uint8Array,ve=Uint16Array,hn=Int32Array,ts=new j([0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0,0,0,0]),ss=new j([0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13,0,0]),pn=new j([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]),ns=function(s,e){for(var t=new ve(31),n=0;n<31;++n)t[n]=e+=1<<s[n-1];for(var r=new hn(t[30]),n=1;n<30;++n)for(var i=t[n];i<t[n+1];++i)r[i]=i-t[n]<<5|n;return{b:t,r}},rs=ns(ts,2),is=rs.b,mn=rs.r;is[28]=258,mn[258]=28;for(var gn=ns(ss,0),yn=gn.b,mt=new ve(32768),E=0;E<32768;++E){var ie=(E&43690)>>1|(E&21845)<<1;ie=(ie&52428)>>2|(ie&13107)<<2,ie=(ie&61680)>>4|(ie&3855)<<4,mt[E]=((ie&65280)>>8|(ie&255)<<8)>>1}for(var $e=(function(s,e,t){for(var n=s.length,r=0,i=new ve(e);r<n;++r)s[r]&&++i[s[r]-1];var a=new ve(e);for(r=1;r<e;++r)a[r]=a[r-1]+i[r-1]<<1;var o;if(t){o=new ve(1<<e);var c=15-e;for(r=0;r<n;++r)if(s[r])for(var l=r<<4|s[r],d=e-s[r],h=a[s[r]-1]++<<d,y=h|(1<<d)-1;h<=y;++h)o[mt[h]>>c]=l}else for(o=new ve(n),r=0;r<n;++r)s[r]&&(o[r]=mt[a[s[r]-1]++]>>15-s[r]);return o}),Pe=new j(288),E=0;E<144;++E)Pe[E]=8;for(var E=144;E<256;++E)Pe[E]=9;for(var E=256;E<280;++E)Pe[E]=7;for(var E=280;E<288;++E)Pe[E]=8;for(var as=new j(32),E=0;E<32;++E)as[E]=5;var vn=$e(Pe,9,1),_n=$e(as,5,1),gt=function(s){for(var e=s[0],t=1;t<s.length;++t)s[t]>e&&(e=s[t]);return e},F=function(s,e,t){var n=e/8|0;return(s[n]|s[n+1]<<8)>>(e&7)&t},yt=function(s,e){var t=e/8|0;return(s[t]|s[t+1]<<8|s[t+2]<<16)>>(e&7)},bn=function(s){return(s+7)/8|0},vt=function(s,e,t){return(e==null||e<0)&&(e=0),(t==null||t>s.length)&&(t=s.length),new j(s.subarray(e,t))},wn=["unexpected EOF","invalid block type","invalid length/literal","invalid distance","stream finished","no stream handler",,"no callback","invalid UTF-8 data","extra field too long","date not in range 1980-2099","filename too long","stream finishing","invalid zip data"],V=function(s,e,t){var n=new Error(e||wn[s]);if(n.code=s,Error.captureStackTrace&&Error.captureStackTrace(n,V),!t)throw n;return n},kn=function(s,e,t,n){var r=s.length,i=n?n.length:0;if(!r||e.f&&!e.l)return t||new j(0);var a=!t,o=a||e.i!=2,c=e.i;a&&(t=new j(r*3));var l=function(Ts){var Cs=t.length;if(Ts>Cs){var Es=new j(Math.max(Cs*2,Ts));Es.set(t),t=Es}},d=e.f||0,h=e.p||0,y=e.b||0,$=e.l,R=e.d,C=e.m,A=e.n,k=r*8;do{if(!$){d=F(s,h,1);var L=F(s,h+1,3);if(h+=3,L)if(L==1)$=vn,R=_n,C=9,A=5;else if(L==2){var we=F(s,h,31)+257,tt=F(s,h+10,15)+4,st=we+F(s,h+5,31)+1;h+=14;for(var fe=new j(st),Me=new j(19),M=0;M<tt;++M)Me[pn[M]]=F(s,h+M*3,7);h+=tt*3;for(var ke=gt(Me),Ze=(1<<ke)-1,Z=$e(Me,ke,1),M=0;M<st;){var U=Z[F(s,h,Ze)];h+=U&15;var P=U>>4;if(P<16)fe[M++]=P;else{var X=0,xe=0;for(P==16?(xe=3+F(s,h,3),h+=2,X=fe[M-1]):P==17?(xe=3+F(s,h,7),h+=3):P==18&&(xe=11+F(s,h,127),h+=7);xe--;)fe[M++]=X}}var je=fe.subarray(0,we),ae=fe.subarray(we);C=gt(je),A=gt(ae),$=$e(je,C,1),R=$e(ae,A,1)}else V(1);else{var P=bn(h)+4,Le=s[P-4]|s[P-3]<<8,be=P+Le;if(be>r){c&&V(0);break}o&&l(y+Le),t.set(s.subarray(P,be),y),e.b=y+=Le,e.p=h=be*8,e.f=d;continue}if(h>k){c&&V(0);break}}o&&l(y+131072);for(var ur=(1<<C)-1,dr=(1<<A)-1,$t=h;;$t=h){var X=$[yt(s,h)&ur],Se=X>>4;if(h+=X&15,h>k){c&&V(0);break}if(X||V(2),Se<256)t[y++]=Se;else if(Se==256){$t=h,$=null;break}else{var xs=Se-254;if(Se>264){var M=Se-257,Ve=ts[M];xs=F(s,h,(1<<Ve)-1)+is[M],h+=Ve}var Pt=R[yt(s,h)&dr],Ot=Pt>>4;Pt||V(3),h+=Pt&15;var ae=yn[Ot];if(Ot>3){var Ve=ss[Ot];ae+=yt(s,h)&(1<<Ve)-1,h+=Ve}if(h>k){c&&V(0);break}o&&l(y+131072);var Ss=y+xs;if(y<ae){var As=i-ae,fr=Math.min(ae,Ss);for(As+y<0&&V(3);y<fr;++y)t[y]=n[As+y]}for(;y<Ss;++y)t[y]=t[y-ae]}}e.l=$,e.p=$t,e.b=y,e.f=d,$&&(d=1,e.m=C,e.d=R,e.n=A)}while(!d);return y!=t.length&&a?vt(t,0,y):t.subarray(0,y)},xn=new j(0),q=function(s,e){return s[e]|s[e+1]<<8},B=function(s,e){return(s[e]|s[e+1]<<8|s[e+2]<<16|s[e+3]<<24)>>>0},_t=function(s,e){return B(s,e)+B(s,e+4)*4294967296};function Sn(s,e){return kn(s,{i:2},e&&e.out,e&&e.dictionary)}var bt=typeof TextDecoder<"u"&&new TextDecoder,An=0;try{bt.decode(xn,{stream:!0}),An=1}catch{}var Tn=function(s){for(var e="",t=0;;){var n=s[t++],r=(n>127)+(n>223)+(n>239);if(t+r>s.length)return{s:e,r:vt(s,t-1)};r?r==3?(n=((n&15)<<18|(s[t++]&63)<<12|(s[t++]&63)<<6|s[t++]&63)-65536,e+=String.fromCharCode(55296|n>>10,56320|n&1023)):r&1?e+=String.fromCharCode((n&31)<<6|s[t++]&63):e+=String.fromCharCode((n&15)<<12|(s[t++]&63)<<6|s[t++]&63):e+=String.fromCharCode(n)}};function os(s,e){if(e){for(var t="",n=0;n<s.length;n+=16384)t+=String.fromCharCode.apply(null,s.subarray(n,n+16384));return t}else{if(bt)return bt.decode(s);var r=Tn(s),i=r.s,t=r.r;return t.length&&V(8),i}}var Cn=function(s,e){return e+30+q(s,e+26)+q(s,e+28)},En=function(s,e,t){var n=q(s,e+28),r=q(s,e+30),i=os(s.subarray(e+46,e+46+n),!(q(s,e+8)&2048)),a=e+46+n,o=Nn(s,a,r,t,B(s,e+20),B(s,e+24),B(s,e+42)),c=o[0],l=o[1],d=o[2];return[q(s,e+10),c,l,i,a+r+q(s,e+32),d]},Nn=function(s,e,t,n,r,i,a){var o=r==4294967295,c=i==4294967295,l=a==4294967295,d=e+t,h=o+c+l;if(n&&h){for(;e+4<d;e+=4+q(s,e+2))if(q(s,e)==1)return[o?_t(s,e+4+8*c):r,c?_t(s,e+4):i,l?_t(s,e+4+8*(c+o)):a,1];n<2&&V(13)}return[r,i,a,0]};function In(s,e){for(var t={},n=s.length-22;B(s,n)!=101010256;--n)(!n||s.length-n>65558)&&V(13);var r=q(s,n+8);if(!r)return{};var i=B(s,n+16),a=B(s,n-20)==117853008;if(a){var o=B(s,n-12);a=B(s,o)==101075792,a&&(r=B(s,o+32),i=B(s,o+48))}for(var c=0;c<r;++c){var l=En(s,i,a),d=l[0],h=l[1],y=l[2],$=l[3],R=l[4],C=l[5],A=Cn(s,C);i=R,d?d==8?t[$]=Sn(s.subarray(A,A+h),{out:new j(y)}):V(14,"unknown compression type "+d):t[$]=vt(s,A,A+h)}return t}const cs=[80,75];function wt(s){return s.length>=2&&s[0]===cs[0]&&s[1]===cs[1]}function kt(s){const e=s instanceof Uint8Array?s:new Uint8Array(s);if(!wt(e))throw new Error("Not a ZIP archive");const t=In(e),n=new Map;for(const[r,i]of Object.entries(t))!i||r.endsWith("/")||n.set(H(r),i);return n}function H(s){return s.replace(/\\/g,"/").replace(/^\.\//,"").replace(/^\/+/,"")}function Oe(s,e){const t=Qe(s,e);if(!t)throw new Error(`Missing zip entry: ${e}`);return os(t)}function Qe(s,e){const t=H(e);if(s.has(t))return s.get(t);const n=t.toLowerCase();for(const[r,i]of s)if(r.toLowerCase()===n)return i}function $n(s){return[...s.keys()]}function Pn(s){var t;switch(((t=s.split(".").pop())==null?void 0:t.toLowerCase())??""){case"png":return"image/png";case"jpg":case"jpeg":return"image/jpeg";case"gif":return"image/gif";case"webp":return"image/webp";case"svg":return"image/svg+xml";case"mp3":return"audio/mpeg";case"wav":return"audio/wav";case"ogg":return"audio/ogg";case"m4a":return"audio/mp4";case"webm":return"audio/webm";case"vtt":return"text/vtt";case"html":case"xhtml":case"htm":return"application/xhtml+xml";case"css":return"text/css";case"json":return"application/json";case"woff":return"font/woff";case"woff2":return"font/woff2";case"ttf":return"font/ttf";case"otf":return"font/otf";default:return"application/octet-stream"}}function ls(s,e){const t=new Uint8Array(s.byteLength);t.set(s);const n=new Blob([t.buffer],{type:Pn(e)});return URL.createObjectURL(n)}async function On(s){const e=await fetch(s);if(!e.ok)throw new Error(`Failed to fetch ${s}: ${e.status}`);return e.arrayBuffer()}function Rn(s){return xt(kt(s))}function xt(s){const e=Oe(s,"META-INF/container.xml"),t=J(e,/full-path\s*=\s*"([^"]+)"/i);if(!t)throw new Error("Invalid EPUB: missing rootfile in container.xml");const n=H(t),r=n.includes("/")?n.replace(/\/[^/]+$/,"/"):"",i=Oe(s,n),a=fs(i,"dc:title")||fs(i,"title")||"EPUB Story",o=jn(i)??{width:768,height:1024},c=Mn(i,r),l=Zn(i),d=[],h=new Map,y=A=>{const k=H(A);if(h.has(k))return h.get(k);const L=Qe(s,k);if(!L)throw new Error(`EPUB missing file: ${k}`);const P=ls(L,k);return d.push(P),h.set(k,P),P},$={},R=[];if(l.forEach((A,k)=>{const L=c.get(A);if(!L||!/html|xml/i.test(L.mediaType)&&!L.href.match(/\.x?html?$/i))return;const P=L.href,Le=Oe(s,P),be=P.includes("/")?P.replace(/\/[^/]+$/,"/"):"",we=`page-${k+1}`,tt=zn(Le),{html:st,imageHrefs:fe}=Bn(tt,be,Z=>{const U=H(Z.includes(":")?Z:`${be}${Z}`);try{return y(U)}catch{return Z}}),Me=[{id:`${we}-text`,type:"text",layout:{x:"5%",y:"5%",width:"90%",height:"90%"},html:st}],M=fe[0];let ke;if(M){const Z=`img-${k}-0`;$[Z]={type:"image",src:y(M)},ke={asset:Z,color:"#ffffff"}}else ke={color:"#ffffff"};let Ze;if(L.mediaOverlay){const Z=c.get(L.mediaOverlay);if(Z){const U=Vn(Oe(s,Z.href),Z.href);if(U.audioHref){const X=`vo-${k}`,xe=H(U.audioHref.includes("/")||U.audioHref.startsWith(".")?ds(Z.href,U.audioHref):`${r}${U.audioHref}`);$[X]={type:"audio",src:y(xe),channel:"vo"};const je=U.cues;je.length?Ze={audio:X,cues:je}:Ze={audio:X}}}}R.push({id:we,background:ke,readAloud:Ze,blocks:Me})}),R.length===0)throw new Error("Invalid EPUB: no spine HTML documents found");return{story:ye({id:`epub-${Fn(a)}`,title:a,pageSize:o,layout:{mode:"auto",singleBreakpoint:900},fonts:[],assets:$,pages:R}),blobUrls:d}}function Ln(s){return!!Qe(s,"META-INF/container.xml")}function Mn(s,e){const t=new Map,n=/<item\b[^>]*>/gi;let r;for(;r=n.exec(s);){const i=r[0],a=J(i,/\bid\s*=\s*"([^"]+)"/i),o=J(i,/\bhref\s*=\s*"([^"]+)"/i),c=J(i,/\bmedia-type\s*=\s*"([^"]+)"/i)??"",l=J(i,/\bmedia-overlay\s*=\s*"([^"]+)"/i)??void 0,d=J(i,/\bproperties\s*=\s*"([^"]+)"/i)??void 0;!a||!o||t.set(a,{id:a,href:H(`${e}${o}`),mediaType:c,mediaOverlay:l,properties:d})}return t}function Zn(s){const e=s.match(/<spine\b[^>]*>([\s\S]*?)<\/spine>/i);if(!e)return[];const t=[],n=/<itemref\b[^>]*\bidref\s*=\s*"([^"]+)"[^>]*>/gi;let r;for(;r=n.exec(e[1]);)t.push(r[1]);return t}function jn(s){const e=s.match(/<meta\b[^>]*name\s*=\s*"viewport"[^>]*content\s*=\s*"([^"]+)"[^>]*>/i)||s.match(/<meta\b[^>]*content\s*=\s*"([^"]+)"[^>]*name\s*=\s*"viewport"[^>]*>/i);if(!e)return null;const t=e[1],n=t.match(/width\s*=\s*(\d+)/i),r=t.match(/height\s*=\s*(\d+)/i);return!n||!r?null:{width:Number(n[1]),height:Number(r[1])}}function Vn(s,e){const t=[];let n;const r=J(s,/<audio\b[^>]*\bsrc\s*=\s*"([^"]+)"/i);r&&(n=ds(e,r));const i=/<par\b[^>]*>([\s\S]*?)<\/par>/gi;let a,o=0;for(;a=i.exec(s);){const c=a[1],l=J(c,/<text\b[^>]*\bsrc\s*=\s*"([^"]+)"/i),d=J(c,/\bclipBegin\s*=\s*"([^"]+)"/i),h=J(c,/\bclipEnd\s*=\s*"([^"]+)"/i),y=l!=null&&l.includes("#")?l.split("#")[1]:`cue-${o}`;d==null||h==null||(t.push({id:y||`cue-${o}`,start:us(d),end:us(h)}),o+=1)}return{audioHref:n,cues:t}}function us(s){const e=s.replace(/^npt=/i,"").trim();if(/^\d+(\.\d+)?$/.test(e))return Number(e);const t=e.split(":").map(Number);return t.length===3?t[0]*3600+t[1]*60+t[2]:t.length===2?t[0]*60+t[1]:0}function zn(s){const e=s.match(/<body\b[^>]*>([\s\S]*?)<\/body>/i);return e?e[1].trim():s}function Bn(s,e,t){const n=[];return{html:s.replace(/\b(src|href)\s*=\s*["']([^"']+)["']/gi,(i,a,o)=>{if(/^(?:[a-z]+:|#|data:)/i.test(o))return i;const c=H(`${e}${o}`);/\.(png|jpe?g|gif|webp|svg)$/i.test(o)&&n.push(c);const l=t(o);return`${a}="${l}"`}),imageHrefs:n}}function ds(s,e){if(/^(?:[a-z]+:)/i.test(e))return e;const n=((s.includes("/")?s.replace(/\/[^/]+$/,"/"):"")+e).split("/"),r=[];for(const i of n)!i||i==="."||(i===".."?r.pop():r.push(i));return r.join("/")}function J(s,e){const t=s.match(e);return t?t[1]:null}function fs(s,e){const t=new RegExp(`<${e.replace(":",":")}[^>]*>([^<]*)</${e.replace(":",":")}>`,"i"),n=s.match(t);return n?n[1].trim():null}function Fn(s){return s.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-|-$/g,"").slice(0,48)||"book"}function St(s){const e=$n(s),t=e.find(r=>r==="story.json"||r.toLowerCase()==="story.json");if(t)return t;const n=e.filter(r=>r.toLowerCase().endsWith("/story.json")||r.toLowerCase()==="story.json").sort((r,i)=>r.length-i.length);if(n[0])return n[0];throw new Error("Invalid .fanci package: missing story.json")}function At(s){const e=St(s),t=e.includes("/")?e.replace(/\/[^/]+$/,"/"):"",n=ye(JSON.parse(Oe(s,e))),r=new Map,i=[];for(const[a,o]of s){if(a===e)continue;const c=ls(o,a);i.push(c),r.set(a,c),t&&a.startsWith(t)&&r.set(a.slice(t.length),c)}return Wn(n,a=>Dn(r,t,a)),{story:n,pathUrls:r,blobUrls:i,storyDir:t}}function Un(s){return At(kt(s))}function Dn(s,e,t){const n=H(t);if(s.has(n))return s.get(n);const r=H(`${e}${n}`);if(s.has(r))return s.get(r);const i=n.toLowerCase();for(const[a,o]of s)if(a.toLowerCase()===i||a.toLowerCase().endsWith(`/${i}`))return o}function Wn(s,e){for(const t of s.fonts){const n=e(t.src);n&&(t.src=n)}for(const t of Object.values(s.assets)){const n=e(t.src);n&&(t.src=n)}for(const t of s.pages)for(const n of t.blocks)if(n.type==="text"&&n.htmlSrc){const r=e(n.htmlSrc);r&&(n.htmlSrc=r)}}function qn(s){if(Qe(s,"META-INF/container.xml"))return!1;try{return St(s),!0}catch{return!1}}const Ke=".fanci";function Tt(s){const e=s.split("?")[0].split("#")[0],t=e.split("/").pop()??e,n=t.lastIndexOf(".");return n>=0?t.slice(n).toLowerCase():""}function Hn(s,e){if(typeof s=="object"&&s!==null&&!(s instanceof Blob)&&!(s instanceof ArrayBuffer)&&!(s instanceof Uint8Array)&&!ArrayBuffer.isView(s)&&("story"in s||"id"in s&&"pages"in s))return"object";const t=e??(typeof s=="string"?s:s instanceof File?s.name:""),n=Tt(t);return n===Ke||n===".fanci.zip"?"fanci":n===".epub"?"epub":"json"}async function Jn(s){return s instanceof ArrayBuffer?s:s instanceof Uint8Array?s.buffer.slice(s.byteOffset,s.byteOffset+s.byteLength):s.arrayBuffer()}async function Ct(s,e){const t=typeof e=="string"?{baseUrl:e}:e??{},n=t.onProgress??(()=>{});if(Yn(s)){n({stage:"parse",progress:.1,detail:"story object"});const r=ye(s),i=t.baseUrl??(typeof location<"u"?location.href:"");n({stage:"assets",progress:.2,detail:"fonts"}),await Ie(r,i);const a=await Re(r,i,n,.25,1);return n({stage:"complete",progress:1}),{story:r,baseUrl:i,assets:a,blobUrls:[],kind:"object"}}if(typeof s=="object"&&s!==null&&"story"in s&&!hs(s)){const r=s;return Ct(r.story,{baseUrl:t.baseUrl??r.baseUrl,name:t.name,onProgress:t.onProgress})}if(typeof s=="string")return Xn(s,t,n);if(hs(s)){n({stage:"fetch",progress:.05,detail:"bytes"});const r=await Jn(s),i=t.name??(s instanceof File?s.name:void 0)??"";return Et(r,i,t.baseUrl,n)}throw new Error("Unsupported story source")}async function Xn(s,e,t){const n=Tt(s),r=Hn(s,e.name??s);if(t({stage:"fetch",progress:.02,detail:s}),n===Ke||n===".epub"||r==="fanci"||r==="epub"){const y=await On(s);return t({stage:"fetch",progress:.15,detail:"package downloaded"}),Et(y,e.name??s,e.baseUrl,t)}const i=await fetch(s);if(!i.ok)throw new Error(`Failed to load story: ${i.status} ${i.statusText}`);const a=await i.arrayBuffer(),o=new Uint8Array(a);if(wt(o))return t({stage:"fetch",progress:.15,detail:"zip downloaded"}),Et(a,e.name??s,e.baseUrl,t);t({stage:"parse",progress:.2,detail:"json"});const c=new TextDecoder().decode(o),l=ye(JSON.parse(c)),d=e.baseUrl??fn(new URL(s,location.href).href);await Ie(l,d);const h=await Re(l,d,t,.3,1);return t({stage:"complete",progress:1}),{story:l,baseUrl:d,assets:h,blobUrls:[],kind:"json"}}async function Et(s,e,t,n){const r=new Uint8Array(s),i=Tt(e);if(wt(r)){n({stage:"unpack",progress:.2,detail:"unzip"});const l=kt(r);if(n({stage:"unpack",progress:.35,detail:`${l.size} entries`}),i===".epub"||Ln(l)){n({stage:"parse",progress:.4,detail:"epub"});const{story:d,blobUrls:h}=xt(l);await Ie(d,t??"");const y=await Re(d,t??"",n,.5,1);return n({stage:"complete",progress:1}),{story:d,baseUrl:t??"",assets:y,blobUrls:h,kind:"epub"}}if(i===Ke||qn(l)){n({stage:"parse",progress:.4,detail:"fanci"});const{story:d,blobUrls:h}=At(l);await Ie(d,t??"");const y=await Re(d,t??"",n,.5,1);return n({stage:"complete",progress:1}),{story:d,baseUrl:t??"",assets:y,blobUrls:h,kind:"fanci"}}throw new Error("ZIP archive is neither a .fanci package (story.json) nor an EPUB (META-INF/container.xml)")}n({stage:"parse",progress:.25,detail:"json bytes"});const a=ye(JSON.parse(new TextDecoder().decode(r))),o=t??(typeof location<"u"?location.href:"");await Ie(a,o);const c=await Re(a,o,n,.35,1);return n({stage:"complete",progress:1}),{story:a,baseUrl:o,assets:c,blobUrls:[],kind:"json"}}function Yn(s){return typeof s=="object"&&s!==null&&!Array.isArray(s)&&!(s instanceof Blob)&&!(s instanceof ArrayBuffer)&&!(s instanceof Uint8Array)&&"id"in s&&"pages"in s&&"pageSize"in s}function hs(s){return s instanceof ArrayBuffer||s instanceof Uint8Array||s instanceof Blob||typeof File<"u"&&s instanceof File}async function Re(s,e,t,n,r){var R;const i=new Map,a=new Map,o=new Map,c=new Map,l=Object.entries(s.assets),d=[];for(const C of s.pages)for(const A of C.blocks)if(A.type==="text"&&A.htmlSrc&&!A.html&&d.push(async()=>{const k=Ge(e,A.htmlSrc);c.set(`htmlSrc:${A.id}`,await et(k))}),(R=C.readAloud)!=null&&R.cues&&typeof C.readAloud.cues=="string"){const k=C.readAloud.cues;s.assets[k]||d.push(async()=>{const L=Ge(e,k);try{o.set(k,ht(await et(L)))}catch{}})}const h=l.length+d.length||1;let y=0;const $=C=>{y+=1;const A=y/h,k=n+(r-n)*Math.min(1,A);t({stage:"assets",progress:k,count:y,total:h,detail:C})};return await Promise.all(l.map(async([C,A])=>{const k=Ge(e,A.src);A.type==="image"?i.set(C,await Gn(k)):A.type==="audio"?a.set(C,{url:k,channel:A.channel??"vo"}):A.type==="vtt"?o.set(C,ht(await et(k))):A.type==="html"&&c.set(C,await et(k)),$(C)})),await Promise.all(d.map(async C=>{await C(),$("fragment")})),l.length===0&&d.length===0&&t({stage:"assets",progress:r,count:0,total:0,detail:"none"}),{images:i,audioUrls:a,cues:o,html:c}}function Gn(s){return new Promise((e,t)=>{const n=new Image;n.decoding="async",n.onload=()=>e(n),n.onerror=()=>t(new Error(`Failed to load image: ${s}`)),n.src=s})}async function et(s){const e=await fetch(s);if(!e.ok)throw new Error(`Failed to load ${s}: ${e.status}`);return e.text()}function ps(s){for(const e of s.blobUrls)try{URL.revokeObjectURL(e)}catch{}s.blobUrls.length=0}function ms(s,e,t){return s==="auto"?e>=t?"two-page":"single":s}function gs(s){if(s.length===0)return[];const e=[];e.push({index:0,left:{kind:"blank"},right:{kind:"page",pageIndex:0,pageId:s[0].id}});let t=1;for(;t<s.length;){const n={kind:"page",pageIndex:t,pageId:s[t].id},r=t+1<s.length?{kind:"page",pageIndex:t+1,pageId:s[t+1].id}:{kind:"blank"};e.push({index:e.length,left:n,right:r}),t+=2}return e}function ys(s){const e=[];return s.left.kind==="page"&&e.push(s.left.pageId),s.right.kind==="page"&&e.push(s.right.pageId),e}function Qn(s,e){const t=s.findIndex(n=>n.left.kind==="page"&&n.left.pageId===e||n.right.kind==="page"&&n.right.pageId===e);return t<0?0:t}class Kn{constructor(e,t){g(this,"story");g(this,"spreadView");g(this,"spreads");g(this,"spreadIndex",0);g(this,"preferredMode");g(this,"resolvedMode","single");g(this,"breakpoint");g(this,"listeners",new Map);g(this,"busy",!1);this.story=e,this.spreadView=t,this.spreads=gs(e.pages),this.preferredMode=e.layout.mode,this.breakpoint=e.layout.singleBreakpoint}get layoutMode(){return this.resolvedMode}get currentSpread(){return this.spreads[this.spreadIndex]}get currentPageIds(){return ys(this.currentSpread)}on(e,t){return this.listeners.has(e)||this.listeners.set(e,new Set),this.listeners.get(e).add(t),()=>{var n;return(n=this.listeners.get(e))==null?void 0:n.delete(t)}}setLayoutMode(e,t){this.preferredMode=e,this.updateLayout(t,!1)}updateLayout(e,t=!0){const n=ms(this.preferredMode,e,this.breakpoint),r=n!==this.resolvedMode;this.resolvedMode=n,this.spreadView.setLayoutMode(n),r&&t&&this.emit("layoutchange",{layoutMode:n})}async showInitial(){await this.spreadView.showSpread(this.currentSpread,"none"),this.emitPageChange()}async next(){this.busy||this.spreadIndex>=this.spreads.length-1||(this.busy=!0,this.spreadIndex+=1,await this.spreadView.showSpread(this.currentSpread,"next"),this.emitPageChange(),this.busy=!1)}async prev(){this.busy||this.spreadIndex<=0||(this.busy=!0,this.spreadIndex-=1,await this.spreadView.showSpread(this.currentSpread,"prev"),this.emitPageChange(),this.busy=!1)}async goTo(e){const t=Qn(this.spreads,e);if(t===this.spreadIndex)return;const n=t>this.spreadIndex?"next":"prev";this.busy=!0,this.spreadIndex=t,await this.spreadView.showSpread(this.currentSpread,n),this.emitPageChange(),this.busy=!1}emitPageChange(){this.emit("pagechange",{pageIds:this.currentPageIds,index:this.spreadIndex,layoutMode:this.resolvedMode})}emit(e,t){const n=this.listeners.get(e);if(n)for(const r of n)r(t)}}function er(s){const e=s??{},t={left:_e(e.x??0),top:_e(e.y??0)};return e.width!=null&&(t.width=_e(e.width)),e.height!=null&&(t.height=_e(e.height)),t}function Nt(s,e){const t=er(e);s.style.left=t.left,s.style.top=t.top,t.width&&(s.style.width=t.width),t.height&&(s.style.height=t.height),(e==null?void 0:e.horizontalAlign)==="right"?(s.style.left="auto",s.style.right=_e(e.x??0)):(e==null?void 0:e.horizontalAlign)==="center"&&(s.style.left="50%",s.style.transform=`${s.style.transform||""} translateX(-50%)`.trim()),(e==null?void 0:e.verticalAlign)==="bottom"?(s.style.top="auto",s.style.bottom=_e(e.y??0)):(e==null?void 0:e.verticalAlign)==="center"&&(s.style.top="50%",s.style.transform=`${s.style.transform||""} translateY(-50%)`.trim())}function _e(s){return typeof s=="number"?`${s}px`:/^-?\d+(\.\d+)?$/.test(s)?`${s}px`:s}function tr(s,e){const t=document.createElement("button");return t.type="button",t.className="fc-block fc-block-hotspot",t.dataset.blockId=s.id,t.setAttribute("aria-label",s.ariaLabel??s.id),Nt(t,s.layout),t.addEventListener("click",n=>{n.stopPropagation(),e(s.onTap??[])}),t}function sr(s,e){var i;const t=document.createElement("div");t.className=`fc-block fc-block-image${s.className?` ${s.className}`:""}`,t.dataset.blockId=s.id,Nt(t,s.layout);const n=document.createElement("img");n.alt="",n.draggable=!1,e&&(n.src=e.src);const r=((i=s.layout)==null?void 0:i.fit)??"contain";return n.style.objectFit=r,t.appendChild(n),t}function nr(s,e){const t=document.createElement("div");return t.className="fc-block fc-block-text",t.dataset.blockId=s.id,Nt(t,s.layout),t.innerHTML=e,t.querySelectorAll("[id]").forEach(n=>{n.classList.add("fc-cue")}),s.style&&(s.style.fontFamily&&(t.style.fontFamily=s.style.fontFamily),s.style.fontSize&&(t.style.fontSize=s.style.fontSize),s.style.color&&(t.style.color=s.style.color),s.style.textAlign&&(t.style.textAlign=s.style.textAlign),s.style.lineHeight!=null&&(t.style.lineHeight=String(s.style.lineHeight))),t}class vs{constructor(e,t,n){g(this,"element");g(this,"page");g(this,"blank");var r,i;if(this.page=e,this.blank=!e,this.element=document.createElement("article"),this.element.className=`fc-page${this.blank?" fc-page-blank":""}`,this.element.setAttribute("role",this.blank?"presentation":"document"),!e){this.element.dataset.blank="true";return}if(this.element.dataset.pageId=e.id,(r=e.background)!=null&&r.color&&(this.element.style.backgroundColor=e.background.color),(i=e.background)!=null&&i.asset){const a=t.images.get(e.background.asset);a&&(this.element.style.backgroundImage=`url(${JSON.stringify(a.src)})`,this.element.style.backgroundSize="cover",this.element.style.backgroundPosition="center")}for(const a of e.blocks)if(a.type==="text"){const o=a.html??t.html.get(`htmlSrc:${a.id}`)??(a.htmlSrc?t.html.get(a.htmlSrc):void 0)??"";this.element.appendChild(nr(a,o))}else a.type==="image"?this.element.appendChild(sr(a,t.images.get(a.asset))):a.type==="hotspot"&&this.element.appendChild(tr(a,o=>n.onTapActions(o,this.element)))}destroy(){this.element.remove()}}class rr{constructor(e,t,n){g(this,"element");g(this,"bookEl");g(this,"leftSlot");g(this,"rightSlot");g(this,"leftPage",null);g(this,"rightPage",null);g(this,"story");g(this,"assets");g(this,"onTapActions");g(this,"turning",!1);this.story=e,this.assets=t,this.onTapActions=n,this.element=document.createElement("div"),this.element.className="fc-spread-viewport",this.bookEl=document.createElement("div"),this.bookEl.className="fc-spread",this.leftSlot=document.createElement("div"),this.leftSlot.className="fc-leaf fc-leaf-left",this.rightSlot=document.createElement("div"),this.rightSlot.className="fc-leaf fc-leaf-right",this.bookEl.append(this.leftSlot,this.rightSlot),this.element.appendChild(this.bookEl)}setLayoutMode(e){this.element.dataset.layoutMode=e,this.element.classList.toggle("fc-spread-viewport-single",e==="single"),this.element.classList.toggle("fc-spread-viewport-two",e==="two-page")}showSpread(e,t="none"){return t==="none"||this.turning?(this.mountSpread(e),Promise.resolve()):(this.turning=!0,this.bookEl.classList.remove("fc-turn-next","fc-turn-prev"),this.bookEl.offsetWidth,this.bookEl.classList.add(t==="next"?"fc-turn-next":"fc-turn-prev"),new Promise(n=>{const r=()=>{this.bookEl.removeEventListener("animationend",r),this.bookEl.classList.remove("fc-turn-next","fc-turn-prev"),this.mountSpread(e),this.turning=!1,n()};this.bookEl.addEventListener("animationend",r),window.setTimeout(r,450)}))}getPageElement(e){var t,n,r,i;return((n=(t=this.leftPage)==null?void 0:t.page)==null?void 0:n.id)===e?this.leftPage.element:((i=(r=this.rightPage)==null?void 0:r.page)==null?void 0:i.id)===e?this.rightPage.element:null}getVisiblePageElements(e,t){const n=[];return e==="two-page"?(t.left.kind==="page"&&this.leftPage&&n.push(this.leftPage.element),t.right.kind==="page"&&this.rightPage&&n.push(this.rightPage.element)):t.left.kind==="blank"&&t.right.kind==="page"&&this.rightPage?n.push(this.rightPage.element):t.right.kind==="blank"&&t.left.kind==="page"&&this.leftPage?n.push(this.leftPage.element):t.left.kind==="page"&&this.leftPage?n.push(this.leftPage.element):t.right.kind==="page"&&this.rightPage&&n.push(this.rightPage.element),n}updateStageSize(e,t,n,r){const{width:i,height:a}=this.story.pageSize,o=i*2,c=a;let l;n==="single"?l=Math.min(e/i,t/a):l=Math.min(e/o,t/c),this.bookEl.style.width=`${o}px`,this.bookEl.style.height=`${c}px`,this.bookEl.style.setProperty("--fc-page-width",`${i}px`),this.bookEl.style.setProperty("--fc-page-height",`${a}px`);let d=0;n==="single"&&r&&r.left.kind==="blank"&&(d=-i*l),this.bookEl.style.transform=`translateX(${d}px) scale(${l})`,this.bookEl.style.transformOrigin="left top",this.element.style.width=n==="single"?`${i*l}px`:`${o*l}px`,this.element.style.height=`${c*l}px`}destroy(){var e,t;(e=this.leftPage)==null||e.destroy(),(t=this.rightPage)==null||t.destroy(),this.element.remove()}mountSpread(e){var t,n;(t=this.leftPage)==null||t.destroy(),(n=this.rightPage)==null||n.destroy(),this.leftSlot.replaceChildren(),this.rightSlot.replaceChildren(),this.leftPage=this.createLeaf(e.left),this.rightPage=this.createLeaf(e.right),this.leftSlot.appendChild(this.leftPage.element),this.rightSlot.appendChild(this.rightPage.element)}createLeaf(e){if(e.kind==="blank")return new vs(null,this.assets,{onTapActions:this.onTapActions});const t=this.story.pages[e.pageIndex];return new vs(t,this.assets,{onTapActions:this.onTapActions})}}function _s(s,e){const t=s==null?void 0:s.container;if(!(t!=null&&t.send))return;const n=or(e.progress);t.send("progress",n),t.send("loading",{stage:e.stage,progress:n,count:e.count,total:e.total,detail:e.detail})}function ir(s){var e,t;(t=(e=s==null?void 0:s.container)==null?void 0:e.send)==null||t.call(e,"loaded")}function ar(){let s;return{promise:new Promise(t=>{s=t}),resolve:s}}function or(s){return Number.isNaN(s)?0:Math.min(1,Math.max(0,s))}function bs(s,e,t={}){const n=[];let r=!1;const i=(a,o)=>{if(!(a!=null&&a.subscribe))return;const c=a.subscribe(o);typeof c=="function"?n.push(c):c&&typeof c.unsubscribe=="function"&&n.push(()=>{var l;return(l=c.unsubscribe)==null?void 0:l.call(c)})};return s!=null&&s.state&&(i(s.state.pause,a=>{var c;const o=!!a;e.setPaused(o),(c=t.onPause)==null||c.call(t,o)}),i(s.state.soundVolume,a=>e.setVolume("sound",Number(a))),i(s.state.voVolume,a=>e.setVolume("vo",Number(a))),i(s.state.sfxVolume,a=>e.setVolume("sfx",Number(a))),i(s.state.musicVolume,a=>e.setVolume("music",Number(a))),i(s.state.captionsMuted,a=>{var o;r=!!a,(o=t.onCaptionsMuted)==null||o.call(t,r)})),{get captionsMuted(){return r},destroy(){for(const a of n)a()}}}async function ws(s){var e,t;try{const n=await import("springroll"),r=n.Application??((e=n.default)==null?void 0:e.Application),i=n.ApplicationPlugin??((t=n.default)==null?void 0:t.ApplicationPlugin);if(!r)return null;const a=ar(),o=`fancifully-story-load-${Math.random().toString(36).slice(2,9)}`;if(i&&typeof r.uses=="function"){const l=new i({name:o});l.preload=()=>a.promise,r.uses(l)}else a.resolve();return{app:new r({features:s}),loadGate:a,owned:!0}}catch{return null}}function ks(s){var e;return!((e=s==null?void 0:s.state)!=null&&e.ready)||s.state.ready.value===!0?Promise.resolve():new Promise(t=>{const n=s.state.ready.subscribe(r=>{r&&(typeof n=="function"&&n(),t())})})}const cr={sound:!0,soundVolume:!0,vo:!0,voVolume:!0,sfx:!0,sfxVolume:!0,music:!0,musicVolume:!0,captions:!0};class It{constructor(e,t,n,r){g(this,"element");g(this,"root");g(this,"stage");g(this,"chrome");g(this,"captionsEl");g(this,"loaded");g(this,"spreadView");g(this,"pager");g(this,"bus",new Y);g(this,"readAloud");g(this,"springroll");g(this,"bindings",null);g(this,"sfxAudio");g(this,"unbindSwipe",null);g(this,"resizeObserver",null);g(this,"listeners",new Map);g(this,"destroyed",!1);this.root=e,this.loaded=t,this.springroll=n,this.element=document.createElement("div"),this.element.className="fc-root",this.element.tabIndex=0,this.stage=document.createElement("div"),this.stage.className="fc-stage",this.captionsEl=document.createElement("div"),this.captionsEl.className="fc-captions",this.captionsEl.setAttribute("aria-live","polite"),this.chrome=document.createElement("div"),this.chrome.className="fc-chrome",this.chrome.innerHTML=`
|
|
5
|
+
<button type="button" class="fc-btn fc-btn-prev" aria-label="Previous page">Prev</button>
|
|
6
|
+
<button type="button" class="fc-btn fc-btn-read" aria-label="Read aloud">Read</button>
|
|
7
|
+
<button type="button" class="fc-btn fc-btn-next" aria-label="Next page">Next</button>
|
|
8
|
+
`,this.spreadView=new rr(t.story,t.assets,(i,a)=>this.handleTapActions(i,a)),this.pager=new Kn(t.story,this.spreadView),this.readAloud=new Ns(this.bus),this.sfxAudio=new Audio,this.bus.register(this.sfxAudio,"sfx"),this.stage.appendChild(this.spreadView.element),this.element.append(this.stage,this.captionsEl,this.chrome),this.root.appendChild(this.element),this.wireChrome(),this.wirePager(r),this.wireSpringroll(),this.wireResize(),this.unbindSwipe=Is(this.stage,{onSwipeLeft:()=>void this.next(),onSwipeRight:()=>void this.prev()}),this.element.addEventListener("keydown",i=>{i.key==="ArrowRight"?(i.preventDefault(),this.next()):i.key==="ArrowLeft"?(i.preventDefault(),this.prev()):i.key===" "&&(i.preventDefault(),this.playReadAloud())}),this.readAloud.onCaption(i=>{this.captionsEl.textContent=i??"",this.captionsEl.hidden=!i})}static async create(e,t){const n={...cr,...t.features};let r=t.springroll??null,i=null;if(!r){const d=await ws(n);d&&(r=d.app,i=d.loadGate,lr(r))}const a=[];t.onProgress&&a.push(t.onProgress);const o=d=>{_s(r,d);for(const h of a)h(d)};o({stage:"fetch",progress:0,detail:"start"});const c=await Ct(t.story,{baseUrl:t.baseUrl,name:t.storyName,onProgress:o});i==null||i.resolve(),await ks(r);const l=new It(e,c,r,t.autoPlayReadAloud??!1);return l.pager.updateLayout(e.clientWidth||window.innerWidth,!1),l.layoutStage(),await l.pager.showInitial(),l.emit("ready",{story:c.story}),l}get story(){return this.loaded.story}get layoutMode(){return this.pager.layoutMode}get pageIds(){return this.pager.currentPageIds}get spreadIndex(){return this.pager.currentSpread.index}on(e,t){return this.listeners.has(e)||this.listeners.set(e,new Set),this.listeners.get(e).add(t),()=>{var n;return(n=this.listeners.get(e))==null?void 0:n.delete(t)}}next(){return this.readAloud.stop(),this.pager.next().then(()=>this.layoutStage())}prev(){return this.readAloud.stop(),this.pager.prev().then(()=>this.layoutStage())}goTo(e){return this.readAloud.stop(),this.pager.goTo(e).then(()=>this.layoutStage())}setLayoutMode(e){this.pager.setLayoutMode(e,this.root.clientWidth||window.innerWidth),this.layoutStage(),this.emit("layoutchange",{layoutMode:this.pager.layoutMode})}playReadAloud(){const e=this.buildReadAloudClips();return this.readAloud.playSequence(e)}pause(){this.readAloud.pause(),this.bus.setPaused(!0)}resume(){this.bus.setPaused(!1),this.readAloud.resume()}destroy(){var e,t,n;this.destroyed||(this.destroyed=!0,this.readAloud.destroy(),this.bus.unregister(this.sfxAudio),(e=this.bindings)==null||e.destroy(),(t=this.unbindSwipe)==null||t.call(this),(n=this.resizeObserver)==null||n.disconnect(),this.spreadView.destroy(),this.element.remove(),this.listeners.clear(),ps(this.loaded))}wireChrome(){var e,t,n;(e=this.chrome.querySelector(".fc-btn-prev"))==null||e.addEventListener("click",()=>void this.prev()),(t=this.chrome.querySelector(".fc-btn-next"))==null||t.addEventListener("click",()=>void this.next()),(n=this.chrome.querySelector(".fc-btn-read"))==null||n.addEventListener("click",()=>void this.playReadAloud())}wirePager(e){this.pager.on("pagechange",t=>{this.emit("pagechange",t),e&&this.playReadAloud()}),this.pager.on("layoutchange",t=>{this.layoutStage(),this.emit("layoutchange",t)})}wireSpringroll(){this.bindings=bs(this.springroll,this.bus,{onCaptionsMuted:e=>this.readAloud.setCaptionsMuted(e),onPause:e=>{e?this.readAloud.pause():this.readAloud.resume()}})}wireResize(){const e=()=>{this.pager.updateLayout(this.root.clientWidth||window.innerWidth),this.layoutStage()};typeof ResizeObserver<"u"?(this.resizeObserver=new ResizeObserver(e),this.resizeObserver.observe(this.root)):window.addEventListener("resize",e)}layoutStage(){const e=this.stage.clientWidth||this.root.clientWidth||window.innerWidth,t=this.stage.clientHeight||Math.max(320,this.root.clientHeight-64);this.spreadView.updateStageSize(e,t,this.pager.layoutMode,this.pager.currentSpread)}buildReadAloudClips(){const e=this.pager.layoutMode,t=this.pager.currentSpread,n=e==="two-page"?[t.left,t.right]:t.left.kind==="blank"?[t.right]:t.right.kind==="blank"?[t.left]:[t.left],r=[];for(const i of n){if(i.kind!=="page")continue;const a=this.loaded.story.pages[i.pageIndex];if(!a.readAloud)continue;const o=this.loaded.assets.audioUrls.get(a.readAloud.audio);if(!o)continue;const c=this.resolveCues(a.readAloud.cues),l=this.spreadView.getPageElement(a.id);r.push({url:o.url,channel:o.channel,cues:c,root:l})}return r}resolveCues(e){return e?Array.isArray(e)?e:this.loaded.assets.cues.get(e)??[]:[]}handleTapActions(e,t){for(const n of e)if("play"in n){const r=this.loaded.assets.audioUrls.get(n.play);if(!r)continue;this.sfxAudio.src=r.url,this.bus.applyTo(this.sfxAudio,r.channel),this.sfxAudio.play().catch(()=>{})}else if("toggleClass"in n){const r=t.querySelector(`[data-block-id="${n.toggleClass.target}"]`);r==null||r.classList.toggle(n.toggleClass.className)}}emit(e,t){const n=this.listeners.get(e);if(n)for(const r of n)r(t)}}function lr(s){var t,n,r,i,a,o;const e=s.state;e&&((t=e.pause)==null||t.subscribe(()=>{}),(n=e.soundVolume)==null||n.subscribe(()=>{}),(r=e.voVolume)==null||r.subscribe(()=>{}),(i=e.sfxVolume)==null||i.subscribe(()=>{}),(a=e.musicVolume)==null||a.subscribe(()=>{}),(o=e.captionsMuted)==null||o.subscribe(()=>{}))}return T.CueTimeline=Rt,T.FANCI_EXTENSION=Ke,T.Storybook=It,T.bindApplication=bs,T.buildSpreads=gs,T.contentPageIds=ys,T.createSpringrollApplication=ws,T.findStoryJsonPath=St,T.loadEpubFromBytes=Rn,T.loadEpubFromZip=xt,T.loadFanciFromBytes=Un,T.loadFanciFromZip=At,T.loadStory=Ct,T.parseStory=ye,T.parseVtt=ht,T.reportSpringrollLoaded=ir,T.reportSpringrollProgress=_s,T.resolveLayoutMode=ms,T.revokeLoadedStory=ps,T.storySchema=Kt,T.waitForSpringrollReady=ks,Object.defineProperty(T,Symbol.toStringTag,{value:"Module"}),T})({});
|