(() => {
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __commonJS = (cb, mod) => function __require() {
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
};
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 __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
// If the importer is in node compatibility mode or this is not an ESM
// file that has been converted to a CommonJS file using a Babel-
// compatible transform (i.e. "__esModule" has not been set), then set
// "default" to the CommonJS "module.exports" for node compatibility.
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
mod
));
// node_modules/lodash.debounce/index.js
var require_lodash = __commonJS({
"node_modules/lodash.debounce/index.js"(exports, module) {
var FUNC_ERROR_TEXT = "Expected a function";
var NAN = 0 / 0;
var symbolTag = "[object Symbol]";
var reTrim = /^\s+|\s+$/g;
var reIsBadHex = /^[-+]0x[0-9a-f]+$/i;
var reIsBinary = /^0b[01]+$/i;
var reIsOctal = /^0o[0-7]+$/i;
var freeParseInt = parseInt;
var freeGlobal = typeof global == "object" && global && global.Object === Object && global;
var freeSelf = typeof self == "object" && self && self.Object === Object && self;
var root = freeGlobal || freeSelf || Function("return this")();
var objectProto = Object.prototype;
var objectToString = objectProto.toString;
var nativeMax = Math.max;
var nativeMin = Math.min;
var now = function() {
return root.Date.now();
};
function debounce4(func, wait, options) {
var lastArgs, lastThis, maxWait, result, timerId, lastCallTime, lastInvokeTime = 0, leading = false, maxing = false, trailing = true;
if (typeof func != "function") {
throw new TypeError(FUNC_ERROR_TEXT);
}
wait = toNumber(wait) || 0;
if (isObject(options)) {
leading = !!options.leading;
maxing = "maxWait" in options;
maxWait = maxing ? nativeMax(toNumber(options.maxWait) || 0, wait) : maxWait;
trailing = "trailing" in options ? !!options.trailing : trailing;
}
function invokeFunc(time) {
var args = lastArgs, thisArg = lastThis;
lastArgs = lastThis = void 0;
lastInvokeTime = time;
result = func.apply(thisArg, args);
return result;
}
function leadingEdge(time) {
lastInvokeTime = time;
timerId = setTimeout(timerExpired, wait);
return leading ? invokeFunc(time) : result;
}
function remainingWait(time) {
var timeSinceLastCall = time - lastCallTime, timeSinceLastInvoke = time - lastInvokeTime, result2 = wait - timeSinceLastCall;
return maxing ? nativeMin(result2, maxWait - timeSinceLastInvoke) : result2;
}
function shouldInvoke(time) {
var timeSinceLastCall = time - lastCallTime, timeSinceLastInvoke = time - lastInvokeTime;
return lastCallTime === void 0 || timeSinceLastCall >= wait || timeSinceLastCall < 0 || maxing && timeSinceLastInvoke >= maxWait;
}
function timerExpired() {
var time = now();
if (shouldInvoke(time)) {
return trailingEdge(time);
}
timerId = setTimeout(timerExpired, remainingWait(time));
}
function trailingEdge(time) {
timerId = void 0;
if (trailing && lastArgs) {
return invokeFunc(time);
}
lastArgs = lastThis = void 0;
return result;
}
function cancel() {
if (timerId !== void 0) {
clearTimeout(timerId);
}
lastInvokeTime = 0;
lastArgs = lastCallTime = lastThis = timerId = void 0;
}
function flush() {
return timerId === void 0 ? result : trailingEdge(now());
}
function debounced() {
var time = now(), isInvoking = shouldInvoke(time);
lastArgs = arguments;
lastThis = this;
lastCallTime = time;
if (isInvoking) {
if (timerId === void 0) {
return leadingEdge(lastCallTime);
}
if (maxing) {
timerId = setTimeout(timerExpired, wait);
return invokeFunc(lastCallTime);
}
}
if (timerId === void 0) {
timerId = setTimeout(timerExpired, wait);
}
return result;
}
debounced.cancel = cancel;
debounced.flush = flush;
return debounced;
}
function isObject(value) {
var type = typeof value;
return !!value && (type == "object" || type == "function");
}
function isObjectLike(value) {
return !!value && typeof value == "object";
}
function isSymbol(value) {
return typeof value == "symbol" || isObjectLike(value) && objectToString.call(value) == symbolTag;
}
function toNumber(value) {
if (typeof value == "number") {
return value;
}
if (isSymbol(value)) {
return NAN;
}
if (isObject(value)) {
var other = typeof value.valueOf == "function" ? value.valueOf() : value;
value = isObject(other) ? other + "" : other;
}
if (typeof value != "string") {
return value === 0 ? value : +value;
}
value = value.replace(reTrim, "");
var isBinary = reIsBinary.test(value);
return isBinary || reIsOctal.test(value) ? freeParseInt(value.slice(2), isBinary ? 2 : 8) : reIsBadHex.test(value) ? NAN : +value;
}
module.exports = debounce4;
}
});
// node_modules/@hotwired/stimulus/dist/stimulus.js
var EventListener = class {
constructor(eventTarget, eventName, eventOptions) {
this.eventTarget = eventTarget;
this.eventName = eventName;
this.eventOptions = eventOptions;
this.unorderedBindings = /* @__PURE__ */ new Set();
}
connect() {
this.eventTarget.addEventListener(this.eventName, this, this.eventOptions);
}
disconnect() {
this.eventTarget.removeEventListener(this.eventName, this, this.eventOptions);
}
bindingConnected(binding) {
this.unorderedBindings.add(binding);
}
bindingDisconnected(binding) {
this.unorderedBindings.delete(binding);
}
handleEvent(event) {
const extendedEvent = extendEvent(event);
for (const binding of this.bindings) {
if (extendedEvent.immediatePropagationStopped) {
break;
} else {
binding.handleEvent(extendedEvent);
}
}
}
hasBindings() {
return this.unorderedBindings.size > 0;
}
get bindings() {
return Array.from(this.unorderedBindings).sort((left2, right2) => {
const leftIndex = left2.index, rightIndex = right2.index;
return leftIndex < rightIndex ? -1 : leftIndex > rightIndex ? 1 : 0;
});
}
};
function extendEvent(event) {
if ("immediatePropagationStopped" in event) {
return event;
} else {
const { stopImmediatePropagation } = event;
return Object.assign(event, {
immediatePropagationStopped: false,
stopImmediatePropagation() {
this.immediatePropagationStopped = true;
stopImmediatePropagation.call(this);
}
});
}
}
var Dispatcher = class {
constructor(application2) {
this.application = application2;
this.eventListenerMaps = /* @__PURE__ */ new Map();
this.started = false;
}
start() {
if (!this.started) {
this.started = true;
this.eventListeners.forEach((eventListener) => eventListener.connect());
}
}
stop() {
if (this.started) {
this.started = false;
this.eventListeners.forEach((eventListener) => eventListener.disconnect());
}
}
get eventListeners() {
return Array.from(this.eventListenerMaps.values()).reduce((listeners, map) => listeners.concat(Array.from(map.values())), []);
}
bindingConnected(binding) {
this.fetchEventListenerForBinding(binding).bindingConnected(binding);
}
bindingDisconnected(binding, clearEventListeners = false) {
this.fetchEventListenerForBinding(binding).bindingDisconnected(binding);
if (clearEventListeners)
this.clearEventListenersForBinding(binding);
}
handleError(error2, message, detail = {}) {
this.application.handleError(error2, `Error ${message}`, detail);
}
clearEventListenersForBinding(binding) {
const eventListener = this.fetchEventListenerForBinding(binding);
if (!eventListener.hasBindings()) {
eventListener.disconnect();
this.removeMappedEventListenerFor(binding);
}
}
removeMappedEventListenerFor(binding) {
const { eventTarget, eventName, eventOptions } = binding;
const eventListenerMap = this.fetchEventListenerMapForEventTarget(eventTarget);
const cacheKey = this.cacheKey(eventName, eventOptions);
eventListenerMap.delete(cacheKey);
if (eventListenerMap.size == 0)
this.eventListenerMaps.delete(eventTarget);
}
fetchEventListenerForBinding(binding) {
const { eventTarget, eventName, eventOptions } = binding;
return this.fetchEventListener(eventTarget, eventName, eventOptions);
}
fetchEventListener(eventTarget, eventName, eventOptions) {
const eventListenerMap = this.fetchEventListenerMapForEventTarget(eventTarget);
const cacheKey = this.cacheKey(eventName, eventOptions);
let eventListener = eventListenerMap.get(cacheKey);
if (!eventListener) {
eventListener = this.createEventListener(eventTarget, eventName, eventOptions);
eventListenerMap.set(cacheKey, eventListener);
}
return eventListener;
}
createEventListener(eventTarget, eventName, eventOptions) {
const eventListener = new EventListener(eventTarget, eventName, eventOptions);
if (this.started) {
eventListener.connect();
}
return eventListener;
}
fetchEventListenerMapForEventTarget(eventTarget) {
let eventListenerMap = this.eventListenerMaps.get(eventTarget);
if (!eventListenerMap) {
eventListenerMap = /* @__PURE__ */ new Map();
this.eventListenerMaps.set(eventTarget, eventListenerMap);
}
return eventListenerMap;
}
cacheKey(eventName, eventOptions) {
const parts = [eventName];
Object.keys(eventOptions).sort().forEach((key) => {
parts.push(`${eventOptions[key] ? "" : "!"}${key}`);
});
return parts.join(":");
}
};
var defaultActionDescriptorFilters = {
stop({ event, value }) {
if (value)
event.stopPropagation();
return true;
},
prevent({ event, value }) {
if (value)
event.preventDefault();
return true;
},
self({ event, value, element }) {
if (value) {
return element === event.target;
} else {
return true;
}
}
};
var descriptorPattern = /^(?:(?:([^.]+?)\+)?(.+?)(?:\.(.+?))?(?:@(window|document))?->)?(.+?)(?:#([^:]+?))(?::(.+))?$/;
function parseActionDescriptorString(descriptorString) {
const source = descriptorString.trim();
const matches = source.match(descriptorPattern) || [];
let eventName = matches[2];
let keyFilter = matches[3];
if (keyFilter && !["keydown", "keyup", "keypress"].includes(eventName)) {
eventName += `.${keyFilter}`;
keyFilter = "";
}
return {
eventTarget: parseEventTarget(matches[4]),
eventName,
eventOptions: matches[7] ? parseEventOptions(matches[7]) : {},
identifier: matches[5],
methodName: matches[6],
keyFilter: matches[1] || keyFilter
};
}
function parseEventTarget(eventTargetName) {
if (eventTargetName == "window") {
return window;
} else if (eventTargetName == "document") {
return document;
}
}
function parseEventOptions(eventOptions) {
return eventOptions.split(":").reduce((options, token) => Object.assign(options, { [token.replace(/^!/, "")]: !/^!/.test(token) }), {});
}
function stringifyEventTarget(eventTarget) {
if (eventTarget == window) {
return "window";
} else if (eventTarget == document) {
return "document";
}
}
function camelize(value) {
return value.replace(/(?:[_-])([a-z0-9])/g, (_, char) => char.toUpperCase());
}
function namespaceCamelize(value) {
return camelize(value.replace(/--/g, "-").replace(/__/g, "_"));
}
function capitalize(value) {
return value.charAt(0).toUpperCase() + value.slice(1);
}
function dasherize(value) {
return value.replace(/([A-Z])/g, (_, char) => `-${char.toLowerCase()}`);
}
function tokenize(value) {
return value.match(/[^\s]+/g) || [];
}
function isSomething(object) {
return object !== null && object !== void 0;
}
function hasProperty(object, property) {
return Object.prototype.hasOwnProperty.call(object, property);
}
var allModifiers = ["meta", "ctrl", "alt", "shift"];
var Action = class {
constructor(element, index, descriptor, schema) {
this.element = element;
this.index = index;
this.eventTarget = descriptor.eventTarget || element;
this.eventName = descriptor.eventName || getDefaultEventNameForElement(element) || error("missing event name");
this.eventOptions = descriptor.eventOptions || {};
this.identifier = descriptor.identifier || error("missing identifier");
this.methodName = descriptor.methodName || error("missing method name");
this.keyFilter = descriptor.keyFilter || "";
this.schema = schema;
}
static forToken(token, schema) {
return new this(token.element, token.index, parseActionDescriptorString(token.content), schema);
}
toString() {
const eventFilter = this.keyFilter ? `.${this.keyFilter}` : "";
const eventTarget = this.eventTargetName ? `@${this.eventTargetName}` : "";
return `${this.eventName}${eventFilter}${eventTarget}->${this.identifier}#${this.methodName}`;
}
shouldIgnoreKeyboardEvent(event) {
if (!this.keyFilter) {
return false;
}
const filters = this.keyFilter.split("+");
if (this.keyFilterDissatisfied(event, filters)) {
return true;
}
const standardFilter = filters.filter((key) => !allModifiers.includes(key))[0];
if (!standardFilter) {
return false;
}
if (!hasProperty(this.keyMappings, standardFilter)) {
error(`contains unknown key filter: ${this.keyFilter}`);
}
return this.keyMappings[standardFilter].toLowerCase() !== event.key.toLowerCase();
}
shouldIgnoreMouseEvent(event) {
if (!this.keyFilter) {
return false;
}
const filters = [this.keyFilter];
if (this.keyFilterDissatisfied(event, filters)) {
return true;
}
return false;
}
get params() {
const params = {};
const pattern = new RegExp(`^data-${this.identifier}-(.+)-param$`, "i");
for (const { name, value } of Array.from(this.element.attributes)) {
const match = name.match(pattern);
const key = match && match[1];
if (key) {
params[camelize(key)] = typecast(value);
}
}
return params;
}
get eventTargetName() {
return stringifyEventTarget(this.eventTarget);
}
get keyMappings() {
return this.schema.keyMappings;
}
keyFilterDissatisfied(event, filters) {
const [meta, ctrl, alt, shift] = allModifiers.map((modifier) => filters.includes(modifier));
return event.metaKey !== meta || event.ctrlKey !== ctrl || event.altKey !== alt || event.shiftKey !== shift;
}
};
var defaultEventNames = {
a: () => "click",
button: () => "click",
form: () => "submit",
details: () => "toggle",
input: (e) => e.getAttribute("type") == "submit" ? "click" : "input",
select: () => "change",
textarea: () => "input"
};
function getDefaultEventNameForElement(element) {
const tagName = element.tagName.toLowerCase();
if (tagName in defaultEventNames) {
return defaultEventNames[tagName](element);
}
}
function error(message) {
throw new Error(message);
}
function typecast(value) {
try {
return JSON.parse(value);
} catch (o_O) {
return value;
}
}
var Binding = class {
constructor(context, action) {
this.context = context;
this.action = action;
}
get index() {
return this.action.index;
}
get eventTarget() {
return this.action.eventTarget;
}
get eventOptions() {
return this.action.eventOptions;
}
get identifier() {
return this.context.identifier;
}
handleEvent(event) {
const actionEvent = this.prepareActionEvent(event);
if (this.willBeInvokedByEvent(event) && this.applyEventModifiers(actionEvent)) {
this.invokeWithEvent(actionEvent);
}
}
get eventName() {
return this.action.eventName;
}
get method() {
const method = this.controller[this.methodName];
if (typeof method == "function") {
return method;
}
throw new Error(`Action "${this.action}" references undefined method "${this.methodName}"`);
}
applyEventModifiers(event) {
const { element } = this.action;
const { actionDescriptorFilters } = this.context.application;
const { controller } = this.context;
let passes = true;
for (const [name, value] of Object.entries(this.eventOptions)) {
if (name in actionDescriptorFilters) {
const filter = actionDescriptorFilters[name];
passes = passes && filter({ name, value, event, element, controller });
} else {
continue;
}
}
return passes;
}
prepareActionEvent(event) {
return Object.assign(event, { params: this.action.params });
}
invokeWithEvent(event) {
const { target, currentTarget } = event;
try {
this.method.call(this.controller, event);
this.context.logDebugActivity(this.methodName, { event, target, currentTarget, action: this.methodName });
} catch (error2) {
const { identifier, controller, element, index } = this;
const detail = { identifier, controller, element, index, event };
this.context.handleError(error2, `invoking action "${this.action}"`, detail);
}
}
willBeInvokedByEvent(event) {
const eventTarget = event.target;
if (event instanceof KeyboardEvent && this.action.shouldIgnoreKeyboardEvent(event)) {
return false;
}
if (event instanceof MouseEvent && this.action.shouldIgnoreMouseEvent(event)) {
return false;
}
if (this.element === eventTarget) {
return true;
} else if (eventTarget instanceof Element && this.element.contains(eventTarget)) {
return this.scope.containsElement(eventTarget);
} else {
return this.scope.containsElement(this.action.element);
}
}
get controller() {
return this.context.controller;
}
get methodName() {
return this.action.methodName;
}
get element() {
return this.scope.element;
}
get scope() {
return this.context.scope;
}
};
var ElementObserver = class {
constructor(element, delegate) {
this.mutationObserverInit = { attributes: true, childList: true, subtree: true };
this.element = element;
this.started = false;
this.delegate = delegate;
this.elements = /* @__PURE__ */ new Set();
this.mutationObserver = new MutationObserver((mutations) => this.processMutations(mutations));
}
start() {
if (!this.started) {
this.started = true;
this.mutationObserver.observe(this.element, this.mutationObserverInit);
this.refresh();
}
}
pause(callback) {
if (this.started) {
this.mutationObserver.disconnect();
this.started = false;
}
callback();
if (!this.started) {
this.mutationObserver.observe(this.element, this.mutationObserverInit);
this.started = true;
}
}
stop() {
if (this.started) {
this.mutationObserver.takeRecords();
this.mutationObserver.disconnect();
this.started = false;
}
}
refresh() {
if (this.started) {
const matches = new Set(this.matchElementsInTree());
for (const element of Array.from(this.elements)) {
if (!matches.has(element)) {
this.removeElement(element);
}
}
for (const element of Array.from(matches)) {
this.addElement(element);
}
}
}
processMutations(mutations) {
if (this.started) {
for (const mutation of mutations) {
this.processMutation(mutation);
}
}
}
processMutation(mutation) {
if (mutation.type == "attributes") {
this.processAttributeChange(mutation.target, mutation.attributeName);
} else if (mutation.type == "childList") {
this.processRemovedNodes(mutation.removedNodes);
this.processAddedNodes(mutation.addedNodes);
}
}
processAttributeChange(element, attributeName) {
if (this.elements.has(element)) {
if (this.delegate.elementAttributeChanged && this.matchElement(element)) {
this.delegate.elementAttributeChanged(element, attributeName);
} else {
this.removeElement(element);
}
} else if (this.matchElement(element)) {
this.addElement(element);
}
}
processRemovedNodes(nodes) {
for (const node of Array.from(nodes)) {
const element = this.elementFromNode(node);
if (element) {
this.processTree(element, this.removeElement);
}
}
}
processAddedNodes(nodes) {
for (const node of Array.from(nodes)) {
const element = this.elementFromNode(node);
if (element && this.elementIsActive(element)) {
this.processTree(element, this.addElement);
}
}
}
matchElement(element) {
return this.delegate.matchElement(element);
}
matchElementsInTree(tree = this.element) {
return this.delegate.matchElementsInTree(tree);
}
processTree(tree, processor) {
for (const element of this.matchElementsInTree(tree)) {
processor.call(this, element);
}
}
elementFromNode(node) {
if (node.nodeType == Node.ELEMENT_NODE) {
return node;
}
}
elementIsActive(element) {
if (element.isConnected != this.element.isConnected) {
return false;
} else {
return this.element.contains(element);
}
}
addElement(element) {
if (!this.elements.has(element)) {
if (this.elementIsActive(element)) {
this.elements.add(element);
if (this.delegate.elementMatched) {
this.delegate.elementMatched(element);
}
}
}
}
removeElement(element) {
if (this.elements.has(element)) {
this.elements.delete(element);
if (this.delegate.elementUnmatched) {
this.delegate.elementUnmatched(element);
}
}
}
};
var AttributeObserver = class {
constructor(element, attributeName, delegate) {
this.attributeName = attributeName;
this.delegate = delegate;
this.elementObserver = new ElementObserver(element, this);
}
get element() {
return this.elementObserver.element;
}
get selector() {
return `[${this.attributeName}]`;
}
start() {
this.elementObserver.start();
}
pause(callback) {
this.elementObserver.pause(callback);
}
stop() {
this.elementObserver.stop();
}
refresh() {
this.elementObserver.refresh();
}
get started() {
return this.elementObserver.started;
}
matchElement(element) {
return element.hasAttribute(this.attributeName);
}
matchElementsInTree(tree) {
const match = this.matchElement(tree) ? [tree] : [];
const matches = Array.from(tree.querySelectorAll(this.selector));
return match.concat(matches);
}
elementMatched(element) {
if (this.delegate.elementMatchedAttribute) {
this.delegate.elementMatchedAttribute(element, this.attributeName);
}
}
elementUnmatched(element) {
if (this.delegate.elementUnmatchedAttribute) {
this.delegate.elementUnmatchedAttribute(element, this.attributeName);
}
}
elementAttributeChanged(element, attributeName) {
if (this.delegate.elementAttributeValueChanged && this.attributeName == attributeName) {
this.delegate.elementAttributeValueChanged(element, attributeName);
}
}
};
function add(map, key, value) {
fetch(map, key).add(value);
}
function del(map, key, value) {
fetch(map, key).delete(value);
prune(map, key);
}
function fetch(map, key) {
let values = map.get(key);
if (!values) {
values = /* @__PURE__ */ new Set();
map.set(key, values);
}
return values;
}
function prune(map, key) {
const values = map.get(key);
if (values != null && values.size == 0) {
map.delete(key);
}
}
var Multimap = class {
constructor() {
this.valuesByKey = /* @__PURE__ */ new Map();
}
get keys() {
return Array.from(this.valuesByKey.keys());
}
get values() {
const sets = Array.from(this.valuesByKey.values());
return sets.reduce((values, set) => values.concat(Array.from(set)), []);
}
get size() {
const sets = Array.from(this.valuesByKey.values());
return sets.reduce((size, set) => size + set.size, 0);
}
add(key, value) {
add(this.valuesByKey, key, value);
}
delete(key, value) {
del(this.valuesByKey, key, value);
}
has(key, value) {
const values = this.valuesByKey.get(key);
return values != null && values.has(value);
}
hasKey(key) {
return this.valuesByKey.has(key);
}
hasValue(value) {
const sets = Array.from(this.valuesByKey.values());
return sets.some((set) => set.has(value));
}
getValuesForKey(key) {
const values = this.valuesByKey.get(key);
return values ? Array.from(values) : [];
}
getKeysForValue(value) {
return Array.from(this.valuesByKey).filter(([_key, values]) => values.has(value)).map(([key, _values]) => key);
}
};
var SelectorObserver = class {
constructor(element, selector, delegate, details) {
this._selector = selector;
this.details = details;
this.elementObserver = new ElementObserver(element, this);
this.delegate = delegate;
this.matchesByElement = new Multimap();
}
get started() {
return this.elementObserver.started;
}
get selector() {
return this._selector;
}
set selector(selector) {
this._selector = selector;
this.refresh();
}
start() {
this.elementObserver.start();
}
pause(callback) {
this.elementObserver.pause(callback);
}
stop() {
this.elementObserver.stop();
}
refresh() {
this.elementObserver.refresh();
}
get element() {
return this.elementObserver.element;
}
matchElement(element) {
const { selector } = this;
if (selector) {
const matches = element.matches(selector);
if (this.delegate.selectorMatchElement) {
return matches && this.delegate.selectorMatchElement(element, this.details);
}
return matches;
} else {
return false;
}
}
matchElementsInTree(tree) {
const { selector } = this;
if (selector) {
const match = this.matchElement(tree) ? [tree] : [];
const matches = Array.from(tree.querySelectorAll(selector)).filter((match2) => this.matchElement(match2));
return match.concat(matches);
} else {
return [];
}
}
elementMatched(element) {
const { selector } = this;
if (selector) {
this.selectorMatched(element, selector);
}
}
elementUnmatched(element) {
const selectors = this.matchesByElement.getKeysForValue(element);
for (const selector of selectors) {
this.selectorUnmatched(element, selector);
}
}
elementAttributeChanged(element, _attributeName) {
const { selector } = this;
if (selector) {
const matches = this.matchElement(element);
const matchedBefore = this.matchesByElement.has(selector, element);
if (matches && !matchedBefore) {
this.selectorMatched(element, selector);
} else if (!matches && matchedBefore) {
this.selectorUnmatched(element, selector);
}
}
}
selectorMatched(element, selector) {
this.delegate.selectorMatched(element, selector, this.details);
this.matchesByElement.add(selector, element);
}
selectorUnmatched(element, selector) {
this.delegate.selectorUnmatched(element, selector, this.details);
this.matchesByElement.delete(selector, element);
}
};
var StringMapObserver = class {
constructor(element, delegate) {
this.element = element;
this.delegate = delegate;
this.started = false;
this.stringMap = /* @__PURE__ */ new Map();
this.mutationObserver = new MutationObserver((mutations) => this.processMutations(mutations));
}
start() {
if (!this.started) {
this.started = true;
this.mutationObserver.observe(this.element, { attributes: true, attributeOldValue: true });
this.refresh();
}
}
stop() {
if (this.started) {
this.mutationObserver.takeRecords();
this.mutationObserver.disconnect();
this.started = false;
}
}
refresh() {
if (this.started) {
for (const attributeName of this.knownAttributeNames) {
this.refreshAttribute(attributeName, null);
}
}
}
processMutations(mutations) {
if (this.started) {
for (const mutation of mutations) {
this.processMutation(mutation);
}
}
}
processMutation(mutation) {
const attributeName = mutation.attributeName;
if (attributeName) {
this.refreshAttribute(attributeName, mutation.oldValue);
}
}
refreshAttribute(attributeName, oldValue) {
const key = this.delegate.getStringMapKeyForAttribute(attributeName);
if (key != null) {
if (!this.stringMap.has(attributeName)) {
this.stringMapKeyAdded(key, attributeName);
}
const value = this.element.getAttribute(attributeName);
if (this.stringMap.get(attributeName) != value) {
this.stringMapValueChanged(value, key, oldValue);
}
if (value == null) {
const oldValue2 = this.stringMap.get(attributeName);
this.stringMap.delete(attributeName);
if (oldValue2)
this.stringMapKeyRemoved(key, attributeName, oldValue2);
} else {
this.stringMap.set(attributeName, value);
}
}
}
stringMapKeyAdded(key, attributeName) {
if (this.delegate.stringMapKeyAdded) {
this.delegate.stringMapKeyAdded(key, attributeName);
}
}
stringMapValueChanged(value, key, oldValue) {
if (this.delegate.stringMapValueChanged) {
this.delegate.stringMapValueChanged(value, key, oldValue);
}
}
stringMapKeyRemoved(key, attributeName, oldValue) {
if (this.delegate.stringMapKeyRemoved) {
this.delegate.stringMapKeyRemoved(key, attributeName, oldValue);
}
}
get knownAttributeNames() {
return Array.from(new Set(this.currentAttributeNames.concat(this.recordedAttributeNames)));
}
get currentAttributeNames() {
return Array.from(this.element.attributes).map((attribute) => attribute.name);
}
get recordedAttributeNames() {
return Array.from(this.stringMap.keys());
}
};
var TokenListObserver = class {
constructor(element, attributeName, delegate) {
this.attributeObserver = new AttributeObserver(element, attributeName, this);
this.delegate = delegate;
this.tokensByElement = new Multimap();
}
get started() {
return this.attributeObserver.started;
}
start() {
this.attributeObserver.start();
}
pause(callback) {
this.attributeObserver.pause(callback);
}
stop() {
this.attributeObserver.stop();
}
refresh() {
this.attributeObserver.refresh();
}
get element() {
return this.attributeObserver.element;
}
get attributeName() {
return this.attributeObserver.attributeName;
}
elementMatchedAttribute(element) {
this.tokensMatched(this.readTokensForElement(element));
}
elementAttributeValueChanged(element) {
const [unmatchedTokens, matchedTokens] = this.refreshTokensForElement(element);
this.tokensUnmatched(unmatchedTokens);
this.tokensMatched(matchedTokens);
}
elementUnmatchedAttribute(element) {
this.tokensUnmatched(this.tokensByElement.getValuesForKey(element));
}
tokensMatched(tokens) {
tokens.forEach((token) => this.tokenMatched(token));
}
tokensUnmatched(tokens) {
tokens.forEach((token) => this.tokenUnmatched(token));
}
tokenMatched(token) {
this.delegate.tokenMatched(token);
this.tokensByElement.add(token.element, token);
}
tokenUnmatched(token) {
this.delegate.tokenUnmatched(token);
this.tokensByElement.delete(token.element, token);
}
refreshTokensForElement(element) {
const previousTokens = this.tokensByElement.getValuesForKey(element);
const currentTokens = this.readTokensForElement(element);
const firstDifferingIndex = zip(previousTokens, currentTokens).findIndex(([previousToken, currentToken]) => !tokensAreEqual(previousToken, currentToken));
if (firstDifferingIndex == -1) {
return [[], []];
} else {
return [previousTokens.slice(firstDifferingIndex), currentTokens.slice(firstDifferingIndex)];
}
}
readTokensForElement(element) {
const attributeName = this.attributeName;
const tokenString = element.getAttribute(attributeName) || "";
return parseTokenString(tokenString, element, attributeName);
}
};
function parseTokenString(tokenString, element, attributeName) {
return tokenString.trim().split(/\s+/).filter((content) => content.length).map((content, index) => ({ element, attributeName, content, index }));
}
function zip(left2, right2) {
const length = Math.max(left2.length, right2.length);
return Array.from({ length }, (_, index) => [left2[index], right2[index]]);
}
function tokensAreEqual(left2, right2) {
return left2 && right2 && left2.index == right2.index && left2.content == right2.content;
}
var ValueListObserver = class {
constructor(element, attributeName, delegate) {
this.tokenListObserver = new TokenListObserver(element, attributeName, this);
this.delegate = delegate;
this.parseResultsByToken = /* @__PURE__ */ new WeakMap();
this.valuesByTokenByElement = /* @__PURE__ */ new WeakMap();
}
get started() {
return this.tokenListObserver.started;
}
start() {
this.tokenListObserver.start();
}
stop() {
this.tokenListObserver.stop();
}
refresh() {
this.tokenListObserver.refresh();
}
get element() {
return this.tokenListObserver.element;
}
get attributeName() {
return this.tokenListObserver.attributeName;
}
tokenMatched(token) {
const { element } = token;
const { value } = this.fetchParseResultForToken(token);
if (value) {
this.fetchValuesByTokenForElement(element).set(token, value);
this.delegate.elementMatchedValue(element, value);
}
}
tokenUnmatched(token) {
const { element } = token;
const { value } = this.fetchParseResultForToken(token);
if (value) {
this.fetchValuesByTokenForElement(element).delete(token);
this.delegate.elementUnmatchedValue(element, value);
}
}
fetchParseResultForToken(token) {
let parseResult = this.parseResultsByToken.get(token);
if (!parseResult) {
parseResult = this.parseToken(token);
this.parseResultsByToken.set(token, parseResult);
}
return parseResult;
}
fetchValuesByTokenForElement(element) {
let valuesByToken = this.valuesByTokenByElement.get(element);
if (!valuesByToken) {
valuesByToken = /* @__PURE__ */ new Map();
this.valuesByTokenByElement.set(element, valuesByToken);
}
return valuesByToken;
}
parseToken(token) {
try {
const value = this.delegate.parseValueForToken(token);
return { value };
} catch (error2) {
return { error: error2 };
}
}
};
var BindingObserver = class {
constructor(context, delegate) {
this.context = context;
this.delegate = delegate;
this.bindingsByAction = /* @__PURE__ */ new Map();
}
start() {
if (!this.valueListObserver) {
this.valueListObserver = new ValueListObserver(this.element, this.actionAttribute, this);
this.valueListObserver.start();
}
}
stop() {
if (this.valueListObserver) {
this.valueListObserver.stop();
delete this.valueListObserver;
this.disconnectAllActions();
}
}
get element() {
return this.context.element;
}
get identifier() {
return this.context.identifier;
}
get actionAttribute() {
return this.schema.actionAttribute;
}
get schema() {
return this.context.schema;
}
get bindings() {
return Array.from(this.bindingsByAction.values());
}
connectAction(action) {
const binding = new Binding(this.context, action);
this.bindingsByAction.set(action, binding);
this.delegate.bindingConnected(binding);
}
disconnectAction(action) {
const binding = this.bindingsByAction.get(action);
if (binding) {
this.bindingsByAction.delete(action);
this.delegate.bindingDisconnected(binding);
}
}
disconnectAllActions() {
this.bindings.forEach((binding) => this.delegate.bindingDisconnected(binding, true));
this.bindingsByAction.clear();
}
parseValueForToken(token) {
const action = Action.forToken(token, this.schema);
if (action.identifier == this.identifier) {
return action;
}
}
elementMatchedValue(element, action) {
this.connectAction(action);
}
elementUnmatchedValue(element, action) {
this.disconnectAction(action);
}
};
var ValueObserver = class {
constructor(context, receiver) {
this.context = context;
this.receiver = receiver;
this.stringMapObserver = new StringMapObserver(this.element, this);
this.valueDescriptorMap = this.controller.valueDescriptorMap;
}
start() {
this.stringMapObserver.start();
this.invokeChangedCallbacksForDefaultValues();
}
stop() {
this.stringMapObserver.stop();
}
get element() {
return this.context.element;
}
get controller() {
return this.context.controller;
}
getStringMapKeyForAttribute(attributeName) {
if (attributeName in this.valueDescriptorMap) {
return this.valueDescriptorMap[attributeName].name;
}
}
stringMapKeyAdded(key, attributeName) {
const descriptor = this.valueDescriptorMap[attributeName];
if (!this.hasValue(key)) {
this.invokeChangedCallback(key, descriptor.writer(this.receiver[key]), descriptor.writer(descriptor.defaultValue));
}
}
stringMapValueChanged(value, name, oldValue) {
const descriptor = this.valueDescriptorNameMap[name];
if (value === null)
return;
if (oldValue === null) {
oldValue = descriptor.writer(descriptor.defaultValue);
}
this.invokeChangedCallback(name, value, oldValue);
}
stringMapKeyRemoved(key, attributeName, oldValue) {
const descriptor = this.valueDescriptorNameMap[key];
if (this.hasValue(key)) {
this.invokeChangedCallback(key, descriptor.writer(this.receiver[key]), oldValue);
} else {
this.invokeChangedCallback(key, descriptor.writer(descriptor.defaultValue), oldValue);
}
}
invokeChangedCallbacksForDefaultValues() {
for (const { key, name, defaultValue, writer } of this.valueDescriptors) {
if (defaultValue != void 0 && !this.controller.data.has(key)) {
this.invokeChangedCallback(name, writer(defaultValue), void 0);
}
}
}
invokeChangedCallback(name, rawValue, rawOldValue) {
const changedMethodName = `${name}Changed`;
const changedMethod = this.receiver[changedMethodName];
if (typeof changedMethod == "function") {
const descriptor = this.valueDescriptorNameMap[name];
try {
const value = descriptor.reader(rawValue);
let oldValue = rawOldValue;
if (rawOldValue) {
oldValue = descriptor.reader(rawOldValue);
}
changedMethod.call(this.receiver, value, oldValue);
} catch (error2) {
if (error2 instanceof TypeError) {
error2.message = `Stimulus Value "${this.context.identifier}.${descriptor.name}" - ${error2.message}`;
}
throw error2;
}
}
}
get valueDescriptors() {
const { valueDescriptorMap } = this;
return Object.keys(valueDescriptorMap).map((key) => valueDescriptorMap[key]);
}
get valueDescriptorNameMap() {
const descriptors = {};
Object.keys(this.valueDescriptorMap).forEach((key) => {
const descriptor = this.valueDescriptorMap[key];
descriptors[descriptor.name] = descriptor;
});
return descriptors;
}
hasValue(attributeName) {
const descriptor = this.valueDescriptorNameMap[attributeName];
const hasMethodName = `has${capitalize(descriptor.name)}`;
return this.receiver[hasMethodName];
}
};
var TargetObserver = class {
constructor(context, delegate) {
this.context = context;
this.delegate = delegate;
this.targetsByName = new Multimap();
}
start() {
if (!this.tokenListObserver) {
this.tokenListObserver = new TokenListObserver(this.element, this.attributeName, this);
this.tokenListObserver.start();
}
}
stop() {
if (this.tokenListObserver) {
this.disconnectAllTargets();
this.tokenListObserver.stop();
delete this.tokenListObserver;
}
}
tokenMatched({ element, content: name }) {
if (this.scope.containsElement(element)) {
this.connectTarget(element, name);
}
}
tokenUnmatched({ element, content: name }) {
this.disconnectTarget(element, name);
}
connectTarget(element, name) {
var _a;
if (!this.targetsByName.has(name, element)) {
this.targetsByName.add(name, element);
(_a = this.tokenListObserver) === null || _a === void 0 ? void 0 : _a.pause(() => this.delegate.targetConnected(element, name));
}
}
disconnectTarget(element, name) {
var _a;
if (this.targetsByName.has(name, element)) {
this.targetsByName.delete(name, element);
(_a = this.tokenListObserver) === null || _a === void 0 ? void 0 : _a.pause(() => this.delegate.targetDisconnected(element, name));
}
}
disconnectAllTargets() {
for (const name of this.targetsByName.keys) {
for (const element of this.targetsByName.getValuesForKey(name)) {
this.disconnectTarget(element, name);
}
}
}
get attributeName() {
return `data-${this.context.identifier}-target`;
}
get element() {
return this.context.element;
}
get scope() {
return this.context.scope;
}
};
function readInheritableStaticArrayValues(constructor, propertyName) {
const ancestors = getAncestorsForConstructor(constructor);
return Array.from(ancestors.reduce((values, constructor2) => {
getOwnStaticArrayValues(constructor2, propertyName).forEach((name) => values.add(name));
return values;
}, /* @__PURE__ */ new Set()));
}
function readInheritableStaticObjectPairs(constructor, propertyName) {
const ancestors = getAncestorsForConstructor(constructor);
return ancestors.reduce((pairs, constructor2) => {
pairs.push(...getOwnStaticObjectPairs(constructor2, propertyName));
return pairs;
}, []);
}
function getAncestorsForConstructor(constructor) {
const ancestors = [];
while (constructor) {
ancestors.push(constructor);
constructor = Object.getPrototypeOf(constructor);
}
return ancestors.reverse();
}
function getOwnStaticArrayValues(constructor, propertyName) {
const definition = constructor[propertyName];
return Array.isArray(definition) ? definition : [];
}
function getOwnStaticObjectPairs(constructor, propertyName) {
const definition = constructor[propertyName];
return definition ? Object.keys(definition).map((key) => [key, definition[key]]) : [];
}
var OutletObserver = class {
constructor(context, delegate) {
this.started = false;
this.context = context;
this.delegate = delegate;
this.outletsByName = new Multimap();
this.outletElementsByName = new Multimap();
this.selectorObserverMap = /* @__PURE__ */ new Map();
this.attributeObserverMap = /* @__PURE__ */ new Map();
}
start() {
if (!this.started) {
this.outletDefinitions.forEach((outletName) => {
this.setupSelectorObserverForOutlet(outletName);
this.setupAttributeObserverForOutlet(outletName);
});
this.started = true;
this.dependentContexts.forEach((context) => context.refresh());
}
}
refresh() {
this.selectorObserverMap.forEach((observer) => observer.refresh());
this.attributeObserverMap.forEach((observer) => observer.refresh());
}
stop() {
if (this.started) {
this.started = false;
this.disconnectAllOutlets();
this.stopSelectorObservers();
this.stopAttributeObservers();
}
}
stopSelectorObservers() {
if (this.selectorObserverMap.size > 0) {
this.selectorObserverMap.forEach((observer) => observer.stop());
this.selectorObserverMap.clear();
}
}
stopAttributeObservers() {
if (this.attributeObserverMap.size > 0) {
this.attributeObserverMap.forEach((observer) => observer.stop());
this.attributeObserverMap.clear();
}
}
selectorMatched(element, _selector, { outletName }) {
const outlet = this.getOutlet(element, outletName);
if (outlet) {
this.connectOutlet(outlet, element, outletName);
}
}
selectorUnmatched(element, _selector, { outletName }) {
const outlet = this.getOutletFromMap(element, outletName);
if (outlet) {
this.disconnectOutlet(outlet, element, outletName);
}
}
selectorMatchElement(element, { outletName }) {
const selector = this.selector(outletName);
const hasOutlet = this.hasOutlet(element, outletName);
const hasOutletController = element.matches(`[${this.schema.controllerAttribute}~=${outletName}]`);
if (selector) {
return hasOutlet && hasOutletController && element.matches(selector);
} else {
return false;
}
}
elementMatchedAttribute(_element, attributeName) {
const outletName = this.getOutletNameFromOutletAttributeName(attributeName);
if (outletName) {
this.updateSelectorObserverForOutlet(outletName);
}
}
elementAttributeValueChanged(_element, attributeName) {
const outletName = this.getOutletNameFromOutletAttributeName(attributeName);
if (outletName) {
this.updateSelectorObserverForOutlet(outletName);
}
}
elementUnmatchedAttribute(_element, attributeName) {
const outletName = this.getOutletNameFromOutletAttributeName(attributeName);
if (outletName) {
this.updateSelectorObserverForOutlet(outletName);
}
}
connectOutlet(outlet, element, outletName) {
var _a;
if (!this.outletElementsByName.has(outletName, element)) {
this.outletsByName.add(outletName, outlet);
this.outletElementsByName.add(outletName, element);
(_a = this.selectorObserverMap.get(outletName)) === null || _a === void 0 ? void 0 : _a.pause(() => this.delegate.outletConnected(outlet, element, outletName));
}
}
disconnectOutlet(outlet, element, outletName) {
var _a;
if (this.outletElementsByName.has(outletName, element)) {
this.outletsByName.delete(outletName, outlet);
this.outletElementsByName.delete(outletName, element);
(_a = this.selectorObserverMap.get(outletName)) === null || _a === void 0 ? void 0 : _a.pause(() => this.delegate.outletDisconnected(outlet, element, outletName));
}
}
disconnectAllOutlets() {
for (const outletName of this.outletElementsByName.keys) {
for (const element of this.outletElementsByName.getValuesForKey(outletName)) {
for (const outlet of this.outletsByName.getValuesForKey(outletName)) {
this.disconnectOutlet(outlet, element, outletName);
}
}
}
}
updateSelectorObserverForOutlet(outletName) {
const observer = this.selectorObserverMap.get(outletName);
if (observer) {
observer.selector = this.selector(outletName);
}
}
setupSelectorObserverForOutlet(outletName) {
const selector = this.selector(outletName);
const selectorObserver = new SelectorObserver(document.body, selector, this, { outletName });
this.selectorObserverMap.set(outletName, selectorObserver);
selectorObserver.start();
}
setupAttributeObserverForOutlet(outletName) {
const attributeName = this.attributeNameForOutletName(outletName);
const attributeObserver = new AttributeObserver(this.scope.element, attributeName, this);
this.attributeObserverMap.set(outletName, attributeObserver);
attributeObserver.start();
}
selector(outletName) {
return this.scope.outlets.getSelectorForOutletName(outletName);
}
attributeNameForOutletName(outletName) {
return this.scope.schema.outletAttributeForScope(this.identifier, outletName);
}
getOutletNameFromOutletAttributeName(attributeName) {
return this.outletDefinitions.find((outletName) => this.attributeNameForOutletName(outletName) === attributeName);
}
get outletDependencies() {
const dependencies = new Multimap();
this.router.modules.forEach((module) => {
const constructor = module.definition.controllerConstructor;
const outlets = readInheritableStaticArrayValues(constructor, "outlets");
outlets.forEach((outlet) => dependencies.add(outlet, module.identifier));
});
return dependencies;
}
get outletDefinitions() {
return this.outletDependencies.getKeysForValue(this.identifier);
}
get dependentControllerIdentifiers() {
return this.outletDependencies.getValuesForKey(this.identifier);
}
get dependentContexts() {
const identifiers = this.dependentControllerIdentifiers;
return this.router.contexts.filter((context) => identifiers.includes(context.identifier));
}
hasOutlet(element, outletName) {
return !!this.getOutlet(element, outletName) || !!this.getOutletFromMap(element, outletName);
}
getOutlet(element, outletName) {
return this.application.getControllerForElementAndIdentifier(element, outletName);
}
getOutletFromMap(element, outletName) {
return this.outletsByName.getValuesForKey(outletName).find((outlet) => outlet.element === element);
}
get scope() {
return this.context.scope;
}
get schema() {
return this.context.schema;
}
get identifier() {
return this.context.identifier;
}
get application() {
return this.context.application;
}
get router() {
return this.application.router;
}
};
var Context = class {
constructor(module, scope) {
this.logDebugActivity = (functionName, detail = {}) => {
const { identifier, controller, element } = this;
detail = Object.assign({ identifier, controller, element }, detail);
this.application.logDebugActivity(this.identifier, functionName, detail);
};
this.module = module;
this.scope = scope;
this.controller = new module.controllerConstructor(this);
this.bindingObserver = new BindingObserver(this, this.dispatcher);
this.valueObserver = new ValueObserver(this, this.controller);
this.targetObserver = new TargetObserver(this, this);
this.outletObserver = new OutletObserver(this, this);
try {
this.controller.initialize();
this.logDebugActivity("initialize");
} catch (error2) {
this.handleError(error2, "initializing controller");
}
}
connect() {
this.bindingObserver.start();
this.valueObserver.start();
this.targetObserver.start();
this.outletObserver.start();
try {
this.controller.connect();
this.logDebugActivity("connect");
} catch (error2) {
this.handleError(error2, "connecting controller");
}
}
refresh() {
this.outletObserver.refresh();
}
disconnect() {
try {
this.controller.disconnect();
this.logDebugActivity("disconnect");
} catch (error2) {
this.handleError(error2, "disconnecting controller");
}
this.outletObserver.stop();
this.targetObserver.stop();
this.valueObserver.stop();
this.bindingObserver.stop();
}
get application() {
return this.module.application;
}
get identifier() {
return this.module.identifier;
}
get schema() {
return this.application.schema;
}
get dispatcher() {
return this.application.dispatcher;
}
get element() {
return this.scope.element;
}
get parentElement() {
return this.element.parentElement;
}
handleError(error2, message, detail = {}) {
const { identifier, controller, element } = this;
detail = Object.assign({ identifier, controller, element }, detail);
this.application.handleError(error2, `Error ${message}`, detail);
}
targetConnected(element, name) {
this.invokeControllerMethod(`${name}TargetConnected`, element);
}
targetDisconnected(element, name) {
this.invokeControllerMethod(`${name}TargetDisconnected`, element);
}
outletConnected(outlet, element, name) {
this.invokeControllerMethod(`${namespaceCamelize(name)}OutletConnected`, outlet, element);
}
outletDisconnected(outlet, element, name) {
this.invokeControllerMethod(`${namespaceCamelize(name)}OutletDisconnected`, outlet, element);
}
invokeControllerMethod(methodName, ...args) {
const controller = this.controller;
if (typeof controller[methodName] == "function") {
controller[methodName](...args);
}
}
};
function bless(constructor) {
return shadow(constructor, getBlessedProperties(constructor));
}
function shadow(constructor, properties) {
const shadowConstructor = extend(constructor);
const shadowProperties = getShadowProperties(constructor.prototype, properties);
Object.defineProperties(shadowConstructor.prototype, shadowProperties);
return shadowConstructor;
}
function getBlessedProperties(constructor) {
const blessings = readInheritableStaticArrayValues(constructor, "blessings");
return blessings.reduce((blessedProperties, blessing) => {
const properties = blessing(constructor);
for (const key in properties) {
const descriptor = blessedProperties[key] || {};
blessedProperties[key] = Object.assign(descriptor, properties[key]);
}
return blessedProperties;
}, {});
}
function getShadowProperties(prototype, properties) {
return getOwnKeys(properties).reduce((shadowProperties, key) => {
const descriptor = getShadowedDescriptor(prototype, properties, key);
if (descriptor) {
Object.assign(shadowProperties, { [key]: descriptor });
}
return shadowProperties;
}, {});
}
function getShadowedDescriptor(prototype, properties, key) {
const shadowingDescriptor = Object.getOwnPropertyDescriptor(prototype, key);
const shadowedByValue = shadowingDescriptor && "value" in shadowingDescriptor;
if (!shadowedByValue) {
const descriptor = Object.getOwnPropertyDescriptor(properties, key).value;
if (shadowingDescriptor) {
descriptor.get = shadowingDescriptor.get || descriptor.get;
descriptor.set = shadowingDescriptor.set || descriptor.set;
}
return descriptor;
}
}
var getOwnKeys = (() => {
if (typeof Object.getOwnPropertySymbols == "function") {
return (object) => [...Object.getOwnPropertyNames(object), ...Object.getOwnPropertySymbols(object)];
} else {
return Object.getOwnPropertyNames;
}
})();
var extend = (() => {
function extendWithReflect(constructor) {
function extended() {
return Reflect.construct(constructor, arguments, new.target);
}
extended.prototype = Object.create(constructor.prototype, {
constructor: { value: extended }
});
Reflect.setPrototypeOf(extended, constructor);
return extended;
}
function testReflectExtension() {
const a = function() {
this.a.call(this);
};
const b = extendWithReflect(a);
b.prototype.a = function() {
};
return new b();
}
try {
testReflectExtension();
return extendWithReflect;
} catch (error2) {
return (constructor) => class extended extends constructor {
};
}
})();
function blessDefinition(definition) {
return {
identifier: definition.identifier,
controllerConstructor: bless(definition.controllerConstructor)
};
}
var Module = class {
constructor(application2, definition) {
this.application = application2;
this.definition = blessDefinition(definition);
this.contextsByScope = /* @__PURE__ */ new WeakMap();
this.connectedContexts = /* @__PURE__ */ new Set();
}
get identifier() {
return this.definition.identifier;
}
get controllerConstructor() {
return this.definition.controllerConstructor;
}
get contexts() {
return Array.from(this.connectedContexts);
}
connectContextForScope(scope) {
const context = this.fetchContextForScope(scope);
this.connectedContexts.add(context);
context.connect();
}
disconnectContextForScope(scope) {
const context = this.contextsByScope.get(scope);
if (context) {
this.connectedContexts.delete(context);
context.disconnect();
}
}
fetchContextForScope(scope) {
let context = this.contextsByScope.get(scope);
if (!context) {
context = new Context(this, scope);
this.contextsByScope.set(scope, context);
}
return context;
}
};
var ClassMap = class {
constructor(scope) {
this.scope = scope;
}
has(name) {
return this.data.has(this.getDataKey(name));
}
get(name) {
return this.getAll(name)[0];
}
getAll(name) {
const tokenString = this.data.get(this.getDataKey(name)) || "";
return tokenize(tokenString);
}
getAttributeName(name) {
return this.data.getAttributeNameForKey(this.getDataKey(name));
}
getDataKey(name) {
return `${name}-class`;
}
get data() {
return this.scope.data;
}
};
var DataMap = class {
constructor(scope) {
this.scope = scope;
}
get element() {
return this.scope.element;
}
get identifier() {
return this.scope.identifier;
}
get(key) {
const name = this.getAttributeNameForKey(key);
return this.element.getAttribute(name);
}
set(key, value) {
const name = this.getAttributeNameForKey(key);
this.element.setAttribute(name, value);
return this.get(key);
}
has(key) {
const name = this.getAttributeNameForKey(key);
return this.element.hasAttribute(name);
}
delete(key) {
if (this.has(key)) {
const name = this.getAttributeNameForKey(key);
this.element.removeAttribute(name);
return true;
} else {
return false;
}
}
getAttributeNameForKey(key) {
return `data-${this.identifier}-${dasherize(key)}`;
}
};
var Guide = class {
constructor(logger) {
this.warnedKeysByObject = /* @__PURE__ */ new WeakMap();
this.logger = logger;
}
warn(object, key, message) {
let warnedKeys = this.warnedKeysByObject.get(object);
if (!warnedKeys) {
warnedKeys = /* @__PURE__ */ new Set();
this.warnedKeysByObject.set(object, warnedKeys);
}
if (!warnedKeys.has(key)) {
warnedKeys.add(key);
this.logger.warn(message, object);
}
}
};
function attributeValueContainsToken(attributeName, token) {
return `[${attributeName}~="${token}"]`;
}
var TargetSet = class {
constructor(scope) {
this.scope = scope;
}
get element() {
return this.scope.element;
}
get identifier() {
return this.scope.identifier;
}
get schema() {
return this.scope.schema;
}
has(targetName) {
return this.find(targetName) != null;
}
find(...targetNames) {
return targetNames.reduce((target, targetName) => target || this.findTarget(targetName) || this.findLegacyTarget(targetName), void 0);
}
findAll(...targetNames) {
return targetNames.reduce((targets, targetName) => [
...targets,
...this.findAllTargets(targetName),
...this.findAllLegacyTargets(targetName)
], []);
}
findTarget(targetName) {
const selector = this.getSelectorForTargetName(targetName);
return this.scope.findElement(selector);
}
findAllTargets(targetName) {
const selector = this.getSelectorForTargetName(targetName);
return this.scope.findAllElements(selector);
}
getSelectorForTargetName(targetName) {
const attributeName = this.schema.targetAttributeForScope(this.identifier);
return attributeValueContainsToken(attributeName, targetName);
}
findLegacyTarget(targetName) {
const selector = this.getLegacySelectorForTargetName(targetName);
return this.deprecate(this.scope.findElement(selector), targetName);
}
findAllLegacyTargets(targetName) {
const selector = this.getLegacySelectorForTargetName(targetName);
return this.scope.findAllElements(selector).map((element) => this.deprecate(element, targetName));
}
getLegacySelectorForTargetName(targetName) {
const targetDescriptor = `${this.identifier}.${targetName}`;
return attributeValueContainsToken(this.schema.targetAttribute, targetDescriptor);
}
deprecate(element, targetName) {
if (element) {
const { identifier } = this;
const attributeName = this.schema.targetAttribute;
const revisedAttributeName = this.schema.targetAttributeForScope(identifier);
this.guide.warn(element, `target:${targetName}`, `Please replace ${attributeName}="${identifier}.${targetName}" with ${revisedAttributeName}="${targetName}". The ${attributeName} attribute is deprecated and will be removed in a future version of Stimulus.`);
}
return element;
}
get guide() {
return this.scope.guide;
}
};
var OutletSet = class {
constructor(scope, controllerElement) {
this.scope = scope;
this.controllerElement = controllerElement;
}
get element() {
return this.scope.element;
}
get identifier() {
return this.scope.identifier;
}
get schema() {
return this.scope.schema;
}
has(outletName) {
return this.find(outletName) != null;
}
find(...outletNames) {
return outletNames.reduce((outlet, outletName) => outlet || this.findOutlet(outletName), void 0);
}
findAll(...outletNames) {
return outletNames.reduce((outlets, outletName) => [...outlets, ...this.findAllOutlets(outletName)], []);
}
getSelectorForOutletName(outletName) {
const attributeName = this.schema.outletAttributeForScope(this.identifier, outletName);
return this.controllerElement.getAttribute(attributeName);
}
findOutlet(outletName) {
const selector = this.getSelectorForOutletName(outletName);
if (selector)
return this.findElement(selector, outletName);
}
findAllOutlets(outletName) {
const selector = this.getSelectorForOutletName(outletName);
return selector ? this.findAllElements(selector, outletName) : [];
}
findElement(selector, outletName) {
const elements = this.scope.queryElements(selector);
return elements.filter((element) => this.matchesElement(element, selector, outletName))[0];
}
findAllElements(selector, outletName) {
const elements = this.scope.queryElements(selector);
return elements.filter((element) => this.matchesElement(element, selector, outletName));
}
matchesElement(element, selector, outletName) {
const controllerAttribute = element.getAttribute(this.scope.schema.controllerAttribute) || "";
return element.matches(selector) && controllerAttribute.split(" ").includes(outletName);
}
};
var Scope = class _Scope {
constructor(schema, element, identifier, logger) {
this.targets = new TargetSet(this);
this.classes = new ClassMap(this);
this.data = new DataMap(this);
this.containsElement = (element2) => {
return element2.closest(this.controllerSelector) === this.element;
};
this.schema = schema;
this.element = element;
this.identifier = identifier;
this.guide = new Guide(logger);
this.outlets = new OutletSet(this.documentScope, element);
}
findElement(selector) {
return this.element.matches(selector) ? this.element : this.queryElements(selector).find(this.containsElement);
}
findAllElements(selector) {
return [
...this.element.matches(selector) ? [this.element] : [],
...this.queryElements(selector).filter(this.containsElement)
];
}
queryElements(selector) {
return Array.from(this.element.querySelectorAll(selector));
}
get controllerSelector() {
return attributeValueContainsToken(this.schema.controllerAttribute, this.identifier);
}
get isDocumentScope() {
return this.element === document.documentElement;
}
get documentScope() {
return this.isDocumentScope ? this : new _Scope(this.schema, document.documentElement, this.identifier, this.guide.logger);
}
};
var ScopeObserver = class {
constructor(element, schema, delegate) {
this.element = element;
this.schema = schema;
this.delegate = delegate;
this.valueListObserver = new ValueListObserver(this.element, this.controllerAttribute, this);
this.scopesByIdentifierByElement = /* @__PURE__ */ new WeakMap();
this.scopeReferenceCounts = /* @__PURE__ */ new WeakMap();
}
start() {
this.valueListObserver.start();
}
stop() {
this.valueListObserver.stop();
}
get controllerAttribute() {
return this.schema.controllerAttribute;
}
parseValueForToken(token) {
const { element, content: identifier } = token;
return this.parseValueForElementAndIdentifier(element, identifier);
}
parseValueForElementAndIdentifier(element, identifier) {
const scopesByIdentifier = this.fetchScopesByIdentifierForElement(element);
let scope = scopesByIdentifier.get(identifier);
if (!scope) {
scope = this.delegate.createScopeForElementAndIdentifier(element, identifier);
scopesByIdentifier.set(identifier, scope);
}
return scope;
}
elementMatchedValue(element, value) {
const referenceCount = (this.scopeReferenceCounts.get(value) || 0) + 1;
this.scopeReferenceCounts.set(value, referenceCount);
if (referenceCount == 1) {
this.delegate.scopeConnected(value);
}
}
elementUnmatchedValue(element, value) {
const referenceCount = this.scopeReferenceCounts.get(value);
if (referenceCount) {
this.scopeReferenceCounts.set(value, referenceCount - 1);
if (referenceCount == 1) {
this.delegate.scopeDisconnected(value);
}
}
}
fetchScopesByIdentifierForElement(element) {
let scopesByIdentifier = this.scopesByIdentifierByElement.get(element);
if (!scopesByIdentifier) {
scopesByIdentifier = /* @__PURE__ */ new Map();
this.scopesByIdentifierByElement.set(element, scopesByIdentifier);
}
return scopesByIdentifier;
}
};
var Router = class {
constructor(application2) {
this.application = application2;
this.scopeObserver = new ScopeObserver(this.element, this.schema, this);
this.scopesByIdentifier = new Multimap();
this.modulesByIdentifier = /* @__PURE__ */ new Map();
}
get element() {
return this.application.element;
}
get schema() {
return this.application.schema;
}
get logger() {
return this.application.logger;
}
get controllerAttribute() {
return this.schema.controllerAttribute;
}
get modules() {
return Array.from(this.modulesByIdentifier.values());
}
get contexts() {
return this.modules.reduce((contexts, module) => contexts.concat(module.contexts), []);
}
start() {
this.scopeObserver.start();
}
stop() {
this.scopeObserver.stop();
}
loadDefinition(definition) {
this.unloadIdentifier(definition.identifier);
const module = new Module(this.application, definition);
this.connectModule(module);
const afterLoad = definition.controllerConstructor.afterLoad;
if (afterLoad) {
afterLoad.call(definition.controllerConstructor, definition.identifier, this.application);
}
}
unloadIdentifier(identifier) {
const module = this.modulesByIdentifier.get(identifier);
if (module) {
this.disconnectModule(module);
}
}
getContextForElementAndIdentifier(element, identifier) {
const module = this.modulesByIdentifier.get(identifier);
if (module) {
return module.contexts.find((context) => context.element == element);
}
}
proposeToConnectScopeForElementAndIdentifier(element, identifier) {
const scope = this.scopeObserver.parseValueForElementAndIdentifier(element, identifier);
if (scope) {
this.scopeObserver.elementMatchedValue(scope.element, scope);
} else {
console.error(`Couldn't find or create scope for identifier: "${identifier}" and element:`, element);
}
}
handleError(error2, message, detail) {
this.application.handleError(error2, message, detail);
}
createScopeForElementAndIdentifier(element, identifier) {
return new Scope(this.schema, element, identifier, this.logger);
}
scopeConnected(scope) {
this.scopesByIdentifier.add(scope.identifier, scope);
const module = this.modulesByIdentifier.get(scope.identifier);
if (module) {
module.connectContextForScope(scope);
}
}
scopeDisconnected(scope) {
this.scopesByIdentifier.delete(scope.identifier, scope);
const module = this.modulesByIdentifier.get(scope.identifier);
if (module) {
module.disconnectContextForScope(scope);
}
}
connectModule(module) {
this.modulesByIdentifier.set(module.identifier, module);
const scopes = this.scopesByIdentifier.getValuesForKey(module.identifier);
scopes.forEach((scope) => module.connectContextForScope(scope));
}
disconnectModule(module) {
this.modulesByIdentifier.delete(module.identifier);
const scopes = this.scopesByIdentifier.getValuesForKey(module.identifier);
scopes.forEach((scope) => module.disconnectContextForScope(scope));
}
};
var defaultSchema = {
controllerAttribute: "data-controller",
actionAttribute: "data-action",
targetAttribute: "data-target",
targetAttributeForScope: (identifier) => `data-${identifier}-target`,
outletAttributeForScope: (identifier, outlet) => `data-${identifier}-${outlet}-outlet`,
keyMappings: Object.assign(Object.assign({ enter: "Enter", tab: "Tab", esc: "Escape", space: " ", up: "ArrowUp", down: "ArrowDown", left: "ArrowLeft", right: "ArrowRight", home: "Home", end: "End", page_up: "PageUp", page_down: "PageDown" }, objectFromEntries("abcdefghijklmnopqrstuvwxyz".split("").map((c) => [c, c]))), objectFromEntries("0123456789".split("").map((n) => [n, n])))
};
function objectFromEntries(array) {
return array.reduce((memo, [k, v]) => Object.assign(Object.assign({}, memo), { [k]: v }), {});
}
var Application = class {
constructor(element = document.documentElement, schema = defaultSchema) {
this.logger = console;
this.debug = false;
this.logDebugActivity = (identifier, functionName, detail = {}) => {
if (this.debug) {
this.logFormattedMessage(identifier, functionName, detail);
}
};
this.element = element;
this.schema = schema;
this.dispatcher = new Dispatcher(this);
this.router = new Router(this);
this.actionDescriptorFilters = Object.assign({}, defaultActionDescriptorFilters);
}
static start(element, schema) {
const application2 = new this(element, schema);
application2.start();
return application2;
}
async start() {
await domReady();
this.logDebugActivity("application", "starting");
this.dispatcher.start();
this.router.start();
this.logDebugActivity("application", "start");
}
stop() {
this.logDebugActivity("application", "stopping");
this.dispatcher.stop();
this.router.stop();
this.logDebugActivity("application", "stop");
}
register(identifier, controllerConstructor) {
this.load({ identifier, controllerConstructor });
}
registerActionOption(name, filter) {
this.actionDescriptorFilters[name] = filter;
}
load(head, ...rest) {
const definitions = Array.isArray(head) ? head : [head, ...rest];
definitions.forEach((definition) => {
if (definition.controllerConstructor.shouldLoad) {
this.router.loadDefinition(definition);
}
});
}
unload(head, ...rest) {
const identifiers = Array.isArray(head) ? head : [head, ...rest];
identifiers.forEach((identifier) => this.router.unloadIdentifier(identifier));
}
get controllers() {
return this.router.contexts.map((context) => context.controller);
}
getControllerForElementAndIdentifier(element, identifier) {
const context = this.router.getContextForElementAndIdentifier(element, identifier);
return context ? context.controller : null;
}
handleError(error2, message, detail) {
var _a;
this.logger.error(`%s
%o
%o`, message, error2, detail);
(_a = window.onerror) === null || _a === void 0 ? void 0 : _a.call(window, message, "", 0, 0, error2);
}
logFormattedMessage(identifier, functionName, detail = {}) {
detail = Object.assign({ application: this }, detail);
this.logger.groupCollapsed(`${identifier} #${functionName}`);
this.logger.log("details:", Object.assign({}, detail));
this.logger.groupEnd();
}
};
function domReady() {
return new Promise((resolve) => {
if (document.readyState == "loading") {
document.addEventListener("DOMContentLoaded", () => resolve());
} else {
resolve();
}
});
}
function ClassPropertiesBlessing(constructor) {
const classes = readInheritableStaticArrayValues(constructor, "classes");
return classes.reduce((properties, classDefinition) => {
return Object.assign(properties, propertiesForClassDefinition(classDefinition));
}, {});
}
function propertiesForClassDefinition(key) {
return {
[`${key}Class`]: {
get() {
const { classes } = this;
if (classes.has(key)) {
return classes.get(key);
} else {
const attribute = classes.getAttributeName(key);
throw new Error(`Missing attribute "${attribute}"`);
}
}
},
[`${key}Classes`]: {
get() {
return this.classes.getAll(key);
}
},
[`has${capitalize(key)}Class`]: {
get() {
return this.classes.has(key);
}
}
};
}
function OutletPropertiesBlessing(constructor) {
const outlets = readInheritableStaticArrayValues(constructor, "outlets");
return outlets.reduce((properties, outletDefinition) => {
return Object.assign(properties, propertiesForOutletDefinition(outletDefinition));
}, {});
}
function getOutletController(controller, element, identifier) {
return controller.application.getControllerForElementAndIdentifier(element, identifier);
}
function getControllerAndEnsureConnectedScope(controller, element, outletName) {
let outletController = getOutletController(controller, element, outletName);
if (outletController)
return outletController;
controller.application.router.proposeToConnectScopeForElementAndIdentifier(element, outletName);
outletController = getOutletController(controller, element, outletName);
if (outletController)
return outletController;
}
function propertiesForOutletDefinition(name) {
const camelizedName = namespaceCamelize(name);
return {
[`${camelizedName}Outlet`]: {
get() {
const outletElement = this.outlets.find(name);
const selector = this.outlets.getSelectorForOutletName(name);
if (outletElement) {
const outletController = getControllerAndEnsureConnectedScope(this, outletElement, name);
if (outletController)
return outletController;
throw new Error(`The provided outlet element is missing an outlet controller "${name}" instance for host controller "${this.identifier}"`);
}
throw new Error(`Missing outlet element "${name}" for host controller "${this.identifier}". Stimulus couldn't find a matching outlet element using selector "${selector}".`);
}
},
[`${camelizedName}Outlets`]: {
get() {
const outlets = this.outlets.findAll(name);
if (outlets.length > 0) {
return outlets.map((outletElement) => {
const outletController = getControllerAndEnsureConnectedScope(this, outletElement, name);
if (outletController)
return outletController;
console.warn(`The provided outlet element is missing an outlet controller "${name}" instance for host controller "${this.identifier}"`, outletElement);
}).filter((controller) => controller);
}
return [];
}
},
[`${camelizedName}OutletElement`]: {
get() {
const outletElement = this.outlets.find(name);
const selector = this.outlets.getSelectorForOutletName(name);
if (outletElement) {
return outletElement;
} else {
throw new Error(`Missing outlet element "${name}" for host controller "${this.identifier}". Stimulus couldn't find a matching outlet element using selector "${selector}".`);
}
}
},
[`${camelizedName}OutletElements`]: {
get() {
return this.outlets.findAll(name);
}
},
[`has${capitalize(camelizedName)}Outlet`]: {
get() {
return this.outlets.has(name);
}
}
};
}
function TargetPropertiesBlessing(constructor) {
const targets = readInheritableStaticArrayValues(constructor, "targets");
return targets.reduce((properties, targetDefinition) => {
return Object.assign(properties, propertiesForTargetDefinition(targetDefinition));
}, {});
}
function propertiesForTargetDefinition(name) {
return {
[`${name}Target`]: {
get() {
const target = this.targets.find(name);
if (target) {
return target;
} else {
throw new Error(`Missing target element "${name}" for "${this.identifier}" controller`);
}
}
},
[`${name}Targets`]: {
get() {
return this.targets.findAll(name);
}
},
[`has${capitalize(name)}Target`]: {
get() {
return this.targets.has(name);
}
}
};
}
function ValuePropertiesBlessing(constructor) {
const valueDefinitionPairs = readInheritableStaticObjectPairs(constructor, "values");
const propertyDescriptorMap = {
valueDescriptorMap: {
get() {
return valueDefinitionPairs.reduce((result, valueDefinitionPair) => {
const valueDescriptor = parseValueDefinitionPair(valueDefinitionPair, this.identifier);
const attributeName = this.data.getAttributeNameForKey(valueDescriptor.key);
return Object.assign(result, { [attributeName]: valueDescriptor });
}, {});
}
}
};
return valueDefinitionPairs.reduce((properties, valueDefinitionPair) => {
return Object.assign(properties, propertiesForValueDefinitionPair(valueDefinitionPair));
}, propertyDescriptorMap);
}
function propertiesForValueDefinitionPair(valueDefinitionPair, controller) {
const definition = parseValueDefinitionPair(valueDefinitionPair, controller);
const { key, name, reader: read2, writer: write2 } = definition;
return {
[name]: {
get() {
const value = this.data.get(key);
if (value !== null) {
return read2(value);
} else {
return definition.defaultValue;
}
},
set(value) {
if (value === void 0) {
this.data.delete(key);
} else {
this.data.set(key, write2(value));
}
}
},
[`has${capitalize(name)}`]: {
get() {
return this.data.has(key) || definition.hasCustomDefaultValue;
}
}
};
}
function parseValueDefinitionPair([token, typeDefinition], controller) {
return valueDescriptorForTokenAndTypeDefinition({
controller,
token,
typeDefinition
});
}
function parseValueTypeConstant(constant) {
switch (constant) {
case Array:
return "array";
case Boolean:
return "boolean";
case Number:
return "number";
case Object:
return "object";
case String:
return "string";
}
}
function parseValueTypeDefault(defaultValue) {
switch (typeof defaultValue) {
case "boolean":
return "boolean";
case "number":
return "number";
case "string":
return "string";
}
if (Array.isArray(defaultValue))
return "array";
if (Object.prototype.toString.call(defaultValue) === "[object Object]")
return "object";
}
function parseValueTypeObject(payload) {
const { controller, token, typeObject } = payload;
const hasType = isSomething(typeObject.type);
const hasDefault = isSomething(typeObject.default);
const fullObject = hasType && hasDefault;
const onlyType = hasType && !hasDefault;
const onlyDefault = !hasType && hasDefault;
const typeFromObject = parseValueTypeConstant(typeObject.type);
const typeFromDefaultValue = parseValueTypeDefault(payload.typeObject.default);
if (onlyType)
return typeFromObject;
if (onlyDefault)
return typeFromDefaultValue;
if (typeFromObject !== typeFromDefaultValue) {
const propertyPath = controller ? `${controller}.${token}` : token;
throw new Error(`The specified default value for the Stimulus Value "${propertyPath}" must match the defined type "${typeFromObject}". The provided default value of "${typeObject.default}" is of type "${typeFromDefaultValue}".`);
}
if (fullObject)
return typeFromObject;
}
function parseValueTypeDefinition(payload) {
const { controller, token, typeDefinition } = payload;
const typeObject = { controller, token, typeObject: typeDefinition };
const typeFromObject = parseValueTypeObject(typeObject);
const typeFromDefaultValue = parseValueTypeDefault(typeDefinition);
const typeFromConstant = parseValueTypeConstant(typeDefinition);
const type = typeFromObject || typeFromDefaultValue || typeFromConstant;
if (type)
return type;
const propertyPath = controller ? `${controller}.${typeDefinition}` : token;
throw new Error(`Unknown value type "${propertyPath}" for "${token}" value`);
}
function defaultValueForDefinition(typeDefinition) {
const constant = parseValueTypeConstant(typeDefinition);
if (constant)
return defaultValuesByType[constant];
const hasDefault = hasProperty(typeDefinition, "default");
const hasType = hasProperty(typeDefinition, "type");
const typeObject = typeDefinition;
if (hasDefault)
return typeObject.default;
if (hasType) {
const { type } = typeObject;
const constantFromType = parseValueTypeConstant(type);
if (constantFromType)
return defaultValuesByType[constantFromType];
}
return typeDefinition;
}
function valueDescriptorForTokenAndTypeDefinition(payload) {
const { token, typeDefinition } = payload;
const key = `${dasherize(token)}-value`;
const type = parseValueTypeDefinition(payload);
return {
type,
key,
name: camelize(key),
get defaultValue() {
return defaultValueForDefinition(typeDefinition);
},
get hasCustomDefaultValue() {
return parseValueTypeDefault(typeDefinition) !== void 0;
},
reader: readers[type],
writer: writers[type] || writers.default
};
}
var defaultValuesByType = {
get array() {
return [];
},
boolean: false,
number: 0,
get object() {
return {};
},
string: ""
};
var readers = {
array(value) {
const array = JSON.parse(value);
if (!Array.isArray(array)) {
throw new TypeError(`expected value of type "array" but instead got value "${value}" of type "${parseValueTypeDefault(array)}"`);
}
return array;
},
boolean(value) {
return !(value == "0" || String(value).toLowerCase() == "false");
},
number(value) {
return Number(value.replace(/_/g, ""));
},
object(value) {
const object = JSON.parse(value);
if (object === null || typeof object != "object" || Array.isArray(object)) {
throw new TypeError(`expected value of type "object" but instead got value "${value}" of type "${parseValueTypeDefault(object)}"`);
}
return object;
},
string(value) {
return value;
}
};
var writers = {
default: writeString,
array: writeJSON,
object: writeJSON
};
function writeJSON(value) {
return JSON.stringify(value);
}
function writeString(value) {
return `${value}`;
}
var Controller = class {
constructor(context) {
this.context = context;
}
static get shouldLoad() {
return true;
}
static afterLoad(_identifier, _application) {
return;
}
get application() {
return this.context.application;
}
get scope() {
return this.context.scope;
}
get element() {
return this.scope.element;
}
get identifier() {
return this.scope.identifier;
}
get targets() {
return this.scope.targets;
}
get outlets() {
return this.scope.outlets;
}
get classes() {
return this.scope.classes;
}
get data() {
return this.scope.data;
}
initialize() {
}
connect() {
}
disconnect() {
}
dispatch(eventName, { target = this.element, detail = {}, prefix = this.identifier, bubbles = true, cancelable = true } = {}) {
const type = prefix ? `${prefix}:${eventName}` : eventName;
const event = new CustomEvent(type, { detail, bubbles, cancelable });
target.dispatchEvent(event);
return event;
}
};
Controller.blessings = [
ClassPropertiesBlessing,
TargetPropertiesBlessing,
ValuePropertiesBlessing,
OutletPropertiesBlessing
];
Controller.targets = [];
Controller.outlets = [];
Controller.values = {};
// src/js/controllers/resource_layout_controller.js
var resource_layout_controller_default = class extends Controller {
connect() {
console.log(`resource-layout connected: ${this.element}`);
}
};
// src/js/controllers/nav_grid_menu_item_controller.js
var nav_grid_menu_item_controller_default = class extends Controller {
connect() {
console.log(`nav-grid-menu-item connected: ${this.element}`);
}
};
// src/js/controllers/nav_grid_menu_controller.js
var nav_grid_menu_controller_default = class extends Controller {
connect() {
console.log(`nav-grid-menu connected: ${this.element}`);
}
};
// src/js/controllers/nav_user_section_controller.js
var nav_user_section_controller_default = class extends Controller {
connect() {
console.log(`nav-user-section connected: ${this.element}`);
}
};
// src/js/controllers/nav_user_link_controller.js
var nav_user_link_controller_default = class extends Controller {
connect() {
console.log(`nav-user-link connected: ${this.element}`);
}
};
// src/js/controllers/nav_user_controller.js
var nav_user_controller_default = class extends Controller {
connect() {
console.log(`nav-user connected: ${this.element}`);
}
};
// src/js/controllers/header_controller.js
var header_controller_default = class extends Controller {
static targets = ["openIcon", "closeIcon"];
static outlets = ["sidebar"];
static values = {
placement: { type: String, default: "left" },
bodyScrolling: { type: Boolean, default: false },
backdrop: { type: Boolean, default: true },
edge: { type: Boolean, default: false },
edgeOffset: { type: String, default: "bottom-[60px]" }
};
static classes = {
backdrop: "bg-gray-900/50 dark:bg-gray-900/80 fixed inset-0 z-30"
};
initialize() {
this.visible = false;
this.handleEscapeKey = this.handleEscapeKey.bind(this);
}
connect() {
document.addEventListener("keydown", this.handleEscapeKey);
}
sidebarOutletConnected() {
this.#setupDrawer(this.sidebarOutlet.element);
}
disconnect() {
this.#removeBackdrop();
document.removeEventListener("keydown", this.handleEscapeKey);
if (!this.bodyScrollingValue) {
document.body.classList.remove("overflow-hidden");
}
}
#setupDrawer(drawerElement) {
drawerElement.setAttribute("aria-hidden", "true");
drawerElement.classList.add("transition-transform");
this.#getPlacementClasses(this.placementValue).base.forEach((className) => {
drawerElement.classList.add(className);
});
}
toggleDrawer() {
this.visible ? this.hideDrawer() : this.showDrawer();
}
showDrawer() {
if (this.edgeValue) {
this.#toggleEdgePlacementClasses(`${this.placementValue}-edge`, true);
} else {
this.#togglePlacementClasses(this.placementValue, true);
}
this.openIconTarget.classList.add("hidden");
this.openIconTarget.setAttribute("aria-hidden", "true");
this.closeIconTarget.classList.remove("hidden");
this.closeIconTarget.setAttribute("aria-hidden", "false");
this.sidebarOutlet.element.setAttribute("aria-modal", "true");
this.sidebarOutlet.element.setAttribute("role", "dialog");
this.sidebarOutlet.element.removeAttribute("aria-hidden");
if (!this.bodyScrollingValue) {
document.body.classList.add("overflow-hidden");
}
if (this.backdropValue) {
this.#createBackdrop();
}
this.visible = true;
this.dispatch("show");
}
hideDrawer() {
if (this.edgeValue) {
this.#toggleEdgePlacementClasses(`${this.placementValue}-edge`, false);
} else {
this.#togglePlacementClasses(this.placementValue, false);
}
this.openIconTarget.classList.remove("hidden");
this.openIconTarget.setAttribute("aria-hidden", "false");
this.closeIconTarget.classList.add("hidden");
this.closeIconTarget.setAttribute("aria-hidden", "true");
this.sidebarOutlet.element.setAttribute("aria-hidden", "true");
this.sidebarOutlet.element.removeAttribute("aria-modal");
this.sidebarOutlet.element.removeAttribute("role");
if (!this.bodyScrollingValue) {
document.body.classList.remove("overflow-hidden");
}
if (this.backdropValue) {
this.#removeBackdrop();
}
this.visible = false;
this.dispatch("hide");
}
handleEscapeKey(event) {
if (event.key === "Escape" && this.visible) {
this.hideDrawer();
}
}
#createBackdrop() {
if (!this.visible) {
const backdrop = document.createElement("div");
backdrop.setAttribute("data-drawer-backdrop", "");
backdrop.classList.add(...this.constructor.classes.backdrop.split(" "));
backdrop.addEventListener("click", () => this.hideDrawer());
document.body.appendChild(backdrop);
}
}
#removeBackdrop() {
const backdrop = document.querySelector("[data-drawer-backdrop]");
if (backdrop) {
backdrop.remove();
}
}
#getPlacementClasses(placement) {
const placements2 = {
top: {
base: ["top-0", "left-0", "right-0"],
active: ["transform-none"],
inactive: ["-translate-y-full"]
},
right: {
base: ["right-0", "top-0"],
active: ["transform-none"],
inactive: ["translate-x-full"]
},
bottom: {
base: ["bottom-0", "left-0", "right-0"],
active: ["transform-none"],
inactive: ["translate-y-full"]
},
left: {
base: ["left-0", "top-0"],
active: ["transform-none"],
inactive: ["-translate-x-full"]
},
"bottom-edge": {
base: ["left-0", "top-0"],
active: ["transform-none"],
inactive: ["translate-y-full", this.edgeOffsetValue]
}
};
return placements2[placement] || placements2.left;
}
#togglePlacementClasses(placement, show) {
const classes = this.#getPlacementClasses(placement);
if (show) {
classes.active.forEach((c) => this.sidebarOutlet.element.classList.add(c));
classes.inactive.forEach((c) => this.sidebarOutlet.element.classList.remove(c));
} else {
classes.active.forEach((c) => this.sidebarOutlet.element.classList.remove(c));
classes.inactive.forEach((c) => this.sidebarOutlet.element.classList.add(c));
}
}
#toggleEdgePlacementClasses(placement, show) {
this.#togglePlacementClasses(placement, show);
}
};
// src/js/controllers/sidebar_menu_item_controller.js
var sidebar_menu_item_controller_default = class extends Controller {
connect() {
console.log(`sidebar-menu-item connected: ${this.element}`);
}
};
// src/js/controllers/sidebar_menu_controller.js
var sidebar_menu_controller_default = class extends Controller {
connect() {
console.log(`sidebar-menu connected: ${this.element}`);
}
};
// src/js/controllers/sidebar_controller.js
var sidebar_controller_default = class extends Controller {
connect() {
console.log(`sidebar connected: ${this.element}`);
}
};
// src/js/controllers/has_many_panel_controller.js
var has_many_panel_controller_default = class extends Controller {
connect() {
console.log(`has-many-panel connected: ${this.element}`);
}
};
// src/js/controllers/nested_resource_form_fields_controller.js
var nested_resource_form_fields_controller_default = class extends Controller {
static targets = ["target", "template", "addButton"];
static values = {
wrapperSelector: {
type: String,
default: ".nested-resource-form-fields"
},
limit: Number
};
connect() {
this.updateState();
}
add(e) {
e.preventDefault();
const content = this.templateTarget.innerHTML.replace(/NEW_RECORD/g, (/* @__PURE__ */ new Date()).getTime().toString());
this.targetTarget.insertAdjacentHTML("beforebegin", content);
const event = new CustomEvent("nested-resource-form-fields:add", { bubbles: true });
this.element.dispatchEvent(event);
this.updateState();
}
remove(e) {
e.preventDefault();
const wrapper = e.target.closest(this.wrapperSelectorValue);
if (wrapper.dataset.newRecord !== void 0) {
wrapper.remove();
} else {
wrapper.style.display = "none";
wrapper.classList.remove(...wrapper.classList);
const input = wrapper.querySelector("input[name*='_destroy']");
input.value = "1";
}
const event = new CustomEvent("nested-resource-form-fields:remove", { bubbles: true });
this.element.dispatchEvent(event);
this.updateState();
}
updateState() {
if (!this.hasAddButtonTarget || this.limitValue == 0)
return;
if (this.childCount >= this.limitValue)
this.addButtonTarget.style.display = "none";
else
this.addButtonTarget.style.display = "initial";
}
get childCount() {
return this.element.querySelectorAll(this.wrapperSelectorValue).length;
}
};
// src/js/controllers/toolbar_controller.js
var toolbar_controller_default = class extends Controller {
connect() {
console.log(`toolbar connected: ${this.element}`);
}
};
// src/js/controllers/table_search_input_controller.js
var table_search_input_controller_default = class extends Controller {
connect() {
console.log(`table-search-input connected: ${this.element}`);
}
};
// src/js/controllers/table_toolbar_controller.js
var table_toolbar_controller_default = class extends Controller {
connect() {
console.log(`table-toolbar connected: ${this.element}`);
}
};
// src/js/controllers/table_controller.js
var table_controller_default = class extends Controller {
connect() {
console.log(`table connected: ${this.element}`);
}
};
// src/js/controllers/form_controller.js
var import_lodash = __toESM(require_lodash(), 1);
var form_controller_default = class extends Controller {
connect() {
console.log(`form connected: ${this.element}`);
}
submit() {
this.element.requestSubmit();
}
};
// node_modules/flowbite/lib/esm/dom/events.js
var Events = (
/** @class */
function() {
function Events2(eventType, eventFunctions) {
if (eventFunctions === void 0) {
eventFunctions = [];
}
this._eventType = eventType;
this._eventFunctions = eventFunctions;
}
Events2.prototype.init = function() {
var _this = this;
this._eventFunctions.forEach(function(eventFunction) {
if (typeof window !== "undefined") {
window.addEventListener(_this._eventType, eventFunction);
}
});
};
return Events2;
}()
);
var events_default = Events;
// node_modules/flowbite/lib/esm/dom/instances.js
var Instances = (
/** @class */
function() {
function Instances2() {
this._instances = {
Accordion: {},
Carousel: {},
Collapse: {},
Dial: {},
Dismiss: {},
Drawer: {},
Dropdown: {},
Modal: {},
Popover: {},
Tabs: {},
Tooltip: {},
InputCounter: {},
CopyClipboard: {}
};
}
Instances2.prototype.addInstance = function(component, instance, id, override) {
if (override === void 0) {
override = false;
}
if (!this._instances[component]) {
console.warn("Flowbite: Component ".concat(component, " does not exist."));
return false;
}
if (this._instances[component][id] && !override) {
console.warn("Flowbite: Instance with ID ".concat(id, " already exists."));
return;
}
if (override && this._instances[component][id]) {
this._instances[component][id].destroyAndRemoveInstance();
}
this._instances[component][id ? id : this._generateRandomId()] = instance;
};
Instances2.prototype.getAllInstances = function() {
return this._instances;
};
Instances2.prototype.getInstances = function(component) {
if (!this._instances[component]) {
console.warn("Flowbite: Component ".concat(component, " does not exist."));
return false;
}
return this._instances[component];
};
Instances2.prototype.getInstance = function(component, id) {
if (!this._componentAndInstanceCheck(component, id)) {
return;
}
if (!this._instances[component][id]) {
console.warn("Flowbite: Instance with ID ".concat(id, " does not exist."));
return;
}
return this._instances[component][id];
};
Instances2.prototype.destroyAndRemoveInstance = function(component, id) {
if (!this._componentAndInstanceCheck(component, id)) {
return;
}
this.destroyInstanceObject(component, id);
this.removeInstance(component, id);
};
Instances2.prototype.removeInstance = function(component, id) {
if (!this._componentAndInstanceCheck(component, id)) {
return;
}
delete this._instances[component][id];
};
Instances2.prototype.destroyInstanceObject = function(component, id) {
if (!this._componentAndInstanceCheck(component, id)) {
return;
}
this._instances[component][id].destroy();
};
Instances2.prototype.instanceExists = function(component, id) {
if (!this._instances[component]) {
return false;
}
if (!this._instances[component][id]) {
return false;
}
return true;
};
Instances2.prototype._generateRandomId = function() {
return Math.random().toString(36).substr(2, 9);
};
Instances2.prototype._componentAndInstanceCheck = function(component, id) {
if (!this._instances[component]) {
console.warn("Flowbite: Component ".concat(component, " does not exist."));
return false;
}
if (!this._instances[component][id]) {
console.warn("Flowbite: Instance with ID ".concat(id, " does not exist."));
return false;
}
return true;
};
return Instances2;
}()
);
var instances = new Instances();
var instances_default = instances;
if (typeof window !== "undefined") {
window.FlowbiteInstances = instances;
}
// node_modules/flowbite/lib/esm/components/accordion/index.js
var __assign = function() {
__assign = Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s)
if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
var Default = {
alwaysOpen: false,
activeClasses: "bg-gray-100 dark:bg-gray-800 text-gray-900 dark:text-white",
inactiveClasses: "text-gray-500 dark:text-gray-400",
onOpen: function() {
},
onClose: function() {
},
onToggle: function() {
}
};
var DefaultInstanceOptions = {
id: null,
override: true
};
var Accordion = (
/** @class */
function() {
function Accordion2(accordionEl, items, options, instanceOptions) {
if (accordionEl === void 0) {
accordionEl = null;
}
if (items === void 0) {
items = [];
}
if (options === void 0) {
options = Default;
}
if (instanceOptions === void 0) {
instanceOptions = DefaultInstanceOptions;
}
this._instanceId = instanceOptions.id ? instanceOptions.id : accordionEl.id;
this._accordionEl = accordionEl;
this._items = items;
this._options = __assign(__assign({}, Default), options);
this._initialized = false;
this.init();
instances_default.addInstance("Accordion", this, this._instanceId, instanceOptions.override);
}
Accordion2.prototype.init = function() {
var _this = this;
if (this._items.length && !this._initialized) {
this._items.forEach(function(item) {
if (item.active) {
_this.open(item.id);
}
var clickHandler = function() {
_this.toggle(item.id);
};
item.triggerEl.addEventListener("click", clickHandler);
item.clickHandler = clickHandler;
});
this._initialized = true;
}
};
Accordion2.prototype.destroy = function() {
if (this._items.length && this._initialized) {
this._items.forEach(function(item) {
item.triggerEl.removeEventListener("click", item.clickHandler);
delete item.clickHandler;
});
this._initialized = false;
}
};
Accordion2.prototype.removeInstance = function() {
instances_default.removeInstance("Accordion", this._instanceId);
};
Accordion2.prototype.destroyAndRemoveInstance = function() {
this.destroy();
this.removeInstance();
};
Accordion2.prototype.getItem = function(id) {
return this._items.filter(function(item) {
return item.id === id;
})[0];
};
Accordion2.prototype.open = function(id) {
var _a, _b;
var _this = this;
var item = this.getItem(id);
if (!this._options.alwaysOpen) {
this._items.map(function(i) {
var _a2, _b2;
if (i !== item) {
(_a2 = i.triggerEl.classList).remove.apply(_a2, _this._options.activeClasses.split(" "));
(_b2 = i.triggerEl.classList).add.apply(_b2, _this._options.inactiveClasses.split(" "));
i.targetEl.classList.add("hidden");
i.triggerEl.setAttribute("aria-expanded", "false");
i.active = false;
if (i.iconEl) {
i.iconEl.classList.add("rotate-180");
}
}
});
}
(_a = item.triggerEl.classList).add.apply(_a, this._options.activeClasses.split(" "));
(_b = item.triggerEl.classList).remove.apply(_b, this._options.inactiveClasses.split(" "));
item.triggerEl.setAttribute("aria-expanded", "true");
item.targetEl.classList.remove("hidden");
item.active = true;
if (item.iconEl) {
item.iconEl.classList.remove("rotate-180");
}
this._options.onOpen(this, item);
};
Accordion2.prototype.toggle = function(id) {
var item = this.getItem(id);
if (item.active) {
this.close(id);
} else {
this.open(id);
}
this._options.onToggle(this, item);
};
Accordion2.prototype.close = function(id) {
var _a, _b;
var item = this.getItem(id);
(_a = item.triggerEl.classList).remove.apply(_a, this._options.activeClasses.split(" "));
(_b = item.triggerEl.classList).add.apply(_b, this._options.inactiveClasses.split(" "));
item.targetEl.classList.add("hidden");
item.triggerEl.setAttribute("aria-expanded", "false");
item.active = false;
if (item.iconEl) {
item.iconEl.classList.add("rotate-180");
}
this._options.onClose(this, item);
};
Accordion2.prototype.updateOnOpen = function(callback) {
this._options.onOpen = callback;
};
Accordion2.prototype.updateOnClose = function(callback) {
this._options.onClose = callback;
};
Accordion2.prototype.updateOnToggle = function(callback) {
this._options.onToggle = callback;
};
return Accordion2;
}()
);
function initAccordions() {
document.querySelectorAll("[data-accordion]").forEach(function($accordionEl) {
var alwaysOpen = $accordionEl.getAttribute("data-accordion");
var activeClasses = $accordionEl.getAttribute("data-active-classes");
var inactiveClasses = $accordionEl.getAttribute("data-inactive-classes");
var items = [];
$accordionEl.querySelectorAll("[data-accordion-target]").forEach(function($triggerEl) {
if ($triggerEl.closest("[data-accordion]") === $accordionEl) {
var item = {
id: $triggerEl.getAttribute("data-accordion-target"),
triggerEl: $triggerEl,
targetEl: document.querySelector($triggerEl.getAttribute("data-accordion-target")),
iconEl: $triggerEl.querySelector("[data-accordion-icon]"),
active: $triggerEl.getAttribute("aria-expanded") === "true" ? true : false
};
items.push(item);
}
});
new Accordion($accordionEl, items, {
alwaysOpen: alwaysOpen === "open" ? true : false,
activeClasses: activeClasses ? activeClasses : Default.activeClasses,
inactiveClasses: inactiveClasses ? inactiveClasses : Default.inactiveClasses
});
});
}
if (typeof window !== "undefined") {
window.Accordion = Accordion;
window.initAccordions = initAccordions;
}
// node_modules/flowbite/lib/esm/components/collapse/index.js
var __assign2 = function() {
__assign2 = Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s)
if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign2.apply(this, arguments);
};
var Default2 = {
onCollapse: function() {
},
onExpand: function() {
},
onToggle: function() {
}
};
var DefaultInstanceOptions2 = {
id: null,
override: true
};
var Collapse = (
/** @class */
function() {
function Collapse2(targetEl, triggerEl, options, instanceOptions) {
if (targetEl === void 0) {
targetEl = null;
}
if (triggerEl === void 0) {
triggerEl = null;
}
if (options === void 0) {
options = Default2;
}
if (instanceOptions === void 0) {
instanceOptions = DefaultInstanceOptions2;
}
this._instanceId = instanceOptions.id ? instanceOptions.id : targetEl.id;
this._targetEl = targetEl;
this._triggerEl = triggerEl;
this._options = __assign2(__assign2({}, Default2), options);
this._visible = false;
this._initialized = false;
this.init();
instances_default.addInstance("Collapse", this, this._instanceId, instanceOptions.override);
}
Collapse2.prototype.init = function() {
var _this = this;
if (this._triggerEl && this._targetEl && !this._initialized) {
if (this._triggerEl.hasAttribute("aria-expanded")) {
this._visible = this._triggerEl.getAttribute("aria-expanded") === "true";
} else {
this._visible = !this._targetEl.classList.contains("hidden");
}
this._clickHandler = function() {
_this.toggle();
};
this._triggerEl.addEventListener("click", this._clickHandler);
this._initialized = true;
}
};
Collapse2.prototype.destroy = function() {
if (this._triggerEl && this._initialized) {
this._triggerEl.removeEventListener("click", this._clickHandler);
this._initialized = false;
}
};
Collapse2.prototype.removeInstance = function() {
instances_default.removeInstance("Collapse", this._instanceId);
};
Collapse2.prototype.destroyAndRemoveInstance = function() {
this.destroy();
this.removeInstance();
};
Collapse2.prototype.collapse = function() {
this._targetEl.classList.add("hidden");
if (this._triggerEl) {
this._triggerEl.setAttribute("aria-expanded", "false");
}
this._visible = false;
this._options.onCollapse(this);
};
Collapse2.prototype.expand = function() {
this._targetEl.classList.remove("hidden");
if (this._triggerEl) {
this._triggerEl.setAttribute("aria-expanded", "true");
}
this._visible = true;
this._options.onExpand(this);
};
Collapse2.prototype.toggle = function() {
if (this._visible) {
this.collapse();
} else {
this.expand();
}
this._options.onToggle(this);
};
Collapse2.prototype.updateOnCollapse = function(callback) {
this._options.onCollapse = callback;
};
Collapse2.prototype.updateOnExpand = function(callback) {
this._options.onExpand = callback;
};
Collapse2.prototype.updateOnToggle = function(callback) {
this._options.onToggle = callback;
};
return Collapse2;
}()
);
function initCollapses() {
document.querySelectorAll("[data-collapse-toggle]").forEach(function($triggerEl) {
var targetId = $triggerEl.getAttribute("data-collapse-toggle");
var $targetEl = document.getElementById(targetId);
if ($targetEl) {
if (!instances_default.instanceExists("Collapse", $targetEl.getAttribute("id"))) {
new Collapse($targetEl, $triggerEl);
} else {
new Collapse($targetEl, $triggerEl, {}, {
id: $targetEl.getAttribute("id") + "_" + instances_default._generateRandomId()
});
}
} else {
console.error('The target element with id "'.concat(targetId, '" does not exist. Please check the data-collapse-toggle attribute.'));
}
});
}
if (typeof window !== "undefined") {
window.Collapse = Collapse;
window.initCollapses = initCollapses;
}
var collapse_default = Collapse;
// node_modules/flowbite/lib/esm/components/carousel/index.js
var __assign3 = function() {
__assign3 = Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s)
if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign3.apply(this, arguments);
};
var Default3 = {
defaultPosition: 0,
indicators: {
items: [],
activeClasses: "bg-white dark:bg-gray-800",
inactiveClasses: "bg-white/50 dark:bg-gray-800/50 hover:bg-white dark:hover:bg-gray-800"
},
interval: 3e3,
onNext: function() {
},
onPrev: function() {
},
onChange: function() {
}
};
var DefaultInstanceOptions3 = {
id: null,
override: true
};
var Carousel = (
/** @class */
function() {
function Carousel2(carouselEl, items, options, instanceOptions) {
if (carouselEl === void 0) {
carouselEl = null;
}
if (items === void 0) {
items = [];
}
if (options === void 0) {
options = Default3;
}
if (instanceOptions === void 0) {
instanceOptions = DefaultInstanceOptions3;
}
this._instanceId = instanceOptions.id ? instanceOptions.id : carouselEl.id;
this._carouselEl = carouselEl;
this._items = items;
this._options = __assign3(__assign3(__assign3({}, Default3), options), { indicators: __assign3(__assign3({}, Default3.indicators), options.indicators) });
this._activeItem = this.getItem(this._options.defaultPosition);
this._indicators = this._options.indicators.items;
this._intervalDuration = this._options.interval;
this._intervalInstance = null;
this._initialized = false;
this.init();
instances_default.addInstance("Carousel", this, this._instanceId, instanceOptions.override);
}
Carousel2.prototype.init = function() {
var _this = this;
if (this._items.length && !this._initialized) {
this._items.map(function(item) {
item.el.classList.add("absolute", "inset-0", "transition-transform", "transform");
});
if (this.getActiveItem()) {
this.slideTo(this.getActiveItem().position);
} else {
this.slideTo(0);
}
this._indicators.map(function(indicator, position) {
indicator.el.addEventListener("click", function() {
_this.slideTo(position);
});
});
this._initialized = true;
}
};
Carousel2.prototype.destroy = function() {
if (this._initialized) {
this._initialized = false;
}
};
Carousel2.prototype.removeInstance = function() {
instances_default.removeInstance("Carousel", this._instanceId);
};
Carousel2.prototype.destroyAndRemoveInstance = function() {
this.destroy();
this.removeInstance();
};
Carousel2.prototype.getItem = function(position) {
return this._items[position];
};
Carousel2.prototype.slideTo = function(position) {
var nextItem = this._items[position];
var rotationItems = {
left: nextItem.position === 0 ? this._items[this._items.length - 1] : this._items[nextItem.position - 1],
middle: nextItem,
right: nextItem.position === this._items.length - 1 ? this._items[0] : this._items[nextItem.position + 1]
};
this._rotate(rotationItems);
this._setActiveItem(nextItem);
if (this._intervalInstance) {
this.pause();
this.cycle();
}
this._options.onChange(this);
};
Carousel2.prototype.next = function() {
var activeItem = this.getActiveItem();
var nextItem = null;
if (activeItem.position === this._items.length - 1) {
nextItem = this._items[0];
} else {
nextItem = this._items[activeItem.position + 1];
}
this.slideTo(nextItem.position);
this._options.onNext(this);
};
Carousel2.prototype.prev = function() {
var activeItem = this.getActiveItem();
var prevItem = null;
if (activeItem.position === 0) {
prevItem = this._items[this._items.length - 1];
} else {
prevItem = this._items[activeItem.position - 1];
}
this.slideTo(prevItem.position);
this._options.onPrev(this);
};
Carousel2.prototype._rotate = function(rotationItems) {
this._items.map(function(item) {
item.el.classList.add("hidden");
});
if (this._items.length === 1) {
rotationItems.middle.el.classList.remove("-translate-x-full", "translate-x-full", "translate-x-0", "hidden", "z-10");
rotationItems.middle.el.classList.add("translate-x-0", "z-20");
return;
}
rotationItems.left.el.classList.remove("-translate-x-full", "translate-x-full", "translate-x-0", "hidden", "z-20");
rotationItems.left.el.classList.add("-translate-x-full", "z-10");
rotationItems.middle.el.classList.remove("-translate-x-full", "translate-x-full", "translate-x-0", "hidden", "z-10");
rotationItems.middle.el.classList.add("translate-x-0", "z-30");
rotationItems.right.el.classList.remove("-translate-x-full", "translate-x-full", "translate-x-0", "hidden", "z-30");
rotationItems.right.el.classList.add("translate-x-full", "z-20");
};
Carousel2.prototype.cycle = function() {
var _this = this;
if (typeof window !== "undefined") {
this._intervalInstance = window.setInterval(function() {
_this.next();
}, this._intervalDuration);
}
};
Carousel2.prototype.pause = function() {
clearInterval(this._intervalInstance);
};
Carousel2.prototype.getActiveItem = function() {
return this._activeItem;
};
Carousel2.prototype._setActiveItem = function(item) {
var _a, _b;
var _this = this;
this._activeItem = item;
var position = item.position;
if (this._indicators.length) {
this._indicators.map(function(indicator) {
var _a2, _b2;
indicator.el.setAttribute("aria-current", "false");
(_a2 = indicator.el.classList).remove.apply(_a2, _this._options.indicators.activeClasses.split(" "));
(_b2 = indicator.el.classList).add.apply(_b2, _this._options.indicators.inactiveClasses.split(" "));
});
(_a = this._indicators[position].el.classList).add.apply(_a, this._options.indicators.activeClasses.split(" "));
(_b = this._indicators[position].el.classList).remove.apply(_b, this._options.indicators.inactiveClasses.split(" "));
this._indicators[position].el.setAttribute("aria-current", "true");
}
};
Carousel2.prototype.updateOnNext = function(callback) {
this._options.onNext = callback;
};
Carousel2.prototype.updateOnPrev = function(callback) {
this._options.onPrev = callback;
};
Carousel2.prototype.updateOnChange = function(callback) {
this._options.onChange = callback;
};
return Carousel2;
}()
);
function initCarousels() {
document.querySelectorAll("[data-carousel]").forEach(function($carouselEl) {
var interval = $carouselEl.getAttribute("data-carousel-interval");
var slide = $carouselEl.getAttribute("data-carousel") === "slide" ? true : false;
var items = [];
var defaultPosition = 0;
if ($carouselEl.querySelectorAll("[data-carousel-item]").length) {
Array.from($carouselEl.querySelectorAll("[data-carousel-item]")).map(function($carouselItemEl, position) {
items.push({
position,
el: $carouselItemEl
});
if ($carouselItemEl.getAttribute("data-carousel-item") === "active") {
defaultPosition = position;
}
});
}
var indicators = [];
if ($carouselEl.querySelectorAll("[data-carousel-slide-to]").length) {
Array.from($carouselEl.querySelectorAll("[data-carousel-slide-to]")).map(function($indicatorEl) {
indicators.push({
position: parseInt($indicatorEl.getAttribute("data-carousel-slide-to")),
el: $indicatorEl
});
});
}
var carousel = new Carousel($carouselEl, items, {
defaultPosition,
indicators: {
items: indicators
},
interval: interval ? interval : Default3.interval
});
if (slide) {
carousel.cycle();
}
var carouselNextEl = $carouselEl.querySelector("[data-carousel-next]");
var carouselPrevEl = $carouselEl.querySelector("[data-carousel-prev]");
if (carouselNextEl) {
carouselNextEl.addEventListener("click", function() {
carousel.next();
});
}
if (carouselPrevEl) {
carouselPrevEl.addEventListener("click", function() {
carousel.prev();
});
}
});
}
if (typeof window !== "undefined") {
window.Carousel = Carousel;
window.initCarousels = initCarousels;
}
// node_modules/flowbite/lib/esm/components/dismiss/index.js
var __assign4 = function() {
__assign4 = Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s)
if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign4.apply(this, arguments);
};
var Default4 = {
transition: "transition-opacity",
duration: 300,
timing: "ease-out",
onHide: function() {
}
};
var DefaultInstanceOptions4 = {
id: null,
override: true
};
var Dismiss = (
/** @class */
function() {
function Dismiss2(targetEl, triggerEl, options, instanceOptions) {
if (targetEl === void 0) {
targetEl = null;
}
if (triggerEl === void 0) {
triggerEl = null;
}
if (options === void 0) {
options = Default4;
}
if (instanceOptions === void 0) {
instanceOptions = DefaultInstanceOptions4;
}
this._instanceId = instanceOptions.id ? instanceOptions.id : targetEl.id;
this._targetEl = targetEl;
this._triggerEl = triggerEl;
this._options = __assign4(__assign4({}, Default4), options);
this._initialized = false;
this.init();
instances_default.addInstance("Dismiss", this, this._instanceId, instanceOptions.override);
}
Dismiss2.prototype.init = function() {
var _this = this;
if (this._triggerEl && this._targetEl && !this._initialized) {
this._clickHandler = function() {
_this.hide();
};
this._triggerEl.addEventListener("click", this._clickHandler);
this._initialized = true;
}
};
Dismiss2.prototype.destroy = function() {
if (this._triggerEl && this._initialized) {
this._triggerEl.removeEventListener("click", this._clickHandler);
this._initialized = false;
}
};
Dismiss2.prototype.removeInstance = function() {
instances_default.removeInstance("Dismiss", this._instanceId);
};
Dismiss2.prototype.destroyAndRemoveInstance = function() {
this.destroy();
this.removeInstance();
};
Dismiss2.prototype.hide = function() {
var _this = this;
this._targetEl.classList.add(this._options.transition, "duration-".concat(this._options.duration), this._options.timing, "opacity-0");
setTimeout(function() {
_this._targetEl.classList.add("hidden");
}, this._options.duration);
this._options.onHide(this, this._targetEl);
};
Dismiss2.prototype.updateOnHide = function(callback) {
this._options.onHide = callback;
};
return Dismiss2;
}()
);
function initDismisses() {
document.querySelectorAll("[data-dismiss-target]").forEach(function($triggerEl) {
var targetId = $triggerEl.getAttribute("data-dismiss-target");
var $dismissEl = document.querySelector(targetId);
if ($dismissEl) {
new Dismiss($dismissEl, $triggerEl);
} else {
console.error('The dismiss element with id "'.concat(targetId, '" does not exist. Please check the data-dismiss-target attribute.'));
}
});
}
if (typeof window !== "undefined") {
window.Dismiss = Dismiss;
window.initDismisses = initDismisses;
}
// node_modules/@popperjs/core/lib/enums.js
var top = "top";
var bottom = "bottom";
var right = "right";
var left = "left";
var auto = "auto";
var basePlacements = [top, bottom, right, left];
var start = "start";
var end = "end";
var clippingParents = "clippingParents";
var viewport = "viewport";
var popper = "popper";
var reference = "reference";
var variationPlacements = /* @__PURE__ */ basePlacements.reduce(function(acc, placement) {
return acc.concat([placement + "-" + start, placement + "-" + end]);
}, []);
var placements = /* @__PURE__ */ [].concat(basePlacements, [auto]).reduce(function(acc, placement) {
return acc.concat([placement, placement + "-" + start, placement + "-" + end]);
}, []);
var beforeRead = "beforeRead";
var read = "read";
var afterRead = "afterRead";
var beforeMain = "beforeMain";
var main = "main";
var afterMain = "afterMain";
var beforeWrite = "beforeWrite";
var write = "write";
var afterWrite = "afterWrite";
var modifierPhases = [beforeRead, read, afterRead, beforeMain, main, afterMain, beforeWrite, write, afterWrite];
// node_modules/@popperjs/core/lib/dom-utils/getNodeName.js
function getNodeName(element) {
return element ? (element.nodeName || "").toLowerCase() : null;
}
// node_modules/@popperjs/core/lib/dom-utils/getWindow.js
function getWindow(node) {
if (node == null) {
return window;
}
if (node.toString() !== "[object Window]") {
var ownerDocument = node.ownerDocument;
return ownerDocument ? ownerDocument.defaultView || window : window;
}
return node;
}
// node_modules/@popperjs/core/lib/dom-utils/instanceOf.js
function isElement(node) {
var OwnElement = getWindow(node).Element;
return node instanceof OwnElement || node instanceof Element;
}
function isHTMLElement(node) {
var OwnElement = getWindow(node).HTMLElement;
return node instanceof OwnElement || node instanceof HTMLElement;
}
function isShadowRoot(node) {
if (typeof ShadowRoot === "undefined") {
return false;
}
var OwnElement = getWindow(node).ShadowRoot;
return node instanceof OwnElement || node instanceof ShadowRoot;
}
// node_modules/@popperjs/core/lib/modifiers/applyStyles.js
function applyStyles(_ref) {
var state = _ref.state;
Object.keys(state.elements).forEach(function(name) {
var style = state.styles[name] || {};
var attributes = state.attributes[name] || {};
var element = state.elements[name];
if (!isHTMLElement(element) || !getNodeName(element)) {
return;
}
Object.assign(element.style, style);
Object.keys(attributes).forEach(function(name2) {
var value = attributes[name2];
if (value === false) {
element.removeAttribute(name2);
} else {
element.setAttribute(name2, value === true ? "" : value);
}
});
});
}
function effect(_ref2) {
var state = _ref2.state;
var initialStyles = {
popper: {
position: state.options.strategy,
left: "0",
top: "0",
margin: "0"
},
arrow: {
position: "absolute"
},
reference: {}
};
Object.assign(state.elements.popper.style, initialStyles.popper);
state.styles = initialStyles;
if (state.elements.arrow) {
Object.assign(state.elements.arrow.style, initialStyles.arrow);
}
return function() {
Object.keys(state.elements).forEach(function(name) {
var element = state.elements[name];
var attributes = state.attributes[name] || {};
var styleProperties = Object.keys(state.styles.hasOwnProperty(name) ? state.styles[name] : initialStyles[name]);
var style = styleProperties.reduce(function(style2, property) {
style2[property] = "";
return style2;
}, {});
if (!isHTMLElement(element) || !getNodeName(element)) {
return;
}
Object.assign(element.style, style);
Object.keys(attributes).forEach(function(attribute) {
element.removeAttribute(attribute);
});
});
};
}
var applyStyles_default = {
name: "applyStyles",
enabled: true,
phase: "write",
fn: applyStyles,
effect,
requires: ["computeStyles"]
};
// node_modules/@popperjs/core/lib/utils/getBasePlacement.js
function getBasePlacement(placement) {
return placement.split("-")[0];
}
// node_modules/@popperjs/core/lib/utils/math.js
var max = Math.max;
var min = Math.min;
var round = Math.round;
// node_modules/@popperjs/core/lib/utils/userAgent.js
function getUAString() {
var uaData = navigator.userAgentData;
if (uaData != null && uaData.brands && Array.isArray(uaData.brands)) {
return uaData.brands.map(function(item) {
return item.brand + "/" + item.version;
}).join(" ");
}
return navigator.userAgent;
}
// node_modules/@popperjs/core/lib/dom-utils/isLayoutViewport.js
function isLayoutViewport() {
return !/^((?!chrome|android).)*safari/i.test(getUAString());
}
// node_modules/@popperjs/core/lib/dom-utils/getBoundingClientRect.js
function getBoundingClientRect(element, includeScale, isFixedStrategy) {
if (includeScale === void 0) {
includeScale = false;
}
if (isFixedStrategy === void 0) {
isFixedStrategy = false;
}
var clientRect = element.getBoundingClientRect();
var scaleX = 1;
var scaleY = 1;
if (includeScale && isHTMLElement(element)) {
scaleX = element.offsetWidth > 0 ? round(clientRect.width) / element.offsetWidth || 1 : 1;
scaleY = element.offsetHeight > 0 ? round(clientRect.height) / element.offsetHeight || 1 : 1;
}
var _ref = isElement(element) ? getWindow(element) : window, visualViewport = _ref.visualViewport;
var addVisualOffsets = !isLayoutViewport() && isFixedStrategy;
var x = (clientRect.left + (addVisualOffsets && visualViewport ? visualViewport.offsetLeft : 0)) / scaleX;
var y = (clientRect.top + (addVisualOffsets && visualViewport ? visualViewport.offsetTop : 0)) / scaleY;
var width = clientRect.width / scaleX;
var height = clientRect.height / scaleY;
return {
width,
height,
top: y,
right: x + width,
bottom: y + height,
left: x,
x,
y
};
}
// node_modules/@popperjs/core/lib/dom-utils/getLayoutRect.js
function getLayoutRect(element) {
var clientRect = getBoundingClientRect(element);
var width = element.offsetWidth;
var height = element.offsetHeight;
if (Math.abs(clientRect.width - width) <= 1) {
width = clientRect.width;
}
if (Math.abs(clientRect.height - height) <= 1) {
height = clientRect.height;
}
return {
x: element.offsetLeft,
y: element.offsetTop,
width,
height
};
}
// node_modules/@popperjs/core/lib/dom-utils/contains.js
function contains(parent, child) {
var rootNode = child.getRootNode && child.getRootNode();
if (parent.contains(child)) {
return true;
} else if (rootNode && isShadowRoot(rootNode)) {
var next = child;
do {
if (next && parent.isSameNode(next)) {
return true;
}
next = next.parentNode || next.host;
} while (next);
}
return false;
}
// node_modules/@popperjs/core/lib/dom-utils/getComputedStyle.js
function getComputedStyle(element) {
return getWindow(element).getComputedStyle(element);
}
// node_modules/@popperjs/core/lib/dom-utils/isTableElement.js
function isTableElement(element) {
return ["table", "td", "th"].indexOf(getNodeName(element)) >= 0;
}
// node_modules/@popperjs/core/lib/dom-utils/getDocumentElement.js
function getDocumentElement(element) {
return ((isElement(element) ? element.ownerDocument : (
// $FlowFixMe[prop-missing]
element.document
)) || window.document).documentElement;
}
// node_modules/@popperjs/core/lib/dom-utils/getParentNode.js
function getParentNode(element) {
if (getNodeName(element) === "html") {
return element;
}
return (
// this is a quicker (but less type safe) way to save quite some bytes from the bundle
// $FlowFixMe[incompatible-return]
// $FlowFixMe[prop-missing]
element.assignedSlot || // step into the shadow DOM of the parent of a slotted node
element.parentNode || // DOM Element detected
(isShadowRoot(element) ? element.host : null) || // ShadowRoot detected
// $FlowFixMe[incompatible-call]: HTMLElement is a Node
getDocumentElement(element)
);
}
// node_modules/@popperjs/core/lib/dom-utils/getOffsetParent.js
function getTrueOffsetParent(element) {
if (!isHTMLElement(element) || // https://github.com/popperjs/popper-core/issues/837
getComputedStyle(element).position === "fixed") {
return null;
}
return element.offsetParent;
}
function getContainingBlock(element) {
var isFirefox = /firefox/i.test(getUAString());
var isIE = /Trident/i.test(getUAString());
if (isIE && isHTMLElement(element)) {
var elementCss = getComputedStyle(element);
if (elementCss.position === "fixed") {
return null;
}
}
var currentNode = getParentNode(element);
if (isShadowRoot(currentNode)) {
currentNode = currentNode.host;
}
while (isHTMLElement(currentNode) && ["html", "body"].indexOf(getNodeName(currentNode)) < 0) {
var css = getComputedStyle(currentNode);
if (css.transform !== "none" || css.perspective !== "none" || css.contain === "paint" || ["transform", "perspective"].indexOf(css.willChange) !== -1 || isFirefox && css.willChange === "filter" || isFirefox && css.filter && css.filter !== "none") {
return currentNode;
} else {
currentNode = currentNode.parentNode;
}
}
return null;
}
function getOffsetParent(element) {
var window2 = getWindow(element);
var offsetParent = getTrueOffsetParent(element);
while (offsetParent && isTableElement(offsetParent) && getComputedStyle(offsetParent).position === "static") {
offsetParent = getTrueOffsetParent(offsetParent);
}
if (offsetParent && (getNodeName(offsetParent) === "html" || getNodeName(offsetParent) === "body" && getComputedStyle(offsetParent).position === "static")) {
return window2;
}
return offsetParent || getContainingBlock(element) || window2;
}
// node_modules/@popperjs/core/lib/utils/getMainAxisFromPlacement.js
function getMainAxisFromPlacement(placement) {
return ["top", "bottom"].indexOf(placement) >= 0 ? "x" : "y";
}
// node_modules/@popperjs/core/lib/utils/within.js
function within(min2, value, max2) {
return max(min2, min(value, max2));
}
function withinMaxClamp(min2, value, max2) {
var v = within(min2, value, max2);
return v > max2 ? max2 : v;
}
// node_modules/@popperjs/core/lib/utils/getFreshSideObject.js
function getFreshSideObject() {
return {
top: 0,
right: 0,
bottom: 0,
left: 0
};
}
// node_modules/@popperjs/core/lib/utils/mergePaddingObject.js
function mergePaddingObject(paddingObject) {
return Object.assign({}, getFreshSideObject(), paddingObject);
}
// node_modules/@popperjs/core/lib/utils/expandToHashMap.js
function expandToHashMap(value, keys) {
return keys.reduce(function(hashMap, key) {
hashMap[key] = value;
return hashMap;
}, {});
}
// node_modules/@popperjs/core/lib/modifiers/arrow.js
var toPaddingObject = function toPaddingObject2(padding, state) {
padding = typeof padding === "function" ? padding(Object.assign({}, state.rects, {
placement: state.placement
})) : padding;
return mergePaddingObject(typeof padding !== "number" ? padding : expandToHashMap(padding, basePlacements));
};
function arrow(_ref) {
var _state$modifiersData$;
var state = _ref.state, name = _ref.name, options = _ref.options;
var arrowElement = state.elements.arrow;
var popperOffsets2 = state.modifiersData.popperOffsets;
var basePlacement = getBasePlacement(state.placement);
var axis = getMainAxisFromPlacement(basePlacement);
var isVertical = [left, right].indexOf(basePlacement) >= 0;
var len = isVertical ? "height" : "width";
if (!arrowElement || !popperOffsets2) {
return;
}
var paddingObject = toPaddingObject(options.padding, state);
var arrowRect = getLayoutRect(arrowElement);
var minProp = axis === "y" ? top : left;
var maxProp = axis === "y" ? bottom : right;
var endDiff = state.rects.reference[len] + state.rects.reference[axis] - popperOffsets2[axis] - state.rects.popper[len];
var startDiff = popperOffsets2[axis] - state.rects.reference[axis];
var arrowOffsetParent = getOffsetParent(arrowElement);
var clientSize = arrowOffsetParent ? axis === "y" ? arrowOffsetParent.clientHeight || 0 : arrowOffsetParent.clientWidth || 0 : 0;
var centerToReference = endDiff / 2 - startDiff / 2;
var min2 = paddingObject[minProp];
var max2 = clientSize - arrowRect[len] - paddingObject[maxProp];
var center = clientSize / 2 - arrowRect[len] / 2 + centerToReference;
var offset2 = within(min2, center, max2);
var axisProp = axis;
state.modifiersData[name] = (_state$modifiersData$ = {}, _state$modifiersData$[axisProp] = offset2, _state$modifiersData$.centerOffset = offset2 - center, _state$modifiersData$);
}
function effect2(_ref2) {
var state = _ref2.state, options = _ref2.options;
var _options$element = options.element, arrowElement = _options$element === void 0 ? "[data-popper-arrow]" : _options$element;
if (arrowElement == null) {
return;
}
if (typeof arrowElement === "string") {
arrowElement = state.elements.popper.querySelector(arrowElement);
if (!arrowElement) {
return;
}
}
if (!contains(state.elements.popper, arrowElement)) {
return;
}
state.elements.arrow = arrowElement;
}
var arrow_default = {
name: "arrow",
enabled: true,
phase: "main",
fn: arrow,
effect: effect2,
requires: ["popperOffsets"],
requiresIfExists: ["preventOverflow"]
};
// node_modules/@popperjs/core/lib/utils/getVariation.js
function getVariation(placement) {
return placement.split("-")[1];
}
// node_modules/@popperjs/core/lib/modifiers/computeStyles.js
var unsetSides = {
top: "auto",
right: "auto",
bottom: "auto",
left: "auto"
};
function roundOffsetsByDPR(_ref, win) {
var x = _ref.x, y = _ref.y;
var dpr = win.devicePixelRatio || 1;
return {
x: round(x * dpr) / dpr || 0,
y: round(y * dpr) / dpr || 0
};
}
function mapToStyles(_ref2) {
var _Object$assign2;
var popper2 = _ref2.popper, popperRect = _ref2.popperRect, placement = _ref2.placement, variation = _ref2.variation, offsets = _ref2.offsets, position = _ref2.position, gpuAcceleration = _ref2.gpuAcceleration, adaptive = _ref2.adaptive, roundOffsets = _ref2.roundOffsets, isFixed = _ref2.isFixed;
var _offsets$x = offsets.x, x = _offsets$x === void 0 ? 0 : _offsets$x, _offsets$y = offsets.y, y = _offsets$y === void 0 ? 0 : _offsets$y;
var _ref3 = typeof roundOffsets === "function" ? roundOffsets({
x,
y
}) : {
x,
y
};
x = _ref3.x;
y = _ref3.y;
var hasX = offsets.hasOwnProperty("x");
var hasY = offsets.hasOwnProperty("y");
var sideX = left;
var sideY = top;
var win = window;
if (adaptive) {
var offsetParent = getOffsetParent(popper2);
var heightProp = "clientHeight";
var widthProp = "clientWidth";
if (offsetParent === getWindow(popper2)) {
offsetParent = getDocumentElement(popper2);
if (getComputedStyle(offsetParent).position !== "static" && position === "absolute") {
heightProp = "scrollHeight";
widthProp = "scrollWidth";
}
}
offsetParent = offsetParent;
if (placement === top || (placement === left || placement === right) && variation === end) {
sideY = bottom;
var offsetY = isFixed && offsetParent === win && win.visualViewport ? win.visualViewport.height : (
// $FlowFixMe[prop-missing]
offsetParent[heightProp]
);
y -= offsetY - popperRect.height;
y *= gpuAcceleration ? 1 : -1;
}
if (placement === left || (placement === top || placement === bottom) && variation === end) {
sideX = right;
var offsetX = isFixed && offsetParent === win && win.visualViewport ? win.visualViewport.width : (
// $FlowFixMe[prop-missing]
offsetParent[widthProp]
);
x -= offsetX - popperRect.width;
x *= gpuAcceleration ? 1 : -1;
}
}
var commonStyles = Object.assign({
position
}, adaptive && unsetSides);
var _ref4 = roundOffsets === true ? roundOffsetsByDPR({
x,
y
}, getWindow(popper2)) : {
x,
y
};
x = _ref4.x;
y = _ref4.y;
if (gpuAcceleration) {
var _Object$assign;
return Object.assign({}, commonStyles, (_Object$assign = {}, _Object$assign[sideY] = hasY ? "0" : "", _Object$assign[sideX] = hasX ? "0" : "", _Object$assign.transform = (win.devicePixelRatio || 1) <= 1 ? "translate(" + x + "px, " + y + "px)" : "translate3d(" + x + "px, " + y + "px, 0)", _Object$assign));
}
return Object.assign({}, commonStyles, (_Object$assign2 = {}, _Object$assign2[sideY] = hasY ? y + "px" : "", _Object$assign2[sideX] = hasX ? x + "px" : "", _Object$assign2.transform = "", _Object$assign2));
}
function computeStyles(_ref5) {
var state = _ref5.state, options = _ref5.options;
var _options$gpuAccelerat = options.gpuAcceleration, gpuAcceleration = _options$gpuAccelerat === void 0 ? true : _options$gpuAccelerat, _options$adaptive = options.adaptive, adaptive = _options$adaptive === void 0 ? true : _options$adaptive, _options$roundOffsets = options.roundOffsets, roundOffsets = _options$roundOffsets === void 0 ? true : _options$roundOffsets;
var commonStyles = {
placement: getBasePlacement(state.placement),
variation: getVariation(state.placement),
popper: state.elements.popper,
popperRect: state.rects.popper,
gpuAcceleration,
isFixed: state.options.strategy === "fixed"
};
if (state.modifiersData.popperOffsets != null) {
state.styles.popper = Object.assign({}, state.styles.popper, mapToStyles(Object.assign({}, commonStyles, {
offsets: state.modifiersData.popperOffsets,
position: state.options.strategy,
adaptive,
roundOffsets
})));
}
if (state.modifiersData.arrow != null) {
state.styles.arrow = Object.assign({}, state.styles.arrow, mapToStyles(Object.assign({}, commonStyles, {
offsets: state.modifiersData.arrow,
position: "absolute",
adaptive: false,
roundOffsets
})));
}
state.attributes.popper = Object.assign({}, state.attributes.popper, {
"data-popper-placement": state.placement
});
}
var computeStyles_default = {
name: "computeStyles",
enabled: true,
phase: "beforeWrite",
fn: computeStyles,
data: {}
};
// node_modules/@popperjs/core/lib/modifiers/eventListeners.js
var passive = {
passive: true
};
function effect3(_ref) {
var state = _ref.state, instance = _ref.instance, options = _ref.options;
var _options$scroll = options.scroll, scroll = _options$scroll === void 0 ? true : _options$scroll, _options$resize = options.resize, resize = _options$resize === void 0 ? true : _options$resize;
var window2 = getWindow(state.elements.popper);
var scrollParents = [].concat(state.scrollParents.reference, state.scrollParents.popper);
if (scroll) {
scrollParents.forEach(function(scrollParent) {
scrollParent.addEventListener("scroll", instance.update, passive);
});
}
if (resize) {
window2.addEventListener("resize", instance.update, passive);
}
return function() {
if (scroll) {
scrollParents.forEach(function(scrollParent) {
scrollParent.removeEventListener("scroll", instance.update, passive);
});
}
if (resize) {
window2.removeEventListener("resize", instance.update, passive);
}
};
}
var eventListeners_default = {
name: "eventListeners",
enabled: true,
phase: "write",
fn: function fn() {
},
effect: effect3,
data: {}
};
// node_modules/@popperjs/core/lib/utils/getOppositePlacement.js
var hash = {
left: "right",
right: "left",
bottom: "top",
top: "bottom"
};
function getOppositePlacement(placement) {
return placement.replace(/left|right|bottom|top/g, function(matched) {
return hash[matched];
});
}
// node_modules/@popperjs/core/lib/utils/getOppositeVariationPlacement.js
var hash2 = {
start: "end",
end: "start"
};
function getOppositeVariationPlacement(placement) {
return placement.replace(/start|end/g, function(matched) {
return hash2[matched];
});
}
// node_modules/@popperjs/core/lib/dom-utils/getWindowScroll.js
function getWindowScroll(node) {
var win = getWindow(node);
var scrollLeft = win.pageXOffset;
var scrollTop = win.pageYOffset;
return {
scrollLeft,
scrollTop
};
}
// node_modules/@popperjs/core/lib/dom-utils/getWindowScrollBarX.js
function getWindowScrollBarX(element) {
return getBoundingClientRect(getDocumentElement(element)).left + getWindowScroll(element).scrollLeft;
}
// node_modules/@popperjs/core/lib/dom-utils/getViewportRect.js
function getViewportRect(element, strategy) {
var win = getWindow(element);
var html = getDocumentElement(element);
var visualViewport = win.visualViewport;
var width = html.clientWidth;
var height = html.clientHeight;
var x = 0;
var y = 0;
if (visualViewport) {
width = visualViewport.width;
height = visualViewport.height;
var layoutViewport = isLayoutViewport();
if (layoutViewport || !layoutViewport && strategy === "fixed") {
x = visualViewport.offsetLeft;
y = visualViewport.offsetTop;
}
}
return {
width,
height,
x: x + getWindowScrollBarX(element),
y
};
}
// node_modules/@popperjs/core/lib/dom-utils/getDocumentRect.js
function getDocumentRect(element) {
var _element$ownerDocumen;
var html = getDocumentElement(element);
var winScroll = getWindowScroll(element);
var body = (_element$ownerDocumen = element.ownerDocument) == null ? void 0 : _element$ownerDocumen.body;
var width = max(html.scrollWidth, html.clientWidth, body ? body.scrollWidth : 0, body ? body.clientWidth : 0);
var height = max(html.scrollHeight, html.clientHeight, body ? body.scrollHeight : 0, body ? body.clientHeight : 0);
var x = -winScroll.scrollLeft + getWindowScrollBarX(element);
var y = -winScroll.scrollTop;
if (getComputedStyle(body || html).direction === "rtl") {
x += max(html.clientWidth, body ? body.clientWidth : 0) - width;
}
return {
width,
height,
x,
y
};
}
// node_modules/@popperjs/core/lib/dom-utils/isScrollParent.js
function isScrollParent(element) {
var _getComputedStyle = getComputedStyle(element), overflow = _getComputedStyle.overflow, overflowX = _getComputedStyle.overflowX, overflowY = _getComputedStyle.overflowY;
return /auto|scroll|overlay|hidden/.test(overflow + overflowY + overflowX);
}
// node_modules/@popperjs/core/lib/dom-utils/getScrollParent.js
function getScrollParent(node) {
if (["html", "body", "#document"].indexOf(getNodeName(node)) >= 0) {
return node.ownerDocument.body;
}
if (isHTMLElement(node) && isScrollParent(node)) {
return node;
}
return getScrollParent(getParentNode(node));
}
// node_modules/@popperjs/core/lib/dom-utils/listScrollParents.js
function listScrollParents(element, list) {
var _element$ownerDocumen;
if (list === void 0) {
list = [];
}
var scrollParent = getScrollParent(element);
var isBody = scrollParent === ((_element$ownerDocumen = element.ownerDocument) == null ? void 0 : _element$ownerDocumen.body);
var win = getWindow(scrollParent);
var target = isBody ? [win].concat(win.visualViewport || [], isScrollParent(scrollParent) ? scrollParent : []) : scrollParent;
var updatedList = list.concat(target);
return isBody ? updatedList : (
// $FlowFixMe[incompatible-call]: isBody tells us target will be an HTMLElement here
updatedList.concat(listScrollParents(getParentNode(target)))
);
}
// node_modules/@popperjs/core/lib/utils/rectToClientRect.js
function rectToClientRect(rect) {
return Object.assign({}, rect, {
left: rect.x,
top: rect.y,
right: rect.x + rect.width,
bottom: rect.y + rect.height
});
}
// node_modules/@popperjs/core/lib/dom-utils/getClippingRect.js
function getInnerBoundingClientRect(element, strategy) {
var rect = getBoundingClientRect(element, false, strategy === "fixed");
rect.top = rect.top + element.clientTop;
rect.left = rect.left + element.clientLeft;
rect.bottom = rect.top + element.clientHeight;
rect.right = rect.left + element.clientWidth;
rect.width = element.clientWidth;
rect.height = element.clientHeight;
rect.x = rect.left;
rect.y = rect.top;
return rect;
}
function getClientRectFromMixedType(element, clippingParent, strategy) {
return clippingParent === viewport ? rectToClientRect(getViewportRect(element, strategy)) : isElement(clippingParent) ? getInnerBoundingClientRect(clippingParent, strategy) : rectToClientRect(getDocumentRect(getDocumentElement(element)));
}
function getClippingParents(element) {
var clippingParents2 = listScrollParents(getParentNode(element));
var canEscapeClipping = ["absolute", "fixed"].indexOf(getComputedStyle(element).position) >= 0;
var clipperElement = canEscapeClipping && isHTMLElement(element) ? getOffsetParent(element) : element;
if (!isElement(clipperElement)) {
return [];
}
return clippingParents2.filter(function(clippingParent) {
return isElement(clippingParent) && contains(clippingParent, clipperElement) && getNodeName(clippingParent) !== "body";
});
}
function getClippingRect(element, boundary, rootBoundary, strategy) {
var mainClippingParents = boundary === "clippingParents" ? getClippingParents(element) : [].concat(boundary);
var clippingParents2 = [].concat(mainClippingParents, [rootBoundary]);
var firstClippingParent = clippingParents2[0];
var clippingRect = clippingParents2.reduce(function(accRect, clippingParent) {
var rect = getClientRectFromMixedType(element, clippingParent, 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;
}, getClientRectFromMixedType(element, firstClippingParent, strategy));
clippingRect.width = clippingRect.right - clippingRect.left;
clippingRect.height = clippingRect.bottom - clippingRect.top;
clippingRect.x = clippingRect.left;
clippingRect.y = clippingRect.top;
return clippingRect;
}
// node_modules/@popperjs/core/lib/utils/computeOffsets.js
function computeOffsets(_ref) {
var reference2 = _ref.reference, element = _ref.element, placement = _ref.placement;
var basePlacement = placement ? getBasePlacement(placement) : null;
var variation = placement ? getVariation(placement) : null;
var commonX = reference2.x + reference2.width / 2 - element.width / 2;
var commonY = reference2.y + reference2.height / 2 - element.height / 2;
var offsets;
switch (basePlacement) {
case top:
offsets = {
x: commonX,
y: reference2.y - element.height
};
break;
case bottom:
offsets = {
x: commonX,
y: reference2.y + reference2.height
};
break;
case right:
offsets = {
x: reference2.x + reference2.width,
y: commonY
};
break;
case left:
offsets = {
x: reference2.x - element.width,
y: commonY
};
break;
default:
offsets = {
x: reference2.x,
y: reference2.y
};
}
var mainAxis = basePlacement ? getMainAxisFromPlacement(basePlacement) : null;
if (mainAxis != null) {
var len = mainAxis === "y" ? "height" : "width";
switch (variation) {
case start:
offsets[mainAxis] = offsets[mainAxis] - (reference2[len] / 2 - element[len] / 2);
break;
case end:
offsets[mainAxis] = offsets[mainAxis] + (reference2[len] / 2 - element[len] / 2);
break;
default:
}
}
return offsets;
}
// node_modules/@popperjs/core/lib/utils/detectOverflow.js
function detectOverflow(state, options) {
if (options === void 0) {
options = {};
}
var _options = options, _options$placement = _options.placement, placement = _options$placement === void 0 ? state.placement : _options$placement, _options$strategy = _options.strategy, strategy = _options$strategy === void 0 ? state.strategy : _options$strategy, _options$boundary = _options.boundary, boundary = _options$boundary === void 0 ? clippingParents : _options$boundary, _options$rootBoundary = _options.rootBoundary, rootBoundary = _options$rootBoundary === void 0 ? viewport : _options$rootBoundary, _options$elementConte = _options.elementContext, elementContext = _options$elementConte === void 0 ? popper : _options$elementConte, _options$altBoundary = _options.altBoundary, altBoundary = _options$altBoundary === void 0 ? false : _options$altBoundary, _options$padding = _options.padding, padding = _options$padding === void 0 ? 0 : _options$padding;
var paddingObject = mergePaddingObject(typeof padding !== "number" ? padding : expandToHashMap(padding, basePlacements));
var altContext = elementContext === popper ? reference : popper;
var popperRect = state.rects.popper;
var element = state.elements[altBoundary ? altContext : elementContext];
var clippingClientRect = getClippingRect(isElement(element) ? element : element.contextElement || getDocumentElement(state.elements.popper), boundary, rootBoundary, strategy);
var referenceClientRect = getBoundingClientRect(state.elements.reference);
var popperOffsets2 = computeOffsets({
reference: referenceClientRect,
element: popperRect,
strategy: "absolute",
placement
});
var popperClientRect = rectToClientRect(Object.assign({}, popperRect, popperOffsets2));
var elementClientRect = elementContext === popper ? popperClientRect : referenceClientRect;
var overflowOffsets = {
top: clippingClientRect.top - elementClientRect.top + paddingObject.top,
bottom: elementClientRect.bottom - clippingClientRect.bottom + paddingObject.bottom,
left: clippingClientRect.left - elementClientRect.left + paddingObject.left,
right: elementClientRect.right - clippingClientRect.right + paddingObject.right
};
var offsetData = state.modifiersData.offset;
if (elementContext === popper && offsetData) {
var offset2 = offsetData[placement];
Object.keys(overflowOffsets).forEach(function(key) {
var multiply = [right, bottom].indexOf(key) >= 0 ? 1 : -1;
var axis = [top, bottom].indexOf(key) >= 0 ? "y" : "x";
overflowOffsets[key] += offset2[axis] * multiply;
});
}
return overflowOffsets;
}
// node_modules/@popperjs/core/lib/utils/computeAutoPlacement.js
function computeAutoPlacement(state, options) {
if (options === void 0) {
options = {};
}
var _options = options, placement = _options.placement, boundary = _options.boundary, rootBoundary = _options.rootBoundary, padding = _options.padding, flipVariations = _options.flipVariations, _options$allowedAutoP = _options.allowedAutoPlacements, allowedAutoPlacements = _options$allowedAutoP === void 0 ? placements : _options$allowedAutoP;
var variation = getVariation(placement);
var placements2 = variation ? flipVariations ? variationPlacements : variationPlacements.filter(function(placement2) {
return getVariation(placement2) === variation;
}) : basePlacements;
var allowedPlacements = placements2.filter(function(placement2) {
return allowedAutoPlacements.indexOf(placement2) >= 0;
});
if (allowedPlacements.length === 0) {
allowedPlacements = placements2;
}
var overflows = allowedPlacements.reduce(function(acc, placement2) {
acc[placement2] = detectOverflow(state, {
placement: placement2,
boundary,
rootBoundary,
padding
})[getBasePlacement(placement2)];
return acc;
}, {});
return Object.keys(overflows).sort(function(a, b) {
return overflows[a] - overflows[b];
});
}
// node_modules/@popperjs/core/lib/modifiers/flip.js
function getExpandedFallbackPlacements(placement) {
if (getBasePlacement(placement) === auto) {
return [];
}
var oppositePlacement = getOppositePlacement(placement);
return [getOppositeVariationPlacement(placement), oppositePlacement, getOppositeVariationPlacement(oppositePlacement)];
}
function flip(_ref) {
var state = _ref.state, options = _ref.options, name = _ref.name;
if (state.modifiersData[name]._skip) {
return;
}
var _options$mainAxis = options.mainAxis, checkMainAxis = _options$mainAxis === void 0 ? true : _options$mainAxis, _options$altAxis = options.altAxis, checkAltAxis = _options$altAxis === void 0 ? true : _options$altAxis, specifiedFallbackPlacements = options.fallbackPlacements, padding = options.padding, boundary = options.boundary, rootBoundary = options.rootBoundary, altBoundary = options.altBoundary, _options$flipVariatio = options.flipVariations, flipVariations = _options$flipVariatio === void 0 ? true : _options$flipVariatio, allowedAutoPlacements = options.allowedAutoPlacements;
var preferredPlacement = state.options.placement;
var basePlacement = getBasePlacement(preferredPlacement);
var isBasePlacement = basePlacement === preferredPlacement;
var fallbackPlacements = specifiedFallbackPlacements || (isBasePlacement || !flipVariations ? [getOppositePlacement(preferredPlacement)] : getExpandedFallbackPlacements(preferredPlacement));
var placements2 = [preferredPlacement].concat(fallbackPlacements).reduce(function(acc, placement2) {
return acc.concat(getBasePlacement(placement2) === auto ? computeAutoPlacement(state, {
placement: placement2,
boundary,
rootBoundary,
padding,
flipVariations,
allowedAutoPlacements
}) : placement2);
}, []);
var referenceRect = state.rects.reference;
var popperRect = state.rects.popper;
var checksMap = /* @__PURE__ */ new Map();
var makeFallbackChecks = true;
var firstFittingPlacement = placements2[0];
for (var i = 0; i < placements2.length; i++) {
var placement = placements2[i];
var _basePlacement = getBasePlacement(placement);
var isStartVariation = getVariation(placement) === start;
var isVertical = [top, bottom].indexOf(_basePlacement) >= 0;
var len = isVertical ? "width" : "height";
var overflow = detectOverflow(state, {
placement,
boundary,
rootBoundary,
altBoundary,
padding
});
var mainVariationSide = isVertical ? isStartVariation ? right : left : isStartVariation ? bottom : top;
if (referenceRect[len] > popperRect[len]) {
mainVariationSide = getOppositePlacement(mainVariationSide);
}
var altVariationSide = getOppositePlacement(mainVariationSide);
var checks = [];
if (checkMainAxis) {
checks.push(overflow[_basePlacement] <= 0);
}
if (checkAltAxis) {
checks.push(overflow[mainVariationSide] <= 0, overflow[altVariationSide] <= 0);
}
if (checks.every(function(check) {
return check;
})) {
firstFittingPlacement = placement;
makeFallbackChecks = false;
break;
}
checksMap.set(placement, checks);
}
if (makeFallbackChecks) {
var numberOfChecks = flipVariations ? 3 : 1;
var _loop = function _loop2(_i2) {
var fittingPlacement = placements2.find(function(placement2) {
var checks2 = checksMap.get(placement2);
if (checks2) {
return checks2.slice(0, _i2).every(function(check) {
return check;
});
}
});
if (fittingPlacement) {
firstFittingPlacement = fittingPlacement;
return "break";
}
};
for (var _i = numberOfChecks; _i > 0; _i--) {
var _ret = _loop(_i);
if (_ret === "break")
break;
}
}
if (state.placement !== firstFittingPlacement) {
state.modifiersData[name]._skip = true;
state.placement = firstFittingPlacement;
state.reset = true;
}
}
var flip_default = {
name: "flip",
enabled: true,
phase: "main",
fn: flip,
requiresIfExists: ["offset"],
data: {
_skip: false
}
};
// node_modules/@popperjs/core/lib/modifiers/hide.js
function getSideOffsets(overflow, rect, preventedOffsets) {
if (preventedOffsets === void 0) {
preventedOffsets = {
x: 0,
y: 0
};
}
return {
top: overflow.top - rect.height - preventedOffsets.y,
right: overflow.right - rect.width + preventedOffsets.x,
bottom: overflow.bottom - rect.height + preventedOffsets.y,
left: overflow.left - rect.width - preventedOffsets.x
};
}
function isAnySideFullyClipped(overflow) {
return [top, right, bottom, left].some(function(side) {
return overflow[side] >= 0;
});
}
function hide(_ref) {
var state = _ref.state, name = _ref.name;
var referenceRect = state.rects.reference;
var popperRect = state.rects.popper;
var preventedOffsets = state.modifiersData.preventOverflow;
var referenceOverflow = detectOverflow(state, {
elementContext: "reference"
});
var popperAltOverflow = detectOverflow(state, {
altBoundary: true
});
var referenceClippingOffsets = getSideOffsets(referenceOverflow, referenceRect);
var popperEscapeOffsets = getSideOffsets(popperAltOverflow, popperRect, preventedOffsets);
var isReferenceHidden = isAnySideFullyClipped(referenceClippingOffsets);
var hasPopperEscaped = isAnySideFullyClipped(popperEscapeOffsets);
state.modifiersData[name] = {
referenceClippingOffsets,
popperEscapeOffsets,
isReferenceHidden,
hasPopperEscaped
};
state.attributes.popper = Object.assign({}, state.attributes.popper, {
"data-popper-reference-hidden": isReferenceHidden,
"data-popper-escaped": hasPopperEscaped
});
}
var hide_default = {
name: "hide",
enabled: true,
phase: "main",
requiresIfExists: ["preventOverflow"],
fn: hide
};
// node_modules/@popperjs/core/lib/modifiers/offset.js
function distanceAndSkiddingToXY(placement, rects, offset2) {
var basePlacement = getBasePlacement(placement);
var invertDistance = [left, top].indexOf(basePlacement) >= 0 ? -1 : 1;
var _ref = typeof offset2 === "function" ? offset2(Object.assign({}, rects, {
placement
})) : offset2, skidding = _ref[0], distance = _ref[1];
skidding = skidding || 0;
distance = (distance || 0) * invertDistance;
return [left, right].indexOf(basePlacement) >= 0 ? {
x: distance,
y: skidding
} : {
x: skidding,
y: distance
};
}
function offset(_ref2) {
var state = _ref2.state, options = _ref2.options, name = _ref2.name;
var _options$offset = options.offset, offset2 = _options$offset === void 0 ? [0, 0] : _options$offset;
var data = placements.reduce(function(acc, placement) {
acc[placement] = distanceAndSkiddingToXY(placement, state.rects, offset2);
return acc;
}, {});
var _data$state$placement = data[state.placement], x = _data$state$placement.x, y = _data$state$placement.y;
if (state.modifiersData.popperOffsets != null) {
state.modifiersData.popperOffsets.x += x;
state.modifiersData.popperOffsets.y += y;
}
state.modifiersData[name] = data;
}
var offset_default = {
name: "offset",
enabled: true,
phase: "main",
requires: ["popperOffsets"],
fn: offset
};
// node_modules/@popperjs/core/lib/modifiers/popperOffsets.js
function popperOffsets(_ref) {
var state = _ref.state, name = _ref.name;
state.modifiersData[name] = computeOffsets({
reference: state.rects.reference,
element: state.rects.popper,
strategy: "absolute",
placement: state.placement
});
}
var popperOffsets_default = {
name: "popperOffsets",
enabled: true,
phase: "read",
fn: popperOffsets,
data: {}
};
// node_modules/@popperjs/core/lib/utils/getAltAxis.js
function getAltAxis(axis) {
return axis === "x" ? "y" : "x";
}
// node_modules/@popperjs/core/lib/modifiers/preventOverflow.js
function preventOverflow(_ref) {
var state = _ref.state, options = _ref.options, name = _ref.name;
var _options$mainAxis = options.mainAxis, checkMainAxis = _options$mainAxis === void 0 ? true : _options$mainAxis, _options$altAxis = options.altAxis, checkAltAxis = _options$altAxis === void 0 ? false : _options$altAxis, boundary = options.boundary, rootBoundary = options.rootBoundary, altBoundary = options.altBoundary, padding = options.padding, _options$tether = options.tether, tether = _options$tether === void 0 ? true : _options$tether, _options$tetherOffset = options.tetherOffset, tetherOffset = _options$tetherOffset === void 0 ? 0 : _options$tetherOffset;
var overflow = detectOverflow(state, {
boundary,
rootBoundary,
padding,
altBoundary
});
var basePlacement = getBasePlacement(state.placement);
var variation = getVariation(state.placement);
var isBasePlacement = !variation;
var mainAxis = getMainAxisFromPlacement(basePlacement);
var altAxis = getAltAxis(mainAxis);
var popperOffsets2 = state.modifiersData.popperOffsets;
var referenceRect = state.rects.reference;
var popperRect = state.rects.popper;
var tetherOffsetValue = typeof tetherOffset === "function" ? tetherOffset(Object.assign({}, state.rects, {
placement: state.placement
})) : tetherOffset;
var normalizedTetherOffsetValue = typeof tetherOffsetValue === "number" ? {
mainAxis: tetherOffsetValue,
altAxis: tetherOffsetValue
} : Object.assign({
mainAxis: 0,
altAxis: 0
}, tetherOffsetValue);
var offsetModifierState = state.modifiersData.offset ? state.modifiersData.offset[state.placement] : null;
var data = {
x: 0,
y: 0
};
if (!popperOffsets2) {
return;
}
if (checkMainAxis) {
var _offsetModifierState$;
var mainSide = mainAxis === "y" ? top : left;
var altSide = mainAxis === "y" ? bottom : right;
var len = mainAxis === "y" ? "height" : "width";
var offset2 = popperOffsets2[mainAxis];
var min2 = offset2 + overflow[mainSide];
var max2 = offset2 - overflow[altSide];
var additive = tether ? -popperRect[len] / 2 : 0;
var minLen = variation === start ? referenceRect[len] : popperRect[len];
var maxLen = variation === start ? -popperRect[len] : -referenceRect[len];
var arrowElement = state.elements.arrow;
var arrowRect = tether && arrowElement ? getLayoutRect(arrowElement) : {
width: 0,
height: 0
};
var arrowPaddingObject = state.modifiersData["arrow#persistent"] ? state.modifiersData["arrow#persistent"].padding : getFreshSideObject();
var arrowPaddingMin = arrowPaddingObject[mainSide];
var arrowPaddingMax = arrowPaddingObject[altSide];
var arrowLen = within(0, referenceRect[len], arrowRect[len]);
var minOffset = isBasePlacement ? referenceRect[len] / 2 - additive - arrowLen - arrowPaddingMin - normalizedTetherOffsetValue.mainAxis : minLen - arrowLen - arrowPaddingMin - normalizedTetherOffsetValue.mainAxis;
var maxOffset = isBasePlacement ? -referenceRect[len] / 2 + additive + arrowLen + arrowPaddingMax + normalizedTetherOffsetValue.mainAxis : maxLen + arrowLen + arrowPaddingMax + normalizedTetherOffsetValue.mainAxis;
var arrowOffsetParent = state.elements.arrow && getOffsetParent(state.elements.arrow);
var clientOffset = arrowOffsetParent ? mainAxis === "y" ? arrowOffsetParent.clientTop || 0 : arrowOffsetParent.clientLeft || 0 : 0;
var offsetModifierValue = (_offsetModifierState$ = offsetModifierState == null ? void 0 : offsetModifierState[mainAxis]) != null ? _offsetModifierState$ : 0;
var tetherMin = offset2 + minOffset - offsetModifierValue - clientOffset;
var tetherMax = offset2 + maxOffset - offsetModifierValue;
var preventedOffset = within(tether ? min(min2, tetherMin) : min2, offset2, tether ? max(max2, tetherMax) : max2);
popperOffsets2[mainAxis] = preventedOffset;
data[mainAxis] = preventedOffset - offset2;
}
if (checkAltAxis) {
var _offsetModifierState$2;
var _mainSide = mainAxis === "x" ? top : left;
var _altSide = mainAxis === "x" ? bottom : right;
var _offset = popperOffsets2[altAxis];
var _len = altAxis === "y" ? "height" : "width";
var _min = _offset + overflow[_mainSide];
var _max = _offset - overflow[_altSide];
var isOriginSide = [top, left].indexOf(basePlacement) !== -1;
var _offsetModifierValue = (_offsetModifierState$2 = offsetModifierState == null ? void 0 : offsetModifierState[altAxis]) != null ? _offsetModifierState$2 : 0;
var _tetherMin = isOriginSide ? _min : _offset - referenceRect[_len] - popperRect[_len] - _offsetModifierValue + normalizedTetherOffsetValue.altAxis;
var _tetherMax = isOriginSide ? _offset + referenceRect[_len] + popperRect[_len] - _offsetModifierValue - normalizedTetherOffsetValue.altAxis : _max;
var _preventedOffset = tether && isOriginSide ? withinMaxClamp(_tetherMin, _offset, _tetherMax) : within(tether ? _tetherMin : _min, _offset, tether ? _tetherMax : _max);
popperOffsets2[altAxis] = _preventedOffset;
data[altAxis] = _preventedOffset - _offset;
}
state.modifiersData[name] = data;
}
var preventOverflow_default = {
name: "preventOverflow",
enabled: true,
phase: "main",
fn: preventOverflow,
requiresIfExists: ["offset"]
};
// node_modules/@popperjs/core/lib/dom-utils/getHTMLElementScroll.js
function getHTMLElementScroll(element) {
return {
scrollLeft: element.scrollLeft,
scrollTop: element.scrollTop
};
}
// node_modules/@popperjs/core/lib/dom-utils/getNodeScroll.js
function getNodeScroll(node) {
if (node === getWindow(node) || !isHTMLElement(node)) {
return getWindowScroll(node);
} else {
return getHTMLElementScroll(node);
}
}
// node_modules/@popperjs/core/lib/dom-utils/getCompositeRect.js
function isElementScaled(element) {
var rect = element.getBoundingClientRect();
var scaleX = round(rect.width) / element.offsetWidth || 1;
var scaleY = round(rect.height) / element.offsetHeight || 1;
return scaleX !== 1 || scaleY !== 1;
}
function getCompositeRect(elementOrVirtualElement, offsetParent, isFixed) {
if (isFixed === void 0) {
isFixed = false;
}
var isOffsetParentAnElement = isHTMLElement(offsetParent);
var offsetParentIsScaled = isHTMLElement(offsetParent) && isElementScaled(offsetParent);
var documentElement = getDocumentElement(offsetParent);
var rect = getBoundingClientRect(elementOrVirtualElement, offsetParentIsScaled, isFixed);
var scroll = {
scrollLeft: 0,
scrollTop: 0
};
var offsets = {
x: 0,
y: 0
};
if (isOffsetParentAnElement || !isOffsetParentAnElement && !isFixed) {
if (getNodeName(offsetParent) !== "body" || // https://github.com/popperjs/popper-core/issues/1078
isScrollParent(documentElement)) {
scroll = getNodeScroll(offsetParent);
}
if (isHTMLElement(offsetParent)) {
offsets = getBoundingClientRect(offsetParent, true);
offsets.x += offsetParent.clientLeft;
offsets.y += offsetParent.clientTop;
} else if (documentElement) {
offsets.x = getWindowScrollBarX(documentElement);
}
}
return {
x: rect.left + scroll.scrollLeft - offsets.x,
y: rect.top + scroll.scrollTop - offsets.y,
width: rect.width,
height: rect.height
};
}
// node_modules/@popperjs/core/lib/utils/orderModifiers.js
function order(modifiers) {
var map = /* @__PURE__ */ new Map();
var visited = /* @__PURE__ */ new Set();
var result = [];
modifiers.forEach(function(modifier) {
map.set(modifier.name, modifier);
});
function sort(modifier) {
visited.add(modifier.name);
var requires = [].concat(modifier.requires || [], modifier.requiresIfExists || []);
requires.forEach(function(dep) {
if (!visited.has(dep)) {
var depModifier = map.get(dep);
if (depModifier) {
sort(depModifier);
}
}
});
result.push(modifier);
}
modifiers.forEach(function(modifier) {
if (!visited.has(modifier.name)) {
sort(modifier);
}
});
return result;
}
function orderModifiers(modifiers) {
var orderedModifiers = order(modifiers);
return modifierPhases.reduce(function(acc, phase) {
return acc.concat(orderedModifiers.filter(function(modifier) {
return modifier.phase === phase;
}));
}, []);
}
// node_modules/@popperjs/core/lib/utils/debounce.js
function debounce2(fn2) {
var pending;
return function() {
if (!pending) {
pending = new Promise(function(resolve) {
Promise.resolve().then(function() {
pending = void 0;
resolve(fn2());
});
});
}
return pending;
};
}
// node_modules/@popperjs/core/lib/utils/mergeByName.js
function mergeByName(modifiers) {
var merged = modifiers.reduce(function(merged2, current) {
var existing = merged2[current.name];
merged2[current.name] = existing ? Object.assign({}, existing, current, {
options: Object.assign({}, existing.options, current.options),
data: Object.assign({}, existing.data, current.data)
}) : current;
return merged2;
}, {});
return Object.keys(merged).map(function(key) {
return merged[key];
});
}
// node_modules/@popperjs/core/lib/createPopper.js
var DEFAULT_OPTIONS = {
placement: "bottom",
modifiers: [],
strategy: "absolute"
};
function areValidElements() {
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
return !args.some(function(element) {
return !(element && typeof element.getBoundingClientRect === "function");
});
}
function popperGenerator(generatorOptions) {
if (generatorOptions === void 0) {
generatorOptions = {};
}
var _generatorOptions = generatorOptions, _generatorOptions$def = _generatorOptions.defaultModifiers, defaultModifiers2 = _generatorOptions$def === void 0 ? [] : _generatorOptions$def, _generatorOptions$def2 = _generatorOptions.defaultOptions, defaultOptions2 = _generatorOptions$def2 === void 0 ? DEFAULT_OPTIONS : _generatorOptions$def2;
return function createPopper2(reference2, popper2, options) {
if (options === void 0) {
options = defaultOptions2;
}
var state = {
placement: "bottom",
orderedModifiers: [],
options: Object.assign({}, DEFAULT_OPTIONS, defaultOptions2),
modifiersData: {},
elements: {
reference: reference2,
popper: popper2
},
attributes: {},
styles: {}
};
var effectCleanupFns = [];
var isDestroyed = false;
var instance = {
state,
setOptions: function setOptions(setOptionsAction) {
var options2 = typeof setOptionsAction === "function" ? setOptionsAction(state.options) : setOptionsAction;
cleanupModifierEffects();
state.options = Object.assign({}, defaultOptions2, state.options, options2);
state.scrollParents = {
reference: isElement(reference2) ? listScrollParents(reference2) : reference2.contextElement ? listScrollParents(reference2.contextElement) : [],
popper: listScrollParents(popper2)
};
var orderedModifiers = orderModifiers(mergeByName([].concat(defaultModifiers2, state.options.modifiers)));
state.orderedModifiers = orderedModifiers.filter(function(m) {
return m.enabled;
});
runModifierEffects();
return instance.update();
},
// Sync update – it will always be executed, even if not necessary. This
// is useful for low frequency updates where sync behavior simplifies the
// logic.
// For high frequency updates (e.g. `resize` and `scroll` events), always
// prefer the async Popper#update method
forceUpdate: function forceUpdate() {
if (isDestroyed) {
return;
}
var _state$elements = state.elements, reference3 = _state$elements.reference, popper3 = _state$elements.popper;
if (!areValidElements(reference3, popper3)) {
return;
}
state.rects = {
reference: getCompositeRect(reference3, getOffsetParent(popper3), state.options.strategy === "fixed"),
popper: getLayoutRect(popper3)
};
state.reset = false;
state.placement = state.options.placement;
state.orderedModifiers.forEach(function(modifier) {
return state.modifiersData[modifier.name] = Object.assign({}, modifier.data);
});
for (var index = 0; index < state.orderedModifiers.length; index++) {
if (state.reset === true) {
state.reset = false;
index = -1;
continue;
}
var _state$orderedModifie = state.orderedModifiers[index], fn2 = _state$orderedModifie.fn, _state$orderedModifie2 = _state$orderedModifie.options, _options = _state$orderedModifie2 === void 0 ? {} : _state$orderedModifie2, name = _state$orderedModifie.name;
if (typeof fn2 === "function") {
state = fn2({
state,
options: _options,
name,
instance
}) || state;
}
}
},
// Async and optimistically optimized update – it will not be executed if
// not necessary (debounced to run at most once-per-tick)
update: debounce2(function() {
return new Promise(function(resolve) {
instance.forceUpdate();
resolve(state);
});
}),
destroy: function destroy() {
cleanupModifierEffects();
isDestroyed = true;
}
};
if (!areValidElements(reference2, popper2)) {
return instance;
}
instance.setOptions(options).then(function(state2) {
if (!isDestroyed && options.onFirstUpdate) {
options.onFirstUpdate(state2);
}
});
function runModifierEffects() {
state.orderedModifiers.forEach(function(_ref) {
var name = _ref.name, _ref$options = _ref.options, options2 = _ref$options === void 0 ? {} : _ref$options, effect4 = _ref.effect;
if (typeof effect4 === "function") {
var cleanupFn = effect4({
state,
name,
instance,
options: options2
});
var noopFn = function noopFn2() {
};
effectCleanupFns.push(cleanupFn || noopFn);
}
});
}
function cleanupModifierEffects() {
effectCleanupFns.forEach(function(fn2) {
return fn2();
});
effectCleanupFns = [];
}
return instance;
};
}
// node_modules/@popperjs/core/lib/popper.js
var defaultModifiers = [eventListeners_default, popperOffsets_default, computeStyles_default, applyStyles_default, offset_default, flip_default, preventOverflow_default, arrow_default, hide_default];
var createPopper = /* @__PURE__ */ popperGenerator({
defaultModifiers
});
// node_modules/flowbite/lib/esm/components/dropdown/index.js
var __assign5 = function() {
__assign5 = Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s)
if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign5.apply(this, arguments);
};
var __spreadArray = function(to, from, pack) {
if (pack || arguments.length === 2)
for (var i = 0, l = from.length, ar; i < l; i++) {
if (ar || !(i in from)) {
if (!ar)
ar = Array.prototype.slice.call(from, 0, i);
ar[i] = from[i];
}
}
return to.concat(ar || Array.prototype.slice.call(from));
};
var Default5 = {
placement: "bottom",
triggerType: "click",
offsetSkidding: 0,
offsetDistance: 10,
delay: 300,
ignoreClickOutsideClass: false,
onShow: function() {
},
onHide: function() {
},
onToggle: function() {
}
};
var DefaultInstanceOptions5 = {
id: null,
override: true
};
var Dropdown = (
/** @class */
function() {
function Dropdown2(targetElement, triggerElement, options, instanceOptions) {
if (targetElement === void 0) {
targetElement = null;
}
if (triggerElement === void 0) {
triggerElement = null;
}
if (options === void 0) {
options = Default5;
}
if (instanceOptions === void 0) {
instanceOptions = DefaultInstanceOptions5;
}
this._instanceId = instanceOptions.id ? instanceOptions.id : targetElement.id;
this._targetEl = targetElement;
this._triggerEl = triggerElement;
this._options = __assign5(__assign5({}, Default5), options);
this._popperInstance = null;
this._visible = false;
this._initialized = false;
this.init();
instances_default.addInstance("Dropdown", this, this._instanceId, instanceOptions.override);
}
Dropdown2.prototype.init = function() {
if (this._triggerEl && this._targetEl && !this._initialized) {
this._popperInstance = this._createPopperInstance();
this._setupEventListeners();
this._initialized = true;
}
};
Dropdown2.prototype.destroy = function() {
var _this = this;
var triggerEvents = this._getTriggerEvents();
if (this._options.triggerType === "click") {
triggerEvents.showEvents.forEach(function(ev) {
_this._triggerEl.removeEventListener(ev, _this._clickHandler);
});
}
if (this._options.triggerType === "hover") {
triggerEvents.showEvents.forEach(function(ev) {
_this._triggerEl.removeEventListener(ev, _this._hoverShowTriggerElHandler);
_this._targetEl.removeEventListener(ev, _this._hoverShowTargetElHandler);
});
triggerEvents.hideEvents.forEach(function(ev) {
_this._triggerEl.removeEventListener(ev, _this._hoverHideHandler);
_this._targetEl.removeEventListener(ev, _this._hoverHideHandler);
});
}
this._popperInstance.destroy();
this._initialized = false;
};
Dropdown2.prototype.removeInstance = function() {
instances_default.removeInstance("Dropdown", this._instanceId);
};
Dropdown2.prototype.destroyAndRemoveInstance = function() {
this.destroy();
this.removeInstance();
};
Dropdown2.prototype._setupEventListeners = function() {
var _this = this;
var triggerEvents = this._getTriggerEvents();
this._clickHandler = function() {
_this.toggle();
};
if (this._options.triggerType === "click") {
triggerEvents.showEvents.forEach(function(ev) {
_this._triggerEl.addEventListener(ev, _this._clickHandler);
});
}
this._hoverShowTriggerElHandler = function(ev) {
if (ev.type === "click") {
_this.toggle();
} else {
setTimeout(function() {
_this.show();
}, _this._options.delay);
}
};
this._hoverShowTargetElHandler = function() {
_this.show();
};
this._hoverHideHandler = function() {
setTimeout(function() {
if (!_this._targetEl.matches(":hover")) {
_this.hide();
}
}, _this._options.delay);
};
if (this._options.triggerType === "hover") {
triggerEvents.showEvents.forEach(function(ev) {
_this._triggerEl.addEventListener(ev, _this._hoverShowTriggerElHandler);
_this._targetEl.addEventListener(ev, _this._hoverShowTargetElHandler);
});
triggerEvents.hideEvents.forEach(function(ev) {
_this._triggerEl.addEventListener(ev, _this._hoverHideHandler);
_this._targetEl.addEventListener(ev, _this._hoverHideHandler);
});
}
};
Dropdown2.prototype._createPopperInstance = function() {
return createPopper(this._triggerEl, this._targetEl, {
placement: this._options.placement,
modifiers: [
{
name: "offset",
options: {
offset: [
this._options.offsetSkidding,
this._options.offsetDistance
]
}
}
]
});
};
Dropdown2.prototype._setupClickOutsideListener = function() {
var _this = this;
this._clickOutsideEventListener = function(ev) {
_this._handleClickOutside(ev, _this._targetEl);
};
document.body.addEventListener("click", this._clickOutsideEventListener, true);
};
Dropdown2.prototype._removeClickOutsideListener = function() {
document.body.removeEventListener("click", this._clickOutsideEventListener, true);
};
Dropdown2.prototype._handleClickOutside = function(ev, targetEl) {
var clickedEl = ev.target;
var ignoreClickOutsideClass = this._options.ignoreClickOutsideClass;
var isIgnored = false;
if (ignoreClickOutsideClass) {
var ignoredClickOutsideEls = document.querySelectorAll(".".concat(ignoreClickOutsideClass));
ignoredClickOutsideEls.forEach(function(el) {
if (el.contains(clickedEl)) {
isIgnored = true;
return;
}
});
}
if (clickedEl !== targetEl && !targetEl.contains(clickedEl) && !this._triggerEl.contains(clickedEl) && !isIgnored && this.isVisible()) {
this.hide();
}
};
Dropdown2.prototype._getTriggerEvents = function() {
switch (this._options.triggerType) {
case "hover":
return {
showEvents: ["mouseenter", "click"],
hideEvents: ["mouseleave"]
};
case "click":
return {
showEvents: ["click"],
hideEvents: []
};
case "none":
return {
showEvents: [],
hideEvents: []
};
default:
return {
showEvents: ["click"],
hideEvents: []
};
}
};
Dropdown2.prototype.toggle = function() {
if (this.isVisible()) {
this.hide();
} else {
this.show();
}
this._options.onToggle(this);
};
Dropdown2.prototype.isVisible = function() {
return this._visible;
};
Dropdown2.prototype.show = function() {
this._targetEl.classList.remove("hidden");
this._targetEl.classList.add("block");
this._popperInstance.setOptions(function(options) {
return __assign5(__assign5({}, options), { modifiers: __spreadArray(__spreadArray([], options.modifiers, true), [
{ name: "eventListeners", enabled: true }
], false) });
});
this._setupClickOutsideListener();
this._popperInstance.update();
this._visible = true;
this._options.onShow(this);
};
Dropdown2.prototype.hide = function() {
this._targetEl.classList.remove("block");
this._targetEl.classList.add("hidden");
this._popperInstance.setOptions(function(options) {
return __assign5(__assign5({}, options), { modifiers: __spreadArray(__spreadArray([], options.modifiers, true), [
{ name: "eventListeners", enabled: false }
], false) });
});
this._visible = false;
this._removeClickOutsideListener();
this._options.onHide(this);
};
Dropdown2.prototype.updateOnShow = function(callback) {
this._options.onShow = callback;
};
Dropdown2.prototype.updateOnHide = function(callback) {
this._options.onHide = callback;
};
Dropdown2.prototype.updateOnToggle = function(callback) {
this._options.onToggle = callback;
};
return Dropdown2;
}()
);
function initDropdowns() {
document.querySelectorAll("[data-dropdown-toggle]").forEach(function($triggerEl) {
var dropdownId = $triggerEl.getAttribute("data-dropdown-toggle");
var $dropdownEl = document.getElementById(dropdownId);
if ($dropdownEl) {
var placement = $triggerEl.getAttribute("data-dropdown-placement");
var offsetSkidding = $triggerEl.getAttribute("data-dropdown-offset-skidding");
var offsetDistance = $triggerEl.getAttribute("data-dropdown-offset-distance");
var triggerType = $triggerEl.getAttribute("data-dropdown-trigger");
var delay = $triggerEl.getAttribute("data-dropdown-delay");
var ignoreClickOutsideClass = $triggerEl.getAttribute("data-dropdown-ignore-click-outside-class");
new Dropdown($dropdownEl, $triggerEl, {
placement: placement ? placement : Default5.placement,
triggerType: triggerType ? triggerType : Default5.triggerType,
offsetSkidding: offsetSkidding ? parseInt(offsetSkidding) : Default5.offsetSkidding,
offsetDistance: offsetDistance ? parseInt(offsetDistance) : Default5.offsetDistance,
delay: delay ? parseInt(delay) : Default5.delay,
ignoreClickOutsideClass: ignoreClickOutsideClass ? ignoreClickOutsideClass : Default5.ignoreClickOutsideClass
});
} else {
console.error('The dropdown element with id "'.concat(dropdownId, '" does not exist. Please check the data-dropdown-toggle attribute.'));
}
});
}
if (typeof window !== "undefined") {
window.Dropdown = Dropdown;
window.initDropdowns = initDropdowns;
}
var dropdown_default = Dropdown;
// node_modules/flowbite/lib/esm/components/modal/index.js
var __assign6 = function() {
__assign6 = Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s)
if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign6.apply(this, arguments);
};
var Default6 = {
placement: "center",
backdropClasses: "bg-gray-900/50 dark:bg-gray-900/80 fixed inset-0 z-40",
backdrop: "dynamic",
closable: true,
onHide: function() {
},
onShow: function() {
},
onToggle: function() {
}
};
var DefaultInstanceOptions6 = {
id: null,
override: true
};
var Modal = (
/** @class */
function() {
function Modal2(targetEl, options, instanceOptions) {
if (targetEl === void 0) {
targetEl = null;
}
if (options === void 0) {
options = Default6;
}
if (instanceOptions === void 0) {
instanceOptions = DefaultInstanceOptions6;
}
this._eventListenerInstances = [];
this._instanceId = instanceOptions.id ? instanceOptions.id : targetEl.id;
this._targetEl = targetEl;
this._options = __assign6(__assign6({}, Default6), options);
this._isHidden = true;
this._backdropEl = null;
this._initialized = false;
this.init();
instances_default.addInstance("Modal", this, this._instanceId, instanceOptions.override);
}
Modal2.prototype.init = function() {
var _this = this;
if (this._targetEl && !this._initialized) {
this._getPlacementClasses().map(function(c) {
_this._targetEl.classList.add(c);
});
this._initialized = true;
}
};
Modal2.prototype.destroy = function() {
if (this._initialized) {
this.removeAllEventListenerInstances();
this._destroyBackdropEl();
this._initialized = false;
}
};
Modal2.prototype.removeInstance = function() {
instances_default.removeInstance("Modal", this._instanceId);
};
Modal2.prototype.destroyAndRemoveInstance = function() {
this.destroy();
this.removeInstance();
};
Modal2.prototype._createBackdrop = function() {
var _a;
if (this._isHidden) {
var backdropEl = document.createElement("div");
backdropEl.setAttribute("modal-backdrop", "");
(_a = backdropEl.classList).add.apply(_a, this._options.backdropClasses.split(" "));
document.querySelector("body").append(backdropEl);
this._backdropEl = backdropEl;
}
};
Modal2.prototype._destroyBackdropEl = function() {
if (!this._isHidden) {
document.querySelector("[modal-backdrop]").remove();
}
};
Modal2.prototype._setupModalCloseEventListeners = function() {
var _this = this;
if (this._options.backdrop === "dynamic") {
this._clickOutsideEventListener = function(ev) {
_this._handleOutsideClick(ev.target);
};
this._targetEl.addEventListener("click", this._clickOutsideEventListener, true);
}
this._keydownEventListener = function(ev) {
if (ev.key === "Escape") {
_this.hide();
}
};
document.body.addEventListener("keydown", this._keydownEventListener, true);
};
Modal2.prototype._removeModalCloseEventListeners = function() {
if (this._options.backdrop === "dynamic") {
this._targetEl.removeEventListener("click", this._clickOutsideEventListener, true);
}
document.body.removeEventListener("keydown", this._keydownEventListener, true);
};
Modal2.prototype._handleOutsideClick = function(target) {
if (target === this._targetEl || target === this._backdropEl && this.isVisible()) {
this.hide();
}
};
Modal2.prototype._getPlacementClasses = function() {
switch (this._options.placement) {
case "top-left":
return ["justify-start", "items-start"];
case "top-center":
return ["justify-center", "items-start"];
case "top-right":
return ["justify-end", "items-start"];
case "center-left":
return ["justify-start", "items-center"];
case "center":
return ["justify-center", "items-center"];
case "center-right":
return ["justify-end", "items-center"];
case "bottom-left":
return ["justify-start", "items-end"];
case "bottom-center":
return ["justify-center", "items-end"];
case "bottom-right":
return ["justify-end", "items-end"];
default:
return ["justify-center", "items-center"];
}
};
Modal2.prototype.toggle = function() {
if (this._isHidden) {
this.show();
} else {
this.hide();
}
this._options.onToggle(this);
};
Modal2.prototype.show = function() {
if (this.isHidden) {
this._targetEl.classList.add("flex");
this._targetEl.classList.remove("hidden");
this._targetEl.setAttribute("aria-modal", "true");
this._targetEl.setAttribute("role", "dialog");
this._targetEl.removeAttribute("aria-hidden");
this._createBackdrop();
this._isHidden = false;
if (this._options.closable) {
this._setupModalCloseEventListeners();
}
document.body.classList.add("overflow-hidden");
this._options.onShow(this);
}
};
Modal2.prototype.hide = function() {
if (this.isVisible) {
this._targetEl.classList.add("hidden");
this._targetEl.classList.remove("flex");
this._targetEl.setAttribute("aria-hidden", "true");
this._targetEl.removeAttribute("aria-modal");
this._targetEl.removeAttribute("role");
this._destroyBackdropEl();
this._isHidden = true;
document.body.classList.remove("overflow-hidden");
if (this._options.closable) {
this._removeModalCloseEventListeners();
}
this._options.onHide(this);
}
};
Modal2.prototype.isVisible = function() {
return !this._isHidden;
};
Modal2.prototype.isHidden = function() {
return this._isHidden;
};
Modal2.prototype.addEventListenerInstance = function(element, type, handler) {
this._eventListenerInstances.push({
element,
type,
handler
});
};
Modal2.prototype.removeAllEventListenerInstances = function() {
this._eventListenerInstances.map(function(eventListenerInstance) {
eventListenerInstance.element.removeEventListener(eventListenerInstance.type, eventListenerInstance.handler);
});
this._eventListenerInstances = [];
};
Modal2.prototype.getAllEventListenerInstances = function() {
return this._eventListenerInstances;
};
Modal2.prototype.updateOnShow = function(callback) {
this._options.onShow = callback;
};
Modal2.prototype.updateOnHide = function(callback) {
this._options.onHide = callback;
};
Modal2.prototype.updateOnToggle = function(callback) {
this._options.onToggle = callback;
};
return Modal2;
}()
);
function initModals() {
document.querySelectorAll("[data-modal-target]").forEach(function($triggerEl) {
var modalId = $triggerEl.getAttribute("data-modal-target");
var $modalEl = document.getElementById(modalId);
if ($modalEl) {
var placement = $modalEl.getAttribute("data-modal-placement");
var backdrop = $modalEl.getAttribute("data-modal-backdrop");
new Modal($modalEl, {
placement: placement ? placement : Default6.placement,
backdrop: backdrop ? backdrop : Default6.backdrop
});
} else {
console.error("Modal with id ".concat(modalId, " does not exist. Are you sure that the data-modal-target attribute points to the correct modal id?."));
}
});
document.querySelectorAll("[data-modal-toggle]").forEach(function($triggerEl) {
var modalId = $triggerEl.getAttribute("data-modal-toggle");
var $modalEl = document.getElementById(modalId);
if ($modalEl) {
var modal_1 = instances_default.getInstance("Modal", modalId);
if (modal_1) {
var toggleModal = function() {
modal_1.toggle();
};
$triggerEl.addEventListener("click", toggleModal);
modal_1.addEventListenerInstance($triggerEl, "click", toggleModal);
} else {
console.error("Modal with id ".concat(modalId, " has not been initialized. Please initialize it using the data-modal-target attribute."));
}
} else {
console.error("Modal with id ".concat(modalId, " does not exist. Are you sure that the data-modal-toggle attribute points to the correct modal id?"));
}
});
document.querySelectorAll("[data-modal-show]").forEach(function($triggerEl) {
var modalId = $triggerEl.getAttribute("data-modal-show");
var $modalEl = document.getElementById(modalId);
if ($modalEl) {
var modal_2 = instances_default.getInstance("Modal", modalId);
if (modal_2) {
var showModal = function() {
modal_2.show();
};
$triggerEl.addEventListener("click", showModal);
modal_2.addEventListenerInstance($triggerEl, "click", showModal);
} else {
console.error("Modal with id ".concat(modalId, " has not been initialized. Please initialize it using the data-modal-target attribute."));
}
} else {
console.error("Modal with id ".concat(modalId, " does not exist. Are you sure that the data-modal-show attribute points to the correct modal id?"));
}
});
document.querySelectorAll("[data-modal-hide]").forEach(function($triggerEl) {
var modalId = $triggerEl.getAttribute("data-modal-hide");
var $modalEl = document.getElementById(modalId);
if ($modalEl) {
var modal_3 = instances_default.getInstance("Modal", modalId);
if (modal_3) {
var hideModal = function() {
modal_3.hide();
};
$triggerEl.addEventListener("click", hideModal);
modal_3.addEventListenerInstance($triggerEl, "click", hideModal);
} else {
console.error("Modal with id ".concat(modalId, " has not been initialized. Please initialize it using the data-modal-target attribute."));
}
} else {
console.error("Modal with id ".concat(modalId, " does not exist. Are you sure that the data-modal-hide attribute points to the correct modal id?"));
}
});
}
if (typeof window !== "undefined") {
window.Modal = Modal;
window.initModals = initModals;
}
// node_modules/flowbite/lib/esm/components/drawer/index.js
var __assign7 = function() {
__assign7 = Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s)
if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign7.apply(this, arguments);
};
var Default7 = {
placement: "left",
bodyScrolling: false,
backdrop: true,
edge: false,
edgeOffset: "bottom-[60px]",
backdropClasses: "bg-gray-900/50 dark:bg-gray-900/80 fixed inset-0 z-30",
onShow: function() {
},
onHide: function() {
},
onToggle: function() {
}
};
var DefaultInstanceOptions7 = {
id: null,
override: true
};
var Drawer = (
/** @class */
function() {
function Drawer2(targetEl, options, instanceOptions) {
if (targetEl === void 0) {
targetEl = null;
}
if (options === void 0) {
options = Default7;
}
if (instanceOptions === void 0) {
instanceOptions = DefaultInstanceOptions7;
}
this._eventListenerInstances = [];
this._instanceId = instanceOptions.id ? instanceOptions.id : targetEl.id;
this._targetEl = targetEl;
this._options = __assign7(__assign7({}, Default7), options);
this._visible = false;
this._initialized = false;
this.init();
instances_default.addInstance("Drawer", this, this._instanceId, instanceOptions.override);
}
Drawer2.prototype.init = function() {
var _this = this;
if (this._targetEl && !this._initialized) {
this._targetEl.setAttribute("aria-hidden", "true");
this._targetEl.classList.add("transition-transform");
this._getPlacementClasses(this._options.placement).base.map(function(c) {
_this._targetEl.classList.add(c);
});
this._handleEscapeKey = function(event) {
if (event.key === "Escape") {
if (_this.isVisible()) {
_this.hide();
}
}
};
document.addEventListener("keydown", this._handleEscapeKey);
this._initialized = true;
}
};
Drawer2.prototype.destroy = function() {
if (this._initialized) {
this.removeAllEventListenerInstances();
this._destroyBackdropEl();
document.removeEventListener("keydown", this._handleEscapeKey);
this._initialized = false;
}
};
Drawer2.prototype.removeInstance = function() {
instances_default.removeInstance("Drawer", this._instanceId);
};
Drawer2.prototype.destroyAndRemoveInstance = function() {
this.destroy();
this.removeInstance();
};
Drawer2.prototype.hide = function() {
var _this = this;
if (this._options.edge) {
this._getPlacementClasses(this._options.placement + "-edge").active.map(function(c) {
_this._targetEl.classList.remove(c);
});
this._getPlacementClasses(this._options.placement + "-edge").inactive.map(function(c) {
_this._targetEl.classList.add(c);
});
} else {
this._getPlacementClasses(this._options.placement).active.map(function(c) {
_this._targetEl.classList.remove(c);
});
this._getPlacementClasses(this._options.placement).inactive.map(function(c) {
_this._targetEl.classList.add(c);
});
}
this._targetEl.setAttribute("aria-hidden", "true");
this._targetEl.removeAttribute("aria-modal");
this._targetEl.removeAttribute("role");
if (!this._options.bodyScrolling) {
document.body.classList.remove("overflow-hidden");
}
if (this._options.backdrop) {
this._destroyBackdropEl();
}
this._visible = false;
this._options.onHide(this);
};
Drawer2.prototype.show = function() {
var _this = this;
if (this._options.edge) {
this._getPlacementClasses(this._options.placement + "-edge").active.map(function(c) {
_this._targetEl.classList.add(c);
});
this._getPlacementClasses(this._options.placement + "-edge").inactive.map(function(c) {
_this._targetEl.classList.remove(c);
});
} else {
this._getPlacementClasses(this._options.placement).active.map(function(c) {
_this._targetEl.classList.add(c);
});
this._getPlacementClasses(this._options.placement).inactive.map(function(c) {
_this._targetEl.classList.remove(c);
});
}
this._targetEl.setAttribute("aria-modal", "true");
this._targetEl.setAttribute("role", "dialog");
this._targetEl.removeAttribute("aria-hidden");
if (!this._options.bodyScrolling) {
document.body.classList.add("overflow-hidden");
}
if (this._options.backdrop) {
this._createBackdrop();
}
this._visible = true;
this._options.onShow(this);
};
Drawer2.prototype.toggle = function() {
if (this.isVisible()) {
this.hide();
} else {
this.show();
}
};
Drawer2.prototype._createBackdrop = function() {
var _a;
var _this = this;
if (!this._visible) {
var backdropEl = document.createElement("div");
backdropEl.setAttribute("drawer-backdrop", "");
(_a = backdropEl.classList).add.apply(_a, this._options.backdropClasses.split(" "));
document.querySelector("body").append(backdropEl);
backdropEl.addEventListener("click", function() {
_this.hide();
});
}
};
Drawer2.prototype._destroyBackdropEl = function() {
if (this._visible && document.querySelector("[drawer-backdrop]") !== null) {
document.querySelector("[drawer-backdrop]").remove();
}
};
Drawer2.prototype._getPlacementClasses = function(placement) {
switch (placement) {
case "top":
return {
base: ["top-0", "left-0", "right-0"],
active: ["transform-none"],
inactive: ["-translate-y-full"]
};
case "right":
return {
base: ["right-0", "top-0"],
active: ["transform-none"],
inactive: ["translate-x-full"]
};
case "bottom":
return {
base: ["bottom-0", "left-0", "right-0"],
active: ["transform-none"],
inactive: ["translate-y-full"]
};
case "left":
return {
base: ["left-0", "top-0"],
active: ["transform-none"],
inactive: ["-translate-x-full"]
};
case "bottom-edge":
return {
base: ["left-0", "top-0"],
active: ["transform-none"],
inactive: ["translate-y-full", this._options.edgeOffset]
};
default:
return {
base: ["left-0", "top-0"],
active: ["transform-none"],
inactive: ["-translate-x-full"]
};
}
};
Drawer2.prototype.isHidden = function() {
return !this._visible;
};
Drawer2.prototype.isVisible = function() {
return this._visible;
};
Drawer2.prototype.addEventListenerInstance = function(element, type, handler) {
this._eventListenerInstances.push({
element,
type,
handler
});
};
Drawer2.prototype.removeAllEventListenerInstances = function() {
this._eventListenerInstances.map(function(eventListenerInstance) {
eventListenerInstance.element.removeEventListener(eventListenerInstance.type, eventListenerInstance.handler);
});
this._eventListenerInstances = [];
};
Drawer2.prototype.getAllEventListenerInstances = function() {
return this._eventListenerInstances;
};
Drawer2.prototype.updateOnShow = function(callback) {
this._options.onShow = callback;
};
Drawer2.prototype.updateOnHide = function(callback) {
this._options.onHide = callback;
};
Drawer2.prototype.updateOnToggle = function(callback) {
this._options.onToggle = callback;
};
return Drawer2;
}()
);
function initDrawers() {
document.querySelectorAll("[data-drawer-target]").forEach(function($triggerEl) {
var drawerId = $triggerEl.getAttribute("data-drawer-target");
var $drawerEl = document.getElementById(drawerId);
if ($drawerEl) {
var placement = $triggerEl.getAttribute("data-drawer-placement");
var bodyScrolling = $triggerEl.getAttribute("data-drawer-body-scrolling");
var backdrop = $triggerEl.getAttribute("data-drawer-backdrop");
var edge = $triggerEl.getAttribute("data-drawer-edge");
var edgeOffset = $triggerEl.getAttribute("data-drawer-edge-offset");
new Drawer($drawerEl, {
placement: placement ? placement : Default7.placement,
bodyScrolling: bodyScrolling ? bodyScrolling === "true" ? true : false : Default7.bodyScrolling,
backdrop: backdrop ? backdrop === "true" ? true : false : Default7.backdrop,
edge: edge ? edge === "true" ? true : false : Default7.edge,
edgeOffset: edgeOffset ? edgeOffset : Default7.edgeOffset
});
} else {
console.error("Drawer with id ".concat(drawerId, " not found. Are you sure that the data-drawer-target attribute points to the correct drawer id?"));
}
});
document.querySelectorAll("[data-drawer-toggle]").forEach(function($triggerEl) {
var drawerId = $triggerEl.getAttribute("data-drawer-toggle");
var $drawerEl = document.getElementById(drawerId);
if ($drawerEl) {
var drawer_1 = instances_default.getInstance("Drawer", drawerId);
if (drawer_1) {
var toggleDrawer = function() {
drawer_1.toggle();
};
$triggerEl.addEventListener("click", toggleDrawer);
drawer_1.addEventListenerInstance($triggerEl, "click", toggleDrawer);
} else {
console.error("Drawer with id ".concat(drawerId, " has not been initialized. Please initialize it using the data-drawer-target attribute."));
}
} else {
console.error("Drawer with id ".concat(drawerId, " not found. Are you sure that the data-drawer-target attribute points to the correct drawer id?"));
}
});
document.querySelectorAll("[data-drawer-dismiss], [data-drawer-hide]").forEach(function($triggerEl) {
var drawerId = $triggerEl.getAttribute("data-drawer-dismiss") ? $triggerEl.getAttribute("data-drawer-dismiss") : $triggerEl.getAttribute("data-drawer-hide");
var $drawerEl = document.getElementById(drawerId);
if ($drawerEl) {
var drawer_2 = instances_default.getInstance("Drawer", drawerId);
if (drawer_2) {
var hideDrawer = function() {
drawer_2.hide();
};
$triggerEl.addEventListener("click", hideDrawer);
drawer_2.addEventListenerInstance($triggerEl, "click", hideDrawer);
} else {
console.error("Drawer with id ".concat(drawerId, " has not been initialized. Please initialize it using the data-drawer-target attribute."));
}
} else {
console.error("Drawer with id ".concat(drawerId, " not found. Are you sure that the data-drawer-target attribute points to the correct drawer id"));
}
});
document.querySelectorAll("[data-drawer-show]").forEach(function($triggerEl) {
var drawerId = $triggerEl.getAttribute("data-drawer-show");
var $drawerEl = document.getElementById(drawerId);
if ($drawerEl) {
var drawer_3 = instances_default.getInstance("Drawer", drawerId);
if (drawer_3) {
var showDrawer = function() {
drawer_3.show();
};
$triggerEl.addEventListener("click", showDrawer);
drawer_3.addEventListenerInstance($triggerEl, "click", showDrawer);
} else {
console.error("Drawer with id ".concat(drawerId, " has not been initialized. Please initialize it using the data-drawer-target attribute."));
}
} else {
console.error("Drawer with id ".concat(drawerId, " not found. Are you sure that the data-drawer-target attribute points to the correct drawer id?"));
}
});
}
if (typeof window !== "undefined") {
window.Drawer = Drawer;
window.initDrawers = initDrawers;
}
// node_modules/flowbite/lib/esm/components/tabs/index.js
var __assign8 = function() {
__assign8 = Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s)
if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign8.apply(this, arguments);
};
var Default8 = {
defaultTabId: null,
activeClasses: "text-blue-600 hover:text-blue-600 dark:text-blue-500 dark:hover:text-blue-500 border-blue-600 dark:border-blue-500",
inactiveClasses: "dark:border-transparent text-gray-500 hover:text-gray-600 dark:text-gray-400 border-gray-100 hover:border-gray-300 dark:border-gray-700 dark:hover:text-gray-300",
onShow: function() {
}
};
var DefaultInstanceOptions8 = {
id: null,
override: true
};
var Tabs = (
/** @class */
function() {
function Tabs2(tabsEl, items, options, instanceOptions) {
if (tabsEl === void 0) {
tabsEl = null;
}
if (items === void 0) {
items = [];
}
if (options === void 0) {
options = Default8;
}
if (instanceOptions === void 0) {
instanceOptions = DefaultInstanceOptions8;
}
this._instanceId = instanceOptions.id ? instanceOptions.id : tabsEl.id;
this._tabsEl = tabsEl;
this._items = items;
this._activeTab = options ? this.getTab(options.defaultTabId) : null;
this._options = __assign8(__assign8({}, Default8), options);
this._initialized = false;
this.init();
instances_default.addInstance("Tabs", this, this._tabsEl.id, true);
instances_default.addInstance("Tabs", this, this._instanceId, instanceOptions.override);
}
Tabs2.prototype.init = function() {
var _this = this;
if (this._items.length && !this._initialized) {
if (!this._activeTab) {
this.setActiveTab(this._items[0]);
}
this.show(this._activeTab.id, true);
this._items.map(function(tab) {
tab.triggerEl.addEventListener("click", function(event) {
event.preventDefault();
_this.show(tab.id);
});
});
}
};
Tabs2.prototype.destroy = function() {
if (this._initialized) {
this._initialized = false;
}
};
Tabs2.prototype.removeInstance = function() {
this.destroy();
instances_default.removeInstance("Tabs", this._instanceId);
};
Tabs2.prototype.destroyAndRemoveInstance = function() {
this.destroy();
this.removeInstance();
};
Tabs2.prototype.getActiveTab = function() {
return this._activeTab;
};
Tabs2.prototype.setActiveTab = function(tab) {
this._activeTab = tab;
};
Tabs2.prototype.getTab = function(id) {
return this._items.filter(function(t) {
return t.id === id;
})[0];
};
Tabs2.prototype.show = function(id, forceShow) {
var _a, _b;
var _this = this;
if (forceShow === void 0) {
forceShow = false;
}
var tab = this.getTab(id);
if (tab === this._activeTab && !forceShow) {
return;
}
this._items.map(function(t) {
var _a2, _b2;
if (t !== tab) {
(_a2 = t.triggerEl.classList).remove.apply(_a2, _this._options.activeClasses.split(" "));
(_b2 = t.triggerEl.classList).add.apply(_b2, _this._options.inactiveClasses.split(" "));
t.targetEl.classList.add("hidden");
t.triggerEl.setAttribute("aria-selected", "false");
}
});
(_a = tab.triggerEl.classList).add.apply(_a, this._options.activeClasses.split(" "));
(_b = tab.triggerEl.classList).remove.apply(_b, this._options.inactiveClasses.split(" "));
tab.triggerEl.setAttribute("aria-selected", "true");
tab.targetEl.classList.remove("hidden");
this.setActiveTab(tab);
this._options.onShow(this, tab);
};
Tabs2.prototype.updateOnShow = function(callback) {
this._options.onShow = callback;
};
return Tabs2;
}()
);
function initTabs() {
document.querySelectorAll("[data-tabs-toggle]").forEach(function($parentEl) {
var tabItems = [];
var activeClasses = $parentEl.getAttribute("data-tabs-active-classes");
var inactiveClasses = $parentEl.getAttribute("data-tabs-inactive-classes");
var defaultTabId = null;
$parentEl.querySelectorAll('[role="tab"]').forEach(function($triggerEl) {
var isActive = $triggerEl.getAttribute("aria-selected") === "true";
var tab = {
id: $triggerEl.getAttribute("data-tabs-target"),
triggerEl: $triggerEl,
targetEl: document.querySelector($triggerEl.getAttribute("data-tabs-target"))
};
tabItems.push(tab);
if (isActive) {
defaultTabId = tab.id;
}
});
new Tabs($parentEl, tabItems, {
defaultTabId,
activeClasses: activeClasses ? activeClasses : Default8.activeClasses,
inactiveClasses: inactiveClasses ? inactiveClasses : Default8.inactiveClasses
});
});
}
if (typeof window !== "undefined") {
window.Tabs = Tabs;
window.initTabs = initTabs;
}
// node_modules/flowbite/lib/esm/components/tooltip/index.js
var __assign9 = function() {
__assign9 = Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s)
if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign9.apply(this, arguments);
};
var __spreadArray2 = function(to, from, pack) {
if (pack || arguments.length === 2)
for (var i = 0, l = from.length, ar; i < l; i++) {
if (ar || !(i in from)) {
if (!ar)
ar = Array.prototype.slice.call(from, 0, i);
ar[i] = from[i];
}
}
return to.concat(ar || Array.prototype.slice.call(from));
};
var Default9 = {
placement: "top",
triggerType: "hover",
onShow: function() {
},
onHide: function() {
},
onToggle: function() {
}
};
var DefaultInstanceOptions9 = {
id: null,
override: true
};
var Tooltip = (
/** @class */
function() {
function Tooltip2(targetEl, triggerEl, options, instanceOptions) {
if (targetEl === void 0) {
targetEl = null;
}
if (triggerEl === void 0) {
triggerEl = null;
}
if (options === void 0) {
options = Default9;
}
if (instanceOptions === void 0) {
instanceOptions = DefaultInstanceOptions9;
}
this._instanceId = instanceOptions.id ? instanceOptions.id : targetEl.id;
this._targetEl = targetEl;
this._triggerEl = triggerEl;
this._options = __assign9(__assign9({}, Default9), options);
this._popperInstance = null;
this._visible = false;
this._initialized = false;
this.init();
instances_default.addInstance("Tooltip", this, this._instanceId, instanceOptions.override);
}
Tooltip2.prototype.init = function() {
if (this._triggerEl && this._targetEl && !this._initialized) {
this._setupEventListeners();
this._popperInstance = this._createPopperInstance();
this._initialized = true;
}
};
Tooltip2.prototype.destroy = function() {
var _this = this;
if (this._initialized) {
var triggerEvents = this._getTriggerEvents();
triggerEvents.showEvents.forEach(function(ev) {
_this._triggerEl.removeEventListener(ev, _this._showHandler);
});
triggerEvents.hideEvents.forEach(function(ev) {
_this._triggerEl.removeEventListener(ev, _this._hideHandler);
});
this._removeKeydownListener();
this._removeClickOutsideListener();
if (this._popperInstance) {
this._popperInstance.destroy();
}
this._initialized = false;
}
};
Tooltip2.prototype.removeInstance = function() {
instances_default.removeInstance("Tooltip", this._instanceId);
};
Tooltip2.prototype.destroyAndRemoveInstance = function() {
this.destroy();
this.removeInstance();
};
Tooltip2.prototype._setupEventListeners = function() {
var _this = this;
var triggerEvents = this._getTriggerEvents();
this._showHandler = function() {
_this.show();
};
this._hideHandler = function() {
_this.hide();
};
triggerEvents.showEvents.forEach(function(ev) {
_this._triggerEl.addEventListener(ev, _this._showHandler);
});
triggerEvents.hideEvents.forEach(function(ev) {
_this._triggerEl.addEventListener(ev, _this._hideHandler);
});
};
Tooltip2.prototype._createPopperInstance = function() {
return createPopper(this._triggerEl, this._targetEl, {
placement: this._options.placement,
modifiers: [
{
name: "offset",
options: {
offset: [0, 8]
}
}
]
});
};
Tooltip2.prototype._getTriggerEvents = function() {
switch (this._options.triggerType) {
case "hover":
return {
showEvents: ["mouseenter", "focus"],
hideEvents: ["mouseleave", "blur"]
};
case "click":
return {
showEvents: ["click", "focus"],
hideEvents: ["focusout", "blur"]
};
case "none":
return {
showEvents: [],
hideEvents: []
};
default:
return {
showEvents: ["mouseenter", "focus"],
hideEvents: ["mouseleave", "blur"]
};
}
};
Tooltip2.prototype._setupKeydownListener = function() {
var _this = this;
this._keydownEventListener = function(ev) {
if (ev.key === "Escape") {
_this.hide();
}
};
document.body.addEventListener("keydown", this._keydownEventListener, true);
};
Tooltip2.prototype._removeKeydownListener = function() {
document.body.removeEventListener("keydown", this._keydownEventListener, true);
};
Tooltip2.prototype._setupClickOutsideListener = function() {
var _this = this;
this._clickOutsideEventListener = function(ev) {
_this._handleClickOutside(ev, _this._targetEl);
};
document.body.addEventListener("click", this._clickOutsideEventListener, true);
};
Tooltip2.prototype._removeClickOutsideListener = function() {
document.body.removeEventListener("click", this._clickOutsideEventListener, true);
};
Tooltip2.prototype._handleClickOutside = function(ev, targetEl) {
var clickedEl = ev.target;
if (clickedEl !== targetEl && !targetEl.contains(clickedEl) && !this._triggerEl.contains(clickedEl) && this.isVisible()) {
this.hide();
}
};
Tooltip2.prototype.isVisible = function() {
return this._visible;
};
Tooltip2.prototype.toggle = function() {
if (this.isVisible()) {
this.hide();
} else {
this.show();
}
};
Tooltip2.prototype.show = function() {
this._targetEl.classList.remove("opacity-0", "invisible");
this._targetEl.classList.add("opacity-100", "visible");
this._popperInstance.setOptions(function(options) {
return __assign9(__assign9({}, options), { modifiers: __spreadArray2(__spreadArray2([], options.modifiers, true), [
{ name: "eventListeners", enabled: true }
], false) });
});
this._setupClickOutsideListener();
this._setupKeydownListener();
this._popperInstance.update();
this._visible = true;
this._options.onShow(this);
};
Tooltip2.prototype.hide = function() {
this._targetEl.classList.remove("opacity-100", "visible");
this._targetEl.classList.add("opacity-0", "invisible");
this._popperInstance.setOptions(function(options) {
return __assign9(__assign9({}, options), { modifiers: __spreadArray2(__spreadArray2([], options.modifiers, true), [
{ name: "eventListeners", enabled: false }
], false) });
});
this._removeClickOutsideListener();
this._removeKeydownListener();
this._visible = false;
this._options.onHide(this);
};
Tooltip2.prototype.updateOnShow = function(callback) {
this._options.onShow = callback;
};
Tooltip2.prototype.updateOnHide = function(callback) {
this._options.onHide = callback;
};
Tooltip2.prototype.updateOnToggle = function(callback) {
this._options.onToggle = callback;
};
return Tooltip2;
}()
);
function initTooltips() {
document.querySelectorAll("[data-tooltip-target]").forEach(function($triggerEl) {
var tooltipId = $triggerEl.getAttribute("data-tooltip-target");
var $tooltipEl = document.getElementById(tooltipId);
if ($tooltipEl) {
var triggerType = $triggerEl.getAttribute("data-tooltip-trigger");
var placement = $triggerEl.getAttribute("data-tooltip-placement");
new Tooltip($tooltipEl, $triggerEl, {
placement: placement ? placement : Default9.placement,
triggerType: triggerType ? triggerType : Default9.triggerType
});
} else {
console.error('The tooltip element with id "'.concat(tooltipId, '" does not exist. Please check the data-tooltip-target attribute.'));
}
});
}
if (typeof window !== "undefined") {
window.Tooltip = Tooltip;
window.initTooltips = initTooltips;
}
// node_modules/flowbite/lib/esm/components/popover/index.js
var __assign10 = function() {
__assign10 = Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s)
if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign10.apply(this, arguments);
};
var __spreadArray3 = function(to, from, pack) {
if (pack || arguments.length === 2)
for (var i = 0, l = from.length, ar; i < l; i++) {
if (ar || !(i in from)) {
if (!ar)
ar = Array.prototype.slice.call(from, 0, i);
ar[i] = from[i];
}
}
return to.concat(ar || Array.prototype.slice.call(from));
};
var Default10 = {
placement: "top",
offset: 10,
triggerType: "hover",
onShow: function() {
},
onHide: function() {
},
onToggle: function() {
}
};
var DefaultInstanceOptions10 = {
id: null,
override: true
};
var Popover = (
/** @class */
function() {
function Popover2(targetEl, triggerEl, options, instanceOptions) {
if (targetEl === void 0) {
targetEl = null;
}
if (triggerEl === void 0) {
triggerEl = null;
}
if (options === void 0) {
options = Default10;
}
if (instanceOptions === void 0) {
instanceOptions = DefaultInstanceOptions10;
}
this._instanceId = instanceOptions.id ? instanceOptions.id : targetEl.id;
this._targetEl = targetEl;
this._triggerEl = triggerEl;
this._options = __assign10(__assign10({}, Default10), options);
this._popperInstance = null;
this._visible = false;
this._initialized = false;
this.init();
instances_default.addInstance("Popover", this, instanceOptions.id ? instanceOptions.id : this._targetEl.id, instanceOptions.override);
}
Popover2.prototype.init = function() {
if (this._triggerEl && this._targetEl && !this._initialized) {
this._setupEventListeners();
this._popperInstance = this._createPopperInstance();
this._initialized = true;
}
};
Popover2.prototype.destroy = function() {
var _this = this;
if (this._initialized) {
var triggerEvents = this._getTriggerEvents();
triggerEvents.showEvents.forEach(function(ev) {
_this._triggerEl.removeEventListener(ev, _this._showHandler);
_this._targetEl.removeEventListener(ev, _this._showHandler);
});
triggerEvents.hideEvents.forEach(function(ev) {
_this._triggerEl.removeEventListener(ev, _this._hideHandler);
_this._targetEl.removeEventListener(ev, _this._hideHandler);
});
this._removeKeydownListener();
this._removeClickOutsideListener();
if (this._popperInstance) {
this._popperInstance.destroy();
}
this._initialized = false;
}
};
Popover2.prototype.removeInstance = function() {
instances_default.removeInstance("Popover", this._instanceId);
};
Popover2.prototype.destroyAndRemoveInstance = function() {
this.destroy();
this.removeInstance();
};
Popover2.prototype._setupEventListeners = function() {
var _this = this;
var triggerEvents = this._getTriggerEvents();
this._showHandler = function() {
_this.show();
};
this._hideHandler = function() {
setTimeout(function() {
if (!_this._targetEl.matches(":hover")) {
_this.hide();
}
}, 100);
};
triggerEvents.showEvents.forEach(function(ev) {
_this._triggerEl.addEventListener(ev, _this._showHandler);
_this._targetEl.addEventListener(ev, _this._showHandler);
});
triggerEvents.hideEvents.forEach(function(ev) {
_this._triggerEl.addEventListener(ev, _this._hideHandler);
_this._targetEl.addEventListener(ev, _this._hideHandler);
});
};
Popover2.prototype._createPopperInstance = function() {
return createPopper(this._triggerEl, this._targetEl, {
placement: this._options.placement,
modifiers: [
{
name: "offset",
options: {
offset: [0, this._options.offset]
}
}
]
});
};
Popover2.prototype._getTriggerEvents = function() {
switch (this._options.triggerType) {
case "hover":
return {
showEvents: ["mouseenter", "focus"],
hideEvents: ["mouseleave", "blur"]
};
case "click":
return {
showEvents: ["click", "focus"],
hideEvents: ["focusout", "blur"]
};
case "none":
return {
showEvents: [],
hideEvents: []
};
default:
return {
showEvents: ["mouseenter", "focus"],
hideEvents: ["mouseleave", "blur"]
};
}
};
Popover2.prototype._setupKeydownListener = function() {
var _this = this;
this._keydownEventListener = function(ev) {
if (ev.key === "Escape") {
_this.hide();
}
};
document.body.addEventListener("keydown", this._keydownEventListener, true);
};
Popover2.prototype._removeKeydownListener = function() {
document.body.removeEventListener("keydown", this._keydownEventListener, true);
};
Popover2.prototype._setupClickOutsideListener = function() {
var _this = this;
this._clickOutsideEventListener = function(ev) {
_this._handleClickOutside(ev, _this._targetEl);
};
document.body.addEventListener("click", this._clickOutsideEventListener, true);
};
Popover2.prototype._removeClickOutsideListener = function() {
document.body.removeEventListener("click", this._clickOutsideEventListener, true);
};
Popover2.prototype._handleClickOutside = function(ev, targetEl) {
var clickedEl = ev.target;
if (clickedEl !== targetEl && !targetEl.contains(clickedEl) && !this._triggerEl.contains(clickedEl) && this.isVisible()) {
this.hide();
}
};
Popover2.prototype.isVisible = function() {
return this._visible;
};
Popover2.prototype.toggle = function() {
if (this.isVisible()) {
this.hide();
} else {
this.show();
}
this._options.onToggle(this);
};
Popover2.prototype.show = function() {
this._targetEl.classList.remove("opacity-0", "invisible");
this._targetEl.classList.add("opacity-100", "visible");
this._popperInstance.setOptions(function(options) {
return __assign10(__assign10({}, options), { modifiers: __spreadArray3(__spreadArray3([], options.modifiers, true), [
{ name: "eventListeners", enabled: true }
], false) });
});
this._setupClickOutsideListener();
this._setupKeydownListener();
this._popperInstance.update();
this._visible = true;
this._options.onShow(this);
};
Popover2.prototype.hide = function() {
this._targetEl.classList.remove("opacity-100", "visible");
this._targetEl.classList.add("opacity-0", "invisible");
this._popperInstance.setOptions(function(options) {
return __assign10(__assign10({}, options), { modifiers: __spreadArray3(__spreadArray3([], options.modifiers, true), [
{ name: "eventListeners", enabled: false }
], false) });
});
this._removeClickOutsideListener();
this._removeKeydownListener();
this._visible = false;
this._options.onHide(this);
};
Popover2.prototype.updateOnShow = function(callback) {
this._options.onShow = callback;
};
Popover2.prototype.updateOnHide = function(callback) {
this._options.onHide = callback;
};
Popover2.prototype.updateOnToggle = function(callback) {
this._options.onToggle = callback;
};
return Popover2;
}()
);
function initPopovers() {
document.querySelectorAll("[data-popover-target]").forEach(function($triggerEl) {
var popoverID = $triggerEl.getAttribute("data-popover-target");
var $popoverEl = document.getElementById(popoverID);
if ($popoverEl) {
var triggerType = $triggerEl.getAttribute("data-popover-trigger");
var placement = $triggerEl.getAttribute("data-popover-placement");
var offset2 = $triggerEl.getAttribute("data-popover-offset");
new Popover($popoverEl, $triggerEl, {
placement: placement ? placement : Default10.placement,
offset: offset2 ? parseInt(offset2) : Default10.offset,
triggerType: triggerType ? triggerType : Default10.triggerType
});
} else {
console.error('The popover element with id "'.concat(popoverID, '" does not exist. Please check the data-popover-target attribute.'));
}
});
}
if (typeof window !== "undefined") {
window.Popover = Popover;
window.initPopovers = initPopovers;
}
// node_modules/flowbite/lib/esm/components/dial/index.js
var __assign11 = function() {
__assign11 = Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s)
if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign11.apply(this, arguments);
};
var Default11 = {
triggerType: "hover",
onShow: function() {
},
onHide: function() {
},
onToggle: function() {
}
};
var DefaultInstanceOptions11 = {
id: null,
override: true
};
var Dial = (
/** @class */
function() {
function Dial2(parentEl, triggerEl, targetEl, options, instanceOptions) {
if (parentEl === void 0) {
parentEl = null;
}
if (triggerEl === void 0) {
triggerEl = null;
}
if (targetEl === void 0) {
targetEl = null;
}
if (options === void 0) {
options = Default11;
}
if (instanceOptions === void 0) {
instanceOptions = DefaultInstanceOptions11;
}
this._instanceId = instanceOptions.id ? instanceOptions.id : targetEl.id;
this._parentEl = parentEl;
this._triggerEl = triggerEl;
this._targetEl = targetEl;
this._options = __assign11(__assign11({}, Default11), options);
this._visible = false;
this._initialized = false;
this.init();
instances_default.addInstance("Dial", this, this._instanceId, instanceOptions.override);
}
Dial2.prototype.init = function() {
var _this = this;
if (this._triggerEl && this._targetEl && !this._initialized) {
var triggerEventTypes = this._getTriggerEventTypes(this._options.triggerType);
this._showEventHandler = function() {
_this.show();
};
triggerEventTypes.showEvents.forEach(function(ev) {
_this._triggerEl.addEventListener(ev, _this._showEventHandler);
_this._targetEl.addEventListener(ev, _this._showEventHandler);
});
this._hideEventHandler = function() {
if (!_this._parentEl.matches(":hover")) {
_this.hide();
}
};
triggerEventTypes.hideEvents.forEach(function(ev) {
_this._parentEl.addEventListener(ev, _this._hideEventHandler);
});
this._initialized = true;
}
};
Dial2.prototype.destroy = function() {
var _this = this;
if (this._initialized) {
var triggerEventTypes = this._getTriggerEventTypes(this._options.triggerType);
triggerEventTypes.showEvents.forEach(function(ev) {
_this._triggerEl.removeEventListener(ev, _this._showEventHandler);
_this._targetEl.removeEventListener(ev, _this._showEventHandler);
});
triggerEventTypes.hideEvents.forEach(function(ev) {
_this._parentEl.removeEventListener(ev, _this._hideEventHandler);
});
this._initialized = false;
}
};
Dial2.prototype.removeInstance = function() {
instances_default.removeInstance("Dial", this._instanceId);
};
Dial2.prototype.destroyAndRemoveInstance = function() {
this.destroy();
this.removeInstance();
};
Dial2.prototype.hide = function() {
this._targetEl.classList.add("hidden");
if (this._triggerEl) {
this._triggerEl.setAttribute("aria-expanded", "false");
}
this._visible = false;
this._options.onHide(this);
};
Dial2.prototype.show = function() {
this._targetEl.classList.remove("hidden");
if (this._triggerEl) {
this._triggerEl.setAttribute("aria-expanded", "true");
}
this._visible = true;
this._options.onShow(this);
};
Dial2.prototype.toggle = function() {
if (this._visible) {
this.hide();
} else {
this.show();
}
};
Dial2.prototype.isHidden = function() {
return !this._visible;
};
Dial2.prototype.isVisible = function() {
return this._visible;
};
Dial2.prototype._getTriggerEventTypes = function(triggerType) {
switch (triggerType) {
case "hover":
return {
showEvents: ["mouseenter", "focus"],
hideEvents: ["mouseleave", "blur"]
};
case "click":
return {
showEvents: ["click", "focus"],
hideEvents: ["focusout", "blur"]
};
case "none":
return {
showEvents: [],
hideEvents: []
};
default:
return {
showEvents: ["mouseenter", "focus"],
hideEvents: ["mouseleave", "blur"]
};
}
};
Dial2.prototype.updateOnShow = function(callback) {
this._options.onShow = callback;
};
Dial2.prototype.updateOnHide = function(callback) {
this._options.onHide = callback;
};
Dial2.prototype.updateOnToggle = function(callback) {
this._options.onToggle = callback;
};
return Dial2;
}()
);
function initDials() {
document.querySelectorAll("[data-dial-init]").forEach(function($parentEl) {
var $triggerEl = $parentEl.querySelector("[data-dial-toggle]");
if ($triggerEl) {
var dialId = $triggerEl.getAttribute("data-dial-toggle");
var $dialEl = document.getElementById(dialId);
if ($dialEl) {
var triggerType = $triggerEl.getAttribute("data-dial-trigger");
new Dial($parentEl, $triggerEl, $dialEl, {
triggerType: triggerType ? triggerType : Default11.triggerType
});
} else {
console.error("Dial with id ".concat(dialId, " does not exist. Are you sure that the data-dial-toggle attribute points to the correct modal id?"));
}
} else {
console.error("Dial with id ".concat($parentEl.id, " does not have a trigger element. Are you sure that the data-dial-toggle attribute exists?"));
}
});
}
if (typeof window !== "undefined") {
window.Dial = Dial;
window.initDials = initDials;
}
// node_modules/flowbite/lib/esm/components/input-counter/index.js
var __assign12 = function() {
__assign12 = Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s)
if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign12.apply(this, arguments);
};
var Default12 = {
minValue: null,
maxValue: null,
onIncrement: function() {
},
onDecrement: function() {
}
};
var DefaultInstanceOptions12 = {
id: null,
override: true
};
var InputCounter = (
/** @class */
function() {
function InputCounter2(targetEl, incrementEl, decrementEl, options, instanceOptions) {
if (targetEl === void 0) {
targetEl = null;
}
if (incrementEl === void 0) {
incrementEl = null;
}
if (decrementEl === void 0) {
decrementEl = null;
}
if (options === void 0) {
options = Default12;
}
if (instanceOptions === void 0) {
instanceOptions = DefaultInstanceOptions12;
}
this._instanceId = instanceOptions.id ? instanceOptions.id : targetEl.id;
this._targetEl = targetEl;
this._incrementEl = incrementEl;
this._decrementEl = decrementEl;
this._options = __assign12(__assign12({}, Default12), options);
this._initialized = false;
this.init();
instances_default.addInstance("InputCounter", this, this._instanceId, instanceOptions.override);
}
InputCounter2.prototype.init = function() {
var _this = this;
if (this._targetEl && !this._initialized) {
this._inputHandler = function(event) {
{
var target = event.target;
if (!/^\d*$/.test(target.value)) {
target.value = target.value.replace(/[^\d]/g, "");
}
if (_this._options.maxValue !== null && parseInt(target.value) > _this._options.maxValue) {
target.value = _this._options.maxValue.toString();
}
if (_this._options.minValue !== null && parseInt(target.value) < _this._options.minValue) {
target.value = _this._options.minValue.toString();
}
}
};
this._incrementClickHandler = function() {
_this.increment();
};
this._decrementClickHandler = function() {
_this.decrement();
};
this._targetEl.addEventListener("input", this._inputHandler);
if (this._incrementEl) {
this._incrementEl.addEventListener("click", this._incrementClickHandler);
}
if (this._decrementEl) {
this._decrementEl.addEventListener("click", this._decrementClickHandler);
}
this._initialized = true;
}
};
InputCounter2.prototype.destroy = function() {
if (this._targetEl && this._initialized) {
this._targetEl.removeEventListener("input", this._inputHandler);
if (this._incrementEl) {
this._incrementEl.removeEventListener("click", this._incrementClickHandler);
}
if (this._decrementEl) {
this._decrementEl.removeEventListener("click", this._decrementClickHandler);
}
this._initialized = false;
}
};
InputCounter2.prototype.removeInstance = function() {
instances_default.removeInstance("InputCounter", this._instanceId);
};
InputCounter2.prototype.destroyAndRemoveInstance = function() {
this.destroy();
this.removeInstance();
};
InputCounter2.prototype.getCurrentValue = function() {
return parseInt(this._targetEl.value) || 0;
};
InputCounter2.prototype.increment = function() {
if (this._options.maxValue !== null && this.getCurrentValue() >= this._options.maxValue) {
return;
}
this._targetEl.value = (this.getCurrentValue() + 1).toString();
this._options.onIncrement(this);
};
InputCounter2.prototype.decrement = function() {
if (this._options.minValue !== null && this.getCurrentValue() <= this._options.minValue) {
return;
}
this._targetEl.value = (this.getCurrentValue() - 1).toString();
this._options.onDecrement(this);
};
InputCounter2.prototype.updateOnIncrement = function(callback) {
this._options.onIncrement = callback;
};
InputCounter2.prototype.updateOnDecrement = function(callback) {
this._options.onDecrement = callback;
};
return InputCounter2;
}()
);
function initInputCounters() {
document.querySelectorAll("[data-input-counter]").forEach(function($targetEl) {
var targetId = $targetEl.id;
var $incrementEl = document.querySelector('[data-input-counter-increment="' + targetId + '"]');
var $decrementEl = document.querySelector('[data-input-counter-decrement="' + targetId + '"]');
var minValue = $targetEl.getAttribute("data-input-counter-min");
var maxValue = $targetEl.getAttribute("data-input-counter-max");
if ($targetEl) {
if (!instances_default.instanceExists("InputCounter", $targetEl.getAttribute("id"))) {
new InputCounter($targetEl, $incrementEl ? $incrementEl : null, $decrementEl ? $decrementEl : null, {
minValue: minValue ? parseInt(minValue) : null,
maxValue: maxValue ? parseInt(maxValue) : null
});
}
} else {
console.error('The target element with id "'.concat(targetId, '" does not exist. Please check the data-input-counter attribute.'));
}
});
}
if (typeof window !== "undefined") {
window.InputCounter = InputCounter;
window.initInputCounters = initInputCounters;
}
// node_modules/flowbite/lib/esm/components/clipboard/index.js
var __assign13 = function() {
__assign13 = Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s)
if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign13.apply(this, arguments);
};
var Default13 = {
htmlEntities: false,
contentType: "input",
onCopy: function() {
}
};
var DefaultInstanceOptions13 = {
id: null,
override: true
};
var CopyClipboard = (
/** @class */
function() {
function CopyClipboard2(triggerEl, targetEl, options, instanceOptions) {
if (triggerEl === void 0) {
triggerEl = null;
}
if (targetEl === void 0) {
targetEl = null;
}
if (options === void 0) {
options = Default13;
}
if (instanceOptions === void 0) {
instanceOptions = DefaultInstanceOptions13;
}
this._instanceId = instanceOptions.id ? instanceOptions.id : targetEl.id;
this._triggerEl = triggerEl;
this._targetEl = targetEl;
this._options = __assign13(__assign13({}, Default13), options);
this._initialized = false;
this.init();
instances_default.addInstance("CopyClipboard", this, this._instanceId, instanceOptions.override);
}
CopyClipboard2.prototype.init = function() {
var _this = this;
if (this._targetEl && this._triggerEl && !this._initialized) {
this._triggerElClickHandler = function() {
_this.copy();
};
if (this._triggerEl) {
this._triggerEl.addEventListener("click", this._triggerElClickHandler);
}
this._initialized = true;
}
};
CopyClipboard2.prototype.destroy = function() {
if (this._triggerEl && this._targetEl && this._initialized) {
if (this._triggerEl) {
this._triggerEl.removeEventListener("click", this._triggerElClickHandler);
}
this._initialized = false;
}
};
CopyClipboard2.prototype.removeInstance = function() {
instances_default.removeInstance("CopyClipboard", this._instanceId);
};
CopyClipboard2.prototype.destroyAndRemoveInstance = function() {
this.destroy();
this.removeInstance();
};
CopyClipboard2.prototype.getTargetValue = function() {
if (this._options.contentType === "input") {
return this._targetEl.value;
}
if (this._options.contentType === "innerHTML") {
return this._targetEl.innerHTML;
}
if (this._options.contentType === "textContent") {
return this._targetEl.textContent.replace(/\s+/g, " ").trim();
}
};
CopyClipboard2.prototype.copy = function() {
var textToCopy = this.getTargetValue();
if (this._options.htmlEntities) {
textToCopy = this.decodeHTML(textToCopy);
}
var tempTextArea = document.createElement("textarea");
tempTextArea.value = textToCopy;
document.body.appendChild(tempTextArea);
tempTextArea.select();
document.execCommand("copy");
document.body.removeChild(tempTextArea);
this._options.onCopy(this);
return textToCopy;
};
CopyClipboard2.prototype.decodeHTML = function(html) {
var textarea = document.createElement("textarea");
textarea.innerHTML = html;
return textarea.textContent;
};
CopyClipboard2.prototype.updateOnCopyCallback = function(callback) {
this._options.onCopy = callback;
};
return CopyClipboard2;
}()
);
function initCopyClipboards() {
document.querySelectorAll("[data-copy-to-clipboard-target]").forEach(function($triggerEl) {
var targetId = $triggerEl.getAttribute("data-copy-to-clipboard-target");
var $targetEl = document.getElementById(targetId);
var contentType = $triggerEl.getAttribute("data-copy-to-clipboard-content-type");
var htmlEntities = $triggerEl.getAttribute("data-copy-to-clipboard-html-entities");
if ($targetEl) {
if (!instances_default.instanceExists("CopyClipboard", $targetEl.getAttribute("id"))) {
new CopyClipboard($triggerEl, $targetEl, {
htmlEntities: htmlEntities && htmlEntities === "true" ? true : Default13.htmlEntities,
contentType: contentType ? contentType : Default13.contentType
});
}
} else {
console.error('The target element with id "'.concat(targetId, '" does not exist. Please check the data-copy-to-clipboard-target attribute.'));
}
});
}
if (typeof window !== "undefined") {
window.CopyClipboard = CopyClipboard;
window.initClipboards = initCopyClipboards;
}
// node_modules/flowbite/lib/esm/components/index.js
function initFlowbite() {
initAccordions();
initCollapses();
initCarousels();
initDismisses();
initDropdowns();
initModals();
initDrawers();
initTabs();
initTooltips();
initPopovers();
initDials();
initInputCounters();
initCopyClipboards();
}
if (typeof window !== "undefined") {
window.initFlowbite = initFlowbite;
}
// node_modules/flowbite/lib/esm/index.js
var events = new events_default("load", [
initAccordions,
initCollapses,
initCarousels,
initDismisses,
initDropdowns,
initModals,
initDrawers,
initTabs,
initTooltips,
initPopovers,
initDials,
initInputCounters,
initCopyClipboards
]);
events.init();
// src/js/controllers/resource_drop_down_controller.js
var resource_drop_down_controller_default = class extends Controller {
static targets = ["trigger", "menu"];
connect() {
console.log(`resource-drop-down connected: ${this.element}`);
this.dropdown = new dropdown_default(this.menuTarget, this.triggerTarget);
}
disconnect() {
this.dropdown = null;
}
toggle() {
this.dropdown.toggle();
}
show() {
this.dropdown.show();
}
hide() {
this.dropdown.hide();
}
};
// src/js/controllers/resource_collapse_controller.js
var resource_collapse_controller_default = class extends Controller {
static targets = ["trigger", "menu"];
connect() {
console.log(`resource-collapse connected: ${this.element}`);
this.collapse = new collapse_default(this.menuTarget, this.triggerTarget);
}
disconnect() {
this.collapse = null;
}
toggle() {
this.collapse.toggle();
}
show() {
this.collapse.show();
}
hide() {
this.collapse.hide();
}
};
// src/js/controllers/resource_dismiss_controller.js
var resource_dismiss_controller_default = class extends Controller {
static values = {
after: Number
};
connect() {
console.log(`resource-dismiss connected: ${this.element}`);
if (this.hasAfterValue && this.afterValue > 0) {
this.autoDismissTimeout = setTimeout(() => {
this.dismiss();
this.autoDismissTimeout = null;
}, this.afterValue);
}
}
disconnect() {
if (this.autoDismissTimeout)
clearTimeout(this.autoDismissTimeout);
this.autoDismissTimeout = null;
}
dismiss() {
this.element.remove();
}
};
// src/js/controllers/frame_navigator_controller.js
var frame_navigator_controller_default = class extends Controller {
static targets = ["frame", "refreshButton", "backButton", "homeButton"];
connect() {
console.log(`frame-navigator connected: ${this.element}`);
this.#loadingStarted();
this.srcHistory = [];
this.originalFrameSrc = this.frameTarget.src;
if (this.hasRefreshButtonTarget) {
this.refreshButtonTarget.style.display = "";
this.refreshButtonClicked = this.refreshButtonClicked.bind(this);
this.refreshButtonTarget.addEventListener("click", this.refreshButtonClicked);
}
if (this.hasBackButtonTarget) {
this.backButtonClicked = this.backButtonClicked.bind(this);
this.backButtonTarget.addEventListener("click", this.backButtonClicked);
}
if (this.hasHomeButtonTarget) {
this.homeButtonClicked = this.homeButtonClicked.bind(this);
this.homeButtonTarget.addEventListener("click", this.homeButtonClicked);
}
this.frameLoaded = this.frameLoaded.bind(this);
this.frameTarget.addEventListener("turbo:frame-load", this.frameLoaded);
this.frameLoading = this.frameLoading.bind(this);
this.frameTarget.addEventListener("turbo:click", this.frameLoading);
this.frameTarget.addEventListener("turbo:submit-start", this.frameLoading);
this.frameFailed = this.frameFailed.bind(this);
this.frameTarget.addEventListener("turbo:fetch-request-error", this.frameFailed);
}
disconnect() {
if (this.hasRefreshButtonTarget)
this.refreshButtonTarget.removeEventListener("click", this.refreshButtonClicked);
if (this.hasBackButtonTarget)
this.backButtonTarget.removeEventListener("click", this.backButtonClicked);
if (this.hasHomeButtonTarget)
this.homeButtonTarget.removeEventListener("click", this.homeButtonClicked);
this.frameTarget.removeEventListener("turbo:frame-load", this.frameLoaded);
this.frameTarget.removeEventListener("turbo:click", this.frameLoading);
this.frameTarget.removeEventListener("turbo:submit-start", this.frameLoading);
this.frameTarget.removeEventListener("turbo:fetch-request-error", this.frameFailed);
}
frameLoading(event) {
this.#loadingStarted();
}
frameFailed(event) {
this.#loadingStopped();
}
frameLoaded(event) {
this.#loadingStopped();
let src = event.target.src;
if (src == this.currentSrc) {
} else if (src == this.originalFrameSrc)
this.srcHistory = [src];
else
this.srcHistory.push(src);
this.#updateNavigationButtonsDisplay();
}
refreshButtonClicked(event) {
this.frameLoading(null);
this.frameTarget.reload();
}
backButtonClicked(event) {
this.frameLoading(null);
this.srcHistory.pop();
this.frameTarget.src = this.currentSrc;
}
homeButtonClicked(event) {
this.frameLoading(null);
this.frameTarget.src = this.originalFrameSrc;
}
get currentSrc() {
return this.srcHistory[this.srcHistory.length - 1];
}
#loadingStarted() {
if (this.hasRefreshButtonTarget)
this.refreshButtonTarget.classList.add("motion-safe:animate-spin");
this.frameTarget.classList.add("motion-safe:animate-pulse");
}
#loadingStopped() {
if (this.hasRefreshButtonTarget)
this.refreshButtonTarget.classList.remove("motion-safe:animate-spin");
this.frameTarget.classList.remove("motion-safe:animate-pulse");
}
#updateNavigationButtonsDisplay() {
if (this.hasHomeButtonTarget) {
this.homeButtonTarget.style.display = this.srcHistory.length > 2 ? "" : "none";
}
if (this.hasBackButtonTarget) {
this.backButtonTarget.style.display = this.srcHistory.length > 1 ? "" : "none";
}
}
};
// src/js/controllers/color_mode_controller.js
var color_mode_controller_default = class extends Controller {
// static targets = ["trigger", "menu"]
connect() {
console.log(`color-mode connected: ${this.element}`);
this.updateColorMode();
}
disconnect() {
}
updateColorMode() {
if (localStorage.theme === "dark" || !("theme" in localStorage) && window.matchMedia("(prefers-color-scheme: dark)").matches) {
document.documentElement.classList.add("dark");
} else {
document.documentElement.classList.remove("dark");
}
}
setLightColorMode() {
localStorage.theme = "light";
this.updateColorMode();
}
setDarkColorMode() {
localStorage.theme = "dark";
this.updateColorMode();
}
setSystemColorMode() {
localStorage.removeItem("theme");
this.updateColorMode();
}
};
// src/js/controllers/easymde_controller.js
var easymde_controller_default = class extends Controller {
connect() {
console.log(`easymde connected: ${this.element}`);
self.easyMDE = new EasyMDE({ element: this.element });
}
disconnect() {
self.easyMDE.toTextArea();
self.easyMDE = null;
}
};
// src/js/controllers/slim_select_controller.js
var slim_select_controller_default = class extends Controller {
connect() {
console.log(`slim-select connected: ${this.element}`);
self.slimSelect = new SlimSelect({
select: this.element
});
}
disconnect() {
self.slimSelect.destroy();
self.slimSelect = null;
}
};
// src/js/controllers/flatpickr_controller.js
var flatpickr_controller_default = class extends Controller {
connect() {
console.log(`flatpickr connected: ${this.element}`);
self.picker = new flatpickr(this.element, this.#buildOptions());
}
disconnect() {
self.picker.destroy();
self.picker = null;
}
#buildOptions() {
let options = { altInput: true };
if (this.element.attributes.type.value == "datetime-local") {
options.enableTime = true;
} else if (this.element.attributes.type.value == "time") {
options.enableTime = true;
options.noCalendar = true;
}
return options;
}
};
// src/js/controllers/register_controllers.js
function register_controllers_default(application2) {
application2.register("resource-layout", resource_layout_controller_default);
application2.register("nav-grid-menu-item", nav_grid_menu_item_controller_default);
application2.register("nav-grid-menu", nav_grid_menu_controller_default);
application2.register("nav-user-section", nav_user_section_controller_default);
application2.register("nav-user-link", nav_user_link_controller_default);
application2.register("nav-user", nav_user_controller_default);
application2.register("header", header_controller_default);
application2.register("sidebar-menu-item", sidebar_menu_item_controller_default);
application2.register("sidebar-menu", sidebar_menu_controller_default);
application2.register("sidebar", sidebar_controller_default);
application2.register("has-many-panel", has_many_panel_controller_default);
application2.register("nested-resource-form-fields", nested_resource_form_fields_controller_default);
application2.register("toolbar", toolbar_controller_default);
application2.register("table-search-input", table_search_input_controller_default);
application2.register("table-toolbar", table_toolbar_controller_default);
application2.register("table", table_controller_default);
application2.register("form", form_controller_default);
application2.register("resource-drop-down", resource_drop_down_controller_default);
application2.register("resource-collapse", resource_collapse_controller_default);
application2.register("resource-dismiss", resource_dismiss_controller_default);
application2.register("frame-navigator", frame_navigator_controller_default);
application2.register("color-mode", color_mode_controller_default);
application2.register("easymde", easymde_controller_default);
application2.register("slim-select", slim_select_controller_default);
application2.register("flatpickr", flatpickr_controller_default);
}
// node_modules/@hotwired/turbo/dist/turbo.es2017-esm.js
(function(prototype) {
if (typeof prototype.requestSubmit == "function")
return;
prototype.requestSubmit = function(submitter) {
if (submitter) {
validateSubmitter(submitter, this);
submitter.click();
} else {
submitter = document.createElement("input");
submitter.type = "submit";
submitter.hidden = true;
this.appendChild(submitter);
submitter.click();
this.removeChild(submitter);
}
};
function validateSubmitter(submitter, form) {
submitter instanceof HTMLElement || raise(TypeError, "parameter 1 is not of type 'HTMLElement'");
submitter.type == "submit" || raise(TypeError, "The specified element is not a submit button");
submitter.form == form || raise(DOMException, "The specified element is not owned by this form element", "NotFoundError");
}
function raise(errorConstructor, message, name) {
throw new errorConstructor("Failed to execute 'requestSubmit' on 'HTMLFormElement': " + message + ".", name);
}
})(HTMLFormElement.prototype);
var submittersByForm = /* @__PURE__ */ new WeakMap();
function findSubmitterFromClickTarget(target) {
const element = target instanceof Element ? target : target instanceof Node ? target.parentElement : null;
const candidate = element ? element.closest("input, button") : null;
return candidate?.type == "submit" ? candidate : null;
}
function clickCaptured(event) {
const submitter = findSubmitterFromClickTarget(event.target);
if (submitter && submitter.form) {
submittersByForm.set(submitter.form, submitter);
}
}
(function() {
if ("submitter" in Event.prototype)
return;
let prototype = window.Event.prototype;
if ("SubmitEvent" in window) {
const prototypeOfSubmitEvent = window.SubmitEvent.prototype;
if (/Apple Computer/.test(navigator.vendor) && !("submitter" in prototypeOfSubmitEvent)) {
prototype = prototypeOfSubmitEvent;
} else {
return;
}
}
addEventListener("click", clickCaptured, true);
Object.defineProperty(prototype, "submitter", {
get() {
if (this.type == "submit" && this.target instanceof HTMLFormElement) {
return submittersByForm.get(this.target);
}
}
});
})();
var FrameLoadingStyle = {
eager: "eager",
lazy: "lazy"
};
var FrameElement = class _FrameElement extends HTMLElement {
static delegateConstructor = void 0;
loaded = Promise.resolve();
static get observedAttributes() {
return ["disabled", "loading", "src"];
}
constructor() {
super();
this.delegate = new _FrameElement.delegateConstructor(this);
}
connectedCallback() {
this.delegate.connect();
}
disconnectedCallback() {
this.delegate.disconnect();
}
reload() {
return this.delegate.sourceURLReloaded();
}
attributeChangedCallback(name) {
if (name == "loading") {
this.delegate.loadingStyleChanged();
} else if (name == "src") {
this.delegate.sourceURLChanged();
} else if (name == "disabled") {
this.delegate.disabledChanged();
}
}
/**
* Gets the URL to lazily load source HTML from
*/
get src() {
return this.getAttribute("src");
}
/**
* Sets the URL to lazily load source HTML from
*/
set src(value) {
if (value) {
this.setAttribute("src", value);
} else {
this.removeAttribute("src");
}
}
/**
* Gets the refresh mode for the frame.
*/
get refresh() {
return this.getAttribute("refresh");
}
/**
* Sets the refresh mode for the frame.
*/
set refresh(value) {
if (value) {
this.setAttribute("refresh", value);
} else {
this.removeAttribute("refresh");
}
}
/**
* Determines if the element is loading
*/
get loading() {
return frameLoadingStyleFromString(this.getAttribute("loading") || "");
}
/**
* Sets the value of if the element is loading
*/
set loading(value) {
if (value) {
this.setAttribute("loading", value);
} else {
this.removeAttribute("loading");
}
}
/**
* Gets the disabled state of the frame.
*
* If disabled, no requests will be intercepted by the frame.
*/
get disabled() {
return this.hasAttribute("disabled");
}
/**
* Sets the disabled state of the frame.
*
* If disabled, no requests will be intercepted by the frame.
*/
set disabled(value) {
if (value) {
this.setAttribute("disabled", "");
} else {
this.removeAttribute("disabled");
}
}
/**
* Gets the autoscroll state of the frame.
*
* If true, the frame will be scrolled into view automatically on update.
*/
get autoscroll() {
return this.hasAttribute("autoscroll");
}
/**
* Sets the autoscroll state of the frame.
*
* If true, the frame will be scrolled into view automatically on update.
*/
set autoscroll(value) {
if (value) {
this.setAttribute("autoscroll", "");
} else {
this.removeAttribute("autoscroll");
}
}
/**
* Determines if the element has finished loading
*/
get complete() {
return !this.delegate.isLoading;
}
/**
* Gets the active state of the frame.
*
* If inactive, source changes will not be observed.
*/
get isActive() {
return this.ownerDocument === document && !this.isPreview;
}
/**
* Sets the active state of the frame.
*
* If inactive, source changes will not be observed.
*/
get isPreview() {
return this.ownerDocument?.documentElement?.hasAttribute("data-turbo-preview");
}
};
function frameLoadingStyleFromString(style) {
switch (style.toLowerCase()) {
case "lazy":
return FrameLoadingStyle.lazy;
default:
return FrameLoadingStyle.eager;
}
}
function expandURL(locatable) {
return new URL(locatable.toString(), document.baseURI);
}
function getAnchor(url) {
let anchorMatch;
if (url.hash) {
return url.hash.slice(1);
} else if (anchorMatch = url.href.match(/#(.*)$/)) {
return anchorMatch[1];
}
}
function getAction$1(form, submitter) {
const action = submitter?.getAttribute("formaction") || form.getAttribute("action") || form.action;
return expandURL(action);
}
function getExtension(url) {
return (getLastPathComponent(url).match(/\.[^.]*$/) || [])[0] || "";
}
function isHTML(url) {
return !!getExtension(url).match(/^(?:|\.(?:htm|html|xhtml|php))$/);
}
function isPrefixedBy(baseURL, url) {
const prefix = getPrefix(url);
return baseURL.href === expandURL(prefix).href || baseURL.href.startsWith(prefix);
}
function locationIsVisitable(location2, rootLocation) {
return isPrefixedBy(location2, rootLocation) && isHTML(location2);
}
function getRequestURL(url) {
const anchor = getAnchor(url);
return anchor != null ? url.href.slice(0, -(anchor.length + 1)) : url.href;
}
function toCacheKey(url) {
return getRequestURL(url);
}
function urlsAreEqual(left2, right2) {
return expandURL(left2).href == expandURL(right2).href;
}
function getPathComponents(url) {
return url.pathname.split("/").slice(1);
}
function getLastPathComponent(url) {
return getPathComponents(url).slice(-1)[0];
}
function getPrefix(url) {
return addTrailingSlash(url.origin + url.pathname);
}
function addTrailingSlash(value) {
return value.endsWith("/") ? value : value + "/";
}
var FetchResponse = class {
constructor(response) {
this.response = response;
}
get succeeded() {
return this.response.ok;
}
get failed() {
return !this.succeeded;
}
get clientError() {
return this.statusCode >= 400 && this.statusCode <= 499;
}
get serverError() {
return this.statusCode >= 500 && this.statusCode <= 599;
}
get redirected() {
return this.response.redirected;
}
get location() {
return expandURL(this.response.url);
}
get isHTML() {
return this.contentType && this.contentType.match(/^(?:text\/([^\s;,]+\b)?html|application\/xhtml\+xml)\b/);
}
get statusCode() {
return this.response.status;
}
get contentType() {
return this.header("Content-Type");
}
get responseText() {
return this.response.clone().text();
}
get responseHTML() {
if (this.isHTML) {
return this.response.clone().text();
} else {
return Promise.resolve(void 0);
}
}
header(name) {
return this.response.headers.get(name);
}
};
function activateScriptElement(element) {
if (element.getAttribute("data-turbo-eval") == "false") {
return element;
} else {
const createdScriptElement = document.createElement("script");
const cspNonce = getMetaContent("csp-nonce");
if (cspNonce) {
createdScriptElement.nonce = cspNonce;
}
createdScriptElement.textContent = element.textContent;
createdScriptElement.async = false;
copyElementAttributes(createdScriptElement, element);
return createdScriptElement;
}
}
function copyElementAttributes(destinationElement, sourceElement) {
for (const { name, value } of sourceElement.attributes) {
destinationElement.setAttribute(name, value);
}
}
function createDocumentFragment(html) {
const template = document.createElement("template");
template.innerHTML = html;
return template.content;
}
function dispatch(eventName, { target, cancelable, detail } = {}) {
const event = new CustomEvent(eventName, {
cancelable,
bubbles: true,
composed: true,
detail
});
if (target && target.isConnected) {
target.dispatchEvent(event);
} else {
document.documentElement.dispatchEvent(event);
}
return event;
}
function nextRepaint() {
if (document.visibilityState === "hidden") {
return nextEventLoopTick();
} else {
return nextAnimationFrame();
}
}
function nextAnimationFrame() {
return new Promise((resolve) => requestAnimationFrame(() => resolve()));
}
function nextEventLoopTick() {
return new Promise((resolve) => setTimeout(() => resolve(), 0));
}
function nextMicrotask() {
return Promise.resolve();
}
function parseHTMLDocument(html = "") {
return new DOMParser().parseFromString(html, "text/html");
}
function unindent(strings, ...values) {
const lines = interpolate(strings, values).replace(/^\n/, "").split("\n");
const match = lines[0].match(/^\s+/);
const indent = match ? match[0].length : 0;
return lines.map((line) => line.slice(indent)).join("\n");
}
function interpolate(strings, values) {
return strings.reduce((result, string, i) => {
const value = values[i] == void 0 ? "" : values[i];
return result + string + value;
}, "");
}
function uuid() {
return Array.from({ length: 36 }).map((_, i) => {
if (i == 8 || i == 13 || i == 18 || i == 23) {
return "-";
} else if (i == 14) {
return "4";
} else if (i == 19) {
return (Math.floor(Math.random() * 4) + 8).toString(16);
} else {
return Math.floor(Math.random() * 15).toString(16);
}
}).join("");
}
function getAttribute(attributeName, ...elements) {
for (const value of elements.map((element) => element?.getAttribute(attributeName))) {
if (typeof value == "string")
return value;
}
return null;
}
function hasAttribute(attributeName, ...elements) {
return elements.some((element) => element && element.hasAttribute(attributeName));
}
function markAsBusy(...elements) {
for (const element of elements) {
if (element.localName == "turbo-frame") {
element.setAttribute("busy", "");
}
element.setAttribute("aria-busy", "true");
}
}
function clearBusyState(...elements) {
for (const element of elements) {
if (element.localName == "turbo-frame") {
element.removeAttribute("busy");
}
element.removeAttribute("aria-busy");
}
}
function waitForLoad(element, timeoutInMilliseconds = 2e3) {
return new Promise((resolve) => {
const onComplete = () => {
element.removeEventListener("error", onComplete);
element.removeEventListener("load", onComplete);
resolve();
};
element.addEventListener("load", onComplete, { once: true });
element.addEventListener("error", onComplete, { once: true });
setTimeout(resolve, timeoutInMilliseconds);
});
}
function getHistoryMethodForAction(action) {
switch (action) {
case "replace":
return history.replaceState;
case "advance":
case "restore":
return history.pushState;
}
}
function isAction(action) {
return action == "advance" || action == "replace" || action == "restore";
}
function getVisitAction(...elements) {
const action = getAttribute("data-turbo-action", ...elements);
return isAction(action) ? action : null;
}
function getMetaElement(name) {
return document.querySelector(`meta[name="${name}"]`);
}
function getMetaContent(name) {
const element = getMetaElement(name);
return element && element.content;
}
function setMetaContent(name, content) {
let element = getMetaElement(name);
if (!element) {
element = document.createElement("meta");
element.setAttribute("name", name);
document.head.appendChild(element);
}
element.setAttribute("content", content);
return element;
}
function findClosestRecursively(element, selector) {
if (element instanceof Element) {
return element.closest(selector) || findClosestRecursively(element.assignedSlot || element.getRootNode()?.host, selector);
}
}
function elementIsFocusable(element) {
const inertDisabledOrHidden = "[inert], :disabled, [hidden], details:not([open]), dialog:not([open])";
return !!element && element.closest(inertDisabledOrHidden) == null && typeof element.focus == "function";
}
function queryAutofocusableElement(elementOrDocumentFragment) {
return Array.from(elementOrDocumentFragment.querySelectorAll("[autofocus]")).find(elementIsFocusable);
}
async function around(callback, reader) {
const before = reader();
callback();
await nextAnimationFrame();
const after = reader();
return [before, after];
}
function doesNotTargetIFrame(anchor) {
if (anchor.hasAttribute("target")) {
for (const element of document.getElementsByName(anchor.target)) {
if (element instanceof HTMLIFrameElement)
return false;
}
}
return true;
}
function findLinkFromClickTarget(target) {
return findClosestRecursively(target, "a[href]:not([target^=_]):not([download])");
}
function getLocationForLink(link) {
return expandURL(link.getAttribute("href") || "");
}
function debounce3(fn2, delay) {
let timeoutId = null;
return (...args) => {
const callback = () => fn2.apply(this, args);
clearTimeout(timeoutId);
timeoutId = setTimeout(callback, delay);
};
}
var LimitedSet = class extends Set {
constructor(maxSize) {
super();
this.maxSize = maxSize;
}
add(value) {
if (this.size >= this.maxSize) {
const iterator = this.values();
const oldestValue = iterator.next().value;
this.delete(oldestValue);
}
super.add(value);
}
};
var recentRequests = new LimitedSet(20);
var nativeFetch = window.fetch;
function fetchWithTurboHeaders(url, options = {}) {
const modifiedHeaders = new Headers(options.headers || {});
const requestUID = uuid();
recentRequests.add(requestUID);
modifiedHeaders.append("X-Turbo-Request-Id", requestUID);
return nativeFetch(url, {
...options,
headers: modifiedHeaders
});
}
function fetchMethodFromString(method) {
switch (method.toLowerCase()) {
case "get":
return FetchMethod.get;
case "post":
return FetchMethod.post;
case "put":
return FetchMethod.put;
case "patch":
return FetchMethod.patch;
case "delete":
return FetchMethod.delete;
}
}
var FetchMethod = {
get: "get",
post: "post",
put: "put",
patch: "patch",
delete: "delete"
};
function fetchEnctypeFromString(encoding) {
switch (encoding.toLowerCase()) {
case FetchEnctype.multipart:
return FetchEnctype.multipart;
case FetchEnctype.plain:
return FetchEnctype.plain;
default:
return FetchEnctype.urlEncoded;
}
}
var FetchEnctype = {
urlEncoded: "application/x-www-form-urlencoded",
multipart: "multipart/form-data",
plain: "text/plain"
};
var FetchRequest = class {
abortController = new AbortController();
#resolveRequestPromise = (_value) => {
};
constructor(delegate, method, location2, requestBody = new URLSearchParams(), target = null, enctype = FetchEnctype.urlEncoded) {
const [url, body] = buildResourceAndBody(expandURL(location2), method, requestBody, enctype);
this.delegate = delegate;
this.url = url;
this.target = target;
this.fetchOptions = {
credentials: "same-origin",
redirect: "follow",
method,
headers: { ...this.defaultHeaders },
body,
signal: this.abortSignal,
referrer: this.delegate.referrer?.href
};
this.enctype = enctype;
}
get method() {
return this.fetchOptions.method;
}
set method(value) {
const fetchBody = this.isSafe ? this.url.searchParams : this.fetchOptions.body || new FormData();
const fetchMethod = fetchMethodFromString(value) || FetchMethod.get;
this.url.search = "";
const [url, body] = buildResourceAndBody(this.url, fetchMethod, fetchBody, this.enctype);
this.url = url;
this.fetchOptions.body = body;
this.fetchOptions.method = fetchMethod;
}
get headers() {
return this.fetchOptions.headers;
}
set headers(value) {
this.fetchOptions.headers = value;
}
get body() {
if (this.isSafe) {
return this.url.searchParams;
} else {
return this.fetchOptions.body;
}
}
set body(value) {
this.fetchOptions.body = value;
}
get location() {
return this.url;
}
get params() {
return this.url.searchParams;
}
get entries() {
return this.body ? Array.from(this.body.entries()) : [];
}
cancel() {
this.abortController.abort();
}
async perform() {
const { fetchOptions } = this;
this.delegate.prepareRequest(this);
const event = await this.#allowRequestToBeIntercepted(fetchOptions);
try {
this.delegate.requestStarted(this);
if (event.detail.fetchRequest) {
this.response = event.detail.fetchRequest.response;
} else {
this.response = fetchWithTurboHeaders(this.url.href, fetchOptions);
}
const response = await this.response;
return await this.receive(response);
} catch (error2) {
if (error2.name !== "AbortError") {
if (this.#willDelegateErrorHandling(error2)) {
this.delegate.requestErrored(this, error2);
}
throw error2;
}
} finally {
this.delegate.requestFinished(this);
}
}
async receive(response) {
const fetchResponse = new FetchResponse(response);
const event = dispatch("turbo:before-fetch-response", {
cancelable: true,
detail: { fetchResponse },
target: this.target
});
if (event.defaultPrevented) {
this.delegate.requestPreventedHandlingResponse(this, fetchResponse);
} else if (fetchResponse.succeeded) {
this.delegate.requestSucceededWithResponse(this, fetchResponse);
} else {
this.delegate.requestFailedWithResponse(this, fetchResponse);
}
return fetchResponse;
}
get defaultHeaders() {
return {
Accept: "text/html, application/xhtml+xml"
};
}
get isSafe() {
return isSafe(this.method);
}
get abortSignal() {
return this.abortController.signal;
}
acceptResponseType(mimeType) {
this.headers["Accept"] = [mimeType, this.headers["Accept"]].join(", ");
}
async #allowRequestToBeIntercepted(fetchOptions) {
const requestInterception = new Promise((resolve) => this.#resolveRequestPromise = resolve);
const event = dispatch("turbo:before-fetch-request", {
cancelable: true,
detail: {
fetchOptions,
url: this.url,
resume: this.#resolveRequestPromise
},
target: this.target
});
this.url = event.detail.url;
if (event.defaultPrevented)
await requestInterception;
return event;
}
#willDelegateErrorHandling(error2) {
const event = dispatch("turbo:fetch-request-error", {
target: this.target,
cancelable: true,
detail: { request: this, error: error2 }
});
return !event.defaultPrevented;
}
};
function isSafe(fetchMethod) {
return fetchMethodFromString(fetchMethod) == FetchMethod.get;
}
function buildResourceAndBody(resource, method, requestBody, enctype) {
const searchParams = Array.from(requestBody).length > 0 ? new URLSearchParams(entriesExcludingFiles(requestBody)) : resource.searchParams;
if (isSafe(method)) {
return [mergeIntoURLSearchParams(resource, searchParams), null];
} else if (enctype == FetchEnctype.urlEncoded) {
return [resource, searchParams];
} else {
return [resource, requestBody];
}
}
function entriesExcludingFiles(requestBody) {
const entries = [];
for (const [name, value] of requestBody) {
if (value instanceof File)
continue;
else
entries.push([name, value]);
}
return entries;
}
function mergeIntoURLSearchParams(url, requestBody) {
const searchParams = new URLSearchParams(entriesExcludingFiles(requestBody));
url.search = searchParams.toString();
return url;
}
var AppearanceObserver = class {
started = false;
constructor(delegate, element) {
this.delegate = delegate;
this.element = element;
this.intersectionObserver = new IntersectionObserver(this.intersect);
}
start() {
if (!this.started) {
this.started = true;
this.intersectionObserver.observe(this.element);
}
}
stop() {
if (this.started) {
this.started = false;
this.intersectionObserver.unobserve(this.element);
}
}
intersect = (entries) => {
const lastEntry = entries.slice(-1)[0];
if (lastEntry?.isIntersecting) {
this.delegate.elementAppearedInViewport(this.element);
}
};
};
var StreamMessage = class {
static contentType = "text/vnd.turbo-stream.html";
static wrap(message) {
if (typeof message == "string") {
return new this(createDocumentFragment(message));
} else {
return message;
}
}
constructor(fragment) {
this.fragment = importStreamElements(fragment);
}
};
function importStreamElements(fragment) {
for (const element of fragment.querySelectorAll("turbo-stream")) {
const streamElement = document.importNode(element, true);
for (const inertScriptElement of streamElement.templateElement.content.querySelectorAll("script")) {
inertScriptElement.replaceWith(activateScriptElement(inertScriptElement));
}
element.replaceWith(streamElement);
}
return fragment;
}
var PREFETCH_DELAY = 100;
var PrefetchCache = class {
#prefetchTimeout = null;
#prefetched = null;
get(url) {
if (this.#prefetched && this.#prefetched.url === url && this.#prefetched.expire > Date.now()) {
return this.#prefetched.request;
}
}
setLater(url, request, ttl) {
this.clear();
this.#prefetchTimeout = setTimeout(() => {
request.perform();
this.set(url, request, ttl);
this.#prefetchTimeout = null;
}, PREFETCH_DELAY);
}
set(url, request, ttl) {
this.#prefetched = { url, request, expire: new Date((/* @__PURE__ */ new Date()).getTime() + ttl) };
}
clear() {
if (this.#prefetchTimeout)
clearTimeout(this.#prefetchTimeout);
this.#prefetched = null;
}
};
var cacheTtl = 10 * 1e3;
var prefetchCache = new PrefetchCache();
var FormSubmissionState = {
initialized: "initialized",
requesting: "requesting",
waiting: "waiting",
receiving: "receiving",
stopping: "stopping",
stopped: "stopped"
};
var FormSubmission = class _FormSubmission {
state = FormSubmissionState.initialized;
static confirmMethod(message, _element, _submitter) {
return Promise.resolve(confirm(message));
}
constructor(delegate, formElement, submitter, mustRedirect = false) {
const method = getMethod(formElement, submitter);
const action = getAction(getFormAction(formElement, submitter), method);
const body = buildFormData(formElement, submitter);
const enctype = getEnctype(formElement, submitter);
this.delegate = delegate;
this.formElement = formElement;
this.submitter = submitter;
this.fetchRequest = new FetchRequest(this, method, action, body, formElement, enctype);
this.mustRedirect = mustRedirect;
}
get method() {
return this.fetchRequest.method;
}
set method(value) {
this.fetchRequest.method = value;
}
get action() {
return this.fetchRequest.url.toString();
}
set action(value) {
this.fetchRequest.url = expandURL(value);
}
get body() {
return this.fetchRequest.body;
}
get enctype() {
return this.fetchRequest.enctype;
}
get isSafe() {
return this.fetchRequest.isSafe;
}
get location() {
return this.fetchRequest.url;
}
// The submission process
async start() {
const { initialized, requesting } = FormSubmissionState;
const confirmationMessage = getAttribute("data-turbo-confirm", this.submitter, this.formElement);
if (typeof confirmationMessage === "string") {
const answer = await _FormSubmission.confirmMethod(confirmationMessage, this.formElement, this.submitter);
if (!answer) {
return;
}
}
if (this.state == initialized) {
this.state = requesting;
return this.fetchRequest.perform();
}
}
stop() {
const { stopping, stopped } = FormSubmissionState;
if (this.state != stopping && this.state != stopped) {
this.state = stopping;
this.fetchRequest.cancel();
return true;
}
}
// Fetch request delegate
prepareRequest(request) {
if (!request.isSafe) {
const token = getCookieValue(getMetaContent("csrf-param")) || getMetaContent("csrf-token");
if (token) {
request.headers["X-CSRF-Token"] = token;
}
}
if (this.requestAcceptsTurboStreamResponse(request)) {
request.acceptResponseType(StreamMessage.contentType);
}
}
requestStarted(_request) {
this.state = FormSubmissionState.waiting;
this.submitter?.setAttribute("disabled", "");
this.setSubmitsWith();
markAsBusy(this.formElement);
dispatch("turbo:submit-start", {
target: this.formElement,
detail: { formSubmission: this }
});
this.delegate.formSubmissionStarted(this);
}
requestPreventedHandlingResponse(request, response) {
prefetchCache.clear();
this.result = { success: response.succeeded, fetchResponse: response };
}
requestSucceededWithResponse(request, response) {
if (response.clientError || response.serverError) {
this.delegate.formSubmissionFailedWithResponse(this, response);
return;
}
prefetchCache.clear();
if (this.requestMustRedirect(request) && responseSucceededWithoutRedirect(response)) {
const error2 = new Error("Form responses must redirect to another location");
this.delegate.formSubmissionErrored(this, error2);
} else {
this.state = FormSubmissionState.receiving;
this.result = { success: true, fetchResponse: response };
this.delegate.formSubmissionSucceededWithResponse(this, response);
}
}
requestFailedWithResponse(request, response) {
this.result = { success: false, fetchResponse: response };
this.delegate.formSubmissionFailedWithResponse(this, response);
}
requestErrored(request, error2) {
this.result = { success: false, error: error2 };
this.delegate.formSubmissionErrored(this, error2);
}
requestFinished(_request) {
this.state = FormSubmissionState.stopped;
this.submitter?.removeAttribute("disabled");
this.resetSubmitterText();
clearBusyState(this.formElement);
dispatch("turbo:submit-end", {
target: this.formElement,
detail: { formSubmission: this, ...this.result }
});
this.delegate.formSubmissionFinished(this);
}
// Private
setSubmitsWith() {
if (!this.submitter || !this.submitsWith)
return;
if (this.submitter.matches("button")) {
this.originalSubmitText = this.submitter.innerHTML;
this.submitter.innerHTML = this.submitsWith;
} else if (this.submitter.matches("input")) {
const input = this.submitter;
this.originalSubmitText = input.value;
input.value = this.submitsWith;
}
}
resetSubmitterText() {
if (!this.submitter || !this.originalSubmitText)
return;
if (this.submitter.matches("button")) {
this.submitter.innerHTML = this.originalSubmitText;
} else if (this.submitter.matches("input")) {
const input = this.submitter;
input.value = this.originalSubmitText;
}
}
requestMustRedirect(request) {
return !request.isSafe && this.mustRedirect;
}
requestAcceptsTurboStreamResponse(request) {
return !request.isSafe || hasAttribute("data-turbo-stream", this.submitter, this.formElement);
}
get submitsWith() {
return this.submitter?.getAttribute("data-turbo-submits-with");
}
};
function buildFormData(formElement, submitter) {
const formData = new FormData(formElement);
const name = submitter?.getAttribute("name");
const value = submitter?.getAttribute("value");
if (name) {
formData.append(name, value || "");
}
return formData;
}
function getCookieValue(cookieName) {
if (cookieName != null) {
const cookies = document.cookie ? document.cookie.split("; ") : [];
const cookie = cookies.find((cookie2) => cookie2.startsWith(cookieName));
if (cookie) {
const value = cookie.split("=").slice(1).join("=");
return value ? decodeURIComponent(value) : void 0;
}
}
}
function responseSucceededWithoutRedirect(response) {
return response.statusCode == 200 && !response.redirected;
}
function getFormAction(formElement, submitter) {
const formElementAction = typeof formElement.action === "string" ? formElement.action : null;
if (submitter?.hasAttribute("formaction")) {
return submitter.getAttribute("formaction") || "";
} else {
return formElement.getAttribute("action") || formElementAction || "";
}
}
function getAction(formAction, fetchMethod) {
const action = expandURL(formAction);
if (isSafe(fetchMethod)) {
action.search = "";
}
return action;
}
function getMethod(formElement, submitter) {
const method = submitter?.getAttribute("formmethod") || formElement.getAttribute("method") || "";
return fetchMethodFromString(method.toLowerCase()) || FetchMethod.get;
}
function getEnctype(formElement, submitter) {
return fetchEnctypeFromString(submitter?.getAttribute("formenctype") || formElement.enctype);
}
var Snapshot = class {
constructor(element) {
this.element = element;
}
get activeElement() {
return this.element.ownerDocument.activeElement;
}
get children() {
return [...this.element.children];
}
hasAnchor(anchor) {
return this.getElementForAnchor(anchor) != null;
}
getElementForAnchor(anchor) {
return anchor ? this.element.querySelector(`[id='${anchor}'], a[name='${anchor}']`) : null;
}
get isConnected() {
return this.element.isConnected;
}
get firstAutofocusableElement() {
return queryAutofocusableElement(this.element);
}
get permanentElements() {
return queryPermanentElementsAll(this.element);
}
getPermanentElementById(id) {
return getPermanentElementById(this.element, id);
}
getPermanentElementMapForSnapshot(snapshot) {
const permanentElementMap = {};
for (const currentPermanentElement of this.permanentElements) {
const { id } = currentPermanentElement;
const newPermanentElement = snapshot.getPermanentElementById(id);
if (newPermanentElement) {
permanentElementMap[id] = [currentPermanentElement, newPermanentElement];
}
}
return permanentElementMap;
}
};
function getPermanentElementById(node, id) {
return node.querySelector(`#${id}[data-turbo-permanent]`);
}
function queryPermanentElementsAll(node) {
return node.querySelectorAll("[id][data-turbo-permanent]");
}
var FormSubmitObserver = class {
started = false;
constructor(delegate, eventTarget) {
this.delegate = delegate;
this.eventTarget = eventTarget;
}
start() {
if (!this.started) {
this.eventTarget.addEventListener("submit", this.submitCaptured, true);
this.started = true;
}
}
stop() {
if (this.started) {
this.eventTarget.removeEventListener("submit", this.submitCaptured, true);
this.started = false;
}
}
submitCaptured = () => {
this.eventTarget.removeEventListener("submit", this.submitBubbled, false);
this.eventTarget.addEventListener("submit", this.submitBubbled, false);
};
submitBubbled = (event) => {
if (!event.defaultPrevented) {
const form = event.target instanceof HTMLFormElement ? event.target : void 0;
const submitter = event.submitter || void 0;
if (form && submissionDoesNotDismissDialog(form, submitter) && submissionDoesNotTargetIFrame(form, submitter) && this.delegate.willSubmitForm(form, submitter)) {
event.preventDefault();
event.stopImmediatePropagation();
this.delegate.formSubmitted(form, submitter);
}
}
};
};
function submissionDoesNotDismissDialog(form, submitter) {
const method = submitter?.getAttribute("formmethod") || form.getAttribute("method");
return method != "dialog";
}
function submissionDoesNotTargetIFrame(form, submitter) {
if (submitter?.hasAttribute("formtarget") || form.hasAttribute("target")) {
const target = submitter?.getAttribute("formtarget") || form.target;
for (const element of document.getElementsByName(target)) {
if (element instanceof HTMLIFrameElement)
return false;
}
return true;
} else {
return true;
}
}
var View = class {
#resolveRenderPromise = (_value) => {
};
#resolveInterceptionPromise = (_value) => {
};
constructor(delegate, element) {
this.delegate = delegate;
this.element = element;
}
// Scrolling
scrollToAnchor(anchor) {
const element = this.snapshot.getElementForAnchor(anchor);
if (element) {
this.scrollToElement(element);
this.focusElement(element);
} else {
this.scrollToPosition({ x: 0, y: 0 });
}
}
scrollToAnchorFromLocation(location2) {
this.scrollToAnchor(getAnchor(location2));
}
scrollToElement(element) {
element.scrollIntoView();
}
focusElement(element) {
if (element instanceof HTMLElement) {
if (element.hasAttribute("tabindex")) {
element.focus();
} else {
element.setAttribute("tabindex", "-1");
element.focus();
element.removeAttribute("tabindex");
}
}
}
scrollToPosition({ x, y }) {
this.scrollRoot.scrollTo(x, y);
}
scrollToTop() {
this.scrollToPosition({ x: 0, y: 0 });
}
get scrollRoot() {
return window;
}
// Rendering
async render(renderer) {
const { isPreview, shouldRender, willRender, newSnapshot: snapshot } = renderer;
const shouldInvalidate = willRender;
if (shouldRender) {
try {
this.renderPromise = new Promise((resolve) => this.#resolveRenderPromise = resolve);
this.renderer = renderer;
await this.prepareToRenderSnapshot(renderer);
const renderInterception = new Promise((resolve) => this.#resolveInterceptionPromise = resolve);
const options = { resume: this.#resolveInterceptionPromise, render: this.renderer.renderElement, renderMethod: this.renderer.renderMethod };
const immediateRender = this.delegate.allowsImmediateRender(snapshot, options);
if (!immediateRender)
await renderInterception;
await this.renderSnapshot(renderer);
this.delegate.viewRenderedSnapshot(snapshot, isPreview, this.renderer.renderMethod);
this.delegate.preloadOnLoadLinksForView(this.element);
this.finishRenderingSnapshot(renderer);
} finally {
delete this.renderer;
this.#resolveRenderPromise(void 0);
delete this.renderPromise;
}
} else if (shouldInvalidate) {
this.invalidate(renderer.reloadReason);
}
}
invalidate(reason) {
this.delegate.viewInvalidated(reason);
}
async prepareToRenderSnapshot(renderer) {
this.markAsPreview(renderer.isPreview);
await renderer.prepareToRender();
}
markAsPreview(isPreview) {
if (isPreview) {
this.element.setAttribute("data-turbo-preview", "");
} else {
this.element.removeAttribute("data-turbo-preview");
}
}
markVisitDirection(direction) {
this.element.setAttribute("data-turbo-visit-direction", direction);
}
unmarkVisitDirection() {
this.element.removeAttribute("data-turbo-visit-direction");
}
async renderSnapshot(renderer) {
await renderer.render();
}
finishRenderingSnapshot(renderer) {
renderer.finishRendering();
}
};
var FrameView = class extends View {
missing() {
this.element.innerHTML = `Content missing`;
}
get snapshot() {
return new Snapshot(this.element);
}
};
var LinkInterceptor = class {
constructor(delegate, element) {
this.delegate = delegate;
this.element = element;
}
start() {
this.element.addEventListener("click", this.clickBubbled);
document.addEventListener("turbo:click", this.linkClicked);
document.addEventListener("turbo:before-visit", this.willVisit);
}
stop() {
this.element.removeEventListener("click", this.clickBubbled);
document.removeEventListener("turbo:click", this.linkClicked);
document.removeEventListener("turbo:before-visit", this.willVisit);
}
clickBubbled = (event) => {
if (this.respondsToEventTarget(event.target)) {
this.clickEvent = event;
} else {
delete this.clickEvent;
}
};
linkClicked = (event) => {
if (this.clickEvent && this.respondsToEventTarget(event.target) && event.target instanceof Element) {
if (this.delegate.shouldInterceptLinkClick(event.target, event.detail.url, event.detail.originalEvent)) {
this.clickEvent.preventDefault();
event.preventDefault();
this.delegate.linkClickIntercepted(event.target, event.detail.url, event.detail.originalEvent);
}
}
delete this.clickEvent;
};
willVisit = (_event) => {
delete this.clickEvent;
};
respondsToEventTarget(target) {
const element = target instanceof Element ? target : target instanceof Node ? target.parentElement : null;
return element && element.closest("turbo-frame, html") == this.element;
}
};
var LinkClickObserver = class {
started = false;
constructor(delegate, eventTarget) {
this.delegate = delegate;
this.eventTarget = eventTarget;
}
start() {
if (!this.started) {
this.eventTarget.addEventListener("click", this.clickCaptured, true);
this.started = true;
}
}
stop() {
if (this.started) {
this.eventTarget.removeEventListener("click", this.clickCaptured, true);
this.started = false;
}
}
clickCaptured = () => {
this.eventTarget.removeEventListener("click", this.clickBubbled, false);
this.eventTarget.addEventListener("click", this.clickBubbled, false);
};
clickBubbled = (event) => {
if (event instanceof MouseEvent && this.clickEventIsSignificant(event)) {
const target = event.composedPath && event.composedPath()[0] || event.target;
const link = findLinkFromClickTarget(target);
if (link && doesNotTargetIFrame(link)) {
const location2 = getLocationForLink(link);
if (this.delegate.willFollowLinkToLocation(link, location2, event)) {
event.preventDefault();
this.delegate.followedLinkToLocation(link, location2);
}
}
}
};
clickEventIsSignificant(event) {
return !(event.target && event.target.isContentEditable || event.defaultPrevented || event.which > 1 || event.altKey || event.ctrlKey || event.metaKey || event.shiftKey);
}
};
var FormLinkClickObserver = class {
constructor(delegate, element) {
this.delegate = delegate;
this.linkInterceptor = new LinkClickObserver(this, element);
}
start() {
this.linkInterceptor.start();
}
stop() {
this.linkInterceptor.stop();
}
// Link hover observer delegate
canPrefetchRequestToLocation(link, location2) {
return false;
}
prefetchAndCacheRequestToLocation(link, location2) {
return;
}
// Link click observer delegate
willFollowLinkToLocation(link, location2, originalEvent) {
return this.delegate.willSubmitFormLinkToLocation(link, location2, originalEvent) && (link.hasAttribute("data-turbo-method") || link.hasAttribute("data-turbo-stream"));
}
followedLinkToLocation(link, location2) {
const form = document.createElement("form");
const type = "hidden";
for (const [name, value] of location2.searchParams) {
form.append(Object.assign(document.createElement("input"), { type, name, value }));
}
const action = Object.assign(location2, { search: "" });
form.setAttribute("data-turbo", "true");
form.setAttribute("action", action.href);
form.setAttribute("hidden", "");
const method = link.getAttribute("data-turbo-method");
if (method)
form.setAttribute("method", method);
const turboFrame = link.getAttribute("data-turbo-frame");
if (turboFrame)
form.setAttribute("data-turbo-frame", turboFrame);
const turboAction = getVisitAction(link);
if (turboAction)
form.setAttribute("data-turbo-action", turboAction);
const turboConfirm = link.getAttribute("data-turbo-confirm");
if (turboConfirm)
form.setAttribute("data-turbo-confirm", turboConfirm);
const turboStream = link.hasAttribute("data-turbo-stream");
if (turboStream)
form.setAttribute("data-turbo-stream", "");
this.delegate.submittedFormLinkToLocation(link, location2, form);
document.body.appendChild(form);
form.addEventListener("turbo:submit-end", () => form.remove(), { once: true });
requestAnimationFrame(() => form.requestSubmit());
}
};
var Bardo = class {
static async preservingPermanentElements(delegate, permanentElementMap, callback) {
const bardo = new this(delegate, permanentElementMap);
bardo.enter();
await callback();
bardo.leave();
}
constructor(delegate, permanentElementMap) {
this.delegate = delegate;
this.permanentElementMap = permanentElementMap;
}
enter() {
for (const id in this.permanentElementMap) {
const [currentPermanentElement, newPermanentElement] = this.permanentElementMap[id];
this.delegate.enteringBardo(currentPermanentElement, newPermanentElement);
this.replaceNewPermanentElementWithPlaceholder(newPermanentElement);
}
}
leave() {
for (const id in this.permanentElementMap) {
const [currentPermanentElement] = this.permanentElementMap[id];
this.replaceCurrentPermanentElementWithClone(currentPermanentElement);
this.replacePlaceholderWithPermanentElement(currentPermanentElement);
this.delegate.leavingBardo(currentPermanentElement);
}
}
replaceNewPermanentElementWithPlaceholder(permanentElement) {
const placeholder = createPlaceholderForPermanentElement(permanentElement);
permanentElement.replaceWith(placeholder);
}
replaceCurrentPermanentElementWithClone(permanentElement) {
const clone = permanentElement.cloneNode(true);
permanentElement.replaceWith(clone);
}
replacePlaceholderWithPermanentElement(permanentElement) {
const placeholder = this.getPlaceholderById(permanentElement.id);
placeholder?.replaceWith(permanentElement);
}
getPlaceholderById(id) {
return this.placeholders.find((element) => element.content == id);
}
get placeholders() {
return [...document.querySelectorAll("meta[name=turbo-permanent-placeholder][content]")];
}
};
function createPlaceholderForPermanentElement(permanentElement) {
const element = document.createElement("meta");
element.setAttribute("name", "turbo-permanent-placeholder");
element.setAttribute("content", permanentElement.id);
return element;
}
var Renderer = class {
#activeElement = null;
constructor(currentSnapshot, newSnapshot, renderElement, isPreview, willRender = true) {
this.currentSnapshot = currentSnapshot;
this.newSnapshot = newSnapshot;
this.isPreview = isPreview;
this.willRender = willRender;
this.renderElement = renderElement;
this.promise = new Promise((resolve, reject) => this.resolvingFunctions = { resolve, reject });
}
get shouldRender() {
return true;
}
get reloadReason() {
return;
}
prepareToRender() {
return;
}
render() {
}
finishRendering() {
if (this.resolvingFunctions) {
this.resolvingFunctions.resolve();
delete this.resolvingFunctions;
}
}
async preservingPermanentElements(callback) {
await Bardo.preservingPermanentElements(this, this.permanentElementMap, callback);
}
focusFirstAutofocusableElement() {
const element = this.connectedSnapshot.firstAutofocusableElement;
if (element) {
element.focus();
}
}
// Bardo delegate
enteringBardo(currentPermanentElement) {
if (this.#activeElement)
return;
if (currentPermanentElement.contains(this.currentSnapshot.activeElement)) {
this.#activeElement = this.currentSnapshot.activeElement;
}
}
leavingBardo(currentPermanentElement) {
if (currentPermanentElement.contains(this.#activeElement) && this.#activeElement instanceof HTMLElement) {
this.#activeElement.focus();
this.#activeElement = null;
}
}
get connectedSnapshot() {
return this.newSnapshot.isConnected ? this.newSnapshot : this.currentSnapshot;
}
get currentElement() {
return this.currentSnapshot.element;
}
get newElement() {
return this.newSnapshot.element;
}
get permanentElementMap() {
return this.currentSnapshot.getPermanentElementMapForSnapshot(this.newSnapshot);
}
get renderMethod() {
return "replace";
}
};
var FrameRenderer = class extends Renderer {
static renderElement(currentElement, newElement) {
const destinationRange = document.createRange();
destinationRange.selectNodeContents(currentElement);
destinationRange.deleteContents();
const frameElement = newElement;
const sourceRange = frameElement.ownerDocument?.createRange();
if (sourceRange) {
sourceRange.selectNodeContents(frameElement);
currentElement.appendChild(sourceRange.extractContents());
}
}
constructor(delegate, currentSnapshot, newSnapshot, renderElement, isPreview, willRender = true) {
super(currentSnapshot, newSnapshot, renderElement, isPreview, willRender);
this.delegate = delegate;
}
get shouldRender() {
return true;
}
async render() {
await nextRepaint();
this.preservingPermanentElements(() => {
this.loadFrameElement();
});
this.scrollFrameIntoView();
await nextRepaint();
this.focusFirstAutofocusableElement();
await nextRepaint();
this.activateScriptElements();
}
loadFrameElement() {
this.delegate.willRenderFrame(this.currentElement, this.newElement);
this.renderElement(this.currentElement, this.newElement);
}
scrollFrameIntoView() {
if (this.currentElement.autoscroll || this.newElement.autoscroll) {
const element = this.currentElement.firstElementChild;
const block = readScrollLogicalPosition(this.currentElement.getAttribute("data-autoscroll-block"), "end");
const behavior = readScrollBehavior(this.currentElement.getAttribute("data-autoscroll-behavior"), "auto");
if (element) {
element.scrollIntoView({ block, behavior });
return true;
}
}
return false;
}
activateScriptElements() {
for (const inertScriptElement of this.newScriptElements) {
const activatedScriptElement = activateScriptElement(inertScriptElement);
inertScriptElement.replaceWith(activatedScriptElement);
}
}
get newScriptElements() {
return this.currentElement.querySelectorAll("script");
}
};
function readScrollLogicalPosition(value, defaultValue) {
if (value == "end" || value == "start" || value == "center" || value == "nearest") {
return value;
} else {
return defaultValue;
}
}
function readScrollBehavior(value, defaultValue) {
if (value == "auto" || value == "smooth") {
return value;
} else {
return defaultValue;
}
}
var ProgressBar = class _ProgressBar {
static animationDuration = 300;
/*ms*/
static get defaultCSS() {
return unindent`
.turbo-progress-bar {
position: fixed;
display: block;
top: 0;
left: 0;
height: 3px;
background: #0076ff;
z-index: 2147483647;
transition:
width ${_ProgressBar.animationDuration}ms ease-out,
opacity ${_ProgressBar.animationDuration / 2}ms ${_ProgressBar.animationDuration / 2}ms ease-in;
transform: translate3d(0, 0, 0);
}
`;
}
hiding = false;
value = 0;
visible = false;
constructor() {
this.stylesheetElement = this.createStylesheetElement();
this.progressElement = this.createProgressElement();
this.installStylesheetElement();
this.setValue(0);
}
show() {
if (!this.visible) {
this.visible = true;
this.installProgressElement();
this.startTrickling();
}
}
hide() {
if (this.visible && !this.hiding) {
this.hiding = true;
this.fadeProgressElement(() => {
this.uninstallProgressElement();
this.stopTrickling();
this.visible = false;
this.hiding = false;
});
}
}
setValue(value) {
this.value = value;
this.refresh();
}
// Private
installStylesheetElement() {
document.head.insertBefore(this.stylesheetElement, document.head.firstChild);
}
installProgressElement() {
this.progressElement.style.width = "0";
this.progressElement.style.opacity = "1";
document.documentElement.insertBefore(this.progressElement, document.body);
this.refresh();
}
fadeProgressElement(callback) {
this.progressElement.style.opacity = "0";
setTimeout(callback, _ProgressBar.animationDuration * 1.5);
}
uninstallProgressElement() {
if (this.progressElement.parentNode) {
document.documentElement.removeChild(this.progressElement);
}
}
startTrickling() {
if (!this.trickleInterval) {
this.trickleInterval = window.setInterval(this.trickle, _ProgressBar.animationDuration);
}
}
stopTrickling() {
window.clearInterval(this.trickleInterval);
delete this.trickleInterval;
}
trickle = () => {
this.setValue(this.value + Math.random() / 100);
};
refresh() {
requestAnimationFrame(() => {
this.progressElement.style.width = `${10 + this.value * 90}%`;
});
}
createStylesheetElement() {
const element = document.createElement("style");
element.type = "text/css";
element.textContent = _ProgressBar.defaultCSS;
if (this.cspNonce) {
element.nonce = this.cspNonce;
}
return element;
}
createProgressElement() {
const element = document.createElement("div");
element.className = "turbo-progress-bar";
return element;
}
get cspNonce() {
return getMetaContent("csp-nonce");
}
};
var HeadSnapshot = class extends Snapshot {
detailsByOuterHTML = this.children.filter((element) => !elementIsNoscript(element)).map((element) => elementWithoutNonce(element)).reduce((result, element) => {
const { outerHTML } = element;
const details = outerHTML in result ? result[outerHTML] : {
type: elementType(element),
tracked: elementIsTracked(element),
elements: []
};
return {
...result,
[outerHTML]: {
...details,
elements: [...details.elements, element]
}
};
}, {});
get trackedElementSignature() {
return Object.keys(this.detailsByOuterHTML).filter((outerHTML) => this.detailsByOuterHTML[outerHTML].tracked).join("");
}
getScriptElementsNotInSnapshot(snapshot) {
return this.getElementsMatchingTypeNotInSnapshot("script", snapshot);
}
getStylesheetElementsNotInSnapshot(snapshot) {
return this.getElementsMatchingTypeNotInSnapshot("stylesheet", snapshot);
}
getElementsMatchingTypeNotInSnapshot(matchedType, snapshot) {
return Object.keys(this.detailsByOuterHTML).filter((outerHTML) => !(outerHTML in snapshot.detailsByOuterHTML)).map((outerHTML) => this.detailsByOuterHTML[outerHTML]).filter(({ type }) => type == matchedType).map(({ elements: [element] }) => element);
}
get provisionalElements() {
return Object.keys(this.detailsByOuterHTML).reduce((result, outerHTML) => {
const { type, tracked, elements } = this.detailsByOuterHTML[outerHTML];
if (type == null && !tracked) {
return [...result, ...elements];
} else if (elements.length > 1) {
return [...result, ...elements.slice(1)];
} else {
return result;
}
}, []);
}
getMetaValue(name) {
const element = this.findMetaElementByName(name);
return element ? element.getAttribute("content") : null;
}
findMetaElementByName(name) {
return Object.keys(this.detailsByOuterHTML).reduce((result, outerHTML) => {
const {
elements: [element]
} = this.detailsByOuterHTML[outerHTML];
return elementIsMetaElementWithName(element, name) ? element : result;
}, void 0 | void 0);
}
};
function elementType(element) {
if (elementIsScript(element)) {
return "script";
} else if (elementIsStylesheet(element)) {
return "stylesheet";
}
}
function elementIsTracked(element) {
return element.getAttribute("data-turbo-track") == "reload";
}
function elementIsScript(element) {
const tagName = element.localName;
return tagName == "script";
}
function elementIsNoscript(element) {
const tagName = element.localName;
return tagName == "noscript";
}
function elementIsStylesheet(element) {
const tagName = element.localName;
return tagName == "style" || tagName == "link" && element.getAttribute("rel") == "stylesheet";
}
function elementIsMetaElementWithName(element, name) {
const tagName = element.localName;
return tagName == "meta" && element.getAttribute("name") == name;
}
function elementWithoutNonce(element) {
if (element.hasAttribute("nonce")) {
element.setAttribute("nonce", "");
}
return element;
}
var PageSnapshot = class _PageSnapshot extends Snapshot {
static fromHTMLString(html = "") {
return this.fromDocument(parseHTMLDocument(html));
}
static fromElement(element) {
return this.fromDocument(element.ownerDocument);
}
static fromDocument({ documentElement, body, head }) {
return new this(documentElement, body, new HeadSnapshot(head));
}
constructor(documentElement, body, headSnapshot) {
super(body);
this.documentElement = documentElement;
this.headSnapshot = headSnapshot;
}
clone() {
const clonedElement = this.element.cloneNode(true);
const selectElements = this.element.querySelectorAll("select");
const clonedSelectElements = clonedElement.querySelectorAll("select");
for (const [index, source] of selectElements.entries()) {
const clone = clonedSelectElements[index];
for (const option of clone.selectedOptions)
option.selected = false;
for (const option of source.selectedOptions)
clone.options[option.index].selected = true;
}
for (const clonedPasswordInput of clonedElement.querySelectorAll('input[type="password"]')) {
clonedPasswordInput.value = "";
}
return new _PageSnapshot(this.documentElement, clonedElement, this.headSnapshot);
}
get lang() {
return this.documentElement.getAttribute("lang");
}
get headElement() {
return this.headSnapshot.element;
}
get rootLocation() {
const root = this.getSetting("root") ?? "/";
return expandURL(root);
}
get cacheControlValue() {
return this.getSetting("cache-control");
}
get isPreviewable() {
return this.cacheControlValue != "no-preview";
}
get isCacheable() {
return this.cacheControlValue != "no-cache";
}
get isVisitable() {
return this.getSetting("visit-control") != "reload";
}
get prefersViewTransitions() {
return this.headSnapshot.getMetaValue("view-transition") === "same-origin";
}
get shouldMorphPage() {
return this.getSetting("refresh-method") === "morph";
}
get shouldPreserveScrollPosition() {
return this.getSetting("refresh-scroll") === "preserve";
}
// Private
getSetting(name) {
return this.headSnapshot.getMetaValue(`turbo-${name}`);
}
};
var ViewTransitioner = class {
#viewTransitionStarted = false;
#lastOperation = Promise.resolve();
renderChange(useViewTransition, render) {
if (useViewTransition && this.viewTransitionsAvailable && !this.#viewTransitionStarted) {
this.#viewTransitionStarted = true;
this.#lastOperation = this.#lastOperation.then(async () => {
await document.startViewTransition(render).finished;
});
} else {
this.#lastOperation = this.#lastOperation.then(render);
}
return this.#lastOperation;
}
get viewTransitionsAvailable() {
return document.startViewTransition;
}
};
var defaultOptions = {
action: "advance",
historyChanged: false,
visitCachedSnapshot: () => {
},
willRender: true,
updateHistory: true,
shouldCacheSnapshot: true,
acceptsStreamResponse: false
};
var TimingMetric = {
visitStart: "visitStart",
requestStart: "requestStart",
requestEnd: "requestEnd",
visitEnd: "visitEnd"
};
var VisitState = {
initialized: "initialized",
started: "started",
canceled: "canceled",
failed: "failed",
completed: "completed"
};
var SystemStatusCode = {
networkFailure: 0,
timeoutFailure: -1,
contentTypeMismatch: -2
};
var Direction = {
advance: "forward",
restore: "back",
replace: "none"
};
var Visit = class {
identifier = uuid();
// Required by turbo-ios
timingMetrics = {};
followedRedirect = false;
historyChanged = false;
scrolled = false;
shouldCacheSnapshot = true;
acceptsStreamResponse = false;
snapshotCached = false;
state = VisitState.initialized;
viewTransitioner = new ViewTransitioner();
constructor(delegate, location2, restorationIdentifier, options = {}) {
this.delegate = delegate;
this.location = location2;
this.restorationIdentifier = restorationIdentifier || uuid();
const {
action,
historyChanged,
referrer,
snapshot,
snapshotHTML,
response,
visitCachedSnapshot,
willRender,
updateHistory,
shouldCacheSnapshot,
acceptsStreamResponse,
direction
} = {
...defaultOptions,
...options
};
this.action = action;
this.historyChanged = historyChanged;
this.referrer = referrer;
this.snapshot = snapshot;
this.snapshotHTML = snapshotHTML;
this.response = response;
this.isSamePage = this.delegate.locationWithActionIsSamePage(this.location, this.action);
this.isPageRefresh = this.view.isPageRefresh(this);
this.visitCachedSnapshot = visitCachedSnapshot;
this.willRender = willRender;
this.updateHistory = updateHistory;
this.scrolled = !willRender;
this.shouldCacheSnapshot = shouldCacheSnapshot;
this.acceptsStreamResponse = acceptsStreamResponse;
this.direction = direction || Direction[action];
}
get adapter() {
return this.delegate.adapter;
}
get view() {
return this.delegate.view;
}
get history() {
return this.delegate.history;
}
get restorationData() {
return this.history.getRestorationDataForIdentifier(this.restorationIdentifier);
}
get silent() {
return this.isSamePage;
}
start() {
if (this.state == VisitState.initialized) {
this.recordTimingMetric(TimingMetric.visitStart);
this.state = VisitState.started;
this.adapter.visitStarted(this);
this.delegate.visitStarted(this);
}
}
cancel() {
if (this.state == VisitState.started) {
if (this.request) {
this.request.cancel();
}
this.cancelRender();
this.state = VisitState.canceled;
}
}
complete() {
if (this.state == VisitState.started) {
this.recordTimingMetric(TimingMetric.visitEnd);
this.adapter.visitCompleted(this);
this.state = VisitState.completed;
this.followRedirect();
if (!this.followedRedirect) {
this.delegate.visitCompleted(this);
}
}
}
fail() {
if (this.state == VisitState.started) {
this.state = VisitState.failed;
this.adapter.visitFailed(this);
this.delegate.visitCompleted(this);
}
}
changeHistory() {
if (!this.historyChanged && this.updateHistory) {
const actionForHistory = this.location.href === this.referrer?.href ? "replace" : this.action;
const method = getHistoryMethodForAction(actionForHistory);
this.history.update(method, this.location, this.restorationIdentifier);
this.historyChanged = true;
}
}
issueRequest() {
if (this.hasPreloadedResponse()) {
this.simulateRequest();
} else if (this.shouldIssueRequest() && !this.request) {
this.request = new FetchRequest(this, FetchMethod.get, this.location);
this.request.perform();
}
}
simulateRequest() {
if (this.response) {
this.startRequest();
this.recordResponse();
this.finishRequest();
}
}
startRequest() {
this.recordTimingMetric(TimingMetric.requestStart);
this.adapter.visitRequestStarted(this);
}
recordResponse(response = this.response) {
this.response = response;
if (response) {
const { statusCode } = response;
if (isSuccessful(statusCode)) {
this.adapter.visitRequestCompleted(this);
} else {
this.adapter.visitRequestFailedWithStatusCode(this, statusCode);
}
}
}
finishRequest() {
this.recordTimingMetric(TimingMetric.requestEnd);
this.adapter.visitRequestFinished(this);
}
loadResponse() {
if (this.response) {
const { statusCode, responseHTML } = this.response;
this.render(async () => {
if (this.shouldCacheSnapshot)
this.cacheSnapshot();
if (this.view.renderPromise)
await this.view.renderPromise;
if (isSuccessful(statusCode) && responseHTML != null) {
const snapshot = PageSnapshot.fromHTMLString(responseHTML);
await this.renderPageSnapshot(snapshot, false);
this.adapter.visitRendered(this);
this.complete();
} else {
await this.view.renderError(PageSnapshot.fromHTMLString(responseHTML), this);
this.adapter.visitRendered(this);
this.fail();
}
});
}
}
getCachedSnapshot() {
const snapshot = this.view.getCachedSnapshotForLocation(this.location) || this.getPreloadedSnapshot();
if (snapshot && (!getAnchor(this.location) || snapshot.hasAnchor(getAnchor(this.location)))) {
if (this.action == "restore" || snapshot.isPreviewable) {
return snapshot;
}
}
}
getPreloadedSnapshot() {
if (this.snapshotHTML) {
return PageSnapshot.fromHTMLString(this.snapshotHTML);
}
}
hasCachedSnapshot() {
return this.getCachedSnapshot() != null;
}
loadCachedSnapshot() {
const snapshot = this.getCachedSnapshot();
if (snapshot) {
const isPreview = this.shouldIssueRequest();
this.render(async () => {
this.cacheSnapshot();
if (this.isSamePage || this.isPageRefresh) {
this.adapter.visitRendered(this);
} else {
if (this.view.renderPromise)
await this.view.renderPromise;
await this.renderPageSnapshot(snapshot, isPreview);
this.adapter.visitRendered(this);
if (!isPreview) {
this.complete();
}
}
});
}
}
followRedirect() {
if (this.redirectedToLocation && !this.followedRedirect && this.response?.redirected) {
this.adapter.visitProposedToLocation(this.redirectedToLocation, {
action: "replace",
response: this.response,
shouldCacheSnapshot: false,
willRender: false
});
this.followedRedirect = true;
}
}
goToSamePageAnchor() {
if (this.isSamePage) {
this.render(async () => {
this.cacheSnapshot();
this.performScroll();
this.changeHistory();
this.adapter.visitRendered(this);
});
}
}
// Fetch request delegate
prepareRequest(request) {
if (this.acceptsStreamResponse) {
request.acceptResponseType(StreamMessage.contentType);
}
}
requestStarted() {
this.startRequest();
}
requestPreventedHandlingResponse(_request, _response) {
}
async requestSucceededWithResponse(request, response) {
const responseHTML = await response.responseHTML;
const { redirected, statusCode } = response;
if (responseHTML == void 0) {
this.recordResponse({
statusCode: SystemStatusCode.contentTypeMismatch,
redirected
});
} else {
this.redirectedToLocation = response.redirected ? response.location : void 0;
this.recordResponse({ statusCode, responseHTML, redirected });
}
}
async requestFailedWithResponse(request, response) {
const responseHTML = await response.responseHTML;
const { redirected, statusCode } = response;
if (responseHTML == void 0) {
this.recordResponse({
statusCode: SystemStatusCode.contentTypeMismatch,
redirected
});
} else {
this.recordResponse({ statusCode, responseHTML, redirected });
}
}
requestErrored(_request, _error) {
this.recordResponse({
statusCode: SystemStatusCode.networkFailure,
redirected: false
});
}
requestFinished() {
this.finishRequest();
}
// Scrolling
performScroll() {
if (!this.scrolled && !this.view.forceReloaded && !this.view.shouldPreserveScrollPosition(this)) {
if (this.action == "restore") {
this.scrollToRestoredPosition() || this.scrollToAnchor() || this.view.scrollToTop();
} else {
this.scrollToAnchor() || this.view.scrollToTop();
}
if (this.isSamePage) {
this.delegate.visitScrolledToSamePageLocation(this.view.lastRenderedLocation, this.location);
}
this.scrolled = true;
}
}
scrollToRestoredPosition() {
const { scrollPosition } = this.restorationData;
if (scrollPosition) {
this.view.scrollToPosition(scrollPosition);
return true;
}
}
scrollToAnchor() {
const anchor = getAnchor(this.location);
if (anchor != null) {
this.view.scrollToAnchor(anchor);
return true;
}
}
// Instrumentation
recordTimingMetric(metric) {
this.timingMetrics[metric] = (/* @__PURE__ */ new Date()).getTime();
}
getTimingMetrics() {
return { ...this.timingMetrics };
}
// Private
getHistoryMethodForAction(action) {
switch (action) {
case "replace":
return history.replaceState;
case "advance":
case "restore":
return history.pushState;
}
}
hasPreloadedResponse() {
return typeof this.response == "object";
}
shouldIssueRequest() {
if (this.isSamePage) {
return false;
} else if (this.action == "restore") {
return !this.hasCachedSnapshot();
} else {
return this.willRender;
}
}
cacheSnapshot() {
if (!this.snapshotCached) {
this.view.cacheSnapshot(this.snapshot).then((snapshot) => snapshot && this.visitCachedSnapshot(snapshot));
this.snapshotCached = true;
}
}
async render(callback) {
this.cancelRender();
this.frame = await nextRepaint();
await callback();
delete this.frame;
}
async renderPageSnapshot(snapshot, isPreview) {
await this.viewTransitioner.renderChange(this.view.shouldTransitionTo(snapshot), async () => {
await this.view.renderPage(snapshot, isPreview, this.willRender, this);
this.performScroll();
});
}
cancelRender() {
if (this.frame) {
cancelAnimationFrame(this.frame);
delete this.frame;
}
}
};
function isSuccessful(statusCode) {
return statusCode >= 200 && statusCode < 300;
}
var BrowserAdapter = class {
progressBar = new ProgressBar();
constructor(session2) {
this.session = session2;
}
visitProposedToLocation(location2, options) {
if (locationIsVisitable(location2, this.navigator.rootLocation)) {
this.navigator.startVisit(location2, options?.restorationIdentifier || uuid(), options);
} else {
window.location.href = location2.toString();
}
}
visitStarted(visit2) {
this.location = visit2.location;
visit2.loadCachedSnapshot();
visit2.issueRequest();
visit2.goToSamePageAnchor();
}
visitRequestStarted(visit2) {
this.progressBar.setValue(0);
if (visit2.hasCachedSnapshot() || visit2.action != "restore") {
this.showVisitProgressBarAfterDelay();
} else {
this.showProgressBar();
}
}
visitRequestCompleted(visit2) {
visit2.loadResponse();
}
visitRequestFailedWithStatusCode(visit2, statusCode) {
switch (statusCode) {
case SystemStatusCode.networkFailure:
case SystemStatusCode.timeoutFailure:
case SystemStatusCode.contentTypeMismatch:
return this.reload({
reason: "request_failed",
context: {
statusCode
}
});
default:
return visit2.loadResponse();
}
}
visitRequestFinished(_visit) {
}
visitCompleted(_visit) {
this.progressBar.setValue(1);
this.hideVisitProgressBar();
}
pageInvalidated(reason) {
this.reload(reason);
}
visitFailed(_visit) {
this.progressBar.setValue(1);
this.hideVisitProgressBar();
}
visitRendered(_visit) {
}
// Form Submission Delegate
formSubmissionStarted(_formSubmission) {
this.progressBar.setValue(0);
this.showFormProgressBarAfterDelay();
}
formSubmissionFinished(_formSubmission) {
this.progressBar.setValue(1);
this.hideFormProgressBar();
}
// Private
showVisitProgressBarAfterDelay() {
this.visitProgressBarTimeout = window.setTimeout(this.showProgressBar, this.session.progressBarDelay);
}
hideVisitProgressBar() {
this.progressBar.hide();
if (this.visitProgressBarTimeout != null) {
window.clearTimeout(this.visitProgressBarTimeout);
delete this.visitProgressBarTimeout;
}
}
showFormProgressBarAfterDelay() {
if (this.formProgressBarTimeout == null) {
this.formProgressBarTimeout = window.setTimeout(this.showProgressBar, this.session.progressBarDelay);
}
}
hideFormProgressBar() {
this.progressBar.hide();
if (this.formProgressBarTimeout != null) {
window.clearTimeout(this.formProgressBarTimeout);
delete this.formProgressBarTimeout;
}
}
showProgressBar = () => {
this.progressBar.show();
};
reload(reason) {
dispatch("turbo:reload", { detail: reason });
window.location.href = this.location?.toString() || window.location.href;
}
get navigator() {
return this.session.navigator;
}
};
var CacheObserver = class {
selector = "[data-turbo-temporary]";
deprecatedSelector = "[data-turbo-cache=false]";
started = false;
start() {
if (!this.started) {
this.started = true;
addEventListener("turbo:before-cache", this.removeTemporaryElements, false);
}
}
stop() {
if (this.started) {
this.started = false;
removeEventListener("turbo:before-cache", this.removeTemporaryElements, false);
}
}
removeTemporaryElements = (_event) => {
for (const element of this.temporaryElements) {
element.remove();
}
};
get temporaryElements() {
return [...document.querySelectorAll(this.selector), ...this.temporaryElementsWithDeprecation];
}
get temporaryElementsWithDeprecation() {
const elements = document.querySelectorAll(this.deprecatedSelector);
if (elements.length) {
console.warn(
`The ${this.deprecatedSelector} selector is deprecated and will be removed in a future version. Use ${this.selector} instead.`
);
}
return [...elements];
}
};
var FrameRedirector = class {
constructor(session2, element) {
this.session = session2;
this.element = element;
this.linkInterceptor = new LinkInterceptor(this, element);
this.formSubmitObserver = new FormSubmitObserver(this, element);
}
start() {
this.linkInterceptor.start();
this.formSubmitObserver.start();
}
stop() {
this.linkInterceptor.stop();
this.formSubmitObserver.stop();
}
// Link interceptor delegate
shouldInterceptLinkClick(element, _location, _event) {
return this.#shouldRedirect(element);
}
linkClickIntercepted(element, url, event) {
const frame = this.#findFrameElement(element);
if (frame) {
frame.delegate.linkClickIntercepted(element, url, event);
}
}
// Form submit observer delegate
willSubmitForm(element, submitter) {
return element.closest("turbo-frame") == null && this.#shouldSubmit(element, submitter) && this.#shouldRedirect(element, submitter);
}
formSubmitted(element, submitter) {
const frame = this.#findFrameElement(element, submitter);
if (frame) {
frame.delegate.formSubmitted(element, submitter);
}
}
#shouldSubmit(form, submitter) {
const action = getAction$1(form, submitter);
const meta = this.element.ownerDocument.querySelector(`meta[name="turbo-root"]`);
const rootLocation = expandURL(meta?.content ?? "/");
return this.#shouldRedirect(form, submitter) && locationIsVisitable(action, rootLocation);
}
#shouldRedirect(element, submitter) {
const isNavigatable = element instanceof HTMLFormElement ? this.session.submissionIsNavigatable(element, submitter) : this.session.elementIsNavigatable(element);
if (isNavigatable) {
const frame = this.#findFrameElement(element, submitter);
return frame ? frame != element.closest("turbo-frame") : false;
} else {
return false;
}
}
#findFrameElement(element, submitter) {
const id = submitter?.getAttribute("data-turbo-frame") || element.getAttribute("data-turbo-frame");
if (id && id != "_top") {
const frame = this.element.querySelector(`#${id}:not([disabled])`);
if (frame instanceof FrameElement) {
return frame;
}
}
}
};
var History = class {
location;
restorationIdentifier = uuid();
restorationData = {};
started = false;
pageLoaded = false;
currentIndex = 0;
constructor(delegate) {
this.delegate = delegate;
}
start() {
if (!this.started) {
addEventListener("popstate", this.onPopState, false);
addEventListener("load", this.onPageLoad, false);
this.currentIndex = history.state?.turbo?.restorationIndex || 0;
this.started = true;
this.replace(new URL(window.location.href));
}
}
stop() {
if (this.started) {
removeEventListener("popstate", this.onPopState, false);
removeEventListener("load", this.onPageLoad, false);
this.started = false;
}
}
push(location2, restorationIdentifier) {
this.update(history.pushState, location2, restorationIdentifier);
}
replace(location2, restorationIdentifier) {
this.update(history.replaceState, location2, restorationIdentifier);
}
update(method, location2, restorationIdentifier = uuid()) {
if (method === history.pushState)
++this.currentIndex;
const state = { turbo: { restorationIdentifier, restorationIndex: this.currentIndex } };
method.call(history, state, "", location2.href);
this.location = location2;
this.restorationIdentifier = restorationIdentifier;
}
// Restoration data
getRestorationDataForIdentifier(restorationIdentifier) {
return this.restorationData[restorationIdentifier] || {};
}
updateRestorationData(additionalData) {
const { restorationIdentifier } = this;
const restorationData = this.restorationData[restorationIdentifier];
this.restorationData[restorationIdentifier] = {
...restorationData,
...additionalData
};
}
// Scroll restoration
assumeControlOfScrollRestoration() {
if (!this.previousScrollRestoration) {
this.previousScrollRestoration = history.scrollRestoration ?? "auto";
history.scrollRestoration = "manual";
}
}
relinquishControlOfScrollRestoration() {
if (this.previousScrollRestoration) {
history.scrollRestoration = this.previousScrollRestoration;
delete this.previousScrollRestoration;
}
}
// Event handlers
onPopState = (event) => {
if (this.shouldHandlePopState()) {
const { turbo } = event.state || {};
if (turbo) {
this.location = new URL(window.location.href);
const { restorationIdentifier, restorationIndex } = turbo;
this.restorationIdentifier = restorationIdentifier;
const direction = restorationIndex > this.currentIndex ? "forward" : "back";
this.delegate.historyPoppedToLocationWithRestorationIdentifierAndDirection(this.location, restorationIdentifier, direction);
this.currentIndex = restorationIndex;
}
}
};
onPageLoad = async (_event) => {
await nextMicrotask();
this.pageLoaded = true;
};
// Private
shouldHandlePopState() {
return this.pageIsLoaded();
}
pageIsLoaded() {
return this.pageLoaded || document.readyState == "complete";
}
};
var LinkPrefetchObserver = class {
started = false;
#prefetchedLink = null;
constructor(delegate, eventTarget) {
this.delegate = delegate;
this.eventTarget = eventTarget;
}
start() {
if (this.started)
return;
if (this.eventTarget.readyState === "loading") {
this.eventTarget.addEventListener("DOMContentLoaded", this.#enable, { once: true });
} else {
this.#enable();
}
}
stop() {
if (!this.started)
return;
this.eventTarget.removeEventListener("mouseenter", this.#tryToPrefetchRequest, {
capture: true,
passive: true
});
this.eventTarget.removeEventListener("mouseleave", this.#cancelRequestIfObsolete, {
capture: true,
passive: true
});
this.eventTarget.removeEventListener("turbo:before-fetch-request", this.#tryToUsePrefetchedRequest, true);
this.started = false;
}
#enable = () => {
this.eventTarget.addEventListener("mouseenter", this.#tryToPrefetchRequest, {
capture: true,
passive: true
});
this.eventTarget.addEventListener("mouseleave", this.#cancelRequestIfObsolete, {
capture: true,
passive: true
});
this.eventTarget.addEventListener("turbo:before-fetch-request", this.#tryToUsePrefetchedRequest, true);
this.started = true;
};
#tryToPrefetchRequest = (event) => {
if (getMetaContent("turbo-prefetch") === "false")
return;
const target = event.target;
const isLink = target.matches && target.matches("a[href]:not([target^=_]):not([download])");
if (isLink && this.#isPrefetchable(target)) {
const link = target;
const location2 = getLocationForLink(link);
if (this.delegate.canPrefetchRequestToLocation(link, location2)) {
this.#prefetchedLink = link;
const fetchRequest = new FetchRequest(
this,
FetchMethod.get,
location2,
new URLSearchParams(),
target
);
prefetchCache.setLater(location2.toString(), fetchRequest, this.#cacheTtl);
}
}
};
#cancelRequestIfObsolete = (event) => {
if (event.target === this.#prefetchedLink)
this.#cancelPrefetchRequest();
};
#cancelPrefetchRequest = () => {
prefetchCache.clear();
this.#prefetchedLink = null;
};
#tryToUsePrefetchedRequest = (event) => {
if (event.target.tagName !== "FORM" && event.detail.fetchOptions.method === "get") {
const cached = prefetchCache.get(event.detail.url.toString());
if (cached) {
event.detail.fetchRequest = cached;
}
prefetchCache.clear();
}
};
prepareRequest(request) {
const link = request.target;
request.headers["X-Sec-Purpose"] = "prefetch";
const turboFrame = link.closest("turbo-frame");
const turboFrameTarget = link.getAttribute("data-turbo-frame") || turboFrame?.getAttribute("target") || turboFrame?.id;
if (turboFrameTarget && turboFrameTarget !== "_top") {
request.headers["Turbo-Frame"] = turboFrameTarget;
}
}
// Fetch request interface
requestSucceededWithResponse() {
}
requestStarted(fetchRequest) {
}
requestErrored(fetchRequest) {
}
requestFinished(fetchRequest) {
}
requestPreventedHandlingResponse(fetchRequest, fetchResponse) {
}
requestFailedWithResponse(fetchRequest, fetchResponse) {
}
get #cacheTtl() {
return Number(getMetaContent("turbo-prefetch-cache-time")) || cacheTtl;
}
#isPrefetchable(link) {
const href = link.getAttribute("href");
if (!href)
return false;
if (unfetchableLink(link))
return false;
if (linkToTheSamePage(link))
return false;
if (linkOptsOut(link))
return false;
if (nonSafeLink(link))
return false;
if (eventPrevented(link))
return false;
return true;
}
};
var unfetchableLink = (link) => {
return link.origin !== document.location.origin || !["http:", "https:"].includes(link.protocol) || link.hasAttribute("target");
};
var linkToTheSamePage = (link) => {
return link.pathname + link.search === document.location.pathname + document.location.search || link.href.startsWith("#");
};
var linkOptsOut = (link) => {
if (link.getAttribute("data-turbo-prefetch") === "false")
return true;
if (link.getAttribute("data-turbo") === "false")
return true;
const turboPrefetchParent = findClosestRecursively(link, "[data-turbo-prefetch]");
if (turboPrefetchParent && turboPrefetchParent.getAttribute("data-turbo-prefetch") === "false")
return true;
return false;
};
var nonSafeLink = (link) => {
const turboMethod = link.getAttribute("data-turbo-method");
if (turboMethod && turboMethod.toLowerCase() !== "get")
return true;
if (isUJS(link))
return true;
if (link.hasAttribute("data-turbo-confirm"))
return true;
if (link.hasAttribute("data-turbo-stream"))
return true;
return false;
};
var isUJS = (link) => {
return link.hasAttribute("data-remote") || link.hasAttribute("data-behavior") || link.hasAttribute("data-confirm") || link.hasAttribute("data-method");
};
var eventPrevented = (link) => {
const event = dispatch("turbo:before-prefetch", { target: link, cancelable: true });
return event.defaultPrevented;
};
var Navigator = class {
constructor(delegate) {
this.delegate = delegate;
}
proposeVisit(location2, options = {}) {
if (this.delegate.allowsVisitingLocationWithAction(location2, options.action)) {
this.delegate.visitProposedToLocation(location2, options);
}
}
startVisit(locatable, restorationIdentifier, options = {}) {
this.stop();
this.currentVisit = new Visit(this, expandURL(locatable), restorationIdentifier, {
referrer: this.location,
...options
});
this.currentVisit.start();
}
submitForm(form, submitter) {
this.stop();
this.formSubmission = new FormSubmission(this, form, submitter, true);
this.formSubmission.start();
}
stop() {
if (this.formSubmission) {
this.formSubmission.stop();
delete this.formSubmission;
}
if (this.currentVisit) {
this.currentVisit.cancel();
delete this.currentVisit;
}
}
get adapter() {
return this.delegate.adapter;
}
get view() {
return this.delegate.view;
}
get rootLocation() {
return this.view.snapshot.rootLocation;
}
get history() {
return this.delegate.history;
}
// Form submission delegate
formSubmissionStarted(formSubmission) {
if (typeof this.adapter.formSubmissionStarted === "function") {
this.adapter.formSubmissionStarted(formSubmission);
}
}
async formSubmissionSucceededWithResponse(formSubmission, fetchResponse) {
if (formSubmission == this.formSubmission) {
const responseHTML = await fetchResponse.responseHTML;
if (responseHTML) {
const shouldCacheSnapshot = formSubmission.isSafe;
if (!shouldCacheSnapshot) {
this.view.clearSnapshotCache();
}
const { statusCode, redirected } = fetchResponse;
const action = this.#getActionForFormSubmission(formSubmission, fetchResponse);
const visitOptions = {
action,
shouldCacheSnapshot,
response: { statusCode, responseHTML, redirected }
};
this.proposeVisit(fetchResponse.location, visitOptions);
}
}
}
async formSubmissionFailedWithResponse(formSubmission, fetchResponse) {
const responseHTML = await fetchResponse.responseHTML;
if (responseHTML) {
const snapshot = PageSnapshot.fromHTMLString(responseHTML);
if (fetchResponse.serverError) {
await this.view.renderError(snapshot, this.currentVisit);
} else {
await this.view.renderPage(snapshot, false, true, this.currentVisit);
}
if (!snapshot.shouldPreserveScrollPosition) {
this.view.scrollToTop();
}
this.view.clearSnapshotCache();
}
}
formSubmissionErrored(formSubmission, error2) {
console.error(error2);
}
formSubmissionFinished(formSubmission) {
if (typeof this.adapter.formSubmissionFinished === "function") {
this.adapter.formSubmissionFinished(formSubmission);
}
}
// Visit delegate
visitStarted(visit2) {
this.delegate.visitStarted(visit2);
}
visitCompleted(visit2) {
this.delegate.visitCompleted(visit2);
}
locationWithActionIsSamePage(location2, action) {
const anchor = getAnchor(location2);
const currentAnchor = getAnchor(this.view.lastRenderedLocation);
const isRestorationToTop = action === "restore" && typeof anchor === "undefined";
return action !== "replace" && getRequestURL(location2) === getRequestURL(this.view.lastRenderedLocation) && (isRestorationToTop || anchor != null && anchor !== currentAnchor);
}
visitScrolledToSamePageLocation(oldURL, newURL) {
this.delegate.visitScrolledToSamePageLocation(oldURL, newURL);
}
// Visits
get location() {
return this.history.location;
}
get restorationIdentifier() {
return this.history.restorationIdentifier;
}
#getActionForFormSubmission(formSubmission, fetchResponse) {
const { submitter, formElement } = formSubmission;
return getVisitAction(submitter, formElement) || this.#getDefaultAction(fetchResponse);
}
#getDefaultAction(fetchResponse) {
const sameLocationRedirect = fetchResponse.redirected && fetchResponse.location.href === this.location?.href;
return sameLocationRedirect ? "replace" : "advance";
}
};
var PageStage = {
initial: 0,
loading: 1,
interactive: 2,
complete: 3
};
var PageObserver = class {
stage = PageStage.initial;
started = false;
constructor(delegate) {
this.delegate = delegate;
}
start() {
if (!this.started) {
if (this.stage == PageStage.initial) {
this.stage = PageStage.loading;
}
document.addEventListener("readystatechange", this.interpretReadyState, false);
addEventListener("pagehide", this.pageWillUnload, false);
this.started = true;
}
}
stop() {
if (this.started) {
document.removeEventListener("readystatechange", this.interpretReadyState, false);
removeEventListener("pagehide", this.pageWillUnload, false);
this.started = false;
}
}
interpretReadyState = () => {
const { readyState } = this;
if (readyState == "interactive") {
this.pageIsInteractive();
} else if (readyState == "complete") {
this.pageIsComplete();
}
};
pageIsInteractive() {
if (this.stage == PageStage.loading) {
this.stage = PageStage.interactive;
this.delegate.pageBecameInteractive();
}
}
pageIsComplete() {
this.pageIsInteractive();
if (this.stage == PageStage.interactive) {
this.stage = PageStage.complete;
this.delegate.pageLoaded();
}
}
pageWillUnload = () => {
this.delegate.pageWillUnload();
};
get readyState() {
return document.readyState;
}
};
var ScrollObserver = class {
started = false;
constructor(delegate) {
this.delegate = delegate;
}
start() {
if (!this.started) {
addEventListener("scroll", this.onScroll, false);
this.onScroll();
this.started = true;
}
}
stop() {
if (this.started) {
removeEventListener("scroll", this.onScroll, false);
this.started = false;
}
}
onScroll = () => {
this.updatePosition({ x: window.pageXOffset, y: window.pageYOffset });
};
// Private
updatePosition(position) {
this.delegate.scrollPositionChanged(position);
}
};
var StreamMessageRenderer = class {
render({ fragment }) {
Bardo.preservingPermanentElements(this, getPermanentElementMapForFragment(fragment), () => {
withAutofocusFromFragment(fragment, () => {
withPreservedFocus(() => {
document.documentElement.appendChild(fragment);
});
});
});
}
// Bardo delegate
enteringBardo(currentPermanentElement, newPermanentElement) {
newPermanentElement.replaceWith(currentPermanentElement.cloneNode(true));
}
leavingBardo() {
}
};
function getPermanentElementMapForFragment(fragment) {
const permanentElementsInDocument = queryPermanentElementsAll(document.documentElement);
const permanentElementMap = {};
for (const permanentElementInDocument of permanentElementsInDocument) {
const { id } = permanentElementInDocument;
for (const streamElement of fragment.querySelectorAll("turbo-stream")) {
const elementInStream = getPermanentElementById(streamElement.templateElement.content, id);
if (elementInStream) {
permanentElementMap[id] = [permanentElementInDocument, elementInStream];
}
}
}
return permanentElementMap;
}
async function withAutofocusFromFragment(fragment, callback) {
const generatedID = `turbo-stream-autofocus-${uuid()}`;
const turboStreams = fragment.querySelectorAll("turbo-stream");
const elementWithAutofocus = firstAutofocusableElementInStreams(turboStreams);
let willAutofocusId = null;
if (elementWithAutofocus) {
if (elementWithAutofocus.id) {
willAutofocusId = elementWithAutofocus.id;
} else {
willAutofocusId = generatedID;
}
elementWithAutofocus.id = willAutofocusId;
}
callback();
await nextRepaint();
const hasNoActiveElement = document.activeElement == null || document.activeElement == document.body;
if (hasNoActiveElement && willAutofocusId) {
const elementToAutofocus = document.getElementById(willAutofocusId);
if (elementIsFocusable(elementToAutofocus)) {
elementToAutofocus.focus();
}
if (elementToAutofocus && elementToAutofocus.id == generatedID) {
elementToAutofocus.removeAttribute("id");
}
}
}
async function withPreservedFocus(callback) {
const [activeElementBeforeRender, activeElementAfterRender] = await around(callback, () => document.activeElement);
const restoreFocusTo = activeElementBeforeRender && activeElementBeforeRender.id;
if (restoreFocusTo) {
const elementToFocus = document.getElementById(restoreFocusTo);
if (elementIsFocusable(elementToFocus) && elementToFocus != activeElementAfterRender) {
elementToFocus.focus();
}
}
}
function firstAutofocusableElementInStreams(nodeListOfStreamElements) {
for (const streamElement of nodeListOfStreamElements) {
const elementWithAutofocus = queryAutofocusableElement(streamElement.templateElement.content);
if (elementWithAutofocus)
return elementWithAutofocus;
}
return null;
}
var StreamObserver = class {
sources = /* @__PURE__ */ new Set();
#started = false;
constructor(delegate) {
this.delegate = delegate;
}
start() {
if (!this.#started) {
this.#started = true;
addEventListener("turbo:before-fetch-response", this.inspectFetchResponse, false);
}
}
stop() {
if (this.#started) {
this.#started = false;
removeEventListener("turbo:before-fetch-response", this.inspectFetchResponse, false);
}
}
connectStreamSource(source) {
if (!this.streamSourceIsConnected(source)) {
this.sources.add(source);
source.addEventListener("message", this.receiveMessageEvent, false);
}
}
disconnectStreamSource(source) {
if (this.streamSourceIsConnected(source)) {
this.sources.delete(source);
source.removeEventListener("message", this.receiveMessageEvent, false);
}
}
streamSourceIsConnected(source) {
return this.sources.has(source);
}
inspectFetchResponse = (event) => {
const response = fetchResponseFromEvent(event);
if (response && fetchResponseIsStream(response)) {
event.preventDefault();
this.receiveMessageResponse(response);
}
};
receiveMessageEvent = (event) => {
if (this.#started && typeof event.data == "string") {
this.receiveMessageHTML(event.data);
}
};
async receiveMessageResponse(response) {
const html = await response.responseHTML;
if (html) {
this.receiveMessageHTML(html);
}
}
receiveMessageHTML(html) {
this.delegate.receivedMessageFromStream(StreamMessage.wrap(html));
}
};
function fetchResponseFromEvent(event) {
const fetchResponse = event.detail?.fetchResponse;
if (fetchResponse instanceof FetchResponse) {
return fetchResponse;
}
}
function fetchResponseIsStream(response) {
const contentType = response.contentType ?? "";
return contentType.startsWith(StreamMessage.contentType);
}
var ErrorRenderer = class extends Renderer {
static renderElement(currentElement, newElement) {
const { documentElement, body } = document;
documentElement.replaceChild(newElement, body);
}
async render() {
this.replaceHeadAndBody();
this.activateScriptElements();
}
replaceHeadAndBody() {
const { documentElement, head } = document;
documentElement.replaceChild(this.newHead, head);
this.renderElement(this.currentElement, this.newElement);
}
activateScriptElements() {
for (const replaceableElement of this.scriptElements) {
const parentNode = replaceableElement.parentNode;
if (parentNode) {
const element = activateScriptElement(replaceableElement);
parentNode.replaceChild(element, replaceableElement);
}
}
}
get newHead() {
return this.newSnapshot.headSnapshot.element;
}
get scriptElements() {
return document.documentElement.querySelectorAll("script");
}
};
var Idiomorph = /* @__PURE__ */ function() {
let EMPTY_SET = /* @__PURE__ */ new Set();
let defaults = {
morphStyle: "outerHTML",
callbacks: {
beforeNodeAdded: noOp,
afterNodeAdded: noOp,
beforeNodeMorphed: noOp,
afterNodeMorphed: noOp,
beforeNodeRemoved: noOp,
afterNodeRemoved: noOp,
beforeAttributeUpdated: noOp
},
head: {
style: "merge",
shouldPreserve: function(elt) {
return elt.getAttribute("im-preserve") === "true";
},
shouldReAppend: function(elt) {
return elt.getAttribute("im-re-append") === "true";
},
shouldRemove: noOp,
afterHeadMorphed: noOp
}
};
function morph(oldNode, newContent, config = {}) {
if (oldNode instanceof Document) {
oldNode = oldNode.documentElement;
}
if (typeof newContent === "string") {
newContent = parseContent(newContent);
}
let normalizedContent = normalizeContent(newContent);
let ctx = createMorphContext(oldNode, normalizedContent, config);
return morphNormalizedContent(oldNode, normalizedContent, ctx);
}
function morphNormalizedContent(oldNode, normalizedNewContent, ctx) {
if (ctx.head.block) {
let oldHead = oldNode.querySelector("head");
let newHead = normalizedNewContent.querySelector("head");
if (oldHead && newHead) {
let promises = handleHeadElement(newHead, oldHead, ctx);
Promise.all(promises).then(function() {
morphNormalizedContent(oldNode, normalizedNewContent, Object.assign(ctx, {
head: {
block: false,
ignore: true
}
}));
});
return;
}
}
if (ctx.morphStyle === "innerHTML") {
morphChildren(normalizedNewContent, oldNode, ctx);
return oldNode.children;
} else if (ctx.morphStyle === "outerHTML" || ctx.morphStyle == null) {
let bestMatch = findBestNodeMatch(normalizedNewContent, oldNode, ctx);
let previousSibling = bestMatch?.previousSibling;
let nextSibling = bestMatch?.nextSibling;
let morphedNode = morphOldNodeTo(oldNode, bestMatch, ctx);
if (bestMatch) {
return insertSiblings(previousSibling, morphedNode, nextSibling);
} else {
return [];
}
} else {
throw "Do not understand how to morph style " + ctx.morphStyle;
}
}
function ignoreValueOfActiveElement(possibleActiveElement, ctx) {
return ctx.ignoreActiveValue && possibleActiveElement === document.activeElement && possibleActiveElement !== document.body;
}
function morphOldNodeTo(oldNode, newContent, ctx) {
if (ctx.ignoreActive && oldNode === document.activeElement)
;
else if (newContent == null) {
if (ctx.callbacks.beforeNodeRemoved(oldNode) === false)
return oldNode;
oldNode.remove();
ctx.callbacks.afterNodeRemoved(oldNode);
return null;
} else if (!isSoftMatch(oldNode, newContent)) {
if (ctx.callbacks.beforeNodeRemoved(oldNode) === false)
return oldNode;
if (ctx.callbacks.beforeNodeAdded(newContent) === false)
return oldNode;
oldNode.parentElement.replaceChild(newContent, oldNode);
ctx.callbacks.afterNodeAdded(newContent);
ctx.callbacks.afterNodeRemoved(oldNode);
return newContent;
} else {
if (ctx.callbacks.beforeNodeMorphed(oldNode, newContent) === false)
return oldNode;
if (oldNode instanceof HTMLHeadElement && ctx.head.ignore)
;
else if (oldNode instanceof HTMLHeadElement && ctx.head.style !== "morph") {
handleHeadElement(newContent, oldNode, ctx);
} else {
syncNodeFrom(newContent, oldNode, ctx);
if (!ignoreValueOfActiveElement(oldNode, ctx)) {
morphChildren(newContent, oldNode, ctx);
}
}
ctx.callbacks.afterNodeMorphed(oldNode, newContent);
return oldNode;
}
}
function morphChildren(newParent, oldParent, ctx) {
let nextNewChild = newParent.firstChild;
let insertionPoint = oldParent.firstChild;
let newChild;
while (nextNewChild) {
newChild = nextNewChild;
nextNewChild = newChild.nextSibling;
if (insertionPoint == null) {
if (ctx.callbacks.beforeNodeAdded(newChild) === false)
return;
oldParent.appendChild(newChild);
ctx.callbacks.afterNodeAdded(newChild);
removeIdsFromConsideration(ctx, newChild);
continue;
}
if (isIdSetMatch(newChild, insertionPoint, ctx)) {
morphOldNodeTo(insertionPoint, newChild, ctx);
insertionPoint = insertionPoint.nextSibling;
removeIdsFromConsideration(ctx, newChild);
continue;
}
let idSetMatch = findIdSetMatch(newParent, oldParent, newChild, insertionPoint, ctx);
if (idSetMatch) {
insertionPoint = removeNodesBetween(insertionPoint, idSetMatch, ctx);
morphOldNodeTo(idSetMatch, newChild, ctx);
removeIdsFromConsideration(ctx, newChild);
continue;
}
let softMatch = findSoftMatch(newParent, oldParent, newChild, insertionPoint, ctx);
if (softMatch) {
insertionPoint = removeNodesBetween(insertionPoint, softMatch, ctx);
morphOldNodeTo(softMatch, newChild, ctx);
removeIdsFromConsideration(ctx, newChild);
continue;
}
if (ctx.callbacks.beforeNodeAdded(newChild) === false)
return;
oldParent.insertBefore(newChild, insertionPoint);
ctx.callbacks.afterNodeAdded(newChild);
removeIdsFromConsideration(ctx, newChild);
}
while (insertionPoint !== null) {
let tempNode = insertionPoint;
insertionPoint = insertionPoint.nextSibling;
removeNode(tempNode, ctx);
}
}
function ignoreAttribute(attr, to, updateType, ctx) {
if (attr === "value" && ctx.ignoreActiveValue && to === document.activeElement) {
return true;
}
return ctx.callbacks.beforeAttributeUpdated(attr, to, updateType) === false;
}
function syncNodeFrom(from, to, ctx) {
let type = from.nodeType;
if (type === 1) {
const fromAttributes = from.attributes;
const toAttributes = to.attributes;
for (const fromAttribute of fromAttributes) {
if (ignoreAttribute(fromAttribute.name, to, "update", ctx)) {
continue;
}
if (to.getAttribute(fromAttribute.name) !== fromAttribute.value) {
to.setAttribute(fromAttribute.name, fromAttribute.value);
}
}
for (let i = toAttributes.length - 1; 0 <= i; i--) {
const toAttribute = toAttributes[i];
if (ignoreAttribute(toAttribute.name, to, "remove", ctx)) {
continue;
}
if (!from.hasAttribute(toAttribute.name)) {
to.removeAttribute(toAttribute.name);
}
}
}
if (type === 8 || type === 3) {
if (to.nodeValue !== from.nodeValue) {
to.nodeValue = from.nodeValue;
}
}
if (!ignoreValueOfActiveElement(to, ctx)) {
syncInputValue(from, to, ctx);
}
}
function syncBooleanAttribute(from, to, attributeName, ctx) {
if (from[attributeName] !== to[attributeName]) {
let ignoreUpdate = ignoreAttribute(attributeName, to, "update", ctx);
if (!ignoreUpdate) {
to[attributeName] = from[attributeName];
}
if (from[attributeName]) {
if (!ignoreUpdate) {
to.setAttribute(attributeName, from[attributeName]);
}
} else {
if (!ignoreAttribute(attributeName, to, "remove", ctx)) {
to.removeAttribute(attributeName);
}
}
}
}
function syncInputValue(from, to, ctx) {
if (from instanceof HTMLInputElement && to instanceof HTMLInputElement && from.type !== "file") {
let fromValue = from.value;
let toValue = to.value;
syncBooleanAttribute(from, to, "checked", ctx);
syncBooleanAttribute(from, to, "disabled", ctx);
if (!from.hasAttribute("value")) {
if (!ignoreAttribute("value", to, "remove", ctx)) {
to.value = "";
to.removeAttribute("value");
}
} else if (fromValue !== toValue) {
if (!ignoreAttribute("value", to, "update", ctx)) {
to.setAttribute("value", fromValue);
to.value = fromValue;
}
}
} else if (from instanceof HTMLOptionElement) {
syncBooleanAttribute(from, to, "selected", ctx);
} else if (from instanceof HTMLTextAreaElement && to instanceof HTMLTextAreaElement) {
let fromValue = from.value;
let toValue = to.value;
if (ignoreAttribute("value", to, "update", ctx)) {
return;
}
if (fromValue !== toValue) {
to.value = fromValue;
}
if (to.firstChild && to.firstChild.nodeValue !== fromValue) {
to.firstChild.nodeValue = fromValue;
}
}
}
function handleHeadElement(newHeadTag, currentHead, ctx) {
let added = [];
let removed = [];
let preserved = [];
let nodesToAppend = [];
let headMergeStyle = ctx.head.style;
let srcToNewHeadNodes = /* @__PURE__ */ new Map();
for (const newHeadChild of newHeadTag.children) {
srcToNewHeadNodes.set(newHeadChild.outerHTML, newHeadChild);
}
for (const currentHeadElt of currentHead.children) {
let inNewContent = srcToNewHeadNodes.has(currentHeadElt.outerHTML);
let isReAppended = ctx.head.shouldReAppend(currentHeadElt);
let isPreserved = ctx.head.shouldPreserve(currentHeadElt);
if (inNewContent || isPreserved) {
if (isReAppended) {
removed.push(currentHeadElt);
} else {
srcToNewHeadNodes.delete(currentHeadElt.outerHTML);
preserved.push(currentHeadElt);
}
} else {
if (headMergeStyle === "append") {
if (isReAppended) {
removed.push(currentHeadElt);
nodesToAppend.push(currentHeadElt);
}
} else {
if (ctx.head.shouldRemove(currentHeadElt) !== false) {
removed.push(currentHeadElt);
}
}
}
}
nodesToAppend.push(...srcToNewHeadNodes.values());
let promises = [];
for (const newNode of nodesToAppend) {
let newElt = document.createRange().createContextualFragment(newNode.outerHTML).firstChild;
if (ctx.callbacks.beforeNodeAdded(newElt) !== false) {
if (newElt.href || newElt.src) {
let resolve = null;
let promise = new Promise(function(_resolve) {
resolve = _resolve;
});
newElt.addEventListener("load", function() {
resolve();
});
promises.push(promise);
}
currentHead.appendChild(newElt);
ctx.callbacks.afterNodeAdded(newElt);
added.push(newElt);
}
}
for (const removedElement of removed) {
if (ctx.callbacks.beforeNodeRemoved(removedElement) !== false) {
currentHead.removeChild(removedElement);
ctx.callbacks.afterNodeRemoved(removedElement);
}
}
ctx.head.afterHeadMorphed(currentHead, { added, kept: preserved, removed });
return promises;
}
function noOp() {
}
function mergeDefaults(config) {
let finalConfig = {};
Object.assign(finalConfig, defaults);
Object.assign(finalConfig, config);
finalConfig.callbacks = {};
Object.assign(finalConfig.callbacks, defaults.callbacks);
Object.assign(finalConfig.callbacks, config.callbacks);
finalConfig.head = {};
Object.assign(finalConfig.head, defaults.head);
Object.assign(finalConfig.head, config.head);
return finalConfig;
}
function createMorphContext(oldNode, newContent, config) {
config = mergeDefaults(config);
return {
target: oldNode,
newContent,
config,
morphStyle: config.morphStyle,
ignoreActive: config.ignoreActive,
ignoreActiveValue: config.ignoreActiveValue,
idMap: createIdMap(oldNode, newContent),
deadIds: /* @__PURE__ */ new Set(),
callbacks: config.callbacks,
head: config.head
};
}
function isIdSetMatch(node1, node2, ctx) {
if (node1 == null || node2 == null) {
return false;
}
if (node1.nodeType === node2.nodeType && node1.tagName === node2.tagName) {
if (node1.id !== "" && node1.id === node2.id) {
return true;
} else {
return getIdIntersectionCount(ctx, node1, node2) > 0;
}
}
return false;
}
function isSoftMatch(node1, node2) {
if (node1 == null || node2 == null) {
return false;
}
return node1.nodeType === node2.nodeType && node1.tagName === node2.tagName;
}
function removeNodesBetween(startInclusive, endExclusive, ctx) {
while (startInclusive !== endExclusive) {
let tempNode = startInclusive;
startInclusive = startInclusive.nextSibling;
removeNode(tempNode, ctx);
}
removeIdsFromConsideration(ctx, endExclusive);
return endExclusive.nextSibling;
}
function findIdSetMatch(newContent, oldParent, newChild, insertionPoint, ctx) {
let newChildPotentialIdCount = getIdIntersectionCount(ctx, newChild, oldParent);
let potentialMatch = null;
if (newChildPotentialIdCount > 0) {
let potentialMatch2 = insertionPoint;
let otherMatchCount = 0;
while (potentialMatch2 != null) {
if (isIdSetMatch(newChild, potentialMatch2, ctx)) {
return potentialMatch2;
}
otherMatchCount += getIdIntersectionCount(ctx, potentialMatch2, newContent);
if (otherMatchCount > newChildPotentialIdCount) {
return null;
}
potentialMatch2 = potentialMatch2.nextSibling;
}
}
return potentialMatch;
}
function findSoftMatch(newContent, oldParent, newChild, insertionPoint, ctx) {
let potentialSoftMatch = insertionPoint;
let nextSibling = newChild.nextSibling;
let siblingSoftMatchCount = 0;
while (potentialSoftMatch != null) {
if (getIdIntersectionCount(ctx, potentialSoftMatch, newContent) > 0) {
return null;
}
if (isSoftMatch(newChild, potentialSoftMatch)) {
return potentialSoftMatch;
}
if (isSoftMatch(nextSibling, potentialSoftMatch)) {
siblingSoftMatchCount++;
nextSibling = nextSibling.nextSibling;
if (siblingSoftMatchCount >= 2) {
return null;
}
}
potentialSoftMatch = potentialSoftMatch.nextSibling;
}
return potentialSoftMatch;
}
function parseContent(newContent) {
let parser = new DOMParser();
let contentWithSvgsRemoved = newContent.replace(/