UNPKG

preline

Version:

Preline UI is an open-source set of prebuilt UI components based on the utility-first Tailwind CSS framework.

16 lines 6.7 kB
var t={7615(t,i,o){o.d(i,{A:()=>e}); /* * HSBasePlugin * @version: 4.2.0 * @author: Preline Labs Ltd. * @license: Licensed under MIT and Preline UI Fair Use License (https://preline.co/docs/license.html) * Copyright 2024 Preline Labs Ltd. */ class e{constructor(t,i,o){this.el=t,this.options=i,this.events=o,this.el=t,this.options=i,this.events={}}createCollection(t,i){var o,e;let n=t;if(!Array.isArray(n)&&"undefined"!=typeof window){const t=null===(o=this.constructor)||void 0===o?void 0:o.name,i="string"==typeof t&&t.startsWith("HS")?`$hs${t.slice(2)}Collection`:null;i&&(Array.isArray(window[i])||(window[i]=[]),n=window[i])}Array.isArray(n)&&n.push({id:(null===(e=null==i?void 0:i.el)||void 0===e?void 0:e.id)||n.length+1,element:i})}fireEvent(t,i=null){if(this.events.hasOwnProperty(t))return this.events[t](i)}on(t,i){this.events[t]=i}}},794(t,i,o){o.d(i,{A:()=>s});var e=o(7615); /* * HSRangeSlider * @version: 4.2.0 * @author: Preline Labs Ltd. * @license: Licensed under MIT and Preline UI Fair Use License (https://preline.co/docs/license.html) * Copyright 2024 Preline Labs Ltd. */class n extends e.A{constructor(t,i,o){var e;if(super(t,i||{},o),!n.isAvailable())throw new Error(n.unavailableMessage);const s=t.getAttribute("data-hs-range-slider"),r=s?JSON.parse(s):{};this.concatOptions=Object.assign(Object.assign(Object.assign({},r),i),{cssClasses:Object.assign(Object.assign({},noUiSlider.cssClasses),this.processClasses(r.cssClasses))}),this.wrapper=this.concatOptions.wrapper||t.closest(".hs-range-slider-wrapper")||null,this.currentValue=this.concatOptions.currentValue?Array.from(this.concatOptions.currentValue):Array.from((null===(e=this.wrapper)||void 0===e?void 0:e.querySelectorAll(".hs-range-slider-current-value"))||[]),this.icons=this.concatOptions.icons||{},this.init()}get formattedValue(){const t=this.el.noUiSlider.get();if(Array.isArray(t)&&this.format){const i=[];return t.forEach(t=>{i.push(this.format.to(t))}),i}return this.format?this.format.to(t):t}processClasses(t){const i={};return Object.keys(t).forEach(o=>{o&&(i[o]=`${noUiSlider.cssClasses[o]} ${t[o]}`)}),i}init(){var t,i,o,e,n,s,r,l,a,d,c,h,u;this.createCollection(window.$hsRangeSliderCollection,this),("object"==typeof(null===(t=this.concatOptions)||void 0===t?void 0:t.formatter)?"thousandsSeparatorAndDecimalPoints"===(null===(o=null===(i=this.concatOptions)||void 0===i?void 0:i.formatter)||void 0===o?void 0:o.type):"thousandsSeparatorAndDecimalPoints"===(null===(e=this.concatOptions)||void 0===e?void 0:e.formatter))?this.thousandsSeparatorAndDecimalPointsFormatter():("object"==typeof(null===(n=this.concatOptions)||void 0===n?void 0:n.formatter)?"integer"===(null===(r=null===(s=this.concatOptions)||void 0===s?void 0:s.formatter)||void 0===r?void 0:r.type):"integer"===(null===(l=this.concatOptions)||void 0===l?void 0:l.formatter))?this.integerFormatter():"object"==typeof(null===(a=this.concatOptions)||void 0===a?void 0:a.formatter)&&((null===(c=null===(d=this.concatOptions)||void 0===d?void 0:d.formatter)||void 0===c?void 0:c.prefix)||(null===(u=null===(h=this.concatOptions)||void 0===h?void 0:h.formatter)||void 0===u?void 0:u.postfix))&&this.prefixOrPostfixFormatter(),noUiSlider.create(this.el,this.concatOptions),this.currentValue&&this.currentValue.length>0&&this.el.noUiSlider.on("update",t=>{this.updateCurrentValue(t)}),this.concatOptions.disabled&&this.setDisabled(),this.icons.handle&&this.buildHandleIcon()}formatValue(t){var i,o,e,n,s,r,l,a,d;let c="";return"object"==typeof(null===(i=this.concatOptions)||void 0===i?void 0:i.formatter)?((null===(e=null===(o=this.concatOptions)||void 0===o?void 0:o.formatter)||void 0===e?void 0:e.prefix)&&(c+=null===(s=null===(n=this.concatOptions)||void 0===n?void 0:n.formatter)||void 0===s?void 0:s.prefix),c+=t,(null===(l=null===(r=this.concatOptions)||void 0===r?void 0:r.formatter)||void 0===l?void 0:l.postfix)&&(c+=null===(d=null===(a=this.concatOptions)||void 0===a?void 0:a.formatter)||void 0===d?void 0:d.postfix)):c+=t,c}integerFormatter(){var t;this.format={to:t=>this.formatValue(Math.round(t)),from:t=>Math.round(+t)},(null===(t=this.concatOptions)||void 0===t?void 0:t.tooltips)&&(this.concatOptions.tooltips=this.format)}prefixOrPostfixFormatter(){var t;this.format={to:t=>this.formatValue(t),from:t=>+t},(null===(t=this.concatOptions)||void 0===t?void 0:t.tooltips)&&(this.concatOptions.tooltips=this.format)}thousandsSeparatorAndDecimalPointsFormatter(){var t;this.format={to:t=>this.formatValue(new Intl.NumberFormat("en-US",{minimumFractionDigits:2,maximumFractionDigits:2}).format(t)),from:t=>parseFloat(t.replace(/,/g,""))},(null===(t=this.concatOptions)||void 0===t?void 0:t.tooltips)&&(this.concatOptions.tooltips=this.format)}setDisabled(){this.el.setAttribute("disabled","disabled"),this.el.classList.add("disabled")}buildHandleIcon(){if(!this.icons.handle)return!1;const t=this.el.querySelector(".noUi-handle");if(!t)return!1;t.innerHTML=this.icons.handle}updateCurrentValue(t){this.currentValue&&0!==this.currentValue.length&&t.forEach((t,i)=>{var o;const e=null===(o=this.currentValue)||void 0===o?void 0:o[i];if(!e)return;const n=this.format?this.format.to(t).toString():t.toString();e instanceof HTMLInputElement?e.value=n:e.textContent=n})}destroy(){this.el.noUiSlider.destroy(),this.format=null,window.$hsRangeSliderCollection=window.$hsRangeSliderCollection.filter(({element:t})=>t.el!==this.el)}static isAvailable(){return"undefined"!=typeof noUiSlider}static getInstance(t,i=!1){const o=window.$hsRangeSliderCollection.find(i=>i.element.el===("string"==typeof t?document.querySelector(t):t));return o?i?o:o.element.el:null}static autoInit(){const t="[data-hs-range-slider]:not(.--prevent-on-load-init)";n.isAvailable()?(window.$hsRangeSliderCollection||(window.$hsRangeSliderCollection=[]),window.$hsRangeSliderCollection&&(window.$hsRangeSliderCollection=window.$hsRangeSliderCollection.filter(({element:t})=>document.contains(t.el))),document.querySelectorAll(t).forEach(t=>{window.$hsRangeSliderCollection.find(i=>{var o;return(null===(o=null==i?void 0:i.element)||void 0===o?void 0:o.el)===t})||new n(t)})):document.querySelectorAll(t).length&&console.error(n.unavailableMessage)}}n.unavailableMessage="HSRangeSlider: noUiSlider is not available, please add it to the page.";const s=n}},i={};function o(e){var n=i[e];if(void 0!==n)return n.exports;var s=i[e]={exports:{}};return t[e](s,s.exports,o),s.exports}o.d=(t,i)=>{for(var e in i)o.o(i,e)&&!o.o(t,e)&&Object.defineProperty(t,e,{enumerable:!0,get:i[e]})},o.o=(t,i)=>Object.prototype.hasOwnProperty.call(t,i);var e=o(794);window.addEventListener("load",()=>{e.A.autoInit()}),"undefined"!=typeof window&&(window.HSRangeSlider=e.A);