UNPKG

@readium/navigator

Version:

Next generation SDK for publications in Web Apps

1 lines 578 kB
(function(y,Se){typeof exports=="object"&&typeof module<"u"?Se(exports):typeof define=="function"&&define.amd?define(["exports"],Se):(y=typeof globalThis<"u"?globalThis:y||self,Se(y.navigator={}))})(this,(function(y){"use strict";var le;const R=class R{constructor(e){this.uri=e}static deserialize(e){if(!(!e||typeof e!="string"))return new R(e)}serialize(){return this.uri}get isWCAGLevelA(){return this===R.EPUB_A11Y_10_WCAG_20_A||this===R.EPUB_A11Y_11_WCAG_20_A||this===R.EPUB_A11Y_11_WCAG_21_A||this===R.EPUB_A11Y_11_WCAG_22_A}get isWCAGLevelAA(){return this===R.EPUB_A11Y_10_WCAG_20_AA||this===R.EPUB_A11Y_11_WCAG_20_AA||this===R.EPUB_A11Y_11_WCAG_21_AA||this===R.EPUB_A11Y_11_WCAG_22_AA}get isWCAGLevelAAA(){return this===R.EPUB_A11Y_10_WCAG_20_AAA||this===R.EPUB_A11Y_11_WCAG_20_AAA||this===R.EPUB_A11Y_11_WCAG_21_AAA||this===R.EPUB_A11Y_11_WCAG_22_AAA}};R.EPUB_A11Y_10_WCAG_20_A=new R("http://www.idpf.org/epub/a11y/accessibility-20170105.html#wcag-a"),R.EPUB_A11Y_10_WCAG_20_AA=new R("http://www.idpf.org/epub/a11y/accessibility-20170105.html#wcag-aa"),R.EPUB_A11Y_10_WCAG_20_AAA=new R("http://www.idpf.org/epub/a11y/accessibility-20170105.html#wcag-aaa"),R.EPUB_A11Y_11_WCAG_20_A=new R("https://www.w3.org/TR/epub-a11y-11#wcag-2.0-a"),R.EPUB_A11Y_11_WCAG_20_AA=new R("https://www.w3.org/TR/epub-a11y-11#wcag-2.0-aa"),R.EPUB_A11Y_11_WCAG_20_AAA=new R("https://www.w3.org/TR/epub-a11y-11#wcag-2.0-aaa"),R.EPUB_A11Y_11_WCAG_21_A=new R("https://www.w3.org/TR/epub-a11y-11#wcag-2.1-a"),R.EPUB_A11Y_11_WCAG_21_AA=new R("https://www.w3.org/TR/epub-a11y-11#wcag-2.1-aa"),R.EPUB_A11Y_11_WCAG_21_AAA=new R("https://www.w3.org/TR/epub-a11y-11#wcag-2.1-aaa"),R.EPUB_A11Y_11_WCAG_22_A=new R("https://www.w3.org/TR/epub-a11y-11#wcag-2.2-a"),R.EPUB_A11Y_11_WCAG_22_AA=new R("https://www.w3.org/TR/epub-a11y-11#wcag-2.2-aa"),R.EPUB_A11Y_11_WCAG_22_AAA=new R("https://www.w3.org/TR/epub-a11y-11#wcag-2.2-aaa");let Se=R;const z=class z{constructor(e){this.value=e}static deserialize(e){if(!(!e||typeof e!="string"))return new z(e)}serialize(){return this.value}};z.AUDITORY=new z("auditory"),z.CHART_ON_VISUAL=new z("chartOnVisual"),z.CHEM_ON_VISUAL=new z("chemOnVisual"),z.COLOR_DEPENDENT=new z("colorDependent"),z.DIAGRAM_ON_VISUAL=new z("diagramOnVisual"),z.MATH_ON_VISUAL=new z("mathOnVisual"),z.MUSIC_ON_VISUAL=new z("musicOnVisual"),z.TACTILE=new z("tactile"),z.TEXT_ON_VISUAL=new z("textOnVisual"),z.TEXTUAL=new z("textual"),z.VISUAL=new z("visual");let Rn=z;const W=class W{constructor(e){if(typeof e=="string"){if(!W.VALID_MODES.has(e.toLowerCase()))return;this.value=e.toLowerCase()}else{const t=e.filter(n=>W.VALID_MODES.has(n.toLowerCase()));if(t.length===0)return;this.value=Array.from(new Set(t))}}static deserialize(e){if(!e)return;if(typeof e=="string")return new W(e);if(!Array.isArray(e))return;const t=e.filter(n=>n?W.VALID_MODES.has(n.toLowerCase()):!1);if(t.length!==0)return new W(t)}serialize(){return this.value}};W.VALID_MODES=new Set(["auditory","tactile","textual","visual"]),W.AUDITORY=new W("auditory"),W.TACTILE=new W("tactile"),W.TEXTUAL=new W("textual"),W.VISUAL=new W("visual");let Pn=W;const S=class S{constructor(e){this.value=e}static deserialize(e){if(!(!e||typeof e!="string"))return new S(e)}serialize(){return this.value}};S.NONE=new S("none"),S.ANNOTATIONS=new S("annotations"),S.ARIA=new S("ARIA"),S.INDEX=new S("index"),S.PAGE_BREAK_MARKERS=new S("pageBreakMarkers"),S.PAGE_NAVIGATION=new S("pageNavigation"),S.PRINT_PAGE_NUMBERS=new S("printPageNumbers"),S.READING_ORDER=new S("readingOrder"),S.STRUCTURAL_NAVIGATION=new S("structuralNavigation"),S.TABLE_OF_CONTENTS=new S("tableOfContents"),S.TAGGED_PDF=new S("taggedPDF"),S.ALTERNATIVE_TEXT=new S("alternativeText"),S.AUDIO_DESCRIPTION=new S("audioDescription"),S.CAPTIONS=new S("captions"),S.CLOSED_CAPTIONS=new S("closedCaptions"),S.DESCRIBED_MATH=new S("describedMath"),S.LONG_DESCRIPTION=new S("longDescription"),S.OPEN_CAPTIONS=new S("openCaptions"),S.SIGN_LANGUAGE=new S("signLanguage"),S.TRANSCRIPT=new S("transcript"),S.DISPLAY_TRANSFORMABILITY=new S("displayTransformability"),S.SYNCHRONIZED_AUDIO_TEXT=new S("synchronizedAudioText"),S.TIMING_CONTROL=new S("timingControl"),S.UNLOCKED=new S("unlocked"),S.CHEM_ML=new S("ChemML"),S.LATEX=new S("latex"),S.LATEX_CHEMISTRY=new S("latex-chemistry"),S.MATH_ML=new S("MathML"),S.MATH_ML_CHEMISTRY=new S("MathML-chemistry"),S.TTS_MARKUP=new S("ttsMarkup"),S.HIGH_CONTRAST_AUDIO=new S("highContrastAudio"),S.HIGH_CONTRAST_DISPLAY=new S("highContrastDisplay"),S.LARGE_PRINT=new S("largePrint"),S.BRAILLE=new S("braille"),S.TACTILE_GRAPHIC=new S("tactileGraphic"),S.TACTILE_OBJECT=new S("tactileObject"),S.FULL_RUBY_ANNOTATIONS=new S("fullRubyAnnotations"),S.HORIZONTAL_WRITING=new S("horizontalWriting"),S.RUBY_ANNOTATIONS=new S("rubyAnnotations"),S.VERTICAL_WRITING=new S("verticalWriting"),S.WITH_ADDITIONAL_WORD_SEGMENTATION=new S("withAdditionalWordSegmentation"),S.WITHOUT_ADDITIONAL_WORD_SEGMENTATION=new S("withoutAdditionalWordSegmentation");let it=S;const L=class L{constructor(e){this.value=e}static deserialize(e){if(!(!e||typeof e!="string"))return new L(e)}serialize(){return this.value}};L.FLASHING=new L("flashing"),L.NO_FLASHING_HAZARD=new L("noFlashingHazard"),L.UNKNOWN_FLASHING_HAZARD=new L("unknownFlashingHazard"),L.MOTION_SIMULATION=new L("motionSimulation"),L.NO_MOTION_SIMULATION_HAZARD=new L("noMotionSimulationHazard"),L.UNKNOWN_MOTION_SIMULATION_HAZARD=new L("unknownMotionSimulationHazard"),L.SOUND=new L("sound"),L.NO_SOUND_HAZARD=new L("noSoundHazard"),L.UNKNOWN_SOUND_HAZARD=new L("unknownSoundHazard"),L.UNKNOWN=new L("unknown"),L.NONE=new L("none");let Cn=L;const O=class O{constructor(e){this.value=e}static deserialize(e){if(!(!e||typeof e!="string"))return new O(e)}serialize(){return this.value}};O.NONE=new O("none"),O.DOCUMENTED=new O("documented"),O.LEGAL=new O("legal"),O.TEMPORARY=new O("temporary"),O.TECHNICAL=new O("technical"),O.EAA_DISPROPORTIONATE_BURDEN=new O("eaa-disproportionate-burden"),O.EAA_FUNDAMENTAL_ALTERATION=new O("eaa-fundamental-alteration"),O.EAA_MICROENTERPRISE=new O("eaa-microenterprise"),O.EAA_TECHNICAL_IMPOSSIBILITY=new O("eaa-technical-impossibility"),O.EAA_TEMPORARY=new O("eaa-temporary");let kn=O;const En=["en","ar","da","fr","it","pt_PT","sv"],fo={publication: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"}}`)},xn={fr:()=>Promise.resolve().then(()=>da),ar:()=>Promise.resolve().then(()=>ua),da:()=>Promise.resolve().then(()=>ma),it:()=>Promise.resolve().then(()=>pa),pt_PT:()=>Promise.resolve().then(()=>ga),sv:()=>Promise.resolve().then(()=>fa)},Fn=fo?.publication?.metadata?.accessibility?.["display-guide"]||{};class _e{constructor(){this.currentLocaleCode="en",this.locale=Fn,this.loadedLocales={},this.loadedLocales.en=Fn}static getInstance(){return _e.instance||(_e.instance=new _e),_e.instance}async loadLocale(e){if(!En.includes(e))return console.warn(`Locale '${e}' is not enabled`),!1;if(e in this.loadedLocales)return!0;try{if(!(e in xn))return console.warn(`Locale file not found for: ${e}`),!1;const i=(await xn[e]()).default?.publication?.metadata?.accessibility?.["display-guide"];return i?(this.loadedLocales[e]=i,!0):(console.warn(`No accessibility strings found in locale ${e}`),!1)}catch(t){return console.warn(`Failed to load locale ${e}:`,t),!1}}registerLocale(e,t){if(!e||typeof e!="string")throw new Error("Locale code must be a non-empty string");this.loadedLocales[e]=t}async setLocale(e){return e in this.loadedLocales||await this.loadLocale(e),e in this.loadedLocales?(this.locale=this.loadedLocales[e],this.currentLocaleCode=e,!0):(console.warn(`Locale '${e}' is not available`),!1)}getCurrentLocale(){return this.currentLocaleCode}getAvailableLocales(){return En}getNestedValue(e,t){const n=t.split(".");let i=e;for(const o of n){if(i==null)return;i=i[o]}return i}getString(e){let t=this.getNestedValue(this.locale,e);return t===void 0&&this.currentLocaleCode!=="en"&&(t=this.getNestedValue(this.loadedLocales.en,e)),t!==void 0?typeof t=="string"?{compact:t,descriptive:t}:t:(console.warn(`Missing localization for key: ${e}`),{compact:"",descriptive:""})}}_e.getInstance();var b=(r=>(r.reflowable="reflowable",r.fixed="fixed",r.scrolled="scrolled",r))(b||{});class wt{constructor(e){this.algorithm=e.algorithm,this.compression=e.compression,this.originalLength=e.originalLength,this.profile=e.profile,this.scheme=e.scheme}static deserialize(e){if(e&&e.algorithm)return new wt({algorithm:e.algorithm,compression:e.compression,originalLength:e.originalLength,profile:e.profile,scheme:e.scheme})}serialize(){const e={algorithm:this.algorithm};return this.compression!==void 0&&(e.compression=this.compression),this.originalLength!==void 0&&(e.originalLength=this.originalLength),this.profile!==void 0&&(e.profile=this.profile),this.scheme!==void 0&&(e.scheme=this.scheme),e}}var J=(r=>(r.left="left",r.right="right",r.center="center",r))(J||{});let Z=class wn{constructor(e){this.otherProperties=e}get page(){return this.otherProperties.page}static deserialize(e){if(e)return new wn(e)}serialize(){return this.otherProperties}add(e){const t=Object.assign({},this.otherProperties);for(const n in e)t[n]=e[n];return new wn(t)}};Object.defineProperty(Z.prototype,"encryption",{get:function(){return wt.deserialize(this.otherProperties.encrypted)}});function yo(r){return r&&Array.isArray(r)?r:void 0}function zn(r){return r&&typeof r=="string"?[r]:yo(r)}function Ln(r){return typeof r=="string"?new Date(r):void 0}function ot(r){return isNaN(r)?void 0:r}function $(r){return ot(r)!==void 0&&Math.sign(r)>=0?r:void 0}function So(r){const e=new Array;return r.forEach(t=>e.push(t)),e}class f{constructor(e){let t,n,i=e.mediaType.replace(/\s/g,"").split(";");const o=i[0].split("/");if(o.length===2){if(t=o[0].toLowerCase().trim(),n=o[1].toLowerCase().trim(),t.length===0||n.length===0)throw new Error("Invalid media type")}else throw new Error("Invalid media type");const a={};for(let u=1;u<i.length;u++){const g=i[u].split("=");if(g.length===2){const m=g[0].toLocaleLowerCase(),p=m==="charset"?g[1].toUpperCase():g[1];a[m]=p}}const s={},l=Object.keys(a);l.sort((u,g)=>u.localeCompare(g)),l.forEach(u=>s[u]=a[u]);let d="";for(const u in s){const g=s[u];d+=`;${u}=${g}`}const c=`${t}/${n}${d}`,h=s.encoding;this.string=c,this.type=t,this.subtype=n,this.parameters=s,this.encoding=h,this.name=e.name,this.fileExtension=e.fileExtension}static parse(e){return new f(e)}get structuredSyntaxSuffix(){const e=this.subtype.split("+");return e.length>1?`+${e[e.length-1]}`:void 0}get charset(){return this.parameters.charset}contains(e){const t=typeof e=="string"?f.parse({mediaType:e}):e;if(!((this.type==="*"||this.type===t.type)&&(this.subtype==="*"||this.subtype===t.subtype)))return!1;const n=new Set(Object.entries(this.parameters).map(([o,a])=>`${o}=${a}`)),i=new Set(Object.entries(t.parameters).map(([o,a])=>`${o}=${a}`));for(const o of Array.from(n.values()))if(!i.has(o))return!1;return!0}matches(e){const t=typeof e=="string"?f.parse({mediaType:e}):e;return this.contains(t)||t.contains(this)}matchesAny(...e){for(const t of e)if(this.matches(t))return!0;return!1}equals(e){return this.string===e.string}get isZIP(){return this.matchesAny(f.ZIP,f.LCP_PROTECTED_AUDIOBOOK,f.LCP_PROTECTED_PDF)||this.structuredSyntaxSuffix==="+zip"}get isJSON(){return this.matchesAny(f.JSON)||this.structuredSyntaxSuffix==="+json"}get isOPDS(){return this.matchesAny(f.OPDS1,f.OPDS1_ENTRY,f.OPDS2,f.OPDS2_PUBLICATION,f.OPDS_AUTHENTICATION)||this.structuredSyntaxSuffix==="+json"}get isHTML(){return this.matchesAny(f.HTML,f.XHTML)}get isBitmap(){return this.matchesAny(f.AVIF,f.BMP,f.GIF,f.JPEG,f.PNG,f.TIFF,f.WEBP)}get isAudio(){return this.type==="audio"}get isVideo(){return this.type==="video"}get isRWPM(){return this.matchesAny(f.READIUM_AUDIOBOOK_MANIFEST,f.DIVINA_MANIFEST,f.READIUM_WEBPUB_MANIFEST)}get isPublication(){return this.matchesAny(f.READIUM_AUDIOBOOK,f.READIUM_AUDIOBOOK_MANIFEST,f.CBZ,f.DIVINA,f.DIVINA_MANIFEST,f.EPUB,f.LCP_PROTECTED_AUDIOBOOK,f.LCP_PROTECTED_PDF,f.LPF,f.PDF,f.W3C_WPUB_MANIFEST,f.READIUM_WEBPUB,f.READIUM_WEBPUB_MANIFEST,f.ZAB)}static get AAC(){return f.parse({mediaType:"audio/aac",fileExtension:"aac"})}static get ACSM(){return f.parse({mediaType:"application/vnd.adobe.adept+xml",name:"Adobe Content Server Message",fileExtension:"acsm"})}static get AIFF(){return f.parse({mediaType:"audio/aiff",fileExtension:"aiff"})}static get AVI(){return f.parse({mediaType:"video/x-msvideo",fileExtension:"avi"})}static get AVIF(){return f.parse({mediaType:"image/avif",fileExtension:"avif"})}static get BINARY(){return f.parse({mediaType:"application/octet-stream"})}static get BMP(){return f.parse({mediaType:"image/bmp",fileExtension:"bmp"})}static get CBZ(){return f.parse({mediaType:"application/vnd.comicbook+zip",name:"Comic Book Archive",fileExtension:"cbz"})}static get CSS(){return f.parse({mediaType:"text/css",fileExtension:"css"})}static get DIVINA(){return f.parse({mediaType:"application/divina+zip",name:"Digital Visual Narratives",fileExtension:"divina"})}static get DIVINA_MANIFEST(){return f.parse({mediaType:"application/divina+json",name:"Digital Visual Narratives",fileExtension:"json"})}static get EPUB(){return f.parse({mediaType:"application/epub+zip",name:"EPUB",fileExtension:"epub"})}static get GIF(){return f.parse({mediaType:"image/gif",fileExtension:"gif"})}static get GZ(){return f.parse({mediaType:"application/gzip",fileExtension:"gz"})}static get HTML(){return f.parse({mediaType:"text/html",fileExtension:"html"})}static get JAVASCRIPT(){return f.parse({mediaType:"text/javascript",fileExtension:"js"})}static get JPEG(){return f.parse({mediaType:"image/jpeg",fileExtension:"jpeg"})}static get JSON(){return f.parse({mediaType:"application/json"})}static get LCP_LICENSE_DOCUMENT(){return f.parse({mediaType:"application/vnd.readium.lcp.license.v1.0+json",name:"LCP License",fileExtension:"lcpl"})}static get LCP_PROTECTED_AUDIOBOOK(){return f.parse({mediaType:"application/audiobook+lcp",name:"LCP Protected Audiobook",fileExtension:"lcpa"})}static get LCP_PROTECTED_PDF(){return f.parse({mediaType:"application/pdf+lcp",name:"LCP Protected PDF",fileExtension:"lcpdf"})}static get LCP_STATUS_DOCUMENT(){return f.parse({mediaType:"application/vnd.readium.license.status.v1.0+json"})}static get LPF(){return f.parse({mediaType:"application/lpf+zip",fileExtension:"lpf"})}static get MP3(){return f.parse({mediaType:"audio/mpeg",fileExtension:"mp3"})}static get MPEG(){return f.parse({mediaType:"video/mpeg",fileExtension:"mpeg"})}static get NCX(){return f.parse({mediaType:"application/x-dtbncx+xml",fileExtension:"ncx"})}static get OGG(){return f.parse({mediaType:"audio/ogg",fileExtension:"oga"})}static get OGV(){return f.parse({mediaType:"video/ogg",fileExtension:"ogv"})}static get OPDS1(){return f.parse({mediaType:"application/atom+xml;profile=opds-catalog"})}static get OPDS1_ENTRY(){return f.parse({mediaType:"application/atom+xml;type=entry;profile=opds-catalog"})}static get OPDS2(){return f.parse({mediaType:"application/opds+json"})}static get OPDS2_PUBLICATION(){return f.parse({mediaType:"application/opds-publication+json"})}static get OPDS_AUTHENTICATION(){return f.parse({mediaType:"application/opds-authentication+json"})}static get OPUS(){return f.parse({mediaType:"audio/opus",fileExtension:"opus"})}static get OTF(){return f.parse({mediaType:"font/otf",fileExtension:"otf"})}static get PDF(){return f.parse({mediaType:"application/pdf",name:"PDF",fileExtension:"pdf"})}static get PNG(){return f.parse({mediaType:"image/png",fileExtension:"png"})}static get READIUM_AUDIOBOOK(){return f.parse({mediaType:"application/audiobook+zip",name:"Readium Audiobook",fileExtension:"audiobook"})}static get READIUM_AUDIOBOOK_MANIFEST(){return f.parse({mediaType:"application/audiobook+json",name:"Readium Audiobook",fileExtension:"json"})}static get READIUM_CONTENT_DOCUMENT(){return f.parse({mediaType:"application/vnd.readium.content+json",name:"Readium Content Document",fileExtension:"json"})}static get READIUM_GUIDED_NAVIGATION_DOCUMENT(){return f.parse({mediaType:"application/guided-navigation+json",name:"Readium Guided Navigation Document",fileExtension:"json"})}static get READIUM_POSITION_LIST(){return f.parse({mediaType:"application/vnd.readium.position-list+json",name:"Readium Position List",fileExtension:"json"})}static get READIUM_WEBPUB(){return f.parse({mediaType:"application/webpub+zip",name:"Readium Web Publication",fileExtension:"webpub"})}static get READIUM_WEBPUB_MANIFEST(){return f.parse({mediaType:"application/webpub+json",name:"Readium Web Publication",fileExtension:"json"})}static get SMIL(){return f.parse({mediaType:"application/smil+xml",fileExtension:"smil"})}static get SVG(){return f.parse({mediaType:"image/svg+xml",fileExtension:"svg"})}static get TEXT(){return f.parse({mediaType:"text/plain",fileExtension:"txt"})}static get TIFF(){return f.parse({mediaType:"image/tiff",fileExtension:"tiff"})}static get TTF(){return f.parse({mediaType:"font/ttf",fileExtension:"ttf"})}static get W3C_WPUB_MANIFEST(){return f.parse({mediaType:"application/x.readium.w3c.wpub+json",name:"Web Publication",fileExtension:"json"})}static get WAV(){return f.parse({mediaType:"audio/wav",fileExtension:"wav"})}static get WEBM_AUDIO(){return f.parse({mediaType:"audio/webm",fileExtension:"webm"})}static get WEBM_VIDEO(){return f.parse({mediaType:"video/webm",fileExtension:"webm"})}static get WEBP(){return f.parse({mediaType:"image/webp",fileExtension:"webp"})}static get WOFF(){return f.parse({mediaType:"font/woff",fileExtension:"woff"})}static get WOFF2(){return f.parse({mediaType:"font/woff2",fileExtension:"woff2"})}static get XHTML(){return f.parse({mediaType:"application/xhtml+xml",fileExtension:"xhtml"})}static get XML(){return f.parse({mediaType:"application/xml",fileExtension:"xml"})}static get ZAB(){return f.parse({mediaType:"application/x.readium.zab+zip",name:"Zipped Audio Book",fileExtension:"zab"})}static get ZIP(){return f.parse({mediaType:"application/zip",fileExtension:"zip"})}}class On{constructor(e){this.uri=e,this.parameters=this.getParameters(e)}getParameters(e){const t=/\{\??([^}]+)\}/g,n=e.match(t);return n?new Set(n.join(",").replace(t,"$1").split(",").map(i=>i.trim())):new Set}expand(e){const t=i=>i.split(",").map(o=>{const a=e[o];return a?encodeURIComponent(a):""}).join(","),n=i=>"?"+i.split(",").map(o=>{const a=o.split("=")[0],s=e[a];return s?`${a}=${encodeURIComponent(s)}`:""}).join("&");return this.uri.replace(/\{(\??)([^}]+)\}/g,(...i)=>i[1]?n(i[2]):t(i[2]))}}class E{constructor(e){this.fragments=e.fragments?e.fragments:new Array,this.progression=e.progression,this.totalProgression=e.totalProgression,this.position=e.position,this.otherLocations=e.otherLocations}static deserialize(e){if(!e)return;const t=ot(e.progression),n=ot(e.totalProgression),i=ot(e.position),o=new Map,a=new Set(["fragment","fragments","progression","totalProgression","position"]);return Object.entries(e).forEach(([s,l])=>{a.has(s)||o.set(s,l)}),new E({fragments:zn(e.fragments||e.fragment),progression:t!==void 0&&t>=0&&t<=1?t:void 0,totalProgression:n!==void 0&&n>=0&&n<=1?n:void 0,position:i!==void 0&&i>0?i:void 0,otherLocations:o.size===0?void 0:o})}serialize(){const e={};return this.fragments&&(e.fragments=this.fragments),this.progression!==void 0&&(e.progression=this.progression),this.totalProgression!==void 0&&(e.totalProgression=this.totalProgression),this.position!==void 0&&(e.position=this.position),this.otherLocations&&this.otherLocations.forEach((t,n)=>e[n]=t),e}}class Q{constructor(e){this.after=e.after,this.before=e.before,this.highlight=e.highlight}static deserialize(e){if(e)return new Q({after:e.after,before:e.before,highlight:e.highlight})}serialize(){const e={};return this.after!==void 0&&(e.after=this.after),this.before!==void 0&&(e.before=this.before),this.highlight!==void 0&&(e.highlight=this.highlight),e}}class N{constructor(e){this.href=e.href,this.type=e.type,this.title=e.title,this.locations=e.locations?e.locations:new E({}),this.text=e.text}static deserialize(e){if(e&&e.href&&e.type)return new N({href:e.href,type:e.type,title:e.title,locations:E.deserialize(e.locations),text:Q.deserialize(e.text)})}serialize(){const e={href:this.href,type:this.type};return this.title!==void 0&&(e.title=this.title),this.locations&&(e.locations=this.locations.serialize()),this.text&&(e.text=this.text.serialize()),e}copyWithLocations(e){return new N({href:this.href,type:this.type,title:this.title,text:this.text,locations:new E({...this.locations,...e})})}}class K{constructor(e){this.href=e.href,this.templated=e.templated,this.type=e.type,this.title=e.title,this.rels=e.rels,this.properties=e.properties,this.height=e.height,this.width=e.width,this.size=e.size,this.duration=e.duration,this.bitrate=e.bitrate,this.languages=e.languages,this.alternates=e.alternates,this.children=e.children}static deserialize(e){if(!(!e||typeof e.href!="string"))return new K({href:e.href,templated:e.templated,type:e.type,title:e.title,rels:e.rel?Array.isArray(e.rel)?new Set(e.rel):new Set([e.rel]):void 0,properties:Z.deserialize(e.properties),height:$(e.height),width:$(e.width),size:$(e.size),duration:$(e.duration),bitrate:$(e.bitrate),languages:zn(e.language),alternates:rt.deserialize(e.alternate),children:rt.deserialize(e.children)})}serialize(){const e={href:this.href};return this.templated!==void 0&&(e.templated=this.templated),this.type!==void 0&&(e.type=this.type),this.title!==void 0&&(e.title=this.title),this.rels&&(e.rel=So(this.rels)),this.properties&&(e.properties=this.properties.serialize()),this.height!==void 0&&(e.height=this.height),this.width!==void 0&&(e.width=this.width),this.size!==void 0&&(e.size=this.size),this.duration!==void 0&&(e.duration=this.duration),this.bitrate!==void 0&&(e.bitrate=this.bitrate),this.languages&&(e.language=this.languages),this.alternates&&(e.alternate=this.alternates.serialize()),this.children&&(e.children=this.children.serialize()),e}get mediaType(){return this.type!==void 0?f.parse({mediaType:this.type}):f.BINARY}toURL(e){const t=this.href.replace(/^(\/)/,"");if(t.length===0)return;let n=e||"/";return n.startsWith("/")&&(n="file://"+n),new URL(t,n).href.replace(/^(file:\/\/)/,"")}get templateParameters(){return this.templated?new On(this.href).parameters:new Set}expandTemplate(e){return new K({href:new On(this.href).expand(e),templated:!1})}addProperties(e){const t=K.deserialize(this.serialize());return t.properties=t.properties?t.properties?.add(e):new Z(e),t}get locator(){let e=this.href.split("#");return new N({href:e.length>0&&e[0]!==void 0?e[0]:this.href,type:this.type??"",title:this.title,locations:new E({fragments:e.length>1&&e[1]!==void 0?[e[1]]:[]})})}}class rt{constructor(e){this.items=e}static deserialize(e){if(e&&Array.isArray(e))return new rt(e.map(t=>K.deserialize(t)).filter(t=>t!==void 0))}serialize(){return this.items.map(e=>e.serialize())}findWithRel(e){const t=n=>n.rels&&n.rels.has(e);return this.items.find(t)}filterByRel(e){const t=n=>n.rels&&n.rels.has(e);return this.items.filter(t)}findWithHref(e){const t=n=>n.href===e;return this.items.find(t)}findIndexWithHref(e){const t=n=>n.href===e;return this.items.findIndex(t)}findWithMediaType(e){const t=n=>n.mediaType.matches(e);return this.items.find(t)}filterByMediaType(e){const t=n=>n.mediaType.matches(e);return this.items.filter(t)}filterByMediaTypes(e){const t=n=>{for(const i of e)if(n.mediaType.matches(i))return!0;return!1};return this.items.filter(t)}everyIsAudio(){const e=t=>t.mediaType.isAudio;return this.items.length>0&&this.items.every(e)}everyIsBitmap(){const e=t=>t.mediaType.isBitmap;return this.items.length>0&&this.items.every(e)}everyIsHTML(){const e=t=>t.mediaType.isHTML;return this.items.length>0&&this.items.every(e)}everyIsVideo(){const e=t=>t.mediaType.isVideo;return this.items.length>0&&this.items.every(e)}everyMatchesMediaType(e){return Array.isArray(e)?this.items.length>0&&this.items.every(t=>{for(const n of e)return t.mediaType.matches(n);return!1}):this.items.length>0&&this.items.every(t=>t.mediaType.matches(e))}filterLinksHasType(){return this.items.filter(e=>e.type)}}var An=(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))(An||{}),H=(r=>(r.ltr="ltr",r.rtl="rtl",r))(H||{});Z.prototype.getContains=function(){return new Set(this.otherProperties.contains||[])};function _o(r){const e=r.split(",")[0].trim(),i=(e.toLowerCase().startsWith("npt:")?e.slice(4):e).split(":");if(i.length===1){const o=parseFloat(i[0]);return isNaN(o)?void 0:o}if(i.length===2){const o=parseInt(i[0],10),a=parseFloat(i[1]);return isNaN(o)||isNaN(a)?void 0:o*60+a}if(i.length===3){const o=parseInt(i[0],10),a=parseInt(i[1],10),s=parseFloat(i[2]);return isNaN(o)||isNaN(a)||isNaN(s)?void 0:o*3600+a*60+s}}class at{constructor(e){this.cssSelector=e.cssSelector,this.textNodeIndex=e.textNodeIndex,this.charOffset=e.charOffset}static deserialize(e){if(!(e&&e.cssSelector))return;let t=$(e.textNodeIndex);if(t===void 0)return;let n=$(e.charOffset);return n===void 0&&(n=$(e.offset)),new at({cssSelector:e.cssSelector,textNodeIndex:t,charOffset:n})}serialize(){const e={cssSelector:this.cssSelector,textNodeIndex:this.textNodeIndex};return this.charOffset!==void 0&&(e.charOffset=this.charOffset),e}}class Rt{constructor(e){this.start=e.start,this.end=e.end}static deserialize(e){if(!e)return;let t=at.deserialize(e.start);if(t)return new Rt({start:t,end:at.deserialize(e.end)})}serialize(){const e={start:this.start.serialize()};return this.end&&(e.end=this.end.serialize()),e}}E.prototype.getCssSelector=function(){return this.otherLocations?.get("cssSelector")},E.prototype.getPartialCfi=function(){return this.otherLocations?.get("partialCfi")},E.prototype.getDomRange=function(){return Rt.deserialize(this.otherLocations?.get("domRange"))},E.prototype.fragmentParameters=function(){return new Map(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=>[r[0].trim().toLowerCase(),r[1].trim()]))},E.prototype.htmlId=function(){if(!this.fragments.length)return;let r=this.fragments.find(e=>e.length&&!e.includes("="));if(!r){const e=this.fragmentParameters();e.has("id")?r=e.get("id"):e.has("name")&&(r=e.get("name"))}return r?.startsWith("#")?r.slice(1):r},E.prototype.page=function(){const r=parseInt(this.fragmentParameters().get("page"));if(!isNaN(r)&&r>=0)return r},E.prototype.time=function(){const r=this.fragmentParameters().get("t");if(r)return _o(r)},E.prototype.space=function(){const r=this.fragmentParameters();if(!r.has("xywh"))return;const e=r.get("xywh").split(",").map(t=>parseInt(t));if(e.length===4&&!e.some(isNaN))return e};class Pt{constructor(e){this.currency=e.currency,this.value=e.value}static deserialize(e){if(!e)return;let t=e.currency;if(!(t&&typeof t=="string"&&t.length>0))return;let n=$(e.value);if(n!==void 0)return new Pt({currency:t,value:n})}serialize(){return{currency:this.currency,value:this.value}}}class Ne{constructor(e){this.type=e.type,this.children=e.children}static deserialize(e){if(e&&e.type)return new Ne({type:e.type,children:Ne.deserializeArray(e.children)})}static deserializeArray(e){if(Array.isArray(e))return e.map(t=>Ne.deserialize(t)).filter(t=>t!==void 0)}serialize(){const e={type:this.type};return this.children&&(e.children=this.children.map(t=>t.serialize())),e}}class Ct{constructor(e){this.total=e.total,this.position=e.position}static deserialize(e){if(e)return new Ct({total:$(e.total),position:$(e.position)})}serialize(){const e={};return this.total!==void 0&&(e.total=this.total),this.position!==void 0&&(e.position=this.position),e}}class kt{constructor(e){this.total=e.total,this.available=e.available}static deserialize(e){if(e)return new kt({total:$(e.total),available:$(e.available)})}serialize(){const e={};return this.total!==void 0&&(e.total=this.total),this.available!==void 0&&(e.available=this.available),e}}class Et{constructor(e){this.state=e.state,this.since=e.since,this.until=e.until}static deserialize(e){if(e&&e.state)return new Et({state:e.state,since:Ln(e.since),until:Ln(e.until)})}serialize(){const e={state:this.state};return this.since!==void 0&&(e.since=this.since.toISOString()),this.until!==void 0&&(e.until=this.until.toISOString()),e}}Z.prototype.getNumberOfItems=function(){return $(this.otherProperties.numberOfItems)},Z.prototype.getPrice=function(){return Pt.deserialize(this.otherProperties.price)},Z.prototype.getIndirectAcquisitions=function(){const r=this.otherProperties.indirectAcquisition;if(r&&Array.isArray(r))return r.map(e=>Ne.deserialize(e)).filter(e=>e!==void 0)},Z.prototype.getHolds=function(){return Ct.deserialize(this.otherProperties.holds)},Z.prototype.getCopies=function(){return kt.deserialize(this.otherProperties.copies)},Z.prototype.getAvailability=function(){return Et.deserialize(this.otherProperties.availability)},Z.prototype.getAuthenticate=function(){return K.deserialize(this.otherProperties.authenticate)};const bo="CssSelectorGenerator";function Tn(r="unknown problem",...e){console.warn(`${bo}: ${r}`,...e)}function vo(r){return r instanceof RegExp}function wo(r){return r.replace(/[|\\{}()[\]^$+?.]/g,"\\$&").replace(/\*/g,".+")}function Ro(r){const e=r.map(t=>{if(vo(t))return n=>t.test(n);if(typeof t=="function")return n=>{const i=t(n);return typeof i!="boolean"?(Tn("pattern matcher function invalid","Provided pattern matching function does not return boolean. It's result will be ignored.",t),!1):i};if(typeof t=="string"){const n=new RegExp("^"+wo(t)+"$");return i=>n.test(i)}return Tn("pattern matcher invalid","Pattern matching only accepts strings, regular expressions and/or functions. This item is invalid and will be ignored.",t),()=>!1});return t=>e.some(n=>n(t))}Ro(["class","id","ng-*"]);const Po=Math.pow(2,32),Nn=()=>Math.round(Math.random()*Po).toString(36),xt=()=>`${Math.round(performance.now())}-${Nn()}-${Nn()}`,be=1;class Co{constructor(e){this.destination=null,this.registrar=new Map,this.origin="",this.channelId="",this.receiver=this.receive.bind(this),this.preLog=[],this.wnd=e,e.addEventListener("message",this.receiver)}receive(e){if(e.source===null)throw Error("Event source is null");if(typeof e.data!="object")return;const t=e.data;if(!(!("_readium"in t)||!t._readium||t._readium<=0)){if(t.key==="_ping"){if(!this.destination){if(this.destination=e.source,this.origin=e.origin,this.channelId=t._channel,t._readium!==be){t._readium>be?this.send("error",`received comms version ${t._readium} higher than ${be}`):this.send("error",`received comms version ${t._readium} lower than ${be}`),this.destination=null,this.origin="",this.channelId="";return}this.send("_pong",void 0),this.preLog.forEach(n=>this.send("log",n)),this.preLog=[]}return}else if(this.channelId){if(t._channel!==this.channelId||e.origin!==this.origin)return}else return;this.handle(t)}}handle(e){const t=this.registrar.get(e.key);if(!t||t.length===0){e.strict&&this.send("_unhandled",e);return}t.forEach(n=>n.cb(e.data,i=>{this.send("_ack",i,e.id)}))}register(e,t,n){Array.isArray(e)||(e=[e]),e.forEach(i=>{const o=this.registrar.get(i);if(o&&o.length>=0){if(o.find(s=>s.module===t))throw new Error(`Trying to register another callback for combination of event ${i} and module ${t}`);o.push({cb:n,module:t}),this.registrar.set(i,o)}else this.registrar.set(i,[{cb:n,module:t}])})}unregister(e,t){Array.isArray(e)||(e=[e]),e.forEach(n=>{const i=this.registrar.get(n);!i||i.length===0||i.splice(i.findIndex(o=>o.module===t),1)})}unregisterAll(e){this.registrar.forEach((t,n)=>this.registrar.set(n,t.filter(i=>i.module!==e)))}log(...e){this.destination?this.send("log",e):this.preLog.push(e)}get ready(){return!!this.destination}destroy(){this.destination=null,this.channelId="",this.preLog=[],this.registrar.clear(),this.wnd.removeEventListener("message",this.receiver)}send(e,t,n=void 0,i=[]){if(!this.destination)throw Error("Attempted to send comms message before destination has been initialized");const o={_readium:be,_channel:this.channelId,id:n??xt(),key:e,data:t};try{this.destination.postMessage(o,{targetOrigin:this.origin,transfer:i})}catch(a){if(i.length>0)throw a;this.destination.postMessage(o,this.origin,i)}}}class ve{}function Mn(r){return r.split("").reverse().join("")}function ko(r,e,t){const n=Mn(e);return t.map(i=>{const o=Math.max(0,i.end-e.length-i.errors),a=Mn(r.slice(o,i.end));return{start:In(a,n,i.errors).reduce((l,d)=>i.end-d.end<l?i.end-d.end:l,i.end),end:i.end,errors:i.errors}})}function Ft(r){return(r|-r)>>31&1}function Un(r,e,t,n){let i=r.P[t],o=r.M[t];const a=n>>>31,s=e[t]|a,l=s|o,d=(s&i)+i^i|s;let c=o|~(d|i),h=i&d;const u=Ft(c&r.lastRowMask[t])-Ft(h&r.lastRowMask[t]);return c<<=1,h<<=1,h|=a,c|=Ft(n)-a,i=h|~(l|c),o=c&l,r.P[t]=i,r.M[t]=o,u}function In(r,e,t){if(e.length===0)return[];t=Math.min(t,e.length);const n=[],i=32,o=Math.ceil(e.length/i)-1,a={P:new Uint32Array(o+1),M:new Uint32Array(o+1),lastRowMask:new Uint32Array(o+1)};a.lastRowMask.fill(1<<31),a.lastRowMask[o]=1<<(e.length-1)%i;const s=new Uint32Array(o+1),l=new Map,d=[];for(let u=0;u<256;u++)d.push(s);for(let u=0;u<e.length;u+=1){const g=e.charCodeAt(u);if(l.has(g))continue;const m=new Uint32Array(o+1);l.set(g,m),g<d.length&&(d[g]=m);for(let p=0;p<=o;p+=1){m[p]=0;for(let _=0;_<i;_+=1){const v=p*i+_;if(v>=e.length)continue;e.charCodeAt(v)===g&&(m[p]|=1<<_)}}}let c=Math.max(0,Math.ceil(t/i)-1);const h=new Uint32Array(o+1);for(let u=0;u<=c;u+=1)h[u]=(u+1)*i;h[o]=e.length;for(let u=0;u<=c;u+=1)a.P[u]=-1,a.M[u]=0;for(let u=0;u<r.length;u+=1){const g=r.charCodeAt(u);let m;g<d.length?m=d[g]:(m=l.get(g),typeof m>"u"&&(m=s));let p=0;for(let _=0;_<=c;_+=1)p=Un(a,m,_,p),h[_]+=p;if(h[c]-p<=t&&c<o&&(m[c+1]&1||p<0)){c+=1,a.P[c]=-1,a.M[c]=0;let _;if(c===o){const v=e.length%i;_=v===0?i:v}else _=i;h[c]=h[c-1]+_-p+Un(a,m,c,p)}else for(;c>0&&h[c]>=t+i;)c-=1;c===o&&h[c]<=t&&(h[c]<t&&n.splice(0,n.length),n.push({start:-1,end:u+1,errors:h[c]}),t=h[c])}return n}function Eo(r,e,t){const n=In(r,e,t);return ko(r,e,n)}function Hn(r,e,t){let n=0;const i=[];for(;n!==-1;)n=r.indexOf(e,n),n!==-1&&(i.push({start:n,end:n+e.length,errors:0}),n+=1);return i.length>0?i:Eo(r,e,t)}function Dn(r,e){return e.length===0||r.length===0?0:1-Hn(r,e,e.length)[0].errors/e.length}function xo(r,e,t={}){if(e.length===0)return null;const n=Math.min(256,e.length/2),i=Hn(r,e,n);if(i.length===0)return null;const o=s=>{const u=1-s.errors/e.length,g=t.prefix?Dn(r.slice(Math.max(0,s.start-t.prefix.length),s.start),t.prefix):1,m=t.suffix?Dn(r.slice(s.end,s.end+t.suffix.length),t.suffix):1;let p=1;return typeof t.hint=="number"&&(p=1-Math.abs(s.start-t.hint)/r.length),(50*u+20*g+20*m+2*p)/92},a=i.map(s=>({start:s.start,end:s.end,score:o(s)}));return a.sort((s,l)=>l.score-s.score),a[0]}function zt(r,e,t){const n=t===1?e:e-1;if(r.charAt(n).trim()!=="")return e;let i,o;if(t===2?(i=r.substring(0,e),o=i.trimEnd()):(i=r.substring(e),o=i.trimStart()),!o.length)return-1;const a=i.length-o.length;return t===2?e-a:e+a}function Wn(r,e){const t=r.commonAncestorContainer.ownerDocument.createNodeIterator(r.commonAncestorContainer,NodeFilter.SHOW_TEXT),n=e===1?r.startContainer:r.endContainer,i=e===1?r.endContainer:r.startContainer;let o=t.nextNode();for(;o&&o!==n;)o=t.nextNode();e===2&&(o=t.previousNode());let a=-1;const s=()=>{if(o=e===1?t.nextNode():t.previousNode(),o){const l=o.textContent,d=e===1?0:l.length;a=zt(l,d,e)}};for(;o&&a===-1&&o!==i;)s();if(o&&a>=0)return{node:o,offset:a};throw new RangeError("No text nodes with non-whitespace text found in range")}function Fo(r){if(!r.toString().trim().length)throw new RangeError("Range contains no non-whitespace text");if(r.startContainer.nodeType!==Node.TEXT_NODE)throw new RangeError("Range startContainer is not a text node");if(r.endContainer.nodeType!==Node.TEXT_NODE)throw new RangeError("Range endContainer is not a text node");const e=r.cloneRange();let t=!1,n=!1;const i={start:zt(r.startContainer.textContent,r.startOffset,1),end:zt(r.endContainer.textContent,r.endOffset,2)};if(i.start>=0&&(e.setStart(r.startContainer,i.start),t=!0),i.end>0&&(e.setEnd(r.endContainer,i.end),n=!0),t&&n)return e;if(!t){const{node:o,offset:a}=Wn(e,1);o&&a>=0&&e.setStart(o,a)}if(!n){const{node:o,offset:a}=Wn(e,2);o&&a>0&&e.setEnd(o,a)}return e}function Bn(r){switch(r.nodeType){case Node.ELEMENT_NODE:case Node.TEXT_NODE:return r.textContent?.length??0;default:return 0}}function jn(r){let e=r.previousSibling,t=0;for(;e;)t+=Bn(e),e=e.previousSibling;return t}function Gn(r,...e){let t=e.shift();const n=r.ownerDocument.createNodeIterator(r,NodeFilter.SHOW_TEXT),i=[];let o=n.nextNode(),a,s=0;for(;t!==void 0&&o;)a=o,s+a.data.length>t?(i.push({node:a,offset:t-s}),t=e.shift()):(o=n.nextNode(),s+=a.data.length);for(;t!==void 0&&a&&s===t;)i.push({node:a,offset:a.data.length}),t=e.shift();if(t!==void 0)throw new RangeError("Offset exceeds text length");return i}class ee{constructor(e,t){if(t<0)throw new Error("Offset is invalid");this.element=e,this.offset=t}relativeTo(e){if(!e.contains(this.element))throw new Error("Parent is not an ancestor of current element");let t=this.element,n=this.offset;for(;t!==e;)n+=jn(t),t=t.parentElement;return new ee(t,n)}resolve(e={}){try{return Gn(this.element,this.offset)[0]}catch(t){if(this.offset===0&&e.direction!==void 0){const n=document.createTreeWalker(this.element.getRootNode(),NodeFilter.SHOW_TEXT);n.currentNode=this.element;const i=e.direction===1,o=i?n.nextNode():n.previousNode();if(!o)throw t;return{node:o,offset:i?0:o.data.length}}else throw t}}static fromCharOffset(e,t){switch(e.nodeType){case Node.TEXT_NODE:return ee.fromPoint(e,t);case Node.ELEMENT_NODE:return new ee(e,t);default:throw new Error("Node is not an element or text node")}}static fromPoint(e,t){switch(e.nodeType){case Node.TEXT_NODE:{if(t<0||t>e.data.length)throw new Error("Text node offset is out of range");if(!e.parentElement)throw new Error("Text node has no parent");const n=jn(e)+t;return new ee(e.parentElement,n)}case Node.ELEMENT_NODE:{if(t<0||t>e.childNodes.length)throw new Error("Child node offset is out of range");let n=0;for(let i=0;i<t;i++)n+=Bn(e.childNodes[i]);return new ee(e,n)}default:throw new Error("Point is not in an element or text node")}}}class se{constructor(e,t){this.start=e,this.end=t}relativeTo(e){return new se(this.start.relativeTo(e),this.end.relativeTo(e))}toRange(){let e,t;this.start.element===this.end.element&&this.start.offset<=this.end.offset?[e,t]=Gn(this.start.element,this.start.offset,this.end.offset):(e=this.start.resolve({direction:1}),t=this.end.resolve({direction:2}));const n=new Range;return n.setStart(e.node,e.offset),n.setEnd(t.node,t.offset),n}static fromRange(e){const t=ee.fromPoint(e.startContainer,e.startOffset),n=ee.fromPoint(e.endContainer,e.endOffset);return new se(t,n)}static fromOffsets(e,t,n){return new se(new ee(e,t),new ee(e,n))}static trimmedRange(e){return Fo(se.fromRange(e).toRange())}}class st{constructor(e,t,n){this.root=e,this.start=t,this.end=n}static fromRange(e,t){const n=se.fromRange(t).relativeTo(e);return new st(e,n.start.offset,n.end.offset)}static fromSelector(e,t){return new st(e,t.start,t.end)}toSelector(){return{type:"TextPositionSelector",start:this.start,end:this.end}}toRange(){return se.fromOffsets(this.root,this.start,this.end).toRange()}}class lt{constructor(e,t,n={}){this.root=e,this.exact=t,this.context=n}static fromRange(e,t){const n=e.textContent,i=se.fromRange(t).relativeTo(e),o=i.start.offset,a=i.end.offset,s=32;return new lt(e,n.slice(o,a),{prefix:n.slice(Math.max(0,o-s),o),suffix:n.slice(a,Math.mi