@readium/navigator-html-injectables 2.5.0 → 2.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/Loader.js +1 -0
- package/dist/comms/comms.js +1 -0
- package/dist/comms/mid.js +1 -0
- package/dist/helpers/animation.js +1 -0
- package/dist/helpers/css.js +1 -0
- package/dist/helpers/document.js +1 -0
- package/dist/helpers/dom.js +1 -0
- package/dist/helpers/locator.js +1 -0
- package/dist/helpers/rect.js +1 -0
- package/dist/helpers/sanitize.js +1 -0
- package/dist/index.js +1 -4601
- package/dist/keyboard/KeyCombinationManager.js +1 -0
- package/dist/keyboard/KeyboardCombinations.js +1 -0
- package/dist/modules/Decorator.js +24 -0
- package/dist/modules/Module.js +1 -0
- package/dist/modules/ModuleLibrary.js +1 -0
- package/dist/modules/Peripherals.js +1 -0
- package/dist/modules/setup/FixedSetup.js +13 -0
- package/dist/modules/setup/ReflowableSetup.js +1 -0
- package/dist/modules/setup/Setup.js +1 -0
- package/dist/modules/setup/WebPubSetup.js +1 -0
- package/dist/modules/snapper/CJKVerticalSnapper.js +12 -0
- package/dist/modules/snapper/ColumnSnapper.js +35 -0
- package/dist/modules/snapper/ScrollSnapper.js +9 -0
- package/dist/modules/snapper/Snapper.js +5 -0
- package/dist/modules/snapper/WebPubSnapper.js +1 -0
- package/dist/protection/BulkCopyProtector.js +1 -0
- package/dist/protection/PatternAnalyzer.js +1 -0
- package/dist/protection/PrintProtector.js +15 -0
- package/dist/protection/SelectionAnalyzer.js +1 -0
- package/dist/protection/config.js +1 -0
- package/dist/vendor/approx-string-match/index.js +1 -0
- package/dist/vendor/hypothesis/anchoring/match-quote.js +1 -0
- package/dist/vendor/hypothesis/anchoring/text-range.js +1 -0
- package/dist/vendor/hypothesis/anchoring/trim-range.js +1 -0
- package/dist/vendor/hypothesis/anchoring/types.js +1 -0
- package/package.json +9 -8
- package/src/comms/comms.ts +11 -1
- package/src/comms/keys.ts +6 -2
- package/src/helpers/css.ts +1 -1
- package/src/helpers/document.ts +5 -5
- package/src/helpers/locator.ts +5 -5
- package/src/helpers/rect.ts +79 -18
- package/src/index.ts +1 -1
- package/src/modules/Decorator.ts +404 -107
- package/src/modules/snapper/CJKVerticalSnapper.ts +34 -7
- package/src/modules/snapper/ColumnSnapper.ts +54 -6
- package/src/modules/snapper/ScrollSnapper.ts +30 -7
- package/src/modules/snapper/Snapper.ts +144 -0
- package/src/modules/snapper/WebPubSnapper.ts +31 -7
- package/types/src/comms/comms.d.ts +10 -1
- package/types/src/comms/keys.d.ts +2 -2
- package/types/src/helpers/css.d.ts +1 -1
- package/types/src/helpers/document.d.ts +5 -5
- package/types/src/helpers/rect.d.ts +2 -1
- package/types/src/index.d.ts +1 -1
- package/types/src/modules/Decorator.d.ts +33 -7
- package/types/src/modules/snapper/CJKVerticalSnapper.d.ts +1 -0
- package/types/src/modules/snapper/ColumnSnapper.d.ts +14 -1
- package/types/src/modules/snapper/ScrollSnapper.d.ts +1 -0
- package/types/src/modules/snapper/Snapper.d.ts +58 -0
- package/types/src/modules/snapper/WebPubSnapper.d.ts +1 -0
- package/dist/ar-DyHX_uy2.js +0 -7
- package/dist/da-Dct0PS3E.js +0 -7
- package/dist/fr-C5HEel98.js +0 -7
- package/dist/index.umd.cjs +0 -96
- package/dist/it-DFOBoXGy.js +0 -7
- package/dist/pt_PT-Di3sVjze.js +0 -7
- package/dist/sv-BfzAFsVN.js +0 -7
- package/src/helpers/color.ts +0 -268
- package/src/helpers/sML.ts +0 -143
- package/types/src/helpers/color.d.ts +0 -27
- package/types/src/helpers/sML.d.ts +0 -56
package/dist/Loader.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{Comms as r}from"./comms/comms.js";import{ModuleLibrary as d}from"./modules/ModuleLibrary.js";class m{constructor(o=window,e=[]){this.loadedModules=[],this.wnd=o,this.comms=new r(o);const t=[...new Set(e)];if(t.length){if(typeof o>"u")throw Error("Loader is not in a web browser");o.parent!==o&&this.comms.log("Loader is probably in a frame"),this.loadedModules=t.map(s=>{const i=this.loadModule(s);if(i)return i.mount(this.wnd,this.comms),i}).filter(s=>s!==void 0)}}loadModule(o){const e=d.get(o);return e===void 0?(this.comms.log(`Module "${name}" does not exist in the library`),e):new e}addModule(o){const e=this.loadModule(o);return!e||!e.mount(this.wnd,this.comms)?!1:(this.loadedModules.push(e),!0)}removeModule(o){const e=d.get(o);if(e===void 0)return this.comms.log(`Module "${o}" does not exist in the library`),!1;const t=this.loadedModules.findIndex(s=>s instanceof e);return t<0?!1:(this.loadedModules[t].unmount(this.wnd,this.comms),this.loadedModules.splice(t,1),!0)}destroy(){this.comms.destroy(),this.loadedModules.forEach(o=>o.unmount(this.wnd,this.comms)),this.loadedModules=[]}}export{m as Loader};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{mid as a}from"./mid.js";const n=1;class c{constructor(i){this.destination=null,this.registrar=new Map,this.origin="",this.channelId="",this.receiver=this.receive.bind(this),this.preLog=[],this.wnd=i,i.addEventListener("message",this.receiver)}receive(i){if(i.source===null)throw Error("Event source is null");if(typeof i.data!="object")return;const e=i.data;if(!(!("_readium"in e)||!e._readium||e._readium<=0)){if(e.key==="_ping"){if(!this.destination){if(this.destination=i.source,this.origin=i.origin,this.channelId=e._channel,e._readium!==n){e._readium>n?this.send("error",`received comms version ${e._readium} higher than ${n}`):this.send("error",`received comms version ${e._readium} lower than ${n}`),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(e._channel!==this.channelId||i.origin!==this.origin)return}else return;this.handle(e)}}handle(i){const e=this.registrar.get(i.key);if(!e||e.length===0){i.strict&&this.send("_unhandled",i);return}e.forEach(r=>r.cb(i.data,t=>{this.send("_ack",t,i.id)}))}register(i,e,r){Array.isArray(i)||(i=[i]),i.forEach(t=>{const s=this.registrar.get(t);if(s&&s.length>=0){if(s.find(o=>o.module===e))throw new Error(`Trying to register another callback for combination of event ${t} and module ${e}`);s.push({cb:r,module:e}),this.registrar.set(t,s)}else this.registrar.set(t,[{cb:r,module:e}])})}unregister(i,e){Array.isArray(i)||(i=[i]),i.forEach(r=>{const t=this.registrar.get(r);!t||t.length===0||t.splice(t.findIndex(s=>s.module===e),1)})}unregisterAll(i){this.registrar.forEach((e,r)=>this.registrar.set(r,e.filter(t=>t.module!==i)))}log(...i){this.destination?this.send("log",i):this.preLog.push(i)}get ready(){return!!this.destination}destroy(){this.destination=null,this.channelId="",this.preLog=[],this.registrar.clear(),this.wnd.removeEventListener("message",this.receiver)}send(i,e,r=void 0,t=[]){if(!this.destination)throw Error("Attempted to send comms message before destination has been initialized");const s={_readium:n,_channel:this.channelId,id:r??a(),key:i,data:e};try{this.destination.postMessage(s,{targetOrigin:this.origin,transfer:t})}catch(h){if(t.length>0)throw h;this.destination.postMessage(s,this.origin,t)}}}export{n as COMMS_VERSION,c as Comms};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const o=Math.pow(2,32),t=()=>Math.round(Math.random()*o).toString(36),n=()=>`${Math.round(performance.now())}-${t()}-${t()}`;export{n as mid};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
function n(e){return e<.5?2*e*e:-1+(4-2*e)*e}export{n as easeInOutQuad};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const l=new Set(["backgroundColor","textColor","linkColor","visitedColor","primaryColor","secondaryColor","selectionBackgroundColor","selectionTextColor","blendFilter","darkenFilter","invertFilter","invertGaiji"]),s=/--(?:USER|RS)__([\w-]+)/g;function f(e,t){const r=e??"",o=t??"",n=new Set;for(const c of r.matchAll(s))n.add(c[1]);for(const c of o.matchAll(s))n.add(c[1]);for(const c of n)if(!l.has(c))return!0;return!1}function i(e){const t={},r=e.document.documentElement.style;for(const o in e.document.documentElement.style)Object.hasOwn(r,o)&&!Number.isNaN(Number.parseInt(o))&&(t[r[o]]=r.getPropertyValue(r[o]));return t}function m(e,t){const r=i(e);Object.keys(r).forEach(o=>{t.hasOwnProperty(o)||a(e,o)}),Object.entries(t).forEach(([o,n])=>{r[o]!==n&&u(e,o,n)})}function d(e,t){return e.document.documentElement.style.getPropertyValue(t)}function u(e,t,r){e.document.documentElement.style.setProperty(t,r)}function a(e,t){e.document.documentElement.style.removeProperty(t)}export{i as getProperties,d as getProperty,a as removeProperty,u as setProperty,f as styleChangeAffectsLayout,m as updateProperties};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
function x(t){return(t.document.documentElement.dir||t.document.body.dir).toLowerCase()==="rtl"}function C(t){return(t.getComputedStyle(t.document.documentElement).writingMode||t.getComputedStyle(t.document.body).writingMode)==="vertical-lr"}function v(t){const e=t.getComputedStyle(t.document.documentElement).writingMode||t.getComputedStyle(t.document.body).writingMode;return e==="vertical-rl"||e==="vertical-lr"}function b(t){const e=v(t),r=e&&C(t),i=t.innerWidth,u=t.innerHeight,s=t.document.scrollingElement,f=s.scrollLeft,g=s.scrollTop,d=parseInt(t.getComputedStyle(t.document.documentElement).getPropertyValue("column-count")),l=e&&!r?s.scrollWidth-i+f:f,n=g;return{isVertical:e,isVertLR:r,viewportInlineSize:e?u:i,viewportBlockSize:e?i:u,pageInlineSize:e?u:i/(d||1),xDocOffset:l,yDocOffset:n,inlineScrollOffset:e?n:l,blockScrollOffset:e?l:n,inlineStart:o=>e?o.top:o.left,blockStart:o=>e?o.left:o.top,inlineSize:o=>e?o.height:o.width,blockSize:o=>e?o.width:o.height,applyPosition(o,m,p,a,y,c){o.style.position="absolute",e?(o.style.top=`${m*c}px`,o.style.left=`${p*c}px`,o.style.height=`${a*c}px`,o.style.width=`${y*c}px`):(o.style.left=`${m*c}px`,o.style.top=`${p*c}px`,o.style.width=`${a*c}px`,o.style.height=`${y*c}px`)},toRect(o,m,p,a){return e?new DOMRect(m,o,a,p):new DOMRect(o,m,p,a)}}}function S(t){return parseInt(t.getComputedStyle(t.document.documentElement).getPropertyValue("column-count"))}function h(t){const e=getComputedStyle(t),r=parseFloat(e.paddingTop||"0"),i=parseFloat(e.paddingBottom||"0");return t.clientHeight-r-i}function E(t){const e=S(t);if(!e)return!1;const r=t.document.querySelectorAll("div[id^='readium-virtual-page']");for(const l of r)l.remove();const i=r.length,u=t.document.scrollingElement.scrollWidth,s=t.visualViewport.width,g=Math.round(u/s*e)%e,d=e===1||g===0?0:e-g;if(d>0)for(let l=0;l<d;l++){const n=t.document.createElement("div");n.setAttribute("id",`readium-virtual-page-${l}`),n.dataset.readium="true",CSS.supports("break-before","column")?n.style.breakBefore="column":(CSS.supports("break-inside","avoid-column")&&(n.style.breakInside="avoid-column"),n.style.height=h(t.document.documentElement)+"px"),n.innerHTML="​",t.document.body.appendChild(n)}return i!==d}function M(t){const e=t.document.createElement("style");e.appendChild(t.document.createTextNode("*{}")),t.document.body.appendChild(e),t.document.body.removeChild(e)}export{E as appendVirtualColumnIfNeeded,M as forceWebkitRecalc,S as getColumnCountPerScreen,h as getContentHeight,x as isRTL,C as isVerticalLR,v as isVerticalWriting,b as makeWritingContext};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{Locator as c,LocatorText as u,LocatorLocations as s}from"@readium/shared";function y(t){const e=t.getSelection();e&&e.removeAllRanges()}const l=["a","area","audio","button","canvas","details","input","label","option","select","submit","textarea","video"],a=["dialog","radiogroup","radio","menu","menuitem"];function f(t){return d(t)?null:g(t)?t:t.parentElement?f(t.parentElement):null}function d(t){return t?t.closest("[inert]")!==null||t.hasAttribute("disabled"):!0}function g(t){return t?t.role&&a.includes(t.role)?!0:t.tagName.toLowerCase()==="iframe"?!1:t.tabIndex>=0?!0:l.includes(t.nodeName.toLowerCase())||t.hasAttribute("contenteditable")&&t.getAttribute("contenteditable")?.toLowerCase()!=="false":!1}function v(t,e){const n=o(t,t.document.body,e),r=t._readium_cssSelectorGenerator.getCssSelector(n,{selectors:["tag","id","class","nthchild","nthoftype","attribute"]});return new c({href:"#",type:"application/xhtml+xml",locations:new s({otherLocations:new Map([["cssSelector",r]])}),text:new u({highlight:n.textContent||void 0})})}function o(t,e,n){for(var r=0;r<e.children.length;r++){const i=e.children[r];if(!p(i)&&b(t,i,n))return h(t,i)?i:o(t,i,n)}return e}function b(t,e,n){if(e===document.body||e===document.documentElement)return!0;if(!document||!document.documentElement||!document.body)return!1;const r=e.getBoundingClientRect();return n?r.bottom>0&&r.top<t.innerHeight:r.right>0&&r.left<t.innerWidth}function h(t,e){const n=e.getBoundingClientRect();return n.top>=0&&n.left>=0&&n.bottom<=t.innerHeight&&n.right<=t.innerWidth}function p(t){const e=getComputedStyle(t);if(e){const n=e.getPropertyValue("display");if(n!="block"&&n!="list-item"||e.getPropertyValue("opacity")==="0")return!0}return!1}export{y as deselect,v as findFirstVisibleLocator,d as isElementBlocked,g as isInteractiveElement,f as nearestInteractiveElement};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{getCssSelector as i}from"@readium/shared";import{TextQuoteAnchor as l}from"../vendor/hypothesis/anchoring/types.js";function a(o){const t=o.tagName.toUpperCase();return t==="IMG"||t==="VIDEO"||t==="AUDIO"||t==="IFRAME"||t==="OBJECT"||t==="EMBED"||t==="CANVAS"}function g(o,t){try{const r=t.locations,f=t.text;if(f&&f.highlight){let e;r&&i(r)&&(e=o.querySelector(i(r))),e||(e=o.body);const n=new l(e,f.highlight,{prefix:f.before,suffix:f.after});try{return n.toRange()}catch{return console.warn("Quote not found:",n),null}}if(r){let e=null;if(!e&&i(r)&&(e=o.querySelector(i(r))),!e&&r.fragments){for(const n of r.fragments)if(e=o.getElementById(n),e)break}if(e){const n=o.createRange();return e.childNodes.length===0||a(e)?(n.selectNode(e),n):(n.setStartBefore(e),n.setEndAfter(e),n)}}}catch(r){console.error(r)}return null}export{g as rangeFromLocator};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
function y(t,e){const i=e.map(g=>g.toUpperCase()),n=[],o=t.commonAncestorContainer,h=o.nodeType===Node.TEXT_NODE?o.parentNode:o,l=t.startContainer.ownerDocument.createTreeWalker(h,NodeFilter.SHOW_TEXT);let f=l.nextNode();for(;f;){if(t.intersectsNode(f)){let g=f.parentNode,m=!1;for(;g;){if(g.nodeType===Node.ELEMENT_NODE&&i.includes(g.tagName.toUpperCase())){m=!0;break}g=g.parentNode}if(!m){const s=t.cloneRange();s.selectNode(f),s.compareBoundaryPoints(Range.START_TO_START,t)<0&&s.setStart(t.startContainer,t.startOffset),s.compareBoundaryPoints(Range.END_TO_END,t)>0&&s.setEnd(t.endContainer,t.endOffset);for(const r of s.getClientRects())n.push({left:r.left,right:r.right,top:r.top,bottom:r.bottom,width:r.width,height:r.height})}}f=l.nextNode()}return n}function _(t,e,i=!1,n=0){let h;if(Array.isArray(t))h=t;else{let s=t.getClientRects();s.length||t.commonAncestorContainer.nodeType===Node.ELEMENT_NODE&&(s=t.commonAncestorContainer.getClientRects()),h=[];for(const r of s)h.push({bottom:r.bottom,height:r.height,left:r.left,right:r.right,top:r.top,width:r.width})}if(n)for(const s of h)s.left-=n,s.top-=n,s.right+=n,s.bottom+=n,s.width+=n*2,s.height+=n*2;const l=b(h,1,e,i),f=N(l,1),g=w(f),m=4;for(let s=g.length-1;s>=0;s--){const r=g[s];if(!(r.width*r.height>m))if(g.length>1)g.splice(s,1);else break}return g}function b(t,e,i,n=!1){for(let o=0;o<t.length;o++)for(let h=o+1;h<t.length;h++){const l=t[o],f=t[h];if(l===f)continue;const g=p(l.top,f.top,e)&&p(l.bottom,f.bottom,e),m=p(l.left,f.left,e)&&p(l.right,f.right,e);if((m&&!i&&!n||g&&!m)&&R(l,f,e)){const u=t.filter(c=>c!==l&&c!==f),C=E(l,f);return u.push(C),b(u,e,i,n)}}return t}function E(t,e){const i=Math.min(t.left,e.left),n=Math.max(t.right,e.right),o=Math.min(t.top,e.top),h=Math.max(t.bottom,e.bottom);return{bottom:h,height:h-o,left:i,right:n,top:o,width:n-i}}function N(t,e){const i=new Set(t);for(const n of t){if(!(n.width>1&&n.height>1)){i.delete(n);continue}for(const h of t)if(n!==h&&i.has(h)&&A(h,n,e)){i.delete(n);break}}return Array.from(i)}function A(t,e,i){return a(t,e.left,e.top,i)&&a(t,e.right,e.top,i)&&a(t,e.left,e.bottom,i)&&a(t,e.right,e.bottom,i)}function a(t,e,i,n){return(t.left<e||p(t.left,e,n))&&(t.right>e||p(t.right,e,n))&&(t.top<i||p(t.top,i,n))&&(t.bottom>i||p(t.bottom,i,n))}function w(t){for(let e=0;e<t.length;e++)for(let i=e+1;i<t.length;i++){const n=t[e],o=t[i];if(n!==o&&R(n,o,-1)){let h=[],l;const f=d(n,o);if(f.length===1)h=f,l=n;else{const m=d(o,n);f.length<m.length?(h=f,l=n):(h=m,l=o)}const g=t.filter(m=>m!==l);return Array.prototype.push.apply(g,h),w(g)}}return t}function d(t,e){const i=M(e,t);if(i.height===0||i.width===0)return[t];const n=[];{const o={bottom:t.bottom,height:0,left:t.left,right:i.left,top:t.top,width:0};o.width=o.right-o.left,o.height=o.bottom-o.top,o.height!==0&&o.width!==0&&n.push(o)}{const o={bottom:i.top,height:0,left:i.left,right:i.right,top:t.top,width:0};o.width=o.right-o.left,o.height=o.bottom-o.top,o.height!==0&&o.width!==0&&n.push(o)}{const o={bottom:t.bottom,height:0,left:i.left,right:i.right,top:i.bottom,width:0};o.width=o.right-o.left,o.height=o.bottom-o.top,o.height!==0&&o.width!==0&&n.push(o)}{const o={bottom:t.bottom,height:0,left:i.right,right:t.right,top:t.top,width:0};o.width=o.right-o.left,o.height=o.bottom-o.top,o.height!==0&&o.width!==0&&n.push(o)}return n}function M(t,e){const i=Math.max(t.left,e.left),n=Math.min(t.right,e.right),o=Math.max(t.top,e.top),h=Math.min(t.bottom,e.bottom);return{bottom:h,height:Math.max(0,h-o),left:i,right:n,top:o,width:Math.max(0,n-i)}}function R(t,e,i){return(t.left<e.right||i>=0&&p(t.left,e.right,i))&&(e.left<t.right||i>=0&&p(e.left,t.right,i))&&(t.top<e.bottom||i>=0&&p(t.top,e.bottom,i))&&(e.top<t.bottom||i>=0&&p(e.top,t.bottom,i))}function p(t,e,i){return Math.abs(t-e)<=i}export{_ as getClientRectsNoOverlap,y as getTextClientRects,a as rectContainsPoint};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const i=["div","span","p","br","hr","b","i","em","strong","s","u","mark","small","sub","sup","abbr","cite","code","data","dfn","kbd","q","samp","time","var","blockquote","pre","svg","g","path","circle","ellipse","rect","line","polygon","polyline","text","tspan","defs","use"],a=/^on/i,c=new Set(["href","src","action","formaction","xlink:href"]),l=/^\s*(javascript|data):/i;function d(t,n){const o=t.document.createElement("div");if("Sanitizer"in t&&typeof o.setHTML=="function")try{const r=new t.Sanitizer({allowElements:i});return o.setHTML(n,{sanitizer:r}),o.firstElementChild}catch{}const e=t.document.implementation.createHTMLDocument("");for(e.body.innerHTML=n,f(e.body,new Set(i));e.body.firstChild;)o.appendChild(t.document.adoptNode(e.body.firstChild));return o.firstElementChild}function f(t,n){const o=Array.from(t.querySelectorAll("*")).reverse();for(const e of o){if(!n.has(e.localName)){e.replaceWith(...Array.from(e.childNodes));continue}for(const{name:r,value:s}of Array.from(e.attributes))(a.test(r)||c.has(r)&&l.test(s))&&e.removeAttribute(r)}}export{d as sanitizeHTML};
|