@webority/ui-elements 0.177.0 → 0.178.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/WuiInlineEdit-D7AuEv1R.js +1 -0
- package/dist/{WuiSavedViews-BKpnSd-Y.js → WuiSavedViews-BR6ZHd9Y.js} +1 -1
- package/dist/{WuiSelect-iUXaHKw5.js → WuiSelect-CNff3FNi.js} +1 -1
- package/dist/{chips-xXgAvIFy.js → chips-BdpsN50B.js} +1 -1
- package/dist/{drawerDiscard-z1PsI4cx.js → drawerDiscard-APy8TZxi.js} +1 -1
- package/dist/elements/inline-edit.js +1 -1
- package/dist/elements/saved-views.js +1 -1
- package/dist/elements/select.js +1 -1
- package/dist/{fileViewerPdf-Tb26qdtM.js → fileViewerPdf-BET_tiP6.js} +1 -1
- package/dist/inlineEdit.g-DLDVospu.js +1 -0
- package/dist/loader-A38-PdcB.js +1 -0
- package/dist/{search-Bhn-bjLL.js → search-Dl07KqWw.js} +1 -1
- package/dist/server.js +1 -1
- package/dist/text.js +1 -1
- package/dist/ui-elements/carousel.global.js +1 -1
- package/dist/ui-elements/code-block.global.js +1 -1
- package/dist/ui-elements/command-palette.global.js +1 -1
- package/dist/ui-elements/comment-thread.global.js +1 -1
- package/dist/ui-elements/consent-banner.global.js +1 -1
- package/dist/ui-elements/context-menu.global.js +1 -1
- package/dist/ui-elements/data-table.global.js +1 -0
- package/dist/ui-elements/date-range.global.js +1 -1
- package/dist/ui-elements/date-time.global.js +1 -1
- package/dist/ui-elements/datepicker.global.js +1 -1
- package/dist/ui-elements/dock.global.js +1 -0
- package/dist/ui-elements/drawer.global.js +1 -1
- package/dist/ui-elements/dropdown.global.js +1 -1
- package/dist/ui-elements/entry-grid.global.js +1 -1
- package/dist/ui-elements/gantt.global.js +1 -1
- package/dist/ui-elements/glyphs.global.js +1 -1
- package/dist/ui-elements/hover-card.global.js +1 -0
- package/dist/ui-elements/image-crop.global.js +1 -1
- package/dist/ui-elements/inline-edit.global.js +1 -1
- package/dist/ui-elements/kanban.global.js +1 -1
- package/dist/ui-elements/lead-popup.global.js +1 -1
- package/dist/ui-elements/lightbox.global.js +1 -1
- package/dist/ui-elements/markdown.global.js +1 -1
- package/dist/ui-elements/navigation-menu.global.js +1 -0
- package/dist/ui-elements/notification-center.global.js +1 -0
- package/dist/ui-elements/onboarding-checklist.global.js +1 -0
- package/dist/ui-elements/org-tree.global.js +1 -1
- package/dist/ui-elements/otp.global.js +1 -0
- package/dist/ui-elements/overflow.global.js +1 -0
- package/dist/ui-elements/phone.global.js +1 -1
- package/dist/ui-elements/popover.global.js +1 -1
- package/dist/ui-elements/rating.global.js +1 -0
- package/dist/ui-elements/record-pager.global.js +1 -0
- package/dist/ui-elements/relative-time.global.js +1 -0
- package/dist/ui-elements/saved-views.global.js +1 -1
- package/dist/ui-elements/select-chips.global.js +1 -1
- package/dist/ui-elements/select-recents.global.js +1 -1
- package/dist/ui-elements/select-search.global.js +1 -1
- package/dist/ui-elements/select-window.global.js +1 -1
- package/dist/ui-elements/shortcuts.global.js +1 -0
- package/dist/ui-elements/show-more.global.js +1 -0
- package/dist/ui-elements/slider.global.js +1 -1
- package/dist/ui-elements/sortable.global.js +1 -1
- package/dist/ui-elements/status-icon.global.js +1 -1
- package/dist/ui-elements/table-export.global.js +1 -1
- package/dist/ui-elements/timepicker.global.js +1 -1
- package/dist/ui-elements/tour.global.js +1 -1
- package/dist/ui-elements/tree-picker.global.js +1 -1
- package/dist/ui-elements/tree.global.js +1 -1
- package/dist/ui-elements/truncate.global.js +1 -0
- package/dist/ui-elements/whats-new.global.js +1 -0
- package/dist/ui-elements/wizard.global.js +1 -1
- package/dist/ui-elements.global.js +1 -1
- package/dist/ui-elements.js +1 -1
- package/dist/ui-file-viewer.global.js +1 -1
- package/dist/ui-file-viewer.js +1 -1
- package/package.json +5 -5
- package/types/WuiInlineEdit.d.ts +10 -0
- package/types/global/core.d.ts +1 -17
- package/types/global/shared.d.ts +6 -0
- package/types/razor-js/modules/lazyModules.d.ts +22 -0
- package/types/razor-js/modules/themeCopy.d.ts +1 -0
- package/types/razor-js/webority-ui.d.ts +2 -2
- package/dist/WuiInlineEdit-p0cm_i90.js +0 -1
- package/dist/inlineEdit.g-ZxRNYq0t.js +0 -1
- package/dist/loader-DvNLnnaO.js +0 -1
package/dist/ui-elements.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{n as e}from"./elementBase-Cxeyx0tU.js";import{n as ee}from"./filterPopover-DskHFNLi.js";import{t}from"./kanban-jQCTLG3Q.js";import{n}from"./statusIcons-Cd3GJcBR.js";import{t as r}from"./WuiCarousel-B0yPDH5I.js";import{t as i}from"./WuiCodeBlock-BWYZ1S70.js";import{t as a}from"./WuiCommandPalette-u1XD5WMv.js";import{t as o}from"./WuiCommentThread-e5t7HceL.js";import{t as s}from"./WuiConsentBanner-nTua-kEd.js";import{t as c}from"./WuiContextMenu-DEWYYFRG.js";import{t as l}from"./WuiDataTable-Ble3hl5L.js";import{t as u}from"./WuiDatePicker-3D33rzH4.js";import{t as d}from"./WuiDateRange-BnEJ2WpL.js";import{t as f}from"./WuiDateTime-Vimu6grS.js";import{t as p}from"./WuiDock-2LGlbEFx.js";import{t as m}from"./WuiDrawer-BsY0fs_u.js";import{t as h}from"./WuiDropdown-6g074v1T.js";import{t as g}from"./WuiEntryGrid-DkW0tIDy.js";import{t as _}from"./WuiGantt-BqNhYIr6.js";import{t as v}from"./WuiHoverCard-DhJcIIM1.js";import{t as y}from"./WuiImageCrop-UakcSM2k.js";import{t as b}from"./WuiInlineEdit-
|
|
1
|
+
import{n as e}from"./elementBase-Cxeyx0tU.js";import{n as ee}from"./filterPopover-DskHFNLi.js";import{t}from"./kanban-jQCTLG3Q.js";import{n}from"./statusIcons-Cd3GJcBR.js";import{t as r}from"./WuiCarousel-B0yPDH5I.js";import{t as i}from"./WuiCodeBlock-BWYZ1S70.js";import{t as a}from"./WuiCommandPalette-u1XD5WMv.js";import{t as o}from"./WuiCommentThread-e5t7HceL.js";import{t as s}from"./WuiConsentBanner-nTua-kEd.js";import{t as c}from"./WuiContextMenu-DEWYYFRG.js";import{t as l}from"./WuiDataTable-Ble3hl5L.js";import{t as u}from"./WuiDatePicker-3D33rzH4.js";import{t as d}from"./WuiDateRange-BnEJ2WpL.js";import{t as f}from"./WuiDateTime-Vimu6grS.js";import{t as p}from"./WuiDock-2LGlbEFx.js";import{t as m}from"./WuiDrawer-BsY0fs_u.js";import{t as h}from"./WuiDropdown-6g074v1T.js";import{t as g}from"./WuiEntryGrid-DkW0tIDy.js";import{t as _}from"./WuiGantt-BqNhYIr6.js";import{t as v}from"./WuiHoverCard-DhJcIIM1.js";import{t as y}from"./WuiImageCrop-UakcSM2k.js";import{t as b}from"./WuiInlineEdit-D7AuEv1R.js";import{t as x}from"./WuiLeadPopup-DaYZ2zCJ.js";import{t as S}from"./WuiLightbox-DpHJAMO3.js";import{t as C}from"./WuiMarkdown-DRtGPxQX.js";import{r as w}from"./WuiMentionInput-DPpEVL2s.js";import{t as T}from"./WuiModal-DQbVJGUo.js";import{t as E}from"./WuiNavigationMenu-KdW7yuLn.js";import{t as D}from"./WuiNotificationCenter-DuvGrqwr.js";import{t as O}from"./WuiOnboardingChecklist-C-nllg2h.js";import{t as k}from"./WuiOrgTree-DWSk_LHd.js";import{t as A}from"./WuiOtp-Cc0formv.js";import{t as j}from"./WuiOverflow-fZKqdsr-.js";import{t as M}from"./WuiPhone--w-taM5Q.js";import{t as N}from"./WuiPopover-BvWKRNQY.js";import{t as P}from"./WuiRating-DIQfif9x.js";import{t as F}from"./WuiRecordPager-BXoe4KfU.js";import{t as I}from"./WuiRelativeTime-CSg9vzfk.js";import{t as L}from"./WuiSavedViews-BR6ZHd9Y.js";import{t as R}from"./WuiSelect-CNff3FNi.js";import{t as z}from"./WuiShortcuts-CRCctX82.js";import{t as B}from"./WuiShowMore-BoYCrYYf.js";import{t as V}from"./WuiSlider-CK7_l_R5.js";import{t as H}from"./WuiSortable-x8Mg0tOv.js";import{t as U}from"./WuiTimePicker-DYLFaWDc.js";import{t as W}from"./WuiTour-BgpMa8J5.js";import{t as G}from"./WuiTree-BjtuCasB.js";import{t as K}from"./WuiTreePicker-DLddmEgG.js";import{t as q}from"./WuiTruncate-BB4i8wHE.js";import{n as J,t as Y}from"./WuiWhatsNew-Dm4Yl68x.js";import{n as X,t as Z}from"./WuiWizardStep-gFtuUzsL.js";import{c as Q,f as te,l as ne,m as re,p as ie,s as ae,u as oe}from"./formatters-DTW53DjY.js";import{_ as se,r as ce}from"./themeTransition-TF0BqM20.js";import{t as le}from"./drawerDiscard-APy8TZxi.js";import{n as ue}from"./shortcutKeys-BMTWgV2g.js";function $(){ee(),e(`wui-select`,R),e(`wui-saved-views`,L),e(`wui-phone`,M),e(`wui-datepicker`,u),e(`wui-date-range`,d),e(`wui-date-time`,f),e(`wui-dock`,p),e(`wui-image-crop`,y),e(`wui-kanban`,t),e(`wui-lead-popup`,x),e(`wui-inline-edit`,b),e(`wui-consent-banner`,s),e(`wui-slider`,V),e(`wui-sortable`,H),e(`wui-timepicker`,U),e(`wui-tour`,W),e(`wui-tree`,G),e(`wui-tree-picker`,K),e(`wui-org-tree`,k),e(`wui-command-palette`,a),e(`wui-context-menu`,c),e(`wui-otp`,A),e(`wui-status-icon`,n),e(`wui-shortcuts`,z),e(`wui-record-pager`,F),e(`wui-carousel`,r),e(`wui-code-block`,i),e(`wui-markdown`,C),e(`wui-modal`,T),e(`wui-data-table`,l),e(`wui-drawer`,m),e(`wui-dropdown`,h),e(`wui-entry-grid`,g),e(`wui-gantt`,_),e(`wui-hover-card`,v),e(`wui-lightbox`,S),e(`wui-navigation-menu`,E),e(`wui-notification-center`,D),e(`wui-onboarding-checklist`,O),e(`wui-overflow`,j),e(`wui-popover`,N),e(`wui-rating`,P),e(`wui-relative-time`,I),e(`wui-show-more`,B),e(`wui-truncate`,q),e(`wui-whats-new`,J),e(`wui-mention-input`,w),e(`wui-comment-thread`,o),e(`wui-wizard-step`,Z),e(`wui-wizard`,X)}$();export{le as DISCARD_EVENT,se as ROW_DROP_EVENT,ue as SHORTCUT_EVENT,ce as THEME_CHANGE_EVENT,Y as WHATS_NEW_READ_EVENT,r as WuiCarousel,i as WuiCodeBlock,a as WuiCommandPalette,o as WuiCommentThread,s as WuiConsentBanner,c as WuiContextMenu,l as WuiDataTable,u as WuiDatePicker,d as WuiDateRange,f as WuiDateTime,p as WuiDock,m as WuiDrawer,h as WuiDropdown,g as WuiEntryGrid,_ as WuiGantt,v as WuiHoverCard,y as WuiImageCrop,b as WuiInlineEdit,t as WuiKanban,x as WuiLeadPopup,S as WuiLightbox,C as WuiMarkdown,w as WuiMentionInput,T as WuiModal,E as WuiNavigationMenu,D as WuiNotificationCenter,O as WuiOnboardingChecklist,k as WuiOrgTree,A as WuiOtp,j as WuiOverflow,M as WuiPhone,N as WuiPopover,P as WuiRating,F as WuiRecordPager,I as WuiRelativeTime,L as WuiSavedViews,R as WuiSelect,z as WuiShortcuts,B as WuiShowMore,V as WuiSlider,H as WuiSortable,n as WuiStatusIcon,U as WuiTimePicker,W as WuiTour,G as WuiTree,K as WuiTreePicker,q as WuiTruncate,J as WuiWhatsNew,X as WuiWizard,Z as WuiWizardStep,$ as defineWeborityElements,ae as formatCompact,Q as formatCurrency,ne as formatDate,oe as formatDateTime,te as formatNumber,ie as formatPercent,re as formatValue};
|
|
@@ -14,6 +14,6 @@ ${n.map((e,t)=>`@page s${t} { size: ${e}; margin: 0; }`).join(`
|
|
|
14
14
|
`)}
|
|
15
15
|
html, body { margin: 0; padding: 0; }
|
|
16
16
|
img { display: block; break-after: page; }
|
|
17
|
-
img:last-child { break-after: auto; }`,pages:e.map(e=>({url:e.url,width:e.width,height:e.height,page:`s${n.indexOf(t(e))}`}))}}function Lo(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 Z(e,t){let n=e[t];if(n===void 0)throw RangeError(`No item at index ${t}.`);return n}function Ro(e){let t=[...e].sort((e,t)=>e-t);return Z(t,Math.floor(t.length/2))}var Q,zo,Bo,Vo,Ho,Uo,Wo,Go,Ko,qo,Jo,Yo,Xo,Zo,Qo,$o,es,ts,ns,rs,is,as,os,ss,cs,ls,us=n((()=>{_o(),yo(),Do(),We(),O(),Ao(),tt(),rt(),Q=()=>Ge(`fileViewer`,nt),zo=[.5,.75,1,1.25,1.5,2,3],Bo=[.5,.75,1,1.25,1.5,2],Vo=[{key:`fit-width`,textKey:`fitWidthLabel`},{key:`fit-page`,textKey:`fitPageLabel`}],Ho=96/72,Uo=12,Wo=10,Go=168,Ko=150,qo=2,Jo=2e3,Yo=5,Xo=150,Zo=16777216,Qo=null,$o=e=>Vo.some(t=>t.key===e),es=e=>{if($o(e))return e;let t=Number(e);return zo.includes(t)?t:`fit-width`},ts=e=>e instanceof Element&&e.closest(`input, textarea, select, [contenteditable='true'], .dropdown-menu`),ns=e=>/^(https?:|mailto:)/i.test(e),rs=class{constructor(e,t){this.shell=e,this.source=t;let n=e.prefs;this.zoom=es(n.zoom),this.twoPage=n.twoPage===!0,this.showThumbs=n.thumbnails===!0,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(){Mo(this.source.workerSrc),this.task=yn({url:this.source.src,...No(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:Ho});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,this.zoomMenu?.close();for(let e of this._timers)window.clearTimeout(e);this._scrollFrame!==void 0&&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(e=>{p(`PDF load failed before the viewer closed.`,e)}).finally(()=>e.destroy())}_buildToolbar(){let{start:e,center:t,end:n,host:r}=this.shell;this.thumbsButton=A(`menu`,``,{size:17}),this.thumbsButton.addEventListener(`click`,()=>this._setThumbs(!this.showThumbs)),e.prepend(this.thumbsButton),this.prevButton=A(`chevron-up`,Q().previousPageLabel),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`,Q().pageNumberLabel),this.pageInput.inputMode=`numeric`,this.pageInput.addEventListener(`input`,()=>{this.pageInput.value=this.pageInput.value.replace(/[^\d]/g,``)}),this.pageInput.addEventListener(`keydown`,e=>{ko(e)&&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=A(`chevron-down`,Q().nextPageLabel),this.nextButton.addEventListener(`click`,()=>this.goToPage(this.current()+this.cols())),t.append(this.prevButton,i,this.nextButton),this.searchButton=A(`search`,Q().searchDocumentLabel,{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=A(`zoom-out`,Q().zoomOutLabel),this.zoomOutButton.addEventListener(`click`,()=>this._stepZoom(-1)),this.zoomButton=document.createElement(`button`),this.zoomButton.type=`button`,this.zoomButton.className=`wui-file-viewer-zoom`,this.zoomMenu=Ue(this.zoomButton,{label:Q().zoomLabel,items:()=>[...Bo.map(e=>({key:String(e),label:`${Math.round(e*100)}%`,checked:this.zoom===e})),{key:`fit-divider`,divider:!0},...Vo.map(e=>({key:e.key,label:Q()[e.textKey],checked:this.zoom===e.key}))],onPick:e=>this._setZoom(es(e))}),this.zoomInButton=A(`zoom-in`,Q().zoomInLabel),this.zoomInButton.addEventListener(`click`,()=>this._stepZoom(1));let o=document.createElement(`span`);o.className=`wui-file-viewer-divider`,this.twoPageButton=A(`two-page`,Q().twoPageViewLabel),this.twoPageButton.addEventListener(`click`,()=>this._setTwoPage(!this.twoPage)),this.printButton=A(`printer`,Q().printLabel,{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=Q().searchDocumentLabel,this.searchInput.setAttribute(`aria-label`,Q().searchDocumentLabel),this.searchInput.addEventListener(`input`,()=>this._setQuery(this.searchInput.value)),this.searchInput.addEventListener(`keydown`,e=>{ko(e)?(e.preventDefault(),this._goToHit(this.search.current+(e.shiftKey?-1:1))):e.key===`Escape`&&(e.preventDefault(),e.stopPropagation(),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=A(`chevron-up`,Q().previousMatchLabel),this.prevHitButton.addEventListener(`click`,()=>this._goToHit(this.search.current-1)),this.nextHitButton=A(`chevron-down`,Q().nextMatchLabel),this.nextHitButton.addEventListener(`click`,()=>this._goToHit(this.search.current+1));let n=A(`x`,Q().closeSearchLabel);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.replaceChildren(`${n}%`,D(`chevron-down`,{size:12})??``),this.zoomButton.setAttribute(`aria-label`,Ke(Q().zoomText,{percent:n}))),He(this.thumbsButton,this.showThumbs?Q().hideThumbnailsLabel:Q().showThumbnailsLabel),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,He(this.printButton,this.printButton.disabled?Q().preparingPrintLabel:Q().printLabel),He(this.searchButton,this.search.open?Q().closeSearchLabel:Q().searchDocumentLabel),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`,Q().documentPagesLabel),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=Ro(this.sizes.map(e=>e.width)),n=Ro(this.sizes.map(e=>e.height)),r=(this.area.width-24-(e-1)*Wo)/(t*e);return this.zoom===`fit-page`&&(r=Math.min(r,(this.area.height-24)/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=Uo,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}=Z(this.sizes,e-1),r=Z(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*Ho)),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+Wo,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=Z(this.rows,e);return{page:Z(t.pages,0),within:(this.scrollPos.top-t.top)/Math.max(t.height+Wo,1),left:this.scrollPos.left}}_restore(e,t){let n=this.scroller;if(e){let r=Z(this.rows,Z(this.rowOf,e.page));n.scrollTop=r.top+e.within*(r.height+Wo),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;Z(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&&Z(this.rows,i).top<t;i++){let{top:a,height:o}=Z(this.rows,i),s=Math.min(a+o,t)-Math.max(a,e);s>r&&(r=s,n=i)}return Z(Z(this.rows,n).pages,0)}_onScroll(){this.scrollPos={top:this.scroller.scrollTop,left:this.scroller.scrollLeft},this._scrollFrame!==void 0&&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)-qo),t=Math.min(this.rows.length-1,this._rowAt(this.scrollPos.top+this.area.height)+qo),n=new Set;for(let r=e;r<=t;r++)for(let e of Z(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?Ko: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=Z(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),Z(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]??NaN)-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*Ho}),i=window.devicePixelRatio||1,a=Math.sqrt(Zo/(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?void 0:[o,0,0,o,0,0]});try{await e.task.promise}catch(e){s.width=0,s.height=0,os(e)!==`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=Z(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 Zi({textContentSource:t.streamTextContent({includeMarkedContent:!0,disableNormalization:!0}),container:n,viewport:t.getViewport({scale:this.scale*Ho})});try{await e.textLayer.render()}catch(e){os(e)!==`AbortException`&&this._warn(`text layer failed`,e);return}e.released||this.destroyed||(Z(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&&ns(e.url))),i=(await Promise.all(r.map(async e=>e.url?{link:e,target:void 0}:{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=NaN,r=NaN,i=NaN,s=NaN]=a.convertToViewportRectangle(e.rect),c=document.createElement(`a`);if(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);else if(t){let e=t;c.href=`#page=${e}`,c.setAttribute(`aria-label`,Ke(Q().goToPageText,{targetPage:e})),c.addEventListener(`click`,t=>{t.preventDefault(),this.goToPage(e)})}o.append(c)}e.links=o,Z(this.pageEls,e.n).append(o)}async _destPage(e){try{let t=(typeof e==`string`?await this.pdf.getDestination(e):e)?.[0];if(t==null)return null;let n=is(t)?await this.pdf.getPageIndex(t):t;if(typeof n!=`number`)throw TypeError(`The link destination is not a page.`);return n+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(Z(this.rows,Z(this.rowOf,t)).top-Uo,this.scroller.scrollHeight-this.scroller.clientHeight);window.clearTimeout(this._jumpTimer);let r=this._endJump;r&&this.scroller.removeEventListener(`scrollend`,r),this._endJump=()=>{window.clearTimeout(this._jumpTimer);let e=this._endJump;e&&this.scroller.removeEventListener(`scrollend`,e),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,Jo),this._timers.add(this._jumpTimer),this.scroller.scrollTo({top:n,behavior:ls()})),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=Math.round((this.scale||1)*100);return e>0?zo.find(e=>Math.round(e*100)>t)??null:[...zo].reverse().find(e=>Math.round(e*100)<t)??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=void 0,this._followThumb())}_buildThumbs(){this.thumbEls=[],this._thumbObserver=new IntersectionObserver(e=>{for(let t of e)t.isIntersecting&&t.target instanceof HTMLElement&&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`,Ke(Q().goToPageText,{targetPage:e}));let{width:n,height:r}=Z(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:Go*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),os(t)!==`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(Go*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._activeThumb!==void 0&&this.thumbEls[this._activeThumb]?.classList.remove(`active`),this._activeThumb=e,this.thumbEls[e]?.classList.add(`active`),this.thumbEls[e]?.scrollIntoView({behavior:ls(),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(),xo(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?Co(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;if(this.search={...r,hits:e,current:t},n){let t=new Map;e.forEach((e,n)=>{let r=t.get(e.page)??[];r.push({...e,n}),t.set(e.page,r)}),this.search.byPage=t}let i=n?new Set([...r.marked.keys(),...this.search.byPage?.keys()??[]]):new Set([r.hits[r.current]?.page,e[t]?.page].filter(e=>e!==void 0));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,i=Array.isArray(r)?r[e-1]?.items:void 0,a=this.search.open?this.search.byPage?.get(e)??[]:[],o=this.search.marked.get(e)??new Set,s=new Set;i&&a.length&&i.forEach((e,t)=>{let r=wo(e,a),i=n[t];r.length&&i&&(s.add(t),Lo(i,r,this.search.current))});for(let e of o){let t=n[e];!s.has(e)&&t&&t.replaceChildren(t.textContent??``)}s.size?this.search.marked.set(e,s):this.search.marked.delete(e)}_bringHitIntoView(){let e=this.search.hits[this.search.current];if(!e)return;let t=Z(this.rows,Z(this.rowOf,e.page)),n=this.scrollPos.top;(t.top+t.height<n||t.top>n+this.area.height)&&(this.scroller.scrollTop=t.top-Uo),this._revealHit(e.page)}_revealHit(e){let t=this.search.hits[this.search.current];if(!this._revealPending||!t||t.page!==e)return;let n=Z(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=bo(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||ts(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)<Yo&&Math.abs(r)<Yo)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:Xo/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/Xo*25.4,height:i.height/Xo*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=Q().documentPrintingTitle,n.tabIndex=-1,n.setAttribute(`aria-hidden`,`true`),e.frame=n,n.srcdoc=Fo(this.shell.name()),n.addEventListener(`load`,async()=>{if(this.printRun===e)try{let{css:r,pages:i}=Io(t),a=n.contentWindow,o=n.contentDocument;if(!a||!o)throw TypeError(`The print frame has no document.`);let s=`CSSStyleSheet`in a?a.CSSStyleSheet:void 0;if(!as(s))throw TypeError(`The print frame has no CSSStyleSheet.`);let c=new s;c.replaceSync(r),o.adoptedStyleSheets=[c];let l=i.map(e=>{let t=o.createElement(`img`);return t.src=e.url,t.alt=``,t.style.setProperty(`width`,`${e.width}mm`),t.style.setProperty(`height`,`${e.height}mm`),t.style.setProperty(`page`,e.page),t});if(o.body.append(...l),await Promise.all(l.map(ss)),this.printRun!==e)return;e.ready=!0,this._syncToolbar(),a.addEventListener(`afterprint`,()=>{this.printRun===e&&this._releasePrint()},{once:!0}),a.focus(),a.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){f(`[wui-file-viewer] ${e}:`,t instanceof Error?t.message:t)}},is=e=>typeof e==`object`&&!!e,as=e=>typeof e==`function`,os=e=>e instanceof Error?e.name:void 0,ss=e=>e.complete?null:new Promise(t=>{e.addEventListener(`load`,t,{once:!0}),e.addEventListener(`error`,t,{once:!0})}),cs=e=>String(e??``).replace(/&/g,`&`).replace(/</g,`<`).replace(/>/g,`>`),ls=()=>window.matchMedia?.(`(prefers-reduced-motion: reduce)`).matches?`auto`:`smooth`})),ds=r({ImageView:()=>gs}),fs,ps,ms,hs,gs,_s,vs,ys=n((()=>{m(),We(),O(),tt(),rt(),fs=()=>Ge(`fileViewer`,nt),ps=[.1,.25,.5,.75,1,1.5,2,3,4],ms=[.25,.5,1,2,4],hs=5,gs=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.zoomMenu?.close(),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=A(`zoom-out`,fs().zoomOutLabel),this.zoomOutButton.addEventListener(`click`,()=>this._stepZoom(-1)),this.zoomButton=document.createElement(`button`),this.zoomButton.type=`button`,this.zoomButton.className=`wui-file-viewer-zoom`,this.zoomMenu=Ue(this.zoomButton,{label:fs().zoomLabel,items:()=>[...ms.map(e=>({key:String(e),label:`${Math.round(e*100)}%`,checked:this.zoom===e})),{key:`fit-divider`,divider:!0},{key:`fit`,label:fs().fitLabel,checked:this.zoom===`fit`}],onPick:e=>this._setZoom(e===`fit`?`fit`:Number(e))}),this.zoomInButton=A(`zoom-in`,fs().zoomInLabel),this.zoomInButton.addEventListener(`click`,()=>this._stepZoom(1));let a=A(`rotate-ccw`,fs().rotateLeftLabel);a.addEventListener(`click`,()=>this._rotate(-90));let o=A(`rotate-cw`,fs().rotateRightLabel);o.addEventListener(`click`,()=>this._rotate(90));let s=document.createElement(`span`);s.className=`wui-file-viewer-divider wui-file-viewer-print`;let c=A(`printer`,fs().printLabel,{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`,fs().imageLabel),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-32)/e,(this.area.height-32)/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.replaceChildren(`${n}%`,D(`chevron-down`,{size:12})??``),this.zoomButton.setAttribute(`aria-label`,Ke(fs().zoomText,{percent:n})),this.zoomOutButton.disabled=this._zoomStep(-1)==null,this.zoomInButton.disabled=this._zoomStep(1)==null}_zoomStep(e){let t=Math.round(this.scale()*100);return e>0?ps.find(e=>Math.round(e*100)>t)??null:[...ps].reverse().find(e=>Math.round(e*100)<t)??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)<hs&&Math.abs(r)<hs)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=fs().imagePrintingTitle,e.tabIndex=-1,e.setAttribute(`aria-hidden`,`true`);let t=this.rotation%180!=0,n=new URL(this.source.src,document.baseURI).href;e.srcdoc=`<!doctype html><html><head><title>${vs(this.shell.name())}</title></head><body></body></html>`,e.addEventListener(`load`,async()=>{try{let r=e.contentWindow,i=e.contentDocument;if(!r||!i)throw TypeError(`The print frame has no document.`);let a=`CSSStyleSheet`in r?r.CSSStyleSheet:void 0;if(!_s(a))throw TypeError(`The print frame has no CSSStyleSheet.`);let o=new a;o.replaceSync(`@page { margin: 10mm; }
|
|
17
|
+
img:last-child { break-after: auto; }`,pages:e.map(e=>({url:e.url,width:e.width,height:e.height,page:`s${n.indexOf(t(e))}`}))}}function Lo(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 Z(e,t){let n=e[t];if(n===void 0)throw RangeError(`No item at index ${t}.`);return n}function Ro(e){let t=[...e].sort((e,t)=>e-t);return Z(t,Math.floor(t.length/2))}var Q,zo,Bo,Vo,Ho,Uo,Wo,Go,Ko,qo,Jo,Yo,Xo,Zo,Qo,$o,es,ts,ns,rs,is,as,os,ss,cs,ls,us=n((()=>{_o(),yo(),Do(),We(),O(),Ao(),tt(),rt(),Q=()=>Ge(`fileViewer`,nt),zo=[.5,.75,1,1.25,1.5,2,3],Bo=[.5,.75,1,1.25,1.5,2],Vo=[{key:`fit-width`,textKey:`fitWidthLabel`},{key:`fit-page`,textKey:`fitPageLabel`}],Ho=96/72,Uo=12,Wo=10,Go=168,Ko=150,qo=2,Jo=2e3,Yo=5,Xo=150,Zo=16777216,Qo=null,$o=e=>Vo.some(t=>t.key===e),es=e=>{if($o(e))return e;let t=Number(e);return zo.includes(t)?t:`fit-width`},ts=e=>e instanceof Element&&e.closest(`input, textarea, select, [contenteditable='true'], .dropdown-menu`),ns=e=>/^(https?:|mailto:)/i.test(e),rs=class{constructor(e,t){this.shell=e,this.source=t;let n=e.prefs;this.zoom=es(n.zoom),this.twoPage=n.twoPage===!0,this.showThumbs=n.thumbnails===!0,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(){Mo(this.source.workerSrc),this.task=yn({url:this.source.src,...No(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:Ho});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,this.zoomMenu?.close();for(let e of this._timers)window.clearTimeout(e);this._scrollFrame!==void 0&&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(e=>{p(`PDF load failed before the viewer closed.`,e)}).finally(()=>e.destroy())}_buildToolbar(){let{start:e,center:t,end:n,host:r}=this.shell;this.thumbsButton=A(`menu`,``,{size:17}),this.thumbsButton.addEventListener(`click`,()=>this._setThumbs(!this.showThumbs)),e.prepend(this.thumbsButton),this.prevButton=A(`chevron-up`,Q().previousPageLabel),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`,Q().pageNumberLabel),this.pageInput.inputMode=`numeric`,this.pageInput.addEventListener(`input`,()=>{this.pageInput.value=this.pageInput.value.replace(/[^\d]/g,``)}),this.pageInput.addEventListener(`keydown`,e=>{ko(e)&&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=A(`chevron-down`,Q().nextPageLabel),this.nextButton.addEventListener(`click`,()=>this.goToPage(this.current()+this.cols())),t.append(this.prevButton,i,this.nextButton),this.searchButton=A(`search`,Q().searchDocumentLabel,{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=A(`zoom-out`,Q().zoomOutLabel),this.zoomOutButton.addEventListener(`click`,()=>this._stepZoom(-1)),this.zoomButton=document.createElement(`button`),this.zoomButton.type=`button`,this.zoomButton.className=`wui-file-viewer-zoom`,this.zoomMenu=Ue(this.zoomButton,{label:Q().zoomLabel,items:()=>[...Bo.map(e=>({key:String(e),label:`${Math.round(e*100)}%`,checked:this.zoom===e})),{key:`fit-divider`,divider:!0},...Vo.map(e=>({key:e.key,label:Q()[e.textKey],checked:this.zoom===e.key}))],onPick:e=>this._setZoom(es(e))}),this.zoomInButton=A(`zoom-in`,Q().zoomInLabel),this.zoomInButton.addEventListener(`click`,()=>this._stepZoom(1));let o=document.createElement(`span`);o.className=`wui-file-viewer-divider`,this.twoPageButton=A(`two-page`,Q().twoPageViewLabel),this.twoPageButton.addEventListener(`click`,()=>this._setTwoPage(!this.twoPage)),this.printButton=A(`printer`,Q().printLabel,{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 wui-input-sm`,this.searchInput.placeholder=Q().searchDocumentLabel,this.searchInput.setAttribute(`aria-label`,Q().searchDocumentLabel),this.searchInput.addEventListener(`input`,()=>this._setQuery(this.searchInput.value)),this.searchInput.addEventListener(`keydown`,e=>{ko(e)?(e.preventDefault(),this._goToHit(this.search.current+(e.shiftKey?-1:1))):e.key===`Escape`&&(e.preventDefault(),e.stopPropagation(),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=A(`chevron-up`,Q().previousMatchLabel),this.prevHitButton.addEventListener(`click`,()=>this._goToHit(this.search.current-1)),this.nextHitButton=A(`chevron-down`,Q().nextMatchLabel),this.nextHitButton.addEventListener(`click`,()=>this._goToHit(this.search.current+1));let n=A(`x`,Q().closeSearchLabel);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.replaceChildren(`${n}%`,D(`chevron-down`,{size:12})??``),this.zoomButton.setAttribute(`aria-label`,Ke(Q().zoomText,{percent:n}))),He(this.thumbsButton,this.showThumbs?Q().hideThumbnailsLabel:Q().showThumbnailsLabel),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,He(this.printButton,this.printButton.disabled?Q().preparingPrintLabel:Q().printLabel),He(this.searchButton,this.search.open?Q().closeSearchLabel:Q().searchDocumentLabel),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`,Q().documentPagesLabel),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=Ro(this.sizes.map(e=>e.width)),n=Ro(this.sizes.map(e=>e.height)),r=(this.area.width-24-(e-1)*Wo)/(t*e);return this.zoom===`fit-page`&&(r=Math.min(r,(this.area.height-24)/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=Uo,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}=Z(this.sizes,e-1),r=Z(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*Ho)),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+Wo,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=Z(this.rows,e);return{page:Z(t.pages,0),within:(this.scrollPos.top-t.top)/Math.max(t.height+Wo,1),left:this.scrollPos.left}}_restore(e,t){let n=this.scroller;if(e){let r=Z(this.rows,Z(this.rowOf,e.page));n.scrollTop=r.top+e.within*(r.height+Wo),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;Z(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&&Z(this.rows,i).top<t;i++){let{top:a,height:o}=Z(this.rows,i),s=Math.min(a+o,t)-Math.max(a,e);s>r&&(r=s,n=i)}return Z(Z(this.rows,n).pages,0)}_onScroll(){this.scrollPos={top:this.scroller.scrollTop,left:this.scroller.scrollLeft},this._scrollFrame!==void 0&&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)-qo),t=Math.min(this.rows.length-1,this._rowAt(this.scrollPos.top+this.area.height)+qo),n=new Set;for(let r=e;r<=t;r++)for(let e of Z(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?Ko: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=Z(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),Z(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]??NaN)-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*Ho}),i=window.devicePixelRatio||1,a=Math.sqrt(Zo/(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?void 0:[o,0,0,o,0,0]});try{await e.task.promise}catch(e){s.width=0,s.height=0,os(e)!==`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=Z(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 Zi({textContentSource:t.streamTextContent({includeMarkedContent:!0,disableNormalization:!0}),container:n,viewport:t.getViewport({scale:this.scale*Ho})});try{await e.textLayer.render()}catch(e){os(e)!==`AbortException`&&this._warn(`text layer failed`,e);return}e.released||this.destroyed||(Z(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&&ns(e.url))),i=(await Promise.all(r.map(async e=>e.url?{link:e,target:void 0}:{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=NaN,r=NaN,i=NaN,s=NaN]=a.convertToViewportRectangle(e.rect),c=document.createElement(`a`);if(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);else if(t){let e=t;c.href=`#page=${e}`,c.setAttribute(`aria-label`,Ke(Q().goToPageText,{targetPage:e})),c.addEventListener(`click`,t=>{t.preventDefault(),this.goToPage(e)})}o.append(c)}e.links=o,Z(this.pageEls,e.n).append(o)}async _destPage(e){try{let t=(typeof e==`string`?await this.pdf.getDestination(e):e)?.[0];if(t==null)return null;let n=is(t)?await this.pdf.getPageIndex(t):t;if(typeof n!=`number`)throw TypeError(`The link destination is not a page.`);return n+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(Z(this.rows,Z(this.rowOf,t)).top-Uo,this.scroller.scrollHeight-this.scroller.clientHeight);window.clearTimeout(this._jumpTimer);let r=this._endJump;r&&this.scroller.removeEventListener(`scrollend`,r),this._endJump=()=>{window.clearTimeout(this._jumpTimer);let e=this._endJump;e&&this.scroller.removeEventListener(`scrollend`,e),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,Jo),this._timers.add(this._jumpTimer),this.scroller.scrollTo({top:n,behavior:ls()})),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=Math.round((this.scale||1)*100);return e>0?zo.find(e=>Math.round(e*100)>t)??null:[...zo].reverse().find(e=>Math.round(e*100)<t)??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=void 0,this._followThumb())}_buildThumbs(){this.thumbEls=[],this._thumbObserver=new IntersectionObserver(e=>{for(let t of e)t.isIntersecting&&t.target instanceof HTMLElement&&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`,Ke(Q().goToPageText,{targetPage:e}));let{width:n,height:r}=Z(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:Go*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),os(t)!==`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(Go*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._activeThumb!==void 0&&this.thumbEls[this._activeThumb]?.classList.remove(`active`),this._activeThumb=e,this.thumbEls[e]?.classList.add(`active`),this.thumbEls[e]?.scrollIntoView({behavior:ls(),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(),xo(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?Co(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;if(this.search={...r,hits:e,current:t},n){let t=new Map;e.forEach((e,n)=>{let r=t.get(e.page)??[];r.push({...e,n}),t.set(e.page,r)}),this.search.byPage=t}let i=n?new Set([...r.marked.keys(),...this.search.byPage?.keys()??[]]):new Set([r.hits[r.current]?.page,e[t]?.page].filter(e=>e!==void 0));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,i=Array.isArray(r)?r[e-1]?.items:void 0,a=this.search.open?this.search.byPage?.get(e)??[]:[],o=this.search.marked.get(e)??new Set,s=new Set;i&&a.length&&i.forEach((e,t)=>{let r=wo(e,a),i=n[t];r.length&&i&&(s.add(t),Lo(i,r,this.search.current))});for(let e of o){let t=n[e];!s.has(e)&&t&&t.replaceChildren(t.textContent??``)}s.size?this.search.marked.set(e,s):this.search.marked.delete(e)}_bringHitIntoView(){let e=this.search.hits[this.search.current];if(!e)return;let t=Z(this.rows,Z(this.rowOf,e.page)),n=this.scrollPos.top;(t.top+t.height<n||t.top>n+this.area.height)&&(this.scroller.scrollTop=t.top-Uo),this._revealHit(e.page)}_revealHit(e){let t=this.search.hits[this.search.current];if(!this._revealPending||!t||t.page!==e)return;let n=Z(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=bo(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||ts(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)<Yo&&Math.abs(r)<Yo)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:Xo/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/Xo*25.4,height:i.height/Xo*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=Q().documentPrintingTitle,n.tabIndex=-1,n.setAttribute(`aria-hidden`,`true`),e.frame=n,n.srcdoc=Fo(this.shell.name()),n.addEventListener(`load`,async()=>{if(this.printRun===e)try{let{css:r,pages:i}=Io(t),a=n.contentWindow,o=n.contentDocument;if(!a||!o)throw TypeError(`The print frame has no document.`);let s=`CSSStyleSheet`in a?a.CSSStyleSheet:void 0;if(!as(s))throw TypeError(`The print frame has no CSSStyleSheet.`);let c=new s;c.replaceSync(r),o.adoptedStyleSheets=[c];let l=i.map(e=>{let t=o.createElement(`img`);return t.src=e.url,t.alt=``,t.style.setProperty(`width`,`${e.width}mm`),t.style.setProperty(`height`,`${e.height}mm`),t.style.setProperty(`page`,e.page),t});if(o.body.append(...l),await Promise.all(l.map(ss)),this.printRun!==e)return;e.ready=!0,this._syncToolbar(),a.addEventListener(`afterprint`,()=>{this.printRun===e&&this._releasePrint()},{once:!0}),a.focus(),a.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){f(`[wui-file-viewer] ${e}:`,t instanceof Error?t.message:t)}},is=e=>typeof e==`object`&&!!e,as=e=>typeof e==`function`,os=e=>e instanceof Error?e.name:void 0,ss=e=>e.complete?null:new Promise(t=>{e.addEventListener(`load`,t,{once:!0}),e.addEventListener(`error`,t,{once:!0})}),cs=e=>String(e??``).replace(/&/g,`&`).replace(/</g,`<`).replace(/>/g,`>`),ls=()=>window.matchMedia?.(`(prefers-reduced-motion: reduce)`).matches?`auto`:`smooth`})),ds=r({ImageView:()=>gs}),fs,ps,ms,hs,gs,_s,vs,ys=n((()=>{m(),We(),O(),tt(),rt(),fs=()=>Ge(`fileViewer`,nt),ps=[.1,.25,.5,.75,1,1.5,2,3,4],ms=[.25,.5,1,2,4],hs=5,gs=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.zoomMenu?.close(),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=A(`zoom-out`,fs().zoomOutLabel),this.zoomOutButton.addEventListener(`click`,()=>this._stepZoom(-1)),this.zoomButton=document.createElement(`button`),this.zoomButton.type=`button`,this.zoomButton.className=`wui-file-viewer-zoom`,this.zoomMenu=Ue(this.zoomButton,{label:fs().zoomLabel,items:()=>[...ms.map(e=>({key:String(e),label:`${Math.round(e*100)}%`,checked:this.zoom===e})),{key:`fit-divider`,divider:!0},{key:`fit`,label:fs().fitLabel,checked:this.zoom===`fit`}],onPick:e=>this._setZoom(e===`fit`?`fit`:Number(e))}),this.zoomInButton=A(`zoom-in`,fs().zoomInLabel),this.zoomInButton.addEventListener(`click`,()=>this._stepZoom(1));let a=A(`rotate-ccw`,fs().rotateLeftLabel);a.addEventListener(`click`,()=>this._rotate(-90));let o=A(`rotate-cw`,fs().rotateRightLabel);o.addEventListener(`click`,()=>this._rotate(90));let s=document.createElement(`span`);s.className=`wui-file-viewer-divider wui-file-viewer-print`;let c=A(`printer`,fs().printLabel,{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`,fs().imageLabel),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-32)/e,(this.area.height-32)/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.replaceChildren(`${n}%`,D(`chevron-down`,{size:12})??``),this.zoomButton.setAttribute(`aria-label`,Ke(fs().zoomText,{percent:n})),this.zoomOutButton.disabled=this._zoomStep(-1)==null,this.zoomInButton.disabled=this._zoomStep(1)==null}_zoomStep(e){let t=Math.round(this.scale()*100);return e>0?ps.find(e=>Math.round(e*100)>t)??null:[...ps].reverse().find(e=>Math.round(e*100)<t)??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)<hs&&Math.abs(r)<hs)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=fs().imagePrintingTitle,e.tabIndex=-1,e.setAttribute(`aria-hidden`,`true`);let t=this.rotation%180!=0,n=new URL(this.source.src,document.baseURI).href;e.srcdoc=`<!doctype html><html><head><title>${vs(this.shell.name())}</title></head><body></body></html>`,e.addEventListener(`load`,async()=>{try{let r=e.contentWindow,i=e.contentDocument;if(!r||!i)throw TypeError(`The print frame has no document.`);let a=`CSSStyleSheet`in r?r.CSSStyleSheet:void 0;if(!_s(a))throw TypeError(`The print frame has no CSSStyleSheet.`);let o=new a;o.replaceSync(`@page { margin: 10mm; }
|
|
18
18
|
html, body { margin: 0; height: 100%; }
|
|
19
19
|
body { display: flex; align-items: center; justify-content: center; }`),i.adoptedStyleSheets=[o];let s=i.createElement(`img`);s.src=n,s.alt=``,s.style.setProperty(`max-width`,t?`100vh`:`100vw`),s.style.setProperty(`max-height`,t?`100vw`:`100vh`),s.style.setProperty(`transform`,`rotate(${this.rotation}deg)`),i.body.append(s),s.complete||await new Promise(e=>{s.addEventListener(`load`,e,{once:!0}),s.addEventListener(`error`,e,{once:!0})}),r.focus(),r.print()}catch(e){f(`[wui-file-viewer] print failed:`,e instanceof Error?e.message:void 0),window.open(this.source.src,`_blank`,`noopener`)}},{once:!0}),this._printFrame=e,document.body.append(e)}},_s=e=>typeof e==`function`,vs=e=>String(e??``).replace(/&/g,`&`).replace(/</g,`<`).replace(/>/g,`>`).replace(/"/g,`"`)})),bs=r({MediaView:()=>Ds,formatTime:()=>xs});function xs(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 $,Ss,Cs,ws,Ts,Es,Ds,Os=n((()=>{m(),We(),O(),tt(),rt(),$=()=>Ge(`fileViewer`,nt),Ss=[.5,.75,1,1.25,1.5,2],Cs=5,ws=.1,Ts=e=>typeof e==`number`&&Ss.includes(e),Es=e=>e instanceof Element&&e.closest(`input, textarea, select, button, a, .dropdown-menu`),Ds=class{constructor(e,t){this.shell=e,this.source=t,this.destroyed=!1}load(){let{kind:e,src:t,captions:n}=this.source,r=e===`video`?document.createElement(`video`):document.createElement(`audio`);if(r.className=`wui-file-viewer-${e}`,r.preload=`metadata`,Object.assign(r,{playsInline:!0}),e===`video`&&n){let e=document.createElement(`track`);e.kind=`captions`,e.label=$().captionsLabel,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=Ts(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.speedMenu?.close(),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`?$().videoLabel:$().audioLabel),r===`audio`){let e=document.createElement(`div`);e.className=`wui-file-viewer-audio-art`,e.replaceChildren(...[D(`music`,{size:40})].filter(e=>e!==null)),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=A(`play`,$().playLabel,{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`,$().seekLabel),this.seek.addEventListener(`input`,()=>{n.currentTime=Number(this.seek.value)}),this.timeTotal=document.createElement(`span`),this.timeTotal.className=`wui-file-viewer-time`,this.muteButton=A(`volume-high`,$().muteLabel,{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`,$().volumeLabel),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`,this.speedMenu=Ue(this.speedButton,{label:$().playbackSpeedLabel,items:()=>Ss.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=A(`subtitle`,$().showCaptionsLabel,{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=>{f(`[wui-file-viewer] play refused:`,e instanceof Error?e.message:void 0)}):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;Ve(this.playButton,e?`pause`:`play`,18),He(this.playButton,e?$().pauseLabel:$().playLabel),this.shell.host.classList.toggle(`wui-file-viewer-playing`,e)}_syncTime(){let e=this.media.currentTime,t=this.media.duration;this.timeNow.textContent=xs(e),this.timeTotal.textContent=xs(t),this.seek.max=String(Number.isFinite(t)?t:0),this.seek.value=String(e),this.seek.setAttribute(`aria-valuetext`,Ke($().seekValueText,{now:xs(e),total:xs(t)}))}_syncVolume(){let e=this.media.muted||this.media.volume===0;Ve(this.muteButton,e?`volume-mute`:`volume-high`,18),He(this.muteButton,e?$().unmuteLabel:$().muteLabel),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`,Ke($().playbackSpeedText,{label:e}))}_syncCaptions(){if(!this.captionsButton)return;let e=this._captionsOn();this.captionsButton.setAttribute(`aria-pressed`,String(e)),He(this.captionsButton,e?$().hideCaptionsLabel:$().showCaptionsLabel)}_keyDown(e){if(e.defaultPrevented||e.altKey||e.ctrlKey||e.metaKey||Es(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-Cs);else if(n===`arrowright`)t.currentTime=Math.min(t.duration||0,t.currentTime+Cs);else if(n===`arrowup`)this._setVolume(t.volume+ws);else if(n===`arrowdown`)this._setVolume(t.volume-ws);else if(n===`m`)this._setMuted(!t.muted);else if(n===`c`&&this.captionsButton)this._setCaptions(!this._captionsOn());else return;e.preventDefault()}}}));m(),_(),We(),o(),tt(),rt();var ks=()=>Ge(`fileViewer`,nt),As={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`},js={"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`},Ms=`wui-file-viewer:load`,Ns=`wui-file-viewer:error`,Ps=`wui-file-viewer:prefs-change`;function Fs(e,t){let n=(String(e??``).split(`;`)[0]??``).trim().toLowerCase();if(n)return js[n]??null;let r=String(t??``).split(/[?#]/)[0]??``;return As[r.includes(`.`)?(r.split(`.`).pop()??``).toLowerCase():``]??null}function Is(e){let t=(String(e??``).split(/[?#]/)[0]??``).split(`/`).filter(Boolean).pop()??``;try{return decodeURIComponent(t)}catch{return t}}var Ls={pdf:()=>Promise.resolve().then(()=>(us(),jo)).then(e=>e.PdfView),image:()=>Promise.resolve().then(()=>(ys(),ds)).then(e=>e.ImageView),video:()=>Promise.resolve().then(()=>(Os(),bs)).then(e=>e.MediaView),audio:()=>Promise.resolve().then(()=>(Os(),bs)).then(e=>e.MediaView)},Rs=0,zs=class e extends y{static defaultAssetBase=``;static get observedAttributes(){return[`src`,`name`,`type`,`download`,`print`,`worker-src`,`asset-base`,`captions`]}uid;_prefs;_hostPrefs;_onFullscreen;_view;_loadId;_actionsBox;constructor(){super(),Rs+=1,this.uid=`wui-file-viewer-${Rs}`,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||Is(this.src)||ks().documentLabel}connectedCallback(){if(a(this,`prefs`)){let e=this.prefs;Reflect.deleteProperty(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=Fs(this.type,this.name||this.src);if(!this.src){this._settle(ks().noFileText);return}if(!n){this._settle(ks().unsupportedFileText,{offerDownload:!0});return}this._status(ks().loadingText);let r;try{r=await Ls[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:Vs(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(Ms,{bubbles:!0,detail:e})))},fail:e=>{t()&&this._fail(e)}}}_render(){let e=g(`div`,{class:`wui-file-viewer-toolbar`}),t=g(`div`,{class:`wui-file-viewer-group wui-file-viewer-start`}),n=g(`span`,{class:`wui-file-viewer-name`});n.textContent=this.displayName(),n.title=this.displayName(),t.append(n);let r=g(`div`,{class:`wui-file-viewer-group wui-file-viewer-center`}),i=g(`div`,{class:`wui-file-viewer-group wui-file-viewer-end`}),a=g(`div`,{class:`wui-file-viewer-group wui-file-viewer-view-end`}),o=document.createElement(`a`);o.className=`u-action wui-file-viewer-download`,o.style.setProperty(`--wui-action-size`,`32px`),Ve(o,`download`),He(o,ks().downloadLabel);let s=A(`maximize-4`,ks().fullScreenLabel,{className:`wui-file-viewer-fullscreen`});s.addEventListener(`click`,()=>this.toggleFullscreen()),s.hidden=!document.fullscreenEnabled,this._actionsBox??=g(`div`,{class:`wui-file-viewer-actions`});let c=this._actionsBox;c.append(...this.querySelectorAll(`:scope > [slot="actions"]`)),i.append(a,o,s,c);let l=g(`search`,{class:`wui-file-viewer-search`});l.hidden=!0,e.append(t,r,i,l);let u=g(`div`,{class:`wui-file-viewer-body`,"aria-busy":`true`});this.replaceChildren(e,u),this._parts={toolbar:e,start:t,name:n,center:r,end:i,viewEnd:a,downloadLink:o,fullscreen:s,actionsBox:c,search:l,body:u},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 instanceof HTMLElement&&(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=d(`neutral`,`outline`,`sm`),e.dataset.wui=s,e.href=this.src,e.setAttribute(`download`,this.displayName()),e.textContent=ks().downloadLabel,n.append(e)}this._parts.body.replaceChildren(n)}_settle(e,t){this._parts.body.removeAttribute(`aria-busy`),this._status(e,t)}_fail(e){this._view?.destroy(),this._view=null,this._settle(ks().openFailedText,{offerDownload:!0});let t=typeof e==`object`&&e&&`message`in e?e.message:void 0;this.dispatchEvent(new CustomEvent(Ns,{bubbles:!0,detail:{message:t??String(e)}}))}toggleFullscreen(){document.fullscreenElement?document.exitFullscreen():this.requestFullscreen().catch(e=>{f(`[wui-file-viewer] full screen refused:`,e?.message)})}_syncFullscreen(){if(!this._parts)return;let e=document.fullscreenElement===this,t=this._parts.fullscreen;Ve(t,e?`x`:`maximize-4`),He(t,e?ks().exitFullScreenLabel:ks().fullScreenLabel),this._parts.actionsBox.hidden=e}_readPrefs(){if(this._hostPrefs||!this.viewKey)return{...this._prefs};try{let e=JSON.parse(window.localStorage.getItem(`wui-view:${this.viewKey}`)??`{}`);return Bs(e)?e:{}}catch{return{}}}_savePrefs(e){if(this._prefs={...this._prefs,...e},this.dispatchEvent(new CustomEvent(Ps,{bubbles:!0,detail:{...this._prefs}})),!this._hostPrefs&&this.viewKey)try{window.localStorage.setItem(`wui-view:${this.viewKey}`,JSON.stringify(this._prefs))}catch(e){if(!(e instanceof DOMException))throw e}}};function Bs(e){return typeof e==`object`&&!!e}function Vs(e){return e&&new URL(e,document.baseURI).href}var Hs=typeof document>`u`?null:document.currentScript;return Hs instanceof HTMLScriptElement&&Hs.src&&(zs.defaultAssetBase=new URL(`pdfjs/`,Hs.src).href),i(`wui-file-viewer`,zs),e.WuiFileViewer=zs,e.fileKind=Fs,e.fileNameFromUrl=Is,e.renderPdfFirstPage=(e,t)=>Promise.resolve().then(()=>(us(),jo)).then(n=>n.renderFirstPage(e,{assetBase:zs.defaultAssetBase||void 0,...t})),e})({});
|
package/dist/ui-file-viewer.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{d as e,f as t,i as n,l as r,o as i,r as a,s as o,t as s}from"./fileViewer.g-D_zLw_p-.js";function c(e,t){if(typeof customElements>`u`||customElements.get(e))return;let n=[];if(typeof document<`u`)for(let r of document.querySelectorAll(e))for(let i of Object.keys(r)){let a=Object.getOwnPropertyDescriptor(t.prototype,i);if(a&&(a.set||a.get)&&(n.push([r,i,Reflect.get(r,i)]),!Reflect.deleteProperty(r,i)))throw Error(`defineElement: could not clear the early "${i}" property on <${e}>.`)}customElements.define(e,t);for(let[t,r,i]of n)if(!Reflect.set(t,r,i))throw Error(`defineElement: could not restore the "${r}" property on <${e}>.`)}var l=`AppButton`,u=/* @__PURE__ */ new Set([`primary`,`success`,`warning`,`danger`,`info`,`neutral`]),d={solid:e=>`btn-${e}`,soft:e=>`btn-soft-${e}`,outline:e=>`btn-outline-${e}`,ghost:e=>`btn-ghost-${e}`,link:e=>`btn-link-${e}`,glass:()=>`btn-glass`};function f(e){return t(d,e)}function p(e=`primary`,t=`solid`,n=`md`){if(!u.has(e))throw RangeError(`buttonClass: unknown tone "${e}"`);if(!f(t))throw RangeError(`buttonClass: unknown variant "${t}"`);let r=d[t](e);return n===`md`?`btn ${r}`:`btn ${r} btn-${n}`}var m=`@webority/ui-elements needs a browser DOM; import its types or helpers entry on the server`;if(typeof HTMLElement>`u`)throw Error(m);var h=HTMLElement,g=()=>a(`fileViewer`,s),_={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`},v={"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`},y=`wui-file-viewer:load`,b=`wui-file-viewer:error`,x=`wui-file-viewer:prefs-change`;function S(e,t){let n=(String(e??``).split(`;`)[0]??``).trim().toLowerCase();if(n)return v[n]??null;let r=String(t??``).split(/[?#]/)[0]??``;return _[r.includes(`.`)?(r.split(`.`).pop()??``).toLowerCase():``]??null}function C(e){let t=(String(e??``).split(/[?#]/)[0]??``).split(`/`).filter(Boolean).pop()??``;try{return decodeURIComponent(t)}catch{return t}}var w={pdf:()=>import(`./fileViewerPdf-
|
|
1
|
+
import{d as e,f as t,i as n,l as r,o as i,r as a,s as o,t as s}from"./fileViewer.g-D_zLw_p-.js";function c(e,t){if(typeof customElements>`u`||customElements.get(e))return;let n=[];if(typeof document<`u`)for(let r of document.querySelectorAll(e))for(let i of Object.keys(r)){let a=Object.getOwnPropertyDescriptor(t.prototype,i);if(a&&(a.set||a.get)&&(n.push([r,i,Reflect.get(r,i)]),!Reflect.deleteProperty(r,i)))throw Error(`defineElement: could not clear the early "${i}" property on <${e}>.`)}customElements.define(e,t);for(let[t,r,i]of n)if(!Reflect.set(t,r,i))throw Error(`defineElement: could not restore the "${r}" property on <${e}>.`)}var l=`AppButton`,u=/* @__PURE__ */ new Set([`primary`,`success`,`warning`,`danger`,`info`,`neutral`]),d={solid:e=>`btn-${e}`,soft:e=>`btn-soft-${e}`,outline:e=>`btn-outline-${e}`,ghost:e=>`btn-ghost-${e}`,link:e=>`btn-link-${e}`,glass:()=>`btn-glass`};function f(e){return t(d,e)}function p(e=`primary`,t=`solid`,n=`md`){if(!u.has(e))throw RangeError(`buttonClass: unknown tone "${e}"`);if(!f(t))throw RangeError(`buttonClass: unknown variant "${t}"`);let r=d[t](e);return n===`md`?`btn ${r}`:`btn ${r} btn-${n}`}var m=`@webority/ui-elements needs a browser DOM; import its types or helpers entry on the server`;if(typeof HTMLElement>`u`)throw Error(m);var h=HTMLElement,g=()=>a(`fileViewer`,s),_={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`},v={"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`},y=`wui-file-viewer:load`,b=`wui-file-viewer:error`,x=`wui-file-viewer:prefs-change`;function S(e,t){let n=(String(e??``).split(`;`)[0]??``).trim().toLowerCase();if(n)return v[n]??null;let r=String(t??``).split(/[?#]/)[0]??``;return _[r.includes(`.`)?(r.split(`.`).pop()??``).toLowerCase():``]??null}function C(e){let t=(String(e??``).split(/[?#]/)[0]??``).split(`/`).filter(Boolean).pop()??``;try{return decodeURIComponent(t)}catch{return t}}var w={pdf:()=>import(`./fileViewerPdf-BET_tiP6.js`).then(e=>e.PdfView),image:()=>import(`./fileViewerImage-DnzDd-rQ.js`).then(e=>e.ImageView),video:()=>import(`./fileViewerMedia-Dm99qAjY.js`).then(e=>e.MediaView),audio:()=>import(`./fileViewerMedia-Dm99qAjY.js`).then(e=>e.MediaView)},T=0,E=class a extends h{static defaultAssetBase=``;static get observedAttributes(){return[`src`,`name`,`type`,`download`,`print`,`worker-src`,`asset-base`,`captions`]}uid;_prefs;_hostPrefs;_onFullscreen;_view;_loadId;_actionsBox;constructor(){super(),T+=1,this.uid=`wui-file-viewer-${T}`,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||C(this.src)||g().documentLabel}connectedCallback(){if(t(this,`prefs`)){let e=this.prefs;Reflect.deleteProperty(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=S(this.type,this.name||this.src);if(!this.src){this._settle(g().noFileText);return}if(!t){this._settle(g().unsupportedFileText,{offerDownload:!0});return}this._status(g().loadingText);let n;try{n=await w[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:O(this.assetBase||a.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(y,{bubbles:!0,detail:e})))},fail:e=>{t()&&this._fail(e)}}}_render(){let e=r(`div`,{class:`wui-file-viewer-toolbar`}),t=r(`div`,{class:`wui-file-viewer-group wui-file-viewer-start`}),a=r(`span`,{class:`wui-file-viewer-name`});a.textContent=this.displayName(),a.title=this.displayName(),t.append(a);let s=r(`div`,{class:`wui-file-viewer-group wui-file-viewer-center`}),c=r(`div`,{class:`wui-file-viewer-group wui-file-viewer-end`}),l=r(`div`,{class:`wui-file-viewer-group wui-file-viewer-view-end`}),u=document.createElement(`a`);u.className=`u-action wui-file-viewer-download`,u.style.setProperty(`--wui-action-size`,`32px`),i(u,`download`),o(u,g().downloadLabel);let d=n(`maximize-4`,g().fullScreenLabel,{className:`wui-file-viewer-fullscreen`});d.addEventListener(`click`,()=>this.toggleFullscreen()),d.hidden=!document.fullscreenEnabled,this._actionsBox??=r(`div`,{class:`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`,{class:`wui-file-viewer-search`});p.hidden=!0,e.append(t,s,c,p);let m=r(`div`,{class:`wui-file-viewer-body`,"aria-busy":`true`});this.replaceChildren(e,m),this._parts={toolbar:e,start:t,name:a,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 instanceof HTMLElement&&(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=p(`neutral`,`outline`,`sm`),e.dataset.wui=l,e.href=this.src,e.setAttribute(`download`,this.displayName()),e.textContent=g().downloadLabel,n.append(e)}this._parts.body.replaceChildren(n)}_settle(e,t){this._parts.body.removeAttribute(`aria-busy`),this._status(e,t)}_fail(e){this._view?.destroy(),this._view=null,this._settle(g().openFailedText,{offerDownload:!0});let t=typeof e==`object`&&e&&`message`in e?e.message:void 0;this.dispatchEvent(new CustomEvent(b,{bubbles:!0,detail:{message:t??String(e)}}))}toggleFullscreen(){document.fullscreenElement?document.exitFullscreen():this.requestFullscreen().catch(t=>{e(`[wui-file-viewer] full screen refused:`,t?.message)})}_syncFullscreen(){if(!this._parts)return;let e=document.fullscreenElement===this,t=this._parts.fullscreen;i(t,e?`x`:`maximize-4`),o(t,e?g().exitFullScreenLabel:g().fullScreenLabel),this._parts.actionsBox.hidden=e}_readPrefs(){if(this._hostPrefs||!this.viewKey)return{...this._prefs};try{let e=JSON.parse(window.localStorage.getItem(`wui-view:${this.viewKey}`)??`{}`);return D(e)?e:{}}catch{return{}}}_savePrefs(e){if(this._prefs={...this._prefs,...e},this.dispatchEvent(new CustomEvent(x,{bubbles:!0,detail:{...this._prefs}})),!this._hostPrefs&&this.viewKey)try{window.localStorage.setItem(`wui-view:${this.viewKey}`,JSON.stringify(this._prefs))}catch(e){if(!(e instanceof DOMException))throw e}}};function D(e){return typeof e==`object`&&!!e}function O(e){return e&&new URL(e,document.baseURI).href}var k=typeof document>`u`?null:document.currentScript;k instanceof HTMLScriptElement&&k.src&&(E.defaultAssetBase=new URL(`pdfjs/`,k.src).href),c(`wui-file-viewer`,E);var A=(e,t)=>import(`./fileViewerPdf-BET_tiP6.js`).then(n=>n.renderFirstPage(e,{assetBase:E.defaultAssetBase||void 0,...t}));export{E as WuiFileViewer,S as fileKind,C as fileNameFromUrl,A as renderPdfFirstPage};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webority/ui-elements",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.178.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",
|
|
@@ -275,10 +275,10 @@
|
|
|
275
275
|
"@tiptap/starter-kit": "3.31.4",
|
|
276
276
|
"@types/node": "25.6.0",
|
|
277
277
|
"@vitest/coverage-v8": "5.1.0",
|
|
278
|
-
"@webority/biome-config": "0.
|
|
279
|
-
"@webority/markdown-core": "0.
|
|
280
|
-
"@webority/theme": "0.
|
|
281
|
-
"@webority/web-core": "0.
|
|
278
|
+
"@webority/biome-config": "0.178.0",
|
|
279
|
+
"@webority/markdown-core": "0.178.0",
|
|
280
|
+
"@webority/theme": "0.178.0",
|
|
281
|
+
"@webority/web-core": "0.178.0",
|
|
282
282
|
"echarts": "6.1.0",
|
|
283
283
|
"jsdom": "30.1.1",
|
|
284
284
|
"libphonenumber-js": "^1.13.9",
|
package/types/WuiInlineEdit.d.ts
CHANGED
|
@@ -2,6 +2,10 @@ import { type DigitGrouping } from "./digitGrouping.ts";
|
|
|
2
2
|
import { ElementBase } from "./elementBase.ts";
|
|
3
3
|
import { type InlineEditFailedDetail, type InlineEditSavedDetail, type InlineEditType } from "./inlineEditText.ts";
|
|
4
4
|
import { type HttpKind } from "./server/wuiHttp.ts";
|
|
5
|
+
type SelectRow = {
|
|
6
|
+
value: string;
|
|
7
|
+
label: string;
|
|
8
|
+
};
|
|
5
9
|
type SaveOutcome = {
|
|
6
10
|
ok: true;
|
|
7
11
|
text?: string;
|
|
@@ -26,6 +30,8 @@ export declare class WuiInlineEdit extends ElementBase {
|
|
|
26
30
|
_pressed: boolean;
|
|
27
31
|
_popupOpen: boolean;
|
|
28
32
|
_savedTimer: ReturnType<typeof setTimeout> | null;
|
|
33
|
+
_optionsLoaded: boolean;
|
|
34
|
+
_optionsLoading: Promise<void> | null;
|
|
29
35
|
/** Set by the page in controlled mode, to be awaited on save. */
|
|
30
36
|
save?: (next: string) => Promise<void> | void;
|
|
31
37
|
/** Set by the page, to return a refusal message for a value, or null to accept it. */
|
|
@@ -39,6 +45,10 @@ export declare class WuiInlineEdit extends ElementBase {
|
|
|
39
45
|
edit(): void;
|
|
40
46
|
/** Close the control and keep the value as it was. */
|
|
41
47
|
cancel(): void;
|
|
48
|
+
_needsLoad(): boolean;
|
|
49
|
+
_loadOptions(): void;
|
|
50
|
+
_showRows(control: InlineEditControl, rows: SelectRow[]): void;
|
|
51
|
+
_showLoadError(): void;
|
|
42
52
|
_onClick(e: Event): void;
|
|
43
53
|
_onKeyCapture(): void;
|
|
44
54
|
_onKeyDown(e: KeyboardEvent): void;
|
package/types/global/core.d.ts
CHANGED
|
@@ -1,19 +1,4 @@
|
|
|
1
|
-
import { WuiDataTable } from "../WuiDataTable.ts";
|
|
2
|
-
import { WuiDock } from "../WuiDock.ts";
|
|
3
|
-
import { WuiHoverCard } from "../WuiHoverCard.ts";
|
|
4
|
-
import { WuiNavigationMenu } from "../WuiNavigationMenu.ts";
|
|
5
|
-
import { WuiNotificationCenter } from "../WuiNotificationCenter.ts";
|
|
6
|
-
import { WuiOnboardingChecklist } from "../WuiOnboardingChecklist.ts";
|
|
7
|
-
import { WuiOtp } from "../WuiOtp.ts";
|
|
8
|
-
import { WuiOverflow } from "../WuiOverflow.ts";
|
|
9
|
-
import { WuiRating } from "../WuiRating.ts";
|
|
10
|
-
import { WuiRecordPager } from "../WuiRecordPager.ts";
|
|
11
|
-
import { WuiRelativeTime } from "../WuiRelativeTime.ts";
|
|
12
1
|
import { WuiSelect } from "../WuiSelect.ts";
|
|
13
|
-
import { WuiShortcuts } from "../WuiShortcuts.ts";
|
|
14
|
-
import { WuiShowMore } from "../WuiShowMore.ts";
|
|
15
|
-
import { WuiTruncate } from "../WuiTruncate.ts";
|
|
16
|
-
import { WuiWhatsNew } from "../WuiWhatsNew.ts";
|
|
17
2
|
import { whenElementsReady } from "./loader.ts";
|
|
18
3
|
import { SHARED_MODULES } from "./shared.ts";
|
|
19
4
|
declare global {
|
|
@@ -49,7 +34,6 @@ export { addRowSelectCells, addSelectColumn, attachShiftRange, createSelectHeade
|
|
|
49
34
|
export { fillText, pluralText, readText, setText } from "../text/textStore.ts";
|
|
50
35
|
export { matchSegments } from "../textMatch.ts";
|
|
51
36
|
export { applyTheme, DEFAULT_THEME_EFFECT, DEFAULT_THEME_STORAGE_KEY, nextTheme, readStoredTheme, resolveTheme, storeTheme, THEME_BOOT_SCRIPT_BODY, THEME_CHANGE_EVENT, THEME_EFFECT_DURATION, THEME_EFFECTS, THEME_MODES, THEME_SWITCHING_CLASS, themeBootScript, themeKeyframes, transitionTheme, watchSystemTheme, } from "../themeTransition.ts";
|
|
52
|
-
export { WHATS_NEW_READ_EVENT } from "../WuiWhatsNew.ts";
|
|
53
37
|
export { isTimeZone, todayIn, wallClockOf, zoneOffsetMs, zoneParts } from "../zone.ts";
|
|
54
38
|
export { glyphNode } from "./glyphs.ts";
|
|
55
|
-
export {
|
|
39
|
+
export { WuiSelect, whenElementsReady };
|
package/types/global/shared.d.ts
CHANGED
|
@@ -21,6 +21,7 @@ import * as menuKeyNav from "../menuKeyNav.ts";
|
|
|
21
21
|
import * as nativeOverlay from "../nativeOverlay.ts";
|
|
22
22
|
import * as notificationDays from "../notificationDays.ts";
|
|
23
23
|
import * as optionLabel from "../optionLabel.ts";
|
|
24
|
+
import * as relativeTime from "../relativeTime.ts";
|
|
24
25
|
import * as rtl from "../rtl.ts";
|
|
25
26
|
import * as selectList from "../select/list.ts";
|
|
26
27
|
import * as partRegistry from "../select/partRegistry.ts";
|
|
@@ -28,6 +29,7 @@ import * as selectRemote from "../select/remote.ts";
|
|
|
28
29
|
import * as selectWindow from "../select/window.ts";
|
|
29
30
|
import * as serverHtml from "../server/serverHtml.ts";
|
|
30
31
|
import * as wuiHttp from "../server/wuiHttp.ts";
|
|
32
|
+
import * as shortcutKeys from "../shortcutKeys.ts";
|
|
31
33
|
import * as stepperHeader from "../stepperHeader.ts";
|
|
32
34
|
import * as svgNodes from "../svgNodes.ts";
|
|
33
35
|
import * as tableSelect from "../tableSelect.ts";
|
|
@@ -35,6 +37,7 @@ import * as textStore from "../text/textStore.ts";
|
|
|
35
37
|
import * as datePickerText from "../text/web/datePicker.g.ts";
|
|
36
38
|
import * as drawerText from "../text/web/drawer.g.ts";
|
|
37
39
|
import * as httpFailureText from "../text/web/httpFailure.g.ts";
|
|
40
|
+
import * as notificationCentreText from "../text/web/notificationCentre.g.ts";
|
|
38
41
|
import * as selectText from "../text/web/select.g.ts";
|
|
39
42
|
import * as textMatch from "../textMatch.ts";
|
|
40
43
|
import * as tooltips from "../tooltips.ts";
|
|
@@ -70,15 +73,18 @@ export interface SharedModules {
|
|
|
70
73
|
readonly mentionText: typeof mentionText;
|
|
71
74
|
readonly menuKeyNav: typeof menuKeyNav;
|
|
72
75
|
readonly nativeOverlay: typeof nativeOverlay;
|
|
76
|
+
readonly notificationCentreText: typeof notificationCentreText;
|
|
73
77
|
readonly notificationDays: typeof notificationDays;
|
|
74
78
|
readonly optionLabel: typeof optionLabel;
|
|
75
79
|
readonly partRegistry: typeof partRegistry;
|
|
80
|
+
readonly relativeTime: typeof relativeTime;
|
|
76
81
|
readonly rtl: typeof rtl;
|
|
77
82
|
readonly selectList: typeof selectList;
|
|
78
83
|
readonly selectRemote: typeof selectRemote;
|
|
79
84
|
readonly selectText: typeof selectText;
|
|
80
85
|
readonly selectWindow: typeof selectWindow;
|
|
81
86
|
readonly serverHtml: typeof serverHtml;
|
|
87
|
+
readonly shortcutKeys: typeof shortcutKeys;
|
|
82
88
|
readonly stepperHeader: typeof stepperHeader;
|
|
83
89
|
readonly svgNodes: typeof svgNodes;
|
|
84
90
|
readonly tableExport: typeof tableExport;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export declare const LAZY_GROUPS: readonly ["files", "splitFilter", "themeTabs", "fieldChecks", "markupCheck"];
|
|
2
|
+
export type LazyGroup = (typeof LAZY_GROUPS)[number];
|
|
3
|
+
export declare const MARKUP_RULE_MARKERS: readonly string[];
|
|
4
|
+
export declare const GROUP_MARKERS: Readonly<Record<LazyGroup, string>>;
|
|
5
|
+
export declare const needsGroup: (group: LazyGroup, root: Document | Element, doc?: Document) => boolean;
|
|
6
|
+
export declare const groupFile: (group: LazyGroup) => string;
|
|
7
|
+
export declare const ownScriptUrl: (doc?: Document) => string;
|
|
8
|
+
export declare const groupUrl: (group: LazyGroup, scriptUrl: string) => string;
|
|
9
|
+
export interface GroupLoader<Modules extends Record<LazyGroup, unknown>> {
|
|
10
|
+
load: <G extends LazyGroup>(group: G) => Promise<Modules[G]>;
|
|
11
|
+
loaded: <G extends LazyGroup>(group: G) => Modules[G] | undefined;
|
|
12
|
+
track: (work: Promise<unknown>) => void;
|
|
13
|
+
settled: () => Promise<void>;
|
|
14
|
+
}
|
|
15
|
+
export declare const createGroupLoader: <Modules extends Record<LazyGroup, unknown>>(scriptUrl: string, importGroup: <G extends LazyGroup>(group: G, url: string) => Promise<Modules[G]>) => GroupLoader<Modules>;
|
|
16
|
+
export declare const BRIDGE_KEY = "WeborityUiRazorInternal";
|
|
17
|
+
export declare const BRIDGED_MODULES: Readonly<Record<string, string>>;
|
|
18
|
+
export interface RazorBridge {
|
|
19
|
+
readonly modules: Readonly<Record<string, object>>;
|
|
20
|
+
readonly settled: () => Promise<void>;
|
|
21
|
+
}
|
|
22
|
+
export declare const exposeBridge: (bridge: RazorBridge) => void;
|
|
@@ -3,7 +3,7 @@ import "./modules/pageListeners.ts";
|
|
|
3
3
|
import { button, drawer, filePicker, modal, pane, shell, table, tour, unsaved } from "./modules/api.ts";
|
|
4
4
|
import { look } from "./modules/look.ts";
|
|
5
5
|
import { dismissAllToasts, toast } from "./modules/toast.ts";
|
|
6
|
-
import
|
|
6
|
+
import * as validation from "./modules/validation.ts";
|
|
7
7
|
declare const refresh: (root?: Document | Element) => void;
|
|
8
8
|
export interface WuiApi {
|
|
9
9
|
modal: typeof modal;
|
|
@@ -17,7 +17,7 @@ export interface WuiApi {
|
|
|
17
17
|
unsaved: typeof unsaved;
|
|
18
18
|
toast: typeof toast;
|
|
19
19
|
dismissAllToasts: typeof dismissAllToasts;
|
|
20
|
-
showErrorSummary: typeof showErrorSummary;
|
|
20
|
+
showErrorSummary: typeof validation.showErrorSummary;
|
|
21
21
|
look: typeof look;
|
|
22
22
|
refresh: typeof refresh;
|
|
23
23
|
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{i as e}from"./calendarMath-CT99RyhR.js";import{n as t,r as n,t as r}from"./digitGrouping-CCPI3HK3.js";import{t as i}from"./elementBase-Cxeyx0tU.js";import{o as a}from"./formatters-DTW53DjY.js";import{n as o}from"./imeSafeEnter-DeO_3lXy.js";import{n as s,t as c}from"./inlineEditText-DRBhMnam.js";import{m as l}from"./wuiHttp-Cw7V8u2w.js";import{r as u,t as d}from"./textStore-DBplASiZ.js";import{t as f}from"./httpFailure.g-DjZzGxPj.js";import{t as p}from"./inlineEdit.g-ZxRNYq0t.js";var m=()=>u(`inlineEdit`,p),h=e=>s.some(t=>t===e),g=`[data-wui-display]`,_=`[data-wui-value]`,v=`[data-wui-editor]`,y=`[data-wui-control]`,b=`[data-wui-error]`,x=`[data-wui-live]`,S=`[aria-expanded="true"]`,C=/* @__PURE__ */ new Set([`select`,`date`]),w=e=>{let t=(typeof e==`object`||typeof e==`function`)&&e!==null&&`message`in e?e.message:void 0;return typeof t==`string`&&t?t:m().serverMessage},T=e=>e instanceof HTMLElement&&typeof(`value`in e?e.value:void 0)==`string`,E=(e,t)=>{let n=e?.querySelector(t)??null;return n instanceof HTMLElement?n:null},D=class extends i{_wired;_editing;_busy;_draft;_pressed;_popupOpen;_savedTimer;static get observedAttributes(){return[`disabled`]}constructor(){super(),this._wired=!1,this._editing=!1,this._busy=!1,this._draft=null,this._pressed=!1,this._popupOpen=!1,this._savedTimer=null,this._onClick=this._onClick.bind(this),this._onKeyCapture=this._onKeyCapture.bind(this),this._onKeyDown=this._onKeyDown.bind(this),this._onFocusOut=this._onFocusOut.bind(this),this._onPointerDown=this._onPointerDown.bind(this),this._onPointerUp=this._onPointerUp.bind(this),this._onChange=this._onChange.bind(this)}connectedCallback(){this._wired||(this._wired=!0,this._grouping(),this.addEventListener(`click`,this._onClick),this.addEventListener(`auxclick`,this._onClick),this.addEventListener(`keydown`,this._onKeyCapture,!0),this.addEventListener(`keydown`,this._onKeyDown),this.addEventListener(`focusout`,this._onFocusOut),this.addEventListener(`pointerdown`,this._onPointerDown),this.addEventListener(`change`,this._onChange))}disconnectedCallback(){clearTimeout(this._savedTimer??void 0),this._savedTimer=null,this._releasePress()}attributeChangedCallback(e){e===`disabled`&&this.hasAttribute(`disabled`)&&this.cancel()}edit(){if(this._editing||this._busy||this.hasAttribute(`disabled`))return;let e=E(this,g),t=E(this,v),n=this._control();e&&t&&n&&(this._editing=!0,this._setState(null),n.value=this._draft??this._value(),t.hidden=!1,this.setAttribute(`data-wui-editing`,``),this._focusControl(n),e.hidden=!0)}cancel(){this._editing&&(this._draft=null,this._setError(null),this.getAttribute(`data-wui-state`)===`error`&&this._setState(null),this._close())}_onClick(e){e.stopPropagation();let t=e.target instanceof Node?e.target:null;e.type===`click`&&!this._editing&&this.querySelector(g)?.contains(t)&&this.edit()}_onKeyCapture(){this._popupOpen=!!(this._editing&&this.querySelector(v)?.querySelector(S))}_onKeyDown(e){if(!this._editing){(o(e)||e.key===` `)&&e.stopPropagation();return}if(e.stopPropagation(),this._popupOpen)return;if(e.key===`Escape`){e.preventDefault(),this.cancel();return}let t=this._type();e.key!==`Enter`||C.has(t)||(t!==`textarea`||e.ctrlKey||e.metaKey)&&(e.preventDefault(),this._commit(this._control()?.value??``))}_onFocusOut(e){if(!this._editing||this._pressed)return;let t=e.relatedTarget instanceof Node?e.relatedTarget:null;t&&this.contains(t)||document.hasFocus()&&this._commit(this._control()?.value??``)}_onPointerDown(){this._editing&&(this._pressed=!0,document.addEventListener(`pointerup`,this._onPointerUp,!0),document.addEventListener(`pointercancel`,this._onPointerUp,!0))}_onPointerUp(){this._releasePress(),setTimeout(()=>{this._pressed=!1,this._editing&&!this.contains(document.activeElement)&&document.hasFocus()&&this._commit(this._control()?.value??``)},0)}_releasePress(){document.removeEventListener(`pointerup`,this._onPointerUp,!0),document.removeEventListener(`pointercancel`,this._onPointerUp,!0)}_onChange(e){if(!this._editing||!C.has(this._type()))return;let t=this._control();t&&e.target===t&&queueMicrotask(()=>this._commit(t.value))}async _commit(e){if(!this._editing||this._busy)return;let t=this._value();if(e===t){this.cancel();return}let n=typeof this.validate==`function`?this.validate(e):null;if(n){this._setError(n),this._announce(n);return}let r=this.hasAttribute(`controlled`);this._draft=null,this._setError(null),this._busy=!0,this._setState(`saving`),this.setAttribute(`aria-busy`,`true`);let i=r?null:this._readShown();r||this._showValue(e),this._close();let a=await this._persist(e,r);this._busy=!1,this.removeAttribute(`aria-busy`);let o=this.getAttribute(`label`)||``;a.ok?(this.setAttribute(`value`,e),!r&&a.text&&this._showText(a.text,!1),this._setState(`saved`),this._savedTimer=setTimeout(()=>this._setState(null),c),this._announce(d(m().savedText,{label:o})),this._fire(`wui:inline-edit:saved`,{value:e,previous:t})):(i&&this._restoreShown(i),a.kind===`session`||a.kind===`aborted`?this._setState(null):(this._draft=e,this._setState(`error`),this._setError(a.message),this._announce(d(m().notSavedText,{label:o,reason:a.message})),this._fire(`wui:inline-edit:failed`,{value:e,previous:t,kind:a.kind,message:a.message})))}async _persist(e,t){if(t){if(typeof this.save!=`function`)return{ok:!0};try{return await this.save(e),{ok:!0}}catch(e){return{ok:!1,kind:`server`,message:w(e)}}}let n=this.getAttribute(`action`);if(!n)return{ok:!0};let r=new URLSearchParams({[this.getAttribute(`name`)||`value`]:e}),i=await l(n,{method:`POST`,body:r});if(i.ok)return{ok:!0,text:i.html.trim()};let a={forbidden:m().forbiddenMessage,networkCheck:u(`httpFailure`,f).networkCheckText,client:m().clientMessage,validation:m().validationMessage,server:m().serverMessage,network:m().networkMessage};return{ok:!1,kind:i.kind,message:i.message||a[i.kind]||m().serverMessage}}_close(){let e=E(this,g),t=E(this,v),n=this.contains(document.activeElement);this._editing=!1,this.removeAttribute(`data-wui-editing`),t&&(t.hidden=!0),e&&(e.hidden=!1),E(t,S)?.click(),n&&e?.focus()}_focusControl(e){if(!C.has(this._type())){e.focus(),e.select?.();return}let t=E(e,`button`);t&&(t.focus(),t.getAttribute(`aria-expanded`)!==`true`&&t.click())}_showValue(t){if(t===``){this._showText(this.getAttribute(`placeholder`)||a(),!0);return}let n=this._type(),i=t;if(n===`date`)i=e(t)||t;else if(n===`select`){let e=[...this._control()?.querySelectorAll(`[data-value]`)??[]].find(e=>e.getAttribute(`data-value`)===t);e&&(i=(e.textContent??``).trim())}else n===`number`&&this._grouping()===`indian`&&(i=r(t));this._showText(i,!1)}_readShown(){let e=this.querySelector(_);return e?{nodes:[...e.childNodes].map(e=>e.cloneNode(!0)),empty:e.hasAttribute(`data-wui-empty`)}:null}_restoreShown(e){let t=this.querySelector(_);t&&(t.replaceChildren(...e.nodes),t.toggleAttribute(`data-wui-empty`,e.empty))}_showText(e,t){let n=this.querySelector(_);n&&(n.textContent=e,n.toggleAttribute(`data-wui-empty`,t))}_setError(e){let t=E(this,b),n=this._control();t&&(t.textContent=e||``,t.hidden=!e),e?n?.setAttribute(`aria-invalid`,`true`):n?.removeAttribute(`aria-invalid`)}_setState(e){clearTimeout(this._savedTimer??void 0),this._savedTimer=null,e?this.setAttribute(`data-wui-state`,e):this.removeAttribute(`data-wui-state`)}_announce(e){let t=this.querySelector(x);t&&e&&(t.textContent=``,t.textContent=e)}_fire(e,t){this.dispatchEvent(new CustomEvent(e,{bubbles:!0,detail:t}))}_control(){let e=this.querySelector(y);return T(e)?e:null}_value(){return this.getAttribute(`value`)??``}_type(){let e=this.getAttribute(`type`);return h(e)?e:`text`}_grouping(){let e=this.getAttribute(`grouping`)??`none`;if(!n(e))throw Error(t(e));return e}};export{D as t};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
var e={clientMessage:`This could not be saved. Refresh the page and try again.`,editText:`Edit {label}: `,forbiddenMessage:`You do not have permission to change this.`,networkMessage:`Could not reach the server, so this was not saved. Check your connection and try again.`,notSavedText:`{label} was not saved. {reason}`,readOnlyText:`{label}: `,savedText:`{label} saved.`,serverMessage:`Something went wrong on our side, so this was not saved. Try again in a moment.`,validationMessage:`This value was not accepted. Check it and try again.`};export{e as t};
|
package/dist/loader-DvNLnnaO.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
var e=Object.freeze({carousel:{entries:[`elements/carousel.ts`],tags:[`wui-carousel`]},"code-block":{entries:[`elements/code-block.ts`],tags:[`wui-code-block`]},"command-palette":{entries:[`elements/command-palette.ts`],tags:[`wui-command-palette`]},"comment-thread":{entries:[`elements/comment-thread.ts`],tags:[`wui-mention-input`,`wui-comment-thread`]},"consent-banner":{entries:[`elements/consent-banner.ts`],tags:[`wui-consent-banner`]},"context-menu":{entries:[`elements/context-menu.ts`],tags:[`wui-context-menu`]},"date-range":{entries:[`elements/date-range.ts`],tags:[`wui-date-range`]},"date-time":{entries:[`elements/date-time.ts`],tags:[`wui-date-time`]},datepicker:{entries:[`elements/datepicker.ts`],tags:[`wui-datepicker`]},drawer:{entries:[`elements/drawer.ts`],tags:[`wui-drawer`]},dropdown:{entries:[`elements/dropdown.ts`],tags:[`wui-dropdown`]},"entry-grid":{entries:[`elements/entry-grid.ts`],tags:[`wui-entry-grid`]},gantt:{entries:[`elements/gantt.ts`],tags:[`wui-gantt`]},"image-crop":{entries:[`elements/image-crop.ts`],tags:[`wui-image-crop`]},"inline-edit":{entries:[`elements/inline-edit.ts`],tags:[`wui-inline-edit`]},kanban:{entries:[`elements/kanban.ts`],tags:[`wui-kanban`]},"lead-popup":{entries:[`elements/lead-popup.ts`],tags:[`wui-lead-popup`]},lightbox:{entries:[`elements/lightbox.ts`],tags:[`wui-lightbox`]},"org-tree":{entries:[`elements/org-tree.ts`],tags:[`wui-org-tree`]},markdown:{entries:[`elements/markdown.ts`],tags:[`wui-markdown`]},phone:{entries:[`elements/phone.ts`,`global/parts/select-country.ts`],tags:[`wui-phone`]},popover:{entries:[`elements/popover.ts`],tags:[`wui-popover`]},"saved-views":{entries:[`elements/saved-views.ts`],tags:[`wui-saved-views`]},glyphs:{entries:[`global/parts/glyphs.ts`],tags:[]},"select-chips":{entries:[`global/parts/select-chips.ts`],tags:[]},"select-recents":{entries:[`global/parts/select-recents.ts`],tags:[]},"select-search":{entries:[`global/parts/select-search.ts`],tags:[]},"select-window":{entries:[`global/parts/select-window.ts`],tags:[]},"table-export":{entries:[`global/parts/table-export.ts`],tags:[]},slider:{entries:[`elements/slider.ts`],tags:[`wui-slider`]},sortable:{entries:[`elements/sortable.ts`],tags:[`wui-sortable`]},"status-icon":{entries:[`elements/status-icon.ts`],tags:[`wui-status-icon`]},timepicker:{entries:[`elements/timepicker.ts`],tags:[`wui-timepicker`]},tour:{entries:[`elements/tour.ts`],tags:[`wui-tour`]},tree:{entries:[`elements/tree.ts`],tags:[`wui-tree`]},"tree-picker":{entries:[`elements/tree-picker.ts`],tags:[`wui-tree-picker`]},wizard:{entries:[`elements/wizard.ts`],tags:[`wui-wizard-step`,`wui-wizard`]},chart:{file:`ui-chart.global.js`,tags:[`wui-chart`],selfContained:!0},calendar:{file:`ui-calendar.global.js`,tags:[`wui-calendar`],selfContained:!0},"rich-text":{file:`ui-rich-text.global.js`,tags:[`wui-rich-text`],selfContained:!0},"file-viewer":{file:`ui-file-viewer.global.js`,tags:[`wui-file-viewer`],selfContained:!0}});Object.freeze({anchorOverlay:`anchorOverlay.ts`,avatarNode:`avatarNode.ts`,buttonClass:`buttonClass.ts`,calendarMath:`calendarMath.ts`,copyText:`copyText.ts`,dataTable:`dataTable.ts`,datePickerText:`text/web/datePicker.g.ts`,defineElement:`defineElement.ts`,devWarn:`devWarn.ts`,dom:`dom.ts`,drawerText:`text/web/drawer.g.ts`,elementBase:`elementBase.ts`,fieldState:`fieldState.ts`,formatters:`formatters.ts`,formMirror:`formMirror.ts`,glyphs:`global/glyphs.ts`,hasOwn:`hasOwn.ts`,httpFailureText:`text/web/httpFailure.g.ts`,iconGlyphs:`iconGlyphs.g.ts`,imeSafeEnter:`imeSafeEnter.ts`,isDrawn:`isDrawn.ts`,listboxKeyNav:`listboxKeyNav.ts`,loader:`global/loader.ts`,mentionText:`mentionText.ts`,menuKeyNav:`menuKeyNav.ts`,nativeOverlay:`nativeOverlay.ts`,notificationDays:`notificationDays.ts`,optionLabel:`optionLabel.ts`,partRegistry:`select/partRegistry.ts`,rtl:`rtl.ts`,selectList:`select/list.ts`,selectRemote:`select/remote.ts`,selectText:`text/web/select.g.ts`,selectWindow:`select/window.ts`,serverHtml:`server/serverHtml.ts`,stepperHeader:`stepperHeader.ts`,svgNodes:`svgNodes.ts`,tableExport:`global/tableExport.ts`,tableSelect:`tableSelect.ts`,textMatch:`textMatch.ts`,textStore:`text/textStore.ts`,tooltips:`tooltips.ts`,wuiHttp:`server/wuiHttp.ts`,WuiSelect:`WuiSelect.ts`,zone:`zone.ts`});var t=`wui-elements:defined`,n=`wui-elements:load-error`,r=/* @__PURE__ */ new Map;for(let[t,n]of Object.entries(e))for(let e of n.tags)r.set(e,t);[...r.keys()].join(`,`);export{n,t};
|