var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __esm = (fn, res) => function __init() {
return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
};
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
// node_modules/preline/src/plugins/accessibility-manager/index.ts
var HSAccessibilityObserver, accessibility_manager_default;
var init_accessibility_manager = __esm({
"node_modules/preline/src/plugins/accessibility-manager/index.ts"() {
HSAccessibilityObserver = class {
components = [];
currentlyOpenedComponents = [];
activeComponent = null;
allowedKeybindings = /* @__PURE__ */ new Set([
"Escape",
"Enter",
" ",
"Space",
"ArrowDown",
"ArrowUp",
"ArrowLeft",
"ArrowRight",
"Tab",
"Home",
"End"
]);
constructor() {
this.initGlobalListeners();
}
initGlobalListeners() {
document.addEventListener(
"keydown",
(evt) => this.handleGlobalKeydown(evt)
);
document.addEventListener(
"focusin",
(evt) => this.handleGlobalFocusin(evt)
);
}
isAllowedKeybinding(evt) {
if (this.allowedKeybindings.has(evt.key)) {
return true;
}
if (evt.key.length === 1 && /^[a-zA-Z]$/.test(evt.key) && !evt.metaKey && !evt.ctrlKey && !evt.altKey && !evt.shiftKey) {
return true;
}
return false;
}
getActiveComponent(el) {
if (!el) return null;
const containingComponents = this.components.filter(
(comp) => comp.wrapper.contains(el) || comp.context && comp.context.contains(el)
);
if (containingComponents.length === 0) return null;
if (containingComponents.length === 1) return containingComponents[0];
let closestComponent = null;
let minDistance = Number.MAX_SAFE_INTEGER;
for (const comp of containingComponents) {
let distance = 0;
let current = el;
while (current && current !== comp.wrapper && current !== comp.context) {
distance++;
current = current.parentElement;
}
if (distance < minDistance) {
minDistance = distance;
closestComponent = comp;
}
}
return closestComponent;
}
handleGlobalFocusin(evt) {
const target = evt.target;
this.activeComponent = this.getActiveComponent(target);
}
handleGlobalKeydown(evt) {
const target = evt.target;
this.activeComponent = this.getActiveComponent(target);
if (!this.activeComponent) return;
if (!this.isAllowedKeybinding(evt)) {
return;
}
switch (evt.key) {
case "Escape":
if (!this.activeComponent.isOpened) {
const closestOpenParent = this.findClosestOpenParent(target);
if (closestOpenParent?.handlers.onEsc) {
closestOpenParent.handlers.onEsc();
evt.preventDefault();
evt.stopPropagation();
}
} else if (this.activeComponent.handlers.onEsc) {
this.activeComponent.handlers.onEsc();
evt.preventDefault();
evt.stopPropagation();
}
break;
case "Enter":
if (this.activeComponent.handlers.onEnter) {
this.activeComponent.handlers.onEnter();
evt.preventDefault();
evt.stopPropagation();
}
break;
case " ":
case "Space":
if (target.tagName === "INPUT" || target.tagName === "TEXTAREA") {
return;
}
if (this.activeComponent.handlers.onSpace) {
this.activeComponent.handlers.onSpace();
evt.preventDefault();
evt.stopPropagation();
}
break;
case "ArrowDown":
case "ArrowUp":
case "ArrowLeft":
case "ArrowRight":
if (this.activeComponent.handlers.onArrow) {
if (evt.metaKey || evt.ctrlKey || evt.altKey || evt.shiftKey) {
return;
}
this.activeComponent.handlers.onArrow(evt);
evt.preventDefault();
evt.stopPropagation();
}
break;
case "Tab":
if (!this.activeComponent.handlers.onTab) break;
const handler = evt.shiftKey ? this.activeComponent.handlers.onShiftTab : this.activeComponent.handlers.onTab;
if (handler) handler();
break;
case "Home":
if (this.activeComponent.handlers.onHome) {
this.activeComponent.handlers.onHome();
evt.preventDefault();
evt.stopPropagation();
}
break;
case "End":
if (this.activeComponent.handlers.onEnd) {
this.activeComponent.handlers.onEnd();
evt.preventDefault();
evt.stopPropagation();
}
break;
default:
if (this.activeComponent.handlers.onFirstLetter && evt.key.length === 1 && /^[a-zA-Z]$/.test(evt.key)) {
this.activeComponent.handlers.onFirstLetter(evt.key);
evt.preventDefault();
evt.stopPropagation();
}
break;
}
}
findClosestOpenParent(target) {
let current = target.parentElement;
while (current) {
const parentComponent = this.currentlyOpenedComponents.find(
(comp) => comp.wrapper === current && comp !== this.activeComponent
);
if (parentComponent) {
return parentComponent;
}
current = current.parentElement;
}
return null;
}
registerComponent(wrapper, handlers, isOpened = true, name = "", selector = "", context) {
const component = {
wrapper,
handlers,
isOpened,
name,
selector,
context,
isRegistered: true
};
this.components.push(component);
return component;
}
updateComponentState(component, isOpened) {
component.isOpened = isOpened;
if (isOpened) {
if (!this.currentlyOpenedComponents.includes(component)) {
this.currentlyOpenedComponents.push(component);
}
} else {
this.currentlyOpenedComponents = this.currentlyOpenedComponents.filter(
(comp) => comp !== component
);
}
}
unregisterComponent(component) {
this.components = this.components.filter((comp) => comp !== component);
this.currentlyOpenedComponents = this.currentlyOpenedComponents.filter(
(comp) => comp !== component
);
}
addAllowedKeybinding(key) {
this.allowedKeybindings.add(key);
}
removeAllowedKeybinding(key) {
this.allowedKeybindings.delete(key);
}
getAllowedKeybindings() {
return Array.from(this.allowedKeybindings);
}
};
accessibility_manager_default = HSAccessibilityObserver;
}
});
// node_modules/preline/src/utils/index.ts
var stringToBoolean, getClassProperty, getClassPropertyAlt, isDirectChild, isEnoughSpace, isFormElement, isIOS, isIpadOS, isJson, debounce, dispatch, afterTransition, htmlToElement, classToClassList;
var init_utils = __esm({
"node_modules/preline/src/utils/index.ts"() {
stringToBoolean = (string) => {
return string === "true" ? true : false;
};
getClassProperty = (el, prop, val = "") => {
return (window.getComputedStyle(el).getPropertyValue(prop) || val).replace(
" ",
""
);
};
getClassPropertyAlt = (el, prop, val = "") => {
let targetClass = "";
el.classList.forEach((c) => {
if (c.includes(prop)) {
targetClass = c;
}
});
return targetClass.match(/:(.*)]/) ? targetClass.match(/:(.*)]/)[1] : val;
};
isDirectChild = (parent, child) => {
const children = parent.children;
for (let i = 0; i < children.length; i++) {
if (children[i] === child) return true;
}
return false;
};
isEnoughSpace = (el, toggle, preferredPosition = "auto", space = 10, wrapper = null) => {
const referenceRect = toggle.getBoundingClientRect();
const wrapperRect = wrapper ? wrapper.getBoundingClientRect() : null;
const viewportHeight = window.innerHeight;
const spaceAbove = wrapperRect ? referenceRect.top - wrapperRect.top : referenceRect.top;
const spaceBelow = (wrapper ? wrapperRect.bottom : viewportHeight) - referenceRect.bottom;
const minimumSpaceRequired = el.clientHeight + space;
if (preferredPosition === "bottom") {
return spaceBelow >= minimumSpaceRequired;
} else if (preferredPosition === "top") {
return spaceAbove >= minimumSpaceRequired;
} else {
return spaceAbove >= minimumSpaceRequired || spaceBelow >= minimumSpaceRequired;
}
};
isFormElement = (target) => {
return target instanceof HTMLInputElement || target instanceof HTMLTextAreaElement || target instanceof HTMLSelectElement;
};
isIOS = () => {
if (/iPad|iPhone|iPod/.test(navigator.platform)) {
return true;
} else {
return navigator.maxTouchPoints && navigator.maxTouchPoints > 2 && /MacIntel/.test(navigator.platform);
}
};
isIpadOS = () => {
return navigator.maxTouchPoints && navigator.maxTouchPoints > 2 && /MacIntel/.test(navigator.platform);
};
isJson = (str) => {
if (typeof str !== "string") return false;
const firstChar = str.trim()[0];
const lastChar = str.trim().slice(-1);
if (firstChar === "{" && lastChar === "}" || firstChar === "[" && lastChar === "]") {
try {
JSON.parse(str);
return true;
} catch {
return false;
}
}
return false;
};
debounce = (func, timeout = 200) => {
let timer;
return (...args) => {
clearTimeout(timer);
timer = setTimeout(() => {
func.apply(void 0, args);
}, timeout);
};
};
dispatch = (evt, element, payload = null) => {
const event = new CustomEvent(evt, {
detail: { payload },
bubbles: true,
cancelable: true,
composed: false
});
element.dispatchEvent(event);
};
afterTransition = (el, callback) => {
const handleEvent = () => {
callback();
el.removeEventListener("transitionend", handleEvent, true);
};
const computedStyle = window.getComputedStyle(el);
const transitionDuration = computedStyle.getPropertyValue(
"transition-duration"
);
const transitionProperty = computedStyle.getPropertyValue(
"transition-property"
);
const hasTransition = transitionProperty !== "none" && parseFloat(transitionDuration) > 0;
if (hasTransition) el.addEventListener("transitionend", handleEvent, true);
else callback();
};
htmlToElement = (html) => {
const template = document.createElement("template");
html = html.trim();
template.innerHTML = html;
return template.content.firstChild;
};
classToClassList = (classes, target, splitter = " ", action = "add") => {
const classesToArray = classes.split(splitter);
classesToArray.forEach((cl) => {
if (cl.trim()) {
action === "add" ? target.classList.add(cl) : target.classList.remove(cl);
}
});
};
}
});
// node_modules/preline/src/plugins/base-plugin/index.ts
var HSBasePlugin;
var init_base_plugin = __esm({
"node_modules/preline/src/plugins/base-plugin/index.ts"() {
HSBasePlugin = class {
constructor(el, options, events) {
this.el = el;
this.options = options;
this.events = events;
this.el = el;
this.options = options;
this.events = {};
}
createCollection(collection, element) {
collection.push({
id: element?.el?.id || collection.length + 1,
element
});
}
fireEvent(evt, payload = null) {
if (this.events.hasOwnProperty(evt)) return this.events[evt](payload);
}
on(evt, cb) {
this.events[evt] = cb;
}
};
}
});
// node_modules/preline/src/constants.ts
var POSITIONS, BREAKPOINTS;
var init_constants = __esm({
"node_modules/preline/src/constants.ts"() {
POSITIONS = {
auto: "auto",
"auto-start": "auto-start",
"auto-end": "auto-end",
top: "top",
"top-left": "top-start",
"top-right": "top-end",
bottom: "bottom",
"bottom-left": "bottom-start",
"bottom-right": "bottom-end",
right: "right",
"right-start": "right-start",
"right-end": "right-end",
left: "left",
"left-start": "left-start",
"left-end": "left-end"
};
BREAKPOINTS = {
xs: 0,
sm: 640,
md: 768,
lg: 1024,
xl: 1280,
"2xl": 1536
};
}
});
// node_modules/preline/src/plugins/select/index.ts
var HSSelect, select_default;
var init_select = __esm({
"node_modules/preline/src/plugins/select/index.ts"() {
init_utils();
init_base_plugin();
init_accessibility_manager();
init_constants();
HSSelect = class _HSSelect extends HSBasePlugin {
accessibilityComponent;
value;
placeholder;
hasSearch;
minSearchLength;
preventSearchFocus;
mode;
viewport;
_isOpened;
isMultiple;
isDisabled;
selectedItems;
apiUrl;
apiQuery;
apiOptions;
apiDataPart;
apiSearchQueryKey;
apiLoadMore;
apiFieldsMap;
apiIconTag;
apiSelectedValues;
toggleTag;
toggleClasses;
toggleSeparators;
toggleCountText;
toggleCountTextPlacement;
toggleCountTextMinItems;
toggleCountTextMode;
wrapperClasses;
tagsItemTemplate;
tagsItemClasses;
tagsInputId;
tagsInputClasses;
dropdownTag;
dropdownClasses;
dropdownDirectionClasses;
dropdownSpace;
dropdownPlacement;
dropdownAutoPlacement;
dropdownVerticalFixedPlacement;
dropdownScope;
searchTemplate;
searchWrapperTemplate;
searchPlaceholder;
searchId;
searchLimit;
isSearchDirectMatch;
searchClasses;
searchWrapperClasses;
searchNoResultTemplate;
searchNoResultText;
searchNoResultClasses;
optionAllowEmptyOption;
optionTag;
optionTemplate;
optionClasses;
descriptionClasses;
iconClasses;
animationInProcess;
currentPage;
isLoading;
hasMore;
wrapper;
toggle;
toggleTextWrapper;
tagsInput;
dropdown;
floatingUIInstance;
searchWrapper;
search;
searchNoResult;
selectOptions;
extraMarkup;
isAddTagOnEnter;
tagsInputHelper;
remoteOptions;
disabledObserver = null;
optionId = 0;
onWrapperClickListener;
onToggleClickListener;
onTagsInputFocusListener;
onTagsInputInputListener;
onTagsInputInputSecondListener;
onTagsInputKeydownListener;
onSearchInputListener;
isSelectedOptionOnTop;
constructor(el, options) {
super(el, options);
const data = el.getAttribute("data-hs-select");
const dataOptions = data ? JSON.parse(data) : {};
const concatOptions = {
...dataOptions,
...options
};
this.value = concatOptions?.value || this.el.value || null;
this.placeholder = concatOptions?.placeholder || "Select...";
this.hasSearch = concatOptions?.hasSearch || false;
this.minSearchLength = concatOptions?.minSearchLength ?? 0;
this.preventSearchFocus = concatOptions?.preventSearchFocus || false;
this.mode = concatOptions?.mode || "default";
this.viewport = typeof concatOptions?.viewport !== "undefined" ? document.querySelector(concatOptions?.viewport) : null;
this._isOpened = Boolean(concatOptions?.isOpened) || false;
this.isMultiple = this.el.hasAttribute("multiple") || false;
this.isDisabled = this.el.hasAttribute("disabled") || false;
this.selectedItems = [];
this.apiUrl = concatOptions?.apiUrl || null;
this.apiQuery = concatOptions?.apiQuery || null;
this.apiOptions = concatOptions?.apiOptions || null;
this.apiSearchQueryKey = concatOptions?.apiSearchQueryKey || null;
this.apiDataPart = concatOptions?.apiDataPart || null;
this.apiLoadMore = concatOptions?.apiLoadMore === true ? {
perPage: 10,
scrollThreshold: 100
} : typeof concatOptions?.apiLoadMore === "object" && concatOptions?.apiLoadMore !== null ? {
perPage: concatOptions.apiLoadMore.perPage || 10,
scrollThreshold: concatOptions.apiLoadMore.scrollThreshold || 100
} : false;
this.apiFieldsMap = concatOptions?.apiFieldsMap || null;
this.apiIconTag = concatOptions?.apiIconTag || null;
this.apiSelectedValues = concatOptions?.apiSelectedValues || null;
this.currentPage = 0;
this.isLoading = false;
this.hasMore = true;
this.wrapperClasses = concatOptions?.wrapperClasses || null;
this.toggleTag = concatOptions?.toggleTag || null;
this.toggleClasses = concatOptions?.toggleClasses || null;
this.toggleCountText = typeof concatOptions?.toggleCountText === void 0 ? null : concatOptions.toggleCountText;
this.toggleCountTextPlacement = concatOptions?.toggleCountTextPlacement || "postfix";
this.toggleCountTextMinItems = concatOptions?.toggleCountTextMinItems || 1;
this.toggleCountTextMode = concatOptions?.toggleCountTextMode || "countAfterLimit";
this.toggleSeparators = {
items: concatOptions?.toggleSeparators?.items || ", ",
betweenItemsAndCounter: concatOptions?.toggleSeparators?.betweenItemsAndCounter || "and"
};
this.tagsItemTemplate = concatOptions?.tagsItemTemplate || null;
this.tagsItemClasses = concatOptions?.tagsItemClasses || null;
this.tagsInputId = concatOptions?.tagsInputId || null;
this.tagsInputClasses = concatOptions?.tagsInputClasses || null;
this.dropdownTag = concatOptions?.dropdownTag || null;
this.dropdownClasses = concatOptions?.dropdownClasses || null;
this.dropdownDirectionClasses = concatOptions?.dropdownDirectionClasses || null;
this.dropdownSpace = concatOptions?.dropdownSpace || 10;
this.dropdownPlacement = concatOptions?.dropdownPlacement || null;
this.dropdownVerticalFixedPlacement = concatOptions?.dropdownVerticalFixedPlacement || null;
this.dropdownScope = concatOptions?.dropdownScope || "parent";
this.dropdownAutoPlacement = concatOptions?.dropdownAutoPlacement || false;
this.searchTemplate = concatOptions?.searchTemplate || null;
this.searchWrapperTemplate = concatOptions?.searchWrapperTemplate || null;
this.searchWrapperClasses = concatOptions?.searchWrapperClasses || "bg-white p-2 sticky top-0";
this.searchId = concatOptions?.searchId || null;
this.searchLimit = concatOptions?.searchLimit || Infinity;
this.isSearchDirectMatch = typeof concatOptions?.isSearchDirectMatch !== "undefined" ? concatOptions?.isSearchDirectMatch : true;
this.searchClasses = concatOptions?.searchClasses || "block w-[calc(100%-32px)] text-sm border-gray-200 rounded-md focus:border-blue-500 focus:ring-blue-500 dark:bg-neutral-900 dark:border-neutral-700 dark:text-neutral-400 py-2 px-3 my-2 mx-4";
this.searchPlaceholder = concatOptions?.searchPlaceholder || "Search...";
this.searchNoResultTemplate = concatOptions?.searchNoResultTemplate || " ";
this.searchNoResultText = concatOptions?.searchNoResultText || "No results found";
this.searchNoResultClasses = concatOptions?.searchNoResultClasses || "px-4 text-sm text-gray-800 dark:text-neutral-200";
this.optionAllowEmptyOption = typeof concatOptions?.optionAllowEmptyOption !== "undefined" ? concatOptions?.optionAllowEmptyOption : false;
this.optionTemplate = concatOptions?.optionTemplate || null;
this.optionTag = concatOptions?.optionTag || null;
this.optionClasses = concatOptions?.optionClasses || null;
this.extraMarkup = concatOptions?.extraMarkup || null;
this.descriptionClasses = concatOptions?.descriptionClasses || null;
this.iconClasses = concatOptions?.iconClasses || null;
this.isAddTagOnEnter = concatOptions?.isAddTagOnEnter ?? true;
this.isSelectedOptionOnTop = concatOptions?.isSelectedOptionOnTop ?? false;
this.animationInProcess = false;
this.selectOptions = [];
this.remoteOptions = [];
this.tagsInputHelper = null;
this.disabledObserver = new MutationObserver((muts) => {
if (muts.some((m) => m.attributeName === "disabled")) {
this.setDisabledState(this.el.hasAttribute("disabled"));
}
});
this.disabledObserver.observe(this.el, {
attributes: true,
attributeFilter: ["disabled"]
});
this.init();
}
wrapperClick(evt) {
if (!evt.target.closest("[data-hs-select-dropdown]") && !evt.target.closest("[data-tag-value]")) {
this.tagsInput.focus();
}
}
toggleClick() {
if (this.isDisabled) return false;
this.toggleFn();
}
tagsInputFocus() {
if (!this._isOpened) this.open();
}
tagsInputInput() {
this.calculateInputWidth();
}
tagsInputInputSecond(evt) {
if (!this.apiUrl) {
this.searchOptions(evt.target.value);
}
}
tagsInputKeydown(evt) {
if (evt.key === "Enter" && this.isAddTagOnEnter) {
const val = evt.target.value;
if (this.selectOptions.find((el) => el.val === val)) {
return false;
}
this.addSelectOption(val, val);
this.buildOption(val, val);
this.buildOriginalOption(val, val);
this.dropdown.querySelector(`[data-value="${val}"]`).click();
this.resetTagsInputField();
}
}
searchInput(evt) {
const newVal = evt.target.value;
if (this.apiUrl) this.remoteSearch(newVal);
else this.searchOptions(newVal);
}
setValue(val) {
this.value = val;
this.clearSelections();
if (Array.isArray(val)) {
if (this.mode === "tags") {
this.unselectMultipleItems();
this.selectMultipleItems();
this.selectedItems = [];
const existingTags = this.wrapper.querySelectorAll("[data-tag-value]");
existingTags.forEach((tag) => tag.remove());
this.setTagsItems();
this.reassignTagsInputPlaceholder(
this.hasValue() ? "" : this.placeholder
);
} else {
this.toggleTextWrapper.innerHTML = this.hasValue() ? this.stringFromValue() : this.placeholder;
this.unselectMultipleItems();
this.selectMultipleItems();
}
} else {
this.setToggleTitle();
if (this.toggle.querySelector("[data-icon]")) this.setToggleIcon();
if (this.toggle.querySelector("[data-title]")) this.setToggleTitle();
this.selectSingleItem();
}
}
setDisabledState(isDisabled) {
this.isDisabled = isDisabled;
const target = this.mode === "tags" ? this.wrapper : this.toggle;
target?.classList.toggle("disabled", isDisabled);
if (isDisabled && this.isOpened()) this.close();
}
hasValue() {
if (!this.isMultiple) {
return this.value !== null && this.value !== void 0 && this.value !== "";
}
return Array.isArray(this.value) && this.value.length > 0 && this.value.some((val) => val !== null && val !== void 0 && val !== "");
}
init() {
this.createCollection(window.$hsSelectCollection, this);
this.build();
if (typeof window !== "undefined") {
if (!window.HSAccessibilityObserver) {
window.HSAccessibilityObserver = new accessibility_manager_default();
}
this.setupAccessibility();
}
}
build() {
this.el.style.display = "none";
if (this.el.children) {
Array.from(this.el.children).filter(
(el) => this.optionAllowEmptyOption || !this.optionAllowEmptyOption && el.value && el.value !== ""
).forEach((el) => {
const data = el.getAttribute("data-hs-select-option");
this.selectOptions = [
...this.selectOptions,
{
title: el.textContent,
val: el.value,
disabled: el.disabled,
options: data !== "undefined" ? JSON.parse(data) : null
}
];
});
}
if (this.optionAllowEmptyOption && !this.value) {
this.value = "";
}
if (this.isMultiple) {
const selectedOptions = Array.from(this.el.children).filter(
(el) => el.selected
);
const values = [];
selectedOptions.forEach((el) => {
values.push(el.value);
});
this.value = values;
}
this.buildWrapper();
if (this.mode === "tags") this.buildTags();
else this.buildToggle();
this.buildDropdown();
if (this.extraMarkup) this.buildExtraMarkup();
}
buildWrapper() {
this.wrapper = document.createElement("div");
this.wrapper.classList.add("hs-select", "relative");
this.setDisabledState(this.isDisabled);
if (this.mode === "tags") {
this.onWrapperClickListener = (evt) => this.wrapperClick(evt);
this.wrapper.addEventListener("click", this.onWrapperClickListener);
}
if (this.wrapperClasses) {
classToClassList(this.wrapperClasses, this.wrapper);
}
this.el.before(this.wrapper);
this.wrapper.append(this.el);
}
buildExtraMarkup() {
const appendMarkup = (markup) => {
const el = htmlToElement(markup);
this.wrapper.append(el);
return el;
};
const clickHandle = (el) => {
if (!el.classList.contains("--prevent-click")) {
el.addEventListener("click", (evt) => {
evt.stopPropagation();
if (!this.isDisabled) this.toggleFn();
});
}
};
if (Array.isArray(this.extraMarkup)) {
this.extraMarkup.forEach((el) => {
const newEl = appendMarkup(el);
clickHandle(newEl);
});
} else {
const newEl = appendMarkup(this.extraMarkup);
clickHandle(newEl);
}
}
buildToggle() {
let icon, title;
this.toggleTextWrapper = document.createElement("span");
this.toggleTextWrapper.classList.add("truncate");
this.toggle = htmlToElement(this.toggleTag || "
");
icon = this.toggle.querySelector("[data-icon]");
title = this.toggle.querySelector("[data-title]");
if (!this.isMultiple && icon) this.setToggleIcon();
if (!this.isMultiple && title) this.setToggleTitle();
if (this.isMultiple) {
this.toggleTextWrapper.innerHTML = this.hasValue() ? this.stringFromValue() : this.placeholder;
} else {
this.toggleTextWrapper.innerHTML = this.getItemByValue(this.value)?.title || this.placeholder;
}
if (!title) this.toggle.append(this.toggleTextWrapper);
if (this.toggleClasses) classToClassList(this.toggleClasses, this.toggle);
if (this.isDisabled) this.toggle.classList.add("disabled");
if (this.wrapper) this.wrapper.append(this.toggle);
if (this.toggle?.ariaExpanded) {
if (this._isOpened) this.toggle.ariaExpanded = "true";
else this.toggle.ariaExpanded = "false";
}
this.onToggleClickListener = () => this.toggleClick();
this.toggle.addEventListener("click", this.onToggleClickListener);
}
setToggleIcon() {
const item = this.getItemByValue(this.value);
const icon = this.toggle.querySelector("[data-icon]");
if (icon) {
icon.innerHTML = "";
const img = htmlToElement(
this.apiUrl && this.apiIconTag ? this.apiIconTag || "" : item?.options?.icon || ""
);
if (this.value && this.apiUrl && this.apiIconTag && item[this.apiFieldsMap.icon]) {
img.src = item[this.apiFieldsMap.icon] || "";
}
icon.append(img);
if (!img?.src) icon.classList.add("hidden");
else icon.classList.remove("hidden");
}
}
setToggleTitle() {
const title = this.toggle.querySelector("[data-title]");
let value = this.placeholder;
if (this.optionAllowEmptyOption && this.value === "") {
const emptyOption = this.selectOptions.find(
(el) => el.val === ""
);
value = emptyOption?.title || this.placeholder;
} else if (this.value) {
if (this.apiUrl) {
const selectedOption = this.remoteOptions.find(
(el) => `${el[this.apiFieldsMap.val]}` === this.value || `${el[this.apiFieldsMap.title]}` === this.value
);
if (selectedOption) {
value = selectedOption[this.apiFieldsMap.title];
}
} else {
const selectedOption = this.selectOptions.find(
(el) => el.val === this.value
);
if (selectedOption) {
value = selectedOption.title;
}
}
}
if (title) {
title.innerHTML = value;
title.classList.add("truncate");
this.toggle.append(title);
} else {
this.toggleTextWrapper.innerHTML = value;
}
}
buildTags() {
if (this.isDisabled) this.wrapper.classList.add("disabled");
this.wrapper.setAttribute("tabindex", "0");
this.buildTagsInput();
this.setTagsItems();
}
reassignTagsInputPlaceholder(placeholder) {
this.tagsInput.placeholder = placeholder;
this.tagsInputHelper.innerHTML = placeholder;
this.calculateInputWidth();
}
buildTagsItem(val) {
const item = this.getItemByValue(val);
let template, title, remove, icon;
const newItem = document.createElement("div");
newItem.setAttribute("data-tag-value", val);
if (this.tagsItemClasses) classToClassList(this.tagsItemClasses, newItem);
if (this.tagsItemTemplate) {
template = htmlToElement(this.tagsItemTemplate);
newItem.append(template);
}
if (item?.options?.icon || this.apiIconTag) {
const img = htmlToElement(
this.apiUrl && this.apiIconTag ? this.apiIconTag : item?.options?.icon
);
if (this.apiUrl && this.apiIconTag && item[this.apiFieldsMap.icon]) {
img.src = item[this.apiFieldsMap.icon] || "";
}
icon = template ? template.querySelector("[data-icon]") : document.createElement("span");
icon.append(img);
if (!template) newItem.append(icon);
}
if (template && template.querySelector("[data-icon]") && !item?.options?.icon && !this.apiUrl && !this.apiIconTag && !item[this.apiFieldsMap?.icon]) {
template.querySelector("[data-icon]").classList.add("hidden");
}
title = template ? template.querySelector("[data-title]") : document.createElement("span");
if (this.apiUrl && this.apiFieldsMap?.title && item[this.apiFieldsMap.title]) {
title.textContent = item[this.apiFieldsMap.title];
} else {
title.textContent = item.title || "";
}
if (!template) newItem.append(title);
if (template) {
remove = template.querySelector("[data-remove]");
} else {
remove = document.createElement("span");
remove.textContent = "X";
newItem.append(remove);
}
remove.addEventListener("click", () => {
this.value = this.value.filter((el) => el !== val);
this.selectedItems = this.selectedItems.filter((el) => el !== val);
if (!this.hasValue()) {
this.reassignTagsInputPlaceholder(this.placeholder);
}
this.unselectMultipleItems();
this.selectMultipleItems();
newItem.remove();
this.triggerChangeEventForNativeSelect();
});
this.wrapper.append(newItem);
}
getItemByValue(val) {
const value = this.apiUrl ? this.remoteOptions.find(
(el) => `${el[this.apiFieldsMap.val]}` === val || el[this.apiFieldsMap.title] === val
) : this.selectOptions.find((el) => el.val === val);
return value;
}
setTagsItems() {
if (this.value) {
const values = Array.isArray(this.value) ? this.value : this.value != null ? [this.value] : [];
values.forEach((val) => {
if (!this.selectedItems.includes(val)) this.buildTagsItem(val);
this.selectedItems = !this.selectedItems.includes(val) ? [...this.selectedItems, val] : this.selectedItems;
});
}
if (this._isOpened && this.floatingUIInstance) {
this.floatingUIInstance.update();
}
}
buildTagsInput() {
this.tagsInput = document.createElement("input");
if (this.tagsInputId) this.tagsInput.id = this.tagsInputId;
if (this.tagsInputClasses) {
classToClassList(this.tagsInputClasses, this.tagsInput);
}
this.tagsInput.setAttribute("tabindex", "-1");
this.onTagsInputFocusListener = () => this.tagsInputFocus();
this.onTagsInputInputListener = () => this.tagsInputInput();
this.onTagsInputInputSecondListener = debounce(
(evt) => this.tagsInputInputSecond(evt)
);
this.onTagsInputKeydownListener = (evt) => this.tagsInputKeydown(evt);
this.tagsInput.addEventListener("focus", this.onTagsInputFocusListener);
this.tagsInput.addEventListener("input", this.onTagsInputInputListener);
this.tagsInput.addEventListener(
"input",
this.onTagsInputInputSecondListener
);
this.tagsInput.addEventListener("keydown", this.onTagsInputKeydownListener);
this.wrapper.append(this.tagsInput);
setTimeout(() => {
this.adjustInputWidth();
this.reassignTagsInputPlaceholder(
this.hasValue() ? "" : this.placeholder
);
});
}
buildDropdown() {
this.dropdown = htmlToElement(this.dropdownTag || "
");
this.dropdown.setAttribute("data-hs-select-dropdown", "");
if (this.dropdownScope === "parent") {
this.dropdown.classList.add("absolute");
if (!this.dropdownVerticalFixedPlacement) {
this.dropdown.classList.add("top-full");
}
}
this.dropdown.role = "listbox";
this.dropdown.tabIndex = -1;
this.dropdown.ariaOrientation = "vertical";
if (!this._isOpened) this.dropdown.classList.add("hidden");
if (this.dropdownClasses) {
classToClassList(this.dropdownClasses, this.dropdown);
}
if (this.wrapper) this.wrapper.append(this.dropdown);
if (this.dropdown && this.hasSearch) this.buildSearch();
if (this.selectOptions) {
this.selectOptions.forEach(
(props, i) => this.buildOption(
props.title,
props.val,
props.disabled,
props.selected,
props.options,
`${i}`
)
);
}
if (this.apiUrl) this.optionsFromRemoteData();
if (!this.apiUrl) {
this.sortElements(this.el, "option");
this.sortElements(this.dropdown, "[data-value]");
}
if (this.dropdownScope === "window") this.buildFloatingUI();
if (this.dropdown && this.apiLoadMore) this.setupInfiniteScroll();
}
setupInfiniteScroll() {
this.dropdown.addEventListener("scroll", this.handleScroll.bind(this));
}
async handleScroll() {
if (!this.dropdown || this.isLoading || !this.hasMore || !this.apiLoadMore) return;
const { scrollTop, scrollHeight, clientHeight } = this.dropdown;
const scrollThreshold = typeof this.apiLoadMore === "object" ? this.apiLoadMore.scrollThreshold : 100;
const isNearBottom = scrollHeight - scrollTop - clientHeight < scrollThreshold;
if (isNearBottom) await this.loadMore();
}
async loadMore() {
if (!this.apiUrl || this.isLoading || !this.hasMore || !this.apiLoadMore) {
return;
}
this.isLoading = true;
try {
const url = new URL(this.apiUrl);
const paginationParam = this.apiFieldsMap?.page || this.apiFieldsMap?.offset || "page";
const isOffsetBased = !!this.apiFieldsMap?.offset;
const perPage = typeof this.apiLoadMore === "object" ? this.apiLoadMore.perPage : 10;
if (isOffsetBased) {
const offset3 = this.currentPage * perPage;
url.searchParams.set(paginationParam, offset3.toString());
this.currentPage++;
} else {
this.currentPage++;
url.searchParams.set(paginationParam, this.currentPage.toString());
}
url.searchParams.set(
this.apiFieldsMap?.limit || "limit",
perPage.toString()
);
const response = await fetch(url.toString(), this.apiOptions || {});
const data = await response.json();
const items = this.apiDataPart ? data[this.apiDataPart] : data.results;
const total = data.count || 0;
const currentOffset = this.currentPage * perPage;
if (items && items.length > 0) {
this.remoteOptions = [...this.remoteOptions || [], ...items];
this.buildOptionsFromRemoteData(items);
this.hasMore = currentOffset < total;
} else {
this.hasMore = false;
}
} catch (error) {
this.hasMore = false;
console.error("Error loading more options:", error);
} finally {
this.isLoading = false;
}
}
buildFloatingUI() {
if (typeof FloatingUIDOM !== "undefined" && FloatingUIDOM.computePosition) {
document.body.appendChild(this.dropdown);
const reference = this.mode === "tags" ? this.wrapper : this.toggle;
const middleware = [
FloatingUIDOM.offset([0, 5])
];
if (this.dropdownAutoPlacement && typeof FloatingUIDOM.flip === "function") {
middleware.push(FloatingUIDOM.flip({
fallbackPlacements: [
"bottom-start",
"bottom-end",
"top-start",
"top-end"
]
}));
}
const options = {
placement: POSITIONS[this.dropdownPlacement] || "bottom",
strategy: "fixed",
middleware
};
const update2 = () => {
FloatingUIDOM.computePosition(reference, this.dropdown, options).then(
({ x, y, placement: computedPlacement }) => {
Object.assign(this.dropdown.style, {
position: "fixed",
left: `${x}px`,
top: `${y}px`,
[`margin${computedPlacement === "bottom" ? "Top" : computedPlacement === "top" ? "Bottom" : computedPlacement === "right" ? "Left" : "Right"}`]: `${this.dropdownSpace}px`
});
this.dropdown.setAttribute("data-placement", computedPlacement);
}
);
};
update2();
const cleanup = FloatingUIDOM.autoUpdate(
reference,
this.dropdown,
update2
);
this.floatingUIInstance = {
update: update2,
destroy: cleanup
};
} else {
console.error("FloatingUIDOM not found! Please enable it on the page.");
}
}
updateDropdownWidth() {
const toggle = this.mode === "tags" ? this.wrapper : this.toggle;
this.dropdown.style.width = `${toggle.clientWidth}px`;
}
buildSearch() {
let input;
this.searchWrapper = htmlToElement(
this.searchWrapperTemplate || "
"
);
if (this.searchWrapperClasses) {
classToClassList(this.searchWrapperClasses, this.searchWrapper);
}
input = this.searchWrapper.querySelector("[data-input]");
const search = htmlToElement(
this.searchTemplate || ' '
);
this.search = search.tagName === "INPUT" ? search : search.querySelector(":scope input");
this.search.placeholder = this.searchPlaceholder;
if (this.searchClasses) classToClassList(this.searchClasses, this.search);
if (this.searchId) this.search.id = this.searchId;
this.onSearchInputListener = debounce(
(evt) => this.searchInput(evt)
);
this.search.addEventListener("input", this.onSearchInputListener);
if (input) input.append(search);
else this.searchWrapper.append(search);
this.dropdown.append(this.searchWrapper);
}
buildOption(title, val, disabled = false, selected = false, options, index = "1", id) {
let template = null;
let titleWrapper = null;
let iconWrapper = null;
let descriptionWrapper = null;
const option = htmlToElement(this.optionTag || "
");
option.setAttribute("data-value", val);
option.setAttribute("data-title-value", title);
option.setAttribute("tabIndex", index);
option.classList.add("cursor-pointer");
option.setAttribute("data-id", id || `${this.optionId}`);
if (!id) this.optionId++;
if (disabled) option.classList.add("disabled");
if (selected) {
if (this.isMultiple) this.value = [...this.value, val];
else this.value = val;
}
if (this.optionTemplate) {
template = htmlToElement(this.optionTemplate);
option.append(template);
}
if (template) {
titleWrapper = template.querySelector("[data-title]");
titleWrapper.textContent = title || "";
} else {
option.textContent = title || "";
}
if (options) {
if (options.icon) {
const img = htmlToElement(this.apiIconTag ?? options.icon);
img.classList.add("max-w-full");
if (this.apiUrl) {
img.setAttribute("alt", title);
img.setAttribute("src", options.icon);
}
if (template) {
iconWrapper = template.querySelector("[data-icon]");
iconWrapper.append(img);
} else {
const icon = htmlToElement("
");
if (this.iconClasses) classToClassList(this.iconClasses, icon);
icon.append(img);
option.append(icon);
}
}
if (options.description) {
if (template) {
descriptionWrapper = template.querySelector("[data-description]");
if (descriptionWrapper) {
descriptionWrapper.append(options.description);
}
} else {
const description = htmlToElement("
");
description.textContent = options.description;
if (this.descriptionClasses) {
classToClassList(this.descriptionClasses, description);
}
option.append(description);
}
}
}
if (template && template.querySelector("[data-icon]") && !options && !options?.icon) {
template.querySelector("[data-icon]").classList.add("hidden");
}
if (this.value && (this.isMultiple ? this.value.includes(val) : this.value === val)) {
option.classList.add("selected");
}
if (!disabled) {
option.addEventListener("click", () => this.onSelectOption(val));
}
if (this.optionClasses) classToClassList(this.optionClasses, option);
if (this.dropdown) this.dropdown.append(option);
if (selected) this.setNewValue();
}
buildOptionFromRemoteData(title, val, disabled = false, selected = false, index = "1", id, options) {
if (index) {
this.buildOption(title, val, disabled, selected, options, index, id);
} else {
alert(
"ID parameter is required for generating remote options! Please check your API endpoint have it."
);
}
}
buildOptionsFromRemoteData(data) {
data.forEach((el, i) => {
let id = null;
let title = "";
let value = "";
const options = {
id: "",
val: "",
title: "",
icon: null,
description: null,
rest: {}
};
Object.keys(el).forEach((key) => {
if (el[this.apiFieldsMap.id]) id = el[this.apiFieldsMap.id];
if (el[this.apiFieldsMap.val]) {
value = `${el[this.apiFieldsMap.val]}`;
}
if (el[this.apiFieldsMap.title]) {
title = el[this.apiFieldsMap.title];
if (!el[this.apiFieldsMap.val]) {
value = title;
}
}
if (el[this.apiFieldsMap.icon]) {
options.icon = el[this.apiFieldsMap.icon];
}
if (el[this.apiFieldsMap?.description]) {
options.description = el[this.apiFieldsMap.description];
}
options.rest[key] = el[key];
});
const existingOption = this.dropdown.querySelector(
`[data-value="${value}"]`
);
if (!existingOption) {
const isSelected = this.apiSelectedValues ? Array.isArray(this.apiSelectedValues) ? this.apiSelectedValues.includes(value) : this.apiSelectedValues === value : false;
this.buildOriginalOption(
title,
value,
id,
false,
isSelected,
options
);
this.buildOptionFromRemoteData(
title,
value,
false,
isSelected,
`${i}`,
id,
options
);
if (isSelected) {
if (this.isMultiple) {
if (!this.value) this.value = [];
if (Array.isArray(this.value)) {
this.value = [...this.value, value];
}
} else {
this.value = value;
}
}
}
});
this.sortElements(this.el, "option");
this.sortElements(this.dropdown, "[data-value]");
}
async optionsFromRemoteData(val = "") {
const res = await this.apiRequest(val);
this.remoteOptions = res;
if (res.length) this.buildOptionsFromRemoteData(this.remoteOptions);
else console.log("There is no data were responded!");
}
async apiRequest(val = "") {
try {
const url = new URL(this.apiUrl);
const queryParams = new URLSearchParams(this.apiQuery ?? "");
const options = this.apiOptions ?? {};
const key = this.apiSearchQueryKey ?? "q";
const trimmed = (val ?? "").trim().toLowerCase();
if (trimmed !== "") queryParams.set(key, encodeURIComponent(trimmed));
if (this.apiLoadMore) {
const perPage = typeof this.apiLoadMore === "object" ? this.apiLoadMore.perPage : 10;
const pageKey = this.apiFieldsMap?.page ?? this.apiFieldsMap?.offset ?? "page";
const limitKey = this.apiFieldsMap?.limit ?? "limit";
const isOffset = Boolean(this.apiFieldsMap?.offset);
queryParams.delete(pageKey);
queryParams.delete(limitKey);
queryParams.set(pageKey, isOffset ? "0" : "1");
queryParams.set(limitKey, String(perPage));
}
url.search = queryParams.toString();
const res = await fetch(url.toString(), options);
const json = await res.json();
return this.apiDataPart ? json[this.apiDataPart] : json;
} catch (err) {
console.error(err);
}
}
sortElements(container, selector) {
const items = Array.from(container.querySelectorAll(selector));
if (this.isSelectedOptionOnTop) {
items.sort((a, b) => {
const isASelected = a.classList.contains("selected") || a.hasAttribute("selected");
const isBSelected = b.classList.contains("selected") || b.hasAttribute("selected");
if (isASelected && !isBSelected) return -1;
if (!isASelected && isBSelected) return 1;
return 0;
});
}
items.forEach((item) => container.appendChild(item));
}
async remoteSearch(val) {
if (val.length <= this.minSearchLength) {
const res2 = await this.apiRequest("");
this.remoteOptions = res2;
Array.from(this.dropdown.querySelectorAll("[data-value]")).forEach(
(el) => el.remove()
);
Array.from(this.el.querySelectorAll("option[value]")).forEach(
(el) => {
el.remove();
}
);
if (res2.length) this.buildOptionsFromRemoteData(res2);
else console.log("No data responded!");
return false;
}
const res = await this.apiRequest(val);
this.remoteOptions = res;
let newIds = res.map((item) => `${item.id}`);
let restOptions = null;
const pseudoOptions = this.dropdown.querySelectorAll("[data-value]");
const options = this.el.querySelectorAll("[data-hs-select-option]");
options.forEach((el) => {
const dataId = el.getAttribute("data-id");
if (!newIds.includes(dataId) && !this.value?.includes(el.value)) {
this.destroyOriginalOption(el.value);
}
});
pseudoOptions.forEach((el) => {
const dataId = el.getAttribute("data-id");
if (!newIds.includes(dataId) && !this.value?.includes(el.getAttribute("data-value"))) {
this.destroyOption(el.getAttribute("data-value"));
} else newIds = newIds.filter((item) => item !== dataId);
});
restOptions = res.filter(
(item) => newIds.includes(`${item.id}`)
);
if (restOptions.length) this.buildOptionsFromRemoteData(restOptions);
else console.log("No data responded!");
}
destroyOption(val) {
const option = this.dropdown.querySelector(`[data-value="${val}"]`);
if (!option) return false;
option.remove();
}
buildOriginalOption(title, val, id, disabled, selected, options) {
const option = htmlToElement(" ");
option.setAttribute("value", val);
if (disabled) option.setAttribute("disabled", "disabled");
if (selected) option.setAttribute("selected", "selected");
if (id) option.setAttribute("data-id", id);
option.setAttribute("data-hs-select-option", JSON.stringify(options));
option.innerText = title;
this.el.append(option);
}
destroyOriginalOption(val) {
const option = this.el.querySelector(`[value="${val}"]`);
if (!option) return false;
option.remove();
}
buildTagsInputHelper() {
this.tagsInputHelper = document.createElement("span");
this.tagsInputHelper.style.fontSize = window.getComputedStyle(
this.tagsInput
).fontSize;
this.tagsInputHelper.style.fontFamily = window.getComputedStyle(
this.tagsInput
).fontFamily;
this.tagsInputHelper.style.fontWeight = window.getComputedStyle(
this.tagsInput
).fontWeight;
this.tagsInputHelper.style.letterSpacing = window.getComputedStyle(
this.tagsInput
).letterSpacing;
this.tagsInputHelper.style.visibility = "hidden";
this.tagsInputHelper.style.whiteSpace = "pre";
this.tagsInputHelper.style.position = "absolute";
this.wrapper.appendChild(this.tagsInputHelper);
}
calculateInputWidth() {
this.tagsInputHelper.textContent = this.tagsInput.value || this.tagsInput.placeholder;
const inputPadding = parseInt(window.getComputedStyle(this.tagsInput).paddingLeft) + parseInt(window.getComputedStyle(this.tagsInput).paddingRight);
const inputBorder = parseInt(window.getComputedStyle(this.tagsInput).borderLeftWidth) + parseInt(window.getComputedStyle(this.tagsInput).borderRightWidth);
const newWidth = this.tagsInputHelper.offsetWidth + inputPadding + inputBorder;
const maxWidth = this.wrapper.offsetWidth - (parseInt(window.getComputedStyle(this.wrapper).paddingLeft) + parseInt(window.getComputedStyle(this.wrapper).paddingRight));
this.tagsInput.style.width = `${Math.min(newWidth, maxWidth) + 2}px`;
}
adjustInputWidth() {
this.buildTagsInputHelper();
this.calculateInputWidth();
}
onSelectOption(val) {
this.clearSelections();
if (this.isMultiple) {
if (!Array.isArray(this.value)) this.value = [];
this.value = this.value.includes(val) ? this.value.filter((el) => el !== val) : [...this.value, val];
this.selectMultipleItems();
this.setNewValue();
} else {
this.value = val;
this.selectSingleItem();
this.setNewValue();
}
this.fireEvent("change", this.value);
if (this.mode === "tags") {
const intersection = this.selectedItems.filter(
(x) => !this.value.includes(x)
);
if (intersection.length) {
intersection.forEach((el) => {
this.selectedItems = this.selectedItems.filter((elI) => elI !== el);
this.wrapper.querySelector(`[data-tag-value="${el}"]`).remove();
});
}
this.resetTagsInputField();
}
if (!this.isMultiple) {
if (this.toggle.querySelector("[data-icon]")) this.setToggleIcon();
if (this.toggle.querySelector("[data-title]")) this.setToggleTitle();
this.close(true);
}
if (!this.hasValue() && this.mode === "tags") {
this.reassignTagsInputPlaceholder(this.placeholder);
}
if (this._isOpened && this.mode === "tags" && this.tagsInput) {
this.tagsInput.focus();
}
this.triggerChangeEventForNativeSelect();
}
triggerChangeEventForNativeSelect() {
const selectChangeEvent = new Event("change", { bubbles: true });
this.el.dispatchEvent(selectChangeEvent);
dispatch("change.hs.select", this.el, this.value);
}
addSelectOption(title, val, disabled, selected, options) {
this.selectOptions = [
...this.selectOptions,
{
title,
val,
disabled,
selected,
options
}
];
}
removeSelectOption(val, isArray = false) {
const hasOption = !!this.selectOptions.some(
(el) => el.val === val
);
if (!hasOption) return false;
this.selectOptions = this.selectOptions.filter(
(el) => el.val !== val
);
this.value = isArray ? this.value.filter((item) => item !== val) : val;
}
resetTagsInputField() {
this.tagsInput.value = "";
this.reassignTagsInputPlaceholder("");
this.searchOptions("");
}
clearSelections() {
Array.from(this.dropdown.children).forEach((el) => {
if (el.classList.contains("selected")) el.classList.remove("selected");
});
Array.from(this.el.children).forEach((el) => {
if (el.selected) {
el.selected = false;
}
});
}
setNewValue() {
if (this.mode === "tags") {
this.setTagsItems();
} else {
if (this.optionAllowEmptyOption && this.value === "") {
const emptyOption = this.selectOptions.find(
(el) => el.val === ""
);
this.toggleTextWrapper.innerHTML = emptyOption?.title || this.placeholder;
} else {
if (this.hasValue()) {
if (this.apiUrl) {
const selectedItem = this.dropdown.querySelector(
`[data-value="${this.value}"]`
);
if (selectedItem) {
this.toggleTextWrapper.innerHTML = selectedItem.getAttribute("data-title-value") || this.placeholder;
} else {
const selectedOption = this.remoteOptions.find(
(el) => {
const val = el[this.apiFieldsMap.val] ? `${el[this.apiFieldsMap.val]}` : el[this.apiFieldsMap.title];
return val === this.value;
}
);
this.toggleTextWrapper.innerHTML = selectedOption ? `${selectedOption[this.apiFieldsMap.title]}` : this.stringFromValue();
}
} else {
this.toggleTextWrapper.innerHTML = this.stringFromValue();
}
} else {
this.toggleTextWrapper.innerHTML = this.placeholder;
}
}
}
}
stringFromValueBasic(options) {
const value = [];
let title = "";
options.forEach((el) => {
if (this.isMultiple) {
if (Array.isArray(this.value) && this.value.includes(el.val)) {
value.push(el.title);
}
} else {
if (this.value === el.val) value.push(el.title);
}
});
if (this.toggleCountText !== void 0 && this.toggleCountText !== null && value.length >= this.toggleCountTextMinItems) {
if (this.toggleCountTextMode === "nItemsAndCount") {
const nItems = value.slice(0, this.toggleCountTextMinItems - 1);
const tempTitle = [nItems.join(this.toggleSeparators.items)];
const count = `${value.length - nItems.length}`;
if (this?.toggleSeparators?.betweenItemsAndCounter) {
tempTitle.push(this.toggleSeparators.betweenItemsAndCounter);
}
if (this.toggleCountText) {
switch (this.toggleCountTextPlacement) {
case "postfix-no-space":
tempTitle.push(`${count}${this.toggleCountText}`);
break;
case "prefix-no-space":
tempTitle.push(`${this.toggleCountText}${count}`);
break;
case "prefix":
tempTitle.push(`${this.toggleCountText} ${count}`);
break;
default:
tempTitle.push(`${count} ${this.toggleCountText}`);
break;
}
}
title = tempTitle.join(" ");
} else {
title = `${value.length} ${this.toggleCountText}`;
}
} else {
title = value.join(this.toggleSeparators.items);
}
return title;
}
stringFromValueRemoteData() {
const options = this.dropdown.querySelectorAll("[data-title-value]");
const value = [];
let title = "";
options.forEach((el) => {
const dataValue = el.getAttribute("data-value");
const dataTitleValue = el.getAttribute("data-title-value");
if (this.isMultiple) {
if (Array.isArray(this.value) && this.value.includes(dataValue)) {
value.push(dataTitleValue);
}
} else {
if (this.value === dataValue) value.push(dataTitleValue);
}
});
if (this.toggleCountText && this.toggleCountText !== "" && value.length >= this.toggleCountTextMinItems) {
if (this.toggleCountTextMode === "nItemsAndCount") {
const nItems = value.slice(0, this.toggleCountTextMinItems - 1);
title = `${nItems.join(this.toggleSeparators.items)} ${this.toggleSeparators.betweenItemsAndCounter} ${value.length - nItems.length} ${this.toggleCountText}`;
} else {
title = `${value.length} ${this.toggleCountText}`;
}
} else {
title = value.join(this.toggleSeparators.items);
}
return title;
}
stringFromValue() {
const result = this.apiUrl ? this.stringFromValueRemoteData() : this.stringFromValueBasic(this.selectOptions);
return result;
}
selectSingleItem() {
const selectedOption = Array.from(this.el.children).find(
(el) => this.value === el.value
);
selectedOption.selected = true;
const selectedItem = Array.from(this.dropdown.children).find(
(el) => this.value === el.getAttribute("data-value")
);
if (selectedItem) selectedItem.classList.add("selected");
this.sortElements(this.el, "option");
this.sortElements(this.dropdown, "[data-value]");
}
selectMultipleItems() {
if (!Array.isArray(this.value)) return;
Array.from(this.dropdown.children).filter((el) => this.value.includes(el.getAttribute("data-value"))).forEach((el) => el.classList.add("selected"));
Array.from(this.el.children).filter((el) => this.value.includes(el.value)).forEach((el) => el.selected = true);
this.sortElements(this.el, "option");
this.sortElements(this.dropdown, "[data-value]");
}
unselectMultipleItems() {
Array.from(this.dropdown.children).forEach(
(el) => el.classList.remove("selected")
);
Array.from(this.el.children).forEach(
(el) => el.selected = false
);
this.sortElements(this.el, "option");
this.sortElements(this.dropdown, "[data-value]");
}
searchOptions(val) {
if (val.length <= this.minSearchLength) {
if (this.searchNoResult) {
this.searchNoResult.remove();
this.searchNoResult = null;
}
const options2 = this.dropdown.querySelectorAll("[data-value]");
options2.forEach((el) => {
el.classList.remove("hidden");
});
return false;
}
if (this.searchNoResult) {
this.searchNoResult.remove();
this.searchNoResult = null;
}
this.searchNoResult = htmlToElement(this.searchNoResultTemplate);
this.searchNoResult.innerText = this.searchNoResultText;
classToClassList(this.searchNoResultClasses, this.searchNoResult);
const options = this.dropdown.querySelectorAll("[data-value]");
let hasItems = false;
let countLimit;
if (this.searchLimit) countLimit = 0;
options.forEach((el) => {
const optionVal = el.getAttribute("data-title-value").toLocaleLowerCase();
const directMatch = this.isSearchDirectMatch;
let condition;
if (directMatch) {
condition = !optionVal.includes(val.toLowerCase()) || this.searchLimit && countLimit >= this.searchLimit;
} else {
const regexSafeVal = val ? val.split("").map((char) => /\w/.test(char) ? `${char}[\\W_]*` : "\\W*").join("") : "";
const regex = new RegExp(regexSafeVal, "i");
condition = !regex.test(optionVal.trim()) || this.searchLimit && countLimit >= this.searchLimit;
}
if (condition) {
el.classList.add("hidden");
} else {
el.classList.remove("hidden");
hasItems = true;
if (this.searchLimit) countLimit++;
}
});
if (!hasItems) this.dropdown.append(this.searchNoResult);
}
eraseToggleIcon() {
const icon = this.toggle.querySelector("[data-icon]");
if (icon) {
icon.innerHTML = null;
icon.classList.add("hidden");
}
}
eraseToggleTitle() {
const title = this.toggle.querySelector("[data-title]");
if (title) {
title.innerHTML = this.placeholder;
} else {
this.toggleTextWrapper.innerHTML = this.placeholder;
}
}
toggleFn() {
if (this._isOpened) this.close();
else this.open();
}
// Accessibility methods
setupAccessibility() {
this.accessibilityComponent = window.HSAccessibilityObserver.registerComponent(
this.wrapper,
{
onEnter: () => {
if (!this._isOpened) {
this.open();
} else {
const highlighted = this.dropdown.querySelector(
".hs-select-option-highlighted"
);
if (highlighted) {
this.onSelectOption(
highlighted.getAttribute("data-value") || ""
);
if (this._isOpened) {
highlighted.focus();
}
}
}
},
onSpace: () => {
if (!this._isOpened) {
this.open();
} else {
const highlighted = this.dropdown.querySelector(
".hs-select-option-highlighted"
);
if (highlighted) {
this.onSelectOption(
highlighted.getAttribute("data-value") || ""
);
if (this._isOpened) {
highlighted.focus();
}
}
}
},
onEsc: () => {
if (this._isOpened) {
this.close(true);
}
},
onArrow: (evt) => {
if (evt.metaKey) return;
if (!this._isOpened && evt.key === "ArrowDown") {
this.open();
return;
}
if (this._isOpened) {
switch (evt.key) {
case "ArrowDown":
this.focusMenuItem("next");
break;
case "ArrowUp":
this.focusMenuItem("prev");
break;
case "Home":
this.onStartEnd(true);
break;
case "End":
this.onStartEnd(false);
break;
}
}
},
onHome: () => {
if (this._isOpened) this.onStartEnd(true);
},
onEnd: () => {
if (this._isOpened) this.onStartEnd(false);
},
onTab: () => {
if (this._isOpened) this.close();
}
},
this._isOpened,
"Select",
".hs-select",
this.dropdown
);
}
focusMenuItem(direction) {
const options = Array.from(
this.dropdown.querySelectorAll(":scope > *:not(.hidden)")
).filter(
(el) => !el.classList.contains("disabled")
);
if (!options.length) return;
const current = this.dropdown.querySelector(
".hs-select-option-highlighted"
);
const currentIndex = current ? options.indexOf(current) : -1;
const nextIndex = direction === "next" ? (currentIndex + 1) % options.length : (currentIndex - 1 + options.length) % options.length;
if (current) current.classList.remove("hs-select-option-highlighted");
options[nextIndex].classList.add("hs-select-option-highlighted");
options[nextIndex].focus();
}
onStartEnd(isStart = true) {
if (!this.dropdown) return;
const options = Array.from(
this.dropdown.querySelectorAll(":scope > *:not(.hidden)")
).filter(
(el) => !el.classList.contains("disabled")
);
if (!options.length) return;
const current = this.dropdown.querySelector(
".hs-select-option-highlighted"
);
if (current) current.classList.remove("hs-select-option-highlighted");
const index = isStart ? 0 : options.length - 1;
options[index].classList.add("hs-select-option-highlighted");
options[index].focus();
}
// Public methods
destroy() {
if (this.wrapper) {
this.wrapper.removeEventListener("click", this.onWrapperClickListener);
}
if (this.toggle) {
this.toggle.removeEventListener("click", this.onToggleClickListener);
}
if (this.tagsInput) {
this.tagsInput.removeEventListener(
"focus",
this.onTagsInputFocusListener
);
this.tagsInput.removeEventListener(
"input",
this.onTagsInputInputListener
);
this.tagsInput.removeEventListener(
"input",
this.onTagsInputInputSecondListener
);
this.tagsInput.removeEventListener(
"keydown",
this.onTagsInputKeydownListener
);
}
if (this.search) {
this.search.removeEventListener("input", this.onSearchInputListener);
}
const parent = this.el.parentElement.parentElement;
this.el.classList.add("hidden");
this.el.style.display = "";
parent.prepend(this.el);
parent.querySelector(".hs-select").remove();
this.wrapper = null;
this.disabledObserver?.disconnect();
this.disabledObserver = null;
window.$hsSelectCollection = window.$hsSelectCollection.filter(
({ element }) => element.el !== this.el
);
}
open() {
const currentlyOpened = window?.$hsSelectCollection?.find((el) => el.element.isOpened()) || null;
if (currentlyOpened) currentlyOpened.element.close();
if (this.animationInProcess) return false;
this.animationInProcess = true;
if (this.dropdownScope === "window") {
this.dropdown.classList.add("invisible");
}
this.dropdown.classList.remove("hidden");
if (this.dropdownScope !== "window") this.recalculateDirection();
setTimeout(() => {
if (this?.toggle?.ariaExpanded) this.toggle.ariaExpanded = "true";
this.wrapper.classList.add("active");
this.dropdown.classList.add("opened");
if (this.dropdown.classList.contains("w-full") && this.dropdownScope === "window") {
this.updateDropdownWidth();
}
if (this.floatingUIInstance && this.dropdownScope === "window") {
this.floatingUIInstance.update();
this.dropdown.classList.remove("invisible");
}
if (this.hasSearch && !this.preventSearchFocus) this.search.focus();
this.animationInProcess = false;
});
this._isOpened = true;
if (window.HSAccessibilityObserver && this.accessibilityComponent) {
window.HSAccessibilityObserver.updateComponentState(
this.accessibilityComponent,
this._isOpened
);
}
}
close(forceFocus = false) {
if (this.animationInProcess) return false;
this.animationInProcess = true;
if (this?.toggle?.ariaExpanded) this.toggle.ariaExpanded = "false";
this.wrapper.classList.remove("active");
this.dropdown.classList.remove("opened", "bottom-full", "top-full");
if (this.dropdownDirectionClasses?.bottom) {
this.dropdown.classList.remove(this.dropdownDirectionClasses.bottom);
}
if (this.dropdownDirectionClasses?.top) {
this.dropdown.classList.remove(this.dropdownDirectionClasses.top);
}
this.dropdown.style.marginTop = "";
this.dropdown.style.marginBottom = "";
afterTransition(this.dropdown, () => {
this.dropdown.classList.add("hidden");
if (this.hasSearch) {
this.search.value = "";
if (!this.apiUrl) {
this.search.dispatchEvent(new Event("input", { bubbles: true }));
}
this.search.blur();
}
if (forceFocus) {
if (this.mode?.includes("tags")) this.wrapper.focus();
else this.toggle.focus();
}
this.animationInProcess = false;
});
this.dropdown.querySelector(".hs-select-option-highlighted")?.classList.remove("hs-select-option-highlighted");
this._isOpened = false;
if (window.HSAccessibilityObserver && this.accessibilityComponent) {
window.HSAccessibilityObserver.updateComponentState(
this.accessibilityComponent,
this._isOpened
);
}
}
addOption(items) {
let i = `${this.selectOptions.length}`;
const addOption = (option) => {
const { title, val, disabled, selected, options } = option;
const hasOption = !!this.selectOptions.some(
(el) => el.val === val
);
if (!hasOption) {
this.addSelectOption(title, val, disabled, selected, options);
this.buildOption(title, val, disabled, selected, options, i);
this.buildOriginalOption(title, val, null, disabled, selected, options);
if (selected && !this.isMultiple) this.onSelectOption(val);
}
};
if (Array.isArray(items)) {
items.forEach((option) => {
addOption(option);
});
} else {
addOption(items);
}
this.sortElements(this.el, "option");
this.sortElements(this.dropdown, "[data-value]");
}
removeOption(values) {
const removeOption = (val, isArray = false) => {
const hasOption = !!this.selectOptions.some(
(el) => el.val === val
);
if (hasOption) {
this.removeSelectOption(val, isArray);
this.destroyOption(val);
this.destroyOriginalOption(val);
if (this.value === val) {
this.value = null;
this.eraseToggleTitle();
this.eraseToggleIcon();
}
}
};
if (Array.isArray(values)) {
values.forEach((val) => {
removeOption(val, this.isMultiple);
});
} else {
removeOption(values, this.isMultiple);
}
this.setNewValue();
this.sortElements(this.el, "option");
this.sortElements(this.dropdown, "[data-value]");
}
recalculateDirection() {
if (this?.dropdownVerticalFixedPlacement && (this.dropdown.classList.contains("bottom-full") || this.dropdown.classList.contains("top-full"))) return false;
if (this?.dropdownVerticalFixedPlacement === "top") {
this.dropdown.classList.add("bottom-full");
this.dropdown.style.marginBottom = `${this.dropdownSpace}px`;
} else if (this?.dropdownVerticalFixedPlacement === "bottom") {
this.dropdown.classList.add("top-full");
this.dropdown.style.marginTop = `${this.dropdownSpace}px`;
} else if (isEnoughSpace(
this.dropdown,
this.toggle || this.tagsInput,
"bottom",
this.dropdownSpace,
this.viewport
)) {
this.dropdown.classList.remove("bottom-full");
if (this.dropdownDirectionClasses?.bottom) {
this.dropdown.classList.remove(this.dropdownDirectionClasses.bottom);
}
this.dropdown.style.marginBottom = "";
this.dropdown.classList.add("top-full");
if (this.dropdownDirectionClasses?.top) {
this.dropdown.classList.add(this.dropdownDirectionClasses.top);
}
this.dropdown.style.marginTop = `${this.dropdownSpace}px`;
} else {
this.dropdown.classList.remove("top-full");
if (this.dropdownDirectionClasses?.top) {
this.dropdown.classList.remove(this.dropdownDirectionClasses.top);
}
this.dropdown.style.marginTop = "";
this.dropdown.classList.add("bottom-full");
if (this.dropdownDirectionClasses?.bottom) {
this.dropdown.classList.add(this.dropdownDirectionClasses.bottom);
}
this.dropdown.style.marginBottom = `${this.dropdownSpace}px`;
}
}
isOpened() {
return this._isOpened || false;
}
containsElement(element) {
return this.wrapper?.contains(element) || false;
}
// Static methods
static findInCollection(target) {
return window.$hsSelectCollection.find((el) => {
if (target instanceof _HSSelect) return el.element.el === target.el;
else if (typeof target === "string") {
return el.element.el === document.querySelector(target);
} else return el.element.el === target;
}) || null;
}
static getInstance(target, isInstance) {
const elInCollection = window.$hsSelectCollection.find(
(el) => el.element.el === (typeof target === "string" ? document.querySelector(target) : target)
);
return elInCollection ? isInstance ? elInCollection : elInCollection.element : null;
}
static autoInit() {
if (!window.$hsSelectCollection) {
window.$hsSelectCollection = [];
window.addEventListener("click", (evt) => {
const evtTarget = evt.target;
_HSSelect.closeCurrentlyOpened(evtTarget);
});
}
if (window.$hsSelectCollection) {
window.$hsSelectCollection = window.$hsSelectCollection.filter(
({ element }) => document.contains(element.el)
);
}
document.querySelectorAll("[data-hs-select]:not(.--prevent-on-load-init)").forEach((el) => {
if (!window.$hsSelectCollection.find(
(elC) => elC?.element?.el === el
)) {
const data = el.getAttribute("data-hs-select");
const options = data ? JSON.parse(data) : {};
new _HSSelect(el, options);
}
});
}
static open(target) {
const instance = _HSSelect.findInCollection(target);
if (instance && !instance.element.isOpened()) instance.element.open();
}
static close(target) {
const instance = _HSSelect.findInCollection(target);
if (instance && instance.element.isOpened()) instance.element.close();
}
static closeCurrentlyOpened(evtTarget = null) {
if (!evtTarget.closest(".hs-select.active") && !evtTarget.closest("[data-hs-select-dropdown].opened")) {
const currentlyOpened = window.$hsSelectCollection.filter(
(el) => el.element.isOpened()
) || null;
if (currentlyOpened) {
currentlyOpened.forEach((el) => {
el.element.close();
});
}
}
}
};
window.addEventListener("load", () => {
HSSelect.autoInit();
});
document.addEventListener("scroll", () => {
if (!window.$hsSelectCollection) return false;
const target = window.$hsSelectCollection.find((el) => el.element.isOpened());
if (target) target.element.recalculateDirection();
});
if (typeof window !== "undefined") {
window.HSSelect = HSSelect;
}
select_default = HSSelect;
}
});
// node_modules/preline/src/plugins/datatable/index.ts
var datatable_exports = {};
__export(datatable_exports, {
default: () => datatable_default
});
var HSDataTable, datatable_default;
var init_datatable = __esm({
"node_modules/preline/src/plugins/datatable/index.ts"() {
init_utils();
init_base_plugin();
HSDataTable = class _HSDataTable extends HSBasePlugin {
concatOptions;
dataTable;
table;
searches;
pageEntitiesList;
pagingList;
pagingPagesList;
pagingPrevList;
pagingNextList;
infoList;
rowSelectingAll;
rowSelectingIndividual;
maxPagesToShow;
isRowSelecting;
pageBtnClasses;
onSearchInputListener;
onPageEntitiesChangeListener;
onSinglePagingClickListener;
onPagingPrevClickListener;
onPagingNextClickListener;
onRowSelectingAllChangeListener;
constructor(el, options, events) {
super(el, options, events);
this.el = typeof el === "string" ? document.querySelector(el) : el;
const columnDefs = [];
Array.from(this.el.querySelectorAll("thead th, thead td")).forEach(
(th, ind) => {
if (th.classList.contains("--exclude-from-ordering"))
columnDefs.push({
targets: ind,
orderable: false
});
}
);
const data = this.el.getAttribute("data-hs-datatable");
const dataOptions = data ? JSON.parse(data) : {};
this.concatOptions = {
searching: true,
lengthChange: false,
order: [],
columnDefs: [...columnDefs],
...dataOptions,
...options
};
this.table = this.el.querySelector("table");
this.searches = Array.from(this.el.querySelectorAll("[data-hs-datatable-search]")) ?? null;
this.pageEntitiesList = Array.from(this.el.querySelectorAll("[data-hs-datatable-page-entities]")) ?? null;
this.pagingList = Array.from(this.el.querySelectorAll("[data-hs-datatable-paging]")) ?? null;
this.pagingPagesList = Array.from(this.el.querySelectorAll("[data-hs-datatable-paging-pages]")) ?? null;
this.pagingPrevList = Array.from(this.el.querySelectorAll("[data-hs-datatable-paging-prev]")) ?? null;
this.pagingNextList = Array.from(this.el.querySelectorAll("[data-hs-datatable-paging-next]")) ?? null;
this.infoList = Array.from(this.el.querySelectorAll("[data-hs-datatable-info]")) ?? null;
if (this.concatOptions?.rowSelectingOptions)
this.rowSelectingAll = (this.concatOptions?.rowSelectingOptions?.selectAllSelector ? document.querySelector(
this.concatOptions?.rowSelectingOptions?.selectAllSelector
) : document.querySelector("[data-hs-datatable-row-selecting-all]")) ?? null;
if (this.concatOptions?.rowSelectingOptions)
this.rowSelectingIndividual = this.concatOptions?.rowSelectingOptions?.individualSelector ?? "[data-hs-datatable-row-selecting-individual]";
if (this.pageEntitiesList.length) this.concatOptions.pageLength = parseInt(this.pageEntitiesList[0].value);
this.maxPagesToShow = 3;
this.isRowSelecting = !!this.concatOptions?.rowSelectingOptions;
this.pageBtnClasses = this.concatOptions?.pagingOptions?.pageBtnClasses ?? null;
this.onSearchInputListener = [];
this.onPageEntitiesChangeListener = [];
this.onSinglePagingClickListener = [];
this.onPagingPrevClickListener = [];
this.onPagingNextClickListener = [];
this.init();
}
init() {
this.createCollection(window.$hsDataTableCollection, this);
this.initTable();
if (this.searches.length) this.initSearch();
if (this.pageEntitiesList.length) this.initPageEntities();
if (this.pagingList.length) this.initPaging();
if (this.pagingPagesList.length) this.buildPagingPages();
if (this.pagingPrevList.length) this.initPagingPrev();
if (this.pagingNextList.length) this.initPagingNext();
if (this.infoList.length) this.initInfo();
if (this.isRowSelecting) this.initRowSelecting();
}
initTable() {
this.dataTable = new DataTable(this.table, this.concatOptions);
if (this.isRowSelecting) this.triggerChangeEventToRow();
this.dataTable.on("draw", () => {
if (this.isRowSelecting) this.updateSelectAllCheckbox();
if (this.isRowSelecting) this.triggerChangeEventToRow();
this.updateInfo();
this.pagingPagesList.forEach((el) => this.updatePaging(el));
});
}
searchInput(evt) {
this.onSearchInput(evt.target.value);
}
pageEntitiesChange(evt) {
this.onEntitiesChange(parseInt(evt.target.value), evt.target);
}
pagingPrevClick() {
this.onPrevClick();
}
pagingNextClick() {
this.onNextClick();
}
rowSelectingAllChange() {
this.onSelectAllChange();
}
singlePagingClick(count) {
this.onPageClick(count);
}
// Search
initSearch() {
this.searches.forEach((el) => {
this.onSearchInputListener.push({
el,
fn: debounce((evt) => this.searchInput(evt))
});
el.addEventListener("input", this.onSearchInputListener.find((search) => search.el === el).fn);
});
}
onSearchInput(val) {
this.dataTable.search(val).draw();
}
// Page entities
initPageEntities() {
this.pageEntitiesList.forEach((el) => {
this.onPageEntitiesChangeListener.push({
el,
fn: (evt) => this.pageEntitiesChange(evt)
});
el.addEventListener("change", this.onPageEntitiesChangeListener.find((pageEntity) => pageEntity.el === el).fn);
});
}
onEntitiesChange(entities, target) {
const otherEntities = this.pageEntitiesList.filter((el) => el !== target);
if (otherEntities.length) otherEntities.forEach((el) => {
if (window.HSSelect) {
const hsSelectInstance = window.HSSelect.getInstance(el, true);
if (hsSelectInstance) hsSelectInstance.element.setValue(`${entities}`);
} else el.value = `${entities}`;
});
this.dataTable.page.len(entities).draw();
}
// Info
initInfo() {
this.infoList.forEach((el) => {
this.initInfoFrom(el);
this.initInfoTo(el);
this.initInfoLength(el);
});
}
initInfoFrom(el) {
const infoFrom = el.querySelector("[data-hs-datatable-info-from]") ?? null;
const { start } = this.dataTable.page.info();
if (infoFrom) infoFrom.innerText = `${start + 1}`;
}
initInfoTo(el) {
const infoTo = el.querySelector("[data-hs-datatable-info-to]") ?? null;
const { end } = this.dataTable.page.info();
if (infoTo) infoTo.innerText = `${end}`;
}
initInfoLength(el) {
const infoLength = el.querySelector("[data-hs-datatable-info-length]") ?? null;
const { recordsTotal } = this.dataTable.page.info();
if (infoLength) infoLength.innerText = `${recordsTotal}`;
}
updateInfo() {
this.initInfo();
}
// Paging
initPaging() {
this.pagingList.forEach((el) => this.hidePagingIfSinglePage(el));
}
hidePagingIfSinglePage(el) {
const { pages } = this.dataTable.page.info();
if (pages < 2) {
el.classList.add("hidden");
el.style.display = "none";
} else {
el.classList.remove("hidden");
el.style.display = "";
}
}
initPagingPrev() {
this.pagingPrevList.forEach((el) => {
this.onPagingPrevClickListener.push({
el,
fn: () => this.pagingPrevClick()
});
el.addEventListener("click", this.onPagingPrevClickListener.find((pagingPrev) => pagingPrev.el === el).fn);
});
}
onPrevClick() {
this.dataTable.page("previous").draw("page");
}
disablePagingArrow(el, statement) {
if (statement) {
el.classList.add("disabled");
el.setAttribute("disabled", "disabled");
} else {
el.classList.remove("disabled");
el.removeAttribute("disabled");
}
}
initPagingNext() {
this.pagingNextList.forEach((el) => {
this.onPagingNextClickListener.push({
el,
fn: () => this.pagingNextClick()
});
el.addEventListener("click", this.onPagingNextClickListener.find((pagingNext) => pagingNext.el === el).fn);
});
}
onNextClick() {
this.dataTable.page("next").draw("page");
}
buildPagingPages() {
this.pagingPagesList.forEach((el) => this.updatePaging(el));
}
updatePaging(pagingPages) {
const { page, pages, length } = this.dataTable.page.info();
const totalRecords = this.dataTable.rows({ search: "applied" }).count();
const totalPages = Math.ceil(totalRecords / length);
const currentPage = page + 1;
let startPage = Math.max(1, currentPage - Math.floor(this.maxPagesToShow / 2));
let endPage = Math.min(totalPages, startPage + (this.maxPagesToShow - 1));
if (endPage - startPage + 1 < this.maxPagesToShow) {
startPage = Math.max(1, endPage - this.maxPagesToShow + 1);
}
pagingPages.innerHTML = "";
if (startPage > 1) {
this.buildPagingPage(1, pagingPages);
if (startPage > 2) pagingPages.appendChild(htmlToElement(`... `));
}
for (let i = startPage; i <= endPage; i++) {
this.buildPagingPage(i, pagingPages);
}
if (endPage < totalPages) {
if (endPage < totalPages - 1) pagingPages.appendChild(htmlToElement(`... `));
this.buildPagingPage(totalPages, pagingPages);
}
this.pagingPrevList.forEach((el) => this.disablePagingArrow(el, page === 0));
this.pagingNextList.forEach((el) => this.disablePagingArrow(el, page === pages - 1));
this.pagingList.forEach((el) => this.hidePagingIfSinglePage(el));
}
buildPagingPage(counter, target) {
const { page } = this.dataTable.page.info();
const pageEl = htmlToElement(` `);
pageEl.innerText = `${counter}`;
pageEl.setAttribute("data-page", `${counter}`);
if (this.pageBtnClasses) classToClassList(this.pageBtnClasses, pageEl);
if (page === counter - 1) pageEl.classList.add("active");
this.onSinglePagingClickListener.push({
el: pageEl,
fn: () => this.singlePagingClick(counter)
});
pageEl.addEventListener("click", this.onSinglePagingClickListener.find((singlePaging) => singlePaging.el === pageEl).fn);
target.append(pageEl);
}
onPageClick(counter) {
this.dataTable.page(counter - 1).draw("page");
}
// Select row
initRowSelecting() {
this.onRowSelectingAllChangeListener = () => this.rowSelectingAllChange();
this.rowSelectingAll.addEventListener(
"change",
this.onRowSelectingAllChangeListener
);
}
triggerChangeEventToRow() {
this.table.querySelectorAll(`tbody ${this.rowSelectingIndividual}`).forEach((el) => {
el.addEventListener("change", () => {
this.updateSelectAllCheckbox();
});
});
}
onSelectAllChange() {
let isChecked = this.rowSelectingAll.checked;
const visibleRows = Array.from(
this.dataTable.rows({ page: "current", search: "applied" }).nodes()
);
visibleRows.forEach((el) => {
const checkbox = el.querySelector(this.rowSelectingIndividual);
if (checkbox) checkbox.checked = isChecked;
});
this.updateSelectAllCheckbox();
}
updateSelectAllCheckbox() {
const searchRelatedItems = this.dataTable.rows({ search: "applied" }).count();
if (!searchRelatedItems) {
this.rowSelectingAll.checked = false;
return false;
}
let isChecked = true;
const visibleRows = Array.from(
this.dataTable.rows({
page: "current",
search: "applied"
}).nodes()
);
visibleRows.forEach((el) => {
const checkbox = el.querySelector(this.rowSelectingIndividual);
if (checkbox && !checkbox.checked) {
isChecked = false;
return false;
}
});
this.rowSelectingAll.checked = isChecked;
}
// Public methods
destroy() {
if (this.searches) {
this.onSearchInputListener.forEach(({ el, fn }) => el.removeEventListener("click", fn));
}
if (this.pageEntitiesList) this.onPageEntitiesChangeListener.forEach(({ el, fn }) => el.removeEventListener("change", fn));
if (this.pagingPagesList.length) {
this.onSinglePagingClickListener.forEach(({ el, fn }) => el.removeEventListener("click", fn));
this.pagingPagesList.forEach((el) => el.innerHTML = "");
}
if (this.pagingPrevList.length) this.onPagingPrevClickListener.forEach(({ el, fn }) => el.removeEventListener("click", fn));
if (this.pagingNextList.length) this.onPagingNextClickListener.forEach(({ el, fn }) => el.removeEventListener("click", fn));
if (this.rowSelectingAll)
this.rowSelectingAll.removeEventListener(
"change",
this.onRowSelectingAllChangeListener
);
this.dataTable.destroy();
this.rowSelectingAll = null;
this.rowSelectingIndividual = null;
window.$hsDataTableCollection = window.$hsDataTableCollection.filter(({ element }) => element.el !== this.el);
}
// Static methods
static getInstance(target, isInstance) {
const elInCollection = window.$hsDataTableCollection.find(
(el) => el.element.el === (typeof target === "string" ? document.querySelector(target) : target)
);
return elInCollection ? isInstance ? elInCollection : elInCollection.element.el : null;
}
static autoInit() {
if (!window.$hsDataTableCollection) window.$hsDataTableCollection = [];
if (window.$hsDataTableCollection)
window.$hsDataTableCollection = window.$hsDataTableCollection.filter(
({ element }) => document.contains(element.el)
);
document.querySelectorAll("[data-hs-datatable]:not(.--prevent-on-load-init)").forEach((el) => {
if (!window.$hsDataTableCollection.find(
(elC) => elC?.element?.el === el
))
new _HSDataTable(el);
});
}
};
window.addEventListener("load", () => {
if (document.querySelectorAll(
"[data-hs-datatable]:not(.--prevent-on-load-init)"
).length) {
if (typeof jQuery === "undefined")
console.error(
"HSDataTable: jQuery is not available, please add it to the page."
);
if (typeof DataTable === "undefined")
console.error(
"HSDataTable: DataTable is not available, please add it to the page."
);
}
if (typeof DataTable !== "undefined" && typeof jQuery !== "undefined")
HSDataTable.autoInit();
});
if (typeof window !== "undefined") {
window.HSDataTable = HSDataTable;
}
datatable_default = HSDataTable;
}
});
// node_modules/preline/src/plugins/file-upload/index.ts
var file_upload_exports = {};
__export(file_upload_exports, {
default: () => file_upload_default
});
var HSFileUpload, file_upload_default;
var init_file_upload = __esm({
"node_modules/preline/src/plugins/file-upload/index.ts"() {
init_utils();
init_base_plugin();
if (typeof Dropzone !== "undefined") Dropzone.autoDiscover = false;
HSFileUpload = class _HSFileUpload extends HSBasePlugin {
concatOptions;
previewTemplate;
extensions = {};
singleton;
dropzone;
onReloadButtonClickListener;
onTempFileInputChangeListener;
constructor(el, options, events) {
super(el, options, events);
this.el = typeof el === "string" ? document.querySelector(el) : el;
const data = this.el.getAttribute("data-hs-file-upload");
const dataOptions = data ? JSON.parse(data) : {};
this.previewTemplate = this.el.querySelector("[data-hs-file-upload-preview]")?.innerHTML || ``;
this.extensions = _.merge(
{
default: {
icon: ' ',
class: "size-5"
},
xls: {
icon: ' ',
class: "size-5"
},
doc: {
icon: ' ',
class: "size-5"
},
zip: {
icon: ' ',
class: "size-5"
}
},
dataOptions.extensions
);
this.singleton = dataOptions.singleton;
this.concatOptions = {
clickable: this.el.querySelector(
"[data-hs-file-upload-trigger]"
),
previewsContainer: this.el.querySelector(
"[data-hs-file-upload-previews]"
),
addRemoveLinks: false,
previewTemplate: this.previewTemplate,
autoHideTrigger: false,
...dataOptions,
...options
};
this.onReloadButtonClickListener = [];
this.onTempFileInputChangeListener = [];
this.init();
}
tempFileInputChange(event, file) {
const input = event.target;
const newFile = input.files?.[0];
if (newFile) {
const dzNewFile = newFile;
dzNewFile.status = Dropzone.ADDED;
dzNewFile.accepted = true;
dzNewFile.previewElement = file.previewElement;
dzNewFile.previewTemplate = file.previewTemplate;
dzNewFile.previewsContainer = file.previewsContainer;
this.dropzone.removeFile(file);
this.dropzone.addFile(dzNewFile);
}
}
reloadButtonClick(evt, file) {
evt.preventDefault();
evt.stopPropagation();
const tempFileInput = document.createElement("input");
tempFileInput.type = "file";
this.onTempFileInputChangeListener.push({
el: tempFileInput,
fn: (event) => this.tempFileInputChange(event, file)
});
tempFileInput.click();
tempFileInput.addEventListener(
"change",
this.onTempFileInputChangeListener.find((el) => el.el === tempFileInput).fn
);
}
init() {
this.createCollection(window.$hsFileUploadCollection, this);
this.initDropzone();
}
initDropzone() {
const clear = this.el.querySelector(
"[data-hs-file-upload-clear]"
);
const pseudoTriggers = Array.from(
this.el.querySelectorAll("[data-hs-file-upload-pseudo-trigger]")
);
this.dropzone = new Dropzone(this.el, this.concatOptions);
this.dropzone.on("addedfile", (file) => this.onAddFile(file));
this.dropzone.on("removedfile", () => this.onRemoveFile());
this.dropzone.on(
"uploadprogress",
(file, progress) => this.onUploadProgress(file, progress)
);
this.dropzone.on("complete", (file) => this.onComplete(file));
if (clear)
clear.onclick = () => {
if (this.dropzone.files.length) this.dropzone.removeAllFiles(true);
};
if (pseudoTriggers.length)
pseudoTriggers.forEach((el) => {
el.onclick = () => {
if (this.concatOptions?.clickable)
(this.concatOptions?.clickable).click();
};
});
}
// Public methods
destroy() {
this.onTempFileInputChangeListener.forEach((el) => {
el.el.removeEventListener("change", el.fn);
});
this.onTempFileInputChangeListener = null;
this.onReloadButtonClickListener.forEach((el) => {
el.el.removeEventListener("click", el.fn);
});
this.onReloadButtonClickListener = null;
this.dropzone.destroy();
window.$hsFileUploadCollection = window.$hsFileUploadCollection.filter(
({ element }) => element.el !== this.el
);
}
onAddFile(file) {
const { previewElement } = file;
const reloadButton = file.previewElement.querySelector(
"[data-hs-file-upload-reload]"
);
if (!previewElement) return false;
if (this.singleton && this.dropzone.files.length > 1)
this.dropzone.removeFile(this.dropzone.files[0]);
if (reloadButton) {
this.onReloadButtonClickListener.push({
el: reloadButton,
fn: (evt) => this.reloadButtonClick(evt, file)
});
reloadButton.addEventListener(
"click",
this.onReloadButtonClickListener.find((el) => el.el === reloadButton).fn
);
}
this.previewAccepted(file);
}
previewAccepted(file) {
const { previewElement } = file;
const fileInfo = this.splitFileName(file.name);
const fileName = previewElement.querySelector(
"[data-hs-file-upload-file-name]"
);
const fileExt = previewElement.querySelector(
"[data-hs-file-upload-file-ext]"
);
const fileSize = previewElement.querySelector(
"[data-hs-file-upload-file-size]"
);
const fileIcon = previewElement.querySelector(
"[data-hs-file-upload-file-icon]"
);
const trigger = this.el.querySelector(
"[data-hs-file-upload-trigger]"
);
const preview = previewElement.querySelector(
"[data-dz-thumbnail]"
);
const remove = previewElement.querySelector(
"[data-hs-file-upload-remove]"
);
if (fileName) fileName.textContent = fileInfo.name;
if (fileExt) fileExt.textContent = fileInfo.extension;
if (fileSize) fileSize.textContent = this.formatFileSize(file.size);
if (preview) {
if (file.type.includes("image/")) preview.classList.remove("hidden");
else this.setIcon(fileInfo.extension, fileIcon);
}
if (this.dropzone.files.length > 0 && this.concatOptions.autoHideTrigger)
trigger.style.display = "none";
if (remove) remove.onclick = () => this.dropzone.removeFile(file);
}
onRemoveFile() {
const trigger = this.el.querySelector(
"[data-hs-file-upload-trigger]"
);
if (this.dropzone.files.length === 0 && this.concatOptions.autoHideTrigger)
trigger.style.display = "";
}
onUploadProgress(file, progress) {
const { previewElement } = file;
if (!previewElement) return false;
const progressBar = previewElement.querySelector(
"[data-hs-file-upload-progress-bar]"
);
const progressBarPane = previewElement.querySelector(
"[data-hs-file-upload-progress-bar-pane]"
);
const progressBarValue = previewElement.querySelector(
"[data-hs-file-upload-progress-bar-value]"
);
const currentProgress = Math.floor(progress);
if (progressBar)
progressBar.setAttribute("aria-valuenow", `${currentProgress}`);
if (progressBarPane) progressBarPane.style.width = `${currentProgress}%`;
if (progressBarValue) progressBarValue.innerText = `${currentProgress}`;
}
onComplete(file) {
const { previewElement } = file;
if (!previewElement) return false;
previewElement.classList.add("complete");
}
setIcon(ext, file) {
const icon = this.createIcon(ext);
file.append(icon);
}
createIcon(ext) {
const icon = this.extensions[ext]?.icon ? htmlToElement(this.extensions[ext].icon) : htmlToElement(this.extensions.default.icon);
classToClassList(
this.extensions[ext]?.class ? this.extensions[ext].class : this.extensions.default.class,
icon
);
return icon;
}
formatFileSize(size2) {
if (size2 < 1024) {
return size2.toFixed(2) + " B";
} else if (size2 < 1024 * 1024) {
return (size2 / 1024).toFixed(2) + " KB";
} else if (size2 < 1024 * 1024 * 1024) {
return (size2 / (1024 * 1024)).toFixed(2) + " MB";
} else if (size2 < 1024 * 1024 * 1024 * 1024) {
return (size2 / (1024 * 1024 * 1024)).toFixed(2) + " GB";
} else {
return (size2 / (1024 * 1024 * 1024 * 1024)).toFixed(2) + " TB";
}
}
splitFileName(file) {
let dotIndex = file.lastIndexOf(".");
if (dotIndex == -1) return { name: file, extension: "" };
return {
name: file.substring(0, dotIndex),
extension: file.substring(dotIndex + 1)
};
}
// Static methods
static getInstance(target, isInstance) {
const elInCollection = window.$hsFileUploadCollection.find(
(el) => el.element.el === (typeof target === "string" ? document.querySelector(target) : target)
);
return elInCollection ? isInstance ? elInCollection : elInCollection.element.el : null;
}
static autoInit() {
if (!window.$hsFileUploadCollection) window.$hsFileUploadCollection = [];
if (window.$hsFileUploadCollection)
window.$hsFileUploadCollection = window.$hsFileUploadCollection.filter(
({ element }) => document.contains(element.el)
);
document.querySelectorAll("[data-hs-file-upload]:not(.--prevent-on-load-init)").forEach((el) => {
if (!window.$hsFileUploadCollection.find(
(elC) => elC?.element?.el === el
))
new _HSFileUpload(el);
});
}
};
window.addEventListener("load", () => {
if (document.querySelectorAll(
"[data-hs-file-upload]:not(.--prevent-on-load-init)"
).length) {
if (typeof _ === "undefined")
console.error(
"HSFileUpload: Lodash is not available, please add it to the page."
);
if (typeof Dropzone === "undefined")
console.error(
"HSFileUpload: Dropzone is not available, please add it to the page."
);
}
if (typeof _ !== "undefined" && typeof Dropzone !== "undefined") {
HSFileUpload.autoInit();
}
});
if (typeof window !== "undefined") {
window.HSFileUpload = HSFileUpload;
}
file_upload_default = HSFileUpload;
}
});
// node_modules/preline/src/plugins/range-slider/index.ts
var range_slider_exports = {};
__export(range_slider_exports, {
default: () => range_slider_default
});
var HSRangeSlider, range_slider_default;
var init_range_slider = __esm({
"node_modules/preline/src/plugins/range-slider/index.ts"() {
init_base_plugin();
HSRangeSlider = class _HSRangeSlider extends HSBasePlugin {
concatOptions;
wrapper;
currentValue;
format;
icons;
constructor(el, options, events) {
super(el, options, events);
const data = el.getAttribute("data-hs-range-slider");
const dataOptions = data ? JSON.parse(data) : {};
this.concatOptions = {
...dataOptions,
...options,
cssClasses: {
...noUiSlider.cssClasses,
...this.processClasses(dataOptions.cssClasses)
}
};
this.wrapper = this.concatOptions.wrapper || el.closest(".hs-range-slider-wrapper") || null;
this.currentValue = this.concatOptions.currentValue ? Array.from(this.concatOptions.currentValue) : Array.from(
this.wrapper?.querySelectorAll(".hs-range-slider-current-value") || []
);
this.icons = this.concatOptions.icons || {};
this.init();
}
get formattedValue() {
const values = this.el.noUiSlider.get();
if (Array.isArray(values) && this.format) {
const updateValues = [];
values.forEach((val) => {
updateValues.push(this.format.to(val));
});
return updateValues;
} else if (this.format) {
return this.format.to(values);
} else {
return values;
}
}
processClasses(cl) {
const mergedClasses = {};
Object.keys(cl).forEach((key) => {
if (key) mergedClasses[key] = `${noUiSlider.cssClasses[key]} ${cl[key]}`;
});
return mergedClasses;
}
init() {
this.createCollection(window.$hsRangeSliderCollection, this);
if (typeof this.concatOptions?.formatter === "object" ? this.concatOptions?.formatter?.type === "thousandsSeparatorAndDecimalPoints" : this.concatOptions?.formatter === "thousandsSeparatorAndDecimalPoints") {
this.thousandsSeparatorAndDecimalPointsFormatter();
} else if (typeof this.concatOptions?.formatter === "object" ? this.concatOptions?.formatter?.type === "integer" : this.concatOptions?.formatter === "integer") {
this.integerFormatter();
} else if (typeof this.concatOptions?.formatter === "object" && (this.concatOptions?.formatter?.prefix || this.concatOptions?.formatter?.postfix)) {
this.prefixOrPostfixFormatter();
}
noUiSlider.create(this.el, this.concatOptions);
if (this.currentValue && this.currentValue.length > 0) {
this.el.noUiSlider.on(
"update",
(values) => {
this.updateCurrentValue(values);
}
);
}
if (this.concatOptions.disabled) this.setDisabled();
if (this.icons.handle) this.buildHandleIcon();
}
formatValue(val) {
let result = "";
if (typeof this.concatOptions?.formatter === "object") {
if (this.concatOptions?.formatter?.prefix) {
result += this.concatOptions?.formatter?.prefix;
}
result += val;
if (this.concatOptions?.formatter?.postfix) {
result += this.concatOptions?.formatter?.postfix;
}
} else result += val;
return result;
}
integerFormatter() {
this.format = {
to: (val) => this.formatValue(Math.round(val)),
from: (val) => Math.round(+val)
};
if (this.concatOptions?.tooltips) this.concatOptions.tooltips = this.format;
}
prefixOrPostfixFormatter() {
this.format = {
to: (val) => this.formatValue(val),
from: (val) => +val
};
if (this.concatOptions?.tooltips) this.concatOptions.tooltips = this.format;
}
thousandsSeparatorAndDecimalPointsFormatter() {
this.format = {
to: (val) => this.formatValue(
new Intl.NumberFormat("en-US", {
minimumFractionDigits: 2,
maximumFractionDigits: 2
}).format(val)
),
from: (val) => parseFloat(val.replace(/,/g, ""))
};
if (this.concatOptions?.tooltips) this.concatOptions.tooltips = this.format;
}
setDisabled() {
this.el.setAttribute("disabled", "disabled");
this.el.classList.add("disabled");
}
buildHandleIcon() {
if (!this.icons.handle) return false;
const handle = this.el.querySelector(".noUi-handle");
if (!handle) return false;
handle.innerHTML = this.icons.handle;
}
updateCurrentValue(values) {
if (!this.currentValue || this.currentValue.length === 0) return;
values.forEach((value, index) => {
const element = this.currentValue?.[index];
if (!element) return;
const formattedValue = this.format ? this.format.to(value).toString() : value.toString();
if (element instanceof HTMLInputElement) {
element.value = formattedValue;
} else {
element.textContent = formattedValue;
}
});
}
// Public methods
destroy() {
this.el.noUiSlider.destroy();
this.format = null;
window.$hsRangeSliderCollection = window.$hsRangeSliderCollection.filter(
({ element }) => element.el !== this.el
);
}
// Static methods
static getInstance(target, isInstance = false) {
const elInCollection = window.$hsRangeSliderCollection.find(
(el) => el.element.el === (typeof target === "string" ? document.querySelector(target) : target)
);
return elInCollection ? isInstance ? elInCollection : elInCollection.element.el : null;
}
static autoInit() {
if (!window.$hsRangeSliderCollection) window.$hsRangeSliderCollection = [];
if (window.$hsRangeSliderCollection) {
window.$hsRangeSliderCollection = window.$hsRangeSliderCollection.filter(
({ element }) => document.contains(element.el)
);
}
document.querySelectorAll("[data-hs-range-slider]:not(.--prevent-on-load-init)").forEach((el) => {
if (!window.$hsRangeSliderCollection.find(
(elC) => elC?.element?.el === el
)) {
new _HSRangeSlider(el);
}
});
}
};
window.addEventListener("load", () => {
HSRangeSlider.autoInit();
});
if (typeof window !== "undefined") {
window.HSRangeSlider = HSRangeSlider;
}
range_slider_default = HSRangeSlider;
}
});
// node_modules/vanilla-calendar-pro/index.mjs
function getOffset(e2) {
if (!e2 || !e2.getBoundingClientRect) return { top: 0, bottom: 0, left: 0, right: 0 };
const t = e2.getBoundingClientRect(), n = document.documentElement;
return { bottom: t.bottom, right: t.right, top: t.top + window.scrollY - n.clientTop, left: t.left + window.scrollX - n.clientLeft };
}
function getViewportDimensions() {
return { vw: Math.max(document.documentElement.clientWidth || 0, window.innerWidth || 0), vh: Math.max(document.documentElement.clientHeight || 0, window.innerHeight || 0) };
}
function getWindowScrollPosition() {
return { left: window.scrollX || document.documentElement.scrollLeft || 0, top: window.scrollY || document.documentElement.scrollTop || 0 };
}
function calculateAvailableSpace(e2) {
const { top: t, left: n } = getWindowScrollPosition(), { top: a, left: l } = getOffset(e2), { vh: o, vw: s } = getViewportDimensions(), i = a - t, r = l - n;
return { top: i, bottom: o - (i + e2.clientHeight), left: r, right: s - (r + e2.clientWidth) };
}
function getAvailablePosition(e2, t, n = 5) {
const a = { top: true, bottom: true, left: true, right: true }, l = [];
if (!t || !e2) return { canShow: a, parentPositions: l };
const { bottom: o, top: s } = calculateAvailableSpace(e2), { top: i, left: r } = getOffset(e2), { height: c, width: d } = t.getBoundingClientRect(), { vh: u, vw: m } = getViewportDimensions(), h = m / 2, p = u / 2;
return [{ condition: i < p, position: "top" }, { condition: i > p, position: "bottom" }, { condition: r < h, position: "left" }, { condition: r > h, position: "right" }].forEach(({ condition: e3, position: t2 }) => {
e3 && l.push(t2);
}), Object.assign(a, { top: c <= s - n, bottom: c <= o - n, left: d <= r, right: d <= m - r }), { canShow: a, parentPositions: l };
}
function findBestPickerPosition(e2, t) {
const n = "left";
if (!t || !e2) return n;
const { canShow: a, parentPositions: l } = getAvailablePosition(e2, t), o = a.left && a.right;
return (o && a.bottom ? "center" : o && a.top ? ["top", "center"] : Array.isArray(l) ? ["bottom" === l[0] ? "top" : "bottom", ...l.slice(1)] : l) || n;
}
var __defProp2, __defProps, __getOwnPropDescs, __getOwnPropSymbols, __hasOwnProp2, __propIsEnum, __defNormalProp, __spreadValues, __spreadProps, __publicField, errorMessages, setContext, destroy, hide2, handleDay, createDatePopup, getDate, getDateString, parseDates, updateAttribute, setDateModifier, getLocaleString, getWeekNumber, addWeekNumberForDate, setDaysAsDisabled, createDate, createDatesFromCurrentMonth, createDatesFromNextMonth, createDatesFromPrevMonth, createWeekNumbers, createDates, layoutDefault, layoutMonths, layoutMultiple, layoutYears, ArrowNext, ArrowPrev, ControlTime, DateRangeTooltip, Dates, Month, Months, Week, WeekNumbers, Year, Years, components, getComponent, parseLayout, parseMultipleLayout, createLayouts, setVisibilityArrows, handleDefaultType, handleYearType, visibilityArrows, visibilityHandler, visibilityTitle, setYearModifier, getColumnID, createMonthEl, createMonths, TimeInput, TimeRange, handleActions, transformTime24, handleClickKeepingTime, transformTime12, updateInputAndRange, updateKeepingTime$1, handleInput$1, updateInputAndTime, updateKeepingTime, handleRange, handleMouseOver, handleMouseOut, handleTime, createTime, createWeek, createYearEl, createYears, trackChangesHTMLElement, haveListener, setTheme, trackChangesThemeInSystemSettings, detectTheme, handleTheme, capitalizeFirstLetter, getLocaleWeekday, getLocaleMonth, getLocale, create, handleArrowKeys, handleMonth, handleClickArrow, canToggleSelection, handleSelectDate, createDateRangeTooltip, state, addHoverEffect, removeHoverEffect, handleHoverDatesEvent, handleHoverSelectedDatesRangeEvent, optimizedHoverHandler, optimizedHandleHoverDatesEvent, optimizedHandleHoverSelectedDatesRangeEvent, handleCancelSelectionDates, handleMouseLeave, updateDisabledDates, handleSelectDateRange, updateDateModifier, handleClickDate, typeClick, getValue, handleMultipleYearSelection, handleMultipleMonthSelection, handleItemClick, handleClickType, handleClickMonthOrYear, handleClickWeekNumber, handleClickWeekDay, handleClick, initMonthsCount, getLocalDate, resolveDate, initRange, initSelectedDates, displayClosestValidDate, setInitialContext, initSelectedMonthYear, initTime, initAllVariables, reset, createToInput, handleInput, init, update, replaceProperties, set, setPosition, show, labels, styles, OptionsCalendar, _Calendar, Calendar;
var init_vanilla_calendar_pro = __esm({
"node_modules/vanilla-calendar-pro/index.mjs"() {
__defProp2 = Object.defineProperty;
__defProps = Object.defineProperties;
__getOwnPropDescs = Object.getOwnPropertyDescriptors;
__getOwnPropSymbols = Object.getOwnPropertySymbols;
__hasOwnProp2 = Object.prototype.hasOwnProperty;
__propIsEnum = Object.prototype.propertyIsEnumerable;
__defNormalProp = (e2, t, n) => t in e2 ? __defProp2(e2, t, { enumerable: true, configurable: true, writable: true, value: n }) : e2[t] = n;
__spreadValues = (e2, t) => {
for (var n in t || (t = {})) __hasOwnProp2.call(t, n) && __defNormalProp(e2, n, t[n]);
if (__getOwnPropSymbols) for (var n of __getOwnPropSymbols(t)) __propIsEnum.call(t, n) && __defNormalProp(e2, n, t[n]);
return e2;
};
__spreadProps = (e2, t) => __defProps(e2, __getOwnPropDescs(t));
__publicField = (e2, t, n) => (__defNormalProp(e2, "symbol" != typeof t ? t + "" : t, n), n);
errorMessages = { notFoundSelector: (e2) => `${e2} is not found, check the first argument passed to new Calendar.`, notInit: 'The calendar has not been initialized, please initialize it using the "init()" method first.', notLocale: "You specified an incorrect language label or did not specify the required number of values \u200B\u200Bfor \xABlocale.weekdays\xBB or \xABlocale.months\xBB.", incorrectTime: "The value of the time property can be: false, 12 or 24.", incorrectMonthsCount: "For the \xABmultiple\xBB calendar type, the \xABdisplayMonthsCount\xBB parameter can have a value from 2 to 12, and for all others it cannot be greater than 1." };
setContext = (e2, t, n) => {
e2.context[t] = n;
};
destroy = (e2) => {
var t, n, a, l, o;
if (!e2.context.isInit) throw new Error(errorMessages.notInit);
e2.inputMode ? (null == (t = e2.context.mainElement.parentElement) || t.removeChild(e2.context.mainElement), null == (a = null == (n = e2.context.inputElement) ? void 0 : n.replaceWith) || a.call(n, e2.context.originalElement), setContext(e2, "inputElement", void 0)) : null == (o = (l = e2.context.mainElement).replaceWith) || o.call(l, e2.context.originalElement), setContext(e2, "mainElement", e2.context.originalElement), e2.onDestroy && e2.onDestroy(e2);
};
hide2 = (e2) => {
e2.context.isShowInInputMode && e2.context.currentType && (e2.context.mainElement.dataset.vcCalendarHidden = "", setContext(e2, "isShowInInputMode", false), e2.context.cleanupHandlers[0] && (e2.context.cleanupHandlers.forEach((e3) => e3()), setContext(e2, "cleanupHandlers", [])), e2.onHide && e2.onHide(e2));
};
handleDay = (e2, t, n, a) => {
var l;
const o = a.querySelector(`[data-vc-date="${t}"]`), s = null == o ? void 0 : o.querySelector("[data-vc-date-btn]");
if (!o || !s) return;
if ((null == n ? void 0 : n.modifier) && s.classList.add(...n.modifier.trim().split(" ")), !(null == n ? void 0 : n.html)) return;
const i = document.createElement("div");
i.className = e2.styles.datePopup, i.dataset.vcDatePopup = "", i.innerHTML = e2.sanitizerHTML(n.html), s.ariaExpanded = "true", s.ariaLabel = `${s.ariaLabel}, ${null == (l = null == i ? void 0 : i.textContent) ? void 0 : l.replace(/^\s+|\s+(?=\s)|\s+$/g, "").replace(/ /g, " ")}`, o.appendChild(i), requestAnimationFrame(() => {
if (!i) return;
const { canShow: e3 } = getAvailablePosition(o, i), t2 = e3.bottom ? o.offsetHeight : -i.offsetHeight, n2 = e3.left && !e3.right ? o.offsetWidth - i.offsetWidth / 2 : !e3.left && e3.right ? i.offsetWidth / 2 : 0;
Object.assign(i.style, { left: `${n2}px`, top: `${t2}px` });
});
};
createDatePopup = (e2, t) => {
var n;
e2.popups && (null == (n = Object.entries(e2.popups)) || n.forEach(([n2, a]) => handleDay(e2, n2, a, t)));
};
getDate = (e2) => /* @__PURE__ */ new Date(`${e2}T00:00:00`);
getDateString = (e2) => `${e2.getFullYear()}-${String(e2.getMonth() + 1).padStart(2, "0")}-${String(e2.getDate()).padStart(2, "0")}`;
parseDates = (e2) => e2.reduce((e3, t) => {
if (t instanceof Date || "number" == typeof t) {
const n = t instanceof Date ? t : new Date(t);
e3.push(n.toISOString().substring(0, 10));
} else t.match(/^(\d{4}-\d{2}-\d{2})$/g) ? e3.push(t) : t.replace(/(\d{4}-\d{2}-\d{2}).*?(\d{4}-\d{2}-\d{2})/g, (t2, n, a) => {
const l = getDate(n), o = getDate(a), s = new Date(l.getTime());
for (; s <= o; s.setDate(s.getDate() + 1)) e3.push(getDateString(s));
return t2;
});
return e3;
}, []);
updateAttribute = (e2, t, n, a = "") => {
t ? e2.setAttribute(n, a) : e2.getAttribute(n) === a && e2.removeAttribute(n);
};
setDateModifier = (e2, t, n, a, l, o, s) => {
var i, r, c, d;
const u = getDate(e2.context.displayDateMin) > getDate(o) || getDate(e2.context.displayDateMax) < getDate(o) || (null == (i = e2.context.disableDates) ? void 0 : i.includes(o)) || !e2.selectionMonthsMode && "current" !== s || !e2.selectionYearsMode && getDate(o).getFullYear() !== t;
updateAttribute(n, u, "data-vc-date-disabled"), a && updateAttribute(a, u, "aria-disabled", "true"), a && updateAttribute(a, u, "tabindex", "-1"), updateAttribute(n, !e2.disableToday && e2.context.dateToday === o, "data-vc-date-today"), updateAttribute(n, !e2.disableToday && e2.context.dateToday === o, "aria-current", "date"), updateAttribute(n, null == (r = e2.selectedWeekends) ? void 0 : r.includes(l), "data-vc-date-weekend");
const m = (null == (c = e2.selectedHolidays) ? void 0 : c[0]) ? parseDates(e2.selectedHolidays) : [];
if (updateAttribute(n, m.includes(o), "data-vc-date-holiday"), (null == (d = e2.context.selectedDates) ? void 0 : d.includes(o)) ? (n.setAttribute("data-vc-date-selected", ""), a && a.setAttribute("aria-selected", "true"), e2.context.selectedDates.length > 1 && "multiple-ranged" === e2.selectionDatesMode && (e2.context.selectedDates[0] === o && e2.context.selectedDates[e2.context.selectedDates.length - 1] === o ? n.setAttribute("data-vc-date-selected", "first-and-last") : e2.context.selectedDates[0] === o ? n.setAttribute("data-vc-date-selected", "first") : e2.context.selectedDates[e2.context.selectedDates.length - 1] === o && n.setAttribute("data-vc-date-selected", "last"), e2.context.selectedDates[0] !== o && e2.context.selectedDates[e2.context.selectedDates.length - 1] !== o && n.setAttribute("data-vc-date-selected", "middle"))) : n.hasAttribute("data-vc-date-selected") && (n.removeAttribute("data-vc-date-selected"), a && a.removeAttribute("aria-selected")), !e2.context.disableDates.includes(o) && e2.enableEdgeDatesOnly && e2.context.selectedDates.length > 1 && "multiple-ranged" === e2.selectionDatesMode) {
const t2 = getDate(e2.context.selectedDates[0]), a2 = getDate(e2.context.selectedDates[e2.context.selectedDates.length - 1]), l2 = getDate(o);
updateAttribute(n, l2 > t2 && l2 < a2, "data-vc-date-selected", "middle");
}
};
getLocaleString = (e2, t, n) => (/* @__PURE__ */ new Date(`${e2}T00:00:00.000Z`)).toLocaleString(t, n);
getWeekNumber = (e2, t) => {
const n = getDate(e2), a = (n.getDay() - t + 7) % 7;
n.setDate(n.getDate() + 4 - a);
const l = new Date(n.getFullYear(), 0, 1), o = Math.ceil(((+n - +l) / 864e5 + 1) / 7);
return { year: n.getFullYear(), week: o };
};
addWeekNumberForDate = (e2, t, n) => {
const a = getWeekNumber(n, e2.firstWeekday);
a && (t.dataset.vcDateWeekNumber = String(a.week));
};
setDaysAsDisabled = (e2, t, n) => {
var a, l, o, s, i;
const r = null == (a = e2.disableWeekdays) ? void 0 : a.includes(n), c = e2.disableAllDates && !!(null == (l = e2.context.enableDates) ? void 0 : l[0]);
!r && !c || (null == (o = e2.context.enableDates) ? void 0 : o.includes(t)) || (null == (s = e2.context.disableDates) ? void 0 : s.includes(t)) || (e2.context.disableDates.push(t), null == (i = e2.context.disableDates) || i.sort((e3, t2) => +new Date(e3) - +new Date(t2)));
};
createDate = (e2, t, n, a, l, o) => {
const s = getDate(l).getDay(), i = "string" == typeof e2.locale && e2.locale.length ? e2.locale : "en", r = document.createElement("div");
let c;
r.className = e2.styles.date, r.dataset.vcDate = l, r.dataset.vcDateMonth = o, r.dataset.vcDateWeekDay = String(s), ("current" === o || e2.displayDatesOutside) && (c = document.createElement("button"), c.className = e2.styles.dateBtn, c.type = "button", c.role = "gridcell", c.ariaLabel = getLocaleString(l, i, { dateStyle: "long", timeZone: "UTC" }), c.dataset.vcDateBtn = "", c.innerText = String(a), r.appendChild(c)), e2.enableWeekNumbers && addWeekNumberForDate(e2, r, l), setDaysAsDisabled(e2, l, s), setDateModifier(e2, t, r, c, s, l, o), n.appendChild(r), e2.onCreateDateEls && e2.onCreateDateEls(e2, r);
};
createDatesFromCurrentMonth = (e2, t, n, a, l) => {
for (let o = 1; o <= n; o++) {
const n2 = new Date(a, l, o);
createDate(e2, a, t, o, getDateString(n2), "current");
}
};
createDatesFromNextMonth = (e2, t, n, a, l, o) => {
const s = o + n, i = 7 * Math.ceil(s / 7) - s, r = l + 1 === 12 ? a + 1 : a, c = l + 1 === 12 ? "01" : l + 2 < 10 ? `0${l + 2}` : l + 2;
for (let n2 = 1; n2 <= i; n2++) {
const l2 = n2 < 10 ? `0${n2}` : String(n2);
createDate(e2, a, t, n2, `${r}-${c}-${l2}`, "next");
}
};
createDatesFromPrevMonth = (e2, t, n, a, l) => {
let o = new Date(n, a, 0).getDate() - (l - 1);
const s = 0 === a ? n - 1 : n, i = 0 === a ? 12 : a < 10 ? `0${a}` : a;
for (let a2 = l; a2 > 0; a2--, o++) {
createDate(e2, n, t, o, `${s}-${i}-${o}`, "prev");
}
};
createWeekNumbers = (e2, t, n, a, l) => {
if (!e2.enableWeekNumbers) return;
a.textContent = "";
const o = document.createElement("b");
o.className = e2.styles.weekNumbersTitle, o.innerText = "#", o.dataset.vcWeekNumbers = "title", a.appendChild(o);
const s = document.createElement("div");
s.className = e2.styles.weekNumbersContent, s.dataset.vcWeekNumbers = "content", a.appendChild(s);
const i = document.createElement("button");
i.type = "button", i.className = e2.styles.weekNumber;
const r = l.querySelectorAll("[data-vc-date]"), c = Math.ceil((t + n) / 7);
for (let t2 = 0; t2 < c; t2++) {
const n2 = r[0 === t2 ? 6 : 7 * t2].dataset.vcDate, a2 = getWeekNumber(n2, e2.firstWeekday);
if (!a2) return;
const l2 = i.cloneNode(true);
l2.innerText = String(a2.week), l2.dataset.vcWeekNumber = String(a2.week), l2.dataset.vcWeekYear = String(a2.year), l2.role = "rowheader", l2.ariaLabel = `${a2.week}`, s.appendChild(l2);
}
};
createDates = (e2) => {
const t = new Date(e2.context.selectedYear, e2.context.selectedMonth, 1), n = e2.context.mainElement.querySelectorAll('[data-vc="dates"]'), a = e2.context.mainElement.querySelectorAll('[data-vc-week="numbers"]');
n.forEach((n2, l) => {
e2.selectionDatesMode || (n2.dataset.vcDatesDisabled = ""), n2.textContent = "";
const o = new Date(t);
o.setMonth(o.getMonth() + l);
const s = o.getMonth(), i = o.getFullYear(), r = (new Date(i, s, 1).getDay() - e2.firstWeekday + 7) % 7, c = new Date(i, s + 1, 0).getDate();
createDatesFromPrevMonth(e2, n2, i, s, r), createDatesFromCurrentMonth(e2, n2, c, i, s), createDatesFromNextMonth(e2, n2, c, i, s, r), createDatePopup(e2, n2), createWeekNumbers(e2, r, c, a[l], n2);
});
};
layoutDefault = (e2) => `
<#WeekNumbers />
<#Week />
<#Dates />
<#DateRangeTooltip />
<#ControlTime />
`;
layoutMonths = (e2) => `
`;
layoutMultiple = (e2) => `
<#ArrowPrev [month] />
<#ArrowNext [month] />
<#Multiple>
<#WeekNumbers />
<#Week />
<#Dates />
<#/Multiple>
<#DateRangeTooltip />
<#ControlTime />
`;
layoutYears = (e2) => `
`;
ArrowNext = (e2, t) => ` `;
ArrowPrev = (e2, t) => ` `;
ControlTime = (e2) => e2.selectionTimeMode ? `
` : "";
DateRangeTooltip = (e2) => e2.onCreateDateRangeTooltip ? `
` : "";
Dates = (e2) => `
`;
Month = (e2) => ` `;
Months = (e2) => `
`;
Week = (e2) => `
`;
WeekNumbers = (e2) => e2.enableWeekNumbers ? `
` : "";
Year = (e2) => ` `;
Years = (e2) => `
`;
components = { ArrowNext, ArrowPrev, ControlTime, Dates, DateRangeTooltip, Month, Months, Week, WeekNumbers, Year, Years };
getComponent = (e2) => components[e2];
parseLayout = (e2, t) => t.replace(/[\n\t]/g, "").replace(/<#(?!\/?Multiple)(.*?)>/g, (t2, n) => {
const a = (n.match(/\[(.*?)\]/) || [])[1], l = n.replace(/[/\s\n\t]|\[(.*?)\]/g, ""), o = getComponent(l), s = o ? o(e2, null != a ? a : null) : "";
return e2.sanitizerHTML(s);
}).replace(/[\n\t]/g, "");
parseMultipleLayout = (e2, t) => t.replace(new RegExp("<#Multiple>(.*?)<#\\/Multiple>", "gs"), (t2, n) => {
const a = Array(e2.context.displayMonthsCount).fill(n).join("");
return e2.sanitizerHTML(a);
}).replace(/[\n\t]/g, "");
createLayouts = (e2, t) => {
const n = { default: layoutDefault, month: layoutMonths, year: layoutYears, multiple: layoutMultiple };
if (Object.keys(n).forEach((t2) => {
const a = t2;
e2.layouts[a].length || (e2.layouts[a] = n[a](e2));
}), e2.context.mainElement.className = e2.styles.calendar, e2.context.mainElement.dataset.vc = "calendar", e2.context.mainElement.dataset.vcType = e2.context.currentType, e2.context.mainElement.role = "application", e2.context.mainElement.tabIndex = 0, e2.context.mainElement.ariaLabel = e2.labels.application, "multiple" !== e2.context.currentType) {
if ("multiple" === e2.type && t) {
const n2 = e2.context.mainElement.querySelector('[data-vc="controls"]'), a = e2.context.mainElement.querySelector('[data-vc="grid"]'), l = t.closest('[data-vc="column"]');
return n2 && e2.context.mainElement.removeChild(n2), a && (a.dataset.vcGrid = "hidden"), l && (l.dataset.vcColumn = e2.context.currentType), void (l && (l.innerHTML = e2.sanitizerHTML(parseLayout(e2, e2.layouts[e2.context.currentType]))));
}
e2.context.mainElement.innerHTML = e2.sanitizerHTML(parseLayout(e2, e2.layouts[e2.context.currentType]));
} else e2.context.mainElement.innerHTML = e2.sanitizerHTML(parseMultipleLayout(e2, parseLayout(e2, e2.layouts[e2.context.currentType])));
};
setVisibilityArrows = (e2, t, n, a) => {
e2.style.visibility = n ? "hidden" : "", t.style.visibility = a ? "hidden" : "";
};
handleDefaultType = (e2, t, n) => {
const a = getDate(getDateString(new Date(e2.context.selectedYear, e2.context.selectedMonth, 1))), l = new Date(a.getTime()), o = new Date(a.getTime());
l.setMonth(l.getMonth() - e2.monthsToSwitch), o.setMonth(o.getMonth() + e2.monthsToSwitch);
const s = getDate(e2.context.dateMin), i = getDate(e2.context.dateMax);
e2.selectionYearsMode || (s.setFullYear(a.getFullYear()), i.setFullYear(a.getFullYear()));
const r = !e2.selectionMonthsMode || l.getFullYear() < s.getFullYear() || l.getFullYear() === s.getFullYear() && l.getMonth() < s.getMonth(), c = !e2.selectionMonthsMode || o.getFullYear() > i.getFullYear() || o.getFullYear() === i.getFullYear() && o.getMonth() > i.getMonth() - (e2.context.displayMonthsCount - 1);
setVisibilityArrows(t, n, r, c);
};
handleYearType = (e2, t, n) => {
const a = getDate(e2.context.dateMin), l = getDate(e2.context.dateMax), o = !!(a.getFullYear() && e2.context.displayYear - 7 <= a.getFullYear()), s = !!(l.getFullYear() && e2.context.displayYear + 7 >= l.getFullYear());
setVisibilityArrows(t, n, o, s);
};
visibilityArrows = (e2) => {
if ("month" === e2.context.currentType) return;
const t = e2.context.mainElement.querySelector('[data-vc-arrow="prev"]'), n = e2.context.mainElement.querySelector('[data-vc-arrow="next"]');
if (!t || !n) return;
({ default: () => handleDefaultType(e2, t, n), year: () => handleYearType(e2, t, n) })["multiple" === e2.context.currentType ? "default" : e2.context.currentType]();
};
visibilityHandler = (e2, t, n, a, l) => {
const o = new Date(a.setFullYear(e2.context.selectedYear, e2.context.selectedMonth + n)).getFullYear(), s = new Date(a.setMonth(e2.context.selectedMonth + n)).getMonth(), i = e2.context.locale.months.long[s], r = t.closest('[data-vc="column"]');
r && (r.ariaLabel = `${i} ${o}`);
const c = { month: { id: s, label: i }, year: { id: o, label: o } };
t.innerText = String(c[l].label), t.dataset[`vc${l.charAt(0).toUpperCase() + l.slice(1)}`] = String(c[l].id), t.ariaLabel = `${e2.labels[l]} ${c[l].label}`;
const d = { month: e2.selectionMonthsMode, year: e2.selectionYearsMode }, u = false === d[l] || "only-arrows" === d[l];
u && (t.tabIndex = -1), t.disabled = u;
};
visibilityTitle = (e2) => {
const t = e2.context.mainElement.querySelectorAll('[data-vc="month"]'), n = e2.context.mainElement.querySelectorAll('[data-vc="year"]'), a = new Date(e2.context.selectedYear, e2.context.selectedMonth, 1);
[t, n].forEach((t2) => null == t2 ? void 0 : t2.forEach((t3, n2) => visibilityHandler(e2, t3, n2, a, t3.dataset.vc)));
};
setYearModifier = (e2, t, n, a, l) => {
var o;
const s = { month: "[data-vc-months-month]", year: "[data-vc-years-year]" }, i = { month: { selected: "data-vc-months-month-selected", aria: "aria-selected", value: "vcMonthsMonth", selectedProperty: "selectedMonth" }, year: { selected: "data-vc-years-year-selected", aria: "aria-selected", value: "vcYearsYear", selectedProperty: "selectedYear" } };
l && (null == (o = e2.context.mainElement.querySelectorAll(s[n])) || o.forEach((e3) => {
e3.removeAttribute(i[n].selected), e3.removeAttribute(i[n].aria);
}), setContext(e2, i[n].selectedProperty, Number(t.dataset[i[n].value])), visibilityTitle(e2), "year" === n && visibilityArrows(e2)), a && (t.setAttribute(i[n].selected, ""), t.setAttribute(i[n].aria, "true"));
};
getColumnID = (e2, t) => {
var n;
if ("multiple" !== e2.type) return { currentValue: null, columnID: 0 };
const a = e2.context.mainElement.querySelectorAll('[data-vc="column"]'), l = Array.from(a).findIndex((e3) => e3.closest(`[data-vc-column="${t}"]`));
return { currentValue: l >= 0 ? Number(null == (n = a[l].querySelector(`[data-vc="${t}"]`)) ? void 0 : n.getAttribute(`data-vc-${t}`)) : null, columnID: Math.max(l, 0) };
};
createMonthEl = (e2, t, n, a, l, o, s) => {
const i = t.cloneNode(false);
return i.className = e2.styles.monthsMonth, i.innerText = a, i.ariaLabel = l, i.role = "gridcell", i.dataset.vcMonthsMonth = `${s}`, o && (i.ariaDisabled = "true"), o && (i.tabIndex = -1), i.disabled = o, setYearModifier(e2, i, "month", n === s, false), i;
};
createMonths = (e2, t) => {
var n, a;
const l = null == (n = null == t ? void 0 : t.closest('[data-vc="header"]')) ? void 0 : n.querySelector('[data-vc="year"]'), o = l ? Number(l.dataset.vcYear) : e2.context.selectedYear, s = (null == t ? void 0 : t.dataset.vcMonth) ? Number(t.dataset.vcMonth) : e2.context.selectedMonth;
setContext(e2, "currentType", "month"), createLayouts(e2, t), visibilityTitle(e2);
const i = e2.context.mainElement.querySelector('[data-vc="months"]');
if (!e2.selectionMonthsMode || !i) return;
const r = e2.monthsToSwitch > 1 ? e2.context.locale.months.long.map((t2, n2) => s - e2.monthsToSwitch * n2).concat(e2.context.locale.months.long.map((t2, n2) => s + e2.monthsToSwitch * n2)).filter((e3) => e3 >= 0 && e3 <= 12) : Array.from(Array(12).keys()), c = document.createElement("button");
c.type = "button";
for (let t2 = 0; t2 < 12; t2++) {
const n2 = getDate(e2.context.dateMin), a2 = getDate(e2.context.dateMax), l2 = e2.context.displayMonthsCount - 1, { columnID: d } = getColumnID(e2, "month"), u = o <= n2.getFullYear() && t2 < n2.getMonth() + d || o >= a2.getFullYear() && t2 > a2.getMonth() - l2 + d || o > a2.getFullYear() || t2 !== s && !r.includes(t2), m = createMonthEl(e2, c, s, e2.context.locale.months.short[t2], e2.context.locale.months.long[t2], u, t2);
i.appendChild(m), e2.onCreateMonthEls && e2.onCreateMonthEls(e2, m);
}
null == (a = e2.context.mainElement.querySelector("[data-vc-months-month]:not([disabled])")) || a.focus();
};
TimeInput = (e2, t, n, a, l) => `
`;
TimeRange = (e2, t, n, a, l, o, s) => `
`;
handleActions = (e2, t, n, a) => {
({ hour: () => setContext(e2, "selectedHours", n), minute: () => setContext(e2, "selectedMinutes", n) })[a](), setContext(e2, "selectedTime", `${e2.context.selectedHours}:${e2.context.selectedMinutes}${e2.context.selectedKeeping ? ` ${e2.context.selectedKeeping}` : ""}`), e2.onChangeTime && e2.onChangeTime(e2, t, false), e2.inputMode && e2.context.inputElement && e2.context.mainElement && e2.onChangeToInput && e2.onChangeToInput(e2, t);
};
transformTime24 = (e2, t) => {
var n;
return (null == (n = { 0: { AM: "00", PM: "12" }, 1: { AM: "01", PM: "13" }, 2: { AM: "02", PM: "14" }, 3: { AM: "03", PM: "15" }, 4: { AM: "04", PM: "16" }, 5: { AM: "05", PM: "17" }, 6: { AM: "06", PM: "18" }, 7: { AM: "07", PM: "19" }, 8: { AM: "08", PM: "20" }, 9: { AM: "09", PM: "21" }, 10: { AM: "10", PM: "22" }, 11: { AM: "11", PM: "23" }, 12: { AM: "00", PM: "12" } }[Number(e2)]) ? void 0 : n[t]) || String(e2);
};
handleClickKeepingTime = (e2, t, n, a, l) => {
const o = (o2) => {
const s = "AM" === e2.context.selectedKeeping ? "PM" : "AM", i = transformTime24(e2.context.selectedHours, s);
Number(i) <= a && Number(i) >= l ? (setContext(e2, "selectedKeeping", s), n.value = i, handleActions(e2, o2, e2.context.selectedHours, "hour"), t.ariaLabel = `${e2.labels.btnKeeping} ${e2.context.selectedKeeping}`, t.innerText = e2.context.selectedKeeping) : e2.onChangeTime && e2.onChangeTime(e2, o2, true);
};
return t.addEventListener("click", o), () => {
t.removeEventListener("click", o);
};
};
transformTime12 = (e2) => ({ 0: "12", 13: "01", 14: "02", 15: "03", 16: "04", 17: "05", 18: "06", 19: "07", 20: "08", 21: "09", 22: "10", 23: "11" })[Number(e2)] || String(e2);
updateInputAndRange = (e2, t, n, a) => {
e2.value = n, t.value = a;
};
updateKeepingTime$1 = (e2, t, n) => {
t && n && (setContext(e2, "selectedKeeping", n), t.innerText = n);
};
handleInput$1 = (e2, t, n, a, l, o, s) => {
const i = { hour: (i2, r2, c) => {
if (!e2.selectionTimeMode) return;
({ 12: () => {
if (!e2.context.selectedKeeping) return;
const d = Number(transformTime24(r2, e2.context.selectedKeeping));
if (!(d <= o && d >= s)) return updateInputAndRange(n, t, e2.context.selectedHours, e2.context.selectedHours), void (e2.onChangeTime && e2.onChangeTime(e2, c, true));
updateInputAndRange(n, t, transformTime12(r2), transformTime24(r2, e2.context.selectedKeeping)), i2 > 12 && updateKeepingTime$1(e2, a, "PM"), handleActions(e2, c, transformTime12(r2), l);
}, 24: () => {
if (!(i2 <= o && i2 >= s)) return updateInputAndRange(n, t, e2.context.selectedHours, e2.context.selectedHours), void (e2.onChangeTime && e2.onChangeTime(e2, c, true));
updateInputAndRange(n, t, r2, r2), handleActions(e2, c, r2, l);
} })[e2.selectionTimeMode]();
}, minute: (a2, i2, r2) => {
if (!(a2 <= o && a2 >= s)) return n.value = e2.context.selectedMinutes, void (e2.onChangeTime && e2.onChangeTime(e2, r2, true));
n.value = i2, t.value = i2, handleActions(e2, r2, i2, l);
} }, r = (e3) => {
const t2 = Number(n.value), a2 = n.value.padStart(2, "0");
i[l] && i[l](t2, a2, e3);
};
return n.addEventListener("change", r), () => {
n.removeEventListener("change", r);
};
};
updateInputAndTime = (e2, t, n, a, l) => {
t.value = l, handleActions(e2, n, l, a);
};
updateKeepingTime = (e2, t, n) => {
t && (setContext(e2, "selectedKeeping", n), t.innerText = n);
};
handleRange = (e2, t, n, a, l) => {
const o = (o2) => {
const s = Number(t.value), i = t.value.padStart(2, "0"), r = "hour" === l, c = 24 === e2.selectionTimeMode, d = s > 0 && s < 12;
r && !c && updateKeepingTime(e2, a, 0 === s || d ? "AM" : "PM"), updateInputAndTime(e2, n, o2, l, !r || c || d ? i : transformTime12(t.value));
};
return t.addEventListener("input", o), () => {
t.removeEventListener("input", o);
};
};
handleMouseOver = (e2) => e2.setAttribute("data-vc-input-focus", "");
handleMouseOut = (e2) => e2.removeAttribute("data-vc-input-focus");
handleTime = (e2, t) => {
const n = t.querySelector('[data-vc-time-range="hour"] input[name="hour"]'), a = t.querySelector('[data-vc-time-range="minute"] input[name="minute"]'), l = t.querySelector('[data-vc-time-input="hour"] input[name="hour"]'), o = t.querySelector('[data-vc-time-input="minute"] input[name="minute"]'), s = t.querySelector('[data-vc-time="keeping"]');
if (!(n && a && l && o)) return;
const i = (e3) => {
e3.target === n && handleMouseOver(l), e3.target === a && handleMouseOver(o);
}, r = (e3) => {
e3.target === n && handleMouseOut(l), e3.target === a && handleMouseOut(o);
};
return t.addEventListener("mouseover", i), t.addEventListener("mouseout", r), handleInput$1(e2, n, l, s, "hour", e2.timeMaxHour, e2.timeMinHour), handleInput$1(e2, a, o, s, "minute", e2.timeMaxMinute, e2.timeMinMinute), handleRange(e2, n, l, s, "hour"), handleRange(e2, a, o, s, "minute"), s && handleClickKeepingTime(e2, s, n, e2.timeMaxHour, e2.timeMinHour), () => {
t.removeEventListener("mouseover", i), t.removeEventListener("mouseout", r);
};
};
createTime = (e2) => {
const t = e2.context.mainElement.querySelector('[data-vc="time"]');
if (!e2.selectionTimeMode || !t) return;
const [n, a] = [e2.timeMinHour, e2.timeMaxHour], [l, o] = [e2.timeMinMinute, e2.timeMaxMinute], s = e2.context.selectedKeeping ? transformTime24(e2.context.selectedHours, e2.context.selectedKeeping) : e2.context.selectedHours, i = "range" === e2.timeControls;
var r;
t.innerHTML = e2.sanitizerHTML(`
${TimeInput("hour", e2.styles.timeHour, e2.labels, e2.context.selectedHours, i)}
${TimeInput("minute", e2.styles.timeMinute, e2.labels, e2.context.selectedMinutes, i)}
${12 === e2.selectionTimeMode ? (r = e2.context.selectedKeeping, `${r} `) : ""}
${TimeRange("hour", e2.styles.timeRange, e2.labels, n, a, e2.timeStepHour, s)}
${TimeRange("minute", e2.styles.timeRange, e2.labels, l, o, e2.timeStepMinute, e2.context.selectedMinutes)}
`), handleTime(e2, t);
};
createWeek = (e2) => {
const t = e2.selectedWeekends ? [...e2.selectedWeekends] : [], n = [...e2.context.locale.weekdays.long].reduce((n2, a2, l) => [...n2, { id: l, titleShort: e2.context.locale.weekdays.short[l], titleLong: a2, isWeekend: t.includes(l) }], []), a = [...n.slice(e2.firstWeekday), ...n.slice(0, e2.firstWeekday)];
e2.context.mainElement.querySelectorAll('[data-vc="week"]').forEach((t2) => {
const n2 = e2.onClickWeekDay ? document.createElement("button") : document.createElement("b");
e2.onClickWeekDay && (n2.type = "button"), a.forEach((a2) => {
const l = n2.cloneNode(true);
l.innerText = a2.titleShort, l.className = e2.styles.weekDay, l.role = "columnheader", l.ariaLabel = a2.titleLong, l.dataset.vcWeekDay = String(a2.id), a2.isWeekend && (l.dataset.vcWeekDayOff = ""), t2.appendChild(l);
});
});
};
createYearEl = (e2, t, n, a, l) => {
const o = t.cloneNode(false);
return o.className = e2.styles.yearsYear, o.innerText = String(l), o.ariaLabel = String(l), o.role = "gridcell", o.dataset.vcYearsYear = `${l}`, a && (o.ariaDisabled = "true"), a && (o.tabIndex = -1), o.disabled = a, setYearModifier(e2, o, "year", n === l, false), o;
};
createYears = (e2, t) => {
var n;
const a = (null == t ? void 0 : t.dataset.vcYear) ? Number(t.dataset.vcYear) : e2.context.selectedYear;
setContext(e2, "currentType", "year"), createLayouts(e2, t), visibilityTitle(e2), visibilityArrows(e2);
const l = e2.context.mainElement.querySelector('[data-vc="years"]');
if (!e2.selectionYearsMode || !l) return;
const o = "multiple" !== e2.type || e2.context.selectedYear === a ? 0 : 1, s = document.createElement("button");
s.type = "button";
for (let t2 = e2.context.displayYear - 7; t2 < e2.context.displayYear + 8; t2++) {
const n2 = t2 < getDate(e2.context.dateMin).getFullYear() + o || t2 > getDate(e2.context.dateMax).getFullYear(), i = createYearEl(e2, s, a, n2, t2);
l.appendChild(i), e2.onCreateYearEls && e2.onCreateYearEls(e2, i);
}
null == (n = e2.context.mainElement.querySelector("[data-vc-years-year]:not([disabled])")) || n.focus();
};
trackChangesHTMLElement = (e2, t, n) => {
new MutationObserver((e3) => {
for (let a = 0; a < e3.length; a++) {
if (e3[a].attributeName === t) {
n();
break;
}
}
}).observe(e2, { attributes: true });
};
haveListener = { value: false, set: () => haveListener.value = true, check: () => haveListener.value };
setTheme = (e2, t) => e2.dataset.vcTheme = t;
trackChangesThemeInSystemSettings = (e2, t) => {
if (setTheme(e2.context.mainElement, t.matches ? "dark" : "light"), "system" !== e2.selectedTheme || haveListener.check()) return;
const n = (e3) => {
const t2 = document.querySelectorAll('[data-vc="calendar"]');
null == t2 || t2.forEach((t3) => setTheme(t3, e3.matches ? "dark" : "light"));
};
t.addEventListener ? t.addEventListener("change", n) : t.addListener(n), haveListener.set();
};
detectTheme = (e2, t) => {
const n = e2.themeAttrDetect.length ? document.querySelector(e2.themeAttrDetect) : null, a = e2.themeAttrDetect.replace(/^.*\[(.+)\]/g, (e3, t2) => t2);
if (!n || "system" === n.getAttribute(a)) return void trackChangesThemeInSystemSettings(e2, t);
const l = n.getAttribute(a);
l ? (setTheme(e2.context.mainElement, l), trackChangesHTMLElement(n, a, () => {
const t2 = n.getAttribute(a);
t2 && setTheme(e2.context.mainElement, t2);
})) : trackChangesThemeInSystemSettings(e2, t);
};
handleTheme = (e2) => {
"not all" !== window.matchMedia("(prefers-color-scheme)").media ? "system" === e2.selectedTheme ? detectTheme(e2, window.matchMedia("(prefers-color-scheme: dark)")) : setTheme(e2.context.mainElement, e2.selectedTheme) : setTheme(e2.context.mainElement, "light");
};
capitalizeFirstLetter = (e2) => e2.charAt(0).toUpperCase() + e2.slice(1).replace(/\./, "");
getLocaleWeekday = (e2, t, n) => {
const a = /* @__PURE__ */ new Date(`1978-01-0${t + 1}T00:00:00.000Z`), l = a.toLocaleString(n, { weekday: "short", timeZone: "UTC" }), o = a.toLocaleString(n, { weekday: "long", timeZone: "UTC" });
e2.context.locale.weekdays.short.push(capitalizeFirstLetter(l)), e2.context.locale.weekdays.long.push(capitalizeFirstLetter(o));
};
getLocaleMonth = (e2, t, n) => {
const a = /* @__PURE__ */ new Date(`1978-${String(t + 1).padStart(2, "0")}-01T00:00:00.000Z`), l = a.toLocaleString(n, { month: "short", timeZone: "UTC" }), o = a.toLocaleString(n, { month: "long", timeZone: "UTC" });
e2.context.locale.months.short.push(capitalizeFirstLetter(l)), e2.context.locale.months.long.push(capitalizeFirstLetter(o));
};
getLocale = (e2) => {
var t, n, a, l, o, s, i, r;
if (!(e2.context.locale.weekdays.short[6] && e2.context.locale.weekdays.long[6] && e2.context.locale.months.short[11] && e2.context.locale.months.long[11])) if ("string" == typeof e2.locale) {
if ("string" == typeof e2.locale && !e2.locale.length) throw new Error(errorMessages.notLocale);
Array.from({ length: 7 }, (t2, n2) => getLocaleWeekday(e2, n2, e2.locale)), Array.from({ length: 12 }, (t2, n2) => getLocaleMonth(e2, n2, e2.locale));
} else {
if (!((null == (n = null == (t = e2.locale) ? void 0 : t.weekdays) ? void 0 : n.short[6]) && (null == (l = null == (a = e2.locale) ? void 0 : a.weekdays) ? void 0 : l.long[6]) && (null == (s = null == (o = e2.locale) ? void 0 : o.months) ? void 0 : s.short[11]) && (null == (r = null == (i = e2.locale) ? void 0 : i.months) ? void 0 : r.long[11]))) throw new Error(errorMessages.notLocale);
setContext(e2, "locale", __spreadValues({}, e2.locale));
}
};
create = (e2) => {
const t = { default: () => {
createWeek(e2), createDates(e2);
}, multiple: () => {
createWeek(e2), createDates(e2);
}, month: () => createMonths(e2), year: () => createYears(e2) };
handleTheme(e2), getLocale(e2), createLayouts(e2), visibilityTitle(e2), visibilityArrows(e2), createTime(e2), t[e2.context.currentType]();
};
handleArrowKeys = (e2) => {
const t = (t2) => {
var n;
const a = t2.target;
if (!["ArrowUp", "ArrowDown", "ArrowLeft", "ArrowRight"].includes(t2.key) || "button" !== a.localName) return;
const l = Array.from(e2.context.mainElement.querySelectorAll('[data-vc="calendar"] button')), o = l.indexOf(a);
if (-1 === o) return;
const s = (i = l[o]).hasAttribute("data-vc-date-btn") ? 7 : i.hasAttribute("data-vc-months-month") ? 4 : i.hasAttribute("data-vc-years-year") ? 5 : 1;
var i;
const r = (0, { ArrowUp: () => Math.max(0, o - s), ArrowDown: () => Math.min(l.length - 1, o + s), ArrowLeft: () => Math.max(0, o - 1), ArrowRight: () => Math.min(l.length - 1, o + 1) }[t2.key])();
null == (n = l[r]) || n.focus();
};
return e2.context.mainElement.addEventListener("keydown", t), () => e2.context.mainElement.removeEventListener("keydown", t);
};
handleMonth = (e2, t) => {
const n = getDate(getDateString(new Date(e2.context.selectedYear, e2.context.selectedMonth, 1)));
({ prev: () => n.setMonth(n.getMonth() - e2.monthsToSwitch), next: () => n.setMonth(n.getMonth() + e2.monthsToSwitch) })[t](), setContext(e2, "selectedMonth", n.getMonth()), setContext(e2, "selectedYear", n.getFullYear()), visibilityTitle(e2), visibilityArrows(e2), createDates(e2);
};
handleClickArrow = (e2, t) => {
const n = t.target.closest("[data-vc-arrow]");
if (n) {
if (["default", "multiple"].includes(e2.context.currentType)) handleMonth(e2, n.dataset.vcArrow);
else if ("year" === e2.context.currentType && void 0 !== e2.context.displayYear) {
const a = { prev: -15, next: 15 }[n.dataset.vcArrow];
setContext(e2, "displayYear", e2.context.displayYear + a), createYears(e2, t.target);
}
e2.onClickArrow && e2.onClickArrow(e2, t);
}
};
canToggleSelection = (e2) => void 0 === e2.enableDateToggle || ("function" == typeof e2.enableDateToggle ? e2.enableDateToggle(e2) : e2.enableDateToggle);
handleSelectDate = (e2, t, n) => {
const a = t.dataset.vcDate, l = t.closest("[data-vc-date][data-vc-date-selected]"), o = canToggleSelection(e2);
if (l && !o) return;
const s = l ? e2.context.selectedDates.filter((e3) => e3 !== a) : n ? [...e2.context.selectedDates, a] : [a];
setContext(e2, "selectedDates", s);
};
createDateRangeTooltip = (e2, t, n) => {
if (!t) return;
if (!n) return t.dataset.vcDateRangeTooltip = "hidden", void (t.textContent = "");
const a = e2.context.mainElement.getBoundingClientRect(), l = n.getBoundingClientRect();
t.style.left = l.left - a.left + l.width / 2 + "px", t.style.top = l.bottom - a.top - l.height + "px", t.dataset.vcDateRangeTooltip = "visible", t.innerHTML = e2.sanitizerHTML(e2.onCreateDateRangeTooltip(e2, n, t, l, a));
};
state = { self: null, lastDateEl: null, isHovering: false, rangeMin: void 0, rangeMax: void 0, tooltipEl: null, timeoutId: null };
addHoverEffect = (e2, t, n) => {
var a, l, o;
if (!(null == (l = null == (a = state.self) ? void 0 : a.context) ? void 0 : l.selectedDates[0])) return;
const s = getDateString(e2);
(null == (o = state.self.context.disableDates) ? void 0 : o.includes(s)) || (state.self.context.mainElement.querySelectorAll(`[data-vc-date="${s}"]`).forEach((e3) => e3.dataset.vcDateHover = ""), t.forEach((e3) => e3.dataset.vcDateHover = "first"), n.forEach((e3) => {
"first" === e3.dataset.vcDateHover ? e3.dataset.vcDateHover = "first-and-last" : e3.dataset.vcDateHover = "last";
}));
};
removeHoverEffect = () => {
var e2, t;
if (!(null == (t = null == (e2 = state.self) ? void 0 : e2.context) ? void 0 : t.mainElement)) return;
state.self.context.mainElement.querySelectorAll("[data-vc-date-hover]").forEach((e3) => e3.removeAttribute("data-vc-date-hover"));
};
handleHoverDatesEvent = (e2) => {
var t, n;
if (!e2 || !(null == (n = null == (t = state.self) ? void 0 : t.context) ? void 0 : n.selectedDates[0])) return;
if (!e2.closest('[data-vc="dates"]')) return state.lastDateEl = null, createDateRangeTooltip(state.self, state.tooltipEl, null), void removeHoverEffect();
const a = e2.closest("[data-vc-date]");
if (!a || state.lastDateEl === a) return;
state.lastDateEl = a, createDateRangeTooltip(state.self, state.tooltipEl, a), removeHoverEffect();
const l = a.dataset.vcDate, o = getDate(state.self.context.selectedDates[0]), s = getDate(l), i = state.self.context.mainElement.querySelectorAll(`[data-vc-date="${state.self.context.selectedDates[0]}"]`), r = state.self.context.mainElement.querySelectorAll(`[data-vc-date="${l}"]`), [c, d] = o < s ? [i, r] : [r, i], [u, m] = o < s ? [o, s] : [s, o];
for (let e3 = new Date(u); e3 <= m; e3.setDate(e3.getDate() + 1)) addHoverEffect(e3, c, d);
};
handleHoverSelectedDatesRangeEvent = (e2) => {
const t = null == e2 ? void 0 : e2.closest("[data-vc-date-selected]");
if (!t && state.lastDateEl) return state.lastDateEl = null, void createDateRangeTooltip(state.self, state.tooltipEl, null);
t && state.lastDateEl !== t && (state.lastDateEl = t, createDateRangeTooltip(state.self, state.tooltipEl, t));
};
optimizedHoverHandler = (e2) => (t) => {
const n = t.target;
state.isHovering || (state.isHovering = true, requestAnimationFrame(() => {
e2(n), state.isHovering = false;
}));
};
optimizedHandleHoverDatesEvent = optimizedHoverHandler(handleHoverDatesEvent);
optimizedHandleHoverSelectedDatesRangeEvent = optimizedHoverHandler(handleHoverSelectedDatesRangeEvent);
handleCancelSelectionDates = (e2) => {
state.self && "Escape" === e2.key && (state.lastDateEl = null, setContext(state.self, "selectedDates", []), state.self.context.mainElement.removeEventListener("mousemove", optimizedHandleHoverDatesEvent), state.self.context.mainElement.removeEventListener("keydown", handleCancelSelectionDates), createDateRangeTooltip(state.self, state.tooltipEl, null), removeHoverEffect());
};
handleMouseLeave = () => {
null !== state.timeoutId && clearTimeout(state.timeoutId), state.timeoutId = setTimeout(() => {
state.lastDateEl = null, createDateRangeTooltip(state.self, state.tooltipEl, null), removeHoverEffect();
}, 50);
};
updateDisabledDates = () => {
var e2, t, n, a;
if (!(null == (n = null == (t = null == (e2 = state.self) ? void 0 : e2.context) ? void 0 : t.selectedDates) ? void 0 : n[0]) || !(null == (a = state.self.context.disableDates) ? void 0 : a[0])) return;
const l = getDate(state.self.context.selectedDates[0]), [o, s] = state.self.context.disableDates.map((e3) => getDate(e3)).reduce(([e3, t2], n2) => [l >= n2 ? n2 : e3, l < n2 && null === t2 ? n2 : t2], [null, null]);
o && setContext(state.self, "displayDateMin", getDateString(new Date(o.setDate(o.getDate() + 1)))), s && setContext(state.self, "displayDateMax", getDateString(new Date(s.setDate(s.getDate() - 1))));
state.self.disableDatesPast && !state.self.disableAllDates && getDate(state.self.context.displayDateMin) < getDate(state.self.context.dateToday) && setContext(state.self, "displayDateMin", state.self.context.dateToday);
};
handleSelectDateRange = (e2, t) => {
state.self = e2, state.lastDateEl = t, removeHoverEffect(), e2.disableDatesGaps && (state.rangeMin = state.rangeMin ? state.rangeMin : e2.context.displayDateMin, state.rangeMax = state.rangeMax ? state.rangeMax : e2.context.displayDateMax), e2.onCreateDateRangeTooltip && (state.tooltipEl = e2.context.mainElement.querySelector("[data-vc-date-range-tooltip]"));
const n = null == t ? void 0 : t.dataset.vcDate;
if (n) {
const t2 = 1 === e2.context.selectedDates.length && e2.context.selectedDates[0].includes(n), a = t2 && !canToggleSelection(e2) ? [n, n] : t2 && canToggleSelection(e2) ? [] : e2.context.selectedDates.length > 1 ? [n] : [...e2.context.selectedDates, n];
setContext(e2, "selectedDates", a), e2.context.selectedDates.length > 1 && e2.context.selectedDates.sort((e3, t3) => +new Date(e3) - +new Date(t3));
}
({ set: () => (e2.disableDatesGaps && updateDisabledDates(), createDateRangeTooltip(state.self, state.tooltipEl, t), state.self.context.mainElement.removeEventListener("mousemove", optimizedHandleHoverSelectedDatesRangeEvent), state.self.context.mainElement.removeEventListener("mouseleave", handleMouseLeave), state.self.context.mainElement.removeEventListener("keydown", handleCancelSelectionDates), state.self.context.mainElement.addEventListener("mousemove", optimizedHandleHoverDatesEvent), state.self.context.mainElement.addEventListener("mouseleave", handleMouseLeave), state.self.context.mainElement.addEventListener("keydown", handleCancelSelectionDates), () => {
state.self.context.mainElement.removeEventListener("mousemove", optimizedHandleHoverDatesEvent), state.self.context.mainElement.removeEventListener("mouseleave", handleMouseLeave), state.self.context.mainElement.removeEventListener("keydown", handleCancelSelectionDates);
}), reset: () => {
const [n2, a] = [e2.context.selectedDates[0], e2.context.selectedDates[e2.context.selectedDates.length - 1]], l = e2.context.selectedDates[0] !== e2.context.selectedDates[e2.context.selectedDates.length - 1], o = parseDates([`${n2}:${a}`]).filter((t2) => !e2.context.disableDates.includes(t2)), s = l ? e2.enableEdgeDatesOnly ? [n2, a] : o : [e2.context.selectedDates[0], e2.context.selectedDates[0]];
if (setContext(e2, "selectedDates", s), e2.disableDatesGaps && (setContext(e2, "displayDateMin", state.rangeMin), setContext(e2, "displayDateMax", state.rangeMax)), state.self.context.mainElement.removeEventListener("mousemove", optimizedHandleHoverDatesEvent), state.self.context.mainElement.removeEventListener("mouseleave", handleMouseLeave), state.self.context.mainElement.removeEventListener("keydown", handleCancelSelectionDates), e2.onCreateDateRangeTooltip) return e2.context.selectedDates[0] || (state.self.context.mainElement.removeEventListener("mousemove", optimizedHandleHoverSelectedDatesRangeEvent), state.self.context.mainElement.removeEventListener("mouseleave", handleMouseLeave), createDateRangeTooltip(state.self, state.tooltipEl, null)), e2.context.selectedDates[0] && (state.self.context.mainElement.addEventListener("mousemove", optimizedHandleHoverSelectedDatesRangeEvent), state.self.context.mainElement.addEventListener("mouseleave", handleMouseLeave), createDateRangeTooltip(state.self, state.tooltipEl, t)), () => {
state.self.context.mainElement.removeEventListener("mousemove", optimizedHandleHoverSelectedDatesRangeEvent), state.self.context.mainElement.removeEventListener("mouseleave", handleMouseLeave);
};
} })[1 === e2.context.selectedDates.length ? "set" : "reset"]();
};
updateDateModifier = (e2) => {
e2.context.mainElement.querySelectorAll("[data-vc-date]").forEach((t) => {
const n = t.querySelector("[data-vc-date-btn]"), a = t.dataset.vcDate, l = getDate(a).getDay();
setDateModifier(e2, e2.context.selectedYear, t, n, l, a, "current");
});
};
handleClickDate = (e2, t) => {
var n;
const a = t.target, l = a.closest("[data-vc-date-btn]");
if (!e2.selectionDatesMode || !["single", "multiple", "multiple-ranged"].includes(e2.selectionDatesMode) || !l) return;
const o = l.closest("[data-vc-date]");
({ single: () => handleSelectDate(e2, o, false), multiple: () => handleSelectDate(e2, o, true), "multiple-ranged": () => handleSelectDateRange(e2, o) })[e2.selectionDatesMode](), null == (n = e2.context.selectedDates) || n.sort((e3, t2) => +new Date(e3) - +new Date(t2)), e2.onClickDate && e2.onClickDate(e2, t), e2.inputMode && e2.context.inputElement && e2.context.mainElement && e2.onChangeToInput && e2.onChangeToInput(e2, t);
const s = a.closest('[data-vc-date-month="prev"]'), i = a.closest('[data-vc-date-month="next"]');
({ prev: () => e2.enableMonthChangeOnDayClick ? handleMonth(e2, "prev") : updateDateModifier(e2), next: () => e2.enableMonthChangeOnDayClick ? handleMonth(e2, "next") : updateDateModifier(e2), current: () => updateDateModifier(e2) })[s ? "prev" : i ? "next" : "current"]();
};
typeClick = ["month", "year"];
getValue = (e2, t, n) => {
const { currentValue: a, columnID: l } = getColumnID(e2, t);
return "month" === e2.context.currentType && l >= 0 ? n - l : "year" === e2.context.currentType && e2.context.selectedYear !== a ? n - 1 : n;
};
handleMultipleYearSelection = (e2, t) => {
const n = getValue(e2, "year", Number(t.dataset.vcYearsYear)), a = getDate(e2.context.dateMin), l = getDate(e2.context.dateMax), o = e2.context.displayMonthsCount - 1, { columnID: s } = getColumnID(e2, "year"), i = e2.context.selectedMonth < a.getMonth() && n <= a.getFullYear(), r = e2.context.selectedMonth > l.getMonth() - o + s && n >= l.getFullYear(), c = n < a.getFullYear(), d = n > l.getFullYear(), u = i || c ? a.getFullYear() : r || d ? l.getFullYear() : n, m = i || c ? a.getMonth() : r || d ? l.getMonth() - o + s : e2.context.selectedMonth;
setContext(e2, "selectedYear", u), setContext(e2, "selectedMonth", m);
};
handleMultipleMonthSelection = (e2, t) => {
const n = t.closest('[data-vc-column="month"]').querySelector('[data-vc="year"]'), a = getValue(e2, "month", Number(t.dataset.vcMonthsMonth)), l = Number(n.dataset.vcYear), o = getDate(e2.context.dateMin), s = getDate(e2.context.dateMax), i = a < o.getMonth() && l <= o.getFullYear(), r = a > s.getMonth() && l >= s.getFullYear();
setContext(e2, "selectedYear", l), setContext(e2, "selectedMonth", i ? o.getMonth() : r ? s.getMonth() : a);
};
handleItemClick = (e2, t, n, a) => {
var l;
({ year: () => {
if ("multiple" === e2.type) return handleMultipleYearSelection(e2, a);
setContext(e2, "selectedYear", Number(a.dataset.vcYearsYear));
}, month: () => {
if ("multiple" === e2.type) return handleMultipleMonthSelection(e2, a);
setContext(e2, "selectedMonth", Number(a.dataset.vcMonthsMonth));
} })[n]();
({ year: () => {
var n2;
return null == (n2 = e2.onClickYear) ? void 0 : n2.call(e2, e2, t);
}, month: () => {
var n2;
return null == (n2 = e2.onClickMonth) ? void 0 : n2.call(e2, e2, t);
} })[n](), e2.context.currentType !== e2.type ? (setContext(e2, "currentType", e2.type), create(e2), null == (l = e2.context.mainElement.querySelector(`[data-vc="${n}"]`)) || l.focus()) : setYearModifier(e2, a, n, true, true);
};
handleClickType = (e2, t, n) => {
var a;
const l = t.target, o = l.closest(`[data-vc="${n}"]`), s = { year: () => createYears(e2, l), month: () => createMonths(e2, l) };
if (o && e2.onClickTitle && e2.onClickTitle(e2, t), o && e2.context.currentType !== n) return s[n]();
const i = l.closest(`[data-vc-${n}s-${n}]`);
if (i) return handleItemClick(e2, t, n, i);
const r = l.closest('[data-vc="grid"]'), c = l.closest('[data-vc="column"]');
(e2.context.currentType === n && o || "multiple" === e2.type && e2.context.currentType === n && r && !c) && (setContext(e2, "currentType", e2.type), create(e2), null == (a = e2.context.mainElement.querySelector(`[data-vc="${n}"]`)) || a.focus());
};
handleClickMonthOrYear = (e2, t) => {
const n = { month: e2.selectionMonthsMode, year: e2.selectionYearsMode };
typeClick.forEach((a) => {
n[a] && t.target && handleClickType(e2, t, a);
});
};
handleClickWeekNumber = (e2, t) => {
if (!e2.enableWeekNumbers || !e2.onClickWeekNumber) return;
const n = t.target.closest("[data-vc-week-number]"), a = e2.context.mainElement.querySelectorAll("[data-vc-date-week-number]");
if (!n || !a[0]) return;
const l = Number(n.innerText), o = Number(n.dataset.vcWeekYear), s = Array.from(a).filter((e3) => Number(e3.dataset.vcDateWeekNumber) === l);
e2.onClickWeekNumber(e2, l, o, s, t);
};
handleClickWeekDay = (e2, t) => {
if (!e2.onClickWeekDay) return;
const n = t.target.closest("[data-vc-week-day]"), a = t.target.closest('[data-vc="column"]'), l = a ? a.querySelectorAll("[data-vc-date-week-day]") : e2.context.mainElement.querySelectorAll("[data-vc-date-week-day]");
if (!n || !l[0]) return;
const o = Number(n.dataset.vcWeekDay), s = Array.from(l).filter((e3) => Number(e3.dataset.vcDateWeekDay) === o);
e2.onClickWeekDay(e2, o, s, t);
};
handleClick = (e2) => {
const t = (t2) => {
handleClickArrow(e2, t2), handleClickWeekDay(e2, t2), handleClickWeekNumber(e2, t2), handleClickDate(e2, t2), handleClickMonthOrYear(e2, t2);
};
return e2.context.mainElement.addEventListener("click", t), () => e2.context.mainElement.removeEventListener("click", t);
};
initMonthsCount = (e2) => {
if ("multiple" === e2.type && (e2.displayMonthsCount <= 1 || e2.displayMonthsCount > 12)) throw new Error(errorMessages.incorrectMonthsCount);
if ("multiple" !== e2.type && e2.displayMonthsCount > 1) throw new Error(errorMessages.incorrectMonthsCount);
setContext(e2, "displayMonthsCount", e2.displayMonthsCount ? e2.displayMonthsCount : "multiple" === e2.type ? 2 : 1);
};
getLocalDate = () => {
const e2 = /* @__PURE__ */ new Date();
return new Date(e2.getTime() - 6e4 * e2.getTimezoneOffset()).toISOString().substring(0, 10);
};
resolveDate = (e2, t) => "today" === e2 ? getLocalDate() : e2 instanceof Date || "number" == typeof e2 || "string" == typeof e2 ? parseDates([e2])[0] : t;
initRange = (e2) => {
var t, n, a;
const l = resolveDate(e2.dateMin, e2.dateMin), o = resolveDate(e2.dateMax, e2.dateMax), s = resolveDate(e2.displayDateMin, l), i = resolveDate(e2.displayDateMax, o);
setContext(e2, "dateToday", resolveDate(e2.dateToday, e2.dateToday)), setContext(e2, "displayDateMin", s ? getDate(l) >= getDate(s) ? l : s : l), setContext(e2, "displayDateMax", i ? getDate(o) <= getDate(i) ? o : i : o);
const r = e2.disableDatesPast && !e2.disableAllDates && getDate(s) < getDate(e2.context.dateToday);
setContext(e2, "displayDateMin", r || e2.disableAllDates ? e2.context.dateToday : s), setContext(e2, "displayDateMax", e2.disableAllDates ? e2.context.dateToday : i), setContext(e2, "disableDates", e2.disableDates[0] && !e2.disableAllDates ? parseDates(e2.disableDates) : e2.disableAllDates ? [e2.context.displayDateMin] : []), e2.context.disableDates.length > 1 && e2.context.disableDates.sort((e3, t2) => +new Date(e3) - +new Date(t2)), setContext(e2, "enableDates", e2.enableDates[0] ? parseDates(e2.enableDates) : []), (null == (t = e2.context.enableDates) ? void 0 : t[0]) && (null == (n = e2.context.disableDates) ? void 0 : n[0]) && setContext(e2, "disableDates", e2.context.disableDates.filter((t2) => !e2.context.enableDates.includes(t2))), e2.context.enableDates.length > 1 && e2.context.enableDates.sort((e3, t2) => +new Date(e3) - +new Date(t2)), (null == (a = e2.context.enableDates) ? void 0 : a[0]) && e2.disableAllDates && (setContext(e2, "displayDateMin", e2.context.enableDates[0]), setContext(e2, "displayDateMax", e2.context.enableDates[e2.context.enableDates.length - 1])), setContext(e2, "dateMin", e2.displayDisabledDates ? l : e2.context.displayDateMin), setContext(e2, "dateMax", e2.displayDisabledDates ? o : e2.context.displayDateMax);
};
initSelectedDates = (e2) => {
var t;
setContext(e2, "selectedDates", (null == (t = e2.selectedDates) ? void 0 : t[0]) ? parseDates(e2.selectedDates) : []);
};
displayClosestValidDate = (e2) => {
const t = (t2) => {
const n2 = new Date(t2);
setInitialContext(e2, n2.getMonth(), n2.getFullYear());
};
if (e2.displayDateMin && "today" !== e2.displayDateMin && (n = e2.displayDateMin, a = /* @__PURE__ */ new Date(), new Date(n).getTime() > a.getTime())) {
const n2 = e2.selectedDates.length && e2.selectedDates[0] ? parseDates(e2.selectedDates)[0] : e2.displayDateMin;
return t(getDate(resolveDate(n2, e2.displayDateMin))), true;
}
var n, a;
if (e2.displayDateMax && "today" !== e2.displayDateMax && ((e3, t2) => new Date(e3).getTime() < t2.getTime())(e2.displayDateMax, /* @__PURE__ */ new Date())) {
const n2 = e2.selectedDates.length && e2.selectedDates[0] ? parseDates(e2.selectedDates)[0] : e2.displayDateMax;
return t(getDate(resolveDate(n2, e2.displayDateMax))), true;
}
return false;
};
setInitialContext = (e2, t, n) => {
setContext(e2, "selectedMonth", t), setContext(e2, "selectedYear", n), setContext(e2, "displayYear", n);
};
initSelectedMonthYear = (e2) => {
var t;
if (e2.enableJumpToSelectedDate && (null == (t = e2.selectedDates) ? void 0 : t[0]) && void 0 === e2.selectedMonth && void 0 === e2.selectedYear) {
const t2 = getDate(parseDates(e2.selectedDates)[0]);
return void setInitialContext(e2, t2.getMonth(), t2.getFullYear());
}
if (displayClosestValidDate(e2)) return;
const n = void 0 !== e2.selectedMonth && Number(e2.selectedMonth) >= 0 && Number(e2.selectedMonth) < 12, a = void 0 !== e2.selectedYear && Number(e2.selectedYear) >= 0 && Number(e2.selectedYear) <= 9999;
setInitialContext(e2, n ? Number(e2.selectedMonth) : getDate(e2.context.dateToday).getMonth(), a ? Number(e2.selectedYear) : getDate(e2.context.dateToday).getFullYear());
};
initTime = (e2) => {
var t, n, a;
if (!e2.selectionTimeMode) return;
if (![12, 24].includes(e2.selectionTimeMode)) throw new Error(errorMessages.incorrectTime);
const l = 12 === e2.selectionTimeMode, o = l ? /^(0[1-9]|1[0-2]):([0-5][0-9]) ?(AM|PM)?$/i : /^([0-1]?[0-9]|2[0-3]):([0-5][0-9])$/;
let [s, i, r] = null != (a = null == (n = null == (t = e2.selectedTime) ? void 0 : t.match(o)) ? void 0 : n.slice(1)) ? a : [];
s ? l && !r && (r = "AM") : (s = l ? transformTime12(String(e2.timeMinHour)) : String(e2.timeMinHour), i = String(e2.timeMinMinute), r = l ? Number(transformTime12(String(e2.timeMinHour))) >= 12 ? "PM" : "AM" : null), setContext(e2, "selectedHours", s.padStart(2, "0")), setContext(e2, "selectedMinutes", i.padStart(2, "0")), setContext(e2, "selectedKeeping", r), setContext(e2, "selectedTime", `${e2.context.selectedHours}:${e2.context.selectedMinutes}${r ? ` ${r}` : ""}`);
};
initAllVariables = (e2) => {
setContext(e2, "currentType", e2.type), initMonthsCount(e2), initRange(e2), initSelectedMonthYear(e2), initSelectedDates(e2), initTime(e2);
};
reset = (e2, { year: t, month: n, dates: a, time: l, locale: o }, s = true) => {
var i;
const r = { year: e2.selectedYear, month: e2.selectedMonth, dates: e2.selectedDates, time: e2.selectedTime };
if (e2.selectedYear = t ? r.year : e2.context.selectedYear, e2.selectedMonth = n ? r.month : e2.context.selectedMonth, e2.selectedTime = l ? r.time : e2.context.selectedTime, e2.selectedDates = "only-first" === a && (null == (i = e2.context.selectedDates) ? void 0 : i[0]) ? [e2.context.selectedDates[0]] : true === a ? r.dates : e2.context.selectedDates, o) {
setContext(e2, "locale", { months: { short: [], long: [] }, weekdays: { short: [], long: [] } });
}
initAllVariables(e2), s && create(e2), e2.selectedYear = r.year, e2.selectedMonth = r.month, e2.selectedDates = r.dates, e2.selectedTime = r.time, "multiple-ranged" === e2.selectionDatesMode && a && handleSelectDateRange(e2, null);
};
createToInput = (e2) => {
const t = document.createElement("div");
return t.className = e2.styles.calendar, t.dataset.vc = "calendar", t.dataset.vcInput = "", t.dataset.vcCalendarHidden = "", setContext(e2, "inputModeInit", true), setContext(e2, "isShowInInputMode", false), setContext(e2, "mainElement", t), document.body.appendChild(e2.context.mainElement), reset(e2, { year: true, month: true, dates: true, time: true, locale: true }), setTimeout(() => show(e2)), e2.onInit && e2.onInit(e2), handleArrowKeys(e2), handleClick(e2);
};
handleInput = (e2) => {
setContext(e2, "inputElement", e2.context.mainElement);
const t = () => {
e2.context.inputModeInit ? setTimeout(() => show(e2)) : createToInput(e2);
};
return e2.context.inputElement.addEventListener("click", t), e2.context.inputElement.addEventListener("focus", t), () => {
e2.context.inputElement.removeEventListener("click", t), e2.context.inputElement.removeEventListener("focus", t);
};
};
init = (e2) => (setContext(e2, "originalElement", e2.context.mainElement.cloneNode(true)), setContext(e2, "isInit", true), e2.inputMode ? handleInput(e2) : (initAllVariables(e2), create(e2), e2.onInit && e2.onInit(e2), handleArrowKeys(e2), handleClick(e2)));
update = (e2, t) => {
if (!e2.context.isInit) throw new Error(errorMessages.notInit);
reset(e2, __spreadValues(__spreadValues({}, { year: true, month: true, dates: true, time: true, locale: true }), t), !(e2.inputMode && !e2.context.inputModeInit)), e2.onUpdate && e2.onUpdate(e2);
};
replaceProperties = (e2, t) => {
const n = Object.keys(t);
for (let a = 0; a < n.length; a++) {
const l = n[a];
"object" != typeof e2[l] || "object" != typeof t[l] || t[l] instanceof Date || Array.isArray(t[l]) ? void 0 !== t[l] && (e2[l] = t[l]) : replaceProperties(e2[l], t[l]);
}
};
set = (e2, t, n) => {
replaceProperties(e2, t), e2.context.isInit && update(e2, n);
};
setPosition = (e2, t, n) => {
if (!e2) return;
const a = "auto" === n ? findBestPickerPosition(e2, t) : n, l = { top: -t.offsetHeight, bottom: e2.offsetHeight, left: 0, center: e2.offsetWidth / 2 - t.offsetWidth / 2, right: e2.offsetWidth - t.offsetWidth }, o = Array.isArray(a) ? a[0] : "bottom", s = Array.isArray(a) ? a[1] : a;
t.dataset.vcPosition = o;
const { top: i, left: r } = getOffset(e2), c = i + l[o];
let d = r + l[s];
const { vw: u } = getViewportDimensions();
if (d + t.clientWidth > u) {
const e3 = window.innerWidth - document.body.clientWidth;
d = u - t.clientWidth - e3;
} else d < 0 && (d = 0);
Object.assign(t.style, { left: `${d}px`, top: `${c}px` });
};
show = (e2) => {
if (e2.context.isShowInInputMode) return;
if (!e2.context.currentType) return void e2.context.mainElement.click();
setContext(e2, "cleanupHandlers", []), setContext(e2, "isShowInInputMode", true), setPosition(e2.context.inputElement, e2.context.mainElement, e2.positionToInput), e2.context.mainElement.removeAttribute("data-vc-calendar-hidden");
const t = () => {
setPosition(e2.context.inputElement, e2.context.mainElement, e2.positionToInput);
};
window.addEventListener("resize", t), e2.context.cleanupHandlers.push(() => window.removeEventListener("resize", t));
const n = (t2) => {
"Escape" === t2.key && hide2(e2);
};
document.addEventListener("keydown", n), e2.context.cleanupHandlers.push(() => document.removeEventListener("keydown", n));
const a = (t2) => {
t2.target === e2.context.inputElement || e2.context.mainElement.contains(t2.target) || hide2(e2);
};
document.addEventListener("click", a, { capture: true }), e2.context.cleanupHandlers.push(() => document.removeEventListener("click", a, { capture: true })), e2.onShow && e2.onShow(e2);
};
labels = { application: "Calendar", navigation: "Calendar Navigation", arrowNext: { month: "Next month", year: "Next list of years" }, arrowPrev: { month: "Previous month", year: "Previous list of years" }, month: "Select month, current selected month:", months: "List of months", year: "Select year, current selected year:", years: "List of years", week: "Days of the week", weekNumber: "Numbers of weeks in a year", dates: "Dates in the current month", selectingTime: "Selecting a time ", inputHour: "Hours", inputMinute: "Minutes", rangeHour: "Slider for selecting hours", rangeMinute: "Slider for selecting minutes", btnKeeping: "Switch AM/PM, current position:" };
styles = { calendar: "vc", controls: "vc-controls", grid: "vc-grid", column: "vc-column", header: "vc-header", headerContent: "vc-header__content", month: "vc-month", year: "vc-year", arrowPrev: "vc-arrow vc-arrow_prev", arrowNext: "vc-arrow vc-arrow_next", wrapper: "vc-wrapper", content: "vc-content", months: "vc-months", monthsMonth: "vc-months__month", years: "vc-years", yearsYear: "vc-years__year", week: "vc-week", weekDay: "vc-week__day", weekNumbers: "vc-week-numbers", weekNumbersTitle: "vc-week-numbers__title", weekNumbersContent: "vc-week-numbers__content", weekNumber: "vc-week-number", dates: "vc-dates", date: "vc-date", dateBtn: "vc-date__btn", datePopup: "vc-date__popup", dateRangeTooltip: "vc-date-range-tooltip", time: "vc-time", timeContent: "vc-time__content", timeHour: "vc-time__hour", timeMinute: "vc-time__minute", timeKeeping: "vc-time__keeping", timeRanges: "vc-time__ranges", timeRange: "vc-time__range" };
OptionsCalendar = class {
constructor() {
__publicField(this, "type", "default"), __publicField(this, "inputMode", false), __publicField(this, "positionToInput", "left"), __publicField(this, "firstWeekday", 1), __publicField(this, "monthsToSwitch", 1), __publicField(this, "themeAttrDetect", "html[data-theme]"), __publicField(this, "locale", "en"), __publicField(this, "dateToday", "today"), __publicField(this, "dateMin", "1970-01-01"), __publicField(this, "dateMax", "2470-12-31"), __publicField(this, "displayDateMin"), __publicField(this, "displayDateMax"), __publicField(this, "displayDatesOutside", true), __publicField(this, "displayDisabledDates", false), __publicField(this, "displayMonthsCount"), __publicField(this, "disableDates", []), __publicField(this, "disableAllDates", false), __publicField(this, "disableDatesPast", false), __publicField(this, "disableDatesGaps", false), __publicField(this, "disableWeekdays", []), __publicField(this, "disableToday", false), __publicField(this, "enableDates", []), __publicField(this, "enableEdgeDatesOnly", true), __publicField(this, "enableDateToggle", true), __publicField(this, "enableWeekNumbers", false), __publicField(this, "enableMonthChangeOnDayClick", true), __publicField(this, "enableJumpToSelectedDate", false), __publicField(this, "selectionDatesMode", "single"), __publicField(this, "selectionMonthsMode", true), __publicField(this, "selectionYearsMode", true), __publicField(this, "selectionTimeMode", false), __publicField(this, "selectedDates", []), __publicField(this, "selectedMonth"), __publicField(this, "selectedYear"), __publicField(this, "selectedHolidays", []), __publicField(this, "selectedWeekends", [0, 6]), __publicField(this, "selectedTime"), __publicField(this, "selectedTheme", "system"), __publicField(this, "timeMinHour", 0), __publicField(this, "timeMaxHour", 23), __publicField(this, "timeMinMinute", 0), __publicField(this, "timeMaxMinute", 59), __publicField(this, "timeControls", "all"), __publicField(this, "timeStepHour", 1), __publicField(this, "timeStepMinute", 1), __publicField(this, "sanitizerHTML", (e2) => e2), __publicField(this, "onClickDate"), __publicField(this, "onClickWeekDay"), __publicField(this, "onClickWeekNumber"), __publicField(this, "onClickTitle"), __publicField(this, "onClickMonth"), __publicField(this, "onClickYear"), __publicField(this, "onClickArrow"), __publicField(this, "onChangeTime"), __publicField(this, "onChangeToInput"), __publicField(this, "onCreateDateRangeTooltip"), __publicField(this, "onCreateDateEls"), __publicField(this, "onCreateMonthEls"), __publicField(this, "onCreateYearEls"), __publicField(this, "onInit"), __publicField(this, "onUpdate"), __publicField(this, "onDestroy"), __publicField(this, "onShow"), __publicField(this, "onHide"), __publicField(this, "popups", {}), __publicField(this, "labels", __spreadValues({}, labels)), __publicField(this, "layouts", { default: "", multiple: "", month: "", year: "" }), __publicField(this, "styles", __spreadValues({}, styles));
}
};
_Calendar = class e extends OptionsCalendar {
constructor(t, n) {
var a;
super(), __publicField(this, "init", () => init(this)), __publicField(this, "update", (e2) => update(this, e2)), __publicField(this, "destroy", () => destroy(this)), __publicField(this, "show", () => show(this)), __publicField(this, "hide", () => hide2(this)), __publicField(this, "set", (e2, t2) => set(this, e2, t2)), __publicField(this, "context"), this.context = __spreadProps(__spreadValues({}, this.context), { locale: { months: { short: [], long: [] }, weekdays: { short: [], long: [] } } }), setContext(this, "mainElement", "string" == typeof t ? null != (a = e.memoizedElements.get(t)) ? a : this.queryAndMemoize(t) : t), n && replaceProperties(this, n);
}
queryAndMemoize(t) {
const n = document.querySelector(t);
if (!n) throw new Error(errorMessages.notFoundSelector(t));
return e.memoizedElements.set(t, n), n;
}
};
__publicField(_Calendar, "memoizedElements", /* @__PURE__ */ new Map());
Calendar = _Calendar;
}
});
// node_modules/preline/src/plugins/datepicker/vanilla-datepicker-pro.ts
var CustomVanillaCalendar, vanilla_datepicker_pro_default;
var init_vanilla_datepicker_pro = __esm({
"node_modules/preline/src/plugins/datepicker/vanilla-datepicker-pro.ts"() {
init_vanilla_calendar_pro();
CustomVanillaCalendar = class extends Calendar {
constructor(selector, options) {
super(selector, options);
const parentSet = this.set;
this.set = (options2, resetOptions) => {
if (parentSet) parentSet.call(this, options2, resetOptions);
if (options2.selectedTime && this.onChangeTime) {
this.onChangeTime(this, null, true);
}
if (options2.selectedMonth && this.onClickMonth) {
this.onClickMonth(this, null);
}
if (options2.selectedYear && this.onClickYear) {
this.onClickYear(this, null);
}
};
}
static get defaultStyles() {
return {
calendar: "vc",
controls: "vc-controls",
grid: "vc-grid",
column: "vc-column",
header: "vc-header",
headerContent: "vc-header__content",
month: "vc-month",
year: "vc-year",
arrowPrev: "vc-arrow vc-arrow_prev",
arrowNext: "vc-arrow vc-arrow_next",
wrapper: "vc-wrapper",
content: "vc-content",
months: "vc-months",
monthsMonth: "vc-months__month",
years: "vc-years",
yearsYear: "vc-years__year",
week: "vc-week",
weekDay: "vc-week__day",
weekNumbers: "vc-week-numbers",
weekNumbersTitle: "vc-week-numbers__title",
weekNumbersContent: "vc-week-numbers__content",
weekNumber: "vc-week-number",
dates: "vc-dates",
date: "vc-date",
dateBtn: "vc-date__btn",
datePopup: "vc-date__popup",
dateRangeTooltip: "vc-date-range-tooltip",
time: "vc-time",
timeContent: "vc-time__content",
timeHour: "vc-time__hour",
timeMinute: "vc-time__minute",
timeKeeping: "vc-time__keeping",
timeRanges: "vc-time__ranges",
timeRange: "vc-time__range"
};
}
logInfo() {
console.log("This log is from CustomVanillaCalendar!", this);
}
};
vanilla_datepicker_pro_default = CustomVanillaCalendar;
}
});
// node_modules/preline/src/plugins/datepicker/templates.ts
var templates;
var init_templates = __esm({
"node_modules/preline/src/plugins/datepicker/templates.ts"() {
templates = {
default: (theme = false) => `
<#CustomArrowPrev />
<#CustomMonth />
/
<#CustomYear />
<#CustomArrowNext />
`,
multiple: (theme = false) => `
<#CustomArrowPrev />
<#CustomArrowNext />
<#Multiple>
<#CustomMonth />
/
<#CustomYear />
<#/Multiple>
`,
year: (theme = false) => `
<#CustomArrowPrev />
<#Month />
/
<#Year />
<#CustomArrowNext />
`,
month: (theme = false) => `
`,
// Custom
years: (options, theme = false) => {
return `
${options}
`;
},
months: (theme = false) => `
January
February
March
April
May
June
July
August
September
October
November
December
`,
hours: (theme = false) => `
01
02
03
04
05
06
07
08
09
10
11
12
`,
minutes: (theme = false) => `
00
01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
`,
meridiem: (theme = false) => ``
};
}
});
// node_modules/preline/src/plugins/datepicker/locale.ts
var todayTranslations;
var init_locale = __esm({
"node_modules/preline/src/plugins/datepicker/locale.ts"() {
todayTranslations = {
"ru-RU": "\u0441\u0435\u0433\u043E\u0434\u043D\u044F",
"ru": "\u0441\u0435\u0433\u043E\u0434\u043D\u044F",
"de-DE": "Heute",
"de": "Heute",
"fr-FR": "Aujourd'hui",
"fr": "Aujourd'hui",
"es-ES": "Hoy",
"es": "Hoy",
"it-IT": "Oggi",
"it": "Oggi",
"pt-BR": "Hoje",
"pt": "Hoje",
"pl-PL": "Dzisiaj",
"pl": "Dzisiaj",
"uk-UA": "\u0421\u044C\u043E\u0433\u043E\u0434\u043D\u0456",
"uk": "\u0421\u044C\u043E\u0433\u043E\u0434\u043D\u0456",
"zh-CN": "\u4ECA\u5929",
"zh": "\u4ECA\u5929",
"ja-JP": "\u4ECA\u65E5",
"ja": "\u4ECA\u65E5",
"ko-KR": "\uC624\uB298",
"ko": "\uC624\uB298",
"ar-SA": "\u0627\u0644\u064A\u0648\u0645",
"ar": "\u0627\u0644\u064A\u0648\u0645",
"hi-IN": "\u0906\u091C",
"hi": "\u0906\u091C",
"tr-TR": "Bug\xFCn",
"tr": "Bug\xFCn",
"nl-NL": "Vandaag",
"nl": "Vandaag",
"sv-SE": "Idag",
"sv": "Idag",
"da-DK": "I dag",
"da": "I dag",
"no-NO": "I dag",
"no": "I dag",
"fi-FI": "T\xE4n\xE4\xE4n",
"fi": "T\xE4n\xE4\xE4n",
"cs-CZ": "Dnes",
"cs": "Dnes",
"sk-SK": "Dnes",
"sk": "Dnes",
"hu-HU": "Ma",
"hu": "Ma",
"ro-RO": "Ast\u0103zi",
"ro": "Ast\u0103zi",
"bg-BG": "\u0414\u043D\u0435\u0441",
"bg": "\u0414\u043D\u0435\u0441",
"hr-HR": "Danas",
"hr": "Danas",
"sr-RS": "\u0414\u0430\u043D\u0430\u0441",
"sr": "\u0414\u0430\u043D\u0430\u0441",
"sl-SI": "Danes",
"sl": "Danes",
"et-EE": "T\xE4na",
"et": "T\xE4na",
"lv-LV": "\u0160odien",
"lv": "\u0160odien",
"lt-LT": "\u0160iandien",
"lt": "\u0160iandien",
"el-GR": "\u03A3\u03AE\u03BC\u03B5\u03C1\u03B1",
"el": "\u03A3\u03AE\u03BC\u03B5\u03C1\u03B1",
"he-IL": "\u05D4\u05D9\u05D5\u05DD",
"he": "\u05D4\u05D9\u05D5\u05DD",
"th-TH": "\u0E27\u0E31\u0E19\u0E19\u0E35\u0E49",
"th": "\u0E27\u0E31\u0E19\u0E19\u0E35\u0E49",
"vi-VN": "H\xF4m nay",
"vi": "H\xF4m nay",
"id-ID": "Hari ini",
"id": "Hari ini",
"ms-MY": "Hari ini",
"ms": "Hari ini",
"fa-IR": "\u0627\u0645\u0631\u0648\u0632",
"fa": "\u0627\u0645\u0631\u0648\u0632",
"ur-PK": "\u0622\u062C",
"ur": "\u0622\u062C",
"bn-BD": "\u0986\u099C",
"bn": "\u0986\u099C",
"ta-IN": "\u0B87\u0BA9\u0BCD\u0BB1\u0BC1",
"ta": "\u0B87\u0BA9\u0BCD\u0BB1\u0BC1",
"te-IN": "\u0C28\u0C47\u0C21\u0C41",
"te": "\u0C28\u0C47\u0C21\u0C41",
"ml-IN": "\u0D07\u0D28\u0D4D\u0D28\u0D4D",
"ml": "\u0D07\u0D28\u0D4D\u0D28\u0D4D",
"kn-IN": "\u0C87\u0C82\u0CA6\u0CC1",
"kn": "\u0C87\u0C82\u0CA6\u0CC1",
"gu-IN": "\u0A86\u0A9C\u0AC7",
"gu": "\u0A86\u0A9C\u0AC7",
"pa-IN": "\u0A05\u0A71\u0A1C",
"pa": "\u0A05\u0A71\u0A1C",
"or-IN": "\u0B06\u0B1C\u0B3F",
"or": "\u0B06\u0B1C\u0B3F",
"as-IN": "\u0986\u099C\u09BF",
"as": "\u0986\u099C\u09BF",
"ne-NP": "\u0906\u091C",
"ne": "\u0906\u091C",
"si-LK": "\u0D85\u0DAF",
"si": "\u0D85\u0DAF",
"my-MM": "\u101A\u1014\u1031\u1037",
"my": "\u101A\u1014\u1031\u1037",
"km-KH": "\u1790\u17D2\u1784\u17C3\u1793\u17C1\u17C7",
"km": "\u1790\u17D2\u1784\u17C3\u1793\u17C1\u17C7",
"lo-LA": "\u0EA1\u0EB7\u0EC9\u0E99\u0EB5\u0EC9",
"lo": "\u0EA1\u0EB7\u0EC9\u0E99\u0EB5\u0EC9",
"mn-MN": "\u04E8\u043D\u04E9\u04E9\u0434\u04E9\u0440",
"mn": "\u04E8\u043D\u04E9\u04E9\u0434\u04E9\u0440",
"ka-GE": "\u10D3\u10E6\u10D4\u10E1",
"ka": "\u10D3\u10E6\u10D4\u10E1",
"hy-AM": "\u0531\u0575\u057D\u0585\u0580",
"hy": "\u0531\u0575\u057D\u0585\u0580",
"az-AZ": "Bu g\xFCn",
"az": "Bu g\xFCn",
"kk-KZ": "\u0411\u04AF\u0433\u0456\u043D",
"kk": "\u0411\u04AF\u0433\u0456\u043D",
"ky-KG": "\u0411\u04AF\u0433\u04AF\u043D",
"ky": "\u0411\u04AF\u0433\u04AF\u043D",
"uz-UZ": "Bugun",
"uz": "Bugun",
"tg-TJ": "\u0418\u043C\u0440\u04EF\u0437",
"tg": "\u0418\u043C\u0440\u04EF\u0437",
"ps-AF": "\u0646\u0646",
"ps": "\u0646\u0646",
"ku-IQ": "\u0626\u06D5\u0645\u0695\u06C6",
"ku": "\u0626\u06D5\u0645\u0695\u06C6",
"yi-IL": "\u05D4\u05D9\u05D9\u05E0\u05D8",
"yi": "\u05D4\u05D9\u05D9\u05E0\u05D8",
"lb-LU": "Haut",
"lb": "Haut",
"is-IS": "\xCD dag",
"is": "\xCD dag",
"mt-MT": "Illum",
"mt": "Illum",
"cy-GB": "Heddiw",
"cy": "Heddiw",
"ga-IE": "Inniu",
"ga": "Inniu",
"gd-GB": "An-diugh",
"gd": "An-diugh",
"kw-GB": "Hedhyw",
"kw": "Hedhyw",
"br-FR": "Hiziv",
"br": "Hiziv",
"oc-FR": "U\xE8i",
"oc": "U\xE8i",
"ca-ES": "Avui",
"ca": "Avui",
"eu-ES": "Gaur",
"eu": "Gaur",
"gl-ES": "Hoxe",
"gl": "Hoxe",
"ast-ES": "G\xFCei",
"ast": "G\xFCei",
"an-ES": "Hue",
"an": "Hue",
"fur-IT": "Vu\xEA",
"fur": "Vu\xEA",
"lij-IT": "Ancheu",
"lij": "Ancheu",
"pms-IT": "Ancheuj",
"pms": "Ancheuj",
"rm-CH": "Oz",
"rm": "Oz",
"gsw-CH": "H\xFCt",
"gsw": "H\xFCt",
"wae-CH": "H\xFCt",
"wae": "H\xFCt",
"bar-AT": "Heit",
"bar": "Heit",
"ksh-DE": "H\xFCck",
"ksh": "H\xFCck",
"nds-DE": "Vundaag",
"nds": "Vundaag",
"pfl-DE": "Haid",
"pfl": "Haid",
"pdc-US": "Heit",
"pdc": "Heit",
"af-ZA": "Vandag",
"af": "Vandag",
"zu-ZA": "Namhlanje",
"zu": "Namhlanje",
"xh-ZA": "Namhlanje",
"xh": "Namhlanje",
"st-ZA": "Kajeno",
"st": "Kajeno",
"tn-ZA": "Kajeno",
"tn": "Kajeno",
"ve-ZA": "Leno",
"ve": "Leno",
"nso-ZA": "Kajeno",
"nso": "Kajeno",
"ts-ZA": "Namuntlha",
"ts": "Namuntlha",
"ss-ZA": "Lamuhla",
"ss": "Lamuhla",
"nr-ZA": "Namhlanje",
"nr": "Namhlanje",
"ff-SN": "Hannde",
"ff": "Hannde",
"wo-SN": "Tey",
"wo": "Tey",
"ig-NG": "Taa",
"ig": "Taa",
"yo-NG": "L\xF3n\xEC\xED",
"yo": "L\xF3n\xEC\xED",
"ha-NG": "Yau",
"ha": "Yau",
"sw-KE": "Leo",
"sw": "Leo",
"am-ET": "\u12DB\u122C",
"am": "\u12DB\u122C",
"ti-ER": "\u120E\u121A",
"ti": "\u120E\u121A",
"so-SO": "Maanta",
"so": "Maanta",
"om-ET": "Har'a",
"om": "Har'a"
};
}
});
// node_modules/preline/src/plugins/datepicker/index.ts
var datepicker_exports = {};
__export(datepicker_exports, {
default: () => datepicker_default
});
var HSDatepicker, datepicker_default;
var init_datepicker = __esm({
"node_modules/preline/src/plugins/datepicker/index.ts"() {
init_utils();
init_vanilla_datepicker_pro();
init_templates();
init_locale();
init_utils();
init_select();
init_base_plugin();
HSDatepicker = class _HSDatepicker extends HSBasePlugin {
dataOptions;
concatOptions;
updatedStyles;
vanillaCalendar;
constructor(el, options, events) {
super(el, options, events);
const dataOptions = el.getAttribute("data-hs-datepicker") ? JSON.parse(el.getAttribute("data-hs-datepicker")) : {};
this.dataOptions = {
...dataOptions,
...options
};
const removeDefaultStyles = typeof this.dataOptions?.removeDefaultStyles !== "undefined" ? this.dataOptions?.removeDefaultStyles : false;
this.updatedStyles = _.mergeWith(
removeDefaultStyles ? {} : vanilla_datepicker_pro_default.defaultStyles,
this.dataOptions?.styles || {},
(a, b) => {
if (typeof a === "string" && typeof b === "string") {
return `${a} ${b}`;
}
}
);
const today = /* @__PURE__ */ new Date();
const defaults = {
selectedTheme: this.dataOptions.selectedTheme ?? "",
styles: this.updatedStyles,
dateMin: this.dataOptions.dateMin ?? today.toISOString().split("T")[0],
dateMax: this.dataOptions.dateMax ?? "2470-12-31",
mode: this.dataOptions.mode ?? "default",
inputMode: typeof this.dataOptions.inputMode !== "undefined" ? this.dataOptions.inputMode : true
};
const chainCallbacks = (superCallback, customCallback) => (self) => {
superCallback?.(self);
customCallback?.(self);
};
const initTime2 = (self) => {
if (this.hasTime(self)) this.initCustomTime(self);
};
const _options = {
layouts: {
month: templates.month(defaults.selectedTheme)
},
onInit: chainCallbacks(this.dataOptions.onInit, (self) => {
if (defaults.mode === "custom-select" && !this.dataOptions.inputMode) {
initTime2(self);
}
}),
onShow: chainCallbacks(this.dataOptions.onShow, (self) => {
if (defaults.mode === "custom-select") {
this.updateCustomSelects(self);
initTime2(self);
}
}),
onHide: chainCallbacks(this.dataOptions.onHide, (self) => {
if (defaults.mode === "custom-select") {
this.destroySelects(self.context.mainElement);
}
}),
onUpdate: chainCallbacks(this.dataOptions.onUpdate, (self) => {
this.updateCalendar(self.context.mainElement);
}),
onCreateDateEls: chainCallbacks(
this.dataOptions.onCreateDateEls,
(self) => {
if (defaults.mode === "custom-select") this.updateCustomSelects(self);
}
),
onChangeToInput: chainCallbacks(
this.dataOptions.onChangeToInput,
(self) => {
if (!self.context.inputElement) return;
this.setInputValue(
self.context.inputElement,
self.context.selectedDates
);
const data = {
selectedDates: self.context.selectedDates,
selectedTime: self.context.selectedTime,
rest: self.context
};
this.fireEvent("change", data);
dispatch("change.hs.datepicker", this.el, data);
}
),
onChangeTime: chainCallbacks(this.dataOptions.onChangeTime, initTime2),
onClickYear: chainCallbacks(this.dataOptions.onClickYear, initTime2),
onClickMonth: chainCallbacks(this.dataOptions.onClickMonth, initTime2),
onClickArrow: chainCallbacks(this.dataOptions.onClickArrow, (self) => {
if (defaults.mode === "custom-select") {
setTimeout(() => {
this.disableNav();
this.disableOptions();
this.updateCalendar(self.context.mainElement);
});
}
})
};
this.concatOptions = _.merge(_options, this.dataOptions);
const processedOptions = {
...defaults,
layouts: {
default: this.processCustomTemplate(
templates.default(defaults.selectedTheme),
"default"
),
multiple: this.processCustomTemplate(
templates.multiple(defaults.selectedTheme),
"multiple"
),
year: this.processCustomTemplate(
templates.year(defaults.selectedTheme),
"default"
)
}
};
this.concatOptions = _.merge(this.concatOptions, processedOptions);
this.vanillaCalendar = new vanilla_datepicker_pro_default(
this.el,
this.concatOptions
);
this.init();
}
init() {
this.createCollection(window.$hsDatepickerCollection, this);
this.vanillaCalendar.init();
if (this.dataOptions?.selectedDates) {
this.setInputValue(
this.vanillaCalendar.context.inputElement,
this.formatDateArrayToIndividualDates(this.dataOptions?.selectedDates)
);
}
}
getTimeParts(time) {
const [_time, meridiem] = time.split(" ");
const [hours, minutes] = _time.split(":");
return [hours, minutes, meridiem];
}
getCurrentMonthAndYear(el) {
const currentMonthHolder = el.querySelector('[data-vc="month"]');
const currentYearHolder = el.querySelector('[data-vc="year"]');
return {
month: +currentMonthHolder.getAttribute("data-vc-month"),
year: +currentYearHolder.getAttribute("data-vc-year")
};
}
setInputValue(target, dates) {
const dateFormat = this.dataOptions?.dateFormat;
const dateSeparator = this.dataOptions?.inputModeOptions?.dateSeparator ?? ".";
const itemsSeparator = this.dataOptions?.inputModeOptions?.itemsSeparator ?? ", ";
const selectionDatesMode = this.dataOptions?.selectionDatesMode ?? "single";
if (dates.length && dates.length > 1) {
if (selectionDatesMode === "multiple") {
const temp = [];
dates.forEach(
(date) => temp.push(
dateFormat ? this.formatDate(date, dateFormat) : this.changeDateSeparator(date, dateSeparator)
)
);
target.value = temp.join(itemsSeparator);
} else {
const formattedStart = dateFormat ? this.formatDate(dates[0], dateFormat) : this.changeDateSeparator(dates[0], dateSeparator);
const formattedEnd = dateFormat ? this.formatDate(dates[1], dateFormat) : this.changeDateSeparator(dates[1], dateSeparator);
target.value = [formattedStart, formattedEnd].join(itemsSeparator);
}
} else if (dates.length && dates.length === 1) {
target.value = dateFormat ? this.formatDate(dates[0], dateFormat) : this.changeDateSeparator(dates[0], dateSeparator);
} else target.value = "";
}
getLocalizedTodayText(locale) {
return todayTranslations[locale] || "Today";
}
changeDateSeparator(date, separator = ".", defaultSeparator = "-") {
const dateObj = new Date(date);
if (this.dataOptions?.replaceTodayWithText) {
const today = /* @__PURE__ */ new Date();
const isToday = dateObj.toDateString() === today.toDateString();
if (isToday) {
const dateLocale = this.dataOptions?.dateLocale;
return this.getLocalizedTodayText(dateLocale);
}
}
const newDate = date.split(defaultSeparator);
return newDate.join(separator);
}
formatDateArrayToIndividualDates(dates) {
const selectionDatesMode = this.dataOptions?.selectionDatesMode ?? "single";
const expandDateRange = (start, end) => {
const startDate = new Date(start);
const endDate = new Date(end);
const result = [];
while (startDate <= endDate) {
result.push(startDate.toISOString().split("T")[0]);
startDate.setDate(startDate.getDate() + 1);
}
return result;
};
const formatDate = (date) => {
if (typeof date === "string") {
if (date.toLowerCase() === "today") {
const today = /* @__PURE__ */ new Date();
return [today.toISOString().split("T")[0]];
}
const rangeMatch = date.match(
/^(\d{4}-\d{2}-\d{2})\s*[^a-zA-Z0-9]*\s*(\d{4}-\d{2}-\d{2})$/
);
if (rangeMatch) {
const [_2, start, end] = rangeMatch;
return selectionDatesMode === "multiple-ranged" ? [start, end] : expandDateRange(start.trim(), end.trim());
}
return [date];
} else if (typeof date === "number") {
return [new Date(date).toISOString().split("T")[0]];
} else if (date instanceof Date) {
return [date.toISOString().split("T")[0]];
}
return [];
};
return dates.flatMap(formatDate);
}
hasTime(el) {
const { mainElement } = el.context;
const hours = mainElement.querySelector(
"[data-hs-select].--hours"
);
const minutes = mainElement.querySelector(
"[data-hs-select].--minutes"
);
const meridiem = mainElement.querySelector(
"[data-hs-select].--meridiem"
);
return hours && minutes && meridiem;
}
createArrowFromTemplate(template, classes = false) {
if (!classes) return template;
const temp = htmlToElement(template);
classToClassList(classes, temp);
return temp.outerHTML;
}
concatObjectProperties(shared, other) {
const result = {};
const allKeys = /* @__PURE__ */ new Set([
...Object.keys(shared || {}),
...Object.keys(other || {})
]);
allKeys.forEach((key) => {
const sharedValue = shared[key] || "";
const otherValue = other[key] || "";
result[key] = `${sharedValue} ${otherValue}`.trim();
});
return result;
}
updateTemplate(template, shared, specific) {
if (!shared) return template;
const defaultOptions = JSON.parse(
template.match(/data-hs-select='([^']+)'/)[1]
);
const concatOptions = this.concatObjectProperties(shared, specific);
const mergedOptions = _.merge(defaultOptions, concatOptions);
const updatedTemplate = template.replace(
/data-hs-select='[^']+'/,
`data-hs-select='${JSON.stringify(mergedOptions)}'`
);
return updatedTemplate;
}
initCustomTime(self) {
const { mainElement } = self.context;
const timeParts = this.getTimeParts(self.selectedTime ?? "12:00 PM");
const selectors = {
hours: mainElement.querySelector(
"[data-hs-select].--hours"
),
minutes: mainElement.querySelector(
"[data-hs-select].--minutes"
),
meridiem: mainElement.querySelector(
"[data-hs-select].--meridiem"
)
};
Object.entries(selectors).forEach(([key, element]) => {
if (!select_default.getInstance(element, true)) {
const instance = new select_default(element);
instance.setValue(
timeParts[key === "meridiem" ? 2 : key === "minutes" ? 1 : 0]
);
instance.el.addEventListener("change.hs.select", (evt) => {
this.destroySelects(mainElement);
const updatedTime = {
hours: key === "hours" ? evt.detail.payload : timeParts[0],
minutes: key === "minutes" ? evt.detail.payload : timeParts[1],
meridiem: key === "meridiem" ? evt.detail.payload : timeParts[2]
};
self.set({
selectedTime: `${updatedTime.hours}:${updatedTime.minutes} ${updatedTime.meridiem}`
}, {
dates: false,
year: false,
month: false
});
});
}
});
}
initCustomMonths(self) {
const { mainElement } = self.context;
const columns = Array.from(mainElement.querySelectorAll(".--single-month"));
if (columns.length) {
columns.forEach((column, idx) => {
const _month = column.querySelector(
"[data-hs-select].--month"
);
const isInstanceExists = select_default.getInstance(_month, true);
if (isInstanceExists) return false;
const instance = new select_default(_month);
const { month, year } = this.getCurrentMonthAndYear(column);
instance.setValue(`${month}`);
instance.el.addEventListener("change.hs.select", (evt) => {
this.destroySelects(mainElement);
self.set({
selectedMonth: +evt.detail.payload - idx < 0 ? 11 : +evt.detail.payload - idx,
selectedYear: +evt.detail.payload - idx < 0 ? +year - 1 : year
}, {
dates: false,
time: false
});
});
});
}
}
initCustomYears(self) {
const { mainElement } = self.context;
const columns = Array.from(mainElement.querySelectorAll(".--single-month"));
if (columns.length) {
columns.forEach((column) => {
const _year = column.querySelector(
"[data-hs-select].--year"
);
const isInstanceExists = select_default.getInstance(_year, true);
if (isInstanceExists) return false;
const instance = new select_default(_year);
const { month, year } = this.getCurrentMonthAndYear(column);
instance.setValue(`${year}`);
instance.el.addEventListener("change.hs.select", (evt) => {
const { dateMax, displayMonthsCount } = this.vanillaCalendar.context;
const maxYear = new Date(dateMax).getFullYear();
const maxMonth = new Date(dateMax).getMonth();
this.destroySelects(mainElement);
self.set({
selectedMonth: month > maxMonth - displayMonthsCount && +evt.detail.payload === maxYear ? maxMonth - displayMonthsCount + 1 : month,
selectedYear: evt.detail.payload
}, {
dates: false,
time: false
});
});
});
}
}
generateCustomTimeMarkup() {
const customSelectOptions = this.updatedStyles?.customSelect;
const hours = customSelectOptions ? this.updateTemplate(
templates.hours(this.concatOptions.selectedTheme),
customSelectOptions?.shared || {},
customSelectOptions?.hours || {}
) : templates.hours(this.concatOptions.selectedTheme);
const minutes = customSelectOptions ? this.updateTemplate(
templates.minutes(this.concatOptions.selectedTheme),
customSelectOptions?.shared || {},
customSelectOptions?.minutes || {}
) : templates.minutes(this.concatOptions.selectedTheme);
const meridiem = customSelectOptions ? this.updateTemplate(
templates.meridiem(this.concatOptions.selectedTheme),
customSelectOptions?.shared || {},
customSelectOptions?.meridiem || {}
) : templates.meridiem(this.concatOptions.selectedTheme);
const time = this?.dataOptions?.templates?.time ?? `
${hours}
:
${minutes}
${meridiem}
`;
return `${time}
`;
}
generateCustomMonthMarkup() {
const mode = this?.dataOptions?.mode ?? "default";
const customSelectOptions = this.updatedStyles?.customSelect;
const updatedTemplate = customSelectOptions ? this.updateTemplate(
templates.months(this.concatOptions.selectedTheme),
customSelectOptions?.shared || {},
customSelectOptions?.months || {}
) : templates.months(this.concatOptions.selectedTheme);
const month = mode === "custom-select" ? updatedTemplate : "<#Month />";
return month;
}
generateCustomYearMarkup() {
const mode = this?.dataOptions?.mode ?? "default";
if (mode === "custom-select") {
const today = /* @__PURE__ */ new Date();
const dateMin = this?.dataOptions?.dateMin ?? today.toISOString().split("T")[0];
const tempDateMax = this?.dataOptions?.dateMax ?? "2470-12-31";
const dateMax = tempDateMax;
const startDate = new Date(dateMin);
const endDate = new Date(dateMax);
const startDateYear = startDate.getFullYear();
const endDateYear = endDate.getFullYear();
const generateOptions = () => {
let result = "";
for (let i = startDateYear; i <= endDateYear; i++) {
result += `${i} `;
}
return result;
};
const years = templates.years(
generateOptions(),
this.concatOptions.selectedTheme
);
const customSelectOptions = this.updatedStyles?.customSelect;
const updatedTemplate = customSelectOptions ? this.updateTemplate(
years,
customSelectOptions?.shared || {},
customSelectOptions?.years || {}
) : years;
return updatedTemplate;
} else {
return "<#Year />";
}
}
generateCustomArrowPrevMarkup() {
const arrowPrev = this?.dataOptions?.templates?.arrowPrev ? this.createArrowFromTemplate(
this.dataOptions.templates.arrowPrev,
this.updatedStyles.arrowPrev
) : "<#ArrowPrev [month] />";
return arrowPrev;
}
generateCustomArrowNextMarkup() {
const arrowNext = this?.dataOptions?.templates?.arrowNext ? this.createArrowFromTemplate(
this.dataOptions.templates.arrowNext,
this.updatedStyles.arrowNext
) : "<#ArrowNext [month] />";
return arrowNext;
}
parseCustomTime(template) {
template = template.replace(
/<#CustomTime\s*\/>/g,
this.generateCustomTimeMarkup()
);
return template;
}
parseCustomMonth(template) {
template = template.replace(
/<#CustomMonth\s*\/>/g,
this.generateCustomMonthMarkup()
);
return template;
}
parseCustomYear(template) {
template = template.replace(
/<#CustomYear\s*\/>/g,
this.generateCustomYearMarkup()
);
return template;
}
parseArrowPrev(template) {
template = template.replace(
/<#CustomArrowPrev\s*\/>/g,
this.generateCustomArrowPrevMarkup()
);
return template;
}
parseArrowNext(template) {
template = template.replace(
/<#CustomArrowNext\s*\/>/g,
this.generateCustomArrowNextMarkup()
);
return template;
}
processCustomTemplate(template, type) {
const templateAccordingToType = type === "default" ? this?.dataOptions?.layouts?.default : this?.dataOptions?.layouts?.multiple;
const processedCustomMonth = this.parseCustomMonth(
templateAccordingToType ?? template
);
const processedCustomYear = this.parseCustomYear(processedCustomMonth);
const processedCustomTime = this.parseCustomTime(processedCustomYear);
const processedCustomArrowPrev = this.parseArrowPrev(processedCustomTime);
const processedCustomTemplate = this.parseArrowNext(
processedCustomArrowPrev
);
return processedCustomTemplate;
}
disableOptions() {
const { mainElement, dateMax, displayMonthsCount } = this.vanillaCalendar.context;
const maxDate = new Date(dateMax);
const columns = Array.from(mainElement.querySelectorAll(".--single-month"));
columns.forEach((column, idx) => {
const year = +column.querySelector('[data-vc="year"]')?.getAttribute(
"data-vc-year"
);
const monthOptions = column.querySelectorAll(
"[data-hs-select].--month option"
);
const pseudoOptions = column.querySelectorAll(
"[data-hs-select-dropdown] [data-value]"
);
const isDisabled = (option) => {
const value = +option.getAttribute("data-value");
return value > maxDate.getMonth() - displayMonthsCount + idx + 1 && year === maxDate.getFullYear();
};
Array.from(monthOptions).forEach(
(option) => option.toggleAttribute("disabled", isDisabled(option))
);
Array.from(pseudoOptions).forEach(
(option) => option.classList.toggle("disabled", isDisabled(option))
);
});
}
disableNav() {
const {
mainElement,
dateMax,
selectedYear,
selectedMonth,
displayMonthsCount
} = this.vanillaCalendar.context;
const maxYear = new Date(dateMax).getFullYear();
const next = mainElement.querySelector(
'[data-vc-arrow="next"]'
);
if (selectedYear === maxYear && selectedMonth + displayMonthsCount > 11) {
next.style.visibility = "hidden";
} else next.style.visibility = "";
}
destroySelects(container) {
const selects = Array.from(container.querySelectorAll("[data-hs-select]"));
selects.forEach((select) => {
const instance = select_default.getInstance(select, true);
if (instance) instance.element.destroy();
});
}
updateSelect(el, value) {
const instance = select_default.getInstance(el, true);
if (instance) instance.element.setValue(value);
}
updateCalendar(calendar) {
const columns = calendar.querySelectorAll(".--single-month");
if (columns.length) {
columns.forEach((column) => {
const { month, year } = this.getCurrentMonthAndYear(column);
this.updateSelect(
column.querySelector("[data-hs-select].--month"),
`${month}`
);
this.updateSelect(
column.querySelector("[data-hs-select].--year"),
`${year}`
);
});
}
}
updateCustomSelects(el) {
setTimeout(() => {
this.disableOptions();
this.disableNav();
this.initCustomMonths(el);
this.initCustomYears(el);
});
}
// Public methods
getCurrentState() {
return {
selectedDates: this.vanillaCalendar.selectedDates,
selectedTime: this.vanillaCalendar.selectedTime
};
}
formatDate(date, format) {
const dateFormat = format || this.dataOptions?.dateFormat;
const dateLocale = this.dataOptions?.dateLocale || void 0;
if (!dateFormat) {
const dateSeparator = this.dataOptions?.inputModeOptions?.dateSeparator ?? ".";
return this.changeDateSeparator(date, dateSeparator);
}
const dateObj = new Date(date);
if (isNaN(dateObj.getTime())) {
return this.changeDateSeparator(date);
}
let result = "";
let i = 0;
while (i < dateFormat.length) {
if (dateFormat.slice(i, i + 4) === "YYYY") {
result += dateObj.getFullYear().toString();
i += 4;
} else if (dateFormat.slice(i, i + 4) === "dddd") {
const dayName = dateObj.toLocaleDateString(dateLocale, {
weekday: "long"
});
if (this.dataOptions?.replaceTodayWithText) {
const today = /* @__PURE__ */ new Date();
const isToday = dateObj.toDateString() === today.toDateString();
if (isToday) {
result += this.getLocalizedTodayText(dateLocale);
} else {
result += dayName;
}
} else {
result += dayName;
}
i += 4;
} else if (dateFormat.slice(i, i + 4) === "MMMM") {
result += dateObj.toLocaleDateString(dateLocale, { month: "long" });
i += 4;
} else if (dateFormat.slice(i, i + 3) === "ddd") {
const dayName = dateObj.toLocaleDateString(dateLocale, {
weekday: "short"
});
if (this.dataOptions?.replaceTodayWithText) {
const today = /* @__PURE__ */ new Date();
const isToday = dateObj.toDateString() === today.toDateString();
if (isToday) {
result += this.getLocalizedTodayText(dateLocale);
} else {
result += dayName;
}
} else {
result += dayName;
}
i += 3;
} else if (dateFormat.slice(i, i + 3) === "MMM") {
result += dateObj.toLocaleDateString(dateLocale, { month: "short" });
i += 3;
} else if (dateFormat.slice(i, i + 2) === "YY") {
result += dateObj.getFullYear().toString().slice(-2);
i += 2;
} else if (dateFormat.slice(i, i + 2) === "MM") {
result += String(dateObj.getMonth() + 1).padStart(2, "0");
i += 2;
} else if (dateFormat.slice(i, i + 2) === "DD") {
result += String(dateObj.getDate()).padStart(2, "0");
i += 2;
} else if (dateFormat.slice(i, i + 2) === "HH") {
result += String(dateObj.getHours()).padStart(2, "0");
i += 2;
} else if (dateFormat.slice(i, i + 2) === "mm") {
result += String(dateObj.getMinutes()).padStart(2, "0");
i += 2;
} else if (dateFormat.slice(i, i + 2) === "ss") {
result += String(dateObj.getSeconds()).padStart(2, "0");
i += 2;
} else if (dateFormat[i] === "Y") {
result += dateObj.getFullYear().toString();
i += 1;
} else if (dateFormat[i] === "M") {
result += String(dateObj.getMonth() + 1);
i += 1;
} else if (dateFormat[i] === "D") {
result += String(dateObj.getDate());
i += 1;
} else if (dateFormat[i] === "H") {
result += String(dateObj.getHours());
i += 1;
} else if (dateFormat[i] === "m") {
result += String(dateObj.getMinutes());
i += 1;
} else if (dateFormat[i] === "s") {
result += String(dateObj.getSeconds());
i += 1;
} else {
result += dateFormat[i];
i += 1;
}
}
return result;
}
destroy() {
if (this.vanillaCalendar) {
this.vanillaCalendar.destroy();
this.vanillaCalendar = null;
}
window.$hsDatepickerCollection = window.$hsDatepickerCollection.filter(
({ element }) => element.el !== this.el
);
}
// Static methods
static getInstance(target, isInstance) {
const elInCollection = window.$hsDatepickerCollection.find(
(el) => el.element.el === (typeof target === "string" ? document.querySelector(target) : target)
);
return elInCollection ? isInstance ? elInCollection : elInCollection.element.el : null;
}
static autoInit() {
if (!window.$hsDatepickerCollection) window.$hsDatepickerCollection = [];
document.querySelectorAll(".hs-datepicker:not(.--prevent-on-load-init)").forEach((el) => {
if (!window.$hsDatepickerCollection.find(
(elC) => elC?.element?.el === el
)) {
new _HSDatepicker(el);
}
});
}
};
window.addEventListener("load", () => {
HSDatepicker.autoInit();
});
if (typeof window !== "undefined") {
window.HSDatepicker = HSDatepicker;
}
datepicker_default = HSDatepicker;
}
});
// node_modules/preline/src/index.ts
init_accessibility_manager();
// node_modules/preline/src/plugins/copy-markup/index.ts
init_utils();
init_base_plugin();
var HSCopyMarkup = class _HSCopyMarkup extends HSBasePlugin {
targetSelector;
wrapperSelector;
limit;
target;
wrapper;
items;
onElementClickListener;
onDeleteItemButtonClickListener;
constructor(el, options) {
super(el, options);
const data = el.getAttribute("data-hs-copy-markup");
const dataOptions = data ? JSON.parse(data) : {};
const concatOptions = {
...dataOptions,
...options
};
this.targetSelector = concatOptions?.targetSelector || null;
this.wrapperSelector = concatOptions?.wrapperSelector || null;
this.limit = concatOptions?.limit || null;
this.items = [];
if (this.targetSelector) this.init();
}
elementClick() {
this.copy();
}
deleteItemButtonClick(item) {
this.delete(item);
}
init() {
this.createCollection(window.$hsCopyMarkupCollection, this);
this.onElementClickListener = () => this.elementClick();
this.setTarget();
this.setWrapper();
this.addPredefinedItems();
this.el.addEventListener("click", this.onElementClickListener);
}
copy() {
if (this.limit && this.items.length >= this.limit) return false;
if (this.el.hasAttribute("disabled")) this.el.setAttribute("disabled", "");
const copiedElement = this.target.cloneNode(true);
this.addToItems(copiedElement);
if (this.limit && this.items.length >= this.limit) {
this.el.setAttribute("disabled", "disabled");
}
this.fireEvent("copy", copiedElement);
dispatch("copy.hs.copyMarkup", copiedElement, copiedElement);
}
addPredefinedItems() {
Array.from(this.wrapper.children).filter(
(el) => !el.classList.contains("[--ignore-for-count]")
).forEach((el) => {
this.addToItems(el);
});
if (this.limit && this.items.length >= this.limit) {
this.el.setAttribute("disabled", "disabled");
}
}
setTarget() {
const target = typeof this.targetSelector === "string" ? document.querySelector(this.targetSelector).cloneNode(true) : this.targetSelector.cloneNode(true);
target.removeAttribute("id");
this.target = target;
}
setWrapper() {
this.wrapper = typeof this.wrapperSelector === "string" ? document.querySelector(this.wrapperSelector) : this.wrapperSelector;
}
addToItems(item) {
const deleteItemButton = item.querySelector(
"[data-hs-copy-markup-delete-item]"
);
if (this.wrapper) this.wrapper.append(item);
else this.el.before(item);
if (deleteItemButton) {
this.onDeleteItemButtonClickListener = () => this.deleteItemButtonClick(item);
deleteItemButton.addEventListener(
"click",
this.onDeleteItemButtonClickListener
);
}
this.items.push(item);
}
// Public methods
delete(target) {
const index = this.items.indexOf(target);
if (index !== -1) this.items.splice(index, 1);
target.remove();
if (this.limit && this.items.length < this.limit) {
this.el.removeAttribute("disabled");
}
this.fireEvent("delete", target);
dispatch("delete.hs.copyMarkup", target, target);
}
destroy() {
const deleteItemButtons = this.wrapper.querySelectorAll(
"[data-hs-copy-markup-delete-item]"
);
this.el.removeEventListener("click", this.onElementClickListener);
if (deleteItemButtons.length) {
deleteItemButtons.forEach(
(el) => el.removeEventListener("click", this.onDeleteItemButtonClickListener)
);
}
this.el.removeAttribute("disabled");
this.target = null;
this.wrapper = null;
this.items = null;
window.$hsCopyMarkupCollection = window.$hsCopyMarkupCollection.filter(
({ element }) => element.el !== this.el
);
}
// Static method
static getInstance(target, isInstance) {
const elInCollection = window.$hsCopyMarkupCollection.find(
(el) => el.element.el === (typeof target === "string" ? document.querySelector(target) : target)
);
return elInCollection ? isInstance ? elInCollection : elInCollection.element : null;
}
static autoInit() {
if (!window.$hsCopyMarkupCollection) window.$hsCopyMarkupCollection = [];
if (window.$hsCopyMarkupCollection) {
window.$hsCopyMarkupCollection = window.$hsCopyMarkupCollection.filter(
({ element }) => document.contains(element.el)
);
}
document.querySelectorAll("[data-hs-copy-markup]:not(.--prevent-on-load-init)").forEach((el) => {
if (!window.$hsCopyMarkupCollection.find(
(elC) => elC?.element?.el === el
)) {
const data = el.getAttribute("data-hs-copy-markup");
const options = data ? JSON.parse(data) : {};
new _HSCopyMarkup(el, options);
}
});
}
};
window.addEventListener("load", () => {
HSCopyMarkup.autoInit();
});
if (typeof window !== "undefined") {
window.HSCopyMarkup = HSCopyMarkup;
}
var copy_markup_default = HSCopyMarkup;
// node_modules/preline/src/plugins/accordion/index.ts
init_utils();
init_base_plugin();
var HSAccordion = class _HSAccordion extends HSBasePlugin {
toggle;
content;
group;
isAlwaysOpened;
keepOneOpen;
isToggleStopPropagated;
onToggleClickListener;
static selectable;
constructor(el, options, events) {
super(el, options, events);
this.toggle = this.el.querySelector(".hs-accordion-toggle") || null;
this.content = this.el.querySelector(".hs-accordion-content") || null;
this.group = this.el.closest(".hs-accordion-group") || null;
this.update();
this.isToggleStopPropagated = stringToBoolean(
getClassProperty(this.toggle, "--stop-propagation", "false") || "false"
);
this.keepOneOpen = this.group ? stringToBoolean(
getClassProperty(this.group, "--keep-one-open", "false") || "false"
) : false;
if (this.toggle && this.content) this.init();
}
init() {
this.createCollection(window.$hsAccordionCollection, this);
this.onToggleClickListener = (evt) => this.toggleClick(evt);
this.toggle.addEventListener("click", this.onToggleClickListener);
}
// Public methods
toggleClick(evt) {
if (this.el.classList.contains("active") && this.keepOneOpen) return false;
if (this.isToggleStopPropagated) evt.stopPropagation();
if (this.el.classList.contains("active")) {
this.hide();
} else {
this.show();
}
}
show() {
if (this.group && !this.isAlwaysOpened && this.group.querySelector(":scope > .hs-accordion.active") && this.group.querySelector(":scope > .hs-accordion.active") !== this.el) {
const currentlyOpened = window.$hsAccordionCollection.find(
(el) => el.element.el === this.group.querySelector(":scope > .hs-accordion.active")
);
currentlyOpened.element.hide();
}
if (this.el.classList.contains("active")) return false;
this.el.classList.add("active");
if (this?.toggle?.ariaExpanded) this.toggle.ariaExpanded = "true";
this.fireEvent("beforeOpen", this.el);
dispatch("beforeOpen.hs.accordion", this.el, this.el);
this.content.style.display = "block";
this.content.style.height = "0";
setTimeout(() => {
this.content.style.height = `${this.content.scrollHeight}px`;
afterTransition(this.content, () => {
this.content.style.display = "block";
this.content.style.height = "";
this.fireEvent("open", this.el);
dispatch("open.hs.accordion", this.el, this.el);
});
});
}
hide() {
if (!this.el.classList.contains("active")) return false;
this.el.classList.remove("active");
if (this?.toggle?.ariaExpanded) this.toggle.ariaExpanded = "false";
this.fireEvent("beforeClose", this.el);
dispatch("beforeClose.hs.accordion", this.el, this.el);
this.content.style.height = `${this.content.scrollHeight}px`;
setTimeout(() => {
this.content.style.height = "0";
});
afterTransition(this.content, () => {
this.content.style.display = "none";
this.content.style.height = "";
this.fireEvent("close", this.el);
dispatch("close.hs.accordion", this.el, this.el);
});
}
update() {
this.group = this.el.closest(".hs-accordion-group") || null;
if (!this.group) return false;
this.isAlwaysOpened = this.group.hasAttribute("data-hs-accordion-always-open") || false;
window.$hsAccordionCollection.map((el) => {
if (el.id === this.el.id) {
el.element.group = this.group;
el.element.isAlwaysOpened = this.isAlwaysOpened;
}
return el;
});
}
destroy() {
if (_HSAccordion?.selectable?.length) {
_HSAccordion.selectable.forEach((item) => {
item.listeners.forEach(({ el, listener }) => {
el.removeEventListener("click", listener);
});
});
}
if (this.onToggleClickListener) {
this.toggle.removeEventListener("click", this.onToggleClickListener);
}
this.toggle = null;
this.content = null;
this.group = null;
this.onToggleClickListener = null;
window.$hsAccordionCollection = window.$hsAccordionCollection.filter(
({ element }) => element.el !== this.el
);
}
// Static methods
static findInCollection(target) {
return window.$hsAccordionCollection.find((el) => {
if (target instanceof _HSAccordion) return el.element.el === target.el;
else if (typeof target === "string") return el.element.el === document.querySelector(target);
else return el.element.el === target;
}) || null;
}
static autoInit() {
if (!window.$hsAccordionCollection) window.$hsAccordionCollection = [];
if (window.$hsAccordionCollection) {
window.$hsAccordionCollection = window.$hsAccordionCollection.filter(
({ element }) => document.contains(element.el)
);
}
document.querySelectorAll(".hs-accordion:not(.--prevent-on-load-init)").forEach((el) => {
if (!window.$hsAccordionCollection.find(
(elC) => elC?.element?.el === el
))
new _HSAccordion(el);
});
}
static getInstance(target, isInstance) {
const elInCollection = window.$hsAccordionCollection.find(
(el) => el.element.el === (typeof target === "string" ? document.querySelector(target) : target)
);
return elInCollection ? isInstance ? elInCollection : elInCollection.element.el : null;
}
static show(target) {
const instance = _HSAccordion.findInCollection(target);
if (instance && instance.element.content.style.display !== "block") instance.element.show();
}
static hide(target) {
const instance = _HSAccordion.findInCollection(target);
const style = instance ? window.getComputedStyle(instance.element.content) : null;
if (instance && style.display !== "none") instance.element.hide();
}
static onSelectableClick = (evt, item, el) => {
evt.stopPropagation();
_HSAccordion.toggleSelected(item, el);
};
static treeView() {
if (!document.querySelectorAll(".hs-accordion-treeview-root").length)
return false;
this.selectable = [];
document.querySelectorAll(".hs-accordion-treeview-root").forEach((el) => {
const data = el?.getAttribute("data-hs-accordion-options");
const options = data ? JSON.parse(data) : {};
this.selectable.push({
el,
options: { ...options },
listeners: []
});
});
if (this.selectable.length)
this.selectable.forEach((item) => {
const { el } = item;
el.querySelectorAll(".hs-accordion-selectable").forEach(
(_el) => {
const listener = (evt) => this.onSelectableClick(evt, item, _el);
_el.addEventListener("click", listener);
item.listeners.push({ el: _el, listener });
}
);
});
}
static toggleSelected(root, item) {
if (item.classList.contains("selected")) item.classList.remove("selected");
else {
root.el.querySelectorAll(".hs-accordion-selectable").forEach((el) => el.classList.remove("selected"));
item.classList.add("selected");
}
}
// Backward compatibility
static on(evt, target, cb) {
const instance = _HSAccordion.findInCollection(target);
if (instance) instance.element.events[evt] = cb;
}
};
window.addEventListener("load", () => {
HSAccordion.autoInit();
if (document.querySelectorAll(".hs-accordion-treeview-root").length)
HSAccordion.treeView();
});
if (typeof window !== "undefined") {
window.HSAccordion = HSAccordion;
}
var accordion_default = HSAccordion;
// node_modules/preline/src/plugins/carousel/index.ts
init_utils();
init_base_plugin();
init_constants();
var HSCarousel = class _HSCarousel extends HSBasePlugin {
currentIndex;
loadingClasses;
dotsItemClasses;
isAutoHeight;
isAutoPlay;
isCentered;
isDraggable;
isInfiniteLoop;
isRTL;
isSnap;
hasSnapSpacers;
slidesQty;
speed;
updateDelay;
loadingClassesRemove;
loadingClassesAdd;
afterLoadingClassesAdd;
container;
inner;
slides;
prev;
next;
dots;
dotsItems;
info;
infoTotal;
infoCurrent;
sliderWidth;
timer;
// Drag events' help variables
isScrolling;
isDragging;
dragStartX;
initialTranslateX;
// Touch events' help variables
touchX;
touchY;
// Resize events' help variables
resizeContainer;
resizeContainerWidth;
// Listeners
onPrevClickListener;
onNextClickListener;
onContainerScrollListener;
onElementTouchStartListener;
onElementTouchEndListener;
onInnerMouseDownListener;
onInnerTouchStartListener;
onDocumentMouseMoveListener;
onDocumentTouchMoveListener;
onDocumentMouseUpListener;
onDocumentTouchEndListener;
onDotClickListener;
constructor(el, options) {
super(el, options);
const data = el.getAttribute("data-hs-carousel");
const dataOptions = data ? JSON.parse(data) : {};
const concatOptions = {
...dataOptions,
...options
};
this.currentIndex = concatOptions.currentIndex || 0;
this.loadingClasses = concatOptions.loadingClasses ? `${concatOptions.loadingClasses}`.split(",") : null;
this.dotsItemClasses = concatOptions.dotsItemClasses ? concatOptions.dotsItemClasses : null;
this.isAutoHeight = typeof concatOptions.isAutoHeight !== "undefined" ? concatOptions.isAutoHeight : false;
this.isAutoPlay = typeof concatOptions.isAutoPlay !== "undefined" ? concatOptions.isAutoPlay : false;
this.isCentered = typeof concatOptions.isCentered !== "undefined" ? concatOptions.isCentered : false;
this.isDraggable = typeof concatOptions.isDraggable !== "undefined" ? concatOptions.isDraggable : false;
this.isInfiniteLoop = typeof concatOptions.isInfiniteLoop !== "undefined" ? concatOptions.isInfiniteLoop : false;
this.isRTL = typeof concatOptions.isRTL !== "undefined" ? concatOptions.isRTL : false;
this.isSnap = typeof concatOptions.isSnap !== "undefined" ? concatOptions.isSnap : false;
this.hasSnapSpacers = typeof concatOptions.hasSnapSpacers !== "undefined" ? concatOptions.hasSnapSpacers : true;
this.speed = concatOptions.speed || 4e3;
this.updateDelay = concatOptions.updateDelay || 0;
this.slidesQty = concatOptions.slidesQty || 1;
this.loadingClassesRemove = this.loadingClasses?.[0] ? this.loadingClasses[0].split(" ") : "opacity-0";
this.loadingClassesAdd = this.loadingClasses?.[1] ? this.loadingClasses[1].split(" ") : "";
this.afterLoadingClassesAdd = this.loadingClasses?.[2] ? this.loadingClasses[2].split(" ") : "";
this.container = this.el.querySelector(".hs-carousel") || null;
this.inner = this.el.querySelector(".hs-carousel-body") || null;
this.slides = this.el.querySelectorAll(".hs-carousel-slide") || [];
this.prev = this.el.querySelector(".hs-carousel-prev") || null;
this.next = this.el.querySelector(".hs-carousel-next") || null;
this.dots = this.el.querySelector(".hs-carousel-pagination") || null;
this.info = this.el.querySelector(".hs-carousel-info") || null;
this.infoTotal = this?.info?.querySelector(".hs-carousel-info-total") || null;
this.infoCurrent = this?.info?.querySelector(".hs-carousel-info-current") || null;
this.sliderWidth = this.el.getBoundingClientRect().width;
this.isDragging = false;
this.dragStartX = null;
this.initialTranslateX = null;
this.touchX = {
start: 0,
end: 0
};
this.touchY = {
start: 0,
end: 0
};
this.resizeContainer = document.querySelector("body");
this.resizeContainerWidth = 0;
this.init();
}
setIsSnap() {
const containerRect = this.container.getBoundingClientRect();
const containerCenter = containerRect.left + containerRect.width / 2;
let closestElement = null;
let closestElementIndex = null;
let closestDistance = Infinity;
Array.from(this.inner.children).forEach((child) => {
const childRect = child.getBoundingClientRect();
const innerContainerRect = this.inner.getBoundingClientRect();
const childCenter = childRect.left + childRect.width / 2 - innerContainerRect.left;
const distance = Math.abs(
containerCenter - (innerContainerRect.left + childCenter)
);
if (distance < closestDistance) {
closestDistance = distance;
closestElement = child;
}
});
if (closestElement) {
closestElementIndex = Array.from(this.slides).findIndex(
(el) => el === closestElement
);
}
this.setIndex(closestElementIndex);
if (this.dots) this.setCurrentDot();
}
prevClick() {
this.goToPrev();
if (this.isAutoPlay) {
this.resetTimer();
this.setTimer();
}
}
nextClick() {
this.goToNext();
if (this.isAutoPlay) {
this.resetTimer();
this.setTimer();
}
}
containerScroll() {
clearTimeout(this.isScrolling);
this.isScrolling = setTimeout(() => {
this.setIsSnap();
}, 100);
}
elementTouchStart(evt) {
this.touchX.start = evt.changedTouches[0].screenX;
this.touchY.start = evt.changedTouches[0].screenY;
}
elementTouchEnd(evt) {
this.touchX.end = evt.changedTouches[0].screenX;
this.touchY.end = evt.changedTouches[0].screenY;
this.detectDirection();
}
innerMouseDown(evt) {
this.handleDragStart(evt);
}
innerTouchStart(evt) {
this.handleDragStart(evt);
}
documentMouseMove(evt) {
this.handleDragMove(evt);
}
documentTouchMove(evt) {
this.handleDragMove(evt);
}
documentMouseUp() {
this.handleDragEnd();
}
documentTouchEnd() {
this.handleDragEnd();
}
dotClick(ind) {
this.goTo(ind);
if (this.isAutoPlay) {
this.resetTimer();
this.setTimer();
}
}
init() {
this.createCollection(window.$hsCarouselCollection, this);
if (this.inner) {
this.calculateWidth();
if (this.isDraggable && !this.isSnap) this.initDragHandling();
}
if (this.prev) {
this.onPrevClickListener = () => this.prevClick();
this.prev.addEventListener("click", this.onPrevClickListener);
}
if (this.next) {
this.onNextClickListener = () => this.nextClick();
this.next.addEventListener("click", this.onNextClickListener);
}
if (this.dots) this.initDots();
if (this.info) this.buildInfo();
if (this.slides.length) {
this.addCurrentClass();
if (!this.isInfiniteLoop) this.addDisabledClass();
if (this.isAutoPlay) this.autoPlay();
}
setTimeout(() => {
if (this.isSnap) this.setIsSnap();
if (this.loadingClassesRemove) {
if (typeof this.loadingClassesRemove === "string") {
this.inner.classList.remove(this.loadingClassesRemove);
} else this.inner.classList.remove(...this.loadingClassesRemove);
}
if (this.loadingClassesAdd) {
if (typeof this.loadingClassesAdd === "string") {
this.inner.classList.add(this.loadingClassesAdd);
} else this.inner.classList.add(...this.loadingClassesAdd);
}
if (this.inner && this.afterLoadingClassesAdd) {
setTimeout(() => {
if (typeof this.afterLoadingClassesAdd === "string") {
this.inner.classList.add(this.afterLoadingClassesAdd);
} else this.inner.classList.add(...this.afterLoadingClassesAdd);
});
}
}, 400);
if (this.isSnap) {
this.onContainerScrollListener = () => this.containerScroll();
this.container.addEventListener("scroll", this.onContainerScrollListener);
}
this.el.classList.add("init");
if (!this.isSnap) {
this.onElementTouchStartListener = (evt) => this.elementTouchStart(evt);
this.onElementTouchEndListener = (evt) => this.elementTouchEnd(evt);
this.el.addEventListener("touchstart", this.onElementTouchStartListener);
this.el.addEventListener("touchend", this.onElementTouchEndListener);
}
this.observeResize();
}
initDragHandling() {
const scrollableElement = this.inner;
this.onInnerMouseDownListener = (evt) => this.innerMouseDown(evt);
this.onInnerTouchStartListener = (evt) => this.innerTouchStart(evt);
this.onDocumentMouseMoveListener = (evt) => this.documentMouseMove(evt);
this.onDocumentTouchMoveListener = (evt) => this.documentTouchMove(evt);
this.onDocumentMouseUpListener = () => this.documentMouseUp();
this.onDocumentTouchEndListener = () => this.documentTouchEnd();
if (scrollableElement) {
scrollableElement.addEventListener(
"mousedown",
this.onInnerMouseDownListener
);
scrollableElement.addEventListener(
"touchstart",
this.onInnerTouchStartListener,
{ passive: true }
);
document.addEventListener("mousemove", this.onDocumentMouseMoveListener);
document.addEventListener("touchmove", this.onDocumentTouchMoveListener, {
passive: false
});
document.addEventListener("mouseup", this.onDocumentMouseUpListener);
document.addEventListener("touchend", this.onDocumentTouchEndListener);
}
}
getTranslateXValue() {
const transformMatrix = window.getComputedStyle(this.inner).transform;
if (transformMatrix !== "none") {
const matrixValues = transformMatrix.match(/matrix.*\((.+)\)/)?.[1].split(", ");
if (matrixValues) {
let translateX = parseFloat(
matrixValues.length === 6 ? matrixValues[4] : matrixValues[12]
);
if (this.isRTL) translateX = -translateX;
return isNaN(translateX) || translateX === 0 ? 0 : -translateX;
}
}
return 0;
}
removeClickEventWhileDragging(evt) {
evt.preventDefault();
}
handleDragStart(evt) {
evt.preventDefault();
this.isDragging = true;
this.dragStartX = this.getEventX(evt);
this.initialTranslateX = this.isRTL ? this.getTranslateXValue() : -this.getTranslateXValue();
this.inner.classList.add("dragging");
}
handleDragMove(evt) {
if (!this.isDragging) return;
this.inner.querySelectorAll("a:not(.prevented-click)").forEach((el) => {
el.classList.add("prevented-click");
el.addEventListener("click", this.removeClickEventWhileDragging);
});
const currentX = this.getEventX(evt);
let deltaX = currentX - this.dragStartX;
if (this.isRTL) deltaX = -deltaX;
const newTranslateX = this.initialTranslateX + deltaX;
const newTranslateXFunc = () => {
let calcWidth = this.sliderWidth * this.slides.length / this.getCurrentSlidesQty() - this.sliderWidth;
const containerWidth = this.sliderWidth;
const itemWidth = containerWidth / this.getCurrentSlidesQty();
const centeredOffset = (containerWidth - itemWidth) / 2;
const limitStart = this.isCentered ? centeredOffset : 0;
if (this.isCentered) calcWidth = calcWidth + centeredOffset;
const limitEnd = -calcWidth;
if (this.isRTL) {
if (newTranslateX < limitStart) return limitStart;
if (newTranslateX > calcWidth) return limitEnd;
else return -newTranslateX;
} else {
if (newTranslateX > limitStart) return limitStart;
else if (newTranslateX < -calcWidth) return limitEnd;
else return newTranslateX;
}
};
this.setTranslate(newTranslateXFunc());
}
handleDragEnd() {
if (!this.isDragging) return;
this.isDragging = false;
const containerWidth = this.sliderWidth;
const itemWidth = containerWidth / this.getCurrentSlidesQty();
const currentTranslateX = this.getTranslateXValue();
let closestIndex = Math.round(currentTranslateX / itemWidth);
if (this.isRTL) closestIndex = Math.round(currentTranslateX / itemWidth);
this.inner.classList.remove("dragging");
setTimeout(() => {
this.calculateTransform(closestIndex);
if (this.dots) this.setCurrentDot();
this.dragStartX = null;
this.initialTranslateX = null;
this.inner.querySelectorAll("a.prevented-click").forEach((el) => {
el.classList.remove("prevented-click");
el.removeEventListener("click", this.removeClickEventWhileDragging);
});
});
}
getEventX(event) {
return event instanceof MouseEvent ? event.clientX : event.touches[0].clientX;
}
getCurrentSlidesQty() {
if (typeof this.slidesQty === "object") {
const windowWidth = document.body.clientWidth;
let currentRes = 0;
Object.keys(this.slidesQty).forEach((key) => {
if (windowWidth >= (typeof key + 1 === "number" ? this.slidesQty[key] : BREAKPOINTS[key])) {
currentRes = this.slidesQty[key];
}
});
return currentRes;
} else {
return this.slidesQty;
}
}
buildSnapSpacers() {
const existingBefore = this.inner.querySelector(".hs-snap-before");
const existingAfter = this.inner.querySelector(".hs-snap-after");
if (existingBefore) existingBefore.remove();
if (existingAfter) existingAfter.remove();
const containerWidth = this.sliderWidth;
const itemWidth = containerWidth / this.getCurrentSlidesQty();
const spacerWidth = containerWidth / 2 - itemWidth / 2;
const before = htmlToElement(
`
`
);
const after = htmlToElement(
`
`
);
this.inner.prepend(before);
this.inner.appendChild(after);
}
initDots() {
if (this.el.querySelectorAll(".hs-carousel-pagination-item").length) {
this.setDots();
} else this.buildDots();
if (this.dots) this.setCurrentDot();
}
buildDots() {
this.dots.innerHTML = "";
const slidesQty = !this.isCentered && this.slidesQty ? this.slides.length - (this.getCurrentSlidesQty() - 1) : this.slides.length;
for (let i = 0; i < slidesQty; i++) {
const singleDot = this.buildSingleDot(i);
this.dots.append(singleDot);
}
}
setDots() {
this.dotsItems = this.dots.querySelectorAll(".hs-carousel-pagination-item");
this.dotsItems.forEach((dot, ind) => {
const targetIndex = dot.getAttribute(
"data-carousel-pagination-item-target"
);
this.singleDotEvents(dot, targetIndex ? +targetIndex : ind);
});
}
goToCurrentDot() {
const container = this.dots;
const containerRect = container.getBoundingClientRect();
const containerScrollLeft = container.scrollLeft;
const containerScrollTop = container.scrollTop;
const containerWidth = container.clientWidth;
const containerHeight = container.clientHeight;
const item = this.dotsItems[this.currentIndex];
const itemRect = item.getBoundingClientRect();
const itemLeft = itemRect.left - containerRect.left + containerScrollLeft;
const itemRight = itemLeft + item.clientWidth;
const itemTop = itemRect.top - containerRect.top + containerScrollTop;
const itemBottom = itemTop + item.clientHeight;
let scrollLeft = containerScrollLeft;
let scrollTop = containerScrollTop;
if (itemLeft < containerScrollLeft || itemRight > containerScrollLeft + containerWidth) {
scrollLeft = itemRight - containerWidth;
}
if (itemTop < containerScrollTop || itemBottom > containerScrollTop + containerHeight) {
scrollTop = itemBottom - containerHeight;
}
container.scrollTo({
left: scrollLeft,
top: scrollTop,
behavior: "smooth"
});
}
buildInfo() {
if (this.infoTotal) this.setInfoTotal();
if (this.infoCurrent) this.setInfoCurrent();
}
setInfoTotal() {
this.infoTotal.innerText = `${this.slides.length}`;
}
setInfoCurrent() {
this.infoCurrent.innerText = `${this.currentIndex + 1}`;
}
buildSingleDot(ind) {
const singleDot = htmlToElement(" ");
if (this.dotsItemClasses) classToClassList(this.dotsItemClasses, singleDot);
this.singleDotEvents(singleDot, ind);
return singleDot;
}
singleDotEvents(dot, ind) {
this.onDotClickListener = () => this.dotClick(ind);
dot.addEventListener("click", this.onDotClickListener);
}
observeResize() {
const resizeObserver = new ResizeObserver(
debounce((entries) => {
for (let entry of entries) {
const newWidth = entry.contentRect.width;
if (newWidth !== this.resizeContainerWidth) {
this.recalculateWidth();
if (this.dots) this.initDots();
this.addCurrentClass();
this.resizeContainerWidth = newWidth;
}
}
}, this.updateDelay)
);
resizeObserver.observe(this.resizeContainer);
}
calculateWidth() {
if (!this.isSnap) {
this.inner.style.width = `${this.sliderWidth * this.slides.length / this.getCurrentSlidesQty()}px`;
}
this.slides.forEach((el) => {
el.style.width = `${this.sliderWidth / this.getCurrentSlidesQty()}px`;
});
this.calculateTransform();
}
addCurrentClass() {
if (this.isSnap) {
const itemsQty = Math.floor(this.getCurrentSlidesQty() / 2);
for (let i = 0; i < this.slides.length; i++) {
const slide = this.slides[i];
if (i <= this.currentIndex + itemsQty && i >= this.currentIndex - itemsQty) {
slide.classList.add("active");
} else slide.classList.remove("active");
}
} else {
const maxIndex = this.isCentered ? this.currentIndex + this.getCurrentSlidesQty() + (this.getCurrentSlidesQty() - 1) : this.currentIndex + this.getCurrentSlidesQty();
this.slides.forEach((el, i) => {
if (i >= this.currentIndex && i < maxIndex) {
el.classList.add("active");
} else {
el.classList.remove("active");
}
});
}
}
setCurrentDot() {
const toggleDotActive = (el, i) => {
let statement = false;
const itemsQty = Math.floor(this.getCurrentSlidesQty() / 2);
if (this.isSnap && !this.hasSnapSpacers) {
statement = i === (this.getCurrentSlidesQty() % 2 === 0 ? this.currentIndex - itemsQty + 1 : this.currentIndex - itemsQty);
} else statement = i === this.currentIndex;
if (statement) el.classList.add("active");
else el.classList.remove("active");
};
if (this.dotsItems) {
this.dotsItems.forEach((el, i) => toggleDotActive(el, i));
} else {
this.dots.querySelectorAll(":scope > *").forEach((el, i) => toggleDotActive(el, i));
}
}
setElementToDisabled(el) {
el.classList.add("disabled");
if (el.tagName === "BUTTON" || el.tagName === "INPUT") {
el.setAttribute("disabled", "disabled");
}
}
unsetElementToDisabled(el) {
el.classList.remove("disabled");
if (el.tagName === "BUTTON" || el.tagName === "INPUT") {
el.removeAttribute("disabled");
}
}
addDisabledClass() {
if (!this.prev || !this.next) return false;
const gapValue = getComputedStyle(this.inner).getPropertyValue("gap");
const itemsQty = Math.floor(this.getCurrentSlidesQty() / 2);
let currentIndex = 0;
let maxIndex = 0;
let statementPrev = false;
let statementNext = false;
if (this.isSnap) {
currentIndex = this.currentIndex;
maxIndex = this.hasSnapSpacers ? this.slides.length - 1 : this.slides.length - itemsQty - 1;
statementPrev = this.hasSnapSpacers ? currentIndex === 0 : this.getCurrentSlidesQty() % 2 === 0 ? currentIndex - itemsQty < 0 : currentIndex - itemsQty === 0;
statementNext = currentIndex >= maxIndex && this.container.scrollLeft + this.container.clientWidth + (parseFloat(gapValue) || 0) >= this.container.scrollWidth;
} else {
currentIndex = this.currentIndex;
maxIndex = this.isCentered ? this.slides.length - this.getCurrentSlidesQty() + (this.getCurrentSlidesQty() - 1) : this.slides.length - this.getCurrentSlidesQty();
statementPrev = currentIndex === 0;
statementNext = currentIndex >= maxIndex;
}
if (statementPrev) {
this.unsetElementToDisabled(this.next);
this.setElementToDisabled(this.prev);
} else if (statementNext) {
this.unsetElementToDisabled(this.prev);
this.setElementToDisabled(this.next);
} else {
this.unsetElementToDisabled(this.prev);
this.unsetElementToDisabled(this.next);
}
}
autoPlay() {
this.setTimer();
}
setTimer() {
this.timer = setInterval(() => {
if (this.currentIndex === this.slides.length - 1) this.goTo(0);
else this.goToNext();
}, this.speed);
}
resetTimer() {
clearInterval(this.timer);
}
detectDirection() {
const deltaX = this.touchX.end - this.touchX.start;
const deltaY = this.touchY.end - this.touchY.start;
const absDeltaX = Math.abs(deltaX);
const absDeltaY = Math.abs(deltaY);
const SWIPE_THRESHOLD = 30;
if (absDeltaX < SWIPE_THRESHOLD || absDeltaX < absDeltaY) return;
const isSwipeToNext = this.isRTL ? deltaX > 0 : deltaX < 0;
if (!this.isInfiniteLoop) {
if (isSwipeToNext && this.currentIndex < this.slides.length - this.getCurrentSlidesQty()) {
this.goToNext();
}
if (!isSwipeToNext && this.currentIndex > 0) {
this.goToPrev();
}
} else {
if (isSwipeToNext) this.goToNext();
else this.goToPrev();
}
}
calculateTransform(currentIdx) {
if (currentIdx !== void 0) this.currentIndex = currentIdx;
const containerWidth = this.sliderWidth;
const itemWidth = containerWidth / this.getCurrentSlidesQty();
let translateX = this.currentIndex * itemWidth;
if (this.isSnap && !this.isCentered) {
if (this.container.scrollLeft < containerWidth && this.container.scrollLeft + itemWidth / 2 > containerWidth) {
this.container.scrollLeft = this.container.scrollWidth;
}
}
if (this.isCentered && !this.isSnap) {
const centeredOffset = (containerWidth - itemWidth) / 2;
if (this.currentIndex === 0) translateX = -centeredOffset;
else if (this.currentIndex >= this.slides.length - this.getCurrentSlidesQty() + (this.getCurrentSlidesQty() - 1)) {
const totalSlideWidth = this.slides.length * itemWidth;
translateX = totalSlideWidth - containerWidth + centeredOffset;
} else translateX = this.currentIndex * itemWidth - centeredOffset;
}
if (!this.isSnap) this.setTransform(translateX);
if (this.isAutoHeight) {
this.inner.style.height = `${this.slides[this.currentIndex].clientHeight}px`;
}
if (this.dotsItems) this.goToCurrentDot();
this.addCurrentClass();
if (!this.isInfiniteLoop) this.addDisabledClass();
if (this.isSnap && this.hasSnapSpacers) this.buildSnapSpacers();
if (this.infoCurrent) this.setInfoCurrent();
}
setTransform(val) {
if (this.slides.length > this.getCurrentSlidesQty()) {
this.inner.style.transform = this.isRTL ? `translate(${val}px, 0px)` : `translate(${-val}px, 0px)`;
} else this.inner.style.transform = "translate(0px, 0px)";
}
setTranslate(val) {
this.inner.style.transform = this.isRTL ? `translate(${-val}px, 0px)` : `translate(${val}px, 0px)`;
}
setIndex(i) {
this.currentIndex = i;
this.addCurrentClass();
if (!this.isInfiniteLoop) this.addDisabledClass();
}
// Public methods
recalculateWidth() {
this.sliderWidth = this.inner.parentElement.getBoundingClientRect().width;
this.calculateWidth();
if (this.sliderWidth !== this.inner.parentElement.getBoundingClientRect().width) {
this.recalculateWidth();
}
}
goToPrev() {
if (this.currentIndex > 0) {
this.currentIndex--;
} else {
this.currentIndex = this.slides.length - this.getCurrentSlidesQty();
}
this.fireEvent("update", this.currentIndex);
if (this.isSnap) {
const itemWidth = this.sliderWidth / this.getCurrentSlidesQty();
this.container.scrollBy({
left: Math.max(-this.container.scrollLeft, -itemWidth),
behavior: "smooth"
});
this.addCurrentClass();
if (!this.isInfiniteLoop) this.addDisabledClass();
} else this.calculateTransform();
if (this.dots) this.setCurrentDot();
}
goToNext() {
const statement = this.isCentered ? this.slides.length - this.getCurrentSlidesQty() + (this.getCurrentSlidesQty() - 1) : this.slides.length - this.getCurrentSlidesQty();
if (this.currentIndex < statement) {
this.currentIndex++;
} else {
this.currentIndex = 0;
}
this.fireEvent("update", this.currentIndex);
if (this.isSnap) {
const itemWidth = this.sliderWidth / this.getCurrentSlidesQty();
const maxScrollLeft = this.container.scrollWidth - this.container.clientWidth;
this.container.scrollBy({
left: Math.min(itemWidth, maxScrollLeft - this.container.scrollLeft),
behavior: "smooth"
});
this.addCurrentClass();
if (!this.isInfiniteLoop) this.addDisabledClass();
} else this.calculateTransform();
if (this.dots) this.setCurrentDot();
}
goTo(i) {
const currentIndex = this.currentIndex;
this.currentIndex = i;
this.fireEvent("update", this.currentIndex);
if (this.isSnap) {
const itemWidth = this.sliderWidth / this.getCurrentSlidesQty();
const index = currentIndex > this.currentIndex ? currentIndex - this.currentIndex : this.currentIndex - currentIndex;
const width = currentIndex > this.currentIndex ? -(itemWidth * index) : itemWidth * index;
this.container.scrollBy({
left: width,
behavior: "smooth"
});
this.addCurrentClass();
if (!this.isInfiniteLoop) this.addDisabledClass();
} else this.calculateTransform();
if (this.dots) this.setCurrentDot();
}
destroy() {
if (this.loadingClassesAdd) {
if (typeof this.loadingClassesAdd === "string") {
this.inner.classList.remove(this.loadingClassesAdd);
} else this.inner.classList.remove(...this.loadingClassesAdd);
}
if (this.inner && this.afterLoadingClassesAdd) {
setTimeout(() => {
if (typeof this.afterLoadingClassesAdd === "string") {
this.inner.classList.remove(this.afterLoadingClassesAdd);
} else this.inner.classList.remove(...this.afterLoadingClassesAdd);
});
}
this.el.classList.remove("init");
this.inner.classList.remove("dragging");
this.slides.forEach((el) => el.classList.remove("active"));
if (this?.dotsItems?.length) {
this.dotsItems.forEach((el) => el.classList.remove("active"));
}
this.prev.classList.remove("disabled");
this.next.classList.remove("disabled");
this.inner.style.width = "";
this.slides.forEach((el) => el.style.width = "");
if (!this.isSnap) this.inner.style.transform = "";
if (this.isAutoHeight) this.inner.style.height = "";
this.prev.removeEventListener("click", this.onPrevClickListener);
this.next.removeEventListener("click", this.onNextClickListener);
this.container.removeEventListener(
"scroll",
this.onContainerScrollListener
);
this.el.removeEventListener("touchstart", this.onElementTouchStartListener);
this.el.removeEventListener("touchend", this.onElementTouchEndListener);
this.inner.removeEventListener("mousedown", this.onInnerMouseDownListener);
this.inner.removeEventListener(
"touchstart",
this.onInnerTouchStartListener
);
document.removeEventListener("mousemove", this.onDocumentMouseMoveListener);
document.removeEventListener("touchmove", this.onDocumentTouchMoveListener);
document.removeEventListener("mouseup", this.onDocumentMouseUpListener);
document.removeEventListener("touchend", this.onDocumentTouchEndListener);
this.inner.querySelectorAll("a:not(.prevented-click)").forEach((el) => {
el.classList.remove("prevented-click");
el.removeEventListener("click", this.removeClickEventWhileDragging);
});
if (this?.dotsItems?.length || this.dots.querySelectorAll(":scope > *").length) {
const dots = this?.dotsItems || this.dots.querySelectorAll(":scope > *");
dots.forEach(
(el) => el.removeEventListener("click", this.onDotClickListener)
);
this.dots.innerHTML = null;
}
this.inner.querySelector(".hs-snap-before").remove();
this.inner.querySelector(".hs-snap-after").remove();
this.dotsItems = null;
this.isDragging = false;
this.dragStartX = null;
this.initialTranslateX = null;
window.$hsCarouselCollection = window.$hsCarouselCollection.filter(
({ element }) => element.el !== this.el
);
}
// Static methods
static getInstance(target, isInstance) {
const elInCollection = window.$hsCarouselCollection.find(
(el) => el.element.el === (typeof target === "string" ? document.querySelector(target) : target)
);
return elInCollection ? isInstance ? elInCollection : elInCollection.element : null;
}
static autoInit() {
if (!window.$hsCarouselCollection) window.$hsCarouselCollection = [];
if (window.$hsCarouselCollection) {
window.$hsCarouselCollection = window.$hsCarouselCollection.filter(
({ element }) => document.contains(element.el)
);
}
document.querySelectorAll("[data-hs-carousel]:not(.--prevent-on-load-init)").forEach((el) => {
if (!window.$hsCarouselCollection.find(
(elC) => elC?.element?.el === el
)) {
new _HSCarousel(el);
}
});
}
};
window.addEventListener("load", () => {
HSCarousel.autoInit();
});
if (typeof window !== "undefined") {
window.HSCarousel = HSCarousel;
}
var carousel_default = HSCarousel;
// node_modules/preline/src/plugins/collapse/index.ts
init_utils();
init_base_plugin();
var HSCollapse = class _HSCollapse extends HSBasePlugin {
contentId;
content;
animationInProcess;
onElementClickListener;
constructor(el, options, events) {
super(el, options, events);
this.contentId = this.el.dataset.hsCollapse;
this.content = document.querySelector(this.contentId);
this.animationInProcess = false;
if (this.content) this.init();
}
elementClick() {
if (this.content.classList.contains("open")) {
this.hide();
} else {
this.show();
}
}
init() {
this.createCollection(window.$hsCollapseCollection, this);
this.onElementClickListener = () => this.elementClick();
if (this?.el?.ariaExpanded) {
if (this.el.classList.contains("open")) this.el.ariaExpanded = "true";
else this.el.ariaExpanded = "false";
}
this.el.addEventListener("click", this.onElementClickListener);
}
hideAllMegaMenuItems() {
this.content.querySelectorAll(".hs-mega-menu-content.block").forEach((el) => {
el.classList.remove("block");
el.classList.add("hidden");
});
}
// Public methods
show() {
if (this.animationInProcess || this.el.classList.contains("open"))
return false;
this.animationInProcess = true;
this.el.classList.add("open");
if (this?.el?.ariaExpanded) this.el.ariaExpanded = "true";
this.content.classList.add("open");
this.content.classList.remove("hidden");
this.content.style.height = "0";
setTimeout(() => {
this.content.style.height = `${this.content.scrollHeight}px`;
this.fireEvent("beforeOpen", this.el);
dispatch("beforeOpen.hs.collapse", this.el, this.el);
});
afterTransition(this.content, () => {
this.content.style.height = "";
this.fireEvent("open", this.el);
dispatch("open.hs.collapse", this.el, this.el);
this.animationInProcess = false;
});
}
hide() {
if (this.animationInProcess || !this.el.classList.contains("open"))
return false;
this.animationInProcess = true;
this.el.classList.remove("open");
if (this?.el?.ariaExpanded) this.el.ariaExpanded = "false";
this.content.style.height = `${this.content.scrollHeight}px`;
setTimeout(() => {
this.content.style.height = "0";
});
this.content.classList.remove("open");
afterTransition(this.content, () => {
this.content.classList.add("hidden");
this.content.style.height = "";
this.fireEvent("hide", this.el);
dispatch("hide.hs.collapse", this.el, this.el);
this.animationInProcess = false;
});
if (this.content.querySelectorAll(".hs-mega-menu-content.block").length) {
this.hideAllMegaMenuItems();
}
}
destroy() {
this.el.removeEventListener("click", this.onElementClickListener);
this.content = null;
this.animationInProcess = false;
window.$hsCollapseCollection = window.$hsCollapseCollection.filter(
({ element }) => element.el !== this.el
);
}
// Static methods
static findInCollection(target) {
return window.$hsCollapseCollection.find((el) => {
if (target instanceof _HSCollapse) return el.element.el === target.el;
else if (typeof target === "string") return el.element.el === document.querySelector(target);
else return el.element.el === target;
}) || null;
}
static getInstance(target, isInstance = false) {
const elInCollection = window.$hsCollapseCollection.find(
(el) => el.element.el === (typeof target === "string" ? document.querySelector(target) : target)
);
return elInCollection ? isInstance ? elInCollection : elInCollection.element.el : null;
}
static autoInit() {
if (!window.$hsCollapseCollection) window.$hsCollapseCollection = [];
if (window.$hsCollapseCollection)
window.$hsCollapseCollection = window.$hsCollapseCollection.filter(
({ element }) => document.contains(element.el)
);
document.querySelectorAll(".hs-collapse-toggle:not(.--prevent-on-load-init)").forEach((el) => {
if (!window.$hsCollapseCollection.find(
(elC) => elC?.element?.el === el
))
new _HSCollapse(el);
});
}
static show(target) {
const instance = _HSCollapse.findInCollection(target);
if (instance && instance.element.content.classList.contains("hidden")) instance.element.show();
}
static hide(target) {
const instance = _HSCollapse.findInCollection(target);
if (instance && !instance.element.content.classList.contains("hidden")) instance.element.hide();
}
// Backward compatibility
static on(evt, target, cb) {
const instance = _HSCollapse.findInCollection(target);
if (instance) instance.element.events[evt] = cb;
}
};
window.addEventListener("load", () => {
HSCollapse.autoInit();
});
if (typeof window !== "undefined") {
window.HSCollapse = HSCollapse;
}
var collapse_default = HSCollapse;
// node_modules/preline/src/plugins/combobox/index.ts
init_utils();
init_base_plugin();
init_accessibility_manager();
var HSComboBox = class _HSComboBox extends HSBasePlugin {
gap;
viewport;
preventVisibility;
minSearchLength;
apiUrl;
apiDataPart;
apiQuery;
apiSearchQuery;
apiSearchPath;
apiSearchDefaultPath;
apiHeaders;
apiGroupField;
outputItemTemplate;
outputEmptyTemplate;
outputLoaderTemplate;
groupingType;
groupingTitleTemplate;
tabsWrapperTemplate;
preventSelection;
preventAutoPosition;
preventClientFiltering;
isOpenOnFocus;
keepOriginalOrder;
preserveSelectionOnEmpty;
accessibilityComponent;
input;
output;
itemsWrapper;
items;
tabs;
toggle;
toggleClose;
toggleOpen;
outputPlaceholder;
outputLoader;
value;
selected;
currentData;
groups;
selectedGroup;
isOpened;
isCurrent;
animationInProcess;
isSearchLengthExceeded = false;
onInputFocusListener;
onInputInputListener;
onToggleClickListener;
onToggleCloseClickListener;
onToggleOpenClickListener;
constructor(el, options, events) {
super(el, options, events);
const data = el.getAttribute("data-hs-combo-box");
const dataOptions = data ? JSON.parse(data) : {};
const concatOptions = {
...dataOptions,
...options
};
this.gap = 5;
this.viewport = (typeof concatOptions?.viewport === "string" ? document.querySelector(concatOptions?.viewport) : concatOptions?.viewport) ?? null;
this.preventVisibility = concatOptions?.preventVisibility ?? false;
this.minSearchLength = concatOptions?.minSearchLength ?? 0;
this.apiUrl = concatOptions?.apiUrl ?? null;
this.apiDataPart = concatOptions?.apiDataPart ?? null;
this.apiQuery = concatOptions?.apiQuery ?? null;
this.apiSearchQuery = concatOptions?.apiSearchQuery ?? null;
this.apiSearchPath = concatOptions?.apiSearchPath ?? null;
this.apiSearchDefaultPath = concatOptions?.apiSearchDefaultPath ?? null;
this.apiHeaders = concatOptions?.apiHeaders ?? {};
this.apiGroupField = concatOptions?.apiGroupField ?? null;
this.outputItemTemplate = concatOptions?.outputItemTemplate ?? ``;
this.outputEmptyTemplate = concatOptions?.outputEmptyTemplate ?? `Nothing found...
`;
this.outputLoaderTemplate = concatOptions?.outputLoaderTemplate ?? ``;
this.groupingType = concatOptions?.groupingType ?? null;
this.groupingTitleTemplate = concatOptions?.groupingTitleTemplate ?? (this.groupingType === "default" ? `
` : ` `);
this.tabsWrapperTemplate = concatOptions?.tabsWrapperTemplate ?? `
`;
this.preventSelection = concatOptions?.preventSelection ?? false;
this.preventAutoPosition = concatOptions?.preventAutoPosition ?? false;
this.preventClientFiltering = options?.preventClientFiltering ?? (!!concatOptions?.apiSearchQuery || !!concatOptions?.apiSearchPath);
this.isOpenOnFocus = concatOptions?.isOpenOnFocus ?? false;
this.keepOriginalOrder = concatOptions?.keepOriginalOrder ?? false;
this.preserveSelectionOnEmpty = concatOptions?.preserveSelectionOnEmpty ?? true;
this.input = this.el.querySelector("[data-hs-combo-box-input]") ?? null;
this.output = this.el.querySelector("[data-hs-combo-box-output]") ?? null;
this.itemsWrapper = this.el.querySelector("[data-hs-combo-box-output-items-wrapper]") ?? null;
this.items = Array.from(this.el.querySelectorAll("[data-hs-combo-box-output-item]")) ?? [];
this.tabs = [];
this.toggle = this.el.querySelector("[data-hs-combo-box-toggle]") ?? null;
this.toggleClose = this.el.querySelector("[data-hs-combo-box-close]") ?? null;
this.toggleOpen = this.el.querySelector("[data-hs-combo-box-open]") ?? null;
this.outputPlaceholder = null;
this.selected = this.value = this.el.querySelector("[data-hs-combo-box-input]").value ?? "";
this.currentData = null;
this.isOpened = false;
this.isCurrent = false;
this.animationInProcess = false;
this.selectedGroup = "all";
this.init();
}
inputFocus() {
if (!this.isOpened) {
this.setResultAndRender();
this.open();
}
}
inputInput(evt) {
const val = evt.target.value.trim();
if (val.length <= this.minSearchLength) this.setResultAndRender("");
else this.setResultAndRender(val);
if (!this.preserveSelectionOnEmpty && val === "") {
this.selected = "";
this.value = "";
this.currentData = null;
}
if (this.input.value !== "") this.el.classList.add("has-value");
else this.el.classList.remove("has-value");
if (!this.isOpened) this.open();
}
toggleClick() {
if (this.isOpened) this.close();
else this.open(this.toggle.getAttribute("data-hs-combo-box-toggle"));
}
toggleCloseClick() {
this.close();
}
toggleOpenClick() {
this.open();
}
init() {
this.createCollection(window.$hsComboBoxCollection, this);
this.build();
if (typeof window !== "undefined") {
if (!window.HSAccessibilityObserver) {
window.HSAccessibilityObserver = new accessibility_manager_default();
}
this.setupAccessibility();
}
}
build() {
this.buildInput();
if (this.groupingType) this.setGroups();
this.buildItems();
if (this.preventVisibility) {
if (!this.preventAutoPosition) this.recalculateDirection();
}
if (this.toggle) this.buildToggle();
if (this.toggleClose) this.buildToggleClose();
if (this.toggleOpen) this.buildToggleOpen();
}
getNestedProperty(obj, path) {
return path.split(".").reduce(
(acc, key) => acc && acc[key],
obj
);
}
setValue(val, data = null) {
this.selected = val;
this.value = val;
this.input.value = val;
if (data) this.currentData = data;
this.fireEvent("select", this.currentData);
dispatch("select.hs.combobox", this.el, this.currentData);
}
setValueAndOpen(val) {
this.value = val;
if (this.items.length) {
this.setItemsVisibility();
}
}
setValueAndClear(val, data = null) {
if (val) this.setValue(val, data);
else this.setValue(this.selected, data);
if (this.outputPlaceholder) this.destroyOutputPlaceholder();
}
setSelectedByValue(val) {
this.items.forEach((el) => {
const valueElement = el.querySelector("[data-hs-combo-box-value]");
if (valueElement && val.includes(valueElement.textContent)) {
el.classList.add("selected");
} else {
el.classList.remove("selected");
}
});
}
setResultAndRender(value = "") {
let _value = this.preventVisibility ? this.input.value : value;
this.setResults(_value);
if (this.apiSearchQuery || this.apiSearchPath || this.apiSearchDefaultPath) this.itemsFromJson();
if (_value === "") this.isSearchLengthExceeded = true;
else this.isSearchLengthExceeded = false;
this.updatePlaceholderVisibility();
}
setResults(val) {
this.value = val;
this.resultItems();
this.updatePlaceholderVisibility();
}
updatePlaceholderVisibility() {
if (this.hasVisibleItems()) this.destroyOutputPlaceholder();
else this.buildOutputPlaceholder();
}
setGroups() {
const groups = [];
this.items.forEach((item) => {
const { group } = JSON.parse(
item.getAttribute("data-hs-combo-box-output-item")
);
if (!groups.some((el) => el?.name === group.name)) {
groups.push(group);
}
});
this.groups = groups;
}
setApiGroups(items) {
const groups = [];
items.forEach((item) => {
const group = item[this.apiGroupField];
if (!groups.some((el) => el.name === group)) {
groups.push({
name: group,
title: group
});
}
});
this.groups = groups;
}
setItemsVisibility() {
if (this.preventClientFiltering) {
this.items.forEach((el) => {
el.style.display = "";
});
return false;
}
if (this.groupingType === "tabs" && this.selectedGroup !== "all") {
this.items.forEach((item) => {
item.style.display = "none";
});
}
const items = this.groupingType === "tabs" ? this.selectedGroup === "all" ? this.items : this.items.filter((f) => {
const { group } = JSON.parse(
f.getAttribute("data-hs-combo-box-output-item")
);
return group.name === this.selectedGroup;
}) : this.items;
if (this.groupingType === "tabs" && this.selectedGroup !== "all") {
items.forEach((item) => {
item.style.display = "block";
});
}
items.forEach((item) => {
if (!this.isTextExistsAny(item, this.value)) {
item.style.display = "none";
} else item.style.display = "block";
});
if (this.groupingType === "default") {
this.output.querySelectorAll("[data-hs-combo-box-group-title]").forEach((el) => {
const g = el.getAttribute("data-hs-combo-box-group-title");
const items2 = this.items.filter((f) => {
const { group } = JSON.parse(
f.getAttribute("data-hs-combo-box-output-item")
);
return group.name === g && f.style.display === "block";
});
if (items2.length) el.style.display = "block";
else el.style.display = "none";
});
}
}
isTextExistsAny(el, val) {
return Array.from(
el.querySelectorAll("[data-hs-combo-box-search-text]")
).some(
(elI) => elI.getAttribute("data-hs-combo-box-search-text").toLowerCase().includes(val.toLowerCase())
);
}
hasVisibleItems() {
if (!this.items.length) return false;
return this.items.some((el) => {
const style = window.getComputedStyle(el);
return style.display !== "none" && style.visibility !== "hidden";
});
}
valuesBySelector(el) {
return Array.from(
el.querySelectorAll("[data-hs-combo-box-search-text]")
).reduce(
(acc, cur) => [
...acc,
cur.getAttribute("data-hs-combo-box-search-text")
],
[]
);
}
sortItems() {
if (this.keepOriginalOrder) return this.items;
const compareFn = (i1, i2) => {
const a = i1.querySelector("[data-hs-combo-box-value]").textContent;
const b = i2.querySelector("[data-hs-combo-box-value]").textContent;
if (a < b) {
return -1;
} else if (a > b) {
return 1;
}
return 0;
};
return this.items.sort(compareFn);
}
buildInput() {
if (this.isOpenOnFocus) {
this.onInputFocusListener = () => this.inputFocus();
this.input.addEventListener("focus", this.onInputFocusListener);
}
this.onInputInputListener = debounce(
(evt) => this.inputInput(evt)
);
this.input.addEventListener("input", this.onInputInputListener);
}
async buildItems() {
this.output.role = "listbox";
this.output.tabIndex = -1;
this.output.ariaOrientation = "vertical";
if (this.apiUrl) await this.itemsFromJson();
else {
if (this.itemsWrapper) this.itemsWrapper.innerHTML = "";
else this.output.innerHTML = "";
this.itemsFromHtml();
}
if (this?.items.length && this.items[0].classList.contains("selected")) {
this.currentData = JSON.parse(
this.items[0].getAttribute("data-hs-combo-box-item-stored-data")
);
}
}
buildOutputLoader() {
if (this.outputLoader) return false;
this.outputLoader = htmlToElement(this.outputLoaderTemplate);
if (this.items.length || this.outputPlaceholder) {
this.outputLoader.style.position = "absolute";
this.outputLoader.style.top = "0";
this.outputLoader.style.bottom = "0";
this.outputLoader.style.left = "0";
this.outputLoader.style.right = "0";
this.outputLoader.style.zIndex = "2";
} else {
this.outputLoader.style.position = "";
this.outputLoader.style.top = "";
this.outputLoader.style.bottom = "";
this.outputLoader.style.left = "";
this.outputLoader.style.right = "";
this.outputLoader.style.zIndex = "";
this.outputLoader.style.height = "30px";
}
this.output.append(this.outputLoader);
}
buildToggle() {
if (this.isOpened) {
if (this?.toggle?.ariaExpanded) this.toggle.ariaExpanded = "true";
if (this?.input?.ariaExpanded) this.input.ariaExpanded = "true";
} else {
if (this?.toggle?.ariaExpanded) this.toggle.ariaExpanded = "false";
if (this?.input?.ariaExpanded) this.input.ariaExpanded = "false";
}
this.onToggleClickListener = () => this.toggleClick();
this.toggle.addEventListener("click", this.onToggleClickListener);
}
buildToggleClose() {
this.onToggleCloseClickListener = () => this.toggleCloseClick();
this.toggleClose.addEventListener("click", this.onToggleCloseClickListener);
}
buildToggleOpen() {
this.onToggleOpenClickListener = () => this.toggleOpenClick();
this.toggleOpen.addEventListener("click", this.onToggleOpenClickListener);
}
buildOutputPlaceholder() {
if (!this.outputPlaceholder) {
this.outputPlaceholder = htmlToElement(this.outputEmptyTemplate);
}
this.appendItemsToWrapper(this.outputPlaceholder);
}
destroyOutputLoader() {
if (this.outputLoader) this.outputLoader.remove();
this.outputLoader = null;
}
itemRender(item) {
const val = item.querySelector("[data-hs-combo-box-value]").textContent;
const data = JSON.parse(item.getAttribute("data-hs-combo-box-item-stored-data")) ?? null;
if (this.itemsWrapper) this.itemsWrapper.append(item);
else this.output.append(item);
if (!this.preventSelection) {
item.addEventListener("click", () => {
this.close(val, data);
this.setSelectedByValue(this.valuesBySelector(item));
});
}
}
plainRender(items) {
items.forEach((item) => {
this.itemRender(item);
});
}
jsonItemsRender(items) {
items.forEach((item, index) => {
const newItem = htmlToElement(this.outputItemTemplate);
newItem.setAttribute(
"data-hs-combo-box-item-stored-data",
JSON.stringify(item)
);
newItem.querySelectorAll("[data-hs-combo-box-output-item-field]").forEach((el) => {
const valueAttr = el.getAttribute(
"data-hs-combo-box-output-item-field"
);
let value = "";
try {
const fields = JSON.parse(valueAttr);
if (Array.isArray(fields)) {
value = fields.map((field) => this.getNestedProperty(item, field)).filter(Boolean).join(" ");
} else {
value = this.getNestedProperty(item, valueAttr);
}
} catch (e2) {
value = this.getNestedProperty(item, valueAttr);
}
el.textContent = value ?? "";
if (!value && el.hasAttribute("data-hs-combo-box-output-item-hide-if-empty")) {
el.style.display = "none";
}
});
newItem.querySelectorAll("[data-hs-combo-box-search-text]").forEach((el) => {
const valueAttr = el.getAttribute(
"data-hs-combo-box-output-item-field"
);
let value = "";
try {
const fields = JSON.parse(valueAttr);
if (Array.isArray(fields)) {
value = fields.map((field) => this.getNestedProperty(item, field)).filter(Boolean).join(" ");
} else {
value = this.getNestedProperty(item, valueAttr);
}
} catch (e2) {
value = this.getNestedProperty(item, valueAttr);
}
el.setAttribute(
"data-hs-combo-box-search-text",
value ?? ""
);
});
newItem.querySelectorAll("[data-hs-combo-box-output-item-attr]").forEach((el) => {
const attributes = JSON.parse(
el.getAttribute("data-hs-combo-box-output-item-attr")
);
attributes.forEach((attr) => {
let value = item[attr.valueFrom];
if (attr.attr === "class" && el.className) {
el.className = `${el.className} ${value}`.trim();
} else {
el.setAttribute(attr.attr, value);
}
});
});
newItem.setAttribute("tabIndex", `${index}`);
if (this.groupingType === "tabs" || this.groupingType === "default") {
newItem.setAttribute(
"data-hs-combo-box-output-item",
`{"group": {"name": "${item[this.apiGroupField]}", "title": "${item[this.apiGroupField]}"}}`
);
}
this.items = [...this.items, newItem];
if (!this.preventSelection) {
newItem.addEventListener("click", () => {
this.close(
newItem.querySelector("[data-hs-combo-box-value]").textContent,
JSON.parse(newItem.getAttribute("data-hs-combo-box-item-stored-data"))
);
this.setSelectedByValue(this.valuesBySelector(newItem));
});
}
this.appendItemsToWrapper(newItem);
});
}
groupDefaultRender() {
this.groups.forEach((el) => {
const title = htmlToElement(this.groupingTitleTemplate);
title.setAttribute("data-hs-combo-box-group-title", el.name);
title.classList.add("--exclude-accessibility");
title.innerText = el.title;
if (this.itemsWrapper) this.itemsWrapper.append(title);
else this.output.append(title);
const items = this.sortItems().filter((f) => {
const { group } = JSON.parse(
f.getAttribute("data-hs-combo-box-output-item")
);
return group.name === el.name;
});
this.plainRender(items);
});
}
groupTabsRender() {
const tabsScroll = htmlToElement(this.tabsWrapperTemplate);
const tabsWrapper = htmlToElement(
`
`
);
tabsScroll.append(tabsWrapper);
this.output.insertBefore(tabsScroll, this.output.firstChild);
const tabDef = htmlToElement(this.groupingTitleTemplate);
tabDef.setAttribute("data-hs-combo-box-group-title", "all");
tabDef.classList.add("--exclude-accessibility", "active");
tabDef.innerText = "All";
this.tabs = [...this.tabs, tabDef];
tabsWrapper.append(tabDef);
tabDef.addEventListener("click", () => {
this.selectedGroup = "all";
const selectedTab = this.tabs.find(
(elI) => elI.getAttribute("data-hs-combo-box-group-title") === this.selectedGroup
);
this.tabs.forEach((el) => el.classList.remove("active"));
selectedTab.classList.add("active");
this.setItemsVisibility();
});
this.groups.forEach((el) => {
const tab = htmlToElement(this.groupingTitleTemplate);
tab.setAttribute("data-hs-combo-box-group-title", el.name);
tab.classList.add("--exclude-accessibility");
tab.innerText = el.title;
this.tabs = [...this.tabs, tab];
tabsWrapper.append(tab);
tab.addEventListener("click", () => {
this.selectedGroup = el.name;
const selectedTab = this.tabs.find(
(elI) => elI.getAttribute("data-hs-combo-box-group-title") === this.selectedGroup
);
this.tabs.forEach((el2) => el2.classList.remove("active"));
selectedTab.classList.add("active");
this.setItemsVisibility();
});
});
}
itemsFromHtml() {
if (this.groupingType === "default") {
this.groupDefaultRender();
} else if (this.groupingType === "tabs") {
const items = this.sortItems();
this.groupTabsRender();
this.plainRender(items);
} else {
const items = this.sortItems();
this.plainRender(items);
}
this.setResults(this.input.value);
}
async itemsFromJson() {
if (this.isSearchLengthExceeded) {
this.buildOutputPlaceholder();
return false;
}
this.buildOutputLoader();
try {
const query = `${this.apiQuery}`;
let searchQuery;
let searchPath;
let url = this.apiUrl;
if (!this.apiSearchQuery && this.apiSearchPath) {
if (this.apiSearchDefaultPath && this.value === "") {
searchPath = `/${this.apiSearchDefaultPath}`;
} else {
searchPath = `/${this.apiSearchPath}/${this.value.toLowerCase()}`;
}
if (this.apiSearchPath || this.apiSearchDefaultPath) {
url += searchPath;
}
} else {
searchQuery = `${this.apiSearchQuery}=${this.value.toLowerCase()}`;
if (this.apiQuery && this.apiSearchQuery) {
url += `?${searchQuery}&${query}`;
} else if (this.apiQuery) {
url += `?${query}`;
} else if (this.apiSearchQuery) {
url += `?${searchQuery}`;
}
}
const res = await fetch(url, this.apiHeaders);
if (!res.ok) {
this.items = [];
if (this.itemsWrapper) this.itemsWrapper.innerHTML = "";
else this.output.innerHTML = "";
this.setResults(this.input.value);
return;
}
let items = await res.json();
if (this.apiDataPart) {
items = items[this.apiDataPart];
}
if (!Array.isArray(items)) {
items = [];
}
if (this.apiSearchQuery || this.apiSearchPath) {
this.items = [];
}
if (this.itemsWrapper) {
this.itemsWrapper.innerHTML = "";
} else {
this.output.innerHTML = "";
}
if (this.groupingType === "tabs") {
this.setApiGroups(items);
this.groupTabsRender();
this.jsonItemsRender(items);
} else if (this.groupingType === "default") {
this.setApiGroups(items);
this.groups.forEach((el) => {
const title = htmlToElement(this.groupingTitleTemplate);
title.setAttribute("data-hs-combo-box-group-title", el.name);
title.classList.add("--exclude-accessibility");
title.innerText = el.title;
const newItems = items.filter(
(i) => i[this.apiGroupField] === el.name
);
if (this.itemsWrapper) this.itemsWrapper.append(title);
else this.output.append(title);
this.jsonItemsRender(newItems);
});
} else {
this.jsonItemsRender(items);
}
this.setResults(
this.input.value.length <= this.minSearchLength ? "" : this.input.value
);
this.updatePlaceholderVisibility();
} catch (err) {
console.error("Error fetching items:", err);
this.items = [];
if (this.itemsWrapper) {
this.itemsWrapper.innerHTML = "";
} else {
this.output.innerHTML = "";
}
this.setResults(this.input.value);
} finally {
this.destroyOutputLoader();
}
}
appendItemsToWrapper(item) {
if (this.itemsWrapper) {
this.itemsWrapper.append(item);
} else {
this.output.append(item);
}
}
resultItems() {
if (!this.items.length) return false;
this.setItemsVisibility();
this.setSelectedByValue([this.selected]);
}
destroyOutputPlaceholder() {
if (this.outputPlaceholder) this.outputPlaceholder.remove();
this.outputPlaceholder = null;
}
getPreparedItems(isReversed = false, output) {
if (!output) return null;
const preparedItems = isReversed ? Array.from(
output.querySelectorAll(":scope > *:not(.--exclude-accessibility)")
).filter((el) => el.style.display !== "none").reverse() : Array.from(
output.querySelectorAll(":scope > *:not(.--exclude-accessibility)")
).filter((el) => el.style.display !== "none");
const items = preparedItems.filter(
(el) => !el.classList.contains("disabled")
);
return items;
}
setHighlighted(prev, current, input) {
current.focus();
input.value = current.querySelector("[data-hs-combo-box-value]").getAttribute("data-hs-combo-box-search-text");
if (prev) prev.classList.remove("hs-combo-box-output-item-highlighted");
current.classList.add("hs-combo-box-output-item-highlighted");
}
// Accessibility methods
setupAccessibility() {
const output = this.itemsWrapper ?? this.output;
this.accessibilityComponent = window.HSAccessibilityObserver.registerComponent(
this.el,
{
onEnter: () => this.onEnter(),
onSpace: () => this.onEnter(),
onEsc: () => {
if (this.isOpened) {
this.close();
if (this.input) this.input.focus();
}
},
onArrow: (evt) => {
if (!this.isOpened && evt.key === "ArrowDown") {
this.open();
return;
}
if (this.isOpened) {
switch (evt.key) {
case "ArrowDown":
this.focusMenuItem("next");
break;
case "ArrowUp":
this.focusMenuItem("prev");
break;
case "Home":
this.onStartEnd(true);
break;
case "End":
this.onStartEnd(false);
break;
}
}
}
// onTab: () => this.onTab(),
// onFirstLetter: (key: string) => this.onFirstLetter(key),
},
this.isOpened,
"ComboBox",
"[data-hs-combo-box]",
output
);
}
onEnter() {
if (!this.isOpened) {
this.open();
} else {
const highlighted = this.output.querySelector(
".hs-combo-box-output-item-highlighted"
);
if (highlighted) {
this.close(
highlighted.querySelector("[data-hs-combo-box-value]")?.getAttribute(
"data-hs-combo-box-search-text"
) ?? null,
JSON.parse(
highlighted.getAttribute("data-hs-combo-box-item-stored-data")
) ?? null
);
if (this.input) this.input.focus();
}
}
}
focusMenuItem(direction) {
const output = this.itemsWrapper ?? this.output;
if (!output) return false;
const options = Array.from(
output.querySelectorAll(":scope > *:not(.--exclude-accessibility)")
).filter((el) => el.style.display !== "none");
if (!options.length) return false;
const current = output.querySelector(
".hs-combo-box-output-item-highlighted"
);
const currentIndex = current ? options.indexOf(current) : -1;
const nextIndex = direction === "next" ? (currentIndex + 1) % options.length : (currentIndex - 1 + options.length) % options.length;
if (current) {
current.classList.remove("hs-combo-box-output-item-highlighted");
}
options[nextIndex].classList.add("hs-combo-box-output-item-highlighted");
options[nextIndex].focus();
this.input.value = options[nextIndex].querySelector("[data-hs-combo-box-value]").getAttribute("data-hs-combo-box-search-text");
}
onStartEnd(isStart = true) {
const output = this.itemsWrapper ?? this.output;
if (!output) return false;
const options = Array.from(
output.querySelectorAll(":scope > *:not(.--exclude-accessibility)")
).filter((el) => el.style.display !== "none");
if (!options.length) return false;
const current = output.querySelector(
".hs-combo-box-output-item-highlighted"
);
this.setHighlighted(
current,
options[0],
this.input
);
}
// Public methods
getCurrentData() {
return this.currentData;
}
setCurrent() {
if (window.$hsComboBoxCollection.length) {
window.$hsComboBoxCollection.map((el) => el.element.isCurrent = false);
this.isCurrent = true;
}
}
open(val) {
if (this.animationInProcess) return false;
if (typeof val !== "undefined") this.setValueAndOpen(val);
if (this.preventVisibility) return false;
this.animationInProcess = true;
this.output.style.display = "block";
if (!this.preventAutoPosition) this.recalculateDirection();
setTimeout(() => {
if (this?.input?.ariaExpanded) this.input.ariaExpanded = "true";
if (this?.toggle?.ariaExpanded) this.toggle.ariaExpanded = "true";
this.el.classList.add("active");
this.animationInProcess = false;
});
this.isOpened = true;
if (window.HSAccessibilityObserver && this.accessibilityComponent) {
window.HSAccessibilityObserver.updateComponentState(
this.accessibilityComponent,
true
);
}
}
close(val, data = null) {
if (this.animationInProcess) return false;
if (this.preventVisibility) {
this.setValueAndClear(val, data);
if (this.input.value !== "") this.el.classList.add("has-value");
else this.el.classList.remove("has-value");
return false;
}
if (!this.preserveSelectionOnEmpty && this.input.value.trim() === "") {
this.selected = "";
this.value = "";
}
this.animationInProcess = true;
if (this?.input?.ariaExpanded) this.input.ariaExpanded = "false";
if (this?.toggle?.ariaExpanded) this.toggle.ariaExpanded = "false";
this.el.classList.remove("active");
if (!this.preventAutoPosition) {
this.output.classList.remove("bottom-full", "top-full");
this.output.style.marginTop = "";
this.output.style.marginBottom = "";
}
afterTransition(this.output, () => {
this.output.style.display = "none";
this.setValueAndClear(val, data || null);
this.animationInProcess = false;
});
if (this.input.value !== "") this.el.classList.add("has-value");
else this.el.classList.remove("has-value");
this.isOpened = false;
if (window.HSAccessibilityObserver && this.accessibilityComponent) {
window.HSAccessibilityObserver.updateComponentState(
this.accessibilityComponent,
false
);
}
}
recalculateDirection() {
if (isEnoughSpace(
this.output,
this.input,
"bottom",
this.gap,
this.viewport
)) {
this.output.classList.remove("bottom-full");
this.output.style.marginBottom = "";
this.output.classList.add("top-full");
this.output.style.marginTop = `${this.gap}px`;
} else {
this.output.classList.remove("top-full");
this.output.style.marginTop = "";
this.output.classList.add("bottom-full");
this.output.style.marginBottom = `${this.gap}px`;
}
}
destroy() {
this.input.removeEventListener("focus", this.onInputFocusListener);
this.input.removeEventListener("input", this.onInputInputListener);
this.toggle.removeEventListener("click", this.onToggleClickListener);
if (this.toggleClose) {
this.toggleClose.removeEventListener(
"click",
this.onToggleCloseClickListener
);
}
if (this.toggleOpen) {
this.toggleOpen.removeEventListener(
"click",
this.onToggleOpenClickListener
);
}
this.el.classList.remove("has-value", "active");
if (this.items.length) {
this.items.forEach((el) => {
el.classList.remove("selected");
el.style.display = "";
});
}
this.output.removeAttribute("role");
this.output.removeAttribute("tabindex");
this.output.removeAttribute("aria-orientation");
if (this.outputLoader) {
this.outputLoader.remove();
this.outputLoader = null;
}
if (this.outputPlaceholder) {
this.outputPlaceholder.remove();
this.outputPlaceholder = null;
}
if (this.apiUrl) {
this.output.innerHTML = "";
}
this.items = [];
if (typeof window !== "undefined" && window.HSAccessibilityObserver) {
window.HSAccessibilityObserver.unregisterComponent(
this.accessibilityComponent
);
}
window.$hsComboBoxCollection = window.$hsComboBoxCollection.filter(
({ element }) => element.el !== this.el
);
}
// Static methods
static getInstance(target, isInstance) {
const elInCollection = window.$hsComboBoxCollection.find(
(el) => el.element.el === (typeof target === "string" ? document.querySelector(target) : target)
);
return elInCollection ? isInstance ? elInCollection : elInCollection.element : null;
}
static autoInit() {
if (!window.$hsComboBoxCollection) {
window.$hsComboBoxCollection = [];
window.addEventListener("click", (evt) => {
const evtTarget = evt.target;
_HSComboBox.closeCurrentlyOpened(evtTarget);
});
}
if (window.$hsComboBoxCollection) {
window.$hsComboBoxCollection = window.$hsComboBoxCollection.filter(
({ element }) => document.contains(element.el)
);
}
document.querySelectorAll("[data-hs-combo-box]:not(.--prevent-on-load-init)").forEach((el) => {
if (!window.$hsComboBoxCollection.find(
(elC) => elC?.element?.el === el
)) {
const data = el.getAttribute("data-hs-combo-box");
const options = data ? JSON.parse(data) : {};
new _HSComboBox(el, options);
}
});
}
static close(target) {
const elInCollection = window.$hsComboBoxCollection.find(
(el) => el.element.el === (typeof target === "string" ? document.querySelector(target) : target)
);
if (elInCollection && elInCollection.element.isOpened) {
elInCollection.element.close();
}
}
static closeCurrentlyOpened(evtTarget = null) {
if (!evtTarget.closest("[data-hs-combo-box].active")) {
const currentlyOpened = window.$hsComboBoxCollection.filter(
(el) => el.element.isOpened
) || null;
if (currentlyOpened) {
currentlyOpened.forEach((el) => {
el.element.close();
});
}
}
}
};
window.addEventListener("load", () => {
HSComboBox.autoInit();
});
document.addEventListener("scroll", () => {
if (!window.$hsComboBoxCollection) return false;
const target = window.$hsComboBoxCollection.find((el) => el.element.isOpened);
if (target && !target.element.preventAutoPosition) {
target.element.recalculateDirection();
}
});
if (typeof window !== "undefined") {
window.HSComboBox = HSComboBox;
}
var combobox_default = HSComboBox;
// node_modules/preline/src/plugins/dropdown/index.ts
init_utils();
// node_modules/@floating-ui/utils/dist/floating-ui.utils.mjs
var min = Math.min;
var max = Math.max;
var round = Math.round;
var floor = Math.floor;
var createCoords = (v) => ({
x: v,
y: v
});
var oppositeSideMap = {
left: "right",
right: "left",
bottom: "top",
top: "bottom"
};
var oppositeAlignmentMap = {
start: "end",
end: "start"
};
function evaluate(value, param) {
return typeof value === "function" ? value(param) : value;
}
function getSide(placement) {
return placement.split("-")[0];
}
function getAlignment(placement) {
return placement.split("-")[1];
}
function getOppositeAxis(axis) {
return axis === "x" ? "y" : "x";
}
function getAxisLength(axis) {
return axis === "y" ? "height" : "width";
}
var yAxisSides = /* @__PURE__ */ new Set(["top", "bottom"]);
function getSideAxis(placement) {
return yAxisSides.has(getSide(placement)) ? "y" : "x";
}
function getAlignmentAxis(placement) {
return getOppositeAxis(getSideAxis(placement));
}
function getAlignmentSides(placement, rects, rtl) {
if (rtl === void 0) {
rtl = false;
}
const alignment = getAlignment(placement);
const alignmentAxis = getAlignmentAxis(placement);
const length = getAxisLength(alignmentAxis);
let mainAlignmentSide = alignmentAxis === "x" ? alignment === (rtl ? "end" : "start") ? "right" : "left" : alignment === "start" ? "bottom" : "top";
if (rects.reference[length] > rects.floating[length]) {
mainAlignmentSide = getOppositePlacement(mainAlignmentSide);
}
return [mainAlignmentSide, getOppositePlacement(mainAlignmentSide)];
}
function getExpandedPlacements(placement) {
const oppositePlacement = getOppositePlacement(placement);
return [getOppositeAlignmentPlacement(placement), oppositePlacement, getOppositeAlignmentPlacement(oppositePlacement)];
}
function getOppositeAlignmentPlacement(placement) {
return placement.replace(/start|end/g, (alignment) => oppositeAlignmentMap[alignment]);
}
var lrPlacement = ["left", "right"];
var rlPlacement = ["right", "left"];
var tbPlacement = ["top", "bottom"];
var btPlacement = ["bottom", "top"];
function getSideList(side, isStart, rtl) {
switch (side) {
case "top":
case "bottom":
if (rtl) return isStart ? rlPlacement : lrPlacement;
return isStart ? lrPlacement : rlPlacement;
case "left":
case "right":
return isStart ? tbPlacement : btPlacement;
default:
return [];
}
}
function getOppositeAxisPlacements(placement, flipAlignment, direction, rtl) {
const alignment = getAlignment(placement);
let list = getSideList(getSide(placement), direction === "start", rtl);
if (alignment) {
list = list.map((side) => side + "-" + alignment);
if (flipAlignment) {
list = list.concat(list.map(getOppositeAlignmentPlacement));
}
}
return list;
}
function getOppositePlacement(placement) {
return placement.replace(/left|right|bottom|top/g, (side) => oppositeSideMap[side]);
}
function expandPaddingObject(padding) {
return {
top: 0,
right: 0,
bottom: 0,
left: 0,
...padding
};
}
function getPaddingObject(padding) {
return typeof padding !== "number" ? expandPaddingObject(padding) : {
top: padding,
right: padding,
bottom: padding,
left: padding
};
}
function rectToClientRect(rect) {
const {
x,
y,
width,
height
} = rect;
return {
width,
height,
top: y,
left: x,
right: x + width,
bottom: y + height,
x,
y
};
}
// node_modules/@floating-ui/core/dist/floating-ui.core.mjs
function computeCoordsFromPlacement(_ref, placement, rtl) {
let {
reference,
floating
} = _ref;
const sideAxis = getSideAxis(placement);
const alignmentAxis = getAlignmentAxis(placement);
const alignLength = getAxisLength(alignmentAxis);
const side = getSide(placement);
const isVertical = sideAxis === "y";
const commonX = reference.x + reference.width / 2 - floating.width / 2;
const commonY = reference.y + reference.height / 2 - floating.height / 2;
const commonAlign = reference[alignLength] / 2 - floating[alignLength] / 2;
let coords;
switch (side) {
case "top":
coords = {
x: commonX,
y: reference.y - floating.height
};
break;
case "bottom":
coords = {
x: commonX,
y: reference.y + reference.height
};
break;
case "right":
coords = {
x: reference.x + reference.width,
y: commonY
};
break;
case "left":
coords = {
x: reference.x - floating.width,
y: commonY
};
break;
default:
coords = {
x: reference.x,
y: reference.y
};
}
switch (getAlignment(placement)) {
case "start":
coords[alignmentAxis] -= commonAlign * (rtl && isVertical ? -1 : 1);
break;
case "end":
coords[alignmentAxis] += commonAlign * (rtl && isVertical ? -1 : 1);
break;
}
return coords;
}
var computePosition = async (reference, floating, config) => {
const {
placement = "bottom",
strategy = "absolute",
middleware = [],
platform: platform2
} = config;
const validMiddleware = middleware.filter(Boolean);
const rtl = await (platform2.isRTL == null ? void 0 : platform2.isRTL(floating));
let rects = await platform2.getElementRects({
reference,
floating,
strategy
});
let {
x,
y
} = computeCoordsFromPlacement(rects, placement, rtl);
let statefulPlacement = placement;
let middlewareData = {};
let resetCount = 0;
for (let i = 0; i < validMiddleware.length; i++) {
const {
name,
fn
} = validMiddleware[i];
const {
x: nextX,
y: nextY,
data,
reset: reset2
} = await fn({
x,
y,
initialPlacement: placement,
placement: statefulPlacement,
strategy,
middlewareData,
rects,
platform: platform2,
elements: {
reference,
floating
}
});
x = nextX != null ? nextX : x;
y = nextY != null ? nextY : y;
middlewareData = {
...middlewareData,
[name]: {
...middlewareData[name],
...data
}
};
if (reset2 && resetCount <= 50) {
resetCount++;
if (typeof reset2 === "object") {
if (reset2.placement) {
statefulPlacement = reset2.placement;
}
if (reset2.rects) {
rects = reset2.rects === true ? await platform2.getElementRects({
reference,
floating,
strategy
}) : reset2.rects;
}
({
x,
y
} = computeCoordsFromPlacement(rects, statefulPlacement, rtl));
}
i = -1;
}
}
return {
x,
y,
placement: statefulPlacement,
strategy,
middlewareData
};
};
async function detectOverflow(state2, options) {
var _await$platform$isEle;
if (options === void 0) {
options = {};
}
const {
x,
y,
platform: platform2,
rects,
elements,
strategy
} = state2;
const {
boundary = "clippingAncestors",
rootBoundary = "viewport",
elementContext = "floating",
altBoundary = false,
padding = 0
} = evaluate(options, state2);
const paddingObject = getPaddingObject(padding);
const altContext = elementContext === "floating" ? "reference" : "floating";
const element = elements[altBoundary ? altContext : elementContext];
const clippingClientRect = rectToClientRect(await platform2.getClippingRect({
element: ((_await$platform$isEle = await (platform2.isElement == null ? void 0 : platform2.isElement(element))) != null ? _await$platform$isEle : true) ? element : element.contextElement || await (platform2.getDocumentElement == null ? void 0 : platform2.getDocumentElement(elements.floating)),
boundary,
rootBoundary,
strategy
}));
const rect = elementContext === "floating" ? {
x,
y,
width: rects.floating.width,
height: rects.floating.height
} : rects.reference;
const offsetParent = await (platform2.getOffsetParent == null ? void 0 : platform2.getOffsetParent(elements.floating));
const offsetScale = await (platform2.isElement == null ? void 0 : platform2.isElement(offsetParent)) ? await (platform2.getScale == null ? void 0 : platform2.getScale(offsetParent)) || {
x: 1,
y: 1
} : {
x: 1,
y: 1
};
const elementClientRect = rectToClientRect(platform2.convertOffsetParentRelativeRectToViewportRelativeRect ? await platform2.convertOffsetParentRelativeRectToViewportRelativeRect({
elements,
rect,
offsetParent,
strategy
}) : rect);
return {
top: (clippingClientRect.top - elementClientRect.top + paddingObject.top) / offsetScale.y,
bottom: (elementClientRect.bottom - clippingClientRect.bottom + paddingObject.bottom) / offsetScale.y,
left: (clippingClientRect.left - elementClientRect.left + paddingObject.left) / offsetScale.x,
right: (elementClientRect.right - clippingClientRect.right + paddingObject.right) / offsetScale.x
};
}
var flip = function(options) {
if (options === void 0) {
options = {};
}
return {
name: "flip",
options,
async fn(state2) {
var _middlewareData$arrow, _middlewareData$flip;
const {
placement,
middlewareData,
rects,
initialPlacement,
platform: platform2,
elements
} = state2;
const {
mainAxis: checkMainAxis = true,
crossAxis: checkCrossAxis = true,
fallbackPlacements: specifiedFallbackPlacements,
fallbackStrategy = "bestFit",
fallbackAxisSideDirection = "none",
flipAlignment = true,
...detectOverflowOptions
} = evaluate(options, state2);
if ((_middlewareData$arrow = middlewareData.arrow) != null && _middlewareData$arrow.alignmentOffset) {
return {};
}
const side = getSide(placement);
const initialSideAxis = getSideAxis(initialPlacement);
const isBasePlacement = getSide(initialPlacement) === initialPlacement;
const rtl = await (platform2.isRTL == null ? void 0 : platform2.isRTL(elements.floating));
const fallbackPlacements = specifiedFallbackPlacements || (isBasePlacement || !flipAlignment ? [getOppositePlacement(initialPlacement)] : getExpandedPlacements(initialPlacement));
const hasFallbackAxisSideDirection = fallbackAxisSideDirection !== "none";
if (!specifiedFallbackPlacements && hasFallbackAxisSideDirection) {
fallbackPlacements.push(...getOppositeAxisPlacements(initialPlacement, flipAlignment, fallbackAxisSideDirection, rtl));
}
const placements2 = [initialPlacement, ...fallbackPlacements];
const overflow = await detectOverflow(state2, detectOverflowOptions);
const overflows = [];
let overflowsData = ((_middlewareData$flip = middlewareData.flip) == null ? void 0 : _middlewareData$flip.overflows) || [];
if (checkMainAxis) {
overflows.push(overflow[side]);
}
if (checkCrossAxis) {
const sides2 = getAlignmentSides(placement, rects, rtl);
overflows.push(overflow[sides2[0]], overflow[sides2[1]]);
}
overflowsData = [...overflowsData, {
placement,
overflows
}];
if (!overflows.every((side2) => side2 <= 0)) {
var _middlewareData$flip2, _overflowsData$filter;
const nextIndex = (((_middlewareData$flip2 = middlewareData.flip) == null ? void 0 : _middlewareData$flip2.index) || 0) + 1;
const nextPlacement = placements2[nextIndex];
if (nextPlacement) {
const ignoreCrossAxisOverflow = checkCrossAxis === "alignment" ? initialSideAxis !== getSideAxis(nextPlacement) : false;
if (!ignoreCrossAxisOverflow || // We leave the current main axis only if every placement on that axis
// overflows the main axis.
overflowsData.every((d) => getSideAxis(d.placement) === initialSideAxis ? d.overflows[0] > 0 : true)) {
return {
data: {
index: nextIndex,
overflows: overflowsData
},
reset: {
placement: nextPlacement
}
};
}
}
let resetPlacement = (_overflowsData$filter = overflowsData.filter((d) => d.overflows[0] <= 0).sort((a, b) => a.overflows[1] - b.overflows[1])[0]) == null ? void 0 : _overflowsData$filter.placement;
if (!resetPlacement) {
switch (fallbackStrategy) {
case "bestFit": {
var _overflowsData$filter2;
const placement2 = (_overflowsData$filter2 = overflowsData.filter((d) => {
if (hasFallbackAxisSideDirection) {
const currentSideAxis = getSideAxis(d.placement);
return currentSideAxis === initialSideAxis || // Create a bias to the `y` side axis due to horizontal
// reading directions favoring greater width.
currentSideAxis === "y";
}
return true;
}).map((d) => [d.placement, d.overflows.filter((overflow2) => overflow2 > 0).reduce((acc, overflow2) => acc + overflow2, 0)]).sort((a, b) => a[1] - b[1])[0]) == null ? void 0 : _overflowsData$filter2[0];
if (placement2) {
resetPlacement = placement2;
}
break;
}
case "initialPlacement":
resetPlacement = initialPlacement;
break;
}
}
if (placement !== resetPlacement) {
return {
reset: {
placement: resetPlacement
}
};
}
}
return {};
}
};
};
var originSides = /* @__PURE__ */ new Set(["left", "top"]);
async function convertValueToCoords(state2, options) {
const {
placement,
platform: platform2,
elements
} = state2;
const rtl = await (platform2.isRTL == null ? void 0 : platform2.isRTL(elements.floating));
const side = getSide(placement);
const alignment = getAlignment(placement);
const isVertical = getSideAxis(placement) === "y";
const mainAxisMulti = originSides.has(side) ? -1 : 1;
const crossAxisMulti = rtl && isVertical ? -1 : 1;
const rawValue = evaluate(options, state2);
let {
mainAxis,
crossAxis,
alignmentAxis
} = typeof rawValue === "number" ? {
mainAxis: rawValue,
crossAxis: 0,
alignmentAxis: null
} : {
mainAxis: rawValue.mainAxis || 0,
crossAxis: rawValue.crossAxis || 0,
alignmentAxis: rawValue.alignmentAxis
};
if (alignment && typeof alignmentAxis === "number") {
crossAxis = alignment === "end" ? alignmentAxis * -1 : alignmentAxis;
}
return isVertical ? {
x: crossAxis * crossAxisMulti,
y: mainAxis * mainAxisMulti
} : {
x: mainAxis * mainAxisMulti,
y: crossAxis * crossAxisMulti
};
}
var offset = function(options) {
if (options === void 0) {
options = 0;
}
return {
name: "offset",
options,
async fn(state2) {
var _middlewareData$offse, _middlewareData$arrow;
const {
x,
y,
placement,
middlewareData
} = state2;
const diffCoords = await convertValueToCoords(state2, options);
if (placement === ((_middlewareData$offse = middlewareData.offset) == null ? void 0 : _middlewareData$offse.placement) && (_middlewareData$arrow = middlewareData.arrow) != null && _middlewareData$arrow.alignmentOffset) {
return {};
}
return {
x: x + diffCoords.x,
y: y + diffCoords.y,
data: {
...diffCoords,
placement
}
};
}
};
};
// node_modules/@floating-ui/utils/dist/floating-ui.utils.dom.mjs
function hasWindow() {
return typeof window !== "undefined";
}
function getNodeName(node) {
if (isNode(node)) {
return (node.nodeName || "").toLowerCase();
}
return "#document";
}
function getWindow(node) {
var _node$ownerDocument;
return (node == null || (_node$ownerDocument = node.ownerDocument) == null ? void 0 : _node$ownerDocument.defaultView) || window;
}
function getDocumentElement(node) {
var _ref;
return (_ref = (isNode(node) ? node.ownerDocument : node.document) || window.document) == null ? void 0 : _ref.documentElement;
}
function isNode(value) {
if (!hasWindow()) {
return false;
}
return value instanceof Node || value instanceof getWindow(value).Node;
}
function isElement(value) {
if (!hasWindow()) {
return false;
}
return value instanceof Element || value instanceof getWindow(value).Element;
}
function isHTMLElement(value) {
if (!hasWindow()) {
return false;
}
return value instanceof HTMLElement || value instanceof getWindow(value).HTMLElement;
}
function isShadowRoot(value) {
if (!hasWindow() || typeof ShadowRoot === "undefined") {
return false;
}
return value instanceof ShadowRoot || value instanceof getWindow(value).ShadowRoot;
}
var invalidOverflowDisplayValues = /* @__PURE__ */ new Set(["inline", "contents"]);
function isOverflowElement(element) {
const {
overflow,
overflowX,
overflowY,
display
} = getComputedStyle2(element);
return /auto|scroll|overlay|hidden|clip/.test(overflow + overflowY + overflowX) && !invalidOverflowDisplayValues.has(display);
}
var tableElements = /* @__PURE__ */ new Set(["table", "td", "th"]);
function isTableElement(element) {
return tableElements.has(getNodeName(element));
}
var topLayerSelectors = [":popover-open", ":modal"];
function isTopLayer(element) {
return topLayerSelectors.some((selector) => {
try {
return element.matches(selector);
} catch (_e) {
return false;
}
});
}
var transformProperties = ["transform", "translate", "scale", "rotate", "perspective"];
var willChangeValues = ["transform", "translate", "scale", "rotate", "perspective", "filter"];
var containValues = ["paint", "layout", "strict", "content"];
function isContainingBlock(elementOrCss) {
const webkit = isWebKit();
const css = isElement(elementOrCss) ? getComputedStyle2(elementOrCss) : elementOrCss;
return transformProperties.some((value) => css[value] ? css[value] !== "none" : false) || (css.containerType ? css.containerType !== "normal" : false) || !webkit && (css.backdropFilter ? css.backdropFilter !== "none" : false) || !webkit && (css.filter ? css.filter !== "none" : false) || willChangeValues.some((value) => (css.willChange || "").includes(value)) || containValues.some((value) => (css.contain || "").includes(value));
}
function getContainingBlock(element) {
let currentNode = getParentNode(element);
while (isHTMLElement(currentNode) && !isLastTraversableNode(currentNode)) {
if (isContainingBlock(currentNode)) {
return currentNode;
} else if (isTopLayer(currentNode)) {
return null;
}
currentNode = getParentNode(currentNode);
}
return null;
}
function isWebKit() {
if (typeof CSS === "undefined" || !CSS.supports) return false;
return CSS.supports("-webkit-backdrop-filter", "none");
}
var lastTraversableNodeNames = /* @__PURE__ */ new Set(["html", "body", "#document"]);
function isLastTraversableNode(node) {
return lastTraversableNodeNames.has(getNodeName(node));
}
function getComputedStyle2(element) {
return getWindow(element).getComputedStyle(element);
}
function getNodeScroll(element) {
if (isElement(element)) {
return {
scrollLeft: element.scrollLeft,
scrollTop: element.scrollTop
};
}
return {
scrollLeft: element.scrollX,
scrollTop: element.scrollY
};
}
function getParentNode(node) {
if (getNodeName(node) === "html") {
return node;
}
const result = (
// Step into the shadow DOM of the parent of a slotted node.
node.assignedSlot || // DOM Element detected.
node.parentNode || // ShadowRoot detected.
isShadowRoot(node) && node.host || // Fallback.
getDocumentElement(node)
);
return isShadowRoot(result) ? result.host : result;
}
function getNearestOverflowAncestor(node) {
const parentNode = getParentNode(node);
if (isLastTraversableNode(parentNode)) {
return node.ownerDocument ? node.ownerDocument.body : node.body;
}
if (isHTMLElement(parentNode) && isOverflowElement(parentNode)) {
return parentNode;
}
return getNearestOverflowAncestor(parentNode);
}
function getOverflowAncestors(node, list, traverseIframes) {
var _node$ownerDocument2;
if (list === void 0) {
list = [];
}
if (traverseIframes === void 0) {
traverseIframes = true;
}
const scrollableAncestor = getNearestOverflowAncestor(node);
const isBody = scrollableAncestor === ((_node$ownerDocument2 = node.ownerDocument) == null ? void 0 : _node$ownerDocument2.body);
const win = getWindow(scrollableAncestor);
if (isBody) {
const frameElement = getFrameElement(win);
return list.concat(win, win.visualViewport || [], isOverflowElement(scrollableAncestor) ? scrollableAncestor : [], frameElement && traverseIframes ? getOverflowAncestors(frameElement) : []);
}
return list.concat(scrollableAncestor, getOverflowAncestors(scrollableAncestor, [], traverseIframes));
}
function getFrameElement(win) {
return win.parent && Object.getPrototypeOf(win.parent) ? win.frameElement : null;
}
// node_modules/@floating-ui/dom/dist/floating-ui.dom.mjs
function getCssDimensions(element) {
const css = getComputedStyle2(element);
let width = parseFloat(css.width) || 0;
let height = parseFloat(css.height) || 0;
const hasOffset = isHTMLElement(element);
const offsetWidth = hasOffset ? element.offsetWidth : width;
const offsetHeight = hasOffset ? element.offsetHeight : height;
const shouldFallback = round(width) !== offsetWidth || round(height) !== offsetHeight;
if (shouldFallback) {
width = offsetWidth;
height = offsetHeight;
}
return {
width,
height,
$: shouldFallback
};
}
function unwrapElement(element) {
return !isElement(element) ? element.contextElement : element;
}
function getScale(element) {
const domElement = unwrapElement(element);
if (!isHTMLElement(domElement)) {
return createCoords(1);
}
const rect = domElement.getBoundingClientRect();
const {
width,
height,
$
} = getCssDimensions(domElement);
let x = ($ ? round(rect.width) : rect.width) / width;
let y = ($ ? round(rect.height) : rect.height) / height;
if (!x || !Number.isFinite(x)) {
x = 1;
}
if (!y || !Number.isFinite(y)) {
y = 1;
}
return {
x,
y
};
}
var noOffsets = /* @__PURE__ */ createCoords(0);
function getVisualOffsets(element) {
const win = getWindow(element);
if (!isWebKit() || !win.visualViewport) {
return noOffsets;
}
return {
x: win.visualViewport.offsetLeft,
y: win.visualViewport.offsetTop
};
}
function shouldAddVisualOffsets(element, isFixed, floatingOffsetParent) {
if (isFixed === void 0) {
isFixed = false;
}
if (!floatingOffsetParent || isFixed && floatingOffsetParent !== getWindow(element)) {
return false;
}
return isFixed;
}
function getBoundingClientRect(element, includeScale, isFixedStrategy, offsetParent) {
if (includeScale === void 0) {
includeScale = false;
}
if (isFixedStrategy === void 0) {
isFixedStrategy = false;
}
const clientRect = element.getBoundingClientRect();
const domElement = unwrapElement(element);
let scale = createCoords(1);
if (includeScale) {
if (offsetParent) {
if (isElement(offsetParent)) {
scale = getScale(offsetParent);
}
} else {
scale = getScale(element);
}
}
const visualOffsets = shouldAddVisualOffsets(domElement, isFixedStrategy, offsetParent) ? getVisualOffsets(domElement) : createCoords(0);
let x = (clientRect.left + visualOffsets.x) / scale.x;
let y = (clientRect.top + visualOffsets.y) / scale.y;
let width = clientRect.width / scale.x;
let height = clientRect.height / scale.y;
if (domElement) {
const win = getWindow(domElement);
const offsetWin = offsetParent && isElement(offsetParent) ? getWindow(offsetParent) : offsetParent;
let currentWin = win;
let currentIFrame = getFrameElement(currentWin);
while (currentIFrame && offsetParent && offsetWin !== currentWin) {
const iframeScale = getScale(currentIFrame);
const iframeRect = currentIFrame.getBoundingClientRect();
const css = getComputedStyle2(currentIFrame);
const left = iframeRect.left + (currentIFrame.clientLeft + parseFloat(css.paddingLeft)) * iframeScale.x;
const top = iframeRect.top + (currentIFrame.clientTop + parseFloat(css.paddingTop)) * iframeScale.y;
x *= iframeScale.x;
y *= iframeScale.y;
width *= iframeScale.x;
height *= iframeScale.y;
x += left;
y += top;
currentWin = getWindow(currentIFrame);
currentIFrame = getFrameElement(currentWin);
}
}
return rectToClientRect({
width,
height,
x,
y
});
}
function getWindowScrollBarX(element, rect) {
const leftScroll = getNodeScroll(element).scrollLeft;
if (!rect) {
return getBoundingClientRect(getDocumentElement(element)).left + leftScroll;
}
return rect.left + leftScroll;
}
function getHTMLOffset(documentElement, scroll) {
const htmlRect = documentElement.getBoundingClientRect();
const x = htmlRect.left + scroll.scrollLeft - getWindowScrollBarX(documentElement, htmlRect);
const y = htmlRect.top + scroll.scrollTop;
return {
x,
y
};
}
function convertOffsetParentRelativeRectToViewportRelativeRect(_ref) {
let {
elements,
rect,
offsetParent,
strategy
} = _ref;
const isFixed = strategy === "fixed";
const documentElement = getDocumentElement(offsetParent);
const topLayer = elements ? isTopLayer(elements.floating) : false;
if (offsetParent === documentElement || topLayer && isFixed) {
return rect;
}
let scroll = {
scrollLeft: 0,
scrollTop: 0
};
let scale = createCoords(1);
const offsets = createCoords(0);
const isOffsetParentAnElement = isHTMLElement(offsetParent);
if (isOffsetParentAnElement || !isOffsetParentAnElement && !isFixed) {
if (getNodeName(offsetParent) !== "body" || isOverflowElement(documentElement)) {
scroll = getNodeScroll(offsetParent);
}
if (isHTMLElement(offsetParent)) {
const offsetRect = getBoundingClientRect(offsetParent);
scale = getScale(offsetParent);
offsets.x = offsetRect.x + offsetParent.clientLeft;
offsets.y = offsetRect.y + offsetParent.clientTop;
}
}
const htmlOffset = documentElement && !isOffsetParentAnElement && !isFixed ? getHTMLOffset(documentElement, scroll) : createCoords(0);
return {
width: rect.width * scale.x,
height: rect.height * scale.y,
x: rect.x * scale.x - scroll.scrollLeft * scale.x + offsets.x + htmlOffset.x,
y: rect.y * scale.y - scroll.scrollTop * scale.y + offsets.y + htmlOffset.y
};
}
function getClientRects(element) {
return Array.from(element.getClientRects());
}
function getDocumentRect(element) {
const html = getDocumentElement(element);
const scroll = getNodeScroll(element);
const body = element.ownerDocument.body;
const width = max(html.scrollWidth, html.clientWidth, body.scrollWidth, body.clientWidth);
const height = max(html.scrollHeight, html.clientHeight, body.scrollHeight, body.clientHeight);
let x = -scroll.scrollLeft + getWindowScrollBarX(element);
const y = -scroll.scrollTop;
if (getComputedStyle2(body).direction === "rtl") {
x += max(html.clientWidth, body.clientWidth) - width;
}
return {
width,
height,
x,
y
};
}
var SCROLLBAR_MAX = 25;
function getViewportRect(element, strategy) {
const win = getWindow(element);
const html = getDocumentElement(element);
const visualViewport = win.visualViewport;
let width = html.clientWidth;
let height = html.clientHeight;
let x = 0;
let y = 0;
if (visualViewport) {
width = visualViewport.width;
height = visualViewport.height;
const visualViewportBased = isWebKit();
if (!visualViewportBased || visualViewportBased && strategy === "fixed") {
x = visualViewport.offsetLeft;
y = visualViewport.offsetTop;
}
}
const windowScrollbarX = getWindowScrollBarX(html);
if (windowScrollbarX <= 0) {
const doc = html.ownerDocument;
const body = doc.body;
const bodyStyles = getComputedStyle(body);
const bodyMarginInline = doc.compatMode === "CSS1Compat" ? parseFloat(bodyStyles.marginLeft) + parseFloat(bodyStyles.marginRight) || 0 : 0;
const clippingStableScrollbarWidth = Math.abs(html.clientWidth - body.clientWidth - bodyMarginInline);
if (clippingStableScrollbarWidth <= SCROLLBAR_MAX) {
width -= clippingStableScrollbarWidth;
}
} else if (windowScrollbarX <= SCROLLBAR_MAX) {
width += windowScrollbarX;
}
return {
width,
height,
x,
y
};
}
var absoluteOrFixed = /* @__PURE__ */ new Set(["absolute", "fixed"]);
function getInnerBoundingClientRect(element, strategy) {
const clientRect = getBoundingClientRect(element, true, strategy === "fixed");
const top = clientRect.top + element.clientTop;
const left = clientRect.left + element.clientLeft;
const scale = isHTMLElement(element) ? getScale(element) : createCoords(1);
const width = element.clientWidth * scale.x;
const height = element.clientHeight * scale.y;
const x = left * scale.x;
const y = top * scale.y;
return {
width,
height,
x,
y
};
}
function getClientRectFromClippingAncestor(element, clippingAncestor, strategy) {
let rect;
if (clippingAncestor === "viewport") {
rect = getViewportRect(element, strategy);
} else if (clippingAncestor === "document") {
rect = getDocumentRect(getDocumentElement(element));
} else if (isElement(clippingAncestor)) {
rect = getInnerBoundingClientRect(clippingAncestor, strategy);
} else {
const visualOffsets = getVisualOffsets(element);
rect = {
x: clippingAncestor.x - visualOffsets.x,
y: clippingAncestor.y - visualOffsets.y,
width: clippingAncestor.width,
height: clippingAncestor.height
};
}
return rectToClientRect(rect);
}
function hasFixedPositionAncestor(element, stopNode) {
const parentNode = getParentNode(element);
if (parentNode === stopNode || !isElement(parentNode) || isLastTraversableNode(parentNode)) {
return false;
}
return getComputedStyle2(parentNode).position === "fixed" || hasFixedPositionAncestor(parentNode, stopNode);
}
function getClippingElementAncestors(element, cache) {
const cachedResult = cache.get(element);
if (cachedResult) {
return cachedResult;
}
let result = getOverflowAncestors(element, [], false).filter((el) => isElement(el) && getNodeName(el) !== "body");
let currentContainingBlockComputedStyle = null;
const elementIsFixed = getComputedStyle2(element).position === "fixed";
let currentNode = elementIsFixed ? getParentNode(element) : element;
while (isElement(currentNode) && !isLastTraversableNode(currentNode)) {
const computedStyle = getComputedStyle2(currentNode);
const currentNodeIsContaining = isContainingBlock(currentNode);
if (!currentNodeIsContaining && computedStyle.position === "fixed") {
currentContainingBlockComputedStyle = null;
}
const shouldDropCurrentNode = elementIsFixed ? !currentNodeIsContaining && !currentContainingBlockComputedStyle : !currentNodeIsContaining && computedStyle.position === "static" && !!currentContainingBlockComputedStyle && absoluteOrFixed.has(currentContainingBlockComputedStyle.position) || isOverflowElement(currentNode) && !currentNodeIsContaining && hasFixedPositionAncestor(element, currentNode);
if (shouldDropCurrentNode) {
result = result.filter((ancestor) => ancestor !== currentNode);
} else {
currentContainingBlockComputedStyle = computedStyle;
}
currentNode = getParentNode(currentNode);
}
cache.set(element, result);
return result;
}
function getClippingRect(_ref) {
let {
element,
boundary,
rootBoundary,
strategy
} = _ref;
const elementClippingAncestors = boundary === "clippingAncestors" ? isTopLayer(element) ? [] : getClippingElementAncestors(element, this._c) : [].concat(boundary);
const clippingAncestors = [...elementClippingAncestors, rootBoundary];
const firstClippingAncestor = clippingAncestors[0];
const clippingRect = clippingAncestors.reduce((accRect, clippingAncestor) => {
const rect = getClientRectFromClippingAncestor(element, clippingAncestor, strategy);
accRect.top = max(rect.top, accRect.top);
accRect.right = min(rect.right, accRect.right);
accRect.bottom = min(rect.bottom, accRect.bottom);
accRect.left = max(rect.left, accRect.left);
return accRect;
}, getClientRectFromClippingAncestor(element, firstClippingAncestor, strategy));
return {
width: clippingRect.right - clippingRect.left,
height: clippingRect.bottom - clippingRect.top,
x: clippingRect.left,
y: clippingRect.top
};
}
function getDimensions(element) {
const {
width,
height
} = getCssDimensions(element);
return {
width,
height
};
}
function getRectRelativeToOffsetParent(element, offsetParent, strategy) {
const isOffsetParentAnElement = isHTMLElement(offsetParent);
const documentElement = getDocumentElement(offsetParent);
const isFixed = strategy === "fixed";
const rect = getBoundingClientRect(element, true, isFixed, offsetParent);
let scroll = {
scrollLeft: 0,
scrollTop: 0
};
const offsets = createCoords(0);
function setLeftRTLScrollbarOffset() {
offsets.x = getWindowScrollBarX(documentElement);
}
if (isOffsetParentAnElement || !isOffsetParentAnElement && !isFixed) {
if (getNodeName(offsetParent) !== "body" || isOverflowElement(documentElement)) {
scroll = getNodeScroll(offsetParent);
}
if (isOffsetParentAnElement) {
const offsetRect = getBoundingClientRect(offsetParent, true, isFixed, offsetParent);
offsets.x = offsetRect.x + offsetParent.clientLeft;
offsets.y = offsetRect.y + offsetParent.clientTop;
} else if (documentElement) {
setLeftRTLScrollbarOffset();
}
}
if (isFixed && !isOffsetParentAnElement && documentElement) {
setLeftRTLScrollbarOffset();
}
const htmlOffset = documentElement && !isOffsetParentAnElement && !isFixed ? getHTMLOffset(documentElement, scroll) : createCoords(0);
const x = rect.left + scroll.scrollLeft - offsets.x - htmlOffset.x;
const y = rect.top + scroll.scrollTop - offsets.y - htmlOffset.y;
return {
x,
y,
width: rect.width,
height: rect.height
};
}
function isStaticPositioned(element) {
return getComputedStyle2(element).position === "static";
}
function getTrueOffsetParent(element, polyfill) {
if (!isHTMLElement(element) || getComputedStyle2(element).position === "fixed") {
return null;
}
if (polyfill) {
return polyfill(element);
}
let rawOffsetParent = element.offsetParent;
if (getDocumentElement(element) === rawOffsetParent) {
rawOffsetParent = rawOffsetParent.ownerDocument.body;
}
return rawOffsetParent;
}
function getOffsetParent(element, polyfill) {
const win = getWindow(element);
if (isTopLayer(element)) {
return win;
}
if (!isHTMLElement(element)) {
let svgOffsetParent = getParentNode(element);
while (svgOffsetParent && !isLastTraversableNode(svgOffsetParent)) {
if (isElement(svgOffsetParent) && !isStaticPositioned(svgOffsetParent)) {
return svgOffsetParent;
}
svgOffsetParent = getParentNode(svgOffsetParent);
}
return win;
}
let offsetParent = getTrueOffsetParent(element, polyfill);
while (offsetParent && isTableElement(offsetParent) && isStaticPositioned(offsetParent)) {
offsetParent = getTrueOffsetParent(offsetParent, polyfill);
}
if (offsetParent && isLastTraversableNode(offsetParent) && isStaticPositioned(offsetParent) && !isContainingBlock(offsetParent)) {
return win;
}
return offsetParent || getContainingBlock(element) || win;
}
var getElementRects = async function(data) {
const getOffsetParentFn = this.getOffsetParent || getOffsetParent;
const getDimensionsFn = this.getDimensions;
const floatingDimensions = await getDimensionsFn(data.floating);
return {
reference: getRectRelativeToOffsetParent(data.reference, await getOffsetParentFn(data.floating), data.strategy),
floating: {
x: 0,
y: 0,
width: floatingDimensions.width,
height: floatingDimensions.height
}
};
};
function isRTL(element) {
return getComputedStyle2(element).direction === "rtl";
}
var platform = {
convertOffsetParentRelativeRectToViewportRelativeRect,
getDocumentElement,
getClippingRect,
getOffsetParent,
getElementRects,
getClientRects,
getDimensions,
getScale,
isElement,
isRTL
};
function rectsAreEqual(a, b) {
return a.x === b.x && a.y === b.y && a.width === b.width && a.height === b.height;
}
function observeMove(element, onMove) {
let io = null;
let timeoutId;
const root = getDocumentElement(element);
function cleanup() {
var _io;
clearTimeout(timeoutId);
(_io = io) == null || _io.disconnect();
io = null;
}
function refresh(skip, threshold) {
if (skip === void 0) {
skip = false;
}
if (threshold === void 0) {
threshold = 1;
}
cleanup();
const elementRectForRootMargin = element.getBoundingClientRect();
const {
left,
top,
width,
height
} = elementRectForRootMargin;
if (!skip) {
onMove();
}
if (!width || !height) {
return;
}
const insetTop = floor(top);
const insetRight = floor(root.clientWidth - (left + width));
const insetBottom = floor(root.clientHeight - (top + height));
const insetLeft = floor(left);
const rootMargin = -insetTop + "px " + -insetRight + "px " + -insetBottom + "px " + -insetLeft + "px";
const options = {
rootMargin,
threshold: max(0, min(1, threshold)) || 1
};
let isFirstUpdate = true;
function handleObserve(entries) {
const ratio = entries[0].intersectionRatio;
if (ratio !== threshold) {
if (!isFirstUpdate) {
return refresh();
}
if (!ratio) {
timeoutId = setTimeout(() => {
refresh(false, 1e-7);
}, 1e3);
} else {
refresh(false, ratio);
}
}
if (ratio === 1 && !rectsAreEqual(elementRectForRootMargin, element.getBoundingClientRect())) {
refresh();
}
isFirstUpdate = false;
}
try {
io = new IntersectionObserver(handleObserve, {
...options,
// Handle