@webority/ui-elements 0.50.0 → 0.51.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.
@@ -16,9 +16,9 @@ ${r}
16
16
  html, body { margin: 0; padding: 0; }
17
17
  img { display: block; break-after: page; }
18
18
  img:last-child { break-after: auto; }
19
- </style></head><body>${i}</body></html>`}function da(e,t,n){let r=e.textContent,i=[],a=0;for(let{from:e,to:o,n:s}of t){e>a&&i.push(document.createTextNode(r.slice(a,e)));let t=document.createElement(`mark`);t.className=s===n?`wui-file-viewer-hit wui-file-viewer-hit-current`:`wui-file-viewer-hit`,t.textContent=r.slice(e,o),i.push(t),a=o}a<r.length&&i.push(document.createTextNode(r.slice(a))),e.replaceChildren(...i)}function fa(e){let t=[...e].sort((e,t)=>e-t);return t[Math.floor(t.length/2)]}var pa,ma,ha,ga,_a,va,ya,ba,xa,Sa,Ca,wa,Ta,Ea,Da,Oa,ka,Aa,ja,Ma,Na=n((()=>{Xi(),Qi(),aa(),_(),f(),pa=[.5,.75,1,1.25,1.5,2,3],ma=[.5,.75,1,1.25,1.5,2],ha=[{key:`fit-width`,label:`Fit width`},{key:`fit-page`,label:`Fit page`}],ga=96/72,_a=12,va=10,ya=168,ba=150,xa=2,Sa=2e3,Ca=5,wa=150,Ta=16777216,Ea=null,Da=e=>{if(ha.some(t=>t.key===e))return e;let t=Number(e);return pa.includes(t)?t:`fit-width`},Oa=e=>e instanceof Element&&e.closest(`input, textarea, select, [contenteditable='true'], .dropdown-menu`),ka=e=>/^(https?:|mailto:)/i.test(e),Aa=class{constructor(e,t){this.shell=e,this.source=t;let n=e.prefs;this.zoom=Da(n.zoom),this.twoPage=n.twoPage===!0,this.showThumbs=n.thumbnails===!0,this.pdf=null,this.sizes=[],this.rows=[],this.rowOf=[],this.scale=0,this.drawnScale=0,this.pages=new Map,this.thumbsDrawn=new Set,this.area={width:0,height:0},this.scrollPos={top:0,left:0},this.jumpTarget=null,this.search={open:!1,query:``,index:null,indexing:!1,hits:[],current:-1,marked:new Map},this.printRun=null,this.destroyed=!1,this._timers=new Set}load(){return this._loading=this._load(),this._loading}async _load(){sa(this.source.workerSrc),this.task=nt({url:this.source.src,...ca(this.source.assetBase)});let e;try{e=await this.task.promise}catch(e){this.destroyed||this.shell.fail(e);return}if(this.destroyed){e.destroy();return}this.pdf=e;let t=await Promise.all(Array.from({length:e.numPages},(t,n)=>e.getPage(n+1)));this.destroyed||(this.sizes=t.map(e=>{let t=e.getViewport({scale:ga});return{width:t.width,height:t.height}}),this._buildToolbar(),this._buildBody(),this._layout(),this.shell.loaded({kind:`pdf`,pages:e.numPages}))}destroy(){this.destroyed=!0;for(let e of this._timers)window.clearTimeout(e);window.cancelAnimationFrame(this._scrollFrame),this._resizeObserver?.disconnect(),this._onKeyDown&&this.shell.host.removeEventListener(`keydown`,this._onKeyDown),this._thumbObserver?.disconnect();for(let e of[...this.pages.keys()])this._release(e);this._releasePrint();let e=this.task;e&&(this._loading??Promise.resolve()).catch(()=>{}).finally(()=>e.destroy())}_buildToolbar(){let{start:e,center:t,end:n,host:r}=this.shell;this.thumbsButton=p(`menu`,``,{size:17}),this.thumbsButton.addEventListener(`click`,()=>this._setThumbs(!this.showThumbs)),e.prepend(this.thumbsButton),this.prevButton=p(`chevron-up`,`Previous page`),this.prevButton.addEventListener(`click`,()=>this.goToPage(this.current()-this.cols()));let i=document.createElement(`span`);i.className=`wui-file-viewer-page`,this.pageInput=document.createElement(`input`),this.pageInput.className=`wui-file-viewer-page-input`,this.pageInput.setAttribute(`aria-label`,`Page number`),this.pageInput.inputMode=`numeric`,this.pageInput.addEventListener(`input`,()=>{this.pageInput.value=this.pageInput.value.replace(/[^\d]/g,``)}),this.pageInput.addEventListener(`keydown`,e=>{e.key===`Enter`&&this.pageInput.blur()}),this.pageInput.addEventListener(`blur`,()=>this._commitPageInput());let a=document.createElement(`span`);a.className=`wui-file-viewer-page-total`,a.textContent=`/ ${this.pdf.numPages}`,i.append(this.pageInput,a),this.nextButton=p(`chevron-down`,`Next page`),this.nextButton.addEventListener(`click`,()=>this.goToPage(this.current()+this.cols())),t.append(this.prevButton,i,this.nextButton),this.searchButton=p(`search`,`Search the document`,{className:`wui-file-viewer-search-toggle`}),this.searchButton.setAttribute(`aria-controls`,`${r.uid}-search`),this.searchButton.addEventListener(`click`,()=>this.search.open?this._closeSearch():this._openSearch()),this.zoomOutButton=p(`zoom-out`,`Zoom out`),this.zoomOutButton.addEventListener(`click`,()=>this._stepZoom(-1)),this.zoomButton=document.createElement(`button`),this.zoomButton.type=`button`,this.zoomButton.className=`wui-file-viewer-zoom`,g(this.zoomButton,{label:`Zoom`,items:()=>[...ma.map(e=>({key:String(e),label:`${Math.round(e*100)}%`,checked:this.zoom===e})),{key:`fit-divider`,divider:!0},...ha.map(e=>({key:e.key,label:e.label,checked:this.zoom===e.key}))],onPick:e=>this._setZoom(Da(e))}),this.zoomInButton=p(`zoom-in`,`Zoom in`),this.zoomInButton.addEventListener(`click`,()=>this._stepZoom(1));let o=document.createElement(`span`);o.className=`wui-file-viewer-divider`,this.twoPageButton=p(`two-page`,`Two-page view`),this.twoPageButton.addEventListener(`click`,()=>this._setTwoPage(!this.twoPage)),this.printButton=p(`printer`,`Print`),this.printButton.addEventListener(`click`,()=>this.print()),n.prepend(this.searchButton,this.zoomOutButton,this.zoomButton,this.zoomInButton,o,this.twoPageButton,this.printButton),this._buildSearchRow(),this._syncToolbar()}_buildSearchRow(){let e=this.shell.search;e.id=`${this.shell.host.uid}-search`;let t=document.createElement(`div`);t.className=`wui-file-viewer-search-field`,this.searchInput=document.createElement(`input`),this.searchInput.type=`search`,this.searchInput.className=`form-control form-control-sm`,this.searchInput.placeholder=`Search the document`,this.searchInput.setAttribute(`aria-label`,`Search the document`),this.searchInput.addEventListener(`input`,()=>this._setQuery(this.searchInput.value)),this.searchInput.addEventListener(`keydown`,e=>{e.key===`Enter`?(e.preventDefault(),this._goToHit(this.search.current+(e.shiftKey?-1:1))):e.key===`Escape`&&(e.preventDefault(),this._closeSearch())}),t.append(this.searchInput),this.searchStatus=document.createElement(`span`),this.searchStatus.className=`wui-file-viewer-search-count`,this.searchStatus.setAttribute(`aria-live`,`polite`),this.prevHitButton=p(`chevron-up`,`Previous match`),this.prevHitButton.addEventListener(`click`,()=>this._goToHit(this.search.current-1)),this.nextHitButton=p(`chevron-down`,`Next match`),this.nextHitButton.addEventListener(`click`,()=>this._goToHit(this.search.current+1));let n=p(`x`,`Close search`);n.addEventListener(`click`,()=>this._closeSearch()),e.append(t,this.searchStatus,this.prevHitButton,this.nextHitButton,n)}_syncToolbar(){let e=this.current(),t=this.rows.length-1;document.activeElement!==this.pageInput&&(this.pageInput.value=String(e)),this.prevButton.disabled=e<=1,this.nextButton.disabled=(this.rowOf[e]??0)>=t,this.zoomOutButton.disabled=this._zoomStep(-1)==null,this.zoomInButton.disabled=this._zoomStep(1)==null;let n=Math.round((this.scale||1)*100);this._shownPercent!==n&&(this._shownPercent=n,this.zoomButton.innerHTML=`${n}%${u(`chevron-down`,{size:12})}`,this.zoomButton.setAttribute(`aria-label`,`Zoom, ${n}%`)),h(this.thumbsButton,this.showThumbs?`Hide thumbnails`:`Show thumbnails`),this.thumbsButton.setAttribute(`aria-pressed`,String(this.showThumbs)),this.twoPageButton.setAttribute(`aria-pressed`,String(this.twoPage)),this.printButton.disabled=this.printRun!=null&&!this.printRun.ready,h(this.printButton,this.printButton.disabled?`Preparing to print`:`Print`),h(this.searchButton,this.search.open?`Close search`:`Search the document`),this.searchButton.setAttribute(`aria-expanded`,String(this.search.open)),this._syncSearchStatus()}_buildBody(){let e=this.shell.body;this.thumbRail=document.createElement(`div`),this.thumbRail.className=`wui-file-viewer-thumbs wui-scroll${this.showThumbs?` open`:``}`,this.scroller=document.createElement(`div`),this.scroller.className=`wui-file-viewer-scroll wui-scroll`,this.scroller.tabIndex=0,this.scroller.setAttribute(`role`,`region`),this.scroller.setAttribute(`aria-label`,`Document pages`),this.pagesEl=document.createElement(`div`),this.pagesEl.className=`wui-file-viewer-pages`,this.scroller.append(this.pagesEl),e.replaceChildren(this.thumbRail,this.scroller),this.pageEls=[];for(let e=1;e<=this.pdf.numPages;e++){let t=document.createElement(`div`);t.className=`wui-file-viewer-sheet`,t.dataset.page=String(e),this.pageEls[e]=t}this.showThumbs&&this._buildThumbs(),this.scroller.addEventListener(`scroll`,()=>this._onScroll(),{passive:!0}),this.scroller.addEventListener(`pointerdown`,e=>this._panStart(e)),this.scroller.addEventListener(`pointermove`,e=>this._panMove(e));for(let e of[`pointerup`,`pointercancel`,`lostpointercapture`])this.scroller.addEventListener(e,()=>this._panEnd());this.scroller.addEventListener(`wheel`,e=>{if(!e.ctrlKey&&!e.metaKey)return;e.preventDefault();let t=performance.now();t-(this._lastWheelZoom??0)<120||(this._lastWheelZoom=t,this._stepZoom(e.deltaY<0?1:-1))},{passive:!1}),this._onKeyDown=e=>this._keyDown(e),this.shell.host.addEventListener(`keydown`,this._onKeyDown),this._resizeObserver=new ResizeObserver(()=>{let e=this.scroller.clientWidth,t=this.scroller.clientHeight;e===this.area.width&&t===this.area.height||(this.area={width:e,height:t},this._layout())}),this._resizeObserver.observe(this.scroller),this.area={width:this.scroller.clientWidth,height:this.scroller.clientHeight}}cols(){return this.twoPage?2:1}_targetScale(){if(typeof this.zoom==`number`)return this.zoom;let e=this.cols(),t=fa(this.sizes.map(e=>e.width)),n=fa(this.sizes.map(e=>e.height)),r=(this.area.width-2*_a-(e-1)*va)/(t*e);return this.zoom===`fit-page`&&(r=Math.min(r,(this.area.height-2*_a)/n)),Math.max(r,.1)}_layout(){if(!this.pdf||!this.area.width)return;let e=this._anchor();this.scale=this._targetScale();let t=this.cols();this.rows=[],this.rowOf=[];let n=_a,r=document.createDocumentFragment();for(let e=1;e<=this.pdf.numPages;e+=t){let i=[];for(let n=e;n<e+t&&n<=this.pdf.numPages;n++)i.push(n);let a=document.createElement(`div`);a.className=`wui-file-viewer-row`;let o=0;for(let e of i){let{width:t,height:n}=this.sizes[e-1],r=this.pageEls[e];r.style.width=`${Math.floor(t*this.scale)}px`,r.style.height=`${Math.floor(n*this.scale)}px`,r.style.setProperty(`--scale-factor`,String(this.scale*ga)),o=Math.max(o,Math.floor(n*this.scale)),a.append(r),this.rowOf[e]=this.rows.length}this.rows.push({pages:i,top:n,height:o}),n+=o+va,r.append(a)}let i=this.scroller.scrollWidth;this.pagesEl.replaceChildren(r),this._restore(e,i),this._scheduleRedraw(),this._update()}_anchor(){if(!this.rows.length)return null;let e=this._rowAt(this.scrollPos.top),t=this.rows[e];return{page:t.pages[0],within:(this.scrollPos.top-t.top)/Math.max(t.height+va,1),left:this.scrollPos.left}}_restore(e,t){let n=this.scroller;if(e){let r=this.rows[this.rowOf[e.page]];n.scrollTop=r.top+e.within*(r.height+va),n.scrollLeft=(t?(e.left+n.clientWidth/2)/t:.5)*n.scrollWidth-n.clientWidth/2}this.scrollPos={top:n.scrollTop,left:n.scrollLeft}}_rowAt(e){let t=0,n=this.rows.length-1;for(;t<n;){let r=t+n+1>>1;this.rows[r].top<=e+1?t=r:n=r-1}return t}current(){if(this.jumpTarget!=null)return this.jumpTarget;if(!this.rows.length)return 1;let e=this.scrollPos.top,t=e+this.area.height,n=this._rowAt(e),r=-1;for(let i=n;i<this.rows.length&&this.rows[i].top<t;i++){let{top:a,height:o}=this.rows[i],s=Math.min(a+o,t)-Math.max(a,e);s>r&&(r=s,n=i)}return this.rows[n].pages[0]}_onScroll(){this.scrollPos={top:this.scroller.scrollTop,left:this.scroller.scrollLeft},window.cancelAnimationFrame(this._scrollFrame),this._scrollFrame=window.requestAnimationFrame(()=>this._update())}_update(){if(!this.rows.length||this.destroyed)return;let e=Math.max(0,this._rowAt(this.scrollPos.top)-xa),t=Math.min(this.rows.length-1,this._rowAt(this.scrollPos.top+this.area.height)+xa),n=new Set;for(let r=e;r<=t;r++)for(let e of this.rows[r].pages)n.add(e);for(let e of[...this.pages.keys()])n.has(e)||this._release(e);this.visibleRow=this._rowAt(this.scrollPos.top);for(let e of n)this.pages.has(e)||this._mount(e);this._pump(),this._syncToolbar(),this.showThumbs&&this._followThumb()}_scheduleRedraw(){if(this.scale===this.drawnScale)return;window.clearTimeout(this._redrawTimer),this._timers.delete(this._redrawTimer);let e=this.drawnScale?ba:0;this._redrawTimer=window.setTimeout(()=>{this._timers.delete(this._redrawTimer),this.drawnScale=this.scale,this._pump()},e),this._timers.add(this._redrawTimer)}_mount(e){let t=this.pageEls[e],n={n:e,drawnAt:0,task:null,canvas:null,text:null,textLayer:null,links:null};this.pages.set(e,n);let r=document.createElement(`div`);r.className=`wui-file-viewer-skeleton`,t.replaceChildren(r),this._drawText(n),this._drawLinks(n)}_release(e){let t=this.pages.get(e);t&&(t.released=!0,t.task?.cancel(),t.textLayer?.cancel(),t.canvas&&(t.canvas.width=0,t.canvas.height=0),this.pages.delete(e),this.search.marked.delete(e),this.pageEls[e].replaceChildren())}_pump(){if(this._drawing||!this.drawnScale||this.destroyed)return;let e=this.visibleRow??0,t=null,n=1/0;for(let r of this.pages.values()){if(r.drawnAt===this.drawnScale)continue;let i=Math.abs(this.rowOf[r.n]-e);i<n&&(n=i,t=r)}t&&(this._drawing=!0,this._drawCanvas(t).finally(()=>{this._drawing=!1,this._pump()}))}async _drawCanvas(e){let t=this.drawnScale,n=await this.pdf.getPage(e.n);if(e.released||this.destroyed)return;let r=n.getViewport({scale:t*ga}),i=window.devicePixelRatio||1,a=Math.sqrt(Ta/(r.width*r.height)),o=Math.min(i,a),s=document.createElement(`canvas`);s.className=`wui-file-viewer-canvas`,s.width=Math.floor(r.width*o),s.height=Math.floor(r.height*o),s.setAttribute(`aria-hidden`,`true`),e.task=n.render({canvas:s,viewport:r,transform:o===1?null:[o,0,0,o,0,0]});try{await e.task.promise}catch(e){s.width=0,s.height=0,e?.name!==`RenderingCancelledException`&&this._warn(`page draw failed`,e);return}finally{e.task=null}if(e.released||this.destroyed){s.width=0,s.height=0;return}let c=this.pageEls[e.n];e.canvas?(e.canvas.replaceWith(s),e.canvas.width=0,e.canvas.height=0):(c.querySelector(`.wui-file-viewer-skeleton`)?.remove(),c.prepend(s)),e.canvas=s,e.drawnAt=t,this.showThumbs&&!this.thumbsDrawn.has(e.n)&&this._thumbFromCanvas(e.n,s)}async _drawText(e){let t=await this.pdf.getPage(e.n);if(e.released||this.destroyed)return;let n=document.createElement(`div`);n.className=`wui-file-viewer-text`,e.text=n,e.textLayer=new jr({textContentSource:t.streamTextContent({includeMarkedContent:!0,disableNormalization:!0}),container:n,viewport:t.getViewport({scale:this.scale*ga})});try{await e.textLayer.render()}catch(e){e?.name!==`AbortException`&&this._warn(`text layer failed`,e);return}e.released||this.destroyed||(this.pageEls[e.n].append(n),this._markPage(e.n),this._revealHit(e.n))}async _drawLinks(e){let t=await this.pdf.getPage(e.n),n=await t.getAnnotations({intent:`display`});if(e.released||this.destroyed)return;let r=n.filter(e=>e.subtype===`Link`&&(e.dest||e.url&&ka(e.url))),i=(await Promise.all(r.map(async e=>e.url?{link:e}:{link:e,target:await this._destPage(e.dest)}))).filter(({link:e,target:t})=>e.url||t);if(!i.length||e.released||this.destroyed)return;let a=t.getViewport({scale:1}),o=document.createElement(`div`);o.className=`wui-file-viewer-links`;for(let{link:e,target:t}of i){let[n,r,i,s]=a.convertToViewportRectangle(e.rect),c=document.createElement(`a`);c.style.left=`${Math.min(n,i)/a.width*100}%`,c.style.top=`${Math.min(r,s)/a.height*100}%`,c.style.width=`${Math.abs(i-n)/a.width*100}%`,c.style.height=`${Math.abs(s-r)/a.height*100}%`,e.url?(c.href=e.url,c.target=`_blank`,c.rel=`noopener noreferrer`,c.title=e.url,c.setAttribute(`aria-label`,e.url)):(c.href=`#page=${t}`,c.setAttribute(`aria-label`,`Go to page ${t}`),c.addEventListener(`click`,e=>{e.preventDefault(),this.goToPage(t)})),o.append(c)}e.links=o,this.pageEls[e.n].append(o)}async _destPage(e){try{let t=(typeof e==`string`?await this.pdf.getDestination(e):e)?.[0];return t==null?null:(typeof t==`object`?await this.pdf.getPageIndex(t):t)+1}catch(e){return this._warn(`link target not found`,e),null}}goToPage(e){let t=Math.min(Math.max(1,e),this.pdf.numPages),n=Math.min(this.rows[this.rowOf[t]].top-_a,this.scroller.scrollHeight-this.scroller.clientHeight);window.clearTimeout(this._jumpTimer),this.scroller.removeEventListener(`scrollend`,this._endJump),this._endJump=()=>{window.clearTimeout(this._jumpTimer),this.scroller.removeEventListener(`scrollend`,this._endJump),this.jumpTarget=null,this._syncToolbar()},Math.abs(n-this.scroller.scrollTop)>=1&&(this.jumpTarget=t,this.scroller.addEventListener(`scrollend`,this._endJump),this._jumpTimer=window.setTimeout(this._endJump,Sa),this._timers.add(this._jumpTimer),this.scroller.scrollTo({top:n,behavior:Ma()})),this._syncToolbar()}_commitPageInput(){let e=Number.parseInt(this.pageInput.value,10);Number.isNaN(e)?this.pageInput.value=String(this.current()):this.goToPage(e)}_zoomStep(e){let t=this.scale||1;return e>0?pa.find(e=>e>t+.001)??null:[...pa].reverse().find(e=>e<t-.001)??null}_stepZoom(e){let t=this._zoomStep(e);t!=null&&this._setZoom(t)}_setZoom(e){this.zoom=e,this.shell.savePrefs({zoom:String(e)}),this._layout()}_setTwoPage(e){this.twoPage=e,this.shell.savePrefs({twoPage:e}),this._layout()}_setThumbs(e){this.showThumbs=e,this.shell.savePrefs({thumbnails:e}),this.thumbRail.classList.toggle(`open`,e),e&&!this.thumbRail.childElementCount&&this._buildThumbs(),this._syncToolbar(),e&&(this._activeThumb=null,this._followThumb())}_buildThumbs(){this.thumbEls=[],this._thumbObserver=new IntersectionObserver(e=>{for(let t of e)t.isIntersecting&&this._drawThumb(Number(t.target.dataset.page))},{root:this.thumbRail,rootMargin:`200px 0px`});for(let e=1;e<=this.pdf.numPages;e++){let t=document.createElement(`button`);t.type=`button`,t.className=`wui-file-viewer-thumb`,t.dataset.page=String(e),t.setAttribute(`aria-label`,`Go to page ${e}`);let{width:n,height:r}=this.sizes[e-1],i=document.createElement(`span`);i.className=`wui-file-viewer-thumb-frame`,i.style.aspectRatio=`${n} / ${r}`;let a=document.createElement(`span`);a.className=`wui-file-viewer-thumb-no`,a.textContent=String(e),t.append(i,a),t.addEventListener(`click`,()=>this.goToPage(e)),this.thumbRail.append(t),this.thumbEls[e]=t,this._thumbObserver.observe(t)}}async _drawThumb(e){if(this.thumbsDrawn.has(e))return;this.thumbsDrawn.add(e);let t=this.pages.get(e)?.canvas;if(t){this._thumbFromCanvas(e,t);return}let n=await this.pdf.getPage(e);if(this.destroyed)return;let r=window.devicePixelRatio||1,i=n.getViewport({scale:ya*r/n.getViewport({scale:1}).width}),a=document.createElement(`canvas`);a.width=Math.floor(i.width),a.height=Math.floor(i.height);try{await n.render({canvas:a,viewport:i}).promise}catch(t){this.thumbsDrawn.delete(e),t?.name!==`RenderingCancelledException`&&this._warn(`thumbnail draw failed`,t);return}this._setThumbImage(e,a)}_thumbFromCanvas(e,t){this.thumbsDrawn.add(e);let n=window.devicePixelRatio||1,r=document.createElement(`canvas`);r.width=Math.floor(ya*n),r.height=Math.floor(r.width*t.height/t.width),r.getContext(`2d`)?.drawImage(t,0,0,r.width,r.height),this._setThumbImage(e,r)}_setThumbImage(e,t){let n=this.thumbEls?.[e]?.querySelector(`.wui-file-viewer-thumb-frame`);n&&(t.setAttribute(`aria-hidden`,`true`),n.replaceChildren(t))}_followThumb(){let e=this.current();e===this._activeThumb||!this.thumbEls||(this.thumbEls[this._activeThumb]?.classList.remove(`active`),this._activeThumb=e,this.thumbEls[e]?.classList.add(`active`),this.thumbEls[e]?.scrollIntoView({behavior:Ma(),block:`nearest`}))}_openSearch(){this.search.open=!0,this.shell.search.hidden=!1,this._syncToolbar(),this.searchInput.focus(),this.searchInput.select(),!this.search.index&&!this.search.indexing&&(this.search.indexing=!0,this._syncSearchStatus(),ea(this.pdf).then(e=>{this.search.index=e}).catch(e=>{this._warn(`text index failed`,e),this.search.index=!1}).finally(()=>{this.search.indexing=!1,this.destroyed||this._setQuery(this.search.query)}))}_closeSearch(){this.search.open=!1,this.shell.search.hidden=!0,this._applyHits([],-1),this._syncToolbar(),this.searchButton.focus()}_setQuery(e){this.search.query=e;let t=this.search.index?na(this.search.index,e):[],n=this.current(),r=t.findIndex(e=>e.page>=n);this._applyHits(t,t.length?Math.max(r,0):-1),this._revealPending=t.length>0,t.length&&this._bringHitIntoView()}_goToHit(e){let{hits:t}=this.search;t.length&&(this._applyHits(t,(e+t.length)%t.length),this._revealPending=!0,this._bringHitIntoView())}_applyHits(e,t){let n=e!==this.search.hits,r=this.search;this.search={...r,hits:e,current:t},n&&(this.search.byPage=new Map,e.forEach((e,t)=>{this.search.byPage.has(e.page)||this.search.byPage.set(e.page,[]),this.search.byPage.get(e.page).push({...e,n:t})}));let i=n?new Set([...r.marked.keys(),...this.search.byPage.keys()]):new Set([r.hits[r.current]?.page,e[t]?.page].filter(Boolean));for(let e of i)this._markPage(e);this._syncSearchStatus()}_markPage(e){let t=this.pages.get(e),n=t?.textLayer?.textDivs;if(!n||!t.text?.isConnected)return;let r=this.search.index?.[e-1]?.items,i=this.search.open?this.search.byPage?.get(e)??[]:[],a=this.search.marked.get(e)??new Set,o=new Set;r&&i.length&&r.forEach((e,t)=>{let r=ra(e,i);!r.length||!n[t]||(o.add(t),da(n[t],r,this.search.current))});for(let e of a)!o.has(e)&&n[e]&&n[e].replaceChildren(n[e].textContent);o.size?this.search.marked.set(e,o):this.search.marked.delete(e)}_bringHitIntoView(){let e=this.search.hits[this.search.current];if(!e)return;let t=this.rows[this.rowOf[e.page]],n=this.scrollPos.top;(t.top+t.height<n||t.top>n+this.area.height)&&(this.scroller.scrollTop=t.top-_a),this._revealHit(e.page)}_revealHit(e){let t=this.search.hits[this.search.current];if(!this._revealPending||!t||t.page!==e)return;let n=this.pageEls[e].querySelector(`.wui-file-viewer-hit-current`);if(!n)return;this._revealPending=!1;let r=this.scroller.getBoundingClientRect(),i=n.getBoundingClientRect();(i.top<r.top||i.bottom>r.bottom)&&(this.scroller.scrollTop+=i.top-r.top-this.scroller.clientHeight/2),(i.left<r.left||i.right>r.right)&&(this.scroller.scrollLeft+=i.left-r.left-this.scroller.clientWidth/2)}_syncSearchStatus(){this.searchStatus&&(this.searchStatus.textContent=$i(this.search),this.prevHitButton.disabled=!this.search.hits.length,this.nextHitButton.disabled=!this.search.hits.length)}_keyDown(e){if(e.defaultPrevented||e.altKey)return;if(e.ctrlKey||e.metaKey){if(e.key===`f`||e.key===`F`)this._openSearch();else if(e.key===`+`||e.key===`=`)this._stepZoom(1);else if(e.key===`-`||e.key===`_`)this._stepZoom(-1);else if(e.key===`0`)this._setZoom(`fit-width`);else return;e.preventDefault();return}if(e.shiftKey||Oa(e.target))return;let t=this.cols();if(e.key===`PageDown`)this.goToPage(this.current()+t);else if(e.key===`PageUp`)this.goToPage(this.current()-t);else if(e.key===`Home`)this.goToPage(1);else if(e.key===`End`)this.goToPage(this.pdf.numPages);else return;e.preventDefault()}_panStart(e){let t=this.scroller;e.button!==0||t.scrollWidth<=t.clientWidth&&t.scrollHeight<=t.clientHeight||e.target instanceof Element&&e.target.closest(`a`)||(this._pan={id:e.pointerId,x:e.clientX,y:e.clientY,left:t.scrollLeft,top:t.scrollTop,active:!1})}_panMove(e){let t=this._pan;if(!t)return;let n=e.clientX-t.x,r=e.clientY-t.y;if(!t.active){if(Math.abs(n)<Ca&&Math.abs(r)<Ca)return;t.active=!0,this.scroller.setPointerCapture(t.id),this.scroller.classList.add(`wui-file-viewer-panning`)}this.scroller.scrollLeft=t.left-n,this.scroller.scrollTop=t.top-r}_panEnd(){let e=this._pan;e?.active&&(this.scroller.hasPointerCapture(e.id)&&this.scroller.releasePointerCapture(e.id),this.scroller.classList.remove(`wui-file-viewer-panning`)),this._pan=null}async print(){this._releasePrint();let e={ready:!1,urls:[]};this.printRun=e,this._syncToolbar();try{let t=[];for(let n=1;n<=this.pdf.numPages;n++){let r=await this.pdf.getPage(n),i=r.getViewport({scale:wa/72}),a=document.createElement(`canvas`);a.width=Math.floor(i.width),a.height=Math.floor(i.height),await r.render({canvas:a,viewport:i,intent:`print`}).promise;let o=await new Promise((e,t)=>a.toBlob(n=>n?e(n):t(Error(`Page image failed`)),`image/png`));a.width=0,a.height=0;let s=URL.createObjectURL(o);if(e.urls.push(s),t.push({url:s,width:i.width/wa*25.4,height:i.height/wa*25.4}),this.printRun!==e)throw new DOMException(`Print replaced`,`AbortError`)}let n=document.createElement(`iframe`);n.className=`wui-file-viewer-print-frame`,n.title=`Document for printing`,n.tabIndex=-1,n.setAttribute(`aria-hidden`,`true`),e.frame=n,n.srcdoc=ua(this.shell.name(),t),n.addEventListener(`load`,()=>{if(this.printRun===e){e.ready=!0,this._syncToolbar();try{n.contentWindow.addEventListener(`afterprint`,()=>{this.printRun===e&&this._releasePrint()},{once:!0}),n.contentWindow.focus(),n.contentWindow.print()}catch(e){this._printFallback(e)}}},{once:!0}),document.body.append(n)}catch(t){if(this.printRun!==e){for(let t of e.urls)URL.revokeObjectURL(t);return}this._printFallback(t)}}_printFallback(e){this._releasePrint(),this._warn(`print failed`,e),window.open(this.source.src,`_blank`,`noopener`)}_releasePrint(){let e=this.printRun;if(this.printRun=null,e){e.frame?.remove();for(let t of e.urls)URL.revokeObjectURL(t)}this.printButton&&this._syncToolbar()}_warn(e,t){console.warn(`[wui-file-viewer] ${e}:`,t?.message??t)}},ja=e=>String(e??``).replace(/&/g,`&amp;`).replace(/</g,`&lt;`).replace(/>/g,`&gt;`),Ma=()=>window.matchMedia?.(`(prefers-reduced-motion: reduce)`).matches?`auto`:`smooth`})),Pa=r({ImageView:()=>za}),Fa,Ia,La,Ra,za,Ba,Va=n((()=>{_(),f(),Fa=[.1,.25,.5,.75,1,1.5,2,3,4],Ia=[.25,.5,1,2,4],La=16,Ra=5,za=class{constructor(e,t){this.shell=e,this.source=t,this.zoom=`fit`,this.rotation=0,this.area={width:0,height:0},this.destroyed=!1}load(){let e=document.createElement(`img`);e.className=`wui-file-viewer-image`,e.alt=this.shell.name(),e.decoding=`async`,e.draggable=!1,e.addEventListener(`load`,()=>{this.destroyed||(this.natural={width:e.naturalWidth||300,height:e.naturalHeight||150},this._build(e),this.shell.loaded({kind:`image`,pages:1}))}),e.addEventListener(`error`,()=>{this.destroyed||this.shell.fail(Error(`The image could not be decoded.`))}),e.src=this.source.src,this.img=e}destroy(){this.destroyed=!0,this._resizeObserver?.disconnect(),this._onKeyDown&&this.shell.host.removeEventListener(`keydown`,this._onKeyDown),this._printFrame?.remove(),this.img?.removeAttribute(`src`)}_build(e){let{center:t,end:n,body:r,host:i}=this.shell;this.zoomOutButton=p(`zoom-out`,`Zoom out`),this.zoomOutButton.addEventListener(`click`,()=>this._stepZoom(-1)),this.zoomButton=document.createElement(`button`),this.zoomButton.type=`button`,this.zoomButton.className=`wui-file-viewer-zoom`,g(this.zoomButton,{label:`Zoom`,items:()=>[...Ia.map(e=>({key:String(e),label:`${Math.round(e*100)}%`,checked:this.zoom===e})),{key:`fit-divider`,divider:!0},{key:`fit`,label:`Fit`,checked:this.zoom===`fit`}],onPick:e=>this._setZoom(e===`fit`?`fit`:Number(e))}),this.zoomInButton=p(`zoom-in`,`Zoom in`),this.zoomInButton.addEventListener(`click`,()=>this._stepZoom(1));let a=p(`rotate-ccw`,`Rotate left`);a.addEventListener(`click`,()=>this._rotate(-90));let o=p(`rotate-cw`,`Rotate right`);o.addEventListener(`click`,()=>this._rotate(90));let s=document.createElement(`span`);s.className=`wui-file-viewer-divider`;let c=p(`printer`,`Print`);c.addEventListener(`click`,()=>this.print()),t.append(this.zoomOutButton,this.zoomButton,this.zoomInButton),n.prepend(a,o,s,c),this.scroller=document.createElement(`div`),this.scroller.className=`wui-file-viewer-scroll wui-file-viewer-image-scroll wui-scroll`,this.scroller.tabIndex=0,this.scroller.setAttribute(`role`,`region`),this.scroller.setAttribute(`aria-label`,`Image`),this.stage=document.createElement(`div`),this.stage.className=`wui-file-viewer-image-stage`,this.stage.append(e),this.scroller.append(this.stage),r.replaceChildren(this.scroller),this.scroller.addEventListener(`pointerdown`,e=>this._panStart(e)),this.scroller.addEventListener(`pointermove`,e=>this._panMove(e));for(let e of[`pointerup`,`pointercancel`,`lostpointercapture`])this.scroller.addEventListener(e,()=>this._panEnd());this.scroller.addEventListener(`wheel`,e=>{if(!e.ctrlKey&&!e.metaKey)return;e.preventDefault();let t=performance.now();t-(this._lastWheelZoom??0)<120||(this._lastWheelZoom=t,this._stepZoom(e.deltaY<0?1:-1))},{passive:!1}),this._onKeyDown=e=>this._keyDown(e),i.addEventListener(`keydown`,this._onKeyDown),this._resizeObserver=new ResizeObserver(()=>{let e=this.scroller.clientWidth,t=this.scroller.clientHeight;e===this.area.width&&t===this.area.height||(this.area={width:e,height:t},this._layout())}),this._resizeObserver.observe(this.scroller),this.area={width:this.scroller.clientWidth,height:this.scroller.clientHeight},this._layout()}_turned(){let{width:e,height:t}=this.natural;return this.rotation%180==0?{width:e,height:t}:{width:t,height:e}}scale(){if(typeof this.zoom==`number`)return this.zoom;let{width:e,height:t}=this._turned(),n=Math.min((this.area.width-2*La)/e,(this.area.height-2*La)/t);return Math.max(Math.min(1,n),.01)}_layout(){if(!this.stage)return;let e=this.scale(),t=this._turned();this.stage.style.width=`${Math.round(t.width*e)}px`,this.stage.style.height=`${Math.round(t.height*e)}px`,this.img.style.width=`${Math.round(this.natural.width*e)}px`,this.img.style.height=`${Math.round(this.natural.height*e)}px`,this.img.style.transform=`translate(-50%, -50%) rotate(${this.rotation}deg)`;let n=Math.round(e*100);this.zoomButton.innerHTML=`${n}%${u(`chevron-down`,{size:12})}`,this.zoomButton.setAttribute(`aria-label`,`Zoom, ${n}%`),this.zoomOutButton.disabled=this._zoomStep(-1)==null,this.zoomInButton.disabled=this._zoomStep(1)==null}_zoomStep(e){let t=this.scale();return e>0?Fa.find(e=>e>t+.001)??null:[...Fa].reverse().find(e=>e<t-.001)??null}_stepZoom(e){let t=this._zoomStep(e);t!=null&&this._setZoom(t)}_setZoom(e){let t=this.scroller,n=(t.scrollLeft+t.clientWidth/2)/Math.max(t.scrollWidth,1),r=(t.scrollTop+t.clientHeight/2)/Math.max(t.scrollHeight,1);this.zoom=e,this._layout(),t.scrollLeft=n*t.scrollWidth-t.clientWidth/2,t.scrollTop=r*t.scrollHeight-t.clientHeight/2}_rotate(e){this.rotation=(this.rotation+e+360)%360,this._setZoom(this.zoom)}_keyDown(e){if(!(e.defaultPrevented||e.altKey||!(e.ctrlKey||e.metaKey))){if(e.key===`+`||e.key===`=`)this._stepZoom(1);else if(e.key===`-`||e.key===`_`)this._stepZoom(-1);else if(e.key===`0`)this._setZoom(`fit`);else return;e.preventDefault()}}_panStart(e){let t=this.scroller;e.button!==0||t.scrollWidth<=t.clientWidth&&t.scrollHeight<=t.clientHeight||(this._pan={id:e.pointerId,x:e.clientX,y:e.clientY,left:t.scrollLeft,top:t.scrollTop,active:!1})}_panMove(e){let t=this._pan;if(!t)return;let n=e.clientX-t.x,r=e.clientY-t.y;if(!t.active){if(Math.abs(n)<Ra&&Math.abs(r)<Ra)return;t.active=!0,this.scroller.setPointerCapture(t.id),this.scroller.classList.add(`wui-file-viewer-panning`)}this.scroller.scrollLeft=t.left-n,this.scroller.scrollTop=t.top-r}_panEnd(){let e=this._pan;e?.active&&(this.scroller.hasPointerCapture(e.id)&&this.scroller.releasePointerCapture(e.id),this.scroller.classList.remove(`wui-file-viewer-panning`)),this._pan=null}print(){this._printFrame?.remove();let e=document.createElement(`iframe`);e.className=`wui-file-viewer-print-frame`,e.title=`Image for printing`,e.tabIndex=-1,e.setAttribute(`aria-hidden`,`true`);let t=this.rotation%180!=0,n=new URL(this.source.src,document.baseURI).href,r=t?`max-width: 100vh; max-height: 100vw;`:`max-width: 100vw; max-height: 100vh;`;e.srcdoc=`<!doctype html><html><head><title>${Ba(this.shell.name())}</title><style>
19
+ </style></head><body>${i}</body></html>`}function da(e,t,n){let r=e.textContent,i=[],a=0;for(let{from:e,to:o,n:s}of t){e>a&&i.push(document.createTextNode(r.slice(a,e)));let t=document.createElement(`mark`);t.className=s===n?`wui-file-viewer-hit wui-file-viewer-hit-current`:`wui-file-viewer-hit`,t.textContent=r.slice(e,o),i.push(t),a=o}a<r.length&&i.push(document.createTextNode(r.slice(a))),e.replaceChildren(...i)}function fa(e){let t=[...e].sort((e,t)=>e-t);return t[Math.floor(t.length/2)]}var pa,ma,ha,ga,_a,va,ya,ba,xa,Sa,Ca,wa,Ta,Ea,Da,Oa,ka,Aa,ja,Ma,Na=n((()=>{Xi(),Qi(),aa(),_(),f(),pa=[.5,.75,1,1.25,1.5,2,3],ma=[.5,.75,1,1.25,1.5,2],ha=[{key:`fit-width`,label:`Fit width`},{key:`fit-page`,label:`Fit page`}],ga=96/72,_a=12,va=10,ya=168,ba=150,xa=2,Sa=2e3,Ca=5,wa=150,Ta=16777216,Ea=null,Da=e=>{if(ha.some(t=>t.key===e))return e;let t=Number(e);return pa.includes(t)?t:`fit-width`},Oa=e=>e instanceof Element&&e.closest(`input, textarea, select, [contenteditable='true'], .dropdown-menu`),ka=e=>/^(https?:|mailto:)/i.test(e),Aa=class{constructor(e,t){this.shell=e,this.source=t;let n=e.prefs;this.zoom=Da(n.zoom),this.twoPage=n.twoPage===!0,this.showThumbs=n.thumbnails===!0,this.pdf=null,this.sizes=[],this.rows=[],this.rowOf=[],this.scale=0,this.drawnScale=0,this.pages=new Map,this.thumbsDrawn=new Set,this.area={width:0,height:0},this.scrollPos={top:0,left:0},this.jumpTarget=null,this.search={open:!1,query:``,index:null,indexing:!1,hits:[],current:-1,marked:new Map},this.printRun=null,this.destroyed=!1,this._timers=new Set}load(){return this._loading=this._load(),this._loading}async _load(){sa(this.source.workerSrc),this.task=nt({url:this.source.src,...ca(this.source.assetBase)});let e;try{e=await this.task.promise}catch(e){this.destroyed||this.shell.fail(e);return}if(this.destroyed){e.destroy();return}this.pdf=e;let t=await Promise.all(Array.from({length:e.numPages},(t,n)=>e.getPage(n+1)));this.destroyed||(this.sizes=t.map(e=>{let t=e.getViewport({scale:ga});return{width:t.width,height:t.height}}),this._buildToolbar(),this._buildBody(),this._layout(),this.shell.loaded({kind:`pdf`,pages:e.numPages}))}destroy(){this.destroyed=!0;for(let e of this._timers)window.clearTimeout(e);window.cancelAnimationFrame(this._scrollFrame),this._resizeObserver?.disconnect(),this._onKeyDown&&this.shell.host.removeEventListener(`keydown`,this._onKeyDown),this._thumbObserver?.disconnect();for(let e of[...this.pages.keys()])this._release(e);this._releasePrint();let e=this.task;e&&(this._loading??Promise.resolve()).catch(()=>{}).finally(()=>e.destroy())}_buildToolbar(){let{start:e,center:t,end:n,host:r}=this.shell;this.thumbsButton=p(`menu`,``,{size:17}),this.thumbsButton.addEventListener(`click`,()=>this._setThumbs(!this.showThumbs)),e.prepend(this.thumbsButton),this.prevButton=p(`chevron-up`,`Previous page`),this.prevButton.addEventListener(`click`,()=>this.goToPage(this.current()-this.cols()));let i=document.createElement(`span`);i.className=`wui-file-viewer-page`,this.pageInput=document.createElement(`input`),this.pageInput.className=`wui-file-viewer-page-input`,this.pageInput.setAttribute(`aria-label`,`Page number`),this.pageInput.inputMode=`numeric`,this.pageInput.addEventListener(`input`,()=>{this.pageInput.value=this.pageInput.value.replace(/[^\d]/g,``)}),this.pageInput.addEventListener(`keydown`,e=>{e.key===`Enter`&&this.pageInput.blur()}),this.pageInput.addEventListener(`blur`,()=>this._commitPageInput());let a=document.createElement(`span`);a.className=`wui-file-viewer-page-total`,a.textContent=`/ ${this.pdf.numPages}`,i.append(this.pageInput,a),this.nextButton=p(`chevron-down`,`Next page`),this.nextButton.addEventListener(`click`,()=>this.goToPage(this.current()+this.cols())),t.append(this.prevButton,i,this.nextButton),this.searchButton=p(`search`,`Search the document`,{className:`wui-file-viewer-search-toggle`}),this.searchButton.setAttribute(`aria-controls`,`${r.uid}-search`),this.searchButton.addEventListener(`click`,()=>this.search.open?this._closeSearch():this._openSearch()),this.zoomOutButton=p(`zoom-out`,`Zoom out`),this.zoomOutButton.addEventListener(`click`,()=>this._stepZoom(-1)),this.zoomButton=document.createElement(`button`),this.zoomButton.type=`button`,this.zoomButton.className=`wui-file-viewer-zoom`,g(this.zoomButton,{label:`Zoom`,items:()=>[...ma.map(e=>({key:String(e),label:`${Math.round(e*100)}%`,checked:this.zoom===e})),{key:`fit-divider`,divider:!0},...ha.map(e=>({key:e.key,label:e.label,checked:this.zoom===e.key}))],onPick:e=>this._setZoom(Da(e))}),this.zoomInButton=p(`zoom-in`,`Zoom in`),this.zoomInButton.addEventListener(`click`,()=>this._stepZoom(1));let o=document.createElement(`span`);o.className=`wui-file-viewer-divider`,this.twoPageButton=p(`two-page`,`Two-page view`),this.twoPageButton.addEventListener(`click`,()=>this._setTwoPage(!this.twoPage)),this.printButton=p(`printer`,`Print`,{className:`wui-file-viewer-print`}),this.printButton.addEventListener(`click`,()=>this.print()),this.printButton.hidden=!this.shell.print(),n.prepend(this.searchButton,this.zoomOutButton,this.zoomButton,this.zoomInButton,o,this.twoPageButton,this.printButton),this._buildSearchRow(),this._syncToolbar()}_buildSearchRow(){let e=this.shell.search;e.id=`${this.shell.host.uid}-search`;let t=document.createElement(`div`);t.className=`wui-file-viewer-search-field`,this.searchInput=document.createElement(`input`),this.searchInput.type=`search`,this.searchInput.className=`form-control form-control-sm`,this.searchInput.placeholder=`Search the document`,this.searchInput.setAttribute(`aria-label`,`Search the document`),this.searchInput.addEventListener(`input`,()=>this._setQuery(this.searchInput.value)),this.searchInput.addEventListener(`keydown`,e=>{e.key===`Enter`?(e.preventDefault(),this._goToHit(this.search.current+(e.shiftKey?-1:1))):e.key===`Escape`&&(e.preventDefault(),this._closeSearch())}),t.append(this.searchInput),this.searchStatus=document.createElement(`span`),this.searchStatus.className=`wui-file-viewer-search-count`,this.searchStatus.setAttribute(`aria-live`,`polite`),this.prevHitButton=p(`chevron-up`,`Previous match`),this.prevHitButton.addEventListener(`click`,()=>this._goToHit(this.search.current-1)),this.nextHitButton=p(`chevron-down`,`Next match`),this.nextHitButton.addEventListener(`click`,()=>this._goToHit(this.search.current+1));let n=p(`x`,`Close search`);n.addEventListener(`click`,()=>this._closeSearch()),e.append(t,this.searchStatus,this.prevHitButton,this.nextHitButton,n)}_syncToolbar(){let e=this.current(),t=this.rows.length-1;document.activeElement!==this.pageInput&&(this.pageInput.value=String(e)),this.prevButton.disabled=e<=1,this.nextButton.disabled=(this.rowOf[e]??0)>=t,this.zoomOutButton.disabled=this._zoomStep(-1)==null,this.zoomInButton.disabled=this._zoomStep(1)==null;let n=Math.round((this.scale||1)*100);this._shownPercent!==n&&(this._shownPercent=n,this.zoomButton.innerHTML=`${n}%${u(`chevron-down`,{size:12})}`,this.zoomButton.setAttribute(`aria-label`,`Zoom, ${n}%`)),h(this.thumbsButton,this.showThumbs?`Hide thumbnails`:`Show thumbnails`),this.thumbsButton.setAttribute(`aria-pressed`,String(this.showThumbs)),this.twoPageButton.setAttribute(`aria-pressed`,String(this.twoPage)),this.printButton.disabled=this.printRun!=null&&!this.printRun.ready,h(this.printButton,this.printButton.disabled?`Preparing to print`:`Print`),h(this.searchButton,this.search.open?`Close search`:`Search the document`),this.searchButton.setAttribute(`aria-expanded`,String(this.search.open)),this._syncSearchStatus()}_buildBody(){let e=this.shell.body;this.thumbRail=document.createElement(`div`),this.thumbRail.className=`wui-file-viewer-thumbs wui-scroll${this.showThumbs?` open`:``}`,this.scroller=document.createElement(`div`),this.scroller.className=`wui-file-viewer-scroll wui-scroll`,this.scroller.tabIndex=0,this.scroller.setAttribute(`role`,`region`),this.scroller.setAttribute(`aria-label`,`Document pages`),this.pagesEl=document.createElement(`div`),this.pagesEl.className=`wui-file-viewer-pages`,this.scroller.append(this.pagesEl),e.replaceChildren(this.thumbRail,this.scroller),this.pageEls=[];for(let e=1;e<=this.pdf.numPages;e++){let t=document.createElement(`div`);t.className=`wui-file-viewer-sheet`,t.dataset.page=String(e),this.pageEls[e]=t}this.showThumbs&&this._buildThumbs(),this.scroller.addEventListener(`scroll`,()=>this._onScroll(),{passive:!0}),this.scroller.addEventListener(`pointerdown`,e=>this._panStart(e)),this.scroller.addEventListener(`pointermove`,e=>this._panMove(e));for(let e of[`pointerup`,`pointercancel`,`lostpointercapture`])this.scroller.addEventListener(e,()=>this._panEnd());this.scroller.addEventListener(`wheel`,e=>{if(!e.ctrlKey&&!e.metaKey)return;e.preventDefault();let t=performance.now();t-(this._lastWheelZoom??0)<120||(this._lastWheelZoom=t,this._stepZoom(e.deltaY<0?1:-1))},{passive:!1}),this._onKeyDown=e=>this._keyDown(e),this.shell.host.addEventListener(`keydown`,this._onKeyDown),this._resizeObserver=new ResizeObserver(()=>{let e=this.scroller.clientWidth,t=this.scroller.clientHeight;e===this.area.width&&t===this.area.height||(this.area={width:e,height:t},this._layout())}),this._resizeObserver.observe(this.scroller),this.area={width:this.scroller.clientWidth,height:this.scroller.clientHeight}}cols(){return this.twoPage?2:1}_targetScale(){if(typeof this.zoom==`number`)return this.zoom;let e=this.cols(),t=fa(this.sizes.map(e=>e.width)),n=fa(this.sizes.map(e=>e.height)),r=(this.area.width-2*_a-(e-1)*va)/(t*e);return this.zoom===`fit-page`&&(r=Math.min(r,(this.area.height-2*_a)/n)),Math.max(r,.1)}_layout(){if(!this.pdf||!this.area.width)return;let e=this._anchor();this.scale=this._targetScale();let t=this.cols();this.rows=[],this.rowOf=[];let n=_a,r=document.createDocumentFragment();for(let e=1;e<=this.pdf.numPages;e+=t){let i=[];for(let n=e;n<e+t&&n<=this.pdf.numPages;n++)i.push(n);let a=document.createElement(`div`);a.className=`wui-file-viewer-row`;let o=0;for(let e of i){let{width:t,height:n}=this.sizes[e-1],r=this.pageEls[e];r.style.width=`${Math.floor(t*this.scale)}px`,r.style.height=`${Math.floor(n*this.scale)}px`,r.style.setProperty(`--scale-factor`,String(this.scale*ga)),o=Math.max(o,Math.floor(n*this.scale)),a.append(r),this.rowOf[e]=this.rows.length}this.rows.push({pages:i,top:n,height:o}),n+=o+va,r.append(a)}let i=this.scroller.scrollWidth;this.pagesEl.replaceChildren(r),this._restore(e,i),this._scheduleRedraw(),this._update()}_anchor(){if(!this.rows.length)return null;let e=this._rowAt(this.scrollPos.top),t=this.rows[e];return{page:t.pages[0],within:(this.scrollPos.top-t.top)/Math.max(t.height+va,1),left:this.scrollPos.left}}_restore(e,t){let n=this.scroller;if(e){let r=this.rows[this.rowOf[e.page]];n.scrollTop=r.top+e.within*(r.height+va),n.scrollLeft=(t?(e.left+n.clientWidth/2)/t:.5)*n.scrollWidth-n.clientWidth/2}this.scrollPos={top:n.scrollTop,left:n.scrollLeft}}_rowAt(e){let t=0,n=this.rows.length-1;for(;t<n;){let r=t+n+1>>1;this.rows[r].top<=e+1?t=r:n=r-1}return t}current(){if(this.jumpTarget!=null)return this.jumpTarget;if(!this.rows.length)return 1;let e=this.scrollPos.top,t=e+this.area.height,n=this._rowAt(e),r=-1;for(let i=n;i<this.rows.length&&this.rows[i].top<t;i++){let{top:a,height:o}=this.rows[i],s=Math.min(a+o,t)-Math.max(a,e);s>r&&(r=s,n=i)}return this.rows[n].pages[0]}_onScroll(){this.scrollPos={top:this.scroller.scrollTop,left:this.scroller.scrollLeft},window.cancelAnimationFrame(this._scrollFrame),this._scrollFrame=window.requestAnimationFrame(()=>this._update())}_update(){if(!this.rows.length||this.destroyed)return;let e=Math.max(0,this._rowAt(this.scrollPos.top)-xa),t=Math.min(this.rows.length-1,this._rowAt(this.scrollPos.top+this.area.height)+xa),n=new Set;for(let r=e;r<=t;r++)for(let e of this.rows[r].pages)n.add(e);for(let e of[...this.pages.keys()])n.has(e)||this._release(e);this.visibleRow=this._rowAt(this.scrollPos.top);for(let e of n)this.pages.has(e)||this._mount(e);this._pump(),this._syncToolbar(),this.showThumbs&&this._followThumb()}_scheduleRedraw(){if(this.scale===this.drawnScale)return;window.clearTimeout(this._redrawTimer),this._timers.delete(this._redrawTimer);let e=this.drawnScale?ba:0;this._redrawTimer=window.setTimeout(()=>{this._timers.delete(this._redrawTimer),this.drawnScale=this.scale,this._pump()},e),this._timers.add(this._redrawTimer)}_mount(e){let t=this.pageEls[e],n={n:e,drawnAt:0,task:null,canvas:null,text:null,textLayer:null,links:null};this.pages.set(e,n);let r=document.createElement(`div`);r.className=`wui-file-viewer-skeleton`,t.replaceChildren(r),this._drawText(n),this._drawLinks(n)}_release(e){let t=this.pages.get(e);t&&(t.released=!0,t.task?.cancel(),t.textLayer?.cancel(),t.canvas&&(t.canvas.width=0,t.canvas.height=0),this.pages.delete(e),this.search.marked.delete(e),this.pageEls[e].replaceChildren())}_pump(){if(this._drawing||!this.drawnScale||this.destroyed)return;let e=this.visibleRow??0,t=null,n=1/0;for(let r of this.pages.values()){if(r.drawnAt===this.drawnScale)continue;let i=Math.abs(this.rowOf[r.n]-e);i<n&&(n=i,t=r)}t&&(this._drawing=!0,this._drawCanvas(t).finally(()=>{this._drawing=!1,this._pump()}))}async _drawCanvas(e){let t=this.drawnScale,n=await this.pdf.getPage(e.n);if(e.released||this.destroyed)return;let r=n.getViewport({scale:t*ga}),i=window.devicePixelRatio||1,a=Math.sqrt(Ta/(r.width*r.height)),o=Math.min(i,a),s=document.createElement(`canvas`);s.className=`wui-file-viewer-canvas`,s.width=Math.floor(r.width*o),s.height=Math.floor(r.height*o),s.setAttribute(`aria-hidden`,`true`),e.task=n.render({canvas:s,viewport:r,transform:o===1?null:[o,0,0,o,0,0]});try{await e.task.promise}catch(e){s.width=0,s.height=0,e?.name!==`RenderingCancelledException`&&this._warn(`page draw failed`,e);return}finally{e.task=null}if(e.released||this.destroyed){s.width=0,s.height=0;return}let c=this.pageEls[e.n];e.canvas?(e.canvas.replaceWith(s),e.canvas.width=0,e.canvas.height=0):(c.querySelector(`.wui-file-viewer-skeleton`)?.remove(),c.prepend(s)),e.canvas=s,e.drawnAt=t,this.showThumbs&&!this.thumbsDrawn.has(e.n)&&this._thumbFromCanvas(e.n,s)}async _drawText(e){let t=await this.pdf.getPage(e.n);if(e.released||this.destroyed)return;let n=document.createElement(`div`);n.className=`wui-file-viewer-text`,e.text=n,e.textLayer=new jr({textContentSource:t.streamTextContent({includeMarkedContent:!0,disableNormalization:!0}),container:n,viewport:t.getViewport({scale:this.scale*ga})});try{await e.textLayer.render()}catch(e){e?.name!==`AbortException`&&this._warn(`text layer failed`,e);return}e.released||this.destroyed||(this.pageEls[e.n].append(n),this._markPage(e.n),this._revealHit(e.n))}async _drawLinks(e){let t=await this.pdf.getPage(e.n),n=await t.getAnnotations({intent:`display`});if(e.released||this.destroyed)return;let r=n.filter(e=>e.subtype===`Link`&&(e.dest||e.url&&ka(e.url))),i=(await Promise.all(r.map(async e=>e.url?{link:e}:{link:e,target:await this._destPage(e.dest)}))).filter(({link:e,target:t})=>e.url||t);if(!i.length||e.released||this.destroyed)return;let a=t.getViewport({scale:1}),o=document.createElement(`div`);o.className=`wui-file-viewer-links`;for(let{link:e,target:t}of i){let[n,r,i,s]=a.convertToViewportRectangle(e.rect),c=document.createElement(`a`);c.style.left=`${Math.min(n,i)/a.width*100}%`,c.style.top=`${Math.min(r,s)/a.height*100}%`,c.style.width=`${Math.abs(i-n)/a.width*100}%`,c.style.height=`${Math.abs(s-r)/a.height*100}%`,e.url?(c.href=e.url,c.target=`_blank`,c.rel=`noopener noreferrer`,c.title=e.url,c.setAttribute(`aria-label`,e.url)):(c.href=`#page=${t}`,c.setAttribute(`aria-label`,`Go to page ${t}`),c.addEventListener(`click`,e=>{e.preventDefault(),this.goToPage(t)})),o.append(c)}e.links=o,this.pageEls[e.n].append(o)}async _destPage(e){try{let t=(typeof e==`string`?await this.pdf.getDestination(e):e)?.[0];return t==null?null:(typeof t==`object`?await this.pdf.getPageIndex(t):t)+1}catch(e){return this._warn(`link target not found`,e),null}}goToPage(e){let t=Math.min(Math.max(1,e),this.pdf.numPages),n=Math.min(this.rows[this.rowOf[t]].top-_a,this.scroller.scrollHeight-this.scroller.clientHeight);window.clearTimeout(this._jumpTimer),this.scroller.removeEventListener(`scrollend`,this._endJump),this._endJump=()=>{window.clearTimeout(this._jumpTimer),this.scroller.removeEventListener(`scrollend`,this._endJump),this.jumpTarget=null,this._syncToolbar()},Math.abs(n-this.scroller.scrollTop)>=1&&(this.jumpTarget=t,this.scroller.addEventListener(`scrollend`,this._endJump),this._jumpTimer=window.setTimeout(this._endJump,Sa),this._timers.add(this._jumpTimer),this.scroller.scrollTo({top:n,behavior:Ma()})),this._syncToolbar()}_commitPageInput(){let e=Number.parseInt(this.pageInput.value,10);Number.isNaN(e)?this.pageInput.value=String(this.current()):this.goToPage(e)}_zoomStep(e){let t=this.scale||1;return e>0?pa.find(e=>e>t+.001)??null:[...pa].reverse().find(e=>e<t-.001)??null}_stepZoom(e){let t=this._zoomStep(e);t!=null&&this._setZoom(t)}_setZoom(e){this.zoom=e,this.shell.savePrefs({zoom:String(e)}),this._layout()}_setTwoPage(e){this.twoPage=e,this.shell.savePrefs({twoPage:e}),this._layout()}_setThumbs(e){this.showThumbs=e,this.shell.savePrefs({thumbnails:e}),this.thumbRail.classList.toggle(`open`,e),e&&!this.thumbRail.childElementCount&&this._buildThumbs(),this._syncToolbar(),e&&(this._activeThumb=null,this._followThumb())}_buildThumbs(){this.thumbEls=[],this._thumbObserver=new IntersectionObserver(e=>{for(let t of e)t.isIntersecting&&this._drawThumb(Number(t.target.dataset.page))},{root:this.thumbRail,rootMargin:`200px 0px`});for(let e=1;e<=this.pdf.numPages;e++){let t=document.createElement(`button`);t.type=`button`,t.className=`wui-file-viewer-thumb`,t.dataset.page=String(e),t.setAttribute(`aria-label`,`Go to page ${e}`);let{width:n,height:r}=this.sizes[e-1],i=document.createElement(`span`);i.className=`wui-file-viewer-thumb-frame`,i.style.aspectRatio=`${n} / ${r}`;let a=document.createElement(`span`);a.className=`wui-file-viewer-thumb-no`,a.textContent=String(e),t.append(i,a),t.addEventListener(`click`,()=>this.goToPage(e)),this.thumbRail.append(t),this.thumbEls[e]=t,this._thumbObserver.observe(t)}}async _drawThumb(e){if(this.thumbsDrawn.has(e))return;this.thumbsDrawn.add(e);let t=this.pages.get(e)?.canvas;if(t){this._thumbFromCanvas(e,t);return}let n=await this.pdf.getPage(e);if(this.destroyed)return;let r=window.devicePixelRatio||1,i=n.getViewport({scale:ya*r/n.getViewport({scale:1}).width}),a=document.createElement(`canvas`);a.width=Math.floor(i.width),a.height=Math.floor(i.height);try{await n.render({canvas:a,viewport:i}).promise}catch(t){this.thumbsDrawn.delete(e),t?.name!==`RenderingCancelledException`&&this._warn(`thumbnail draw failed`,t);return}this._setThumbImage(e,a)}_thumbFromCanvas(e,t){this.thumbsDrawn.add(e);let n=window.devicePixelRatio||1,r=document.createElement(`canvas`);r.width=Math.floor(ya*n),r.height=Math.floor(r.width*t.height/t.width),r.getContext(`2d`)?.drawImage(t,0,0,r.width,r.height),this._setThumbImage(e,r)}_setThumbImage(e,t){let n=this.thumbEls?.[e]?.querySelector(`.wui-file-viewer-thumb-frame`);n&&(t.setAttribute(`aria-hidden`,`true`),n.replaceChildren(t))}_followThumb(){let e=this.current();e===this._activeThumb||!this.thumbEls||(this.thumbEls[this._activeThumb]?.classList.remove(`active`),this._activeThumb=e,this.thumbEls[e]?.classList.add(`active`),this.thumbEls[e]?.scrollIntoView({behavior:Ma(),block:`nearest`}))}_openSearch(){this.search.open=!0,this.shell.search.hidden=!1,this._syncToolbar(),this.searchInput.focus(),this.searchInput.select(),!this.search.index&&!this.search.indexing&&(this.search.indexing=!0,this._syncSearchStatus(),ea(this.pdf).then(e=>{this.search.index=e}).catch(e=>{this._warn(`text index failed`,e),this.search.index=!1}).finally(()=>{this.search.indexing=!1,this.destroyed||this._setQuery(this.search.query)}))}_closeSearch(){this.search.open=!1,this.shell.search.hidden=!0,this._applyHits([],-1),this._syncToolbar(),this.searchButton.focus()}_setQuery(e){this.search.query=e;let t=this.search.index?na(this.search.index,e):[],n=this.current(),r=t.findIndex(e=>e.page>=n);this._applyHits(t,t.length?Math.max(r,0):-1),this._revealPending=t.length>0,t.length&&this._bringHitIntoView()}_goToHit(e){let{hits:t}=this.search;t.length&&(this._applyHits(t,(e+t.length)%t.length),this._revealPending=!0,this._bringHitIntoView())}_applyHits(e,t){let n=e!==this.search.hits,r=this.search;this.search={...r,hits:e,current:t},n&&(this.search.byPage=new Map,e.forEach((e,t)=>{this.search.byPage.has(e.page)||this.search.byPage.set(e.page,[]),this.search.byPage.get(e.page).push({...e,n:t})}));let i=n?new Set([...r.marked.keys(),...this.search.byPage.keys()]):new Set([r.hits[r.current]?.page,e[t]?.page].filter(Boolean));for(let e of i)this._markPage(e);this._syncSearchStatus()}_markPage(e){let t=this.pages.get(e),n=t?.textLayer?.textDivs;if(!n||!t.text?.isConnected)return;let r=this.search.index?.[e-1]?.items,i=this.search.open?this.search.byPage?.get(e)??[]:[],a=this.search.marked.get(e)??new Set,o=new Set;r&&i.length&&r.forEach((e,t)=>{let r=ra(e,i);!r.length||!n[t]||(o.add(t),da(n[t],r,this.search.current))});for(let e of a)!o.has(e)&&n[e]&&n[e].replaceChildren(n[e].textContent);o.size?this.search.marked.set(e,o):this.search.marked.delete(e)}_bringHitIntoView(){let e=this.search.hits[this.search.current];if(!e)return;let t=this.rows[this.rowOf[e.page]],n=this.scrollPos.top;(t.top+t.height<n||t.top>n+this.area.height)&&(this.scroller.scrollTop=t.top-_a),this._revealHit(e.page)}_revealHit(e){let t=this.search.hits[this.search.current];if(!this._revealPending||!t||t.page!==e)return;let n=this.pageEls[e].querySelector(`.wui-file-viewer-hit-current`);if(!n)return;this._revealPending=!1;let r=this.scroller.getBoundingClientRect(),i=n.getBoundingClientRect();(i.top<r.top||i.bottom>r.bottom)&&(this.scroller.scrollTop+=i.top-r.top-this.scroller.clientHeight/2),(i.left<r.left||i.right>r.right)&&(this.scroller.scrollLeft+=i.left-r.left-this.scroller.clientWidth/2)}_syncSearchStatus(){this.searchStatus&&(this.searchStatus.textContent=$i(this.search),this.prevHitButton.disabled=!this.search.hits.length,this.nextHitButton.disabled=!this.search.hits.length)}_keyDown(e){if(e.defaultPrevented||e.altKey)return;if(e.ctrlKey||e.metaKey){if(e.key===`f`||e.key===`F`)this._openSearch();else if(e.key===`+`||e.key===`=`)this._stepZoom(1);else if(e.key===`-`||e.key===`_`)this._stepZoom(-1);else if(e.key===`0`)this._setZoom(`fit-width`);else return;e.preventDefault();return}if(e.shiftKey||Oa(e.target))return;let t=this.cols();if(e.key===`PageDown`)this.goToPage(this.current()+t);else if(e.key===`PageUp`)this.goToPage(this.current()-t);else if(e.key===`Home`)this.goToPage(1);else if(e.key===`End`)this.goToPage(this.pdf.numPages);else return;e.preventDefault()}_panStart(e){let t=this.scroller;e.button!==0||t.scrollWidth<=t.clientWidth&&t.scrollHeight<=t.clientHeight||e.target instanceof Element&&e.target.closest(`a`)||(this._pan={id:e.pointerId,x:e.clientX,y:e.clientY,left:t.scrollLeft,top:t.scrollTop,active:!1})}_panMove(e){let t=this._pan;if(!t)return;let n=e.clientX-t.x,r=e.clientY-t.y;if(!t.active){if(Math.abs(n)<Ca&&Math.abs(r)<Ca)return;t.active=!0,this.scroller.setPointerCapture(t.id),this.scroller.classList.add(`wui-file-viewer-panning`)}this.scroller.scrollLeft=t.left-n,this.scroller.scrollTop=t.top-r}_panEnd(){let e=this._pan;e?.active&&(this.scroller.hasPointerCapture(e.id)&&this.scroller.releasePointerCapture(e.id),this.scroller.classList.remove(`wui-file-viewer-panning`)),this._pan=null}async print(){this._releasePrint();let e={ready:!1,urls:[]};this.printRun=e,this._syncToolbar();try{let t=[];for(let n=1;n<=this.pdf.numPages;n++){let r=await this.pdf.getPage(n),i=r.getViewport({scale:wa/72}),a=document.createElement(`canvas`);a.width=Math.floor(i.width),a.height=Math.floor(i.height),await r.render({canvas:a,viewport:i,intent:`print`}).promise;let o=await new Promise((e,t)=>a.toBlob(n=>n?e(n):t(Error(`Page image failed`)),`image/png`));a.width=0,a.height=0;let s=URL.createObjectURL(o);if(e.urls.push(s),t.push({url:s,width:i.width/wa*25.4,height:i.height/wa*25.4}),this.printRun!==e)throw new DOMException(`Print replaced`,`AbortError`)}let n=document.createElement(`iframe`);n.className=`wui-file-viewer-print-frame`,n.title=`Document for printing`,n.tabIndex=-1,n.setAttribute(`aria-hidden`,`true`),e.frame=n,n.srcdoc=ua(this.shell.name(),t),n.addEventListener(`load`,()=>{if(this.printRun===e){e.ready=!0,this._syncToolbar();try{n.contentWindow.addEventListener(`afterprint`,()=>{this.printRun===e&&this._releasePrint()},{once:!0}),n.contentWindow.focus(),n.contentWindow.print()}catch(e){this._printFallback(e)}}},{once:!0}),document.body.append(n)}catch(t){if(this.printRun!==e){for(let t of e.urls)URL.revokeObjectURL(t);return}this._printFallback(t)}}_printFallback(e){this._releasePrint(),this._warn(`print failed`,e),window.open(this.source.src,`_blank`,`noopener`)}_releasePrint(){let e=this.printRun;if(this.printRun=null,e){e.frame?.remove();for(let t of e.urls)URL.revokeObjectURL(t)}this.printButton&&this._syncToolbar()}_warn(e,t){console.warn(`[wui-file-viewer] ${e}:`,t?.message??t)}},ja=e=>String(e??``).replace(/&/g,`&amp;`).replace(/</g,`&lt;`).replace(/>/g,`&gt;`),Ma=()=>window.matchMedia?.(`(prefers-reduced-motion: reduce)`).matches?`auto`:`smooth`})),Pa=r({ImageView:()=>za}),Fa,Ia,La,Ra,za,Ba,Va=n((()=>{_(),f(),Fa=[.1,.25,.5,.75,1,1.5,2,3,4],Ia=[.25,.5,1,2,4],La=16,Ra=5,za=class{constructor(e,t){this.shell=e,this.source=t,this.zoom=`fit`,this.rotation=0,this.area={width:0,height:0},this.destroyed=!1}load(){let e=document.createElement(`img`);e.className=`wui-file-viewer-image`,e.alt=this.shell.name(),e.decoding=`async`,e.draggable=!1,e.addEventListener(`load`,()=>{this.destroyed||(this.natural={width:e.naturalWidth||300,height:e.naturalHeight||150},this._build(e),this.shell.loaded({kind:`image`,pages:1}))}),e.addEventListener(`error`,()=>{this.destroyed||this.shell.fail(Error(`The image could not be decoded.`))}),e.src=this.source.src,this.img=e}destroy(){this.destroyed=!0,this._resizeObserver?.disconnect(),this._onKeyDown&&this.shell.host.removeEventListener(`keydown`,this._onKeyDown),this._printFrame?.remove(),this.img?.removeAttribute(`src`)}_build(e){let{center:t,end:n,body:r,host:i}=this.shell;this.zoomOutButton=p(`zoom-out`,`Zoom out`),this.zoomOutButton.addEventListener(`click`,()=>this._stepZoom(-1)),this.zoomButton=document.createElement(`button`),this.zoomButton.type=`button`,this.zoomButton.className=`wui-file-viewer-zoom`,g(this.zoomButton,{label:`Zoom`,items:()=>[...Ia.map(e=>({key:String(e),label:`${Math.round(e*100)}%`,checked:this.zoom===e})),{key:`fit-divider`,divider:!0},{key:`fit`,label:`Fit`,checked:this.zoom===`fit`}],onPick:e=>this._setZoom(e===`fit`?`fit`:Number(e))}),this.zoomInButton=p(`zoom-in`,`Zoom in`),this.zoomInButton.addEventListener(`click`,()=>this._stepZoom(1));let a=p(`rotate-ccw`,`Rotate left`);a.addEventListener(`click`,()=>this._rotate(-90));let o=p(`rotate-cw`,`Rotate right`);o.addEventListener(`click`,()=>this._rotate(90));let s=document.createElement(`span`);s.className=`wui-file-viewer-divider wui-file-viewer-print`;let c=p(`printer`,`Print`,{className:`wui-file-viewer-print`});c.addEventListener(`click`,()=>this.print()),s.hidden=c.hidden=!this.shell.print(),t.append(this.zoomOutButton,this.zoomButton,this.zoomInButton),n.prepend(a,o,s,c),this.scroller=document.createElement(`div`),this.scroller.className=`wui-file-viewer-scroll wui-file-viewer-image-scroll wui-scroll`,this.scroller.tabIndex=0,this.scroller.setAttribute(`role`,`region`),this.scroller.setAttribute(`aria-label`,`Image`),this.stage=document.createElement(`div`),this.stage.className=`wui-file-viewer-image-stage`,this.stage.append(e),this.scroller.append(this.stage),r.replaceChildren(this.scroller),this.scroller.addEventListener(`pointerdown`,e=>this._panStart(e)),this.scroller.addEventListener(`pointermove`,e=>this._panMove(e));for(let e of[`pointerup`,`pointercancel`,`lostpointercapture`])this.scroller.addEventListener(e,()=>this._panEnd());this.scroller.addEventListener(`wheel`,e=>{if(!e.ctrlKey&&!e.metaKey)return;e.preventDefault();let t=performance.now();t-(this._lastWheelZoom??0)<120||(this._lastWheelZoom=t,this._stepZoom(e.deltaY<0?1:-1))},{passive:!1}),this._onKeyDown=e=>this._keyDown(e),i.addEventListener(`keydown`,this._onKeyDown),this._resizeObserver=new ResizeObserver(()=>{let e=this.scroller.clientWidth,t=this.scroller.clientHeight;e===this.area.width&&t===this.area.height||(this.area={width:e,height:t},this._layout())}),this._resizeObserver.observe(this.scroller),this.area={width:this.scroller.clientWidth,height:this.scroller.clientHeight},this._layout()}_turned(){let{width:e,height:t}=this.natural;return this.rotation%180==0?{width:e,height:t}:{width:t,height:e}}scale(){if(typeof this.zoom==`number`)return this.zoom;let{width:e,height:t}=this._turned(),n=Math.min((this.area.width-2*La)/e,(this.area.height-2*La)/t);return Math.max(n,.01)}_layout(){if(!this.stage)return;let e=this.scale(),t=this._turned();this.stage.style.width=`${Math.round(t.width*e)}px`,this.stage.style.height=`${Math.round(t.height*e)}px`,this.img.style.width=`${Math.round(this.natural.width*e)}px`,this.img.style.height=`${Math.round(this.natural.height*e)}px`,this.img.style.transform=`translate(-50%, -50%) rotate(${this.rotation}deg)`;let n=Math.round(e*100);this.zoomButton.innerHTML=`${n}%${u(`chevron-down`,{size:12})}`,this.zoomButton.setAttribute(`aria-label`,`Zoom, ${n}%`),this.zoomOutButton.disabled=this._zoomStep(-1)==null,this.zoomInButton.disabled=this._zoomStep(1)==null}_zoomStep(e){let t=this.scale();return e>0?Fa.find(e=>e>t+.001)??null:[...Fa].reverse().find(e=>e<t-.001)??null}_stepZoom(e){let t=this._zoomStep(e);t!=null&&this._setZoom(t)}_setZoom(e){let t=this.scroller,n=(t.scrollLeft+t.clientWidth/2)/Math.max(t.scrollWidth,1),r=(t.scrollTop+t.clientHeight/2)/Math.max(t.scrollHeight,1);this.zoom=e,this._layout(),t.scrollLeft=n*t.scrollWidth-t.clientWidth/2,t.scrollTop=r*t.scrollHeight-t.clientHeight/2}_rotate(e){this.rotation=(this.rotation+e+360)%360,this._setZoom(this.zoom)}_keyDown(e){if(!(e.defaultPrevented||e.altKey||!(e.ctrlKey||e.metaKey))){if(e.key===`+`||e.key===`=`)this._stepZoom(1);else if(e.key===`-`||e.key===`_`)this._stepZoom(-1);else if(e.key===`0`)this._setZoom(`fit`);else return;e.preventDefault()}}_panStart(e){let t=this.scroller;e.button!==0||t.scrollWidth<=t.clientWidth&&t.scrollHeight<=t.clientHeight||(this._pan={id:e.pointerId,x:e.clientX,y:e.clientY,left:t.scrollLeft,top:t.scrollTop,active:!1})}_panMove(e){let t=this._pan;if(!t)return;let n=e.clientX-t.x,r=e.clientY-t.y;if(!t.active){if(Math.abs(n)<Ra&&Math.abs(r)<Ra)return;t.active=!0,this.scroller.setPointerCapture(t.id),this.scroller.classList.add(`wui-file-viewer-panning`)}this.scroller.scrollLeft=t.left-n,this.scroller.scrollTop=t.top-r}_panEnd(){let e=this._pan;e?.active&&(this.scroller.hasPointerCapture(e.id)&&this.scroller.releasePointerCapture(e.id),this.scroller.classList.remove(`wui-file-viewer-panning`)),this._pan=null}print(){this._printFrame?.remove();let e=document.createElement(`iframe`);e.className=`wui-file-viewer-print-frame`,e.title=`Image for printing`,e.tabIndex=-1,e.setAttribute(`aria-hidden`,`true`);let t=this.rotation%180!=0,n=new URL(this.source.src,document.baseURI).href,r=t?`max-width: 100vh; max-height: 100vw;`:`max-width: 100vw; max-height: 100vh;`;e.srcdoc=`<!doctype html><html><head><title>${Ba(this.shell.name())}</title><style>
20
20
  @page { margin: 10mm; }
