{
"version": 3,
"sources": ["../../../node_modules/@rails/actioncable/src/adapters.js", "../../../node_modules/@rails/actioncable/src/logger.js", "../../../node_modules/@rails/actioncable/src/connection_monitor.js", "../../../node_modules/@rails/actioncable/src/internal.js", "../../../node_modules/@rails/actioncable/src/connection.js", "../../../node_modules/@rails/actioncable/src/subscription.js", "../../../node_modules/@rails/actioncable/src/subscription_guarantor.js", "../../../node_modules/@rails/actioncable/src/subscriptions.js", "../../../node_modules/@rails/actioncable/src/consumer.js", "../../../node_modules/@rails/actioncable/src/index.js", "../../../node_modules/slim-select/dist/slimselect.js", "../../../node_modules/@hotwired/turbo/dist/turbo.es2017-esm.js", "../../../node_modules/@hotwired/turbo-rails/app/javascript/turbo/cable.js", "../../../node_modules/@hotwired/turbo-rails/app/javascript/turbo/snakeize.js", "../../../node_modules/@hotwired/turbo-rails/app/javascript/turbo/cable_stream_source_element.js", "../../../node_modules/@hotwired/turbo-rails/app/javascript/turbo/fetch_requests.js", "../../../node_modules/@hotwired/turbo-rails/app/javascript/turbo/index.js", "../../../node_modules/@hotwired/stimulus/dist/stimulus.js", "../../javascript/controllers/application.js", "../../javascript/controllers/hello_controller.js", "../../javascript/controllers/slim_controller.js", "../../javascript/controllers/index.js"],
"sourcesContent": ["export default {\n logger: typeof console !== \"undefined\" ? console : undefined,\n WebSocket: typeof WebSocket !== \"undefined\" ? WebSocket : undefined,\n}\n", "import adapters from \"./adapters\"\n\n// The logger is disabled by default. You can enable it with:\n//\n// ActionCable.logger.enabled = true\n//\n// Example:\n//\n// import * as ActionCable from '@rails/actioncable'\n//\n// ActionCable.logger.enabled = true\n// ActionCable.logger.log('Connection Established.')\n//\n\nexport default {\n log(...messages) {\n if (this.enabled) {\n messages.push(Date.now())\n adapters.logger.log(\"[ActionCable]\", ...messages)\n }\n },\n}\n", "import logger from \"./logger\"\n\n// Responsible for ensuring the cable connection is in good health by validating the heartbeat pings sent from the server, and attempting\n// revival reconnections if things go astray. Internal class, not intended for direct user manipulation.\n\nconst now = () => new Date().getTime()\n\nconst secondsSince = time => (now() - time) / 1000\n\nclass ConnectionMonitor {\n constructor(connection) {\n this.visibilityDidChange = this.visibilityDidChange.bind(this)\n this.connection = connection\n this.reconnectAttempts = 0\n }\n\n start() {\n if (!this.isRunning()) {\n this.startedAt = now()\n delete this.stoppedAt\n this.startPolling()\n addEventListener(\"visibilitychange\", this.visibilityDidChange)\n logger.log(`ConnectionMonitor started. stale threshold = ${this.constructor.staleThreshold} s`)\n }\n }\n\n stop() {\n if (this.isRunning()) {\n this.stoppedAt = now()\n this.stopPolling()\n removeEventListener(\"visibilitychange\", this.visibilityDidChange)\n logger.log(\"ConnectionMonitor stopped\")\n }\n }\n\n isRunning() {\n return this.startedAt && !this.stoppedAt\n }\n\n recordMessage() {\n this.pingedAt = now()\n }\n\n recordConnect() {\n this.reconnectAttempts = 0\n delete this.disconnectedAt\n logger.log(\"ConnectionMonitor recorded connect\")\n }\n\n recordDisconnect() {\n this.disconnectedAt = now()\n logger.log(\"ConnectionMonitor recorded disconnect\")\n }\n\n // Private\n\n startPolling() {\n this.stopPolling()\n this.poll()\n }\n\n stopPolling() {\n clearTimeout(this.pollTimeout)\n }\n\n poll() {\n this.pollTimeout = setTimeout(() => {\n this.reconnectIfStale()\n this.poll()\n }\n , this.getPollInterval())\n }\n\n getPollInterval() {\n const { staleThreshold, reconnectionBackoffRate } = this.constructor\n const backoff = Math.pow(1 + reconnectionBackoffRate, Math.min(this.reconnectAttempts, 10))\n const jitterMax = this.reconnectAttempts === 0 ? 1.0 : reconnectionBackoffRate\n const jitter = jitterMax * Math.random()\n return staleThreshold * 1000 * backoff * (1 + jitter)\n }\n\n reconnectIfStale() {\n if (this.connectionIsStale()) {\n logger.log(`ConnectionMonitor detected stale connection. reconnectAttempts = ${this.reconnectAttempts}, time stale = ${secondsSince(this.refreshedAt)} s, stale threshold = ${this.constructor.staleThreshold} s`)\n this.reconnectAttempts++\n if (this.disconnectedRecently()) {\n logger.log(`ConnectionMonitor skipping reopening recent disconnect. time disconnected = ${secondsSince(this.disconnectedAt)} s`)\n } else {\n logger.log(\"ConnectionMonitor reopening\")\n this.connection.reopen()\n }\n }\n }\n\n get refreshedAt() {\n return this.pingedAt ? this.pingedAt : this.startedAt\n }\n\n connectionIsStale() {\n return secondsSince(this.refreshedAt) > this.constructor.staleThreshold\n }\n\n disconnectedRecently() {\n return this.disconnectedAt && (secondsSince(this.disconnectedAt) < this.constructor.staleThreshold)\n }\n\n visibilityDidChange() {\n if (document.visibilityState === \"visible\") {\n setTimeout(() => {\n if (this.connectionIsStale() || !this.connection.isOpen()) {\n logger.log(`ConnectionMonitor reopening stale connection on visibilitychange. visibilityState = ${document.visibilityState}`)\n this.connection.reopen()\n }\n }\n , 200)\n }\n }\n\n}\n\nConnectionMonitor.staleThreshold = 6 // Server::Connections::BEAT_INTERVAL * 2 (missed two pings)\nConnectionMonitor.reconnectionBackoffRate = 0.15\n\nexport default ConnectionMonitor\n", "export default {\n \"message_types\": {\n \"welcome\": \"welcome\",\n \"disconnect\": \"disconnect\",\n \"ping\": \"ping\",\n \"confirmation\": \"confirm_subscription\",\n \"rejection\": \"reject_subscription\"\n },\n \"disconnect_reasons\": {\n \"unauthorized\": \"unauthorized\",\n \"invalid_request\": \"invalid_request\",\n \"server_restart\": \"server_restart\",\n \"remote\": \"remote\"\n },\n \"default_mount_path\": \"/cable\",\n \"protocols\": [\n \"actioncable-v1-json\",\n \"actioncable-unsupported\"\n ]\n}\n", "import adapters from \"./adapters\"\nimport ConnectionMonitor from \"./connection_monitor\"\nimport INTERNAL from \"./internal\"\nimport logger from \"./logger\"\n\n// Encapsulate the cable connection held by the consumer. This is an internal class not intended for direct user manipulation.\n\nconst {message_types, protocols} = INTERNAL\nconst supportedProtocols = protocols.slice(0, protocols.length - 1)\n\nconst indexOf = [].indexOf\n\nclass Connection {\n constructor(consumer) {\n this.open = this.open.bind(this)\n this.consumer = consumer\n this.subscriptions = this.consumer.subscriptions\n this.monitor = new ConnectionMonitor(this)\n this.disconnected = true\n }\n\n send(data) {\n if (this.isOpen()) {\n this.webSocket.send(JSON.stringify(data))\n return true\n } else {\n return false\n }\n }\n\n open() {\n if (this.isActive()) {\n logger.log(`Attempted to open WebSocket, but existing socket is ${this.getState()}`)\n return false\n } else {\n const socketProtocols = [...protocols, ...this.consumer.subprotocols || []]\n logger.log(`Opening WebSocket, current state is ${this.getState()}, subprotocols: ${socketProtocols}`)\n if (this.webSocket) { this.uninstallEventHandlers() }\n this.webSocket = new adapters.WebSocket(this.consumer.url, socketProtocols)\n this.installEventHandlers()\n this.monitor.start()\n return true\n }\n }\n\n close({allowReconnect} = {allowReconnect: true}) {\n if (!allowReconnect) { this.monitor.stop() }\n // Avoid closing websockets in a \"connecting\" state due to Safari 15.1+ bug. See: https://github.com/rails/rails/issues/43835#issuecomment-1002288478\n if (this.isOpen()) {\n return this.webSocket.close()\n }\n }\n\n reopen() {\n logger.log(`Reopening WebSocket, current state is ${this.getState()}`)\n if (this.isActive()) {\n try {\n return this.close()\n } catch (error) {\n logger.log(\"Failed to reopen WebSocket\", error)\n }\n finally {\n logger.log(`Reopening WebSocket in ${this.constructor.reopenDelay}ms`)\n setTimeout(this.open, this.constructor.reopenDelay)\n }\n } else {\n return this.open()\n }\n }\n\n getProtocol() {\n if (this.webSocket) {\n return this.webSocket.protocol\n }\n }\n\n isOpen() {\n return this.isState(\"open\")\n }\n\n isActive() {\n return this.isState(\"open\", \"connecting\")\n }\n\n triedToReconnect() {\n return this.monitor.reconnectAttempts > 0\n }\n\n // Private\n\n isProtocolSupported() {\n return indexOf.call(supportedProtocols, this.getProtocol()) >= 0\n }\n\n isState(...states) {\n return indexOf.call(states, this.getState()) >= 0\n }\n\n getState() {\n if (this.webSocket) {\n for (let state in adapters.WebSocket) {\n if (adapters.WebSocket[state] === this.webSocket.readyState) {\n return state.toLowerCase()\n }\n }\n }\n return null\n }\n\n installEventHandlers() {\n for (let eventName in this.events) {\n const handler = this.events[eventName].bind(this)\n this.webSocket[`on${eventName}`] = handler\n }\n }\n\n uninstallEventHandlers() {\n for (let eventName in this.events) {\n this.webSocket[`on${eventName}`] = function() {}\n }\n }\n\n}\n\nConnection.reopenDelay = 500\n\nConnection.prototype.events = {\n message(event) {\n if (!this.isProtocolSupported()) { return }\n const {identifier, message, reason, reconnect, type} = JSON.parse(event.data)\n this.monitor.recordMessage()\n switch (type) {\n case message_types.welcome:\n if (this.triedToReconnect()) {\n this.reconnectAttempted = true\n }\n this.monitor.recordConnect()\n return this.subscriptions.reload()\n case message_types.disconnect:\n logger.log(`Disconnecting. Reason: ${reason}`)\n return this.close({allowReconnect: reconnect})\n case message_types.ping:\n return null\n case message_types.confirmation:\n this.subscriptions.confirmSubscription(identifier)\n if (this.reconnectAttempted) {\n this.reconnectAttempted = false\n return this.subscriptions.notify(identifier, \"connected\", {reconnected: true})\n } else {\n return this.subscriptions.notify(identifier, \"connected\", {reconnected: false})\n }\n case message_types.rejection:\n return this.subscriptions.reject(identifier)\n default:\n return this.subscriptions.notify(identifier, \"received\", message)\n }\n },\n\n open() {\n logger.log(`WebSocket onopen event, using '${this.getProtocol()}' subprotocol`)\n this.disconnected = false\n if (!this.isProtocolSupported()) {\n logger.log(\"Protocol is unsupported. Stopping monitor and disconnecting.\")\n return this.close({allowReconnect: false})\n }\n },\n\n close(event) {\n logger.log(\"WebSocket onclose event\")\n if (this.disconnected) { return }\n this.disconnected = true\n this.monitor.recordDisconnect()\n return this.subscriptions.notifyAll(\"disconnected\", {willAttemptReconnect: this.monitor.isRunning()})\n },\n\n error() {\n logger.log(\"WebSocket onerror event\")\n }\n}\n\nexport default Connection\n", "// A new subscription is created through the ActionCable.Subscriptions instance available on the consumer.\n// It provides a number of callbacks and a method for calling remote procedure calls on the corresponding\n// Channel instance on the server side.\n//\n// An example demonstrates the basic functionality:\n//\n// App.appearance = App.cable.subscriptions.create(\"AppearanceChannel\", {\n// connected() {\n// // Called once the subscription has been successfully completed\n// },\n//\n// disconnected({ willAttemptReconnect: boolean }) {\n// // Called when the client has disconnected with the server.\n// // The object will have an `willAttemptReconnect` property which\n// // says whether the client has the intention of attempting\n// // to reconnect.\n// },\n//\n// appear() {\n// this.perform('appear', {appearing_on: this.appearingOn()})\n// },\n//\n// away() {\n// this.perform('away')\n// },\n//\n// appearingOn() {\n// $('main').data('appearing-on')\n// }\n// })\n//\n// The methods #appear and #away forward their intent to the remote AppearanceChannel instance on the server\n// by calling the `perform` method with the first parameter being the action (which maps to AppearanceChannel#appear/away).\n// The second parameter is a hash that'll get JSON encoded and made available on the server in the data parameter.\n//\n// This is how the server component would look:\n//\n// class AppearanceChannel < ApplicationActionCable::Channel\n// def subscribed\n// current_user.appear\n// end\n//\n// def unsubscribed\n// current_user.disappear\n// end\n//\n// def appear(data)\n// current_user.appear on: data['appearing_on']\n// end\n//\n// def away\n// current_user.away\n// end\n// end\n//\n// The \"AppearanceChannel\" name is automatically mapped between the client-side subscription creation and the server-side Ruby class name.\n// The AppearanceChannel#appear/away public methods are exposed automatically to client-side invocation through the perform method.\n\nconst extend = function(object, properties) {\n if (properties != null) {\n for (let key in properties) {\n const value = properties[key]\n object[key] = value\n }\n }\n return object\n}\n\nexport default class Subscription {\n constructor(consumer, params = {}, mixin) {\n this.consumer = consumer\n this.identifier = JSON.stringify(params)\n extend(this, mixin)\n }\n\n // Perform a channel action with the optional data passed as an attribute\n perform(action, data = {}) {\n data.action = action\n return this.send(data)\n }\n\n send(data) {\n return this.consumer.send({command: \"message\", identifier: this.identifier, data: JSON.stringify(data)})\n }\n\n unsubscribe() {\n return this.consumer.subscriptions.remove(this)\n }\n}\n", "import logger from \"./logger\"\n\n// Responsible for ensuring channel subscribe command is confirmed, retrying until confirmation is received.\n// Internal class, not intended for direct user manipulation.\n\nclass SubscriptionGuarantor {\n constructor(subscriptions) {\n this.subscriptions = subscriptions\n this.pendingSubscriptions = []\n }\n\n guarantee(subscription) {\n if(this.pendingSubscriptions.indexOf(subscription) == -1){ \n logger.log(`SubscriptionGuarantor guaranteeing ${subscription.identifier}`)\n this.pendingSubscriptions.push(subscription) \n }\n else {\n logger.log(`SubscriptionGuarantor already guaranteeing ${subscription.identifier}`)\n }\n this.startGuaranteeing()\n }\n\n forget(subscription) {\n logger.log(`SubscriptionGuarantor forgetting ${subscription.identifier}`)\n this.pendingSubscriptions = (this.pendingSubscriptions.filter((s) => s !== subscription))\n }\n\n startGuaranteeing() {\n this.stopGuaranteeing()\n this.retrySubscribing()\n }\n \n stopGuaranteeing() {\n clearTimeout(this.retryTimeout)\n }\n\n retrySubscribing() {\n this.retryTimeout = setTimeout(() => {\n if (this.subscriptions && typeof(this.subscriptions.subscribe) === \"function\") {\n this.pendingSubscriptions.map((subscription) => {\n logger.log(`SubscriptionGuarantor resubscribing ${subscription.identifier}`)\n this.subscriptions.subscribe(subscription)\n })\n }\n }\n , 500)\n }\n}\n\nexport default SubscriptionGuarantor", "import Subscription from \"./subscription\"\nimport SubscriptionGuarantor from \"./subscription_guarantor\"\nimport logger from \"./logger\"\n\n// Collection class for creating (and internally managing) channel subscriptions.\n// The only method intended to be triggered by the user is ActionCable.Subscriptions#create,\n// and it should be called through the consumer like so:\n//\n// App = {}\n// App.cable = ActionCable.createConsumer(\"ws://example.com/accounts/1\")\n// App.appearance = App.cable.subscriptions.create(\"AppearanceChannel\")\n//\n// For more details on how you'd configure an actual channel subscription, see ActionCable.Subscription.\n\nexport default class Subscriptions {\n constructor(consumer) {\n this.consumer = consumer\n this.guarantor = new SubscriptionGuarantor(this)\n this.subscriptions = []\n }\n\n create(channelName, mixin) {\n const channel = channelName\n const params = typeof channel === \"object\" ? channel : {channel}\n const subscription = new Subscription(this.consumer, params, mixin)\n return this.add(subscription)\n }\n\n // Private\n\n add(subscription) {\n this.subscriptions.push(subscription)\n this.consumer.ensureActiveConnection()\n this.notify(subscription, \"initialized\")\n this.subscribe(subscription)\n return subscription\n }\n\n remove(subscription) {\n this.forget(subscription)\n if (!this.findAll(subscription.identifier).length) {\n this.sendCommand(subscription, \"unsubscribe\")\n }\n return subscription\n }\n\n reject(identifier) {\n return this.findAll(identifier).map((subscription) => {\n this.forget(subscription)\n this.notify(subscription, \"rejected\")\n return subscription\n })\n }\n\n forget(subscription) {\n this.guarantor.forget(subscription)\n this.subscriptions = (this.subscriptions.filter((s) => s !== subscription))\n return subscription\n }\n\n findAll(identifier) {\n return this.subscriptions.filter((s) => s.identifier === identifier)\n }\n\n reload() {\n return this.subscriptions.map((subscription) =>\n this.subscribe(subscription))\n }\n\n notifyAll(callbackName, ...args) {\n return this.subscriptions.map((subscription) =>\n this.notify(subscription, callbackName, ...args))\n }\n\n notify(subscription, callbackName, ...args) {\n let subscriptions\n if (typeof subscription === \"string\") {\n subscriptions = this.findAll(subscription)\n } else {\n subscriptions = [subscription]\n }\n\n return subscriptions.map((subscription) =>\n (typeof subscription[callbackName] === \"function\" ? subscription[callbackName](...args) : undefined))\n }\n\n subscribe(subscription) {\n if (this.sendCommand(subscription, \"subscribe\")) {\n this.guarantor.guarantee(subscription)\n }\n }\n\n confirmSubscription(identifier) {\n logger.log(`Subscription confirmed ${identifier}`)\n this.findAll(identifier).map((subscription) =>\n this.guarantor.forget(subscription))\n }\n\n sendCommand(subscription, command) {\n const {identifier} = subscription\n return this.consumer.send({command, identifier})\n }\n}\n", "import Connection from \"./connection\"\nimport Subscriptions from \"./subscriptions\"\n\n// The ActionCable.Consumer establishes the connection to a server-side Ruby Connection object. Once established,\n// the ActionCable.ConnectionMonitor will ensure that its properly maintained through heartbeats and checking for stale updates.\n// The Consumer instance is also the gateway to establishing subscriptions to desired channels through the #createSubscription\n// method.\n//\n// The following example shows how this can be set up:\n//\n// App = {}\n// App.cable = ActionCable.createConsumer(\"ws://example.com/accounts/1\")\n// App.appearance = App.cable.subscriptions.create(\"AppearanceChannel\")\n//\n// For more details on how you'd configure an actual channel subscription, see ActionCable.Subscription.\n//\n// When a consumer is created, it automatically connects with the server.\n//\n// To disconnect from the server, call\n//\n// App.cable.disconnect()\n//\n// and to restart the connection:\n//\n// App.cable.connect()\n//\n// Any channel subscriptions which existed prior to disconnecting will\n// automatically resubscribe.\n\nexport default class Consumer {\n constructor(url) {\n this._url = url\n this.subscriptions = new Subscriptions(this)\n this.connection = new Connection(this)\n this.subprotocols = []\n }\n\n get url() {\n return createWebSocketURL(this._url)\n }\n\n send(data) {\n return this.connection.send(data)\n }\n\n connect() {\n return this.connection.open()\n }\n\n disconnect() {\n return this.connection.close({allowReconnect: false})\n }\n\n ensureActiveConnection() {\n if (!this.connection.isActive()) {\n return this.connection.open()\n }\n }\n\n addSubProtocol(subprotocol) {\n this.subprotocols = [...this.subprotocols, subprotocol]\n }\n}\n\nexport function createWebSocketURL(url) {\n if (typeof url === \"function\") {\n url = url()\n }\n\n if (url && !/^wss?:/i.test(url)) {\n const a = document.createElement(\"a\")\n a.href = url\n // Fix populating Location properties in IE. Otherwise, protocol will be blank.\n a.href = a.href\n a.protocol = a.protocol.replace(\"http\", \"ws\")\n return a.href\n } else {\n return url\n }\n}\n", "import Connection from \"./connection\"\nimport ConnectionMonitor from \"./connection_monitor\"\nimport Consumer, { createWebSocketURL } from \"./consumer\"\nimport INTERNAL from \"./internal\"\nimport Subscription from \"./subscription\"\nimport Subscriptions from \"./subscriptions\"\nimport SubscriptionGuarantor from \"./subscription_guarantor\"\nimport adapters from \"./adapters\"\nimport logger from \"./logger\"\n\nexport {\n Connection,\n ConnectionMonitor,\n Consumer,\n INTERNAL,\n Subscription,\n Subscriptions,\n SubscriptionGuarantor,\n adapters,\n createWebSocketURL,\n logger,\n}\n\nexport function createConsumer(url = getConfig(\"url\") || INTERNAL.default_mount_path) {\n return new Consumer(url)\n}\n\nexport function getConfig(name) {\n const element = document.head.querySelector(`meta[name='action-cable-${name}']`)\n if (element) {\n return element.getAttribute(\"content\")\n }\n}\n", "(function (global, factory) {\n typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :\n typeof define === 'function' && define.amd ? define(factory) :\n (global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.SlimSelect = factory());\n})(this, (function () { 'use strict';\n\n class CssClasses {\n constructor(classes) {\n if (!classes) {\n classes = {};\n }\n this.main = classes.main || 'ss-main';\n this.placeholder = classes.placeholder || 'ss-placeholder';\n this.values = classes.values || 'ss-values';\n this.single = classes.single || 'ss-single';\n this.max = classes.max || 'ss-max';\n this.value = classes.value || 'ss-value';\n this.valueText = classes.valueText || 'ss-value-text';\n this.valueDelete = classes.valueDelete || 'ss-value-delete';\n this.valueOut = classes.valueOut || 'ss-value-out';\n this.deselect = classes.deselect || 'ss-deselect';\n this.deselectPath = classes.deselectPath || 'M10,10 L90,90 M10,90 L90,10';\n this.arrow = classes.arrow || 'ss-arrow';\n this.arrowClose = classes.arrowClose || 'M10,30 L50,70 L90,30';\n this.arrowOpen = classes.arrowOpen || 'M10,70 L50,30 L90,70';\n this.content = classes.content || 'ss-content';\n this.openAbove = classes.openAbove || 'ss-open-above';\n this.openBelow = classes.openBelow || 'ss-open-below';\n this.search = classes.search || 'ss-search';\n this.searchHighlighter = classes.searchHighlighter || 'ss-search-highlight';\n this.searching = classes.searching || 'ss-searching';\n this.addable = classes.addable || 'ss-addable';\n this.addablePath = classes.addablePath || 'M50,10 L50,90 M10,50 L90,50';\n this.list = classes.list || 'ss-list';\n this.optgroup = classes.optgroup || 'ss-optgroup';\n this.optgroupLabel = classes.optgroupLabel || 'ss-optgroup-label';\n this.optgroupLabelText = classes.optgroupLabelText || 'ss-optgroup-label-text';\n this.optgroupActions = classes.optgroupActions || 'ss-optgroup-actions';\n this.optgroupSelectAll = classes.optgroupSelectAll || 'ss-selectall';\n this.optgroupSelectAllBox = classes.optgroupSelectAllBox || 'M60,10 L10,10 L10,90 L90,90 L90,50';\n this.optgroupSelectAllCheck = classes.optgroupSelectAllCheck || 'M30,45 L50,70 L90,10';\n this.optgroupClosable = classes.optgroupClosable || 'ss-closable';\n this.option = classes.option || 'ss-option';\n this.optionDelete = classes.optionDelete || 'M10,10 L90,90 M10,90 L90,10';\n this.highlighted = classes.highlighted || 'ss-highlighted';\n this.open = classes.open || 'ss-open';\n this.close = classes.close || 'ss-close';\n this.selected = classes.selected || 'ss-selected';\n this.error = classes.error || 'ss-error';\n this.disabled = classes.disabled || 'ss-disabled';\n this.hide = classes.hide || 'ss-hide';\n }\n }\n\n function generateID() {\n return Math.random().toString(36).substring(2, 10);\n }\n function hasClassInTree(element, className) {\n function hasClass(e, c) {\n if (c && e && e.classList && e.classList.contains(c)) {\n return e;\n }\n if (c && e && e.dataset && e.dataset.id && e.dataset.id === className) {\n return e;\n }\n return null;\n }\n function parentByClass(e, c) {\n if (!e || e === document) {\n return null;\n }\n else if (hasClass(e, c)) {\n return e;\n }\n else {\n return parentByClass(e.parentNode, c);\n }\n }\n return hasClass(element, className) || parentByClass(element, className);\n }\n function debounce(func, wait = 50, immediate = false) {\n let timeout;\n return function (...args) {\n const context = self;\n const later = () => {\n timeout = null;\n if (!immediate) {\n func.apply(context, args);\n }\n };\n const callNow = immediate && !timeout;\n clearTimeout(timeout);\n timeout = setTimeout(later, wait);\n if (callNow) {\n func.apply(context, args);\n }\n };\n }\n function isEqual(a, b) {\n return JSON.stringify(a) === JSON.stringify(b);\n }\n function kebabCase(str) {\n const result = str.replace(/[A-Z\\u00C0-\\u00D6\\u00D8-\\u00DE]/g, (match) => '-' + match.toLowerCase());\n return str[0] === str[0].toUpperCase() ? result.substring(1) : result;\n }\n\n class Optgroup {\n constructor(optgroup) {\n this.id = !optgroup.id || optgroup.id === '' ? generateID() : optgroup.id;\n this.label = optgroup.label || '';\n this.selectAll = optgroup.selectAll === undefined ? false : optgroup.selectAll;\n this.selectAllText = optgroup.selectAllText || 'Select All';\n this.closable = optgroup.closable || 'off';\n this.options = [];\n if (optgroup.options) {\n for (const o of optgroup.options) {\n this.options.push(new Option(o));\n }\n }\n }\n }\n class Option {\n constructor(option) {\n this.id = !option.id || option.id === '' ? generateID() : option.id;\n this.value = option.value === undefined ? option.text : option.value;\n this.text = option.text || '';\n this.html = option.html || '';\n this.selected = option.selected !== undefined ? option.selected : false;\n this.display = option.display !== undefined ? option.display : true;\n this.disabled = option.disabled !== undefined ? option.disabled : false;\n this.mandatory = option.mandatory !== undefined ? option.mandatory : false;\n this.placeholder = option.placeholder !== undefined ? option.placeholder : false;\n this.class = option.class || '';\n this.style = option.style || '';\n this.data = option.data || {};\n }\n }\n class Store {\n constructor(type, data) {\n this.selectType = 'single';\n this.data = [];\n this.selectedOrder = [];\n this.selectType = type;\n this.setData(data);\n }\n validateDataArray(data) {\n if (!Array.isArray(data)) {\n return new Error('Data must be an array');\n }\n for (let dataObj of data) {\n if (dataObj instanceof Optgroup || 'label' in dataObj) {\n if (!('label' in dataObj)) {\n return new Error('Optgroup must have a label');\n }\n if ('options' in dataObj && dataObj.options) {\n for (let option of dataObj.options) {\n const validationError = this.validateOption(option);\n if (validationError) {\n return validationError;\n }\n }\n }\n }\n else if (dataObj instanceof Option || 'text' in dataObj) {\n const validationError = this.validateOption(dataObj);\n if (validationError) {\n return validationError;\n }\n }\n else {\n return new Error('Data object must be a valid optgroup or option');\n }\n }\n return null;\n }\n validateOption(option) {\n if (!('text' in option)) {\n return new Error('Option must have a text');\n }\n return null;\n }\n partialToFullData(data) {\n let dataFinal = [];\n data.forEach((dataObj) => {\n if (dataObj instanceof Optgroup || 'label' in dataObj) {\n let optOptions = [];\n if ('options' in dataObj && dataObj.options) {\n dataObj.options.forEach((option) => {\n optOptions.push(new Option(option));\n });\n }\n if (optOptions.length > 0) {\n dataFinal.push(new Optgroup(dataObj));\n }\n }\n if (dataObj instanceof Option || 'text' in dataObj) {\n dataFinal.push(new Option(dataObj));\n }\n });\n return dataFinal;\n }\n setData(data) {\n this.data = this.partialToFullData(data);\n if (this.selectType === 'single') {\n this.setSelectedBy('id', this.getSelected());\n }\n }\n getData() {\n return this.filter(null, true);\n }\n getDataOptions() {\n return this.filter(null, false);\n }\n addOption(option, addToStart = false) {\n if (addToStart) {\n let data = [new Option(option)];\n this.setData(data.concat(this.getData()));\n }\n else {\n this.setData(this.getData().concat(new Option(option)));\n }\n }\n setSelectedBy(selectedType, selectedValues) {\n let firstOption = null;\n let hasSelected = false;\n const selectedObjects = [];\n for (let dataObj of this.data) {\n if (dataObj instanceof Optgroup) {\n for (let option of dataObj.options) {\n if (!firstOption) {\n firstOption = option;\n }\n option.selected = hasSelected ? false : selectedValues.includes(option[selectedType]);\n if (option.selected) {\n selectedObjects.push(option);\n if (this.selectType === 'single') {\n hasSelected = true;\n }\n }\n }\n }\n if (dataObj instanceof Option) {\n if (!firstOption) {\n firstOption = dataObj;\n }\n dataObj.selected = hasSelected ? false : selectedValues.includes(dataObj[selectedType]);\n if (dataObj.selected) {\n selectedObjects.push(dataObj);\n if (this.selectType === 'single') {\n hasSelected = true;\n }\n }\n }\n }\n if (this.selectType === 'single' && firstOption && !hasSelected) {\n firstOption.selected = true;\n selectedObjects.push(firstOption);\n }\n const selectedIds = selectedValues.map((value) => {\n var _a;\n return ((_a = selectedObjects.find((option) => option[selectedType] === value)) === null || _a === void 0 ? void 0 : _a.id) || '';\n });\n this.selectedOrder = selectedIds;\n }\n getSelected() {\n return this.getSelectedOptions().map((option) => option.id);\n }\n getSelectedValues() {\n return this.getSelectedOptions().map((option) => option.value);\n }\n getSelectedOptions() {\n return this.filter((opt) => {\n return opt.selected;\n }, false);\n }\n getOptgroupByID(id) {\n for (let dataObj of this.data) {\n if (dataObj instanceof Optgroup && dataObj.id === id) {\n return dataObj;\n }\n }\n return null;\n }\n getOptionByID(id) {\n let options = this.filter((opt) => {\n return opt.id === id;\n }, false);\n return options.length ? options[0] : null;\n }\n getSelectType() {\n return this.selectType;\n }\n getFirstOption() {\n let option = null;\n for (let dataObj of this.data) {\n if (dataObj instanceof Optgroup) {\n option = dataObj.options[0];\n }\n else if (dataObj instanceof Option) {\n option = dataObj;\n }\n if (option) {\n break;\n }\n }\n return option;\n }\n search(search, searchFilter) {\n search = search.trim();\n if (search === '') {\n return this.getData();\n }\n return this.filter((opt) => {\n return searchFilter(opt, search);\n }, true);\n }\n filter(filter, includeOptgroup) {\n const dataSearch = [];\n this.data.forEach((dataObj) => {\n if (dataObj instanceof Optgroup) {\n let optOptions = [];\n dataObj.options.forEach((option) => {\n if (!filter || filter(option)) {\n if (!includeOptgroup) {\n dataSearch.push(new Option(option));\n }\n else {\n optOptions.push(new Option(option));\n }\n }\n });\n if (optOptions.length > 0) {\n let optgroup = new Optgroup(dataObj);\n optgroup.options = optOptions;\n dataSearch.push(optgroup);\n }\n }\n if (dataObj instanceof Option) {\n if (!filter || filter(dataObj)) {\n dataSearch.push(new Option(dataObj));\n }\n }\n });\n return dataSearch;\n }\n selectedOrderOptions(options) {\n const newOrder = [];\n this.selectedOrder.forEach((id) => {\n const option = options.find((opt) => opt.id === id);\n if (option) {\n newOrder.push(option);\n }\n });\n options.forEach((option) => {\n let isIn = false;\n newOrder.forEach((selectedOption) => {\n if (option.id === selectedOption.id) {\n isIn = true;\n return;\n }\n });\n if (!isIn) {\n newOrder.push(option);\n }\n });\n return newOrder;\n }\n }\n\n class Render {\n constructor(settings, classes, store, callbacks) {\n this.store = store;\n this.settings = settings;\n this.classes = classes;\n this.callbacks = callbacks;\n this.main = this.mainDiv();\n this.content = this.contentDiv();\n this.updateClassStyles();\n this.updateAriaAttributes();\n if (this.settings.contentLocation) {\n this.settings.contentLocation.appendChild(this.content.main);\n }\n }\n enable() {\n this.main.main.classList.remove(this.classes.disabled);\n this.content.search.input.disabled = false;\n }\n disable() {\n this.main.main.classList.add(this.classes.disabled);\n this.content.search.input.disabled = true;\n }\n open() {\n this.main.arrow.path.setAttribute('d', this.classes.arrowOpen);\n this.main.main.classList.add(this.settings.openPosition === 'up' ? this.classes.openAbove : this.classes.openBelow);\n this.main.main.setAttribute('aria-expanded', 'true');\n this.moveContent();\n const selectedOptions = this.store.getSelectedOptions();\n if (selectedOptions.length) {\n const selectedId = selectedOptions[selectedOptions.length - 1].id;\n const selectedOption = this.content.list.querySelector('[data-id=\"' + selectedId + '\"]');\n if (selectedOption) {\n this.ensureElementInView(this.content.list, selectedOption);\n }\n }\n }\n close() {\n this.main.main.classList.remove(this.classes.openAbove);\n this.main.main.classList.remove(this.classes.openBelow);\n this.main.main.setAttribute('aria-expanded', 'false');\n this.content.main.classList.remove(this.classes.openAbove);\n this.content.main.classList.remove(this.classes.openBelow);\n this.main.arrow.path.setAttribute('d', this.classes.arrowClose);\n }\n updateClassStyles() {\n this.main.main.className = '';\n this.main.main.removeAttribute('style');\n this.content.main.className = '';\n this.content.main.removeAttribute('style');\n this.main.main.classList.add(this.classes.main);\n this.content.main.classList.add(this.classes.content);\n if (this.settings.style !== '') {\n this.main.main.style.cssText = this.settings.style;\n this.content.main.style.cssText = this.settings.style;\n }\n if (this.settings.class.length) {\n for (const c of this.settings.class) {\n if (c.trim() !== '') {\n this.main.main.classList.add(c.trim());\n this.content.main.classList.add(c.trim());\n }\n }\n }\n if (this.settings.contentPosition === 'relative' || this.settings.contentPosition === 'fixed') {\n this.content.main.classList.add('ss-' + this.settings.contentPosition);\n }\n }\n updateAriaAttributes() {\n this.main.main.role = 'combobox';\n this.main.main.setAttribute('aria-haspopup', 'listbox');\n this.main.main.setAttribute('aria-controls', this.content.main.id);\n this.main.main.setAttribute('aria-expanded', 'false');\n this.content.main.setAttribute('role', 'listbox');\n }\n mainDiv() {\n var _a;\n const main = document.createElement('div');\n main.dataset.id = this.settings.id;\n main.setAttribute('aria-label', this.settings.ariaLabel);\n main.tabIndex = 0;\n main.onkeydown = (e) => {\n switch (e.key) {\n case 'ArrowUp':\n case 'ArrowDown':\n this.callbacks.open();\n e.key === 'ArrowDown' ? this.highlight('down') : this.highlight('up');\n return false;\n case 'Tab':\n this.callbacks.close();\n return true;\n case 'Enter':\n case ' ':\n this.callbacks.open();\n const highlighted = this.content.list.querySelector('.' + this.classes.highlighted);\n if (highlighted) {\n highlighted.click();\n }\n return false;\n case 'Escape':\n this.callbacks.close();\n return false;\n }\n if (e.key.length === 1) {\n this.callbacks.open();\n }\n return true;\n };\n main.onclick = (e) => {\n if (this.settings.disabled) {\n return;\n }\n this.settings.isOpen ? this.callbacks.close() : this.callbacks.open();\n };\n const values = document.createElement('div');\n values.classList.add(this.classes.values);\n main.appendChild(values);\n const deselect = document.createElement('div');\n deselect.classList.add(this.classes.deselect);\n const selectedOptions = (_a = this.store) === null || _a === void 0 ? void 0 : _a.getSelectedOptions();\n if (!this.settings.allowDeselect || (this.settings.isMultiple && selectedOptions && selectedOptions.length <= 0)) {\n deselect.classList.add(this.classes.hide);\n }\n else {\n deselect.classList.remove(this.classes.hide);\n }\n deselect.onclick = (e) => {\n e.stopPropagation();\n if (this.settings.disabled) {\n return;\n }\n let shouldDelete = true;\n const before = this.store.getSelectedOptions();\n const after = [];\n if (this.callbacks.beforeChange) {\n shouldDelete = this.callbacks.beforeChange(after, before) === true;\n }\n if (shouldDelete) {\n if (this.settings.isMultiple) {\n this.callbacks.setSelected([], false);\n this.updateDeselectAll();\n }\n else {\n const firstOption = this.store.getFirstOption();\n const id = firstOption ? firstOption.id : '';\n this.callbacks.setSelected(id, false);\n }\n if (this.settings.closeOnSelect) {\n this.callbacks.close();\n }\n if (this.callbacks.afterChange) {\n this.callbacks.afterChange(this.store.getSelectedOptions());\n }\n }\n };\n const deselectSvg = document.createElementNS('http://www.w3.org/2000/svg', 'svg');\n deselectSvg.setAttribute('viewBox', '0 0 100 100');\n const deselectPath = document.createElementNS('http://www.w3.org/2000/svg', 'path');\n deselectPath.setAttribute('d', this.classes.deselectPath);\n deselectSvg.appendChild(deselectPath);\n deselect.appendChild(deselectSvg);\n main.appendChild(deselect);\n const arrow = document.createElementNS('http://www.w3.org/2000/svg', 'svg');\n arrow.classList.add(this.classes.arrow);\n arrow.setAttribute('viewBox', '0 0 100 100');\n const arrowPath = document.createElementNS('http://www.w3.org/2000/svg', 'path');\n arrowPath.setAttribute('d', this.classes.arrowClose);\n if (this.settings.alwaysOpen) {\n arrow.classList.add(this.classes.hide);\n }\n arrow.appendChild(arrowPath);\n main.appendChild(arrow);\n return {\n main: main,\n values: values,\n deselect: {\n main: deselect,\n svg: deselectSvg,\n path: deselectPath\n },\n arrow: {\n main: arrow,\n path: arrowPath\n }\n };\n }\n mainFocus(eventType) {\n if (eventType !== 'click') {\n this.main.main.focus({ preventScroll: true });\n }\n }\n placeholder() {\n const placeholderOption = this.store.filter((o) => o.placeholder, false);\n let placeholderText = this.settings.placeholderText;\n if (placeholderOption.length) {\n if (placeholderOption[0].html !== '') {\n placeholderText = placeholderOption[0].html;\n }\n else if (placeholderOption[0].text !== '') {\n placeholderText = placeholderOption[0].text;\n }\n }\n const placeholder = document.createElement('div');\n placeholder.classList.add(this.classes.placeholder);\n placeholder.innerHTML = placeholderText;\n return placeholder;\n }\n renderValues() {\n if (!this.settings.isMultiple) {\n this.renderSingleValue();\n return;\n }\n this.renderMultipleValues();\n this.updateDeselectAll();\n }\n renderSingleValue() {\n const selected = this.store.filter((o) => {\n return o.selected && !o.placeholder;\n }, false);\n const selectedSingle = selected.length > 0 ? selected[0] : null;\n if (!selectedSingle) {\n this.main.values.innerHTML = this.placeholder().outerHTML;\n }\n else {\n const singleValue = document.createElement('div');\n singleValue.classList.add(this.classes.single);\n if (selectedSingle.html) {\n singleValue.innerHTML = selectedSingle.html;\n }\n else {\n singleValue.innerText = selectedSingle.text;\n }\n this.main.values.innerHTML = singleValue.outerHTML;\n }\n if (!this.settings.allowDeselect || !selected.length) {\n this.main.deselect.main.classList.add(this.classes.hide);\n }\n else {\n this.main.deselect.main.classList.remove(this.classes.hide);\n }\n }\n renderMultipleValues() {\n let currentNodes = this.main.values.childNodes;\n let selectedOptions = this.store.filter((opt) => {\n return opt.selected && opt.display;\n }, false);\n if (selectedOptions.length === 0) {\n this.main.values.innerHTML = this.placeholder().outerHTML;\n return;\n }\n else {\n const placeholder = this.main.values.querySelector('.' + this.classes.placeholder);\n if (placeholder) {\n placeholder.remove();\n }\n }\n if (selectedOptions.length > this.settings.maxValuesShown) {\n const singleValue = document.createElement('div');\n singleValue.classList.add(this.classes.max);\n singleValue.textContent = this.settings.maxValuesMessage.replace('{number}', selectedOptions.length.toString());\n this.main.values.innerHTML = singleValue.outerHTML;\n return;\n }\n else {\n const maxValuesMessage = this.main.values.querySelector('.' + this.classes.max);\n if (maxValuesMessage) {\n maxValuesMessage.remove();\n }\n }\n if (this.settings.keepOrder) {\n selectedOptions = this.store.selectedOrderOptions(selectedOptions);\n }\n let removeNodes = [];\n for (let i = 0; i < currentNodes.length; i++) {\n const node = currentNodes[i];\n const id = node.getAttribute('data-id');\n if (id) {\n const found = selectedOptions.filter((opt) => {\n return opt.id === id;\n }, false);\n if (!found.length) {\n removeNodes.push(node);\n }\n }\n }\n for (const n of removeNodes) {\n n.classList.add(this.classes.valueOut);\n setTimeout(() => {\n if (this.main.values.hasChildNodes() && this.main.values.contains(n)) {\n this.main.values.removeChild(n);\n }\n }, 100);\n }\n currentNodes = this.main.values.childNodes;\n for (let d = 0; d < selectedOptions.length; d++) {\n let shouldAdd = true;\n for (let i = 0; i < currentNodes.length; i++) {\n if (selectedOptions[d].id === String(currentNodes[i].dataset.id)) {\n shouldAdd = false;\n }\n }\n if (shouldAdd) {\n if (this.settings.keepOrder) {\n this.main.values.appendChild(this.multipleValue(selectedOptions[d]));\n }\n else {\n if (currentNodes.length === 0) {\n this.main.values.appendChild(this.multipleValue(selectedOptions[d]));\n }\n else if (d === 0) {\n this.main.values.insertBefore(this.multipleValue(selectedOptions[d]), currentNodes[d]);\n }\n else {\n currentNodes[d - 1].insertAdjacentElement('afterend', this.multipleValue(selectedOptions[d]));\n }\n }\n }\n }\n }\n multipleValue(option) {\n const value = document.createElement('div');\n value.classList.add(this.classes.value);\n value.dataset.id = option.id;\n const text = document.createElement('div');\n text.classList.add(this.classes.valueText);\n text.textContent = option.text;\n value.appendChild(text);\n if (!option.mandatory) {\n const deleteDiv = document.createElement('div');\n deleteDiv.classList.add(this.classes.valueDelete);\n deleteDiv.onclick = (e) => {\n e.preventDefault();\n e.stopPropagation();\n if (this.settings.disabled) {\n return;\n }\n let shouldDelete = true;\n const before = this.store.getSelectedOptions();\n const after = before.filter((o) => {\n return o.selected && o.id !== option.id;\n }, true);\n if (this.settings.minSelected && after.length < this.settings.minSelected) {\n return;\n }\n if (this.callbacks.beforeChange) {\n shouldDelete = this.callbacks.beforeChange(after, before) === true;\n }\n if (shouldDelete) {\n let selectedIds = [];\n for (const o of after) {\n if (o instanceof Optgroup) {\n for (const c of o.options) {\n selectedIds.push(c.id);\n }\n }\n if (o instanceof Option) {\n selectedIds.push(o.id);\n }\n }\n this.callbacks.setSelected(selectedIds, false);\n if (this.settings.closeOnSelect) {\n this.callbacks.close();\n }\n if (this.callbacks.afterChange) {\n this.callbacks.afterChange(after);\n }\n this.updateDeselectAll();\n }\n };\n const deleteSvg = document.createElementNS('http://www.w3.org/2000/svg', 'svg');\n deleteSvg.setAttribute('viewBox', '0 0 100 100');\n const deletePath = document.createElementNS('http://www.w3.org/2000/svg', 'path');\n deletePath.setAttribute('d', this.classes.optionDelete);\n deleteSvg.appendChild(deletePath);\n deleteDiv.appendChild(deleteSvg);\n value.appendChild(deleteDiv);\n }\n return value;\n }\n contentDiv() {\n const main = document.createElement('div');\n main.dataset.id = this.settings.id;\n const search = this.searchDiv();\n main.appendChild(search.main);\n const list = this.listDiv();\n main.appendChild(list);\n return {\n main: main,\n search: search,\n list: list\n };\n }\n moveContent() {\n if (this.settings.contentPosition === 'relative') {\n this.moveContentBelow();\n return;\n }\n if (this.settings.openPosition === 'down') {\n this.moveContentBelow();\n return;\n }\n else if (this.settings.openPosition === 'up') {\n this.moveContentAbove();\n return;\n }\n if (this.putContent() === 'up') {\n this.moveContentAbove();\n }\n else {\n this.moveContentBelow();\n }\n }\n searchDiv() {\n const main = document.createElement('div');\n const input = document.createElement('input');\n const addable = document.createElement('div');\n main.classList.add(this.classes.search);\n const searchReturn = {\n main,\n input\n };\n if (!this.settings.showSearch) {\n main.classList.add(this.classes.hide);\n input.readOnly = true;\n }\n input.type = 'search';\n input.placeholder = this.settings.searchPlaceholder;\n input.tabIndex = -1;\n input.setAttribute('aria-label', this.settings.searchPlaceholder);\n input.setAttribute('autocapitalize', 'off');\n input.setAttribute('autocomplete', 'off');\n input.setAttribute('autocorrect', 'off');\n input.oninput = debounce((e) => {\n this.callbacks.search(e.target.value);\n }, 100);\n input.onkeydown = (e) => {\n switch (e.key) {\n case 'ArrowUp':\n case 'ArrowDown':\n e.key === 'ArrowDown' ? this.highlight('down') : this.highlight('up');\n return false;\n case 'Tab':\n this.callbacks.close();\n return true;\n case 'Escape':\n this.callbacks.close();\n return false;\n case ' ':\n const highlighted = this.content.list.querySelector('.' + this.classes.highlighted);\n if (highlighted) {\n highlighted.click();\n return false;\n }\n return true;\n case 'Enter':\n if (this.callbacks.addable) {\n addable.click();\n return false;\n }\n else {\n const highlighted = this.content.list.querySelector('.' + this.classes.highlighted);\n if (highlighted) {\n highlighted.click();\n return false;\n }\n }\n return true;\n }\n return true;\n };\n main.appendChild(input);\n if (this.callbacks.addable) {\n addable.classList.add(this.classes.addable);\n const plus = document.createElementNS('http://www.w3.org/2000/svg', 'svg');\n plus.setAttribute('viewBox', '0 0 100 100');\n const plusPath = document.createElementNS('http://www.w3.org/2000/svg', 'path');\n plusPath.setAttribute('d', this.classes.addablePath);\n plus.appendChild(plusPath);\n addable.appendChild(plus);\n addable.onclick = (e) => {\n e.preventDefault();\n e.stopPropagation();\n if (!this.callbacks.addable) {\n return;\n }\n const inputValue = this.content.search.input.value.trim();\n if (inputValue === '') {\n this.content.search.input.focus();\n return;\n }\n const runFinish = (oo) => {\n let newOption = new Option(oo);\n this.callbacks.addOption(newOption);\n if (this.settings.isMultiple) {\n let ids = this.store.getSelected();\n ids.push(newOption.id);\n this.callbacks.setSelected(ids, true);\n }\n else {\n this.callbacks.setSelected([newOption.id], true);\n }\n this.callbacks.search('');\n if (this.settings.closeOnSelect) {\n setTimeout(() => {\n this.callbacks.close();\n }, 100);\n }\n };\n const addableValue = this.callbacks.addable(inputValue);\n if (addableValue === false || addableValue === undefined || addableValue === null) {\n return;\n }\n if (addableValue instanceof Promise) {\n addableValue.then((value) => {\n if (typeof value === 'string') {\n runFinish({\n text: value,\n value: value\n });\n }\n else if (addableValue instanceof Error) {\n this.renderError(addableValue.message);\n }\n else {\n runFinish(value);\n }\n });\n }\n else if (typeof addableValue === 'string') {\n runFinish({\n text: addableValue,\n value: addableValue\n });\n }\n else if (addableValue instanceof Error) {\n this.renderError(addableValue.message);\n }\n else {\n runFinish(addableValue);\n }\n return;\n };\n main.appendChild(addable);\n searchReturn.addable = {\n main: addable,\n svg: plus,\n path: plusPath\n };\n }\n return searchReturn;\n }\n searchFocus() {\n this.content.search.input.focus();\n }\n getOptions(notPlaceholder = false, notDisabled = false, notHidden = false) {\n let query = '.' + this.classes.option;\n if (notPlaceholder) {\n query += ':not(.' + this.classes.placeholder + ')';\n }\n if (notDisabled) {\n query += ':not(.' + this.classes.disabled + ')';\n }\n if (notHidden) {\n query += ':not(.' + this.classes.hide + ')';\n }\n return Array.from(this.content.list.querySelectorAll(query));\n }\n highlight(dir) {\n const options = this.getOptions(true, true, true);\n if (options.length === 0) {\n return;\n }\n if (options.length === 1) {\n if (!options[0].classList.contains(this.classes.highlighted)) {\n options[0].classList.add(this.classes.highlighted);\n return;\n }\n }\n let highlighted = false;\n for (const o of options) {\n if (o.classList.contains(this.classes.highlighted)) {\n highlighted = true;\n }\n }\n if (!highlighted) {\n for (const o of options) {\n if (o.classList.contains(this.classes.selected)) {\n o.classList.add(this.classes.highlighted);\n break;\n }\n }\n }\n for (let i = 0; i < options.length; i++) {\n if (options[i].classList.contains(this.classes.highlighted)) {\n const prevOption = options[i];\n prevOption.classList.remove(this.classes.highlighted);\n const prevParent = prevOption.parentElement;\n if (prevParent && prevParent.classList.contains(this.classes.open)) {\n const optgroupLabel = prevParent.querySelector('.' + this.classes.optgroupLabel);\n if (optgroupLabel) {\n optgroupLabel.click();\n }\n }\n let selectOption = options[dir === 'down' ? (i + 1 < options.length ? i + 1 : 0) : i - 1 >= 0 ? i - 1 : options.length - 1];\n selectOption.classList.add(this.classes.highlighted);\n this.ensureElementInView(this.content.list, selectOption);\n const selectParent = selectOption.parentElement;\n if (selectParent && selectParent.classList.contains(this.classes.close)) {\n const optgroupLabel = selectParent.querySelector('.' + this.classes.optgroupLabel);\n if (optgroupLabel) {\n optgroupLabel.click();\n }\n }\n return;\n }\n }\n options[dir === 'down' ? 0 : options.length - 1].classList.add(this.classes.highlighted);\n this.ensureElementInView(this.content.list, options[dir === 'down' ? 0 : options.length - 1]);\n }\n listDiv() {\n const options = document.createElement('div');\n options.classList.add(this.classes.list);\n return options;\n }\n renderError(error) {\n this.content.list.innerHTML = '';\n const errorDiv = document.createElement('div');\n errorDiv.classList.add(this.classes.error);\n errorDiv.textContent = error;\n this.content.list.appendChild(errorDiv);\n }\n renderSearching() {\n this.content.list.innerHTML = '';\n const searchingDiv = document.createElement('div');\n searchingDiv.classList.add(this.classes.searching);\n searchingDiv.textContent = this.settings.searchingText;\n this.content.list.appendChild(searchingDiv);\n }\n renderOptions(data) {\n this.content.list.innerHTML = '';\n if (data.length === 0) {\n const noResults = document.createElement('div');\n noResults.classList.add(this.classes.search);\n if (this.callbacks.addable) {\n noResults.innerHTML = this.settings.addableText.replace('{value}', this.content.search.input.value);\n }\n else {\n noResults.innerHTML = this.settings.searchText;\n }\n this.content.list.appendChild(noResults);\n return;\n }\n if (this.settings.allowDeselect && !this.settings.isMultiple) {\n const placeholderOption = this.store.filter((o) => o.placeholder, false);\n if (!placeholderOption.length) {\n this.store.addOption(new Option({\n text: '',\n value: '',\n selected: false,\n placeholder: true\n }), true);\n }\n }\n for (const d of data) {\n if (d instanceof Optgroup) {\n const optgroupEl = document.createElement('div');\n optgroupEl.classList.add(this.classes.optgroup);\n const optgroupLabel = document.createElement('div');\n optgroupLabel.classList.add(this.classes.optgroupLabel);\n optgroupEl.appendChild(optgroupLabel);\n const optgroupLabelText = document.createElement('div');\n optgroupLabelText.classList.add(this.classes.optgroupLabelText);\n optgroupLabelText.textContent = d.label;\n optgroupLabel.appendChild(optgroupLabelText);\n const optgroupActions = document.createElement('div');\n optgroupActions.classList.add(this.classes.optgroupActions);\n optgroupLabel.appendChild(optgroupActions);\n if (this.settings.isMultiple && d.selectAll) {\n const selectAll = document.createElement('div');\n selectAll.classList.add(this.classes.optgroupSelectAll);\n let allSelected = true;\n for (const o of d.options) {\n if (!o.selected) {\n allSelected = false;\n break;\n }\n }\n if (allSelected) {\n selectAll.classList.add(this.classes.selected);\n }\n const selectAllText = document.createElement('span');\n selectAllText.textContent = d.selectAllText;\n selectAll.appendChild(selectAllText);\n const selectAllSvg = document.createElementNS('http://www.w3.org/2000/svg', 'svg');\n selectAllSvg.setAttribute('viewBox', '0 0 100 100');\n selectAll.appendChild(selectAllSvg);\n const selectAllBox = document.createElementNS('http://www.w3.org/2000/svg', 'path');\n selectAllBox.setAttribute('d', this.classes.optgroupSelectAllBox);\n selectAllSvg.appendChild(selectAllBox);\n const selectAllCheck = document.createElementNS('http://www.w3.org/2000/svg', 'path');\n selectAllCheck.setAttribute('d', this.classes.optgroupSelectAllCheck);\n selectAllSvg.appendChild(selectAllCheck);\n selectAll.addEventListener('click', (e) => {\n e.preventDefault();\n e.stopPropagation();\n const currentSelected = this.store.getSelected();\n if (allSelected) {\n const newSelected = currentSelected.filter((s) => {\n for (const o of d.options) {\n if (s === o.id) {\n return false;\n }\n }\n return true;\n });\n this.callbacks.setSelected(newSelected, true);\n return;\n }\n else {\n const newSelected = currentSelected.concat(d.options.map((o) => o.id));\n for (const o of d.options) {\n if (!this.store.getOptionByID(o.id)) {\n this.callbacks.addOption(o);\n }\n }\n this.callbacks.setSelected(newSelected, true);\n return;\n }\n });\n optgroupActions.appendChild(selectAll);\n }\n if (d.closable !== 'off') {\n const optgroupClosable = document.createElement('div');\n optgroupClosable.classList.add(this.classes.optgroupClosable);\n const optgroupClosableSvg = document.createElementNS('http://www.w3.org/2000/svg', 'svg');\n optgroupClosableSvg.setAttribute('viewBox', '0 0 100 100');\n optgroupClosableSvg.classList.add(this.classes.arrow);\n optgroupClosable.appendChild(optgroupClosableSvg);\n const optgroupClosableArrow = document.createElementNS('http://www.w3.org/2000/svg', 'path');\n optgroupClosableSvg.appendChild(optgroupClosableArrow);\n if (d.options.some((o) => o.selected) || this.content.search.input.value.trim() !== '') {\n optgroupClosable.classList.add(this.classes.open);\n optgroupClosableArrow.setAttribute('d', this.classes.arrowOpen);\n }\n else if (d.closable === 'open') {\n optgroupEl.classList.add(this.classes.open);\n optgroupClosableArrow.setAttribute('d', this.classes.arrowOpen);\n }\n else if (d.closable === 'close') {\n optgroupEl.classList.add(this.classes.close);\n optgroupClosableArrow.setAttribute('d', this.classes.arrowClose);\n }\n optgroupLabel.addEventListener('click', (e) => {\n e.preventDefault();\n e.stopPropagation();\n if (optgroupEl.classList.contains(this.classes.close)) {\n optgroupEl.classList.remove(this.classes.close);\n optgroupEl.classList.add(this.classes.open);\n optgroupClosableArrow.setAttribute('d', this.classes.arrowOpen);\n }\n else {\n optgroupEl.classList.remove(this.classes.open);\n optgroupEl.classList.add(this.classes.close);\n optgroupClosableArrow.setAttribute('d', this.classes.arrowClose);\n }\n });\n optgroupActions.appendChild(optgroupClosable);\n }\n optgroupEl.appendChild(optgroupLabel);\n for (const o of d.options) {\n optgroupEl.appendChild(this.option(o));\n }\n this.content.list.appendChild(optgroupEl);\n }\n if (d instanceof Option) {\n this.content.list.appendChild(this.option(d));\n }\n }\n }\n option(option) {\n if (option.placeholder) {\n const placeholder = document.createElement('div');\n placeholder.classList.add(this.classes.option);\n placeholder.classList.add(this.classes.hide);\n return placeholder;\n }\n const optionEl = document.createElement('div');\n optionEl.dataset.id = option.id;\n optionEl.classList.add(this.classes.option);\n optionEl.setAttribute('role', 'option');\n if (option.class) {\n option.class.split(' ').forEach((dataClass) => {\n optionEl.classList.add(dataClass);\n });\n }\n if (option.style) {\n optionEl.style.cssText = option.style;\n }\n if (this.settings.searchHighlight && this.content.search.input.value.trim() !== '') {\n optionEl.innerHTML = this.highlightText(option.html !== '' ? option.html : option.text, this.content.search.input.value, this.classes.searchHighlighter);\n }\n else if (option.html !== '') {\n optionEl.innerHTML = option.html;\n }\n else {\n optionEl.textContent = option.text;\n }\n if (this.settings.showOptionTooltips && optionEl.textContent) {\n optionEl.setAttribute('title', optionEl.textContent);\n }\n if (!option.display) {\n optionEl.classList.add(this.classes.hide);\n }\n if (option.disabled) {\n optionEl.classList.add(this.classes.disabled);\n }\n if (option.selected && this.settings.hideSelected) {\n optionEl.classList.add(this.classes.hide);\n }\n if (option.selected) {\n optionEl.classList.add(this.classes.selected);\n optionEl.setAttribute('aria-selected', 'true');\n this.main.main.setAttribute('aria-activedescendant', optionEl.id);\n }\n else {\n optionEl.classList.remove(this.classes.selected);\n optionEl.setAttribute('aria-selected', 'false');\n }\n optionEl.addEventListener('click', (e) => {\n e.preventDefault();\n e.stopPropagation();\n const selectedOptions = this.store.getSelected();\n const element = e.currentTarget;\n const elementID = String(element.dataset.id);\n if (option.disabled || (option.selected && !this.settings.allowDeselect)) {\n return;\n }\n if ((this.settings.isMultiple && this.settings.maxSelected <= selectedOptions.length && !option.selected) ||\n (this.settings.isMultiple && this.settings.minSelected >= selectedOptions.length && option.selected)) {\n return;\n }\n let shouldUpdate = false;\n const before = this.store.getSelectedOptions();\n let after = [];\n if (this.settings.isMultiple) {\n if (option.selected) {\n after = before.filter((o) => o.id !== elementID);\n }\n else {\n after = before.concat(option);\n }\n }\n if (!this.settings.isMultiple) {\n if (option.selected) {\n after = [];\n }\n else {\n after = [option];\n }\n }\n if (!this.callbacks.beforeChange) {\n shouldUpdate = true;\n }\n if (this.callbacks.beforeChange) {\n if (this.callbacks.beforeChange(after, before) === false) {\n shouldUpdate = false;\n }\n else {\n shouldUpdate = true;\n }\n }\n if (shouldUpdate) {\n if (!this.store.getOptionByID(elementID)) {\n this.callbacks.addOption(option);\n }\n this.callbacks.setSelected(after.map((o) => o.id), false);\n if (this.settings.closeOnSelect) {\n this.callbacks.close();\n }\n if (this.callbacks.afterChange) {\n this.callbacks.afterChange(after);\n }\n }\n });\n return optionEl;\n }\n destroy() {\n this.main.main.remove();\n this.content.main.remove();\n }\n highlightText(str, search, className) {\n let completedString = str;\n const regex = new RegExp('(?![^<]*>)(' + search.trim() + ')(?![^<]*>[^<>]*)', 'i');\n if (!str.match(regex)) {\n return str;\n }\n const matchStartPosition = str.match(regex).index;\n const matchEndPosition = matchStartPosition + str.match(regex)[0].toString().length;\n const originalTextFoundByRegex = str.substring(matchStartPosition, matchEndPosition);\n completedString = completedString.replace(regex, `${originalTextFoundByRegex}`);\n return completedString;\n }\n moveContentAbove() {\n const mainHeight = this.main.main.offsetHeight;\n const contentHeight = this.content.main.offsetHeight;\n this.main.main.classList.remove(this.classes.openBelow);\n this.main.main.classList.add(this.classes.openAbove);\n this.content.main.classList.remove(this.classes.openBelow);\n this.content.main.classList.add(this.classes.openAbove);\n const containerRect = this.main.main.getBoundingClientRect();\n this.content.main.style.margin = '-' + (mainHeight + contentHeight - 1) + 'px 0px 0px 0px';\n this.content.main.style.top =\n containerRect.top + containerRect.height + (this.settings.contentPosition === 'fixed' ? 0 : window.scrollY) + 'px';\n this.content.main.style.left =\n containerRect.left + (this.settings.contentPosition === 'fixed' ? 0 : window.scrollX) + 'px';\n this.content.main.style.width = containerRect.width + 'px';\n }\n moveContentBelow() {\n this.main.main.classList.remove(this.classes.openAbove);\n this.main.main.classList.add(this.classes.openBelow);\n this.content.main.classList.remove(this.classes.openAbove);\n this.content.main.classList.add(this.classes.openBelow);\n const containerRect = this.main.main.getBoundingClientRect();\n this.content.main.style.margin = '-1px 0px 0px 0px';\n if (this.settings.contentPosition !== 'relative') {\n this.content.main.style.top =\n containerRect.top +\n containerRect.height +\n (this.settings.contentPosition === 'fixed' ? 0 : window.scrollY) +\n 'px';\n this.content.main.style.left =\n containerRect.left + (this.settings.contentPosition === 'fixed' ? 0 : window.scrollX) + 'px';\n this.content.main.style.width = containerRect.width + 'px';\n }\n }\n ensureElementInView(container, element) {\n const cTop = container.scrollTop + container.offsetTop;\n const cBottom = cTop + container.clientHeight;\n const eTop = element.offsetTop;\n const eBottom = eTop + element.clientHeight;\n if (eTop < cTop) {\n container.scrollTop -= cTop - eTop;\n }\n else if (eBottom > cBottom) {\n container.scrollTop += eBottom - cBottom;\n }\n }\n putContent() {\n const mainHeight = this.main.main.offsetHeight;\n const mainRect = this.main.main.getBoundingClientRect();\n const contentHeight = this.content.main.offsetHeight;\n const spaceBelow = window.innerHeight - (mainRect.top + mainHeight);\n if (spaceBelow <= contentHeight) {\n if (mainRect.top > contentHeight) {\n return 'up';\n }\n else {\n return 'down';\n }\n }\n return 'down';\n }\n updateDeselectAll() {\n if (!this.store || !this.settings) {\n return;\n }\n const selected = this.store.getSelectedOptions();\n const hasSelectedItems = selected && selected.length > 0;\n const isMultiple = this.settings.isMultiple;\n const allowDeselect = this.settings.allowDeselect;\n const deselectButton = this.main.deselect.main;\n const hideClass = this.classes.hide;\n if (allowDeselect && !(isMultiple && !hasSelectedItems)) {\n deselectButton.classList.remove(hideClass);\n }\n else {\n deselectButton.classList.add(hideClass);\n }\n }\n }\n\n class Select {\n constructor(select) {\n this.listen = false;\n this.observer = null;\n this.select = select;\n this.valueChange = this.valueChange.bind(this);\n this.select.addEventListener('change', this.valueChange, {\n passive: true\n });\n this.observer = new MutationObserver(this.observeCall.bind(this));\n this.changeListen(true);\n }\n enable() {\n this.select.disabled = false;\n }\n disable() {\n this.select.disabled = true;\n }\n hideUI() {\n this.select.tabIndex = -1;\n this.select.style.display = 'none';\n this.select.setAttribute('aria-hidden', 'true');\n }\n showUI() {\n this.select.removeAttribute('tabindex');\n this.select.style.display = '';\n this.select.removeAttribute('aria-hidden');\n }\n changeListen(listen) {\n this.listen = listen;\n if (listen) {\n if (this.observer) {\n this.observer.observe(this.select, {\n subtree: true,\n childList: true,\n attributes: true\n });\n }\n }\n if (!listen) {\n if (this.observer) {\n this.observer.disconnect();\n }\n }\n }\n valueChange(ev) {\n if (this.listen && this.onValueChange) {\n this.onValueChange(this.getSelectedOptions());\n }\n return true;\n }\n observeCall(mutations) {\n if (!this.listen) {\n return;\n }\n let classChanged = false;\n let disabledChanged = false;\n let optgroupOptionChanged = false;\n for (const m of mutations) {\n if (m.target === this.select) {\n if (m.attributeName === 'disabled') {\n disabledChanged = true;\n }\n if (m.attributeName === 'class') {\n classChanged = true;\n }\n if (m.type === 'childList') {\n for (const n of m.addedNodes) {\n if (n.nodeName === 'OPTION' && n.value === this.select.value) {\n this.select.dispatchEvent(new Event('change'));\n break;\n }\n }\n optgroupOptionChanged = true;\n }\n }\n if (m.target.nodeName === 'OPTGROUP' || m.target.nodeName === 'OPTION') {\n optgroupOptionChanged = true;\n }\n }\n if (classChanged && this.onClassChange) {\n this.onClassChange(this.select.className.split(' '));\n }\n if (disabledChanged && this.onDisabledChange) {\n this.changeListen(false);\n this.onDisabledChange(this.select.disabled);\n this.changeListen(true);\n }\n if (optgroupOptionChanged && this.onOptionsChange) {\n this.changeListen(false);\n this.onOptionsChange(this.getData());\n this.changeListen(true);\n }\n }\n getData() {\n let data = [];\n const nodes = this.select.childNodes;\n for (const n of nodes) {\n if (n.nodeName === 'OPTGROUP') {\n data.push(this.getDataFromOptgroup(n));\n }\n if (n.nodeName === 'OPTION') {\n data.push(this.getDataFromOption(n));\n }\n }\n return data;\n }\n getDataFromOptgroup(optgroup) {\n let data = {\n id: optgroup.id,\n label: optgroup.label,\n selectAll: optgroup.dataset ? optgroup.dataset.selectall === 'true' : false,\n selectAllText: optgroup.dataset ? optgroup.dataset.selectalltext : 'Select all',\n closable: optgroup.dataset ? optgroup.dataset.closable : 'off',\n options: []\n };\n const options = optgroup.childNodes;\n for (const o of options) {\n if (o.nodeName === 'OPTION') {\n data.options.push(this.getDataFromOption(o));\n }\n }\n return data;\n }\n getDataFromOption(option) {\n return {\n id: option.id,\n value: option.value,\n text: option.text,\n html: option.dataset && option.dataset.html ? option.dataset.html : '',\n selected: option.selected,\n display: option.style.display !== 'none',\n disabled: option.disabled,\n mandatory: option.dataset ? option.dataset.mandatory === 'true' : false,\n placeholder: option.dataset.placeholder === 'true',\n class: option.className,\n style: option.style.cssText,\n data: option.dataset\n };\n }\n getSelectedOptions() {\n let options = [];\n const opts = this.select.childNodes;\n for (const o of opts) {\n if (o.nodeName === 'OPTGROUP') {\n const optgroupOptions = o.childNodes;\n for (const oo of optgroupOptions) {\n if (oo.nodeName === 'OPTION') {\n const option = oo;\n if (option.selected) {\n options.push(this.getDataFromOption(option));\n }\n }\n }\n }\n if (o.nodeName === 'OPTION') {\n const option = o;\n if (option.selected) {\n options.push(this.getDataFromOption(option));\n }\n }\n }\n return options;\n }\n getSelectedValues() {\n return this.getSelectedOptions().map((option) => option.value);\n }\n setSelected(ids) {\n this.changeListen(false);\n const options = this.select.childNodes;\n for (const o of options) {\n if (o.nodeName === 'OPTGROUP') {\n const optgroup = o;\n const optgroupOptions = optgroup.childNodes;\n for (const oo of optgroupOptions) {\n if (oo.nodeName === 'OPTION') {\n const option = oo;\n option.selected = ids.includes(option.id);\n }\n }\n }\n if (o.nodeName === 'OPTION') {\n const option = o;\n option.selected = ids.includes(option.id);\n }\n }\n this.changeListen(true);\n }\n setSelectedByValue(values) {\n this.changeListen(false);\n const options = this.select.childNodes;\n for (const o of options) {\n if (o.nodeName === 'OPTGROUP') {\n const optgroup = o;\n const optgroupOptions = optgroup.childNodes;\n for (const oo of optgroupOptions) {\n if (oo.nodeName === 'OPTION') {\n const option = oo;\n option.selected = values.includes(option.value);\n }\n }\n }\n if (o.nodeName === 'OPTION') {\n const option = o;\n option.selected = values.includes(option.value);\n }\n }\n this.changeListen(true);\n }\n updateSelect(id, style, classes) {\n this.changeListen(false);\n if (id) {\n this.select.dataset.id = id;\n }\n if (style) {\n this.select.style.cssText = style;\n }\n if (classes) {\n this.select.className = '';\n classes.forEach((c) => {\n if (c.trim() !== '') {\n this.select.classList.add(c.trim());\n }\n });\n }\n this.changeListen(true);\n }\n updateOptions(data) {\n this.changeListen(false);\n this.select.innerHTML = '';\n for (const d of data) {\n if (d instanceof Optgroup) {\n this.select.appendChild(this.createOptgroup(d));\n }\n if (d instanceof Option) {\n this.select.appendChild(this.createOption(d));\n }\n }\n this.select.dispatchEvent(new Event('change', { bubbles: true }));\n this.changeListen(true);\n }\n createOptgroup(optgroup) {\n const optgroupEl = document.createElement('optgroup');\n optgroupEl.id = optgroup.id;\n optgroupEl.label = optgroup.label;\n if (optgroup.selectAll) {\n optgroupEl.dataset.selectAll = 'true';\n }\n if (optgroup.closable !== 'off') {\n optgroupEl.dataset.closable = optgroup.closable;\n }\n if (optgroup.options) {\n for (const o of optgroup.options) {\n optgroupEl.appendChild(this.createOption(o));\n }\n }\n return optgroupEl;\n }\n createOption(info) {\n const optionEl = document.createElement('option');\n optionEl.id = info.id;\n optionEl.value = info.value;\n optionEl.textContent = info.text;\n if (info.html !== '') {\n optionEl.setAttribute('data-html', info.html);\n }\n if (info.selected) {\n optionEl.selected = info.selected;\n }\n if (info.disabled) {\n optionEl.disabled = true;\n }\n if (!info.display) {\n optionEl.style.display = 'none';\n }\n if (info.placeholder) {\n optionEl.setAttribute('data-placeholder', 'true');\n }\n if (info.mandatory) {\n optionEl.setAttribute('data-mandatory', 'true');\n }\n if (info.class) {\n info.class.split(' ').forEach((optionClass) => {\n optionEl.classList.add(optionClass);\n });\n }\n if (info.data && typeof info.data === 'object') {\n Object.keys(info.data).forEach((key) => {\n optionEl.setAttribute('data-' + kebabCase(key), info.data[key]);\n });\n }\n return optionEl;\n }\n destroy() {\n this.changeListen(false);\n this.select.removeEventListener('change', this.valueChange);\n if (this.observer) {\n this.observer.disconnect();\n this.observer = null;\n }\n delete this.select.dataset.id;\n this.showUI();\n }\n }\n\n class Settings {\n constructor(settings) {\n this.id = '';\n this.style = '';\n this.class = [];\n this.isMultiple = false;\n this.isOpen = false;\n this.isFullOpen = false;\n this.intervalMove = null;\n if (!settings) {\n settings = {};\n }\n this.id = 'ss-' + generateID();\n this.style = settings.style || '';\n this.class = settings.class || [];\n this.disabled = settings.disabled !== undefined ? settings.disabled : false;\n this.alwaysOpen = settings.alwaysOpen !== undefined ? settings.alwaysOpen : false;\n this.showSearch = settings.showSearch !== undefined ? settings.showSearch : true;\n this.focusSearch = settings.focusSearch !== undefined ? settings.focusSearch : true;\n this.ariaLabel = settings.ariaLabel || 'Combobox';\n this.searchPlaceholder = settings.searchPlaceholder || 'Search';\n this.searchText = settings.searchText || 'No Results';\n this.searchingText = settings.searchingText || 'Searching...';\n this.searchHighlight = settings.searchHighlight !== undefined ? settings.searchHighlight : false;\n this.closeOnSelect = settings.closeOnSelect !== undefined ? settings.closeOnSelect : true;\n this.contentLocation = settings.contentLocation || document.body;\n this.contentPosition = settings.contentPosition || 'absolute';\n this.openPosition = settings.openPosition || 'auto';\n this.placeholderText = settings.placeholderText !== undefined ? settings.placeholderText : 'Select Value';\n this.allowDeselect = settings.allowDeselect !== undefined ? settings.allowDeselect : false;\n this.hideSelected = settings.hideSelected !== undefined ? settings.hideSelected : false;\n this.keepOrder = settings.keepOrder !== undefined ? settings.keepOrder : false;\n this.showOptionTooltips = settings.showOptionTooltips !== undefined ? settings.showOptionTooltips : false;\n this.minSelected = settings.minSelected || 0;\n this.maxSelected = settings.maxSelected || 1000;\n this.timeoutDelay = settings.timeoutDelay || 200;\n this.maxValuesShown = settings.maxValuesShown || 20;\n this.maxValuesMessage = settings.maxValuesMessage || '{number} selected';\n this.addableText = settings.addableText || 'Press \"Enter\" to add {value}';\n }\n }\n\n class SlimSelect {\n constructor(config) {\n var _a;\n this.events = {\n search: undefined,\n searchFilter: (opt, search) => {\n return opt.text.toLowerCase().indexOf(search.toLowerCase()) !== -1;\n },\n addable: undefined,\n beforeChange: undefined,\n afterChange: undefined,\n beforeOpen: undefined,\n afterOpen: undefined,\n beforeClose: undefined,\n afterClose: undefined\n };\n this.windowResize = debounce(() => {\n if (!this.settings.isOpen && !this.settings.isFullOpen) {\n return;\n }\n this.render.moveContent();\n });\n this.windowScroll = debounce(() => {\n if (!this.settings.isOpen && !this.settings.isFullOpen) {\n return;\n }\n this.render.moveContent();\n });\n this.documentClick = (e) => {\n if (!this.settings.isOpen) {\n return;\n }\n if (e.target && !hasClassInTree(e.target, this.settings.id)) {\n this.close(e.type);\n }\n };\n this.windowVisibilityChange = () => {\n if (document.hidden) {\n this.close();\n }\n };\n this.selectEl = (typeof config.select === 'string' ? document.querySelector(config.select) : config.select);\n if (!this.selectEl) {\n if (config.events && config.events.error) {\n config.events.error(new Error('Could not find select element'));\n }\n return;\n }\n if (this.selectEl.tagName !== 'SELECT') {\n if (config.events && config.events.error) {\n config.events.error(new Error('Element isnt of type select'));\n }\n return;\n }\n if (this.selectEl.dataset.ssid) {\n this.destroy();\n }\n this.settings = new Settings(config.settings);\n this.cssClasses = new CssClasses(config.cssClasses);\n const debounceEvents = ['afterChange', 'beforeOpen', 'afterOpen', 'beforeClose', 'afterClose'];\n for (const key in config.events) {\n if (!config.events.hasOwnProperty(key)) {\n continue;\n }\n if (debounceEvents.indexOf(key) !== -1) {\n this.events[key] = debounce(config.events[key], 100);\n }\n else {\n this.events[key] = config.events[key];\n }\n }\n this.settings.disabled = ((_a = config.settings) === null || _a === void 0 ? void 0 : _a.disabled) ? config.settings.disabled : this.selectEl.disabled;\n this.settings.isMultiple = this.selectEl.multiple;\n this.settings.style = this.selectEl.style.cssText;\n this.settings.class = this.selectEl.className.split(' ');\n this.select = new Select(this.selectEl);\n this.select.updateSelect(this.settings.id, this.settings.style, this.settings.class);\n this.select.hideUI();\n this.select.onValueChange = (options) => {\n this.setSelected(options.map((option) => option.id));\n };\n this.select.onClassChange = (classes) => {\n this.settings.class = classes;\n this.render.updateClassStyles();\n };\n this.select.onDisabledChange = (disabled) => {\n if (disabled) {\n this.disable();\n }\n else {\n this.enable();\n }\n };\n this.select.onOptionsChange = (data) => {\n this.setData(data);\n };\n this.store = new Store(this.settings.isMultiple ? 'multiple' : 'single', config.data ? config.data : this.select.getData());\n if (config.data) {\n this.select.updateOptions(this.store.getData());\n }\n const renderCallbacks = {\n open: this.open.bind(this),\n close: this.close.bind(this),\n addable: this.events.addable ? this.events.addable : undefined,\n setSelected: this.setSelected.bind(this),\n addOption: this.addOption.bind(this),\n search: this.search.bind(this),\n beforeChange: this.events.beforeChange,\n afterChange: this.events.afterChange\n };\n this.render = new Render(this.settings, this.cssClasses, this.store, renderCallbacks);\n this.render.renderValues();\n this.render.renderOptions(this.store.getData());\n const selectAriaLabel = this.selectEl.getAttribute('aria-label');\n const selectAriaLabelledBy = this.selectEl.getAttribute('aria-labelledby');\n if (selectAriaLabel) {\n this.render.main.main.setAttribute('aria-label', selectAriaLabel);\n }\n else if (selectAriaLabelledBy) {\n this.render.main.main.setAttribute('aria-labelledby', selectAriaLabelledBy);\n }\n if (this.selectEl.parentNode) {\n this.selectEl.parentNode.insertBefore(this.render.main.main, this.selectEl.nextSibling);\n }\n window.addEventListener('resize', this.windowResize, false);\n if (this.settings.openPosition === 'auto') {\n window.addEventListener('scroll', this.windowScroll, false);\n }\n document.addEventListener('visibilitychange', this.windowVisibilityChange);\n if (this.settings.disabled) {\n this.disable();\n }\n if (this.settings.alwaysOpen) {\n this.open();\n }\n this.selectEl.slim = this;\n }\n enable() {\n this.settings.disabled = false;\n this.select.enable();\n this.render.enable();\n }\n disable() {\n this.settings.disabled = true;\n this.select.disable();\n this.render.disable();\n }\n getData() {\n return this.store.getData();\n }\n setData(data) {\n const selected = this.store.getSelected();\n const err = this.store.validateDataArray(data);\n if (err) {\n if (this.events.error) {\n this.events.error(err);\n }\n return;\n }\n this.store.setData(data);\n const dataClean = this.store.getData();\n this.select.updateOptions(dataClean);\n this.render.renderValues();\n this.render.renderOptions(dataClean);\n if (this.events.afterChange && !isEqual(selected, this.store.getSelected())) {\n this.events.afterChange(this.store.getSelectedOptions());\n }\n }\n getSelected() {\n let options = this.store.getSelectedOptions();\n if (this.settings.keepOrder) {\n options = this.store.selectedOrderOptions(options);\n }\n return options.map((option) => option.value);\n }\n setSelected(values, runAfterChange = true) {\n const selected = this.store.getSelected();\n const options = this.store.getDataOptions();\n values = Array.isArray(values) ? values : [values];\n const ids = [];\n for (const value of values) {\n if (options.find((option) => option.id == value)) {\n ids.push(value);\n continue;\n }\n for (const option of options.filter((option) => option.value == value)) {\n ids.push(option.id);\n }\n }\n this.store.setSelectedBy('id', ids);\n const data = this.store.getData();\n this.select.updateOptions(data);\n this.render.renderValues();\n if (this.render.content.search.input.value !== '') {\n this.search(this.render.content.search.input.value);\n }\n else {\n this.render.renderOptions(data);\n }\n if (runAfterChange && this.events.afterChange && !isEqual(selected, this.store.getSelected())) {\n this.events.afterChange(this.store.getSelectedOptions());\n }\n }\n addOption(option) {\n const selected = this.store.getSelected();\n if (!this.store.getDataOptions().some((o) => { var _a; return o.value === ((_a = option.value) !== null && _a !== void 0 ? _a : option.text); })) {\n this.store.addOption(option);\n }\n const data = this.store.getData();\n this.select.updateOptions(data);\n this.render.renderValues();\n this.render.renderOptions(data);\n if (this.events.afterChange && !isEqual(selected, this.store.getSelected())) {\n this.events.afterChange(this.store.getSelectedOptions());\n }\n }\n open() {\n if (this.settings.disabled || this.settings.isOpen) {\n return;\n }\n if (this.events.beforeOpen) {\n this.events.beforeOpen();\n }\n this.render.open();\n if (this.settings.showSearch && this.settings.focusSearch) {\n this.render.searchFocus();\n }\n this.settings.isOpen = true;\n setTimeout(() => {\n if (this.events.afterOpen) {\n this.events.afterOpen();\n }\n if (this.settings.isOpen) {\n this.settings.isFullOpen = true;\n }\n document.addEventListener('click', this.documentClick);\n }, this.settings.timeoutDelay);\n if (this.settings.contentPosition === 'absolute') {\n if (this.settings.intervalMove) {\n clearInterval(this.settings.intervalMove);\n }\n this.settings.intervalMove = setInterval(this.render.moveContent.bind(this.render), 500);\n }\n }\n close(eventType = null) {\n if (!this.settings.isOpen || this.settings.alwaysOpen) {\n return;\n }\n if (this.events.beforeClose) {\n this.events.beforeClose();\n }\n this.render.close();\n if (this.render.content.search.input.value !== '') {\n this.search('');\n }\n this.render.mainFocus(eventType);\n this.settings.isOpen = false;\n this.settings.isFullOpen = false;\n setTimeout(() => {\n if (this.events.afterClose) {\n this.events.afterClose();\n }\n document.removeEventListener('click', this.documentClick);\n }, this.settings.timeoutDelay);\n if (this.settings.intervalMove) {\n clearInterval(this.settings.intervalMove);\n }\n }\n search(value) {\n if (this.render.content.search.input.value !== value) {\n this.render.content.search.input.value = value;\n }\n if (!this.events.search) {\n this.render.renderOptions(value === '' ? this.store.getData() : this.store.search(value, this.events.searchFilter));\n return;\n }\n this.render.renderSearching();\n const searchResp = this.events.search(value, this.store.getSelectedOptions());\n if (searchResp instanceof Promise) {\n searchResp\n .then((data) => {\n this.render.renderOptions(this.store.partialToFullData(data));\n })\n .catch((err) => {\n this.render.renderError(typeof err === 'string' ? err : err.message);\n });\n return;\n }\n else if (Array.isArray(searchResp)) {\n this.render.renderOptions(this.store.partialToFullData(searchResp));\n }\n else {\n this.render.renderError('Search event must return a promise or an array of data');\n }\n }\n destroy() {\n document.removeEventListener('click', this.documentClick);\n window.removeEventListener('resize', this.windowResize, false);\n if (this.settings.openPosition === 'auto') {\n window.removeEventListener('scroll', this.windowScroll, false);\n }\n document.removeEventListener('visibilitychange', this.windowVisibilityChange);\n this.store.setData([]);\n this.render.destroy();\n this.select.destroy();\n }\n }\n\n return SlimSelect;\n\n}));\n", "/*!\nTurbo 8.0.12\nCopyright \u00A9 2024 37signals LLC\n */\n/**\n * The MIT License (MIT)\n *\n * Copyright (c) 2019 Javan Makhmali\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in\n * all copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n * THE SOFTWARE.\n */\n\n(function (prototype) {\n if (typeof prototype.requestSubmit == \"function\") return\n\n prototype.requestSubmit = function (submitter) {\n if (submitter) {\n validateSubmitter(submitter, this);\n submitter.click();\n } else {\n submitter = document.createElement(\"input\");\n submitter.type = \"submit\";\n submitter.hidden = true;\n this.appendChild(submitter);\n submitter.click();\n this.removeChild(submitter);\n }\n };\n\n function validateSubmitter(submitter, form) {\n submitter instanceof HTMLElement || raise(TypeError, \"parameter 1 is not of type 'HTMLElement'\");\n submitter.type == \"submit\" || raise(TypeError, \"The specified element is not a submit button\");\n submitter.form == form ||\n raise(DOMException, \"The specified element is not owned by this form element\", \"NotFoundError\");\n }\n\n function raise(errorConstructor, message, name) {\n throw new errorConstructor(\"Failed to execute 'requestSubmit' on 'HTMLFormElement': \" + message + \".\", name)\n }\n})(HTMLFormElement.prototype);\n\nconst submittersByForm = new WeakMap();\n\nfunction findSubmitterFromClickTarget(target) {\n const element = target instanceof Element ? target : target instanceof Node ? target.parentElement : null;\n const candidate = element ? element.closest(\"input, button\") : null;\n return candidate?.type == \"submit\" ? candidate : null\n}\n\nfunction clickCaptured(event) {\n const submitter = findSubmitterFromClickTarget(event.target);\n\n if (submitter && submitter.form) {\n submittersByForm.set(submitter.form, submitter);\n }\n}\n\n(function () {\n if (\"submitter\" in Event.prototype) return\n\n let prototype = window.Event.prototype;\n // Certain versions of Safari 15 have a bug where they won't\n // populate the submitter. This hurts TurboDrive's enable/disable detection.\n // See https://bugs.webkit.org/show_bug.cgi?id=229660\n if (\"SubmitEvent\" in window) {\n const prototypeOfSubmitEvent = window.SubmitEvent.prototype;\n\n if (/Apple Computer/.test(navigator.vendor) && !(\"submitter\" in prototypeOfSubmitEvent)) {\n prototype = prototypeOfSubmitEvent;\n } else {\n return // polyfill not needed\n }\n }\n\n addEventListener(\"click\", clickCaptured, true);\n\n Object.defineProperty(prototype, \"submitter\", {\n get() {\n if (this.type == \"submit\" && this.target instanceof HTMLFormElement) {\n return submittersByForm.get(this.target)\n }\n }\n });\n})();\n\nconst FrameLoadingStyle = {\n eager: \"eager\",\n lazy: \"lazy\"\n};\n\n/**\n * Contains a fragment of HTML which is updated based on navigation within\n * it (e.g. via links or form submissions).\n *\n * @customElement turbo-frame\n * @example\n * \n * \n * Show all expanded messages in this frame.\n * \n *\n * \n * \n */\nclass FrameElement extends HTMLElement {\n static delegateConstructor = undefined\n\n loaded = Promise.resolve()\n\n static get observedAttributes() {\n return [\"disabled\", \"loading\", \"src\"]\n }\n\n constructor() {\n super();\n this.delegate = new FrameElement.delegateConstructor(this);\n }\n\n connectedCallback() {\n this.delegate.connect();\n }\n\n disconnectedCallback() {\n this.delegate.disconnect();\n }\n\n reload() {\n return this.delegate.sourceURLReloaded()\n }\n\n attributeChangedCallback(name) {\n if (name == \"loading\") {\n this.delegate.loadingStyleChanged();\n } else if (name == \"src\") {\n this.delegate.sourceURLChanged();\n } else if (name == \"disabled\") {\n this.delegate.disabledChanged();\n }\n }\n\n /**\n * Gets the URL to lazily load source HTML from\n */\n get src() {\n return this.getAttribute(\"src\")\n }\n\n /**\n * Sets the URL to lazily load source HTML from\n */\n set src(value) {\n if (value) {\n this.setAttribute(\"src\", value);\n } else {\n this.removeAttribute(\"src\");\n }\n }\n\n /**\n * Gets the refresh mode for the frame.\n */\n get refresh() {\n return this.getAttribute(\"refresh\")\n }\n\n /**\n * Sets the refresh mode for the frame.\n */\n set refresh(value) {\n if (value) {\n this.setAttribute(\"refresh\", value);\n } else {\n this.removeAttribute(\"refresh\");\n }\n }\n\n get shouldReloadWithMorph() {\n return this.src && this.refresh === \"morph\"\n }\n\n /**\n * Determines if the element is loading\n */\n get loading() {\n return frameLoadingStyleFromString(this.getAttribute(\"loading\") || \"\")\n }\n\n /**\n * Sets the value of if the element is loading\n */\n set loading(value) {\n if (value) {\n this.setAttribute(\"loading\", value);\n } else {\n this.removeAttribute(\"loading\");\n }\n }\n\n /**\n * Gets the disabled state of the frame.\n *\n * If disabled, no requests will be intercepted by the frame.\n */\n get disabled() {\n return this.hasAttribute(\"disabled\")\n }\n\n /**\n * Sets the disabled state of the frame.\n *\n * If disabled, no requests will be intercepted by the frame.\n */\n set disabled(value) {\n if (value) {\n this.setAttribute(\"disabled\", \"\");\n } else {\n this.removeAttribute(\"disabled\");\n }\n }\n\n /**\n * Gets the autoscroll state of the frame.\n *\n * If true, the frame will be scrolled into view automatically on update.\n */\n get autoscroll() {\n return this.hasAttribute(\"autoscroll\")\n }\n\n /**\n * Sets the autoscroll state of the frame.\n *\n * If true, the frame will be scrolled into view automatically on update.\n */\n set autoscroll(value) {\n if (value) {\n this.setAttribute(\"autoscroll\", \"\");\n } else {\n this.removeAttribute(\"autoscroll\");\n }\n }\n\n /**\n * Determines if the element has finished loading\n */\n get complete() {\n return !this.delegate.isLoading\n }\n\n /**\n * Gets the active state of the frame.\n *\n * If inactive, source changes will not be observed.\n */\n get isActive() {\n return this.ownerDocument === document && !this.isPreview\n }\n\n /**\n * Sets the active state of the frame.\n *\n * If inactive, source changes will not be observed.\n */\n get isPreview() {\n return this.ownerDocument?.documentElement?.hasAttribute(\"data-turbo-preview\")\n }\n}\n\nfunction frameLoadingStyleFromString(style) {\n switch (style.toLowerCase()) {\n case \"lazy\":\n return FrameLoadingStyle.lazy\n default:\n return FrameLoadingStyle.eager\n }\n}\n\nconst drive = {\n enabled: true,\n progressBarDelay: 500,\n unvisitableExtensions: new Set(\n [\n \".7z\", \".aac\", \".apk\", \".avi\", \".bmp\", \".bz2\", \".css\", \".csv\", \".deb\", \".dmg\", \".doc\",\n \".docx\", \".exe\", \".gif\", \".gz\", \".heic\", \".heif\", \".ico\", \".iso\", \".jpeg\", \".jpg\",\n \".js\", \".json\", \".m4a\", \".mkv\", \".mov\", \".mp3\", \".mp4\", \".mpeg\", \".mpg\", \".msi\",\n \".ogg\", \".ogv\", \".pdf\", \".pkg\", \".png\", \".ppt\", \".pptx\", \".rar\", \".rtf\",\n \".svg\", \".tar\", \".tif\", \".tiff\", \".txt\", \".wav\", \".webm\", \".webp\", \".wma\", \".wmv\",\n \".xls\", \".xlsx\", \".xml\", \".zip\"\n ]\n )\n};\n\nfunction activateScriptElement(element) {\n if (element.getAttribute(\"data-turbo-eval\") == \"false\") {\n return element\n } else {\n const createdScriptElement = document.createElement(\"script\");\n const cspNonce = getCspNonce();\n if (cspNonce) {\n createdScriptElement.nonce = cspNonce;\n }\n createdScriptElement.textContent = element.textContent;\n createdScriptElement.async = false;\n copyElementAttributes(createdScriptElement, element);\n return createdScriptElement\n }\n}\n\nfunction copyElementAttributes(destinationElement, sourceElement) {\n for (const { name, value } of sourceElement.attributes) {\n destinationElement.setAttribute(name, value);\n }\n}\n\nfunction createDocumentFragment(html) {\n const template = document.createElement(\"template\");\n template.innerHTML = html;\n return template.content\n}\n\nfunction dispatch(eventName, { target, cancelable, detail } = {}) {\n const event = new CustomEvent(eventName, {\n cancelable,\n bubbles: true,\n composed: true,\n detail\n });\n\n if (target && target.isConnected) {\n target.dispatchEvent(event);\n } else {\n document.documentElement.dispatchEvent(event);\n }\n\n return event\n}\n\nfunction cancelEvent(event) {\n event.preventDefault();\n event.stopImmediatePropagation();\n}\n\nfunction nextRepaint() {\n if (document.visibilityState === \"hidden\") {\n return nextEventLoopTick()\n } else {\n return nextAnimationFrame()\n }\n}\n\nfunction nextAnimationFrame() {\n return new Promise((resolve) => requestAnimationFrame(() => resolve()))\n}\n\nfunction nextEventLoopTick() {\n return new Promise((resolve) => setTimeout(() => resolve(), 0))\n}\n\nfunction nextMicrotask() {\n return Promise.resolve()\n}\n\nfunction parseHTMLDocument(html = \"\") {\n return new DOMParser().parseFromString(html, \"text/html\")\n}\n\nfunction unindent(strings, ...values) {\n const lines = interpolate(strings, values).replace(/^\\n/, \"\").split(\"\\n\");\n const match = lines[0].match(/^\\s+/);\n const indent = match ? match[0].length : 0;\n return lines.map((line) => line.slice(indent)).join(\"\\n\")\n}\n\nfunction interpolate(strings, values) {\n return strings.reduce((result, string, i) => {\n const value = values[i] == undefined ? \"\" : values[i];\n return result + string + value\n }, \"\")\n}\n\nfunction uuid() {\n return Array.from({ length: 36 })\n .map((_, i) => {\n if (i == 8 || i == 13 || i == 18 || i == 23) {\n return \"-\"\n } else if (i == 14) {\n return \"4\"\n } else if (i == 19) {\n return (Math.floor(Math.random() * 4) + 8).toString(16)\n } else {\n return Math.floor(Math.random() * 15).toString(16)\n }\n })\n .join(\"\")\n}\n\nfunction getAttribute(attributeName, ...elements) {\n for (const value of elements.map((element) => element?.getAttribute(attributeName))) {\n if (typeof value == \"string\") return value\n }\n\n return null\n}\n\nfunction hasAttribute(attributeName, ...elements) {\n return elements.some((element) => element && element.hasAttribute(attributeName))\n}\n\nfunction markAsBusy(...elements) {\n for (const element of elements) {\n if (element.localName == \"turbo-frame\") {\n element.setAttribute(\"busy\", \"\");\n }\n element.setAttribute(\"aria-busy\", \"true\");\n }\n}\n\nfunction clearBusyState(...elements) {\n for (const element of elements) {\n if (element.localName == \"turbo-frame\") {\n element.removeAttribute(\"busy\");\n }\n\n element.removeAttribute(\"aria-busy\");\n }\n}\n\nfunction waitForLoad(element, timeoutInMilliseconds = 2000) {\n return new Promise((resolve) => {\n const onComplete = () => {\n element.removeEventListener(\"error\", onComplete);\n element.removeEventListener(\"load\", onComplete);\n resolve();\n };\n\n element.addEventListener(\"load\", onComplete, { once: true });\n element.addEventListener(\"error\", onComplete, { once: true });\n setTimeout(resolve, timeoutInMilliseconds);\n })\n}\n\nfunction getHistoryMethodForAction(action) {\n switch (action) {\n case \"replace\":\n return history.replaceState\n case \"advance\":\n case \"restore\":\n return history.pushState\n }\n}\n\nfunction isAction(action) {\n return action == \"advance\" || action == \"replace\" || action == \"restore\"\n}\n\nfunction getVisitAction(...elements) {\n const action = getAttribute(\"data-turbo-action\", ...elements);\n\n return isAction(action) ? action : null\n}\n\nfunction getMetaElement(name) {\n return document.querySelector(`meta[name=\"${name}\"]`)\n}\n\nfunction getMetaContent(name) {\n const element = getMetaElement(name);\n return element && element.content\n}\n\nfunction getCspNonce() {\n const element = getMetaElement(\"csp-nonce\");\n\n if (element) {\n const { nonce, content } = element;\n return nonce == \"\" ? content : nonce\n }\n}\n\nfunction setMetaContent(name, content) {\n let element = getMetaElement(name);\n\n if (!element) {\n element = document.createElement(\"meta\");\n element.setAttribute(\"name\", name);\n\n document.head.appendChild(element);\n }\n\n element.setAttribute(\"content\", content);\n\n return element\n}\n\nfunction findClosestRecursively(element, selector) {\n if (element instanceof Element) {\n return (\n element.closest(selector) || findClosestRecursively(element.assignedSlot || element.getRootNode()?.host, selector)\n )\n }\n}\n\nfunction elementIsFocusable(element) {\n const inertDisabledOrHidden = \"[inert], :disabled, [hidden], details:not([open]), dialog:not([open])\";\n\n return !!element && element.closest(inertDisabledOrHidden) == null && typeof element.focus == \"function\"\n}\n\nfunction queryAutofocusableElement(elementOrDocumentFragment) {\n return Array.from(elementOrDocumentFragment.querySelectorAll(\"[autofocus]\")).find(elementIsFocusable)\n}\n\nasync function around(callback, reader) {\n const before = reader();\n\n callback();\n\n await nextAnimationFrame();\n\n const after = reader();\n\n return [before, after]\n}\n\nfunction doesNotTargetIFrame(name) {\n if (name === \"_blank\") {\n return false\n } else if (name) {\n for (const element of document.getElementsByName(name)) {\n if (element instanceof HTMLIFrameElement) return false\n }\n\n return true\n } else {\n return true\n }\n}\n\nfunction findLinkFromClickTarget(target) {\n return findClosestRecursively(target, \"a[href]:not([target^=_]):not([download])\")\n}\n\nfunction getLocationForLink(link) {\n return expandURL(link.getAttribute(\"href\") || \"\")\n}\n\nfunction debounce(fn, delay) {\n let timeoutId = null;\n\n return (...args) => {\n const callback = () => fn.apply(this, args);\n clearTimeout(timeoutId);\n timeoutId = setTimeout(callback, delay);\n }\n}\n\nconst submitter = {\n \"aria-disabled\": {\n beforeSubmit: submitter => {\n submitter.setAttribute(\"aria-disabled\", \"true\");\n submitter.addEventListener(\"click\", cancelEvent);\n },\n\n afterSubmit: submitter => {\n submitter.removeAttribute(\"aria-disabled\");\n submitter.removeEventListener(\"click\", cancelEvent);\n }\n },\n\n \"disabled\": {\n beforeSubmit: submitter => submitter.disabled = true,\n afterSubmit: submitter => submitter.disabled = false\n }\n};\n\nclass Config {\n #submitter = null\n\n constructor(config) {\n Object.assign(this, config);\n }\n\n get submitter() {\n return this.#submitter\n }\n\n set submitter(value) {\n this.#submitter = submitter[value] || value;\n }\n}\n\nconst forms = new Config({\n mode: \"on\",\n submitter: \"disabled\"\n});\n\nconst config = {\n drive,\n forms\n};\n\nfunction expandURL(locatable) {\n return new URL(locatable.toString(), document.baseURI)\n}\n\nfunction getAnchor(url) {\n let anchorMatch;\n if (url.hash) {\n return url.hash.slice(1)\n // eslint-disable-next-line no-cond-assign\n } else if ((anchorMatch = url.href.match(/#(.*)$/))) {\n return anchorMatch[1]\n }\n}\n\nfunction getAction$1(form, submitter) {\n const action = submitter?.getAttribute(\"formaction\") || form.getAttribute(\"action\") || form.action;\n\n return expandURL(action)\n}\n\nfunction getExtension(url) {\n return (getLastPathComponent(url).match(/\\.[^.]*$/) || [])[0] || \"\"\n}\n\nfunction isPrefixedBy(baseURL, url) {\n const prefix = getPrefix(url);\n return baseURL.href === expandURL(prefix).href || baseURL.href.startsWith(prefix)\n}\n\nfunction locationIsVisitable(location, rootLocation) {\n return isPrefixedBy(location, rootLocation) && !config.drive.unvisitableExtensions.has(getExtension(location))\n}\n\nfunction getRequestURL(url) {\n const anchor = getAnchor(url);\n return anchor != null ? url.href.slice(0, -(anchor.length + 1)) : url.href\n}\n\nfunction toCacheKey(url) {\n return getRequestURL(url)\n}\n\nfunction urlsAreEqual(left, right) {\n return expandURL(left).href == expandURL(right).href\n}\n\nfunction getPathComponents(url) {\n return url.pathname.split(\"/\").slice(1)\n}\n\nfunction getLastPathComponent(url) {\n return getPathComponents(url).slice(-1)[0]\n}\n\nfunction getPrefix(url) {\n return addTrailingSlash(url.origin + url.pathname)\n}\n\nfunction addTrailingSlash(value) {\n return value.endsWith(\"/\") ? value : value + \"/\"\n}\n\nclass FetchResponse {\n constructor(response) {\n this.response = response;\n }\n\n get succeeded() {\n return this.response.ok\n }\n\n get failed() {\n return !this.succeeded\n }\n\n get clientError() {\n return this.statusCode >= 400 && this.statusCode <= 499\n }\n\n get serverError() {\n return this.statusCode >= 500 && this.statusCode <= 599\n }\n\n get redirected() {\n return this.response.redirected\n }\n\n get location() {\n return expandURL(this.response.url)\n }\n\n get isHTML() {\n return this.contentType && this.contentType.match(/^(?:text\\/([^\\s;,]+\\b)?html|application\\/xhtml\\+xml)\\b/)\n }\n\n get statusCode() {\n return this.response.status\n }\n\n get contentType() {\n return this.header(\"Content-Type\")\n }\n\n get responseText() {\n return this.response.clone().text()\n }\n\n get responseHTML() {\n if (this.isHTML) {\n return this.response.clone().text()\n } else {\n return Promise.resolve(undefined)\n }\n }\n\n header(name) {\n return this.response.headers.get(name)\n }\n}\n\nclass LimitedSet extends Set {\n constructor(maxSize) {\n super();\n this.maxSize = maxSize;\n }\n\n add(value) {\n if (this.size >= this.maxSize) {\n const iterator = this.values();\n const oldestValue = iterator.next().value;\n this.delete(oldestValue);\n }\n super.add(value);\n }\n}\n\nconst recentRequests = new LimitedSet(20);\n\nconst nativeFetch = window.fetch;\n\nfunction fetchWithTurboHeaders(url, options = {}) {\n const modifiedHeaders = new Headers(options.headers || {});\n const requestUID = uuid();\n recentRequests.add(requestUID);\n modifiedHeaders.append(\"X-Turbo-Request-Id\", requestUID);\n\n return nativeFetch(url, {\n ...options,\n headers: modifiedHeaders\n })\n}\n\nfunction fetchMethodFromString(method) {\n switch (method.toLowerCase()) {\n case \"get\":\n return FetchMethod.get\n case \"post\":\n return FetchMethod.post\n case \"put\":\n return FetchMethod.put\n case \"patch\":\n return FetchMethod.patch\n case \"delete\":\n return FetchMethod.delete\n }\n}\n\nconst FetchMethod = {\n get: \"get\",\n post: \"post\",\n put: \"put\",\n patch: \"patch\",\n delete: \"delete\"\n};\n\nfunction fetchEnctypeFromString(encoding) {\n switch (encoding.toLowerCase()) {\n case FetchEnctype.multipart:\n return FetchEnctype.multipart\n case FetchEnctype.plain:\n return FetchEnctype.plain\n default:\n return FetchEnctype.urlEncoded\n }\n}\n\nconst FetchEnctype = {\n urlEncoded: \"application/x-www-form-urlencoded\",\n multipart: \"multipart/form-data\",\n plain: \"text/plain\"\n};\n\nclass FetchRequest {\n abortController = new AbortController()\n #resolveRequestPromise = (_value) => {}\n\n constructor(delegate, method, location, requestBody = new URLSearchParams(), target = null, enctype = FetchEnctype.urlEncoded) {\n const [url, body] = buildResourceAndBody(expandURL(location), method, requestBody, enctype);\n\n this.delegate = delegate;\n this.url = url;\n this.target = target;\n this.fetchOptions = {\n credentials: \"same-origin\",\n redirect: \"follow\",\n method: method.toUpperCase(),\n headers: { ...this.defaultHeaders },\n body: body,\n signal: this.abortSignal,\n referrer: this.delegate.referrer?.href\n };\n this.enctype = enctype;\n }\n\n get method() {\n return this.fetchOptions.method\n }\n\n set method(value) {\n const fetchBody = this.isSafe ? this.url.searchParams : this.fetchOptions.body || new FormData();\n const fetchMethod = fetchMethodFromString(value) || FetchMethod.get;\n\n this.url.search = \"\";\n\n const [url, body] = buildResourceAndBody(this.url, fetchMethod, fetchBody, this.enctype);\n\n this.url = url;\n this.fetchOptions.body = body;\n this.fetchOptions.method = fetchMethod.toUpperCase();\n }\n\n get headers() {\n return this.fetchOptions.headers\n }\n\n set headers(value) {\n this.fetchOptions.headers = value;\n }\n\n get body() {\n if (this.isSafe) {\n return this.url.searchParams\n } else {\n return this.fetchOptions.body\n }\n }\n\n set body(value) {\n this.fetchOptions.body = value;\n }\n\n get location() {\n return this.url\n }\n\n get params() {\n return this.url.searchParams\n }\n\n get entries() {\n return this.body ? Array.from(this.body.entries()) : []\n }\n\n cancel() {\n this.abortController.abort();\n }\n\n async perform() {\n const { fetchOptions } = this;\n this.delegate.prepareRequest(this);\n const event = await this.#allowRequestToBeIntercepted(fetchOptions);\n try {\n this.delegate.requestStarted(this);\n\n if (event.detail.fetchRequest) {\n this.response = event.detail.fetchRequest.response;\n } else {\n this.response = fetchWithTurboHeaders(this.url.href, fetchOptions);\n }\n\n const response = await this.response;\n return await this.receive(response)\n } catch (error) {\n if (error.name !== \"AbortError\") {\n if (this.#willDelegateErrorHandling(error)) {\n this.delegate.requestErrored(this, error);\n }\n throw error\n }\n } finally {\n this.delegate.requestFinished(this);\n }\n }\n\n async receive(response) {\n const fetchResponse = new FetchResponse(response);\n const event = dispatch(\"turbo:before-fetch-response\", {\n cancelable: true,\n detail: { fetchResponse },\n target: this.target\n });\n if (event.defaultPrevented) {\n this.delegate.requestPreventedHandlingResponse(this, fetchResponse);\n } else if (fetchResponse.succeeded) {\n this.delegate.requestSucceededWithResponse(this, fetchResponse);\n } else {\n this.delegate.requestFailedWithResponse(this, fetchResponse);\n }\n return fetchResponse\n }\n\n get defaultHeaders() {\n return {\n Accept: \"text/html, application/xhtml+xml\"\n }\n }\n\n get isSafe() {\n return isSafe(this.method)\n }\n\n get abortSignal() {\n return this.abortController.signal\n }\n\n acceptResponseType(mimeType) {\n this.headers[\"Accept\"] = [mimeType, this.headers[\"Accept\"]].join(\", \");\n }\n\n async #allowRequestToBeIntercepted(fetchOptions) {\n const requestInterception = new Promise((resolve) => (this.#resolveRequestPromise = resolve));\n const event = dispatch(\"turbo:before-fetch-request\", {\n cancelable: true,\n detail: {\n fetchOptions,\n url: this.url,\n resume: this.#resolveRequestPromise\n },\n target: this.target\n });\n this.url = event.detail.url;\n if (event.defaultPrevented) await requestInterception;\n\n return event\n }\n\n #willDelegateErrorHandling(error) {\n const event = dispatch(\"turbo:fetch-request-error\", {\n target: this.target,\n cancelable: true,\n detail: { request: this, error: error }\n });\n\n return !event.defaultPrevented\n }\n}\n\nfunction isSafe(fetchMethod) {\n return fetchMethodFromString(fetchMethod) == FetchMethod.get\n}\n\nfunction buildResourceAndBody(resource, method, requestBody, enctype) {\n const searchParams =\n Array.from(requestBody).length > 0 ? new URLSearchParams(entriesExcludingFiles(requestBody)) : resource.searchParams;\n\n if (isSafe(method)) {\n return [mergeIntoURLSearchParams(resource, searchParams), null]\n } else if (enctype == FetchEnctype.urlEncoded) {\n return [resource, searchParams]\n } else {\n return [resource, requestBody]\n }\n}\n\nfunction entriesExcludingFiles(requestBody) {\n const entries = [];\n\n for (const [name, value] of requestBody) {\n if (value instanceof File) continue\n else entries.push([name, value]);\n }\n\n return entries\n}\n\nfunction mergeIntoURLSearchParams(url, requestBody) {\n const searchParams = new URLSearchParams(entriesExcludingFiles(requestBody));\n\n url.search = searchParams.toString();\n\n return url\n}\n\nclass AppearanceObserver {\n started = false\n\n constructor(delegate, element) {\n this.delegate = delegate;\n this.element = element;\n this.intersectionObserver = new IntersectionObserver(this.intersect);\n }\n\n start() {\n if (!this.started) {\n this.started = true;\n this.intersectionObserver.observe(this.element);\n }\n }\n\n stop() {\n if (this.started) {\n this.started = false;\n this.intersectionObserver.unobserve(this.element);\n }\n }\n\n intersect = (entries) => {\n const lastEntry = entries.slice(-1)[0];\n if (lastEntry?.isIntersecting) {\n this.delegate.elementAppearedInViewport(this.element);\n }\n }\n}\n\nclass StreamMessage {\n static contentType = \"text/vnd.turbo-stream.html\"\n\n static wrap(message) {\n if (typeof message == \"string\") {\n return new this(createDocumentFragment(message))\n } else {\n return message\n }\n }\n\n constructor(fragment) {\n this.fragment = importStreamElements(fragment);\n }\n}\n\nfunction importStreamElements(fragment) {\n for (const element of fragment.querySelectorAll(\"turbo-stream\")) {\n const streamElement = document.importNode(element, true);\n\n for (const inertScriptElement of streamElement.templateElement.content.querySelectorAll(\"script\")) {\n inertScriptElement.replaceWith(activateScriptElement(inertScriptElement));\n }\n\n element.replaceWith(streamElement);\n }\n\n return fragment\n}\n\nconst PREFETCH_DELAY = 100;\n\nclass PrefetchCache {\n #prefetchTimeout = null\n #prefetched = null\n\n get(url) {\n if (this.#prefetched && this.#prefetched.url === url && this.#prefetched.expire > Date.now()) {\n return this.#prefetched.request\n }\n }\n\n setLater(url, request, ttl) {\n this.clear();\n\n this.#prefetchTimeout = setTimeout(() => {\n request.perform();\n this.set(url, request, ttl);\n this.#prefetchTimeout = null;\n }, PREFETCH_DELAY);\n }\n\n set(url, request, ttl) {\n this.#prefetched = { url, request, expire: new Date(new Date().getTime() + ttl) };\n }\n\n clear() {\n if (this.#prefetchTimeout) clearTimeout(this.#prefetchTimeout);\n this.#prefetched = null;\n }\n}\n\nconst cacheTtl = 10 * 1000;\nconst prefetchCache = new PrefetchCache();\n\nconst FormSubmissionState = {\n initialized: \"initialized\",\n requesting: \"requesting\",\n waiting: \"waiting\",\n receiving: \"receiving\",\n stopping: \"stopping\",\n stopped: \"stopped\"\n};\n\nclass FormSubmission {\n state = FormSubmissionState.initialized\n\n static confirmMethod(message) {\n return Promise.resolve(confirm(message))\n }\n\n constructor(delegate, formElement, submitter, mustRedirect = false) {\n const method = getMethod(formElement, submitter);\n const action = getAction(getFormAction(formElement, submitter), method);\n const body = buildFormData(formElement, submitter);\n const enctype = getEnctype(formElement, submitter);\n\n this.delegate = delegate;\n this.formElement = formElement;\n this.submitter = submitter;\n this.fetchRequest = new FetchRequest(this, method, action, body, formElement, enctype);\n this.mustRedirect = mustRedirect;\n }\n\n get method() {\n return this.fetchRequest.method\n }\n\n set method(value) {\n this.fetchRequest.method = value;\n }\n\n get action() {\n return this.fetchRequest.url.toString()\n }\n\n set action(value) {\n this.fetchRequest.url = expandURL(value);\n }\n\n get body() {\n return this.fetchRequest.body\n }\n\n get enctype() {\n return this.fetchRequest.enctype\n }\n\n get isSafe() {\n return this.fetchRequest.isSafe\n }\n\n get location() {\n return this.fetchRequest.url\n }\n\n // The submission process\n\n async start() {\n const { initialized, requesting } = FormSubmissionState;\n const confirmationMessage = getAttribute(\"data-turbo-confirm\", this.submitter, this.formElement);\n\n if (typeof confirmationMessage === \"string\") {\n const confirmMethod = typeof config.forms.confirm === \"function\" ?\n config.forms.confirm :\n FormSubmission.confirmMethod;\n\n const answer = await confirmMethod(confirmationMessage, this.formElement, this.submitter);\n if (!answer) {\n return\n }\n }\n\n if (this.state == initialized) {\n this.state = requesting;\n return this.fetchRequest.perform()\n }\n }\n\n stop() {\n const { stopping, stopped } = FormSubmissionState;\n if (this.state != stopping && this.state != stopped) {\n this.state = stopping;\n this.fetchRequest.cancel();\n return true\n }\n }\n\n // Fetch request delegate\n\n prepareRequest(request) {\n if (!request.isSafe) {\n const token = getCookieValue(getMetaContent(\"csrf-param\")) || getMetaContent(\"csrf-token\");\n if (token) {\n request.headers[\"X-CSRF-Token\"] = token;\n }\n }\n\n if (this.requestAcceptsTurboStreamResponse(request)) {\n request.acceptResponseType(StreamMessage.contentType);\n }\n }\n\n requestStarted(_request) {\n this.state = FormSubmissionState.waiting;\n if (this.submitter) config.forms.submitter.beforeSubmit(this.submitter);\n this.setSubmitsWith();\n markAsBusy(this.formElement);\n dispatch(\"turbo:submit-start\", {\n target: this.formElement,\n detail: { formSubmission: this }\n });\n this.delegate.formSubmissionStarted(this);\n }\n\n requestPreventedHandlingResponse(request, response) {\n prefetchCache.clear();\n\n this.result = { success: response.succeeded, fetchResponse: response };\n }\n\n requestSucceededWithResponse(request, response) {\n if (response.clientError || response.serverError) {\n this.delegate.formSubmissionFailedWithResponse(this, response);\n return\n }\n\n prefetchCache.clear();\n\n if (this.requestMustRedirect(request) && responseSucceededWithoutRedirect(response)) {\n const error = new Error(\"Form responses must redirect to another location\");\n this.delegate.formSubmissionErrored(this, error);\n } else {\n this.state = FormSubmissionState.receiving;\n this.result = { success: true, fetchResponse: response };\n this.delegate.formSubmissionSucceededWithResponse(this, response);\n }\n }\n\n requestFailedWithResponse(request, response) {\n this.result = { success: false, fetchResponse: response };\n this.delegate.formSubmissionFailedWithResponse(this, response);\n }\n\n requestErrored(request, error) {\n this.result = { success: false, error };\n this.delegate.formSubmissionErrored(this, error);\n }\n\n requestFinished(_request) {\n this.state = FormSubmissionState.stopped;\n if (this.submitter) config.forms.submitter.afterSubmit(this.submitter);\n this.resetSubmitterText();\n clearBusyState(this.formElement);\n dispatch(\"turbo:submit-end\", {\n target: this.formElement,\n detail: { formSubmission: this, ...this.result }\n });\n this.delegate.formSubmissionFinished(this);\n }\n\n // Private\n\n setSubmitsWith() {\n if (!this.submitter || !this.submitsWith) return\n\n if (this.submitter.matches(\"button\")) {\n this.originalSubmitText = this.submitter.innerHTML;\n this.submitter.innerHTML = this.submitsWith;\n } else if (this.submitter.matches(\"input\")) {\n const input = this.submitter;\n this.originalSubmitText = input.value;\n input.value = this.submitsWith;\n }\n }\n\n resetSubmitterText() {\n if (!this.submitter || !this.originalSubmitText) return\n\n if (this.submitter.matches(\"button\")) {\n this.submitter.innerHTML = this.originalSubmitText;\n } else if (this.submitter.matches(\"input\")) {\n const input = this.submitter;\n input.value = this.originalSubmitText;\n }\n }\n\n requestMustRedirect(request) {\n return !request.isSafe && this.mustRedirect\n }\n\n requestAcceptsTurboStreamResponse(request) {\n return !request.isSafe || hasAttribute(\"data-turbo-stream\", this.submitter, this.formElement)\n }\n\n get submitsWith() {\n return this.submitter?.getAttribute(\"data-turbo-submits-with\")\n }\n}\n\nfunction buildFormData(formElement, submitter) {\n const formData = new FormData(formElement);\n const name = submitter?.getAttribute(\"name\");\n const value = submitter?.getAttribute(\"value\");\n\n if (name) {\n formData.append(name, value || \"\");\n }\n\n return formData\n}\n\nfunction getCookieValue(cookieName) {\n if (cookieName != null) {\n const cookies = document.cookie ? document.cookie.split(\"; \") : [];\n const cookie = cookies.find((cookie) => cookie.startsWith(cookieName));\n if (cookie) {\n const value = cookie.split(\"=\").slice(1).join(\"=\");\n return value ? decodeURIComponent(value) : undefined\n }\n }\n}\n\nfunction responseSucceededWithoutRedirect(response) {\n return response.statusCode == 200 && !response.redirected\n}\n\nfunction getFormAction(formElement, submitter) {\n const formElementAction = typeof formElement.action === \"string\" ? formElement.action : null;\n\n if (submitter?.hasAttribute(\"formaction\")) {\n return submitter.getAttribute(\"formaction\") || \"\"\n } else {\n return formElement.getAttribute(\"action\") || formElementAction || \"\"\n }\n}\n\nfunction getAction(formAction, fetchMethod) {\n const action = expandURL(formAction);\n\n if (isSafe(fetchMethod)) {\n action.search = \"\";\n }\n\n return action\n}\n\nfunction getMethod(formElement, submitter) {\n const method = submitter?.getAttribute(\"formmethod\") || formElement.getAttribute(\"method\") || \"\";\n return fetchMethodFromString(method.toLowerCase()) || FetchMethod.get\n}\n\nfunction getEnctype(formElement, submitter) {\n return fetchEnctypeFromString(submitter?.getAttribute(\"formenctype\") || formElement.enctype)\n}\n\nclass Snapshot {\n constructor(element) {\n this.element = element;\n }\n\n get activeElement() {\n return this.element.ownerDocument.activeElement\n }\n\n get children() {\n return [...this.element.children]\n }\n\n hasAnchor(anchor) {\n return this.getElementForAnchor(anchor) != null\n }\n\n getElementForAnchor(anchor) {\n return anchor ? this.element.querySelector(`[id='${anchor}'], a[name='${anchor}']`) : null\n }\n\n get isConnected() {\n return this.element.isConnected\n }\n\n get firstAutofocusableElement() {\n return queryAutofocusableElement(this.element)\n }\n\n get permanentElements() {\n return queryPermanentElementsAll(this.element)\n }\n\n getPermanentElementById(id) {\n return getPermanentElementById(this.element, id)\n }\n\n getPermanentElementMapForSnapshot(snapshot) {\n const permanentElementMap = {};\n\n for (const currentPermanentElement of this.permanentElements) {\n const { id } = currentPermanentElement;\n const newPermanentElement = snapshot.getPermanentElementById(id);\n if (newPermanentElement) {\n permanentElementMap[id] = [currentPermanentElement, newPermanentElement];\n }\n }\n\n return permanentElementMap\n }\n}\n\nfunction getPermanentElementById(node, id) {\n return node.querySelector(`#${id}[data-turbo-permanent]`)\n}\n\nfunction queryPermanentElementsAll(node) {\n return node.querySelectorAll(\"[id][data-turbo-permanent]\")\n}\n\nclass FormSubmitObserver {\n started = false\n\n constructor(delegate, eventTarget) {\n this.delegate = delegate;\n this.eventTarget = eventTarget;\n }\n\n start() {\n if (!this.started) {\n this.eventTarget.addEventListener(\"submit\", this.submitCaptured, true);\n this.started = true;\n }\n }\n\n stop() {\n if (this.started) {\n this.eventTarget.removeEventListener(\"submit\", this.submitCaptured, true);\n this.started = false;\n }\n }\n\n submitCaptured = () => {\n this.eventTarget.removeEventListener(\"submit\", this.submitBubbled, false);\n this.eventTarget.addEventListener(\"submit\", this.submitBubbled, false);\n }\n\n submitBubbled = (event) => {\n if (!event.defaultPrevented) {\n const form = event.target instanceof HTMLFormElement ? event.target : undefined;\n const submitter = event.submitter || undefined;\n\n if (\n form &&\n submissionDoesNotDismissDialog(form, submitter) &&\n submissionDoesNotTargetIFrame(form, submitter) &&\n this.delegate.willSubmitForm(form, submitter)\n ) {\n event.preventDefault();\n event.stopImmediatePropagation();\n this.delegate.formSubmitted(form, submitter);\n }\n }\n }\n}\n\nfunction submissionDoesNotDismissDialog(form, submitter) {\n const method = submitter?.getAttribute(\"formmethod\") || form.getAttribute(\"method\");\n\n return method != \"dialog\"\n}\n\nfunction submissionDoesNotTargetIFrame(form, submitter) {\n const target = submitter?.getAttribute(\"formtarget\") || form.getAttribute(\"target\");\n\n return doesNotTargetIFrame(target)\n}\n\nclass View {\n #resolveRenderPromise = (_value) => {}\n #resolveInterceptionPromise = (_value) => {}\n\n constructor(delegate, element) {\n this.delegate = delegate;\n this.element = element;\n }\n\n // Scrolling\n\n scrollToAnchor(anchor) {\n const element = this.snapshot.getElementForAnchor(anchor);\n if (element) {\n this.scrollToElement(element);\n this.focusElement(element);\n } else {\n this.scrollToPosition({ x: 0, y: 0 });\n }\n }\n\n scrollToAnchorFromLocation(location) {\n this.scrollToAnchor(getAnchor(location));\n }\n\n scrollToElement(element) {\n element.scrollIntoView();\n }\n\n focusElement(element) {\n if (element instanceof HTMLElement) {\n if (element.hasAttribute(\"tabindex\")) {\n element.focus();\n } else {\n element.setAttribute(\"tabindex\", \"-1\");\n element.focus();\n element.removeAttribute(\"tabindex\");\n }\n }\n }\n\n scrollToPosition({ x, y }) {\n this.scrollRoot.scrollTo(x, y);\n }\n\n scrollToTop() {\n this.scrollToPosition({ x: 0, y: 0 });\n }\n\n get scrollRoot() {\n return window\n }\n\n // Rendering\n\n async render(renderer) {\n const { isPreview, shouldRender, willRender, newSnapshot: snapshot } = renderer;\n\n // A workaround to ignore tracked element mismatch reloads when performing\n // a promoted Visit from a frame navigation\n const shouldInvalidate = willRender;\n\n if (shouldRender) {\n try {\n this.renderPromise = new Promise((resolve) => (this.#resolveRenderPromise = resolve));\n this.renderer = renderer;\n await this.prepareToRenderSnapshot(renderer);\n\n const renderInterception = new Promise((resolve) => (this.#resolveInterceptionPromise = resolve));\n const options = { resume: this.#resolveInterceptionPromise, render: this.renderer.renderElement, renderMethod: this.renderer.renderMethod };\n const immediateRender = this.delegate.allowsImmediateRender(snapshot, options);\n if (!immediateRender) await renderInterception;\n\n await this.renderSnapshot(renderer);\n this.delegate.viewRenderedSnapshot(snapshot, isPreview, this.renderer.renderMethod);\n this.delegate.preloadOnLoadLinksForView(this.element);\n this.finishRenderingSnapshot(renderer);\n } finally {\n delete this.renderer;\n this.#resolveRenderPromise(undefined);\n delete this.renderPromise;\n }\n } else if (shouldInvalidate) {\n this.invalidate(renderer.reloadReason);\n }\n }\n\n invalidate(reason) {\n this.delegate.viewInvalidated(reason);\n }\n\n async prepareToRenderSnapshot(renderer) {\n this.markAsPreview(renderer.isPreview);\n await renderer.prepareToRender();\n }\n\n markAsPreview(isPreview) {\n if (isPreview) {\n this.element.setAttribute(\"data-turbo-preview\", \"\");\n } else {\n this.element.removeAttribute(\"data-turbo-preview\");\n }\n }\n\n markVisitDirection(direction) {\n this.element.setAttribute(\"data-turbo-visit-direction\", direction);\n }\n\n unmarkVisitDirection() {\n this.element.removeAttribute(\"data-turbo-visit-direction\");\n }\n\n async renderSnapshot(renderer) {\n await renderer.render();\n }\n\n finishRenderingSnapshot(renderer) {\n renderer.finishRendering();\n }\n}\n\nclass FrameView extends View {\n missing() {\n this.element.innerHTML = `Content missing`;\n }\n\n get snapshot() {\n return new Snapshot(this.element)\n }\n}\n\nclass LinkInterceptor {\n constructor(delegate, element) {\n this.delegate = delegate;\n this.element = element;\n }\n\n start() {\n this.element.addEventListener(\"click\", this.clickBubbled);\n document.addEventListener(\"turbo:click\", this.linkClicked);\n document.addEventListener(\"turbo:before-visit\", this.willVisit);\n }\n\n stop() {\n this.element.removeEventListener(\"click\", this.clickBubbled);\n document.removeEventListener(\"turbo:click\", this.linkClicked);\n document.removeEventListener(\"turbo:before-visit\", this.willVisit);\n }\n\n clickBubbled = (event) => {\n if (this.clickEventIsSignificant(event)) {\n this.clickEvent = event;\n } else {\n delete this.clickEvent;\n }\n }\n\n linkClicked = (event) => {\n if (this.clickEvent && this.clickEventIsSignificant(event)) {\n if (this.delegate.shouldInterceptLinkClick(event.target, event.detail.url, event.detail.originalEvent)) {\n this.clickEvent.preventDefault();\n event.preventDefault();\n this.delegate.linkClickIntercepted(event.target, event.detail.url, event.detail.originalEvent);\n }\n }\n delete this.clickEvent;\n }\n\n willVisit = (_event) => {\n delete this.clickEvent;\n }\n\n clickEventIsSignificant(event) {\n const target = event.composed ? event.target?.parentElement : event.target;\n const element = findLinkFromClickTarget(target) || target;\n\n return element instanceof Element && element.closest(\"turbo-frame, html\") == this.element\n }\n}\n\nclass LinkClickObserver {\n started = false\n\n constructor(delegate, eventTarget) {\n this.delegate = delegate;\n this.eventTarget = eventTarget;\n }\n\n start() {\n if (!this.started) {\n this.eventTarget.addEventListener(\"click\", this.clickCaptured, true);\n this.started = true;\n }\n }\n\n stop() {\n if (this.started) {\n this.eventTarget.removeEventListener(\"click\", this.clickCaptured, true);\n this.started = false;\n }\n }\n\n clickCaptured = () => {\n this.eventTarget.removeEventListener(\"click\", this.clickBubbled, false);\n this.eventTarget.addEventListener(\"click\", this.clickBubbled, false);\n }\n\n clickBubbled = (event) => {\n if (event instanceof MouseEvent && this.clickEventIsSignificant(event)) {\n const target = (event.composedPath && event.composedPath()[0]) || event.target;\n const link = findLinkFromClickTarget(target);\n if (link && doesNotTargetIFrame(link.target)) {\n const location = getLocationForLink(link);\n if (this.delegate.willFollowLinkToLocation(link, location, event)) {\n event.preventDefault();\n this.delegate.followedLinkToLocation(link, location);\n }\n }\n }\n }\n\n clickEventIsSignificant(event) {\n return !(\n (event.target && event.target.isContentEditable) ||\n event.defaultPrevented ||\n event.which > 1 ||\n event.altKey ||\n event.ctrlKey ||\n event.metaKey ||\n event.shiftKey\n )\n }\n}\n\nclass FormLinkClickObserver {\n constructor(delegate, element) {\n this.delegate = delegate;\n this.linkInterceptor = new LinkClickObserver(this, element);\n }\n\n start() {\n this.linkInterceptor.start();\n }\n\n stop() {\n this.linkInterceptor.stop();\n }\n\n // Link hover observer delegate\n\n canPrefetchRequestToLocation(link, location) {\n return false\n }\n\n prefetchAndCacheRequestToLocation(link, location) {\n return\n }\n\n // Link click observer delegate\n\n willFollowLinkToLocation(link, location, originalEvent) {\n return (\n this.delegate.willSubmitFormLinkToLocation(link, location, originalEvent) &&\n (link.hasAttribute(\"data-turbo-method\") || link.hasAttribute(\"data-turbo-stream\"))\n )\n }\n\n followedLinkToLocation(link, location) {\n const form = document.createElement(\"form\");\n\n const type = \"hidden\";\n for (const [name, value] of location.searchParams) {\n form.append(Object.assign(document.createElement(\"input\"), { type, name, value }));\n }\n\n const action = Object.assign(location, { search: \"\" });\n form.setAttribute(\"data-turbo\", \"true\");\n form.setAttribute(\"action\", action.href);\n form.setAttribute(\"hidden\", \"\");\n\n const method = link.getAttribute(\"data-turbo-method\");\n if (method) form.setAttribute(\"method\", method);\n\n const turboFrame = link.getAttribute(\"data-turbo-frame\");\n if (turboFrame) form.setAttribute(\"data-turbo-frame\", turboFrame);\n\n const turboAction = getVisitAction(link);\n if (turboAction) form.setAttribute(\"data-turbo-action\", turboAction);\n\n const turboConfirm = link.getAttribute(\"data-turbo-confirm\");\n if (turboConfirm) form.setAttribute(\"data-turbo-confirm\", turboConfirm);\n\n const turboStream = link.hasAttribute(\"data-turbo-stream\");\n if (turboStream) form.setAttribute(\"data-turbo-stream\", \"\");\n\n this.delegate.submittedFormLinkToLocation(link, location, form);\n\n document.body.appendChild(form);\n form.addEventListener(\"turbo:submit-end\", () => form.remove(), { once: true });\n requestAnimationFrame(() => form.requestSubmit());\n }\n}\n\nclass Bardo {\n static async preservingPermanentElements(delegate, permanentElementMap, callback) {\n const bardo = new this(delegate, permanentElementMap);\n bardo.enter();\n await callback();\n bardo.leave();\n }\n\n constructor(delegate, permanentElementMap) {\n this.delegate = delegate;\n this.permanentElementMap = permanentElementMap;\n }\n\n enter() {\n for (const id in this.permanentElementMap) {\n const [currentPermanentElement, newPermanentElement] = this.permanentElementMap[id];\n this.delegate.enteringBardo(currentPermanentElement, newPermanentElement);\n this.replaceNewPermanentElementWithPlaceholder(newPermanentElement);\n }\n }\n\n leave() {\n for (const id in this.permanentElementMap) {\n const [currentPermanentElement] = this.permanentElementMap[id];\n this.replaceCurrentPermanentElementWithClone(currentPermanentElement);\n this.replacePlaceholderWithPermanentElement(currentPermanentElement);\n this.delegate.leavingBardo(currentPermanentElement);\n }\n }\n\n replaceNewPermanentElementWithPlaceholder(permanentElement) {\n const placeholder = createPlaceholderForPermanentElement(permanentElement);\n permanentElement.replaceWith(placeholder);\n }\n\n replaceCurrentPermanentElementWithClone(permanentElement) {\n const clone = permanentElement.cloneNode(true);\n permanentElement.replaceWith(clone);\n }\n\n replacePlaceholderWithPermanentElement(permanentElement) {\n const placeholder = this.getPlaceholderById(permanentElement.id);\n placeholder?.replaceWith(permanentElement);\n }\n\n getPlaceholderById(id) {\n return this.placeholders.find((element) => element.content == id)\n }\n\n get placeholders() {\n return [...document.querySelectorAll(\"meta[name=turbo-permanent-placeholder][content]\")]\n }\n}\n\nfunction createPlaceholderForPermanentElement(permanentElement) {\n const element = document.createElement(\"meta\");\n element.setAttribute(\"name\", \"turbo-permanent-placeholder\");\n element.setAttribute(\"content\", permanentElement.id);\n return element\n}\n\nclass Renderer {\n #activeElement = null\n\n static renderElement(currentElement, newElement) {\n // Abstract method\n }\n\n constructor(currentSnapshot, newSnapshot, isPreview, willRender = true) {\n this.currentSnapshot = currentSnapshot;\n this.newSnapshot = newSnapshot;\n this.isPreview = isPreview;\n this.willRender = willRender;\n this.renderElement = this.constructor.renderElement;\n this.promise = new Promise((resolve, reject) => (this.resolvingFunctions = { resolve, reject }));\n }\n\n get shouldRender() {\n return true\n }\n\n get shouldAutofocus() {\n return true\n }\n\n get reloadReason() {\n return\n }\n\n prepareToRender() {\n return\n }\n\n render() {\n // Abstract method\n }\n\n finishRendering() {\n if (this.resolvingFunctions) {\n this.resolvingFunctions.resolve();\n delete this.resolvingFunctions;\n }\n }\n\n async preservingPermanentElements(callback) {\n await Bardo.preservingPermanentElements(this, this.permanentElementMap, callback);\n }\n\n focusFirstAutofocusableElement() {\n if (this.shouldAutofocus) {\n const element = this.connectedSnapshot.firstAutofocusableElement;\n if (element) {\n element.focus();\n }\n }\n }\n\n // Bardo delegate\n\n enteringBardo(currentPermanentElement) {\n if (this.#activeElement) return\n\n if (currentPermanentElement.contains(this.currentSnapshot.activeElement)) {\n this.#activeElement = this.currentSnapshot.activeElement;\n }\n }\n\n leavingBardo(currentPermanentElement) {\n if (currentPermanentElement.contains(this.#activeElement) && this.#activeElement instanceof HTMLElement) {\n this.#activeElement.focus();\n\n this.#activeElement = null;\n }\n }\n\n get connectedSnapshot() {\n return this.newSnapshot.isConnected ? this.newSnapshot : this.currentSnapshot\n }\n\n get currentElement() {\n return this.currentSnapshot.element\n }\n\n get newElement() {\n return this.newSnapshot.element\n }\n\n get permanentElementMap() {\n return this.currentSnapshot.getPermanentElementMapForSnapshot(this.newSnapshot)\n }\n\n get renderMethod() {\n return \"replace\"\n }\n}\n\nclass FrameRenderer extends Renderer {\n static renderElement(currentElement, newElement) {\n const destinationRange = document.createRange();\n destinationRange.selectNodeContents(currentElement);\n destinationRange.deleteContents();\n\n const frameElement = newElement;\n const sourceRange = frameElement.ownerDocument?.createRange();\n if (sourceRange) {\n sourceRange.selectNodeContents(frameElement);\n currentElement.appendChild(sourceRange.extractContents());\n }\n }\n\n constructor(delegate, currentSnapshot, newSnapshot, renderElement, isPreview, willRender = true) {\n super(currentSnapshot, newSnapshot, renderElement, isPreview, willRender);\n this.delegate = delegate;\n }\n\n get shouldRender() {\n return true\n }\n\n async render() {\n await nextRepaint();\n this.preservingPermanentElements(() => {\n this.loadFrameElement();\n });\n this.scrollFrameIntoView();\n await nextRepaint();\n this.focusFirstAutofocusableElement();\n await nextRepaint();\n this.activateScriptElements();\n }\n\n loadFrameElement() {\n this.delegate.willRenderFrame(this.currentElement, this.newElement);\n this.renderElement(this.currentElement, this.newElement);\n }\n\n scrollFrameIntoView() {\n if (this.currentElement.autoscroll || this.newElement.autoscroll) {\n const element = this.currentElement.firstElementChild;\n const block = readScrollLogicalPosition(this.currentElement.getAttribute(\"data-autoscroll-block\"), \"end\");\n const behavior = readScrollBehavior(this.currentElement.getAttribute(\"data-autoscroll-behavior\"), \"auto\");\n\n if (element) {\n element.scrollIntoView({ block, behavior });\n return true\n }\n }\n return false\n }\n\n activateScriptElements() {\n for (const inertScriptElement of this.newScriptElements) {\n const activatedScriptElement = activateScriptElement(inertScriptElement);\n inertScriptElement.replaceWith(activatedScriptElement);\n }\n }\n\n get newScriptElements() {\n return this.currentElement.querySelectorAll(\"script\")\n }\n}\n\nfunction readScrollLogicalPosition(value, defaultValue) {\n if (value == \"end\" || value == \"start\" || value == \"center\" || value == \"nearest\") {\n return value\n } else {\n return defaultValue\n }\n}\n\nfunction readScrollBehavior(value, defaultValue) {\n if (value == \"auto\" || value == \"smooth\") {\n return value\n } else {\n return defaultValue\n }\n}\n\n// base IIFE to define idiomorph\nvar Idiomorph = (function () {\n\n //=============================================================================\n // AND NOW IT BEGINS...\n //=============================================================================\n let EMPTY_SET = new Set();\n\n // default configuration values, updatable by users now\n let defaults = {\n morphStyle: \"outerHTML\",\n callbacks : {\n beforeNodeAdded: noOp,\n afterNodeAdded: noOp,\n beforeNodeMorphed: noOp,\n afterNodeMorphed: noOp,\n beforeNodeRemoved: noOp,\n afterNodeRemoved: noOp,\n beforeAttributeUpdated: noOp,\n\n },\n head: {\n style: 'merge',\n shouldPreserve: function (elt) {\n return elt.getAttribute(\"im-preserve\") === \"true\";\n },\n shouldReAppend: function (elt) {\n return elt.getAttribute(\"im-re-append\") === \"true\";\n },\n shouldRemove: noOp,\n afterHeadMorphed: noOp,\n }\n };\n\n //=============================================================================\n // Core Morphing Algorithm - morph, morphNormalizedContent, morphOldNodeTo, morphChildren\n //=============================================================================\n function morph(oldNode, newContent, config = {}) {\n\n if (oldNode instanceof Document) {\n oldNode = oldNode.documentElement;\n }\n\n if (typeof newContent === 'string') {\n newContent = parseContent(newContent);\n }\n\n let normalizedContent = normalizeContent(newContent);\n\n let ctx = createMorphContext(oldNode, normalizedContent, config);\n\n return morphNormalizedContent(oldNode, normalizedContent, ctx);\n }\n\n function morphNormalizedContent(oldNode, normalizedNewContent, ctx) {\n if (ctx.head.block) {\n let oldHead = oldNode.querySelector('head');\n let newHead = normalizedNewContent.querySelector('head');\n if (oldHead && newHead) {\n let promises = handleHeadElement(newHead, oldHead, ctx);\n // when head promises resolve, call morph again, ignoring the head tag\n Promise.all(promises).then(function () {\n morphNormalizedContent(oldNode, normalizedNewContent, Object.assign(ctx, {\n head: {\n block: false,\n ignore: true\n }\n }));\n });\n return;\n }\n }\n\n if (ctx.morphStyle === \"innerHTML\") {\n\n // innerHTML, so we are only updating the children\n morphChildren(normalizedNewContent, oldNode, ctx);\n return oldNode.children;\n\n } else if (ctx.morphStyle === \"outerHTML\" || ctx.morphStyle == null) {\n // otherwise find the best element match in the new content, morph that, and merge its siblings\n // into either side of the best match\n let bestMatch = findBestNodeMatch(normalizedNewContent, oldNode, ctx);\n\n // stash the siblings that will need to be inserted on either side of the best match\n let previousSibling = bestMatch?.previousSibling;\n let nextSibling = bestMatch?.nextSibling;\n\n // morph it\n let morphedNode = morphOldNodeTo(oldNode, bestMatch, ctx);\n\n if (bestMatch) {\n // if there was a best match, merge the siblings in too and return the\n // whole bunch\n return insertSiblings(previousSibling, morphedNode, nextSibling);\n } else {\n // otherwise nothing was added to the DOM\n return []\n }\n } else {\n throw \"Do not understand how to morph style \" + ctx.morphStyle;\n }\n }\n\n\n /**\n * @param possibleActiveElement\n * @param ctx\n * @returns {boolean}\n */\n function ignoreValueOfActiveElement(possibleActiveElement, ctx) {\n return ctx.ignoreActiveValue && possibleActiveElement === document.activeElement && possibleActiveElement !== document.body;\n }\n\n /**\n * @param oldNode root node to merge content into\n * @param newContent new content to merge\n * @param ctx the merge context\n * @returns {Element} the element that ended up in the DOM\n */\n function morphOldNodeTo(oldNode, newContent, ctx) {\n if (ctx.ignoreActive && oldNode === document.activeElement) ; else if (newContent == null) {\n if (ctx.callbacks.beforeNodeRemoved(oldNode) === false) return oldNode;\n\n oldNode.remove();\n ctx.callbacks.afterNodeRemoved(oldNode);\n return null;\n } else if (!isSoftMatch(oldNode, newContent)) {\n if (ctx.callbacks.beforeNodeRemoved(oldNode) === false) return oldNode;\n if (ctx.callbacks.beforeNodeAdded(newContent) === false) return oldNode;\n\n oldNode.parentElement.replaceChild(newContent, oldNode);\n ctx.callbacks.afterNodeAdded(newContent);\n ctx.callbacks.afterNodeRemoved(oldNode);\n return newContent;\n } else {\n if (ctx.callbacks.beforeNodeMorphed(oldNode, newContent) === false) return oldNode;\n\n if (oldNode instanceof HTMLHeadElement && ctx.head.ignore) ; else if (oldNode instanceof HTMLHeadElement && ctx.head.style !== \"morph\") {\n handleHeadElement(newContent, oldNode, ctx);\n } else {\n syncNodeFrom(newContent, oldNode, ctx);\n if (!ignoreValueOfActiveElement(oldNode, ctx)) {\n morphChildren(newContent, oldNode, ctx);\n }\n }\n ctx.callbacks.afterNodeMorphed(oldNode, newContent);\n return oldNode;\n }\n }\n\n /**\n * This is the core algorithm for matching up children. The idea is to use id sets to try to match up\n * nodes as faithfully as possible. We greedily match, which allows us to keep the algorithm fast, but\n * by using id sets, we are able to better match up with content deeper in the DOM.\n *\n * Basic algorithm is, for each node in the new content:\n *\n * - if we have reached the end of the old parent, append the new content\n * - if the new content has an id set match with the current insertion point, morph\n * - search for an id set match\n * - if id set match found, morph\n * - otherwise search for a \"soft\" match\n * - if a soft match is found, morph\n * - otherwise, prepend the new node before the current insertion point\n *\n * The two search algorithms terminate if competing node matches appear to outweigh what can be achieved\n * with the current node. See findIdSetMatch() and findSoftMatch() for details.\n *\n * @param {Element} newParent the parent element of the new content\n * @param {Element } oldParent the old content that we are merging the new content into\n * @param ctx the merge context\n */\n function morphChildren(newParent, oldParent, ctx) {\n\n let nextNewChild = newParent.firstChild;\n let insertionPoint = oldParent.firstChild;\n let newChild;\n\n // run through all the new content\n while (nextNewChild) {\n\n newChild = nextNewChild;\n nextNewChild = newChild.nextSibling;\n\n // if we are at the end of the exiting parent's children, just append\n if (insertionPoint == null) {\n if (ctx.callbacks.beforeNodeAdded(newChild) === false) return;\n\n oldParent.appendChild(newChild);\n ctx.callbacks.afterNodeAdded(newChild);\n removeIdsFromConsideration(ctx, newChild);\n continue;\n }\n\n // if the current node has an id set match then morph\n if (isIdSetMatch(newChild, insertionPoint, ctx)) {\n morphOldNodeTo(insertionPoint, newChild, ctx);\n insertionPoint = insertionPoint.nextSibling;\n removeIdsFromConsideration(ctx, newChild);\n continue;\n }\n\n // otherwise search forward in the existing old children for an id set match\n let idSetMatch = findIdSetMatch(newParent, oldParent, newChild, insertionPoint, ctx);\n\n // if we found a potential match, remove the nodes until that point and morph\n if (idSetMatch) {\n insertionPoint = removeNodesBetween(insertionPoint, idSetMatch, ctx);\n morphOldNodeTo(idSetMatch, newChild, ctx);\n removeIdsFromConsideration(ctx, newChild);\n continue;\n }\n\n // no id set match found, so scan forward for a soft match for the current node\n let softMatch = findSoftMatch(newParent, oldParent, newChild, insertionPoint, ctx);\n\n // if we found a soft match for the current node, morph\n if (softMatch) {\n insertionPoint = removeNodesBetween(insertionPoint, softMatch, ctx);\n morphOldNodeTo(softMatch, newChild, ctx);\n removeIdsFromConsideration(ctx, newChild);\n continue;\n }\n\n // abandon all hope of morphing, just insert the new child before the insertion point\n // and move on\n if (ctx.callbacks.beforeNodeAdded(newChild) === false) return;\n\n oldParent.insertBefore(newChild, insertionPoint);\n ctx.callbacks.afterNodeAdded(newChild);\n removeIdsFromConsideration(ctx, newChild);\n }\n\n // remove any remaining old nodes that didn't match up with new content\n while (insertionPoint !== null) {\n\n let tempNode = insertionPoint;\n insertionPoint = insertionPoint.nextSibling;\n removeNode(tempNode, ctx);\n }\n }\n\n //=============================================================================\n // Attribute Syncing Code\n //=============================================================================\n\n /**\n * @param attr {String} the attribute to be mutated\n * @param to {Element} the element that is going to be updated\n * @param updateType {(\"update\"|\"remove\")}\n * @param ctx the merge context\n * @returns {boolean} true if the attribute should be ignored, false otherwise\n */\n function ignoreAttribute(attr, to, updateType, ctx) {\n if(attr === 'value' && ctx.ignoreActiveValue && to === document.activeElement){\n return true;\n }\n return ctx.callbacks.beforeAttributeUpdated(attr, to, updateType) === false;\n }\n\n /**\n * syncs a given node with another node, copying over all attributes and\n * inner element state from the 'from' node to the 'to' node\n *\n * @param {Element} from the element to copy attributes & state from\n * @param {Element} to the element to copy attributes & state to\n * @param ctx the merge context\n */\n function syncNodeFrom(from, to, ctx) {\n let type = from.nodeType;\n\n // if is an element type, sync the attributes from the\n // new node into the new node\n if (type === 1 /* element type */) {\n const fromAttributes = from.attributes;\n const toAttributes = to.attributes;\n for (const fromAttribute of fromAttributes) {\n if (ignoreAttribute(fromAttribute.name, to, 'update', ctx)) {\n continue;\n }\n if (to.getAttribute(fromAttribute.name) !== fromAttribute.value) {\n to.setAttribute(fromAttribute.name, fromAttribute.value);\n }\n }\n // iterate backwards to avoid skipping over items when a delete occurs\n for (let i = toAttributes.length - 1; 0 <= i; i--) {\n const toAttribute = toAttributes[i];\n if (ignoreAttribute(toAttribute.name, to, 'remove', ctx)) {\n continue;\n }\n if (!from.hasAttribute(toAttribute.name)) {\n to.removeAttribute(toAttribute.name);\n }\n }\n }\n\n // sync text nodes\n if (type === 8 /* comment */ || type === 3 /* text */) {\n if (to.nodeValue !== from.nodeValue) {\n to.nodeValue = from.nodeValue;\n }\n }\n\n if (!ignoreValueOfActiveElement(to, ctx)) {\n // sync input values\n syncInputValue(from, to, ctx);\n }\n }\n\n /**\n * @param from {Element} element to sync the value from\n * @param to {Element} element to sync the value to\n * @param attributeName {String} the attribute name\n * @param ctx the merge context\n */\n function syncBooleanAttribute(from, to, attributeName, ctx) {\n if (from[attributeName] !== to[attributeName]) {\n let ignoreUpdate = ignoreAttribute(attributeName, to, 'update', ctx);\n if (!ignoreUpdate) {\n to[attributeName] = from[attributeName];\n }\n if (from[attributeName]) {\n if (!ignoreUpdate) {\n to.setAttribute(attributeName, from[attributeName]);\n }\n } else {\n if (!ignoreAttribute(attributeName, to, 'remove', ctx)) {\n to.removeAttribute(attributeName);\n }\n }\n }\n }\n\n /**\n * NB: many bothans died to bring us information:\n *\n * https://github.com/patrick-steele-idem/morphdom/blob/master/src/specialElHandlers.js\n * https://github.com/choojs/nanomorph/blob/master/lib/morph.jsL113\n *\n * @param from {Element} the element to sync the input value from\n * @param to {Element} the element to sync the input value to\n * @param ctx the merge context\n */\n function syncInputValue(from, to, ctx) {\n if (from instanceof HTMLInputElement &&\n to instanceof HTMLInputElement &&\n from.type !== 'file') {\n\n let fromValue = from.value;\n let toValue = to.value;\n\n // sync boolean attributes\n syncBooleanAttribute(from, to, 'checked', ctx);\n syncBooleanAttribute(from, to, 'disabled', ctx);\n\n if (!from.hasAttribute('value')) {\n if (!ignoreAttribute('value', to, 'remove', ctx)) {\n to.value = '';\n to.removeAttribute('value');\n }\n } else if (fromValue !== toValue) {\n if (!ignoreAttribute('value', to, 'update', ctx)) {\n to.setAttribute('value', fromValue);\n to.value = fromValue;\n }\n }\n } else if (from instanceof HTMLOptionElement) {\n syncBooleanAttribute(from, to, 'selected', ctx);\n } else if (from instanceof HTMLTextAreaElement && to instanceof HTMLTextAreaElement) {\n let fromValue = from.value;\n let toValue = to.value;\n if (ignoreAttribute('value', to, 'update', ctx)) {\n return;\n }\n if (fromValue !== toValue) {\n to.value = fromValue;\n }\n if (to.firstChild && to.firstChild.nodeValue !== fromValue) {\n to.firstChild.nodeValue = fromValue;\n }\n }\n }\n\n //=============================================================================\n // the HEAD tag can be handled specially, either w/ a 'merge' or 'append' style\n //=============================================================================\n function handleHeadElement(newHeadTag, currentHead, ctx) {\n\n let added = [];\n let removed = [];\n let preserved = [];\n let nodesToAppend = [];\n\n let headMergeStyle = ctx.head.style;\n\n // put all new head elements into a Map, by their outerHTML\n let srcToNewHeadNodes = new Map();\n for (const newHeadChild of newHeadTag.children) {\n srcToNewHeadNodes.set(newHeadChild.outerHTML, newHeadChild);\n }\n\n // for each elt in the current head\n for (const currentHeadElt of currentHead.children) {\n\n // If the current head element is in the map\n let inNewContent = srcToNewHeadNodes.has(currentHeadElt.outerHTML);\n let isReAppended = ctx.head.shouldReAppend(currentHeadElt);\n let isPreserved = ctx.head.shouldPreserve(currentHeadElt);\n if (inNewContent || isPreserved) {\n if (isReAppended) {\n // remove the current version and let the new version replace it and re-execute\n removed.push(currentHeadElt);\n } else {\n // this element already exists and should not be re-appended, so remove it from\n // the new content map, preserving it in the DOM\n srcToNewHeadNodes.delete(currentHeadElt.outerHTML);\n preserved.push(currentHeadElt);\n }\n } else {\n if (headMergeStyle === \"append\") {\n // we are appending and this existing element is not new content\n // so if and only if it is marked for re-append do we do anything\n if (isReAppended) {\n removed.push(currentHeadElt);\n nodesToAppend.push(currentHeadElt);\n }\n } else {\n // if this is a merge, we remove this content since it is not in the new head\n if (ctx.head.shouldRemove(currentHeadElt) !== false) {\n removed.push(currentHeadElt);\n }\n }\n }\n }\n\n // Push the remaining new head elements in the Map into the\n // nodes to append to the head tag\n nodesToAppend.push(...srcToNewHeadNodes.values());\n\n let promises = [];\n for (const newNode of nodesToAppend) {\n let newElt = document.createRange().createContextualFragment(newNode.outerHTML).firstChild;\n if (ctx.callbacks.beforeNodeAdded(newElt) !== false) {\n if (newElt.href || newElt.src) {\n let resolve = null;\n let promise = new Promise(function (_resolve) {\n resolve = _resolve;\n });\n newElt.addEventListener('load', function () {\n resolve();\n });\n promises.push(promise);\n }\n currentHead.appendChild(newElt);\n ctx.callbacks.afterNodeAdded(newElt);\n added.push(newElt);\n }\n }\n\n // remove all removed elements, after we have appended the new elements to avoid\n // additional network requests for things like style sheets\n for (const removedElement of removed) {\n if (ctx.callbacks.beforeNodeRemoved(removedElement) !== false) {\n currentHead.removeChild(removedElement);\n ctx.callbacks.afterNodeRemoved(removedElement);\n }\n }\n\n ctx.head.afterHeadMorphed(currentHead, {added: added, kept: preserved, removed: removed});\n return promises;\n }\n\n function noOp() {\n }\n\n /*\n Deep merges the config object and the Idiomoroph.defaults object to\n produce a final configuration object\n */\n function mergeDefaults(config) {\n let finalConfig = {};\n // copy top level stuff into final config\n Object.assign(finalConfig, defaults);\n Object.assign(finalConfig, config);\n\n // copy callbacks into final config (do this to deep merge the callbacks)\n finalConfig.callbacks = {};\n Object.assign(finalConfig.callbacks, defaults.callbacks);\n Object.assign(finalConfig.callbacks, config.callbacks);\n\n // copy head config into final config (do this to deep merge the head)\n finalConfig.head = {};\n Object.assign(finalConfig.head, defaults.head);\n Object.assign(finalConfig.head, config.head);\n return finalConfig;\n }\n\n function createMorphContext(oldNode, newContent, config) {\n config = mergeDefaults(config);\n return {\n target: oldNode,\n newContent: newContent,\n config: config,\n morphStyle: config.morphStyle,\n ignoreActive: config.ignoreActive,\n ignoreActiveValue: config.ignoreActiveValue,\n idMap: createIdMap(oldNode, newContent),\n deadIds: new Set(),\n callbacks: config.callbacks,\n head: config.head\n }\n }\n\n function isIdSetMatch(node1, node2, ctx) {\n if (node1 == null || node2 == null) {\n return false;\n }\n if (node1.nodeType === node2.nodeType && node1.tagName === node2.tagName) {\n if (node1.id !== \"\" && node1.id === node2.id) {\n return true;\n } else {\n return getIdIntersectionCount(ctx, node1, node2) > 0;\n }\n }\n return false;\n }\n\n function isSoftMatch(node1, node2) {\n if (node1 == null || node2 == null) {\n return false;\n }\n return node1.nodeType === node2.nodeType && node1.tagName === node2.tagName\n }\n\n function removeNodesBetween(startInclusive, endExclusive, ctx) {\n while (startInclusive !== endExclusive) {\n let tempNode = startInclusive;\n startInclusive = startInclusive.nextSibling;\n removeNode(tempNode, ctx);\n }\n removeIdsFromConsideration(ctx, endExclusive);\n return endExclusive.nextSibling;\n }\n\n //=============================================================================\n // Scans forward from the insertionPoint in the old parent looking for a potential id match\n // for the newChild. We stop if we find a potential id match for the new child OR\n // if the number of potential id matches we are discarding is greater than the\n // potential id matches for the new child\n //=============================================================================\n function findIdSetMatch(newContent, oldParent, newChild, insertionPoint, ctx) {\n\n // max id matches we are willing to discard in our search\n let newChildPotentialIdCount = getIdIntersectionCount(ctx, newChild, oldParent);\n\n let potentialMatch = null;\n\n // only search forward if there is a possibility of an id match\n if (newChildPotentialIdCount > 0) {\n let potentialMatch = insertionPoint;\n // if there is a possibility of an id match, scan forward\n // keep track of the potential id match count we are discarding (the\n // newChildPotentialIdCount must be greater than this to make it likely\n // worth it)\n let otherMatchCount = 0;\n while (potentialMatch != null) {\n\n // If we have an id match, return the current potential match\n if (isIdSetMatch(newChild, potentialMatch, ctx)) {\n return potentialMatch;\n }\n\n // computer the other potential matches of this new content\n otherMatchCount += getIdIntersectionCount(ctx, potentialMatch, newContent);\n if (otherMatchCount > newChildPotentialIdCount) {\n // if we have more potential id matches in _other_ content, we\n // do not have a good candidate for an id match, so return null\n return null;\n }\n\n // advanced to the next old content child\n potentialMatch = potentialMatch.nextSibling;\n }\n }\n return potentialMatch;\n }\n\n //=============================================================================\n // Scans forward from the insertionPoint in the old parent looking for a potential soft match\n // for the newChild. We stop if we find a potential soft match for the new child OR\n // if we find a potential id match in the old parents children OR if we find two\n // potential soft matches for the next two pieces of new content\n //=============================================================================\n function findSoftMatch(newContent, oldParent, newChild, insertionPoint, ctx) {\n\n let potentialSoftMatch = insertionPoint;\n let nextSibling = newChild.nextSibling;\n let siblingSoftMatchCount = 0;\n\n while (potentialSoftMatch != null) {\n\n if (getIdIntersectionCount(ctx, potentialSoftMatch, newContent) > 0) {\n // the current potential soft match has a potential id set match with the remaining new\n // content so bail out of looking\n return null;\n }\n\n // if we have a soft match with the current node, return it\n if (isSoftMatch(newChild, potentialSoftMatch)) {\n return potentialSoftMatch;\n }\n\n if (isSoftMatch(nextSibling, potentialSoftMatch)) {\n // the next new node has a soft match with this node, so\n // increment the count of future soft matches\n siblingSoftMatchCount++;\n nextSibling = nextSibling.nextSibling;\n\n // If there are two future soft matches, bail to allow the siblings to soft match\n // so that we don't consume future soft matches for the sake of the current node\n if (siblingSoftMatchCount >= 2) {\n return null;\n }\n }\n\n // advanced to the next old content child\n potentialSoftMatch = potentialSoftMatch.nextSibling;\n }\n\n return potentialSoftMatch;\n }\n\n function parseContent(newContent) {\n let parser = new DOMParser();\n\n // remove svgs to avoid false-positive matches on head, etc.\n let contentWithSvgsRemoved = newContent.replace(/