@readium/navigator-html-injectables 1.3.3 → 2.0.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +978 -1213
- package/dist/index.umd.cjs +9 -9
- package/package.json +7 -8
- package/src/comms/keys.ts +2 -0
- package/src/helpers/color.ts +114 -0
- package/src/helpers/css.ts +37 -0
- package/src/helpers/document.ts +42 -21
- package/src/modules/Decorator.ts +3 -5
- package/src/modules/setup/ReflowableSetup.ts +12 -1
- package/src/modules/snapper/ColumnSnapper.ts +35 -9
- package/src/modules/snapper/ScrollSnapper.ts +24 -17
- package/types/src/comms/keys.d.ts +1 -1
- package/types/src/helpers/color.d.ts +16 -0
- package/types/src/helpers/css.d.ts +6 -0
- package/types/src/helpers/document.d.ts +11 -2
- package/types/src/modules/snapper/ScrollSnapper.d.ts +3 -3
- package/src/helpers/scrollSnapperHelper.ts +0 -43
package/dist/index.umd.cjs
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
(function(w,G){typeof exports=="object"&&typeof module<"u"?G(exports):typeof define=="function"&&define.amd?define(["exports"],G):(w=typeof globalThis<"u"?globalThis:w||self,G(w["navigator-html-injectables"]={}))})(this,function(w){"use strict";const G=Math.pow(2,32),ze=()=>Math.round(Math.random()*G).toString(36),De=()=>`${Math.round(performance.now())}-${ze()}-${ze()}`,V=1;class Be{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!==V){t._readium>V?this.send("error",`received comms version ${t._readium} higher than ${V}`):this.send("error",`received comms version ${t._readium} lower than ${V}`),this.destination=null,this.origin="",this.channelId="";return}this.send("_pong",void 0),this.preLog.forEach(r=>this.send("log",r)),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(r=>r.cb(e.data,n=>{this.send("_ack",n,e.id)}))}register(e,t,r){Array.isArray(e)||(e=[e]),e.forEach(n=>{const s=this.registrar.get(n);if(s&&s.length>=0){if(s.find(a=>a.module===t))throw new Error(`Trying to register another callback for combination of event ${n} and module ${t}`);s.push({cb:r,module:t}),this.registrar.set(n,s)}else this.registrar.set(n,[{cb:r,module:t}])})}unregister(e,t){Array.isArray(e)||(e=[e]),e.forEach(r=>{const n=this.registrar.get(r);!n||n.length===0||n.splice(n.findIndex(s=>s.module===t),1)})}unregisterAll(e){this.registrar.forEach((t,r)=>this.registrar.set(r,t.filter(n=>n.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,r=void 0,n=[]){if(!this.destination)throw Error("Attempted to send comms message before destination has been initialized");const s={_readium:V,_channel:this.channelId,id:r??De(),key:e,data:t};try{this.destination.postMessage(s,{targetOrigin:this.origin,transfer:n})}catch(o){if(n.length>0)throw o;this.destination.postMessage(s,this.origin,n)}}}class me{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 me({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}}class b{constructor(e){this.otherProperties=e}static deserialize(e){if(e)return new b(e)}serialize(){return this.otherProperties}add(e){const t=Object.assign({},this.otherProperties);for(const r in e)t[r]=e[r];return new b(t)}}Object.defineProperty(b.prototype,"encryption",{get:function(){return me.deserialize(this.otherProperties.encrypted)}}),b.prototype.getContains=function(){return new Set(this.otherProperties.contains||[])},b.prototype.getLayout=function(){return this.otherProperties.layout};class l{constructor(e){let t,r,n=e.mediaType.replace(/\s/g,"").split(";");const s=n[0].split("/");if(s.length===2){if(t=s[0].toLowerCase().trim(),r=s[1].toLowerCase().trim(),t.length===0||r.length===0)throw new Error("Invalid media type")}else throw new Error("Invalid media type");const o={};for(let d=1;d<n.length;d++){const f=n[d].split("=");if(f.length===2){const v=f[0].toLocaleLowerCase(),g=v==="charset"?f[1].toUpperCase():f[1];o[v]=g}}const a={},h=Object.keys(o);h.sort((d,f)=>d.localeCompare(f)),h.forEach(d=>a[d]=o[d]);let c="";for(const d in a){const f=a[d];c+=`;${d}=${f}`}const u=`${t}/${r}${c}`,p=a.encoding;this.string=u,this.type=t,this.subtype=r,this.parameters=a,this.encoding=p,this.name=e.name,this.fileExtension=e.fileExtension}static parse(e){return new l(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"?l.parse({mediaType:e}):e;if(!((this.type==="*"||this.type===t.type)&&(this.subtype==="*"||this.subtype===t.subtype)))return!1;const r=new Set(Object.entries(this.parameters).map(([s,o])=>`${s}=${o}`)),n=new Set(Object.entries(t.parameters).map(([s,o])=>`${s}=${o}`));for(const s of Array.from(r.values()))if(!n.has(s))return!1;return!0}matches(e){const t=typeof e=="string"?l.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(l.ZIP,l.LCP_PROTECTED_AUDIOBOOK,l.LCP_PROTECTED_PDF)||this.structuredSyntaxSuffix==="+zip"}get isJSON(){return this.matchesAny(l.JSON)||this.structuredSyntaxSuffix==="+json"}get isOPDS(){return this.matchesAny(l.OPDS1,l.OPDS1_ENTRY,l.OPDS2,l.OPDS2_PUBLICATION,l.OPDS_AUTHENTICATION)||this.structuredSyntaxSuffix==="+json"}get isHTML(){return this.matchesAny(l.HTML,l.XHTML)}get isBitmap(){return this.matchesAny(l.BMP,l.GIF,l.JPEG,l.PNG,l.TIFF,l.WEBP)}get isAudio(){return this.type==="audio"}get isVideo(){return this.type==="video"}get isRWPM(){return this.matchesAny(l.READIUM_AUDIOBOOK_MANIFEST,l.DIVINA_MANIFEST,l.READIUM_WEBPUB_MANIFEST)}get isPublication(){return this.matchesAny(l.READIUM_AUDIOBOOK,l.READIUM_AUDIOBOOK_MANIFEST,l.CBZ,l.DIVINA,l.DIVINA_MANIFEST,l.EPUB,l.LCP_PROTECTED_AUDIOBOOK,l.LCP_PROTECTED_PDF,l.LPF,l.PDF,l.W3C_WPUB_MANIFEST,l.READIUM_WEBPUB,l.READIUM_WEBPUB_MANIFEST,l.ZAB)}static get AAC(){return l.parse({mediaType:"audio/aac",fileExtension:"aac"})}static get ACSM(){return l.parse({mediaType:"application/vnd.adobe.adept+xml",name:"Adobe Content Server Message",fileExtension:"acsm"})}static get AIFF(){return l.parse({mediaType:"audio/aiff",fileExtension:"aiff"})}static get AVI(){return l.parse({mediaType:"video/x-msvideo",fileExtension:"avi"})}static get BINARY(){return l.parse({mediaType:"application/octet-stream"})}static get BMP(){return l.parse({mediaType:"image/bmp",fileExtension:"bmp"})}static get CBZ(){return l.parse({mediaType:"application/vnd.comicbook+zip",name:"Comic Book Archive",fileExtension:"cbz"})}static get CSS(){return l.parse({mediaType:"text/css",fileExtension:"css"})}static get DIVINA(){return l.parse({mediaType:"application/divina+zip",name:"Digital Visual Narratives",fileExtension:"divina"})}static get DIVINA_MANIFEST(){return l.parse({mediaType:"application/divina+json",name:"Digital Visual Narratives",fileExtension:"json"})}static get EPUB(){return l.parse({mediaType:"application/epub+zip",name:"EPUB",fileExtension:"epub"})}static get GIF(){return l.parse({mediaType:"image/gif",fileExtension:"gif"})}static get GZ(){return l.parse({mediaType:"application/gzip",fileExtension:"gz"})}static get HTML(){return l.parse({mediaType:"text/html",fileExtension:"html"})}static get JAVASCRIPT(){return l.parse({mediaType:"text/javascript",fileExtension:"js"})}static get JPEG(){return l.parse({mediaType:"image/jpeg",fileExtension:"jpeg"})}static get JSON(){return l.parse({mediaType:"application/json"})}static get LCP_LICENSE_DOCUMENT(){return l.parse({mediaType:"application/vnd.readium.lcp.license.v1.0+json",name:"LCP License",fileExtension:"lcpl"})}static get LCP_PROTECTED_AUDIOBOOK(){return l.parse({mediaType:"application/audiobook+lcp",name:"LCP Protected Audiobook",fileExtension:"lcpa"})}static get LCP_PROTECTED_PDF(){return l.parse({mediaType:"application/pdf+lcp",name:"LCP Protected PDF",fileExtension:"lcpdf"})}static get LCP_STATUS_DOCUMENT(){return l.parse({mediaType:"application/vnd.readium.license.status.v1.0+json"})}static get LPF(){return l.parse({mediaType:"application/lpf+zip",fileExtension:"lpf"})}static get MP3(){return l.parse({mediaType:"audio/mpeg",fileExtension:"mp3"})}static get MPEG(){return l.parse({mediaType:"video/mpeg",fileExtension:"mpeg"})}static get NCX(){return l.parse({mediaType:"application/x-dtbncx+xml",fileExtension:"ncx"})}static get OGG(){return l.parse({mediaType:"audio/ogg",fileExtension:"oga"})}static get OGV(){return l.parse({mediaType:"video/ogg",fileExtension:"ogv"})}static get OPDS1(){return l.parse({mediaType:"application/atom+xml;profile=opds-catalog"})}static get OPDS1_ENTRY(){return l.parse({mediaType:"application/atom+xml;type=entry;profile=opds-catalog"})}static get OPDS2(){return l.parse({mediaType:"application/opds+json"})}static get OPDS2_PUBLICATION(){return l.parse({mediaType:"application/opds-publication+json"})}static get OPDS_AUTHENTICATION(){return l.parse({mediaType:"application/opds-authentication+json"})}static get OPUS(){return l.parse({mediaType:"audio/opus",fileExtension:"opus"})}static get OTF(){return l.parse({mediaType:"font/otf",fileExtension:"otf"})}static get PDF(){return l.parse({mediaType:"application/pdf",name:"PDF",fileExtension:"pdf"})}static get PNG(){return l.parse({mediaType:"image/png",fileExtension:"png"})}static get READIUM_AUDIOBOOK(){return l.parse({mediaType:"application/audiobook+zip",name:"Readium Audiobook",fileExtension:"audiobook"})}static get READIUM_AUDIOBOOK_MANIFEST(){return l.parse({mediaType:"application/audiobook+json",name:"Readium Audiobook",fileExtension:"json"})}static get READIUM_CONTENT_DOCUMENT(){return l.parse({mediaType:"application/vnd.readium.content+json",name:"Readium Content Document",fileExtension:"json"})}static get READIUM_GUIDED_NAVIGATION_DOCUMENT(){return l.parse({mediaType:"application/guided-navigation+json",name:"Readium Guided Navigation Document",fileExtension:"json"})}static get READIUM_POSITION_LIST(){return l.parse({mediaType:"application/vnd.readium.position-list+json",name:"Readium Position List",fileExtension:"json"})}static get READIUM_WEBPUB(){return l.parse({mediaType:"application/webpub+zip",name:"Readium Web Publication",fileExtension:"webpub"})}static get READIUM_WEBPUB_MANIFEST(){return l.parse({mediaType:"application/webpub+json",name:"Readium Web Publication",fileExtension:"json"})}static get SMIL(){return l.parse({mediaType:"application/smil+xml",fileExtension:"smil"})}static get SVG(){return l.parse({mediaType:"image/svg+xml",fileExtension:"svg"})}static get TEXT(){return l.parse({mediaType:"text/plain",fileExtension:"txt"})}static get TIFF(){return l.parse({mediaType:"image/tiff",fileExtension:"tiff"})}static get TTF(){return l.parse({mediaType:"font/ttf",fileExtension:"ttf"})}static get W3C_WPUB_MANIFEST(){return l.parse({mediaType:"application/x.readium.w3c.wpub+json",name:"Web Publication",fileExtension:"json"})}static get WAV(){return l.parse({mediaType:"audio/wav",fileExtension:"wav"})}static get WEBM_AUDIO(){return l.parse({mediaType:"audio/webm",fileExtension:"webm"})}static get WEBM_VIDEO(){return l.parse({mediaType:"video/webm",fileExtension:"webm"})}static get WEBP(){return l.parse({mediaType:"image/webp",fileExtension:"webp"})}static get WOFF(){return l.parse({mediaType:"font/woff",fileExtension:"woff"})}static get WOFF2(){return l.parse({mediaType:"font/woff2",fileExtension:"woff2"})}static get XHTML(){return l.parse({mediaType:"application/xhtml+xml",fileExtension:"xhtml"})}static get XML(){return l.parse({mediaType:"application/xml",fileExtension:"xml"})}static get ZAB(){return l.parse({mediaType:"application/x.readium.zab+zip",name:"Zipped Audio Book",fileExtension:"zab"})}static get ZIP(){return l.parse({mediaType:"application/zip",fileExtension:"zip"})}}class We{constructor(e){this.uri=e,this.parameters=this.getParameters(e)}getParameters(e){const t=/\{\??([^}]+)\}/g,r=e.match(t);return r?new Set(r.join(",").replace(t,"$1").split(",").map(n=>n.trim())):new Set}expand(e){const t=n=>n.split(",").map(s=>{const o=e[s];return o?encodeURIComponent(o):""}).join(","),r=n=>"?"+n.split(",").map(s=>{const o=s.split("=")[0],a=e[o];return a?`${o}=${encodeURIComponent(a)}`:""}).join("&");return this.uri.replace(/\{(\??)([^}]+)\}/g,(...n)=>n[1]?r(n[2]):t(n[2]))}}function kt(i){return i&&i instanceof Array?i:void 0}function Fe(i){return i&&typeof i=="string"?[i]:kt(i)}function ke(i){return typeof i=="string"?new Date(i):void 0}function ee(i){return isNaN(i)?void 0:i}function C(i){return ee(i)!==void 0&&Math.sign(i)>=0?i:void 0}function Ut(i){const e=new Array;return i.forEach(t=>e.push(t)),e}class T{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=ee(e.progression),r=ee(e.totalProgression),n=ee(e.position),s=new Map,o=new Set(["fragment","fragments","progression","totalProgression","position"]);return Object.entries(e).forEach(([a,h])=>{o.has(a)||s.set(a,h)}),new T({fragments:Fe(e.fragments||e.fragment),progression:t!==void 0&&t>=0&&t<=1?t:void 0,totalProgression:r!==void 0&&r>=0&&r<=1?r:void 0,position:n!==void 0&&n>0?n:void 0,otherLocations:s.size===0?void 0:s})}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,r)=>e[r]=t),e}}class _{constructor(e){this.after=e.after,this.before=e.before,this.highlight=e.highlight}static deserialize(e){if(e)return new _({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 z{constructor(e){this.href=e.href,this.type=e.type,this.title=e.title,this.locations=e.locations?e.locations:new T({}),this.text=e.text}static deserialize(e){if(e&&e.href&&e.type)return new z({href:e.href,type:e.type,title:e.title,locations:T.deserialize(e.locations),text:_.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 z({href:this.href,type:this.type,title:this.title,text:this.text,locations:new T({...this.locations,...e})})}}class q{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.duration=e.duration,this.bitrate=e.bitrate,this.languages=e.languages,this.alternates=e.alternates,this.children=e.children}static deserialize(e){if(e&&e.href&&typeof e.href=="string")return new q({href:e.href,templated:e.templated,type:e.type,title:e.title,rels:e.rel?e.rel instanceof Array?new Set(e.rel):new Set([e.rel]):void 0,properties:b.deserialize(e.properties),height:C(e.height),width:C(e.width),duration:C(e.duration),bitrate:C(e.bitrate),languages:Fe(e.language),alternates:te.deserialize(e.alternate),children:te.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=Ut(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.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?l.parse({mediaType:this.type}):l.BINARY}toURL(e){const t=this.href.replace(/^(\/)/,"");if(t.length===0)return;let r=e||"/";return r.startsWith("/")&&(r="file://"+r),new URL(t,r).href.replace(/^(file:\/\/)/,"")}get templateParameters(){return this.templated?new We(this.href).parameters:new Set}expandTemplate(e){return new q({href:new We(this.href).expand(e),templated:!1})}addProperties(e){var t;const r=q.deserialize(this.serialize());return r.properties=r.properties?(t=r.properties)==null?void 0:t.add(e):new b(e),r}get locator(){let e=this.href.split("#");return new z({href:e.length>0&&e[0]!==void 0?e[0]:this.href,type:this.type??"",title:this.title,locations:new T({fragments:e.length>1&&e[1]!==void 0?[e[1]]:[]})})}}class te{constructor(e){this.items=e}static deserialize(e){if(e&&e instanceof Array)return new te(e.map(t=>q.deserialize(t)).filter(t=>t!==void 0))}serialize(){return this.items.map(e=>e.serialize())}findWithRel(e){const t=r=>r.rels&&r.rels.has(e);return this.items.find(t)}filterByRel(e){const t=r=>r.rels&&r.rels.has(e);return this.items.filter(t)}findWithHref(e){const t=r=>r.href===e;return this.items.find(t)}findIndexWithHref(e){const t=r=>r.href===e;return this.items.findIndex(t)}findWithMediaType(e){const t=r=>r.mediaType.matches(e);return this.items.find(t)}filterByMediaType(e){const t=r=>r.mediaType.matches(e);return this.items.filter(t)}filterByMediaTypes(e){const t=r=>{for(const n of e)if(r.mediaType.matches(n))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 r of e)return t.mediaType.matches(r);return!1}):this.items.length>0&&this.items.every(t=>t.mediaType.matches(e))}filterLinksHasType(){return this.items.filter(e=>e.type)}}class ie{constructor(e){this.cssSelector=e.cssSelector,this.textNodeIndex=e.textNodeIndex,this.charOffset=e.charOffset}static deserialize(e){if(!(e&&e.cssSelector))return;let t=C(e.textNodeIndex);if(t===void 0)return;let r=C(e.charOffset);return r===void 0&&(r=C(e.offset)),new ie({cssSelector:e.cssSelector,textNodeIndex:t,charOffset:r})}serialize(){const e={cssSelector:this.cssSelector,textNodeIndex:this.textNodeIndex};return this.charOffset!==void 0&&(e.charOffset=this.charOffset),e}}class ge{constructor(e){this.start=e.start,this.end=e.end}static deserialize(e){if(!e)return;let t=ie.deserialize(e.start);if(t)return new ge({start:t,end:ie.deserialize(e.end)})}serialize(){const e={start:this.start.serialize()};return this.end&&(e.end=this.end.serialize()),e}}T.prototype.getCssSelector=function(){var i;return(i=this.otherLocations)==null?void 0:i.get("cssSelector")},T.prototype.getPartialCfi=function(){var i;return(i=this.otherLocations)==null?void 0:i.get("partialCfi")},T.prototype.getDomRange=function(){var i;return ge.deserialize((i=this.otherLocations)==null?void 0:i.get("domRange"))},T.prototype.fragmentParameters=function(){return new Map(this.fragments.map(i=>i.startsWith("#")?i.slice(1):i).join("&").split("&").filter(i=>!i.startsWith("#")).map(i=>i.split("=")).filter(i=>i.length===2).map(i=>[i[0].trim().toLowerCase(),i[1].trim()]))},T.prototype.htmlId=function(){if(!this.fragments.length)return;let i=this.fragments.find(e=>e.length&&!e.includes("="));if(!i){const e=this.fragmentParameters();e.has("id")?i=e.get("id"):e.has("name")&&(i=e.get("name"))}return i!=null&&i.startsWith("#")?i.slice(1):i},T.prototype.page=function(){const i=parseInt(this.fragmentParameters().get("page"));if(!isNaN(i)&&i>=0)return i},T.prototype.time=function(){const i=parseInt(this.fragmentParameters().get("t"));if(!isNaN(i))return i},T.prototype.space=function(){const i=this.fragmentParameters();if(!i.has("xywh"))return;const e=i.get("xywh").split(",").map(t=>parseInt(t));if(e.length===4&&!e.some(isNaN))return e};class ve{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 r=C(e.value);if(r!==void 0)return new ve({currency:t,value:r})}serialize(){return{currency:this.currency,value:this.value}}}class Y{constructor(e){this.type=e.type,this.children=e.children}static deserialize(e){if(e&&e.type)return new Y({type:e.type,children:Y.deserializeArray(e.children)})}static deserializeArray(e){if(e instanceof Array)return e.map(t=>Y.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 ye{constructor(e){this.total=e.total,this.position=e.position}static deserialize(e){if(e)return new ye({total:C(e.total),position:C(e.position)})}serialize(){const e={};return this.total!==void 0&&(e.total=this.total),this.position!==void 0&&(e.position=this.position),e}}class be{constructor(e){this.total=e.total,this.available=e.available}static deserialize(e){if(e)return new be({total:C(e.total),available:C(e.available)})}serialize(){const e={};return this.total!==void 0&&(e.total=this.total),this.available!==void 0&&(e.available=this.available),e}}class Ee{constructor(e){this.state=e.state,this.since=e.since,this.until=e.until}static deserialize(e){if(e&&e.state)return new Ee({state:e.state,since:ke(e.since),until:ke(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}}b.prototype.getNumberOfItems=function(){return C(this.otherProperties.numberOfItems)},b.prototype.getPrice=function(){return ve.deserialize(this.otherProperties.price)},b.prototype.getIndirectAcquisitions=function(){const i=this.otherProperties.indirectAcquisition;if(i&&i instanceof Array)return i.map(e=>Y.deserialize(e)).filter(e=>e!==void 0)},b.prototype.getHolds=function(){return ye.deserialize(this.otherProperties.holds)},b.prototype.getCopies=function(){return be.deserialize(this.otherProperties.copies)},b.prototype.getAvailability=function(){return Ee.deserialize(this.otherProperties.availability)},b.prototype.getAuthenticate=function(){return q.deserialize(this.otherProperties.authenticate)},b.prototype.getClipped=function(){return this.otherProperties.clipped},b.prototype.getFit=function(){return this.otherProperties.fit},b.prototype.getOrientation=function(){return this.otherProperties.orientation},b.prototype.getOverflow=function(){return this.otherProperties.overflow},b.prototype.getPage=function(){return this.otherProperties.page||void 0},b.prototype.getSpread=function(){return this.otherProperties.spread||void 0};var D;(function(i){i.NONE="none",i.DESCENDANT="descendant",i.CHILD="child"})(D||(D={}));var N;(function(i){i.id="id",i.class="class",i.tag="tag",i.attribute="attribute",i.nthchild="nthchild",i.nthoftype="nthoftype"})(N||(N={}));const Ht="CssSelectorGenerator";function Ue(i="unknown problem",...e){console.warn(`${Ht}: ${i}`,...e)}N.id,N.class,N.tag,N.attribute,Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY;function $t(i){return i instanceof RegExp}function Vt(i){return i.replace(/[|\\{}()[\]^$+?.]/g,"\\$&").replace(/\*/g,".+")}function _t(i){const e=i.map(t=>{if($t(t))return r=>t.test(r);if(typeof t=="function")return r=>{const n=t(r);return typeof n!="boolean"?(Ue("pattern matcher function invalid","Provided pattern matching function does not return boolean. It's result will be ignored.",t),!1):n};if(typeof t=="string"){const r=new RegExp("^"+Vt(t)+"$");return n=>r.test(n)}return Ue("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(r=>r(t))}const qt="",jt=" > ",Xt=" ";D.NONE+"",D.NONE,D.DESCENDANT+"",D.DESCENDANT,D.CHILD+"",D.CHILD,N.nthoftype,N.tag,N.id,N.class,N.attribute,N.nthchild,_t(["class","id","ng-*"]);class J{}function He(i){return i.split("").reverse().join("")}function Gt(i,e,t){const r=He(e);return t.map(n=>{const s=Math.max(0,n.end-e.length-n.errors),o=He(i.slice(s,n.end));return{start:Ve(o,r,n.errors).reduce((h,c)=>n.end-c.end<h?n.end-c.end:h,n.end),end:n.end,errors:n.errors}})}function xe(i){return(i|-i)>>31&1}function $e(i,e,t,r){let n=i.P[t],s=i.M[t];const o=r>>>31,a=e[t]|o,h=a|s,c=(a&n)+n^n|a;let u=s|~(c|n),p=n&c;const d=xe(u&i.lastRowMask[t])-xe(p&i.lastRowMask[t]);return u<<=1,p<<=1,p|=o,u|=xe(r)-o,n=p|~(h|u),s=u&h,i.P[t]=n,i.M[t]=s,d}function Ve(i,e,t){if(e.length===0)return[];t=Math.min(t,e.length);const r=[],n=32,s=Math.ceil(e.length/n)-1,o={P:new Uint32Array(s+1),M:new Uint32Array(s+1),lastRowMask:new Uint32Array(s+1)};o.lastRowMask.fill(1<<31),o.lastRowMask[s]=1<<(e.length-1)%n;const a=new Uint32Array(s+1),h=new Map,c=[];for(let d=0;d<256;d++)c.push(a);for(let d=0;d<e.length;d+=1){const f=e.charCodeAt(d);if(h.has(f))continue;const v=new Uint32Array(s+1);h.set(f,v),f<c.length&&(c[f]=v);for(let g=0;g<=s;g+=1){v[g]=0;for(let y=0;y<n;y+=1){const x=g*n+y;if(x>=e.length)continue;e.charCodeAt(x)===f&&(v[g]|=1<<y)}}}let u=Math.max(0,Math.ceil(t/n)-1);const p=new Uint32Array(s+1);for(let d=0;d<=u;d+=1)p[d]=(d+1)*n;p[s]=e.length;for(let d=0;d<=u;d+=1)o.P[d]=-1,o.M[d]=0;for(let d=0;d<i.length;d+=1){const f=i.charCodeAt(d);let v;f<c.length?v=c[f]:(v=h.get(f),typeof v>"u"&&(v=a));let g=0;for(let y=0;y<=u;y+=1)g=$e(o,v,y,g),p[y]+=g;if(p[u]-g<=t&&u<s&&(v[u+1]&1||g<0)){u+=1,o.P[u]=-1,o.M[u]=0;let y;if(u===s){const x=e.length%n;y=x===0?n:x}else y=n;p[u]=p[u-1]+y-g+$e(o,v,u,g)}else for(;u>0&&p[u]>=t+n;)u-=1;u===s&&p[u]<=t&&(p[u]<t&&r.splice(0,r.length),r.push({start:-1,end:d+1,errors:p[u]}),t=p[u])}return r}function Yt(i,e,t){const r=Ve(i,e,t);return Gt(i,e,r)}function _e(i,e,t){let r=0;const n=[];for(;r!==-1;)r=i.indexOf(e,r),r!==-1&&(n.push({start:r,end:r+e.length,errors:0}),r+=1);return n.length>0?n:Yt(i,e,t)}function qe(i,e){return e.length===0||i.length===0?0:1-_e(i,e,e.length)[0].errors/e.length}function Jt(i,e,t={}){if(e.length===0)return null;const r=Math.min(256,e.length/2),n=_e(i,e,r);if(n.length===0)return null;const s=a=>{const d=1-a.errors/e.length,f=t.prefix?qe(i.slice(Math.max(0,a.start-t.prefix.length),a.start),t.prefix):1,v=t.suffix?qe(i.slice(a.end,a.end+t.suffix.length),t.suffix):1;let g=1;typeof t.hint=="number"&&(g=1-Math.abs(a.start-t.hint)/i.length);const y=50*d+20*f+20*v+2*g,x=50+20+20+2;return y/x},o=n.map(a=>({start:a.start,end:a.end,score:s(a)}));return o.sort((a,h)=>h.score-a.score),o[0]}function we(i,e,t){const r=t===1?e:e-1;if(i.charAt(r).trim()!=="")return e;let n,s;if(t===2?(n=i.substring(0,e),s=n.trimEnd()):(n=i.substring(e),s=n.trimStart()),!s.length)return-1;const o=n.length-s.length;return t===2?e-o:e+o}function je(i,e){const t=i.commonAncestorContainer.ownerDocument.createNodeIterator(i.commonAncestorContainer,NodeFilter.SHOW_TEXT),r=e===1?i.startContainer:i.endContainer,n=e===1?i.endContainer:i.startContainer;let s=t.nextNode();for(;s&&s!==r;)s=t.nextNode();e===2&&(s=t.previousNode());let o=-1;const a=()=>{if(s=e===1?t.nextNode():t.previousNode(),s){const h=s.textContent,c=e===1?0:h.length;o=we(h,c,e)}};for(;s&&o===-1&&s!==n;)a();if(s&&o>=0)return{node:s,offset:o};throw new RangeError("No text nodes with non-whitespace text found in range")}function Kt(i){if(!i.toString().trim().length)throw new RangeError("Range contains no non-whitespace text");if(i.startContainer.nodeType!==Node.TEXT_NODE)throw new RangeError("Range startContainer is not a text node");if(i.endContainer.nodeType!==Node.TEXT_NODE)throw new RangeError("Range endContainer is not a text node");const e=i.cloneRange();let t=!1,r=!1;const n={start:we(i.startContainer.textContent,i.startOffset,1),end:we(i.endContainer.textContent,i.endOffset,2)};if(n.start>=0&&(e.setStart(i.startContainer,n.start),t=!0),n.end>0&&(e.setEnd(i.endContainer,n.end),r=!0),t&&r)return e;if(!t){const{node:s,offset:o}=je(e,1);s&&o>=0&&e.setStart(s,o)}if(!r){const{node:s,offset:o}=je(e,2);s&&o>0&&e.setEnd(s,o)}return e}function Xe(i){var e;switch(i.nodeType){case Node.ELEMENT_NODE:case Node.TEXT_NODE:return((e=i.textContent)==null?void 0:e.length)??0;default:return 0}}function Ge(i){let e=i.previousSibling,t=0;for(;e;)t+=Xe(e),e=e.previousSibling;return t}function Ye(i,...e){let t=e.shift();const r=i.ownerDocument.createNodeIterator(i,NodeFilter.SHOW_TEXT),n=[];let s=r.nextNode(),o,a=0;for(;t!==void 0&&s;)o=s,a+o.data.length>t?(n.push({node:o,offset:t-a}),t=e.shift()):(s=r.nextNode(),a+=o.data.length);for(;t!==void 0&&o&&a===t;)n.push({node:o,offset:o.data.length}),t=e.shift();if(t!==void 0)throw new RangeError("Offset exceeds text length");return n}class L{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,r=this.offset;for(;t!==e;)r+=Ge(t),t=t.parentElement;return new L(t,r)}resolve(e={}){try{return Ye(this.element,this.offset)[0]}catch(t){if(this.offset===0&&e.direction!==void 0){const r=document.createTreeWalker(this.element.getRootNode(),NodeFilter.SHOW_TEXT);r.currentNode=this.element;const n=e.direction===1,s=n?r.nextNode():r.previousNode();if(!s)throw t;return{node:s,offset:n?0:s.data.length}}else throw t}}static fromCharOffset(e,t){switch(e.nodeType){case Node.TEXT_NODE:return L.fromPoint(e,t);case Node.ELEMENT_NODE:return new L(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 r=Ge(e)+t;return new L(e.parentElement,r)}case Node.ELEMENT_NODE:{if(t<0||t>e.childNodes.length)throw new Error("Child node offset is out of range");let r=0;for(let n=0;n<t;n++)r+=Xe(e.childNodes[n]);return new L(e,r)}default:throw new Error("Point is not in an element or text node")}}}class B{constructor(e,t){this.start=e,this.end=t}relativeTo(e){return new B(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]=Ye(this.start.element,this.start.offset,this.end.offset):(e=this.start.resolve({direction:1}),t=this.end.resolve({direction:2}));const r=new Range;return r.setStart(e.node,e.offset),r.setEnd(t.node,t.offset),r}static fromRange(e){const t=L.fromPoint(e.startContainer,e.startOffset),r=L.fromPoint(e.endContainer,e.endOffset);return new B(t,r)}static fromOffsets(e,t,r){return new B(new L(e,t),new L(e,r))}static trimmedRange(e){return Kt(B.fromRange(e).toRange())}}class re{constructor(e,t,r){this.root=e,this.start=t,this.end=r}static fromRange(e,t){const r=B.fromRange(t).relativeTo(e);return new re(e,r.start.offset,r.end.offset)}static fromSelector(e,t){return new re(e,t.start,t.end)}toSelector(){return{type:"TextPositionSelector",start:this.start,end:this.end}}toRange(){return B.fromOffsets(this.root,this.start,this.end).toRange()}}class ne{constructor(e,t,r={}){this.root=e,this.exact=t,this.context=r}static fromRange(e,t){const r=e.textContent,n=B.fromRange(t).relativeTo(e),s=n.start.offset,o=n.end.offset,a=32;return new ne(e,r.slice(s,o),{prefix:r.slice(Math.max(0,s-a),s),suffix:r.slice(o,Math.min(r.length,o+a))})}static fromSelector(e,t){const{prefix:r,suffix:n}=t;return new ne(e,t.exact,{prefix:r,suffix:n})}toSelector(){return{type:"TextQuoteSelector",exact:this.exact,prefix:this.context.prefix,suffix:this.context.suffix}}toRange(e={}){return this.toPositionAnchor(e).toRange()}toPositionAnchor(e={}){const t=this.root.textContent,r=Jt(t,this.exact,{...this.context,hint:e.hint});if(!r)throw new Error("Quote not found");return new re(this.root,r.start,r.end)}}function Zt(i){const e=i.tagName.toUpperCase();return e==="IMG"||e==="VIDEO"||e==="AUDIO"||e==="IFRAME"||e==="OBJECT"||e==="EMBED"||e==="CANVAS"}function Te(i,e){try{const t=e.locations,r=e.text;if(r&&r.highlight){let n;t&&t.getCssSelector()&&(n=i.querySelector(t.getCssSelector())),n||(n=i.body);const s=new ne(n,r.highlight,{prefix:r.before,suffix:r.after});try{return s.toRange()}catch{return console.warn("Quote not found:",s),null}}if(t){let n=null;if(!n&&t.getCssSelector()&&(n=i.querySelector(t.getCssSelector())),!n&&t.fragments){for(const s of t.fragments)if(n=i.getElementById(s),n)break}if(n){const s=i.createRange();return n.childNodes.length===0||Zt(n)?(s.selectNode(n),s):(s.setStartBefore(n),s.setEndAfter(n),s)}}}catch(t){console.error(t)}return null}function Qt(i,e){let t=i.getClientRects();t.length||i.commonAncestorContainer.nodeType===Node.ELEMENT_NODE&&(t=i.commonAncestorContainer.getClientRects());const r=1,n=[];for(const c of t)n.push({bottom:c.bottom,height:c.height,left:c.left,right:c.right,top:c.top,width:c.width});const s=Je(n,r,e),o=ti(s,r),a=Ke(o),h=2*2;for(let c=a.length-1;c>=0;c--){const u=a[c];if(!(u.width*u.height>h))if(a.length>1)a.splice(c,1);else break}return a}function Je(i,e,t){for(let r=0;r<i.length;r++)for(let n=r+1;n<i.length;n++){const s=i[r],o=i[n];if(s===o)continue;const a=A(s.top,o.top,e)&&A(s.bottom,o.bottom,e),h=A(s.left,o.left,e)&&A(s.right,o.right,e);if((h&&!t||a&&!h)&&Qe(s,o,e)){const d=i.filter(v=>v!==s&&v!==o),f=ei(s,o);return d.push(f),Je(d,e,t)}}return i}function ei(i,e){const t=Math.min(i.left,e.left),r=Math.max(i.right,e.right),n=Math.min(i.top,e.top),s=Math.max(i.bottom,e.bottom);return{bottom:s,height:s-n,left:t,right:r,top:n,width:r-t}}function ti(i,e){const t=new Set(i);for(const r of i){if(!(r.width>1&&r.height>1)){t.delete(r);continue}for(const s of i)if(r!==s&&t.has(s)&&ii(s,r,e)){t.delete(r);break}}return Array.from(t)}function ii(i,e,t){return se(i,e.left,e.top,t)&&se(i,e.right,e.top,t)&&se(i,e.left,e.bottom,t)&&se(i,e.right,e.bottom,t)}function se(i,e,t,r){return(i.left<e||A(i.left,e,r))&&(i.right>e||A(i.right,e,r))&&(i.top<t||A(i.top,t,r))&&(i.bottom>t||A(i.bottom,t,r))}function Ke(i){for(let e=0;e<i.length;e++)for(let t=e+1;t<i.length;t++){const r=i[e],n=i[t];if(r!==n&&Qe(r,n,-1)){let s=[],o;const a=Ze(r,n);if(a.length===1)s=a,o=r;else{const c=Ze(n,r);a.length<c.length?(s=a,o=r):(s=c,o=n)}const h=i.filter(c=>c!==o);return Array.prototype.push.apply(h,s),Ke(h)}}return i}function Ze(i,e){const t=ri(e,i);if(t.height===0||t.width===0)return[i];const r=[];{const n={bottom:i.bottom,height:0,left:i.left,right:t.left,top:i.top,width:0};n.width=n.right-n.left,n.height=n.bottom-n.top,n.height!==0&&n.width!==0&&r.push(n)}{const n={bottom:t.top,height:0,left:t.left,right:t.right,top:i.top,width:0};n.width=n.right-n.left,n.height=n.bottom-n.top,n.height!==0&&n.width!==0&&r.push(n)}{const n={bottom:i.bottom,height:0,left:t.left,right:t.right,top:t.bottom,width:0};n.width=n.right-n.left,n.height=n.bottom-n.top,n.height!==0&&n.width!==0&&r.push(n)}{const n={bottom:i.bottom,height:0,left:t.right,right:i.right,top:i.top,width:0};n.width=n.right-n.left,n.height=n.bottom-n.top,n.height!==0&&n.width!==0&&r.push(n)}return r}function ri(i,e){const t=Math.max(i.left,e.left),r=Math.min(i.right,e.right),n=Math.max(i.top,e.top),s=Math.min(i.bottom,e.bottom);return{bottom:s,height:Math.max(0,s-n),left:t,right:r,top:n,width:Math.max(0,r-t)}}function Qe(i,e,t){return(i.left<e.right||t>=0&&A(i.left,e.right,t))&&(e.left<i.right||t>=0&&A(e.left,i.right,t))&&(i.top<e.bottom||t>=0&&A(i.top,e.bottom,t))&&(e.top<i.bottom||t>=0&&A(e.top,i.bottom,t))}function A(i,e,t){return Math.abs(i-e)<=t}var F=[],ni=function(){return F.some(function(i){return i.activeTargets.length>0})},si=function(){return F.some(function(i){return i.skippedTargets.length>0})},et="ResizeObserver loop completed with undelivered notifications.",oi=function(){var i;typeof ErrorEvent=="function"?i=new ErrorEvent("error",{message:et}):(i=document.createEvent("Event"),i.initEvent("error",!1,!1),i.message=et),window.dispatchEvent(i)},K;(function(i){i.BORDER_BOX="border-box",i.CONTENT_BOX="content-box",i.DEVICE_PIXEL_CONTENT_BOX="device-pixel-content-box"})(K||(K={}));var k=function(i){return Object.freeze(i)},ai=function(){function i(e,t){this.inlineSize=e,this.blockSize=t,k(this)}return i}(),tt=function(){function i(e,t,r,n){return this.x=e,this.y=t,this.width=r,this.height=n,this.top=this.y,this.left=this.x,this.bottom=this.top+this.height,this.right=this.left+this.width,k(this)}return i.prototype.toJSON=function(){var e=this,t=e.x,r=e.y,n=e.top,s=e.right,o=e.bottom,a=e.left,h=e.width,c=e.height;return{x:t,y:r,top:n,right:s,bottom:o,left:a,width:h,height:c}},i.fromRect=function(e){return new i(e.x,e.y,e.width,e.height)},i}(),Se=function(i){return i instanceof SVGElement&&"getBBox"in i},it=function(i){if(Se(i)){var e=i.getBBox(),t=e.width,r=e.height;return!t&&!r}var n=i,s=n.offsetWidth,o=n.offsetHeight;return!(s||o||i.getClientRects().length)},rt=function(i){var e;if(i instanceof Element)return!0;var t=(e=i==null?void 0:i.ownerDocument)===null||e===void 0?void 0:e.defaultView;return!!(t&&i instanceof t.Element)},li=function(i){switch(i.tagName){case"INPUT":if(i.type!=="image")break;case"VIDEO":case"AUDIO":case"EMBED":case"OBJECT":case"CANVAS":case"IFRAME":case"IMG":return!0}return!1},Z=typeof window<"u"?window:{},oe=new WeakMap,nt=/auto|scroll/,hi=/^tb|vertical/,ci=/msie|trident/i.test(Z.navigator&&Z.navigator.userAgent),I=function(i){return parseFloat(i||"0")},j=function(i,e,t){return i===void 0&&(i=0),e===void 0&&(e=0),t===void 0&&(t=!1),new ai((t?e:i)||0,(t?i:e)||0)},st=k({devicePixelContentBoxSize:j(),borderBoxSize:j(),contentBoxSize:j(),contentRect:new tt(0,0,0,0)}),ot=function(i,e){if(e===void 0&&(e=!1),oe.has(i)&&!e)return oe.get(i);if(it(i))return oe.set(i,st),st;var t=getComputedStyle(i),r=Se(i)&&i.ownerSVGElement&&i.getBBox(),n=!ci&&t.boxSizing==="border-box",s=hi.test(t.writingMode||""),o=!r&&nt.test(t.overflowY||""),a=!r&&nt.test(t.overflowX||""),h=r?0:I(t.paddingTop),c=r?0:I(t.paddingRight),u=r?0:I(t.paddingBottom),p=r?0:I(t.paddingLeft),d=r?0:I(t.borderTopWidth),f=r?0:I(t.borderRightWidth),v=r?0:I(t.borderBottomWidth),g=r?0:I(t.borderLeftWidth),y=p+c,x=h+u,O=g+f,m=d+v,E=a?i.offsetHeight-m-i.clientHeight:0,M=o?i.offsetWidth-O-i.clientWidth:0,ue=n?y+O:0,de=n?x+m:0,H=r?r.width:I(t.width)-ue-M,$=r?r.height:I(t.height)-de-E,pe=H+y+M+O,fe=$+x+E+m,X=k({devicePixelContentBoxSize:j(Math.round(H*devicePixelRatio),Math.round($*devicePixelRatio),s),borderBoxSize:j(pe,fe,s),contentBoxSize:j(H,$,s),contentRect:new tt(p,h,H,$)});return oe.set(i,X),X},at=function(i,e,t){var r=ot(i,t),n=r.borderBoxSize,s=r.contentBoxSize,o=r.devicePixelContentBoxSize;switch(e){case K.DEVICE_PIXEL_CONTENT_BOX:return o;case K.BORDER_BOX:return n;default:return s}},ui=function(){function i(e){var t=ot(e);this.target=e,this.contentRect=t.contentRect,this.borderBoxSize=k([t.borderBoxSize]),this.contentBoxSize=k([t.contentBoxSize]),this.devicePixelContentBoxSize=k([t.devicePixelContentBoxSize])}return i}(),lt=function(i){if(it(i))return 1/0;for(var e=0,t=i.parentNode;t;)e+=1,t=t.parentNode;return e},di=function(){var i=1/0,e=[];F.forEach(function(o){if(o.activeTargets.length!==0){var a=[];o.activeTargets.forEach(function(c){var u=new ui(c.target),p=lt(c.target);a.push(u),c.lastReportedSize=at(c.target,c.observedBox),p<i&&(i=p)}),e.push(function(){o.callback.call(o.observer,a,o.observer)}),o.activeTargets.splice(0,o.activeTargets.length)}});for(var t=0,r=e;t<r.length;t++){var n=r[t];n()}return i},ht=function(i){F.forEach(function(t){t.activeTargets.splice(0,t.activeTargets.length),t.skippedTargets.splice(0,t.skippedTargets.length),t.observationTargets.forEach(function(n){n.isActive()&&(lt(n.target)>i?t.activeTargets.push(n):t.skippedTargets.push(n))})})},pi=function(){var i=0;for(ht(i);ni();)i=di(),ht(i);return si()&&oi(),i>0},Ce,ct=[],fi=function(){return ct.splice(0).forEach(function(i){return i()})},mi=function(i){if(!Ce){var e=0,t=document.createTextNode(""),r={characterData:!0};new MutationObserver(function(){return fi()}).observe(t,r),Ce=function(){t.textContent="".concat(e?e--:e++)}}ct.push(i),Ce()},gi=function(i){mi(function(){requestAnimationFrame(i)})},ae=0,vi=function(){return!!ae},yi=250,bi={attributes:!0,characterData:!0,childList:!0,subtree:!0},ut=["resize","load","transitionend","animationend","animationstart","animationiteration","keyup","keydown","mouseup","mousedown","mouseover","mouseout","blur","focus"],dt=function(i){return i===void 0&&(i=0),Date.now()+i},Oe=!1,Ei=function(){function i(){var e=this;this.stopped=!0,this.listener=function(){return e.schedule()}}return i.prototype.run=function(e){var t=this;if(e===void 0&&(e=yi),!Oe){Oe=!0;var r=dt(e);gi(function(){var n=!1;try{n=pi()}finally{if(Oe=!1,e=r-dt(),!vi())return;n?t.run(1e3):e>0?t.run(e):t.start()}})}},i.prototype.schedule=function(){this.stop(),this.run()},i.prototype.observe=function(){var e=this,t=function(){return e.observer&&e.observer.observe(document.body,bi)};document.body?t():Z.addEventListener("DOMContentLoaded",t)},i.prototype.start=function(){var e=this;this.stopped&&(this.stopped=!1,this.observer=new MutationObserver(this.listener),this.observe(),ut.forEach(function(t){return Z.addEventListener(t,e.listener,!0)}))},i.prototype.stop=function(){var e=this;this.stopped||(this.observer&&this.observer.disconnect(),ut.forEach(function(t){return Z.removeEventListener(t,e.listener,!0)}),this.stopped=!0)},i}(),Pe=new Ei,pt=function(i){!ae&&i>0&&Pe.start(),ae+=i,!ae&&Pe.stop()},xi=function(i){return!Se(i)&&!li(i)&&getComputedStyle(i).display==="inline"},wi=function(){function i(e,t){this.target=e,this.observedBox=t||K.CONTENT_BOX,this.lastReportedSize={inlineSize:0,blockSize:0}}return i.prototype.isActive=function(){var e=at(this.target,this.observedBox,!0);return xi(this.target)&&(this.lastReportedSize=e),this.lastReportedSize.inlineSize!==e.inlineSize||this.lastReportedSize.blockSize!==e.blockSize},i}(),Ti=function(){function i(e,t){this.activeTargets=[],this.skippedTargets=[],this.observationTargets=[],this.observer=e,this.callback=t}return i}(),le=new WeakMap,ft=function(i,e){for(var t=0;t<i.length;t+=1)if(i[t].target===e)return t;return-1},he=function(){function i(){}return i.connect=function(e,t){var r=new Ti(e,t);le.set(e,r)},i.observe=function(e,t,r){var n=le.get(e),s=n.observationTargets.length===0;ft(n.observationTargets,t)<0&&(s&&F.push(n),n.observationTargets.push(new wi(t,r&&r.box)),pt(1),Pe.schedule())},i.unobserve=function(e,t){var r=le.get(e),n=ft(r.observationTargets,t),s=r.observationTargets.length===1;n>=0&&(s&&F.splice(F.indexOf(r),1),r.observationTargets.splice(n,1),pt(-1))},i.disconnect=function(e){var t=this,r=le.get(e);r.observationTargets.slice().forEach(function(n){return t.unobserve(e,n.target)}),r.activeTargets.splice(0,r.activeTargets.length)},i}(),mt=function(){function i(e){if(arguments.length===0)throw new TypeError("Failed to construct 'ResizeObserver': 1 argument required, but only 0 present.");if(typeof e!="function")throw new TypeError("Failed to construct 'ResizeObserver': The callback provided as parameter 1 is not a function.");he.connect(this,e)}return i.prototype.observe=function(e,t){if(arguments.length===0)throw new TypeError("Failed to execute 'observe' on 'ResizeObserver': 1 argument required, but only 0 present.");if(!rt(e))throw new TypeError("Failed to execute 'observe' on 'ResizeObserver': parameter 1 is not of type 'Element");he.observe(this,e,t)},i.prototype.unobserve=function(e){if(arguments.length===0)throw new TypeError("Failed to execute 'unobserve' on 'ResizeObserver': 1 argument required, but only 0 present.");if(!rt(e))throw new TypeError("Failed to execute 'unobserve' on 'ResizeObserver': parameter 1 is not of type 'Element");he.unobserve(this,e)},i.prototype.disconnect=function(){he.disconnect(this)},i.toString=function(){return"function ResizeObserver () { [polyfill code] }"},i}();function Si(i,e){return i.document.documentElement.style.getPropertyValue(e)}function Ne(i,e,t){i.document.documentElement.style.setProperty(e,t)}function gt(i,e){i.document.documentElement.style.removeProperty(e)}const Ci=window.ResizeObserver||mt;var vt=(i=>(i.Wrap="wrap",i.Viewport="viewport",i.Bounds="bounds",i.Page="page",i))(vt||{}),yt=(i=>(i.Boxes="boxes",i.Bounds="bounds",i))(yt||{});const Oi="Highlight"in window,bt=["IMG","IMAGE","AUDIO","VIDEO","SVG"];class Pi{constructor(e,t,r,n){this.wnd=e,this.comms=t,this.id=r,this.name=n,this.items=[],this.lastItemId=0,this.container=void 0,this.activateable=!1,this.experimentalHighlights=!1,this.currentRender=0,Oi&&(this.experimentalHighlights=!0,this.notTextFlag=new Map)}get activeable(){return this.activateable}set activeable(e){this.activateable=e}add(e){var o,a,h,c;const t=`${this.id}-${this.lastItemId++}`,r=Te(this.wnd.document,e.locator);if(!r){this.comms.log("Can't locate DOM range for decoration",e);return}const n=r.commonAncestorContainer;n.nodeType!==Node.TEXT_NODE&&this.experimentalHighlights&&(bt.includes(n.nodeName.toUpperCase())&&((o=this.notTextFlag)==null||o.set(t,!0)),n.querySelector(bt.join(", ").toLowerCase())&&((a=this.notTextFlag)==null||a.set(t,!0)),(((h=n.textContent)==null?void 0:h.trim())||"").length===0&&((c=this.notTextFlag)==null||c.set(t,!0)));const s={decoration:e,id:t,range:r};this.items.push(s),this.layout(s),this.renderLayout([s])}remove(e){var n,s;const t=this.items.findIndex(o=>o.decoration.id===e);if(t<0)return;const r=this.items[t];if(this.items.splice(t,1),r.clickableElements=void 0,r.container&&(r.container.remove(),r.container=void 0),this.experimentalHighlights&&!((n=this.notTextFlag)!=null&&n.has(r.id))){const o=this.wnd.CSS.highlights.get(this.id);o==null||o.delete(r.range)}(s=this.notTextFlag)==null||s.delete(r.id)}update(e){this.remove(e.id),this.add(e)}clear(){var e;this.clearContainer(),this.items.length=0,(e=this.notTextFlag)==null||e.clear()}requestLayout(){this.wnd.cancelAnimationFrame(this.currentRender),this.clearContainer(),this.items.forEach(e=>this.layout(e)),this.renderLayout(this.items)}experimentalLayout(e){var n,s;const[t,r]=this.requireContainer(!0);r.add(e.range),t.innerHTML=`
|
|
1
|
+
(function(E,$){typeof exports=="object"&&typeof module<"u"?$(exports):typeof define=="function"&&define.amd?define(["exports"],$):(E=typeof globalThis<"u"?globalThis:E||self,$(E["navigator-html-injectables"]={}))})(this,function(E){"use strict";const $=Math.pow(2,32),fe=()=>Math.round(Math.random()*$).toString(36),me=()=>`${Math.round(performance.now())}-${fe()}-${fe()}`,U=1;class ge{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!==U){t._readium>U?this.send("error",`received comms version ${t._readium} higher than ${U}`):this.send("error",`received comms version ${t._readium} lower than ${U}`),this.destination=null,this.origin="",this.channelId="";return}this.send("_pong",void 0),this.preLog.forEach(i=>this.send("log",i)),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(i=>i.cb(e.data,s=>{this.send("_ack",s,e.id)}))}register(e,t,i){Array.isArray(e)||(e=[e]),e.forEach(s=>{const n=this.registrar.get(s);if(n&&n.length>=0){if(n.find(a=>a.module===t))throw new Error(`Trying to register another callback for combination of event ${s} and module ${t}`);n.push({cb:i,module:t}),this.registrar.set(s,n)}else this.registrar.set(s,[{cb:i,module:t}])})}unregister(e,t){Array.isArray(e)||(e=[e]),e.forEach(i=>{const s=this.registrar.get(i);!s||s.length===0||s.splice(s.findIndex(n=>n.module===t),1)})}unregisterAll(e){this.registrar.forEach((t,i)=>this.registrar.set(i,t.filter(s=>s.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,i=void 0,s=[]){if(!this.destination)throw Error("Attempted to send comms message before destination has been initialized");const n={_readium:U,_channel:this.channelId,id:i??me(),key:e,data:t};try{this.destination.postMessage(n,{targetOrigin:this.origin,transfer:s})}catch(o){if(s.length>0)throw o;this.destination.postMessage(n,this.origin,s)}}}class J{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 J({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}}class b{constructor(e){this.otherProperties=e}static deserialize(e){if(e)return new b(e)}serialize(){return this.otherProperties}add(e){const t=Object.assign({},this.otherProperties);for(const i in e)t[i]=e[i];return new b(t)}}Object.defineProperty(b.prototype,"encryption",{get:function(){return J.deserialize(this.otherProperties.encrypted)}}),b.prototype.getContains=function(){return new Set(this.otherProperties.contains||[])},b.prototype.getLayout=function(){return this.otherProperties.layout};class l{constructor(e){let t,i,s=e.mediaType.replace(/\s/g,"").split(";");const n=s[0].split("/");if(n.length===2){if(t=n[0].toLowerCase().trim(),i=n[1].toLowerCase().trim(),t.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<s.length;u++){const f=s[u].split("=");if(f.length===2){const g=f[0].toLocaleLowerCase(),m=g==="charset"?f[1].toUpperCase():f[1];o[g]=m}}const a={},h=Object.keys(o);h.sort((u,f)=>u.localeCompare(f)),h.forEach(u=>a[u]=o[u]);let c="";for(const u in a){const f=a[u];c+=`;${u}=${f}`}const d=`${t}/${i}${c}`,p=a.encoding;this.string=d,this.type=t,this.subtype=i,this.parameters=a,this.encoding=p,this.name=e.name,this.fileExtension=e.fileExtension}static parse(e){return new l(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"?l.parse({mediaType:e}):e;if(!((this.type==="*"||this.type===t.type)&&(this.subtype==="*"||this.subtype===t.subtype)))return!1;const i=new Set(Object.entries(this.parameters).map(([n,o])=>`${n}=${o}`)),s=new Set(Object.entries(t.parameters).map(([n,o])=>`${n}=${o}`));for(const n of Array.from(i.values()))if(!s.has(n))return!1;return!0}matches(e){const t=typeof e=="string"?l.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(l.ZIP,l.LCP_PROTECTED_AUDIOBOOK,l.LCP_PROTECTED_PDF)||this.structuredSyntaxSuffix==="+zip"}get isJSON(){return this.matchesAny(l.JSON)||this.structuredSyntaxSuffix==="+json"}get isOPDS(){return this.matchesAny(l.OPDS1,l.OPDS1_ENTRY,l.OPDS2,l.OPDS2_PUBLICATION,l.OPDS_AUTHENTICATION)||this.structuredSyntaxSuffix==="+json"}get isHTML(){return this.matchesAny(l.HTML,l.XHTML)}get isBitmap(){return this.matchesAny(l.BMP,l.GIF,l.JPEG,l.PNG,l.TIFF,l.WEBP)}get isAudio(){return this.type==="audio"}get isVideo(){return this.type==="video"}get isRWPM(){return this.matchesAny(l.READIUM_AUDIOBOOK_MANIFEST,l.DIVINA_MANIFEST,l.READIUM_WEBPUB_MANIFEST)}get isPublication(){return this.matchesAny(l.READIUM_AUDIOBOOK,l.READIUM_AUDIOBOOK_MANIFEST,l.CBZ,l.DIVINA,l.DIVINA_MANIFEST,l.EPUB,l.LCP_PROTECTED_AUDIOBOOK,l.LCP_PROTECTED_PDF,l.LPF,l.PDF,l.W3C_WPUB_MANIFEST,l.READIUM_WEBPUB,l.READIUM_WEBPUB_MANIFEST,l.ZAB)}static get AAC(){return l.parse({mediaType:"audio/aac",fileExtension:"aac"})}static get ACSM(){return l.parse({mediaType:"application/vnd.adobe.adept+xml",name:"Adobe Content Server Message",fileExtension:"acsm"})}static get AIFF(){return l.parse({mediaType:"audio/aiff",fileExtension:"aiff"})}static get AVI(){return l.parse({mediaType:"video/x-msvideo",fileExtension:"avi"})}static get BINARY(){return l.parse({mediaType:"application/octet-stream"})}static get BMP(){return l.parse({mediaType:"image/bmp",fileExtension:"bmp"})}static get CBZ(){return l.parse({mediaType:"application/vnd.comicbook+zip",name:"Comic Book Archive",fileExtension:"cbz"})}static get CSS(){return l.parse({mediaType:"text/css",fileExtension:"css"})}static get DIVINA(){return l.parse({mediaType:"application/divina+zip",name:"Digital Visual Narratives",fileExtension:"divina"})}static get DIVINA_MANIFEST(){return l.parse({mediaType:"application/divina+json",name:"Digital Visual Narratives",fileExtension:"json"})}static get EPUB(){return l.parse({mediaType:"application/epub+zip",name:"EPUB",fileExtension:"epub"})}static get GIF(){return l.parse({mediaType:"image/gif",fileExtension:"gif"})}static get GZ(){return l.parse({mediaType:"application/gzip",fileExtension:"gz"})}static get HTML(){return l.parse({mediaType:"text/html",fileExtension:"html"})}static get JAVASCRIPT(){return l.parse({mediaType:"text/javascript",fileExtension:"js"})}static get JPEG(){return l.parse({mediaType:"image/jpeg",fileExtension:"jpeg"})}static get JSON(){return l.parse({mediaType:"application/json"})}static get LCP_LICENSE_DOCUMENT(){return l.parse({mediaType:"application/vnd.readium.lcp.license.v1.0+json",name:"LCP License",fileExtension:"lcpl"})}static get LCP_PROTECTED_AUDIOBOOK(){return l.parse({mediaType:"application/audiobook+lcp",name:"LCP Protected Audiobook",fileExtension:"lcpa"})}static get LCP_PROTECTED_PDF(){return l.parse({mediaType:"application/pdf+lcp",name:"LCP Protected PDF",fileExtension:"lcpdf"})}static get LCP_STATUS_DOCUMENT(){return l.parse({mediaType:"application/vnd.readium.license.status.v1.0+json"})}static get LPF(){return l.parse({mediaType:"application/lpf+zip",fileExtension:"lpf"})}static get MP3(){return l.parse({mediaType:"audio/mpeg",fileExtension:"mp3"})}static get MPEG(){return l.parse({mediaType:"video/mpeg",fileExtension:"mpeg"})}static get NCX(){return l.parse({mediaType:"application/x-dtbncx+xml",fileExtension:"ncx"})}static get OGG(){return l.parse({mediaType:"audio/ogg",fileExtension:"oga"})}static get OGV(){return l.parse({mediaType:"video/ogg",fileExtension:"ogv"})}static get OPDS1(){return l.parse({mediaType:"application/atom+xml;profile=opds-catalog"})}static get OPDS1_ENTRY(){return l.parse({mediaType:"application/atom+xml;type=entry;profile=opds-catalog"})}static get OPDS2(){return l.parse({mediaType:"application/opds+json"})}static get OPDS2_PUBLICATION(){return l.parse({mediaType:"application/opds-publication+json"})}static get OPDS_AUTHENTICATION(){return l.parse({mediaType:"application/opds-authentication+json"})}static get OPUS(){return l.parse({mediaType:"audio/opus",fileExtension:"opus"})}static get OTF(){return l.parse({mediaType:"font/otf",fileExtension:"otf"})}static get PDF(){return l.parse({mediaType:"application/pdf",name:"PDF",fileExtension:"pdf"})}static get PNG(){return l.parse({mediaType:"image/png",fileExtension:"png"})}static get READIUM_AUDIOBOOK(){return l.parse({mediaType:"application/audiobook+zip",name:"Readium Audiobook",fileExtension:"audiobook"})}static get READIUM_AUDIOBOOK_MANIFEST(){return l.parse({mediaType:"application/audiobook+json",name:"Readium Audiobook",fileExtension:"json"})}static get READIUM_CONTENT_DOCUMENT(){return l.parse({mediaType:"application/vnd.readium.content+json",name:"Readium Content Document",fileExtension:"json"})}static get READIUM_GUIDED_NAVIGATION_DOCUMENT(){return l.parse({mediaType:"application/guided-navigation+json",name:"Readium Guided Navigation Document",fileExtension:"json"})}static get READIUM_POSITION_LIST(){return l.parse({mediaType:"application/vnd.readium.position-list+json",name:"Readium Position List",fileExtension:"json"})}static get READIUM_WEBPUB(){return l.parse({mediaType:"application/webpub+zip",name:"Readium Web Publication",fileExtension:"webpub"})}static get READIUM_WEBPUB_MANIFEST(){return l.parse({mediaType:"application/webpub+json",name:"Readium Web Publication",fileExtension:"json"})}static get SMIL(){return l.parse({mediaType:"application/smil+xml",fileExtension:"smil"})}static get SVG(){return l.parse({mediaType:"image/svg+xml",fileExtension:"svg"})}static get TEXT(){return l.parse({mediaType:"text/plain",fileExtension:"txt"})}static get TIFF(){return l.parse({mediaType:"image/tiff",fileExtension:"tiff"})}static get TTF(){return l.parse({mediaType:"font/ttf",fileExtension:"ttf"})}static get W3C_WPUB_MANIFEST(){return l.parse({mediaType:"application/x.readium.w3c.wpub+json",name:"Web Publication",fileExtension:"json"})}static get WAV(){return l.parse({mediaType:"audio/wav",fileExtension:"wav"})}static get WEBM_AUDIO(){return l.parse({mediaType:"audio/webm",fileExtension:"webm"})}static get WEBM_VIDEO(){return l.parse({mediaType:"video/webm",fileExtension:"webm"})}static get WEBP(){return l.parse({mediaType:"image/webp",fileExtension:"webp"})}static get WOFF(){return l.parse({mediaType:"font/woff",fileExtension:"woff"})}static get WOFF2(){return l.parse({mediaType:"font/woff2",fileExtension:"woff2"})}static get XHTML(){return l.parse({mediaType:"application/xhtml+xml",fileExtension:"xhtml"})}static get XML(){return l.parse({mediaType:"application/xml",fileExtension:"xml"})}static get ZAB(){return l.parse({mediaType:"application/x.readium.zab+zip",name:"Zipped Audio Book",fileExtension:"zab"})}static get ZIP(){return l.parse({mediaType:"application/zip",fileExtension:"zip"})}}class ye{constructor(e){this.uri=e,this.parameters=this.getParameters(e)}getParameters(e){const t=/\{\??([^}]+)\}/g,i=e.match(t);return i?new Set(i.join(",").replace(t,"$1").split(",").map(s=>s.trim())):new Set}expand(e){const t=s=>s.split(",").map(n=>{const o=e[n];return o?encodeURIComponent(o):""}).join(","),i=s=>"?"+s.split(",").map(n=>{const o=n.split("=")[0],a=e[o];return a?`${o}=${encodeURIComponent(a)}`:""}).join("&");return this.uri.replace(/\{(\??)([^}]+)\}/g,(...s)=>s[1]?i(s[2]):t(s[2]))}}function ut(r){return r&&r instanceof Array?r:void 0}function ve(r){return r&&typeof r=="string"?[r]:ut(r)}function be(r){return typeof r=="string"?new Date(r):void 0}function q(r){return isNaN(r)?void 0:r}function C(r){return q(r)!==void 0&&Math.sign(r)>=0?r:void 0}function pt(r){const e=new Array;return r.forEach(t=>e.push(t)),e}class x{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=q(e.progression),i=q(e.totalProgression),s=q(e.position),n=new Map,o=new Set(["fragment","fragments","progression","totalProgression","position"]);return Object.entries(e).forEach(([a,h])=>{o.has(a)||n.set(a,h)}),new x({fragments:ve(e.fragments||e.fragment),progression:t!==void 0&&t>=0&&t<=1?t:void 0,totalProgression:i!==void 0&&i>=0&&i<=1?i:void 0,position:s!==void 0&&s>0?s:void 0,otherLocations:n.size===0?void 0:n})}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,i)=>e[i]=t),e}}class k{constructor(e){this.after=e.after,this.before=e.before,this.highlight=e.highlight}static deserialize(e){if(e)return new k({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 R{constructor(e){this.href=e.href,this.type=e.type,this.title=e.title,this.locations=e.locations?e.locations:new x({}),this.text=e.text}static deserialize(e){if(e&&e.href&&e.type)return new R({href:e.href,type:e.type,title:e.title,locations:x.deserialize(e.locations),text:k.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 R({href:this.href,type:this.type,title:this.title,text:this.text,locations:new x({...this.locations,...e})})}}class H{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.duration=e.duration,this.bitrate=e.bitrate,this.languages=e.languages,this.alternates=e.alternates,this.children=e.children}static deserialize(e){if(e&&e.href&&typeof e.href=="string")return new H({href:e.href,templated:e.templated,type:e.type,title:e.title,rels:e.rel?e.rel instanceof Array?new Set(e.rel):new Set([e.rel]):void 0,properties:b.deserialize(e.properties),height:C(e.height),width:C(e.width),duration:C(e.duration),bitrate:C(e.bitrate),languages:ve(e.language),alternates:_.deserialize(e.alternate),children:_.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=pt(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.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?l.parse({mediaType:this.type}):l.BINARY}toURL(e){const t=this.href.replace(/^(\/)/,"");if(t.length===0)return;let i=e||"/";return i.startsWith("/")&&(i="file://"+i),new URL(t,i).href.replace(/^(file:\/\/)/,"")}get templateParameters(){return this.templated?new ye(this.href).parameters:new Set}expandTemplate(e){return new H({href:new ye(this.href).expand(e),templated:!1})}addProperties(e){var t;const i=H.deserialize(this.serialize());return i.properties=i.properties?(t=i.properties)==null?void 0:t.add(e):new b(e),i}get locator(){let e=this.href.split("#");return new R({href:e.length>0&&e[0]!==void 0?e[0]:this.href,type:this.type??"",title:this.title,locations:new x({fragments:e.length>1&&e[1]!==void 0?[e[1]]:[]})})}}class _{constructor(e){this.items=e}static deserialize(e){if(e&&e instanceof Array)return new _(e.map(t=>H.deserialize(t)).filter(t=>t!==void 0))}serialize(){return this.items.map(e=>e.serialize())}findWithRel(e){const t=i=>i.rels&&i.rels.has(e);return this.items.find(t)}filterByRel(e){const t=i=>i.rels&&i.rels.has(e);return this.items.filter(t)}findWithHref(e){const t=i=>i.href===e;return this.items.find(t)}findIndexWithHref(e){const t=i=>i.href===e;return this.items.findIndex(t)}findWithMediaType(e){const t=i=>i.mediaType.matches(e);return this.items.find(t)}filterByMediaType(e){const t=i=>i.mediaType.matches(e);return this.items.filter(t)}filterByMediaTypes(e){const t=i=>{for(const s of e)if(i.mediaType.matches(s))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 i of e)return t.mediaType.matches(i);return!1}):this.items.length>0&&this.items.every(t=>t.mediaType.matches(e))}filterLinksHasType(){return this.items.filter(e=>e.type)}}class X{constructor(e){this.cssSelector=e.cssSelector,this.textNodeIndex=e.textNodeIndex,this.charOffset=e.charOffset}static deserialize(e){if(!(e&&e.cssSelector))return;let t=C(e.textNodeIndex);if(t===void 0)return;let i=C(e.charOffset);return i===void 0&&(i=C(e.offset)),new X({cssSelector:e.cssSelector,textNodeIndex:t,charOffset:i})}serialize(){const e={cssSelector:this.cssSelector,textNodeIndex:this.textNodeIndex};return this.charOffset!==void 0&&(e.charOffset=this.charOffset),e}}class Q{constructor(e){this.start=e.start,this.end=e.end}static deserialize(e){if(!e)return;let t=X.deserialize(e.start);if(t)return new Q({start:t,end:X.deserialize(e.end)})}serialize(){const e={start:this.start.serialize()};return this.end&&(e.end=this.end.serialize()),e}}x.prototype.getCssSelector=function(){var r;return(r=this.otherLocations)==null?void 0:r.get("cssSelector")},x.prototype.getPartialCfi=function(){var r;return(r=this.otherLocations)==null?void 0:r.get("partialCfi")},x.prototype.getDomRange=function(){var r;return Q.deserialize((r=this.otherLocations)==null?void 0:r.get("domRange"))},x.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()]))},x.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!=null&&r.startsWith("#")?r.slice(1):r},x.prototype.page=function(){const r=parseInt(this.fragmentParameters().get("page"));if(!isNaN(r)&&r>=0)return r},x.prototype.time=function(){const r=parseInt(this.fragmentParameters().get("t"));if(!isNaN(r))return r},x.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 ee{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 i=C(e.value);if(i!==void 0)return new ee({currency:t,value:i})}serialize(){return{currency:this.currency,value:this.value}}}class j{constructor(e){this.type=e.type,this.children=e.children}static deserialize(e){if(e&&e.type)return new j({type:e.type,children:j.deserializeArray(e.children)})}static deserializeArray(e){if(e instanceof Array)return e.map(t=>j.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 te{constructor(e){this.total=e.total,this.position=e.position}static deserialize(e){if(e)return new te({total:C(e.total),position:C(e.position)})}serialize(){const e={};return this.total!==void 0&&(e.total=this.total),this.position!==void 0&&(e.position=this.position),e}}class ie{constructor(e){this.total=e.total,this.available=e.available}static deserialize(e){if(e)return new ie({total:C(e.total),available:C(e.available)})}serialize(){const e={};return this.total!==void 0&&(e.total=this.total),this.available!==void 0&&(e.available=this.available),e}}class re{constructor(e){this.state=e.state,this.since=e.since,this.until=e.until}static deserialize(e){if(e&&e.state)return new re({state:e.state,since:be(e.since),until:be(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}}b.prototype.getNumberOfItems=function(){return C(this.otherProperties.numberOfItems)},b.prototype.getPrice=function(){return ee.deserialize(this.otherProperties.price)},b.prototype.getIndirectAcquisitions=function(){const r=this.otherProperties.indirectAcquisition;if(r&&r instanceof Array)return r.map(e=>j.deserialize(e)).filter(e=>e!==void 0)},b.prototype.getHolds=function(){return te.deserialize(this.otherProperties.holds)},b.prototype.getCopies=function(){return ie.deserialize(this.otherProperties.copies)},b.prototype.getAvailability=function(){return re.deserialize(this.otherProperties.availability)},b.prototype.getAuthenticate=function(){return H.deserialize(this.otherProperties.authenticate)},b.prototype.getClipped=function(){return this.otherProperties.clipped},b.prototype.getFit=function(){return this.otherProperties.fit},b.prototype.getOrientation=function(){return this.otherProperties.orientation},b.prototype.getOverflow=function(){return this.otherProperties.overflow},b.prototype.getPage=function(){return this.otherProperties.page||void 0},b.prototype.getSpread=function(){return this.otherProperties.spread||void 0};var z;(function(r){r.NONE="none",r.DESCENDANT="descendant",r.CHILD="child"})(z||(z={}));var N;(function(r){r.id="id",r.class="class",r.tag="tag",r.attribute="attribute",r.nthchild="nthchild",r.nthoftype="nthoftype"})(N||(N={}));const ft="CssSelectorGenerator";function Ee(r="unknown problem",...e){console.warn(`${ft}: ${r}`,...e)}N.id,N.class,N.tag,N.attribute,Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY;function mt(r){return r instanceof RegExp}function gt(r){return r.replace(/[|\\{}()[\]^$+?.]/g,"\\$&").replace(/\*/g,".+")}function yt(r){const e=r.map(t=>{if(mt(t))return i=>t.test(i);if(typeof t=="function")return i=>{const s=t(i);return typeof s!="boolean"?(Ee("pattern matcher function invalid","Provided pattern matching function does not return boolean. It's result will be ignored.",t),!1):s};if(typeof t=="string"){const i=new RegExp("^"+gt(t)+"$");return s=>i.test(s)}return Ee("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(i=>i(t))}const vt="",bt=" > ",Et=" ";z.NONE+"",z.NONE,z.DESCENDANT+"",z.DESCENDANT,z.CHILD+"",z.CHILD,N.nthoftype,N.tag,N.id,N.class,N.attribute,N.nthchild,yt(["class","id","ng-*"]);class V{}function xe(r){return r.split("").reverse().join("")}function xt(r,e,t){const i=xe(e);return t.map(s=>{const n=Math.max(0,s.end-e.length-s.errors),o=xe(r.slice(n,s.end));return{start:Te(o,i,s.errors).reduce((h,c)=>s.end-c.end<h?s.end-c.end:h,s.end),end:s.end,errors:s.errors}})}function se(r){return(r|-r)>>31&1}function Se(r,e,t,i){let s=r.P[t],n=r.M[t];const o=i>>>31,a=e[t]|o,h=a|n,c=(a&s)+s^s|a;let d=n|~(c|s),p=s&c;const u=se(d&r.lastRowMask[t])-se(p&r.lastRowMask[t]);return d<<=1,p<<=1,p|=o,d|=se(i)-o,s=p|~(h|d),n=d&h,r.P[t]=s,r.M[t]=n,u}function Te(r,e,t){if(e.length===0)return[];t=Math.min(t,e.length);const i=[],s=32,n=Math.ceil(e.length/s)-1,o={P:new Uint32Array(n+1),M:new Uint32Array(n+1),lastRowMask:new Uint32Array(n+1)};o.lastRowMask.fill(1<<31),o.lastRowMask[n]=1<<(e.length-1)%s;const a=new Uint32Array(n+1),h=new Map,c=[];for(let u=0;u<256;u++)c.push(a);for(let u=0;u<e.length;u+=1){const f=e.charCodeAt(u);if(h.has(f))continue;const g=new Uint32Array(n+1);h.set(f,g),f<c.length&&(c[f]=g);for(let m=0;m<=n;m+=1){g[m]=0;for(let v=0;v<s;v+=1){const T=m*s+v;if(T>=e.length)continue;e.charCodeAt(T)===f&&(g[m]|=1<<v)}}}let d=Math.max(0,Math.ceil(t/s)-1);const p=new Uint32Array(n+1);for(let u=0;u<=d;u+=1)p[u]=(u+1)*s;p[n]=e.length;for(let u=0;u<=d;u+=1)o.P[u]=-1,o.M[u]=0;for(let u=0;u<r.length;u+=1){const f=r.charCodeAt(u);let g;f<c.length?g=c[f]:(g=h.get(f),typeof g>"u"&&(g=a));let m=0;for(let v=0;v<=d;v+=1)m=Se(o,g,v,m),p[v]+=m;if(p[d]-m<=t&&d<n&&(g[d+1]&1||m<0)){d+=1,o.P[d]=-1,o.M[d]=0;let v;if(d===n){const T=e.length%s;v=T===0?s:T}else v=s;p[d]=p[d-1]+v-m+Se(o,g,d,m)}else for(;d>0&&p[d]>=t+s;)d-=1;d===n&&p[d]<=t&&(p[d]<t&&i.splice(0,i.length),i.push({start:-1,end:u+1,errors:p[d]}),t=p[d])}return i}function St(r,e,t){const i=Te(r,e,t);return xt(r,e,i)}function we(r,e,t){let i=0;const s=[];for(;i!==-1;)i=r.indexOf(e,i),i!==-1&&(s.push({start:i,end:i+e.length,errors:0}),i+=1);return s.length>0?s:St(r,e,t)}function Ce(r,e){return e.length===0||r.length===0?0:1-we(r,e,e.length)[0].errors/e.length}function Tt(r,e,t={}){if(e.length===0)return null;const i=Math.min(256,e.length/2),s=we(r,e,i);if(s.length===0)return null;const n=a=>{const u=1-a.errors/e.length,f=t.prefix?Ce(r.slice(Math.max(0,a.start-t.prefix.length),a.start),t.prefix):1,g=t.suffix?Ce(r.slice(a.end,a.end+t.suffix.length),t.suffix):1;let m=1;typeof t.hint=="number"&&(m=1-Math.abs(a.start-t.hint)/r.length);const v=50*u+20*f+20*g+2*m,T=50+20+20+2;return v/T},o=s.map(a=>({start:a.start,end:a.end,score:n(a)}));return o.sort((a,h)=>h.score-a.score),o[0]}function ne(r,e,t){const i=t===1?e:e-1;if(r.charAt(i).trim()!=="")return e;let s,n;if(t===2?(s=r.substring(0,e),n=s.trimEnd()):(s=r.substring(e),n=s.trimStart()),!n.length)return-1;const o=s.length-n.length;return t===2?e-o:e+o}function Pe(r,e){const t=r.commonAncestorContainer.ownerDocument.createNodeIterator(r.commonAncestorContainer,NodeFilter.SHOW_TEXT),i=e===1?r.startContainer:r.endContainer,s=e===1?r.endContainer:r.startContainer;let n=t.nextNode();for(;n&&n!==i;)n=t.nextNode();e===2&&(n=t.previousNode());let o=-1;const a=()=>{if(n=e===1?t.nextNode():t.previousNode(),n){const h=n.textContent,c=e===1?0:h.length;o=ne(h,c,e)}};for(;n&&o===-1&&n!==s;)a();if(n&&o>=0)return{node:n,offset:o};throw new RangeError("No text nodes with non-whitespace text found in range")}function wt(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,i=!1;const s={start:ne(r.startContainer.textContent,r.startOffset,1),end:ne(r.endContainer.textContent,r.endOffset,2)};if(s.start>=0&&(e.setStart(r.startContainer,s.start),t=!0),s.end>0&&(e.setEnd(r.endContainer,s.end),i=!0),t&&i)return e;if(!t){const{node:n,offset:o}=Pe(e,1);n&&o>=0&&e.setStart(n,o)}if(!i){const{node:n,offset:o}=Pe(e,2);n&&o>0&&e.setEnd(n,o)}return e}function Ne(r){var e;switch(r.nodeType){case Node.ELEMENT_NODE:case Node.TEXT_NODE:return((e=r.textContent)==null?void 0:e.length)??0;default:return 0}}function Me(r){let e=r.previousSibling,t=0;for(;e;)t+=Ne(e),e=e.previousSibling;return t}function Oe(r,...e){let t=e.shift();const i=r.ownerDocument.createNodeIterator(r,NodeFilter.SHOW_TEXT),s=[];let n=i.nextNode(),o,a=0;for(;t!==void 0&&n;)o=n,a+o.data.length>t?(s.push({node:o,offset:t-a}),t=e.shift()):(n=i.nextNode(),a+=o.data.length);for(;t!==void 0&&o&&a===t;)s.push({node:o,offset:o.data.length}),t=e.shift();if(t!==void 0)throw new RangeError("Offset exceeds text length");return s}class A{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,i=this.offset;for(;t!==e;)i+=Me(t),t=t.parentElement;return new A(t,i)}resolve(e={}){try{return Oe(this.element,this.offset)[0]}catch(t){if(this.offset===0&&e.direction!==void 0){const i=document.createTreeWalker(this.element.getRootNode(),NodeFilter.SHOW_TEXT);i.currentNode=this.element;const s=e.direction===1,n=s?i.nextNode():i.previousNode();if(!n)throw t;return{node:n,offset:s?0:n.data.length}}else throw t}}static fromCharOffset(e,t){switch(e.nodeType){case Node.TEXT_NODE:return A.fromPoint(e,t);case Node.ELEMENT_NODE:return new A(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 i=Me(e)+t;return new A(e.parentElement,i)}case Node.ELEMENT_NODE:{if(t<0||t>e.childNodes.length)throw new Error("Child node offset is out of range");let i=0;for(let s=0;s<t;s++)i+=Ne(e.childNodes[s]);return new A(e,i)}default:throw new Error("Point is not in an element or text node")}}}class D{constructor(e,t){this.start=e,this.end=t}relativeTo(e){return new D(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]=Oe(this.start.element,this.start.offset,this.end.offset):(e=this.start.resolve({direction:1}),t=this.end.resolve({direction:2}));const i=new Range;return i.setStart(e.node,e.offset),i.setEnd(t.node,t.offset),i}static fromRange(e){const t=A.fromPoint(e.startContainer,e.startOffset),i=A.fromPoint(e.endContainer,e.endOffset);return new D(t,i)}static fromOffsets(e,t,i){return new D(new A(e,t),new A(e,i))}static trimmedRange(e){return wt(D.fromRange(e).toRange())}}class G{constructor(e,t,i){this.root=e,this.start=t,this.end=i}static fromRange(e,t){const i=D.fromRange(t).relativeTo(e);return new G(e,i.start.offset,i.end.offset)}static fromSelector(e,t){return new G(e,t.start,t.end)}toSelector(){return{type:"TextPositionSelector",start:this.start,end:this.end}}toRange(){return D.fromOffsets(this.root,this.start,this.end).toRange()}}class Y{constructor(e,t,i={}){this.root=e,this.exact=t,this.context=i}static fromRange(e,t){const i=e.textContent,s=D.fromRange(t).relativeTo(e),n=s.start.offset,o=s.end.offset,a=32;return new Y(e,i.slice(n,o),{prefix:i.slice(Math.max(0,n-a),n),suffix:i.slice(o,Math.min(i.length,o+a))})}static fromSelector(e,t){const{prefix:i,suffix:s}=t;return new Y(e,t.exact,{prefix:i,suffix:s})}toSelector(){return{type:"TextQuoteSelector",exact:this.exact,prefix:this.context.prefix,suffix:this.context.suffix}}toRange(e={}){return this.toPositionAnchor(e).toRange()}toPositionAnchor(e={}){const t=this.root.textContent,i=Tt(t,this.exact,{...this.context,hint:e.hint});if(!i)throw new Error("Quote not found");return new G(this.root,i.start,i.end)}}function Ct(r){const e=r.tagName.toUpperCase();return e==="IMG"||e==="VIDEO"||e==="AUDIO"||e==="IFRAME"||e==="OBJECT"||e==="EMBED"||e==="CANVAS"}function oe(r,e){try{const t=e.locations,i=e.text;if(i&&i.highlight){let s;t&&t.getCssSelector()&&(s=r.querySelector(t.getCssSelector())),s||(s=r.body);const n=new Y(s,i.highlight,{prefix:i.before,suffix:i.after});try{return n.toRange()}catch{return console.warn("Quote not found:",n),null}}if(t){let s=null;if(!s&&t.getCssSelector()&&(s=r.querySelector(t.getCssSelector())),!s&&t.fragments){for(const n of t.fragments)if(s=r.getElementById(n),s)break}if(s){const n=r.createRange();return s.childNodes.length===0||Ct(s)?(n.selectNode(s),n):(n.setStartBefore(s),n.setEndAfter(s),n)}}}catch(t){console.error(t)}return null}function Pt(r,e){let t=r.getClientRects();t.length||r.commonAncestorContainer.nodeType===Node.ELEMENT_NODE&&(t=r.commonAncestorContainer.getClientRects());const i=1,s=[];for(const c of t)s.push({bottom:c.bottom,height:c.height,left:c.left,right:c.right,top:c.top,width:c.width});const n=Ae(s,i,e),o=Mt(n,i),a=Ie(o),h=2*2;for(let c=a.length-1;c>=0;c--){const d=a[c];if(!(d.width*d.height>h))if(a.length>1)a.splice(c,1);else break}return a}function Ae(r,e,t){for(let i=0;i<r.length;i++)for(let s=i+1;s<r.length;s++){const n=r[i],o=r[s];if(n===o)continue;const a=M(n.top,o.top,e)&&M(n.bottom,o.bottom,e),h=M(n.left,o.left,e)&&M(n.right,o.right,e);if((h&&!t||a&&!h)&&Re(n,o,e)){const u=r.filter(g=>g!==n&&g!==o),f=Nt(n,o);return u.push(f),Ae(u,e,t)}}return r}function Nt(r,e){const t=Math.min(r.left,e.left),i=Math.max(r.right,e.right),s=Math.min(r.top,e.top),n=Math.max(r.bottom,e.bottom);return{bottom:n,height:n-s,left:t,right:i,top:s,width:i-t}}function Mt(r,e){const t=new Set(r);for(const i of r){if(!(i.width>1&&i.height>1)){t.delete(i);continue}for(const n of r)if(i!==n&&t.has(n)&&Ot(n,i,e)){t.delete(i);break}}return Array.from(t)}function Ot(r,e,t){return K(r,e.left,e.top,t)&&K(r,e.right,e.top,t)&&K(r,e.left,e.bottom,t)&&K(r,e.right,e.bottom,t)}function K(r,e,t,i){return(r.left<e||M(r.left,e,i))&&(r.right>e||M(r.right,e,i))&&(r.top<t||M(r.top,t,i))&&(r.bottom>t||M(r.bottom,t,i))}function Ie(r){for(let e=0;e<r.length;e++)for(let t=e+1;t<r.length;t++){const i=r[e],s=r[t];if(i!==s&&Re(i,s,-1)){let n=[],o;const a=Le(i,s);if(a.length===1)n=a,o=i;else{const c=Le(s,i);a.length<c.length?(n=a,o=i):(n=c,o=s)}const h=r.filter(c=>c!==o);return Array.prototype.push.apply(h,n),Ie(h)}}return r}function Le(r,e){const t=At(e,r);if(t.height===0||t.width===0)return[r];const i=[];{const s={bottom:r.bottom,height:0,left:r.left,right:t.left,top:r.top,width:0};s.width=s.right-s.left,s.height=s.bottom-s.top,s.height!==0&&s.width!==0&&i.push(s)}{const s={bottom:t.top,height:0,left:t.left,right:t.right,top:r.top,width:0};s.width=s.right-s.left,s.height=s.bottom-s.top,s.height!==0&&s.width!==0&&i.push(s)}{const s={bottom:r.bottom,height:0,left:t.left,right:t.right,top:t.bottom,width:0};s.width=s.right-s.left,s.height=s.bottom-s.top,s.height!==0&&s.width!==0&&i.push(s)}{const s={bottom:r.bottom,height:0,left:t.right,right:r.right,top:r.top,width:0};s.width=s.right-s.left,s.height=s.bottom-s.top,s.height!==0&&s.width!==0&&i.push(s)}return i}function At(r,e){const t=Math.max(r.left,e.left),i=Math.min(r.right,e.right),s=Math.max(r.top,e.top),n=Math.min(r.bottom,e.bottom);return{bottom:n,height:Math.max(0,n-s),left:t,right:i,top:s,width:Math.max(0,i-t)}}function Re(r,e,t){return(r.left<e.right||t>=0&&M(r.left,e.right,t))&&(e.left<r.right||t>=0&&M(e.left,r.right,t))&&(r.top<e.bottom||t>=0&&M(r.top,e.bottom,t))&&(e.top<r.bottom||t>=0&&M(e.top,r.bottom,t))}function M(r,e,t){return Math.abs(r-e)<=t}function ze(r){const e={},t=r.document.documentElement.style;for(const i in r.document.documentElement.style)Object.hasOwn(t,i)&&!Number.isNaN(Number.parseInt(i))&&(e[t[i]]=t.getPropertyValue(t[i]));return e}function It(r,e){const t=ze(r);Object.keys(t).forEach(i=>{e.hasOwnProperty(i)||ae(r,i)}),Object.entries(e).forEach(([i,s])=>{t[i]!==s&&Z(r,i,s)})}function De(r,e){return r.document.documentElement.style.getPropertyValue(e)}function Z(r,e,t){r.document.documentElement.style.setProperty(e,t)}function ae(r,e){r.document.documentElement.style.removeProperty(e)}const Lt=r=>{if(r.startsWith("rgb")){const e=r.match(/rgb\((\d+),\s(\d+),\s(\d+)(?:,\s(\d+))?\)/);if(e)return{r:parseInt(e[1],10),g:parseInt(e[2],10),b:parseInt(e[3],10),a:e[4]?parseInt(e[4],10)/255:1}}else if(r.startsWith("#")){const e=r.slice(1);if(e.length===3||e.length===4)return{r:parseInt(e[0]+e[0],16)/255,g:parseInt(e[1]+e[1],16)/255,b:parseInt(e[2]+e[2],16)/255,a:e.length===4?parseInt(e[3]+e[3],16)/255:1};if(e.length===6||e.length===8)return{r:parseInt(e[0]+e[1],16)/255,g:parseInt(e[2]+e[3],16)/255,b:parseInt(e[4]+e[5],16)/255,a:e.length===8?parseInt(e[6]+e[7],16)/255:1}}return{r:0,g:0,b:0,a:1}},Rt=r=>.2126*r.r*r.a+.7152*r.g*r.a+.0722*r.b*r.a,zt=r=>{const e=Lt(r);return Rt(e)<128};var We=(r=>(r.Wrap="wrap",r.Viewport="viewport",r.Bounds="bounds",r.Page="page",r))(We||{}),Fe=(r=>(r.Boxes="boxes",r.Bounds="bounds",r))(Fe||{});const Dt="Highlight"in window,Be=["IMG","IMAGE","AUDIO","VIDEO","SVG"];class Wt{constructor(e,t,i,s){this.wnd=e,this.comms=t,this.id=i,this.name=s,this.items=[],this.lastItemId=0,this.container=void 0,this.activateable=!1,this.experimentalHighlights=!1,this.currentRender=0,Dt&&(this.experimentalHighlights=!0,this.notTextFlag=new Map)}get activeable(){return this.activateable}set activeable(e){this.activateable=e}add(e){var o,a,h,c;const t=`${this.id}-${this.lastItemId++}`,i=oe(this.wnd.document,e.locator);if(!i){this.comms.log("Can't locate DOM range for decoration",e);return}const s=i.commonAncestorContainer;s.nodeType!==Node.TEXT_NODE&&this.experimentalHighlights&&(Be.includes(s.nodeName.toUpperCase())&&((o=this.notTextFlag)==null||o.set(t,!0)),s.querySelector(Be.join(", ").toLowerCase())&&((a=this.notTextFlag)==null||a.set(t,!0)),(((h=s.textContent)==null?void 0:h.trim())||"").length===0&&((c=this.notTextFlag)==null||c.set(t,!0)));const n={decoration:e,id:t,range:i};this.items.push(n),this.layout(n),this.renderLayout([n])}remove(e){var s,n;const t=this.items.findIndex(o=>o.decoration.id===e);if(t<0)return;const i=this.items[t];if(this.items.splice(t,1),i.clickableElements=void 0,i.container&&(i.container.remove(),i.container=void 0),this.experimentalHighlights&&!((s=this.notTextFlag)!=null&&s.has(i.id))){const o=this.wnd.CSS.highlights.get(this.id);o==null||o.delete(i.range)}(n=this.notTextFlag)==null||n.delete(i.id)}update(e){this.remove(e.id),this.add(e)}clear(){var e;this.clearContainer(),this.items.length=0,(e=this.notTextFlag)==null||e.clear()}requestLayout(){this.wnd.cancelAnimationFrame(this.currentRender),this.clearContainer(),this.items.forEach(e=>this.layout(e)),this.renderLayout(this.items)}experimentalLayout(e){var s,n;const[t,i]=this.requireContainer(!0);i.add(e.range),t.innerHTML=`
|
|
2
2
|
::highlight(${this.id}) {
|
|
3
3
|
color: black;
|
|
4
|
-
background-color: ${((
|
|
5
|
-
}`}layout(e){var
|
|
4
|
+
background-color: ${((n=(s=e.decoration)==null?void 0:s.style)==null?void 0:n.tint)??"yellow"};
|
|
5
|
+
}`}layout(e){var g,m,v,T,I;if(this.experimentalHighlights&&!((g=this.notTextFlag)!=null&&g.has(e.id)))return this.experimentalLayout(e);const t=this.wnd.document.createElement("div");t.setAttribute("id",e.id),t.style.setProperty("pointer-events","none");const i=this.wnd.innerWidth,s=parseInt(getComputedStyle(this.wnd.document.documentElement).getPropertyValue("column-count")),n=i/(s||1),o=this.wnd.document.scrollingElement,a=o.scrollLeft,h=o.scrollTop,c=(y,S,L)=>{var ot,at,lt,ht,ct,dt;if(y.style.position="absolute",((at=(ot=e.decoration)==null?void 0:ot.style)==null?void 0:at.width)==="viewport"){y.style.width=`${i}px`,y.style.height=`${S.height}px`;let ce=Math.floor(S.left/i)*i;y.style.left=`${ce+a}px`,y.style.top=`${S.top+h}px`}else if(((ht=(lt=e.decoration)==null?void 0:lt.style)==null?void 0:ht.width)==="bounds")y.style.width=`${L.width}px`,y.style.height=`${S.height}px`,y.style.left=`${L.left+a}px`,y.style.top=`${S.top+h}px`;else if(((dt=(ct=e.decoration)==null?void 0:ct.style)==null?void 0:dt.width)==="page"){y.style.width=`${n}px`,y.style.height=`${S.height}px`;let ce=Math.floor(S.left/n)*n;y.style.left=`${ce+a}px`,y.style.top=`${S.top+h}px`}else y.style.width=`${S.width}px`,y.style.height=`${S.height}px`,y.style.left=`${S.left+a}px`,y.style.top=`${S.top+h}px`},d=e.range.getBoundingClientRect();let p=this.wnd.document.createElement("template");const u=De(this.wnd,"--USER__appearance")==="readium-night-on"||zt(De(this.wnd,"--USER__backgroundColor"));p.innerHTML=`
|
|
6
6
|
<div
|
|
7
7
|
class="r2-highlight-0"
|
|
8
|
-
style="${[`background-color: ${((
|
|
8
|
+
style="${[`background-color: ${((v=(m=e.decoration)==null?void 0:m.style)==null?void 0:v.tint)??"yellow"} !important`,`mix-blend-mode: ${u?"exclusion":"multiply"} !important`,"opacity: 1 !important","box-sizing: border-box !important"].join("; ")}"
|
|
9
9
|
>
|
|
10
10
|
</div>
|
|
11
|
-
`.trim();const f=p.content.firstElementChild;if(((
|
|
11
|
+
`.trim();const f=p.content.firstElementChild;if(((I=(T=e.decoration)==null?void 0:T.style)==null?void 0:I.layout)==="bounds"){const y=f.cloneNode(!0);y.style.setProperty("pointer-events","none"),c(y,d,d),t.append(y)}else{let y=Pt(e.range,!0);y=y.sort((S,L)=>S.top<L.top?-1:S.top>L.top?1:0);for(let S of y){const L=f.cloneNode(!0);L.style.setProperty("pointer-events","none"),c(L,S,d),t.append(L)}}e.container=t,e.clickableElements=Array.from(t.querySelectorAll("[data-activable='1']")),e.clickableElements.length||(e.clickableElements=Array.from(t.children))}renderLayout(e){this.wnd.cancelAnimationFrame(this.currentRender),this.currentRender=this.wnd.requestAnimationFrame(()=>{if(e=e.filter(i=>{var s;return!this.experimentalHighlights||!!((s=this.notTextFlag)!=null&&s.has(i.id))}),!e||e.length===0)return;this.requireContainer().append(...e.map(i=>i.container).filter(i=>!!i))})}requireContainer(e=!1){if(e){let t;this.wnd.document.getElementById(`${this.id}-style`)?t=this.wnd.document.getElementById(`${this.id}-style`):(t=this.wnd.document.createElement("style"),t.dataset.readium="true",t.id=`${this.id}-style`,this.wnd.document.head.appendChild(t));let i;return this.wnd.CSS.highlights.has(this.id)?i=this.wnd.CSS.highlights.get(this.id):(i=new this.wnd.Highlight,this.wnd.CSS.highlights.set(this.id,i)),[t,i]}return this.container||(this.container=this.wnd.document.createElement("div"),this.container.setAttribute("id",this.id),this.container.dataset.group=this.name,this.container.dataset.readium="true",this.container.style.setProperty("pointer-events","none"),this.container.style.display="contents",this.wnd.document.body.append(this.container)),this.container}clearContainer(){this.experimentalHighlights&&this.wnd.CSS.highlights.delete(this.id),this.container&&(this.container.remove(),this.container=void 0)}}const Ue=class de extends V{constructor(){super(...arguments),this.resizeFrame=0,this.lastGroupId=0,this.groups=new Map,this.handleResizer=this.handleResize.bind(this)}cleanup(){this.groups.forEach(e=>e.clear()),this.groups.clear()}handleResize(){this.wnd.clearTimeout(this.resizeFrame),this.resizeFrame=this.wnd.setTimeout(()=>{this.groups.forEach(e=>{e.experimentalHighlights||e.requestLayout()})},50)}mount(e,t){return this.wnd=e,t.register("decorate",de.moduleName,(i,s)=>{const n=i;n.decoration&&n.decoration.locator&&(n.decoration.locator=R.deserialize(n.decoration.locator)),this.groups.has(n.group)||this.groups.set(n.group,new Wt(e,t,`readium-decoration-${this.lastGroupId++}`,n.group));const o=this.groups.get(n.group);switch(n.action){case"add":o==null||o.add(n.decoration);break;case"remove":o==null||o.remove(n.decoration.id);break;case"clear":o==null||o.clear();break;case"update":o==null||o.update(n.decoration);break}s(!0)}),this.resizeObserver=new ResizeObserver(()=>e.requestAnimationFrame(()=>this.handleResize())),this.resizeObserver.observe(e.document.body),e.addEventListener("orientationchange",this.handleResizer),e.addEventListener("resize",this.handleResizer),t.log("Decorator Mounted"),!0}unmount(e,t){return e.removeEventListener("orientationchange",this.handleResizer),e.removeEventListener("resize",this.handleResizer),t.unregisterAll(de.moduleName),this.resizeObserver.disconnect(),this.cleanup(),t.log("Decorator Unmounted"),!0}};Ue.moduleName="decorator";let ke=Ue;const He="readium-snapper-style",$e=class ue extends V{constructor(){super(...arguments),this.protected=!1}buildStyles(){return`
|
|
12
12
|
html, body {
|
|
13
13
|
touch-action: manipulation;
|
|
14
14
|
user-select: ${this.protected?"none":"auto"};
|
|
15
|
-
}`}mount(e,t){const
|
|
15
|
+
}`}mount(e,t){const i=e.document.createElement("style");return i.dataset.readium="true",i.id=He,i.textContent=this.buildStyles(),e.document.head.appendChild(i),t.register("protect",ue.moduleName,(s,n)=>{this.protected=!0,i.textContent=this.buildStyles(),n(!0)}),t.register("unprotect",ue.moduleName,(s,n)=>{this.protected=!1,i.textContent=this.buildStyles(),n(!0)}),t.log("Snapper Mounted"),!0}unmount(e,t){var i;return(i=e.document.getElementById(He))==null||i.remove(),t.log("Snapper Unmounted"),!0}};$e.moduleName="snapper";let je=$e;function F(r){return r.document.body.dir.toLowerCase()==="rtl"}function Ve(r){return parseInt(r.getComputedStyle(r.document.documentElement).getPropertyValue("column-count"))}function qe(r){const e=getComputedStyle(r),t=parseFloat(e.paddingTop||"0"),i=parseFloat(e.paddingBottom||"0");return r.clientHeight-t-i}function _e(r){const e=r.document.querySelectorAll("div[id^='readium-virtual-page']");for(const a of e)a.remove();const t=Ve(r),i=r.document.scrollingElement.scrollWidth,s=Math.ceil(i/r.innerWidth)*t,n=Math.round(i/r.innerWidth*t),o=t===1?0:s-n;if(o>0)for(let a=0;a<o;a++){const h=r.document.createElement("div");h.setAttribute("id",`readium-virtual-page-${a}`),h.dataset.readium="true",CSS.supports("break-before","column")?h.style.breakBefore="column":(CSS.supports("break-inside","avoid-column")&&(h.style.breakInside="avoid-column"),h.style.height=qe(r.document.documentElement)+"px"),h.innerHTML="​",r.document.body.appendChild(h)}}function Ft(r){return r<.5?2*r*r:-1+(4-2*r)*r}function w(r){const e=r.getSelection();e&&e.removeAllRanges()}const Bt=["a","audio","button","canvas","details","input","label","option","select","submit","textarea","video"];function Xe(r){var e;return Bt.indexOf(r.nodeName.toLowerCase())!==-1||r.hasAttribute("contenteditable")&&((e=r.getAttribute("contenteditable"))==null?void 0:e.toLowerCase())!=="false"?r:r.parentElement?Xe(r.parentElement):null}function Ge(r,e){const t=Ye(r,r.document.body,e),i=r._readium_cssSelectorGenerator.getCssSelector(t,{selectors:["tag","id","class","nthchild","nthoftype","attribute"]});return new R({href:"#",type:"application/xhtml+xml",locations:new x({otherLocations:new Map([["cssSelector",i]])}),text:new k({highlight:t.textContent||void 0})})}function Ye(r,e,t){for(var i=0;i<e.children.length;i++){const s=e.children[i];if(!Ht(s)&&Ut(r,s,t))return kt(r,s)?s:Ye(r,s,t)}return e}function Ut(r,e,t){if(e===document.body||e===document.documentElement)return!0;if(!document||!document.documentElement||!document.body)return!1;const i=e.getBoundingClientRect();return t?i.bottom>0&&i.top<r.innerHeight:i.right>0&&i.left<r.innerWidth}function kt(r,e){const t=e.getBoundingClientRect();return t.top>=0&&t.left>=0&&t.bottom<=r.innerHeight&&t.right<=r.innerWidth}function Ht(r){const e=getComputedStyle(r);if(e){const t=e.getPropertyValue("display");if(t!="block"&&t!="list-item"||e.getPropertyValue("opacity")==="0")return!0}return!1}const Ke="readium-column-snapper-style",$t=200,Ze=class P extends je{constructor(){super(...arguments),this.shakeTimeout=0,this.snappingCancelled=!1,this.alreadyScrollLeft=0,this.overscroll=0,this.cachedScrollWidth=0,this.touchState=0,this.startingX=void 0,this.endingX=void 0,this.onTouchStarter=this.onTouchStart.bind(this),this.onTouchEnder=this.onTouchEnd.bind(this),this.onWidthChanger=this.onWidthChange.bind(this),this.onTouchMover=this.onTouchMove.bind(this)}doc(){return this.wnd.document.scrollingElement}scrollOffset(){return this.doc().scrollLeft>0?this.doc().scrollLeft:this.alreadyScrollLeft}snapOffset(e){const t=e+(F(this.wnd)?-1:1);return t-t%this.wnd.innerWidth}reportProgress(){this.comms.send("progress",{progress:this.wnd.scrollX/this.cachedScrollWidth,reference:this.wnd.innerWidth/this.doc().scrollWidth})}shake(){if(this.overscroll!==0||this.shakeTimeout!==0)return;const e=this.doc();e.classList.add(F(this.wnd)?"readium-bounce-l":"readium-bounce-r");const t=this.scrollOffset();this.shakeTimeout=this.wnd.setTimeout(()=>{e.classList.remove("readium-bounce-l"),e.classList.remove("readium-bounce-r"),this.shakeTimeout=0,this.doc().scrollLeft=t},150)}takeOverSnap(){var t;this.snappingCancelled=!0,this.clearTouches();const e=this.doc();this.overscroll=((t=e.style.transform)==null?void 0:t.length)>12?parseFloat(e.style.transform.slice(12).split("px")[0]):0}snapCurrentOffset(e=!1,t=!1){const i=this.wnd.scrollX>0?this.wnd.scrollX:this.alreadyScrollLeft,s=this.doc(),n=this.dragOffset(),o=Ve(this.wnd),a=Math.min(Math.max(0,i),this.cachedScrollWidth),h=F(this.wnd)?-1:1,c=h*(this.wnd.innerWidth/3)*(h*n>0?2:1),d=this.snapOffset(a+c);if(e&&d!==this.scrollOffset()){this.snappingCancelled=!1;const p=(m,v,T,I)=>T>I?v:m+(v-m)*Ft(T/I),u=$t*o;let f;const g=m=>{if(this.snappingCancelled)return;f||(f=m);const v=m-f,T=p(this.overscroll,0,v,u),I=p(i,d,v,u);s.scrollLeft=I,this.overscroll!==0&&(s.style.transform=`translate3d(${-T}px, 0px, 0px)`),v<u?this.wnd.requestAnimationFrame(g):(this.clearTouches(),s.style.removeProperty("transform"),s.scrollLeft=d,t||this.reportProgress())};this.wnd.requestAnimationFrame(g)}else s.style.removeProperty("transform"),this.wnd.requestAnimationFrame(()=>{s.scrollLeft=d,this.clearTouches(),t||this.reportProgress()})}dragOffset(){return(this.startingX??0)-(this.endingX??0)}clearTouches(){this.startingX=void 0,this.endingX=void 0,this.overscroll=0}onTouchStart(e){switch(e.stopPropagation(),this.takeOverSnap(),e.touches.length){case 1:break;case 2:this.onTouchEnd(e);return;default:{this.onTouchEnd(e),this.comms.send("tap_more",e.touches.length);return}}this.startingX=e.touches[0].clientX,this.alreadyScrollLeft=this.doc().scrollLeft,this.touchState=1}onTouchEnd(e){if(this.touchState===2){const t=this.dragOffset(),i=this.scrollOffset();this.cachedScrollWidth<=this.wnd.innerWidth?(this.reportProgress(),t>5&&this.comms.send("no_more",void 0),t<-5&&this.comms.send("no_less",void 0)):i<5&&t<5?(this.alreadyScrollLeft=0,this.comms.send("no_less",void 0)):this.cachedScrollWidth-i-this.wnd.innerWidth<5&&t>5&&(this.alreadyScrollLeft=this.cachedScrollWidth,this.comms.send("no_more",void 0)),this.snapCurrentOffset(!0),this.comms.send("swipe",t)}this.touchState=0}onWidthChange(){this.cachedScrollWidth=this.doc().scrollWidth,this.comms.ready&&this.snapCurrentOffset()}onTouchMove(e){if(this.touchState===0)return;this.touchState===1&&(this.touchState=2,w(this.wnd)),this.endingX=e.touches[0].clientX;const t=this.dragOffset(),i=this.alreadyScrollLeft+t;i<0?(this.overscroll=i,this.doc().style.transform=`translate3d(${-this.overscroll}px, 0px, 0px)`):i+this.wnd.innerWidth>this.cachedScrollWidth?(this.overscroll=i,this.doc().style.transform=`translate3d(${-i}px, 0px, 0px)`):(this.overscroll=0,this.doc().style.removeProperty("transform"),this.doc().scrollLeft=this.alreadyScrollLeft+t)}mount(e,t){if(this.wnd=e,this.comms=t,!super.mount(e,t))return!1;e.navigator.epubReadingSystem.layoutStyle="paginated";const i=e.document.createElement("style");i.dataset.readium="true",i.id=Ke,i.textContent=`
|
|
16
16
|
@keyframes readium-bounce-l-animation {
|
|
17
17
|
0%, 100% {transform: translate3d(0, 0, 0);}
|
|
18
18
|
50% {transform: translate3d(-50px, 0, 0);}
|
|
@@ -46,7 +46,7 @@
|
|
|
46
46
|
body::-webkit-scrollbar {
|
|
47
47
|
display: none; /* for Chrome, Safari, and Opera */
|
|
48
48
|
}
|
|
49
|
-
`,e.document.head.appendChild(
|
|
49
|
+
`,e.document.head.appendChild(i),this.resizeObserver=new ResizeObserver(()=>{e.requestAnimationFrame(()=>{e&&_e(e)}),this.onWidthChange()}),this.resizeObserver.observe(e.document.body),this.mutationObserver=new MutationObserver(n=>{for(const o of n)if(o.target===this.wnd.document.documentElement){const a=o.oldValue,h=o.target.getAttribute("style"),c=/transform\s*:\s*([^;]+)/,d=a==null?void 0:a.match(c),p=h==null?void 0:h.match(c);(!d&&!p||d&&!p||d&&p&&d[1]!==p[1])&&(e.requestAnimationFrame(()=>{e&&_e(e)}),this.onWidthChange())}else e.requestAnimationFrame(()=>this.cachedScrollWidth=this.doc().scrollWidth)}),e.frameElement&&this.mutationObserver.observe(e.frameElement,{attributes:!0,attributeFilter:["style"]}),this.mutationObserver.observe(e.document,{attributes:!0,attributeFilter:["style"]}),this.mutationObserver.observe(e.document.documentElement,{attributes:!0,attributeFilter:["style"]});const s=n=>{const o=this.doc().scrollLeft;return this.doc().scrollLeft=this.snapOffset(n),o!==this.doc().scrollLeft};return e.addEventListener("orientationchange",this.onWidthChanger),e.addEventListener("resize",this.onWidthChanger),e.requestAnimationFrame(()=>this.cachedScrollWidth=this.doc().scrollWidth),t.register("go_progression",P.moduleName,(n,o)=>{const a=n;if(a<0||a>1){t.send("error",{message:"go_progression must be given a position from 0.0 to 1.0"}),o(!1);return}this.wnd.requestAnimationFrame(()=>{this.cachedScrollWidth=this.doc().scrollWidth;const h=this.cachedScrollWidth,c=F(e)?-1:1,d=h*a*c;this.doc().scrollLeft=this.snapOffset(d),this.reportProgress(),w(this.wnd),o(!0)})}),t.register("go_id",P.moduleName,(n,o)=>{const a=e.document.getElementById(n);if(!a){o(!1);return}this.wnd.requestAnimationFrame(()=>{this.doc().scrollLeft=this.snapOffset(a.getBoundingClientRect().left+e.scrollX),this.reportProgress(),w(this.wnd),o(!0)})}),t.register("go_text",P.moduleName,(n,o)=>{let a;Array.isArray(n)&&(n.length>1&&(a=n[1]),n=n[0]);const h=k.deserialize(n),c=oe(this.wnd.document,new R({href:e.location.href,type:"text/html",text:h,locations:a?new x({otherLocations:new Map([["cssSelector",a]])}):void 0}));if(!c){o(!1);return}this.wnd.requestAnimationFrame(()=>{this.doc().scrollLeft=this.snapOffset(c.getBoundingClientRect().left+e.scrollX),this.reportProgress(),w(this.wnd),o(!0)})}),t.register("go_end",P.moduleName,(n,o)=>{const a=F(e)?-1:1;this.wnd.requestAnimationFrame(()=>{this.cachedScrollWidth=this.doc().scrollWidth;const h=this.cachedScrollWidth*a;if(this.doc().scrollLeft===h)return o(!1);this.doc().scrollLeft=this.snapOffset(h),this.reportProgress(),w(this.wnd),o(!0)})}),t.register("go_start",P.moduleName,(n,o)=>{this.wnd.requestAnimationFrame(()=>{if(this.doc().scrollLeft===0)return o(!1);this.doc().scrollLeft=0,this.reportProgress(),w(this.wnd),o(!0)})}),t.register("go_prev",P.moduleName,(n,o)=>{this.wnd.requestAnimationFrame(()=>{this.cachedScrollWidth=this.doc().scrollWidth;const a=e.scrollX-e.innerWidth,h=F(e)?-(this.cachedScrollWidth-e.innerWidth):0,c=s(Math.max(a,h));c&&(this.reportProgress(),w(this.wnd)),o(c)})}),t.register("go_next",P.moduleName,(n,o)=>{this.wnd.requestAnimationFrame(()=>{this.cachedScrollWidth=this.doc().scrollWidth;const a=e.scrollX+e.innerWidth,h=F(e)?0:this.cachedScrollWidth-e.innerWidth,c=s(Math.min(a,h));c&&(this.reportProgress(),w(this.wnd)),o(c)})}),t.register("unfocus",P.moduleName,(n,o)=>{this.snappingCancelled=!0,w(this.wnd),o(!0)}),t.register("shake",P.moduleName,(n,o)=>{this.shake(),o(!0)}),t.register("focus",P.moduleName,(n,o)=>{this.wnd.requestAnimationFrame(()=>{this.cachedScrollWidth=this.doc().scrollWidth,this.snapCurrentOffset(!1,!0),this.reportProgress(),o(!0)})}),t.register("first_visible_locator",P.moduleName,(n,o)=>{const a=Ge(e,!1);this.comms.send("first_visible_locator",a.serialize()),o(!0)}),e.addEventListener("touchstart",this.onTouchStarter,{passive:!0}),e.addEventListener("touchend",this.onTouchEnder,{passive:!0}),e.addEventListener("touchmove",this.onTouchMover,{passive:!0}),e.document.addEventListener("touchstart",()=>{}),t.log("ColumnSnapper Mounted"),!0}unmount(e,t){var i;return this.snappingCancelled=!0,t.unregisterAll(P.moduleName),this.resizeObserver.disconnect(),this.mutationObserver.disconnect(),e.removeEventListener("touchstart",this.onTouchStarter),e.removeEventListener("touchend",this.onTouchEnder),e.removeEventListener("touchmove",this.onTouchMover),e.removeEventListener("orientationchange",this.onWidthChanger),e.removeEventListener("resize",this.onWidthChanger),(i=e.document.getElementById(Ke))==null||i.remove(),t.log("ColumnSnapper Unmounted"),super.unmount(e,t)}};Ze.moduleName="column_snapper";let jt=Ze;const Je="readium-scroll-snapper-style",Qe=class O extends je{constructor(){super(...arguments),this.isScrolling=!1,this.handleScroll=()=>{this.isScrolling||(this.isScrolling=!0,this.wnd.requestAnimationFrame(()=>{const e=this.doc().scrollTop/this.doc().offsetHeight;this.reportProgress({progress:e,reference:this.wnd.innerHeight/this.doc().scrollHeight}),this.isScrolling=!1}))}}doc(){return this.wnd.document.scrollingElement}reportProgress(e){this.comms.send("progress",e)}mount(e,t){this.wnd=e,this.comms=t,e.navigator.epubReadingSystem.layoutStyle="scrolling";const i=e.document.createElement("style");return i.dataset.readium="true",i.id=Je,i.textContent=`
|
|
50
50
|
* {
|
|
51
51
|
scrollbar-width: none; /* for Firefox */
|
|
52
52
|
}
|
|
@@ -54,7 +54,7 @@
|
|
|
54
54
|
body::-webkit-scrollbar {
|
|
55
55
|
display: none; /* for Chrome, Safari, and Opera */
|
|
56
56
|
}
|
|
57
|
-
`,e.document.head.appendChild(
|
|
57
|
+
`,e.document.head.appendChild(i),this.resizeObserver=new ResizeObserver(()=>{this.comms.ready&&this.handleScroll()}),this.resizeObserver.observe(e.document.body),e.addEventListener("scroll",this.handleScroll,{passive:!0}),t.register("go_progression",O.moduleName,(s,n)=>{const o=s;if(o<0||o>1){t.send("error",{message:"go_progression must be given a position from 0.0 to 1.0"}),n(!1);return}this.wnd.requestAnimationFrame(()=>{this.doc().scrollTop=this.doc().offsetHeight*o,this.reportProgress({progress:o,reference:this.wnd.innerHeight/this.doc().scrollHeight}),w(this.wnd),n(!0)})}),t.register("go_id",O.moduleName,(s,n)=>{const o=e.document.getElementById(s);if(!o){n(!1);return}this.wnd.requestAnimationFrame(()=>{this.doc().scrollTop=o.getBoundingClientRect().top+e.scrollY-e.innerHeight/2;const a=this.doc().scrollTop/this.doc().offsetHeight;this.reportProgress({progress:a,reference:this.wnd.innerHeight/this.doc().scrollHeight}),w(this.wnd),n(!0)})}),t.register("go_text",O.moduleName,(s,n)=>{let o;Array.isArray(s)&&(s.length>1&&(o=s[1]),s=s[0]);const a=k.deserialize(s),h=oe(this.wnd.document,new R({href:e.location.href,type:"text/html",text:a,locations:o?new x({otherLocations:new Map([["cssSelector",o]])}):void 0}));if(!h){n(!1);return}this.wnd.requestAnimationFrame(()=>{this.doc().scrollTop=h.getBoundingClientRect().top+e.scrollY-e.innerHeight/2;const c=this.doc().scrollTop/this.doc().offsetHeight;this.reportProgress({progress:c,reference:this.wnd.innerHeight/this.doc().scrollHeight}),w(this.wnd),n(!0)})}),t.register("go_start",O.moduleName,(s,n)=>{if(this.doc().scrollTop===0)return n(!1);this.doc().scrollTop=0,this.reportProgress({progress:0,reference:this.wnd.innerHeight/this.doc().scrollHeight}),n(!0)}),t.register("go_end",O.moduleName,(s,n)=>{if(this.doc().scrollTop===0)return n(!1);this.doc().scrollTop=0,this.reportProgress({progress:0,reference:this.wnd.innerHeight/this.doc().scrollHeight}),n(!0)}),t.register("unfocus",O.moduleName,(s,n)=>{w(this.wnd),n(!0)}),t.register(["go_next","go_prev"],O.moduleName,(s,n)=>n(!1)),t.register("focus",O.moduleName,(s,n)=>{const o=this.doc().scrollTop/this.doc().offsetHeight;this.reportProgress({progress:o,reference:this.wnd.innerHeight/this.doc().scrollHeight}),n(!0)}),t.register("first_visible_locator",O.moduleName,(s,n)=>{const o=Ge(e,!0);this.comms.send("first_visible_locator",o.serialize()),n(!0)}),t.log("ScrollSnapper Mounted"),!0}unmount(e,t){var i;return t.unregisterAll(O.moduleName),this.resizeObserver.disconnect(),this.handleScroll&&e.removeEventListener("scroll",this.handleScroll),(i=e.document.getElementById(Je))==null||i.remove(),t.log("ScrollSnapper Unmounted"),!0}};Qe.moduleName="scroll_snapper";let Vt=Qe;class le extends V{constructor(){super(...arguments),this.pointerMoved=!1,this.onPointerUp=this.onPointUp.bind(this),this.onPointerMove=this.onPointMove.bind(this),this.onPointerDown=this.onPointDown.bind(this),this.onContextMenu=this.onContext.bind(this),this.onClicker=this.onClick.bind(this)}onPointUp(e){var s,n,o,a,h;const t=this.wnd.getSelection();if(t&&((s=t.toString())==null?void 0:s.length)>0){const c=(n=t.getRangeAt(0))==null?void 0:n.getClientRects();if(!c||c.length===0)return;const d=c[0],p={text:t.toString(),x:d.x,y:d.y,width:d.width,height:d.height,targetFrameSrc:(a=(o=this.wnd)==null?void 0:o.location)==null?void 0:a.href};this.comms.send("text_selected",p)}if(this.pointerMoved){this.pointerMoved=!1;return}if(!(t!=null&&t.isCollapsed)||!e.isPrimary)return;const i=this.wnd.devicePixelRatio;e.preventDefault(),this.comms.send(e.pointerType==="touch"?"tap":"click",{defaultPrevented:e.defaultPrevented,x:e.clientX*i,y:e.clientY*i,targetFrameSrc:this.wnd.location.href,targetElement:e.target.outerHTML,interactiveElement:(h=Xe(e.target))==null?void 0:h.outerHTML,cssSelector:this.wnd._readium_cssSelectorGenerator.getCssSelector(e.target)}),this.pointerMoved=!1}onPointMove(e){if(e.movementY!==void 0&&e.movementX!==void 0){(Math.abs(e.movementX)>1||Math.abs(e.movementY)>1)&&(this.pointerMoved=!0);return}this.pointerMoved=!0}onPointDown(){this.pointerMoved=!1}onContext(e){this.onPointUp(e),this.pointerMoved=!1}onClick(e){if(e.preventDefault(),!e.isTrusted){const t=new PointerEvent("pointerup",{isPrimary:!0,pointerType:"mouse",clientX:e.clientX,clientY:e.clientY});Object.defineProperty(t,"target",{writable:!1,value:e.target}),Object.defineProperty(t,"defaultPrevented",{writable:!1,value:e.defaultPrevented}),this.onPointUp(t)}}mount(e,t){return this.wnd=e,this.comms=t,e.document.addEventListener("pointerdown",this.onPointerDown),e.document.addEventListener("pointerup",this.onPointerUp),e.document.addEventListener("contextmenu",this.onContextMenu),e.document.addEventListener("pointermove",this.onPointerMove),e.document.addEventListener("click",this.onClicker),t.log("Peripherals Mounted"),!0}unmount(e,t){return e.document.removeEventListener("pointerdown",this.onPointerDown),e.document.removeEventListener("pointerup",this.onPointerUp),e.document.removeEventListener("contextmenu",this.onContextMenu),e.document.removeEventListener("pointermove",this.onPointerMove),e.document.removeEventListener("click",this.onClicker),t.log("Peripherals Unmounted"),!0}}le.moduleName="peripherals";const et=class pe extends V{constructor(){super(...arguments),this.mediaPlayingCount=0,this.allAnimations=new Set}wndOnErr(e){var t;(t=this.comms)==null||t.send("error",{message:e.message,filename:e.filename,lineno:e.lineno,colno:e.colno})}unblock(e){var t;for(e._readium_blockEvents=!1;((t=e._readium_blockedEvents)==null?void 0:t.length)>0;){const i=e._readium_blockedEvents.shift();switch(i[0]){case 0:Reflect.apply(i[1],i[2],i[3]);break;case 1:const s=i[1],n=i[2];e.removeEventListener(s.type,e._readium_eventBlocker,!0);const o=new Event(s.type,{bubbles:s.bubbles,cancelable:s.cancelable});n?n.dispatchEvent(o):e.dispatchEvent(o);break}}}onMediaPlayEvent(){var e;this.mediaPlayingCount++,(e=this.comms)==null||e.send("media_play",this.mediaPlayingCount)}onMediaPauseEvent(){var e;this.mediaPlayingCount>0&&this.mediaPlayingCount--,(e=this.comms)==null||e.send("media_pause",this.mediaPlayingCount)}pauseAllMedia(e){const t=e.document.querySelectorAll("audio,video");for(let i=0;i<t.length;i++)t[i].pause()}mount(e,t){this.comms=t,e.addEventListener("error",this.wndOnErr,!1),Reflect.defineProperty(e.navigator,"epubReadingSystem",{value:{name:"readium-ts-toolkit",version:"2.0.0-beta.1",hasFeature:(s,n="")=>{switch(s){case"dom-manipulation":return!0;case"layout-changes":return!0;case"touch-events":return!0;case"mouse-events":return!0;case"keyboard-events":return!0;case"spine-scripting":return!0;case"embedded-web-content":return!0;default:return!1}}},writable:!1}),"getAnimations"in e.document&&e.document.getAnimations().forEach(s=>{s.cancel(),this.allAnimations.add(s)}),t.register("activate",pe.moduleName,(s,n)=>{this.allAnimations.forEach(o=>{o.cancel(),o.play()}),n(!0)}),t.register("unfocus",pe.moduleName,(s,n)=>{this.pauseAllMedia(e),this.allAnimations.forEach(o=>o.pause()),n(!0)});const i=e.document.querySelectorAll("audio,video");for(let s=0;s<i.length;s++){const n=i[s];n.addEventListener("play",this.onMediaPlayEvent,{passive:!0}),n.addEventListener("pause",this.onMediaPauseEvent,{passive:!0})}return t.log("Setup Mounted"),!0}unmount(e,t){return e.removeEventListener("error",this.wndOnErr),e.removeEventListener("play",this.onMediaPlayEvent),e.removeEventListener("pause",this.onMediaPauseEvent),this.allAnimations.forEach(i=>i.cancel()),this.allAnimations.clear(),t.log("Setup Unmounted"),!0}};et.moduleName="setup";let tt=et;const it="readium-viewport",rt=class B extends tt{onViewportWidthChanged(e){const t=e.target;Z(t,"--RS__viewportWidth",`${t.innerWidth}px`)}mount(e,t){if(!super.mount(e,t))return!1;const i=e.document.createElement("meta");return i.dataset.readium="true",i.setAttribute("name","viewport"),i.setAttribute("id",it),i.setAttribute("content","width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no, shrink-to-fit=no"),e.document.head.appendChild(i),e.addEventListener("orientationchange",this.onViewportWidthChanged),e.addEventListener("resize",this.onViewportWidthChanged),this.onViewportWidthChanged({target:e}),t.register("get_properties",B.moduleName,(s,n)=>{ze(e),n(!0)}),t.register("update_properties",B.moduleName,(s,n)=>{s["--RS__viewportWidth"]=`${e.innerWidth}px`,It(e,s),n(!0)}),t.register("set_property",B.moduleName,(s,n)=>{const o=s;Z(e,o[0],o[1]),n(!0)}),t.register("remove_property",B.moduleName,(s,n)=>{ae(e,s),n(!0)}),t.register("activate",B.moduleName,(s,n)=>{this.unblock(e),n(!0)}),t.log("ReflowableSetup Mounted"),!0}unmount(e,t){var i;return t.unregisterAll(B.moduleName),(i=e.document.head.querySelector(`#${it}`))==null||i.remove(),e.removeEventListener("orientationchange",this.onViewportWidthChanged),t.log("ReflowableSetup Unmounted"),super.unmount(e,t)}};rt.moduleName="reflowable_setup";let qt=rt;const st="readium-fixed-style",nt=class W extends tt{mount(e,t){if(!super.mount(e,t))return!1;e.navigator.epubReadingSystem.layoutStyle="paginated";const i=e.document.createElement("style");return i.id=st,i.dataset.readium="true",i.textContent=`
|
|
58
58
|
html, body {
|
|
59
59
|
text-size-adjust: none;
|
|
60
60
|
-ms-text-size-adjust: none;
|
|
@@ -66,4 +66,4 @@
|
|
|
66
66
|
min-height: 100%;
|
|
67
67
|
|
|
68
68
|
/*cursor: var() TODO*/
|
|
69
|
-
}`,e.document.head.appendChild(
|
|
69
|
+
}`,e.document.head.appendChild(i),t.register("set_property",W.moduleName,(s,n)=>{const o=s;Z(e,o[0],o[1]),n(!0)}),t.register("remove_property",W.moduleName,(s,n)=>{ae(e,s),n(!0)}),t.register("first_visible_locator",W.moduleName,(s,n)=>n(!1)),t.register("unfocus",W.moduleName,(s,n)=>{w(e),n(!0)}),t.register(["focus","go_next","go_prev","go_id","go_end","go_start","go_text","go_progression"],W.moduleName,(s,n)=>n(!0)),t.register("activate",W.moduleName,(s,n)=>{this.unblock(e),n(!0)}),t.log("FixedSetup Mounted"),!0}unmount(e,t){var i;return t.unregisterAll(W.moduleName),(i=e.document.getElementById(st))==null||i.remove(),t.log("FixedSetup Unmounted"),super.unmount(e,t)}};nt.moduleName="fixed_setup";let _t=nt;const Xt=["fixed_setup","decorator","peripherals"],Gt=["reflowable_setup","decorator","peripherals","column_snapper","scroll_snapper"],he=new Map([_t,qt,le,ke,jt,Vt].map(r=>[r.moduleName,r]));class Yt{constructor(e=window,t=[]){this.loadedModules=[],this.wnd=e,this.comms=new ge(e);const i=[...new Set(t)];if(i.length){if(typeof e>"u")throw Error("Loader is not in a web browser");e.parent!==e&&this.comms.log("Loader is probably in a frame"),this.loadedModules=i.map(s=>{const n=this.loadModule(s);if(n)return n.mount(this.wnd,this.comms),n}).filter(s=>s!==void 0)}}loadModule(e){const t=he.get(e);return t===void 0?(this.comms.log(`Module "${name}" does not exist in the library`),t):new t}addModule(e){const t=this.loadModule(e);return!t||!t.mount(this.wnd,this.comms)?!1:(this.loadedModules.push(t),!0)}removeModule(e){const t=he.get(e);if(t===void 0)return this.comms.log(`Module "${e}" does not exist in the library`),!1;const i=this.loadedModules.findIndex(s=>s instanceof t);return i<0?!1:(this.loadedModules[i].unmount(this.wnd,this.comms),this.loadedModules.splice(i,1),!0)}destroy(){this.comms.destroy(),this.loadedModules.forEach(e=>e.unmount(this.wnd,this.comms)),this.loadedModules=[]}}E.COMMS_VERSION=U,E.Comms=ge,E.Decorator=ke,E.FXLModules=Xt,E.Layout=Fe,E.Loader=Yt,E.Module=V,E.ModuleLibrary=he,E.Peripherals=le,E.ReflowableModules=Gt,E.Width=We,E.mid=me,Object.defineProperty(E,Symbol.toStringTag,{value:"Module"})});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@readium/navigator-html-injectables",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0-beta.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "An embeddable solution for connecting frames of HTML publications with a Readium Navigator",
|
|
6
6
|
"author": "readium",
|
|
@@ -26,6 +26,9 @@
|
|
|
26
26
|
"reader",
|
|
27
27
|
"viewer"
|
|
28
28
|
],
|
|
29
|
+
"scripts": {
|
|
30
|
+
"build": "tsc && vite build"
|
|
31
|
+
},
|
|
29
32
|
"main": "./dist/index.umd.cjs",
|
|
30
33
|
"module": "./dist/index.js",
|
|
31
34
|
"types": "./types/src/index.d.ts",
|
|
@@ -45,14 +48,10 @@
|
|
|
45
48
|
"node": ">=18"
|
|
46
49
|
},
|
|
47
50
|
"devDependencies": {
|
|
48
|
-
"@
|
|
51
|
+
"@readium/shared": "workspace:*",
|
|
49
52
|
"css-selector-generator": "^3.6.9",
|
|
50
53
|
"tslib": "^2.6.1",
|
|
51
54
|
"typescript": "^5.4.5",
|
|
52
|
-
"vite": "^4.5.5"
|
|
53
|
-
"@readium/shared": "1.2.1"
|
|
54
|
-
},
|
|
55
|
-
"scripts": {
|
|
56
|
-
"build": "tsc && vite build"
|
|
55
|
+
"vite": "^4.5.5"
|
|
57
56
|
}
|
|
58
|
-
}
|
|
57
|
+
}
|
package/src/comms/keys.ts
CHANGED
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
export const colorToRgba = (color: string): { r: number; g: number; b: number; a: number; } => {
|
|
2
|
+
if (color.startsWith("rgb")) {
|
|
3
|
+
const rgb = color.match(/rgb\((\d+),\s(\d+),\s(\d+)(?:,\s(\d+))?\)/);
|
|
4
|
+
if (rgb) {
|
|
5
|
+
return {
|
|
6
|
+
r: parseInt(rgb[1], 10),
|
|
7
|
+
g: parseInt(rgb[2], 10),
|
|
8
|
+
b: parseInt(rgb[3], 10),
|
|
9
|
+
a: rgb[4] ? parseInt(rgb[4], 10) / 255 : 1,
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
} else if (color.startsWith("#")) {
|
|
13
|
+
const hex = color.slice(1);
|
|
14
|
+
if (hex.length === 3 || hex.length === 4) {
|
|
15
|
+
return {
|
|
16
|
+
r: parseInt(hex[0] + hex[0], 16) / 255,
|
|
17
|
+
g: parseInt(hex[1] + hex[1], 16) / 255,
|
|
18
|
+
b: parseInt(hex[2] + hex[2], 16) / 255,
|
|
19
|
+
a: hex.length === 4 ? parseInt(hex[3] + hex[3], 16) / 255 : 1,
|
|
20
|
+
};
|
|
21
|
+
} else if (hex.length === 6 || hex.length === 8) {
|
|
22
|
+
return {
|
|
23
|
+
r: parseInt(hex[0] + hex[1], 16) / 255,
|
|
24
|
+
g: parseInt(hex[2] + hex[3], 16) / 255,
|
|
25
|
+
b: parseInt(hex[4] + hex[5], 16) / 255,
|
|
26
|
+
a: hex.length === 8 ? parseInt(hex[6] + hex[7], 16) / 255 : 1,
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
return { r: 0, g: 0, b: 0, a: 1 };
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
export const getLuminance = (color: { r: number; g: number; b: number; a: number }): number => {
|
|
34
|
+
return 0.2126 * color.r * color.a + 0.7152 * color.g * color.a + 0.0722 * color.b * color.a;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export const isDarkColor = (color: string): boolean => {
|
|
38
|
+
const rgba = colorToRgba(color);
|
|
39
|
+
const luminance = getLuminance(rgba);
|
|
40
|
+
return luminance < 128;
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
export const isLightColor = (color: string): boolean => !isDarkColor(color);
|
|
44
|
+
|
|
45
|
+
export const checkContrast = (color1: string, color2: string): number => {
|
|
46
|
+
const rgba1 = colorToRgba(color1);
|
|
47
|
+
const rgba2 = colorToRgba(color2);
|
|
48
|
+
const lum1 = getLuminance(rgba1);
|
|
49
|
+
const lum2 = getLuminance(rgba2);
|
|
50
|
+
const brightest = Math.max(lum1, lum2);
|
|
51
|
+
const darkest = Math.min(lum1, lum2);
|
|
52
|
+
return (brightest + 0.05) / (darkest + 0.05);
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
export const ensureContrast = (color1: string, color2: string, contrast: number = 4.5): string[] => {
|
|
56
|
+
const c1 = colorToRgba(color1);
|
|
57
|
+
const c2 = colorToRgba(color2);
|
|
58
|
+
|
|
59
|
+
const lum1 = getLuminance(c1);
|
|
60
|
+
const lum2 = getLuminance(c2);
|
|
61
|
+
const [darkest, brightest] = lum1 < lum2 ? [lum1, lum2] : [lum2, lum1];
|
|
62
|
+
|
|
63
|
+
const contrastRatio = (brightest + 0.05) / (darkest + 0.05);
|
|
64
|
+
if (contrastRatio >= contrast) {
|
|
65
|
+
return [
|
|
66
|
+
`rgba(${c1.r}, ${c1.g}, ${c1.b}, ${c1.a})`,
|
|
67
|
+
`rgba(${c2.r}, ${c2.g}, ${c2.b}, ${c2.a})`
|
|
68
|
+
];
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
const adjustColor = (color: { r: number; g: number; b: number; a: number }, delta: number) => ({
|
|
72
|
+
r: Math.max(0, Math.min(255, color.r + delta)),
|
|
73
|
+
g: Math.max(0, Math.min(255, color.g + delta)),
|
|
74
|
+
b: Math.max(0, Math.min(255, color.b + delta)),
|
|
75
|
+
a: color.a
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
const delta = ((contrast - contrastRatio) * 255) / (contrastRatio + 0.05);
|
|
79
|
+
let correctedColor: { r: number; g: number; b: number; a: number };
|
|
80
|
+
let otherColor: { r: number; g: number; b: number; a: number };
|
|
81
|
+
if (lum1 < lum2) {
|
|
82
|
+
correctedColor = c1;
|
|
83
|
+
otherColor = c2;
|
|
84
|
+
} else {
|
|
85
|
+
correctedColor = c2;
|
|
86
|
+
otherColor = c1;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
const correctedColorAdjusted = adjustColor(correctedColor, -delta);
|
|
90
|
+
const newLum = getLuminance(correctedColorAdjusted);
|
|
91
|
+
const newContrastRatio = (brightest + 0.05) / (newLum + 0.05);
|
|
92
|
+
|
|
93
|
+
if (newContrastRatio < contrast) {
|
|
94
|
+
const updatedDelta = ((contrast - newContrastRatio) * 255) / (newContrastRatio + 0.05);
|
|
95
|
+
const otherColorAdjusted = adjustColor(otherColor, updatedDelta);
|
|
96
|
+
return [
|
|
97
|
+
lum1 < lum2
|
|
98
|
+
? `rgba(${correctedColorAdjusted.r}, ${correctedColorAdjusted.g}, ${correctedColorAdjusted.b}, ${correctedColorAdjusted.a})`
|
|
99
|
+
: `rgba(${otherColorAdjusted.r}, ${otherColorAdjusted.g}, ${otherColorAdjusted.b}, ${otherColorAdjusted.a})`,
|
|
100
|
+
lum1 < lum2
|
|
101
|
+
? `rgba(${otherColorAdjusted.r}, ${otherColorAdjusted.g}, ${otherColorAdjusted.b}, ${otherColorAdjusted.a})`
|
|
102
|
+
: `rgba(${correctedColorAdjusted.r}, ${correctedColorAdjusted.g}, ${correctedColorAdjusted.b}, ${correctedColorAdjusted.a})`,
|
|
103
|
+
];
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
return [
|
|
107
|
+
lum1 < lum2
|
|
108
|
+
? `rgba(${correctedColorAdjusted.r}, ${correctedColorAdjusted.g}, ${correctedColorAdjusted.b}, ${correctedColorAdjusted.a})`
|
|
109
|
+
: `rgba(${otherColor.r}, ${otherColor.g}, ${otherColor.b}, ${otherColor.a})`,
|
|
110
|
+
lum1 < lum2
|
|
111
|
+
? `rgba(${otherColor.r}, ${otherColor.g}, ${otherColor.b}, ${otherColor.a})`
|
|
112
|
+
: `rgba(${correctedColorAdjusted.r}, ${correctedColorAdjusted.g}, ${correctedColorAdjusted.b}, ${correctedColorAdjusted.a})`,
|
|
113
|
+
];
|
|
114
|
+
};
|