hypothesis 1.1637.0 → 1.1638.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 CHANGED
@@ -1 +1 @@
1
- !function(){"use strict";var s={"scripts/annotator.bundle.js":"scripts/annotator.bundle.js?b60fc8","styles/annotator.css":"styles/annotator.css?b497a3","styles/annotator.css.map":"styles/annotator.css.map?b9df74","styles/highlights.css":"styles/highlights.css?24baca","styles/highlights.css.map":"styles/highlights.css.map?377599","styles/katex.min.css":"styles/katex.min.css?921c28","styles/katex.min.css.map":"styles/katex.min.css.map?e7e03f","styles/pdfjs-overrides.css":"styles/pdfjs-overrides.css?c95edf","styles/pdfjs-overrides.css.map":"styles/pdfjs-overrides.css.map?1d8ac6","styles/sidebar.css.map":"styles/sidebar.css.map?c4cba4","styles/sidebar.css":"styles/sidebar.css?c949f4","styles/ui-playground.css":"styles/ui-playground.css?6778a6","styles/ui-playground.css.map":"styles/ui-playground.css.map?0e6471","scripts/sidebar.bundle.js":"scripts/sidebar.bundle.js?2a986d","scripts/annotator.bundle.js.map":"scripts/annotator.bundle.js.map?b0032b","scripts/ui-playground.bundle.js":"scripts/ui-playground.bundle.js?7f00d1","scripts/sidebar.bundle.js.map":"scripts/sidebar.bundle.js.map?71edbd","scripts/ui-playground.bundle.js.map":"scripts/ui-playground.bundle.js.map?f8f9bd"};function t(s){s.setAttribute("data-hypothesis-asset","")}function e(s,e){var o=s.createElement("link");o.rel="stylesheet",o.type="text/css",o.href=e,t(o),s.head.appendChild(o)}function o(s,e){var o=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},r=o.esModule,n=void 0===r||r,i=o.forceReload,a=void 0!==i&&i,l=s.createElement("script");n&&(l.type="module"),a&&(e+="#ts=".concat(Date.now())),l.src=e,l.async=!1,t(l),s.head.appendChild(l)}function r(s,e,o,r){var n=s.createElement("link");n.rel=e,n.href=r,n.type="application/annotator+".concat(o),t(n),s.head.appendChild(n)}function n(s,e,o){var r=s.createElement("link");r.rel="preload",r.as=e,r.href=o,"fetch"===e&&(r.crossOrigin="anonymous"),t(r),s.head.appendChild(r)}function i(s,t){return s.assetRoot+"build/"+s.manifest[t]}function a(s){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:document;if(-1===s.indexOf("{"))return s;var e=function(){var s,t,e=(arguments.length>0&&void 0!==arguments[0]?arguments[0]:document).currentScript;return e?(s=e.src,(t=s.match(/(https?):\/\/([^:/]+)/))?{protocol:t[1],hostname:t[2]}:null):null}(t);if(!e)throw new Error("Could not process URL template because script origin is unknown");return s=(s=s.replace("{current_host}",e.hostname)).replace("{current_scheme}",e.protocol)}if(function(){var s=[()=>Object.fromEntries([]),()=>new URL(document.location.href),()=>new Request("https://hypothes.is"),()=>Element.prototype.attachShadow,()=>CSS.supports("display: grid"),()=>(document.evaluate("/html/body",document,null,XPathResult.ANY_TYPE,null),!0)];try{return s.every((s=>s()))}catch(s){return!1}}()){var l=function(s){for(var t={},e=s.querySelectorAll("script.js-hypothesis-config"),o=0;o<e.length;o++){var r=void 0;try{r=JSON.parse(e[o].textContent||"")}catch(s){console.warn("Could not parse settings from js-hypothesis-config tags",s),r={}}Object.assign(t,r)}return t}(document),p=a(l.assetRoot||"https://cdn.hypothes.is/hypothesis/1.1637.0/");if(document.querySelector("hypothesis-app")){!function(s,t){n(s,"fetch",t.apiUrl),n(s,"fetch",t.apiUrl+"links");for(var r=0,a=["scripts/sidebar.bundle.js"];r<a.length;r++)o(s,i(t,a[r]),{esModule:!0});for(var l=0,p=["styles/katex.min.css","styles/sidebar.css"];l<p.length;l++)e(s,i(t,p[l]))}(document,{assetRoot:p,manifest:s,apiUrl:l.apiUrl})}else{var c=function(){var s;return null===(s=(arguments.length>0&&void 0!==arguments[0]?arguments[0]:window).chrome)||void 0===s||null===(s=s.runtime)||void 0===s?void 0:s.id}();if(c&&!function(s){return!!(arguments.length>1&&void 0!==arguments[1]?arguments[1]:document).querySelector("script.js-hypothesis-config[data-extension-id=".concat(s,"]"))}(c))throw new Error("Could not start Hypothesis extension as configuration is missing");var d=l,h=a(d.notebookAppUrl||"https://hypothes.is/notebook"),u=a(d.profileAppUrl||"https://hypothes.is/user-profile"),y=a(d.sidebarAppUrl||"https://hypothes.is/app.html");!function(s,t){if(!s.querySelector('link[type="application/annotator+html"]')){r(s,"sidebar","html",t.sidebarAppUrl),r(s,"notebook","html",t.notebookAppUrl),r(s,"profile","html",t.profileAppUrl),n(s,"style",i(t,"styles/annotator.css")),r(s,"hypothesis-client","javascript",t.assetRoot+"build/boot.js");for(var a=0,l=["scripts/annotator.bundle.js"];a<l.length;a++)o(s,i(t,l[a]),{esModule:!1});var p=[];void 0!==window.PDFViewerApplication&&p.push("styles/pdfjs-overrides.css"),p.push("styles/highlights.css");for(var c=0,d=p;c<d.length;c++)e(s,i(t,d[c]))}}(document,{assetRoot:p,manifest:s,notebookAppUrl:h,profileAppUrl:u,sidebarAppUrl:y})}}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/.")}();
1
+ !function(){"use strict";var s={"scripts/annotator.bundle.js":"scripts/annotator.bundle.js?10c52b","styles/annotator.css":"styles/annotator.css?b497a3","styles/annotator.css.map":"styles/annotator.css.map?b9df74","styles/highlights.css":"styles/highlights.css?24baca","styles/highlights.css.map":"styles/highlights.css.map?377599","styles/katex.min.css":"styles/katex.min.css?921c28","styles/katex.min.css.map":"styles/katex.min.css.map?e7e03f","styles/pdfjs-overrides.css":"styles/pdfjs-overrides.css?c95edf","styles/pdfjs-overrides.css.map":"styles/pdfjs-overrides.css.map?1d8ac6","styles/sidebar.css":"styles/sidebar.css?c949f4","styles/sidebar.css.map":"styles/sidebar.css.map?c4cba4","styles/ui-playground.css":"styles/ui-playground.css?6778a6","styles/ui-playground.css.map":"styles/ui-playground.css.map?0e6471","scripts/annotator.bundle.js.map":"scripts/annotator.bundle.js.map?3d7332","scripts/sidebar.bundle.js":"scripts/sidebar.bundle.js?3b9b11","scripts/ui-playground.bundle.js":"scripts/ui-playground.bundle.js?7f00d1","scripts/ui-playground.bundle.js.map":"scripts/ui-playground.bundle.js.map?f8f9bd","scripts/sidebar.bundle.js.map":"scripts/sidebar.bundle.js.map?71edbd"};function t(s){s.setAttribute("data-hypothesis-asset","")}function e(s,e){var o=s.createElement("link");o.rel="stylesheet",o.type="text/css",o.href=e,t(o),s.head.appendChild(o)}function o(s,e){var o=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},r=o.esModule,n=void 0===r||r,i=o.forceReload,a=void 0!==i&&i,l=s.createElement("script");n&&(l.type="module"),a&&(e+="#ts=".concat(Date.now())),l.src=e,l.async=!1,t(l),s.head.appendChild(l)}function r(s,e,o,r){var n=s.createElement("link");n.rel=e,n.href=r,n.type="application/annotator+".concat(o),t(n),s.head.appendChild(n)}function n(s,e,o){var r=s.createElement("link");r.rel="preload",r.as=e,r.href=o,"fetch"===e&&(r.crossOrigin="anonymous"),t(r),s.head.appendChild(r)}function i(s,t){return s.assetRoot+"build/"+s.manifest[t]}function a(s){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:document;if(-1===s.indexOf("{"))return s;var e=function(){var s,t,e=(arguments.length>0&&void 0!==arguments[0]?arguments[0]:document).currentScript;return e?(s=e.src,(t=s.match(/(https?):\/\/([^:/]+)/))?{protocol:t[1],hostname:t[2]}:null):null}(t);if(!e)throw new Error("Could not process URL template because script origin is unknown");return s=(s=s.replace("{current_host}",e.hostname)).replace("{current_scheme}",e.protocol)}if(function(){var s=[()=>Object.fromEntries([]),()=>new URL(document.location.href),()=>new Request("https://hypothes.is"),()=>Element.prototype.attachShadow,()=>CSS.supports("display: grid"),()=>(document.evaluate("/html/body",document,null,XPathResult.ANY_TYPE,null),!0)];try{return s.every((s=>s()))}catch(s){return!1}}()){var l=function(s){for(var t={},e=s.querySelectorAll("script.js-hypothesis-config"),o=0;o<e.length;o++){var r=void 0;try{r=JSON.parse(e[o].textContent||"")}catch(s){console.warn("Could not parse settings from js-hypothesis-config tags",s),r={}}Object.assign(t,r)}return t}(document),p=a(l.assetRoot||"https://cdn.hypothes.is/hypothesis/1.1638.0/");if(document.querySelector("hypothesis-app")){!function(s,t){n(s,"fetch",t.apiUrl),n(s,"fetch",t.apiUrl+"links");for(var r=0,a=["scripts/sidebar.bundle.js"];r<a.length;r++)o(s,i(t,a[r]),{esModule:!0});for(var l=0,p=["styles/katex.min.css","styles/sidebar.css"];l<p.length;l++)e(s,i(t,p[l]))}(document,{assetRoot:p,manifest:s,apiUrl:l.apiUrl})}else{var c=function(){var s;return null===(s=(arguments.length>0&&void 0!==arguments[0]?arguments[0]:window).chrome)||void 0===s||null===(s=s.runtime)||void 0===s?void 0:s.id}();if(c&&!function(s){return!!(arguments.length>1&&void 0!==arguments[1]?arguments[1]:document).querySelector("script.js-hypothesis-config[data-extension-id=".concat(s,"]"))}(c))throw new Error("Could not start Hypothesis extension as configuration is missing");var d=l,h=a(d.notebookAppUrl||"https://hypothes.is/notebook"),u=a(d.profileAppUrl||"https://hypothes.is/user-profile"),y=a(d.sidebarAppUrl||"https://hypothes.is/app.html");!function(s,t){if(!s.querySelector('link[type="application/annotator+html"]')){r(s,"sidebar","html",t.sidebarAppUrl),r(s,"notebook","html",t.notebookAppUrl),r(s,"profile","html",t.profileAppUrl),n(s,"style",i(t,"styles/annotator.css")),r(s,"hypothesis-client","javascript",t.assetRoot+"build/boot.js");for(var a=0,l=["scripts/annotator.bundle.js"];a<l.length;a++)o(s,i(t,l[a]),{esModule:!1});var p=[];void 0!==window.PDFViewerApplication&&p.push("styles/pdfjs-overrides.css"),p.push("styles/highlights.css");for(var c=0,d=p;c<d.length;c++)e(s,i(t,d[c]))}}(document,{assetRoot:p,manifest:s,notebookAppUrl:h,profileAppUrl:u,sidebarAppUrl:y})}}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/.")}();
@@ -1,5 +1,5 @@
1
1
  {
2
- "scripts/annotator.bundle.js": "scripts/annotator.bundle.js?b60fc8",
2
+ "scripts/annotator.bundle.js": "scripts/annotator.bundle.js?10c52b",
3
3
  "styles/annotator.css": "styles/annotator.css?b497a3",
4
4
  "styles/annotator.css.map": "styles/annotator.css.map?b9df74",
5
5
  "styles/highlights.css": "styles/highlights.css?24baca",
@@ -8,13 +8,13 @@
8
8
  "styles/katex.min.css.map": "styles/katex.min.css.map?e7e03f",
9
9
  "styles/pdfjs-overrides.css": "styles/pdfjs-overrides.css?c95edf",
10
10
  "styles/pdfjs-overrides.css.map": "styles/pdfjs-overrides.css.map?1d8ac6",
11
- "styles/sidebar.css.map": "styles/sidebar.css.map?c4cba4",
12
11
  "styles/sidebar.css": "styles/sidebar.css?c949f4",
12
+ "styles/sidebar.css.map": "styles/sidebar.css.map?c4cba4",
13
13
  "styles/ui-playground.css": "styles/ui-playground.css?6778a6",
14
14
  "styles/ui-playground.css.map": "styles/ui-playground.css.map?0e6471",
15
- "scripts/sidebar.bundle.js": "scripts/sidebar.bundle.js?2a986d",
16
- "scripts/annotator.bundle.js.map": "scripts/annotator.bundle.js.map?b0032b",
15
+ "scripts/annotator.bundle.js.map": "scripts/annotator.bundle.js.map?3d7332",
16
+ "scripts/sidebar.bundle.js": "scripts/sidebar.bundle.js?3b9b11",
17
17
  "scripts/ui-playground.bundle.js": "scripts/ui-playground.bundle.js?7f00d1",
18
- "scripts/sidebar.bundle.js.map": "scripts/sidebar.bundle.js.map?71edbd",
19
- "scripts/ui-playground.bundle.js.map": "scripts/ui-playground.bundle.js.map?f8f9bd"
18
+ "scripts/ui-playground.bundle.js.map": "scripts/ui-playground.bundle.js.map?f8f9bd",
19
+ "scripts/sidebar.bundle.js.map": "scripts/sidebar.bundle.js.map?71edbd"
20
20
  }
