@webority/ui-elements 0.139.4 → 0.140.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{WuiCodeBlock-vV4v7-c7.js → WuiCodeBlock-CXBYH2Ej.js} +1 -1
- package/dist/WuiCommandPalette-Bk9UuXmZ.js +2 -0
- package/dist/{WuiDatePicker-D6x670lh.js → WuiDatePicker-_h8R3HSU.js} +1 -1
- package/dist/{WuiDateRange-DUkF9FYe.js → WuiDateRange-BtkmxMSN.js} +1 -1
- package/dist/WuiLeadPopup-Dwmg7coE.js +382 -0
- package/dist/{WuiLightbox-CDcqNQun.js → WuiLightbox-DCTE3ULH.js} +1 -1
- package/dist/{WuiPhone-C1t2nZvd.js → WuiPhone-oEkvgH1D.js} +1 -1
- package/dist/{WuiSelect-CrH5CX6K.js → WuiSelect-BEhh06ZD.js} +1 -1
- package/dist/{WuiTimePicker-BcH9_gEm.js → WuiTimePicker-CLS7ahpd.js} +1 -1
- package/dist/{WuiTree-BFm_hpSK.js → WuiTree-BZaGfmr9.js} +1 -1
- package/dist/{WuiWizardStep-BI6ClNdF.js → WuiWizardStep-DB-BbyEO.js} +1 -1
- package/dist/{chips-Bbr0xJXV.js → chips-CjCv74bk.js} +1 -1
- package/dist/{drawerDiscard-DR04quK7.js → drawerDiscard-DBTsXGV8.js} +1 -1
- package/dist/elements/code-block.js +1 -1
- package/dist/elements/command-palette.js +1 -1
- package/dist/elements/date-range.js +1 -1
- package/dist/elements/datepicker.js +1 -1
- package/dist/elements/lead-popup.js +1 -1
- package/dist/elements/lightbox.js +1 -1
- package/dist/elements/phone.js +1 -1
- package/dist/elements/select.js +1 -1
- package/dist/elements/timepicker.js +1 -1
- package/dist/elements/tree.js +1 -1
- package/dist/elements/wizard.js +1 -1
- package/dist/{fileViewerImage-C85kWKJQ.js → fileViewerImage-CLzN49Fd.js} +1 -1
- package/dist/{fileViewerMedia-D_dPdoK1.js → fileViewerMedia-BQ0lVXy9.js} +1 -1
- package/dist/{fileViewerPdf-BWeQ2WJ2.js → fileViewerPdf-6MAAzmCM.js} +1 -1
- package/dist/fileViewerUi-DQH6_B1a.js +1 -0
- package/dist/helpers.js +1 -1
- package/dist/iconGlyphs.g-BlwTSNXS.js +1 -0
- package/dist/{optionLabel-CjrUbe2a.js → optionLabel-CLemms21.js} +1 -1
- package/dist/{search-BWWjNvZu.js → search-rosjW6Tp.js} +1 -1
- package/dist/server.js +1 -1
- package/dist/ui-elements/carousel.global.js +1 -1
- package/dist/ui-elements/code-block.global.js +1 -1
- package/dist/ui-elements/command-palette.global.js +2 -2
- package/dist/ui-elements/comment-thread.global.js +1 -1
- package/dist/ui-elements/consent-banner.global.js +1 -1
- package/dist/ui-elements/context-menu.global.js +1 -1
- package/dist/ui-elements/date-range.global.js +1 -1
- package/dist/ui-elements/drawer.global.js +1 -1
- package/dist/ui-elements/image-crop.global.js +1 -1
- package/dist/ui-elements/inline-edit.global.js +1 -1
- package/dist/ui-elements/kanban.global.js +1 -1
- package/dist/ui-elements/lead-popup.global.js +89 -13
- package/dist/ui-elements/lightbox.global.js +1 -1
- package/dist/ui-elements/markdown.global.js +1 -1
- package/dist/ui-elements/org-tree.global.js +1 -1
- package/dist/ui-elements/phone.global.js +1 -1
- package/dist/ui-elements/resizable.global.js +1 -1
- package/dist/ui-elements/saved-views.global.js +1 -1
- package/dist/ui-elements/select-chips.global.js +1 -1
- package/dist/ui-elements/select-search.global.js +1 -1
- package/dist/ui-elements/slider.global.js +1 -1
- package/dist/ui-elements/sortable.global.js +1 -1
- package/dist/ui-elements/status-icon.global.js +1 -1
- package/dist/ui-elements/timepicker.global.js +1 -1
- package/dist/ui-elements/tour.global.js +1 -1
- package/dist/ui-elements/tree.global.js +1 -1
- package/dist/ui-elements/wizard.global.js +1 -1
- package/dist/ui-elements.global.js +3 -3
- package/dist/ui-elements.js +1 -1
- package/dist/ui-file-viewer.global.js +1 -1
- package/dist/ui-file-viewer.js +1 -1
- package/dist/ui-lead-popup.global.js +1 -1
- package/package.json +3 -2
- package/dist/WuiCommandPalette-CtF31Bbo.js +0 -2
- package/dist/WuiLeadPopup-CWv93qlo.js +0 -306
- package/dist/fileViewerUi-7v_4Oz8G.js +0 -1
- package/dist/iconGlyphs.g-gURMSeyB.js +0 -1
package/dist/ui-file-viewer.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{i as e,o as t,r as n,t as r}from"./fileViewerUi-
|
|
1
|
+
import{i as e,o as t,r as n,t as r}from"./fileViewerUi-DQH6_B1a.js";var i=`AppButton`,a={primary:`btn-primary`,soft:`btn-soft-primary`,outline:`btn-outline-primary`,ghost:`btn-ghost-primary`,text:`btn-link-primary`,danger:`btn-danger`,success:`btn-success`,"outline-danger":`btn-outline-danger`,light:`btn-neutral`,warning:`btn-warning`,neutral:`btn-soft-neutral`,"outline-light":`btn-glass`,"outline-secondary":`btn-outline-neutral`};function o(e=`primary`,t=`md`){let n=a[e];if(!n)throw Error(`buttonClass: unknown variant "${e}"`);return t===`md`?`btn ${n}`:`btn ${n} btn-${t}`}var s=typeof HTMLElement>`u`?class{}:HTMLElement,c={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`},l={"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`},u=`wui-file-viewer:load`,d=`wui-file-viewer:error`,f=`wui-file-viewer:prefs-change`;function p(e,t){let n=String(e??``).split(`;`)[0].trim().toLowerCase();if(n)return l[n]??null;let r=String(t??``).split(/[?#]/)[0];return c[r.includes(`.`)?r.split(`.`).pop().toLowerCase():``]??null}function m(e){let t=String(e??``).split(/[?#]/)[0].split(`/`).filter(Boolean).pop()??``;try{return decodeURIComponent(t)}catch{return t}}var h={pdf:()=>import(`./fileViewerPdf-6MAAzmCM.js`).then(e=>e.PdfView),image:()=>import(`./fileViewerImage-CLzN49Fd.js`).then(e=>e.ImageView),video:()=>import(`./fileViewerMedia-BQ0lVXy9.js`).then(e=>e.MediaView),audio:()=>import(`./fileViewerMedia-BQ0lVXy9.js`).then(e=>e.MediaView)},g=0,_=class a extends s{static defaultAssetBase=``;static get observedAttributes(){return[`src`,`name`,`type`,`download`,`print`,`worker-src`,`asset-base`,`captions`]}constructor(){super(),g+=1,this.uid=`wui-file-viewer-${g}`,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||m(this.src)||`Document`}connectedCallback(){if(Object.hasOwn(this,`prefs`)){let e=this.prefs;delete this.prefs,this.prefs=e}document.addEventListener(`fullscreenchange`,this._onFullscreen),this._open()}disconnectedCallback(){document.removeEventListener(`fullscreenchange`,this._onFullscreen),this._close()}attributeChangedCallback(e,t,n){this.isConnected&&this._parts&&t!==n&&(e===`name`?this._parts.name.textContent=this.displayName():e===`download`?this._syncDownload():e===`print`?this._syncPrint():this._open())}_close(){this._view?.destroy(),this._view=null,this._loadId=(this._loadId??0)+1}async _open(){this._close();let e=this._loadId;this._render(),this._prefs=this._readPrefs();let t=p(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 h[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:v(this.assetBase||a.defaultAssetBase)}),this._view.load())}_shell(e){let t=()=>e===this._loadId,n=this._parts;return{host:this,start:n.start,center:n.center,end:n.viewEnd,search:n.search,body:n.body,prefs:{...this._prefs},name:()=>this.displayName(),print:()=>this.print,savePrefs:e=>{t()&&this._savePrefs(e)},loaded:e=>{t()&&(n.body.removeAttribute(`aria-busy`),this.dispatchEvent(new CustomEvent(u,{bubbles:!0,detail:e})))},fail:e=>{t()&&this._fail(e)}}}_render(){let t=(e,t)=>{let n=document.createElement(e);return n.className=t,n},i=t(`div`,`wui-file-viewer-toolbar`),a=t(`div`,`wui-file-viewer-group wui-file-viewer-start`),o=t(`span`,`wui-file-viewer-name`);o.textContent=this.displayName(),o.title=this.displayName(),a.append(o);let s=t(`div`,`wui-file-viewer-group wui-file-viewer-center`),c=t(`div`,`wui-file-viewer-group wui-file-viewer-end`),l=t(`div`,`wui-file-viewer-group wui-file-viewer-view-end`),u=t(`a`,`u-action wui-file-viewer-download`);u.style.setProperty(`--wui-action-size`,`32px`),n(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??=t(`div`,`wui-file-viewer-actions`);let f=this._actionsBox;f.append(...this.querySelectorAll(`:scope > [slot="actions"]`)),c.append(l,u,d,f);let p=t(`search`,`wui-file-viewer-search`);p.hidden=!0,i.append(a,s,c,p);let m=t(`div`,`wui-file-viewer-body`);m.setAttribute(`aria-busy`,`true`),this.replaceChildren(i,m),this._parts={toolbar:i,start:a,name:o,center:s,end:c,viewEnd:l,downloadLink:u,fullscreen:d,actionsBox:f,search:p,body:m},this._syncDownload(),this._syncFullscreen()}_syncDownload(){let e=this._parts.downloadLink;e.hidden=!this.download||!this.src,e.href=this.src,e.setAttribute(`download`,this.displayName())}_syncPrint(){for(let e of this._parts.toolbar.querySelectorAll(`.wui-file-viewer-print`))e.hidden=!this.print}_status(e,{offerDownload:t=!1}={}){let n=document.createElement(`div`);n.className=`wui-file-viewer-status`;let r=document.createElement(`p`);if(r.textContent=e,n.append(r),t&&this.src){let e=document.createElement(`a`);e.className=o(`outline-secondary`,`sm`),e.dataset.wui=i,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}),this.dispatchEvent(new CustomEvent(d,{bubbles:!0,detail:{message:e?.message??String(e)}}))}toggleFullscreen(){document.fullscreenElement?document.exitFullscreen():this.requestFullscreen().catch(e=>{t(`[wui-file-viewer] full screen refused:`,e?.message)})}_syncFullscreen(){if(!this._parts)return;let t=document.fullscreenElement===this,r=this._parts.fullscreen;n(r,t?`x`:`maximize-4`),e(r,t?`Exit full screen`:`Full screen`),this._parts.actionsBox.hidden=t}_readPrefs(){if(this._hostPrefs||!this.viewKey)return{...this._prefs};try{return JSON.parse(window.localStorage.getItem(`wui-view:${this.viewKey}`)??`{}`)??{}}catch{return{}}}_savePrefs(e){if(this._prefs={...this._prefs,...e},this.dispatchEvent(new CustomEvent(f,{bubbles:!0,detail:{...this._prefs}})),!this._hostPrefs&&this.viewKey)try{window.localStorage.setItem(`wui-view:${this.viewKey}`,JSON.stringify(this._prefs))}catch{}}};function v(e){return e&&new URL(e,document.baseURI).href}var y=typeof document>`u`?null:document.currentScript;y?.src&&(_.defaultAssetBase=new URL(`pdfjs/`,y.src).href),typeof customElements<`u`&&!customElements.get(`wui-file-viewer`)&&customElements.define(`wui-file-viewer`,_);var b=(e,t)=>import(`./fileViewerPdf-6MAAzmCM.js`).then(n=>n.renderFirstPage(e,{assetBase:_.defaultAssetBase||void 0,...t}));export{_ as WuiFileViewer,p as fileKind,m as fileNameFromUrl,b as renderPdfFirstPage};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(){function e(e,...t){console.warn(e,...t)}var t=typeof HTMLElement>`u`?class{}:HTMLElement,n={"--color-primary":`#4F46E5`,"--color-primary-hover":`#4338CA`,"--color-on-primary":`#FFFFFF`,"--color-text":`#071437`,"--color-text-muted":`#4B5675`,"--color-border":`#EBEDF3`,"--color-surface":`#FFFFFF`,"--wui-radius-lg":`14px`,"--wui-shadow-modal":`0px 24px 60px -16px rgba(7, 20, 55, 0.28)`,"--wui-z-modal":`1505`},r=e=>`var(${e}, ${n[e]})`,i=` :host { all: initial; display: contents; font-family: inherit; font-size: 16px; line-height: 1.5; color: ${r(`--color-text`)}; } *, *::before, *::after { box-sizing: border-box; } [hidden] { display: none !important; } dialog { z-index: ${r(`--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: ${r(`--color-surface`)}; color: ${r(`--color-text`)}; border: 1px solid ${r(`--color-border`)}; border-radius: ${r(`--wui-radius-lg`)}; box-shadow: ${r(`--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: ${r(`--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 ${r(`--color-primary`)}; outline-offset: 2px; } .wlp-heading { margin: 0 32px 8px 0; font-size: 20px; font-weight: 600; line-height: 1.3; color: ${r(`--color-text`)}; } .wlp-description { margin: 0 0 16px; font-size: 14px; color: ${r(`--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: ${r(`--color-text`)}; } .wlp-req { margin-inline-start: 2px; color: ${r(`--color-primary`)}; } .wlp-input { width: 100%; padding: 9px 12px; border: 1px solid ${r(`--color-border`)}; border-radius: 8px; background: ${r(`--color-surface`)}; color: ${r(`--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); } .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 ${r(`--color-primary`)}; border-radius: 8px; background: ${r(`--color-primary`)}; color: ${r(`--color-on-primary`)}; font: inherit; font-size: 15px; font-weight: 500; cursor: pointer; } .wlp-button:hover { background: ${r(`--color-primary-hover`)}; border-color: ${r(`--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: ${r(`--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: ${r(`--color-text-muted`)}; } .wlp-secondary-row::before, .wlp-secondary-row::after { content: ""; flex: 1; height: 1px; background: ${r(`--color-border`)}; } .wlp-secondary { display: block; margin-top: 10px; text-align: center; color: ${r(`--color-primary`)}; font-weight: 500; } .wlp-success-title { margin: 0 32px 8px 0; font-size: 20px; font-weight: 600; color: ${r(`--color-text`)}; } .wlp-success-text { margin: 0 0 16px; color: ${r(`--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; } } `,a=[`name`,`email`,`phone`,`company`,`message`],o=[`name`,`email`],s={name:`Name`,email:`Email`,phone:`Phone number`,company:`Company`,message:`Message`},c={name:100,email:320,phone:40,company:150,message:1e3},l={name:`name`,email:`email`,phone:`tel`,company:`organization`},u=`input:not([type=hidden]), textarea, select, button, a[href]`,d=[`exit`,`delay`,`scroll`,`pages`],f=/^[^\s@]+@[^\s@]+\.[^\s@]+$/,p=864e5,m=`comment_subject`,h=`__RequestVerificationToken`,g=`__FormStamp`,_=`__CaptchaToken`,v=`Something went wrong. Please try again or contact us directly.`,y=`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.triggers.delay-seconds.scroll-percent.pages-viewed.storage-key.dismiss-days.submitted-days.success-close-seconds.preview`.split(`.`),b=new Set;function x(t,n){b.has(t)||(b.add(t),e(n))}var S=0;function C(e){return(e??``).split(/\s+/).map(e=>e.trim()).filter(Boolean)}function w(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 T(e){return String(e??``).replace(/&/g,`&`).replace(/</g,`<`).replace(/>/g,`>`).replace(/"/g,`"`)}var E=null;function D(e){E||(E=new CSSStyleSheet,E.replaceSync(i)),e.adoptedStyleSheets=[E]}function O(e,t){return e instanceof Error&&e.message?e.message:t}var k=class extends t{static get observedAttributes(){return y}constructor(){super(),S+=1,this._uid=`wlp-${S}`,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`){this._open||e!==`manual`&&(this._opened||this._blocked()||document.querySelector(`dialog[open], .modal.show`))||(this._rendered||this._render(),this._opened=!0,this._open=!0,clearTimeout(this._delayTimer),this._showForm(),this._modal=!this.preview,this._modal?(this._returnTo=document.activeElement,this._prevOverflow=document.documentElement.style.overflow,document.documentElement.style.overflow=`hidden`,this._dialog().showModal(),this._dialog().querySelector(`[data-wlp-field] [data-wlp-input]`)?.focus()):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),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 this._root().querySelector(`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=C(this.getAttribute(`fields`)).filter(e=>a.includes(e)?!0:(x(`field:${e}`,`[@webority/ui-elements] <wui-lead-popup> has no field "${e}". It is ignored.`),!1));return e.length?e:o}_requiredKeys(){let e=this._fieldKeys();return C(this.getAttribute(`required`)).filter(t=>e.includes(t))}_label(e){return w(this.getAttribute(`labels`))[e]||s[e]}_postedName(e){return this._text(`field-prefix`)+(w(this.getAttribute(`field-names`))[e]||e)}_maxLength(e){let t=Number(w(this.getAttribute(`max-lengths`))[e]);return Number.isInteger(t)&&t>0?t:c[e]}_triggers(){if(this.preview)return[];let e=(this.getAttribute(`triggers`)??``).split(/\s+/).filter(e=>d.includes(e));return e.length?this.getAttribute(`storage-key`)?e:(x(`storage-key`,`[@webority/ui-elements] <wui-lead-popup> has triggers but no storage-key. The triggers are off.`),[]):[]}_render(){let e=this._root();D(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="${T(this._text(`close-label`,`Close`))}" data-wlp-close>×</button> <div class="wlp-form-view"> <h2 class="wlp-heading" id="${t}-h">${T(i)}</h2> ${a?`<p class="wlp-description" id="${t}-d">${T(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>${T(this._text(`submit-label`,`Send`))}</button> </div> <input type="text" name="${m}" 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>${T(this._text(`secondary-divider`,`or`))}</span></div><a class="wlp-secondary" href="${T(s)}" data-wlp-secondary>${T(o)}</a>`:``} </div> <div class="wlp-success-view" hidden> <h2 class="wlp-success-title" role="status" tabindex="-1" data-wlp-success-title>${T(this._text(`success-title`,`Thank you`))}</h2> ${this._text(`success-text`)?`<p class="wlp-success-text">${T(this._text(`success-text`))}</p>`:``} <button type="button" class="wlp-button" data-wlp-done>${T(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=T(this._postedName(e)),o=this._maxLength(e),s=t?`<span class="wlp-req" aria-hidden="true">*</span><span class="wlp-visually-hidden">required</span>`:``,c=`id="${n}" data-wlp-input="${e}" name="${a}" maxlength="${o}"${t?` aria-required="true"`:``}`,u=e===`message`?`<textarea class="wlp-input" rows="4" ${c}></textarea>`:`<input class="wlp-input" type="${e===`email`?`email`:e===`phone`?`tel`:`text`}" ${c}${l[e]?` autocomplete="${l[e]}"`:``}>`;return` <div class="wlp-field" data-wlp-field="${e}"> <label class="wlp-label" for="${n}">${T(i)}${s}</label> ${u} <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(u)).filter(e=>!e.disabled&&e.getClientRects().length>0);if(!n.length)return;let r=n.indexOf(this._root().activeElement);t.preventDefault(),n[r===-1?t.shiftKey?n.length-1:0:(r+(t.shiftKey?-1:1)+n.length)%n.length].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`)),e.querySelector(`[data-wlp-form]`).addEventListener(`submit`,e=>this._onSubmit(e))}_showForm(){let e=this._root();e.querySelector(`.wlp-form-view`).hidden=!1,e.querySelector(`.wlp-success-view`).hidden=!0}_showSuccess(){let e=this._root();e.querySelector(`.wlp-form-view`).hidden=!0;let t=e.querySelector(`.wlp-success-view`);t.hidden=!1,e.querySelector(`[data-wlp-success-title]`).focus()}_setFieldError(e,t){let n=this._root(),r=n.querySelector(`[data-wlp-input="${e}"]`),i=n.querySelector(`#${this._uid}-e-${e}`);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}"]`).value.trim();n[r]=i;let a=``;!i&&e.has(r)?a=`Enter your ${this._label(r).toLowerCase()}`:r===`email`&&i&&!f.test(i)&&(a=`Enter a valid email address`);let o=this._setFieldError(r,a);a&&!t&&(t=o)}return t?(t.focus(),null):n}_setBusy(e){this._posting=e;let t=this._root().querySelector(`[data-wlp-form]`);e?t.setAttribute(`aria-busy`,`true`):t.removeAttribute(`aria-busy`),this._root().querySelector(`[data-wlp-submit]`).disabled=e}_fail(e,t){this._setBusy(!1);let n=this._root().querySelector(`[data-wlp-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;this._root().querySelector(`[data-wlp-form-error]`).hidden=!0;let t=this._validate();t&&!this.preview&&await this._post(t)}async _post(e){let t=globalThis.WeborityPublicForms;if(!t){x(`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`,v));return}let n=this._text(`error-text`,v),r=this._text(`public-form`);this._setBusy(!0);let i,a;try{i=await t.session(),a=await t.mintToken(r)}catch(e){this._fail(`gate`,O(e,n));return}let o=this._root(),s=new FormData;for(let t of this._fieldKeys())s.append(this._postedName(t),e[t]);s.set(h,i.token),s.set(g,i.formStamp),s.set(_,a),s.set(m,o.querySelector(`[data-wlp-honeypot]`).value),this._emit(`wui-lead-popup-before-submit`,{formData:s});let c;try{c=await fetch(this._text(`action`),{method:`POST`,body:s,credentials:`same-origin`,headers:{"X-Requested-With":`XMLHttpRequest`}})}catch{this._fail(`network`,n);return}if(!c.ok){let e=await c.json().catch(()=>null),t=typeof e?.detail==`string`?e.detail.trim():``;this._fail(`server`,t||n);return}let l=await c.json().catch(()=>null);this._succeed(e,l)}_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),clearTimeout(this._closeTimer),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*p}_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{}}};typeof customElements<`u`&&!customElements.get(`wui-lead-popup`)&&customElements.define(`wui-lead-popup`,k)})();
|
|
1
|
+
(function(){function e(e,...t){console.warn(e,...t)}var t=typeof HTMLElement>`u`?class{}:HTMLElement,n={"--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`},r=e=>`var(${e}, ${n[e]})`,i=` :host { all: initial; display: contents; font-family: inherit; font-size: 16px; line-height: 1.5; color: ${r(`--color-text`)}; } *, *::before, *::after { box-sizing: border-box; } [hidden] { display: none !important; } dialog { z-index: ${r(`--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: ${r(`--color-surface`)}; color: ${r(`--color-text`)}; border: 1px solid ${r(`--color-border`)}; border-radius: ${r(`--wui-radius-lg`)}; box-shadow: ${r(`--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: ${r(`--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 ${r(`--color-primary`)}; outline-offset: 2px; } .wlp-heading { margin: 0 32px 8px 0; font-size: 20px; font-weight: 600; line-height: 1.3; color: ${r(`--color-text`)}; } .wlp-description { margin: 0 0 16px; font-size: 14px; color: ${r(`--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: ${r(`--color-text`)}; } .wlp-req { margin-inline-start: 2px; color: ${r(`--color-primary`)}; } .wlp-input { width: 100%; padding: 9px 12px; border: 1px solid ${r(`--color-border`)}; border-radius: 8px; background: ${r(`--color-surface`)}; color: ${r(`--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: ${r(`--color-text`)}; } .form-check-input { flex: none; width: 20px; height: 20px; margin: 0; appearance: none; -webkit-appearance: none; border: 1.6px solid ${r(`--color-border-strong`)}; border-radius: ${r(`--wui-radius-sm`)}; corner-shape: squircle; background-color: ${r(`--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: ${r(`--color-primary`)}; box-shadow: 0 0 0 2px ${r(`--color-primary-soft`)}; } .form-check-input:checked { border-color: ${r(`--color-primary`)}; background-color: ${r(`--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 ${r(`--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: ${r(`--color-primary-text`)}; font-weight: 500; text-decoration: underline; text-underline-offset: 3px; } .wlp-consent-link:focus-visible { outline: 2px solid ${r(`--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 ${r(`--color-primary`)}; border-radius: 8px; background: ${r(`--color-primary`)}; color: ${r(`--color-on-primary`)}; font: inherit; font-size: 15px; font-weight: 500; cursor: pointer; } .wlp-button:hover { background: ${r(`--color-primary-hover`)}; border-color: ${r(`--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: ${r(`--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: ${r(`--color-text-muted`)}; } .wlp-secondary-row::before, .wlp-secondary-row::after { content: ""; flex: 1; height: 1px; background: ${r(`--color-border`)}; } .wlp-secondary { display: block; margin-top: 10px; text-align: center; color: ${r(`--color-primary`)}; font-weight: 500; } .wlp-success-title { margin: 0 32px 8px 0; font-size: 20px; font-weight: 600; color: ${r(`--color-text`)}; } .wlp-success-text { margin: 0 0 16px; color: ${r(`--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; } } `,a=[`name`,`email`,`phone`,`company`,`message`,`consent`],o=[`name`,`email`],s={name:`Name`,email:`Email`,phone:`Phone number`,company:`Company`,message:`Message`,consent:`I agree to be contacted about my enquiry`,consentLink:`Privacy policy`},c={name:100,email:320,phone:40,company:150,message:1e3},l={name:`name`,email:`email`,phone:`tel`,company:`organization`},u=`input:not([type=hidden]), textarea, select, button, a[href]`,d=[`exit`,`delay`,`scroll`,`pages`],f=/^[^\s@]+@[^\s@]+\.[^\s@]+$/,p=864e5,m=`comment_subject`,h=`__RequestVerificationToken`,g=`__FormStamp`,_=`__CaptchaToken`,v=`Something went wrong. Please try again or contact us directly.`,y=`Tick the box to continue`,b=`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(`.`),x=new Set;function S(t,n){x.has(t)||(x.add(t),e(n))}var C=0;function w(e){return(e??``).split(/\s+/).map(e=>e.trim()).filter(Boolean)}function T(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 E(e){return String(e??``).replace(/&/g,`&`).replace(/</g,`<`).replace(/>/g,`>`).replace(/"/g,`"`)}var D=null;function O(e){D||(D=new CSSStyleSheet,D.replaceSync(i)),e.adoptedStyleSheets=[D]}function k(e,t){return e instanceof Error&&e.message?e.message:t}var A=class extends t{static get observedAttributes(){return b}constructor(){super(),C+=1,this._uid=`wlp-${C}`,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`){this._open||e!==`manual`&&(this._opened||this._blocked()||document.querySelector(`dialog[open], .modal.show`))||(this._rendered||this._render(),this._opened=!0,this._open=!0,clearTimeout(this._delayTimer),this._showForm(),this._modal=!this.preview,this._modal?(this._returnTo=document.activeElement,this._prevOverflow=document.documentElement.style.overflow,document.documentElement.style.overflow=`hidden`,this._dialog().showModal(),this._dialog().querySelector(`[data-wlp-field] [data-wlp-input]`)?.focus()):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),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 this._root().querySelector(`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=w(this.getAttribute(`fields`)).filter(e=>a.includes(e)?!0:(S(`field:${e}`,`[@webority/ui-elements] <wui-lead-popup> has no field "${e}". It is ignored.`),!1));return e.length?e:o}_requiredKeys(){let e=this._fieldKeys();return w(this.getAttribute(`required`)).filter(t=>e.includes(t))}_label(e){return T(this.getAttribute(`labels`))[e]||s[e]}_postedName(e){return this._text(`field-prefix`)+(T(this.getAttribute(`field-names`))[e]||e)}_maxLength(e){let t=Number(T(this.getAttribute(`max-lengths`))[e]);return Number.isInteger(t)&&t>0?t:c[e]}_triggers(){if(this.preview)return[];let e=(this.getAttribute(`triggers`)??``).split(/\s+/).filter(e=>d.includes(e));return e.length?this.getAttribute(`storage-key`)?e:(S(`storage-key`,`[@webority/ui-elements] <wui-lead-popup> has triggers but no storage-key. The triggers are off.`),[]):[]}_render(){let e=this._root();O(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="${E(this._text(`close-label`,`Close`))}" data-wlp-close>×</button> <div class="wlp-form-view"> <h2 class="wlp-heading" id="${t}-h">${E(i)}</h2> ${a?`<p class="wlp-description" id="${t}-d">${E(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>${E(this._text(`submit-label`,`Send`))}</button> </div> <input type="text" name="${m}" 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>${E(this._text(`secondary-divider`,`or`))}</span></div><a class="wlp-secondary" href="${E(s)}" data-wlp-secondary>${E(o)}</a>`:``} </div> <div class="wlp-success-view" hidden> <h2 class="wlp-success-title" role="status" tabindex="-1" data-wlp-success-title>${E(this._text(`success-title`,`Thank you`))}</h2> ${this._text(`success-text`)?`<p class="wlp-success-text">${E(this._text(`success-text`))}</p>`:``} <button type="button" class="wlp-button" data-wlp-done>${E(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=E(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="${E(t)}">${E(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}">${E(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}`,u=e===`message`?`<textarea class="wlp-input" rows="4" ${c}></textarea>`:`<input class="wlp-input" type="${e===`email`?`email`:e===`phone`?`tel`:`text`}" ${c}${l[e]?` autocomplete="${l[e]}"`:``}>`;return` <div class="wlp-field" data-wlp-field="${e}"> <label class="wlp-label" for="${n}">${E(i)}${o}</label> ${u} <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(u)).filter(e=>!e.disabled&&e.getClientRects().length>0);if(!n.length)return;let r=n.indexOf(this._root().activeElement);t.preventDefault(),n[r===-1?t.shiftKey?n.length-1:0:(r+(t.shiftKey?-1:1)+n.length)%n.length].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`)),e.querySelector(`[data-wlp-form]`).addEventListener(`submit`,e=>this._onSubmit(e))}_showForm(){let e=this._root();e.querySelector(`.wlp-form-view`).hidden=!1,e.querySelector(`.wlp-success-view`).hidden=!0}_showSuccess(){let e=this._root();e.querySelector(`.wlp-form-view`).hidden=!0;let t=e.querySelector(`.wlp-success-view`);t.hidden=!1,e.querySelector(`[data-wlp-success-title]`).focus()}_setFieldError(e,t){let n=this._root(),r=n.querySelector(`[data-wlp-input="${e}"]`),i=n.querySelector(`#${this._uid}-e-${e}`);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}"]`),a=r===`consent`?i.checked:i.value.trim();n[r]=a;let o=``;!a&&e.has(r)?o=r===`consent`?y:`Enter your ${this._label(r).toLowerCase()}`:r===`email`&&a&&!f.test(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=this._root().querySelector(`[data-wlp-form]`);e?t.setAttribute(`aria-busy`,`true`):t.removeAttribute(`aria-busy`),this._root().querySelector(`[data-wlp-submit]`).disabled=e}_fail(e,t){this._setBusy(!1);let n=this._root().querySelector(`[data-wlp-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;this._root().querySelector(`[data-wlp-form-error]`).hidden=!0;let t=this._validate();t&&!this.preview&&await this._post(t)}async _post(e){let t=globalThis.WeborityPublicForms;if(!t){S(`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`,v));return}let n=this._text(`error-text`,v),r=this._text(`public-form`);this._setBusy(!0);let i,a;try{i=await t.session(),a=await t.mintToken(r)}catch(e){this._fail(`gate`,k(e,n));return}let o=this._root(),s=new FormData;for(let t of this._fieldKeys())s.append(this._postedName(t),e[t]);s.set(h,i.token),s.set(g,i.formStamp),s.set(_,a),s.set(m,o.querySelector(`[data-wlp-honeypot]`).value),this._emit(`wui-lead-popup-before-submit`,{formData:s});let c;try{c=await fetch(this._text(`action`),{method:`POST`,body:s,credentials:`same-origin`,headers:{"X-Requested-With":`XMLHttpRequest`}})}catch{this._fail(`network`,n);return}if(!c.ok){let e=await c.json().catch(()=>null),t=typeof e?.detail==`string`?e.detail.trim():``;this._fail(`server`,t||n);return}let l=await c.json().catch(()=>null);this._succeed(e,l)}_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),clearTimeout(this._closeTimer),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*p}_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{}}};typeof customElements<`u`&&!customElements.get(`wui-lead-popup`)&&customElements.define(`wui-lead-popup`,A)})();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webority/ui-elements",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.140.1",
|
|
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",
|
|
@@ -99,7 +99,8 @@
|
|
|
99
99
|
"@tiptap/markdown": "3.31.4",
|
|
100
100
|
"@tiptap/starter-kit": "3.31.4",
|
|
101
101
|
"@vitest/coverage-v8": "5.0.1",
|
|
102
|
-
"@webority/markdown-core": "0.
|
|
102
|
+
"@webority/markdown-core": "0.140.1",
|
|
103
|
+
"@webority/theme": "0.140.1",
|
|
103
104
|
"echarts": "6.1.0",
|
|
104
105
|
"jsdom": "30.1.1",
|
|
105
106
|
"libphonenumber-js": "^1.13.9",
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
import{t as e}from"./elementBase-DV9IZZCu.js";import{n as t}from"./optionLabel-CjrUbe2a.js";import{t as n}from"./textMatch-wdY7XLIc.js";var r=`[role="option"]`,i=`No results`,a=`All`,o=`Recent`,s=5,c=20,l=`.wui-cmd-back, [data-depth]`,u=0,d=class extends e{static get observedAttributes(){return[`filter`,`highlight`,`empty-text`,`path`,`root-label`,`recents-key`,`recents-limit`,`recents-label`]}constructor(){super(),this._path=[],this._crumbSig=null,this._modal=null,this._recentsId=`wui-cmd-recents-${++u}`,this._onModalHidden=()=>this._reset(),this._activeId=null,this._lastQuery=null,this._lastIds=null,this._userChose=!1,this._onKeyDown=e=>this._handleKeyDown(e),this._onClick=e=>{let t=e.target?.closest?.(l);if(t&&this.contains(t)){let e=t.matches(`.wui-cmd-back`)?this._path.length-1:Number(t.dataset.depth);this._goTo(this._path.slice(0,e));return}let n=this._optionFrom(e.target);n&&this._select(n)},this._onMouseDown=e=>{let t=e.target?.closest?.(l);(t&&this.contains(t)||this._optionFrom(e.target,!0))&&e.preventDefault()},this._onMouseMove=e=>{let t=this._optionFrom(e.target);t&&t.id!==this._activeId&&(this._userChose=!0,this._setActive(t,!1))},this._onInput=e=>{this.hasAttribute(`filter`)&&e.target===this._input()&&(this._applyFilter(),this.refresh())}}connectedCallback(){this._teardown(),this.addEventListener(`keydown`,this._onKeyDown),this.addEventListener(`click`,this._onClick),this.addEventListener(`mousedown`,this._onMouseDown),this.addEventListener(`mousemove`,this._onMouseMove),this.addEventListener(`input`,this._onInput),this._modal=this.closest(`.modal`),this._modal?.addEventListener(`hidden.bs.modal`,this._onModalHidden),this._readPath(),this.hasAttribute(`filter`)&&this._applyFilter(),this.refresh()}disconnectedCallback(){this._teardown()}attributeChangedCallback(e){this.isConnected&&(e===`path`&&this._readPath(),this.hasAttribute(`filter`)&&this._applyFilter(),this.refresh())}get filter(){return this.hasAttribute(`filter`)}set filter(e){this.toggleAttribute(`filter`,!!e)}get highlight(){return this.getAttribute(`highlight`)!==`false`}set highlight(e){this.setAttribute(`highlight`,e?`true`:`false`)}get emptyText(){return this.getAttribute(`empty-text`)??i}set emptyText(e){this.setAttribute(`empty-text`,String(e??``))}refresh(){this._renderRecents(),this._renderCrumbs();let e=this._input(),t=e?e.value:``,n=t!==this._lastQuery;this._lastQuery=t;let r=this._selectableOptions(),i=r.map(e=>e.id).join(`
|
|
2
|
-
`),a=i!==this._lastIds;this._lastIds=i;let o=!n&&(this._userChose||!a)?r.find(e=>e.id===this._activeId):null;o||(this._userChose=!1),this._setActive(o??r[0]??null,n)}_input(){return this.querySelector(`[role="combobox"]`)}_optionFrom(e,t=!1){let n=e?.closest?.(r);return n&&this.contains(n)&&!this._isHidden(n)&&(t||!this._isDisabled(n))?n:null}_isDisabled(e){return e.getAttribute(`aria-disabled`)===`true`}_isHidden(e){return e.hidden||!!e.closest(`[role="group"]`)?.hidden}_selectableOptions(){return[...this.querySelectorAll(r)].filter(e=>!this._isHidden(e)&&!this._isDisabled(e))}_setActive(e,t){this._activeId=e?e.id:null;for(let t of this.querySelectorAll(r))t.setAttribute(`aria-selected`,t===e?`true`:`false`);let n=this._input();n&&(e?n.setAttribute(`aria-activedescendant`,e.id):n.removeAttribute(`aria-activedescendant`)),e&&t&&e.scrollIntoView({block:`nearest`})}_move(e){let t=this._selectableOptions();if(!t.length)return;let n=t.findIndex(e=>e.id===this._activeId),r=n<0?e>0?0:t.length-1:(n+e+t.length)%t.length;this._userChose=!0,this._setActive(t[r],!0)}_handleKeyDown(e){if(e.target===this._input()){if(e.key===`ArrowDown`||e.key===`ArrowUp`)e.preventDefault(),this._move(e.key===`ArrowDown`?1:-1);else if(e.key===`Backspace`&&!e.isComposing&&this._path.length&&!e.target.value)e.preventDefault(),this._goTo(this._path.slice(0,-1));else if(e.key===`Enter`&&!e.isComposing){let t=this._selectableOptions().find(e=>e.id===this._activeId);if(!t)return;e.preventDefault(),this._select(t)}}}_select(e){this._remember(e),this.dispatchEvent(new CustomEvent(`wui-command-palette:select`,{bubbles:!0,cancelable:!0,detail:{key:e.dataset.key??null,groupKey:e.dataset.groupKey??null,id:e.id}}))&&(e.dataset.opens?this._open(e.dataset.opens):e.dataset.href&&this._navigate(e.dataset.href))}_open(e){let t=[...this.querySelectorAll(`.wui-cmd-page`)].find(t=>t.dataset.page===e);this._goTo([...this._path,{key:e,label:t?.dataset.label??e}])}_goTo(e){this._input()?.focus(),this.dispatchEvent(new CustomEvent(`wui-command-palette:navigate`,{bubbles:!0,cancelable:!0,detail:{path:e}}))&&(this._path=e,this._restart())}_restart(){let e=this._input();e&&(e.value=``),this.hasAttribute(`filter`)&&this._applyFilter(),this.refresh()}_reset(){this.hasAttribute(`path`)||(this._path=[],this._restart())}_readPath(){let e=this.getAttribute(`path`);if(e==null)return;let t=JSON.parse(e);this._path=Array.isArray(t)?t.filter(e=>e&&typeof e.key==`string`&&typeof e.label==`string`):[]}_renderCrumbs(){let e=this.querySelector(`.wui-cmd-crumbs`);if(!e)return;let t=this.getAttribute(`root-label`)??a,n=JSON.stringify([t,this._path]);if(e.hidden=this._path.length===0,n===this._crumbSig)return;this._crumbSig=n;let r=e.querySelector(`.wui-cmd-trail`);if(!r)return;let i=[t,...this._path.map(e=>e.label)];r.replaceChildren(...i.map((e,t)=>{let n=document.createElement(`li`),r=t===i.length-1,a=document.createElement(r?`span`:`button`);return a.className=`wui-cmd-crumb`,a.textContent=e,r?a.setAttribute(`aria-current`,`page`):(a.type=`button`,a.dataset.depth=String(t)),n.append(a),n}))}_recentsHost(){return this.querySelector(`.wui-cmd-recents`)}_realOptions(){let e=this._recentsHost();return[...this.querySelectorAll(r)].filter(t=>!e?.contains(t))}_recentEntries(){let e=this.getAttribute(`recents-key`);if(!e)return[];let t;try{t=JSON.parse(globalThis.localStorage?.getItem(e)??`[]`)}catch{return[]}return Array.isArray(t)?t.filter(e=>e&&typeof e.g==`string`&&typeof e.k==`string`):[]}_recentsLimit(){let e=Number.parseInt(this.getAttribute(`recents-limit`)??``,10);return Number.isFinite(e)&&e>0?Math.min(e,c):s}_remember(e){let t=this.getAttribute(`recents-key`),{groupKey:n,key:r,opens:i}=e.dataset;if(!t||i||n==null||r==null)return;let a=[{g:n,k:r},...this._recentEntries().filter(e=>e.g!==n||e.k!==r)];try{globalThis.localStorage?.setItem(t,JSON.stringify(a.slice(0,this._recentsLimit())))}catch{}}_renderRecents(){let e=this._recentsHost();if(!e)return;let t=this._input(),n=this._path.length===0&&!(t?.value??``).trim()?this._recentEntries():[],r=this._realOptions(),i=[];for(let e of n){let t=r.find(t=>t.dataset.groupKey===e.g&&t.dataset.key===e.k);if(t&&!t.dataset.opens&&!this._isDisabled(t)&&i.push(t),i.length>=this._recentsLimit())break}if(!i.length){e.firstChild&&e.replaceChildren();return}let a=`${this._recentsId}-label`,s=document.createElement(`div`);s.className=`wui-cmd-group`,s.setAttribute(`role`,`group`),s.setAttribute(`aria-labelledby`,a);let c=document.createElement(`div`);c.className=`wui-cmd-group-label`,c.setAttribute(`role`,`presentation`),c.id=a,c.textContent=this.getAttribute(`recents-label`)??o,s.append(c);for(let e of i){let t=e.cloneNode(!0);t.id=`${this._recentsId}-${e.id}`,t.hidden=!1,t.removeAttribute(`aria-selected`),s.append(t)}e.replaceChildren(s)}_inScope(e,t){return!t||(e.closest(`.wui-cmd-page`)?.dataset.page??null)===(this._path.at(-1)?.key??null)}_navigate(e){window.location.assign(e)}_applyFilter(){let e=this._input(),i=(e?e.value:``).trim(),a=i.toLowerCase(),o=this.highlight,s=[...this.querySelectorAll(`.wui-cmd-page`)],c=s.length>0,l=this._path.at(-1)?.key??null;for(let e of s)e.hidden=e.dataset.page!==l;let u=0;for(let e of this._realOptions()){let r=e.querySelector(`.wui-cmd-item-label`),s=e.dataset.label??r?.textContent??``,l=this._inScope(e,c)&&(!a||s.toLowerCase().includes(a));e.hidden=!l,l&&u++,r&&(r.innerHTML=n(s,o?i:``).map(e=>e.match?`<mark class="wui-cmd-mark">${t(e.text)}</mark>`:t(e.text)).join(``))}let d=this._recentsHost();for(let e of this.querySelectorAll(`[role="group"]`))d?.contains(e)||(e.hidden=![...e.querySelectorAll(r)].some(e=>!e.hidden));let f=this.querySelector(`[role="listbox"]`);f&&(f.hidden=u===0);let p=this.querySelector(`.wui-cmd-empty`);p&&(p.textContent=a&&u===0?this.emptyText:``)}_teardown(){this.removeEventListener(`keydown`,this._onKeyDown),this.removeEventListener(`click`,this._onClick),this.removeEventListener(`mousedown`,this._onMouseDown),this.removeEventListener(`mousemove`,this._onMouseMove),this.removeEventListener(`input`,this._onInput),this._modal?.removeEventListener(`hidden.bs.modal`,this._onModalHidden),this._modal=null}};export{d as t};
|
|
@@ -1,306 +0,0 @@
|
|
|
1
|
-
import{n as e}from"./devWarn-DXdRWZs3.js";import{t}from"./elementBase-DV9IZZCu.js";var n={"--color-primary":`#4F46E5`,"--color-primary-hover":`#4338CA`,"--color-on-primary":`#FFFFFF`,"--color-text":`#071437`,"--color-text-muted":`#4B5675`,"--color-border":`#EBEDF3`,"--color-surface":`#FFFFFF`,"--wui-radius-lg":`14px`,"--wui-shadow-modal":`0px 24px 60px -16px rgba(7, 20, 55, 0.28)`,"--wui-z-modal":`1505`},r=e=>`var(${e}, ${n[e]})`,i=`
|
|
2
|
-
:host {
|
|
3
|
-
all: initial;
|
|
4
|
-
display: contents;
|
|
5
|
-
font-family: inherit;
|
|
6
|
-
font-size: 16px;
|
|
7
|
-
line-height: 1.5;
|
|
8
|
-
color: ${r(`--color-text`)};
|
|
9
|
-
}
|
|
10
|
-
*, *::before, *::after {
|
|
11
|
-
box-sizing: border-box;
|
|
12
|
-
}
|
|
13
|
-
[hidden] {
|
|
14
|
-
display: none !important;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
dialog {
|
|
18
|
-
z-index: ${r(`--wui-z-modal`)};
|
|
19
|
-
width: 100%;
|
|
20
|
-
max-width: none;
|
|
21
|
-
height: 100%;
|
|
22
|
-
max-height: none;
|
|
23
|
-
margin: 0;
|
|
24
|
-
padding: 0;
|
|
25
|
-
border: 0;
|
|
26
|
-
background: transparent;
|
|
27
|
-
color: inherit;
|
|
28
|
-
}
|
|
29
|
-
dialog[open] {
|
|
30
|
-
display: flex;
|
|
31
|
-
align-items: center;
|
|
32
|
-
justify-content: center;
|
|
33
|
-
}
|
|
34
|
-
:host([preview]) dialog {
|
|
35
|
-
position: static;
|
|
36
|
-
height: auto;
|
|
37
|
-
}
|
|
38
|
-
dialog::backdrop {
|
|
39
|
-
background: rgba(0, 0, 0, 0.7);
|
|
40
|
-
backdrop-filter: blur(5px);
|
|
41
|
-
}
|
|
42
|
-
dialog[open]::backdrop {
|
|
43
|
-
animation: wlp-fade 0.3s ease-out;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
.wlp-card {
|
|
47
|
-
position: relative;
|
|
48
|
-
width: 90%;
|
|
49
|
-
max-width: 440px;
|
|
50
|
-
max-height: calc(100dvh - 32px);
|
|
51
|
-
overflow-y: auto;
|
|
52
|
-
padding: 24px;
|
|
53
|
-
background: ${r(`--color-surface`)};
|
|
54
|
-
color: ${r(`--color-text`)};
|
|
55
|
-
border: 1px solid ${r(`--color-border`)};
|
|
56
|
-
border-radius: ${r(`--wui-radius-lg`)};
|
|
57
|
-
box-shadow: ${r(`--wui-shadow-modal`)};
|
|
58
|
-
text-align: start;
|
|
59
|
-
}
|
|
60
|
-
dialog[open] .wlp-card {
|
|
61
|
-
animation: wlp-card-in 0.2s ease-out;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
.wlp-close {
|
|
65
|
-
position: absolute;
|
|
66
|
-
top: 12px;
|
|
67
|
-
inset-inline-end: 12px;
|
|
68
|
-
width: 32px;
|
|
69
|
-
height: 32px;
|
|
70
|
-
padding: 0;
|
|
71
|
-
border: 0;
|
|
72
|
-
border-radius: 50%;
|
|
73
|
-
background: transparent;
|
|
74
|
-
color: ${r(`--color-text-muted`)};
|
|
75
|
-
font: inherit;
|
|
76
|
-
font-size: 22px;
|
|
77
|
-
line-height: 1;
|
|
78
|
-
cursor: pointer;
|
|
79
|
-
}
|
|
80
|
-
.wlp-close:focus-visible,
|
|
81
|
-
.wlp-button:focus-visible,
|
|
82
|
-
.wlp-input:focus-visible,
|
|
83
|
-
.wlp-secondary:focus-visible {
|
|
84
|
-
outline: 2px solid ${r(`--color-primary`)};
|
|
85
|
-
outline-offset: 2px;
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
.wlp-heading {
|
|
89
|
-
margin: 0 32px 8px 0;
|
|
90
|
-
font-size: 20px;
|
|
91
|
-
font-weight: 600;
|
|
92
|
-
line-height: 1.3;
|
|
93
|
-
color: ${r(`--color-text`)};
|
|
94
|
-
}
|
|
95
|
-
.wlp-description {
|
|
96
|
-
margin: 0 0 16px;
|
|
97
|
-
font-size: 14px;
|
|
98
|
-
color: ${r(`--color-text-muted`)};
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
.wlp-form {
|
|
102
|
-
display: grid;
|
|
103
|
-
gap: 14px;
|
|
104
|
-
margin: 0;
|
|
105
|
-
}
|
|
106
|
-
.wlp-field {
|
|
107
|
-
display: grid;
|
|
108
|
-
gap: 4px;
|
|
109
|
-
}
|
|
110
|
-
.wlp-label {
|
|
111
|
-
font-size: 14px;
|
|
112
|
-
font-weight: 500;
|
|
113
|
-
color: ${r(`--color-text`)};
|
|
114
|
-
}
|
|
115
|
-
.wlp-req {
|
|
116
|
-
margin-inline-start: 2px;
|
|
117
|
-
color: ${r(`--color-primary`)};
|
|
118
|
-
}
|
|
119
|
-
.wlp-input {
|
|
120
|
-
width: 100%;
|
|
121
|
-
padding: 9px 12px;
|
|
122
|
-
border: 1px solid ${r(`--color-border`)};
|
|
123
|
-
border-radius: 8px;
|
|
124
|
-
background: ${r(`--color-surface`)};
|
|
125
|
-
color: ${r(`--color-text`)};
|
|
126
|
-
font: inherit;
|
|
127
|
-
font-size: 15px;
|
|
128
|
-
}
|
|
129
|
-
textarea.wlp-input {
|
|
130
|
-
resize: vertical;
|
|
131
|
-
min-height: 96px;
|
|
132
|
-
}
|
|
133
|
-
.wlp-input[aria-invalid="true"] {
|
|
134
|
-
border-color: var(--color-danger, #B42318);
|
|
135
|
-
}
|
|
136
|
-
.wlp-error {
|
|
137
|
-
margin: 0;
|
|
138
|
-
font-size: 13px;
|
|
139
|
-
color: var(--color-danger, #B42318);
|
|
140
|
-
}
|
|
141
|
-
.wlp-form-error {
|
|
142
|
-
margin: 0;
|
|
143
|
-
font-size: 14px;
|
|
144
|
-
color: var(--color-danger, #B42318);
|
|
145
|
-
}
|
|
146
|
-
.wlp-visually-hidden {
|
|
147
|
-
position: absolute;
|
|
148
|
-
width: 1px;
|
|
149
|
-
height: 1px;
|
|
150
|
-
margin: -1px;
|
|
151
|
-
padding: 0;
|
|
152
|
-
overflow: hidden;
|
|
153
|
-
clip: rect(0, 0, 0, 0);
|
|
154
|
-
white-space: nowrap;
|
|
155
|
-
border: 0;
|
|
156
|
-
}
|
|
157
|
-
.wlp-honeypot {
|
|
158
|
-
position: absolute !important;
|
|
159
|
-
left: -9999px !important;
|
|
160
|
-
width: 1px;
|
|
161
|
-
height: 1px;
|
|
162
|
-
opacity: 0;
|
|
163
|
-
pointer-events: none;
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
.wlp-actions {
|
|
167
|
-
display: flex;
|
|
168
|
-
justify-content: flex-end;
|
|
169
|
-
align-items: center;
|
|
170
|
-
gap: 8px;
|
|
171
|
-
margin-top: 4px;
|
|
172
|
-
}
|
|
173
|
-
.wlp-button {
|
|
174
|
-
display: inline-flex;
|
|
175
|
-
align-items: center;
|
|
176
|
-
justify-content: center;
|
|
177
|
-
min-height: 36px;
|
|
178
|
-
padding: 8px 16px;
|
|
179
|
-
border: 1px solid ${r(`--color-primary`)};
|
|
180
|
-
border-radius: 8px;
|
|
181
|
-
background: ${r(`--color-primary`)};
|
|
182
|
-
color: ${r(`--color-on-primary`)};
|
|
183
|
-
font: inherit;
|
|
184
|
-
font-size: 15px;
|
|
185
|
-
font-weight: 500;
|
|
186
|
-
cursor: pointer;
|
|
187
|
-
}
|
|
188
|
-
.wlp-button:hover {
|
|
189
|
-
background: ${r(`--color-primary-hover`)};
|
|
190
|
-
border-color: ${r(`--color-primary-hover`)};
|
|
191
|
-
}
|
|
192
|
-
.wlp-button:disabled {
|
|
193
|
-
opacity: 0.6;
|
|
194
|
-
cursor: default;
|
|
195
|
-
}
|
|
196
|
-
.wlp-notice {
|
|
197
|
-
margin: 4px 0 0;
|
|
198
|
-
font-size: 12px;
|
|
199
|
-
line-height: 1.4;
|
|
200
|
-
color: ${r(`--color-text-muted`)};
|
|
201
|
-
}
|
|
202
|
-
.wlp-notice a {
|
|
203
|
-
color: inherit;
|
|
204
|
-
text-decoration: underline;
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
.wlp-secondary-row {
|
|
208
|
-
display: flex;
|
|
209
|
-
align-items: center;
|
|
210
|
-
gap: 10px;
|
|
211
|
-
margin-top: 14px;
|
|
212
|
-
font-size: 14px;
|
|
213
|
-
color: ${r(`--color-text-muted`)};
|
|
214
|
-
}
|
|
215
|
-
.wlp-secondary-row::before,
|
|
216
|
-
.wlp-secondary-row::after {
|
|
217
|
-
content: "";
|
|
218
|
-
flex: 1;
|
|
219
|
-
height: 1px;
|
|
220
|
-
background: ${r(`--color-border`)};
|
|
221
|
-
}
|
|
222
|
-
.wlp-secondary {
|
|
223
|
-
display: block;
|
|
224
|
-
margin-top: 10px;
|
|
225
|
-
text-align: center;
|
|
226
|
-
color: ${r(`--color-primary`)};
|
|
227
|
-
font-weight: 500;
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
.wlp-success-title {
|
|
231
|
-
margin: 0 32px 8px 0;
|
|
232
|
-
font-size: 20px;
|
|
233
|
-
font-weight: 600;
|
|
234
|
-
color: ${r(`--color-text`)};
|
|
235
|
-
}
|
|
236
|
-
.wlp-success-text {
|
|
237
|
-
margin: 0 0 16px;
|
|
238
|
-
color: ${r(`--color-text-muted`)};
|
|
239
|
-
}
|
|
240
|
-
.wlp-success-view .wlp-button {
|
|
241
|
-
width: 100%;
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
@keyframes wlp-fade {
|
|
245
|
-
from { opacity: 0; }
|
|
246
|
-
to { opacity: 1; }
|
|
247
|
-
}
|
|
248
|
-
@keyframes wlp-card-in {
|
|
249
|
-
from { opacity: 0; transform: scale(0.96); }
|
|
250
|
-
to { opacity: 1; transform: scale(1); }
|
|
251
|
-
}
|
|
252
|
-
|
|
253
|
-
@media (max-width: 575.98px) {
|
|
254
|
-
.wlp-card {
|
|
255
|
-
width: calc(100% - 32px);
|
|
256
|
-
max-width: none;
|
|
257
|
-
padding: 20px 16px;
|
|
258
|
-
}
|
|
259
|
-
.wlp-input {
|
|
260
|
-
font-size: 16px;
|
|
261
|
-
}
|
|
262
|
-
.wlp-button,
|
|
263
|
-
.wlp-close {
|
|
264
|
-
min-height: 44px;
|
|
265
|
-
}
|
|
266
|
-
.wlp-close {
|
|
267
|
-
min-width: 44px;
|
|
268
|
-
}
|
|
269
|
-
}
|
|
270
|
-
|
|
271
|
-
@media (prefers-reduced-motion: reduce) {
|
|
272
|
-
dialog[open]::backdrop,
|
|
273
|
-
dialog[open] .wlp-card {
|
|
274
|
-
animation: none;
|
|
275
|
-
}
|
|
276
|
-
}
|
|
277
|
-
`,a=[`name`,`email`,`phone`,`company`,`message`],o=[`name`,`email`],s={name:`Name`,email:`Email`,phone:`Phone number`,company:`Company`,message:`Message`},c={name:100,email:320,phone:40,company:150,message:1e3},l={name:`name`,email:`email`,phone:`tel`,company:`organization`},u=`input:not([type=hidden]), textarea, select, button, a[href]`,d=[`exit`,`delay`,`scroll`,`pages`],f=/^[^\s@]+@[^\s@]+\.[^\s@]+$/,p=864e5,m=`comment_subject`,h=`__RequestVerificationToken`,g=`__FormStamp`,_=`__CaptchaToken`,v=`Something went wrong. Please try again or contact us directly.`,y=/* @__PURE__ */ `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.triggers.delay-seconds.scroll-percent.pages-viewed.storage-key.dismiss-days.submitted-days.success-close-seconds.preview`.split(`.`),b=/* @__PURE__ */ new Set;function x(t,n){b.has(t)||(b.add(t),e(n))}var S=0;function C(e){return(e??``).split(/\s+/).map(e=>e.trim()).filter(Boolean)}function w(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 T(e){return String(e??``).replace(/&/g,`&`).replace(/</g,`<`).replace(/>/g,`>`).replace(/"/g,`"`)}var E=null;function D(e){E||(E=new CSSStyleSheet,E.replaceSync(i)),e.adoptedStyleSheets=[E]}function O(e,t){return e instanceof Error&&e.message?e.message:t}var k=class extends t{static get observedAttributes(){return y}constructor(){super(),S+=1,this._uid=`wlp-${S}`,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`){this._open||e!==`manual`&&(this._opened||this._blocked()||document.querySelector(`dialog[open], .modal.show`))||(this._rendered||this._render(),this._opened=!0,this._open=!0,clearTimeout(this._delayTimer),this._showForm(),this._modal=!this.preview,this._modal?(this._returnTo=document.activeElement,this._prevOverflow=document.documentElement.style.overflow,document.documentElement.style.overflow=`hidden`,this._dialog().showModal(),this._dialog().querySelector(`[data-wlp-field] [data-wlp-input]`)?.focus()):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),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 this._root().querySelector(`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=C(this.getAttribute(`fields`)).filter(e=>a.includes(e)?!0:(x(`field:${e}`,`[@webority/ui-elements] <wui-lead-popup> has no field "${e}". It is ignored.`),!1));return e.length?e:o}_requiredKeys(){let e=this._fieldKeys();return C(this.getAttribute(`required`)).filter(t=>e.includes(t))}_label(e){return w(this.getAttribute(`labels`))[e]||s[e]}_postedName(e){return this._text(`field-prefix`)+(w(this.getAttribute(`field-names`))[e]||e)}_maxLength(e){let t=Number(w(this.getAttribute(`max-lengths`))[e]);return Number.isInteger(t)&&t>0?t:c[e]}_triggers(){if(this.preview)return[];let e=(this.getAttribute(`triggers`)??``).split(/\s+/).filter(e=>d.includes(e));return e.length?this.getAttribute(`storage-key`)?e:(x(`storage-key`,`[@webority/ui-elements] <wui-lead-popup> has triggers but no storage-key. The triggers are off.`),[]):[]}_render(){let e=this._root();D(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=`
|
|
278
|
-
<dialog class="wlp-dialog" aria-labelledby="${t}-h"${a?` aria-describedby="${t}-d"`:``}>
|
|
279
|
-
<div class="wlp-card">
|
|
280
|
-
<button type="button" class="wlp-close" aria-label="${T(this._text(`close-label`,`Close`))}" data-wlp-close>×</button>
|
|
281
|
-
<div class="wlp-form-view">
|
|
282
|
-
<h2 class="wlp-heading" id="${t}-h">${T(i)}</h2>
|
|
283
|
-
${a?`<p class="wlp-description" id="${t}-d">${T(a)}</p>`:``}
|
|
284
|
-
<form class="wlp-form" novalidate data-wlp-form>
|
|
285
|
-
${c}
|
|
286
|
-
<p class="wlp-form-error" role="alert" hidden data-wlp-form-error></p>
|
|
287
|
-
<div class="wlp-actions">
|
|
288
|
-
<button type="submit" class="wlp-button" data-wlp-submit>${T(this._text(`submit-label`,`Send`))}</button>
|
|
289
|
-
</div>
|
|
290
|
-
<input type="text" name="${m}" class="wlp-honeypot" tabindex="-1" autocomplete="off" aria-hidden="true" data-wlp-honeypot>
|
|
291
|
-
<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>
|
|
292
|
-
</form>
|
|
293
|
-
${o&&s?`<div class="wlp-secondary-row"><span>${T(this._text(`secondary-divider`,`or`))}</span></div><a class="wlp-secondary" href="${T(s)}" data-wlp-secondary>${T(o)}</a>`:``}
|
|
294
|
-
</div>
|
|
295
|
-
<div class="wlp-success-view" hidden>
|
|
296
|
-
<h2 class="wlp-success-title" role="status" tabindex="-1" data-wlp-success-title>${T(this._text(`success-title`,`Thank you`))}</h2>
|
|
297
|
-
${this._text(`success-text`)?`<p class="wlp-success-text">${T(this._text(`success-text`))}</p>`:``}
|
|
298
|
-
<button type="button" class="wlp-button" data-wlp-done>${T(this._text(`close-label`,`Close`))}</button>
|
|
299
|
-
</div>
|
|
300
|
-
</div>
|
|
301
|
-
</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=T(this._postedName(e)),o=this._maxLength(e),s=t?`<span class="wlp-req" aria-hidden="true">*</span><span class="wlp-visually-hidden">required</span>`:``,c=`id="${n}" data-wlp-input="${e}" name="${a}" maxlength="${o}"${t?` aria-required="true"`:``}`,u=e===`message`?`<textarea class="wlp-input" rows="4" ${c}></textarea>`:`<input class="wlp-input" type="${e===`email`?`email`:e===`phone`?`tel`:`text`}" ${c}${l[e]?` autocomplete="${l[e]}"`:``}>`;return`
|
|
302
|
-
<div class="wlp-field" data-wlp-field="${e}">
|
|
303
|
-
<label class="wlp-label" for="${n}">${T(i)}${s}</label>
|
|
304
|
-
${u}
|
|
305
|
-
<p class="wlp-error" id="${r}" hidden></p>
|
|
306
|
-
</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(u)).filter(e=>!e.disabled&&e.getClientRects().length>0);if(!n.length)return;let r=n.indexOf(this._root().activeElement);t.preventDefault(),n[r===-1?t.shiftKey?n.length-1:0:(r+(t.shiftKey?-1:1)+n.length)%n.length].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`)),e.querySelector(`[data-wlp-form]`).addEventListener(`submit`,e=>this._onSubmit(e))}_showForm(){let e=this._root();e.querySelector(`.wlp-form-view`).hidden=!1,e.querySelector(`.wlp-success-view`).hidden=!0}_showSuccess(){let e=this._root();e.querySelector(`.wlp-form-view`).hidden=!0;let t=e.querySelector(`.wlp-success-view`);t.hidden=!1,e.querySelector(`[data-wlp-success-title]`).focus()}_setFieldError(e,t){let n=this._root(),r=n.querySelector(`[data-wlp-input="${e}"]`),i=n.querySelector(`#${this._uid}-e-${e}`);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}"]`).value.trim();n[r]=i;let a=``;!i&&e.has(r)?a=`Enter your ${this._label(r).toLowerCase()}`:r===`email`&&i&&!f.test(i)&&(a=`Enter a valid email address`);let o=this._setFieldError(r,a);a&&!t&&(t=o)}return t?(t.focus(),null):n}_setBusy(e){this._posting=e;let t=this._root().querySelector(`[data-wlp-form]`);e?t.setAttribute(`aria-busy`,`true`):t.removeAttribute(`aria-busy`),this._root().querySelector(`[data-wlp-submit]`).disabled=e}_fail(e,t){this._setBusy(!1);let n=this._root().querySelector(`[data-wlp-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;this._root().querySelector(`[data-wlp-form-error]`).hidden=!0;let t=this._validate();t&&!this.preview&&await this._post(t)}async _post(e){let t=globalThis.WeborityPublicForms;if(!t){x(`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`,v));return}let n=this._text(`error-text`,v),r=this._text(`public-form`);this._setBusy(!0);let i,a;try{i=await t.session(),a=await t.mintToken(r)}catch(e){this._fail(`gate`,O(e,n));return}let o=this._root(),s=new FormData;for(let t of this._fieldKeys())s.append(this._postedName(t),e[t]);s.set(h,i.token),s.set(g,i.formStamp),s.set(_,a),s.set(m,o.querySelector(`[data-wlp-honeypot]`).value),this._emit(`wui-lead-popup-before-submit`,{formData:s});let c;try{c=await fetch(this._text(`action`),{method:`POST`,body:s,credentials:`same-origin`,headers:{"X-Requested-With":`XMLHttpRequest`}})}catch{this._fail(`network`,n);return}if(!c.ok){let e=await c.json().catch(()=>null),t=typeof e?.detail==`string`?e.detail.trim():``;this._fail(`server`,t||n);return}let l=await c.json().catch(()=>null);this._succeed(e,l)}_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),clearTimeout(this._closeTimer),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*p}_remember(e){let t=this.getAttribute(`storage-key`);if(t&&!this.preview)try{localStorage.setItem(t,JSON.stringify({state:e,at:(/* @__PURE__ */ new Date()).toISOString()}))}catch{}}};export{k as t};
|