UNPKG

@readium/navigator

Version:

Next generation SDK for publications in Web Apps

1,145 lines (1,144 loc) 475 kB
const P = class P { constructor(t) { this.uri = t; } /** * Parses an [AccessibilityProfile] from its RWPM JSON representation. */ static deserialize(t) { if (!(!t || typeof t != "string")) return new P(t); } /** * Serializes an [AccessibilityProfile] to its RWPM JSON representation. */ serialize() { return this.uri; } /** * Returns true if the profile is a WCAG Level A profile. */ get isWCAGLevelA() { return this === P.EPUB_A11Y_10_WCAG_20_A || this === P.EPUB_A11Y_11_WCAG_20_A || this === P.EPUB_A11Y_11_WCAG_21_A || this === P.EPUB_A11Y_11_WCAG_22_A; } /** * Returns true if the profile is a WCAG Level AA profile. */ get isWCAGLevelAA() { return this === P.EPUB_A11Y_10_WCAG_20_AA || this === P.EPUB_A11Y_11_WCAG_20_AA || this === P.EPUB_A11Y_11_WCAG_21_AA || this === P.EPUB_A11Y_11_WCAG_22_AA; } /** * Returns true if the profile is a WCAG Level AAA profile. */ get isWCAGLevelAAA() { return this === P.EPUB_A11Y_10_WCAG_20_AAA || this === P.EPUB_A11Y_11_WCAG_20_AAA || this === P.EPUB_A11Y_11_WCAG_21_AAA || this === P.EPUB_A11Y_11_WCAG_22_AAA; } }; P.EPUB_A11Y_10_WCAG_20_A = new P("http://www.idpf.org/epub/a11y/accessibility-20170105.html#wcag-a"), P.EPUB_A11Y_10_WCAG_20_AA = new P("http://www.idpf.org/epub/a11y/accessibility-20170105.html#wcag-aa"), P.EPUB_A11Y_10_WCAG_20_AAA = new P("http://www.idpf.org/epub/a11y/accessibility-20170105.html#wcag-aaa"), P.EPUB_A11Y_11_WCAG_20_A = new P("https://www.w3.org/TR/epub-a11y-11#wcag-2.0-a"), P.EPUB_A11Y_11_WCAG_20_AA = new P("https://www.w3.org/TR/epub-a11y-11#wcag-2.0-aa"), P.EPUB_A11Y_11_WCAG_20_AAA = new P("https://www.w3.org/TR/epub-a11y-11#wcag-2.0-aaa"), P.EPUB_A11Y_11_WCAG_21_A = new P("https://www.w3.org/TR/epub-a11y-11#wcag-2.1-a"), P.EPUB_A11Y_11_WCAG_21_AA = new P("https://www.w3.org/TR/epub-a11y-11#wcag-2.1-aa"), P.EPUB_A11Y_11_WCAG_21_AAA = new P("https://www.w3.org/TR/epub-a11y-11#wcag-2.1-aaa"), P.EPUB_A11Y_11_WCAG_22_A = new P("https://www.w3.org/TR/epub-a11y-11#wcag-2.2-a"), P.EPUB_A11Y_11_WCAG_22_AA = new P("https://www.w3.org/TR/epub-a11y-11#wcag-2.2-aa"), P.EPUB_A11Y_11_WCAG_22_AAA = new P("https://www.w3.org/TR/epub-a11y-11#wcag-2.2-aaa"); let si = P; const k = class k { constructor(t) { this.value = t; } /** * Parses an [AccessMode] from its RWPM JSON representation. */ static deserialize(t) { if (!(!t || typeof t != "string")) return new k(t); } /** * Serializes an [AccessMode] to its RWPM JSON representation. */ serialize() { return this.value; } }; k.AUDITORY = new k("auditory"), k.CHART_ON_VISUAL = new k("chartOnVisual"), k.CHEM_ON_VISUAL = new k("chemOnVisual"), k.COLOR_DEPENDENT = new k("colorDependent"), k.DIAGRAM_ON_VISUAL = new k("diagramOnVisual"), k.MATH_ON_VISUAL = new k("mathOnVisual"), k.MUSIC_ON_VISUAL = new k("musicOnVisual"), k.TACTILE = new k("tactile"), k.TEXT_ON_VISUAL = new k("textOnVisual"), k.TEXTUAL = new k("textual"), k.VISUAL = new k("visual"); let ri = k; const U = class U { constructor(t) { if (typeof t == "string") { if (!U.VALID_MODES.has(t.toLowerCase())) return; this.value = t.toLowerCase(); } else { const e = t.filter( (i) => U.VALID_MODES.has(i.toLowerCase()) ); if (e.length === 0) return; this.value = Array.from(new Set(e)); } } /** * Parses a [PrimaryAccessMode] from its RWPM JSON representation. */ static deserialize(t) { if (!t) return; if (typeof t == "string") return new U(t); if (!Array.isArray(t)) return; const e = t.filter((i) => i ? U.VALID_MODES.has(i.toLowerCase()) : !1); if (e.length !== 0) return new U(e); } /** * Serializes a [PrimaryAccessMode] to its RWPM JSON representation. */ serialize() { return this.value; } }; U.VALID_MODES = /* @__PURE__ */ new Set(["auditory", "tactile", "textual", "visual"]), U.AUDITORY = new U("auditory"), U.TACTILE = new U("tactile"), U.TEXTUAL = new U("textual"), U.VISUAL = new U("visual"); let oi = U; const y = class y { constructor(t) { this.value = t; } /** * Parses a [Feature] from its RWPM JSON representation. */ static deserialize(t) { if (!(!t || typeof t != "string")) return new y(t); } /** * Serializes a [Feature] to its RWPM JSON representation. */ serialize() { return this.value; } }; y.NONE = new y("none"), y.ANNOTATIONS = new y("annotations"), y.ARIA = new y("ARIA"), y.INDEX = new y("index"), y.PAGE_BREAK_MARKERS = new y("pageBreakMarkers"), y.PAGE_NAVIGATION = new y("pageNavigation"), y.PRINT_PAGE_NUMBERS = new y("printPageNumbers"), y.READING_ORDER = new y("readingOrder"), y.STRUCTURAL_NAVIGATION = new y("structuralNavigation"), y.TABLE_OF_CONTENTS = new y("tableOfContents"), y.TAGGED_PDF = new y("taggedPDF"), y.ALTERNATIVE_TEXT = new y("alternativeText"), y.AUDIO_DESCRIPTION = new y("audioDescription"), y.CAPTIONS = new y("captions"), y.CLOSED_CAPTIONS = new y("closedCaptions"), y.DESCRIBED_MATH = new y("describedMath"), y.LONG_DESCRIPTION = new y("longDescription"), y.OPEN_CAPTIONS = new y("openCaptions"), y.SIGN_LANGUAGE = new y("signLanguage"), y.TRANSCRIPT = new y("transcript"), y.DISPLAY_TRANSFORMABILITY = new y("displayTransformability"), y.SYNCHRONIZED_AUDIO_TEXT = new y("synchronizedAudioText"), y.TIMING_CONTROL = new y("timingControl"), y.UNLOCKED = new y("unlocked"), y.CHEM_ML = new y("ChemML"), y.LATEX = new y("latex"), y.LATEX_CHEMISTRY = new y("latex-chemistry"), y.MATH_ML = new y("MathML"), y.MATH_ML_CHEMISTRY = new y("MathML-chemistry"), y.TTS_MARKUP = new y("ttsMarkup"), y.HIGH_CONTRAST_AUDIO = new y("highContrastAudio"), y.HIGH_CONTRAST_DISPLAY = new y("highContrastDisplay"), y.LARGE_PRINT = new y("largePrint"), y.BRAILLE = new y("braille"), y.TACTILE_GRAPHIC = new y("tactileGraphic"), y.TACTILE_OBJECT = new y("tactileObject"), y.FULL_RUBY_ANNOTATIONS = new y("fullRubyAnnotations"), y.HORIZONTAL_WRITING = new y("horizontalWriting"), y.RUBY_ANNOTATIONS = new y("rubyAnnotations"), y.VERTICAL_WRITING = new y("verticalWriting"), y.WITH_ADDITIONAL_WORD_SEGMENTATION = new y("withAdditionalWordSegmentation"), y.WITHOUT_ADDITIONAL_WORD_SEGMENTATION = new y("withoutAdditionalWordSegmentation"); let $t = y; const O = class O { constructor(t) { this.value = t; } /** * Parses a [Hazard] from its RWPM JSON representation. */ static deserialize(t) { if (!(!t || typeof t != "string")) return new O(t); } /** * Serializes a [Hazard] to its RWPM JSON representation. */ serialize() { return this.value; } }; O.FLASHING = new O("flashing"), O.NO_FLASHING_HAZARD = new O("noFlashingHazard"), O.UNKNOWN_FLASHING_HAZARD = new O("unknownFlashingHazard"), O.MOTION_SIMULATION = new O("motionSimulation"), O.NO_MOTION_SIMULATION_HAZARD = new O("noMotionSimulationHazard"), O.UNKNOWN_MOTION_SIMULATION_HAZARD = new O("unknownMotionSimulationHazard"), O.SOUND = new O("sound"), O.NO_SOUND_HAZARD = new O("noSoundHazard"), O.UNKNOWN_SOUND_HAZARD = new O("unknownSoundHazard"), O.UNKNOWN = new O("unknown"), O.NONE = new O("none"); let ai = O; const A = class A { constructor(t) { this.value = t; } /** * Parses an [Exemption] from its RWPM JSON representation. */ static deserialize(t) { if (!(!t || typeof t != "string")) return new A(t); } /** * Serializes an [Exemption] to its RWPM JSON representation. */ serialize() { return this.value; } }; A.NONE = new A("none"), A.DOCUMENTED = new A("documented"), A.LEGAL = new A("legal"), A.TEMPORARY = new A("temporary"), A.TECHNICAL = new A("technical"), A.EAA_DISPROPORTIONATE_BURDEN = new A("eaa-disproportionate-burden"), A.EAA_FUNDAMENTAL_ALTERATION = new A("eaa-fundamental-alteration"), A.EAA_MICROENTERPRISE = new A("eaa-microenterprise"), A.EAA_TECHNICAL_IMPOSSIBILITY = new A("eaa-technical-impossibility"), A.EAA_TEMPORARY = new A("eaa-temporary"); let li = A; const hi = ["en", "ar", "da", "fr", "it", "pt_PT", "sv"], Un = /* @__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"}}`), Hn = { publication: Un }, ci = { fr: () => import("./fr-C5HEel98.js"), ar: () => import("./ar-DyHX_uy2.js"), da: () => import("./da-Dct0PS3E.js"), // 'el': () => import('@edrlab/thorium-locales/publication-metadata/el.json'), // 'et': () => import('@edrlab/thorium-locales/publication-metadata/et.json'), it: () => import("./it-DFOBoXGy.js"), pt_PT: () => import("./pt_PT-Di3sVjze.js"), sv: () => import("./sv-BfzAFsVN.js") // 'tr': () => import('@edrlab/thorium-locales/publication-metadata/tr.json'), // 'uk': () => import('@edrlab/thorium-locales/publication-metadata/uk.json') }, di = Hn?.publication?.metadata?.accessibility?.["display-guide"] || {}; class vt { constructor() { this.currentLocaleCode = "en", this.locale = di, this.loadedLocales = {}, this.loadedLocales.en = di; } static getInstance() { return vt.instance || (vt.instance = new vt()), vt.instance; } /** * Loads a locale dynamically * @param localeCode BCP 47 language code (e.g., 'en', 'fr') * @returns Promise indicating if the locale was loaded successfully */ async loadLocale(t) { if (!hi.includes(t)) return console.warn(`Locale '${t}' is not enabled`), !1; if (t in this.loadedLocales) return !0; try { if (!(t in ci)) return console.warn(`Locale file not found for: ${t}`), !1; const n = (await ci[t]()).default?.publication?.metadata?.accessibility?.["display-guide"]; return n ? (this.loadedLocales[t] = n, !0) : (console.warn(`No accessibility strings found in locale ${t}`), !1); } catch (e) { return console.warn(`Failed to load locale ${t}:`, e), !1; } } /** * Registers a new locale or updates an existing one * @param localeCode BCP 47 language code (e.g., 'en', 'fr-FR') * @param localeData The locale data to register */ registerLocale(t, e) { if (!t || typeof t != "string") throw new Error("Locale code must be a non-empty string"); this.loadedLocales[t] = e; } /** * Sets the current locale by language code, loading it dynamically if needed * @param localeCode BCP 47 language code (e.g., 'en', 'fr') * @returns Promise indicating if the locale was set successfully */ async setLocale(t) { 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); } /** * Gets the current locale code (BCP 47) */ getCurrentLocale() { return this.currentLocaleCode; } /** * Gets a list of available locale codes */ getAvailableLocales() { return hi; } getNestedValue(t, e) { const i = e.split("."); let n = t; for (const s of i) { if (n == null) return; n = n[s]; } return n; } /** * Gets a localized string by key * @param key The key for the string to retrieve * @returns The localized string as a [L10nString], or an empty string if not found */ getString(t) { let e = this.getNestedValue(this.locale, t); 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: "" }); } } vt.getInstance(); var v = /* @__PURE__ */ ((r) => (r.reflowable = "reflowable", r.fixed = "fixed", r.scrolled = "scrolled", r))(v || {}); class He { /** * Creates a [Encryption]. */ constructor(t) { this.algorithm = t.algorithm, this.compression = t.compression, this.originalLength = t.originalLength, this.profile = t.profile, this.scheme = t.scheme; } /** * Parses a [Encryption] from its RWPM JSON representation. */ static deserialize(t) { if (t && t.algorithm) return new He({ algorithm: t.algorithm, compression: t.compression, originalLength: t.originalLength, profile: t.profile, scheme: t.scheme }); } /** * Serializes a [Encryption] to its RWPM JSON representation. */ serialize() { const t = { algorithm: this.algorithm }; 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; } } var K = /* @__PURE__ */ ((r) => (r.left = "left", r.right = "right", r.center = "center", r))(K || {}); let J = class Ce { constructor(t) { this.otherProperties = t; } get page() { return this.otherProperties.page; } /** * Creates a [Properties] from its RWPM JSON representation. */ static deserialize(t) { if (t) return new Ce(t); } /** * Serializes a [Properties] to its RWPM JSON representation. */ serialize() { return this.otherProperties; } /** * Makes a copy of this [Properties] after merging in the given additional other [properties]. */ add(t) { const e = Object.assign({}, this.otherProperties); for (const i in t) e[i] = t[i]; return new Ce(e); } }; Object.defineProperty(J.prototype, "encryption", { get: function() { return He.deserialize(this.otherProperties.encrypted); } }); function Wn(r) { return r && Array.isArray(r) ? r : void 0; } function tn(r) { return r && typeof r == "string" ? [r] : Wn(r); } function ui(r) { return typeof r == "string" ? new Date(r) : void 0; } function jt(r) { return isNaN(r) ? void 0 : r; } function $(r) { return jt(r) !== void 0 && Math.sign(r) >= 0 ? r : void 0; } function Bn(r) { const t = new Array(); return r.forEach((e) => t.push(e)), t; } class g { /** Creates a MediaType object. */ constructor(t) { let e, i, n = t.mediaType.replace(/\s/g, "").split(";"); const s = n[0].split("/"); if (s.length === 2) { if (e = s[0].toLowerCase().trim(), i = s[1].toLowerCase().trim(), e.length === 0 || i.length === 0) throw new Error("Invalid media type"); } else throw new Error("Invalid media type"); const o = {}; for (let u = 1; u < n.length; u++) { const m = n[u].split("="); if (m.length === 2) { const p = m[0].toLocaleLowerCase(), f = p === "charset" ? m[1].toUpperCase() : m[1]; o[p] = f; } } const a = {}, l = Object.keys(o); l.sort((u, m) => u.localeCompare(m)), l.forEach((u) => a[u] = o[u]); let d = ""; for (const u in a) { const m = a[u]; d += `;${u}=${m}`; } const h = `${e}/${i}${d}`, c = a.encoding; this.string = h, this.type = e, this.subtype = i, this.parameters = a, this.encoding = c, this.name = t.name, this.fileExtension = t.fileExtension; } static parse(t) { return new g(t); } /** Structured syntax suffix, e.g. `+zip` in `application/epub+zip`. * Gives a hint on the underlying structure of this media type. * See. https://tools.ietf.org/html/rfc6838#section-4.2.8 */ get structuredSyntaxSuffix() { const t = this.subtype.split("+"); return t.length > 1 ? `+${t[t.length - 1]}` : void 0; } /** Parameter values might or might not be case-sensitive, depending on the semantics of * the parameter name. * https://tools.ietf.org/html/rfc2616#section-3.7 * * The character set names may be up to 40 characters taken from the printable characters * of US-ASCII. However, no distinction is made between use of upper and lower case * letters. * https://www.iana.org/assignments/character-sets/character-sets.xhtml */ get charset() { return this.parameters.charset; } /** Returns whether the given `other` media type is included in this media type. * For example, `text/html` contains `text/html;charset=utf-8`. * - `other` must match the parameters in the `parameters` property, but extra parameters * are ignored. * - Order of parameters is ignored. * - Wildcards are supported, meaning that `image/*` contains `image/png` */ contains(t) { const e = typeof t == "string" ? g.parse({ mediaType: t }) : t; if (!((this.type === "*" || this.type === e.type) && (this.subtype === "*" || this.subtype === e.subtype))) return !1; const i = new Set( Object.entries(this.parameters).map(([s, o]) => `${s}=${o}`) ), n = new Set( Object.entries(e.parameters).map(([s, o]) => `${s}=${o}`) ); for (const s of Array.from(i.values())) if (!n.has(s)) return !1; return !0; } /** Returns whether this media type and `other` are the same, ignoring parameters that * are not in both media types. * For example, `text/html` matches `text/html;charset=utf-8`, but `text/html;charset=ascii` * doesn't. This is basically like `contains`, but working in both direction. */ matches(t) { const e = typeof t == "string" ? g.parse({ mediaType: t }) : t; return this.contains(e) || e.contains(this); } /** * Returns whether this media type matches any of the [others] media types. */ matchesAny(...t) { for (const e of t) if (this.matches(e)) return !0; return !1; } /** Checks the MediaType equals another one (comparing their string) */ equals(t) { return this.string === t.string; } /** Returns whether this media type is structured as a ZIP archive. */ get isZIP() { return this.matchesAny( g.ZIP, g.LCP_PROTECTED_AUDIOBOOK, g.LCP_PROTECTED_PDF ) || this.structuredSyntaxSuffix === "+zip"; } /** Returns whether this media type is structured as a JSON file. */ get isJSON() { return this.matchesAny(g.JSON) || this.structuredSyntaxSuffix === "+json"; } /** Returns whether this media type is of an OPDS feed. */ get isOPDS() { return this.matchesAny( g.OPDS1, g.OPDS1_ENTRY, g.OPDS2, g.OPDS2_PUBLICATION, g.OPDS_AUTHENTICATION ) || this.structuredSyntaxSuffix === "+json"; } /** Returns whether this media type is of an HTML document. */ get isHTML() { return this.matchesAny(g.HTML, g.XHTML); } /** Returns whether this media type is of a bitmap image, so excluding vectorial formats. */ get isBitmap() { return this.matchesAny( g.AVIF, g.BMP, g.GIF, g.JPEG, g.PNG, g.TIFF, g.WEBP ); } /** Returns whether this media type is of an audio clip. */ get isAudio() { return this.type === "audio"; } /** Returns whether this media type is of a video clip. */ get isVideo() { return this.type === "video"; } /** Returns whether this media type is of a Readium Web Publication Manifest. */ get isRWPM() { return this.matchesAny( g.READIUM_AUDIOBOOK_MANIFEST, g.DIVINA_MANIFEST, g.READIUM_WEBPUB_MANIFEST ); } /** Returns whether this media type is of a publication file. */ get isPublication() { return this.matchesAny( g.READIUM_AUDIOBOOK, g.READIUM_AUDIOBOOK_MANIFEST, g.CBZ, g.DIVINA, g.DIVINA_MANIFEST, g.EPUB, g.LCP_PROTECTED_AUDIOBOOK, g.LCP_PROTECTED_PDF, g.LPF, g.PDF, g.W3C_WPUB_MANIFEST, g.READIUM_WEBPUB, g.READIUM_WEBPUB_MANIFEST, g.ZAB ); } // Known Media Types static get AAC() { return g.parse({ mediaType: "audio/aac", fileExtension: "aac" }); } static get ACSM() { return g.parse({ mediaType: "application/vnd.adobe.adept+xml", name: "Adobe Content Server Message", fileExtension: "acsm" }); } static get AIFF() { return g.parse({ mediaType: "audio/aiff", fileExtension: "aiff" }); } static get AVI() { return g.parse({ mediaType: "video/x-msvideo", fileExtension: "avi" }); } static get AVIF() { return g.parse({ mediaType: "image/avif", fileExtension: "avif" }); } static get BINARY() { return g.parse({ mediaType: "application/octet-stream" }); } static get BMP() { return g.parse({ mediaType: "image/bmp", fileExtension: "bmp" }); } static get CBZ() { return g.parse({ mediaType: "application/vnd.comicbook+zip", name: "Comic Book Archive", fileExtension: "cbz" }); } static get CSS() { return g.parse({ mediaType: "text/css", fileExtension: "css" }); } static get DIVINA() { return g.parse({ mediaType: "application/divina+zip", name: "Digital Visual Narratives", fileExtension: "divina" }); } static get DIVINA_MANIFEST() { return g.parse({ mediaType: "application/divina+json", name: "Digital Visual Narratives", fileExtension: "json" }); } static get EPUB() { return g.parse({ mediaType: "application/epub+zip", name: "EPUB", fileExtension: "epub" }); } static get GIF() { return g.parse({ mediaType: "image/gif", fileExtension: "gif" }); } static get GZ() { return g.parse({ mediaType: "application/gzip", fileExtension: "gz" }); } static get HTML() { return g.parse({ mediaType: "text/html", fileExtension: "html" }); } static get JAVASCRIPT() { return g.parse({ mediaType: "text/javascript", fileExtension: "js" }); } static get JPEG() { return g.parse({ mediaType: "image/jpeg", fileExtension: "jpeg" }); } static get JSON() { return g.parse({ mediaType: "application/json" }); } static get LCP_LICENSE_DOCUMENT() { return g.parse({ mediaType: "application/vnd.readium.lcp.license.v1.0+json", name: "LCP License", fileExtension: "lcpl" }); } static get LCP_PROTECTED_AUDIOBOOK() { return g.parse({ mediaType: "application/audiobook+lcp", name: "LCP Protected Audiobook", fileExtension: "lcpa" }); } static get LCP_PROTECTED_PDF() { return g.parse({ mediaType: "application/pdf+lcp", name: "LCP Protected PDF", fileExtension: "lcpdf" }); } static get LCP_STATUS_DOCUMENT() { return g.parse({ mediaType: "application/vnd.readium.license.status.v1.0+json" }); } static get LPF() { return g.parse({ mediaType: "application/lpf+zip", fileExtension: "lpf" }); } static get MP3() { return g.parse({ mediaType: "audio/mpeg", fileExtension: "mp3" }); } static get MPEG() { return g.parse({ mediaType: "video/mpeg", fileExtension: "mpeg" }); } static get NCX() { return g.parse({ mediaType: "application/x-dtbncx+xml", fileExtension: "ncx" }); } static get OGG() { return g.parse({ mediaType: "audio/ogg", fileExtension: "oga" }); } static get OGV() { return g.parse({ mediaType: "video/ogg", fileExtension: "ogv" }); } static get OPDS1() { return g.parse({ mediaType: "application/atom+xml;profile=opds-catalog" }); } static get OPDS1_ENTRY() { return g.parse({ mediaType: "application/atom+xml;type=entry;profile=opds-catalog" }); } static get OPDS2() { return g.parse({ mediaType: "application/opds+json" }); } static get OPDS2_PUBLICATION() { return g.parse({ mediaType: "application/opds-publication+json" }); } static get OPDS_AUTHENTICATION() { return g.parse({ mediaType: "application/opds-authentication+json" }); } static get OPUS() { return g.parse({ mediaType: "audio/opus", fileExtension: "opus" }); } static get OTF() { return g.parse({ mediaType: "font/otf", fileExtension: "otf" }); } static get PDF() { return g.parse({ mediaType: "application/pdf", name: "PDF", fileExtension: "pdf" }); } static get PNG() { return g.parse({ mediaType: "image/png", fileExtension: "png" }); } static get READIUM_AUDIOBOOK() { return g.parse({ mediaType: "application/audiobook+zip", name: "Readium Audiobook", fileExtension: "audiobook" }); } static get READIUM_AUDIOBOOK_MANIFEST() { return g.parse({ mediaType: "application/audiobook+json", name: "Readium Audiobook", fileExtension: "json" }); } static get READIUM_CONTENT_DOCUMENT() { return g.parse({ mediaType: "application/vnd.readium.content+json", name: "Readium Content Document", fileExtension: "json" }); } static get READIUM_GUIDED_NAVIGATION_DOCUMENT() { return g.parse({ mediaType: "application/guided-navigation+json", name: "Readium Guided Navigation Document", fileExtension: "json" }); } static get READIUM_POSITION_LIST() { return g.parse({ mediaType: "application/vnd.readium.position-list+json", name: "Readium Position List", fileExtension: "json" }); } static get READIUM_WEBPUB() { return g.parse({ mediaType: "application/webpub+zip", name: "Readium Web Publication", fileExtension: "webpub" }); } static get READIUM_WEBPUB_MANIFEST() { return g.parse({ mediaType: "application/webpub+json", name: "Readium Web Publication", fileExtension: "json" }); } static get SMIL() { return g.parse({ mediaType: "application/smil+xml", fileExtension: "smil" }); } static get SVG() { return g.parse({ mediaType: "image/svg+xml", fileExtension: "svg" }); } static get TEXT() { return g.parse({ mediaType: "text/plain", fileExtension: "txt" }); } static get TIFF() { return g.parse({ mediaType: "image/tiff", fileExtension: "tiff" }); } static get TTF() { return g.parse({ mediaType: "font/ttf", fileExtension: "ttf" }); } static get W3C_WPUB_MANIFEST() { return g.parse({ mediaType: "application/x.readium.w3c.wpub+json", name: "Web Publication", fileExtension: "json" }); } static get WAV() { return g.parse({ mediaType: "audio/wav", fileExtension: "wav" }); } static get WEBM_AUDIO() { return g.parse({ mediaType: "audio/webm", fileExtension: "webm" }); } static get WEBM_VIDEO() { return g.parse({ mediaType: "video/webm", fileExtension: "webm" }); } static get WEBP() { return g.parse({ mediaType: "image/webp", fileExtension: "webp" }); } static get WOFF() { return g.parse({ mediaType: "font/woff", fileExtension: "woff" }); } static get WOFF2() { return g.parse({ mediaType: "font/woff2", fileExtension: "woff2" }); } static get XHTML() { return g.parse({ mediaType: "application/xhtml+xml", fileExtension: "xhtml" }); } static get XML() { return g.parse({ mediaType: "application/xml", fileExtension: "xml" }); } static get ZAB() { return g.parse({ mediaType: "application/x.readium.zab+zip", name: "Zipped Audio Book", fileExtension: "zab" }); } static get ZIP() { return g.parse({ mediaType: "application/zip", fileExtension: "zip" }); } } class pi { constructor(t) { this.uri = t, this.parameters = this.getParameters(t); } /** * List of URI template parameter keys, if the [Link] is templated. */ getParameters(t) { const e = /\{\??([^}]+)\}/g, i = t.match(e); return i ? new Set( i.join(",").replace(e, "$1").split(",").map((n) => n.trim()) ) : /* @__PURE__ */ new Set(); } /** Expands the URI by replacing the template variables by the given parameters. * Any extra parameter is appended as query parameters. * See RFC 6570 on URI template: https://tools.ietf.org/html/rfc6570 */ expand(t) { const e = (n) => n.split(",").map((s) => { const o = t[s]; return o ? encodeURIComponent(o) : ""; }).join(","), i = (n) => "?" + n.split(",").map((s) => { const o = s.split("=")[0], a = t[o]; return a ? `${o}=${encodeURIComponent(a)}` : ""; }).join("&"); return this.uri.replace(/\{(\??)([^}]+)\}/g, (...n) => n[1] ? i(n[2]) : e(n[2])); } } class L { /** * Creates a [Locations]. */ constructor(t) { this.fragments = t.fragments ? t.fragments : new Array(), this.progression = t.progression, this.totalProgression = t.totalProgression, this.position = t.position, this.otherLocations = t.otherLocations; } /** * Parses a [Locations] from its RWPM JSON representation. */ static deserialize(t) { if (!t) return; const e = jt(t.progression), i = jt(t.totalProgression), n = jt(t.position), s = /* @__PURE__ */ new Map(), o = /* @__PURE__ */ new Set([ "fragment", "fragments", "progression", "totalProgression", "position" ]); return Object.entries(t).forEach(([a, l]) => { o.has(a) || s.set(a, l); }), new L({ fragments: tn(t.fragments || t.fragment), progression: e !== void 0 && e >= 0 && e <= 1 ? e : void 0, totalProgression: i !== void 0 && i >= 0 && i <= 1 ? i : void 0, position: n !== void 0 && n > 0 ? n : void 0, otherLocations: s.size === 0 ? void 0 : s }); } /** * Serializes a [Locations] to its RWPM JSON representation. */ serialize() { const t = {}; 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; } } class tt { /** * Creates a [Text]. */ constructor(t) { this.after = t.after, this.before = t.before, this.highlight = t.highlight; } /** * Parses a [Locations] from its RWPM JSON representation. */ static deserialize(t) { if (t) return new tt({ after: t.after, before: t.before, highlight: t.highlight }); } /** * Serializes a [Locations] to its RWPM JSON representation. */ serialize() { const t = {}; 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; } } class F { /** * Creates a [Locator]. */ constructor(t) { this.href = t.href, this.type = t.type, this.title = t.title, this.locations = t.locations ? t.locations : new L({}), this.text = t.text; } /** * Parses a [Link] from its RWPM JSON representation. */ static deserialize(t) { if (t && t.href && t.type) return new F({ href: t.href, type: t.type, title: t.title, locations: L.deserialize(t.locations), text: tt.deserialize(t.text) }); } /** * Serializes a [Link] to its RWPM JSON representation. */ serialize() { const t = { href: this.href, type: this.type }; return this.title !== void 0 && (t.title = this.title), this.locations && (t.locations = this.locations.serialize()), this.text && (t.text = this.text.serialize()), t; } /** * Shortcut to get a copy of the [Locator] with different [Locations] sub-properties. */ copyWithLocations(t) { return new F({ href: this.href, type: this.type, title: this.title, text: this.text, locations: new L({ ...this.locations, ...t }) }); } } class q { /** * Creates a [Link]. */ constructor(t) { 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; } /** * Parses a [Link] from its RWPM JSON representation. */ static deserialize(t) { if (!(!t || typeof t.href != "string")) return new q({ href: t.href, templated: t.templated, type: t.type, title: t.title, rels: t.rel ? Array.isArray(t.rel) ? new Set(t.rel) : /* @__PURE__ */ new Set([t.rel]) : void 0, properties: J.deserialize(t.properties), height: $(t.height), width: $(t.width), size: $(t.size), duration: $(t.duration), bitrate: $(t.bitrate), languages: tn(t.language), alternates: Gt.deserialize(t.alternate), children: Gt.deserialize(t.children) }); } /** * Serializes a [Link] to its RWPM JSON representation. */ serialize() { const t = { href: this.href }; 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 = Bn(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; } /** MediaType of the linked resource. */ get mediaType() { return this.type !== void 0 ? g.parse({ mediaType: this.type }) : g.BINARY; } /** Computes an absolute URL to the link, relative to the given `baseURL`. * If the link's `href` is already absolute, the `baseURL` is ignored. */ toURL(t) { const e = this.href.replace(/^(\/)/, ""); if (e.length === 0) return; let i = t || "/"; return i.startsWith("/") && (i = "file://" + i), new URL(e, i).href.replace(/^(file:\/\/)/, ""); } /** List of URI template parameter keys, if the `Link` is templated. */ get templateParameters() { return this.templated ? new pi(this.href).parameters : /* @__PURE__ */ new Set(); } /** Expands the `Link`'s HREF by replacing URI template variables by the given parameters. * See RFC 6570 on URI template: https://tools.ietf.org/html/rfc6570 */ expandTemplate(t) { return new q({ href: new pi(this.href).expand(t), templated: !1 }); } /** * Makes a copy of this [Link] after merging in the given additional other [properties]. */ addProperties(t) { const e = q.deserialize(this.serialize()); return e.properties = e.properties ? e.properties?.add(t) : new J(t), e; } /** * Creates a [Locator] from a reading order [Link]. */ get locator() { let t = this.href.split("#"); return new F({ href: t.length > 0 && t[0] !== void 0 ? t[0] : this.href, type: this.type ?? "", title: this.title, locations: new L({ fragments: t.length > 1 && t[1] !== void 0 ? [t[1]] : [] }) }); } } class Gt { /** * Creates a [Links]. */ constructor(t) { this.items = t; } /** * Creates a list of [Link] from its RWPM JSON representation. */ static deserialize(t) { if (t && Array.isArray(t)) return new Gt( t.map((e) => q.deserialize(e)).filter((e) => e !== void 0) ); } /** * Serializes an array of [Link] to its RWPM JSON representation. */ serialize() { return this.items.map((t) => t.serialize()); } /** Finds the first link with the given relation. */ findWithRel(t) { const e = (i) => i.rels && i.rels.has(t); return this.items.find(e); } /** Finds all the links with the given relation. */ filterByRel(t) { const e = (i) => i.rels && i.rels.has(t); return this.items.filter(e); } /** Finds the first link matching the given HREF. */ findWithHref(t) { const e = (i) => i.href === t; return this.items.find(e); } /** Finds the index of the first link matching the given HREF. */ findIndexWithHref(t) { const e = (i) => i.href === t; return this.items.findIndex(e); } /** Finds the first link matching the given media type. */ findWithMediaType(t) { const e = (i) => i.mediaType.matches(t); return this.items.find(e); } /** Finds all the links matching the given media type. */ filterByMediaType(t) { const e = (i) => i.mediaType.matches(t); return this.items.filter(e); } /** Finds all the links matching any of the given media types. */ filterByMediaTypes(t) { const e = (i) => { for (const n of t) if (i.mediaType.matches(n)) return !0; return !1; }; return this.items.filter(e); } /** Returns whether all the resources in the collection are audio clips. */ everyIsAudio() { const t = (e) => e.mediaType.isAudio; return this.items.length > 0 && this.items.every(t); } /** Returns whether all the resources in the collection are bitmaps. */ everyIsBitmap() { const t = (e) => e.mediaType.isBitmap; return this.items.length > 0 && this.items.every(t); } /** Returns whether all the resources in the collection are HTML documents. */ everyIsHTML() { const t = (e) => e.mediaType.isHTML; return this.items.length > 0 && this.items.every(t); } /** Returns whether all the resources in the collection are video clips. */ everyIsVideo() { const t = (e) => e.mediaType.isVideo; return this.items.length > 0 && this.items.every(t); } /** Returns whether all the resources in the collection are matching any of the given media types. */ everyMatchesMediaType(t) { return Array.isArray(t) ? this.items.length > 0 && this.items.every((e) => { for (const i of t) return e.mediaType.matches(i); return !1; }) : this.items.length > 0 && this.items.every((e) => e.mediaType.matches(t)); } filterLinksHasType() { return this.items.filter((t) => t.type); } } var en = /* @__PURE__ */ ((r) => (r.EPUB = "https://readium.org/webpub-manifest/profiles/epub", r.AUDIOBOOK = "https://readium.org/webpub-manifest/profiles/audiobook", r.DIVINA = "https://readium.org/webpub-manifest/profiles/divina", r.PDF = "https://readium.org/webpub-manifest/profiles/pdf", r))(en || {}), I = /* @__PURE__ */ ((r) => (r.ltr = "ltr", r.rtl = "rtl", r))(I || {}); J.prototype.getContains = function() { return new Set(this.otherProperties.contains || []); }; function Vn(r) { const t = r.split(",")[0].trim(), n = (t.toLowerCase().startsWith("npt:") ? t.slice(4) : t).split(":"); if (n.length === 1) { const s = parseFloat(n[0]); return isNaN(s) ? void 0 : s; } if (n.length === 2) { const s = parseInt(n[0], 10), o = parseFloat(n[1]); return isNaN(s) || isNaN(o) ? void 0 : s * 60 + o; } if (n.length === 3) { const s = parseInt(n[0], 10), o = parseInt(n[1], 10), a = parseFloat(n[2]); return isNaN(s) || isNaN(o) || isNaN(a) ? void 0 : s * 3600 + o * 60 + a; } } class Xt { /** * Creates a [DomRange]. */ constructor(t) { this.cssSelector = t.cssSelector, this.textNodeIndex = t.textNodeIndex, this.charOffset = t.charOffset; } /** * Parses a [DomRangePoint] from its RWPM JSON representation. */ static deserialize(t) { if (!(t && t.cssSelector)) return; let e = $(t.textNodeIndex); if (e === void 0) return; let i = $(t.charOffset); return i === void 0 && (i = $(t.offset)), new Xt({ cssSelector: t.cssSelector, textNodeIndex: e, charOffset: i }); } /** * Serializes a [DomRangePoint] to its RWPM JSON representation. */ serialize() { const t = { cssSelector: this.cssSelector, textNodeIndex: this.textNodeIndex