@readium/navigator-html-injectables 2.5.0 → 2.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.
Files changed (73) hide show
  1. package/dist/Loader.js +1 -0
  2. package/dist/comms/comms.js +1 -0
  3. package/dist/comms/mid.js +1 -0
  4. package/dist/helpers/animation.js +1 -0
  5. package/dist/helpers/css.js +1 -0
  6. package/dist/helpers/document.js +1 -0
  7. package/dist/helpers/dom.js +1 -0
  8. package/dist/helpers/locator.js +1 -0
  9. package/dist/helpers/rect.js +1 -0
  10. package/dist/helpers/sanitize.js +1 -0
  11. package/dist/index.js +1 -4601
  12. package/dist/keyboard/KeyCombinationManager.js +1 -0
  13. package/dist/keyboard/KeyboardCombinations.js +1 -0
  14. package/dist/modules/Decorator.js +24 -0
  15. package/dist/modules/Module.js +1 -0
  16. package/dist/modules/ModuleLibrary.js +1 -0
  17. package/dist/modules/Peripherals.js +1 -0
  18. package/dist/modules/setup/FixedSetup.js +13 -0
  19. package/dist/modules/setup/ReflowableSetup.js +1 -0
  20. package/dist/modules/setup/Setup.js +1 -0
  21. package/dist/modules/setup/WebPubSetup.js +1 -0
  22. package/dist/modules/snapper/CJKVerticalSnapper.js +12 -0
  23. package/dist/modules/snapper/ColumnSnapper.js +35 -0
  24. package/dist/modules/snapper/ScrollSnapper.js +9 -0
  25. package/dist/modules/snapper/Snapper.js +5 -0
  26. package/dist/modules/snapper/WebPubSnapper.js +1 -0
  27. package/dist/protection/BulkCopyProtector.js +1 -0
  28. package/dist/protection/PatternAnalyzer.js +1 -0
  29. package/dist/protection/PrintProtector.js +15 -0
  30. package/dist/protection/SelectionAnalyzer.js +1 -0
  31. package/dist/protection/config.js +1 -0
  32. package/dist/vendor/approx-string-match/index.js +1 -0
  33. package/dist/vendor/hypothesis/anchoring/match-quote.js +1 -0
  34. package/dist/vendor/hypothesis/anchoring/text-range.js +1 -0
  35. package/dist/vendor/hypothesis/anchoring/trim-range.js +1 -0
  36. package/dist/vendor/hypothesis/anchoring/types.js +1 -0
  37. package/package.json +9 -8
  38. package/src/comms/comms.ts +11 -1
  39. package/src/comms/keys.ts +6 -2
  40. package/src/helpers/css.ts +1 -1
  41. package/src/helpers/document.ts +5 -5
  42. package/src/helpers/locator.ts +5 -5
  43. package/src/helpers/rect.ts +79 -18
  44. package/src/index.ts +1 -1
  45. package/src/modules/Decorator.ts +404 -107
  46. package/src/modules/snapper/CJKVerticalSnapper.ts +34 -7
  47. package/src/modules/snapper/ColumnSnapper.ts +54 -6
  48. package/src/modules/snapper/ScrollSnapper.ts +30 -7
  49. package/src/modules/snapper/Snapper.ts +144 -0
  50. package/src/modules/snapper/WebPubSnapper.ts +31 -7
  51. package/types/src/comms/comms.d.ts +10 -1
  52. package/types/src/comms/keys.d.ts +2 -2
  53. package/types/src/helpers/css.d.ts +1 -1
  54. package/types/src/helpers/document.d.ts +5 -5
  55. package/types/src/helpers/rect.d.ts +2 -1
  56. package/types/src/index.d.ts +1 -1
  57. package/types/src/modules/Decorator.d.ts +33 -7
  58. package/types/src/modules/snapper/CJKVerticalSnapper.d.ts +1 -0
  59. package/types/src/modules/snapper/ColumnSnapper.d.ts +14 -1
  60. package/types/src/modules/snapper/ScrollSnapper.d.ts +1 -0
  61. package/types/src/modules/snapper/Snapper.d.ts +58 -0
  62. package/types/src/modules/snapper/WebPubSnapper.d.ts +1 -0
  63. package/dist/ar-DyHX_uy2.js +0 -7
  64. package/dist/da-Dct0PS3E.js +0 -7
  65. package/dist/fr-C5HEel98.js +0 -7
  66. package/dist/index.umd.cjs +0 -96
  67. package/dist/it-DFOBoXGy.js +0 -7
  68. package/dist/pt_PT-Di3sVjze.js +0 -7
  69. package/dist/sv-BfzAFsVN.js +0 -7
  70. package/src/helpers/color.ts +0 -268
  71. package/src/helpers/sML.ts +0 -143
  72. package/types/src/helpers/color.d.ts +0 -27
  73. package/types/src/helpers/sML.d.ts +0 -56
