hypothesis 1.1197.0 → 1.1199.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";function s(s){s.setAttribute("data-hypothesis-asset","")}function t(t,e){var n=t.createElement("link");n.rel="stylesheet",n.type="text/css",n.href=e,s(n),t.head.appendChild(n)}function e(t,e){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},r=n.esModule,o=void 0===r||r,a=n.forceReload,i=void 0!==a&&a,l=t.createElement("script");o&&(l.type="module"),i&&(e+="#ts=".concat(Date.now())),l.src=e,l.async=!1,s(l),t.head.appendChild(l)}function n(t,e,n,r){var o=t.createElement("link");o.rel=e,o.href=r,o.type="application/annotator+".concat(n),s(o),t.head.appendChild(o)}function r(t,e,n){var r=t.createElement("link");r.rel="preload",r.as=e,r.href=n,"fetch"===e&&(r.crossOrigin="anonymous"),s(r),t.head.appendChild(r)}function o(s,t){return s.assetRoot+"build/"+s.manifest[t]}function a(s){var t=s.match(/(https?):\/\/([^:/]+)/);return t?{protocol:t[1],hostname:t[2]}:null}function i(){var s=arguments.length>0&&void 0!==arguments[0]?arguments[0]:document,t=s.currentScript;return t?a(t.src):null}function l(s){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:document;if(-1===s.indexOf("{"))return s;var e=i(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)}var c={"scripts/annotator.bundle.js":"scripts/annotator.bundle.js?
|
|
1
|
+
!function(){"use strict";function s(s){s.setAttribute("data-hypothesis-asset","")}function t(t,e){var n=t.createElement("link");n.rel="stylesheet",n.type="text/css",n.href=e,s(n),t.head.appendChild(n)}function e(t,e){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},r=n.esModule,o=void 0===r||r,a=n.forceReload,i=void 0!==a&&a,l=t.createElement("script");o&&(l.type="module"),i&&(e+="#ts=".concat(Date.now())),l.src=e,l.async=!1,s(l),t.head.appendChild(l)}function n(t,e,n,r){var o=t.createElement("link");o.rel=e,o.href=r,o.type="application/annotator+".concat(n),s(o),t.head.appendChild(o)}function r(t,e,n){var r=t.createElement("link");r.rel="preload",r.as=e,r.href=n,"fetch"===e&&(r.crossOrigin="anonymous"),s(r),t.head.appendChild(r)}function o(s,t){return s.assetRoot+"build/"+s.manifest[t]}function a(s){var t=s.match(/(https?):\/\/([^:/]+)/);return t?{protocol:t[1],hostname:t[2]}:null}function i(){var s=arguments.length>0&&void 0!==arguments[0]?arguments[0]:document,t=s.currentScript;return t?a(t.src):null}function l(s){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:document;if(-1===s.indexOf("{"))return s;var e=i(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)}var c={"scripts/annotator.bundle.js":"scripts/annotator.bundle.js?837db8","styles/annotator.css.map":"styles/annotator.css.map?fc23a9","styles/highlights.css":"styles/highlights.css?6b4ebd","styles/highlights.css.map":"styles/highlights.css.map?241350","styles/katex.min.css":"styles/katex.min.css?e9b69c","styles/annotator.css":"styles/annotator.css?06256b","styles/katex.min.css.map":"styles/katex.min.css.map?42d80c","styles/pdfjs-overrides.css":"styles/pdfjs-overrides.css?c95edf","styles/pdfjs-overrides.css.map":"styles/pdfjs-overrides.css.map?1d8ac6","styles/sidebar.css.map":"styles/sidebar.css.map?ed8195","styles/sidebar.css":"styles/sidebar.css?4d73b9","styles/ui-playground.css.map":"styles/ui-playground.css.map?564f8e","styles/ui-playground.css":"styles/ui-playground.css?9d243f","scripts/sidebar.bundle.js":"scripts/sidebar.bundle.js?fbb6fc","scripts/annotator.bundle.js.map":"scripts/annotator.bundle.js.map?dd5e71","scripts/ui-playground.bundle.js":"scripts/ui-playground.bundle.js?99ff43","scripts/ui-playground.bundle.js.map":"scripts/ui-playground.bundle.js.map?cfed99","scripts/sidebar.bundle.js.map":"scripts/sidebar.bundle.js.map?45ddc9"};if(function(){var s=[function(){return Object.fromEntries([])},function(){return new URL(document.location.href)},function(){return new Request("https://hypothes.is")},function(){return Element.prototype.attachShadow},function(){return CSS.supports("display: grid")},function(){return document.evaluate("/html/body",document,null,XPathResult.ANY_TYPE,null),!0}];try{return s.every((function(s){return s()}))}catch(s){return!1}}()){var p=function(s){for(var t={},e=s.querySelectorAll("script.js-hypothesis-config"),n=0;n<e.length;n++){var r=void 0;try{r=JSON.parse(e[n].textContent||"")}catch(s){console.warn("Could not parse settings from js-hypothesis-config tags",s),r={}}Object.assign(t,r)}return t}(document),d=l(p.assetRoot||"https://cdn.hypothes.is/hypothesis/1.1199.0/");if(document.querySelector("hypothesis-app")){!function(s,n){r(s,"fetch",n.apiUrl),r(s,"fetch",n.apiUrl+"links");for(var a=0,i=["scripts/sidebar.bundle.js"];a<i.length;a++)e(s,o(n,i[a]),{esModule:!0});for(var l=0,c=["styles/katex.min.css","styles/sidebar.css"];l<c.length;l++)t(s,o(n,c[l]))}(document,{assetRoot:d,manifest:c,apiUrl:p.apiUrl})}else{var u=p,h=l(u.notebookAppUrl||"https://hypothes.is/notebook"),y=l(u.sidebarAppUrl||"https://hypothes.is/app.html");!function(s,a){if(!s.querySelector('link[type="application/annotator+html"]')){n(s,"sidebar","html",a.sidebarAppUrl),n(s,"notebook","html",a.notebookAppUrl),r(s,"style",o(a,"styles/annotator.css")),n(s,"hypothesis-client","javascript",a.assetRoot+"build/boot.js");for(var i=0,l=["scripts/annotator.bundle.js"];i<l.length;i++)e(s,o(a,l[i]),{esModule:!1});var c=[];void 0!==window.PDFViewerApplication&&c.push("styles/pdfjs-overrides.css"),c.push("styles/highlights.css");for(var p=0,d=c;p<d.length;p++)t(s,o(a,d[p]))}}(document,{assetRoot:d,manifest:c,notebookAppUrl:h,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,20 +1,20 @@
|
|
|
1
1
|
{
|
|
2
|
-
"scripts/annotator.bundle.js": "scripts/annotator.bundle.js?
|
|
3
|
-
"styles/annotator.css": "styles/annotator.css?06256b",
|
|
2
|
+
"scripts/annotator.bundle.js": "scripts/annotator.bundle.js?837db8",
|
|
4
3
|
"styles/annotator.css.map": "styles/annotator.css.map?fc23a9",
|
|
5
4
|
"styles/highlights.css": "styles/highlights.css?6b4ebd",
|
|
6
5
|
"styles/highlights.css.map": "styles/highlights.css.map?241350",
|
|
7
6
|
"styles/katex.min.css": "styles/katex.min.css?e9b69c",
|
|
7
|
+
"styles/annotator.css": "styles/annotator.css?06256b",
|
|
8
8
|
"styles/katex.min.css.map": "styles/katex.min.css.map?42d80c",
|
|
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": "styles/sidebar.css?4d73b9",
|
|
12
11
|
"styles/sidebar.css.map": "styles/sidebar.css.map?ed8195",
|
|
13
|
-
"styles/
|
|
12
|
+
"styles/sidebar.css": "styles/sidebar.css?4d73b9",
|
|
14
13
|
"styles/ui-playground.css.map": "styles/ui-playground.css.map?564f8e",
|
|
15
|
-
"
|
|
14
|
+
"styles/ui-playground.css": "styles/ui-playground.css?9d243f",
|
|
15
|
+
"scripts/sidebar.bundle.js": "scripts/sidebar.bundle.js?fbb6fc",
|
|
16
|
+
"scripts/annotator.bundle.js.map": "scripts/annotator.bundle.js.map?dd5e71",
|
|
16
17
|
"scripts/ui-playground.bundle.js": "scripts/ui-playground.bundle.js?99ff43",
|
|
17
|
-
"scripts/sidebar.bundle.js": "scripts/sidebar.bundle.js?38e79a",
|
|
18
18
|
"scripts/ui-playground.bundle.js.map": "scripts/ui-playground.bundle.js.map?cfed99",
|
|
19
|
-
"scripts/sidebar.bundle.js.map": "scripts/sidebar.bundle.js.map?
|
|
19
|
+
"scripts/sidebar.bundle.js.map": "scripts/sidebar.bundle.js.map?45ddc9"
|
|
20
20
|
}
|
|
@@ -95,72 +95,72 @@ if(t instanceof RangeError)return null;throw t}}canStyleClusteredHighlights(){re
|
|
|
95
95
|
var i,o,r,s,a,l,c=0,h=!1,u=!1,d=!0;if("function"!=typeof t)throw new TypeError("Expected a function");function f(e){var n=i,r=o;return i=o=void 0,c=e,s=t.apply(r,n)}function p(t){return c=t,a=setTimeout(m,e),h?f(t):s}function g(t){var n=t-l;return void 0===l||n>=e||n<0||u&&t-c>=r}function m(){var t=Ai();if(g(t))return _(t);a=setTimeout(m,function(t){var n=e-(t-l);return u?ki(n,r-(t-c)):n}(t))}function _(t){return a=void 0,d&&i?f(t):(i=o=void 0,s)}function v(){var t=Ai(),n=g(t);if(i=arguments,o=this,l=t,n){if(void 0===a)return p(l);if(u)return a=setTimeout(m,e),f(l)}return void 0===a&&(a=setTimeout(m,e)),s}return e=Ri(e)||0,Ti(n)&&(h=!!n.leading,r=(u="maxWait"in n)?Ni(Ri(n.maxWait)||0,e):r,d="trailing"in n?!!n.trailing:d),v.cancel=function(){void 0!==a&&clearTimeout(a),c=0,i=l=o=a=void 0},v.flush=function(){return void 0===a?s:_(Ai())},v};function Pi(t,e,n,i=0){let o=i;for(;o<t.length&&e>0;)n(t[o])&&--e,++o;return o}function Oi(t,e,n,i){let o=0;for(let r=n;r<i;r++)e(t[r])&&++o;return o}function Mi(t,e,n,i,o){
|
|
96
96
|
const r=Oi(t,o,0,n),s=Oi(t,o,n,i);let a=Pi(e,r,o);for(;a<e.length&&!o(e[a]);)++a;return[a,Pi(e,s,o,a)]}const Ii=0,Bi=3,Fi=new Map,Di=new Map;function Hi(t,e){return`${t}:${e}`}function Vi(t){var e;const n="closest"in t?t:t.parentElement;return null!==(e=null==n?void 0:n.closest(".textLayer"))&&void 0!==e?e:null}function qi(){return PDFViewerApplication.pdfViewer}async function Ui(t){const e=qi();let n=e.getPageView(t);return n&&n.pdfPage||(n=await new Promise((n=>{const i=()=>{e.eventBus?e.eventBus.off("pagesloaded",i):document.removeEventListener("pagesloaded",i),n(e.getPageView(t))};e.eventBus?e.eventBus.on("pagesloaded",i):document.addEventListener("pagesloaded",i)}))),n}function zi(t){const e=Fi.get(t);if(e)return e;const n=(async()=>{const e=await Ui(t);return(await e.pdfPage.getTextContent({normalizeWhitespace:!0})).items.map((t=>t.str)).join("")})();return Fi.set(t,n),n}async function Wi(t){const e=qi();let n=0,i=0,o="";for(let r=0;r<e.pagesCount;r++)if(o=await zi(r),n=i,i+=o.length,i>=t)return{
|
|
97
97
|
index:r,offset:n,text:o};return{index:e.pagesCount-1,offset:n,text:o}}function ji(t){switch(t){case" ":case"\f":case"\n":case"\r":case"\t":case"\v":case" ":return!0;default:return!1}}const $i=t=>!ji(t);async function Xi(t,e,n){const[i,o]=await Promise.all([Ui(t),zi(t)]);if(i.renderingState===Bi&&i.textLayer&&i.textLayer.renderingDone){var r;const t=null!==(r=i.textLayer.textLayerDiv)&&void 0!==r?r:i.textLayer.div;if(!t)throw new Error("Unable to find PDF.js text layer root");const s=t.textContent,[a,l]=Mi(o,s,e,n,$i);Yi(s.slice(a,l))!==Yi(o.slice(e,n))&&yn("Text layer text does not match page text. Highlights will be mis-aligned.");const c=new je(t,a),h=new je(t,l);return new $e(c,h).toRange()}const s=function(t){let e=t.querySelector(Xe);return e||(e=document.createElement("span"),e.classList.add("annotator-placeholder"),e.textContent="Loading annotations...",t.appendChild(e),e)}(i.div),a=document.createRange();return a.setStartBefore(s),a.setEndAfter(s),a}function Yi(t){let e="";for(let n=0;n<t.length;n++){
|
|
98
|
-
const i=t[n];ji(i)||(e+=i)}return e}async function Zi(t,e){const n=e.find((t=>"TextQuoteSelector"===t.type));if(!n)throw new Error("No quote selector found");const i=e.find((t=>"TextPositionSelector"===t.type));if(i){try{const{index:t,offset:e,text:o}=await Wi(i.start),r=i.start-e,s=i.end-e,a=o.substring(r,s);if(n.exact!==a)throw new Error("quote mismatch");return await Xi(t,r,s)}catch{}try{const t=Hi(n.exact,i.start),e=Di.get(t);if(e){const{pageIndex:t,anchor:n}=e;return await Xi(t,n.start,n.end)}}catch{}}return async function(t,e){const n=qi().pagesCount,i=Array(n).fill(0).map(((t,e)=>e));let o,r;if(e){const{index:t,offset:n}=await Wi(e);o=t,r=e-n,i.sort(((e,n)=>Math.abs(e-t)-Math.abs(n-t)))}const s=void 0!==t.prefix?Yi(t.prefix):void 0,a=void 0!==t.suffix?Yi(t.suffix):void 0,l=Yi(t.exact);let c;for(
|
|
98
|
+
const i=t[n];ji(i)||(e+=i)}return e}async function Zi(t,e){const n=e.find((t=>"TextQuoteSelector"===t.type));if(!n)throw new Error("No quote selector found");const i=e.find((t=>"TextPositionSelector"===t.type));if(i){try{const{index:t,offset:e,text:o}=await Wi(i.start),r=i.start-e,s=i.end-e,a=o.substring(r,s);if(n.exact!==a)throw new Error("quote mismatch");return await Xi(t,r,s)}catch{}try{const t=Hi(n.exact,i.start),e=Di.get(t);if(e){const{pageIndex:t,anchor:n}=e;return await Xi(t,n.start,n.end)}}catch{}}return async function(t,e){const n=qi().pagesCount,i=Array(n).fill(0).map(((t,e)=>e));let o,r;if(e){const{index:t,offset:n}=await Wi(e);o=t,r=e-n,i.sort(((e,n)=>Math.abs(e-t)-Math.abs(n-t)))}const s=void 0!==t.prefix?Yi(t.prefix):void 0,a=void 0!==t.suffix?Yi(t.suffix):void 0,l=Yi(t.exact);let c;for(const t of i){const e=await zi(t),n=Yi(e);let i;void 0!==o&&void 0!==r&&(t<o?i=n.length:t===o?[i]=Mi(e,n,r,r,$i):i=0);const h=Tn(n,l,{prefix:s,suffix:a,hint:i});if(h&&(!c||h.score>c.match.score)){
|
|
99
99
|
const[i,o]=Mi(n,e,h.start,h.end,$i);c={page:t,match:{start:i,end:o,score:h.score}};const r=n.slice(h.start,h.end)===l,u=void 0!==s&&n.slice(Math.max(0,h.start-s.length),h.start)===s,d=void 0!==a&&n.slice(h.end,a.length)===a,f=void 0!==s||void 0!==a;if(r&&(u||d||!f))break}}if(c){const{page:n,match:i}=c;if(e){const o=Hi(t.exact,e);Di.set(o,{pageIndex:n,anchor:i})}return Xi(n,i.start,i.end)}throw new Error("Quote not found")}(n,null==i?void 0:i.start)}function Gi(t){try{t=$e.fromRange(t).toRange()}catch{throw new Error("Selection does not contain text")}const e=Vi(t.startContainer),n=Vi(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]}async function Ki(t,e){const[n,i]=Gi(e),o=je.fromPoint(n.startContainer,n.startOffset).relativeTo(i),r=je.fromPoint(n.endContainer,n.endOffset).relativeTo(i),s=function(t){let e=0;for(;t.previousSibling;)++e,t=t.previousSibling;return e
|
|
100
100
|
}(i.parentNode),a=await async function(t){if(t>=qi().pagesCount)throw new Error("Invalid page index");let e=0;for(let n=0;n<t;n++)e+=(await zi(n)).length;return e}(s);return[{type:"TextPositionSelector",start:a+o.offset,end:a+r.offset},Bn.fromRange(t,n).toSelector()]}function Qi({children:t}){return ht("div",{className:"flex flex-col",children:t})}function Ji({info:t}){let e=t.item.title;return t.item.subtitle&&(e+=`: ${t.item.subtitle}`),ht("div",{className:h("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:[ht("div",{"data-testid":"content-logo",children:t.logo&&ht(Ae,{href:t.logo.link,target:"_blank","data-testid":"logo-link",children:ht("img",{alt:t.logo.title,src:t.logo.logo,"data-testid":"logo-image"})})}),ht("div",{className:h("hidden","2xl:block 2xl:whitespace-nowrap 2xl:overflow-hidden 2xl:text-ellipsis","font-semibold"),
|
|
101
101
|
"data-testid":"content-container-info",title:t.container.title,children:t.container.title}),ht("div",{className:h("flex justify-center items-center gap-x-2"),"data-testid":"content-item-info",children:[ht("div",{className:h("hidden","2xl:block 2xl:grow")}),t.links.previousItem&&ht(_,{children:[ht(Ae,{classes:"flex gap-x-1 items-center text-annotator-sm whitespace-nowrap",title:"Open previous item",href:t.links.previousItem,underline:"always",target:"_blank","data-testid":"content-previous-link",children:[ht(le,{className:"w-em h-em"}),ht("span",{children:"Previous"})]}),ht("div",{className:"text-annotator-sm",children:"|"})]}),ht("div",{className:h("min-w-0 whitespace-nowrap overflow-hidden text-ellipsis shrink font-medium"),children:ht(ke,{title:e,href:t.links.currentItem,"data-testid":"content-item-link",target:"_blank",unstyled:!0,children:e})}),t.links.nextItem&&ht(_,{children:[ht("div",{className:"text-annotator-sm",children:"|"}),ht(Ae,{title:"Open next item",
|
|
102
102
|
classes:"flex gap-x-1 items-center text-annotator-sm whitespace-nowrap",href:t.links.nextItem,underline:"always",target:"_blank","data-testid":"content-next-link",children:[ht("span",{children:"Next"}),ht(he,{className:"w-em h-em"})]})]})]})]})}function to(){return ht("div",{className:"bg-white",role:"alert",children:ht("div",{className:h("flex items-center gap-x-2","border border-yellow-notice bg-yellow-notice/10 text-annotator-base"),children:[ht("div",{className:"bg-yellow-notice text-white p-2",children:ht(yt,{name:"caution",classes:"text-annotator-xl"})}),ht("div",{children:[ht("strong",{children:"This PDF does not contain selectable text:"})," ",ht(bt,{target:"_blank",href:"https://web.hypothes.is/help/how-to-ocr-optimize-pdfs/",children:"Learn how to fix this"})," ","in order to annotate with Hypothesis."]})]})})}class eo{constructor(t){this._loaded=function(t){return t.initializedPromise?t.initializedPromise:t.initialized?Promise.resolve():new Promise((e=>{const n=setInterval((()=>{
|
|
103
103
|
t.initialized&&(clearTimeout(n),e())}),5)}))}(t).then((()=>t.downloadComplete?t:new Promise((e=>{const n=()=>{t.eventBus?(t.eventBus.off("documentload",n),t.eventBus.off("documentloaded",n)):window.removeEventListener("documentload",n),e(t)};t.eventBus?(t.eventBus.on("documentloaded",n),t.eventBus.on("documentload",n)):window.addEventListener("documentload",n)}))))}getUri(){return this._loaded.then((t=>{let e=oo(t);return e||(e=io(no(t))),e}))}async getMetadata(){const t=await this._loaded,{info:e,contentDispositionFilename:n,metadata:i}=await t.pdfDocument.getMetadata(),o=no(t),r=oo(t);let s;s=null!=i&&i.has("dc:title")&&"Untitled"!==i.get("dc:title")?i.get("dc:title"):null!=e&&e.Title?e.Title:n||(r?function(t){const e=new URL(t).pathname.split("/");return e[e.length-1]}(r):"");const a=[{href:io(o)}];return r&&a.push({href:r}),{title:s,link:a,documentFingerprint:o}}}function no(t){return Array.isArray(t.pdfDocument.fingerprints)?t.pdfDocument.fingerprints[0]:t.pdfDocument.fingerprint}function io(t){
|
|
104
|
-
return`urn:x-pdf:${t}`}function oo(t){if(!t.url)return null;const e=Vn(t.url);return 0!==e.indexOf("file://")?e:null}function ro(t){var e;const n=null===(e=t.highlights)||void 0===e?void 0:e[0];return n&&Ye(n)}function so(t){return new Promise((e=>setTimeout(e,t)))}class ao extends Pt{constructor(t,e={}){var n,i,o;super(),this.
|
|
105
|
-
this._updateAnnotationLayerVisibility=()=>{const t=r.getSelection();this.
|
|
106
|
-
const t=qi();let e=!1;for(let n=0;n<t.pagesCount;n++)if((await zi(n)).trim().length>0){e=!0;break}return e}();this._updateBannerState({noTextWarning:!t})}catch(t){console.warn("Unable to check for text in PDF:",t)}}_updateBannerState(t){this._bannerState={...this._bannerState,...t};const e=document.querySelector("#outerContainer");var n;if(!(this._bannerState.contentInfo||this._bannerState.noTextWarning))return null===(n=this._banner)||void 0===n||n.remove(),this._banner=null,void(e.style.height="");this._banner||(this._banner=document.createElement("hypothesis-banner"),
|
|
107
|
-
;if(null!=e&&null!==(n=e.textLayer)&&void 0!==n&&n.renderingDone)switch(e.renderingState){case Ii:e.textLayer=null;break;case Bi:i=e.div,o=void 0,null===(o=i.querySelector(Xe))||void 0===o||o.remove()}}var i,o;for(
|
|
108
|
-
const t=await this._waitForAnnotationToBeAnchored(e,this._reanchoringMaxWait);if(!t)return;const n=this._anchorOffset(t);if(null===n)return;await gi(this.contentContainer(),n)}}async _waitForAnnotationToBeAnchored(t,e){var n;const i=Date.now();let o;do{o=this.
|
|
109
|
-
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 ho(t),this._isDisconnected)return;t.contentWindow.addEventListener("unload",(()=>{this._removeFrame(t)})),this._onFrameAdded(t)}catch(e){console.warn(`Unable to inject the Hypothesis client (from '${document.location.href}' into a cross-origin frame '${t.src}')`)}}_removeFrame(t){
|
|
110
|
-
;const r=new WeakSet,s=()=>{clearTimeout(i),i=void 0},a=()=>{const n=t.contentDocument;if(n){if(!r.has(n)){if(r.add(n),s(),!function(t){var e;return"about:blank"===(null===(e=t.contentDocument)||void 0===e?void 0:e.location.href)&&t.hasAttribute("src")&&"about:blank"!==t.src}(t)){"interactive"===n.readyState||"complete"===n.readyState?e(null,n):n.addEventListener("DOMContentLoaded",(()=>e(null,n)))}var i;t.contentDocument&&(null===(i=t.contentWindow)||void 0===i||i.addEventListener("unload",o))}}else{s();const n=t.isConnected?"Frame is cross-origin":"Frame is disconnected";e(new Error(n))}}
|
|
111
|
-
;const i=t.parentNode,o=document.createElement("hypothesis-text-layer");i.insertBefore(o,t.nextSibling),i.style.position="relative",o.style.position="absolute",o.style.top="0",o.style.left="0",o.style.color="transparent",o.style.textAlign="left",o.style.mixBlendMode="multiply";const r="sans-serif";o.style.fontSize="16px",o.style.fontFamily=r;const s=document.createElement("canvas").getContext("2d");s.font="16px sans-serif";const a=(t,e,n="px")=>`calc(var(--${t}-scale) * ${e}${n})`,l=function(t,e){const n=[];let i={text:"",rect:new DOMRect};const o=()=>{i.text.length>0&&(n.push(i),i={text:"",
|
|
112
|
-
s.rect=Xn(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=Yn(e.rect),i=Yn(t.rect).y-n.y;(!$n(e.rect,t.rect)||jn(e.rect,t.rect)||i<0||i>4*t.rect.height)&&h()}c.lines.push(t),c.rect=Xn(c.rect,t.rect)}return h(),l}(e,n);for(const t of l){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 i of t.lines){
|
|
113
|
-
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),i=a("x",t.rect.width/n.width,""),l=a("y",t.rect.height/16,"");e.style.transform=`scale(${i}, ${l})`,o.append(e)}e.append(o)}o.append(e)}const c=()=>{const{width:e,height:n}=t.getBoundingClientRect();o.style.width=e+"px",o.style.height=n+"px",o.style.setProperty("--x-scale",`${e}`),o.style.setProperty("--y-scale",`${n}`)};c(),this.container=o,this._updateTextLayerSize=Li(c,{maxWait:50}),
|
|
114
|
-
null===(t=this._imageSizeObserver)||void 0===t||t.disconnect()}}class po{constructor(t,e){this._config=e,this._frameObserver=new co(t,(t=>go(t,e)),(()=>{}))}destroy(){this._frameObserver.disconnect()}}async function go(t,e,n){if(null!==t.contentDocument.querySelector("script.js-hypothesis-config"))return;await ho(t);const{assetRoot:i,notebookAppUrl:o,sidebarAppUrl:r}=Wt(document),s={...e,assetRoot:i,notebookAppUrl:o,sidebarAppUrl:r,subFrameIdentifier:null!=n?n:Et(10)},a=document.createElement("script");a.className="js-hypothesis-config",a.setAttribute("data-remove-on-unload",""),
|
|
115
|
-
constructor(t){Ct(this,"_frameObserver",void 0);const e=mo();if(!e)throw new Error("Book container element not found");const n=new WeakSet,i=e.shadowRoot,o=()=>{const e=i.querySelector("iframe");e&&!n.has(e)&&(n.add(e),uo(e,((n,i)=>{if(n)return;const o=i.body;o&&!o.querySelector("#page-content")&&go(e,t,"vitalsource-content")})))};o(),this._frameObserver=new MutationObserver(o),this._frameObserver.observe(i,{childList:!0,subtree:!0})}destroy(){this._frameObserver.disconnect()}}function yo(){return document.querySelector("img#pbk-page")}class bo extends Pt{constructor(t=document.body,e){
|
|
116
|
-
}));const o=new wn;o.update({html_side_by_side:!0}),this._htmlIntegration=new mi({container:t,features:o}),this._listeners=new xt;const r=["mouseup","mousedown","mouseout"];for(const t of r)this._listeners.add(document.documentElement,t,(t=>{t.stopPropagation()}));const s=window.frameElement;s&&function(t){if("no"!==t.getAttribute("scrolling"))return;const e=document.createElement("style");e.textContent="iframe { height: 100% !important; }",t.insertAdjacentElement("beforebegin",e);const n=()=>t.removeAttribute("scrolling");n(),new MutationObserver(n).observe(t,{attributes:!0})}(s)
|
|
117
|
-
this._htmlIntegration.destroy()}anchor(t,e){return this._htmlIntegration.anchor(t,e)}async describe(t,e){const n=this._htmlIntegration.describe(t,e),{cfi:i,index:o,page:r,title:s,url:a}=await this._getPageInfo(!0),l=[{type:"EPUBContentSelector",cfi:i,url:a,title:s}];return"pbk"===this._bookElement.getBookInfo().format&&l.push({type:"PageSelector",index:o,label:r}),n.push(...l),n}contentContainer(){return this._htmlIntegration.contentContainer()}fitSideBySide(t){const e=yo();if(e&&this._textLayer){const n=e.parentElement,i=this._textLayer,o=window.innerWidth-t.width;return ei((()=>{
|
|
118
|
-
;const n=null===(e=t.target[0].selector)||void 0===e?void 0:e.find((t=>"EPUBContentSelector"===t.type));if(null!=n&&n.cfi)this._bookElement.goToCfi(n.cfi);else{if(null==n||!n.url)throw new Error("No segment information available");this._bookElement.goToURL(function(t){const e=new URL(t,document.baseURI);return e.pathname+e.search}(n.url))}}persistFrame(){return!0}async _getPageInfo(t){const[e,n]=await Promise.all([this._bookElement.getCurrentPage(),t?this._bookElement.getTOC():void 0]);let i;if(n){var o;i=e.chapterTitle;const t=lo(e.cfi),r=null===(o=n.data)||void 0===o?void 0:o.find((e=>lo(e.cfi)===t));r&&(i=r.title)}return{cfi:e.cfi,index:e.index,
|
|
119
|
-
t.toString()}async scrollToAnchor(t){return this._htmlIntegration.scrollToAnchor(t)}_bookIsSingleDocument(){return this._features.flagEnabled("book_as_single_document")}waitForFeatureFlags(){return!0}}function wo(t){if(
|
|
120
|
-
this._cancelPendingCallback()}_cancelPendingCallback(){this._pendingCallback&&(clearTimeout(this._pendingCallback),this._pendingCallback=null)}}function So(){const t=function(t,e){const n=new Set,i=new Set;return Ke(t,(t=>{let o=t;for(;o&&!n.has(o);){n.add(o);const t=e(o);null!=t&&i.add(t),o=o.parentNode}})),[...i]}(window.getSelection().getRangeAt(0),(t=>{var e;return null===(e=t._annotation)||void 0===e?void 0:e.$tag}));return t}function Eo(t){const e=function(t){let e=t.nodeType===Node.ELEMENT_NODE?t:t.parentElement;const n=[];for(;e;)e.classList.contains("hypothesis-highlight")&&n.push(e),e=e.parentElement;return n
|
|
121
|
-
Ct(this,"selectedRanges",void 0),Ct(this,"anchors",void 0),Ct(this,"features",void 0),Ct(this,"_featureFlagsReceived",void 0),Ct(this,"_adder",void 0),Ct(this,"_clusterToolbar",void 0),Ct(this,"_hostFrame",void 0),Ct(this,"_highlightsVisible",void 0),Ct(this,"_isAdderVisible",void 0),Ct(this,"_informHostOnNextSelectionClear",void 0),Ct(this,"_selectionObserver",void 0),Ct(this,"_annotations",void 0),Ct(this,"_frameIdentifier",void 0),Ct(this,"_portFinder",void 0),Ct(this,"_integration",void 0),Ct(this,"_hostRPC",void 0),Ct(this,"_sidebarRPC",void 0),Ct(this,"_bucketBarClient",void 0),Ct(this,"_sideBySideActive",void 0),Ct(this,"_listeners",void 0),
|
|
122
|
-
focusInSidebar:!0})}),this._selectionObserver=new xo((t=>{t?this._onSelection(t):this._onClearSelection()})),this.anchors=[],this._annotations=new Set,this._frameIdentifier=e.subFrameIdentifier||null,this._portFinder=new At({hostFrame:this._hostFrame,source:"guest",sourceId:null!==(i=this._frameIdentifier)&&void 0!==i?i:void 0}),this.features=new wn,this._featureFlagsReceived=new Promise((t=>{this.features.on("flagsChanged",t)})),this._integration=wo(this),this._integration.on("uriChanged",(()=>this._sendDocumentInfo())),e.contentInfoBanner)&&(null===(s=(a=this._integration).showContentInfo)||void 0===s||s.call(a,e.contentInfoBanner))
|
|
123
|
-
this._sideBySideActive=!1,this._listeners=new xt,this._setupElementEvents(),this._hoveredAnnotations=new Set}_setupElementEvents(){const t=t=>{this._sideBySideActive||Eo(t).length||this._sidebarRPC.call("closeSidebar")};this._listeners.add(this.element,"mouseup",(t=>{const{target:e,metaKey:n,ctrlKey:i}=t,o=Eo(e);if(o.length&&this._highlightsVisible){const t=n||i;this.selectAnnotations(o,{toggle:t})}})),this._listeners.add(this.element,"mousedown",(({target:e})=>{t(e)})),this._listeners.add(this.element,"touchstart",(({target:e})=>{t(e)})),this._listeners.add(this.element,"mouseover",(({target:t})=>{const e=Eo(t)
|
|
124
|
-
;const[r,s,a]=await Promise.all([this._integration.uri(),this._integration.getMetadata(),null===(t=(e=this._integration).segmentInfo)||void 0===t?void 0:t.call(e)]);return{uri:Vn(r),metadata:s,segmentInfo:a,persistent:null!==(n=null===(i=(o=this._integration).persistFrame)||void 0===i?void 0:i.call(o))&&void 0!==n&&n}}async _sendDocumentInfo(){var t,e;null!==(t=(e=this._integration).waitForFeatureFlags)&&void 0!==t&&t.call(e)&&await this._featureFlagsReceived;const n=await this.getDocumentInfo();this._sidebarRPC.call("documentInfoChanged",n)}_repositionAdder(){var t;if(!1===this._isAdderVisible)return
|
|
125
|
-
this._hostRPC.on("scrollToClosestOffScreenAnchor",((t,e)=>this._scrollToClosestOffScreenAnchor(t,e))),this._hostRPC.on("selectAnnotations",((t,e)=>this.selectAnnotations(t,{toggle:e}))),this._hostRPC.on("sidebarLayoutChanged",(e=>{var n,i;((n=window)===(i=t)||n.parent===i&&n.frameElement&&n.frameElement.getBoundingClientRect().width/n.parent.innerWidth>=.8)&&this.fitSideBySide(e)})),this._hostRPC.on("close",(()=>this.emit("hostDisconnected")));const e=await this._portFinder.discover("host");this._hostRPC.connect(e)}async _connectSidebar(){this._sidebarRPC.on("featureFlagsUpdated",(t=>this.features.update(t))),
|
|
126
|
-
this._sidebarRPC.on("setHighlightsVisible",(t=>{this.setHighlightsVisible(t,!1)})),this._sidebarRPC.on("deleteAnnotation",(t=>this.detach(t))),this._sidebarRPC.on("loadAnnotations",(t=>t.forEach((t=>this.anchor(t))))),this._sidebarRPC.on("showContentInfo",(t=>{var e,n;return null===(e=(n=this._integration).showContentInfo)||void 0===e?void 0:e.call(n,t)})),this._sidebarRPC.on("navigateToSegment",(t=>{var e,n;return null===(e=(n=this._integration).navigateToSegment)||void 0===e?void 0:e.call(n,t)})),this._portFinder.discover("sidebar").then((t=>{this._sidebarRPC.connect(t)})),this._sendDocumentInfo()}destroy(){var t
|
|
127
|
-
;const n=No(t);if(!n)return;const i=en(n,null===(e=t.annotation)||void 0===e?void 0:e.$cluster);i.forEach((e=>{e._annotation=t.annotation})),t.highlights=i,this._hoveredAnnotations.has(t.annotation.$tag)&&rn(i,!0)};this.detach(t.$tag,!1),this._annotations.add(t.$tag),t.target||(t.target=[]);const n=await Promise.all(t.target.map((async e=>{if(!e.selector||!e.selector.some((t=>"TextQuoteSelector"===t.type)))return{annotation:t,target:e};let n;try{const i=await this._integration.anchor(this.element,e.selector),o=$e.fromRange(i);n={annotation:t,target:e,range:o}}catch(i){n={annotation:t,target:e}}return n})))
|
|
128
|
-
_updateAnchors(t,e){var n;this.anchors=t,null===(n=this._clusterToolbar)||void 0===n||n.scheduleClusterUpdates(),e&&this._bucketBarClient.update(this.anchors)}async createAnnotation({highlight:t=!1}={}){const e=this.selectedRanges;this.selectedRanges=[];const n=await this.getDocumentInfo(),i=this.element,o=(await Promise.all(e.map((t=>this._integration.describe(i,t))))).map((t=>({source:n.uri,selector:t}))),r={uri:n.uri,document:n.metadata,target:o,$highlight:t,$cluster:t?"user-highlights":"user-annotations",$tag:"a:"+Et(8)};return this._sidebarRPC.call("createAnnotation",r),this.anchor(r),ko(),r}
|
|
129
|
-
;const t=sn(r.highlights).top;"up"===e&&t>=137||"down"===e&&t<=window.innerHeight-22||(!n||"up"===e&&t>i||"down"===e&&t<i)&&(n=r,i=t)}return n}(this.anchors.filter((({annotation:e})=>t.includes(e.$tag))),e);n&&this._integration.scrollToAnchor(n)}_onSelection(t){const e=this._integration.getAnnotatableRange(t);if(!e)return void this._onClearSelection();const n=document.getSelection(),i=Ze(n),o=Qe(n);o?(this.selectedRanges=[e],this._hostRPC.call("textSelected"),this._adder.annotationsForSelection=So(),this._isAdderVisible=!0,this._adder.show(o,i)):this._onClearSelection()}_onClearSelection(){this._isAdderVisible=!1,
|
|
130
|
-
t.classList.toggle("hypothesis-highlights-always-on",e)}(this.element,t),this._highlightsVisible=t,e&&this._hostRPC.call("highlightsVisibleChanged",t)}get highlightsVisible(){return this._highlightsVisible}fitSideBySide(t){this._sideBySideActive=this._integration.fitSideBySide(t)}get sideBySideActive(){return this._sideBySideActive}get hoveredAnnotationTags(){return this._hoveredAnnotations}_handleShortcut(t){Jt(t,"Ctrl+Shift+H")&&this.setHighlightsVisible(!this._highlightsVisible)}}function To(t,e){const n=new URL(t),i=new URLSearchParams;return i.append("config",JSON.stringify(e)),n.hash=i.toString(),n.toString()}
|
|
131
|
-
;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 i}function Lo({config:t,groupId:e}){return ht("iframe",{title:"Hypothesis annotation notebook",className:"h-full w-full border-0",allowFullScreen:!0,src:To(t.notebookAppUrl,{...Ro(t.notebookAppUrl,t),group:e})})}function Po({eventBus:t,config:e}){const[n,i]=K(0),[o,r]=K(!0),[s,a]=K(null),l=tt(""),c=tt(null);Q((()=>(l.current=document.body.style.overflow,()=>{document.body.style.overflow=l.current})),[]),Q((()=>{
|
|
132
|
-
children:ht("div",{className:"relative w-full h-full","data-testid":"notebook-inner",children:[ht("div",{className:"absolute right-0 m-3",children:ht(Se,{title:"Close the Notebook",onClick:()=>{var t;r(!0),null===(t=c.current)||void 0===t||t.publish("closeNotebook")},variant:"dark",children:ht(oe,{className:"w-4 h-4"})})}),ht(Lo,{config:e,groupId:s},n)]})})}class Oo{constructor(t,e,n){this._outerContainer=document.createElement("hypothesis-notebook"),t.appendChild(this._outerContainer),this.shadowRoot=Ie(this._outerContainer),B(ht(Po,{eventBus:e,config:n}),this.shadowRoot)}destroy(){B(null,this.shadowRoot),this._outerContainer.remove()}}var Mo={},Io={get exports(){return Mo},
|
|
133
|
-
;if(t)if(t.forEach)t.forEach(e,n);else if(t.length!==o)for(i=0;i<t.length;)e.call(n,t[i],i,t),i++;else for(i in t)t.hasOwnProperty(i)&&e.call(n,t[i],i,t)}function p(t,n,i){var o="DEPRECATED METHOD: "+n+"\n"+i+" AT \n";return function(){var n=new Error("get-stack-trace"),i=n&&n.stack?n.stack.replace(/^[^\(]+?[\n$]/gm,"").replace(/^\s+at\s+/gm,"").replace(/^Object.<anonymous>\s*\(/gm,"{anonymous}()@"):"Unknown Stack Trace",r=e.console&&(e.console.warn||e.console.log);return r&&r.call(e.console,o,i),t.apply(this,arguments)}}r="function"!=typeof Object.assign?function(t){if(t===o||null===t)throw new TypeError("Cannot convert undefined or null to object");for(var e=Object(t),n=1;n<arguments.length;n++){var i=arguments[n]
|
|
134
|
-
}),"merge","Use `assign`.");function _(t,e,n){var i,o=e.prototype;(i=t.prototype=Object.create(o)).constructor=t,i._super=o,n&&r(i,n)}function v(t,e){return function(){return t.apply(e,arguments)}}function y(t,e){return"function"==typeof t?t.apply(e&&e[0]||o,e):t}function b(t,e){return t===o?e:t}function w(t,e,n){f(E(e),(function(e){t.addEventListener(e,n,!1)}))}function C(t,e,n){f(E(e),(function(e){t.removeEventListener(e,n,!1)}))}function x(t,e){for(;t;){if(t==e)return!0;t=t.parentNode}return!1}function S(t,e){return t.indexOf(e)>-1}function E(t){return t.trim().split(/\s+/g)}function N(t,e,n){if(t.indexOf&&!n)return t.indexOf(e);for(var i=0;i<t.length;){if(n&&t[i][n]==e||!n&&t[i]===e)return i;i++}return-1}function k(t){
|
|
135
|
-
for(var n,i,r=e[0].toUpperCase()+e.slice(1),a=0;a<s.length;){if((i=(n=s[a])?n+r:e)in t)return i;a++}return o}var R=1;function L(t){var n=t.ownerDocument||t;return n.defaultView||n.parentWindow||e}var P="ontouchstart"in e,O=T(e,"PointerEvent")!==o,M=P&&/mobile|tablet|ip(ad|hone|od)|android/i.test(navigator.userAgent),I="touch",B="mouse",F=24,D=["x","y"],H=["clientX","clientY"];function V(t,e){var n=this;this.manager=t,this.callback=e,this.element=t.element,this.target=t.options.inputTarget,this.domHandler=function(e){y(t.options.enable,[t])&&n.handler(e)},this.init()}function q(t,e,n){var i=n.pointers.length,r=n.changedPointers.length,s=1&e&&i-r==0,a=12&e&&i-r==0;n.isFirst=!!s,n.isFinal=!!a,s&&(t.session={}),n.eventType=e,function(t,e){var n=t.session,i=e.pointers,r=i.length
|
|
136
|
-
e.angle=X(l,u),e.distance=$(l,u),function(t,e){var n=e.center,i=t.offsetDelta||{},o=t.prevDelta||{},r=t.prevInput||{};1!==e.eventType&&4!==r.eventType||(o=t.prevDelta={x:r.deltaX||0,y:r.deltaY||0},i=t.offsetDelta={x:n.x,y:n.y});e.deltaX=o.x+(n.x-i.x),e.deltaY=o.y+(n.y-i.y)}(n,e),e.offsetDirection=j(e.deltaX,e.deltaY);var d=W(e.deltaTime,e.deltaX,e.deltaY);e.overallVelocityX=d.x,e.overallVelocityY=d.y,e.overallVelocity=c(d.x)>c(d.y)?d.x:d.y,e.scale=a?(f=a.pointers,p=i,$(p[0],p[1],H)/$(f[0],f[1],H)):1,e.rotation=a?function(t,e){return X(e[1],e[0],H)+X(t[1],t[0],H)}(a.pointers,i):0,e.maxPointers=n.prevInput?e.pointers.length>n.prevInput.maxPointers?e.pointers.length:n.prevInput.maxPointers:e.pointers.length,function(t,e){var n,i,r,s,a=t.lastInterval||e,l=e.timeStamp-a.timeStamp
|
|
137
|
-
e.velocityX=i,e.velocityY=r,e.direction=s}(n,e);var f,p;var g=t.element;x(e.srcEvent.target,g)&&(g=e.srcEvent.target);e.target=g}(t,n),t.emit("hammer.input",n),t.recognize(n),t.session.prevInput=n}function U(t){for(var e=[],n=0;n<t.pointers.length;)e[n]={clientX:l(t.pointers[n].clientX),clientY:l(t.pointers[n].clientY)},n++;return{timeStamp:h(),pointers:e,center:z(e),deltaX:t.deltaX,deltaY:t.deltaY}}function z(t){var e=t.length;if(1===e)return{x:l(t[0].clientX),y:l(t[0].clientY)};for(var n=0,i=0,o=0;o<e;)n+=t[o].clientX,i+=t[o].clientY,o++;return{x:l(n/e),y:l(i/e)}}function W(t,e,n){return{x:e/t||0,y:n/t||0}}function j(t,e){return t===e?1:c(t)>=c(e)?t<0?2:4:e<0?8:16}function $(t,e,n){n||(n=D);var i=e[n[0]]-t[n[0]],o=e[n[1]]-t[n[1]];return Math.sqrt(i*i+o*o)}function X(t,e,n){
|
|
138
|
-
this.evTarget&&w(this.target,this.evTarget,this.domHandler),this.evWin&&w(L(this.element),this.evWin,this.domHandler)},destroy:function(){this.evEl&&C(this.element,this.evEl,this.domHandler),this.evTarget&&C(this.target,this.evTarget,this.domHandler),this.evWin&&C(L(this.element),this.evWin,this.domHandler)}};var Y={mousedown:1,mousemove:2,mouseup:4},Z="mousedown",G="mousemove mouseup";function K(){this.evEl=Z,this.evWin=G,this.pressed=!1,V.apply(this,arguments)}_(K,V,{handler:function(t){var e=Y[t.type];1&e&&0===t.button&&(this.pressed=!0),2&e&&1!==t.which&&(e=4),this.pressed&&(4&e&&(this.pressed=!1),this.callback(this.manager,e,{pointers:[t],changedPointers:[t],pointerType:B,srcEvent:t}))}});var Q={pointerdown:1,pointermove:2,pointerup:4,pointercancel:8,pointerout:8},J={2:I,3:"pen",4:B,5:"kinect"
|
|
139
|
-
e.MSPointerEvent&&!e.PointerEvent&&(tt="MSPointerDown",et="MSPointerMove MSPointerUp MSPointerCancel"),_(nt,V,{handler:function(t){var e=this.store,n=!1,i=t.type.toLowerCase().replace("ms",""),o=Q[i],r=J[t.pointerType]||t.pointerType,s=r==I,a=N(e,t.pointerId,"pointerId");1&o&&(0===t.button||s)?a<0&&(e.push(t),a=e.length-1):12&o&&(n=!0),a<0||(e[a]=t,this.callback(this.manager,o,{pointers:e,changedPointers:[t],pointerType:r,srcEvent:t}),n&&e.splice(a,1))}});var it={touchstart:1,touchmove:2,touchend:4,touchcancel:8},ot="touchstart",rt="touchstart touchmove touchend touchcancel";function st(){this.evTarget=ot,this.evWin=rt,this.started=!1,V.apply(this,arguments)}function at(t,e){var n=k(t.touches),i=k(t.changedTouches);return 12&e&&(n=A(n.concat(i),"identifier",!0)),[n,i]}_(st,V,{handler:function(t){var e=it[t.type]
|
|
140
|
-
srcEvent:t})}}});var lt={touchstart:1,touchmove:2,touchend:4,touchcancel:8},ct="touchstart touchmove touchend touchcancel";function ht(){this.evTarget=ct,this.targetIds={},V.apply(this,arguments)}function ut(t,e){var n=k(t.touches),i=this.targetIds;if(3&e&&1===n.length)return i[n[0].identifier]=!0,[n,n];var o,r,s=k(t.changedTouches),a=[],l=this.target;if(r=n.filter((function(t){return x(t.target,l)})),1===e)for(o=0;o<r.length;)i[r[o].identifier]=!0,o++;for(o=0;o<s.length;)i[s[o].identifier]&&a.push(s[o]),12&e&&delete i[s[o].identifier],o++;return a.length?[A(r.concat(a),"identifier",!0),a]:void 0}_(ht,V,{handler:function(t){var e=lt[t.type],n=ut.call(this,t,e);n&&this.callback(this.manager,e,{pointers:n[0],changedPointers:n[1],pointerType:I,srcEvent:t})}});function dt(){V.apply(this,arguments)
|
|
141
|
-
pt.call(this,e)):12&t&&pt.call(this,e)}function pt(t){var e=t.changedPointers[0];if(e.identifier===this.primaryTouch){var n={x:e.clientX,y:e.clientY};this.lastTouches.push(n);var i=this.lastTouches;setTimeout((function(){var t=i.indexOf(n);t>-1&&i.splice(t,1)}),2500)}}function gt(t){for(var e=t.srcEvent.clientX,n=t.srcEvent.clientY,i=0;i<this.lastTouches.length;i++){var o=this.lastTouches[i],r=Math.abs(e-o.x),s=Math.abs(n-o.y);if(r<=25&&s<=25)return!0}return!1}_(dt,V,{handler:function(t,e,n){var i=n.pointerType==I,o=n.pointerType==B;if(!(o&&n.sourceCapabilities&&n.sourceCapabilities.firesTouchEvents)){if(i)ft.call(this,e,n);else if(o&>.call(this,n))return;this.callback(t,e,n)}},destroy:function(){this.touch.destroy(),this.mouse.destroy()}})
|
|
142
|
-
t[i]=!n||e.CSS.supports("touch-action",i)})),t}();function Et(t,e){this.manager=t,this.set(e)}Et.prototype={set:function(t){t==vt&&(t=this.compute()),_t&&this.manager.element.style&&St[t]&&(this.manager.element.style[mt]=t),this.actions=t.toLowerCase().trim()},update:function(){this.set(this.manager.options.touchAction)},compute:function(){var t=[];return f(this.manager.recognizers,(function(e){y(e.options.enable,[e])&&(t=t.concat(e.getTouchAction()))})),function(t){if(S(t,wt))return wt;var e=S(t,Ct),n=S(t,xt);if(e&&n)return wt;if(e||n)return e?Ct:xt;if(S(t,bt))return bt;return yt}(t.join(" "))},preventDefaults:function(t){var e=t.srcEvent,n=t.offsetDirection;if(this.manager.session.prevented)e.preventDefault();else{
|
|
143
|
-
t.preventDefault()}};var Nt=32;function kt(t){this.options=r({},this.defaults,t||{}),this.id=R++,this.manager=null,this.options.enable=b(this.options.enable,!0),this.state=1,this.simultaneous={},this.requireFail=[]}function At(t){return 16&t?"cancel":8&t?"end":4&t?"move":2&t?"start":""}function Tt(t){return 16==t?"down":8==t?"up":2==t?"left":4==t?"right":""}function Rt(t,e){var n=e.manager;return n?n.get(t):t}function Lt(){kt.apply(this,arguments)}function Pt(){Lt.apply(this,arguments),this.pX=null,this.pY=null}function Ot(){Lt.apply(this,arguments)}function Mt(){kt.apply(this,arguments),this._timer=null,this._input=null}function It(){Lt.apply(this,arguments)}function Bt(){Lt.apply(this,arguments)}function Ft(){
|
|
144
|
-
this.manager&&this.manager.touchAction.update(),this},recognizeWith:function(t){if(d(t,"recognizeWith",this))return this;var e=this.simultaneous;return e[(t=Rt(t,this)).id]||(e[t.id]=t,t.recognizeWith(this)),this},dropRecognizeWith:function(t){return d(t,"dropRecognizeWith",this)||(t=Rt(t,this),delete this.simultaneous[t.id]),this},requireFailure:function(t){if(d(t,"requireFailure",this))return this;var e=this.requireFail;return-1===N(e,t=Rt(t,this))&&(e.push(t),t.requireFailure(this)),this},dropRequireFailure:function(t){if(d(t,"dropRequireFailure",this))return this;t=Rt(t,this);var e=N(this.requireFail,t);return e>-1&&this.requireFail.splice(e,1),this},hasRequireFailures:function(){return this.requireFail.length>0},canRecognizeWith:function(t){
|
|
145
|
-
if(this.canEmit())return this.emit(t);this.state=Nt},canEmit:function(){for(var t=0;t<this.requireFail.length;){if(!(33&this.requireFail[t].state))return!1;t++}return!0},recognize:function(t){var e=r({},t);if(!y(this.options.enable,[this,e]))return this.reset(),void(this.state=Nt);56&this.state&&(this.state=1),this.state=this.process(e),30&this.state&&this.tryEmit(e)},process:function(t){},getTouchAction:function(){},reset:function(){}},_(Lt,kt,{defaults:{pointers:1},attrTest:function(t){var e=this.options.pointers;return 0===e||t.pointers.length===e},process:function(t){var e=this.state,n=t.eventType,i=6&e,o=this.attrTest(t);return i&&(8&n||!o)?16|e:i||o?4&n?8|e:2&e?4|e:2:Nt}}),_(Pt,Lt,{defaults:{event:"pan",threshold:10,pointers:1,direction:30},
|
|
146
|
-
n=r!=this.pX,i=Math.abs(t.deltaX)):(o=0===s?1:s<0?8:16,n=s!=this.pY,i=Math.abs(t.deltaY))),t.direction=o,n&&i>e.threshold&&o&e.direction},attrTest:function(t){return Lt.prototype.attrTest.call(this,t)&&(2&this.state||!(2&this.state)&&this.directionTest(t))},emit:function(t){this.pX=t.deltaX,this.pY=t.deltaY;var e=Tt(t.direction);e&&(t.additionalEvent=this.options.event+e),this._super.emit.call(this,t)}}),_(Ot,Lt,{defaults:{event:"pinch",threshold:0,pointers:2},getTouchAction:function(){return[wt]},attrTest:function(t){return this._super.attrTest.call(this,t)&&(Math.abs(t.scale-1)>this.options.threshold||2&this.state)},emit:function(t){if(1!==t.scale){var e=t.scale<1?"in":"out";t.additionalEvent=this.options.event+e}this._super.emit.call(this,t)}}),_(Mt,kt,{
|
|
147
|
-
|
|
148
|
-
this._super.attrTest.call(this,t)&&n&t.offsetDirection&&t.distance>this.options.threshold&&t.maxPointers==this.options.pointers&&c(e)>this.options.velocity&&4&t.eventType},emit:function(t){var e=Tt(t.offsetDirection);e&&this.manager.emit(this.options.event+e,t),this.manager.emit(this.options.event,t)}}),_(Ft,kt,{defaults:{event:"tap",pointers:1,taps:1,interval:300,time:250,threshold:9,posThreshold:10},getTouchAction:function(){return[bt]},process:function(t){var e=this.options,n=t.pointers.length===e.pointers,i=t.distance<e.threshold,o=t.deltaTime<e.time;if(this.reset(),1&t.eventType&&0===this.count)return this.failTimeout();if(i&&o&&n){if(4!=t.eventType)return this.failTimeout();var r=!this.pTime||t.timeStamp-this.pTime<e.interval,s=!this.pCenter||$(this.pCenter,t.center)<e.posThreshold;if(this.pTime=t.timeStamp,this.pCenter=t.center,s&&r?this.count+=1:this.count=1,
|
|
149
|
-
2):8}return Nt},failTimeout:function(){return this._timer=u((function(){this.state=Nt}),this.options.interval,this),Nt},reset:function(){clearTimeout(this._timer)},emit:function(){8==this.state&&(this._input.tapCount=this.count,this.manager.emit(this.options.event,this._input))}}),Dt.VERSION="2.0.7",Dt.defaults={domEvents:!1,touchAction:vt,enable:!0,inputTarget:null,inputClass:null,preset:[[It,{enable:!1}],[Ot,{enable:!1},["rotate"]],[Bt,{direction:6}],[Pt,{direction:6},["swipe"]],[Ft],[Ft,{event:"doubletap",taps:2},["tap"]],[Mt]],cssProps:{userSelect:"none",touchSelect:"none",touchCallout:"none",contentZooming:"none",userDrag:"none",tapHighlightColor:"rgba(0,0,0,0)"}};function Ht(t,e){var n;this.options=r({},Dt.defaults,e||{}),this.options.inputTarget=this.options.inputTarget||t,this.handlers={},this.session={},this.recognizers=[],this.oldCssProps={},this.element=t,
|
|
150
|
-
f(this.options.recognizers,(function(t){var e=this.add(new t[0](t[1]));t[2]&&e.recognizeWith(t[2]),t[3]&&e.requireFailure(t[3])}),this)}function Vt(t,e){var n,i=t.element;i.style&&(f(t.options.cssProps,(function(o,r){n=T(i.style,r),e?(t.oldCssProps[n]=i.style[n],i.style[n]=o):i.style[n]=t.oldCssProps[n]||""})),e||(t.oldCssProps={}))}Ht.prototype={set:function(t){return r(this.options,t),t.touchAction&&this.touchAction.update(),t.inputTarget&&(this.input.destroy(),this.input.target=t.inputTarget,this.input.init()),this},stop:function(t){this.session.stopped=t?2:1},recognize:function(t){var e=this.session;if(!e.stopped){var n;this.touchAction.preventDefaults(t);var i=this.recognizers,o=e.curRecognizer;(!o||o&&8&o.state)&&(o=e.curRecognizer=null);for(var r=0;r<i.length;)n=i[r],2===e.stopped||o&&n!=o&&!n.canRecognizeWith(o)?n.reset():n.recognize(t)
|
|
151
|
-
;for(var e=this.recognizers,n=0;n<e.length;n++)if(e[n].options.event==t)return e[n];return null},add:function(t){if(d(t,"add",this))return this;var e=this.get(t.options.event);return e&&this.remove(e),this.recognizers.push(t),t.manager=this,this.touchAction.update(),t},remove:function(t){if(d(t,"remove",this))return this;if(t=this.get(t)){var e=this.recognizers,n=N(e,t);-1!==n&&(e.splice(n,1),this.touchAction.update())}return this},on:function(t,e){if(t!==o&&e!==o){var n=this.handlers;return f(E(t),(function(t){n[t]=n[t]||[],n[t].push(e)})),this}},off:function(t,e){if(t!==o){var n=this.handlers;return f(E(t),(function(t){e?n[t]&&n[t].splice(N(n[t],e),1):delete n[t]})),this}},emit:function(t,e){this.options.domEvents&&function(t,e){var i=n.createEvent("Event");i.initEvent(t,!0,!0),i.gesture=e,e.target.dispatchEvent(i)}(t,e);var i=this.handlers[t]&&this.handlers[t].slice();if(i&&i.length){e.type=t,e.preventDefault=function(){
|
|
152
|
-
this.element&&Vt(this,!1),this.handlers={},this.session={},this.input.destroy(),this.element=null}},r(Dt,{INPUT_START:1,INPUT_MOVE:2,INPUT_END:4,INPUT_CANCEL:8,STATE_POSSIBLE:1,STATE_BEGAN:2,STATE_CHANGED:4,STATE_ENDED:8,STATE_RECOGNIZED:8,STATE_CANCELLED:16,STATE_FAILED:Nt,DIRECTION_NONE:1,DIRECTION_LEFT:2,DIRECTION_RIGHT:4,DIRECTION_UP:8,DIRECTION_DOWN:16,DIRECTION_HORIZONTAL:6,DIRECTION_VERTICAL:F,DIRECTION_ALL:30,Manager:Ht,Input:V,TouchAction:Et,TouchInput:ht,MouseInput:K,PointerEventInput:nt,TouchMouseInput:dt,SingleTouchInput:st,Recognizer:kt,AttrRecognizer:Lt,Tap:Ft,Pan:Pt,Swipe:Bt,Pinch:Ot,Rotate:It,Press:Mt,on:w,off:C,each:f,merge:m,extend:g,assign:r,inherit:_,bindFn:v,prefixed:T}),(void 0!==e?e:"undefined"!=typeof self?self:{}).Hammer=Dt,t.exports?t.exports=Dt:e.Hammer=Dt}(window,document)}(Io);function Bo({children:t}){return ht("ul",{
|
|
153
|
-
function Fo({children:t,topPosition:e}){return ht("li",{className:h("absolute right-0","pointer-events-auto"),style:{top:e},children:t})}function Do({above:t,below:e,buckets:n,onFocusAnnotations:i,onScrollToClosestOffScreenAnchor:o,onSelectAnnotations:r}){const s=t.tags.size>0,a=e.tags.size>0;return ht(Bo,{children:[s&&ht(Fo,{topPosition:t.position,children:ht(_t,{className:h("BucketButton UpBucketButton","right-0 mt-[-11px]"),"data-testid":"up-navigation-button",onClick:()=>o([...t.tags],"up"),onBlur:()=>i([]),onFocus:()=>i([...t.tags]),onMouseEnter:()=>i([...t.tags]),onMouseOut:()=>i([]),title:`Go up to next annotations (${t.tags.size})`,children:t.tags.size})}),n.map(((t,e)=>ht(Fo,{topPosition:t.position,children:ht(_t,{className:h("BucketButton LeftBucketButton","right-0 mt-[-8px]"),onClick:e=>r([...t.tags],e.metaKey||e.ctrlKey),onBlur:()=>i([]),onFocus:()=>i([...t.tags]),
|
|
154
|
-
},e))),a&&ht(Fo,{topPosition:e.position,children:ht(_t,{className:"BucketButton DownBucketButton right-0","data-testid":"down-navigation-button",onClick:()=>o([...e.tags],"down"),onBlur:()=>i([]),onFocus:()=>i([...e.tags]),onMouseEnter:()=>i([...e.tags]),onMouseOut:()=>i([]),title:`Go up to next annotations (${e.tags.size})`,children:e.tags.size})})]})}class Ho{constructor(t,{onFocusAnnotations:e,onScrollToClosestOffScreenAnchor:n,onSelectAnnotations:i}){this._bucketsContainer=document.createElement("div"),t.appendChild(this._bucketsContainer),this._onFocusAnnotations=e,this._onScrollToClosestOffScreenAnchor=n,this._onSelectAnnotations=i,this.update([])}destroy(){B(null,this._bucketsContainer),this._bucketsContainer.remove()}update(t){const e=function(t){const e=new Set,n=new Set,i=[];let o=null;function r({bottom:t,tag:e,top:n}){return{bottom:t,position:n+(t-n)/2,tags:new Set([e]),
|
|
155
|
-
;if(!o)return void(o=r(t));const s=t.top>o.top&&t.bottom<o.bottom;if(t.top-o.bottom>60&&!s)i.push(o),o=r(t);else{const e=t.bottom>o.bottom?t.bottom:o.bottom,n=e-o.top;o.tags.add(t.tag),o.bottom=e,o.position=o.top+n/2}})),o&&i.push(o),{above:{tags:e,position:137},below:{tags:n,position:window.innerHeight-22},buckets:i}}(t);B(ht(Do,{above:e.above,below:e.below,buckets:e.buckets,onFocusAnnotations:t=>this._onFocusAnnotations(t),onScrollToClosestOffScreenAnchor:(t,e)=>this._onScrollToClosestOffScreenAnchor(t,e),onSelectAnnotations:(t,e)=>this._onSelectAnnotations(t,e)}),this._bucketsContainer)}}function Vo({...t}){const{icon:e,title:n,...i}=t;return ht(mt,{className:h("w-[30px] h-[30px]","rounded-px","flex items-center justify-center","border bg-white text-grey-6 hover:text-grey-9","shadow transition-colors"),icon:e,title:n,...i})}function qo({highlightsVisible:t}){return ht("div",{
|
|
156
|
-
function Uo({closeSidebar:t,createAnnotation:e,isSidebarOpen:n,newAnnotationType:i,showHighlights:o,toggleHighlights:r,toggleSidebar:s,toggleSidebarRef:a,useMinimalControls:l=!1}){return ht("div",{className:h("absolute left-[-33px] w-[33px] z-2","text-px-base leading-none"),children:[l&&n&&ht(mt,{className:h("w-[27px] h-[27px] mt-[140px] ml-px-1.5","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",icon:"cancel",onClick:t}),!l&&ht(_,{children:[ht(mt,{className:h("h-[40px] w-[33px] pl-px-1.5","bg-white text-grey-5 hover:text-grey-9","border-l border-b"),buttonRef:a,title:"Annotation sidebar",icon:n?"caret-right":"caret-left",expanded:n,pressed:n,onClick:s}),ht("div",{className:"space-y-px-1.5 mt-px-2",children:[ht(Vo,{title:"Show highlights",icon:o?"show":"hide",selected:o,
|
|
157
|
-
highlightsVisible:o})]})]})}class zo{constructor(t,e){const{createAnnotation:n,setSidebarOpen:i,setHighlightsVisible:o}=e;this._container=t,this._useMinimalControls=!1,this._newAnnotationType="note",this._highlightsVisible=!1,this._sidebarOpen=!1,this._closeSidebar=()=>i(!1),this._toggleSidebar=()=>i(!this._sidebarOpen),this._toggleHighlights=()=>o(!this._highlightsVisible),this._createAnnotation=()=>{n(),i(!0)},this._sidebarToggleButton={current:null},this.render()}getWidth(){return this._container.firstChild.getBoundingClientRect().width}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}
|
|
158
|
-
get sidebarToggleButton(){return this._sidebarToggleButton.current}render(){B(ht(Uo,{closeSidebar:this._closeSidebar,createAnnotation:this._createAnnotation,newAnnotationType:this._newAnnotationType,isSidebarOpen:this._sidebarOpen,showHighlights:this._highlightsVisible,toggleHighlights:this._toggleHighlights,toggleSidebar:this._toggleSidebar,toggleSidebarRef:this._sidebarToggleButton,useMinimalControls:this.useMinimalControls}),this._container)}}const Wo=280;class jo{constructor(t,e,n){if(this._emitter=e.createEmitter(),this._guestWithSelection=null,this._guestRPC=[],this._sidebarRPC=new Ut,this.iframe=function(t){const e=t.sidebarAppUrl,n=To(e,Ro(e,t)),i=document.createElement("iframe");return i.setAttribute("allowfullscreen",""),i.src=n,i.title="Hypothesis annotation viewer",i.className="sidebar-frame",i}(n),this._config=n,this.bucketBar=null,this.features=new wn,
|
|
159
|
-
this.externalFrame.appendChild(this.iframe)}else{this.iframeContainer=document.createElement("div"),this.iframeContainer.style.display="none",this.iframeContainer.className="sidebar-container","clean"===n.theme?this.iframeContainer.classList.add("theme-clean"):this.bucketBar=new Ho(this.iframeContainer,{onFocusAnnotations:t=>this._guestRPC.forEach((e=>e.call("hoverAnnotations",t))),onScrollToClosestOffScreenAnchor:(t,e)=>this._guestRPC.forEach((n=>n.call("scrollToClosestOffScreenAnchor",t,e))),onSelectAnnotations:(t,e)=>this._guestRPC.forEach((n=>n.call("selectAnnotations",t,e)))}),this.iframeContainer.appendChild(this.iframe),this.hypothesisSidebar=document.createElement("hypothesis-sidebar");Ie(this.hypothesisSidebar).appendChild(this.iframeContainer),t.appendChild(this.hypothesisSidebar)}this.iframe.contentWindow&&Bt(this.iframe.contentWindow),this._listeners=new xt
|
|
160
|
-
;(null!==(t=this._guestWithSelection)&&void 0!==t?t:this._guestRPC[0]).call("createAnnotation")},setSidebarOpen:t=>t?this.open():this.close(),setHighlightsVisible:t=>this.setHighlightsVisible(t)}),"clean"===n.theme?this.toolbar.useMinimalControls=!0:this.toolbar.useMinimalControls=!1,this.iframeContainer?(this.iframeContainer.prepend(o),this.toolbarWidth=this.toolbar.getWidth()):this.toolbarWidth=0,this._listeners.add(window,"resize",(()=>this._onResize())),this._gestureState={initial:null,final:null},this._setupGestures(),this.close();const[r]=n.services||[];r&&(this.onLoginRequest=r.onLoginRequest,this.onLogoutRequest=r.onLogoutRequest,this.onSignupRequest=r.onSignupRequest,this.onProfileRequest=r.onProfileRequest,this.onHelpRequest=r.onHelpRequest),this.onLayoutChange=n.onLayoutChange,this._layoutState={expanded:!1,width:0,toolbarWidth:0},this._updateLayoutState(!1),
|
|
161
|
-
null===(t=this.bucketBar)||void 0===t||t.destroy(),this._listeners.removeAll(),null===(e=this._hammerManager)||void 0===e||e.destroy(),this.hypothesisSidebar?this.hypothesisSidebar.remove():this.iframe.remove(),this._emitter.destroy(),Bt(null)}onFrameConnected(t,e){switch(t){case"guest":this._connectGuest(e);break;case"sidebar":this._sidebarRPC.connect(e)}}_connectGuest(t){const e=new Ut;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("highlightsVisibleChanged",(t=>{this.setHighlightsVisible(t)}));const n=this.bucketBar;n&&e.on("anchorsChanged",(t=>{0===this._guestRPC.indexOf(e)&&n.update(t)})),
|
|
162
|
-
this._guestRPC=this._guestRPC.filter((t=>t!==e))})),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;this.setHighlightsVisible(t),(this._config.openSidebar||this._config.annotations||this._config.query||this._config.group)&&this.open()})),
|
|
163
|
-
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._emitter.subscribe("closeNotebook",(()=>{this.show()}));[["loginRequested",this.onLoginRequest],["logoutRequested",this.onLogoutRequest],["signupRequested",this.onSignupRequest],["profileRequested",this.onProfileRequest],["helpRequested",this.onHelpRequest]].forEach((([t,e])=>{e&&this._sidebarRPC.on(t,(()=>e()))}))}_resetGestureState(){this._gestureState={initial:null,final:null}}_setupGestures(){const t=this.toolbar.sidebarToggleButton;t&&(this._hammerManager=new Mo.Manager(t),this._hammerManager.on("panstart panend panleft panright",(t=>this._onPan(t))),this._hammerManager.add(new Mo.Pan({direction:Mo.DIRECTION_HORIZONTAL})))}_updateLayout(){this.renderFrame||(this.renderFrame=requestAnimationFrame((()=>{if(this.renderFrame=null,
|
|
104
|
+
return`urn:x-pdf:${t}`}function oo(t){if(!t.url)return null;const e=Vn(t.url);return 0!==e.indexOf("file://")?e:null}function ro(t){var e;const n=null===(e=t.highlights)||void 0===e?void 0:e[0];return n&&Ye(n)}function so(t){return new Promise((e=>setTimeout(e,t)))}class ao extends Pt{constructor(t,e={}){var n,i,o;super(),Ct(this,"_annotator",void 0),Ct(this,"_banner",void 0),Ct(this,"_bannerState",void 0),Ct(this,"_destroyed",void 0),Ct(this,"_listeners",void 0),Ct(this,"_observer",void 0),Ct(this,"_pdfContainer",void 0),Ct(this,"_pdfMetadata",void 0),Ct(this,"_pdfViewer",void 0),Ct(this,"_reanchoringMaxWait",void 0),Ct(this,"_updateAnnotationLayerVisibility",void 0),this._annotator=t;const r=window,s=r.PDFViewerApplication;this._pdfViewer=s.pdfViewer,this._pdfViewer.viewer.classList.add("has-transparent-text-layer"),this._pdfContainer=null!==(n=null===(i=s.appConfig)||void 0===i?void 0:i.appContainer)&&void 0!==n?n:document.body,this._pdfMetadata=new eo(s),
|
|
105
|
+
this._observer=new MutationObserver(Li((()=>this._update()),100)),this._observer.observe(this._pdfViewer.viewer,{attributes:!0,attributeFilter:["data-loaded"],childList:!0,subtree:!0}),this._reanchoringMaxWait=null!==(o=e.reanchoringMaxWait)&&void 0!==o?o:3e3,this._banner=null,this._bannerState={contentInfo:null,noTextWarning:!1},this._updateBannerState(this._bannerState),this._checkForSelectableText(),this._updateAnnotationLayerVisibility=()=>{const t=r.getSelection();this._pdfViewer.viewer.classList.toggle("is-selecting",!t.isCollapsed)},this._listeners=new xt,this._listeners.add(document,"selectionchange",this._updateAnnotationLayerVisibility),this._destroyed=!1}destroy(){var t;this._listeners.removeAll(),this._pdfViewer.viewer.classList.remove("has-transparent-text-layer"),this._observer.disconnect(),null===(t=this._banner)||void 0===t||t.remove(),this._destroyed=!0}uri(){return this._pdfMetadata.getUri()}getMetadata(){return this._pdfMetadata.getMetadata()}showContentInfo(t){this._updateBannerState({
|
|
106
|
+
contentInfo:t})}anchor(t,e){return Zi(0,e)}getAnnotatableRange(t){try{const e=$e.trimmedRange(t);if(function(t){try{return Gi(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 Ki(t,e)}async _checkForSelectableText(){try{await this.uri()}catch(t){return}if(!this._destroyed)try{const t=await async function(){const t=qi();let e=!1;for(let n=0;n<t.pagesCount;n++)if((await zi(n)).trim().length>0){e=!0;break}return e}();this._updateBannerState({noTextWarning:!t})}catch(t){console.warn("Unable to check for text in PDF:",t)}}_updateBannerState(t){this._bannerState={...this._bannerState,...t};const e=document.querySelector("#outerContainer");var n;if(!(this._bannerState.contentInfo||this._bannerState.noTextWarning))return null===(n=this._banner)||void 0===n||n.remove(),this._banner=null,void(e.style.height="");this._banner||(this._banner=document.createElement("hypothesis-banner"),
|
|
107
|
+
document.body.prepend(this._banner),Ie(this._banner)),B(ht(Qi,{children:[this._bannerState.contentInfo&&ht(Ji,{info:this._bannerState.contentInfo}),this._bannerState.noTextWarning&&ht(to,{})]}),this._banner.shadowRoot);const i=this._banner.getBoundingClientRect().height;e.style.height=`calc(100% - ${i}px)`}_update(){const t=[],e=this._pdfViewer.pagesCount;for(let t=0;t<e;t++){var n;const e=this._pdfViewer.getPageView(t);if(null!=e&&null!==(n=e.textLayer)&&void 0!==n&&n.renderingDone)switch(e.renderingState){case Ii:e.textLayer=null;break;case Bi:i=e.div,o=void 0,null===(o=i.querySelector(Xe))||void 0===o||o.remove()}}var i,o;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 i=e.highlights[n];if(!document.body.contains(i)){e.highlights.splice(n,1),delete e.range,t.push(e.annotation);break}}}t.map((t=>this._annotator.anchor(t)))}contentContainer(){return document.querySelector("#viewerContainer")}fitSideBySide(t){
|
|
108
|
+
const e=window.innerWidth-t.width,n=t.expanded&&e>=680,i=n?t.width:t.toolbarWidth;this._pdfContainer.style.width=`calc(100% - ${i}px)`;const o=this._pdfViewer.currentScaleValue;return"auto"!==o&&"page-fit"!==o&&"page-width"!==o||(this._pdfViewer.currentScaleValue=o),this._pdfViewer.update(),n}async scrollToAnchor(t){const e=t.annotation,n=ro(t),i=this._anchorOffset(t);if(null!==i&&(await gi(this.contentContainer(),i),n)){const t=await this._waitForAnnotationToBeAnchored(e,this._reanchoringMaxWait);if(!t)return;const n=this._anchorOffset(t);if(null===n)return;await gi(this.contentContainer(),n)}}async _waitForAnnotationToBeAnchored(t,e){var n;const i=Date.now();let o;do{o=this._annotator.anchors.find((e=>e.annotation===t)),o&&!ro(o)||(o=null,await so(20))}while(!o&&Date.now()-i<e);return null!==(n=o)&&void 0!==n?n:null}_anchorOffset(t){if(!t.highlights)return null;return function(t,e){let n=0;for(;t!==e&&e.contains(t);)n+=t.offsetTop,t=t.offsetParent;return n}(t.highlights[0],this.contentContainer())}}
|
|
109
|
+
function lo(t){const e=function(t){if(!t.includes("["))return t;let e="",n=!1,i=!1;for(const o of t)n||"^"!==o?(n||"["!==o?!n&&i&&"]"===o?i=!1:i||(e+=o):i=!0,n=!1):n=!0;return e}(t),n=e.indexOf("!");return-1===n?e:e.slice(0,n)}class co{constructor(t,e,n){this._element=t,this._onFrameAdded=e,this._onFrameRemoved=n,this._annotatableFrames=new Set,this._isDisconnected=!1,this._mutationObserver=new MutationObserver(Li((()=>{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 ho(t),this._isDisconnected)return;t.contentWindow.addEventListener("unload",(()=>{this._removeFrame(t)})),this._onFrameAdded(t)}catch(e){console.warn(`Unable to inject the Hypothesis client (from '${document.location.href}' into a cross-origin frame '${t.src}')`)}}_removeFrame(t){
|
|
110
|
+
this._annotatableFrames.delete(t),this._onFrameRemoved(t)}_discoverFrames(){const t=new Set(this._element.querySelectorAll("iframe[enable-annotation]"));for(let e of t)this._annotatableFrames.has(e)||this._addFrame(e);for(let e of this._annotatableFrames)t.has(e)||this._removeFrame(e)}}function ho(t){return new Promise(((e,n)=>{const i=uo(t,((t,o)=>{i(),o?e(o):n(t)}))}))}function uo(t,e,{pollInterval:n=10}={}){let i,o;const r=new WeakSet,s=()=>{clearTimeout(i),i=void 0},a=()=>{const n=t.contentDocument;if(n){if(!r.has(n)){if(r.add(n),s(),!function(t){var e;return"about:blank"===(null===(e=t.contentDocument)||void 0===e?void 0:e.location.href)&&t.hasAttribute("src")&&"about:blank"!==t.src}(t)){"interactive"===n.readyState||"complete"===n.readyState?e(null,n):n.addEventListener("DOMContentLoaded",(()=>e(null,n)))}var i;t.contentDocument&&(null===(i=t.contentWindow)||void 0===i||i.addEventListener("unload",o))}}else{s();const n=t.isConnected?"Frame is cross-origin":"Frame is disconnected";e(new Error(n))}}
|
|
111
|
+
;let l=!1;o=()=>{s(),l||(i=setInterval(a,n))},t.addEventListener("load",a);const c=setTimeout(a,0);return()=>{l=!0,clearTimeout(c),s(),t.removeEventListener("load",a)}}class fo{constructor(t,e,n){if(Ct(this,"container",void 0),Ct(this,"_imageSizeObserver",void 0),Ct(this,"_listeners",void 0),Ct(this,"_updateTextLayerSize",void 0),e.length!==n.length)throw new Error("Char boxes length does not match text length");const i=t.parentNode,o=document.createElement("hypothesis-text-layer");i.insertBefore(o,t.nextSibling),i.style.position="relative",o.style.position="absolute",o.style.top="0",o.style.left="0",o.style.color="transparent",o.style.textAlign="left",o.style.mixBlendMode="multiply";const r="sans-serif";o.style.fontSize="16px",o.style.fontFamily=r;const s=document.createElement("canvas").getContext("2d");s.font="16px sans-serif";const a=(t,e,n="px")=>`calc(var(--${t}-scale) * ${e}${n})`,l=function(t,e){const n=[];let i={text:"",rect:new DOMRect};const o=()=>{i.text.length>0&&(n.push(i),i={text:"",
|
|
112
|
+
rect:new DOMRect})};for(const[n,r]of t.entries()){const t=e[n],s=/\s/.test(t);i.text.length>0&&!jn(i.rect,r)&&o(),i.rect=Xn(i.rect,r),i.text+=s?" ":t,s&&o()}o();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=Yn(e.rect),i=Yn(t.rect).x-n.x;(!jn(e.rect,t.rect)||i<0)&&a()}s.words.push(t),s.rect=Xn(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=Yn(e.rect),i=Yn(t.rect).y-n.y;(!$n(e.rect,t.rect)||jn(e.rect,t.rect)||i<0||i>4*t.rect.height)&&h()}c.lines.push(t),c.rect=Xn(c.rect,t.rect)}return h(),l}(e,n);for(const t of l){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 i of t.lines){
|
|
113
|
+
const o=document.createElement("hypothesis-text-line");o.style.display="block",o.style.marginLeft=a("x",i.rect.left-t.rect.left),o.style.height=a("y",i.rect.height),n&&(o.style.marginTop=a("y",i.rect.top-n.rect.bottom)),n=i,o.style.whiteSpace="nowrap";let r=null;for(const t of i.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),i=a("x",t.rect.width/n.width,""),l=a("y",t.rect.height/16,"");e.style.transform=`scale(${i}, ${l})`,o.append(e)}e.append(o)}o.append(e)}const c=()=>{const{width:e,height:n}=t.getBoundingClientRect();o.style.width=e+"px",o.style.height=n+"px",o.style.setProperty("--x-scale",`${e}`),o.style.setProperty("--y-scale",`${n}`)};c(),this.container=o,this._updateTextLayerSize=Li(c,{maxWait:50}),
|
|
114
|
+
this._listeners=new xt,"undefined"!=typeof ResizeObserver&&(this._imageSizeObserver=new ResizeObserver((()=>{this._updateTextLayerSize()})),this._imageSizeObserver.observe(t)),this._listeners.add(window,"resize",this._updateTextLayerSize)}updateSync(){this._updateTextLayerSize(),this._updateTextLayerSize.flush()}destroy(){var t;this.container.remove(),this._listeners.removeAll(),this._updateTextLayerSize.cancel(),null===(t=this._imageSizeObserver)||void 0===t||t.disconnect()}}class po{constructor(t,e){this._config=e,this._frameObserver=new co(t,(t=>go(t,e)),(()=>{}))}destroy(){this._frameObserver.disconnect()}}async function go(t,e,n){if(null!==t.contentDocument.querySelector("script.js-hypothesis-config"))return;await ho(t);const{assetRoot:i,notebookAppUrl:o,sidebarAppUrl:r}=Wt(document),s={...e,assetRoot:i,notebookAppUrl:o,sidebarAppUrl:r,subFrameIdentifier:null!=n?n:Et(10)},a=document.createElement("script");a.className="js-hypothesis-config",a.setAttribute("data-remove-on-unload",""),
|
|
115
|
+
a.type="application/json",a.innerText=JSON.stringify(s);const l=document.createElement("script");l.async=!0,l.src=e.clientUrl;const c=t.contentDocument;c.body.appendChild(a),c.body.appendChild(l)}function mo(t=document){return t.querySelector("mosaic-book")}function _o(t=window){var e;if(mo(t.document))return"container";const n=null===(e=t.frameElement)||void 0===e?void 0:e.ownerDocument;return n&&mo(n)?"content":null}class vo{constructor(t){Ct(this,"_frameObserver",void 0);const e=mo();if(!e)throw new Error("Book container element not found");const n=new WeakSet,i=e.shadowRoot,o=()=>{const e=i.querySelector("iframe");e&&!n.has(e)&&(n.add(e),uo(e,((n,i)=>{if(n)return;const o=i.body;o&&!o.querySelector("#page-content")&&go(e,t,"vitalsource-content")})))};o(),this._frameObserver=new MutationObserver(o),this._frameObserver.observe(i,{childList:!0,subtree:!0})}destroy(){this._frameObserver.disconnect()}}function yo(){return document.querySelector("img#pbk-page")}class bo extends Pt{constructor(t=document.body,e){
|
|
116
|
+
var n;super(),Ct(this,"_bookElement",void 0),Ct(this,"_features",void 0),Ct(this,"_htmlIntegration",void 0),Ct(this,"_listeners",void 0),Ct(this,"_textLayer",void 0),this._features=e.features;const i=null!==(n=e.bookElement)&&void 0!==n?n:mo(window.parent.document);if(!i)throw new Error("Failed to find <mosaic-book> element in container frame");this._bookElement=i,this._features.on("flagsChanged",(()=>{this.emit("uriChanged")}));const o=new wn;o.update({html_side_by_side:!0}),this._htmlIntegration=new mi({container:t,features:o}),this._listeners=new xt;const r=["mouseup","mousedown","mouseout"];for(const t of r)this._listeners.add(document.documentElement,t,(t=>{t.stopPropagation()}));const s=window.frameElement;s&&function(t){if("no"!==t.getAttribute("scrolling"))return;const e=document.createElement("style");e.textContent="iframe { height: 100% !important; }",t.insertAdjacentElement("beforebegin",e);const n=()=>t.removeAttribute("scrolling");n(),new MutationObserver(n).observe(t,{attributes:!0})}(s)
|
|
117
|
+
;const a=yo(),l=window.innerPageData;if(a&&l){const t=l.glyphs.glyphs.map((t=>{const e=t.l/100,n=t.r/100,i=t.t/100,o=t.b/100;return new DOMRect(e,i,n-e,o-i)}));this._textLayer=new fo(a,t,l.words),this._textLayer.container.style.zIndex="100"}}getAnnotatableRange(t){return this._htmlIntegration.getAnnotatableRange(t)}destroy(){var t;null===(t=this._textLayer)||void 0===t||t.destroy(),this._listeners.removeAll(),this._htmlIntegration.destroy()}anchor(t,e){return this._htmlIntegration.anchor(t,e)}async describe(t,e){const n=this._htmlIntegration.describe(t,e),{cfi:i,index:o,page:r,title:s,url:a}=await this._getPageInfo(!0),l=[{type:"EPUBContentSelector",cfi:i,url:a,title:s}];return"pbk"===this._bookElement.getBookInfo().format&&l.push({type:"PageSelector",index:o,label:r}),n.push(...l),n}contentContainer(){return this._htmlIntegration.contentContainer()}fitSideBySide(t){const e=yo();if(e&&this._textLayer){const n=e.parentElement,i=this._textLayer,o=window.innerWidth-t.width;return ei((()=>{
|
|
118
|
+
t.expanded&&o>480?(n.style.textAlign="left",e.style.width=`${o}px`):(n.style.textAlign="",e.style.width=""),i.updateSync()})),t.expanded}return this._htmlIntegration.fitSideBySide(t)}async getMetadata(){if(this._bookIsSingleDocument()){return{title:this._bookElement.getBookInfo().title,link:[]}}return{title:document.title,link:[]}}navigateToSegment(t){var e;const n=null===(e=t.target[0].selector)||void 0===e?void 0:e.find((t=>"EPUBContentSelector"===t.type));if(null!=n&&n.cfi)this._bookElement.goToCfi(n.cfi);else{if(null==n||!n.url)throw new Error("No segment information available");this._bookElement.goToURL(function(t){const e=new URL(t,document.baseURI);return e.pathname+e.search}(n.url))}}persistFrame(){return!0}async _getPageInfo(t){const[e,n]=await Promise.all([this._bookElement.getCurrentPage(),t?this._bookElement.getTOC():void 0]);let i;if(n){var o;i=e.chapterTitle;const t=lo(e.cfi),r=null===(o=n.data)||void 0===o?void 0:o.find((e=>lo(e.cfi)===t));r&&(i=r.title)}return{cfi:e.cfi,index:e.index,
|
|
119
|
+
page:e.page,title:i,url:new URL(e.absoluteURL,document.baseURI).toString()}}async segmentInfo(){const{cfi:t,url:e}=await this._getPageInfo(!1);return{cfi:t,url:e}}async uri(){if(this._bookIsSingleDocument()){return`https://bookshelf.vitalsource.com/reader/books/${this._bookElement.getBookInfo().isbn}`}const t=new URL(document.location.href);return t.search="",t.toString()}async scrollToAnchor(t){return this._htmlIntegration.scrollToAnchor(t)}_bookIsSingleDocument(){return this._features.flagEnabled("book_as_single_document")}waitForFeatureFlags(){return!0}}function wo(t){if(void 0!==window.PDFViewerApplication)return new ao(t);return"content"===_o()?new bo(document.body,{features:t.features}):new mi({features:t.features})}function Co(t){const e=t.getSelection();if(!e||0===e.rangeCount)return null;const n=e.getRangeAt(0);return n.collapsed?null:n}class xo{constructor(t,e=document){let n=!1;this._pendingCallback=null;const i=(n=10)=>{this._pendingCallback=setTimeout((()=>{t(Co(e))}),n)},o=t=>{
|
|
120
|
+
if("mousedown"===t.type&&(n=!0),"mouseup"===t.type&&(n=!1),n)return;this._cancelPendingCallback();const e="mouseup"===t.type?10:100;i(e)};this._document=e,this._listeners=new xt,this._listeners.add(e,"selectionchange",o),this._listeners.add(e.body,"mousedown",o),this._listeners.add(e.body,"mouseup",o),i(1)}disconnect(){this._listeners.removeAll(),this._cancelPendingCallback()}_cancelPendingCallback(){this._pendingCallback&&(clearTimeout(this._pendingCallback),this._pendingCallback=null)}}function So(){const t=function(t,e){const n=new Set,i=new Set;return Ke(t,(t=>{let o=t;for(;o&&!n.has(o);){n.add(o);const t=e(o);null!=t&&i.add(t),o=o.parentNode}})),[...i]}(window.getSelection().getRangeAt(0),(t=>{var e;return null===(e=t._annotation)||void 0===e?void 0:e.$tag}));return t}function Eo(t){const e=function(t){let e=t.nodeType===Node.ELEMENT_NODE?t:t.parentElement;const n=[];for(;e;)e.classList.contains("hypothesis-highlight")&&n.push(e),e=e.parentElement;return n
|
|
121
|
+
}(t).map((t=>t._annotation)).filter((t=>void 0!==t)).map((t=>null==t?void 0:t.$tag));return e}function No(t){if(!t.range)return null;try{return t.range.toRange()}catch{return null}}function ko(){var t;null===(t=document.getSelection())||void 0===t||t.removeAllRanges()}class Ao extends Pt{constructor(t,e={},n=window){var i,o,r,s,a;(super(),Ct(this,"element",void 0),Ct(this,"selectedRanges",void 0),Ct(this,"anchors",void 0),Ct(this,"features",void 0),Ct(this,"_featureFlagsReceived",void 0),Ct(this,"_adder",void 0),Ct(this,"_clusterToolbar",void 0),Ct(this,"_hostFrame",void 0),Ct(this,"_highlightsVisible",void 0),Ct(this,"_isAdderVisible",void 0),Ct(this,"_informHostOnNextSelectionClear",void 0),Ct(this,"_selectionObserver",void 0),Ct(this,"_annotations",void 0),Ct(this,"_frameIdentifier",void 0),Ct(this,"_portFinder",void 0),Ct(this,"_integration",void 0),Ct(this,"_hostRPC",void 0),Ct(this,"_sidebarRPC",void 0),Ct(this,"_bucketBarClient",void 0),Ct(this,"_sideBySideActive",void 0),Ct(this,"_listeners",void 0),
|
|
122
|
+
Ct(this,"_hoveredAnnotations",void 0),this.element=t,this._hostFrame=n,this._highlightsVisible=!1,this._isAdderVisible=!1,this._informHostOnNextSelectionClear=!0,this.selectedRanges=[],this._adder=new Fe(this.element,{onAnnotate:()=>this.createAnnotation(),onHighlight:()=>this.createAnnotation({highlight:!0}),onShowAnnotations:t=>this.selectAnnotations(t,{focusInSidebar:!0})}),this._selectionObserver=new xo((t=>{t?this._onSelection(t):this._onClearSelection()})),this.anchors=[],this._annotations=new Set,this._frameIdentifier=e.subFrameIdentifier||null,this._portFinder=new At({hostFrame:this._hostFrame,source:"guest",sourceId:null!==(i=this._frameIdentifier)&&void 0!==i?i:void 0}),this.features=new wn,this._featureFlagsReceived=new Promise((t=>{this.features.on("flagsChanged",t)})),this._integration=wo(this),this._integration.on("uriChanged",(()=>this._sendDocumentInfo())),e.contentInfoBanner)&&(null===(s=(a=this._integration).showContentInfo)||void 0===s||s.call(a,e.contentInfoBanner))
|
|
123
|
+
;null!==(o=(r=this._integration).canStyleClusteredHighlights)&&void 0!==o&&o.call(r)&&(this._clusterToolbar=new _n(this._integration.contentContainer(),{features:this.features})),this._hostRPC=new Ut,this._connectHost(n),this._sidebarRPC=new Ut,this._connectSidebar(),this._bucketBarClient=new dn({contentContainer:this._integration.contentContainer(),hostRPC:this._hostRPC}),this._sideBySideActive=!1,this._listeners=new xt,this._setupElementEvents(),this._hoveredAnnotations=new Set}_setupElementEvents(){const t=t=>{this._sideBySideActive||Eo(t).length||this._sidebarRPC.call("closeSidebar")};this._listeners.add(this.element,"mouseup",(t=>{const{target:e,metaKey:n,ctrlKey:i}=t,o=Eo(e);if(o.length&&this._highlightsVisible){const t=n||i;this.selectAnnotations(o,{toggle:t})}})),this._listeners.add(this.element,"mousedown",(({target:e})=>{t(e)})),this._listeners.add(this.element,"touchstart",(({target:e})=>{t(e)})),this._listeners.add(this.element,"mouseover",(({target:t})=>{const e=Eo(t)
|
|
124
|
+
;e.length&&this._highlightsVisible&&this._sidebarRPC.call("hoverAnnotations",e)})),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(){var t,e,n,i,o;const[r,s,a]=await Promise.all([this._integration.uri(),this._integration.getMetadata(),null===(t=(e=this._integration).segmentInfo)||void 0===t?void 0:t.call(e)]);return{uri:Vn(r),metadata:s,segmentInfo:a,persistent:null!==(n=null===(i=(o=this._integration).persistFrame)||void 0===i?void 0:i.call(o))&&void 0!==n&&n}}async _sendDocumentInfo(){var t,e;null!==(t=(e=this._integration).waitForFeatureFlags)&&void 0!==t&&t.call(e)&&await this._featureFlagsReceived;const n=await this.getDocumentInfo();this._sidebarRPC.call("documentInfoChanged",n)}_repositionAdder(){var t;if(!1===this._isAdderVisible)return
|
|
125
|
+
;const e=null===(t=window.getSelection())||void 0===t?void 0:t.getRangeAt(0);e&&this._onSelection(e)}async _connectHost(t){this._hostRPC.on("clearSelection",(()=>{Co(document)&&(this._informHostOnNextSelectionClear=!1,ko())})),this._hostRPC.on("createAnnotation",(()=>this.createAnnotation())),this._hostRPC.on("hoverAnnotations",(t=>this._hoverAnnotations(t))),this._hostRPC.on("scrollToClosestOffScreenAnchor",((t,e)=>this._scrollToClosestOffScreenAnchor(t,e))),this._hostRPC.on("selectAnnotations",((t,e)=>this.selectAnnotations(t,{toggle:e}))),this._hostRPC.on("sidebarLayoutChanged",(e=>{var n,i;((n=window)===(i=t)||n.parent===i&&n.frameElement&&n.frameElement.getBoundingClientRect().width/n.parent.innerWidth>=.8)&&this.fitSideBySide(e)})),this._hostRPC.on("close",(()=>this.emit("hostDisconnected")));const e=await this._portFinder.discover("host");this._hostRPC.connect(e)}async _connectSidebar(){this._sidebarRPC.on("featureFlagsUpdated",(t=>this.features.update(t))),
|
|
126
|
+
this._sidebarRPC.on("hoverAnnotations",(t=>this._hoverAnnotations(t))),this._sidebarRPC.on("scrollToAnnotation",(t=>{const e=this.anchors.find((e=>e.annotation.$tag===t));if(null==e||!e.highlights)return;const n=No(e);if(!n)return;const i=new CustomEvent("scrolltorange",{bubbles:!0,cancelable:!0,detail:n});this.element.dispatchEvent(i)&&this._integration.scrollToAnchor(e)})),this._sidebarRPC.on("setHighlightsVisible",(t=>{this.setHighlightsVisible(t,!1)})),this._sidebarRPC.on("deleteAnnotation",(t=>this.detach(t))),this._sidebarRPC.on("loadAnnotations",(t=>t.forEach((t=>this.anchor(t))))),this._sidebarRPC.on("showContentInfo",(t=>{var e,n;return null===(e=(n=this._integration).showContentInfo)||void 0===e?void 0:e.call(n,t)})),this._sidebarRPC.on("navigateToSegment",(t=>{var e,n;return null===(e=(n=this._integration).navigateToSegment)||void 0===e?void 0:e.call(n,t)})),this._portFinder.discover("sidebar").then((t=>{this._sidebarRPC.connect(t)})),this._sendDocumentInfo()}destroy(){var t
|
|
127
|
+
;this._portFinder.destroy(),this._hostRPC.destroy(),this._sidebarRPC.destroy(),this._listeners.removeAll(),this._selectionObserver.disconnect(),this._adder.destroy(),this._bucketBarClient.destroy(),null===(t=this._clusterToolbar)||void 0===t||t.destroy(),function(t){on(Array.from(t.querySelectorAll("hypothesis-highlight")))}(this.element),this._integration.destroy()}async anchor(t){const e=t=>{var e;const n=No(t);if(!n)return;const i=en(n,null===(e=t.annotation)||void 0===e?void 0:e.$cluster);i.forEach((e=>{e._annotation=t.annotation})),t.highlights=i,this._hoveredAnnotations.has(t.annotation.$tag)&&rn(i,!0)};this.detach(t.$tag,!1),this._annotations.add(t.$tag),t.target||(t.target=[]);const n=await Promise.all(t.target.map((async e=>{if(!e.selector||!e.selector.some((t=>"TextQuoteSelector"===t.type)))return{annotation:t,target:e};let n;try{const i=await this._integration.anchor(this.element,e.selector),o=$e.fromRange(i);n={annotation:t,target:e,range:o}}catch(i){n={annotation:t,target:e}}return n})))
|
|
128
|
+
;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.range)),this._updateAnchors(this.anchors.concat(n),!0),this._sidebarRPC.call("syncAnchoringStatus",t),n}detach(t,e=!0){this._annotations.delete(t);const n=[];for(const e of this.anchors)e.annotation.$tag!==t?n.push(e):e.highlights&&on(e.highlights);this._updateAnchors(n,e)}_updateAnchors(t,e){var n;this.anchors=t,null===(n=this._clusterToolbar)||void 0===n||n.scheduleClusterUpdates(),e&&this._bucketBarClient.update(this.anchors)}async createAnnotation({highlight:t=!1}={}){const e=this.selectedRanges;this.selectedRanges=[];const n=await this.getDocumentInfo(),i=this.element,o=(await Promise.all(e.map((t=>this._integration.describe(i,t))))).map((t=>({source:n.uri,selector:t}))),r={uri:n.uri,document:n.metadata,target:o,$highlight:t,$cluster:t?"user-highlights":"user-annotations",$tag:"a:"+Et(8)};return this._sidebarRPC.call("createAnnotation",r),this.anchor(r),ko(),r}
|
|
129
|
+
_hoverAnnotations(t){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);rn(e.highlights,n)}this._sidebarRPC.call("hoverAnnotations",t)}_scrollToClosestOffScreenAnchor(t,e){const n=function(t,e){let n=null,i=0;for(let r of t){var o;if(null===(o=r.highlights)||void 0===o||!o.length)continue;const t=sn(r.highlights).top;"up"===e&&t>=137||"down"===e&&t<=window.innerHeight-22||(!n||"up"===e&&t>i||"down"===e&&t<i)&&(n=r,i=t)}return n}(this.anchors.filter((({annotation:e})=>t.includes(e.$tag))),e);n&&this._integration.scrollToAnchor(n)}_onSelection(t){const e=this._integration.getAnnotatableRange(t);if(!e)return void this._onClearSelection();const n=document.getSelection(),i=Ze(n),o=Qe(n);o?(this.selectedRanges=[e],this._hostRPC.call("textSelected"),this._adder.annotationsForSelection=So(),this._isAdderVisible=!0,this._adder.show(o,i)):this._onClearSelection()}_onClearSelection(){this._isAdderVisible=!1,
|
|
130
|
+
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")}setHighlightsVisible(t,e=!0){!function(t,e){t.classList.toggle("hypothesis-highlights-always-on",e)}(this.element,t),this._highlightsVisible=t,e&&this._hostRPC.call("highlightsVisibleChanged",t)}get highlightsVisible(){return this._highlightsVisible}fitSideBySide(t){this._sideBySideActive=this._integration.fitSideBySide(t)}get sideBySideActive(){return this._sideBySideActive}get hoveredAnnotationTags(){return this._hoveredAnnotations}_handleShortcut(t){Jt(t,"Ctrl+Shift+H")&&this.setHighlightsVisible(!this._highlightsVisible)}}function To(t,e){const n=new URL(t),i=new URLSearchParams;return i.append("config",JSON.stringify(e)),n.hash=i.toString(),n.toString()}
|
|
131
|
+
function Ro(t,e){var n;const i={};for(let[t,n]of Object.entries(e))"notebookAppUrl"!==t&&"sidebarAppUrl"!==t&&null!=n&&(i[t]=n);i.origin=new URL(t).origin,i.version="1.1199.0";const o=new URL(window.location.href);if(o.hash="",i.hostURL=o.toString(),Array.isArray(i.services)&&(null===(n=i.services)||void 0===n?void 0:n.length)>0){const t=i.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 i}function Lo({config:t,groupId:e}){return ht("iframe",{title:"Hypothesis annotation notebook",className:"h-full w-full border-0",allowFullScreen:!0,src:To(t.notebookAppUrl,{...Ro(t.notebookAppUrl,t),group:e})})}function Po({eventBus:t,config:e}){const[n,i]=K(0),[o,r]=K(!0),[s,a]=K(null),l=tt(""),c=tt(null);Q((()=>(l.current=document.body.style.overflow,()=>{document.body.style.overflow=l.current})),[]),Q((()=>{
|
|
132
|
+
document.body.style.overflow=o?l.current:"hidden"}),[o]),Q((()=>{const e=t.createEmitter();return e.subscribe("openNotebook",(t=>{r(!1),i((t=>t+1)),a(t)})),c.current=e,()=>{e.destroy()}}),[t]);return null===s?null:ht("div",{className:h("fixed z-max top-0 left-0 right-0 bottom-0 p-3 bg-black/50",{hidden:o}),"data-testid":"notebook-outer",children:ht("div",{className:"relative w-full h-full","data-testid":"notebook-inner",children:[ht("div",{className:"absolute right-0 m-3",children:ht(Se,{title:"Close the Notebook",onClick:()=>{var t;r(!0),null===(t=c.current)||void 0===t||t.publish("closeNotebook")},variant:"dark",children:ht(oe,{className:"w-4 h-4"})})}),ht(Lo,{config:e,groupId:s},n)]})})}class Oo{constructor(t,e,n){this._outerContainer=document.createElement("hypothesis-notebook"),t.appendChild(this._outerContainer),this.shadowRoot=Ie(this._outerContainer),B(ht(Po,{eventBus:e,config:n}),this.shadowRoot)}destroy(){B(null,this.shadowRoot),this._outerContainer.remove()}}var Mo={},Io={get exports(){return Mo},
|
|
133
|
+
set exports(t){Mo=t}};!function(t){!function(e,n,i,o){var r,s=["","webkit","Moz","MS","ms","o"],a=n.createElement("div"),l=Math.round,c=Math.abs,h=Date.now;function u(t,e,n){return setTimeout(v(t,n),e)}function d(t,e,n){return!!Array.isArray(t)&&(f(t,n[e],n),!0)}function f(t,e,n){var i;if(t)if(t.forEach)t.forEach(e,n);else if(t.length!==o)for(i=0;i<t.length;)e.call(n,t[i],i,t),i++;else for(i in t)t.hasOwnProperty(i)&&e.call(n,t[i],i,t)}function p(t,n,i){var o="DEPRECATED METHOD: "+n+"\n"+i+" AT \n";return function(){var n=new Error("get-stack-trace"),i=n&&n.stack?n.stack.replace(/^[^\(]+?[\n$]/gm,"").replace(/^\s+at\s+/gm,"").replace(/^Object.<anonymous>\s*\(/gm,"{anonymous}()@"):"Unknown Stack Trace",r=e.console&&(e.console.warn||e.console.log);return r&&r.call(e.console,o,i),t.apply(this,arguments)}}r="function"!=typeof Object.assign?function(t){if(t===o||null===t)throw new TypeError("Cannot convert undefined or null to object");for(var e=Object(t),n=1;n<arguments.length;n++){var i=arguments[n]
|
|
134
|
+
;if(i!==o&&null!==i)for(var r in i)i.hasOwnProperty(r)&&(e[r]=i[r])}return e}:Object.assign;var g=p((function(t,e,n){for(var i=Object.keys(e),r=0;r<i.length;)(!n||n&&t[i[r]]===o)&&(t[i[r]]=e[i[r]]),r++;return t}),"extend","Use `assign`."),m=p((function(t,e){return g(t,e,!0)}),"merge","Use `assign`.");function _(t,e,n){var i,o=e.prototype;(i=t.prototype=Object.create(o)).constructor=t,i._super=o,n&&r(i,n)}function v(t,e){return function(){return t.apply(e,arguments)}}function y(t,e){return"function"==typeof t?t.apply(e&&e[0]||o,e):t}function b(t,e){return t===o?e:t}function w(t,e,n){f(E(e),(function(e){t.addEventListener(e,n,!1)}))}function C(t,e,n){f(E(e),(function(e){t.removeEventListener(e,n,!1)}))}function x(t,e){for(;t;){if(t==e)return!0;t=t.parentNode}return!1}function S(t,e){return t.indexOf(e)>-1}function E(t){return t.trim().split(/\s+/g)}function N(t,e,n){if(t.indexOf&&!n)return t.indexOf(e);for(var i=0;i<t.length;){if(n&&t[i][n]==e||!n&&t[i]===e)return i;i++}return-1}function k(t){
|
|
135
|
+
return Array.prototype.slice.call(t,0)}function A(t,e,n){for(var i=[],o=[],r=0;r<t.length;){var s=e?t[r][e]:t[r];N(o,s)<0&&i.push(t[r]),o[r]=s,r++}return n&&(i=e?i.sort((function(t,n){return t[e]>n[e]})):i.sort()),i}function T(t,e){for(var n,i,r=e[0].toUpperCase()+e.slice(1),a=0;a<s.length;){if((i=(n=s[a])?n+r:e)in t)return i;a++}return o}var R=1;function L(t){var n=t.ownerDocument||t;return n.defaultView||n.parentWindow||e}var P="ontouchstart"in e,O=T(e,"PointerEvent")!==o,M=P&&/mobile|tablet|ip(ad|hone|od)|android/i.test(navigator.userAgent),I="touch",B="mouse",F=24,D=["x","y"],H=["clientX","clientY"];function V(t,e){var n=this;this.manager=t,this.callback=e,this.element=t.element,this.target=t.options.inputTarget,this.domHandler=function(e){y(t.options.enable,[t])&&n.handler(e)},this.init()}function q(t,e,n){var i=n.pointers.length,r=n.changedPointers.length,s=1&e&&i-r==0,a=12&e&&i-r==0;n.isFirst=!!s,n.isFinal=!!a,s&&(t.session={}),n.eventType=e,function(t,e){var n=t.session,i=e.pointers,r=i.length
|
|
136
|
+
;n.firstInput||(n.firstInput=U(e));r>1&&!n.firstMultiple?n.firstMultiple=U(e):1===r&&(n.firstMultiple=!1);var s=n.firstInput,a=n.firstMultiple,l=a?a.center:s.center,u=e.center=z(i);e.timeStamp=h(),e.deltaTime=e.timeStamp-s.timeStamp,e.angle=X(l,u),e.distance=$(l,u),function(t,e){var n=e.center,i=t.offsetDelta||{},o=t.prevDelta||{},r=t.prevInput||{};1!==e.eventType&&4!==r.eventType||(o=t.prevDelta={x:r.deltaX||0,y:r.deltaY||0},i=t.offsetDelta={x:n.x,y:n.y});e.deltaX=o.x+(n.x-i.x),e.deltaY=o.y+(n.y-i.y)}(n,e),e.offsetDirection=j(e.deltaX,e.deltaY);var d=W(e.deltaTime,e.deltaX,e.deltaY);e.overallVelocityX=d.x,e.overallVelocityY=d.y,e.overallVelocity=c(d.x)>c(d.y)?d.x:d.y,e.scale=a?(f=a.pointers,p=i,$(p[0],p[1],H)/$(f[0],f[1],H)):1,e.rotation=a?function(t,e){return X(e[1],e[0],H)+X(t[1],t[0],H)}(a.pointers,i):0,e.maxPointers=n.prevInput?e.pointers.length>n.prevInput.maxPointers?e.pointers.length:n.prevInput.maxPointers:e.pointers.length,function(t,e){var n,i,r,s,a=t.lastInterval||e,l=e.timeStamp-a.timeStamp
|
|
137
|
+
;if(8!=e.eventType&&(l>25||a.velocity===o)){var h=e.deltaX-a.deltaX,u=e.deltaY-a.deltaY,d=W(l,h,u);i=d.x,r=d.y,n=c(d.x)>c(d.y)?d.x:d.y,s=j(h,u),t.lastInterval=e}else n=a.velocity,i=a.velocityX,r=a.velocityY,s=a.direction;e.velocity=n,e.velocityX=i,e.velocityY=r,e.direction=s}(n,e);var f,p;var g=t.element;x(e.srcEvent.target,g)&&(g=e.srcEvent.target);e.target=g}(t,n),t.emit("hammer.input",n),t.recognize(n),t.session.prevInput=n}function U(t){for(var e=[],n=0;n<t.pointers.length;)e[n]={clientX:l(t.pointers[n].clientX),clientY:l(t.pointers[n].clientY)},n++;return{timeStamp:h(),pointers:e,center:z(e),deltaX:t.deltaX,deltaY:t.deltaY}}function z(t){var e=t.length;if(1===e)return{x:l(t[0].clientX),y:l(t[0].clientY)};for(var n=0,i=0,o=0;o<e;)n+=t[o].clientX,i+=t[o].clientY,o++;return{x:l(n/e),y:l(i/e)}}function W(t,e,n){return{x:e/t||0,y:n/t||0}}function j(t,e){return t===e?1:c(t)>=c(e)?t<0?2:4:e<0?8:16}function $(t,e,n){n||(n=D);var i=e[n[0]]-t[n[0]],o=e[n[1]]-t[n[1]];return Math.sqrt(i*i+o*o)}function X(t,e,n){
|
|
138
|
+
n||(n=D);var i=e[n[0]]-t[n[0]],o=e[n[1]]-t[n[1]];return 180*Math.atan2(o,i)/Math.PI}V.prototype={handler:function(){},init:function(){this.evEl&&w(this.element,this.evEl,this.domHandler),this.evTarget&&w(this.target,this.evTarget,this.domHandler),this.evWin&&w(L(this.element),this.evWin,this.domHandler)},destroy:function(){this.evEl&&C(this.element,this.evEl,this.domHandler),this.evTarget&&C(this.target,this.evTarget,this.domHandler),this.evWin&&C(L(this.element),this.evWin,this.domHandler)}};var Y={mousedown:1,mousemove:2,mouseup:4},Z="mousedown",G="mousemove mouseup";function K(){this.evEl=Z,this.evWin=G,this.pressed=!1,V.apply(this,arguments)}_(K,V,{handler:function(t){var e=Y[t.type];1&e&&0===t.button&&(this.pressed=!0),2&e&&1!==t.which&&(e=4),this.pressed&&(4&e&&(this.pressed=!1),this.callback(this.manager,e,{pointers:[t],changedPointers:[t],pointerType:B,srcEvent:t}))}});var Q={pointerdown:1,pointermove:2,pointerup:4,pointercancel:8,pointerout:8},J={2:I,3:"pen",4:B,5:"kinect"
|
|
139
|
+
},tt="pointerdown",et="pointermove pointerup pointercancel";function nt(){this.evEl=tt,this.evWin=et,V.apply(this,arguments),this.store=this.manager.session.pointerEvents=[]}e.MSPointerEvent&&!e.PointerEvent&&(tt="MSPointerDown",et="MSPointerMove MSPointerUp MSPointerCancel"),_(nt,V,{handler:function(t){var e=this.store,n=!1,i=t.type.toLowerCase().replace("ms",""),o=Q[i],r=J[t.pointerType]||t.pointerType,s=r==I,a=N(e,t.pointerId,"pointerId");1&o&&(0===t.button||s)?a<0&&(e.push(t),a=e.length-1):12&o&&(n=!0),a<0||(e[a]=t,this.callback(this.manager,o,{pointers:e,changedPointers:[t],pointerType:r,srcEvent:t}),n&&e.splice(a,1))}});var it={touchstart:1,touchmove:2,touchend:4,touchcancel:8},ot="touchstart",rt="touchstart touchmove touchend touchcancel";function st(){this.evTarget=ot,this.evWin=rt,this.started=!1,V.apply(this,arguments)}function at(t,e){var n=k(t.touches),i=k(t.changedTouches);return 12&e&&(n=A(n.concat(i),"identifier",!0)),[n,i]}_(st,V,{handler:function(t){var e=it[t.type]
|
|
140
|
+
;if(1===e&&(this.started=!0),this.started){var n=at.call(this,t,e);12&e&&n[0].length-n[1].length==0&&(this.started=!1),this.callback(this.manager,e,{pointers:n[0],changedPointers:n[1],pointerType:I,srcEvent:t})}}});var lt={touchstart:1,touchmove:2,touchend:4,touchcancel:8},ct="touchstart touchmove touchend touchcancel";function ht(){this.evTarget=ct,this.targetIds={},V.apply(this,arguments)}function ut(t,e){var n=k(t.touches),i=this.targetIds;if(3&e&&1===n.length)return i[n[0].identifier]=!0,[n,n];var o,r,s=k(t.changedTouches),a=[],l=this.target;if(r=n.filter((function(t){return x(t.target,l)})),1===e)for(o=0;o<r.length;)i[r[o].identifier]=!0,o++;for(o=0;o<s.length;)i[s[o].identifier]&&a.push(s[o]),12&e&&delete i[s[o].identifier],o++;return a.length?[A(r.concat(a),"identifier",!0),a]:void 0}_(ht,V,{handler:function(t){var e=lt[t.type],n=ut.call(this,t,e);n&&this.callback(this.manager,e,{pointers:n[0],changedPointers:n[1],pointerType:I,srcEvent:t})}});function dt(){V.apply(this,arguments)
|
|
141
|
+
;var t=v(this.handler,this);this.touch=new ht(this.manager,t),this.mouse=new K(this.manager,t),this.primaryTouch=null,this.lastTouches=[]}function ft(t,e){1&t?(this.primaryTouch=e.changedPointers[0].identifier,pt.call(this,e)):12&t&&pt.call(this,e)}function pt(t){var e=t.changedPointers[0];if(e.identifier===this.primaryTouch){var n={x:e.clientX,y:e.clientY};this.lastTouches.push(n);var i=this.lastTouches;setTimeout((function(){var t=i.indexOf(n);t>-1&&i.splice(t,1)}),2500)}}function gt(t){for(var e=t.srcEvent.clientX,n=t.srcEvent.clientY,i=0;i<this.lastTouches.length;i++){var o=this.lastTouches[i],r=Math.abs(e-o.x),s=Math.abs(n-o.y);if(r<=25&&s<=25)return!0}return!1}_(dt,V,{handler:function(t,e,n){var i=n.pointerType==I,o=n.pointerType==B;if(!(o&&n.sourceCapabilities&&n.sourceCapabilities.firesTouchEvents)){if(i)ft.call(this,e,n);else if(o&>.call(this,n))return;this.callback(t,e,n)}},destroy:function(){this.touch.destroy(),this.mouse.destroy()}})
|
|
142
|
+
;var mt=T(a.style,"touchAction"),_t=mt!==o,vt="compute",yt="auto",bt="manipulation",wt="none",Ct="pan-x",xt="pan-y",St=function(){if(!_t)return!1;var t={},n=e.CSS&&e.CSS.supports;return["auto","manipulation","pan-y","pan-x","pan-x pan-y","none"].forEach((function(i){t[i]=!n||e.CSS.supports("touch-action",i)})),t}();function Et(t,e){this.manager=t,this.set(e)}Et.prototype={set:function(t){t==vt&&(t=this.compute()),_t&&this.manager.element.style&&St[t]&&(this.manager.element.style[mt]=t),this.actions=t.toLowerCase().trim()},update:function(){this.set(this.manager.options.touchAction)},compute:function(){var t=[];return f(this.manager.recognizers,(function(e){y(e.options.enable,[e])&&(t=t.concat(e.getTouchAction()))})),function(t){if(S(t,wt))return wt;var e=S(t,Ct),n=S(t,xt);if(e&&n)return wt;if(e||n)return e?Ct:xt;if(S(t,bt))return bt;return yt}(t.join(" "))},preventDefaults:function(t){var e=t.srcEvent,n=t.offsetDirection;if(this.manager.session.prevented)e.preventDefault();else{
|
|
143
|
+
var i=this.actions,o=S(i,wt)&&!St.none,r=S(i,xt)&&!St["pan-y"],s=S(i,Ct)&&!St["pan-x"];if(o){var a=1===t.pointers.length,l=t.distance<2,c=t.deltaTime<250;if(a&&l&&c)return}if(!s||!r)return o||r&&6&n||s&&n&F?this.preventSrc(e):void 0}},preventSrc:function(t){this.manager.session.prevented=!0,t.preventDefault()}};var Nt=32;function kt(t){this.options=r({},this.defaults,t||{}),this.id=R++,this.manager=null,this.options.enable=b(this.options.enable,!0),this.state=1,this.simultaneous={},this.requireFail=[]}function At(t){return 16&t?"cancel":8&t?"end":4&t?"move":2&t?"start":""}function Tt(t){return 16==t?"down":8==t?"up":2==t?"left":4==t?"right":""}function Rt(t,e){var n=e.manager;return n?n.get(t):t}function Lt(){kt.apply(this,arguments)}function Pt(){Lt.apply(this,arguments),this.pX=null,this.pY=null}function Ot(){Lt.apply(this,arguments)}function Mt(){kt.apply(this,arguments),this._timer=null,this._input=null}function It(){Lt.apply(this,arguments)}function Bt(){Lt.apply(this,arguments)}function Ft(){
|
|
144
|
+
kt.apply(this,arguments),this.pTime=!1,this.pCenter=!1,this._timer=null,this._input=null,this.count=0}function Dt(t,e){return(e=e||{}).recognizers=b(e.recognizers,Dt.defaults.preset),new Ht(t,e)}kt.prototype={defaults:{},set:function(t){return r(this.options,t),this.manager&&this.manager.touchAction.update(),this},recognizeWith:function(t){if(d(t,"recognizeWith",this))return this;var e=this.simultaneous;return e[(t=Rt(t,this)).id]||(e[t.id]=t,t.recognizeWith(this)),this},dropRecognizeWith:function(t){return d(t,"dropRecognizeWith",this)||(t=Rt(t,this),delete this.simultaneous[t.id]),this},requireFailure:function(t){if(d(t,"requireFailure",this))return this;var e=this.requireFail;return-1===N(e,t=Rt(t,this))&&(e.push(t),t.requireFailure(this)),this},dropRequireFailure:function(t){if(d(t,"dropRequireFailure",this))return this;t=Rt(t,this);var e=N(this.requireFail,t);return e>-1&&this.requireFail.splice(e,1),this},hasRequireFailures:function(){return this.requireFail.length>0},canRecognizeWith:function(t){
|
|
145
|
+
return!!this.simultaneous[t.id]},emit:function(t){var e=this,n=this.state;function i(n){e.manager.emit(n,t)}n<8&&i(e.options.event+At(n)),i(e.options.event),t.additionalEvent&&i(t.additionalEvent),n>=8&&i(e.options.event+At(n))},tryEmit:function(t){if(this.canEmit())return this.emit(t);this.state=Nt},canEmit:function(){for(var t=0;t<this.requireFail.length;){if(!(33&this.requireFail[t].state))return!1;t++}return!0},recognize:function(t){var e=r({},t);if(!y(this.options.enable,[this,e]))return this.reset(),void(this.state=Nt);56&this.state&&(this.state=1),this.state=this.process(e),30&this.state&&this.tryEmit(e)},process:function(t){},getTouchAction:function(){},reset:function(){}},_(Lt,kt,{defaults:{pointers:1},attrTest:function(t){var e=this.options.pointers;return 0===e||t.pointers.length===e},process:function(t){var e=this.state,n=t.eventType,i=6&e,o=this.attrTest(t);return i&&(8&n||!o)?16|e:i||o?4&n?8|e:2&e?4|e:2:Nt}}),_(Pt,Lt,{defaults:{event:"pan",threshold:10,pointers:1,direction:30},
|
|
146
|
+
getTouchAction:function(){var t=this.options.direction,e=[];return 6&t&&e.push(xt),t&F&&e.push(Ct),e},directionTest:function(t){var e=this.options,n=!0,i=t.distance,o=t.direction,r=t.deltaX,s=t.deltaY;return o&e.direction||(6&e.direction?(o=0===r?1:r<0?2:4,n=r!=this.pX,i=Math.abs(t.deltaX)):(o=0===s?1:s<0?8:16,n=s!=this.pY,i=Math.abs(t.deltaY))),t.direction=o,n&&i>e.threshold&&o&e.direction},attrTest:function(t){return Lt.prototype.attrTest.call(this,t)&&(2&this.state||!(2&this.state)&&this.directionTest(t))},emit:function(t){this.pX=t.deltaX,this.pY=t.deltaY;var e=Tt(t.direction);e&&(t.additionalEvent=this.options.event+e),this._super.emit.call(this,t)}}),_(Ot,Lt,{defaults:{event:"pinch",threshold:0,pointers:2},getTouchAction:function(){return[wt]},attrTest:function(t){return this._super.attrTest.call(this,t)&&(Math.abs(t.scale-1)>this.options.threshold||2&this.state)},emit:function(t){if(1!==t.scale){var e=t.scale<1?"in":"out";t.additionalEvent=this.options.event+e}this._super.emit.call(this,t)}}),_(Mt,kt,{
|
|
147
|
+
defaults:{event:"press",pointers:1,time:251,threshold:9},getTouchAction:function(){return[yt]},process:function(t){var e=this.options,n=t.pointers.length===e.pointers,i=t.distance<e.threshold,o=t.deltaTime>e.time;if(this._input=t,!i||!n||12&t.eventType&&!o)this.reset();else if(1&t.eventType)this.reset(),this._timer=u((function(){this.state=8,this.tryEmit()}),e.time,this);else if(4&t.eventType)return 8;return Nt},reset:function(){clearTimeout(this._timer)},emit:function(t){8===this.state&&(t&&4&t.eventType?this.manager.emit(this.options.event+"up",t):(this._input.timeStamp=h(),this.manager.emit(this.options.event,this._input)))}}),_(It,Lt,{defaults:{event:"rotate",threshold:0,pointers:2},getTouchAction:function(){return[wt]},attrTest:function(t){return this._super.attrTest.call(this,t)&&(Math.abs(t.rotation)>this.options.threshold||2&this.state)}}),_(Bt,Lt,{defaults:{event:"swipe",threshold:10,velocity:.3,direction:30,pointers:1},getTouchAction:function(){return Pt.prototype.getTouchAction.call(this)},
|
|
148
|
+
attrTest:function(t){var e,n=this.options.direction;return 30&n?e=t.overallVelocity:6&n?e=t.overallVelocityX:n&F&&(e=t.overallVelocityY),this._super.attrTest.call(this,t)&&n&t.offsetDirection&&t.distance>this.options.threshold&&t.maxPointers==this.options.pointers&&c(e)>this.options.velocity&&4&t.eventType},emit:function(t){var e=Tt(t.offsetDirection);e&&this.manager.emit(this.options.event+e,t),this.manager.emit(this.options.event,t)}}),_(Ft,kt,{defaults:{event:"tap",pointers:1,taps:1,interval:300,time:250,threshold:9,posThreshold:10},getTouchAction:function(){return[bt]},process:function(t){var e=this.options,n=t.pointers.length===e.pointers,i=t.distance<e.threshold,o=t.deltaTime<e.time;if(this.reset(),1&t.eventType&&0===this.count)return this.failTimeout();if(i&&o&&n){if(4!=t.eventType)return this.failTimeout();var r=!this.pTime||t.timeStamp-this.pTime<e.interval,s=!this.pCenter||$(this.pCenter,t.center)<e.posThreshold;if(this.pTime=t.timeStamp,this.pCenter=t.center,s&&r?this.count+=1:this.count=1,
|
|
149
|
+
this._input=t,0===this.count%e.taps)return this.hasRequireFailures()?(this._timer=u((function(){this.state=8,this.tryEmit()}),e.interval,this),2):8}return Nt},failTimeout:function(){return this._timer=u((function(){this.state=Nt}),this.options.interval,this),Nt},reset:function(){clearTimeout(this._timer)},emit:function(){8==this.state&&(this._input.tapCount=this.count,this.manager.emit(this.options.event,this._input))}}),Dt.VERSION="2.0.7",Dt.defaults={domEvents:!1,touchAction:vt,enable:!0,inputTarget:null,inputClass:null,preset:[[It,{enable:!1}],[Ot,{enable:!1},["rotate"]],[Bt,{direction:6}],[Pt,{direction:6},["swipe"]],[Ft],[Ft,{event:"doubletap",taps:2},["tap"]],[Mt]],cssProps:{userSelect:"none",touchSelect:"none",touchCallout:"none",contentZooming:"none",userDrag:"none",tapHighlightColor:"rgba(0,0,0,0)"}};function Ht(t,e){var n;this.options=r({},Dt.defaults,e||{}),this.options.inputTarget=this.options.inputTarget||t,this.handlers={},this.session={},this.recognizers=[],this.oldCssProps={},this.element=t,
|
|
150
|
+
this.input=new((n=this).options.inputClass||(O?nt:M?ht:P?dt:K))(n,q),this.touchAction=new Et(this,this.options.touchAction),Vt(this,!0),f(this.options.recognizers,(function(t){var e=this.add(new t[0](t[1]));t[2]&&e.recognizeWith(t[2]),t[3]&&e.requireFailure(t[3])}),this)}function Vt(t,e){var n,i=t.element;i.style&&(f(t.options.cssProps,(function(o,r){n=T(i.style,r),e?(t.oldCssProps[n]=i.style[n],i.style[n]=o):i.style[n]=t.oldCssProps[n]||""})),e||(t.oldCssProps={}))}Ht.prototype={set:function(t){return r(this.options,t),t.touchAction&&this.touchAction.update(),t.inputTarget&&(this.input.destroy(),this.input.target=t.inputTarget,this.input.init()),this},stop:function(t){this.session.stopped=t?2:1},recognize:function(t){var e=this.session;if(!e.stopped){var n;this.touchAction.preventDefaults(t);var i=this.recognizers,o=e.curRecognizer;(!o||o&&8&o.state)&&(o=e.curRecognizer=null);for(var r=0;r<i.length;)n=i[r],2===e.stopped||o&&n!=o&&!n.canRecognizeWith(o)?n.reset():n.recognize(t),
|
|
151
|
+
!o&&14&n.state&&(o=e.curRecognizer=n),r++}},get:function(t){if(t instanceof kt)return t;for(var e=this.recognizers,n=0;n<e.length;n++)if(e[n].options.event==t)return e[n];return null},add:function(t){if(d(t,"add",this))return this;var e=this.get(t.options.event);return e&&this.remove(e),this.recognizers.push(t),t.manager=this,this.touchAction.update(),t},remove:function(t){if(d(t,"remove",this))return this;if(t=this.get(t)){var e=this.recognizers,n=N(e,t);-1!==n&&(e.splice(n,1),this.touchAction.update())}return this},on:function(t,e){if(t!==o&&e!==o){var n=this.handlers;return f(E(t),(function(t){n[t]=n[t]||[],n[t].push(e)})),this}},off:function(t,e){if(t!==o){var n=this.handlers;return f(E(t),(function(t){e?n[t]&&n[t].splice(N(n[t],e),1):delete n[t]})),this}},emit:function(t,e){this.options.domEvents&&function(t,e){var i=n.createEvent("Event");i.initEvent(t,!0,!0),i.gesture=e,e.target.dispatchEvent(i)}(t,e);var i=this.handlers[t]&&this.handlers[t].slice();if(i&&i.length){e.type=t,e.preventDefault=function(){
|
|
152
|
+
e.srcEvent.preventDefault()};for(var o=0;o<i.length;)i[o](e),o++}},destroy:function(){this.element&&Vt(this,!1),this.handlers={},this.session={},this.input.destroy(),this.element=null}},r(Dt,{INPUT_START:1,INPUT_MOVE:2,INPUT_END:4,INPUT_CANCEL:8,STATE_POSSIBLE:1,STATE_BEGAN:2,STATE_CHANGED:4,STATE_ENDED:8,STATE_RECOGNIZED:8,STATE_CANCELLED:16,STATE_FAILED:Nt,DIRECTION_NONE:1,DIRECTION_LEFT:2,DIRECTION_RIGHT:4,DIRECTION_UP:8,DIRECTION_DOWN:16,DIRECTION_HORIZONTAL:6,DIRECTION_VERTICAL:F,DIRECTION_ALL:30,Manager:Ht,Input:V,TouchAction:Et,TouchInput:ht,MouseInput:K,PointerEventInput:nt,TouchMouseInput:dt,SingleTouchInput:st,Recognizer:kt,AttrRecognizer:Lt,Tap:Ft,Pan:Pt,Swipe:Bt,Pinch:Ot,Rotate:It,Press:Mt,on:w,off:C,each:f,merge:m,extend:g,assign:r,inherit:_,bindFn:v,prefixed:T}),(void 0!==e?e:"undefined"!=typeof self?self:{}).Hammer=Dt,t.exports?t.exports=Dt:e.Hammer=Dt}(window,document)}(Io);function Bo({children:t}){return ht("ul",{
|
|
153
|
+
className:h("absolute w-[23px] left-[-22px] h-full","bg-grey-2 sidebar-collapsed:bg-black/[.08]","pointer-events-none"),children:t})}function Fo({children:t,topPosition:e}){return ht("li",{className:h("absolute right-0","pointer-events-auto"),style:{top:e},children:t})}function Do({above:t,below:e,buckets:n,onFocusAnnotations:i,onScrollToClosestOffScreenAnchor:o,onSelectAnnotations:r}){const s=t.tags.size>0,a=e.tags.size>0;return ht(Bo,{children:[s&&ht(Fo,{topPosition:t.position,children:ht(_t,{className:h("BucketButton UpBucketButton","right-0 mt-[-11px]"),"data-testid":"up-navigation-button",onClick:()=>o([...t.tags],"up"),onBlur:()=>i([]),onFocus:()=>i([...t.tags]),onMouseEnter:()=>i([...t.tags]),onMouseOut:()=>i([]),title:`Go up to next annotations (${t.tags.size})`,children:t.tags.size})}),n.map(((t,e)=>ht(Fo,{topPosition:t.position,children:ht(_t,{className:h("BucketButton LeftBucketButton","right-0 mt-[-8px]"),onClick:e=>r([...t.tags],e.metaKey||e.ctrlKey),onBlur:()=>i([]),onFocus:()=>i([...t.tags]),
|
|
154
|
+
onMouseEnter:()=>i([...t.tags]),onMouseOut:()=>i([]),title:`Select nearby annotations (${t.tags.size})`,children:t.tags.size})},e))),a&&ht(Fo,{topPosition:e.position,children:ht(_t,{className:"BucketButton DownBucketButton right-0","data-testid":"down-navigation-button",onClick:()=>o([...e.tags],"down"),onBlur:()=>i([]),onFocus:()=>i([...e.tags]),onMouseEnter:()=>i([...e.tags]),onMouseOut:()=>i([]),title:`Go up to next annotations (${e.tags.size})`,children:e.tags.size})})]})}class Ho{constructor(t,{onFocusAnnotations:e,onScrollToClosestOffScreenAnchor:n,onSelectAnnotations:i}){this._bucketsContainer=document.createElement("div"),t.appendChild(this._bucketsContainer),this._onFocusAnnotations=e,this._onScrollToClosestOffScreenAnchor=n,this._onSelectAnnotations=i,this.update([])}destroy(){B(null,this._bucketsContainer),this._bucketsContainer.remove()}update(t){const e=function(t){const e=new Set,n=new Set,i=[];let o=null;function r({bottom:t,tag:e,top:n}){return{bottom:t,position:n+(t-n)/2,tags:new Set([e]),
|
|
155
|
+
top:n}}return t.forEach((t=>{if(t.top<137)return void e.add(t.tag);if(t.top>window.innerHeight-22)return void n.add(t.tag);if(!o)return void(o=r(t));const s=t.top>o.top&&t.bottom<o.bottom;if(t.top-o.bottom>60&&!s)i.push(o),o=r(t);else{const e=t.bottom>o.bottom?t.bottom:o.bottom,n=e-o.top;o.tags.add(t.tag),o.bottom=e,o.position=o.top+n/2}})),o&&i.push(o),{above:{tags:e,position:137},below:{tags:n,position:window.innerHeight-22},buckets:i}}(t);B(ht(Do,{above:e.above,below:e.below,buckets:e.buckets,onFocusAnnotations:t=>this._onFocusAnnotations(t),onScrollToClosestOffScreenAnchor:(t,e)=>this._onScrollToClosestOffScreenAnchor(t,e),onSelectAnnotations:(t,e)=>this._onSelectAnnotations(t,e)}),this._bucketsContainer)}}function Vo({...t}){const{icon:e,title:n,...i}=t;return ht(mt,{className:h("w-[30px] h-[30px]","rounded-px","flex items-center justify-center","border bg-white text-grey-6 hover:text-grey-9","shadow transition-colors"),icon:e,title:n,...i})}function qo({highlightsVisible:t}){return ht("div",{
|
|
156
|
+
className:"sr-only",role:"status","data-testid":"toolbar-status",children:t?"Highlights visible":"Highlights hidden"})}function Uo({closeSidebar:t,createAnnotation:e,isSidebarOpen:n,newAnnotationType:i,showHighlights:o,toggleHighlights:r,toggleSidebar:s,toggleSidebarRef:a,useMinimalControls:l=!1}){return ht("div",{className:h("absolute left-[-33px] w-[33px] z-2","text-px-base leading-none"),children:[l&&n&&ht(mt,{className:h("w-[27px] h-[27px] mt-[140px] ml-px-1.5","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",icon:"cancel",onClick:t}),!l&&ht(_,{children:[ht(mt,{className:h("h-[40px] w-[33px] pl-px-1.5","bg-white text-grey-5 hover:text-grey-9","border-l border-b"),buttonRef:a,title:"Annotation sidebar",icon:n?"caret-right":"caret-left",expanded:n,pressed:n,onClick:s}),ht("div",{className:"space-y-px-1.5 mt-px-2",children:[ht(Vo,{title:"Show highlights",icon:o?"show":"hide",selected:o,
|
|
157
|
+
onClick:r}),ht(Vo,{title:"note"===i?"New page note":"New annotation",icon:"note"===i?"note":"annotate",onClick:e})]}),ht(qo,{highlightsVisible:o})]})]})}class zo{constructor(t,e){const{createAnnotation:n,setSidebarOpen:i,setHighlightsVisible:o}=e;this._container=t,this._useMinimalControls=!1,this._newAnnotationType="note",this._highlightsVisible=!1,this._sidebarOpen=!1,this._closeSidebar=()=>i(!1),this._toggleSidebar=()=>i(!this._sidebarOpen),this._toggleHighlights=()=>o(!this._highlightsVisible),this._createAnnotation=()=>{n(),i(!0)},this._sidebarToggleButton={current:null},this.render()}getWidth(){return this._container.firstChild.getBoundingClientRect().width}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}
|
|
158
|
+
set highlightsVisible(t){this._highlightsVisible=t,this.render()}get highlightsVisible(){return this._highlightsVisible}get sidebarToggleButton(){return this._sidebarToggleButton.current}render(){B(ht(Uo,{closeSidebar:this._closeSidebar,createAnnotation:this._createAnnotation,newAnnotationType:this._newAnnotationType,isSidebarOpen:this._sidebarOpen,showHighlights:this._highlightsVisible,toggleHighlights:this._toggleHighlights,toggleSidebar:this._toggleSidebar,toggleSidebarRef:this._sidebarToggleButton,useMinimalControls:this.useMinimalControls}),this._container)}}const Wo=280;class jo{constructor(t,e,n){if(this._emitter=e.createEmitter(),this._guestWithSelection=null,this._guestRPC=[],this._sidebarRPC=new Ut,this.iframe=function(t){const e=t.sidebarAppUrl,n=To(e,Ro(e,t)),i=document.createElement("iframe");return i.setAttribute("allowfullscreen",""),i.src=n,i.title="Hypothesis annotation viewer",i.className="sidebar-frame",i}(n),this._config=n,this.bucketBar=null,this.features=new wn,
|
|
159
|
+
n.externalContainerSelector){var i;this.externalFrame=null!==(i=document.querySelector(n.externalContainerSelector))&&void 0!==i?i:t,this.externalFrame.appendChild(this.iframe)}else{this.iframeContainer=document.createElement("div"),this.iframeContainer.style.display="none",this.iframeContainer.className="sidebar-container","clean"===n.theme?this.iframeContainer.classList.add("theme-clean"):this.bucketBar=new Ho(this.iframeContainer,{onFocusAnnotations:t=>this._guestRPC.forEach((e=>e.call("hoverAnnotations",t))),onScrollToClosestOffScreenAnchor:(t,e)=>this._guestRPC.forEach((n=>n.call("scrollToClosestOffScreenAnchor",t,e))),onSelectAnnotations:(t,e)=>this._guestRPC.forEach((n=>n.call("selectAnnotations",t,e)))}),this.iframeContainer.appendChild(this.iframe),this.hypothesisSidebar=document.createElement("hypothesis-sidebar");Ie(this.hypothesisSidebar).appendChild(this.iframeContainer),t.appendChild(this.hypothesisSidebar)}this.iframe.contentWindow&&Bt(this.iframe.contentWindow),this._listeners=new xt
|
|
160
|
+
;const o=document.createElement("div");this.toolbar=new zo(o,{createAnnotation:()=>{var t;if(0===this._guestRPC.length)return;(null!==(t=this._guestWithSelection)&&void 0!==t?t:this._guestRPC[0]).call("createAnnotation")},setSidebarOpen:t=>t?this.open():this.close(),setHighlightsVisible:t=>this.setHighlightsVisible(t)}),"clean"===n.theme?this.toolbar.useMinimalControls=!0:this.toolbar.useMinimalControls=!1,this.iframeContainer?(this.iframeContainer.prepend(o),this.toolbarWidth=this.toolbar.getWidth()):this.toolbarWidth=0,this._listeners.add(window,"resize",(()=>this._onResize())),this._gestureState={initial:null,final:null},this._setupGestures(),this.close();const[r]=n.services||[];r&&(this.onLoginRequest=r.onLoginRequest,this.onLogoutRequest=r.onLogoutRequest,this.onSignupRequest=r.onSignupRequest,this.onProfileRequest=r.onProfileRequest,this.onHelpRequest=r.onHelpRequest),this.onLayoutChange=n.onLayoutChange,this._layoutState={expanded:!1,width:0,toolbarWidth:0},this._updateLayoutState(!1),
|
|
161
|
+
this._setupSidebarEvents()}destroy(){var t,e;this._guestRPC.forEach((t=>t.destroy())),this._sidebarRPC.destroy(),null===(t=this.bucketBar)||void 0===t||t.destroy(),this._listeners.removeAll(),null===(e=this._hammerManager)||void 0===e||e.destroy(),this.hypothesisSidebar?this.hypothesisSidebar.remove():this.iframe.remove(),this._emitter.destroy(),Bt(null)}onFrameConnected(t,e){switch(t){case"guest":this._connectGuest(e);break;case"sidebar":this._sidebarRPC.connect(e)}}_connectGuest(t){const e=new Ut;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("highlightsVisibleChanged",(t=>{this.setHighlightsVisible(t)}));const n=this.bucketBar;n&&e.on("anchorsChanged",(t=>{0===this._guestRPC.indexOf(e)&&n.update(t)})),
|
|
162
|
+
e.on("close",(()=>{e.destroy(),e===this._guestWithSelection&&(this._guestWithSelection=null),this._guestRPC=this._guestRPC.filter((t=>t!==e))})),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;this.setHighlightsVisible(t),(this._config.openSidebar||this._config.annotations||this._config.query||this._config.group)&&this.open()})),
|
|
163
|
+
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._emitter.subscribe("closeNotebook",(()=>{this.show()}));[["loginRequested",this.onLoginRequest],["logoutRequested",this.onLogoutRequest],["signupRequested",this.onSignupRequest],["profileRequested",this.onProfileRequest],["helpRequested",this.onHelpRequest]].forEach((([t,e])=>{e&&this._sidebarRPC.on(t,(()=>e()))}))}_resetGestureState(){this._gestureState={initial:null,final:null}}_setupGestures(){const t=this.toolbar.sidebarToggleButton;t&&(this._hammerManager=new Mo.Manager(t),this._hammerManager.on("panstart panend panleft panright",(t=>this._onPan(t))),this._hammerManager.add(new Mo.Pan({direction:Mo.DIRECTION_HORIZONTAL})))}_updateLayout(){this.renderFrame||(this.renderFrame=requestAnimationFrame((()=>{if(this.renderFrame=null,
|
|
164
164
|
this._gestureState.final!==this._gestureState.initial&&this.iframeContainer){const t=this._gestureState.final,e=-t;this.iframeContainer.style.marginLeft=`${t}px`,e>=Wo&&(this.iframeContainer.style.width=`${e}px`),this._updateLayoutState()}})))}_updateLayoutState(t){var e;const n=this.iframeContainer&&this.toolbar.getWidth()||0,i=null!==(e=this.iframeContainer)&&void 0!==e?e:this.externalFrame,o=i.getBoundingClientRect(),r=window.getComputedStyle(i),s=parseInt(r.width),a=parseInt(r.marginLeft);let l=n;"boolean"==typeof t?t&&(l+=s):(a<Wo?l-=a:l+=s,t=l>n);const c={expanded:t,width:t?l:n,height:o.height,toolbarWidth:n};this._layoutState=c,this.onLayoutChange&&this.onLayoutChange(c),this._guestRPC.forEach((t=>t.call("sidebarLayoutChanged",c)))}_onResize(){!0===this.toolbar.sidebarOpen&&(window.innerWidth<Wo?this.close():this.open())}_onPan(t){const e=this.iframeContainer;if(e)switch(t.type){case"panstart":this._resetGestureState(),e.classList.add("sidebar-no-transition"),e.style.pointerEvents="none",
|
|
165
165
|
this._gestureState.initial=parseInt(getComputedStyle(e).marginLeft);break;case"panend":e.classList.remove("sidebar-no-transition"),e.style.pointerEvents="",null===this._gestureState.final||this._gestureState.final<=-280?this.open():this.close(),this._resetGestureState();break;case"panleft":case"panright":{if("number"!=typeof this._gestureState.initial)return;const e=this._gestureState.initial,n=t.deltaX;this._gestureState.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.iframeContainer&&(this.iframeContainer.style.marginLeft="",this.iframeContainer.classList.add("sidebar-collapsed")),this.toolbar.sidebarOpen=!1,
|
|
166
166
|
"whenSidebarOpen"===this._config.showHighlights&&this.setHighlightsVisible(!1),this._updateLayoutState(!1)}setHighlightsVisible(t){this.toolbar.highlightsVisible=t,this._sidebarRPC.call("setHighlightsVisible",t)}show(){this.iframeContainer&&this.iframeContainer.classList.remove("is-hidden")}hide(){this.iframeContainer&&this.iframeContainer.classList.add("is-hidden")}}class $o{constructor(t){this._emitter=t,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,i])=>n!==t||i!==e))}destroy(){for(let[t,e]of this._subscriptions)this._emitter.off(t,e);this._subscriptions=[]}}class Xo{constructor(){this._emitter=new Pt}createEmitter(){return new $o(this._emitter)}}!function(t,{reset:e=!1}={}){e&&ut.clear();for(let[e,n]of Object.entries(t))ut.set(e,n)}(wt);const Yo=document.querySelector('link[type="application/annotator+html"][rel="sidebar"]')
|