hypothesis 1.1759.0 → 1.1760.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.
|
@@ -103,96 +103,97 @@ secondColor:"transparent",thirdColor:"transparent"},pink:{color:"var(--hypothesi
|
|
|
103
103
|
this._features=e.features,this._container=new Pn("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=To,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 t of Object.keys(this.appliedStyles))this._setClusterStyles(t,this.appliedStyles[t]);this._activate(this._isActive())}_updateClusters(){this._isActive()&&io(this._element)}_isActive(){return this._features.flagEnabled("styled_highlight_clusters")}_activate(t){this._element.classList.toggle("hypothesis-highlights-clustered",t),this._container.render()}_setClusterStyle(t,e){
|
|
104
104
|
document.documentElement.style.setProperty(t,e)}_setClusterStyles(t,e){const n=Po[e];for(const e of Object.keys(n))this._setClusterStyle(`--hypothesis-${t}-${e}`,n[e])}_onChangeClusterStyle(t,e){this.appliedStyles[t]=e,this._setClusterStyles(t,e),this._container.render()}_render(){return St(Eo,{active:this._isActive(),availableStyles:Po,currentStyles:this.appliedStyles,onStyleChange:(t,e)=>this._onChangeClusterStyle(t,e)})}}function Lo(t){return t.split("").reverse().join("")}function Oo(t){return(t|-t)>>31&1}function Io(t,e,n,o){let i=t.P[n],r=t.M[n];const s=o>>>31,a=e[n]|s,l=a|r,c=(a&i)+i^i|a;let h=r|~(c|i),d=i&c;const u=Oo(h&t.lastRowMask[n])-Oo(d&t.lastRowMask[n]);return h<<=1,d<<=1,d|=s,h|=Oo(o)-s,i=d|~(l|h),r=h&l,t.P[n]=i,t.M[n]=r,u}function Bo(t,e,n){if(0===e.length)return[];n=Math.min(n,e.length);const o=[],i=32,r=Math.ceil(e.length/i)-1,s={P:new Uint32Array(r+1),M:new Uint32Array(r+1),lastRowMask:new Uint32Array(r+1)};s.lastRowMask.fill(1<<31),s.lastRowMask[r]=1<<(e.length-1)%i
|
|
105
105
|
;const a=new Uint32Array(r+1),l=new Map,c=[];for(let t=0;t<256;t++)c.push(a);for(let t=0;t<e.length;t+=1){const n=e.charCodeAt(t);if(l.has(n))continue;const o=new Uint32Array(r+1);l.set(n,o),n<c.length&&(c[n]=o);for(let t=0;t<=r;t+=1){o[t]=0;for(let r=0;r<i;r+=1){const s=t*i+r;if(s>=e.length)continue;e.charCodeAt(s)===n&&(o[t]|=1<<r)}}}let h=Math.max(0,Math.ceil(n/i)-1);const d=new Uint32Array(r+1);for(let t=0;t<=h;t+=1)d[t]=(t+1)*i;d[r]=e.length;for(let t=0;t<=h;t+=1)s.P[t]=-1,s.M[t]=0;for(let u=0;u<t.length;u+=1){const f=t.charCodeAt(u);let p;f<c.length?p=c[f]:(p=l.get(f),void 0===p&&(p=a));let g=0;for(let t=0;t<=h;t+=1)g=Io(s,p,t,g),d[t]+=g;if(d[h]-g<=n&&h<r&&(1&p[h+1]||g<0)){let t;if(h+=1,s.P[h]=-1,s.M[h]=0,h===r){const n=e.length%i;t=0===n?i:n}else t=i;d[h]=d[h-1]+t-g+Io(s,p,h,g)}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 Do(t,e,n){return function(t,e,n){const o=Lo(e);return n.map((n=>{
|
|
106
|
-
const i=Math.max(0,n.end-e.length-n.errors);return{start:Bo(Lo(t.slice(i,n.end)),o,n.errors).reduce(((t,e)=>n.end-e.end<t?n.end-e.end:t),n.end),end:n.end,errors:n.errors}}))}(t,e,Bo(t,e,n))}function Fo(t,e,n){let o=0;const i=[];for(;-1!==o;)o=t.indexOf(e,o),-1!==o&&(i.push({start:o,end:o+e.length,errors:0}),o+=1);return i.length>0?i:Do(t,e,n)}function Ho(t,e){if(0===e.length||0===t.length)return 0;return 1-Fo(t,e,e.length)[0].errors/e.length}function Vo(t,e,n={}){if(0===e.length)return null;const o=Math.min(256,e.length/2),i=Fo(t,e,o);if(0===i.length)return null;const r=o=>{const i=1-o.errors/e.length,r=n.prefix?Ho(t.slice(Math.max(0,o.start-n.prefix.length),o.start),n.prefix):1,s=n.suffix?Ho(t.slice(o.end,o.end+n.suffix.length),n.suffix):1;let a=1;if("number"==typeof n.hint){a=1-Math.abs(o.start-n.hint)/t.length}return(50*i+20*r+20*s+2*a)/92},s=i.map((t=>({start:t.start,end:t.end,score:r(t)})));return s.sort(((t,e)=>e.score-t.score)),s[0]}function zo(t){const e=
|
|
107
|
-
;return"#text"===e?"text()":e}(t),n=function(t){let e=0,n=t;for(;n;)n.nodeName===t.nodeName&&(e+=1),n=n.previousSibling;return e}(t);return`${e}[${n}]`}function
|
|
108
|
-
constructor(t,e){this.root=t,this.range=e}static fromRange(t,e){return new
|
|
109
|
-
return Un.fromOffsets(this.root,this.start,this.end).toRange()}}class
|
|
110
|
-
const n=Xo(t?.getAttribute("data-time-start")??""),o=
|
|
111
|
-
;return o.setEnd(i,i.childNodes.length),o}static fromSelector(t,e){const{start:n,end:o}=e;return new
|
|
112
|
-
|
|
113
|
-
o=t.align.
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
_getMetaTags(
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
;
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
const
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
;const i=
|
|
134
|
-
"
|
|
135
|
-
href:t.links.
|
|
136
|
-
|
|
137
|
-
return
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
const
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
;
|
|
149
|
-
|
|
150
|
-
;
|
|
151
|
-
|
|
152
|
-
const n=
|
|
153
|
-
|
|
154
|
-
;
|
|
155
|
-
children:"You are outside the page range for this assignment. Annotations made here may not be counted."})}class
|
|
156
|
-
this.
|
|
157
|
-
|
|
158
|
-
this.
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
this._sidebarRPC.on("
|
|
164
|
-
|
|
165
|
-
;this._drawTool.getKeyboardModeState().keyboardActive
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
document:
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
106
|
+
const i=Math.max(0,n.end-e.length-n.errors);return{start:Bo(Lo(t.slice(i,n.end)),o,n.errors).reduce(((t,e)=>n.end-e.end<t?n.end-e.end:t),n.end),end:n.end,errors:n.errors}}))}(t,e,Bo(t,e,n))}function Fo(t,e,n){let o=0;const i=[];for(;-1!==o;)o=t.indexOf(e,o),-1!==o&&(i.push({start:o,end:o+e.length,errors:0}),o+=1);return i.length>0?i:Do(t,e,n)}function Ho(t,e){if(0===e.length||0===t.length)return 0;return 1-Fo(t,e,e.length)[0].errors/e.length}function Vo(t,e,n={}){if(0===e.length)return null;const o=Math.min(256,e.length/2),i=Fo(t,e,o);if(0===i.length)return null;const r=o=>{const i=1-o.errors/e.length,r=n.prefix?Ho(t.slice(Math.max(0,o.start-n.prefix.length),o.start),n.prefix):1,s=n.suffix?Ho(t.slice(o.end,o.end+n.suffix.length),n.suffix):1;let a=1;if("number"==typeof n.hint){a=1-Math.abs(o.start-n.hint)/t.length}return(50*i+20*r+20*s+2*a)/92},s=i.map((t=>({start:t.start,end:t.end,score:r(t)})));return s.sort(((t,e)=>e.score-t.score)),s[0]}function zo(t){const e=document.createElement("div")
|
|
107
|
+
;return e.appendChild(t.cloneContents()),function(t){for(const e of Array.from(t.querySelectorAll("br")))e.replaceWith(document.createTextNode(" "));return t.textContent??""}(e)}function Uo(t,e){let n=0;for(const o of t){if(!(o<e))break;n+=1}return e-n}function $o(t){const e=function(t){const e=t.nodeName.toLowerCase();return"#text"===e?"text()":e}(t),n=function(t){let e=0,n=t;for(;n;)n.nodeName===t.nodeName&&(e+=1),n=n.previousSibling;return e}(t);return`${e}[${n}]`}function qo(t,e){let n="",o=t;for(;o!==e;){if(!o)throw new Error("Node is not a descendant of root");n=$o(o)+"/"+n,o=o.parentNode}return n="/"+n,n=n.replace(/\/$/,""),n}function Wo(t,e,n){e=e.toUpperCase();let o=-1;for(let i=0;i<t.children.length;i++){const r=t.children[i];if(r.nodeName.toUpperCase()===e&&(++o,o===n))return r}return null}function jo(t,e=document.body){try{return function(t,e){if(null===t.match(/^(\/[A-Za-z0-9-]+(\[[0-9]+\])?)+$/))throw new Error("Expression is not a simple XPath");const n=t.split("/");let o=e;n.shift()
|
|
108
|
+
;for(const t of n){let e,n;const i=t.indexOf("[");if(-1!==i){e=t.slice(0,i);const o=t.slice(i+1,t.indexOf("]"));if(n=parseInt(o)-1,n<0)return null}else e=t,n=0;const r=Wo(o,e,n);if(!r)return null;o=r}return o}(t,e)}catch{return document.evaluate("."+t,e,null,XPathResult.FIRST_ORDERED_NODE_TYPE,null).singleNodeValue}}class Ko{constructor(t,e){this.root=t,this.range=e}static fromRange(t,e){return new Ko(t,e)}static fromSelector(t,e){const n=jo(e.startContainer,t);if(!n)throw new Error("Failed to resolve startContainer XPath");const o=jo(e.endContainer,t);if(!o)throw new Error("Failed to resolve endContainer XPath");const i=zn.fromCharOffset(n,e.startOffset),r=zn.fromCharOffset(o,e.endOffset),s=new Un(i,r).toRange();return new Ko(t,s)}toRange(){return this.range}toSelector(){const t=Un.fromRange(this.range).toRange(),e=Un.fromRange(t),n=qo(e.start.element,this.root),o=qo(e.end.element,this.root);return{type:"RangeSelector",startContainer:n,startOffset:e.start.offset,endContainer:o,endOffset:e.end.offset}}}
|
|
109
|
+
class Xo{constructor(t,e,n){this.root=t,this.start=e,this.end=n}static fromRange(t,e){const n=Un.fromRange(e).relativeTo(t);return new Xo(t,n.start.offset,n.end.offset)}static fromSelector(t,e){return new Xo(t,e.start,e.end)}toSelector(){return{type:"TextPositionSelector",start:this.start,end:this.end}}toRange(){return Un.fromOffsets(this.root,this.start,this.end).toRange()}}class Yo{constructor(t,e,n={}){this.root=t,this.exact=e,this.context=n}static fromRange(t,e){const n=t.textContent??"",o=Un.fromRange(e).relativeTo(t),i=o.start.offset,r=o.end.offset,s=zo(e),a=zo(Un.fromOffsets(t,Math.max(0,i-32),i).toRange()),l=zo(Un.fromOffsets(t,r,Math.min(n.length,r+32)).toRange());return new Yo(t,s,{prefix:a,suffix:l})}static fromSelector(t,e){const{prefix:n,suffix:o}=e;return new Yo(t,e.exact,{prefix:n,suffix:o})}toSelector(){return{type:"TextQuoteSelector",exact:this.exact,prefix:this.context.prefix,suffix:this.context.suffix}}toRange(t={}){return this.toPositionAnchor(t).toRange()}toPositionAnchor(t={}){
|
|
110
|
+
const{text:e,brPositionsInText:n}=function(t){let e="";const n=[],o=t=>{if(t.nodeType!==Node.TEXT_NODE){if(t.nodeType===Node.ELEMENT_NODE){if("BR"===t.tagName)return n.push(e.length),void(e+=" ");for(const e of Array.from(t.childNodes))o(e)}}else e+=t.textContent??""};return o(t),{text:e,brPositionsInText:n}}(this.root),o=Vo(e,this.exact,{...this.context,hint:t.hint});if(!o)throw new Error("Quote not found");return new Xo(this.root,Uo(n,o.start),Uo(n,o.end))}}function Go(t){const e=parseFloat(t);return!Number.isFinite(e)||e<0?null:e}function Qo(t){return t instanceof Element?t:t.parentElement}function Jo(t,e=t){const n=Go(t?.getAttribute("data-time-start")??""),o=Go(e?.getAttribute("data-time-end")??"");return"number"!=typeof n||"number"!=typeof o||o<n?null:[n,o]}class Zo{constructor(t,e,n){this.root=t,this.start=e,this.end=n}static fromRange(t,e){const n=Qo(e.startContainer)?.closest("[data-time-start]"),o=Qo(e.endContainer)?.closest("[data-time-end]"),i=Jo(n,o);if(!i)return null;const[r,s]=i
|
|
111
|
+
;return new Zo(t,r,s)}toRange(){const t=[...this.root.querySelectorAll("[data-time-start]")].map((t=>{const e=Jo(t);if(!e)return null;const[n,o]=e;return{element:t,start:n,end:o}})).filter((t=>null!==t));t.sort(((t,e)=>t.start-e.start));const e=function(t,e){for(let n=t.length-1;n>=0;n--)if(e(t[n]))return n;return-1}(t,(t=>t.start<=this.start&&t.end>=this.start));if(-1===e)throw new Error("Start segment not found");const n=e+t.slice(e).findIndex((t=>t.start<=this.end&&t.end>=this.end));if(-1===n)throw new Error("End segment not found");const o=new Range;o.setStart(t[e].element,0);const i=t[n].element;return o.setEnd(i,i.childNodes.length),o}static fromSelector(t,e){const{start:n,end:o}=e;return new Zo(t,n,o)}toSelector(){return{type:"MediaTimeSelector",start:this.start,end:this.end}}}async function ti(t,e){return t.toRange(e)}function ei(t,e,n){const o=t[e];if("function"!=typeof o)throw new Error("Can only intercept functions");return t[e]=(...e)=>{const i=o.call(t,...e);return n(...e),i},()=>{t[e]=o}}
|
|
112
|
+
function ni(t){return t.replace(/#.*/,"")}class oi{constructor(t,e=(()=>location.href)){this._listeners=new mt;let n=e();const o=(o=e())=>{ni(n)!==ni(o)&&(n=o,t(o))},i=function(){const t=window.navigation;return"function"==typeof Navigation&&t instanceof Navigation?t:null}();if(i)this._listeners.add(i,"navigatesuccess",(()=>o()));else{const t=[ei(window.history,"pushState",(()=>o())),ei(window.history,"replaceState",(()=>o()))];this._unpatchHistory=()=>t.forEach((t=>t())),this._listeners.add(window,"popstate",(()=>o()))}}disconnect(){this._unpatchHistory?.(),this._listeners.removeAll()}}var ii,ri;var si=function(){if(ri)return ii;ri=1;var t="complete",e="canceled";function n(t,e,n){t.self===t?t.scrollTo(e,n):(t.scrollLeft=e,t.scrollTop=n)}function o(e){var i=e._scrollSettings;if(i){var r=i.maxSynchronousAlignments,s=function(t,e){
|
|
113
|
+
var n,o,i,r,s,a,l,c=t.align,h=t.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,p=c&&null!=c.topOffset?c.topOffset:0,g=d,_=u;if(t.isWindow(e))a=Math.min(h.width,e.innerWidth),l=Math.min(h.height,e.innerHeight),o=h.left+e.pageXOffset-e.innerWidth*g+a*g,i=h.top+e.pageYOffset-e.innerHeight*_+l*_,o-=f,i-=p,o=t.align.lockX?e.pageXOffset:o,i=t.align.lockY?e.pageYOffset:i,r=o-e.pageXOffset,s=i-e.pageYOffset;else{a=h.width,l=h.height,n=e.getBoundingClientRect();var m=h.left-(n.left-e.scrollLeft),b=h.top-(n.top-e.scrollTop);o=m+a*g-e.clientWidth*g,i=b+l*_-e.clientHeight*_,o-=f,i-=p,o=Math.max(Math.min(o,e.scrollWidth-e.clientWidth),0),i=Math.max(Math.min(i,e.scrollHeight-e.clientHeight),0),o=t.align.lockX?e.scrollLeft:o,i=t.align.lockY?e.scrollTop:i,r=o-e.scrollLeft,s=i-e.scrollTop}return{x:o,y:i,differenceX:r,differenceY:s}}(i,e),a=Date.now()-i.startTime,l=Math.min(1/i.time*a,1);if(i.endIterations>=r)return n(e,s.x,s.y),
|
|
114
|
+
e._scrollSettings=null,i.end(t);var c=1-i.ease(l);if(n(e,s.x-s.differenceX*c,s.y-s.differenceY*c),a>=i.time)return i.endIterations++,i.scrollAncestor&&o(i.scrollAncestor),void o(e);!function(t){if("requestAnimationFrame"in window)return window.requestAnimationFrame(t);setTimeout(t,16)}(o.bind(null,e))}}function i(t){return t.self===t}function r(t){return"pageXOffset"in t||(t.scrollHeight!==t.clientHeight||t.scrollWidth!==t.clientWidth)&&"hidden"!==getComputedStyle(t).overflow}function s(){return!0}function a(t){if(t.assignedSlot)return a(t.assignedSlot);if(t.parentElement)return"body"===t.parentElement.tagName.toLowerCase()?t.parentElement.ownerDocument.defaultView||t.parentElement.ownerDocument.ownerWindow:t.parentElement;if(t.getRootNode){var e=t.getRootNode();if(11===e.nodeType)return e.host}}return ii=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(t){return 1-Math.pow(1-t,t/2)},l.align=l.align||{}
|
|
115
|
+
;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 p=[];h;)if(l.debug&&console.log("Scrolling parent node",h),u(h,d)&&(f?f(h,r):r(h))&&(d++,p.push(h)),!(h=a(h))){g(t);break}return p.reduce(((t,r,s)=>function(t,n,r,s,a){var l,c=!n._scrollSettings,h=n._scrollSettings,d=Date.now(),u={passive:!0};function f(t){n._scrollSettings=null,n.parentElement&&n.parentElement._scrollSettings&&n.parentElement._scrollSettings.end(t),r.debug&&console.log("Scrolling ended with type",t,"for",n),a(t),l&&(n.removeEventListener("touchstart",l,u),n.removeEventListener("wheel",l,u))}h&&h.end(e);var p=r.maxSynchronousAlignments;return null==p&&(p=3),n._scrollSettings={startTime:d,endIterations:0,target:t,time:r.time,ease:r.ease,align:r.align,isWindow:r.isWindow||i,maxSynchronousAlignments:p,end:f,scrollAncestor:s},"cancellable"in r&&!r.cancellable||(l=f.bind(null,e),n.addEventListener("touchstart",l,u),
|
|
116
|
+
n.addEventListener("wheel",l,u)),c&&o(n),l}(n,r,l,p[s+1],g)),null)}function g(t){--d||c&&c(t)}},ii}(),ai=kt(si);function li(t,e,n){return t+n*(e-t)}async function ci(t,e,{maxDuration:n=500}={}){const o=t.scrollTop,i=e,r=Date.now(),s=Math.min(Math.abs(i-o)/3,n);let a=0;for(;a<1;)await new Promise((t=>{requestAnimationFrame(t)})),a=Math.min(1,(Date.now()-r)/s),t.scrollTop=li(o,i,a)}function hi(t,e=document.baseURI){return new URL(t,e).href.toString().replace(/#.*/,"")}class di{constructor(t={}){this.document=t.document||document}uri(){let t=this._getDocumentHref();try{t=decodeURIComponent(t)}catch(t){console.error("Error decoding URI:",t)}const e=this._getLinks();for(const n of e)"canonical"===n.rel&&(t=n.href);return t}getDocumentMetadata(){const t={title:document.title,link:[],dc:this._getMetaTags("name","dc."),eprints:this._getMetaTags("name","eprints."),facebook:this._getMetaTags("property","og:"),highwire:this._getMetaTags("name","citation_"),prism:this._getMetaTags("name","prism."),
|
|
117
|
+
twitter:this._getMetaTags("name","twitter:")},e=this._getFavicon();e&&(t.favicon=e),t.title=this._getTitle(t),t.link=this._getLinks(t);const n=t.link.find((t=>t.href.startsWith("urn:x-dc")));n&&(t.documentFingerprint=n.href);const o=this._getVersion(t);return null!==o&&(t.version=o),t}_getVersion(t){const e=[t.highwire.id??[],t.highwire.public_url??[],[t.link.find((t=>"canonical"===t.rel))?.href]];let n=null;for(const t of e){const e=this._findVersion(t);if(!e)return null;if(null===n)n=e;else if(n!==e)return null}return n}_findVersion(t){for(const e of t){const t=this._extractVersionFromUri(e);if(null!==t)return t}return null}_extractVersionFromUri(t){if(void 0===t)return null;const e=t.trim().match(/(?<![a-zA-Z])v(\d+)$/i);if(!e)return null;const n=parseInt(e[1],10);return n>=1&&n<=25?n:null}_getMetaTags(t,e){const n={};for(const o of Array.from(this.document.querySelectorAll("meta"))){const i=o.getAttribute(t),{content:r}=o;if(i&&r){const t=i.match(RegExp(`^${e}(.+)$`,"i"));if(t){const e=t[1].toLowerCase()
|
|
118
|
+
;n[e]?n[e].push(r):n[e]=[r]}}}return n}_getTitle(t){return t.highwire.title?t.highwire.title[0]:t.eprints.title?t.eprints.title[0]:t.prism.title?t.prism.title[0]:t.facebook.title?t.facebook.title[0]:t.twitter.title?t.twitter.title[0]:t.dc.title?t.dc.title[0]:this.document.title}_getLinks(t={dc:{},highwire:{}}){const e=[{href:this._getDocumentHref()}],n=Array.from(this.document.querySelectorAll("link"));for(const t of n)if(["alternate","canonical","bookmark","shortlink"].includes(t.rel)){if("alternate"===t.rel){if(t.type&&t.type.match(/^application\/(rss|atom)\+xml/))continue;if(t.hreflang)continue}try{const n=this._absoluteUrl(t.href);e.push({href:n,rel:t.rel,type:t.type})}catch{}}for(const n of Object.keys(t.highwire)){const o=t.highwire[n];if("pdf_url"===n)for(const t of o)try{e.push({href:this._absoluteUrl(t),type:"application/pdf"})}catch{}if("doi"===n)for(let t of o)"doi:"!==t.slice(0,4)&&(t=`doi:${t}`),e.push({href:t})}for(const n of Object.keys(t.dc)){const o=t.dc[n]
|
|
119
|
+
;if("identifier"===n)for(const t of o)"doi:"===t.slice(0,4)&&e.push({href:t})}const o=t.dc["relation.ispartof"],i=t.dc.identifier;if(o&&i){const t=o[o.length-1],n=i[i.length-1],r="urn:x-dc:"+encodeURIComponent(t)+"/"+encodeURIComponent(n);e.push({href:r})}return e}_getFavicon(){let t=null;for(const e of Array.from(this.document.querySelectorAll("link")))if(["shortcut icon","icon"].includes(e.rel))try{t=this._absoluteUrl(e.href)}catch{}return t}_absoluteUrl(t){return hi(t,this.document.baseURI)}_getDocumentHref(){const{href:t}=this.document.location,e=["http:","https:","file:"],n=new URL(t).protocol;return e.includes(n)?t:this.document.baseURI&&e.includes(new URL(this.document.baseURI).protocol)?this.document.baseURI:t}}class ui extends Me{constructor({features:t,container:e=document.body,sideBySideOptions:n}){super(),this.featureFlags=t,this.container=e,this._htmlMeta=new di,this._prevURI=this._htmlMeta.uri(),this._sideBySideEnabled=!0,this._sideBySideOptions=n??{mode:"auto"},this._sideBySideActive=!1,
|
|
120
|
+
this._lastLayout=null,this._navObserver=new oi((()=>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(t,e){return function(t,e,n={}){let o=null,i=null,r=null,s=null;for(const t of e)switch(t.type){case"TextPositionSelector":i=t,n.hint=i.start;break;case"TextQuoteSelector":r=t;break;case"RangeSelector":s=t;break;case"MediaTimeSelector":o=t}const a=t=>{if(r?.exact&&t.toString()!==r.exact)throw new Error("quote mismatch");return t};let l=Promise.reject("unable to anchor");if(s){const e=s;l=l.catch((()=>ti(Ko.fromSelector(t,e),n).then(a)))}if(i){const e=i;l=l.catch((()=>ti(Xo.fromSelector(t,e),n).then(a)))}if(r){const e=r;l=l.catch((()=>ti(Yo.fromSelector(t,e),n)))}if(o){const e=o;l=l.catch((()=>Zo.fromSelector(t,e).toRange()))}return l}(t,e)}
|
|
121
|
+
describe(t,e){if(e instanceof Range)return function(t,e){const n=[Zo,Ko,Xo,Yo],o=[];for(const i of n)try{const n=i.fromRange(t,e);n&&o.push(n.toSelector())}catch{}return o}(t,e);throw new Error("Unsupported region type")}_checkForURIChange(){const t=this._htmlMeta.uri();t!==this._prevURI&&(this._prevURI=t,this.emit("uriChanged",t))}getAnnotatableRange(t){try{return Un.trimmedRange(t)}catch(t){if(t instanceof RangeError)return null;throw t}}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(t){this._lastLayout=t;const e=window.innerWidth-t.width,n=this._sideBySideEnabled&&"auto"===this._sideBySideOptions.mode&&t.expanded&&e>=480;return n?this._activateSideBySide(t.width):this._sideBySideActive&&this._deactivateSideBySide(),this._sideBySideActive=n,
|
|
122
|
+
this.container.classList.toggle("hypothesis-sidebyside-active",this._sideBySideActive),n}sideBySideActive(){return this._sideBySideActive}supportedTools(){return["selection"]}_activateSideBySide(t){const e=t+12,n=t=>parseInt(window.getComputedStyle(t).marginLeft,10);on((()=>{document.body.style.marginLeft="",document.body.style.marginRight="";const t=n(document.body);document.body.style.marginRight=`${e}px`;const o=function(t){const e=new Map,n=new Map,o=Qe.join(","),i=Array.from(t.querySelectorAll(o)).map((t=>({rect:t.getBoundingClientRect(),textLength:t.textContent.length}))).filter((({rect:t})=>t.width>0&&t.height>0)).sort(((t,e)=>e.textLength-t.textLength)).slice(0,15);if(i.forEach((({rect:t})=>{let o=e.get(t.left)??0;o+=1,e.set(t.left,o);let i=n.get(t.right)??0;i+=1,n.set(t.right,i)})),0===e.size||0===n.size)return null;const r=[...e.entries()].sort(((t,e)=>e[1]-t[1])),s=[...n.entries()].sort(((t,e)=>e[1]-t[1])),[a]=r[0],[l]=s[0];return{left:a,right:l}}(document.body);if(o){
|
|
123
|
+
const i=Math.max(0,window.innerWidth-e-o.right);if(i>0){const t=Math.max(0,e-i);document.body.style.marginRight=`${t}px`}n(document.body)>t&&(document.body.style.marginLeft=`${t}px`),o.left<12&&(document.body.style.marginLeft="12px")}else document.body.style.marginLeft="",document.body.style.marginRight=""}))}_deactivateSideBySide(){on((()=>{document.body.style.marginLeft="",document.body.style.marginRight=""}))}async getMetadata(){return this._htmlMeta.getDocumentMetadata()}async uri(){return this._htmlMeta.uri()}async scrollToAnchor(t){const e=t.highlights?.[0];e&&await async function(t,{maxDuration:e=500}={}){const n=t.closest("body");n&&"BODY"!==n.tagName&&Object.defineProperty(n,"tagName",{value:"BODY",configurable:!0});const o=t.closest("details");o&&!o.hasAttribute("open")&&(o.open=!0),await new Promise((n=>ai(t,{time:e},n)))}(e)}}var fi,pi;var gi=function(){if(pi)return fi;pi=1
|
|
124
|
+
;var t=NaN,e="[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 At&&At&&At.Object===Object&&At,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 p(t){var e=typeof t;return!!t&&("object"==e||"function"==e)}function g(a){if("number"==typeof a)return a;if(function(t){return"symbol"==typeof t||function(t){return!!t&&"object"==typeof t}(t)&&h.call(t)==e}(a))return t;if(p(a)){var l="function"==typeof a.valueOf?a.valueOf():a;a=p(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)?t:+a}return fi=function(t,e,n){var o,i,r,s,a,l,c=0,h=!1,_=!1,m=!0;if("function"!=typeof t)throw new TypeError("Expected a function");function b(e){var n=o,r=i;return o=i=void 0,c=e,s=t.apply(r,n)}function y(t){var n=t-l;return void 0===l||n>=e||n<0||_&&t-c>=r}
|
|
125
|
+
function w(){var t=f();if(y(t))return v(t);a=setTimeout(w,function(t){var n=e-(t-l);return _?u(n,r-(t-c)):n}(t))}function v(t){return a=void 0,m&&o?b(t):(o=i=void 0,s)}function x(){var t=f(),n=y(t);if(o=arguments,i=this,l=t,n){if(void 0===a)return function(t){return c=t,a=setTimeout(w,e),h?b(t):s}(l);if(_)return a=setTimeout(w,e),b(l)}return void 0===a&&(a=setTimeout(w,e)),s}return e=g(e)||0,p(n)&&(h=!!n.leading,r=(_="maxWait"in n)?d(g(n.maxWait)||0,e):r,m="trailing"in n?!!n.trailing:m),x.cancel=function(){void 0!==a&&clearTimeout(a),c=0,o=l=i=a=void 0},x.flush=function(){return void 0===a?s:v(f())},x},fi}(),_i=kt(gi);function mi(t,e,n,o=0){let i=o;for(;i<t.length&&e>0;)n(t[i])&&--e,++i;return i}function bi(t,e,n,o){let i=0;for(let r=n;r<o;r++)e(t[r])&&++i;return i}const yi=new Map;function wi(t,e){const n=t.normalize("NFKD");if(n===t)return{input:t,output:n};const o=[],i=[];let r=0,s=0;for(const n of t){const t=n.codePointAt(0);let a=yi.get(t);if(void 0===a&&(a=n.normalize("NFKD").length,yi.set(t,a)),
|
|
126
|
+
e.offsets){for(let t=0;t<n.length;t++)i.push(s);s+=a}if(e.reverseOffsets){for(let t=0;t<a;t++)o.push(r);r+=n.length}}return e.offsets&&i.push(n.length),e.reverseOffsets&&o.push(r),{input:t,output:n,reverseOffsets:o,offsets:i}}function vi(t,e,n,o,i,r={}){n=Math.max(0,Math.min(n,t.length)),o=Math.max(n,Math.min(o,t.length));const s=r.normalize?wi(t,{offsets:!0}):{output:t},a=r.normalize?wi(e,{reverseOffsets:!0}):{output:e},l=s.offsets?.[n]??n,c=s.offsets?.[o]??o,h=bi(s.output,i,0,l),d=bi(s.output,i,l,c);let u=mi(a.output,h,i);for(;u<a.output.length&&!i(a.output[u]);)++u;const f=mi(a.output,d,i,u);return[a.reverseOffsets?.[u]??u,a.reverseOffsets?.[f]??f]}const xi={INITIAL:0,FINISHED:3},Ci=new Map,Si=new Map;function Ai(t,e){return`${t}:${e}`}function ki(t){const e="closest"in t?t:t.parentElement;return e?.closest(".textLayer")??null}function Mi(){return PDFViewerApplication.pdfViewer}async function Ri(t){const e=Mi();let n=e.getPageView(t);return n&&n.pdfPage||(n=await new Promise((n=>{const o=()=>{
|
|
127
|
+
e.eventBus?e.eventBus.off("pagesloaded",o):document.removeEventListener("pagesloaded",o),n(e.getPageView(t))};e.eventBus?e.eventBus.on("pagesloaded",o):document.addEventListener("pagesloaded",o)}))),n}function Ei(t,e){return document.elementsFromPoint(t,e).find((t=>t.classList.contains("textLayer")))}function Pi(t){const e=Ci.get(t);if(e)return e;const n=(async()=>{const e=await Ri(t);return(await e.pdfPage.getTextContent({normalizeWhitespace:!0})).items.map((t=>t.str)).join("")})();return Ci.set(t,n),n}async function Ti(t){const e=Mi();let n=0,o=0,i="";for(let r=0;r<e.pagesCount;r++)if(i=await Pi(r),n=o,o+=i.length,o>=t)return{index:r,offset:n,text:i};return{index:e.pagesCount-1,offset:n,text:i}}function Ni(t){switch(t){case" ":case"\f":case"\n":case"\r":case"\t":case"\v":case" ":return!0;default:return!1}}const Li=t=>!Ni(t);function Oi(t){return void 0!==t.renderingDone?t.renderingDone:!!t.div&&null!==t.div.querySelector(".endOfContent")}async function Ii(t,e,n){const[o,i]=await Promise.all([Ri(t),Pi(t)])
|
|
128
|
+
;if(o.renderingState===xi.FINISHED&&o.textLayer&&Oi(o.textLayer)){const t=o.textLayer.textLayerDiv??o.textLayer.div;if(!t)throw new Error("Unable to find PDF.js text layer root");const r=t.textContent,[s,a]=vi(i,r,e,n,Li,{normalize:!0}),l=Bi(r.slice(s,a)),c=Bi(i.slice(e,n));l.normalize("NFKD")!==c.normalize("NFKD")&&Ao("Text layer text does not match page text. Highlights will be mis-aligned.");const h=new zn(t,s),d=new zn(t,a);return new Un(h,d).toRange()}const r=function(t){let e=t.querySelector($n);return e||(e=document.createElement("span"),e.classList.add("annotator-placeholder"),e.textContent="Loading annotations...",t.appendChild(e),e)}(o.div),s=document.createRange();return s.setStartBefore(r),s.setEndAfter(r),s}function Bi(t){let e="";for(let n=0;n<t.length;n++){const o=t[n];Ni(o)||(e+=o)}return e}async function Di(t){const e=t.find((t=>"TextQuoteSelector"===t.type));if(!e)throw new Error("No quote selector found");const n=t.find((t=>"TextPositionSelector"===t.type));if(n){try{
|
|
129
|
+
const{index:t,offset:o,text:i}=await Ti(n.start),r=n.start-o,s=n.end-o,a=i.substring(r,s);if(e.exact!==a)throw new Error("quote mismatch");return await Ii(t,r,s)}catch{}try{const t=Ai(e.exact,n.start),o=Si.get(t);if(o){const{pageIndex:t,anchor:e}=o;return await Ii(t,e.start,e.end)}}catch{}}return async function(t,e){const n=Mi().pagesCount,o=Array(n).fill(0).map(((t,e)=>e));let i,r;if(e){const{index:t,offset:n}=await Ti(e);i=t,r=e-n,o.sort(((e,n)=>Math.abs(e-t)-Math.abs(n-t)))}const s=void 0!==t.prefix?Bi(t.prefix):void 0,a=void 0!==t.suffix?Bi(t.suffix):void 0,l=Bi(t.exact);let c;for(const t of o){const e=await Pi(t),n=Bi(e);let o;void 0!==i&&void 0!==r&&(t<i?o=n.length:t===i?[o]=vi(e,n,r,r,Li,{normalize:!1}):o=0);const h=Vo(n,l,{prefix:s,suffix:a,hint:o});if(h&&(!c||h.score>c.match.score)){const[o,i]=vi(n,e,h.start,h.end,Li);c={page:t,match:{start:o,end:i,score:h.score}}
|
|
130
|
+
;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(e){const i=Ai(t.exact,e);Si.set(i,{pageIndex:n,anchor:o})}return Ii(n,o.start,o.end)}throw new Error("Quote not found")}(e,n?.start)}async function Fi(t){const e=t.find((t=>"PageSelector"===t.type)),n=t.find((t=>"ShapeSelector"===t.type));if(n){if(!e)throw new Error("Cannot anchor a shape selector without a page");return async function(t,e){const n=Mi();if("number"!=typeof t.index||t.index<0||t.index>=n.pagesCount)throw new Error("PDF page index is invalid");const o=await Ri(t.index),i=o.div,r=o.viewport,s=t=>function(t,e,n){return Math.max(Math.min(t,n),e)}(t,0,1);let a;switch(e.shape.type){case"rect":{const t=e.shape;let[n,o]=r.convertToViewportPoint(t.left,t.top),[i,l]=r.convertToViewportPoint(t.right,t.bottom);i<n&&([n,i]=[i,n]),l<o&&([o,l]=[l,o]),a={type:"rect",left:s(n/r.width),
|
|
131
|
+
top:s(o/r.height),right:s(i/r.width),bottom:s(l/r.height)}}break;case"point":{const t=e.shape,[n,i]=o.viewport.convertToViewportPoint(t.x,t.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"}}(e,n)}return Di(t)}function Hi(t){try{t=Un.fromRange(t).toRange()}catch{throw new Error("Selection does not contain text")}const e=ki(t.startContainer),n=ki(t.endContainer);if(!e||!n)throw new Error("Selection is outside page text");if(e!==n)throw new Error("Selecting across page breaks is not supported");return[t,e]}function Vi(t){const e=t.closest(".page"),n=parseInt(e?.getAttribute("data-page-number")??"");if(!Number.isInteger(n))throw new Error("Unable to get page number from element");return n-1}async function zi(t){const[e,n]=Hi(t),o=zn.fromPoint(e.startContainer,e.startOffset).relativeTo(n),i=zn.fromPoint(e.endContainer,e.endOffset).relativeTo(n),r=Vi(n),s=await async function(t){
|
|
132
|
+
if(t>=Mi().pagesCount)throw new Error("Invalid page index");let e=0;for(let n=0;n<t;n++)e+=(await Pi(n)).length;return e}(r),a=await Ri(r);return[{type:"TextPositionSelector",start:s+o.offset,end:s+i.offset},Yo.fromRange(a.div,e).toSelector(),$i(a,r)]}async function Ui(t,e){const n=document.elementsFromPoint(t,e);for(const o of n){if(!o.classList.contains("page"))continue;const n=Vi(o),i=getComputedStyle(o),r=parseFloat(i.borderLeftWidth),s=parseFloat(i.borderTopWidth),a=o.getBoundingClientRect(),l=t-a.left-r,c=e-a.top-s,h=await Ri(n),[d,u]=h.getPagePoint(l,c);return{pageIndex:n,x:d,y:u}}return null}function $i(t,e){return{type:"PageSelector",index:e,label:t.pageLabel??`${e+1}`}}async function qi(t){const e=t=>{const[e,n,o,i]=t.view;return{left:e,top:i,right:o,bottom:n}},n=(t,e)=>function(t,e){const n=t.ownerDocument.createNodeIterator(t,NodeFilter.SHOW_TEXT),o=[];let i,r;for(;r=n.nextNode();){const t=r,n=t.data.split(/\b/);let s=0;for(const r of n){const n=new Range;n.setStart(t,s);const a=s+r.length
|
|
133
|
+
;n.setEnd(t,a);const l=n.getBoundingClientRect();$e(l,e)&&(i&&!qe(i,l)&&o.push(" "),o.push(r),i=l),s=a}}return o.join("")}(t,e).slice(0,256);switch(t.type){case"rect":{const[o,i]=await Promise.all([Ui(t.left,t.top),Ui(t.right,t.bottom)]);if(!o)throw new Error("Top-left point is not in a page");if(!i)throw new Error("Bottom-right point is not in a page");if(o.pageIndex!==i.pageIndex)throw new Error("Shape must start and end on same page");const r=await Ri(o.pageIndex),s={type:"rect",left:o.x,top:o.y,right:i.x,bottom:i.y},a=Ei(t.left,t.top);let l;if(a){l=n(a,new DOMRect(t.left,t.top,t.right-t.left,t.bottom-t.top))}return[$i(r,o.pageIndex),{type:"ShapeSelector",anchor:"page",shape:s,view:e(r.pdfPage),text:l}]}case"point":{const o=await Ui(t.x,t.y);if(!o)throw new Error("Point is not in a page");const i=Ei(t.x,t.y);let r;if(i){r=n(i,new DOMRect(t.x,t.y,1,1))}const s=await Ri(o.pageIndex);return[$i(s,o.pageIndex),{type:"ShapeSelector",anchor:"page",shape:{type:"point",x:o.x,y:o.y},text:r,view:e(s.pdfPage)}]}
|
|
134
|
+
default:throw new Error("Unsupported shape")}}function Wi({children:t}){return St("div",{className:"flex flex-col",children:t})}function ji({info:t}){let e=t.item.title;return t.item.subtitle&&(e+=`: ${t.item.subtitle}`),St("div",{className:Tt("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:[St("div",{"data-testid":"content-logo",children:t.logo&&St(we,{href:t.logo.link,target:"_blank","data-testid":"logo-link",underline:"none",children:St("img",{alt:t.logo.title,src:t.logo.logo,"data-testid":"logo-image"})})}),St("div",{className:Tt("hidden","2xl:block 2xl:whitespace-nowrap 2xl:overflow-hidden 2xl:text-ellipsis","font-semibold"),"data-testid":"content-container-info",title:t.container.title,children:t.container.title}),St("div",{className:Tt("flex justify-center items-center gap-x-2"),"data-testid":"content-item-info",children:[St("div",{
|
|
135
|
+
className:Tt("hidden","2xl:block 2xl:grow")}),t.links.previousItem&&St(y,{children:[St(we,{title:"Open previous item",href:t.links.previousItem,underline:"always",target:"_blank","data-testid":"content-previous-link",children:St("div",{className:"flex gap-x-1 items-center text-annotator-sm whitespace-nowrap",children:[St(Dt,{className:"w-em h-em"}),St("span",{children:"Previous"})]})}),St("div",{className:"text-annotator-sm",children:"|"})]}),St("div",{className:Tt("min-w-0 whitespace-nowrap overflow-hidden text-ellipsis shrink font-medium"),children:St(we,{title:e,href:t.links.currentItem,"data-testid":"content-item-link",target:"_blank",unstyled:!0,children:e})}),t.links.nextItem&&St(y,{children:[St("div",{className:"text-annotator-sm",children:"|"}),St(we,{title:"Open next item",href:t.links.nextItem,underline:"always",target:"_blank","data-testid":"content-next-link",children:St("div",{className:"flex gap gap-x-1 items-center text-annotator-sm whitespace-nowrap",children:[St("span",{children:"Next"
|
|
136
|
+
}),St(Ft,{className:"w-em h-em"})]})})]})]})]})}function Ki(){return St("div",{className:"bg-white",role:"alert",children:St("div",{className:Tt("flex items-center gap-x-2","border border-yellow-notice bg-yellow-notice/10 text-annotator-base"),children:[St("div",{className:"bg-yellow-notice text-white p-2",children:St(Ht,{className:"text-annotator-xl"})}),St("div",{children:[St("strong",{children:"Text annotation tools are unavailable because this PDF does not contain selectable text."})," ",St(we,{target:"_blank",href:"https://web.hypothes.is/help/how-to-ocr-optimize-pdfs/",underline:"always",children:"Learn more here"}),"."]})]})})}class Xi{constructor(t){this._loaded=function(t){return t.initializedPromise?t.initializedPromise:t.initialized?Promise.resolve():new Promise((e=>{const n=setInterval((()=>{t.initialized&&(clearTimeout(n),e())}),5)}))}(t).then((async()=>{const e=await async function(t){return void 0!==t.downloadComplete?t.downloadComplete:(await t.pdfDocument.getDownloadInfo(),!0)}(t)
|
|
137
|
+
;return e?t:new Promise((e=>{const n=()=>{t.eventBus?(t.eventBus.off("documentload",n),t.eventBus.off("documentloaded",n)):window.removeEventListener("documentload",n),e(t)};t.eventBus?(t.eventBus.on("documentloaded",n),t.eventBus.on("documentload",n)):window.addEventListener("documentload",n)}))}))}getUri(){return this._loaded.then((t=>{let e=Qi(t);return e||(e=Gi(Yi(t))),e}))}async getMetadata(){const t=await this._loaded,{info:e,contentDispositionFilename:n,metadata:o}=await t.pdfDocument.getMetadata(),i=Yi(t),r=Qi(t),s=o?.get("dc:title");let a;a=s&&"Untitled"!==s?s:e?.Title?e.Title:n||(r?function(t){const e=new URL(t),n=e.pathname.split("/");return n[n.length-1]}(r):"");const l=[{href:Gi(i)}];return r&&l.push({href:r}),{title:a,link:l,documentFingerprint:i}}}function Yi(t){return Array.isArray(t.pdfDocument.fingerprints)?t.pdfDocument.fingerprints[0]:t.pdfDocument.fingerprint}function Gi(t){return`urn:x-pdf:${t}`}function Qi(t){if(!t.url)return null;const e=hi(t.url);return 0!==e.indexOf("file://")?e:null
|
|
138
|
+
}function Ji(t){const e=t.highlights?.[0];return e&&qn(e)}function Zi(t){return new Promise((e=>setTimeout(e,t)))}class tr{constructor(){this._pdfjsContainer=document.querySelector("#outerContainer"),this._contentInfo=null,this._noTextWarning=!1,this._container=null}setContentInfo(t){this._contentInfo=t,this._update()}showNoTextWarning(t){this._noTextWarning=t,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 Pn("banner",(()=>this._render())),document.body.prepend(this._container.element)),this._container.render();const t=this._container.element.getBoundingClientRect().height;this._pdfjsContainer.style.height=`calc(100% - ${t}px)`}_render(){return St(Wi,{children:[this._contentInfo&&St(ji,{info:this._contentInfo}),this._noTextWarning&&St(Ki,{})]})}}class er extends Me{
|
|
139
|
+
constructor({annotator:t,features:e,reanchoringMaxWait:n}){super(),this._annotator=t;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 Xi(i),this._observer=new MutationObserver(_i((()=>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 tr,this._checkForSelectableText(),this._sideBySideActive=!1,this._updateAnnotationLayerVisibility=()=>{const t=o.getSelection();this._pdfViewer.viewer.classList.toggle("is-selecting",!t.isCollapsed)},this._listeners=new mt,this._listeners.add(document,"selectionchange",this._updateAnnotationLayerVisibility),this._destroyed=!1,this._features=e,this._features.on("flagsChanged",(()=>{this.emit("supportedToolsChanged",this.supportedTools())})),
|
|
140
|
+
this._pdfViewer.viewer.addEventListener("click",(t=>{const e=t.target;e instanceof HTMLAnchorElement&&(e.target="blank");oo(t.clientX,t.clientY).length>0&&t.preventDefault()}))}destroy(){this.fitSideBySide({expanded:!1,width:0,toolbarWidth:0,height:window.innerHeight}),this._listeners.removeAll(),this._pdfViewer.viewer.classList.remove("has-transparent-text-layer"),this._observer.disconnect(),this._banner.destroy(),this._destroyed=!0,super.destroy()}uri(){return this._pdfMetadata.getUri()}getMetadata(){return this._pdfMetadata.getMetadata()}showContentInfo(t){this._banner.setContentInfo(t)}anchor(t,e){return Fi(e)}getAnnotatableRange(t){try{const e=Un.trimmedRange(t);if(function(t){try{return Hi(t),!0}catch{return!1}}(e))return e}catch(t){if(!(t instanceof RangeError))throw t}return null}canStyleClusteredHighlights(){return!0}describe(t,e){return e instanceof Range?zi(e):qi(e)}async _checkForSelectableText(){try{await this.uri()}catch{return}if(!this._destroyed)try{const t=await async function(){const t=Mi()
|
|
141
|
+
;let e=!1;for(let n=0;n<t.pagesCount;n++)if((await Pi(n)).trim().length>0){e=!0;break}return e}();this._banner.showNoTextWarning(!t)}catch(t){console.warn("Unable to check for text in PDF:",t)}}_update(){const t=[],e=this._pdfViewer.pagesCount;for(let t=0;t<e;t++){const e=this._pdfViewer.getPageView(t);if(e?.textLayer&&Oi(e.textLayer))switch(e.renderingState){case xi.INITIAL:e.textLayer=null;break;case xi.FINISHED:n=e.div,n.querySelector($n)?.remove()}}var n;for(const e of this._annotator.anchors)if(e.highlights){if(t.includes(e.annotation))continue;for(let n=0;n<e.highlights.length;n++){const o=e.highlights[n];if(!document.body.contains(o)){e.highlights.splice(n,1),delete e.region,t.push(e.annotation);break}}}t.map((t=>this._annotator.anchor(t)))}contentContainer(){return document.querySelector("#viewerContainer")}fitSideBySide(t){const e=window.innerWidth-t.width,n=t.expanded&&e>=680,o=n?t.width:t.toolbarWidth;this._pdfContainer.style.width=`calc(100% - ${o}px)`;const i=this._pdfViewer.currentScaleValue
|
|
142
|
+
;return"auto"!==i&&"page-fit"!==i&&"page-width"!==i||(this._pdfViewer.currentScaleValue=i),this._pdfViewer.update(),this._sideBySideActive=n,n}sideBySideActive(){return this._sideBySideActive}supportedTools(){const t=this._features?.flagEnabled("pdf_image_annotation");return t?["selection","rect","point"]:["selection"]}async scrollToAnchor(t){const e=t.annotation,n=Ji(t),o=this._anchorOffset(t);if(null!==o&&(await ci(this.contentContainer(),o),n)){const t=await this._waitForAnnotationToBeAnchored(e,this._reanchoringMaxWait);if(!t)return;const n=this._anchorOffset(t);if(null===n)return;await ci(this.contentContainer(),n)}}async _waitForAnnotationToBeAnchored(t,e){const n=Date.now();let o;do{o=this._annotator.anchors.find((e=>e.annotation===t)),o&&!Ji(o)||(o=null,await Zi(20))}while(!o&&Date.now()-n<e);return o??null}_anchorOffset(t){if(!t.highlights)return null;const e=t.highlights[0];return function(t,e,n={}){let o=0,i=e;for(;i!==t&&t.contains(i);)o+=i.offsetTop,i=i.offsetParent;if("center"===n.position){
|
|
143
|
+
const n=t.getBoundingClientRect(),i=e.getBoundingClientRect();o-=n.height/2-i.height/2}return o}(this.contentContainer(),e,{position:"center"})}async renderToBitmap(t,e){const n=t.target.selector?.find((t=>"ShapeSelector"===t.type)),o=t.target.selector?.find((t=>"PageSelector"===t.type));if(!o||!n)throw new Error("Can only render bitmaps for anchors with shapes");const i=this._pdfViewer.getPageView(o.index);if(!i)throw new Error("Failed to get page view");let r,s,a,l;switch(n.shape.type){case"rect":({left:r,right:s,top:a,bottom:l}=n.shape);break;case"point":{const{x:t,y:e}=n.shape,[o,,c]=i.pdfPage.view,h=.1*Math.abs(c-o);r=t-h,a=e+h,s=t+h,l=e-h}break;default:throw new Error("Unsupported shape type")}s<r&&([r,s]=[s,r]),s=Math.max(s,r+1),a<l&&([a,l]=[l,a]),a=Math.max(a,l+1);const c=i.pdfPage.rotate%360;if(c%90!=0)throw new Error("Page rotation is not a multiple of 90 degrees");let h,d;0===c||180===c?(h=Math.abs(s-r),d=Math.abs(l-a)):(h=Math.abs(l-a),d=Math.abs(s-r))
|
|
144
|
+
;const u=96/72,f=e.devicePixelRatio??1,p=h*u*f,g=h/d,_="number"==typeof e.maxWidth?Math.min(e.maxWidth,p):p,m=_/g,b=i.pdfPage.getViewport({scale:1}),y=_/p*u*f,w=new(0,b.constructor)({rotation:c,scale:y,userUnit:b.userUnit,viewBox:[r,l,s,a]}),v=Math.max(_,1),x=Math.max(m,1),C=new OffscreenCanvas(v,x),S=C.getContext("2d"),A=i.pdfPage.render({canvasContext:S,viewport:w});if(await A.promise,"point"===n.shape.type){S.save(),S.scale(y,y);const t=n.shape.x-r,e=n.shape.y-l,o=5;S.strokeStyle="black",S.fillStyle="yellow",S.beginPath(),S.arc(t,e,o,0,2*Math.PI),S.fill(),S.stroke(),S.restore()}return C.transferToImageBitmap()}}function nr(t){if(!t.includes("["))return t;let e="",n=!1,o=!1;for(const i of t)n||"^"!==i?(n||"["!==i?!n&&o&&"]"===i?o=!1:o||(e+=i):o=!0,n=!1):n=!0;return e}function or(t){const e=nr(t),n=e.indexOf("!");return-1===n?e:e.slice(0,n)}class ir{constructor(t,e,n){this._element=t,this._onFrameAdded=e,this._onFrameRemoved=n,this._annotatableFrames=new Set,this._isDisconnected=!1,
|
|
145
|
+
this._mutationObserver=new MutationObserver(_i((()=>{this._discoverFrames()}),40)),this._discoverFrames(),this._mutationObserver.observe(this._element,{childList:!0,subtree:!0,attributeFilter:["enable-annotation"]})}disconnect(){this._isDisconnected=!0,this._mutationObserver.disconnect()}async _addFrame(t){this._annotatableFrames.add(t);try{if(await rr(t),this._isDisconnected)return;t.contentWindow.addEventListener("unload",(()=>{this._removeFrame(t)})),this._onFrameAdded(t)}catch{console.warn(`Unable to inject the Hypothesis client (from '${document.location.href}' into a cross-origin frame '${t.src}')`)}}_removeFrame(t){this._annotatableFrames.delete(t),this._onFrameRemoved(t)}_discoverFrames(){const t=new Set(this._element.querySelectorAll("iframe[enable-annotation]"));for(const e of t)this._annotatableFrames.has(e)||this._addFrame(e);for(const e of this._annotatableFrames)t.has(e)||this._removeFrame(e)}}function rr(t){return new Promise(((e,n)=>{const o=sr(t,((t,i)=>{o(),i?e(i):n(t)}))}))}
|
|
146
|
+
function sr(t,e,{pollInterval:n=10}={}){let o,i;const r=new WeakSet,s=()=>{clearTimeout(o),o=void 0},a=()=>{const n=t.contentDocument;if(n){if(!r.has(n)){if(r.add(n),s(),!function(t){return"about:blank"===t.contentDocument?.location.href&&t.hasAttribute("src")&&"about:blank"!==t.src}(t)){"interactive"===n.readyState||"complete"===n.readyState?e(null,n):n.addEventListener("DOMContentLoaded",(()=>e(null,n)))}t.contentDocument&&t.contentWindow?.addEventListener("unload",i)}}else{s();const n=t.isConnected?"Frame is cross-origin":"Frame is disconnected";e(new Error(n))}};let l=!1;i=()=>{s(),l||(o=setInterval(a,n))},t.addEventListener("load",a);const c=setTimeout(a,0);return()=>{l=!0,clearTimeout(c),s(),t.removeEventListener("load",a)}}class ar{constructor(t,e){this._config=e,this._frameObserver=new ir(t,(t=>lr(t,e)),(()=>{}))}destroy(){this._frameObserver.disconnect()}}async function lr(t,e,n){if(null!==t.contentDocument.querySelector("script.js-hypothesis-config"))return;await rr(t)
|
|
147
|
+
;const{assetRoot:o,notebookAppUrl:i,profileAppUrl:r,sidebarAppUrl:s}=He(document),a={...e,assetRoot:o,notebookAppUrl:i,profileAppUrl:r,sidebarAppUrl:s,subFrameIdentifier:n??Ce(10)},l=document.createElement("script");l.className="js-hypothesis-config",l.setAttribute("data-remove-on-unload",""),l.type="application/json",l.innerText=JSON.stringify(a);const c=document.createElement("script");c.async=!0,c.src=e.clientUrl;const h=t.contentDocument;h.body.appendChild(l),h.body.appendChild(c)}class cr{constructor(t,e,n){if(e.length!==n.length)throw new Error("Char boxes length does not match text length");const o=t.parentNode,i=document.createElement("hypothesis-text-layer");o.insertBefore(i,t.nextSibling),o.style.position="relative",i.style.position="absolute",i.style.top="0",i.style.left="0",i.style.color="transparent",i.style.textAlign="left",i.style.mixBlendMode="multiply";const r="sans-serif";i.style.fontSize="16px",i.style.fontFamily=r;const s=document.createElement("canvas").getContext("2d");s.font=`16px ${r}`
|
|
148
|
+
;const a=(t,e,n="px")=>`calc(var(--${t}-scale) * ${e}${n})`,l=function(t,e){const n=[];let o={text:"",rect:new DOMRect};const i=()=>{o.text.length>0&&(n.push(o),o={text:"",rect:new DOMRect})};for(const[n,r]of t.entries()){const t=e[n],s=/\s/.test(t);o.text.length>0&&!qe(o.rect,r)&&i(),o.rect=je(o.rect,r),o.text+=s?" ":t,s&&i()}i();const r=[];let s={words:[],rect:new DOMRect};const a=()=>{s.words.length>0&&(r.push(s),s={words:[],rect:new DOMRect})};for(const t of n){const e=s.words[s.words.length-1];if(e){const n=Ke(e.rect),o=Ke(t.rect).x-n.x;(!qe(e.rect,t.rect)||o<0)&&a()}s.words.push(t),s.rect=je(s.rect,t.rect)}a();const l=[];let c={lines:[],rect:new DOMRect};const h=()=>{c.lines.length>0&&(l.push(c),c={lines:[],rect:new DOMRect})};for(const t of r){const e=c.lines[c.lines.length-1];if(e){const n=Ke(e.rect),o=Ke(t.rect).y-n.y;(!We(e.rect,t.rect)||qe(e.rect,t.rect)||o<0||o>4*t.rect.height)&&h()}c.lines.push(t),c.rect=je(c.rect,t.rect)}return h(),l}(e,n);for(const t of l){
|
|
149
|
+
const e=document.createElement("hypothesis-text-column");e.style.display="block",e.style.position="absolute",e.style.left=a("x",t.rect.left),e.style.top=a("y",t.rect.top);let n=null;for(const o of t.lines){const i=document.createElement("hypothesis-text-line");i.style.display="block",i.style.marginLeft=a("x",o.rect.left-t.rect.left),i.style.height=a("y",o.rect.height),n&&(i.style.marginTop=a("y",o.rect.top-n.rect.bottom)),n=o,i.style.whiteSpace="nowrap";let r=null;for(const t of o.words){const e=document.createElement("hypothesis-text-word");e.style.display="inline-block",e.style.transformOrigin="top left",e.textContent=t.text,r&&(e.style.marginLeft=a("x",t.rect.left-r.rect.right)),r=t,e.style.width=a("x",t.rect.width),e.style.height=a("y",t.rect.height),e.style.whiteSpace="pre";const n=s.measureText(t.text),o=a("x",t.rect.width/n.width,""),l=a("y",t.rect.height/16,"");e.style.transform=`scale(${o}, ${l})`,i.append(e)}e.append(i)}i.append(e)}const c=()=>{const{width:e,height:n}=t.getBoundingClientRect()
|
|
150
|
+
;i.style.width=e+"px",i.style.height=n+"px",i.style.setProperty("--x-scale",`${e}`),i.style.setProperty("--y-scale",`${n}`)};c(),this.container=i,this._updateTextLayerSize=_i(c,{maxWait:50}),this._listeners=new mt,"undefined"!=typeof ResizeObserver&&(this._imageSizeObserver=new ResizeObserver((()=>{this._updateTextLayerSize()})),this._imageSizeObserver.observe(t)),this._listeners.add(window,"resize",this._updateTextLayerSize)}updateSync(){this._updateTextLayerSize(),this._updateTextLayerSize.flush()}destroy(){this.container.remove(),this._listeners.removeAll(),this._updateTextLayerSize.cancel(),this._imageSizeObserver?.disconnect()}}function hr(t=document){return t.querySelector("mosaic-book")}function dr(t=window){if(hr(t.document))return"container";const e=t.frameElement?.ownerDocument;return e&&hr(e)?"content":null}class ur{constructor(t){const e=hr();if(!e)throw new Error("Book container element not found");const n=new WeakSet,o=e.shadowRoot,i=()=>{const e=o.querySelector("iframe")
|
|
151
|
+
;e&&!n.has(e)&&(n.add(e),sr(e,((n,o)=>{if(n)return;const i=o.body;i&&!i.querySelector("#page-content")&&lr(e,t,"vitalsource-content")})))};i(),this._frameObserver=new MutationObserver(i),this._frameObserver.observe(o,{childList:!0,subtree:!0})}destroy(){this._frameObserver.disconnect()}}function fr(){return document.querySelector("img#pbk-page")}class pr extends Me{constructor(t=document.body,e={}){super();const n=e.bookElement??hr(window.parent.document);if(!n)throw new Error("Failed to find <mosaic-book> element in container frame");this._bookElement=n;const o=new Mo;this._htmlIntegration=new ui({container:t,features:o}),this._listeners=new mt;const i=["mouseup","mousedown","mouseout"];for(const t of i)this._listeners.add(document.documentElement,t,(t=>{t.stopPropagation()}));const r=window.frameElement;r&&function(t){if("no"!==t.getAttribute("scrolling"))return;const e=document.createElement("style");e.textContent="iframe { height: 100% !important; }",t.insertAdjacentElement("beforebegin",e)
|
|
152
|
+
;const n=()=>t.removeAttribute("scrolling");n(),new MutationObserver(n).observe(t,{attributes:!0})}(r);const s=fr(),a=window.innerPageData;if(s&&a){const t=a.glyphs.glyphs.map((t=>{const e=t.l/100,n=t.r/100,o=t.t/100,i=t.b/100;return new DOMRect(e,o,n-e,i-o)}));this._textLayer=new cr(s,t,a.words),this._textLayer.container.style.zIndex="100",this._sideBySideActive=!1}}getAnnotatableRange(t){return this._htmlIntegration.getAnnotatableRange(t)}destroy(){this._textLayer&&(this._textLayer.destroy(),this.fitSideBySide({expanded:!1,height:window.innerHeight,width:0,toolbarWidth:0})),this._listeners.removeAll(),this._htmlIntegration.destroy(),super.destroy()}anchor(t,e){return this._htmlIntegration.anchor(t,e)}async describe(t,e){const n=this._htmlIntegration.describe(t,e),{cfi:o,index:i,page:r,title:s,url:a}=await this._getPageInfo({includeTitle:!0,includePageIndex:!0}),l=[{type:"EPUBContentSelector",cfi:o,url:a,title:s}];if("number"==typeof i){const t={type:"PageSelector",index:i,label:r};l.push(t)}
|
|
153
|
+
return n.push(...l),n}contentContainer(){return this._htmlIntegration.contentContainer()}fitSideBySide(t){const e=fr();if(e&&this._textLayer){const n=e.parentElement,o=this._textLayer,i=window.innerWidth-t.width;return this._sideBySideActive=!1,on((()=>{t.expanded&&i>480?(n.style.textAlign="left",e.style.width=`${i}px`,this._sideBySideActive=!0):(n.style.textAlign="",e.style.width=""),o.updateSync()})),this._sideBySideActive}return this._htmlIntegration.fitSideBySide(t)}sideBySideActive(){return"boolean"==typeof this._sideBySideActive?this._sideBySideActive:this._htmlIntegration.sideBySideActive()}supportedTools(){return["selection"]}async getMetadata(){return{title:this._bookElement.getBookInfo().title,link:[]}}navigateToSegment(t){const e=t.target[0].selector?.find((t=>"EPUBContentSelector"===t.type));if(e?.cfi)this._bookElement.goToCfi(e.cfi);else{if(!e?.url)throw new Error("No segment information available");this._bookElement.goToURL(function(t){const e=new URL(t,document.baseURI)
|
|
154
|
+
;return e.pathname+e.search}(e.url))}}persistFrame(){return!0}async _getPageInfo({includeTitle:t=!1,includePageIndex:e=!1}={}){const[n,o,i]=await Promise.all([this._bookElement.getCurrentPage(),t?this._bookElement.getTOC():void 0,e?this._bookElement.getPages():void 0]),r=["absoluteURL","cfi"];for(const t of r)if(!(t in n))throw new Error(`Page metadata field "${t}" is missing`);let s;if(o){s=n.chapterTitle;const t=or(n.cfi),e=o.data?.find((e=>or(e.cfi)===t));e&&(s=e.title)}let a=n.index;if(void 0===a&&i){const t=i.data?.findIndex((t=>t.cfi===n.cfi));-1!==t&&(a=t)}return{cfi:n.cfi,index:a,page:n.page,title:s,url:new URL(n.absoluteURL,document.baseURI).toString()}}async _getPageRange(t){let e=[];try{const t=await this._bookElement.getPageBreaks();t.ok&&t.data&&(e=t.data)}catch(t){console.error("Failed to get page breaks",t)}const n=nr(t),o=e.filter((t=>t.cfiWithoutAssertions.split("!")[0]===n));let i;if(o.length>0){i={start:o[0].label,end:o[o.length-1].label}}return i}async segmentInfo(){
|
|
155
|
+
const{cfi:t,url:e}=await this._getPageInfo();return{cfi:t,pages:await this._getPageRange(t),url:e}}async uri(){const t=this._bookElement.getBookInfo().isbn;if(!t)throw new Error("Unable to get book ID from VitalSource");return`https://bookshelf.vitalsource.com/reader/books/${t}`}async scrollToAnchor(t){return this._htmlIntegration.scrollToAnchor(t)}}function gr(t){if(void 0!==window.PDFViewerApplication)return new er({annotator:t,features:t.features});return"content"===dr()?new pr(document.body):new ui({features:t.features,sideBySideOptions:t.sideBySide})}function _r(){return St(_e,{classes:"fixed left-[10px] top-[10px]","data-testid":"outside-assignment-notice",status:"notice",variant:"raised",children:"You are outside the page range for this assignment. Annotations made here may not be counted."})}class mr{constructor(t){this._visible=!1,this._container=new Pn("notice",(()=>this._render())),t.appendChild(this._container.element)}destroy(){this._container.destroy()}setVisible(t){this._visible=t,
|
|
156
|
+
this._container.render()}_render(){return this._visible?St(_r,{}):null}}class br{constructor(t,e=document){let n=!1;this._pendingCallback=null;const o=(n=10)=>{this._pendingCallback=setTimeout((()=>{t(jn(e.getSelection()))}),n)},i=t=>{if("mousedown"===t.type&&(n=!0),"mouseup"===t.type&&(n=!1),n)return;this._cancelPendingCallback();const e="mouseup"===t.type?10:100;o(e)};this._document=e,this._listeners=new mt,this._listeners.add(e,"selectionchange",i),this._listeners.add(e.body,"mousedown",i),this._listeners.add(e.body,"mouseup",i),o(1)}disconnect(){this._listeners.removeAll(),this._cancelPendingCallback()}_cancelPendingCallback(){this._pendingCallback&&(clearTimeout(this._pendingCallback),this._pendingCallback=null)}}function yr(t,e){if(t===e)return!0;if(t.parent!==e)return!1;if(!t.frameElement)return!1;return t.frameElement.getBoundingClientRect().width/t.parent.innerWidth>=.8}function wr(){return function(t,e){const n=new Set,o=new Set;return Yn(t,(t=>{for(;t&&!n.has(t);){n.add(t);const i=e(t)
|
|
157
|
+
;null!=i&&o.add(i),t=t.parentNode}})),[...o]}(jn()??new Range,(t=>t._annotation?.$tag))}function vr(t,e,n){return t.getHighlightsFromPoint(e,n).map((t=>t._annotation?.$tag)).filter((t=>void 0!==t))}function xr(t){if(!t.region)return null;if(!function(t){return void 0!==t&&"toRange"in t&&"function"==typeof t.toRange}(t.region))return t.region;try{return t.region.toRange()}catch{return null}}function Cr(){document.getSelection()?.removeAllRanges()}class Sr extends CustomEvent{constructor(t){super("scrolltorange",{bubbles:!0,cancelable:!0,detail:t}),this._ready=null}get ready(){return this._ready}waitUntil(t){this._ready=t}}class Ar extends Me{constructor(t,e={},n=window){super(),this.element=t,this._contentReady=e.contentReady,this._commentsMode=e.commentsMode??!1,this._hostFrame=n,this._highlightsVisible=!1,this._isAdderVisible=!1,this._informHostOnNextSelectionClear=!0,this.selectedRanges=[],this._outsideAssignmentNotice=null,this._highlighter=new Zn(this.element),this._adder=new Ln(this.element,{
|
|
158
|
+
onAnnotate:()=>this.createAnnotationFromSelection(),onHighlight:()=>this.createAnnotationFromSelection({highlight:!0}),onShowAnnotations:t=>this.selectAnnotations(t,{focusInSidebar:!0})}),this._drawTool=new xo(this.element),this._drawTool.setOnKeyboardModeChange((t=>{this._hostRPC.call("keyboardModeChanged",t)})),this._setupGlobalKeyboardListener(),this._selectionObserver=new br((t=>{t?this._onSelection(t):this._onClearSelection()})),this.anchors=[],this._annotations=new Set,this._frameIdentifier=e.subFrameIdentifier||null,this._portFinder=new ke({hostFrame:this._hostFrame,source:"guest",sourceId:this._frameIdentifier??void 0}),this.features=new Mo,this._featureFlagsReceived=new Promise((t=>{this.features.on("flagsChanged",t)})),this.sideBySide=e.sideBySide,this._integration=gr(this),this._integration.on("uriChanged",(()=>this._sendDocumentInfo())),e.contentInfoBanner&&this._integration.showContentInfo?.(e.contentInfoBanner),
|
|
159
|
+
this._integration.canStyleClusteredHighlights?.()&&(this._clusterToolbar=new No(this._integration.contentContainer(),{features:this.features})),this._integration.on("supportedToolsChanged",(()=>this._notifySupportedToolsChanged())),this._hostRPC=new De,this._connectHost(n),this._sidebarRPC=new De,this._sidebarLayout=null,this._connectSidebar(),this._bucketBarClient=new ho({contentContainer:this._integration.contentContainer(),hostRPC:this._hostRPC}),this._listeners=new mt,this._setupElementEvents(),this._hoveredAnnotations=new Set}_sideBySideActive(){return"manual"===this.sideBySide?.mode&&this.sideBySide.isActive?this.sideBySide.isActive():this._integration.sideBySideActive()}_setupElementEvents(){this._listeners.add(this.element,"mouseup",(t=>{if(!document.getSelection()?.isCollapsed)return;const{clientX:e,clientY:n,metaKey:o,ctrlKey:i}=t,r=vr(this._highlighter,e,n);if(r.length){const t=o||i;this.selectAnnotations(r,{toggle:t})}})),this._listeners.add(this.element,"pointerdown",(t=>{
|
|
160
|
+
this._sideBySideActive()||t.composedPath().some((t=>t instanceof Element&&t.localName.startsWith("hypothesis-")))||vr(this._highlighter,t.clientX,t.clientY).length||yr(window,this._hostFrame)&&this._sidebarLayout?.expanded&&window.innerWidth-t.clientX<this._sidebarLayout.width||this._sidebarRPC.call("closeSidebar")})),this._listeners.add(this.element,"mouseover",(({clientX:t,clientY:e})=>{const n=vr(this._highlighter,t,e);n.length&&this._sidebarRPC.call("hoverAnnotations",n)})),this._listeners.add(this.element,"mouseout",(()=>{this._highlightsVisible&&this._sidebarRPC.call("hoverAnnotations",[])})),this._listeners.add(this.element,"keydown",(t=>{this._handleShortcut(t)})),this._listeners.add(window,"resize",(()=>this._repositionAdder()))}async getDocumentInfo(){const[t,e,n]=await Promise.all([this._integration.uri(),this._integration.getMetadata(),this._integration.segmentInfo?.()]);return{uri:hi(t),metadata:e,segmentInfo:n,persistent:this._integration.persistFrame?.()??!1}}async _sendDocumentInfo(){
|
|
161
|
+
this._integration.waitForFeatureFlags?.()&&await this._featureFlagsReceived;const t=await this.getDocumentInfo();this._sidebarRPC.call("documentInfoChanged",t)}_repositionAdder(){if(!this._isAdderVisible)return;const t=jn();t&&this._onSelection(t)}async _connectHost(t){this._hostRPC.on("clearSelection",(()=>{jn()&&(this._informHostOnNextSelectionClear=!1,Cr())})),this._hostRPC.on("createAnnotation",(({tool:t})=>t?("rect"===t&&void 0===this._pendingKeyboardMode&&(this._pendingKeyboardMode="move"),this.createAnnotation(t)):(this._drawTool.cancel(),null))),this._hostRPC.on("hoverAnnotations",(t=>this._hoverAnnotations(t))),this._hostRPC.on("scrollToAnnotation",(t=>{this._scrollToAnnotation(t)})),this._hostRPC.on("selectAnnotations",((t,e)=>this.selectAnnotations(t,{toggle:e}))),this._hostRPC.on("setKeyboardMode",(({mode:t})=>{["move","resize","rect"].includes(t)&&this._drawTool.setKeyboardMode(t)})),this._hostRPC.on("activateMoveMode",(()=>{this._activateToolWithMoveMode("rect")})),
|
|
162
|
+
this._hostRPC.on("activatePointMoveMode",(()=>{this._activateToolWithMoveMode("point")})),this._hostRPC.on("sidebarLayoutChanged",(e=>{yr(window,t)&&this.fitSideBySide(e),this.element.dispatchEvent(new Co({sidebarLayout:e,sideBySideActive:this._sideBySideActive()}))})),this._hostRPC.on("close",(()=>this.emit("hostDisconnected"))),this._notifySupportedToolsChanged();const e=await this._portFinder.discover("host");this._hostRPC.connect(e)}_notifySupportedToolsChanged(){this._hostRPC.call("supportedToolsChanged",this._integration.supportedTools())}async _scrollToAnchor(t){const e=xr(t);if(!e)return;let n;e instanceof Range?n=e:(n=new Range,n.selectNodeContents(e.anchor));const o=new Sr(n);this.element.dispatchEvent(o)&&(await o.ready,await this._integration.scrollToAnchor(t))}async _scrollToAnnotation(t){const e=this.anchors.find((e=>e.annotation.$tag===t));e?.highlights&&await this._scrollToAnchor(e)}async _connectSidebar(){this._sidebarRPC.on("featureFlagsUpdated",(t=>this.features.update(t))),
|
|
163
|
+
this._sidebarRPC.on("shortcutsUpdated",(t=>{wn(t)})),this._sidebarRPC.on("hoverAnnotations",(t=>this._hoverAnnotations(t))),this._sidebarRPC.on("scrollToAnnotation",(t=>{this._scrollToAnnotation(t)})),this._sidebarRPC.on("setHighlightsVisible",(t=>{this.setHighlightsVisible(t,!1)})),this._sidebarRPC.on("deleteAnnotation",(t=>this.detach(t))),this._sidebarRPC.on("getDocumentInfo",(async t=>t(await this.getDocumentInfo()))),this._sidebarRPC.on("loadAnnotations",(async t=>{try{await Promise.all(t.map((t=>this.anchor(t))))}catch(t){console.warn("Failed to anchor annotations:",t)}})),this._sidebarRPC.on("showContentInfo",(t=>this._integration.showContentInfo?.(t))),this._sidebarRPC.on("setOutsideAssignmentNoticeVisible",(t=>{this._setOutsideAssignmentNoticeVisible(t)})),this._sidebarRPC.on("navigateToSegment",(t=>this._integration.navigateToSegment?.(t))),this._sidebarRPC.on("renderThumbnail",((t,e,n)=>{(async()=>{
|
|
164
|
+
if(!this._integration.renderToBitmap)throw new Error("Thumbnail rendering not supported for document type");const n=this.anchors.find((e=>e.annotation.$tag===t));if(!n)throw new Error("Annotation not anchored in guest");return this._integration.renderToBitmap(n,e)})().then((t=>n({ok:!0,value:t}))).catch((t=>n({ok:!1,error:t.message})))})),this._portFinder.discover("sidebar").then((t=>{this._sidebarRPC.connect(t)})),this._sendDocumentInfo()}destroy(){this._drawTool.destroy(),this._portFinder.destroy(),this._hostRPC.destroy(),this._sidebarRPC.destroy(),this._listeners.removeAll(),this._selectionObserver.disconnect(),this._adder.destroy(),this._bucketBarClient.destroy(),this._clusterToolbar?.destroy(),this._outsideAssignmentNotice?.destroy(),this._highlighter.removeAllHighlights(),this._integration.destroy(),this._globalKeyboardListenerCleanup?.(),super.destroy()}_isKeyboardAnnotationModeEnabled(){return this.features.flagEnabled("vpat_keyboard")}_setupGlobalKeyboardListener(){const t=t=>{if(Ge(t.target))return
|
|
165
|
+
;if(!this._isKeyboardAnnotationModeEnabled())return;const e=yn(),n=this._integration.supportedTools(),o=n.includes("rect"),i=n.includes("point"),r=e.activateRectMove;if(r&&un(t,r)&&o){t.preventDefault(),t.stopPropagation();return void(this._drawTool.getKeyboardModeState().keyboardActive?this._drawTool.setKeyboardMode("move"):(this._pendingKeyboardMode="move",this.createAnnotation("rect").catch((()=>{this._pendingKeyboardMode=void 0}))))}const s=e.activateRectResize;if(s&&un(t,s)&&o){t.preventDefault(),t.stopPropagation();return void(this._drawTool.getKeyboardModeState().keyboardActive?this._drawTool.setKeyboardMode("resize"):(this._pendingKeyboardMode="resize",this.createAnnotation("rect").catch((()=>{this._pendingKeyboardMode=void 0}))))}const a=e.activatePoint;if(a&&un(t,a)&&i){t.preventDefault(),t.stopPropagation();this._drawTool.getKeyboardModeState().keyboardActive||(this._pendingKeyboardMode="move",this.createAnnotation("point").catch((()=>{this._pendingKeyboardMode=void 0})))}else;}
|
|
166
|
+
;document.body.addEventListener("keydown",t),this._globalKeyboardListenerCleanup=()=>{document.body.removeEventListener("keydown",t)}}async anchor(t){this._contentReady&&(await this._contentReady,this._contentReady=void 0);const e=t=>{const e=xr(t);if(!e)return;let n;n=e instanceof Range?this._highlighter.highlightRange(e,t.annotation?.$cluster):this._highlighter.highlightShape(e),n.forEach((e=>{e._annotation=t.annotation})),t.highlights=n,this._hoveredAnnotations.has(t.annotation.$tag)&&this._highlighter.setHighlightsFocused(n,!0)};this.detach(t.$tag,!1),this._annotations.add(t.$tag),t.target||(t.target=[]);const n=await Promise.all(t.target.map((async e=>{if(!e.selector||!e.selector.some((t=>"TextQuoteSelector"===t.type||"ShapeSelector"===t.type)))return{annotation:t,target:e};let n;try{const o=await this._integration.anchor(this.element,e.selector);if(o instanceof Range){const i=Un.fromRange(o);n={annotation:t,target:e,region:i}}else n={annotation:t,target:e,region:o}}catch{n={annotation:t,target:e}}
|
|
167
|
+
return n})));if(!this._annotations.has(t.$tag))return[];for(const t of n)e(t);return t.$orphan=n.length>0&&n.every((t=>t.target.selector&&!t.region)),this._updateAnchors(this.anchors.concat(n),!0),this._sidebarRPC.call("syncAnchoringStatus",t),n}detach(t,e=!0){this._annotations.delete(t);const n=[];for(const e of this.anchors)e.annotation.$tag!==t?n.push(e):e.highlights&&this._highlighter.removeHighlights(e.highlights);this._updateAnchors(n,e)}_updateAnchors(t,e){this.anchors=t,this._clusterToolbar?.scheduleClusterUpdates(),e&&this._bucketBarClient.update(this.anchors)}async createAnnotation(t){if("selection"===t)return this.createAnnotationFromSelection();if(!["rect","point"].includes(t))throw new Error("Unsupported annotation tool");{let e=!1;try{this._hostRPC.call("activeToolChanged",t);const e=this._pendingKeyboardMode;this._pendingKeyboardMode=void 0;const n=await this._drawTool.draw(t,e),o=await this.getDocumentInfo(),i=[{source:o.uri,selector:await this._integration.describe(this.element,n)}],r={
|
|
168
|
+
uri:o.uri,document:o.metadata,target:i,$tag:"a:"+Ce(8)};return this._sidebarRPC.call("createAnnotation",r),this.anchor(r),r}catch(t){if(t instanceof vo&&["canceled","restarted"].includes(t.kind))return e="restarted"===t.kind,null;throw t}finally{e||this._hostRPC.call("activeToolChanged",null)}}}_activateToolWithMoveMode(t){this._drawTool.getKeyboardModeState().keyboardActive?this._drawTool.setKeyboardMode("move"):(this._pendingKeyboardMode="move",this.createAnnotation(t).catch((()=>{this._pendingKeyboardMode=void 0})))}async createAnnotationFromSelection({highlight:t=!1}={}){const e=this.selectedRanges;this.selectedRanges=[];const n=await this.getDocumentInfo(),o=this.element,i=(await Promise.all(e.map((t=>this._integration.describe(o,t))))).map((t=>({source:n.uri,selector:t}))),r={uri:n.uri,document:n.metadata,target:i,$highlight:t,$cluster:t?"user-highlights":"user-annotations",$tag:"a:"+Ce(8)};return this._sidebarRPC.call("createAnnotation",r),this.anchor(r),Cr(),r}_hoverAnnotations(t){
|
|
169
|
+
this._hoveredAnnotations.clear(),t.forEach((t=>this._hoveredAnnotations.add(t)));for(const e of this.anchors)if(e.highlights){const n=t.includes(e.annotation.$tag);this._highlighter.setHighlightsFocused(e.highlights,n)}this._sidebarRPC.call("hoverAnnotations",t)}_onSelection(t){const e=this._integration.getAnnotatableRange(t);if(!e)return void this._onClearSelection();const n=document.getSelection(),o=Kn(n),i=Gn(n);i?(this.selectedRanges=[e],this._hostRPC.call("textSelected"),this._commentsMode||(this._adder.annotationsForSelection=wr(),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(t,{toggle:e=!1,focusInSidebar:n=!1}={}){e?this._sidebarRPC.call("toggleAnnotationSelection",t):this._sidebarRPC.call("showAnnotations",t,n),this._sidebarRPC.call("openSidebar")}
|
|
170
|
+
setHighlightsVisible(t,e=!0){this._highlighter.setHighlightsVisible(t),this._highlightsVisible=t,e&&this._hostRPC.call("highlightsVisibleChanged",t)}get highlightsVisible(){return this._highlightsVisible}fitSideBySide(t){this._sidebarLayout=t,this._integration.fitSideBySide(t)}get hoveredAnnotationTags(){return this._hoveredAnnotations}_handleShortcut(t){const e=yn().toggleHighlights;e&&un(t,e)&&this.setHighlightsVisible(!this._highlightsVisible&&!this._commentsMode)}_setOutsideAssignmentNoticeVisible(t){this._outsideAssignmentNotice||(this._outsideAssignmentNotice=new mr(this.element)),this._outsideAssignmentNotice.setVisible(t)}}function kr(t,e){const n=new URL(t),o=new URLSearchParams;return o.append("config",JSON.stringify(e)),n.hash=o.toString(),n.toString()}function Mr(t,e){const n={};for(const[t,o]of Object.entries(e))"notebookAppUrl"!==t&&"sidebarAppUrl"!==t&&null!=o&&(n[t]=o);n.origin=new URL(t).origin,n.version="1.1760.0";const o=new URL(window.location.href);if(o.hash="",n.hostURL=o.toString(),
|
|
171
|
+
Array.isArray(n.services)&&n.services?.length>0){const t=n.services[0];t.onLoginRequest&&(t.onLoginRequestProvided=!0),t.onLogoutRequest&&(t.onLogoutRequestProvided=!0),t.onSignupRequest&&(t.onSignupRequestProvided=!0),t.onProfileRequest&&(t.onProfileRequestProvided=!0),t.onHelpRequest&&(t.onHelpRequestProvided=!0)}return n}function Rr({closed:t,onClose:e,children:n,className:o,"data-testid":i,"aria-label":r}){const s=it(null);return nt((()=>{t?s.current?.close():s.current?.showModal()}),[t]),nt((()=>{const t=s.current;return t?.addEventListener("cancel",e),()=>{t?.removeEventListener("cancel",e)}}),[e]),St("dialog",{ref:s,className:Tt("relative m-5 w-full h-full backdrop:bg-black/50",o),"data-testid":i,"aria-label":r,children:n})}function Er({closed:t,children:e,className:n,...o}){return St("div",{...o,className:Tt("fixed z-max top-0 left-0 right-0 bottom-0 p-3 bg-black/50",{hidden:t}),children:St("div",{className:Tt("relative w-full h-full",n),children:e})})}function Pr({document_:t=document,...e}){
|
|
172
|
+
return St(rt((()=>function(t){return"function"==typeof t.createElement("dialog").showModal}(t)?Rr:Er),[t]),{...e})}function Tr({config:t,groupId:e}){return St("iframe",{title:"Hypothesis annotation notebook",className:"h-full w-full border-0",allow:"fullscreen; clipboard-write",src:kr(t.notebookAppUrl,{...Mr(t.notebookAppUrl,t),group:e})})}function Nr({eventBus:t,config:e}){const[n,o]=et(0),[i,r]=et(!0),[s,a]=et(null),l=it(""),c=it(null);nt((()=>(l.current=document.body.style.overflow,()=>{document.body.style.overflow=l.current})),[]),nt((()=>{document.body.style.overflow=i?l.current:"hidden"}),[i]),nt((()=>{const e=t.createEmitter();return e.subscribe("openNotebook",(t=>{r(!1),o((t=>t+1)),a(t)})),c.current=e,()=>{e.destroy()}}),[t]);const h=st((()=>{r(!0),c.current?.publish("closeNotebook")}),[]);return null===s?null:St(Pr,{closed:i,onClose:h,"data-testid":"notebook-outer","aria-label":"Hypothesis notebook",children:[St("div",{className:"absolute right-0 m-3",children:St(oe,{title:"Close notebook",onClick:h,
|
|
173
|
+
variant:"dark",classes:Tt("!bg-transparent enabled:hover:!bg-grey-3"),"data-testid":"close-button",children:St(It,{className:"w-4 h-4"})})}),St(Tr,{config:e,groupId:s},n)]})}class Lr{constructor(t,e,n){this._container=new Pn("notebook",(()=>St(Nr,{eventBus:e,config:n}))),t.append(this._container.element),this._container.render()}destroy(){this._container.destroy()}}function Or({eventBus:t,config:e}){const[n,o]=et(!0),i=it(null);nt((()=>{const e=t.createEmitter();return e.subscribe("openProfile",(()=>{o(!1)})),i.current=e,()=>{e.destroy()}}),[t]);const r=()=>{o(!0),i.current?.publish("closeProfile")};return n?null:St(Pr,{closed:n,onClose:r,"data-testid":"profile-outer","aria-label":"Hypothesis profile",children:[St("div",{className:"absolute right-0 m-3",children:St(oe,{title:"Close profile dialog",onClick:r,variant:"dark",classes:Tt("!bg-transparent enabled:hover:!bg-grey-3"),children:St(It,{className:"w-4 h-4"})})}),St("iframe",{title:"Hypothesis profile",className:"h-full w-full border-0",
|
|
174
|
+
src:e.profileAppUrl})]})}class Ir{constructor(t,e,n){this._container=new Pn("profile",(()=>St(Or,{eventBus:e,config:n}))),t.append(this._container.element),this._container.render()}destroy(){this._container.destroy()}}function Br({above:t,below:e,buckets:n,onFocusAnnotations:o,onScrollToAnnotation:i,onSelectAnnotations:r}){const s=t.anchors.length>0,a=e.anchors.length>0,l=t=>t.anchors.map((t=>t.tag));return St("ul",{className:"relative",children:[s&&St("li",{className:"absolute right-0 pointer-events-auto mt-[-11px]",style:{top:t.position},children:St(ve,{"data-testid":"up-navigation-button",direction:"up",onClick:()=>{const e=[...t.anchors].sort(((t,e)=>t.bottom-e.bottom)),n=e[e.length-1];i(n.tag)},onBlur:()=>o([]),onFocus:()=>o(l(t)),onMouseEnter:()=>o(l(t)),onMouseOut:()=>o([]),title:`Go up to next annotations (${t.anchors.length})`,children:t.anchors.length})}),n.map(((t,e)=>St("li",{className:"absolute right-0 pointer-events-auto mt-[-8px]",style:{top:t.position},children:St(ve,{direction:"left",
|
|
175
|
+
onClick:e=>r(l(t),e.metaKey||e.ctrlKey),onBlur:()=>o([]),onFocus:()=>o(l(t)),onMouseEnter:()=>o(l(t)),onMouseOut:()=>o([]),title:`Select nearby annotations (${t.anchors.length})`,children:t.anchors.length})},e))),a&&St("li",{className:"absolute right-0 pointer-events-auto",style:{top:e.position},children:St(ve,{"data-testid":"down-navigation-button",direction:"down",onClick:()=>{const t=[...e.anchors].sort(((t,e)=>t.top-e.top)),n=t[0];i(n.tag)},onBlur:()=>o([]),onFocus:()=>o(l(e)),onMouseEnter:()=>o(l(e)),onMouseOut:()=>o([]),title:`Go up to next annotations (${e.anchors.length})`,children:e.anchors.length})})]})}class Dr{constructor(t,{onFocusAnnotations:e,onScrollToAnnotation:n,onSelectAnnotations:o}){this._positions=[],this._container=new Pn("bucket-bar",(()=>this._render())),Object.assign(this._container.element.style,{display:"block",flexGrow:"1",width:"100%"}),t.appendChild(this._container.element),this._onFocusAnnotations=e,this._onScrollToAnnotation=n,this._onSelectAnnotations=o,
|
|
176
|
+
this._container.render()}destroy(){this._container.destroy()}update(t){this._positions=t,this._container.render()}_render(){const t=function(t,e){const n=[],o=[],i=[];let r=null;function s(t){const{bottom:e,top:n}=t;return{bottom:e,position:n+(e-n)/2,anchors:[t],top:n}}const a=e.getBoundingClientRect(),l=t.map((t=>({tag:t.tag,top:t.top-a.top,bottom:t.bottom-a.top})));for(const t of l){const e=(t.top+t.bottom)/2;if(e<30){n.push(t);continue}if(e>a.height-30){o.push(t);continue}if(!r){r=s(t);continue}const l=t.top>r.top&&t.bottom<r.bottom;if(t.top-r.bottom>60&&!l)i.push(r),r=s(t);else{const e=t.bottom>r.bottom?t.bottom:r.bottom,n=e-r.top;r.anchors.push(t),r.bottom=e,r.position=r.top+n/2}}return r&&i.push(r),{above:{anchors:n,position:25},below:{anchors:o,position:a.height-30},buckets:i}}(this._positions,this._container.element);return St(Br,{above:t.above,below:t.below,buckets:t.buckets,onFocusAnnotations:t=>this._onFocusAnnotations(t),onScrollToAnnotation:t=>this._onScrollToAnnotation(t),
|
|
177
|
+
onSelectAnnotations:(t,e)=>this._onSelectAnnotations(t,e)})}}function Fr({emitter:t}){const[e,n]=et([]),o=st((t=>n((e=>[...e,t]))),[]),i=st((t=>n((e=>e.filter((e=>e.id!==t))))),[]);return nt((()=>(t.subscribe("toastMessageAdded",o),t.subscribe("toastMessageDismissed",i),()=>{t.unsubscribe("toastMessageAdded",o),t.unsubscribe("toastMessageDismissed",i)})),[t,i,o]),St(ye,{messages:e,onMessageDismiss:i})}function Hr(t){return St("svg",{xmlns:"http://www.w3.org/2000/svg",width:"16",height:"16",viewBox:"0 0 16 16","aria-hidden":"true",...t,children:[St("g",{"fill-rule":"evenodd",children:[St("path",{fill:"none",d:"M0 0h16v16H0z"}),St("path",{fill:"currentColor","clip-rule":"evenodd",
|
|
177
178
|
d:"M2.5 0h-1A1.5 1.5 0 0 0 0 1.5v1 a1.5 1.5 0 0 0 1 1.415v8.17 A1.5 1.5 0 0 0 0 13.5v1 A1.5 1.5 0 0 0 1.5 16h1 a1.5 1.5 0 0 0 1.415-1h8.17 a1.5 1.5 0 0 0 1.415 1h1 a1.5 1.5 0 0 0 1.5-1.5v-1 a1.5 1.5 0 0 0-1-1.415v-8.17 A1.5 1.5 0 0 0 16 2.5v-1 A1.5 1.5 0 0 0 14.5 0h-1 a1.5 1.5 0 0 0-1.415 1h-8.17 A1.5 1.5 0 0 0 2.5 0 m9.585 13 c.151-.426.489-.764.915-.915v-8.17 A1.5 1.5 0 0 1 12.085 3h-8.17 c-.151.426-.489.764-.915.915v8.17 c.426.151.764.489.915.915z M1 1.5 a.5.5 0 0 1 .5-.5h1 a.5.5 0 0 1 .5.5v1 a.5.5 0 0 1-.5.5h-1 a.5.5 0 0 1-.5-.5z M1.5 13 a.5.5 0 0 0-.5.5v1 a.5.5 0 0 0 .5.5h1 a.5.5 0 0 0 .5-.5v-1 a.5.5 0 0 0-.5-.5z M13 1.5 a.5.5 0 0 1 .5-.5h1 a.5.5 0 0 1 .5.5v1 a.5.5 0 0 1-.5.5h-1 a.5.5 0 0 1-.5-.5z m.5 11.5 a.5.5 0 0 0-.5.5v1 a.5.5 0 0 0 .5.5h1 a.5.5 0 0 0 .5-.5v-1 a.5.5 0 0 0-.5-.5z"})]}),St("g",{transform:"translate(3 3) scale(0.0833)",stroke:"currentColor","stroke-width":"10","stroke-linecap":"round","stroke-linejoin":"round",fill:"none",children:[St("path",{d:"M60 15 L60 48"}),St("path",{
|
|
178
|
-
d:"M45 30 L60 15 L75 30"}),St("path",{d:"M60 72 L60 105"}),St("path",{d:"M45 90 L60 105 L75 90"}),St("path",{d:"M15 60 L48 60"}),St("path",{d:"M30 45 L15 60 L30 75"}),St("path",{d:"M72 60 L105 60"}),St("path",{d:"M90 45 L105 60 L90 75"})]})]})}function
|
|
179
|
+
d:"M45 30 L60 15 L75 30"}),St("path",{d:"M60 72 L60 105"}),St("path",{d:"M45 90 L60 105 L75 90"}),St("path",{d:"M15 60 L48 60"}),St("path",{d:"M30 45 L15 60 L30 75"}),St("path",{d:"M72 60 L105 60"}),St("path",{d:"M90 45 L105 60 L90 75"})]})]})}function Vr(t){return St("svg",{xmlns:"http://www.w3.org/2000/svg",width:"16",height:"16",viewBox:"0 0 16 16","aria-hidden":"true",...t,children:[St("g",{"fill-rule":"evenodd",children:[St("path",{fill:"none",d:"M0 0h16v16H0z"}),St("path",{fill:"currentColor","clip-rule":"evenodd",
|
|
179
180
|
d:"M2.5 0h-1A1.5 1.5 0 0 0 0 1.5v1 a1.5 1.5 0 0 0 1 1.415v8.17 A1.5 1.5 0 0 0 0 13.5v1 A1.5 1.5 0 0 0 1.5 16h1 a1.5 1.5 0 0 0 1.415-1h8.17 a1.5 1.5 0 0 0 1.415 1h1 a1.5 1.5 0 0 0 1.5-1.5v-1 a1.5 1.5 0 0 0-1-1.415v-8.17 A1.5 1.5 0 0 0 16 2.5v-1 A1.5 1.5 0 0 0 14.5 0h-1 a1.5 1.5 0 0 0-1.415 1h-8.17 A1.5 1.5 0 0 0 2.5 0 m9.585 13 c.151-.426.489-.764.915-.915v-8.17 A1.5 1.5 0 0 1 12.085 3h-8.17 c-.151.426-.489.764-.915.915v8.17 c.426.151.764.489.915.915z M1 1.5 a.5.5 0 0 1 .5-.5h1 a.5.5 0 0 1 .5.5v1 a.5.5 0 0 1-.5.5h-1 a.5.5 0 0 1-.5-.5z M1.5 13 a.5.5 0 0 0-.5.5v1 a.5.5 0 0 0 .5.5h1 a.5.5 0 0 0 .5-.5v-1 a.5.5 0 0 0-.5-.5z M13 1.5 a.5.5 0 0 1 .5-.5h1 a.5.5 0 0 1 .5.5v1 a.5.5 0 0 1-.5.5h-1 a.5.5 0 0 1-.5-.5z m.5 11.5 a.5.5 0 0 0-.5.5v1 a.5.5 0 0 0 .5.5h1 a.5.5 0 0 0 .5-.5v-1 a.5.5 0 0 0-.5-.5z"})]}),St("g",{transform:"translate(3 3) scale(0.0833)",stroke:"currentColor","stroke-width":"18","stroke-linecap":"round","stroke-linejoin":"round",fill:"none",children:[St("path",{d:"M30 30 L55 55"}),St("path",{
|
|
180
|
-
d:"M65 65 L90 90"}),St("path",{d:"M30 45 L30 30 L45 30"}),St("path",{d:"M75 90 L90 90 L90 75"})]})]})}function
|
|
181
|
-
function
|
|
182
|
-
title:"Annotation sidebar",expanded:o,"aria-controls":i,onClick:c,unstyled:!0,children:St(o?Ft:Dt,{})}),St("div",{className:"space-y-[6px] mt-[8px]",children:[St(
|
|
181
|
+
d:"M65 65 L90 90"}),St("path",{d:"M30 45 L30 30 L45 30"}),St("path",{d:"M75 90 L90 90 L90 75"})]})]})}function zr(t,e,n){return t&&"rect"===e?"move"===n?"Move mode (Ctrl+Shift+Y) - Click to switch to Resize mode":"resize"===n?"Resize mode (Ctrl+Shift+J) - Click to switch to Rectangle mode":"Rectangle mode - Click to switch to Move mode":"Rectangle annotation"}function Ur(t,e){return n=>{"Enter"===n.key&&t&&!e&&(n.preventDefault(),n.stopPropagation(),t())}}function $r({mode:t}){return St("move"===t?Hr:"resize"===t?Vr:Zt,{})}function qr({icon:t,pressedBackground:e=!0,...n}){return St(ee,{classes:Tt("justify-center rounded","w-[30px] h-[30px] touch:h-[40px]","shadow border bg-white text-grey-6 hover:text-grey-9",e&&"aria-pressed:bg-grey-3"),...n,size:"custom",variant:"custom",children:St(t,{})})}function Wr({highlightsVisible:t}){return St("div",{className:"sr-only",role:"status","data-testid":"toolbar-status",children:t?"Highlights visible":"Highlights hidden"})}
|
|
182
|
+
function jr({activeTool:t=null,closeSidebar:e,createAnnotation:n,isSidebarOpen:o,sidebarContainerId:i,newAnnotationType:r,showHighlights:s,supportedTools:a=["selection"],toggleHighlights:l,toggleSidebar:c,toggleSidebarRef:h,useMinimalControls:d=!1,keyboardMode:u=null,keyboardActive:f=!1,onModeClick:p,onActivateMoveMode:g,onActivatePointMoveMode:_}){return St("div",{className:Tt({"absolute right-full":d,"relative right-[11px]":!d},"w-[33px] z-2","text-px-base leading-none"),children:[d&&o&&St(ee,{classes:Tt("transition-colors focus-visible-ring ring-inset","w-[27px] h-[27px] mt-[140px] ml-[6px]","flex items-center justify-center bg-white border","text-grey-6 hover:text-grey-9 transition-colors","border-r-0","shadow-sidebar"),title:"Close annotation sidebar",onClick:e,unstyled:!0,children:St(It,{})}),!d&&St(y,{children:[St(ee,{classes:Tt("transition-colors focus-visible-ring ring-inset","h-[40px] w-[33px] pl-[6px] rounded-bl","bg-white text-grey-6 hover:text-grey-9","border-l border-b"),elementRef:h,
|
|
183
|
+
title:"Annotation sidebar",expanded:o,"aria-controls":i,onClick:c,unstyled:!0,children:St(o?Ft:Dt,{})}),St("div",{className:"space-y-[6px] mt-[8px]",children:[St(qr,{title:"Show highlights",icon:s?te:$t,pressed:s,pressedBackground:!1,onClick:l}),a.includes("selection")&&St(qr,{"data-testid":"text-annotation",title:"note"===r?"New page note":"New annotation",icon:"note"===r?Kt:Ot,onClick:()=>n("selection")}),a.includes("rect")&&St(qr,{"data-testid":"rect-annotation",pressed:"rect"===t,title:zr(f,t,u??null),icon:f&&"rect"===t?()=>St($r,{mode:u??"rect"}):Zt,onClick:()=>{f&&"rect"===t?p?.():n("rect"===t?null:"rect")},onKeyDown:Ur(g,f)}),a.includes("point")&&St(qr,{"data-testid":"point-annotation",pressed:"point"===t,title:"Pin annotation",icon:Xt,onClick:()=>n("point"===t?null:"point"),onKeyDown:Ur(_,f)})]}),St(Wr,{highlightsVisible:s})]})]})}class Kr{constructor(t,e){const{createAnnotation:n,setSidebarOpen:o,setHighlightsVisible:i}=e;this.container=t,this._activeTool=null,this._useMinimalControls=!1,
|
|
183
184
|
this._newAnnotationType="note",this._highlightsVisible=!1,this._sidebarOpen=!1,this._sidebarContainerId=e.sidebarContainerId,this._supportedAnnotationTools=["selection"],this._keyboardMode=null,this._keyboardActive=!1,this._closeSidebar=()=>o(!1),this._toggleSidebar=()=>o(!this._sidebarOpen),this._toggleHighlights=()=>i(!this._highlightsVisible),this._createAnnotation=t=>{n(t),"selection"===t&&o(!0)},this._sidebarToggleButton={current:null},this.render()}getWidth(){return this.container.firstChild.getBoundingClientRect().width}set activeTool(t){this._activeTool=t,this.render()}get activeTool(){return this._activeTool}set useMinimalControls(t){this._useMinimalControls=t,this.render()}get useMinimalControls(){return this._useMinimalControls}set sidebarOpen(t){this._sidebarOpen=t,this.render()}get sidebarOpen(){return this._sidebarOpen}set newAnnotationType(t){this._newAnnotationType=t,this.render()}get newAnnotationType(){return this._newAnnotationType}set highlightsVisible(t){this._highlightsVisible=t,
|
|
184
|
-
this.render()}get highlightsVisible(){return this._highlightsVisible}get sidebarToggleButton(){return this._sidebarToggleButton.current}set supportedAnnotationTools(t){this._supportedAnnotationTools=t,this.render()}get supportedAnnotationTools(){return this._supportedAnnotationTools}set keyboardModeState(t){this._keyboardActive=t.keyboardActive,this._keyboardMode=t.keyboardMode,this.render()}get keyboardModeState(){return{keyboardActive:this._keyboardActive,keyboardMode:this._keyboardMode}}set modeButtonCallbacks(t){this._onModeClick=t.onModeClick,this._onActivateMoveMode=t.onActivateMoveMode,this._onActivatePointMoveMode=t.onActivatePointMoveMode,this.render()}get modeButtonCallbacks(){return{onModeClick:this._onModeClick,onActivateMoveMode:this._onActivateMoveMode,onActivatePointMoveMode:this._onActivatePointMoveMode}}render(){H(St(
|
|
185
|
-
sidebarContainerId:this._sidebarContainerId,showHighlights:this._highlightsVisible,supportedTools:this._supportedAnnotationTools,toggleHighlights:this._toggleHighlights,toggleSidebar:this._toggleSidebar,toggleSidebarRef:this._sidebarToggleButton,useMinimalControls:this.useMinimalControls,keyboardMode:this._keyboardMode,keyboardActive:this._keyboardActive,onModeClick:this._onModeClick,onActivateMoveMode:this._onActivateMoveMode,onActivatePointMoveMode:this._onActivatePointMoveMode}),this.container)}}class
|
|
186
|
-
if(null===this._startX)return;const e=t.clientX-this._startX;!this._dragActive&&Math.abs(e)>=this._threshold&&(this._dragActive=!0,n({type:"dragstart",deltaX:e})),this._dragActive&&n({type:"dragmove",deltaX:e})}))}destroy(){this._listeners.removeAll()}}const
|
|
185
|
+
this.render()}get highlightsVisible(){return this._highlightsVisible}get sidebarToggleButton(){return this._sidebarToggleButton.current}set supportedAnnotationTools(t){this._supportedAnnotationTools=t,this.render()}get supportedAnnotationTools(){return this._supportedAnnotationTools}set keyboardModeState(t){this._keyboardActive=t.keyboardActive,this._keyboardMode=t.keyboardMode,this.render()}get keyboardModeState(){return{keyboardActive:this._keyboardActive,keyboardMode:this._keyboardMode}}set modeButtonCallbacks(t){this._onModeClick=t.onModeClick,this._onActivateMoveMode=t.onActivateMoveMode,this._onActivatePointMoveMode=t.onActivatePointMoveMode,this.render()}get modeButtonCallbacks(){return{onModeClick:this._onModeClick,onActivateMoveMode:this._onActivateMoveMode,onActivatePointMoveMode:this._onActivatePointMoveMode}}render(){H(St(jr,{activeTool:this._activeTool,closeSidebar:this._closeSidebar,createAnnotation:this._createAnnotation,newAnnotationType:this._newAnnotationType,isSidebarOpen:this._sidebarOpen,
|
|
186
|
+
sidebarContainerId:this._sidebarContainerId,showHighlights:this._highlightsVisible,supportedTools:this._supportedAnnotationTools,toggleHighlights:this._toggleHighlights,toggleSidebar:this._toggleSidebar,toggleSidebarRef:this._sidebarToggleButton,useMinimalControls:this.useMinimalControls,keyboardMode:this._keyboardMode,keyboardActive:this._keyboardActive,onModeClick:this._onModeClick,onActivateMoveMode:this._onActivateMoveMode,onActivatePointMoveMode:this._onActivatePointMoveMode}),this.container)}}class Xr{constructor({target:t,threshold:e=10,onDrag:n}){t.style.touchAction="none",this._listeners=new mt,this._startX=null,this._dragActive=!1,this._threshold=e,this._listeners.add(t,"pointerdown",(t=>{this._startX=t.clientX}));const o=t=>{if(null!==this._startX&&this._dragActive){const e=t.clientX-this._startX;n({type:"dragend",deltaX:e})}this._startX=null,this._dragActive=!1};this._listeners.add(window,"pointercancel",o),this._listeners.add(window,"pointerup",o),this._listeners.add(window,"pointermove",(t=>{
|
|
187
|
+
if(null===this._startX)return;const e=t.clientX-this._startX;!this._dragActive&&Math.abs(e)>=this._threshold&&(this._dragActive=!0,n({type:"dragstart",deltaX:e})),this._dragActive&&n({type:"dragmove",deltaX:e})}))}destroy(){this._listeners.removeAll()}}const Yr=280;class Gr{constructor(t,e,n){this._emitter=e.createEmitter(),this._guestWithSelection=null,this._guestRPC=[],this._sidebarRPC=new De,this.iframe=function(t){const e=t.sidebarAppUrl,n=kr(e,Mr(e,t)),o=document.createElement("iframe");return o.src=n,o.title="Hypothesis annotation viewer",o.className="sidebar-frame",o.allow="fullscreen; clipboard-write",o}(n),this._config=n,this.bucketBar=null,this.features=new Mo;const o="sidebar-container",i=document.createElement("div");if(i.setAttribute("data-testid","toolbar-container"),this.toolbar=new Kr(i,{sidebarContainerId:o,createAnnotation:t=>{if(0===this._guestRPC.length)return;(this._guestWithSelection??this._guestRPC[0]).call("createAnnotation",{tool:t})},setSidebarOpen:t=>t?this.open():this.close(),
|
|
187
188
|
setHighlightsVisible:t=>this.setHighlightsVisible(t)}),this.toolbar.modeButtonCallbacks={onModeClick:()=>{const t=this._getGuestRPC();if(!t)return;const e=this.toolbar.keyboardModeState?.keyboardMode||"rect";let n;n="rect"===e?"move":"move"===e?"resize":"rect",t.call("setKeyboardMode",{mode:n})},onActivateMoveMode:()=>{const t=this._getGuestRPC();t&&t.call("activateMoveMode")},onActivatePointMoveMode:()=>{const t=this._getGuestRPC();t&&t.call("activatePointMoveMode")}},n.externalContainerSelector)this.externalFrame=document.querySelector(n.externalContainerSelector)??t,this.externalFrame.appendChild(this.iframe);else{if(this.iframeContainer=document.createElement("div"),this.iframeContainer.style.display="none",this.iframeContainer.className="sidebar-container",this.iframeContainer.id=o,"clean"===n.theme)this.iframeContainer.classList.add("theme-clean"),this.iframeContainer.append(i),this.toolbar.useMinimalControls=!0;else{let t;n.bucketContainerSelector&&(t=document.querySelector(n.bucketContainerSelector),
|
|
188
|
-
t||console.warn(`Custom bucket container "${n.bucketContainerSelector}" not found`));const e=document.createElement("div");e.setAttribute("data-testid","sidebar-edge"),e.className=Tt("absolute top-0 bottom-0 w-[23px] left-[-22px]","flex flex-col pr-[5px]","bg-grey-2 sidebar-collapsed:bg-black/[.08]","pointer-events-none"),i.className="pointer-events-auto",e.append(i),this.iframeContainer.append(e),t||(t=e),this.bucketBar=new
|
|
189
|
-
this._messagesElement=document.createElement("div"),e.appendChild(this._messagesElement),H(St(
|
|
189
|
+
t||console.warn(`Custom bucket container "${n.bucketContainerSelector}" not found`));const e=document.createElement("div");e.setAttribute("data-testid","sidebar-edge"),e.className=Tt("absolute top-0 bottom-0 w-[23px] left-[-22px]","flex flex-col pr-[5px]","bg-grey-2 sidebar-collapsed:bg-black/[.08]","pointer-events-none"),i.className="pointer-events-auto",e.append(i),this.iframeContainer.append(e),t||(t=e),this.bucketBar=new Dr(t,{onFocusAnnotations:t=>this._guestRPC.forEach((e=>e.call("hoverAnnotations",t))),onScrollToAnnotation:t=>this._guestRPC.forEach((e=>e.call("scrollToAnnotation",t))),onSelectAnnotations:(t,e)=>this._guestRPC.forEach((n=>n.call("selectAnnotations",t,e)))})}this.iframeContainer.appendChild(this.iframe),this._hypothesisSidebar=document.createElement("hypothesis-sidebar");const{shadowRoot:e,stylesLoaded:r}=En(this._hypothesisSidebar);e.appendChild(this.iframeContainer),r.then((()=>this._onResize())),t.appendChild(this._hypothesisSidebar),
|
|
190
|
+
this._messagesElement=document.createElement("div"),e.appendChild(this._messagesElement),H(St(Fr,{emitter:this._emitter}),this._messagesElement)}this.iframe.contentWindow&&Te(this.iframe.contentWindow),this._listeners=new mt,this.iframeContainer?this._toolbarWidth=this.toolbar.getWidth():this._toolbarWidth=0,this._listeners.add(window,"resize",(()=>this._onResize())),this._dragResizeState={initial:null,final:null};const r=this.toolbar.sidebarToggleButton;r&&(this._dragResizeHandler=new Xr({target:r,onDrag:t=>this._onDragSidebarToggleButton(t)})),this.close();const[s]=n.services||[];s&&(this.onLoginRequest=s.onLoginRequest,this.onLogoutRequest=s.onLogoutRequest,this.onSignupRequest=s.onSignupRequest,this.onProfileRequest=s.onProfileRequest,this.onHelpRequest=s.onHelpRequest),this.onLayoutChange=n.onLayoutChange,this._layoutState={expanded:!1,width:0,height:0,toolbarWidth:0},this._updateLayoutState(!1),this._setupSidebarEvents()}_getGuestRPC(){return this._guestRPC[0]??null}destroy(){
|
|
190
191
|
this._guestRPC.forEach((t=>t.destroy())),this._sidebarRPC.destroy(),this.bucketBar?.destroy(),this._listeners.removeAll(),this._dragResizeHandler?.destroy(),this._hypothesisSidebar?(H(null,this._messagesElement),this._hypothesisSidebar.remove()):this.iframe.remove(),this._emitter.destroy(),Te(null)}onFrameConnected(t,e){switch(t){case"guest":this._connectGuest(e);break;case"sidebar":this._sidebarRPC.connect(e)}}_connectGuest(t){const e=new De;e.on("textSelected",(()=>{this._guestWithSelection=e,this.toolbar.newAnnotationType="annotation",this._guestRPC.filter((t=>t!==e)).forEach((t=>t.call("clearSelection")))})),e.on("textUnselected",(()=>{this._guestWithSelection=null,this.toolbar.newAnnotationType="note",this._guestRPC.filter((t=>t!==e)).forEach((t=>t.call("clearSelection")))})),e.on("activeToolChanged",(t=>{this.toolbar.activeTool=t})),e.on("highlightsVisibleChanged",(t=>{this.setHighlightsVisible(t)}));const n=this.bucketBar;n&&e.on("anchorsChanged",(t=>{0===this._guestRPC.indexOf(e)&&n.update(t)})),
|
|
191
192
|
e.on("close",(()=>{e.destroy(),e===this._guestWithSelection&&(this._guestWithSelection=null),this._guestRPC=this._guestRPC.filter((t=>t!==e))})),e.on("supportedToolsChanged",(t=>{this.toolbar.supportedAnnotationTools=t})),e.on("keyboardModeChanged",(t=>{this.toolbar.keyboardModeState=t})),e.connect(t),this._guestRPC.push(e),e.call("sidebarLayoutChanged",this._layoutState)}_setupSidebarEvents(){var t;t=document.body,this._sidebarRPC.on("publicAnnotationCountChanged",(function(e){const n=t.querySelectorAll("[data-hypothesis-annotation-count]");Array.from(n).forEach((t=>{t.textContent=e.toString()}))})),function(t,e){const n=t.querySelectorAll("[data-hypothesis-trigger]");Array.from(n).forEach((t=>{t.addEventListener("click",(t=>{e(),t.stopPropagation()}))}))}(document.body,(()=>this.open())),this._sidebarRPC.on("featureFlagsUpdated",(t=>this.features.update(t))),this._sidebarRPC.on("connect",(()=>{this.iframeContainer&&(this.iframeContainer.style.display="");const t="always"===this._config.showHighlights
|
|
192
193
|
;this.setHighlightsVisible(t),(this._config.openSidebar||this._config.annotations||this._config.query||this._config.group)&&this.open()})),this._sidebarRPC.on("showHighlights",(()=>this.setHighlightsVisible(!0))),this._sidebarRPC.on("openSidebar",(()=>this.open())),this._sidebarRPC.on("closeSidebar",(()=>this.close())),this._sidebarRPC.on("openNotebook",(t=>{this.hide(),this._emitter.publish("openNotebook",t)})),this._sidebarRPC.on("openProfile",(()=>{this.hide(),this._emitter.publish("openProfile")})),this._emitter.subscribe("closeProfile",(()=>{this.show()})),this._emitter.subscribe("closeNotebook",(()=>{this.show()})),this._sidebarRPC.on("toastMessageAdded",(t=>{this._emitter.publish("toastMessageAdded",t)})),this._sidebarRPC.on("toastMessageDismissed",(t=>{this._emitter.publish("toastMessageDismissed",t)}))
|
|
193
|
-
;[["loginRequested",this.onLoginRequest],["logoutRequested",this.onLogoutRequest],["signupRequested",this.onSignupRequest],["profileRequested",this.onProfileRequest],["helpRequested",this.onHelpRequest]].forEach((([t,e])=>{e&&this._sidebarRPC.on(t,(()=>e()))}))}_resetDragResizeState(){this._dragResizeState={initial:null,final:null}}_updateLayout(){this._renderFrame||(this._renderFrame=requestAnimationFrame((()=>{if(this._renderFrame=void 0,"number"==typeof this._dragResizeState.final&&this._dragResizeState.final!==this._dragResizeState.initial&&this.iframeContainer){const t=this._dragResizeState.final,e=-t;this.iframeContainer.style.marginLeft=`${t}px`,e>=
|
|
194
|
-
;"boolean"==typeof t?t&&(a+=r):(s<
|
|
195
|
-
;this._dragResizeState.final=Math.min(Math.round(e+n),0),this._updateLayout();break}}}open(){if(this._sidebarRPC.call("sidebarOpened"),this.iframeContainer){const t=this.iframeContainer.getBoundingClientRect().width;this.iframeContainer.style.marginLeft=-1*t+"px",this.iframeContainer.classList.remove("sidebar-collapsed")}this.toolbar.sidebarOpen=!0,"whenSidebarOpen"===this._config.showHighlights&&this.setHighlightsVisible(!0),this._updateLayoutState(!0)}close(){this._sidebarRPC.call("sidebarClosed"),this.iframeContainer&&(this.iframeContainer.style.marginLeft="",this.iframeContainer.classList.add("sidebar-collapsed")),this.toolbar.sidebarOpen=!1,"whenSidebarOpen"===this._config.showHighlights&&this.setHighlightsVisible(!1),this._updateLayoutState(!1)}setHighlightsVisible(t){this.toolbar.highlightsVisible=t,this._sidebarRPC.call("setHighlightsVisible",t)}show(){this.iframeContainer?.classList.remove("is-hidden")}hide(){this.iframeContainer?.classList.add("is-hidden")}}class
|
|
196
|
-
this._subscriptions=[]}publish(t,...e){this._emitter.emit(t,...e)}subscribe(t,e){this._emitter.on(t,e),this._subscriptions.push([t,e])}unsubscribe(t,e){this._emitter.off(t,e),this._subscriptions=this._subscriptions.filter((([n,o])=>n!==t||o!==e))}destroy(){for(const[t,e]of this._subscriptions)this._emitter.off(t,e);this._subscriptions=[]}}class
|
|
197
|
-
}())return void console.warn("Hypothesis did not load because it found an existing instance on the page.");const t=hn("sidebar"),e=new URL(t.sidebarAppUrl).origin,n=new Ne(e),o=new
|
|
194
|
+
;[["loginRequested",this.onLoginRequest],["logoutRequested",this.onLogoutRequest],["signupRequested",this.onSignupRequest],["profileRequested",this.onProfileRequest],["helpRequested",this.onHelpRequest]].forEach((([t,e])=>{e&&this._sidebarRPC.on(t,(()=>e()))}))}_resetDragResizeState(){this._dragResizeState={initial:null,final:null}}_updateLayout(){this._renderFrame||(this._renderFrame=requestAnimationFrame((()=>{if(this._renderFrame=void 0,"number"==typeof this._dragResizeState.final&&this._dragResizeState.final!==this._dragResizeState.initial&&this.iframeContainer){const t=this._dragResizeState.final,e=-t;this.iframeContainer.style.marginLeft=`${t}px`,e>=Yr&&(this.iframeContainer.style.width=`${e}px`),this._updateLayoutState()}})))}_updateLayoutState(t){const e=this.iframeContainer&&this.toolbar.getWidth()||0,n=this.iframeContainer??this.externalFrame,{height:o}=n.getBoundingClientRect(),i=window.getComputedStyle(n),r=parseInt(i.width),s=parseInt(i.marginLeft);let a=e
|
|
195
|
+
;"boolean"==typeof t?t&&(a+=r):(s<Yr?a-=s:a+=r,t=a>e);const l={expanded:t,width:t?a:e,height:o,toolbarWidth:e};this._layoutState=l,this.onLayoutChange?.(l),this._guestRPC.forEach((t=>t.call("sidebarLayoutChanged",l)))}_onResize(){this.toolbar.sidebarOpen&&(window.innerWidth<Yr?this.close():this.open())}isResizing(){return null!==this._dragResizeState.initial}_onDragSidebarToggleButton(t){const e=this.iframeContainer;if(e)switch(t.type){case"dragstart":this._resetDragResizeState(),e.classList.add("sidebar-no-transition"),this.toolbar.container.style.pointerEvents="none",this._dragResizeState.initial=parseInt(getComputedStyle(e).marginLeft);break;case"dragend":e.classList.remove("sidebar-no-transition"),this.toolbar.container.style.pointerEvents="",null===this._dragResizeState.final||this._dragResizeState.final<=-280?this.open():this.close(),this._resetDragResizeState();break;case"dragmove":{if("number"!=typeof this._dragResizeState.initial)return;const e=this._dragResizeState.initial,n=t.deltaX
|
|
196
|
+
;this._dragResizeState.final=Math.min(Math.round(e+n),0),this._updateLayout();break}}}open(){if(this._sidebarRPC.call("sidebarOpened"),this.iframeContainer){const t=this.iframeContainer.getBoundingClientRect().width;this.iframeContainer.style.marginLeft=-1*t+"px",this.iframeContainer.classList.remove("sidebar-collapsed")}this.toolbar.sidebarOpen=!0,"whenSidebarOpen"===this._config.showHighlights&&this.setHighlightsVisible(!0),this._updateLayoutState(!0)}close(){this._sidebarRPC.call("sidebarClosed"),this.iframeContainer&&(this.iframeContainer.style.marginLeft="",this.iframeContainer.classList.add("sidebar-collapsed")),this.toolbar.sidebarOpen=!1,"whenSidebarOpen"===this._config.showHighlights&&this.setHighlightsVisible(!1),this._updateLayoutState(!1)}setHighlightsVisible(t){this.toolbar.highlightsVisible=t,this._sidebarRPC.call("setHighlightsVisible",t)}show(){this.iframeContainer?.classList.remove("is-hidden")}hide(){this.iframeContainer?.classList.add("is-hidden")}}class Qr{constructor(t){this._emitter=t,
|
|
197
|
+
this._subscriptions=[]}publish(t,...e){this._emitter.emit(t,...e)}subscribe(t,e){this._emitter.on(t,e),this._subscriptions.push([t,e])}unsubscribe(t,e){this._emitter.off(t,e),this._subscriptions=this._subscriptions.filter((([n,o])=>n!==t||o!==e))}destroy(){for(const[t,e]of this._subscriptions)this._emitter.off(t,e);this._subscriptions=[]}}class Jr{constructor(){this._emitter=new Me}createEmitter(){return new Qr(this._emitter)}}const Zr=document.querySelector('link[type="application/annotator+html"][rel="sidebar"]');new Promise((t=>{"loading"!==document.readyState&&t(),document.addEventListener("readystatechange",(()=>t()))})).then((function(){const t=hn("annotator");let e=()=>{};const n=new Promise((t=>{e=t}));Zr.addEventListener("destroy",e);const o=t.subFrameIdentifier?window.parent:window,i=[];if(o===window){if(function(){const t=document.querySelectorAll(["hypothesis-sidebar","hypothesis-notebook","hypothesis-profile"].join(","));return t.forEach((t=>t.remove())),t.length>0
|
|
198
|
+
}())return void console.warn("Hypothesis did not load because it found an existing instance on the page.");const t=hn("sidebar"),e=new URL(t.sidebarAppUrl).origin,n=new Ne(e),o=new Jr,r=new Gr(document.body,o,t),s=new Lr(document.body,o,hn("notebook")),a=new Ir(document.body,o,hn("profile"));n.on("frameConnected",((t,e)=>r.onFrameConnected(t,e))),i.push(n,r,s,a)}if("container"===dr()){const e=new ur(t);i.push(e)}else{const n=new ar(document.body,t),r=new Ar(document.body,t,o);r.on("hostDisconnected",e),i.push(n,r)}n.then((()=>{i.forEach((t=>t.destroy()));document.querySelectorAll("[data-hypothesis-asset]").forEach((t=>t.remove())),function(t=document){Array.from(t.querySelectorAll("script.js-hypothesis-config[data-remove-on-unload]")).forEach((t=>t.remove()))}()}))}))}();
|
|
198
199
|
//# sourceMappingURL=annotator.bundle.js.map
|