@toneflix/flipbook 0.0.0-stage → 0.2.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.
@@ -0,0 +1,143 @@
1
+ import { Face, FlipbookBook, FlipbookLabels, FlipbookPage, FlipbookPhoto, FlipbookReader, FrameStyle, GripOptions, PaperColor, TurnPhysics } from "@toneflix/flipbook-core";
2
+ export * from "@toneflix/flipbook-core";
3
+ interface FlipbookPlace {
4
+ /** How many leaves lie on the left: 0 is the closed front cover. */
5
+ flipped: number;
6
+ label: string;
7
+ faces: Face[];
8
+ }
9
+ interface FlipbookOptions {
10
+ book: FlipbookBook;
11
+ /** Open at this page (1-based) instead of the cover. */
12
+ startPage?: number;
13
+ /** Two pages side by side, one at a time, or whichever fits the space (default). */
14
+ layout?: 'auto' | 'spread' | 'single';
15
+ /** Show the top and bottom bars. */
16
+ controls?: boolean;
17
+ /** Hide the bars after this many ms without movement, or never with false. */
18
+ autoHide?: number | false;
19
+ thumbnails?: boolean;
20
+ soundButton?: boolean;
21
+ /** Play a paper sound on each turn. The sound button remembers the reader's choice. */
22
+ sound?: boolean;
23
+ fullscreenButton?: boolean;
24
+ /** Ask phones held upright to turn sideways, offering single pages instead. */
25
+ landscape?: boolean;
26
+ /** Arrow, page and Home/End keys: while the book has focus (true) or anywhere on the page ('global'). */
27
+ keyboard?: boolean | 'global';
28
+ /** Covers swing on the spine like board instead of curling like paper. */
29
+ stiffCovers?: boolean;
30
+ physics?: Partial<TurnPhysics>;
31
+ grip?: Partial<GripOptions>;
32
+ /** Strength of the light and shadow around a turning page, from 0 to 1 or more. */
33
+ shading?: number;
34
+ /** Backdrop behind the book. Defaults to a glow tinted by the cover. */
35
+ background?: string;
36
+ labels?: Partial<FlipbookLabels>;
37
+ onPageChange?: (place: FlipbookPlace) => void;
38
+ /** A page started to turn over. */
39
+ onFlip?: () => void;
40
+ }
41
+ /**
42
+ * A photo book that opens across two pages, turned by dragging, flicking, tapping, buttons or
43
+ * keys. Mount it into any sized element; call `destroy()` when it goes away.
44
+ */
45
+ export declare class Flipbook {
46
+ readonly container: HTMLElement;
47
+ readonly root: HTMLDivElement;
48
+ readonly reader: FlipbookReader;
49
+ private settings;
50
+ private layout;
51
+ private size;
52
+ private orientation;
53
+ private portraitChoice;
54
+ private soundOn;
55
+ private stripOpen;
56
+ private chromeVisible;
57
+ private hideTimer;
58
+ private lastPlace;
59
+ private rendering;
60
+ private dirty;
61
+ private faces;
62
+ private overlays;
63
+ private cleanups;
64
+ private els;
65
+ constructor(container: HTMLElement, options: FlipbookOptions);
66
+ /** Changes options in place; the reader keeps their page. */
67
+ update(options: Partial<FlipbookOptions>): void;
68
+ next(): void;
69
+ prev(): void;
70
+ /** Opens at a `flipped` value. */
71
+ go(flipped: number): void;
72
+ /** Opens at a page (1-based). */
73
+ goToPage(page: number): void;
74
+ destroy(): void;
75
+ private static resolve;
76
+ private get spread();
77
+ private buildLayout;
78
+ private build;
79
+ private listen;
80
+ private onKey;
81
+ /** Pointer position from the top of the spine. */
82
+ private toBook;
83
+ private poke;
84
+ private toggleSound;
85
+ private toggleFullscreen;
86
+ private clearFaces;
87
+ /** Brings the DOM in line with the reader. Re-entrant calls (from the reader) run once more at the end. */
88
+ private render;
89
+ private renderOnce;
90
+ /** Faces of the leaves around the opening. Each keeps its element while it moves between roles, so pages never reload mid-turn. */
91
+ private renderFaces;
92
+ private renderOverlays;
93
+ private paint;
94
+ private renderChrome;
95
+ /** A strip of every spread (or page) to jump around the book. */
96
+ private renderStrip;
97
+ /** Shown on phones held upright: books are read sideways. */
98
+ private renderRotatePrompt;
99
+ private static stageTint;
100
+ }
101
+ type Side = 'left' | 'right';
102
+ interface PageLook {
103
+ paper: PaperColor;
104
+ frame: FrameStyle;
105
+ }
106
+ interface PageOptions {
107
+ /** Printed in the outer bottom corner. */
108
+ number?: number;
109
+ side?: Side;
110
+ /** False draws placeholders instead of loading images. */
111
+ showImages?: boolean;
112
+ /** Editor: makes each photo slot clickable. */
113
+ onSlotClick?: (slot: number) => void;
114
+ activeSlot?: number | null;
115
+ }
116
+ /** A photo printed on a page inside its frame. */
117
+ export declare function printedPhoto(photo: FlipbookPhoto | null, frame: FrameStyle, fit?: 'cover' | 'contain', show?: boolean, scale?: number): HTMLDivElement;
118
+ /** The inside of one book page. The parent must have `container-type: size`. */
119
+ export declare function renderPage(page: FlipbookPage, look: PageLook, options?: PageOptions): HTMLDivElement;
120
+ /** The front cover: cloth with the title and an inset photo. */
121
+ export declare function renderCover(book: FlipbookBook, showImages?: boolean): HTMLDivElement;
122
+ export declare function renderBackCover(book: FlipbookBook): HTMLDivElement;
123
+ export declare function renderTitlePage(book: FlipbookBook, look: PageLook, side?: Side): HTMLDivElement;
124
+ export declare function renderColophon(book: FlipbookBook, look: PageLook, side?: Side): HTMLDivElement;
125
+ export declare function renderBlank(look: PageLook, side?: Side): HTMLDivElement;
126
+ /** Any face of a book. Page numbers and the spine curve need `side`. */
127
+ export declare function renderFace(face: Face, book: FlipbookBook, side?: Side, numbered?: boolean): HTMLDivElement;
128
+ /**
129
+ * A soft paper swish made from filtered noise, so no audio file is needed. Browsers only allow
130
+ * audio after a user gesture, which a page turn always is.
131
+ */
132
+ export declare function playPageTurn(volume?: number): void;
133
+ /**
134
+ * Goes full screen and locks the screen to landscape where the browser allows it (Chrome on
135
+ * Android). iOS Safari supports neither for pages, so callers keep the rotate prompt there.
136
+ */
137
+ export declare function enterLandscape(el: HTMLElement): Promise<boolean>;
138
+ /** Media queries that decide whether a phone is held upright. */
139
+ export declare function watchOrientation(onChange: (state: {
140
+ portrait: boolean;
141
+ touch: boolean;
142
+ }) => void): () => void;
143
+ export type { FlipbookOptions, FlipbookPlace, PageLook, PageOptions, Side };
@@ -0,0 +1,143 @@
1
+ import { Face, FlipbookBook, FlipbookLabels, FlipbookPage, FlipbookPhoto, FlipbookReader, FrameStyle, GripOptions, PaperColor, TurnPhysics } from "@toneflix/flipbook-core";
2
+ export * from "@toneflix/flipbook-core";
3
+ interface FlipbookPlace {
4
+ /** How many leaves lie on the left: 0 is the closed front cover. */
5
+ flipped: number;
6
+ label: string;
7
+ faces: Face[];
8
+ }
9
+ interface FlipbookOptions {
10
+ book: FlipbookBook;
11
+ /** Open at this page (1-based) instead of the cover. */
12
+ startPage?: number;
13
+ /** Two pages side by side, one at a time, or whichever fits the space (default). */
14
+ layout?: 'auto' | 'spread' | 'single';
15
+ /** Show the top and bottom bars. */
16
+ controls?: boolean;
17
+ /** Hide the bars after this many ms without movement, or never with false. */
18
+ autoHide?: number | false;
19
+ thumbnails?: boolean;
20
+ soundButton?: boolean;
21
+ /** Play a paper sound on each turn. The sound button remembers the reader's choice. */
22
+ sound?: boolean;
23
+ fullscreenButton?: boolean;
24
+ /** Ask phones held upright to turn sideways, offering single pages instead. */
25
+ landscape?: boolean;
26
+ /** Arrow, page and Home/End keys: while the book has focus (true) or anywhere on the page ('global'). */
27
+ keyboard?: boolean | 'global';
28
+ /** Covers swing on the spine like board instead of curling like paper. */
29
+ stiffCovers?: boolean;
30
+ physics?: Partial<TurnPhysics>;
31
+ grip?: Partial<GripOptions>;
32
+ /** Strength of the light and shadow around a turning page, from 0 to 1 or more. */
33
+ shading?: number;
34
+ /** Backdrop behind the book. Defaults to a glow tinted by the cover. */
35
+ background?: string;
36
+ labels?: Partial<FlipbookLabels>;
37
+ onPageChange?: (place: FlipbookPlace) => void;
38
+ /** A page started to turn over. */
39
+ onFlip?: () => void;
40
+ }
41
+ /**
42
+ * A photo book that opens across two pages, turned by dragging, flicking, tapping, buttons or
43
+ * keys. Mount it into any sized element; call `destroy()` when it goes away.
44
+ */
45
+ export declare class Flipbook {
46
+ readonly container: HTMLElement;
47
+ readonly root: HTMLDivElement;
48
+ readonly reader: FlipbookReader;
49
+ private settings;
50
+ private layout;
51
+ private size;
52
+ private orientation;
53
+ private portraitChoice;
54
+ private soundOn;
55
+ private stripOpen;
56
+ private chromeVisible;
57
+ private hideTimer;
58
+ private lastPlace;
59
+ private rendering;
60
+ private dirty;
61
+ private faces;
62
+ private overlays;
63
+ private cleanups;
64
+ private els;
65
+ constructor(container: HTMLElement, options: FlipbookOptions);
66
+ /** Changes options in place; the reader keeps their page. */
67
+ update(options: Partial<FlipbookOptions>): void;
68
+ next(): void;
69
+ prev(): void;
70
+ /** Opens at a `flipped` value. */
71
+ go(flipped: number): void;
72
+ /** Opens at a page (1-based). */
73
+ goToPage(page: number): void;
74
+ destroy(): void;
75
+ private static resolve;
76
+ private get spread();
77
+ private buildLayout;
78
+ private build;
79
+ private listen;
80
+ private onKey;
81
+ /** Pointer position from the top of the spine. */
82
+ private toBook;
83
+ private poke;
84
+ private toggleSound;
85
+ private toggleFullscreen;
86
+ private clearFaces;
87
+ /** Brings the DOM in line with the reader. Re-entrant calls (from the reader) run once more at the end. */
88
+ private render;
89
+ private renderOnce;
90
+ /** Faces of the leaves around the opening. Each keeps its element while it moves between roles, so pages never reload mid-turn. */
91
+ private renderFaces;
92
+ private renderOverlays;
93
+ private paint;
94
+ private renderChrome;
95
+ /** A strip of every spread (or page) to jump around the book. */
96
+ private renderStrip;
97
+ /** Shown on phones held upright: books are read sideways. */
98
+ private renderRotatePrompt;
99
+ private static stageTint;
100
+ }
101
+ type Side = 'left' | 'right';
102
+ interface PageLook {
103
+ paper: PaperColor;
104
+ frame: FrameStyle;
105
+ }
106
+ interface PageOptions {
107
+ /** Printed in the outer bottom corner. */
108
+ number?: number;
109
+ side?: Side;
110
+ /** False draws placeholders instead of loading images. */
111
+ showImages?: boolean;
112
+ /** Editor: makes each photo slot clickable. */
113
+ onSlotClick?: (slot: number) => void;
114
+ activeSlot?: number | null;
115
+ }
116
+ /** A photo printed on a page inside its frame. */
117
+ export declare function printedPhoto(photo: FlipbookPhoto | null, frame: FrameStyle, fit?: 'cover' | 'contain', show?: boolean, scale?: number): HTMLDivElement;
118
+ /** The inside of one book page. The parent must have `container-type: size`. */
119
+ export declare function renderPage(page: FlipbookPage, look: PageLook, options?: PageOptions): HTMLDivElement;
120
+ /** The front cover: cloth with the title and an inset photo. */
121
+ export declare function renderCover(book: FlipbookBook, showImages?: boolean): HTMLDivElement;
122
+ export declare function renderBackCover(book: FlipbookBook): HTMLDivElement;
123
+ export declare function renderTitlePage(book: FlipbookBook, look: PageLook, side?: Side): HTMLDivElement;
124
+ export declare function renderColophon(book: FlipbookBook, look: PageLook, side?: Side): HTMLDivElement;
125
+ export declare function renderBlank(look: PageLook, side?: Side): HTMLDivElement;
126
+ /** Any face of a book. Page numbers and the spine curve need `side`. */
127
+ export declare function renderFace(face: Face, book: FlipbookBook, side?: Side, numbered?: boolean): HTMLDivElement;
128
+ /**
129
+ * A soft paper swish made from filtered noise, so no audio file is needed. Browsers only allow
130
+ * audio after a user gesture, which a page turn always is.
131
+ */
132
+ export declare function playPageTurn(volume?: number): void;
133
+ /**
134
+ * Goes full screen and locks the screen to landscape where the browser allows it (Chrome on
135
+ * Android). iOS Safari supports neither for pages, so callers keep the rotate prompt there.
136
+ */
137
+ export declare function enterLandscape(el: HTMLElement): Promise<boolean>;
138
+ /** Media queries that decide whether a phone is held upright. */
139
+ export declare function watchOrientation(onChange: (state: {
140
+ portrait: boolean;
141
+ touch: boolean;
142
+ }) => void): () => void;
143
+ export type { FlipbookOptions, FlipbookPlace, PageLook, PageOptions, Side };