hypothesis 1.1604.0 → 1.1605.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/build/boot.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
!function(){"use strict";var s={"scripts/annotator.bundle.js":"scripts/annotator.bundle.js?
|
|
1
|
+
!function(){"use strict";var s={"scripts/annotator.bundle.js":"scripts/annotator.bundle.js?4ba653","styles/annotator.css":"styles/annotator.css?427463","styles/annotator.css.map":"styles/annotator.css.map?94a857","styles/highlights.css":"styles/highlights.css?6b4ebd","styles/highlights.css.map":"styles/highlights.css.map?241350","styles/katex.min.css":"styles/katex.min.css?d92c5a","styles/katex.min.css.map":"styles/katex.min.css.map?e7e03f","styles/pdfjs-overrides.css":"styles/pdfjs-overrides.css?c95edf","styles/pdfjs-overrides.css.map":"styles/pdfjs-overrides.css.map?1d8ac6","styles/sidebar.css":"styles/sidebar.css?0692da","styles/sidebar.css.map":"styles/sidebar.css.map?4344ed","styles/ui-playground.css.map":"styles/ui-playground.css.map?bad68d","styles/ui-playground.css":"styles/ui-playground.css?322473","scripts/annotator.bundle.js.map":"scripts/annotator.bundle.js.map?3a7d8c","scripts/sidebar.bundle.js":"scripts/sidebar.bundle.js?af8aed","scripts/ui-playground.bundle.js":"scripts/ui-playground.bundle.js?4107fe","scripts/sidebar.bundle.js.map":"scripts/sidebar.bundle.js.map?acf867","scripts/ui-playground.bundle.js.map":"scripts/ui-playground.bundle.js.map?f66fa1"};function t(s){s.setAttribute("data-hypothesis-asset","")}function e(s,e){var o=s.createElement("link");o.rel="stylesheet",o.type="text/css",o.href=e,t(o),s.head.appendChild(o)}function o(s,e){var o=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},r=o.esModule,n=void 0===r||r,a=o.forceReload,i=void 0!==a&&a,l=s.createElement("script");n&&(l.type="module"),i&&(e+="#ts=".concat(Date.now())),l.src=e,l.async=!1,t(l),s.head.appendChild(l)}function r(s,e,o,r){var n=s.createElement("link");n.rel=e,n.href=r,n.type="application/annotator+".concat(o),t(n),s.head.appendChild(n)}function n(s,e,o){var r=s.createElement("link");r.rel="preload",r.as=e,r.href=o,"fetch"===e&&(r.crossOrigin="anonymous"),t(r),s.head.appendChild(r)}function a(s,t){return s.assetRoot+"build/"+s.manifest[t]}function i(s){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:document;if(-1===s.indexOf("{"))return s;var e=function(){var s,t,e=(arguments.length>0&&void 0!==arguments[0]?arguments[0]:document).currentScript;return e?(s=e.src,(t=s.match(/(https?):\/\/([^:/]+)/))?{protocol:t[1],hostname:t[2]}:null):null}(t);if(!e)throw new Error("Could not process URL template because script origin is unknown");return s=(s=s.replace("{current_host}",e.hostname)).replace("{current_scheme}",e.protocol)}if(function(){var s=[()=>Object.fromEntries([]),()=>new URL(document.location.href),()=>new Request("https://hypothes.is"),()=>Element.prototype.attachShadow,()=>CSS.supports("display: grid"),()=>(document.evaluate("/html/body",document,null,XPathResult.ANY_TYPE,null),!0)];try{return s.every((s=>s()))}catch(s){return!1}}()){var l=function(s){for(var t={},e=s.querySelectorAll("script.js-hypothesis-config"),o=0;o<e.length;o++){var r=void 0;try{r=JSON.parse(e[o].textContent||"")}catch(s){console.warn("Could not parse settings from js-hypothesis-config tags",s),r={}}Object.assign(t,r)}return t}(document),p=i(l.assetRoot||"https://cdn.hypothes.is/hypothesis/1.1605.0/");if(document.querySelector("hypothesis-app")){!function(s,t){n(s,"fetch",t.apiUrl),n(s,"fetch",t.apiUrl+"links");for(var r=0,i=["scripts/sidebar.bundle.js"];r<i.length;r++)o(s,a(t,i[r]),{esModule:!0});for(var l=0,p=["styles/katex.min.css","styles/sidebar.css"];l<p.length;l++)e(s,a(t,p[l]))}(document,{assetRoot:p,manifest:s,apiUrl:l.apiUrl})}else{var c=function(){var s;return null===(s=(arguments.length>0&&void 0!==arguments[0]?arguments[0]:window).chrome)||void 0===s||null===(s=s.runtime)||void 0===s?void 0:s.id}();if(c&&!function(s){return!!(arguments.length>1&&void 0!==arguments[1]?arguments[1]:document).querySelector("script.js-hypothesis-config[data-extension-id=".concat(s,"]"))}(c))throw new Error("Could not start Hypothesis extension as configuration is missing");var d=l,h=i(d.notebookAppUrl||"https://hypothes.is/notebook"),u=i(d.profileAppUrl||"https://hypothes.is/user-profile"),y=i(d.sidebarAppUrl||"https://hypothes.is/app.html");!function(s,t){if(!s.querySelector('link[type="application/annotator+html"]')){r(s,"sidebar","html",t.sidebarAppUrl),r(s,"notebook","html",t.notebookAppUrl),r(s,"profile","html",t.profileAppUrl),n(s,"style",a(t,"styles/annotator.css")),r(s,"hypothesis-client","javascript",t.assetRoot+"build/boot.js");for(var i=0,l=["scripts/annotator.bundle.js"];i<l.length;i++)o(s,a(t,l[i]),{esModule:!1});var p=[];void 0!==window.PDFViewerApplication&&p.push("styles/pdfjs-overrides.css"),p.push("styles/highlights.css");for(var c=0,d=p;c<d.length;c++)e(s,a(t,d[c]))}}(document,{assetRoot:p,manifest:s,notebookAppUrl:h,profileAppUrl:u,sidebarAppUrl:y})}}else console.warn("The Hypothesis annotation tool is not supported in this browser. See https://web.hypothes.is/help/which-browsers-are-supported-by-hypothesis/.")}();
|
package/build/manifest.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"scripts/annotator.bundle.js": "scripts/annotator.bundle.js?
|
|
2
|
+
"scripts/annotator.bundle.js": "scripts/annotator.bundle.js?4ba653",
|
|
3
3
|
"styles/annotator.css": "styles/annotator.css?427463",
|
|
4
4
|
"styles/annotator.css.map": "styles/annotator.css.map?94a857",
|
|
5
5
|
"styles/highlights.css": "styles/highlights.css?6b4ebd",
|
|
@@ -8,13 +8,13 @@
|
|
|
8
8
|
"styles/katex.min.css.map": "styles/katex.min.css.map?e7e03f",
|
|
9
9
|
"styles/pdfjs-overrides.css": "styles/pdfjs-overrides.css?c95edf",
|
|
10
10
|
"styles/pdfjs-overrides.css.map": "styles/pdfjs-overrides.css.map?1d8ac6",
|
|
11
|
-
"styles/sidebar.css.map": "styles/sidebar.css.map?4344ed",
|
|
12
11
|
"styles/sidebar.css": "styles/sidebar.css?0692da",
|
|
13
|
-
"styles/
|
|
12
|
+
"styles/sidebar.css.map": "styles/sidebar.css.map?4344ed",
|
|
14
13
|
"styles/ui-playground.css.map": "styles/ui-playground.css.map?bad68d",
|
|
15
|
-
"
|
|
16
|
-
"scripts/
|
|
14
|
+
"styles/ui-playground.css": "styles/ui-playground.css?322473",
|
|
15
|
+
"scripts/annotator.bundle.js.map": "scripts/annotator.bundle.js.map?3a7d8c",
|
|
16
|
+
"scripts/sidebar.bundle.js": "scripts/sidebar.bundle.js?af8aed",
|
|
17
17
|
"scripts/ui-playground.bundle.js": "scripts/ui-playground.bundle.js?4107fe",
|
|
18
|
-
"scripts/
|
|
19
|
-
"scripts/
|
|
18
|
+
"scripts/sidebar.bundle.js.map": "scripts/sidebar.bundle.js.map?acf867",
|
|
19
|
+
"scripts/ui-playground.bundle.js.map": "scripts/ui-playground.bundle.js.map?f66fa1"
|
|
20
20
|
}
|
|
@@ -118,16 +118,16 @@ Vn((()=>{document.body.style.marginLeft="",document.body.style.marginRight=""}))
|
|
|
118
118
|
;if(function(e){return"symbol"==typeof e||function(e){return!!e&&"object"==typeof e}(e)&&u.call(e)==n}(e))return t;if(p(e)){var l="function"==typeof e.valueOf?e.valueOf():e;e=p(l)?l+"":l}if("string"!=typeof e)return 0===e?e:+e;e=e.replace(o,"");var c=r.test(e);return c||s.test(e)?a(e.slice(2),c?2:8):i.test(e)?t:+e}return Ri=function(e,t,n){var o,i,r,s,a,l,c=0,d=!1,u=!1,_=!0;if("function"!=typeof e)throw new TypeError("Expected a function");function b(t){var n=o,r=i;return o=i=void 0,c=t,s=e.apply(r,n)}function v(e){var n=e-l;return void 0===l||n>=t||n<0||u&&e-c>=r}function w(){var e=m();if(v(e))return y(e);a=setTimeout(w,function(e){var n=t-(e-l);return u?f(n,r-(e-c)):n}(e))}function y(e){return a=void 0,_&&o?b(e):(o=i=void 0,s)}function x(){var e=m(),n=v(e);if(o=arguments,i=this,l=e,n){if(void 0===a)return function(e){return c=e,a=setTimeout(w,t),d?b(e):s}(l);if(u)return a=setTimeout(w,t),b(l)}return void 0===a&&(a=setTimeout(w,t)),s}return t=g(t)||0,p(n)&&(d=!!n.leading,
|
|
119
119
|
r=(u="maxWait"in n)?h(g(n.maxWait)||0,t):r,_="trailing"in n?!!n.trailing:_),x.cancel=function(){void 0!==a&&clearTimeout(a),c=0,o=l=i=a=void 0},x.flush=function(){return void 0===a?s:y(m())},x},Ri}(),Mi=t(Pi);function Li(e,t,n,o=0){let i=o;for(;i<e.length&&t>0;)n(e[i])&&--t,++i;return i}function Oi(e,t,n,o){let i=0;for(let r=n;r<o;r++)t(e[r])&&++i;return i}function Ii(e,t,n,o,i){const r=Oi(e,i,0,n),s=Oi(e,i,n,o);let a=Li(t,r,i);for(;a<t.length&&!i(t[a]);)++a;return[a,Li(t,s,i,a)]}const Bi={INITIAL:0,FINISHED:3},Di=new Map,Fi=new Map;function Hi(e,t){return`${e}:${t}`}function Vi(e){let t=0;for(;e.previousSibling;)++t,e=e.previousSibling;return t}function Ui(e){const t="closest"in e?e:e.parentElement;return t?.closest(".textLayer")??null}function qi(){return PDFViewerApplication.pdfViewer}async function zi(e){const t=qi();let n=t.getPageView(e);return n&&n.pdfPage||(n=await new Promise((n=>{const o=()=>{t.eventBus?t.eventBus.off("pagesloaded",o):document.removeEventListener("pagesloaded",o),n(t.getPageView(e))
|
|
120
120
|
};t.eventBus?t.eventBus.on("pagesloaded",o):document.addEventListener("pagesloaded",o)}))),n}function $i(e){const t=Di.get(e);if(t)return t;const n=(async()=>{const t=await zi(e);return(await t.pdfPage.getTextContent({normalizeWhitespace:!0})).items.map((e=>e.str)).join("")})();return Di.set(e,n),n}async function Wi(e){const t=qi();let n=0,o=0,i="";for(let r=0;r<t.pagesCount;r++)if(i=await $i(r),n=o,o+=i.length,o>=e)return{index:r,offset:n,text:i};return{index:t.pagesCount-1,offset:n,text:i}}function ji(e){switch(e){case" ":case"\f":case"\n":case"\r":case"\t":case"\v":case" ":return!0;default:return!1}}const Xi=e=>!ji(e);function Ki(e){return void 0!==e.renderingDone?e.renderingDone:!!e.div&&null!==e.div.querySelector(".endOfContent")}async function Yi(e,t,n){const[o,i]=await Promise.all([zi(e),$i(e)]);if(o.renderingState===Bi.FINISHED&&o.textLayer&&Ki(o.textLayer)){const e=o.textLayer.textLayerDiv??o.textLayer.div;if(!e)throw new Error("Unable to find PDF.js text layer root")
|
|
121
|
-
;const r=e.textContent,[s,a]=Ii(i,r,t,n,Xi);Gi(r.slice(s,a))!==Gi(i.slice(t,n))&&zo("Text layer text does not match page text. Highlights will be mis-aligned.");const l=new po(e,s),c=new po(e,a);return new go(l,c).toRange()}const r=function(e){let t=e.querySelector(_o);return t||(t=document.createElement("span"),t.classList.add("annotator-placeholder"),t.textContent="Loading annotations...",e.appendChild(t),t)}(o.div),s=document.createRange();return s.setStartBefore(r),s.setEndAfter(r),s}function Gi(e){let t="";for(let n=0;n<e.length;n++){const o=e[n];ji(o)||(t+=o)}return t}async function Qi(e
|
|
122
|
-
;return await Yi(e,
|
|
123
|
-
}catch{throw new Error("Selection does not contain text")}const t=Ui(e.startContainer),n=Ui(e.endContainer);if(!t||!n)throw new Error("Selection is outside page text");if(t!==n)throw new Error("Selecting across page breaks is not supported");return[e,t]}async function Zi(e
|
|
121
|
+
;const r=e.textContent,[s,a]=Ii(i,r,t,n,Xi);Gi(r.slice(s,a))!==Gi(i.slice(t,n))&&zo("Text layer text does not match page text. Highlights will be mis-aligned.");const l=new po(e,s),c=new po(e,a);return new go(l,c).toRange()}const r=function(e){let t=e.querySelector(_o);return t||(t=document.createElement("span"),t.classList.add("annotator-placeholder"),t.textContent="Loading annotations...",e.appendChild(t),t)}(o.div),s=document.createRange();return s.setStartBefore(r),s.setEndAfter(r),s}function Gi(e){let t="";for(let n=0;n<e.length;n++){const o=e[n];ji(o)||(t+=o)}return t}async function Qi(e){const t=e.find((e=>"TextQuoteSelector"===e.type));if(!t)throw new Error("No quote selector found");const n=e.find((e=>"TextPositionSelector"===e.type));if(n){try{const{index:e,offset:o,text:i}=await Wi(n.start),r=n.start-o,s=n.end-o,a=i.substring(r,s);if(t.exact!==a)throw new Error("quote mismatch");return await Yi(e,r,s)}catch{}try{const e=Hi(t.exact,n.start),o=Fi.get(e);if(o){const{pageIndex:e,anchor:t}=o
|
|
122
|
+
;return await Yi(e,t.start,t.end)}}catch{}}return async function(e,t){const n=qi().pagesCount,o=Array(n).fill(0).map(((e,t)=>t));let i,r;if(t){const{index:e,offset:n}=await Wi(t);i=e,r=t-n,o.sort(((t,n)=>Math.abs(t-e)-Math.abs(n-e)))}const s=void 0!==e.prefix?Gi(e.prefix):void 0,a=void 0!==e.suffix?Gi(e.suffix):void 0,l=Gi(e.exact);let c;for(const e of o){const t=await $i(e),n=Gi(t);let o;void 0!==i&&void 0!==r&&(e<i?o=n.length:e===i?[o]=Ii(t,n,r,r,Xi):o=0);const d=ii(n,l,{prefix:s,suffix:a,hint:o});if(d&&(!c||d.score>c.match.score)){const[o,i]=Ii(n,t,d.start,d.end,Xi);c={page:e,match:{start:o,end:i,score:d.score}};const r=n.slice(d.start,d.end)===l,u=void 0!==s&&n.slice(Math.max(0,d.start-s.length),d.start)===s,h=void 0!==a&&n.slice(d.end,a.length)===a;if(r&&(u||h||void 0===s&&void 0===a))break}}if(c){const{page:n,match:o}=c;if(t){const i=Hi(e.exact,t);Fi.set(i,{pageIndex:n,anchor:o})}return Yi(n,o.start,o.end)}throw new Error("Quote not found")}(t,n?.start)}function Ji(e){try{e=go.fromRange(e).toRange()
|
|
123
|
+
}catch{throw new Error("Selection does not contain text")}const t=Ui(e.startContainer),n=Ui(e.endContainer);if(!t||!n)throw new Error("Selection is outside page text");if(t!==n)throw new Error("Selecting across page breaks is not supported");return[e,t]}async function Zi(e){const[t,n]=Ji(e),o=po.fromPoint(t.startContainer,t.startOffset).relativeTo(n),i=po.fromPoint(t.endContainer,t.endOffset).relativeTo(n),r=Vi(n.parentNode),s=r+1,a=await async function(e){if(e>=qi().pagesCount)throw new Error("Invalid page index");let t=0;for(let n=0;n<e;n++)t+=(await $i(n)).length;return t}(r),l=await zi(r);return[{type:"TextPositionSelector",start:a+o.offset,end:a+i.offset},ui.fromRange(l.div,t).toSelector(),{type:"PageSelector",index:r,label:l.pageLabel??s.toString()}]}async function er(e,t){const n=document.elementsFromPoint(e,t);for(const o of n){if(!o.classList.contains("page"))continue;const n=Vi(o),i=o.getBoundingClientRect(),r=e-i.left,s=t-i.top,a=await zi(n),[l,c]=a.getPagePoint(r,s);return{pageIndex:n,x:l,y:c}}
|
|
124
124
|
return null}function tr({children:e}){return Pe("div",{className:"flex flex-col",children:e})}function nr({info:e}){let t=e.item.title;return e.item.subtitle&&(t+=`: ${e.item.subtitle}`),Pe("div",{className:Re("h-10 bg-white px-4 text-slate-7 text-annotator-base border-b","grid items-center","grid-cols-[100px_minmax(0,auto)]","2xl:grid-cols-[100px_minmax(0,auto)_minmax(0,auto)] 2xl:gap-x-3"),children:[Pe("div",{"data-testid":"content-logo",children:e.logo&&Pe(Zt,{href:e.logo.link,target:"_blank","data-testid":"logo-link",underline:"none",children:Pe("img",{alt:e.logo.title,src:e.logo.logo,"data-testid":"logo-image"})})}),Pe("div",{className:Re("hidden","2xl:block 2xl:whitespace-nowrap 2xl:overflow-hidden 2xl:text-ellipsis","font-semibold"),"data-testid":"content-container-info",title:e.container.title,children:e.container.title}),Pe("div",{className:Re("flex justify-center items-center gap-x-2"),"data-testid":"content-item-info",children:[Pe("div",{className:Re("hidden","2xl:block 2xl:grow")
|
|
125
125
|
}),e.links.previousItem&&Pe(x,{children:[Pe(Zt,{title:"Open previous item",href:e.links.previousItem,underline:"always",target:"_blank","data-testid":"content-previous-link",children:Pe("div",{className:"flex gap-x-1 items-center text-annotator-sm whitespace-nowrap",children:[Pe(ze,{className:"w-em h-em"}),Pe("span",{children:"Previous"})]})}),Pe("div",{className:"text-annotator-sm",children:"|"})]}),Pe("div",{className:Re("min-w-0 whitespace-nowrap overflow-hidden text-ellipsis shrink font-medium"),children:Pe(Zt,{title:t,href:e.links.currentItem,"data-testid":"content-item-link",target:"_blank",unstyled:!0,children:t})}),e.links.nextItem&&Pe(x,{children:[Pe("div",{className:"text-annotator-sm",children:"|"}),Pe(Zt,{title:"Open next item",href:e.links.nextItem,underline:"always",target:"_blank","data-testid":"content-next-link",children:Pe("div",{className:"flex gap gap-x-1 items-center text-annotator-sm whitespace-nowrap",children:[Pe("span",{children:"Next"}),Pe(We,{className:"w-em h-em"})]})})]})]})]})}
|
|
126
126
|
function or(){return Pe("div",{className:"bg-white",role:"alert",children:Pe("div",{className:Re("flex items-center gap-x-2","border border-yellow-notice bg-yellow-notice/10 text-annotator-base"),children:[Pe("div",{className:"bg-yellow-notice text-white p-2",children:Pe(Xe,{className:"text-annotator-xl"})}),Pe("div",{children:[Pe("strong",{children:"This PDF does not contain selectable text:"})," ",Pe(Zt,{target:"_blank",href:"https://web.hypothes.is/help/how-to-ocr-optimize-pdfs/",underline:"always",children:"Learn how to fix this"})," ","in order to annotate with Hypothesis."]})]})})}class ir{constructor(e){this._loaded=function(e){return e.initializedPromise?e.initializedPromise:e.initialized?Promise.resolve():new Promise((t=>{const n=setInterval((()=>{e.initialized&&(clearTimeout(n),t())}),5)}))}(e).then((async()=>{const t=await async function(e){return void 0!==e.downloadComplete?e.downloadComplete:(await e.pdfDocument.getDownloadInfo(),!0)}(e);return t?e:new Promise((t=>{const n=()=>{
|
|
127
127
|
e.eventBus?(e.eventBus.off("documentload",n),e.eventBus.off("documentloaded",n)):window.removeEventListener("documentload",n),t(e)};e.eventBus?(e.eventBus.on("documentloaded",n),e.eventBus.on("documentload",n)):window.addEventListener("documentload",n)}))}))}getUri(){return this._loaded.then((e=>{let t=ar(e);return t||(t=sr(rr(e))),t}))}async getMetadata(){const e=await this._loaded,{info:t,contentDispositionFilename:n,metadata:o}=await e.pdfDocument.getMetadata(),i=rr(e),r=ar(e);let s;s=o?.has("dc:title")&&"Untitled"!==o.get("dc:title")?o.get("dc:title"):t?.Title?t.Title:n||(r?function(e){const t=new URL(e),n=t.pathname.split("/");return n[n.length-1]}(r):"");const a=[{href:sr(i)}];return r&&a.push({href:r}),{title:s,link:a,documentFingerprint:i}}}function rr(e){return Array.isArray(e.pdfDocument.fingerprints)?e.pdfDocument.fingerprints[0]:e.pdfDocument.fingerprint}function sr(e){return`urn:x-pdf:${e}`}function ar(e){if(!e.url)return null;const t=Ei(e.url);return 0!==t.indexOf("file://")?t:null}
|
|
128
128
|
function lr(e){const t=e.highlights?.[0];return t&&bo(t)}function cr(e){return new Promise((t=>setTimeout(t,e)))}class dr{constructor(){this._pdfjsContainer=document.querySelector("#outerContainer"),this._contentInfo=null,this._noTextWarning=!1,this._container=null}setContentInfo(e){this._contentInfo=e,this._update()}showNoTextWarning(e){this._noTextWarning=e,this._update()}destroy(){this._container?.destroy()}_update(){if(!(this._noTextWarning||this._contentInfo))return this._container?.destroy(),this._container=null,void(this._pdfjsContainer.style.height="");this._container||(this._container=new oo("banner",(()=>this._render())),document.body.prepend(this._container.element)),this._container.render();const e=this._container.element.getBoundingClientRect().height;this._pdfjsContainer.style.height=`calc(100% - ${e}px)`}_render(){return Pe(tr,{children:[this._contentInfo&&Pe(nr,{info:this._contentInfo}),this._noTextWarning&&Pe(or,{})]})}}class ur extends dn.TinyEmitter{
|
|
129
129
|
constructor({annotator:e,features:t,reanchoringMaxWait:n}){super(),this._annotator=e;const o=window,i=o.PDFViewerApplication;this._pdfViewer=i.pdfViewer,this._pdfViewer.viewer.classList.add("has-transparent-text-layer"),this._pdfContainer=i.appConfig?.appContainer??document.body,this._pdfMetadata=new ir(i),this._observer=new MutationObserver(Mi((()=>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 dr,this._checkForSelectableText(),this._sideBySideActive=!1,this._updateAnnotationLayerVisibility=()=>{const e=o.getSelection();this._pdfViewer.viewer.classList.toggle("is-selecting",!e.isCollapsed)},this._listeners=new ve,this._listeners.add(document,"selectionchange",this._updateAnnotationLayerVisibility),this._destroyed=!1,this._features=t,this._features.on("flagsChanged",(()=>{this.emit("supportedToolsChanged",this.supportedTools())}))}destroy(){this.fitSideBySide({
|
|
130
|
-
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}uri(){return this._pdfMetadata.getUri()}getMetadata(){return this._pdfMetadata.getMetadata()}showContentInfo(e){this._banner.setContentInfo(e)}anchor(e,t){return Qi(
|
|
130
|
+
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}uri(){return this._pdfMetadata.getUri()}getMetadata(){return this._pdfMetadata.getMetadata()}showContentInfo(e){this._banner.setContentInfo(e)}anchor(e,t){return Qi(t)}getAnnotatableRange(e){try{const t=go.trimmedRange(e);if(function(e){try{return Ji(e),!0}catch{return!1}}(t))return t}catch(e){if(!(e instanceof RangeError))throw e}return null}canStyleClusteredHighlights(){return!0}describe(e,t){return t instanceof Range?Zi(t):async function(e){switch(e.type){case"rect":{const[t,n]=await Promise.all([er(e.left,e.top),er(e.right,e.bottom)]);if(!t)throw new Error("Top-left point is not in a page");if(!n)throw new Error("Bottom-right point is not in a page");if(t.pageIndex!==n.pageIndex)throw new Error("Shape must start and end on same page");return[{type:"PageSelector",
|
|
131
131
|
index:t.pageIndex},{type:"ShapeSelector",shape:{type:"rect",left:t.x,top:t.y,right:n.x,bottom:n.y}}]}case"point":{const t=await er(e.x,e.y);if(!t)throw new Error("Point is not in a page");return[{type:"PageSelector",index:t.pageIndex},{type:"ShapeSelector",shape:{type:"point",x:t.x,y:t.y}}]}default:throw new Error("Unsupported shape")}}(t)}async _checkForSelectableText(){try{await this.uri()}catch{return}if(!this._destroyed)try{const e=await async function(){const e=qi();let t=!1;for(let n=0;n<e.pagesCount;n++)if((await $i(n)).trim().length>0){t=!0;break}return t}();this._banner.showNoTextWarning(!e)}catch(e){console.warn("Unable to check for text in PDF:",e)}}_update(){const e=[],t=this._pdfViewer.pagesCount;for(let e=0;e<t;e++){const t=this._pdfViewer.getPageView(e);if(t?.textLayer&&Ki(t.textLayer))switch(t.renderingState){case Bi.INITIAL:t.textLayer=null;break;case Bi.FINISHED:n=t.div,n.querySelector(_o)?.remove()}}var n;for(const t of this._annotator.anchors)if(t.highlights){
|
|
132
132
|
if(e.includes(t.annotation))continue;for(let n=0;n<t.highlights.length;n++){const o=t.highlights[n];if(!document.body.contains(o)){t.highlights.splice(n,1),delete t.range,e.push(t.annotation);break}}}e.map((e=>this._annotator.anchor(e)))}contentContainer(){return document.querySelector("#viewerContainer")}fitSideBySide(e){const t=window.innerWidth-e.width,n=e.expanded&&t>=680,o=n?e.width:e.toolbarWidth;this._pdfContainer.style.width=`calc(100% - ${o}px)`;const i=this._pdfViewer.currentScaleValue;return"auto"!==i&&"page-fit"!==i&&"page-width"!==i||(this._pdfViewer.currentScaleValue=i),this._pdfViewer.update(),this._sideBySideActive=n,n}sideBySideActive(){return this._sideBySideActive}supportedTools(){const e=this._features?.flagEnabled("pdf_image_annotation");return e?["selection","rect","point"]:["selection"]}async scrollToAnchor(e){const t=e.annotation,n=lr(e),o=this._anchorOffset(e);if(null!==o&&(await Si(this.contentContainer(),o),n)){
|
|
133
133
|
const e=await this._waitForAnnotationToBeAnchored(t,this._reanchoringMaxWait);if(!e)return;const n=this._anchorOffset(e);if(null===n)return;await Si(this.contentContainer(),n)}}async _waitForAnnotationToBeAnchored(e,t){const n=Date.now();let o;do{o=this._annotator.anchors.find((t=>t.annotation===e)),o&&!lr(o)||(o=null,await cr(20))}while(!o&&Date.now()-n<t);return o??null}_anchorOffset(e){if(!e.highlights)return null;return function(e,t){let n=0;for(;e!==t&&t.contains(e);)n+=e.offsetTop,e=e.offsetParent;return n}(e.highlights[0],this.contentContainer())}}function hr(e){if(!e.includes("["))return e;let t="",n=!1,o=!1;for(const i of e)n||"^"!==i?(n||"["!==i?!n&&o&&"]"===i?o=!1:o||(t+=i):o=!0,n=!1):n=!0;return t}function fr(e){const t=hr(e),n=t.indexOf("!");return-1===n?t:t.slice(0,n)}class mr{constructor(e,t,n){this._element=e,this._onFrameAdded=t,this._onFrameRemoved=n,this._annotatableFrames=new Set,this._isDisconnected=!1,this._mutationObserver=new MutationObserver(Mi((()=>{this._discoverFrames()}),40)),
|
|
@@ -153,7 +153,7 @@ this._portFinder.destroy(),this._hostRPC.destroy(),this._sidebarRPC.destroy(),th
|
|
|
153
153
|
annotation:e,target:t}}return n})));if(!this._annotations.has(e.$tag))return[];for(const e of n)t(e);return e.$orphan=n.length>0&&n.every((e=>e.target.selector&&!e.range)),this._updateAnchors(this.anchors.concat(n),!0),this._sidebarRPC.call("syncAnchoringStatus",e),n}detach(e,t=!0){this._annotations.delete(e);const n=[];for(const t of this.anchors)t.annotation.$tag!==e?n.push(t):t.highlights&&Ro(t.highlights);this._updateAnchors(n,t)}_updateAnchors(e,t){this.anchors=e,this._clusterToolbar?.scheduleClusterUpdates(),t&&this._bucketBarClient.update(this.anchors)}async createAnnotation(e){if("selection"===e)return this.createAnnotationFromSelection();if(["rect","point"].includes(e)){const t=await this._drawTool.draw(e),n=await this.getDocumentInfo(),o=[{source:n.uri,selector:await this._integration.describe(this.element,t)}],i={uri:n.uri,document:n.metadata,target:o,$tag:"a:"+on(8)};return this._sidebarRPC.call("createAnnotation",i),i}throw new Error("Unsupported annotation tool")}
|
|
154
154
|
async createAnnotationFromSelection({highlight:e=!1}={}){const t=this.selectedRanges;this.selectedRanges=[];const n=await this.getDocumentInfo(),o=this.element,i=(await Promise.all(t.map((e=>this._integration.describe(o,e))))).map((e=>({source:n.uri,selector:e}))),r={uri:n.uri,document:n.metadata,target:i,$highlight:e,$cluster:e?"user-highlights":"user-annotations",$tag:"a:"+on(8)};return this._sidebarRPC.call("createAnnotation",r),this.anchor(r),Lr(),r}_hoverAnnotations(e){this._hoveredAnnotations.clear(),e.forEach((e=>this._hoveredAnnotations.add(e)));for(const t of this.anchors)if(t.highlights){const n=e.includes(t.annotation.$tag);To(t.highlights,n)}this._sidebarRPC.call("hoverAnnotations",e)}_onSelection(e){const t=this._integration.getAnnotatableRange(e);if(!t)return void this._onClearSelection();const n=document.getSelection(),o=yo(n),i=Co(n);i?(this.selectedRanges=[t],this._hostRPC.call("textSelected"),this._adder.annotationsForSelection=Tr(),this._isAdderVisible=!0,
|
|
155
155
|
this._adder.show(i,o)):this._onClearSelection()}_onClearSelection(){this._isAdderVisible=!1,this._adder.hide(),this.selectedRanges=[],this._informHostOnNextSelectionClear&&this._hostRPC.call("textUnselected"),this._informHostOnNextSelectionClear=!0}selectAnnotations(e,{toggle:t=!1,focusInSidebar:n=!1}={}){t?this._sidebarRPC.call("toggleAnnotationSelection",e):this._sidebarRPC.call("showAnnotations",e,n),this._sidebarRPC.call("openSidebar")}setHighlightsVisible(e,t=!0){!function(e,t){e.classList.toggle("hypothesis-highlights-always-on",t)}(this.element,e),this._highlightsVisible=e,t&&this._hostRPC.call("highlightsVisibleChanged",e)}get highlightsVisible(){return this._highlightsVisible}fitSideBySide(e){this._sidebarLayout=e,this._integration.fitSideBySide(e)}get hoveredAnnotationTags(){return this._hoveredAnnotations}_handleShortcut(e){Kn(e,"Ctrl+Shift+H")&&this.setHighlightsVisible(!this._highlightsVisible)}_setOutsideAssignmentNoticeVisible(e){
|
|
156
|
-
this._outsideAssignmentNotice||(this._outsideAssignmentNotice=new Ar(this.element)),this._outsideAssignmentNotice.setVisible(e)}}function Br(e,t){const n=new URL(e),o=new URLSearchParams;return o.append("config",JSON.stringify(t)),n.hash=o.toString(),n.toString()}function Dr(e,t){const n={};for(const[e,o]of Object.entries(t))"notebookAppUrl"!==e&&"sidebarAppUrl"!==e&&null!=o&&(n[e]=o);n.origin=new URL(e).origin,n.version="1.
|
|
156
|
+
this._outsideAssignmentNotice||(this._outsideAssignmentNotice=new Ar(this.element)),this._outsideAssignmentNotice.setVisible(e)}}function Br(e,t){const n=new URL(e),o=new URLSearchParams;return o.append("config",JSON.stringify(t)),n.hash=o.toString(),n.toString()}function Dr(e,t){const n={};for(const[e,o]of Object.entries(t))"notebookAppUrl"!==e&&"sidebarAppUrl"!==e&&null!=o&&(n[e]=o);n.origin=new URL(e).origin,n.version="1.1605.0";const o=new URL(window.location.href);if(o.hash="",n.hostURL=o.toString(),Array.isArray(n.services)&&n.services?.length>0){const e=n.services[0];e.onLoginRequest&&(e.onLoginRequestProvided=!0),e.onLogoutRequest&&(e.onLogoutRequestProvided=!0),e.onSignupRequest&&(e.onSignupRequestProvided=!0),e.onProfileRequest&&(e.onProfileRequestProvided=!0),e.onHelpRequest&&(e.onHelpRequestProvided=!0)}return n}function Fr({closed:e,onClose:t,children:n,"data-testid":o,"aria-label":i}){const r=se(null);return ie((()=>{e?r.current?.close():r.current?.showModal()}),[e]),ie((()=>{const e=r.current
|
|
157
157
|
;return e?.addEventListener("cancel",t),()=>{e?.removeEventListener("cancel",t)}}),[t]),Pe("dialog",{ref:r,className:"relative w-full h-full backdrop:bg-black/50","data-testid":o,"aria-label":i,children:n})}function Hr({closed:e,children:t,...n}){return Pe("div",{...n,className:Re("fixed z-max top-0 left-0 right-0 bottom-0 p-3 bg-black/50",{hidden:e}),children:Pe("div",{className:"relative w-full h-full",children:t})})}function Vr({document_:e=document,...t}){return Pe(ae((()=>function(e){return"function"==typeof e.createElement("dialog").showModal}(e)?Fr:Hr),[e]),{...t})}function Ur({config:e,groupId:t}){return Pe("iframe",{title:"Hypothesis annotation notebook",className:"h-full w-full border-0",allow:"fullscreen; clipboard-write",src:Br(e.notebookAppUrl,{...Dr(e.notebookAppUrl,e),group:t})})}function qr({eventBus:e,config:t}){const[n,o]=oe(0),[i,r]=oe(!0),[s,a]=oe(null),l=se(""),c=se(null);ie((()=>(l.current=document.body.style.overflow,()=>{document.body.style.overflow=l.current})),[]),ie((()=>{
|
|
158
158
|
document.body.style.overflow=i?l.current:"hidden"}),[i]),ie((()=>{const t=e.createEmitter();return t.subscribe("openNotebook",(e=>{r(!1),o((e=>e+1)),a(e)})),c.current=t,()=>{t.destroy()}}),[e]);const d=le((()=>{r(!0),c.current?.publish("closeNotebook")}),[]);return null===s?null:Pe(Vr,{closed:i,onClose:d,"data-testid":"notebook-outer","aria-label":"Hypothesis notebook",children:[Pe("div",{className:"absolute right-0 m-3",children:Pe(kt,{title:"Close notebook",onClick:d,variant:"dark",classes:Re("!bg-transparent enabled:hover:!bg-grey-3"),"data-testid":"close-button",children:Pe(He,{className:"w-4 h-4"})})}),Pe(Ur,{config:t,groupId:s},n)]})}class zr{constructor(e,t,n){this._container=new oo("notebook",(()=>Pe(qr,{eventBus:t,config:n}))),e.append(this._container.element),this._container.render()}destroy(){this._container.destroy()}}function $r({eventBus:e,config:t}){const[n,o]=oe(!0),i=se(null);ie((()=>{const t=e.createEmitter();return t.subscribe("openProfile",(()=>{o(!1)})),i.current=t,()=>{t.destroy()}
|
|
159
159
|
}),[e]);const r=()=>{o(!0),i.current?.publish("closeProfile")};return n?null:Pe(Vr,{closed:n,onClose:r,"data-testid":"profile-outer","aria-label":"Hypothesis profile",children:[Pe("div",{className:"absolute right-0 m-3",children:Pe(kt,{title:"Close profile dialog",onClick:r,variant:"dark",classes:Re("!bg-transparent enabled:hover:!bg-grey-3"),children:Pe(He,{className:"w-4 h-4"})})}),Pe("iframe",{title:"Hypothesis profile",className:"h-full w-full border-0",src:t.profileAppUrl})]})}class Wr{constructor(e,t,n){this._container=new oo("profile",(()=>Pe($r,{eventBus:t,config:n}))),e.append(this._container.element),this._container.render()}destroy(){this._container.destroy()}}function jr({above:e,below:t,buckets:n,onFocusAnnotations:o,onScrollToAnnotation:i,onSelectAnnotations:r}){const s=e.anchors.length>0,a=t.anchors.length>0,l=e=>e.anchors.map((e=>e.tag));return Pe("ul",{className:"relative",children:[s&&Pe("li",{className:"absolute right-0 pointer-events-auto mt-[-11px]",style:{top:e.position},children:Pe(tn,{
|