postext-folio 0.52.6 → 0.52.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (73) hide show
  1. package/dist/postext/book.d.ts +35 -0
  2. package/dist/postext/book.d.ts.map +1 -0
  3. package/dist/postext/book.js +96 -0
  4. package/dist/postext/book.js.map +1 -0
  5. package/dist/postext/constants.d.ts +36 -0
  6. package/dist/postext/constants.d.ts.map +1 -0
  7. package/dist/postext/constants.js +13 -0
  8. package/dist/postext/constants.js.map +1 -0
  9. package/dist/postext/pageVideos.d.ts +26 -0
  10. package/dist/postext/pageVideos.d.ts.map +1 -0
  11. package/dist/postext/pageVideos.js +276 -0
  12. package/dist/postext/pageVideos.js.map +1 -0
  13. package/dist/postext/painting.d.ts +30 -0
  14. package/dist/postext/painting.d.ts.map +1 -0
  15. package/dist/postext/painting.js +167 -0
  16. package/dist/postext/painting.js.map +1 -0
  17. package/dist/postext/sharp.d.ts +19 -0
  18. package/dist/postext/sharp.d.ts.map +1 -0
  19. package/dist/postext/sharp.js +121 -0
  20. package/dist/postext/sharp.js.map +1 -0
  21. package/dist/postext/state.d.ts +29 -0
  22. package/dist/postext/state.d.ts.map +1 -0
  23. package/dist/postext/state.js +2 -0
  24. package/dist/postext/state.js.map +1 -0
  25. package/dist/postext/sweep.d.ts +24 -0
  26. package/dist/postext/sweep.d.ts.map +1 -0
  27. package/dist/postext/sweep.js +37 -0
  28. package/dist/postext/sweep.js.map +1 -0
  29. package/dist/postext/types.d.ts +77 -0
  30. package/dist/postext/types.d.ts.map +1 -0
  31. package/dist/postext/types.js +2 -0
  32. package/dist/postext/types.js.map +1 -0
  33. package/dist/postext.d.ts +6 -124
  34. package/dist/postext.d.ts.map +1 -1
  35. package/dist/postext.js +87 -732
  36. package/dist/postext.js.map +1 -1
  37. package/dist/viewer/constants.d.ts +30 -0
  38. package/dist/viewer/constants.d.ts.map +1 -0
  39. package/dist/viewer/constants.js +49 -0
  40. package/dist/viewer/constants.js.map +1 -0
  41. package/dist/viewer/input.d.ts +15 -0
  42. package/dist/viewer/input.d.ts.map +1 -0
  43. package/dist/viewer/input.js +142 -0
  44. package/dist/viewer/input.js.map +1 -0
  45. package/dist/viewer/layout.d.ts +24 -0
  46. package/dist/viewer/layout.d.ts.map +1 -0
  47. package/dist/viewer/layout.js +183 -0
  48. package/dist/viewer/layout.js.map +1 -0
  49. package/dist/viewer/lens.d.ts +42 -0
  50. package/dist/viewer/lens.d.ts.map +1 -0
  51. package/dist/viewer/lens.js +166 -0
  52. package/dist/viewer/lens.js.map +1 -0
  53. package/dist/viewer/pointer.d.ts +37 -0
  54. package/dist/viewer/pointer.d.ts.map +1 -0
  55. package/dist/viewer/pointer.js +250 -0
  56. package/dist/viewer/pointer.js.map +1 -0
  57. package/dist/viewer/state.d.ts +70 -0
  58. package/dist/viewer/state.d.ts.map +1 -0
  59. package/dist/viewer/state.js +2 -0
  60. package/dist/viewer/state.js.map +1 -0
  61. package/dist/viewer/turning.d.ts +34 -0
  62. package/dist/viewer/turning.d.ts.map +1 -0
  63. package/dist/viewer/turning.js +156 -0
  64. package/dist/viewer/turning.js.map +1 -0
  65. package/dist/viewer/types.d.ts +241 -0
  66. package/dist/viewer/types.d.ts.map +1 -0
  67. package/dist/viewer/types.js +2 -0
  68. package/dist/viewer/types.js.map +1 -0
  69. package/dist/viewer.d.ts +3 -242
  70. package/dist/viewer.d.ts.map +1 -1
  71. package/dist/viewer.js +104 -976
  72. package/dist/viewer.js.map +1 -1
  73. package/package.json +3 -3
