@webority/ui-elements 0.152.0 → 0.154.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.
Files changed (71) hide show
  1. package/dist/{WuiCodeBlock-DHpmEskS.js → WuiCodeBlock-cLLbSBK4.js} +1 -1
  2. package/dist/{WuiCommandPalette-DqHh4lH6.js → WuiCommandPalette-Dpz0DXKJ.js} +1 -1
  3. package/dist/{WuiDataTable-B4BYCd_s.js → WuiDataTable-8nQDiTHE.js} +1 -1
  4. package/dist/{WuiLeadPopup-YN4YCbOe.js → WuiLeadPopup-BmZG0Fk_.js} +1 -1
  5. package/dist/{WuiOnboardingChecklist-Cx-TgpBY.js → WuiOnboardingChecklist-C-nllg2h.js} +1 -1
  6. package/dist/{WuiResizable-DQZdQVCz.js → WuiResizable-KvfLtbCw.js} +1 -1
  7. package/dist/{WuiSavedViews-UaiP6YNG.js → WuiSavedViews-Br9YKOVU.js} +1 -1
  8. package/dist/{WuiSelect-DBPre2oe.js → WuiSelect-BPWPI07i.js} +1 -1
  9. package/dist/{chips-Dony2fgq.js → chips-Dr_W3avk.js} +1 -1
  10. package/dist/copyText-Q-QZKBmx.js +1 -0
  11. package/dist/dataTable-CcH1lBIM.js +1 -0
  12. package/dist/{drawerDiscard-C0yRSl1I.js → drawerDiscard-Cra-QhD5.js} +1 -1
  13. package/dist/elements/code-block.js +1 -1
  14. package/dist/elements/command-palette.js +1 -1
  15. package/dist/elements/data-table.js +1 -1
  16. package/dist/elements/filter-popover.js +1 -1
  17. package/dist/elements/kanban.js +1 -1
  18. package/dist/elements/lead-popup.js +1 -1
  19. package/dist/elements/onboarding-checklist.js +1 -1
  20. package/dist/elements/resizable.js +1 -1
  21. package/dist/elements/saved-views.js +1 -1
  22. package/dist/elements/select.js +1 -1
  23. package/dist/filterPopover-CaHWe9V0.js +1 -0
  24. package/dist/helpers.js +1 -1
  25. package/dist/{kanban-Dz8m-17x.js → kanban-CDaks135.js} +1 -1
  26. package/dist/{kanbanModel-C2IOPJ8L.js → kanbanModel-BaT75e-b.js} +1 -1
  27. package/dist/recents-Dcw-b5cB.js +1 -0
  28. package/dist/{search-C8xIzt6h.js → search-PZCXpBAn.js} +1 -1
  29. package/dist/server.js +1 -1
  30. package/dist/{themeTransition-9LQC6fx8.js → themeTransition-CfrJtERx.js} +1 -1
  31. package/dist/ui-elements/carousel.global.js +1 -1
  32. package/dist/ui-elements/code-block.global.js +1 -1
  33. package/dist/ui-elements/command-palette.global.js +2 -2
  34. package/dist/ui-elements/comment-thread.global.js +1 -1
  35. package/dist/ui-elements/consent-banner.global.js +1 -1
  36. package/dist/ui-elements/context-menu.global.js +1 -1
  37. package/dist/ui-elements/date-range.global.js +1 -1
  38. package/dist/ui-elements/drawer.global.js +1 -1
  39. package/dist/ui-elements/glyphs.global.js +1 -1
  40. package/dist/ui-elements/image-crop.global.js +1 -1
  41. package/dist/ui-elements/inline-edit.global.js +1 -1
  42. package/dist/ui-elements/kanban.global.js +1 -1
  43. package/dist/ui-elements/lead-popup.global.js +2 -2
  44. package/dist/ui-elements/lightbox.global.js +1 -1
  45. package/dist/ui-elements/markdown.global.js +1 -1
  46. package/dist/ui-elements/org-tree.global.js +1 -1
  47. package/dist/ui-elements/phone.global.js +1 -1
  48. package/dist/ui-elements/resizable.global.js +1 -1
  49. package/dist/ui-elements/saved-views.global.js +1 -1
  50. package/dist/ui-elements/select-chips.global.js +1 -1
  51. package/dist/ui-elements/select-recents.global.js +1 -1
  52. package/dist/ui-elements/select-search.global.js +1 -1
  53. package/dist/ui-elements/slider.global.js +1 -1
  54. package/dist/ui-elements/sortable.global.js +1 -1
  55. package/dist/ui-elements/status-icon.global.js +1 -1
  56. package/dist/ui-elements/timepicker.global.js +1 -1
  57. package/dist/ui-elements/tour.global.js +1 -1
  58. package/dist/ui-elements/tree.global.js +1 -1
  59. package/dist/ui-elements/wizard.global.js +1 -1
  60. package/dist/ui-elements.global.js +3 -3
  61. package/dist/ui-elements.js +1 -1
  62. package/dist/ui-file-viewer.global.js +1 -1
  63. package/dist/ui-file-viewer.js +1 -1
  64. package/dist/ui-lead-popup.global.js +1 -1
  65. package/package.json +4 -4
  66. package/types/copyText.d.ts +1 -1
  67. package/types/themeTransition.d.ts +1 -1
  68. package/dist/copyText-DM5HhXjf.js +0 -1
  69. package/dist/dataTable-B-7oAeii.js +0 -1
  70. package/dist/filterPopover-D8BOb-Hz.js +0 -1
  71. package/dist/recents-CmLLdV8O.js +0 -1
@@ -1 +1 @@
1
- import{n as e}from"./elementBase-Cxeyx0tU.js";import{n as t}from"./filterPopover-D8BOb-Hz.js";import{t as n}from"./kanban-Dz8m-17x.js";import{n as r}from"./statusIcons-CRtqA_1C.js";import{t as i}from"./WuiCarousel-DthhDxH-.js";import{t as a}from"./WuiCodeBlock-DHpmEskS.js";import{t as o}from"./WuiCommandPalette-DqHh4lH6.js";import{t as s}from"./WuiCommentThread-BmRsl0K1.js";import{t as c}from"./WuiConsentBanner-Bm7tT3_5.js";import{t as l}from"./WuiContextMenu-sPTmEEVn.js";import{t as u}from"./WuiDataTable-B4BYCd_s.js";import{t as d}from"./WuiDatePicker-DLEsnzqG.js";import{t as f}from"./WuiDateRange-9Xqs5nvv.js";import{t as p}from"./WuiDock-d5abaLkL.js";import{t as m}from"./WuiDrawer-B3YFmxl2.js";import{t as h}from"./WuiHoverCard-CE3dHKaM.js";import{t as g}from"./WuiImageCrop-ChvH8GKb.js";import{t as _}from"./WuiInlineEdit-BlBuWkHG.js";import{t as v}from"./WuiLeadPopup-YN4YCbOe.js";import{t as y}from"./WuiLightbox-C2A14vHx.js";import{t as b}from"./WuiMarkdown-BXY0QKaO.js";import{i as x}from"./WuiMentionInput-8Xjkzdqg.js";import{t as S}from"./WuiNavigationMenu-CZ3XhFam.js";import{t as C}from"./WuiNotificationCenter-ClkCTUnp.js";import{t as w}from"./WuiOnboardingChecklist-Cx-TgpBY.js";import{t as T}from"./WuiOrgTree-DzeLFQxy.js";import{t as E}from"./WuiOtp-DonxSwVn.js";import{t as D}from"./WuiOverflow-B0wA6aDe.js";import{t as O}from"./WuiPhone-BVNVerap.js";import{t as k}from"./WuiRating-DLVduJZ_.js";import{t as A}from"./WuiRecordPager-7HVGoFlP.js";import{t as j}from"./WuiRelativeTime-DyeUQOQ8.js";import{t as M}from"./WuiResizable-DQZdQVCz.js";import{t as N}from"./WuiRollingNumber-sfgNzaP0.js";import{t as P}from"./WuiSavedViews-UaiP6YNG.js";import{t as F}from"./WuiSelect-DBPre2oe.js";import{t as I}from"./WuiShortcuts-D3rWkaOm.js";import{t as L}from"./WuiShowMore-CvdNQXrA.js";import{t as R}from"./WuiSlider-D33Y3_t9.js";import{t as z}from"./WuiSortable-CBLMNRuZ.js";import{t as B}from"./WuiTimePicker-DOodgU2O.js";import{t as V}from"./WuiTour-Cx61ijsm.js";import{t as H}from"./WuiTree-0Yqu199O.js";import{t as U}from"./WuiTruncate-C2WV1-NN.js";import{n as W,t as ee}from"./WuiWhatsNew-dLGyA4g1.js";import{n as G,t as K}from"./WuiWizardStep-Cencr-mT.js";import{c as q,f as J,l as Y,m as X,p as Z,s as Q,u as te}from"./formatters-ljfITOZ3.js";import{_ as ne,r as re}from"./themeTransition-9LQC6fx8.js";import{t as ie}from"./drawerDiscard-C0yRSl1I.js";import{i as ae}from"./shortcutKeys-COVLox98.js";function $(){t(),e(`wui-select`,F),e(`wui-saved-views`,P),e(`wui-phone`,O),e(`wui-datepicker`,d),e(`wui-date-range`,f),e(`wui-dock`,p),e(`wui-image-crop`,g),e(`wui-kanban`,n),e(`wui-lead-popup`,v),e(`wui-inline-edit`,_),e(`wui-consent-banner`,c),e(`wui-slider`,R),e(`wui-sortable`,z),e(`wui-timepicker`,B),e(`wui-tour`,V),e(`wui-tree`,H),e(`wui-org-tree`,T),e(`wui-command-palette`,o),e(`wui-context-menu`,l),e(`wui-otp`,E),e(`wui-status-icon`,r),e(`wui-shortcuts`,I),e(`wui-record-pager`,A),e(`wui-carousel`,i),e(`wui-code-block`,a),e(`wui-markdown`,b),e(`wui-data-table`,u),e(`wui-drawer`,m),e(`wui-hover-card`,h),e(`wui-lightbox`,y),e(`wui-navigation-menu`,S),e(`wui-notification-center`,C),e(`wui-onboarding-checklist`,w),e(`wui-overflow`,D),e(`wui-rating`,k),e(`wui-relative-time`,j),e(`wui-resizable`,M),e(`wui-rolling-number`,N),e(`wui-show-more`,L),e(`wui-truncate`,U),e(`wui-whats-new`,W),e(`wui-mention-input`,x),e(`wui-comment-thread`,s),e(`wui-wizard-step`,K),e(`wui-wizard`,G)}$();export{ie as DISCARD_EVENT,ne as ROW_DROP_EVENT,ae as SHORTCUT_EVENT,re as THEME_CHANGE_EVENT,ee as WHATS_NEW_READ_EVENT,i as WuiCarousel,a as WuiCodeBlock,o as WuiCommandPalette,s as WuiCommentThread,c as WuiConsentBanner,l as WuiContextMenu,u as WuiDataTable,d as WuiDatePicker,f as WuiDateRange,p as WuiDock,m as WuiDrawer,h as WuiHoverCard,g as WuiImageCrop,_ as WuiInlineEdit,n as WuiKanban,v as WuiLeadPopup,y as WuiLightbox,b as WuiMarkdown,x as WuiMentionInput,S as WuiNavigationMenu,C as WuiNotificationCenter,w as WuiOnboardingChecklist,T as WuiOrgTree,E as WuiOtp,D as WuiOverflow,O as WuiPhone,k as WuiRating,A as WuiRecordPager,j as WuiRelativeTime,M as WuiResizable,N as WuiRollingNumber,P as WuiSavedViews,F as WuiSelect,I as WuiShortcuts,L as WuiShowMore,R as WuiSlider,z as WuiSortable,r as WuiStatusIcon,B as WuiTimePicker,V as WuiTour,H as WuiTree,U as WuiTruncate,W as WuiWhatsNew,G as WuiWizard,K as WuiWizardStep,$ as defineWeborityElements,Q as formatCompact,q as formatCurrency,Y as formatDate,te as formatDateTime,J as formatNumber,Z as formatPercent,X as formatValue};
1
+ import{n as e}from"./elementBase-Cxeyx0tU.js";import{n as t}from"./filterPopover-CaHWe9V0.js";import{t as n}from"./kanban-CDaks135.js";import{n as r}from"./statusIcons-CRtqA_1C.js";import{t as i}from"./WuiCarousel-DthhDxH-.js";import{t as a}from"./WuiCodeBlock-cLLbSBK4.js";import{t as o}from"./WuiCommandPalette-Dpz0DXKJ.js";import{t as s}from"./WuiCommentThread-BmRsl0K1.js";import{t as c}from"./WuiConsentBanner-Bm7tT3_5.js";import{t as l}from"./WuiContextMenu-sPTmEEVn.js";import{t as u}from"./WuiDataTable-8nQDiTHE.js";import{t as d}from"./WuiDatePicker-DLEsnzqG.js";import{t as f}from"./WuiDateRange-9Xqs5nvv.js";import{t as p}from"./WuiDock-d5abaLkL.js";import{t as m}from"./WuiDrawer-B3YFmxl2.js";import{t as h}from"./WuiHoverCard-CE3dHKaM.js";import{t as g}from"./WuiImageCrop-ChvH8GKb.js";import{t as _}from"./WuiInlineEdit-BlBuWkHG.js";import{t as v}from"./WuiLeadPopup-BmZG0Fk_.js";import{t as y}from"./WuiLightbox-C2A14vHx.js";import{t as b}from"./WuiMarkdown-BXY0QKaO.js";import{i as x}from"./WuiMentionInput-8Xjkzdqg.js";import{t as S}from"./WuiNavigationMenu-CZ3XhFam.js";import{t as C}from"./WuiNotificationCenter-ClkCTUnp.js";import{t as w}from"./WuiOnboardingChecklist-C-nllg2h.js";import{t as T}from"./WuiOrgTree-DzeLFQxy.js";import{t as E}from"./WuiOtp-DonxSwVn.js";import{t as D}from"./WuiOverflow-B0wA6aDe.js";import{t as O}from"./WuiPhone-BVNVerap.js";import{t as k}from"./WuiRating-DLVduJZ_.js";import{t as A}from"./WuiRecordPager-7HVGoFlP.js";import{t as j}from"./WuiRelativeTime-DyeUQOQ8.js";import{t as M}from"./WuiResizable-KvfLtbCw.js";import{t as N}from"./WuiRollingNumber-sfgNzaP0.js";import{t as P}from"./WuiSavedViews-Br9YKOVU.js";import{t as F}from"./WuiSelect-BPWPI07i.js";import{t as I}from"./WuiShortcuts-D3rWkaOm.js";import{t as L}from"./WuiShowMore-CvdNQXrA.js";import{t as R}from"./WuiSlider-D33Y3_t9.js";import{t as z}from"./WuiSortable-CBLMNRuZ.js";import{t as B}from"./WuiTimePicker-DOodgU2O.js";import{t as V}from"./WuiTour-Cx61ijsm.js";import{t as H}from"./WuiTree-0Yqu199O.js";import{t as U}from"./WuiTruncate-C2WV1-NN.js";import{n as W,t as ee}from"./WuiWhatsNew-dLGyA4g1.js";import{n as G,t as K}from"./WuiWizardStep-Cencr-mT.js";import{c as q,f as J,l as Y,m as X,p as Z,s as Q,u as te}from"./formatters-ljfITOZ3.js";import{_ as ne,r as re}from"./themeTransition-CfrJtERx.js";import{t as ie}from"./drawerDiscard-Cra-QhD5.js";import{i as ae}from"./shortcutKeys-COVLox98.js";function $(){t(),e(`wui-select`,F),e(`wui-saved-views`,P),e(`wui-phone`,O),e(`wui-datepicker`,d),e(`wui-date-range`,f),e(`wui-dock`,p),e(`wui-image-crop`,g),e(`wui-kanban`,n),e(`wui-lead-popup`,v),e(`wui-inline-edit`,_),e(`wui-consent-banner`,c),e(`wui-slider`,R),e(`wui-sortable`,z),e(`wui-timepicker`,B),e(`wui-tour`,V),e(`wui-tree`,H),e(`wui-org-tree`,T),e(`wui-command-palette`,o),e(`wui-context-menu`,l),e(`wui-otp`,E),e(`wui-status-icon`,r),e(`wui-shortcuts`,I),e(`wui-record-pager`,A),e(`wui-carousel`,i),e(`wui-code-block`,a),e(`wui-markdown`,b),e(`wui-data-table`,u),e(`wui-drawer`,m),e(`wui-hover-card`,h),e(`wui-lightbox`,y),e(`wui-navigation-menu`,S),e(`wui-notification-center`,C),e(`wui-onboarding-checklist`,w),e(`wui-overflow`,D),e(`wui-rating`,k),e(`wui-relative-time`,j),e(`wui-resizable`,M),e(`wui-rolling-number`,N),e(`wui-show-more`,L),e(`wui-truncate`,U),e(`wui-whats-new`,W),e(`wui-mention-input`,x),e(`wui-comment-thread`,s),e(`wui-wizard-step`,K),e(`wui-wizard`,G)}$();export{ie as DISCARD_EVENT,ne as ROW_DROP_EVENT,ae as SHORTCUT_EVENT,re as THEME_CHANGE_EVENT,ee as WHATS_NEW_READ_EVENT,i as WuiCarousel,a as WuiCodeBlock,o as WuiCommandPalette,s as WuiCommentThread,c as WuiConsentBanner,l as WuiContextMenu,u as WuiDataTable,d as WuiDatePicker,f as WuiDateRange,p as WuiDock,m as WuiDrawer,h as WuiHoverCard,g as WuiImageCrop,_ as WuiInlineEdit,n as WuiKanban,v as WuiLeadPopup,y as WuiLightbox,b as WuiMarkdown,x as WuiMentionInput,S as WuiNavigationMenu,C as WuiNotificationCenter,w as WuiOnboardingChecklist,T as WuiOrgTree,E as WuiOtp,D as WuiOverflow,O as WuiPhone,k as WuiRating,A as WuiRecordPager,j as WuiRelativeTime,M as WuiResizable,N as WuiRollingNumber,P as WuiSavedViews,F as WuiSelect,I as WuiShortcuts,L as WuiShowMore,R as WuiSlider,z as WuiSortable,r as WuiStatusIcon,B as WuiTimePicker,V as WuiTour,H as WuiTree,U as WuiTruncate,W as WuiWhatsNew,G as WuiWizard,K as WuiWizardStep,$ as defineWeborityElements,Q as formatCompact,q as formatCurrency,Y as formatDate,te as formatDateTime,J as formatNumber,Z as formatPercent,X as formatValue};
@@ -16,4 +16,4 @@ html, body { margin: 0; padding: 0; }
16
16
  img { display: block; break-after: page; }
