@zinejs/core 0.4.1 → 0.6.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/README.md +11 -0
- package/dist/controls/arrows.d.ts +17 -0
- package/dist/controls/builtins.d.ts +8 -0
- package/dist/controls/controls.d.ts +14 -0
- package/dist/controls/icons.d.ts +51 -0
- package/dist/controls/outline.d.ts +14 -0
- package/dist/controls/qr.d.ts +16 -0
- package/dist/controls/registry.d.ts +21 -0
- package/dist/controls/search.d.ts +13 -0
- package/dist/controls/share.d.ts +13 -0
- package/dist/controls/sidebar.d.ts +24 -0
- package/dist/controls/socials.d.ts +16 -0
- package/dist/controls/styles.d.ts +3 -0
- package/dist/controls/thumbnails.d.ts +17 -0
- package/dist/controls/toolbar.d.ts +45 -0
- package/dist/controls/types.d.ts +81 -0
- package/dist/controls-BrPo8pKL.js +649 -0
- package/dist/controls-BrPo8pKL.js.map +1 -0
- package/dist/engine/deeplink.d.ts +18 -0
- package/dist/engine/emitter.d.ts +6 -0
- package/dist/engine/zoomTile.d.ts +65 -0
- package/dist/icons-D87p7JMP.js +29 -0
- package/dist/icons-D87p7JMP.js.map +1 -0
- package/dist/index.d.ts +4 -2
- package/dist/index.js +765 -348
- package/dist/index.js.map +1 -1
- package/dist/index.umd.js +447 -5
- package/dist/index.umd.js.map +1 -1
- package/dist/registry-5nuYFMd4.js +36 -0
- package/dist/registry-5nuYFMd4.js.map +1 -0
- package/dist/share-CyrZiFqf.js +283 -0
- package/dist/share-CyrZiFqf.js.map +1 -0
- package/dist/source/types.d.ts +61 -2
- package/dist/zine.d.ts +161 -3
- package/options.schema.json +53 -0
- package/package.json +13 -1
|
@@ -0,0 +1,649 @@
|
|
|
1
|
+
import { i as e, n as t, t as n } from "./registry-5nuYFMd4.js";
|
|
2
|
+
import { n as r, t as i } from "./icons-D87p7JMP.js";
|
|
3
|
+
//#region src/controls/builtins.ts
|
|
4
|
+
var a = Math.SQRT2, o = (e) => e.zine.container.ownerDocument?.fullscreenElement === e.zine.container;
|
|
5
|
+
function s() {
|
|
6
|
+
t({
|
|
7
|
+
id: "prev",
|
|
8
|
+
title: "Previous page",
|
|
9
|
+
icon: i.prev,
|
|
10
|
+
isDisabled: (e) => !e.zine.canFlipPrev(),
|
|
11
|
+
action: (e) => e.zine.flipPrev()
|
|
12
|
+
}), t({
|
|
13
|
+
id: "next",
|
|
14
|
+
title: "Next page",
|
|
15
|
+
icon: i.next,
|
|
16
|
+
isDisabled: (e) => !e.zine.canFlipNext(),
|
|
17
|
+
action: (e) => e.zine.flipNext()
|
|
18
|
+
});
|
|
19
|
+
let e = (e) => e.zine.getDirection() === "rtl";
|
|
20
|
+
t({
|
|
21
|
+
id: "first",
|
|
22
|
+
title: "First page",
|
|
23
|
+
icon: (t) => e(t) ? i.last : i.first,
|
|
24
|
+
isDisabled: (e) => !e.zine.canFlipPrev(),
|
|
25
|
+
action: (e) => {
|
|
26
|
+
e.zine.flipTo(0), e.close();
|
|
27
|
+
}
|
|
28
|
+
}), t({
|
|
29
|
+
id: "last",
|
|
30
|
+
title: "Last page",
|
|
31
|
+
icon: (t) => e(t) ? i.first : i.last,
|
|
32
|
+
isDisabled: (e) => !e.zine.canFlipNext(),
|
|
33
|
+
action: (e) => {
|
|
34
|
+
e.zine.flipTo(e.zine.getPageCount() - 1), e.close();
|
|
35
|
+
}
|
|
36
|
+
}), t({
|
|
37
|
+
id: "zoomIn",
|
|
38
|
+
title: "Zoom in",
|
|
39
|
+
icon: i.zoomIn,
|
|
40
|
+
isDisabled: (e) => e.zine.getZoom() >= e.zine.getMaxZoom() - 1e-6,
|
|
41
|
+
action: (e) => e.zine.setZoom(e.zine.getZoom() * a)
|
|
42
|
+
}), t({
|
|
43
|
+
id: "zoomOut",
|
|
44
|
+
title: "Zoom out",
|
|
45
|
+
icon: i.zoomOut,
|
|
46
|
+
isDisabled: (e) => e.zine.getZoom() <= 1.000001,
|
|
47
|
+
action: (e) => e.zine.setZoom(e.zine.getZoom() / a)
|
|
48
|
+
}), t({
|
|
49
|
+
id: "fullscreen",
|
|
50
|
+
title: "Fullscreen",
|
|
51
|
+
icon: i.fullscreen,
|
|
52
|
+
isVisible: (e) => typeof e.zine.container.requestFullscreen == "function",
|
|
53
|
+
isActive: o,
|
|
54
|
+
action: (e) => {
|
|
55
|
+
let t = e.zine.container.ownerDocument;
|
|
56
|
+
o(e) ? t?.exitFullscreen?.() : e.zine.container.requestFullscreen?.(), e.close();
|
|
57
|
+
}
|
|
58
|
+
}), t({
|
|
59
|
+
id: "share",
|
|
60
|
+
title: "Share",
|
|
61
|
+
icon: i.share,
|
|
62
|
+
action: (e) => {
|
|
63
|
+
e.close(), import("./share-CyrZiFqf.js").then(({ ShareDialog: t }) => new t(e.zine, e.zine.container)).catch(() => {
|
|
64
|
+
navigator.clipboard?.writeText(e.zine.pageLink()).catch(() => {});
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
}), t({
|
|
68
|
+
id: "download",
|
|
69
|
+
title: "Download PDF",
|
|
70
|
+
icon: i.download,
|
|
71
|
+
isVisible: (e) => e.zine.canDownload(),
|
|
72
|
+
action: (e) => {
|
|
73
|
+
e.zine.download(), e.close();
|
|
74
|
+
}
|
|
75
|
+
}), t({
|
|
76
|
+
id: "spread",
|
|
77
|
+
title: (e) => e.zine.isSinglePage() ? "Show two pages" : "Show one page",
|
|
78
|
+
icon: (e) => e.zine.isSinglePage() ? i.twoPages : i.onePage,
|
|
79
|
+
isVisible: (e) => !e.zine.isResponsiveSingle(),
|
|
80
|
+
action: (e) => {
|
|
81
|
+
e.zine.toggleSpreadMode(), e.close();
|
|
82
|
+
}
|
|
83
|
+
}), t({
|
|
84
|
+
id: "print",
|
|
85
|
+
title: "Print",
|
|
86
|
+
icon: i.print,
|
|
87
|
+
isVisible: (e) => e.zine.canPrint(),
|
|
88
|
+
action: (e) => {
|
|
89
|
+
e.zine.print(), e.close();
|
|
90
|
+
}
|
|
91
|
+
}), t({
|
|
92
|
+
id: "menu",
|
|
93
|
+
title: "More",
|
|
94
|
+
icon: i.menu,
|
|
95
|
+
children: [
|
|
96
|
+
"first",
|
|
97
|
+
"last",
|
|
98
|
+
"spread",
|
|
99
|
+
"thumbnails",
|
|
100
|
+
"outline",
|
|
101
|
+
"print",
|
|
102
|
+
"download"
|
|
103
|
+
]
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
//#endregion
|
|
107
|
+
//#region src/controls/styles.ts
|
|
108
|
+
var c = "zine-controls-style", l = "\n/* Docked mode wraps the book so the bar can sit beside it without shrinking the container,\n whose measured box the renderer and hit-testing both depend on.\n The wrapper deliberately does not stretch or grow its children: the container keeps whatever\n width, aspect-ratio and auto-margins the consumer's own CSS gave it. */\n.zine-controls-wrap { display: flex; }\n/* Stacked: children keep their own width (so a percentage or auto-margin still resolves against\n the wrapper) and take only the height they ask for. */\n.zine-controls-wrap-top,\n.zine-controls-wrap-bottom { flex-direction: column; align-items: stretch; }\n/* Side by side: the bar is only as wide as its buttons, and both are vertically centred. */\n.zine-controls-wrap-left,\n.zine-controls-wrap-right { flex-direction: row; align-items: center; }\n/* min-height:0 matters as much as min-width here. A flex item's automatic minimum size floors it\n at its content, so once the canvas has grown for a taller layout the book cannot shrink back —\n its aspect-ratio is restored but ignored, leaving the extra height behind. */\n.zine-controls-wrap > * { flex: 0 0 auto; min-width: 0; min-height: 0; }\n\n.zine-controls {\n position: relative;\n display: flex;\n gap: 4px;\n padding: 5px;\n z-index: 2;\n box-sizing: border-box;\n font: 500 12px/1.2 system-ui, sans-serif;\n color: var(--zine-controls-fg, #f4f4f5);\n touch-action: auto;\n -webkit-user-select: none;\n user-select: none;\n}\n.zine-controls-docked { flex: 0 0 auto; justify-content: center; align-items: center; }\n.zine-controls-floating {\n position: absolute;\n /* Transparent to the book except on the buttons themselves, so gaps stay draggable. */\n pointer-events: none;\n}\n.zine-controls-bar {\n display: flex;\n align-items: center;\n gap: 1px;\n padding: 3px;\n border-radius: 8px;\n pointer-events: auto;\n background: var(--zine-controls-bg, rgba(24, 24, 27, 0.82));\n backdrop-filter: blur(8px);\n}\n/* Floating: lifted off the page it covers. Docked: flat, with an outline so it reads as a\n control strip rather than a shadow hanging in empty space. */\n.zine-controls-floating .zine-controls-bar { box-shadow: 0 2px 12px rgba(0, 0, 0, 0.28); }\n.zine-controls-docked .zine-controls-bar {\n border: 1px solid var(--zine-controls-hover, rgba(255, 255, 255, 0.14));\n}\n.zine-controls-floating.zine-controls-bottom { inset: auto 0 0 0; justify-content: center; }\n.zine-controls-floating.zine-controls-top { inset: 0 0 auto 0; justify-content: center; }\n.zine-controls-floating.zine-controls-left { inset: 0 auto 0 0; align-items: center; }\n.zine-controls-floating.zine-controls-right { inset: 0 0 0 auto; align-items: center; }\n/* A bar on a vertical edge stacks its buttons, docked or floating. */\n.zine-controls-left .zine-controls-bar,\n.zine-controls-right .zine-controls-bar { flex-direction: column; }\n\n.zine-controls-btn {\n display: inline-flex;\n align-items: center;\n justify-content: center;\n width: 26px;\n height: 26px;\n padding: 0;\n border: 0;\n border-radius: 6px;\n background: transparent;\n color: inherit;\n cursor: pointer;\n font: inherit;\n}\n.zine-controls-btn svg { width: 15px; height: 15px; }\n.zine-controls-btn:hover:not(:disabled) { background: var(--zine-controls-hover, rgba(255,255,255,0.14)); }\n.zine-controls-btn:focus-visible {\n outline: 2px solid var(--zine-controls-accent, #7dd3fc);\n outline-offset: 1px;\n}\n.zine-controls-btn:disabled { opacity: 0.38; cursor: default; }\n/* A custom widget cannot always be disabled itself, so it is marked instead and reads the same. */\n.zine-controls-off { opacity: 0.38; }\n.zine-controls-off[aria-disabled='true'] { pointer-events: none; }\n.zine-controls-btn[aria-pressed=\"true\"],\n.zine-controls-btn[aria-expanded=\"true\"] { background: var(--zine-controls-hover, rgba(255,255,255,0.14)); }\n\n.zine-controls-sep {\n width: 1px;\n align-self: stretch;\n margin: 3px 3px;\n background: currentColor;\n opacity: 0.22;\n}\n.zine-controls-left .zine-controls-sep,\n.zine-controls-right .zine-controls-sep { width: auto; height: 1px; margin: 3px 3px; }\n\n.zine-controls-page {\n display: inline-flex;\n align-items: center;\n gap: 3px;\n padding: 0 3px;\n pointer-events: auto;\n white-space: nowrap;\n}\n.zine-controls-page input {\n width: 2.2em;\n padding: 2px 3px;\n border: 1px solid var(--zine-controls-hover, rgba(255,255,255,0.2));\n border-radius: 4px;\n background: rgba(0, 0, 0, 0.25);\n color: inherit;\n font: inherit;\n text-align: center;\n -moz-appearance: textfield;\n}\n.zine-controls-page input::-webkit-outer-spin-button,\n.zine-controls-page input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }\n.zine-controls-page input:focus-visible {\n outline: 2px solid var(--zine-controls-accent, #7dd3fc);\n outline-offset: 0;\n}\n\n.zine-controls-menu {\n position: absolute;\n display: flex;\n flex-direction: column;\n gap: 1px;\n min-width: 152px;\n padding: 4px;\n border-radius: 8px;\n pointer-events: auto;\n background: var(--zine-controls-bg, rgba(24, 24, 27, 0.94));\n box-shadow: 0 6px 22px rgba(0, 0, 0, 0.36);\n backdrop-filter: blur(8px);\n}\n.zine-controls-menu .zine-controls-btn {\n width: 100%;\n height: auto;\n gap: 8px;\n padding: 6px 8px;\n justify-content: flex-start;\n}\n\n/* Search shares the rail: a query field pinned at the top over a scrolling list of hits. */\n.zine-search { gap: 0; overflow: hidden; }\n.zine-search-input {\n flex: 0 0 auto;\n width: 100%;\n padding: 6px 8px;\n border: 1px solid var(--zine-controls-hover, rgba(255,255,255,0.2));\n border-radius: 6px;\n background: rgba(0, 0, 0, 0.25);\n color: inherit;\n font: inherit;\n box-sizing: border-box;\n}\n.zine-search-hits {\n flex: 1 1 auto;\n overflow-y: auto;\n overscroll-behavior: contain;\n margin-top: 5px;\n scrollbar-width: thin;\n}\n.zine-search-hit {\n display: block;\n width: 100%;\n padding: 6px 8px;\n border: 0;\n border-radius: 5px;\n background: transparent;\n color: inherit;\n font: inherit;\n text-align: left;\n cursor: pointer;\n box-sizing: border-box;\n}\n.zine-search-hit:hover { background: var(--zine-controls-hover, rgba(255,255,255,0.14)); }\n.zine-search-hit:focus-visible {\n outline: 2px solid var(--zine-controls-accent, #7dd3fc);\n outline-offset: -2px;\n}\n.zine-search-page { display: block; font-size: 0.9em; opacity: 0.85; }\n.zine-search-hit small {\n display: block;\n margin-top: 2px;\n opacity: 0.62;\n line-height: 1.35;\n overflow-wrap: anywhere;\n}\n\n/* Page-turn arrows flanking the book. Like the docked toolbar and the side panels, they sit\n outside the container so they never shrink the book or intercept its gestures. */\n.zine-arrows-wrap {\n display: flex;\n align-items: center;\n gap: 4px;\n min-width: 0;\n}\n.zine-arrows-wrap > *:not(.zine-arrow) { flex: 1 1 auto; min-width: 0; min-height: 0; }\n.zine-arrow {\n flex: 0 0 auto;\n display: inline-flex;\n align-items: center;\n justify-content: center;\n width: 40px;\n height: 40px;\n padding: 0;\n border: 0;\n border-radius: 50%;\n background: var(--zine-controls-bg, rgba(24, 24, 27, 0.82));\n color: var(--zine-controls-fg, #f4f4f5);\n cursor: pointer;\n backdrop-filter: blur(8px);\n -webkit-user-select: none;\n user-select: none;\n}\n.zine-arrow svg { width: 22px; height: 22px; }\n.zine-arrow:hover:not(:disabled) { background: var(--zine-controls-hover, rgba(255,255,255,0.22)); }\n.zine-arrow:focus-visible {\n outline: 2px solid var(--zine-controls-accent, #7dd3fc);\n outline-offset: 2px;\n}\n/* Nothing to turn to: invisible, but still occupying its slot so the book does not slide across\n as the reader reaches a cover. */\n.zine-arrow-hidden { visibility: hidden; }\n/* No room to flank on a narrow screen; the toolbar's own prev/next still work. */\n@media (max-width: 640px) {\n .zine-arrow { display: none; }\n}\n@media (prefers-reduced-motion: no-preference) {\n .zine-arrow { transition: background 120ms ease; }\n}\n\n/* Side panels (thumbnails, outline). The rail wraps the book and its docked toolbar so it sits\n beside them without shrinking the container the renderer measures. */\n.zine-panel-wrap { display: flex; align-items: stretch; gap: 8px; }\n\n/* The holder stretches to the book's height; the rail is absolutely positioned inside it so a\n long list scrolls rather than growing the row and running past the bottom of the book. */\n.zine-panel-holder {\n position: relative;\n flex: 0 0 auto;\n align-self: stretch;\n min-height: 0;\n}\n.zine-panel {\n position: absolute;\n inset: 0;\n display: flex;\n flex-direction: column;\n gap: 6px;\n overflow-y: auto;\n overscroll-behavior: contain;\n padding: 6px;\n box-sizing: border-box;\n border-radius: 8px;\n background: var(--zine-controls-bg, rgba(24, 24, 27, 0.82));\n color: var(--zine-controls-fg, #f4f4f5);\n font: 500 11px/1.2 system-ui, sans-serif;\n scrollbar-width: thin;\n touch-action: auto;\n -webkit-user-select: none;\n user-select: none;\n}\n/* Overlay fallback, used when the container has no parent to wrap. */\n.zine-panel-overlay { position: absolute; inset: 0 auto 0 0; z-index: 3; }\n.zine-panel-active { background: var(--zine-controls-hover, rgba(255,255,255,0.18)); }\n.zine-panel-note { padding: 8px; opacity: 0.66; line-height: 1.4; }\n\n.zine-thumbs { align-items: center; }\n\n.zine-thumbs-row {\n display: flex;\n flex-wrap: wrap;\n justify-content: center;\n gap: 2px;\n width: 100%;\n padding: 4px;\n border: 0;\n border-radius: 6px;\n background: transparent;\n color: inherit;\n font: inherit;\n cursor: pointer;\n box-sizing: border-box;\n}\n.zine-thumbs-row:hover { background: var(--zine-controls-hover, rgba(255,255,255,0.14)); }\n.zine-thumbs-row:focus-visible {\n outline: 2px solid var(--zine-controls-accent, #7dd3fc);\n outline-offset: -2px;\n}\n.zine-thumbs-row.zine-panel-active .zine-thumbs-cell {\n outline: 1px solid var(--zine-controls-accent, #7dd3fc);\n}\n\n/* Outline: a single column of headings, indented by depth. */\n.zine-outline { gap: 1px; }\n.zine-outline-row {\n display: block;\n width: 100%;\n padding: 6px 8px;\n border: 0;\n border-radius: 5px;\n background: transparent;\n color: inherit;\n font: inherit;\n text-align: left;\n line-height: 1.35;\n cursor: pointer;\n box-sizing: border-box;\n overflow-wrap: anywhere;\n}\n.zine-outline-row:hover:not(:disabled) {\n background: var(--zine-controls-hover, rgba(255,255,255,0.14));\n}\n.zine-outline-row:focus-visible {\n outline: 2px solid var(--zine-controls-accent, #7dd3fc);\n outline-offset: -2px;\n}\n/* A heading whose destination could not be resolved: shown, but nothing to click through to. */\n.zine-outline-row:disabled { opacity: 0.5; cursor: default; }\n\n.zine-thumbs-cell {\n flex: 1 1 0;\n min-width: 0;\n min-height: 24px;\n display: flex;\n background: rgba(0, 0, 0, 0.3);\n border-radius: 2px;\n overflow: hidden;\n}\n/* A lone page in a book that pairs elsewhere (a cover, a back page) keeps one page's width and\n centres, instead of stretching across both columns. */\n.zine-thumbs-row-lone .zine-thumbs-cell { flex: 0 0 calc(50% - 1px); }\n.zine-thumbs-img { display: block; width: 100%; height: auto; }\n.zine-thumbs-caption { flex: 1 0 100%; text-align: center; opacity: 0.7; }\n\n/* Share dialog. Centred over the page rather than in the side rail: a QR and six destinations\n need more room than the rail gives, and sharing is a brief interruption, not a browsing mode. */\n.zine-share-backdrop {\n position: fixed;\n inset: 0;\n z-index: 2147483000;\n display: flex;\n align-items: center;\n justify-content: center;\n padding: 16px;\n background: rgba(0, 0, 0, 0.55);\n font: 500 13px/1.4 system-ui, sans-serif;\n color: var(--zine-controls-fg, #f4f4f5);\n}\n.zine-share {\n width: min(320px, 100%);\n max-height: 100%;\n overflow-y: auto;\n display: flex;\n flex-direction: column;\n gap: 12px;\n padding: 14px;\n border-radius: 12px;\n background: var(--zine-share-bg, #1c1c20);\n box-shadow: 0 18px 50px rgba(0, 0, 0, 0.45);\n box-sizing: border-box;\n}\n.zine-share-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }\n.zine-share-head strong { font-size: 15px; }\n.zine-share-close {\n display: inline-flex;\n width: 26px;\n height: 26px;\n align-items: center;\n justify-content: center;\n padding: 0;\n border: 0;\n border-radius: 6px;\n background: transparent;\n color: inherit;\n cursor: pointer;\n}\n.zine-share-close svg { width: 16px; height: 16px; }\n.zine-share-close:hover { background: var(--zine-controls-hover, rgba(255,255,255,0.14)); }\n\n.zine-share-qr {\n align-self: center;\n line-height: 0;\n padding: 8px;\n border-radius: 8px;\n background: #fff;\n}\n.zine-share-qr svg { display: block; }\n\n.zine-share-link { display: flex; gap: 6px; }\n.zine-share-link input {\n flex: 1 1 auto;\n min-width: 0;\n padding: 7px 9px;\n border: 1px solid var(--zine-controls-hover, rgba(255,255,255,0.2));\n border-radius: 7px;\n background: rgba(0, 0, 0, 0.3);\n color: inherit;\n font: inherit;\n}\n.zine-share-copy {\n flex: 0 0 auto;\n min-width: 74px;\n padding: 7px 12px;\n border: 0;\n border-radius: 7px;\n background: var(--zine-controls-accent, #7dd3fc);\n color: #06202c;\n font: inherit;\n font-weight: 600;\n cursor: pointer;\n}\n\n.zine-share-socials { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; }\n.zine-share-social {\n display: inline-flex;\n width: 38px;\n height: 38px;\n align-items: center;\n justify-content: center;\n border-radius: 8px;\n background: rgba(255, 255, 255, 0.08);\n color: inherit;\n text-decoration: none;\n}\n.zine-share-social svg { width: 19px; height: 19px; }\n.zine-share-social:hover { background: var(--zine-controls-hover, rgba(255,255,255,0.18)); }\n.zine-share-close:focus-visible,\n.zine-share-copy:focus-visible,\n.zine-share-social:focus-visible,\n.zine-share-link input:focus-visible {\n outline: 2px solid var(--zine-controls-accent, #7dd3fc);\n outline-offset: 2px;\n}\n\n@media (prefers-reduced-motion: no-preference) {\n .zine-controls-btn { transition: background 120ms ease; }\n}\n";
|
|
109
|
+
function u(e) {
|
|
110
|
+
if (e.getElementById(c)) return;
|
|
111
|
+
let t = e.createElement("style");
|
|
112
|
+
t.id = c, t.textContent = l, (e.head ?? e.documentElement)?.appendChild(t);
|
|
113
|
+
}
|
|
114
|
+
//#endregion
|
|
115
|
+
//#region src/controls/sidebar.ts
|
|
116
|
+
var d = class {
|
|
117
|
+
root;
|
|
118
|
+
#e;
|
|
119
|
+
#t = null;
|
|
120
|
+
constructor(e, t, n) {
|
|
121
|
+
this.#e = e.createElement("div"), this.#e.className = "zine-panel-holder", this.#e.style.width = `${n.width}px`, this.root = e.createElement("div"), this.root.className = `zine-panel ${n.className}`, this.root.setAttribute("role", "listbox"), this.root.setAttribute("aria-label", n.label), this.#e.appendChild(this.root);
|
|
122
|
+
for (let e of [
|
|
123
|
+
"pointerdown",
|
|
124
|
+
"pointerup",
|
|
125
|
+
"pointermove",
|
|
126
|
+
"click",
|
|
127
|
+
"dblclick",
|
|
128
|
+
"wheel"
|
|
129
|
+
]) this.root.addEventListener(e, (e) => e.stopPropagation());
|
|
130
|
+
this.#n(e, t);
|
|
131
|
+
}
|
|
132
|
+
setWidth(e) {
|
|
133
|
+
this.#e.style.width = `${e}px`;
|
|
134
|
+
}
|
|
135
|
+
#n(e, t) {
|
|
136
|
+
if (!t.parentNode) {
|
|
137
|
+
this.#e.classList.add("zine-panel-overlay"), t.appendChild(this.#e);
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
let n = t.closest(".zine-controls-wrap") ?? t, r = e.createElement("div");
|
|
141
|
+
r.className = "zine-panel-wrap", n.parentNode.insertBefore(r, n), r.append(this.#e, n), this.#t = r;
|
|
142
|
+
}
|
|
143
|
+
destroy() {
|
|
144
|
+
this.#e.remove();
|
|
145
|
+
let e = this.#t;
|
|
146
|
+
if (e?.parentNode) {
|
|
147
|
+
for (; e.firstChild;) e.parentNode.insertBefore(e.firstChild, e);
|
|
148
|
+
e.remove();
|
|
149
|
+
}
|
|
150
|
+
this.#t = null;
|
|
151
|
+
}
|
|
152
|
+
}, f = 78, p = class {
|
|
153
|
+
#e;
|
|
154
|
+
#t;
|
|
155
|
+
#n;
|
|
156
|
+
#r = [];
|
|
157
|
+
#i = null;
|
|
158
|
+
#a = [];
|
|
159
|
+
constructor(e, t) {
|
|
160
|
+
this.#e = e;
|
|
161
|
+
let n = t.ownerDocument;
|
|
162
|
+
this.#t = n, this.#n = new d(n, t, {
|
|
163
|
+
className: "zine-thumbs",
|
|
164
|
+
label: "Pages",
|
|
165
|
+
width: 90
|
|
166
|
+
}), this.#o(), this.#a.push(e.on("pageChanged", () => this.#l())), this.#l();
|
|
167
|
+
}
|
|
168
|
+
#o() {
|
|
169
|
+
let e = this.#e.getSpreads(), t = this.#e.getDirection() === "rtl", n = e.some((e) => e.left !== null && e.right !== null);
|
|
170
|
+
this.#n.root.classList.toggle("zine-thumbs-solo", !n), n && this.#n.setWidth(170);
|
|
171
|
+
for (let [r, i] of e.entries()) {
|
|
172
|
+
let e = this.#t.createElement("button");
|
|
173
|
+
e.type = "button", e.className = "zine-thumbs-row", e.setAttribute("role", "option"), t && (e.style.flexDirection = "row-reverse");
|
|
174
|
+
let a = [i.left, i.right].filter((e) => e !== null);
|
|
175
|
+
n && a.length === 1 && e.classList.add("zine-thumbs-row-lone");
|
|
176
|
+
for (let t of a) {
|
|
177
|
+
let n = this.#t.createElement("span");
|
|
178
|
+
n.className = "zine-thumbs-cell", n.dataset.page = String(t), e.appendChild(n);
|
|
179
|
+
}
|
|
180
|
+
let o = [...a].sort((e, t) => e - t).map((e) => e + 1);
|
|
181
|
+
e.setAttribute("aria-label", o.length > 1 ? `Pages ${o[0]}–${o.at(-1)}` : `Page ${o[0] ?? ""}`);
|
|
182
|
+
let s = this.#t.createElement("span");
|
|
183
|
+
s.className = "zine-thumbs-caption", s.textContent = o.join("–"), e.appendChild(s), e.addEventListener("click", () => {
|
|
184
|
+
a.length > 0 && this.#e.flipTo(Math.min(...a));
|
|
185
|
+
}), this.#n.root.appendChild(e), this.#r.push({
|
|
186
|
+
el: e,
|
|
187
|
+
spread: r
|
|
188
|
+
});
|
|
189
|
+
}
|
|
190
|
+
this.#s();
|
|
191
|
+
}
|
|
192
|
+
#s() {
|
|
193
|
+
let e = [...this.#n.root.querySelectorAll(".zine-thumbs-cell[data-page]")];
|
|
194
|
+
if (typeof IntersectionObserver > "u") {
|
|
195
|
+
for (let t of e) this.#c(t);
|
|
196
|
+
return;
|
|
197
|
+
}
|
|
198
|
+
this.#i = new IntersectionObserver((e, t) => {
|
|
199
|
+
for (let n of e) n.isIntersecting && (t.unobserve(n.target), this.#c(n.target));
|
|
200
|
+
}, {
|
|
201
|
+
root: this.#n.root,
|
|
202
|
+
rootMargin: "200px"
|
|
203
|
+
});
|
|
204
|
+
for (let t of e) this.#i.observe(t);
|
|
205
|
+
}
|
|
206
|
+
async #c(e) {
|
|
207
|
+
let t = Number(e.dataset.page), n = await this.#e.getPageImage(t);
|
|
208
|
+
if (!n || !e.isConnected) return;
|
|
209
|
+
let r = n.width, i = n.height;
|
|
210
|
+
if (!r || !i) return;
|
|
211
|
+
let a = Math.min(2, globalThis.devicePixelRatio || 1), o = this.#t.createElement("canvas");
|
|
212
|
+
o.width = Math.max(1, Math.round(f * a)), o.height = Math.max(1, Math.round(f * i / r * a)), o.className = "zine-thumbs-img";
|
|
213
|
+
let s = o.getContext("2d");
|
|
214
|
+
if (s) {
|
|
215
|
+
try {
|
|
216
|
+
s.drawImage(n, 0, 0, o.width, o.height);
|
|
217
|
+
} catch {
|
|
218
|
+
return;
|
|
219
|
+
}
|
|
220
|
+
e.replaceChildren(o);
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
#l() {
|
|
224
|
+
let e = this.#e.getSpreadIndex();
|
|
225
|
+
for (let { el: t, spread: n } of this.#r) {
|
|
226
|
+
let r = n === e;
|
|
227
|
+
t.classList.toggle("zine-panel-active", r), t.setAttribute("aria-selected", String(r)), r && t.scrollIntoView?.({ block: "nearest" });
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
destroy() {
|
|
231
|
+
for (let e of this.#a) e();
|
|
232
|
+
this.#a = [], this.#i?.disconnect(), this.#i = null, this.#n.destroy();
|
|
233
|
+
}
|
|
234
|
+
}, m = 208, h = 12, g = class {
|
|
235
|
+
#e;
|
|
236
|
+
#t;
|
|
237
|
+
#n;
|
|
238
|
+
#r = [];
|
|
239
|
+
#i = [];
|
|
240
|
+
constructor(e, t) {
|
|
241
|
+
this.#e = e;
|
|
242
|
+
let n = t.ownerDocument;
|
|
243
|
+
this.#t = n, this.#n = new d(n, t, {
|
|
244
|
+
className: "zine-outline",
|
|
245
|
+
label: "Outline",
|
|
246
|
+
width: m
|
|
247
|
+
}), this.#a("Loading…"), this.#o(), this.#i.push(e.on("pageChanged", () => this.#c()));
|
|
248
|
+
}
|
|
249
|
+
#a(e) {
|
|
250
|
+
let t = this.#t.createElement("div");
|
|
251
|
+
t.className = "zine-panel-note", t.textContent = e, this.#n.root.replaceChildren(t);
|
|
252
|
+
}
|
|
253
|
+
async #o() {
|
|
254
|
+
let e = await this.#e.getOutline();
|
|
255
|
+
if (this.#n.root.isConnected) {
|
|
256
|
+
if (e.length === 0) {
|
|
257
|
+
this.#a("This document has no outline.");
|
|
258
|
+
return;
|
|
259
|
+
}
|
|
260
|
+
this.#n.root.replaceChildren(), this.#s(e, 0), this.#c();
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
#s(e, t) {
|
|
264
|
+
for (let n of e) {
|
|
265
|
+
let e = this.#t.createElement("button");
|
|
266
|
+
if (e.type = "button", e.className = "zine-outline-row", e.setAttribute("role", "option"), e.style.paddingLeft = `${8 + t * h}px`, e.textContent = n.title, e.title = n.title, n.page === null) e.disabled = !0;
|
|
267
|
+
else {
|
|
268
|
+
let t = n.page;
|
|
269
|
+
e.setAttribute("aria-label", `${n.title}, page ${t + 1}`), e.addEventListener("click", () => this.#e.flipTo(t)), this.#r.push({
|
|
270
|
+
el: e,
|
|
271
|
+
page: t
|
|
272
|
+
});
|
|
273
|
+
}
|
|
274
|
+
this.#n.root.appendChild(e), n.children.length > 0 && this.#s(n.children, t + 1);
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
#c() {
|
|
278
|
+
let e = this.#e.getPage(), t = null, n = -1;
|
|
279
|
+
for (let { el: r, page: i } of this.#r) r.classList.remove("zine-panel-active"), r.removeAttribute("aria-selected"), i <= e && i >= n && (t = r, n = i);
|
|
280
|
+
t && (t.classList.add("zine-panel-active"), t.setAttribute("aria-selected", "true"), t.scrollIntoView?.({ block: "nearest" }));
|
|
281
|
+
}
|
|
282
|
+
destroy() {
|
|
283
|
+
for (let e of this.#i) e();
|
|
284
|
+
this.#i = [], this.#n.destroy();
|
|
285
|
+
}
|
|
286
|
+
}, _ = 208, v = 180, y = 2, b = class {
|
|
287
|
+
#e;
|
|
288
|
+
#t;
|
|
289
|
+
#n;
|
|
290
|
+
#r;
|
|
291
|
+
#i;
|
|
292
|
+
#a = 0;
|
|
293
|
+
#o = null;
|
|
294
|
+
constructor(e, t) {
|
|
295
|
+
this.#e = e;
|
|
296
|
+
let n = t.ownerDocument;
|
|
297
|
+
this.#t = n, this.#n = new d(n, t, {
|
|
298
|
+
className: "zine-search",
|
|
299
|
+
label: "Search results",
|
|
300
|
+
width: _
|
|
301
|
+
}), this.#r = n.createElement("input"), this.#r.type = "search", this.#r.className = "zine-search-input", this.#r.placeholder = "Search…", this.#r.setAttribute("aria-label", "Search the document"), this.#r.addEventListener("input", () => {
|
|
302
|
+
this.#o && clearTimeout(this.#o), this.#o = setTimeout(() => void this.#c(), v);
|
|
303
|
+
}), this.#r.addEventListener("keydown", (e) => {
|
|
304
|
+
e.key === "Enter" && (this.#o && clearTimeout(this.#o), this.#c());
|
|
305
|
+
}), this.#i = n.createElement("div"), this.#i.className = "zine-search-hits", this.#n.root.append(this.#r, this.#i), this.#r.focus();
|
|
306
|
+
}
|
|
307
|
+
#s(e) {
|
|
308
|
+
let t = this.#t.createElement("div");
|
|
309
|
+
t.className = "zine-panel-note", t.textContent = e, this.#i.replaceChildren(t);
|
|
310
|
+
}
|
|
311
|
+
async #c() {
|
|
312
|
+
let e = this.#r.value.trim(), t = ++this.#a;
|
|
313
|
+
if (e.length < y) {
|
|
314
|
+
this.#i.replaceChildren();
|
|
315
|
+
return;
|
|
316
|
+
}
|
|
317
|
+
this.#s("Searching…");
|
|
318
|
+
let n = await this.#e.search(e);
|
|
319
|
+
if (!(t !== this.#a || !this.#n.root.isConnected)) {
|
|
320
|
+
if (n.length === 0) {
|
|
321
|
+
this.#s(`No matches for “${e}”`);
|
|
322
|
+
return;
|
|
323
|
+
}
|
|
324
|
+
this.#i.replaceChildren(...n.map((e) => {
|
|
325
|
+
let t = this.#t.createElement("button");
|
|
326
|
+
t.type = "button", t.className = "zine-search-hit", t.setAttribute("role", "option"), t.setAttribute("aria-label", `Page ${e.page + 1}: ${e.excerpt}`);
|
|
327
|
+
let n = this.#t.createElement("span");
|
|
328
|
+
n.className = "zine-search-page", n.textContent = `Page ${e.page + 1}`;
|
|
329
|
+
let r = this.#t.createElement("small");
|
|
330
|
+
return r.textContent = e.excerpt, t.append(n, r), t.addEventListener("click", () => this.#e.flipTo(e.page)), t;
|
|
331
|
+
}));
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
destroy() {
|
|
335
|
+
this.#o && clearTimeout(this.#o), this.#o = null, this.#a++, this.#n.destroy();
|
|
336
|
+
}
|
|
337
|
+
}, x = class {
|
|
338
|
+
#e;
|
|
339
|
+
#t;
|
|
340
|
+
#n;
|
|
341
|
+
#r = null;
|
|
342
|
+
#i = [];
|
|
343
|
+
constructor(e, t) {
|
|
344
|
+
this.#e = e;
|
|
345
|
+
let n = t.ownerDocument, r = e.getDirection() === "rtl";
|
|
346
|
+
this.#t = this.#a(n, r ? i.next : i.prev, "Previous page", () => e.flipPrev()), this.#n = this.#a(n, r ? i.prev : i.next, "Next page", () => e.flipNext()), this.#o(n, t);
|
|
347
|
+
let a = () => this.#s();
|
|
348
|
+
this.#i.push(e.on("pageChanged", a)), this.#i.push(e.on("flipEnd", a)), this.#s();
|
|
349
|
+
}
|
|
350
|
+
#a(e, t, n, i) {
|
|
351
|
+
let a = e.createElement("button");
|
|
352
|
+
a.type = "button", a.className = "zine-arrow", a.title = n, a.setAttribute("aria-label", n), a.appendChild(r(e, t)), a.addEventListener("click", i);
|
|
353
|
+
for (let e of [
|
|
354
|
+
"pointerdown",
|
|
355
|
+
"pointerup",
|
|
356
|
+
"click"
|
|
357
|
+
]) a.addEventListener(e, (e) => e.stopPropagation());
|
|
358
|
+
return a;
|
|
359
|
+
}
|
|
360
|
+
#o(e, t) {
|
|
361
|
+
let n = t.closest(".zine-panel-wrap") ?? t.closest(".zine-controls-wrap") ?? t, r = n.parentNode;
|
|
362
|
+
if (!r) return;
|
|
363
|
+
let i = e.createElement("div");
|
|
364
|
+
i.className = "zine-arrows-wrap", r.insertBefore(i, n), i.append(this.#t, n, this.#n), this.#r = i;
|
|
365
|
+
}
|
|
366
|
+
#s() {
|
|
367
|
+
for (let [e, t] of [[this.#t, this.#e.canFlipPrev()], [this.#n, this.#e.canFlipNext()]]) e.disabled = !t, e.classList.toggle("zine-arrow-hidden", !t);
|
|
368
|
+
}
|
|
369
|
+
destroy() {
|
|
370
|
+
for (let e of this.#i) e();
|
|
371
|
+
this.#i = [], this.#t.remove(), this.#n.remove();
|
|
372
|
+
let e = this.#r;
|
|
373
|
+
if (e?.parentNode) {
|
|
374
|
+
for (; e.firstChild;) e.parentNode.insertBefore(e.firstChild, e);
|
|
375
|
+
e.remove();
|
|
376
|
+
}
|
|
377
|
+
this.#r = null;
|
|
378
|
+
}
|
|
379
|
+
}, S = {
|
|
380
|
+
thumbnails: p,
|
|
381
|
+
outline: g,
|
|
382
|
+
search: b
|
|
383
|
+
}, C = [
|
|
384
|
+
"pointerdown",
|
|
385
|
+
"pointerup",
|
|
386
|
+
"pointermove",
|
|
387
|
+
"click",
|
|
388
|
+
"dblclick",
|
|
389
|
+
"wheel",
|
|
390
|
+
"keydown"
|
|
391
|
+
], w = class {
|
|
392
|
+
#e;
|
|
393
|
+
#t;
|
|
394
|
+
#n;
|
|
395
|
+
#r;
|
|
396
|
+
#i = [];
|
|
397
|
+
#a = null;
|
|
398
|
+
#o = [];
|
|
399
|
+
#s = null;
|
|
400
|
+
#c = null;
|
|
401
|
+
#l;
|
|
402
|
+
#u = null;
|
|
403
|
+
#d = null;
|
|
404
|
+
#f = null;
|
|
405
|
+
#p = null;
|
|
406
|
+
constructor(e, t, n) {
|
|
407
|
+
this.#e = e, this.#l = t;
|
|
408
|
+
let r = t.ownerDocument;
|
|
409
|
+
this.#t = r, u(r);
|
|
410
|
+
let i = n.position ?? "bottom", a = n.docked ?? !0;
|
|
411
|
+
this.#n = r.createElement("div"), this.#n.className = [
|
|
412
|
+
"zine-controls",
|
|
413
|
+
`zine-controls-${i}`,
|
|
414
|
+
a ? "zine-controls-docked" : "zine-controls-floating",
|
|
415
|
+
n.className
|
|
416
|
+
].filter(Boolean).join(" "), this.#n.setAttribute("role", "toolbar"), this.#n.setAttribute("aria-label", "Flipbook controls"), this.#r = r.createElement("div"), this.#r.className = "zine-controls-bar", this.#n.appendChild(this.#r), this.#n.addEventListener("keydown", (e) => this.#E(e));
|
|
417
|
+
for (let e of C) this.#n.addEventListener(e, (e) => this.#h(e));
|
|
418
|
+
this.#m(t, i, a);
|
|
419
|
+
let o = () => this.#D();
|
|
420
|
+
this.#o.push(e.on("pageChanged", o)), this.#o.push(e.on("zoomChanged", o)), this.#o.push(e.on("flipEnd", o));
|
|
421
|
+
let s = (e) => {
|
|
422
|
+
this.#a && !this.#a.el.contains(e.target) && this.#T();
|
|
423
|
+
};
|
|
424
|
+
r.addEventListener("pointerdown", s, !0), this.#o.push(() => r.removeEventListener("pointerdown", s, !0));
|
|
425
|
+
}
|
|
426
|
+
#m(e, t, n) {
|
|
427
|
+
if (!n) {
|
|
428
|
+
e.appendChild(this.#n);
|
|
429
|
+
return;
|
|
430
|
+
}
|
|
431
|
+
let r = e.parentNode;
|
|
432
|
+
if (!r) {
|
|
433
|
+
this.#n.classList.replace("zine-controls-docked", "zine-controls-floating"), e.appendChild(this.#n);
|
|
434
|
+
return;
|
|
435
|
+
}
|
|
436
|
+
let i = this.#t.createElement("div");
|
|
437
|
+
i.className = `zine-controls-wrap zine-controls-wrap-${t}`, r.insertBefore(i, e), i.appendChild(e), t === "top" || t === "left" ? i.insertBefore(this.#n, e) : i.appendChild(this.#n), this.#c = i;
|
|
438
|
+
}
|
|
439
|
+
mount(e) {
|
|
440
|
+
this.#_(e.items ?? n), (e.arrows ?? !0) && (this.#p = new x(this.#e, this.#l)), this.#D(), this.#A();
|
|
441
|
+
}
|
|
442
|
+
destroy() {
|
|
443
|
+
for (let e of this.#o) e();
|
|
444
|
+
this.#o = [], this.#T(), this.#u?.destroy(), this.#u = null, this.#d = null, this.#n.remove();
|
|
445
|
+
let e = this.#c;
|
|
446
|
+
e?.parentNode && (e.parentNode.insertBefore(e.firstChild, e), e.remove()), this.#c = null, this.#p?.destroy(), this.#p = null;
|
|
447
|
+
}
|
|
448
|
+
#h(e) {
|
|
449
|
+
e.stopPropagation();
|
|
450
|
+
}
|
|
451
|
+
#g(e = () => this.#T()) {
|
|
452
|
+
return {
|
|
453
|
+
zine: this.#e,
|
|
454
|
+
close: e
|
|
455
|
+
};
|
|
456
|
+
}
|
|
457
|
+
#_(t) {
|
|
458
|
+
for (let n of t) {
|
|
459
|
+
if (n === "|") {
|
|
460
|
+
let e = this.#t.createElement("div");
|
|
461
|
+
e.className = "zine-controls-sep", this.#r.appendChild(e);
|
|
462
|
+
continue;
|
|
463
|
+
}
|
|
464
|
+
let t = e(n), r;
|
|
465
|
+
t.render ? (r = t.render(this.#g()), this.#i.push({
|
|
466
|
+
el: r,
|
|
467
|
+
def: t
|
|
468
|
+
})) : r = this.#b(t, "zine-controls-btn"), this.#r.appendChild(r);
|
|
469
|
+
}
|
|
470
|
+
}
|
|
471
|
+
#v(e) {
|
|
472
|
+
return typeof e.title == "function" ? e.title(this.#g()) : e.title;
|
|
473
|
+
}
|
|
474
|
+
#y(e) {
|
|
475
|
+
return typeof e.icon == "function" ? e.icon(this.#g()) : e.icon;
|
|
476
|
+
}
|
|
477
|
+
#b(e, t, n = !1) {
|
|
478
|
+
let i = this.#t.createElement("button"), a = this.#v(e), o = this.#y(e);
|
|
479
|
+
if (i.type = "button", i.className = t, i.title = a, i.setAttribute("aria-label", a), o && i.appendChild(r(this.#t, o)), n || !o) {
|
|
480
|
+
let e = this.#t.createElement("span");
|
|
481
|
+
e.className = "zine-controls-label", e.textContent = a, i.appendChild(e);
|
|
482
|
+
}
|
|
483
|
+
return i.addEventListener("click", () => this.#x(e, i)), this.#i.push({
|
|
484
|
+
el: i,
|
|
485
|
+
def: e
|
|
486
|
+
}), i;
|
|
487
|
+
}
|
|
488
|
+
#x(e, t) {
|
|
489
|
+
if (!e.isDisabled?.(this.#g())) {
|
|
490
|
+
if (e.children) {
|
|
491
|
+
this.#a?.trigger === t ? this.#T() : this.#S(e, t);
|
|
492
|
+
return;
|
|
493
|
+
}
|
|
494
|
+
e.action?.(this.#g()), this.#D();
|
|
495
|
+
}
|
|
496
|
+
}
|
|
497
|
+
#S(t, n) {
|
|
498
|
+
this.#T();
|
|
499
|
+
let r = this.#t.createElement("div");
|
|
500
|
+
r.className = "zine-controls-menu", r.setAttribute("role", "menu");
|
|
501
|
+
let i = this.#g();
|
|
502
|
+
for (let n of t.children ?? []) {
|
|
503
|
+
if (n === "|") continue;
|
|
504
|
+
let t = e(n);
|
|
505
|
+
if (t.isVisible && !t.isVisible(i)) continue;
|
|
506
|
+
let a;
|
|
507
|
+
t.render ? (a = t.render(this.#g()), this.#i.push({
|
|
508
|
+
el: a,
|
|
509
|
+
def: t
|
|
510
|
+
})) : a = this.#b(t, "zine-controls-btn", !0), a.setAttribute("role", "menuitem"), r.appendChild(a);
|
|
511
|
+
}
|
|
512
|
+
this.#C(r, n), this.#D(), r.querySelector("button")?.focus();
|
|
513
|
+
}
|
|
514
|
+
#C(e, t) {
|
|
515
|
+
this.#n.appendChild(e), this.#a = {
|
|
516
|
+
el: e,
|
|
517
|
+
trigger: t
|
|
518
|
+
}, t.setAttribute("aria-expanded", "true"), this.#w(e, t);
|
|
519
|
+
}
|
|
520
|
+
#w(e, t) {
|
|
521
|
+
let n = this.#n.getBoundingClientRect(), r = t.getBoundingClientRect(), i = e.getBoundingClientRect();
|
|
522
|
+
if (!n.width || !i.width) return;
|
|
523
|
+
let a = r.left - n.left + r.width / 2 - i.width / 2;
|
|
524
|
+
a = Math.max(4, Math.min(a, n.width - i.width - 4)), e.style.left = `${a}px`;
|
|
525
|
+
let o = r.bottom - n.top + 6, s = r.top - n.top - i.height - 6;
|
|
526
|
+
e.style.top = `${s >= 0 ? s : o}px`;
|
|
527
|
+
}
|
|
528
|
+
#T() {
|
|
529
|
+
if (!this.#a) return;
|
|
530
|
+
let { el: e, trigger: t } = this.#a;
|
|
531
|
+
this.#a = null, t.removeAttribute("aria-expanded"), this.#i = this.#i.filter((t) => !e.contains(t.el)), e.remove(), this.#t.activeElement && e.contains(this.#t.activeElement) && t.focus();
|
|
532
|
+
}
|
|
533
|
+
#E(e) {
|
|
534
|
+
if (e.key === "Escape" && this.#a) {
|
|
535
|
+
let { trigger: t } = this.#a;
|
|
536
|
+
this.#T(), t.focus(), e.preventDefault();
|
|
537
|
+
return;
|
|
538
|
+
}
|
|
539
|
+
let t = [...this.#n.querySelectorAll("button, input")], n = t.indexOf(this.#t.activeElement);
|
|
540
|
+
if (n < 0 || this.#t.activeElement instanceof HTMLInputElement) return;
|
|
541
|
+
let r = e.key === "ArrowRight" || e.key === "ArrowDown" ? 1 : e.key === "ArrowLeft" || e.key === "ArrowUp" ? -1 : 0;
|
|
542
|
+
r !== 0 && (t[(n + r + t.length) % t.length]?.focus(), e.preventDefault());
|
|
543
|
+
}
|
|
544
|
+
#D() {
|
|
545
|
+
let e = this.#g();
|
|
546
|
+
for (let { el: t, def: n } of this.#i) {
|
|
547
|
+
let i = n.children ? this.#k(n, e) : n.isVisible?.(e);
|
|
548
|
+
i !== void 0 && (t.style.display = i ? "" : "none");
|
|
549
|
+
let a = n.isDisabled?.(e) ?? !1;
|
|
550
|
+
for (let e of this.#O(t)) e.disabled = a;
|
|
551
|
+
if (this.#O(t).length || t.setAttribute("aria-disabled", String(a)), t.classList.toggle("zine-controls-off", a), n.isActive && t.setAttribute("aria-pressed", String(n.isActive(e))), typeof n.title == "function") {
|
|
552
|
+
let r = n.title(e);
|
|
553
|
+
t.title = r, t.setAttribute("aria-label", r);
|
|
554
|
+
let i = t.querySelector(".zine-controls-label");
|
|
555
|
+
i && (i.textContent = r);
|
|
556
|
+
}
|
|
557
|
+
typeof n.icon == "function" && t.querySelector("svg")?.replaceWith(r(this.#t, n.icon(e)));
|
|
558
|
+
}
|
|
559
|
+
this.#s && this.#t.activeElement !== this.#s && (this.#s.value = String(this.#e.getPage() + 1));
|
|
560
|
+
}
|
|
561
|
+
#O(e) {
|
|
562
|
+
return e instanceof HTMLButtonElement || e instanceof HTMLInputElement ? [e] : [...e.querySelectorAll("button, input")];
|
|
563
|
+
}
|
|
564
|
+
#k(t, n) {
|
|
565
|
+
return t.isVisible && !t.isVisible(n) ? !1 : (t.children ?? []).some((t) => {
|
|
566
|
+
if (t === "|") return !1;
|
|
567
|
+
let r = e(t);
|
|
568
|
+
return !r.isVisible || r.isVisible(n);
|
|
569
|
+
});
|
|
570
|
+
}
|
|
571
|
+
makePageInput() {
|
|
572
|
+
let e = this.#t.createElement("div");
|
|
573
|
+
e.className = "zine-controls-page";
|
|
574
|
+
let t = this.#t.createElement("input");
|
|
575
|
+
t.type = "number", t.min = "1", t.max = String(this.#e.getPageCount()), t.value = String(this.#e.getPage() + 1), t.setAttribute("aria-label", "Page number");
|
|
576
|
+
let n = this.#t.createElement("span");
|
|
577
|
+
n.textContent = `/ ${this.#e.getPageCount()}`;
|
|
578
|
+
let r = () => {
|
|
579
|
+
let e = Number(t.value);
|
|
580
|
+
Number.isFinite(e) && this.#e.flipTo(Math.round(e) - 1), t.value = String(this.#e.getPage() + 1);
|
|
581
|
+
};
|
|
582
|
+
return t.addEventListener("keydown", (e) => {
|
|
583
|
+
e.key === "Enter" && (r(), t.blur());
|
|
584
|
+
}), t.addEventListener("blur", r), e.append(t, n), this.#s = t, e;
|
|
585
|
+
}
|
|
586
|
+
openPanel() {
|
|
587
|
+
return this.#d;
|
|
588
|
+
}
|
|
589
|
+
hasOutline() {
|
|
590
|
+
return this.#f === !0;
|
|
591
|
+
}
|
|
592
|
+
#A() {
|
|
593
|
+
this.#f !== null || !this.#e.canOutline() || (this.#f = !1, this.#e.getOutline().then((e) => {
|
|
594
|
+
if (e.length === 0) return;
|
|
595
|
+
this.#f = !0, this.#D();
|
|
596
|
+
let t = this.#a;
|
|
597
|
+
if (t) {
|
|
598
|
+
let e = this.#i.find((e) => e.el === t.trigger)?.def;
|
|
599
|
+
this.#T(), e && this.#S(e, t.trigger);
|
|
600
|
+
}
|
|
601
|
+
}));
|
|
602
|
+
}
|
|
603
|
+
togglePanel(e) {
|
|
604
|
+
let t = this.#d;
|
|
605
|
+
this.#u?.destroy(), this.#u = null, this.#d = null, t !== e && (this.#u = new S[e](this.#e, this.#l), this.#d = e), this.#D();
|
|
606
|
+
}
|
|
607
|
+
};
|
|
608
|
+
function T(e) {
|
|
609
|
+
s(), t({
|
|
610
|
+
id: "thumbnails",
|
|
611
|
+
title: () => e.openPanel() === "thumbnails" ? "Hide thumbnails" : "Show thumbnails",
|
|
612
|
+
icon: i.thumbnails,
|
|
613
|
+
isVisible: (e) => e.zine.isDocument(),
|
|
614
|
+
isActive: () => e.openPanel() === "thumbnails",
|
|
615
|
+
action: (t) => {
|
|
616
|
+
e.togglePanel("thumbnails"), t.close();
|
|
617
|
+
}
|
|
618
|
+
}), t({
|
|
619
|
+
id: "outline",
|
|
620
|
+
title: () => e.openPanel() === "outline" ? "Hide outline" : "Show outline",
|
|
621
|
+
icon: i.outline,
|
|
622
|
+
isVisible: () => e.hasOutline(),
|
|
623
|
+
isActive: () => e.openPanel() === "outline",
|
|
624
|
+
action: (t) => {
|
|
625
|
+
e.togglePanel("outline"), t.close();
|
|
626
|
+
}
|
|
627
|
+
}), t({
|
|
628
|
+
id: "pageInput",
|
|
629
|
+
title: "Page",
|
|
630
|
+
render: () => e.makePageInput()
|
|
631
|
+
}), t({
|
|
632
|
+
id: "search",
|
|
633
|
+
title: () => e.openPanel() === "search" ? "Hide search" : "Search",
|
|
634
|
+
icon: i.search,
|
|
635
|
+
isVisible: (e) => e.zine.canSearch(),
|
|
636
|
+
isActive: () => e.openPanel() === "search",
|
|
637
|
+
action: () => e.togglePanel("search")
|
|
638
|
+
});
|
|
639
|
+
}
|
|
640
|
+
//#endregion
|
|
641
|
+
//#region src/controls/controls.ts
|
|
642
|
+
function E(e, t, n = {}) {
|
|
643
|
+
let r = new w(e, t, n);
|
|
644
|
+
return T(r), r.mount(n), () => r.destroy();
|
|
645
|
+
}
|
|
646
|
+
//#endregion
|
|
647
|
+
export { E as mountControls };
|
|
648
|
+
|
|
649
|
+
//# sourceMappingURL=controls-BrPo8pKL.js.map
|