@travelopia/web-components 0.9.10 → 0.9.12

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.
@@ -1 +1 @@
1
- {"version":3,"file":"dist/lightbox/index.js","mappings":"mBAaO,MAAMA,UAA0BC,YAkBtC,WAAAC,G,UAECC,QAhBS,KAAAC,gBAA8C,KAC9C,KAAAC,aAAuB,GACvB,KAAAC,UAAyD,KACzD,KAAAC,YAAsB,EACtB,KAAAC,YAAsB,EACtB,KAAAC,eAAyB,IAGzB,KAAAC,yBAA+C,KAWxDC,KAAKC,mBAAqBD,KAAKE,cAAcC,KAAMH,MAGnDA,KAAKI,cAAgBJ,KAAKK,cAAe,UACzCL,KAAKM,iBAAmBN,KAAKO,iBAAkB,wBAG7B,QAAlB,EAAAP,KAAKI,qBAAa,SAAEI,iBAAkB,QAASR,KAAKS,kBAAkBN,KAAMH,OAC1D,QAAlB,EAAAA,KAAKI,qBAAa,SAAEI,iBAAkB,aAAcR,KAAKU,iBAAiBP,KAAMH,OAC9D,QAAlB,EAAAA,KAAKI,qBAAa,SAAEI,iBAAkB,WAAYR,KAAKW,eAAeR,KAAMH,MAC7E,CAOA,6BAAWY,GAEV,MAAO,CAAE,OAAQ,QAAS,QAAS,yBAA0B,UAC9D,CASA,wBAAAC,CAA0BC,EAAe,GAAIC,EAAmB,GAAIC,EAAmB,IAEjFD,IAAaC,IAMlBhB,KAAKiB,cAAe,IAAIC,YAAa,WAGhC,UAAYJ,GAChBd,KAAKmB,4BAID,SAAWL,GAAQ,UAAYA,GACnCd,KAAKoB,uBAEP,CAOA,aAAAC,GAEC,MAAO,OAASrB,KAAKsB,aAAc,OACpC,CAKA,YAAIC,GAEH,OAAOvB,KAAKP,eACb,CAOA,YAAI8B,CAAUA,GAEbvB,KAAKP,gBAAkB8B,EACvBvB,KAAKiB,cAAe,IAAIC,YAAa,iBAGrC,MAAMM,EAA2CxB,KAAKK,cAAe,uBAGrE,GAAOmB,EAM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AAY,GAGjB,IAAM,IAAI4E,EAAI,EAAGA,EAAID,EAAaC,IAAM,CAEvC,MAAMvB,EAAUpF,KAAKuB,SAASC,QAAQE,WAAW,GAGjD1B,KAAK4G,YAAaxB,E,CAEpB,EC7CM,MAAMyB,UAAiCvH,YAS7C,WAAAC,G,MAECC,QACAQ,KAAK2F,SAAW3F,KAAK4F,QAAS,eAGA,QAA9B,EAAA5F,KAAKK,cAAe,iBAAU,SAAEG,iBAAkB,QAASR,KAAK8G,YAAY3G,KAAMH,MACnF,CAKA,WAAA8G,G,MAEQ9G,KAAK2F,WAMZ3F,KAAK2F,SAAS1D,aAAwC,QAAzB,EAAAkD,OAAQnF,KAAK+G,mBAAY,QAAI,EAG1D/G,KAAK2F,SAASvE,uBACf,CAOA,QAAA2F,G,MAEC,IAAO/G,KAAK2F,SAEX,OAAO,EAIR,MAAMqB,EAA2ChH,KAAK4F,QAAS,mBAG/D,OAASqB,MAAMC,KAA2B,QAArB,EAAAF,aAAW,EAAXA,EAAaG,gBAAQ,QAAI,IAAKC,QAASpH,MAAW,CACxE,ECxCDqH,eAAeC,OAAQ,cAAejI,GACtCgI,eAAeC,OAAQ,sBAAuB7B,GAC9C4B,eAAeC,OAAQ,oBAAqB5B,GAC5C2B,eAAeC,OAAQ,uBAAwBzB,GAC/CwB,eAAeC,OAAQ,mBAAoBxB,GAC3CuB,eAAeC,OAAQ,oBAAqBvB,GAC5CsB,eAAeC,OAAQ,sBAAuBjB,GAC9CgB,eAAeC,OAAQ,kBAAmBd,GAC1Ca,eAAeC,OAAQ,uBAAwBT,E","sources":["webpack://@travelopia/web-components/./src/lightbox/tp-lightbox.ts","webpack://@travelopia/web-components/./src/lightbox/tp-lightbox-content.ts","webpack://@travelopia/web-components/./src/lightbox/tp-lightbox-close.ts","webpack://@travelopia/web-components/./src/lightbox/tp-lightbox-previous.ts","webpack://@travelopia/web-components/./src/lightbox/tp-lightbox-next.ts","webpack://@travelopia/web-components/./src/lightbox/tp-lightbox-count.ts","webpack://@travelopia/web-components/./src/lightbox/tp-lightbox-trigger.ts","webpack://@travelopia/web-components/./src/lightbox/tp-lightbox-nav.ts","webpack://@travelopia/web-components/./src/lightbox/tp-lightbox-nav-item.ts","webpack://@travelopia/web-components/./src/lightbox/index.ts"],"sourcesContent":["/**\n * Internal dependencies.\n */\nimport { TPLightboxContentElement } from './tp-lightbox-content';\nimport { TPLightboxPreviousElement } from './tp-lightbox-previous';\nimport { TPLightboxNextElement } from './tp-lightbox-next';\nimport { TPLightboxTriggerElement } from './tp-lightbox-trigger';\nimport { TPLightboxCountElement } from './tp-lightbox-count';\nimport { TPLightboxNavItemElement } from './tp-lightbox-nav-item';\n\n/**\n * TP Lightbox.\n */\nexport class TPLightboxElement extends HTMLElement {\n\t/**\n\t * Properties.\n\t */\n\tprotected currentTemplate: HTMLTemplateElement | null = null;\n\tprotected currentGroup: string = '';\n\tprotected allGroups: NodeListOf<TPLightboxTriggerElement> | null = null;\n\tprotected touchStartX: number = 0;\n\tprotected touchStartY: number = 0;\n\tprotected swipeThreshold: number = 200;\n\tprotected dialogElement: HTMLDialogElement | null;\n\tprotected lightboxNavItems: NodeListOf<TPLightboxNavItemElement> | null;\n\tprotected previouslyFocusedElement: HTMLElement | null = null;\n\tprotected readonly boundHandleKeyDown: ( e: KeyboardEvent ) => void;\n\n\t/**\n\t * Constructor.\n\t */\n\tconstructor() {\n\t\t// Initialize parent.\n\t\tsuper();\n\n\t\t// Bind event handlers.\n\t\tthis.boundHandleKeyDown = this.handleKeyDown.bind( this );\n\n\t\t// Initialize\n\t\tthis.dialogElement = this.querySelector( 'dialog' );\n\t\tthis.lightboxNavItems = this.querySelectorAll( 'tp-lightbox-nav-item' );\n\n\t\t// Event listeners.\n\t\tthis.dialogElement?.addEventListener( 'click', this.handleDialogClick.bind( this ) );\n\t\tthis.dialogElement?.addEventListener( 'touchstart', this.handleTouchStart.bind( this ) );\n\t\tthis.dialogElement?.addEventListener( 'touchend', this.handleTouchEnd.bind( this ) );\n\t}\n\n\t/**\n\t * Get observed attributes.\n\t *\n\t * @return {Array} List of observed attributes.\n\t */\n\tstatic get observedAttributes(): string[] {\n\t\t// Attributes to observe.\n\t\treturn [ 'open', 'index', 'total', 'close-on-overlay-click', 'loading' ];\n\t}\n\n\t/**\n\t * Attribute changed callback.\n\t *\n\t * @param {string} name Attribute name.\n\t * @param {string} oldValue Old value.\n\t * @param {string} newValue New value.\n\t */\n\tattributeChangedCallback( name: string = '', oldValue: string = '', newValue: string = '' ): void {\n\t\t// Prevent redundant updates.\n\t\tif ( oldValue === newValue ) {\n\t\t\t// Early return.\n\t\t\treturn;\n\t\t}\n\n\t\t// Trigger change event.\n\t\tthis.dispatchEvent( new CustomEvent( 'change' ) );\n\n\t\t// Trigger current index target if index has changed.\n\t\tif ( 'index' === name ) {\n\t\t\tthis.triggerCurrentIndexTarget();\n\t\t}\n\n\t\t// Trigger navigation update if open or index has changed.\n\t\tif ( 'open' === name || 'index' === name ) {\n\t\t\tthis.updateNavCurrentItem();\n\t\t}\n\t}\n\n\t/**\n\t * Check if ARIA management is enabled.\n\t *\n\t * @return {boolean} Whether ARIA is enabled.\n\t */\n\tisAriaEnabled(): boolean {\n\t\t// Return whether ARIA management is enabled (default: yes).\n\t\treturn 'no' !== this.getAttribute( 'aria' );\n\t}\n\n\t/**\n\t * Get template.\n\t */\n\tget template(): HTMLTemplateElement | null {\n\t\t// Return current template.\n\t\treturn this.currentTemplate;\n\t}\n\n\t/**\n\t * Set template.\n\t *\n\t * @param {HTMLTemplateElement} template The template.\n\t */\n\tset template( template: HTMLTemplateElement | null ) {\n\t\t// Set the template.\n\t\tthis.currentTemplate = template;\n\t\tthis.dispatchEvent( new CustomEvent( 'template-set' ) );\n\n\t\t// Get lightbox content element.\n\t\tconst content: TPLightboxContentElement | null = this.querySelector( 'tp-lightbox-content' );\n\n\t\t// Check if we have a content.\n\t\tif ( ! content ) {\n\t\t\t// No we don't. Exit.\n\t\t\treturn;\n\t\t}\n\n\t\t// Check if we have a template.\n\t\tif ( this.currentTemplate ) {\n\t\t\t/**\n\t\t\t * We do, update content with template's content.\n\t\t\t * We do this rather than a string to avoid script injection.\n\t\t\t */\n\t\t\tconst templateContent: Node = this.currentTemplate.content.cloneNode( true );\n\t\t\tcontent.replaceChildren( templateContent );\n\t\t\tthis.dispatchEvent( new CustomEvent( 'content-change' ) );\n\n\t\t\t// Prepare image loading.\n\t\t\tsetTimeout( (): void => {\n\t\t\t\t// We do, prepare image loading.\n\t\t\t\tthis.prepareImageLoading();\n\t\t\t\tthis.prepareNavigation();\n\t\t\t}, 0 );\n\t\t} else {\n\t\t\t// We don't, set content as empty.\n\t\t\tcontent.innerHTML = '';\n\t\t}\n\t}\n\n\t/**\n\t * Get current group.\n\t */\n\tget group(): string {\n\t\t// Return current group.\n\t\treturn this.currentGroup;\n\t}\n\n\t/**\n\t * Set current group.\n\t *\n\t * @param {string} group Group name.\n\t */\n\tset group( group: string ) {\n\t\t// Set current group.\n\t\tthis.currentGroup = group;\n\t}\n\n\t/**\n\t * Get current index.\n\t */\n\tget currentIndex(): number {\n\t\t// Return current index.\n\t\treturn parseInt( this.getAttribute( 'index' ) ?? '1' );\n\t}\n\n\t/**\n\t * Set current index.\n\t *\n\t * @param {number} index Current index.\n\t */\n\tset currentIndex( index: number ) {\n\t\t// Set current index.\n\t\tif ( index < 1 ) {\n\t\t\tindex = 1;\n\t\t}\n\n\t\t// Setting this attributes triggers a re-trigger.\n\t\tthis.setAttribute( 'index', index.toString() );\n\n\t\t// dispatch slide-set event.\n\t\tthis.dispatchEvent( new CustomEvent( 'slide-set', {\n\t\t\tdetail: {\n\t\t\t\tslideIndex: index,\n\t\t\t},\n\t\t} ) );\n\t}\n\n\t/**\n\t * Trigger the target that matches the current index within current group.\n\t */\n\ttriggerCurrentIndexTarget(): void {\n\t\t// Get all groups and check if current index exists within group.\n\t\tconst allGroups: NodeListOf<TPLightboxTriggerElement> | null = this.getAllGroups();\n\n\t\t// Bail early if we don't have groups.\n\t\tif ( ! allGroups || ! allGroups[ this.currentIndex - 1 ] ) {\n\t\t\t// No we don't. Exit.\n\t\t\treturn;\n\t\t}\n\n\t\t// Trigger element within group.\n\t\tallGroups[ this.currentIndex - 1 ].trigger();\n\t}\n\n\t/**\n\t * Open lightbox.\n\t */\n\topen(): void {\n\t\t// Get the dialog element.\n\t\tconst dialog: HTMLDialogElement | null = this.querySelector( 'dialog' );\n\n\t\t// Check if dialog exists or is already open.\n\t\tif ( ! dialog || dialog.open ) {\n\t\t\t// Yes it is, Exit.\n\t\t\treturn;\n\t\t}\n\n\t\t// Save the currently focused element to restore later (if manage-focus is enabled).\n\t\tif ( 'no' !== this.getAttribute( 'manage-focus' ) ) {\n\t\t\tthis.previouslyFocusedElement = this.ownerDocument.activeElement as HTMLElement;\n\t\t}\n\n\t\t// First, take this opportunity to update all groups (if it wasn't set from the trigger).\n\t\tif ( '' !== this.group && ! this.allGroups ) {\n\t\t\tthis.updateAllGroups();\n\t\t}\n\n\t\t// Now, show the modal.\n\t\tdialog.showModal();\n\t\tthis.setAttribute( 'open', 'yes' );\n\n\t\t// Add keyboard event listener for arrow navigation.\n\t\tdocument.addEventListener( 'keydown', this.boundHandleKeyDown );\n\n\t\t// Move focus into the lightbox (if manage-focus is enabled).\n\t\tif ( 'no' !== this.getAttribute( 'manage-focus' ) ) {\n\t\t\tthis.setInitialFocus();\n\t\t}\n\t}\n\n\t/**\n\t * Close lightbox.\n\t */\n\tclose(): void {\n\t\t// Remove keyboard event listener.\n\t\tdocument.removeEventListener( 'keydown', this.boundHandleKeyDown );\n\n\t\t// Find and close the dialog.\n\t\tconst dialog: HTMLDialogElement | null = this.querySelector( 'dialog' );\n\t\tdialog?.close();\n\t\tthis.removeAttribute( 'open' );\n\n\t\t// Restore focus to the previously focused element (if manage-focus is enabled).\n\t\tif ( 'no' !== this.getAttribute( 'manage-focus' ) && this.previouslyFocusedElement ) {\n\t\t\tthis.previouslyFocusedElement.focus();\n\t\t\tthis.previouslyFocusedElement = null;\n\t\t}\n\n\t\t// Clear groups from memory.\n\t\tthis.allGroups = null;\n\t}\n\n\t/**\n\t * Navigate previous.\n\t */\n\tprevious(): void {\n\t\t// Check if we even have a group.\n\t\tif ( '' === this.group ) {\n\t\t\t// No we don't. Exit.\n\t\t\treturn;\n\t\t}\n\n\t\t// Check if we have elements within group.\n\t\tconst allGroups: NodeListOf<TPLightboxTriggerElement> | null = this.getAllGroups();\n\n\t\t// Bail early if we don't have groups.\n\t\tif ( ! allGroups ) {\n\t\t\t// No we don't. Exit.\n\t\t\treturn;\n\t\t}\n\n\t\t// Decrement the current index.\n\t\tif ( this.currentIndex > 1 ) {\n\t\t\tthis.currentIndex--;\n\t\t}\n\t}\n\n\t/**\n\t * Navigate next.\n\t */\n\tnext(): void {\n\t\t// Check if we even have a group.\n\t\tif ( '' === this.group ) {\n\t\t\t// No we don't. Exit.\n\t\t\treturn;\n\t\t}\n\n\t\t// Check if we have elements within group.\n\t\tconst allGroups: NodeListOf<TPLightboxTriggerElement> | null = this.getAllGroups();\n\n\t\t// Bail early if we don't have groups.\n\t\tif ( ! allGroups ) {\n\t\t\t// No we don't. Exit.\n\t\t\treturn;\n\t\t}\n\n\t\t// Increment the current index.\n\t\tif ( this.currentIndex < allGroups.length ) {\n\t\t\tthis.currentIndex++;\n\t\t}\n\t}\n\n\t/**\n\t * Update all groups and save it to memory.\n\t *\n\t * @param {NodeList} allGroups All groups.\n\t */\n\tupdateAllGroups( allGroups: NodeListOf<TPLightboxTriggerElement> | null = null ): void {\n\t\t// Update all groups.\n\t\tif ( allGroups && allGroups.length ) {\n\t\t\tthis.allGroups = allGroups;\n\t\t\tthis.setAttribute( 'total', this.allGroups.length.toString() );\n\n\t\t\t// Exit.\n\t\t\treturn;\n\t\t}\n\n\t\t// Get all groups.\n\t\tthis.allGroups = document.querySelectorAll( `tp-lightbox-trigger[group=\"${ this.group }\"]` );\n\n\t\t// Update total.\n\t\tif ( ! this.allGroups.length ) {\n\t\t\tthis.allGroups = null;\n\t\t} else {\n\t\t\tthis.setAttribute( 'total', this.allGroups.length.toString() );\n\t\t}\n\t}\n\n\t/**\n\t * Get all groups from memory.\n\t */\n\tgetAllGroups(): NodeListOf<TPLightboxTriggerElement> | null {\n\t\t// Return all groups.\n\t\treturn this.allGroups;\n\t}\n\n\t/**\n\t * Prepare navigation.\n\t */\n\tprepareNavigation(): void {\n\t\t// Update counter.\n\t\tconst count: TPLightboxCountElement | null = this.querySelector( 'tp-lightbox-count' );\n\t\tcount?.update();\n\n\t\t// Get previous and next elements.\n\t\tconst previous: TPLightboxPreviousElement | null = this.querySelector( 'tp-lightbox-previous' );\n\t\tconst next: TPLightboxNextElement | null = this.querySelector( 'tp-lightbox-next' );\n\n\t\t// Bail early if we don't have either.\n\t\tif ( ! previous && ! next ) {\n\t\t\t// Exit.\n\t\t\treturn;\n\t\t}\n\n\t\t// Get buttons inside prev/next for ARIA.\n\t\tconst previousButton: HTMLButtonElement | null = previous?.querySelector( 'button' ) ?? null;\n\t\tconst nextButton: HTMLButtonElement | null = next?.querySelector( 'button' ) ?? null;\n\t\tconst ariaEnabled: boolean = this.isAriaEnabled();\n\n\t\t// Check if we have a group.\n\t\tif ( '' === this.group ) {\n\t\t\tprevious?.setAttribute( 'disabled', 'yes' );\n\t\t\tnext?.setAttribute( 'disabled', 'yes' );\n\n\t\t\t// Set aria-disabled on buttons.\n\t\t\tif ( ariaEnabled ) {\n\t\t\t\tpreviousButton?.setAttribute( 'aria-disabled', 'true' );\n\t\t\t\tnextButton?.setAttribute( 'aria-disabled', 'true' );\n\t\t\t}\n\n\t\t\t// Exit.\n\t\t\treturn;\n\t\t}\n\n\t\t// Check if we have elements within the group.\n\t\tconst allGroups: NodeListOf<TPLightboxTriggerElement> | null = this.getAllGroups();\n\n\t\t// Disable if we don't have any.\n\t\tif ( ! allGroups ) {\n\t\t\tprevious?.setAttribute( 'disabled', 'yes' );\n\t\t\tnext?.setAttribute( 'disabled', 'yes' );\n\n\t\t\t// Set aria-disabled on buttons.\n\t\t\tif ( ariaEnabled ) {\n\t\t\t\tpreviousButton?.setAttribute( 'aria-disabled', 'true' );\n\t\t\t\tnextButton?.setAttribute( 'aria-disabled', 'true' );\n\t\t\t}\n\n\t\t\t// Exit.\n\t\t\treturn;\n\t\t}\n\n\t\t// Enable / disable previous navigation.\n\t\tif ( this.currentIndex <= 1 ) {\n\t\t\tprevious?.setAttribute( 'disabled', 'yes' );\n\n\t\t\t// Set aria-disabled on previous button.\n\t\t\tif ( ariaEnabled ) {\n\t\t\t\tpreviousButton?.setAttribute( 'aria-disabled', 'true' );\n\t\t\t}\n\t\t} else {\n\t\t\tprevious?.removeAttribute( 'disabled' );\n\n\t\t\t// Remove aria-disabled from previous button.\n\t\t\tif ( ariaEnabled ) {\n\t\t\t\tpreviousButton?.removeAttribute( 'aria-disabled' );\n\t\t\t}\n\t\t}\n\n\t\t// Enable / disable next navigation.\n\t\tif ( this.currentIndex < allGroups.length ) {\n\t\t\tnext?.removeAttribute( 'disabled' );\n\n\t\t\t// Remove aria-disabled from next button.\n\t\t\tif ( ariaEnabled ) {\n\t\t\t\t// Next is at the end, disable it.\n\t\t\t\tnextButton?.removeAttribute( 'aria-disabled' );\n\t\t\t}\n\t\t} else {\n\t\t\tnext?.setAttribute( 'disabled', 'yes' );\n\n\t\t\t// Set aria-disabled on next button.\n\t\t\tif ( ariaEnabled ) {\n\t\t\t\tnextButton?.setAttribute( 'aria-disabled', 'true' );\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Prepare image loading.\n\t */\n\tprepareImageLoading(): void {\n\t\t// Get lightbox content element.\n\t\tconst content: TPLightboxContentElement | null = this.querySelector( 'tp-lightbox-content' );\n\n\t\t// Bail early if we don't have content.\n\t\tif ( ! content ) {\n\t\t\t// Exit.\n\t\t\treturn;\n\t\t}\n\n\t\t// Bail if there are no images within current content.\n\t\tconst images: NodeListOf<HTMLImageElement> = content.querySelectorAll( 'img' );\n\n\t\t// Exit early if there are no images.\n\t\tif ( ! images.length ) {\n\t\t\tthis.removeAttribute( 'loading' );\n\n\t\t\t// Exit.\n\t\t\treturn;\n\t\t}\n\n\t\t// Start off by setting the state as loading.\n\t\tthis.setAttribute( 'loading', 'yes' );\n\n\t\t// Prepare increment variables.\n\t\tlet counter: number = 0;\n\t\tconst totalImages: number = images.length;\n\n\t\t/**\n\t\t * Increment counter.\n\t\t */\n\t\tconst incrementLoadingCounter = (): void => {\n\t\t\t// Increment\n\t\t\tcounter++;\n\n\t\t\t// Remove loading attribute once all images have loaded.\n\t\t\tif ( counter === totalImages ) {\n\t\t\t\tthis.removeAttribute( 'loading' );\n\t\t\t}\n\t\t};\n\n\t\t// Check if images have loaded, else add an event listener.\n\t\timages.forEach( ( image: HTMLImageElement ): void => {\n\t\t\t// Check if image has loaded.\n\t\t\tif ( image.complete ) {\n\t\t\t\tincrementLoadingCounter();\n\t\t\t} else {\n\t\t\t\timage.addEventListener( 'load', incrementLoadingCounter, { once: true } );\n\t\t\t}\n\t\t} );\n\t}\n\n\t/**\n\t * Handle when the dialog is clicked.\n\t *\n\t * @param {Event} e Click event.\n\t */\n\thandleDialogClick( e: MouseEvent ): void {\n\t\t// Close on overlay click.\n\t\tif (\n\t\t\t'yes' === this.getAttribute( 'close-on-overlay-click' ) &&\n\t\t\tthis.querySelector( 'dialog' ) === e.target\n\t\t) {\n\t\t\tthis.close();\n\t\t}\n\t}\n\n\t/**\n\t * Handles the touch start event.\n\t *\n\t * @param { TouchEvent } evt The touch event.\n\t */\n\thandleTouchStart( evt: TouchEvent ): void {\n\t\t// Check if we should allow swiping?\n\t\tif ( 'yes' !== this.getAttribute( 'swipe' ) ) {\n\t\t\t// Nope.\n\t\t\treturn;\n\t\t}\n\n\t\t// Set the start points.\n\t\tthis.touchStartX = evt.touches[ 0 ].clientX;\n\t\tthis.touchStartY = evt.touches[ 0 ].clientY;\n\t}\n\n\t/**\n\t * Handles the touch end event.\n\t *\n\t * @param { TouchEvent } evt The touch event.\n\t */\n\thandleTouchEnd( evt: TouchEvent ): void {\n\t\t// Check if we should allow swiping?\n\t\tif ( 'yes' !== this.getAttribute( 'swipe' ) ) {\n\t\t\t// Nope.\n\t\t\treturn;\n\t\t}\n\n\t\t// Calculate the distances.\n\t\tconst touchEndX: number = evt.changedTouches[ 0 ].clientX;\n\t\tconst touchEndY: number = evt.changedTouches[ 0 ].clientY;\n\t\tconst swipeDistanceX: number = touchEndX - this.touchStartX;\n\t\tconst swipeDistanceY: number = touchEndY - this.touchStartY;\n\n\t\t// Is this horizontal swipe?\n\t\tconst isHorizontalSwipe = Math.abs( swipeDistanceX ) > Math.abs( swipeDistanceY );\n\n\t\t// Check if this was a horizontal swipe?\n\t\tif ( ! isHorizontalSwipe ) {\n\t\t\t// Bail.\n\t\t\treturn;\n\t\t}\n\n\t\t// Swipe settings\n\t\tthis.swipeThreshold = Number( this.getAttribute( 'swipe-threshold' ) ?? '200' );\n\n\t\t// Check if it's a right or left swipe.\n\t\tif ( swipeDistanceX > 0 ) {\n\t\t\t// Right-Swipe: Check if horizontal swipe distance is less than the threshold.\n\t\t\tif ( swipeDistanceX < this.swipeThreshold ) {\n\t\t\t\tthis.previous();\n\t\t\t}\n\t\t} else if ( swipeDistanceX < 0 ) {\n\t\t\t// Left-Swipe: Check if horizontal swipe distance is less than the threshold.\n\t\t\tif ( swipeDistanceX > -this.swipeThreshold ) {\n\t\t\t\tthis.next();\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Update current item in navigation.\n\t */\n\tupdateNavCurrentItem(): void {\n\t\t// Bail if we don't have nav items.\n\t\tif ( ! this.lightboxNavItems ) {\n\t\t\t// Exit.\n\t\t\treturn;\n\t\t}\n\n\t\t// Check if ARIA management is enabled.\n\t\tconst ariaEnabled = this.isAriaEnabled();\n\n\t\t// Update current item.\n\t\tthis.lightboxNavItems.forEach( ( navItem: TPLightboxNavItemElement, index: number ): void => {\n\t\t\t// Get the button inside the nav item.\n\t\t\tconst button: HTMLButtonElement | null = navItem.querySelector( 'button' );\n\n\t\t\t// Update current attribute.\n\t\t\tif ( this.currentIndex - 1 === index ) {\n\t\t\t\tnavItem.setAttribute( 'current', 'yes' );\n\n\t\t\t\t// Set aria-current on the button (if ARIA is enabled).\n\t\t\t\tif ( ariaEnabled && button ) {\n\t\t\t\t\tbutton.setAttribute( 'aria-current', 'true' );\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tnavItem.removeAttribute( 'current' );\n\n\t\t\t\t// Remove aria-current from the button (if ARIA is enabled).\n\t\t\t\tif ( ariaEnabled && button ) {\n\t\t\t\t\tbutton.removeAttribute( 'aria-current' );\n\t\t\t\t}\n\t\t\t}\n\t\t} );\n\t}\n\n\t/**\n\t * Set initial focus when lightbox opens.\n\t * Looks for [autofocus] element, otherwise focuses the dialog.\n\t */\n\tprivate setInitialFocus(): void {\n\t\t// Look for an element with autofocus attribute.\n\t\tconst autofocusElement = this.querySelector<HTMLElement>( '[autofocus]' );\n\n\t\t// Do we have an autofocus element?\n\t\tif ( autofocusElement ) {\n\t\t\tautofocusElement.focus();\n\n\t\t\t// Early return.\n\t\t\treturn;\n\t\t}\n\n\t\t// Otherwise, focus the dialog itself.\n\t\tthis.dialogElement?.focus();\n\t}\n\n\t/**\n\t * Handle keydown events for arrow navigation.\n\t *\n\t * @param {KeyboardEvent} e Keyboard event.\n\t */\n\tprivate handleKeyDown( e: KeyboardEvent ): void {\n\t\t// Check if arrow navigation is enabled (disabled by default).\n\t\tif ( 'yes' !== this.getAttribute( 'arrow-navigation' ) ) {\n\t\t\t// Early return.\n\t\t\treturn;\n\t\t}\n\n\t\t// Navigate on arrow keys.\n\t\tif ( 'ArrowLeft' === e.key ) {\n\t\t\te.preventDefault();\n\t\t\tthis.previous();\n\t\t} else if ( 'ArrowRight' === e.key ) {\n\t\t\te.preventDefault();\n\t\t\tthis.next();\n\t\t}\n\t}\n}\n","/**\n * TP Lightbox Content.\n */\nexport class TPLightboxContentElement extends HTMLElement {\n}\n","/**\n * Internal dependencies.\n */\nimport { TPLightboxElement } from './tp-lightbox';\n\n/**\n * TP Lightbox Close.\n */\nexport class TPLightboxCloseElement extends HTMLElement {\n\t/**\n\t * Constructor.\n\t */\n\tconstructor() {\n\t\t// Initialize parent.\n\t\tsuper();\n\n\t\t// Events.\n\t\tthis.querySelector( 'button' )?.addEventListener( 'click', this.close.bind( this ) );\n\t}\n\n\t/**\n\t * Close the lightbox.\n\t */\n\tclose(): void {\n\t\t// Get lightbox.\n\t\tconst lightbox: TPLightboxElement | null = this.closest( 'tp-lightbox' );\n\n\t\t// Check if we have a lightbox.\n\t\tif ( lightbox ) {\n\t\t\tsetTimeout( (): void => {\n\t\t\t\t// Close the lightbox.\n\t\t\t\tlightbox.close();\n\t\t\t}, 0 );\n\t\t}\n\t}\n}\n","/**\n * Internal dependencies.\n */\nimport { TPLightboxElement } from './tp-lightbox';\n\n/**\n * TP Lightbox Close.\n */\nexport class TPLightboxPreviousElement extends HTMLElement {\n\t/**\n\t * Constructor.\n\t */\n\tconstructor() {\n\t\t// Initialize parent.\n\t\tsuper();\n\n\t\t// Events.\n\t\tthis.querySelector( 'button' )?.addEventListener( 'click', this.previous.bind( this ) );\n\t}\n\n\t/**\n\t * Navigate previous.\n\t */\n\tprevious(): void {\n\t\t// Check if we are disabled.\n\t\tif ( 'yes' === this.getAttribute( 'disabled' ) ) {\n\t\t\t// No we don't. Exit.\n\t\t\treturn;\n\t\t}\n\n\t\t// Get lightbox.\n\t\tconst lightbox: TPLightboxElement | null = this.closest( 'tp-lightbox' );\n\n\t\t// Check if we have a lightbox.\n\t\tif ( lightbox ) {\n\t\t\tsetTimeout( (): void => {\n\t\t\t\t// Previous.\n\t\t\t\tlightbox.previous();\n\t\t\t}, 0 );\n\t\t}\n\t}\n}\n","/**\n * Internal dependencies.\n */\nimport { TPLightboxElement } from './tp-lightbox';\n\n/**\n * TP Lightbox Close.\n */\nexport class TPLightboxNextElement extends HTMLElement {\n\t/**\n\t * Constructor.\n\t */\n\tconstructor() {\n\t\t// Initialize parent.\n\t\tsuper();\n\n\t\t// Events.\n\t\tthis.querySelector( 'button' )?.addEventListener( 'click', this.next.bind( this ) );\n\t}\n\n\t/**\n\t * Navigate next.\n\t */\n\tnext(): void {\n\t\t// Check if next is disabled.\n\t\tif ( 'yes' === this.getAttribute( 'disabled' ) ) {\n\t\t\t// Yes it is. Exit.\n\t\t\treturn;\n\t\t}\n\n\t\t// Get lightbox.\n\t\tconst lightbox: TPLightboxElement | null = this.closest( 'tp-lightbox' );\n\n\t\t// Check if we have a lightbox.\n\t\tif ( lightbox ) {\n\t\t\tsetTimeout( (): void => {\n\t\t\t\t// Initiate next.\n\t\t\t\tlightbox.next();\n\t\t\t}, 0 );\n\t\t}\n\t}\n}\n","/**\n * Internal dependencies.\n */\nimport { TPLightboxElement } from './tp-lightbox';\n\n/**\n * TP Slider Count.\n */\nexport class TPLightboxCountElement extends HTMLElement {\n\t/**\n\t * Get observed attributes.\n\t *\n\t * @return {Array} Observed attributes.\n\t */\n\tstatic get observedAttributes(): string[] {\n\t\t// Attributes to observe.\n\t\treturn [ 'format' ];\n\t}\n\n\t/**\n\t * Get format.\n\t *\n\t * @return {string} Format.\n\t */\n\tget format(): string {\n\t\t// Get format.\n\t\treturn this.getAttribute( 'format' ) ?? '$current / $total';\n\t}\n\n\t/**\n\t * Set format.\n\t *\n\t * @param {string} format Format.\n\t */\n\tset format( format: string ) {\n\t\t// Set the 'format' attribute value.\n\t\tthis.setAttribute( 'format', format );\n\t}\n\n\t/**\n\t * Attribute changed callback.\n\t */\n\tattributeChangedCallback(): void {\n\t\t// On change of format attribute, update the component.\n\t\tthis.update();\n\t}\n\n\t/**\n\t * Update component.\n\t */\n\tupdate(): void {\n\t\t// Get lightbox.\n\t\tconst lightbox: TPLightboxElement | null = this.closest( 'tp-lightbox' );\n\n\t\t// Check if we have a lightbox.\n\t\tif ( ! lightbox ) {\n\t\t\t// Exit.\n\t\t\treturn;\n\t\t}\n\n\t\t// Get current and total.\n\t\tconst current: string = lightbox.currentIndex.toString();\n\t\tconst total: string = lightbox.getAttribute( 'total' ) ?? '';\n\n\t\t// Update variables in format attribute (using textContent for XSS protection).\n\t\tthis.textContent =\n\t\t\tthis.format\n\t\t\t\t.replace( '$current', current )\n\t\t\t\t.replace( '$total', total );\n\n\t\t// Update current and total attributes.\n\t\tthis.setAttribute( 'current', current );\n\t\tthis.setAttribute( 'total', total );\n\t}\n}\n","/**\n * Internal dependencies.\n */\nimport { TPLightboxElement } from './tp-lightbox';\n\n/**\n * TP Lightbox Trigger.\n */\nexport class TPLightboxTriggerElement extends HTMLElement {\n\t/**\n\t * Constructor.\n\t */\n\tconstructor() {\n\t\t// Initialize parent.\n\t\tsuper();\n\n\t\t// Events.\n\t\tthis.querySelector( 'button' )?.addEventListener( 'click', this.trigger.bind( this ) );\n\t}\n\n\t/**\n\t * Trigger the lightbox.\n\t */\n\ttrigger(): void {\n\t\t// Get lightbox ID and template.\n\t\tconst lightboxId: string | null = this.getAttribute( 'lightbox' );\n\t\tconst template: HTMLTemplateElement | null = this.querySelector( 'template' );\n\n\t\t// We can't proceed without them.\n\t\tif ( ! lightboxId || ! template ) {\n\t\t\t// Exit.\n\t\t\treturn;\n\t\t}\n\n\t\t// Get the lightbox.\n\t\tconst lightbox: TPLightboxElement | null = document.querySelector( `#${ lightboxId.toString() }` );\n\n\t\t// Check to see if we have a lightbox.\n\t\tif ( ! lightbox ) {\n\t\t\t// Exit.\n\t\t\treturn;\n\t\t}\n\n\t\t// Check to see if we have a group.\n\t\tconst group: string = this.getAttribute( 'group' ) ?? '';\n\n\t\t// Yield to main thread.\n\t\tsetTimeout( (): void => {\n\t\t\t// Prepare lightbox.\n\t\t\tlightbox.template = template;\n\t\t\tlightbox.group = group;\n\n\t\t\t// Set index and group if we have them.\n\t\t\tif ( '' !== group ) {\n\t\t\t\tconst allGroups: NodeListOf<TPLightboxTriggerElement> = document.querySelectorAll( `tp-lightbox-trigger[group=\"${ group }\"]` );\n\n\t\t\t\t// Update all groups.\n\t\t\t\tif ( allGroups.length ) {\n\t\t\t\t\t/**\n\t\t\t\t\t * We do this when we're opening a lightbox, or navigating.\n\t\t\t\t\t * This allows consumers to inject elements at any point.\n\t\t\t\t\t */\n\t\t\t\t\tlightbox.updateAllGroups( allGroups );\n\n\t\t\t\t\t// Get current trigger's index within the group.\n\t\t\t\t\tallGroups.forEach( ( triggerElement: TPLightboxTriggerElement, index: number ): void => {\n\t\t\t\t\t\t// Update current index.\n\t\t\t\t\t\tif ( this === triggerElement ) {\n\t\t\t\t\t\t\tlightbox.currentIndex = index + 1;\n\t\t\t\t\t\t}\n\t\t\t\t\t} );\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// All done, lets open the lightbox.\n\t\t\tlightbox.open();\n\t\t}, 0 );\n\t}\n}\n","/**\n * Internal dependencies.\n */\nimport { TPLightboxElement } from './tp-lightbox';\n\n/**\n * TP Lightbox Nav.\n */\nexport class TPLightboxNavElement extends HTMLElement {\n\t/**\n\t * Properties.\n\t */\n\tprotected template: HTMLTemplateElement | null = null;\n\tprotected lightbox : TPLightboxElement | null;\n\n\t/**\n\t * Constructor.\n\t */\n\tconstructor() {\n\t\t// Initialize parent.\n\t\tsuper();\n\n\t\t// Initialize properties.\n\t\tthis.template = this.querySelector( 'template' );\n\t\tthis.lightbox = this.closest( 'tp-lightbox' );\n\n\t\t// Add event listener.\n\t\tthis.lightbox?.addEventListener( 'template-set', this.setTemplate.bind( this ) );\n\t}\n\n\t/**\n\t * Set the template.\n\t */\n\tsetTemplate(): void {\n\t\t// Bail if no template.\n\t\tif ( ! this.template ) {\n\t\t\t// Exit.\n\t\t\treturn;\n\t\t}\n\n\t\t// Total slides.\n\t\tconst totalSlides = Number( this.lightbox?.getAttribute( 'total' ) ?? 0 );\n\n\t\t// Clear the navigation.\n\t\tthis.innerHTML = '';\n\n\t\t// Append the navigation items.\n\t\tfor ( let i = 0; i < totalSlides; i++ ) {\n\t\t\t// Clone the template.\n\t\t\tconst navItem = this.template.content.cloneNode( true );\n\n\t\t\t// Append the clone.\n\t\t\tthis.appendChild( navItem );\n\t\t}\n\t}\n}\n","/**\n * Internal dependencies.\n */\nimport { TPLightboxElement } from './tp-lightbox';\nimport { TPLightboxNavElement } from './tp-lightbox-nav';\n\n/**\n * TP Lightbox Nav Item.\n */\nexport class TPLightboxNavItemElement extends HTMLElement {\n\t/**\n\t * Properties.\n\t */\n\tprotected lightbox : TPLightboxElement | null;\n\n\t/**\n\t * Constructor.\n\t */\n\tconstructor() {\n\t\t// Initialize parent.\n\t\tsuper();\n\t\tthis.lightbox = this.closest( 'tp-lightbox' );\n\n\t\t// Get the nav-item button.\n\t\tthis.querySelector( 'button' )?.addEventListener( 'click', this.handleClick.bind( this ) );\n\t}\n\n\t/**\n\t * Handle when the button is clicked.\n\t */\n\thandleClick(): void {\n\t\t// Check if lightbox exists.\n\t\tif ( ! this.lightbox ) {\n\t\t\t// No its not! Terminate.\n\t\t\treturn;\n\t\t}\n\n\t\t// Set current slide.\n\t\tthis.lightbox.currentIndex = Number( this.getIndex() ) ?? 1;\n\n\t\t// Update navigation current item.\n\t\tthis.lightbox.updateNavCurrentItem();\n\t}\n\n\t/**\n\t * Get index of this item inside the navigation.\n\t *\n\t * @return {number} Index.\n\t */\n\tgetIndex(): number {\n\t\t// Bail if no lightbox.\n\t\tif ( ! this.lightbox ) {\n\t\t\t// Exit.\n\t\t\treturn 0;\n\t\t}\n\n\t\t// No, find it in the navigation.\n\t\tconst lightboxNav: TPLightboxNavElement | null = this.closest( 'tp-lightbox-nav' );\n\n\t\t// Return index of this element considering the step value.\n\t\treturn ( Array.from( lightboxNav?.children ?? [] ).indexOf( this ) ) + 1;\n\t}\n}\n","/**\n * Styles.\n */\nimport './style.scss';\n\n/**\n * Components.\n */\nimport { TPLightboxElement } from './tp-lightbox';\nimport { TPLightboxContentElement } from './tp-lightbox-content';\nimport { TPLightboxCloseElement } from './tp-lightbox-close';\nimport { TPLightboxPreviousElement } from './tp-lightbox-previous';\nimport { TPLightboxNextElement } from './tp-lightbox-next';\nimport { TPLightboxCountElement } from './tp-lightbox-count';\nimport { TPLightboxTriggerElement } from './tp-lightbox-trigger';\nimport { TPLightboxNavElement } from './tp-lightbox-nav';\nimport { TPLightboxNavItemElement } from './tp-lightbox-nav-item';\n\n/**\n * Register Components.\n */\ncustomElements.define( 'tp-lightbox', TPLightboxElement );\ncustomElements.define( 'tp-lightbox-content', TPLightboxContentElement );\ncustomElements.define( 'tp-lightbox-close', TPLightboxCloseElement );\ncustomElements.define( 'tp-lightbox-previous', TPLightboxPreviousElement );\ncustomElements.define( 'tp-lightbox-next', TPLightboxNextElement );\ncustomElements.define( 'tp-lightbox-count', TPLightboxCountElement );\ncustomElements.define( 'tp-lightbox-trigger', TPLightboxTriggerElement );\ncustomElements.define( 'tp-lightbox-nav', TPLightboxNavElement );\ncustomElements.define( 'tp-lightbox-nav-item', TPLightboxNavItemElement );\n"],"names":["TPLightboxElement","HTMLElement","constructor","super","currentTemplate","currentGroup","allGroups","touchStartX","touchStartY","swipeThreshold","previouslyFocusedElement","this","boundHandleKeyDown","handleKeyDown","bind","dialogElement","querySelector","lightboxNavItems","querySelectorAll","addEventListener","handleDialogClick","handleTouchStart","handleTouchEnd","observedAttributes","attributeChangedCallback","name","oldValue","newValue","dispatchEvent","CustomEvent","triggerCurrentIndexTarget","updateNavCurrentItem","isAriaEnabled","getAttribute","template","content","templateContent","cloneNode","replaceChildren","setTimeout","prepareImageLoading","prepareNavigation","innerHTML","group","currentIndex","parseInt","index","setAttribute","toString","detail","slideIndex","getAllGroups","trigger","open","dialog","ownerDocument","activeElement","updateAllGroups","showModal","document","setInitialFocus","close","removeEventListener","removeAttribute","focus","previous","next","length","count","update","previousButton","nextButton","ariaEnabled","images","counter","totalImages","incrementLoadingCounter","forEach","image","complete","once","e","target","evt","touches","clientX","clientY","touchEndX","changedTouches","touchEndY","swipeDistanceX","swipeDistanceY","Math","abs","Number","navItem","button","autofocusElement","key","preventDefault","TPLightboxContentElement","TPLightboxCloseElement","lightbox","closest","TPLightboxPreviousElement","TPLightboxNextElement","TPLightboxCountElement","format","current","total","textContent","replace","TPLightboxTriggerElement","lightboxId","triggerElement","TPLightboxNavElement","setTemplate","totalSlides","i","appendChild","TPLightboxNavItemElement","handleClick","getIndex","lightboxNav","Array","from","children","indexOf","customElements","define"],"sourceRoot":""}
1
+ {"version":3,"file":"dist/lightbox/index.js","mappings":"mBAaO,MAAMA,UAA0BC,YAkBtC,WAAAC,G,YAECC,QAhBS,KAAAC,gBAA8C,KAC9C,KAAAC,aAAuB,GACvB,KAAAC,UAAyD,KACzD,KAAAC,YAAsB,EACtB,KAAAC,YAAsB,EACtB,KAAAC,eAAyB,IAGzB,KAAAC,yBAA+C,KAWxDC,KAAKC,mBAAqBD,KAAKE,cAAcC,KAAMH,MAGnDA,KAAKI,cAAgBJ,KAAKK,cAAe,UACzCL,KAAKM,iBAAmBN,KAAKO,iBAAkB,wBAG7B,QAAlB,EAAAP,KAAKI,qBAAa,SAAEI,iBAAkB,QAASR,KAAKS,kBAAkBN,KAAMH,OAC1D,QAAlB,EAAAA,KAAKI,qBAAa,SAAEI,iBAAkB,aAAcR,KAAKU,iBAAiBP,KAAMH,OAC9D,QAAlB,EAAAA,KAAKI,qBAAa,SAAEI,iBAAkB,WAAYR,KAAKW,eAAeR,KAAMH,OAC1D,QAAlB,EAAAA,KAAKI,qBAAa,SAAEI,iBAAkB,QAASR,KAAKY,kBAAkBT,KAAMH,MAC7E,CAOA,6BAAWa,GAEV,MAAO,CAAE,OAAQ,QAAS,QAAS,yBAA0B,UAC9D,CASA,wBAAAC,CAA0BC,EAAe,GAAIC,EAAmB,GAAIC,EAAmB,IAEjFD,IAAaC,IAMlBjB,KAAKkB,cAAe,IAAIC,YAAa,WAGhC,UAAYJ,GAChBf,KAAKoB,4BAID,SAAWL,GAAQ,UAAYA,GACnCf,KAAKqB,uBAEP,CAOA,aAAAC,GAEC,MAAO,OAAStB,KAAKuB,aAAc,OACpC,CAKA,YAAIC,GAEH,OAAOxB,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ts","webpack://@travelopia/web-components/./src/lightbox/tp-lightbox-close.ts","webpack://@travelopia/web-components/./src/lightbox/tp-lightbox-previous.ts","webpack://@travelopia/web-components/./src/lightbox/tp-lightbox-next.ts","webpack://@travelopia/web-components/./src/lightbox/tp-lightbox-count.ts","webpack://@travelopia/web-components/./src/lightbox/tp-lightbox-trigger.ts","webpack://@travelopia/web-components/./src/lightbox/tp-lightbox-nav.ts","webpack://@travelopia/web-components/./src/lightbox/tp-lightbox-nav-item.ts","webpack://@travelopia/web-components/./src/lightbox/index.ts"],"sourcesContent":["/**\n * Internal dependencies.\n */\nimport { TPLightboxContentElement } from './tp-lightbox-content';\nimport { TPLightboxPreviousElement } from './tp-lightbox-previous';\nimport { TPLightboxNextElement } from './tp-lightbox-next';\nimport { TPLightboxTriggerElement } from './tp-lightbox-trigger';\nimport { TPLightboxCountElement } from './tp-lightbox-count';\nimport { TPLightboxNavItemElement } from './tp-lightbox-nav-item';\n\n/**\n * TP Lightbox.\n */\nexport class TPLightboxElement extends HTMLElement {\n\t/**\n\t * Properties.\n\t */\n\tprotected currentTemplate: HTMLTemplateElement | null = null;\n\tprotected currentGroup: string = '';\n\tprotected allGroups: NodeListOf<TPLightboxTriggerElement> | null = null;\n\tprotected touchStartX: number = 0;\n\tprotected touchStartY: number = 0;\n\tprotected swipeThreshold: number = 200;\n\tprotected dialogElement: HTMLDialogElement | null;\n\tprotected lightboxNavItems: NodeListOf<TPLightboxNavItemElement> | null;\n\tprotected previouslyFocusedElement: HTMLElement | null = null;\n\tprotected readonly boundHandleKeyDown: ( e: KeyboardEvent ) => void;\n\n\t/**\n\t * Constructor.\n\t */\n\tconstructor() {\n\t\t// Initialize parent.\n\t\tsuper();\n\n\t\t// Bind event handlers.\n\t\tthis.boundHandleKeyDown = this.handleKeyDown.bind( this );\n\n\t\t// Initialize\n\t\tthis.dialogElement = this.querySelector( 'dialog' );\n\t\tthis.lightboxNavItems = this.querySelectorAll( 'tp-lightbox-nav-item' );\n\n\t\t// Event listeners.\n\t\tthis.dialogElement?.addEventListener( 'click', this.handleDialogClick.bind( this ) );\n\t\tthis.dialogElement?.addEventListener( 'touchstart', this.handleTouchStart.bind( this ) );\n\t\tthis.dialogElement?.addEventListener( 'touchend', this.handleTouchEnd.bind( this ) );\n\t\tthis.dialogElement?.addEventListener( 'close', this.handleDialogClose.bind( this ) );\n\t}\n\n\t/**\n\t * Get observed attributes.\n\t *\n\t * @return {Array} List of observed attributes.\n\t */\n\tstatic get observedAttributes(): string[] {\n\t\t// Attributes to observe.\n\t\treturn [ 'open', 'index', 'total', 'close-on-overlay-click', 'loading' ];\n\t}\n\n\t/**\n\t * Attribute changed callback.\n\t *\n\t * @param {string} name Attribute name.\n\t * @param {string} oldValue Old value.\n\t * @param {string} newValue New value.\n\t */\n\tattributeChangedCallback( name: string = '', oldValue: string = '', newValue: string = '' ): void {\n\t\t// Prevent redundant updates.\n\t\tif ( oldValue === newValue ) {\n\t\t\t// Early return.\n\t\t\treturn;\n\t\t}\n\n\t\t// Trigger change event.\n\t\tthis.dispatchEvent( new CustomEvent( 'change' ) );\n\n\t\t// Trigger current index target if index has changed.\n\t\tif ( 'index' === name ) {\n\t\t\tthis.triggerCurrentIndexTarget();\n\t\t}\n\n\t\t// Trigger navigation update if open or index has changed.\n\t\tif ( 'open' === name || 'index' === name ) {\n\t\t\tthis.updateNavCurrentItem();\n\t\t}\n\t}\n\n\t/**\n\t * Check if ARIA management is enabled.\n\t *\n\t * @return {boolean} Whether ARIA is enabled.\n\t */\n\tisAriaEnabled(): boolean {\n\t\t// Return whether ARIA management is enabled (default: yes).\n\t\treturn 'no' !== this.getAttribute( 'aria' );\n\t}\n\n\t/**\n\t * Get template.\n\t */\n\tget template(): HTMLTemplateElement | null {\n\t\t// Return current template.\n\t\treturn this.currentTemplate;\n\t}\n\n\t/**\n\t * Set template.\n\t *\n\t * @param {HTMLTemplateElement} template The template.\n\t */\n\tset template( template: HTMLTemplateElement | null ) {\n\t\t// Set the template.\n\t\tthis.currentTemplate = template;\n\t\tthis.dispatchEvent( new CustomEvent( 'template-set' ) );\n\n\t\t// Get lightbox content element.\n\t\tconst content: TPLightboxContentElement | null = this.querySelector( 'tp-lightbox-content' );\n\n\t\t// Check if we have a content.\n\t\tif ( ! content ) {\n\t\t\t// No we don't. Exit.\n\t\t\treturn;\n\t\t}\n\n\t\t// Check if we have a template.\n\t\tif ( this.currentTemplate ) {\n\t\t\t/**\n\t\t\t * We do, update content with template's content.\n\t\t\t * We do this rather than a string to avoid script injection.\n\t\t\t */\n\t\t\tconst templateContent: Node = this.currentTemplate.content.cloneNode( true );\n\t\t\tcontent.replaceChildren( templateContent );\n\t\t\tthis.dispatchEvent( new CustomEvent( 'content-change' ) );\n\n\t\t\t// Prepare image loading.\n\t\t\tsetTimeout( (): void => {\n\t\t\t\t// We do, prepare image loading.\n\t\t\t\tthis.prepareImageLoading();\n\t\t\t\tthis.prepareNavigation();\n\t\t\t}, 0 );\n\t\t} else {\n\t\t\t// We don't, set content as empty.\n\t\t\tcontent.innerHTML = '';\n\t\t}\n\t}\n\n\t/**\n\t * Get current group.\n\t */\n\tget group(): string {\n\t\t// Return current group.\n\t\treturn this.currentGroup;\n\t}\n\n\t/**\n\t * Set current group.\n\t *\n\t * @param {string} group Group name.\n\t */\n\tset group( group: string ) {\n\t\t// Set current group.\n\t\tthis.currentGroup = group;\n\t}\n\n\t/**\n\t * Get current index.\n\t */\n\tget currentIndex(): number {\n\t\t// Return current index.\n\t\treturn parseInt( this.getAttribute( 'index' ) ?? '1' );\n\t}\n\n\t/**\n\t * Set current index.\n\t *\n\t * @param {number} index Current index.\n\t */\n\tset currentIndex( index: number ) {\n\t\t// Set current index.\n\t\tif ( index < 1 ) {\n\t\t\tindex = 1;\n\t\t}\n\n\t\t// Setting this attributes triggers a re-trigger.\n\t\tthis.setAttribute( 'index', index.toString() );\n\n\t\t// dispatch slide-set event.\n\t\tthis.dispatchEvent( new CustomEvent( 'slide-set', {\n\t\t\tdetail: {\n\t\t\t\tslideIndex: index,\n\t\t\t},\n\t\t} ) );\n\t}\n\n\t/**\n\t * Trigger the target that matches the current index within current group.\n\t */\n\ttriggerCurrentIndexTarget(): void {\n\t\t// Get all groups and check if current index exists within group.\n\t\tconst allGroups: NodeListOf<TPLightboxTriggerElement> | null = this.getAllGroups();\n\n\t\t// Bail early if we don't have groups.\n\t\tif ( ! allGroups || ! allGroups[ this.currentIndex - 1 ] ) {\n\t\t\t// No we don't. Exit.\n\t\t\treturn;\n\t\t}\n\n\t\t// Trigger element within group.\n\t\tallGroups[ this.currentIndex - 1 ].trigger();\n\t}\n\n\t/**\n\t * Open lightbox.\n\t */\n\topen(): void {\n\t\t// Get the dialog element.\n\t\tconst dialog: HTMLDialogElement | null = this.querySelector( 'dialog' );\n\n\t\t// Check if dialog exists or is already open.\n\t\tif ( ! dialog || dialog.open ) {\n\t\t\t// Yes it is, Exit.\n\t\t\treturn;\n\t\t}\n\n\t\t// Save the currently focused element to restore later (if manage-focus is enabled).\n\t\tif ( 'no' !== this.getAttribute( 'manage-focus' ) ) {\n\t\t\tthis.previouslyFocusedElement = this.ownerDocument.activeElement as HTMLElement;\n\t\t}\n\n\t\t// First, take this opportunity to update all groups (if it wasn't set from the trigger).\n\t\tif ( '' !== this.group && ! this.allGroups ) {\n\t\t\tthis.updateAllGroups();\n\t\t}\n\n\t\t// Now, show the modal.\n\t\tdialog.showModal();\n\t\tthis.setAttribute( 'open', 'yes' );\n\n\t\t// Add keyboard event listener for arrow navigation.\n\t\tdocument.addEventListener( 'keydown', this.boundHandleKeyDown );\n\n\t\t// Move focus into the lightbox (if manage-focus is enabled).\n\t\tif ( 'no' !== this.getAttribute( 'manage-focus' ) ) {\n\t\t\tthis.setInitialFocus();\n\t\t}\n\t}\n\n\t/**\n\t * Close lightbox.\n\t */\n\tclose(): void {\n\t\t// Remove keyboard event listener.\n\t\tdocument.removeEventListener( 'keydown', this.boundHandleKeyDown );\n\n\t\t// Find and close the dialog.\n\t\tconst dialog: HTMLDialogElement | null = this.querySelector( 'dialog' );\n\t\tdialog?.close();\n\t\tthis.removeAttribute( 'open' );\n\n\t\t// Restore focus to the previously focused element (if manage-focus is enabled).\n\t\tif ( 'no' !== this.getAttribute( 'manage-focus' ) && this.previouslyFocusedElement ) {\n\t\t\tthis.previouslyFocusedElement.focus();\n\t\t\tthis.previouslyFocusedElement = null;\n\t\t}\n\n\t\t// Clear groups from memory.\n\t\tthis.allGroups = null;\n\t}\n\n\t/**\n\t * Navigate previous.\n\t */\n\tprevious(): void {\n\t\t// Check if we even have a group.\n\t\tif ( '' === this.group ) {\n\t\t\t// No we don't. Exit.\n\t\t\treturn;\n\t\t}\n\n\t\t// Check if we have elements within group.\n\t\tconst allGroups: NodeListOf<TPLightboxTriggerElement> | null = this.getAllGroups();\n\n\t\t// Bail early if we don't have groups.\n\t\tif ( ! allGroups ) {\n\t\t\t// No we don't. Exit.\n\t\t\treturn;\n\t\t}\n\n\t\t// Decrement the current index.\n\t\tif ( this.currentIndex > 1 ) {\n\t\t\tthis.currentIndex--;\n\t\t}\n\t}\n\n\t/**\n\t * Navigate next.\n\t */\n\tnext(): void {\n\t\t// Check if we even have a group.\n\t\tif ( '' === this.group ) {\n\t\t\t// No we don't. Exit.\n\t\t\treturn;\n\t\t}\n\n\t\t// Check if we have elements within group.\n\t\tconst allGroups: NodeListOf<TPLightboxTriggerElement> | null = this.getAllGroups();\n\n\t\t// Bail early if we don't have groups.\n\t\tif ( ! allGroups ) {\n\t\t\t// No we don't. Exit.\n\t\t\treturn;\n\t\t}\n\n\t\t// Increment the current index.\n\t\tif ( this.currentIndex < allGroups.length ) {\n\t\t\tthis.currentIndex++;\n\t\t}\n\t}\n\n\t/**\n\t * Update all groups and save it to memory.\n\t *\n\t * @param {NodeList} allGroups All groups.\n\t */\n\tupdateAllGroups( allGroups: NodeListOf<TPLightboxTriggerElement> | null = null ): void {\n\t\t// Update all groups.\n\t\tif ( allGroups && allGroups.length ) {\n\t\t\tthis.allGroups = allGroups;\n\t\t\tthis.setAttribute( 'total', this.allGroups.length.toString() );\n\n\t\t\t// Exit.\n\t\t\treturn;\n\t\t}\n\n\t\t// Get all groups.\n\t\tthis.allGroups = document.querySelectorAll( `tp-lightbox-trigger[group=\"${ this.group }\"]` );\n\n\t\t// Update total.\n\t\tif ( ! this.allGroups.length ) {\n\t\t\tthis.allGroups = null;\n\t\t} else {\n\t\t\tthis.setAttribute( 'total', this.allGroups.length.toString() );\n\t\t}\n\t}\n\n\t/**\n\t * Get all groups from memory.\n\t */\n\tgetAllGroups(): NodeListOf<TPLightboxTriggerElement> | null {\n\t\t// Return all groups.\n\t\treturn this.allGroups;\n\t}\n\n\t/**\n\t * Prepare navigation.\n\t */\n\tprepareNavigation(): void {\n\t\t// Update all counters.\n\t\tconst counts: NodeListOf<TPLightboxCountElement> = this.querySelectorAll( 'tp-lightbox-count' );\n\t\tcounts.forEach( ( count: TPLightboxCountElement ): void => count.update() );\n\n\t\t// Get previous and next elements.\n\t\tconst previous: TPLightboxPreviousElement | null = this.querySelector( 'tp-lightbox-previous' );\n\t\tconst next: TPLightboxNextElement | null = this.querySelector( 'tp-lightbox-next' );\n\n\t\t// Bail early if we don't have either.\n\t\tif ( ! previous && ! next ) {\n\t\t\t// Exit.\n\t\t\treturn;\n\t\t}\n\n\t\t// Get buttons inside prev/next for ARIA.\n\t\tconst previousButton: HTMLButtonElement | null = previous?.querySelector( 'button' ) ?? null;\n\t\tconst nextButton: HTMLButtonElement | null = next?.querySelector( 'button' ) ?? null;\n\t\tconst ariaEnabled: boolean = this.isAriaEnabled();\n\n\t\t// Check if we have a group.\n\t\tif ( '' === this.group ) {\n\t\t\tprevious?.setAttribute( 'disabled', 'yes' );\n\t\t\tnext?.setAttribute( 'disabled', 'yes' );\n\n\t\t\t// Set aria-disabled on buttons.\n\t\t\tif ( ariaEnabled ) {\n\t\t\t\tpreviousButton?.setAttribute( 'aria-disabled', 'true' );\n\t\t\t\tnextButton?.setAttribute( 'aria-disabled', 'true' );\n\t\t\t}\n\n\t\t\t// Exit.\n\t\t\treturn;\n\t\t}\n\n\t\t// Check if we have elements within the group.\n\t\tconst allGroups: NodeListOf<TPLightboxTriggerElement> | null = this.getAllGroups();\n\n\t\t// Disable if we don't have any.\n\t\tif ( ! allGroups ) {\n\t\t\tprevious?.setAttribute( 'disabled', 'yes' );\n\t\t\tnext?.setAttribute( 'disabled', 'yes' );\n\n\t\t\t// Set aria-disabled on buttons.\n\t\t\tif ( ariaEnabled ) {\n\t\t\t\tpreviousButton?.setAttribute( 'aria-disabled', 'true' );\n\t\t\t\tnextButton?.setAttribute( 'aria-disabled', 'true' );\n\t\t\t}\n\n\t\t\t// Exit.\n\t\t\treturn;\n\t\t}\n\n\t\t// Enable / disable previous navigation.\n\t\tif ( this.currentIndex <= 1 ) {\n\t\t\tprevious?.setAttribute( 'disabled', 'yes' );\n\n\t\t\t// Set aria-disabled on previous button.\n\t\t\tif ( ariaEnabled ) {\n\t\t\t\tpreviousButton?.setAttribute( 'aria-disabled', 'true' );\n\t\t\t}\n\t\t} else {\n\t\t\tprevious?.removeAttribute( 'disabled' );\n\n\t\t\t// Remove aria-disabled from previous button.\n\t\t\tif ( ariaEnabled ) {\n\t\t\t\tpreviousButton?.removeAttribute( 'aria-disabled' );\n\t\t\t}\n\t\t}\n\n\t\t// Enable / disable next navigation.\n\t\tif ( this.currentIndex < allGroups.length ) {\n\t\t\tnext?.removeAttribute( 'disabled' );\n\n\t\t\t// Remove aria-disabled from next button.\n\t\t\tif ( ariaEnabled ) {\n\t\t\t\t// Next is at the end, disable it.\n\t\t\t\tnextButton?.removeAttribute( 'aria-disabled' );\n\t\t\t}\n\t\t} else {\n\t\t\tnext?.setAttribute( 'disabled', 'yes' );\n\n\t\t\t// Set aria-disabled on next button.\n\t\t\tif ( ariaEnabled ) {\n\t\t\t\tnextButton?.setAttribute( 'aria-disabled', 'true' );\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Prepare image loading.\n\t */\n\tprepareImageLoading(): void {\n\t\t// Get lightbox content element.\n\t\tconst content: TPLightboxContentElement | null = this.querySelector( 'tp-lightbox-content' );\n\n\t\t// Bail early if we don't have content.\n\t\tif ( ! content ) {\n\t\t\t// Exit.\n\t\t\treturn;\n\t\t}\n\n\t\t// Bail if there are no images within current content.\n\t\tconst images: NodeListOf<HTMLImageElement> = content.querySelectorAll( 'img' );\n\n\t\t// Exit early if there are no images.\n\t\tif ( ! images.length ) {\n\t\t\tthis.removeAttribute( 'loading' );\n\n\t\t\t// Exit.\n\t\t\treturn;\n\t\t}\n\n\t\t// Start off by setting the state as loading.\n\t\tthis.setAttribute( 'loading', 'yes' );\n\n\t\t// Prepare increment variables.\n\t\tlet counter: number = 0;\n\t\tconst totalImages: number = images.length;\n\n\t\t/**\n\t\t * Increment counter.\n\t\t */\n\t\tconst incrementLoadingCounter = (): void => {\n\t\t\t// Increment\n\t\t\tcounter++;\n\n\t\t\t// Remove loading attribute once all images have loaded.\n\t\t\tif ( counter === totalImages ) {\n\t\t\t\tthis.removeAttribute( 'loading' );\n\t\t\t}\n\t\t};\n\n\t\t// Check if images have loaded, else add an event listener.\n\t\timages.forEach( ( image: HTMLImageElement ): void => {\n\t\t\t// Check if image has loaded.\n\t\t\tif ( image.complete ) {\n\t\t\t\tincrementLoadingCounter();\n\t\t\t} else {\n\t\t\t\timage.addEventListener( 'load', incrementLoadingCounter, { once: true } );\n\t\t\t}\n\t\t} );\n\t}\n\n\t/**\n\t * Handle when the dialog is clicked.\n\t *\n\t * @param {Event} e Click event.\n\t */\n\thandleDialogClick( e: MouseEvent ): void {\n\t\t// Close on overlay click.\n\t\tif (\n\t\t\t'yes' === this.getAttribute( 'close-on-overlay-click' ) &&\n\t\t\tthis.querySelector( 'dialog' ) === e.target\n\t\t) {\n\t\t\tthis.close();\n\t\t}\n\t}\n\n\t/**\n\t * Handle when the dialog is closed (e.g., via Escape key).\n\t * Syncs lightbox state with native dialog close behavior.\n\t */\n\thandleDialogClose(): void {\n\t\t// Only sync if the lightbox thinks it's still open.\n\t\tif ( this.hasAttribute( 'open' ) ) {\n\t\t\tthis.close();\n\t\t}\n\t}\n\n\t/**\n\t * Handles the touch start event.\n\t *\n\t * @param { TouchEvent } evt The touch event.\n\t */\n\thandleTouchStart( evt: TouchEvent ): void {\n\t\t// Check if we should allow swiping?\n\t\tif ( 'yes' !== this.getAttribute( 'swipe' ) ) {\n\t\t\t// Nope.\n\t\t\treturn;\n\t\t}\n\n\t\t// Set the start points.\n\t\tthis.touchStartX = evt.touches[ 0 ].clientX;\n\t\tthis.touchStartY = evt.touches[ 0 ].clientY;\n\t}\n\n\t/**\n\t * Handles the touch end event.\n\t *\n\t * @param { TouchEvent } evt The touch event.\n\t */\n\thandleTouchEnd( evt: TouchEvent ): void {\n\t\t// Check if we should allow swiping?\n\t\tif ( 'yes' !== this.getAttribute( 'swipe' ) ) {\n\t\t\t// Nope.\n\t\t\treturn;\n\t\t}\n\n\t\t// Calculate the distances.\n\t\tconst touchEndX: number = evt.changedTouches[ 0 ].clientX;\n\t\tconst touchEndY: number = evt.changedTouches[ 0 ].clientY;\n\t\tconst swipeDistanceX: number = touchEndX - this.touchStartX;\n\t\tconst swipeDistanceY: number = touchEndY - this.touchStartY;\n\n\t\t// Is this horizontal swipe?\n\t\tconst isHorizontalSwipe = Math.abs( swipeDistanceX ) > Math.abs( swipeDistanceY );\n\n\t\t// Check if this was a horizontal swipe?\n\t\tif ( ! isHorizontalSwipe ) {\n\t\t\t// Bail.\n\t\t\treturn;\n\t\t}\n\n\t\t// Swipe settings\n\t\tthis.swipeThreshold = Number( this.getAttribute( 'swipe-threshold' ) ?? '200' );\n\n\t\t// Check if it's a right or left swipe.\n\t\tif ( swipeDistanceX > 0 ) {\n\t\t\t// Right-Swipe: Check if horizontal swipe distance is less than the threshold.\n\t\t\tif ( swipeDistanceX < this.swipeThreshold ) {\n\t\t\t\tthis.previous();\n\t\t\t}\n\t\t} else if ( swipeDistanceX < 0 ) {\n\t\t\t// Left-Swipe: Check if horizontal swipe distance is less than the threshold.\n\t\t\tif ( swipeDistanceX > -this.swipeThreshold ) {\n\t\t\t\tthis.next();\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Update current item in navigation.\n\t */\n\tupdateNavCurrentItem(): void {\n\t\t// Bail if we don't have nav items.\n\t\tif ( ! this.lightboxNavItems ) {\n\t\t\t// Exit.\n\t\t\treturn;\n\t\t}\n\n\t\t// Check if ARIA management is enabled.\n\t\tconst ariaEnabled = this.isAriaEnabled();\n\n\t\t// Update current item.\n\t\tthis.lightboxNavItems.forEach( ( navItem: TPLightboxNavItemElement, index: number ): void => {\n\t\t\t// Get the button inside the nav item.\n\t\t\tconst button: HTMLButtonElement | null = navItem.querySelector( 'button' );\n\n\t\t\t// Update current attribute.\n\t\t\tif ( this.currentIndex - 1 === index ) {\n\t\t\t\tnavItem.setAttribute( 'current', 'yes' );\n\n\t\t\t\t// Set aria-current on the button (if ARIA is enabled).\n\t\t\t\tif ( ariaEnabled && button ) {\n\t\t\t\t\tbutton.setAttribute( 'aria-current', 'true' );\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tnavItem.removeAttribute( 'current' );\n\n\t\t\t\t// Remove aria-current from the button (if ARIA is enabled).\n\t\t\t\tif ( ariaEnabled && button ) {\n\t\t\t\t\tbutton.removeAttribute( 'aria-current' );\n\t\t\t\t}\n\t\t\t}\n\t\t} );\n\t}\n\n\t/**\n\t * Set initial focus when lightbox opens.\n\t * Looks for [autofocus] element, otherwise focuses the dialog.\n\t */\n\tprivate setInitialFocus(): void {\n\t\t// Look for an element with autofocus attribute.\n\t\tconst autofocusElement = this.querySelector<HTMLElement>( '[autofocus]' );\n\n\t\t// Do we have an autofocus element?\n\t\tif ( autofocusElement ) {\n\t\t\tautofocusElement.focus();\n\n\t\t\t// Early return.\n\t\t\treturn;\n\t\t}\n\n\t\t// Otherwise, focus the dialog itself.\n\t\tthis.dialogElement?.focus();\n\t}\n\n\t/**\n\t * Handle keydown events for arrow navigation.\n\t *\n\t * @param {KeyboardEvent} e Keyboard event.\n\t */\n\tprivate handleKeyDown( e: KeyboardEvent ): void {\n\t\t// Check if arrow navigation is enabled (disabled by default).\n\t\tif ( 'yes' !== this.getAttribute( 'arrow-navigation' ) ) {\n\t\t\t// Early return.\n\t\t\treturn;\n\t\t}\n\n\t\t// Navigate on arrow keys.\n\t\tif ( 'ArrowLeft' === e.key ) {\n\t\t\te.preventDefault();\n\t\t\tthis.previous();\n\t\t} else if ( 'ArrowRight' === e.key ) {\n\t\t\te.preventDefault();\n\t\t\tthis.next();\n\t\t}\n\t}\n}\n","/**\n * TP Lightbox Content.\n */\nexport class TPLightboxContentElement extends HTMLElement {\n}\n","/**\n * Internal dependencies.\n */\nimport { TPLightboxElement } from './tp-lightbox';\n\n/**\n * TP Lightbox Close.\n */\nexport class TPLightboxCloseElement extends HTMLElement {\n\t/**\n\t * Constructor.\n\t */\n\tconstructor() {\n\t\t// Initialize parent.\n\t\tsuper();\n\n\t\t// Events.\n\t\tthis.querySelector( 'button' )?.addEventListener( 'click', this.close.bind( this ) );\n\t}\n\n\t/**\n\t * Close the lightbox.\n\t */\n\tclose(): void {\n\t\t// Get lightbox.\n\t\tconst lightbox: TPLightboxElement | null = this.closest( 'tp-lightbox' );\n\n\t\t// Check if we have a lightbox.\n\t\tif ( lightbox ) {\n\t\t\tsetTimeout( (): void => {\n\t\t\t\t// Close the lightbox.\n\t\t\t\tlightbox.close();\n\t\t\t}, 0 );\n\t\t}\n\t}\n}\n","/**\n * Internal dependencies.\n */\nimport { TPLightboxElement } from './tp-lightbox';\n\n/**\n * TP Lightbox Close.\n */\nexport class TPLightboxPreviousElement extends HTMLElement {\n\t/**\n\t * Constructor.\n\t */\n\tconstructor() {\n\t\t// Initialize parent.\n\t\tsuper();\n\n\t\t// Events.\n\t\tthis.querySelector( 'button' )?.addEventListener( 'click', this.previous.bind( this ) );\n\t}\n\n\t/**\n\t * Navigate previous.\n\t */\n\tprevious(): void {\n\t\t// Check if we are disabled.\n\t\tif ( 'yes' === this.getAttribute( 'disabled' ) ) {\n\t\t\t// No we don't. Exit.\n\t\t\treturn;\n\t\t}\n\n\t\t// Get lightbox.\n\t\tconst lightbox: TPLightboxElement | null = this.closest( 'tp-lightbox' );\n\n\t\t// Check if we have a lightbox.\n\t\tif ( lightbox ) {\n\t\t\tsetTimeout( (): void => {\n\t\t\t\t// Previous.\n\t\t\t\tlightbox.previous();\n\t\t\t}, 0 );\n\t\t}\n\t}\n}\n","/**\n * Internal dependencies.\n */\nimport { TPLightboxElement } from './tp-lightbox';\n\n/**\n * TP Lightbox Close.\n */\nexport class TPLightboxNextElement extends HTMLElement {\n\t/**\n\t * Constructor.\n\t */\n\tconstructor() {\n\t\t// Initialize parent.\n\t\tsuper();\n\n\t\t// Events.\n\t\tthis.querySelector( 'button' )?.addEventListener( 'click', this.next.bind( this ) );\n\t}\n\n\t/**\n\t * Navigate next.\n\t */\n\tnext(): void {\n\t\t// Check if next is disabled.\n\t\tif ( 'yes' === this.getAttribute( 'disabled' ) ) {\n\t\t\t// Yes it is. Exit.\n\t\t\treturn;\n\t\t}\n\n\t\t// Get lightbox.\n\t\tconst lightbox: TPLightboxElement | null = this.closest( 'tp-lightbox' );\n\n\t\t// Check if we have a lightbox.\n\t\tif ( lightbox ) {\n\t\t\tsetTimeout( (): void => {\n\t\t\t\t// Initiate next.\n\t\t\t\tlightbox.next();\n\t\t\t}, 0 );\n\t\t}\n\t}\n}\n","/**\n * Internal dependencies.\n */\nimport { TPLightboxElement } from './tp-lightbox';\n\n/**\n * TP Slider Count.\n */\nexport class TPLightboxCountElement extends HTMLElement {\n\t/**\n\t * Get observed attributes.\n\t *\n\t * @return {Array} Observed attributes.\n\t */\n\tstatic get observedAttributes(): string[] {\n\t\t// Attributes to observe.\n\t\treturn [ 'format' ];\n\t}\n\n\t/**\n\t * Get format.\n\t *\n\t * @return {string} Format.\n\t */\n\tget format(): string {\n\t\t// Get format.\n\t\treturn this.getAttribute( 'format' ) ?? '$current / $total';\n\t}\n\n\t/**\n\t * Set format.\n\t *\n\t * @param {string} format Format.\n\t */\n\tset format( format: string ) {\n\t\t// Set the 'format' attribute value.\n\t\tthis.setAttribute( 'format', format );\n\t}\n\n\t/**\n\t * Attribute changed callback.\n\t */\n\tattributeChangedCallback(): void {\n\t\t// On change of format attribute, update the component.\n\t\tthis.update();\n\t}\n\n\t/**\n\t * Update component.\n\t */\n\tupdate(): void {\n\t\t// Get lightbox.\n\t\tconst lightbox: TPLightboxElement | null = this.closest( 'tp-lightbox' );\n\n\t\t// Check if we have a lightbox.\n\t\tif ( ! lightbox ) {\n\t\t\t// Exit.\n\t\t\treturn;\n\t\t}\n\n\t\t// Get current and total.\n\t\tconst current: string = lightbox.currentIndex.toString();\n\t\tconst total: string = lightbox.getAttribute( 'total' ) ?? '';\n\n\t\t// Update variables in format attribute (using textContent for XSS protection).\n\t\tthis.textContent =\n\t\t\tthis.format\n\t\t\t\t.replace( '$current', current )\n\t\t\t\t.replace( '$total', total );\n\n\t\t// Update current and total attributes.\n\t\tthis.setAttribute( 'current', current );\n\t\tthis.setAttribute( 'total', total );\n\t}\n}\n","/**\n * Internal dependencies.\n */\nimport { TPLightboxElement } from './tp-lightbox';\n\n/**\n * TP Lightbox Trigger.\n */\nexport class TPLightboxTriggerElement extends HTMLElement {\n\t/**\n\t * Constructor.\n\t */\n\tconstructor() {\n\t\t// Initialize parent.\n\t\tsuper();\n\n\t\t// Events.\n\t\tthis.querySelector( 'button' )?.addEventListener( 'click', this.trigger.bind( this ) );\n\t}\n\n\t/**\n\t * Trigger the lightbox.\n\t */\n\ttrigger(): void {\n\t\t// Get lightbox ID and template.\n\t\tconst lightboxId: string | null = this.getAttribute( 'lightbox' );\n\t\tconst template: HTMLTemplateElement | null = this.querySelector( 'template' );\n\n\t\t// We can't proceed without them.\n\t\tif ( ! lightboxId || ! template ) {\n\t\t\t// Exit.\n\t\t\treturn;\n\t\t}\n\n\t\t// Get the lightbox.\n\t\tconst lightbox: TPLightboxElement | null = document.querySelector( `#${ lightboxId.toString() }` );\n\n\t\t// Check to see if we have a lightbox.\n\t\tif ( ! lightbox ) {\n\t\t\t// Exit.\n\t\t\treturn;\n\t\t}\n\n\t\t// Check to see if we have a group.\n\t\tconst group: string = this.getAttribute( 'group' ) ?? '';\n\n\t\t// Yield to main thread.\n\t\tsetTimeout( (): void => {\n\t\t\t// Prepare lightbox.\n\t\t\tlightbox.template = template;\n\t\t\tlightbox.group = group;\n\n\t\t\t// Set index and group if we have them.\n\t\t\tif ( '' !== group ) {\n\t\t\t\tconst allGroups: NodeListOf<TPLightboxTriggerElement> = document.querySelectorAll( `tp-lightbox-trigger[group=\"${ group }\"]` );\n\n\t\t\t\t// Update all groups.\n\t\t\t\tif ( allGroups.length ) {\n\t\t\t\t\t/**\n\t\t\t\t\t * We do this when we're opening a lightbox, or navigating.\n\t\t\t\t\t * This allows consumers to inject elements at any point.\n\t\t\t\t\t */\n\t\t\t\t\tlightbox.updateAllGroups( allGroups );\n\n\t\t\t\t\t// Get current trigger's index within the group.\n\t\t\t\t\tallGroups.forEach( ( triggerElement: TPLightboxTriggerElement, index: number ): void => {\n\t\t\t\t\t\t// Update current index.\n\t\t\t\t\t\tif ( this === triggerElement ) {\n\t\t\t\t\t\t\tlightbox.currentIndex = index + 1;\n\t\t\t\t\t\t}\n\t\t\t\t\t} );\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// All done, lets open the lightbox.\n\t\t\tlightbox.open();\n\t\t}, 0 );\n\t}\n}\n","/**\n * Internal dependencies.\n */\nimport { TPLightboxElement } from './tp-lightbox';\n\n/**\n * TP Lightbox Nav.\n */\nexport class TPLightboxNavElement extends HTMLElement {\n\t/**\n\t * Properties.\n\t */\n\tprotected template: HTMLTemplateElement | null = null;\n\tprotected lightbox : TPLightboxElement | null;\n\n\t/**\n\t * Constructor.\n\t */\n\tconstructor() {\n\t\t// Initialize parent.\n\t\tsuper();\n\n\t\t// Initialize properties.\n\t\tthis.template = this.querySelector( 'template' );\n\t\tthis.lightbox = this.closest( 'tp-lightbox' );\n\n\t\t// Add event listener.\n\t\tthis.lightbox?.addEventListener( 'template-set', this.setTemplate.bind( this ) );\n\t}\n\n\t/**\n\t * Set the template.\n\t */\n\tsetTemplate(): void {\n\t\t// Bail if no template.\n\t\tif ( ! this.template ) {\n\t\t\t// Exit.\n\t\t\treturn;\n\t\t}\n\n\t\t// Total slides.\n\t\tconst totalSlides = Number( this.lightbox?.getAttribute( 'total' ) ?? 0 );\n\n\t\t// Clear the navigation.\n\t\tthis.innerHTML = '';\n\n\t\t// Append the navigation items.\n\t\tfor ( let i = 0; i < totalSlides; i++ ) {\n\t\t\t// Clone the template.\n\t\t\tconst navItem = this.template.content.cloneNode( true );\n\n\t\t\t// Append the clone.\n\t\t\tthis.appendChild( navItem );\n\t\t}\n\t}\n}\n","/**\n * Internal dependencies.\n */\nimport { TPLightboxElement } from './tp-lightbox';\nimport { TPLightboxNavElement } from './tp-lightbox-nav';\n\n/**\n * TP Lightbox Nav Item.\n */\nexport class TPLightboxNavItemElement extends HTMLElement {\n\t/**\n\t * Properties.\n\t */\n\tprotected lightbox : TPLightboxElement | null;\n\n\t/**\n\t * Constructor.\n\t */\n\tconstructor() {\n\t\t// Initialize parent.\n\t\tsuper();\n\t\tthis.lightbox = this.closest( 'tp-lightbox' );\n\n\t\t// Get the nav-item button.\n\t\tthis.querySelector( 'button' )?.addEventListener( 'click', this.handleClick.bind( this ) );\n\t}\n\n\t/**\n\t * Handle when the button is clicked.\n\t */\n\thandleClick(): void {\n\t\t// Check if lightbox exists.\n\t\tif ( ! this.lightbox ) {\n\t\t\t// No its not! Terminate.\n\t\t\treturn;\n\t\t}\n\n\t\t// Set current slide.\n\t\tthis.lightbox.currentIndex = Number( this.getIndex() ) ?? 1;\n\n\t\t// Update navigation current item.\n\t\tthis.lightbox.updateNavCurrentItem();\n\t}\n\n\t/**\n\t * Get index of this item inside the navigation.\n\t *\n\t * @return {number} Index.\n\t */\n\tgetIndex(): number {\n\t\t// Bail if no lightbox.\n\t\tif ( ! this.lightbox ) {\n\t\t\t// Exit.\n\t\t\treturn 0;\n\t\t}\n\n\t\t// No, find it in the navigation.\n\t\tconst lightboxNav: TPLightboxNavElement | null = this.closest( 'tp-lightbox-nav' );\n\n\t\t// Return index of this element considering the step value.\n\t\treturn ( Array.from( lightboxNav?.children ?? [] ).indexOf( this ) ) + 1;\n\t}\n}\n","/**\n * Styles.\n */\nimport './style.scss';\n\n/**\n * Components.\n */\nimport { TPLightboxElement } from './tp-lightbox';\nimport { TPLightboxContentElement } from './tp-lightbox-content';\nimport { TPLightboxCloseElement } from './tp-lightbox-close';\nimport { TPLightboxPreviousElement } from './tp-lightbox-previous';\nimport { TPLightboxNextElement } from './tp-lightbox-next';\nimport { TPLightboxCountElement } from './tp-lightbox-count';\nimport { TPLightboxTriggerElement } from './tp-lightbox-trigger';\nimport { TPLightboxNavElement } from './tp-lightbox-nav';\nimport { TPLightboxNavItemElement } from './tp-lightbox-nav-item';\n\n/**\n * Register Components.\n */\ncustomElements.define( 'tp-lightbox', TPLightboxElement );\ncustomElements.define( 'tp-lightbox-content', TPLightboxContentElement );\ncustomElements.define( 'tp-lightbox-close', TPLightboxCloseElement );\ncustomElements.define( 'tp-lightbox-previous', TPLightboxPreviousElement );\ncustomElements.define( 'tp-lightbox-next', TPLightboxNextElement );\ncustomElements.define( 'tp-lightbox-count', TPLightboxCountElement );\ncustomElements.define( 'tp-lightbox-trigger', TPLightboxTriggerElement );\ncustomElements.define( 'tp-lightbox-nav', TPLightboxNavElement );\ncustomElements.define( 'tp-lightbox-nav-item', TPLightboxNavItemElement );\n"],"names":["TPLightboxElement","HTMLElement","constructor","super","currentTemplate","currentGroup","allGroups","touchStartX","touchStartY","swipeThreshold","previouslyFocusedElement","this","boundHandleKeyDown","handleKeyDown","bind","dialogElement","querySelector","lightboxNavItems","querySelectorAll","addEventListener","handleDialogClick","handleTouchStart","handleTouchEnd","handleDialogClose","observedAttributes","attributeChangedCallback","name","oldValue","newValue","dispatchEvent","CustomEvent","triggerCurrentIndexTarget","updateNavCurrentItem","isAriaEnabled","getAttribute","template","content","templateContent","cloneNode","replaceChildren","setTimeout","prepareImageLoading","prepareNavigation","innerHTML","group","currentIndex","parseInt","index","setAttribute","toString","detail","slideIndex","getAllGroups","trigger","open","dialog","ownerDocument","activeElement","updateAllGroups","showModal","document","setInitialFocus","close","removeEventListener","removeAttribute","focus","previous","next","length","forEach","count","update","previousButton","nextButton","ariaEnabled","images","counter","totalImages","incrementLoadingCounter","image","complete","once","e","target","hasAttribute","evt","touches","clientX","clientY","touchEndX","changedTouches","touchEndY","swipeDistanceX","swipeDistanceY","Math","abs","Number","navItem","button","autofocusElement","key","preventDefault","TPLightboxContentElement","TPLightboxCloseElement","lightbox","closest","TPLightboxPreviousElement","TPLightboxNextElement","TPLightboxCountElement","format","current","total","textContent","replace","TPLightboxTriggerElement","lightboxId","triggerElement","TPLightboxNavElement","setTemplate","totalSlides","i","appendChild","TPLightboxNavItemElement","handleClick","getIndex","lightboxNav","Array","from","children","indexOf","customElements","define"],"ignoreList":[],"sourceRoot":""}
@@ -1 +1 @@
1
- {"version":3,"file":"dist/modal/index.js","mappings":"mBAQO,MAAMA,UAAuBC,YAmBnC,WAAAC,G,MAECC,QAjBO,KAAAC,yBAA+C,KAK/C,KAAAC,gBAA6B,GAe7BC,KAAKC,aAAc,aACzBD,KAAKE,aAAc,WAAY,MAIhCF,KAAKG,mBAAqBH,KAAKI,cAAcC,KAAML,MAGnB,QAAhC,EAAAM,SAASC,cAAe,eAAQ,SAAEC,YAAaR,MAG/CA,KAAKS,iBAAkB,QAAST,KAAKU,YAAYL,KAAML,MACxD,CAKA,IAAAW,GAECX,KAAKF,yBAA2BE,KAAKY,cAAcC,cAGnDb,KAAKc,cAAe,IAAIC,YAAa,cAAe,CAAEC,SAAS,KAC/DhB,KAAKE,aAAc,OAAQ,OAG3BF,KAAKiB,kBAAkB,GAGvBX,SAASG,iBAAkB,UAAWT,KAAKG,oBAGt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,GAAK,IAAMD,EAAkBR,OAI5B,YAHAI,EAAEE,iBAOH,MAAMI,EAAeF,EAAmB,GAClCG,EAAcH,EAAmBA,EAAkBR,OAAS,GAC5DjB,EAAgBb,KAAKY,cAAcC,cAGzC,GAAKqB,EAAEQ,UAAY7B,IAAkB2B,EAKpC,OAJAN,EAAEE,sBACFK,EAAYlB,QAONW,EAAEQ,UAAY7B,IAAkB4B,IACtCP,EAAEE,iBACFI,EAAajB,QAEf,CAOA,WAAAb,CAAawB,GAEPA,EAAES,SAAW3C,MAAQ,QAAUA,KAAKkB,aAAc,yBACtDgB,EAAEE,iBACFF,EAAEU,kBACF5C,KAAKoB,QAEP,EC3NM,MAAMyB,UAA4BlD,YAIxC,WAAAC,GAECC,QAGA,MAAMiD,EAAmC9C,KAAKO,cAAe,UAC7DuC,SAAAA,EAAQrC,iBAAkB,QAAST,KAAK+C,WAAW1C,KAAML,MAC1D,CAKA,UAAA+C,GAEC,MAAMC,EAA+BhD,KAAKiD,QAAS,YACnDD,SAAAA,EAAO5B,OACR,ECdD8B,eAAeC,OAAQ,WAAYzD,GACnCwD,eAAeC,OAAQ,iBAAkBN,E","sources":["webpack://@travelopia/web-components/./src/modal/tp-modal.ts","webpack://@travelopia/web-components/./src/modal/tp-modal-close.ts","webpack://@travelopia/web-components/./src/modal/index.ts"],"sourcesContent":["/**\n * Focusable elements selector.\n */\nconst FOCUSABLE_ELEMENTS = 'a[href], button:not([disabled]), input:not([disabled]), select:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex=\"-1\"])';\n\n/**\n * TP Modal.\n */\nexport class TPModalElement extends HTMLElement {\n\t/**\n\t * Previously focused element before modal opened.\n\t */\n\tprivate previouslyFocusedElement: HTMLElement | null = null;\n\n\t/**\n\t * Elements that were made inert when modal opened.\n\t */\n\tprivate inertedElements: Element[] = [];\n\n\t/**\n\t * Bound event handlers for cleanup.\n\t */\n\tprivate readonly boundHandleKeyDown: ( e: KeyboardEvent ) => void;\n\n\t/**\n\t * Constructor.\n\t */\n\tconstructor() {\n\t\t// Initialize parent.\n\t\tsuper();\n\n\t\t// Make modal programmatically focusable for focus management.\n\t\tif ( ! this.hasAttribute( 'tabindex' ) ) {\n\t\t\tthis.setAttribute( 'tabindex', '-1' );\n\t\t}\n\n\t\t// Bind event handlers.\n\t\tthis.boundHandleKeyDown = this.handleKeyDown.bind( this );\n\n\t\t// Move modal as a direct descendent of body to avoid z-index issues.\n\t\tdocument.querySelector( 'body' )?.appendChild( this );\n\n\t\t// Event listeners.\n\t\tthis.addEventListener( 'click', this.handleClick.bind( this ) );\n\t}\n\n\t/**\n\t * Open the modal.\n\t */\n\topen(): void {\n\t\t// Save the currently focused element to restore later.\n\t\tthis.previouslyFocusedElement = this.ownerDocument.activeElement as HTMLElement;\n\n\t\t// Dispatch before-open event and set open attribute.\n\t\tthis.dispatchEvent( new CustomEvent( 'before-open', { bubbles: true } ) );\n\t\tthis.setAttribute( 'open', 'yes' );\n\n\t\t// Make all siblings inert to trap focus and hide from AT.\n\t\tthis.setSiblingsInert( true );\n\n\t\t// Add keyboard event listener for Escape and focus trap.\n\t\tdocument.addEventListener( 'keydown', this.boundHandleKeyDown );\n\n\t\t// Move focus into the modal (enabled by default, disable with manage-focus=\"no\").\n\t\tif ( 'no' !== this.getAttribute( 'manage-focus' ) ) {\n\t\t\tthis.setInitialFocus();\n\t\t}\n\n\t\t// Dispatch open event.\n\t\tthis.dispatchEvent( new CustomEvent( 'open', { bubbles: true } ) );\n\t}\n\n\t/**\n\t * Close the modal.\n\t */\n\tclose(): void {\n\t\t// Remove keyboard event listener.\n\t\tdocument.removeEventListener( 'keydown', this.boundHandleKeyDown );\n\n\t\t// Dispatch before-close event and remove open attribute.\n\t\tthis.dispatchEvent( new CustomEvent( 'before-close', { bubbles: true } ) );\n\t\tthis.removeAttribute( 'open' );\n\n\t\t// Restore siblings from inert state.\n\t\tthis.setSiblingsInert( false );\n\n\t\t// Restore focus to the previously focused element (if manage-focus is enabled).\n\t\tif ( 'no' !== this.getAttribute( 'manage-focus' ) && this.previouslyFocusedElement ) {\n\t\t\tthis.previouslyFocusedElement.focus();\n\t\t\tthis.previouslyFocusedElement = null;\n\t\t}\n\n\t\t// Dispatch close event.\n\t\tthis.dispatchEvent( new CustomEvent( 'close', { bubbles: true } ) );\n\t}\n\n\t/**\n\t * Set initial focus when modal opens.\n\t * Looks for [autofocus] element, otherwise focuses the modal container.\n\t */\n\tprivate setInitialFocus(): void {\n\t\t// Look for an element with autofocus attribute.\n\t\tconst autofocusElement = this.querySelector<HTMLElement>( '[autofocus]' );\n\n\t\t// Do we have an autofocus element?\n\t\tif ( autofocusElement ) {\n\t\t\tautofocusElement.focus();\n\n\t\t\t// Early return.\n\t\t\treturn;\n\t\t}\n\n\t\t// Otherwise, focus the modal container itself.\n\t\tthis.focus();\n\t}\n\n\t/**\n\t * Set or remove inert and aria-hidden on all siblings.\n\t *\n\t * @param {boolean} inert Whether to make siblings inert.\n\t */\n\tprivate setSiblingsInert( inert: boolean ): void {\n\t\t// Get all body children except this modal.\n\t\tconst bodyChildren = document.body.children;\n\n\t\t// Should we make them inert?\n\t\tif ( inert ) {\n\t\t\t// Clear any previously stored elements.\n\t\t\tthis.inertedElements = [];\n\n\t\t\t// Loop through body children and set inert.\n\t\t\tfor ( let i = 0; i < bodyChildren.length; i++ ) {\n\t\t\t\tconst element = bodyChildren[ i ];\n\n\t\t\t\t// Skip this modal and script/style elements.\n\t\t\t\tif ( element === this || 'SCRIPT' === element.tagName || 'STYLE' === element.tagName ) {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\t// Set inert and aria-hidden, store reference for cleanup.\n\t\t\t\telement.setAttribute( 'inert', '' );\n\t\t\t\telement.setAttribute( 'aria-hidden', 'true' );\n\t\t\t\tthis.inertedElements.push( element );\n\t\t\t}\n\t\t} else {\n\t\t\t// Remove inert and aria-hidden from previously inerted elements.\n\t\t\tfor ( const element of this.inertedElements ) {\n\t\t\t\telement.removeAttribute( 'inert' );\n\t\t\t\telement.removeAttribute( 'aria-hidden' );\n\t\t\t}\n\n\t\t\t// Clear stored elements.\n\t\t\tthis.inertedElements = [];\n\t\t}\n\t}\n\n\t/**\n\t * Handle keydown events for Escape and focus trap.\n\t *\n\t * @param {KeyboardEvent} e Keyboard event.\n\t */\n\tprivate handleKeyDown( e: KeyboardEvent ): void {\n\t\t// Close on Escape.\n\t\tif ( 'Escape' === e.key ) {\n\t\t\te.preventDefault();\n\t\t\tthis.close();\n\n\t\t\t// Early return.\n\t\t\treturn;\n\t\t}\n\n\t\t// Handle focus trap on Tab (enabled by default, disable with focus-trap=\"no\").\n\t\tif ( 'Tab' === e.key && 'no' !== this.getAttribute( 'focus-trap' ) ) {\n\t\t\tthis.trapFocus( e );\n\t\t}\n\t}\n\n\t/**\n\t * Trap focus within the modal.\n\t *\n\t * @param {KeyboardEvent} e Keyboard event.\n\t */\n\tprivate trapFocus( e: KeyboardEvent ): void {\n\t\t// Get all focusable elements within the modal.\n\t\tconst focusableElements = this.querySelectorAll<HTMLElement>( FOCUSABLE_ELEMENTS );\n\n\t\t// Do we have focusable elements?\n\t\tif ( 0 === focusableElements.length ) {\n\t\t\te.preventDefault();\n\n\t\t\t// Early return.\n\t\t\treturn;\n\t\t}\n\n\t\t// Get first, last, and currently focused elements.\n\t\tconst firstElement = focusableElements[ 0 ];\n\t\tconst lastElement = focusableElements[ focusableElements.length - 1 ];\n\t\tconst activeElement = this.ownerDocument.activeElement;\n\n\t\t// Shift+Tab on first element: move to last.\n\t\tif ( e.shiftKey && activeElement === firstElement ) {\n\t\t\te.preventDefault();\n\t\t\tlastElement.focus();\n\n\t\t\t// Early return.\n\t\t\treturn;\n\t\t}\n\n\t\t// Tab on last element: move to first.\n\t\tif ( ! e.shiftKey && activeElement === lastElement ) {\n\t\t\te.preventDefault();\n\t\t\tfirstElement.focus();\n\t\t}\n\t}\n\n\t/**\n\t * Handle when the component is clicked.\n\t *\n\t * @param {Event} e Event.\n\t */\n\thandleClick( e: Event ): void {\n\t\t// Close on overlay click.\n\t\tif ( e.target === this && 'yes' === this.getAttribute( 'overlay-click-close' ) ) {\n\t\t\te.preventDefault();\n\t\t\te.stopPropagation();\n\t\t\tthis.close();\n\t\t}\n\t}\n}\n","/**\n * Internal dependencies.\n */\nimport { TPModalElement } from './tp-modal';\n\n/**\n * TP Modal Close.\n */\nexport class TPModalCloseElement extends HTMLElement {\n\t/**\n\t * Constructor.\n\t */\n\tconstructor() {\n\t\t// Initialize parent.\n\t\tsuper();\n\n\t\t// Add event listener.\n\t\tconst button: HTMLButtonElement | null = this.querySelector( 'button' );\n\t\tbutton?.addEventListener( 'click', this.closeModal.bind( this ) );\n\t}\n\n\t/**\n\t * Close the modal.\n\t */\n\tcloseModal(): void {\n\t\t// Get modal and apply close method.\n\t\tconst modal: TPModalElement | null = this.closest( 'tp-modal' );\n\t\tmodal?.close();\n\t}\n}\n","/**\n * Styles.\n */\nimport './style.scss';\n\n/**\n * Components.\n */\nimport { TPModalElement } from './tp-modal';\nimport { TPModalCloseElement } from './tp-modal-close';\n\n/**\n * Register Components.\n */\ncustomElements.define( 'tp-modal', TPModalElement );\ncustomElements.define( 'tp-modal-close', TPModalCloseElement );\n"],"names":["TPModalElement","HTMLElement","constructor","super","previouslyFocusedElement","inertedElements","this","hasAttribute","setAttribute","boundHandleKeyDown","handleKeyDown","bind","document","querySelector","appendChild","addEventListener","handleClick","open","ownerDocument","activeElement","dispatchEvent","CustomEvent","bubbles","setSiblingsInert","getAttribute","setInitialFocus","close","removeEventListener","removeAttribute","focus","autofocusElement","inert","bodyChildren","body","children","i","length","element","tagName","push","e","key","preventDefault","trapFocus","focusableElements","querySelectorAll","firstElement","lastElement","shiftKey","target","stopPropagation","TPModalCloseElement","button","closeModal","modal","closest","customElements","define"],"sourceRoot":""}
1
+ {"version":3,"file":"dist/modal/index.js","mappings":"mBAQO,MAAMA,UAAuBC,YAmBnC,WAAAC,G,MAECC,QAjBO,KAAAC,yBAA+C,KAK/C,KAAAC,g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AQ7B,aAAc,cAAe,QACrCF,KAAKD,gBAAgBkC,KAAMF,GAC5B,CACD,KAAO,CAEN,IAAM,MAAMA,KAAW/B,KAAKD,gBAC3BgC,EAAQT,gBAAiB,SACzBS,EAAQT,gBAAiB,eAI1BtB,KAAKD,gBAAkB,EACxB,CACD,CAOQ,aAAAK,CAAe8B,GAEtB,GAAK,WAAaA,EAAEC,IAKnB,OAJAD,EAAEE,sBACFpC,KAAKoB,QAOD,QAAUc,EAAEC,KAAO,OAASnC,KAAKkB,aAAc,eACnDlB,KAAKqC,UAAWH,EAElB,CAOQ,SAAAG,CAAWH,GAElB,MAAMI,EAAoBtC,KAAKuC,iBArLN,6IAwLzB,GAAK,IAAMD,EAAkBR,OAI5B,YAHAI,EAAEE,iBAOH,MAAMI,EAAeF,EAAmB,GAClCG,EAAcH,EAAmBA,EAAkBR,OAAS,GAC5DjB,EAAgBb,KAAKY,cAAcC,cAGzC,GAAKqB,EAAEQ,UAAY7B,IAAkB2B,EAKpC,OAJAN,EAAEE,sBACFK,EAAYlB,QAONW,EAAEQ,UAAY7B,IAAkB4B,IACtCP,EAAEE,iBACFI,EAAajB,QAEf,CAOA,WAAAb,CAAawB,GAEPA,EAAES,SAAW3C,MAAQ,QAAUA,KAAKkB,aAAc,yBACtDgB,EAAEE,iBACFF,EAAEU,kBACF5C,KAAKoB,QAEP,EC3NM,MAAMyB,UAA4BlD,YAIxC,WAAAC,GAECC,QAGA,MAAMiD,EAAmC9C,KAAKO,cAAe,UAC7DuC,SAAAA,EAAQrC,iBAAkB,QAAST,KAAK+C,WAAW1C,KAAML,MAC1D,CAKA,UAAA+C,GAEC,MAAMC,EAA+BhD,KAAKiD,QAAS,YACnDD,SAAAA,EAAO5B,OACR,ECdD8B,eAAeC,OAAQ,WAAYzD,GACnCwD,eAAeC,OAAQ,iBAAkBN,E","sources":["webpack://@travelopia/web-components/./src/modal/tp-modal.ts","webpack://@travelopia/web-components/./src/modal/tp-modal-close.ts","webpack://@travelopia/web-components/./src/modal/index.ts"],"sourcesContent":["/**\n * Focusable elements selector.\n */\nconst FOCUSABLE_ELEMENTS = 'a[href], button:not([disabled]), input:not([disabled]), select:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex=\"-1\"])';\n\n/**\n * TP Modal.\n */\nexport class TPModalElement extends HTMLElement {\n\t/**\n\t * Previously focused element before modal opened.\n\t */\n\tprivate previouslyFocusedElement: HTMLElement | null = null;\n\n\t/**\n\t * Elements that were made inert when modal opened.\n\t */\n\tprivate inertedElements: Element[] = [];\n\n\t/**\n\t * Bound event handlers for cleanup.\n\t */\n\tprivate readonly boundHandleKeyDown: ( e: KeyboardEvent ) => void;\n\n\t/**\n\t * Constructor.\n\t */\n\tconstructor() {\n\t\t// Initialize parent.\n\t\tsuper();\n\n\t\t// Make modal programmatically focusable for focus management.\n\t\tif ( ! this.hasAttribute( 'tabindex' ) ) {\n\t\t\tthis.setAttribute( 'tabindex', '-1' );\n\t\t}\n\n\t\t// Bind event handlers.\n\t\tthis.boundHandleKeyDown = this.handleKeyDown.bind( this );\n\n\t\t// Move modal as a direct descendent of body to avoid z-index issues.\n\t\tdocument.querySelector( 'body' )?.appendChild( this );\n\n\t\t// Event listeners.\n\t\tthis.addEventListener( 'click', this.handleClick.bind( this ) );\n\t}\n\n\t/**\n\t * Open the modal.\n\t */\n\topen(): void {\n\t\t// Save the currently focused element to restore later.\n\t\tthis.previouslyFocusedElement = this.ownerDocument.activeElement as HTMLElement;\n\n\t\t// Dispatch before-open event and set open attribute.\n\t\tthis.dispatchEvent( new CustomEvent( 'before-open', { bubbles: true } ) );\n\t\tthis.setAttribute( 'open', 'yes' );\n\n\t\t// Make all siblings inert to trap focus and hide from AT.\n\t\tthis.setSiblingsInert( true );\n\n\t\t// Add keyboard event listener for Escape and focus trap.\n\t\tdocument.addEventListener( 'keydown', this.boundHandleKeyDown );\n\n\t\t// Move focus into the modal (enabled by default, disable with manage-focus=\"no\").\n\t\tif ( 'no' !== this.getAttribute( 'manage-focus' ) ) {\n\t\t\tthis.setInitialFocus();\n\t\t}\n\n\t\t// Dispatch open event.\n\t\tthis.dispatchEvent( new CustomEvent( 'open', { bubbles: true } ) );\n\t}\n\n\t/**\n\t * Close the modal.\n\t */\n\tclose(): void {\n\t\t// Remove keyboard event listener.\n\t\tdocument.removeEventListener( 'keydown', this.boundHandleKeyDown );\n\n\t\t// Dispatch before-close event and remove open attribute.\n\t\tthis.dispatchEvent( new CustomEvent( 'before-close', { bubbles: true } ) );\n\t\tthis.removeAttribute( 'open' );\n\n\t\t// Restore siblings from inert state.\n\t\tthis.setSiblingsInert( false );\n\n\t\t// Restore focus to the previously focused element (if manage-focus is enabled).\n\t\tif ( 'no' !== this.getAttribute( 'manage-focus' ) && this.previouslyFocusedElement ) {\n\t\t\tthis.previouslyFocusedElement.focus();\n\t\t\tthis.previouslyFocusedElement = null;\n\t\t}\n\n\t\t// Dispatch close event.\n\t\tthis.dispatchEvent( new CustomEvent( 'close', { bubbles: true } ) );\n\t}\n\n\t/**\n\t * Set initial focus when modal opens.\n\t * Looks for [autofocus] element, otherwise focuses the modal container.\n\t */\n\tprivate setInitialFocus(): void {\n\t\t// Look for an element with autofocus attribute.\n\t\tconst autofocusElement = this.querySelector<HTMLElement>( '[autofocus]' );\n\n\t\t// Do we have an autofocus element?\n\t\tif ( autofocusElement ) {\n\t\t\tautofocusElement.focus();\n\n\t\t\t// Early return.\n\t\t\treturn;\n\t\t}\n\n\t\t// Otherwise, focus the modal container itself.\n\t\tthis.focus();\n\t}\n\n\t/**\n\t * Set or remove inert and aria-hidden on all siblings.\n\t *\n\t * @param {boolean} inert Whether to make siblings inert.\n\t */\n\tprivate setSiblingsInert( inert: boolean ): void {\n\t\t// Get all body children except this modal.\n\t\tconst bodyChildren = document.body.children;\n\n\t\t// Should we make them inert?\n\t\tif ( inert ) {\n\t\t\t// Clear any previously stored elements.\n\t\t\tthis.inertedElements = [];\n\n\t\t\t// Loop through body children and set inert.\n\t\t\tfor ( let i = 0; i < bodyChildren.length; i++ ) {\n\t\t\t\tconst element = bodyChildren[ i ];\n\n\t\t\t\t// Skip this modal and script/style elements.\n\t\t\t\tif ( element === this || 'SCRIPT' === element.tagName || 'STYLE' === element.tagName ) {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\t// Set inert and aria-hidden, store reference for cleanup.\n\t\t\t\telement.setAttribute( 'inert', '' );\n\t\t\t\telement.setAttribute( 'aria-hidden', 'true' );\n\t\t\t\tthis.inertedElements.push( element );\n\t\t\t}\n\t\t} else {\n\t\t\t// Remove inert and aria-hidden from previously inerted elements.\n\t\t\tfor ( const element of this.inertedElements ) {\n\t\t\t\telement.removeAttribute( 'inert' );\n\t\t\t\telement.removeAttribute( 'aria-hidden' );\n\t\t\t}\n\n\t\t\t// Clear stored elements.\n\t\t\tthis.inertedElements = [];\n\t\t}\n\t}\n\n\t/**\n\t * Handle keydown events for Escape and focus trap.\n\t *\n\t * @param {KeyboardEvent} e Keyboard event.\n\t */\n\tprivate handleKeyDown( e: KeyboardEvent ): void {\n\t\t// Close on Escape.\n\t\tif ( 'Escape' === e.key ) {\n\t\t\te.preventDefault();\n\t\t\tthis.close();\n\n\t\t\t// Early return.\n\t\t\treturn;\n\t\t}\n\n\t\t// Handle focus trap on Tab (enabled by default, disable with focus-trap=\"no\").\n\t\tif ( 'Tab' === e.key && 'no' !== this.getAttribute( 'focus-trap' ) ) {\n\t\t\tthis.trapFocus( e );\n\t\t}\n\t}\n\n\t/**\n\t * Trap focus within the modal.\n\t *\n\t * @param {KeyboardEvent} e Keyboard event.\n\t */\n\tprivate trapFocus( e: KeyboardEvent ): void {\n\t\t// Get all focusable elements within the modal.\n\t\tconst focusableElements = this.querySelectorAll<HTMLElement>( FOCUSABLE_ELEMENTS );\n\n\t\t// Do we have focusable elements?\n\t\tif ( 0 === focusableElements.length ) {\n\t\t\te.preventDefault();\n\n\t\t\t// Early return.\n\t\t\treturn;\n\t\t}\n\n\t\t// Get first, last, and currently focused elements.\n\t\tconst firstElement = focusableElements[ 0 ];\n\t\tconst lastElement = focusableElements[ focusableElements.length - 1 ];\n\t\tconst activeElement = this.ownerDocument.activeElement;\n\n\t\t// Shift+Tab on first element: move to last.\n\t\tif ( e.shiftKey && activeElement === firstElement ) {\n\t\t\te.preventDefault();\n\t\t\tlastElement.focus();\n\n\t\t\t// Early return.\n\t\t\treturn;\n\t\t}\n\n\t\t// Tab on last element: move to first.\n\t\tif ( ! e.shiftKey && activeElement === lastElement ) {\n\t\t\te.preventDefault();\n\t\t\tfirstElement.focus();\n\t\t}\n\t}\n\n\t/**\n\t * Handle when the component is clicked.\n\t *\n\t * @param {Event} e Event.\n\t */\n\thandleClick( e: Event ): void {\n\t\t// Close on overlay click.\n\t\tif ( e.target === this && 'yes' === this.getAttribute( 'overlay-click-close' ) ) {\n\t\t\te.preventDefault();\n\t\t\te.stopPropagation();\n\t\t\tthis.close();\n\t\t}\n\t}\n}\n","/**\n * Internal dependencies.\n */\nimport { TPModalElement } from './tp-modal';\n\n/**\n * TP Modal Close.\n */\nexport class TPModalCloseElement extends HTMLElement {\n\t/**\n\t * Constructor.\n\t */\n\tconstructor() {\n\t\t// Initialize parent.\n\t\tsuper();\n\n\t\t// Add event listener.\n\t\tconst button: HTMLButtonElement | null = this.querySelector( 'button' );\n\t\tbutton?.addEventListener( 'click', this.closeModal.bind( this ) );\n\t}\n\n\t/**\n\t * Close the modal.\n\t */\n\tcloseModal(): void {\n\t\t// Get modal and apply close method.\n\t\tconst modal: TPModalElement | null = this.closest( 'tp-modal' );\n\t\tmodal?.close();\n\t}\n}\n","/**\n * Styles.\n */\nimport './style.scss';\n\n/**\n * Components.\n */\nimport { TPModalElement } from './tp-modal';\nimport { TPModalCloseElement } from './tp-modal-close';\n\n/**\n * Register Components.\n */\ncustomElements.define( 'tp-modal', TPModalElement );\ncustomElements.define( 'tp-modal-close', TPModalCloseElement );\n"],"names":["TPModalElement","HTMLElement","constructor","super","previouslyFocusedElement","inertedElements","this","hasAttribute","setAttribute","boundHandleKeyDown","handleKeyDown","bind","document","querySelector","appendChild","addEventListener","handleClick","open","ownerDocument","activeElement","dispatchEvent","CustomEvent","bubbles","setSiblingsInert","getAttribute","setInitialFocus","close","removeEventListener","removeAttribute","focus","autofocusElement","inert","bodyChildren","body","children","i","length","element","tagName","push","e","key","preventDefault","trapFocus","focusableElements","querySelectorAll","firstElement","lastElement","shiftKey","target","stopPropagation","TPModalCloseElement","button","closeModal","modal","closest","customElements","define"],"ignoreList":[],"sourceRoot":""}
@@ -1,2 +1,2 @@
1
- (()=>{"use strict";class t extends HTMLElement{constructor(){super(),this.currentlyHighlightedOption=-1,this.keyboardEventListener=this.handleKeyboardInputs.bind(this),document.addEventListener("click",this.handleDocumentClick.bind(this)),this.addEventListener("change",this.update.bind(this)),this.addEventListener("focusout",this.handleFocusOut.bind(this));const t=this.querySelector("tp-multi-select-options");t&&new MutationObserver(this.initialize.bind(this)).observe(t,{childList:!0,subtree:!0}),this.initialize()}static get observedAttributes(){return["open","aria"]}isAriaEnabled(){return"no"!==this.getAttribute("aria")}attributeChangedCallback(t="",e="",i=""){e!==i&&"open"===t&&("yes"===i?(document.addEventListener("keydown",this.keyboardEventListener),this.updateAriaExpanded(!0),this.highlightNextOption(),this.dispatchEvent(new CustomEvent("open",{bubbles:!0}))):(this.unHighlightAllOptions(),document.removeEventListener("keydown",this.keyboardEventListener),this.updateAriaExpanded(!1),this.dispatchEvent(new CustomEvent("close",{bubbles:!0}))))}set value(t){if(!t||!Array.isArray(t))return;const e=this.querySelectorAll("tp-multi-select-option");null==e||e.forEach((e=>{var i;t.includes(null!==(i=e.getAttribute("value"))&&void 0!==i?i:"")?e.setAttribute("selected","yes"):e.removeAttribute("selected")})),this.dispatchEvent(new CustomEvent("change",{bubbles:!0}))}get value(){const t=[],e=this.querySelectorAll("select option[selected]");return null==e||e.forEach((e=>{const i=e.getAttribute("value");i&&t.push(i)})),t}updateFormFieldValue(){const t=this.querySelectorAll("tp-multi-select-option"),e=this.querySelector("select");if(!t||!e)return;const i=Array.from(e.options);t.forEach((t=>{var s,l;const n=null!==(s=t.getAttribute("value"))&&void 0!==s?s:"";if(n){const s=i.find((t=>t.value===n));if("yes"===t.getAttribute("selected"))if(s)s.setAttribute("selected","selected");else{const i=document.createElement("option");i.setAttribute("value",null!==(l=t.getAttribute("value"))&&void 0!==l?l:""),i.setAttribute("selected","selected"),null==e||e.append(i)}else null==s||s.remove()}})),e.dispatchEvent(new Event("change"))}update(){this.updateFormFieldValue();const t=this.value;0!==t.length?this.setAttribute("selected","yes"):this.removeAttribute("selected");const e=this.querySelector("tp-multi-select-status");e&&(t.length>0?e.setAttribute("total",t.length.toString()):e.removeAttribute("total"))}handleDocumentClick(t){this===t.target||this.contains(t.target)||this.removeAttribute("open")}initialize(){var t;let e=this.querySelector("select");if(e)e.innerHTML="";else{e=document.createElement("select"),e.setAttribute("name",null!==(t=this.getAttribute("name"))&&void 0!==t?t:"");const i=this.getAttribute("form");i&&e.setAttribute("form",i),"no"!==this.getAttribute("multiple")&&e.setAttribute("multiple","multiple"),this.append(e)}this.update()}select(t=""){if("no"===this.getAttribute("multiple")&&(this.unSelectAll(),""===t))return void("yes"===this.getAttribute("close-on-select")&&this.removeAttribute("open"));const e=this.querySelectorAll(`tp-multi-select-option[value="${t}"]`);null==e||e.forEach((t=>{"yes"!==t.getAttribute("disabled")&&t.setAttribute("selected","yes")}));const i=this.querySelector("tp-multi-select-search");null==i||i.clear(),null==i||i.focus(),"yes"===this.getAttribute("close-on-select")&&this.removeAttribute("open"),this.update()}selectAll(){const t=this.querySelectorAll("tp-multi-select-option");null==t||t.forEach((t=>{"yes"!==t.getAttribute("disabled")&&t.setAttribute("selected","yes")})),this.update()}unSelect(t=""){const e=this.querySelectorAll(`tp-multi-select-option[value="${t}"]`);null==e||e.forEach((t=>{t.removeAttribute("selected")})),this.update()}unSelectAll(){const t=this.querySelectorAll("tp-multi-select-option");null==t||t.forEach((t=>{t.removeAttribute("selected")})),this.update()}handleKeyboardInputs(t){switch(t.key){case"ArrowDown":t.preventDefault(),this.highlightNextOption();break;case"ArrowUp":t.preventDefault(),this.highlightPreviousOption();break;case"Enter":this.toggleHighlightedOption();break;case"Escape":this.unHighlightAllOptions(),this.removeAttribute("open")}}highlightNextOption(){const t=this.querySelectorAll('tp-multi-select-option:not([hidden="yes"])');if(!t)return void(this.currentlyHighlightedOption=-1);let e=this.currentlyHighlightedOption+1;for(;e<t.length&&"yes"===t[e].getAttribute("disabled");)e++;e!==t.length&&(-1!==this.currentlyHighlightedOption&&t[this.currentlyHighlightedOption].removeAttribute("highlighted"),t[e].setAttribute("highlighted","yes"),t[e].scrollIntoView({behavior:"smooth",block:"nearest"}),this.updateAriaActiveDescendant(t[e].id||null),this.currentlyHighlightedOption=e)}highlightPreviousOption(){const t=this.querySelectorAll('tp-multi-select-option:not([hidden="yes"])');if(!t)return void(this.currentlyHighlightedOption=-1);let e=this.currentlyHighlightedOption-1;for(;e>=0&&"yes"===t[e].getAttribute("disabled");)e--;e<0||(0!==this.currentlyHighlightedOption&&t[this.currentlyHighlightedOption].removeAttribute("highlighted"),t[e].setAttribute("highlighted","yes"),t[e].scrollIntoView({behavior:"smooth",block:"nearest"}),this.updateAriaActiveDescendant(t[e].id||null),this.currentlyHighlightedOption=e)}toggleHighlightedOption(){const t=this.querySelector('tp-multi-select-option[highlighted="yes"]');null==t||t.toggle(null)}unHighlightAllOptions(){this.currentlyHighlightedOption=-1;const t=this.querySelectorAll("tp-multi-select-option");t&&t.forEach((t=>{t.removeAttribute("highlighted")})),this.updateAriaActiveDescendant(null)}getComboboxElement(){return this.querySelector("tp-multi-select-search input")||this.querySelector("tp-multi-select-field")}updateAriaExpanded(t){if(!this.isAriaEnabled())return;const e=this.getComboboxElement();e&&e.setAttribute("aria-expanded",t?"true":"false")}updateAriaActiveDescendant(t){if(!this.isAriaEnabled())return;const e=this.getComboboxElement();e&&(t?e.setAttribute("aria-activedescendant",t):e.removeAttribute("aria-activedescendant"))}handleFocusOut(t){t.relatedTarget&&this.contains(t.relatedTarget)||this.removeAttribute("open")}}class e extends HTMLElement{constructor(){super(),this.addEventListener("click",this.toggleOpen.bind(this)),this.addEventListener("keydown",this.handleKeydown.bind(this))}handleKeydown(t){const e=this.closest("tp-multi-select");e&&("Enter"!==t.key&&" "!==t.key&&"ArrowDown"!==t.key||"yes"!==e.getAttribute("open")&&(t.preventDefault(),t.stopPropagation(),e.setAttribute("open","yes")))}connectedCallback(){this.setupAriaAttributes(),this.setupLabelClick()}setupLabelClick(){const t=this.getAttribute("aria-labelledby");if(!t)return;const e=document.getElementById(t);e&&e.addEventListener("click",(()=>{this.focus()}))}setupAriaAttributes(){const t=this.closest("tp-multi-select");if(!(null==t?void 0:t.isAriaEnabled()))return;if(t.querySelector("tp-multi-select-search input"))return;const e=t.querySelector("tp-multi-select-options");this.setAttribute("role","combobox"),this.setAttribute("aria-haspopup","listbox"),this.setAttribute("aria-expanded","false"),this.hasAttribute("tabindex")||this.setAttribute("tabindex","0"),e&&this.setAttribute("aria-controls",e.id)}toggleOpen(){const t=this.closest("tp-multi-select");t&&("yes"===t.getAttribute("open")?t.removeAttribute("open"):t.setAttribute("open","yes"))}}class i extends HTMLElement{}class s extends HTMLElement{static get observedAttributes(){return["total","format"]}attributeChangedCallback(t="",e="",i=""){e!==i&&this.update()}update(){var t,e,i,s;const l=null!==(t=this.getAttribute("format"))&&void 0!==t?t:"$total Selected";let n=l.replace("$total",null!==(e=this.getAttribute("total"))&&void 0!==e?e:"");if(l.includes("$value")){const t=this.closest("tp-multi-select");if(t){const e=null!==(i=t.value)&&void 0!==i?i:[];let l="";if(e.length>0){const i=t.querySelector(`tp-multi-select-option[value="${e[0]}"]`);i&&(l=null!==(s=i.getAttribute("label"))&&void 0!==s?s:"")}n=n.replace("$value",l)}}this.innerHTML=n}}let l=0;class n extends HTMLElement{connectedCallback(){this.setupAriaAttributes()}setupAriaAttributes(){const t=this.closest("tp-multi-select");(null==t?void 0:t.isAriaEnabled())&&(this.id||(this.id="tp-multi-select-listbox-"+ ++l),this.setAttribute("role","listbox"),"no"!==t.getAttribute("multiple")&&this.setAttribute("aria-multiselectable","true"))}}let r=0;class u extends HTMLElement{constructor(){super(),this.addEventListener("click",this.toggle.bind(this))}static get observedAttributes(){return["selected"]}connectedCallback(){this.setupAriaAttributes()}attributeChangedCallback(t="",e="",i=""){e!==i&&"selected"===t&&this.updateAriaState()}setupAriaAttributes(){const t=this.closest("tp-multi-select");(null==t?void 0:t.isAriaEnabled())&&(this.id||(this.id="tp-multi-select-option-"+ ++r),this.setAttribute("role","option"),this.hasAttribute("tabindex")||this.setAttribute("tabindex","-1"),this.updateAriaState())}updateAriaState(){const t=this.closest("tp-multi-select");if(!(null==t?void 0:t.isAriaEnabled()))return;const e="yes"===this.getAttribute("selected");this.setAttribute("aria-selected",e?"true":"false")}toggle(t){var e;null==t||t.preventDefault(),null==t||t.stopPropagation();const i=this.closest("tp-multi-select"),s=null!==(e=this.getAttribute("value"))&&void 0!==e?e:"";"yes"!==this.getAttribute("selected")?(null==i||i.select(s),null==i||i.dispatchEvent(new CustomEvent("select",{bubbles:!0,detail:{value:s}}))):(null==i||i.unSelect(s),null==i||i.dispatchEvent(new CustomEvent("unselect",{bubbles:!0,detail:{value:s}}))),null==i||i.dispatchEvent(new CustomEvent("change",{bubbles:!0}))}}class o extends HTMLElement{constructor(){var t;super();const e=this.querySelector("input");null==e||e.addEventListener("keydown",this.handleKeyboardInputs.bind(this)),null==e||e.addEventListener("keyup",this.handleSearchChange.bind(this)),null==e||e.addEventListener("input",this.handleSearchChange.bind(this)),this.addEventListener("click",this.handleClick.bind(this)),null===(t=this.closest("tp-multi-select"))||void 0===t||t.addEventListener("open",this.focus.bind(this))}connectedCallback(){this.setupAriaAttributes()}setupAriaAttributes(){const t=this.closest("tp-multi-select");if(!(null==t?void 0:t.isAriaEnabled()))return;const e=this.querySelector("input");if(!e)return;const i=t.querySelector("tp-multi-select-options");e.setAttribute("role","combobox"),e.setAttribute("aria-haspopup","listbox"),e.setAttribute("aria-expanded","false"),e.setAttribute("aria-autocomplete","list"),(null==i?void 0:i.id)&&e.setAttribute("aria-controls",i.id)}handleKeyboardInputs(t){const e=this.closest("tp-multi-select"),i=this.querySelector("input");if(e&&i)switch(t.key){case"Enter":t.preventDefault();break;case"ArrowDown":"yes"!==e.getAttribute("open")&&(t.stopPropagation(),e.setAttribute("open","yes"));break;case"Backspace":if(0===i.value.length){const t=e.querySelector("tp-multi-select-pill:last-of-type");t&&t.removePill()}}}handleSearchChange(){var t;const e=this.closest("tp-multi-select"),i=this.querySelector("input"),s=null===(t=this.closest("tp-multi-select"))||void 0===t?void 0:t.querySelectorAll("tp-multi-select-option");if(!e||!i||!s)return;let l=0;s.forEach((t=>{var e;(null===(e=t.getAttribute("label"))||void 0===e?void 0:e.toLowerCase().match(new RegExp(`.*${i.value.toLowerCase().replace(/\s/g,".*")}.*`)))?(t.removeAttribute("hidden"),l++):t.setAttribute("hidden","yes")})),""===i.value?i.removeAttribute("style"):(i.style.width=`${i.value.length+2}ch`,e.setAttribute("open","yes")),e.setAttribute("visible-options",l.toString())}handleClick(t){var e;t.preventDefault(),t.stopPropagation(),this.dispatchEvent(new CustomEvent("multi-select-opened")),document.dispatchEvent(new Event("click")),null===(e=this.closest("tp-multi-select"))||void 0===e||e.setAttribute("open","yes")}clear(){const t=this.querySelector("input");t&&(t.value="",t.dispatchEvent(new Event("change")))}focus(){var t;this.handleSearchChange(),null===(t=this.querySelector("input"))||void 0===t||t.focus()}}class c extends HTMLElement{constructor(){var t,e;super(),this.defaultRole=null,this.defaultAriaLive=null,null===(e=null===(t=this.closest("tp-multi-select"))||void 0===t?void 0:t.querySelector("tp-multi-select-search input"))||void 0===e||e.addEventListener("input",this.update.bind(this))}connectedCallback(){this.defaultRole=this.getAttribute("role"),this.defaultAriaLive=this.getAttribute("aria-live"),this.update()}update(){var t,e;const i=this.closest("tp-multi-select");if(!i)return;const s=i.querySelectorAll('tp-multi-select-option:not([hidden="yes"])').length,l=null!==(t=this.getAttribute("format"))&&void 0!==t?t:"$count results",n=null!==(e=this.getAttribute("no-results-format"))&&void 0!==e?e:"No results found",r=this.getAttribute("no-results-role"),u=this.getAttribute("no-results-aria-live");0===s?(this.textContent=n,r&&this.setAttribute("role",r),u&&this.setAttribute("aria-live",u)):(this.textContent=l.replace("$count",s.toString()),this.defaultRole?this.setAttribute("role",this.defaultRole):this.removeAttribute("role"),this.defaultAriaLive?this.setAttribute("aria-live",this.defaultAriaLive):this.removeAttribute("aria-live"))}}class a extends HTMLElement{constructor(){var t;super(),null===(t=this.querySelector("button"))||void 0===t||t.addEventListener("click",this.handleButtonClick.bind(this))}handleButtonClick(t){null==t||t.preventDefault(),null==t||t.stopPropagation(),this.removePill()}removePill(){var t;const e=this.closest("tp-multi-select");e&&this.getAttribute("value")&&(e.unSelect(null!==(t=this.getAttribute("value"))&&void 0!==t?t:""),e.dispatchEvent(new CustomEvent("unselect",{bubbles:!0})),e.dispatchEvent(new CustomEvent("change",{bubbles:!0})))}}class h extends HTMLElement{constructor(){var t,e,i;super(),null===(t=this.closest("tp-multi-select"))||void 0===t||t.addEventListener("change",this.update.bind(this)),null===(i=null===(e=this.closest("tp-multi-select"))||void 0===e?void 0:e.querySelector("select"))||void 0===i||i.addEventListener("change",(()=>this.update())),this.update()}update(){var t;const e=this.closest("tp-multi-select");if(!e)return;const i=this.querySelectorAll("tp-multi-select-pill"),s=null!==(t=[...new Set(e.value)])&&void 0!==t?t:[],l=[];i.forEach((t=>{var e;const i=null!==(e=t.getAttribute("value"))&&void 0!==e?e:"";""!==i&&(l.push(i),s.includes(i)||t.remove())})),s.filter((t=>!l.includes(t))).forEach((t=>{var i;if(""===t)return;const s=e.querySelector(`tp-multi-select-option[value="${t}"]`);s&&this.appendChild(this.createPill(t,null!==(i=s.getAttribute("label"))&&void 0!==i?i:""))}))}createPill(t,e){const i=document.createElement("tp-multi-select-pill");i.setAttribute("value",t);const s=document.createElement("span");s.textContent=e;const l=document.createElement("button");l.setAttribute("type","button");const n=this.getAttribute("remove-format");return l.textContent=n?n.replace("$label",e):"x",l.addEventListener("click",(()=>{i.removePill()})),l.addEventListener("keydown",(t=>{"Enter"!==t.key&&" "!==t.key||t.stopPropagation()})),i.appendChild(s),i.appendChild(l),i}}let d=0;class p extends HTMLElement{constructor(){var t;super(),null===(t=this.closest("tp-multi-select"))||void 0===t||t.addEventListener("change",this.handleValueChanged.bind(this)),this.addEventListener("click",this.toggleSelectAll.bind(this))}connectedCallback(){this.setupAriaAttributes()}setupAriaAttributes(){const t=this.closest("tp-multi-select");(null==t?void 0:t.isAriaEnabled())&&(this.id||(this.id="tp-multi-select-all-"+ ++d),this.setAttribute("role","option"),this.updateAriaState())}updateAriaState(){const t=this.closest("tp-multi-select");if(!(null==t?void 0:t.isAriaEnabled()))return;const e="yes"===this.getAttribute("selected");this.setAttribute("aria-selected",e?"true":"false")}handleValueChanged(){var t,e;const i=this.closest("tp-multi-select"),s=null==i?void 0:i.querySelectorAll("tp-multi-select-option");i&&s&&(Array.from(s).filter((t=>"yes"!==t.getAttribute("disabled"))).length===i.value.length?(this.setAttribute("selected","yes"),this.innerHTML=null!==(t=this.getAttribute("unselect-text"))&&void 0!==t?t:""):(this.removeAttribute("selected"),this.innerHTML=null!==(e=this.getAttribute("select-text"))&&void 0!==e?e:""),this.updateAriaState())}toggleSelectAll(){const t=this.closest("tp-multi-select");t&&("yes"!==this.getAttribute("selected")?(t.selectAll(),t.dispatchEvent(new CustomEvent("select-all",{bubbles:!0}))):(t.unSelectAll(),t.dispatchEvent(new CustomEvent("unselect-all",{bubbles:!0}))),t.dispatchEvent(new CustomEvent("change",{bubbles:!0})))}}customElements.define("tp-multi-select",t),customElements.define("tp-multi-select-field",e),customElements.define("tp-multi-select-placeholder",i),customElements.define("tp-multi-select-status",s),customElements.define("tp-multi-select-options",n),customElements.define("tp-multi-select-option",u),customElements.define("tp-multi-select-search",o),customElements.define("tp-multi-select-search-status",c),customElements.define("tp-multi-select-pill",a),customElements.define("tp-multi-select-pills",h),customElements.define("tp-multi-select-select-all",p)})();
1
+ (()=>{"use strict";class t extends HTMLElement{constructor(){super(),this.currentlyHighlightedOption=-1,this.keyboardEventListener=this.handleKeyboardInputs.bind(this),document.addEventListener("click",this.handleDocumentClick.bind(this)),this.addEventListener("change",this.update.bind(this)),this.addEventListener("focusout",this.handleFocusOut.bind(this));const t=this.querySelector("tp-multi-select-options");t&&new MutationObserver(this.initialize.bind(this)).observe(t,{childList:!0,subtree:!0}),this.initialize()}static get observedAttributes(){return["open","aria"]}isAriaEnabled(){return"no"!==this.getAttribute("aria")}attributeChangedCallback(t="",e="",i=""){e!==i&&"open"===t&&("yes"===i?(document.addEventListener("keydown",this.keyboardEventListener),this.updateAriaExpanded(!0),this.highlightNextOption(),this.dispatchEvent(new CustomEvent("open",{bubbles:!0}))):(this.unHighlightAllOptions(),document.removeEventListener("keydown",this.keyboardEventListener),this.updateAriaExpanded(!1),this.dispatchEvent(new CustomEvent("close",{bubbles:!0}))))}set value(t){if(!t||!Array.isArray(t))return;const e=this.querySelectorAll("tp-multi-select-option");null==e||e.forEach(e=>{var i;t.includes(null!==(i=e.getAttribute("value"))&&void 0!==i?i:"")?e.setAttribute("selected","yes"):e.removeAttribute("selected")}),this.dispatchEvent(new CustomEvent("change",{bubbles:!0}))}get value(){const t=[],e=this.querySelectorAll("select option[selected]");return null==e||e.forEach(e=>{const i=e.getAttribute("value");i&&t.push(i)}),t}updateFormFieldValue(){const t=this.querySelectorAll("tp-multi-select-option"),e=this.querySelector("select");if(!t||!e)return;const i=Array.from(e.options);t.forEach(t=>{var s,l;const n=null!==(s=t.getAttribute("value"))&&void 0!==s?s:"";if(n){const s=i.find(t=>t.value===n);if("yes"===t.getAttribute("selected"))if(s)s.setAttribute("selected","selected");else{const i=document.createElement("option");i.setAttribute("value",null!==(l=t.getAttribute("value"))&&void 0!==l?l:""),i.setAttribute("selected","selected"),null==e||e.append(i)}else null==s||s.remove()}}),e.dispatchEvent(new Event("change"))}update(){this.updateFormFieldValue();const t=this.value;0!==t.length?this.setAttribute("selected","yes"):this.removeAttribute("selected");const e=this.querySelector("tp-multi-select-status");e&&(t.length>0?e.setAttribute("total",t.length.toString()):e.removeAttribute("total"))}handleDocumentClick(t){this===t.target||this.contains(t.target)||this.removeAttribute("open")}initialize(){var t;let e=this.querySelector("select");if(e)e.innerHTML="";else{e=document.createElement("select"),e.setAttribute("name",null!==(t=this.getAttribute("name"))&&void 0!==t?t:"");const i=this.getAttribute("form");i&&e.setAttribute("form",i),"no"!==this.getAttribute("multiple")&&e.setAttribute("multiple","multiple"),this.append(e)}this.update()}select(t=""){if("no"===this.getAttribute("multiple")&&(this.unSelectAll(),""===t))return void("yes"===this.getAttribute("close-on-select")&&this.removeAttribute("open"));const e=this.querySelectorAll(`tp-multi-select-option[value="${t}"]`);null==e||e.forEach(t=>{"yes"!==t.getAttribute("disabled")&&t.setAttribute("selected","yes")});const i=this.querySelector("tp-multi-select-search");null==i||i.clear(),null==i||i.focus(),"yes"===this.getAttribute("close-on-select")&&this.removeAttribute("open"),this.update()}selectAll(){const t=this.querySelectorAll("tp-multi-select-option");null==t||t.forEach(t=>{"yes"!==t.getAttribute("disabled")&&t.setAttribute("selected","yes")}),this.update()}unSelect(t=""){const e=this.querySelectorAll(`tp-multi-select-option[value="${t}"]`);null==e||e.forEach(t=>{t.removeAttribute("selected")}),this.update()}unSelectAll(){const t=this.querySelectorAll("tp-multi-select-option");null==t||t.forEach(t=>{t.removeAttribute("selected")}),this.update()}handleKeyboardInputs(t){switch(t.key){case"ArrowDown":t.preventDefault(),this.highlightNextOption();break;case"ArrowUp":t.preventDefault(),this.highlightPreviousOption();break;case"Enter":this.toggleHighlightedOption();break;case"Escape":this.unHighlightAllOptions(),this.removeAttribute("open")}}highlightNextOption(){const t=this.querySelectorAll('tp-multi-select-option:not([hidden="yes"])');if(!t)return void(this.currentlyHighlightedOption=-1);let e=this.currentlyHighlightedOption+1;for(;e<t.length&&"yes"===t[e].getAttribute("disabled");)e++;e!==t.length&&(-1!==this.currentlyHighlightedOption&&t[this.currentlyHighlightedOption].removeAttribute("highlighted"),t[e].setAttribute("highlighted","yes"),t[e].scrollIntoView({behavior:"smooth",block:"nearest"}),this.updateAriaActiveDescendant(t[e].id||null),this.currentlyHighlightedOption=e)}highlightPreviousOption(){const t=this.querySelectorAll('tp-multi-select-option:not([hidden="yes"])');if(!t)return void(this.currentlyHighlightedOption=-1);let e=this.currentlyHighlightedOption-1;for(;e>=0&&"yes"===t[e].getAttribute("disabled");)e--;e<0||(0!==this.currentlyHighlightedOption&&t[this.currentlyHighlightedOption].removeAttribute("highlighted"),t[e].setAttribute("highlighted","yes"),t[e].scrollIntoView({behavior:"smooth",block:"nearest"}),this.updateAriaActiveDescendant(t[e].id||null),this.currentlyHighlightedOption=e)}toggleHighlightedOption(){const t=this.querySelector('tp-multi-select-option[highlighted="yes"]');null==t||t.toggle(null)}unHighlightAllOptions(){this.currentlyHighlightedOption=-1;const t=this.querySelectorAll("tp-multi-select-option");t&&t.forEach(t=>{t.removeAttribute("highlighted")}),this.updateAriaActiveDescendant(null)}getComboboxElement(){return this.querySelector("tp-multi-select-search input")||this.querySelector("tp-multi-select-field")}updateAriaExpanded(t){if(!this.isAriaEnabled())return;const e=this.getComboboxElement();e&&e.setAttribute("aria-expanded",t?"true":"false")}updateAriaActiveDescendant(t){if(!this.isAriaEnabled())return;const e=this.getComboboxElement();e&&(t?e.setAttribute("aria-activedescendant",t):e.removeAttribute("aria-activedescendant"))}handleFocusOut(t){t.relatedTarget&&this.contains(t.relatedTarget)||this.removeAttribute("open")}}class e extends HTMLElement{constructor(){super(),this.addEventListener("click",this.toggleOpen.bind(this)),this.addEventListener("keydown",this.handleKeydown.bind(this))}handleKeydown(t){const e=this.closest("tp-multi-select");e&&("Enter"!==t.key&&" "!==t.key&&"ArrowDown"!==t.key||"yes"!==e.getAttribute("open")&&(t.preventDefault(),t.stopPropagation(),e.setAttribute("open","yes")))}connectedCallback(){this.setupAriaAttributes(),this.setupLabelClick()}setupLabelClick(){const t=this.getAttribute("aria-labelledby");if(!t)return;const e=document.getElementById(t);e&&e.addEventListener("click",()=>{this.focus()})}setupAriaAttributes(){const t=this.closest("tp-multi-select");if(!(null==t?void 0:t.isAriaEnabled()))return;if(t.querySelector("tp-multi-select-search input"))return;const e=t.querySelector("tp-multi-select-options");this.setAttribute("role","combobox"),this.setAttribute("aria-haspopup","listbox"),this.setAttribute("aria-expanded","false"),this.hasAttribute("tabindex")||this.setAttribute("tabindex","0"),e&&this.setAttribute("aria-controls",e.id)}toggleOpen(){const t=this.closest("tp-multi-select");t&&("yes"===t.getAttribute("open")?t.removeAttribute("open"):t.setAttribute("open","yes"))}}class i extends HTMLElement{}class s extends HTMLElement{static get observedAttributes(){return["total","format"]}attributeChangedCallback(t="",e="",i=""){e!==i&&this.update()}update(){var t,e,i,s;const l=null!==(t=this.getAttribute("format"))&&void 0!==t?t:"$total Selected";let n=l.replace("$total",null!==(e=this.getAttribute("total"))&&void 0!==e?e:"");if(l.includes("$value")){const t=this.closest("tp-multi-select");if(t){const e=null!==(i=t.value)&&void 0!==i?i:[];let l="";if(e.length>0){const i=t.querySelector(`tp-multi-select-option[value="${e[0]}"]`);i&&(l=null!==(s=i.getAttribute("label"))&&void 0!==s?s:"")}n=n.replace("$value",l)}}this.innerHTML=n}}let l=0;class n extends HTMLElement{connectedCallback(){this.setupAriaAttributes()}setupAriaAttributes(){const t=this.closest("tp-multi-select");(null==t?void 0:t.isAriaEnabled())&&(this.id||(this.id="tp-multi-select-listbox-"+ ++l),this.setAttribute("role","listbox"),"no"!==t.getAttribute("multiple")&&this.setAttribute("aria-multiselectable","true"))}}let r=0;class u extends HTMLElement{constructor(){super(),this.addEventListener("click",this.toggle.bind(this))}static get observedAttributes(){return["selected"]}connectedCallback(){this.setupAriaAttributes()}attributeChangedCallback(t="",e="",i=""){e!==i&&"selected"===t&&this.updateAriaState()}setupAriaAttributes(){const t=this.closest("tp-multi-select");(null==t?void 0:t.isAriaEnabled())&&(this.id||(this.id="tp-multi-select-option-"+ ++r),this.setAttribute("role","option"),this.hasAttribute("tabindex")||this.setAttribute("tabindex","-1"),this.updateAriaState())}updateAriaState(){const t=this.closest("tp-multi-select");if(!(null==t?void 0:t.isAriaEnabled()))return;const e="yes"===this.getAttribute("selected");this.setAttribute("aria-selected",e?"true":"false")}toggle(t){var e;null==t||t.preventDefault(),null==t||t.stopPropagation();const i=this.closest("tp-multi-select"),s=null!==(e=this.getAttribute("value"))&&void 0!==e?e:"";"yes"!==this.getAttribute("selected")?(null==i||i.select(s),null==i||i.dispatchEvent(new CustomEvent("select",{bubbles:!0,detail:{value:s}}))):(null==i||i.unSelect(s),null==i||i.dispatchEvent(new CustomEvent("unselect",{bubbles:!0,detail:{value:s}}))),null==i||i.dispatchEvent(new CustomEvent("change",{bubbles:!0}))}}class o extends HTMLElement{constructor(){var t;super();const e=this.querySelector("input");null==e||e.addEventListener("keydown",this.handleKeyboardInputs.bind(this)),null==e||e.addEventListener("keyup",this.handleSearchChange.bind(this)),null==e||e.addEventListener("input",this.handleSearchChange.bind(this)),this.addEventListener("click",this.handleClick.bind(this)),null===(t=this.closest("tp-multi-select"))||void 0===t||t.addEventListener("open",this.focus.bind(this))}connectedCallback(){this.setupAriaAttributes()}setupAriaAttributes(){const t=this.closest("tp-multi-select");if(!(null==t?void 0:t.isAriaEnabled()))return;const e=this.querySelector("input");if(!e)return;const i=t.querySelector("tp-multi-select-options");e.setAttribute("role","combobox"),e.setAttribute("aria-haspopup","listbox"),e.setAttribute("aria-expanded","false"),e.setAttribute("aria-autocomplete","list"),(null==i?void 0:i.id)&&e.setAttribute("aria-controls",i.id)}handleKeyboardInputs(t){const e=this.closest("tp-multi-select"),i=this.querySelector("input");if(e&&i)switch(t.key){case"Enter":t.preventDefault();break;case"ArrowDown":"yes"!==e.getAttribute("open")&&(t.stopPropagation(),e.setAttribute("open","yes"));break;case"Backspace":if(0===i.value.length){const t=e.querySelector("tp-multi-select-pill:last-of-type");t&&t.removePill()}}}handleSearchChange(){var t;const e=this.closest("tp-multi-select"),i=this.querySelector("input"),s=null===(t=this.closest("tp-multi-select"))||void 0===t?void 0:t.querySelectorAll("tp-multi-select-option");if(!e||!i||!s)return;let l=0;s.forEach(t=>{var e;(null===(e=t.getAttribute("label"))||void 0===e?void 0:e.toLowerCase().match(new RegExp(`.*${i.value.toLowerCase().replace(/\s/g,".*")}.*`)))?(t.removeAttribute("hidden"),l++):t.setAttribute("hidden","yes")}),""===i.value?i.removeAttribute("style"):(i.style.width=`${i.value.length+2}ch`,e.setAttribute("open","yes")),e.setAttribute("visible-options",l.toString())}handleClick(t){var e;t.preventDefault(),t.stopPropagation(),this.dispatchEvent(new CustomEvent("multi-select-opened")),document.dispatchEvent(new Event("click")),null===(e=this.closest("tp-multi-select"))||void 0===e||e.setAttribute("open","yes")}clear(){const t=this.querySelector("input");t&&(t.value="",t.dispatchEvent(new Event("change")))}focus(){var t;this.handleSearchChange(),null===(t=this.querySelector("input"))||void 0===t||t.focus()}}class c extends HTMLElement{constructor(){var t,e;super(),this.defaultRole=null,this.defaultAriaLive=null,null===(e=null===(t=this.closest("tp-multi-select"))||void 0===t?void 0:t.querySelector("tp-multi-select-search input"))||void 0===e||e.addEventListener("input",this.update.bind(this))}connectedCallback(){this.defaultRole=this.getAttribute("role"),this.defaultAriaLive=this.getAttribute("aria-live"),this.update()}update(){var t,e;const i=this.closest("tp-multi-select");if(!i)return;const s=i.querySelectorAll('tp-multi-select-option:not([hidden="yes"])').length,l=null!==(t=this.getAttribute("format"))&&void 0!==t?t:"$count results",n=null!==(e=this.getAttribute("no-results-format"))&&void 0!==e?e:"No results found",r=this.getAttribute("no-results-role"),u=this.getAttribute("no-results-aria-live");0===s?(this.textContent=n,r&&this.setAttribute("role",r),u&&this.setAttribute("aria-live",u)):(this.textContent=l.replace("$count",s.toString()),this.defaultRole?this.setAttribute("role",this.defaultRole):this.removeAttribute("role"),this.defaultAriaLive?this.setAttribute("aria-live",this.defaultAriaLive):this.removeAttribute("aria-live"))}}class a extends HTMLElement{constructor(){var t;super(),null===(t=this.querySelector("button"))||void 0===t||t.addEventListener("click",this.handleButtonClick.bind(this))}handleButtonClick(t){null==t||t.preventDefault(),null==t||t.stopPropagation(),this.removePill()}removePill(){var t;const e=this.closest("tp-multi-select");e&&this.getAttribute("value")&&(e.unSelect(null!==(t=this.getAttribute("value"))&&void 0!==t?t:""),e.dispatchEvent(new CustomEvent("unselect",{bubbles:!0})),e.dispatchEvent(new CustomEvent("change",{bubbles:!0})))}}class h extends HTMLElement{constructor(){var t,e,i;super(),null===(t=this.closest("tp-multi-select"))||void 0===t||t.addEventListener("change",this.update.bind(this)),null===(i=null===(e=this.closest("tp-multi-select"))||void 0===e?void 0:e.querySelector("select"))||void 0===i||i.addEventListener("change",()=>this.update()),this.update()}update(){const t=this.closest("tp-multi-select");if(!t)return;const e=this.querySelectorAll("tp-multi-select-pill"),i=[...new Set(t.value)],s=[];e.forEach(t=>{var e;const l=null!==(e=t.getAttribute("value"))&&void 0!==e?e:"";""!==l&&(s.push(l),i.includes(l)||t.remove())}),i.filter(t=>!s.includes(t)).forEach(e=>{var i;if(""===e)return;const s=t.querySelector(`tp-multi-select-option[value="${e}"]`);s&&this.appendChild(this.createPill(e,null!==(i=s.getAttribute("label"))&&void 0!==i?i:""))})}createPill(t,e){const i=document.createElement("tp-multi-select-pill");i.setAttribute("value",t);const s=document.createElement("span");s.textContent=e;const l=document.createElement("button");l.setAttribute("type","button");const n=this.getAttribute("remove-format");return l.textContent=n?n.replace("$label",e):"x",l.addEventListener("click",()=>{i.removePill()}),l.addEventListener("keydown",t=>{"Enter"!==t.key&&" "!==t.key||t.stopPropagation()}),i.appendChild(s),i.appendChild(l),i}}let d=0;class p extends HTMLElement{constructor(){var t;super(),null===(t=this.closest("tp-multi-select"))||void 0===t||t.addEventListener("change",this.handleValueChanged.bind(this)),this.addEventListener("click",this.toggleSelectAll.bind(this))}connectedCallback(){this.setupAriaAttributes()}setupAriaAttributes(){const t=this.closest("tp-multi-select");(null==t?void 0:t.isAriaEnabled())&&(this.id||(this.id="tp-multi-select-all-"+ ++d),this.setAttribute("role","option"),this.updateAriaState())}updateAriaState(){const t=this.closest("tp-multi-select");if(!(null==t?void 0:t.isAriaEnabled()))return;const e="yes"===this.getAttribute("selected");this.setAttribute("aria-selected",e?"true":"false")}handleValueChanged(){var t,e;const i=this.closest("tp-multi-select"),s=null==i?void 0:i.querySelectorAll("tp-multi-select-option");i&&s&&(Array.from(s).filter(t=>"yes"!==t.getAttribute("disabled")).length===i.value.length?(this.setAttribute("selected","yes"),this.innerHTML=null!==(t=this.getAttribute("unselect-text"))&&void 0!==t?t:""):(this.removeAttribute("selected"),this.innerHTML=null!==(e=this.getAttribute("select-text"))&&void 0!==e?e:""),this.updateAriaState())}toggleSelectAll(){const t=this.closest("tp-multi-select");t&&("yes"!==this.getAttribute("selected")?(t.selectAll(),t.dispatchEvent(new CustomEvent("select-all",{bubbles:!0}))):(t.unSelectAll(),t.dispatchEvent(new CustomEvent("unselect-all",{bubbles:!0}))),t.dispatchEvent(new CustomEvent("change",{bubbles:!0})))}}customElements.define("tp-multi-select",t),customElements.define("tp-multi-select-field",e),customElements.define("tp-multi-select-placeholder",i),customElements.define("tp-multi-select-status",s),customElements.define("tp-multi-select-options",n),customElements.define("tp-multi-select-option",u),customElements.define("tp-multi-select-search",o),customElements.define("tp-multi-select-search-status",c),customElements.define("tp-multi-select-pill",a),customElements.define("tp-multi-select-pills",h),customElements.define("tp-multi-select-select-all",p)})();
2
2
  //# sourceMappingURL=index.js.map