hypothesis 1.1622.0 → 1.1623.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/build/boot.js CHANGED
@@ -1 +1 @@
1
- !function(){"use strict";var s={"scripts/annotator.bundle.js":"scripts/annotator.bundle.js?249ccb","styles/annotator.css":"styles/annotator.css?c7d4b9","styles/annotator.css.map":"styles/annotator.css.map?ffc171","styles/highlights.css":"styles/highlights.css?468946","styles/highlights.css.map":"styles/highlights.css.map?ee982b","styles/katex.min.css":"styles/katex.min.css?921c28","styles/katex.min.css.map":"styles/katex.min.css.map?e7e03f","styles/pdfjs-overrides.css":"styles/pdfjs-overrides.css?c95edf","styles/pdfjs-overrides.css.map":"styles/pdfjs-overrides.css.map?1d8ac6","styles/sidebar.css.map":"styles/sidebar.css.map?c4cba4","styles/sidebar.css":"styles/sidebar.css?c949f4","styles/ui-playground.css":"styles/ui-playground.css?6778a6","styles/ui-playground.css.map":"styles/ui-playground.css.map?0e6471","scripts/sidebar.bundle.js":"scripts/sidebar.bundle.js?86da5b","scripts/annotator.bundle.js.map":"scripts/annotator.bundle.js.map?252aca","scripts/ui-playground.bundle.js":"scripts/ui-playground.bundle.js?5d518f","scripts/sidebar.bundle.js.map":"scripts/sidebar.bundle.js.map?b0c97f","scripts/ui-playground.bundle.js.map":"scripts/ui-playground.bundle.js.map?77f32b"};function t(s){s.setAttribute("data-hypothesis-asset","")}function e(s,e){var o=s.createElement("link");o.rel="stylesheet",o.type="text/css",o.href=e,t(o),s.head.appendChild(o)}function o(s,e){var o=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},r=o.esModule,n=void 0===r||r,i=o.forceReload,a=void 0!==i&&i,l=s.createElement("script");n&&(l.type="module"),a&&(e+="#ts=".concat(Date.now())),l.src=e,l.async=!1,t(l),s.head.appendChild(l)}function r(s,e,o,r){var n=s.createElement("link");n.rel=e,n.href=r,n.type="application/annotator+".concat(o),t(n),s.head.appendChild(n)}function n(s,e,o){var r=s.createElement("link");r.rel="preload",r.as=e,r.href=o,"fetch"===e&&(r.crossOrigin="anonymous"),t(r),s.head.appendChild(r)}function i(s,t){return s.assetRoot+"build/"+s.manifest[t]}function a(s){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:document;if(-1===s.indexOf("{"))return s;var e=function(){var s,t,e=(arguments.length>0&&void 0!==arguments[0]?arguments[0]:document).currentScript;return e?(s=e.src,(t=s.match(/(https?):\/\/([^:/]+)/))?{protocol:t[1],hostname:t[2]}:null):null}(t);if(!e)throw new Error("Could not process URL template because script origin is unknown");return s=(s=s.replace("{current_host}",e.hostname)).replace("{current_scheme}",e.protocol)}if(function(){var s=[()=>Object.fromEntries([]),()=>new URL(document.location.href),()=>new Request("https://hypothes.is"),()=>Element.prototype.attachShadow,()=>CSS.supports("display: grid"),()=>(document.evaluate("/html/body",document,null,XPathResult.ANY_TYPE,null),!0)];try{return s.every((s=>s()))}catch(s){return!1}}()){var l=function(s){for(var t={},e=s.querySelectorAll("script.js-hypothesis-config"),o=0;o<e.length;o++){var r=void 0;try{r=JSON.parse(e[o].textContent||"")}catch(s){console.warn("Could not parse settings from js-hypothesis-config tags",s),r={}}Object.assign(t,r)}return t}(document),p=a(l.assetRoot||"https://cdn.hypothes.is/hypothesis/1.1622.0/");if(document.querySelector("hypothesis-app")){!function(s,t){n(s,"fetch",t.apiUrl),n(s,"fetch",t.apiUrl+"links");for(var r=0,a=["scripts/sidebar.bundle.js"];r<a.length;r++)o(s,i(t,a[r]),{esModule:!0});for(var l=0,p=["styles/katex.min.css","styles/sidebar.css"];l<p.length;l++)e(s,i(t,p[l]))}(document,{assetRoot:p,manifest:s,apiUrl:l.apiUrl})}else{var c=function(){var s;return null===(s=(arguments.length>0&&void 0!==arguments[0]?arguments[0]:window).chrome)||void 0===s||null===(s=s.runtime)||void 0===s?void 0:s.id}();if(c&&!function(s){return!!(arguments.length>1&&void 0!==arguments[1]?arguments[1]:document).querySelector("script.js-hypothesis-config[data-extension-id=".concat(s,"]"))}(c))throw new Error("Could not start Hypothesis extension as configuration is missing");var d=l,h=a(d.notebookAppUrl||"https://hypothes.is/notebook"),u=a(d.profileAppUrl||"https://hypothes.is/user-profile"),y=a(d.sidebarAppUrl||"https://hypothes.is/app.html");!function(s,t){if(!s.querySelector('link[type="application/annotator+html"]')){r(s,"sidebar","html",t.sidebarAppUrl),r(s,"notebook","html",t.notebookAppUrl),r(s,"profile","html",t.profileAppUrl),n(s,"style",i(t,"styles/annotator.css")),r(s,"hypothesis-client","javascript",t.assetRoot+"build/boot.js");for(var a=0,l=["scripts/annotator.bundle.js"];a<l.length;a++)o(s,i(t,l[a]),{esModule:!1});var p=[];void 0!==window.PDFViewerApplication&&p.push("styles/pdfjs-overrides.css"),p.push("styles/highlights.css");for(var c=0,d=p;c<d.length;c++)e(s,i(t,d[c]))}}(document,{assetRoot:p,manifest:s,notebookAppUrl:h,profileAppUrl:u,sidebarAppUrl:y})}}else console.warn("The Hypothesis annotation tool is not supported in this browser. See https://web.hypothes.is/help/which-browsers-are-supported-by-hypothesis/.")}();
1
+ !function(){"use strict";var s={"scripts/annotator.bundle.js":"scripts/annotator.bundle.js?65f3db","styles/annotator.css":"styles/annotator.css?b497a3","styles/annotator.css.map":"styles/annotator.css.map?b9df74","styles/highlights.css":"styles/highlights.css?468946","styles/highlights.css.map":"styles/highlights.css.map?ee982b","styles/katex.min.css":"styles/katex.min.css?921c28","styles/katex.min.css.map":"styles/katex.min.css.map?e7e03f","styles/pdfjs-overrides.css":"styles/pdfjs-overrides.css?c95edf","styles/pdfjs-overrides.css.map":"styles/pdfjs-overrides.css.map?1d8ac6","styles/sidebar.css":"styles/sidebar.css?c949f4","styles/sidebar.css.map":"styles/sidebar.css.map?c4cba4","styles/ui-playground.css":"styles/ui-playground.css?6778a6","styles/ui-playground.css.map":"styles/ui-playground.css.map?0e6471","scripts/annotator.bundle.js.map":"scripts/annotator.bundle.js.map?51fea6","scripts/sidebar.bundle.js":"scripts/sidebar.bundle.js?d02bd1","scripts/ui-playground.bundle.js":"scripts/ui-playground.bundle.js?5d518f","scripts/ui-playground.bundle.js.map":"scripts/ui-playground.bundle.js.map?77f32b","scripts/sidebar.bundle.js.map":"scripts/sidebar.bundle.js.map?b0c97f"};function t(s){s.setAttribute("data-hypothesis-asset","")}function e(s,e){var o=s.createElement("link");o.rel="stylesheet",o.type="text/css",o.href=e,t(o),s.head.appendChild(o)}function o(s,e){var o=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},r=o.esModule,n=void 0===r||r,i=o.forceReload,a=void 0!==i&&i,l=s.createElement("script");n&&(l.type="module"),a&&(e+="#ts=".concat(Date.now())),l.src=e,l.async=!1,t(l),s.head.appendChild(l)}function r(s,e,o,r){var n=s.createElement("link");n.rel=e,n.href=r,n.type="application/annotator+".concat(o),t(n),s.head.appendChild(n)}function n(s,e,o){var r=s.createElement("link");r.rel="preload",r.as=e,r.href=o,"fetch"===e&&(r.crossOrigin="anonymous"),t(r),s.head.appendChild(r)}function i(s,t){return s.assetRoot+"build/"+s.manifest[t]}function a(s){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:document;if(-1===s.indexOf("{"))return s;var e=function(){var s,t,e=(arguments.length>0&&void 0!==arguments[0]?arguments[0]:document).currentScript;return e?(s=e.src,(t=s.match(/(https?):\/\/([^:/]+)/))?{protocol:t[1],hostname:t[2]}:null):null}(t);if(!e)throw new Error("Could not process URL template because script origin is unknown");return s=(s=s.replace("{current_host}",e.hostname)).replace("{current_scheme}",e.protocol)}if(function(){var s=[()=>Object.fromEntries([]),()=>new URL(document.location.href),()=>new Request("https://hypothes.is"),()=>Element.prototype.attachShadow,()=>CSS.supports("display: grid"),()=>(document.evaluate("/html/body",document,null,XPathResult.ANY_TYPE,null),!0)];try{return s.every((s=>s()))}catch(s){return!1}}()){var l=function(s){for(var t={},e=s.querySelectorAll("script.js-hypothesis-config"),o=0;o<e.length;o++){var r=void 0;try{r=JSON.parse(e[o].textContent||"")}catch(s){console.warn("Could not parse settings from js-hypothesis-config tags",s),r={}}Object.assign(t,r)}return t}(document),p=a(l.assetRoot||"https://cdn.hypothes.is/hypothesis/1.1623.0/");if(document.querySelector("hypothesis-app")){!function(s,t){n(s,"fetch",t.apiUrl),n(s,"fetch",t.apiUrl+"links");for(var r=0,a=["scripts/sidebar.bundle.js"];r<a.length;r++)o(s,i(t,a[r]),{esModule:!0});for(var l=0,p=["styles/katex.min.css","styles/sidebar.css"];l<p.length;l++)e(s,i(t,p[l]))}(document,{assetRoot:p,manifest:s,apiUrl:l.apiUrl})}else{var c=function(){var s;return null===(s=(arguments.length>0&&void 0!==arguments[0]?arguments[0]:window).chrome)||void 0===s||null===(s=s.runtime)||void 0===s?void 0:s.id}();if(c&&!function(s){return!!(arguments.length>1&&void 0!==arguments[1]?arguments[1]:document).querySelector("script.js-hypothesis-config[data-extension-id=".concat(s,"]"))}(c))throw new Error("Could not start Hypothesis extension as configuration is missing");var d=l,h=a(d.notebookAppUrl||"https://hypothes.is/notebook"),u=a(d.profileAppUrl||"https://hypothes.is/user-profile"),y=a(d.sidebarAppUrl||"https://hypothes.is/app.html");!function(s,t){if(!s.querySelector('link[type="application/annotator+html"]')){r(s,"sidebar","html",t.sidebarAppUrl),r(s,"notebook","html",t.notebookAppUrl),r(s,"profile","html",t.profileAppUrl),n(s,"style",i(t,"styles/annotator.css")),r(s,"hypothesis-client","javascript",t.assetRoot+"build/boot.js");for(var a=0,l=["scripts/annotator.bundle.js"];a<l.length;a++)o(s,i(t,l[a]),{esModule:!1});var p=[];void 0!==window.PDFViewerApplication&&p.push("styles/pdfjs-overrides.css"),p.push("styles/highlights.css");for(var c=0,d=p;c<d.length;c++)e(s,i(t,d[c]))}}(document,{assetRoot:p,manifest:s,notebookAppUrl:h,profileAppUrl:u,sidebarAppUrl:y})}}else console.warn("The Hypothesis annotation tool is not supported in this browser. See https://web.hypothes.is/help/which-browsers-are-supported-by-hypothesis/.")}();
@@ -1,20 +1,20 @@
1
1
  {
2
- "scripts/annotator.bundle.js": "scripts/annotator.bundle.js?249ccb",
3
- "styles/annotator.css": "styles/annotator.css?c7d4b9",
4
- "styles/annotator.css.map": "styles/annotator.css.map?ffc171",
2
+ "scripts/annotator.bundle.js": "scripts/annotator.bundle.js?65f3db",
3
+ "styles/annotator.css": "styles/annotator.css?b497a3",
4
+ "styles/annotator.css.map": "styles/annotator.css.map?b9df74",
5
5
  "styles/highlights.css": "styles/highlights.css?468946",
6
6
  "styles/highlights.css.map": "styles/highlights.css.map?ee982b",
7
7
  "styles/katex.min.css": "styles/katex.min.css?921c28",
8
8
  "styles/katex.min.css.map": "styles/katex.min.css.map?e7e03f",
9
9
  "styles/pdfjs-overrides.css": "styles/pdfjs-overrides.css?c95edf",
10
10
  "styles/pdfjs-overrides.css.map": "styles/pdfjs-overrides.css.map?1d8ac6",
11
- "styles/sidebar.css.map": "styles/sidebar.css.map?c4cba4",
12
11
  "styles/sidebar.css": "styles/sidebar.css?c949f4",
12
+ "styles/sidebar.css.map": "styles/sidebar.css.map?c4cba4",
13
13
  "styles/ui-playground.css": "styles/ui-playground.css?6778a6",
14
14
  "styles/ui-playground.css.map": "styles/ui-playground.css.map?0e6471",
15
- "scripts/sidebar.bundle.js": "scripts/sidebar.bundle.js?86da5b",
16
- "scripts/annotator.bundle.js.map": "scripts/annotator.bundle.js.map?252aca",
15
+ "scripts/annotator.bundle.js.map": "scripts/annotator.bundle.js.map?51fea6",
16
+ "scripts/sidebar.bundle.js": "scripts/sidebar.bundle.js?d02bd1",
17
17
  "scripts/ui-playground.bundle.js": "scripts/ui-playground.bundle.js?5d518f",
18
- "scripts/sidebar.bundle.js.map": "scripts/sidebar.bundle.js.map?b0c97f",
19
- "scripts/ui-playground.bundle.js.map": "scripts/ui-playground.bundle.js.map?77f32b"
18
+ "scripts/ui-playground.bundle.js.map": "scripts/ui-playground.bundle.js.map?77f32b",
19
+ "scripts/sidebar.bundle.js.map": "scripts/sidebar.bundle.js.map?b0c97f"
20
20
  }
