hypothesis 1.1045.0 → 1.1048.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/build/boot.js +1 -1
- package/build/manifest.json +14 -14
- package/build/scripts/annotator.bundle.js +45 -45
- package/build/scripts/annotator.bundle.js.map +1 -1
- package/build/scripts/sidebar.bundle.js +324 -324
- package/build/scripts/sidebar.bundle.js.map +1 -1
- package/build/scripts/ui-playground.bundle.js.map +1 -1
- package/build/styles/annotator.css +26 -0
- package/build/styles/annotator.css.map +1 -1
- package/build/styles/highlights.css.map +1 -1
- package/build/styles/pdfjs-overrides.css +1 -1
- package/build/styles/pdfjs-overrides.css.map +1 -1
- package/build/styles/sidebar.css +32 -1
- package/build/styles/sidebar.css.map +1 -1
- package/build/styles/ui-playground.css +27 -1
- package/build/styles/ui-playground.css.map +1 -1
- package/package.json +2 -2
package/build/boot.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
!function(){"use strict";function t(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n]);return t}function e(t){for(var e=arguments.length,n=new Array(e>1?e-1:0),r=1;r<e;r++)n[r-1]=arguments[r];return n.every((function(e){return"function"==typeof t[e]}))}var n={es2017:function(){return!e(Object,"entries","values")},es2018:function(){return"function"!=typeof Promise||!e(Promise.prototype,"finally")}};function r(t,e){var n="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(!n){if(Array.isArray(t)||(n=o(t))||e&&t&&"number"==typeof t.length){n&&(t=n);var r=0,s=function(){};return{s:s,n:function(){return r>=t.length?{done:!0}:{done:!1,value:t[r++]}},e:function(t){throw t},f:s}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var a,i=!0,l=!1;return{s:function(){n=n.call(t)},n:function(){var t=n.next();return i=t.done,t},e:function(t){l=!0,a=t},f:function(){try{i||null==n.return||n.return()}finally{if(l)throw a}}}}function s(t){return function(t){if(Array.isArray(t))return a(t)}(t)||function(t){if("undefined"!=typeof Symbol&&null!=t[Symbol.iterator]||null!=t["@@iterator"])return Array.from(t)}(t)||o(t)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function o(t,e){if(t){if("string"==typeof t)return a(t,e);var n=Object.prototype.toString.call(t).slice(8,-1);return"Object"===n&&t.constructor&&(n=t.constructor.name),"Map"===n||"Set"===n?Array.from(t):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?a(t,e):void 0}}function a(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,r=new Array(e);n<e;n++)r[n]=t[n];return r}var i=["es2017","es2018"];function l(t){t.setAttribute("data-hypothesis-asset","")}function c(t,e){var n=t.createElement("link");n.rel="stylesheet",n.type="text/css",n.href=e,l(n),t.head.appendChild(n)}function u(t,e){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},r=n.esModule,s=void 0===r||r,o=n.forceReload,a=void 0!==o&&o,i=t.createElement("script");s&&(i.type="module"),a&&(e+="#ts=".concat(Date.now())),i.src=e,i.async=!1,l(i),t.head.appendChild(i)}function p(t,e,n,r){var s=t.createElement("link");s.rel=e,s.href=r,s.type="application/annotator+".concat(n),l(s),t.head.appendChild(s)}function d(t,e,n){var r=t.createElement("link");r.rel="preload",r.as=e,r.href=n,"fetch"===e&&(r.crossOrigin="anonymous"),l(r),t.head.appendChild(r)}function f(t,e){return t.assetRoot+"build/"+t.manifest[e]}function h(t){return function(t){return t.filter((function(t){var e=n[t];if(!e)throw new Error('Unknown polyfill set "'.concat(t,'"'));return e()}))}(t).map((function(t){return"scripts/polyfills-".concat(t,".bundle.js")}))}function y(t){var e=t.match(/(https?):\/\/([^:/]+)/);return e?{protocol:e[1],hostname:e[2]}:null}function m(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:document,e=t.currentScript;return e?y(e.src):null}function b(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:document;if(-1===t.indexOf("{"))return t;var n=m(e);if(!n)throw new Error("Could not process URL template because script origin is unknown");return t=(t=t.replace("{current_host}",n.hostname)).replace("{current_scheme}",n.protocol)}var v={"scripts/annotator.bundle.js":"scripts/annotator.bundle.js?
|
|
1
|
+
!function(){"use strict";function t(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n]);return t}function e(t){for(var e=arguments.length,n=new Array(e>1?e-1:0),r=1;r<e;r++)n[r-1]=arguments[r];return n.every((function(e){return"function"==typeof t[e]}))}var n={es2017:function(){return!e(Object,"entries","values")},es2018:function(){return"function"!=typeof Promise||!e(Promise.prototype,"finally")}};function r(t,e){var n="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(!n){if(Array.isArray(t)||(n=o(t))||e&&t&&"number"==typeof t.length){n&&(t=n);var r=0,s=function(){};return{s:s,n:function(){return r>=t.length?{done:!0}:{done:!1,value:t[r++]}},e:function(t){throw t},f:s}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var a,i=!0,l=!1;return{s:function(){n=n.call(t)},n:function(){var t=n.next();return i=t.done,t},e:function(t){l=!0,a=t},f:function(){try{i||null==n.return||n.return()}finally{if(l)throw a}}}}function s(t){return function(t){if(Array.isArray(t))return a(t)}(t)||function(t){if("undefined"!=typeof Symbol&&null!=t[Symbol.iterator]||null!=t["@@iterator"])return Array.from(t)}(t)||o(t)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function o(t,e){if(t){if("string"==typeof t)return a(t,e);var n=Object.prototype.toString.call(t).slice(8,-1);return"Object"===n&&t.constructor&&(n=t.constructor.name),"Map"===n||"Set"===n?Array.from(t):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?a(t,e):void 0}}function a(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,r=new Array(e);n<e;n++)r[n]=t[n];return r}var i=["es2017","es2018"];function l(t){t.setAttribute("data-hypothesis-asset","")}function c(t,e){var n=t.createElement("link");n.rel="stylesheet",n.type="text/css",n.href=e,l(n),t.head.appendChild(n)}function u(t,e){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},r=n.esModule,s=void 0===r||r,o=n.forceReload,a=void 0!==o&&o,i=t.createElement("script");s&&(i.type="module"),a&&(e+="#ts=".concat(Date.now())),i.src=e,i.async=!1,l(i),t.head.appendChild(i)}function p(t,e,n,r){var s=t.createElement("link");s.rel=e,s.href=r,s.type="application/annotator+".concat(n),l(s),t.head.appendChild(s)}function d(t,e,n){var r=t.createElement("link");r.rel="preload",r.as=e,r.href=n,"fetch"===e&&(r.crossOrigin="anonymous"),l(r),t.head.appendChild(r)}function f(t,e){return t.assetRoot+"build/"+t.manifest[e]}function h(t){return function(t){return t.filter((function(t){var e=n[t];if(!e)throw new Error('Unknown polyfill set "'.concat(t,'"'));return e()}))}(t).map((function(t){return"scripts/polyfills-".concat(t,".bundle.js")}))}function y(t){var e=t.match(/(https?):\/\/([^:/]+)/);return e?{protocol:e[1],hostname:e[2]}:null}function m(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:document,e=t.currentScript;return e?y(e.src):null}function b(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:document;if(-1===t.indexOf("{"))return t;var n=m(e);if(!n)throw new Error("Could not process URL template because script origin is unknown");return t=(t=t.replace("{current_host}",n.hostname)).replace("{current_scheme}",n.protocol)}var v={"scripts/annotator.bundle.js":"scripts/annotator.bundle.js?9f5f72","scripts/ui-playground.bundle.js":"scripts/ui-playground.bundle.js?dc7bc7","scripts/ui-playground.bundle.js.map":"scripts/ui-playground.bundle.js.map?ca443c","styles/annotator.css":"styles/annotator.css?f36ed8","styles/annotator.css.map":"styles/annotator.css.map?8cdbab","styles/highlights.css":"styles/highlights.css?5dd56a","styles/highlights.css.map":"styles/highlights.css.map?abf9aa","styles/katex.min.css":"styles/katex.min.css?ac2365","styles/katex.min.css.map":"styles/katex.min.css.map?4daef7","styles/pdfjs-overrides.css":"styles/pdfjs-overrides.css?c95edf","styles/pdfjs-overrides.css.map":"styles/pdfjs-overrides.css.map?961d51","styles/sidebar.css":"styles/sidebar.css?c86538","styles/sidebar.css.map":"styles/sidebar.css.map?d2ee26","styles/ui-playground.css":"styles/ui-playground.css?baf705","styles/ui-playground.css.map":"styles/ui-playground.css.map?d367b6","scripts/annotator.bundle.js.map":"scripts/annotator.bundle.js.map?ed9619","scripts/sidebar.bundle.js":"scripts/sidebar.bundle.js?67a058","scripts/sidebar.bundle.js.map":"scripts/sidebar.bundle.js.map?dec874"};if(function(){var t=[function(){return Promise.resolve()},function(){return new Map},function(){return new URL(document.location.href)},function(){return new Request("https://hypothes.is")},function(){return Element.prototype.attachShadow},function(){return CSS.supports("display: grid")},function(){return document.evaluate("/html/body",document,null,XPathResult.ANY_TYPE,null),!0}];try{return t.every((function(t){return t()}))}catch(t){return!1}}()){var g=function(e){for(var n={},r=e.querySelectorAll("script.js-hypothesis-config"),s=0;s<r.length;s++){var o=void 0;try{o=JSON.parse(r[s].textContent||"")}catch(t){console.warn("Could not parse settings from js-hypothesis-config tags",t),o={}}t(n,o)}return n}(document),j=b(g.assetRoot||"https://cdn.hypothes.is/hypothesis/1.1048.0/");if(document.querySelector("hypothesis-app")){!function(t,e){d(t,"fetch",e.apiUrl),d(t,"fetch",e.apiUrl+"links");var n,o=h(i),a=r([].concat(s(o),["scripts/sidebar.bundle.js"]));try{for(a.s();!(n=a.n()).done;)u(t,f(e,n.value),{esModule:!0})}catch(t){a.e(t)}finally{a.f()}for(var l=0,p=["styles/katex.min.css","styles/sidebar.css"];l<p.length;l++)c(t,f(e,p[l]))}(document,{assetRoot:j,manifest:v,apiUrl:g.apiUrl})}else{var w=g,A=b(w.notebookAppUrl||"https://hypothes.is/notebook"),k=b(w.sidebarAppUrl||"https://hypothes.is/app.html");!function(t,e){if(!t.querySelector('link[type="application/annotator+html"]')){p(t,"sidebar","html",e.sidebarAppUrl),p(t,"notebook","html",e.notebookAppUrl),d(t,"style",f(e,"styles/annotator.css")),p(t,"hypothesis-client","javascript",e.assetRoot+"build/boot.js");var n,o=h(i),a=r([].concat(s(o),["scripts/annotator.bundle.js"]));try{for(a.s();!(n=a.n()).done;)u(t,f(e,n.value),{esModule:!1})}catch(t){a.e(t)}finally{a.f()}var l=[];void 0!==window.PDFViewerApplication&&l.push("styles/pdfjs-overrides.css"),l.push("styles/highlights.css");for(var y=0,m=l;y<m.length;y++)c(t,f(e,m[y]))}}(document,{assetRoot:j,manifest:v,notebookAppUrl:A,sidebarAppUrl:k})}}else console.warn("The Hypothesis annotation tool is not supported in this browser. See https://web.hypothes.is/help/which-browsers-are-supported-by-hypothesis/.")}();
|
package/build/manifest.json
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
{
|
|
2
|
-
"scripts/annotator.bundle.js": "scripts/annotator.bundle.js?
|
|
2
|
+
"scripts/annotator.bundle.js": "scripts/annotator.bundle.js?9f5f72",
|
|
3
3
|
"scripts/ui-playground.bundle.js": "scripts/ui-playground.bundle.js?dc7bc7",
|
|
4
|
-
"
|
|
5
|
-
"styles/annotator.css
|
|
4
|
+
"scripts/ui-playground.bundle.js.map": "scripts/ui-playground.bundle.js.map?ca443c",
|
|
5
|
+
"styles/annotator.css": "styles/annotator.css?f36ed8",
|
|
6
|
+
"styles/annotator.css.map": "styles/annotator.css.map?8cdbab",
|
|
6
7
|
"styles/highlights.css": "styles/highlights.css?5dd56a",
|
|
7
|
-
"styles/highlights.css.map": "styles/highlights.css.map?
|
|
8
|
+
"styles/highlights.css.map": "styles/highlights.css.map?abf9aa",
|
|
8
9
|
"styles/katex.min.css": "styles/katex.min.css?ac2365",
|
|
9
10
|
"styles/katex.min.css.map": "styles/katex.min.css.map?4daef7",
|
|
10
|
-
"styles/pdfjs-overrides.css": "styles/pdfjs-overrides.css?
|
|
11
|
-
"styles/pdfjs-overrides.css.map": "styles/pdfjs-overrides.css.map?
|
|
12
|
-
"styles/sidebar.css": "styles/sidebar.css?
|
|
13
|
-
"styles/sidebar.css.map": "styles/sidebar.css.map?
|
|
14
|
-
"styles/ui-playground.css
|
|
15
|
-
"styles/ui-playground.css": "styles/ui-playground.css?
|
|
16
|
-
"scripts/
|
|
17
|
-
"scripts/
|
|
18
|
-
"scripts/
|
|
19
|
-
"scripts/sidebar.bundle.js.map": "scripts/sidebar.bundle.js.map?84574e"
|
|
11
|
+
"styles/pdfjs-overrides.css": "styles/pdfjs-overrides.css?c95edf",
|
|
12
|
+
"styles/pdfjs-overrides.css.map": "styles/pdfjs-overrides.css.map?961d51",
|
|
13
|
+
"styles/sidebar.css": "styles/sidebar.css?c86538",
|
|
14
|
+
"styles/sidebar.css.map": "styles/sidebar.css.map?d2ee26",
|
|
15
|
+
"styles/ui-playground.css": "styles/ui-playground.css?baf705",
|
|
16
|
+
"styles/ui-playground.css.map": "styles/ui-playground.css.map?d367b6",
|
|
17
|
+
"scripts/annotator.bundle.js.map": "scripts/annotator.bundle.js.map?ed9619",
|
|
18
|
+
"scripts/sidebar.bundle.js": "scripts/sidebar.bundle.js?67a058",
|
|
19
|
+
"scripts/sidebar.bundle.js.map": "scripts/sidebar.bundle.js.map?dec874"
|
|
20
20
|
}
|
|
@@ -56,55 +56,55 @@ if(!t.contains(this.element))throw new Error("Parent is not an ancestor of curre
|
|
|
56
56
|
if(e<0||e>t.childNodes.length)throw new Error("Child node offset is out of range");let n=0;for(let o=0;o<e;o++)n+=fe(t.childNodes[o]);return new me(t,n)}default:throw new Error("Point is not in an element or text node")}}}class _e{constructor(t,e){this.start=t,this.end=e}relativeTo(t){return new _e(this.start.relativeTo(t),this.end.relativeTo(t))}toRange(){let t,e;this.start.element===this.end.element&&this.start.offset<=this.end.offset?[t,e]=ge(this.start.element,this.start.offset,this.end.offset):(t=this.start.resolve({direction:1}),e=this.end.resolve({direction:2}));const n=new Range;return n.setStart(t.node,t.offset),n.setEnd(e.node,e.offset),n}static fromRange(t){const e=me.fromPoint(t.startContainer,t.startOffset),n=me.fromPoint(t.endContainer,t.endOffset);return new _e(e,n)}static fromOffsets(t,e,n){return new _e(new me(t,e),new me(t,n))}}const ve=".annotator-placeholder";function ye(t){return!!t.parentElement&&null!==t.parentElement.closest(ve)}function we(t){
|
|
57
57
|
if(t.focusNode===t.anchorNode)return t.focusOffset<t.anchorOffset;return t.getRangeAt(0).startContainer===t.focusNode}function be(t,e){try{var n,o;const i=null!==(n=null===(o=e.nodeValue)||void 0===o?void 0:o.length)&&void 0!==n?n:e.childNodes.length;return t.comparePoint(e,0)<=0&&t.comparePoint(e,i)>=0}catch(t){return!1}}function Ce(t,e){const n=t.commonAncestorContainer,o=n.ownerDocument.createNodeIterator(n,NodeFilter.SHOW_ALL);let i;for(;i=o.nextNode();)be(t,i)&&e(i)}function xe(t){if(t.isCollapsed)return null;const e=function(t){const e=/^\s*$/,n=[];Ce(t,(t=>{t.nodeType!==Node.TEXT_NODE||t.textContent.match(e)||n.push(t)}));let o=[];return n.forEach((e=>{const n=e.ownerDocument.createRange();if(n.selectNodeContents(e),e===t.startContainer&&n.setStart(e,t.startOffset),e===t.endContainer&&n.setEnd(e,t.endOffset),n.collapsed)return;const i=Array.from(n.getClientRects());n.detach(),o=o.concat(i)})),o}(t.getRangeAt(0));return 0===e.length?null:we(t)?e[0]:e[e.length-1]}const Se="http://www.w3.org/2000/svg"
|
|
58
58
|
;function Ee(t,e="hypothesis-highlight"){const n=function(t){if(t.collapsed)return[];let e=t.commonAncestorContainer;if(e.nodeType!==Node.ELEMENT_NODE&&(e=e.parentElement),!e)return[];const n=[],o=e.ownerDocument.createNodeIterator(e,NodeFilter.SHOW_TEXT);let i;for(;i=o.nextNode();){if(!be(t,i))continue;let e=i;e===t.startContainer&&t.startOffset>0?e.splitText(t.startOffset):(e===t.endContainer&&t.endOffset<e.data.length&&e.splitText(t.endOffset),n.push(e))}return n}(t),o=n.length>0&&ye(n[0]);let i=[],r=null,s=null;n.forEach((t=>{r&&r.nextSibling===t?s.push(t):(s=[t],i.push(s)),r=t}));const a=/^\s*$/;i=i.filter((t=>t.some((t=>!a.test(t.data)))));const c=[];return i.forEach((t=>{const n=document.createElement("hypothesis-highlight");n.className=e;t[0].parentNode.replaceChild(n,t[0]),t.forEach((t=>n.appendChild(t))),c.push(n)})),o||function(t){if(0===t.length)return;const e=function(t){const e=t.closest(".page");return e&&e.querySelector(".canvasWrapper > canvas")||null}(t[0]);if(!e||!e.parentElement)return
|
|
59
|
-
;let n=e.parentElement.querySelector(".hypothesis-highlight-layer");
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
;
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
;
|
|
66
|
-
|
|
67
|
-
;
|
|
68
|
-
;
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
;
|
|
90
|
-
;if(null
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
;
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
this._listeners.add(
|
|
59
|
+
;let n=e.parentElement.querySelector(".hypothesis-highlight-layer");if(!n){n=document.createElementNS(Se,"svg"),n.setAttribute("class","hypothesis-highlight-layer"),e.parentElement.appendChild(n),e.parentElement.style.position="relative";const t=n.style;t.position="absolute",t.left="0",t.top="0",t.width="100%",t.height="100%",t.mixBlendMode="multiply"}const o=e.getBoundingClientRect(),i=t.map((t=>{const e=t.getBoundingClientRect(),n=document.createElementNS(Se,"rect");return n.setAttribute("x",(e.left-o.left).toString()),n.setAttribute("y",(e.top-o.top).toString()),n.setAttribute("width",e.width.toString()),n.setAttribute("height",e.height.toString()),n.setAttribute("class","hypothesis-svg-highlight"),t.classList.add("is-transparent"),t.svgHighlight=n,n}));n.append(...i)}(c),c}function Te(t,e){const n=t.parentNode;e.forEach((e=>n.insertBefore(e,t))),t.remove()}function Ae(t){for(let e of t){if(e.parentNode){Te(e,Array.from(e.childNodes))}e.svgHighlight&&e.svgHighlight.remove()}}function ke(t,e){
|
|
60
|
+
t.forEach((t=>{if(t.svgHighlight){if(t.svgHighlight.classList.toggle("is-focused",e),e){t.svgHighlight.parentNode.append(t.svgHighlight)}}else t.classList.toggle("hypothesis-highlight-focused",e)}))}function Re(t){const e=t.map((t=>t.getBoundingClientRect()));return e.reduce(((t,e)=>({top:Math.min(t.top,e.top),left:Math.min(t.left,e.left),bottom:Math.max(t.bottom,e.bottom),right:Math.max(t.right,e.right)})))}class Le{constructor({contentContainer:t,hostRPC:e}){this._hostRPC=e,this._updatePending=!1,this._anchors=[],this._listeners=new kt,this._listeners.add(window,"resize",(()=>this.update())),this._listeners.add(window,"scroll",(()=>this.update())),this._listeners.add(t,"scroll",(()=>this.update()))}destroy(){this._listeners.removeAll()}update(t){t&&(this._anchors=t),this._updatePending||(this._updatePending=!0,requestAnimationFrame((()=>{const t=function(t){const e=[];return t.forEach((({annotation:t,highlights:n})=>{if(null==n||!n.length)return;const{top:o,bottom:i}=Re(n);o>=i||e.push({tag:t.$tag,top:o,
|
|
61
|
+
bottom:i})})),e.sort(((t,e)=>t.top-e.top)),e}(this._anchors);this._hostRPC.call("anchorsChanged",t),this._updatePending=!1})))}}function Pe(t){return t.split("").reverse().join("")}function Me(t){return(t|-t)>>31&1}function Ne(t,e,n,o){let i=t.P[n],r=t.M[n];const s=o>>>31,a=e[n]|s,c=a|r,l=(a&i)+i^i|a;let h=r|~(l|i),u=i&l;const d=Me(h&t.lastRowMask[n])-Me(u&t.lastRowMask[n]);return h<<=1,u<<=1,u|=s,h|=Me(o)-s,i=u|~(c|h),r=h&c,t.P[n]=i,t.M[n]=r,d}function Oe(t,e,n){if(0===e.length)return[];n=Math.min(n,e.length);const o=[],i=32,r=Math.ceil(e.length/i)-1,s={P:new Uint32Array(r+1),M:new Uint32Array(r+1),lastRowMask:new Uint32Array(r+1)};s.lastRowMask.fill(1<<31),s.lastRowMask[r]=1<<(e.length-1)%i;const a=new Uint32Array(r+1),c=new Map,l=[];for(let t=0;t<256;t++)l.push(a);for(let t=0;t<e.length;t+=1){const n=e.charCodeAt(t);if(c.has(n))continue;const o=new Uint32Array(r+1);c.set(n,o),n<l.length&&(l[n]=o);for(let t=0;t<=r;t+=1){o[t]=0;for(let r=0;r<i;r+=1){const s=t*i+r;if(s>=e.length)continue
|
|
62
|
+
;e.charCodeAt(s)===n&&(o[t]|=1<<r)}}}let h=Math.max(0,Math.ceil(n/i)-1);const u=new Uint32Array(r+1);for(let t=0;t<=h;t+=1)u[t]=(t+1)*i;u[r]=e.length;for(let t=0;t<=h;t+=1)s.P[t]=-1,s.M[t]=0;for(let d=0;d<t.length;d+=1){const f=t.charCodeAt(d);let p;f<l.length?p=l[f]:(p=c.get(f),void 0===p&&(p=a));let g=0;for(let t=0;t<=h;t+=1)g=Ne(s,p,t,g),u[t]+=g;if(u[h]-g<=n&&h<r&&(1&p[h+1]||g<0)){let t;if(h+=1,s.P[h]=-1,s.M[h]=0,h===r){const n=e.length%i;t=0===n?i:n}else t=i;u[h]=u[h-1]+t-g+Ne(s,p,h,g)}else for(;h>0&&u[h]>=n+i;)h-=1;h===r&&u[h]<=n&&(u[h]<n&&o.splice(0,o.length),o.push({start:-1,end:d+1,errors:u[h]}),n=u[h])}return o}function Ie(t,e,n){return function(t,e,n){const o=Pe(e);return n.map((n=>{const i=Math.max(0,n.end-e.length-n.errors);return{start:Oe(Pe(t.slice(i,n.end)),o,n.errors).reduce(((t,e)=>n.end-e.end<t?n.end-e.end:t),n.end),end:n.end,errors:n.errors}}))}(t,e,Oe(t,e,n))}function De(t,e,n){let o=0,i=[];for(;-1!==o;)o=t.indexOf(e,o),-1!==o&&(i.push({start:o,end:o+e.length,errors:0}),o+=1)
|
|
63
|
+
;return i.length>0?i:Ie(t,e,n)}function Be(t,e){if(0===e.length||0===t.length)return 0;return 1-De(t,e,e.length)[0].errors/e.length}function Fe(t,e,n={}){if(0===e.length)return null;const o=Math.min(256,e.length/2),i=De(t,e,o);if(0===i.length)return null;const r=o=>{const i=1-o.errors/e.length,r=n.prefix?Be(t.slice(Math.max(0,o.start-n.prefix.length),o.start),n.prefix):1,s=n.suffix?Be(t.slice(o.end,o.end+n.suffix.length),n.suffix):1;let a=1;if("number"==typeof n.hint){a=1-Math.abs(o.start-n.hint)/t.length}return(50*i+20*r+20*s+2*a)/92},s=i.map((t=>({start:t.start,end:t.end,score:r(t)})));return s.sort(((t,e)=>e.score-t.score)),s[0]}function He(t){const e=function(t){const e=t.nodeName.toLowerCase();let n=e;return"#text"===e&&(n="text()"),n}(t),n=function(t){let e=0,n=t;for(;n;)n.nodeName===t.nodeName&&(e+=1),n=n.previousSibling;return e}(t);return`${e}[${n}]`}function Ve(t,e){let n="",o=t;for(;o!==e;){if(!o)throw new Error("Node is not a descendant of root");n=He(o)+"/"+n,o=o.parentNode}return n="/"+n,
|
|
64
|
+
n=n.replace(/\/$/,""),n}function qe(t,e,n){e=e.toUpperCase();let o=-1;for(let i=0;i<t.children.length;i++){const r=t.children[i];if(r.nodeName.toUpperCase()===e&&(++o,o===n))return r}return null}function Ue(t,e=document.body){try{return function(t,e){if(null===t.match(/^(\/[A-Za-z0-9-]+(\[[0-9]+\])?)+$/))throw new Error("Expression is not a simple XPath");const n=t.split("/");let o=e;n.shift();for(let t of n){let e,n;const i=t.indexOf("[");if(-1!==i){e=t.slice(0,i);const o=t.slice(i+1,t.indexOf("]"));if(n=parseInt(o)-1,n<0)return null}else e=t,n=0;const r=qe(o,e,n);if(!r)return null;o=r}return o}(t,e)}catch(n){return document.evaluate("."+t,e,null,XPathResult.FIRST_ORDERED_NODE_TYPE,null).singleNodeValue}}class We{constructor(t,e){this.root=t,this.range=e}static fromRange(t,e){return new We(t,e)}static fromSelector(t,e){const n=Ue(e.startContainer,t);if(!n)throw new Error("Failed to resolve startContainer XPath");const o=Ue(e.endContainer,t);if(!o)throw new Error("Failed to resolve endContainer XPath")
|
|
65
|
+
;const i=me.fromCharOffset(n,e.startOffset),r=me.fromCharOffset(o,e.endOffset),s=new _e(i,r).toRange();return new We(t,s)}toRange(){return this.range}toSelector(){const t=_e.fromRange(this.range).toRange(),e=_e.fromRange(t),n=Ve(e.start.element,this.root),o=Ve(e.end.element,this.root);return{type:"RangeSelector",startContainer:n,startOffset:e.start.offset,endContainer:o,endOffset:e.end.offset}}}class ze{constructor(t,e,n){this.root=t,this.start=e,this.end=n}static fromRange(t,e){const n=_e.fromRange(e).relativeTo(t);return new ze(t,n.start.offset,n.end.offset)}static fromSelector(t,e){return new ze(t,e.start,e.end)}toSelector(){return{type:"TextPositionSelector",start:this.start,end:this.end}}toRange(){return _e.fromOffsets(this.root,this.start,this.end).toRange()}}class $e{constructor(t,e,n={}){this.root=t,this.exact=e,this.context=n}static fromRange(t,e){const n=t.textContent,o=_e.fromRange(e).relativeTo(t),i=o.start.offset,r=o.end.offset;return new $e(t,n.slice(i,r),{prefix:n.slice(Math.max(0,i-32),i),
|
|
66
|
+
suffix:n.slice(r,Math.min(n.length,r+32))})}static fromSelector(t,e){const{prefix:n,suffix:o}=e;return new $e(t,e.exact,{prefix:n,suffix:o})}toSelector(){return{type:"TextQuoteSelector",exact:this.exact,prefix:this.context.prefix,suffix:this.context.suffix}}toRange(t={}){return this.toPositionAnchor(t).toRange()}toPositionAnchor(t={}){const e=Fe(this.root.textContent,this.exact,{...this.context,hint:t.hint});if(!e)throw new Error("Quote not found");return new ze(this.root,e.start,e.end)}}async function je(t,e={}){return t.toRange(e)}function Xe(t,e,n={}){let o=null,i=null,r=null;for(let t of e)switch(t.type){case"TextPositionSelector":o=t,n.hint=o.start;break;case"TextQuoteSelector":i=t;break;case"RangeSelector":r=t}const s=t=>{var e;if(null!==(e=i)&&void 0!==e&&e.exact&&t.toString()!==i.exact)throw new Error("quote mismatch");return t};let a=Promise.reject("unable to anchor");if(r){const e=r;a=a.catch((()=>je(We.fromSelector(t,e),n).then(s)))}if(o){const e=o
|
|
67
|
+
;a=a.catch((()=>je(ze.fromSelector(t,e),n).then(s)))}if(i){const e=i;a=a.catch((()=>je($e.fromSelector(t,e),n)))}return a}function Ye(t,e){const n=[We,ze,$e],o=[];for(let i of n)try{const n=i.fromRange(t,e);o.push(n.toSelector())}catch(t){continue}return o}function Ge(t,e=document.baseURI){return new URL(t,e).href.toString().replace(/#.*/,"")}class Ze{constructor(t={}){this.document=t.document||document}uri(){let t=decodeURIComponent(this._getDocumentHref());const e=this._getLinks();for(let n of e)"canonical"===n.rel&&(t=n.href);return t}getDocumentMetadata(){const t={title:document.title,link:[],dc:this._getMetaTags("name","dc."),eprints:this._getMetaTags("name","eprints."),facebook:this._getMetaTags("property","og:"),highwire:this._getMetaTags("name","citation_"),prism:this._getMetaTags("name","prism."),twitter:this._getMetaTags("name","twitter:")},e=this._getFavicon();e&&(t.favicon=e),t.title=this._getTitle(t),t.link=this._getLinks(t);const n=t.link.find((t=>t.href.startsWith("urn:x-dc")))
|
|
68
|
+
;return n&&(t.documentFingerprint=n.href),t}_getMetaTags(t,e){const n={};for(let o of Array.from(this.document.querySelectorAll("meta"))){const i=o.getAttribute(t),{content:r}=o;if(i&&r){const t=i.match(RegExp(`^${e}(.+)$`,"i"));if(t){const e=t[1].toLowerCase();n[e]?n[e].push(r):n[e]=[r]}}}return n}_getTitle(t){return t.highwire.title?t.highwire.title[0]:t.eprints.title?t.eprints.title[0]:t.prism.title?t.prism.title[0]:t.facebook.title?t.facebook.title[0]:t.twitter.title?t.twitter.title[0]:t.dc.title?t.dc.title[0]:this.document.title}_getLinks(t={dc:{},highwire:{}}){const e=[{href:this._getDocumentHref()}],n=Array.from(this.document.querySelectorAll("link"));for(let t of n)if(["alternate","canonical","bookmark","shortlink"].includes(t.rel)){if("alternate"===t.rel){if(t.type&&t.type.match(/^application\/(rss|atom)\+xml/))continue;if(t.hreflang)continue}try{const n=this._absoluteUrl(t.href);e.push({href:n,rel:t.rel,type:t.type})}catch(t){}}for(let n of Object.keys(t.highwire)){const o=t.highwire[n]
|
|
69
|
+
;if("pdf_url"===n)for(let t of o)try{e.push({href:this._absoluteUrl(t),type:"application/pdf"})}catch(t){}if("doi"===n)for(let t of o)"doi:"!==t.slice(0,4)&&(t=`doi:${t}`),e.push({href:t})}for(let n of Object.keys(t.dc)){const o=t.dc[n];if("identifier"===n)for(let t of o)"doi:"===t.slice(0,4)&&e.push({href:t})}const o=t.dc["relation.ispartof"],i=t.dc.identifier;if(o&&i){const t=o[o.length-1],n=i[i.length-1],r="urn:x-dc:"+encodeURIComponent(t)+"/"+encodeURIComponent(n);e.push({href:r})}return e}_getFavicon(){let t=null;for(let e of Array.from(this.document.querySelectorAll("link")))if(["shortcut icon","icon"].includes(e.rel))try{t=this._absoluteUrl(e.href)}catch(t){}return t}_absoluteUrl(t){return Ge(t,this.document.baseURI)}_getDocumentHref(){const{href:t}=this.document.location,e=["http:","https:","file:"],n=new URL(t).protocol;return e.includes(n)?t:this.document.baseURI&&e.includes(new URL(this.document.baseURI).protocol)?this.document.baseURI:t}}function Ke(t){return t.width<=0||t.height<=0}
|
|
70
|
+
function Je(t,e,n,o){return Math.max(t,n)<Math.min(e,o)}function Qe(t,e){return!Ke(t)&&!Ke(e)&&(Je(t.left,t.right,e.left,e.right)&&Je(t.top,t.bottom,e.top,e.bottom))}function tn(t,e){return Je(t.top,t.bottom,e.top,e.bottom)}function en(t,e){return Je(t.left,t.right,e.left,e.right)}function nn(t,e){if(Ke(t))return e;if(Ke(e))return t;const n=Math.min(t.left,e.left),o=Math.min(t.top,e.top),i=Math.max(t.right,e.right),r=Math.max(t.bottom,e.bottom);return new DOMRect(n,o,i-n,r-o)}function on(t){return new DOMPoint((t.left+t.right)/2,(t.top+t.bottom)/2)}const rn=["p",".para"];let sn;function an(t,e=0,n=t.data.length){return sn||(sn=document.createRange()),sn.setStart(t,e),sn.setEnd(t,n),sn.getBoundingClientRect()}function cn(t){const e=t.getBoundingClientRect();return e.x-=t.scrollLeft,e.y-=t.scrollTop,e.height=Math.max(e.height,t.scrollHeight),e.width=Math.max(e.width,t.scrollWidth),e}function*ln(t,e,n=(()=>!0)){let o=t.firstChild;for(;o;){if(o.nodeType===Node.ELEMENT_NODE){const t=o,i=Qe(cn(t),e)
|
|
71
|
+
;n(t)&&i&&(yield*ln(t,e,n))}else if(o.nodeType===Node.TEXT_NODE){const t=o;Qe(an(t),e)&&(yield t)}o=o.nextSibling}}function hn(t,e){let n=null;const o=t=>!function(t){switch(getComputedStyle(t).position){case"fixed":case"sticky":return!0;default:return!1}}(t);t:for(let s of ln(t,e,o)){let t=0;for(let o of s.data.split(/\b/)){if(/\S/.test(o)){const a=t,c=t+o.length,l=an(s,a,c);if(r=l,!Ke(i=e)&&!Ke(r)&&r.left>=i.left&&r.right<=i.right&&r.top>=i.top&&r.bottom<=i.bottom){n=document.createRange(),n.setStart(s,a),n.setEnd(s,c);break t}}t+=o.length}}var i,r;return n}function un(t,e=document.documentElement,n=new DOMRect(0,0,window.innerWidth,window.innerHeight)){const o=hn(e,n);if(!o)return t(),0;const i=o.getBoundingClientRect().top;t();const r=o.getBoundingClientRect().top-i;return e.scrollTop+=r,r}var dn="complete",fn="canceled";function pn(t,e,n){t.self===t?t.scrollTo(e,n):(t.scrollLeft=e,t.scrollTop=n)}function gn(t){var e=t._scrollSettings;if(e){var n=e.maxSynchronousAlignments,o=function(t,e){
|
|
72
|
+
var n,o,i,r,s,a,c,l=t.align,h=t.target.getBoundingClientRect(),u=l&&null!=l.left?l.left:.5,d=l&&null!=l.top?l.top:.5,f=l&&null!=l.leftOffset?l.leftOffset:0,p=l&&null!=l.topOffset?l.topOffset:0,g=u,m=d;if(t.isWindow(e))a=Math.min(h.width,e.innerWidth),c=Math.min(h.height,e.innerHeight),o=h.left+e.pageXOffset-e.innerWidth*g+a*g,i=h.top+e.pageYOffset-e.innerHeight*m+c*m,o-=f,i-=p,o=t.align.lockX?e.pageXOffset:o,i=t.align.lockY?e.pageYOffset:i,r=o-e.pageXOffset,s=i-e.pageYOffset;else{a=h.width,c=h.height,n=e.getBoundingClientRect();var _=h.left-(n.left-e.scrollLeft),v=h.top-(n.top-e.scrollTop);o=_+a*g-e.clientWidth*g,i=v+c*m-e.clientHeight*m,o-=f,i-=p,o=Math.max(Math.min(o,e.scrollWidth-e.clientWidth),0),i=Math.max(Math.min(i,e.scrollHeight-e.clientHeight),0),o=t.align.lockX?e.scrollLeft:o,i=t.align.lockY?e.scrollTop:i,r=o-e.scrollLeft,s=i-e.scrollTop}return{x:o,y:i,differenceX:r,differenceY:s}}(e,t),i=Date.now()-e.startTime,r=Math.min(1/e.time*i,1);if(e.endIterations>=n)return pn(t,o.x,o.y),
|
|
73
|
+
t._scrollSettings=null,e.end(dn);var s=1-e.ease(r);if(pn(t,o.x-o.differenceX*s,o.y-o.differenceY*s),i>=e.time)return e.endIterations++,e.scrollAncestor&&gn(e.scrollAncestor),void gn(t);!function(t){if("requestAnimationFrame"in window)return window.requestAnimationFrame(t);setTimeout(t,16)}(gn.bind(null,t))}}function mn(t){return t.self===t}function _n(t){return"pageXOffset"in t||(t.scrollHeight!==t.clientHeight||t.scrollWidth!==t.clientWidth)&&"hidden"!==getComputedStyle(t).overflow}function vn(){return!0}function yn(t){if(t.assignedSlot)return yn(t.assignedSlot);if(t.parentElement)return"BODY"===t.parentElement.tagName?t.parentElement.ownerDocument.defaultView||t.parentElement.ownerDocument.ownerWindow:t.parentElement;if(t.getRootNode){var e=t.getRootNode();if(11===e.nodeType)return e.host}}var wn=function(t,e,n){if(t){"function"==typeof e&&(n=e,e=null),e||(e={}),e.time=isNaN(e.time)?1e3:e.time,e.ease=e.ease||function(t){return 1-Math.pow(1-t,t/2)},e.align=e.align||{}
|
|
74
|
+
;var o=yn(t),i=1,r=e.validTarget||vn,s=e.isScrollable;e.debug&&(console.log("About to scroll to",t),o||console.error("Target did not have a parent, is it mounted in the DOM?"));for(var a=[];o;)if(e.debug&&console.log("Scrolling parent node",o),r(o,i)&&(s?s(o,_n):_n(o))&&(i++,a.push(o)),!(o=yn(o))){c(dn);break}return a.reduce(((n,o,i)=>function(t,e,n,o,i){var r,s=!e._scrollSettings,a=e._scrollSettings,c=Date.now(),l={passive:!0};function h(t){e._scrollSettings=null,e.parentElement&&e.parentElement._scrollSettings&&e.parentElement._scrollSettings.end(t),n.debug&&console.log("Scrolling ended with type",t,"for",e),i(t),r&&(e.removeEventListener("touchstart",r,l),e.removeEventListener("wheel",r,l))}a&&a.end(fn);var u=n.maxSynchronousAlignments;return null==u&&(u=3),e._scrollSettings={startTime:c,endIterations:0,target:t,time:n.time,ease:n.ease,align:n.align,isWindow:n.isWindow||mn,maxSynchronousAlignments:u,end:h,scrollAncestor:o},"cancellable"in n&&!n.cancellable||(r=h.bind(null,fn),
|
|
75
|
+
e.addEventListener("touchstart",r,l),e.addEventListener("wheel",r,l)),s&&gn(e),r}(t,o,e,a[i+1],c)),null)}function c(t){--i||n&&n(t)}};function bn(t,e,n){return t+n*(e-t)}async function Cn(t,e,{maxDuration:n=500}={}){const o=t.scrollTop,i=e,r=Date.now(),s=Math.min(Math.abs(i-o)/3,n);let a=0;for(;a<1;)await new Promise((t=>{requestAnimationFrame(t)})),a=Math.min(1,(Date.now()-r)/s),t.scrollTop=bn(o,i,a)}class xn{constructor(t=document.body){this.container=t,this.anchor=Xe,this.describe=Ye,this._htmlMeta=new Ze,this.sideBySideEnabled=!1}canAnnotate(){return!0}destroy(){}contentContainer(){return this.container}fitSideBySide(t){const e=window.innerWidth-t.width,n=t.expanded&&e>=480;return!!this.sideBySideEnabled&&(n?(this._activateSideBySide(t.width),!0):(this._deactivateSideBySide(),!1))}_activateSideBySide(t){const e=t+12,n=t=>parseInt(window.getComputedStyle(t).marginLeft,10);un((()=>{document.body.style.marginLeft="",document.body.style.marginRight="";const t=n(document.body)
|
|
76
|
+
;document.body.style.marginRight=`${e}px`;const o=function(t){const e=new Map,n=new Map,o=rn.join(","),i=Array.from(t.querySelectorAll(o)).map((t=>({rect:t.getBoundingClientRect(),textLength:t.textContent.length}))).filter((({rect:t})=>t.width>0&&t.height>0)).sort(((t,e)=>e.textLength-t.textLength)).slice(0,15);if(i.forEach((({rect:t})=>{var o,i;let r=null!==(o=e.get(t.left))&&void 0!==o?o:0;r+=1,e.set(t.left,r);let s=null!==(i=n.get(t.right))&&void 0!==i?i:0;s+=1,n.set(t.right,s)})),0===e.size||0===n.size)return null;const r=[...e.entries()].sort(((t,e)=>e[1]-t[1])),s=[...n.entries()].sort(((t,e)=>e[1]-t[1])),[a]=r[0],[c]=s[0];return{left:a,right:c}}(document.body);if(o){const i=Math.max(0,window.innerWidth-e-o.right);if(i>0){const t=Math.max(0,e-i);document.body.style.marginRight=`${t}px`}n(document.body)>t&&(document.body.style.marginLeft=`${t}px`),o.left<12&&(document.body.style.marginLeft="12px")}else document.body.style.marginLeft="",document.body.style.marginRight=""}))}_deactivateSideBySide(){
|
|
77
|
+
un((()=>{document.body.style.marginLeft="",document.body.style.marginRight=""}))}async getMetadata(){return this._htmlMeta.getDocumentMetadata()}async uri(){return this._htmlMeta.uri()}async scrollToAnchor(t){var e;const n=null===(e=t.highlights)||void 0===e?void 0:e[0];n&&await async function(t,{maxDuration:e=500}={}){const n=t.closest("body");n&&"BODY"!==n.tagName&&Object.defineProperty(n,"tagName",{value:"BODY",configurable:!0}),await new Promise((n=>wn(t,{time:e},n)))}(n)}}var Sn=/^\s+|\s+$/g,En=/^[-+]0x[0-9a-f]+$/i,Tn=/^0b[01]+$/i,An=/^0o[0-7]+$/i,kn=parseInt,Rn="object"==typeof t&&t&&t.Object===Object&&t,Ln="object"==typeof self&&self&&self.Object===Object&&self,Pn=Rn||Ln||Function("return this")(),Mn=Object.prototype.toString,Nn=Math.max,On=Math.min,In=function(){return Pn.Date.now()};function Dn(t){var e=typeof t;return!!t&&("object"==e||"function"==e)}function Bn(t){if("number"==typeof t)return t;if(function(t){return"symbol"==typeof t||function(t){return!!t&&"object"==typeof t
|
|
78
|
+
}(t)&&"[object Symbol]"==Mn.call(t)}(t))return NaN;if(Dn(t)){var e="function"==typeof t.valueOf?t.valueOf():t;t=Dn(e)?e+"":e}if("string"!=typeof t)return 0===t?t:+t;t=t.replace(Sn,"");var n=Tn.test(t);return n||An.test(t)?kn(t.slice(2),n?2:8):En.test(t)?NaN:+t}var Fn=function(t,e,n){var o,i,r,s,a,c,l=0,h=!1,u=!1,d=!0;if("function"!=typeof t)throw new TypeError("Expected a function");function f(e){var n=o,r=i;return o=i=void 0,l=e,s=t.apply(r,n)}function p(t){return l=t,a=setTimeout(m,e),h?f(t):s}function g(t){var n=t-c;return void 0===c||n>=e||n<0||u&&t-l>=r}function m(){var t=In();if(g(t))return _(t);a=setTimeout(m,function(t){var n=e-(t-c);return u?On(n,r-(t-l)):n}(t))}function _(t){return a=void 0,d&&o?f(t):(o=i=void 0,s)}function v(){var t=In(),n=g(t);if(o=arguments,i=this,c=t,n){if(void 0===a)return p(c);if(u)return a=setTimeout(m,e),f(c)}return void 0===a&&(a=setTimeout(m,e)),s}return e=Bn(e)||0,Dn(n)&&(h=!!n.leading,r=(u="maxWait"in n)?Nn(Bn(n.maxWait)||0,e):r,d="trailing"in n?!!n.trailing:d),
|
|
79
|
+
v.cancel=function(){void 0!==a&&clearTimeout(a),l=0,o=c=i=a=void 0},v.flush=function(){return void 0===a?s:_(In())},v};let Hn=new Set;function Vn(...t){const e=t.join();Hn.has(e)||(console.warn(...t),Hn.add(e))}function qn(t,e,n,o=0){let i=o;for(;i<t.length&&e>0;)n(t[i])&&--e,++i;return i}function Un(t,e,n,o){let i=0;for(let r=n;r<o;r++)e(t[r])&&++i;return i}function Wn(t,e,n,o,i){const r=Un(t,i,0,n),s=Un(t,i,n,o);let a=qn(e,r,i);for(;a<e.length&&!i(e[a]);)++a;return[a,qn(e,s,i,a)]}Vn.reset=()=>{Hn.clear()};const zn=0,$n=3,jn=new Map,Xn=new Map;function Yn(t,e){return`${t}:${e}`}function Gn(t){var e;const n="closest"in t?t:t.parentElement;return null!==(e=null==n?void 0:n.closest(".textLayer"))&&void 0!==e?e:null}function Zn(){return PDFViewerApplication.pdfViewer}async function Kn(t){const e=Zn();let n=e.getPageView(t);return n&&n.pdfPage||(n=await new Promise((n=>{const o=()=>{e.eventBus?e.eventBus.off("pagesloaded",o):document.removeEventListener("pagesloaded",o),n(e.getPageView(t))}
|
|
80
|
+
;e.eventBus?e.eventBus.on("pagesloaded",o):document.addEventListener("pagesloaded",o)}))),n}function Jn(t){const e=jn.get(t);if(e)return e;const n=(async()=>{const e=await Kn(t);return(await e.pdfPage.getTextContent({normalizeWhitespace:!0})).items.map((t=>t.str)).join("")})();return jn.set(t,n),n}async function Qn(t){const e=Zn();let n=0,o=0,i="";for(let r=0;r<e.pagesCount;r++)if(i=await Jn(r),n=o,o+=i.length,o>=t)return{index:r,offset:n,text:i};return{index:e.pagesCount-1,offset:n,text:i}}function to(t){switch(t){case" ":case"\f":case"\n":case"\r":case"\t":case"\v":case" ":return!0;default:return!1}}const eo=t=>!to(t);async function no(t,e,n){const[o,i]=await Promise.all([Kn(t),Jn(t)]);if(o.renderingState===$n&&o.textLayer&&o.textLayer.renderingDone){const t=o.textLayer.textLayerDiv,r=t.textContent,[s,a]=Wn(i,r,e,n,eo);oo(r.slice(s,a))!==oo(i.slice(e,n))&&Vn("Text layer text does not match page text. Highlights will be mis-aligned.");const c=new me(t,s),l=new me(t,a);return new _e(c,l).toRange()}
|
|
81
|
+
const r=function(t){let e=t.querySelector(ve);return e||(e=document.createElement("span"),e.classList.add("annotator-placeholder"),e.textContent="Loading annotations...",t.appendChild(e),e)}(o.div),s=document.createRange();return s.setStartBefore(r),s.setEndAfter(r),s}function oo(t){let e="";for(let n=0;n<t.length;n++){const o=t[n];to(o)||(e+=o)}return e}async function io(t,e){const n=e.find((t=>"TextQuoteSelector"===t.type));if(!n)throw new Error("No quote selector found");const o=e.find((t=>"TextPositionSelector"===t.type));if(o){try{const{index:t,offset:e,text:i}=await Qn(o.start),r=o.start-e,s=o.end-e,a=i.substring(r,s);if(n.exact!==a)throw new Error("quote mismatch");return await no(t,r,s)}catch{}try{const t=Yn(n.exact,o.start),e=Xn.get(t);if(e){const{pageIndex:t,anchor:n}=e;return await no(t,n.start,n.end)}}catch{}}return async function(t,e){const n=Zn().pagesCount,o=Array(n).fill(0).map(((t,e)=>e));let i,r;if(e){const{index:t,offset:n}=await Qn(e);i=t,r=e-n,o.sort(((e,n)=>Math.abs(e-t)-Math.abs(n-t)))}
|
|
82
|
+
const s=void 0!==t.prefix?oo(t.prefix):void 0,a=void 0!==t.suffix?oo(t.suffix):void 0,c=oo(t.exact);let l;for(let t of o){const e=await Jn(t),n=oo(e);let o;void 0!==i&&void 0!==r&&(t<i?o=n.length:t===i?[o]=Wn(e,n,r,r,eo):o=0);const h=Fe(n,c,{prefix:s,suffix:a,hint:o});if(h&&(!l||h.score>l.match.score)){const[o,i]=Wn(n,e,h.start,h.end,eo);l={page:t,match:{start:o,end:i,score:h.score}};const r=n.slice(h.start,h.end)===c,u=void 0!==s&&n.slice(Math.max(0,h.start-s.length),h.start)===s,d=void 0!==a&&n.slice(h.end,a.length)===a,f=void 0!==s||void 0!==a;if(r&&(u||d||!f))break}}if(l){const{page:n,match:o}=l;if(e){const i=Yn(t.exact,e);Xn.set(i,{pageIndex:n,anchor:o})}return no(n,o.start,o.end)}throw new Error("Quote not found")}(n,null==o?void 0:o.start)}function ro(t){try{t=_e.fromRange(t).toRange()}catch{throw new Error("Selection does not contain text")}const e=Gn(t.startContainer),n=Gn(t.endContainer);if(!e||!n)throw new Error("Selection is outside page text")
|
|
83
|
+
;if(e!==n)throw new Error("Selecting across page breaks is not supported");return[t,e]}async function so(t,e){const[n,o]=ro(e),i=me.fromPoint(n.startContainer,n.startOffset).relativeTo(o),r=me.fromPoint(n.endContainer,n.endOffset).relativeTo(o),s=function(t){let e=0;for(;t.previousSibling;)++e,t=t.previousSibling;return e}(o.parentNode),a=await async function(t){if(t>=Zn().pagesCount)throw new Error("Invalid page index");let e=0;for(let n=0;n<t;n++)e+=(await Jn(n)).length;return e}(s);return[{type:"TextPositionSelector",start:a+i.offset,end:a+r.offset},$e.fromRange(t,n).toSelector()]}function ao({children:t}){return mt("div",{className:"flex flex-col",children:t})}function co({provider:t,onClose:e}){return mt("div",{className:"flex items-center border-b gap-x-4 px-2 py-1 bg-white text-annotator-lg",children:["jstor"===t&&mt(f,{children:[mt(Tt,{href:"https://jstor.org",target:"_blank",children:mt(Et,{classes:"w-[97px] h-[25px]",name:"jstor",title:"Document hosted by JSTOR"})}),mt("div",{className:"grow",
|
|
84
|
+
children:["Document hosted by ",mt("b",{children:"JSTOR"})]})]}),mt("div",{className:"text-annotator-base",children:mt(xt,{onClick:e,"data-testid":"close-button",children:"Close"})})]})}function lo(){return mt("div",{className:"bg-white",children:mt("div",{className:Z("flex items-center gap-x-2","border border-yellow-notice bg-yellow-notice/10 text-annotator-base"),children:[mt("div",{className:"bg-yellow-notice text-white p-2",children:mt(Et,{name:"caution",classes:"text-annotator-xl"})}),mt("div",{children:[mt("strong",{children:"This PDF does not contain selectable text:"})," ",mt(Tt,{target:"_blank",href:"https://web.hypothes.is/help/how-to-ocr-optimize-pdfs/",children:"Learn how to fix this"})," ","in order to annotate with Hypothesis."]})]})})}class ho{constructor(t){this._loaded=function(t){return t.initializedPromise?t.initializedPromise:t.initialized?Promise.resolve():new Promise((e=>{const n=setInterval((()=>{t.initialized&&(clearTimeout(n),e())}),5)}))
|
|
85
|
+
}(t).then((()=>t.downloadComplete?t:new Promise((e=>{const n=()=>{t.eventBus?(t.eventBus.off("documentload",n),t.eventBus.off("documentloaded",n)):window.removeEventListener("documentload",n),e(t)};t.eventBus?(t.eventBus.on("documentloaded",n),t.eventBus.on("documentload",n)):window.addEventListener("documentload",n)}))))}getUri(){return this._loaded.then((t=>{let e=po(t);return e||(e=fo(uo(t))),e}))}async getMetadata(){const t=await this._loaded,{info:e,contentDispositionFilename:n,metadata:o}=await t.pdfDocument.getMetadata(),i=uo(t),r=po(t);let s;s=null!=o&&o.has("dc:title")&&"Untitled"!==o.get("dc:title")?o.get("dc:title"):null!=e&&e.Title?e.Title:n||(r?function(t){const e=new URL(t).pathname.split("/");return e[e.length-1]}(r):"");const a=[{href:fo(i)}];return r&&a.push({href:r}),{title:s,link:a,documentFingerprint:i}}}function uo(t){return Array.isArray(t.pdfDocument.fingerprints)?t.pdfDocument.fingerprints[0]:t.pdfDocument.fingerprint}function fo(t){return`urn:x-pdf:${t}`}function po(t){
|
|
86
|
+
if(!t.url)return null;const e=Ge(t.url);return 0!==e.indexOf("file://")?e:null}function go(t){var e;const n=null===(e=t.highlights)||void 0===e?void 0:e[0];return n&&ye(n)}function mo(t){return new Promise((e=>setTimeout(e,t)))}class _o{constructor(t,e={}){var n,o,i,r;this.annotator=t;const s=window,a=s.PDFViewerApplication;this.pdfViewer=a.pdfViewer,this.pdfViewer.viewer.classList.add("has-transparent-text-layer"),this.pdfContainer=null!==(n=null===(o=a.appConfig)||void 0===o?void 0:o.appContainer)&&void 0!==n?n:document.body,this.pdfMetadata=new ho(a),this.observer=new MutationObserver(Fn((()=>this._update()),100)),this.observer.observe(this.pdfViewer.viewer,{attributes:!0,attributeFilter:["data-loaded"],childList:!0,subtree:!0}),this._reanchoringMaxWait=null!==(i=e.reanchoringMaxWait)&&void 0!==i?i:3e3,this._banner=null,this._bannerState={contentPartner:null!==(r=e.contentPartner)&&void 0!==r?r:null,noTextWarning:!1},this._updateBannerState(this._bannerState),this._checkForSelectableText(),
|
|
87
|
+
this._updateAnnotationLayerVisibility=()=>{const t=s.getSelection();this.pdfViewer.viewer.classList.toggle("is-selecting",!t.isCollapsed)},this._listeners=new kt,this._listeners.add(document,"selectionchange",this._updateAnnotationLayerVisibility),this._destroyed=!1}destroy(){var t;this._listeners.removeAll(),this.pdfViewer.viewer.classList.remove("has-transparent-text-layer"),this.observer.disconnect(),null===(t=this._banner)||void 0===t||t.remove(),this._destroyed=!0}uri(){return this.pdfMetadata.getUri()}getMetadata(){return this.pdfMetadata.getMetadata()}anchor(t,e){return io(0,e)}canAnnotate(t){return function(t){try{return ro(t),!0}catch{return!1}}(t)}describe(t,e){return so(t,e)}async _checkForSelectableText(){try{await this.uri()}catch(t){return}if(!this._destroyed)try{const t=await async function(){const t=Zn();let e=!1;for(let n=0;n<t.pagesCount;n++)if((await Jn(n)).trim().length>0){e=!0;break}return e}();this._updateBannerState({noTextWarning:!t})}catch(t){
|
|
88
|
+
console.warn("Unable to check for text in PDF:",t)}}_updateBannerState(t){this._bannerState={...this._bannerState,...t};const e=document.querySelector("#outerContainer");var n;if(!(this._bannerState.contentPartner||this._bannerState.noTextWarning))return null===(n=this._banner)||void 0===n||n.remove(),this._banner=null,void(e.style.height="");this._banner||(this._banner=document.createElement("hypothesis-banner"),document.body.prepend(this._banner),he(this._banner)),M(mt(ao,{children:[this._bannerState.contentPartner&&mt(co,{provider:this._bannerState.contentPartner,onClose:()=>this._updateBannerState({contentPartner:null})}),this._bannerState.noTextWarning&&mt(lo,{})]}),this._banner.shadowRoot);const o=this._banner.getBoundingClientRect().height;e.style.height=`calc(100% - ${o}px)`}_update(){const t=[],e=this.pdfViewer.pagesCount;for(let t=0;t<e;t++){var n;const e=this.pdfViewer.getPageView(t);if(null!=e&&null!==(n=e.textLayer)&&void 0!==n&&n.renderingDone)switch(e.renderingState){case zn:e.textLayer=null
|
|
89
|
+
;break;case $n:o=e.div,i=void 0,null===(i=o.querySelector(ve))||void 0===i||i.remove()}}var o,i;for(let e of this.annotator.anchors)if(e.highlights){if(t.includes(e.annotation))continue;for(let n=0;n<e.highlights.length;n++){const o=e.highlights[n];if(!document.body.contains(o)){e.highlights.splice(n,1),delete e.range,t.push(e.annotation);break}}}t.map((t=>this.annotator.anchor(t)))}contentContainer(){return document.querySelector("#viewerContainer")}fitSideBySide(t){const e=window.innerWidth-t.width,n=t.expanded&&e>=680,o=n?t.width:t.toolbarWidth;this.pdfContainer.style.width=`calc(100% - ${o}px)`;const i=this.pdfViewer.currentScaleValue;return"auto"!==i&&"page-fit"!==i&&"page-width"!==i||(this.pdfViewer.currentScaleValue=i),this.pdfViewer.update(),n}async scrollToAnchor(t){const e=t.annotation,n=go(t),o=this._anchorOffset(t);if(null!==o&&(await Cn(this.contentContainer(),o),n)){const t=await this._waitForAnnotationToBeAnchored(e,this._reanchoringMaxWait);if(!t)return;const n=this._anchorOffset(t)
|
|
90
|
+
;if(null===n)return;await Cn(this.contentContainer(),n)}}async _waitForAnnotationToBeAnchored(t,e){var n;const o=Date.now();let i;do{i=this.annotator.anchors.find((e=>e.annotation===t)),i&&!go(i)||(i=null,await mo(20))}while(!i&&Date.now()-o<e);return null!==(n=i)&&void 0!==n?n:null}_anchorOffset(t){if(!t.highlights)return null;return function(t,e){let n=0;for(;t!==e&&e.contains(t);)n+=t.offsetTop,t=t.offsetParent;return n}(t.highlights[0],this.contentContainer())}}class vo{constructor(t,e,n){this._element=t,this._onFrameAdded=e,this._onFrameRemoved=n,this._annotatableFrames=new Set,this._isDisconnected=!1,this._mutationObserver=new MutationObserver(Fn((()=>{this._discoverFrames()}),40)),this._discoverFrames(),this._mutationObserver.observe(this._element,{childList:!0,subtree:!0,attributeFilter:["enable-annotation"]})}disconnect(){this._isDisconnected=!0,this._mutationObserver.disconnect()}async _addFrame(t){this._annotatableFrames.add(t);try{if(await yo(t),this._isDisconnected)return
|
|
91
|
+
;t.contentWindow.addEventListener("unload",(()=>{this._removeFrame(t)})),this._onFrameAdded(t)}catch(e){console.warn(`Unable to inject the Hypothesis client (from '${document.location.href}' into a cross-origin frame '${t.src}')`)}}_removeFrame(t){this._annotatableFrames.delete(t),this._onFrameRemoved(t)}_discoverFrames(){const t=new Set(this._element.querySelectorAll("iframe[enable-annotation]"));for(let e of t)this._annotatableFrames.has(e)||this._addFrame(e);for(let e of this._annotatableFrames)t.has(e)||this._removeFrame(e)}}function yo(t){return new Promise(((e,n)=>{const o=wo(t,((t,i)=>{o(),i?e(i):n(t)}))}))}function wo(t,e,{pollInterval:n=10}={}){let o,i;const r=new WeakSet,s=()=>{clearTimeout(o),o=void 0},a=()=>{const n=t.contentDocument;if(n){if(!r.has(n)){if(r.add(n),s(),!function(t){var e;return"about:blank"===(null===(e=t.contentDocument)||void 0===e?void 0:e.location.href)&&t.hasAttribute("src")&&"about:blank"!==t.src}(t)){
|
|
92
|
+
"interactive"===n.readyState||"complete"===n.readyState?e(null,n):n.addEventListener("DOMContentLoaded",(()=>e(null,n)))}var o;t.contentDocument&&(null===(o=t.contentWindow)||void 0===o||o.addEventListener("unload",i))}}else e(new Error("Frame is cross-origin"))};let c=!1;i=()=>{s(),c||(o=setInterval(a,n))},t.addEventListener("load",a);const l=setTimeout(a,0);return()=>{c=!0,clearTimeout(l),s(),t.removeEventListener("load",a)}}class bo{constructor(t,e,n){if(e.length!==n.length)throw new Error("Char boxes length does not match text length");const o=t.parentNode,i=document.createElement("hypothesis-text-layer");o.insertBefore(i,t.nextSibling),o.style.position="relative",i.style.position="absolute",i.style.top="0",i.style.left="0",i.style.color="transparent",i.style.textAlign="left",i.style.mixBlendMode="multiply";const r="sans-serif";i.style.fontSize="16px",i.style.fontFamily=r;const s=document.createElement("canvas").getContext("2d");s.font="16px sans-serif"
|
|
93
|
+
;const a=(t,e,n="px")=>`calc(var(--${t}-scale) * ${e}${n})`,c=function(t,e){const n=[];let o={text:"",rect:new DOMRect};const i=()=>{o.text.length>0&&(n.push(o),o={text:"",rect:new DOMRect})};for(let[n,r]of t.entries()){const t=e[n],s=/\s/.test(t);o.rect=nn(o.rect,r),o.text+=s?" ":t,s&&i()}i();const r=[];let s={words:[],rect:new DOMRect};const a=()=>{s.words.length>0&&(r.push(s),s={words:[],rect:new DOMRect})};for(let t of n){const e=s.words[s.words.length-1];if(e){const n=on(e.rect),o=on(t.rect).x-n.x;(!tn(e.rect,t.rect)||o<0)&&a()}s.words.push(t),s.rect=nn(s.rect,t.rect)}a();const c=[];let l={lines:[],rect:new DOMRect};const h=()=>{l.lines.length>0&&(c.push(l),l={lines:[],rect:new DOMRect})};for(let t of r){const e=l.lines[l.lines.length-1];if(e){const n=on(e.rect),o=on(t.rect).y-n.y;(!en(e.rect,t.rect)||tn(e.rect,t.rect)||o<0||o>4*t.rect.height)&&h()}l.lines.push(t),l.rect=nn(l.rect,t.rect)}return h(),c}(e,n);for(let t of c){const e=document.createElement("hypothesis-text-column");e.style.display="block",
|
|
94
|
+
e.style.position="absolute",e.style.left=a("x",t.rect.left),e.style.top=a("y",t.rect.top);let n=null;for(let o of t.lines){const i=document.createElement("hypothesis-text-line");i.style.display="block",i.style.marginLeft=a("x",o.rect.left-t.rect.left),i.style.height=a("y",o.rect.height),n&&(i.style.marginTop=a("y",o.rect.top-n.rect.bottom)),n=o,i.style.whiteSpace="nowrap";let r=null;for(let t of o.words){const e=document.createElement("hypothesis-text-word");e.style.display="inline-block",e.style.transformOrigin="top left",e.textContent=t.text,r&&(e.style.marginLeft=a("x",t.rect.left-r.rect.right)),r=t,e.style.width=a("x",t.rect.width),e.style.height=a("y",t.rect.height),e.style.whiteSpace="pre";const n=s.measureText(t.text),o=a("x",t.rect.width/n.width,""),c=a("y",t.rect.height/16,"");e.style.transform=`scale(${o}, ${c})`,i.append(e)}e.append(i)}i.append(e)}const l=()=>{const{width:e,height:n}=t.getBoundingClientRect();i.style.width=e+"px",i.style.height=n+"px",i.style.setProperty("--x-scale",`${e}`),
|
|
95
|
+
i.style.setProperty("--y-scale",`${n}`)};l(),this.container=i,this._updateTextLayerSize=Fn(l,{maxWait:50}),this._listeners=new kt,"undefined"!=typeof ResizeObserver&&(this._imageSizeObserver=new ResizeObserver((()=>{this._updateTextLayerSize()})),this._imageSizeObserver.observe(t)),this._listeners.add(window,"resize",this._updateTextLayerSize)}updateSync(){this._updateTextLayerSize(),this._updateTextLayerSize.flush()}destroy(){var t;this.container.remove(),this._listeners.removeAll(),this._updateTextLayerSize.cancel(),null===(t=this._imageSizeObserver)||void 0===t||t.disconnect()}}class Co{constructor(t,e){this._config=e,this._frameObserver=new vo(t,(t=>xo(t,e)),(()=>{}))}destroy(){this._frameObserver.disconnect()}}async function xo(t,e){if(null!==t.contentDocument.querySelector("script.js-hypothesis-config"))return;await yo(t);const{assetRoot:n,notebookAppUrl:o,sidebarAppUrl:i}=Yt(document),r={...e,assetRoot:n,notebookAppUrl:o,sidebarAppUrl:i,subFrameIdentifier:Lt(10)},s=document.createElement("script")
|
|
96
|
+
;s.className="js-hypothesis-config",s.type="application/json",s.innerText=JSON.stringify(r);const a=document.createElement("script");a.async=!0,a.src=e.clientUrl;const c=t.contentDocument;c.body.appendChild(s),c.body.appendChild(a)}function So(t=document){return t.querySelector("mosaic-book")}function Eo(t=window){var e;if(So(t.document))return"container";const n=null===(e=t.frameElement)||void 0===e?void 0:e.ownerDocument;return n&&So(n)?"content":null}class To{constructor(t){const e=So();if(!e)throw new Error("Book container element not found");const n=new WeakSet,o=e.shadowRoot,i=()=>{const e=o.querySelector("iframe");e&&!n.has(e)&&(n.add(e),wo(e,((n,o)=>{const i=null==o?void 0:o.body;i&&!i.querySelector("#page-content")&&xo(e,t)})))};i(),this._frameObserver=new MutationObserver(i),this._frameObserver.observe(o,{childList:!0,subtree:!0})}destroy(){this._frameObserver.disconnect()}}function Ao(){return document.querySelector("img#pbk-page")}class ko{constructor(t=document.body){
|
|
97
|
+
this._htmlIntegration=new xn(t),this._htmlIntegration.sideBySideEnabled=!0,this._listeners=new kt;const e=["mouseup","mousedown","mouseout"];for(let t of e)this._listeners.add(document.documentElement,t,(t=>{t.stopPropagation()}));const n=window.frameElement;n&&function(t){if("no"!==t.getAttribute("scrolling"))return;const e=document.createElement("style");e.textContent="iframe { height: 100% !important; }",t.insertAdjacentElement("beforebegin",e);const n=()=>t.removeAttribute("scrolling");n(),new MutationObserver(n).observe(t,{attributes:!0})}(n);const o=Ao(),i=window.innerPageData;if(o&&i){const t=i.glyphs.glyphs.map((t=>{const e=t.l/100,n=t.r/100,o=t.t/100,i=t.b/100;return new DOMRect(e,o,n-e,i-o)}));this._textLayer=new bo(o,t,i.words),this._textLayer.container.style.zIndex="100"}}canAnnotate(){return!0}destroy(){var t;null===(t=this._textLayer)||void 0===t||t.destroy(),this._listeners.removeAll(),this._htmlIntegration.destroy()}anchor(t,e){return this._htmlIntegration.anchor(t,e)}describe(t,e){
|
|
98
|
+
return this._htmlIntegration.describe(t,e)}contentContainer(){return this._htmlIntegration.contentContainer()}fitSideBySide(t){const e=Ao();if(e&&this._textLayer){const n=e.parentElement,o=this._textLayer,i=window.innerWidth-t.width;return un((()=>{t.expanded&&i>480?(n.style.textAlign="left",e.style.width=`${i}px`):(n.style.textAlign="",e.style.width=""),o.updateSync()})),t.expanded}return this._htmlIntegration.fitSideBySide(t)}async getMetadata(){return{title:document.title,link:[]}}async uri(){const t=new URL(document.location.href);return t.search="",t.toString()}async scrollToAnchor(t){return this._htmlIntegration.scrollToAnchor(t)}}function Ro(t,{contentPartner:e}={}){if("undefined"!=typeof PDFViewerApplication)return new _o(t,{contentPartner:e});return"content"===Eo()?new ko:new xn}function Lo(t){const e=t.getSelection();if(!e||0===e.rangeCount)return null;const n=e.getRangeAt(0);return n.collapsed?null:n}class Po{constructor(t,e=document){let n=!1;this._pendingCallback=null;const o=(n=10)=>{
|
|
99
|
+
this._pendingCallback=setTimeout((()=>{t(Lo(e))}),n)},i=t=>{if("mousedown"===t.type&&(n=!0),"mouseup"===t.type&&(n=!1),n)return;this._cancelPendingCallback();const e="mouseup"===t.type?10:100;o(e)};this._document=e,this._listeners=new kt,this._listeners.add(e,"selectionchange",i),this._listeners.add(e.body,"mousedown",i),this._listeners.add(e.body,"mouseup",i),o(1)}disconnect(){this._listeners.removeAll(),this._cancelPendingCallback()}_cancelPendingCallback(){this._pendingCallback&&(clearTimeout(this._pendingCallback),this._pendingCallback=null)}}function Mo(){const t=function(t,e){const n=new Set,o=new Set;return Ce(t,(t=>{let i=t;for(;i&&!n.has(i);){n.add(i);const t=e(i);null!=t&&o.add(t),i=i.parentNode}})),[...o]}(window.getSelection().getRangeAt(0),(t=>{var e;return null===(e=t._annotation)||void 0===e?void 0:e.$tag}));return t}function No(t){const e=function(t){let e=t.nodeType===Node.ELEMENT_NODE?t:t.parentElement;const n=[];for(;e;)e.classList.contains("hypothesis-highlight")&&n.push(e),
|
|
100
|
+
e=e.parentElement;return n}(t).map((t=>t._annotation)).filter((t=>void 0!==t)).map((t=>null==t?void 0:t.$tag));return e}function Oo(t){if(!t.range)return null;try{return t.range.toRange()}catch{return null}}function Io(){var t;null===(t=document.getSelection())||void 0===t||t.removeAllRanges()}class Do{constructor(t,e={},n=window){this.element=t,this._hostFrame=n,this._highlightsVisible=!1,this._isAdderVisible=!1,this._informHostOnNextSelectionClear=!0,this.selectedRanges=[],this._adder=new de(this.element,{onAnnotate:()=>this.createAnnotation(),onHighlight:()=>this.createAnnotation({highlight:!0}),onShowAnnotations:t=>this.selectAnnotations(t)}),this._selectionObserver=new Po((t=>{t?this._onSelection(t):this._onClearSelection()})),this.anchors=[],this._annotations=new Set,this._frameIdentifier=e.subFrameIdentifier||null,this._portFinder=new Nt({hostFrame:this._hostFrame,source:"guest"}),this._integration=Ro(this,{contentPartner:e.contentPartner}),this._hostRPC=new jt,this._connectHost(n),
|
|
101
|
+
this._sidebarRPC=new jt,this._connectSidebar(),this._bucketBarClient=new Le({contentContainer:this._integration.contentContainer(),hostRPC:this._hostRPC}),this._sideBySideActive=!1,this._listeners=new kt,this._setupElementEvents(),this._focusedAnnotations=new Set}_setupElementEvents(){const t=t=>{this._sideBySideActive||No(t).length||this._sidebarRPC.call("closeSidebar")};this._listeners.add(this.element,"mouseup",(t=>{const{target:e,metaKey:n,ctrlKey:o}=t,i=No(e);if(i.length&&this._highlightsVisible){const t=n||o;this.selectAnnotations(i,t)}})),this._listeners.add(this.element,"mousedown",(({target:e})=>{t(e)})),this._listeners.add(this.element,"touchstart",(({target:e})=>{t(e)})),this._listeners.add(this.element,"mouseover",(({target:t})=>{const e=No(t);e.length&&this._highlightsVisible&&this._sidebarRPC.call("focusAnnotations",e)})),this._listeners.add(this.element,"mouseout",(()=>{this._highlightsVisible&&this._sidebarRPC.call("focusAnnotations",[])})),
|
|
102
|
+
this._listeners.add(window,"resize",(()=>this._repositionAdder()))}async getDocumentInfo(){const[t,e]=await Promise.all([this._integration.uri(),this._integration.getMetadata()]);return{uri:Ge(t),metadata:e,frameIdentifier:this._frameIdentifier}}_repositionAdder(){var t;if(!1===this._isAdderVisible)return;const e=null===(t=window.getSelection())||void 0===t?void 0:t.getRangeAt(0);e&&this._onSelection(e)}async _connectHost(t){this._hostRPC.on("clearSelection",(()=>{Lo(document)&&(this._informHostOnNextSelectionClear=!1,Io())})),this._hostRPC.on("createAnnotation",(()=>this.createAnnotation())),this._hostRPC.on("focusAnnotations",(t=>this._focusAnnotations(t))),this._hostRPC.on("scrollToClosestOffScreenAnchor",((t,e)=>this._scrollToClosestOffScreenAnchor(t,e))),this._hostRPC.on("selectAnnotations",((t,e)=>this.selectAnnotations(t,e))),this._hostRPC.on("sidebarLayoutChanged",(e=>{var n,o
|
|
103
103
|
;((n=window)===(o=t)||n.parent===o&&n.frameElement&&n.frameElement.getBoundingClientRect().width/n.parent.innerWidth>=.8)&&this.fitSideBySide(e)}));const e=await this._portFinder.discover("host");this._hostRPC.connect(e)}async _connectSidebar(){this._sidebarRPC.on("focusAnnotations",(t=>this._focusAnnotations(t))),this._sidebarRPC.on("scrollToAnnotation",(t=>{const e=this.anchors.find((e=>e.annotation.$tag===t));if(null==e||!e.highlights)return;const n=Oo(e);if(!n)return;const o=new CustomEvent("scrolltorange",{bubbles:!0,cancelable:!0,detail:n});this.element.dispatchEvent(o)&&this._integration.scrollToAnchor(e)})),this._sidebarRPC.on("setHighlightsVisible",(t=>{this.setHighlightsVisible(t)})),this._sidebarRPC.on("deleteAnnotation",(t=>this.detach(t))),this._sidebarRPC.on("loadAnnotations",(t=>t.forEach((t=>this.anchor(t))))),this._portFinder.discover("sidebar").then((t=>{this._sidebarRPC.connect(t)})),this.getDocumentInfo().then((t=>this._sidebarRPC.call("documentInfoChanged",t)))}destroy(){
|
|
104
104
|
this._portFinder.destroy(),this._hostRPC.destroy(),this._sidebarRPC.destroy(),this._listeners.removeAll(),this._selectionObserver.disconnect(),this._adder.destroy(),this._bucketBarClient.destroy(),function(t){Ae(Array.from(t.querySelectorAll("hypothesis-highlight")))}(this.element),this._integration.destroy()}async anchor(t){const e=t=>{const e=Oo(t);if(!e)return;const n=Ee(e);n.forEach((e=>{e._annotation=t.annotation})),t.highlights=n,this._focusedAnnotations.has(t.annotation.$tag)&&ke(n,!0)};this.detach(t.$tag,!1),this._annotations.add(t.$tag),t.target||(t.target=[]);const n=await Promise.all(t.target.map((async e=>{if(!e.selector||!e.selector.some((t=>"TextQuoteSelector"===t.type)))return{annotation:t,target:e};let n;try{const o=await this._integration.anchor(this.element,e.selector),i=_e.fromRange(o);n={annotation:t,target:e,range:i}}catch(o){n={annotation:t,target:e}}return n})));if(!this._annotations.has(t.$tag))return[];for(let t of n)e(t)
|
|
105
105
|
;return t.$orphan=n.length>0&&n.every((t=>t.target.selector&&!t.range)),this._updateAnchors(this.anchors.concat(n),!0),this._sidebarRPC.call("syncAnchoringStatus",t),n}detach(t,e=!0){this._annotations.delete(t);const n=[];for(let e of this.anchors)e.annotation.$tag!==t?n.push(e):e.highlights&&Ae(e.highlights);this._updateAnchors(n,e)}_updateAnchors(t,e){this.anchors=t,e&&this._bucketBarClient.update(this.anchors)}async createAnnotation({highlight:t=!1}={}){const e=this.selectedRanges;this.selectedRanges=[];const n=await this.getDocumentInfo(),o=this.element,i=(await Promise.all(e.map((t=>this._integration.describe(o,t))))).map((t=>({source:n.uri,selector:t}))),r={uri:n.uri,document:n.metadata,target:i,$highlight:t,$tag:"a:"+Lt(8)};return this._sidebarRPC.call("createAnnotation",r),this.anchor(r),Io(),r}_focusAnnotations(t){this._focusedAnnotations.clear(),t.forEach((t=>this._focusedAnnotations.add(t)));for(let e of this.anchors)if(e.highlights){const n=t.includes(e.annotation.$tag);ke(e.highlights,n)}
|
|
106
106
|
this._sidebarRPC.call("focusAnnotations",t)}_scrollToClosestOffScreenAnchor(t,e){const n=function(t,e){let n=null,o=0;for(let r of t){var i;if(null===(i=r.highlights)||void 0===i||!i.length)continue;const t=Re(r.highlights).top;"up"===e&&t>=137||"down"===e&&t<=window.innerHeight-22||(!n||"up"===e&&t>o||"down"===e&&t<o)&&(n=r,o=t)}return n}(this.anchors.filter((({annotation:e})=>t.includes(e.$tag))),e);n&&this._integration.scrollToAnchor(n)}_onSelection(t){if(!this._integration.canAnnotate(t))return void this._onClearSelection();const e=document.getSelection(),n=we(e),o=xe(e);o?(this.selectedRanges=[t],this._hostRPC.call("textSelected"),this._adder.annotationsForSelection=Mo(),this._isAdderVisible=!0,this._adder.show(o,n)):this._onClearSelection()}_onClearSelection(){this._isAdderVisible=!1,this._adder.hide(),this.selectedRanges=[],this._informHostOnNextSelectionClear&&this._hostRPC.call("textUnselected"),this._informHostOnNextSelectionClear=!0}selectAnnotations(t,e=!1){
|
|
107
|
-
e?this._sidebarRPC.call("toggleAnnotationSelection",t):this._sidebarRPC.call("showAnnotations",t),this._sidebarRPC.call("openSidebar")}setHighlightsVisible(t){!function(t,e){t.classList.toggle("hypothesis-highlights-always-on",e)}(this.element,t),this._highlightsVisible=t}fitSideBySide(t){this._sideBySideActive=this._integration.fitSideBySide(t)}get sideBySideActive(){return this._sideBySideActive}get focusedAnnotationTags(){return this._focusedAnnotations}}function Bo(t,e){const n=new URL(t),o=new URLSearchParams;return o.append("config",JSON.stringify(e)),n.hash=o.toString(),n.toString()}function Fo(t,e){var n;const o={};for(let[t,n]of Object.entries(e))"notebookAppUrl"!==t&&"sidebarAppUrl"!==t&&null!=n&&(o[t]=n);o.origin=new URL(t).origin,o.version="1.
|
|
107
|
+
e?this._sidebarRPC.call("toggleAnnotationSelection",t):this._sidebarRPC.call("showAnnotations",t),this._sidebarRPC.call("openSidebar")}setHighlightsVisible(t){!function(t,e){t.classList.toggle("hypothesis-highlights-always-on",e)}(this.element,t),this._highlightsVisible=t}fitSideBySide(t){this._sideBySideActive=this._integration.fitSideBySide(t)}get sideBySideActive(){return this._sideBySideActive}get focusedAnnotationTags(){return this._focusedAnnotations}}function Bo(t,e){const n=new URL(t),o=new URLSearchParams;return o.append("config",JSON.stringify(e)),n.hash=o.toString(),n.toString()}function Fo(t,e){var n;const o={};for(let[t,n]of Object.entries(e))"notebookAppUrl"!==t&&"sidebarAppUrl"!==t&&null!=n&&(o[t]=n);o.origin=new URL(t).origin,o.version="1.1048.0";const i=new URL(window.location.href);if(i.hash="",o.hostURL=i.toString(),Array.isArray(o.services)&&(null===(n=o.services)||void 0===n?void 0:n.length)>0){const t=o.services[0];t.onLoginRequest&&(t.onLoginRequestProvided=!0),
|
|
108
108
|
t.onLogoutRequest&&(t.onLogoutRequestProvided=!0),t.onSignupRequest&&(t.onSignupRequestProvided=!0),t.onProfileRequest&&(t.onProfileRequestProvided=!0),t.onHelpRequest&&(t.onHelpRequestProvided=!0)}return o}function Ho({config:t,groupId:e}){return mt("iframe",{title:"Hypothesis annotation notebook",className:"h-full w-full border-0",allowFullScreen:!0,src:Bo(t.notebookAppUrl,{...Fo(t.notebookAppUrl,t),group:e})})}function Vo({eventBus:t,config:e}){const[n,o]=rt(0),[i,r]=rt(!0),[s,a]=rt(null),c=ct(""),l=ct(null);st((()=>(c.current=document.body.style.overflow,()=>{document.body.style.overflow=c.current})),[]),st((()=>{document.body.style.overflow=i?c.current:"hidden"}),[i]),st((()=>{const e=t.createEmitter();return e.subscribe("openNotebook",(t=>{r(!1),o((t=>t+1)),a(t)})),l.current=e,()=>{e.destroy()}}),[t]);return null===s?null:mt("div",{className:Z("fixed z-max top-0 left-0 right-0 bottom-0 p-3 bg-black/50",{hidden:i}),"data-testid":"notebook-outer",children:mt("div",{className:"relative w-full h-full",
|
|
109
109
|
"data-testid":"notebook-inner",children:[mt("div",{className:"absolute right-0 text-xl m-3",children:mt(Ct,{icon:"cancel",title:"Close the Notebook",onClick:()=>{var t;r(!0),null===(t=l.current)||void 0===t||t.publish("closeNotebook")},variant:"dark"})}),mt(Ho,{config:e,groupId:s},n)]})})}class qo{constructor(t,e,n){this._outerContainer=document.createElement("hypothesis-notebook"),t.appendChild(this._outerContainer),this.shadowRoot=he(this._outerContainer),M(mt(Vo,{eventBus:e,config:n}),this.shadowRoot)}destroy(){M(null,this.shadowRoot),this._outerContainer.remove()}}var Uo={exports:{}};!function(t){!function(e,n,o,i){var r,s=["","webkit","Moz","MS","ms","o"],a=n.createElement("div"),c=Math.round,l=Math.abs,h=Date.now;function u(t,e,n){return setTimeout(v(t,n),e)}function d(t,e,n){return!!Array.isArray(t)&&(f(t,n[e],n),!0)}function f(t,e,n){var o;if(t)if(t.forEach)t.forEach(e,n);else if(t.length!==i)for(o=0;o<t.length;)e.call(n,t[o],o,t),o++;else for(o in t)t.hasOwnProperty(o)&&e.call(n,t[o],o,t)}
|
|
110
110
|
function p(t,n,o){var i="DEPRECATED METHOD: "+n+"\n"+o+" AT \n";return function(){var n=new Error("get-stack-trace"),o=n&&n.stack?n.stack.replace(/^[^\(]+?[\n$]/gm,"").replace(/^\s+at\s+/gm,"").replace(/^Object.<anonymous>\s*\(/gm,"{anonymous}()@"):"Unknown Stack Trace",r=e.console&&(e.console.warn||e.console.log);return r&&r.call(e.console,i,o),t.apply(this,arguments)}}r="function"!=typeof Object.assign?function(t){if(t===i||null===t)throw new TypeError("Cannot convert undefined or null to object");for(var e=Object(t),n=1;n<arguments.length;n++){var o=arguments[n];if(o!==i&&null!==o)for(var r in o)o.hasOwnProperty(r)&&(e[r]=o[r])}return e}:Object.assign;var g=p((function(t,e,n){for(var o=Object.keys(e),r=0;r<o.length;)(!n||n&&t[o[r]]===i)&&(t[o[r]]=e[o[r]]),r++;return t}),"extend","Use `assign`."),m=p((function(t,e){return g(t,e,!0)}),"merge","Use `assign`.");function _(t,e,n){var o,i=e.prototype;(o=t.prototype=Object.create(i)).constructor=t,o._super=i,n&&r(o,n)}function v(t,e){return function(){
|