21
21
  html, body { margin: 0; height: 100%; }
22
22
  body { display: flex; align-items: center; justify-content: center; }
23
23
  img { ${r} transform: rotate(${this.rotation}deg); }
24
- </style></head><body><img src="${Ba(n)}" alt=""></body></html>`,e.addEventListener(`load`,()=>{try{e.contentWindow.focus(),e.contentWindow.print()}catch(e){console.warn(`[wui-file-viewer] print failed:`,e?.message),window.open(this.source.src,`_blank`,`noopener`)}},{once:!0}),this._printFrame=e,document.body.append(e)}},Ba=e=>String(e??``).replace(/&/g,`&amp;`).replace(/</g,`&lt;`).replace(/>/g,`&gt;`).replace(/"/g,`&quot;`)})),Ha=r({MediaView:()=>Ja,formatTime:()=>Ua});function Ua(e){if(!Number.isFinite(e)||e<0)return`0:00`;let t=Math.floor(e),n=Math.floor(t/3600),r=Math.floor(t%3600/60),i=String(t%60).padStart(2,`0`);return n?`${n}:${String(r).padStart(2,`0`)}:${i}`:`${r}:${i}`}var Wa,Ga,Ka,qa,Ja,Ya=n((()=>{_(),f(),Wa=[.5,.75,1,1.25,1.5,2],Ga=5,Ka=.1,qa=e=>e instanceof Element&&e.closest(`input, textarea, select, button, a, .dropdown-menu`),Ja=class{constructor(e,t){this.shell=e,this.source=t,this.destroyed=!1}load(){let{kind:e,src:t,captions:n}=this.source,r=document.createElement(e);if(r.className=`wui-file-viewer-${e}`,r.preload=`metadata`,r.playsInline=!0,e===`video`&&n){let e=document.createElement(`track`);e.kind=`captions`,e.label=`Captions`,e.srclang=`en`,e.src=n,r.append(e)}let i=this.shell.prefs;typeof i.volume==`number`&&(r.volume=Math.min(Math.max(i.volume,0),1)),r.muted=i.muted===!0,r.addEventListener(`loadedmetadata`,()=>{this.destroyed||(r.playbackRate=Wa.includes(i.speed)?i.speed:1,this._build(),this.shell.loaded({kind:e,pages:1}))},{once:!0}),r.addEventListener(`error`,()=>{this.destroyed||this.shell.fail(Error(`The file could not be played.`))}),r.src=t,this.media=r}destroy(){this.destroyed=!0,this._onKeyDown&&this.shell.host.removeEventListener(`keydown`,this._onKeyDown),this.media&&(this.media.pause(),this.media.removeAttribute(`src`),this.media.load())}_build(){let{body:e,host:t}=this.shell,n=this.media,r=this.source.kind,i=document.createElement(`div`);i.className=`wui-file-viewer-player wui-file-viewer-player-${r}`;let a=document.createElement(`div`);if(a.className=`wui-file-viewer-stage`,a.tabIndex=0,a.setAttribute(`role`,`group`),a.setAttribute(`aria-label`,r===`video`?`Video`:`Audio`),r===`audio`){let e=document.createElement(`div`);e.className=`wui-file-viewer-audio-art`,e.innerHTML=u(`music`,{size:40}),a.append(e,n)}else a.append(n),n.addEventListener(`click`,()=>this.togglePlay());let o=document.createElement(`div`);o.className=`wui-file-viewer-controls`,this.playButton=p(`play`,`Play`,{size:18}),this.playButton.addEventListener(`click`,()=>this.togglePlay()),this.timeNow=document.createElement(`span`),this.timeNow.className=`wui-file-viewer-time`,this.seek=document.createElement(`input`),this.seek.type=`range`,this.seek.className=`form-range wui-file-viewer-seek`,this.seek.min=`0`,this.seek.step=`any`,this.seek.setAttribute(`aria-label`,`Seek`),this.seek.addEventListener(`input`,()=>{n.currentTime=Number(this.seek.value)}),this.timeTotal=document.createElement(`span`),this.timeTotal.className=`wui-file-viewer-time`,this.muteButton=p(`volume-high`,`Mute`,{size:18}),this.muteButton.addEventListener(`click`,()=>this._setMuted(!n.muted)),this.volume=document.createElement(`input`),this.volume.type=`range`,this.volume.className=`form-range wui-file-viewer-volume`,this.volume.min=`0`,this.volume.max=`1`,this.volume.step=`0.05`,this.volume.setAttribute(`aria-label`,`Volume`),this.volume.addEventListener(`input`,()=>this._setVolume(Number(this.volume.value))),this.speedButton=document.createElement(`button`),this.speedButton.type=`button`,this.speedButton.className=`wui-file-viewer-zoom wui-file-viewer-speed`,g(this.speedButton,{label:`Playback speed`,items:()=>Wa.map(e=>({key:String(e),label:`${e}x`,checked:n.playbackRate===e})),onPick:e=>this._setSpeed(Number(e))}),o.append(this.playButton,this.timeNow,this.seek,this.timeTotal,this.muteButton,this.volume,this.speedButton),r===`video`&&this.source.captions&&(this.captionsButton=p(`subtitle`,`Show captions`,{size:18}),this.captionsButton.addEventListener(`click`,()=>this._setCaptions(!this._captionsOn())),o.append(this.captionsButton)),i.append(a,o),e.replaceChildren(i);for(let e of[`play`,`pause`,`ended`])n.addEventListener(e,()=>this._syncPlay());n.addEventListener(`timeupdate`,()=>this._syncTime()),n.addEventListener(`durationchange`,()=>this._syncTime()),n.addEventListener(`volumechange`,()=>this._syncVolume()),n.addEventListener(`ratechange`,()=>this._syncSpeed()),this._onKeyDown=e=>this._keyDown(e),t.addEventListener(`keydown`,this._onKeyDown),this._syncPlay(),this._syncTime(),this._syncVolume(),this._syncSpeed(),this._syncCaptions()}seekTo(e){let t=this.media.duration;this.media.currentTime=Math.min(Math.max(e,0),Number.isFinite(t)?t:1/0)}togglePlay(){this.media.paused||this.media.ended?this.media.play().catch(e=>{console.warn(`[wui-file-viewer] play refused:`,e?.message)}):this.media.pause()}_setMuted(e){this.media.muted=e,!e&&this.media.volume===0&&(this.media.volume=.5),this.shell.savePrefs({muted:this.media.muted,volume:this.media.volume})}_setVolume(e){this.media.volume=Math.min(Math.max(e,0),1),this.media.muted=this.media.volume===0,this.shell.savePrefs({muted:this.media.muted,volume:this.media.volume})}_setSpeed(e){this.media.playbackRate=e,this.shell.savePrefs({speed:e})}_captionsOn(){return this.media.textTracks?.[0]?.mode===`showing`}_setCaptions(e){let t=this.media.textTracks?.[0];t&&(t.mode=e?`showing`:`hidden`),this._syncCaptions()}_syncPlay(){let e=!this.media.paused&&!this.media.ended;m(this.playButton,e?`pause`:`play`,18),h(this.playButton,e?`Pause`:`Play`),this.shell.host.classList.toggle(`wui-file-viewer-playing`,e)}_syncTime(){let e=this.media.currentTime,t=this.media.duration;this.timeNow.textContent=Ua(e),this.timeTotal.textContent=Ua(t),this.seek.max=String(Number.isFinite(t)?t:0),this.seek.value=String(e),this.seek.setAttribute(`aria-valuetext`,`${Ua(e)} of ${Ua(t)}`)}_syncVolume(){let e=this.media.muted||this.media.volume===0;m(this.muteButton,e?`volume-mute`:`volume-high`,18),h(this.muteButton,e?`Unmute`:`Mute`),this.volume.value=String(this.media.muted?0:this.media.volume)}_syncSpeed(){let e=`${this.media.playbackRate}x`;this.speedButton.textContent=e,this.speedButton.setAttribute(`aria-label`,`Playback speed, ${e}`)}_syncCaptions(){if(!this.captionsButton)return;let e=this._captionsOn();this.captionsButton.setAttribute(`aria-pressed`,String(e)),h(this.captionsButton,e?`Hide captions`:`Show captions`)}_keyDown(e){if(e.defaultPrevented||e.altKey||e.ctrlKey||e.metaKey||qa(e.target))return;let t=this.media,n=e.key.toLowerCase();if(n===` `||n===`k`)this.togglePlay();else if(n===`arrowleft`)t.currentTime=Math.max(0,t.currentTime-Ga);else if(n===`arrowright`)t.currentTime=Math.min(t.duration||0,t.currentTime+Ga);else if(n===`arrowup`)this._setVolume(t.volume+Ka);else if(n===`arrowdown`)this._setVolume(t.volume-Ka);else if(n===`m`)this._setMuted(!t.muted);else if(n===`c`&&this.captionsButton)this._setCaptions(!this._captionsOn());else return;e.preventDefault()}}}));_();var Xa={pdf:`pdf`,jpg:`image`,jpeg:`image`,png:`image`,webp:`image`,gif:`image`,avif:`image`,bmp:`image`,svg:`image`,mp4:`video`,m4v:`video`,webm:`video`,ogv:`video`,mp3:`audio`,m4a:`audio`,aac:`audio`,wav:`audio`,ogg:`audio`,oga:`audio`,opus:`audio`,flac:`audio`},Za={"application/pdf":`pdf`,"image/jpeg":`image`,"image/png":`image`,"image/webp":`image`,"image/gif":`image`,"image/avif":`image`,"image/bmp":`image`,"image/svg+xml":`image`,"video/mp4":`video`,"video/webm":`video`,"video/ogg":`video`,"audio/mpeg":`audio`,"audio/mp4":`audio`,"audio/aac":`audio`,"audio/wav":`audio`,"audio/x-wav":`audio`,"audio/ogg":`audio`,"audio/opus":`audio`,"audio/webm":`audio`,"audio/flac":`audio`},Qa=`wui-file-viewer:load`,$a=`wui-file-viewer:error`,eo=`wui-file-viewer:prefs-change`;function to(e,t){let n=String(e??``).split(`;`)[0].trim().toLowerCase();if(n)return Za[n]??null;let r=String(t??``).split(/[?#]/)[0];return Xa[r.includes(`.`)?r.split(`.`).pop().toLowerCase():``]??null}function no(e){let t=String(e??``).split(/[?#]/)[0].split(`/`).filter(Boolean).pop()??``;try{return decodeURIComponent(t)}catch{return t}}var ro={pdf:()=>Promise.resolve().then(()=>(Na(),oa)).then(e=>e.PdfView),image:()=>Promise.resolve().then(()=>(Va(),Pa)).then(e=>e.ImageView),video:()=>Promise.resolve().then(()=>(Ya(),Ha)).then(e=>e.MediaView),audio:()=>Promise.resolve().then(()=>(Ya(),Ha)).then(e=>e.MediaView)},io=0,ao=class e extends i{static defaultAssetBase=``;static get observedAttributes(){return[`src`,`name`,`type`,`download`,`worker-src`,`asset-base`,`captions`]}constructor(){super(),io+=1,this.uid=`wui-file-viewer-${io}`,this._prefs={},this._onFullscreen=()=>this._syncFullscreen()}get src(){return this.getAttribute(`src`)??``}set src(e){this.setAttribute(`src`,String(e??``))}get name(){return this.getAttribute(`name`)??``}set name(e){this.setAttribute(`name`,String(e??``))}get type(){return this.getAttribute(`type`)??``}set type(e){this.setAttribute(`type`,String(e??``))}get viewKey(){return this.getAttribute(`view-key`)??``}set viewKey(e){this.setAttribute(`view-key`,String(e??``))}get download(){return this.hasAttribute(`download`)}set download(e){this.toggleAttribute(`download`,e===!0||e===``||e===`true`)}get workerSrc(){return this.getAttribute(`worker-src`)??``}set workerSrc(e){this.setAttribute(`worker-src`,String(e??``))}get captions(){return this.getAttribute(`captions`)??``}set captions(e){this.setAttribute(`captions`,String(e??``))}get assetBase(){return this.getAttribute(`asset-base`)??``}set assetBase(e){this.setAttribute(`asset-base`,String(e??``))}get prefs(){return{...this._prefs}}set prefs(e){this._hostPrefs=!0,this._prefs=e&&typeof e==`object`?{...e}:{}}get actionsContainer(){return this._actionsBox??null}seekTo(e){if(typeof e!=`number`||!Number.isFinite(e))throw TypeError(`[wui-file-viewer] seekTo takes a number of seconds; got ${String(e)}.`);return this._view?.seekTo?(this._view.seekTo(e),!0):!1}displayName(){return this.name||no(this.src)||`Document`}connectedCallback(){if(Object.hasOwn(this,`prefs`)){let e=this.prefs;delete this.prefs,this.prefs=e}document.addEventListener(`fullscreenchange`,this._onFullscreen),this._open()}disconnectedCallback(){document.removeEventListener(`fullscreenchange`,this._onFullscreen),this._close()}attributeChangedCallback(e,t,n){!this.isConnected||!this._parts||t===n||(e===`name`?this._parts.name.textContent=this.displayName():e===`download`?this._syncDownload():this._open())}_close(){this._view?.destroy(),this._view=null,this._loadId=(this._loadId??0)+1}async _open(){this._close();let t=this._loadId;this._render(),this._prefs=this._readPrefs();let n=to(this.type,this.name||this.src);if(!this.src){this._status(`No file to show.`);return}if(!n){this._status(`This file can't be shown here.`,{offerDownload:!0});return}this._status(`Loading...`);let r;try{r=await ro[n]()}catch(e){t===this._loadId&&this._fail(e);return}t===this._loadId&&(this._view=new r(this._shell(t),{src:this.src,kind:n,captions:this.captions,workerSrc:this.workerSrc,assetBase:oo(this.assetBase||e.defaultAssetBase)}),this._view.load())}_shell(e){let t=()=>e===this._loadId,n=this._parts;return{host:this,start:n.start,center:n.center,end:n.viewEnd,search:n.search,body:n.body,prefs:{...this._prefs},name:()=>this.displayName(),savePrefs:e=>{t()&&this._savePrefs(e)},loaded:e=>{t()&&(n.body.removeAttribute(`aria-busy`),this.dispatchEvent(new CustomEvent(Qa,{bubbles:!0,detail:e})))},fail:e=>{t()&&this._fail(e)}}}_render(){let e=(e,t)=>{let n=document.createElement(e);return n.className=t,n},t=e(`div`,`wui-file-viewer-toolbar`),n=e(`div`,`wui-file-viewer-group wui-file-viewer-start`),r=e(`span`,`wui-file-viewer-name`);r.textContent=this.displayName(),r.title=this.displayName(),n.append(r);let i=e(`div`,`wui-file-viewer-group wui-file-viewer-center`),a=e(`div`,`wui-file-viewer-group wui-file-viewer-end`),o=e(`div`,`wui-file-viewer-group wui-file-viewer-view-end`),s=e(`a`,`u-action wui-file-viewer-download`);s.style.setProperty(`--wui-action-size`,`32px`),m(s,`download`),h(s,`Download`);let c=p(`maximize-4`,`Full screen`,{className:`wui-file-viewer-fullscreen`});c.addEventListener(`click`,()=>this.toggleFullscreen()),c.hidden=!document.fullscreenEnabled,this._actionsBox??=e(`div`,`wui-file-viewer-actions`);let l=this._actionsBox;l.append(...this.querySelectorAll(`:scope > [slot="actions"]`)),a.append(o,s,c,l);let u=e(`search`,`wui-file-viewer-search`);u.hidden=!0,t.append(n,i,a,u);let d=e(`div`,`wui-file-viewer-body`);d.setAttribute(`aria-busy`,`true`),this.replaceChildren(t,d),this._parts={toolbar:t,start:n,name:r,center:i,end:a,viewEnd:o,downloadLink:s,fullscreen:c,actionsBox:l,search:u,body:d},this._syncDownload(),this._syncFullscreen()}_syncDownload(){let e=this._parts.downloadLink;e.hidden=!this.download||!this.src,e.href=this.src,e.setAttribute(`download`,this.displayName())}_status(e,{offerDownload:t=!1}={}){let n=document.createElement(`div`);n.className=`wui-file-viewer-status`;let r=document.createElement(`p`);if(r.textContent=e,n.append(r),t&&this.src){let e=document.createElement(`a`);e.className=`btn btn-sm btn-outline-secondary`,e.href=this.src,e.setAttribute(`download`,this.displayName()),e.textContent=`Download`,n.append(e)}this._parts.body.replaceChildren(n)}_fail(e){this._view?.destroy(),this._view=null,this._parts.body.removeAttribute(`aria-busy`),this._status(`Couldn't open this file.`,{offerDownload:!0}),this.dispatchEvent(new CustomEvent($a,{bubbles:!0,detail:{message:e?.message??String(e)}}))}toggleFullscreen(){if(document.fullscreenElement){document.exitFullscreen();return}this.requestFullscreen().catch(e=>{console.warn(`[wui-file-viewer] full screen refused:`,e?.message)})}_syncFullscreen(){if(!this._parts)return;let e=document.fullscreenElement===this,t=this._parts.fullscreen;m(t,e?`x`:`maximize-4`),h(t,e?`Exit full screen`:`Full screen`),this._parts.actionsBox.hidden=e}_readPrefs(){if(this._hostPrefs||!this.viewKey)return{...this._prefs};try{return JSON.parse(window.localStorage.getItem(`wui-view:${this.viewKey}`)??`{}`)??{}}catch{return{}}}_savePrefs(e){if(this._prefs={...this._prefs,...e},this.dispatchEvent(new CustomEvent(eo,{bubbles:!0,detail:{...this._prefs}})),!(this._hostPrefs||!this.viewKey))try{window.localStorage.setItem(`wui-view:${this.viewKey}`,JSON.stringify(this._prefs))}catch{}}};function oo(e){return e&&new URL(e,document.baseURI).href}var so=typeof document>`u`?null:document.currentScript;return so?.src&&(ao.defaultAssetBase=new URL(`pdfjs/`,so.src).href),typeof customElements<`u`&&!customElements.get(`wui-file-viewer`)&&customElements.define(`wui-file-viewer`,ao),e.WuiFileViewer=ao,e.fileKind=to,e.fileNameFromUrl=no,e.renderPdfFirstPage=(e,t)=>Promise.resolve().then(()=>(Na(),oa)).then(n=>n.renderFirstPage(e,{assetBase:ao.defaultAssetBase||void 0,...t})),e})({});
24
+ </style></head><body><img src="${Ba(n)}" alt=""></body></html>`,e.addEventListener(`load`,()=>{try{e.contentWindow.focus(),e.contentWindow.print()}catch(e){console.warn(`[wui-file-viewer] print failed:`,e?.message),window.open(this.source.src,`_blank`,`noopener`)}},{once:!0}),this._printFrame=e,document.body.append(e)}},Ba=e=>String(e??``).replace(/&/g,`&amp;`).replace(/</g,`&lt;`).replace(/>/g,`&gt;`).replace(/"/g,`&quot;`)})),Ha=r({MediaView:()=>Ja,formatTime:()=>Ua});function Ua(e){if(!Number.isFinite(e)||e<0)return`0:00`;let t=Math.floor(e),n=Math.floor(t/3600),r=Math.floor(t%3600/60),i=String(t%60).padStart(2,`0`);return n?`${n}:${String(r).padStart(2,`0`)}:${i}`:`${r}:${i}`}var Wa,Ga,Ka,qa,Ja,Ya=n((()=>{_(),f(),Wa=[.5,.75,1,1.25,1.5,2],Ga=5,Ka=.1,qa=e=>e instanceof Element&&e.closest(`input, textarea, select, button, a, .dropdown-menu`),Ja=class{constructor(e,t){this.shell=e,this.source=t,this.destroyed=!1}load(){let{kind:e,src:t,captions:n}=this.source,r=document.createElement(e);if(r.className=`wui-file-viewer-${e}`,r.preload=`metadata`,r.playsInline=!0,e===`video`&&n){let e=document.createElement(`track`);e.kind=`captions`,e.label=`Captions`,e.srclang=`en`,e.src=n,r.append(e)}let i=this.shell.prefs;typeof i.volume==`number`&&(r.volume=Math.min(Math.max(i.volume,0),1)),r.muted=i.muted===!0,r.addEventListener(`loadedmetadata`,()=>{this.destroyed||(r.playbackRate=Wa.includes(i.speed)?i.speed:1,this._build(),this.shell.loaded({kind:e,pages:1}))},{once:!0}),r.addEventListener(`error`,()=>{this.destroyed||this.shell.fail(Error(`The file could not be played.`))}),r.src=t,this.media=r}destroy(){this.destroyed=!0,this._onKeyDown&&this.shell.host.removeEventListener(`keydown`,this._onKeyDown),this.media&&(this.media.pause(),this.media.removeAttribute(`src`),this.media.load())}_build(){let{body:e,host:t}=this.shell,n=this.media,r=this.source.kind,i=document.createElement(`div`);i.className=`wui-file-viewer-player wui-file-viewer-player-${r}`;let a=document.createElement(`div`);if(a.className=`wui-file-viewer-stage`,a.tabIndex=0,a.setAttribute(`role`,`group`),a.setAttribute(`aria-label`,r===`video`?`Video`:`Audio`),r===`audio`){let e=document.createElement(`div`);e.className=`wui-file-viewer-audio-art`,e.innerHTML=u(`music`,{size:40}),a.append(e,n)}else a.append(n),n.addEventListener(`click`,()=>this.togglePlay());let o=document.createElement(`div`);o.className=`wui-file-viewer-controls`,this.playButton=p(`play`,`Play`,{size:18}),this.playButton.addEventListener(`click`,()=>this.togglePlay()),this.timeNow=document.createElement(`span`),this.timeNow.className=`wui-file-viewer-time`,this.seek=document.createElement(`input`),this.seek.type=`range`,this.seek.className=`form-range wui-file-viewer-seek`,this.seek.min=`0`,this.seek.step=`any`,this.seek.setAttribute(`aria-label`,`Seek`),this.seek.addEventListener(`input`,()=>{n.currentTime=Number(this.seek.value)}),this.timeTotal=document.createElement(`span`),this.timeTotal.className=`wui-file-viewer-time`,this.muteButton=p(`volume-high`,`Mute`,{size:18}),this.muteButton.addEventListener(`click`,()=>this._setMuted(!n.muted)),this.volume=document.createElement(`input`),this.volume.type=`range`,this.volume.className=`form-range wui-file-viewer-volume`,this.volume.min=`0`,this.volume.max=`1`,this.volume.step=`0.05`,this.volume.setAttribute(`aria-label`,`Volume`),this.volume.addEventListener(`input`,()=>this._setVolume(Number(this.volume.value))),this.speedButton=document.createElement(`button`),this.speedButton.type=`button`,this.speedButton.className=`wui-file-viewer-zoom wui-file-viewer-speed`,g(this.speedButton,{label:`Playback speed`,items:()=>Wa.map(e=>({key:String(e),label:`${e}x`,checked:n.playbackRate===e})),onPick:e=>this._setSpeed(Number(e))}),o.append(this.playButton,this.timeNow,this.seek,this.timeTotal,this.muteButton,this.volume,this.speedButton),r===`video`&&this.source.captions&&(this.captionsButton=p(`subtitle`,`Show captions`,{size:18}),this.captionsButton.addEventListener(`click`,()=>this._setCaptions(!this._captionsOn())),o.append(this.captionsButton)),i.append(a,o),e.replaceChildren(i);for(let e of[`play`,`pause`,`ended`])n.addEventListener(e,()=>this._syncPlay());n.addEventListener(`timeupdate`,()=>this._syncTime()),n.addEventListener(`durationchange`,()=>this._syncTime()),n.addEventListener(`volumechange`,()=>this._syncVolume()),n.addEventListener(`ratechange`,()=>this._syncSpeed()),this._onKeyDown=e=>this._keyDown(e),t.addEventListener(`keydown`,this._onKeyDown),this._syncPlay(),this._syncTime(),this._syncVolume(),this._syncSpeed(),this._syncCaptions()}seekTo(e){let t=this.media.duration;this.media.currentTime=Math.min(Math.max(e,0),Number.isFinite(t)?t:1/0)}togglePlay(){this.media.paused||this.media.ended?this.media.play().catch(e=>{console.warn(`[wui-file-viewer] play refused:`,e?.message)}):this.media.pause()}_setMuted(e){this.media.muted=e,!e&&this.media.volume===0&&(this.media.volume=.5),this.shell.savePrefs({muted:this.media.muted,volume:this.media.volume})}_setVolume(e){this.media.volume=Math.min(Math.max(e,0),1),this.media.muted=this.media.volume===0,this.shell.savePrefs({muted:this.media.muted,volume:this.media.volume})}_setSpeed(e){this.media.playbackRate=e,this.shell.savePrefs({speed:e})}_captionsOn(){return this.media.textTracks?.[0]?.mode===`showing`}_setCaptions(e){let t=this.media.textTracks?.[0];t&&(t.mode=e?`showing`:`hidden`),this._syncCaptions()}_syncPlay(){let e=!this.media.paused&&!this.media.ended;m(this.playButton,e?`pause`:`play`,18),h(this.playButton,e?`Pause`:`Play`),this.shell.host.classList.toggle(`wui-file-viewer-playing`,e)}_syncTime(){let e=this.media.currentTime,t=this.media.duration;this.timeNow.textContent=Ua(e),this.timeTotal.textContent=Ua(t),this.seek.max=String(Number.isFinite(t)?t:0),this.seek.value=String(e),this.seek.setAttribute(`aria-valuetext`,`${Ua(e)} of ${Ua(t)}`)}_syncVolume(){let e=this.media.muted||this.media.volume===0;m(this.muteButton,e?`volume-mute`:`volume-high`,18),h(this.muteButton,e?`Unmute`:`Mute`),this.volume.value=String(this.media.muted?0:this.media.volume)}_syncSpeed(){let e=`${this.media.playbackRate}x`;this.speedButton.textContent=e,this.speedButton.setAttribute(`aria-label`,`Playback speed, ${e}`)}_syncCaptions(){if(!this.captionsButton)return;let e=this._captionsOn();this.captionsButton.setAttribute(`aria-pressed`,String(e)),h(this.captionsButton,e?`Hide captions`:`Show captions`)}_keyDown(e){if(e.defaultPrevented||e.altKey||e.ctrlKey||e.metaKey||qa(e.target))return;let t=this.media,n=e.key.toLowerCase();if(n===` `||n===`k`)this.togglePlay();else if(n===`arrowleft`)t.currentTime=Math.max(0,t.currentTime-Ga);else if(n===`arrowright`)t.currentTime=Math.min(t.duration||0,t.currentTime+Ga);else if(n===`arrowup`)this._setVolume(t.volume+Ka);else if(n===`arrowdown`)this._setVolume(t.volume-Ka);else if(n===`m`)this._setMuted(!t.muted);else if(n===`c`&&this.captionsButton)this._setCaptions(!this._captionsOn());else return;e.preventDefault()}}}));_();var Xa={pdf:`pdf`,jpg:`image`,jpeg:`image`,png:`image`,webp:`image`,gif:`image`,avif:`image`,bmp:`image`,svg:`image`,mp4:`video`,m4v:`video`,webm:`video`,ogv:`video`,mp3:`audio`,m4a:`audio`,aac:`audio`,wav:`audio`,ogg:`audio`,oga:`audio`,opus:`audio`,flac:`audio`},Za={"application/pdf":`pdf`,"image/jpeg":`image`,"image/png":`image`,"image/webp":`image`,"image/gif":`image`,"image/avif":`image`,"image/bmp":`image`,"image/svg+xml":`image`,"video/mp4":`video`,"video/webm":`video`,"video/ogg":`video`,"audio/mpeg":`audio`,"audio/mp4":`audio`,"audio/aac":`audio`,"audio/wav":`audio`,"audio/x-wav":`audio`,"audio/ogg":`audio`,"audio/opus":`audio`,"audio/webm":`audio`,"audio/flac":`audio`},Qa=`wui-file-viewer:load`,$a=`wui-file-viewer:error`,eo=`wui-file-viewer:prefs-change`;function to(e,t){let n=String(e??``).split(`;`)[0].trim().toLowerCase();if(n)return Za[n]??null;let r=String(t??``).split(/[?#]/)[0];return Xa[r.includes(`.`)?r.split(`.`).pop().toLowerCase():``]??null}function no(e){let t=String(e??``).split(/[?#]/)[0].split(`/`).filter(Boolean).pop()??``;try{return decodeURIComponent(t)}catch{return t}}var ro={pdf:()=>Promise.resolve().then(()=>(Na(),oa)).then(e=>e.PdfView),image:()=>Promise.resolve().then(()=>(Va(),Pa)).then(e=>e.ImageView),video:()=>Promise.resolve().then(()=>(Ya(),Ha)).then(e=>e.MediaView),audio:()=>Promise.resolve().then(()=>(Ya(),Ha)).then(e=>e.MediaView)},io=0,ao=class e extends i{static defaultAssetBase=``;static get observedAttributes(){return[`src`,`name`,`type`,`download`,`print`,`worker-src`,`asset-base`,`captions`]}constructor(){super(),io+=1,this.uid=`wui-file-viewer-${io}`,this._prefs={},this._onFullscreen=()=>this._syncFullscreen()}get src(){return this.getAttribute(`src`)??``}set src(e){this.setAttribute(`src`,String(e??``))}get name(){return this.getAttribute(`name`)??``}set name(e){this.setAttribute(`name`,String(e??``))}get type(){return this.getAttribute(`type`)??``}set type(e){this.setAttribute(`type`,String(e??``))}get viewKey(){return this.getAttribute(`view-key`)??``}set viewKey(e){this.setAttribute(`view-key`,String(e??``))}get download(){return this.hasAttribute(`download`)}set download(e){this.toggleAttribute(`download`,e===!0||e===``||e===`true`)}get print(){return this.getAttribute(`print`)!==`false`}set print(e){this.setAttribute(`print`,e===!1||e===`false`?`false`:`true`)}get workerSrc(){return this.getAttribute(`worker-src`)??``}set workerSrc(e){this.setAttribute(`worker-src`,String(e??``))}get captions(){return this.getAttribute(`captions`)??``}set captions(e){this.setAttribute(`captions`,String(e??``))}get assetBase(){return this.getAttribute(`asset-base`)??``}set assetBase(e){this.setAttribute(`asset-base`,String(e??``))}get prefs(){return{...this._prefs}}set prefs(e){this._hostPrefs=!0,this._prefs=e&&typeof e==`object`?{...e}:{}}get actionsContainer(){return this._actionsBox??null}seekTo(e){if(typeof e!=`number`||!Number.isFinite(e))throw TypeError(`[wui-file-viewer] seekTo takes a number of seconds; got ${String(e)}.`);return this._view?.seekTo?(this._view.seekTo(e),!0):!1}displayName(){return this.name||no(this.src)||`Document`}connectedCallback(){if(Object.hasOwn(this,`prefs`)){let e=this.prefs;delete this.prefs,this.prefs=e}document.addEventListener(`fullscreenchange`,this._onFullscreen),this._open()}disconnectedCallback(){document.removeEventListener(`fullscreenchange`,this._onFullscreen),this._close()}attributeChangedCallback(e,t,n){!this.isConnected||!this._parts||t===n||(e===`name`?this._parts.name.textContent=this.displayName():e===`download`?this._syncDownload():e===`print`?this._syncPrint():this._open())}_close(){this._view?.destroy(),this._view=null,this._loadId=(this._loadId??0)+1}async _open(){this._close();let t=this._loadId;this._render(),this._prefs=this._readPrefs();let n=to(this.type,this.name||this.src);if(!this.src){this._status(`No file to show.`);return}if(!n){this._status(`This file can't be shown here.`,{offerDownload:!0});return}this._status(`Loading...`);let r;try{r=await ro[n]()}catch(e){t===this._loadId&&this._fail(e);return}t===this._loadId&&(this._view=new r(this._shell(t),{src:this.src,kind:n,captions:this.captions,workerSrc:this.workerSrc,assetBase:oo(this.assetBase||e.defaultAssetBase)}),this._view.load())}_shell(e){let t=()=>e===this._loadId,n=this._parts;return{host:this,start:n.start,center:n.center,end:n.viewEnd,search:n.search,body:n.body,prefs:{...this._prefs},name:()=>this.displayName(),print:()=>this.print,savePrefs:e=>{t()&&this._savePrefs(e)},loaded:e=>{t()&&(n.body.removeAttribute(`aria-busy`),this.dispatchEvent(new CustomEvent(Qa,{bubbles:!0,detail:e})))},fail:e=>{t()&&this._fail(e)}}}_render(){let e=(e,t)=>{let n=document.createElement(e);return n.className=t,n},t=e(`div`,`wui-file-viewer-toolbar`),n=e(`div`,`wui-file-viewer-group wui-file-viewer-start`),r=e(`span`,`wui-file-viewer-name`);r.textContent=this.displayName(),r.title=this.displayName(),n.append(r);let i=e(`div`,`wui-file-viewer-group wui-file-viewer-center`),a=e(`div`,`wui-file-viewer-group wui-file-viewer-end`),o=e(`div`,`wui-file-viewer-group wui-file-viewer-view-end`),s=e(`a`,`u-action wui-file-viewer-download`);s.style.setProperty(`--wui-action-size`,`32px`),m(s,`download`),h(s,`Download`);let c=p(`maximize-4`,`Full screen`,{className:`wui-file-viewer-fullscreen`});c.addEventListener(`click`,()=>this.toggleFullscreen()),c.hidden=!document.fullscreenEnabled,this._actionsBox??=e(`div`,`wui-file-viewer-actions`);let l=this._actionsBox;l.append(...this.querySelectorAll(`:scope > [slot="actions"]`)),a.append(o,s,c,l);let u=e(`search`,`wui-file-viewer-search`);u.hidden=!0,t.append(n,i,a,u);let d=e(`div`,`wui-file-viewer-body`);d.setAttribute(`aria-busy`,`true`),this.replaceChildren(t,d),this._parts={toolbar:t,start:n,name:r,center:i,end:a,viewEnd:o,downloadLink:s,fullscreen:c,actionsBox:l,search:u,body:d},this._syncDownload(),this._syncFullscreen()}_syncDownload(){let e=this._parts.downloadLink;e.hidden=!this.download||!this.src,e.href=this.src,e.setAttribute(`download`,this.displayName())}_syncPrint(){for(let e of this._parts.toolbar.querySelectorAll(`.wui-file-viewer-print`))e.hidden=!this.print}_status(e,{offerDownload:t=!1}={}){let n=document.createElement(`div`);n.className=`wui-file-viewer-status`;let r=document.createElement(`p`);if(r.textContent=e,n.append(r),t&&this.src){let e=document.createElement(`a`);e.className=`btn btn-sm btn-outline-secondary`,e.href=this.src,e.setAttribute(`download`,this.displayName()),e.textContent=`Download`,n.append(e)}this._parts.body.replaceChildren(n)}_fail(e){this._view?.destroy(),this._view=null,this._parts.body.removeAttribute(`aria-busy`),this._status(`Couldn't open this file.`,{offerDownload:!0}),this.dispatchEvent(new CustomEvent($a,{bubbles:!0,detail:{message:e?.message??String(e)}}))}toggleFullscreen(){if(document.fullscreenElement){document.exitFullscreen();return}this.requestFullscreen().catch(e=>{console.warn(`[wui-file-viewer] full screen refused:`,e?.message)})}_syncFullscreen(){if(!this._parts)return;let e=document.fullscreenElement===this,t=this._parts.fullscreen;m(t,e?`x`:`maximize-4`),h(t,e?`Exit full screen`:`Full screen`),this._parts.actionsBox.hidden=e}_readPrefs(){if(this._hostPrefs||!this.viewKey)return{...this._prefs};try{return JSON.parse(window.localStorage.getItem(`wui-view:${this.viewKey}`)??`{}`)??{}}catch{return{}}}_savePrefs(e){if(this._prefs={...this._prefs,...e},this.dispatchEvent(new CustomEvent(eo,{bubbles:!0,detail:{...this._prefs}})),!(this._hostPrefs||!this.viewKey))try{window.localStorage.setItem(`wui-view:${this.viewKey}`,JSON.stringify(this._prefs))}catch{}}};function oo(e){return e&&new URL(e,document.baseURI).href}var so=typeof document>`u`?null:document.currentScript;return so?.src&&(ao.defaultAssetBase=new URL(`pdfjs/`,so.src).href),typeof customElements<`u`&&!customElements.get(`wui-file-viewer`)&&customElements.define(`wui-file-viewer`,ao),e.WuiFileViewer=ao,e.fileKind=to,e.fileNameFromUrl=no,e.renderPdfFirstPage=(e,t)=>Promise.resolve().then(()=>(Na(),oa)).then(n=>n.renderFirstPage(e,{assetBase:ao.defaultAssetBase||void 0,...t})),e})({});
@@ -1 +1 @@
1
- import{i as e,r as t,t as n}from"./fileViewerUi-DasgDsU-.js";var r=typeof HTMLElement>`u`?class{}:HTMLElement,i={pdf:`pdf`,jpg:`image`,jpeg:`image`,png:`image`,webp:`image`,gif:`image`,avif:`image`,bmp:`image`,svg:`image`,mp4:`video`,m4v:`video`,webm:`video`,ogv:`video`,mp3:`audio`,m4a:`audio`,aac:`audio`,wav:`audio`,ogg:`audio`,oga:`audio`,opus:`audio`,flac:`audio`},a={"application/pdf":`pdf`,"image/jpeg":`image`,"image/png":`image`,"image/webp":`image`,"image/gif":`image`,"image/avif":`image`,"image/bmp":`image`,"image/svg+xml":`image`,"video/mp4":`video`,"video/webm":`video`,"video/ogg":`video`,"audio/mpeg":`audio`,"audio/mp4":`audio`,"audio/aac":`audio`,"audio/wav":`audio`,"audio/x-wav":`audio`,"audio/ogg":`audio`,"audio/opus":`audio`,"audio/webm":`audio`,"audio/flac":`audio`},o=`wui-file-viewer:load`,s=`wui-file-viewer:error`,c=`wui-file-viewer:prefs-change`;function l(e,t){let n=String(e??``).split(`;`)[0].trim().toLowerCase();if(n)return a[n]??null;let r=String(t??``).split(/[?#]/)[0];return i[r.includes(`.`)?r.split(`.`).pop().toLowerCase():``]??null}function u(e){let t=String(e??``).split(/[?#]/)[0].split(`/`).filter(Boolean).pop()??``;try{return decodeURIComponent(t)}catch{return t}}var d={pdf:()=>import(`./fileViewerPdf-BoBPB1so.js`).then(e=>e.PdfView),image:()=>import(`./fileViewerImage-Y9QBn2Rj.js`).then(e=>e.ImageView),video:()=>import(`./fileViewerMedia-CaJaVnjE.js`).then(e=>e.MediaView),audio:()=>import(`./fileViewerMedia-CaJaVnjE.js`).then(e=>e.MediaView)},f=0,p=class i extends r{static defaultAssetBase=``;static get observedAttributes(){return[`src`,`name`,`type`,`download`,`worker-src`,`asset-base`,`captions`]}constructor(){super(),f+=1,this.uid=`wui-file-viewer-${f}`,this._prefs={},this._onFullscreen=()=>this._syncFullscreen()}get src(){return this.getAttribute(`src`)??``}set src(e){this.setAttribute(`src`,String(e??``))}get name(){return this.getAttribute(`name`)??``}set name(e){this.setAttribute(`name`,String(e??``))}get type(){return this.getAttribute(`type`)??``}set type(e){this.setAttribute(`type`,String(e??``))}get viewKey(){return this.getAttribute(`view-key`)??``}set viewKey(e){this.setAttribute(`view-key`,String(e??``))}get download(){return this.hasAttribute(`download`)}set download(e){this.toggleAttribute(`download`,e===!0||e===``||e===`true`)}get workerSrc(){return this.getAttribute(`worker-src`)??``}set workerSrc(e){this.setAttribute(`worker-src`,String(e??``))}get captions(){return this.getAttribute(`captions`)??``}set captions(e){this.setAttribute(`captions`,String(e??``))}get assetBase(){return this.getAttribute(`asset-base`)??``}set assetBase(e){this.setAttribute(`asset-base`,String(e??``))}get prefs(){return{...this._prefs}}set prefs(e){this._hostPrefs=!0,this._prefs=e&&typeof e==`object`?{...e}:{}}get actionsContainer(){return this._actionsBox??null}seekTo(e){if(typeof e!=`number`||!Number.isFinite(e))throw TypeError(`[wui-file-viewer] seekTo takes a number of seconds; got ${String(e)}.`);return this._view?.seekTo?(this._view.seekTo(e),!0):!1}displayName(){return this.name||u(this.src)||`Document`}connectedCallback(){if(Object.hasOwn(this,`prefs`)){let e=this.prefs;delete this.prefs,this.prefs=e}document.addEventListener(`fullscreenchange`,this._onFullscreen),this._open()}disconnectedCallback(){document.removeEventListener(`fullscreenchange`,this._onFullscreen),this._close()}attributeChangedCallback(e,t,n){!this.isConnected||!this._parts||t===n||(e===`name`?this._parts.name.textContent=this.displayName():e===`download`?this._syncDownload():this._open())}_close(){this._view?.destroy(),this._view=null,this._loadId=(this._loadId??0)+1}async _open(){this._close();let e=this._loadId;this._render(),this._prefs=this._readPrefs();let t=l(this.type,this.name||this.src);if(!this.src){this._status(`No file to show.`);return}if(!t){this._status(`This file can't be shown here.`,{offerDownload:!0});return}this._status(`Loading...`);let n;try{n=await d[t]()}catch(t){e===this._loadId&&this._fail(t);return}e===this._loadId&&(this._view=new n(this._shell(e),{src:this.src,kind:t,captions:this.captions,workerSrc:this.workerSrc,assetBase:m(this.assetBase||i.defaultAssetBase)}),this._view.load())}_shell(e){let t=()=>e===this._loadId,n=this._parts;return{host:this,start:n.start,center:n.center,end:n.viewEnd,search:n.search,body:n.body,prefs:{...this._prefs},name:()=>this.displayName(),savePrefs:e=>{t()&&this._savePrefs(e)},loaded:e=>{t()&&(n.body.removeAttribute(`aria-busy`),this.dispatchEvent(new CustomEvent(o,{bubbles:!0,detail:e})))},fail:e=>{t()&&this._fail(e)}}}_render(){let r=(e,t)=>{let n=document.createElement(e);return n.className=t,n},i=r(`div`,`wui-file-viewer-toolbar`),a=r(`div`,`wui-file-viewer-group wui-file-viewer-start`),o=r(`span`,`wui-file-viewer-name`);o.textContent=this.displayName(),o.title=this.displayName(),a.append(o);let s=r(`div`,`wui-file-viewer-group wui-file-viewer-center`),c=r(`div`,`wui-file-viewer-group wui-file-viewer-end`),l=r(`div`,`wui-file-viewer-group wui-file-viewer-view-end`),u=r(`a`,`u-action wui-file-viewer-download`);u.style.setProperty(`--wui-action-size`,`32px`),t(u,`download`),e(u,`Download`);let d=n(`maximize-4`,`Full screen`,{className:`wui-file-viewer-fullscreen`});d.addEventListener(`click`,()=>this.toggleFullscreen()),d.hidden=!document.fullscreenEnabled,this._actionsBox??=r(`div`,`wui-file-viewer-actions`);let f=this._actionsBox;f.append(...this.querySelectorAll(`:scope > [slot="actions"]`)),c.append(l,u,d,f);let p=r(`search`,`wui-file-viewer-search`);p.hidden=!0,i.append(a,s,c,p);let m=r(`div`,`wui-file-viewer-body`);m.setAttribute(`aria-busy`,`true`),this.replaceChildren(i,m),this._parts={toolbar:i,start:a,name:o,center:s,end:c,viewEnd:l,downloadLink:u,fullscreen:d,actionsBox:f,search:p,body:m},this._syncDownload(),this._syncFullscreen()}_syncDownload(){let e=this._parts.downloadLink;e.hidden=!this.download||!this.src,e.href=this.src,e.setAttribute(`download`,this.displayName())}_status(e,{offerDownload:t=!1}={}){let n=document.createElement(`div`);n.className=`wui-file-viewer-status`;let r=document.createElement(`p`);if(r.textContent=e,n.append(r),t&&this.src){let e=document.createElement(`a`);e.className=`btn btn-sm btn-outline-secondary`,e.href=this.src,e.setAttribute(`download`,this.displayName()),e.textContent=`Download`,n.append(e)}this._parts.body.replaceChildren(n)}_fail(e){this._view?.destroy(),this._view=null,this._parts.body.removeAttribute(`aria-busy`),this._status(`Couldn't open this file.`,{offerDownload:!0}),this.dispatchEvent(new CustomEvent(s,{bubbles:!0,detail:{message:e?.message??String(e)}}))}toggleFullscreen(){if(document.fullscreenElement){document.exitFullscreen();return}this.requestFullscreen().catch(e=>{console.warn(`[wui-file-viewer] full screen refused:`,e?.message)})}_syncFullscreen(){if(!this._parts)return;let n=document.fullscreenElement===this,r=this._parts.fullscreen;t(r,n?`x`:`maximize-4`),e(r,n?`Exit full screen`:`Full screen`),this._parts.actionsBox.hidden=n}_readPrefs(){if(this._hostPrefs||!this.viewKey)return{...this._prefs};try{return JSON.parse(window.localStorage.getItem(`wui-view:${this.viewKey}`)??`{}`)??{}}catch{return{}}}_savePrefs(e){if(this._prefs={...this._prefs,...e},this.dispatchEvent(new CustomEvent(c,{bubbles:!0,detail:{...this._prefs}})),!(this._hostPrefs||!this.viewKey))try{window.localStorage.setItem(`wui-view:${this.viewKey}`,JSON.stringify(this._prefs))}catch{}}};function m(e){return e&&new URL(e,document.baseURI).href}var h=typeof document>`u`?null:document.currentScript;h?.src&&(p.defaultAssetBase=new URL(`pdfjs/`,h.src).href),typeof customElements<`u`&&!customElements.get(`wui-file-viewer`)&&customElements.define(`wui-file-viewer`,p);var g=(e,t)=>import(`./fileViewerPdf-BoBPB1so.js`).then(n=>n.renderFirstPage(e,{assetBase:p.defaultAssetBase||void 0,...t}));export{p as WuiFileViewer,l as fileKind,u as fileNameFromUrl,g as renderPdfFirstPage};
1
+ import{i as e,r as t,t as n}from"./fileViewerUi-DasgDsU-.js";var r=typeof HTMLElement>`u`?class{}:HTMLElement,i={pdf:`pdf`,jpg:`image`,jpeg:`image`,png:`image`,webp:`image`,gif:`image`,avif:`image`,bmp:`image`,svg:`image`,mp4:`video`,m4v:`video`,webm:`video`,ogv:`video`,mp3:`audio`,m4a:`audio`,aac:`audio`,wav:`audio`,ogg:`audio`,oga:`audio`,opus:`audio`,flac:`audio`},a={"application/pdf":`pdf`,"image/jpeg":`image`,"image/png":`image`,"image/webp":`image`,"image/gif":`image`,"image/avif":`image`,"image/bmp":`image`,"image/svg+xml":`image`,"video/mp4":`video`,"video/webm":`video`,"video/ogg":`video`,"audio/mpeg":`audio`,"audio/mp4":`audio`,"audio/aac":`audio`,"audio/wav":`audio`,"audio/x-wav":`audio`,"audio/ogg":`audio`,"audio/opus":`audio`,"audio/webm":`audio`,"audio/flac":`audio`},o=`wui-file-viewer:load`,s=`wui-file-viewer:error`,c=`wui-file-viewer:prefs-change`;function l(e,t){let n=String(e??``).split(`;`)[0].trim().toLowerCase();if(n)return a[n]??null;let r=String(t??``).split(/[?#]/)[0];return i[r.includes(`.`)?r.split(`.`).pop().toLowerCase():``]??null}function u(e){let t=String(e??``).split(/[?#]/)[0].split(`/`).filter(Boolean).pop()??``;try{return decodeURIComponent(t)}catch{return t}}var d={pdf:()=>import(`./fileViewerPdf-DGU_-iub.js`).then(e=>e.PdfView),image:()=>import(`./fileViewerImage-Bis2gnyc.js`).then(e=>e.ImageView),video:()=>import(`./fileViewerMedia-CaJaVnjE.js`).then(e=>e.MediaView),audio:()=>import(`./fileViewerMedia-CaJaVnjE.js`).then(e=>e.MediaView)},f=0,p=class i extends r{static defaultAssetBase=``;static get observedAttributes(){return[`src`,`name`,`type`,`download`,`print`,`worker-src`,`asset-base`,`captions`]}constructor(){super(),f+=1,this.uid=`wui-file-viewer-${f}`,this._prefs={},this._onFullscreen=()=>this._syncFullscreen()}get src(){return this.getAttribute(`src`)??``}set src(e){this.setAttribute(`src`,String(e??``))}get name(){return this.getAttribute(`name`)??``}set name(e){this.setAttribute(`name`,String(e??``))}get type(){return this.getAttribute(`type`)??``}set type(e){this.setAttribute(`type`,String(e??``))}get viewKey(){return this.getAttribute(`view-key`)??``}set viewKey(e){this.setAttribute(`view-key`,String(e??``))}get download(){return this.hasAttribute(`download`)}set download(e){this.toggleAttribute(`download`,e===!0||e===``||e===`true`)}get print(){return this.getAttribute(`print`)!==`false`}set print(e){this.setAttribute(`print`,e===!1||e===`false`?`false`:`true`)}get workerSrc(){return this.getAttribute(`worker-src`)??``}set workerSrc(e){this.setAttribute(`worker-src`,String(e??``))}get captions(){return this.getAttribute(`captions`)??``}set captions(e){this.setAttribute(`captions`,String(e??``))}get assetBase(){return this.getAttribute(`asset-base`)??``}set assetBase(e){this.setAttribute(`asset-base`,String(e??``))}get prefs(){return{...this._prefs}}set prefs(e){this._hostPrefs=!0,this._prefs=e&&typeof e==`object`?{...e}:{}}get actionsContainer(){return this._actionsBox??null}seekTo(e){if(typeof e!=`number`||!Number.isFinite(e))throw TypeError(`[wui-file-viewer] seekTo takes a number of seconds; got ${String(e)}.`);return this._view?.seekTo?(this._view.seekTo(e),!0):!1}displayName(){return this.name||u(this.src)||`Document`}connectedCallback(){if(Object.hasOwn(this,`prefs`)){let e=this.prefs;delete this.prefs,this.prefs=e}document.addEventListener(`fullscreenchange`,this._onFullscreen),this._open()}disconnectedCallback(){document.removeEventListener(`fullscreenchange`,this._onFullscreen),this._close()}attributeChangedCallback(e,t,n){!this.isConnected||!this._parts||t===n||(e===`name`?this._parts.name.textContent=this.displayName():e===`download`?this._syncDownload():e===`print`?this._syncPrint():this._open())}_close(){this._view?.destroy(),this._view=null,this._loadId=(this._loadId??0)+1}async _open(){this._close();let e=this._loadId;this._render(),this._prefs=this._readPrefs();let t=l(this.type,this.name||this.src);if(!this.src){this._status(`No file to show.`);return}if(!t){this._status(`This file can't be shown here.`,{offerDownload:!0});return}this._status(`Loading...`);let n;try{n=await d[t]()}catch(t){e===this._loadId&&this._fail(t);return}e===this._loadId&&(this._view=new n(this._shell(e),{src:this.src,kind:t,captions:this.captions,workerSrc:this.workerSrc,assetBase:m(this.assetBase||i.defaultAssetBase)}),this._view.load())}_shell(e){let t=()=>e===this._loadId,n=this._parts;return{host:this,start:n.start,center:n.center,end:n.viewEnd,search:n.search,body:n.body,prefs:{...this._prefs},name:()=>this.displayName(),print:()=>this.print,savePrefs:e=>{t()&&this._savePrefs(e)},loaded:e=>{t()&&(n.body.removeAttribute(`aria-busy`),this.dispatchEvent(new CustomEvent(o,{bubbles:!0,detail:e})))},fail:e=>{t()&&this._fail(e)}}}_render(){let r=(e,t)=>{let n=document.createElement(e);return n.className=t,n},i=r(`div`,`wui-file-viewer-toolbar`),a=r(`div`,`wui-file-viewer-group wui-file-viewer-start`),o=r(`span`,`wui-file-viewer-name`);o.textContent=this.displayName(),o.title=this.displayName(),a.append(o);let s=r(`div`,`wui-file-viewer-group wui-file-viewer-center`),c=r(`div`,`wui-file-viewer-group wui-file-viewer-end`),l=r(`div`,`wui-file-viewer-group wui-file-viewer-view-end`),u=r(`a`,`u-action wui-file-viewer-download`);u.style.setProperty(`--wui-action-size`,`32px`),t(u,`download`),e(u,`Download`);let d=n(`maximize-4`,`Full screen`,{className:`wui-file-viewer-fullscreen`});d.addEventListener(`click`,()=>this.toggleFullscreen()),d.hidden=!document.fullscreenEnabled,this._actionsBox??=r(`div`,`wui-file-viewer-actions`);let f=this._actionsBox;f.append(...this.querySelectorAll(`:scope > [slot="actions"]`)),c.append(l,u,d,f);let p=r(`search`,`wui-file-viewer-search`);p.hidden=!0,i.append(a,s,c,p);let m=r(`div`,`wui-file-viewer-body`);m.setAttribute(`aria-busy`,`true`),this.replaceChildren(i,m),this._parts={toolbar:i,start:a,name:o,center:s,end:c,viewEnd:l,downloadLink:u,fullscreen:d,actionsBox:f,search:p,body:m},this._syncDownload(),this._syncFullscreen()}_syncDownload(){let e=this._parts.downloadLink;e.hidden=!this.download||!this.src,e.href=this.src,e.setAttribute(`download`,this.displayName())}_syncPrint(){for(let e of this._parts.toolbar.querySelectorAll(`.wui-file-viewer-print`))e.hidden=!this.print}_status(e,{offerDownload:t=!1}={}){let n=document.createElement(`div`);n.className=`wui-file-viewer-status`;let r=document.createElement(`p`);if(r.textContent=e,n.append(r),t&&this.src){let e=document.createElement(`a`);e.className=`btn btn-sm btn-outline-secondary`,e.href=this.src,e.setAttribute(`download`,this.displayName()),e.textContent=`Download`,n.append(e)}this._parts.body.replaceChildren(n)}_fail(e){this._view?.destroy(),this._view=null,this._parts.body.removeAttribute(`aria-busy`),this._status(`Couldn't open this file.`,{offerDownload:!0}),this.dispatchEvent(new CustomEvent(s,{bubbles:!0,detail:{message:e?.message??String(e)}}))}toggleFullscreen(){if(document.fullscreenElement){document.exitFullscreen();return}this.requestFullscreen().catch(e=>{console.warn(`[wui-file-viewer] full screen refused:`,e?.message)})}_syncFullscreen(){if(!this._parts)return;let n=document.fullscreenElement===this,r=this._parts.fullscreen;t(r,n?`x`:`maximize-4`),e(r,n?`Exit full screen`:`Full screen`),this._parts.actionsBox.hidden=n}_readPrefs(){if(this._hostPrefs||!this.viewKey)return{...this._prefs};try{return JSON.parse(window.localStorage.getItem(`wui-view:${this.viewKey}`)??`{}`)??{}}catch{return{}}}_savePrefs(e){if(this._prefs={...this._prefs,...e},this.dispatchEvent(new CustomEvent(c,{bubbles:!0,detail:{...this._prefs}})),!(this._hostPrefs||!this.viewKey))try{window.localStorage.setItem(`wui-view:${this.viewKey}`,JSON.stringify(this._prefs))}catch{}}};function m(e){return e&&new URL(e,document.baseURI).href}var h=typeof document>`u`?null:document.currentScript;h?.src&&(p.defaultAssetBase=new URL(`pdfjs/`,h.src).href),typeof customElements<`u`&&!customElements.get(`wui-file-viewer`)&&customElements.define(`wui-file-viewer`,p);var g=(e,t)=>import(`./fileViewerPdf-DGU_-iub.js`).then(n=>n.renderFirstPage(e,{assetBase:p.defaultAssetBase||void 0,...t}));export{p as WuiFileViewer,l as fileKind,u as fileNameFromUrl,g as renderPdfFirstPage};
@@ -1 +1 @@
1
- (function(){function e(e,t){typeof customElements<`u`&&!customElements.get(e)&&customElements.define(e,t)}var t=typeof HTMLElement>`u`?class{}:HTMLElement,n=4,r=300,i=400;function a(e,t,a={}){if(!e||!t)return;let o=e.getBoundingClientRect(),s=a.clampHeight?t.scrollTop:0;a.clampHeight&&(t.style.maxHeight=``);let c=t.offsetHeight,l=window.innerHeight-o.bottom,u=l<c+n&&o.top>l;if(t.classList.toggle(`drop-up`,u),t.style.position=`fixed`,t.style.top=u?`${Math.max(n,o.top-c-n)}px`:`${o.bottom+n}px`,a.clampHeight){let e=u?o.top-n*2:window.innerHeight-o.bottom-n*2;e<c&&(t.style.maxHeight=`${Math.max(e,0)}px`),t.scrollTop=s}a.matchWidth&&(o.width>=r?(t.style.minWidth=`${o.width}px`,t.style.width=`${o.width}px`,t.style.maxWidth=`${o.width}px`):(t.style.minWidth=`${o.width}px`,t.style.width=`max-content`,t.style.maxWidth=`${Math.min(i,window.innerWidth-n*2)}px`));let d=t.offsetWidth,f=Math.min(o.left,window.innerWidth-d-n);t.style.left=`${Math.max(n,f)}px`}function o(e,t){s(e),e._reanchor=t,e._reanchorScroll=n=>{n.target instanceof Node&&typeof e.contains==`function`&&e.contains(n.target)||t()},window.addEventListener(`resize`,e._reanchor),window.addEventListener(`scroll`,e._reanchorScroll,!0)}function s(e){e?._reanchor&&(window.removeEventListener(`resize`,e._reanchor),window.removeEventListener(`scroll`,e._reanchorScroll,!0),e._reanchor=null,e._reanchorScroll=null)}var c=` :host { all: initial; ${Object.entries({"--wui-z-tour":`1550`,"--wui-radius-sm":`8px`,"--wui-radius-lg":`14px`,"--wui-shadow-overlay":`0 8px 28px -6px rgba(7, 20, 55, 0.14)`,"--color-primary":`#4F46E5`,"--color-primary-hover":`#4338CA`,"--color-primary-ink":`#4F46E5`,"--color-primary-text":`#FFFFFF`,"--color-scrim-strong":`color-mix(in srgb, #071437 62%, transparent)`,"--color-surface":`#FFFFFF`,"--color-text":`#071437`,"--color-text-muted":`#4B5675`,"--color-border":`#EBEDF3`}).map(([e,t])=>` ${e}: ${t};`).join(` `)} } *, *::before, *::after { box-sizing: border-box; } [hidden] { display: none !important; } .visually-hidden { position: absolute !important; width: 1px !important; height: 1px !important; padding: 0 !important; margin: -1px !important; overflow: hidden !important; clip: rect(0, 0, 0, 0) !important; white-space: nowrap !important; border: 0 !important; } .btn { display: inline-block; margin: 0; padding: 0.25rem 0.5rem; border: 1px solid transparent; border-radius: 0.375rem; background: transparent; font: inherit; font-size: 0.875rem; font-weight: 500; line-height: 1.5; text-align: center; text-decoration: none; white-space: nowrap; cursor: pointer; } .btn:focus-visible { outline: 2px solid var(--color-primary); outline-offset: 2px; } .btn-primary { background: var(--color-primary); border-color: var(--color-primary); color: var(--color-primary-text); } .btn-primary:hover { background: var(--color-primary-hover); border-color: var(--color-primary-hover); } .btn-outline-secondary { border-color: var(--color-text-muted); color: var(--color-text-muted); } .btn-outline-secondary:hover { background: var(--color-text-muted); color: #fff; } .btn-link { font-weight: 400; color: var(--color-primary-ink); text-decoration: underline; } .btn-link:hover { color: var(--color-primary-hover); } .wui-tour-layer { position: fixed; inset: 0; z-index: var(--wui-z-tour); pointer-events: none; font-family: "Webority Sans", "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif; font-size: 16px; font-weight: 400; line-height: 1.5; color: var(--color-text); text-align: start; } .wui-tour-spot { position: fixed; border-radius: var(--wui-radius-sm); box-shadow: 0 0 0 2px var(--color-primary), 0 0 0 100vmax var(--color-scrim-strong); pointer-events: none; } @media (prefers-reduced-motion: no-preference) { .wui-tour-spot { transition: top 160ms ease, left 160ms ease, width 160ms ease, height 160ms ease; } } .wui-tour-card { display: flex; flex-direction: column; gap: 8px; width: min(360px, 100vw - 16px); padding: 16px; overflow-y: auto; background: var(--color-surface); color: var(--color-text); border: 1px solid var(--color-border); border-radius: var(--wui-radius-lg); corner-shape: squircle; box-shadow: var(--wui-shadow-overlay); pointer-events: auto; } .wui-tour-card:focus { outline: none; } .wui-tour-card:focus-visible { outline: 2px solid var(--color-primary); outline-offset: 2px; } .wui-tour-position { margin: 0; font-size: 12px; color: var(--color-text-muted); } .wui-tour-title { margin: 0; font-size: 16px; font-weight: 600; } .wui-tour-text { margin: 0; font-size: 14px; color: var(--color-text-muted); } .wui-tour-actions { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: 4px; } .wui-tour-nav { display: flex; gap: 8px; } .wui-tour-skip { color: var(--color-text-muted); } .wui-tour-back, .wui-tour-next { min-width: 64px; } `,l=`wui-tour-step`,u=`wui-tour-host`,d=`wui-tour-seen:`,f={back:`Back`,next:`Next`,skip:`Skip`,done:`Done`},p={back:`back-label`,next:`next-label`,skip:`skip-label`,done:`done-label`},m=4,h=0;function g(e=d,t=globalThis.localStorage){return{isSeen:async n=>t.getItem(e+n)===`1`,markSeen:async n=>{t.setItem(e+n,`1`)}}}var _=e=>!e?.isConnected||getComputedStyle(e).visibility===`hidden`?!1:e.getClientRects().length>0,v=e=>!!e&&(e.isContentEditable||/^(INPUT|TEXTAREA|SELECT)$/.test(e.tagName)),y=()=>{let e=document.activeElement;for(;e?.shadowRoot?.activeElement;)e=e.shadowRoot.activeElement;return e},b=null;function x(e){if(`adoptedStyleSheets`in e&&typeof CSSStyleSheet==`function`&&`replaceSync`in CSSStyleSheet.prototype){b||(b=new CSSStyleSheet,b.replaceSync(c)),e.adoptedStyleSheets=[b];return}let t=document.createElement(`style`);t.textContent=c,e.appendChild(t)}var S=class extends t{static get observedAttributes(){return[`open`]}constructor(){super(),this.seenStore=null,this.onBeforeStep=null,this._run=0,this._running=!1,this._layer=null,this._outer=null,this._shadow=null}connectedCallback(){this.hasAttribute(`open`)&&this.start()}disconnectedCallback(){this.stop()}attributeChangedCallback(e,t,n){e!==`open`||!this.isConnected||(n===null?this.stop():this.start())}get tourId(){return this.getAttribute(`tour-id`)||``}set tourId(e){e==null||e===``?this.removeAttribute(`tour-id`):this.setAttribute(`tour-id`,String(e))}get isolated(){return this.hasAttribute(`isolated`)}set isolated(e){this.toggleAttribute(`isolated`,e===!0||e===``||e===`true`)}_stepList(){return Array.from(this.querySelectorAll(`:scope > ${l}`),e=>({target:e.getAttribute(`target`)||``,title:e.getAttribute(`title`)||void 0,description:e.textContent.trim()}))}_store(){return this.seenStore?this.seenStore:this.getAttribute(`seen-store`)===`local`?g():globalThis.window?.WUI?.tour?.seenStore||null}_label(e){return this.getAttribute(p[e])||f[e]}async start(){if(this._running)return;this._running=!0;let e=++this._run;this.hasAttribute(`open`)||this.setAttribute(`open`,``);try{await this._start(e)}catch(t){throw e===this._run&&(this._running=!1),t}}async _start(e){this._steps=this._stepList();let t=this._store();if(t&&!this.tourId)throw Error(`<wui-tour> needs a tour-id to use a seen store.`);if(t&&await t.isSeen(this.tourId)){e===this._run&&this._finish(`alreadySeen`);return}this._returnFocus=document.activeElement;let n=await this._locate(0,1,e);if(e===this._run){if(!n){this._finish(`noTargets`);return}this._firstIndex=n.index,this._build(),this._show(n)}}next(){return this._move(1)}back(){return!this._current||this._current.index<=this._firstIndex?Promise.resolve():this._move(-1)}async goTo(e){if(this._current){if(!Number.isInteger(e)||e<0||e>=this._steps.length)throw RangeError(`<wui-tour> has no step ${e}; it has ${this._steps.length}.`);await this._go(e,1)}}stop(){this._running&&(this._run++,this._teardown(),this._running=!1,this.hasAttribute(`open`)&&this.removeAttribute(`open`))}async _locate(e,t,n){let r=this._steps;for(let i=e;i>=0&&i<r.length;i+=t){let e=r[i];if(await this._beforeStep(e,i),n!==this._run)return null;if(!e.target)return{index:i,target:null};let t=document.querySelector(e.target);if(_(t))return{index:i,target:t}}return null}async _beforeStep(e,t){let n=[];this.dispatchEvent(new CustomEvent(`wui-tour:beforestep`,{bubbles:!0,detail:{step:e,index:t,wait:e=>n.push(e)}})),await Promise.all(n),typeof this.onBeforeStep==`function`&&await this.onBeforeStep(e,t)}_build(){let e=`wui-tour-${++h}`,t=document.createElement(`div`);t.className=`wui-tour-layer`,t.innerHTML=` <div class="wui-tour-spot" aria-hidden="true"></div> <div class="wui-tour-card" role="dialog" aria-modal="true" tabindex="-1" aria-labelledby="${e}-title" aria-describedby="${e}-text"> <p class="wui-tour-position"></p> <h2 class="wui-tour-title" id="${e}-title"></h2> <p class="wui-tour-text" id="${e}-text"></p> <div class="wui-tour-actions"> <button type="button" class="btn btn-sm btn-link wui-tour-skip"></button> <div class="wui-tour-nav"> <button type="button" class="btn btn-sm btn-outline-secondary wui-tour-back"></button> <button type="button" class="btn btn-sm btn-primary wui-tour-next"></button> </div> </div> </div> <div class="visually-hidden" role="status" aria-live="polite"></div>`;let n=t;this._shadow=null,this.isolated&&(n=document.createElement(u),this._shadow=n.attachShadow({mode:`open`}),x(this._shadow),this._shadow.appendChild(t)),document.body.appendChild(n),this._outer=n,this._layer=t,this._spot=t.querySelector(`.wui-tour-spot`),this._card=t.querySelector(`.wui-tour-card`),this._live=t.querySelector(`[role=status]`),this._card.querySelector(`.wui-tour-skip`).addEventListener(`click`,()=>this._close(`skipped`)),this._card.querySelector(`.wui-tour-back`).addEventListener(`click`,()=>this._move(-1)),this._card.querySelector(`.wui-tour-next`).addEventListener(`click`,()=>this._move(1)),this._shadow&&this._card.removeAttribute(`aria-modal`),this._onKey=e=>this._key(e),this._onFocusIn=e=>{this._layer&&!this._layer.contains(e.target)&&this._card.focus()},document.addEventListener(`keydown`,this._onKey,!0),this._shadow||document.addEventListener(`focusin`,this._onFocusIn),o(n,()=>this._place())}_active(){return this._shadow?this._shadow.activeElement:document.activeElement}_show(e){this._current=e;let{index:t,target:n}=e,r=this._steps[t],i=this._steps,a=t===i.length-1,o=this._card;o.querySelector(`.wui-tour-position`).textContent=`Step ${t+1} of ${i.length}`;let s=o.querySelector(`.wui-tour-title`);s.textContent=r.title||``,s.hidden=!r.title,o.querySelector(`.wui-tour-text`).textContent=r.description||``,o.querySelector(`.wui-tour-skip`).textContent=this._label(`skip`),o.querySelector(`.wui-tour-back`).textContent=this._label(`back`),o.querySelector(`.wui-tour-back`).hidden=t<=this._firstIndex,o.querySelector(`.wui-tour-next`).textContent=this._label(a?`done`:`next`),this._live.textContent=[`Step ${t+1} of ${i.length}`,r.title,r.description].filter(Boolean).join(`. `),n?.scrollIntoView?.({block:`center`,inline:`nearest`}),this._place();let c=this._active();(o.contains(c)?!c.hidden:this._shadow!==null&&v(y()))||o.focus(),this.dispatchEvent(new CustomEvent(`wui-tour:step`,{bubbles:!0,detail:{step:r,index:t}}))}_place(){if(!this._current||!this._layer)return;let e=this._spot.style,t=this._card.style;if(!this._current.target){e.top=`50%`,e.left=`50%`,e.width=`0px`,e.height=`0px`,e.boxShadow=`0 0 0 100vmax var(--color-scrim-strong)`,this._card.classList.remove(`drop-up`),t.position=`fixed`,t.top=`50%`,t.left=`50%`,t.transform=`translate(-50%, -50%)`,t.maxHeight=`calc(100vh - 16px)`;return}e.boxShadow=``,t.transform=``;let n=this._current.target.getBoundingClientRect();e.top=`${n.top-m}px`,e.left=`${n.left-m}px`,e.width=`${n.width+m*2}px`,e.height=`${n.height+m*2}px`,a(this._spot,this._card,{clampHeight:!0})}async _move(e){this._current&&await this._go(this._current.index+e,e)}async _go(e,t){if(!this._current||this._moving)return;this._moving=!0;let n=this._run;try{let r=await this._locate(e,t,n);if(n!==this._run)return;r?this._show(r):t>0&&await this._close(`finished`)}finally{this._moving=!1}}_key(e){if(!(!this._layer||e.altKey||e.ctrlKey||e.metaKey)){if(e.key===`Escape`)e.preventDefault(),e.stopPropagation(),this._close(`skipped`);else if(e.key===`ArrowRight`||e.key===`ArrowLeft`){if(this._shadow&&v(e.composedPath?.()[0]??e.target))return;e.preventDefault(),e.key===`ArrowRight`?this._move(1):this._current.index>this._firstIndex&&this._move(-1)}else if(e.key===`Tab`&&!this._shadow){let t=Array.from(this._card.querySelectorAll(`button`)).filter(e=>!e.hidden),n=t[0],r=t[t.length-1],i=this._active();!this._card.contains(i)||e.shiftKey&&(i===n||i===this._card)?(e.preventDefault(),(e.shiftKey?r:n).focus()):!e.shiftKey&&i===r&&(e.preventDefault(),n.focus())}}}_teardown(){if(!this._layer)return;document.removeEventListener(`keydown`,this._onKey,!0),document.removeEventListener(`focusin`,this._onFocusIn);let e=!this._shadow||this._shadow.activeElement!==null||!document.activeElement||document.activeElement===document.body;s(this._outer),this._outer.remove(),this._outer=null,this._shadow=null,this._layer=null,this._current=null;let t=this._returnFocus;this._returnFocus=null,e&&t?.isConnected&&t.focus?.()}async _close(e){let t=this._run;this._teardown();let n=this._store();try{n&&t===this._run&&await n.markSeen(this.tourId)}finally{this._finish(e)}}_finish(e){this._run++,this._running=!1,this.hasAttribute(`open`)&&this.removeAttribute(`open`),this.dispatchEvent(new CustomEvent(`wui-tour:close`,{bubbles:!0,detail:{reason:e}}))}},C=class extends t{constructor(){super(),this.shadowRoot||this.attachShadow({mode:`open`})}};e(`wui-tour`,S),e(`wui-tour-step`,C)})();
1
+ (function(){function e(e,t){typeof customElements<`u`&&!customElements.get(e)&&customElements.define(e,t)}var t=typeof HTMLElement>`u`?class{}:HTMLElement,n=4,r=300,i=400;function a(e,t,a={}){if(!e||!t)return;let o=e.getBoundingClientRect(),s=a.clampHeight?t.scrollTop:0;a.clampHeight&&(t.style.maxHeight=``);let c=t.offsetHeight,l=window.innerHeight-o.bottom,u=l<c+n&&o.top>l;if(t.classList.toggle(`drop-up`,u),t.style.position=`fixed`,t.style.top=u?`${Math.max(n,o.top-c-n)}px`:`${o.bottom+n}px`,a.clampHeight){let e=u?o.top-n*2:window.innerHeight-o.bottom-n*2;e<c&&(t.style.maxHeight=`${Math.max(e,0)}px`),t.scrollTop=s}a.matchWidth&&(o.width>=r?(t.style.minWidth=`${o.width}px`,t.style.width=`${o.width}px`,t.style.maxWidth=`${o.width}px`):(t.style.minWidth=`${o.width}px`,t.style.width=`max-content`,t.style.maxWidth=`${Math.min(i,window.innerWidth-n*2)}px`));let d=t.offsetWidth,f=Math.min(o.left,window.innerWidth-d-n);t.style.left=`${Math.max(n,f)}px`}function o(e,t){s(e),e._reanchor=t,e._reanchorScroll=n=>{n.target instanceof Node&&typeof e.contains==`function`&&e.contains(n.target)||t()},window.addEventListener(`resize`,e._reanchor),window.addEventListener(`scroll`,e._reanchorScroll,!0)}function s(e){e?._reanchor&&(window.removeEventListener(`resize`,e._reanchor),window.removeEventListener(`scroll`,e._reanchorScroll,!0),e._reanchor=null,e._reanchorScroll=null)}var c=` :host { all: initial; ${Object.entries({"--wui-z-tour":`1550`,"--wui-radius-sm":`8px`,"--wui-radius-lg":`14px`,"--wui-shadow-overlay":`0 8px 28px -6px rgba(7, 20, 55, 0.14)`,"--color-primary":`#4F46E5`,"--color-primary-hover":`#4338CA`,"--color-primary-ink":`#4F46E5`,"--color-primary-text":`#FFFFFF`,"--color-scrim-strong":`color-mix(in srgb, #071437 62%, transparent)`,"--color-surface":`#FFFFFF`,"--color-text":`#071437`,"--color-text-muted":`#4B5675`,"--color-border":`#EBEDF3`}).map(([e,t])=>` ${e}: ${t};`).join(` `)} } *, *::before, *::after { box-sizing: border-box; } [hidden] { display: none !important; } .visually-hidden { position: absolute !important; width: 1px !important; height: 1px !important; padding: 0 !important; margin: -1px !important; overflow: hidden !important; clip: rect(0, 0, 0, 0) !important; white-space: nowrap !important; border: 0 !important; } .btn { display: inline-block; margin: 0; padding: 0.25rem 0.5rem; border: 1px solid transparent; border-radius: 0.375rem; background: transparent; font: inherit; font-size: 0.875rem; font-weight: 500; line-height: 1.5; text-align: center; text-decoration: none; white-space: nowrap; cursor: pointer; } .btn:focus-visible { outline: 2px solid var(--color-primary); outline-offset: 2px; } .btn-primary { background: var(--color-primary); border-color: var(--color-primary); color: var(--color-primary-text); } .btn-primary:hover { background: var(--color-primary-hover); border-color: var(--color-primary-hover); } .btn-outline-secondary { border-color: var(--color-text-muted); color: var(--color-text-muted); } .btn-outline-secondary:hover { background: var(--color-text-muted); color: #fff; } .btn-link { font-weight: 400; color: var(--color-primary-ink); text-decoration: underline; } .btn-link:hover { color: var(--color-primary-hover); } .wui-tour-layer { position: fixed; inset: 0; z-index: var(--wui-z-tour); pointer-events: none; font-family: "Webority Sans", "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif; font-size: 16px; font-weight: 400; line-height: 1.5; color: var(--color-text); text-align: start; } .wui-tour-spot { position: fixed; border-radius: var(--wui-radius-sm); box-shadow: 0 0 0 2px var(--color-primary), 0 0 0 100vmax var(--color-scrim-strong); pointer-events: none; } @media (prefers-reduced-motion: no-preference) { .wui-tour-spot { transition: top 160ms ease, left 160ms ease, width 160ms ease, height 160ms ease; } } .wui-tour-card { display: flex; flex-direction: column; gap: 8px; width: min(360px, 100vw - 16px); padding: 16px; overflow-y: auto; background: var(--color-surface); color: var(--color-text); border: 1px solid var(--color-border); border-radius: var(--wui-radius-lg); corner-shape: squircle; box-shadow: var(--wui-shadow-overlay); pointer-events: auto; } .wui-tour-card:focus { outline: none; } .wui-tour-card:focus-visible { outline: 2px solid var(--color-primary); outline-offset: 2px; } .wui-tour-position { margin: 0; font-size: 12px; color: var(--color-text-muted); } .wui-tour-title { margin: 0; font-size: 16px; font-weight: 600; } .wui-tour-text { margin: 0; font-size: 14px; color: var(--color-text-muted); } .wui-tour-actions { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: 4px; } .wui-tour-nav { display: flex; gap: 8px; } .wui-tour-skip { color: var(--color-text-muted); } .wui-tour-back, .wui-tour-next { min-width: 64px; } `,l=`wui-tour-step`,u=`wui-tour-host`,d=`wui-tour-seen:`,f={back:`Back`,next:`Next`,skip:`Skip`,done:`Done`},p={back:`back-label`,next:`next-label`,skip:`skip-label`,done:`done-label`},m=4,h=0;function g(e=d,t=globalThis.localStorage){return{isSeen:async n=>t.getItem(e+n)===`1`,markSeen:async n=>{t.setItem(e+n,`1`)}}}var _=e=>!e?.isConnected||getComputedStyle(e).visibility===`hidden`?!1:e.getClientRects().length>0,v=e=>!!e&&(e.isContentEditable||/^(INPUT|TEXTAREA|SELECT)$/.test(e.tagName)),y=()=>{let e=document.activeElement;for(;e?.shadowRoot?.activeElement;)e=e.shadowRoot.activeElement;return e},b=null;function x(e){if(`adoptedStyleSheets`in e&&typeof CSSStyleSheet==`function`&&`replaceSync`in CSSStyleSheet.prototype){b||(b=new CSSStyleSheet,b.replaceSync(c)),e.adoptedStyleSheets=[b];return}let t=document.createElement(`style`);t.textContent=c,e.appendChild(t)}var S=class extends t{static get observedAttributes(){return[`open`]}constructor(){super(),this.seenStore=null,this.onBeforeStep=null,this._run=0,this._running=!1,this._layer=null,this._outer=null,this._shadow=null}connectedCallback(){this.hasAttribute(`open`)&&this.start()}disconnectedCallback(){this.stop()}attributeChangedCallback(e,t,n){e!==`open`||!this.isConnected||(n===null?this.stop():this.start())}get tourId(){return this.getAttribute(`tour-id`)||``}set tourId(e){e==null||e===``?this.removeAttribute(`tour-id`):this.setAttribute(`tour-id`,String(e))}get isolated(){return this.hasAttribute(`isolated`)}set isolated(e){this.toggleAttribute(`isolated`,e===!0||e===``||e===`true`)}_stepList(){return Array.from(this.querySelectorAll(`:scope > ${l}`),e=>({target:e.getAttribute(`target`)||``,title:e.getAttribute(`title`)||void 0,description:e.textContent.trim()}))}_store(){return this.seenStore?this.seenStore:this.getAttribute(`seen-store`)===`local`?g():globalThis.window?.WUI?.tour?.seenStore||null}_label(e){return this.getAttribute(p[e])||f[e]}async start(){if(this._running)return;this._running=!0;let e=++this._run;this.hasAttribute(`open`)||this.setAttribute(`open`,``);try{await this._start(e)}catch(t){throw e===this._run&&(this._running=!1),t}}async _start(e){this._steps=this._stepList();let t=this._store();if(t&&!this.tourId)throw Error(`<wui-tour> needs a tour-id to use a seen store.`);if(t&&await t.isSeen(this.tourId)){e===this._run&&this._finish(`alreadySeen`);return}this._returnFocus=document.activeElement;let n=await this._locate(0,1,e);if(e===this._run){if(!n){this._finish(`noTargets`);return}this._firstIndex=n.index,this._build(),this._show(n)}}next(){return this._move(1)}back(){return!this._current||this._current.index<=this._firstIndex?Promise.resolve():this._move(-1)}async goTo(e){if(this._current){if(!Number.isInteger(e)||e<0||e>=this._steps.length)throw RangeError(`<wui-tour> has no step ${e}; it has ${this._steps.length}.`);await this._go(e,1)}}stop(){this._running&&(this._run++,this._teardown(),this._running=!1,this.hasAttribute(`open`)&&this.removeAttribute(`open`))}async _locate(e,t,n){let r=this._steps;for(let i=e;i>=0&&i<r.length;i+=t){let e=r[i];if(await this._beforeStep(e,i),n!==this._run)return null;if(!e.target)return{index:i,target:null};let t=document.querySelector(e.target);if(_(t))return{index:i,target:t}}return null}async _beforeStep(e,t){let n=[];this.dispatchEvent(new CustomEvent(`wui-tour:beforestep`,{bubbles:!0,detail:{step:e,index:t,wait:e=>n.push(e)}})),await Promise.all(n),typeof this.onBeforeStep==`function`&&await this.onBeforeStep(e,t)}_build(){let e=`wui-tour-${++h}`,t=document.createElement(`div`);t.className=`wui-tour-layer`,t.innerHTML=` <div class="wui-tour-spot" aria-hidden="true"></div> <div class="wui-tour-card" role="dialog" aria-modal="true" tabindex="-1" aria-labelledby="${e}-title" aria-describedby="${e}-text"> <p class="wui-tour-position"></p> <h2 class="wui-tour-title" id="${e}-title"></h2> <p class="wui-tour-text" id="${e}-text"></p> <div class="wui-tour-actions"> <button type="button" class="btn btn-sm btn-link wui-tour-skip"></button> <div class="wui-tour-nav"> <button type="button" class="btn btn-sm btn-outline-secondary wui-tour-back"></button> <button type="button" class="btn btn-sm btn-primary wui-tour-next"></button> </div> </div> </div> <div class="visually-hidden" role="status" aria-live="polite"></div>`;let n=t;this._shadow=null,this.isolated&&(n=document.createElement(u),this._shadow=n.attachShadow({mode:`open`}),x(this._shadow),this._shadow.appendChild(t)),document.body.appendChild(n),this._outer=n,this._layer=t,this._spot=t.querySelector(`.wui-tour-spot`),this._card=t.querySelector(`.wui-tour-card`),this._live=t.querySelector(`[role=status]`),this._card.querySelector(`.wui-tour-skip`).addEventListener(`click`,()=>this._close(`skipped`)),this._card.querySelector(`.wui-tour-back`).addEventListener(`click`,()=>this._move(-1)),this._card.querySelector(`.wui-tour-next`).addEventListener(`click`,()=>this._move(1)),this._shadow&&this._card.removeAttribute(`aria-modal`),this._onKey=e=>this._key(e),this._onFocusIn=e=>{this._layer&&!this._layer.contains(e.target)&&this._card.focus()},document.addEventListener(`keydown`,this._onKey,!0),this._shadow||document.addEventListener(`focusin`,this._onFocusIn),o(n,()=>this._place())}_active(){return this._shadow?this._shadow.activeElement:document.activeElement}_show(e){this._current=e;let{index:t,target:n}=e,r=this._steps[t],i=this._steps,a=t===i.length-1,o=this._card;o.querySelector(`.wui-tour-position`).textContent=`Step ${t+1} of ${i.length}`;let s=o.querySelector(`.wui-tour-title`);s.textContent=r.title||``,s.hidden=!r.title,o.querySelector(`.wui-tour-text`).textContent=r.description||``,o.querySelector(`.wui-tour-skip`).textContent=this._label(`skip`),o.querySelector(`.wui-tour-back`).textContent=this._label(`back`),o.querySelector(`.wui-tour-back`).hidden=t<=this._firstIndex,o.querySelector(`.wui-tour-next`).textContent=this._label(a?`done`:`next`),this._live.textContent=[`Step ${t+1} of ${i.length}`,r.title,r.description].filter(Boolean).join(`. `),n?.scrollIntoView?.({block:`center`,inline:`nearest`}),this._place();let c=this._active();(o.contains(c)?!c.hidden:this._shadow!==null&&v(y()))||o.focus(),this.dispatchEvent(new CustomEvent(`wui-tour:step`,{bubbles:!0,detail:{step:r,index:t}}))}_place(){if(!this._current||!this._layer)return;let e=this._spot.style,t=this._card.style;if(!this._current.target){e.top=`50%`,e.left=`50%`,e.width=`0px`,e.height=`0px`,e.boxShadow=`0 0 0 100vmax var(--color-scrim-strong)`,this._card.classList.remove(`drop-up`),t.position=`fixed`,t.top=`50%`,t.left=`50%`,t.transform=`translate(-50%, -50%)`,t.maxHeight=`calc(100vh - 16px)`;return}e.boxShadow=``,t.transform=``;let n=this._current.target.getBoundingClientRect(),r={top:n.top-m,left:n.left-m,width:n.width+m*2,height:n.height+m*2,bottom:n.bottom+m,right:n.right+m};e.top=`${r.top}px`,e.left=`${r.left}px`,e.width=`${r.width}px`,e.height=`${r.height}px`,a({getBoundingClientRect:()=>r},this._card,{clampHeight:!0})}async _move(e){this._current&&await this._go(this._current.index+e,e)}async _go(e,t){if(!this._current||this._moving)return;this._moving=!0;let n=this._run;try{let r=await this._locate(e,t,n);if(n!==this._run)return;r?this._show(r):t>0&&await this._close(`finished`)}finally{this._moving=!1}}_key(e){if(!(!this._layer||e.altKey||e.ctrlKey||e.metaKey)){if(e.key===`Escape`)e.preventDefault(),e.stopPropagation(),this._close(`skipped`);else if(e.key===`ArrowRight`||e.key===`ArrowLeft`){if(this._shadow&&v(e.composedPath?.()[0]??e.target))return;e.preventDefault(),e.key===`ArrowRight`?this._move(1):this._current.index>this._firstIndex&&this._move(-1)}else if(e.key===`Tab`&&!this._shadow){let t=Array.from(this._card.querySelectorAll(`button`)).filter(e=>!e.hidden),n=t[0],r=t[t.length-1],i=this._active();!this._card.contains(i)||e.shiftKey&&(i===n||i===this._card)?(e.preventDefault(),(e.shiftKey?r:n).focus()):!e.shiftKey&&i===r&&(e.preventDefault(),n.focus())}}}_teardown(){if(!this._layer)return;document.removeEventListener(`keydown`,this._onKey,!0),document.removeEventListener(`focusin`,this._onFocusIn);let e=!this._shadow||this._shadow.activeElement!==null||!document.activeElement||document.activeElement===document.body;s(this._outer),this._outer.remove(),this._outer=null,this._shadow=null,this._layer=null,this._current=null;let t=this._returnFocus;this._returnFocus=null,e&&t?.isConnected&&t.focus?.()}async _close(e){let t=this._run;this._teardown();let n=this._store();try{n&&t===this._run&&await n.markSeen(this.tourId)}finally{this._finish(e)}}_finish(e){this._run++,this._running=!1,this.hasAttribute(`open`)&&this.removeAttribute(`open`),this.dispatchEvent(new CustomEvent(`wui-tour:close`,{bubbles:!0,detail:{reason:e}}))}},C=class extends t{constructor(){super(),this.shadowRoot||this.attachShadow({mode:`open`})}};e(`wui-tour`,S),e(`wui-tour-step`,C)})();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webority/ui-elements",
3
- "version": "0.50.0",
3
+ "version": "0.51.0",
4
4
  "description": "Webority framework-agnostic UI custom elements (<wui-*>) — the single implementation of the interactive components, styled by @webority/theme. Used natively in Razor and wrapped by @webority/ui-react.",
5
5
  "license": "SEE LICENSE IN LICENSE",
6
6
  "type": "module",
@@ -1,6 +0,0 @@
1
- import{a as e,n as t,t as n}from"./fileViewerUi-DasgDsU-.js";var r=[.1,.25,.5,.75,1,1.5,2,3,4],i=[.25,.5,1,2,4],a=16,o=5,s=class{constructor(e,t){this.shell=e,this.source=t,this.zoom=`fit`,this.rotation=0,this.area={width:0,height:0},this.destroyed=!1}load(){let e=document.createElement(`img`);e.className=`wui-file-viewer-image`,e.alt=this.shell.name(),e.decoding=`async`,e.draggable=!1,e.addEventListener(`load`,()=>{this.destroyed||(this.natural={width:e.naturalWidth||300,height:e.naturalHeight||150},this._build(e),this.shell.loaded({kind:`image`,pages:1}))}),e.addEventListener(`error`,()=>{this.destroyed||this.shell.fail(Error(`The image could not be decoded.`))}),e.src=this.source.src,this.img=e}destroy(){this.destroyed=!0,this._resizeObserver?.disconnect(),this._onKeyDown&&this.shell.host.removeEventListener(`keydown`,this._onKeyDown),this._printFrame?.remove(),this.img?.removeAttribute(`src`)}_build(e){let{center:r,end:a,body:o,host:s}=this.shell;this.zoomOutButton=n(`zoom-out`,`Zoom out`),this.zoomOutButton.addEventListener(`click`,()=>this._stepZoom(-1)),this.zoomButton=document.createElement(`button`),this.zoomButton.type=`button`,this.zoomButton.className=`wui-file-viewer-zoom`,t(this.zoomButton,{label:`Zoom`,items:()=>[...i.map(e=>({key:String(e),label:`${Math.round(e*100)}%`,checked:this.zoom===e})),{key:`fit-divider`,divider:!0},{key:`fit`,label:`Fit`,checked:this.zoom===`fit`}],onPick:e=>this._setZoom(e===`fit`?`fit`:Number(e))}),this.zoomInButton=n(`zoom-in`,`Zoom in`),this.zoomInButton.addEventListener(`click`,()=>this._stepZoom(1));let c=n(`rotate-ccw`,`Rotate left`);c.addEventListener(`click`,()=>this._rotate(-90));let l=n(`rotate-cw`,`Rotate right`);l.addEventListener(`click`,()=>this._rotate(90));let u=document.createElement(`span`);u.className=`wui-file-viewer-divider`;let d=n(`printer`,`Print`);d.addEventListener(`click`,()=>this.print()),r.append(this.zoomOutButton,this.zoomButton,this.zoomInButton),a.prepend(c,l,u,d),this.scroller=document.createElement(`div`),this.scroller.className=`wui-file-viewer-scroll wui-file-viewer-image-scroll wui-scroll`,this.scroller.tabIndex=0,this.scroller.setAttribute(`role`,`region`),this.scroller.setAttribute(`aria-label`,`Image`),this.stage=document.createElement(`div`),this.stage.className=`wui-file-viewer-image-stage`,this.stage.append(e),this.scroller.append(this.stage),o.replaceChildren(this.scroller),this.scroller.addEventListener(`pointerdown`,e=>this._panStart(e)),this.scroller.addEventListener(`pointermove`,e=>this._panMove(e));for(let e of[`pointerup`,`pointercancel`,`lostpointercapture`])this.scroller.addEventListener(e,()=>this._panEnd());this.scroller.addEventListener(`wheel`,e=>{if(!e.ctrlKey&&!e.metaKey)return;e.preventDefault();let t=performance.now();t-(this._lastWheelZoom??0)<120||(this._lastWheelZoom=t,this._stepZoom(e.deltaY<0?1:-1))},{passive:!1}),this._onKeyDown=e=>this._keyDown(e),s.addEventListener(`keydown`,this._onKeyDown),this._resizeObserver=new ResizeObserver(()=>{let e=this.scroller.clientWidth,t=this.scroller.clientHeight;e===this.area.width&&t===this.area.height||(this.area={width:e,height:t},this._layout())}),this._resizeObserver.observe(this.scroller),this.area={width:this.scroller.clientWidth,height:this.scroller.clientHeight},this._layout()}_turned(){let{width:e,height:t}=this.natural;return this.rotation%180==0?{width:e,height:t}:{width:t,height:e}}scale(){if(typeof this.zoom==`number`)return this.zoom;let{width:e,height:t}=this._turned(),n=Math.min((this.area.width-2*a)/e,(this.area.height-2*a)/t);return Math.max(Math.min(1,n),.01)}_layout(){if(!this.stage)return;let t=this.scale(),n=this._turned();this.stage.style.width=`${Math.round(n.width*t)}px`,this.stage.style.height=`${Math.round(n.height*t)}px`,this.img.style.width=`${Math.round(this.natural.width*t)}px`,this.img.style.height=`${Math.round(this.natural.height*t)}px`,this.img.style.transform=`translate(-50%, -50%) rotate(${this.rotation}deg)`;let r=Math.round(t*100);this.zoomButton.innerHTML=`${r}%${e(`chevron-down`,{size:12})}`,this.zoomButton.setAttribute(`aria-label`,`Zoom, ${r}%`),this.zoomOutButton.disabled=this._zoomStep(-1)==null,this.zoomInButton.disabled=this._zoomStep(1)==null}_zoomStep(e){let t=this.scale();return e>0?r.find(e=>e>t+.001)??null:[...r].reverse().find(e=>e<t-.001)??null}_stepZoom(e){let t=this._zoomStep(e);t!=null&&this._setZoom(t)}_setZoom(e){let t=this.scroller,n=(t.scrollLeft+t.clientWidth/2)/Math.max(t.scrollWidth,1),r=(t.scrollTop+t.clientHeight/2)/Math.max(t.scrollHeight,1);this.zoom=e,this._layout(),t.scrollLeft=n*t.scrollWidth-t.clientWidth/2,t.scrollTop=r*t.scrollHeight-t.clientHeight/2}_rotate(e){this.rotation=(this.rotation+e+360)%360,this._setZoom(this.zoom)}_keyDown(e){if(!(e.defaultPrevented||e.altKey||!(e.ctrlKey||e.metaKey))){if(e.key===`+`||e.key===`=`)this._stepZoom(1);else if(e.key===`-`||e.key===`_`)this._stepZoom(-1);else if(e.key===`0`)this._setZoom(`fit`);else return;e.preventDefault()}}_panStart(e){let t=this.scroller;e.button!==0||t.scrollWidth<=t.clientWidth&&t.scrollHeight<=t.clientHeight||(this._pan={id:e.pointerId,x:e.clientX,y:e.clientY,left:t.scrollLeft,top:t.scrollTop,active:!1})}_panMove(e){let t=this._pan;if(!t)return;let n=e.clientX-t.x,r=e.clientY-t.y;if(!t.active){if(Math.abs(n)<o&&Math.abs(r)<o)return;t.active=!0,this.scroller.setPointerCapture(t.id),this.scroller.classList.add(`wui-file-viewer-panning`)}this.scroller.scrollLeft=t.left-n,this.scroller.scrollTop=t.top-r}_panEnd(){let e=this._pan;e?.active&&(this.scroller.hasPointerCapture(e.id)&&this.scroller.releasePointerCapture(e.id),this.scroller.classList.remove(`wui-file-viewer-panning`)),this._pan=null}print(){this._printFrame?.remove();let e=document.createElement(`iframe`);e.className=`wui-file-viewer-print-frame`,e.title=`Image for printing`,e.tabIndex=-1,e.setAttribute(`aria-hidden`,`true`);let t=this.rotation%180!=0,n=new URL(this.source.src,document.baseURI).href,r=t?`max-width: 100vh; max-height: 100vw;`:`max-width: 100vw; max-height: 100vh;`;e.srcdoc=`<!doctype html><html><head><title>${c(this.shell.name())}</title><style>
2
- @page { margin: 10mm; }
3
- html, body { margin: 0; height: 100%; }
4
- body { display: flex; align-items: center; justify-content: center; }
5
- img { ${r} transform: rotate(${this.rotation}deg); }
6
- </style></head><body><img src="${c(n)}" alt=""></body></html>`,e.addEventListener(`load`,()=>{try{e.contentWindow.focus(),e.contentWindow.print()}catch(e){console.warn(`[wui-file-viewer] print failed:`,e?.message),window.open(this.source.src,`_blank`,`noopener`)}},{once:!0}),this._printFrame=e,document.body.append(e)}},c=e=>String(e??``).replace(/&/g,`&amp;`).replace(/</g,`&lt;`).replace(/>/g,`&gt;`).replace(/"/g,`&quot;`);export{s as ImageView};