@@ -156,25 +156,25 @@ if(!this._integration.renderToBitmap)throw new Error("Thumbnail rendering not su
156
156
  if(!t.selector||!t.selector.some((e=>"TextQuoteSelector"===e.type||"ShapeSelector"===e.type)))return{annotation:e,target:t};let n;try{const o=await this._integration.anchor(this.element,t.selector);if(o instanceof Range){const i=mo.fromRange(o);n={annotation:e,target:t,region:i}}else n={annotation:e,target:t,region:o}}catch{n={annotation:e,target:t}}return n})));if(!this._annotations.has(e.$tag))return[];for(const e of n)t(e);return e.$orphan=n.length>0&&n.every((e=>e.target.selector&&!e.region)),this._updateAnchors(this.anchors.concat(n),!0),this._sidebarRPC.call("syncAnchoringStatus",e),n}detach(e,t=!0){this._annotations.delete(e);const n=[];for(const t of this.anchors)t.annotation.$tag!==e?n.push(t):t.highlights&&Eo(t.highlights);this._updateAnchors(n,t)}_updateAnchors(e,t){this.anchors=e,this._clusterToolbar?.scheduleClusterUpdates(),t&&this._bucketBarClient.update(this.anchors)}async createAnnotation(e){if("selection"===e)return this.createAnnotationFromSelection();if(["rect","point"].includes(e)){
157
157
  const t=await this._drawTool.draw(e),n=await this.getDocumentInfo(),o=[{source:n.uri,selector:await this._integration.describe(this.element,t)}],i={uri:n.uri,document:n.metadata,target:o,$tag:"a:"+on(8)};return this._sidebarRPC.call("createAnnotation",i),this.anchor(i),i}throw new Error("Unsupported annotation tool")}async createAnnotationFromSelection({highlight:e=!1}={}){const t=this.selectedRanges;this.selectedRanges=[];const n=await this.getDocumentInfo(),o=this.element,i=(await Promise.all(t.map((e=>this._integration.describe(o,e))))).map((e=>({source:n.uri,selector:e}))),r={uri:n.uri,document:n.metadata,target:i,$highlight:e,$cluster:e?"user-highlights":"user-annotations",$tag:"a:"+on(8)};return this._sidebarRPC.call("createAnnotation",r),this.anchor(r),Lr(),r}_hoverAnnotations(e){this._hoveredAnnotations.clear(),e.forEach((e=>this._hoveredAnnotations.add(e)));for(const t of this.anchors)if(t.highlights){const n=e.includes(t.annotation.$tag);ko(t.highlights,n)}this._sidebarRPC.call("hoverAnnotations",e)
158
158
  }_onSelection(e){const t=this._integration.getAnnotatableRange(e);if(!t)return void this._onClearSelection();const n=document.getSelection(),o=wo(n),i=xo(n);i?(this.selectedRanges=[t],this._hostRPC.call("textSelected"),this._adder.annotationsForSelection=Pr(),this._isAdderVisible=!0,this._adder.show(i,o)):this._onClearSelection()}_onClearSelection(){this._isAdderVisible=!1,this._adder.hide(),this.selectedRanges=[],this._informHostOnNextSelectionClear&&this._hostRPC.call("textUnselected"),this._informHostOnNextSelectionClear=!0}selectAnnotations(e,{toggle:t=!1,focusInSidebar:n=!1}={}){t?this._sidebarRPC.call("toggleAnnotationSelection",e):this._sidebarRPC.call("showAnnotations",e,n),this._sidebarRPC.call("openSidebar")}setHighlightsVisible(e,t=!0){!function(e,t){e.classList.toggle("hypothesis-highlights-always-on",t)}(this.element,e),this._highlightsVisible=e,t&&this._hostRPC.call("highlightsVisibleChanged",e)}get highlightsVisible(){return this._highlightsVisible}fitSideBySide(e){this._sidebarLayout=e,
159
- this._integration.fitSideBySide(e)}get hoveredAnnotationTags(){return this._hoveredAnnotations}_handleShortcut(e){jn(e,"Ctrl+Shift+H")&&this.setHighlightsVisible(!this._highlightsVisible)}_setOutsideAssignmentNoticeVisible(e){this._outsideAssignmentNotice||(this._outsideAssignmentNotice=new Er(this.element)),this._outsideAssignmentNotice.setVisible(e)}}function Br(e,t){const n=new URL(e),o=new URLSearchParams;return o.append("config",JSON.stringify(t)),n.hash=o.toString(),n.toString()}function Dr(e,t){const n={};for(const[e,o]of Object.entries(t))"notebookAppUrl"!==e&&"sidebarAppUrl"!==e&&null!=o&&(n[e]=o);n.origin=new URL(e).origin,n.version="1.1622.0";const o=new URL(window.location.href);if(o.hash="",n.hostURL=o.toString(),Array.isArray(n.services)&&n.services?.length>0){const e=n.services[0];e.onLoginRequest&&(e.onLoginRequestProvided=!0),e.onLogoutRequest&&(e.onLogoutRequestProvided=!0),e.onSignupRequest&&(e.onSignupRequestProvided=!0),e.onProfileRequest&&(e.onProfileRequestProvided=!0),
159
+ this._integration.fitSideBySide(e)}get hoveredAnnotationTags(){return this._hoveredAnnotations}_handleShortcut(e){jn(e,"Ctrl+Shift+H")&&this.setHighlightsVisible(!this._highlightsVisible)}_setOutsideAssignmentNoticeVisible(e){this._outsideAssignmentNotice||(this._outsideAssignmentNotice=new Er(this.element)),this._outsideAssignmentNotice.setVisible(e)}}function Br(e,t){const n=new URL(e),o=new URLSearchParams;return o.append("config",JSON.stringify(t)),n.hash=o.toString(),n.toString()}function Dr(e,t){const n={};for(const[e,o]of Object.entries(t))"notebookAppUrl"!==e&&"sidebarAppUrl"!==e&&null!=o&&(n[e]=o);n.origin=new URL(e).origin,n.version="1.1623.0";const o=new URL(window.location.href);if(o.hash="",n.hostURL=o.toString(),Array.isArray(n.services)&&n.services?.length>0){const e=n.services[0];e.onLoginRequest&&(e.onLoginRequestProvided=!0),e.onLogoutRequest&&(e.onLogoutRequestProvided=!0),e.onSignupRequest&&(e.onSignupRequestProvided=!0),e.onProfileRequest&&(e.onProfileRequestProvided=!0),
160
160
  e.onHelpRequest&&(e.onHelpRequestProvided=!0)}return n}function Fr({closed:e,onClose:t,children:n,"data-testid":o,"aria-label":i}){const r=se(null);return ie((()=>{e?r.current?.close():r.current?.showModal()}),[e]),ie((()=>{const e=r.current;return e?.addEventListener("cancel",t),()=>{e?.removeEventListener("cancel",t)}}),[t]),Te("dialog",{ref:r,className:"relative w-full h-full backdrop:bg-black/50","data-testid":o,"aria-label":i,children:n})}function Hr({closed:e,children:t,...n}){return Te("div",{...n,className:Re("fixed z-max top-0 left-0 right-0 bottom-0 p-3 bg-black/50",{hidden:e}),children:Te("div",{className:"relative w-full h-full",children:t})})}function Vr({document_:e=document,...t}){return Te(ae((()=>function(e){return"function"==typeof e.createElement("dialog").showModal}(e)?Fr:Hr),[e]),{...t})}function Ur({config:e,groupId:t}){return Te("iframe",{title:"Hypothesis annotation notebook",className:"h-full w-full border-0",allow:"fullscreen; clipboard-write",src:Br(e.notebookAppUrl,{
161
161
  ...Dr(e.notebookAppUrl,e),group:t})})}function qr({eventBus:e,config:t}){const[n,o]=oe(0),[i,r]=oe(!0),[s,a]=oe(null),l=se(""),c=se(null);ie((()=>(l.current=document.body.style.overflow,()=>{document.body.style.overflow=l.current})),[]),ie((()=>{document.body.style.overflow=i?l.current:"hidden"}),[i]),ie((()=>{const t=e.createEmitter();return t.subscribe("openNotebook",(e=>{r(!1),o((e=>e+1)),a(e)})),c.current=t,()=>{t.destroy()}}),[e]);const h=le((()=>{r(!0),c.current?.publish("closeNotebook")}),[]);return null===s?null:Te(Vr,{closed:i,onClose:h,"data-testid":"notebook-outer","aria-label":"Hypothesis notebook",children:[Te("div",{className:"absolute right-0 m-3",children:Te(kt,{title:"Close notebook",onClick:h,variant:"dark",classes:Re("!bg-transparent enabled:hover:!bg-grey-3"),"data-testid":"close-button",children:Te(He,{className:"w-4 h-4"})})}),Te(Ur,{config:t,groupId:s},n)]})}class $r{constructor(e,t,n){this._container=new to("notebook",(()=>Te(qr,{eventBus:t,config:n}))),
162
162
  e.append(this._container.element),this._container.render()}destroy(){this._container.destroy()}}function zr({eventBus:e,config:t}){const[n,o]=oe(!0),i=se(null);ie((()=>{const t=e.createEmitter();return t.subscribe("openProfile",(()=>{o(!1)})),i.current=t,()=>{t.destroy()}}),[e]);const r=()=>{o(!0),i.current?.publish("closeProfile")};return n?null:Te(Vr,{closed:n,onClose:r,"data-testid":"profile-outer","aria-label":"Hypothesis profile",children:[Te("div",{className:"absolute right-0 m-3",children:Te(kt,{title:"Close profile dialog",onClick:r,variant:"dark",classes:Re("!bg-transparent enabled:hover:!bg-grey-3"),children:Te(He,{className:"w-4 h-4"})})}),Te("iframe",{title:"Hypothesis profile",className:"h-full w-full border-0",src:t.profileAppUrl})]})}class Wr{constructor(e,t,n){this._container=new to("profile",(()=>Te(zr,{eventBus:t,config:n}))),e.append(this._container.element),this._container.render()}destroy(){this._container.destroy()}}