17
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 ka(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 $(e,t){let n=e[t];if(n===void 0)throw RangeError(`No item at index ${t}.`);return n}function Aa(e){let t=[...e].sort((e,t)=>e-t);return $(t,Math.floor(t.length/2))}var ja,Ma,Na,Pa,Fa,Ia,La,Ra,za,Ba,Va,Ha,Ua,Wa,Ga,Ka,qa,Ja,Ya,Xa,Za,Qa,$a,eo,to,no=n((()=>{pa(),ha(),Sa(),j(),ee(),ja=[.5,.75,1,1.25,1.5,2,3],Ma=[.5,.75,1,1.25,1.5,2],Na=[{key:`fit-width`,label:`Fit width`},{key:`fit-page`,label:`Fit page`}],Pa=96/72,Fa=12,Ia=10,La=168,Ra=150,za=2,Ba=2e3,Va=5,Ha=150,Ua=16777216,Wa=null,Ga=e=>Na.some(t=>t.key===e),Ka=e=>{if(Ga(e))return e;let t=Number(e);return ja.includes(t)?t:`fit-width`},qa=e=>e instanceof Element&&e.closest(`input, textarea, select, [contenteditable='true'], .dropdown-menu`),Ja=e=>/^(https?:|mailto:)/i.test(e),Ya=class{constructor(e,t){this.shell=e,this.source=t;let n=e.prefs;this.zoom=Ka(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(){wa(this.source.workerSrc),this.task=ht({url:this.source.src,...Ta(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:Pa});return{width:t.width,height:t.height}}),this._buildToolbar(),this._buildBody(),this._layout(),this.shell.loaded({kind:`pdf`,pages:e.numPages}))}destroy(){this.destroyed=!0;for(let e of this._timers)window.clearTimeout(e);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=>{d(`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=O(`menu`,``,{size:17}),this.thumbsButton.addEventListener(`click`,()=>this._setThumbs(!this.showThumbs)),e.prepend(this.thumbsButton),this.prevButton=O(`chevron-up`,`Previous page`),this.prevButton.addEventListener(`click`,()=>this.goToPage(this.current()-this.cols()));let i=document.createElement(`span`);i.className=`wui-file-viewer-page`,this.pageInput=document.createElement(`input`),this.pageInput.className=`wui-file-viewer-page-input`,this.pageInput.setAttribute(`aria-label`,`Page number`),this.pageInput.inputMode=`numeric`,this.pageInput.addEventListener(`input`,()=>{this.pageInput.value=this.pageInput.value.replace(/[^\d]/g,``)}),this.pageInput.addEventListener(`keydown`,e=>{e.key===`Enter`&&this.pageInput.blur()}),this.pageInput.addEventListener(`blur`,()=>this._commitPageInput());let a=document.createElement(`span`);a.className=`wui-file-viewer-page-total`,a.textContent=`/ ${this.pdf.numPages}`,i.append(this.pageInput,a),this.nextButton=O(`chevron-down`,`Next page`),this.nextButton.addEventListener(`click`,()=>this.goToPage(this.current()+this.cols())),t.append(this.prevButton,i,this.nextButton),this.searchButton=O(`search`,`Search the document`,{className:`wui-file-viewer-search-toggle`}),this.searchButton.setAttribute(`aria-controls`,`${r.uid}-search`),this.searchButton.addEventListener(`click`,()=>this.search.open?this._closeSearch():this._openSearch()),this.zoomOutButton=O(`zoom-out`,`Zoom out`),this.zoomOutButton.addEventListener(`click`,()=>this._stepZoom(-1)),this.zoomButton=document.createElement(`button`),this.zoomButton.type=`button`,this.zoomButton.className=`wui-file-viewer-zoom`,te(this.zoomButton,{label:`Zoom`,items:()=>[...Ma.map(e=>({key:String(e),label:`${Math.round(e*100)}%`,checked:this.zoom===e})),{key:`fit-divider`,divider:!0},...Na.map(e=>({key:e.key,label:e.label,checked:this.zoom===e.key}))],onPick:e=>this._setZoom(Ka(e))}),this.zoomInButton=O(`zoom-in`,`Zoom in`),this.zoomInButton.addEventListener(`click`,()=>this._stepZoom(1));let o=document.createElement(`span`);o.className=`wui-file-viewer-divider`,this.twoPageButton=O(`two-page`,`Two-page view`),this.twoPageButton.addEventListener(`click`,()=>this._setTwoPage(!this.twoPage)),this.printButton=O(`printer`,`Print`,{className:`wui-file-viewer-print`}),this.printButton.addEventListener(`click`,()=>this.print()),this.printButton.hidden=!this.shell.print(),n.prepend(this.searchButton,this.zoomOutButton,this.zoomButton,this.zoomInButton,o,this.twoPageButton,this.printButton),this._buildSearchRow(),this._syncToolbar()}_buildSearchRow(){let e=this.shell.search;e.id=`${this.shell.host.uid}-search`;let t=document.createElement(`div`);t.className=`wui-file-viewer-search-field`,this.searchInput=document.createElement(`input`),this.searchInput.type=`search`,this.searchInput.className=`form-control form-control-sm`,this.searchInput.placeholder=`Search the document`,this.searchInput.setAttribute(`aria-label`,`Search the document`),this.searchInput.addEventListener(`input`,()=>this._setQuery(this.searchInput.value)),this.searchInput.addEventListener(`keydown`,e=>{e.key===`Enter`?(e.preventDefault(),this._goToHit(this.search.current+(e.shiftKey?-1:1))):e.key===`Escape`&&(e.preventDefault(),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=O(`chevron-up`,`Previous match`),this.prevHitButton.addEventListener(`click`,()=>this._goToHit(this.search.current-1)),this.nextHitButton=O(`chevron-down`,`Next match`),this.nextHitButton.addEventListener(`click`,()=>this._goToHit(this.search.current+1));let n=O(`x`,`Close search`);n.addEventListener(`click`,()=>this._closeSearch()),e.append(t,this.searchStatus,this.prevHitButton,this.nextHitButton,n)}_syncToolbar(){let e=this.current(),t=this.rows.length-1;document.activeElement!==this.pageInput&&(this.pageInput.value=String(e)),this.prevButton.disabled=e<=1,this.nextButton.disabled=(this.rowOf[e]??0)>=t,this.zoomOutButton.disabled=this._zoomStep(-1)==null,this.zoomInButton.disabled=this._zoomStep(1)==null;let n=Math.round((this.scale||1)*100);this._shownPercent!==n&&(this._shownPercent=n,this.zoomButton.innerHTML=`${n}%${E(`chevron-down`,{size:12})}`,this.zoomButton.setAttribute(`aria-label`,`Zoom, ${n}%`)),A(this.thumbsButton,this.showThumbs?`Hide thumbnails`:`Show thumbnails`),this.thumbsButton.setAttribute(`aria-pressed`,String(this.showThumbs)),this.twoPageButton.setAttribute(`aria-pressed`,String(this.twoPage)),this.printButton.disabled=this.printRun!=null&&!this.printRun.ready,A(this.printButton,this.printButton.disabled?`Preparing to print`:`Print`),A(this.searchButton,this.search.open?`Close search`:`Search the document`),this.searchButton.setAttribute(`aria-expanded`,String(this.search.open)),this._syncSearchStatus()}_buildBody(){let e=this.shell.body;this.thumbRail=document.createElement(`div`),this.thumbRail.className=`wui-file-viewer-thumbs wui-scroll${this.showThumbs?` open`:``}`,this.scroller=document.createElement(`div`),this.scroller.className=`wui-file-viewer-scroll wui-scroll`,this.scroller.tabIndex=0,this.scroller.setAttribute(`role`,`region`),this.scroller.setAttribute(`aria-label`,`Document pages`),this.pagesEl=document.createElement(`div`),this.pagesEl.className=`wui-file-viewer-pages`,this.scroller.append(this.pagesEl),e.replaceChildren(this.thumbRail,this.scroller),this.pageEls=[];for(let e=1;e<=this.pdf.numPages;e++){let t=document.createElement(`div`);t.className=`wui-file-viewer-sheet`,t.dataset.page=String(e),this.pageEls[e]=t}this.showThumbs&&this._buildThumbs(),this.scroller.addEventListener(`scroll`,()=>this._onScroll(),{passive:!0}),this.scroller.addEventListener(`pointerdown`,e=>this._panStart(e)),this.scroller.addEventListener(`pointermove`,e=>this._panMove(e));for(let e of[`pointerup`,`pointercancel`,`lostpointercapture`])this.scroller.addEventListener(e,()=>this._panEnd());this.scroller.addEventListener(`wheel`,e=>{if(!e.ctrlKey&&!e.metaKey)return;e.preventDefault();let t=performance.now();t-(this._lastWheelZoom??0)<120||(this._lastWheelZoom=t,this._stepZoom(e.deltaY<0?1:-1))},{passive:!1}),this._onKeyDown=e=>this._keyDown(e),this.shell.host.addEventListener(`keydown`,this._onKeyDown),this._resizeObserver=new ResizeObserver(()=>{let e=this.scroller.clientWidth,t=this.scroller.clientHeight;(e!==this.area.width||t!==this.area.height)&&(this.area={width:e,height:t},this._layout())}),this._resizeObserver.observe(this.scroller),this.area={width:this.scroller.clientWidth,height:this.scroller.clientHeight}}cols(){return this.twoPage?2:1}_targetScale(){if(typeof this.zoom==`number`)return this.zoom;let e=this.cols(),t=Aa(this.sizes.map(e=>e.width)),n=Aa(this.sizes.map(e=>e.height)),r=(this.area.width-24-(e-1)*Ia)/(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=Fa,r=document.createDocumentFragment();for(let e=1;e<=this.pdf.numPages;e+=t){let i=[];for(let n=e;n<e+t&&n<=this.pdf.numPages;n++)i.push(n);let a=document.createElement(`div`);a.className=`wui-file-viewer-row`;let o=0;for(let e of i){let{width:t,height:n}=$(this.sizes,e-1),r=$(this.pageEls,e);r.style.width=`${Math.floor(t*this.scale)}px`,r.style.height=`${Math.floor(n*this.scale)}px`,r.style.setProperty(`--scale-factor`,String(this.scale*Pa)),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+Ia,r.append(a)}let i=this.scroller.scrollWidth;this.pagesEl.replaceChildren(r),this._restore(e,i),this._scheduleRedraw(),this._update()}_anchor(){if(!this.rows.length)return null;let e=this._rowAt(this.scrollPos.top),t=$(this.rows,e);return{page:$(t.pages,0),within:(this.scrollPos.top-t.top)/Math.max(t.height+Ia,1),left:this.scrollPos.left}}_restore(e,t){let n=this.scroller;if(e){let r=$(this.rows,$(this.rowOf,e.page));n.scrollTop=r.top+e.within*(r.height+Ia),n.scrollLeft=(t?(e.left+n.clientWidth/2)/t:.5)*n.scrollWidth-n.clientWidth/2}this.scrollPos={top:n.scrollTop,left:n.scrollLeft}}_rowAt(e){let t=0,n=this.rows.length-1;for(;t<n;){let r=t+n+1>>1;$(this.rows,r).top<=e+1?t=r:n=r-1}return t}current(){if(this.jumpTarget!=null)return this.jumpTarget;if(!this.rows.length)return 1;let e=this.scrollPos.top,t=e+this.area.height,n=this._rowAt(e),r=-1;for(let i=n;i<this.rows.length&&$(this.rows,i).top<t;i++){let{top:a,height:o}=$(this.rows,i),s=Math.min(a+o,t)-Math.max(a,e);s>r&&(r=s,n=i)}return $($(this.rows,n).pages,0)}_onScroll(){this.scrollPos={top:this.scroller.scrollTop,left:this.scroller.scrollLeft},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)-za),t=Math.min(this.rows.length-1,this._rowAt(this.scrollPos.top+this.area.height)+za),n=new Set;for(let r=e;r<=t;r++)for(let e of $(this.rows,r).pages)n.add(e);for(let e of[...this.pages.keys()])n.has(e)||this._release(e);this.visibleRow=this._rowAt(this.scrollPos.top);for(let e of n)this.pages.has(e)||this._mount(e);this._pump(),this._syncToolbar(),this.showThumbs&&this._followThumb()}_scheduleRedraw(){if(this.scale===this.drawnScale)return;window.clearTimeout(this._redrawTimer),this._timers.delete(this._redrawTimer);let e=this.drawnScale?Ra:0;this._redrawTimer=window.setTimeout(()=>{this._timers.delete(this._redrawTimer),this.drawnScale=this.scale,this._pump()},e),this._timers.add(this._redrawTimer)}_mount(e){let t=$(this.pageEls,e),n={n:e,drawnAt:0,task:null,canvas:null,text:null,textLayer:null,links:null};this.pages.set(e,n);let r=document.createElement(`div`);r.className=`wui-file-viewer-skeleton`,t.replaceChildren(r),this._drawText(n),this._drawLinks(n)}_release(e){let t=this.pages.get(e);t&&(t.released=!0,t.task?.cancel(),t.textLayer?.cancel(),t.canvas&&(t.canvas.width=0,t.canvas.height=0),this.pages.delete(e),this.search.marked.delete(e),$(this.pageEls,e).replaceChildren())}_pump(){if(this._drawing||!this.drawnScale||this.destroyed)return;let e=this.visibleRow??0,t=null,n=1/0;for(let r of this.pages.values()){if(r.drawnAt===this.drawnScale)continue;let i=Math.abs((this.rowOf[r.n]??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*Pa}),i=window.devicePixelRatio||1,a=Math.sqrt(Ua/(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,Qa(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=$(this.pageEls,e.n);e.canvas?(e.canvas.replaceWith(s),e.canvas.width=0,e.canvas.height=0):(c.querySelector(`.wui-file-viewer-skeleton`)?.remove(),c.prepend(s)),e.canvas=s,e.drawnAt=t,this.showThumbs&&!this.thumbsDrawn.has(e.n)&&this._thumbFromCanvas(e.n,s)}async _drawText(e){let t=await this.pdf.getPage(e.n);if(e.released||this.destroyed)return;let n=document.createElement(`div`);n.className=`wui-file-viewer-text`,e.text=n,e.textLayer=new Jr({textContentSource:t.streamTextContent({includeMarkedContent:!0,disableNormalization:!0}),container:n,viewport:t.getViewport({scale:this.scale*Pa})});try{await e.textLayer.render()}catch(e){Qa(e)!==`AbortException`&&this._warn(`text layer failed`,e);return}e.released||this.destroyed||($(this.pageEls,e.n).append(n),this._markPage(e.n),this._revealHit(e.n))}async _drawLinks(e){let t=await this.pdf.getPage(e.n),n=await t.getAnnotations({intent:`display`});if(e.released||this.destroyed)return;let r=n.filter(e=>e.subtype===`Link`&&(e.dest||e.url&&Ja(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`,`Go to page ${e}`),c.addEventListener(`click`,t=>{t.preventDefault(),this.goToPage(e)})}o.append(c)}e.links=o,$(this.pageEls,e.n).append(o)}async _destPage(e){try{let t=(typeof e==`string`?await this.pdf.getDestination(e):e)?.[0];if(t==null)return null;let n=Xa(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($(this.rows,$(this.rowOf,t)).top-Fa,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,Ba),this._timers.add(this._jumpTimer),this.scroller.scrollTo({top:n,behavior:to()})),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?ja.find(e=>Math.round(e*100)>t)??null:[...ja].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`,`Go to page ${e}`);let{width:n,height:r}=$(this.sizes,e-1),i=document.createElement(`span`);i.className=`wui-file-viewer-thumb-frame`,i.style.aspectRatio=`${n} / ${r}`;let a=document.createElement(`span`);a.className=`wui-file-viewer-thumb-no`,a.textContent=String(e),t.append(i,a),t.addEventListener(`click`,()=>this.goToPage(e)),this.thumbRail.append(t),this.thumbEls[e]=t,this._thumbObserver.observe(t)}}async _drawThumb(e){if(this.thumbsDrawn.has(e))return;this.thumbsDrawn.add(e);let t=this.pages.get(e)?.canvas;if(t){this._thumbFromCanvas(e,t);return}let n=await this.pdf.getPage(e);if(this.destroyed)return;let r=window.devicePixelRatio||1,i=n.getViewport({scale:La*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),Qa(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(La*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:to(),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(),_a(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?ya(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=ba(e,a),i=n[t];r.length&&i&&(s.add(t),ka(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=$(this.rows,$(this.rowOf,e.page)),n=this.scrollPos.top;(t.top+t.height<n||t.top>n+this.area.height)&&(this.scroller.scrollTop=t.top-Fa),this._revealHit(e.page)}_revealHit(e){let t=this.search.hits[this.search.current];if(!this._revealPending||!t||t.page!==e)return;let n=$(this.pageEls,e).querySelector(`.wui-file-viewer-hit-current`);if(!n)return;this._revealPending=!1;let r=this.scroller.getBoundingClientRect(),i=n.getBoundingClientRect();(i.top<r.top||i.bottom>r.bottom)&&(this.scroller.scrollTop+=i.top-r.top-this.scroller.clientHeight/2),(i.left<r.left||i.right>r.right)&&(this.scroller.scrollLeft+=i.left-r.left-this.scroller.clientWidth/2)}_syncSearchStatus(){this.searchStatus&&(this.searchStatus.textContent=ga(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||qa(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)<Va&&Math.abs(r)<Va)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:Ha/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/Ha*25.4,height:i.height/Ha*25.4}),this.printRun!==e)throw new DOMException(`Print replaced`,`AbortError`)}let n=document.createElement(`iframe`);n.className=`wui-file-viewer-print-frame`,n.title=`Document for printing`,n.tabIndex=-1,n.setAttribute(`aria-hidden`,`true`),e.frame=n,n.srcdoc=Da(this.shell.name()),n.addEventListener(`load`,async()=>{if(this.printRun===e)try{let{css:r,pages:i}=Oa(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(!Za(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($a)),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){u(`[wui-file-viewer] ${e}:`,t instanceof Error?t.message:t)}},Xa=e=>typeof e==`object`&&!!e,Za=e=>typeof e==`function`,Qa=e=>e instanceof Error?e.name:void 0,$a=e=>e.complete?null:new Promise(t=>{e.addEventListener(`load`,t,{once:!0}),e.addEventListener(`error`,t,{once:!0})}),eo=e=>String(e??``).replace(/&/g,`&amp;`).replace(/</g,`&lt;`).replace(/>/g,`&gt;`),to=()=>window.matchMedia?.(`(prefers-reduced-motion: reduce)`).matches?`auto`:`smooth`})),ro=r({ImageView:()=>so}),io,ao,oo,so,co,lo,uo=n((()=>{f(),j(),ee(),io=[.1,.25,.5,.75,1,1.5,2,3,4],ao=[.25,.5,1,2,4],oo=5,so=class{constructor(e,t){this.shell=e,this.source=t,this.zoom=`fit`,this.rotation=0,this.area={width:0,height:0},this.destroyed=!1}load(){let e=document.createElement(`img`);e.className=`wui-file-viewer-image`,e.alt=this.shell.name(),e.decoding=`async`,e.draggable=!1,e.addEventListener(`load`,()=>{this.destroyed||(this.natural={width:e.naturalWidth||300,height:e.naturalHeight||150},this._build(e),this.shell.loaded({kind:`image`,pages:1}))}),e.addEventListener(`error`,()=>{this.destroyed||this.shell.fail(Error(`The image could not be decoded.`))}),e.src=this.source.src,this.img=e}destroy(){this.destroyed=!0,this._resizeObserver?.disconnect(),this._onKeyDown&&this.shell.host.removeEventListener(`keydown`,this._onKeyDown),this._printFrame?.remove(),this.img?.removeAttribute(`src`)}_build(e){let{center:t,end:n,body:r,host:i}=this.shell;this.zoomOutButton=O(`zoom-out`,`Zoom out`),this.zoomOutButton.addEventListener(`click`,()=>this._stepZoom(-1)),this.zoomButton=document.createElement(`button`),this.zoomButton.type=`button`,this.zoomButton.className=`wui-file-viewer-zoom`,te(this.zoomButton,{label:`Zoom`,items:()=>[...ao.map(e=>({key:String(e),label:`${Math.round(e*100)}%`,checked:this.zoom===e})),{key:`fit-divider`,divider:!0},{key:`fit`,label:`Fit`,checked:this.zoom===`fit`}],onPick:e=>this._setZoom(e===`fit`?`fit`:Number(e))}),this.zoomInButton=O(`zoom-in`,`Zoom in`),this.zoomInButton.addEventListener(`click`,()=>this._stepZoom(1));let a=O(`rotate-ccw`,`Rotate left`);a.addEventListener(`click`,()=>this._rotate(-90));let o=O(`rotate-cw`,`Rotate right`);o.addEventListener(`click`,()=>this._rotate(90));let s=document.createElement(`span`);s.className=`wui-file-viewer-divider wui-file-viewer-print`;let c=O(`printer`,`Print`,{className:`wui-file-viewer-print`});c.addEventListener(`click`,()=>this.print()),s.hidden=c.hidden=!this.shell.print(),t.append(this.zoomOutButton,this.zoomButton,this.zoomInButton),n.prepend(a,o,s,c),this.scroller=document.createElement(`div`),this.scroller.className=`wui-file-viewer-scroll wui-file-viewer-image-scroll wui-scroll`,this.scroller.tabIndex=0,this.scroller.setAttribute(`role`,`region`),this.scroller.setAttribute(`aria-label`,`Image`),this.stage=document.createElement(`div`),this.stage.className=`wui-file-viewer-image-stage`,this.stage.append(e),this.scroller.append(this.stage),r.replaceChildren(this.scroller),this.scroller.addEventListener(`pointerdown`,e=>this._panStart(e)),this.scroller.addEventListener(`pointermove`,e=>this._panMove(e));for(let e of[`pointerup`,`pointercancel`,`lostpointercapture`])this.scroller.addEventListener(e,()=>this._panEnd());this.scroller.addEventListener(`wheel`,e=>{if(!e.ctrlKey&&!e.metaKey)return;e.preventDefault();let t=performance.now();t-(this._lastWheelZoom??0)<120||(this._lastWheelZoom=t,this._stepZoom(e.deltaY<0?1:-1))},{passive:!1}),this._onKeyDown=e=>this._keyDown(e),i.addEventListener(`keydown`,this._onKeyDown),this._resizeObserver=new ResizeObserver(()=>{let e=this.scroller.clientWidth,t=this.scroller.clientHeight;(e!==this.area.width||t!==this.area.height)&&(this.area={width:e,height:t},this._layout())}),this._resizeObserver.observe(this.scroller),this.area={width:this.scroller.clientWidth,height:this.scroller.clientHeight},this._layout()}_turned(){let{width:e,height:t}=this.natural;return this.rotation%180==0?{width:e,height:t}:{width:t,height:e}}scale(){if(typeof this.zoom==`number`)return this.zoom;let{width:e,height:t}=this._turned(),n=Math.min((this.area.width-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.innerHTML=`${n}%${E(`chevron-down`,{size:12})}`,this.zoomButton.setAttribute(`aria-label`,`Zoom, ${n}%`),this.zoomOutButton.disabled=this._zoomStep(-1)==null,this.zoomInButton.disabled=this._zoomStep(1)==null}_zoomStep(e){let t=Math.round(this.scale()*100);return e>0?io.find(e=>Math.round(e*100)>t)??null:[...io].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)<oo&&Math.abs(r)<oo)return;t.active=!0,this.scroller.setPointerCapture(t.id),this.scroller.classList.add(`wui-file-viewer-panning`)}this.scroller.scrollLeft=t.left-n,this.scroller.scrollTop=t.top-r}_panEnd(){let e=this._pan;e?.active&&(this.scroller.hasPointerCapture(e.id)&&this.scroller.releasePointerCapture(e.id),this.scroller.classList.remove(`wui-file-viewer-panning`)),this._pan=null}print(){this._printFrame?.remove();let e=document.createElement(`iframe`);e.className=`wui-file-viewer-print-frame`,e.title=`Image for printing`,e.tabIndex=-1,e.setAttribute(`aria-hidden`,`true`);let t=this.rotation%180!=0,n=new URL(this.source.src,document.baseURI).href;e.srcdoc=`<!doctype html><html><head><title>${lo(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(!co(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
- 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){u(`[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)}},co=e=>typeof e==`function`,lo=e=>String(e??``).replace(/&/g,`&amp;`).replace(/</g,`&lt;`).replace(/>/g,`&gt;`).replace(/"/g,`&quot;`)})),fo=r({MediaView:()=>yo,formatTime:()=>po});function po(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 mo,ho,go,_o,vo,yo,bo=n((()=>{f(),j(),ee(),mo=[.5,.75,1,1.25,1.5,2],ho=5,go=.1,_o=e=>typeof e==`number`&&mo.includes(e),vo=e=>e instanceof Element&&e.closest(`input, textarea, select, button, a, .dropdown-menu`),yo=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=`Captions`,e.srclang=`en`,e.src=n,r.append(e)}let i=this.shell.prefs;typeof i.volume==`number`&&(r.volume=Math.min(Math.max(i.volume,0),1)),r.muted=i.muted===!0,r.addEventListener(`loadedmetadata`,()=>{this.destroyed||(r.playbackRate=_o(i.speed)?i.speed:1,this._build(),this.shell.loaded({kind:e,pages:1}))},{once:!0}),r.addEventListener(`error`,()=>{this.destroyed||this.shell.fail(Error(`The file could not be played.`))}),r.src=t,this.media=r}destroy(){this.destroyed=!0,this._onKeyDown&&this.shell.host.removeEventListener(`keydown`,this._onKeyDown),this.media&&(this.media.pause(),this.media.removeAttribute(`src`),this.media.load())}_build(){let{body:e,host:t}=this.shell,n=this.media,r=this.source.kind,i=document.createElement(`div`);i.className=`wui-file-viewer-player wui-file-viewer-player-${r}`;let a=document.createElement(`div`);if(a.className=`wui-file-viewer-stage`,a.tabIndex=0,a.setAttribute(`role`,`group`),a.setAttribute(`aria-label`,r===`video`?`Video`:`Audio`),r===`audio`){let e=document.createElement(`div`);e.className=`wui-file-viewer-audio-art`,e.innerHTML=E(`music`,{size:40}),a.append(e,n)}else a.append(n),n.addEventListener(`click`,()=>this.togglePlay());let o=document.createElement(`div`);o.className=`wui-file-viewer-controls`,this.playButton=O(`play`,`Play`,{size:18}),this.playButton.addEventListener(`click`,()=>this.togglePlay()),this.timeNow=document.createElement(`span`),this.timeNow.className=`wui-file-viewer-time`,this.seek=document.createElement(`input`),this.seek.type=`range`,this.seek.className=`form-range wui-file-viewer-seek`,this.seek.min=`0`,this.seek.step=`any`,this.seek.setAttribute(`aria-label`,`Seek`),this.seek.addEventListener(`input`,()=>{n.currentTime=Number(this.seek.value)}),this.timeTotal=document.createElement(`span`),this.timeTotal.className=`wui-file-viewer-time`,this.muteButton=O(`volume-high`,`Mute`,{size:18}),this.muteButton.addEventListener(`click`,()=>this._setMuted(!n.muted)),this.volume=document.createElement(`input`),this.volume.type=`range`,this.volume.className=`form-range wui-file-viewer-volume`,this.volume.min=`0`,this.volume.max=`1`,this.volume.step=`0.05`,this.volume.setAttribute(`aria-label`,`Volume`),this.volume.addEventListener(`input`,()=>this._setVolume(Number(this.volume.value))),this.speedButton=document.createElement(`button`),this.speedButton.type=`button`,this.speedButton.className=`wui-file-viewer-zoom wui-file-viewer-speed`,te(this.speedButton,{label:`Playback speed`,items:()=>mo.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=O(`subtitle`,`Show captions`,{size:18}),this.captionsButton.addEventListener(`click`,()=>this._setCaptions(!this._captionsOn())),o.append(this.captionsButton)),i.append(a,o),e.replaceChildren(i);for(let e of[`play`,`pause`,`ended`])n.addEventListener(e,()=>this._syncPlay());n.addEventListener(`timeupdate`,()=>this._syncTime()),n.addEventListener(`durationchange`,()=>this._syncTime()),n.addEventListener(`volumechange`,()=>this._syncVolume()),n.addEventListener(`ratechange`,()=>this._syncSpeed()),this._onKeyDown=e=>this._keyDown(e),t.addEventListener(`keydown`,this._onKeyDown),this._syncPlay(),this._syncTime(),this._syncVolume(),this._syncSpeed(),this._syncCaptions()}seekTo(e){let t=this.media.duration;this.media.currentTime=Math.min(Math.max(e,0),Number.isFinite(t)?t:1/0)}togglePlay(){this.media.paused||this.media.ended?this.media.play().catch(e=>{u(`[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;k(this.playButton,e?`pause`:`play`,18),A(this.playButton,e?`Pause`:`Play`),this.shell.host.classList.toggle(`wui-file-viewer-playing`,e)}_syncTime(){let e=this.media.currentTime,t=this.media.duration;this.timeNow.textContent=po(e),this.timeTotal.textContent=po(t),this.seek.max=String(Number.isFinite(t)?t:0),this.seek.value=String(e),this.seek.setAttribute(`aria-valuetext`,`${po(e)} of ${po(t)}`)}_syncVolume(){let e=this.media.muted||this.media.volume===0;k(this.muteButton,e?`volume-mute`:`volume-high`,18),A(this.muteButton,e?`Unmute`:`Mute`),this.volume.value=String(this.media.muted?0:this.media.volume)}_syncSpeed(){let e=`${this.media.playbackRate}x`;this.speedButton.textContent=e,this.speedButton.setAttribute(`aria-label`,`Playback speed, ${e}`)}_syncCaptions(){if(!this.captionsButton)return;let e=this._captionsOn();this.captionsButton.setAttribute(`aria-pressed`,String(e)),A(this.captionsButton,e?`Hide captions`:`Show captions`)}_keyDown(e){if(e.defaultPrevented||e.altKey||e.ctrlKey||e.metaKey||vo(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-ho);else if(n===`arrowright`)t.currentTime=Math.min(t.duration||0,t.currentTime+ho);else if(n===`arrowup`)this._setVolume(t.volume+go);else if(n===`arrowdown`)this._setVolume(t.volume-go);else if(n===`m`)this._setMuted(!t.muted);else if(n===`c`&&this.captionsButton)this._setCaptions(!this._captionsOn());else return;e.preventDefault()}}}));f(),j();var xo={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`},So={"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`},Co=`wui-file-viewer:load`,wo=`wui-file-viewer:error`,To=`wui-file-viewer:prefs-change`;function Eo(e,t){let n=(String(e??``).split(`;`)[0]??``).trim().toLowerCase();if(n)return So[n]??null;let r=String(t??``).split(/[?#]/)[0]??``;return xo[r.includes(`.`)?(r.split(`.`).pop()??``).toLowerCase():``]??null}function Do(e){let t=(String(e??``).split(/[?#]/)[0]??``).split(`/`).filter(Boolean).pop()??``;try{return decodeURIComponent(t)}catch{return t}}var Oo={pdf:()=>Promise.resolve().then(()=>(no(),Ca)).then(e=>e.PdfView),image:()=>Promise.resolve().then(()=>(uo(),ro)).then(e=>e.ImageView),video:()=>Promise.resolve().then(()=>(bo(),fo)).then(e=>e.MediaView),audio:()=>Promise.resolve().then(()=>(bo(),fo)).then(e=>e.MediaView)},ko=0,Ao=class e extends m{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(),ko+=1,this.uid=`wui-file-viewer-${ko}`,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||Do(this.src)||`Document`}connectedCallback(){if(Object.hasOwn(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=Eo(this.type,this.name||this.src);if(!this.src){this._settle(`No file to show.`);return}if(!n){this._settle(`This file can't be shown here.`,{offerDownload:!0});return}this._status(`Loading...`);let r;try{r=await Oo[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:Mo(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(Co,{bubbles:!0,detail:e})))},fail:e=>{t()&&this._fail(e)}}}_render(){let e=(e,t)=>{let n=document.createElement(e);return n.className=t,n},t=e(`div`,`wui-file-viewer-toolbar`),n=e(`div`,`wui-file-viewer-group wui-file-viewer-start`),r=e(`span`,`wui-file-viewer-name`);r.textContent=this.displayName(),r.title=this.displayName(),n.append(r);let i=e(`div`,`wui-file-viewer-group wui-file-viewer-center`),a=e(`div`,`wui-file-viewer-group wui-file-viewer-end`),o=e(`div`,`wui-file-viewer-group wui-file-viewer-view-end`),s=document.createElement(`a`);s.className=`u-action wui-file-viewer-download`,s.style.setProperty(`--wui-action-size`,`32px`),k(s,`download`),A(s,`Download`);let c=O(`maximize-4`,`Full screen`,{className:`wui-file-viewer-fullscreen`});c.addEventListener(`click`,()=>this.toggleFullscreen()),c.hidden=!document.fullscreenEnabled,this._actionsBox??=e(`div`,`wui-file-viewer-actions`);let l=this._actionsBox;l.append(...this.querySelectorAll(`:scope > [slot="actions"]`)),a.append(o,s,c,l);let u=e(`search`,`wui-file-viewer-search`);u.hidden=!0,t.append(n,i,a,u);let d=e(`div`,`wui-file-viewer-body`);d.setAttribute(`aria-busy`,`true`),this.replaceChildren(t,d),this._parts={toolbar:t,start:n,name:r,center:i,end:a,viewEnd:o,downloadLink:s,fullscreen:c,actionsBox:l,search:u,body:d},this._syncDownload(),this._syncFullscreen()}_syncDownload(){let e=this._parts.downloadLink;e.hidden=!this.download||!this.src,e.href=this.src,e.setAttribute(`download`,this.displayName())}_syncPrint(){for(let e of this._parts.toolbar.querySelectorAll(`.wui-file-viewer-print`))e 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=l(`neutral`,`outline`,`sm`),e.dataset.wui=a,e.href=this.src,e.setAttribute(`download`,this.displayName()),e.textContent=`Download`,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(`Couldn't open this file.`,{offerDownload:!0});let t=typeof e==`object`&&e&&`message`in e?e.message:void 0;this.dispatchEvent(new CustomEvent(wo,{bubbles:!0,detail:{message:t??String(e)}}))}toggleFullscreen(){document.fullscreenElement?document.exitFullscreen():this.requestFullscreen().catch(e=>{u(`[wui-file-viewer] full screen refused:`,e?.message)})}_syncFullscreen(){if(!this._parts)return;let e=document.fullscreenElement===this,t=this._parts.fullscreen;k(t,e?`x`:`maximize-4`),A(t,e?`Exit full screen`:`Full screen`),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 jo(e)?e:{}}catch{return{}}}_savePrefs(e){if(this._prefs={...this._prefs,...e},this.dispatchEvent(new CustomEvent(To,{bubbles:!0,detail:{...this._prefs}})),!this._hostPrefs&&this.viewKey)try{window.localStorage.setItem(`wui-view:${this.viewKey}`,JSON.stringify(this._prefs))}catch{}}};function jo(e){return typeof e==`object`&&!!e}function Mo(e){return e&&new URL(e,document.baseURI).href}var No=typeof document>`u`?null:document.currentScript;return No instanceof HTMLScriptElement&&No.src&&(Ao.defaultAssetBase=new URL(`pdfjs/`,No.src).href),i(`wui-file-viewer`,Ao),e.WuiFileViewer=Ao,e.fileKind=Eo,e.fileNameFromUrl=Do,e.renderPdfFirstPage=(e,t)=>Promise.resolve().then(()=>(no(),Ca)).then(n=>n.renderFirstPage(e,{assetBase:Ao.defaultAssetBase||void 0,...t})),e})({});
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){u(`[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)}},co=e=>typeof e==`function`,lo=e=>String(e??``).replace(/&/g,`&amp;`).replace(/</g,`&lt;`).replace(/>/g,`&gt;`).replace(/"/g,`&quot;`)})),fo=r({MediaView:()=>yo,formatTime:()=>po});function po(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 mo,ho,go,_o,vo,yo,bo=n((()=>{f(),j(),ee(),mo=[.5,.75,1,1.25,1.5,2],ho=5,go=.1,_o=e=>typeof e==`number`&&mo.includes(e),vo=e=>e instanceof Element&&e.closest(`input, textarea, select, button, a, .dropdown-menu`),yo=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=`Captions`,e.srclang=`en`,e.src=n,r.append(e)}let i=this.shell.prefs;typeof i.volume==`number`&&(r.volume=Math.min(Math.max(i.volume,0),1)),r.muted=i.muted===!0,r.addEventListener(`loadedmetadata`,()=>{this.destroyed||(r.playbackRate=_o(i.speed)?i.speed:1,this._build(),this.shell.loaded({kind:e,pages:1}))},{once:!0}),r.addEventListener(`error`,()=>{this.destroyed||this.shell.fail(Error(`The file could not be played.`))}),r.src=t,this.media=r}destroy(){this.destroyed=!0,this._onKeyDown&&this.shell.host.removeEventListener(`keydown`,this._onKeyDown),this.media&&(this.media.pause(),this.media.removeAttribute(`src`),this.media.load())}_build(){let{body:e,host:t}=this.shell,n=this.media,r=this.source.kind,i=document.createElement(`div`);i.className=`wui-file-viewer-player wui-file-viewer-player-${r}`;let a=document.createElement(`div`);if(a.className=`wui-file-viewer-stage`,a.tabIndex=0,a.setAttribute(`role`,`group`),a.setAttribute(`aria-label`,r===`video`?`Video`:`Audio`),r===`audio`){let e=document.createElement(`div`);e.className=`wui-file-viewer-audio-art`,e.innerHTML=E(`music`,{size:40}),a.append(e,n)}else a.append(n),n.addEventListener(`click`,()=>this.togglePlay());let o=document.createElement(`div`);o.className=`wui-file-viewer-controls`,this.playButton=O(`play`,`Play`,{size:18}),this.playButton.addEventListener(`click`,()=>this.togglePlay()),this.timeNow=document.createElement(`span`),this.timeNow.className=`wui-file-viewer-time`,this.seek=document.createElement(`input`),this.seek.type=`range`,this.seek.className=`form-range wui-file-viewer-seek`,this.seek.min=`0`,this.seek.step=`any`,this.seek.setAttribute(`aria-label`,`Seek`),this.seek.addEventListener(`input`,()=>{n.currentTime=Number(this.seek.value)}),this.timeTotal=document.createElement(`span`),this.timeTotal.className=`wui-file-viewer-time`,this.muteButton=O(`volume-high`,`Mute`,{size:18}),this.muteButton.addEventListener(`click`,()=>this._setMuted(!n.muted)),this.volume=document.createElement(`input`),this.volume.type=`range`,this.volume.className=`form-range wui-file-viewer-volume`,this.volume.min=`0`,this.volume.max=`1`,this.volume.step=`0.05`,this.volume.setAttribute(`aria-label`,`Volume`),this.volume.addEventListener(`input`,()=>this._setVolume(Number(this.volume.value))),this.speedButton=document.createElement(`button`),this.speedButton.type=`button`,this.speedButton.className=`wui-file-viewer-zoom wui-file-viewer-speed`,te(this.speedButton,{label:`Playback speed`,items:()=>mo.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=O(`subtitle`,`Show captions`,{size:18}),this.captionsButton.addEventListener(`click`,()=>this._setCaptions(!this._captionsOn())),o.append(this.captionsButton)),i.append(a,o),e.replaceChildren(i);for(let e of[`play`,`pause`,`ended`])n.addEventListener(e,()=>this._syncPlay());n.addEventListener(`timeupdate`,()=>this._syncTime()),n.addEventListener(`durationchange`,()=>this._syncTime()),n.addEventListener(`volumechange`,()=>this._syncVolume()),n.addEventListener(`ratechange`,()=>this._syncSpeed()),this._onKeyDown=e=>this._keyDown(e),t.addEventListener(`keydown`,this._onKeyDown),this._syncPlay(),this._syncTime(),this._syncVolume(),this._syncSpeed(),this._syncCaptions()}seekTo(e){let t=this.media.duration;this.media.currentTime=Math.min(Math.max(e,0),Number.isFinite(t)?t:1/0)}togglePlay(){this.media.paused||this.media.ended?this.media.play().catch(e=>{u(`[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;k(this.playButton,e?`pause`:`play`,18),A(this.playButton,e?`Pause`:`Play`),this.shell.host.classList.toggle(`wui-file-viewer-playing`,e)}_syncTime(){let e=this.media.currentTime,t=this.media.duration;this.timeNow.textContent=po(e),this.timeTotal.textContent=po(t),this.seek.max=String(Number.isFinite(t)?t:0),this.seek.value=String(e),this.seek.setAttribute(`aria-valuetext`,`${po(e)} of ${po(t)}`)}_syncVolume(){let e=this.media.muted||this.media.volume===0;k(this.muteButton,e?`volume-mute`:`volume-high`,18),A(this.muteButton,e?`Unmute`:`Mute`),this.volume.value=String(this.media.muted?0:this.media.volume)}_syncSpeed(){let e=`${this.media.playbackRate}x`;this.speedButton.textContent=e,this.speedButton.setAttribute(`aria-label`,`Playback speed, ${e}`)}_syncCaptions(){if(!this.captionsButton)return;let e=this._captionsOn();this.captionsButton.setAttribute(`aria-pressed`,String(e)),A(this.captionsButton,e?`Hide captions`:`Show captions`)}_keyDown(e){if(e.defaultPrevented||e.altKey||e.ctrlKey||e.metaKey||vo(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-ho);else if(n===`arrowright`)t.currentTime=Math.min(t.duration||0,t.currentTime+ho);else if(n===`arrowup`)this._setVolume(t.volume+go);else if(n===`arrowdown`)this._setVolume(t.volume-go);else if(n===`m`)this._setMuted(!t.muted);else if(n===`c`&&this.captionsButton)this._setCaptions(!this._captionsOn());else return;e.preventDefault()}}}));f(),j();var xo={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`},So={"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`},Co=`wui-file-viewer:load`,wo=`wui-file-viewer:error`,To=`wui-file-viewer:prefs-change`;function Eo(e,t){let n=(String(e??``).split(`;`)[0]??``).trim().toLowerCase();if(n)return So[n]??null;let r=String(t??``).split(/[?#]/)[0]??``;return xo[r.includes(`.`)?(r.split(`.`).pop()??``).toLowerCase():``]??null}function Do(e){let t=(String(e??``).split(/[?#]/)[0]??``).split(`/`).filter(Boolean).pop()??``;try{return decodeURIComponent(t)}catch{return t}}var Oo={pdf:()=>Promise.resolve().then(()=>(no(),Ca)).then(e=>e.PdfView),image:()=>Promise.resolve().then(()=>(uo(),ro)).then(e=>e.ImageView),video:()=>Promise.resolve().then(()=>(bo(),fo)).then(e=>e.MediaView),audio:()=>Promise.resolve().then(()=>(bo(),fo)).then(e=>e.MediaView)},ko=0,Ao=class e extends m{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(),ko+=1,this.uid=`wui-file-viewer-${ko}`,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||Do(this.src)||`Document`}connectedCallback(){if(Object.hasOwn(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=Eo(this.type,this.name||this.src);if(!this.src){this._settle(`No file to show.`);return}if(!n){this._settle(`This file can't be shown here.`,{offerDownload:!0});return}this._status(`Loading...`);let r;try{r=await Oo[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:Mo(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(Co,{bubbles:!0,detail:e})))},fail:e=>{t()&&this._fail(e)}}}_render(){let e=(e,t)=>{let n=document.createElement(e);return n.className=t,n},t=e(`div`,`wui-file-viewer-toolbar`),n=e(`div`,`wui-file-viewer-group wui-file-viewer-start`),r=e(`span`,`wui-file-viewer-name`);r.textContent=this.displayName(),r.title=this.displayName(),n.append(r);let i=e(`div`,`wui-file-viewer-group wui-file-viewer-center`),a=e(`div`,`wui-file-viewer-group wui-file-viewer-end`),o=e(`div`,`wui-file-viewer-group wui-file-viewer-view-end`),s=document.createElement(`a`);s.className=`u-action wui-file-viewer-download`,s.style.setProperty(`--wui-action-size`,`32px`),k(s,`download`),A(s,`Download`);let c=O(`maximize-4`,`Full screen`,{className:`wui-file-viewer-fullscreen`});c.addEventListener(`click`,()=>this.toggleFullscreen()),c.hidden=!document.fullscreenEnabled,this._actionsBox??=e(`div`,`wui-file-viewer-actions`);let l=this._actionsBox;l.append(...this.querySelectorAll(`:scope > [slot="actions"]`)),a.append(o,s,c,l);let u=e(`search`,`wui-file-viewer-search`);u.hidden=!0,t.append(n,i,a,u);let d=e(`div`,`wui-file-viewer-body`);d.setAttribute(`aria-busy`,`true`),this.replaceChildren(t,d),this._parts={toolbar:t,start:n,name:r,center:i,end:a,viewEnd:o,downloadLink:s,fullscreen:c,actionsBox:l,search:u,body:d},this._syncDownload(),this._syncFullscreen()}_syncDownload(){let e=this._parts.downloadLink;e.hidden=!this.download||!this.src,e.href=this.src,e.setAttribute(`download`,this.displayName())}_syncPrint(){for(let e of this._parts.toolbar.querySelectorAll(`.wui-file-viewer-print`))e 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=l(`neutral`,`outline`,`sm`),e.dataset.wui=a,e.href=this.src,e.setAttribute(`download`,this.displayName()),e.textContent=`Download`,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(`Couldn't open this file.`,{offerDownload:!0});let t=typeof e==`object`&&e&&`message`in e?e.message:void 0;this.dispatchEvent(new CustomEvent(wo,{bubbles:!0,detail:{message:t??String(e)}}))}toggleFullscreen(){document.fullscreenElement?document.exitFullscreen():this.requestFullscreen().catch(e=>{u(`[wui-file-viewer] full screen refused:`,e?.message)})}_syncFullscreen(){if(!this._parts)return;let e=document.fullscreenElement===this,t=this._parts.fullscreen;k(t,e?`x`:`maximize-4`),A(t,e?`Exit full screen`:`Full screen`),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 jo(e)?e:{}}catch{return{}}}_savePrefs(e){if(this._prefs={...this._prefs,...e},this.dispatchEvent(new CustomEvent(To,{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 jo(e){return typeof e==`object`&&!!e}function Mo(e){return e&&new URL(e,document.baseURI).href}var No=typeof document>`u`?null:document.currentScript;return No instanceof HTMLScriptElement&&No.src&&(Ao.defaultAssetBase=new URL(`pdfjs/`,No.src).href),i(`wui-file-viewer`,Ao),e.WuiFileViewer=Ao,e.fileKind=Eo,e.fileNameFromUrl=Do,e.renderPdfFirstPage=(e,t)=>Promise.resolve().then(()=>(no(),Ca)).then(n=>n.renderFirstPage(e,{assetBase:Ao.defaultAssetBase||void 0,...t})),e})({});
@@ -1 +1 @@
1
- import{i as e,r as t,s as n,t as r}from"./fileViewerUi-ResPjO1o.js";function i(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 a=`AppButton`,o=/* @__PURE__ */ new Set([`primary`,`success`,`warning`,`danger`,`info`,`neutral`]),s={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 c(e){return Object.hasOwn(s,e)}function l(e=`primary`,t=`solid`,n=`md`){if(!o.has(e))throw RangeError(`buttonClass: unknown tone "${e}"`);if(!c(t))throw RangeError(`buttonClass: unknown variant "${t}"`);let r=s[t](e);return n===`md`?`btn ${r}`:`btn ${r} btn-${n}`}var u=`@webority/ui-elements needs a browser DOM; import its types or helpers entry on the server`;if(typeof HTMLElement>`u`)throw Error(u);var d=HTMLElement,f={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`},p={"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`},m=`wui-file-viewer:load`,h=`wui-file-viewer:error`,g=`wui-file-viewer:prefs-change`;function _(e,t){let n=(String(e??``).split(`;`)[0]??``).trim().toLowerCase();if(n)return p[n]??null;let r=String(t??``).split(/[?#]/)[0]??``;return f[r.includes(`.`)?(r.split(`.`).pop()??``).toLowerCase():``]??null}function v(e){let t=(String(e??``).split(/[?#]/)[0]??``).split(`/`).filter(Boolean).pop()??``;try{return decodeURIComponent(t)}catch{return t}}var y={pdf:()=>import(`./fileViewerPdf-CdaDuaRJ.js`).then(e=>e.PdfView),image:()=>import(`./fileViewerImage-Bt1jeArm.js`).then(e=>e.ImageView),video:()=>import(`./fileViewerMedia-Bp1uHJvC.js`).then(e=>e.MediaView),audio:()=>import(`./fileViewerMedia-Bp1uHJvC.js`).then(e=>e.MediaView)},b=0,x=class i extends d{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(),b+=1,this.uid=`wui-file-viewer-${b}`,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||v(this.src)||`Document`}connectedCallback(){if(Object.hasOwn(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=_(this.type,this.name||this.src);if(!this.src){this._settle(`No file to show.`);return}if(!t){this._settle(`This file can't be shown here.`,{offerDownload:!0});return}this._status(`Loading...`);let n;try{n=await y[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:C(this.assetBase||i.defaultAssetBase)}),this._view.load())}_shell(e){let t=()=>e===this._loadId,n=this._parts;return{host:this,start:n.start,center:n.center,end:n.viewEnd,search:n.search,body:n.body,prefs:{...this._prefs},name:()=>this.displayName(),print:()=>this.print,savePrefs:e=>{t()&&this._savePrefs(e)},loaded:e=>{t()&&(n.body.removeAttribute(`aria-busy`),this.dispatchEvent(new CustomEvent(m,{bubbles:!0,detail:e})))},fail:e=>{t()&&this._fail(e)}}}_render(){let n=(e,t)=>{let n=document.createElement(e);return n.className=t,n},i=n(`div`,`wui-file-viewer-toolbar`),a=n(`div`,`wui-file-viewer-group wui-file-viewer-start`),o=n(`span`,`wui-file-viewer-name`);o.textContent=this.displayName(),o.title=this.displayName(),a.append(o);let s=n(`div`,`wui-file-viewer-group wui-file-viewer-center`),c=n(`div`,`wui-file-viewer-group wui-file-viewer-end`),l=n(`div`,`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`),t(u,`download`),e(u,`Download`);let d=r(`maximize-4`,`Full screen`,{className:`wui-file-viewer-fullscreen`});d.addEventListener(`click`,()=>this.toggleFullscreen()),d.hidden=!document.fullscreenEnabled,this._actionsBox??=n(`div`,`wui-file-viewer-actions`);let f=this._actionsBox;f.append(...this.querySelectorAll(`:scope > [slot="actions"]`)),c.append(l,u,d,f);let p=n(`search`,`wui-file-viewer-search`);p.hidden=!0,i.append(a,s,c,p);let m=n(`div`,`wui-file-viewer-body`);m.setAttribute(`aria-busy`,`true`),this.replaceChildren(i,m),this._parts={toolbar:i,start:a,name:o,center:s,end:c,viewEnd:l,downloadLink:u,fullscreen:d,actionsBox:f,search:p,body:m},this._syncDownload(),this._syncFullscreen()}_syncDownload(){let e=this._parts.downloadLink;e.hidden=!this.download||!this.src,e.href=this.src,e.setAttribute(`download`,this.displayName())}_syncPrint(){for(let e of this._parts.toolbar.querySelectorAll(`.wui-file-viewer-print`))e 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=l(`neutral`,`outline`,`sm`),e.dataset.wui=a,e.href=this.src,e.setAttribute(`download`,this.displayName()),e.textContent=`Download`,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(`Couldn't open this file.`,{offerDownload:!0});let t=typeof e==`object`&&e&&`message`in e?e.message:void 0;this.dispatchEvent(new CustomEvent(h,{bubbles:!0,detail:{message:t??String(e)}}))}toggleFullscreen(){document.fullscreenElement?document.exitFullscreen():this.requestFullscreen().catch(e=>{n(`[wui-file-viewer] full screen refused:`,e?.message)})}_syncFullscreen(){if(!this._parts)return;let n=document.fullscreenElement===this,r=this._parts.fullscreen;t(r,n?`x`:`maximize-4`),e(r,n?`Exit full screen`:`Full screen`),this._parts.actionsBox.hidden=n}_readPrefs(){if(this._hostPrefs||!this.viewKey)return{...this._prefs};try{let e=JSON.parse(window.localStorage.getItem(`wui-view:${this.viewKey}`)??`{}`);return S(e)?e:{}}catch{return{}}}_savePrefs(e){if(this._prefs={...this._prefs,...e},this.dispatchEvent(new CustomEvent(g,{bubbles:!0,detail:{...this._prefs}})),!this._hostPrefs&&this.viewKey)try{window.localStorage.setItem(`wui-view:${this.viewKey}`,JSON.stringify(this._prefs))}catch{}}};function S(e){return typeof e==`object`&&!!e}function C(e){return e&&new URL(e,document.baseURI).href}var w=typeof document>`u`?null:document.currentScript;w instanceof HTMLScriptElement&&w.src&&(x.defaultAssetBase=new URL(`pdfjs/`,w.src).href),i(`wui-file-viewer`,x);var T=(e,t)=>import(`./fileViewerPdf-CdaDuaRJ.js`).then(n=>n.renderFirstPage(e,{assetBase:x.defaultAssetBase||void 0,...t}));export{x as WuiFileViewer,_ as fileKind,v as fileNameFromUrl,T as renderPdfFirstPage};
1
+ import{i as e,r as t,s as n,t as r}from"./fileViewerUi-ResPjO1o.js";function i(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 a=`AppButton`,o=/* @__PURE__ */ new Set([`primary`,`success`,`warning`,`danger`,`info`,`neutral`]),s={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 c(e){return Object.hasOwn(s,e)}function l(e=`primary`,t=`solid`,n=`md`){if(!o.has(e))throw RangeError(`buttonClass: unknown tone "${e}"`);if(!c(t))throw RangeError(`buttonClass: unknown variant "${t}"`);let r=s[t](e);return n===`md`?`btn ${r}`:`btn ${r} btn-${n}`}var u=`@webority/ui-elements needs a browser DOM; import its types or helpers entry on the server`;if(typeof HTMLElement>`u`)throw Error(u);var d=HTMLElement,f={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`},p={"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`},m=`wui-file-viewer:load`,h=`wui-file-viewer:error`,g=`wui-file-viewer:prefs-change`;function _(e,t){let n=(String(e??``).split(`;`)[0]??``).trim().toLowerCase();if(n)return p[n]??null;let r=String(t??``).split(/[?#]/)[0]??``;return f[r.includes(`.`)?(r.split(`.`).pop()??``).toLowerCase():``]??null}function v(e){let t=(String(e??``).split(/[?#]/)[0]??``).split(`/`).filter(Boolean).pop()??``;try{return decodeURIComponent(t)}catch{return t}}var y={pdf:()=>import(`./fileViewerPdf-CdaDuaRJ.js`).then(e=>e.PdfView),image:()=>import(`./fileViewerImage-Bt1jeArm.js`).then(e=>e.ImageView),video:()=>import(`./fileViewerMedia-Bp1uHJvC.js`).then(e=>e.MediaView),audio:()=>import(`./fileViewerMedia-Bp1uHJvC.js`).then(e=>e.MediaView)},b=0,x=class i extends d{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(),b+=1,this.uid=`wui-file-viewer-${b}`,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||v(this.src)||`Document`}connectedCallback(){if(Object.hasOwn(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=_(this.type,this.name||this.src);if(!this.src){this._settle(`No file to show.`);return}if(!t){this._settle(`This file can't be shown here.`,{offerDownload:!0});return}this._status(`Loading...`);let n;try{n=await y[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:C(this.assetBase||i.defaultAssetBase)}),this._view.load())}_shell(e){let t=()=>e===this._loadId,n=this._parts;return{host:this,start:n.start,center:n.center,end:n.viewEnd,search:n.search,body:n.body,prefs:{...this._prefs},name:()=>this.displayName(),print:()=>this.print,savePrefs:e=>{t()&&this._savePrefs(e)},loaded:e=>{t()&&(n.body.removeAttribute(`aria-busy`),this.dispatchEvent(new CustomEvent(m,{bubbles:!0,detail:e})))},fail:e=>{t()&&this._fail(e)}}}_render(){let n=(e,t)=>{let n=document.createElement(e);return n.className=t,n},i=n(`div`,`wui-file-viewer-toolbar`),a=n(`div`,`wui-file-viewer-group wui-file-viewer-start`),o=n(`span`,`wui-file-viewer-name`);o.textContent=this.displayName(),o.title=this.displayName(),a.append(o);let s=n(`div`,`wui-file-viewer-group wui-file-viewer-center`),c=n(`div`,`wui-file-viewer-group wui-file-viewer-end`),l=n(`div`,`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`),t(u,`download`),e(u,`Download`);let d=r(`maximize-4`,`Full screen`,{className:`wui-file-viewer-fullscreen`});d.addEventListener(`click`,()=>this.toggleFullscreen()),d.hidden=!document.fullscreenEnabled,this._actionsBox??=n(`div`,`wui-file-viewer-actions`);let f=this._actionsBox;f.append(...this.querySelectorAll(`:scope > [slot="actions"]`)),c.append(l,u,d,f);let p=n(`search`,`wui-file-viewer-search`);p.hidden=!0,i.append(a,s,c,p);let m=n(`div`,`wui-file-viewer-body`);m.setAttribute(`aria-busy`,`true`),this.replaceChildren(i,m),this._parts={toolbar:i,start:a,name:o,center:s,end:c,viewEnd:l,downloadLink:u,fullscreen:d,actionsBox:f,search:p,body:m},this._syncDownload(),this._syncFullscreen()}_syncDownload(){let e=this._parts.downloadLink;e.hidden=!this.download||!this.src,e.href=this.src,e.setAttribute(`download`,this.displayName())}_syncPrint(){for(let e of this._parts.toolbar.querySelectorAll(`.wui-file-viewer-print`))e 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=l(`neutral`,`outline`,`sm`),e.dataset.wui=a,e.href=this.src,e.setAttribute(`download`,this.displayName()),e.textContent=`Download`,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(`Couldn't open this file.`,{offerDownload:!0});let t=typeof e==`object`&&e&&`message`in e?e.message:void 0;this.dispatchEvent(new CustomEvent(h,{bubbles:!0,detail:{message:t??String(e)}}))}toggleFullscreen(){document.fullscreenElement?document.exitFullscreen():this.requestFullscreen().catch(e=>{n(`[wui-file-viewer] full screen refused:`,e?.message)})}_syncFullscreen(){if(!this._parts)return;let n=document.fullscreenElement===this,r=this._parts.fullscreen;t(r,n?`x`:`maximize-4`),e(r,n?`Exit full screen`:`Full screen`),this._parts.actionsBox.hidden=n}_readPrefs(){if(this._hostPrefs||!this.viewKey)return{...this._prefs};try{let e=JSON.parse(window.localStorage.getItem(`wui-view:${this.viewKey}`)??`{}`);return S(e)?e:{}}catch{return{}}}_savePrefs(e){if(this._prefs={...this._prefs,...e},this.dispatchEvent(new CustomEvent(g,{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 S(e){return typeof e==`object`&&!!e}function C(e){return e&&new URL(e,document.baseURI).href}var w=typeof document>`u`?null:document.currentScript;w instanceof HTMLScriptElement&&w.src&&(x.defaultAssetBase=new URL(`pdfjs/`,w.src).href),i(`wui-file-viewer`,x);var T=(e,t)=>import(`./fileViewerPdf-CdaDuaRJ.js`).then(n=>n.renderFirstPage(e,{assetBase:x.defaultAssetBase||void 0,...t}));export{x as WuiFileViewer,_ as fileKind,v as fileNameFromUrl,T as renderPdfFirstPage};
@@ -1 +1 @@
1
- (function(){function e(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}>.`)}function t(e,...t){console.warn(e,...t)}function n(e,...t){console.error(e,...t)}var r=`@webority/ui-elements needs a browser DOM; import its types or helpers entry on the server`;if(typeof HTMLElement>`u`)throw Error(r);var i=HTMLElement,a={"--color-primary":`#4F46E5`,"--color-primary-hover":`#4338CA`,"--color-primary-soft":`#E0E7FF`,"--color-primary-text":`#4F46E5`,"--color-on-primary":`#FFFFFF`,"--color-text":`#071437`,"--color-text-muted":`#4B5675`,"--color-border":`#EBEDF3`,"--color-border-strong":`#C4CADA`,"--color-surface":`#FFFFFF`,"--wui-radius-sm":`8px`,"--wui-radius-lg":`14px`,"--wui-shadow-modal":`0px 24px 60px -16px rgba(7, 20, 55, 0.28)`,"--wui-z-modal":`1505`},o=e=>`var(${e}, ${a[e]})`,s=` :host { all: initial; display: contents; font-family: inherit; font-size: 16px; line-height: 1.5; color: ${o(`--color-text`)}; } *, *::before, *::after { box-sizing: border-box; } [hidden] { display: none !important; } dialog { z-index: ${o(`--wui-z-modal`)}; width: 100%; max-width: none; height: 100%; max-height: none; margin: 0; padding: 0; border: 0; background: transparent; color: inherit; } dialog[open] { display: flex; align-items: center; justify-content: center; } :host([preview]) dialog { position: static; height: auto; } dialog::backdrop { background: rgba(0, 0, 0, 0.7); backdrop-filter: blur(5px); } dialog[open]::backdrop { animation: wlp-fade 0.3s ease-out; } .wlp-card { position: relative; width: 90%; max-width: 440px; max-height: calc(100dvh - 32px); overflow-y: auto; padding: 24px; background: ${o(`--color-surface`)}; color: ${o(`--color-text`)}; border: 1px solid ${o(`--color-border`)}; border-radius: ${o(`--wui-radius-lg`)}; box-shadow: ${o(`--wui-shadow-modal`)}; text-align: start; } dialog[open] .wlp-card { animation: wlp-card-in 0.2s ease-out; } .wlp-close { position: absolute; top: 12px; inset-inline-end: 12px; width: 32px; height: 32px; padding: 0; border: 0; border-radius: 50%; background: transparent; color: ${o(`--color-text-muted`)}; font: inherit; font-size: 22px; line-height: 1; cursor: pointer; } .wlp-close:focus-visible, .wlp-button:focus-visible, .wlp-input:focus-visible, .wlp-secondary:focus-visible { outline: 2px solid ${o(`--color-primary`)}; outline-offset: 2px; } .wlp-heading { margin: 0 32px 8px 0; font-size: 20px; font-weight: 600; line-height: 1.3; color: ${o(`--color-text`)}; } .wlp-description { margin: 0 0 16px; font-size: 14px; color: ${o(`--color-text-muted`)}; } .wlp-form { display: grid; gap: 14px; margin: 0; } .wlp-field { display: grid; gap: 4px; } .wlp-label { font-size: 14px; font-weight: 500; color: ${o(`--color-text`)}; } .wlp-req { margin-inline-start: 2px; color: ${o(`--color-primary`)}; } .wlp-input { width: 100%; padding: 9px 12px; border: 1px solid ${o(`--color-border`)}; border-radius: 8px; background: ${o(`--color-surface`)}; color: ${o(`--color-text`)}; font: inherit; font-size: 15px; } textarea.wlp-input { resize: vertical; min-height: 96px; } .wlp-input[aria-invalid="true"] { border-color: var(--color-danger, #B42318); } .wlp-error { margin: 0; font-size: 13px; color: var(--color-danger, #B42318); } .wlp-form-error { margin: 0; font-size: 14px; color: var(--color-danger, #B42318); } /* The consent field uses the theme's checkbox markup; its look is restated here because the theme's rules cannot reach the shadow root. */ .form-check { display: grid; grid-template-columns: auto 1fr; align-items: center; column-gap: 12px; font-size: 14px; line-height: 1.4; color: ${o(`--color-text`)}; } .form-check-input { flex: none; width: 20px; height: 20px; margin: 0; appearance: none; -webkit-appearance: none; border: 1.6px solid ${o(`--color-border-strong`)}; border-radius: ${o(`--wui-radius-sm`)}; corner-shape: squircle; background-color: ${o(`--color-surface`)}; background-repeat: no-repeat; background-position: center; background-size: 15px 15px; cursor: pointer; transition: border-color 0.15s ease, background-color 0.15s ease, box-shadow 0.15s ease; } .form-check-input:hover:not(:checked) { border-color: ${o(`--color-primary`)}; box-shadow: 0 0 0 2px ${o(`--color-primary-soft`)}; } .form-check-input:checked { border-color: ${o(`--color-primary`)}; background-color: ${o(`--color-primary`)}; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='3.4' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M5 12.5l4.5 4.5L19 7'/%3E%3C/svg%3E"); } .form-check-input:focus-visible { outline: 2px solid ${o(`--color-primary`)}; outline-offset: 2px; box-shadow: none; } .form-check-input[aria-invalid="true"] { border-color: var(--color-danger, #B42318); } .form-check-label { min-width: 0; cursor: pointer; } .wlp-field-consent .wlp-error { margin-inline-start: 32px; } .wlp-consent-link { grid-column: 2; justify-self: start; color: ${o(`--color-primary-text`)}; font-weight: 500; text-decoration: underline; text-underline-offset: 3px; } .wlp-consent-link:focus-visible { outline: 2px solid ${o(`--color-primary`)}; outline-offset: 2px; border-radius: 4px; } .wlp-visually-hidden { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; } .wlp-honeypot { position: absolute !important; left: -9999px !important; width: 1px; height: 1px; opacity: 0; pointer-events: none; } .wlp-actions { display: flex; justify-content: flex-end; align-items: center; gap: 8px; margin-top: 4px; } .wlp-button { display: inline-flex; align-items: center; justify-content: center; min-height: 36px; padding: 8px 16px; border: 1px solid ${o(`--color-primary`)}; border-radius: 8px; background: ${o(`--color-primary`)}; color: ${o(`--color-on-primary`)}; font: inherit; font-size: 15px; font-weight: 500; cursor: pointer; } .wlp-button:hover { background: ${o(`--color-primary-hover`)}; border-color: ${o(`--color-primary-hover`)}; } .wlp-button:disabled { opacity: 0.6; cursor: default; } .wlp-notice { margin: 4px 0 0; font-size: 12px; line-height: 1.4; color: ${o(`--color-text-muted`)}; } .wlp-notice a { color: inherit; text-decoration: underline; } .wlp-secondary-row { display: flex; align-items: center; gap: 10px; margin-top: 14px; font-size: 14px; color: ${o(`--color-text-muted`)}; } .wlp-secondary-row::before, .wlp-secondary-row::after { content: ""; flex: 1; height: 1px; background: ${o(`--color-border`)}; } .wlp-secondary { display: block; margin-top: 10px; text-align: center; color: ${o(`--color-primary`)}; font-weight: 500; } .wlp-success-title { margin: 0 32px 8px 0; font-size: 20px; font-weight: 600; color: ${o(`--color-text`)}; } .wlp-success-text { margin: 0 0 16px; color: ${o(`--color-text-muted`)}; } .wlp-success-view .wlp-button { width: 100%; } @keyframes wlp-fade { from { opacity: 0; } to { opacity: 1; } } @keyframes wlp-card-in { from { opacity: 0; transform: scale(0.96); } to { opacity: 1; transform: scale(1); } } @media (max-width: 575.98px) { .wlp-card { width: calc(100% - 32px); max-width: none; padding: 20px 16px; } .wlp-input { font-size: 16px; } .wlp-button, .wlp-close { min-height: 44px; } .wlp-close { min-width: 44px; } } @media (prefers-reduced-motion: reduce) { dialog[open]::backdrop, dialog[open] .wlp-card { animation: none; } } `,c=[`name`,`email`,`phone`,`company`,`message`,`consent`],l=[`name`,`email`],u={name:`Name`,email:`Email`,phone:`Phone number`,company:`Company`,message:`Message`,consent:`I agree to be contacted about my enquiry`,consentLink:`Privacy policy`},d={name:100,email:320,phone:40,company:150,message:1e3},f={name:`name`,email:`email`,phone:`tel`,company:`organization`},p=`input:not([type=hidden]), textarea, select, button, a[href]`,m=[`exit`,`delay`,`scroll`,`pages`],h=/^[^\s@]+@[^\s@]+\.[^\s@]+$/,g=864e5,_=`comment_subject`,v=`__RequestVerificationToken`,y=`__FormStamp`,b=`__CaptchaToken`,x=`Something went wrong. Please try again or contact us directly.`,S=`Tick the box to continue`,C=`action.public-form.heading.description.fields.required.field-prefix.field-names.labels.max-lengths.submit-label.success-title.success-text.error-text.close-label.secondary-label.secondary-href.secondary-divider.consent-href.triggers.delay-seconds.scroll-percent.pages-viewed.storage-key.dismiss-days.submitted-days.success-close-seconds.preview`.split(`.`),w=new Set;function T(e,n){w.has(e)||(w.add(e),t(n))}var E=0;function D(e){return(e??``).split(/\s+/).map(e=>e.trim()).filter(Boolean)}function O(e){let t={};for(let n of(e??``).split(`;`)){let e=n.indexOf(`=`);if(e<0)continue;let r=n.slice(0,e).trim();r&&(t[r]=n.slice(e+1).trim())}return t}function k(e){return String(e??``).replace(/&/g,`&amp;`).replace(/</g,`&lt;`).replace(/>/g,`&gt;`).replace(/"/g,`&quot;`)}var A=null;function j(e){A||(A=new CSSStyleSheet,A.replaceSync(s)),e.adoptedStyleSheets=[A]}function M(e,t){return e instanceof Error&&e.message?e.message:t}function N(e){return c.some(t=>t===e)}function P(e){return m.some(t=>t===e)}function F(e,t,n){if(e instanceof t)return e;throw Error(`${n} missing`)}e(`wui-lead-popup`,class extends i{_uid;_rendered;_open;_opened;_posting;_stale;_armed;_session;_returnTo;_prevOverflow;_delayTimer;_closeTimer;_modal;_onMouseLeave;_onVisibility;_onScroll;static get observedAttributes(){return C}constructor(){super(),E+=1,this._uid=`wlp-${E}`,this._rendered=!1,this._open=!1,this._opened=!1,this._posting=!1,this._stale=!1,this._armed=!1,this._session=null,this._returnTo=null,this._prevOverflow=``,this._delayTimer=null,this._closeTimer=null,this._onMouseLeave=e=>{!this._fine()||e.clientY>0||!this._engaged()||this.open(`exit`)},this._onVisibility=()=>{document.visibilityState===`hidden`&&!this._fine()&&this._engaged()&&this.open(`exit`)},this._onScroll=()=>this._trackScroll()}get isOpen(){return this._open}set isOpen(e){e?this.open(`manual`):this.close(`dismiss`)}connectedCallback(){this._rendered||this._render(),this._arm(),this.preview&&!this._open&&this.open(`manual`)}disconnectedCallback(){this._disarm(),this._open&&this._release()}attributeChangedCallback(){this._rendered&&(this._open?this._stale=!0:this._render())}open(e=`manual`){if(!this._open&&!(e!==`manual`&&(this._opened||this._blocked()||document.querySelector(`dialog[open], .modal.show`)))){if(this._rendered||this._render(),this._opened=!0,this._open=!0,clearTimeout(this._delayTimer??void 0),this._showForm(),this._modal=!this.preview,this._modal){let e=document.activeElement;this._returnTo=e instanceof HTMLElement||e instanceof SVGElement?e:null,this._prevOverflow=document.documentElement.style.overflow,document.documentElement.style.overflow=`hidden`;let t=this._dialog();t.showModal();let n=t.querySelector(`[data-wlp-field] [data-wlp-input]`);n instanceof HTMLElement&&n.focus()}else this._dialog().setAttribute(`open`,``);this._remember(`shown`),this._emit(`wui-lead-popup-shown`,{trigger:e})}}close(e=`dismiss`){if(!this._open)return;clearTimeout(this._closeTimer??void 0),this._release();let t=this._returnTo;this._returnTo=null,t?.isConnected&&typeof t.focus==`function`&&t.focus(),this._stale&&this._render(),this._emit(`wui-lead-popup-closed`,{reason:e})}_release(){this._open=!1,this._dialog().close(),this._modal&&(document.documentElement.style.overflow=this._prevOverflow)}_root(){return this.shadowRoot??this.attachShadow({mode:`open`})}_dialog(){return F(this._root().querySelector(`dialog`),HTMLDialogElement,`dialog`)}_emit(e,t){this.dispatchEvent(new CustomEvent(e,{bubbles:!0,composed:!0,detail:t}))}_text(e,t=``){return this.getAttribute(e)||t}_number(e,t){let n=this.getAttribute(e);if(n===null||n.trim()===``)return t;let r=Number(n);return Number.isFinite(r)&&r>=0?r:t}get preview(){return this.hasAttribute(`preview`)}set preview(e){this.toggleAttribute(`preview`,e===!0||e===``||e===`true`)}_fieldKeys(){let e=D(this.getAttribute(`fields`)).filter(e=>N(e)?!0:(T(`field:${e}`,`[@webority/ui-elements] <wui-lead-popup> has no field "${e}". It is ignored.`),!1));return e.length?e:l}_requiredKeys(){let e=this._fieldKeys();return D(this.getAttribute(`required`)).filter(t=>N(t)&&e.includes(t))}_label(e){return O(this.getAttribute(`labels`))[e]||u[e]}_postedName(e){return this._text(`field-prefix`)+(O(this.getAttribute(`field-names`))[e]||e)}_maxLength(e){let t=Number(O(this.getAttribute(`max-lengths`))[e]);return Number.isInteger(t)&&t>0?t:d[e]}_triggers(){if(this.preview)return[];let e=(this.getAttribute(`triggers`)??``).split(/\s+/).filter(P);return e.length?this.getAttribute(`storage-key`)?e:(T(`storage-key`,`[@webority/ui-elements] <wui-lead-popup> has triggers but no storage-key. The triggers are off.`),[]):[]}_render(){let e=this._root();j(e);let t=this._uid,n=this._fieldKeys(),r=new Set(this._requiredKeys()),i=this._text(`heading`),a=this._text(`description`),o=this._text(`secondary-label`),s=this._text(`secondary-href`),c=n.map(e=>this._fieldMarkup(e,r.has(e))).join(``),l=document.createElement(`template`);l.innerHTML=` <dialog class="wlp-dialog" aria-labelledby="${t}-h"${a?` aria-describedby="${t}-d"`:``}> <div class="wlp-card"> <button type="button" class="wlp-close" aria-label="${k(this._text(`close-label`,`Close`))}" data-wlp-close>&times;</button> <div class="wlp-form-view"> <h2 class="wlp-heading" id="${t}-h">${k(i)}</h2> ${a?`<p class="wlp-description" id="${t}-d">${k(a)}</p>`:``} <form class="wlp-form" novalidate data-wlp-form> ${c} <p class="wlp-form-error" role="alert" hidden data-wlp-form-error></p> <div class="wlp-actions"> <button type="submit" class="wlp-button" data-wlp-submit>${k(this._text(`submit-label`,`Send`))}</button> </div> <input type="text" name="${_}" class="wlp-honeypot" tabindex="-1" autocomplete="off" aria-hidden="true" data-wlp-honeypot> <p class="wlp-notice" data-recaptcha-notice>This site is protected by reCAPTCHA and the Google <a href="https://policies.google.com/privacy" target="_blank" rel="noopener">Privacy Policy</a> and <a href="https://policies.google.com/terms" target="_blank" rel="noopener">Terms of Service</a> apply.</p> </form> ${o&&s?`<div class="wlp-secondary-row"><span>${k(this._text(`secondary-divider`,`or`))}</span></div><a class="wlp-secondary" href="${k(s)}" data-wlp-secondary>${k(o)}</a>`:``} </div> <div class="wlp-success-view" hidden> <h2 class="wlp-success-title" role="status" tabindex="-1" data-wlp-success-title>${k(this._text(`success-title`,`Thank you`))}</h2> ${this._text(`success-text`)?`<p class="wlp-success-text">${k(this._text(`success-text`))}</p>`:``} <button type="button" class="wlp-button" data-wlp-done>${k(this._text(`close-label`,`Close`))}</button> </div> </div> </dialog>`,e.replaceChildren(l.content),this._rendered=!0,this._stale=!1,this._wire()}_fieldMarkup(e,t){let n=`${this._uid}-f-${e}`,r=`${this._uid}-e-${e}`,i=this._label(e),a=k(this._postedName(e)),o=t?`<span class="wlp-req" aria-hidden="true">*</span><span class="wlp-visually-hidden">required</span>`:``,s=t?` aria-required="true"`:``;if(e===`consent`){let t=this._text(`consent-href`),c=t?`<a class="wlp-consent-link" href="${k(t)}">${k(this._label(`consentLink`))}</a>`:``;return` <div class="wlp-field wlp-field-consent" data-wlp-field="${e}"> <div class="form-check"> <input class="form-check-input" type="checkbox" id="${n}" data-wlp-input="${e}" name="${a}"${s}> <label class="form-check-label" for="${n}">${k(i)}${o}</label> ${c} </div> <p class="wlp-error" id="${r}" hidden></p> </div>`}let c=`id="${n}" data-wlp-input="${e}" name="${a}" maxlength="${this._maxLength(e)}"${s}`,l=e===`message`?`<textarea class="wlp-input" rows="4" ${c}></textarea>`:`<input class="wlp-input" type="${e===`email`?`email`:e===`phone`?`tel`:`text`}" ${c}${f[e]?` autocomplete="${f[e]}"`:``}>`;return` <div class="wlp-field" data-wlp-field="${e}"> <label class="wlp-label" for="${n}">${k(i)}${o}</label> ${l} <p class="wlp-error" id="${r}" hidden></p> </div>`}_wire(){let e=this._dialog();e.addEventListener(`cancel`,e=>{e.preventDefault(),this.close(`escape`)}),e.addEventListener(`click`,t=>{t.target===e&&this.close(`backdrop`)}),e.addEventListener(`keydown`,t=>{if(t.key!==`Tab`||!this._modal)return;let n=Array.from(e.querySelectorAll(p)).filter(e=>e instanceof HTMLElement&&!(`disabled`in e&&e.disabled===!0)&&e.getClientRects().length>0);if(!n.length)return;let r=this._root().activeElement,i=r instanceof HTMLElement?n.indexOf(r):-1;t.preventDefault();let a=n[i===-1?t.shiftKey?n.length-1:0:(i+(t.shiftKey?-1:1)+n.length)%n.length];if(!a)throw Error(`tab stop missing`);a.focus()});for(let t of e.querySelectorAll(`[data-wlp-close]`))t.addEventListener(`click`,()=>this.close(`dismiss`));e.querySelector(`[data-wlp-done]`)?.addEventListener(`click`,()=>this.close(`submitted`)),e.querySelector(`[data-wlp-secondary]`)?.addEventListener(`click`,()=>this.close(`secondary`)),F(e.querySelector(`[data-wlp-form]`),HTMLFormElement,`form`).addEventListener(`submit`,e=>this._onSubmit(e))}_showForm(){let e=this._root();F(e.querySelector(`.wlp-form-view`),HTMLElement,`form view`).hidden=!1,F(e.querySelector(`.wlp-success-view`),HTMLElement,`success view`).hidden=!0}_showSuccess(){let e=this._root();F(e.querySelector(`.wlp-form-view`),HTMLElement,`form view`).hidden=!0;let t=F(e.querySelector(`.wlp-success-view`),HTMLElement,`success view`);t.hidden=!1,F(e.querySelector(`[data-wlp-success-title]`),HTMLElement,`success title`).focus()}_setFieldError(e,t){let n=this._root(),r=F(n.querySelector(`[data-wlp-input="${e}"]`),HTMLElement,`${e} field`),i=F(n.querySelector(`#${this._uid}-e-${e}`),HTMLElement,`${e} error`);return i.textContent=t,i.hidden=!t,t?(r.setAttribute(`aria-invalid`,`true`),r.setAttribute(`aria-describedby`,i.id)):(r.removeAttribute(`aria-invalid`),r.removeAttribute(`aria-describedby`)),r}_validate(){let e=new Set(this._requiredKeys()),t=null,n={};for(let r of this._fieldKeys()){let i=this._root().querySelector(`[data-wlp-input="${r}"]`);if(!(i instanceof HTMLInputElement||i instanceof HTMLTextAreaElement))throw Error(`${r} field missing`);let a=r===`consent`&&i instanceof HTMLInputElement?i.checked:i.value.trim();n[r]=a;let o=``;!a&&e.has(r)?o=r===`consent`?S:`Enter your ${this._label(r).toLowerCase()}`:r===`email`&&a&&!h.test(String(a))&&(o=`Enter a valid email address`);let s=this._setFieldError(r,o);o&&!t&&(t=s)}return t?(t.focus(),null):n}_setBusy(e){this._posting=e;let t=F(this._root().querySelector(`[data-wlp-form]`),HTMLElement,`form`);e?t.setAttribute(`aria-busy`,`true`):t.removeAttribute(`aria-busy`),F(this._root().querySelector(`[data-wlp-submit]`),HTMLButtonElement,`submit button`).disabled=e}_fail(e,t){this._setBusy(!1);let n=F(this._root().querySelector(`[data-wlp-form-error]`),HTMLElement,`form error`);n.textContent=t,n.hidden=!t,this._emit(`wui-lead-popup-error`,{message:t,reason:e})}async _onSubmit(e){if(e.preventDefault(),this._posting)return;F(this._root().querySelector(`[data-wlp-form-error]`),HTMLElement,`form error`).hidden=!0;let t=this._validate();t&&!this.preview&&await this._post(t)}async _post(e){let t=globalThis.WeborityPublicForms;if(!t){T(`gate`,`[@webority/ui-elements] <wui-lead-popup> needs window.WeborityPublicForms. Load Webority.Security.Razor's public-form.js.`),this._fail(`gate`,this._text(`error-text`,x));return}let r=this._text(`error-text`,x),i=this._text(`public-form`);this._setBusy(!0);let a,o;try{a=await t.session(),o=await t.mintToken(i)}catch(e){this._fail(`gate`,M(e,r));return}let s=this._root(),c=new FormData;for(let t of this._fieldKeys())c.append(this._postedName(t),String(e[t]));c.set(v,a.token),c.set(y,a.formStamp),c.set(b,o),c.set(_,F(s.querySelector(`[data-wlp-honeypot]`),HTMLInputElement,`honeypot`).value),this._emit(`wui-lead-popup-before-submit`,{formData:c});let l;try{l=await fetch(this._text(`action`),{method:`POST`,body:c,credentials:`same-origin`,headers:{"X-Requested-With":`XMLHttpRequest`}})}catch{this._fail(`network`,r);return}let u;try{u=await this._readJson(l)}catch(e){n(`<wui-lead-popup> could not read the response body`,e),this._fail(`server`,r);return}if(l.ok)this._succeed(e,u);else{let e=typeof u==`object`&&u&&`detail`in u&&typeof u.detail==`string`?u.detail.trim():``;this._fail(`server`,e||r)}}async _readJson(e){return e.json()}_succeed(e,t){this._setBusy(!1),this._remember(`submitted`),this._emit(`wui-lead-popup-submitted`,{values:e,response:t}),this._showSuccess();let n=this._number(`success-close-seconds`,5);n>0&&(this._closeTimer=setTimeout(()=>this.close(`submitted`),n*1e3))}_arm(){if(this._armed)return;this._armed=!0;let e=this._triggers();if(!e.length)return;this._session=this._loadSession();let t=location.pathname+location.search;if(this._session.pages.includes(t)||this._session.pages.push(t),this._saveSession(),e.includes(`exit`)&&(document.documentElement.addEventListener(`mouseleave`,this._onMouseLeave),document.addEventListener(`visibilitychange`,this._onVisibility)),e.includes(`delay`)){let e=Math.max(0,this._number(`delay-seconds`,30)*1e3-(Date.now()-this._session.start));this._delayTimer=setTimeout(()=>this.open(`delay`),e)}e.includes(`scroll`)&&(window.addEventListener(`scroll`,this._onScroll,{passive:!0}),this._trackScroll()),e.includes(`pages`)&&this._session.pages.length>this._number(`pages-viewed`,2)&&this.open(`pages`)}_disarm(){this._armed=!1,clearTimeout(this._delayTimer??void 0),clearTimeout(this._closeTimer??void 0),document.documentElement.removeEventListener(`mouseleave`,this._onMouseLeave),document.removeEventListener(`visibilitychange`,this._onVisibility),window.removeEventListener(`scroll`,this._onScroll)}_trackScroll(){let e=document.documentElement.scrollHeight;if(this._session&&e>0){let t=(window.scrollY+window.innerHeight)/e*100;t>this._session.maxScroll&&(this._session.maxScroll=t,this._saveSession()),this._session.maxScroll>this._number(`scroll-percent`,50)&&this.open(`scroll`)}}_fine(){return typeof matchMedia!=`function`||matchMedia(`(pointer: fine)`).matches}_engaged(){let e=this._session;return e?Date.now()-e.start>this._number(`delay-seconds`,30)*1e3||e.maxScroll>this._number(`scroll-percent`,50)||e.pages.length>this._number(`pages-viewed`,2):!1}_sessionKey(){return`wui-lead-popup:${this.getAttribute(`storage-key`)}`}_loadSession(){let e={start:Date.now(),maxScroll:0,pages:[]};try{let e=sessionStorage.getItem(this._sessionKey());if(e){let t=JSON.parse(e);if(Number.isFinite(t.start)&&Number.isFinite(t.maxScroll)&&Array.isArray(t.pages))return t}}catch{return e}return e}_saveSession(){try{sessionStorage.setItem(this._sessionKey(),JSON.stringify(this._session))}catch{}}_readMemory(){let e=this.getAttribute(`storage-key`);if(!e)return null;try{let t=JSON.parse(localStorage.getItem(e)??`null`);if((t?.state===`shown`||t?.state===`submitted`)&&Number.isFinite(Date.parse(t.at)))return t}catch{return null}return null}_blocked(){let e=this._readMemory();if(!e)return!1;let t=e.state===`shown`?this._number(`dismiss-days`,30):this._number(`submitted-days`,365);return Date.now()-Date.parse(e.at)<t*g}_remember(e){let t=this.getAttribute(`storage-key`);if(t&&!this.preview)try{localStorage.setItem(t,JSON.stringify({state:e,at:new Date().toISOString()}))}catch{}}})})();
1
+ (function(){function e(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}>.`)}function t(e,...t){console.warn(e,...t)}function n(e,...t){console.error(e,...t)}var r=`@webority/ui-elements needs a browser DOM; import its types or helpers entry on the server`;if(typeof HTMLElement>`u`)throw Error(r);var i=HTMLElement,a={"--color-primary":`#4F46E5`,"--color-primary-hover":`#4338CA`,"--color-primary-soft":`#E0E7FF`,"--color-primary-text":`#4F46E5`,"--color-on-primary":`#FFFFFF`,"--color-text":`#071437`,"--color-text-muted":`#4B5675`,"--color-border":`#EBEDF3`,"--color-border-strong":`#C4CADA`,"--color-surface":`#FFFFFF`,"--wui-radius-sm":`8px`,"--wui-radius-lg":`14px`,"--wui-shadow-modal":`0px 24px 60px -16px rgba(7, 20, 55, 0.28)`,"--wui-z-modal":`1505`},o=e=>`var(${e}, ${a[e]})`,s=` :host { all: initial; display: contents; font-family: inherit; font-size: 16px; line-height: 1.5; color: ${o(`--color-text`)}; } *, *::before, *::after { box-sizing: border-box; } [hidden] { display: none !important; } dialog { z-index: ${o(`--wui-z-modal`)}; width: 100%; max-width: none; height: 100%; max-height: none; margin: 0; padding: 0; border: 0; background: transparent; color: inherit; } dialog[open] { display: flex; align-items: center; justify-content: center; } :host([preview]) dialog { position: static; height: auto; } dialog::backdrop { background: rgba(0, 0, 0, 0.7); backdrop-filter: blur(5px); } dialog[open]::backdrop { animation: wlp-fade 0.3s ease-out; } .wlp-card { position: relative; width: 90%; max-width: 440px; max-height: calc(100dvh - 32px); overflow-y: auto; padding: 24px; background: ${o(`--color-surface`)}; color: ${o(`--color-text`)}; border: 1px solid ${o(`--color-border`)}; border-radius: ${o(`--wui-radius-lg`)}; box-shadow: ${o(`--wui-shadow-modal`)}; text-align: start; } dialog[open] .wlp-card { animation: wlp-card-in 0.2s ease-out; } .wlp-close { position: absolute; top: 12px; inset-inline-end: 12px; width: 32px; height: 32px; padding: 0; border: 0; border-radius: 50%; background: transparent; color: ${o(`--color-text-muted`)}; font: inherit; font-size: 22px; line-height: 1; cursor: pointer; } .wlp-close:focus-visible, .wlp-button:focus-visible, .wlp-input:focus-visible, .wlp-secondary:focus-visible { outline: 2px solid ${o(`--color-primary`)}; outline-offset: 2px; } .wlp-heading { margin: 0 32px 8px 0; font-size: 20px; font-weight: 600; line-height: 1.3; color: ${o(`--color-text`)}; } .wlp-description { margin: 0 0 16px; font-size: 14px; color: ${o(`--color-text-muted`)}; } .wlp-form { display: grid; gap: 14px; margin: 0; } .wlp-field { display: grid; gap: 4px; } .wlp-label { font-size: 14px; font-weight: 500; color: ${o(`--color-text`)}; } .wlp-req { margin-inline-start: 2px; color: ${o(`--color-primary`)}; } .wlp-input { width: 100%; padding: 9px 12px; border: 1px solid ${o(`--color-border`)}; border-radius: 8px; background: ${o(`--color-surface`)}; color: ${o(`--color-text`)}; font: inherit; font-size: 15px; } textarea.wlp-input { resize: vertical; min-height: 96px; } .wlp-input[aria-invalid="true"] { border-color: var(--color-danger, #B42318); } .wlp-error { margin: 0; font-size: 13px; color: var(--color-danger, #B42318); } .wlp-form-error { margin: 0; font-size: 14px; color: var(--color-danger, #B42318); } /* The consent field uses the theme's checkbox markup; its look is restated here because the theme's rules cannot reach the shadow root. */ .form-check { display: grid; grid-template-columns: auto 1fr; align-items: center; column-gap: 12px; font-size: 14px; line-height: 1.4; color: ${o(`--color-text`)}; } .form-check-input { flex: none; width: 20px; height: 20px; margin: 0; appearance: none; -webkit-appearance: none; border: 1.6px solid ${o(`--color-border-strong`)}; border-radius: ${o(`--wui-radius-sm`)}; corner-shape: squircle; background-color: ${o(`--color-surface`)}; background-repeat: no-repeat; background-position: center; background-size: 15px 15px; cursor: pointer; transition: border-color 0.15s ease, background-color 0.15s ease, box-shadow 0.15s ease; } .form-check-input:hover:not(:checked) { border-color: ${o(`--color-primary`)}; box-shadow: 0 0 0 2px ${o(`--color-primary-soft`)}; } .form-check-input:checked { border-color: ${o(`--color-primary`)}; background-color: ${o(`--color-primary`)}; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='3.4' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M5 12.5l4.5 4.5L19 7'/%3E%3C/svg%3E"); } .form-check-input:focus-visible { outline: 2px solid ${o(`--color-primary`)}; outline-offset: 2px; box-shadow: none; } .form-check-input[aria-invalid="true"] { border-color: var(--color-danger, #B42318); } .form-check-label { min-width: 0; cursor: pointer; } .wlp-field-consent .wlp-error { margin-inline-start: 32px; } .wlp-consent-link { grid-column: 2; justify-self: start; color: ${o(`--color-primary-text`)}; font-weight: 500; text-decoration: underline; text-underline-offset: 3px; } .wlp-consent-link:focus-visible { outline: 2px solid ${o(`--color-primary`)}; outline-offset: 2px; border-radius: 4px; } .wlp-visually-hidden { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; } .wlp-honeypot { position: absolute !important; left: -9999px !important; width: 1px; height: 1px; opacity: 0; pointer-events: none; } .wlp-actions { display: flex; justify-content: flex-end; align-items: center; gap: 8px; margin-top: 4px; } .wlp-button { display: inline-flex; align-items: center; justify-content: center; min-height: 36px; padding: 8px 16px; border: 1px solid ${o(`--color-primary`)}; border-radius: 8px; background: ${o(`--color-primary`)}; color: ${o(`--color-on-primary`)}; font: inherit; font-size: 15px; font-weight: 500; cursor: pointer; } .wlp-button:hover { background: ${o(`--color-primary-hover`)}; border-color: ${o(`--color-primary-hover`)}; } .wlp-button:disabled { opacity: 0.6; cursor: default; } .wlp-notice { margin: 4px 0 0; font-size: 12px; line-height: 1.4; color: ${o(`--color-text-muted`)}; } .wlp-notice a { color: inherit; text-decoration: underline; } .wlp-secondary-row { display: flex; align-items: center; gap: 10px; margin-top: 14px; font-size: 14px; color: ${o(`--color-text-muted`)}; } .wlp-secondary-row::before, .wlp-secondary-row::after { content: ""; flex: 1; height: 1px; background: ${o(`--color-border`)}; } .wlp-secondary { display: block; margin-top: 10px; text-align: center; color: ${o(`--color-primary`)}; font-weight: 500; } .wlp-success-title { margin: 0 32px 8px 0; font-size: 20px; font-weight: 600; color: ${o(`--color-text`)}; } .wlp-success-text { margin: 0 0 16px; color: ${o(`--color-text-muted`)}; } .wlp-success-view .wlp-button { width: 100%; } @keyframes wlp-fade { from { opacity: 0; } to { opacity: 1; } } @keyframes wlp-card-in { from { opacity: 0; transform: scale(0.96); } to { opacity: 1; transform: scale(1); } } @media (max-width: 575.98px) { .wlp-card { width: calc(100% - 32px); max-width: none; padding: 20px 16px; } .wlp-input { font-size: 16px; } .wlp-button, .wlp-close { min-height: 44px; } .wlp-close { min-width: 44px; } } @media (prefers-reduced-motion: reduce) { dialog[open]::backdrop, dialog[open] .wlp-card { animation: none; } } `,c=[`name`,`email`,`phone`,`company`,`message`,`consent`],l=[`name`,`email`],u={name:`Name`,email:`Email`,phone:`Phone number`,company:`Company`,message:`Message`,consent:`I agree to be contacted about my enquiry`,consentLink:`Privacy policy`},d={name:100,email:320,phone:40,company:150,message:1e3},f={name:`name`,email:`email`,phone:`tel`,company:`organization`},p=`input:not([type=hidden]), textarea, select, button, a[href]`,m=[`exit`,`delay`,`scroll`,`pages`],h=/^[^\s@]+@[^\s@]+\.[^\s@]+$/,g=864e5,_=`comment_subject`,v=`__RequestVerificationToken`,y=`__FormStamp`,b=`__CaptchaToken`,x=`Something went wrong. Please try again or contact us directly.`,S=`Tick the box to continue`,C=`action.public-form.heading.description.fields.required.field-prefix.field-names.labels.max-lengths.submit-label.success-title.success-text.error-text.close-label.secondary-label.secondary-href.secondary-divider.consent-href.triggers.delay-seconds.scroll-percent.pages-viewed.storage-key.dismiss-days.submitted-days.success-close-seconds.preview`.split(`.`),w=new Set;function T(e,n){w.has(e)||(w.add(e),t(n))}var E=0;function D(e){return(e??``).split(/\s+/).map(e=>e.trim()).filter(Boolean)}function O(e){let t={};for(let n of(e??``).split(`;`)){let e=n.indexOf(`=`);if(e<0)continue;let r=n.slice(0,e).trim();r&&(t[r]=n.slice(e+1).trim())}return t}function k(e){return String(e??``).replace(/&/g,`&amp;`).replace(/</g,`&lt;`).replace(/>/g,`&gt;`).replace(/"/g,`&quot;`)}var A=null;function j(e){A||(A=new CSSStyleSheet,A.replaceSync(s)),e.adoptedStyleSheets=[A]}function M(e,t){return e instanceof Error&&e.message?e.message:t}function N(e){return c.some(t=>t===e)}function P(e){return m.some(t=>t===e)}function F(e,t,n){if(e instanceof t)return e;throw Error(`${n} missing`)}e(`wui-lead-popup`,class extends i{_uid;_rendered;_open;_opened;_posting;_stale;_armed;_session;_returnTo;_prevOverflow;_delayTimer;_closeTimer;_modal;_onMouseLeave;_onVisibility;_onScroll;static get observedAttributes(){return C}constructor(){super(),E+=1,this._uid=`wlp-${E}`,this._rendered=!1,this._open=!1,this._opened=!1,this._posting=!1,this._stale=!1,this._armed=!1,this._session=null,this._returnTo=null,this._prevOverflow=``,this._delayTimer=null,this._closeTimer=null,this._onMouseLeave=e=>{!this._fine()||e.clientY>0||!this._engaged()||this.open(`exit`)},this._onVisibility=()=>{document.visibilityState===`hidden`&&!this._fine()&&this._engaged()&&this.open(`exit`)},this._onScroll=()=>this._trackScroll()}get isOpen(){return this._open}set isOpen(e){e?this.open(`manual`):this.close(`dismiss`)}connectedCallback(){this._rendered||this._render(),this._arm(),this.preview&&!this._open&&this.open(`manual`)}disconnectedCallback(){this._disarm(),this._open&&this._release()}attributeChangedCallback(){this._rendered&&(this._open?this._stale=!0:this._render())}open(e=`manual`){if(!this._open&&!(e!==`manual`&&(this._opened||this._blocked()||document.querySelector(`dialog[open], .modal.show`)))){if(this._rendered||this._render(),this._opened=!0,this._open=!0,clearTimeout(this._delayTimer??void 0),this._showForm(),this._modal=!this.preview,this._modal){let e=document.activeElement;this._returnTo=e instanceof HTMLElement||e instanceof SVGElement?e:null,this._prevOverflow=document.documentElement.style.overflow,document.documentElement.style.overflow=`hidden`;let t=this._dialog();t.showModal();let n=t.querySelector(`[data-wlp-field] [data-wlp-input]`);n instanceof HTMLElement&&n.focus()}else this._dialog().setAttribute(`open`,``);this._remember(`shown`),this._emit(`wui-lead-popup-shown`,{trigger:e})}}close(e=`dismiss`){if(!this._open)return;clearTimeout(this._closeTimer??void 0),this._release();let t=this._returnTo;this._returnTo=null,t?.isConnected&&typeof t.focus==`function`&&t.focus(),this._stale&&this._render(),this._emit(`wui-lead-popup-closed`,{reason:e})}_release(){this._open=!1,this._dialog().close(),this._modal&&(document.documentElement.style.overflow=this._prevOverflow)}_root(){return this.shadowRoot??this.attachShadow({mode:`open`})}_dialog(){return F(this._root().querySelector(`dialog`),HTMLDialogElement,`dialog`)}_emit(e,t){this.dispatchEvent(new CustomEvent(e,{bubbles:!0,composed:!0,detail:t}))}_text(e,t=``){return this.getAttribute(e)||t}_number(e,t){let n=this.getAttribute(e);if(n===null||n.trim()===``)return t;let r=Number(n);return Number.isFinite(r)&&r>=0?r:t}get preview(){return this.hasAttribute(`preview`)}set preview(e){this.toggleAttribute(`preview`,e===!0||e===``||e===`true`)}_fieldKeys(){let e=D(this.getAttribute(`fields`)).filter(e=>N(e)?!0:(T(`field:${e}`,`[@webority/ui-elements] <wui-lead-popup> has no field "${e}". It is ignored.`),!1));return e.length?e:l}_requiredKeys(){let e=this._fieldKeys();return D(this.getAttribute(`required`)).filter(t=>N(t)&&e.includes(t))}_label(e){return O(this.getAttribute(`labels`))[e]||u[e]}_postedName(e){return this._text(`field-prefix`)+(O(this.getAttribute(`field-names`))[e]||e)}_maxLength(e){let t=Number(O(this.getAttribute(`max-lengths`))[e]);return Number.isInteger(t)&&t>0?t:d[e]}_triggers(){if(this.preview)return[];let e=(this.getAttribute(`triggers`)??``).split(/\s+/).filter(P);return e.length?this.getAttribute(`storage-key`)?e:(T(`storage-key`,`[@webority/ui-elements] <wui-lead-popup> has triggers but no storage-key. The triggers are off.`),[]):[]}_render(){let e=this._root();j(e);let t=this._uid,n=this._fieldKeys(),r=new Set(this._requiredKeys()),i=this._text(`heading`),a=this._text(`description`),o=this._text(`secondary-label`),s=this._text(`secondary-href`),c=n.map(e=>this._fieldMarkup(e,r.has(e))).join(``),l=document.createElement(`template`);l.innerHTML=` <dialog class="wlp-dialog" aria-labelledby="${t}-h"${a?` aria-describedby="${t}-d"`:``}> <div class="wlp-card"> <button type="button" class="wlp-close" aria-label="${k(this._text(`close-label`,`Close`))}" data-wlp-close>&times;</button> <div class="wlp-form-view"> <h2 class="wlp-heading" id="${t}-h">${k(i)}</h2> ${a?`<p class="wlp-description" id="${t}-d">${k(a)}</p>`:``} <form class="wlp-form" novalidate data-wlp-form> ${c} <p class="wlp-form-error" role="alert" hidden data-wlp-form-error></p> <div class="wlp-actions"> <button type="submit" class="wlp-button" data-wlp-submit>${k(this._text(`submit-label`,`Send`))}</button> </div> <input type="text" name="${_}" class="wlp-honeypot" tabindex="-1" autocomplete="off" aria-hidden="true" data-wlp-honeypot> <p class="wlp-notice" data-recaptcha-notice>This site is protected by reCAPTCHA and the Google <a href="https://policies.google.com/privacy" target="_blank" rel="noopener">Privacy Policy</a> and <a href="https://policies.google.com/terms" target="_blank" rel="noopener">Terms of Service</a> apply.</p> </form> ${o&&s?`<div class="wlp-secondary-row"><span>${k(this._text(`secondary-divider`,`or`))}</span></div><a class="wlp-secondary" href="${k(s)}" data-wlp-secondary>${k(o)}</a>`:``} </div> <div class="wlp-success-view" hidden> <h2 class="wlp-success-title" role="status" tabindex="-1" data-wlp-success-title>${k(this._text(`success-title`,`Thank you`))}</h2> ${this._text(`success-text`)?`<p class="wlp-success-text">${k(this._text(`success-text`))}</p>`:``} <button type="button" class="wlp-button" data-wlp-done>${k(this._text(`close-label`,`Close`))}</button> </div> </div> </dialog>`,e.replaceChildren(l.content),this._rendered=!0,this._stale=!1,this._wire()}_fieldMarkup(e,t){let n=`${this._uid}-f-${e}`,r=`${this._uid}-e-${e}`,i=this._label(e),a=k(this._postedName(e)),o=t?`<span class="wlp-req" aria-hidden="true">*</span><span class="wlp-visually-hidden">required</span>`:``,s=t?` aria-required="true"`:``;if(e===`consent`){let t=this._text(`consent-href`),c=t?`<a class="wlp-consent-link" href="${k(t)}">${k(this._label(`consentLink`))}</a>`:``;return` <div class="wlp-field wlp-field-consent" data-wlp-field="${e}"> <div class="form-check"> <input class="form-check-input" type="checkbox" id="${n}" data-wlp-input="${e}" name="${a}"${s}> <label class="form-check-label" for="${n}">${k(i)}${o}</label> ${c} </div> <p class="wlp-error" id="${r}" hidden></p> </div>`}let c=`id="${n}" data-wlp-input="${e}" name="${a}" maxlength="${this._maxLength(e)}"${s}`,l=e===`message`?`<textarea class="wlp-input" rows="4" ${c}></textarea>`:`<input class="wlp-input" type="${e===`email`?`email`:e===`phone`?`tel`:`text`}" ${c}${f[e]?` autocomplete="${f[e]}"`:``}>`;return` <div class="wlp-field" data-wlp-field="${e}"> <label class="wlp-label" for="${n}">${k(i)}${o}</label> ${l} <p class="wlp-error" id="${r}" hidden></p> </div>`}_wire(){let e=this._dialog();e.addEventListener(`cancel`,e=>{e.preventDefault(),this.close(`escape`)}),e.addEventListener(`click`,t=>{t.target===e&&this.close(`backdrop`)}),e.addEventListener(`keydown`,t=>{if(t.key!==`Tab`||!this._modal)return;let n=Array.from(e.querySelectorAll(p)).filter(e=>e instanceof HTMLElement&&!(`disabled`in e&&e.disabled===!0)&&e.getClientRects().length>0);if(!n.length)return;let r=this._root().activeElement,i=r instanceof HTMLElement?n.indexOf(r):-1;t.preventDefault();let a=n[i===-1?t.shiftKey?n.length-1:0:(i+(t.shiftKey?-1:1)+n.length)%n.length];if(!a)throw Error(`tab stop missing`);a.focus()});for(let t of e.querySelectorAll(`[data-wlp-close]`))t.addEventListener(`click`,()=>this.close(`dismiss`));e.querySelector(`[data-wlp-done]`)?.addEventListener(`click`,()=>this.close(`submitted`)),e.querySelector(`[data-wlp-secondary]`)?.addEventListener(`click`,()=>this.close(`secondary`)),F(e.querySelector(`[data-wlp-form]`),HTMLFormElement,`form`).addEventListener(`submit`,e=>this._onSubmit(e))}_showForm(){let e=this._root();F(e.querySelector(`.wlp-form-view`),HTMLElement,`form view`).hidden=!1,F(e.querySelector(`.wlp-success-view`),HTMLElement,`success view`).hidden=!0}_showSuccess(){let e=this._root();F(e.querySelector(`.wlp-form-view`),HTMLElement,`form view`).hidden=!0;let t=F(e.querySelector(`.wlp-success-view`),HTMLElement,`success view`);t.hidden=!1,F(e.querySelector(`[data-wlp-success-title]`),HTMLElement,`success title`).focus()}_setFieldError(e,t){let n=this._root(),r=F(n.querySelector(`[data-wlp-input="${e}"]`),HTMLElement,`${e} field`),i=F(n.querySelector(`#${this._uid}-e-${e}`),HTMLElement,`${e} error`);return i.textContent=t,i.hidden=!t,t?(r.setAttribute(`aria-invalid`,`true`),r.setAttribute(`aria-describedby`,i.id)):(r.removeAttribute(`aria-invalid`),r.removeAttribute(`aria-describedby`)),r}_validate(){let e=new Set(this._requiredKeys()),t=null,n={};for(let r of this._fieldKeys()){let i=this._root().querySelector(`[data-wlp-input="${r}"]`);if(!(i instanceof HTMLInputElement||i instanceof HTMLTextAreaElement))throw Error(`${r} field missing`);let a=r===`consent`&&i instanceof HTMLInputElement?i.checked:i.value.trim();n[r]=a;let o=``;!a&&e.has(r)?o=r===`consent`?S:`Enter your ${this._label(r).toLowerCase()}`:r===`email`&&a&&!h.test(String(a))&&(o=`Enter a valid email address`);let s=this._setFieldError(r,o);o&&!t&&(t=s)}return t?(t.focus(),null):n}_setBusy(e){this._posting=e;let t=F(this._root().querySelector(`[data-wlp-form]`),HTMLElement,`form`);e?t.setAttribute(`aria-busy`,`true`):t.removeAttribute(`aria-busy`),F(this._root().querySelector(`[data-wlp-submit]`),HTMLButtonElement,`submit button`).disabled=e}_fail(e,t){this._setBusy(!1);let n=F(this._root().querySelector(`[data-wlp-form-error]`),HTMLElement,`form error`);n.textContent=t,n.hidden=!t,this._emit(`wui-lead-popup-error`,{message:t,reason:e})}async _onSubmit(e){if(e.preventDefault(),this._posting)return;F(this._root().querySelector(`[data-wlp-form-error]`),HTMLElement,`form error`).hidden=!0;let t=this._validate();t&&!this.preview&&await this._post(t)}async _post(e){let t=globalThis.WeborityPublicForms;if(!t){T(`gate`,`[@webority/ui-elements] <wui-lead-popup> needs window.WeborityPublicForms. Load Webority.Security.Razor's public-form.js.`),this._fail(`gate`,this._text(`error-text`,x));return}let r=this._text(`error-text`,x),i=this._text(`public-form`);this._setBusy(!0);let a,o;try{a=await t.session(),o=await t.mintToken(i)}catch(e){this._fail(`gate`,M(e,r));return}let s=this._root(),c=new FormData;for(let t of this._fieldKeys())c.append(this._postedName(t),String(e[t]));c.set(v,a.token),c.set(y,a.formStamp),c.set(b,o),c.set(_,F(s.querySelector(`[data-wlp-honeypot]`),HTMLInputElement,`honeypot`).value),this._emit(`wui-lead-popup-before-submit`,{formData:c});let l;try{l=await fetch(this._text(`action`),{method:`POST`,body:c,credentials:`same-origin`,headers:{"X-Requested-With":`XMLHttpRequest`}})}catch{this._fail(`network`,r);return}let u;try{u=await this._readJson(l)}catch(e){n(`<wui-lead-popup> could not read the response body`,e),this._fail(`server`,r);return}if(l.ok)this._succeed(e,u);else{let e=typeof u==`object`&&u&&`detail`in u&&typeof u.detail==`string`?u.detail.trim():``;this._fail(`server`,e||r)}}async _readJson(e){return e.json()}_succeed(e,t){this._setBusy(!1),this._remember(`submitted`),this._emit(`wui-lead-popup-submitted`,{values:e,response:t}),this._showSuccess();let n=this._number(`success-close-seconds`,5);n>0&&(this._closeTimer=setTimeout(()=>this.close(`submitted`),n*1e3))}_arm(){if(this._armed)return;this._armed=!0;let e=this._triggers();if(!e.length)return;this._session=this._loadSession();let t=location.pathname+location.search;if(this._session.pages.includes(t)||this._session.pages.push(t),this._saveSession(),e.includes(`exit`)&&(document.documentElement.addEventListener(`mouseleave`,this._onMouseLeave),document.addEventListener(`visibilitychange`,this._onVisibility)),e.includes(`delay`)){let e=Math.max(0,this._number(`delay-seconds`,30)*1e3-(Date.now()-this._session.start));this._delayTimer=setTimeout(()=>this.open(`delay`),e)}e.includes(`scroll`)&&(window.addEventListener(`scroll`,this._onScroll,{passive:!0}),this._trackScroll()),e.includes(`pages`)&&this._session.pages.length>this._number(`pages-viewed`,2)&&this.open(`pages`)}_disarm(){this._armed=!1,clearTimeout(this._delayTimer??void 0),clearTimeout(this._closeTimer??void 0),document.documentElement.removeEventListener(`mouseleave`,this._onMouseLeave),document.removeEventListener(`visibilitychange`,this._onVisibility),window.removeEventListener(`scroll`,this._onScroll)}_trackScroll(){let e=document.documentElement.scrollHeight;if(this._session&&e>0){let t=(window.scrollY+window.innerHeight)/e*100;t>this._session.maxScroll&&(this._session.maxScroll=t,this._saveSession()),this._session.maxScroll>this._number(`scroll-percent`,50)&&this.open(`scroll`)}}_fine(){return typeof matchMedia!=`function`||matchMedia(`(pointer: fine)`).matches}_engaged(){let e=this._session;return e?Date.now()-e.start>this._number(`delay-seconds`,30)*1e3||e.maxScroll>this._number(`scroll-percent`,50)||e.pages.length>this._number(`pages-viewed`,2):!1}_sessionKey(){return`wui-lead-popup:${this.getAttribute(`storage-key`)}`}_loadSession(){let e={start:Date.now(),maxScroll:0,pages:[]};try{let e=sessionStorage.getItem(this._sessionKey());if(e){let t=JSON.parse(e);if(Number.isFinite(t.start)&&Number.isFinite(t.maxScroll)&&Array.isArray(t.pages))return t}}catch{return e}return e}_saveSession(){try{sessionStorage.setItem(this._sessionKey(),JSON.stringify(this._session))}catch(e){if(!(e instanceof DOMException))throw e}}_readMemory(){let e=this.getAttribute(`storage-key`);if(!e)return null;try{let t=JSON.parse(localStorage.getItem(e)??`null`);if((t?.state===`shown`||t?.state===`submitted`)&&Number.isFinite(Date.parse(t.at)))return t}catch{return null}return null}_blocked(){let e=this._readMemory();if(!e)return!1;let t=e.state===`shown`?this._number(`dismiss-days`,30):this._number(`submitted-days`,365);return Date.now()-Date.parse(e.at)<t*g}_remember(e){let t=this.getAttribute(`storage-key`);if(t&&!this.preview)try{localStorage.setItem(t,JSON.stringify({state:e,at:new Date().toISOString()}))}catch(e){if(!(e instanceof DOMException))throw e}}})})();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webority/ui-elements",
3
- "version": "0.152.0",
3
+ "version": "0.154.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",
@@ -250,9 +250,9 @@
250
250
  "@tiptap/starter-kit": "3.31.4",
251
251
  "@types/node": "25.6.0",
252
252
  "@vitest/coverage-v8": "5.1.0",
253
- "@webority/biome-config": "0.152.0",
254
- "@webority/markdown-core": "0.152.0",
255
- "@webority/theme": "0.152.0",
253
+ "@webority/biome-config": "0.154.0",
254
+ "@webority/markdown-core": "0.154.0",
255
+ "@webority/theme": "0.154.0",
256
256
  "echarts": "6.1.0",
257
257
  "jsdom": "30.1.1",
258
258
  "libphonenumber-js": "^1.13.9",
@@ -2,7 +2,7 @@
2
2
  export declare const COPY_FEEDBACK_MS = 2000;
3
3
  /**
4
4
  * Copy plain text to the clipboard. Tries `navigator.clipboard.writeText`, then falls
5
- * back to a hidden textarea + `document.execCommand("copy")`. Never throws.
5
+ * back to a hidden textarea + `document.execCommand("copy")`.
6
6
  *
7
7
  * @param text
8
8
  * @returns true when the copy succeeded
@@ -37,7 +37,7 @@ export declare function resolveTheme(mode: string | undefined): ResolvedTheme;
37
37
  * offers only light and dark shows an `auto` as resolveTheme() reads it; the page stays on auto.
38
38
  */
39
39
  export declare function readStoredTheme(storageKey?: string): ThemeMode;
40
- /** Remember a choice. Storage failures are swallowed: the page still switches for this visit. */
40
+ /** Remember a choice. A refused storage write is ignored: the page still switches for this visit. */
41
41
  export declare function storeTheme(mode: ThemeMode, storageKey?: string): void;
42
42
  /** Write the mode and its resolved theme onto <html>, which is where the design system reads them. */
43
43
  export declare function applyTheme(mode: ThemeMode): void;
@@ -1 +0,0 @@
1
- var e=2e3;async function t(e){try{if(navigator.clipboard?.writeText)return await navigator.clipboard.writeText(e),!0}catch{}try{let t=document.createElement(`textarea`);t.value=e,t.style.position=`fixed`,t.style.top=`0`,t.style.left=`0`,t.style.opacity=`0`,document.body.appendChild(t),t.select();let n=document.execCommand(`copy`);return document.body.removeChild(t),!!n}catch{return!1}}export{t as n,e as t};
@@ -1 +0,0 @@
1
- import{f as e}from"./formatters-ljfITOZ3.js";var t=48,n=1200,r=10,i=50,a=[`start`,`end`],o=8,s={comfortable:72,cozy:48,compact:40},c={resize:e=>e?`Resize ${e} column`:`Resize column`,width:e=>`${e} pixels`,rows:t=>`${e(t,{decimals:0})} ${t===1?`row`:`rows`}`,saved:e=>e?`${e} saved.`:`Row saved.`,savedMany:t=>`${e(t,{decimals:0})} rows saved.`,notSaved:(e,t)=>`${e?`${e} was not saved.`:`Row was not saved.`}${t?` ${t}`:``}`},l=t=>e(t,{decimals:0}),u=e=>Math.min(n,Math.max(48,Math.round(Number(e)||0)));function d(e,t,n=[]){let r=new Map(n.map(e=>[e,[]]));return e.forEach((e,n)=>{let i=t(e,n),a=r.get(i);a||(a=[],r.set(i,a)),a.push(e)}),[...r].filter(([,e])=>e.length>0).map(([e,t])=>({key:e,items:t}))}function f({scrollTop:e,viewport:t,rowHeight:n,count:r,overscan:i=8}){let a=n>0?n:s.comfortable,o=Math.floor(Math.max(0,e)/a),c=Math.max(0,o-i);c-=c%2;let l=Math.min(r,o+Math.ceil(Math.max(0,t)/a)+i),u=Math.min(c,l);return{start:u,end:l,before:u*a,after:Math.max(0,r-l)*a}}var p=e=>`wui-widths:${e}`;function m(e){if(!e)return{};try{let t=JSON.parse(window.localStorage.getItem(p(e))||`{}`),n={};if(t&&typeof t==`object`)for(let[e,r]of Object.entries(t))Number.isFinite(r)&&(n[e]=u(r));return n}catch{return{}}}function h(e,t){if(e)try{Object.keys(t).length?window.localStorage.setItem(p(e),JSON.stringify(t)):window.localStorage.removeItem(p(e))}catch{}}var g=(e,t)=>`--wui-pin-${e}-${t}`,_=`--wui-pin-at`,v=(e,t)=>`var(${g(e,t)}, 0px)`;function y(e){let t=e.map(()=>null),n=-1;e.forEach((e,t)=>{e===`start`&&(n=t)});let r=0;for(let i=0;i<=n;i++)(e[i]===`start`||e[i]===`lead`)&&(t[i]={side:`start`,ordinal:r++,edge:!1});let i=t[n];i&&(i.edge=!0);let a=-1;r=0;for(let n=e.length-1;n>=0;n--)e[n]===`end`&&(t[n]={side:`end`,ordinal:r++,edge:!1},a=n);let o=t[a];return o&&(o.edge=!0),t}var b=e=>e?`wui-pin-${e.side}${e.edge?` wui-pin-${e.side}-edge`:``}`:``,x=200,S=220,C=`cubic-bezier(0.22, 1, 0.36, 1)`,w=()=>typeof window<`u`&&typeof window.matchMedia==`function`&&window.matchMedia(`(prefers-reduced-motion: reduce)`).matches,T=e=>e.getAttribute(`data-row-key`)??e;function E(e){let t=[...e];if(t.length>200)return null;let n=/* @__PURE__ */ new Map;for(let e of t)e.hidden||n.set(T(e),e.offsetTop);return n}function D(e,t){let n=[...e];if(!t||n.length>200||w())return 0;let r=0;for(let e of n){if(e.hidden||typeof e.animate!=`function`)continue;let n=t.get(T(e));if(n===void 0)continue;let i=n-e.offsetTop;Math.abs(i)<1||(e.animate([{transform:`translateY(${i}px)`},{transform:`translateY(0)`}],{duration:220,easing:C}),r++)}return r}function O(e,t){if(!e||!t)return!1;let n=new Set(t),r=new Set(e),i=e.filter(e=>n.has(e)),a=t.filter(e=>r.has(e));return i.some((e,t)=>e!==a[t])}var k=[`saving`,`error`],A=`data-wui-save-state`,j=`wui-row-save-error`,M=e=>{let t=e.querySelector(`:scope > .wui-name-cell`);return t instanceof HTMLTableCellElement?t:[...e.cells].find(e=>!e.matches(`.wui-select-cell, .wui-expand-cell`))??null};function N(e){let t=M(e);if(!t)return``;let n=t.querySelector(`.u-name`);if(n)return(n.textContent??``).trim();let r=``;for(let e of t.childNodes)e instanceof Element&&e.classList.contains(`wui-row-save-error`)||(r+=e.textContent??``);return r.replace(/\s+/g,` `).trim()}function P(e,t,n=``){if(t!==null&&!k.includes(t))throw Error(`A row's save state is ${k.join(` or `)} (or null to clear it), not "${t}".`);e.querySelector(`:scope > * > .${j}`)?.remove(),t===null?e.removeAttribute(A):e.setAttribute(A,t),t===`saving`?e.setAttribute(`aria-busy`,`true`):e.removeAttribute(`aria-busy`);let r=t===`error`&&n?M(e):null;if(r){let t=e.ownerDocument.createElement(`span`);t.className=j,t.textContent=n,r.append(t)}}function F(e,t){let n=[];if(!e)return n;for(let[r,i]of e){let e=t.get(r);i.state===`saving`&&e&&e.state!==`saving`&&n.push({label:e.label,ok:e.state!==`error`,message:e.message||``})}return n}function I(e){let t=e.filter(e=>e.ok),n=[],[r]=t;t.length===1&&r?n.push(c.saved(r.label)):t.length>1&&n.push(c.savedMany(t.length));for(let t of e)t.ok||n.push(c.notSaved(t.label,t.message));return n.join(` `)}export{F as A,y as C,O as D,N as E,h as M,I as O,g as S,m as T,d as _,a,v as b,s as c,A as d,j as f,l as g,u as h,_ as i,f as j,P as k,x as l,o as m,t as n,r as o,k as p,c as r,i as s,n as t,S as u,M as v,D as w,b as x,E as y};
@@ -1 +0,0 @@
1
- import{n as e,r as t,t as n}from"./anchorOverlay-CXnWfezA.js";import{n as r,t as i}from"./elementBase-Cxeyx0tU.js";import{d as a}from"./shortcutKeys-COVLox98.js";var o=2,s=`wui-filter-popover-pinned`,c=`.wui-filter-popover-trigger`,l=`.wui-filter-popover-panel`,u=`.wui-filter-popover-head`,d=`input:not([type]),input[type="text"],input[type="search"]`,f=`a[href],button:not([disabled]),input:not([disabled]):not([type='hidden']),select:not([disabled]),textarea:not([disabled]),[tabindex]:not([tabindex='-1'])`;function p(){try{return sessionStorage.getItem(s)===`1`}catch{return!1}}function m(e){try{e?sessionStorage.setItem(s,`1`):sessionStorage.removeItem(s)}catch{}}function h(e){if(e===null||e instanceof Node)return e;throw TypeError(`event target is not a node`)}function g(e,t){let n=e?.querySelector(t)??null;return n instanceof HTMLElement?n:null}var _=class extends i{_doc;_timer;_sticky;_inside;_pendingSubmit;_onEnter;_onLeave;_onClick;_onChange;_onListClose;_onFocusOut;_onKeyDown;_onShortcut;_onEscape;_onOutside;constructor(){super(),this._doc=null,this._timer=null,this._sticky=!1,this._inside=!1,this._pendingSubmit=!1,this._onEnter=e=>{e.pointerType!==`touch`&&e.pointerType!==`pen`&&(this._inside=!0,this._schedule(!0))},this._onLeave=e=>{e.pointerType!==`touch`&&e.pointerType!==`pen`&&(this._inside=!1,this._schedule(!1))},this._onClick=e=>{this._trigger?.contains(h(e.target))&&(this._clear(),this.isOpen&&this._sticky?this._close(!0):this._open(!0,e.detail===0))},this._onChange=e=>{let t=this._pin;if(t&&e.target===t){m(t.checked),t.checked?this._clear():this._schedule(!1);return}let n=e.target;if(n instanceof Element&&n.closest(`wui-select[mode="multiple"], wui-select[mode="tag"]`)?.querySelector(`[aria-expanded="true"]`)){this._pendingSubmit=!0;return}let r=this.closest(`form.wui-filter-form`);r instanceof HTMLFormElement&&r.requestSubmit()},this._onListClose=()=>{if(!this._pendingSubmit)return;this._pendingSubmit=!1;let e=this.closest(`form.wui-filter-form`);e instanceof HTMLFormElement&&e.requestSubmit()},this._onFocusOut=e=>{this.contains(h(e.relatedTarget))||this._schedule(!1)},this._onKeyDown=e=>{let t=e.target;if(e.key!==`Enter`||!(t instanceof Element)||!this._panel?.contains(t)||!t.matches(d))return;e.preventDefault();let n=this.closest(`form.wui-filter-form`);n instanceof HTMLFormElement&&n.requestSubmit()},this._onShortcut=e=>{this.ownerDocument.querySelector(`wui-filter-popover`)===this&&a(e,{f:()=>this._open(!0,!0)})},this._onEscape=e=>{e.key===`Escape`&&this.isOpen&&this._close(!0)},this._onOutside=e=>{this.isOpen&&!e.composedPath().includes(this)&&this._close(!1)}}get isOpen(){let e=this._panel;return e?!e.hidden:!1}connectedCallback(){this._doc=this.ownerDocument,this.addEventListener(`pointerenter`,this._onEnter),this.addEventListener(`pointerleave`,this._onLeave),this.addEventListener(`click`,this._onClick),this.addEventListener(`change`,this._onChange),this.addEventListener(`focusout`,this._onFocusOut),this.addEventListener(`keydown`,this._onKeyDown),this.addEventListener(`wui-select:close`,this._onListClose),this._doc.addEventListener(`keydown`,this._onShortcut),p()&&this._pin&&(this._pin.checked=!0,this._open(!1,!1))}disconnectedCallback(){this._clear(),this.removeEventListener(`pointerenter`,this._onEnter),this.removeEventListener(`pointerleave`,this._onLeave),this.removeEventListener(`click`,this._onClick),this.removeEventListener(`change`,this._onChange),this.removeEventListener(`focusout`,this._onFocusOut),this.removeEventListener(`keydown`,this._onKeyDown),this.removeEventListener(`wui-select:close`,this._onListClose),this._doc?.removeEventListener(`keydown`,this._onShortcut),this._doc?.removeEventListener(`keydown`,this._onEscape),this._doc?.removeEventListener(`click`,this._onOutside),t(this),this._doc=null}get _trigger(){return g(this,c)}get _panel(){return g(this,l)}get _pin(){let e=this.querySelector(`${u} input[type="checkbox"]`);return e instanceof HTMLInputElement?e:null}get _pinned(){return this._pin?.checked===!0}_clear(){this._timer!==null&&clearTimeout(this._timer),this._timer=null}_schedule(e){if(this._clear(),e){if(this.isOpen)return;this._timer=setTimeout(()=>{this._timer=null,this._open(!1,!1)},150)}else this.isOpen&&!this._stayOpen()&&(this._timer=setTimeout(()=>{this._timer=null,this._stayOpen()||this._close(!1)},400))}_stayOpen(){let e=this._panel;return e?this._pinned||this._inside||e.contains(this.ownerDocument.activeElement)||e.querySelector(`[aria-expanded="true"]`)!==null:!1}_open(t,n){this._clear();let r=this._panel,i=this._trigger;r&&i&&(this.isOpen?t&&(this._sticky=!0):(r.hidden=!1,i.setAttribute(`aria-expanded`,`true`),this._sticky=t,this._reposition(),e(this,()=>{this._triggerOutOfView()?this._close(!1):this._reposition()}),this._doc?.addEventListener(`keydown`,this._onEscape),this._doc?.addEventListener(`click`,this._onOutside)),n&&(g(r.querySelector(`.wui-filter-popover-grid`),f)??g(r,f))?.focus())}_close(e){this._clear();let n=this._panel;if(!n||!this.isOpen)return;let r=n.contains(this.ownerDocument.activeElement);n.hidden=!0,this._trigger?.setAttribute(`aria-expanded`,`false`),this._sticky=!1,t(this),this._doc?.removeEventListener(`keydown`,this._onEscape),this._doc?.removeEventListener(`click`,this._onOutside),e&&r&&this._trigger?.focus()}_reposition(){this.isOpen&&this._trigger&&n(this._trigger,this._panel,{clampHeight:!0,alignEnd:!0})}_triggerOutOfView(){let e=this._trigger;if(!e||!this._doc?.elementFromPoint)return!1;let t=e.getBoundingClientRect();if(!t.width&&!t.height)return!1;let n=this._doc.elementFromPoint(t.left+t.width/2,t.top+t.height/2);return!n||!(e.contains(n)||this._panel?.contains(n))}};function v(){r(`wui-filter-popover`,_)}export{v as n,o as t};
@@ -1 +0,0 @@
1
- import{n as e}from"./devWarn-DXdRWZs3.js";var t=`Recent`,n=5,r=20;function i(){let i,a=null,o=()=>i.getAttribute(`recents-key`)??``,s=()=>i.mode!==`tag`&&o()!==``,c=(t,n)=>{t!==a&&(a=t,e(`<wui-select> recents-limit "${t}" ${n}.`))},l=()=>{let e=i.getAttribute(`recents-limit`);if(e===null)return n;let t=Number(e);return!Number.isInteger(t)||t<1?(c(e,`is not a whole number from 1 to 20; 5 is used`),n):t>r?(c(e,`is over 20; 20 is used`),r):t},u=()=>{let e;try{e=JSON.parse(globalThis.localStorage?.getItem(o())??`[]`)}catch{return[]}return Array.isArray(e)?e.filter(e=>typeof e==`string`):[]},d=e=>{try{globalThis.localStorage?.setItem(o(),JSON.stringify(e))}catch{}};return{mount(t){i=t,i.mode===`tag`?e(`<wui-select> recents-key is not used in mode "tag"; it is ignored.`):o()===``&&e(`<wui-select> recents-key is empty; no recents are kept.`)},onPick(e,t){if(!s()||t?.isCustom)return!1;let n=String(e.value);return n===``||Array.isArray(i.value)&&i.value.includes(n)||d([n,...u().filter(e=>e!==n)].slice(0,l())),!1},recents(e){if(!s())return null;let n=l(),r=[];for(let t of u()){let i=e.find(e=>String(e.value)===t);if(i&&!i.disabled&&r.push(i),r.length===n)break}return r.length?{label:i.getAttribute(`recents-label`)||t,options:r}:null},teardown(){}}}export{i as default};