hypothesis 1.992.0 → 1.995.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/boot.js +1 -1
- package/build/manifest.json +11 -11
- package/build/scripts/annotator.bundle.js +48 -48
- package/build/scripts/annotator.bundle.js.map +1 -1
- package/build/scripts/sidebar.bundle.js +30 -30
- package/build/scripts/sidebar.bundle.js.map +1 -1
- package/build/styles/annotator.css +17 -3
- package/build/styles/annotator.css.map +1 -1
- package/build/styles/sidebar.css +16 -2
- package/build/styles/sidebar.css.map +1 -1
- package/build/styles/ui-playground.css +16 -2
- package/build/styles/ui-playground.css.map +1 -1
- package/package.json +2 -2
package/build/boot.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
!function(){"use strict";function t(t,e){for(var s in e)e.hasOwnProperty(s)&&(t[s]=e[s]);return t}function e(t){for(var e=arguments.length,s=new Array(e>1?e-1:0),n=1;n<e;n++)s[n-1]=arguments[n];return s.every((function(e){return"function"==typeof t[e]}))}var s={es2017:function(){return!e(Object,"entries","values")},es2018:function(){return"function"!=typeof Promise||!e(Promise.prototype,"finally")}};function n(t){return function(t){if(Array.isArray(t))return r(t)}(t)||function(t){if("undefined"!=typeof Symbol&&null!=t[Symbol.iterator]||null!=t["@@iterator"])return Array.from(t)}(t)||function(t,e){if(!t)return;if("string"==typeof t)return r(t,e);var s=Object.prototype.toString.call(t).slice(8,-1);"Object"===s&&t.constructor&&(s=t.constructor.name);if("Map"===s||"Set"===s)return Array.from(t);if("Arguments"===s||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(s))return r(t,e)}(t)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function r(t,e){(null==e||e>t.length)&&(e=t.length);for(var s=0,n=new Array(e);s<e;s++)n[s]=t[s];return n}var o=["es2017","es2018"];function a(t){t.setAttribute("data-hypothesis-asset","")}function i(t,e){var s=t.createElement("link");s.rel="stylesheet",s.type="text/css",s.href=e,a(s),t.head.appendChild(s)}function c(t,e){var s=arguments.length>2&&void 0!==arguments[2]&&arguments[2],n=t.createElement("script");n.type="module",s&&(e+="#ts=".concat(Date.now())),n.src=e,n.async=!1,a(n),t.head.appendChild(n)}function l(t,e,s,n){var r=t.createElement("link");r.rel=e,r.href=n,r.type="application/annotator+".concat(s),a(r),t.head.appendChild(r)}function u(t,e,s){var n=t.createElement("link");n.rel="preload",n.as=e,n.href=s,"fetch"===e&&(n.crossOrigin="anonymous"),a(n),t.head.appendChild(n)}function p(t,e){return t.assetRoot+"build/"+t.manifest[e]}function d(t,e,s){var n=arguments.length>3&&void 0!==arguments[3]?arguments[3]:{},r=n.forceModuleReload;s.forEach((function(s){var n=p(e,s);n.match(/\.css/)?i(t,n):c(t,n,r)}))}function h(t){return function(t){return t.filter((function(t){var e=s[t];if(!e)throw new Error('Unknown polyfill set "'.concat(t,'"'));return e()}))}(t).map((function(t){return"scripts/polyfills-".concat(t,".bundle.js")}))}function f(t){var e=t.match(/(https?):\/\/([^:/]+)/);return e?{protocol:e[1],hostname:e[2]}:null}function y(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:document,e=t.currentScript;return e?f(e.src):null}function m(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:document;if(-1===t.indexOf("{"))return t;var s=y(e);if(!s)throw new Error("Could not process URL template because script origin is unknown");return t=(t=t.replace("{current_host}",s.hostname)).replace("{current_scheme}",s.protocol)}var b={"scripts/annotator.bundle.js":"scripts/annotator.bundle.js?
|
|
1
|
+
!function(){"use strict";function t(t,e){for(var s in e)e.hasOwnProperty(s)&&(t[s]=e[s]);return t}function e(t){for(var e=arguments.length,s=new Array(e>1?e-1:0),n=1;n<e;n++)s[n-1]=arguments[n];return s.every((function(e){return"function"==typeof t[e]}))}var s={es2017:function(){return!e(Object,"entries","values")},es2018:function(){return"function"!=typeof Promise||!e(Promise.prototype,"finally")}};function n(t){return function(t){if(Array.isArray(t))return r(t)}(t)||function(t){if("undefined"!=typeof Symbol&&null!=t[Symbol.iterator]||null!=t["@@iterator"])return Array.from(t)}(t)||function(t,e){if(!t)return;if("string"==typeof t)return r(t,e);var s=Object.prototype.toString.call(t).slice(8,-1);"Object"===s&&t.constructor&&(s=t.constructor.name);if("Map"===s||"Set"===s)return Array.from(t);if("Arguments"===s||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(s))return r(t,e)}(t)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function r(t,e){(null==e||e>t.length)&&(e=t.length);for(var s=0,n=new Array(e);s<e;s++)n[s]=t[s];return n}var o=["es2017","es2018"];function a(t){t.setAttribute("data-hypothesis-asset","")}function i(t,e){var s=t.createElement("link");s.rel="stylesheet",s.type="text/css",s.href=e,a(s),t.head.appendChild(s)}function c(t,e){var s=arguments.length>2&&void 0!==arguments[2]&&arguments[2],n=t.createElement("script");n.type="module",s&&(e+="#ts=".concat(Date.now())),n.src=e,n.async=!1,a(n),t.head.appendChild(n)}function l(t,e,s,n){var r=t.createElement("link");r.rel=e,r.href=n,r.type="application/annotator+".concat(s),a(r),t.head.appendChild(r)}function u(t,e,s){var n=t.createElement("link");n.rel="preload",n.as=e,n.href=s,"fetch"===e&&(n.crossOrigin="anonymous"),a(n),t.head.appendChild(n)}function p(t,e){return t.assetRoot+"build/"+t.manifest[e]}function d(t,e,s){var n=arguments.length>3&&void 0!==arguments[3]?arguments[3]:{},r=n.forceModuleReload;s.forEach((function(s){var n=p(e,s);n.match(/\.css/)?i(t,n):c(t,n,r)}))}function h(t){return function(t){return t.filter((function(t){var e=s[t];if(!e)throw new Error('Unknown polyfill set "'.concat(t,'"'));return e()}))}(t).map((function(t){return"scripts/polyfills-".concat(t,".bundle.js")}))}function f(t){var e=t.match(/(https?):\/\/([^:/]+)/);return e?{protocol:e[1],hostname:e[2]}:null}function y(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:document,e=t.currentScript;return e?f(e.src):null}function m(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:document;if(-1===t.indexOf("{"))return t;var s=y(e);if(!s)throw new Error("Could not process URL template because script origin is unknown");return t=(t=t.replace("{current_host}",s.hostname)).replace("{current_scheme}",s.protocol)}var b={"scripts/annotator.bundle.js":"scripts/annotator.bundle.js?bb876c","scripts/ui-playground.bundle.js":"scripts/ui-playground.bundle.js?ca5bf9","styles/annotator.css":"styles/annotator.css?6a7cf1","styles/annotator.css.map":"styles/annotator.css.map?29fdb5","styles/highlights.css":"styles/highlights.css?c308d0","styles/highlights.css.map":"styles/highlights.css.map?5be890","styles/katex.min.css":"styles/katex.min.css?28919c","styles/katex.min.css.map":"styles/katex.min.css.map?4daef7","styles/pdfjs-overrides.css":"styles/pdfjs-overrides.css?ed2cb3","styles/pdfjs-overrides.css.map":"styles/pdfjs-overrides.css.map?13b830","styles/sidebar.css":"styles/sidebar.css?55e1db","styles/sidebar.css.map":"styles/sidebar.css.map?a69ac0","scripts/ui-playground.bundle.js.map":"scripts/ui-playground.bundle.js.map?33e08f","styles/ui-playground.css.map":"styles/ui-playground.css.map?9ef6ce","styles/ui-playground.css":"styles/ui-playground.css?482199","scripts/annotator.bundle.js.map":"scripts/annotator.bundle.js.map?79511b","scripts/sidebar.bundle.js":"scripts/sidebar.bundle.js?2af36c","scripts/sidebar.bundle.js.map":"scripts/sidebar.bundle.js.map?efe522"};if(function(){var t=[function(){return Promise.resolve()},function(){return new Map},function(){return new URL(document.location.href)},function(){return new Request("https://hypothes.is")},function(){return Element.prototype.attachShadow},function(){return CSS.supports("display: grid")},function(){return document.evaluate("/html/body",document,null,XPathResult.ANY_TYPE,null),!0}];try{return t.every((function(t){return t()}))}catch(t){return!1}}()){var v=function(e){for(var s={},n=e.querySelectorAll("script.js-hypothesis-config"),r=0;r<n.length;r++){var o=void 0;try{o=JSON.parse(n[r].textContent||"")}catch(t){console.warn("Could not parse settings from js-hypothesis-config tags",t),o={}}t(s,o)}return s}(document),g=m(v.assetRoot||"https://cdn.hypothes.is/hypothesis/1.995.0/");if(document.querySelector("hypothesis-app"))!function(t,e){u(t,"fetch",e.apiUrl),u(t,"fetch",e.apiUrl+"links");var s=h(o);d(t,e,[].concat(n(s),["scripts/sidebar.bundle.js","styles/katex.min.css","styles/sidebar.css"]))}(document,{assetRoot:g,manifest:b,apiUrl:v.apiUrl});else{var j=m(v.notebookAppUrl||"https://hypothes.is/notebook"),w=m(v.sidebarAppUrl||"https://hypothes.is/app.html");!function(t,e){if(!t.querySelector('link[type="application/annotator+html"]')){l(t,"sidebar","html",e.sidebarAppUrl),l(t,"notebook","html",e.notebookAppUrl),u(t,"style",p(e,"styles/annotator.css")),l(t,"hypothesis-client","javascript",e.assetRoot+"build/boot.js");var s=h(o),r=[];void 0!==window.PDFViewerApplication&&r.push("styles/pdfjs-overrides.css"),d(t,e,[].concat(n(s),r,["scripts/annotator.bundle.js","styles/highlights.css"]),{forceModuleReload:!0})}}(document,{assetRoot:g,manifest:b,notebookAppUrl:j,sidebarAppUrl:w})}}else console.warn("The Hypothesis annotation tool is not supported in this browser. See https://web.hypothes.is/help/which-browsers-are-supported-by-hypothesis/.")}();
|
package/build/manifest.json
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
{
|
|
2
|
-
"scripts/annotator.bundle.js": "scripts/annotator.bundle.js?
|
|
2
|
+
"scripts/annotator.bundle.js": "scripts/annotator.bundle.js?bb876c",
|
|
3
3
|
"scripts/ui-playground.bundle.js": "scripts/ui-playground.bundle.js?ca5bf9",
|
|
4
|
-
"
|
|
5
|
-
"styles/annotator.css": "styles/annotator.css?
|
|
6
|
-
"styles/annotator.css.map": "styles/annotator.css.map?33fa1b",
|
|
4
|
+
"styles/annotator.css": "styles/annotator.css?6a7cf1",
|
|
5
|
+
"styles/annotator.css.map": "styles/annotator.css.map?29fdb5",
|
|
7
6
|
"styles/highlights.css": "styles/highlights.css?c308d0",
|
|
8
7
|
"styles/highlights.css.map": "styles/highlights.css.map?5be890",
|
|
9
8
|
"styles/katex.min.css": "styles/katex.min.css?28919c",
|
|
10
9
|
"styles/katex.min.css.map": "styles/katex.min.css.map?4daef7",
|
|
11
10
|
"styles/pdfjs-overrides.css": "styles/pdfjs-overrides.css?ed2cb3",
|
|
12
11
|
"styles/pdfjs-overrides.css.map": "styles/pdfjs-overrides.css.map?13b830",
|
|
13
|
-
"styles/sidebar.css": "styles/sidebar.css?
|
|
14
|
-
"styles/sidebar.css.map": "styles/sidebar.css.map?
|
|
15
|
-
"
|
|
16
|
-
"styles/ui-playground.css.map": "styles/ui-playground.css.map?
|
|
17
|
-
"
|
|
18
|
-
"scripts/
|
|
19
|
-
"scripts/sidebar.bundle.js
|
|
12
|
+
"styles/sidebar.css": "styles/sidebar.css?55e1db",
|
|
13
|
+
"styles/sidebar.css.map": "styles/sidebar.css.map?a69ac0",
|
|
14
|
+
"scripts/ui-playground.bundle.js.map": "scripts/ui-playground.bundle.js.map?33e08f",
|
|
15
|
+
"styles/ui-playground.css.map": "styles/ui-playground.css.map?9ef6ce",
|
|
16
|
+
"styles/ui-playground.css": "styles/ui-playground.css?482199",
|
|
17
|
+
"scripts/annotator.bundle.js.map": "scripts/annotator.bundle.js.map?79511b",
|
|
18
|
+
"scripts/sidebar.bundle.js": "scripts/sidebar.bundle.js?2af36c",
|
|
19
|
+
"scripts/sidebar.bundle.js.map": "scripts/sidebar.bundle.js.map?efe522"
|
|
20
20
|
}
|
|
@@ -68,43 +68,43 @@ static fromRange(t,e){const n=fe.fromRange(e).relativeTo(t);return new $e(t,n.st
|
|
|
68
68
|
;return new $e(this.root,e.start,e.end)}}async function Xe(t,e={}){return t.toRange(e)}function Ye(t,e,n={}){let o=null,i=null,r=null;for(let t of e)switch(t.type){case"TextPositionSelector":o=t,n.hint=o.start;break;case"TextQuoteSelector":i=t;break;case"RangeSelector":r=t}const s=t=>{var e;if(null!==(e=i)&&void 0!==e&&e.exact&&t.toString()!==i.exact)throw new Error("quote mismatch");return t};let a=Promise.reject("unable to anchor");return r&&(a=a.catch((()=>Xe(ze.fromSelector(t,r),n).then(s)))),o&&(a=a.catch((()=>Xe($e.fromSelector(t,o),n).then(s)))),i&&(a=a.catch((()=>Xe(je.fromSelector(t,i),n)))),a}function Ze(t,e){const n=[ze,$e,je],o=[];for(let i of n)try{const n=i.fromRange(t,e);o.push(n.toSelector())}catch(t){continue}return o}function Ge(t,e=document.baseURI){return new URL(t,e).href.toString().replace(/#.*/,"")}class Ke{constructor(t={}){this.document=t.document||document}uri(){let t=decodeURIComponent(this._getDocumentHref());const e=this._getLinks();for(let n of e)"canonical"===n.rel&&(t=n.href)
|
|
69
69
|
;return t}getDocumentMetadata(){const t={title:document.title,link:[],dc:this._getMetaTags("name","dc."),eprints:this._getMetaTags("name","eprints."),facebook:this._getMetaTags("property","og:"),highwire:this._getMetaTags("name","citation_"),prism:this._getMetaTags("name","prism."),twitter:this._getMetaTags("name","twitter:")},e=this._getFavicon();e&&(t.favicon=e),t.title=this._getTitle(t),t.link=this._getLinks(t);const n=t.link.find((t=>t.href.startsWith("urn:x-dc")));return n&&(t.documentFingerprint=n.href),t}_getMetaTags(t,e){const n={};for(let o of Array.from(this.document.querySelectorAll("meta"))){const i=o.getAttribute(t),{content:r}=o;if(i&&r){const t=i.match(RegExp(`^${e}(.+)$`,"i"));if(t){const e=t[1].toLowerCase();n[e]?n[e].push(r):n[e]=[r]}}}return n}_getTitle(t){return t.highwire.title?t.highwire.title[0]:t.eprints.title?t.eprints.title[0]:t.prism.title?t.prism.title[0]:t.facebook.title?t.facebook.title[0]:t.twitter.title?t.twitter.title[0]:t.dc.title?t.dc.title[0]:this.document.title}
|
|
70
70
|
_getLinks(t={dc:{},highwire:{}}){const e=[{href:this._getDocumentHref()}],n=Array.from(this.document.querySelectorAll("link"));for(let t of n)if(["alternate","canonical","bookmark","shortlink"].includes(t.rel)){if("alternate"===t.rel){if(t.type&&t.type.match(/^application\/(rss|atom)\+xml/))continue;if(t.hreflang)continue}try{const n=this._absoluteUrl(t.href);e.push({href:n,rel:t.rel,type:t.type})}catch(t){}}for(let n of Object.keys(t.highwire)){const o=t.highwire[n];if("pdf_url"===n)for(let t of o)try{e.push({href:this._absoluteUrl(t),type:"application/pdf"})}catch(t){}if("doi"===n)for(let t of o)"doi:"!==t.slice(0,4)&&(t=`doi:${t}`),e.push({href:t})}for(let n of Object.keys(t.dc)){const o=t.dc[n];if("identifier"===n)for(let t of o)"doi:"===t.slice(0,4)&&e.push({href:t})}const o=t.dc["relation.ispartof"],i=t.dc.identifier;if(o&&i){const t=o[o.length-1],n=i[i.length-1],r="urn:x-dc:"+encodeURIComponent(t)+"/"+encodeURIComponent(n);e.push({href:r})}return e}_getFavicon(){let t=null
|
|
71
|
-
;for(let e of Array.from(this.document.querySelectorAll("link")))if(["shortcut icon","icon"].includes(e.rel))try{t=this._absoluteUrl(e.href)}catch(t){}return t}_absoluteUrl(t){return Ge(t,this.document.baseURI)}_getDocumentHref(){const{href:t}=this.document.location,e=["http:","https:","file:"],n=new URL(t).protocol;return e.includes(n)?t:this.document.baseURI&&e.includes(new URL(this.document.baseURI).protocol)?this.document.baseURI:t}}function Je(t){return t.width<=0||t.height<=0}function Qe(t,e,n,o){return Math.max(t,n)<Math.min(e,o)}function tn(t,e){return!Je(t)&&!Je(e)&&(Qe(t.left,t.right,e.left,e.right)&&Qe(t.top,t.bottom,e.top,e.bottom))}
|
|
72
|
-
function
|
|
73
|
-
fitSideBySide(t){return!!this.sideBySideEnabled&&(t.expanded?(this._activateSideBySide(t.width),!0):(this._deactivateSideBySide(),!1))}_activateSideBySide(t){const e=t+12;
|
|
74
|
-
}else document.body.style.marginLeft="",document.body.style.marginRight=""}))}_deactivateSideBySide(){
|
|
75
|
-
if("string"!=typeof t)return 0===t?t:+t;t=t.replace(
|
|
76
|
-
;function
|
|
77
|
-
;for(let r=0;r<e.pagesCount;r++)if(i=await
|
|
78
|
-
;if(!n)throw new Error("No quote selector found");const o=e.find((t=>"TextPositionSelector"===t.type));if(o){try{const{index:t,offset:e,text:i}=await
|
|
79
|
-
;const e=n.slice(u.start,u.end)===l,i=void 0!==s&&n.slice(Math.max(0,u.start-s.length),u.start)===s,r=void 0!==a&&n.slice(u.end,a.length)===a,h=void 0!==s||void 0!==a;if(e&&(i||r||!h))break}}if(c){const{page:n,match:o}=c;if(e){const i=
|
|
80
|
-
;for(let n=0;n<t;n++)e+=(await
|
|
81
|
-
return t.initializedPromise?t.initializedPromise:t.initialized?Promise.resolve():new Promise((e=>{const n=setInterval((()=>{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=
|
|
82
|
-
return Array.isArray(t.pdfDocument.fingerprints)?t.pdfDocument.fingerprints[0]:t.pdfDocument.fingerprint}function
|
|
83
|
-
this._checkForSelectableText(),this._updateAnnotationLayerVisibility=()=>{const t=r.getSelection();this.pdfViewer.viewer.classList.toggle("is-selecting",!t.isCollapsed)},this._listeners=new At,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._warningBanner)||void 0===t||t.remove(),this._destroyed=!0}uri(){return this.pdfMetadata.getUri()}getMetadata(){return this.pdfMetadata.getMetadata()}anchor(t,e){return
|
|
84
|
-
console.warn("Unable to check for text in PDF:",t)}}_toggleNoSelectableTextWarning(t){const e=document.querySelector("#outerContainer");var n;if(!t)return null===(n=this._warningBanner)||void 0===n||n.remove(),this._warningBanner=null,void(e.style.height="");this._warningBanner=document.createElement("hypothesis-banner"),document.body.prepend(this._warningBanner);const o=se(this._warningBanner);L(mt(
|
|
85
|
-
;if(!document.body.contains(o)){e.highlights.splice(n,1),delete e.range,t.push(e.annotation);break}}}t.map((t=>this.annotator.anchor(t)))}contentContainer(){return document.querySelector("#viewerContainer")}fitSideBySide(t){const e=window.innerWidth-t.width,n=t.expanded&&e>=680,o=n?t.width:t.toolbarWidth;this.pdfContainer.style.width=`calc(100% - ${o}px)`;const i=this.pdfViewer.currentScaleValue;return"auto"!==i&&"page-fit"!==i&&"page-width"!==i||(this.pdfViewer.currentScaleValue=i),this.pdfViewer.update(),n}async scrollToAnchor(t){const e=t.annotation,n=
|
|
86
|
-
;return null!==(n=i)&&void 0!==n?n:null}_anchorOffset(t){if(!t.highlights)return null;return function(t,e){let n=0;for(;t!==e&&e.contains(t);)n+=t.offsetTop,t=t.offsetParent;return n}(t.highlights[0],this.contentContainer())}}function
|
|
87
|
-
t.style.transformOrigin="top left",t.textContent=l,i.append(t),i.append(" "),h||(h=t.getBoundingClientRect().height),c.push({span:t,box:a,width:s.measureText(l).width,height:h}),a=null,l=""};for(let t=0;t<e.length;t++){const o=n[t];if(/\s/.test(o)){u();continue}const i=e[t];a=
|
|
88
|
-
null===(t=this._imageSizeObserver)||void 0===t||t.disconnect()}}class
|
|
89
|
-
;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
|
|
90
|
-
;const l=t.contentDocument;l.body.appendChild(s),l.body.appendChild(a)}function
|
|
91
|
-
;for(let t of e)this._listeners.add(document.documentElement,t,(t=>{t.stopPropagation()}));const n=
|
|
92
|
-
;return t.search="",t.toString()}async scrollToAnchor(t){return this._htmlIntegration.scrollToAnchor(t)}}function
|
|
93
|
-
const t=function(t,e){const n=new Set,o=new Set;return _e(t,(t=>{let i=t;for(;i&&!n.has(i);){n.add(i);const t=e(i);null!=t&&o.add(t),i=i.parentNode}})),[...o]}(window.getSelection().getRangeAt(0),(t=>{var e;return null===(e=t._annotation)||void 0===e?void 0:e.$tag}));return t}function
|
|
94
|
-
onHighlight:()=>this.createAnnotation({highlight:!0}),onShowAnnotations:t=>this.selectAnnotations(t)}),this._selectionObserver=new
|
|
95
|
-
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=
|
|
96
|
-
this._hostRPC.on("focusAnnotations",(t=>this._focusAnnotations(t))),this._hostRPC.on("scrollToClosestOffScreenAnchor",((t,e)=>this._scrollToClosestOffScreenAnchor(t,e))),this._hostRPC.on("selectAnnotations",((t,e)=>this.selectAnnotations(t,e))),this._hostRPC.on("sidebarLayoutChanged",(e=>{var n,o;((n=window)===(o=t)||n.parent===o&&n.frameElement&&n.frameElement.getBoundingClientRect().width/n.parent.innerWidth>=.8)&&this.fitSideBySide(e)}));const e=await this._portFinder.discover("host");this._hostRPC.connect(e)}async _connectSidebar(){this._sidebarRPC.on("focusAnnotations",(t=>this._focusAnnotations(t))),this._sidebarRPC.on("scrollToAnnotation",(t=>{const e=this.anchors.find((e=>e.annotation.$tag===t));if(null==e||!e.highlights)return;const n=
|
|
97
|
-
this._sidebarRPC.on("deleteAnnotation",(t=>this.detach(t))),this._sidebarRPC.on("loadAnnotations",(t=>t.forEach((t=>this.anchor(t))))),this._portFinder.discover("sidebar").then((t=>{this._sidebarRPC.connect(t)})),this.getDocumentInfo().then((t=>this._sidebarRPC.call("documentInfoChanged",t)))}destroy(){this._portFinder.destroy(),this._hostRPC.destroy(),this._sidebarRPC.destroy(),this._listeners.removeAll(),this._selectionObserver.disconnect(),this._adder.destroy(),this._bucketBarClient.destroy(),function(t){be(Array.from(t.querySelectorAll("hypothesis-highlight")))}(this.element),this._integration.destroy()}async anchor(t){const e=t=>{const e=
|
|
98
|
-
target:e};let n;try{const o=await this._integration.anchor(this.element,e.selector),i=fe.fromRange(o);n={annotation:t,target:e,range:i}}catch(o){n={annotation:t,target:e}}return n})));if(!this._annotations.has(t.$tag))return[];for(let t of n)e(t);return t.$orphan=n.length>0&&n.every((t=>t.target.selector&&!t.range)),this._updateAnchors(this.anchors.concat(n),!0),this._sidebarRPC.call("syncAnchoringStatus",t),n}detach(t,e=!0){this._annotations.delete(t);const n=[];for(let e of this.anchors)e.annotation.$tag!==t?n.push(e):e.highlights&&be(e.highlights);this._updateAnchors(n,e)}_updateAnchors(t,e){this.anchors=t,e&&this._bucketBarClient.update(this.anchors)}async createAnnotation({highlight:t=!1}={}){const e=this.selectedRanges;this.selectedRanges=[];const n=await this.getDocumentInfo(),o=this.element,i=(await Promise.all(e.map((t=>this._integration.describe(o,t))))).map((t=>({source:n.uri,selector:t}))),r={uri:n.uri,
|
|
99
|
-
;return this._sidebarRPC.call("createAnnotation",r),this.anchor(r),
|
|
100
|
-
this._adder.show(o,n)):this._onClearSelection()}_onClearSelection(){this._isAdderVisible=!1,this._adder.hide(),this.selectedRanges=[],this._informHostOnNextSelectionClear&&this._hostRPC.call("textUnselected"),this._informHostOnNextSelectionClear=!0}selectAnnotations(t,e=!1){e?this._sidebarRPC.call("toggleAnnotationSelection",t):this._sidebarRPC.call("showAnnotations",t),this._sidebarRPC.call("openSidebar")}setHighlightsVisible(t){!function(t,e){t.classList.toggle("hypothesis-highlights-always-on",e)}(this.element,t),this._highlightsVisible=t}fitSideBySide(t){this._sideBySideActive=this._integration.fitSideBySide(t)}get sideBySideActive(){return this._sideBySideActive}get focusedAnnotationTags(){return this._focusedAnnotations}}function
|
|
101
|
-
;o.origin=new URL(t).origin,o.version="1.
|
|
102
|
-
c.current=e,()=>{e.destroy()}}),[t]);return null===s?null:mt("div",{className:G("
|
|
103
|
-
;if(t)if(t.forEach)t.forEach(e,n);else if(t.length!==i)for(o=0;o<t.length;)e.call(n,t[o],o,t),o++;else for(o in t)t.hasOwnProperty(o)&&e.call(n,t[o],o,t)}function p(t,n,o){var i="DEPRECATED METHOD: "+n+"\n"+o+" AT \n";return function(){var n=new Error("get-stack-trace"),o=n&&n.stack?n.stack.replace(/^[^\(]+?[\n$]/gm,"").replace(/^\s+at\s+/gm,"").replace(/^Object.<anonymous>\s*\(/gm,"{anonymous}()@"):"Unknown Stack Trace",r=e.console&&(e.console.warn||e.console.log);return r&&r.call(e.console,i,o),t.apply(this,arguments)}}r="function"!=typeof Object.assign?function(t){if(t===i||null===t)throw new TypeError("Cannot convert undefined or null to object");for(var e=Object(t),n=1;n<arguments.length;n++){var o=arguments[n];if(o!==i&&null!==o)for(var r in o)o.hasOwnProperty(r)&&(e[r]=o[r])}return e}:Object.assign;var g=p((function(t,e,n){for(var o=Object.keys(e),r=0;r<o.length;)(!n||n&&t[o[r]]===i)&&(t[o[r]]=e[o[r]]),r++;return t
|
|
104
|
-
}),"merge","Use `assign`.");function _(t,e,n){var o,i=e.prototype;(o=t.prototype=Object.create(i)).constructor=t,o._super=i,n&&r(o,n)}function v(t,e){return function(){return t.apply(e,arguments)}}function y(t,e){return"function"==typeof t?t.apply(e&&e[0]||i,e):t}function w(t,e){return t===i?e:t}function b(t,e,n){f(x(e),(function(e){t.addEventListener(e,n,!1)}))}function C(t,e,n){f(x(e),(function(e){t.removeEventListener(e,n,!1)}))}function E(t,e){for(;t;){if(t==e)return!0;t=t.parentNode}return!1}function S(t,e){return t.indexOf(e)>-1}function x(t){return t.trim().split(/\s+/g)}function T(t,e,n){if(t.indexOf&&!n)return t.indexOf(e);for(var o=0;o<t.length;){if(n&&t[o][n]==e||!n&&t[o]===e)return o;o++}return-1}function A(t){return Array.prototype.slice.call(t,0)}function k(t,e,n){for(var o=[],i=[],r=0;r<t.length;){var s=e?t[r][e]:t[r];T(i,s)<0&&o.push(t[r]),i[r]=s,r++}return n&&(o=e?o.sort((function(t,n){return t[e]>n[e]})):o.sort()),o}
|
|
105
|
-
for(var n,o,r=e[0].toUpperCase()+e.slice(1),a=0;a<s.length;){if((o=(n=s[a])?n+r:e)in t)return o;a++}return i}var N=1;function P(t){var n=t.ownerDocument||t;return n.defaultView||n.parentWindow||e}var L="ontouchstart"in e,M=R(e,"PointerEvent")!==i,O=L&&/mobile|tablet|ip(ad|hone|od)|android/i.test(navigator.userAgent),I="touch",B="mouse",D=24,F=["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 o=n.pointers.length,r=n.changedPointers.length,s=1&e&&o-r==0,a=12&e&&o-r==0;n.isFirst=!!s,n.isFinal=!!a,s&&(t.session={}),n.eventType=e,function(t,e){var n=t.session,o=e.pointers,r=o.length;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=W(o);e.timeStamp=h(),
|
|
106
|
-
e.angle=X(l,u),e.distance=j(l,u),function(t,e){var n=e.center,o=t.offsetDelta||{},i=t.prevDelta||{},r=t.prevInput||{};1!==e.eventType&&4!==r.eventType||(i=t.prevDelta={x:r.deltaX||0,y:r.deltaY||0},o=t.offsetDelta={x:n.x,y:n.y});e.deltaX=i.x+(n.x-o.x),e.deltaY=i.y+(n.y-o.y)}(n,e),e.offsetDirection=$(e.deltaX,e.deltaY);var d=z(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=o,j(p[0],p[1],H)/j(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,o):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,o,r,s,a=t.lastInterval||e,l=e.timeStamp-a.timeStamp;if(8!=e.eventType&&(l>25||a.velocity===i)){var h=e.deltaX-a.deltaX,u=e.deltaY-a.deltaY,d=z(l,h,u);o=d.x,r=d.y,n=c(d.x)>c(d.y)?d.x:d.y,s=$(h,u),t.lastInterval=e}else n=a.velocity,o=a.velocityX,
|
|
107
|
-
e.velocityX=o,e.velocityY=r,e.direction=s}(n,e);var f,p;var g=t.element;E(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:W(e),deltaX:t.deltaX,deltaY:t.deltaY}}function W(t){var e=t.length;if(1===e)return{x:l(t[0].clientX),y:l(t[0].clientY)};for(var n=0,o=0,i=0;i<e;)n+=t[i].clientX,o+=t[i].clientY,i++;return{x:l(n/e),y:l(o/e)}}function z(t,e,n){return{x:e/t||0,y:n/t||0}}function $(t,e){return t===e?1:c(t)>=c(e)?t<0?2:4:e<0?8:16}function j(t,e,n){n||(n=F);var o=e[n[0]]-t[n[0]],i=e[n[1]]-t[n[1]];return Math.sqrt(o*o+i*i)}function X(t,e,n){n||(n=F);var o=e[n[0]]-t[n[0]],i=e[n[1]]-t[n[1]];return 180*Math.atan2(i,o)/Math.PI}V.prototype={handler:function(){},init:function(){this.evEl&&b(this.element,this.evEl,this.domHandler),
|
|
71
|
+
;for(let e of Array.from(this.document.querySelectorAll("link")))if(["shortcut icon","icon"].includes(e.rel))try{t=this._absoluteUrl(e.href)}catch(t){}return t}_absoluteUrl(t){return Ge(t,this.document.baseURI)}_getDocumentHref(){const{href:t}=this.document.location,e=["http:","https:","file:"],n=new URL(t).protocol;return e.includes(n)?t:this.document.baseURI&&e.includes(new URL(this.document.baseURI).protocol)?this.document.baseURI:t}}function Je(t){return t.width<=0||t.height<=0}function Qe(t,e,n,o){return Math.max(t,n)<Math.min(e,o)}function tn(t,e){return!Je(t)&&!Je(e)&&(Qe(t.left,t.right,e.left,e.right)&&Qe(t.top,t.bottom,e.top,e.bottom))}const en=["p",".para"];let nn;function on(t,e=0,n=t.data.length){return nn||(nn=document.createRange()),nn.setStart(t,e),nn.setEnd(t,n),nn.getBoundingClientRect()}function*rn(t,e){let n=t.firstChild;for(;n;){if(n.nodeType===Node.ELEMENT_NODE){const t=n;tn(t.getBoundingClientRect(),e)&&(yield*rn(t,e))}else if(n.nodeType===Node.TEXT_NODE){const t=n;tn(on(t),e)&&(yield t)
|
|
72
|
+
}n=n.nextSibling}}function sn(t){let e=null;const n=function(t,e){const n=Math.max(t.left,e.left),o=Math.min(t.right,e.right),i=Math.max(t.top,e.top),r=Math.min(t.bottom,e.bottom);return new DOMRect(n,i,o-n,r-i)}(t.getBoundingClientRect(),new DOMRect(0,0,window.innerWidth,window.innerHeight));if(n.width<0||n.height<0)return null;t:for(let r of rn(t,n)){let t=0;for(let s of r.data.split(/\b/)){if(/\S/.test(s)){const a=t,l=t+s.length,c=on(r,a,l);if(i=c,!Je(o=n)&&!Je(i)&&i.left>=o.left&&i.right<=o.right&&i.top>=o.top&&i.bottom<=o.bottom){e=document.createRange(),e.setStart(r,a),e.setEnd(r,l);break t}}t+=s.length}}var o,i;return e}function an(t,e=document.documentElement){const n=sn(e);if(!n)return t(),0;const o=n.getBoundingClientRect().top;t();const i=n.getBoundingClientRect().top-o;return e.scrollTop+=i,i}class ln{constructor(t=document.body){this.container=t,this.anchor=Ye,this.describe=Ze,this._htmlMeta=new Ke,this.sideBySideEnabled=!1}canAnnotate(){return!0}destroy(){}contentContainer(){
|
|
73
|
+
return this.container}fitSideBySide(t){return!!this.sideBySideEnabled&&(t.expanded?(this._activateSideBySide(t.width),!0):(this._deactivateSideBySide(),!1))}_activateSideBySide(t){const e=t+12;an((()=>{document.body.style.marginRight=`${e}px`;const t=function(t){const e=new Map,n=new Map,o=en.join(","),i=Array.from(t.querySelectorAll(o)).map((t=>({rect:t.getBoundingClientRect(),textLength:t.textContent.length}))).filter((({rect:t})=>t.width>0&&t.height>0)).sort(((t,e)=>e.textLength-t.textLength)).slice(0,15);if(i.forEach((({rect:t})=>{var o,i;let r=null!==(o=e.get(t.left))&&void 0!==o?o:0;r+=1,e.set(t.left,r);let s=null!==(i=n.get(t.right))&&void 0!==i?i:0;s+=1,n.set(t.right,s)})),0===e.size||0===n.size)return null;const r=[...e.entries()].sort(((t,e)=>e[1]-t[1])),s=[...n.entries()].sort(((t,e)=>e[1]-t[1])),[a]=r[0],[l]=s[0];return{left:a,right:l}}(document.body);if(t){const n=Math.max(0,window.innerWidth-e-t.right);if(n>0){const t=Math.max(0,e-n);document.body.style.marginRight=`${t}px`}
|
|
74
|
+
t.left<12&&(document.body.style.marginLeft="12px")}else document.body.style.marginLeft="",document.body.style.marginRight=""}))}_deactivateSideBySide(){an((()=>{document.body.style.marginLeft="",document.body.style.marginRight=""}))}async getMetadata(){return this._htmlMeta.getDocumentMetadata()}async uri(){return this._htmlMeta.uri()}scrollToAnchor(t){const e=t.highlights;return new Promise((t=>{Pe(e[0],t)}))}}var cn=/^\s+|\s+$/g,hn=/^[-+]0x[0-9a-f]+$/i,un=/^0b[01]+$/i,dn=/^0o[0-7]+$/i,fn=parseInt,pn="object"==typeof t&&t&&t.Object===Object&&t,gn="object"==typeof self&&self&&self.Object===Object&&self,mn=pn||gn||Function("return this")(),_n=Object.prototype.toString,vn=Math.max,yn=Math.min,wn=function(){return mn.Date.now()};function bn(t){var e=typeof t;return!!t&&("object"==e||"function"==e)}function Cn(t){if("number"==typeof t)return t;if(function(t){return"symbol"==typeof t||function(t){return!!t&&"object"==typeof t}(t)&&"[object Symbol]"==_n.call(t)}(t))return NaN;if(bn(t)){
|
|
75
|
+
var e="function"==typeof t.valueOf?t.valueOf():t;t=bn(e)?e+"":e}if("string"!=typeof t)return 0===t?t:+t;t=t.replace(cn,"");var n=un.test(t);return n||dn.test(t)?fn(t.slice(2),n?2:8):hn.test(t)?NaN:+t}var En=function(t,e,n){var o,i,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=o,r=i;return o=i=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=wn();if(g(t))return _(t);a=setTimeout(m,function(t){var n=e-(t-l);return u?yn(n,r-(t-c)):n}(t))}function _(t){return a=void 0,d&&o?f(t):(o=i=void 0,s)}function v(){var t=wn(),n=g(t);if(o=arguments,i=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=Cn(e)||0,bn(n)&&(h=!!n.leading,r=(u="maxWait"in n)?vn(Cn(n.maxWait)||0,e):r,d="trailing"in n?!!n.trailing:d),v.cancel=function(){void 0!==a&&clearTimeout(a),c=0,o=l=i=a=void 0},
|
|
76
|
+
v.flush=function(){return void 0===a?s:_(wn())},v};let Sn=new Set;function xn(...t){const e=t.join();Sn.has(e)||(console.warn(...t),Sn.add(e))}xn.reset=()=>{Sn.clear()};const Tn=0,An=3,kn=new Map,Rn=new Map;function Nn(t,e){return`${t}:${e}`}function Pn(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 Ln(){return PDFViewerApplication.pdfViewer}async function Mn(t){const e=Ln();let n=e.getPageView(t);return n&&n.pdfPage||(n=await new Promise((n=>{const o=()=>{e.eventBus?e.eventBus.off("pagesloaded",o):document.removeEventListener("pagesloaded",o),n(e.getPageView(t))};e.eventBus?e.eventBus.on("pagesloaded",o):document.addEventListener("pagesloaded",o)}))),n}function On(t){const e=kn.get(t);if(e)return e;const n=(async()=>{const e=await Mn(t);let n=(await e.pdfPage.getTextContent({normalizeWhitespace:!0})).items;return n.length>0&&!("hasEOL"in n[0])&&(n=n.filter((t=>/\S/.test(t.str)))),n.map((t=>t.str)).join("")})()
|
|
77
|
+
;return kn.set(t,n),n}async function In(t){const e=Ln();let n=0,o=0,i="";for(let r=0;r<e.pagesCount;r++)if(i=await On(r),n=o,o+=i.length,o>=t)return{index:r,offset:n,text:i};return{index:e.pagesCount-1,offset:n,text:i}}async function Bn(t,e,n){const[o,i]=await Promise.all([Mn(t),On(t)]);if(o.renderingState===An&&o.textLayer&&o.textLayer.renderingDone){const t=o.textLayer.textLayerDiv;i!==t.textContent&&xn("PDF text layer content does not match page text. This will cause anchoring misalignment.");const r=new de(t,e),s=new de(t,n);return new fe(r,s).toRange()}const r=function(t){let e=t.querySelector(".annotator-placeholder");return e||(e=document.createElement("span"),e.classList.add("annotator-placeholder"),e.textContent="Loading annotations...",t.appendChild(e),e)}(o.div),s=document.createRange();return s.setStartBefore(r),s.setEndAfter(r),s}function Dn(t){const e=[];let n="";for(let o=0;o<t.length;o++){const i=t[o];" "!==i&&"\t"!==i&&"\n"!==i&&(n+=i,e.push(o))}return[n,e]}async function Fn(t,e){
|
|
78
|
+
const n=e.find((t=>"TextQuoteSelector"===t.type));if(!n)throw new Error("No quote selector found");const o=e.find((t=>"TextPositionSelector"===t.type));if(o){try{const{index:t,offset:e,text:i}=await In(o.start),r=o.start-e,s=o.end-e,a=i.substring(r,s);if(n.exact!==a)throw new Error("quote mismatch");return await Bn(t,r,s)}catch{}try{const t=Nn(n.exact,o.start),e=Rn.get(t);if(e){const{pageIndex:t,anchor:n}=e;return await Bn(t,n.start,n.end)}}catch{}}return async function(t,e){const n=Ln().pagesCount,o=Array(n).fill(0).map(((t,e)=>e));let i,r;if(e){const{index:t,offset:n}=await In(e);i=t,r=e-n,o.sort(((e,n)=>Math.abs(e-t)-Math.abs(n-t)))}const[s]=void 0!==t.prefix?Dn(t.prefix):[],[a]=void 0!==t.suffix?Dn(t.suffix):[],[l]=Dn(t.exact);let c;for(let t of o){const e=await On(t),[n,o]=Dn(e);let h;if(void 0!==i&&void 0!==r){let n;for(n=t<i?e.length:t===i?r:0,h=0;h<o.length&&o[h]<n;)++h}const u=He(n,l,{prefix:s,suffix:a,hint:h});if(u&&(!c||u.score>c.match.score)){c={page:t,match:{start:o[u.start],end:o[u.end-1]+1,
|
|
79
|
+
score:u.score}};const e=n.slice(u.start,u.end)===l,i=void 0!==s&&n.slice(Math.max(0,u.start-s.length),u.start)===s,r=void 0!==a&&n.slice(u.end,a.length)===a,h=void 0!==s||void 0!==a;if(e&&(i||r||!h))break}}if(c){const{page:n,match:o}=c;if(e){const i=Nn(t.exact,e);Rn.set(i,{pageIndex:n,anchor:o})}return Bn(n,o.start,o.end)}throw new Error("Quote not found")}(n,null==o?void 0:o.start)}function Hn(t){try{t=fe.fromRange(t).toRange()}catch{throw new Error("Selection does not contain text")}const e=Pn(t.startContainer),n=Pn(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 Vn(t,e){const[n,o]=Hn(e),i=de.fromPoint(n.startContainer,n.startOffset).relativeTo(o),r=de.fromPoint(n.endContainer,n.endOffset).relativeTo(o),s=function(t){let e=0;for(;t.previousSibling;)++e,t=t.previousSibling;return e}(o.parentNode),a=await async function(t){if(t>=Ln().pagesCount)throw new Error("Invalid page index")
|
|
80
|
+
;let e=0;for(let n=0;n<t;n++)e+=(await On(n)).length;return e}(s);return[{type:"TextPositionSelector",start:a+i.offset,end:a+r.offset},je.fromRange(t,n).toSelector()]}function qn(){return mt("div",{className:"WarningBanner WarningBanner--notice",children:[mt("div",{className:"WarningBanner__type",children:mt(vt,{name:"caution",className:"WarningBanner__icon"})}),mt("div",{className:"WarningBanner__message",children:[mt("strong",{children:"This PDF does not contain selectable text:"})," ",mt("a",{target:"_blank",rel:"noreferrer",href:"https://web.hypothes.is/help/how-to-ocr-optimize-pdfs/",children:"Learn how to fix this"})," ","in order to annotate with Hypothesis."]})]})}function Un(t,e,n){return t+n*(e-t)}async function Wn(t,e,{maxDuration:n=500}={}){const o=t.scrollTop,i=e,r=Date.now(),s=Math.min(Math.abs(i-o)/3,n);let a=0;for(;a<1;)await new Promise((t=>{requestAnimationFrame(t)})),a=Math.min(1,(Date.now()-r)/s),t.scrollTop=Un(o,i,a)}class zn{constructor(t){this._loaded=function(t){
|
|
81
|
+
return t.initializedPromise?t.initializedPromise:t.initialized?Promise.resolve():new Promise((e=>{const n=setInterval((()=>{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=Xn(t);return e||(e=jn($n(t))),e}))}async getMetadata(){const t=await this._loaded,{info:e,contentDispositionFilename:n,metadata:o}=await t.pdfDocument.getMetadata(),i=$n(t),r=Xn(t);let s;s=null!=o&&o.has("dc:title")&&"Untitled"!==o.get("dc:title")?o.get("dc:title"):null!=e&&e.Title?e.Title:n||(r?function(t){const e=new URL(t).pathname.split("/");return e[e.length-1]}(r):"");const a=[{href:jn(i)}];return r&&a.push({href:r}),{title:s,link:a,documentFingerprint:i}}}function $n(t){
|
|
82
|
+
return Array.isArray(t.pdfDocument.fingerprints)?t.pdfDocument.fingerprints[0]:t.pdfDocument.fingerprint}function jn(t){return`urn:x-pdf:${t}`}function Xn(t){if(!t.url)return null;const e=Ge(t.url);return 0!==e.indexOf("file://")?e:null}function Yn(t){var e;const n=null===(e=t.highlights)||void 0===e?void 0:e[0];return n&&pe(n)}function Zn(t){return new Promise((e=>setTimeout(e,t)))}class Gn{constructor(t,e={}){var n,o,i;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===(o=s.appConfig)||void 0===o?void 0:o.appContainer)&&void 0!==n?n:document.body,this.pdfMetadata=new zn(s),this.observer=new MutationObserver(En((()=>this._update()),100)),this.observer.observe(this.pdfViewer.viewer,{attributes:!0,attributeFilter:["data-loaded"],childList:!0,subtree:!0}),this._reanchoringMaxWait=null!==(i=e.reanchoringMaxWait)&&void 0!==i?i:3e3,this._warningBanner=null,
|
|
83
|
+
this._checkForSelectableText(),this._updateAnnotationLayerVisibility=()=>{const t=r.getSelection();this.pdfViewer.viewer.classList.toggle("is-selecting",!t.isCollapsed)},this._listeners=new At,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._warningBanner)||void 0===t||t.remove(),this._destroyed=!0}uri(){return this.pdfMetadata.getUri()}getMetadata(){return this.pdfMetadata.getMetadata()}anchor(t,e){return Fn(0,e)}canAnnotate(t){return function(t){try{return Hn(t),!0}catch{return!1}}(t)}describe(t,e){return Vn(t,e)}async _checkForSelectableText(){try{await this.uri()}catch(t){return}if(!this._destroyed)try{const t=await async function(){const t=Ln();let e=!1;for(let n=0;n<t.pagesCount;n++)if((await On(n)).trim().length>0){e=!0;break}return e}();this._toggleNoSelectableTextWarning(!t)}catch(t){
|
|
84
|
+
console.warn("Unable to check for text in PDF:",t)}}_toggleNoSelectableTextWarning(t){const e=document.querySelector("#outerContainer");var n;if(!t)return null===(n=this._warningBanner)||void 0===n||n.remove(),this._warningBanner=null,void(e.style.height="");this._warningBanner=document.createElement("hypothesis-banner"),document.body.prepend(this._warningBanner);const o=se(this._warningBanner);L(mt(qn,{}),o);const i=this._warningBanner.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 Tn:e.textLayer=null;break;case An:o=e.div,i=void 0,null===(i=o.querySelector(".annotator-placeholder"))||void 0===i||i.remove()}}var o,i;for(let e of this.annotator.anchors)if(e.highlights){if(t.includes(e.annotation))continue;for(let n=0;n<e.highlights.length;n++){const o=e.highlights[n]
|
|
85
|
+
;if(!document.body.contains(o)){e.highlights.splice(n,1),delete e.range,t.push(e.annotation);break}}}t.map((t=>this.annotator.anchor(t)))}contentContainer(){return document.querySelector("#viewerContainer")}fitSideBySide(t){const e=window.innerWidth-t.width,n=t.expanded&&e>=680,o=n?t.width:t.toolbarWidth;this.pdfContainer.style.width=`calc(100% - ${o}px)`;const i=this.pdfViewer.currentScaleValue;return"auto"!==i&&"page-fit"!==i&&"page-width"!==i||(this.pdfViewer.currentScaleValue=i),this.pdfViewer.update(),n}async scrollToAnchor(t){const e=t.annotation,n=Yn(t),o=this._anchorOffset(t);if(null!==o&&(await Wn(this.contentContainer(),o),n)){const t=await this._waitForAnnotationToBeAnchored(e,this._reanchoringMaxWait);if(!t)return;const n=this._anchorOffset(t);if(null===n)return;await Wn(this.contentContainer(),n)}}async _waitForAnnotationToBeAnchored(t,e){var n;const o=Date.now();let i;do{i=this.annotator.anchors.find((e=>e.annotation===t)),i&&!Yn(i)||(i=null,await Zn(20))}while(!i&&Date.now()-o<e)
|
|
86
|
+
;return null!==(n=i)&&void 0!==n?n:null}_anchorOffset(t){if(!t.highlights)return null;return function(t,e){let n=0;for(;t!==e&&e.contains(t);)n+=t.offsetTop,t=t.offsetParent;return n}(t.highlights[0],this.contentContainer())}}function Kn(t,e){return t?{left:Math.min(t.left,e.left),right:Math.max(t.right,e.right),top:Math.min(t.top,e.top),bottom:Math.max(t.bottom,e.bottom)}:e}class Jn{constructor(t,e,n){if(e.length!==n.length)throw new Error("Char boxes length does not match text length");const o=t.parentNode,i=document.createElement("hypothesis-text-layer");o.insertBefore(i,t.nextSibling),o.style.position="relative",i.style.position="absolute",i.style.top="0",i.style.left="0",i.style.mixBlendMode="multiply";const r="sans-serif";i.style.fontSize="16px",i.style.fontFamily=r;const s=document.createElement("canvas").getContext("2d");s.font="16px sans-serif";let a=null,l="";const c=[];let h=0;const u=()=>{if(!a)return;const t=document.createElement("span");t.style.position="absolute",t.style.color="transparent",
|
|
87
|
+
t.style.transformOrigin="top left",t.textContent=l,i.append(t),i.append(" "),h||(h=t.getBoundingClientRect().height),c.push({span:t,box:a,width:s.measureText(l).width,height:h}),a=null,l=""};for(let t=0;t<e.length;t++){const o=n[t];if(/\s/.test(o)){u();continue}const i=e[t];a=Kn(a,i),l+=o}u();const d=()=>{const{width:e,height:n}=t.getBoundingClientRect();i.style.width=e+"px",i.style.height=n+"px";for(let{span:t,box:o,width:i,height:r}of c){const s=o.left*e,a=o.top*n,l=o.right*e,c=o.bottom*n;t.style.left=s+"px",t.style.top=a+"px";const h=(l-s)/i,u=(c-a)/r;t.style.transform=`scale(${h}, ${u})`}};d(),this.container=i,this._updateBoxSizes=En(d,{maxWait:50}),this._listeners=new At,"undefined"!=typeof ResizeObserver&&(this._imageSizeObserver=new ResizeObserver((()=>{this._updateBoxSizes()})),this._imageSizeObserver.observe(t)),this._listeners.add(window,"resize",this._updateBoxSizes)}destroy(){var t;this.container.remove(),this._listeners.removeAll(),this._updateBoxSizes.cancel(),
|
|
88
|
+
null===(t=this._imageSizeObserver)||void 0===t||t.disconnect()}}class Qn{constructor(t,e,n){this._element=t,this._onFrameAdded=e,this._onFrameRemoved=n,this._annotatableFrames=new Set,this._isDisconnected=!1,this._mutationObserver=new MutationObserver(En((()=>{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 to(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){this._annotatableFrames.delete(t),this._onFrameRemoved(t)}_discoverFrames(){const t=new Set(this._element.querySelectorAll("iframe[enable-annotation]"))
|
|
89
|
+
;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 to(t){return new Promise((e=>{const n=t.contentWindow.document,{readyState:o,location:i}=n;"about:blank"===i.href&&t.hasAttribute("src")&&"about:blank"!==t.src?t.addEventListener("load",(()=>{e()})):"loading"!==o?e():n.addEventListener("DOMContentLoaded",(()=>e()))}))}class eo{constructor(t,e){this._config=e,this._frameObserver=new Qn(t,(t=>no(t,e)),(()=>{}))}destroy(){this._frameObserver.disconnect()}}async function no(t,e){if(null!==t.contentDocument.querySelector("script.js-hypothesis-config"))return;await to(t);const{assetRoot:n,notebookAppUrl:o,sidebarAppUrl:i}=$t(document),r={...e,assetRoot:n,notebookAppUrl:o,sidebarAppUrl:i,subFrameIdentifier:Rt(10)},s=document.createElement("script");s.className="js-hypothesis-config",s.type="application/json",s.innerText=JSON.stringify(r);const a=document.createElement("script");a.async=!0,a.src=e.clientUrl
|
|
90
|
+
;const l=t.contentDocument;l.body.appendChild(s),l.body.appendChild(a)}function oo(t=document){return t.querySelector("mosaic-book")}function io(t=window){var e;if(oo(t.document))return"container";const n=null===(e=t.frameElement)||void 0===e?void 0:e.ownerDocument;return n&&oo(n)?"content":null}class ro{constructor(t){const e=oo();if(!e)throw new Error("Book container element not found");const n=new WeakSet,o=e=>{var n;const o=null===(n=e.contentDocument)||void 0===n?void 0:n.body;o&&o.children.length>0&&!o.querySelector("#page-content")&&no(e,t)},i=e.shadowRoot,r=()=>{const t=i.querySelector("iframe");t&&!n.has(t)&&(n.add(t),o(t),t.addEventListener("load",(()=>{o(t)})))};r(),this._frameObserver=new MutationObserver(r),this._frameObserver.observe(i,{childList:!0,subtree:!0})}destroy(){this._frameObserver.disconnect()}}function so(){return document.querySelector("img#pbk-page")}class ao{constructor(t=document.body){this._htmlIntegration=new ln(t),this._htmlIntegration.sideBySideEnabled=!0,
|
|
91
|
+
this._listeners=new At;const e=["mousedown","mouseup","mouseout"];for(let t of e)this._listeners.add(document.documentElement,t,(t=>{t.stopPropagation()}));const n=so(),o=window.innerPageData;n&&o&&(this._textLayer=new Jn(n,o.glyphs.glyphs.map((t=>({left:t.l/100,right:t.r/100,top:t.t/100,bottom:t.b/100}))),o.words),this._textLayer.container.style.zIndex="100")}canAnnotate(){return!0}destroy(){var t;null===(t=this._textLayer)||void 0===t||t.destroy(),this._listeners.removeAll(),this._htmlIntegration.destroy()}anchor(t,e){return this._htmlIntegration.anchor(t,e)}describe(t,e){return this._htmlIntegration.describe(t,e)}contentContainer(){return this._htmlIntegration.contentContainer()}fitSideBySide(t){const e=so();if(e&&this._textLayer){const n=e.parentElement,o=window.innerWidth-t.width,i=250;return t.expanded&&o>i?(n.style.textAlign="left",e.style.width=`${o}px`):(n.style.textAlign="",e.style.width=""),t.expanded}return this._htmlIntegration.fitSideBySide(t)}async getMetadata(){return{title:document.title,
|
|
92
|
+
link:[]}}async uri(){const t=new URL(document.location.href);return t.search="",t.toString()}async scrollToAnchor(t){return this._htmlIntegration.scrollToAnchor(t)}}function lo(t){if("undefined"!=typeof PDFViewerApplication)return new Gn(t);return"content"===io()?new ao:new ln}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 ho{constructor(t,e=document){let n=!1;this._pendingCallback=null;const o=(n=10)=>{this._pendingCallback=setTimeout((()=>{t(co(e))}),n)};this._eventHandler=t=>{if("mousedown"===t.type&&(n=!0),"mouseup"===t.type&&(n=!1),n)return;this._cancelPendingCallback();const e="mouseup"===t.type?10:100;o(e)},this._document=e,this._listeners=new At,this._events=["mousedown","mouseup","selectionchange"];for(let t of this._events)this._listeners.add(e,t,this._eventHandler);o(1)}disconnect(){this._listeners.removeAll(),this._cancelPendingCallback()}_cancelPendingCallback(){
|
|
93
|
+
this._pendingCallback&&(clearTimeout(this._pendingCallback),this._pendingCallback=null)}}function uo(){const t=function(t,e){const n=new Set,o=new Set;return _e(t,(t=>{let i=t;for(;i&&!n.has(i);){n.add(i);const t=e(i);null!=t&&o.add(t),i=i.parentNode}})),[...o]}(window.getSelection().getRangeAt(0),(t=>{var e;return null===(e=t._annotation)||void 0===e?void 0:e.$tag}));return t}function fo(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}(t).map((t=>t._annotation)).filter((t=>void 0!==t)).map((t=>null==t?void 0:t.$tag));return e}function po(t){if(!t.range)return null;try{return t.range.toRange()}catch{return null}}function go(){var t;null===(t=document.getSelection())||void 0===t||t.removeAllRanges()}class mo{constructor(t,e={},n=window){this.element=t,this._hostFrame=n,this._highlightsVisible=!1,this._isAdderVisible=!1,this._informHostOnNextSelectionClear=!0,
|
|
94
|
+
this.selectedRanges=[],this._adder=new le(this.element,{onAnnotate:()=>this.createAnnotation(),onHighlight:()=>this.createAnnotation({highlight:!0}),onShowAnnotations:t=>this.selectAnnotations(t)}),this._selectionObserver=new ho((t=>{t?this._onSelection(t):this._onClearSelection()})),this.anchors=[],this._annotations=new Set,this._frameIdentifier=e.subFrameIdentifier||null,this._portFinder=new Lt({hostFrame:this._hostFrame,source:"guest"}),this._integration=lo(this),this._hostRPC=new Wt,this._connectHost(n),this._sidebarRPC=new Wt,this._connectSidebar(),this._bucketBarClient=new Se({contentContainer:this._integration.contentContainer(),hostRPC:this._hostRPC}),this._sideBySideActive=!1,this._listeners=new At,this._setupElementEvents(),this._focusedAnnotations=new Set}_setupElementEvents(){const t=t=>{this._sideBySideActive||fo(t).length||this._sidebarRPC.call("closeSidebar")};this._listeners.add(this.element,"mouseup",(t=>{const{target:e,metaKey:n,ctrlKey:o}=t,i=fo(e);if(i.length&&this._highlightsVisible){
|
|
95
|
+
const t=n||o;this.selectAnnotations(i,t)}})),this._listeners.add(this.element,"mousedown",(({target:e})=>{t(e)})),this._listeners.add(this.element,"touchstart",(({target:e})=>{t(e)})),this._listeners.add(this.element,"mouseover",(({target:t})=>{const e=fo(t);e.length&&this._highlightsVisible&&this._sidebarRPC.call("focusAnnotations",e)})),this._listeners.add(this.element,"mouseout",(()=>{this._highlightsVisible&&this._sidebarRPC.call("focusAnnotations",[])})),this._listeners.add(window,"resize",(()=>this._repositionAdder()))}async getDocumentInfo(){const[t,e]=await Promise.all([this._integration.uri(),this._integration.getMetadata()]);return{uri:Ge(t),metadata:e,frameIdentifier:this._frameIdentifier}}_repositionAdder(){var t;if(!1===this._isAdderVisible)return;const e=null===(t=window.getSelection())||void 0===t?void 0:t.getRangeAt(0);e&&this._onSelection(e)}async _connectHost(t){this._hostRPC.on("clearSelection",(()=>{co(document)&&(this._informHostOnNextSelectionClear=!1,go())})),
|
|
96
|
+
this._hostRPC.on("createAnnotation",(()=>this.createAnnotation())),this._hostRPC.on("focusAnnotations",(t=>this._focusAnnotations(t))),this._hostRPC.on("scrollToClosestOffScreenAnchor",((t,e)=>this._scrollToClosestOffScreenAnchor(t,e))),this._hostRPC.on("selectAnnotations",((t,e)=>this.selectAnnotations(t,e))),this._hostRPC.on("sidebarLayoutChanged",(e=>{var n,o;((n=window)===(o=t)||n.parent===o&&n.frameElement&&n.frameElement.getBoundingClientRect().width/n.parent.innerWidth>=.8)&&this.fitSideBySide(e)}));const e=await this._portFinder.discover("host");this._hostRPC.connect(e)}async _connectSidebar(){this._sidebarRPC.on("focusAnnotations",(t=>this._focusAnnotations(t))),this._sidebarRPC.on("scrollToAnnotation",(t=>{const e=this.anchors.find((e=>e.annotation.$tag===t));if(null==e||!e.highlights)return;const n=po(e);if(!n)return;const o=new CustomEvent("scrolltorange",{bubbles:!0,cancelable:!0,detail:n});this.element.dispatchEvent(o)&&this._integration.scrollToAnchor(e)})),
|
|
97
|
+
this._sidebarRPC.on("setHighlightsVisible",(t=>{this.setHighlightsVisible(t)})),this._sidebarRPC.on("deleteAnnotation",(t=>this.detach(t))),this._sidebarRPC.on("loadAnnotations",(t=>t.forEach((t=>this.anchor(t))))),this._portFinder.discover("sidebar").then((t=>{this._sidebarRPC.connect(t)})),this.getDocumentInfo().then((t=>this._sidebarRPC.call("documentInfoChanged",t)))}destroy(){this._portFinder.destroy(),this._hostRPC.destroy(),this._sidebarRPC.destroy(),this._listeners.removeAll(),this._selectionObserver.disconnect(),this._adder.destroy(),this._bucketBarClient.destroy(),function(t){be(Array.from(t.querySelectorAll("hypothesis-highlight")))}(this.element),this._integration.destroy()}async anchor(t){const e=t=>{const e=po(t);if(!e)return;const n=ye(e);n.forEach((e=>{e._annotation=t.annotation})),t.highlights=n,this._focusedAnnotations.has(t.annotation.$tag)&&Ce(n,!0)};this.detach(t.$tag,!1),this._annotations.add(t.$tag),t.target||(t.target=[]);const n=await Promise.all(t.target.map((async e=>{
|
|
98
|
+
if(!e.selector||!e.selector.some((t=>"TextQuoteSelector"===t.type)))return{annotation:t,target:e};let n;try{const o=await this._integration.anchor(this.element,e.selector),i=fe.fromRange(o);n={annotation:t,target:e,range:i}}catch(o){n={annotation:t,target:e}}return n})));if(!this._annotations.has(t.$tag))return[];for(let t of n)e(t);return t.$orphan=n.length>0&&n.every((t=>t.target.selector&&!t.range)),this._updateAnchors(this.anchors.concat(n),!0),this._sidebarRPC.call("syncAnchoringStatus",t),n}detach(t,e=!0){this._annotations.delete(t);const n=[];for(let e of this.anchors)e.annotation.$tag!==t?n.push(e):e.highlights&&be(e.highlights);this._updateAnchors(n,e)}_updateAnchors(t,e){this.anchors=t,e&&this._bucketBarClient.update(this.anchors)}async createAnnotation({highlight:t=!1}={}){const e=this.selectedRanges;this.selectedRanges=[];const n=await this.getDocumentInfo(),o=this.element,i=(await Promise.all(e.map((t=>this._integration.describe(o,t))))).map((t=>({source:n.uri,selector:t}))),r={uri:n.uri,
|
|
99
|
+
document:n.metadata,target:i,$highlight:t,$tag:"a:"+Rt(8)};return this._sidebarRPC.call("createAnnotation",r),this.anchor(r),go(),r}_focusAnnotations(t){this._focusedAnnotations.clear(),t.forEach((t=>this._focusedAnnotations.add(t)));for(let e of this.anchors)if(e.highlights){const n=t.includes(e.annotation.$tag);Ce(e.highlights,n)}this._sidebarRPC.call("focusAnnotations",t)}_scrollToClosestOffScreenAnchor(t,e){const n=function(t,e){let n=null,o=0;for(let r of t){var i;if(null===(i=r.highlights)||void 0===i||!i.length)continue;const t=Ee(r.highlights).top;"up"===e&&t>=137||"down"===e&&t<=window.innerHeight-22||(!n||"up"===e&&t>o||"down"===e&&t<o)&&(n=r,o=t)}return n}(this.anchors.filter((({annotation:e})=>t.includes(e.$tag))),e);n&&this._integration.scrollToAnchor(n)}_onSelection(t){if(!this._integration.canAnnotate(t))return void this._onClearSelection();const e=document.getSelection(),n=ge(e),o=ve(e);o?(this.selectedRanges=[t],this._hostRPC.call("textSelected"),this._adder.annotationsForSelection=uo(),
|
|
100
|
+
this._isAdderVisible=!0,this._adder.show(o,n)):this._onClearSelection()}_onClearSelection(){this._isAdderVisible=!1,this._adder.hide(),this.selectedRanges=[],this._informHostOnNextSelectionClear&&this._hostRPC.call("textUnselected"),this._informHostOnNextSelectionClear=!0}selectAnnotations(t,e=!1){e?this._sidebarRPC.call("toggleAnnotationSelection",t):this._sidebarRPC.call("showAnnotations",t),this._sidebarRPC.call("openSidebar")}setHighlightsVisible(t){!function(t,e){t.classList.toggle("hypothesis-highlights-always-on",e)}(this.element,t),this._highlightsVisible=t}fitSideBySide(t){this._sideBySideActive=this._integration.fitSideBySide(t)}get sideBySideActive(){return this._sideBySideActive}get focusedAnnotationTags(){return this._focusedAnnotations}}function _o(t,e){const n=new URL(t),o=new URLSearchParams;return o.append("config",JSON.stringify(e)),n.hash=o.toString(),n.toString()}function vo(t,e){var n;const o={};for(let[t,n]of Object.entries(e))"notebookAppUrl"!==t&&"sidebarAppUrl"!==t&&null!=n&&(o[t]=n)
|
|
101
|
+
;o.origin=new URL(t).origin,o.version="1.995.0";const i=new URL(window.location.href);if(i.hash="",o.hostURL=i.toString(),(null===(n=o.services)||void 0===n?void 0:n.length)>0){const t=o.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 o}function yo({config:t,groupId:e}){return mt("iframe",{title:"Hypothesis annotation notebook",className:"h-full w-full border-0",allowFullScreen:!0,src:_o(t.notebookAppUrl,{...vo(t.notebookAppUrl,t),group:e})})}function wo({eventBus:t,config:e}){const[n,o]=rt(0),[i,r]=rt(!0),[s,a]=rt(null),l=lt(""),c=lt(null);st((()=>(l.current=document.body.style.overflow,()=>{document.body.style.overflow=l.current})),[]),st((()=>{document.body.style.overflow=i?l.current:"hidden"}),[i]),st((()=>{const e=t.createEmitter();return e.subscribe("openNotebook",(t=>{r(!1),o((t=>t+1)),
|
|
102
|
+
a(t)})),c.current=e,()=>{e.destroy()}}),[t]);return null===s?null:mt("div",{className:G("fixed z-max top-0 left-0 right-0 bottom-0 p-3 bg-black/50",{hidden:i}),"data-testid":"notebook-outer",children:mt("div",{className:"relative w-full h-full","data-testid":"notebook-inner",children:[mt("div",{className:"absolute right-0 text-xl m-3",children:mt(Ct,{icon:"cancel",title:"Close the Notebook",onClick:()=>{var t;r(!0),null===(t=c.current)||void 0===t||t.publish("closeNotebook")},variant:"dark"})}),mt(yo,{config:e,groupId:s},n)]})})}class bo{constructor(t,e,n={}){this._outerContainer=document.createElement("hypothesis-notebook"),t.appendChild(this._outerContainer),this.shadowRoot=se(this._outerContainer),L(mt(wo,{eventBus:e,config:n}),this.shadowRoot)}destroy(){L(null,this.shadowRoot),this._outerContainer.remove()}}var Co={exports:{}};!function(t){!function(e,n,o,i){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)}
|
|
103
|
+
function d(t,e,n){return!!Array.isArray(t)&&(f(t,n[e],n),!0)}function f(t,e,n){var o;if(t)if(t.forEach)t.forEach(e,n);else if(t.length!==i)for(o=0;o<t.length;)e.call(n,t[o],o,t),o++;else for(o in t)t.hasOwnProperty(o)&&e.call(n,t[o],o,t)}function p(t,n,o){var i="DEPRECATED METHOD: "+n+"\n"+o+" AT \n";return function(){var n=new Error("get-stack-trace"),o=n&&n.stack?n.stack.replace(/^[^\(]+?[\n$]/gm,"").replace(/^\s+at\s+/gm,"").replace(/^Object.<anonymous>\s*\(/gm,"{anonymous}()@"):"Unknown Stack Trace",r=e.console&&(e.console.warn||e.console.log);return r&&r.call(e.console,i,o),t.apply(this,arguments)}}r="function"!=typeof Object.assign?function(t){if(t===i||null===t)throw new TypeError("Cannot convert undefined or null to object");for(var e=Object(t),n=1;n<arguments.length;n++){var o=arguments[n];if(o!==i&&null!==o)for(var r in o)o.hasOwnProperty(r)&&(e[r]=o[r])}return e}:Object.assign;var g=p((function(t,e,n){for(var o=Object.keys(e),r=0;r<o.length;)(!n||n&&t[o[r]]===i)&&(t[o[r]]=e[o[r]]),r++;return t
|
|
104
|
+
}),"extend","Use `assign`."),m=p((function(t,e){return g(t,e,!0)}),"merge","Use `assign`.");function _(t,e,n){var o,i=e.prototype;(o=t.prototype=Object.create(i)).constructor=t,o._super=i,n&&r(o,n)}function v(t,e){return function(){return t.apply(e,arguments)}}function y(t,e){return"function"==typeof t?t.apply(e&&e[0]||i,e):t}function w(t,e){return t===i?e:t}function b(t,e,n){f(x(e),(function(e){t.addEventListener(e,n,!1)}))}function C(t,e,n){f(x(e),(function(e){t.removeEventListener(e,n,!1)}))}function E(t,e){for(;t;){if(t==e)return!0;t=t.parentNode}return!1}function S(t,e){return t.indexOf(e)>-1}function x(t){return t.trim().split(/\s+/g)}function T(t,e,n){if(t.indexOf&&!n)return t.indexOf(e);for(var o=0;o<t.length;){if(n&&t[o][n]==e||!n&&t[o]===e)return o;o++}return-1}function A(t){return Array.prototype.slice.call(t,0)}function k(t,e,n){for(var o=[],i=[],r=0;r<t.length;){var s=e?t[r][e]:t[r];T(i,s)<0&&o.push(t[r]),i[r]=s,r++}return n&&(o=e?o.sort((function(t,n){return t[e]>n[e]})):o.sort()),o}
|
|
105
|
+
function R(t,e){for(var n,o,r=e[0].toUpperCase()+e.slice(1),a=0;a<s.length;){if((o=(n=s[a])?n+r:e)in t)return o;a++}return i}var N=1;function P(t){var n=t.ownerDocument||t;return n.defaultView||n.parentWindow||e}var L="ontouchstart"in e,M=R(e,"PointerEvent")!==i,O=L&&/mobile|tablet|ip(ad|hone|od)|android/i.test(navigator.userAgent),I="touch",B="mouse",D=24,F=["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 o=n.pointers.length,r=n.changedPointers.length,s=1&e&&o-r==0,a=12&e&&o-r==0;n.isFirst=!!s,n.isFinal=!!a,s&&(t.session={}),n.eventType=e,function(t,e){var n=t.session,o=e.pointers,r=o.length;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=W(o);e.timeStamp=h(),
|
|
106
|
+
e.deltaTime=e.timeStamp-s.timeStamp,e.angle=X(l,u),e.distance=j(l,u),function(t,e){var n=e.center,o=t.offsetDelta||{},i=t.prevDelta||{},r=t.prevInput||{};1!==e.eventType&&4!==r.eventType||(i=t.prevDelta={x:r.deltaX||0,y:r.deltaY||0},o=t.offsetDelta={x:n.x,y:n.y});e.deltaX=i.x+(n.x-o.x),e.deltaY=i.y+(n.y-o.y)}(n,e),e.offsetDirection=$(e.deltaX,e.deltaY);var d=z(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=o,j(p[0],p[1],H)/j(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,o):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,o,r,s,a=t.lastInterval||e,l=e.timeStamp-a.timeStamp;if(8!=e.eventType&&(l>25||a.velocity===i)){var h=e.deltaX-a.deltaX,u=e.deltaY-a.deltaY,d=z(l,h,u);o=d.x,r=d.y,n=c(d.x)>c(d.y)?d.x:d.y,s=$(h,u),t.lastInterval=e}else n=a.velocity,o=a.velocityX,
|
|
107
|
+
r=a.velocityY,s=a.direction;e.velocity=n,e.velocityX=o,e.velocityY=r,e.direction=s}(n,e);var f,p;var g=t.element;E(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:W(e),deltaX:t.deltaX,deltaY:t.deltaY}}function W(t){var e=t.length;if(1===e)return{x:l(t[0].clientX),y:l(t[0].clientY)};for(var n=0,o=0,i=0;i<e;)n+=t[i].clientX,o+=t[i].clientY,i++;return{x:l(n/e),y:l(o/e)}}function z(t,e,n){return{x:e/t||0,y:n/t||0}}function $(t,e){return t===e?1:c(t)>=c(e)?t<0?2:4:e<0?8:16}function j(t,e,n){n||(n=F);var o=e[n[0]]-t[n[0]],i=e[n[1]]-t[n[1]];return Math.sqrt(o*o+i*i)}function X(t,e,n){n||(n=F);var o=e[n[0]]-t[n[0]],i=e[n[1]]-t[n[1]];return 180*Math.atan2(i,o)/Math.PI}V.prototype={handler:function(){},init:function(){this.evEl&&b(this.element,this.evEl,this.domHandler),
|
|
108
108
|
this.evTarget&&b(this.target,this.evTarget,this.domHandler),this.evWin&&b(P(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(P(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 J={pointerdown:1,pointermove:2,pointerup:4,pointercancel:8,pointerout:8},Q={2:I,3:"pen",4:B,5:"kinect"},tt="pointerdown",et="pointermove pointerup pointercancel";function nt(){this.evEl=tt,this.evWin=et,V.apply(this,arguments),this.store=this.manager.session.pointerEvents=[]}
|
|
109
109
|
e.MSPointerEvent&&!e.PointerEvent&&(tt="MSPointerDown",et="MSPointerMove MSPointerUp MSPointerCancel"),_(nt,V,{handler:function(t){var e=this.store,n=!1,o=t.type.toLowerCase().replace("ms",""),i=J[o],r=Q[t.pointerType]||t.pointerType,s=r==I,a=T(e,t.pointerId,"pointerId");1&i&&(0===t.button||s)?a<0&&(e.push(t),a=e.length-1):12&i&&(n=!0),a<0||(e[a]=t,this.callback(this.manager,i,{pointers:e,changedPointers:[t],pointerType:r,srcEvent:t}),n&&e.splice(a,1))}});var ot={touchstart:1,touchmove:2,touchend:4,touchcancel:8},it="touchstart",rt="touchstart touchmove touchend touchcancel";function st(){this.evTarget=it,this.evWin=rt,this.started=!1,V.apply(this,arguments)}function at(t,e){var n=A(t.touches),o=A(t.changedTouches);return 12&e&&(n=k(n.concat(o),"identifier",!0)),[n,o]}_(st,V,{handler:function(t){var e=ot[t.type];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,
|
|
110
110
|
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=A(t.touches),o=this.targetIds;if(3&e&&1===n.length)return o[n[0].identifier]=!0,[n,n];var i,r,s=A(t.changedTouches),a=[],l=this.target;if(r=n.filter((function(t){return E(t.target,l)})),1===e)for(i=0;i<r.length;)o[r[i].identifier]=!0,i++;for(i=0;i<s.length;)o[s[i].identifier]&&a.push(s[i]),12&e&&delete o[s[i].identifier],i++;return a.length?[k(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);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,
|
|
@@ -119,20 +119,20 @@ this._super.attrTest.call(this,t)&&n&t.offsetDirection&&t.distance>this.options.
|
|
|
119
119
|
2):8}return Tt},failTimeout:function(){return this._timer=u((function(){this.state=Tt}),this.options.interval,this),Tt},reset:function(){clearTimeout(this._timer)},emit:function(){8==this.state&&(this._input.tapCount=this.count,this.manager.emit(this.options.event,this._input))}}),Ft.VERSION="2.0.7",Ft.defaults={domEvents:!1,touchAction:vt,enable:!0,inputTarget:null,inputClass:null,preset:[[It,{enable:!1}],[Mt,{enable:!1},["rotate"]],[Bt,{direction:6}],[Lt,{direction:6},["swipe"]],[Dt],[Dt,{event:"doubletap",taps:2},["tap"]],[Ot]],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({},Ft.defaults,e||{}),this.options.inputTarget=this.options.inputTarget||t,this.handlers={},this.session={},this.recognizers=[],this.oldCssProps={},this.element=t,this.input=new((n=this).options.inputClass||(M?nt:O?ht:L?dt:K))(n,q),this.touchAction=new xt(this,this.options.touchAction),Vt(this,!0),
|
|
120
120
|
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,o=t.element;o.style&&(f(t.options.cssProps,(function(i,r){n=R(o.style,r),e?(t.oldCssProps[n]=o.style[n],o.style[n]=i):o.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 o=this.recognizers,i=e.curRecognizer;(!i||i&&8&i.state)&&(i=e.curRecognizer=null);for(var r=0;r<o.length;)n=o[r],2===e.stopped||i&&n!=i&&!n.canRecognizeWith(i)?n.reset():n.recognize(t),!i&&14&n.state&&(i=e.curRecognizer=n),r++}},get:function(t){if(t instanceof At)return t
|
|
121
121
|
;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=T(e,t);-1!==n&&(e.splice(n,1),this.touchAction.update())}return this},on:function(t,e){if(t!==i&&e!==i){var n=this.handlers;return f(x(t),(function(t){n[t]=n[t]||[],n[t].push(e)})),this}},off:function(t,e){if(t!==i){var n=this.handlers;return f(x(t),(function(t){e?n[t]&&n[t].splice(T(n[t],e),1):delete n[t]})),this}},emit:function(t,e){this.options.domEvents&&function(t,e){var o=n.createEvent("Event");o.initEvent(t,!0,!0),o.gesture=e,e.target.dispatchEvent(o)}(t,e);var o=this.handlers[t]&&this.handlers[t].slice();if(o&&o.length){e.type=t,e.preventDefault=function(){e.srcEvent.preventDefault()};for(var i=0;i<o.length;)o[i](e),i++}},destroy:function(){
|
|
122
|
-
this.element&&Vt(this,!1),this.handlers={},this.session={},this.input.destroy(),this.element=null}},r(Ft,{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:Tt,DIRECTION_NONE:1,DIRECTION_LEFT:2,DIRECTION_RIGHT:4,DIRECTION_UP:8,DIRECTION_DOWN:16,DIRECTION_HORIZONTAL:6,DIRECTION_VERTICAL:D,DIRECTION_ALL:30,Manager:Ht,Input:V,TouchAction:xt,TouchInput:ht,MouseInput:K,PointerEventInput:nt,TouchMouseInput:dt,SingleTouchInput:st,Recognizer:At,AttrRecognizer:Pt,Tap:Dt,Pan:Lt,Swipe:Bt,Pinch:Mt,Rotate:It,Press:Ot,on:b,off:C,each:f,merge:m,extend:g,assign:r,inherit:_,bindFn:v,prefixed:R}),(void 0!==e?e:"undefined"!=typeof self?self:{}).Hammer=Ft,t.exports?t.exports=Ft:e.Hammer=Ft}(window,document)}(
|
|
123
|
-
function
|
|
124
|
-
},e))),a&&mt(
|
|
125
|
-
;if(!i)return void(i=r(t));const s=t.top>i.top&&t.bottom<i.bottom;if(t.top-i.bottom>60&&!s)o.push(i),i=r(t);else{const e=t.bottom>i.bottom?t.bottom:i.bottom,n=e-i.top;i.tags.add(t.tag),i.bottom=e,i.position=i.top+n/2}})),i&&o.push(i),{above:{tags:e,position:137},below:{tags:n,position:window.innerHeight-22},buckets:o}}(t);L(mt(
|
|
126
|
-
function
|
|
122
|
+
this.element&&Vt(this,!1),this.handlers={},this.session={},this.input.destroy(),this.element=null}},r(Ft,{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:Tt,DIRECTION_NONE:1,DIRECTION_LEFT:2,DIRECTION_RIGHT:4,DIRECTION_UP:8,DIRECTION_DOWN:16,DIRECTION_HORIZONTAL:6,DIRECTION_VERTICAL:D,DIRECTION_ALL:30,Manager:Ht,Input:V,TouchAction:xt,TouchInput:ht,MouseInput:K,PointerEventInput:nt,TouchMouseInput:dt,SingleTouchInput:st,Recognizer:At,AttrRecognizer:Pt,Tap:Dt,Pan:Lt,Swipe:Bt,Pinch:Mt,Rotate:It,Press:Ot,on:b,off:C,each:f,merge:m,extend:g,assign:r,inherit:_,bindFn:v,prefixed:R}),(void 0!==e?e:"undefined"!=typeof self?self:{}).Hammer=Ft,t.exports?t.exports=Ft:e.Hammer=Ft}(window,document)}(Co);var Eo=Co.exports;function So({children:t}){return mt("ul",{className:G("absolute w-[23px] left-[-22px] h-full","bg-grey-2 annotator-collapsed:bg-black/[.08]","pointer-events-none"),children:t})}
|
|
123
|
+
function xo({children:t,topPosition:e}){return mt("li",{className:G("absolute right-0","pointer-events-auto"),style:{top:e},children:t})}function To({above:t,below:e,buckets:n,onFocusAnnotations:o,onScrollToClosestOffScreenAnchor:i,onSelectAnnotations:r}){const s=t.tags.size>0,a=e.tags.size>0;return mt(So,{children:[s&&mt(xo,{topPosition:t.position,children:mt(Et,{className:G("BucketButton UpBucketButton","right-0 mt-[-11px]"),"data-testid":"up-navigation-button",onClick:()=>i([...t.tags],"up"),onBlur:()=>o([]),onFocus:()=>o([...t.tags]),onMouseEnter:()=>o([...t.tags]),onMouseOut:()=>o([]),title:`Go up to next annotations (${t.tags.size})`,children:t.tags.size})}),n.map(((t,e)=>mt(xo,{topPosition:t.position,children:mt(Et,{className:G("BucketButton LeftBucketButton","right-0 mt-[-8px]"),onClick:e=>r([...t.tags],e.metaKey||e.ctrlKey),onBlur:()=>o([]),onFocus:()=>o([...t.tags]),onMouseEnter:()=>o([...t.tags]),onMouseOut:()=>o([]),title:`Select nearby annotations (${t.tags.size})`,children:t.tags.size})
|
|
124
|
+
},e))),a&&mt(xo,{topPosition:e.position,children:mt(Et,{className:"BucketButton DownBucketButton right-0","data-testid":"down-navigation-button",onClick:()=>i([...e.tags],"down"),onBlur:()=>o([]),onFocus:()=>o([...e.tags]),onMouseEnter:()=>o([...e.tags]),onMouseOut:()=>o([]),title:`Go up to next annotations (${e.tags.size})`,children:e.tags.size})})]})}class Ao{constructor(t,{onFocusAnnotations:e,onScrollToClosestOffScreenAnchor:n,onSelectAnnotations:o}){this._bucketsContainer=document.createElement("div"),t.appendChild(this._bucketsContainer),this._onFocusAnnotations=e,this._onScrollToClosestOffScreenAnchor=n,this._onSelectAnnotations=o,this.update([])}destroy(){L(null,this._bucketsContainer),this._bucketsContainer.remove()}update(t){const e=function(t){const e=new Set,n=new Set,o=[];let i=null;function r({bottom:t,tag:e,top:n}){return{bottom:t,position:n+(t-n)/2,tags:new Set([e]),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)
|
|
125
|
+
;if(!i)return void(i=r(t));const s=t.top>i.top&&t.bottom<i.bottom;if(t.top-i.bottom>60&&!s)o.push(i),i=r(t);else{const e=t.bottom>i.bottom?t.bottom:i.bottom,n=e-i.top;i.tags.add(t.tag),i.bottom=e,i.position=i.top+n/2}})),i&&o.push(i),{above:{tags:e,position:137},below:{tags:n,position:window.innerHeight-22},buckets:o}}(t);L(mt(To,{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)}}let ko={};const Ro=t=>{ko=t||{}},No=function(t){t.on("featureFlagsUpdated",Ro)};function Po({...t}){const{icon:e,title:n,...o}=t;return mt(Ct,{className:G("w-[30px] h-[30px]","flex items-center justify-center","border rounded bg-white text-grey-6 hover:text-grey-9 text-annotator-lg","shadow transition-colors"),icon:e,title:n,...o})}
|
|
126
|
+
function Lo({closeSidebar:t,createAnnotation:e,isSidebarOpen:n,newAnnotationType:o,showHighlights:i,toggleHighlights:r,toggleSidebar:s,toggleSidebarRef:a,useMinimalControls:l=!1}){return mt("div",{className:"absolute left-[-33px] w-[33px] z-2",children:[l&&n&&mt(Ct,{className:G("w-[27px] h-[27px] mt-[140px] ml-[6px]","flex items-center justify-center bg-white border","text-grey-6 hover:text-grey-9 text-annotator-lg transition-colors","border-r-0","shadow-sidebar"),title:"Close annotation sidebar",icon:"cancel",onClick:t}),!l&&mt(f,{children:[mt(Ct,{className:G("h-[40px] w-[33px]","bg-white text-grey-5 pl-1.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}),mt("div",{className:"space-y-1.5 mt-2",children:[mt(Po,{title:"Show highlights",icon:i?"show":"hide",selected:i,onClick:r}),mt(Po,{title:"note"===o?"New page note":"New annotation",icon:"note"===o?"note":"annotate",onClick:e})]})]})]})}class Mo{constructor(t,e){
|
|
127
127
|
const{createAnnotation:n,setSidebarOpen:o,setHighlightsVisible:i}=e;this._container=t,this._useMinimalControls=!1,this._newAnnotationType="note",this._highlightsVisible=!1,this._sidebarOpen=!1,this._closeSidebar=()=>o(!1),this._toggleSidebar=()=>o(!this._sidebarOpen),this._toggleHighlights=()=>i(!this._highlightsVisible),this._createAnnotation=()=>{n(),o(!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}set highlightsVisible(t){this._highlightsVisible=t,this.render()}get highlightsVisible(){return this._highlightsVisible}get sidebarToggleButton(){return this._sidebarToggleButton.current}
|
|
128
|
-
render(){L(mt(
|
|
129
|
-
this.iframeContainer=document.createElement("div"),this.iframeContainer.style.display="none",this.iframeContainer.className="annotator-frame","clean"===n.theme?this.iframeContainer.classList.add("annotator-frame--theme-clean"):this.bucketBar=new
|
|
128
|
+
render(){L(mt(Lo,{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)}}class Oo{constructor(t,e,n={}){if(this._emitter=e.createEmitter(),this._guestWithSelection=null,this._guestRPC=[],this._sidebarRPC=new Wt,this.iframe=function(t){const e=_o(t.sidebarAppUrl,vo(t.sidebarAppUrl,t)),n=document.createElement("iframe");return n.setAttribute("allowfullscreen",""),n.src=e,n.title="Hypothesis annotation viewer",n.className="h-sidebar-iframe",n}(n),this._config=n,this.bucketBar=null,n.externalContainerSelector){var o;this.externalFrame=null!==(o=document.querySelector(n.externalContainerSelector))&&void 0!==o?o:t,this.externalFrame.appendChild(this.iframe)}else{
|
|
129
|
+
this.iframeContainer=document.createElement("div"),this.iframeContainer.style.display="none",this.iframeContainer.className="annotator-frame","clean"===n.theme?this.iframeContainer.classList.add("annotator-frame--theme-clean"):this.bucketBar=new Ao(this.iframeContainer,{onFocusAnnotations:t=>this._guestRPC.forEach((e=>e.call("focusAnnotations",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");se(this.hypothesisSidebar).appendChild(this.iframeContainer),t.appendChild(this.hypothesisSidebar)}this.iframe.contentWindow&&Ht(this.iframe.contentWindow),this._listeners=new At;const i=document.createElement("div");this.toolbar=new Mo(i,{createAnnotation:()=>{var t;if(0===this._guestRPC.length)return
|
|
130
130
|
;(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(i),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),this._setupSidebarEvents()}destroy(){var t,e;this._guestRPC.forEach((t=>t.destroy())),this._sidebarRPC.destroy(),
|
|
131
131
|
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(),Ht(null)}onFrameConnected(t,e){switch(t){case"guest":this._connectGuest(e);break;case"sidebar":this._sidebarRPC.connect(e)}}_connectGuest(t){const e=new Wt;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")))}));const n=this.bucketBar;n&&e.on("anchorsChanged",(t=>{0===this._guestRPC.indexOf(e)&&n.update(t)})),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),
|
|
132
|
-
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}))})),function(t,e){const n=t.querySelectorAll("[data-hypothesis-trigger]");function o(t){e(),t.stopPropagation()}Array.from(n).forEach((t=>{t.addEventListener("click",o)}))}(document.body,(()=>this.open())),
|
|
133
|
-
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
|
|
132
|
+
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}))})),function(t,e){const n=t.querySelectorAll("[data-hypothesis-trigger]");function o(t){e(),t.stopPropagation()}Array.from(n).forEach((t=>{t.addEventListener("click",o)}))}(document.body,(()=>this.open())),No(this._sidebarRPC),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()})),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(),
|
|
133
|
+
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 Eo.Manager(t).on("panstart panend panleft panright",(t=>this._onPan(t))),this._hammerManager.add(new Eo.Pan({direction:Eo.DIRECTION_HORIZONTAL})))}_updateLayout(){this.renderFrame||(this.renderFrame=requestAnimationFrame((()=>{if(this.renderFrame=null,this._gestureState.final!==this._gestureState.initial&&this.iframeContainer){const t=this._gestureState.final,e=-t;this.iframeContainer.style.marginLeft=`${t}px`,e>=280&&(this.iframeContainer.style.width=`${e}px`),this._updateLayoutState()}})))}
|
|
134
134
|
_updateLayoutState(t){var e;const n=this.iframeContainer&&this.toolbar.getWidth()||0,o=null!==(e=this.iframeContainer)&&void 0!==e?e:this.externalFrame,i=o.getBoundingClientRect(),r=window.getComputedStyle(o),s=parseInt(r.width),a=parseInt(r.marginLeft);let l=n;"boolean"==typeof t?t&&(l+=s):(a<280?l-=a:l+=s,t=l>n);const c={expanded:t,width:t?l:n,height:i.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<280?this.close():this.open())}_onPan(t){const e=this.iframeContainer;if(e)switch(t.type){case"panstart":this._resetGestureState(),e.classList.add("annotator-no-transition"),e.style.pointerEvents="none",this._gestureState.initial=parseInt(getComputedStyle(e).marginLeft);break;case"panend":e.classList.remove("annotator-no-transition"),e.style.pointerEvents="",null===this._gestureState.final||this._gestureState.final<=-280?this.open():this.close(),
|
|
135
135
|
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("annotator-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("annotator-collapsed")),this.toolbar.sidebarOpen=!1,"whenSidebarOpen"===this._config.showHighlights&&this.setHighlightsVisible(!1),this._updateLayoutState(!1)}setHighlightsVisible(t){this.toolbar.highlightsVisible=t,this._sidebarRPC.call("setHighlightsVisible",t)}show(){
|
|
136
|
-
this.iframeContainer&&this.iframeContainer.classList.remove("is-hidden")}hide(){this.iframeContainer&&this.iframeContainer.classList.add("is-hidden")}}class
|
|
137
|
-
const t=function(t=navigator.userAgent){if(!Ut(t))return()=>{};const e=t=>{var e;if("hypothesisPortClosed"===(null===(e=t.data)||void 0===e?void 0:e.type)&&t.ports[0]){const e=t.ports[0];qt(e,"close"),e.close()}};return window.addEventListener("message",e),()=>window.removeEventListener("message",e)}();n.push({destroy:t});const e=Kt("sidebar"),o=new URL(e.sidebarAppUrl).origin,i=new Vt(o),r=new
|
|
136
|
+
this.iframeContainer&&this.iframeContainer.classList.remove("is-hidden")}hide(){this.iframeContainer&&this.iframeContainer.classList.add("is-hidden")}}class Io{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,o])=>n!==t||o!==e))}destroy(){for(let[t,e]of this._subscriptions)this._emitter.off(t,e);this._subscriptions=[]}}class Bo{constructor(){this._emitter=new It}createEmitter(){return new Io(this._emitter)}}!function(t,{reset:e=!1}={}){e&&_t.clear();for(let[e,n]of Object.entries(t))_t.set(e,n)}(Tt);const Do=document.querySelector('link[type="application/annotator+html"][rel="sidebar"]');new Promise((t=>{"loading"!==document.readyState&&t(),document.addEventListener("readystatechange",(()=>t()))})).then((function(){const t=Kt("annotator"),e=t.subFrameIdentifier?window.parent:window,n=[];if(e===window){
|
|
137
|
+
const t=function(t=navigator.userAgent){if(!Ut(t))return()=>{};const e=t=>{var e;if("hypothesisPortClosed"===(null===(e=t.data)||void 0===e?void 0:e.type)&&t.ports[0]){const e=t.ports[0];qt(e,"close"),e.close()}};return window.addEventListener("message",e),()=>window.removeEventListener("message",e)}();n.push({destroy:t});const e=Kt("sidebar"),o=new URL(e.sidebarAppUrl).origin,i=new Vt(o),r=new Bo,s=new Oo(document.body,r,e),a=new bo(document.body,r,Kt("notebook"));i.on("frameConnected",((t,e)=>s.onFrameConnected(t,e))),n.push(i,s,a)}if("container"===io()){const e=new ro(t);n.push(e)}else{const o=new eo(document.body,t),i=new mo(document.body,t,e);n.push(o,i)}Do.addEventListener("destroy",(()=>{n.forEach((t=>t.destroy()));document.querySelectorAll("[data-hypothesis-asset]").forEach((t=>t.remove()))}))}));
|
|
138
138
|
//# sourceMappingURL=annotator.bundle.js.map
|