@@ -74,57 +74,57 @@ const Xn=(e=window)=>e.matchMedia("(pointer: coarse)").matches;function Yn({badg
74
74
  return Pe("div",{className:"sr-only",children:[Pe("span",{"aria-live":"polite","aria-atomic":"true",role:"status","data-testid":"annotation-count-announce",children:e>0&&Pe("span",{children:[e," ",1===e?"annotation":"annotations"," for this selection."]})}),Pe("ul",{"aria-live":"polite","data-testid":"annotate-shortcuts-announce",children:t&&Pe(w,{children:[e>0&&Pe("li",{children:["Press ","'S'"," to show annotations."]}),Pe("li",{children:["Press ","'A'"," to annotate."]}),Pe("li",{children:["Press ","'H'"," to highlight."]})]})})]})}function Jn({arrowDirection:e,isVisible:t,onCommand:n,annotationCount:o=0}){const i=t?"a":null,r=t?"h":null,s=t?"s":null;return jn(t?"Escape":null,(()=>n("hide"))),Pe("div",{className:Ee("all-initial","border border-solid border-grey-3","absolute select-none bg-white rounded shadow-intense","opacity-5",{"animate-adder-pop-up":"up"===e&&t,"animate-adder-pop-down":"down"===e&&t}),"data-component":"AdderToolbar",dir:"ltr",style:{visibility:t?"visible":"hidden"},children:[Pe("div",{
75
75
  className:Ee("flex group"),children:[Pe(Gn,{icon:Be,onClick:()=>n("annotate"),label:"Annotate",shortcut:i}),Pe(Gn,{icon:nt,onClick:()=>n("highlight"),label:"Highlight",shortcut:r}),o>0&&Pe(w,{children:[Pe("div",{className:Ee("m-1.5 border-r border-grey-4 border-solid")}),Pe(Gn,{badgeCount:o,onClick:()=>n("show"),label:"Show",shortcut:s})]})]}),Pe(Kn,{arrowDirection:e}),Pe(Qn,{annotationCount:o,isVisible:t})]})}function Zn(e){const t=e.attachShadow({mode:"open"});return function(e){const t=document.querySelector('link[rel="preload"][href*="/build/styles/annotator.css"]')?.href;if(!t)return;const n=document.createElement("link");n.rel="stylesheet",n.href=t,e.appendChild(n)}(t),t}class eo{constructor(e,t){const n=`hypothesis-${e}`;this._element=document.createElement(n),this._shadowRoot=Zn(this._element),this._render=t}destroy(){F(null,this._shadowRoot),this._element.remove()}get element(){return this._element}render(){F(this._render(),this._shadowRoot)}}let to=function(e){return e[e.DOWN=1]="DOWN",
76
76
  e[e.UP=2]="UP",e}({});function no(e){return e.toString()+"px"}class oo{constructor(e,t){this._view=e.ownerDocument.defaultView,this._isVisible=!1,this._arrowDirection="up",this._annotationsForSelection=[],this._onAnnotate=t.onAnnotate,this._onHighlight=t.onHighlight,this._onShowAnnotations=t.onShowAnnotations,this._container=new eo("adder",(()=>this._render())),e.appendChild(this._container.element),Object.assign(this._container.element.style,{position:"absolute",top:0,left:0}),this._container.render()}get annotationsForSelection(){return this._annotationsForSelection}set annotationsForSelection(e){this._annotationsForSelection=e,this._container.render()}hide(){this._isVisible=!1,this._container.render(),Object.assign(this._container.element.style,{top:0,left:0})}destroy(){this._container.destroy()}show(e,t){const{left:n,top:o,arrowDirection:i}=this._calculateTarget(e,t);this._showAt(n,o),this._isVisible=!0,this._arrowDirection=i===to.UP?"up":"down",this._container.render()}_firstChild(){
77
- return this._container.element.shadowRoot.firstChild}_width(){return this._firstChild().getBoundingClientRect().width}_height(){return this._firstChild().getBoundingClientRect().height}_calculateTarget(e,t){let n,o,i;n=t&&!Xn()?to.DOWN:to.UP;const r=Math.min(20,e.width),s=this._width(),a=Xn()?10:0,l=this._height();return i=t?e.left-s/2+r:e.left+e.width-s/2-r,e.top-l<0&&n===to.DOWN?n=to.UP:e.top+l>this._view.innerHeight&&(n=to.DOWN),o=n===to.UP?e.top+e.height+10+a:e.top-l-10,i=Math.max(i,0),i=Math.min(i,this._view.innerWidth-s),o=Math.max(o,0),o=Math.min(o,this._view.innerHeight-l),{top:o,left:i,arrowDirection:n}}_findZindex(e,t){if(void 0===document.elementsFromPoint)return 32768;const n=this._width(),o=this._height(),i=[...new Set([...document.elementsFromPoint(e,t),...document.elementsFromPoint(e,t+o),...document.elementsFromPoint(e+n/2,t+o/2),...document.elementsFromPoint(e+n,t),...document.elementsFromPoint(e+n,t+o)])].map((e=>+getComputedStyle(e).zIndex)).filter(Number.isInteger);return i.push(0),
78
- Math.max(...i)+1}_showAt(e,t){const n=function(e){let t=e.parentElement;for(;t.parentElement&&"static"===getComputedStyle(t).position;)t=t.parentElement;return t}(this._container.element).getBoundingClientRect(),o=this._findZindex(e,t);Object.assign(this._container.element.style,{left:no(e-n.left),top:no(t-n.top),zIndex:o})}_render(){return Pe(Jn,{isVisible:this._isVisible,arrowDirection:this._arrowDirection,onCommand:e=>{switch(e){case"annotate":this._onAnnotate(),this.hide();break;case"highlight":this._onHighlight(),this.hide();break;case"show":this._onShowAnnotations(this.annotationsForSelection);break;case"hide":this.hide()}},annotationCount:this.annotationsForSelection.length})}}var io=function(e){return e[e.Forwards=1]="Forwards",e[e.Backwards=2]="Backwards",e}(io||{});function ro(e,t,n){const o=n===io.Forwards?t:t-1;if(""!==e.charAt(o).trim())return t;let i,r;if(n===io.Backwards?(i=e.substring(0,t),r=i.trimEnd()):(i=e.substring(t),r=i.trimStart()),!r.length)return-1;const s=i.length-r.length
79
- ;return n===io.Backwards?t-s:t+s}function so(e,t){const n=e.commonAncestorContainer.ownerDocument.createNodeIterator(e.commonAncestorContainer,NodeFilter.SHOW_TEXT),o=t===io.Forwards?e.startContainer:e.endContainer,i=t===io.Forwards?e.endContainer:e.startContainer;let r=n.nextNode();for(;r&&r!==o;)r=n.nextNode();t===io.Backwards&&(r=n.previousNode());let s=-1;const a=()=>{if(r=t===io.Forwards?n.nextNode():n.previousNode(),r){const e=r.textContent,n=t===io.Forwards?0:e.length;s=ro(e,n,t)}};for(;r&&-1===s&&r!==i;)a();if(r&&s>=0)return{node:r,offset:s};throw new RangeError("No text nodes with non-whitespace text found in range")}function ao(e){switch(e.nodeType){case Node.ELEMENT_NODE:case Node.TEXT_NODE:return e.textContent?.length??0;default:return 0}}function lo(e){let t=e.previousSibling,n=0;for(;t;)n+=ao(t),t=t.previousSibling;return n}function co(e,...t){let n=t.shift();const o=e.ownerDocument.createNodeIterator(e,NodeFilter.SHOW_TEXT),i=[];let r,s=o.nextNode(),a=0;for(;void 0!==n&&s;)r=s,
80
- a+r.data.length>n?(i.push({node:r,offset:n-a}),n=t.shift()):(s=o.nextNode(),a+=r.data.length);for(;void 0!==n&&r&&a===n;)i.push({node:r,offset:r.data.length}),n=t.shift();if(void 0!==n)throw new RangeError("Offset exceeds text length");return i}let ho=function(e){return e[e.FORWARDS=1]="FORWARDS",e[e.BACKWARDS=2]="BACKWARDS",e}({});class uo{constructor(e,t){if(t<0)throw new Error("Offset is invalid");this.element=e,this.offset=t}relativeTo(e){if(!e.contains(this.element))throw new Error("Parent is not an ancestor of current element");let t=this.element,n=this.offset;for(;t!==e;)n+=lo(t),t=t.parentElement;return new uo(t,n)}resolve(e={}){try{return co(this.element,this.offset)[0]}catch(t){if(0===this.offset&&void 0!==e.direction){const n=document.createTreeWalker(this.element.getRootNode(),NodeFilter.SHOW_TEXT);n.currentNode=this.element;const o=e.direction===ho.FORWARDS,i=o?n.nextNode():n.previousNode();if(!i)throw t;return{node:i,offset:o?0:i.data.length}}throw t}}static fromCharOffset(e,t){
81
- switch(e.nodeType){case Node.TEXT_NODE:return uo.fromPoint(e,t);case Node.ELEMENT_NODE:return new uo(e,t);default:throw new Error("Node is not an element or text node")}}static fromPoint(e,t){switch(e.nodeType){case Node.TEXT_NODE:{if(t<0||t>e.data.length)throw new Error("Text node offset is out of range");if(!e.parentElement)throw new Error("Text node has no parent");const n=lo(e)+t;return new uo(e.parentElement,n)}case Node.ELEMENT_NODE:{if(t<0||t>e.childNodes.length)throw new Error("Child node offset is out of range");let n=0;for(let o=0;o<t;o++)n+=ao(e.childNodes[o]);return new uo(e,n)}default:throw new Error("Point is not in an element or text node")}}}class fo{constructor(e,t){this.start=e,this.end=t}relativeTo(e){return new fo(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]=co(this.start.element,this.start.offset,this.end.offset):(e=this.start.resolve({direction:ho.FORWARDS}),t=this.end.resolve({
82
- direction:ho.BACKWARDS}));const n=new Range;return n.setStart(e.node,e.offset),n.setEnd(t.node,t.offset),n}static fromRange(e){const t=uo.fromPoint(e.startContainer,e.startOffset),n=uo.fromPoint(e.endContainer,e.endOffset);return new fo(t,n)}static fromOffsets(e,t,n){return new fo(new uo(e,t),new uo(e,n))}static trimmedRange(e){return function(e){if(!e.toString().trim().length)throw new RangeError("Range contains no non-whitespace text");if(e.startContainer.nodeType!==Node.TEXT_NODE)throw new RangeError("Range startContainer is not a text node");if(e.endContainer.nodeType!==Node.TEXT_NODE)throw new RangeError("Range endContainer is not a text node");const t=e.cloneRange();let n=!1,o=!1;const i={start:ro(e.startContainer.textContent,e.startOffset,io.Forwards),end:ro(e.endContainer.textContent,e.endOffset,io.Backwards)};if(i.start>=0&&(t.setStart(e.startContainer,i.start),n=!0),i.end>0&&(t.setEnd(e.endContainer,i.end),o=!0),n&&o)return t;if(!n){const{node:e,offset:n}=so(t,io.Forwards);e&&n>=0&&t.setStart(e,n)}
83
- if(!o){const{node:e,offset:n}=so(t,io.Backwards);e&&n>0&&t.setEnd(e,n)}return t}(fo.fromRange(e).toRange())}}const mo=".annotator-placeholder";function po(e){return!!e.parentElement&&null!==e.parentElement.closest(mo)}function go(e,t){const n=new Range;return e.compareBoundaryPoints(Range.START_TO_START,t)<=0?n.setStart(e.startContainer,e.startOffset):n.setStart(t.startContainer,t.startOffset),e.compareBoundaryPoints(Range.END_TO_END,t)>=0?n.setEnd(e.endContainer,e.endOffset):n.setEnd(t.endContainer,t.endOffset),n}function _o(e=document.getSelection()){if(!e||0===e.rangeCount)return null;let t=e.getRangeAt(0);for(let n=1;n<e.rangeCount;n++)t=go(t,e.getRangeAt(n));return t.collapsed?null:t}function bo(e){if(e.focusNode===e.anchorNode)return e.focusOffset<e.anchorOffset;return _o(e).startContainer===e.focusNode}function wo(e,t){try{const n=t.nodeValue?.length??t.childNodes.length;return e.comparePoint(t,0)<=0&&e.comparePoint(t,n)>=0}catch{return!1}}function vo(e,t){
84
- const n=e.commonAncestorContainer,o=n.ownerDocument.createNodeIterator(n,NodeFilter.SHOW_ALL);let i;for(;i=o.nextNode();)wo(e,i)&&t(i)}function yo(e){const t=_o(e);if(!t)return null;const n=function(e){const t=[];return vo(e,(e=>{Pn(e)&&!e.textContent.match(/^\s*$/)&&t.push(e)})),t.flatMap((t=>{const n=t.ownerDocument.createRange();if(n.selectNodeContents(t),t===e.startContainer&&n.setStart(t,e.startOffset),t===e.endContainer&&n.setEnd(t,e.endOffset),n.collapsed)return[];const o=Array.from(n.getClientRects());return n.detach(),o}))}(t);return 0===n.length?null:bo(e)?n[0]:n[n.length-1]}const xo="http://www.w3.org/2000/svg",No=["user-annotations","user-highlights","other-content"];class Co{constructor(e=document.body){this.root=e}highlightShape(e){const{shape:t,anchor:n}=e,o=document.createElement("hypothesis-highlight");if(o.className="hypothesis-shape-highlight","rect"===t.type){const e=t.right-t.left,n=t.bottom-t.top;o.style.left=100*t.left+"%",o.style.top=100*t.top+"%",o.style.width=`calc(${100*e}% - 6px)`,
85
- o.style.height=`calc(${100*n}% - 6px)`}else if("point"===t.type){const e=7;o.style.left=`calc(${100*t.x}% - ${e+3}px)`,o.style.top=`calc(${100*t.y}% - ${e+3}px)`,o.style.width=2*e+"px",o.style.height=2*e+"px",o.style.borderRadius="50%"}return n.append(o),[o]}highlightRange(e,t){const n=function(e){if(e.collapsed)return[];let t=e.commonAncestorContainer;t&&t.nodeType!==Node.ELEMENT_NODE&&(t=t.parentElement);if(!t)return[];const n=[],o=t.ownerDocument.createNodeIterator(t,NodeFilter.SHOW_TEXT);let i;for(;i=o.nextNode();){if(!wo(e,i))continue;const t=i;t===e.startContainer&&e.startOffset>0?t.splitText(e.startOffset):(t===e.endContainer&&e.endOffset<t.data.length&&t.splitText(e.endOffset),n.push(t))}return n}(e),o=n.length>0&&po(n[0]);let i=[],r=null,s=null;n.forEach((e=>{r&&r.nextSibling===e?s.push(e):(s=[e],i.push(s)),r=e}));const a=/^\s*$/;i=i.filter((e=>{const t=e[0].parentElement;return 1===t?.childNodes.length&&"SPAN"===t?.tagName||e.some((e=>!a.test(e.data)))}));const l=[];return i.forEach((e=>{
86
- const n=document.createElement("hypothesis-highlight");n.className=Ee("hypothesis-highlight",t);e[0].parentNode.replaceChild(n,e[0]),e.forEach((e=>n.appendChild(e))),l.push(n)})),o||function(e,t){if(0===e.length)return;const n=function(e){const t=e.closest(".page");if(!t)return null;const n=t.querySelector(".canvasWrapper > canvas");if(!n)return null;return n}(e[0]);if(!n||!n.parentElement)return;let o=n.parentElement.querySelector(".hypothesis-highlight-layer");if(!o){o=document.createElementNS(xo,"svg"),o.setAttribute("class","hypothesis-highlight-layer"),n.parentElement.appendChild(o),n.parentElement.style.position="relative";const e=o.style;e.position="absolute",e.left="0",e.top="0",e.width="100%",e.height="100%",e.mixBlendMode="multiply"}const i=n.getBoundingClientRect(),r=e.map((e=>{const n=e.getBoundingClientRect(),o=document.createElementNS(xo,"rect"),r=(n.left-i.left)/i.width,s=(n.top-i.top)/i.height,a=n.width/i.width,l=n.height/i.height;return o.setAttribute("x",100*r+"%"),
87
- o.setAttribute("y",100*s+"%"),o.setAttribute("width",100*a+"%"),o.setAttribute("height",100*l+"%"),o.setAttribute("class",Ee("hypothesis-svg-highlight",t)),e.classList.add("is-transparent"),e.svgHighlight=o,o}));o.append(...r)}(l,t),l}removeAllHighlights(){const e=Array.from(this.root.querySelectorAll("hypothesis-highlight"));this.removeHighlights(e)}removeHighlights(e){!function(e,t){e.forEach((e=>{e.svgHighlight?Ao(e.svgHighlight,t):e.classList.toggle("hypothesis-highlight-focused",t)}))}(e,!1);for(const t of e){if(t.parentNode){So(t,Array.from(t.childNodes))}t.svgHighlight&&t.svgHighlight.remove()}}setHighlightsFocused(e,t){e.forEach((e=>{e.svgHighlight?Ao(e.svgHighlight,t):e.classList.toggle("hypothesis-highlight-focused",t)}))}setHighlightsVisible(e){this.root.classList.toggle(ko,e)}getHighlightsFromPoint(e,t){return Eo(e,t)}}function So(e,t){const n=e.parentNode;t.forEach((t=>n.insertBefore(t,e))),e.remove()}function Ao(e,t){const n=e.parentNode,o=e.getAttribute("data-focused-id")
88
- ;if(Boolean(o)!==t)if(t){e.setAttribute("data-focused-id",nn(8));const t=e.cloneNode();t.setAttribute("data-is-focused","data-is-focused"),n.append(t)}else{const t=n.querySelector(`[data-focused-id="${o}"][data-is-focused]`);t?.remove(),e.removeAttribute("data-focused-id")}}const ko="hypothesis-highlights-always-on";function Eo(e,t){const n=`.${ko}`,o=document.elementsFromPoint(e,t).filter((e=>"hypothesis-highlight"===e.localName&&e.closest(n))),i=[];for(const o of document.querySelectorAll("hypothesis-highlight.hypothesis-shape-highlight")){if(!o.closest(n))continue;const r=o.getBoundingClientRect();e>=r.left&&e<r.right&&t>=r.top&&t<r.bottom&&i.push(o)}return[...o,...i]}function Ro(e){Mo(To(e)),function(e){for(const[t,n]of function(e){const t=new Map;for(const n of(e??document).getElementsByClassName("hypothesis-highlight-layer"))t.set(n,Array.from(n.querySelectorAll(".hypothesis-svg-highlight")));return t}(e)){n.every(((e,t,n)=>0===t||Oo(e)>=Oo(n[t-1])))||(n.sort(((e,t)=>Oo(e)-Oo(t))),
89
- t.replaceChildren(...n))}}(e)}const Po=e=>"hypothesis-highlight"===e.tagName.toLowerCase();function To(e){let t;return t=Po(e)?Array.from(e.children).filter(Po):Array.from(e.getElementsByTagName("hypothesis-highlight")).filter((e=>!e.parentElement||!Po(e.parentElement))),t}function Mo(e,t="",n=0,o=0){for(const i of e){const e=No.find((e=>i.classList.contains(e)))??"other-content",r=t&&e===t?o+1:0;i.setAttribute("data-nesting-level",`${n}`),i.setAttribute("data-cluster-level",`${r}`),i.svgHighlight&&(i.svgHighlight.setAttribute("data-nesting-level",`${n}`),i.svgHighlight.setAttribute("data-cluster-level",`${r}`)),Mo(To(i),e,n+1,r)}}function Oo(e){return e.getAttribute("data-is-focused")?Number.MAX_SAFE_INTEGER:parseInt(e.getAttribute("data-nesting-level")??"0",10)}function Io(e){const t=[];return e.forEach((({annotation:e,highlights:n})=>{if(!n?.length)return;const{top:o,bottom:i}=function(e){const t=e.map((e=>e.getBoundingClientRect()));return t.reduce(((e,t)=>({top:Math.min(e.top,t.top),
90
- left:Math.min(e.left,t.left),bottom:Math.max(e.bottom,t.bottom),right:Math.max(e.right,t.right)})))}(n);o>=i||t.push({tag:e.$tag,top:o,bottom:i})})),t.sort(((e,t)=>e.top-t.top)),t}class Lo{constructor({contentContainer:e,hostRPC:t}){this._hostRPC=t,this._updatePending=!1,this._anchors=[],this._listeners=new ge,this._listeners.add(window,"resize",(()=>this.update())),this._listeners.add(window,"scroll",(()=>this.update())),this._listeners.add(e,"scroll",(()=>this.update()),{capture:!0})}destroy(){this._listeners.removeAll()}update(e){e&&(this._anchors=e),this._updatePending||(this._updatePending=!0,requestAnimationFrame((()=>{const e=Io(this._anchors);this._hostRPC.call("anchorsChanged",e),this._updatePending=!1})))}}function Bo(e){const t=Math.min(e.left,e.right),n=Math.max(e.left,e.right);return{type:"rect",left:t,top:Math.min(e.top,e.bottom),right:n,bottom:Math.max(e.top,e.bottom)}}class Ho extends Error{constructor(e,t="Drawing failed"){super(t),this.kind=e}}class Fo{constructor(e){this._container=e,
91
- this._tool="rect"}destroy(){this.cancel()}async draw(e){this._tool=e,this.cancel("restarted");const t=document.createElementNS("http://www.w3.org/2000/svg","svg");t.setAttribute("data-testid","surface"),t.style.cursor="crosshair",t.style.touchAction="none",t.style.position="absolute",t.setAttribute("width","100%"),t.setAttribute("height","100%"),t.style.left="0px",t.style.top="0px",t.style.zIndex="10",this._container.append(t),this._surface=t;const{promise:n,resolve:o,reject:i}=function(){let e,t;return{promise:new Promise(((n,o)=>{e=n,t=o})),resolve:e,reject:t}}();return this._drawEnd=o,this._drawError=i,this._surface.addEventListener("pointerdown",(e=>{switch(this._tool){case"rect":this._shape={type:"rect",left:e.clientX,top:e.clientY,right:e.clientX,bottom:e.clientY};break;case"point":this._shape={type:"point",x:e.clientX,y:e.clientY}}this._renderSurface()})),this._surface.addEventListener("pointermove",(e=>{if(this._shape){switch(this._shape.type){case"rect":this._shape.right=e.clientX,
92
- this._shape.bottom=e.clientY;break;case"point":this._shape.x=e.clientX,this._shape.y=e.clientY}this._renderSurface()}})),this._surface.addEventListener("pointerup",(e=>{if(this._shape){switch(this._shape.type){case"rect":this._shape.right=e.clientX,this._shape.bottom=e.clientY,o(Bo(this._shape));break;case"point":this._shape.x=e.clientX,this._shape.y=e.clientY,o(this._shape)}this._abortDraw?.abort(),e.stopPropagation()}})),this._surface.addEventListener("wheel",(e=>{let t=Math.abs(e.deltaY),n=Math.abs(e.deltaX);for(const o of document.elementsFromPoint(e.clientX,e.clientY)){const i=o.scrollLeft;o.scrollLeft+=n*Math.sign(e.deltaX),n-=Math.abs(o.scrollLeft-i);const r=o.scrollTop;o.scrollTop+=t*Math.sign(e.deltaY),t-=Math.abs(o.scrollTop-r)}})),this._abortDraw=new AbortController,document.body.addEventListener("keydown",(e=>{"Escape"===e.key&&(this._drawError&&this._drawError(new Ho("canceled","Drawing canceled")),this._abortDraw?.abort())}),{signal:this._abortDraw.signal}),this._abortDraw.signal.onabort=()=>{
93
- this._surface?.remove(),this._shape=void 0,this._surface=void 0,this._drawError=void 0,this._drawEnd=void 0,this._abortDraw=void 0},this._renderSurface(),n}cancel(e="canceled"){this._drawError&&this._drawError(new Ho(e,"Drawing canceled")),this._abortDraw?.abort()}_renderSurface(){if(this._surface)if("rect"===this._shape?.type){const e=Bo(this._shape);F(Pe(w,{children:[Pe("rect",{stroke:"white","stroke-dasharray":"5","stroke-width":"1px",fill:"grey","fill-opacity":"0.5",x:e.left,y:e.top,width:e.right-e.left,height:e.bottom-e.top}),Pe("rect",{stroke:"grey","stroke-dasharray":"5","stroke-dashoffset":"5","stroke-width":"1px",fill:"none",x:e.left,y:e.top,width:e.right-e.left,height:e.bottom-e.top})]}),this._surface)}else if("point"===this._shape?.type){const e=this._shape;F(Pe("circle",{stroke:"black","stroke-width":"1px",fill:"yellow",cx:e.x,cy:e.y,r:5}),this._surface)}else F(null,this._surface)}}class Do extends CustomEvent{constructor(e){super("hypothesis:layoutchange",{bubbles:!0,cancelable:!1,detail:e})}}
94
- const Vo=new Set;function Uo(...e){const t=e.join();Vo.has(t)||(console.warn(...e),Vo.add(t))}Uo.reset=()=>{Vo.clear()};const qo=["pdf_image_annotation","styled_highlight_clusters"];class $o extends an{constructor(e=qo){super(),this._flags=new Map,this._knownFlags=e}update(e){this._flags.clear();for(const[t,n]of Object.entries(e))this._flags.set(t,n);this.emit("flagsChanged")}flagEnabled(e){return this._knownFlags.includes(e)?this._flags.get(e)??!1:(Uo("Looked up unknown feature",e),!1)}allFlags(){return Object.fromEntries(this._flags)}}function zo({cluster:e,label:t,onChange:n,currentStyles:o,highlightStyles:i}){const r=o[e],s="transparent"===r;return Pe("div",{className:"space-y-2",children:[Pe("div",{className:"flex items-center gap-x-2 text-annotator-base",children:Pe("div",{className:"grow text-color-text px-2 py-1 rounded",style:{backgroundColor:i[r].color},children:t})}),Pe("div",{className:"flex items-center gap-x-2",children:Object.keys(i).map((t=>Pe("div",{className:"relative",children:[Pe("input",{
95
- className:Ee("absolute w-6 h-6","opacity-[.00001]","cursor-pointer"),name:e,id:`hypothesis-${e}-${t}`,checked:r===t,onChange:n,type:"radio",value:t}),Pe("label",{className:"block",htmlFor:`${e}-${t}`,children:[Pe("div",{style:{backgroundColor:i[t].color},className:Ee("block w-6 h-6 rounded-full flex items-center justify-center",{"border-2 border-slate-0":r!==t,"border-2 border-slate-3":r===t}),children:"transparent"===t&&Pe(et,{className:Ee("w-3 h-3",{"text-slate-3":!s,"text-slate-7":s})})}),Pe("span",{className:"sr-only",children:t})]})]},`${e}-${t}`)))})]})}function Wo({active:e,availableStyles:t,currentStyles:n,onStyleChange:o}){const i=re((e=>{const t=e.target,n=t.name,i=t.value;o(n,i)}),[o]),[r,s]=ee(!1);return e?Pe(Me,{classes:"overflow-hidden",children:Pe("div",{className:"flex flex-col text-annotator-base text-color-text",children:[Pe(Ct,{classes:"rounded-none","data-testid":"control-toggle-button",onClick:()=>s(!r),title:r?"Hide highlight settings":"Show highlight settings",children:Pe(w,r?{
96
- children:[Pe(Ve,{}),Pe("span",{children:"Highlight Appearance"})]}:{children:[Pe(ze,{}),Pe(nt,{})]})}),r&&Pe(Ie,{"data-testid":"cluster-style-controls",size:"sm",children:[Pe(zo,{highlightStyles:t,label:"My annotations",cluster:"user-annotations",onChange:i,currentStyles:n}),Pe(zo,{highlightStyles:t,label:"My highlights",cluster:"user-highlights",onChange:i,currentStyles:n}),Pe(zo,{highlightStyles:t,label:"Everybody's content",cluster:"other-content",onChange:i,currentStyles:n})]})]})}):null}const jo={transparent:{color:"transparent",secondColor:"transparent",thirdColor:"transparent"},pink:{color:"var(--hypothesis-color-pink)",secondColor:"var(--hypothesis-color-pink-1)",thirdColor:"var(--hypothesis-color-pink-2)"},orange:{color:"var(--hypothesis-color-orange)",secondColor:"var(--hypothesis-color-orange-1)",thirdColor:"var(--hypothesis-color-orange-2)"},yellow:{color:"var(--hypothesis-color-yellow)",secondColor:"var(--hypothesis-color-yellow-1)",thirdColor:"var(--hypothesis-color-yellow-2)"},green:{
97
- color:"var(--hypothesis-color-green)",secondColor:"var(--hypothesis-color-green-1)",thirdColor:"var(--hypothesis-color-green-2)"},purple:{color:"var(--hypothesis-color-purple)",secondColor:"var(--hypothesis-color-purple-1)",thirdColor:"var(--hypothesis-color-purple-2)"},grey:{color:"var(--hypothesis-color-grey)",secondColor:"var(--hypothesis-color-grey-1)",thirdColor:"var(--hypothesis-color-grey-2)"}},Xo={"other-content":"yellow","user-annotations":"orange","user-highlights":"purple"};class Yo{constructor(e,t){this._element=e,this._features=t.features,this._container=new eo("highlight-cluster-toolbar",(()=>this._render())),this._element.appendChild(this._container.element),Object.assign(this._container.element.style,{position:"fixed",top:`${this._element.offsetTop+4}px`,left:"4px"}),this.appliedStyles=Xo,this._init(),this._features.on("flagsChanged",(()=>{this._activate(this._isActive())})),this._container.render()}destroy(){clearTimeout(this._updateTimeout),this._activate(!1),this._container.destroy()}
98
- scheduleClusterUpdates(){clearTimeout(this._updateTimeout),this._updateTimeout=setTimeout((()=>this._updateClusters()),100)}_init(){for(const e of Object.keys(this.appliedStyles))this._setClusterStyles(e,this.appliedStyles[e]);this._activate(this._isActive())}_updateClusters(){this._isActive()&&Ro(this._element)}_isActive(){return this._features.flagEnabled("styled_highlight_clusters")}_activate(e){this._element.classList.toggle("hypothesis-highlights-clustered",e),this._container.render()}_setClusterStyle(e,t){document.documentElement.style.setProperty(e,t)}_setClusterStyles(e,t){const n=jo[t];for(const t of Object.keys(n))this._setClusterStyle(`--hypothesis-${e}-${t}`,n[t])}_onChangeClusterStyle(e,t){this.appliedStyles[e]=t,this._setClusterStyles(e,t),this._container.render()}_render(){return Pe(Wo,{active:this._isActive(),availableStyles:jo,currentStyles:this.appliedStyles,onStyleChange:(e,t)=>this._onChangeClusterStyle(e,t)})}}function Ko(e){return e.split("").reverse().join("")}function Go(e){
99
- return(e|-e)>>31&1}function Qo(e,t,n,o){let i=e.P[n],r=e.M[n];const s=o>>>31,a=t[n]|s,l=a|r,c=(a&i)+i^i|a;let h=r|~(c|i),d=i&c;const u=Go(h&e.lastRowMask[n])-Go(d&e.lastRowMask[n]);return h<<=1,d<<=1,d|=s,h|=Go(o)-s,i=d|~(l|h),r=h&l,e.P[n]=i,e.M[n]=r,u}function Jo(e,t,n){if(0===t.length)return[];n=Math.min(n,t.length);const o=[],i=32,r=Math.ceil(t.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<<(t.length-1)%i;const a=new Uint32Array(r+1),l=new Map,c=[];for(let e=0;e<256;e++)c.push(a);for(let e=0;e<t.length;e+=1){const n=t.charCodeAt(e);if(l.has(n))continue;const o=new Uint32Array(r+1);l.set(n,o),n<c.length&&(c[n]=o);for(let e=0;e<=r;e+=1){o[e]=0;for(let r=0;r<i;r+=1){const s=e*i+r;if(s>=t.length)continue;t.charCodeAt(s)===n&&(o[e]|=1<<r)}}}let h=Math.max(0,Math.ceil(n/i)-1);const d=new Uint32Array(r+1);for(let e=0;e<=h;e+=1)d[e]=(e+1)*i;d[r]=t.length;for(let e=0;e<=h;e+=1)s.P[e]=-1,s.M[e]=0
100
- ;for(let u=0;u<e.length;u+=1){const f=e.charCodeAt(u);let m;f<c.length?m=c[f]:(m=l.get(f),void 0===m&&(m=a));let p=0;for(let e=0;e<=h;e+=1)p=Qo(s,m,e,p),d[e]+=p;if(d[h]-p<=n&&h<r&&(1&m[h+1]||p<0)){let e;if(h+=1,s.P[h]=-1,s.M[h]=0,h===r){const n=t.length%i;e=0===n?i:n}else e=i;d[h]=d[h-1]+e-p+Qo(s,m,h,p)}else for(;h>0&&d[h]>=n+i;)h-=1;h===r&&d[h]<=n&&(d[h]<n&&o.splice(0,o.length),o.push({start:-1,end:u+1,errors:d[h]}),n=d[h])}return o}function Zo(e,t,n){return function(e,t,n){const o=Ko(t);return n.map((n=>{const i=Math.max(0,n.end-t.length-n.errors);return{start:Jo(Ko(e.slice(i,n.end)),o,n.errors).reduce(((e,t)=>n.end-t.end<e?n.end-t.end:e),n.end),end:n.end,errors:n.errors}}))}(e,t,Jo(e,t,n))}function ei(e,t,n){let o=0;const i=[];for(;-1!==o;)o=e.indexOf(t,o),-1!==o&&(i.push({start:o,end:o+t.length,errors:0}),o+=1);return i.length>0?i:Zo(e,t,n)}function ti(e,t){if(0===t.length||0===e.length)return 0;return 1-ei(e,t,t.length)[0].errors/t.length}function ni(e,t,n={}){if(0===t.length)return null
101
- ;const o=Math.min(256,t.length/2),i=ei(e,t,o);if(0===i.length)return null;const r=o=>{const i=1-o.errors/t.length,r=n.prefix?ti(e.slice(Math.max(0,o.start-n.prefix.length),o.start),n.prefix):1,s=n.suffix?ti(e.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)/e.length}return(50*i+20*r+20*s+2*a)/92},s=i.map((e=>({start:e.start,end:e.end,score:r(e)})));return s.sort(((e,t)=>t.score-e.score)),s[0]}function oi(e){const t=function(e){const t=e.nodeName.toLowerCase();return"#text"===t?"text()":t}(e),n=function(e){let t=0,n=e;for(;n;)n.nodeName===e.nodeName&&(t+=1),n=n.previousSibling;return t}(e);return`${t}[${n}]`}function ii(e,t){let n="",o=e;for(;o!==t;){if(!o)throw new Error("Node is not a descendant of root");n=oi(o)+"/"+n,o=o.parentNode}return n="/"+n,n=n.replace(/\/$/,""),n}function ri(e,t,n){t=t.toUpperCase();let o=-1;for(let i=0;i<e.children.length;i++){const r=e.children[i];if(r.nodeName.toUpperCase()===t&&(++o,o===n))return r}return null}
102
- function si(e,t=document.body){try{return function(e,t){if(null===e.match(/^(\/[A-Za-z0-9-]+(\[[0-9]+\])?)+$/))throw new Error("Expression is not a simple XPath");const n=e.split("/");let o=t;n.shift();for(const e of n){let t,n;const i=e.indexOf("[");if(-1!==i){t=e.slice(0,i);const o=e.slice(i+1,e.indexOf("]"));if(n=parseInt(o)-1,n<0)return null}else t=e,n=0;const r=ri(o,t,n);if(!r)return null;o=r}return o}(e,t)}catch{return document.evaluate("."+e,t,null,XPathResult.FIRST_ORDERED_NODE_TYPE,null).singleNodeValue}}class ai{constructor(e,t){this.root=e,this.range=t}static fromRange(e,t){return new ai(e,t)}static fromSelector(e,t){const n=si(t.startContainer,e);if(!n)throw new Error("Failed to resolve startContainer XPath");const o=si(t.endContainer,e);if(!o)throw new Error("Failed to resolve endContainer XPath");const i=uo.fromCharOffset(n,t.startOffset),r=uo.fromCharOffset(o,t.endOffset),s=new fo(i,r).toRange();return new ai(e,s)}toRange(){return this.range}toSelector(){
103
- const e=fo.fromRange(this.range).toRange(),t=fo.fromRange(e),n=ii(t.start.element,this.root),o=ii(t.end.element,this.root);return{type:"RangeSelector",startContainer:n,startOffset:t.start.offset,endContainer:o,endOffset:t.end.offset}}}class li{constructor(e,t,n){this.root=e,this.start=t,this.end=n}static fromRange(e,t){const n=fo.fromRange(t).relativeTo(e);return new li(e,n.start.offset,n.end.offset)}static fromSelector(e,t){return new li(e,t.start,t.end)}toSelector(){return{type:"TextPositionSelector",start:this.start,end:this.end}}toRange(){return fo.fromOffsets(this.root,this.start,this.end).toRange()}}class ci{constructor(e,t,n={}){this.root=e,this.exact=t,this.context=n}static fromRange(e,t){const n=e.textContent,o=fo.fromRange(t).relativeTo(e),i=o.start.offset,r=o.end.offset;return new ci(e,n.slice(i,r),{prefix:n.slice(Math.max(0,i-32),i),suffix:n.slice(r,Math.min(n.length,r+32))})}static fromSelector(e,t){const{prefix:n,suffix:o}=t;return new ci(e,t.exact,{prefix:n,suffix:o})}toSelector(){return{
104
- type:"TextQuoteSelector",exact:this.exact,prefix:this.context.prefix,suffix:this.context.suffix}}toRange(e={}){return this.toPositionAnchor(e).toRange()}toPositionAnchor(e={}){const t=ni(this.root.textContent,this.exact,{...this.context,hint:e.hint});if(!t)throw new Error("Quote not found");return new li(this.root,t.start,t.end)}}function hi(e){const t=parseFloat(e);return!Number.isFinite(t)||t<0?null:t}function di(e){return e instanceof Element?e:e.parentElement}function ui(e,t=e){const n=hi(e?.getAttribute("data-time-start")??""),o=hi(t?.getAttribute("data-time-end")??"");return"number"!=typeof n||"number"!=typeof o||o<n?null:[n,o]}class fi{constructor(e,t,n){this.root=e,this.start=t,this.end=n}static fromRange(e,t){const n=di(t.startContainer)?.closest("[data-time-start]"),o=di(t.endContainer)?.closest("[data-time-end]"),i=ui(n,o);if(!i)return null;const[r,s]=i;return new fi(e,r,s)}toRange(){const e=[...this.root.querySelectorAll("[data-time-start]")].map((e=>{const t=ui(e);if(!t)return null;const[n,o]=t
105
- ;return{element:e,start:n,end:o}})).filter((e=>null!==e));e.sort(((e,t)=>e.start-t.start));const t=function(e,t){for(let n=e.length-1;n>=0;n--)if(t(e[n]))return n;return-1}(e,(e=>e.start<=this.start&&e.end>=this.start));if(-1===t)throw new Error("Start segment not found");const n=t+e.slice(t).findIndex((e=>e.start<=this.end&&e.end>=this.end));if(-1===n)throw new Error("End segment not found");const o=new Range;o.setStart(e[t].element,0);const i=e[n].element;return o.setEnd(i,i.childNodes.length),o}static fromSelector(e,t){const{start:n,end:o}=t;return new fi(e,n,o)}toSelector(){return{type:"MediaTimeSelector",start:this.start,end:this.end}}}async function mi(e,t){return e.toRange(t)}function pi(e,t,n){const o=e[t];if("function"!=typeof o)throw new Error("Can only intercept functions");return e[t]=(...t)=>{const i=o.call(e,...t);return n(...t),i},()=>{e[t]=o}}function gi(e){return e.replace(/#.*/,"")}class _i{constructor(e,t=(()=>location.href)){this._listeners=new ge;let n=t();const o=(o=t())=>{
106
- gi(n)!==gi(o)&&(n=o,e(o))},i=function(){const e=window.navigation;return"function"==typeof Navigation&&e instanceof Navigation?e:null}();if(i)this._listeners.add(i,"navigatesuccess",(()=>o()));else{const e=[pi(window.history,"pushState",(()=>o())),pi(window.history,"replaceState",(()=>o()))];this._unpatchHistory=()=>e.forEach((e=>e())),this._listeners.add(window,"popstate",(()=>o()))}}disconnect(){this._unpatchHistory?.(),this._listeners.removeAll()}}var bi,wi;var vi=function(){if(wi)return bi;wi=1;var e="complete",t="canceled";function n(e,t,n){e.self===e?e.scrollTo(t,n):(e.scrollLeft=t,e.scrollTop=n)}function o(t){var i=t._scrollSettings;if(i){var r=i.maxSynchronousAlignments,s=function(e,t){var n,o,i,r,s,a,l,c=e.align,h=e.target.getBoundingClientRect(),d=c&&null!=c.left?c.left:.5,u=c&&null!=c.top?c.top:.5,f=c&&null!=c.leftOffset?c.leftOffset:0,m=c&&null!=c.topOffset?c.topOffset:0,p=d,g=u;if(e.isWindow(t))a=Math.min(h.width,t.innerWidth),l=Math.min(h.height,t.innerHeight),
107
- o=h.left+t.pageXOffset-t.innerWidth*p+a*p,i=h.top+t.pageYOffset-t.innerHeight*g+l*g,o-=f,i-=m,o=e.align.lockX?t.pageXOffset:o,i=e.align.lockY?t.pageYOffset:i,r=o-t.pageXOffset,s=i-t.pageYOffset;else{a=h.width,l=h.height,n=t.getBoundingClientRect();var _=h.left-(n.left-t.scrollLeft),b=h.top-(n.top-t.scrollTop);o=_+a*p-t.clientWidth*p,i=b+l*g-t.clientHeight*g,o-=f,i-=m,o=Math.max(Math.min(o,t.scrollWidth-t.clientWidth),0),i=Math.max(Math.min(i,t.scrollHeight-t.clientHeight),0),o=e.align.lockX?t.scrollLeft:o,i=e.align.lockY?t.scrollTop:i,r=o-t.scrollLeft,s=i-t.scrollTop}return{x:o,y:i,differenceX:r,differenceY:s}}(i,t),a=Date.now()-i.startTime,l=Math.min(1/i.time*a,1);if(i.endIterations>=r)return n(t,s.x,s.y),t._scrollSettings=null,i.end(e);var c=1-i.ease(l);if(n(t,s.x-s.differenceX*c,s.y-s.differenceY*c),a>=i.time)return i.endIterations++,i.scrollAncestor&&o(i.scrollAncestor),void o(t);!function(e){if("requestAnimationFrame"in window)return window.requestAnimationFrame(e);setTimeout(e,16)}(o.bind(null,t))}}
108
- function i(e){return e.self===e}function r(e){return"pageXOffset"in e||(e.scrollHeight!==e.clientHeight||e.scrollWidth!==e.clientWidth)&&"hidden"!==getComputedStyle(e).overflow}function s(){return!0}function a(e){if(e.assignedSlot)return a(e.assignedSlot);if(e.parentElement)return"body"===e.parentElement.tagName.toLowerCase()?e.parentElement.ownerDocument.defaultView||e.parentElement.ownerDocument.ownerWindow:e.parentElement;if(e.getRootNode){var t=e.getRootNode();if(11===t.nodeType)return t.host}}return bi=function(n,l,c){if(n){"function"==typeof l&&(c=l,l=null),l||(l={}),l.time=isNaN(l.time)?1e3:l.time,l.ease=l.ease||function(e){return 1-Math.pow(1-e,e/2)},l.align=l.align||{};var h=a(n),d=1,u=l.validTarget||s,f=l.isScrollable;l.debug&&(console.log("About to scroll to",n),h||console.error("Target did not have a parent, is it mounted in the DOM?"));for(var m=[];h;)if(l.debug&&console.log("Scrolling parent node",h),u(h,d)&&(f?f(h,r):r(h))&&(d++,m.push(h)),!(h=a(h))){p(e);break}
109
- return m.reduce(((e,r,s)=>function(e,n,r,s,a){var l,c=!n._scrollSettings,h=n._scrollSettings,d=Date.now(),u={passive:!0};function f(e){n._scrollSettings=null,n.parentElement&&n.parentElement._scrollSettings&&n.parentElement._scrollSettings.end(e),r.debug&&console.log("Scrolling ended with type",e,"for",n),a(e),l&&(n.removeEventListener("touchstart",l,u),n.removeEventListener("wheel",l,u))}h&&h.end(t);var m=r.maxSynchronousAlignments;return null==m&&(m=3),n._scrollSettings={startTime:d,endIterations:0,target:e,time:r.time,ease:r.ease,align:r.align,isWindow:r.isWindow||i,maxSynchronousAlignments:m,end:f,scrollAncestor:s},"cancellable"in r&&!r.cancellable||(l=f.bind(null,t),n.addEventListener("touchstart",l,u),n.addEventListener("wheel",l,u)),c&&o(n),l}(n,r,l,m[s+1],p)),null)}function p(e){--d||c&&c(e)}},bi}(),yi=Ne(vi);function xi(e,t,n){return e+n*(t-e)}async function Ni(e,t,{maxDuration:n=500}={}){const o=e.scrollTop,i=t,r=Date.now(),s=Math.min(Math.abs(i-o)/3,n);let a=0;for(;a<1;)await new Promise((e=>{
110
- requestAnimationFrame(e)})),a=Math.min(1,(Date.now()-r)/s),e.scrollTop=xi(o,i,a)}function Ci(e,t=document.baseURI){return new URL(e,t).href.toString().replace(/#.*/,"")}class Si{constructor(e={}){this.document=e.document||document}uri(){let e=this._getDocumentHref();try{e=decodeURIComponent(e)}catch(e){console.error("Error decoding URI:",e)}const t=this._getLinks();for(const n of t)"canonical"===n.rel&&(e=n.href);return e}getDocumentMetadata(){const e={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:")},t=this._getFavicon();t&&(e.favicon=t),e.title=this._getTitle(e),e.link=this._getLinks(e);const n=e.link.find((e=>e.href.startsWith("urn:x-dc")));return n&&(e.documentFingerprint=n.href),e}_getMetaTags(e,t){const n={}
111
- ;for(const o of Array.from(this.document.querySelectorAll("meta"))){const i=o.getAttribute(e),{content:r}=o;if(i&&r){const e=i.match(RegExp(`^${t}(.+)$`,"i"));if(e){const t=e[1].toLowerCase();n[t]?n[t].push(r):n[t]=[r]}}}return n}_getTitle(e){return e.highwire.title?e.highwire.title[0]:e.eprints.title?e.eprints.title[0]:e.prism.title?e.prism.title[0]:e.facebook.title?e.facebook.title[0]:e.twitter.title?e.twitter.title[0]:e.dc.title?e.dc.title[0]:this.document.title}_getLinks(e={dc:{},highwire:{}}){const t=[{href:this._getDocumentHref()}],n=Array.from(this.document.querySelectorAll("link"));for(const e of n)if(["alternate","canonical","bookmark","shortlink"].includes(e.rel)){if("alternate"===e.rel){if(e.type&&e.type.match(/^application\/(rss|atom)\+xml/))continue;if(e.hreflang)continue}try{const n=this._absoluteUrl(e.href);t.push({href:n,rel:e.rel,type:e.type})}catch{}}for(const n of Object.keys(e.highwire)){const o=e.highwire[n];if("pdf_url"===n)for(const e of o)try{t.push({href:this._absoluteUrl(e),
112
- type:"application/pdf"})}catch{}if("doi"===n)for(let e of o)"doi:"!==e.slice(0,4)&&(e=`doi:${e}`),t.push({href:e})}for(const n of Object.keys(e.dc)){const o=e.dc[n];if("identifier"===n)for(const e of o)"doi:"===e.slice(0,4)&&t.push({href:e})}const o=e.dc["relation.ispartof"],i=e.dc.identifier;if(o&&i){const e=o[o.length-1],n=i[i.length-1],r="urn:x-dc:"+encodeURIComponent(e)+"/"+encodeURIComponent(n);t.push({href:r})}return t}_getFavicon(){let e=null;for(const t of Array.from(this.document.querySelectorAll("link")))if(["shortcut icon","icon"].includes(t.rel))try{e=this._absoluteUrl(t.href)}catch{}return e}_absoluteUrl(e){return Ci(e,this.document.baseURI)}_getDocumentHref(){const{href:e}=this.document.location,t=["http:","https:","file:"],n=new URL(e).protocol;return t.includes(n)?e:this.document.baseURI&&t.includes(new URL(this.document.baseURI).protocol)?this.document.baseURI:e}}class Ai extends an{constructor({features:e,container:t=document.body,sideBySideOptions:n}){super(),this.featureFlags=e,
113
- this.container=t,this._htmlMeta=new Si,this._prevURI=this._htmlMeta.uri(),this._sideBySideEnabled=!0,this._sideBySideOptions=n??{mode:"auto"},this._sideBySideActive=!1,this._lastLayout=null,this._navObserver=new _i((()=>this._checkForURIChange())),this._metaObserver=new MutationObserver((()=>this._checkForURIChange())),this._metaObserver.observe(document.head,{childList:!0,subtree:!0,attributes:!0,attributeFilter:["rel","href","name","content"]}),this._flagsChanged=()=>{},this.featureFlags.on("flagsChanged",this._flagsChanged)}anchor(e,t){return function(e,t,n={}){let o=null,i=null,r=null,s=null;for(const e of t)switch(e.type){case"TextPositionSelector":i=e,n.hint=i.start;break;case"TextQuoteSelector":r=e;break;case"RangeSelector":s=e;break;case"MediaTimeSelector":o=e}const a=e=>{if(r?.exact&&e.toString()!==r.exact)throw new Error("quote mismatch");return e};let l=Promise.reject("unable to anchor");if(s){const t=s;l=l.catch((()=>mi(ai.fromSelector(e,t),n).then(a)))}if(i){const t=i
114
- ;l=l.catch((()=>mi(li.fromSelector(e,t),n).then(a)))}if(r){const t=r;l=l.catch((()=>mi(ci.fromSelector(e,t),n)))}if(o){const t=o;l=l.catch((()=>fi.fromSelector(e,t).toRange()))}return l}(e,t)}describe(e,t){if(t instanceof Range)return function(e,t){const n=[fi,ai,li,ci],o=[];for(const i of n)try{const n=i.fromRange(e,t);n&&o.push(n.toSelector())}catch{}return o}(e,t);throw new Error("Unsupported region type")}_checkForURIChange(){const e=this._htmlMeta.uri();e!==this._prevURI&&(this._prevURI=e,this.emit("uriChanged",e))}getAnnotatableRange(e){try{return fo.trimmedRange(e)}catch(e){if(e instanceof RangeError)return null;throw e}}canStyleClusteredHighlights(){return!0}destroy(){this._deactivateSideBySide(),this._navObserver.disconnect(),this._metaObserver.disconnect(),this.featureFlags.off("flagsChanged",this._flagsChanged),super.destroy()}contentContainer(){return this.container}fitSideBySide(e){this._lastLayout=e
115
- ;const t=window.innerWidth-e.width,n=this._sideBySideEnabled&&"auto"===this._sideBySideOptions.mode&&e.expanded&&t>=480;return n?this._activateSideBySide(e.width):this._sideBySideActive&&this._deactivateSideBySide(),this._sideBySideActive=n,this.container.classList.toggle("hypothesis-sidebyside-active",this._sideBySideActive),n}sideBySideActive(){return this._sideBySideActive}supportedTools(){return["selection"]}_activateSideBySide(e){const t=e+12,n=e=>parseInt(window.getComputedStyle(e).marginLeft,10);Hn((()=>{document.body.style.marginLeft="",document.body.style.marginRight="";const e=n(document.body);document.body.style.marginRight=`${t}px`;const o=function(e){const t=new Map,n=new Map,o=Tn.join(","),i=Array.from(e.querySelectorAll(o)).map((e=>({rect:e.getBoundingClientRect(),textLength:e.textContent.length}))).filter((({rect:e})=>e.width>0&&e.height>0)).sort(((e,t)=>t.textLength-e.textLength)).slice(0,15);if(i.forEach((({rect:e})=>{let o=t.get(e.left)??0;o+=1,t.set(e.left,o);let i=n.get(e.right)??0;i+=1,
116
- n.set(e.right,i)})),0===t.size||0===n.size)return null;const r=[...t.entries()].sort(((e,t)=>t[1]-e[1])),s=[...n.entries()].sort(((e,t)=>t[1]-e[1])),[a]=r[0],[l]=s[0];return{left:a,right:l}}(document.body);if(o){const i=Math.max(0,window.innerWidth-t-o.right);if(i>0){const e=Math.max(0,t-i);document.body.style.marginRight=`${e}px`}n(document.body)>e&&(document.body.style.marginLeft=`${e}px`),o.left<12&&(document.body.style.marginLeft="12px")}else document.body.style.marginLeft="",document.body.style.marginRight=""}))}_deactivateSideBySide(){Hn((()=>{document.body.style.marginLeft="",document.body.style.marginRight=""}))}async getMetadata(){return this._htmlMeta.getDocumentMetadata()}async uri(){return this._htmlMeta.uri()}async scrollToAnchor(e){const t=e.highlights?.[0];t&&await async function(e,{maxDuration:t=500}={}){const n=e.closest("body");n&&"BODY"!==n.tagName&&Object.defineProperty(n,"tagName",{value:"BODY",configurable:!0});const o=e.closest("details");o&&!o.hasAttribute("open")&&(o.open=!0),
117
- await new Promise((n=>yi(e,{time:t},n)))}(t)}}var ki,Ei;var Ri=function(){if(Ei)return ki;Ei=1;var e=NaN,t="[object Symbol]",n=/^\s+|\s+$/g,o=/^[-+]0x[0-9a-f]+$/i,i=/^0b[01]+$/i,r=/^0o[0-7]+$/i,s=parseInt,a="object"==typeof xe&&xe&&xe.Object===Object&&xe,l="object"==typeof self&&self&&self.Object===Object&&self,c=a||l||Function("return this")(),h=Object.prototype.toString,d=Math.max,u=Math.min,f=function(){return c.Date.now()};function m(e){var t=typeof e;return!!e&&("object"==t||"function"==t)}function p(a){if("number"==typeof a)return a;if(function(e){return"symbol"==typeof e||function(e){return!!e&&"object"==typeof e}(e)&&h.call(e)==t}(a))return e;if(m(a)){var l="function"==typeof a.valueOf?a.valueOf():a;a=m(l)?l+"":l}if("string"!=typeof a)return 0===a?a:+a;a=a.replace(n,"");var c=i.test(a);return c||r.test(a)?s(a.slice(2),c?2:8):o.test(a)?e:+a}return ki=function(e,t,n){var o,i,r,s,a,l,c=0,h=!1,g=!1,_=!0;if("function"!=typeof e)throw new TypeError("Expected a function");function b(t){var n=o,r=i
118
- ;return o=i=void 0,c=t,s=e.apply(r,n)}function w(e){var n=e-l;return void 0===l||n>=t||n<0||g&&e-c>=r}function v(){var e=f();if(w(e))return y(e);a=setTimeout(v,function(e){var n=t-(e-l);return g?u(n,r-(e-c)):n}(e))}function y(e){return a=void 0,_&&o?b(e):(o=i=void 0,s)}function x(){var e=f(),n=w(e);if(o=arguments,i=this,l=e,n){if(void 0===a)return function(e){return c=e,a=setTimeout(v,t),h?b(e):s}(l);if(g)return a=setTimeout(v,t),b(l)}return void 0===a&&(a=setTimeout(v,t)),s}return t=p(t)||0,m(n)&&(h=!!n.leading,r=(g="maxWait"in n)?d(p(n.maxWait)||0,t):r,_="trailing"in n?!!n.trailing:_),x.cancel=function(){void 0!==a&&clearTimeout(a),c=0,o=l=i=a=void 0},x.flush=function(){return void 0===a?s:y(f())},x},ki}(),Pi=Ne(Ri);function Ti(e,t,n,o=0){let i=o;for(;i<e.length&&t>0;)n(e[i])&&--t,++i;return i}function Mi(e,t,n,o){let i=0;for(let r=n;r<o;r++)t(e[r])&&++i;return i}function Oi(e,t,n,o,i){const r=Mi(e,i,0,n),s=Mi(e,i,n,o);let a=Ti(t,r,i);for(;a<t.length&&!i(t[a]);)++a;return[a,Ti(t,s,i,a)]}const Ii={INITIAL:0,
119
- FINISHED:3},Li=new Map,Bi=new Map;function Hi(e,t){return`${e}:${t}`}function Fi(e){const t="closest"in e?e:e.parentElement;return t?.closest(".textLayer")??null}function Di(){return PDFViewerApplication.pdfViewer}async function Vi(e){const t=Di();let n=t.getPageView(e);return n&&n.pdfPage||(n=await new Promise((n=>{const o=()=>{t.eventBus?t.eventBus.off("pagesloaded",o):document.removeEventListener("pagesloaded",o),n(t.getPageView(e))};t.eventBus?t.eventBus.on("pagesloaded",o):document.addEventListener("pagesloaded",o)}))),n}function Ui(e){const t=Li.get(e);if(t)return t;const n=(async()=>{const t=await Vi(e);return(await t.pdfPage.getTextContent({normalizeWhitespace:!0})).items.map((e=>e.str)).join("")})();return Li.set(e,n),n}async function qi(e){const t=Di();let n=0,o=0,i="";for(let r=0;r<t.pagesCount;r++)if(i=await Ui(r),n=o,o+=i.length,o>=e)return{index:r,offset:n,text:i};return{index:t.pagesCount-1,offset:n,text:i}}function $i(e){switch(e){case" ":case"\f":case"\n":case"\r":case"\t":case"\v":case" ":
120
- return!0;default:return!1}}const zi=e=>!$i(e);function Wi(e){return void 0!==e.renderingDone?e.renderingDone:!!e.div&&null!==e.div.querySelector(".endOfContent")}async function ji(e,t,n){const[o,i]=await Promise.all([Vi(e),Ui(e)]);if(o.renderingState===Ii.FINISHED&&o.textLayer&&Wi(o.textLayer)){const e=o.textLayer.textLayerDiv??o.textLayer.div;if(!e)throw new Error("Unable to find PDF.js text layer root");const r=e.textContent,[s,a]=Oi(i,r,t,n,zi);Xi(r.slice(s,a))!==Xi(i.slice(t,n))&&Uo("Text layer text does not match page text. Highlights will be mis-aligned.");const l=new uo(e,s),c=new uo(e,a);return new fo(l,c).toRange()}const r=function(e){let t=e.querySelector(mo);return t||(t=document.createElement("span"),t.classList.add("annotator-placeholder"),t.textContent="Loading annotations...",e.appendChild(t),t)}(o.div),s=document.createRange();return s.setStartBefore(r),s.setEndAfter(r),s}function Xi(e){let t="";for(let n=0;n<e.length;n++){const o=e[n];$i(o)||(t+=o)}return t}async function Yi(e){
121
- const t=e.find((e=>"TextQuoteSelector"===e.type));if(!t)throw new Error("No quote selector found");const n=e.find((e=>"TextPositionSelector"===e.type));if(n){try{const{index:e,offset:o,text:i}=await qi(n.start),r=n.start-o,s=n.end-o,a=i.substring(r,s);if(t.exact!==a)throw new Error("quote mismatch");return await ji(e,r,s)}catch{}try{const e=Hi(t.exact,n.start),o=Bi.get(e);if(o){const{pageIndex:e,anchor:t}=o;return await ji(e,t.start,t.end)}}catch{}}return async function(e,t){const n=Di().pagesCount,o=Array(n).fill(0).map(((e,t)=>t));let i,r;if(t){const{index:e,offset:n}=await qi(t);i=e,r=t-n,o.sort(((t,n)=>Math.abs(t-e)-Math.abs(n-e)))}const s=void 0!==e.prefix?Xi(e.prefix):void 0,a=void 0!==e.suffix?Xi(e.suffix):void 0,l=Xi(e.exact);let c;for(const e of o){const t=await Ui(e),n=Xi(t);let o;void 0!==i&&void 0!==r&&(e<i?o=n.length:e===i?[o]=Oi(t,n,r,r,zi):o=0);const h=ni(n,l,{prefix:s,suffix:a,hint:o});if(h&&(!c||h.score>c.match.score)){const[o,i]=Oi(n,t,h.start,h.end,zi);c={page:e,match:{start:o,end:i,
122
- score:h.score}};const r=n.slice(h.start,h.end)===l,d=void 0!==s&&n.slice(Math.max(0,h.start-s.length),h.start)===s,u=void 0!==a&&n.slice(h.end,a.length)===a;if(r&&(d||u||void 0===s&&void 0===a))break}}if(c){const{page:n,match:o}=c;if(t){const i=Hi(e.exact,t);Bi.set(i,{pageIndex:n,anchor:o})}return ji(n,o.start,o.end)}throw new Error("Quote not found")}(t,n?.start)}async function Ki(e){const t=e.find((e=>"PageSelector"===e.type)),n=e.find((e=>"ShapeSelector"===e.type));if(n){if(!t)throw new Error("Cannot anchor a shape selector without a page");return async function(e,t){const n=Di();if("number"!=typeof e.index||e.index<0||e.index>=n.pagesCount)throw new Error("PDF page index is invalid");const o=await Vi(e.index),i=o.div,r=o.viewport,s=e=>function(e,t,n){return Math.max(Math.min(e,n),t)}(e,0,1);let a;switch(t.shape.type){case"rect":{const e=t.shape;let[n,o]=r.convertToViewportPoint(e.left,e.top),[i,l]=r.convertToViewportPoint(e.right,e.bottom);i<n&&([n,i]=[i,n]),l<o&&([o,l]=[l,o]),a={type:"rect",
123
- left:s(n/r.width),top:s(o/r.height),right:s(i/r.width),bottom:s(l/r.height)}}break;case"point":{const e=t.shape,[n,i]=o.viewport.convertToViewportPoint(e.x,e.y);a={type:"point",x:s(n/r.width),y:s(i/r.height)}}break;default:throw new Error("Unsupported shape in shape selector")}return{anchor:i,shape:a,coordinates:"anchor"}}(t,n)}return Yi(e)}function Gi(e){try{e=fo.fromRange(e).toRange()}catch{throw new Error("Selection does not contain text")}const t=Fi(e.startContainer),n=Fi(e.endContainer);if(!t||!n)throw new Error("Selection is outside page text");if(t!==n)throw new Error("Selecting across page breaks is not supported");return[e,t]}function Qi(e){const t=e.closest(".page"),n=parseInt(t?.getAttribute("data-page-number")??"");if(!Number.isInteger(n))throw new Error("Unable to get page number from element");return n-1}async function Ji(e){const[t,n]=Gi(e),o=uo.fromPoint(t.startContainer,t.startOffset).relativeTo(n),i=uo.fromPoint(t.endContainer,t.endOffset).relativeTo(n),r=Qi(n),s=await async function(e){
124
- if(e>=Di().pagesCount)throw new Error("Invalid page index");let t=0;for(let n=0;n<e;n++)t+=(await Ui(n)).length;return t}(r),a=await Vi(r);return[{type:"TextPositionSelector",start:s+o.offset,end:s+i.offset},ci.fromRange(a.div,t).toSelector(),er(a,r)]}async function Zi(e,t){const n=document.elementsFromPoint(e,t);for(const o of n){if(!o.classList.contains("page"))continue;const n=Qi(o),i=getComputedStyle(o),r=parseFloat(i.borderLeftWidth),s=parseFloat(i.borderTopWidth),a=o.getBoundingClientRect(),l=e-a.left-r,c=t-a.top-s,h=await Vi(n),[d,u]=h.getPagePoint(l,c);return{pageIndex:n,x:d,y:u}}return null}function er(e,t){return{type:"PageSelector",index:t,label:e.pageLabel??`${t+1}`}}function tr({children:e}){return Pe("div",{className:"flex flex-col",children:e})}function nr({info:e}){let t=e.item.title;return e.item.subtitle&&(t+=`: ${e.item.subtitle}`),Pe("div",{
125
- className:Ee("h-10 bg-white px-4 text-slate-7 text-annotator-base border-b","grid items-center","grid-cols-[100px_minmax(0,auto)]","2xl:grid-cols-[100px_minmax(0,auto)_minmax(0,auto)] 2xl:gap-x-3"),children:[Pe("div",{"data-testid":"content-logo",children:e.logo&&Pe(Jt,{href:e.logo.link,target:"_blank","data-testid":"logo-link",underline:"none",children:Pe("img",{alt:e.logo.title,src:e.logo.logo,"data-testid":"logo-image"})})}),Pe("div",{className:Ee("hidden","2xl:block 2xl:whitespace-nowrap 2xl:overflow-hidden 2xl:text-ellipsis","font-semibold"),"data-testid":"content-container-info",title:e.container.title,children:e.container.title}),Pe("div",{className:Ee("flex justify-center items-center gap-x-2"),"data-testid":"content-item-info",children:[Pe("div",{className:Ee("hidden","2xl:block 2xl:grow")}),e.links.previousItem&&Pe(w,{children:[Pe(Jt,{title:"Open previous item",href:e.links.previousItem,underline:"always",target:"_blank","data-testid":"content-previous-link",children:Pe("div",{
126
- className:"flex gap-x-1 items-center text-annotator-sm whitespace-nowrap",children:[Pe(qe,{className:"w-em h-em"}),Pe("span",{children:"Previous"})]})}),Pe("div",{className:"text-annotator-sm",children:"|"})]}),Pe("div",{className:Ee("min-w-0 whitespace-nowrap overflow-hidden text-ellipsis shrink font-medium"),children:Pe(Jt,{title:t,href:e.links.currentItem,"data-testid":"content-item-link",target:"_blank",unstyled:!0,children:t})}),e.links.nextItem&&Pe(w,{children:[Pe("div",{className:"text-annotator-sm",children:"|"}),Pe(Jt,{title:"Open next item",href:e.links.nextItem,underline:"always",target:"_blank","data-testid":"content-next-link",children:Pe("div",{className:"flex gap gap-x-1 items-center text-annotator-sm whitespace-nowrap",children:[Pe("span",{children:"Next"}),Pe(ze,{className:"w-em h-em"})]})})]})]})]})}function or(){return Pe("div",{className:"bg-white",role:"alert",children:Pe("div",{
127
- className:Ee("flex items-center gap-x-2","border border-yellow-notice bg-yellow-notice/10 text-annotator-base"),children:[Pe("div",{className:"bg-yellow-notice text-white p-2",children:Pe(je,{className:"text-annotator-xl"})}),Pe("div",{children:[Pe("strong",{children:"This PDF does not contain selectable text:"})," ",Pe(Jt,{target:"_blank",href:"https://web.hypothes.is/help/how-to-ocr-optimize-pdfs/",underline:"always",children:"Learn how to fix this"})," ","in order to annotate with Hypothesis."]})]})})}class ir{constructor(e){this._loaded=function(e){return e.initializedPromise?e.initializedPromise:e.initialized?Promise.resolve():new Promise((t=>{const n=setInterval((()=>{e.initialized&&(clearTimeout(n),t())}),5)}))}(e).then((async()=>{const t=await async function(e){return void 0!==e.downloadComplete?e.downloadComplete:(await e.pdfDocument.getDownloadInfo(),!0)}(e);return t?e:new Promise((t=>{const n=()=>{e.eventBus?(e.eventBus.off("documentload",n),
77
+ return this._container.element.shadowRoot.firstChild}_width(){return this._firstChild().getBoundingClientRect().width}_height(){return this._firstChild().getBoundingClientRect().height}_calculateTarget(e,t){let n,o,i;n=t&&!Xn()?to.DOWN:to.UP;const r=Math.min(20,e.width),s=this._width(),a=Xn()?10:0,l=this._height();return i=t?e.left-s/2+r:e.left+e.width-s/2-r,e.top-l<0&&n===to.DOWN?n=to.UP:e.top+l>this._view.innerHeight&&(n=to.DOWN),o=n===to.UP?e.top+e.height+10+a:e.top-l-10,i=Math.max(i,0),i=Math.min(i,this._view.innerWidth-s),o=Math.max(o,0),o=Math.min(o,this._view.innerHeight-l),{top:o,left:i,arrowDirection:n}}_findZindex(e,t){if(void 0===document.elementsFromPoint)return 32768;const n=this._width(),o=this._height(),i=e=>+getComputedStyle(e).zIndex,r=[...new Set([...document.elementsFromPoint(e,t),...document.elementsFromPoint(e,t+o),...document.elementsFromPoint(e+n/2,t+o/2),...document.elementsFromPoint(e+n,t),...document.elementsFromPoint(e+n,t+o)])].map(i).filter(Number.isInteger);let s=0
78
+ ;for(const e of document.querySelectorAll("hypothesis-highlight"))s=Math.max(s,i(e));return r.push(s),Math.max(...r)+1}_showAt(e,t){const n=function(e){let t=e.parentElement;for(;t.parentElement&&"static"===getComputedStyle(t).position;)t=t.parentElement;return t}(this._container.element).getBoundingClientRect(),o=this._findZindex(e,t);Object.assign(this._container.element.style,{left:no(e-n.left),top:no(t-n.top),zIndex:o})}_render(){return Pe(Jn,{isVisible:this._isVisible,arrowDirection:this._arrowDirection,onCommand:e=>{switch(e){case"annotate":this._onAnnotate(),this.hide();break;case"highlight":this._onHighlight(),this.hide();break;case"show":this._onShowAnnotations(this.annotationsForSelection);break;case"hide":this.hide()}},annotationCount:this.annotationsForSelection.length})}}var io=function(e){return e[e.Forwards=1]="Forwards",e[e.Backwards=2]="Backwards",e}(io||{});function ro(e,t,n){const o=n===io.Forwards?t:t-1;if(""!==e.charAt(o).trim())return t;let i,r;if(n===io.Backwards?(i=e.substring(0,t),
79
+ r=i.trimEnd()):(i=e.substring(t),r=i.trimStart()),!r.length)return-1;const s=i.length-r.length;return n===io.Backwards?t-s:t+s}function so(e,t){const n=e.commonAncestorContainer.ownerDocument.createNodeIterator(e.commonAncestorContainer,NodeFilter.SHOW_TEXT),o=t===io.Forwards?e.startContainer:e.endContainer,i=t===io.Forwards?e.endContainer:e.startContainer;let r=n.nextNode();for(;r&&r!==o;)r=n.nextNode();t===io.Backwards&&(r=n.previousNode());let s=-1;const a=()=>{if(r=t===io.Forwards?n.nextNode():n.previousNode(),r){const e=r.textContent,n=t===io.Forwards?0:e.length;s=ro(e,n,t)}};for(;r&&-1===s&&r!==i;)a();if(r&&s>=0)return{node:r,offset:s};throw new RangeError("No text nodes with non-whitespace text found in range")}function ao(e){switch(e.nodeType){case Node.ELEMENT_NODE:case Node.TEXT_NODE:return e.textContent?.length??0;default:return 0}}function lo(e){let t=e.previousSibling,n=0;for(;t;)n+=ao(t),t=t.previousSibling;return n}function co(e,...t){let n=t.shift()
80
+ ;const o=e.ownerDocument.createNodeIterator(e,NodeFilter.SHOW_TEXT),i=[];let r,s=o.nextNode(),a=0;for(;void 0!==n&&s;)r=s,a+r.data.length>n?(i.push({node:r,offset:n-a}),n=t.shift()):(s=o.nextNode(),a+=r.data.length);for(;void 0!==n&&r&&a===n;)i.push({node:r,offset:r.data.length}),n=t.shift();if(void 0!==n)throw new RangeError("Offset exceeds text length");return i}let ho=function(e){return e[e.FORWARDS=1]="FORWARDS",e[e.BACKWARDS=2]="BACKWARDS",e}({});class uo{constructor(e,t){if(t<0)throw new Error("Offset is invalid");this.element=e,this.offset=t}relativeTo(e){if(!e.contains(this.element))throw new Error("Parent is not an ancestor of current element");let t=this.element,n=this.offset;for(;t!==e;)n+=lo(t),t=t.parentElement;return new uo(t,n)}resolve(e={}){try{return co(this.element,this.offset)[0]}catch(t){if(0===this.offset&&void 0!==e.direction){const n=document.createTreeWalker(this.element.getRootNode(),NodeFilter.SHOW_TEXT);n.currentNode=this.element
81
+ ;const o=e.direction===ho.FORWARDS,i=o?n.nextNode():n.previousNode();if(!i)throw t;return{node:i,offset:o?0:i.data.length}}throw t}}static fromCharOffset(e,t){switch(e.nodeType){case Node.TEXT_NODE:return uo.fromPoint(e,t);case Node.ELEMENT_NODE:return new uo(e,t);default:throw new Error("Node is not an element or text node")}}static fromPoint(e,t){switch(e.nodeType){case Node.TEXT_NODE:{if(t<0||t>e.data.length)throw new Error("Text node offset is out of range");if(!e.parentElement)throw new Error("Text node has no parent");const n=lo(e)+t;return new uo(e.parentElement,n)}case Node.ELEMENT_NODE:{if(t<0||t>e.childNodes.length)throw new Error("Child node offset is out of range");let n=0;for(let o=0;o<t;o++)n+=ao(e.childNodes[o]);return new uo(e,n)}default:throw new Error("Point is not in an element or text node")}}}class fo{constructor(e,t){this.start=e,this.end=t}relativeTo(e){return new fo(this.start.relativeTo(e),this.end.relativeTo(e))}toRange(){let e,t
82
+ ;this.start.element===this.end.element&&this.start.offset<=this.end.offset?[e,t]=co(this.start.element,this.start.offset,this.end.offset):(e=this.start.resolve({direction:ho.FORWARDS}),t=this.end.resolve({direction:ho.BACKWARDS}));const n=new Range;return n.setStart(e.node,e.offset),n.setEnd(t.node,t.offset),n}static fromRange(e){const t=uo.fromPoint(e.startContainer,e.startOffset),n=uo.fromPoint(e.endContainer,e.endOffset);return new fo(t,n)}static fromOffsets(e,t,n){return new fo(new uo(e,t),new uo(e,n))}static trimmedRange(e){return function(e){if(!e.toString().trim().length)throw new RangeError("Range contains no non-whitespace text");if(e.startContainer.nodeType!==Node.TEXT_NODE)throw new RangeError("Range startContainer is not a text node");if(e.endContainer.nodeType!==Node.TEXT_NODE)throw new RangeError("Range endContainer is not a text node");const t=e.cloneRange();let n=!1,o=!1;const i={start:ro(e.startContainer.textContent,e.startOffset,io.Forwards),
83
+ end:ro(e.endContainer.textContent,e.endOffset,io.Backwards)};if(i.start>=0&&(t.setStart(e.startContainer,i.start),n=!0),i.end>0&&(t.setEnd(e.endContainer,i.end),o=!0),n&&o)return t;if(!n){const{node:e,offset:n}=so(t,io.Forwards);e&&n>=0&&t.setStart(e,n)}if(!o){const{node:e,offset:n}=so(t,io.Backwards);e&&n>0&&t.setEnd(e,n)}return t}(fo.fromRange(e).toRange())}}const mo=".annotator-placeholder";function po(e){return!!e.parentElement&&null!==e.parentElement.closest(mo)}function go(e,t){const n=new Range;return e.compareBoundaryPoints(Range.START_TO_START,t)<=0?n.setStart(e.startContainer,e.startOffset):n.setStart(t.startContainer,t.startOffset),e.compareBoundaryPoints(Range.END_TO_END,t)>=0?n.setEnd(e.endContainer,e.endOffset):n.setEnd(t.endContainer,t.endOffset),n}function _o(e=document.getSelection()){if(!e||0===e.rangeCount)return null;let t=e.getRangeAt(0);for(let n=1;n<e.rangeCount;n++)t=go(t,e.getRangeAt(n));return t.collapsed?null:t}function bo(e){
84
+ if(e.focusNode===e.anchorNode)return e.focusOffset<e.anchorOffset;return _o(e).startContainer===e.focusNode}function wo(e,t){try{const n=t.nodeValue?.length??t.childNodes.length;return e.comparePoint(t,0)<=0&&e.comparePoint(t,n)>=0}catch{return!1}}function vo(e,t){const n=e.commonAncestorContainer,o=n.ownerDocument.createNodeIterator(n,NodeFilter.SHOW_ALL);let i;for(;i=o.nextNode();)wo(e,i)&&t(i)}function yo(e){const t=_o(e);if(!t)return null;const n=function(e){const t=[];return vo(e,(e=>{Pn(e)&&!e.textContent.match(/^\s*$/)&&t.push(e)})),t.flatMap((t=>{const n=t.ownerDocument.createRange();if(n.selectNodeContents(t),t===e.startContainer&&n.setStart(t,e.startOffset),t===e.endContainer&&n.setEnd(t,e.endOffset),n.collapsed)return[];const o=Array.from(n.getClientRects());return n.detach(),o}))}(t);return 0===n.length?null:bo(e)?n[0]:n[n.length-1]}const xo="http://www.w3.org/2000/svg",No=["user-annotations","user-highlights","other-content"];class Co{constructor(e=document.body){this.root=e}highlightShape(e){
85
+ const{shape:t,anchor:n}=e,o=document.createElement("hypothesis-highlight");if(o.className="hypothesis-shape-highlight","rect"===t.type){const e=t.right-t.left,n=t.bottom-t.top;o.style.left=100*t.left+"%",o.style.top=100*t.top+"%",o.style.width=`calc(${100*e}% - 6px)`,o.style.height=`calc(${100*n}% - 6px)`}else if("point"===t.type){const e=7;o.style.left=`calc(${100*t.x}% - ${e+3}px)`,o.style.top=`calc(${100*t.y}% - ${e+3}px)`,o.style.width=2*e+"px",o.style.height=2*e+"px",o.style.borderRadius="50%"}return n.append(o),[o]}highlightRange(e,t){const n=function(e){if(e.collapsed)return[];let t=e.commonAncestorContainer;t&&t.nodeType!==Node.ELEMENT_NODE&&(t=t.parentElement);if(!t)return[];const n=[],o=t.ownerDocument.createNodeIterator(t,NodeFilter.SHOW_TEXT);let i;for(;i=o.nextNode();){if(!wo(e,i))continue;const t=i;t===e.startContainer&&e.startOffset>0?t.splitText(e.startOffset):(t===e.endContainer&&e.endOffset<t.data.length&&t.splitText(e.endOffset),n.push(t))}return n}(e),o=n.length>0&&po(n[0])
86
+ ;let i=[],r=null,s=null;n.forEach((e=>{r&&r.nextSibling===e?s.push(e):(s=[e],i.push(s)),r=e}));const a=/^\s*$/;i=i.filter((e=>{const t=e[0].parentElement;return 1===t?.childNodes.length&&"SPAN"===t?.tagName||e.some((e=>!a.test(e.data)))}));const l=[];return i.forEach((e=>{const n=document.createElement("hypothesis-highlight");n.className=Ee("hypothesis-highlight",t);e[0].parentNode.replaceChild(n,e[0]),e.forEach((e=>n.appendChild(e))),l.push(n)})),o||function(e,t){if(0===e.length)return;const n=function(e){const t=e.closest(".page");if(!t)return null;const n=t.querySelector(".canvasWrapper > canvas");if(!n)return null;return n}(e[0]);if(!n||!n.parentElement)return;let o=n.parentElement.querySelector(".hypothesis-highlight-layer");if(!o){o=document.createElementNS(xo,"svg"),o.setAttribute("class","hypothesis-highlight-layer"),n.parentElement.appendChild(o),n.parentElement.style.position="relative";const e=o.style;e.position="absolute",e.left="0",e.top="0",e.width="100%",e.height="100%",
87
+ e.mixBlendMode="multiply"}const i=n.getBoundingClientRect(),r=e.map((e=>{const n=e.getBoundingClientRect(),o=document.createElementNS(xo,"rect"),r=(n.left-i.left)/i.width,s=(n.top-i.top)/i.height,a=n.width/i.width,l=n.height/i.height;return o.setAttribute("x",100*r+"%"),o.setAttribute("y",100*s+"%"),o.setAttribute("width",100*a+"%"),o.setAttribute("height",100*l+"%"),o.setAttribute("class",Ee("hypothesis-svg-highlight",t)),e.classList.add("is-transparent"),e.svgHighlight=o,o}));o.append(...r)}(l,t),l}removeAllHighlights(){const e=Array.from(this.root.querySelectorAll("hypothesis-highlight"));this.removeHighlights(e)}removeHighlights(e){!function(e,t){e.forEach((e=>{e.svgHighlight?Ao(e.svgHighlight,t):e.classList.toggle("hypothesis-highlight-focused",t)}))}(e,!1);for(const t of e){if(t.parentNode){So(t,Array.from(t.childNodes))}t.svgHighlight&&t.svgHighlight.remove()}}setHighlightsFocused(e,t){e.forEach((e=>{e.svgHighlight?Ao(e.svgHighlight,t):e.classList.toggle("hypothesis-highlight-focused",t)}))}
88
+ setHighlightsVisible(e){this.root.classList.toggle(ko,e)}getHighlightsFromPoint(e,t){return Eo(e,t)}}function So(e,t){const n=e.parentNode;t.forEach((t=>n.insertBefore(t,e))),e.remove()}function Ao(e,t){const n=e.parentNode,o=e.getAttribute("data-focused-id");if(Boolean(o)!==t)if(t){e.setAttribute("data-focused-id",nn(8));const t=e.cloneNode();t.setAttribute("data-is-focused","data-is-focused"),n.append(t)}else{const t=n.querySelector(`[data-focused-id="${o}"][data-is-focused]`);t?.remove(),e.removeAttribute("data-focused-id")}}const ko="hypothesis-highlights-always-on";function Eo(e,t){const n=`.${ko}`,o=document.elementsFromPoint(e,t).filter((e=>"hypothesis-highlight"===e.localName&&e.closest(n))),i=[];for(const o of document.querySelectorAll("hypothesis-highlight.hypothesis-shape-highlight")){if(!o.closest(n))continue;const r=o.getBoundingClientRect();e>=r.left&&e<r.right&&t>=r.top&&t<r.bottom&&i.push(o)}return[...o,...i]}function Ro(e){Mo(To(e)),function(e){for(const[t,n]of function(e){const t=new Map
89
+ ;for(const n of(e??document).getElementsByClassName("hypothesis-highlight-layer"))t.set(n,Array.from(n.querySelectorAll(".hypothesis-svg-highlight")));return t}(e)){n.every(((e,t,n)=>0===t||Oo(e)>=Oo(n[t-1])))||(n.sort(((e,t)=>Oo(e)-Oo(t))),t.replaceChildren(...n))}}(e)}const Po=e=>"hypothesis-highlight"===e.tagName.toLowerCase();function To(e){let t;return t=Po(e)?Array.from(e.children).filter(Po):Array.from(e.getElementsByTagName("hypothesis-highlight")).filter((e=>!e.parentElement||!Po(e.parentElement))),t}function Mo(e,t="",n=0,o=0){for(const i of e){const e=No.find((e=>i.classList.contains(e)))??"other-content",r=t&&e===t?o+1:0;i.setAttribute("data-nesting-level",`${n}`),i.setAttribute("data-cluster-level",`${r}`),i.svgHighlight&&(i.svgHighlight.setAttribute("data-nesting-level",`${n}`),i.svgHighlight.setAttribute("data-cluster-level",`${r}`)),Mo(To(i),e,n+1,r)}}function Oo(e){return e.getAttribute("data-is-focused")?Number.MAX_SAFE_INTEGER:parseInt(e.getAttribute("data-nesting-level")??"0",10)}
90
+ function Io(e){const t=[];return e.forEach((({annotation:e,highlights:n})=>{if(!n?.length)return;const{top:o,bottom:i}=function(e){const t=e.map((e=>e.getBoundingClientRect()));return t.reduce(((e,t)=>({top:Math.min(e.top,t.top),left:Math.min(e.left,t.left),bottom:Math.max(e.bottom,t.bottom),right:Math.max(e.right,t.right)})))}(n);o>=i||t.push({tag:e.$tag,top:o,bottom:i})})),t.sort(((e,t)=>e.top-t.top)),t}class Lo{constructor({contentContainer:e,hostRPC:t}){this._hostRPC=t,this._updatePending=!1,this._anchors=[],this._listeners=new ge,this._listeners.add(window,"resize",(()=>this.update())),this._listeners.add(window,"scroll",(()=>this.update())),this._listeners.add(e,"scroll",(()=>this.update()),{capture:!0})}destroy(){this._listeners.removeAll()}update(e){e&&(this._anchors=e),this._updatePending||(this._updatePending=!0,requestAnimationFrame((()=>{const e=Io(this._anchors);this._hostRPC.call("anchorsChanged",e),this._updatePending=!1})))}}function Bo(e){
91
+ const t=Math.min(e.left,e.right),n=Math.max(e.left,e.right);return{type:"rect",left:t,top:Math.min(e.top,e.bottom),right:n,bottom:Math.max(e.top,e.bottom)}}class Ho extends Error{constructor(e,t="Drawing failed"){super(t),this.kind=e}}class Fo{constructor(e){this._container=e,this._tool="rect"}destroy(){this.cancel()}async draw(e){this._tool=e,this.cancel("restarted");const t=document.createElementNS("http://www.w3.org/2000/svg","svg");t.setAttribute("data-testid","surface"),t.style.cursor="crosshair",t.style.touchAction="none",t.style.position="absolute",t.setAttribute("width","100%"),t.setAttribute("height","100%"),t.style.left="0px",t.style.top="0px",t.style.zIndex="10",this._container.append(t),this._surface=t;const{promise:n,resolve:o,reject:i}=function(){let e,t;return{promise:new Promise(((n,o)=>{e=n,t=o})),resolve:e,reject:t}}();return this._drawEnd=o,this._drawError=i,this._surface.addEventListener("pointerdown",(e=>{switch(this._tool){case"rect":this._shape={type:"rect",left:e.clientX,top:e.clientY,
92
+ right:e.clientX,bottom:e.clientY};break;case"point":this._shape={type:"point",x:e.clientX,y:e.clientY}}this._renderSurface()})),this._surface.addEventListener("pointermove",(e=>{if(this._shape){switch(this._shape.type){case"rect":this._shape.right=e.clientX,this._shape.bottom=e.clientY;break;case"point":this._shape.x=e.clientX,this._shape.y=e.clientY}this._renderSurface()}})),this._surface.addEventListener("pointerup",(e=>{if(this._shape){switch(this._shape.type){case"rect":this._shape.right=e.clientX,this._shape.bottom=e.clientY,o(Bo(this._shape));break;case"point":this._shape.x=e.clientX,this._shape.y=e.clientY,o(this._shape)}this._abortDraw?.abort(),e.stopPropagation()}})),this._surface.addEventListener("wheel",(e=>{let t=Math.abs(e.deltaY),n=Math.abs(e.deltaX);for(const o of document.elementsFromPoint(e.clientX,e.clientY)){const i=o.scrollLeft;o.scrollLeft+=n*Math.sign(e.deltaX),n-=Math.abs(o.scrollLeft-i);const r=o.scrollTop;o.scrollTop+=t*Math.sign(e.deltaY),t-=Math.abs(o.scrollTop-r)}})),
93
+ this._abortDraw=new AbortController,document.body.addEventListener("keydown",(e=>{"Escape"===e.key&&(this._drawError&&this._drawError(new Ho("canceled","Drawing canceled")),this._abortDraw?.abort())}),{signal:this._abortDraw.signal}),this._abortDraw.signal.onabort=()=>{this._surface?.remove(),this._shape=void 0,this._surface=void 0,this._drawError=void 0,this._drawEnd=void 0,this._abortDraw=void 0},this._renderSurface(),n}cancel(e="canceled"){this._drawError&&this._drawError(new Ho(e,"Drawing canceled")),this._abortDraw?.abort()}_renderSurface(){if(this._surface)if("rect"===this._shape?.type){const e=Bo(this._shape);F(Pe(w,{children:[Pe("rect",{stroke:"white","stroke-dasharray":"5","stroke-width":"1px",fill:"grey","fill-opacity":"0.5",x:e.left,y:e.top,width:e.right-e.left,height:e.bottom-e.top}),Pe("rect",{stroke:"grey","stroke-dasharray":"5","stroke-dashoffset":"5","stroke-width":"1px",fill:"none",x:e.left,y:e.top,width:e.right-e.left,height:e.bottom-e.top})]}),this._surface)
94
+ }else if("point"===this._shape?.type){const e=this._shape;F(Pe("circle",{stroke:"black","stroke-width":"1px",fill:"yellow",cx:e.x,cy:e.y,r:5}),this._surface)}else F(null,this._surface)}}class Do extends CustomEvent{constructor(e){super("hypothesis:layoutchange",{bubbles:!0,cancelable:!1,detail:e})}}const Vo=new Set;function Uo(...e){const t=e.join();Vo.has(t)||(console.warn(...e),Vo.add(t))}Uo.reset=()=>{Vo.clear()};const qo=["pdf_image_annotation","styled_highlight_clusters"];class $o extends an{constructor(e=qo){super(),this._flags=new Map,this._knownFlags=e}update(e){this._flags.clear();for(const[t,n]of Object.entries(e))this._flags.set(t,n);this.emit("flagsChanged")}flagEnabled(e){return this._knownFlags.includes(e)?this._flags.get(e)??!1:(Uo("Looked up unknown feature",e),!1)}allFlags(){return Object.fromEntries(this._flags)}}function zo({cluster:e,label:t,onChange:n,currentStyles:o,highlightStyles:i}){const r=o[e],s="transparent"===r;return Pe("div",{className:"space-y-2",children:[Pe("div",{
95
+ className:"flex items-center gap-x-2 text-annotator-base",children:Pe("div",{className:"grow text-color-text px-2 py-1 rounded",style:{backgroundColor:i[r].color},children:t})}),Pe("div",{className:"flex items-center gap-x-2",children:Object.keys(i).map((t=>Pe("div",{className:"relative",children:[Pe("input",{className:Ee("absolute w-6 h-6","opacity-[.00001]","cursor-pointer"),name:e,id:`hypothesis-${e}-${t}`,checked:r===t,onChange:n,type:"radio",value:t}),Pe("label",{className:"block",htmlFor:`${e}-${t}`,children:[Pe("div",{style:{backgroundColor:i[t].color},className:Ee("block w-6 h-6 rounded-full flex items-center justify-center",{"border-2 border-slate-0":r!==t,"border-2 border-slate-3":r===t}),children:"transparent"===t&&Pe(et,{className:Ee("w-3 h-3",{"text-slate-3":!s,"text-slate-7":s})})}),Pe("span",{className:"sr-only",children:t})]})]},`${e}-${t}`)))})]})}function Wo({active:e,availableStyles:t,currentStyles:n,onStyleChange:o}){const i=re((e=>{const t=e.target,n=t.name,i=t.value;o(n,i)
96
+ }),[o]),[r,s]=ee(!1);return e?Pe(Me,{classes:"overflow-hidden",children:Pe("div",{className:"flex flex-col text-annotator-base text-color-text",children:[Pe(Ct,{classes:"rounded-none","data-testid":"control-toggle-button",onClick:()=>s(!r),title:r?"Hide highlight settings":"Show highlight settings",children:Pe(w,r?{children:[Pe(Ve,{}),Pe("span",{children:"Highlight Appearance"})]}:{children:[Pe(ze,{}),Pe(nt,{})]})}),r&&Pe(Ie,{"data-testid":"cluster-style-controls",size:"sm",children:[Pe(zo,{highlightStyles:t,label:"My annotations",cluster:"user-annotations",onChange:i,currentStyles:n}),Pe(zo,{highlightStyles:t,label:"My highlights",cluster:"user-highlights",onChange:i,currentStyles:n}),Pe(zo,{highlightStyles:t,label:"Everybody's content",cluster:"other-content",onChange:i,currentStyles:n})]})]})}):null}const jo={transparent:{color:"transparent",secondColor:"transparent",thirdColor:"transparent"},pink:{color:"var(--hypothesis-color-pink)",secondColor:"var(--hypothesis-color-pink-1)",
97
+ thirdColor:"var(--hypothesis-color-pink-2)"},orange:{color:"var(--hypothesis-color-orange)",secondColor:"var(--hypothesis-color-orange-1)",thirdColor:"var(--hypothesis-color-orange-2)"},yellow:{color:"var(--hypothesis-color-yellow)",secondColor:"var(--hypothesis-color-yellow-1)",thirdColor:"var(--hypothesis-color-yellow-2)"},green:{color:"var(--hypothesis-color-green)",secondColor:"var(--hypothesis-color-green-1)",thirdColor:"var(--hypothesis-color-green-2)"},purple:{color:"var(--hypothesis-color-purple)",secondColor:"var(--hypothesis-color-purple-1)",thirdColor:"var(--hypothesis-color-purple-2)"},grey:{color:"var(--hypothesis-color-grey)",secondColor:"var(--hypothesis-color-grey-1)",thirdColor:"var(--hypothesis-color-grey-2)"}},Xo={"other-content":"yellow","user-annotations":"orange","user-highlights":"purple"};class Yo{constructor(e,t){this._element=e,this._features=t.features,this._container=new eo("highlight-cluster-toolbar",(()=>this._render())),this._element.appendChild(this._container.element),
98
+ Object.assign(this._container.element.style,{position:"fixed",top:`${this._element.offsetTop+4}px`,left:"4px"}),this.appliedStyles=Xo,this._init(),this._features.on("flagsChanged",(()=>{this._activate(this._isActive())})),this._container.render()}destroy(){clearTimeout(this._updateTimeout),this._activate(!1),this._container.destroy()}scheduleClusterUpdates(){clearTimeout(this._updateTimeout),this._updateTimeout=setTimeout((()=>this._updateClusters()),100)}_init(){for(const e of Object.keys(this.appliedStyles))this._setClusterStyles(e,this.appliedStyles[e]);this._activate(this._isActive())}_updateClusters(){this._isActive()&&Ro(this._element)}_isActive(){return this._features.flagEnabled("styled_highlight_clusters")}_activate(e){this._element.classList.toggle("hypothesis-highlights-clustered",e),this._container.render()}_setClusterStyle(e,t){document.documentElement.style.setProperty(e,t)}_setClusterStyles(e,t){const n=jo[t];for(const t of Object.keys(n))this._setClusterStyle(`--hypothesis-${e}-${t}`,n[t])}
99
+ _onChangeClusterStyle(e,t){this.appliedStyles[e]=t,this._setClusterStyles(e,t),this._container.render()}_render(){return Pe(Wo,{active:this._isActive(),availableStyles:jo,currentStyles:this.appliedStyles,onStyleChange:(e,t)=>this._onChangeClusterStyle(e,t)})}}function Ko(e){return e.split("").reverse().join("")}function Go(e){return(e|-e)>>31&1}function Qo(e,t,n,o){let i=e.P[n],r=e.M[n];const s=o>>>31,a=t[n]|s,l=a|r,c=(a&i)+i^i|a;let h=r|~(c|i),d=i&c;const u=Go(h&e.lastRowMask[n])-Go(d&e.lastRowMask[n]);return h<<=1,d<<=1,d|=s,h|=Go(o)-s,i=d|~(l|h),r=h&l,e.P[n]=i,e.M[n]=r,u}function Jo(e,t,n){if(0===t.length)return[];n=Math.min(n,t.length);const o=[],i=32,r=Math.ceil(t.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<<(t.length-1)%i;const a=new Uint32Array(r+1),l=new Map,c=[];for(let e=0;e<256;e++)c.push(a);for(let e=0;e<t.length;e+=1){const n=t.charCodeAt(e);if(l.has(n))continue;const o=new Uint32Array(r+1);l.set(n,o),
100
+ n<c.length&&(c[n]=o);for(let e=0;e<=r;e+=1){o[e]=0;for(let r=0;r<i;r+=1){const s=e*i+r;if(s>=t.length)continue;t.charCodeAt(s)===n&&(o[e]|=1<<r)}}}let h=Math.max(0,Math.ceil(n/i)-1);const d=new Uint32Array(r+1);for(let e=0;e<=h;e+=1)d[e]=(e+1)*i;d[r]=t.length;for(let e=0;e<=h;e+=1)s.P[e]=-1,s.M[e]=0;for(let u=0;u<e.length;u+=1){const f=e.charCodeAt(u);let m;f<c.length?m=c[f]:(m=l.get(f),void 0===m&&(m=a));let p=0;for(let e=0;e<=h;e+=1)p=Qo(s,m,e,p),d[e]+=p;if(d[h]-p<=n&&h<r&&(1&m[h+1]||p<0)){let e;if(h+=1,s.P[h]=-1,s.M[h]=0,h===r){const n=t.length%i;e=0===n?i:n}else e=i;d[h]=d[h-1]+e-p+Qo(s,m,h,p)}else for(;h>0&&d[h]>=n+i;)h-=1;h===r&&d[h]<=n&&(d[h]<n&&o.splice(0,o.length),o.push({start:-1,end:u+1,errors:d[h]}),n=d[h])}return o}function Zo(e,t,n){return function(e,t,n){const o=Ko(t);return n.map((n=>{const i=Math.max(0,n.end-t.length-n.errors);return{start:Jo(Ko(e.slice(i,n.end)),o,n.errors).reduce(((e,t)=>n.end-t.end<e?n.end-t.end:e),n.end),end:n.end,errors:n.errors}}))}(e,t,Jo(e,t,n))}function ei(e,t,n){
101
+ let o=0;const i=[];for(;-1!==o;)o=e.indexOf(t,o),-1!==o&&(i.push({start:o,end:o+t.length,errors:0}),o+=1);return i.length>0?i:Zo(e,t,n)}function ti(e,t){if(0===t.length||0===e.length)return 0;return 1-ei(e,t,t.length)[0].errors/t.length}function ni(e,t,n={}){if(0===t.length)return null;const o=Math.min(256,t.length/2),i=ei(e,t,o);if(0===i.length)return null;const r=o=>{const i=1-o.errors/t.length,r=n.prefix?ti(e.slice(Math.max(0,o.start-n.prefix.length),o.start),n.prefix):1,s=n.suffix?ti(e.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)/e.length}return(50*i+20*r+20*s+2*a)/92},s=i.map((e=>({start:e.start,end:e.end,score:r(e)})));return s.sort(((e,t)=>t.score-e.score)),s[0]}function oi(e){const t=function(e){const t=e.nodeName.toLowerCase();return"#text"===t?"text()":t}(e),n=function(e){let t=0,n=e;for(;n;)n.nodeName===e.nodeName&&(t+=1),n=n.previousSibling;return t}(e);return`${t}[${n}]`}function ii(e,t){let n="",o=e;for(;o!==t;){
102
+ if(!o)throw new Error("Node is not a descendant of root");n=oi(o)+"/"+n,o=o.parentNode}return n="/"+n,n=n.replace(/\/$/,""),n}function ri(e,t,n){t=t.toUpperCase();let o=-1;for(let i=0;i<e.children.length;i++){const r=e.children[i];if(r.nodeName.toUpperCase()===t&&(++o,o===n))return r}return null}function si(e,t=document.body){try{return function(e,t){if(null===e.match(/^(\/[A-Za-z0-9-]+(\[[0-9]+\])?)+$/))throw new Error("Expression is not a simple XPath");const n=e.split("/");let o=t;n.shift();for(const e of n){let t,n;const i=e.indexOf("[");if(-1!==i){t=e.slice(0,i);const o=e.slice(i+1,e.indexOf("]"));if(n=parseInt(o)-1,n<0)return null}else t=e,n=0;const r=ri(o,t,n);if(!r)return null;o=r}return o}(e,t)}catch{return document.evaluate("."+e,t,null,XPathResult.FIRST_ORDERED_NODE_TYPE,null).singleNodeValue}}class ai{constructor(e,t){this.root=e,this.range=t}static fromRange(e,t){return new ai(e,t)}static fromSelector(e,t){const n=si(t.startContainer,e)
103
+ ;if(!n)throw new Error("Failed to resolve startContainer XPath");const o=si(t.endContainer,e);if(!o)throw new Error("Failed to resolve endContainer XPath");const i=uo.fromCharOffset(n,t.startOffset),r=uo.fromCharOffset(o,t.endOffset),s=new fo(i,r).toRange();return new ai(e,s)}toRange(){return this.range}toSelector(){const e=fo.fromRange(this.range).toRange(),t=fo.fromRange(e),n=ii(t.start.element,this.root),o=ii(t.end.element,this.root);return{type:"RangeSelector",startContainer:n,startOffset:t.start.offset,endContainer:o,endOffset:t.end.offset}}}class li{constructor(e,t,n){this.root=e,this.start=t,this.end=n}static fromRange(e,t){const n=fo.fromRange(t).relativeTo(e);return new li(e,n.start.offset,n.end.offset)}static fromSelector(e,t){return new li(e,t.start,t.end)}toSelector(){return{type:"TextPositionSelector",start:this.start,end:this.end}}toRange(){return fo.fromOffsets(this.root,this.start,this.end).toRange()}}class ci{constructor(e,t,n={}){this.root=e,this.exact=t,this.context=n}static fromRange(e,t){
104
+ const n=e.textContent,o=fo.fromRange(t).relativeTo(e),i=o.start.offset,r=o.end.offset;return new ci(e,n.slice(i,r),{prefix:n.slice(Math.max(0,i-32),i),suffix:n.slice(r,Math.min(n.length,r+32))})}static fromSelector(e,t){const{prefix:n,suffix:o}=t;return new ci(e,t.exact,{prefix:n,suffix:o})}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=ni(this.root.textContent,this.exact,{...this.context,hint:e.hint});if(!t)throw new Error("Quote not found");return new li(this.root,t.start,t.end)}}function hi(e){const t=parseFloat(e);return!Number.isFinite(t)||t<0?null:t}function di(e){return e instanceof Element?e:e.parentElement}function ui(e,t=e){const n=hi(e?.getAttribute("data-time-start")??""),o=hi(t?.getAttribute("data-time-end")??"");return"number"!=typeof n||"number"!=typeof o||o<n?null:[n,o]}class fi{constructor(e,t,n){this.root=e,this.start=t,this.end=n}
105
+ static fromRange(e,t){const n=di(t.startContainer)?.closest("[data-time-start]"),o=di(t.endContainer)?.closest("[data-time-end]"),i=ui(n,o);if(!i)return null;const[r,s]=i;return new fi(e,r,s)}toRange(){const e=[...this.root.querySelectorAll("[data-time-start]")].map((e=>{const t=ui(e);if(!t)return null;const[n,o]=t;return{element:e,start:n,end:o}})).filter((e=>null!==e));e.sort(((e,t)=>e.start-t.start));const t=function(e,t){for(let n=e.length-1;n>=0;n--)if(t(e[n]))return n;return-1}(e,(e=>e.start<=this.start&&e.end>=this.start));if(-1===t)throw new Error("Start segment not found");const n=t+e.slice(t).findIndex((e=>e.start<=this.end&&e.end>=this.end));if(-1===n)throw new Error("End segment not found");const o=new Range;o.setStart(e[t].element,0);const i=e[n].element;return o.setEnd(i,i.childNodes.length),o}static fromSelector(e,t){const{start:n,end:o}=t;return new fi(e,n,o)}toSelector(){return{type:"MediaTimeSelector",start:this.start,end:this.end}}}async function mi(e,t){return e.toRange(t)}
106
+ function pi(e,t,n){const o=e[t];if("function"!=typeof o)throw new Error("Can only intercept functions");return e[t]=(...t)=>{const i=o.call(e,...t);return n(...t),i},()=>{e[t]=o}}function gi(e){return e.replace(/#.*/,"")}class _i{constructor(e,t=(()=>location.href)){this._listeners=new ge;let n=t();const o=(o=t())=>{gi(n)!==gi(o)&&(n=o,e(o))},i=function(){const e=window.navigation;return"function"==typeof Navigation&&e instanceof Navigation?e:null}();if(i)this._listeners.add(i,"navigatesuccess",(()=>o()));else{const e=[pi(window.history,"pushState",(()=>o())),pi(window.history,"replaceState",(()=>o()))];this._unpatchHistory=()=>e.forEach((e=>e())),this._listeners.add(window,"popstate",(()=>o()))}}disconnect(){this._unpatchHistory?.(),this._listeners.removeAll()}}var bi,wi;var vi=function(){if(wi)return bi;wi=1;var e="complete",t="canceled";function n(e,t,n){e.self===e?e.scrollTo(t,n):(e.scrollLeft=t,e.scrollTop=n)}function o(t){var i=t._scrollSettings;if(i){var r=i.maxSynchronousAlignments,s=function(e,t){
107
+ var n,o,i,r,s,a,l,c=e.align,h=e.target.getBoundingClientRect(),d=c&&null!=c.left?c.left:.5,u=c&&null!=c.top?c.top:.5,f=c&&null!=c.leftOffset?c.leftOffset:0,m=c&&null!=c.topOffset?c.topOffset:0,p=d,g=u;if(e.isWindow(t))a=Math.min(h.width,t.innerWidth),l=Math.min(h.height,t.innerHeight),o=h.left+t.pageXOffset-t.innerWidth*p+a*p,i=h.top+t.pageYOffset-t.innerHeight*g+l*g,o-=f,i-=m,o=e.align.lockX?t.pageXOffset:o,i=e.align.lockY?t.pageYOffset:i,r=o-t.pageXOffset,s=i-t.pageYOffset;else{a=h.width,l=h.height,n=t.getBoundingClientRect();var _=h.left-(n.left-t.scrollLeft),b=h.top-(n.top-t.scrollTop);o=_+a*p-t.clientWidth*p,i=b+l*g-t.clientHeight*g,o-=f,i-=m,o=Math.max(Math.min(o,t.scrollWidth-t.clientWidth),0),i=Math.max(Math.min(i,t.scrollHeight-t.clientHeight),0),o=e.align.lockX?t.scrollLeft:o,i=e.align.lockY?t.scrollTop:i,r=o-t.scrollLeft,s=i-t.scrollTop}return{x:o,y:i,differenceX:r,differenceY:s}}(i,t),a=Date.now()-i.startTime,l=Math.min(1/i.time*a,1);if(i.endIterations>=r)return n(t,s.x,s.y),
108
+ t._scrollSettings=null,i.end(e);var c=1-i.ease(l);if(n(t,s.x-s.differenceX*c,s.y-s.differenceY*c),a>=i.time)return i.endIterations++,i.scrollAncestor&&o(i.scrollAncestor),void o(t);!function(e){if("requestAnimationFrame"in window)return window.requestAnimationFrame(e);setTimeout(e,16)}(o.bind(null,t))}}function i(e){return e.self===e}function r(e){return"pageXOffset"in e||(e.scrollHeight!==e.clientHeight||e.scrollWidth!==e.clientWidth)&&"hidden"!==getComputedStyle(e).overflow}function s(){return!0}function a(e){if(e.assignedSlot)return a(e.assignedSlot);if(e.parentElement)return"body"===e.parentElement.tagName.toLowerCase()?e.parentElement.ownerDocument.defaultView||e.parentElement.ownerDocument.ownerWindow:e.parentElement;if(e.getRootNode){var t=e.getRootNode();if(11===t.nodeType)return t.host}}return bi=function(n,l,c){if(n){"function"==typeof l&&(c=l,l=null),l||(l={}),l.time=isNaN(l.time)?1e3:l.time,l.ease=l.ease||function(e){return 1-Math.pow(1-e,e/2)},l.align=l.align||{}
109
+ ;var h=a(n),d=1,u=l.validTarget||s,f=l.isScrollable;l.debug&&(console.log("About to scroll to",n),h||console.error("Target did not have a parent, is it mounted in the DOM?"));for(var m=[];h;)if(l.debug&&console.log("Scrolling parent node",h),u(h,d)&&(f?f(h,r):r(h))&&(d++,m.push(h)),!(h=a(h))){p(e);break}return m.reduce(((e,r,s)=>function(e,n,r,s,a){var l,c=!n._scrollSettings,h=n._scrollSettings,d=Date.now(),u={passive:!0};function f(e){n._scrollSettings=null,n.parentElement&&n.parentElement._scrollSettings&&n.parentElement._scrollSettings.end(e),r.debug&&console.log("Scrolling ended with type",e,"for",n),a(e),l&&(n.removeEventListener("touchstart",l,u),n.removeEventListener("wheel",l,u))}h&&h.end(t);var m=r.maxSynchronousAlignments;return null==m&&(m=3),n._scrollSettings={startTime:d,endIterations:0,target:e,time:r.time,ease:r.ease,align:r.align,isWindow:r.isWindow||i,maxSynchronousAlignments:m,end:f,scrollAncestor:s},"cancellable"in r&&!r.cancellable||(l=f.bind(null,t),n.addEventListener("touchstart",l,u),
110
+ n.addEventListener("wheel",l,u)),c&&o(n),l}(n,r,l,m[s+1],p)),null)}function p(e){--d||c&&c(e)}},bi}(),yi=Ne(vi);function xi(e,t,n){return e+n*(t-e)}async function Ni(e,t,{maxDuration:n=500}={}){const o=e.scrollTop,i=t,r=Date.now(),s=Math.min(Math.abs(i-o)/3,n);let a=0;for(;a<1;)await new Promise((e=>{requestAnimationFrame(e)})),a=Math.min(1,(Date.now()-r)/s),e.scrollTop=xi(o,i,a)}function Ci(e,t=document.baseURI){return new URL(e,t).href.toString().replace(/#.*/,"")}class Si{constructor(e={}){this.document=e.document||document}uri(){let e=this._getDocumentHref();try{e=decodeURIComponent(e)}catch(e){console.error("Error decoding URI:",e)}const t=this._getLinks();for(const n of t)"canonical"===n.rel&&(e=n.href);return e}getDocumentMetadata(){const e={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."),
111
+ twitter:this._getMetaTags("name","twitter:")},t=this._getFavicon();t&&(e.favicon=t),e.title=this._getTitle(e),e.link=this._getLinks(e);const n=e.link.find((e=>e.href.startsWith("urn:x-dc")));return n&&(e.documentFingerprint=n.href),e}_getMetaTags(e,t){const n={};for(const o of Array.from(this.document.querySelectorAll("meta"))){const i=o.getAttribute(e),{content:r}=o;if(i&&r){const e=i.match(RegExp(`^${t}(.+)$`,"i"));if(e){const t=e[1].toLowerCase();n[t]?n[t].push(r):n[t]=[r]}}}return n}_getTitle(e){return e.highwire.title?e.highwire.title[0]:e.eprints.title?e.eprints.title[0]:e.prism.title?e.prism.title[0]:e.facebook.title?e.facebook.title[0]:e.twitter.title?e.twitter.title[0]:e.dc.title?e.dc.title[0]:this.document.title}_getLinks(e={dc:{},highwire:{}}){const t=[{href:this._getDocumentHref()}],n=Array.from(this.document.querySelectorAll("link"));for(const e of n)if(["alternate","canonical","bookmark","shortlink"].includes(e.rel)){if("alternate"===e.rel){
112
+ if(e.type&&e.type.match(/^application\/(rss|atom)\+xml/))continue;if(e.hreflang)continue}try{const n=this._absoluteUrl(e.href);t.push({href:n,rel:e.rel,type:e.type})}catch{}}for(const n of Object.keys(e.highwire)){const o=e.highwire[n];if("pdf_url"===n)for(const e of o)try{t.push({href:this._absoluteUrl(e),type:"application/pdf"})}catch{}if("doi"===n)for(let e of o)"doi:"!==e.slice(0,4)&&(e=`doi:${e}`),t.push({href:e})}for(const n of Object.keys(e.dc)){const o=e.dc[n];if("identifier"===n)for(const e of o)"doi:"===e.slice(0,4)&&t.push({href:e})}const o=e.dc["relation.ispartof"],i=e.dc.identifier;if(o&&i){const e=o[o.length-1],n=i[i.length-1],r="urn:x-dc:"+encodeURIComponent(e)+"/"+encodeURIComponent(n);t.push({href:r})}return t}_getFavicon(){let e=null;for(const t of Array.from(this.document.querySelectorAll("link")))if(["shortcut icon","icon"].includes(t.rel))try{e=this._absoluteUrl(t.href)}catch{}return e}_absoluteUrl(e){return Ci(e,this.document.baseURI)}_getDocumentHref(){
113
+ const{href:e}=this.document.location,t=["http:","https:","file:"],n=new URL(e).protocol;return t.includes(n)?e:this.document.baseURI&&t.includes(new URL(this.document.baseURI).protocol)?this.document.baseURI:e}}class Ai extends an{constructor({features:e,container:t=document.body,sideBySideOptions:n}){super(),this.featureFlags=e,this.container=t,this._htmlMeta=new Si,this._prevURI=this._htmlMeta.uri(),this._sideBySideEnabled=!0,this._sideBySideOptions=n??{mode:"auto"},this._sideBySideActive=!1,this._lastLayout=null,this._navObserver=new _i((()=>this._checkForURIChange())),this._metaObserver=new MutationObserver((()=>this._checkForURIChange())),this._metaObserver.observe(document.head,{childList:!0,subtree:!0,attributes:!0,attributeFilter:["rel","href","name","content"]}),this._flagsChanged=()=>{},this.featureFlags.on("flagsChanged",this._flagsChanged)}anchor(e,t){return function(e,t,n={}){let o=null,i=null,r=null,s=null;for(const e of t)switch(e.type){case"TextPositionSelector":i=e,n.hint=i.start;break
114
+ ;case"TextQuoteSelector":r=e;break;case"RangeSelector":s=e;break;case"MediaTimeSelector":o=e}const a=e=>{if(r?.exact&&e.toString()!==r.exact)throw new Error("quote mismatch");return e};let l=Promise.reject("unable to anchor");if(s){const t=s;l=l.catch((()=>mi(ai.fromSelector(e,t),n).then(a)))}if(i){const t=i;l=l.catch((()=>mi(li.fromSelector(e,t),n).then(a)))}if(r){const t=r;l=l.catch((()=>mi(ci.fromSelector(e,t),n)))}if(o){const t=o;l=l.catch((()=>fi.fromSelector(e,t).toRange()))}return l}(e,t)}describe(e,t){if(t instanceof Range)return function(e,t){const n=[fi,ai,li,ci],o=[];for(const i of n)try{const n=i.fromRange(e,t);n&&o.push(n.toSelector())}catch{}return o}(e,t);throw new Error("Unsupported region type")}_checkForURIChange(){const e=this._htmlMeta.uri();e!==this._prevURI&&(this._prevURI=e,this.emit("uriChanged",e))}getAnnotatableRange(e){try{return fo.trimmedRange(e)}catch(e){if(e instanceof RangeError)return null;throw e}}canStyleClusteredHighlights(){return!0}destroy(){this._deactivateSideBySide(),
115
+ this._navObserver.disconnect(),this._metaObserver.disconnect(),this.featureFlags.off("flagsChanged",this._flagsChanged),super.destroy()}contentContainer(){return this.container}fitSideBySide(e){this._lastLayout=e;const t=window.innerWidth-e.width,n=this._sideBySideEnabled&&"auto"===this._sideBySideOptions.mode&&e.expanded&&t>=480;return n?this._activateSideBySide(e.width):this._sideBySideActive&&this._deactivateSideBySide(),this._sideBySideActive=n,this.container.classList.toggle("hypothesis-sidebyside-active",this._sideBySideActive),n}sideBySideActive(){return this._sideBySideActive}supportedTools(){return["selection"]}_activateSideBySide(e){const t=e+12,n=e=>parseInt(window.getComputedStyle(e).marginLeft,10);Hn((()=>{document.body.style.marginLeft="",document.body.style.marginRight="";const e=n(document.body);document.body.style.marginRight=`${t}px`;const o=function(e){const t=new Map,n=new Map,o=Tn.join(","),i=Array.from(e.querySelectorAll(o)).map((e=>({rect:e.getBoundingClientRect(),
116
+ textLength:e.textContent.length}))).filter((({rect:e})=>e.width>0&&e.height>0)).sort(((e,t)=>t.textLength-e.textLength)).slice(0,15);if(i.forEach((({rect:e})=>{let o=t.get(e.left)??0;o+=1,t.set(e.left,o);let i=n.get(e.right)??0;i+=1,n.set(e.right,i)})),0===t.size||0===n.size)return null;const r=[...t.entries()].sort(((e,t)=>t[1]-e[1])),s=[...n.entries()].sort(((e,t)=>t[1]-e[1])),[a]=r[0],[l]=s[0];return{left:a,right:l}}(document.body);if(o){const i=Math.max(0,window.innerWidth-t-o.right);if(i>0){const e=Math.max(0,t-i);document.body.style.marginRight=`${e}px`}n(document.body)>e&&(document.body.style.marginLeft=`${e}px`),o.left<12&&(document.body.style.marginLeft="12px")}else document.body.style.marginLeft="",document.body.style.marginRight=""}))}_deactivateSideBySide(){Hn((()=>{document.body.style.marginLeft="",document.body.style.marginRight=""}))}async getMetadata(){return this._htmlMeta.getDocumentMetadata()}async uri(){return this._htmlMeta.uri()}async scrollToAnchor(e){const t=e.highlights?.[0]
117
+ ;t&&await async function(e,{maxDuration:t=500}={}){const n=e.closest("body");n&&"BODY"!==n.tagName&&Object.defineProperty(n,"tagName",{value:"BODY",configurable:!0});const o=e.closest("details");o&&!o.hasAttribute("open")&&(o.open=!0),await new Promise((n=>yi(e,{time:t},n)))}(t)}}var ki,Ei;var Ri=function(){if(Ei)return ki;Ei=1;var e=NaN,t="[object Symbol]",n=/^\s+|\s+$/g,o=/^[-+]0x[0-9a-f]+$/i,i=/^0b[01]+$/i,r=/^0o[0-7]+$/i,s=parseInt,a="object"==typeof xe&&xe&&xe.Object===Object&&xe,l="object"==typeof self&&self&&self.Object===Object&&self,c=a||l||Function("return this")(),h=Object.prototype.toString,d=Math.max,u=Math.min,f=function(){return c.Date.now()};function m(e){var t=typeof e;return!!e&&("object"==t||"function"==t)}function p(a){if("number"==typeof a)return a;if(function(e){return"symbol"==typeof e||function(e){return!!e&&"object"==typeof e}(e)&&h.call(e)==t}(a))return e;if(m(a)){var l="function"==typeof a.valueOf?a.valueOf():a;a=m(l)?l+"":l}if("string"!=typeof a)return 0===a?a:+a;a=a.replace(n,"")
118
+ ;var c=i.test(a);return c||r.test(a)?s(a.slice(2),c?2:8):o.test(a)?e:+a}return ki=function(e,t,n){var o,i,r,s,a,l,c=0,h=!1,g=!1,_=!0;if("function"!=typeof e)throw new TypeError("Expected a function");function b(t){var n=o,r=i;return o=i=void 0,c=t,s=e.apply(r,n)}function w(e){var n=e-l;return void 0===l||n>=t||n<0||g&&e-c>=r}function v(){var e=f();if(w(e))return y(e);a=setTimeout(v,function(e){var n=t-(e-l);return g?u(n,r-(e-c)):n}(e))}function y(e){return a=void 0,_&&o?b(e):(o=i=void 0,s)}function x(){var e=f(),n=w(e);if(o=arguments,i=this,l=e,n){if(void 0===a)return function(e){return c=e,a=setTimeout(v,t),h?b(e):s}(l);if(g)return a=setTimeout(v,t),b(l)}return void 0===a&&(a=setTimeout(v,t)),s}return t=p(t)||0,m(n)&&(h=!!n.leading,r=(g="maxWait"in n)?d(p(n.maxWait)||0,t):r,_="trailing"in n?!!n.trailing:_),x.cancel=function(){void 0!==a&&clearTimeout(a),c=0,o=l=i=a=void 0},x.flush=function(){return void 0===a?s:y(f())},x},ki}(),Pi=Ne(Ri);function Ti(e,t,n,o=0){let i=o;for(;i<e.length&&t>0;)n(e[i])&&--t,++i
119
+ ;return i}function Mi(e,t,n,o){let i=0;for(let r=n;r<o;r++)t(e[r])&&++i;return i}function Oi(e,t,n,o,i){const r=Mi(e,i,0,n),s=Mi(e,i,n,o);let a=Ti(t,r,i);for(;a<t.length&&!i(t[a]);)++a;return[a,Ti(t,s,i,a)]}const Ii={INITIAL:0,FINISHED:3},Li=new Map,Bi=new Map;function Hi(e,t){return`${e}:${t}`}function Fi(e){const t="closest"in e?e:e.parentElement;return t?.closest(".textLayer")??null}function Di(){return PDFViewerApplication.pdfViewer}async function Vi(e){const t=Di();let n=t.getPageView(e);return n&&n.pdfPage||(n=await new Promise((n=>{const o=()=>{t.eventBus?t.eventBus.off("pagesloaded",o):document.removeEventListener("pagesloaded",o),n(t.getPageView(e))};t.eventBus?t.eventBus.on("pagesloaded",o):document.addEventListener("pagesloaded",o)}))),n}function Ui(e){const t=Li.get(e);if(t)return t;const n=(async()=>{const t=await Vi(e);return(await t.pdfPage.getTextContent({normalizeWhitespace:!0})).items.map((e=>e.str)).join("")})();return Li.set(e,n),n}async function qi(e){const t=Di();let n=0,o=0,i=""
120
+ ;for(let r=0;r<t.pagesCount;r++)if(i=await Ui(r),n=o,o+=i.length,o>=e)return{index:r,offset:n,text:i};return{index:t.pagesCount-1,offset:n,text:i}}function $i(e){switch(e){case" ":case"\f":case"\n":case"\r":case"\t":case"\v":case" ":return!0;default:return!1}}const zi=e=>!$i(e);function Wi(e){return void 0!==e.renderingDone?e.renderingDone:!!e.div&&null!==e.div.querySelector(".endOfContent")}async function ji(e,t,n){const[o,i]=await Promise.all([Vi(e),Ui(e)]);if(o.renderingState===Ii.FINISHED&&o.textLayer&&Wi(o.textLayer)){const e=o.textLayer.textLayerDiv??o.textLayer.div;if(!e)throw new Error("Unable to find PDF.js text layer root");const r=e.textContent,[s,a]=Oi(i,r,t,n,zi);Xi(r.slice(s,a))!==Xi(i.slice(t,n))&&Uo("Text layer text does not match page text. Highlights will be mis-aligned.");const l=new uo(e,s),c=new uo(e,a);return new fo(l,c).toRange()}const r=function(e){let t=e.querySelector(mo);return t||(t=document.createElement("span"),t.classList.add("annotator-placeholder"),
121
+ t.textContent="Loading annotations...",e.appendChild(t),t)}(o.div),s=document.createRange();return s.setStartBefore(r),s.setEndAfter(r),s}function Xi(e){let t="";for(let n=0;n<e.length;n++){const o=e[n];$i(o)||(t+=o)}return t}async function Yi(e){const t=e.find((e=>"TextQuoteSelector"===e.type));if(!t)throw new Error("No quote selector found");const n=e.find((e=>"TextPositionSelector"===e.type));if(n){try{const{index:e,offset:o,text:i}=await qi(n.start),r=n.start-o,s=n.end-o,a=i.substring(r,s);if(t.exact!==a)throw new Error("quote mismatch");return await ji(e,r,s)}catch{}try{const e=Hi(t.exact,n.start),o=Bi.get(e);if(o){const{pageIndex:e,anchor:t}=o;return await ji(e,t.start,t.end)}}catch{}}return async function(e,t){const n=Di().pagesCount,o=Array(n).fill(0).map(((e,t)=>t));let i,r;if(t){const{index:e,offset:n}=await qi(t);i=e,r=t-n,o.sort(((t,n)=>Math.abs(t-e)-Math.abs(n-e)))}const s=void 0!==e.prefix?Xi(e.prefix):void 0,a=void 0!==e.suffix?Xi(e.suffix):void 0,l=Xi(e.exact);let c;for(const e of o){
122
+ const t=await Ui(e),n=Xi(t);let o;void 0!==i&&void 0!==r&&(e<i?o=n.length:e===i?[o]=Oi(t,n,r,r,zi):o=0);const h=ni(n,l,{prefix:s,suffix:a,hint:o});if(h&&(!c||h.score>c.match.score)){const[o,i]=Oi(n,t,h.start,h.end,zi);c={page:e,match:{start:o,end:i,score:h.score}};const r=n.slice(h.start,h.end)===l,d=void 0!==s&&n.slice(Math.max(0,h.start-s.length),h.start)===s,u=void 0!==a&&n.slice(h.end,a.length)===a;if(r&&(d||u||void 0===s&&void 0===a))break}}if(c){const{page:n,match:o}=c;if(t){const i=Hi(e.exact,t);Bi.set(i,{pageIndex:n,anchor:o})}return ji(n,o.start,o.end)}throw new Error("Quote not found")}(t,n?.start)}async function Ki(e){const t=e.find((e=>"PageSelector"===e.type)),n=e.find((e=>"ShapeSelector"===e.type));if(n){if(!t)throw new Error("Cannot anchor a shape selector without a page");return async function(e,t){const n=Di();if("number"!=typeof e.index||e.index<0||e.index>=n.pagesCount)throw new Error("PDF page index is invalid");const o=await Vi(e.index),i=o.div,r=o.viewport,s=e=>function(e,t,n){
123
+ return Math.max(Math.min(e,n),t)}(e,0,1);let a;switch(t.shape.type){case"rect":{const e=t.shape;let[n,o]=r.convertToViewportPoint(e.left,e.top),[i,l]=r.convertToViewportPoint(e.right,e.bottom);i<n&&([n,i]=[i,n]),l<o&&([o,l]=[l,o]),a={type:"rect",left:s(n/r.width),top:s(o/r.height),right:s(i/r.width),bottom:s(l/r.height)}}break;case"point":{const e=t.shape,[n,i]=o.viewport.convertToViewportPoint(e.x,e.y);a={type:"point",x:s(n/r.width),y:s(i/r.height)}}break;default:throw new Error("Unsupported shape in shape selector")}return{anchor:i,shape:a,coordinates:"anchor"}}(t,n)}return Yi(e)}function Gi(e){try{e=fo.fromRange(e).toRange()}catch{throw new Error("Selection does not contain text")}const t=Fi(e.startContainer),n=Fi(e.endContainer);if(!t||!n)throw new Error("Selection is outside page text");if(t!==n)throw new Error("Selecting across page breaks is not supported");return[e,t]}function Qi(e){const t=e.closest(".page"),n=parseInt(t?.getAttribute("data-page-number")??"")
124
+ ;if(!Number.isInteger(n))throw new Error("Unable to get page number from element");return n-1}async function Ji(e){const[t,n]=Gi(e),o=uo.fromPoint(t.startContainer,t.startOffset).relativeTo(n),i=uo.fromPoint(t.endContainer,t.endOffset).relativeTo(n),r=Qi(n),s=await async function(e){if(e>=Di().pagesCount)throw new Error("Invalid page index");let t=0;for(let n=0;n<e;n++)t+=(await Ui(n)).length;return t}(r),a=await Vi(r);return[{type:"TextPositionSelector",start:s+o.offset,end:s+i.offset},ci.fromRange(a.div,t).toSelector(),er(a,r)]}async function Zi(e,t){const n=document.elementsFromPoint(e,t);for(const o of n){if(!o.classList.contains("page"))continue;const n=Qi(o),i=getComputedStyle(o),r=parseFloat(i.borderLeftWidth),s=parseFloat(i.borderTopWidth),a=o.getBoundingClientRect(),l=e-a.left-r,c=t-a.top-s,h=await Vi(n),[d,u]=h.getPagePoint(l,c);return{pageIndex:n,x:d,y:u}}return null}function er(e,t){return{type:"PageSelector",index:t,label:e.pageLabel??`${t+1}`}}function tr({children:e}){return Pe("div",{
125
+ className:"flex flex-col",children:e})}function nr({info:e}){let t=e.item.title;return e.item.subtitle&&(t+=`: ${e.item.subtitle}`),Pe("div",{className:Ee("h-10 bg-white px-4 text-slate-7 text-annotator-base border-b","grid items-center","grid-cols-[100px_minmax(0,auto)]","2xl:grid-cols-[100px_minmax(0,auto)_minmax(0,auto)] 2xl:gap-x-3"),children:[Pe("div",{"data-testid":"content-logo",children:e.logo&&Pe(Jt,{href:e.logo.link,target:"_blank","data-testid":"logo-link",underline:"none",children:Pe("img",{alt:e.logo.title,src:e.logo.logo,"data-testid":"logo-image"})})}),Pe("div",{className:Ee("hidden","2xl:block 2xl:whitespace-nowrap 2xl:overflow-hidden 2xl:text-ellipsis","font-semibold"),"data-testid":"content-container-info",title:e.container.title,children:e.container.title}),Pe("div",{className:Ee("flex justify-center items-center gap-x-2"),"data-testid":"content-item-info",children:[Pe("div",{className:Ee("hidden","2xl:block 2xl:grow")}),e.links.previousItem&&Pe(w,{children:[Pe(Jt,{
126
+ title:"Open previous item",href:e.links.previousItem,underline:"always",target:"_blank","data-testid":"content-previous-link",children:Pe("div",{className:"flex gap-x-1 items-center text-annotator-sm whitespace-nowrap",children:[Pe(qe,{className:"w-em h-em"}),Pe("span",{children:"Previous"})]})}),Pe("div",{className:"text-annotator-sm",children:"|"})]}),Pe("div",{className:Ee("min-w-0 whitespace-nowrap overflow-hidden text-ellipsis shrink font-medium"),children:Pe(Jt,{title:t,href:e.links.currentItem,"data-testid":"content-item-link",target:"_blank",unstyled:!0,children:t})}),e.links.nextItem&&Pe(w,{children:[Pe("div",{className:"text-annotator-sm",children:"|"}),Pe(Jt,{title:"Open next item",href:e.links.nextItem,underline:"always",target:"_blank","data-testid":"content-next-link",children:Pe("div",{className:"flex gap gap-x-1 items-center text-annotator-sm whitespace-nowrap",children:[Pe("span",{children:"Next"}),Pe(ze,{className:"w-em h-em"})]})})]})]})]})}function or(){return Pe("div",{
127
+ className:"bg-white",role:"alert",children:Pe("div",{className:Ee("flex items-center gap-x-2","border border-yellow-notice bg-yellow-notice/10 text-annotator-base"),children:[Pe("div",{className:"bg-yellow-notice text-white p-2",children:Pe(je,{className:"text-annotator-xl"})}),Pe("div",{children:[Pe("strong",{children:"This PDF does not contain selectable text:"})," ",Pe(Jt,{target:"_blank",href:"https://web.hypothes.is/help/how-to-ocr-optimize-pdfs/",underline:"always",children:"Learn how to fix this"})," ","in order to annotate with Hypothesis."]})]})})}class ir{constructor(e){this._loaded=function(e){return e.initializedPromise?e.initializedPromise:e.initialized?Promise.resolve():new Promise((t=>{const n=setInterval((()=>{e.initialized&&(clearTimeout(n),t())}),5)}))}(e).then((async()=>{const t=await async function(e){return void 0!==e.downloadComplete?e.downloadComplete:(await e.pdfDocument.getDownloadInfo(),!0)}(e);return t?e:new Promise((t=>{const n=()=>{e.eventBus?(e.eventBus.off("documentload",n),
128
128
  e.eventBus.off("documentloaded",n)):window.removeEventListener("documentload",n),t(e)};e.eventBus?(e.eventBus.on("documentloaded",n),e.eventBus.on("documentload",n)):window.addEventListener("documentload",n)}))}))}getUri(){return this._loaded.then((e=>{let t=ar(e);return t||(t=sr(rr(e))),t}))}async getMetadata(){const e=await this._loaded,{info:t,contentDispositionFilename:n,metadata:o}=await e.pdfDocument.getMetadata(),i=rr(e),r=ar(e);let s;s=o?.has("dc:title")&&"Untitled"!==o.get("dc:title")?o.get("dc:title"):t?.Title?t.Title:n||(r?function(e){const t=new URL(e),n=t.pathname.split("/");return n[n.length-1]}(r):"");const a=[{href:sr(i)}];return r&&a.push({href:r}),{title:s,link:a,documentFingerprint:i}}}function rr(e){return Array.isArray(e.pdfDocument.fingerprints)?e.pdfDocument.fingerprints[0]:e.pdfDocument.fingerprint}function sr(e){return`urn:x-pdf:${e}`}function ar(e){if(!e.url)return null;const t=Ci(e.url);return 0!==t.indexOf("file://")?t:null}function lr(e){const t=e.highlights?.[0];return t&&po(t)}
129
129
  function cr(e){return new Promise((t=>setTimeout(t,e)))}class hr{constructor(){this._pdfjsContainer=document.querySelector("#outerContainer"),this._contentInfo=null,this._noTextWarning=!1,this._container=null}setContentInfo(e){this._contentInfo=e,this._update()}showNoTextWarning(e){this._noTextWarning=e,this._update()}destroy(){this._container?.destroy()}_update(){if(!(this._noTextWarning||this._contentInfo))return this._container?.destroy(),this._container=null,void(this._pdfjsContainer.style.height="");this._container||(this._container=new eo("banner",(()=>this._render())),document.body.prepend(this._container.element)),this._container.render();const e=this._container.element.getBoundingClientRect().height;this._pdfjsContainer.style.height=`calc(100% - ${e}px)`}_render(){return Pe(tr,{children:[this._contentInfo&&Pe(nr,{info:this._contentInfo}),this._noTextWarning&&Pe(or,{})]})}}class dr extends an{constructor({annotator:e,features:t,reanchoringMaxWait:n}){super(),this._annotator=e
130
130
  ;const o=window,i=o.PDFViewerApplication;this._pdfViewer=i.pdfViewer,this._pdfViewer.viewer.classList.add("has-transparent-text-layer"),this._pdfContainer=i.appConfig?.appContainer??document.body,this._pdfMetadata=new ir(i),this._observer=new MutationObserver(Pi((()=>this._update()),100)),this._observer.observe(this._pdfViewer.viewer,{attributes:!0,attributeFilter:["data-loaded"],childList:!0,subtree:!0}),this._reanchoringMaxWait=n??3e3,this._banner=new hr,this._checkForSelectableText(),this._sideBySideActive=!1,this._updateAnnotationLayerVisibility=()=>{const e=o.getSelection();this._pdfViewer.viewer.classList.toggle("is-selecting",!e.isCollapsed)},this._listeners=new ge,this._listeners.add(document,"selectionchange",this._updateAnnotationLayerVisibility),this._destroyed=!1,this._features=t,this._features.on("flagsChanged",(()=>{this.emit("supportedToolsChanged",this.supportedTools())})),this._pdfViewer.viewer.addEventListener("click",(e=>{const t=e.target;t instanceof HTMLAnchorElement&&(t.target="blank")
@@ -157,7 +157,7 @@ this._sidebarRPC.on("renderThumbnail",((e,t,n)=>{(async()=>{if(!this._integratio
157
157
  this._annotations.delete(e);const n=[];for(const t of this.anchors)t.annotation.$tag!==e?n.push(t):t.highlights&&this._highlighter.removeHighlights(t.highlights);this._updateAnchors(n,t)}_updateAnchors(e,t){this.anchors=e,this._clusterToolbar?.scheduleClusterUpdates(),t&&this._bucketBarClient.update(this.anchors)}async createAnnotation(e){if("selection"===e)return this.createAnnotationFromSelection();if(!["rect","point"].includes(e))throw new Error("Unsupported annotation tool");{let t=!1;try{this._hostRPC.call("activeToolChanged",e);const t=await this._drawTool.draw(e),n=await this.getDocumentInfo(),o=[{source:n.uri,selector:await this._integration.describe(this.element,t)}],i={uri:n.uri,document:n.metadata,target:o,$tag:"a:"+nn(8)};return this._sidebarRPC.call("createAnnotation",i),this.anchor(i),i}catch(e){if(e instanceof Ho&&["canceled","restarted"].includes(e.kind))return t="restarted"===e.kind,null;throw e}finally{t||this._hostRPC.call("activeToolChanged",null)}}}
158
158
  async createAnnotationFromSelection({highlight:e=!1}={}){const t=this.selectedRanges;this.selectedRanges=[];const n=await this.getDocumentInfo(),o=this.element,i=(await Promise.all(t.map((e=>this._integration.describe(o,e))))).map((e=>({source:n.uri,selector:e}))),r={uri:n.uri,document:n.metadata,target:i,$highlight:e,$cluster:e?"user-highlights":"user-annotations",$tag:"a:"+nn(8)};return this._sidebarRPC.call("createAnnotation",r),this.anchor(r),Or(),r}_hoverAnnotations(e){this._hoveredAnnotations.clear(),e.forEach((e=>this._hoveredAnnotations.add(e)));for(const t of this.anchors)if(t.highlights){const n=e.includes(t.annotation.$tag);this._highlighter.setHighlightsFocused(t.highlights,n)}this._sidebarRPC.call("hoverAnnotations",e)}_onSelection(e){const t=this._integration.getAnnotatableRange(e);if(!t)return void this._onClearSelection();const n=document.getSelection(),o=bo(n),i=yo(n);i?(this.selectedRanges=[t],this._hostRPC.call("textSelected"),this._adder.annotationsForSelection=Pr(),
159
159
  this._isAdderVisible=!0,this._adder.show(i,o)):this._onClearSelection()}_onClearSelection(){this._isAdderVisible=!1,this._adder.hide(),this.selectedRanges=[],this._informHostOnNextSelectionClear&&this._hostRPC.call("textUnselected"),this._informHostOnNextSelectionClear=!0}selectAnnotations(e,{toggle:t=!1,focusInSidebar:n=!1}={}){t?this._sidebarRPC.call("toggleAnnotationSelection",e):this._sidebarRPC.call("showAnnotations",e,n),this._sidebarRPC.call("openSidebar")}setHighlightsVisible(e,t=!0){this._highlighter.setHighlightsVisible(e),this._highlightsVisible=e,t&&this._hostRPC.call("highlightsVisibleChanged",e)}get highlightsVisible(){return this._highlightsVisible}fitSideBySide(e){this._sidebarLayout=e,this._integration.fitSideBySide(e)}get hoveredAnnotationTags(){return this._hoveredAnnotations}_handleShortcut(e){Wn(e,"Ctrl+Shift+H")&&this.setHighlightsVisible(!this._highlightsVisible)}_setOutsideAssignmentNoticeVisible(e){this._outsideAssignmentNotice||(this._outsideAssignmentNotice=new kr(this.element)),
160
- this._outsideAssignmentNotice.setVisible(e)}}function Br(e,t){const n=new URL(e),o=new URLSearchParams;return o.append("config",JSON.stringify(t)),n.hash=o.toString(),n.toString()}function Hr(e,t){const n={};for(const[e,o]of Object.entries(t))"notebookAppUrl"!==e&&"sidebarAppUrl"!==e&&null!=o&&(n[e]=o);n.origin=new URL(e).origin,n.version="1.1637.0";const o=new URL(window.location.href);if(o.hash="",n.hostURL=o.toString(),Array.isArray(n.services)&&n.services?.length>0){const e=n.services[0];e.onLoginRequest&&(e.onLoginRequestProvided=!0),e.onLogoutRequest&&(e.onLogoutRequestProvided=!0),e.onSignupRequest&&(e.onSignupRequestProvided=!0),e.onProfileRequest&&(e.onProfileRequestProvided=!0),e.onHelpRequest&&(e.onHelpRequestProvided=!0)}return n}function Fr({closed:e,onClose:t,children:n,"data-testid":o,"aria-label":i}){const r=oe(null);return te((()=>{e?r.current?.close():r.current?.showModal()}),[e]),te((()=>{const e=r.current;return e?.addEventListener("cancel",t),()=>{e?.removeEventListener("cancel",t)}
160
+ this._outsideAssignmentNotice.setVisible(e)}}function Br(e,t){const n=new URL(e),o=new URLSearchParams;return o.append("config",JSON.stringify(t)),n.hash=o.toString(),n.toString()}function Hr(e,t){const n={};for(const[e,o]of Object.entries(t))"notebookAppUrl"!==e&&"sidebarAppUrl"!==e&&null!=o&&(n[e]=o);n.origin=new URL(e).origin,n.version="1.1638.0";const o=new URL(window.location.href);if(o.hash="",n.hostURL=o.toString(),Array.isArray(n.services)&&n.services?.length>0){const e=n.services[0];e.onLoginRequest&&(e.onLoginRequestProvided=!0),e.onLogoutRequest&&(e.onLogoutRequestProvided=!0),e.onSignupRequest&&(e.onSignupRequestProvided=!0),e.onProfileRequest&&(e.onProfileRequestProvided=!0),e.onHelpRequest&&(e.onHelpRequestProvided=!0)}return n}function Fr({closed:e,onClose:t,children:n,"data-testid":o,"aria-label":i}){const r=oe(null);return te((()=>{e?r.current?.close():r.current?.showModal()}),[e]),te((()=>{const e=r.current;return e?.addEventListener("cancel",t),()=>{e?.removeEventListener("cancel",t)}
161
161
  }),[t]),Pe("dialog",{ref:r,className:"relative w-full h-full backdrop:bg-black/50","data-testid":o,"aria-label":i,children:n})}function Dr({closed:e,children:t,...n}){return Pe("div",{...n,className:Ee("fixed z-max top-0 left-0 right-0 bottom-0 p-3 bg-black/50",{hidden:e}),children:Pe("div",{className:"relative w-full h-full",children:t})})}function Vr({document_:e=document,...t}){return Pe(ie((()=>function(e){return"function"==typeof e.createElement("dialog").showModal}(e)?Fr:Dr),[e]),{...t})}function Ur({config:e,groupId:t}){return Pe("iframe",{title:"Hypothesis annotation notebook",className:"h-full w-full border-0",allow:"fullscreen; clipboard-write",src:Br(e.notebookAppUrl,{...Hr(e.notebookAppUrl,e),group:t})})}function qr({eventBus:e,config:t}){const[n,o]=ee(0),[i,r]=ee(!0),[s,a]=ee(null),l=oe(""),c=oe(null);te((()=>(l.current=document.body.style.overflow,()=>{document.body.style.overflow=l.current})),[]),te((()=>{document.body.style.overflow=i?l.current:"hidden"}),[i]),te((()=>{
162
162
  const t=e.createEmitter();return t.subscribe("openNotebook",(e=>{r(!1),o((e=>e+1)),a(e)})),c.current=t,()=>{t.destroy()}}),[e]);const h=re((()=>{r(!0),c.current?.publish("closeNotebook")}),[]);return null===s?null:Pe(Vr,{closed:i,onClose:h,"data-testid":"notebook-outer","aria-label":"Hypothesis notebook",children:[Pe("div",{className:"absolute right-0 m-3",children:Pe(kt,{title:"Close notebook",onClick:h,variant:"dark",classes:Ee("!bg-transparent enabled:hover:!bg-grey-3"),"data-testid":"close-button",children:Pe(Fe,{className:"w-4 h-4"})})}),Pe(Ur,{config:t,groupId:s},n)]})}class $r{constructor(e,t,n){this._container=new eo("notebook",(()=>Pe(qr,{eventBus:t,config:n}))),e.append(this._container.element),this._container.render()}destroy(){this._container.destroy()}}function zr({eventBus:e,config:t}){const[n,o]=ee(!0),i=oe(null);te((()=>{const t=e.createEmitter();return t.subscribe("openProfile",(()=>{o(!1)})),i.current=t,()=>{t.destroy()}}),[e]);const r=()=>{o(!0),i.current?.publish("closeProfile")}
163
163
  ;return n?null:Pe(Vr,{closed:n,onClose:r,"data-testid":"profile-outer","aria-label":"Hypothesis profile",children:[Pe("div",{className:"absolute right-0 m-3",children:Pe(kt,{title:"Close profile dialog",onClick:r,variant:"dark",classes:Ee("!bg-transparent enabled:hover:!bg-grey-3"),children:Pe(Fe,{className:"w-4 h-4"})})}),Pe("iframe",{title:"Hypothesis profile",className:"h-full w-full border-0",src:t.profileAppUrl})]})}class Wr{constructor(e,t,n){this._container=new eo("profile",(()=>Pe(zr,{eventBus:t,config:n}))),e.append(this._container.element),this._container.render()}destroy(){this._container.destroy()}}function jr({above:e,below:t,buckets:n,onFocusAnnotations:o,onScrollToAnnotation:i,onSelectAnnotations:r}){const s=e.anchors.length>0,a=t.anchors.length>0,l=e=>e.anchors.map((e=>e.tag));return Pe("ul",{className:"relative",children:[s&&Pe("li",{className:"absolute right-0 pointer-events-auto mt-[-11px]",style:{top:e.position},children:Pe(en,{"data-testid":"up-navigation-button",direction:"up",