163
163
  function jr({above:e,below:t,buckets:n,onFocusAnnotations:o,onScrollToAnnotation:i,onSelectAnnotations:r}){const s=e.anchors.length>0,a=t.anchors.length>0,l=e=>e.anchors.map((e=>e.tag));return Te("ul",{className:"relative",children:[s&&Te("li",{className:"absolute right-0 pointer-events-auto mt-[-11px]",style:{top:e.position},children:Te(tn,{"data-testid":"up-navigation-button",direction:"up",onClick:()=>{const t=[...e.anchors].sort(((e,t)=>e.bottom-t.bottom)),n=t[t.length-1];i(n.tag)},onBlur:()=>o([]),onFocus:()=>o(l(e)),onMouseEnter:()=>o(l(e)),onMouseOut:()=>o([]),title:`Go up to next annotations (${e.anchors.length})`,children:e.anchors.length})}),n.map(((e,t)=>Te("li",{className:"absolute right-0 pointer-events-auto mt-[-8px]",style:{top:e.position},children:Te(tn,{direction:"left",onClick:t=>r(l(e),t.metaKey||t.ctrlKey),onBlur:()=>o([]),onFocus:()=>o(l(e)),onMouseEnter:()=>o(l(e)),onMouseOut:()=>o([]),title:`Select nearby annotations (${e.anchors.length})`,children:e.anchors.length})},t))),a&&Te("li",{
164
164
  className:"absolute right-0 pointer-events-auto",style:{top:t.position},children:Te(tn,{"data-testid":"down-navigation-button",direction:"down",onClick:()=>{const e=[...t.anchors].sort(((e,t)=>e.top-t.top)),n=e[0];i(n.tag)},onBlur:()=>o([]),onFocus:()=>o(l(t)),onMouseEnter:()=>o(l(t)),onMouseOut:()=>o([]),title:`Go up to next annotations (${t.anchors.length})`,children:t.anchors.length})})]})}class Xr{constructor(e,{onFocusAnnotations:t,onScrollToAnnotation:n,onSelectAnnotations:o}){this._positions=[],this._container=new to("bucket-bar",(()=>this._render())),Object.assign(this._container.element.style,{display:"block",flexGrow:"1",width:"100%"}),e.appendChild(this._container.element),this._onFocusAnnotations=t,this._onScrollToAnnotation=n,this._onSelectAnnotations=o,this._container.render()}destroy(){this._container.destroy()}update(e){this._positions=e,this._container.render()}_render(){const e=function(e,t){const n=[],o=[],i=[];let r=null;function s(e){const{bottom:t,top:n}=e;return{bottom:t,
165
- position:n+(t-n)/2,anchors:[e],top:n}}const a=t.getBoundingClientRect(),l=e.map((e=>({tag:e.tag,top:e.top-a.top,bottom:e.bottom-a.top})));for(const e of l){const t=(e.top+e.bottom)/2;if(t<30){n.push(e);continue}if(t>a.height-30){o.push(e);continue}if(!r){r=s(e);continue}const l=e.top>r.top&&e.bottom<r.bottom;if(e.top-r.bottom>60&&!l)i.push(r),r=s(e);else{const t=e.bottom>r.bottom?e.bottom:r.bottom,n=t-r.top;r.anchors.push(e),r.bottom=t,r.position=r.top+n/2}}return r&&i.push(r),{above:{anchors:n,position:30},below:{anchors:o,position:a.height-30},buckets:i}}(this._positions,this._container.element);return Te(jr,{above:e.above,below:e.below,buckets:e.buckets,onFocusAnnotations:e=>this._onFocusAnnotations(e),onScrollToAnnotation:e=>this._onScrollToAnnotation(e),onSelectAnnotations:(e,t)=>this._onSelectAnnotations(e,t)})}}function Yr({emitter:e}){const[t,n]=oe([]),o=le((e=>n((t=>[...t,e]))),[]),i=le((e=>n((t=>t.filter((t=>t.id!==e))))),[]);return ie((()=>(e.subscribe("toastMessageAdded",o),
166
- e.subscribe("toastMessageDismissed",i),()=>{e.unsubscribe("toastMessageAdded",o),e.unsubscribe("toastMessageDismissed",i)})),[e,i,o]),Te(Qt,{messages:t,onMessageDismiss:i})}function Kr({icon:e,...t}){return Te(St,{classes:Re("justify-center rounded","w-[30px] h-[30px]","shadow border bg-white text-grey-6 hover:text-grey-9"),...t,size:"custom",variant:"custom",children:Te(e,{})})}function Gr({highlightsVisible:e}){return Te("div",{className:"sr-only",role:"status","data-testid":"toolbar-status",children:e?"Highlights visible":"Highlights hidden"})}function Qr({closeSidebar:e,createAnnotation:t,isSidebarOpen:n,sidebarContainerId:o,newAnnotationType:i,showHighlights:r,supportedTools:s=["selection"],toggleHighlights:a,toggleSidebar:l,toggleSidebarRef:c,useMinimalControls:h=!1}){return Te("div",{className:Re("absolute left-[-33px] w-[33px] z-2","text-px-base leading-none"),children:[h&&n&&Te(St,{
165
+ position:n+(t-n)/2,anchors:[e],top:n}}const a=t.getBoundingClientRect(),l=e.map((e=>({tag:e.tag,top:e.top-a.top,bottom:e.bottom-a.top})));for(const e of l){const t=(e.top+e.bottom)/2;if(t<30){n.push(e);continue}if(t>a.height-30){o.push(e);continue}if(!r){r=s(e);continue}const l=e.top>r.top&&e.bottom<r.bottom;if(e.top-r.bottom>60&&!l)i.push(r),r=s(e);else{const t=e.bottom>r.bottom?e.bottom:r.bottom,n=t-r.top;r.anchors.push(e),r.bottom=t,r.position=r.top+n/2}}return r&&i.push(r),{above:{anchors:n,position:25},below:{anchors:o,position:a.height-30},buckets:i}}(this._positions,this._container.element);return Te(jr,{above:e.above,below:e.below,buckets:e.buckets,onFocusAnnotations:e=>this._onFocusAnnotations(e),onScrollToAnnotation:e=>this._onScrollToAnnotation(e),onSelectAnnotations:(e,t)=>this._onSelectAnnotations(e,t)})}}function Yr({emitter:e}){const[t,n]=oe([]),o=le((e=>n((t=>[...t,e]))),[]),i=le((e=>n((t=>t.filter((t=>t.id!==e))))),[]);return ie((()=>(e.subscribe("toastMessageAdded",o),
166
+ e.subscribe("toastMessageDismissed",i),()=>{e.unsubscribe("toastMessageAdded",o),e.unsubscribe("toastMessageDismissed",i)})),[e,i,o]),Te(Qt,{messages:t,onMessageDismiss:i})}function Kr({icon:e,...t}){return Te(St,{classes:Re("justify-center rounded","w-[30px] h-[30px]","shadow border bg-white text-grey-6 hover:text-grey-9"),...t,size:"custom",variant:"custom",children:Te(e,{})})}function Gr({highlightsVisible:e}){return Te("div",{className:"sr-only",role:"status","data-testid":"toolbar-status",children:e?"Highlights visible":"Highlights hidden"})}function Qr({closeSidebar:e,createAnnotation:t,isSidebarOpen:n,sidebarContainerId:o,newAnnotationType:i,showHighlights:r,supportedTools:s=["selection"],toggleHighlights:a,toggleSidebar:l,toggleSidebarRef:c,useMinimalControls:h=!1}){return Te("div",{className:Re({"absolute right-full":h,"relative right-[11px]":!h},"w-[33px] z-2","text-px-base leading-none"),children:[h&&n&&Te(St,{
167
167
  classes:Re("transition-colors focus-visible-ring ring-inset","w-[27px] h-[27px] mt-[140px] ml-px-1.5","flex items-center justify-center bg-white border","text-grey-6 hover:text-grey-9 transition-colors","border-r-0","shadow-sidebar"),title:"Close annotation sidebar",onClick:e,unstyled:!0,children:Te(He,{})}),!h&&Te(x,{children:[Te(St,{classes:Re("transition-colors focus-visible-ring ring-inset","h-[40px] w-[33px] pl-[6px] rounded-bl","bg-white text-grey-5 hover:text-grey-9","border-l border-b"),elementRef:c,title:"Annotation sidebar",expanded:n,"aria-controls":o,onClick:l,unstyled:!0,children:Te(n?We:$e,{})}),Te("div",{className:"space-y-px-1.5 mt-px-2",children:[Te(Kr,{title:"Show highlights",icon:r?Nt:tt,pressed:r,onClick:a}),s.includes("selection")&&Te(Kr,{"data-testid":"text-annotation",title:"note"===i?"New page note":"New annotation",icon:"note"===i?dt:De,onClick:()=>t("selection")}),s.includes("rect")&&Te(Kr,{"data-testid":"rect-annotation",title:"Rectangle annotation",icon:rt,onClick:()=>t("rect")
168
168
  }),s.includes("point")&&Te(Kr,{"data-testid":"point-annotation",title:"Point annotation",icon:ft,onClick:()=>t("point")})]}),Te(Gr,{highlightsVisible:r})]})]})}class Jr{constructor(e,t){const{createAnnotation:n,setSidebarOpen:o,setHighlightsVisible:i}=t;this._container=e,this._useMinimalControls=!1,this._newAnnotationType="note",this._highlightsVisible=!1,this._sidebarOpen=!1,this._sidebarContainerId=t.sidebarContainerId,this._supportedAnnotationTools=["selection"],this._closeSidebar=()=>o(!1),this._toggleSidebar=()=>o(!this._sidebarOpen),this._toggleHighlights=()=>i(!this._highlightsVisible),this._createAnnotation=e=>{n(e),"selection"===e&&o(!0)},this._sidebarToggleButton={current:null},this.render()}getWidth(){return this._container.firstChild.getBoundingClientRect().width}set useMinimalControls(e){this._useMinimalControls=e,this.render()}get useMinimalControls(){return this._useMinimalControls}set sidebarOpen(e){this._sidebarOpen=e,this.render()}get sidebarOpen(){return this._sidebarOpen}
169
169
  set newAnnotationType(e){this._newAnnotationType=e,this.render()}get newAnnotationType(){return this._newAnnotationType}set highlightsVisible(e){this._highlightsVisible=e,this.render()}get highlightsVisible(){return this._highlightsVisible}get sidebarToggleButton(){return this._sidebarToggleButton.current}set supportedAnnotationTools(e){this._supportedAnnotationTools=e,this.render()}get supportedAnnotationTools(){return this._supportedAnnotationTools}render(){U(Te(Qr,{closeSidebar:this._closeSidebar,createAnnotation:this._createAnnotation,newAnnotationType:this._newAnnotationType,isSidebarOpen:this._sidebarOpen,sidebarContainerId:this._sidebarContainerId,showHighlights:this._highlightsVisible,supportedTools:this._supportedAnnotationTools,toggleHighlights:this._toggleHighlights,toggleSidebar:this._toggleSidebar,toggleSidebarRef:this._sidebarToggleButton,useMinimalControls:this.useMinimalControls}),this._container)}}class Zr{constructor({target:e,threshold:t=10,onDrag:n}){e.style.touchAction="none",
170
- this._listeners=new we,this._startX=null,this._dragActive=!1,this._threshold=t,this._listeners.add(e,"pointerdown",(e=>{this._startX=e.clientX}));const o=e=>{if(null!==this._startX&&this._dragActive){const t=e.clientX-this._startX;n({type:"dragend",deltaX:t})}this._startX=null,this._dragActive=!1};this._listeners.add(window,"pointercancel",o),this._listeners.add(window,"pointerup",o),this._listeners.add(window,"pointermove",(e=>{if(null===this._startX)return;const t=e.clientX-this._startX;!this._dragActive&&Math.abs(t)>=this._threshold&&(this._dragActive=!0,n({type:"dragstart",deltaX:t})),this._dragActive&&n({type:"dragmove",deltaX:t})}))}destroy(){this._listeners.removeAll()}}class es{constructor(e,t,n){if(this._emitter=t.createEmitter(),this._guestWithSelection=null,this._guestRPC=[],this._sidebarRPC=new wn,this.iframe=function(e){const t=e.sidebarAppUrl,n=Br(t,Dr(t,e)),o=document.createElement("iframe");return o.src=n,o.title="Hypothesis annotation viewer",o.className="sidebar-frame",
171
- o.allow="fullscreen; clipboard-write",o}(n),this._config=n,this.bucketBar=null,this.features=new $o,n.externalContainerSelector)this.externalFrame=document.querySelector(n.externalContainerSelector)??e,this.externalFrame.appendChild(this.iframe);else{if(this.iframeContainer=document.createElement("div"),this.iframeContainer.style.display="none",this.iframeContainer.className="sidebar-container",this.iframeContainer.id="sidebar-container","clean"===n.theme)this.iframeContainer.classList.add("theme-clean");else{let e;n.bucketContainerSelector&&(e=document.querySelector(n.bucketContainerSelector),e||console.warn(`Custom bucket container "${n.bucketContainerSelector}" not found`));const t=document.createElement("div");t.setAttribute("data-testid","sidebar-edge"),t.className=Re("absolute top-0 bottom-0 w-[23px] left-[-22px]","flex flex-col pt-[110px] pr-[5px]","bg-grey-2 sidebar-collapsed:bg-black/[.08]","pointer-events-none"),this.iframeContainer.append(t),e||(e=t),this.bucketBar=new Xr(e,{
172
- onFocusAnnotations:e=>this._guestRPC.forEach((t=>t.call("hoverAnnotations",e))),onScrollToAnnotation:e=>this._guestRPC.forEach((t=>t.call("scrollToAnnotation",e))),onSelectAnnotations:(e,t)=>this._guestRPC.forEach((n=>n.call("selectAnnotations",e,t)))})}this.iframeContainer.appendChild(this.iframe),this._hypothesisSidebar=document.createElement("hypothesis-sidebar");const t=eo(this._hypothesisSidebar);t.appendChild(this.iframeContainer),e.appendChild(this._hypothesisSidebar),this._messagesElement=document.createElement("div"),t.appendChild(this._messagesElement),U(Te(Yr,{emitter:this._emitter}),this._messagesElement)}this.iframe.contentWindow&&un(this.iframe.contentWindow),this._listeners=new we;const o=document.createElement("div");this.toolbar=new Jr(o,{sidebarContainerId:this.iframeContainer?.id,createAnnotation:e=>{if(0===this._guestRPC.length)return;(this._guestWithSelection??this._guestRPC[0]).call("createAnnotation",{tool:e})},setSidebarOpen:e=>e?this.open():this.close(),
173
- setHighlightsVisible:e=>this.setHighlightsVisible(e)}),"clean"===n.theme?this.toolbar.useMinimalControls=!0:this.toolbar.useMinimalControls=!1,this.iframeContainer?(this.iframeContainer.prepend(o),this._toolbarWidth=this.toolbar.getWidth()):this._toolbarWidth=0,this._listeners.add(window,"resize",(()=>this._onResize())),this._dragResizeState={initial:null,final:null};const i=this.toolbar.sidebarToggleButton;i&&(this._dragResizeHandler=new Zr({target:i,onDrag:e=>this._onDragSidebarToggleButton(e)})),this.close();const[r]=n.services||[];r&&(this.onLoginRequest=r.onLoginRequest,this.onLogoutRequest=r.onLogoutRequest,this.onSignupRequest=r.onSignupRequest,this.onProfileRequest=r.onProfileRequest,this.onHelpRequest=r.onHelpRequest),this.onLayoutChange=n.onLayoutChange,this._layoutState={expanded:!1,width:0,height:0,toolbarWidth:0},this._updateLayoutState(!1),this._setupSidebarEvents()}destroy(){this._guestRPC.forEach((e=>e.destroy())),this._sidebarRPC.destroy(),this.bucketBar?.destroy(),
174
- this._listeners.removeAll(),this._dragResizeHandler?.destroy(),this._hypothesisSidebar?(U(null,this._messagesElement),this._hypothesisSidebar.remove()):this.iframe.remove(),this._emitter.destroy(),un(null)}onFrameConnected(e,t){switch(e){case"guest":this._connectGuest(t);break;case"sidebar":this._sidebarRPC.connect(t)}}_connectGuest(e){const t=new wn;t.on("textSelected",(()=>{this._guestWithSelection=t,this.toolbar.newAnnotationType="annotation",this._guestRPC.filter((e=>e!==t)).forEach((e=>e.call("clearSelection")))})),t.on("textUnselected",(()=>{this._guestWithSelection=null,this.toolbar.newAnnotationType="note",this._guestRPC.filter((e=>e!==t)).forEach((e=>e.call("clearSelection")))})),t.on("highlightsVisibleChanged",(e=>{this.setHighlightsVisible(e)}));const n=this.bucketBar;n&&t.on("anchorsChanged",(e=>{0===this._guestRPC.indexOf(t)&&n.update(e)})),t.on("close",(()=>{t.destroy(),t===this._guestWithSelection&&(this._guestWithSelection=null),this._guestRPC=this._guestRPC.filter((e=>e!==t))})),
175
- t.on("supportedToolsChanged",(e=>{this.toolbar.supportedAnnotationTools=e})),t.connect(e),this._guestRPC.push(t),t.call("sidebarLayoutChanged",this._layoutState)}_setupSidebarEvents(){var e;e=document.body,this._sidebarRPC.on("publicAnnotationCountChanged",(function(t){const n=e.querySelectorAll("[data-hypothesis-annotation-count]");Array.from(n).forEach((e=>{e.textContent=t.toString()}))})),function(e,t){const n=e.querySelectorAll("[data-hypothesis-trigger]");Array.from(n).forEach((e=>{e.addEventListener("click",(e=>{t(),e.stopPropagation()}))}))}(document.body,(()=>this.open())),this._sidebarRPC.on("featureFlagsUpdated",(e=>this.features.update(e))),this._sidebarRPC.on("connect",(()=>{this.iframeContainer&&(this.iframeContainer.style.display="");const e="always"===this._config.showHighlights;this.setHighlightsVisible(e),(this._config.openSidebar||this._config.annotations||this._config.query||this._config.group)&&this.open()})),this._sidebarRPC.on("showHighlights",(()=>this.setHighlightsVisible(!0))),
176
- this._sidebarRPC.on("openSidebar",(()=>this.open())),this._sidebarRPC.on("closeSidebar",(()=>this.close())),this._sidebarRPC.on("openNotebook",(e=>{this.hide(),this._emitter.publish("openNotebook",e)})),this._sidebarRPC.on("openProfile",(()=>{this.hide(),this._emitter.publish("openProfile")})),this._emitter.subscribe("closeProfile",(()=>{this.show()})),this._emitter.subscribe("closeNotebook",(()=>{this.show()})),this._sidebarRPC.on("toastMessageAdded",(e=>{this._emitter.publish("toastMessageAdded",e)})),this._sidebarRPC.on("toastMessageDismissed",(e=>{this._emitter.publish("toastMessageDismissed",e)}));[["loginRequested",this.onLoginRequest],["logoutRequested",this.onLogoutRequest],["signupRequested",this.onSignupRequest],["profileRequested",this.onProfileRequest],["helpRequested",this.onHelpRequest]].forEach((([e,t])=>{t&&this._sidebarRPC.on(e,(()=>t()))}))}_resetDragResizeState(){this._dragResizeState={initial:null,final:null}}_updateLayout(){
177
- this._renderFrame||(this._renderFrame=requestAnimationFrame((()=>{if(this._renderFrame=void 0,"number"==typeof this._dragResizeState.final&&this._dragResizeState.final!==this._dragResizeState.initial&&this.iframeContainer){const e=this._dragResizeState.final,t=-e;this.iframeContainer.style.marginLeft=`${e}px`,t>=280&&(this.iframeContainer.style.width=`${t}px`),this._updateLayoutState()}})))}_updateLayoutState(e){const t=this.iframeContainer&&this.toolbar.getWidth()||0,n=this.iframeContainer??this.externalFrame,{height:o}=n.getBoundingClientRect(),i=window.getComputedStyle(n),r=parseInt(i.width),s=parseInt(i.marginLeft);let a=t;"boolean"==typeof e?e&&(a+=r):(s<280?a-=s:a+=r,e=a>t);const l={expanded:e,width:e?a:t,height:o,toolbarWidth:t};this._layoutState=l,this.onLayoutChange?.(l),this._guestRPC.forEach((e=>e.call("sidebarLayoutChanged",l)))}_onResize(){!0===this.toolbar.sidebarOpen&&(window.innerWidth<280?this.close():this.open())}isResizing(){return null!==this._dragResizeState.initial}
170
+ this._listeners=new we,this._startX=null,this._dragActive=!1,this._threshold=t,this._listeners.add(e,"pointerdown",(e=>{this._startX=e.clientX}));const o=e=>{if(null!==this._startX&&this._dragActive){const t=e.clientX-this._startX;n({type:"dragend",deltaX:t})}this._startX=null,this._dragActive=!1};this._listeners.add(window,"pointercancel",o),this._listeners.add(window,"pointerup",o),this._listeners.add(window,"pointermove",(e=>{if(null===this._startX)return;const t=e.clientX-this._startX;!this._dragActive&&Math.abs(t)>=this._threshold&&(this._dragActive=!0,n({type:"dragstart",deltaX:t})),this._dragActive&&n({type:"dragmove",deltaX:t})}))}destroy(){this._listeners.removeAll()}}class es{constructor(e,t,n){this._emitter=t.createEmitter(),this._guestWithSelection=null,this._guestRPC=[],this._sidebarRPC=new wn,this.iframe=function(e){const t=e.sidebarAppUrl,n=Br(t,Dr(t,e)),o=document.createElement("iframe");return o.src=n,o.title="Hypothesis annotation viewer",o.className="sidebar-frame",
171
+ o.allow="fullscreen; clipboard-write",o}(n),this._config=n,this.bucketBar=null,this.features=new $o;const o="sidebar-container",i=document.createElement("div");if(i.setAttribute("data-testid","toolbar-container"),this.toolbar=new Jr(i,{sidebarContainerId:o,createAnnotation:e=>{if(0===this._guestRPC.length)return;(this._guestWithSelection??this._guestRPC[0]).call("createAnnotation",{tool:e})},setSidebarOpen:e=>e?this.open():this.close(),setHighlightsVisible:e=>this.setHighlightsVisible(e)}),n.externalContainerSelector)this.externalFrame=document.querySelector(n.externalContainerSelector)??e,this.externalFrame.appendChild(this.iframe);else{if(this.iframeContainer=document.createElement("div"),this.iframeContainer.style.display="none",this.iframeContainer.className="sidebar-container",this.iframeContainer.id=o,"clean"===n.theme)this.iframeContainer.classList.add("theme-clean"),this.iframeContainer.append(i),this.toolbar.useMinimalControls=!0;else{let e
172
+ ;n.bucketContainerSelector&&(e=document.querySelector(n.bucketContainerSelector),e||console.warn(`Custom bucket container "${n.bucketContainerSelector}" not found`));const t=document.createElement("div");t.setAttribute("data-testid","sidebar-edge"),t.className=Re("absolute top-0 bottom-0 w-[23px] left-[-22px]","flex flex-col pr-[5px]","bg-grey-2 sidebar-collapsed:bg-black/[.08]","pointer-events-none"),i.className="pointer-events-auto",t.append(i),this.iframeContainer.append(t),e||(e=t),this.bucketBar=new Xr(e,{onFocusAnnotations:e=>this._guestRPC.forEach((t=>t.call("hoverAnnotations",e))),onScrollToAnnotation:e=>this._guestRPC.forEach((t=>t.call("scrollToAnnotation",e))),onSelectAnnotations:(e,t)=>this._guestRPC.forEach((n=>n.call("selectAnnotations",e,t)))})}this.iframeContainer.appendChild(this.iframe),this._hypothesisSidebar=document.createElement("hypothesis-sidebar");const t=eo(this._hypothesisSidebar);t.appendChild(this.iframeContainer),e.appendChild(this._hypothesisSidebar),
173
+ this._messagesElement=document.createElement("div"),t.appendChild(this._messagesElement),U(Te(Yr,{emitter:this._emitter}),this._messagesElement)}this.iframe.contentWindow&&un(this.iframe.contentWindow),this._listeners=new we,this.iframeContainer?this._toolbarWidth=this.toolbar.getWidth():this._toolbarWidth=0,this._listeners.add(window,"resize",(()=>this._onResize())),this._dragResizeState={initial:null,final:null};const r=this.toolbar.sidebarToggleButton;r&&(this._dragResizeHandler=new Zr({target:r,onDrag:e=>this._onDragSidebarToggleButton(e)})),this.close();const[s]=n.services||[];s&&(this.onLoginRequest=s.onLoginRequest,this.onLogoutRequest=s.onLogoutRequest,this.onSignupRequest=s.onSignupRequest,this.onProfileRequest=s.onProfileRequest,this.onHelpRequest=s.onHelpRequest),this.onLayoutChange=n.onLayoutChange,this._layoutState={expanded:!1,width:0,height:0,toolbarWidth:0},this._updateLayoutState(!1),this._setupSidebarEvents()}destroy(){this._guestRPC.forEach((e=>e.destroy())),this._sidebarRPC.destroy(),
174
+ this.bucketBar?.destroy(),this._listeners.removeAll(),this._dragResizeHandler?.destroy(),this._hypothesisSidebar?(U(null,this._messagesElement),this._hypothesisSidebar.remove()):this.iframe.remove(),this._emitter.destroy(),un(null)}onFrameConnected(e,t){switch(e){case"guest":this._connectGuest(t);break;case"sidebar":this._sidebarRPC.connect(t)}}_connectGuest(e){const t=new wn;t.on("textSelected",(()=>{this._guestWithSelection=t,this.toolbar.newAnnotationType="annotation",this._guestRPC.filter((e=>e!==t)).forEach((e=>e.call("clearSelection")))})),t.on("textUnselected",(()=>{this._guestWithSelection=null,this.toolbar.newAnnotationType="note",this._guestRPC.filter((e=>e!==t)).forEach((e=>e.call("clearSelection")))})),t.on("highlightsVisibleChanged",(e=>{this.setHighlightsVisible(e)}));const n=this.bucketBar;n&&t.on("anchorsChanged",(e=>{0===this._guestRPC.indexOf(t)&&n.update(e)})),t.on("close",(()=>{t.destroy(),t===this._guestWithSelection&&(this._guestWithSelection=null),
175
+ this._guestRPC=this._guestRPC.filter((e=>e!==t))})),t.on("supportedToolsChanged",(e=>{this.toolbar.supportedAnnotationTools=e})),t.connect(e),this._guestRPC.push(t),t.call("sidebarLayoutChanged",this._layoutState)}_setupSidebarEvents(){var e;e=document.body,this._sidebarRPC.on("publicAnnotationCountChanged",(function(t){const n=e.querySelectorAll("[data-hypothesis-annotation-count]");Array.from(n).forEach((e=>{e.textContent=t.toString()}))})),function(e,t){const n=e.querySelectorAll("[data-hypothesis-trigger]");Array.from(n).forEach((e=>{e.addEventListener("click",(e=>{t(),e.stopPropagation()}))}))}(document.body,(()=>this.open())),this._sidebarRPC.on("featureFlagsUpdated",(e=>this.features.update(e))),this._sidebarRPC.on("connect",(()=>{this.iframeContainer&&(this.iframeContainer.style.display="");const e="always"===this._config.showHighlights;this.setHighlightsVisible(e),(this._config.openSidebar||this._config.annotations||this._config.query||this._config.group)&&this.open()})),
176
+ this._sidebarRPC.on("showHighlights",(()=>this.setHighlightsVisible(!0))),this._sidebarRPC.on("openSidebar",(()=>this.open())),this._sidebarRPC.on("closeSidebar",(()=>this.close())),this._sidebarRPC.on("openNotebook",(e=>{this.hide(),this._emitter.publish("openNotebook",e)})),this._sidebarRPC.on("openProfile",(()=>{this.hide(),this._emitter.publish("openProfile")})),this._emitter.subscribe("closeProfile",(()=>{this.show()})),this._emitter.subscribe("closeNotebook",(()=>{this.show()})),this._sidebarRPC.on("toastMessageAdded",(e=>{this._emitter.publish("toastMessageAdded",e)})),this._sidebarRPC.on("toastMessageDismissed",(e=>{this._emitter.publish("toastMessageDismissed",e)}));[["loginRequested",this.onLoginRequest],["logoutRequested",this.onLogoutRequest],["signupRequested",this.onSignupRequest],["profileRequested",this.onProfileRequest],["helpRequested",this.onHelpRequest]].forEach((([e,t])=>{t&&this._sidebarRPC.on(e,(()=>t()))}))}_resetDragResizeState(){this._dragResizeState={initial:null,final:null}}
177
+ _updateLayout(){this._renderFrame||(this._renderFrame=requestAnimationFrame((()=>{if(this._renderFrame=void 0,"number"==typeof this._dragResizeState.final&&this._dragResizeState.final!==this._dragResizeState.initial&&this.iframeContainer){const e=this._dragResizeState.final,t=-e;this.iframeContainer.style.marginLeft=`${e}px`,t>=280&&(this.iframeContainer.style.width=`${t}px`),this._updateLayoutState()}})))}_updateLayoutState(e){const t=this.iframeContainer&&this.toolbar.getWidth()||0,n=this.iframeContainer??this.externalFrame,{height:o}=n.getBoundingClientRect(),i=window.getComputedStyle(n),r=parseInt(i.width),s=parseInt(i.marginLeft);let a=t;"boolean"==typeof e?e&&(a+=r):(s<280?a-=s:a+=r,e=a>t);const l={expanded:e,width:e?a:t,height:o,toolbarWidth:t};this._layoutState=l,this.onLayoutChange?.(l),this._guestRPC.forEach((e=>e.call("sidebarLayoutChanged",l)))}_onResize(){!0===this.toolbar.sidebarOpen&&(window.innerWidth<280?this.close():this.open())}isResizing(){return null!==this._dragResizeState.initial}
178
178
  _onDragSidebarToggleButton(e){const t=this.iframeContainer;if(t)switch(e.type){case"dragstart":this._resetDragResizeState(),t.classList.add("sidebar-no-transition"),t.style.pointerEvents="none",this._dragResizeState.initial=parseInt(getComputedStyle(t).marginLeft);break;case"dragend":t.classList.remove("sidebar-no-transition"),t.style.pointerEvents="",null===this._dragResizeState.final||this._dragResizeState.final<=-280?this.open():this.close(),this._resetDragResizeState();break;case"dragmove":{if("number"!=typeof this._dragResizeState.initial)return;const t=this._dragResizeState.initial,n=e.deltaX;this._dragResizeState.final=Math.min(Math.round(t+n),0),this._updateLayout();break}}}open(){if(this._sidebarRPC.call("sidebarOpened"),this.iframeContainer){const e=this.iframeContainer.getBoundingClientRect().width;this.iframeContainer.style.marginLeft=-1*e+"px",this.iframeContainer.classList.remove("sidebar-collapsed")}this.toolbar.sidebarOpen=!0,
179
179
  "whenSidebarOpen"===this._config.showHighlights&&this.setHighlightsVisible(!0),this._updateLayoutState(!0)}close(){this._sidebarRPC.call("sidebarClosed"),this.iframeContainer&&(this.iframeContainer.style.marginLeft="",this.iframeContainer.classList.add("sidebar-collapsed")),this.toolbar.sidebarOpen=!1,"whenSidebarOpen"===this._config.showHighlights&&this.setHighlightsVisible(!1),this._updateLayoutState(!1)}setHighlightsVisible(e){this.toolbar.highlightsVisible=e,this._sidebarRPC.call("setHighlightsVisible",e)}show(){this.iframeContainer?.classList.remove("is-hidden")}hide(){this.iframeContainer?.classList.add("is-hidden")}}class ts{constructor(e){this._emitter=e,this._subscriptions=[]}publish(e,...t){this._emitter.emit(e,...t)}subscribe(e,t){this._emitter.on(e,t),this._subscriptions.push([e,t])}unsubscribe(e,t){this._emitter.off(e,t),this._subscriptions=this._subscriptions.filter((([n,o])=>n!==e||o!==t))}destroy(){for(const[e,t]of this._subscriptions)this._emitter.off(e,t);this._subscriptions=[]}}class ns{
180
180
  constructor(){this._emitter=new ln}createEmitter(){return new ts(this._emitter)}}const os=document.querySelector('link[type="application/annotator+html"][rel="sidebar"]');new Promise((e=>{"loading"!==document.readyState&&e(),document.addEventListener("readystatechange",(()=>e()))})).then((function(){const e=zn("annotator");let t=()=>{};const n=new Promise((e=>{t=e}));os.addEventListener("destroy",t);const o=e.subFrameIdentifier?window.parent:window,i=[];if(o===window){if(function(){const e=document.querySelectorAll(["hypothesis-sidebar","hypothesis-notebook","hypothesis-profile"].join(","));return e.forEach((e=>e.remove())),e.length>0}())return void console.warn("Hypothesis did not load because it found an existing instance on the page.");const e=function(e=navigator.userAgent){if(!bn(e))return()=>{};const t=e=>{if("hypothesisPortClosed"===e.data?.type&&e.ports[0]){const t=e.ports[0];_n(t,"close"),t.close()}};return window.addEventListener("message",t),()=>window.removeEventListener("message",t)}();i.push({