@@ -0,0 +1,167 @@
1
+ // The document book's page paintings: which pages are wanted, painting and
2
+ // freeing them, the sweep of a turn and the idle schedule round the open
3
+ // spread (#1276: split out of postext.ts).
4
+ import { renderPageToCanvas } from 'postext';
5
+ import { trimmedSize } from './book.js';
6
+ import { sweepFor, SWEEP_BUDGET_MS } from './sweep.js';
7
+ import { cancelIdle, onIdle } from './constants.js';
8
+ export function createDocumentPainting(deps) {
9
+ const { options, reach, slotWidth, sources, ds, dlate } = deps;
10
+ /** Pages within `reach` spreads of the ones on show. */
11
+ function wanted() {
12
+ const keep = new Set();
13
+ const span = 2 * reach + 1;
14
+ for (const p of ds.focus)
15
+ for (let i = p - span; i <= p + span; i++)
16
+ if (i >= 0 && i < ds.current.pages.length)
17
+ keep.add(i);
18
+ for (const i of ds.sweep)
19
+ keep.add(i);
20
+ return keep;
21
+ }
22
+ /** Paints page `i` on a fresh canvas (the leaves cache their texture by
23
+ * element) exactly `width` device pixels wide. */
24
+ function paint(i, width) {
25
+ const page = ds.current.pages[i];
26
+ if (!page)
27
+ return;
28
+ const canvas = document.createElement("canvas");
29
+ // The page as bound: trimmed, without the slug and the crop marks.
30
+ renderPageToCanvas(page, ds.current, canvas, {
31
+ trim: true,
32
+ scale: width / trimmedSize(page, ds.current).width,
33
+ singleInk: options.singleInk,
34
+ pageNegative: options.pageNegative,
35
+ ...(options.printPreview ? { printPreview: options.printPreview } : {}),
36
+ });
37
+ const old = ds.canvases[i];
38
+ if (old)
39
+ old.width = old.height = 0;
40
+ ds.canvases[i] = canvas;
41
+ ds.painted.set(i, width);
42
+ // A new painting: decorated afresh, on a canvas of its own (its
43
+ // texture follows the element).
44
+ free(ds.decorated[i]);
45
+ ds.decorated[i] = null;
46
+ decorate(i);
47
+ }
48
+ const free = (canvas) => {
49
+ if (canvas)
50
+ canvas.width = canvas.height = 0;
51
+ };
52
+ /** Draws page `i`'s decorations over its painting. True when the page
53
+ * shows another canvas than before (it was not decorated). */
54
+ function decorate(i) {
55
+ const draw = options.decorate;
56
+ const base = ds.canvases[i];
57
+ const page = ds.current.pages[i];
58
+ if (!draw || !base || !page)
59
+ return false;
60
+ let target = ds.decorated[i];
61
+ const fresh = !target;
62
+ target ??= document.createElement("canvas");
63
+ if (target.width !== base.width || target.height !== base.height) {
64
+ target.width = base.width;
65
+ target.height = base.height;
66
+ }
67
+ const ctx = target.getContext("2d");
68
+ if (!ctx)
69
+ return false;
70
+ ctx.setTransform(1, 0, 0, 1, 0, 0);
71
+ ctx.globalCompositeOperation = "source-over";
72
+ ctx.globalAlpha = 1;
73
+ ctx.drawImage(base, 0, 0);
74
+ // The page's own pixels: the canvas shows the trimmed page at its size.
75
+ const inset = Math.max(0, ds.current.trimOffset);
76
+ const scale = base.width / trimmedSize(page, ds.current).width;
77
+ ctx.setTransform(scale, 0, 0, scale, -inset * scale, -inset * scale);
78
+ ctx.save();
79
+ const drew = draw(i, ctx);
80
+ ctx.restore();
81
+ if (!drew && fresh)
82
+ return false;
83
+ ds.decorated[i] = target;
84
+ return fresh;
85
+ }
86
+ /** Paints what the open spread needs now and lets go of the far pages;
87
+ * the rest of the window fills in when the browser is idle. */
88
+ function refresh(urgent) {
89
+ if (!ds.ready)
90
+ return;
91
+ const width = slotWidth();
92
+ const keep = wanted();
93
+ let changed = false;
94
+ for (const i of urgent) {
95
+ if (i < 0 || i >= ds.current.pages.length || ds.painted.get(i) === width)
96
+ continue;
97
+ paint(i, width);
98
+ changed = true;
99
+ }
100
+ for (const i of [...ds.painted.keys()]) {
101
+ if (keep.has(i))
102
+ continue;
103
+ const canvas = ds.canvases[i];
104
+ if (canvas)
105
+ canvas.width = canvas.height = 0;
106
+ ds.canvases[i] = null;
107
+ free(ds.decorated[i]);
108
+ ds.decorated[i] = null;
109
+ ds.painted.delete(i);
110
+ changed = true;
111
+ }
112
+ if (changed)
113
+ dlate.viewer.setPages(sources());
114
+ schedule();
115
+ }
116
+ /** A turn across several spreads: every page its leaves carry is
117
+ * painted, a frame at a time, in the order the leaves lift, so no page
118
+ * goes over blank. */
119
+ function startSweep(target) {
120
+ const next = sweepFor(ds.run, ds.settled, target, ds.current.pages.length);
121
+ ds.run = next.run;
122
+ ds.sweep = next.pages;
123
+ cancelAnimationFrame(ds.sweepFrame);
124
+ ds.sweepFrame = requestAnimationFrame(paintSweep);
125
+ }
126
+ function paintSweep() {
127
+ ds.sweepFrame = 0;
128
+ const width = slotWidth();
129
+ const start = performance.now();
130
+ let changed = false;
131
+ for (const i of ds.sweep) {
132
+ if (ds.painted.get(i) === width)
133
+ continue;
134
+ paint(i, width);
135
+ changed = true;
136
+ if (performance.now() - start > SWEEP_BUDGET_MS)
137
+ break;
138
+ }
139
+ if (!changed)
140
+ return;
141
+ dlate.viewer.setPages(sources());
142
+ ds.sweepFrame = requestAnimationFrame(paintSweep);
143
+ }
144
+ function schedule() {
145
+ cancelIdle(ds.idle);
146
+ ds.idle = onIdle(() => {
147
+ const width = slotWidth();
148
+ const distance = (i) => Math.min(...ds.focus.map((f) => Math.abs(i - f)));
149
+ const next = [...wanted()].filter((i) => ds.painted.get(i) !== width).sort((a, b) => distance(a) - distance(b)).slice(0, 4);
150
+ if (!next.length)
151
+ return;
152
+ for (const i of next)
153
+ paint(i, width);
154
+ dlate.viewer.setPages(sources());
155
+ schedule();
156
+ });
157
+ }
158
+ const around = (state) => {
159
+ const pages = state.pages.length ? state.pages : [0];
160
+ // The leaf a hand would lift next shows the neighbours' pages.
161
+ return [...pages, pages[0] - 2, pages[0] - 1, pages[pages.length - 1] + 1, pages[pages.length - 1] + 2];
162
+ };
163
+ return {
164
+ wanted, paint, free, decorate, refresh, startSweep, around
165
+ };
166
+ }
167
+ //# sourceMappingURL=painting.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"painting.js","sourceRoot":"","sources":["../../src/postext/painting.ts"],"names":[],"mappings":"AAAA,2EAA2E;AAC3E,yEAAyE;AACzE,2CAA2C;AAC3C,OAAO,EAAE,kBAAkB,EAAyB,MAAM,SAAS,CAAC;AACpE,OAAO,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AACxC,OAAO,EAAE,QAAQ,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AACvD,OAAO,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAepD,MAAM,UAAU,sBAAsB,CAAC,IAA0B;IAC/D,MAAM,EACJ,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,OAAO,EAAE,EAAE,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AG,CAAC,EAAE,KAAK,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;IAC1G,CAAC,CAAC;IACF,OAAO;QACL,MAAM,EAAE,KAAK,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM;KAC3D,CAAC;AACJ,CAAC"}
@@ -0,0 +1,19 @@
1
+ import { type Sharp } from './constants.js';
2
+ import type { PageSource } from '../pageFlip.js';
3
+ import type { FolioDocumentOptions } from './types.js';
4
+ import type { FolioDocumentState, FolioDocumentLate } from './state.js';
5
+ /** What createDocumentSharp takes from createFolioFromDocument. */
6
+ export interface DocumentSharpDeps {
7
+ options: FolioDocumentOptions;
8
+ free: (canvas: HTMLCanvasElement | null | undefined) => void;
9
+ ds: FolioDocumentState;
10
+ dlate: FolioDocumentLate;
11
+ }
12
+ export declare function createDocumentSharp(deps: DocumentSharpDeps): {
13
+ sharp: Map<number, Sharp>;
14
+ sharpDirty: Set<number>;
15
+ redecorateSharp: () => void;
16
+ paintSharp: (i: number, width: number) => Promise<PageSource>;
17
+ releaseSharp: () => void;
18
+ };
19
+ //# sourceMappingURL=sharp.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sharp.d.ts","sourceRoot":"","sources":["../../src/postext/sharp.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,KAAK,EAAoB,MAAM,gBAAgB,CAAC;AAE9D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAEjD,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC;AACvD,OAAO,KAAK,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAExE,mEAAmE;AACnE,MAAM,WAAW,iBAAiB;IAChC,OAAO,EAAE,oBAAoB,CAAC;IAC9B,IAAI,EAAE,CAAC,MAAM,EAAE,iBAAiB,GAAG,IAAI,GAAG,SAAS,KAAK,IAAI,CAAC;IAC7D,EAAE,EAAE,kBAAkB,CAAC;IACvB,KAAK,EAAE,iBAAiB,CAAC;CAC1B;AAED,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,iBAAiB;;;;oBAkElC,MAAM,SAAS,MAAM,KAAG,OAAO,CAAC,UAAU,CAAC;;EA+CnE"}
@@ -0,0 +1,121 @@
1
+ // Sharper paintings of the document book's pages for the magnifying glass
2
+ // (#527) (#1276: split out of postext.ts).
3
+ import { SHARP_MAX_PIXELS } from './constants.js';
4
+ import { trimmedSize } from './book.js';
5
+ import { renderPageToCanvas } from 'postext';
6
+ export function createDocumentSharp(deps) {
7
+ const { options, free, ds, dlate } = deps;
8
+ // ── Sharper paintings for the magnifying glass (#527) ──
9
+ /** Page → its painting for the glass (with its decorations), the page
10
+ * as painted without them while it has some (to draw them again from,
11
+ * #543), the width it was painted at and the layout it was painted
12
+ * from. */
13
+ const sharp = new Map();
14
+ let sharpChain = Promise.resolve();
15
+ /** Pages whose sharp paintings wait to be decorated again (once a
16
+ * frame: a drag selects on every move). */
17
+ const sharpDirty = new Set();
18
+ ds.sharpFrame = 0;
19
+ /** Draws page `i`'s decorations over its painting for the glass, from
20
+ * the bare painting (kept while the page has decorations). True when
21
+ * it drew some. */
22
+ function decorateSharp(i, entry) {
23
+ const draw = options.decorate;
24
+ const page = entry.doc.pages[i];
25
+ const ctx = entry.canvas.getContext("2d");
26
+ if (!draw || !page || !ctx)
27
+ return false;
28
+ if (entry.bare) {
29
+ ctx.setTransform(1, 0, 0, 1, 0, 0);
30
+ ctx.globalCompositeOperation = "source-over";
31
+ ctx.globalAlpha = 1;
32
+ ctx.drawImage(entry.bare, 0, 0);
33
+ }
34
+ else {
35
+ const bare = document.createElement("canvas");
36
+ bare.width = entry.canvas.width;
37
+ bare.height = entry.canvas.height;
38
+ bare.getContext("2d")?.drawImage(entry.canvas, 0, 0);
39
+ entry.bare = bare;
40
+ }
41
+ const inset = Math.max(0, entry.doc.trimOffset);
42
+ const scale = entry.canvas.width / trimmedSize(page, entry.doc).width;
43
+ ctx.setTransform(scale, 0, 0, scale, -inset * scale, -inset * scale);
44
+ ctx.save();
45
+ const drew = draw(i, ctx);
46
+ ctx.restore();
47
+ ctx.setTransform(1, 0, 0, 1, 0, 0);
48
+ // No decorations: the painting is bare again.
49
+ if (!drew) {
50
+ free(entry.bare);
51
+ entry.bare = null;
52
+ }
53
+ return drew;
54
+ }
55
+ /** The glass's paintings of these pages decorated again (the selection
56
+ * moved), and shown again. */
57
+ function redecorateSharp() {
58
+ ds.sharpFrame = 0;
59
+ for (const i of sharpDirty) {
60
+ const entry = sharp.get(i);
61
+ if (!entry || entry.doc !== ds.current)
62
+ continue;
63
+ decorateSharp(i, entry);
64
+ dlate.viewer.refreshPage(entry.canvas);
65
+ }
66
+ sharpDirty.clear();
67
+ }
68
+ /** Page `i` painted `width` px wide for the glass, within 1.5 times the
69
+ * page's own resolution and 24 megapixels; one page at a time, each in
70
+ * a task of its own (a newspaper page takes a while to paint). */
71
+ function paintSharp(i, width) {
72
+ const done = sharpChain.then(() => new Promise((resolve) => {
73
+ setTimeout(() => {
74
+ const page = ds.current.pages[i];
75
+ if (!page)
76
+ return resolve(null);
77
+ const size = trimmedSize(page, ds.current);
78
+ const w = Math.max(1, Math.min(width, Math.round(size.width * 1.5), Math.floor(Math.sqrt((SHARP_MAX_PIXELS * size.width) / size.height))));
79
+ const had = sharp.get(i);
80
+ if (had && had.doc === ds.current && had.width >= w)
81
+ return resolve(had.canvas);
82
+ const canvas = document.createElement("canvas");
83
+ const scale = w / size.width;
84
+ renderPageToCanvas(page, ds.current, canvas, { trim: true, scale, singleInk: options.singleInk, pageNegative: options.pageNegative, ...(options.printPreview ? { printPreview: options.printPreview } : {}) });
85
+ const entry = { canvas, bare: null, width: w, doc: ds.current };
86
+ // The decorations too (a selection), over the page as painted.
87
+ decorateSharp(i, entry);
88
+ if (had)
89
+ freeSharp(had);
90
+ sharp.delete(i);
91
+ sharp.set(i, entry);
92
+ // A few pages kept: the spread on show and the one before.
93
+ for (const [k, v] of sharp) {
94
+ if (sharp.size <= 4)
95
+ break;
96
+ freeSharp(v);
97
+ sharp.delete(k);
98
+ }
99
+ resolve(canvas);
100
+ }, 0);
101
+ }));
102
+ sharpChain = done.catch(() => undefined);
103
+ return done;
104
+ }
105
+ function freeSharp(entry) {
106
+ free(entry.canvas);
107
+ free(entry.bare);
108
+ }
109
+ function releaseSharp() {
110
+ for (const v of sharp.values())
111
+ freeSharp(v);
112
+ sharp.clear();
113
+ sharpDirty.clear();
114
+ cancelAnimationFrame(ds.sharpFrame);
115
+ ds.sharpFrame = 0;
116
+ }
117
+ return {
118
+ sharp, sharpDirty, redecorateSharp, paintSharp, releaseSharp
119
+ };
120
+ }
121
+ //# sourceMappingURL=sharp.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sharp.js","sourceRoot":"","sources":["../../src/postext/sharp.ts"],"names":[],"mappings":"AAAA,0EAA0E;AAC1E,2CAA2C;AAC3C,OAAO,EAAc,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAC9D,OAAO,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AAExC,OAAO,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAY7C,MAAM,UAAU,mBAAmB,CAAC,IAAuB;IACzD,MAAM,EACJ,OAAO,EAAE,IAAI,EAAE,EAAE,EAAE,KAAK,EACzB,GAAG,IAAI,CAAC;IACT,0DAA0D;IAC1D;;;gBAGY;IACZ,MAAM,KAAK,GAAG,IAAI,GAAG,EAAiB,CAAC;IACvC,IAAI,UAAU,GAAqB,OAAO,CAAC,OAAO,EAAE,CAAC;IACrD;gDAC4C;IAC5C,MAAM,UAAU,GAAG,IAAI,GAAG,EAAU,CAAC;IACrC,EAAE,CAAC,UAAU,GAAG,CAAC,CAAC;IAElB;;wBAEoB;IACpB,SAAS,aAAa,CAAC,CAAS,EAAE,KAAY;QAC5C,MAAM,IAAI,GAAG,OAAO,CAAC,QAAQ,CAAC;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,EAAE,UAAU,EAAE,YAAY;KAC7D,CAAC;AACJ,CAAC"}
@@ -0,0 +1,29 @@
1
+ import type { VDTDocument } from 'postext';
2
+ import type { SweepRun } from './sweep.js';
3
+ import type { PagePlayer } from './constants.js';
4
+ import type { FolioViewer } from '../viewer/types.js';
5
+ /** The bindings the document book reassigns and more than one of its modules
6
+ * reads or writes: fields of one object. */
7
+ export interface FolioDocumentState {
8
+ current: VDTDocument;
9
+ canvases: (HTMLCanvasElement | null)[];
10
+ decorated: (HTMLCanvasElement | null)[];
11
+ painted: Map<number, number>;
12
+ focus: number[];
13
+ idle: number;
14
+ settled: number[];
15
+ sweep: number[];
16
+ sweepFrame: number;
17
+ run: SweepRun | null;
18
+ turning: boolean;
19
+ ready: boolean;
20
+ players: PagePlayer[];
21
+ autoTimer: number;
22
+ sharpFrame: number;
23
+ }
24
+ /** What a module of the document book calls before the book has made it:
25
+ * filled as soon as each one exists. */
26
+ export interface FolioDocumentLate {
27
+ viewer: FolioViewer;
28
+ }
29
+ //# sourceMappingURL=state.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"state.d.ts","sourceRoot":"","sources":["../../src/postext/state.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAC3C,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAC3C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AACjD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAEtD;6CAC6C;AAC7C,MAAM,WAAW,kBAAkB;IACjC,OAAO,EAAE,WAAW,CAAC;IACrB,QAAQ,EAAE,CAAC,iBAAiB,GAAG,IAAI,CAAC,EAAE,CAAC;IACvC,SAAS,EAAE,CAAC,iBAAiB,GAAG,IAAI,CAAC,EAAE,CAAC;IACxC,OAAO,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC7B,KAAK,EAAE,MAAM,EAAE,CAAC;IAChB,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,KAAK,EAAE,MAAM,EAAE,CAAC;IAChB,UAAU,EAAE,MAAM,CAAC;IACnB,GAAG,EAAE,QAAQ,GAAG,IAAI,CAAC;IACrB,OAAO,EAAE,OAAO,CAAC;IACjB,KAAK,EAAE,OAAO,CAAC;IACf,OAAO,EAAE,UAAU,EAAE,CAAC;IACtB,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,MAAM,CAAC;CACpB;AAED;yCACyC;AACzC,MAAM,WAAW,iBAAiB;IAChC,MAAM,EAAE,WAAW,CAAC;CACrB"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=state.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"state.js","sourceRoot":"","sources":["../../src/postext/state.ts"],"names":[],"mappings":""}
@@ -0,0 +1,24 @@
1
+ /** A run of turns, from the spread at rest to the book's next rest: where
2
+ * its leaves started and, when it opened with a block jump, the spread
3
+ * that block lands on. */
4
+ export interface SweepRun {
5
+ from: number[];
6
+ block: number[] | null;
7
+ }
8
+ /**
9
+ * The pages a turn to `target` sweeps past, in the order its leaves lift,
10
+ * and the run it belongs to. A turn set at rest (`run` null) more than
11
+ * `BLOCK_PAGES` away goes over as one block, as the renderer turns it: it
12
+ * keeps only the pages on show (the block's top face), the target's being
13
+ * painted with it. A target set while leaves are in the air carries the
14
+ * run on leaf by leaf (the renderer lifts a block only with no leaf in
15
+ * the air), so every page from where the run started (or its block
16
+ * lands) to the target is swept, a run of fast clicks included.
17
+ */
18
+ export declare function sweepFor(run: SweepRun | null, settled: number[], target: number[], count: number): {
19
+ run: SweepRun;
20
+ pages: number[];
21
+ };
22
+ /** Painting time per frame while leaves are in the air. */
23
+ export declare const SWEEP_BUDGET_MS = 8;
24
+ //# sourceMappingURL=sweep.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sweep.d.ts","sourceRoot":"","sources":["../../src/postext/sweep.ts"],"names":[],"mappings":"AAOA;;2BAE2B;AAC3B,MAAM,WAAW,QAAQ;IACvB,IAAI,EAAE,MAAM,EAAE,CAAC;IACf,KAAK,EAAE,MAAM,EAAE,GAAG,IAAI,CAAC;CACxB;AAED;;;;;;;;;GASG;AACH,wBAAgB,QAAQ,CAAC,GAAG,EAAE,QAAQ,GAAG,IAAI,EAAE,OAAO,EAAE,MAAM,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,EAAE,KAAK,EAAE,MAAM,GAAG;IAAE,GAAG,EAAE,QAAQ,CAAC;IAAC,KAAK,EAAE,MAAM,EAAE,CAAA;CAAE,CAerI;AACD,2DAA2D;AAC3D,eAAO,MAAM,eAAe,IAAI,CAAC"}
@@ -0,0 +1,37 @@
1
+ // The pages a turn sweeps past, and the painting budget while leaves are in
2
+ // the air (#1276: split out of postext.ts).
3
+ import { BLOCK_PAGES } from '../pageFlip.js';
4
+ /** Pages a turn paints for its leaves, at most. */
5
+ const MAX_SWEEP = 160;
6
+ /**
7
+ * The pages a turn to `target` sweeps past, in the order its leaves lift,
8
+ * and the run it belongs to. A turn set at rest (`run` null) more than
9
+ * `BLOCK_PAGES` away goes over as one block, as the renderer turns it: it
10
+ * keeps only the pages on show (the block's top face), the target's being
11
+ * painted with it. A target set while leaves are in the air carries the
12
+ * run on leaf by leaf (the renderer lifts a block only with no leaf in
13
+ * the air), so every page from where the run started (or its block
14
+ * lands) to the target is swept, a run of fast clicks included.
15
+ */
16
+ export function sweepFor(run, settled, target, count) {
17
+ if (!run) {
18
+ const from = settled.length ? settled : [0];
19
+ if (Math.abs((target[0] ?? 0) - (from[0] ?? 0)) > BLOCK_PAGES)
20
+ return { run: { from, block: target }, pages: [...from] };
21
+ run = { from, block: null };
22
+ }
23
+ const from = run.block ?? run.from;
24
+ const lo = Math.max(0, Math.min(...from, ...target) - 1);
25
+ const hi = Math.min(count - 1, Math.max(...from, ...target) + 1);
26
+ const pages = [];
27
+ for (let i = lo; i <= hi; i++)
28
+ pages.push(i);
29
+ if ((target[0] ?? 0) < (from[0] ?? 0))
30
+ pages.reverse();
31
+ // The block's top face stays until it lands.
32
+ const swept = run.block ? [...run.from, ...pages] : pages;
33
+ return { run, pages: swept.slice(0, MAX_SWEEP) };
34
+ }
35
+ /** Painting time per frame while leaves are in the air. */
36
+ export const SWEEP_BUDGET_MS = 8;
37
+ //# sourceMappingURL=sweep.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sweep.js","sourceRoot":"","sources":["../../src/postext/sweep.ts"],"names":[],"mappings":"AAAA,4EAA4E;AAC5E,4CAA4C;AAC5C,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAE7C,mDAAmD;AACnD,MAAM,SAAS,GAAG,GAAG,CAAC;AAUtB;;;;;;;;;GASG;AACH,MAAM,UAAU,QAAQ,CAAC,GAAoB,EAAE,OAAiB,EAAE,MAAgB,EAAE,KAAa;IAC/F,IAAI,CAAC,GAAG,EAAE,CAAC;QACT,MAAM,IAAI,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;QAC5C,IAAI,IAAI,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,WAAW;YAAE,OAAO,EAAE,GAAG,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,EAAE,EAAE,KAAK,EAAE,CAAC,GAAG,IAAI,CAAC,EAAE,CAAC;QACzH,GAAG,GAAG,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;IAC9B,CAAC;IACD,MAAM,IAAI,GAAG,GAAG,CAAC,KAAK,IAAI,GAAG,CAAC,IAAI,CAAC;IACnC,MAAM,EAAE,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,GAAG,CAAC,GAAG,IAAI,EAAE,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC;IACzD,MAAM,EAAE,GAAG,IAAI,CAAC,GAAG,CAAC,KAAK,GAAG,CAAC,EAAE,IAAI,CAAC,GAAG,CAAC,GAAG,IAAI,EAAE,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC;IACjE,MAAM,KAAK,GAAa,EAAE,CAAC;IAC3B,KAAK,IAAI,CAAC,GAAG,EAAE,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,EAAE;QAAE,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAC7C,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;QAAE,KAAK,CAAC,OAAO,EAAE,CAAC;IACvD,6CAA6C;IAC7C,MAAM,KAAK,GAAG,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,GAAG,GAAG,CAAC,IAAI,EAAE,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC;IAC1D,OAAO,EAAE,GAAG,EAAE,KAAK,EAAE,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,SAAS,CAAC,EAAE,CAAC;AACnD,CAAC;AACD,2DAA2D;AAC3D,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,CAAC"}
@@ -0,0 +1,77 @@
1
+ import type { PrintPreview, VDTDocument } from 'postext';
2
+ import type { FolioOptions, FolioViewer, FolioAppearance, FolioPagePoint } from '../viewer.js';
3
+ export interface FolioDocumentOptions extends Omit<FolioOptions, "pages" | "firstPageRecto" | "binding" | "at" | "aspect"> {
4
+ /** The page to open on (0-based). Default 0. */
5
+ at?: number;
6
+ /** Spreads painted on either side of the open one; pages farther away
7
+ * are let go (drawn as blank paper should a long turn sweep past them).
8
+ * Default 3. */
9
+ window?: number;
10
+ /** Passed to `renderPageToCanvas` (see its `RenderPageOptions`). */
11
+ singleInk?: boolean;
12
+ pageNegative?: boolean;
13
+ /** The print preview (soft proof) of the pages (`createPrintPreview`).
14
+ * With `paper: true` the proof brings the paper's white: give the book
15
+ * a neutral paper shade meanwhile, or it tints that paper again. */
16
+ printPreview?: PrintPreview;
17
+ /** A page's text alternative. Default `Page n`. */
18
+ alt?: (index: number) => string;
19
+ /**
20
+ * Draws over a painted page (a selection, a caret): `ctx` is set to the
21
+ * page's own pixels (the untrimmed sheet, as the document's coordinates
22
+ * are), over the page as painted. Returns whether it drew anything. Run
23
+ * when a page is painted and on `redecorate`.
24
+ */
25
+ decorate?: (index: number, ctx: CanvasRenderingContext2D) => boolean;
26
+ /**
27
+ * Videos printed on the pages play there (#477): a click on a video's
28
+ * poster plays it on the page (in every pointer mode), a click on it
29
+ * again pauses it, and it goes on playing while its leaf turns. Several
30
+ * may play at once (#507, up to eight drawn): starting a video stops the
31
+ * other exclusive ones (`player.exclusive`, the default) and holds those
32
+ * playing alongside (`exclusive: false`) until it pauses or ends; one
33
+ * playing alongside pauses only the exclusive ones. A video with
34
+ * `player.autoplay` starts by itself, muted: an exclusive one the first
35
+ * time its spread is shown (with its sound once the reader has
36
+ * interacted with the page), one playing alongside each time its page
37
+ * comes into view, unless the reader asks for less motion
38
+ * (`prefers-reduced-motion`). A video stops when the book comes to rest
39
+ * on a spread that does not show it. Self-hosted videos only (a file, or its
40
+ * address: MP4, WebM or an HLS stream); a YouTube or Vimeo poster turns
41
+ * the page as any other. The video's server must allow cross-origin
42
+ * reads (CORS) for WebGL to draw it. Default true.
43
+ */
44
+ videos?: boolean;
45
+ /** The address a self-hosted video's file plays from (an object URL for
46
+ * its `fileId`); without one, its production address (`video.url`). */
47
+ videoUrl?: (fileId: string) => string | undefined;
48
+ /** Told when a video on a page starts playing, pauses, stops or cannot
49
+ * play (`error`: no address, a refused cross-origin read, no HLS). */
50
+ onVideo?: (event: {
51
+ resourceId: string;
52
+ page: number;
53
+ state: "playing" | "paused" | "stopped" | "error";
54
+ }) => void;
55
+ }
56
+ export interface FolioDocumentViewer extends FolioViewer {
57
+ /** Shows another layout of the book (after an edit), on the same page
58
+ * unless `at` says otherwise. A page that reads the same as before
59
+ * keeps its painting; `repaint` paints every page again (an image that
60
+ * came in after the pages were painted). `appearance` is laid over the
61
+ * host's own, as `setAppearance` does, for the new document (a chapter
62
+ * saying how many pages of the book lie round it). */
63
+ setDocument(doc: VDTDocument, options?: {
64
+ at?: number;
65
+ repaint?: boolean;
66
+ appearance?: FolioAppearance;
67
+ }): void;
68
+ /** Draws the decorations (`decorate`) again on these pages, or on every
69
+ * painted page; the book shows them at once, on a turning leaf too. */
70
+ redecorate(pages?: Iterable<number>): void;
71
+ /** Plays or pauses the video printed at a point of a page, as a click
72
+ * there does; false when no playable video lies there. */
73
+ toggleVideoAt(point: FolioPagePoint): boolean;
74
+ /** Stops the videos playing on the pages (their posters show again). */
75
+ stopVideo(): void;
76
+ }
77
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/postext/types.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AACzD,OAAO,KAAK,EAAE,YAAY,EAAE,WAAW,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAE/F,MAAM,WAAW,oBAAqB,SAAQ,IAAI,CAAC,YAAY,EAAE,OAAO,GAAG,gBAAgB,GAAG,SAAS,GAAG,IAAI,GAAG,QAAQ,CAAC;IACxH,gDAAgD;IAChD,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ;;qBAEiB;IACjB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,oEAAoE;IACpE,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB;;yEAEqE;IACrE,YAAY,CAAC,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