(() => { var __create = Object.create; var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __getProtoOf = Object.getPrototypeOf; var __hasOwnProp = Object.prototype.hasOwnProperty; var __esm = (fn3, res) => function __init() { return fn3 && (res = (0, fn3[__getOwnPropNames(fn3)[0]])(fn3 = 0)), res; }; var __commonJS = (cb, mod) => function __require() { return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports; }; var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps( // If the importer is in node compatibility mode or this is not an ESM // file that has been converted to a CommonJS file using a Babel- // compatible transform (i.e. "__esModule" has not been set), then set // "default" to the CommonJS "module.exports" for node compatibility. isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod )); // node_modules/@rails/actioncable/src/adapters.js var adapters_default; var init_adapters = __esm({ "node_modules/@rails/actioncable/src/adapters.js"() { adapters_default = { logger: self.console, WebSocket: self.WebSocket }; } }); // node_modules/@rails/actioncable/src/logger.js var logger_default; var init_logger = __esm({ "node_modules/@rails/actioncable/src/logger.js"() { init_adapters(); logger_default = { log(...messages) { if (this.enabled) { messages.push(Date.now()); adapters_default.logger.log("[ActionCable]", ...messages); } } }; } }); // node_modules/@rails/actioncable/src/connection_monitor.js var now, secondsSince, ConnectionMonitor, connection_monitor_default; var init_connection_monitor = __esm({ "node_modules/@rails/actioncable/src/connection_monitor.js"() { init_logger(); now = () => (/* @__PURE__ */ new Date()).getTime(); secondsSince = (time) => (now() - time) / 1e3; ConnectionMonitor = class { constructor(connection) { this.visibilityDidChange = this.visibilityDidChange.bind(this); this.connection = connection; this.reconnectAttempts = 0; } start() { if (!this.isRunning()) { this.startedAt = now(); delete this.stoppedAt; this.startPolling(); addEventListener("visibilitychange", this.visibilityDidChange); logger_default.log(`ConnectionMonitor started. stale threshold = ${this.constructor.staleThreshold} s`); } } stop() { if (this.isRunning()) { this.stoppedAt = now(); this.stopPolling(); removeEventListener("visibilitychange", this.visibilityDidChange); logger_default.log("ConnectionMonitor stopped"); } } isRunning() { return this.startedAt && !this.stoppedAt; } recordPing() { this.pingedAt = now(); } recordConnect() { this.reconnectAttempts = 0; this.recordPing(); delete this.disconnectedAt; logger_default.log("ConnectionMonitor recorded connect"); } recordDisconnect() { this.disconnectedAt = now(); logger_default.log("ConnectionMonitor recorded disconnect"); } // Private startPolling() { this.stopPolling(); this.poll(); } stopPolling() { clearTimeout(this.pollTimeout); } poll() { this.pollTimeout = setTimeout( () => { this.reconnectIfStale(); this.poll(); }, this.getPollInterval() ); } getPollInterval() { const { staleThreshold, reconnectionBackoffRate } = this.constructor; const backoff = Math.pow(1 + reconnectionBackoffRate, Math.min(this.reconnectAttempts, 10)); const jitterMax = this.reconnectAttempts === 0 ? 1 : reconnectionBackoffRate; const jitter = jitterMax * Math.random(); return staleThreshold * 1e3 * backoff * (1 + jitter); } reconnectIfStale() { if (this.connectionIsStale()) { logger_default.log(`ConnectionMonitor detected stale connection. reconnectAttempts = ${this.reconnectAttempts}, time stale = ${secondsSince(this.refreshedAt)} s, stale threshold = ${this.constructor.staleThreshold} s`); this.reconnectAttempts++; if (this.disconnectedRecently()) { logger_default.log(`ConnectionMonitor skipping reopening recent disconnect. time disconnected = ${secondsSince(this.disconnectedAt)} s`); } else { logger_default.log("ConnectionMonitor reopening"); this.connection.reopen(); } } } get refreshedAt() { return this.pingedAt ? this.pingedAt : this.startedAt; } connectionIsStale() { return secondsSince(this.refreshedAt) > this.constructor.staleThreshold; } disconnectedRecently() { return this.disconnectedAt && secondsSince(this.disconnectedAt) < this.constructor.staleThreshold; } visibilityDidChange() { if (document.visibilityState === "visible") { setTimeout( () => { if (this.connectionIsStale() || !this.connection.isOpen()) { logger_default.log(`ConnectionMonitor reopening stale connection on visibilitychange. visibilityState = ${document.visibilityState}`); this.connection.reopen(); } }, 200 ); } } }; ConnectionMonitor.staleThreshold = 6; ConnectionMonitor.reconnectionBackoffRate = 0.15; connection_monitor_default = ConnectionMonitor; } }); // node_modules/@rails/actioncable/src/internal.js var internal_default; var init_internal = __esm({ "node_modules/@rails/actioncable/src/internal.js"() { internal_default = { "message_types": { "welcome": "welcome", "disconnect": "disconnect", "ping": "ping", "confirmation": "confirm_subscription", "rejection": "reject_subscription" }, "disconnect_reasons": { "unauthorized": "unauthorized", "invalid_request": "invalid_request", "server_restart": "server_restart" }, "default_mount_path": "/cable", "protocols": [ "actioncable-v1-json", "actioncable-unsupported" ] }; } }); // node_modules/@rails/actioncable/src/connection.js var message_types, protocols, supportedProtocols, indexOf, Connection, connection_default; var init_connection = __esm({ "node_modules/@rails/actioncable/src/connection.js"() { init_adapters(); init_connection_monitor(); init_internal(); init_logger(); ({ message_types, protocols } = internal_default); supportedProtocols = protocols.slice(0, protocols.length - 1); indexOf = [].indexOf; Connection = class { constructor(consumer2) { this.open = this.open.bind(this); this.consumer = consumer2; this.subscriptions = this.consumer.subscriptions; this.monitor = new connection_monitor_default(this); this.disconnected = true; } send(data2) { if (this.isOpen()) { this.webSocket.send(JSON.stringify(data2)); return true; } else { return false; } } open() { if (this.isActive()) { logger_default.log(`Attempted to open WebSocket, but existing socket is ${this.getState()}`); return false; } else { logger_default.log(`Opening WebSocket, current state is ${this.getState()}, subprotocols: ${protocols}`); if (this.webSocket) { this.uninstallEventHandlers(); } this.webSocket = new adapters_default.WebSocket(this.consumer.url, protocols); this.installEventHandlers(); this.monitor.start(); return true; } } close({ allowReconnect } = { allowReconnect: true }) { if (!allowReconnect) { this.monitor.stop(); } if (this.isOpen()) { return this.webSocket.close(); } } reopen() { logger_default.log(`Reopening WebSocket, current state is ${this.getState()}`); if (this.isActive()) { try { return this.close(); } catch (error) { logger_default.log("Failed to reopen WebSocket", error); } finally { logger_default.log(`Reopening WebSocket in ${this.constructor.reopenDelay}ms`); setTimeout(this.open, this.constructor.reopenDelay); } } else { return this.open(); } } getProtocol() { if (this.webSocket) { return this.webSocket.protocol; } } isOpen() { return this.isState("open"); } isActive() { return this.isState("open", "connecting"); } // Private isProtocolSupported() { return indexOf.call(supportedProtocols, this.getProtocol()) >= 0; } isState(...states) { return indexOf.call(states, this.getState()) >= 0; } getState() { if (this.webSocket) { for (let state in adapters_default.WebSocket) { if (adapters_default.WebSocket[state] === this.webSocket.readyState) { return state.toLowerCase(); } } } return null; } installEventHandlers() { for (let eventName in this.events) { const handler = this.events[eventName].bind(this); this.webSocket[`on${eventName}`] = handler; } } uninstallEventHandlers() { for (let eventName in this.events) { this.webSocket[`on${eventName}`] = function() { }; } } }; Connection.reopenDelay = 500; Connection.prototype.events = { message(event) { if (!this.isProtocolSupported()) { return; } const { identifier, message, reason, reconnect, type } = JSON.parse(event.data); switch (type) { case message_types.welcome: this.monitor.recordConnect(); return this.subscriptions.reload(); case message_types.disconnect: logger_default.log(`Disconnecting. Reason: ${reason}`); return this.close({ allowReconnect: reconnect }); case message_types.ping: return this.monitor.recordPing(); case message_types.confirmation: this.subscriptions.confirmSubscription(identifier); return this.subscriptions.notify(identifier, "connected"); case message_types.rejection: return this.subscriptions.reject(identifier); default: return this.subscriptions.notify(identifier, "received", message); } }, open() { logger_default.log(`WebSocket onopen event, using '${this.getProtocol()}' subprotocol`); this.disconnected = false; if (!this.isProtocolSupported()) { logger_default.log("Protocol is unsupported. Stopping monitor and disconnecting."); return this.close({ allowReconnect: false }); } }, close(event) { logger_default.log("WebSocket onclose event"); if (this.disconnected) { return; } this.disconnected = true; this.monitor.recordDisconnect(); return this.subscriptions.notifyAll("disconnected", { willAttemptReconnect: this.monitor.isRunning() }); }, error() { logger_default.log("WebSocket onerror event"); } }; connection_default = Connection; } }); // node_modules/@rails/actioncable/src/subscription.js var extend, Subscription; var init_subscription = __esm({ "node_modules/@rails/actioncable/src/subscription.js"() { extend = function(object, properties) { if (properties != null) { for (let key in properties) { const value = properties[key]; object[key] = value; } } return object; }; Subscription = class { constructor(consumer2, params = {}, mixin) { this.consumer = consumer2; this.identifier = JSON.stringify(params); extend(this, mixin); } // Perform a channel action with the optional data passed as an attribute perform(action, data2 = {}) { data2.action = action; return this.send(data2); } send(data2) { return this.consumer.send({ command: "message", identifier: this.identifier, data: JSON.stringify(data2) }); } unsubscribe() { return this.consumer.subscriptions.remove(this); } }; } }); // node_modules/@rails/actioncable/src/subscription_guarantor.js var SubscriptionGuarantor, subscription_guarantor_default; var init_subscription_guarantor = __esm({ "node_modules/@rails/actioncable/src/subscription_guarantor.js"() { init_logger(); SubscriptionGuarantor = class { constructor(subscriptions) { this.subscriptions = subscriptions; this.pendingSubscriptions = []; } guarantee(subscription) { if (this.pendingSubscriptions.indexOf(subscription) == -1) { logger_default.log(`SubscriptionGuarantor guaranteeing ${subscription.identifier}`); this.pendingSubscriptions.push(subscription); } else { logger_default.log(`SubscriptionGuarantor already guaranteeing ${subscription.identifier}`); } this.startGuaranteeing(); } forget(subscription) { logger_default.log(`SubscriptionGuarantor forgetting ${subscription.identifier}`); this.pendingSubscriptions = this.pendingSubscriptions.filter((s3) => s3 !== subscription); } startGuaranteeing() { this.stopGuaranteeing(); this.retrySubscribing(); } stopGuaranteeing() { clearTimeout(this.retryTimeout); } retrySubscribing() { this.retryTimeout = setTimeout( () => { if (this.subscriptions && typeof this.subscriptions.subscribe === "function") { this.pendingSubscriptions.map((subscription) => { logger_default.log(`SubscriptionGuarantor resubscribing ${subscription.identifier}`); this.subscriptions.subscribe(subscription); }); } }, 500 ); } }; subscription_guarantor_default = SubscriptionGuarantor; } }); // node_modules/@rails/actioncable/src/subscriptions.js var Subscriptions; var init_subscriptions = __esm({ "node_modules/@rails/actioncable/src/subscriptions.js"() { init_subscription(); init_subscription_guarantor(); init_logger(); Subscriptions = class { constructor(consumer2) { this.consumer = consumer2; this.guarantor = new subscription_guarantor_default(this); this.subscriptions = []; } create(channelName, mixin) { const channel = channelName; const params = typeof channel === "object" ? channel : { channel }; const subscription = new Subscription(this.consumer, params, mixin); return this.add(subscription); } // Private add(subscription) { this.subscriptions.push(subscription); this.consumer.ensureActiveConnection(); this.notify(subscription, "initialized"); this.subscribe(subscription); return subscription; } remove(subscription) { this.forget(subscription); if (!this.findAll(subscription.identifier).length) { this.sendCommand(subscription, "unsubscribe"); } return subscription; } reject(identifier) { return this.findAll(identifier).map((subscription) => { this.forget(subscription); this.notify(subscription, "rejected"); return subscription; }); } forget(subscription) { this.guarantor.forget(subscription); this.subscriptions = this.subscriptions.filter((s3) => s3 !== subscription); return subscription; } findAll(identifier) { return this.subscriptions.filter((s3) => s3.identifier === identifier); } reload() { return this.subscriptions.map((subscription) => this.subscribe(subscription)); } notifyAll(callbackName, ...args) { return this.subscriptions.map((subscription) => this.notify(subscription, callbackName, ...args)); } notify(subscription, callbackName, ...args) { let subscriptions; if (typeof subscription === "string") { subscriptions = this.findAll(subscription); } else { subscriptions = [subscription]; } return subscriptions.map((subscription2) => typeof subscription2[callbackName] === "function" ? subscription2[callbackName](...args) : void 0); } subscribe(subscription) { if (this.sendCommand(subscription, "subscribe")) { this.guarantor.guarantee(subscription); } } confirmSubscription(identifier) { logger_default.log(`Subscription confirmed ${identifier}`); this.findAll(identifier).map((subscription) => this.guarantor.forget(subscription)); } sendCommand(subscription, command) { const { identifier } = subscription; return this.consumer.send({ command, identifier }); } }; } }); // node_modules/@rails/actioncable/src/consumer.js function createWebSocketURL(url) { if (typeof url === "function") { url = url(); } if (url && !/^wss?:/i.test(url)) { const a3 = document.createElement("a"); a3.href = url; a3.href = a3.href; a3.protocol = a3.protocol.replace("http", "ws"); return a3.href; } else { return url; } } var Consumer; var init_consumer = __esm({ "node_modules/@rails/actioncable/src/consumer.js"() { init_connection(); init_subscriptions(); Consumer = class { constructor(url) { this._url = url; this.subscriptions = new Subscriptions(this); this.connection = new connection_default(this); } get url() { return createWebSocketURL(this._url); } send(data2) { return this.connection.send(data2); } connect() { return this.connection.open(); } disconnect() { return this.connection.close({ allowReconnect: false }); } ensureActiveConnection() { if (!this.connection.isActive()) { return this.connection.open(); } } }; } }); // node_modules/@rails/actioncable/src/index.js var src_exports = {}; __export(src_exports, { Connection: () => connection_default, ConnectionMonitor: () => connection_monitor_default, Consumer: () => Consumer, INTERNAL: () => internal_default, Subscription: () => Subscription, SubscriptionGuarantor: () => subscription_guarantor_default, Subscriptions: () => Subscriptions, adapters: () => adapters_default, createConsumer: () => createConsumer, createWebSocketURL: () => createWebSocketURL, getConfig: () => getConfig, logger: () => logger_default }); function createConsumer(url = getConfig("url") || internal_default.default_mount_path) { return new Consumer(url); } function getConfig(name) { const element = document.head.querySelector(`meta[name='action-cable-${name}']`); if (element) { return element.getAttribute("content"); } } var init_src = __esm({ "node_modules/@rails/actioncable/src/index.js"() { init_connection(); init_connection_monitor(); init_consumer(); init_internal(); init_subscription(); init_subscriptions(); init_subscription_guarantor(); init_adapters(); init_logger(); } }); // node_modules/clipboard/dist/clipboard.js var require_clipboard = __commonJS({ "node_modules/clipboard/dist/clipboard.js"(exports, module) { (function webpackUniversalModuleDefinition(root, factory) { if (typeof exports === "object" && typeof module === "object") module.exports = factory(); else if (typeof define === "function" && define.amd) define([], factory); else if (typeof exports === "object") exports["ClipboardJS"] = factory(); else root["ClipboardJS"] = factory(); })(exports, function() { return ( /******/ function() { var __webpack_modules__ = { /***/ 686: ( /***/ function(__unused_webpack_module, __webpack_exports__, __webpack_require__2) { "use strict"; __webpack_require__2.d(__webpack_exports__, { "default": function() { return ( /* binding */ clipboard ); } }); var tiny_emitter = __webpack_require__2(279); var tiny_emitter_default = /* @__PURE__ */ __webpack_require__2.n(tiny_emitter); var listen = __webpack_require__2(370); var listen_default = /* @__PURE__ */ __webpack_require__2.n(listen); var src_select = __webpack_require__2(817); var select_default = /* @__PURE__ */ __webpack_require__2.n(src_select); ; function command(type) { try { return document.execCommand(type); } catch (err) { return false; } } ; var ClipboardActionCut = function ClipboardActionCut2(target) { var selectedText = select_default()(target); command("cut"); return selectedText; }; var actions_cut = ClipboardActionCut; ; function createFakeElement(value) { var isRTL = document.documentElement.getAttribute("dir") === "rtl"; var fakeElement = document.createElement("textarea"); fakeElement.style.fontSize = "12pt"; fakeElement.style.border = "0"; fakeElement.style.padding = "0"; fakeElement.style.margin = "0"; fakeElement.style.position = "absolute"; fakeElement.style[isRTL ? "right" : "left"] = "-9999px"; var yPosition = window.pageYOffset || document.documentElement.scrollTop; fakeElement.style.top = "".concat(yPosition, "px"); fakeElement.setAttribute("readonly", ""); fakeElement.value = value; return fakeElement; } ; var fakeCopyAction = function fakeCopyAction2(value, options) { var fakeElement = createFakeElement(value); options.container.appendChild(fakeElement); var selectedText = select_default()(fakeElement); command("copy"); fakeElement.remove(); return selectedText; }; var ClipboardActionCopy = function ClipboardActionCopy2(target) { var options = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : { container: document.body }; var selectedText = ""; if (typeof target === "string") { selectedText = fakeCopyAction(target, options); } else if (target instanceof HTMLInputElement && !["text", "search", "url", "tel", "password"].includes(target === null || target === void 0 ? void 0 : target.type)) { selectedText = fakeCopyAction(target.value, options); } else { selectedText = select_default()(target); command("copy"); } return selectedText; }; var actions_copy = ClipboardActionCopy; ; function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof2(obj2) { return typeof obj2; }; } else { _typeof = function _typeof2(obj2) { return obj2 && typeof Symbol === "function" && obj2.constructor === Symbol && obj2 !== Symbol.prototype ? "symbol" : typeof obj2; }; } return _typeof(obj); } var ClipboardActionDefault = function ClipboardActionDefault2() { var options = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {}; var _options$action = options.action, action = _options$action === void 0 ? "copy" : _options$action, container = options.container, target = options.target, text = options.text; if (action !== "copy" && action !== "cut") { throw new Error('Invalid "action" value, use either "copy" or "cut"'); } if (target !== void 0) { if (target && _typeof(target) === "object" && target.nodeType === 1) { if (action === "copy" && target.hasAttribute("disabled")) { throw new Error('Invalid "target" attribute. Please use "readonly" instead of "disabled" attribute'); } if (action === "cut" && (target.hasAttribute("readonly") || target.hasAttribute("disabled"))) { throw new Error(`Invalid "target" attribute. You can't cut text from elements with "readonly" or "disabled" attributes`); } } else { throw new Error('Invalid "target" value, use a valid Element'); } } if (text) { return actions_copy(text, { container }); } if (target) { return action === "cut" ? actions_cut(target) : actions_copy(target, { container }); } }; var actions_default = ClipboardActionDefault; ; function clipboard_typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { clipboard_typeof = function _typeof2(obj2) { return typeof obj2; }; } else { clipboard_typeof = function _typeof2(obj2) { return obj2 && typeof Symbol === "function" && obj2.constructor === Symbol && obj2 !== Symbol.prototype ? "symbol" : typeof obj2; }; } return clipboard_typeof(obj); } function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } function _defineProperties(target, props) { for (var i3 = 0; i3 < props.length; i3++) { var descriptor = props[i3]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); } function _setPrototypeOf(o3, p2) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf2(o4, p3) { o4.__proto__ = p3; return o4; }; return _setPrototypeOf(o3, p2); } function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; } function _possibleConstructorReturn(self2, call) { if (call && (clipboard_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self2); } function _assertThisInitialized(self2) { if (self2 === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self2; } function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function() { })); return true; } catch (e3) { return false; } } function _getPrototypeOf(o3) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf2(o4) { return o4.__proto__ || Object.getPrototypeOf(o4); }; return _getPrototypeOf(o3); } function getAttributeValue(suffix, element) { var attribute = "data-clipboard-".concat(suffix); if (!element.hasAttribute(attribute)) { return; } return element.getAttribute(attribute); } var Clipboard = /* @__PURE__ */ function(_Emitter) { _inherits(Clipboard2, _Emitter); var _super = _createSuper(Clipboard2); function Clipboard2(trigger, options) { var _this; _classCallCheck(this, Clipboard2); _this = _super.call(this); _this.resolveOptions(options); _this.listenClick(trigger); return _this; } _createClass(Clipboard2, [{ key: "resolveOptions", value: function resolveOptions() { var options = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {}; this.action = typeof options.action === "function" ? options.action : this.defaultAction; this.target = typeof options.target === "function" ? options.target : this.defaultTarget; this.text = typeof options.text === "function" ? options.text : this.defaultText; this.container = clipboard_typeof(options.container) === "object" ? options.container : document.body; } /** * Adds a click event listener to the passed trigger. * @param {String|HTMLElement|HTMLCollection|NodeList} trigger */ }, { key: "listenClick", value: function listenClick(trigger) { var _this2 = this; this.listener = listen_default()(trigger, "click", function(e3) { return _this2.onClick(e3); }); } /** * Defines a new `ClipboardAction` on each click event. * @param {Event} e */ }, { key: "onClick", value: function onClick(e3) { var trigger = e3.delegateTarget || e3.currentTarget; var action = this.action(trigger) || "copy"; var text = actions_default({ action, container: this.container, target: this.target(trigger), text: this.text(trigger) }); this.emit(text ? "success" : "error", { action, text, trigger, clearSelection: function clearSelection() { if (trigger) { trigger.focus(); } window.getSelection().removeAllRanges(); } }); } /** * Default `action` lookup function. * @param {Element} trigger */ }, { key: "defaultAction", value: function defaultAction(trigger) { return getAttributeValue("action", trigger); } /** * Default `target` lookup function. * @param {Element} trigger */ }, { key: "defaultTarget", value: function defaultTarget(trigger) { var selector = getAttributeValue("target", trigger); if (selector) { return document.querySelector(selector); } } /** * Allow fire programmatically a copy action * @param {String|HTMLElement} target * @param {Object} options * @returns Text copied. */ }, { key: "defaultText", /** * Default `text` lookup function. * @param {Element} trigger */ value: function defaultText(trigger) { return getAttributeValue("text", trigger); } /** * Destroy lifecycle. */ }, { key: "destroy", value: function destroy() { this.listener.destroy(); } }], [{ key: "copy", value: function copy(target) { var options = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : { container: document.body }; return actions_copy(target, options); } /** * Allow fire programmatically a cut action * @param {String|HTMLElement} target * @returns Text cutted. */ }, { key: "cut", value: function cut(target) { return actions_cut(target); } /** * Returns the support of the given action, or all actions if no action is * given. * @param {String} [action] */ }, { key: "isSupported", value: function isSupported() { var action = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : ["copy", "cut"]; var actions = typeof action === "string" ? [action] : action; var support = !!document.queryCommandSupported; actions.forEach(function(action2) { support = support && !!document.queryCommandSupported(action2); }); return support; } }]); return Clipboard2; }(tiny_emitter_default()); var clipboard = Clipboard; } ), /***/ 828: ( /***/ function(module2) { var DOCUMENT_NODE_TYPE = 9; if (typeof Element !== "undefined" && !Element.prototype.matches) { var proto = Element.prototype; proto.matches = proto.matchesSelector || proto.mozMatchesSelector || proto.msMatchesSelector || proto.oMatchesSelector || proto.webkitMatchesSelector; } function closest(element, selector) { while (element && element.nodeType !== DOCUMENT_NODE_TYPE) { if (typeof element.matches === "function" && element.matches(selector)) { return element; } element = element.parentNode; } } module2.exports = closest; } ), /***/ 438: ( /***/ function(module2, __unused_webpack_exports, __webpack_require__2) { var closest = __webpack_require__2(828); function _delegate(element, selector, type, callback, useCapture) { var listenerFn = listener.apply(this, arguments); element.addEventListener(type, listenerFn, useCapture); return { destroy: function() { element.removeEventListener(type, listenerFn, useCapture); } }; } function delegate2(elements, selector, type, callback, useCapture) { if (typeof elements.addEventListener === "function") { return _delegate.apply(null, arguments); } if (typeof type === "function") { return _delegate.bind(null, document).apply(null, arguments); } if (typeof elements === "string") { elements = document.querySelectorAll(elements); } return Array.prototype.map.call(elements, function(element) { return _delegate(element, selector, type, callback, useCapture); }); } function listener(element, selector, type, callback) { return function(e3) { e3.delegateTarget = closest(e3.target, selector); if (e3.delegateTarget) { callback.call(element, e3); } }; } module2.exports = delegate2; } ), /***/ 879: ( /***/ function(__unused_webpack_module, exports2) { exports2.node = function(value) { return value !== void 0 && value instanceof HTMLElement && value.nodeType === 1; }; exports2.nodeList = function(value) { var type = Object.prototype.toString.call(value); return value !== void 0 && (type === "[object NodeList]" || type === "[object HTMLCollection]") && "length" in value && (value.length === 0 || exports2.node(value[0])); }; exports2.string = function(value) { return typeof value === "string" || value instanceof String; }; exports2.fn = function(value) { var type = Object.prototype.toString.call(value); return type === "[object Function]"; }; } ), /***/ 370: ( /***/ function(module2, __unused_webpack_exports, __webpack_require__2) { var is = __webpack_require__2(879); var delegate2 = __webpack_require__2(438); function listen(target, type, callback) { if (!target && !type && !callback) { throw new Error("Missing required arguments"); } if (!is.string(type)) { throw new TypeError("Second argument must be a String"); } if (!is.fn(callback)) { throw new TypeError("Third argument must be a Function"); } if (is.node(target)) { return listenNode(target, type, callback); } else if (is.nodeList(target)) { return listenNodeList(target, type, callback); } else if (is.string(target)) { return listenSelector(target, type, callback); } else { throw new TypeError("First argument must be a String, HTMLElement, HTMLCollection, or NodeList"); } } function listenNode(node, type, callback) { node.addEventListener(type, callback); return { destroy: function() { node.removeEventListener(type, callback); } }; } function listenNodeList(nodeList, type, callback) { Array.prototype.forEach.call(nodeList, function(node) { node.addEventListener(type, callback); }); return { destroy: function() { Array.prototype.forEach.call(nodeList, function(node) { node.removeEventListener(type, callback); }); } }; } function listenSelector(selector, type, callback) { return delegate2(document.body, selector, type, callback); } module2.exports = listen; } ), /***/ 817: ( /***/ function(module2) { function select(element) { var selectedText; if (element.nodeName === "SELECT") { element.focus(); selectedText = element.value; } else if (element.nodeName === "INPUT" || element.nodeName === "TEXTAREA") { var isReadOnly = element.hasAttribute("readonly"); if (!isReadOnly) { element.setAttribute("readonly", ""); } element.select(); element.setSelectionRange(0, element.value.length); if (!isReadOnly) { element.removeAttribute("readonly"); } selectedText = element.value; } else { if (element.hasAttribute("contenteditable")) { element.focus(); } var selection = window.getSelection(); var range = document.createRange(); range.selectNodeContents(element); selection.removeAllRanges(); selection.addRange(range); selectedText = selection.toString(); } return selectedText; } module2.exports = select; } ), /***/ 279: ( /***/ function(module2) { function E2() { } E2.prototype = { on: function(name, callback, ctx) { var e3 = this.e || (this.e = {}); (e3[name] || (e3[name] = [])).push({ fn: callback, ctx }); return this; }, once: function(name, callback, ctx) { var self2 = this; function listener() { self2.off(name, listener); callback.apply(ctx, arguments); } ; listener._ = callback; return this.on(name, listener, ctx); }, emit: function(name) { var data2 = [].slice.call(arguments, 1); var evtArr = ((this.e || (this.e = {}))[name] || []).slice(); var i3 = 0; var len = evtArr.length; for (i3; i3 < len; i3++) { evtArr[i3].fn.apply(evtArr[i3].ctx, data2); } return this; }, off: function(name, callback) { var e3 = this.e || (this.e = {}); var evts = e3[name]; var liveEvents = []; if (evts && callback) { for (var i3 = 0, len = evts.length; i3 < len; i3++) { if (evts[i3].fn !== callback && evts[i3].fn._ !== callback) liveEvents.push(evts[i3]); } } liveEvents.length ? e3[name] = liveEvents : delete e3[name]; return this; } }; module2.exports = E2; module2.exports.TinyEmitter = E2; } ) /******/ }; var __webpack_module_cache__ = {}; function __webpack_require__(moduleId) { if (__webpack_module_cache__[moduleId]) { return __webpack_module_cache__[moduleId].exports; } var module2 = __webpack_module_cache__[moduleId] = { /******/ // no module.id needed /******/ // no module.loaded needed /******/ exports: {} /******/ }; __webpack_modules__[moduleId](module2, module2.exports, __webpack_require__); return module2.exports; } !function() { __webpack_require__.n = function(module2) { var getter = module2 && module2.__esModule ? ( /******/ function() { return module2["default"]; } ) : ( /******/ function() { return module2; } ); __webpack_require__.d(getter, { a: getter }); return getter; }; }(); !function() { __webpack_require__.d = function(exports2, definition) { for (var key in definition) { if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports2, key)) { Object.defineProperty(exports2, key, { enumerable: true, get: definition[key] }); } } }; }(); !function() { __webpack_require__.o = function(obj, prop) { return Object.prototype.hasOwnProperty.call(obj, prop); }; }(); return __webpack_require__(686); }().default ); }); } }); // node_modules/ralix/src/internal_utils.js function getMethods(obj) { let methods = /* @__PURE__ */ new Set(); while (obj = Reflect.getPrototypeOf(obj)) { let keys = Reflect.ownKeys(obj); keys.forEach((k2) => methods.add(k2)); } return methods; } // node_modules/ralix/src/helpers.js var Helpers = class { inject() { getMethods(this).forEach((method) => { if (typeof this[method] === "function" && method != "inject") window[method] = this[method].bind(this); }); } // Selectors find(query) { if (typeof query === "string") return document.querySelector(query); else return query; } findAll(query) { if (query == null) return []; let elements = typeof query === "string" ? document.querySelectorAll(query) : query; if (Array.isArray(elements) || NodeList.prototype.isPrototypeOf(elements)) return elements; else return [elements]; } findParent(queryElem, queryParent) { let elem = find(queryElem); if (queryParent === null || queryParent === void 0) return elem.parentNode; while (elem !== document) { if (elem.matches(queryParent)) return elem; elem = elem.parentNode; } } findParents(queryElem, queryParent) { let elem = find(queryElem); const elements = []; if (queryParent === null || queryParent === void 0) return elements; while (elem !== document) { if (elem.matches(queryParent)) elements.push(elem); elem = elem.parentNode; } return elements; } // Classes addClass(query, classList) { _classModifier("add", query, classList); } removeClass(query, classList) { _classModifier("remove", query, classList); } toggleClass(query, classList, classValue = null) { if (classValue !== null) _classModifier(classValue ? "add" : "remove", query, classList); else _classModifier("toggle", query, classList); } hasClass(query, className) { const el = find(query); if (el) return el.classList.contains(className); } _classModifier(operation, query, classList) { const queries = Array.isArray(query) ? query : [query]; queries.forEach((query2) => { const elements = findAll(query2); if (elements.length == 0) return; elements.forEach((el) => { if (Array.isArray(classList)) el.classList[operation](...classList); else el.classList[operation](classList); }); }); } // Attributes attr(query, attribute, value = null) { const el = find(query); if (!el) return; if (typeof attribute === "string") if (value === null) return el.getAttribute(attribute); else return el.setAttribute(attribute, value); else if (typeof attribute === "object") _setAttributes(el, attribute); } _setAttributes(elem, attributes) { Object.entries(attributes).forEach((entry) => { const [key, value] = entry; elem.setAttribute(key, value); }); } data(query, attribute = null, value = null) { const el = find(query); if (!el) return; if (!attribute && !value) return el.dataset; if (typeof attribute === "string") if (value === null) return el.dataset[attribute]; else return el.dataset[attribute] = value; else if (typeof attribute === "object") _setDataset(el, attribute); } _setDataset(elem, attributes) { Object.entries(attributes).forEach((entry) => { const [key, value] = entry; elem.dataset[key] = value; }); } removeAttr(query, attribute) { const el = find(query); if (!el) return; if (Array.isArray(attribute)) { attribute.forEach((attr2) => { el.removeAttribute(attr2); }); } else if (typeof attribute === "string") { el.removeAttribute(attribute); } } removeData(query, attribute = null) { const el = find(query); if (!el) return; if (Array.isArray(attribute)) { attribute.forEach((attr2) => { delete el.dataset[attr2]; }); } else if (typeof attribute === "string") { delete el.dataset[attribute]; } else if (attribute === null) { for (attr in el.dataset) { delete el.dataset[attr]; } } } // DOM insertHTML(query, html, position = "inner") { const el = find(query); if (!el) return; if (html instanceof Element) html = html.outerHTML; switch (position) { case "inner": el.innerHTML = html; break; case "prepend": el.insertAdjacentHTML("beforebegin", html); break; case "begin": el.insertAdjacentHTML("afterbegin", html); break; case "end": el.insertAdjacentHTML("beforeend", html); break; case "append": el.insertAdjacentHTML("afterend", html); break; } } elem(type, attributes = null) { const el = document.createElement(type); if (attributes) _setAttributes(el, attributes); return el; } // Templates render(template, data2) { return App.templates.render(template, data2); } // Forms serialize(query) { if (query instanceof Element || typeof query == "string") { const form = find(query); if (form) return new URLSearchParams(new FormData(form)).toString(); } else { return Object.keys(query).map((k2) => encodeURIComponent(k2) + "=" + encodeURIComponent(query[k2])).join("&"); } } submit(query) { const form = find(query); if (!form) return; if (App.rails_ujs && data(form, "remote") === "true") App.rails_ujs.fire(form, "submit"); else if (form.requestSubmit) form.requestSubmit(); else form.submit(); } // Navigation visit(url) { if (typeof Turbo !== "undefined") Turbo.visit(url); else if (typeof Turbolinks !== "undefined") Turbolinks.visit(url); else window.location.href = url; } back(fallbackUrl = null) { const referrer = document.referrer; const isOtherHost = !referrer.includes(location.hostname); if (fallbackUrl && (!referrer || isOtherHost || history.length < 2)) visit(fallbackUrl); else history.back(); } reload() { window.location.reload(); } currentUrl() { return window.location.href; } getParam(param = null) { const urlParams = new URL(currentUrl()).searchParams; if (!param) return Object.fromEntries(urlParams); if (urlParams.get(`${param}[]`)) return urlParams.getAll(`${param}[]`); else return urlParams.get(param); } setParam(param, value) { const urlObject = new URL(currentUrl()); if (param instanceof Object) { Object.entries(param).forEach((entry) => { _setParam(urlObject, entry[0], entry[1]); }); } else { _setParam(urlObject, param, value); } history.pushState({}, "", urlObject.href); return urlObject.href; } _setParam(urlObject, param, value) { if (value == null) urlObject.searchParams.delete(param); else urlObject.searchParams.set(param, value); } // Events on(query, events, callback) { let elements = findAll(query); if (elements.length == 0) return; elements.forEach((el) => { events.split(" ").forEach((event) => _addListener(el, event, callback)); }); } currentElement() { return App.currentElement; } currentEvent() { return App.currentEvent; } _addListener(elem, event, callback) { elem.addEventListener(event, (e3) => { if (event == "click" && (["A", "BUTTON"].includes(elem.tagName) || elem.tagName == "INPUT" && elem.type == "submit")) e3.preventDefault(); App.currentElement = elem; App.currentEvent = e3; callback.call(this, e3); App.currentElement = null; App.currentEvent = null; }); } // Ajax async ajax(path, { params = {}, options = {} } = {}) { let format = "text"; if ("format" in options) { format = options.format; delete options.format; } const defaults = { method: "GET", credentials: "include" }; options = Object.assign({}, defaults, options); if (["POST", "PATCH", "PUT"].includes(options.method)) { if (params instanceof FormData) { if ("headers" in options) delete options.headers["Content-Type"]; options = Object.assign({}, { body: params }, options); } else options = Object.assign({}, { body: JSON.stringify(params) }, options); } else if (Object.keys(params).length > 0) path = `${path}?${serialize(params)}`; const response = await fetch(path, options); if (format.toLowerCase() === "json") return response.json(); else return response.text(); } get(path, { params = {}, options = {} } = {}) { options.method = "GET"; return ajax(path, { params, options }); } post(path, { params = {}, options = {} } = {}) { options.method = "POST"; return ajax(path, { params, options }); } }; // node_modules/ralix/src/router.js var Router = class { constructor(routes) { this.routes = routes; } get path() { return window.location.pathname; } dispatch() { if (this.ctrl) this._supressCtrl(); for (let route in this.routes) { if (this.path.match(route)) { this.ctrl = new this.routes[route](); this._exposeCtrl(); break; } } } _exposeCtrl() { getMethods(this.ctrl).forEach((method) => { if (typeof this.ctrl[method] === "function") window[method] = this.ctrl[method].bind(this.ctrl); }); } _supressCtrl() { getMethods(this.ctrl).forEach((method) => { delete window[method]; }); } }; // node_modules/ralix/src/events.js var Events = class { constructor() { this.eventsRegex = /^on(\w+)/; this.availableEvents = []; for (let property in window) { if (this.eventsRegex.test(property)) this.availableEvents.push(`[${property}]`); } } bind() { findAll(this.availableEvents.join(", ")).forEach((element) => { Array.from(element.attributes).forEach((attr2) => { let match = attr2.name.match(this.eventsRegex); if (match) { const [eventType, listener] = match; const originalEvent = element[eventType]; element[eventType] = null; on(element, listener, originalEvent); } }); }); } }; // node_modules/ralix/src/templates.js var Templates = class { constructor(templates) { this.templates = templates || {}; } render(template, data2) { const tmpl = this.templates[template]; if (tmpl) return tmpl.call(this, data2); else throw new Error(`[Ralix] Template '${template}' not found`); } }; // node_modules/ralix/src/app.js var App2 = class { constructor(config = {}) { this.helpers = new Helpers(); this.router = new Router(config.routes); this.events = new Events(); this.templates = new Templates(config.templates); this.rails_ujs = config.rails_ujs || null; this.components = config.components || []; window.App = this; } get ctrl() { return this.router.ctrl; } start() { let loadEvent = "DOMContentLoaded"; if (typeof Turbo !== "undefined") loadEvent = "turbo:load"; if (typeof Turbolinks !== "undefined") loadEvent = "turbolinks:load"; document.addEventListener(loadEvent, () => { this.helpers.inject(); this.router.dispatch(); this.events.bind(); this.components.forEach((component) => { if (typeof component.onload === "function") component.onload(); }); }); } }; // node_modules/@hotwired/turbo/dist/turbo.es2017-esm.js (function() { if (window.Reflect === void 0 || window.customElements === void 0 || window.customElements.polyfillWrapFlushCallback) { return; } const BuiltInHTMLElement = HTMLElement; const wrapperForTheName = { HTMLElement: function HTMLElement2() { return Reflect.construct(BuiltInHTMLElement, [], this.constructor); } }; window.HTMLElement = wrapperForTheName["HTMLElement"]; HTMLElement.prototype = BuiltInHTMLElement.prototype; HTMLElement.prototype.constructor = HTMLElement; Object.setPrototypeOf(HTMLElement, BuiltInHTMLElement); })(); (function(prototype) { if (typeof prototype.requestSubmit == "function") return; prototype.requestSubmit = function(submitter) { if (submitter) { validateSubmitter(submitter, this); submitter.click(); } else { submitter = document.createElement("input"); submitter.type = "submit"; submitter.hidden = true; this.appendChild(submitter); submitter.click(); this.removeChild(submitter); } }; function validateSubmitter(submitter, form) { submitter instanceof HTMLElement || raise(TypeError, "parameter 1 is not of type 'HTMLElement'"); submitter.type == "submit" || raise(TypeError, "The specified element is not a submit button"); submitter.form == form || raise(DOMException, "The specified element is not owned by this form element", "NotFoundError"); } function raise(errorConstructor, message, name) { throw new errorConstructor("Failed to execute 'requestSubmit' on 'HTMLFormElement': " + message + ".", name); } })(HTMLFormElement.prototype); var submittersByForm = /* @__PURE__ */ new WeakMap(); function findSubmitterFromClickTarget(target) { const element = target instanceof Element ? target : target instanceof Node ? target.parentElement : null; const candidate = element ? element.closest("input, button") : null; return (candidate === null || candidate === void 0 ? void 0 : candidate.type) == "submit" ? candidate : null; } function clickCaptured(event) { const submitter = findSubmitterFromClickTarget(event.target); if (submitter && submitter.form) { submittersByForm.set(submitter.form, submitter); } } (function() { if ("submitter" in Event.prototype) return; let prototype = window.Event.prototype; if ("SubmitEvent" in window && /Apple Computer/.test(navigator.vendor)) { prototype = window.SubmitEvent.prototype; } else if ("SubmitEvent" in window) { return; } addEventListener("click", clickCaptured, true); Object.defineProperty(prototype, "submitter", { get() { if (this.type == "submit" && this.target instanceof HTMLFormElement) { return submittersByForm.get(this.target); } } }); })(); var FrameLoadingStyle; (function(FrameLoadingStyle2) { FrameLoadingStyle2["eager"] = "eager"; FrameLoadingStyle2["lazy"] = "lazy"; })(FrameLoadingStyle || (FrameLoadingStyle = {})); var FrameElement = class extends HTMLElement { static get observedAttributes() { return ["disabled", "complete", "loading", "src"]; } constructor() { super(); this.loaded = Promise.resolve(); this.delegate = new FrameElement.delegateConstructor(this); } connectedCallback() { this.delegate.connect(); } disconnectedCallback() { this.delegate.disconnect(); } reload() { return this.delegate.sourceURLReloaded(); } attributeChangedCallback(name) { if (name == "loading") { this.delegate.loadingStyleChanged(); } else if (name == "complete") { this.delegate.completeChanged(); } else if (name == "src") { this.delegate.sourceURLChanged(); } else { this.delegate.disabledChanged(); } } get src() { return this.getAttribute("src"); } set src(value) { if (value) { this.setAttribute("src", value); } else { this.removeAttribute("src"); } } get loading() { return frameLoadingStyleFromString(this.getAttribute("loading") || ""); } set loading(value) { if (value) { this.setAttribute("loading", value); } else { this.removeAttribute("loading"); } } get disabled() { return this.hasAttribute("disabled"); } set disabled(value) { if (value) { this.setAttribute("disabled", ""); } else { this.removeAttribute("disabled"); } } get autoscroll() { return this.hasAttribute("autoscroll"); } set autoscroll(value) { if (value) { this.setAttribute("autoscroll", ""); } else { this.removeAttribute("autoscroll"); } } get complete() { return !this.delegate.isLoading; } get isActive() { return this.ownerDocument === document && !this.isPreview; } get isPreview() { var _a, _b; return (_b = (_a = this.ownerDocument) === null || _a === void 0 ? void 0 : _a.documentElement) === null || _b === void 0 ? void 0 : _b.hasAttribute("data-turbo-preview"); } }; function frameLoadingStyleFromString(style) { switch (style.toLowerCase()) { case "lazy": return FrameLoadingStyle.lazy; default: return FrameLoadingStyle.eager; } } function expandURL(locatable) { return new URL(locatable.toString(), document.baseURI); } function getAnchor(url) { let anchorMatch; if (url.hash) { return url.hash.slice(1); } else if (anchorMatch = url.href.match(/#(.*)$/)) { return anchorMatch[1]; } } function getAction(form, submitter) { const action = (submitter === null || submitter === void 0 ? void 0 : submitter.getAttribute("formaction")) || form.getAttribute("action") || form.action; return expandURL(action); } function getExtension(url) { return (getLastPathComponent(url).match(/\.[^.]*$/) || [])[0] || ""; } function isHTML(url) { return !!getExtension(url).match(/^(?:|\.(?:htm|html|xhtml|php))$/); } function isPrefixedBy(baseURL, url) { const prefix = getPrefix(url); return baseURL.href === expandURL(prefix).href || baseURL.href.startsWith(prefix); } function locationIsVisitable(location2, rootLocation) { return isPrefixedBy(location2, rootLocation) && isHTML(location2); } function getRequestURL(url) { const anchor = getAnchor(url); return anchor != null ? url.href.slice(0, -(anchor.length + 1)) : url.href; } function toCacheKey(url) { return getRequestURL(url); } function urlsAreEqual(left2, right2) { return expandURL(left2).href == expandURL(right2).href; } function getPathComponents(url) { return url.pathname.split("/").slice(1); } function getLastPathComponent(url) { return getPathComponents(url).slice(-1)[0]; } function getPrefix(url) { return addTrailingSlash(url.origin + url.pathname); } function addTrailingSlash(value) { return value.endsWith("/") ? value : value + "/"; } var FetchResponse = class { constructor(response) { this.response = response; } get succeeded() { return this.response.ok; } get failed() { return !this.succeeded; } get clientError() { return this.statusCode >= 400 && this.statusCode <= 499; } get serverError() { return this.statusCode >= 500 && this.statusCode <= 599; } get redirected() { return this.response.redirected; } get location() { return expandURL(this.response.url); } get isHTML() { return this.contentType && this.contentType.match(/^(?:text\/([^\s;,]+\b)?html|application\/xhtml\+xml)\b/); } get statusCode() { return this.response.status; } get contentType() { return this.header("Content-Type"); } get responseText() { return this.response.clone().text(); } get responseHTML() { if (this.isHTML) { return this.response.clone().text(); } else { return Promise.resolve(void 0); } } header(name) { return this.response.headers.get(name); } }; function activateScriptElement(element) { if (element.getAttribute("data-turbo-eval") == "false") { return element; } else { const createdScriptElement = document.createElement("script"); const cspNonce2 = getMetaContent("csp-nonce"); if (cspNonce2) { createdScriptElement.nonce = cspNonce2; } createdScriptElement.textContent = element.textContent; createdScriptElement.async = false; copyElementAttributes(createdScriptElement, element); return createdScriptElement; } } function copyElementAttributes(destinationElement, sourceElement) { for (const { name, value } of sourceElement.attributes) { destinationElement.setAttribute(name, value); } } function createDocumentFragment(html) { const template = document.createElement("template"); template.innerHTML = html; return template.content; } function dispatch(eventName, { target, cancelable, detail } = {}) { const event = new CustomEvent(eventName, { cancelable, bubbles: true, composed: true, detail }); if (target && target.isConnected) { target.dispatchEvent(event); } else { document.documentElement.dispatchEvent(event); } return event; } function nextAnimationFrame() { return new Promise((resolve) => requestAnimationFrame(() => resolve())); } function nextEventLoopTick() { return new Promise((resolve) => setTimeout(() => resolve(), 0)); } function nextMicrotask() { return Promise.resolve(); } function parseHTMLDocument(html = "") { return new DOMParser().parseFromString(html, "text/html"); } function unindent(strings, ...values) { const lines = interpolate(strings, values).replace(/^\n/, "").split("\n"); const match = lines[0].match(/^\s+/); const indent = match ? match[0].length : 0; return lines.map((line) => line.slice(indent)).join("\n"); } function interpolate(strings, values) { return strings.reduce((result, string, i3) => { const value = values[i3] == void 0 ? "" : values[i3]; return result + string + value; }, ""); } function uuid() { return Array.from({ length: 36 }).map((_2, i3) => { if (i3 == 8 || i3 == 13 || i3 == 18 || i3 == 23) { return "-"; } else if (i3 == 14) { return "4"; } else if (i3 == 19) { return (Math.floor(Math.random() * 4) + 8).toString(16); } else { return Math.floor(Math.random() * 15).toString(16); } }).join(""); } function getAttribute(attributeName, ...elements) { for (const value of elements.map((element) => element === null || element === void 0 ? void 0 : element.getAttribute(attributeName))) { if (typeof value == "string") return value; } return null; } function hasAttribute(attributeName, ...elements) { return elements.some((element) => element && element.hasAttribute(attributeName)); } function markAsBusy(...elements) { for (const element of elements) { if (element.localName == "turbo-frame") { element.setAttribute("busy", ""); } element.setAttribute("aria-busy", "true"); } } function clearBusyState(...elements) { for (const element of elements) { if (element.localName == "turbo-frame") { element.removeAttribute("busy"); } element.removeAttribute("aria-busy"); } } function waitForLoad(element, timeoutInMilliseconds = 2e3) { return new Promise((resolve) => { const onComplete = () => { element.removeEventListener("error", onComplete); element.removeEventListener("load", onComplete); resolve(); }; element.addEventListener("load", onComplete, { once: true }); element.addEventListener("error", onComplete, { once: true }); setTimeout(resolve, timeoutInMilliseconds); }); } function getHistoryMethodForAction(action) { switch (action) { case "replace": return history.replaceState; case "advance": case "restore": return history.pushState; } } function isAction(action) { return action == "advance" || action == "replace" || action == "restore"; } function getVisitAction(...elements) { const action = getAttribute("data-turbo-action", ...elements); return isAction(action) ? action : null; } function getMetaElement(name) { return document.querySelector(`meta[name="${name}"]`); } function getMetaContent(name) { const element = getMetaElement(name); return element && element.content; } function setMetaContent(name, content) { let element = getMetaElement(name); if (!element) { element = document.createElement("meta"); element.setAttribute("name", name); document.head.appendChild(element); } element.setAttribute("content", content); return element; } function findClosestRecursively(element, selector) { var _a; if (element instanceof Element) { return element.closest(selector) || findClosestRecursively(element.assignedSlot || ((_a = element.getRootNode()) === null || _a === void 0 ? void 0 : _a.host), selector); } } var FetchMethod; (function(FetchMethod2) { FetchMethod2[FetchMethod2["get"] = 0] = "get"; FetchMethod2[FetchMethod2["post"] = 1] = "post"; FetchMethod2[FetchMethod2["put"] = 2] = "put"; FetchMethod2[FetchMethod2["patch"] = 3] = "patch"; FetchMethod2[FetchMethod2["delete"] = 4] = "delete"; })(FetchMethod || (FetchMethod = {})); function fetchMethodFromString(method) { switch (method.toLowerCase()) { case "get": return FetchMethod.get; case "post": return FetchMethod.post; case "put": return FetchMethod.put; case "patch": return FetchMethod.patch; case "delete": return FetchMethod.delete; } } var FetchRequest = class { constructor(delegate2, method, location2, body = new URLSearchParams(), target = null) { this.abortController = new AbortController(); this.resolveRequestPromise = (_value) => { }; this.delegate = delegate2; this.method = method; this.headers = this.defaultHeaders; this.body = body; this.url = location2; this.target = target; } get location() { return this.url; } get params() { return this.url.searchParams; } get entries() { return this.body ? Array.from(this.body.entries()) : []; } cancel() { this.abortController.abort(); } async perform() { const { fetchOptions } = this; this.delegate.prepareRequest(this); await this.allowRequestToBeIntercepted(fetchOptions); try { this.delegate.requestStarted(this); const response = await fetch(this.url.href, fetchOptions); return await this.receive(response); } catch (error) { if (error.name !== "AbortError") { if (this.willDelegateErrorHandling(error)) { this.delegate.requestErrored(this, error); } throw error; } } finally { this.delegate.requestFinished(this); } } async receive(response) { const fetchResponse = new FetchResponse(response); const event = dispatch("turbo:before-fetch-response", { cancelable: true, detail: { fetchResponse }, target: this.target }); if (event.defaultPrevented) { this.delegate.requestPreventedHandlingResponse(this, fetchResponse); } else if (fetchResponse.succeeded) { this.delegate.requestSucceededWithResponse(this, fetchResponse); } else { this.delegate.requestFailedWithResponse(this, fetchResponse); } return fetchResponse; } get fetchOptions() { var _a; return { method: FetchMethod[this.method].toUpperCase(), credentials: "same-origin", headers: this.headers, redirect: "follow", body: this.isSafe ? null : this.body, signal: this.abortSignal, referrer: (_a = this.delegate.referrer) === null || _a === void 0 ? void 0 : _a.href }; } get defaultHeaders() { return { Accept: "text/html, application/xhtml+xml" }; } get isSafe() { return this.method === FetchMethod.get; } get abortSignal() { return this.abortController.signal; } acceptResponseType(mimeType) { this.headers["Accept"] = [mimeType, this.headers["Accept"]].join(", "); } async allowRequestToBeIntercepted(fetchOptions) { const requestInterception = new Promise((resolve) => this.resolveRequestPromise = resolve); const event = dispatch("turbo:before-fetch-request", { cancelable: true, detail: { fetchOptions, url: this.url, resume: this.resolveRequestPromise }, target: this.target }); if (event.defaultPrevented) await requestInterception; } willDelegateErrorHandling(error) { const event = dispatch("turbo:fetch-request-error", { target: this.target, cancelable: true, detail: { request: this, error } }); return !event.defaultPrevented; } }; var AppearanceObserver = class { constructor(delegate2, element) { this.started = false; this.intersect = (entries) => { const lastEntry = entries.slice(-1)[0]; if (lastEntry === null || lastEntry === void 0 ? void 0 : lastEntry.isIntersecting) { this.delegate.elementAppearedInViewport(this.element); } }; this.delegate = delegate2; this.element = element; this.intersectionObserver = new IntersectionObserver(this.intersect); } start() { if (!this.started) { this.started = true; this.intersectionObserver.observe(this.element); } } stop() { if (this.started) { this.started = false; this.intersectionObserver.unobserve(this.element); } } }; var StreamMessage = class { static wrap(message) { if (typeof message == "string") { return new this(createDocumentFragment(message)); } else { return message; } } constructor(fragment) { this.fragment = importStreamElements(fragment); } }; StreamMessage.contentType = "text/vnd.turbo-stream.html"; function importStreamElements(fragment) { for (const element of fragment.querySelectorAll("turbo-stream")) { const streamElement = document.importNode(element, true); for (const inertScriptElement of streamElement.templateElement.content.querySelectorAll("script")) { inertScriptElement.replaceWith(activateScriptElement(inertScriptElement)); } element.replaceWith(streamElement); } return fragment; } var FormSubmissionState; (function(FormSubmissionState2) { FormSubmissionState2[FormSubmissionState2["initialized"] = 0] = "initialized"; FormSubmissionState2[FormSubmissionState2["requesting"] = 1] = "requesting"; FormSubmissionState2[FormSubmissionState2["waiting"] = 2] = "waiting"; FormSubmissionState2[FormSubmissionState2["receiving"] = 3] = "receiving"; FormSubmissionState2[FormSubmissionState2["stopping"] = 4] = "stopping"; FormSubmissionState2[FormSubmissionState2["stopped"] = 5] = "stopped"; })(FormSubmissionState || (FormSubmissionState = {})); var FormEnctype; (function(FormEnctype2) { FormEnctype2["urlEncoded"] = "application/x-www-form-urlencoded"; FormEnctype2["multipart"] = "multipart/form-data"; FormEnctype2["plain"] = "text/plain"; })(FormEnctype || (FormEnctype = {})); function formEnctypeFromString(encoding) { switch (encoding.toLowerCase()) { case FormEnctype.multipart: return FormEnctype.multipart; case FormEnctype.plain: return FormEnctype.plain; default: return FormEnctype.urlEncoded; } } var FormSubmission = class { static confirmMethod(message, _element, _submitter) { return Promise.resolve(confirm(message)); } constructor(delegate2, formElement, submitter, mustRedirect = false) { this.state = FormSubmissionState.initialized; this.delegate = delegate2; this.formElement = formElement; this.submitter = submitter; this.formData = buildFormData(formElement, submitter); this.location = expandURL(this.action); if (this.method == FetchMethod.get) { mergeFormDataEntries(this.location, [...this.body.entries()]); } this.fetchRequest = new FetchRequest(this, this.method, this.location, this.body, this.formElement); this.mustRedirect = mustRedirect; } get method() { var _a; const method = ((_a = this.submitter) === null || _a === void 0 ? void 0 : _a.getAttribute("formmethod")) || this.formElement.getAttribute("method") || ""; return fetchMethodFromString(method.toLowerCase()) || FetchMethod.get; } get action() { var _a; const formElementAction = typeof this.formElement.action === "string" ? this.formElement.action : null; if ((_a = this.submitter) === null || _a === void 0 ? void 0 : _a.hasAttribute("formaction")) { return this.submitter.getAttribute("formaction") || ""; } else { return this.formElement.getAttribute("action") || formElementAction || ""; } } get body() { if (this.enctype == FormEnctype.urlEncoded || this.method == FetchMethod.get) { return new URLSearchParams(this.stringFormData); } else { return this.formData; } } get enctype() { var _a; return formEnctypeFromString(((_a = this.submitter) === null || _a === void 0 ? void 0 : _a.getAttribute("formenctype")) || this.formElement.enctype); } get isSafe() { return this.fetchRequest.isSafe; } get stringFormData() { return [...this.formData].reduce((entries, [name, value]) => { return entries.concat(typeof value == "string" ? [[name, value]] : []); }, []); } async start() { const { initialized, requesting } = FormSubmissionState; const confirmationMessage = getAttribute("data-turbo-confirm", this.submitter, this.formElement); if (typeof confirmationMessage === "string") { const answer = await FormSubmission.confirmMethod(confirmationMessage, this.formElement, this.submitter); if (!answer) { return; } } if (this.state == initialized) { this.state = requesting; return this.fetchRequest.perform(); } } stop() { const { stopping, stopped } = FormSubmissionState; if (this.state != stopping && this.state != stopped) { this.state = stopping; this.fetchRequest.cancel(); return true; } } prepareRequest(request) { if (!request.isSafe) { const token = getCookieValue(getMetaContent("csrf-param")) || getMetaContent("csrf-token"); if (token) { request.headers["X-CSRF-Token"] = token; } } if (this.requestAcceptsTurboStreamResponse(request)) { request.acceptResponseType(StreamMessage.contentType); } } requestStarted(_request) { var _a; this.state = FormSubmissionState.waiting; (_a = this.submitter) === null || _a === void 0 ? void 0 : _a.setAttribute("disabled", ""); this.setSubmitsWith(); dispatch("turbo:submit-start", { target: this.formElement, detail: { formSubmission: this } }); this.delegate.formSubmissionStarted(this); } requestPreventedHandlingResponse(request, response) { this.result = { success: response.succeeded, fetchResponse: response }; } requestSucceededWithResponse(request, response) { if (response.clientError || response.serverError) { this.delegate.formSubmissionFailedWithResponse(this, response); } else if (this.requestMustRedirect(request) && responseSucceededWithoutRedirect(response)) { const error = new Error("Form responses must redirect to another location"); this.delegate.formSubmissionErrored(this, error); } else { this.state = FormSubmissionState.receiving; this.result = { success: true, fetchResponse: response }; this.delegate.formSubmissionSucceededWithResponse(this, response); } } requestFailedWithResponse(request, response) { this.result = { success: false, fetchResponse: response }; this.delegate.formSubmissionFailedWithResponse(this, response); } requestErrored(request, error) { this.result = { success: false, error }; this.delegate.formSubmissionErrored(this, error); } requestFinished(_request) { var _a; this.state = FormSubmissionState.stopped; (_a = this.submitter) === null || _a === void 0 ? void 0 : _a.removeAttribute("disabled"); this.resetSubmitterText(); dispatch("turbo:submit-end", { target: this.formElement, detail: Object.assign({ formSubmission: this }, this.result) }); this.delegate.formSubmissionFinished(this); } setSubmitsWith() { if (!this.submitter || !this.submitsWith) return; if (this.submitter.matches("button")) { this.originalSubmitText = this.submitter.innerHTML; this.submitter.innerHTML = this.submitsWith; } else if (this.submitter.matches("input")) { const input = this.submitter; this.originalSubmitText = input.value; input.value = this.submitsWith; } } resetSubmitterText() { if (!this.submitter || !this.originalSubmitText) return; if (this.submitter.matches("button")) { this.submitter.innerHTML = this.originalSubmitText; } else if (this.submitter.matches("input")) { const input = this.submitter; input.value = this.originalSubmitText; } } requestMustRedirect(request) { return !request.isSafe && this.mustRedirect; } requestAcceptsTurboStreamResponse(request) { return !request.isSafe || hasAttribute("data-turbo-stream", this.submitter, this.formElement); } get submitsWith() { var _a; return (_a = this.submitter) === null || _a === void 0 ? void 0 : _a.getAttribute("data-turbo-submits-with"); } }; function buildFormData(formElement, submitter) { const formData = new FormData(formElement); const name = submitter === null || submitter === void 0 ? void 0 : submitter.getAttribute("name"); const value = submitter === null || submitter === void 0 ? void 0 : submitter.getAttribute("value"); if (name) { formData.append(name, value || ""); } return formData; } function getCookieValue(cookieName) { if (cookieName != null) { const cookies = document.cookie ? document.cookie.split("; ") : []; const cookie = cookies.find((cookie2) => cookie2.startsWith(cookieName)); if (cookie) { const value = cookie.split("=").slice(1).join("="); return value ? decodeURIComponent(value) : void 0; } } } function responseSucceededWithoutRedirect(response) { return response.statusCode == 200 && !response.redirected; } function mergeFormDataEntries(url, entries) { const searchParams = new URLSearchParams(); for (const [name, value] of entries) { if (value instanceof File) continue; searchParams.append(name, value); } url.search = searchParams.toString(); return url; } var Snapshot = class { constructor(element) { this.element = element; } get activeElement() { return this.element.ownerDocument.activeElement; } get children() { return [...this.element.children]; } hasAnchor(anchor) { return this.getElementForAnchor(anchor) != null; } getElementForAnchor(anchor) { return anchor ? this.element.querySelector(`[id='${anchor}'], a[name='${anchor}']`) : null; } get isConnected() { return this.element.isConnected; } get firstAutofocusableElement() { const inertDisabledOrHidden = "[inert], :disabled, [hidden], details:not([open]), dialog:not([open])"; for (const element of this.element.querySelectorAll("[autofocus]")) { if (element.closest(inertDisabledOrHidden) == null) return element; else continue; } return null; } get permanentElements() { return queryPermanentElementsAll(this.element); } getPermanentElementById(id) { return getPermanentElementById(this.element, id); } getPermanentElementMapForSnapshot(snapshot) { const permanentElementMap = {}; for (const currentPermanentElement of this.permanentElements) { const { id } = currentPermanentElement; const newPermanentElement = snapshot.getPermanentElementById(id); if (newPermanentElement) { permanentElementMap[id] = [currentPermanentElement, newPermanentElement]; } } return permanentElementMap; } }; function getPermanentElementById(node, id) { return node.querySelector(`#${id}[data-turbo-permanent]`); } function queryPermanentElementsAll(node) { return node.querySelectorAll("[id][data-turbo-permanent]"); } var FormSubmitObserver = class { constructor(delegate2, eventTarget) { this.started = false; this.submitCaptured = () => { this.eventTarget.removeEventListener("submit", this.submitBubbled, false); this.eventTarget.addEventListener("submit", this.submitBubbled, false); }; this.submitBubbled = (event) => { if (!event.defaultPrevented) { const form = event.target instanceof HTMLFormElement ? event.target : void 0; const submitter = event.submitter || void 0; if (form && submissionDoesNotDismissDialog(form, submitter) && submissionDoesNotTargetIFrame(form, submitter) && this.delegate.willSubmitForm(form, submitter)) { event.preventDefault(); event.stopImmediatePropagation(); this.delegate.formSubmitted(form, submitter); } } }; this.delegate = delegate2; this.eventTarget = eventTarget; } start() { if (!this.started) { this.eventTarget.addEventListener("submit", this.submitCaptured, true); this.started = true; } } stop() { if (this.started) { this.eventTarget.removeEventListener("submit", this.submitCaptured, true); this.started = false; } } }; function submissionDoesNotDismissDialog(form, submitter) { const method = (submitter === null || submitter === void 0 ? void 0 : submitter.getAttribute("formmethod")) || form.getAttribute("method"); return method != "dialog"; } function submissionDoesNotTargetIFrame(form, submitter) { if ((submitter === null || submitter === void 0 ? void 0 : submitter.hasAttribute("formtarget")) || form.hasAttribute("target")) { const target = (submitter === null || submitter === void 0 ? void 0 : submitter.getAttribute("formtarget")) || form.target; for (const element of document.getElementsByName(target)) { if (element instanceof HTMLIFrameElement) return false; } return true; } else { return true; } } var View = class { constructor(delegate2, element) { this.resolveRenderPromise = (_value) => { }; this.resolveInterceptionPromise = (_value) => { }; this.delegate = delegate2; this.element = element; } scrollToAnchor(anchor) { const element = this.snapshot.getElementForAnchor(anchor); if (element) { this.scrollToElement(element); this.focusElement(element); } else { this.scrollToPosition({ x: 0, y: 0 }); } } scrollToAnchorFromLocation(location2) { this.scrollToAnchor(getAnchor(location2)); } scrollToElement(element) { element.scrollIntoView(); } focusElement(element) { if (element instanceof HTMLElement) { if (element.hasAttribute("tabindex")) { element.focus(); } else { element.setAttribute("tabindex", "-1"); element.focus(); element.removeAttribute("tabindex"); } } } scrollToPosition({ x: x2, y: y2 }) { this.scrollRoot.scrollTo(x2, y2); } scrollToTop() { this.scrollToPosition({ x: 0, y: 0 }); } get scrollRoot() { return window; } async render(renderer) { const { isPreview, shouldRender, newSnapshot: snapshot } = renderer; if (shouldRender) { try { this.renderPromise = new Promise((resolve) => this.resolveRenderPromise = resolve); this.renderer = renderer; await this.prepareToRenderSnapshot(renderer); const renderInterception = new Promise((resolve) => this.resolveInterceptionPromise = resolve); const options = { resume: this.resolveInterceptionPromise, render: this.renderer.renderElement }; const immediateRender = this.delegate.allowsImmediateRender(snapshot, options); if (!immediateRender) await renderInterception; await this.renderSnapshot(renderer); this.delegate.viewRenderedSnapshot(snapshot, isPreview); this.delegate.preloadOnLoadLinksForView(this.element); this.finishRenderingSnapshot(renderer); } finally { delete this.renderer; this.resolveRenderPromise(void 0); delete this.renderPromise; } } else { this.invalidate(renderer.reloadReason); } } invalidate(reason) { this.delegate.viewInvalidated(reason); } async prepareToRenderSnapshot(renderer) { this.markAsPreview(renderer.isPreview); await renderer.prepareToRender(); } markAsPreview(isPreview) { if (isPreview) { this.element.setAttribute("data-turbo-preview", ""); } else { this.element.removeAttribute("data-turbo-preview"); } } async renderSnapshot(renderer) { await renderer.render(); } finishRenderingSnapshot(renderer) { renderer.finishRendering(); } }; var FrameView = class extends View { missing() { this.element.innerHTML = `Content missing`; } get snapshot() { return new Snapshot(this.element); } }; var LinkInterceptor = class { constructor(delegate2, element) { this.clickBubbled = (event) => { if (this.respondsToEventTarget(event.target)) { this.clickEvent = event; } else { delete this.clickEvent; } }; this.linkClicked = (event) => { if (this.clickEvent && this.respondsToEventTarget(event.target) && event.target instanceof Element) { if (this.delegate.shouldInterceptLinkClick(event.target, event.detail.url, event.detail.originalEvent)) { this.clickEvent.preventDefault(); event.preventDefault(); this.delegate.linkClickIntercepted(event.target, event.detail.url, event.detail.originalEvent); } } delete this.clickEvent; }; this.willVisit = (_event) => { delete this.clickEvent; }; this.delegate = delegate2; this.element = element; } start() { this.element.addEventListener("click", this.clickBubbled); document.addEventListener("turbo:click", this.linkClicked); document.addEventListener("turbo:before-visit", this.willVisit); } stop() { this.element.removeEventListener("click", this.clickBubbled); document.removeEventListener("turbo:click", this.linkClicked); document.removeEventListener("turbo:before-visit", this.willVisit); } respondsToEventTarget(target) { const element = target instanceof Element ? target : target instanceof Node ? target.parentElement : null; return element && element.closest("turbo-frame, html") == this.element; } }; var LinkClickObserver = class { constructor(delegate2, eventTarget) { this.started = false; this.clickCaptured = () => { this.eventTarget.removeEventListener("click", this.clickBubbled, false); this.eventTarget.addEventListener("click", this.clickBubbled, false); }; this.clickBubbled = (event) => { if (event instanceof MouseEvent && this.clickEventIsSignificant(event)) { const target = event.composedPath && event.composedPath()[0] || event.target; const link = this.findLinkFromClickTarget(target); if (link && doesNotTargetIFrame(link)) { const location2 = this.getLocationForLink(link); if (this.delegate.willFollowLinkToLocation(link, location2, event)) { event.preventDefault(); this.delegate.followedLinkToLocation(link, location2); } } } }; this.delegate = delegate2; this.eventTarget = eventTarget; } start() { if (!this.started) { this.eventTarget.addEventListener("click", this.clickCaptured, true); this.started = true; } } stop() { if (this.started) { this.eventTarget.removeEventListener("click", this.clickCaptured, true); this.started = false; } } clickEventIsSignificant(event) { return !(event.target && event.target.isContentEditable || event.defaultPrevented || event.which > 1 || event.altKey || event.ctrlKey || event.metaKey || event.shiftKey); } findLinkFromClickTarget(target) { return findClosestRecursively(target, "a[href]:not([target^=_]):not([download])"); } getLocationForLink(link) { return expandURL(link.getAttribute("href") || ""); } }; function doesNotTargetIFrame(anchor) { if (anchor.hasAttribute("target")) { for (const element of document.getElementsByName(anchor.target)) { if (element instanceof HTMLIFrameElement) return false; } return true; } else { return true; } } var FormLinkClickObserver = class { constructor(delegate2, element) { this.delegate = delegate2; this.linkInterceptor = new LinkClickObserver(this, element); } start() { this.linkInterceptor.start(); } stop() { this.linkInterceptor.stop(); } willFollowLinkToLocation(link, location2, originalEvent) { return this.delegate.willSubmitFormLinkToLocation(link, location2, originalEvent) && link.hasAttribute("data-turbo-method"); } followedLinkToLocation(link, location2) { const form = document.createElement("form"); const type = "hidden"; for (const [name, value] of location2.searchParams) { form.append(Object.assign(document.createElement("input"), { type, name, value })); } const action = Object.assign(location2, { search: "" }); form.setAttribute("data-turbo", "true"); form.setAttribute("action", action.href); form.setAttribute("hidden", ""); const method = link.getAttribute("data-turbo-method"); if (method) form.setAttribute("method", method); const turboFrame = link.getAttribute("data-turbo-frame"); if (turboFrame) form.setAttribute("data-turbo-frame", turboFrame); const turboAction = getVisitAction(link); if (turboAction) form.setAttribute("data-turbo-action", turboAction); const turboConfirm = link.getAttribute("data-turbo-confirm"); if (turboConfirm) form.setAttribute("data-turbo-confirm", turboConfirm); const turboStream = link.hasAttribute("data-turbo-stream"); if (turboStream) form.setAttribute("data-turbo-stream", ""); this.delegate.submittedFormLinkToLocation(link, location2, form); document.body.appendChild(form); form.addEventListener("turbo:submit-end", () => form.remove(), { once: true }); requestAnimationFrame(() => form.requestSubmit()); } }; var Bardo = class { static async preservingPermanentElements(delegate2, permanentElementMap, callback) { const bardo = new this(delegate2, permanentElementMap); bardo.enter(); await callback(); bardo.leave(); } constructor(delegate2, permanentElementMap) { this.delegate = delegate2; this.permanentElementMap = permanentElementMap; } enter() { for (const id in this.permanentElementMap) { const [currentPermanentElement, newPermanentElement] = this.permanentElementMap[id]; this.delegate.enteringBardo(currentPermanentElement, newPermanentElement); this.replaceNewPermanentElementWithPlaceholder(newPermanentElement); } } leave() { for (const id in this.permanentElementMap) { const [currentPermanentElement] = this.permanentElementMap[id]; this.replaceCurrentPermanentElementWithClone(currentPermanentElement); this.replacePlaceholderWithPermanentElement(currentPermanentElement); this.delegate.leavingBardo(currentPermanentElement); } } replaceNewPermanentElementWithPlaceholder(permanentElement) { const placeholder = createPlaceholderForPermanentElement(permanentElement); permanentElement.replaceWith(placeholder); } replaceCurrentPermanentElementWithClone(permanentElement) { const clone = permanentElement.cloneNode(true); permanentElement.replaceWith(clone); } replacePlaceholderWithPermanentElement(permanentElement) { const placeholder = this.getPlaceholderById(permanentElement.id); placeholder === null || placeholder === void 0 ? void 0 : placeholder.replaceWith(permanentElement); } getPlaceholderById(id) { return this.placeholders.find((element) => element.content == id); } get placeholders() { return [...document.querySelectorAll("meta[name=turbo-permanent-placeholder][content]")]; } }; function createPlaceholderForPermanentElement(permanentElement) { const element = document.createElement("meta"); element.setAttribute("name", "turbo-permanent-placeholder"); element.setAttribute("content", permanentElement.id); return element; } var Renderer = class { constructor(currentSnapshot, newSnapshot, renderElement, isPreview, willRender = true) { this.activeElement = null; this.currentSnapshot = currentSnapshot; this.newSnapshot = newSnapshot; this.isPreview = isPreview; this.willRender = willRender; this.renderElement = renderElement; this.promise = new Promise((resolve, reject) => this.resolvingFunctions = { resolve, reject }); } get shouldRender() { return true; } get reloadReason() { return; } prepareToRender() { return; } finishRendering() { if (this.resolvingFunctions) { this.resolvingFunctions.resolve(); delete this.resolvingFunctions; } } async preservingPermanentElements(callback) { await Bardo.preservingPermanentElements(this, this.permanentElementMap, callback); } focusFirstAutofocusableElement() { const element = this.connectedSnapshot.firstAutofocusableElement; if (elementIsFocusable(element)) { element.focus(); } } enteringBardo(currentPermanentElement) { if (this.activeElement) return; if (currentPermanentElement.contains(this.currentSnapshot.activeElement)) { this.activeElement = this.currentSnapshot.activeElement; } } leavingBardo(currentPermanentElement) { if (currentPermanentElement.contains(this.activeElement) && this.activeElement instanceof HTMLElement) { this.activeElement.focus(); this.activeElement = null; } } get connectedSnapshot() { return this.newSnapshot.isConnected ? this.newSnapshot : this.currentSnapshot; } get currentElement() { return this.currentSnapshot.element; } get newElement() { return this.newSnapshot.element; } get permanentElementMap() { return this.currentSnapshot.getPermanentElementMapForSnapshot(this.newSnapshot); } }; function elementIsFocusable(element) { return element && typeof element.focus == "function"; } var FrameRenderer = class extends Renderer { static renderElement(currentElement2, newElement) { var _a; const destinationRange = document.createRange(); destinationRange.selectNodeContents(currentElement2); destinationRange.deleteContents(); const frameElement = newElement; const sourceRange = (_a = frameElement.ownerDocument) === null || _a === void 0 ? void 0 : _a.createRange(); if (sourceRange) { sourceRange.selectNodeContents(frameElement); currentElement2.appendChild(sourceRange.extractContents()); } } constructor(delegate2, currentSnapshot, newSnapshot, renderElement, isPreview, willRender = true) { super(currentSnapshot, newSnapshot, renderElement, isPreview, willRender); this.delegate = delegate2; } get shouldRender() { return true; } async render() { await nextAnimationFrame(); this.preservingPermanentElements(() => { this.loadFrameElement(); }); this.scrollFrameIntoView(); await nextAnimationFrame(); this.focusFirstAutofocusableElement(); await nextAnimationFrame(); this.activateScriptElements(); } loadFrameElement() { this.delegate.willRenderFrame(this.currentElement, this.newElement); this.renderElement(this.currentElement, this.newElement); } scrollFrameIntoView() { if (this.currentElement.autoscroll || this.newElement.autoscroll) { const element = this.currentElement.firstElementChild; const block = readScrollLogicalPosition(this.currentElement.getAttribute("data-autoscroll-block"), "end"); const behavior = readScrollBehavior(this.currentElement.getAttribute("data-autoscroll-behavior"), "auto"); if (element) { element.scrollIntoView({ block, behavior }); return true; } } return false; } activateScriptElements() { for (const inertScriptElement of this.newScriptElements) { const activatedScriptElement = activateScriptElement(inertScriptElement); inertScriptElement.replaceWith(activatedScriptElement); } } get newScriptElements() { return this.currentElement.querySelectorAll("script"); } }; function readScrollLogicalPosition(value, defaultValue) { if (value == "end" || value == "start" || value == "center" || value == "nearest") { return value; } else { return defaultValue; } } function readScrollBehavior(value, defaultValue) { if (value == "auto" || value == "smooth") { return value; } else { return defaultValue; } } var ProgressBar = class { static get defaultCSS() { return unindent` .turbo-progress-bar { position: fixed; display: block; top: 0; left: 0; height: 3px; background: #0076ff; z-index: 2147483647; transition: width ${ProgressBar.animationDuration}ms ease-out, opacity ${ProgressBar.animationDuration / 2}ms ${ProgressBar.animationDuration / 2}ms ease-in; transform: translate3d(0, 0, 0); } `; } constructor() { this.hiding = false; this.value = 0; this.visible = false; this.trickle = () => { this.setValue(this.value + Math.random() / 100); }; this.stylesheetElement = this.createStylesheetElement(); this.progressElement = this.createProgressElement(); this.installStylesheetElement(); this.setValue(0); } show() { if (!this.visible) { this.visible = true; this.installProgressElement(); this.startTrickling(); } } hide() { if (this.visible && !this.hiding) { this.hiding = true; this.fadeProgressElement(() => { this.uninstallProgressElement(); this.stopTrickling(); this.visible = false; this.hiding = false; }); } } setValue(value) { this.value = value; this.refresh(); } installStylesheetElement() { document.head.insertBefore(this.stylesheetElement, document.head.firstChild); } installProgressElement() { this.progressElement.style.width = "0"; this.progressElement.style.opacity = "1"; document.documentElement.insertBefore(this.progressElement, document.body); this.refresh(); } fadeProgressElement(callback) { this.progressElement.style.opacity = "0"; setTimeout(callback, ProgressBar.animationDuration * 1.5); } uninstallProgressElement() { if (this.progressElement.parentNode) { document.documentElement.removeChild(this.progressElement); } } startTrickling() { if (!this.trickleInterval) { this.trickleInterval = window.setInterval(this.trickle, ProgressBar.animationDuration); } } stopTrickling() { window.clearInterval(this.trickleInterval); delete this.trickleInterval; } refresh() { requestAnimationFrame(() => { this.progressElement.style.width = `${10 + this.value * 90}%`; }); } createStylesheetElement() { const element = document.createElement("style"); element.type = "text/css"; element.textContent = ProgressBar.defaultCSS; if (this.cspNonce) { element.nonce = this.cspNonce; } return element; } createProgressElement() { const element = document.createElement("div"); element.className = "turbo-progress-bar"; return element; } get cspNonce() { return getMetaContent("csp-nonce"); } }; ProgressBar.animationDuration = 300; var HeadSnapshot = class extends Snapshot { constructor() { super(...arguments); this.detailsByOuterHTML = this.children.filter((element) => !elementIsNoscript(element)).map((element) => elementWithoutNonce(element)).reduce((result, element) => { const { outerHTML } = element; const details = outerHTML in result ? result[outerHTML] : { type: elementType(element), tracked: elementIsTracked(element), elements: [] }; return Object.assign(Object.assign({}, result), { [outerHTML]: Object.assign(Object.assign({}, details), { elements: [...details.elements, element] }) }); }, {}); } get trackedElementSignature() { return Object.keys(this.detailsByOuterHTML).filter((outerHTML) => this.detailsByOuterHTML[outerHTML].tracked).join(""); } getScriptElementsNotInSnapshot(snapshot) { return this.getElementsMatchingTypeNotInSnapshot("script", snapshot); } getStylesheetElementsNotInSnapshot(snapshot) { return this.getElementsMatchingTypeNotInSnapshot("stylesheet", snapshot); } getElementsMatchingTypeNotInSnapshot(matchedType, snapshot) { return Object.keys(this.detailsByOuterHTML).filter((outerHTML) => !(outerHTML in snapshot.detailsByOuterHTML)).map((outerHTML) => this.detailsByOuterHTML[outerHTML]).filter(({ type }) => type == matchedType).map(({ elements: [element] }) => element); } get provisionalElements() { return Object.keys(this.detailsByOuterHTML).reduce((result, outerHTML) => { const { type, tracked, elements } = this.detailsByOuterHTML[outerHTML]; if (type == null && !tracked) { return [...result, ...elements]; } else if (elements.length > 1) { return [...result, ...elements.slice(1)]; } else { return result; } }, []); } getMetaValue(name) { const element = this.findMetaElementByName(name); return element ? element.getAttribute("content") : null; } findMetaElementByName(name) { return Object.keys(this.detailsByOuterHTML).reduce((result, outerHTML) => { const { elements: [element] } = this.detailsByOuterHTML[outerHTML]; return elementIsMetaElementWithName(element, name) ? element : result; }, void 0); } }; function elementType(element) { if (elementIsScript(element)) { return "script"; } else if (elementIsStylesheet(element)) { return "stylesheet"; } } function elementIsTracked(element) { return element.getAttribute("data-turbo-track") == "reload"; } function elementIsScript(element) { const tagName = element.localName; return tagName == "script"; } function elementIsNoscript(element) { const tagName = element.localName; return tagName == "noscript"; } function elementIsStylesheet(element) { const tagName = element.localName; return tagName == "style" || tagName == "link" && element.getAttribute("rel") == "stylesheet"; } function elementIsMetaElementWithName(element, name) { const tagName = element.localName; return tagName == "meta" && element.getAttribute("name") == name; } function elementWithoutNonce(element) { if (element.hasAttribute("nonce")) { element.setAttribute("nonce", ""); } return element; } var PageSnapshot = class extends Snapshot { static fromHTMLString(html = "") { return this.fromDocument(parseHTMLDocument(html)); } static fromElement(element) { return this.fromDocument(element.ownerDocument); } static fromDocument({ head, body }) { return new this(body, new HeadSnapshot(head)); } constructor(element, headSnapshot) { super(element); this.headSnapshot = headSnapshot; } clone() { const clonedElement = this.element.cloneNode(true); const selectElements = this.element.querySelectorAll("select"); const clonedSelectElements = clonedElement.querySelectorAll("select"); for (const [index, source] of selectElements.entries()) { const clone = clonedSelectElements[index]; for (const option of clone.selectedOptions) option.selected = false; for (const option of source.selectedOptions) clone.options[option.index].selected = true; } for (const clonedPasswordInput of clonedElement.querySelectorAll('input[type="password"]')) { clonedPasswordInput.value = ""; } return new PageSnapshot(clonedElement, this.headSnapshot); } get headElement() { return this.headSnapshot.element; } get rootLocation() { var _a; const root = (_a = this.getSetting("root")) !== null && _a !== void 0 ? _a : "/"; return expandURL(root); } get cacheControlValue() { return this.getSetting("cache-control"); } get isPreviewable() { return this.cacheControlValue != "no-preview"; } get isCacheable() { return this.cacheControlValue != "no-cache"; } get isVisitable() { return this.getSetting("visit-control") != "reload"; } getSetting(name) { return this.headSnapshot.getMetaValue(`turbo-${name}`); } }; var TimingMetric; (function(TimingMetric2) { TimingMetric2["visitStart"] = "visitStart"; TimingMetric2["requestStart"] = "requestStart"; TimingMetric2["requestEnd"] = "requestEnd"; TimingMetric2["visitEnd"] = "visitEnd"; })(TimingMetric || (TimingMetric = {})); var VisitState; (function(VisitState2) { VisitState2["initialized"] = "initialized"; VisitState2["started"] = "started"; VisitState2["canceled"] = "canceled"; VisitState2["failed"] = "failed"; VisitState2["completed"] = "completed"; })(VisitState || (VisitState = {})); var defaultOptions = { action: "advance", historyChanged: false, visitCachedSnapshot: () => { }, willRender: true, updateHistory: true, shouldCacheSnapshot: true, acceptsStreamResponse: false }; var SystemStatusCode; (function(SystemStatusCode2) { SystemStatusCode2[SystemStatusCode2["networkFailure"] = 0] = "networkFailure"; SystemStatusCode2[SystemStatusCode2["timeoutFailure"] = -1] = "timeoutFailure"; SystemStatusCode2[SystemStatusCode2["contentTypeMismatch"] = -2] = "contentTypeMismatch"; })(SystemStatusCode || (SystemStatusCode = {})); var Visit = class { constructor(delegate2, location2, restorationIdentifier, options = {}) { this.identifier = uuid(); this.timingMetrics = {}; this.followedRedirect = false; this.historyChanged = false; this.scrolled = false; this.shouldCacheSnapshot = true; this.acceptsStreamResponse = false; this.snapshotCached = false; this.state = VisitState.initialized; this.delegate = delegate2; this.location = location2; this.restorationIdentifier = restorationIdentifier || uuid(); const { action, historyChanged, referrer, snapshot, snapshotHTML, response, visitCachedSnapshot, willRender, updateHistory, shouldCacheSnapshot, acceptsStreamResponse } = Object.assign(Object.assign({}, defaultOptions), options); this.action = action; this.historyChanged = historyChanged; this.referrer = referrer; this.snapshot = snapshot; this.snapshotHTML = snapshotHTML; this.response = response; this.isSamePage = this.delegate.locationWithActionIsSamePage(this.location, this.action); this.visitCachedSnapshot = visitCachedSnapshot; this.willRender = willRender; this.updateHistory = updateHistory; this.scrolled = !willRender; this.shouldCacheSnapshot = shouldCacheSnapshot; this.acceptsStreamResponse = acceptsStreamResponse; } get adapter() { return this.delegate.adapter; } get view() { return this.delegate.view; } get history() { return this.delegate.history; } get restorationData() { return this.history.getRestorationDataForIdentifier(this.restorationIdentifier); } get silent() { return this.isSamePage; } start() { if (this.state == VisitState.initialized) { this.recordTimingMetric(TimingMetric.visitStart); this.state = VisitState.started; this.adapter.visitStarted(this); this.delegate.visitStarted(this); } } cancel() { if (this.state == VisitState.started) { if (this.request) { this.request.cancel(); } this.cancelRender(); this.state = VisitState.canceled; } } complete() { if (this.state == VisitState.started) { this.recordTimingMetric(TimingMetric.visitEnd); this.state = VisitState.completed; this.followRedirect(); if (!this.followedRedirect) { this.adapter.visitCompleted(this); this.delegate.visitCompleted(this); } } } fail() { if (this.state == VisitState.started) { this.state = VisitState.failed; this.adapter.visitFailed(this); } } changeHistory() { var _a; if (!this.historyChanged && this.updateHistory) { const actionForHistory = this.location.href === ((_a = this.referrer) === null || _a === void 0 ? void 0 : _a.href) ? "replace" : this.action; const method = getHistoryMethodForAction(actionForHistory); this.history.update(method, this.location, this.restorationIdentifier); this.historyChanged = true; } } issueRequest() { if (this.hasPreloadedResponse()) { this.simulateRequest(); } else if (this.shouldIssueRequest() && !this.request) { this.request = new FetchRequest(this, FetchMethod.get, this.location); this.request.perform(); } } simulateRequest() { if (this.response) { this.startRequest(); this.recordResponse(); this.finishRequest(); } } startRequest() { this.recordTimingMetric(TimingMetric.requestStart); this.adapter.visitRequestStarted(this); } recordResponse(response = this.response) { this.response = response; if (response) { const { statusCode } = response; if (isSuccessful(statusCode)) { this.adapter.visitRequestCompleted(this); } else { this.adapter.visitRequestFailedWithStatusCode(this, statusCode); } } } finishRequest() { this.recordTimingMetric(TimingMetric.requestEnd); this.adapter.visitRequestFinished(this); } loadResponse() { if (this.response) { const { statusCode, responseHTML } = this.response; this.render(async () => { if (this.shouldCacheSnapshot) this.cacheSnapshot(); if (this.view.renderPromise) await this.view.renderPromise; if (isSuccessful(statusCode) && responseHTML != null) { await this.view.renderPage(PageSnapshot.fromHTMLString(responseHTML), false, this.willRender, this); this.performScroll(); this.adapter.visitRendered(this); this.complete(); } else { await this.view.renderError(PageSnapshot.fromHTMLString(responseHTML), this); this.adapter.visitRendered(this); this.fail(); } }); } } getCachedSnapshot() { const snapshot = this.view.getCachedSnapshotForLocation(this.location) || this.getPreloadedSnapshot(); if (snapshot && (!getAnchor(this.location) || snapshot.hasAnchor(getAnchor(this.location)))) { if (this.action == "restore" || snapshot.isPreviewable) { return snapshot; } } } getPreloadedSnapshot() { if (this.snapshotHTML) { return PageSnapshot.fromHTMLString(this.snapshotHTML); } } hasCachedSnapshot() { return this.getCachedSnapshot() != null; } loadCachedSnapshot() { const snapshot = this.getCachedSnapshot(); if (snapshot) { const isPreview = this.shouldIssueRequest(); this.render(async () => { this.cacheSnapshot(); if (this.isSamePage) { this.adapter.visitRendered(this); } else { if (this.view.renderPromise) await this.view.renderPromise; await this.view.renderPage(snapshot, isPreview, this.willRender, this); this.performScroll(); this.adapter.visitRendered(this); if (!isPreview) { this.complete(); } } }); } } followRedirect() { var _a; if (this.redirectedToLocation && !this.followedRedirect && ((_a = this.response) === null || _a === void 0 ? void 0 : _a.redirected)) { this.adapter.visitProposedToLocation(this.redirectedToLocation, { action: "replace", response: this.response, shouldCacheSnapshot: false, willRender: false }); this.followedRedirect = true; } } goToSamePageAnchor() { if (this.isSamePage) { this.render(async () => { this.cacheSnapshot(); this.performScroll(); this.changeHistory(); this.adapter.visitRendered(this); }); } } prepareRequest(request) { if (this.acceptsStreamResponse) { request.acceptResponseType(StreamMessage.contentType); } } requestStarted() { this.startRequest(); } requestPreventedHandlingResponse(_request, _response) { } async requestSucceededWithResponse(request, response) { const responseHTML = await response.responseHTML; const { redirected, statusCode } = response; if (responseHTML == void 0) { this.recordResponse({ statusCode: SystemStatusCode.contentTypeMismatch, redirected }); } else { this.redirectedToLocation = response.redirected ? response.location : void 0; this.recordResponse({ statusCode, responseHTML, redirected }); } } async requestFailedWithResponse(request, response) { const responseHTML = await response.responseHTML; const { redirected, statusCode } = response; if (responseHTML == void 0) { this.recordResponse({ statusCode: SystemStatusCode.contentTypeMismatch, redirected }); } else { this.recordResponse({ statusCode, responseHTML, redirected }); } } requestErrored(_request, _error) { this.recordResponse({ statusCode: SystemStatusCode.networkFailure, redirected: false }); } requestFinished() { this.finishRequest(); } performScroll() { if (!this.scrolled && !this.view.forceReloaded) { if (this.action == "restore") { this.scrollToRestoredPosition() || this.scrollToAnchor() || this.view.scrollToTop(); } else { this.scrollToAnchor() || this.view.scrollToTop(); } if (this.isSamePage) { this.delegate.visitScrolledToSamePageLocation(this.view.lastRenderedLocation, this.location); } this.scrolled = true; } } scrollToRestoredPosition() { const { scrollPosition } = this.restorationData; if (scrollPosition) { this.view.scrollToPosition(scrollPosition); return true; } } scrollToAnchor() { const anchor = getAnchor(this.location); if (anchor != null) { this.view.scrollToAnchor(anchor); return true; } } recordTimingMetric(metric) { this.timingMetrics[metric] = (/* @__PURE__ */ new Date()).getTime(); } getTimingMetrics() { return Object.assign({}, this.timingMetrics); } getHistoryMethodForAction(action) { switch (action) { case "replace": return history.replaceState; case "advance": case "restore": return history.pushState; } } hasPreloadedResponse() { return typeof this.response == "object"; } shouldIssueRequest() { if (this.isSamePage) { return false; } else if (this.action == "restore") { return !this.hasCachedSnapshot(); } else { return this.willRender; } } cacheSnapshot() { if (!this.snapshotCached) { this.view.cacheSnapshot(this.snapshot).then((snapshot) => snapshot && this.visitCachedSnapshot(snapshot)); this.snapshotCached = true; } } async render(callback) { this.cancelRender(); await new Promise((resolve) => { this.frame = requestAnimationFrame(() => resolve()); }); await callback(); delete this.frame; } cancelRender() { if (this.frame) { cancelAnimationFrame(this.frame); delete this.frame; } } }; function isSuccessful(statusCode) { return statusCode >= 200 && statusCode < 300; } var BrowserAdapter = class { constructor(session2) { this.progressBar = new ProgressBar(); this.showProgressBar = () => { this.progressBar.show(); }; this.session = session2; } visitProposedToLocation(location2, options) { this.navigator.startVisit(location2, (options === null || options === void 0 ? void 0 : options.restorationIdentifier) || uuid(), options); } visitStarted(visit3) { this.location = visit3.location; visit3.loadCachedSnapshot(); visit3.issueRequest(); visit3.goToSamePageAnchor(); } visitRequestStarted(visit3) { this.progressBar.setValue(0); if (visit3.hasCachedSnapshot() || visit3.action != "restore") { this.showVisitProgressBarAfterDelay(); } else { this.showProgressBar(); } } visitRequestCompleted(visit3) { visit3.loadResponse(); } visitRequestFailedWithStatusCode(visit3, statusCode) { switch (statusCode) { case SystemStatusCode.networkFailure: case SystemStatusCode.timeoutFailure: case SystemStatusCode.contentTypeMismatch: return this.reload({ reason: "request_failed", context: { statusCode } }); default: return visit3.loadResponse(); } } visitRequestFinished(_visit) { this.progressBar.setValue(1); this.hideVisitProgressBar(); } visitCompleted(_visit) { } pageInvalidated(reason) { this.reload(reason); } visitFailed(_visit) { } visitRendered(_visit) { } formSubmissionStarted(_formSubmission) { this.progressBar.setValue(0); this.showFormProgressBarAfterDelay(); } formSubmissionFinished(_formSubmission) { this.progressBar.setValue(1); this.hideFormProgressBar(); } showVisitProgressBarAfterDelay() { this.visitProgressBarTimeout = window.setTimeout(this.showProgressBar, this.session.progressBarDelay); } hideVisitProgressBar() { this.progressBar.hide(); if (this.visitProgressBarTimeout != null) { window.clearTimeout(this.visitProgressBarTimeout); delete this.visitProgressBarTimeout; } } showFormProgressBarAfterDelay() { if (this.formProgressBarTimeout == null) { this.formProgressBarTimeout = window.setTimeout(this.showProgressBar, this.session.progressBarDelay); } } hideFormProgressBar() { this.progressBar.hide(); if (this.formProgressBarTimeout != null) { window.clearTimeout(this.formProgressBarTimeout); delete this.formProgressBarTimeout; } } reload(reason) { var _a; dispatch("turbo:reload", { detail: reason }); window.location.href = ((_a = this.location) === null || _a === void 0 ? void 0 : _a.toString()) || window.location.href; } get navigator() { return this.session.navigator; } }; var CacheObserver = class { constructor() { this.selector = "[data-turbo-temporary]"; this.deprecatedSelector = "[data-turbo-cache=false]"; this.started = false; this.removeTemporaryElements = (_event) => { for (const element of this.temporaryElements) { element.remove(); } }; } start() { if (!this.started) { this.started = true; addEventListener("turbo:before-cache", this.removeTemporaryElements, false); } } stop() { if (this.started) { this.started = false; removeEventListener("turbo:before-cache", this.removeTemporaryElements, false); } } get temporaryElements() { return [...document.querySelectorAll(this.selector), ...this.temporaryElementsWithDeprecation]; } get temporaryElementsWithDeprecation() { const elements = document.querySelectorAll(this.deprecatedSelector); if (elements.length) { console.warn(`The ${this.deprecatedSelector} selector is deprecated and will be removed in a future version. Use ${this.selector} instead.`); } return [...elements]; } }; var FrameRedirector = class { constructor(session2, element) { this.session = session2; this.element = element; this.linkInterceptor = new LinkInterceptor(this, element); this.formSubmitObserver = new FormSubmitObserver(this, element); } start() { this.linkInterceptor.start(); this.formSubmitObserver.start(); } stop() { this.linkInterceptor.stop(); this.formSubmitObserver.stop(); } shouldInterceptLinkClick(element, _location, _event) { return this.shouldRedirect(element); } linkClickIntercepted(element, url, event) { const frame = this.findFrameElement(element); if (frame) { frame.delegate.linkClickIntercepted(element, url, event); } } willSubmitForm(element, submitter) { return element.closest("turbo-frame") == null && this.shouldSubmit(element, submitter) && this.shouldRedirect(element, submitter); } formSubmitted(element, submitter) { const frame = this.findFrameElement(element, submitter); if (frame) { frame.delegate.formSubmitted(element, submitter); } } shouldSubmit(form, submitter) { var _a; const action = getAction(form, submitter); const meta = this.element.ownerDocument.querySelector(`meta[name="turbo-root"]`); const rootLocation = expandURL((_a = meta === null || meta === void 0 ? void 0 : meta.content) !== null && _a !== void 0 ? _a : "/"); return this.shouldRedirect(form, submitter) && locationIsVisitable(action, rootLocation); } shouldRedirect(element, submitter) { const isNavigatable = element instanceof HTMLFormElement ? this.session.submissionIsNavigatable(element, submitter) : this.session.elementIsNavigatable(element); if (isNavigatable) { const frame = this.findFrameElement(element, submitter); return frame ? frame != element.closest("turbo-frame") : false; } else { return false; } } findFrameElement(element, submitter) { const id = (submitter === null || submitter === void 0 ? void 0 : submitter.getAttribute("data-turbo-frame")) || element.getAttribute("data-turbo-frame"); if (id && id != "_top") { const frame = this.element.querySelector(`#${id}:not([disabled])`); if (frame instanceof FrameElement) { return frame; } } } }; var History = class { constructor(delegate2) { this.restorationIdentifier = uuid(); this.restorationData = {}; this.started = false; this.pageLoaded = false; this.onPopState = (event) => { if (this.shouldHandlePopState()) { const { turbo } = event.state || {}; if (turbo) { this.location = new URL(window.location.href); const { restorationIdentifier } = turbo; this.restorationIdentifier = restorationIdentifier; this.delegate.historyPoppedToLocationWithRestorationIdentifier(this.location, restorationIdentifier); } } }; this.onPageLoad = async (_event) => { await nextMicrotask(); this.pageLoaded = true; }; this.delegate = delegate2; } start() { if (!this.started) { addEventListener("popstate", this.onPopState, false); addEventListener("load", this.onPageLoad, false); this.started = true; this.replace(new URL(window.location.href)); } } stop() { if (this.started) { removeEventListener("popstate", this.onPopState, false); removeEventListener("load", this.onPageLoad, false); this.started = false; } } push(location2, restorationIdentifier) { this.update(history.pushState, location2, restorationIdentifier); } replace(location2, restorationIdentifier) { this.update(history.replaceState, location2, restorationIdentifier); } update(method, location2, restorationIdentifier = uuid()) { const state = { turbo: { restorationIdentifier } }; method.call(history, state, "", location2.href); this.location = location2; this.restorationIdentifier = restorationIdentifier; } getRestorationDataForIdentifier(restorationIdentifier) { return this.restorationData[restorationIdentifier] || {}; } updateRestorationData(additionalData) { const { restorationIdentifier } = this; const restorationData = this.restorationData[restorationIdentifier]; this.restorationData[restorationIdentifier] = Object.assign(Object.assign({}, restorationData), additionalData); } assumeControlOfScrollRestoration() { var _a; if (!this.previousScrollRestoration) { this.previousScrollRestoration = (_a = history.scrollRestoration) !== null && _a !== void 0 ? _a : "auto"; history.scrollRestoration = "manual"; } } relinquishControlOfScrollRestoration() { if (this.previousScrollRestoration) { history.scrollRestoration = this.previousScrollRestoration; delete this.previousScrollRestoration; } } shouldHandlePopState() { return this.pageIsLoaded(); } pageIsLoaded() { return this.pageLoaded || document.readyState == "complete"; } }; var Navigator = class { constructor(delegate2) { this.delegate = delegate2; } proposeVisit(location2, options = {}) { if (this.delegate.allowsVisitingLocationWithAction(location2, options.action)) { if (locationIsVisitable(location2, this.view.snapshot.rootLocation)) { this.delegate.visitProposedToLocation(location2, options); } else { window.location.href = location2.toString(); } } } startVisit(locatable, restorationIdentifier, options = {}) { this.stop(); this.currentVisit = new Visit(this, expandURL(locatable), restorationIdentifier, Object.assign({ referrer: this.location }, options)); this.currentVisit.start(); } submitForm(form, submitter) { this.stop(); this.formSubmission = new FormSubmission(this, form, submitter, true); this.formSubmission.start(); } stop() { if (this.formSubmission) { this.formSubmission.stop(); delete this.formSubmission; } if (this.currentVisit) { this.currentVisit.cancel(); delete this.currentVisit; } } get adapter() { return this.delegate.adapter; } get view() { return this.delegate.view; } get history() { return this.delegate.history; } formSubmissionStarted(formSubmission) { if (typeof this.adapter.formSubmissionStarted === "function") { this.adapter.formSubmissionStarted(formSubmission); } } async formSubmissionSucceededWithResponse(formSubmission, fetchResponse) { if (formSubmission == this.formSubmission) { const responseHTML = await fetchResponse.responseHTML; if (responseHTML) { const shouldCacheSnapshot = formSubmission.isSafe; if (!shouldCacheSnapshot) { this.view.clearSnapshotCache(); } const { statusCode, redirected } = fetchResponse; const action = this.getActionForFormSubmission(formSubmission); const visitOptions = { action, shouldCacheSnapshot, response: { statusCode, responseHTML, redirected } }; this.proposeVisit(fetchResponse.location, visitOptions); } } } async formSubmissionFailedWithResponse(formSubmission, fetchResponse) { const responseHTML = await fetchResponse.responseHTML; if (responseHTML) { const snapshot = PageSnapshot.fromHTMLString(responseHTML); if (fetchResponse.serverError) { await this.view.renderError(snapshot, this.currentVisit); } else { await this.view.renderPage(snapshot, false, true, this.currentVisit); } this.view.scrollToTop(); this.view.clearSnapshotCache(); } } formSubmissionErrored(formSubmission, error) { console.error(error); } formSubmissionFinished(formSubmission) { if (typeof this.adapter.formSubmissionFinished === "function") { this.adapter.formSubmissionFinished(formSubmission); } } visitStarted(visit3) { this.delegate.visitStarted(visit3); } visitCompleted(visit3) { this.delegate.visitCompleted(visit3); } locationWithActionIsSamePage(location2, action) { const anchor = getAnchor(location2); const currentAnchor = getAnchor(this.view.lastRenderedLocation); const isRestorationToTop = action === "restore" && typeof anchor === "undefined"; return action !== "replace" && getRequestURL(location2) === getRequestURL(this.view.lastRenderedLocation) && (isRestorationToTop || anchor != null && anchor !== currentAnchor); } visitScrolledToSamePageLocation(oldURL, newURL) { this.delegate.visitScrolledToSamePageLocation(oldURL, newURL); } get location() { return this.history.location; } get restorationIdentifier() { return this.history.restorationIdentifier; } getActionForFormSubmission({ submitter, formElement }) { return getVisitAction(submitter, formElement) || "advance"; } }; var PageStage; (function(PageStage2) { PageStage2[PageStage2["initial"] = 0] = "initial"; PageStage2[PageStage2["loading"] = 1] = "loading"; PageStage2[PageStage2["interactive"] = 2] = "interactive"; PageStage2[PageStage2["complete"] = 3] = "complete"; })(PageStage || (PageStage = {})); var PageObserver = class { constructor(delegate2) { this.stage = PageStage.initial; this.started = false; this.interpretReadyState = () => { const { readyState } = this; if (readyState == "interactive") { this.pageIsInteractive(); } else if (readyState == "complete") { this.pageIsComplete(); } }; this.pageWillUnload = () => { this.delegate.pageWillUnload(); }; this.delegate = delegate2; } start() { if (!this.started) { if (this.stage == PageStage.initial) { this.stage = PageStage.loading; } document.addEventListener("readystatechange", this.interpretReadyState, false); addEventListener("pagehide", this.pageWillUnload, false); this.started = true; } } stop() { if (this.started) { document.removeEventListener("readystatechange", this.interpretReadyState, false); removeEventListener("pagehide", this.pageWillUnload, false); this.started = false; } } pageIsInteractive() { if (this.stage == PageStage.loading) { this.stage = PageStage.interactive; this.delegate.pageBecameInteractive(); } } pageIsComplete() { this.pageIsInteractive(); if (this.stage == PageStage.interactive) { this.stage = PageStage.complete; this.delegate.pageLoaded(); } } get readyState() { return document.readyState; } }; var ScrollObserver = class { constructor(delegate2) { this.started = false; this.onScroll = () => { this.updatePosition({ x: window.pageXOffset, y: window.pageYOffset }); }; this.delegate = delegate2; } start() { if (!this.started) { addEventListener("scroll", this.onScroll, false); this.onScroll(); this.started = true; } } stop() { if (this.started) { removeEventListener("scroll", this.onScroll, false); this.started = false; } } updatePosition(position) { this.delegate.scrollPositionChanged(position); } }; var StreamMessageRenderer = class { render({ fragment }) { Bardo.preservingPermanentElements(this, getPermanentElementMapForFragment(fragment), () => document.documentElement.appendChild(fragment)); } enteringBardo(currentPermanentElement, newPermanentElement) { newPermanentElement.replaceWith(currentPermanentElement.cloneNode(true)); } leavingBardo() { } }; function getPermanentElementMapForFragment(fragment) { const permanentElementsInDocument = queryPermanentElementsAll(document.documentElement); const permanentElementMap = {}; for (const permanentElementInDocument of permanentElementsInDocument) { const { id } = permanentElementInDocument; for (const streamElement of fragment.querySelectorAll("turbo-stream")) { const elementInStream = getPermanentElementById(streamElement.templateElement.content, id); if (elementInStream) { permanentElementMap[id] = [permanentElementInDocument, elementInStream]; } } } return permanentElementMap; } var StreamObserver = class { constructor(delegate2) { this.sources = /* @__PURE__ */ new Set(); this.started = false; this.inspectFetchResponse = (event) => { const response = fetchResponseFromEvent(event); if (response && fetchResponseIsStream(response)) { event.preventDefault(); this.receiveMessageResponse(response); } }; this.receiveMessageEvent = (event) => { if (this.started && typeof event.data == "string") { this.receiveMessageHTML(event.data); } }; this.delegate = delegate2; } start() { if (!this.started) { this.started = true; addEventListener("turbo:before-fetch-response", this.inspectFetchResponse, false); } } stop() { if (this.started) { this.started = false; removeEventListener("turbo:before-fetch-response", this.inspectFetchResponse, false); } } connectStreamSource(source) { if (!this.streamSourceIsConnected(source)) { this.sources.add(source); source.addEventListener("message", this.receiveMessageEvent, false); } } disconnectStreamSource(source) { if (this.streamSourceIsConnected(source)) { this.sources.delete(source); source.removeEventListener("message", this.receiveMessageEvent, false); } } streamSourceIsConnected(source) { return this.sources.has(source); } async receiveMessageResponse(response) { const html = await response.responseHTML; if (html) { this.receiveMessageHTML(html); } } receiveMessageHTML(html) { this.delegate.receivedMessageFromStream(StreamMessage.wrap(html)); } }; function fetchResponseFromEvent(event) { var _a; const fetchResponse = (_a = event.detail) === null || _a === void 0 ? void 0 : _a.fetchResponse; if (fetchResponse instanceof FetchResponse) { return fetchResponse; } } function fetchResponseIsStream(response) { var _a; const contentType = (_a = response.contentType) !== null && _a !== void 0 ? _a : ""; return contentType.startsWith(StreamMessage.contentType); } var ErrorRenderer = class extends Renderer { static renderElement(currentElement2, newElement) { const { documentElement, body } = document; documentElement.replaceChild(newElement, body); } async render() { this.replaceHeadAndBody(); this.activateScriptElements(); } replaceHeadAndBody() { const { documentElement, head } = document; documentElement.replaceChild(this.newHead, head); this.renderElement(this.currentElement, this.newElement); } activateScriptElements() { for (const replaceableElement of this.scriptElements) { const parentNode = replaceableElement.parentNode; if (parentNode) { const element = activateScriptElement(replaceableElement); parentNode.replaceChild(element, replaceableElement); } } } get newHead() { return this.newSnapshot.headSnapshot.element; } get scriptElements() { return document.documentElement.querySelectorAll("script"); } }; var PageRenderer = class extends Renderer { static renderElement(currentElement2, newElement) { if (document.body && newElement instanceof HTMLBodyElement) { document.body.replaceWith(newElement); } else { document.documentElement.appendChild(newElement); } } get shouldRender() { return this.newSnapshot.isVisitable && this.trackedElementsAreIdentical; } get reloadReason() { if (!this.newSnapshot.isVisitable) { return { reason: "turbo_visit_control_is_reload" }; } if (!this.trackedElementsAreIdentical) { return { reason: "tracked_element_mismatch" }; } } async prepareToRender() { await this.mergeHead(); } async render() { if (this.willRender) { await this.replaceBody(); } } finishRendering() { super.finishRendering(); if (!this.isPreview) { this.focusFirstAutofocusableElement(); } } get currentHeadSnapshot() { return this.currentSnapshot.headSnapshot; } get newHeadSnapshot() { return this.newSnapshot.headSnapshot; } get newElement() { return this.newSnapshot.element; } async mergeHead() { const mergedHeadElements = this.mergeProvisionalElements(); const newStylesheetElements = this.copyNewHeadStylesheetElements(); this.copyNewHeadScriptElements(); await mergedHeadElements; await newStylesheetElements; } async replaceBody() { await this.preservingPermanentElements(async () => { this.activateNewBody(); await this.assignNewBody(); }); } get trackedElementsAreIdentical() { return this.currentHeadSnapshot.trackedElementSignature == this.newHeadSnapshot.trackedElementSignature; } async copyNewHeadStylesheetElements() { const loadingElements = []; for (const element of this.newHeadStylesheetElements) { loadingElements.push(waitForLoad(element)); document.head.appendChild(element); } await Promise.all(loadingElements); } copyNewHeadScriptElements() { for (const element of this.newHeadScriptElements) { document.head.appendChild(activateScriptElement(element)); } } async mergeProvisionalElements() { const newHeadElements = [...this.newHeadProvisionalElements]; for (const element of this.currentHeadProvisionalElements) { if (!this.isCurrentElementInElementList(element, newHeadElements)) { document.head.removeChild(element); } } for (const element of newHeadElements) { document.head.appendChild(element); } } isCurrentElementInElementList(element, elementList) { for (const [index, newElement] of elementList.entries()) { if (element.tagName == "TITLE") { if (newElement.tagName != "TITLE") { continue; } if (element.innerHTML == newElement.innerHTML) { elementList.splice(index, 1); return true; } } if (newElement.isEqualNode(element)) { elementList.splice(index, 1); return true; } } return false; } removeCurrentHeadProvisionalElements() { for (const element of this.currentHeadProvisionalElements) { document.head.removeChild(element); } } copyNewHeadProvisionalElements() { for (const element of this.newHeadProvisionalElements) { document.head.appendChild(element); } } activateNewBody() { document.adoptNode(this.newElement); this.activateNewBodyScriptElements(); } activateNewBodyScriptElements() { for (const inertScriptElement of this.newBodyScriptElements) { const activatedScriptElement = activateScriptElement(inertScriptElement); inertScriptElement.replaceWith(activatedScriptElement); } } async assignNewBody() { await this.renderElement(this.currentElement, this.newElement); } get newHeadStylesheetElements() { return this.newHeadSnapshot.getStylesheetElementsNotInSnapshot(this.currentHeadSnapshot); } get newHeadScriptElements() { return this.newHeadSnapshot.getScriptElementsNotInSnapshot(this.currentHeadSnapshot); } get currentHeadProvisionalElements() { return this.currentHeadSnapshot.provisionalElements; } get newHeadProvisionalElements() { return this.newHeadSnapshot.provisionalElements; } get newBodyScriptElements() { return this.newElement.querySelectorAll("script"); } }; var SnapshotCache = class { constructor(size) { this.keys = []; this.snapshots = {}; this.size = size; } has(location2) { return toCacheKey(location2) in this.snapshots; } get(location2) { if (this.has(location2)) { const snapshot = this.read(location2); this.touch(location2); return snapshot; } } put(location2, snapshot) { this.write(location2, snapshot); this.touch(location2); return snapshot; } clear() { this.snapshots = {}; } read(location2) { return this.snapshots[toCacheKey(location2)]; } write(location2, snapshot) { this.snapshots[toCacheKey(location2)] = snapshot; } touch(location2) { const key = toCacheKey(location2); const index = this.keys.indexOf(key); if (index > -1) this.keys.splice(index, 1); this.keys.unshift(key); this.trim(); } trim() { for (const key of this.keys.splice(this.size)) { delete this.snapshots[key]; } } }; var PageView = class extends View { constructor() { super(...arguments); this.snapshotCache = new SnapshotCache(10); this.lastRenderedLocation = new URL(location.href); this.forceReloaded = false; } renderPage(snapshot, isPreview = false, willRender = true, visit3) { const renderer = new PageRenderer(this.snapshot, snapshot, PageRenderer.renderElement, isPreview, willRender); if (!renderer.shouldRender) { this.forceReloaded = true; } else { visit3 === null || visit3 === void 0 ? void 0 : visit3.changeHistory(); } return this.render(renderer); } renderError(snapshot, visit3) { visit3 === null || visit3 === void 0 ? void 0 : visit3.changeHistory(); const renderer = new ErrorRenderer(this.snapshot, snapshot, ErrorRenderer.renderElement, false); return this.render(renderer); } clearSnapshotCache() { this.snapshotCache.clear(); } async cacheSnapshot(snapshot = this.snapshot) { if (snapshot.isCacheable) { this.delegate.viewWillCacheSnapshot(); const { lastRenderedLocation: location2 } = this; await nextEventLoopTick(); const cachedSnapshot = snapshot.clone(); this.snapshotCache.put(location2, cachedSnapshot); return cachedSnapshot; } } getCachedSnapshotForLocation(location2) { return this.snapshotCache.get(location2); } get snapshot() { return PageSnapshot.fromElement(this.element); } }; var Preloader = class { constructor(delegate2) { this.selector = "a[data-turbo-preload]"; this.delegate = delegate2; } get snapshotCache() { return this.delegate.navigator.view.snapshotCache; } start() { if (document.readyState === "loading") { return document.addEventListener("DOMContentLoaded", () => { this.preloadOnLoadLinksForView(document.body); }); } else { this.preloadOnLoadLinksForView(document.body); } } preloadOnLoadLinksForView(element) { for (const link of element.querySelectorAll(this.selector)) { this.preloadURL(link); } } async preloadURL(link) { const location2 = new URL(link.href); if (this.snapshotCache.has(location2)) { return; } try { const response = await fetch(location2.toString(), { headers: { "VND.PREFETCH": "true", Accept: "text/html" } }); const responseText = await response.text(); const snapshot = PageSnapshot.fromHTMLString(responseText); this.snapshotCache.put(location2, snapshot); } catch (_2) { } } }; var Session = class { constructor() { this.navigator = new Navigator(this); this.history = new History(this); this.preloader = new Preloader(this); this.view = new PageView(this, document.documentElement); this.adapter = new BrowserAdapter(this); this.pageObserver = new PageObserver(this); this.cacheObserver = new CacheObserver(); this.linkClickObserver = new LinkClickObserver(this, window); this.formSubmitObserver = new FormSubmitObserver(this, document); this.scrollObserver = new ScrollObserver(this); this.streamObserver = new StreamObserver(this); this.formLinkClickObserver = new FormLinkClickObserver(this, document.documentElement); this.frameRedirector = new FrameRedirector(this, document.documentElement); this.streamMessageRenderer = new StreamMessageRenderer(); this.drive = true; this.enabled = true; this.progressBarDelay = 500; this.started = false; this.formMode = "on"; } start() { if (!this.started) { this.pageObserver.start(); this.cacheObserver.start(); this.formLinkClickObserver.start(); this.linkClickObserver.start(); this.formSubmitObserver.start(); this.scrollObserver.start(); this.streamObserver.start(); this.frameRedirector.start(); this.history.start(); this.preloader.start(); this.started = true; this.enabled = true; } } disable() { this.enabled = false; } stop() { if (this.started) { this.pageObserver.stop(); this.cacheObserver.stop(); this.formLinkClickObserver.stop(); this.linkClickObserver.stop(); this.formSubmitObserver.stop(); this.scrollObserver.stop(); this.streamObserver.stop(); this.frameRedirector.stop(); this.history.stop(); this.started = false; } } registerAdapter(adapter) { this.adapter = adapter; } visit(location2, options = {}) { const frameElement = options.frame ? document.getElementById(options.frame) : null; if (frameElement instanceof FrameElement) { frameElement.src = location2.toString(); frameElement.loaded; } else { this.navigator.proposeVisit(expandURL(location2), options); } } connectStreamSource(source) { this.streamObserver.connectStreamSource(source); } disconnectStreamSource(source) { this.streamObserver.disconnectStreamSource(source); } renderStreamMessage(message) { this.streamMessageRenderer.render(StreamMessage.wrap(message)); } clearCache() { this.view.clearSnapshotCache(); } setProgressBarDelay(delay) { this.progressBarDelay = delay; } setFormMode(mode) { this.formMode = mode; } get location() { return this.history.location; } get restorationIdentifier() { return this.history.restorationIdentifier; } historyPoppedToLocationWithRestorationIdentifier(location2, restorationIdentifier) { if (this.enabled) { this.navigator.startVisit(location2, restorationIdentifier, { action: "restore", historyChanged: true }); } else { this.adapter.pageInvalidated({ reason: "turbo_disabled" }); } } scrollPositionChanged(position) { this.history.updateRestorationData({ scrollPosition: position }); } willSubmitFormLinkToLocation(link, location2) { return this.elementIsNavigatable(link) && locationIsVisitable(location2, this.snapshot.rootLocation); } submittedFormLinkToLocation() { } willFollowLinkToLocation(link, location2, event) { return this.elementIsNavigatable(link) && locationIsVisitable(location2, this.snapshot.rootLocation) && this.applicationAllowsFollowingLinkToLocation(link, location2, event); } followedLinkToLocation(link, location2) { const action = this.getActionForLink(link); const acceptsStreamResponse = link.hasAttribute("data-turbo-stream"); this.visit(location2.href, { action, acceptsStreamResponse }); } allowsVisitingLocationWithAction(location2, action) { return this.locationWithActionIsSamePage(location2, action) || this.applicationAllowsVisitingLocation(location2); } visitProposedToLocation(location2, options) { extendURLWithDeprecatedProperties(location2); this.adapter.visitProposedToLocation(location2, options); } visitStarted(visit3) { if (!visit3.acceptsStreamResponse) { markAsBusy(document.documentElement); } extendURLWithDeprecatedProperties(visit3.location); if (!visit3.silent) { this.notifyApplicationAfterVisitingLocation(visit3.location, visit3.action); } } visitCompleted(visit3) { clearBusyState(document.documentElement); this.notifyApplicationAfterPageLoad(visit3.getTimingMetrics()); } locationWithActionIsSamePage(location2, action) { return this.navigator.locationWithActionIsSamePage(location2, action); } visitScrolledToSamePageLocation(oldURL, newURL) { this.notifyApplicationAfterVisitingSamePageLocation(oldURL, newURL); } willSubmitForm(form, submitter) { const action = getAction(form, submitter); return this.submissionIsNavigatable(form, submitter) && locationIsVisitable(expandURL(action), this.snapshot.rootLocation); } formSubmitted(form, submitter) { this.navigator.submitForm(form, submitter); } pageBecameInteractive() { this.view.lastRenderedLocation = this.location; this.notifyApplicationAfterPageLoad(); } pageLoaded() { this.history.assumeControlOfScrollRestoration(); } pageWillUnload() { this.history.relinquishControlOfScrollRestoration(); } receivedMessageFromStream(message) { this.renderStreamMessage(message); } viewWillCacheSnapshot() { var _a; if (!((_a = this.navigator.currentVisit) === null || _a === void 0 ? void 0 : _a.silent)) { this.notifyApplicationBeforeCachingSnapshot(); } } allowsImmediateRender({ element }, options) { const event = this.notifyApplicationBeforeRender(element, options); const { defaultPrevented, detail: { render: render2 } } = event; if (this.view.renderer && render2) { this.view.renderer.renderElement = render2; } return !defaultPrevented; } viewRenderedSnapshot(_snapshot, _isPreview) { this.view.lastRenderedLocation = this.history.location; this.notifyApplicationAfterRender(); } preloadOnLoadLinksForView(element) { this.preloader.preloadOnLoadLinksForView(element); } viewInvalidated(reason) { this.adapter.pageInvalidated(reason); } frameLoaded(frame) { this.notifyApplicationAfterFrameLoad(frame); } frameRendered(fetchResponse, frame) { this.notifyApplicationAfterFrameRender(fetchResponse, frame); } applicationAllowsFollowingLinkToLocation(link, location2, ev) { const event = this.notifyApplicationAfterClickingLinkToLocation(link, location2, ev); return !event.defaultPrevented; } applicationAllowsVisitingLocation(location2) { const event = this.notifyApplicationBeforeVisitingLocation(location2); return !event.defaultPrevented; } notifyApplicationAfterClickingLinkToLocation(link, location2, event) { return dispatch("turbo:click", { target: link, detail: { url: location2.href, originalEvent: event }, cancelable: true }); } notifyApplicationBeforeVisitingLocation(location2) { return dispatch("turbo:before-visit", { detail: { url: location2.href }, cancelable: true }); } notifyApplicationAfterVisitingLocation(location2, action) { return dispatch("turbo:visit", { detail: { url: location2.href, action } }); } notifyApplicationBeforeCachingSnapshot() { return dispatch("turbo:before-cache"); } notifyApplicationBeforeRender(newBody, options) { return dispatch("turbo:before-render", { detail: Object.assign({ newBody }, options), cancelable: true }); } notifyApplicationAfterRender() { return dispatch("turbo:render"); } notifyApplicationAfterPageLoad(timing = {}) { return dispatch("turbo:load", { detail: { url: this.location.href, timing } }); } notifyApplicationAfterVisitingSamePageLocation(oldURL, newURL) { dispatchEvent(new HashChangeEvent("hashchange", { oldURL: oldURL.toString(), newURL: newURL.toString() })); } notifyApplicationAfterFrameLoad(frame) { return dispatch("turbo:frame-load", { target: frame }); } notifyApplicationAfterFrameRender(fetchResponse, frame) { return dispatch("turbo:frame-render", { detail: { fetchResponse }, target: frame, cancelable: true }); } submissionIsNavigatable(form, submitter) { if (this.formMode == "off") { return false; } else { const submitterIsNavigatable = submitter ? this.elementIsNavigatable(submitter) : true; if (this.formMode == "optin") { return submitterIsNavigatable && form.closest('[data-turbo="true"]') != null; } else { return submitterIsNavigatable && this.elementIsNavigatable(form); } } } elementIsNavigatable(element) { const container = findClosestRecursively(element, "[data-turbo]"); const withinFrame = findClosestRecursively(element, "turbo-frame"); if (this.drive || withinFrame) { if (container) { return container.getAttribute("data-turbo") != "false"; } else { return true; } } else { if (container) { return container.getAttribute("data-turbo") == "true"; } else { return false; } } } getActionForLink(link) { return getVisitAction(link) || "advance"; } get snapshot() { return this.view.snapshot; } }; function extendURLWithDeprecatedProperties(url) { Object.defineProperties(url, deprecatedLocationPropertyDescriptors); } var deprecatedLocationPropertyDescriptors = { absoluteURL: { get() { return this.toString(); } } }; var Cache = class { constructor(session2) { this.session = session2; } clear() { this.session.clearCache(); } resetCacheControl() { this.setCacheControl(""); } exemptPageFromCache() { this.setCacheControl("no-cache"); } exemptPageFromPreview() { this.setCacheControl("no-preview"); } setCacheControl(value) { setMetaContent("turbo-cache-control", value); } }; var StreamActions = { after() { this.targetElements.forEach((e3) => { var _a; return (_a = e3.parentElement) === null || _a === void 0 ? void 0 : _a.insertBefore(this.templateContent, e3.nextSibling); }); }, append() { this.removeDuplicateTargetChildren(); this.targetElements.forEach((e3) => e3.append(this.templateContent)); }, before() { this.targetElements.forEach((e3) => { var _a; return (_a = e3.parentElement) === null || _a === void 0 ? void 0 : _a.insertBefore(this.templateContent, e3); }); }, prepend() { this.removeDuplicateTargetChildren(); this.targetElements.forEach((e3) => e3.prepend(this.templateContent)); }, remove() { this.targetElements.forEach((e3) => e3.remove()); }, replace() { this.targetElements.forEach((e3) => e3.replaceWith(this.templateContent)); }, update() { this.targetElements.forEach((targetElement) => { targetElement.innerHTML = ""; targetElement.append(this.templateContent); }); } }; var session = new Session(); var cache = new Cache(session); var { navigator: navigator$1 } = session; function start() { session.start(); } function registerAdapter(adapter) { session.registerAdapter(adapter); } function visit2(location2, options) { session.visit(location2, options); } function connectStreamSource(source) { session.connectStreamSource(source); } function disconnectStreamSource(source) { session.disconnectStreamSource(source); } function renderStreamMessage(message) { session.renderStreamMessage(message); } function clearCache() { console.warn("Please replace `Turbo.clearCache()` with `Turbo.cache.clear()`. The top-level function is deprecated and will be removed in a future version of Turbo.`"); session.clearCache(); } function setProgressBarDelay(delay) { session.setProgressBarDelay(delay); } function setConfirmMethod(confirmMethod) { FormSubmission.confirmMethod = confirmMethod; } function setFormMode(mode) { session.setFormMode(mode); } var Turbo2 = /* @__PURE__ */ Object.freeze({ __proto__: null, navigator: navigator$1, session, cache, PageRenderer, PageSnapshot, FrameRenderer, start, registerAdapter, visit: visit2, connectStreamSource, disconnectStreamSource, renderStreamMessage, clearCache, setProgressBarDelay, setConfirmMethod, setFormMode, StreamActions }); var TurboFrameMissingError = class extends Error { }; var FrameController = class { constructor(element) { this.fetchResponseLoaded = (_fetchResponse) => { }; this.currentFetchRequest = null; this.resolveVisitPromise = () => { }; this.connected = false; this.hasBeenLoaded = false; this.ignoredAttributes = /* @__PURE__ */ new Set(); this.action = null; this.visitCachedSnapshot = ({ element: element2 }) => { const frame = element2.querySelector("#" + this.element.id); if (frame && this.previousFrameElement) { frame.replaceChildren(...this.previousFrameElement.children); } delete this.previousFrameElement; }; this.element = element; this.view = new FrameView(this, this.element); this.appearanceObserver = new AppearanceObserver(this, this.element); this.formLinkClickObserver = new FormLinkClickObserver(this, this.element); this.linkInterceptor = new LinkInterceptor(this, this.element); this.restorationIdentifier = uuid(); this.formSubmitObserver = new FormSubmitObserver(this, this.element); } connect() { if (!this.connected) { this.connected = true; if (this.loadingStyle == FrameLoadingStyle.lazy) { this.appearanceObserver.start(); } else { this.loadSourceURL(); } this.formLinkClickObserver.start(); this.linkInterceptor.start(); this.formSubmitObserver.start(); } } disconnect() { if (this.connected) { this.connected = false; this.appearanceObserver.stop(); this.formLinkClickObserver.stop(); this.linkInterceptor.stop(); this.formSubmitObserver.stop(); } } disabledChanged() { if (this.loadingStyle == FrameLoadingStyle.eager) { this.loadSourceURL(); } } sourceURLChanged() { if (this.isIgnoringChangesTo("src")) return; if (this.element.isConnected) { this.complete = false; } if (this.loadingStyle == FrameLoadingStyle.eager || this.hasBeenLoaded) { this.loadSourceURL(); } } sourceURLReloaded() { const { src } = this.element; this.ignoringChangesToAttribute("complete", () => { this.element.removeAttribute("complete"); }); this.element.src = null; this.element.src = src; return this.element.loaded; } completeChanged() { if (this.isIgnoringChangesTo("complete")) return; this.loadSourceURL(); } loadingStyleChanged() { if (this.loadingStyle == FrameLoadingStyle.lazy) { this.appearanceObserver.start(); } else { this.appearanceObserver.stop(); this.loadSourceURL(); } } async loadSourceURL() { if (this.enabled && this.isActive && !this.complete && this.sourceURL) { this.element.loaded = this.visit(expandURL(this.sourceURL)); this.appearanceObserver.stop(); await this.element.loaded; this.hasBeenLoaded = true; } } async loadResponse(fetchResponse) { if (fetchResponse.redirected || fetchResponse.succeeded && fetchResponse.isHTML) { this.sourceURL = fetchResponse.response.url; } try { const html = await fetchResponse.responseHTML; if (html) { const document2 = parseHTMLDocument(html); const pageSnapshot = PageSnapshot.fromDocument(document2); if (pageSnapshot.isVisitable) { await this.loadFrameResponse(fetchResponse, document2); } else { await this.handleUnvisitableFrameResponse(fetchResponse); } } } finally { this.fetchResponseLoaded = () => { }; } } elementAppearedInViewport(element) { this.proposeVisitIfNavigatedWithAction(element, element); this.loadSourceURL(); } willSubmitFormLinkToLocation(link) { return this.shouldInterceptNavigation(link); } submittedFormLinkToLocation(link, _location, form) { const frame = this.findFrameElement(link); if (frame) form.setAttribute("data-turbo-frame", frame.id); } shouldInterceptLinkClick(element, _location, _event) { return this.shouldInterceptNavigation(element); } linkClickIntercepted(element, location2) { this.navigateFrame(element, location2); } willSubmitForm(element, submitter) { return element.closest("turbo-frame") == this.element && this.shouldInterceptNavigation(element, submitter); } formSubmitted(element, submitter) { if (this.formSubmission) { this.formSubmission.stop(); } this.formSubmission = new FormSubmission(this, element, submitter); const { fetchRequest } = this.formSubmission; this.prepareRequest(fetchRequest); this.formSubmission.start(); } prepareRequest(request) { var _a; request.headers["Turbo-Frame"] = this.id; if ((_a = this.currentNavigationElement) === null || _a === void 0 ? void 0 : _a.hasAttribute("data-turbo-stream")) { request.acceptResponseType(StreamMessage.contentType); } } requestStarted(_request) { markAsBusy(this.element); } requestPreventedHandlingResponse(_request, _response) { this.resolveVisitPromise(); } async requestSucceededWithResponse(request, response) { await this.loadResponse(response); this.resolveVisitPromise(); } async requestFailedWithResponse(request, response) { await this.loadResponse(response); this.resolveVisitPromise(); } requestErrored(request, error) { console.error(error); this.resolveVisitPromise(); } requestFinished(_request) { clearBusyState(this.element); } formSubmissionStarted({ formElement }) { markAsBusy(formElement, this.findFrameElement(formElement)); } formSubmissionSucceededWithResponse(formSubmission, response) { const frame = this.findFrameElement(formSubmission.formElement, formSubmission.submitter); frame.delegate.proposeVisitIfNavigatedWithAction(frame, formSubmission.formElement, formSubmission.submitter); frame.delegate.loadResponse(response); if (!formSubmission.isSafe) { session.clearCache(); } } formSubmissionFailedWithResponse(formSubmission, fetchResponse) { this.element.delegate.loadResponse(fetchResponse); session.clearCache(); } formSubmissionErrored(formSubmission, error) { console.error(error); } formSubmissionFinished({ formElement }) { clearBusyState(formElement, this.findFrameElement(formElement)); } allowsImmediateRender({ element: newFrame }, options) { const event = dispatch("turbo:before-frame-render", { target: this.element, detail: Object.assign({ newFrame }, options), cancelable: true }); const { defaultPrevented, detail: { render: render2 } } = event; if (this.view.renderer && render2) { this.view.renderer.renderElement = render2; } return !defaultPrevented; } viewRenderedSnapshot(_snapshot, _isPreview) { } preloadOnLoadLinksForView(element) { session.preloadOnLoadLinksForView(element); } viewInvalidated() { } willRenderFrame(currentElement2, _newElement) { this.previousFrameElement = currentElement2.cloneNode(true); } async loadFrameResponse(fetchResponse, document2) { const newFrameElement = await this.extractForeignFrameElement(document2.body); if (newFrameElement) { const snapshot = new Snapshot(newFrameElement); const renderer = new FrameRenderer(this, this.view.snapshot, snapshot, FrameRenderer.renderElement, false, false); if (this.view.renderPromise) await this.view.renderPromise; this.changeHistory(); await this.view.render(renderer); this.complete = true; session.frameRendered(fetchResponse, this.element); session.frameLoaded(this.element); this.fetchResponseLoaded(fetchResponse); } else if (this.willHandleFrameMissingFromResponse(fetchResponse)) { this.handleFrameMissingFromResponse(fetchResponse); } } async visit(url) { var _a; const request = new FetchRequest(this, FetchMethod.get, url, new URLSearchParams(), this.element); (_a = this.currentFetchRequest) === null || _a === void 0 ? void 0 : _a.cancel(); this.currentFetchRequest = request; return new Promise((resolve) => { this.resolveVisitPromise = () => { this.resolveVisitPromise = () => { }; this.currentFetchRequest = null; resolve(); }; request.perform(); }); } navigateFrame(element, url, submitter) { const frame = this.findFrameElement(element, submitter); frame.delegate.proposeVisitIfNavigatedWithAction(frame, element, submitter); this.withCurrentNavigationElement(element, () => { frame.src = url; }); } proposeVisitIfNavigatedWithAction(frame, element, submitter) { this.action = getVisitAction(submitter, element, frame); if (this.action) { const pageSnapshot = PageSnapshot.fromElement(frame).clone(); const { visitCachedSnapshot } = frame.delegate; frame.delegate.fetchResponseLoaded = (fetchResponse) => { if (frame.src) { const { statusCode, redirected } = fetchResponse; const responseHTML = frame.ownerDocument.documentElement.outerHTML; const response = { statusCode, redirected, responseHTML }; const options = { response, visitCachedSnapshot, willRender: false, updateHistory: false, restorationIdentifier: this.restorationIdentifier, snapshot: pageSnapshot }; if (this.action) options.action = this.action; session.visit(frame.src, options); } }; } } changeHistory() { if (this.action) { const method = getHistoryMethodForAction(this.action); session.history.update(method, expandURL(this.element.src || ""), this.restorationIdentifier); } } async handleUnvisitableFrameResponse(fetchResponse) { console.warn(`The response (${fetchResponse.statusCode}) from is performing a full page visit due to turbo-visit-control.`); await this.visitResponse(fetchResponse.response); } willHandleFrameMissingFromResponse(fetchResponse) { this.element.setAttribute("complete", ""); const response = fetchResponse.response; const visit3 = async (url, options = {}) => { if (url instanceof Response) { this.visitResponse(url); } else { session.visit(url, options); } }; const event = dispatch("turbo:frame-missing", { target: this.element, detail: { response, visit: visit3 }, cancelable: true }); return !event.defaultPrevented; } handleFrameMissingFromResponse(fetchResponse) { this.view.missing(); this.throwFrameMissingError(fetchResponse); } throwFrameMissingError(fetchResponse) { const message = `The response (${fetchResponse.statusCode}) did not contain the expected and will be ignored. To perform a full page visit instead, set turbo-visit-control to reload.`; throw new TurboFrameMissingError(message); } async visitResponse(response) { const wrapped = new FetchResponse(response); const responseHTML = await wrapped.responseHTML; const { location: location2, redirected, statusCode } = wrapped; return session.visit(location2, { response: { redirected, statusCode, responseHTML } }); } findFrameElement(element, submitter) { var _a; const id = getAttribute("data-turbo-frame", submitter, element) || this.element.getAttribute("target"); return (_a = getFrameElementById(id)) !== null && _a !== void 0 ? _a : this.element; } async extractForeignFrameElement(container) { let element; const id = CSS.escape(this.id); try { element = activateElement(container.querySelector(`turbo-frame#${id}`), this.sourceURL); if (element) { return element; } element = activateElement(container.querySelector(`turbo-frame[src][recurse~=${id}]`), this.sourceURL); if (element) { await element.loaded; return await this.extractForeignFrameElement(element); } } catch (error) { console.error(error); return new FrameElement(); } return null; } formActionIsVisitable(form, submitter) { const action = getAction(form, submitter); return locationIsVisitable(expandURL(action), this.rootLocation); } shouldInterceptNavigation(element, submitter) { const id = getAttribute("data-turbo-frame", submitter, element) || this.element.getAttribute("target"); if (element instanceof HTMLFormElement && !this.formActionIsVisitable(element, submitter)) { return false; } if (!this.enabled || id == "_top") { return false; } if (id) { const frameElement = getFrameElementById(id); if (frameElement) { return !frameElement.disabled; } } if (!session.elementIsNavigatable(element)) { return false; } if (submitter && !session.elementIsNavigatable(submitter)) { return false; } return true; } get id() { return this.element.id; } get enabled() { return !this.element.disabled; } get sourceURL() { if (this.element.src) { return this.element.src; } } set sourceURL(sourceURL) { this.ignoringChangesToAttribute("src", () => { this.element.src = sourceURL !== null && sourceURL !== void 0 ? sourceURL : null; }); } get loadingStyle() { return this.element.loading; } get isLoading() { return this.formSubmission !== void 0 || this.resolveVisitPromise() !== void 0; } get complete() { return this.element.hasAttribute("complete"); } set complete(value) { this.ignoringChangesToAttribute("complete", () => { if (value) { this.element.setAttribute("complete", ""); } else { this.element.removeAttribute("complete"); } }); } get isActive() { return this.element.isActive && this.connected; } get rootLocation() { var _a; const meta = this.element.ownerDocument.querySelector(`meta[name="turbo-root"]`); const root = (_a = meta === null || meta === void 0 ? void 0 : meta.content) !== null && _a !== void 0 ? _a : "/"; return expandURL(root); } isIgnoringChangesTo(attributeName) { return this.ignoredAttributes.has(attributeName); } ignoringChangesToAttribute(attributeName, callback) { this.ignoredAttributes.add(attributeName); callback(); this.ignoredAttributes.delete(attributeName); } withCurrentNavigationElement(element, callback) { this.currentNavigationElement = element; callback(); delete this.currentNavigationElement; } }; function getFrameElementById(id) { if (id != null) { const element = document.getElementById(id); if (element instanceof FrameElement) { return element; } } } function activateElement(element, currentURL) { if (element) { const src = element.getAttribute("src"); if (src != null && currentURL != null && urlsAreEqual(src, currentURL)) { throw new Error(`Matching element has a source URL which references itself`); } if (element.ownerDocument !== document) { element = document.importNode(element, true); } if (element instanceof FrameElement) { element.connectedCallback(); element.disconnectedCallback(); return element; } } } var StreamElement = class extends HTMLElement { static async renderElement(newElement) { await newElement.performAction(); } async connectedCallback() { try { await this.render(); } catch (error) { console.error(error); } finally { this.disconnect(); } } async render() { var _a; return (_a = this.renderPromise) !== null && _a !== void 0 ? _a : this.renderPromise = (async () => { const event = this.beforeRenderEvent; if (this.dispatchEvent(event)) { await nextAnimationFrame(); await event.detail.render(this); } })(); } disconnect() { try { this.remove(); } catch (_a) { } } removeDuplicateTargetChildren() { this.duplicateChildren.forEach((c2) => c2.remove()); } get duplicateChildren() { var _a; const existingChildren = this.targetElements.flatMap((e3) => [...e3.children]).filter((c2) => !!c2.id); const newChildrenIds = [...((_a = this.templateContent) === null || _a === void 0 ? void 0 : _a.children) || []].filter((c2) => !!c2.id).map((c2) => c2.id); return existingChildren.filter((c2) => newChildrenIds.includes(c2.id)); } get performAction() { if (this.action) { const actionFunction = StreamActions[this.action]; if (actionFunction) { return actionFunction; } this.raise("unknown action"); } this.raise("action attribute is missing"); } get targetElements() { if (this.target) { return this.targetElementsById; } else if (this.targets) { return this.targetElementsByQuery; } else { this.raise("target or targets attribute is missing"); } } get templateContent() { return this.templateElement.content.cloneNode(true); } get templateElement() { if (this.firstElementChild === null) { const template = this.ownerDocument.createElement("template"); this.appendChild(template); return template; } else if (this.firstElementChild instanceof HTMLTemplateElement) { return this.firstElementChild; } this.raise("first child element must be a