hypothesis 1.1044.0 → 1.1045.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 +10 -10
- package/build/scripts/annotator.bundle.js +1 -1
- package/build/scripts/sidebar.bundle.js +64 -64
- package/build/scripts/sidebar.bundle.js.map +1 -1
- package/build/styles/annotator.css +86 -2
- package/build/styles/annotator.css.map +1 -1
- package/build/styles/sidebar.css +73 -3
- package/build/styles/sidebar.css.map +1 -1
- package/build/styles/ui-playground.css +87 -4
- package/build/styles/ui-playground.css.map +1 -1
- package/package.json +1 -1
package/build/boot.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
!function(){"use strict";function t(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n]);return t}function e(t){for(var e=arguments.length,n=new Array(e>1?e-1:0),r=1;r<e;r++)n[r-1]=arguments[r];return n.every((function(e){return"function"==typeof t[e]}))}var n={es2017:function(){return!e(Object,"entries","values")},es2018:function(){return"function"!=typeof Promise||!e(Promise.prototype,"finally")}};function r(t,e){var n="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(!n){if(Array.isArray(t)||(n=o(t))||e&&t&&"number"==typeof t.length){n&&(t=n);var r=0,s=function(){};return{s:s,n:function(){return r>=t.length?{done:!0}:{done:!1,value:t[r++]}},e:function(t){throw t},f:s}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var a,i=!0,l=!1;return{s:function(){n=n.call(t)},n:function(){var t=n.next();return i=t.done,t},e:function(t){l=!0,a=t},f:function(){try{i||null==n.return||n.return()}finally{if(l)throw a}}}}function s(t){return function(t){if(Array.isArray(t))return a(t)}(t)||function(t){if("undefined"!=typeof Symbol&&null!=t[Symbol.iterator]||null!=t["@@iterator"])return Array.from(t)}(t)||o(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 o(t,e){if(t){if("string"==typeof t)return a(t,e);var n=Object.prototype.toString.call(t).slice(8,-1);return"Object"===n&&t.constructor&&(n=t.constructor.name),"Map"===n||"Set"===n?Array.from(t):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?a(t,e):void 0}}function a(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,r=new Array(e);n<e;n++)r[n]=t[n];return r}var i=["es2017","es2018"];function l(t){t.setAttribute("data-hypothesis-asset","")}function c(t,e){var n=t.createElement("link");n.rel="stylesheet",n.type="text/css",n.href=e,l(n),t.head.appendChild(n)}function u(t,e){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},r=n.esModule,s=void 0===r||r,o=n.forceReload,a=void 0!==o&&o,i=t.createElement("script");s&&(i.type="module"),a&&(e+="#ts=".concat(Date.now())),i.src=e,i.async=!1,l(i),t.head.appendChild(i)}function p(t,e,n,r){var s=t.createElement("link");s.rel=e,s.href=r,s.type="application/annotator+".concat(n),l(s),t.head.appendChild(s)}function d(t,e,n){var r=t.createElement("link");r.rel="preload",r.as=e,r.href=n,"fetch"===e&&(r.crossOrigin="anonymous"),l(r),t.head.appendChild(r)}function f(t,e){return t.assetRoot+"build/"+t.manifest[e]}function h(t){return function(t){return t.filter((function(t){var e=n[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 y(t){var e=t.match(/(https?):\/\/([^:/]+)/);return e?{protocol:e[1],hostname:e[2]}:null}function m(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:document,e=t.currentScript;return e?y(e.src):null}function b(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:document;if(-1===t.indexOf("{"))return t;var n=m(e);if(!n)throw new Error("Could not process URL template because script origin is unknown");return t=(t=t.replace("{current_host}",n.hostname)).replace("{current_scheme}",n.protocol)}var v={"scripts/annotator.bundle.js":"scripts/annotator.bundle.js?
|
|
1
|
+
!function(){"use strict";function t(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n]);return t}function e(t){for(var e=arguments.length,n=new Array(e>1?e-1:0),r=1;r<e;r++)n[r-1]=arguments[r];return n.every((function(e){return"function"==typeof t[e]}))}var n={es2017:function(){return!e(Object,"entries","values")},es2018:function(){return"function"!=typeof Promise||!e(Promise.prototype,"finally")}};function r(t,e){var n="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(!n){if(Array.isArray(t)||(n=o(t))||e&&t&&"number"==typeof t.length){n&&(t=n);var r=0,s=function(){};return{s:s,n:function(){return r>=t.length?{done:!0}:{done:!1,value:t[r++]}},e:function(t){throw t},f:s}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var a,i=!0,l=!1;return{s:function(){n=n.call(t)},n:function(){var t=n.next();return i=t.done,t},e:function(t){l=!0,a=t},f:function(){try{i||null==n.return||n.return()}finally{if(l)throw a}}}}function s(t){return function(t){if(Array.isArray(t))return a(t)}(t)||function(t){if("undefined"!=typeof Symbol&&null!=t[Symbol.iterator]||null!=t["@@iterator"])return Array.from(t)}(t)||o(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 o(t,e){if(t){if("string"==typeof t)return a(t,e);var n=Object.prototype.toString.call(t).slice(8,-1);return"Object"===n&&t.constructor&&(n=t.constructor.name),"Map"===n||"Set"===n?Array.from(t):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?a(t,e):void 0}}function a(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,r=new Array(e);n<e;n++)r[n]=t[n];return r}var i=["es2017","es2018"];function l(t){t.setAttribute("data-hypothesis-asset","")}function c(t,e){var n=t.createElement("link");n.rel="stylesheet",n.type="text/css",n.href=e,l(n),t.head.appendChild(n)}function u(t,e){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},r=n.esModule,s=void 0===r||r,o=n.forceReload,a=void 0!==o&&o,i=t.createElement("script");s&&(i.type="module"),a&&(e+="#ts=".concat(Date.now())),i.src=e,i.async=!1,l(i),t.head.appendChild(i)}function p(t,e,n,r){var s=t.createElement("link");s.rel=e,s.href=r,s.type="application/annotator+".concat(n),l(s),t.head.appendChild(s)}function d(t,e,n){var r=t.createElement("link");r.rel="preload",r.as=e,r.href=n,"fetch"===e&&(r.crossOrigin="anonymous"),l(r),t.head.appendChild(r)}function f(t,e){return t.assetRoot+"build/"+t.manifest[e]}function h(t){return function(t){return t.filter((function(t){var e=n[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 y(t){var e=t.match(/(https?):\/\/([^:/]+)/);return e?{protocol:e[1],hostname:e[2]}:null}function m(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:document,e=t.currentScript;return e?y(e.src):null}function b(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:document;if(-1===t.indexOf("{"))return t;var n=m(e);if(!n)throw new Error("Could not process URL template because script origin is unknown");return t=(t=t.replace("{current_host}",n.hostname)).replace("{current_scheme}",n.protocol)}var v={"scripts/annotator.bundle.js":"scripts/annotator.bundle.js?f15f79","scripts/ui-playground.bundle.js":"scripts/ui-playground.bundle.js?dc7bc7","styles/annotator.css":"styles/annotator.css?38d1c7","styles/annotator.css.map":"styles/annotator.css.map?2985c0","styles/highlights.css":"styles/highlights.css?5dd56a","styles/highlights.css.map":"styles/highlights.css.map?f623a8","styles/katex.min.css":"styles/katex.min.css?ac2365","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?6767e2","styles/sidebar.css.map":"styles/sidebar.css.map?bb1d7f","styles/ui-playground.css.map":"styles/ui-playground.css.map?deadc2","styles/ui-playground.css":"styles/ui-playground.css?d178ff","scripts/sidebar.bundle.js":"scripts/sidebar.bundle.js?1f026f","scripts/ui-playground.bundle.js.map":"scripts/ui-playground.bundle.js.map?203ad9","scripts/annotator.bundle.js.map":"scripts/annotator.bundle.js.map?48099a","scripts/sidebar.bundle.js.map":"scripts/sidebar.bundle.js.map?84574e"};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 g=function(e){for(var n={},r=e.querySelectorAll("script.js-hypothesis-config"),s=0;s<r.length;s++){var o=void 0;try{o=JSON.parse(r[s].textContent||"")}catch(t){console.warn("Could not parse settings from js-hypothesis-config tags",t),o={}}t(n,o)}return n}(document),j=b(g.assetRoot||"https://cdn.hypothes.is/hypothesis/1.1045.0/");if(document.querySelector("hypothesis-app")){!function(t,e){d(t,"fetch",e.apiUrl),d(t,"fetch",e.apiUrl+"links");var n,o=h(i),a=r([].concat(s(o),["scripts/sidebar.bundle.js"]));try{for(a.s();!(n=a.n()).done;)u(t,f(e,n.value),{esModule:!0})}catch(t){a.e(t)}finally{a.f()}for(var l=0,p=["styles/katex.min.css","styles/sidebar.css"];l<p.length;l++)c(t,f(e,p[l]))}(document,{assetRoot:j,manifest:v,apiUrl:g.apiUrl})}else{var w=g,A=b(w.notebookAppUrl||"https://hypothes.is/notebook"),k=b(w.sidebarAppUrl||"https://hypothes.is/app.html");!function(t,e){if(!t.querySelector('link[type="application/annotator+html"]')){p(t,"sidebar","html",e.sidebarAppUrl),p(t,"notebook","html",e.notebookAppUrl),d(t,"style",f(e,"styles/annotator.css")),p(t,"hypothesis-client","javascript",e.assetRoot+"build/boot.js");var n,o=h(i),a=r([].concat(s(o),["scripts/annotator.bundle.js"]));try{for(a.s();!(n=a.n()).done;)u(t,f(e,n.value),{esModule:!1})}catch(t){a.e(t)}finally{a.f()}var l=[];void 0!==window.PDFViewerApplication&&l.push("styles/pdfjs-overrides.css"),l.push("styles/highlights.css");for(var y=0,m=l;y<m.length;y++)c(t,f(e,m[y]))}}(document,{assetRoot:j,manifest:v,notebookAppUrl:A,sidebarAppUrl:k})}}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?f15f79",
|
|
3
3
|
"scripts/ui-playground.bundle.js": "scripts/ui-playground.bundle.js?dc7bc7",
|
|
4
|
-
"styles/annotator.css": "styles/annotator.css?
|
|
5
|
-
"styles/annotator.css.map": "styles/annotator.css.map?
|
|
4
|
+
"styles/annotator.css": "styles/annotator.css?38d1c7",
|
|
5
|
+
"styles/annotator.css.map": "styles/annotator.css.map?2985c0",
|
|
6
6
|
"styles/highlights.css": "styles/highlights.css?5dd56a",
|
|
7
7
|
"styles/highlights.css.map": "styles/highlights.css.map?f623a8",
|
|
8
8
|
"styles/katex.min.css": "styles/katex.min.css?ac2365",
|
|
9
|
-
"scripts/ui-playground.bundle.js.map": "scripts/ui-playground.bundle.js.map?203ad9",
|
|
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
|
-
"styles/ui-playground.css": "styles/ui-playground.css?
|
|
16
|
-
"styles/ui-playground.css
|
|
12
|
+
"styles/sidebar.css": "styles/sidebar.css?6767e2",
|
|
13
|
+
"styles/sidebar.css.map": "styles/sidebar.css.map?bb1d7f",
|
|
14
|
+
"styles/ui-playground.css.map": "styles/ui-playground.css.map?deadc2",
|
|
15
|
+
"styles/ui-playground.css": "styles/ui-playground.css?d178ff",
|
|
16
|
+
"scripts/sidebar.bundle.js": "scripts/sidebar.bundle.js?1f026f",
|
|
17
|
+
"scripts/ui-playground.bundle.js.map": "scripts/ui-playground.bundle.js.map?203ad9",
|
|
17
18
|
"scripts/annotator.bundle.js.map": "scripts/annotator.bundle.js.map?48099a",
|
|
18
|
-
"scripts/sidebar.bundle.js": "scripts/sidebar.bundle.js?
|
|
19
|
-
"scripts/sidebar.bundle.js.map": "scripts/sidebar.bundle.js.map?d69f8c"
|
|
19
|
+
"scripts/sidebar.bundle.js.map": "scripts/sidebar.bundle.js.map?84574e"
|
|
20
20
|
}
|
|
@@ -104,7 +104,7 @@ this._listeners.add(this.element,"mouseout",(()=>{this._highlightsVisible&&this.
|
|
|
104
104
|
this._portFinder.destroy(),this._hostRPC.destroy(),this._sidebarRPC.destroy(),this._listeners.removeAll(),this._selectionObserver.disconnect(),this._adder.destroy(),this._bucketBarClient.destroy(),function(t){Ae(Array.from(t.querySelectorAll("hypothesis-highlight")))}(this.element),this._integration.destroy()}async anchor(t){const e=t=>{const e=Oo(t);if(!e)return;const n=Ee(e);n.forEach((e=>{e._annotation=t.annotation})),t.highlights=n,this._focusedAnnotations.has(t.annotation.$tag)&&ke(n,!0)};this.detach(t.$tag,!1),this._annotations.add(t.$tag),t.target||(t.target=[]);const n=await Promise.all(t.target.map((async e=>{if(!e.selector||!e.selector.some((t=>"TextQuoteSelector"===t.type)))return{annotation:t,target:e};let n;try{const o=await this._integration.anchor(this.element,e.selector),i=_e.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)
|
|
105
105
|
;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&&Ae(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,document:n.metadata,target:i,$highlight:t,$tag:"a:"+Lt(8)};return this._sidebarRPC.call("createAnnotation",r),this.anchor(r),Io(),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);ke(e.highlights,n)}
|
|
106
106
|
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=Re(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=we(e),o=xe(e);o?(this.selectedRanges=[t],this._hostRPC.call("textSelected"),this._adder.annotationsForSelection=Mo(),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){
|
|
107
|
-
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 Bo(t,e){const n=new URL(t),o=new URLSearchParams;return o.append("config",JSON.stringify(e)),n.hash=o.toString(),n.toString()}function Fo(t,e){var n;const o={};for(let[t,n]of Object.entries(e))"notebookAppUrl"!==t&&"sidebarAppUrl"!==t&&null!=n&&(o[t]=n);o.origin=new URL(t).origin,o.version="1.
|
|
107
|
+
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 Bo(t,e){const n=new URL(t),o=new URLSearchParams;return o.append("config",JSON.stringify(e)),n.hash=o.toString(),n.toString()}function Fo(t,e){var n;const o={};for(let[t,n]of Object.entries(e))"notebookAppUrl"!==t&&"sidebarAppUrl"!==t&&null!=n&&(o[t]=n);o.origin=new URL(t).origin,o.version="1.1045.0";const i=new URL(window.location.href);if(i.hash="",o.hostURL=i.toString(),Array.isArray(o.services)&&(null===(n=o.services)||void 0===n?void 0:n.length)>0){const t=o.services[0];t.onLoginRequest&&(t.onLoginRequestProvided=!0),
|
|
108
108
|
t.onLogoutRequest&&(t.onLogoutRequestProvided=!0),t.onSignupRequest&&(t.onSignupRequestProvided=!0),t.onProfileRequest&&(t.onProfileRequestProvided=!0),t.onHelpRequest&&(t.onHelpRequestProvided=!0)}return o}function Ho({config:t,groupId:e}){return mt("iframe",{title:"Hypothesis annotation notebook",className:"h-full w-full border-0",allowFullScreen:!0,src:Bo(t.notebookAppUrl,{...Fo(t.notebookAppUrl,t),group:e})})}function Vo({eventBus:t,config:e}){const[n,o]=rt(0),[i,r]=rt(!0),[s,a]=rt(null),c=ct(""),l=ct(null);st((()=>(c.current=document.body.style.overflow,()=>{document.body.style.overflow=c.current})),[]),st((()=>{document.body.style.overflow=i?c.current:"hidden"}),[i]),st((()=>{const e=t.createEmitter();return e.subscribe("openNotebook",(t=>{r(!1),o((t=>t+1)),a(t)})),l.current=e,()=>{e.destroy()}}),[t]);return null===s?null:mt("div",{className:Z("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",
|
|
109
109
|
"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=l.current)||void 0===t||t.publish("closeNotebook")},variant:"dark"})}),mt(Ho,{config:e,groupId:s},n)]})})}class qo{constructor(t,e,n){this._outerContainer=document.createElement("hypothesis-notebook"),t.appendChild(this._outerContainer),this.shadowRoot=he(this._outerContainer),M(mt(Vo,{eventBus:e,config:n}),this.shadowRoot)}destroy(){M(null,this.shadowRoot),this._outerContainer.remove()}}var Uo={exports:{}};!function(t){!function(e,n,o,i){var r,s=["","webkit","Moz","MS","ms","o"],a=n.createElement("div"),c=Math.round,l=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 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)}
|
|
110
110
|
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}),"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(){
|
|
@@ -593,72 +593,72 @@ if("requestAnimationFrame"in window)return window.requestAnimationFrame(e);setTi
|
|
|
593
593
|
"font-bold":r}),onClick:a,onMouseDown:a,pressed:!!r,role:"tab",tabIndex:0,title:s,children:Ro(m,{children:[e,t>0&&!n&&Ro("span",{className:"relative bottom-[3px] left-[2px] text-tiny",children:t})]})})}var xg=Ai((function({annotationsService:e,isLoading:t,settings:n}){const r=Ws(),o=r.selectedTab(),i=r.noteCount(),a=r.annotationCount(),s=r.orphanCount(),l=r.isWaitingToAnchorAnnotations(),c=e=>{r.clearSelection(),r.selectTab(e)},u="annotation"===o&&0===a&&!l,h="note"===o&&0===i;return Ro("div",{className:uo("space-y-3 pb-[9px]"),children:[Ro("div",{className:"flex gap-x-6 theme-clean:ml-[15px]",role:"tablist",children:[Ro(wg,{count:a,isWaitingToAnchor:l,isSelected:"annotation"===o,label:"Annotations",onSelect:()=>c("annotation"),children:"Annotations"}),Ro(wg,{count:i,isWaitingToAnchor:l,isSelected:"note"===o,label:"Page notes",onSelect:()=>c("note"),children:"Page Notes"}),s>0&&Ro(wg,{count:s,isWaitingToAnchor:l,isSelected:"orphan"===o,label:"Orphans",onSelect:()=>c("orphan"),children:"Orphans"})]
|
|
594
594
|
}),"note"===o&&n.enableExperimentalNewNoteButton&&Ro("div",{className:"flex justify-end",children:Ro(qo,{"data-testid":"new-note-button",icon:"add",onClick:()=>e.createPageNote(),variant:"primary",style:Si(["ctaBackgroundColor"],n),children:"New note"})}),!t&&h&&Ro(Go,{classes:"text-center",children:Ro("span",{"data-testid":"notes-unavailable-message",children:"There are no page notes in this group."})}),!t&&u&&Ro(Go,{classes:"text-center",children:Ro("span",{"data-testid":"annotations-unavailable-message",children:["There are no annotations in this group.",Ro("br",{}),"Create one by selecting some text and clicking the"," ",Ro(ei,{classes:"inline m-0.5 -mt-0.5",name:"annotate",title:"Annotate"})," ","button."]})})]})}),["annotationsService","settings"]);var kg=Ai((function({frameSync:e,onLogin:t,onSignUp:n,loadAnnotationsService:r,streamer:o}){
|
|
595
595
|
const i=wl(),a=Ws(),s=a.focusedGroupId(),l=a.hasAppliedFilter()||a.hasSelectedAnnotations(),c=a.isLoading(),u=a.isLoggedIn(),h=a.directLinkedAnnotationId(),d=h?a.findAnnotationByID(h):void 0,p=d?dl(d):"annotation",m=a.searchUris(),f=a.hasSidebarOpened(),g=a.profile().userid,v=d&&!1===d.$orphan?d.$tag:null,y=!(c||!h)&&!d,b=a.directLinkedGroupFetchFailed(),_=y||b,w=!_,x=!_&&!l,k=h&&!u&&!y&&!c,S=So(s);xo((()=>{if(!S.current||S.current!==s){if(S.current){let e=a.focusState().active;a.clearSelection(),e&&a.toggleFocusMode(!0)}S.current=s}s&&m.length&&r.load({groupId:s,uris:m})}),[a,r,s,g,m]),xo((()=>{v?(e.focusAnnotations([v]),e.scrollToAnnotation(v),a.selectTab(p)):d&&a.selectTab(p)}),[p,e,d,v,a]);const C=a.hasFetchedProfile();return xo((()=>{C&&(f||u)&&o.connect({applyUpdatesImmediately:!1})}),[C,u,f,o]),Ro("div",{children:[Ro("h2",{className:"sr-only",children:"Annotations"}),w&&Ro(ug,{}),Ro(_g,{onLogin:t,onSignUp:n}),y&&Ro(og,{errorType:"annotation",onLoginRequest:t,showClearSelection:!0}),b&&Ro(og,{
|
|
596
|
-
errorType:"group",onLoginRequest:t}),x&&Ro(xg,{isLoading:c}),Ro(rg,{threads:i.children}),k&&Ro(hg,{onLogin:t})]})}),["frameSync","loadAnnotationsService","streamer"]);var Sg=Ai((function({api:e,toastMessenger:t}){const n=Ws(),r=n.routeParams().q,o=Ao((async t=>{const r={_separate_replies:!0,offset:0,limit:20,...al(t)};try{n.annotationFetchStarted();const t=await e.search(r);n.addAnnotations([...t.rows,...t.replies])}finally{n.annotationFetchFinished()}}),[e,n]);return xo((()=>{n.setSortKey("Newest"),n.clearAnnotations(),o(r).catch((e=>{t.error(`Unable to fetch annotations: ${e.message}`)}))}),[r,o,n,t]),Ro(rg,{threads:wl().children})}),["api","toastMessenger"]);class Cg{constructor(e,t,n=window){var r,o,i;const a="N/A";let s=a;e.userid&&(s=e.userid,e.displayName&&(s=`${e.displayName} (${s})`)),this.version="1.
|
|
596
|
+
errorType:"group",onLoginRequest:t}),x&&Ro(xg,{isLoading:c}),Ro(rg,{threads:i.children}),k&&Ro(hg,{onLogin:t})]})}),["frameSync","loadAnnotationsService","streamer"]);var Sg=Ai((function({api:e,toastMessenger:t}){const n=Ws(),r=n.routeParams().q,o=Ao((async t=>{const r={_separate_replies:!0,offset:0,limit:20,...al(t)};try{n.annotationFetchStarted();const t=await e.search(r);n.addAnnotations([...t.rows,...t.replies])}finally{n.annotationFetchFinished()}}),[e,n]);return xo((()=>{n.setSortKey("Newest"),n.clearAnnotations(),o(r).catch((e=>{t.error(`Unable to fetch annotations: ${e.message}`)}))}),[r,o,n,t]),Ro(rg,{threads:wl().children})}),["api","toastMessenger"]);class Cg{constructor(e,t,n=window){var r,o,i;const a="N/A";let s=a;e.userid&&(s=e.userid,e.displayName&&(s=`${e.displayName} (${s})`)),this.version="1.1045.0",this.userAgent=n.navigator.userAgent,this.urls=t.map((e=>e.uri)).join(", ")||a,
|
|
597
597
|
this.fingerprint=null!==(r=null===(o=t[0])||void 0===o||null===(i=o.metadata)||void 0===i?void 0:i.documentFingerprint)&&void 0!==r?r:a,this.account=s,this.timestamp=(new Date).toString()}asFormattedString(){return`Version: ${this.version}\nUser Agent: ${this.userAgent}\nURL: ${this.urls}\nFingerprint: ${this.fingerprint}\nAccount: ${this.account}\nDate: ${this.timestamp}\n`}asEncodedURLString(){return encodeURIComponent(this.asFormattedString())}}function Ag(e){const t=P(e);return!(null==t||!t.authority)&&t.authority!==e.authDomain}function Tg({commandName:e,iconName:t}){return Ro("span",{className:"whitespace-nowrap",children:[Ro(ei,{name:t,classes:uo("mx-1 -mt-1","text-color-text-light inline")}),Ro("em",{children:e})]})}var Eg=Ai((function({settings:e}){const t=!Ag(e);return Ro("ol",{className:"list-decimal pl-10 space-y-2",children:[Ro("li",{children:["To create an annotation, select text and then select the"," ",Ro(Tg,{iconName:"annotate",commandName:"Annotate"})," ","button."]}),Ro("li",{
|
|
598
|
-
children:["To create a highlight (",Ro(ti,{classes:"underline hover:underline",href:"https://web.hypothes.is/help/why-are-highlights-private-by-default/",target:"_blank",children:"visible only to you"}),"), select text and then select the"," ",Ro(Tg,{iconName:"highlight",commandName:"Highlight"})," ","button."]}),t&&Ro("li",{children:["To annotate in a private group, select the group from the groups dropdown. Don't see your group? Ask the group creator to send a"," ",Ro(ti,{classes:"underline hover:underline",href:"https://web.hypothes.is/help/how-to-join-a-private-group/",target:"_blank",children:"join link"}),")."]}),Ro("li",{children:["To reply to an annotation, select the"," ",Ro(Tg,{iconName:"reply",commandName:"Reply"})," button."]})]})}),["settings"]);
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
const e=Ws(),t=e.
|
|
605
|
-
children:
|
|
606
|
-
children:null===t?Ro("div",{className:"PaginationNavigation__gap",children:"..."}):Ro(qo,{classes:"PaginationPageButton",title:`Go to page ${t}`,pressed:t===e,onClick:e=>a(t,e.target),variant:"dark",children:t.toString()},`page-${n}`)},n)))}),Ro("div",{className:"PaginationNavigation__relative PaginationNavigation__next",children:r&&Ro(qo,{classes:"PaginationPageButton",icon:"arrow-right",iconPosition:"right",title:"Go to next page",onClick:t=>a(e+1,t.target),variant:"dark",children:"next"})})]})}function
|
|
607
|
-
;const r=Ws(),o=r.getFilterValues(),i=r.focusedGroup(),a=r.forcedVisibleThreads().length,s=r.hasAppliedFilter(),l=r.isLoading(),c=r.annotationResultCount(),u=r.pendingUpdateCount(),h=wl(),d=null!==(n=null==i?void 0:i.name)&&void 0!==n?n:"…",p=(null==i?void 0:i.id)||r.directLinkedGroupId(),m=So(1),[f,g]=_o(1),[v,y]=_o(!1),b=e=>{e instanceof
|
|
608
|
-
}),Ro("div",{className:"
|
|
609
|
-
;var
|
|
610
|
-
title:"Copy share link",variant:"dark"})]})}),Ro("p",{"data-testid":"sharing-details",children:["private"===r.type?Ro("span",{children:["Annotations in the private group"," ",Ro("em",{children:r.name})," are only visible to group members."]}):Ro("span",{children:["Anyone using this link may view the annotations in the group"," ",Ro("em",{children:r.name}),"."]})," ",Ro("span",{children:["Private (",Ro(ei,{name:"lock",classes:"inline -mt-0.5"})," ",Ro("em",{children:"Only Me"}),") annotations are only visible to you."]})]}),Ro("div",{className:"text-[24px]",children:Ro(Wl,{shareURI:a})})]}):Ro("p",{"data-testid":"no-sharing",children:"These annotations cannot be shared because this document is not available on the web."})})]})}),["toastMessenger"]);const
|
|
611
|
-
const n="notice"!==e.type?`${e.type.charAt(0).toUpperCase()+e.type.slice(1)}: `:"",r="notice"===e.type?"cancel":e.type;return Ro(Vo,{classes:uo("p-0 flex border",{"border-red-error":"error"===e.type,"border-yellow-notice":"notice"===e.type,"border-green-success":"success"===e.type}),onClick:()=>t(e.id),children:[Ro("div",{className:uo("flex items-center p-3 text-white",{"bg-red-error":"error"===e.type,"bg-yellow-notice":"notice"===e.type,"bg-green-success":"success"===e.type}),children:Ro(ei,{name:r,classes:uo("mt-[2px]")})}),Ro("div",{className:uo("grow p-3 !mt-0"),"data-testid":"toast-message-text",children:[Ro("strong",{children:n}),e.message,e.moreInfoURL&&Ro("div",{className:"text-right",children:Ro(ti,{href:e.moreInfoURL,onClick:e=>e.stopPropagation(),target:"_new",children:"More info"})})]})]})}var
|
|
612
|
-
children:Ws().getToastMessages().map((t=>Ro("li",{className:uo("relative w-full container hover:cursor-pointer",{"motion-safe:animate-slide-in-from-right lg:animate-fade-in":!t.isDismissed,"motion-reduce:animate-fade-in":!t.isDismissed,"animate-fade-out":t.isDismissed}),children:Ro(
|
|
613
|
-
children:[e&&Ro("h2",{className:"MenuSection__heading",children:e}),Ro("ul",{className:"MenuSection__content",children:x(t).map((e=>Ro("li",{children:e},e.key)))})]})}var
|
|
614
|
-
icon:"copy",isSubmenuItem:!0,label:d})}),t.canLeave&&Ro("li",{children:Ro(Af,{icon:"leave",isSubmenuItem:!0,label:"Leave group",onClick:async()=>{const e=`Are you sure you want to leave the group "${t.name}"?`;await bi({title:"Leave group?",message:e,confirmAction:"Leave"})&&n.leave(t.id)}})})]}),!s&&Ro("p",{className:"GroupListItem__footer",children:"This group is restricted to specific URLs."})]})})}),["groups","toastMessenger"]);function
|
|
615
|
-
}(e)||"",n=
|
|
616
|
-
children:[Ro(
|
|
617
|
-
const o=Ws(),i=o.defaultAuthority(),a=xi(e.userid,i),s=P(r),[l,c]=_o(!1),u=e=>s&&!!s[e],h=!a||u("onProfileRequestProvided"),d=!a||u("onLogoutRequestProvided"),p=()=>{t.notifyHost("openNotebook",o.focusedGroupId())},m=()=>a&&t.notifyHost("profileRequested"),f=(()=>{const t={};return h&&(a||(t.href=o.getLink("user",{user:e.username})),t.onClick=m),t})(),g=Ro("span",{className:"p-1",children:Ro(ei,{name:"profile"})});return Ro("div",{"data-testid":"user-menu",onKeyDown:e=>{"n"===e.key&&(p(),c(!1))},children:Ro(Sf,{label:g,title:e.displayName,align:"right",open:l,onOpenChanged:c,children:[Ro(
|
|
618
|
-
const l=!Ag(a),c=Si(["accentColor"],a),u=Ws(),h=u.filterQuery(),d=u.pendingUpdateCount(),p=u.isSidebarPanelOpen("help"),f=u.isSidebarPanelOpen("shareGroupAnnotations");return Ro("div",{className:uo("absolute h-10 left-0 top-0 right-0 z-4","text-grey-7 border-b theme-clean:border-b-0 bg-white"),"data-testid":"top-bar",children:Ro(
|
|
619
|
-
;e&&e.onHelpRequestProvided?t.notifyHost("helpRequested"):u.toggleSidebarPanel("help")},size:"small",title:"Help"}),"logged-in"===e.status?Ro(
|
|
620
|
-
}),[a,s]),u=Co((()=>Si(["appBackgroundColor"],n)),[n]),h="clean"===n.theme,d="sidebar"===l;xo((()=>{(function(e,t,n){const r="object"==typeof t.preferences&&!!t.preferences.show_sidebar_tutorial,o=P(n)||{onHelpRequestProvided:!1};return e&&!o.onHelpRequestProvided&&r})(d,s,n)&&i.openSidebarPanel("help")}),[d,s,n,i]);const p=async()=>{if(P(n))t.notifyHost("loginRequested");else try{await e.login(),i.closeSidebarPanel("loginPrompt"),i.clearGroups(),r.reload()}catch(e){o.error(e.message)}},m=()=>{P(n)?t.notifyHost("signupRequested"):window.open(i.getLink("signup"))};return Ro("div",{className:uo("h-full min-h-full overflow-scroll","p-[9px] lg:pb-16 bg-grey-2","js-thread-list-scroll-root",{"theme-clean":h,"pt-[49px]":"notebook"!==l,"p-4 lg:p-12":"notebook"===l}),"data-testid":"hypothesis-app",style:u,
|
|
621
|
-
;return 1===e?t="You have an unsaved annotation.\nDo you really want to discard this draft?":e>1&&(t="You have "+e+" unsaved annotations.\nDo you really want to discard these drafts?"),bi({title:"Discard drafts?",message:t,confirmAction:"Discard"})})()&&(i.clearGroups(),i.removeAnnotations(i.unsavedAnnotations()),i.discardAllDrafts(),P(n)?t.notifyHost("logoutRequested"):r.logout())},isSidebar:d}),Ro(
|
|
622
|
-
t.permissions=n.isPrivate?Hl(e.user):ql(e.user,e.group)),{...e,...t}}_initialize(e,t=new Date){const n=this._store.getDefault("annotationPrivacy"),r=this._store.focusedGroupId(),o=this._store.profile();if(!r)throw new Error("Cannot create annotation without a group");const i=o.userid;if(!i)throw new Error("Cannot create annotation when logged out");const a=o.user_info,s="s:"+H(8),l=Object.assign({created:t.toISOString(),group:r,permissions:Ul(i,r,n),tags:[],text:"",updated:t.toISOString(),user:i,user_info:a,$tag:s,hidden:!1,links:{},document:{title:""}},e);return da(l)&&(l.permissions=Hl(i)),l}create(e,t=new Date){const n=this._initialize(e,t);this._store.addAnnotations([n]),this._store.deleteNewAndEmptyDrafts(),da(n)||this._store.createDraft(n,{tags:n.tags,text:n.text,isPrivate:!la(n)}),ma(n)?this._store.selectTab("note"):fa(n)&&this._store.selectTab("annotation"),
|
|
623
|
-
;if(!this._store.isLoggedIn())return void this._store.openSidebarPanel("loginPrompt");if(!e)return;const t={target:[],uri:e.uri};this.create(t)}async delete(e){await this._api.annotation.delete({id:e.id}),this._activity.reportActivity("delete",e),this._store.removeAnnotations([e])}async flag(e){await this._api.annotation.flag({id:e.id}),this._activity.reportActivity("flag",e),this._store.updateFlagStatus(e.id,!0)}reply(e,t){const n={group:e.group,permissions:la(e)?ql(t,e.group):Hl(t),references:(e.references||[]).concat(e.id),target:[{source:e.target[0].source}],uri:e.uri};this.create(n)}async save(e){let t,n;const r=this._applyDraftChanges(e);let o;aa(e)?(t=this._api.annotation.update({id:e.id},r),n="update"):(t=this._api.annotation.create({},r),n="create"),this._store.annotationSaveStarted(e);try{o=await t,this._activity.reportActivity(n,o)}finally{this._store.annotationSaveFinished(e)}
|
|
624
|
-
this._store.addAnnotations([o]),o}}
|
|
625
|
-
function
|
|
626
|
-
;const o=()=>this._clientId,i=e=>
|
|
627
|
-
this._timeout=null,this._operationStart=null,this._timer=null,this._options.forever&&(this._cachedTimeouts=this._timeouts.slice(0))}var _v
|
|
628
|
-
r._options.unref&&r._timeout.unref()),r._fn(r._attempts)}),n),this._options.unref&&this._timer.unref(),!0},
|
|
629
|
-
;e.operation=function(n){var r=e.timeouts(n);return new t(r,{forever:n&&(n.forever||n.retries===1/0),unref:n&&n.unref,maxRetryTime:n&&n.maxRetryTime})},e.timeouts=function(e){if(e instanceof Array)return[].concat(e);var t={retries:10,factor:2,minTimeout:1e3,maxTimeout:1/0,randomize:!1};for(var n in e)t[n]=e[n];if(t.minTimeout>t.maxTimeout)throw new Error("minTimeout is greater than maxTimeout");for(var r=[],o=0;o<t.retries;o++)r.push(this.createTimeout(o,t));return e&&e.forever&&!r.length&&r.push(this.createTimeout(o,t)),r.sort((function(e,t){return e-t})),r},e.createTimeout=function(e,t){var n=t.randomize?Math.random()+1:1,r=Math.round(n*Math.max(t.minTimeout,1)*Math.pow(t.factor,e));return r=Math.min(r,t.maxTimeout)},e.wrap=function(t,n,r){if(n instanceof Array&&(r=n,n=null),!r)for(var o in r=[],t)"function"==typeof t[o]&&r.push(o)
|
|
630
|
-
o.retry(e)||(e&&(arguments[0]=o.mainError()),a.apply(this,arguments))})),o.attempt((function(){r.apply(t,i)}))}.bind(t,s),t[a].options=n}}}(
|
|
631
|
-
client_id:this.clientId,grant_type:"authorization_code",code:e})}exchangeGrantToken(e){return this._getAccessToken({grant_type:"urn:ietf:params:oauth:grant-type:jwt-bearer",assertion:e})}refreshToken(e){return this._getAccessToken({grant_type:"refresh_token",refresh_token:e})}async revokeToken(e){try{await this._formPost(this.revokeEndpoint,{token:e})}catch(e){throw new
|
|
632
|
-
;const o=`left=${e.screen.width/2-237.5},top=${e.screen.height/2-215},width=475,height=430`;if(!e.open(r.toString(),"Log in to Hypothesis",o))throw new Error("Failed to open login window");return n.then((e=>e.code))}async _formPost(e,t){const n=new URLSearchParams;for(let[e,r]of Object.entries(t))n.set(e,r);n.sort();return
|
|
633
|
-
clientId:r.oauthClientId,authorizationEndpoint:e["oauth.authorize"],revokeEndpoint:e["oauth.revoke"],tokenEndpoint:l}),s},m=()=>{var e;return null===(e=P(r))||void 0===e?void 0:e.grantToken},f=async()=>{if(!a){const e=m();void 0!==e?a=e?p().then((t=>t.exchangeGrantToken(e))).catch((e=>{var t;throw t="You must reload the page to annotate.",o.error(`Hypothesis login lost: ${t}`,{autoDismiss:!1}),e})):Promise.resolve(null):i?(a=(async e=>{const t=await p(),n=await t.exchangeAuthCode(e);return d(n),n})(i),i=null):a=Promise.resolve(function(){const e=n.getObject(h());return e&&"string"==typeof e.accessToken&&"string"==typeof e.refreshToken&&"number"==typeof e.expiresAt?{accessToken:e.accessToken,refreshToken:e.refreshToken,expiresAt:e.expiresAt}:null}())}const e=a,t=await a;if(!t)return null;if(e!==a)return f();if(Date.now()>t.expiresAt){
|
|
634
|
-
return null}return t.persist&&d(r),r})(t.refreshToken,{persist:void 0===e}),f()}return t.accessToken};(()=>{e.addEventListener("storage",(({key:e})=>{e===h()&&(a=null,this.emit("oauthTokensChanged"))}))})(),this.login=async function(){const t=await p(),n=await t.authorize(e);i=n,a=null},this.logout=async function(){const[e,t]=await Promise.all([a,p()]);e&&await t.revokeToken(e.accessToken),a=Promise.resolve(null),n.removeItem(h())},this.getAccessToken=f}}
|
|
635
|
-
const r=Array.isArray(t),o=()=>r?t.map((e=>e())):t();let i=o();return e((()=>{const e=o();if(r?rs(e,i):e===i)return;const t=i;i=e,n(e,t)}))}
|
|
636
|
-
;if(("guest"===this._source&&"host"===e||"guest"===this._source&&"sidebar"===e||"sidebar"===this._source&&"host"===e||"notebook"===this._source&&"sidebar"===e)&&(t=!0),!t)throw new Error("Invalid request of channel/port");const n=H(6);return new Promise(((t,r)=>{const o=()=>{this._hostFrame.postMessage({frame1:this._source,frame2:e,type:"request",requestId:n},"*")},i=setInterval(o,250),a=setTimeout((()=>{clearInterval(i),r(new Error(`Unable to establish ${this._source}-${e} communication channel`))}),2e4),s=this._listeners.add(window,"message",(r=>{const{data:o,ports:l}=r;
|
|
637
|
-
this._listeners.add(t,"unload",(()=>{this._port&&(
|
|
638
|
-
return e&&"object"==typeof e?"frame-rpc"!==e.protocol||"1.0.0"!==e.version?null:Array.isArray(e.arguments)?e:null:null}_handle(e){const t=this._parseMessage(e),n=this._port;if(t&&n)if("method"in t){if("close"===t.method){if(this._receivedCloseEvent)return;this._receivedCloseEvent=!0}const e=this._methods.get(t.method);if(!e)return;const r=(...e)=>{const r={arguments:e,protocol:"frame-rpc",response:t.sequence,version:"1.0.0"};n.postMessage(r)};e(...t.arguments,r)}else if("response"in t){const e=this._callbacks.get(t.response);this._callbacks.delete(t.response),e&&e(...t.arguments)}}}function
|
|
639
|
-
this._inFrame=new Set,this._highlightsVisible=!1,this._setupSyncToGuests(),this._setupHostEvents()}_setupSyncToGuests(){let e=0;
|
|
640
|
-
t.on("documentInfoChanged",(e=>{this._guestRPC.delete(n),n=e.frameIdentifier,this._guestRPC.set(n,t),this._store.connectFrame({id:e.frameIdentifier,metadata:e.metadata,uri:e.uri})})),t.on("close",(()=>{const e=this._store.frames().find((e=>e.id===n));e&&this._store.destroyFrame(e),t.destroy(),this._guestRPC.delete(n)})),t.on("createAnnotation",(e=>{if(!this._store.isLoggedIn())return this._hostRPC.call("openSidebar"),this._store.openSidebarPanel("loginPrompt"),void this._guestRPC.forEach((t=>t.call("deleteAnnotation",e.$tag)));this._inFrame.add(e.$tag),e.$highlight||this._hostRPC.call("openSidebar"),this._hostRPC.call("showHighlights"),this._annotationsService.create(e)}));let r={};const o=Pl((()=>{this._store.updateAnchorStatus(r),r={}}),10);t.on("syncAnchoringStatus",(({$tag:e,$orphan:t})=>{this._inFrame.add(e),r[e]=t?"orphan":"anchored",o()})),t.on("showAnnotations",(e=>{this._store.selectAnnotations(this._store.findIDsForTags(e)),this._store.selectTab("annotation")})),
|
|
641
|
-
this._store.focusAnnotations(e||[])})),t.on("toggleAnnotationSelection",(e=>{this._store.toggleSelectedAnnotations(this._store.findIDsForTags(e))})),t.on("openSidebar",(()=>{this._hostRPC.call("openSidebar")})),t.on("closeSidebar",(()=>{this._hostRPC.call("closeSidebar")})),t.connect(e),t.call("setHighlightsVisible",this._highlightsVisible)}_setupHostEvents(){this._hostRPC.on("sidebarOpened",(()=>{this._store.setSidebarOpened(!0)})),this._hostRPC.on("setHighlightsVisible",(e=>{this._highlightsVisible=e,this._guestRPC.forEach((t=>t.call("setHighlightsVisible",e)))}))}async connect(){const e=await this._portFinder.discover("host");this._hostRPC.connect(e),this._listeners.add(e,"message",(e=>{const{data:t,ports:n}=e;
|
|
642
|
-
this._guestRPC.forEach((t=>t.call("scrollToAnnotation",e)))}destroy(){this._portFinder.destroy(),this._listeners.removeAll()}}
|
|
643
|
-
|
|
644
|
-
;const i=this._store.directLinkedGroupId();let a=null;i&&(a=this._fetchGroup(i).then((e=>(this._store.clearDirectLinkedGroupFetchFailed(),e))).catch((()=>(this._store.setDirectLinkedGroupFetchFailed(),null))));const s={expand:
|
|
598
|
+
children:["To create a highlight (",Ro(ti,{classes:"underline hover:underline",href:"https://web.hypothes.is/help/why-are-highlights-private-by-default/",target:"_blank",children:"visible only to you"}),"), select text and then select the"," ",Ro(Tg,{iconName:"highlight",commandName:"Highlight"})," ","button."]}),t&&Ro("li",{children:["To annotate in a private group, select the group from the groups dropdown. Don't see your group? Ask the group creator to send a"," ",Ro(ti,{classes:"underline hover:underline",href:"https://web.hypothes.is/help/how-to-join-a-private-group/",target:"_blank",children:"join link"}),")."]}),Ro("li",{children:["To reply to an annotation, select the"," ",Ro(Tg,{iconName:"reply",commandName:"Reply"})," button."]})]})}),["settings"]);function Ng({label:e,children:t,classes:n}){return Ro(m,{children:[Ro("dt",{className:"col-span-1 sm:text-right font-medium",children:e}),Ro("dd",{className:uo("col-span-1 sm:col-span-3 text-color-text-light break-words",n),children:t})]})}
|
|
599
|
+
var Mg=Ai((function({toastMessenger:e,versionData:t}){return Ro("div",{className:"space-y-4",children:[Ro("dl",{className:"grid grid-cols-1 sm:grid-cols-4 sm:gap-x-2",children:[Ro(Ng,{label:"Version",children:t.version}),Ro(Ng,{label:"User Agent",children:t.userAgent}),Ro(Ng,{classes:uo("break-all"),label:"URL",children:t.urls}),Ro(Ng,{label:"Fingerprint",children:t.fingerprint}),Ro(Ng,{label:"Account",children:t.account}),Ro(Ng,{label:"Date",children:t.timestamp})]}),Ro("div",{className:"flex items-center justify-center",children:Ro(qo,{onClick:()=>{try{Gl(t.asFormattedString()),e.success("Copied version info to clipboard")}catch(t){e.error("Unable to copy version info")}},icon:"copy",children:"Copy version details"})})]})}),["toastMessenger"]);function Lg({children:e,onClick:t}){return Ro(Uo,{classes:"leading-none text-brand",onClick:t,children:[e,Ro(ei,{classes:"ml-1",name:"arrow-right"})]})}function zg({linkText:e,url:t}){return Ro("div",{className:"flex-1 border-r last-of-type:border-r-0",
|
|
600
|
+
children:Ro(ti,{href:t,classes:"flex items-center justify-center space-x-2 text-color-text-light text-lg font-medium",target:"_blank",children:[Ro("span",{children:e})," ",Ro(ei,{name:"external",classes:"w-3 h-3"})]})})}var Og=Ai((function({auth:e,session:t}){const n=Ws(),r=n.frames(),o=n.mainFrame(),i=!!n.profile().preferences.show_sidebar_tutorial,[a,s]=_o("tutorial"),l=Co((()=>{const t=e||{status:"logged-out"},n=[...r].sort(((e,t)=>e===o?-1:t===o?1:0));return new Cg(t,n)}),[e,r,o]),c=`https://web.hypothes.is/get-help/?sys_info=${l.asEncodedURLString()}`,u=(e,t)=>{e.preventDefault(),s(t)};return Ro(bg,{title:"Help",panelName:"help",onActiveChanged:Ao((e=>{!e&&i&&t.dismissSidebarTutorial()}),[t,i]),children:Ro("div",{className:"space-y-4",children:[Ro("div",{className:"flex items-center",children:[Ro("h3",{className:"grow text-lg font-medium","data-testid":"subpanel-title",children:{tutorial:"Getting started",versionInfo:"About this version"}[a]}),"versionInfo"===a&&Ro(Lg,{onClick:e=>u(e,"tutorial"),
|
|
601
|
+
children:"Getting started"}),"tutorial"===a&&Ro(Lg,{onClick:e=>u(e,"versionInfo"),children:"About this version"})]}),Ro("div",{className:"border-y py-4",children:["tutorial"===a&&Ro(Eg,{}),"versionInfo"===a&&Ro(Mg,{versionData:l})]}),Ro("div",{className:"flex items-center",children:[Ro(zg,{linkText:"Help topics",url:"https://web.hypothes.is/help/"}),Ro(zg,{linkText:"New support ticket",url:c})]})]})})}),["session"]),Ig={exports:{}};function Rg(){}Rg.prototype={on:function(e,t,n){var r=this.e||(this.e={});return(r[e]||(r[e]=[])).push({fn:t,ctx:n}),this},once:function(e,t,n){var r=this;function o(){r.off(e,o),t.apply(n,arguments)}return o._=t,this.on(e,o,n)},emit:function(e){for(var t=[].slice.call(arguments,1),n=((this.e||(this.e={}))[e]||[]).slice(),r=0,o=n.length;r<o;r++)n[r].fn.apply(n[r].ctx,t);return this},off:function(e,t){var n=this.e||(this.e={}),r=n[e],o=[];if(r&&t)for(var i=0,a=r.length;i<a;i++)r[i].fn!==t&&r[i].fn._!==t&&o.push(r[i]);return o.length?n[e]=o:delete n[e],this}},Ig.exports=Rg
|
|
602
|
+
;var Pg=Ig.exports.TinyEmitter=Rg;class Dg extends Error{constructor(e){super(`Results size exceeds ${e}`)}}function Bg(e){return 0===e?50:200}class Fg extends Pg{constructor(e,{getPageSize:t=Bg,separateReplies:n=!0,incremental:r=!0,maxResults:o=null,sortBy:i="created",sortOrder:a="asc"}={}){super(),this._searchFn=e,this._getPageSize=t,this._separateReplies=n,this._incremental=r,this._maxResults=o,this._sortBy=i,this._sortOrder=a,this._canceled=!1,this._results=[],this._resultCount=null}async _getPage(e,t,n=0){const r=this._getPageSize(n),o={limit:r,sort:this._sortBy,order:this._sortOrder,_separate_replies:this._separateReplies,...e};t&&(o.search_after=t);try{const t=await this._searchFn(o);if(this._canceled)return;if(null===this._resultCount&&(this._resultCount=t.total,this.emit("resultCount",this._resultCount)),this._maxResults&&t.total>this._maxResults)return this.emit("error",new Dg(this._maxResults)),void this.emit("end");const i=t.rows.concat(t.replies||[])
|
|
603
|
+
;this._incremental?this.emit("results",i):this._results=this._results.concat(i);const a=i.length===r,s=i.length>0?i[i.length-1][this._sortBy]:null;a&&s?this._getPage(e,s,n+1):(this._incremental||this.emit("results",this._results),this.emit("end"))}catch(e){if(this._canceled)return;this.emit("error",e),this.emit("end")}}get(e){this._results=[],this._resultCount=null,this._getPage(e)}cancel(){this._canceled=!0,this.emit("end")}}function jg({defaultOption:e,icon:t,onSelect:n,options:r,selectedOption:o,title:i}){const a=[e,...r],s=null!=o?o:e,l=Ro("span",{className:"FilterSelect__menu-label",children:[t&&Ro(ei,{name:t,classes:"text-xl hyp-u-margin--right--3"}),s.display]});return Ro(Sf,{label:l,title:i,contentClass:"FilterSelect__menu",children:a.map((e=>Ro(Af,{onClick:()=>n(e),isSelected:e.value===s.value,label:e.display},e.value)))})}function Hg(){const e=Ws(),t=e.getFilter("user"),n=function(){
|
|
604
|
+
const e=Ws(),t=e.allAnnotations(),n=e.defaultAuthority(),r=e.isFeatureEnabled("client_display_names"),o=e.getFocusFilters(),i=wi(e.profile().userid);return Co((()=>{const e={};if(t.forEach((t=>{const o=wi(t.user);e[o]=Nf(t,xi(t.user,n),r)})),o.user){const t=wi(o.user.value)||o.user.value;e[t]=o.user.display}const a=Object.keys(e).map((t=>({display:t===i?`${e[t]} (Me)`:e[t],value:t})));return a.sort(((e,t)=>i===e.value?-1:i===t.value?1:e.display.localeCompare(t.display))),a}),[t,i,n,r,o.user])}();return Ro(jg,{defaultOption:{value:"",display:"Everybody"},icon:"profile",onSelect:t=>e.setFilter("user",t),options:n,selectedOption:t,title:"Filter by user"})}function qg({forcedVisibleCount:e,isFiltered:t,isLoading:n,resultCount:r}){const o=wl(),i=n?r:fl(o),a=o.children.length>0,s=t&&e>0,l=i-e,c=o.children.length;return Ro("div",{className:"flex gap-x-1 leading-none",children:[n&&Ro(di,{size:"small"}),!n&&Ro("h2",{className:"font-bold",children:[!a&&Ro("span",{children:"No results"}),a&&t&&Ro("span",{
|
|
605
|
+
children:[l," ",1===l?"result":"results"]}),a&&!t&&Ro("span",{children:[c," ",1===c?"thread":"threads"]})]}),s&&Ro("h3",{className:"italic font-normal",children:["(and ",e," more)"]}),!t&&a&&Ro("h3",{className:"italic font-normal",children:["(",i," ",1===i?"annotation":"annotations",")"]})]})}function Ug({currentPage:e,onChangePage:t,totalPages:n}){const r=e<n,o=e>1,i=function(e,t,n=5){if(t<=1)return[];const r=new Set([1,e,t]);let o=1;for(;r.size<Math.min(t,n);)e+o<=t&&r.add(e+o),e-o>=1&&r.add(e-o),++o;const i=[];return[...r].sort(((e,t)=>e-t)).forEach(((e,t,n)=>{t>0&&e-n[t-1]>1&&i.push(null),i.push(e)})),i}(e,n),a=(e,n)=>{t(e),n.blur()};return Ro("div",{className:"PaginationNavigation",children:[Ro("div",{className:"PaginationNavigation__relative PaginationNavigation__prev",children:o&&Ro(qo,{classes:"PaginationPageButton",icon:"arrow-left",title:"Go to previous page",onClick:t=>a(e-1,t.target),variant:"dark",children:"prev"})}),Ro("ul",{className:"PaginationNavigation__pages",
|
|
606
|
+
children:i.map(((t,n)=>Ro("li",{children:null===t?Ro("div",{className:"PaginationNavigation__gap",children:"..."}):Ro(qo,{classes:"PaginationPageButton",title:`Go to page ${t}`,pressed:t===e,onClick:e=>a(t,e.target),variant:"dark",children:t.toString()},`page-${n}`)},n)))}),Ro("div",{className:"PaginationNavigation__relative PaginationNavigation__next",children:r&&Ro(qo,{classes:"PaginationPageButton",icon:"arrow-right",iconPosition:"right",title:"Go to next page",onClick:t=>a(e+1,t.target),variant:"dark",children:"next"})})]})}function $g({currentPage:e,isLoading:t,onChangePage:n,threads:r,pageSize:o=25}){const{paginatedThreads:i,totalPages:a}=Co((()=>{const t=r.filter((e=>fl(e)>0)),n=(e-1)*o,i=n+o,a=Math.ceil(t.length/o);return{paginatedThreads:t.slice(n,i),totalPages:a}}),[r,e,o]);return Ro(m,{children:[Ro(rg,{threads:i}),!t&&Ro(Ug,{currentPage:e,onChangePage:n,totalPages:a})]})}var Gg=Ai((function({loadAnnotationsService:e,streamer:t}){var n
|
|
607
|
+
;const r=Ws(),o=r.getFilterValues(),i=r.focusedGroup(),a=r.forcedVisibleThreads().length,s=r.hasAppliedFilter(),l=r.isLoading(),c=r.annotationResultCount(),u=r.pendingUpdateCount(),h=wl(),d=null!==(n=null==i?void 0:i.name)&&void 0!==n?n:"…",p=(null==i?void 0:i.id)||r.directLinkedGroupId(),m=So(1),[f,g]=_o(1),[v,y]=_o(!1),b=e=>{e instanceof Dg&&y(!0)},_=r.hasFetchedProfile();xo((()=>{_&&t.connect({applyUpdatesImmediately:!1})}),[_,t]),xo((()=>{r.setSortKey("Newest"),p&&e.load({groupId:p,sortBy:"updated",sortOrder:"desc",maxResults:5e3,onError:b,streamFilterBy:"group"})}),[e,p,r]);const w=e=>{g(e)};xo((()=>{w(1)}),[o,i]);const x=So(null);ko((()=>{f!==m.current&&(x.current&&yg(x.current),m.current=f)}),[f]);const k=`Show ${u} new or updated ${u>1?"annotations":"annotation"}`;return Ro("div",{className:"grid gap-2 lg:grid-cols-2","data-testid":"notebook-container",children:[Ro("header",{className:"leading-none lg:col-span-2",ref:x,children:Ro("h1",{className:"text-2xl font-bold",
|
|
608
|
+
"data-testid":"notebook-group-name",children:d})}),Ro("div",{children:Ro(Hg,{})}),Ro("div",{className:"flex items-center lg:justify-self-end text-lg font-medium",children:[u>0&&!s&&Ro(Ho,{icon:"refresh",onClick:()=>t.applyPendingUpdates(),variant:"primary",title:k}),Ro(qg,{forcedVisibleCount:a,isFiltered:s,isLoading:l,resultCount:null!=c?c:0})]}),Ro("div",{className:"lg:col-span-2",children:[v&&Ro("div",{className:"py-4","data-testid":"notebook-messages",children:Ro(ui,{title:"Too many results to show",children:["This preview of the Notebook can show"," ",Ro("strong",{children:["up to ",5e3," results"]})," at a time (there are"," ",c," to show here)."," ",Ro("a",{href:"mailto:support@hypothes.is?subject=Hypothesis%20Notebook&body=Please%20notify%20me%20when%20the%20Hypothesis%20Notebook%20is%20updated%20to%20support%20more%20than%205000%20annotations",children:"Contact us"})," ","if you would like to be notified when support for more annotations is available."]})}),Ro($g,{currentPage:f,isLoading:l,
|
|
609
|
+
onChangePage:w,threads:h.children})]})]})}),["loadAnnotationsService","streamer"]);var Vg=Ai((function({toastMessenger:e}){const t=Ws(),n=t.mainFrame(),r=t.focusedGroup(),o=`Share Annotations in ${r&&r.name||"..."}`,i=r&&n,a=i&&(s=n.uri,l=r.id,jl(s)?`https://hyp.is/go?url=${encodeURIComponent(s)}&group=${l}`:null);var s,l;return Ro(bg,{title:o,panelName:"shareGroupAnnotations",children:[!i&&Ro("div",{className:"flex flex-row items-center justify-center",children:Ro(di,{})}),i&&Ro("div",{className:"text-color-text-light space-y-3",children:a?Ro(m,{children:[Ro("div",{className:"text-color-text font-medium","data-testid":"sharing-intro",children:"private"===r.type?Ro("p",{children:"Use this link to share these annotations with other group members:"}):Ro("p",{children:"Use this link to share these annotations with anyone:"})}),Ro("div",{children:Ro(fi,{children:[Ro(mi,{"aria-label":"Use this URL to share these annotations",type:"text",value:a,readOnly:!0}),Ro(Ho,{icon:"copy",onClick:()=>{try{Gl(a),
|
|
610
|
+
e.success("Copied share link to clipboard")}catch(t){e.error("Unable to copy link")}},title:"Copy share link",variant:"dark"})]})}),Ro("p",{"data-testid":"sharing-details",children:["private"===r.type?Ro("span",{children:["Annotations in the private group"," ",Ro("em",{children:r.name})," are only visible to group members."]}):Ro("span",{children:["Anyone using this link may view the annotations in the group"," ",Ro("em",{children:r.name}),"."]})," ",Ro("span",{children:["Private (",Ro(ei,{name:"lock",classes:"inline -mt-0.5"})," ",Ro("em",{children:"Only Me"}),") annotations are only visible to you."]})]}),Ro("div",{className:"text-[24px]",children:Ro(Wl,{shareURI:a})})]}):Ro("p",{"data-testid":"no-sharing",children:"These annotations cannot be shared because this document is not available on the web."})})]})}),["toastMessenger"]);const Wg=function(e,t){function n({classes:e,elementRef:n,children:r,...o}){return Ro("div",{className:uo(t,e),ref:n,...o,children:r})}return n.displayName=e,n
|
|
611
|
+
}("SidebarContent","mx-auto lg:px-16 lg:max-w-3xl");function Yg({message:e,onDismiss:t}){const n="notice"!==e.type?`${e.type.charAt(0).toUpperCase()+e.type.slice(1)}: `:"",r="notice"===e.type?"cancel":e.type;return Ro(Vo,{classes:uo("p-0 flex border",{"border-red-error":"error"===e.type,"border-yellow-notice":"notice"===e.type,"border-green-success":"success"===e.type}),onClick:()=>t(e.id),children:[Ro("div",{className:uo("flex items-center p-3 text-white",{"bg-red-error":"error"===e.type,"bg-yellow-notice":"notice"===e.type,"bg-green-success":"success"===e.type}),children:Ro(ei,{name:r,classes:uo("mt-[2px]")})}),Ro("div",{className:uo("grow p-3 !mt-0"),"data-testid":"toast-message-text",children:[Ro("strong",{children:n}),e.message,e.moreInfoURL&&Ro("div",{className:"text-right",children:Ro(ti,{href:e.moreInfoURL,onClick:e=>e.stopPropagation(),target:"_new",children:"More info"})})]})]})}var Kg=Ai((function({toastMessenger:e}){return Ro("div",{children:Ro("ul",{"aria-live":"polite",
|
|
612
|
+
"aria-relevant":"additions",className:"absolute z-2 left-0 w-full space-y-2",children:Ws().getToastMessages().map((t=>Ro("li",{className:uo("relative w-full container hover:cursor-pointer",{"motion-safe:animate-slide-in-from-right lg:animate-fade-in":!t.isDismissed,"motion-reduce:animate-fade-in":!t.isDismissed,"animate-fade-out":t.isDismissed}),children:Ro(Yg,{message:t,onDismiss:t=>e.dismiss(t)})},t.id)))})})}),["toastMessenger"]);function Xg(e){return e.organization&&e.organization.name}function Zg(e){const t={};return e.forEach((e=>{if("object"!=typeof e.organization)return;const n="__default__"===(r=e.organization).id?"__default__":`${r.name.toLowerCase()}${r.id}`;var r;void 0===t[n]&&(t[n]={...e.organization,groups:[]}),function(e,t){const n=Object.assign({},e),r=t.groups;!r.length&&e.organization.logo&&(n.logo=e.organization.logo),r.push(n)}(e,t[n])})),t}function Jg(e){const t=Zg(e),n=[],r=[];return Object.keys(t).sort().forEach((e=>{"__default__"===e?n.push(...t[e].groups):r.push(...t[e].groups)})),
|
|
613
|
+
n.length&&r.push(...n),r}function Qg({heading:e,children:t}){return Ro(m,{children:[e&&Ro("h2",{className:"MenuSection__heading",children:e}),Ro("ul",{className:"MenuSection__content",children:x(t).map((e=>Ro("li",{children:e},e.key)))})]})}var ev=Ai((function({isExpanded:e,group:t,groups:n,onExpand:r,toastMessenger:o}){const i=t.links.html,a=i||t.canLeave,s=t.scopes&&!t.scopes.enforced||t.isScopedToUri,l=Ws(),c=l.focusedGroupId(),u=t.id===c,h=t=>{t.stopPropagation(),t.preventDefault(),r(!e)},d="private"===t.type?"Copy invite link":"Copy activity link";return Ro(Af,{icon:t.logo||"blank",iconAlt:Xg(t),isDisabled:!s,isExpanded:!!a&&e,isSelected:u,isSubmenuVisible:a?e:void 0,label:t.name,onClick:s?()=>{l.clearDirectLinkedGroupFetchFailed(),l.clearDirectLinkedIds(),n.focus(t.id)}:h,onToggleSubmenu:h,submenu:Ro(m,{children:[Ro("ul",{children:[i&&Ro("li",{children:Ro(Af,{href:i,icon:"external",isSubmenuItem:!0,label:"View group activity"})}),i&&Ro("li",{children:Ro(Af,{onClick:()=>(e=>{try{Gl(e),
|
|
614
|
+
o.success(`Copied link for "${t.name}"`)}catch(e){o.error("Unable to copy link")}})(i),icon:"copy",isSubmenuItem:!0,label:d})}),t.canLeave&&Ro("li",{children:Ro(Af,{icon:"leave",isSubmenuItem:!0,label:"Leave group",onClick:async()=>{const e=`Are you sure you want to leave the group "${t.name}"?`;await bi({title:"Leave group?",message:e,confirmAction:"Leave"})&&n.leave(t.id)}})})]}),!s&&Ro("p",{className:"GroupListItem__footer",children:"This group is restricted to specific URLs."})]})})}),["groups","toastMessenger"]);function tv({expandedGroup:e,onExpandGroup:t,groups:n,heading:r}){return Ro(Qg,{heading:r,children:n.map((n=>Ro(ev,{isExpanded:n===e,onExpand:e=>t(e?n:null),group:n},n.id)))})}var nv=Ai((function({settings:e}){const t=Ws(),n=t.getCurrentlyViewingGroups(),r=t.getFeaturedGroups(),o=t.getMyGroups(),i=t.focusedGroup(),a=t.profile().userid,s=Co((()=>Jg(o)),[o]),l=Co((()=>Jg(r)),[r]),c=Co((()=>Jg(n)),[n]),u=t.defaultAuthority(),h=a&&!xi(a,u),d=t.getLink("groups.new"),[p,m]=_o(null);let f;if(i){
|
|
615
|
+
const t=i.organization.logo||function(e){const t=P(e);return t&&t.icon?t.icon:null}(e)||"",n=Xg(i)?Xg(i):"";f=Ro("span",{className:"GroupList__menu-label",children:[t&&Ro("img",{className:"GroupList__menu-icon",src:t,alt:n}),i.name]})}else f=Ro("span",{children:"…"});return!!Ag(e)&&n.length+r.length+o.length<2?f:Ro(Sf,{align:"left",contentClass:"GroupList__content",label:f,onOpenChanged:()=>m(null),title:i?`Select group (now viewing: ${i.name})`:"Select group",children:[c.length>0&&Ro(tv,{expandedGroup:p,onExpandGroup:m,heading:"Currently Viewing",groups:c}),l.length>0&&Ro(tv,{expandedGroup:p,onExpandGroup:m,heading:"Featured Groups",groups:l}),s.length>0&&Ro(tv,{expandedGroup:p,onExpandGroup:m,heading:"My Groups",groups:s}),h&&Ro(Af,{icon:"add",href:d,label:"New private group"})]})}),["settings"]);function rv({alwaysExpanded:e,query:t,onSearch:n}){const r=Ws().isLoading(),o=So(),[i,a]=_o(t),[s,l]=_o(t);t!==i&&(l(t),a(t));const c=e||t;return Ro("form",{action:"#",
|
|
616
|
+
className:uo("relative","flex items-center","bg-white/90 hover:bg-white transition-colors"),name:"searchForm",onSubmit:e=>{e.preventDefault(),(o.current.value||i)&&n(o.current.value)},children:[Ro(mi,{"aria-label":"Search",classes:uo("order-1","text-base",{"border-0":!c,"focus:border":!0,border:c},{"max-w-0 p-0":!c,"focus:max-w-[150px] focus:p-1.5 focus:ml-[2px]":!0,"max-w-[150px] p-1.5 ml-[2px]":c},"transition-[max-width] duration-300 ease-out"),dir:"auto",type:"text",name:"query",placeholder:r?"Loading…":"Search…",disabled:r,inputRef:o,value:s||"",onInput:e=>l(e.target.value)}),!r&&Ro("div",{className:"order-0",children:Ro(Ho,{icon:"search",onClick:()=>o.current.focus(),size:"small",title:"Search annotations"})}),r&&Ro(di,{size:"small"})]})}function ov(){const e=Ws(),t=e.sortKey(),n=e.sortKeys().map((n=>Ro(Af,{label:n,onClick:()=>e.setSortKey(n),isSelected:n===t},n))),r=Ro("span",{className:"p-1",children:Ro(ei,{name:"sort"})});return Ro("div",{className:"SortMenu",children:Ro(Sf,{label:r,
|
|
617
|
+
title:`Sort by ${t}`,align:"right",menuIndicator:!1,children:n})})}var iv=Ai((function({router:e}){return Ro(rv,{query:Ws().routeParams().q,onSearch:t=>{e.navigate("stream",{q:t})},alwaysExpanded:!0})}),["router"]);var av=Ai((function({auth:e,frameSync:t,onLogout:n,settings:r}){const o=Ws(),i=o.defaultAuthority(),a=xi(e.userid,i),s=P(r),[l,c]=_o(!1),u=e=>s&&!!s[e],h=!a||u("onProfileRequestProvided"),d=!a||u("onLogoutRequestProvided"),p=()=>{t.notifyHost("openNotebook",o.focusedGroupId())},m=()=>a&&t.notifyHost("profileRequested"),f=(()=>{const t={};return h&&(a||(t.href=o.getLink("user",{user:e.username})),t.onClick=m),t})(),g=Ro("span",{className:"p-1",children:Ro(ei,{name:"profile"})});return Ro("div",{"data-testid":"user-menu",onKeyDown:e=>{"n"===e.key&&(p(),c(!1))},children:Ro(Sf,{label:g,title:e.displayName,align:"right",open:l,onOpenChanged:c,children:[Ro(Qg,{children:[Ro(Af,{label:e.displayName,isDisabled:!h,...f}),!a&&Ro(Af,{label:"Account settings",href:o.getLink("account.settings")}),Ro(Af,{
|
|
618
|
+
label:"Open notebook",onClick:()=>p()})]}),d&&Ro(Qg,{children:Ro(Af,{label:"Log out",onClick:n})})]})})}),["frameSync","settings"]);var sv=Ai((function({auth:e,frameSync:t,isSidebar:n,onLogin:r,onLogout:o,onSignUp:i,settings:a,streamer:s}){const l=!Ag(a),c=Si(["accentColor"],a),u=Ws(),h=u.filterQuery(),d=u.pendingUpdateCount(),p=u.isSidebarPanelOpen("help"),f=u.isSidebarPanelOpen("shareGroupAnnotations");return Ro("div",{className:uo("absolute h-10 left-0 top-0 right-0 z-4","text-grey-7 border-b theme-clean:border-b-0 bg-white"),"data-testid":"top-bar",children:Ro(Wg,{classes:uo("flex items-center h-full","px-[9px]","text-xl"),"data-testid":"top-bar-content",children:[Ro(n?nv:iv,{}),Ro("div",{className:"grow flex items-center justify-end",children:[n&&Ro(m,{children:[d>0&&Ro(Ho,{icon:"refresh",onClick:()=>s.applyPendingUpdates(),size:"small",variant:"primary",title:`Show ${d} new/updated ${1===d?"annotation":"annotations"}`}),Ro(rv,{query:h||null,onSearch:u.setFilterQuery}),Ro(ov,{}),l&&Ro(Ho,{icon:"share",
|
|
619
|
+
expanded:f,onClick:()=>{u.toggleSidebarPanel("shareGroupAnnotations")},size:"small",title:"Share annotations on this page"})]}),Ro(Ho,{icon:"help",expanded:p,onClick:()=>{const e=P(a);e&&e.onHelpRequestProvided?t.notifyHost("helpRequested"):u.toggleSidebarPanel("help")},size:"small",title:"Help"}),"logged-in"===e.status?Ro(av,{auth:e,onLogout:o}):Ro("div",{className:"flex items-center text-lg font-medium space-x-1","data-testid":"login-links",children:["unknown"===e.status&&Ro("span",{children:"⋯"}),"logged-out"===e.status&&Ro(m,{children:[Ro(Uo,{classes:"inline",onClick:i,style:c,variant:"primary",children:"Sign up"}),Ro("div",{children:"/"}),Ro(Uo,{classes:"inline",onClick:r,style:c,variant:"primary",children:"Log in"})]})]})]})]})})}),["frameSync","settings","streamer"]);var lv=Ai((function({auth:e,frameSync:t,settings:n,session:r,toastMessenger:o}){const i=Ws(),a=i.hasFetchedProfile(),s=i.profile(),l=i.route(),c=Co((()=>a?function(e){const t=_i(e.userid);if(t&&e.userid){let n=t.username
|
|
620
|
+
;return e.user_info&&e.user_info.display_name&&(n=e.user_info.display_name),{status:"logged-in",displayName:n,userid:e.userid,username:t.username}}return{status:"logged-out"}}(s):{status:"unknown"}),[a,s]),u=Co((()=>Si(["appBackgroundColor"],n)),[n]),h="clean"===n.theme,d="sidebar"===l;xo((()=>{(function(e,t,n){const r="object"==typeof t.preferences&&!!t.preferences.show_sidebar_tutorial,o=P(n)||{onHelpRequestProvided:!1};return e&&!o.onHelpRequestProvided&&r})(d,s,n)&&i.openSidebarPanel("help")}),[d,s,n,i]);const p=async()=>{if(P(n))t.notifyHost("loginRequested");else try{await e.login(),i.closeSidebarPanel("loginPrompt"),i.clearGroups(),r.reload()}catch(e){o.error(e.message)}},m=()=>{P(n)?t.notifyHost("signupRequested"):window.open(i.getLink("signup"))};return Ro("div",{className:uo("h-full min-h-full overflow-scroll","p-[9px] lg:pb-16 bg-grey-2","js-thread-list-scroll-root",{"theme-clean":h,"pt-[49px]":"notebook"!==l,"p-4 lg:p-12":"notebook"===l}),"data-testid":"hypothesis-app",style:u,
|
|
621
|
+
children:["notebook"!==l&&Ro(sv,{auth:c,onLogin:p,onSignUp:m,onLogout:async()=>{await(async()=>{const e=i.countDrafts();if(0===e)return!0;let t="";return 1===e?t="You have an unsaved annotation.\nDo you really want to discard this draft?":e>1&&(t="You have "+e+" unsaved annotations.\nDo you really want to discard these drafts?"),bi({title:"Discard drafts?",message:t,confirmAction:"Discard"})})()&&(i.clearGroups(),i.removeAnnotations(i.unsavedAnnotations()),i.discardAllDrafts(),P(n)?t.notifyHost("logoutRequested"):r.logout())},isSidebar:d}),Ro(Wg,{children:[Ro(Kg,{}),Ro(Og,{auth:"logged-in"===c.status?c:{}}),Ro(Vg,{}),l&&Ro("main",{children:["annotation"===l&&Ro(ig,{onLogin:p}),"notebook"===l&&Ro(Gg,{}),"stream"===l&&Ro(Sg,{}),"sidebar"===l&&Ro(kg,{onLogin:p,onSignUp:m})]})]})]})}),["auth","frameSync","session","settings","toastMessenger"]);function cv({error:e}){return Ro("div",{className:uo("m-2 mt-12"),children:Ro(ui,{title:"Unable to start Hypothesis",children:e.message})})}class uv{constructor(e,t,n){
|
|
622
|
+
this._activity=e,this._api=t,this._store=n}_applyDraftChanges(e){const t={},n=this._store.getDraft(e);return n&&(t.tags=n.tags,t.text=n.text,t.permissions=n.isPrivate?Hl(e.user):ql(e.user,e.group)),{...e,...t}}_initialize(e,t=new Date){const n=this._store.getDefault("annotationPrivacy"),r=this._store.focusedGroupId(),o=this._store.profile();if(!r)throw new Error("Cannot create annotation without a group");const i=o.userid;if(!i)throw new Error("Cannot create annotation when logged out");const a=o.user_info,s="s:"+H(8),l=Object.assign({created:t.toISOString(),group:r,permissions:Ul(i,r,n),tags:[],text:"",updated:t.toISOString(),user:i,user_info:a,$tag:s,hidden:!1,links:{},document:{title:""}},e);return da(l)&&(l.permissions=Hl(i)),l}create(e,t=new Date){const n=this._initialize(e,t);this._store.addAnnotations([n]),this._store.deleteNewAndEmptyDrafts(),da(n)||this._store.createDraft(n,{tags:n.tags,text:n.text,isPrivate:!la(n)}),ma(n)?this._store.selectTab("note"):fa(n)&&this._store.selectTab("annotation"),
|
|
623
|
+
(n.references||[]).forEach((e=>{this._store.setExpanded(e,!0)}))}createPageNote(){const e=this._store.mainFrame();if(!this._store.isLoggedIn())return void this._store.openSidebarPanel("loginPrompt");if(!e)return;const t={target:[],uri:e.uri};this.create(t)}async delete(e){await this._api.annotation.delete({id:e.id}),this._activity.reportActivity("delete",e),this._store.removeAnnotations([e])}async flag(e){await this._api.annotation.flag({id:e.id}),this._activity.reportActivity("flag",e),this._store.updateFlagStatus(e.id,!0)}reply(e,t){const n={group:e.group,permissions:la(e)?ql(t,e.group):Hl(t),references:(e.references||[]).concat(e.id),target:[{source:e.target[0].source}],uri:e.uri};this.create(n)}async save(e){let t,n;const r=this._applyDraftChanges(e);let o;aa(e)?(t=this._api.annotation.update({id:e.id},r),n="update"):(t=this._api.annotation.create({},r),n="create"),this._store.annotationSaveStarted(e);try{o=await t,this._activity.reportActivity(n,o)}finally{this._store.annotationSaveFinished(e)}
|
|
624
|
+
for(let[t,n]of Object.entries(e))if(t.startsWith("$")){o[t]=n}return this._store.removeDraft(e),this._store.addAnnotations([o]),o}}uv.$inject=["annotationActivity","api","store"];class hv{constructor(e){this._rpc=e.rpc,this._reportConfig=e.reportActivity}reportActivity(e,t){if(!this._rpc||!this._reportConfig)return;let n;switch(e){case"create":n=new Date(t.created).toISOString();break;case"update":n=new Date(t.updated).toISOString();break;default:n=(new Date).toISOString()}const r={date:n,annotation:{id:t.id}};this._reportConfig.events.includes(e)&&q(this._rpc.targetFrame,this._rpc.origin,this._reportConfig.method,[e,r],3e3)}}hv.$inject=["settings"];class dv extends Error{constructor(e,t,n=""){let r="Network request failed";t&&(r+=` (${t.status})`),n&&(r+=`: ${n}`),super(r),this.url=e,this.response=t,this.reason=n}}async function pv(e,t){let n,r;try{n=await fetch(e,t)}catch(t){throw new dv(e,null,t.message)}if(204===n.status)return null;try{r=await n.json()}catch(t){
|
|
625
|
+
throw new dv(e,n,"Failed to parse response")}var o;if(!n.ok)throw new dv(e,n,null===(o=r)||void 0===o?void 0:o.reason);return r}function mv(e){const t={};for(let[n,r]of Object.entries(e))n.startsWith("$")||(t[n]=r);return t}function fv(e){return"url"in e}function gv(e,t,{getAccessToken:n,getClientId:r,onRequestStarted:o,onRequestFinished:i}){return async(a,s)=>{o();try{const[o,l]=await Promise.all([e,n()]),c=function(e,t){let n=e;const r=t.split(".");for(let[e,t]of r.entries()){const o=n[t];if(!o||fv(o)){if(o&&e===r.length-1)return o;break}n=o}return null}(o,t);if(!c)throw new Error(`Missing API route: ${t}`);const u={"Content-Type":"application/json","Hypothesis-Client-Version":"1.1045.0"};l&&(u.Authorization="Bearer "+l);const h=r();h&&(u["X-Client-Id"]=h);const{url:d,unusedParams:p}=bs(c.url,a),m=new URL(d);for(let[e,t]of Object.entries(p)){Array.isArray(t)||(t=[t]);for(let n of t)null!=n&&m.searchParams.append(e,n.toString())}return await pv(m.toString(),{body:s?JSON.stringify(mv(s)):null,headers:u,
|
|
626
|
+
method:c.method})}finally{i()}}}class vv{constructor(e,t,n){const r=e.routes();this._clientId=null;const o=()=>this._clientId,i=e=>gv(r,e,{getAccessToken:t.getAccessToken,getClientId:o,onRequestStarted:n.apiRequestStarted,onRequestFinished:n.apiRequestFinished});this.search=i("search"),this.annotation={create:i("annotation.create"),delete:i("annotation.delete"),get:i("annotation.read"),update:i("annotation.update"),flag:i("annotation.flag"),hide:i("annotation.hide"),unhide:i("annotation.unhide")},this.group={member:{delete:i("group.member.delete")},read:i("group.read")},this.groups={list:i("groups.read")},this.profile={groups:{read:i("profile.groups.read")},read:i("profile.read"),update:i("profile.update")}}setClientId(e){this._clientId=e}}vv.$inject=["apiRoutes","auth","store"];var yv={exports:{}},bv={};function _v(e,t){"boolean"==typeof t&&(t={forever:t}),this._originalTimeouts=JSON.parse(JSON.stringify(e)),this._timeouts=e,this._options=t||{},this._maxRetryTime=t&&t.maxRetryTime||1/0,this._fn=null,
|
|
627
|
+
this._errors=[],this._attempts=1,this._operationTimeout=null,this._operationTimeoutCb=null,this._timeout=null,this._operationStart=null,this._timer=null,this._options.forever&&(this._cachedTimeouts=this._timeouts.slice(0))}var wv=_v;_v.prototype.reset=function(){this._attempts=1,this._timeouts=this._originalTimeouts.slice(0)},_v.prototype.stop=function(){this._timeout&&clearTimeout(this._timeout),this._timer&&clearTimeout(this._timer),this._timeouts=[],this._cachedTimeouts=null},_v.prototype.retry=function(e){if(this._timeout&&clearTimeout(this._timeout),!e)return!1;var t=(new Date).getTime();if(e&&t-this._operationStart>=this._maxRetryTime)return this._errors.push(e),this._errors.unshift(new Error("RetryOperation timeout occurred")),!1;this._errors.push(e);var n=this._timeouts.shift();if(void 0===n){if(!this._cachedTimeouts)return!1;this._errors.splice(0,this._errors.length-1),n=this._cachedTimeouts.slice(-1)}var r=this;return this._timer=setTimeout((function(){r._attempts++,
|
|
628
|
+
r._operationTimeoutCb&&(r._timeout=setTimeout((function(){r._operationTimeoutCb(r._attempts)}),r._operationTimeout),r._options.unref&&r._timeout.unref()),r._fn(r._attempts)}),n),this._options.unref&&this._timer.unref(),!0},_v.prototype.attempt=function(e,t){this._fn=e,t&&(t.timeout&&(this._operationTimeout=t.timeout),t.cb&&(this._operationTimeoutCb=t.cb));var n=this;this._operationTimeoutCb&&(this._timeout=setTimeout((function(){n._operationTimeoutCb()}),n._operationTimeout)),this._operationStart=(new Date).getTime(),this._fn(this._attempts)},_v.prototype.try=function(e){console.log("Using RetryOperation.try() is deprecated"),this.attempt(e)},_v.prototype.start=function(e){console.log("Using RetryOperation.start() is deprecated"),this.attempt(e)},_v.prototype.start=_v.prototype.try,_v.prototype.errors=function(){return this._errors},_v.prototype.attempts=function(){return this._attempts},_v.prototype.mainError=function(){if(0===this._errors.length)return null
|
|
629
|
+
;for(var e={},t=null,n=0,r=0;r<this._errors.length;r++){var o=this._errors[r],i=o.message,a=(e[i]||0)+1;e[i]=a,a>=n&&(t=o,n=a)}return t},function(e){var t=wv;e.operation=function(n){var r=e.timeouts(n);return new t(r,{forever:n&&(n.forever||n.retries===1/0),unref:n&&n.unref,maxRetryTime:n&&n.maxRetryTime})},e.timeouts=function(e){if(e instanceof Array)return[].concat(e);var t={retries:10,factor:2,minTimeout:1e3,maxTimeout:1/0,randomize:!1};for(var n in e)t[n]=e[n];if(t.minTimeout>t.maxTimeout)throw new Error("minTimeout is greater than maxTimeout");for(var r=[],o=0;o<t.retries;o++)r.push(this.createTimeout(o,t));return e&&e.forever&&!r.length&&r.push(this.createTimeout(o,t)),r.sort((function(e,t){return e-t})),r},e.createTimeout=function(e,t){var n=t.randomize?Math.random()+1:1,r=Math.round(n*Math.max(t.minTimeout,1)*Math.pow(t.factor,e));return r=Math.min(r,t.maxTimeout)},e.wrap=function(t,n,r){if(n instanceof Array&&(r=n,n=null),!r)for(var o in r=[],t)"function"==typeof t[o]&&r.push(o)
|
|
630
|
+
;for(var i=0;i<r.length;i++){var a=r[i],s=t[a];t[a]=function(r){var o=e.operation(n),i=Array.prototype.slice.call(arguments,1),a=i.pop();i.push((function(e){o.retry(e)||(e&&(arguments[0]=o.mainError()),a.apply(this,arguments))})),o.attempt((function(){r.apply(t,i)}))}.bind(t,s),t[a].options=n}}}(bv);var xv=W(yv.exports=bv);function kv(e,t){return new Promise(((n,r)=>{const o=xv.operation(t);o.attempt((async()=>{try{const t=await e();o.retry(),n(t)}catch(e){o.retry(e)||r(e)}}))}))}function Sv(e){return kv((()=>pv(e)))}class Cv{constructor(e){this._apiURL=e.apiUrl,this._routeCache=null,this._linkCache=null}routes(){return this._routeCache||(this._routeCache=Sv(this._apiURL).then((e=>e.links))),this._routeCache}links(){return this._linkCache||(this._linkCache=this.routes().then((async e=>{const t=e.links;return await Sv(t.url)}))),this._linkCache}}Cv.$inject=["settings"];class Av extends Error{constructor(e,t){super(e),this.cause=t}}class Tv{constructor(e){this.clientId=e.clientId,
|
|
631
|
+
this.tokenEndpoint=e.tokenEndpoint,this.authorizationEndpoint=e.authorizationEndpoint,this.revokeEndpoint=e.revokeEndpoint}exchangeAuthCode(e){return this._getAccessToken({client_id:this.clientId,grant_type:"authorization_code",code:e})}exchangeGrantToken(e){return this._getAccessToken({grant_type:"urn:ietf:params:oauth:grant-type:jwt-bearer",assertion:e})}refreshToken(e){return this._getAccessToken({grant_type:"refresh_token",refresh_token:e})}async revokeToken(e){try{await this._formPost(this.revokeEndpoint,{token:e})}catch(e){throw new Av("Failed to revoke access token",e)}}authorize(e){const t=H(16),n=new Promise(((n,r)=>{e.addEventListener("message",(function o(i){"object"==typeof i.data&&i.data.state===t&&("authorization_response"===i.data.type&&n(i.data),"authorization_canceled"===i.data.type&&r(new Error("Authorization window was closed")),e.removeEventListener("message",o))}))})),r=new URL(this.authorizationEndpoint);r.searchParams.set("client_id",this.clientId),
|
|
632
|
+
r.searchParams.set("origin",e.location.origin),r.searchParams.set("response_mode","web_message"),r.searchParams.set("response_type","code"),r.searchParams.set("state",t);const o=`left=${e.screen.width/2-237.5},top=${e.screen.height/2-215},width=475,height=430`;if(!e.open(r.toString(),"Log in to Hypothesis",o))throw new Error("Failed to open login window");return n.then((e=>e.code))}async _formPost(e,t){const n=new URLSearchParams;for(let[e,r]of Object.entries(t))n.set(e,r);n.sort();return pv(e,{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded"},body:n.toString()})}async _getAccessToken(e){let t;try{t=await this._formPost(this.tokenEndpoint,e)}catch(e){throw new Av("Failed to fetch access token",e)}return{accessToken:t.access_token,expiresAt:Date.now()+1e3*(t.expires_in-10),refreshToken:t.refresh_token}}}class Ev extends Pg{constructor(e,t,n,r,o){let i,a,s;super();const l=(c="token",u=r.apiUrl,new URL(c,u).href);var c,u;function h(){let e=new URL(r.apiUrl).hostname
|
|
633
|
+
;return e=e.replace(/\./g,"%2E"),`hypothesis.oauth.${e}.token`}function d(e){n.setObject(h(),e)}const p=async()=>{if(s)return s;const e=await t.links();return s=new Tv({clientId:r.oauthClientId,authorizationEndpoint:e["oauth.authorize"],revokeEndpoint:e["oauth.revoke"],tokenEndpoint:l}),s},m=()=>{var e;return null===(e=P(r))||void 0===e?void 0:e.grantToken},f=async()=>{if(!a){const e=m();void 0!==e?a=e?p().then((t=>t.exchangeGrantToken(e))).catch((e=>{var t;throw t="You must reload the page to annotate.",o.error(`Hypothesis login lost: ${t}`,{autoDismiss:!1}),e})):Promise.resolve(null):i?(a=(async e=>{const t=await p(),n=await t.exchangeAuthCode(e);return d(n),n})(i),i=null):a=Promise.resolve(function(){const e=n.getObject(h());return e&&"string"==typeof e.accessToken&&"string"==typeof e.refreshToken&&"number"==typeof e.expiresAt?{accessToken:e.accessToken,refreshToken:e.refreshToken,expiresAt:e.expiresAt}:null}())}const e=a,t=await a;if(!t)return null;if(e!==a)return f();if(Date.now()>t.expiresAt){
|
|
634
|
+
const e=m();return a=(async(e,t)=>{const n=await p();let r;try{if(r=await n.refreshToken(e),Date.now()>r.expiresAt)throw new Error("Refreshed token expired in the past")}catch{return null}return t.persist&&d(r),r})(t.refreshToken,{persist:void 0===e}),f()}return t.accessToken};(()=>{e.addEventListener("storage",(({key:e})=>{e===h()&&(a=null,this.emit("oauthTokensChanged"))}))})(),this.login=async function(){const t=await p(),n=await t.authorize(e);i=n,a=null},this.logout=async function(){const[e,t]=await Promise.all([a,p()]);e&&await t.revokeToken(e.accessToken),a=Promise.resolve(null),n.removeItem(h())},this.getAccessToken=f}}Ev.$inject=["$window","apiRoutes","localStorage","settings","toastMessenger"];class Nv{constructor(e,t){this._annotationsService=e,this._store=t,this._saving=new Set,this._failed=new Set}init(){const e=e=>!this._saving.has(e)&&!this._failed.has(e);this._store.subscribe((()=>{this._store.newHighlights().forEach((t=>{const n=t.$tag;e(n)&&(this._saving.add(n),
|
|
635
|
+
kv((()=>this._annotationsService.save(t))).catch((()=>{this._failed.add(n)})).finally((()=>{this._saving.delete(n)})))}))}))}isSaving(){return this._saving.size>0}}function Mv(e,t,n){const r=Array.isArray(t),o=()=>r?t.map((e=>e())):t();let i=o();return e((()=>{const e=o();if(r?rs(e,i):e===i)return;const t=i;i=e,n(e,t)}))}Nv.$inject=["annotationsService","store"];class Lv{constructor(e,t){this._frameSync=e,this._store=t}init(){const e=()=>this._store.profile().features;Mv(this._store.subscribe,[e,()=>this._store.frames()],(()=>{this._frameSync.notifyHost("featureFlagsUpdated",e()||{})}))}}function zv(e,t){return!!function(e){if(null===e||"object"!=typeof e)return!1;for(let t of["frame1","frame2","type","requestId"])if("string"!=typeof e[t])return!1;return!0}(e)&&JSON.stringify(e,Object.keys(t).sort())===JSON.stringify(t,Object.keys(t).sort())}Lv.$inject=["frameSync","store"];class Ov{constructor({hostFrame:e,source:t}){this._hostFrame=e,this._source=t,this._listeners=new Dl}destroy(){
|
|
636
|
+
this._listeners.removeAll()}async discover(e){let t=!1;if(("guest"===this._source&&"host"===e||"guest"===this._source&&"sidebar"===e||"sidebar"===this._source&&"host"===e||"notebook"===this._source&&"sidebar"===e)&&(t=!0),!t)throw new Error("Invalid request of channel/port");const n=H(6);return new Promise(((t,r)=>{const o=()=>{this._hostFrame.postMessage({frame1:this._source,frame2:e,type:"request",requestId:n},"*")},i=setInterval(o,250),a=setTimeout((()=>{clearInterval(i),r(new Error(`Unable to establish ${this._source}-${e} communication channel`))}),2e4),s=this._listeners.add(window,"message",(r=>{const{data:o,ports:l}=r;zv(o,{frame1:this._source,frame2:e,type:"offer",requestId:n})&&(clearInterval(i),clearTimeout(a),this._listeners.remove(s),t(l[0]))}));o()}))}}function Iv(e,t,n=[],r=-1){e.postMessage({protocol:"frame-rpc",version:"1.0.0",arguments:n,method:t,sequence:r})}class Rv{constructor({userAgent:e=navigator.userAgent,currentWindow:t=window}={}){this._port=null,this._methods=new Map,
|
|
637
|
+
this._sequence=1,this._callbacks=new Map,this._listeners=new Dl,this._listeners.add(t,"unload",(()=>{this._port&&(Iv(this._port,"close"),t!==t.parent&&function(e){const t=e.match(/\bAppleWebKit\/([0-9]+)\b/);return!!t&&!(parseInt(t[1])<=537)}(e)&&t.parent.postMessage({type:"hypothesisPortClosed"},"*",[this._port]))})),this._pendingCalls=[],this._receivedCloseEvent=!1}on(e,t){if(this._port)throw new Error("Cannot add a method handler after a port is connected");this._methods.set(e,t)}connect(e){this._port=e,this._listeners.add(e,"message",(e=>this._handle(e))),e.start(),Iv(e,"connect");for(let[e,t]of this._pendingCalls)this.call(e,...t);this._pendingCalls=[]}destroy(){this._port&&(Iv(this._port,"close"),this._port.close()),this._destroyed=!0,this._listeners.removeAll()}call(e,...t){if(this._port||this._pendingCalls.push([e,t]),!this._port||this._destroyed)return;const n=this._sequence++,r=t[t.length-1];"function"==typeof r&&(this._callbacks.set(n,r),t=t.slice(0,-1)),Iv(this._port,e,t,n)}
|
|
638
|
+
_parseMessage({data:e}){return e&&"object"==typeof e?"frame-rpc"!==e.protocol||"1.0.0"!==e.version?null:Array.isArray(e.arguments)?e:null:null}_handle(e){const t=this._parseMessage(e),n=this._port;if(t&&n)if("method"in t){if("close"===t.method){if(this._receivedCloseEvent)return;this._receivedCloseEvent=!0}const e=this._methods.get(t.method);if(!e)return;const r=(...e)=>{const r={arguments:e,protocol:"frame-rpc",response:t.sequence,version:"1.0.0"};n.postMessage(r)};e(...t.arguments,r)}else if("response"in t){const e=this._callbacks.get(t.response);this._callbacks.delete(t.response),e&&e(...t.arguments)}}}function Pv({$tag:e,target:t,uri:n}){return{$tag:e,target:t,uri:n}}function Dv(e,t){const n=e.find((e=>e.uri===t.uri));if(n)return n;const r=e.find((e=>null===e.id));return r||e[0]}class Bv{constructor(e,t,n){this._window=e,this._annotationsService=t,this._store=n,this._portFinder=new Ov({hostFrame:this._window.parent,source:"sidebar"}),this._listeners=new Dl,this._hostRPC=new Rv,this._guestRPC=new Map,
|
|
639
|
+
this._nextGuestId=0,this._inFrame=new Set,this._highlightsVisible=!1,this._setupSyncToGuests(),this._setupHostEvents()}_setupSyncToGuests(){let e=0;Mv(this._store.subscribe,[()=>this._store.allAnnotations(),()=>this._store.frames()],(([t,n],[r])=>{let o=0;const i=new Set,a=[];t.forEach((e=>{ia(e)||(la(e)&&++o,i.add(e.$tag),this._inFrame.has(e.$tag)||a.push(e))}));const s=r.filter((e=>!i.has(e.$tag)));if(a.length>0){const e=new Map;for(let t of a){var l;const r=Dv(n,t);if(!r)continue;const o=null!==(l=e.get(r.id))&&void 0!==l?l:[];o.push(t),e.set(r.id,o)}for(let[t,n]of e){const e=this._guestRPC.get(t);e&&e.call("loadAnnotations",n.map(Pv))}a.forEach((e=>{this._inFrame.add(e.$tag)}))}s.forEach((e=>{this._guestRPC.forEach((t=>t.call("deleteAnnotation",e.$tag))),this._inFrame.delete(e.$tag)})),n.length>0&&n.every((e=>e.isAnnotationFetchComplete))&&(0!==o&&o===e||(this._hostRPC.call("publicAnnotationCountChanged",o),e=o))}))}_connectGuest(e){const t=new Rv;++this._nextGuestId;let n=`temp-${this._nextGuestId}`
|
|
640
|
+
;this._guestRPC.set(n,t),t.on("documentInfoChanged",(e=>{this._guestRPC.delete(n),n=e.frameIdentifier,this._guestRPC.set(n,t),this._store.connectFrame({id:e.frameIdentifier,metadata:e.metadata,uri:e.uri})})),t.on("close",(()=>{const e=this._store.frames().find((e=>e.id===n));e&&this._store.destroyFrame(e),t.destroy(),this._guestRPC.delete(n)})),t.on("createAnnotation",(e=>{if(!this._store.isLoggedIn())return this._hostRPC.call("openSidebar"),this._store.openSidebarPanel("loginPrompt"),void this._guestRPC.forEach((t=>t.call("deleteAnnotation",e.$tag)));this._inFrame.add(e.$tag),e.$highlight||this._hostRPC.call("openSidebar"),this._hostRPC.call("showHighlights"),this._annotationsService.create(e)}));let r={};const o=Pl((()=>{this._store.updateAnchorStatus(r),r={}}),10);t.on("syncAnchoringStatus",(({$tag:e,$orphan:t})=>{this._inFrame.add(e),r[e]=t?"orphan":"anchored",o()})),t.on("showAnnotations",(e=>{this._store.selectAnnotations(this._store.findIDsForTags(e)),this._store.selectTab("annotation")})),
|
|
641
|
+
t.on("focusAnnotations",(e=>{this._store.focusAnnotations(e||[])})),t.on("toggleAnnotationSelection",(e=>{this._store.toggleSelectedAnnotations(this._store.findIDsForTags(e))})),t.on("openSidebar",(()=>{this._hostRPC.call("openSidebar")})),t.on("closeSidebar",(()=>{this._hostRPC.call("closeSidebar")})),t.connect(e),t.call("setHighlightsVisible",this._highlightsVisible)}_setupHostEvents(){this._hostRPC.on("sidebarOpened",(()=>{this._store.setSidebarOpened(!0)})),this._hostRPC.on("setHighlightsVisible",(e=>{this._highlightsVisible=e,this._guestRPC.forEach((t=>t.call("setHighlightsVisible",e)))}))}async connect(){const e=await this._portFinder.discover("host");this._hostRPC.connect(e),this._listeners.add(e,"message",(e=>{const{data:t,ports:n}=e;zv(t,{frame1:"guest",frame2:"sidebar",type:"offer"})&&this._connectGuest(n[0])}))}notifyHost(e,...t){this._hostRPC.call(e,...t)}focusAnnotations(e){this._store.focusAnnotations(e),this._guestRPC.forEach((t=>t.call("focusAnnotations",e)))}scrollToAnnotation(e){
|
|
642
|
+
this._guestRPC.forEach((t=>t.call("scrollToAnnotation",e)))}destroy(){this._portFinder.destroy(),this._listeners.removeAll()}}Bv.$inject=["$window","annotationsService","store"];const Fv={id:"__default__",name:"__DEFAULT__",logo:"data:image/svg+xml;utf8,"+encodeURIComponent(vi)};const jv=["organization","scopes"];class Hv{constructor(e,t,n,r,o,i){this._store=e,this._api=t,this._auth=n,this._settings=o,this._toastMessenger=i,this._serviceConfig=P(o),this._reloadSetUp=!1}_mainURI(){var e,t;return null!==(e=null===(t=this._store.mainFrame())||void 0===t?void 0:t.uri)&&void 0!==e?e:null}async _filterGroups(e,t,n,r){if(r){const t=e.find((e=>e.id===r));t&&!t.isScopedToUri&&t.scopes&&t.scopes.enforced&&(e=e.filter((e=>e.id!==r)),this._store.setDirectLinkedGroupFetchFailed(),r=null)}if(t)return e;const o=e.some((e=>"__world__"!==e.id&&e.isScopedToUri));return o?"__world__"===r||"__world__"===n?e:e.filter((e=>"__world__"!==e.id)):e}_setupAutoReload(){this._reloadSetUp||(this._reloadSetUp=!0,
|
|
643
|
+
Mv(this._store.subscribe,(()=>this._mainURI()),(()=>{this.load()})),Mv(this._store.subscribe,[()=>this._store.hasFetchedProfile(),()=>this._store.profile().userid],((e,[t])=>{t&&this.load()})))}_addGroupsToStore(e,t){!function(e){e.forEach((e=>{e.organization&&"object"==typeof e.organization||(e.organization=Fv)}))}(e);const n=0===this._store.allGroups().length,r=this._store.getDefault("focusedGroup");this._store.loadGroups(e),n&&(t&&e.some((e=>e.id===t))?this.focus(t):r&&e.some((e=>e.id===r))&&this.focus(r))}_fetchGroup(e){return this._api.group.read({id:e,expand:jv})}async _loadGroupsForUserAndDocument(){var e;const t=()=>function(e,t){const n=t(e);return null!==n?Promise.resolve(n):new Promise((n=>{const r=e.subscribe((()=>{const o=t(e);null!==o&&(r(),n(o))}))}))}(this._store,(()=>this._mainURI()));let n=null;"sidebar"===this._store.route()&&(n=await t()),this._setupAutoReload();const r=this._store.directLinkedAnnotationId();let o=null;r&&(o=this._api.annotation.get({id:r}).catch((()=>null)))
|
|
644
|
+
;const i=this._store.directLinkedGroupId();let a=null;i&&(a=this._fetchGroup(i).then((e=>(this._store.clearDirectLinkedGroupFetchFailed(),e))).catch((()=>(this._store.setDirectLinkedGroupFetchFailed(),null))));const s={expand:jv},l=null===(e=this._serviceConfig)||void 0===e?void 0:e.authority;l&&(s.authority=l),n&&(s.document_uri=n);const[c,u,h,d,p]=await Promise.all([this._api.profile.groups.read({expand:jv}),this._api.groups.list(s),this._auth.getAccessToken(),o,a]);p&&!u.some((e=>e.id===p.id))&&u.push(p);let m=null;if(d){m=d.group;const e=c.concat(u).find((e=>e.id===d.group));if(!e)try{const e=await this._fetchGroup(d.group);u.push(e)}catch(e){this._toastMessenger.error("Unable to fetch group for linked annotation")}}const f=null!==h,g=await this._filterGroups(K(c,u,n,this._settings),f,m,i),v=m||i||null;return this._addGroupsToStore(g,v),g}async _loadServiceSpecifiedGroups(e){const t=await this._api.profile.groups.read({expand:jv});let n;const r=async e=>{try{return await this._fetchGroup(e)}catch(e){
|
|
645
645
|
return n=e,null}},o=await Promise.all(e.map((e=>t.find((t=>t.id===e||t.groupid===e))||r(e)))),i=o.filter((e=>null!==e)),a=this._store.directLinkedGroupId();return this._addGroupsToStore(i,a),n&&this._toastMessenger.error(`Unable to fetch groups: ${n.message}`,{autoDismiss:!1}),i}async load(){var e;const t=null===(e=this._serviceConfig)||void 0===e?void 0:e.groups;if(Array.isArray(t)||"function"==typeof(null==(n=t)?void 0:n.then)){let e=[];try{e=await t}catch(e){this._toastMessenger.error(`Unable to fetch group configuration: ${e.message}`)}return this._loadServiceSpecifiedGroups(e)}return this._loadGroupsForUserAndDocument();var n}focus(e){const t=this._store.focusedGroupId();this._store.focusGroup(e);const n=this._store.focusedGroupId();if(t!==n&&null!==t&&n){const e=this._store.newAnnotations().filter((e=>!ia(e))).map((e=>({...e,group:n})));e.length&&this._store.addAnnotations(e),this._store.setDefault("focusedGroup",n)}}leave(e){return this._api.group.member.delete({pubid:e,userid:"me"})}}
|
|
646
|
-
|
|
647
|
-
this._searchClient.on("error",(e=>{"function"==typeof n?n(e):console.error(e)})),this._searchClient.on("end",(()=>{this._searchClient=null,t&&t.length>0&&this._store.frames().forEach((e=>{t.indexOf(e.uri)>=0&&this._store.updateFrameAnnotationFetchStatus(e.uri,!0)})),this._store.annotationFetchFinished()})),this._store.annotationFetchStarted(),this._searchClient.get({group:e,uri:t})}async loadThread(e){let t,n;this._store.clearAnnotations();try{this._store.annotationFetchStarted(),t=await this._api.annotation.get({id:e}),ia(t)&&(t=await this._api.annotation.get({id:t.references[0]})),n=await this._api.search({references:t.id})}finally{this._store.annotationFetchFinished()}const r=[t,...n.rows];if(this._store.addAnnotations(r),!ia(t)){const e=t.id;this._streamFilter.addClause("/references","one_of",e,!0).addClause("/id","equals",e,!0),this._streamer.setConfig("filter",{filter:this._streamFilter.getFilter()}),this._streamer.connect()}return r}}
|
|
648
|
-
constructor(){this._store=new Map}getItem(e){var t;return null!==(t=this._store.get(e))&&void 0!==t?t:null}setItem(e,t){this._store.set(e,t)}removeItem(e){this._store.delete(e)}}class
|
|
649
|
-
for(let[n,r]of wa(e))t[n]!==r&&n in
|
|
650
|
-
this._didRegisterPopstateListener||(this._window.addEventListener("popstate",(()=>{this.sync()})),this._didRegisterPopstateListener=!0)}navigate(e,t){this._window.history.pushState({},"",this.routeUrl(e,t)),this.sync()}}
|
|
651
|
-
})).then((e=>(this.update(e),this._lastLoadTime=Date.now(),e))).catch((e=>{throw this._lastLoadTime=null,e}))),this._lastLoad}async dismissSidebarTutorial(){const e=await this._api.profile.update({},{preferences:{show_sidebar_tutorial:!1}});this.update(e)}update(e){const t=this._store.profile(),n=e.userid!==t.userid;return this._store.updateProfile(e),this._lastLoad=Promise.resolve(e),this._lastLoadTime=Date.now(),n&&(e.userid?Wr({id:e.userid}):Wr(null)),e}async logout(){try{return await this._auth.logout(),this.reload()}catch(e){throw this._toastMessenger.error("Log out failed"),new Error(e)}}reload(){return this._lastLoad=null,this._lastLoadTime=null,this.load()}}
|
|
652
|
-
return this._filter={match_policy:"include_any",clauses:[],actions:{create:!0,update:!0,delete:!0}},this}}class
|
|
646
|
+
Hv.$inject=["store","api","auth","session","settings","toastMessenger"];class qv{constructor(e,t,n,r){this._api=e,this._store=t,this._streamer=n,this._streamFilter=r,this._searchClient=null}load({groupId:e,uris:t,onError:n,maxResults:r,sortBy:o,sortOrder:i,streamFilterBy:a="uri"}){if(this._store.removeAnnotations(this._store.savedAnnotations()),this._searchClient&&this._searchClient.cancel(),"group"===a)this._streamFilter.resetFilter().addClause("/group","equals",e,!0),this._streamer.setConfig("filter",{filter:this._streamFilter.getFilter()});else t&&t.length>0&&(this._streamFilter.resetFilter().addClause("/uri","one_of",t),this._streamer.setConfig("filter",{filter:this._streamFilter.getFilter()}));const s={incremental:!0,separateReplies:!1,maxResults:r,sortBy:o,sortOrder:i};this._searchClient=new Fg(this._api.search,s),this._searchClient.on("resultCount",(e=>{this._store.setAnnotationResultCount(e)})),this._searchClient.on("results",(e=>{e.length&&this._store.addAnnotations(e)})),
|
|
647
|
+
this._searchClient.on("error",(e=>{"function"==typeof n?n(e):console.error(e)})),this._searchClient.on("end",(()=>{this._searchClient=null,t&&t.length>0&&this._store.frames().forEach((e=>{t.indexOf(e.uri)>=0&&this._store.updateFrameAnnotationFetchStatus(e.uri,!0)})),this._store.annotationFetchFinished()})),this._store.annotationFetchStarted(),this._searchClient.get({group:e,uri:t})}async loadThread(e){let t,n;this._store.clearAnnotations();try{this._store.annotationFetchStarted(),t=await this._api.annotation.get({id:e}),ia(t)&&(t=await this._api.annotation.get({id:t.references[0]})),n=await this._api.search({references:t.id})}finally{this._store.annotationFetchFinished()}const r=[t,...n.rows];if(this._store.addAnnotations(r),!ia(t)){const e=t.id;this._streamFilter.addClause("/references","one_of",e,!0).addClause("/id","equals",e,!0),this._streamer.setConfig("filter",{filter:this._streamFilter.getFilter()}),this._streamer.connect()}return r}}qv.$inject=["api","store","streamer","streamFilter"];class Uv{
|
|
648
|
+
constructor(){this._store=new Map}getItem(e){var t;return null!==(t=this._store.get(e))&&void 0!==t?t:null}setItem(e,t){this._store.set(e,t)}removeItem(e){this._store.delete(e)}}class $v{constructor(e){let t="hypothesis.testKey";try{this._storage=e.localStorage,e.localStorage.setItem(t,t),e.localStorage.getItem(t),e.localStorage.removeItem(t)}catch(e){this._storage=new Uv}}getItem(e){return this._storage.getItem(e)}getObject(e){const t=this._storage.getItem(e);return t?JSON.parse(t):null}setItem(e,t){this._storage.setItem(e,t)}setObject(e,t){const n=JSON.stringify(t);this._storage.setItem(e,n)}removeItem(e){this._storage.removeItem(e)}}$v.$inject=["$window"];const Gv={annotationPrivacy:"hypothesis.privacy",focusedGroup:"hypothesis.groups.focus"};class Vv{constructor(e,t){this._storage=e,this._store=t}init(){for(let[e,t]of wa(Gv)){const n=this._storage.getItem(t);this._store.setDefault(e,n)}Mv(this._store.subscribe,(()=>this._store.getDefaults()),((e,t)=>{
|
|
649
|
+
for(let[n,r]of wa(e))t[n]!==r&&n in Gv&&this._storage.setItem(Gv[n],r)}))}}Vv.$inject=["localStorage","store"];class Wv{constructor(e,t){this._window=e,this._store=t,this._didRegisterPopstateListener=!1}currentRoute(){const e=this._window.location.pathname.slice(1).split("/"),t=new URLSearchParams(this._window.location.search),n={};for(let[e,r]of t)n[e]=r;"client"===e[0]&&e.shift();let r;switch(e[0].replace(/\.html$/,"")){case"a":r="annotation",n.id=e[1]||"";break;case"notebook":r="notebook";break;case"stream":r="stream";break;default:r="sidebar"}return{route:r,params:n}}routeUrl(e,t={}){let n;const r={...t};switch(e){case"annotation":{const e=t.id;delete r.id,n=`/a/${e}`}break;case"notebook":n="/notebook";break;case"stream":n="/stream";break;default:throw new Error(`Cannot generate URL for route "${e}"`)}let o=!1;const i=new URLSearchParams;for(let[e,t]of Object.entries(r))o=!0,i.set(e,t);return o&&(n+="?"+i.toString()),n}sync(){const{route:e,params:t}=this.currentRoute();this._store.changeRoute(e,t),
|
|
650
|
+
this._didRegisterPopstateListener||(this._window.addEventListener("popstate",(()=>{this.sync()})),this._didRegisterPopstateListener=!0)}navigate(e,t){this._window.history.pushState({},"",this.routeUrl(e,t)),this.sync()}}Wv.$inject=["$window","store"];class Yv{constructor(e,t){this._apiRoutes=e,this._store=t}async init(){try{const e=await this._apiRoutes.links();this._store.updateLinks(e)}catch(e){console.warn(`Failed to fetch Hypothesis links: ${e.message}`)}}}Yv.$inject=["apiRoutes","store"];class Kv{constructor(e,t,n,r,o){var i,a;this._api=t,this._auth=n,this._store=e,this._toastMessenger=o,this._authority=null!==(i=null===(a=P(r))||void 0===a?void 0:a.authority)&&void 0!==i?i:null,this._lastLoad=null,this._lastLoadTime=null,n.on("oauthTokensChanged",(()=>this.reload()))}load(){return(!this._lastLoad||!this._lastLoadTime||Date.now()-this._lastLoadTime>3e5)&&(this._lastLoadTime=Date.now(),this._lastLoad=kv((()=>{const e=this._authority?{authority:this._authority}:{};return this._api.profile.read(e)
|
|
651
|
+
})).then((e=>(this.update(e),this._lastLoadTime=Date.now(),e))).catch((e=>{throw this._lastLoadTime=null,e}))),this._lastLoad}async dismissSidebarTutorial(){const e=await this._api.profile.update({},{preferences:{show_sidebar_tutorial:!1}});this.update(e)}update(e){const t=this._store.profile(),n=e.userid!==t.userid;return this._store.updateProfile(e),this._lastLoad=Promise.resolve(e),this._lastLoadTime=Date.now(),n&&(e.userid?Wr({id:e.userid}):Wr(null)),e}async logout(){try{return await this._auth.logout(),this.reload()}catch(e){throw this._toastMessenger.error("Log out failed"),new Error(e)}}reload(){return this._lastLoad=null,this._lastLoadTime=null,this.load()}}Kv.$inject=["store","api","auth","settings","toastMessenger"];class Xv{constructor(){this._filter={match_policy:"include_any",clauses:[],actions:{create:!0,update:!0,delete:!0}}}addClause(e,t,n,r=!1){return this._filter.clauses.push({field:e,operator:t,value:n,case_sensitive:r}),this}getFilter(){return this._filter}resetFilter(){
|
|
652
|
+
return this._filter={match_policy:"include_any",clauses:[],actions:{create:!0,update:!0,delete:!0}},this}}class Zv extends Pg{constructor(e){super();const t=[];let n;const r=()=>{for(;t.length>0;){const e=JSON.stringify(t.shift());n.send(e)}};this.close=()=>{n.close(1e3)},this.send=e=>{t.push(e),this.isConnected()&&r()},this.isConnected=()=>n.readyState===WebSocket.OPEN,(()=>{n=new WebSocket(e),n.onopen=e=>{r(),this.emit("open",e)},n.onclose=e=>{if(1e3===e.code||1001===e.code)return void this.emit("close",e);const t=new Error(`WebSocket closed abnormally, code: ${e.code}`);console.warn(t),this.emit("disconnect")},n.onerror=e=>{this.emit("error",e)},n.onmessage=e=>{this.emit("message",e)}})()}}class Jv{constructor(e,t,n,r,o){this._auth=n,this._groups=r,this._session=o,this._store=e,this._websocketURL=t.links().then((e=>e.websocket)),this.clientId=H(32),this._socket=null,this._updateImmediately=!0,this._configMessages={},this._reconnectionAttempts=0,this._reconnectSetUp=!1}applyPendingUpdates(){
|
|
653
653
|
const e=Object.values(this._store.pendingUpdates());e.length&&this._store.addAnnotations(e);const t=Object.keys(this._store.pendingDeletions()).map((e=>({id:e})));t.length&&this._store.removeAnnotations(t),this._store.clearPendingUpdates()}_handleSocketError(e,t){G("Error connecting to H push notification service:",t);const n=new URL(e).hostname;-1!==["localhost","127.0.0.1"].indexOf(n)&&G("Check that your H service is configured to allow WebSocket connections from "+window.location.origin)}_handleSocketMessage(e){const t=JSON.parse(e.data);if(t)if("annotation-notification"===t.type){const e=t.payload;switch(t.options.action){case"create":case"update":case"past":this._store.receiveRealTimeUpdates({updatedAnnotations:e});break;case"delete":this._store.receiveRealTimeUpdates({deletedAnnotations:e})}this._updateImmediately&&this.applyPendingUpdates()}else if("session-change"===t.type)this._session.update(t.model),this._groups.load();else if("whoyouare"===t.type){const e=this._store.profile().userid
|
|
654
|
-
;t.userid!==e&&console.warn('WebSocket user ID "%s" does not match logged-in ID "%s"',t.userid,e)}else G("Received unsupported notification",t.type)}_sendClientConfig(e){Object.keys(this._configMessages).forEach((t=>{this._configMessages[t]&&e.send(this._configMessages[t])}))}setConfig(e,t){var n;this._configMessages[e]=t,null!==(n=this._socket)&&void 0!==n&&n.isConnected()&&this._socket.send(t)}async _reconnect(){var e;const t=await this._websocketURL;if(!t)return;let n,r;null===(e=this._socket)||void 0===e||e.close();try{n=await this._auth.getAccessToken()}catch(e){throw console.error("Failed to fetch token for WebSocket authentication",e),e}if(n){const e=new URL(t);e.searchParams.set("access_token",n),r=e.toString()}else r=t;const o=new
|
|
655
|
-
}else console.error("Gave up trying to reconnect to Hypothesis real time update service")})),o.on("error",(e=>this._handleSocketError(t,e))),o.on("message",(e=>this._handleSocketMessage(e))),this._socket=o,this.setConfig("client-id",{messageType:"client_id",value:this.clientId}),this.setConfig("auth-check",{type:"whoami",id:1})}async connect(e={}){var t;this._updateImmediately=null===(t=e.applyUpdatesImmediately)||void 0===t||t,this._reconnectSetUp||(this._reconnectSetUp=!0,
|
|
656
|
-
const t=this._storage.getObject("hypothesis.user.tags.map")||{};e.forEach((e=>{t[e]?(t[e].count+=1,t[e].updated=Date.now()):t[e]={text:e,count:1,updated:Date.now()}})),this._storage.setObject("hypothesis.user.tags.map",t);const n=Object.keys(t).sort(((e,n)=>t[e].count!==t[n].count?t[n].count-t[e].count:e.localeCompare(n)));this._storage.setObject("hypothesis.user.tags.list",n)}}
|
|
657
|
-
n&&setTimeout((()=>{this.dismiss(o)}),5e3)}error(e,t){this._addMessage("error",e,t)}success(e,t){this._addMessage("success",e,t)}notice(e,t){this._addMessage("notice",e,t)}}
|
|
658
|
-
if("function"==typeof t)t={class:t};else if(!function(e){return"object"==typeof e&&null!==e&&("value"in e||"function"==typeof e.class||"function"==typeof e.factory)}(t))throw new Error(`Invalid provider for "${e}"`);return this._providers.set(e,t),this}run(e){const t="Injector.run";this.register(t,{factory:e});try{return this.get(t)}finally{this._instances.delete(t),this._providers.delete(t)}}}const
|
|
659
|
-
!1):e.origin===n||(console.warn(`The Hypothesis sidebar is running in a different origin (${e.origin}) than expected (${n}). It may not work.`),!1)}(window);function
|
|
660
|
-
Qt("loaded_scripts",Array.from(document.querySelectorAll("script")).filter((e=>!e.type||e.type.match(/javascript|module/))).map((e=>e.src||"<inline>"))),Gr(((e,t)=>{Jt(e,{tags:{context:t}})}))}(
|
|
654
|
+
;t.userid!==e&&console.warn('WebSocket user ID "%s" does not match logged-in ID "%s"',t.userid,e)}else G("Received unsupported notification",t.type)}_sendClientConfig(e){Object.keys(this._configMessages).forEach((t=>{this._configMessages[t]&&e.send(this._configMessages[t])}))}setConfig(e,t){var n;this._configMessages[e]=t,null!==(n=this._socket)&&void 0!==n&&n.isConnected()&&this._socket.send(t)}async _reconnect(){var e;const t=await this._websocketURL;if(!t)return;let n,r;null===(e=this._socket)||void 0===e||e.close();try{n=await this._auth.getAccessToken()}catch(e){throw console.error("Failed to fetch token for WebSocket authentication",e),e}if(n){const e=new URL(t);e.searchParams.set("access_token",n),r=e.toString()}else r=t;const o=new Zv(r);o.on("open",(()=>{this._reconnectionAttempts=0,this._sendClientConfig(o)})),o.on("disconnect",(()=>{if(++this._reconnectionAttempts,this._reconnectionAttempts<10){const e=1e3*2**this._reconnectionAttempts;setTimeout((()=>this._reconnect()),e)
|
|
655
|
+
}else console.error("Gave up trying to reconnect to Hypothesis real time update service")})),o.on("error",(e=>this._handleSocketError(t,e))),o.on("message",(e=>this._handleSocketMessage(e))),this._socket=o,this.setConfig("client-id",{messageType:"client_id",value:this.clientId}),this.setConfig("auth-check",{type:"whoami",id:1})}async connect(e={}){var t;this._updateImmediately=null===(t=e.applyUpdatesImmediately)||void 0===t||t,this._reconnectSetUp||(this._reconnectSetUp=!0,Mv(this._store.subscribe,(()=>this._store.profile().userid),(()=>{this._reconnect()}))),this._socket||await this._reconnect()}}Jv.$inject=["store","apiRoutes","auth","groups","session"];class Qv{constructor(e){this._storage=e}filter(e,t=null){const n=this._storage.getObject("hypothesis.user.tags.list")||[];let r=0;return n.filter((n=>{if(null!==t&&r>=t)return!1;const o=n.split(/\W+/),i=new RegExp(`^${Y(e)}`,"i");return!(!o.some((e=>e.match(i)))&&!n.match(i))&&(++r,!0)}))}store(e){
|
|
656
|
+
const t=this._storage.getObject("hypothesis.user.tags.map")||{};e.forEach((e=>{t[e]?(t[e].count+=1,t[e].updated=Date.now()):t[e]={text:e,count:1,updated:Date.now()}})),this._storage.setObject("hypothesis.user.tags.map",t);const n=Object.keys(t).sort(((e,n)=>t[e].count!==t[n].count?t[n].count-t[e].count:e.localeCompare(n)));this._storage.setObject("hypothesis.user.tags.list",n)}}Qv.$inject=["localStorage"];class ey{constructor(e){this._store=e}forceVisible(e){e.children.forEach((e=>{this.forceVisible(e)})),e.visible||this._store.setForcedVisible(e.id,!0)}}ey.$inject=["store"];class ty{constructor(e){this._store=e}dismiss(e){const t=this._store.getToastMessage(e);t&&!t.isDismissed&&(this._store.updateToastMessage({...t,isDismissed:!0}),setTimeout((()=>{this._store.removeToastMessage(e)}),500))}_addMessage(e,t,{autoDismiss:n=!0,moreInfoURL:r=""}={}){if(this._store.hasToastMessage(e,t))return;const o=H(10),i={type:e,id:o,message:t,moreInfoURL:r};this._store.addToastMessage({isDismissed:!1,...i}),
|
|
657
|
+
n&&setTimeout((()=>{this.dismiss(o)}),5e3)}error(e,t){this._addMessage("error",e,t)}success(e,t){this._addMessage("success",e,t)}notice(e,t){this._addMessage("notice",e,t)}}ty.$inject=["store"];class ny{constructor(){this._providers=new Map,this._instances=new Map,this._constructing=new Set}get(e){if(this._instances.has(e))return this._instances.get(e);const t=this._providers.get(e);if(!t)throw new Error(`"${e}" is not registered`);if("value"in t)return this._instances.set(e,t.value),t.value;if(this._constructing.has(e))throw new Error(`Encountered a circular dependency when constructing "${e}"`);this._constructing.add(e);try{const n=[],r="class"in t&&t.class.$inject||"factory"in t&&t.factory.$inject||[];for(const t of r)try{n.push(this.get(t))}catch(n){const r=new Error(`Failed to construct dependency "${t}" of "${e}": ${n.message}`);throw r.cause=n,r}let o;if(t.class)o=new t.class(...n);else{o=(0,t.factory)(...n)}return this._instances.set(e,o),o}finally{this._constructing.delete(e)}}register(e,t){
|
|
658
|
+
if("function"==typeof t)t={class:t};else if(!function(e){return"object"==typeof e&&null!==e&&("value"in e||"function"==typeof e.class||"function"==typeof e.factory)}(t))throw new Error(`Invalid provider for "${e}"`);return this._providers.set(e,t),this}run(e){const t="Injector.run";this.register(t,{factory:e});try{return this.get(t)}finally{this._instances.delete(t),this._providers.delete(t)}}}const ry=function(t){for(var n={},r=t.querySelectorAll("script.js-hypothesis-config"),o=0;o<r.length;o++){var i=void 0;try{i=JSON.parse(r[o].textContent||"")}catch(e){console.warn("Could not parse settings from js-hypothesis-config tags",e),i={}}e(n,i)}return n}(document),oy=function(e){const{version:t,origin:n}=R(e.location.href);return"1.1045.0"!==t?(console.warn(`The Hypothesis sidebar is using a different version (1.1045.0) than the host page (${t}). It may not work.`),!1):"null"===e.origin?(console.warn("Hypothesis has been loaded in a sandboxed frame. This is not supported."),
|
|
659
|
+
!1):e.origin===n||(console.warn(`The Hypothesis sidebar is running in a different origin (${e.origin}) than expected (${n}). It may not work.`),!1)}(window);function iy(e,t){e.setClientId(t.clientId)}function ay(e,t,n){e.load(),t.load(),n.sync()}function sy(e,t,n,r){e.init(),t.init(),n.init(),r.init()}function ly(e,t){"sidebar"===t.route()&&e.connect()}ry.sentry&&oy&&function(e){const t=function(){let e=import.meta.url;return e?new URL(e).origin:null}(),n=t?[t]:void 0;Hr({dsn:e.dsn,environment:e.environment,allowUrls:n,ignoreErrors:["Network request failed","Object Not Found Matching Id"],release:"1.1045.0",beforeSend:(e,t)=>{if(Vr>=5)return G("Client-side Sentry quota reached. No further Sentry events will be sent"),null;++Vr;try{const n=t&&t.originalException;n instanceof Event&&Object.assign(e.extra,{type:n.type,detail:n.detail,isTrusted:n.isTrusted})}catch(e){}return e}});try{Qt("host_config",R(window.location.href))}catch(e){}
|
|
660
|
+
Qt("loaded_scripts",Array.from(document.querySelectorAll("script")).filter((e=>!e.type||e.type.match(/javascript|module/))).map((e=>e.src||"<inline>"))),Gr(((e,t)=>{Jt(e,{tags:{context:t}})}))}(ry.sentry),function(e){e.addEventListener("click",(e=>{const t=e.target;if("A"===t.tagName){const e=t;"_blank"===e.target&&(e.rel="noopener")}}))}(document.body),function(e=n){let t=!1;try{document.createElement("div").dir="auto"}catch(e){t=!0}if(t){const t=e.vnode;e.vnode=e=>{if("string"==typeof e.type){const t=e.props;"dir"in t&&"auto"===t.dir&&(t.dir="")}t&&t(e)}}}(),iy.$inject=["api","streamer"],ay.$inject=["groups","session","router"],sy.$inject=["autosaveService","features","persistedDefaults","serviceURL"],ly.$inject=["frameSync","store"],function(e,{reset:t=!1}={}){t&&Po.clear();for(let[t,n]of Object.entries(e))Po.set(t,n)}(yi);const cy=document.querySelector("hypothesis-app");!function(e=window){e.addEventListener("message",J)}(),async function(e,t=window){const n=function(e){
|
|
661
661
|
const t=R(e.location.href),n=["annotations","group","query","appType","openSidebar","showHighlights","services","branding","enableExperimentalNewNoteButton","focus","requestConfigFromFrame","theme","usernameUrl"],r={openSidebar:D,requestConfigFromFrame:e=>{if("string"==typeof e)return e;const t=function(e){return"object"==typeof e&&null!==e?e:{}}(e);return{origin:F(t.origin),ancestorLevel:B(t.ancestorLevel)}}},o={};for(let[e,i]of Object.entries(t))n.includes(e)&&null!==i&&(r[e]?o[e]=r[e](i):o[e]=i);return o}(window),r=function(e,t){const n=e.requestConfigFromFrame;if(!n)return null;if("number"!=typeof n.ancestorLevel||"string"!=typeof n.origin)throw new Error("Improper `requestConfigFromFrame` object. Both `ancestorLevel` and `origin` need to be specified");return{targetFrame:U(n.ancestorLevel,t),origin:n.origin}}(n,t);let o;if(r){const e=await async function(e,t){return{...await q(t.targetFrame,t.origin,"requestConfig",[],3e3),...e.group?{group:e.group}:{}}}(n,r);o=function(e,t){const n=e.services
|
|
662
|
-
;return Array.isArray(n)?(n.forEach(((e,n)=>{"$rpc:requestGroups"===e.groups&&(e.groups=q(t.targetFrame,t.origin,"requestGroups",[n],0).catch((()=>{throw new Error("Unable to fetch groups")})))})),e):e}(e,r)}else o=n;const i={...e,...o};return r&&(i.rpc=r),i.apiUrl=function(e){const t=P(e);if(t){if(t.apiUrl)return t.apiUrl;throw new Error("Service should contain an apiUrl value.")}return e.apiUrl}(i),i}(
|
|
663
|
-
n.register("$window",{value:window}).register("settings",{value:e}),n.run(
|
|
662
|
+
;return Array.isArray(n)?(n.forEach(((e,n)=>{"$rpc:requestGroups"===e.groups&&(e.groups=q(t.targetFrame,t.origin,"requestGroups",[n],0).catch((()=>{throw new Error("Unable to fetch groups")})))})),e):e}(e,r)}else o=n;const i={...e,...o};return r&&(i.rpc=r),i.apiUrl=function(e){const t=P(e);if(t){if(t.apiUrl)return t.apiUrl;throw new Error("Service should contain an apiUrl value.")}return e.apiUrl}(i),i}(ry).then((e=>{!function(e,t){const n=new ny;n.register("annotationsService",uv).register("annotationActivity",hv).register("api",vv).register("apiRoutes",Cv).register("auth",Ev).register("autosaveService",Nv).register("features",Lv).register("frameSync",Bv).register("groups",Hv).register("loadAnnotationsService",qv).register("localStorage",$v).register("persistedDefaults",Vv).register("router",Wv).register("serviceURL",Yv).register("session",Kv).register("streamer",Jv).register("streamFilter",Xv).register("tags",Qv).register("threadsService",ey).register("toastMessenger",ty).register("store",{factory:Vs}),
|
|
663
|
+
n.register("$window",{value:window}).register("settings",{value:e}),n.run(sy),n.run(iy),n.run(ay),n.run(Z),n.run(ly),I(Ro(Ci.Provider,{value:n,children:Ro(lv,{})}),t)}(e,cy)})).catch((e=>function(e,t){console.error("Failed to start Hypothesis client: ",e),I(Ro(cv,{error:e}),t)}(e,cy)));
|
|
664
664
|
//# sourceMappingURL=sidebar.bundle.js.map
|