package/dist/index.js CHANGED
@@ -1,4601 +1 @@
1
- const Ye = Math.pow(2, 32), Zt = () => Math.round(Math.random() * Ye).toString(36), Xe = () => `${Math.round(performance.now())}-${Zt()}-${Zt()}`, et = 1;
2
- class Ke {
3
- constructor(t) {
4
- this.destination = null, this.registrar = /* @__PURE__ */ new Map(), this.origin = "", this.channelId = "", this.receiver = this.receive.bind(this), this.preLog = [], this.wnd = t, t.addEventListener("message", this.receiver);
5
- }
6
- receive(t) {
7
- if (t.source === null) throw Error("Event source is null");
8
- if (typeof t.data != "object") return;
9
- const e = t.data;
10
- if (!(!("_readium" in e) || !e._readium || e._readium <= 0)) {
11
- if (e.key === "_ping") {
12
- if (!this.destination) {
13
- if (this.destination = t.source, this.origin = t.origin, this.channelId = e._channel, e._readium !== et) {
14
- e._readium > et ? this.send("error", `received comms version ${e._readium} higher than ${et}`) : this.send("error", `received comms version ${e._readium} lower than ${et}`), this.destination = null, this.origin = "", this.channelId = "";
15
- return;
16
- }
17
- this.send("_pong", void 0), this.preLog.forEach((i) => this.send("log", i)), this.preLog = [];
18
- }
19
- return;
20
- } else if (this.channelId) {
21
- if (e._channel !== this.channelId || t.origin !== this.origin) return;
22
- } else
23
- return;
24
- this.handle(e);
25
- }
26
- }
27
- handle(t) {
28
- const e = this.registrar.get(t.key);
29
- if (!e || e.length === 0) {
30
- t.strict && this.send("_unhandled", t);
31
- return;
32
- }
33
- e.forEach((i) => i.cb(t.data, (s) => {
34
- this.send("_ack", s, t.id);
35
- }));
36
- }
37
- register(t, e, i) {
38
- Array.isArray(t) || (t = [t]), t.forEach((s) => {
39
- const n = this.registrar.get(s);
40
- if (n && n.length >= 0) {
41
- if (n.find((a) => a.module === e)) throw new Error(`Trying to register another callback for combination of event ${s} and module ${e}`);
42
- n.push({
43
- cb: i,
44
- module: e
45
- }), this.registrar.set(s, n);
46
- } else
47
- this.registrar.set(s, [{
48
- cb: i,
49
- module: e
50
- }]);
51
- });
52
- }
53
- unregister(t, e) {
54
- Array.isArray(t) || (t = [t]), t.forEach((i) => {
55
- const s = this.registrar.get(i);
56
- !s || s.length === 0 || s.splice(s.findIndex((n) => n.module === e), 1);
57
- });
58
- }
59
- unregisterAll(t) {
60
- this.registrar.forEach((e, i) => this.registrar.set(i, e.filter((s) => s.module !== t)));
61
- }
62
- log(...t) {
63
- this.destination ? this.send("log", t) : this.preLog.push(t);
64
- }
65
- get ready() {
66
- return !!this.destination;
67
- }
68
- destroy() {
69
- this.destination = null, this.channelId = "", this.preLog = [], this.registrar.clear(), this.wnd.removeEventListener("message", this.receiver);
70
- }
71
- send(t, e, i = void 0, s = []) {
72
- if (!this.destination) throw Error("Attempted to send comms message before destination has been initialized");
73
- const n = {
74
- _readium: et,
75
- _channel: this.channelId,
76
- id: i ?? Xe(),
77
- // scrict,
78
- key: t,
79
- data: e
80
- };
81
- try {
82
- this.destination.postMessage(n, {
83
- targetOrigin: this.origin,
84
- transfer: s
85
- });
86
- } catch (o) {
87
- if (s.length > 0) throw o;
88
- this.destination.postMessage(n, this.origin, s);
89
- }
90
- }
91
- }
92
- const v = class v {
93
- constructor(t) {
94
- this.uri = t;
95
- }
96
- /**
97
- * Parses an [AccessibilityProfile] from its RWPM JSON representation.
98
- */
99
- static deserialize(t) {
100
- if (!(!t || typeof t != "string"))
101
- return new v(t);
102
- }
103
- /**
104
- * Serializes an [AccessibilityProfile] to its RWPM JSON representation.
105
- */
106
- serialize() {
107
- return this.uri;
108
- }
109
- /**
110
- * Returns true if the profile is a WCAG Level A profile.
111
- */
112
- get isWCAGLevelA() {
113
- return this === v.EPUB_A11Y_10_WCAG_20_A || this === v.EPUB_A11Y_11_WCAG_20_A || this === v.EPUB_A11Y_11_WCAG_21_A || this === v.EPUB_A11Y_11_WCAG_22_A;
114
- }
115
- /**
116
- * Returns true if the profile is a WCAG Level AA profile.
117
- */
118
- get isWCAGLevelAA() {
119
- return this === v.EPUB_A11Y_10_WCAG_20_AA || this === v.EPUB_A11Y_11_WCAG_20_AA || this === v.EPUB_A11Y_11_WCAG_21_AA || this === v.EPUB_A11Y_11_WCAG_22_AA;
120
- }
121
- /**
122
- * Returns true if the profile is a WCAG Level AAA profile.
123
- */
124
- get isWCAGLevelAAA() {
125
- return this === v.EPUB_A11Y_10_WCAG_20_AAA || this === v.EPUB_A11Y_11_WCAG_20_AAA || this === v.EPUB_A11Y_11_WCAG_21_AAA || this === v.EPUB_A11Y_11_WCAG_22_AAA;
126
- }
127
- };
128
- v.EPUB_A11Y_10_WCAG_20_A = new v("http://www.idpf.org/epub/a11y/accessibility-20170105.html#wcag-a"), v.EPUB_A11Y_10_WCAG_20_AA = new v("http://www.idpf.org/epub/a11y/accessibility-20170105.html#wcag-aa"), v.EPUB_A11Y_10_WCAG_20_AAA = new v("http://www.idpf.org/epub/a11y/accessibility-20170105.html#wcag-aaa"), v.EPUB_A11Y_11_WCAG_20_A = new v("https://www.w3.org/TR/epub-a11y-11#wcag-2.0-a"), v.EPUB_A11Y_11_WCAG_20_AA = new v("https://www.w3.org/TR/epub-a11y-11#wcag-2.0-aa"), v.EPUB_A11Y_11_WCAG_20_AAA = new v("https://www.w3.org/TR/epub-a11y-11#wcag-2.0-aaa"), v.EPUB_A11Y_11_WCAG_21_A = new v("https://www.w3.org/TR/epub-a11y-11#wcag-2.1-a"), v.EPUB_A11Y_11_WCAG_21_AA = new v("https://www.w3.org/TR/epub-a11y-11#wcag-2.1-aa"), v.EPUB_A11Y_11_WCAG_21_AAA = new v("https://www.w3.org/TR/epub-a11y-11#wcag-2.1-aaa"), v.EPUB_A11Y_11_WCAG_22_A = new v("https://www.w3.org/TR/epub-a11y-11#wcag-2.2-a"), v.EPUB_A11Y_11_WCAG_22_AA = new v("https://www.w3.org/TR/epub-a11y-11#wcag-2.2-aa"), v.EPUB_A11Y_11_WCAG_22_AAA = new v("https://www.w3.org/TR/epub-a11y-11#wcag-2.2-aaa");
129
- let Jt = v;
130
- const S = class S {
131
- constructor(t) {
132
- this.value = t;
133
- }
134
- /**
135
- * Parses an [AccessMode] from its RWPM JSON representation.
136
- */
137
- static deserialize(t) {
138
- if (!(!t || typeof t != "string"))
139
- return new S(t);
140
- }
141
- /**
142
- * Serializes an [AccessMode] to its RWPM JSON representation.
143
- */
144
- serialize() {
145
- return this.value;
146
- }
147
- };
148
- S.AUDITORY = new S("auditory"), S.CHART_ON_VISUAL = new S("chartOnVisual"), S.CHEM_ON_VISUAL = new S("chemOnVisual"), S.COLOR_DEPENDENT = new S("colorDependent"), S.DIAGRAM_ON_VISUAL = new S("diagramOnVisual"), S.MATH_ON_VISUAL = new S("mathOnVisual"), S.MUSIC_ON_VISUAL = new S("musicOnVisual"), S.TACTILE = new S("tactile"), S.TEXT_ON_VISUAL = new S("textOnVisual"), S.TEXTUAL = new S("textual"), S.VISUAL = new S("visual");
149
- let jt = S;
150
- const L = class L {
151
- constructor(t) {
152
- if (typeof t == "string") {
153
- if (!L.VALID_MODES.has(t.toLowerCase()))
154
- return;
155
- this.value = t.toLowerCase();
156
- } else {
157
- const e = t.filter(
158
- (i) => L.VALID_MODES.has(i.toLowerCase())
159
- );
160
- if (e.length === 0)
161
- return;
162
- this.value = Array.from(new Set(e));
163
- }
164
- }
165
- /**
166
- * Parses a [PrimaryAccessMode] from its RWPM JSON representation.
167
- */
168
- static deserialize(t) {
169
- if (!t) return;
170
- if (typeof t == "string")
171
- return new L(t);
172
- if (!Array.isArray(t)) return;
173
- const e = t.filter((i) => i ? L.VALID_MODES.has(i.toLowerCase()) : !1);
174
- if (e.length !== 0)
175
- return new L(e);
176
- }
177
- /**
178
- * Serializes a [PrimaryAccessMode] to its RWPM JSON representation.
179
- */
180
- serialize() {
181
- return this.value;
182
- }
183
- };
184
- L.VALID_MODES = /* @__PURE__ */ new Set(["auditory", "tactile", "textual", "visual"]), L.AUDITORY = new L("auditory"), L.TACTILE = new L("tactile"), L.TEXTUAL = new L("textual"), L.VISUAL = new L("visual");
185
- let Qt = L;
186
- const p = class p {
187
- constructor(t) {
188
- this.value = t;
189
- }
190
- /**
191
- * Parses a [Feature] from its RWPM JSON representation.
192
- */
193
- static deserialize(t) {
194
- if (!(!t || typeof t != "string"))
195
- return new p(t);
196
- }
197
- /**
198
- * Serializes a [Feature] to its RWPM JSON representation.
199
- */
200
- serialize() {
201
- return this.value;
202
- }
203
- };
204
- p.NONE = new p("none"), p.ANNOTATIONS = new p("annotations"), p.ARIA = new p("ARIA"), p.INDEX = new p("index"), p.PAGE_BREAK_MARKERS = new p("pageBreakMarkers"), p.PAGE_NAVIGATION = new p("pageNavigation"), p.PRINT_PAGE_NUMBERS = new p("printPageNumbers"), p.READING_ORDER = new p("readingOrder"), p.STRUCTURAL_NAVIGATION = new p("structuralNavigation"), p.TABLE_OF_CONTENTS = new p("tableOfContents"), p.TAGGED_PDF = new p("taggedPDF"), p.ALTERNATIVE_TEXT = new p("alternativeText"), p.AUDIO_DESCRIPTION = new p("audioDescription"), p.CAPTIONS = new p("captions"), p.CLOSED_CAPTIONS = new p("closedCaptions"), p.DESCRIBED_MATH = new p("describedMath"), p.LONG_DESCRIPTION = new p("longDescription"), p.OPEN_CAPTIONS = new p("openCaptions"), p.SIGN_LANGUAGE = new p("signLanguage"), p.TRANSCRIPT = new p("transcript"), p.DISPLAY_TRANSFORMABILITY = new p("displayTransformability"), p.SYNCHRONIZED_AUDIO_TEXT = new p("synchronizedAudioText"), p.TIMING_CONTROL = new p("timingControl"), p.UNLOCKED = new p("unlocked"), p.CHEM_ML = new p("ChemML"), p.LATEX = new p("latex"), p.LATEX_CHEMISTRY = new p("latex-chemistry"), p.MATH_ML = new p("MathML"), p.MATH_ML_CHEMISTRY = new p("MathML-chemistry"), p.TTS_MARKUP = new p("ttsMarkup"), p.HIGH_CONTRAST_AUDIO = new p("highContrastAudio"), p.HIGH_CONTRAST_DISPLAY = new p("highContrastDisplay"), p.LARGE_PRINT = new p("largePrint"), p.BRAILLE = new p("braille"), p.TACTILE_GRAPHIC = new p("tactileGraphic"), p.TACTILE_OBJECT = new p("tactileObject"), p.FULL_RUBY_ANNOTATIONS = new p("fullRubyAnnotations"), p.HORIZONTAL_WRITING = new p("horizontalWriting"), p.RUBY_ANNOTATIONS = new p("rubyAnnotations"), p.VERTICAL_WRITING = new p("verticalWriting"), p.WITH_ADDITIONAL_WORD_SEGMENTATION = new p("withAdditionalWordSegmentation"), p.WITHOUT_ADDITIONAL_WORD_SEGMENTATION = new p("withoutAdditionalWordSegmentation");
205
- let te = p;
206
- const w = class w {
207
- constructor(t) {
208
- this.value = t;
209
- }
210
- /**
211
- * Parses a [Hazard] from its RWPM JSON representation.
212
- */
213
- static deserialize(t) {
214
- if (!(!t || typeof t != "string"))
215
- return new w(t);
216
- }
217
- /**
218
- * Serializes a [Hazard] to its RWPM JSON representation.
219
- */
220
- serialize() {
221
- return this.value;
222
- }
223
- };
224
- w.FLASHING = new w("flashing"), w.NO_FLASHING_HAZARD = new w("noFlashingHazard"), w.UNKNOWN_FLASHING_HAZARD = new w("unknownFlashingHazard"), w.MOTION_SIMULATION = new w("motionSimulation"), w.NO_MOTION_SIMULATION_HAZARD = new w("noMotionSimulationHazard"), w.UNKNOWN_MOTION_SIMULATION_HAZARD = new w("unknownMotionSimulationHazard"), w.SOUND = new w("sound"), w.NO_SOUND_HAZARD = new w("noSoundHazard"), w.UNKNOWN_SOUND_HAZARD = new w("unknownSoundHazard"), w.UNKNOWN = new w("unknown"), w.NONE = new w("none");
225
- let ee = w;
226
- const C = class C {
227
- constructor(t) {
228
- this.value = t;
229
- }
230
- /**
231
- * Parses an [Exemption] from its RWPM JSON representation.
232
- */
233
- static deserialize(t) {
234
- if (!(!t || typeof t != "string"))
235
- return new C(t);
236
- }
237
- /**
238
- * Serializes an [Exemption] to its RWPM JSON representation.
239
- */
240
- serialize() {
241
- return this.value;
242
- }
243
- };
244
- C.NONE = new C("none"), C.DOCUMENTED = new C("documented"), C.LEGAL = new C("legal"), C.TEMPORARY = new C("temporary"), C.TECHNICAL = new C("technical"), C.EAA_DISPROPORTIONATE_BURDEN = new C("eaa-disproportionate-burden"), C.EAA_FUNDAMENTAL_ALTERATION = new C("eaa-fundamental-alteration"), C.EAA_MICROENTERPRISE = new C("eaa-microenterprise"), C.EAA_TECHNICAL_IMPOSSIBILITY = new C("eaa-technical-impossibility"), C.EAA_TEMPORARY = new C("eaa-temporary");
245
- let ie = C;
246
- const se = ["en", "ar", "da", "fr", "it", "pt_PT", "sv"], Ze = /* @__PURE__ */ JSON.parse(`{"format":{"audiobook":"Audiobook","audiobookJSON":"Audiobook Manifest","cbz":"Comic Book Archive","divina":"Divina Publication","divinaJSON":"Divina Publication Manifest","epub":"EPUB","lcpa":"LCP Protected Audiobook","lcpdf":"LCP Protected PDF","lcpl":"LCP License Document","pdf":"PDF","rwp":"Readium Web Publication","rwpm":"Readium Web Publication Manifest","zab":"Audiobook Archive","zip":"ZIP Archive"},"kind":{"audiobook_one":"audiobook","audiobook_other":"audiobooks","book_one":"book","book_other":"books","comic_one":"comic","comic_other":"comics","document_one":"document","document_other":"documents"},"metadata":{"accessibility":{"display-guide":{"accessibility-summary":{"no-metadata":"No information is available","publisher-contact":"For more information about the accessibility of this product, please contact the publisher: ","title":"Accessibility summary"},"additional-accessibility-information":{"aria":{"compact":"ARIA roles included","descriptive":"Content is enhanced with ARIA roles to optimize organization and facilitate navigation"},"audio-descriptions":"Audio descriptions","braille":"Braille","color-not-sole-means-of-conveying-information":"Color is not the sole means of conveying information","dyslexia-readability":"Dyslexia readability","full-ruby-annotations":"Full ruby annotations","high-contrast-between-foreground-and-background-audio":"High contrast between foreground and background audio","high-contrast-between-text-and-background":"High contrast between foreground text and background","large-print":"Large print","page-breaks":{"compact":"Page breaks included","descriptive":"Page breaks included from the original print source"},"ruby-annotations":"Some Ruby annotations","sign-language":"Sign language","tactile-graphics":{"compact":"Tactile graphics included","descriptive":"Tactile graphics have been integrated to facilitate access to visual elements for blind people"},"tactile-objects":"Tactile 3D objects","text-to-speech-hinting":"Text-to-speech hinting provided","title":"Additional accessibility information","ultra-high-contrast-between-text-and-background":"Ultra high contrast between text and background","visible-page-numbering":"Visible page numbering","without-background-sounds":"Without background sounds"},"conformance":{"a":{"compact":"This publication meets minimum accessibility standards","descriptive":"The publication contains a conformance statement that it meets the EPUB Accessibility and WCAG 2 Level A standard"},"aa":{"compact":"This publication meets accepted accessibility standards","descriptive":"The publication contains a conformance statement that it meets the EPUB Accessibility and WCAG 2 Level AA standard"},"aaa":{"compact":"This publication exceeds accepted accessibility standards","descriptive":"The publication contains a conformance statement that it meets the EPUB Accessibility and WCAG 2 Level AAA standard"},"certifier":"The publication was certified by ","certifier-credentials":"The certifier's credential is ","details":{"certification-info":"The publication was certified on ","certifier-report":"For more information refer to the certifier's report","claim":"This publication claims to meet","epub-accessibility-1-0":"EPUB Accessibility 1.0","epub-accessibility-1-1":"EPUB Accessibility 1.1","level-a":"Level A","level-aa":"Level AA","level-aaa":"Level AAA","wcag-2-0":{"compact":"WCAG 2.0","descriptive":"Web Content Accessibility Guidelines (WCAG) 2.0"},"wcag-2-1":{"compact":"WCAG 2.1","descriptive":"Web Content Accessibility Guidelines (WCAG) 2.1"},"wcag-2-2":{"compact":"WCAG 2.2","descriptive":"Web Content Accessibility Guidelines (WCAG) 2.2"}},"details-title":"Detailed conformance information","no":"No information is available","title":"Conformance","unknown-standard":"Conformance to accepted standards for accessibility of this publication cannot be determined"},"hazards":{"flashing":{"compact":"Flashing content","descriptive":"The publication contains flashing content that can cause photosensitive seizures"},"flashing-none":{"compact":"No flashing hazards","descriptive":"The publication does not contain flashing content that can cause photosensitive seizures"},"flashing-unknown":{"compact":"Flashing hazards not known","descriptive":"The presence of flashing content that can cause photosensitive seizures could not be determined"},"motion":{"compact":"Motion simulation","descriptive":"The publication contains motion simulations that can cause motion sickness"},"motion-none":{"compact":"No motion simulation hazards","descriptive":"The publication does not contain motion simulations that can cause motion sickness"},"motion-unknown":{"compact":"Motion simulation hazards not known","descriptive":"The presence of motion simulations that can cause motion sickness could not be determined"},"no-metadata":"No information is available","none":{"compact":"No hazards","descriptive":"The publication contains no hazards"},"sound":{"compact":"Sounds","descriptive":"The publication contains sounds that can cause sensitivity issues"},"sound-none":{"compact":"No sound hazards","descriptive":"The publication does not contain sounds that can cause sensitivity issues"},"sound-unknown":{"compact":"Sound hazards not known","descriptive":"The presence of sounds that can cause sensitivity issues could not be determined"},"title":"Hazards","unknown":"The presence of hazards is unknown"},"legal-considerations":{"exempt":{"compact":"Claims an accessibility exemption in some jurisdictions","descriptive":"This publication claims an accessibility exemption in some jurisdictions"},"no-metadata":"No information is available","title":"Legal considerations"},"navigation":{"index":{"compact":"Index","descriptive":"Index with links to referenced entries"},"no-metadata":"No information is available","page-navigation":{"compact":"Go to page","descriptive":"Page list to go to pages from the print source version"},"structural":{"compact":"Headings","descriptive":"Elements such as headings, tables, etc for structured navigation"},"title":"Navigation","toc":{"compact":"Table of contents","descriptive":"Table of contents to all chapters of the text via links"}},"rich-content":{"accessible-chemistry-as-latex":{"compact":"Chemical formulas in LaTeX","descriptive":"Chemical formulas in accessible format (LaTeX)"},"accessible-chemistry-as-mathml":{"compact":"Chemical formulas in MathML","descriptive":"Chemical formulas in accessible format (MathML)"},"accessible-math-as-latex":{"compact":"Math as LaTeX","descriptive":"Math formulas in accessible format (LaTeX)"},"accessible-math-described":"Text descriptions of math are provided","closed-captions":{"compact":"Videos have closed captions","descriptive":"Videos included in publications have closed captions"},"extended-descriptions":"Information-rich images are described by extended descriptions","math-as-mathml":{"compact":"Math as MathML","descriptive":"Math formulas in accessible format (MathML)"},"open-captions":{"compact":"Videos have open captions","descriptive":"Videos included in publications have open captions"},"title":"Rich content","transcript":"Transcript(s) provided","unknown":"No information is available"},"ways-of-reading":{"nonvisual-reading":{"alt-text":{"compact":"Has alternative text","descriptive":"Has alternative text descriptions for images"},"no-metadata":"No information about nonvisual reading is available","none":{"compact":"Not readable in read aloud or dynamic braille","descriptive":"The content is not readable as read aloud speech or dynamic braille"},"not-fully":{"compact":"Not fully readable in read aloud or dynamic braille","descriptive":"Not all of the content will be readable as read aloud speech or dynamic braille"},"readable":{"compact":"Readable in read aloud or dynamic braille","descriptive":"All content can be read as read aloud speech or dynamic braille"}},"prerecorded-audio":{"complementary":{"compact":"Prerecorded audio clips","descriptive":"Prerecorded audio clips are embedded in the content"},"no-metadata":"No information about prerecorded audio is available","only":{"compact":"Prerecorded audio only","descriptive":"Audiobook with no text alternative"},"synchronized":{"compact":"Prerecorded audio synchronized with text","descriptive":"All the content is available as prerecorded audio synchronized with text"}},"title":"Ways of reading","visual-adjustments":{"modifiable":{"compact":"Appearance can be modified","descriptive":"Appearance of the text and page layout can be modified according to the capabilities of the reading system (font family and font size, spaces between paragraphs, sentences, words, and letters, as well as color of background and text)"},"unknown":"No information about appearance modifiability is available","unmodifiable":{"compact":"Appearance cannot be modified","descriptive":"Text and page layout cannot be modified as the reading experience is close to a print version, but reading systems can still provide zooming options"}}}}},"altIdentifier_one":"alternate identifier","altIdentifier_other":"alternate identifiers","artist_one":"artist","artist_other":"artists","author_one":"author","author_other":"authors","collection_one":"editorial collection","collection_other":"editorial collections","colorist_one":"colorist","colorist_other":"colorists","contributor_one":"contributor","contributor_other":"contributors","description":"description","duration":"duration","editor_one":"editor","editor_other":"editors","identifier_one":"identifier","identifier_other":"identifiers","illustrator_one":"illustrator","illustrator_other":"illustrators","imprint_one":"imprint","imprint_other":"imprints","inker_one":"inker","inker_other":"inkers","language_one":"language","language_other":"languages","letterer_one":"letterer","letterer_other":"letterers","modified":"modification date","narrator_one":"narrator","narrator_other":"narrators","numberOfPages":"print length","penciler_one":"penciler","penciler_other":"pencilers","published":"publication date","publisher_one":"publisher","publisher_other":"publishers","series_one":"series","series_other":"series","subject_one":"subject","subject_other":"subjects","subtitle":"subtitle","title":"title","translator_one":"translator","translator_other":"translators"}}`), Je = {
247
- publication: Ze
248
- }, ne = {
249
- fr: () => import("./fr-C5HEel98.js"),
250
- ar: () => import("./ar-DyHX_uy2.js"),
251
- da: () => import("./da-Dct0PS3E.js"),
252
- // 'el': () => import('@edrlab/thorium-locales/publication-metadata/el.json'),
253
- // 'et': () => import('@edrlab/thorium-locales/publication-metadata/et.json'),
254
- it: () => import("./it-DFOBoXGy.js"),
255
- pt_PT: () => import("./pt_PT-Di3sVjze.js"),
256
- sv: () => import("./sv-BfzAFsVN.js")
257
- // 'tr': () => import('@edrlab/thorium-locales/publication-metadata/tr.json'),
258
- // 'uk': () => import('@edrlab/thorium-locales/publication-metadata/uk.json')
259
- }, re = Je?.publication?.metadata?.accessibility?.["display-guide"] || {};
260
- class K {
261
- constructor() {
262
- this.currentLocaleCode = "en", this.locale = re, this.loadedLocales = {}, this.loadedLocales.en = re;
263
- }
264
- static getInstance() {
265
- return K.instance || (K.instance = new K()), K.instance;
266
- }
267
- /**
268
- * Loads a locale dynamically
269
- * @param localeCode BCP 47 language code (e.g., 'en', 'fr')
270
- * @returns Promise indicating if the locale was loaded successfully
271
- */
272
- async loadLocale(t) {
273
- if (!se.includes(t))
274
- return console.warn(`Locale '${t}' is not enabled`), !1;
275
- if (t in this.loadedLocales)
276
- return !0;
277
- try {
278
- if (!(t in ne))
279
- return console.warn(`Locale file not found for: ${t}`), !1;
280
- const s = (await ne[t]()).default?.publication?.metadata?.accessibility?.["display-guide"];
281
- return s ? (this.loadedLocales[t] = s, !0) : (console.warn(`No accessibility strings found in locale ${t}`), !1);
282
- } catch (e) {
283
- return console.warn(`Failed to load locale ${t}:`, e), !1;
284
- }
285
- }
286
- /**
287
- * Registers a new locale or updates an existing one
288
- * @param localeCode BCP 47 language code (e.g., 'en', 'fr-FR')
289
- * @param localeData The locale data to register
290
- */
291
- registerLocale(t, e) {
292
- if (!t || typeof t != "string")
293
- throw new Error("Locale code must be a non-empty string");
294
- this.loadedLocales[t] = e;
295
- }
296
- /**
297
- * Sets the current locale by language code, loading it dynamically if needed
298
- * @param localeCode BCP 47 language code (e.g., 'en', 'fr')
299
- * @returns Promise indicating if the locale was set successfully
300
- */
301
- async setLocale(t) {
302
- return t in this.loadedLocales || await this.loadLocale(t), t in this.loadedLocales ? (this.locale = this.loadedLocales[t], this.currentLocaleCode = t, !0) : (console.warn(`Locale '${t}' is not available`), !1);
303
- }
304
- /**
305
- * Gets the current locale code (BCP 47)
306
- */
307
- getCurrentLocale() {
308
- return this.currentLocaleCode;
309
- }
310
- /**
311
- * Gets a list of available locale codes
312
- */
313
- getAvailableLocales() {
314
- return se;
315
- }
316
- getNestedValue(t, e) {
317
- const i = e.split(".");
318
- let s = t;
319
- for (const n of i) {
320
- if (s == null)
321
- return;
322
- s = s[n];
323
- }
324
- return s;
325
- }
326
- /**
327
- * Gets a localized string by key
328
- * @param key The key for the string to retrieve
329
- * @returns The localized string as a [L10nString], or an empty string if not found
330
- */
331
- getString(t) {
332
- let e = this.getNestedValue(this.locale, t);
333
- return e === void 0 && this.currentLocaleCode !== "en" && (e = this.getNestedValue(this.loadedLocales.en, t)), e !== void 0 ? typeof e == "string" ? { compact: e, descriptive: e } : e : (console.warn(`Missing localization for key: ${t}`), { compact: "", descriptive: "" });
334
- }
335
- }
336
- K.getInstance();
337
- class Ut {
338
- /**
339
- * Creates a [Encryption].
340
- */
341
- constructor(t) {
342
- this.algorithm = t.algorithm, this.compression = t.compression, this.originalLength = t.originalLength, this.profile = t.profile, this.scheme = t.scheme;
343
- }
344
- /**
345
- * Parses a [Encryption] from its RWPM JSON representation.
346
- */
347
- static deserialize(t) {
348
- if (t && t.algorithm)
349
- return new Ut({
350
- algorithm: t.algorithm,
351
- compression: t.compression,
352
- originalLength: t.originalLength,
353
- profile: t.profile,
354
- scheme: t.scheme
355
- });
356
- }
357
- /**
358
- * Serializes a [Encryption] to its RWPM JSON representation.
359
- */
360
- serialize() {
361
- const t = { algorithm: this.algorithm };
362
- return this.compression !== void 0 && (t.compression = this.compression), this.originalLength !== void 0 && (t.originalLength = this.originalLength), this.profile !== void 0 && (t.profile = this.profile), this.scheme !== void 0 && (t.scheme = this.scheme), t;
363
- }
364
- }
365
- class z {
366
- constructor(t) {
367
- this.otherProperties = t;
368
- }
369
- get page() {
370
- return this.otherProperties.page;
371
- }
372
- /**
373
- * Creates a [Properties] from its RWPM JSON representation.
374
- */
375
- static deserialize(t) {
376
- if (t)
377
- return new z(t);
378
- }
379
- /**
380
- * Serializes a [Properties] to its RWPM JSON representation.
381
- */
382
- serialize() {
383
- return this.otherProperties;
384
- }
385
- /**
386
- * Makes a copy of this [Properties] after merging in the given additional other [properties].
387
- */
388
- add(t) {
389
- const e = Object.assign({}, this.otherProperties);
390
- for (const i in t)
391
- e[i] = t[i];
392
- return new z(e);
393
- }
394
- }
395
- Object.defineProperty(z.prototype, "encryption", {
396
- get: function() {
397
- return Ut.deserialize(this.otherProperties.encrypted);
398
- }
399
- });
400
- function je(r) {
401
- return r && Array.isArray(r) ? r : void 0;
402
- }
403
- function Le(r) {
404
- return r && typeof r == "string" ? [r] : je(r);
405
- }
406
- function oe(r) {
407
- return typeof r == "string" ? new Date(r) : void 0;
408
- }
409
- function pt(r) {
410
- return isNaN(r) ? void 0 : r;
411
- }
412
- function D(r) {
413
- return pt(r) !== void 0 && Math.sign(r) >= 0 ? r : void 0;
414
- }
415
- function Qe(r) {
416
- const t = new Array();
417
- return r.forEach((e) => t.push(e)), t;
418
- }
419
- class u {
420
- /** Creates a MediaType object. */
421
- constructor(t) {
422
- let e, i, s = t.mediaType.replace(/\s/g, "").split(";");
423
- const n = s[0].split("/");
424
- if (n.length === 2) {
425
- if (e = n[0].toLowerCase().trim(), i = n[1].toLowerCase().trim(), e.length === 0 || i.length === 0)
426
- throw new Error("Invalid media type");
427
- } else
428
- throw new Error("Invalid media type");
429
- const o = {};
430
- for (let d = 1; d < s.length; d++) {
431
- const f = s[d].split("=");
432
- if (f.length === 2) {
433
- const y = f[0].toLocaleLowerCase(), g = y === "charset" ? f[1].toUpperCase() : f[1];
434
- o[y] = g;
435
- }
436
- }
437
- const a = {}, l = Object.keys(o);
438
- l.sort((d, f) => d.localeCompare(f)), l.forEach((d) => a[d] = o[d]);
439
- let m = "";
440
- for (const d in a) {
441
- const f = a[d];
442
- m += `;${d}=${f}`;
443
- }
444
- const c = `${e}/${i}${m}`, h = a.encoding;
445
- this.string = c, this.type = e, this.subtype = i, this.parameters = a, this.encoding = h, this.name = t.name, this.fileExtension = t.fileExtension;
446
- }
447
- static parse(t) {
448
- return new u(t);
449
- }
450
- /** Structured syntax suffix, e.g. `+zip` in `application/epub+zip`.
451
- * Gives a hint on the underlying structure of this media type.
452
- * See. https://tools.ietf.org/html/rfc6838#section-4.2.8
453
- */
454
- get structuredSyntaxSuffix() {
455
- const t = this.subtype.split("+");
456
- return t.length > 1 ? `+${t[t.length - 1]}` : void 0;
457
- }
458
- /** Parameter values might or might not be case-sensitive, depending on the semantics of
459
- * the parameter name.
460
- * https://tools.ietf.org/html/rfc2616#section-3.7
461
- *
462
- * The character set names may be up to 40 characters taken from the printable characters
463
- * of US-ASCII. However, no distinction is made between use of upper and lower case
464
- * letters.
465
- * https://www.iana.org/assignments/character-sets/character-sets.xhtml
466
- */
467
- get charset() {
468
- return this.parameters.charset;
469
- }
470
- /** Returns whether the given `other` media type is included in this media type.
471
- * For example, `text/html` contains `text/html;charset=utf-8`.
472
- * - `other` must match the parameters in the `parameters` property, but extra parameters
473
- * are ignored.
474
- * - Order of parameters is ignored.
475
- * - Wildcards are supported, meaning that `image/*` contains `image/png`
476
- */
477
- contains(t) {
478
- const e = typeof t == "string" ? u.parse({ mediaType: t }) : t;
479
- if (!((this.type === "*" || this.type === e.type) && (this.subtype === "*" || this.subtype === e.subtype)))
480
- return !1;
481
- const i = new Set(
482
- Object.entries(this.parameters).map(([n, o]) => `${n}=${o}`)
483
- ), s = new Set(
484
- Object.entries(e.parameters).map(([n, o]) => `${n}=${o}`)
485
- );
486
- for (const n of Array.from(i.values()))
487
- if (!s.has(n))
488
- return !1;
489
- return !0;
490
- }
491
- /** Returns whether this media type and `other` are the same, ignoring parameters that
492
- * are not in both media types.
493
- * For example, `text/html` matches `text/html;charset=utf-8`, but `text/html;charset=ascii`
494
- * doesn't. This is basically like `contains`, but working in both direction.
495
- */
496
- matches(t) {
497
- const e = typeof t == "string" ? u.parse({ mediaType: t }) : t;
498
- return this.contains(e) || e.contains(this);
499
- }
500
- /**
501
- * Returns whether this media type matches any of the [others] media types.
502
- */
503
- matchesAny(...t) {
504
- for (const e of t)
505
- if (this.matches(e))
506
- return !0;
507
- return !1;
508
- }
509
- /** Checks the MediaType equals another one (comparing their string) */
510
- equals(t) {
511
- return this.string === t.string;
512
- }
513
- /** Returns whether this media type is structured as a ZIP archive. */
514
- get isZIP() {
515
- return this.matchesAny(
516
- u.ZIP,
517
- u.LCP_PROTECTED_AUDIOBOOK,
518
- u.LCP_PROTECTED_PDF
519
- ) || this.structuredSyntaxSuffix === "+zip";
520
- }
521
- /** Returns whether this media type is structured as a JSON file. */
522
- get isJSON() {
523
- return this.matchesAny(u.JSON) || this.structuredSyntaxSuffix === "+json";
524
- }
525
- /** Returns whether this media type is of an OPDS feed. */
526
- get isOPDS() {
527
- return this.matchesAny(
528
- u.OPDS1,
529
- u.OPDS1_ENTRY,
530
- u.OPDS2,
531
- u.OPDS2_PUBLICATION,
532
- u.OPDS_AUTHENTICATION
533
- ) || this.structuredSyntaxSuffix === "+json";
534
- }
535
- /** Returns whether this media type is of an HTML document. */
536
- get isHTML() {
537
- return this.matchesAny(u.HTML, u.XHTML);
538
- }
539
- /** Returns whether this media type is of a bitmap image, so excluding vectorial formats. */
540
- get isBitmap() {
541
- return this.matchesAny(
542
- u.AVIF,
543
- u.BMP,
544
- u.GIF,
545
- u.JPEG,
546
- u.PNG,
547
- u.TIFF,
548
- u.WEBP
549
- );
550
- }
551
- /** Returns whether this media type is of an audio clip. */
552
- get isAudio() {
553
- return this.type === "audio";
554
- }
555
- /** Returns whether this media type is of a video clip. */
556
- get isVideo() {
557
- return this.type === "video";
558
- }
559
- /** Returns whether this media type is of a Readium Web Publication Manifest. */
560
- get isRWPM() {
561
- return this.matchesAny(
562
- u.READIUM_AUDIOBOOK_MANIFEST,
563
- u.DIVINA_MANIFEST,
564
- u.READIUM_WEBPUB_MANIFEST
565
- );
566
- }
567
- /** Returns whether this media type is of a publication file. */
568
- get isPublication() {
569
- return this.matchesAny(
570
- u.READIUM_AUDIOBOOK,
571
- u.READIUM_AUDIOBOOK_MANIFEST,
572
- u.CBZ,
573
- u.DIVINA,
574
- u.DIVINA_MANIFEST,
575
- u.EPUB,
576
- u.LCP_PROTECTED_AUDIOBOOK,
577
- u.LCP_PROTECTED_PDF,
578
- u.LPF,
579
- u.PDF,
580
- u.W3C_WPUB_MANIFEST,
581
- u.READIUM_WEBPUB,
582
- u.READIUM_WEBPUB_MANIFEST,
583
- u.ZAB
584
- );
585
- }
586
- // Known Media Types
587
- static get AAC() {
588
- return u.parse({ mediaType: "audio/aac", fileExtension: "aac" });
589
- }
590
- static get ACSM() {
591
- return u.parse({
592
- mediaType: "application/vnd.adobe.adept+xml",
593
- name: "Adobe Content Server Message",
594
- fileExtension: "acsm"
595
- });
596
- }
597
- static get AIFF() {
598
- return u.parse({ mediaType: "audio/aiff", fileExtension: "aiff" });
599
- }
600
- static get AVI() {
601
- return u.parse({
602
- mediaType: "video/x-msvideo",
603
- fileExtension: "avi"
604
- });
605
- }
606
- static get AVIF() {
607
- return u.parse({ mediaType: "image/avif", fileExtension: "avif" });
608
- }
609
- static get BINARY() {
610
- return u.parse({ mediaType: "application/octet-stream" });
611
- }
612
- static get BMP() {
613
- return u.parse({ mediaType: "image/bmp", fileExtension: "bmp" });
614
- }
615
- static get CBZ() {
616
- return u.parse({
617
- mediaType: "application/vnd.comicbook+zip",
618
- name: "Comic Book Archive",
619
- fileExtension: "cbz"
620
- });
621
- }
622
- static get CSS() {
623
- return u.parse({ mediaType: "text/css", fileExtension: "css" });
624
- }
625
- static get DIVINA() {
626
- return u.parse({
627
- mediaType: "application/divina+zip",
628
- name: "Digital Visual Narratives",
629
- fileExtension: "divina"
630
- });
631
- }
632
- static get DIVINA_MANIFEST() {
633
- return u.parse({
634
- mediaType: "application/divina+json",
635
- name: "Digital Visual Narratives",
636
- fileExtension: "json"
637
- });
638
- }
639
- static get EPUB() {
640
- return u.parse({
641
- mediaType: "application/epub+zip",
642
- name: "EPUB",
643
- fileExtension: "epub"
644
- });
645
- }
646
- static get GIF() {
647
- return u.parse({ mediaType: "image/gif", fileExtension: "gif" });
648
- }
649
- static get GZ() {
650
- return u.parse({
651
- mediaType: "application/gzip",
652
- fileExtension: "gz"
653
- });
654
- }
655
- static get HTML() {
656
- return u.parse({ mediaType: "text/html", fileExtension: "html" });
657
- }
658
- static get JAVASCRIPT() {
659
- return u.parse({
660
- mediaType: "text/javascript",
661
- fileExtension: "js"
662
- });
663
- }
664
- static get JPEG() {
665
- return u.parse({ mediaType: "image/jpeg", fileExtension: "jpeg" });
666
- }
667
- static get JSON() {
668
- return u.parse({ mediaType: "application/json" });
669
- }
670
- static get LCP_LICENSE_DOCUMENT() {
671
- return u.parse({
672
- mediaType: "application/vnd.readium.lcp.license.v1.0+json",
673
- name: "LCP License",
674
- fileExtension: "lcpl"
675
- });
676
- }
677
- static get LCP_PROTECTED_AUDIOBOOK() {
678
- return u.parse({
679
- mediaType: "application/audiobook+lcp",
680
- name: "LCP Protected Audiobook",
681
- fileExtension: "lcpa"
682
- });
683
- }
684
- static get LCP_PROTECTED_PDF() {
685
- return u.parse({
686
- mediaType: "application/pdf+lcp",
687
- name: "LCP Protected PDF",
688
- fileExtension: "lcpdf"
689
- });
690
- }
691
- static get LCP_STATUS_DOCUMENT() {
692
- return u.parse({
693
- mediaType: "application/vnd.readium.license.status.v1.0+json"
694
- });
695
- }
696
- static get LPF() {
697
- return u.parse({
698
- mediaType: "application/lpf+zip",
699
- fileExtension: "lpf"
700
- });
701
- }
702
- static get MP3() {
703
- return u.parse({ mediaType: "audio/mpeg", fileExtension: "mp3" });
704
- }
705
- static get MPEG() {
706
- return u.parse({ mediaType: "video/mpeg", fileExtension: "mpeg" });
707
- }
708
- static get NCX() {
709
- return u.parse({
710
- mediaType: "application/x-dtbncx+xml",
711
- fileExtension: "ncx"
712
- });
713
- }
714
- static get OGG() {
715
- return u.parse({ mediaType: "audio/ogg", fileExtension: "oga" });
716
- }
717
- static get OGV() {
718
- return u.parse({ mediaType: "video/ogg", fileExtension: "ogv" });
719
- }
720
- static get OPDS1() {
721
- return u.parse({
722
- mediaType: "application/atom+xml;profile=opds-catalog"
723
- });
724
- }
725
- static get OPDS1_ENTRY() {
726
- return u.parse({
727
- mediaType: "application/atom+xml;type=entry;profile=opds-catalog"
728
- });
729
- }
730
- static get OPDS2() {
731
- return u.parse({ mediaType: "application/opds+json" });
732
- }
733
- static get OPDS2_PUBLICATION() {
734
- return u.parse({ mediaType: "application/opds-publication+json" });
735
- }
736
- static get OPDS_AUTHENTICATION() {
737
- return u.parse({
738
- mediaType: "application/opds-authentication+json"
739
- });
740
- }
741
- static get OPUS() {
742
- return u.parse({ mediaType: "audio/opus", fileExtension: "opus" });
743
- }
744
- static get OTF() {
745
- return u.parse({ mediaType: "font/otf", fileExtension: "otf" });
746
- }
747
- static get PDF() {
748
- return u.parse({
749
- mediaType: "application/pdf",
750
- name: "PDF",
751
- fileExtension: "pdf"
752
- });
753
- }
754
- static get PNG() {
755
- return u.parse({ mediaType: "image/png", fileExtension: "png" });
756
- }
757
- static get READIUM_AUDIOBOOK() {
758
- return u.parse({
759
- mediaType: "application/audiobook+zip",
760
- name: "Readium Audiobook",
761
- fileExtension: "audiobook"
762
- });
763
- }
764
- static get READIUM_AUDIOBOOK_MANIFEST() {
765
- return u.parse({
766
- mediaType: "application/audiobook+json",
767
- name: "Readium Audiobook",
768
- fileExtension: "json"
769
- });
770
- }
771
- static get READIUM_CONTENT_DOCUMENT() {
772
- return u.parse({
773
- mediaType: "application/vnd.readium.content+json",
774
- name: "Readium Content Document",
775
- fileExtension: "json"
776
- });
777
- }
778
- static get READIUM_GUIDED_NAVIGATION_DOCUMENT() {
779
- return u.parse({
780
- mediaType: "application/guided-navigation+json",
781
- name: "Readium Guided Navigation Document",
782
- fileExtension: "json"
783
- });
784
- }
785
- static get READIUM_POSITION_LIST() {
786
- return u.parse({
787
- mediaType: "application/vnd.readium.position-list+json",
788
- name: "Readium Position List",
789
- fileExtension: "json"
790
- });
791
- }
792
- static get READIUM_WEBPUB() {
793
- return u.parse({
794
- mediaType: "application/webpub+zip",
795
- name: "Readium Web Publication",
796
- fileExtension: "webpub"
797
- });
798
- }
799
- static get READIUM_WEBPUB_MANIFEST() {
800
- return u.parse({
801
- mediaType: "application/webpub+json",
802
- name: "Readium Web Publication",
803
- fileExtension: "json"
804
- });
805
- }
806
- static get SMIL() {
807
- return u.parse({
808
- mediaType: "application/smil+xml",
809
- fileExtension: "smil"
810
- });
811
- }
812
- static get SVG() {
813
- return u.parse({
814
- mediaType: "image/svg+xml",
815
- fileExtension: "svg"
816
- });
817
- }
818
- static get TEXT() {
819
- return u.parse({ mediaType: "text/plain", fileExtension: "txt" });
820
- }
821
- static get TIFF() {
822
- return u.parse({ mediaType: "image/tiff", fileExtension: "tiff" });
823
- }
824
- static get TTF() {
825
- return u.parse({ mediaType: "font/ttf", fileExtension: "ttf" });
826
- }
827
- static get W3C_WPUB_MANIFEST() {
828
- return u.parse({
829
- mediaType: "application/x.readium.w3c.wpub+json",
830
- name: "Web Publication",
831
- fileExtension: "json"
832
- });
833
- }
834
- static get WAV() {
835
- return u.parse({ mediaType: "audio/wav", fileExtension: "wav" });
836
- }
837
- static get WEBM_AUDIO() {
838
- return u.parse({ mediaType: "audio/webm", fileExtension: "webm" });
839
- }
840
- static get WEBM_VIDEO() {
841
- return u.parse({ mediaType: "video/webm", fileExtension: "webm" });
842
- }
843
- static get WEBP() {
844
- return u.parse({ mediaType: "image/webp", fileExtension: "webp" });
845
- }
846
- static get WOFF() {
847
- return u.parse({ mediaType: "font/woff", fileExtension: "woff" });
848
- }
849
- static get WOFF2() {
850
- return u.parse({ mediaType: "font/woff2", fileExtension: "woff2" });
851
- }
852
- static get XHTML() {
853
- return u.parse({
854
- mediaType: "application/xhtml+xml",
855
- fileExtension: "xhtml"
856
- });
857
- }
858
- static get XML() {
859
- return u.parse({
860
- mediaType: "application/xml",
861
- fileExtension: "xml"
862
- });
863
- }
864
- static get ZAB() {
865
- return u.parse({
866
- mediaType: "application/x.readium.zab+zip",
867
- name: "Zipped Audio Book",
868
- fileExtension: "zab"
869
- });
870
- }
871
- static get ZIP() {
872
- return u.parse({
873
- mediaType: "application/zip",
874
- fileExtension: "zip"
875
- });
876
- }
877
- }
878
- class ae {
879
- constructor(t) {
880
- this.uri = t, this.parameters = this.getParameters(t);
881
- }
882
- /**
883
- * List of URI template parameter keys, if the [Link] is templated.
884
- */
885
- getParameters(t) {
886
- const e = /\{\??([^}]+)\}/g, i = t.match(e);
887
- return i ? new Set(
888
- i.join(",").replace(e, "$1").split(",").map((s) => s.trim())
889
- ) : /* @__PURE__ */ new Set();
890
- }
891
- /** Expands the URI by replacing the template variables by the given parameters.
892
- * Any extra parameter is appended as query parameters.
893
- * See RFC 6570 on URI template: https://tools.ietf.org/html/rfc6570
894
- */
895
- expand(t) {
896
- const e = (s) => s.split(",").map((n) => {
897
- const o = t[n];
898
- return o ? encodeURIComponent(o) : "";
899
- }).join(","), i = (s) => "?" + s.split(",").map((n) => {
900
- const o = n.split("=")[0], a = t[o];
901
- return a ? `${o}=${encodeURIComponent(a)}` : "";
902
- }).join("&");
903
- return this.uri.replace(/\{(\??)([^}]+)\}/g, (...s) => s[1] ? i(s[2]) : e(s[2]));
904
- }
905
- }
906
- class P {
907
- /**
908
- * Creates a [Locations].
909
- */
910
- constructor(t) {
911
- this.fragments = t.fragments ? t.fragments : new Array(), this.progression = t.progression, this.totalProgression = t.totalProgression, this.position = t.position, this.otherLocations = t.otherLocations;
912
- }
913
- /**
914
- * Parses a [Locations] from its RWPM JSON representation.
915
- */
916
- static deserialize(t) {
917
- if (!t) return;
918
- const e = pt(t.progression), i = pt(t.totalProgression), s = pt(t.position), n = /* @__PURE__ */ new Map(), o = /* @__PURE__ */ new Set([
919
- "fragment",
920
- "fragments",
921
- "progression",
922
- "totalProgression",
923
- "position"
924
- ]);
925
- return Object.entries(t).forEach(([a, l]) => {
926
- o.has(a) || n.set(a, l);
927
- }), new P({
928
- fragments: Le(t.fragments || t.fragment),
929
- progression: e !== void 0 && e >= 0 && e <= 1 ? e : void 0,
930
- totalProgression: i !== void 0 && i >= 0 && i <= 1 ? i : void 0,
931
- position: s !== void 0 && s > 0 ? s : void 0,
932
- otherLocations: n.size === 0 ? void 0 : n
933
- });
934
- }
935
- /**
936
- * Serializes a [Locations] to its RWPM JSON representation.
937
- */
938
- serialize() {
939
- const t = {};
940
- return this.fragments && (t.fragments = this.fragments), this.progression !== void 0 && (t.progression = this.progression), this.totalProgression !== void 0 && (t.totalProgression = this.totalProgression), this.position !== void 0 && (t.position = this.position), this.otherLocations && this.otherLocations.forEach((e, i) => t[i] = e), t;
941
- }
942
- }
943
- class $ {
944
- /**
945
- * Creates a [Text].
946
- */
947
- constructor(t) {
948
- this.after = t.after, this.before = t.before, this.highlight = t.highlight;
949
- }
950
- /**
951
- * Parses a [Locations] from its RWPM JSON representation.
952
- */
953
- static deserialize(t) {
954
- if (t)
955
- return new $({
956
- after: t.after,
957
- before: t.before,
958
- highlight: t.highlight
959
- });
960
- }
961
- /**
962
- * Serializes a [Locations] to its RWPM JSON representation.
963
- */
964
- serialize() {
965
- const t = {};
966
- return this.after !== void 0 && (t.after = this.after), this.before !== void 0 && (t.before = this.before), this.highlight !== void 0 && (t.highlight = this.highlight), t;
967
- }
968
- }
969
- class B {
970
- /**
971
- * Creates a [Locator].
972
- */
973
- constructor(t) {
974
- this.href = t.href, this.type = t.type, this.title = t.title, this.locations = t.locations ? t.locations : new P({}), this.text = t.text;
975
- }
976
- /**
977
- * Parses a [Link] from its RWPM JSON representation.
978
- */
979
- static deserialize(t) {
980
- if (t && t.href && t.type)
981
- return new B({
982
- href: t.href,
983
- type: t.type,
984
- title: t.title,
985
- locations: P.deserialize(t.locations),
986
- text: $.deserialize(t.text)
987
- });
988
- }
989
- /**
990
- * Serializes a [Link] to its RWPM JSON representation.
991
- */
992
- serialize() {
993
- const t = { href: this.href, type: this.type };
994
- return this.title !== void 0 && (t.title = this.title), this.locations && (t.locations = this.locations.serialize()), this.text && (t.text = this.text.serialize()), t;
995
- }
996
- /**
997
- * Shortcut to get a copy of the [Locator] with different [Locations] sub-properties.
998
- */
999
- copyWithLocations(t) {
1000
- return new B({
1001
- href: this.href,
1002
- type: this.type,
1003
- title: this.title,
1004
- text: this.text,
1005
- locations: new P({ ...this.locations, ...t })
1006
- });
1007
- }
1008
- }
1009
- class j {
1010
- /**
1011
- * Creates a [Link].
1012
- */
1013
- constructor(t) {
1014
- this.href = t.href, this.templated = t.templated, this.type = t.type, this.title = t.title, this.rels = t.rels, this.properties = t.properties, this.height = t.height, this.width = t.width, this.size = t.size, this.duration = t.duration, this.bitrate = t.bitrate, this.languages = t.languages, this.alternates = t.alternates, this.children = t.children;
1015
- }
1016
- /**
1017
- * Parses a [Link] from its RWPM JSON representation.
1018
- */
1019
- static deserialize(t) {
1020
- if (!(!t || typeof t.href != "string"))
1021
- return new j({
1022
- href: t.href,
1023
- templated: t.templated,
1024
- type: t.type,
1025
- title: t.title,
1026
- rels: t.rel ? Array.isArray(t.rel) ? new Set(t.rel) : /* @__PURE__ */ new Set([t.rel]) : void 0,
1027
- properties: z.deserialize(t.properties),
1028
- height: D(t.height),
1029
- width: D(t.width),
1030
- size: D(t.size),
1031
- duration: D(t.duration),
1032
- bitrate: D(t.bitrate),
1033
- languages: Le(t.language),
1034
- alternates: mt.deserialize(t.alternate),
1035
- children: mt.deserialize(t.children)
1036
- });
1037
- }
1038
- /**
1039
- * Serializes a [Link] to its RWPM JSON representation.
1040
- */
1041
- serialize() {
1042
- const t = { href: this.href };
1043
- return this.templated !== void 0 && (t.templated = this.templated), this.type !== void 0 && (t.type = this.type), this.title !== void 0 && (t.title = this.title), this.rels && (t.rel = Qe(this.rels)), this.properties && (t.properties = this.properties.serialize()), this.height !== void 0 && (t.height = this.height), this.width !== void 0 && (t.width = this.width), this.size !== void 0 && (t.size = this.size), this.duration !== void 0 && (t.duration = this.duration), this.bitrate !== void 0 && (t.bitrate = this.bitrate), this.languages && (t.language = this.languages), this.alternates && (t.alternate = this.alternates.serialize()), this.children && (t.children = this.children.serialize()), t;
1044
- }
1045
- /** MediaType of the linked resource. */
1046
- get mediaType() {
1047
- return this.type !== void 0 ? u.parse({ mediaType: this.type }) : u.BINARY;
1048
- }
1049
- /** Computes an absolute URL to the link, relative to the given `baseURL`.
1050
- * If the link's `href` is already absolute, the `baseURL` is ignored.
1051
- */
1052
- toURL(t) {
1053
- const e = this.href.replace(/^(\/)/, "");
1054
- if (e.length === 0) return;
1055
- let i = t || "/";
1056
- return i.startsWith("/") && (i = "file://" + i), new URL(e, i).href.replace(/^(file:\/\/)/, "");
1057
- }
1058
- /** List of URI template parameter keys, if the `Link` is templated. */
1059
- get templateParameters() {
1060
- return this.templated ? new ae(this.href).parameters : /* @__PURE__ */ new Set();
1061
- }
1062
- /** Expands the `Link`'s HREF by replacing URI template variables by the given parameters.
1063
- * See RFC 6570 on URI template: https://tools.ietf.org/html/rfc6570
1064
- */
1065
- expandTemplate(t) {
1066
- return new j({
1067
- href: new ae(this.href).expand(t),
1068
- templated: !1
1069
- });
1070
- }
1071
- /**
1072
- * Makes a copy of this [Link] after merging in the given additional other [properties].
1073
- */
1074
- addProperties(t) {
1075
- const e = j.deserialize(this.serialize());
1076
- return e.properties = e.properties ? e.properties?.add(t) : new z(t), e;
1077
- }
1078
- /**
1079
- * Creates a [Locator] from a reading order [Link].
1080
- */
1081
- get locator() {
1082
- let t = this.href.split("#");
1083
- return new B({
1084
- href: t.length > 0 && t[0] !== void 0 ? t[0] : this.href,
1085
- type: this.type ?? "",
1086
- title: this.title,
1087
- locations: new P({
1088
- fragments: t.length > 1 && t[1] !== void 0 ? [t[1]] : []
1089
- })
1090
- });
1091
- }
1092
- }
1093
- class mt {
1094
- /**
1095
- * Creates a [Links].
1096
- */
1097
- constructor(t) {
1098
- this.items = t;
1099
- }
1100
- /**
1101
- * Creates a list of [Link] from its RWPM JSON representation.
1102
- */
1103
- static deserialize(t) {
1104
- if (t && Array.isArray(t))
1105
- return new mt(
1106
- t.map((e) => j.deserialize(e)).filter((e) => e !== void 0)
1107
- );
1108
- }
1109
- /**
1110
- * Serializes an array of [Link] to its RWPM JSON representation.
1111
- */
1112
- serialize() {
1113
- return this.items.map((t) => t.serialize());
1114
- }
1115
- /** Finds the first link with the given relation. */
1116
- findWithRel(t) {
1117
- const e = (i) => i.rels && i.rels.has(t);
1118
- return this.items.find(e);
1119
- }
1120
- /** Finds all the links with the given relation. */
1121
- filterByRel(t) {
1122
- const e = (i) => i.rels && i.rels.has(t);
1123
- return this.items.filter(e);
1124
- }
1125
- /** Finds the first link matching the given HREF. */
1126
- findWithHref(t) {
1127
- const e = (i) => i.href === t;
1128
- return this.items.find(e);
1129
- }
1130
- /** Finds the index of the first link matching the given HREF. */
1131
- findIndexWithHref(t) {
1132
- const e = (i) => i.href === t;
1133
- return this.items.findIndex(e);
1134
- }
1135
- /** Finds the first link matching the given media type. */
1136
- findWithMediaType(t) {
1137
- const e = (i) => i.mediaType.matches(t);
1138
- return this.items.find(e);
1139
- }
1140
- /** Finds all the links matching the given media type. */
1141
- filterByMediaType(t) {
1142
- const e = (i) => i.mediaType.matches(t);
1143
- return this.items.filter(e);
1144
- }
1145
- /** Finds all the links matching any of the given media types. */
1146
- filterByMediaTypes(t) {
1147
- const e = (i) => {
1148
- for (const s of t)
1149
- if (i.mediaType.matches(s))
1150
- return !0;
1151
- return !1;
1152
- };
1153
- return this.items.filter(e);
1154
- }
1155
- /** Returns whether all the resources in the collection are audio clips. */
1156
- everyIsAudio() {
1157
- const t = (e) => e.mediaType.isAudio;
1158
- return this.items.length > 0 && this.items.every(t);
1159
- }
1160
- /** Returns whether all the resources in the collection are bitmaps. */
1161
- everyIsBitmap() {
1162
- const t = (e) => e.mediaType.isBitmap;
1163
- return this.items.length > 0 && this.items.every(t);
1164
- }
1165
- /** Returns whether all the resources in the collection are HTML documents. */
1166
- everyIsHTML() {
1167
- const t = (e) => e.mediaType.isHTML;
1168
- return this.items.length > 0 && this.items.every(t);
1169
- }
1170
- /** Returns whether all the resources in the collection are video clips. */
1171
- everyIsVideo() {
1172
- const t = (e) => e.mediaType.isVideo;
1173
- return this.items.length > 0 && this.items.every(t);
1174
- }
1175
- /** Returns whether all the resources in the collection are matching any of the given media types. */
1176
- everyMatchesMediaType(t) {
1177
- return Array.isArray(t) ? this.items.length > 0 && this.items.every((e) => {
1178
- for (const i of t)
1179
- return e.mediaType.matches(i);
1180
- return !1;
1181
- }) : this.items.length > 0 && this.items.every((e) => e.mediaType.matches(t));
1182
- }
1183
- filterLinksHasType() {
1184
- return this.items.filter((t) => t.type);
1185
- }
1186
- }
1187
- z.prototype.getContains = function() {
1188
- return new Set(this.otherProperties.contains || []);
1189
- };
1190
- class ft {
1191
- /**
1192
- * Creates a [DomRange].
1193
- */
1194
- constructor(t) {
1195
- this.cssSelector = t.cssSelector, this.textNodeIndex = t.textNodeIndex, this.charOffset = t.charOffset;
1196
- }
1197
- /**
1198
- * Parses a [DomRangePoint] from its RWPM JSON representation.
1199
- */
1200
- static deserialize(t) {
1201
- if (!(t && t.cssSelector)) return;
1202
- let e = D(t.textNodeIndex);
1203
- if (e === void 0) return;
1204
- let i = D(t.charOffset);
1205
- return i === void 0 && (i = D(t.offset)), new ft({
1206
- cssSelector: t.cssSelector,
1207
- textNodeIndex: e,
1208
- charOffset: i
1209
- });
1210
- }
1211
- /**
1212
- * Serializes a [DomRangePoint] to its RWPM JSON representation.
1213
- */
1214
- serialize() {
1215
- const t = {
1216
- cssSelector: this.cssSelector,
1217
- textNodeIndex: this.textNodeIndex
1218
- };
1219
- return this.charOffset !== void 0 && (t.charOffset = this.charOffset), t;
1220
- }
1221
- }
1222
- class _t {
1223
- /**
1224
- * Creates a [DomRange].
1225
- */
1226
- constructor(t) {
1227
- this.start = t.start, this.end = t.end;
1228
- }
1229
- /**
1230
- * Parses a [DomRange] from its RWPM JSON representation.
1231
- */
1232
- static deserialize(t) {
1233
- if (!t) return;
1234
- let e = ft.deserialize(t.start);
1235
- if (e)
1236
- return new _t({
1237
- start: e,
1238
- end: ft.deserialize(t.end)
1239
- });
1240
- }
1241
- /**
1242
- * Serializes a [DomRange] to its RWPM JSON representation.
1243
- */
1244
- serialize() {
1245
- const t = { start: this.start.serialize() };
1246
- return this.end && (t.end = this.end.serialize()), t;
1247
- }
1248
- }
1249
- P.prototype.getCssSelector = function() {
1250
- return this.otherLocations?.get("cssSelector");
1251
- };
1252
- P.prototype.getPartialCfi = function() {
1253
- return this.otherLocations?.get("partialCfi");
1254
- };
1255
- P.prototype.getDomRange = function() {
1256
- return _t.deserialize(this.otherLocations?.get("domRange"));
1257
- };
1258
- P.prototype.fragmentParameters = function() {
1259
- return new Map(
1260
- this.fragments.map((r) => r.startsWith("#") ? r.slice(1) : r).join("&").split("&").filter((r) => !r.startsWith("#")).map((r) => r.split("=")).filter((r) => r.length === 2).map((r) => [
1261
- r[0].trim().toLowerCase(),
1262
- r[1].trim()
1263
- ])
1264
- );
1265
- };
1266
- P.prototype.htmlId = function() {
1267
- if (!this.fragments.length) return;
1268
- let r = this.fragments.find((t) => t.length && !t.includes("="));
1269
- if (!r) {
1270
- const t = this.fragmentParameters();
1271
- t.has("id") ? r = t.get("id") : t.has("name") && (r = t.get("name"));
1272
- }
1273
- return r?.startsWith("#") ? r.slice(1) : r;
1274
- };
1275
- P.prototype.page = function() {
1276
- const r = parseInt(this.fragmentParameters().get("page"));
1277
- if (!isNaN(r) && r >= 0) return r;
1278
- };
1279
- P.prototype.time = function() {
1280
- const r = parseInt(this.fragmentParameters().get("t"));
1281
- if (!isNaN(r)) return r;
1282
- };
1283
- P.prototype.space = function() {
1284
- const r = this.fragmentParameters();
1285
- if (!r.has("xywh")) return;
1286
- const t = r.get("xywh").split(",").map((e) => parseInt(e));
1287
- if (t.length === 4 && !t.some(isNaN))
1288
- return t;
1289
- };
1290
- class Ft {
1291
- /** Creates a [Price]. */
1292
- constructor(t) {
1293
- this.currency = t.currency, this.value = t.value;
1294
- }
1295
- /**
1296
- * Parses a [Price] from its RWPM JSON representation.
1297
- */
1298
- static deserialize(t) {
1299
- if (!t) return;
1300
- let e = t.currency;
1301
- if (!(e && typeof e == "string" && e.length > 0))
1302
- return;
1303
- let i = D(t.value);
1304
- if (i !== void 0)
1305
- return new Ft({ currency: e, value: i });
1306
- }
1307
- /**
1308
- * Serializes a [Price] to its RWPM JSON representation.
1309
- */
1310
- serialize() {
1311
- return { currency: this.currency, value: this.value };
1312
- }
1313
- }
1314
- class st {
1315
- /** Creates a [Acquisition]. */
1316
- constructor(t) {
1317
- this.type = t.type, this.children = t.children;
1318
- }
1319
- /**
1320
- * Parses a [Acquisition] from its RWPM JSON representation.
1321
- */
1322
- static deserialize(t) {
1323
- if (t && t.type)
1324
- return new st({
1325
- type: t.type,
1326
- children: st.deserializeArray(t.children)
1327
- });
1328
- }
1329
- static deserializeArray(t) {
1330
- if (Array.isArray(t))
1331
- return t.map((e) => st.deserialize(e)).filter((e) => e !== void 0);
1332
- }
1333
- /**
1334
- * Serializes a [Acquisition] to its RWPM JSON representation.
1335
- */
1336
- serialize() {
1337
- const t = { type: this.type };
1338
- return this.children && (t.children = this.children.map((e) => e.serialize())), t;
1339
- }
1340
- }
1341
- class Vt {
1342
- /** Creates a [Price]. */
1343
- constructor(t) {
1344
- this.total = t.total, this.position = t.position;
1345
- }
1346
- /**
1347
- * Parses a [Holds] from its RWPM JSON representation.
1348
- */
1349
- static deserialize(t) {
1350
- if (t)
1351
- return new Vt({
1352
- total: D(t.total),
1353
- position: D(t.position)
1354
- });
1355
- }
1356
- /**
1357
- * Serializes a [Holds] to its RWPM JSON representation.
1358
- */
1359
- serialize() {
1360
- const t = {};
1361
- return this.total !== void 0 && (t.total = this.total), this.position !== void 0 && (t.position = this.position), t;
1362
- }
1363
- }
1364
- class $t {
1365
- /** Creates a [Copies]. */
1366
- constructor(t) {
1367
- this.total = t.total, this.available = t.available;
1368
- }
1369
- /**
1370
- * Parses a [Copies] from its RWPM JSON representation.
1371
- */
1372
- static deserialize(t) {
1373
- if (t)
1374
- return new $t({
1375
- total: D(t.total),
1376
- available: D(t.available)
1377
- });
1378
- }
1379
- /**
1380
- * Serializes a [Copies] to its RWPM JSON representation.
1381
- */
1382
- serialize() {
1383
- const t = {};
1384
- return this.total !== void 0 && (t.total = this.total), this.available !== void 0 && (t.available = this.available), t;
1385
- }
1386
- }
1387
- class Gt {
1388
- /** Creates a [Availability]. */
1389
- constructor(t) {
1390
- this.state = t.state, this.since = t.since, this.until = t.until;
1391
- }
1392
- /**
1393
- * Parses a [Availability] from its RWPM JSON representation.
1394
- */
1395
- static deserialize(t) {
1396
- if (t && t.state)
1397
- return new Gt({
1398
- state: t.state,
1399
- since: oe(t.since),
1400
- until: oe(t.until)
1401
- });
1402
- }
1403
- /**
1404
- * Serializes a [Availability] to its RWPM JSON representation.
1405
- */
1406
- serialize() {
1407
- const t = { state: this.state };
1408
- return this.since !== void 0 && (t.since = this.since.toISOString()), this.until !== void 0 && (t.until = this.until.toISOString()), t;
1409
- }
1410
- }
1411
- z.prototype.getNumberOfItems = function() {
1412
- return D(this.otherProperties.numberOfItems);
1413
- };
1414
- z.prototype.getPrice = function() {
1415
- return Ft.deserialize(this.otherProperties.price);
1416
- };
1417
- z.prototype.getIndirectAcquisitions = function() {
1418
- const r = this.otherProperties.indirectAcquisition;
1419
- if (r && Array.isArray(r))
1420
- return r.map((t) => st.deserialize(t)).filter((t) => t !== void 0);
1421
- };
1422
- z.prototype.getHolds = function() {
1423
- return Vt.deserialize(this.otherProperties.holds);
1424
- };
1425
- z.prototype.getCopies = function() {
1426
- return $t.deserialize(this.otherProperties.copies);
1427
- };
1428
- z.prototype.getAvailability = function() {
1429
- return Gt.deserialize(this.otherProperties.availability);
1430
- };
1431
- z.prototype.getAuthenticate = function() {
1432
- return j.deserialize(this.otherProperties.authenticate);
1433
- };
1434
- const ti = "CssSelectorGenerator";
1435
- function le(r = "unknown problem", ...t) {
1436
- console.warn(`${ti}: ${r}`, ...t);
1437
- }
1438
- function ei(r) {
1439
- return r instanceof RegExp;
1440
- }
1441
- function ii(r) {
1442
- return r.replace(/[|\\{}()[\]^$+?.]/g, "\\$&").replace(/\*/g, ".+");
1443
- }
1444
- function si(r) {
1445
- const t = r.map((e) => {
1446
- if (ei(e))
1447
- return (i) => e.test(i);
1448
- if (typeof e == "function")
1449
- return (i) => {
1450
- const s = e(i);
1451
- return typeof s != "boolean" ? (le("pattern matcher function invalid", "Provided pattern matching function does not return boolean. It's result will be ignored.", e), !1) : s;
1452
- };
1453
- if (typeof e == "string") {
1454
- const i = new RegExp("^" + ii(e) + "$");
1455
- return (s) => i.test(s);
1456
- }
1457
- return le("pattern matcher invalid", "Pattern matching only accepts strings, regular expressions and/or functions. This item is invalid and will be ignored.", e), () => !1;
1458
- });
1459
- return (e) => t.some((i) => i(e));
1460
- }
1461
- si([
1462
- "class",
1463
- "id",
1464
- // Angular attributes
1465
- "ng-*"
1466
- ]);
1467
- class tt {
1468
- }
1469
- function ce(r) {
1470
- return r.split("").reverse().join("");
1471
- }
1472
- function ni(r, t, e) {
1473
- const i = ce(t);
1474
- return e.map((s) => {
1475
- const n = Math.max(0, s.end - t.length - s.errors), o = ce(r.slice(n, s.end));
1476
- return {
1477
- start: Oe(o, i, s.errors).reduce((l, m) => s.end - m.end < l ? s.end - m.end : l, s.end),
1478
- end: s.end,
1479
- errors: s.errors
1480
- };
1481
- });
1482
- }
1483
- function At(r) {
1484
- return (r | -r) >> 31 & 1;
1485
- }
1486
- function he(r, t, e, i) {
1487
- let s = r.P[e], n = r.M[e];
1488
- const o = i >>> 31, a = t[e] | o, l = a | n, m = (a & s) + s ^ s | a;
1489
- let c = n | ~(m | s), h = s & m;
1490
- const d = At(c & r.lastRowMask[e]) - At(h & r.lastRowMask[e]);
1491
- return c <<= 1, h <<= 1, h |= o, c |= At(i) - o, s = h | ~(l | c), n = c & l, r.P[e] = s, r.M[e] = n, d;
1492
- }
1493
- function Oe(r, t, e) {
1494
- if (t.length === 0)
1495
- return [];
1496
- e = Math.min(e, t.length);
1497
- const i = [], s = 32, n = Math.ceil(t.length / s) - 1, o = {
1498
- P: new Uint32Array(n + 1),
1499
- M: new Uint32Array(n + 1),
1500
- lastRowMask: new Uint32Array(n + 1)
1501
- };
1502
- o.lastRowMask.fill(1 << 31), o.lastRowMask[n] = 1 << (t.length - 1) % s;
1503
- const a = new Uint32Array(n + 1), l = /* @__PURE__ */ new Map(), m = [];
1504
- for (let d = 0; d < 256; d++)
1505
- m.push(a);
1506
- for (let d = 0; d < t.length; d += 1) {
1507
- const f = t.charCodeAt(d);
1508
- if (l.has(f))
1509
- continue;
1510
- const y = new Uint32Array(n + 1);
1511
- l.set(f, y), f < m.length && (m[f] = y);
1512
- for (let g = 0; g <= n; g += 1) {
1513
- y[g] = 0;
1514
- for (let b = 0; b < s; b += 1) {
1515
- const N = g * s + b;
1516
- if (N >= t.length)
1517
- continue;
1518
- t.charCodeAt(N) === f && (y[g] |= 1 << b);
1519
- }
1520
- }
1521
- }
1522
- let c = Math.max(0, Math.ceil(e / s) - 1);
1523
- const h = new Uint32Array(n + 1);
1524
- for (let d = 0; d <= c; d += 1)
1525
- h[d] = (d + 1) * s;
1526
- h[n] = t.length;
1527
- for (let d = 0; d <= c; d += 1)
1528
- o.P[d] = -1, o.M[d] = 0;
1529
- for (let d = 0; d < r.length; d += 1) {
1530
- const f = r.charCodeAt(d);
1531
- let y;
1532
- f < m.length ? y = m[f] : (y = l.get(f), typeof y > "u" && (y = a));
1533
- let g = 0;
1534
- for (let b = 0; b <= c; b += 1)
1535
- g = he(o, y, b, g), h[b] += g;
1536
- if (h[c] - g <= e && c < n && (y[c + 1] & 1 || g < 0)) {
1537
- c += 1, o.P[c] = -1, o.M[c] = 0;
1538
- let b;
1539
- if (c === n) {
1540
- const N = t.length % s;
1541
- b = N === 0 ? s : N;
1542
- } else
1543
- b = s;
1544
- h[c] = h[c - 1] + b - g + he(o, y, c, g);
1545
- } else
1546
- for (; c > 0 && h[c] >= e + s; )
1547
- c -= 1;
1548
- c === n && h[c] <= e && (h[c] < e && i.splice(0, i.length), i.push({
1549
- start: -1,
1550
- end: d + 1,
1551
- errors: h[c]
1552
- }), e = h[c]);
1553
- }
1554
- return i;
1555
- }
1556
- function ri(r, t, e) {
1557
- const i = Oe(r, t, e);
1558
- return ni(r, t, i);
1559
- }
1560
- function Re(r, t, e) {
1561
- let i = 0;
1562
- const s = [];
1563
- for (; i !== -1; )
1564
- i = r.indexOf(t, i), i !== -1 && (s.push({
1565
- start: i,
1566
- end: i + t.length,
1567
- errors: 0
1568
- }), i += 1);
1569
- return s.length > 0 ? s : ri(r, t, e);
1570
- }
1571
- function de(r, t) {
1572
- return t.length === 0 || r.length === 0 ? 0 : 1 - Re(r, t, t.length)[0].errors / t.length;
1573
- }
1574
- function oi(r, t, e = {}) {
1575
- if (t.length === 0)
1576
- return null;
1577
- const i = Math.min(256, t.length / 2), s = Re(r, t, i);
1578
- if (s.length === 0)
1579
- return null;
1580
- const n = (a) => {
1581
- const d = 1 - a.errors / t.length, f = e.prefix ? de(
1582
- r.slice(
1583
- Math.max(0, a.start - e.prefix.length),
1584
- a.start
1585
- ),
1586
- e.prefix
1587
- ) : 1, y = e.suffix ? de(
1588
- r.slice(a.end, a.end + e.suffix.length),
1589
- e.suffix
1590
- ) : 1;
1591
- let g = 1;
1592
- return typeof e.hint == "number" && (g = 1 - Math.abs(a.start - e.hint) / r.length), (50 * d + 20 * f + 20 * y + 2 * g) / 92;
1593
- }, o = s.map((a) => ({
1594
- start: a.start,
1595
- end: a.end,
1596
- score: n(a)
1597
- }));
1598
- return o.sort((a, l) => l.score - a.score), o[0];
1599
- }
1600
- function Nt(r, t, e) {
1601
- const i = e === 1 ? t : t - 1;
1602
- if (r.charAt(i).trim() !== "")
1603
- return t;
1604
- let s, n;
1605
- if (e === 2 ? (s = r.substring(0, t), n = s.trimEnd()) : (s = r.substring(t), n = s.trimStart()), !n.length)
1606
- return -1;
1607
- const o = s.length - n.length;
1608
- return e === 2 ? t - o : t + o;
1609
- }
1610
- function ue(r, t) {
1611
- const e = r.commonAncestorContainer.ownerDocument.createNodeIterator(
1612
- r.commonAncestorContainer,
1613
- NodeFilter.SHOW_TEXT
1614
- ), i = t === 1 ? r.startContainer : r.endContainer, s = t === 1 ? r.endContainer : r.startContainer;
1615
- let n = e.nextNode();
1616
- for (; n && n !== i; )
1617
- n = e.nextNode();
1618
- t === 2 && (n = e.previousNode());
1619
- let o = -1;
1620
- const a = () => {
1621
- if (n = t === 1 ? e.nextNode() : e.previousNode(), n) {
1622
- const l = n.textContent, m = t === 1 ? 0 : l.length;
1623
- o = Nt(l, m, t);
1624
- }
1625
- };
1626
- for (; n && o === -1 && n !== s; )
1627
- a();
1628
- if (n && o >= 0)
1629
- return { node: n, offset: o };
1630
- throw new RangeError("No text nodes with non-whitespace text found in range");
1631
- }
1632
- function ai(r) {
1633
- if (!r.toString().trim().length)
1634
- throw new RangeError("Range contains no non-whitespace text");
1635
- if (r.startContainer.nodeType !== Node.TEXT_NODE)
1636
- throw new RangeError("Range startContainer is not a text node");
1637
- if (r.endContainer.nodeType !== Node.TEXT_NODE)
1638
- throw new RangeError("Range endContainer is not a text node");
1639
- const t = r.cloneRange();
1640
- let e = !1, i = !1;
1641
- const s = {
1642
- start: Nt(
1643
- r.startContainer.textContent,
1644
- r.startOffset,
1645
- 1
1646
- /* Forwards */
1647
- ),
1648
- end: Nt(
1649
- r.endContainer.textContent,
1650
- r.endOffset,
1651
- 2
1652
- /* Backwards */
1653
- )
1654
- };
1655
- if (s.start >= 0 && (t.setStart(r.startContainer, s.start), e = !0), s.end > 0 && (t.setEnd(r.endContainer, s.end), i = !0), e && i)
1656
- return t;
1657
- if (!e) {
1658
- const { node: n, offset: o } = ue(
1659
- t,
1660
- 1
1661
- /* Forwards */
1662
- );
1663
- n && o >= 0 && t.setStart(n, o);
1664
- }
1665
- if (!i) {
1666
- const { node: n, offset: o } = ue(
1667
- t,
1668
- 2
1669
- /* Backwards */
1670
- );
1671
- n && o > 0 && t.setEnd(n, o);
1672
- }
1673
- return t;
1674
- }
1675
- function ke(r) {
1676
- switch (r.nodeType) {
1677
- case Node.ELEMENT_NODE:
1678
- case Node.TEXT_NODE:
1679
- return r.textContent?.length ?? 0;
1680
- default:
1681
- return 0;
1682
- }
1683
- }
1684
- function pe(r) {
1685
- let t = r.previousSibling, e = 0;
1686
- for (; t; )
1687
- e += ke(t), t = t.previousSibling;
1688
- return e;
1689
- }
1690
- function Ie(r, ...t) {
1691
- let e = t.shift();
1692
- const i = r.ownerDocument.createNodeIterator(
1693
- r,
1694
- NodeFilter.SHOW_TEXT
1695
- ), s = [];
1696
- let n = i.nextNode(), o, a = 0;
1697
- for (; e !== void 0 && n; )
1698
- o = n, a + o.data.length > e ? (s.push({ node: o, offset: e - a }), e = t.shift()) : (n = i.nextNode(), a += o.data.length);
1699
- for (; e !== void 0 && o && a === e; )
1700
- s.push({ node: o, offset: o.data.length }), e = t.shift();
1701
- if (e !== void 0)
1702
- throw new RangeError("Offset exceeds text length");
1703
- return s;
1704
- }
1705
- class H {
1706
- constructor(t, e) {
1707
- if (e < 0)
1708
- throw new Error("Offset is invalid");
1709
- this.element = t, this.offset = e;
1710
- }
1711
- /**
1712
- * Return a copy of this position with offset relative to a given ancestor
1713
- * element.
1714
- *
1715
- * @param parent - Ancestor of `this.element`
1716
- */
1717
- relativeTo(t) {
1718
- if (!t.contains(this.element))
1719
- throw new Error("Parent is not an ancestor of current element");
1720
- let e = this.element, i = this.offset;
1721
- for (; e !== t; )
1722
- i += pe(e), e = e.parentElement;
1723
- return new H(e, i);
1724
- }
1725
- /**
1726
- * Resolve the position to a specific text node and offset within that node.
1727
- *
1728
- * Throws if `this.offset` exceeds the length of the element's text. In the
1729
- * case where the element has no text and `this.offset` is 0, the `direction`
1730
- * option determines what happens.
1731
- *
1732
- * Offsets at the boundary between two nodes are resolved to the start of the
1733
- * node that begins at the boundary.
1734
- *
1735
- * @param options.direction - Specifies in which direction to search for the
1736
- * nearest text node if `this.offset` is `0` and
1737
- * `this.element` has no text. If not specified an
1738
- * error is thrown.
1739
- *
1740
- * @throws {RangeError}
1741
- */
1742
- resolve(t = {}) {
1743
- try {
1744
- return Ie(this.element, this.offset)[0];
1745
- } catch (e) {
1746
- if (this.offset === 0 && t.direction !== void 0) {
1747
- const i = document.createTreeWalker(
1748
- this.element.getRootNode(),
1749
- NodeFilter.SHOW_TEXT
1750
- );
1751
- i.currentNode = this.element;
1752
- const s = t.direction === 1, n = s ? i.nextNode() : i.previousNode();
1753
- if (!n)
1754
- throw e;
1755
- return { node: n, offset: s ? 0 : n.data.length };
1756
- } else
1757
- throw e;
1758
- }
1759
- }
1760
- /**
1761
- * Construct a `TextPosition` that refers to the `offset`th character within
1762
- * `node`.
1763
- */
1764
- static fromCharOffset(t, e) {
1765
- switch (t.nodeType) {
1766
- case Node.TEXT_NODE:
1767
- return H.fromPoint(t, e);
1768
- case Node.ELEMENT_NODE:
1769
- return new H(t, e);
1770
- default:
1771
- throw new Error("Node is not an element or text node");
1772
- }
1773
- }
1774
- /**
1775
- * Construct a `TextPosition` representing the range start or end point (node, offset).
1776
- *
1777
- * @param node
1778
- * @param offset - Offset within the node
1779
- */
1780
- static fromPoint(t, e) {
1781
- switch (t.nodeType) {
1782
- case Node.TEXT_NODE: {
1783
- if (e < 0 || e > t.data.length)
1784
- throw new Error("Text node offset is out of range");
1785
- if (!t.parentElement)
1786
- throw new Error("Text node has no parent");
1787
- const i = pe(t) + e;
1788
- return new H(t.parentElement, i);
1789
- }
1790
- case Node.ELEMENT_NODE: {
1791
- if (e < 0 || e > t.childNodes.length)
1792
- throw new Error("Child node offset is out of range");
1793
- let i = 0;
1794
- for (let s = 0; s < e; s++)
1795
- i += ke(t.childNodes[s]);
1796
- return new H(t, i);
1797
- }
1798
- default:
1799
- throw new Error("Point is not in an element or text node");
1800
- }
1801
- }
1802
- }
1803
- class V {
1804
- constructor(t, e) {
1805
- this.start = t, this.end = e;
1806
- }
1807
- /**
1808
- * Create a new TextRange whose `start` and `end` are computed relative to
1809
- * `element`. `element` must be an ancestor of both `start.element` and
1810
- * `end.element`.
1811
- */
1812
- relativeTo(t) {
1813
- return new V(
1814
- this.start.relativeTo(t),
1815
- this.end.relativeTo(t)
1816
- );
1817
- }
1818
- /**
1819
- * Resolve this TextRange to a (DOM) Range.
1820
- *
1821
- * The resulting DOM Range will always start and end in a `Text` node.
1822
- * Hence `TextRange.fromRange(range).toRange()` can be used to "shrink" a
1823
- * range to the text it contains.
1824
- *
1825
- * May throw if the `start` or `end` positions cannot be resolved to a range.
1826
- */
1827
- toRange() {
1828
- let t, e;
1829
- this.start.element === this.end.element && this.start.offset <= this.end.offset ? [t, e] = Ie(
1830
- this.start.element,
1831
- this.start.offset,
1832
- this.end.offset
1833
- ) : (t = this.start.resolve({
1834
- direction: 1
1835
- /* FORWARDS */
1836
- }), e = this.end.resolve({
1837
- direction: 2
1838
- /* BACKWARDS */
1839
- }));
1840
- const i = new Range();
1841
- return i.setStart(t.node, t.offset), i.setEnd(e.node, e.offset), i;
1842
- }
1843
- /**
1844
- * Create a TextRange from a (DOM) Range
1845
- */
1846
- static fromRange(t) {
1847
- const e = H.fromPoint(
1848
- t.startContainer,
1849
- t.startOffset
1850
- ), i = H.fromPoint(t.endContainer, t.endOffset);
1851
- return new V(e, i);
1852
- }
1853
- /**
1854
- * Create a TextRange representing the `start`th to `end`th characters in
1855
- * `root`
1856
- */
1857
- static fromOffsets(t, e, i) {
1858
- return new V(
1859
- new H(t, e),
1860
- new H(t, i)
1861
- );
1862
- }
1863
- /**
1864
- * Return a new Range representing `range` trimmed of any leading or trailing
1865
- * whitespace
1866
- */
1867
- static trimmedRange(t) {
1868
- return ai(V.fromRange(t).toRange());
1869
- }
1870
- }
1871
- class gt {
1872
- constructor(t, e, i) {
1873
- this.root = t, this.start = e, this.end = i;
1874
- }
1875
- static fromRange(t, e) {
1876
- const i = V.fromRange(e).relativeTo(t);
1877
- return new gt(
1878
- t,
1879
- i.start.offset,
1880
- i.end.offset
1881
- );
1882
- }
1883
- static fromSelector(t, e) {
1884
- return new gt(t, e.start, e.end);
1885
- }
1886
- toSelector() {
1887
- return {
1888
- type: "TextPositionSelector",
1889
- start: this.start,
1890
- end: this.end
1891
- };
1892
- }
1893
- toRange() {
1894
- return V.fromOffsets(this.root, this.start, this.end).toRange();
1895
- }
1896
- }
1897
- class yt {
1898
- /**
1899
- * @param root - A root element from which to anchor.
1900
- */
1901
- constructor(t, e, i = {}) {
1902
- this.root = t, this.exact = e, this.context = i;
1903
- }
1904
- /**
1905
- * Create a `TextQuoteAnchor` from a range.
1906
- *
1907
- * Will throw if `range` does not contain any text nodes.
1908
- */
1909
- static fromRange(t, e) {
1910
- const i = t.textContent, s = V.fromRange(e).relativeTo(t), n = s.start.offset, o = s.end.offset, a = 32;
1911
- return new yt(t, i.slice(n, o), {
1912
- prefix: i.slice(Math.max(0, n - a), n),
1913
- suffix: i.slice(o, Math.min(i.length, o + a))
1914
- });
1915
- }
1916
- static fromSelector(t, e) {
1917
- const { prefix: i, suffix: s } = e;
1918
- return new yt(t, e.exact, { prefix: i, suffix: s });
1919
- }
1920
- toSelector() {
1921
- return {
1922
- type: "TextQuoteSelector",
1923
- exact: this.exact,
1924
- prefix: this.context.prefix,
1925
- suffix: this.context.suffix
1926
- };
1927
- }
1928
- toRange(t = {}) {
1929
- return this.toPositionAnchor(t).toRange();
1930
- }
1931
- toPositionAnchor(t = {}) {
1932
- const e = this.root.textContent, i = oi(e, this.exact, {
1933
- ...this.context,
1934
- hint: t.hint
1935
- });
1936
- if (!i)
1937
- throw new Error("Quote not found");
1938
- return new gt(this.root, i.start, i.end);
1939
- }
1940
- }
1941
- function li(r) {
1942
- const t = r.tagName.toUpperCase();
1943
- return t === "IMG" || t === "VIDEO" || t === "AUDIO" || t === "IFRAME" || t === "OBJECT" || t === "EMBED" || t === "CANVAS";
1944
- }
1945
- function ct(r, t) {
1946
- try {
1947
- const e = t.locations, i = t.text;
1948
- if (i && i.highlight) {
1949
- let s;
1950
- e && e.getCssSelector() && (s = r.querySelector(e.getCssSelector())), s || (s = r.body);
1951
- const n = new yt(s, i.highlight, {
1952
- prefix: i.before,
1953
- suffix: i.after
1954
- });
1955
- try {
1956
- return n.toRange();
1957
- } catch {
1958
- return console.warn("Quote not found:", n), null;
1959
- }
1960
- }
1961
- if (e) {
1962
- let s = null;
1963
- if (!s && e.getCssSelector() && (s = r.querySelector(e.getCssSelector())), !s && e.fragments) {
1964
- for (const n of e.fragments)
1965
- if (s = r.getElementById(n), s)
1966
- break;
1967
- }
1968
- if (s) {
1969
- const n = r.createRange();
1970
- return s.childNodes.length === 0 || li(s) ? (n.selectNode(s), n) : (n.setStartBefore(s), n.setEndAfter(s), n);
1971
- }
1972
- }
1973
- } catch (e) {
1974
- console.error(e);
1975
- }
1976
- return null;
1977
- }
1978
- function ci(r, t, e = !1) {
1979
- let i = r.getClientRects();
1980
- i.length || r.commonAncestorContainer.nodeType === Node.ELEMENT_NODE && (i = r.commonAncestorContainer.getClientRects());
1981
- const s = 1, n = [];
1982
- for (const c of i)
1983
- n.push({
1984
- bottom: c.bottom,
1985
- height: c.height,
1986
- left: c.left,
1987
- right: c.right,
1988
- top: c.top,
1989
- width: c.width
1990
- });
1991
- const o = De(
1992
- n,
1993
- s,
1994
- t,
1995
- e
1996
- ), a = di(o, s), l = ze(a), m = 4;
1997
- for (let c = l.length - 1; c >= 0; c--) {
1998
- const h = l[c];
1999
- if (!(h.width * h.height > m))
2000
- if (l.length > 1)
2001
- l.splice(c, 1);
2002
- else
2003
- break;
2004
- }
2005
- return l;
2006
- }
2007
- function De(r, t, e, i = !1) {
2008
- for (let s = 0; s < r.length; s++)
2009
- for (let n = s + 1; n < r.length; n++) {
2010
- const o = r[s], a = r[n];
2011
- if (o === a)
2012
- continue;
2013
- const l = M(o.top, a.top, t) && M(o.bottom, a.bottom, t), m = M(o.left, a.left, t) && M(o.right, a.right, t);
2014
- if (l && !m && Me(o, a, t)) {
2015
- const d = r.filter((y) => y !== o && y !== a), f = hi(o, a);
2016
- return d.push(f), De(
2017
- d,
2018
- t,
2019
- e,
2020
- i
2021
- );
2022
- }
2023
- }
2024
- return r;
2025
- }
2026
- function hi(r, t) {
2027
- const e = Math.min(r.left, t.left), i = Math.max(r.right, t.right), s = Math.min(r.top, t.top), n = Math.max(r.bottom, t.bottom);
2028
- return {
2029
- bottom: n,
2030
- height: n - s,
2031
- left: e,
2032
- right: i,
2033
- top: s,
2034
- width: i - e
2035
- };
2036
- }
2037
- function di(r, t) {
2038
- const e = new Set(r);
2039
- for (const i of r) {
2040
- if (!(i.width > 1 && i.height > 1)) {
2041
- e.delete(i);
2042
- continue;
2043
- }
2044
- for (const n of r)
2045
- if (i !== n && e.has(n) && ui(n, i, t)) {
2046
- e.delete(i);
2047
- break;
2048
- }
2049
- }
2050
- return Array.from(e);
2051
- }
2052
- function ui(r, t, e) {
2053
- return Z(r, t.left, t.top, e) && Z(r, t.right, t.top, e) && Z(r, t.left, t.bottom, e) && Z(r, t.right, t.bottom, e);
2054
- }
2055
- function Z(r, t, e, i) {
2056
- return (r.left < t || M(r.left, t, i)) && (r.right > t || M(r.right, t, i)) && (r.top < e || M(r.top, e, i)) && (r.bottom > e || M(r.bottom, e, i));
2057
- }
2058
- function ze(r) {
2059
- for (let t = 0; t < r.length; t++)
2060
- for (let e = t + 1; e < r.length; e++) {
2061
- const i = r[t], s = r[e];
2062
- if (i !== s && Me(i, s, -1)) {
2063
- let n = [], o;
2064
- const a = me(i, s);
2065
- if (a.length === 1)
2066
- n = a, o = i;
2067
- else {
2068
- const m = me(s, i);
2069
- a.length < m.length ? (n = a, o = i) : (n = m, o = s);
2070
- }
2071
- const l = r.filter((m) => m !== o);
2072
- return Array.prototype.push.apply(l, n), ze(l);
2073
- }
2074
- }
2075
- return r;
2076
- }
2077
- function me(r, t) {
2078
- const e = pi(t, r);
2079
- if (e.height === 0 || e.width === 0)
2080
- return [r];
2081
- const i = [];
2082
- {
2083
- const s = {
2084
- bottom: r.bottom,
2085
- height: 0,
2086
- left: r.left,
2087
- right: e.left,
2088
- top: r.top,
2089
- width: 0
2090
- };
2091
- s.width = s.right - s.left, s.height = s.bottom - s.top, s.height !== 0 && s.width !== 0 && i.push(s);
2092
- }
2093
- {
2094
- const s = {
2095
- bottom: e.top,
2096
- height: 0,
2097
- left: e.left,
2098
- right: e.right,
2099
- top: r.top,
2100
- width: 0
2101
- };
2102
- s.width = s.right - s.left, s.height = s.bottom - s.top, s.height !== 0 && s.width !== 0 && i.push(s);
2103
- }
2104
- {
2105
- const s = {
2106
- bottom: r.bottom,
2107
- height: 0,
2108
- left: e.left,
2109
- right: e.right,
2110
- top: e.bottom,
2111
- width: 0
2112
- };
2113
- s.width = s.right - s.left, s.height = s.bottom - s.top, s.height !== 0 && s.width !== 0 && i.push(s);
2114
- }
2115
- {
2116
- const s = {
2117
- bottom: r.bottom,
2118
- height: 0,
2119
- left: e.right,
2120
- right: r.right,
2121
- top: r.top,
2122
- width: 0
2123
- };
2124
- s.width = s.right - s.left, s.height = s.bottom - s.top, s.height !== 0 && s.width !== 0 && i.push(s);
2125
- }
2126
- return i;
2127
- }
2128
- function pi(r, t) {
2129
- const e = Math.max(r.left, t.left), i = Math.min(r.right, t.right), s = Math.max(r.top, t.top), n = Math.min(r.bottom, t.bottom);
2130
- return {
2131
- bottom: n,
2132
- height: Math.max(0, n - s),
2133
- left: e,
2134
- right: i,
2135
- top: s,
2136
- width: Math.max(0, i - e)
2137
- };
2138
- }
2139
- function Me(r, t, e) {
2140
- return (r.left < t.right || e >= 0 && M(r.left, t.right, e)) && (t.left < r.right || e >= 0 && M(t.left, r.right, e)) && (r.top < t.bottom || e >= 0 && M(r.top, t.bottom, e)) && (t.top < r.bottom || e >= 0 && M(t.top, r.bottom, e));
2141
- }
2142
- function M(r, t, e) {
2143
- return Math.abs(r - t) <= e;
2144
- }
2145
- const mi = /* @__PURE__ */ new Set([
2146
- "backgroundColor",
2147
- "textColor",
2148
- "linkColor",
2149
- "visitedColor",
2150
- "primaryColor",
2151
- "secondaryColor",
2152
- "selectionBackgroundColor",
2153
- "selectionTextColor",
2154
- "blendFilter",
2155
- "darkenFilter",
2156
- "invertFilter",
2157
- "invertGaiji"
2158
- ]), fe = /--(?:USER|RS)__([\w-]+)/g;
2159
- function fi(r, t) {
2160
- const e = r ?? "", i = t ?? "", s = /* @__PURE__ */ new Set();
2161
- for (const n of e.matchAll(fe)) s.add(n[1]);
2162
- for (const n of i.matchAll(fe)) s.add(n[1]);
2163
- for (const n of s)
2164
- if (!mi.has(n)) return !0;
2165
- return !1;
2166
- }
2167
- function qt(r) {
2168
- const t = {}, e = r.document.documentElement.style;
2169
- for (const i in r.document.documentElement.style)
2170
- Object.hasOwn(e, i) && !Number.isNaN(Number.parseInt(i)) && (t[e[i]] = e.getPropertyValue(e[i]));
2171
- return t;
2172
- }
2173
- function We(r, t) {
2174
- const e = qt(r);
2175
- Object.keys(e).forEach((i) => {
2176
- t.hasOwnProperty(i) || St(r, i);
2177
- }), Object.entries(t).forEach(([i, s]) => {
2178
- e[i] !== s && at(r, i, s);
2179
- });
2180
- }
2181
- function ge(r, t) {
2182
- return r.document.documentElement.style.getPropertyValue(t);
2183
- }
2184
- function at(r, t, e) {
2185
- r.document.documentElement.style.setProperty(t, e);
2186
- }
2187
- function St(r, t) {
2188
- r.document.documentElement.style.removeProperty(t);
2189
- }
2190
- let dt = null, Ct = null, it = 0;
2191
- const X = { r: 255, g: 255, b: 255, a: 1 }, Y = /* @__PURE__ */ new Map(), gi = () => {
2192
- if (!dt)
2193
- if (typeof OffscreenCanvas < "u")
2194
- dt = new OffscreenCanvas(5, 5), Ct = dt.getContext("2d", {
2195
- willReadFrequently: !0,
2196
- desynchronized: !0
2197
- });
2198
- else {
2199
- const r = document.createElement("canvas");
2200
- r.width = 5, r.height = 5, dt = r, Ct = r.getContext("2d", {
2201
- willReadFrequently: !0,
2202
- desynchronized: !0
2203
- });
2204
- }
2205
- return Ct;
2206
- }, yi = (r) => {
2207
- if (!r) return !0;
2208
- const t = r.trim().toLowerCase();
2209
- return t.startsWith("var(") || [
2210
- "transparent",
2211
- "currentcolor",
2212
- "inherit",
2213
- "initial",
2214
- "revert",
2215
- "unset",
2216
- "revert-layer"
2217
- ].includes(t) ? !0 : [
2218
- "linear-gradient",
2219
- "radial-gradient",
2220
- "conic-gradient",
2221
- "repeating-linear-gradient",
2222
- "repeating-radial-gradient",
2223
- "repeating-conic-gradient"
2224
- ].some((s) => t.includes(s));
2225
- }, ut = (r, t) => {
2226
- console.warn(
2227
- `[Decorator] Could not parse color: "${r}". ${t} Falling back to ${JSON.stringify(X)} to compute contrast. Please use a CSS color value that can be computed to RGB(A).`
2228
- );
2229
- }, lt = (r, t = null) => {
2230
- const e = t ? `${r}|${t}` : r, i = Y.get(e);
2231
- if (i !== void 0)
2232
- return i ?? X;
2233
- if (yi(r))
2234
- return ut(r, "Unsupported color format or special value."), Y.set(e, null), X;
2235
- const s = gi();
2236
- if (!s)
2237
- return ut(r, "Could not get canvas context."), Y.set(e, null), X;
2238
- try {
2239
- it === 0 && s.clearRect(0, 0, 5, 5);
2240
- const n = it % 5, o = Math.floor(it / 5);
2241
- s.clearRect(n, o, 1, 1), t && (s.fillStyle = t, s.fillRect(n, o, 1, 1)), s.fillStyle = r, s.fillRect(n, o, 1, 1);
2242
- const a = s.getImageData(n, o, 1, 1);
2243
- it = (it + 1) % 25;
2244
- const [l, m, c, h] = a.data;
2245
- if (h === 0)
2246
- return ut(r, "Fully transparent color."), Y.set(e, null), X;
2247
- const d = { r: l, g: m, b: c, a: h / 255 };
2248
- return Y.set(e, d), d;
2249
- } catch (n) {
2250
- return ut(r, `Error: ${n instanceof Error ? n.message : String(n)}`), Y.set(e, null), X;
2251
- }
2252
- }, xt = (r) => {
2253
- const t = r / 255;
2254
- return t <= 0.03928 ? t / 12.92 : Math.pow((t + 0.055) / 1.055, 2.4);
2255
- }, Lt = (r) => {
2256
- const t = xt(r.r), e = xt(r.g), i = xt(r.b);
2257
- return 0.2126 * t + 0.7152 * e + 0.0722 * i;
2258
- }, bt = (r, t) => {
2259
- const e = typeof r == "string" ? lt(r) : r, i = typeof t == "string" ? lt(t) : t, s = Lt(e), n = Lt(i), o = Math.max(s, n), a = Math.min(s, n);
2260
- return (o + 0.05) / (a + 0.05);
2261
- }, He = (r, t = null) => {
2262
- const e = lt(r, t), i = bt(e, { r: 255, g: 255, b: 255, a: 1 }), s = bt(e, { r: 0, g: 0, b: 0, a: 1 });
2263
- return i > s;
2264
- }, bi = (r, t = null) => He(r, t) ? "white" : "black", vi = (r) => {
2265
- const t = r.a !== void 0 ? r.a : 1;
2266
- return `rgba(${Math.round(r.r)}, ${Math.round(r.g)}, ${Math.round(r.b)}, ${t})`;
2267
- }, Si = (r, t) => ({
2268
- r: Math.min(255, r.r + (255 - r.r) * t),
2269
- g: Math.min(255, r.g + (255 - r.g) * t),
2270
- b: Math.min(255, r.b + (255 - r.b) * t),
2271
- a: r.a ?? 1
2272
- }), wi = (r, t) => ({
2273
- r: Math.max(0, r.r * (1 - t)),
2274
- g: Math.max(0, r.g * (1 - t)),
2275
- b: Math.max(0, r.b * (1 - t)),
2276
- a: r.a ?? 1
2277
- }), G = (r, t = null, e = 3) => {
2278
- const i = lt(r), s = t ? lt(t) : { r: 255, g: 255, b: 255, a: 1 };
2279
- let n = bt(i, s);
2280
- if (n >= e)
2281
- return r;
2282
- const a = Lt(s) < 0.5;
2283
- let l = { ...i, a: i.a ?? 1 };
2284
- const m = 20, c = 0.1;
2285
- for (let h = 0; h < m && (a ? l = Si(l, c) : l = wi(l, c), n = bt(l, s), !(n >= e)); h++)
2286
- ;
2287
- return vi(l);
2288
- };
2289
- function Ei(r) {
2290
- return (r.document.documentElement.dir || r.document.body.dir).toLowerCase() === "rtl";
2291
- }
2292
- function Be(r) {
2293
- return (r.getComputedStyle(r.document.documentElement).writingMode || r.getComputedStyle(r.document.body).writingMode) === "vertical-lr";
2294
- }
2295
- function Ai(r) {
2296
- const t = r.getComputedStyle(r.document.documentElement).writingMode || r.getComputedStyle(r.document.body).writingMode;
2297
- return t === "vertical-rl" || t === "vertical-lr";
2298
- }
2299
- function Tt(r) {
2300
- const t = Ai(r), e = t && Be(r), i = r.innerWidth, s = r.innerHeight, n = r.document.scrollingElement, o = n.scrollLeft, a = n.scrollTop, l = parseInt(r.getComputedStyle(r.document.documentElement).getPropertyValue("column-count")), m = t && !e ? n.scrollWidth - i + o : o, c = a;
2301
- return {
2302
- isVertical: t,
2303
- isVertLR: e,
2304
- viewportInlineSize: t ? s : i,
2305
- viewportBlockSize: t ? i : s,
2306
- pageInlineSize: t ? s : i / (l || 1),
2307
- xDocOffset: m,
2308
- yDocOffset: c,
2309
- inlineScrollOffset: t ? c : m,
2310
- blockScrollOffset: t ? m : c,
2311
- inlineStart: (h) => t ? h.top : h.left,
2312
- blockStart: (h) => t ? h.left : h.top,
2313
- inlineSize: (h) => t ? h.height : h.width,
2314
- blockSize: (h) => t ? h.width : h.height,
2315
- applyPosition(h, d, f, y, g, b) {
2316
- h.style.position = "absolute", t ? (h.style.top = `${d * b}px`, h.style.left = `${f * b}px`, h.style.height = `${y * b}px`, h.style.width = `${g * b}px`) : (h.style.left = `${d * b}px`, h.style.top = `${f * b}px`, h.style.width = `${y * b}px`, h.style.height = `${g * b}px`);
2317
- },
2318
- toRect(h, d, f, y) {
2319
- return t ? new DOMRect(d, h, y, f) : new DOMRect(h, d, f, y);
2320
- }
2321
- };
2322
- }
2323
- function Ue(r) {
2324
- return parseInt(
2325
- r.getComputedStyle(
2326
- r.document.documentElement
2327
- ).getPropertyValue("column-count")
2328
- );
2329
- }
2330
- function ye(r) {
2331
- const t = getComputedStyle(r), e = parseFloat(t.paddingTop || "0"), i = parseFloat(t.paddingBottom || "0");
2332
- return r.clientHeight - e - i;
2333
- }
2334
- function be(r) {
2335
- const t = Ue(r);
2336
- if (!t)
2337
- return !1;
2338
- const e = r.document.querySelectorAll("div[id^='readium-virtual-page']");
2339
- for (const m of e)
2340
- m.remove();
2341
- const i = e.length, s = r.document.scrollingElement.scrollWidth, n = r.visualViewport.width, a = Math.round(s / n * t) % t, l = t === 1 || a === 0 ? 0 : t - a;
2342
- if (l > 0)
2343
- for (let m = 0; m < l; m++) {
2344
- const c = r.document.createElement("div");
2345
- c.setAttribute("id", `readium-virtual-page-${m}`), c.dataset.readium = "true", CSS.supports("break-before", "column") ? c.style.breakBefore = "column" : (CSS.supports("break-inside", "avoid-column") && (c.style.breakInside = "avoid-column"), c.style.height = ye(r.document.documentElement) + "px"), c.innerHTML = "&#8203;", r.document.body.appendChild(c);
2346
- }
2347
- return i !== l;
2348
- }
2349
- function Yt(r) {
2350
- const t = r.document.createElement("style");
2351
- t.appendChild(r.document.createTextNode("*{}")), r.document.body.appendChild(t), r.document.body.removeChild(t);
2352
- }
2353
- const _e = () => typeof navigator > "u" ? "" : navigator.userAgent || "", Fe = () => typeof navigator > "u" ? void 0 : navigator.userAgentData || void 0;
2354
- class Ve {
2355
- constructor() {
2356
- const t = Fe(), e = _e(), i = (n) => (typeof n == "string" || typeof n == "number") && n ? String(n).replace(/_/g, ".").split(".").map((o) => parseInt(o) || 0) : [], s = (n = "") => {
2357
- if (!n) return [];
2358
- const o = new RegExp("^.*" + n + "[ :\\/]?(\\d+([\\._]\\d+)*).*$");
2359
- return o.test(e) ? i(e.replace(o, "$1")) : [];
2360
- };
2361
- this.OS = ((n) => (/(macOS|Mac OS X)/.test(e) ? (/\(iP(hone|od touch);/.test(e) && (n.iOS = s("CPU (?:iPhone )?OS ")), /\(iPad;/.test(e) ? n.iOS = n.iPadOS = s("CPU (?:iPhone )?OS ") : /(macOS|Mac OS X) \d/.test(e) && (document.ontouchend !== void 0 ? n.iOS = n.iPadOS = s() : n.macOS = s("(?:macOS|Mac OS X) "))) : /Windows( NT)? \d/.test(e) ? n.Windows = ((o) => o[0] !== 6 || !o[1] ? o : o[1] === 1 ? [7] : o[1] === 2 ? [8] : [8, 1])(s("Windows(?: NT)?")) : /Android \d/.test(e) ? n.Android = s("Android") : /CrOS/.test(e) ? n.ChromeOS = s() : /X11;/.test(e) && (n.Linux = s()), n))({}), t && t.getHighEntropyValues(["architecture", "model", "platform", "platformVersion", "uaFullVersion"]).then((n) => ((o) => {
2362
- const a = n.platform, l = n.platformVersion;
2363
- if (!(!a || !l)) {
2364
- if (/^i(OS|P(hone|od touch))$/.test(a)) o.iOS = i(l);
2365
- else if (/^iPad(OS)?$/.test(a)) o.iOS = o.iPadOS = i(l);
2366
- else if (/^(macOS|(Mac )?OS X|Mac(Intel)?)$/.test(a)) document.ontouchend !== void 0 ? o.iOS = o.iPadOS = i() : o.macOS = i(l);
2367
- else if (/^(Microsoft )?Windows$/.test(a)) o.Windows = i(l);
2368
- else if (/^(Google )?Android$/.test(a)) o.Android = i(l);
2369
- else if (/^((Google )?Chrome OS|CrOS)$/.test(a)) o.ChromeOS = i(l);
2370
- else if (/^(Linux|Ubuntu|X11)$/.test(a)) o.Linux = i(l);
2371
- else return;
2372
- Object.keys(this.OS).forEach((m) => delete this.OS[m]), Object.assign(this.OS, o);
2373
- }
2374
- })({})), this.UA = ((n) => {
2375
- let o = !1;
2376
- if (t && Array.isArray(t.brands)) {
2377
- const a = t.brands.reduce((l, m) => (l[m.brand] = [m.version * 1], l), {});
2378
- a["Google Chrome"] ? (o = !0, n.Blink = n.Chromium = a.Chromium || [], n.Chrome = a["Google Chrome"]) : a["Microsoft Edge"] ? (o = !0, n.Blink = n.Chromium = a.Chromium || [], n.Edge = a["Microsoft Edge"]) : a.Opera && (o = !0, n.Blink = n.Chromium = a.Chromium || [], n.Opera = a.Opera);
2379
- }
2380
- return o || (/ Gecko\/\d/.test(e) ? (n.Gecko = s("rv"), / Waterfox\/\d/.test(e) ? n.Waterfox = s("Waterfox") : / Firefox\/\d/.test(e) && (n.Firefox = s("Firefox"))) : / Edge\/\d/.test(e) ? (n.EdgeHTML = s("Edge"), n.Edge = n.EdgeHTML) : / Chrom(ium|e)\/\d/.test(e) ? (n.Blink = n.Chromium = ((a) => a[0] ? a : s("Chrome"))(s("Chromium")), / EdgA?\/\d/.test(e) ? n.Edge = ((a) => a[0] ? a : s("Edg"))(s("EdgA")) : / OPR\/\d/.test(e) ? n.Opera = s("OPR") : / Vivaldi\/\d/.test(e) ? n.Vivaldi = s("Vivaldi") : / Silk\/\d/.test(e) ? n.Silk = s("Silk") : / UCBrowser\/\d/.test(e) ? n.UCBrowser = s("UCBrowser") : / Phoebe\/\d/.test(e) ? n.Phoebe = s("Phoebe") : n.Chrome = ((a) => a[0] ? a : n.Chromium)(s("Chrome"))) : / AppleWebKit\/\d/.test(e) ? (n.WebKit = s("AppleWebKit"), / CriOS \d/.test(e) ? n.Chrome = s("CriOS") : / FxiOS \d/.test(e) ? n.Firefox = s("FxiOS") : / EdgiOS\/\d/.test(e) ? n.Edge = s("EdgiOS") : / Version\/\d/.test(e) && (n.Safari = s("Version"))) : / Trident\/\d/.test(e) && (n.Trident = s("Trident"), n.InternetExplorer = ((a) => a[0] ? a : s("MSIE"))(s("rv")))), /[\[; ]FB(AN|_IAB)\//.test(e) && (n.Facebook = s("FBAV")), / Line\/\d/.test(e) && (n.LINE = s("Line")), n;
2381
- })({}), this.Env = { get: () => [this.OS, this.UA].reduce((n, o) => {
2382
- for (const a in o) o[a] && n.push(a);
2383
- return n;
2384
- }, []) };
2385
- }
2386
- }
2387
- class Ci extends Ve {
2388
- get iOSRequest() {
2389
- const t = Fe(), e = _e();
2390
- if (this.OS.iOS && !this.OS.iPadOS)
2391
- return "mobile";
2392
- if (this.OS.iPadOS)
2393
- return /\(iPad;/.test(e) || t && /^iPad(OS)?$/.test(t.platform) ? "mobile" : "desktop";
2394
- }
2395
- }
2396
- const ve = new Ve(), Yi = new Ci(), Se = [
2397
- // Structure / presentation
2398
- "div",
2399
- "span",
2400
- "p",
2401
- "br",
2402
- "hr",
2403
- "b",
2404
- "i",
2405
- "em",
2406
- "strong",
2407
- "s",
2408
- "u",
2409
- "mark",
2410
- "small",
2411
- "sub",
2412
- "sup",
2413
- "abbr",
2414
- "cite",
2415
- "code",
2416
- "data",
2417
- "dfn",
2418
- "kbd",
2419
- "q",
2420
- "samp",
2421
- "time",
2422
- "var",
2423
- "blockquote",
2424
- "pre",
2425
- // SVG — useful for icon-style decorations (e.g. sidemarks)
2426
- "svg",
2427
- "g",
2428
- "path",
2429
- "circle",
2430
- "ellipse",
2431
- "rect",
2432
- "line",
2433
- "polygon",
2434
- "polyline",
2435
- "text",
2436
- "tspan",
2437
- "defs",
2438
- "use"
2439
- ], xi = /^on/i, Ti = /* @__PURE__ */ new Set(["href", "src", "action", "formaction", "xlink:href"]), Pi = /^\s*(javascript|data):/i;
2440
- function Ni(r, t) {
2441
- const e = r.document.createElement("div");
2442
- if ("Sanitizer" in r && typeof e.setHTML == "function")
2443
- try {
2444
- const s = new r.Sanitizer({ allowElements: Se });
2445
- return e.setHTML(t, { sanitizer: s }), e.firstElementChild;
2446
- } catch {
2447
- }
2448
- const i = r.document.implementation.createHTMLDocument("");
2449
- for (i.body.innerHTML = t, Li(i.body, new Set(Se)); i.body.firstChild; )
2450
- e.appendChild(r.document.adoptNode(i.body.firstChild));
2451
- return e.firstElementChild;
2452
- }
2453
- function Li(r, t) {
2454
- const e = Array.from(r.querySelectorAll("*")).reverse();
2455
- for (const i of e) {
2456
- if (!t.has(i.localName)) {
2457
- i.replaceWith(...Array.from(i.childNodes));
2458
- continue;
2459
- }
2460
- for (const { name: s, value: n } of Array.from(i.attributes))
2461
- (xi.test(s) || Ti.has(s) && Pi.test(n)) && i.removeAttribute(s);
2462
- }
2463
- }
2464
- function Pt(r) {
2465
- switch (r) {
2466
- case E.Mask:
2467
- return "rgba(255, 255, 255, 0.5)";
2468
- case E.Highlight:
2469
- return "#FFFF00";
2470
- default:
2471
- return "#FF0000";
2472
- }
2473
- }
2474
- const E = {
2475
- Highlight: "highlight",
2476
- // Background color overlay.
2477
- Underline: "underline",
2478
- // Underline drawn beneath the text.
2479
- Outline: "outline",
2480
- // Border drawn around the text boxes.
2481
- TextColor: "textColor",
2482
- // Changes the text color directly.
2483
- Mask: "mask",
2484
- // Dims everything outside the selection rects. Use width: Page for block-level behaviour.
2485
- Template: "template"
2486
- // Custom HTML template (HTMLDecorationTemplate).
2487
- };
2488
- var Oi = /* @__PURE__ */ ((r) => (r.Wrap = "wrap", r.Viewport = "viewport", r.Bounds = "bounds", r.Page = "page", r))(Oi || {}), Ri = /* @__PURE__ */ ((r) => (r.Boxes = "boxes", r.Bounds = "bounds", r))(Ri || {});
2489
- const ki = () => "Highlight" in window, we = ["IMG", "IMAGE", "AUDIO", "VIDEO", "SVG"];
2490
- class Ii {
2491
- /**
2492
- * Creates a DecorationGroup object
2493
- * @param id Unique HTML ID-adhering name of the group
2494
- * @param name Human-readable name of the group
2495
- */
2496
- constructor(t, e, i, s) {
2497
- this.wnd = t, this.comms = e, this.id = i, this.name = s, this.items = [], this.lastItemId = 0, this.container = void 0, this._activatable = !1, this.experimentalHighlights = !1, this.maskSvg = void 0, this.shadowHost = void 0, this.shadowRoot = void 0, this.currentRender = 0, ki() && (this.experimentalHighlights = !0, this.notTextFlag = /* @__PURE__ */ new Map()), this.activationHandler = this.handleActivation.bind(this), this.wnd.document.addEventListener("pointerup", this.activationHandler);
2498
- }
2499
- get activatable() {
2500
- return this._activatable;
2501
- }
2502
- set activatable(t) {
2503
- this._activatable = t;
2504
- }
2505
- /**
2506
- * Adds a new decoration to the group.
2507
- * @param decoration Decoration to add
2508
- */
2509
- add(t) {
2510
- const e = `${this.id}-${this.lastItemId++}`, i = ct(this.wnd.document, t.locator);
2511
- if (!i) {
2512
- this.comms.log("Can't locate DOM range for decoration", t);
2513
- return;
2514
- }
2515
- const s = i.commonAncestorContainer;
2516
- if (s.nodeType !== Node.TEXT_NODE && this.experimentalHighlights && (we.includes(s.nodeName.toUpperCase()) && this.notTextFlag?.set(e, !0), i.cloneContents().querySelector(we.join(", ").toLowerCase()) && this.notTextFlag?.set(e, !0), (s.textContent?.trim() || "").length === 0 && this.notTextFlag?.set(e, !0)), this.experimentalHighlights) {
2517
- const { type: o } = t.style, { layout: a, width: l } = t.style;
2518
- o !== E.TextColor && (o === E.Outline || o === E.Template || o === E.Mask || a !== void 0 && a !== "boxes" || l !== void 0 && l !== "wrap") && this.notTextFlag?.set(e, !0);
2519
- }
2520
- const n = {
2521
- decoration: t,
2522
- id: e,
2523
- range: i
2524
- };
2525
- this.items.push(n), this.layout(n), this.renderLayout([n]);
2526
- }
2527
- /**
2528
- * Removes the decoration with given ID from the group.
2529
- * @param identifier ID of item to remove
2530
- */
2531
- remove(t) {
2532
- const e = this.items.findIndex((n) => n.decoration.id === t);
2533
- if (e < 0) return;
2534
- const i = this.items[e], s = i.decoration.style?.type === E.Mask;
2535
- this.items.splice(e, 1), i.clickableElements = void 0, i.container && (i.container.remove(), i.container = void 0), this.experimentalHighlights && !this.notTextFlag?.has(i.id) && this.wnd.CSS.highlights.get(this.id)?.delete(i.range), this.notTextFlag?.delete(i.id), s && this.updateSharedMask();
2536
- }
2537
- /**
2538
- * Notifies that the given decoration was modified and needs to be updated.
2539
- * @param decoration Decoration to update
2540
- */
2541
- update(t) {
2542
- this.remove(t.id), this.add(t);
2543
- }
2544
- /**
2545
- * Removes all decorations from this group.
2546
- */
2547
- clear() {
2548
- this.clearContainer(), this.items.length = 0, this.notTextFlag?.clear(), this.maskSvg && (this.maskSvg.remove(), this.maskSvg = void 0), this.shadowHost && (this.shadowHost.remove(), this.shadowHost = void 0, this.shadowRoot = void 0);
2549
- }
2550
- /**
2551
- * Removes all decorations and tears down event listeners.
2552
- * Must be called when the group is permanently discarded.
2553
- */
2554
- destroy() {
2555
- this.clear(), this.wnd.document.removeEventListener("pointerup", this.activationHandler);
2556
- }
2557
- handleActivation(t) {
2558
- if (!this._activatable) return;
2559
- const e = t.clientX, i = t.clientY, s = this.wnd.devicePixelRatio;
2560
- for (const n of this.items) {
2561
- if (!n.decoration.style?.isActive) continue;
2562
- let o;
2563
- if (n.decoration.style.type === E.Template)
2564
- for (const a of n.clickableElements ?? []) {
2565
- const l = a.getBoundingClientRect();
2566
- if (Z(l, e, i, 0)) {
2567
- o = l;
2568
- break;
2569
- }
2570
- }
2571
- else {
2572
- const a = n.range.getClientRects();
2573
- for (const l of a)
2574
- if (Z(l, e, i, 0)) {
2575
- o = n.range.getBoundingClientRect();
2576
- break;
2577
- }
2578
- }
2579
- if (o) {
2580
- this.comms.send("decoration_activated", {
2581
- decorationId: n.decoration.id,
2582
- group: this.name,
2583
- rect: {
2584
- top: o.top * s,
2585
- left: o.left * s,
2586
- width: o.width * s,
2587
- height: o.height * s
2588
- },
2589
- point: { x: e * s, y: i * s }
2590
- });
2591
- return;
2592
- }
2593
- }
2594
- }
2595
- /**
2596
- * Recreates the decoration elements.
2597
- * To be called after reflowing the resource, for example.
2598
- */
2599
- requestLayout() {
2600
- this.wnd.cancelAnimationFrame(this.currentRender), this.clearContainer(), this.wnd.document.fonts.ready.then(() => {
2601
- this.currentRender = this.wnd.requestAnimationFrame(() => {
2602
- this.items.forEach((t) => this.layout(t)), this.renderLayout(this.items), this.updateSharedMask();
2603
- });
2604
- });
2605
- }
2606
- experimentalLayout(t) {
2607
- const [e, i] = this.requireContainer(!0), s = t.decoration.style, n = s.type ?? E.Highlight, o = s.tint ?? Pt(n), a = s.width, l = s.layout, m = (f, y) => this.wnd.document.caretPositionFromPoint?.(f, y) ?? null;
2608
- if (n === E.TextColor && (l === "bounds" || a === "bounds" || a === "page")) {
2609
- const f = Tt(this.wnd);
2610
- if (f.isVertical)
2611
- console.warn("Vertical writing detected: caretPositionFromPoint has known bugs, falling back to original range"), i.add(t.range);
2612
- else {
2613
- const y = t.range.getBoundingClientRect();
2614
- let g, b;
2615
- a === "page" ? (g = Math.floor(f.inlineStart(y) / f.pageInlineSize) * f.pageInlineSize, b = f.pageInlineSize) : (g = f.inlineStart(y), b = f.inlineSize(y));
2616
- const N = m(g, f.blockStart(y) + 1), x = m(g + b, f.blockStart(y) + f.blockSize(y) - 1);
2617
- if (N && x) {
2618
- const A = this.wnd.document.createRange();
2619
- A.setStart(N.offsetNode, N.offset), A.setEnd(x.offsetNode, x.offset), i.add(A), t.range = A;
2620
- } else
2621
- i.add(t.range);
2622
- }
2623
- } else
2624
- i.add(t.range);
2625
- const c = this.getBackgroundColor(), h = s.enforceContrast !== !1;
2626
- let d;
2627
- switch (n) {
2628
- case E.Underline:
2629
- const f = h ? G(o, c) : o;
2630
- d = `::highlight(${this.id}) {
2631
- text-decoration: underline;
2632
- text-decoration-color: ${f};
2633
- text-decoration-thickness: 0.1em;
2634
- }`;
2635
- break;
2636
- case E.Outline:
2637
- const y = h ? G(o, c) : o;
2638
- d = `::highlight(${this.id}) {
2639
- outline: 2px solid ${y};
2640
- outline-offset: 1px;
2641
- }`;
2642
- break;
2643
- case E.TextColor: {
2644
- const g = h ? G(o, c) : o;
2645
- d = `::highlight(${this.id}) {
2646
- color: ${g};
2647
- }`;
2648
- break;
2649
- }
2650
- case E.Highlight:
2651
- default: {
2652
- const g = h ? G(o, c) : o;
2653
- d = `::highlight(${this.id}) {
2654
- color: ${bi(g, c)};
2655
- background-color: ${g};
2656
- }`;
2657
- }
2658
- }
2659
- e.innerHTML = d;
2660
- }
2661
- /**
2662
- * Layouts a single DecorationItem.
2663
- * @param item
2664
- */
2665
- layout(t) {
2666
- if (this.experimentalHighlights && !this.notTextFlag?.has(t.id))
2667
- return this.experimentalLayout(t);
2668
- const e = this.wnd.document.createElement("div");
2669
- e.setAttribute("id", t.id), e.dataset.highlightId = t.decoration.id, e.style.setProperty("pointer-events", "none");
2670
- const i = Tt(this.wnd);
2671
- let s = 1;
2672
- if (ve.UA.Blink) {
2673
- const c = parseFloat(this.wnd.getComputedStyle(this.wnd.document.documentElement).zoom), h = parseFloat(this.wnd.getComputedStyle(this.wnd.document.body).zoom), d = (c || 1) * (h || 1);
2674
- d && (s = 1 / d);
2675
- }
2676
- const n = (c, h, d, f = 0) => {
2677
- switch (t.decoration?.style?.width) {
2678
- case "viewport": {
2679
- const g = Math.floor(i.inlineStart(h) / i.viewportInlineSize) * i.viewportInlineSize;
2680
- i.applyPosition(c, g + i.inlineScrollOffset + f, i.blockStart(h) + i.blockScrollOffset, i.viewportInlineSize - 2 * f, i.blockSize(h), s);
2681
- break;
2682
- }
2683
- case "page": {
2684
- const g = Math.floor(i.inlineStart(h) / i.pageInlineSize) * i.pageInlineSize;
2685
- i.applyPosition(c, g + i.inlineScrollOffset + f, i.blockStart(h) + i.blockScrollOffset, i.pageInlineSize - 2 * f, i.blockSize(h), s);
2686
- break;
2687
- }
2688
- case "bounds": {
2689
- i.applyPosition(c, i.inlineStart(d) + i.inlineScrollOffset, i.blockStart(h) + i.blockScrollOffset, i.inlineSize(d), i.blockSize(h), s);
2690
- break;
2691
- }
2692
- default:
2693
- i.applyPosition(c, i.inlineStart(h) + i.inlineScrollOffset, i.blockStart(h) + i.blockScrollOffset, i.inlineSize(h), i.blockSize(h), s);
2694
- }
2695
- }, o = t.range.getBoundingClientRect(), a = t.decoration.style, l = (() => {
2696
- if (a.type !== E.Outline) return 0;
2697
- const c = a.width;
2698
- return c === "page" || c === "viewport" ? 3 : 0;
2699
- })();
2700
- let m;
2701
- if (a.type === E.Template) {
2702
- a.stylesheet && this.injectCustomStylesheet(a.stylesheet);
2703
- const c = Ni(this.wnd, a.element);
2704
- if (!c) {
2705
- t.container = e, t.clickableElements = [];
2706
- return;
2707
- }
2708
- c.style.setProperty("pointer-events", "none"), m = c;
2709
- } else {
2710
- const c = a, h = c.type ?? E.Highlight, d = c.tint ?? Pt(h);
2711
- if (h === E.TextColor) {
2712
- t.container = e, t.clickableElements = [];
2713
- return;
2714
- }
2715
- if (h === E.Mask) {
2716
- t.container = e, t.clickableElements = [], this.updateSharedMask();
2717
- return;
2718
- }
2719
- const f = this.getCurrentDarkMode(), y = this.getBackgroundColor(), g = c.enforceContrast !== !1, b = (() => {
2720
- switch (h) {
2721
- case E.Underline: {
2722
- const A = g ? G(d, y) : d;
2723
- return [
2724
- c.layout === "bounds" ? `border-top: 0.1em solid ${A} !important` : null,
2725
- `border-bottom: 0.1em solid ${A} !important`,
2726
- "background-color: transparent !important",
2727
- "box-sizing: border-box !important"
2728
- ].filter(Boolean).join("; ");
2729
- }
2730
- case E.Outline:
2731
- return [
2732
- `outline: 2px solid ${g ? G(d, y) : d} !important`,
2733
- "outline-offset: 1px !important",
2734
- "background-color: transparent !important",
2735
- "box-sizing: border-box !important"
2736
- ].join("; ");
2737
- case E.Highlight:
2738
- default:
2739
- return [
2740
- `background-color: ${g ? G(d, y) : d} !important`,
2741
- `mix-blend-mode: ${f ? "exclusion" : "multiply"} !important`,
2742
- "opacity: 1 !important",
2743
- "box-sizing: border-box !important"
2744
- ].join("; ");
2745
- }
2746
- })(), N = this.wnd.document.createElement("template");
2747
- N.innerHTML = `<div data-readium="true" class="readium-${h}" style="${b}"></div>`.trim(), m = N.content.firstElementChild;
2748
- }
2749
- if (t.decoration?.style?.layout === "bounds") {
2750
- const c = m.cloneNode(!0);
2751
- c.style.setProperty("pointer-events", "none"), n(c, o, o, l), e.append(c);
2752
- } else {
2753
- let c = ci(
2754
- t.range,
2755
- !0,
2756
- // doNotMergeHorizontallyAlignedRects
2757
- i.isVertical
2758
- // doNotMergeVerticallyAlignedRects
2759
- );
2760
- c = c.sort((h, d) => i.isVertical ? (i.isVertLR ? 1 : -1) * (h.left - d.left) : h.top - d.top);
2761
- for (let h of c) {
2762
- const d = m.cloneNode(!0);
2763
- d.style.setProperty("pointer-events", "none"), n(d, h, o, l), e.append(d);
2764
- }
2765
- }
2766
- t.container = e, t.clickableElements = Array.from(
2767
- e.querySelectorAll("[data-activable='1']")
2768
- ), t.clickableElements.length || (t.clickableElements = Array.from(e.children));
2769
- }
2770
- renderLayout(t) {
2771
- this.wnd.cancelAnimationFrame(this.currentRender), this.currentRender = this.wnd.requestAnimationFrame(() => {
2772
- if (t = t.filter((i) => !this.experimentalHighlights || !!this.notTextFlag?.has(i.id)), !t || t.length === 0) return;
2773
- this.requireContainer().append(...t.map((i) => i.container).filter((i) => !!i));
2774
- });
2775
- }
2776
- /**
2777
- * Returns the group container element, after making sure it exists.
2778
- * @returns Group's container
2779
- */
2780
- requireContainer(t = !1) {
2781
- if (t) {
2782
- let e;
2783
- this.wnd.document.getElementById(`${this.id}-style`) ? e = this.wnd.document.getElementById(`${this.id}-style`) : (e = this.wnd.document.createElement("style"), e.dataset.readium = "true", e.id = `${this.id}-style`, this.wnd.document.head.appendChild(e));
2784
- let i;
2785
- return this.wnd.CSS.highlights.has(this.id) ? i = this.wnd.CSS.highlights.get(this.id) : (i = new this.wnd.Highlight(), this.wnd.CSS.highlights.set(this.id, i)), [e, i];
2786
- }
2787
- return this.container || (this.shadowRoot || (this.shadowHost = this.wnd.document.createElement("div"), this.shadowHost.style.cssText = "position:absolute;top:0;left:0;width:100%;height:100%;pointer-events:none", this.wnd.document.body.appendChild(this.shadowHost), this.shadowRoot = this.shadowHost.attachShadow({ mode: "open" })), this.container = this.wnd.document.createElement("div"), this.container.setAttribute("id", this.id), this.container.dataset.group = this.name, this.container.dataset.readium = "true", this.container.style.setProperty("pointer-events", "none"), this.container.style.display = "contents", this.shadowRoot.appendChild(this.container)), this.container;
2788
- }
2789
- getCurrentDarkMode() {
2790
- return ge(this.wnd, "--USER__appearance") === "readium-night-on" || He(this.getBackgroundColor());
2791
- }
2792
- getBackgroundColor() {
2793
- return ge(this.wnd, "--USER__backgroundColor") || this.wnd.getComputedStyle(this.wnd.document.documentElement).getPropertyValue("background-color");
2794
- }
2795
- updateSharedMask() {
2796
- const t = this.items.filter(
2797
- (d) => d.decoration.style?.type === E.Mask
2798
- );
2799
- if (t.length === 0) {
2800
- this.maskSvg && (this.maskSvg.remove(), this.maskSvg = void 0), this.shadowRoot && (this.shadowRoot.innerHTML = "");
2801
- return;
2802
- }
2803
- const e = Tt(this.wnd);
2804
- let i = 1;
2805
- if (ve.UA.Blink) {
2806
- const d = parseFloat(this.wnd.getComputedStyle(this.wnd.document.documentElement).zoom), f = parseFloat(this.wnd.getComputedStyle(this.wnd.document.body).zoom), y = (d || 1) * (f || 1);
2807
- y && (i = 1 / y);
2808
- }
2809
- const s = this.wnd.document.documentElement, n = s.scrollWidth, o = s.scrollHeight, a = [];
2810
- for (const d of t) {
2811
- const f = d.decoration.style, y = f.layout ?? "boxes", g = f.width ?? "wrap", b = d.range.getBoundingClientRect(), N = y === "bounds" ? [b] : Array.from(d.range.getClientRects());
2812
- for (const x of N) {
2813
- let A;
2814
- switch (g) {
2815
- case "viewport": {
2816
- const U = Math.floor(e.inlineStart(x) / e.viewportInlineSize) * e.viewportInlineSize;
2817
- A = e.toRect(U, e.blockStart(x), e.viewportInlineSize, e.blockSize(x));
2818
- break;
2819
- }
2820
- case "page": {
2821
- const U = Math.floor(e.inlineStart(x) / e.pageInlineSize) * e.pageInlineSize;
2822
- A = e.toRect(U, e.blockStart(x), e.pageInlineSize, e.blockSize(x));
2823
- break;
2824
- }
2825
- case "bounds": {
2826
- A = e.toRect(e.inlineStart(b), e.blockStart(x), e.inlineSize(b), e.blockSize(x));
2827
- break;
2828
- }
2829
- default:
2830
- A = x;
2831
- }
2832
- a.push(A);
2833
- }
2834
- }
2835
- const l = [
2836
- `M0 0 H${n} V${o} H0 Z`,
2837
- ...a.map((d) => {
2838
- const f = (d.left + e.xDocOffset) * i, y = (d.top + e.yDocOffset) * i, g = (d.right + e.xDocOffset) * i, b = (d.bottom + e.yDocOffset) * i;
2839
- return `M${f} ${y} H${g} V${b} H${f} Z`;
2840
- })
2841
- ].join(" "), m = "http://www.w3.org/2000/svg";
2842
- if (!this.maskSvg) {
2843
- this.shadowRoot || (this.shadowHost = this.wnd.document.createElement("div"), this.shadowHost.style.cssText = "position:absolute;top:0;left:0;width:100%;height:100%;pointer-events:none", this.wnd.document.body.appendChild(this.shadowHost), this.shadowRoot = this.shadowHost.attachShadow({ mode: "open" })), this.maskSvg = this.wnd.document.createElementNS(m, "svg"), this.maskSvg.style.cssText = `position:absolute;top:0;left:0;width:${n}px;height:${o}px;pointer-events:none;z-index:9999`, this.maskSvg.dataset.readium = "true";
2844
- const d = this.wnd.document.createElementNS(m, "defs"), f = this.wnd.document.createElementNS(m, "clipPath"), y = `${this.id}-mask-clip`;
2845
- f.setAttribute("id", y), f.setAttribute("clipPathUnits", "userSpaceOnUse");
2846
- const g = this.wnd.document.createElementNS(m, "path");
2847
- g.setAttribute("clip-rule", "evenodd"), f.appendChild(g), d.appendChild(f), this.maskSvg.appendChild(d);
2848
- const b = this.wnd.document.createElementNS(m, "rect");
2849
- b.setAttribute("id", `${this.id}-mask-rect`), b.setAttribute("clip-path", `url(#${y})`), b.style.pointerEvents = "none", this.maskSvg.appendChild(b), this.shadowRoot.appendChild(this.maskSvg);
2850
- }
2851
- this.maskSvg.style.width = `${n}px`, this.maskSvg.style.height = `${o}px`;
2852
- const c = this.maskSvg.querySelector("path");
2853
- c && c.setAttribute("d", l);
2854
- const h = this.maskSvg.querySelector("rect");
2855
- if (h) {
2856
- const f = t[0].decoration.style.tint, y = f ?? this.getBackgroundColor() ?? Pt(E.Mask), g = f ? "1" : "0.5";
2857
- h.setAttribute("x", "0"), h.setAttribute("y", "0"), h.setAttribute("width", String(n)), h.setAttribute("height", String(o)), h.setAttribute("fill", y), h.setAttribute("fill-opacity", g);
2858
- }
2859
- }
2860
- injectCustomStylesheet(t) {
2861
- const e = `${this.id}-custom-style`;
2862
- let i = this.wnd.document.getElementById(e);
2863
- i || (i = this.wnd.document.createElement("style"), i.id = e, i.dataset.readium = "true", this.wnd.document.head.appendChild(i)), i.innerHTML = t;
2864
- }
2865
- /**
2866
- * Removes the group container.
2867
- */
2868
- clearContainer() {
2869
- this.experimentalHighlights && this.wnd.CSS.highlights.delete(this.id), this.wnd.document.getElementById(`${this.id}-custom-style`)?.remove(), this.container && (this.container.remove(), this.container = void 0);
2870
- }
2871
- }
2872
- const J = class J extends tt {
2873
- constructor() {
2874
- super(...arguments), this.resizeFrame = 0, this.lastGroupId = 0, this.groups = /* @__PURE__ */ new Map(), this.handleResizer = this.handleResize.bind(this);
2875
- }
2876
- cleanup() {
2877
- this.groups.forEach((t) => t.destroy()), this.groups.clear();
2878
- }
2879
- updateHighlightStyles() {
2880
- this.groups.forEach((t) => {
2881
- t.requestLayout();
2882
- });
2883
- }
2884
- handleResize() {
2885
- this.wnd.clearTimeout(this.resizeFrame), this.resizeFrame = this.wnd.setTimeout(() => {
2886
- this.groups.forEach((t) => {
2887
- t.experimentalHighlights || t.requestLayout();
2888
- });
2889
- }, 50);
2890
- }
2891
- mount(t, e) {
2892
- return this.wnd = t, e.register("decorate", J.moduleName, (i, s) => {
2893
- const n = i;
2894
- (n.action === "add" || n.action === "update") && n.decoration.locator && (n.decoration.locator = B.deserialize(n.decoration.locator)), this.groups.has(n.group) || this.groups.set(n.group, new Ii(
2895
- t,
2896
- e,
2897
- `readium-decoration-${this.lastGroupId++}`,
2898
- n.group
2899
- ));
2900
- const o = this.groups.get(n.group);
2901
- switch (n.action) {
2902
- case "add":
2903
- o?.add(n.decoration);
2904
- break;
2905
- case "remove":
2906
- o?.remove(n.decoration.id);
2907
- break;
2908
- case "clear":
2909
- o?.clear();
2910
- break;
2911
- case "update":
2912
- o?.update(n.decoration);
2913
- break;
2914
- }
2915
- s(!0);
2916
- }), e.register("decoration_activatable", J.moduleName, (i, s) => {
2917
- const n = i, o = this.groups.get(n.group);
2918
- o && (o.activatable = n.activatable), s(!0);
2919
- }), this.resizeObserver = new ResizeObserver(() => t.requestAnimationFrame(() => this.handleResize())), this.resizeObserver.observe(t.document.documentElement), t.addEventListener("orientationchange", this.handleResizer), t.addEventListener("resize", this.handleResizer), this.styleObserver = new MutationObserver((i) => {
2920
- i.some(
2921
- (n) => n.type === "attributes" && n.attributeName === "style" && n.oldValue !== n.target.getAttribute("style")
2922
- ) && this.updateHighlightStyles();
2923
- }), this.styleObserver.observe(t.document.documentElement, {
2924
- attributes: !0,
2925
- attributeFilter: ["style"],
2926
- attributeOldValue: !0
2927
- }), e.log("Decorator Mounted"), !0;
2928
- }
2929
- unmount(t, e) {
2930
- return t.removeEventListener("orientationchange", this.handleResizer), t.removeEventListener("resize", this.handleResizer), e.unregisterAll(J.moduleName), this.resizeObserver.disconnect(), this.styleObserver.disconnect(), this.cleanup(), e.log("Decorator Unmounted"), !0;
2931
- }
2932
- };
2933
- J.moduleName = "decorator";
2934
- let Ot = J;
2935
- const Ee = "readium-snapper-style", nt = class nt extends tt {
2936
- constructor() {
2937
- super(...arguments), this.protected = !1;
2938
- }
2939
- buildStyles() {
2940
- return `
2941
- html, body {
2942
- touch-action: manipulation;
2943
- user-select: ${this.protected ? "none" : "auto"};
2944
- }`;
2945
- }
2946
- mount(t, e) {
2947
- const i = t.document.createElement("style");
2948
- return i.dataset.readium = "true", i.id = Ee, i.textContent = this.buildStyles(), t.document.head.appendChild(i), e.register("protect", nt.moduleName, (s, n) => {
2949
- this.protected = !0, i.textContent = this.buildStyles(), n(!0);
2950
- }), e.register("unprotect", nt.moduleName, (s, n) => {
2951
- this.protected = !1, i.textContent = this.buildStyles(), n(!0);
2952
- }), e.log("Snapper Mounted"), !0;
2953
- }
2954
- unmount(t, e) {
2955
- return t.document.getElementById(Ee)?.remove(), e.log("Snapper Unmounted"), !0;
2956
- }
2957
- };
2958
- nt.moduleName = "snapper";
2959
- let Q = nt;
2960
- function Di(r) {
2961
- return r < 0.5 ? 2 * r * r : -1 + (4 - 2 * r) * r;
2962
- }
2963
- function T(r) {
2964
- const t = r.getSelection();
2965
- t && t.removeAllRanges();
2966
- }
2967
- const zi = [
2968
- "a",
2969
- "area",
2970
- "audio",
2971
- "button",
2972
- "canvas",
2973
- "details",
2974
- "input",
2975
- "label",
2976
- "option",
2977
- "select",
2978
- "submit",
2979
- "textarea",
2980
- "video"
2981
- ], Mi = ["dialog", "radiogroup", "radio", "menu", "menuitem"];
2982
- function Xt(r) {
2983
- return Wi(r) ? null : $e(r) ? r : r.parentElement ? Xt(r.parentElement) : null;
2984
- }
2985
- function Wi(r) {
2986
- return r ? r.closest("[inert]") !== null || r.hasAttribute("disabled") : !0;
2987
- }
2988
- function $e(r) {
2989
- return r ? r.role && Mi.includes(r.role) ? !0 : r.tagName.toLowerCase() === "iframe" ? !1 : r.tabIndex >= 0 ? !0 : zi.includes(r.nodeName.toLowerCase()) || r.hasAttribute("contenteditable") && r.getAttribute("contenteditable")?.toLowerCase() !== "false" : !1;
2990
- }
2991
- function wt(r, t) {
2992
- const e = Ge(r, r.document.body, t), i = r._readium_cssSelectorGenerator.getCssSelector(e, {
2993
- selectors: ["tag", "id", "class", "nthchild", "nthoftype", "attribute"]
2994
- });
2995
- return new B({
2996
- href: "#",
2997
- type: "application/xhtml+xml",
2998
- locations: new P({
2999
- otherLocations: /* @__PURE__ */ new Map([
3000
- ["cssSelector", i]
3001
- ])
3002
- }),
3003
- text: new $({
3004
- highlight: e.textContent || void 0
3005
- })
3006
- });
3007
- }
3008
- function Ge(r, t, e) {
3009
- for (var i = 0; i < t.children.length; i++) {
3010
- const s = t.children[i];
3011
- if (!Ui(s) && Hi(r, s, e))
3012
- return Bi(r, s) ? s : Ge(r, s, e);
3013
- }
3014
- return t;
3015
- }
3016
- function Hi(r, t, e) {
3017
- if (t === document.body || t === document.documentElement)
3018
- return !0;
3019
- if (!document || !document.documentElement || !document.body)
3020
- return !1;
3021
- const i = t.getBoundingClientRect();
3022
- return e ? i.bottom > 0 && i.top < r.innerHeight : i.right > 0 && i.left < r.innerWidth;
3023
- }
3024
- function Bi(r, t) {
3025
- const e = t.getBoundingClientRect();
3026
- return e.top >= 0 && e.left >= 0 && e.bottom <= r.innerHeight && e.right <= r.innerWidth;
3027
- }
3028
- function Ui(r) {
3029
- const t = getComputedStyle(r);
3030
- if (t) {
3031
- const e = t.getPropertyValue("display");
3032
- if (e != "block" && e != "list-item" || t.getPropertyValue("opacity") === "0")
3033
- return !0;
3034
- }
3035
- return !1;
3036
- }
3037
- const _i = {
3038
- maxVelocity: 200,
3039
- // Reasonable default for human-like scrolling (pixels/ms)
3040
- minVariance: 0.01,
3041
- // Default variance threshold
3042
- historySize: 20,
3043
- // Balanced history size for performance
3044
- minDirectionChanges: 0.2,
3045
- // Reasonable default for detecting patterns
3046
- maxConsistentScrolls: 15
3047
- // Balanced threshold for flagging
3048
- }, Kt = {
3049
- maxVelocity: 200,
3050
- // Extremely fast scrolling (pixels/ms)
3051
- minVariance: 1e-5,
3052
- // Near-perfect consistency
3053
- historySize: 100,
3054
- // Large history window
3055
- minDirectionChanges: 0.1,
3056
- // Only trigger on near-perfect patterns
3057
- maxConsistentScrolls: 20
3058
- // Need many consistent scrolls
3059
- }, qe = {
3060
- maxSelectionsPerSecond: 500,
3061
- minVariance: 50,
3062
- historySize: 20
3063
- }, Fi = {
3064
- enabled: !0,
3065
- maxSelectionPercent: 0.1,
3066
- minThreshold: 100,
3067
- absoluteMaxChars: 5e3,
3068
- historySize: 20
3069
- };
3070
- class Et {
3071
- constructor(t = {}) {
3072
- this.history = [], this.consistentScrollCount = 0, this.options = { ..._i, ...t };
3073
- }
3074
- analyze(t, e, i) {
3075
- if (i <= 0) return !1;
3076
- const s = Math.abs(e) / i, n = Date.now();
3077
- if (this.history.push({
3078
- timestamp: n,
3079
- direction: t,
3080
- velocity: s,
3081
- distance: Math.abs(e)
3082
- }), this.history = this.history.filter((g) => n - g.timestamp < 2e3).slice(-(this.options.historySize || 20)), this.history.length < 3) return !1;
3083
- if (s > this.options.maxVelocity)
3084
- return this.resetAfterDetection(), !0;
3085
- const o = this.history.map((g) => g.velocity), a = this.history.map((g) => g.distance), l = o.reduce((g, b) => g + b, 0) / o.length, m = a.reduce((g, b) => g + b, 0) / a.length, c = o.reduce((g, b) => g + Math.pow(b - l, 2), 0) / o.length, h = a.reduce((g, b) => g + Math.pow(b - m, 2), 0) / a.length;
3086
- if (c < this.options.minVariance && h < m * 0.1) {
3087
- if (this.consistentScrollCount++, this.consistentScrollCount >= (this.options.maxConsistentScrolls || 10))
3088
- return this.resetAfterDetection(), !0;
3089
- } else
3090
- this.consistentScrollCount = Math.max(0, this.consistentScrollCount - 1);
3091
- let d = 0, f = this.history[0].direction;
3092
- for (let g = 1; g < this.history.length; g++)
3093
- this.history[g].direction !== f && (d++, f = this.history[g].direction);
3094
- return d / this.history.length > (this.options.minDirectionChanges || 0.3) ? (this.resetAfterDetection(), !0) : !1;
3095
- }
3096
- resetAfterDetection() {
3097
- this.history = this.history.slice(-3), this.consistentScrollCount = 0;
3098
- }
3099
- clear() {
3100
- this.history = [], this.consistentScrollCount = 0;
3101
- }
3102
- }
3103
- const Ae = "readium-column-snapper-style", Vi = 200, O = class O extends Q {
3104
- constructor() {
3105
- super(...arguments), this.isSnapProtectionEnabled = !1, this.patternAnalyzer = null, this.lastTurnTime = 0, this.rtl = !1, this.shakeTimeout = 0, this.snappingCancelled = !1, this.alreadyScrollLeft = 0, this.overscroll = 0, this.cachedScrollWidth = 0, this.touchState = 0, this.startingX = void 0, this.endingX = void 0, this.onTouchStarter = this.onTouchStart.bind(this), this.onTouchEnder = this.onTouchEnd.bind(this), this.onWidthChanger = this.onWidthChange.bind(this), this.onTouchMover = this.onTouchMove.bind(this);
3106
- }
3107
- doc() {
3108
- return this.wnd.document.scrollingElement;
3109
- }
3110
- scrollOffset() {
3111
- const t = this.doc().scrollLeft;
3112
- return t !== 0 ? t : this.alreadyScrollLeft;
3113
- }
3114
- snapOffset(t) {
3115
- const e = t + (this.rtl ? -1 : 1);
3116
- return e - e % this.wnd.innerWidth;
3117
- }
3118
- /**
3119
- * Snap a non-negative normalized offset (distance from document start) to
3120
- * the nearest page boundary. Works identically regardless of reading direction.
3121
- */
3122
- snapNormOffset(t) {
3123
- const e = t + 1;
3124
- return e - e % this.wnd.innerWidth;
3125
- }
3126
- /**
3127
- * Normalized scroll position: distance from document start, always in
3128
- * [0, scrollWidth - innerWidth] regardless of reading direction.
3129
- * scrollLeft may be negative depending on the browser — Math.abs() normalizes it.
3130
- */
3131
- normScroll() {
3132
- const t = this.doc().scrollLeft || this.alreadyScrollLeft;
3133
- return this.rtl ? Math.abs(t) : Math.max(0, this.wnd.scrollX > 0 ? this.wnd.scrollX : t);
3134
- }
3135
- reportProgress() {
3136
- const t = this.cachedScrollWidth, e = this.wnd.innerWidth, i = this.normScroll(), s = Math.max(1, t - e), n = Math.max(0, Math.min(1, i / s)), o = Math.max(0, Math.min(1, (i + e) / t));
3137
- this.comms.send("progress", {
3138
- start: n,
3139
- end: o
3140
- });
3141
- }
3142
- shake() {
3143
- if (this.overscroll !== 0 || this.shakeTimeout !== 0) return;
3144
- const t = this.doc(), e = this.normScroll() < 5, i = this.rtl ? e ? "readium-bounce-r" : "readium-bounce-l" : "readium-bounce-r";
3145
- t.classList.add(i);
3146
- const s = this.scrollOffset();
3147
- this.shakeTimeout = this.wnd.setTimeout(() => {
3148
- t.classList.remove(i), this.shakeTimeout = 0, this.doc().scrollLeft = s;
3149
- }, 150);
3150
- }
3151
- // We have to cache this because during overscroll (transform, or left) the width is incorrect due to browser
3152
- takeOverSnap() {
3153
- this.snappingCancelled = !0, this.clearTouches();
3154
- const t = this.doc();
3155
- this.overscroll = t.style.transform?.length > 12 ? parseFloat(t.style.transform.slice(12).split("px")[0]) : 0;
3156
- }
3157
- // Snaps the current offset to the page width.
3158
- snapCurrentOffset(t = !1, e = !1) {
3159
- const i = this.doc(), s = Ue(this.wnd), n = this.cachedScrollWidth - this.wnd.innerWidth, o = Math.min(Math.max(0, this.normScroll()), n), a = this.dragOffset(), l = this.rtl ? -a : a, m = this.wnd.innerWidth / 3 * (l > 0 ? 2 : 1), c = Math.min(n, Math.max(0, this.snapNormOffset(o + m))), h = this.rtl ? -c : c, d = this.rtl ? -o : o, f = h > d ? "right" : "left";
3160
- if (this.checkSuspiciousSnap(f, Math.abs(h - d)), t && h !== d) {
3161
- this.snappingCancelled = !1;
3162
- const y = (x, A, U, ht) => U > ht ? A : x + (A - x) * Di(U / ht), g = Vi * s;
3163
- let b;
3164
- const N = (x) => {
3165
- if (this.snappingCancelled) return;
3166
- b || (b = x);
3167
- const A = x - b, U = y(this.overscroll, 0, A, g), ht = y(d, h, A, g);
3168
- i.scrollLeft = ht, this.overscroll !== 0 && (i.style.transform = `translate3d(${-U}px, 0px, 0px)`), A < g ? this.wnd.requestAnimationFrame(N) : (this.clearTouches(), i.style.removeProperty("transform"), i.scrollLeft = h, e || this.reportProgress());
3169
- };
3170
- this.wnd.requestAnimationFrame(N);
3171
- } else
3172
- i.style.removeProperty("transform"), this.wnd.requestAnimationFrame(() => {
3173
- i.scrollLeft = h, this.clearTouches(), e || this.reportProgress();
3174
- });
3175
- }
3176
- dragOffset() {
3177
- return (this.startingX ?? 0) - (this.endingX ?? 0);
3178
- }
3179
- clearTouches() {
3180
- this.startingX = void 0, this.endingX = void 0, this.overscroll = 0;
3181
- }
3182
- onTouchStart(t) {
3183
- switch (t.stopPropagation(), this.takeOverSnap(), t.touches.length) {
3184
- case 1:
3185
- break;
3186
- case 2:
3187
- this.onTouchEnd(t);
3188
- return;
3189
- default: {
3190
- this.onTouchEnd(t), this.comms.send("tap_more", t.touches.length);
3191
- return;
3192
- }
3193
- }
3194
- this.startingX = t.touches[0].clientX, this.alreadyScrollLeft = this.doc().scrollLeft, this.touchState = 1;
3195
- }
3196
- onTouchEnd(t) {
3197
- if (this.touchState === 2) {
3198
- const e = this.dragOffset(), i = this.normScroll(), s = this.cachedScrollWidth - this.wnd.innerWidth, n = this.rtl ? -e : e;
3199
- this.cachedScrollWidth <= this.wnd.innerWidth ? (this.reportProgress(), n > 5 && this.comms.send("no_more", void 0), n < -5 && this.comms.send("no_less", void 0)) : i < 5 && n < 5 ? (this.alreadyScrollLeft = 0, this.comms.send("no_less", void 0)) : s - i < 5 && n > 5 && (this.alreadyScrollLeft = this.rtl ? -s : s, this.comms.send("no_more", void 0)), this.snapCurrentOffset(!0), this.comms.send("swipe", e);
3200
- }
3201
- this.touchState = 0;
3202
- }
3203
- onWidthChange() {
3204
- this.cachedScrollWidth = this.doc().scrollWidth, this.comms.ready && this.snapCurrentOffset();
3205
- }
3206
- onTouchMove(t) {
3207
- if (this.touchState === 0) return;
3208
- this.touchState === 1 && (this.touchState = 2, T(this.wnd)), this.endingX = t.touches[0].clientX;
3209
- const e = this.dragOffset(), i = this.alreadyScrollLeft + e, s = this.rtl ? -(this.cachedScrollWidth - this.wnd.innerWidth) : 0, n = this.rtl ? 0 : this.cachedScrollWidth - this.wnd.innerWidth;
3210
- i < s ? (this.overscroll = i, this.doc().style.transform = `translate3d(${-this.overscroll}px, 0px, 0px)`) : i > n ? (this.overscroll = i, this.doc().style.transform = `translate3d(${-i}px, 0px, 0px)`) : (this.overscroll = 0, this.doc().style.removeProperty("transform"), this.doc().scrollLeft = i);
3211
- }
3212
- enableSnapProtection() {
3213
- this.patternAnalyzer || (this.patternAnalyzer = new Et({
3214
- maxVelocity: this.wnd.innerWidth,
3215
- // page width
3216
- minVariance: 0.1,
3217
- // Allow for some variation in swipe speed
3218
- historySize: 5,
3219
- // Fewer samples needed for swipe detection
3220
- maxConsistentScrolls: 3,
3221
- // Lower threshold for consistent scrolling
3222
- minDirectionChanges: 0.3
3223
- // Require more direction changes
3224
- }), this.isSnapProtectionEnabled = !0, this.comms?.log("Snap protection enabled"));
3225
- }
3226
- checkSuspiciousSnap(t, e) {
3227
- if (!this.isSnapProtectionEnabled || !this.patternAnalyzer) return;
3228
- const i = Date.now(), s = i - (this.lastTurnTime || i);
3229
- this.lastTurnTime = i, this.patternAnalyzer.analyze(t, e, s) && this.comms?.send("content_protection", {
3230
- type: "suspicious_snapping",
3231
- timestamp: Date.now(),
3232
- event: null
3233
- });
3234
- }
3235
- mount(t, e) {
3236
- if (this.wnd = t, this.comms = e, this.rtl = Ei(t), !super.mount(t, e)) return !1;
3237
- t.navigator.epubReadingSystem && (t.navigator.epubReadingSystem.layoutStyle = "paginated");
3238
- const i = t.document.createElement("style");
3239
- i.dataset.readium = "true", i.id = Ae, i.textContent = `
3240
- @keyframes readium-bounce-l-animation {
3241
- 0%, 100% {transform: translate3d(0, 0, 0);}
3242
- 50% {transform: translate3d(-50px, 0, 0);}
3243
- }
3244
-
3245
- @keyframes readium-bounce-r-animation {
3246
- 0%, 100% {transform: translate3d(0, 0, 0);}
3247
- 50% {transform: translate3d(50px, 0, 0);}
3248
- }
3249
-
3250
- .readium-bounce-l {
3251
- animation: readium-bounce-l-animation 150ms ease-out 1;
3252
- }
3253
-
3254
- .readium-bounce-r {
3255
- animation: readium-bounce-r-animation 150ms ease-out 1;
3256
- }
3257
-
3258
- html {
3259
- overflow: hidden;
3260
- }
3261
-
3262
- body {
3263
- -ms-overflow-style: none; /* for Internet Explorer, Edge */
3264
- }
3265
-
3266
- * {
3267
- scrollbar-width: none; /* for Firefox */
3268
- }
3269
-
3270
- body::-webkit-scrollbar {
3271
- display: none; /* for Chrome, Safari, and Opera */
3272
- }
3273
- `, t.document.head.appendChild(i), this.resizeObserver = new ResizeObserver(() => {
3274
- t.requestAnimationFrame(() => {
3275
- t && be(t);
3276
- }), this.onWidthChange();
3277
- }), this.resizeObserver.observe(t.document.body), this.mutationObserver = new MutationObserver((o) => {
3278
- for (const a of o)
3279
- if (a.target === this.wnd.document.documentElement) {
3280
- const l = a.oldValue, m = a.target.getAttribute("style"), c = /transform\s*:\s*([^;]+)/, h = l?.match(c), d = m?.match(c);
3281
- (!h && !d && fi(l, m) || h && !d || h && d && h[1] !== d[1]) && (t.requestAnimationFrame(() => {
3282
- t && be(t);
3283
- }), this.onWidthChange());
3284
- } else
3285
- t.requestAnimationFrame(() => this.cachedScrollWidth = this.doc().scrollWidth);
3286
- }), t.frameElement && this.mutationObserver.observe(t.frameElement, { attributes: !0, attributeFilter: ["style"] }), this.mutationObserver.observe(t.document, { attributes: !0, attributeFilter: ["style"] }), this.mutationObserver.observe(t.document.documentElement, { attributes: !0, attributeFilter: ["style"] }), e.register("scroll_protection", O.moduleName, (o, a) => {
3287
- this.enableSnapProtection(), a(!0);
3288
- });
3289
- const s = (o) => {
3290
- const a = this.doc().scrollLeft;
3291
- return this.doc().scrollLeft = this.snapOffset(o), a !== this.doc().scrollLeft;
3292
- }, n = (o) => {
3293
- const a = this.doc().scrollLeft, l = this.snapNormOffset(Math.max(0, Math.min(this.cachedScrollWidth - t.innerWidth, o)));
3294
- return this.doc().scrollLeft = -l, a !== this.doc().scrollLeft;
3295
- };
3296
- return t.addEventListener("orientationchange", this.onWidthChanger), t.addEventListener("resize", this.onWidthChanger), t.requestAnimationFrame(() => this.cachedScrollWidth = this.doc().scrollWidth), e.register("go_progression", O.moduleName, (o, a) => {
3297
- const l = o;
3298
- if (l < 0 || l > 1) {
3299
- e.send("error", {
3300
- message: "go_progression must be given a position from 0.0 to 1.0"
3301
- }), a(!1);
3302
- return;
3303
- }
3304
- this.wnd.requestAnimationFrame(() => {
3305
- this.cachedScrollWidth = this.doc().scrollWidth;
3306
- const c = (this.cachedScrollWidth - t.innerWidth) * l;
3307
- this.rtl ? this.doc().scrollLeft = -this.snapNormOffset(c) : this.doc().scrollLeft = this.snapOffset(c), this.reportProgress(), T(this.wnd), a(!0);
3308
- });
3309
- }), e.register("go_id", O.moduleName, (o, a) => {
3310
- const l = t.document.getElementById(o);
3311
- if (!l) {
3312
- a(!1);
3313
- return;
3314
- }
3315
- this.wnd.requestAnimationFrame(() => {
3316
- this.rtl ? this.doc().scrollLeft = -this.snapNormOffset(l.getBoundingClientRect().left + t.scrollX) : this.doc().scrollLeft = this.snapOffset(l.getBoundingClientRect().left + t.scrollX), this.reportProgress(), T(this.wnd), a(!0);
3317
- });
3318
- }), e.register("go_text", O.moduleName, (o, a) => {
3319
- let l;
3320
- Array.isArray(o) && (o.length > 1 && (l = o[1]), o = o[0]);
3321
- const m = $.deserialize(o), c = ct(this.wnd.document, new B({
3322
- href: t.location.href,
3323
- type: "text/html",
3324
- text: m,
3325
- locations: l ? new P({
3326
- otherLocations: /* @__PURE__ */ new Map([
3327
- ["cssSelector", l]
3328
- ])
3329
- }) : void 0
3330
- }));
3331
- if (!c) {
3332
- a(!1);
3333
- return;
3334
- }
3335
- this.wnd.requestAnimationFrame(() => {
3336
- this.rtl ? this.doc().scrollLeft = -this.snapNormOffset(c.getBoundingClientRect().left + t.scrollX) : this.doc().scrollLeft = this.snapOffset(c.getBoundingClientRect().left + t.scrollX), this.reportProgress(), T(this.wnd), a(!0);
3337
- });
3338
- }), e.register("go_end", O.moduleName, (o, a) => {
3339
- this.wnd.requestAnimationFrame(() => {
3340
- this.cachedScrollWidth = this.doc().scrollWidth;
3341
- let l;
3342
- if (this.rtl ? l = -this.snapNormOffset(this.cachedScrollWidth - t.innerWidth) : l = this.snapOffset(this.cachedScrollWidth), this.doc().scrollLeft === l) return a(!1);
3343
- this.doc().scrollLeft = l, this.reportProgress(), T(this.wnd), a(!0);
3344
- });
3345
- }), e.register("go_start", O.moduleName, (o, a) => {
3346
- this.wnd.requestAnimationFrame(() => {
3347
- if (this.doc().scrollLeft === 0) return a(!1);
3348
- this.doc().scrollLeft = 0, this.reportProgress(), T(this.wnd), a(!0);
3349
- });
3350
- }), e.register("go_prev", O.moduleName, (o, a) => {
3351
- this.wnd.requestAnimationFrame(() => {
3352
- this.cachedScrollWidth = this.doc().scrollWidth;
3353
- let l;
3354
- this.rtl ? l = n(this.normScroll() - t.innerWidth) : l = s(t.scrollX - t.innerWidth), this.reportProgress(), l && (T(this.wnd), this.checkSuspiciousSnap("left", this.wnd.innerWidth)), a(l);
3355
- });
3356
- }), e.register("go_next", O.moduleName, (o, a) => {
3357
- this.wnd.requestAnimationFrame(() => {
3358
- this.cachedScrollWidth = this.doc().scrollWidth;
3359
- let l;
3360
- this.rtl ? l = n(this.normScroll() + t.innerWidth) : l = s(t.scrollX + t.innerWidth), this.reportProgress(), l && (T(this.wnd), this.checkSuspiciousSnap("right", this.wnd.innerWidth)), a(l);
3361
- });
3362
- }), e.register("unfocus", O.moduleName, (o, a) => {
3363
- this.snappingCancelled = !0, T(this.wnd), a(!0);
3364
- }), e.register("shake", O.moduleName, (o, a) => {
3365
- this.shake(), a(!0);
3366
- }), e.register("focus", O.moduleName, (o, a) => {
3367
- this.wnd.requestAnimationFrame(() => {
3368
- this.cachedScrollWidth = this.doc().scrollWidth, this.snapCurrentOffset(!1, !0), this.reportProgress(), a(!0);
3369
- });
3370
- }), e.register("first_visible_locator", O.moduleName, (o, a) => {
3371
- const l = wt(t, !1);
3372
- this.comms.send("first_visible_locator", l.serialize()), a(!0);
3373
- }), t.addEventListener("touchstart", this.onTouchStarter, { passive: !0 }), t.addEventListener("touchend", this.onTouchEnder, { passive: !0 }), t.addEventListener("touchmove", this.onTouchMover, { passive: !0 }), t.document.addEventListener("touchstart", () => {
3374
- }), e.log("ColumnSnapper Mounted"), !0;
3375
- }
3376
- unmount(t, e) {
3377
- return this.snappingCancelled = !0, e.unregisterAll(O.moduleName), this.resizeObserver.disconnect(), this.mutationObserver.disconnect(), this.patternAnalyzer && (this.patternAnalyzer.clear(), this.patternAnalyzer = null, this.isSnapProtectionEnabled = !1), t.removeEventListener("touchstart", this.onTouchStarter), t.removeEventListener("touchend", this.onTouchEnder), t.removeEventListener("touchmove", this.onTouchMover), t.removeEventListener("orientationchange", this.onWidthChanger), t.removeEventListener("resize", this.onWidthChanger), t.document.getElementById(Ae)?.remove(), e.log("ColumnSnapper Unmounted"), super.unmount(t, e);
3378
- }
3379
- };
3380
- O.moduleName = "column_snapper";
3381
- let Rt = O;
3382
- const Ce = "readium-scroll-snapper-style", R = class R extends Q {
3383
- constructor() {
3384
- super(...arguments), this.patternAnalyzer = null, this.lastScrollTime = 0, this.isScrollProtectionEnabled = !1, this.initialScrollHandled = !1, this.isScrolling = !1, this.lastScrollTop = 0, this.isResizing = !1, this.resizeDebounce = null, this.handleScroll = (t) => {
3385
- if (this.comms.ready && !this.isResizing) {
3386
- if (!this.initialScrollHandled) {
3387
- this.lastScrollTop = this.doc().scrollTop, this.initialScrollHandled = !0, this.reportProgress();
3388
- return;
3389
- }
3390
- this.isScrolling || (this.isScrolling = !0, this.wnd.requestAnimationFrame(() => {
3391
- this.reportProgress();
3392
- const e = this.doc().scrollTop, i = e - this.lastScrollTop;
3393
- if (this.lastScrollTop = e, this.isScrollProtectionEnabled && Math.abs(i) > 5) {
3394
- const s = Date.now(), n = s - (this.lastScrollTime || s);
3395
- if (this.patternAnalyzer && this.patternAnalyzer.analyze(
3396
- i > 0 ? "down" : "up",
3397
- Math.abs(i),
3398
- n
3399
- )) {
3400
- const a = t.target && "tagName" in t.target ? { tagName: t.target.tagName } : null;
3401
- this.comms?.send("content_protection", {
3402
- type: "suspicious_scrolling",
3403
- timestamp: Date.now(),
3404
- scrollDelta: i,
3405
- scrollDirection: i > 0 ? "down" : "up",
3406
- targetElement: a
3407
- });
3408
- }
3409
- this.lastScrollTime = s;
3410
- }
3411
- this.comms.send("scroll", i), this.isScrolling = !1;
3412
- }));
3413
- }
3414
- };
3415
- }
3416
- doc() {
3417
- return this.wnd.document.scrollingElement;
3418
- }
3419
- reportProgress() {
3420
- if (!this.comms.ready) return;
3421
- const t = Math.ceil(this.doc().scrollTop), e = this.doc().scrollHeight, i = this.wnd.innerHeight, s = Math.max(0, Math.min(1, t / e)), n = Math.max(0, Math.min(1, (t + i) / e));
3422
- this.comms.send("progress", {
3423
- start: s,
3424
- end: n
3425
- });
3426
- }
3427
- enableScrollProtection() {
3428
- this.patternAnalyzer || (this.patternAnalyzer = new Et(Kt), this.isScrollProtectionEnabled = !0, this.comms?.log("Scroll protection enabled"));
3429
- }
3430
- mount(t, e) {
3431
- this.wnd = t, this.comms = e, this.initialScrollHandled = !1, this.lastScrollTop = 0, this.isResizing = !1, this.resizeDebounce && (this.wnd.clearTimeout(this.resizeDebounce), this.resizeDebounce = null), t.navigator.epubReadingSystem && (t.navigator.epubReadingSystem.layoutStyle = "scrolling");
3432
- const i = t.document.createElement("style");
3433
- return i.dataset.readium = "true", i.id = Ce, i.textContent = `
3434
- * {
3435
- scrollbar-width: none; /* for Firefox */
3436
- }
3437
-
3438
- body::-webkit-scrollbar {
3439
- display: none; /* for Chrome, Safari, and Opera */
3440
- }
3441
- `, t.document.head.appendChild(i), this.resizeObserver = new ResizeObserver(() => {
3442
- this.resizeDebounce && this.wnd.clearTimeout(this.resizeDebounce), this.isResizing = !0, this.resizeDebounce = this.wnd.setTimeout(() => {
3443
- this.isResizing = !1, this.resizeDebounce = null, this.reportProgress();
3444
- }, 50);
3445
- }), this.resizeObserver.observe(t.document.body), t.addEventListener("scroll", this.handleScroll, { passive: !0 }), e.register("force_webkit_recalc", R.moduleName, () => {
3446
- Yt(this.wnd);
3447
- const s = this.doc().scrollTop;
3448
- s > 1 ? this.doc().scrollTop = s - 1 : this.doc().scrollTop = s + 1, this.doc().scrollTop = s;
3449
- }), e.register("go_progression", R.moduleName, (s, n) => {
3450
- const o = s;
3451
- if (o < 0 || o > 1) {
3452
- e.send("error", {
3453
- message: "go_progression must be given a position from 0.0 to 1.0"
3454
- }), n(!1);
3455
- return;
3456
- }
3457
- this.wnd.requestAnimationFrame(() => {
3458
- this.doc().scrollTop = this.doc().offsetHeight * o, this.reportProgress(), T(this.wnd), n(!0);
3459
- });
3460
- }), e.register("go_id", R.moduleName, (s, n) => {
3461
- const o = t.document.getElementById(s);
3462
- if (!o) {
3463
- n(!1);
3464
- return;
3465
- }
3466
- this.wnd.requestAnimationFrame(() => {
3467
- this.doc().scrollTop = o.getBoundingClientRect().top + t.scrollY - t.innerHeight / 2, this.reportProgress(), T(this.wnd), n(!0);
3468
- });
3469
- }), e.register("go_text", R.moduleName, (s, n) => {
3470
- let o;
3471
- Array.isArray(s) && (s.length > 1 && (o = s[1]), s = s[0]);
3472
- const a = $.deserialize(s), l = ct(this.wnd.document, new B({
3473
- href: t.location.href,
3474
- type: "text/html",
3475
- text: a,
3476
- locations: o ? new P({
3477
- otherLocations: /* @__PURE__ */ new Map([
3478
- ["cssSelector", o]
3479
- ])
3480
- }) : void 0
3481
- }));
3482
- if (!l) {
3483
- n(!1);
3484
- return;
3485
- }
3486
- this.wnd.requestAnimationFrame(() => {
3487
- this.doc().scrollTop = l.getBoundingClientRect().top + t.scrollY - t.innerHeight / 2, this.reportProgress(), T(this.wnd), n(!0);
3488
- });
3489
- }), e.register("go_start", R.moduleName, (s, n) => {
3490
- if (this.doc().scrollTop === 0) return n(!1);
3491
- this.doc().scrollTop = 0, this.reportProgress(), n(!0);
3492
- }), e.register("go_end", R.moduleName, (s, n) => {
3493
- if (this.doc().scrollTop === this.doc().scrollHeight - this.doc().offsetHeight) return n(!1);
3494
- this.doc().scrollTop = this.doc().scrollHeight - this.doc().offsetHeight, this.reportProgress(), n(!0);
3495
- }), e.register("unfocus", R.moduleName, (s, n) => {
3496
- T(this.wnd), n(!0);
3497
- }), e.register("scroll_protection", R.moduleName, (s, n) => {
3498
- this.enableScrollProtection(), n(!0);
3499
- }), e.register([
3500
- "go_next",
3501
- "go_prev"
3502
- ], R.moduleName, (s, n) => n(!1)), e.register("focus", R.moduleName, (s, n) => {
3503
- this.reportProgress(), n(!0);
3504
- }), e.register("first_visible_locator", R.moduleName, (s, n) => {
3505
- const o = wt(t, !0);
3506
- this.comms.send("first_visible_locator", o.serialize()), n(!0);
3507
- }), e.log("ScrollSnapper Mounted"), !0;
3508
- }
3509
- unmount(t, e) {
3510
- return e.unregisterAll(R.moduleName), this.resizeObserver.disconnect(), this.handleScroll && t.removeEventListener("scroll", this.handleScroll), t.document.getElementById(Ce)?.remove(), this.patternAnalyzer && (this.patternAnalyzer.clear(), this.patternAnalyzer = null, this.isScrollProtectionEnabled = !1), e.log("ScrollSnapper Unmounted"), !0;
3511
- }
3512
- };
3513
- R.moduleName = "scroll_snapper";
3514
- let kt = R;
3515
- const k = class k extends Q {
3516
- constructor() {
3517
- super(...arguments), this.patternAnalyzer = null, this.lastScrollTime = 0, this.isScrollProtectionEnabled = !1, this.initialScrollHandled = !1, this.isScrolling = !1, this.lastScrollTop = 0, this.isResizing = !1, this.resizeDebounce = null, this.handleScroll = (t) => {
3518
- if (this.comms.ready && !this.isResizing) {
3519
- if (!this.initialScrollHandled) {
3520
- this.lastScrollTop = this.doc().scrollTop, this.initialScrollHandled = !0, this.reportProgress();
3521
- return;
3522
- }
3523
- this.isScrolling || (this.isScrolling = !0, this.wnd.requestAnimationFrame(() => {
3524
- this.reportProgress();
3525
- const e = this.doc().scrollTop, i = e - this.lastScrollTop;
3526
- if (this.lastScrollTop = e, this.isScrollProtectionEnabled && Math.abs(i) > 5) {
3527
- const s = Date.now(), n = s - (this.lastScrollTime || s);
3528
- if (this.patternAnalyzer && this.patternAnalyzer.analyze(
3529
- i > 0 ? "down" : "up",
3530
- Math.abs(i),
3531
- n
3532
- )) {
3533
- const a = t.target && "tagName" in t.target ? { tagName: t.target.tagName } : null;
3534
- this.comms?.send("content_protection", {
3535
- type: "suspicious_scrolling",
3536
- timestamp: Date.now(),
3537
- scrollDelta: i,
3538
- scrollDirection: i > 0 ? "down" : "up",
3539
- targetElement: a
3540
- });
3541
- }
3542
- this.lastScrollTime = s;
3543
- }
3544
- this.comms.send("scroll", i), this.isScrolling = !1;
3545
- }));
3546
- }
3547
- };
3548
- }
3549
- doc() {
3550
- return this.wnd.document.scrollingElement;
3551
- }
3552
- reportProgress() {
3553
- if (!this.comms.ready) return;
3554
- const t = Math.ceil(this.doc().scrollTop), e = this.doc().scrollHeight, i = this.wnd.innerHeight, s = Math.max(0, Math.min(1, t / e)), n = Math.max(0, Math.min(1, (t + i) / e));
3555
- this.comms.send("progress", {
3556
- start: s,
3557
- end: n
3558
- });
3559
- }
3560
- enableScrollProtection() {
3561
- this.patternAnalyzer || (this.patternAnalyzer = new Et(Kt), this.isScrollProtectionEnabled = !0, this.comms?.log("Scroll protection enabled"));
3562
- }
3563
- mount(t, e) {
3564
- return this.wnd = t, this.comms = e, this.initialScrollHandled = !1, this.lastScrollTop = 0, this.isResizing = !1, this.resizeDebounce && (this.wnd.clearTimeout(this.resizeDebounce), this.resizeDebounce = null), this.resizeObserver = new ResizeObserver(() => {
3565
- this.resizeDebounce && this.wnd.clearTimeout(this.resizeDebounce), this.isResizing = !0, this.resizeDebounce = this.wnd.setTimeout(() => {
3566
- this.isResizing = !1, this.resizeDebounce = null, this.reportProgress();
3567
- }, 50);
3568
- }), this.resizeObserver.observe(t.document.body), t.addEventListener("scroll", this.handleScroll, { passive: !0 }), e.register("force_webkit_recalc", k.moduleName, () => {
3569
- Yt(this.wnd);
3570
- const i = this.doc().scrollTop;
3571
- i > 1 ? this.doc().scrollTop = i - 1 : this.doc().scrollTop = i + 1, this.doc().scrollTop = i;
3572
- }), e.register("go_progression", k.moduleName, (i, s) => {
3573
- const n = i;
3574
- if (n < 0 || n > 1) {
3575
- e.send("error", {
3576
- message: "go_progression must be given a position from 0.0 to 1.0"
3577
- }), s(!1);
3578
- return;
3579
- }
3580
- this.wnd.requestAnimationFrame(() => {
3581
- this.doc().scrollTop = this.doc().offsetHeight * n, this.reportProgress(), T(this.wnd), s(!0);
3582
- });
3583
- }), e.register("go_id", k.moduleName, (i, s) => {
3584
- const n = t.document.getElementById(i);
3585
- if (!n) {
3586
- s(!1);
3587
- return;
3588
- }
3589
- this.wnd.requestAnimationFrame(() => {
3590
- this.doc().scrollTop = n.getBoundingClientRect().top + t.scrollY - t.innerHeight / 2, this.reportProgress(), T(this.wnd), s(!0);
3591
- });
3592
- }), e.register("go_text", k.moduleName, (i, s) => {
3593
- let n;
3594
- Array.isArray(i) && (i.length > 1 && (n = i[1]), i = i[0]);
3595
- const o = $.deserialize(i), a = ct(this.wnd.document, new B({
3596
- href: t.location.href,
3597
- type: "text/html",
3598
- text: o,
3599
- locations: n ? new P({
3600
- otherLocations: /* @__PURE__ */ new Map([
3601
- ["cssSelector", n]
3602
- ])
3603
- }) : void 0
3604
- }));
3605
- if (!a) {
3606
- s(!1);
3607
- return;
3608
- }
3609
- this.wnd.requestAnimationFrame(() => {
3610
- this.doc().scrollTop = a.getBoundingClientRect().top + t.scrollY - t.innerHeight / 2, this.reportProgress(), T(this.wnd), s(!0);
3611
- });
3612
- }), e.register("go_start", k.moduleName, (i, s) => {
3613
- if (this.doc().scrollTop === 0) return s(!1);
3614
- this.doc().scrollTop = 0, this.reportProgress(), s(!0);
3615
- }), e.register("go_end", k.moduleName, (i, s) => {
3616
- if (this.doc().scrollTop === this.doc().scrollHeight - this.doc().offsetHeight) return s(!1);
3617
- this.doc().scrollTop = this.doc().scrollHeight - this.doc().offsetHeight, this.reportProgress(), s(!0);
3618
- }), e.register("unfocus", k.moduleName, (i, s) => {
3619
- T(this.wnd), s(!0);
3620
- }), e.register("scroll_protection", k.moduleName, (i, s) => {
3621
- this.enableScrollProtection(), s(!0);
3622
- }), e.register([
3623
- "go_next",
3624
- "go_prev"
3625
- ], k.moduleName, (i, s) => s(!1)), e.register("focus", k.moduleName, (i, s) => {
3626
- this.reportProgress(), s(!0);
3627
- }), e.register("first_visible_locator", k.moduleName, (i, s) => {
3628
- const n = wt(t, !0);
3629
- e.send("first_visible_locator", n.serialize()), s(!0);
3630
- }), e.log("WebPubSnapper Mounted"), !0;
3631
- }
3632
- unmount(t, e) {
3633
- return e.unregisterAll(k.moduleName), this.resizeObserver.disconnect(), this.handleScroll && t.removeEventListener("scroll", this.handleScroll), this.patternAnalyzer && (this.patternAnalyzer.clear(), this.patternAnalyzer = null, this.isScrollProtectionEnabled = !1), e.log("WebPubSnapper Unmounted"), !0;
3634
- }
3635
- };
3636
- k.moduleName = "webpub_snapper";
3637
- let It = k;
3638
- class $i {
3639
- constructor(t, e) {
3640
- this.window = t, this.copyHistory = [], this.lastSelectionLength = 0, this.lastSelectionTime = 0, this.options = e;
3641
- }
3642
- cleanupOldHistory(t) {
3643
- this.copyHistory = this.copyHistory.filter(
3644
- (i) => t - i.timestamp < 1e4
3645
- ), this.copyHistory.length > this.options.historySize && (this.copyHistory = this.copyHistory.slice(-this.options.historySize));
3646
- }
3647
- isSuspiciousPattern(t) {
3648
- return this.copyHistory.length < 3 ? !1 : this.copyHistory.filter(
3649
- (s) => t - s.timestamp < 2e3
3650
- // Last 2 seconds
3651
- ).length >= 3 ? !0 : this.copyHistory.slice().sort((s, n) => s.timestamp - n.timestamp).every((s, n, o) => n === 0 ? !0 : s.length > o[n - 1].length * 1.5);
3652
- }
3653
- shouldAllowCopy(t) {
3654
- if (!this.options.enabled) return !0;
3655
- const e = this.window.getSelection();
3656
- if (!e) return !0;
3657
- const s = e.toString().length, n = this.window.document.body.innerText.length, o = Date.now();
3658
- if (this.cleanupOldHistory(o), s < this.options.minThreshold)
3659
- return this.copyHistory.push({
3660
- timestamp: o,
3661
- length: s,
3662
- wasBlocked: !1
3663
- }), !0;
3664
- const l = o - this.lastSelectionTime < 100 && s > this.lastSelectionLength * 1.5, m = Math.min(
3665
- n * this.options.maxSelectionPercent,
3666
- this.options.absoluteMaxChars
3667
- ), c = this.isSuspiciousPattern(o), h = s > m || l || c;
3668
- return this.copyHistory.push({
3669
- timestamp: o,
3670
- length: s,
3671
- wasBlocked: h
3672
- }), h ? (t?.preventDefault(), !1) : (this.lastSelectionLength = s, this.lastSelectionTime = o, !0);
3673
- }
3674
- destroy() {
3675
- this.lastSelectionLength = 0, this.lastSelectionTime = 0, this.copyHistory = [], this.options.enabled = !1;
3676
- }
3677
- }
3678
- class Gi {
3679
- constructor(t = qe) {
3680
- this.options = t, this.events = [], this.selectionStartTime = 0, this.lastSelectionTime = 0, this.lastSelectionPosition = 0, this.selectionPatterns = [], this.lastSelectedText = "";
3681
- }
3682
- analyze(t) {
3683
- if (!t)
3684
- return this.clear(), !1;
3685
- const e = t.toString();
3686
- if (e.length === 0)
3687
- return this.clear(), !1;
3688
- if (t.type !== "Range" || !t.rangeCount)
3689
- return !1;
3690
- const i = Date.now();
3691
- if (e.length <= 50 || e === this.lastSelectedText)
3692
- return !1;
3693
- if (this.selectionStartTime === 0)
3694
- return this.selectionStartTime = i, this.lastSelectedText = e, !1;
3695
- if (i - this.selectionStartTime < 500)
3696
- return !1;
3697
- i - this.lastSelectionTime > 1e3 && (this.lastSelectionTime = i), this.selectionStartTime === 0 && (this.selectionStartTime = i), this.lastSelectedText = e;
3698
- const n = this.analyzeSelectionPattern(t, i);
3699
- return this.cleanup(i), n;
3700
- }
3701
- analyzeSelectionPattern(t, e) {
3702
- if (!t.rangeCount) return !1;
3703
- const i = t.getRangeAt(0), s = i.toString(), n = (e - this.selectionStartTime) / 1e3;
3704
- if (s.length / Math.max(1, n) > this.options.maxSelectionsPerSecond) return !0;
3705
- const a = i.startOffset, l = Math.abs(a - this.lastSelectionPosition);
3706
- return this.selectionPatterns.push(l), this.selectionPatterns.length > this.options.historySize && (this.selectionPatterns.shift(), this.calculateVariance(this.selectionPatterns) < this.options.minVariance) ? !0 : (this.lastSelectionPosition = a, !1);
3707
- }
3708
- calculateVariance(t) {
3709
- if (t.length === 0) return 0;
3710
- const e = t.reduce((i, s) => i + s, 0) / t.length;
3711
- return t.reduce((i, s) => i + Math.pow(s - e, 2), 0) / t.length;
3712
- }
3713
- cleanup(t) {
3714
- this.events = this.events.filter((e) => t - e.timestamp <= 1e3);
3715
- }
3716
- clear() {
3717
- this.events = [], this.selectionStartTime = 0, this.lastSelectionTime = 0, this.lastSelectionPosition = 0, this.selectionPatterns = [], this.lastSelectedText = "";
3718
- }
3719
- }
3720
- class qi {
3721
- /**
3722
- * Checks if the given keyboard event matches any of the provided key combinations
3723
- */
3724
- match(t, e) {
3725
- for (const i of e)
3726
- if (this.matchesCombo(t, i))
3727
- return !0;
3728
- return !1;
3729
- }
3730
- matchesCombo(t, e) {
3731
- return t.keyCode === e.keyCode && this.matchesModifier(t.ctrlKey, e.ctrl) && this.matchesModifier(t.shiftKey, e.shift) && this.matchesModifier(t.altKey, e.alt) && this.matchesModifier(t.metaKey, e.meta);
3732
- }
3733
- matchesModifier(t, e) {
3734
- return e === void 0 ? !t : t === e;
3735
- }
3736
- /**
3737
- * Creates an event handler that will call the provided handler when any of the key combinations match
3738
- */
3739
- createKeyHandler(t, e) {
3740
- return (i) => {
3741
- this.match(i, t) && (i.preventDefault(), i.stopPropagation(), e(i));
3742
- };
3743
- }
3744
- /**
3745
- * Creates a standardized activity event for keyboard shortcuts
3746
- */
3747
- createActivityEvent(t, e, i, s) {
3748
- let n, o;
3749
- if (s) {
3750
- const a = s.getSelection(), l = a?.toString() || "", c = (l && a?.rangeCount ? a.getRangeAt(0)?.getClientRects() : null)?.[0];
3751
- c && l && (n = {
3752
- text: l,
3753
- x: c.x,
3754
- y: c.y,
3755
- width: c.width,
3756
- height: c.height
3757
- });
3758
- const h = s.document.activeElement;
3759
- h && h !== s.document.body && (o = Xt(h)?.outerHTML);
3760
- }
3761
- return {
3762
- type: e,
3763
- timestamp: Date.now(),
3764
- key: t.key,
3765
- code: t.code,
3766
- keyCode: t.keyCode,
3767
- ctrlKey: t.ctrlKey,
3768
- altKey: t.altKey,
3769
- shiftKey: t.shiftKey,
3770
- metaKey: t.metaKey,
3771
- targetFrameSrc: i,
3772
- selectedText: n,
3773
- interactiveElement: o
3774
- };
3775
- }
3776
- /**
3777
- * Creates handlers for keyboard shortcuts with centralized activity event dispatch
3778
- */
3779
- createKeyboardHandlers(t, e, i, s) {
3780
- const n = [];
3781
- return e.forEach((o) => {
3782
- n.push(...o.keyCombos.map((a) => ({
3783
- ...a,
3784
- handler: (l) => {
3785
- const m = o.type, c = this.createActivityEvent(l, m, t, s);
3786
- i(c);
3787
- }
3788
- })));
3789
- }), n;
3790
- }
3791
- /**
3792
- * Creates a unified keyboard event handler that processes all shortcuts
3793
- */
3794
- createUnifiedHandler(t, e, i, s) {
3795
- const n = this.createKeyboardHandlers(t, e, i, s);
3796
- return (o) => {
3797
- if (o.isTrusted) {
3798
- for (const a of n)
3799
- if (this.match(o, [a])) {
3800
- const l = a.suppressOnInteractiveElement;
3801
- if (l) {
3802
- const m = (s?.document ?? document).activeElement;
3803
- if (Array.isArray(l) ? l.some((c) => m?.matches(c)) : $e(m)) return;
3804
- }
3805
- o.preventDefault(), o.stopPropagation(), a.handler(o);
3806
- return;
3807
- }
3808
- }
3809
- };
3810
- }
3811
- }
3812
- const q = class q extends tt {
3813
- constructor() {
3814
- super(...arguments), this.configApplied = !1, this.cleanupCallbacks = [], this.pointerMoved = !1, this.isContextMenuEnabled = !1, this.isDragAndDropEnabled = !1, this.isSelectionMonitoringEnabled = !1, this.isBulkCopyProtectionEnabled = !1, this.selectionAnalyzer = null, this.currentSelection = null, this.bulkCopyProtector = null, this.keyManager = new qi(), this.keyDownHandler = null, this.preventBulkCopy = (t) => {
3815
- if (!this.isBulkCopyProtectionEnabled || !this.bulkCopyProtector)
3816
- return !0;
3817
- if (!this.bulkCopyProtector.shouldAllowCopy(t)) {
3818
- t.preventDefault();
3819
- const e = this.wnd.getSelection(), i = e?.toString() || "", n = (i ? e?.getRangeAt(0)?.getClientRects() : null)?.[0], o = {
3820
- type: "bulk_copy",
3821
- timestamp: Date.now(),
3822
- clipboardTypes: t.clipboardData?.types ? [...t.clipboardData.types] : [],
3823
- selectedText: n ? {
3824
- text: i,
3825
- x: n.x,
3826
- y: n.y,
3827
- width: n.width,
3828
- height: n.height
3829
- } : void 0,
3830
- selectionLength: i.length,
3831
- targetFrameSrc: this.wnd.location.href
3832
- };
3833
- return this.comms?.send("content_protection", o), !1;
3834
- }
3835
- return !0;
3836
- }, this.handleSelection = (t) => {
3837
- if (!this.isSelectionMonitoringEnabled || !this.wnd || !this.selectionAnalyzer)
3838
- return;
3839
- const e = this.wnd.getSelection();
3840
- if (e) {
3841
- if (this.currentSelection = e.toString(), this.selectionAnalyzer.analyze(e) && this.currentSelection) {
3842
- const s = this.wnd.getSelection(), n = s?.toString() || "", a = (n && s?.rangeCount ? s.getRangeAt(0)?.getClientRects() : null)?.[0], l = {
3843
- type: "suspicious_selection",
3844
- timestamp: Date.now(),
3845
- selectionLength: n.length,
3846
- selectedText: {
3847
- text: n,
3848
- x: a?.x ?? 0,
3849
- y: a?.y ?? 0,
3850
- width: a?.width ?? 0,
3851
- height: a?.height ?? 0
3852
- },
3853
- eventType: t?.type || "selectionchange",
3854
- targetFrameSrc: this.wnd.location.href
3855
- };
3856
- this.comms?.send("content_protection", l);
3857
- }
3858
- } else
3859
- this.currentSelection = null;
3860
- }, this.onDragOver = (t) => {
3861
- this.isDragAndDropEnabled && (t.preventDefault(), t.stopPropagation());
3862
- }, this.onDragStart = (t) => {
3863
- if (this.isDragAndDropEnabled) {
3864
- t.preventDefault();
3865
- const e = {
3866
- type: "drag_detected",
3867
- timestamp: Date.now(),
3868
- dataTransferTypes: t.dataTransfer?.types ? [...t.dataTransfer.types] : [],
3869
- targetFrameSrc: this.wnd.location.href
3870
- };
3871
- return this.comms?.send("content_protection", e), !1;
3872
- } else
3873
- return !0;
3874
- }, this.onDrop = (t) => {
3875
- if (this.isDragAndDropEnabled) {
3876
- t.preventDefault();
3877
- const e = t.dataTransfer, i = {
3878
- type: "drop_detected",
3879
- timestamp: Date.now(),
3880
- dataTransferTypes: e?.types ? [...e.types] : [],
3881
- fileCount: e?.files?.length || 0,
3882
- targetFrameSrc: this.wnd.location.href
3883
- };
3884
- return this.comms?.send("content_protection", i), !1;
3885
- } else
3886
- return !0;
3887
- }, this.onContext = (t) => {
3888
- if (this.isContextMenuEnabled) {
3889
- t.preventDefault();
3890
- const e = this.wnd.getSelection(), i = e?.toString() || "", n = (i && e?.rangeCount ? e.getRangeAt(0)?.getClientRects() : null)?.[0], o = {
3891
- timestamp: Date.now(),
3892
- clientX: t.clientX,
3893
- clientY: t.clientY,
3894
- ...n && {
3895
- selectedText: {
3896
- text: i,
3897
- x: n.x,
3898
- y: n.y,
3899
- width: n.width,
3900
- height: n.height
3901
- }
3902
- },
3903
- targetFrameSrc: this.wnd.location.href
3904
- };
3905
- this.comms?.send("context_menu", o);
3906
- }
3907
- }, this.onPointerUp = this.onPointUp.bind(this), this.onPointerMove = this.onPointMove.bind(this), this.onPointerDown = this.onPointDown.bind(this), this.onClicker = this.onClick.bind(this);
3908
- }
3909
- addContextMenuPrevention() {
3910
- this.isContextMenuEnabled || !this.wnd || (this.wnd.document.addEventListener("contextmenu", this.onContext), this.isContextMenuEnabled = !0);
3911
- }
3912
- removeContextMenuPrevention() {
3913
- !this.isContextMenuEnabled || !this.wnd || (this.wnd.document.removeEventListener("contextmenu", this.onContext), this.isContextMenuEnabled = !1);
3914
- }
3915
- addDragAndDropPrevention() {
3916
- this.isDragAndDropEnabled || !this.wnd || (this.wnd.document.addEventListener("dragstart", this.onDragStart), this.wnd.document.addEventListener("dragover", this.onDragOver), this.wnd.document.addEventListener("drop", this.onDrop), this.isDragAndDropEnabled = !0);
3917
- }
3918
- removeDragAndDropPrevention() {
3919
- !this.isDragAndDropEnabled || !this.wnd || (this.wnd.document.removeEventListener("dragstart", this.onDragStart), this.wnd.document.removeEventListener("dragover", this.onDragOver), this.wnd.document.removeEventListener("drop", this.onDrop), this.isDragAndDropEnabled = !1);
3920
- }
3921
- enableKeyboardPeripherals(t = []) {
3922
- this.disableKeyboardPeripherals();
3923
- const e = (i) => {
3924
- this.comms?.send("keyboard_peripherals", i);
3925
- };
3926
- this.keyDownHandler = this.keyManager.createUnifiedHandler(this.wnd.location.href, t, e, this.wnd), this.wnd && this.wnd.document.addEventListener("keydown", this.keyDownHandler, {
3927
- capture: !0
3928
- });
3929
- }
3930
- disableKeyboardPeripherals() {
3931
- this.wnd && this.keyDownHandler && (this.wnd.document.removeEventListener("keydown", this.keyDownHandler, {
3932
- capture: !0
3933
- }), this.keyDownHandler = null);
3934
- }
3935
- addBulkCopyProtection(t = {}) {
3936
- if (this.isBulkCopyProtectionEnabled || !this.wnd) return;
3937
- const e = Fi, i = t ? { ...e, ...t } : e;
3938
- this.bulkCopyProtector = new $i(this.wnd, i), this.wnd.document.addEventListener("copy", this.preventBulkCopy, !0), this.wnd.document.addEventListener("cut", this.preventBulkCopy, !0), this.isBulkCopyProtectionEnabled = !0;
3939
- }
3940
- removeBulkCopyProtection() {
3941
- !this.isBulkCopyProtectionEnabled || !this.wnd || (this.wnd.document.removeEventListener("copy", this.preventBulkCopy, !0), this.wnd.document.removeEventListener("cut", this.preventBulkCopy, !0), this.bulkCopyProtector?.destroy(), this.bulkCopyProtector = null, this.isBulkCopyProtectionEnabled = !1);
3942
- }
3943
- addSelectionMonitoring(t) {
3944
- if (this.isSelectionMonitoringEnabled || !this.wnd) return;
3945
- const e = t || qe;
3946
- this.selectionAnalyzer = new Gi(e), this.wnd.document.addEventListener("selectionchange", this.handleSelection), this.isSelectionMonitoringEnabled = !0;
3947
- }
3948
- removeSelectionMonitoring() {
3949
- !this.isSelectionMonitoringEnabled || !this.wnd || (this.wnd.document.removeEventListener("selectionchange", this.handleSelection), this.selectionAnalyzer?.clear(), this.selectionAnalyzer = null, this.isSelectionMonitoringEnabled = !1);
3950
- }
3951
- onPointUp(t) {
3952
- const e = this.wnd.getSelection();
3953
- if (e && e.toString()?.length > 0) {
3954
- const s = e.getRangeAt(0)?.getClientRects();
3955
- if (!s || s.length === 0)
3956
- return;
3957
- const n = s[0], o = {
3958
- text: e.toString(),
3959
- x: n.x,
3960
- y: n.y,
3961
- width: n.width,
3962
- height: n.height,
3963
- targetFrameSrc: this.wnd?.location?.href
3964
- };
3965
- this.comms.send("text_selected", o);
3966
- }
3967
- if (this.pointerMoved) {
3968
- this.pointerMoved = !1;
3969
- return;
3970
- }
3971
- if (!e?.isCollapsed || !t.isPrimary) return;
3972
- const i = this.wnd.devicePixelRatio;
3973
- t.preventDefault(), this.comms.send(t.pointerType === "touch" ? "tap" : "click", {
3974
- defaultPrevented: t.defaultPrevented,
3975
- x: t.clientX * i,
3976
- y: t.clientY * i,
3977
- targetFrameSrc: this.wnd.location.href,
3978
- targetElement: t.target.outerHTML,
3979
- interactiveElement: Xt(t.target)?.outerHTML,
3980
- cssSelector: this.wnd._readium_cssSelectorGenerator.getCssSelector(t.target)
3981
- }), this.pointerMoved = !1;
3982
- }
3983
- onPointMove(t) {
3984
- if (t.movementY !== void 0 && t.movementX !== void 0) {
3985
- (Math.abs(t.movementX) > 1 || Math.abs(t.movementY) > 1) && (this.pointerMoved = !0);
3986
- return;
3987
- }
3988
- this.pointerMoved = !0;
3989
- }
3990
- onPointDown() {
3991
- this.pointerMoved = !1;
3992
- }
3993
- onClick(t) {
3994
- if (t.preventDefault(), !t.isTrusted) {
3995
- const e = new PointerEvent("pointerup", {
3996
- isPrimary: !0,
3997
- pointerType: "mouse",
3998
- // Not really a better choice than this
3999
- clientX: t.clientX,
4000
- clientY: t.clientY
4001
- });
4002
- Object.defineProperty(e, "target", { writable: !1, value: t.target }), Object.defineProperty(e, "defaultPrevented", { writable: !1, value: t.defaultPrevented }), this.onPointUp(e);
4003
- }
4004
- }
4005
- registerProtectionHandlers() {
4006
- this.comms?.register("peripherals_protection", q.moduleName, (t, e) => {
4007
- const i = t;
4008
- if (!this.configApplied) {
4009
- if (this.configApplied = !0, i.monitorSelection) {
4010
- const s = typeof i.monitorSelection == "boolean" ? void 0 : i.monitorSelection;
4011
- this.addSelectionMonitoring(s), this.comms?.log("Selection monitoring enabled");
4012
- }
4013
- typeof i.protectCopy == "object" ? (this.addBulkCopyProtection({
4014
- enabled: !0,
4015
- ...i.protectCopy
4016
- }), this.comms?.log("Copy protection enabled (limited)")) : i.protectCopy === !0 && (this.addBulkCopyProtection({
4017
- enabled: !0,
4018
- maxSelectionPercent: 0,
4019
- minThreshold: 0,
4020
- absoluteMaxChars: 0
4021
- }), this.comms?.log("Copy protection enabled")), i.disableContextMenu && (this.addContextMenuPrevention(), this.comms?.log("Context menu protection enabled")), i.disableDragAndDrop && (this.addDragAndDropPrevention(), this.comms?.log("Drag and drop protection enabled"));
4022
- }
4023
- e(!0);
4024
- }), this.comms?.register("unfocus", q.moduleName, (t, e) => {
4025
- this.disableKeyboardPeripherals(), e(!0);
4026
- }), this.comms?.register("keyboard_peripherals", q.moduleName, (t, e) => {
4027
- const i = t;
4028
- i && i.length > 0 && (this.enableKeyboardPeripherals(i), this.comms?.log(`Keyboard peripherals enabled: ${i.map((s) => s.type).join(", ")}`)), e(!0);
4029
- });
4030
- }
4031
- mount(t, e) {
4032
- return this.wnd = t, this.comms = e, this.registerProtectionHandlers(), t.document.addEventListener("pointerdown", this.onPointerDown), t.document.addEventListener("pointerup", this.onPointerUp), t.document.addEventListener("pointermove", this.onPointerMove), t.document.addEventListener("click", this.onClicker), e.log("Peripherals Mounted"), !0;
4033
- }
4034
- unmount(t, e) {
4035
- return this.removeBulkCopyProtection(), this.removeSelectionMonitoring(), this.removeContextMenuPrevention(), this.removeDragAndDropPrevention(), this.disableKeyboardPeripherals(), this.cleanupCallbacks.forEach((i) => i()), this.cleanupCallbacks = [], t.document.removeEventListener("pointerdown", this.onPointerDown), t.document.removeEventListener("pointerup", this.onPointerUp), t.document.removeEventListener("pointermove", this.onPointerMove), t.document.removeEventListener("click", this.onClicker), e.unregisterAll(q.moduleName), this.configApplied = !1, e.log("Peripherals Unmounted"), !0;
4036
- }
4037
- };
4038
- q.moduleName = "peripherals";
4039
- let Dt = q;
4040
- const rt = class rt extends tt {
4041
- constructor() {
4042
- super(...arguments), this.mediaPlayingCount = 0, this.allAnimations = /* @__PURE__ */ new Set();
4043
- }
4044
- wndOnErr(t) {
4045
- this.comms?.send("error", {
4046
- message: t.message,
4047
- filename: t.filename,
4048
- lineno: t.lineno,
4049
- colno: t.colno
4050
- });
4051
- }
4052
- unblock(t) {
4053
- for (t._readium_blockEvents = !1; t._readium_blockedEvents?.length > 0; ) {
4054
- const e = t._readium_blockedEvents.shift();
4055
- switch (e[0]) {
4056
- case 0:
4057
- Reflect.apply(e[1], e[2], e[3]);
4058
- break;
4059
- case 1:
4060
- const i = e[1], s = e[2];
4061
- t.removeEventListener(i.type, t._readium_eventBlocker, !0);
4062
- const n = new Event(i.type, {
4063
- bubbles: i.bubbles,
4064
- cancelable: i.cancelable
4065
- });
4066
- s ? s.dispatchEvent(n) : t.dispatchEvent(n);
4067
- break;
4068
- }
4069
- }
4070
- }
4071
- onMediaPlayEvent() {
4072
- this.mediaPlayingCount++, this.comms?.send("media_play", this.mediaPlayingCount);
4073
- }
4074
- onMediaPauseEvent() {
4075
- this.mediaPlayingCount > 0 && this.mediaPlayingCount--, this.comms?.send("media_pause", this.mediaPlayingCount);
4076
- }
4077
- pauseAllMedia(t) {
4078
- const e = t.document.querySelectorAll("audio,video");
4079
- for (let i = 0; i < e.length; i++)
4080
- e[i].pause();
4081
- }
4082
- mount(t, e) {
4083
- this.comms = e, t.addEventListener(
4084
- "error",
4085
- this.wndOnErr,
4086
- !1
4087
- ), Reflect.defineProperty(t.navigator, "epubReadingSystem", {
4088
- value: {
4089
- name: "readium-ts-toolkit",
4090
- version: "2.5.0",
4091
- hasFeature: (s, n = "") => {
4092
- switch (s) {
4093
- case "dom-manipulation":
4094
- return !0;
4095
- case "layout-changes":
4096
- return !0;
4097
- case "touch-events":
4098
- return !0;
4099
- case "mouse-events":
4100
- return !0;
4101
- case "keyboard-events":
4102
- return !0;
4103
- case "spine-scripting":
4104
- return !0;
4105
- case "embedded-web-content":
4106
- return !0;
4107
- default:
4108
- return !1;
4109
- }
4110
- }
4111
- },
4112
- writable: !1
4113
- }), "getAnimations" in t.document && t.document.getAnimations().forEach((s) => {
4114
- s.cancel(), this.allAnimations.add(s);
4115
- }), e.register("activate", rt.moduleName, (s, n) => {
4116
- this.allAnimations.forEach((o) => {
4117
- o.cancel(), o.play();
4118
- }), n(!0);
4119
- }), e.register("unfocus", rt.moduleName, (s, n) => {
4120
- this.pauseAllMedia(t), this.allAnimations.forEach((o) => o.pause()), n(!0);
4121
- });
4122
- const i = t.document.querySelectorAll("audio,video");
4123
- for (let s = 0; s < i.length; s++) {
4124
- const n = i[s];
4125
- n.addEventListener("play", this.onMediaPlayEvent, {
4126
- passive: !0
4127
- }), n.addEventListener("pause", this.onMediaPauseEvent, {
4128
- passive: !0
4129
- });
4130
- }
4131
- return e.log("Setup Mounted"), !0;
4132
- }
4133
- unmount(t, e) {
4134
- return t.removeEventListener("error", this.wndOnErr), t.removeEventListener("play", this.onMediaPlayEvent), t.removeEventListener("pause", this.onMediaPauseEvent), this.allAnimations.forEach((i) => i.cancel()), this.allAnimations.clear(), e.log("Setup Unmounted"), !0;
4135
- }
4136
- };
4137
- rt.moduleName = "setup";
4138
- let vt = rt;
4139
- const xe = "readium-viewport", _ = class _ extends vt {
4140
- onViewportWidthChanged(t) {
4141
- const e = t.target;
4142
- at(e, "--RS__viewportWidth", `${e.innerWidth}px`);
4143
- }
4144
- mount(t, e) {
4145
- if (!super.mount(t, e)) return !1;
4146
- const i = t.document.createElement("meta");
4147
- return i.dataset.readium = "true", i.setAttribute("name", "viewport"), i.setAttribute("id", xe), i.setAttribute(
4148
- "content",
4149
- "width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no, shrink-to-fit=no"
4150
- ), t.document.head.appendChild(i), t.addEventListener("orientationchange", this.onViewportWidthChanged), t.addEventListener("resize", this.onViewportWidthChanged), this.onViewportWidthChanged({
4151
- target: t
4152
- }), e.register("get_properties", _.moduleName, (s, n) => {
4153
- qt(t), n(!0);
4154
- }), e.register("update_properties", _.moduleName, (s, n) => {
4155
- s["--RS__viewportWidth"] = `${t.innerWidth}px`, We(t, s), n(!0);
4156
- }), e.register("set_property", _.moduleName, (s, n) => {
4157
- const o = s;
4158
- at(t, o[0], o[1]), n(!0);
4159
- }), e.register("remove_property", _.moduleName, (s, n) => {
4160
- St(t, s), n(!0);
4161
- }), e.register("activate", _.moduleName, (s, n) => {
4162
- this.unblock(t), n(!0);
4163
- }), e.log("ReflowableSetup Mounted"), !0;
4164
- }
4165
- unmount(t, e) {
4166
- return e.unregisterAll(_.moduleName), t.document.head.querySelector(`#${xe}`)?.remove(), t.removeEventListener("orientationchange", this.onViewportWidthChanged), e.log("ReflowableSetup Unmounted"), super.unmount(t, e);
4167
- }
4168
- };
4169
- _.moduleName = "reflowable_setup";
4170
- let zt = _;
4171
- const Te = "readium-fixed-style", W = class W extends vt {
4172
- mount(t, e) {
4173
- if (!super.mount(t, e)) return !1;
4174
- t.navigator.epubReadingSystem && (t.navigator.epubReadingSystem.layoutStyle = "paginated");
4175
- const i = t.document.createElement("style");
4176
- return i.id = Te, i.dataset.readium = "true", i.textContent = `
4177
- html, body {
4178
- text-size-adjust: none;
4179
- -ms-text-size-adjust: none;
4180
- -webkit-text-size-adjust: none;
4181
- -moz-text-size-adjust: none;
4182
-
4183
- /* Fight Safari pinches */
4184
- touch-action: none !important;
4185
- min-height: 100%;
4186
-
4187
- /*cursor: var() TODO*/
4188
- }`, t.document.head.appendChild(i), e.register("set_property", W.moduleName, (s, n) => {
4189
- const o = s;
4190
- at(t, o[0], o[1]), n(!0);
4191
- }), e.register("remove_property", W.moduleName, (s, n) => {
4192
- St(t, s), n(!0);
4193
- }), e.register("first_visible_locator", W.moduleName, (s, n) => n(!1)), e.register("unfocus", W.moduleName, (s, n) => {
4194
- T(t), n(!0);
4195
- }), e.register([
4196
- "focus",
4197
- "go_next",
4198
- "go_prev",
4199
- "go_id",
4200
- "go_end",
4201
- "go_start",
4202
- "go_text",
4203
- "go_progression"
4204
- ], W.moduleName, (s, n) => n(!0)), e.register("activate", W.moduleName, (s, n) => {
4205
- this.unblock(t), n(!0);
4206
- }), e.log("FixedSetup Mounted"), !0;
4207
- }
4208
- unmount(t, e) {
4209
- return e.unregisterAll(W.moduleName), t.document.getElementById(Te)?.remove(), e.log("FixedSetup Unmounted"), super.unmount(t, e);
4210
- }
4211
- };
4212
- W.moduleName = "fixed_setup";
4213
- let Mt = W;
4214
- const F = class F extends tt {
4215
- wndOnErr(t) {
4216
- this.comms?.send("error", {
4217
- message: t.message,
4218
- filename: t.filename,
4219
- lineno: t.lineno,
4220
- colno: t.colno
4221
- });
4222
- }
4223
- mount(t, e) {
4224
- return this.comms = e, t.addEventListener(
4225
- "error",
4226
- this.wndOnErr,
4227
- !1
4228
- ), e.register("get_properties", F.moduleName, (i, s) => {
4229
- qt(t), s(!0);
4230
- }), e.register("update_properties", F.moduleName, (i, s) => {
4231
- We(t, i), s(!0);
4232
- }), e.register("set_property", F.moduleName, (i, s) => {
4233
- const n = i;
4234
- at(t, n[0], n[1]), s(!0);
4235
- }), e.register("remove_property", F.moduleName, (i, s) => {
4236
- St(t, i), s(!0);
4237
- }), e.register("activate", F.moduleName, (i, s) => {
4238
- s(!0);
4239
- }), e.log("WebPubSetup Mounted"), !0;
4240
- }
4241
- unmount(t, e) {
4242
- return e.unregisterAll(F.moduleName), t.removeEventListener("error", this.wndOnErr), e.log("WebPubSetup Unmounted"), !0;
4243
- }
4244
- };
4245
- F.moduleName = "webpub_setup";
4246
- let Wt = F;
4247
- const ot = class ot extends tt {
4248
- constructor() {
4249
- super(...arguments), this.styleElement = null, this.beforePrintHandler = null, this.configApplied = !1;
4250
- }
4251
- setupPrintProtection(t, e) {
4252
- if (!e.disable) return;
4253
- const i = t.document.createElement("style");
4254
- i.textContent = `
4255
- @media print {
4256
- body * {
4257
- display: none !important;
4258
- }
4259
- body::after {
4260
- content: "${e.watermark || "Printing has been disabled"}";
4261
- font-size: 200%;
4262
- display: block;
4263
- text-align: center;
4264
- margin-top: 50vh;
4265
- transform: translateY(-50%);
4266
- }
4267
- }
4268
- `, t.document.head.appendChild(i), this.styleElement = i, this.beforePrintHandler = (s) => (s.preventDefault(), !1), t.addEventListener("beforeprint", this.beforePrintHandler);
4269
- }
4270
- registerPrintHandlers() {
4271
- this.comms?.register("print_protection", ot.moduleName, (t) => {
4272
- const e = t;
4273
- return this.configApplied || (this.configApplied = !0, this.setupPrintProtection(this.wnd, e), this.comms?.log("Print protection configuration applied")), !0;
4274
- });
4275
- }
4276
- mount(t, e) {
4277
- return this.wnd = t, this.comms = e, this.registerPrintHandlers(), !0;
4278
- }
4279
- unmount(t, e) {
4280
- return this.beforePrintHandler && (t.removeEventListener("beforeprint", this.beforePrintHandler), this.beforePrintHandler = null), this.styleElement?.parentNode && (this.styleElement.parentNode.removeChild(this.styleElement), this.styleElement = null), this.comms?.unregisterAll(ot.moduleName), this.configApplied = !1, !0;
4281
- }
4282
- };
4283
- ot.moduleName = "print_protection";
4284
- let Ht = ot;
4285
- const Pe = "readium-cjk-vertical-snapper-style", I = class I extends Q {
4286
- constructor() {
4287
- super(...arguments), this.patternAnalyzer = null, this.lastScrollTime = 0, this.isScrollProtectionEnabled = !1, this.initialScrollHandled = !1, this.isScrolling = !1, this.lastScrollLeft = 0, this.isResizing = !1, this.resizeDebounce = null, this.verticalLR = !1, this.handleScroll = (t) => {
4288
- if (this.comms.ready && !this.isResizing) {
4289
- if (!this.initialScrollHandled) {
4290
- this.lastScrollLeft = Math.abs(this.doc().scrollLeft), this.initialScrollHandled = !0, this.reportProgress();
4291
- return;
4292
- }
4293
- this.isScrolling || (this.isScrolling = !0, this.wnd.requestAnimationFrame(() => {
4294
- this.reportProgress();
4295
- const e = Math.abs(this.doc().scrollLeft), i = e - this.lastScrollLeft;
4296
- if (this.lastScrollLeft = e, this.isScrollProtectionEnabled && Math.abs(i) > 5) {
4297
- const s = Date.now(), n = s - (this.lastScrollTime || s);
4298
- if (this.patternAnalyzer && this.patternAnalyzer.analyze(
4299
- // In vertical-rl, norm increases when scrolling forward (toward left/end),
4300
- // so deltaX > 0 = going forward.
4301
- i > 0 ? "down" : "up",
4302
- Math.abs(i),
4303
- n
4304
- )) {
4305
- const a = t.target && "tagName" in t.target ? { tagName: t.target.tagName } : null;
4306
- this.comms?.send("content_protection", {
4307
- type: "suspicious_scrolling",
4308
- timestamp: Date.now(),
4309
- scrollDelta: i,
4310
- scrollDirection: i > 0 ? "left" : "right",
4311
- targetElement: a
4312
- });
4313
- }
4314
- this.lastScrollTime = s;
4315
- }
4316
- this.comms.send("scroll", i), this.isScrolling = !1;
4317
- }));
4318
- }
4319
- };
4320
- }
4321
- doc() {
4322
- return this.wnd.document.scrollingElement;
4323
- }
4324
- /** Total horizontally scrollable distance (magnitude). */
4325
- scrollable() {
4326
- return Math.max(0, this.doc().scrollWidth - this.wnd.innerWidth);
4327
- }
4328
- reportProgress() {
4329
- if (!this.comms.ready) return;
4330
- const t = this.doc().scrollWidth, e = this.wnd.innerWidth, i = Math.max(1, t - e), s = Math.abs(this.doc().scrollLeft), n = Math.max(0, Math.min(1, s / i)), o = Math.max(0, Math.min(1, (s + e) / t));
4331
- this.comms.send("progress", {
4332
- start: n,
4333
- end: o
4334
- });
4335
- }
4336
- enableScrollProtection() {
4337
- this.patternAnalyzer || (this.patternAnalyzer = new Et(Kt), this.isScrollProtectionEnabled = !0, this.comms?.log("Scroll protection enabled"));
4338
- }
4339
- mount(t, e) {
4340
- this.wnd = t, this.comms = e, this.initialScrollHandled = !1, this.lastScrollLeft = 0, this.isResizing = !1, this.verticalLR = Be(t), this.resizeDebounce && (this.wnd.clearTimeout(this.resizeDebounce), this.resizeDebounce = null), t.navigator.epubReadingSystem && (t.navigator.epubReadingSystem.layoutStyle = "scrolling");
4341
- const i = t.document.createElement("style");
4342
- return i.dataset.readium = "true", i.id = Pe, i.textContent = `
4343
- * {
4344
- scrollbar-width: none;
4345
- }
4346
- body::-webkit-scrollbar {
4347
- display: none;
4348
- }
4349
- html {
4350
- overflow-x: auto !important;
4351
- overflow-y: hidden !important;
4352
- }
4353
- `, t.document.head.appendChild(i), this.resizeObserver = new ResizeObserver(() => {
4354
- this.resizeDebounce && this.wnd.clearTimeout(this.resizeDebounce), this.isResizing = !0, this.resizeDebounce = this.wnd.setTimeout(() => {
4355
- this.isResizing = !1, this.resizeDebounce = null, this.reportProgress();
4356
- }, 50);
4357
- }), this.resizeObserver.observe(t.document.body), t.addEventListener("scroll", this.handleScroll, { passive: !0 }), e.register("force_webkit_recalc", I.moduleName, () => {
4358
- Yt(this.wnd);
4359
- const s = this.doc().scrollLeft;
4360
- this.verticalLR ? this.doc().scrollLeft = s > 1 ? s - 1 : s + 1 : this.doc().scrollLeft = s < -1 ? s + 1 : s - 1, this.doc().scrollLeft = s;
4361
- }), e.register("go_progression", I.moduleName, (s, n) => {
4362
- const o = s;
4363
- if (o < 0 || o > 1) {
4364
- e.send("error", {
4365
- message: "go_progression must be given a position from 0.0 to 1.0"
4366
- }), n(!1);
4367
- return;
4368
- }
4369
- this.wnd.requestAnimationFrame(() => {
4370
- const a = this.scrollable() * o;
4371
- this.doc().scrollLeft = this.verticalLR ? a : -a, this.reportProgress(), T(this.wnd), n(!0);
4372
- });
4373
- }), e.register("go_id", I.moduleName, (s, n) => {
4374
- const o = t.document.getElementById(s);
4375
- if (!o) {
4376
- n(!1);
4377
- return;
4378
- }
4379
- this.wnd.requestAnimationFrame(() => {
4380
- this.doc().scrollLeft += o.getBoundingClientRect().left - t.innerWidth / 2, this.reportProgress(), T(this.wnd), n(!0);
4381
- });
4382
- }), e.register("go_text", I.moduleName, (s, n) => {
4383
- let o;
4384
- Array.isArray(s) && (s.length > 1 && (o = s[1]), s = s[0]);
4385
- const a = $.deserialize(s), l = ct(this.wnd.document, new B({
4386
- href: t.location.href,
4387
- type: "text/html",
4388
- text: a,
4389
- locations: o ? new P({
4390
- otherLocations: /* @__PURE__ */ new Map([["cssSelector", o]])
4391
- }) : void 0
4392
- }));
4393
- if (!l) {
4394
- n(!1);
4395
- return;
4396
- }
4397
- this.wnd.requestAnimationFrame(() => {
4398
- this.doc().scrollLeft += l.getBoundingClientRect().left - t.innerWidth / 2, this.reportProgress(), T(this.wnd), n(!0);
4399
- });
4400
- }), e.register("go_start", I.moduleName, (s, n) => {
4401
- if (this.doc().scrollLeft === 0) return n(!1);
4402
- this.doc().scrollLeft = 0, this.reportProgress(), n(!0);
4403
- }), e.register("go_end", I.moduleName, (s, n) => {
4404
- if (Math.abs(this.doc().scrollLeft) === this.scrollable()) return n(!1);
4405
- this.doc().scrollLeft = this.verticalLR ? this.scrollable() : -this.scrollable(), this.reportProgress(), n(!0);
4406
- }), e.register([
4407
- "go_next",
4408
- "go_prev"
4409
- ], I.moduleName, (s, n) => n(!1)), e.register("unfocus", I.moduleName, (s, n) => {
4410
- T(this.wnd), n(!0);
4411
- }), e.register("scroll_protection", I.moduleName, (s, n) => {
4412
- this.enableScrollProtection(), n(!0);
4413
- }), e.register("focus", I.moduleName, (s, n) => {
4414
- this.reportProgress(), n(!0);
4415
- }), e.register("first_visible_locator", I.moduleName, (s, n) => {
4416
- const o = wt(t, !0);
4417
- this.comms.send("first_visible_locator", o.serialize()), n(!0);
4418
- }), e.log("CJKVerticalSnapper Mounted"), !0;
4419
- }
4420
- unmount(t, e) {
4421
- return e.unregisterAll(I.moduleName), this.resizeObserver.disconnect(), this.handleScroll && t.removeEventListener("scroll", this.handleScroll), t.document.getElementById(Pe)?.remove(), this.patternAnalyzer && (this.patternAnalyzer.clear(), this.patternAnalyzer = null, this.isScrollProtectionEnabled = !1), e.log("CJKVerticalSnapper Unmounted"), !0;
4422
- }
4423
- };
4424
- I.moduleName = "cjk_vertical_snapper";
4425
- let Bt = I;
4426
- const Xi = [
4427
- "fixed_setup",
4428
- "decorator",
4429
- "peripherals",
4430
- "print_protection"
4431
- ], Ki = [
4432
- "reflowable_setup",
4433
- "decorator",
4434
- "peripherals",
4435
- "column_snapper",
4436
- "scroll_snapper",
4437
- "cjk_vertical_snapper",
4438
- "print_protection"
4439
- ], Zi = [
4440
- "webpub_setup",
4441
- "webpub_snapper",
4442
- "decorator",
4443
- "peripherals",
4444
- "print_protection"
4445
- ], Ne = new Map([
4446
- // All modules go here
4447
- Mt,
4448
- zt,
4449
- Wt,
4450
- It,
4451
- Dt,
4452
- Ot,
4453
- Rt,
4454
- kt,
4455
- Bt,
4456
- Ht
4457
- ].map((r) => [r.moduleName, r]));
4458
- class Ji {
4459
- /**
4460
- * @param wnd Window instance to operate on
4461
- * @param initialModules List of initial modules to load
4462
- */
4463
- constructor(t = window, e = []) {
4464
- this.loadedModules = [], this.wnd = t, this.comms = new Ke(t);
4465
- const i = [...new Set(e)];
4466
- if (i.length) {
4467
- if (typeof t > "u")
4468
- throw Error("Loader is not in a web browser");
4469
- t.parent !== t && this.comms.log("Loader is probably in a frame"), this.loadedModules = i.map((s) => {
4470
- const n = this.loadModule(s);
4471
- if (n)
4472
- return n.mount(this.wnd, this.comms), n;
4473
- }).filter((s) => s !== void 0);
4474
- }
4475
- }
4476
- loadModule(t) {
4477
- const e = Ne.get(t);
4478
- return e === void 0 ? (this.comms.log(`Module "${name}" does not exist in the library`), e) : new e();
4479
- }
4480
- /**
4481
- * Add a module by name
4482
- * @param moduleName Module name
4483
- * @returns Success
4484
- */
4485
- addModule(t) {
4486
- const e = this.loadModule(t);
4487
- return !e || !e.mount(this.wnd, this.comms) ? !1 : (this.loadedModules.push(e), !0);
4488
- }
4489
- /**
4490
- * Remove a module by name
4491
- * @param moduleName Module name
4492
- * @returns Success
4493
- */
4494
- removeModule(t) {
4495
- const e = Ne.get(t);
4496
- if (e === void 0)
4497
- return this.comms.log(`Module "${t}" does not exist in the library`), !1;
4498
- const i = this.loadedModules.findIndex((s) => s instanceof e);
4499
- return i < 0 ? !1 : (this.loadedModules[i].unmount(this.wnd, this.comms), this.loadedModules.splice(i, 1), !0);
4500
- }
4501
- /**
4502
- * Unmount and remove all modules
4503
- */
4504
- destroy() {
4505
- this.comms.destroy(), this.loadedModules.forEach((t) => t.unmount(this.wnd, this.comms)), this.loadedModules = [];
4506
- }
4507
- }
4508
- const ji = {
4509
- type: "developer_tools",
4510
- keyCombos: [
4511
- { keyCode: 73, meta: !0, alt: !0 },
4512
- // Cmd+Option+I
4513
- { keyCode: 73, ctrl: !0, shift: !0 },
4514
- // Ctrl+Shift+I
4515
- { keyCode: 74, meta: !0, alt: !0 },
4516
- // Cmd+Option+J
4517
- { keyCode: 74, ctrl: !0, shift: !0 },
4518
- // Ctrl+Shift+J
4519
- { keyCode: 85, meta: !0, alt: !0 },
4520
- // Cmd+Option+U
4521
- { keyCode: 67, meta: !0, alt: !0 },
4522
- // Cmd+Option+C
4523
- { keyCode: 67, meta: !0, shift: !0 },
4524
- // Cmd+Shift+C
4525
- { keyCode: 67, ctrl: !0, shift: !0 },
4526
- // Ctrl+Shift+C
4527
- { keyCode: 65, meta: !0, alt: !0 },
4528
- // Cmd+Option+A
4529
- { keyCode: 84, meta: !0, shift: !0, alt: !0 },
4530
- // Cmd+Shift+Option+T
4531
- { keyCode: 67, shift: !0, alt: !0 },
4532
- // Shift+Option+C
4533
- { keyCode: 123 },
4534
- // F12
4535
- { keyCode: 123, shift: !0 },
4536
- // Shift+F12
4537
- { keyCode: 123, ctrl: !0, shift: !0 },
4538
- // Ctrl+Shift+F12
4539
- { keyCode: 123, meta: !0, alt: !0 }
4540
- // Cmd+Option+F12
4541
- ]
4542
- }, Qi = {
4543
- type: "select_all",
4544
- keyCombos: [
4545
- { keyCode: 65, meta: !0 },
4546
- // Cmd+A
4547
- { keyCode: 65, ctrl: !0 }
4548
- // Ctrl+A
4549
- ]
4550
- }, ts = {
4551
- type: "print",
4552
- keyCombos: [
4553
- { keyCode: 80, meta: !0 },
4554
- // Cmd+P
4555
- { keyCode: 80, ctrl: !0 },
4556
- // Ctrl+P
4557
- { keyCode: 80, meta: !0, shift: !0 },
4558
- // Cmd+Shift+P
4559
- { keyCode: 80, ctrl: !0, shift: !0 },
4560
- // Ctrl+Shift+P
4561
- { keyCode: 80, meta: !0, alt: !0 },
4562
- // Cmd+Alt+P
4563
- { keyCode: 80, ctrl: !0, alt: !0 }
4564
- // Ctrl+Alt+P
4565
- ]
4566
- }, es = {
4567
- type: "save",
4568
- keyCombos: [
4569
- { keyCode: 83, meta: !0 },
4570
- // Cmd+S
4571
- { keyCode: 83, ctrl: !0 }
4572
- // Ctrl+S
4573
- ]
4574
- };
4575
- export {
4576
- $i as BulkCopyProtector,
4577
- et as COMMS_VERSION,
4578
- Ke as Comms,
4579
- ji as DEV_TOOLS,
4580
- Ri as DecorationLayout,
4581
- E as DecorationStyleType,
4582
- Oi as DecorationWidth,
4583
- Ot as Decorator,
4584
- Xi as FXLModules,
4585
- qi as KeyCombinationManager,
4586
- Ji as Loader,
4587
- tt as Module,
4588
- Ne as ModuleLibrary,
4589
- ts as PRINT,
4590
- Et as PatternAnalyzer,
4591
- Dt as Peripherals,
4592
- Ht as PrintProtector,
4593
- Ki as ReflowableModules,
4594
- es as SAVE,
4595
- Qi as SELECT_ALL,
4596
- Gi as SelectionAnalyzer,
4597
- Zi as WebPubModules,
4598
- Xe as mid,
4599
- ve as sML,
4600
- Yi as sMLWithRequest
4601
- };
1
+ import{Loader as e}from"./Loader.js";import{COMMS_VERSION as m,Comms as p}from"./comms/comms.js";import{mid as f}from"./comms/mid.js";import{DecorationLayout as x,DecorationStyleType as i,DecorationWidth as n,Decorator as d}from"./modules/Decorator.js";import{Module as y}from"./modules/Module.js";import{FXLModules as M,ModuleLibrary as c,ReflowableModules as P,WebPubModules as S}from"./modules/ModuleLibrary.js";import{Peripherals as s}from"./modules/Peripherals.js";import{BulkCopyProtector as D}from"./protection/BulkCopyProtector.js";import{PatternAnalyzer as A}from"./protection/PatternAnalyzer.js";import{SelectionAnalyzer as T}from"./protection/SelectionAnalyzer.js";import{PrintProtector as V}from"./protection/PrintProtector.js";import{DEV_TOOLS as h,PRINT as z,SAVE as I,SELECT_ALL as N}from"./keyboard/KeyboardCombinations.js";import{KeyCombinationManager as g}from"./keyboard/KeyCombinationManager.js";export{D as BulkCopyProtector,m as COMMS_VERSION,p as Comms,h as DEV_TOOLS,x as DecorationLayout,i as DecorationStyleType,n as DecorationWidth,d as Decorator,M as FXLModules,g as KeyCombinationManager,e as Loader,y as Module,c as ModuleLibrary,z as PRINT,A as PatternAnalyzer,s as Peripherals,V as PrintProtector,P as ReflowableModules,I as SAVE,N as SELECT_ALL,T as SelectionAnalyzer,S as WebPubModules,f as mid};