{ "version": 3, "sources": ["../../node_modules/@elc-online/edl-components/dist/js/Controller.js", "../../node_modules/@elc-online/edl-components/dist/js/alert.js", "../../node_modules/@elc-online/edl-components/dist/js/minimal_header.js", "../../node_modules/@elc-online/edl-components/dist/js/carousel.js", "../../node_modules/@elc-online/edl-components/dist/js/utilities/focus.js", "../../node_modules/@elc-online/edl-components/dist/js/drawer.js", "../../node_modules/@elc-online/edl-components/dist/js/utilities/edge-detection.js", "../../node_modules/@elc-online/edl-components/dist/js/utilities/position.js", "../../node_modules/@elc-online/edl-components/dist/js/popover.js", "../../node_modules/@elc-online/edl-components/dist/js/switch.js", "../../node_modules/@hotwired/stimulus/dist/stimulus.js", "../../global/scripts/utilities/address.ts", "../../global/scripts/utilities/debounce.ts", "../../global/scripts/stimulus/controllers/address-input-controller.ts", "../../global/scripts/stimulus/controllers/address-selector-controller.ts", "../../global/scripts/stimulus/controllers/alert-controller.ts", "../../global/scripts/stimulus/controllers/back-button-controller.ts", "../../global/scripts/stimulus/controllers/carousel-controller.ts", "../../global/scripts/stimulus/controllers/char-limit-controller.ts", "../../global/scripts/utilities/timing.ts", "../../global/scripts/utilities/date.ts", "../../global/scripts/stimulus/controllers/date-display-controller.ts", "../../global/scripts/stimulus/controllers/date-input-controller.ts", "../../global/scripts/stimulus/controllers/dismissible-controller.ts", "../../global/scripts/stimulus/controllers/drawer-controller.ts", "../../global/scripts/stimulus/controllers/form-autofocus-controller.ts", "../../global/scripts/stimulus/controllers/form-auto-submit-controller.ts", "../../global/scripts/stimulus/controllers/gift-wrap-controller.ts", "../../global/scripts/stimulus/controllers/input-validation-controller.ts", "../../global/scripts/stimulus/controllers/menubar-controller.ts", "../../global/scripts/stimulus/controllers/menu-controller.ts", "../../global/scripts/utilities/focus.ts", "../../global/scripts/stimulus/controllers/modal-dialog-controller.ts", "../../global/scripts/stimulus/controllers/vendor/onetrust-controller.ts", "../../global/scripts/stimulus/controllers/page-controller.ts", "../../global/scripts/stimulus/controllers/password-input-controller.ts", "../../global/scripts/stimulus/controllers/password-validator-controller.ts", "../../global/scripts/stimulus/controllers/payment-method-selector-controller.ts", "../../global/scripts/stimulus/controllers/phone-input-controller.ts", "../../global/scripts/stimulus/controllers/popover-controller.ts", "../../global/scripts/stimulus/controllers/privacy-portal-controller.ts", "../../global/scripts/stimulus/controllers/quantity-selector-controller.ts", "../../global/scripts/stimulus/controllers/radio-toggle-controller.ts", "../../global/scripts/stimulus/controllers/select-menu-controller.ts", "../../global/scripts/stimulus/controllers/sticky-footer-bar-controller.ts", "../../global/scripts/stimulus/controllers/switch-controller.ts", "../../global/scripts/stimulus/controllers/toast-controller.ts", "../../global/scripts/stimulus/controllers/toggle-button-controller.ts", "../../global/scripts/stimulus/controllers/toggle-controller.ts", "../../global/scripts/stimulus/controllers/toggle-form-controller.ts", "../../global/scripts/utilities/edge-detection.ts", "../../global/scripts/utilities/position.ts", "../../global/scripts/stimulus/controllers/tooltip-controller.ts", "../../global/scripts/stimulus/controllers/verification-code-controller.ts", "../../node_modules/@hotwired/turbo/dist/turbo.es2017-esm.js", "../../global/scripts/stimulus/controllers/turbo-form-controller.ts", "../../global/scripts/stimulus/index.ts"], "sourcesContent": ["\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nclass Controller {\n constructor(initialAttributes, elementReferences, userOptions) {\n this.currentAttributes = {};\n this.options = Object.assign(Object.assign({}, Controller.defaultOptions), userOptions);\n this.elements = elementReferences;\n this.eventTarget = new EventTarget();\n this.attributes = initialAttributes;\n }\n get attributes() {\n return Object.freeze(Object.assign({}, this.currentAttributes));\n }\n set attributes(newAttributes) {\n if (this.options.mode === 'auto') {\n this.applyAttributesToDOM(this.attributes, newAttributes);\n }\n this.currentAttributes = Object.freeze(Object.assign({}, newAttributes));\n this.publish();\n }\n applyAttributesToDOM(oldAttributes, newAttributes) {\n var _a;\n for (const [elementKey, elementAttributes] of Object.entries(newAttributes)) {\n for (const [name, value] of Object.entries(elementAttributes)) {\n if (this.elements[elementKey] &&\n (!oldAttributes[elementKey] ||\n (oldAttributes[elementKey] &&\n oldAttributes[elementKey][name] !== value))) {\n setHTMLAttribute(this.elements[elementKey], String(name), value);\n updateEventListener(this.elements[elementKey], String(name), value, (_a = oldAttributes[elementKey]) === null || _a === void 0 ? void 0 : _a[name]);\n }\n }\n }\n }\n publish() {\n this.eventTarget.dispatchEvent(new CustomEvent(Controller.AttributesChangeEvent, {\n detail: this.currentAttributes,\n }));\n }\n // Placeholders for child to overwrite\n // eslint-disable-next-line no-empty-function\n connect() { }\n // eslint-disable-next-line no-empty-function\n disconnect() { }\n subscribe(callback) {\n const listener = (event) => {\n const newAttributes = event.detail;\n callback(newAttributes);\n };\n this.eventTarget.addEventListener(Controller.AttributesChangeEvent, listener);\n return () => {\n this.eventTarget.removeEventListener(Controller.AttributesChangeEvent, listener);\n };\n }\n}\nController.AttributesChangeEvent = 'edl:attributeschange';\nController.defaultOptions = {\n mode: 'manual',\n};\nController.uninitializedHandler = () => {\n console.warn('Controller not yet initialized');\n};\nexports.default = Controller;\n// Value can be string, number, boolean, function, undefined, null... any made more sense\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nfunction setHTMLAttribute(element, name, value) {\n if (typeof value === 'string' || typeof value == 'number') {\n element.setAttribute(name, String(value));\n }\n else if (value === true) {\n element.setAttribute(name, name);\n }\n else if (typeof value !== 'function') {\n element.removeAttribute(name);\n }\n}\nfunction updateEventListener(element, name, value, \n// eslint-disable-next-line @typescript-eslint/no-explicit-any\noldAttributes) {\n if (name.startsWith('on')) {\n if (oldAttributes && typeof oldAttributes === 'function') {\n element.removeEventListener(name.substring(2), oldAttributes);\n }\n if (typeof value === 'function') {\n element.addEventListener(name.substring(2), value);\n }\n }\n}\n", "\"use strict\";\nvar __importDefault = (this && this.__importDefault) || function (mod) {\n return (mod && mod.__esModule) ? mod : { \"default\": mod };\n};\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.AlertController = void 0;\nconst Controller_1 = __importDefault(require(\"./Controller\"));\nclass AlertController extends Controller_1.default {\n constructor(elements, options) {\n super(AlertController.initialAttributes, elements, options);\n this.close = () => {\n this.attributes = Object.assign(Object.assign({}, this.attributes), { container: Object.assign(Object.assign({}, this.attributes.container), { hidden: true }) });\n };\n this.attributes = {\n container: {\n hidden: !!elements.container.getAttribute('hidden'),\n },\n close: {\n hidden: !!elements.close.getAttribute('hidden'),\n onclick: this.close,\n },\n };\n }\n}\nexports.AlertController = AlertController;\nAlertController.initialAttributes = {\n container: {\n hidden: false,\n },\n close: {\n hidden: false,\n onclick: Controller_1.default.uninitializedHandler,\n },\n};\n", "\"use strict\";\nvar __importDefault = (this && this.__importDefault) || function (mod) {\n return (mod && mod.__esModule) ? mod : { \"default\": mod };\n};\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.MinimalHeaderController = void 0;\nconst Controller_1 = __importDefault(require(\"./Controller\"));\nclass MinimalHeaderController extends Controller_1.default {\n constructor(elements, options) {\n super(MinimalHeaderController.initialAttributes, elements, options);\n this.goBack = (event) => {\n event.preventDefault();\n window.history.back();\n };\n this.attributes = {\n back: {\n hidden: window.history.length <= 1,\n onclick: this.goBack,\n },\n };\n }\n}\nexports.MinimalHeaderController = MinimalHeaderController;\nMinimalHeaderController.initialAttributes = {\n back: {\n hidden: true,\n onclick: Controller_1.default.uninitializedHandler,\n },\n};\n", "\"use strict\";\nvar __importDefault = (this && this.__importDefault) || function (mod) {\n return (mod && mod.__esModule) ? mod : { \"default\": mod };\n};\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.CarouselController = void 0;\nconst Controller_1 = __importDefault(require(\"./Controller\"));\nconst dataEdlScroll = 'data-edl-scroll';\nvar ScrollType;\n(function (ScrollType) {\n ScrollType[\"DEFAULT\"] = \"default\";\n ScrollType[\"FULL\"] = \"full\";\n})(ScrollType || (ScrollType = {}));\nclass CarouselController extends Controller_1.default {\n constructor(elements, options) {\n super(CarouselController.initialAttributes, elements, options);\n this.dataNavigation = 'data-edl-navigation';\n this.scrollTimeout = null;\n this.prev = () => {\n var _a;\n if (this.scrollType === ScrollType.FULL) {\n const container = this.elements.items;\n const scrollAmount = container.clientWidth;\n container.scrollBy({\n left: -scrollAmount,\n behavior: 'smooth',\n });\n }\n else {\n this.currentSlide = (_a = this.currentSlide) === null || _a === void 0 ? void 0 : _a.previousElementSibling;\n }\n };\n this.next = () => {\n var _a;\n if (this.scrollType === ScrollType.FULL) {\n const container = this.elements.items;\n const scrollAmount = container.clientWidth;\n container.scrollBy({ left: scrollAmount, behavior: 'smooth' });\n }\n else {\n this.currentSlide = (_a = this.currentSlide) === null || _a === void 0 ? void 0 : _a.nextElementSibling;\n }\n };\n this.updateNavState = (value) => {\n if (this.scrollType === ScrollType.FULL) {\n const scrollWidth = this.elements.items.scrollWidth;\n const clientWidth = this.elements.items.clientWidth;\n this.attributes = Object.assign(Object.assign({}, this.attributes), { previous: Object.assign(Object.assign({}, this.attributes.previous), { disabled: value === 0 }), next: Object.assign(Object.assign({}, this.attributes.next), { disabled: value === scrollWidth - clientWidth }) });\n }\n };\n this.setCurrentNav = () => {\n var _a, _b;\n if (this.scrollType === ScrollType.FULL) {\n if (this.scrollTimeout) {\n clearTimeout(this.scrollTimeout);\n }\n this.scrollTimeout = window.setTimeout(() => {\n this.updateNavState(this.elements.items.scrollLeft);\n }, 150);\n }\n else {\n const currentIndex = [...this.elements.items.children].indexOf(this.currentSlide);\n for (const navItem of this.elements.navigation.children) {\n (_a = navItem.querySelector('button')) === null || _a === void 0 ? void 0 : _a.setAttribute('aria-current', 'false');\n }\n (_b = this.elements.navigation.children[currentIndex]\n .querySelector('button')) === null || _b === void 0 ? void 0 : _b.setAttribute('aria-current', 'true');\n }\n };\n this.checkAllItemsVisible = () => {\n const container = this.elements.items;\n const containerRect = container.getBoundingClientRect();\n const firstItem = container.firstElementChild;\n const lastItem = container.lastElementChild;\n if (!firstItem || !lastItem) {\n return;\n }\n const firstItemRect = firstItem.getBoundingClientRect();\n const lastItemRect = lastItem.getBoundingClientRect();\n const itemsCount = container.children.length;\n const itemWidth = firstItemRect.width;\n // Since we have empty space to let user scroll to last element,\n // we need take in count empty element in the calculation\n const effectiveRightBoundary = itemsCount > 2 ? containerRect.right - itemWidth : containerRect.right;\n const allVisible = firstItemRect.left >= containerRect.left &&\n lastItemRect.right <= effectiveRightBoundary;\n container.setAttribute(this.dataNavigation, allVisible.toString());\n };\n this.attributes = {\n previous: {\n onclick: this.prev,\n hidden: false,\n disabled: true,\n },\n next: {\n onclick: this.next,\n hidden: false,\n disabled: false,\n },\n items: {\n onscroll: this.setCurrentNav,\n },\n navigation: {\n hidden: false,\n },\n };\n this.currentSlide = this.elements.items.children[0];\n this.setCurrentNav();\n this.checkAllItemsVisible();\n this.resizeObserver = new ResizeObserver(() => {\n this.checkAllItemsVisible();\n });\n this.resizeObserver.observe(this.elements.items);\n this.elements.navigation.querySelectorAll('button').forEach((button, i) => {\n button.addEventListener('click', () => {\n this.currentSlide = this.elements.items.children[i];\n });\n });\n }\n set currentSlide(slide) {\n slide === null || slide === void 0 ? void 0 : slide.scrollIntoView({ block: 'nearest', inline: 'start' });\n }\n // Current slide is always the first fully visible\n get currentSlide() {\n const containerRect = this.elements.items.getBoundingClientRect();\n // Add small tolerance for floating point calculations\n const tolerance = 1;\n for (const item of this.elements.items.children) {\n const itemRect = item.getBoundingClientRect();\n if (itemRect.left >= containerRect.left - tolerance) {\n return item;\n }\n }\n return this.elements.items.children[0];\n }\n get scrollType() {\n return this.elements.container.getAttribute(dataEdlScroll) === 'full'\n ? ScrollType.FULL\n : ScrollType.DEFAULT;\n }\n disconnect() {\n this.resizeObserver.disconnect();\n }\n}\nexports.CarouselController = CarouselController;\nCarouselController.initialAttributes = {\n previous: {\n onclick: Controller_1.default.uninitializedHandler,\n hidden: false,\n disabled: false,\n },\n next: {\n onclick: Controller_1.default.uninitializedHandler,\n hidden: false,\n disabled: false,\n },\n items: {\n onscroll: Controller_1.default.uninitializedHandler,\n },\n navigation: {\n hidden: false,\n },\n};\n", "\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.FocusGuard = void 0;\nexports.getFocusableElements = getFocusableElements;\nfunction getFocusableElements(container) {\n return [\n ...container.querySelectorAll([\n 'input:not(:disabled):not([type=\"hidden\"])',\n 'button:not(:disabled)',\n 'textarea:not(:disabled)',\n 'select:not(:disabled)',\n 'a[href]',\n '[tabindex]:not([tabindex=\"-1\"])',\n ].join(', ')),\n ];\n}\nclass FocusGuard {\n constructor(containerEl) {\n this.beforeGuard = document.createElement('span');\n this.afterGuard = document.createElement('span');\n this.focusFirst = () => {\n for (const element of this.focusableElements) {\n if (element.checkVisibility()) {\n element.focus();\n break;\n }\n }\n };\n this.focusLast = () => {\n for (const element of [...this.focusableElements].reverse()) {\n if (element.checkVisibility()) {\n element.focus();\n break;\n }\n }\n };\n this.enable = () => {\n this.beforeGuard.setAttribute('tabindex', '0');\n this.afterGuard.setAttribute('tabindex', '0');\n };\n this.disable = () => {\n this.beforeGuard.setAttribute('tabindex', '-1');\n this.afterGuard.setAttribute('tabindex', '-1');\n };\n this.container = containerEl;\n this.focusableElements = getFocusableElements(this.container);\n this.beforeGuard.addEventListener('focus', this.focusLast);\n this.beforeGuard.setAttribute('aria-hidden', 'true');\n this.afterGuard.addEventListener('focus', this.focusFirst);\n this.afterGuard.setAttribute('aria-hidden', 'true');\n this.container.prepend(this.beforeGuard);\n this.container.append(this.afterGuard);\n this.enable();\n }\n}\nexports.FocusGuard = FocusGuard;\n", "\"use strict\";\nvar __importDefault = (this && this.__importDefault) || function (mod) {\n return (mod && mod.__esModule) ? mod : { \"default\": mod };\n};\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.DrawerController = void 0;\nconst Controller_1 = __importDefault(require(\"./Controller\"));\nconst focus_1 = require(\"./utilities/focus\");\nconst expanded = 'aria-expanded';\nconst dataEdlFull = 'data-edl-full';\nconst dataEdlDrawerOpen = 'data-edl-drawer-open';\nclass DrawerController extends Controller_1.default {\n constructor(elements, options) {\n super(DrawerController.initialAttributes, elements, options);\n this.open = () => {\n var _a;\n this.height = DrawerController.minHeight;\n this.attributes = Object.assign(Object.assign({}, this.attributes), { trigger: Object.assign(Object.assign({}, this.attributes.trigger), { [expanded]: 'true' }) });\n document.body.setAttribute(dataEdlDrawerOpen, 'true');\n this.addEventListeners();\n (_a = this.focusGuard) === null || _a === void 0 ? void 0 : _a.enable();\n };\n this.close = () => {\n var _a;\n this.attributes = Object.assign(Object.assign({}, this.attributes), { trigger: Object.assign(Object.assign({}, this.attributes.trigger), { [expanded]: 'false' }) });\n document.body.removeAttribute(dataEdlDrawerOpen);\n this.removeEventListeners();\n this.elements.trigger.focus();\n (_a = this.focusGuard) === null || _a === void 0 ? void 0 : _a.disable();\n };\n this.handleClickOutside = (event) => {\n if (!this.elements.drawer.contains(event.target)) {\n this.close();\n }\n };\n this.handleEscKey = (event) => {\n if (event.key === 'Escape') {\n this.close();\n }\n };\n this.onDragStart = () => {\n this.elements.handle.style.cursor = 'grabbing';\n window.addEventListener('mousemove', this.onDragMove);\n window.addEventListener('touchmove', this.onDragMove, { passive: true });\n window.addEventListener('mouseup', this.onDragEnd);\n window.addEventListener('touchend', this.onDragEnd);\n };\n this.onDragMove = (event) => {\n let clientY;\n const handleTop = this.elements.handle.offsetTop;\n if ('touches' in event && event.touches.length > 0) {\n // Touch event\n clientY = event.touches[0].clientY;\n }\n else if ('clientY' in event) {\n // Mouse event\n clientY = event.clientY;\n }\n if (clientY !== undefined) {\n const viewportHeight = window.innerHeight;\n // client Y goes bottom to top, but viewport Y goes top to bottom, so we need to invert the value by subtracting from 100\n // Need to also adjust the height because we are measuring from the handle\n const pointerYPercent = 100 - ((clientY - handleTop) / viewportHeight) * 100;\n this.height = pointerYPercent;\n }\n };\n this.onDragEnd = () => {\n this.elements.handle.style.cursor = 'grab';\n window.removeEventListener('mousemove', this.onDragMove);\n window.removeEventListener('touchmove', this.onDragMove);\n window.removeEventListener('mouseup', this.onDragEnd);\n window.removeEventListener('touchend', this.onDragEnd);\n if (this.height < DrawerController.closeThreshold) {\n this.close();\n }\n else if (this.height > DrawerController.expandThreshold) {\n this.elements.drawer.setAttribute(dataEdlFull, 'true');\n this.height = 100;\n }\n else {\n this.height = DrawerController.minHeight;\n this.elements.drawer.removeAttribute(dataEdlFull);\n }\n };\n this.attributes = {\n close: {\n onclick: this.close,\n },\n handle: {\n onmousedown: this.onDragStart,\n ontouchstart: this.onDragStart,\n },\n trigger: {\n [expanded]: elements.trigger.getAttribute(expanded) === 'true' ? 'true' : 'false',\n onclick: this.open,\n },\n };\n if (elements.back) {\n this.attributes = Object.assign(Object.assign({}, this.attributes), { back: {\n onclick: this.close,\n } });\n }\n this.focusGuard = new focus_1.FocusGuard(elements.drawer);\n }\n set height(value) {\n this.elements.drawer.style.height = `${Math.min(Math.max(value, 0), 100)}%`;\n }\n get height() {\n return parseFloat(this.elements.drawer.style.height);\n }\n addEventListeners() {\n document.addEventListener('mousedown', this.handleClickOutside);\n document.addEventListener('keydown', this.handleEscKey);\n }\n removeEventListeners() {\n document.removeEventListener('mousedown', this.handleClickOutside);\n document.removeEventListener('keydown', this.handleEscKey);\n }\n}\nexports.DrawerController = DrawerController;\nDrawerController.closeThreshold = 25;\nDrawerController.expandThreshold = 75;\nDrawerController.minHeight = 50;\nDrawerController.initialAttributes = {\n close: {\n onclick: Controller_1.default.uninitializedHandler,\n },\n handle: {\n onmousedown: Controller_1.default.uninitializedHandler,\n ontouchstart: Controller_1.default.uninitializedHandler,\n },\n trigger: {\n [expanded]: 'false',\n onclick: Controller_1.default.uninitializedHandler,\n },\n};\n", "\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.default = getOverflowedEdges;\nfunction getOverflowedEdges(target) {\n var _a, _b;\n const targetBoundaries = target.getBoundingClientRect();\n const overflowedEdges = {\n top: false,\n right: false,\n bottom: false,\n left: false,\n };\n if (targetBoundaries.top < 0) {\n overflowedEdges.top = true;\n }\n if (targetBoundaries.right >\n (((_a = window.visualViewport) === null || _a === void 0 ? void 0 : _a.width) || document.documentElement.clientWidth)) {\n overflowedEdges.right = true;\n }\n if (targetBoundaries.bottom >\n (((_b = window.visualViewport) === null || _b === void 0 ? void 0 : _b.height) || document.documentElement.clientHeight)) {\n overflowedEdges.bottom = true;\n }\n if (targetBoundaries.left < 0) {\n overflowedEdges.left = true;\n }\n return overflowedEdges;\n}\n", "\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.Positions = void 0;\nexports.flipPosition = flipPosition;\nexports.flipAlignment = flipAlignment;\nvar Positions;\n(function (Positions) {\n Positions[\"top\"] = \"top\";\n Positions[\"bottom\"] = \"bottom\";\n Positions[\"left\"] = \"left\";\n Positions[\"right\"] = \"right\";\n Positions[\"start\"] = \"start\";\n Positions[\"center\"] = \"center\";\n Positions[\"end\"] = \"end\";\n})(Positions || (exports.Positions = Positions = {}));\nconst opposite = {\n [Positions.top]: Positions.bottom,\n [Positions.bottom]: Positions.top,\n [Positions.left]: Positions.right,\n [Positions.right]: Positions.left,\n [Positions.start]: Positions.end,\n [Positions.end]: Positions.start,\n [Positions.center]: Positions.center,\n};\nfunction flipPosition(startingPosition, targetSide) {\n const newPosition = startingPosition.replace(opposite[targetSide], targetSide);\n return newPosition;\n}\nfunction flipAlignment(currentAlignment) {\n return opposite[currentAlignment];\n}\n", "\"use strict\";\nvar __importDefault = (this && this.__importDefault) || function (mod) {\n return (mod && mod.__esModule) ? mod : { \"default\": mod };\n};\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.PopoverController = void 0;\nconst Controller_1 = __importDefault(require(\"./Controller\"));\nconst edge_detection_1 = __importDefault(require(\"./utilities/edge-detection\"));\nconst position_1 = require(\"./utilities/position\");\nconst expanded = 'aria-expanded';\nconst placement = 'data-edl-placement';\nconst alignment = 'data-edl-alignment';\nclass PopoverController extends Controller_1.default {\n constructor(elements, options) {\n super(PopoverController.initialAttributes, elements, options);\n this.placementDefault = position_1.Positions.top;\n this.alignmentDefault = position_1.Positions.start;\n this.open = () => {\n this.adjustPosition();\n this.attributes = Object.assign(Object.assign({}, this.attributes), { trigger: Object.assign(Object.assign({}, this.attributes.trigger), { [expanded]: 'true' }) });\n this.addEventListeners();\n };\n this.close = () => {\n this.attributes = Object.assign(Object.assign({}, this.attributes), { trigger: Object.assign(Object.assign({}, this.attributes.trigger), { [expanded]: 'false' }) });\n this.removeEventListeners();\n if (this.elements.trigger.checkVisibility() &&\n !this.elements.trigger.disabled) {\n this.elements.trigger.focus();\n }\n };\n this.toggle = () => (this.isOpen ? this.close() : this.open());\n this.setDefaultPosition = (value, direction) => {\n if (Object.values(position_1.Positions).includes(value)) {\n return value;\n }\n else {\n return direction === placement\n ? this.placementDefault\n : this.alignmentDefault;\n }\n };\n this.handleEscKey = (event) => {\n if (event.key === 'Escape') {\n this.close();\n }\n };\n const initialPlacement = this.elements.container.getAttribute('data-edl-placement');\n const initialAlignment = this.elements.container.getAttribute('data-edl-alignment');\n this.attributes = {\n container: {\n [placement]: this.setDefaultPosition(initialPlacement !== null && initialPlacement !== void 0 ? initialPlacement : this.placementDefault, placement),\n [alignment]: this.setDefaultPosition(initialAlignment !== null && initialAlignment !== void 0 ? initialAlignment : this.alignmentDefault, alignment),\n },\n trigger: {\n [expanded]: elements.trigger.getAttribute(expanded) === 'true' ? 'true' : 'false',\n onclick: this.toggle,\n },\n };\n }\n get isOpen() {\n return this.attributes.trigger[expanded] === 'true';\n }\n addEventListeners() {\n document.addEventListener('keydown', this.handleEscKey);\n }\n removeEventListeners() {\n document.removeEventListener('keydown', this.handleEscKey);\n }\n adjustPosition() {\n const overflowedEdges = (0, edge_detection_1.default)(this.elements.popover);\n const currentPlacement = this.attributes.container[placement];\n const currentAlignment = this.attributes.container[alignment];\n let newPlacement = currentPlacement;\n let newAlignment = currentAlignment;\n // Handle vertical overflow (top or bottom edges).\n // If the current placement is horizontal ('left' or 'right'), flip the alignment.\n // Otherwise, adjust the placement to avoid overflow based on the specific edge.\n if (overflowedEdges.top || overflowedEdges.bottom) {\n if (currentPlacement === position_1.Positions.left ||\n currentPlacement === position_1.Positions.right) {\n newAlignment = (0, position_1.flipAlignment)(currentAlignment);\n }\n else {\n newPlacement = overflowedEdges.top\n ? (0, position_1.flipPosition)(currentPlacement, position_1.Positions.bottom)\n : (0, position_1.flipPosition)(currentPlacement, position_1.Positions.top);\n }\n }\n // Handle horizontal overflow (left or right edges).\n // If the current placement is vertical ('top' or 'bottom'), flip the alignment.\n // Otherwise, adjust the placement to avoid overflow based on the specific edge.\n if (overflowedEdges.right || overflowedEdges.left) {\n if (currentPlacement === position_1.Positions.top ||\n currentPlacement === position_1.Positions.bottom) {\n newAlignment = (0, position_1.flipAlignment)(currentAlignment);\n }\n else {\n newPlacement = overflowedEdges.left\n ? (0, position_1.flipPosition)(currentPlacement, position_1.Positions.right)\n : (0, position_1.flipPosition)(currentPlacement, position_1.Positions.left);\n }\n }\n this.attributes = Object.assign(Object.assign({}, this.attributes), { container: Object.assign(Object.assign({}, this.attributes.container), { [placement]: newPlacement, [alignment]: newAlignment }) });\n }\n}\nexports.PopoverController = PopoverController;\nPopoverController.initialAttributes = {\n container: {},\n trigger: {\n [expanded]: 'false',\n onclick: Controller_1.default.uninitializedHandler,\n },\n};\n", "\"use strict\";\nvar __importDefault = (this && this.__importDefault) || function (mod) {\n return (mod && mod.__esModule) ? mod : { \"default\": mod };\n};\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.SwitchController = void 0;\nconst Controller_1 = __importDefault(require(\"./Controller\"));\nclass SwitchController extends Controller_1.default {\n constructor(elements, options) {\n super(SwitchController.initialAttributes, elements, options);\n this.toggle = () => {\n this.checked = !this.checked;\n };\n this.attributes = {\n button: {\n 'aria-checked': this.elements.button.ariaChecked === 'true' ? 'true' : 'false',\n onclick: this.toggle,\n },\n };\n }\n set checked(value) {\n this.attributes = Object.assign(Object.assign({}, this.attributes), { button: Object.assign(Object.assign({}, this.attributes.button), { 'aria-checked': value ? 'true' : 'false' }) });\n }\n get checked() {\n return this.attributes.button['aria-checked'] === 'true';\n }\n}\nexports.SwitchController = SwitchController;\nSwitchController.initialAttributes = {\n button: {\n 'aria-checked': 'false',\n onclick: Controller_1.default.uninitializedHandler,\n },\n};\n", "/*\nStimulus 3.2.1\nCopyright \u00A9 2023 Basecamp, LLC\n */\nclass EventListener {\n constructor(eventTarget, eventName, eventOptions) {\n this.eventTarget = eventTarget;\n this.eventName = eventName;\n this.eventOptions = eventOptions;\n this.unorderedBindings = new Set();\n }\n connect() {\n this.eventTarget.addEventListener(this.eventName, this, this.eventOptions);\n }\n disconnect() {\n this.eventTarget.removeEventListener(this.eventName, this, this.eventOptions);\n }\n bindingConnected(binding) {\n this.unorderedBindings.add(binding);\n }\n bindingDisconnected(binding) {\n this.unorderedBindings.delete(binding);\n }\n handleEvent(event) {\n const extendedEvent = extendEvent(event);\n for (const binding of this.bindings) {\n if (extendedEvent.immediatePropagationStopped) {\n break;\n }\n else {\n binding.handleEvent(extendedEvent);\n }\n }\n }\n hasBindings() {\n return this.unorderedBindings.size > 0;\n }\n get bindings() {\n return Array.from(this.unorderedBindings).sort((left, right) => {\n const leftIndex = left.index, rightIndex = right.index;\n return leftIndex < rightIndex ? -1 : leftIndex > rightIndex ? 1 : 0;\n });\n }\n}\nfunction extendEvent(event) {\n if (\"immediatePropagationStopped\" in event) {\n return event;\n }\n else {\n const { stopImmediatePropagation } = event;\n return Object.assign(event, {\n immediatePropagationStopped: false,\n stopImmediatePropagation() {\n this.immediatePropagationStopped = true;\n stopImmediatePropagation.call(this);\n },\n });\n }\n}\n\nclass Dispatcher {\n constructor(application) {\n this.application = application;\n this.eventListenerMaps = new Map();\n this.started = false;\n }\n start() {\n if (!this.started) {\n this.started = true;\n this.eventListeners.forEach((eventListener) => eventListener.connect());\n }\n }\n stop() {\n if (this.started) {\n this.started = false;\n this.eventListeners.forEach((eventListener) => eventListener.disconnect());\n }\n }\n get eventListeners() {\n return Array.from(this.eventListenerMaps.values()).reduce((listeners, map) => listeners.concat(Array.from(map.values())), []);\n }\n bindingConnected(binding) {\n this.fetchEventListenerForBinding(binding).bindingConnected(binding);\n }\n bindingDisconnected(binding, clearEventListeners = false) {\n this.fetchEventListenerForBinding(binding).bindingDisconnected(binding);\n if (clearEventListeners)\n this.clearEventListenersForBinding(binding);\n }\n handleError(error, message, detail = {}) {\n this.application.handleError(error, `Error ${message}`, detail);\n }\n clearEventListenersForBinding(binding) {\n const eventListener = this.fetchEventListenerForBinding(binding);\n if (!eventListener.hasBindings()) {\n eventListener.disconnect();\n this.removeMappedEventListenerFor(binding);\n }\n }\n removeMappedEventListenerFor(binding) {\n const { eventTarget, eventName, eventOptions } = binding;\n const eventListenerMap = this.fetchEventListenerMapForEventTarget(eventTarget);\n const cacheKey = this.cacheKey(eventName, eventOptions);\n eventListenerMap.delete(cacheKey);\n if (eventListenerMap.size == 0)\n this.eventListenerMaps.delete(eventTarget);\n }\n fetchEventListenerForBinding(binding) {\n const { eventTarget, eventName, eventOptions } = binding;\n return this.fetchEventListener(eventTarget, eventName, eventOptions);\n }\n fetchEventListener(eventTarget, eventName, eventOptions) {\n const eventListenerMap = this.fetchEventListenerMapForEventTarget(eventTarget);\n const cacheKey = this.cacheKey(eventName, eventOptions);\n let eventListener = eventListenerMap.get(cacheKey);\n if (!eventListener) {\n eventListener = this.createEventListener(eventTarget, eventName, eventOptions);\n eventListenerMap.set(cacheKey, eventListener);\n }\n return eventListener;\n }\n createEventListener(eventTarget, eventName, eventOptions) {\n const eventListener = new EventListener(eventTarget, eventName, eventOptions);\n if (this.started) {\n eventListener.connect();\n }\n return eventListener;\n }\n fetchEventListenerMapForEventTarget(eventTarget) {\n let eventListenerMap = this.eventListenerMaps.get(eventTarget);\n if (!eventListenerMap) {\n eventListenerMap = new Map();\n this.eventListenerMaps.set(eventTarget, eventListenerMap);\n }\n return eventListenerMap;\n }\n cacheKey(eventName, eventOptions) {\n const parts = [eventName];\n Object.keys(eventOptions)\n .sort()\n .forEach((key) => {\n parts.push(`${eventOptions[key] ? \"\" : \"!\"}${key}`);\n });\n return parts.join(\":\");\n }\n}\n\nconst defaultActionDescriptorFilters = {\n stop({ event, value }) {\n if (value)\n event.stopPropagation();\n return true;\n },\n prevent({ event, value }) {\n if (value)\n event.preventDefault();\n return true;\n },\n self({ event, value, element }) {\n if (value) {\n return element === event.target;\n }\n else {\n return true;\n }\n },\n};\nconst descriptorPattern = /^(?:(?:([^.]+?)\\+)?(.+?)(?:\\.(.+?))?(?:@(window|document))?->)?(.+?)(?:#([^:]+?))(?::(.+))?$/;\nfunction parseActionDescriptorString(descriptorString) {\n const source = descriptorString.trim();\n const matches = source.match(descriptorPattern) || [];\n let eventName = matches[2];\n let keyFilter = matches[3];\n if (keyFilter && ![\"keydown\", \"keyup\", \"keypress\"].includes(eventName)) {\n eventName += `.${keyFilter}`;\n keyFilter = \"\";\n }\n return {\n eventTarget: parseEventTarget(matches[4]),\n eventName,\n eventOptions: matches[7] ? parseEventOptions(matches[7]) : {},\n identifier: matches[5],\n methodName: matches[6],\n keyFilter: matches[1] || keyFilter,\n };\n}\nfunction parseEventTarget(eventTargetName) {\n if (eventTargetName == \"window\") {\n return window;\n }\n else if (eventTargetName == \"document\") {\n return document;\n }\n}\nfunction parseEventOptions(eventOptions) {\n return eventOptions\n .split(\":\")\n .reduce((options, token) => Object.assign(options, { [token.replace(/^!/, \"\")]: !/^!/.test(token) }), {});\n}\nfunction stringifyEventTarget(eventTarget) {\n if (eventTarget == window) {\n return \"window\";\n }\n else if (eventTarget == document) {\n return \"document\";\n }\n}\n\nfunction camelize(value) {\n return value.replace(/(?:[_-])([a-z0-9])/g, (_, char) => char.toUpperCase());\n}\nfunction namespaceCamelize(value) {\n return camelize(value.replace(/--/g, \"-\").replace(/__/g, \"_\"));\n}\nfunction capitalize(value) {\n return value.charAt(0).toUpperCase() + value.slice(1);\n}\nfunction dasherize(value) {\n return value.replace(/([A-Z])/g, (_, char) => `-${char.toLowerCase()}`);\n}\nfunction tokenize(value) {\n return value.match(/[^\\s]+/g) || [];\n}\n\nfunction isSomething(object) {\n return object !== null && object !== undefined;\n}\nfunction hasProperty(object, property) {\n return Object.prototype.hasOwnProperty.call(object, property);\n}\n\nconst allModifiers = [\"meta\", \"ctrl\", \"alt\", \"shift\"];\nclass Action {\n constructor(element, index, descriptor, schema) {\n this.element = element;\n this.index = index;\n this.eventTarget = descriptor.eventTarget || element;\n this.eventName = descriptor.eventName || getDefaultEventNameForElement(element) || error(\"missing event name\");\n this.eventOptions = descriptor.eventOptions || {};\n this.identifier = descriptor.identifier || error(\"missing identifier\");\n this.methodName = descriptor.methodName || error(\"missing method name\");\n this.keyFilter = descriptor.keyFilter || \"\";\n this.schema = schema;\n }\n static forToken(token, schema) {\n return new this(token.element, token.index, parseActionDescriptorString(token.content), schema);\n }\n toString() {\n const eventFilter = this.keyFilter ? `.${this.keyFilter}` : \"\";\n const eventTarget = this.eventTargetName ? `@${this.eventTargetName}` : \"\";\n return `${this.eventName}${eventFilter}${eventTarget}->${this.identifier}#${this.methodName}`;\n }\n shouldIgnoreKeyboardEvent(event) {\n if (!this.keyFilter) {\n return false;\n }\n const filters = this.keyFilter.split(\"+\");\n if (this.keyFilterDissatisfied(event, filters)) {\n return true;\n }\n const standardFilter = filters.filter((key) => !allModifiers.includes(key))[0];\n if (!standardFilter) {\n return false;\n }\n if (!hasProperty(this.keyMappings, standardFilter)) {\n error(`contains unknown key filter: ${this.keyFilter}`);\n }\n return this.keyMappings[standardFilter].toLowerCase() !== event.key.toLowerCase();\n }\n shouldIgnoreMouseEvent(event) {\n if (!this.keyFilter) {\n return false;\n }\n const filters = [this.keyFilter];\n if (this.keyFilterDissatisfied(event, filters)) {\n return true;\n }\n return false;\n }\n get params() {\n const params = {};\n const pattern = new RegExp(`^data-${this.identifier}-(.+)-param$`, \"i\");\n for (const { name, value } of Array.from(this.element.attributes)) {\n const match = name.match(pattern);\n const key = match && match[1];\n if (key) {\n params[camelize(key)] = typecast(value);\n }\n }\n return params;\n }\n get eventTargetName() {\n return stringifyEventTarget(this.eventTarget);\n }\n get keyMappings() {\n return this.schema.keyMappings;\n }\n keyFilterDissatisfied(event, filters) {\n const [meta, ctrl, alt, shift] = allModifiers.map((modifier) => filters.includes(modifier));\n return event.metaKey !== meta || event.ctrlKey !== ctrl || event.altKey !== alt || event.shiftKey !== shift;\n }\n}\nconst defaultEventNames = {\n a: () => \"click\",\n button: () => \"click\",\n form: () => \"submit\",\n details: () => \"toggle\",\n input: (e) => (e.getAttribute(\"type\") == \"submit\" ? \"click\" : \"input\"),\n select: () => \"change\",\n textarea: () => \"input\",\n};\nfunction getDefaultEventNameForElement(element) {\n const tagName = element.tagName.toLowerCase();\n if (tagName in defaultEventNames) {\n return defaultEventNames[tagName](element);\n }\n}\nfunction error(message) {\n throw new Error(message);\n}\nfunction typecast(value) {\n try {\n return JSON.parse(value);\n }\n catch (o_O) {\n return value;\n }\n}\n\nclass Binding {\n constructor(context, action) {\n this.context = context;\n this.action = action;\n }\n get index() {\n return this.action.index;\n }\n get eventTarget() {\n return this.action.eventTarget;\n }\n get eventOptions() {\n return this.action.eventOptions;\n }\n get identifier() {\n return this.context.identifier;\n }\n handleEvent(event) {\n const actionEvent = this.prepareActionEvent(event);\n if (this.willBeInvokedByEvent(event) && this.applyEventModifiers(actionEvent)) {\n this.invokeWithEvent(actionEvent);\n }\n }\n get eventName() {\n return this.action.eventName;\n }\n get method() {\n const method = this.controller[this.methodName];\n if (typeof method == \"function\") {\n return method;\n }\n throw new Error(`Action \"${this.action}\" references undefined method \"${this.methodName}\"`);\n }\n applyEventModifiers(event) {\n const { element } = this.action;\n const { actionDescriptorFilters } = this.context.application;\n const { controller } = this.context;\n let passes = true;\n for (const [name, value] of Object.entries(this.eventOptions)) {\n if (name in actionDescriptorFilters) {\n const filter = actionDescriptorFilters[name];\n passes = passes && filter({ name, value, event, element, controller });\n }\n else {\n continue;\n }\n }\n return passes;\n }\n prepareActionEvent(event) {\n return Object.assign(event, { params: this.action.params });\n }\n invokeWithEvent(event) {\n const { target, currentTarget } = event;\n try {\n this.method.call(this.controller, event);\n this.context.logDebugActivity(this.methodName, { event, target, currentTarget, action: this.methodName });\n }\n catch (error) {\n const { identifier, controller, element, index } = this;\n const detail = { identifier, controller, element, index, event };\n this.context.handleError(error, `invoking action \"${this.action}\"`, detail);\n }\n }\n willBeInvokedByEvent(event) {\n const eventTarget = event.target;\n if (event instanceof KeyboardEvent && this.action.shouldIgnoreKeyboardEvent(event)) {\n return false;\n }\n if (event instanceof MouseEvent && this.action.shouldIgnoreMouseEvent(event)) {\n return false;\n }\n if (this.element === eventTarget) {\n return true;\n }\n else if (eventTarget instanceof Element && this.element.contains(eventTarget)) {\n return this.scope.containsElement(eventTarget);\n }\n else {\n return this.scope.containsElement(this.action.element);\n }\n }\n get controller() {\n return this.context.controller;\n }\n get methodName() {\n return this.action.methodName;\n }\n get element() {\n return this.scope.element;\n }\n get scope() {\n return this.context.scope;\n }\n}\n\nclass ElementObserver {\n constructor(element, delegate) {\n this.mutationObserverInit = { attributes: true, childList: true, subtree: true };\n this.element = element;\n this.started = false;\n this.delegate = delegate;\n this.elements = new Set();\n this.mutationObserver = new MutationObserver((mutations) => this.processMutations(mutations));\n }\n start() {\n if (!this.started) {\n this.started = true;\n this.mutationObserver.observe(this.element, this.mutationObserverInit);\n this.refresh();\n }\n }\n pause(callback) {\n if (this.started) {\n this.mutationObserver.disconnect();\n this.started = false;\n }\n callback();\n if (!this.started) {\n this.mutationObserver.observe(this.element, this.mutationObserverInit);\n this.started = true;\n }\n }\n stop() {\n if (this.started) {\n this.mutationObserver.takeRecords();\n this.mutationObserver.disconnect();\n this.started = false;\n }\n }\n refresh() {\n if (this.started) {\n const matches = new Set(this.matchElementsInTree());\n for (const element of Array.from(this.elements)) {\n if (!matches.has(element)) {\n this.removeElement(element);\n }\n }\n for (const element of Array.from(matches)) {\n this.addElement(element);\n }\n }\n }\n processMutations(mutations) {\n if (this.started) {\n for (const mutation of mutations) {\n this.processMutation(mutation);\n }\n }\n }\n processMutation(mutation) {\n if (mutation.type == \"attributes\") {\n this.processAttributeChange(mutation.target, mutation.attributeName);\n }\n else if (mutation.type == \"childList\") {\n this.processRemovedNodes(mutation.removedNodes);\n this.processAddedNodes(mutation.addedNodes);\n }\n }\n processAttributeChange(element, attributeName) {\n if (this.elements.has(element)) {\n if (this.delegate.elementAttributeChanged && this.matchElement(element)) {\n this.delegate.elementAttributeChanged(element, attributeName);\n }\n else {\n this.removeElement(element);\n }\n }\n else if (this.matchElement(element)) {\n this.addElement(element);\n }\n }\n processRemovedNodes(nodes) {\n for (const node of Array.from(nodes)) {\n const element = this.elementFromNode(node);\n if (element) {\n this.processTree(element, this.removeElement);\n }\n }\n }\n processAddedNodes(nodes) {\n for (const node of Array.from(nodes)) {\n const element = this.elementFromNode(node);\n if (element && this.elementIsActive(element)) {\n this.processTree(element, this.addElement);\n }\n }\n }\n matchElement(element) {\n return this.delegate.matchElement(element);\n }\n matchElementsInTree(tree = this.element) {\n return this.delegate.matchElementsInTree(tree);\n }\n processTree(tree, processor) {\n for (const element of this.matchElementsInTree(tree)) {\n processor.call(this, element);\n }\n }\n elementFromNode(node) {\n if (node.nodeType == Node.ELEMENT_NODE) {\n return node;\n }\n }\n elementIsActive(element) {\n if (element.isConnected != this.element.isConnected) {\n return false;\n }\n else {\n return this.element.contains(element);\n }\n }\n addElement(element) {\n if (!this.elements.has(element)) {\n if (this.elementIsActive(element)) {\n this.elements.add(element);\n if (this.delegate.elementMatched) {\n this.delegate.elementMatched(element);\n }\n }\n }\n }\n removeElement(element) {\n if (this.elements.has(element)) {\n this.elements.delete(element);\n if (this.delegate.elementUnmatched) {\n this.delegate.elementUnmatched(element);\n }\n }\n }\n}\n\nclass AttributeObserver {\n constructor(element, attributeName, delegate) {\n this.attributeName = attributeName;\n this.delegate = delegate;\n this.elementObserver = new ElementObserver(element, this);\n }\n get element() {\n return this.elementObserver.element;\n }\n get selector() {\n return `[${this.attributeName}]`;\n }\n start() {\n this.elementObserver.start();\n }\n pause(callback) {\n this.elementObserver.pause(callback);\n }\n stop() {\n this.elementObserver.stop();\n }\n refresh() {\n this.elementObserver.refresh();\n }\n get started() {\n return this.elementObserver.started;\n }\n matchElement(element) {\n return element.hasAttribute(this.attributeName);\n }\n matchElementsInTree(tree) {\n const match = this.matchElement(tree) ? [tree] : [];\n const matches = Array.from(tree.querySelectorAll(this.selector));\n return match.concat(matches);\n }\n elementMatched(element) {\n if (this.delegate.elementMatchedAttribute) {\n this.delegate.elementMatchedAttribute(element, this.attributeName);\n }\n }\n elementUnmatched(element) {\n if (this.delegate.elementUnmatchedAttribute) {\n this.delegate.elementUnmatchedAttribute(element, this.attributeName);\n }\n }\n elementAttributeChanged(element, attributeName) {\n if (this.delegate.elementAttributeValueChanged && this.attributeName == attributeName) {\n this.delegate.elementAttributeValueChanged(element, attributeName);\n }\n }\n}\n\nfunction add(map, key, value) {\n fetch(map, key).add(value);\n}\nfunction del(map, key, value) {\n fetch(map, key).delete(value);\n prune(map, key);\n}\nfunction fetch(map, key) {\n let values = map.get(key);\n if (!values) {\n values = new Set();\n map.set(key, values);\n }\n return values;\n}\nfunction prune(map, key) {\n const values = map.get(key);\n if (values != null && values.size == 0) {\n map.delete(key);\n }\n}\n\nclass Multimap {\n constructor() {\n this.valuesByKey = new Map();\n }\n get keys() {\n return Array.from(this.valuesByKey.keys());\n }\n get values() {\n const sets = Array.from(this.valuesByKey.values());\n return sets.reduce((values, set) => values.concat(Array.from(set)), []);\n }\n get size() {\n const sets = Array.from(this.valuesByKey.values());\n return sets.reduce((size, set) => size + set.size, 0);\n }\n add(key, value) {\n add(this.valuesByKey, key, value);\n }\n delete(key, value) {\n del(this.valuesByKey, key, value);\n }\n has(key, value) {\n const values = this.valuesByKey.get(key);\n return values != null && values.has(value);\n }\n hasKey(key) {\n return this.valuesByKey.has(key);\n }\n hasValue(value) {\n const sets = Array.from(this.valuesByKey.values());\n return sets.some((set) => set.has(value));\n }\n getValuesForKey(key) {\n const values = this.valuesByKey.get(key);\n return values ? Array.from(values) : [];\n }\n getKeysForValue(value) {\n return Array.from(this.valuesByKey)\n .filter(([_key, values]) => values.has(value))\n .map(([key, _values]) => key);\n }\n}\n\nclass IndexedMultimap extends Multimap {\n constructor() {\n super();\n this.keysByValue = new Map();\n }\n get values() {\n return Array.from(this.keysByValue.keys());\n }\n add(key, value) {\n super.add(key, value);\n add(this.keysByValue, value, key);\n }\n delete(key, value) {\n super.delete(key, value);\n del(this.keysByValue, value, key);\n }\n hasValue(value) {\n return this.keysByValue.has(value);\n }\n getKeysForValue(value) {\n const set = this.keysByValue.get(value);\n return set ? Array.from(set) : [];\n }\n}\n\nclass SelectorObserver {\n constructor(element, selector, delegate, details) {\n this._selector = selector;\n this.details = details;\n this.elementObserver = new ElementObserver(element, this);\n this.delegate = delegate;\n this.matchesByElement = new Multimap();\n }\n get started() {\n return this.elementObserver.started;\n }\n get selector() {\n return this._selector;\n }\n set selector(selector) {\n this._selector = selector;\n this.refresh();\n }\n start() {\n this.elementObserver.start();\n }\n pause(callback) {\n this.elementObserver.pause(callback);\n }\n stop() {\n this.elementObserver.stop();\n }\n refresh() {\n this.elementObserver.refresh();\n }\n get element() {\n return this.elementObserver.element;\n }\n matchElement(element) {\n const { selector } = this;\n if (selector) {\n const matches = element.matches(selector);\n if (this.delegate.selectorMatchElement) {\n return matches && this.delegate.selectorMatchElement(element, this.details);\n }\n return matches;\n }\n else {\n return false;\n }\n }\n matchElementsInTree(tree) {\n const { selector } = this;\n if (selector) {\n const match = this.matchElement(tree) ? [tree] : [];\n const matches = Array.from(tree.querySelectorAll(selector)).filter((match) => this.matchElement(match));\n return match.concat(matches);\n }\n else {\n return [];\n }\n }\n elementMatched(element) {\n const { selector } = this;\n if (selector) {\n this.selectorMatched(element, selector);\n }\n }\n elementUnmatched(element) {\n const selectors = this.matchesByElement.getKeysForValue(element);\n for (const selector of selectors) {\n this.selectorUnmatched(element, selector);\n }\n }\n elementAttributeChanged(element, _attributeName) {\n const { selector } = this;\n if (selector) {\n const matches = this.matchElement(element);\n const matchedBefore = this.matchesByElement.has(selector, element);\n if (matches && !matchedBefore) {\n this.selectorMatched(element, selector);\n }\n else if (!matches && matchedBefore) {\n this.selectorUnmatched(element, selector);\n }\n }\n }\n selectorMatched(element, selector) {\n this.delegate.selectorMatched(element, selector, this.details);\n this.matchesByElement.add(selector, element);\n }\n selectorUnmatched(element, selector) {\n this.delegate.selectorUnmatched(element, selector, this.details);\n this.matchesByElement.delete(selector, element);\n }\n}\n\nclass StringMapObserver {\n constructor(element, delegate) {\n this.element = element;\n this.delegate = delegate;\n this.started = false;\n this.stringMap = new Map();\n this.mutationObserver = new MutationObserver((mutations) => this.processMutations(mutations));\n }\n start() {\n if (!this.started) {\n this.started = true;\n this.mutationObserver.observe(this.element, { attributes: true, attributeOldValue: true });\n this.refresh();\n }\n }\n stop() {\n if (this.started) {\n this.mutationObserver.takeRecords();\n this.mutationObserver.disconnect();\n this.started = false;\n }\n }\n refresh() {\n if (this.started) {\n for (const attributeName of this.knownAttributeNames) {\n this.refreshAttribute(attributeName, null);\n }\n }\n }\n processMutations(mutations) {\n if (this.started) {\n for (const mutation of mutations) {\n this.processMutation(mutation);\n }\n }\n }\n processMutation(mutation) {\n const attributeName = mutation.attributeName;\n if (attributeName) {\n this.refreshAttribute(attributeName, mutation.oldValue);\n }\n }\n refreshAttribute(attributeName, oldValue) {\n const key = this.delegate.getStringMapKeyForAttribute(attributeName);\n if (key != null) {\n if (!this.stringMap.has(attributeName)) {\n this.stringMapKeyAdded(key, attributeName);\n }\n const value = this.element.getAttribute(attributeName);\n if (this.stringMap.get(attributeName) != value) {\n this.stringMapValueChanged(value, key, oldValue);\n }\n if (value == null) {\n const oldValue = this.stringMap.get(attributeName);\n this.stringMap.delete(attributeName);\n if (oldValue)\n this.stringMapKeyRemoved(key, attributeName, oldValue);\n }\n else {\n this.stringMap.set(attributeName, value);\n }\n }\n }\n stringMapKeyAdded(key, attributeName) {\n if (this.delegate.stringMapKeyAdded) {\n this.delegate.stringMapKeyAdded(key, attributeName);\n }\n }\n stringMapValueChanged(value, key, oldValue) {\n if (this.delegate.stringMapValueChanged) {\n this.delegate.stringMapValueChanged(value, key, oldValue);\n }\n }\n stringMapKeyRemoved(key, attributeName, oldValue) {\n if (this.delegate.stringMapKeyRemoved) {\n this.delegate.stringMapKeyRemoved(key, attributeName, oldValue);\n }\n }\n get knownAttributeNames() {\n return Array.from(new Set(this.currentAttributeNames.concat(this.recordedAttributeNames)));\n }\n get currentAttributeNames() {\n return Array.from(this.element.attributes).map((attribute) => attribute.name);\n }\n get recordedAttributeNames() {\n return Array.from(this.stringMap.keys());\n }\n}\n\nclass TokenListObserver {\n constructor(element, attributeName, delegate) {\n this.attributeObserver = new AttributeObserver(element, attributeName, this);\n this.delegate = delegate;\n this.tokensByElement = new Multimap();\n }\n get started() {\n return this.attributeObserver.started;\n }\n start() {\n this.attributeObserver.start();\n }\n pause(callback) {\n this.attributeObserver.pause(callback);\n }\n stop() {\n this.attributeObserver.stop();\n }\n refresh() {\n this.attributeObserver.refresh();\n }\n get element() {\n return this.attributeObserver.element;\n }\n get attributeName() {\n return this.attributeObserver.attributeName;\n }\n elementMatchedAttribute(element) {\n this.tokensMatched(this.readTokensForElement(element));\n }\n elementAttributeValueChanged(element) {\n const [unmatchedTokens, matchedTokens] = this.refreshTokensForElement(element);\n this.tokensUnmatched(unmatchedTokens);\n this.tokensMatched(matchedTokens);\n }\n elementUnmatchedAttribute(element) {\n this.tokensUnmatched(this.tokensByElement.getValuesForKey(element));\n }\n tokensMatched(tokens) {\n tokens.forEach((token) => this.tokenMatched(token));\n }\n tokensUnmatched(tokens) {\n tokens.forEach((token) => this.tokenUnmatched(token));\n }\n tokenMatched(token) {\n this.delegate.tokenMatched(token);\n this.tokensByElement.add(token.element, token);\n }\n tokenUnmatched(token) {\n this.delegate.tokenUnmatched(token);\n this.tokensByElement.delete(token.element, token);\n }\n refreshTokensForElement(element) {\n const previousTokens = this.tokensByElement.getValuesForKey(element);\n const currentTokens = this.readTokensForElement(element);\n const firstDifferingIndex = zip(previousTokens, currentTokens).findIndex(([previousToken, currentToken]) => !tokensAreEqual(previousToken, currentToken));\n if (firstDifferingIndex == -1) {\n return [[], []];\n }\n else {\n return [previousTokens.slice(firstDifferingIndex), currentTokens.slice(firstDifferingIndex)];\n }\n }\n readTokensForElement(element) {\n const attributeName = this.attributeName;\n const tokenString = element.getAttribute(attributeName) || \"\";\n return parseTokenString(tokenString, element, attributeName);\n }\n}\nfunction parseTokenString(tokenString, element, attributeName) {\n return tokenString\n .trim()\n .split(/\\s+/)\n .filter((content) => content.length)\n .map((content, index) => ({ element, attributeName, content, index }));\n}\nfunction zip(left, right) {\n const length = Math.max(left.length, right.length);\n return Array.from({ length }, (_, index) => [left[index], right[index]]);\n}\nfunction tokensAreEqual(left, right) {\n return left && right && left.index == right.index && left.content == right.content;\n}\n\nclass ValueListObserver {\n constructor(element, attributeName, delegate) {\n this.tokenListObserver = new TokenListObserver(element, attributeName, this);\n this.delegate = delegate;\n this.parseResultsByToken = new WeakMap();\n this.valuesByTokenByElement = new WeakMap();\n }\n get started() {\n return this.tokenListObserver.started;\n }\n start() {\n this.tokenListObserver.start();\n }\n stop() {\n this.tokenListObserver.stop();\n }\n refresh() {\n this.tokenListObserver.refresh();\n }\n get element() {\n return this.tokenListObserver.element;\n }\n get attributeName() {\n return this.tokenListObserver.attributeName;\n }\n tokenMatched(token) {\n const { element } = token;\n const { value } = this.fetchParseResultForToken(token);\n if (value) {\n this.fetchValuesByTokenForElement(element).set(token, value);\n this.delegate.elementMatchedValue(element, value);\n }\n }\n tokenUnmatched(token) {\n const { element } = token;\n const { value } = this.fetchParseResultForToken(token);\n if (value) {\n this.fetchValuesByTokenForElement(element).delete(token);\n this.delegate.elementUnmatchedValue(element, value);\n }\n }\n fetchParseResultForToken(token) {\n let parseResult = this.parseResultsByToken.get(token);\n if (!parseResult) {\n parseResult = this.parseToken(token);\n this.parseResultsByToken.set(token, parseResult);\n }\n return parseResult;\n }\n fetchValuesByTokenForElement(element) {\n let valuesByToken = this.valuesByTokenByElement.get(element);\n if (!valuesByToken) {\n valuesByToken = new Map();\n this.valuesByTokenByElement.set(element, valuesByToken);\n }\n return valuesByToken;\n }\n parseToken(token) {\n try {\n const value = this.delegate.parseValueForToken(token);\n return { value };\n }\n catch (error) {\n return { error };\n }\n }\n}\n\nclass BindingObserver {\n constructor(context, delegate) {\n this.context = context;\n this.delegate = delegate;\n this.bindingsByAction = new Map();\n }\n start() {\n if (!this.valueListObserver) {\n this.valueListObserver = new ValueListObserver(this.element, this.actionAttribute, this);\n this.valueListObserver.start();\n }\n }\n stop() {\n if (this.valueListObserver) {\n this.valueListObserver.stop();\n delete this.valueListObserver;\n this.disconnectAllActions();\n }\n }\n get element() {\n return this.context.element;\n }\n get identifier() {\n return this.context.identifier;\n }\n get actionAttribute() {\n return this.schema.actionAttribute;\n }\n get schema() {\n return this.context.schema;\n }\n get bindings() {\n return Array.from(this.bindingsByAction.values());\n }\n connectAction(action) {\n const binding = new Binding(this.context, action);\n this.bindingsByAction.set(action, binding);\n this.delegate.bindingConnected(binding);\n }\n disconnectAction(action) {\n const binding = this.bindingsByAction.get(action);\n if (binding) {\n this.bindingsByAction.delete(action);\n this.delegate.bindingDisconnected(binding);\n }\n }\n disconnectAllActions() {\n this.bindings.forEach((binding) => this.delegate.bindingDisconnected(binding, true));\n this.bindingsByAction.clear();\n }\n parseValueForToken(token) {\n const action = Action.forToken(token, this.schema);\n if (action.identifier == this.identifier) {\n return action;\n }\n }\n elementMatchedValue(element, action) {\n this.connectAction(action);\n }\n elementUnmatchedValue(element, action) {\n this.disconnectAction(action);\n }\n}\n\nclass ValueObserver {\n constructor(context, receiver) {\n this.context = context;\n this.receiver = receiver;\n this.stringMapObserver = new StringMapObserver(this.element, this);\n this.valueDescriptorMap = this.controller.valueDescriptorMap;\n }\n start() {\n this.stringMapObserver.start();\n this.invokeChangedCallbacksForDefaultValues();\n }\n stop() {\n this.stringMapObserver.stop();\n }\n get element() {\n return this.context.element;\n }\n get controller() {\n return this.context.controller;\n }\n getStringMapKeyForAttribute(attributeName) {\n if (attributeName in this.valueDescriptorMap) {\n return this.valueDescriptorMap[attributeName].name;\n }\n }\n stringMapKeyAdded(key, attributeName) {\n const descriptor = this.valueDescriptorMap[attributeName];\n if (!this.hasValue(key)) {\n this.invokeChangedCallback(key, descriptor.writer(this.receiver[key]), descriptor.writer(descriptor.defaultValue));\n }\n }\n stringMapValueChanged(value, name, oldValue) {\n const descriptor = this.valueDescriptorNameMap[name];\n if (value === null)\n return;\n if (oldValue === null) {\n oldValue = descriptor.writer(descriptor.defaultValue);\n }\n this.invokeChangedCallback(name, value, oldValue);\n }\n stringMapKeyRemoved(key, attributeName, oldValue) {\n const descriptor = this.valueDescriptorNameMap[key];\n if (this.hasValue(key)) {\n this.invokeChangedCallback(key, descriptor.writer(this.receiver[key]), oldValue);\n }\n else {\n this.invokeChangedCallback(key, descriptor.writer(descriptor.defaultValue), oldValue);\n }\n }\n invokeChangedCallbacksForDefaultValues() {\n for (const { key, name, defaultValue, writer } of this.valueDescriptors) {\n if (defaultValue != undefined && !this.controller.data.has(key)) {\n this.invokeChangedCallback(name, writer(defaultValue), undefined);\n }\n }\n }\n invokeChangedCallback(name, rawValue, rawOldValue) {\n const changedMethodName = `${name}Changed`;\n const changedMethod = this.receiver[changedMethodName];\n if (typeof changedMethod == \"function\") {\n const descriptor = this.valueDescriptorNameMap[name];\n try {\n const value = descriptor.reader(rawValue);\n let oldValue = rawOldValue;\n if (rawOldValue) {\n oldValue = descriptor.reader(rawOldValue);\n }\n changedMethod.call(this.receiver, value, oldValue);\n }\n catch (error) {\n if (error instanceof TypeError) {\n error.message = `Stimulus Value \"${this.context.identifier}.${descriptor.name}\" - ${error.message}`;\n }\n throw error;\n }\n }\n }\n get valueDescriptors() {\n const { valueDescriptorMap } = this;\n return Object.keys(valueDescriptorMap).map((key) => valueDescriptorMap[key]);\n }\n get valueDescriptorNameMap() {\n const descriptors = {};\n Object.keys(this.valueDescriptorMap).forEach((key) => {\n const descriptor = this.valueDescriptorMap[key];\n descriptors[descriptor.name] = descriptor;\n });\n return descriptors;\n }\n hasValue(attributeName) {\n const descriptor = this.valueDescriptorNameMap[attributeName];\n const hasMethodName = `has${capitalize(descriptor.name)}`;\n return this.receiver[hasMethodName];\n }\n}\n\nclass TargetObserver {\n constructor(context, delegate) {\n this.context = context;\n this.delegate = delegate;\n this.targetsByName = new Multimap();\n }\n start() {\n if (!this.tokenListObserver) {\n this.tokenListObserver = new TokenListObserver(this.element, this.attributeName, this);\n this.tokenListObserver.start();\n }\n }\n stop() {\n if (this.tokenListObserver) {\n this.disconnectAllTargets();\n this.tokenListObserver.stop();\n delete this.tokenListObserver;\n }\n }\n tokenMatched({ element, content: name }) {\n if (this.scope.containsElement(element)) {\n this.connectTarget(element, name);\n }\n }\n tokenUnmatched({ element, content: name }) {\n this.disconnectTarget(element, name);\n }\n connectTarget(element, name) {\n var _a;\n if (!this.targetsByName.has(name, element)) {\n this.targetsByName.add(name, element);\n (_a = this.tokenListObserver) === null || _a === void 0 ? void 0 : _a.pause(() => this.delegate.targetConnected(element, name));\n }\n }\n disconnectTarget(element, name) {\n var _a;\n if (this.targetsByName.has(name, element)) {\n this.targetsByName.delete(name, element);\n (_a = this.tokenListObserver) === null || _a === void 0 ? void 0 : _a.pause(() => this.delegate.targetDisconnected(element, name));\n }\n }\n disconnectAllTargets() {\n for (const name of this.targetsByName.keys) {\n for (const element of this.targetsByName.getValuesForKey(name)) {\n this.disconnectTarget(element, name);\n }\n }\n }\n get attributeName() {\n return `data-${this.context.identifier}-target`;\n }\n get element() {\n return this.context.element;\n }\n get scope() {\n return this.context.scope;\n }\n}\n\nfunction readInheritableStaticArrayValues(constructor, propertyName) {\n const ancestors = getAncestorsForConstructor(constructor);\n return Array.from(ancestors.reduce((values, constructor) => {\n getOwnStaticArrayValues(constructor, propertyName).forEach((name) => values.add(name));\n return values;\n }, new Set()));\n}\nfunction readInheritableStaticObjectPairs(constructor, propertyName) {\n const ancestors = getAncestorsForConstructor(constructor);\n return ancestors.reduce((pairs, constructor) => {\n pairs.push(...getOwnStaticObjectPairs(constructor, propertyName));\n return pairs;\n }, []);\n}\nfunction getAncestorsForConstructor(constructor) {\n const ancestors = [];\n while (constructor) {\n ancestors.push(constructor);\n constructor = Object.getPrototypeOf(constructor);\n }\n return ancestors.reverse();\n}\nfunction getOwnStaticArrayValues(constructor, propertyName) {\n const definition = constructor[propertyName];\n return Array.isArray(definition) ? definition : [];\n}\nfunction getOwnStaticObjectPairs(constructor, propertyName) {\n const definition = constructor[propertyName];\n return definition ? Object.keys(definition).map((key) => [key, definition[key]]) : [];\n}\n\nclass OutletObserver {\n constructor(context, delegate) {\n this.started = false;\n this.context = context;\n this.delegate = delegate;\n this.outletsByName = new Multimap();\n this.outletElementsByName = new Multimap();\n this.selectorObserverMap = new Map();\n this.attributeObserverMap = new Map();\n }\n start() {\n if (!this.started) {\n this.outletDefinitions.forEach((outletName) => {\n this.setupSelectorObserverForOutlet(outletName);\n this.setupAttributeObserverForOutlet(outletName);\n });\n this.started = true;\n this.dependentContexts.forEach((context) => context.refresh());\n }\n }\n refresh() {\n this.selectorObserverMap.forEach((observer) => observer.refresh());\n this.attributeObserverMap.forEach((observer) => observer.refresh());\n }\n stop() {\n if (this.started) {\n this.started = false;\n this.disconnectAllOutlets();\n this.stopSelectorObservers();\n this.stopAttributeObservers();\n }\n }\n stopSelectorObservers() {\n if (this.selectorObserverMap.size > 0) {\n this.selectorObserverMap.forEach((observer) => observer.stop());\n this.selectorObserverMap.clear();\n }\n }\n stopAttributeObservers() {\n if (this.attributeObserverMap.size > 0) {\n this.attributeObserverMap.forEach((observer) => observer.stop());\n this.attributeObserverMap.clear();\n }\n }\n selectorMatched(element, _selector, { outletName }) {\n const outlet = this.getOutlet(element, outletName);\n if (outlet) {\n this.connectOutlet(outlet, element, outletName);\n }\n }\n selectorUnmatched(element, _selector, { outletName }) {\n const outlet = this.getOutletFromMap(element, outletName);\n if (outlet) {\n this.disconnectOutlet(outlet, element, outletName);\n }\n }\n selectorMatchElement(element, { outletName }) {\n const selector = this.selector(outletName);\n const hasOutlet = this.hasOutlet(element, outletName);\n const hasOutletController = element.matches(`[${this.schema.controllerAttribute}~=${outletName}]`);\n if (selector) {\n return hasOutlet && hasOutletController && element.matches(selector);\n }\n else {\n return false;\n }\n }\n elementMatchedAttribute(_element, attributeName) {\n const outletName = this.getOutletNameFromOutletAttributeName(attributeName);\n if (outletName) {\n this.updateSelectorObserverForOutlet(outletName);\n }\n }\n elementAttributeValueChanged(_element, attributeName) {\n const outletName = this.getOutletNameFromOutletAttributeName(attributeName);\n if (outletName) {\n this.updateSelectorObserverForOutlet(outletName);\n }\n }\n elementUnmatchedAttribute(_element, attributeName) {\n const outletName = this.getOutletNameFromOutletAttributeName(attributeName);\n if (outletName) {\n this.updateSelectorObserverForOutlet(outletName);\n }\n }\n connectOutlet(outlet, element, outletName) {\n var _a;\n if (!this.outletElementsByName.has(outletName, element)) {\n this.outletsByName.add(outletName, outlet);\n this.outletElementsByName.add(outletName, element);\n (_a = this.selectorObserverMap.get(outletName)) === null || _a === void 0 ? void 0 : _a.pause(() => this.delegate.outletConnected(outlet, element, outletName));\n }\n }\n disconnectOutlet(outlet, element, outletName) {\n var _a;\n if (this.outletElementsByName.has(outletName, element)) {\n this.outletsByName.delete(outletName, outlet);\n this.outletElementsByName.delete(outletName, element);\n (_a = this.selectorObserverMap\n .get(outletName)) === null || _a === void 0 ? void 0 : _a.pause(() => this.delegate.outletDisconnected(outlet, element, outletName));\n }\n }\n disconnectAllOutlets() {\n for (const outletName of this.outletElementsByName.keys) {\n for (const element of this.outletElementsByName.getValuesForKey(outletName)) {\n for (const outlet of this.outletsByName.getValuesForKey(outletName)) {\n this.disconnectOutlet(outlet, element, outletName);\n }\n }\n }\n }\n updateSelectorObserverForOutlet(outletName) {\n const observer = this.selectorObserverMap.get(outletName);\n if (observer) {\n observer.selector = this.selector(outletName);\n }\n }\n setupSelectorObserverForOutlet(outletName) {\n const selector = this.selector(outletName);\n const selectorObserver = new SelectorObserver(document.body, selector, this, { outletName });\n this.selectorObserverMap.set(outletName, selectorObserver);\n selectorObserver.start();\n }\n setupAttributeObserverForOutlet(outletName) {\n const attributeName = this.attributeNameForOutletName(outletName);\n const attributeObserver = new AttributeObserver(this.scope.element, attributeName, this);\n this.attributeObserverMap.set(outletName, attributeObserver);\n attributeObserver.start();\n }\n selector(outletName) {\n return this.scope.outlets.getSelectorForOutletName(outletName);\n }\n attributeNameForOutletName(outletName) {\n return this.scope.schema.outletAttributeForScope(this.identifier, outletName);\n }\n getOutletNameFromOutletAttributeName(attributeName) {\n return this.outletDefinitions.find((outletName) => this.attributeNameForOutletName(outletName) === attributeName);\n }\n get outletDependencies() {\n const dependencies = new Multimap();\n this.router.modules.forEach((module) => {\n const constructor = module.definition.controllerConstructor;\n const outlets = readInheritableStaticArrayValues(constructor, \"outlets\");\n outlets.forEach((outlet) => dependencies.add(outlet, module.identifier));\n });\n return dependencies;\n }\n get outletDefinitions() {\n return this.outletDependencies.getKeysForValue(this.identifier);\n }\n get dependentControllerIdentifiers() {\n return this.outletDependencies.getValuesForKey(this.identifier);\n }\n get dependentContexts() {\n const identifiers = this.dependentControllerIdentifiers;\n return this.router.contexts.filter((context) => identifiers.includes(context.identifier));\n }\n hasOutlet(element, outletName) {\n return !!this.getOutlet(element, outletName) || !!this.getOutletFromMap(element, outletName);\n }\n getOutlet(element, outletName) {\n return this.application.getControllerForElementAndIdentifier(element, outletName);\n }\n getOutletFromMap(element, outletName) {\n return this.outletsByName.getValuesForKey(outletName).find((outlet) => outlet.element === element);\n }\n get scope() {\n return this.context.scope;\n }\n get schema() {\n return this.context.schema;\n }\n get identifier() {\n return this.context.identifier;\n }\n get application() {\n return this.context.application;\n }\n get router() {\n return this.application.router;\n }\n}\n\nclass Context {\n constructor(module, scope) {\n this.logDebugActivity = (functionName, detail = {}) => {\n const { identifier, controller, element } = this;\n detail = Object.assign({ identifier, controller, element }, detail);\n this.application.logDebugActivity(this.identifier, functionName, detail);\n };\n this.module = module;\n this.scope = scope;\n this.controller = new module.controllerConstructor(this);\n this.bindingObserver = new BindingObserver(this, this.dispatcher);\n this.valueObserver = new ValueObserver(this, this.controller);\n this.targetObserver = new TargetObserver(this, this);\n this.outletObserver = new OutletObserver(this, this);\n try {\n this.controller.initialize();\n this.logDebugActivity(\"initialize\");\n }\n catch (error) {\n this.handleError(error, \"initializing controller\");\n }\n }\n connect() {\n this.bindingObserver.start();\n this.valueObserver.start();\n this.targetObserver.start();\n this.outletObserver.start();\n try {\n this.controller.connect();\n this.logDebugActivity(\"connect\");\n }\n catch (error) {\n this.handleError(error, \"connecting controller\");\n }\n }\n refresh() {\n this.outletObserver.refresh();\n }\n disconnect() {\n try {\n this.controller.disconnect();\n this.logDebugActivity(\"disconnect\");\n }\n catch (error) {\n this.handleError(error, \"disconnecting controller\");\n }\n this.outletObserver.stop();\n this.targetObserver.stop();\n this.valueObserver.stop();\n this.bindingObserver.stop();\n }\n get application() {\n return this.module.application;\n }\n get identifier() {\n return this.module.identifier;\n }\n get schema() {\n return this.application.schema;\n }\n get dispatcher() {\n return this.application.dispatcher;\n }\n get element() {\n return this.scope.element;\n }\n get parentElement() {\n return this.element.parentElement;\n }\n handleError(error, message, detail = {}) {\n const { identifier, controller, element } = this;\n detail = Object.assign({ identifier, controller, element }, detail);\n this.application.handleError(error, `Error ${message}`, detail);\n }\n targetConnected(element, name) {\n this.invokeControllerMethod(`${name}TargetConnected`, element);\n }\n targetDisconnected(element, name) {\n this.invokeControllerMethod(`${name}TargetDisconnected`, element);\n }\n outletConnected(outlet, element, name) {\n this.invokeControllerMethod(`${namespaceCamelize(name)}OutletConnected`, outlet, element);\n }\n outletDisconnected(outlet, element, name) {\n this.invokeControllerMethod(`${namespaceCamelize(name)}OutletDisconnected`, outlet, element);\n }\n invokeControllerMethod(methodName, ...args) {\n const controller = this.controller;\n if (typeof controller[methodName] == \"function\") {\n controller[methodName](...args);\n }\n }\n}\n\nfunction bless(constructor) {\n return shadow(constructor, getBlessedProperties(constructor));\n}\nfunction shadow(constructor, properties) {\n const shadowConstructor = extend(constructor);\n const shadowProperties = getShadowProperties(constructor.prototype, properties);\n Object.defineProperties(shadowConstructor.prototype, shadowProperties);\n return shadowConstructor;\n}\nfunction getBlessedProperties(constructor) {\n const blessings = readInheritableStaticArrayValues(constructor, \"blessings\");\n return blessings.reduce((blessedProperties, blessing) => {\n const properties = blessing(constructor);\n for (const key in properties) {\n const descriptor = blessedProperties[key] || {};\n blessedProperties[key] = Object.assign(descriptor, properties[key]);\n }\n return blessedProperties;\n }, {});\n}\nfunction getShadowProperties(prototype, properties) {\n return getOwnKeys(properties).reduce((shadowProperties, key) => {\n const descriptor = getShadowedDescriptor(prototype, properties, key);\n if (descriptor) {\n Object.assign(shadowProperties, { [key]: descriptor });\n }\n return shadowProperties;\n }, {});\n}\nfunction getShadowedDescriptor(prototype, properties, key) {\n const shadowingDescriptor = Object.getOwnPropertyDescriptor(prototype, key);\n const shadowedByValue = shadowingDescriptor && \"value\" in shadowingDescriptor;\n if (!shadowedByValue) {\n const descriptor = Object.getOwnPropertyDescriptor(properties, key).value;\n if (shadowingDescriptor) {\n descriptor.get = shadowingDescriptor.get || descriptor.get;\n descriptor.set = shadowingDescriptor.set || descriptor.set;\n }\n return descriptor;\n }\n}\nconst getOwnKeys = (() => {\n if (typeof Object.getOwnPropertySymbols == \"function\") {\n return (object) => [...Object.getOwnPropertyNames(object), ...Object.getOwnPropertySymbols(object)];\n }\n else {\n return Object.getOwnPropertyNames;\n }\n})();\nconst extend = (() => {\n function extendWithReflect(constructor) {\n function extended() {\n return Reflect.construct(constructor, arguments, new.target);\n }\n extended.prototype = Object.create(constructor.prototype, {\n constructor: { value: extended },\n });\n Reflect.setPrototypeOf(extended, constructor);\n return extended;\n }\n function testReflectExtension() {\n const a = function () {\n this.a.call(this);\n };\n const b = extendWithReflect(a);\n b.prototype.a = function () { };\n return new b();\n }\n try {\n testReflectExtension();\n return extendWithReflect;\n }\n catch (error) {\n return (constructor) => class extended extends constructor {\n };\n }\n})();\n\nfunction blessDefinition(definition) {\n return {\n identifier: definition.identifier,\n controllerConstructor: bless(definition.controllerConstructor),\n };\n}\n\nclass Module {\n constructor(application, definition) {\n this.application = application;\n this.definition = blessDefinition(definition);\n this.contextsByScope = new WeakMap();\n this.connectedContexts = new Set();\n }\n get identifier() {\n return this.definition.identifier;\n }\n get controllerConstructor() {\n return this.definition.controllerConstructor;\n }\n get contexts() {\n return Array.from(this.connectedContexts);\n }\n connectContextForScope(scope) {\n const context = this.fetchContextForScope(scope);\n this.connectedContexts.add(context);\n context.connect();\n }\n disconnectContextForScope(scope) {\n const context = this.contextsByScope.get(scope);\n if (context) {\n this.connectedContexts.delete(context);\n context.disconnect();\n }\n }\n fetchContextForScope(scope) {\n let context = this.contextsByScope.get(scope);\n if (!context) {\n context = new Context(this, scope);\n this.contextsByScope.set(scope, context);\n }\n return context;\n }\n}\n\nclass ClassMap {\n constructor(scope) {\n this.scope = scope;\n }\n has(name) {\n return this.data.has(this.getDataKey(name));\n }\n get(name) {\n return this.getAll(name)[0];\n }\n getAll(name) {\n const tokenString = this.data.get(this.getDataKey(name)) || \"\";\n return tokenize(tokenString);\n }\n getAttributeName(name) {\n return this.data.getAttributeNameForKey(this.getDataKey(name));\n }\n getDataKey(name) {\n return `${name}-class`;\n }\n get data() {\n return this.scope.data;\n }\n}\n\nclass DataMap {\n constructor(scope) {\n this.scope = scope;\n }\n get element() {\n return this.scope.element;\n }\n get identifier() {\n return this.scope.identifier;\n }\n get(key) {\n const name = this.getAttributeNameForKey(key);\n return this.element.getAttribute(name);\n }\n set(key, value) {\n const name = this.getAttributeNameForKey(key);\n this.element.setAttribute(name, value);\n return this.get(key);\n }\n has(key) {\n const name = this.getAttributeNameForKey(key);\n return this.element.hasAttribute(name);\n }\n delete(key) {\n if (this.has(key)) {\n const name = this.getAttributeNameForKey(key);\n this.element.removeAttribute(name);\n return true;\n }\n else {\n return false;\n }\n }\n getAttributeNameForKey(key) {\n return `data-${this.identifier}-${dasherize(key)}`;\n }\n}\n\nclass Guide {\n constructor(logger) {\n this.warnedKeysByObject = new WeakMap();\n this.logger = logger;\n }\n warn(object, key, message) {\n let warnedKeys = this.warnedKeysByObject.get(object);\n if (!warnedKeys) {\n warnedKeys = new Set();\n this.warnedKeysByObject.set(object, warnedKeys);\n }\n if (!warnedKeys.has(key)) {\n warnedKeys.add(key);\n this.logger.warn(message, object);\n }\n }\n}\n\nfunction attributeValueContainsToken(attributeName, token) {\n return `[${attributeName}~=\"${token}\"]`;\n}\n\nclass TargetSet {\n constructor(scope) {\n this.scope = scope;\n }\n get element() {\n return this.scope.element;\n }\n get identifier() {\n return this.scope.identifier;\n }\n get schema() {\n return this.scope.schema;\n }\n has(targetName) {\n return this.find(targetName) != null;\n }\n find(...targetNames) {\n return targetNames.reduce((target, targetName) => target || this.findTarget(targetName) || this.findLegacyTarget(targetName), undefined);\n }\n findAll(...targetNames) {\n return targetNames.reduce((targets, targetName) => [\n ...targets,\n ...this.findAllTargets(targetName),\n ...this.findAllLegacyTargets(targetName),\n ], []);\n }\n findTarget(targetName) {\n const selector = this.getSelectorForTargetName(targetName);\n return this.scope.findElement(selector);\n }\n findAllTargets(targetName) {\n const selector = this.getSelectorForTargetName(targetName);\n return this.scope.findAllElements(selector);\n }\n getSelectorForTargetName(targetName) {\n const attributeName = this.schema.targetAttributeForScope(this.identifier);\n return attributeValueContainsToken(attributeName, targetName);\n }\n findLegacyTarget(targetName) {\n const selector = this.getLegacySelectorForTargetName(targetName);\n return this.deprecate(this.scope.findElement(selector), targetName);\n }\n findAllLegacyTargets(targetName) {\n const selector = this.getLegacySelectorForTargetName(targetName);\n return this.scope.findAllElements(selector).map((element) => this.deprecate(element, targetName));\n }\n getLegacySelectorForTargetName(targetName) {\n const targetDescriptor = `${this.identifier}.${targetName}`;\n return attributeValueContainsToken(this.schema.targetAttribute, targetDescriptor);\n }\n deprecate(element, targetName) {\n if (element) {\n const { identifier } = this;\n const attributeName = this.schema.targetAttribute;\n const revisedAttributeName = this.schema.targetAttributeForScope(identifier);\n this.guide.warn(element, `target:${targetName}`, `Please replace ${attributeName}=\"${identifier}.${targetName}\" with ${revisedAttributeName}=\"${targetName}\". ` +\n `The ${attributeName} attribute is deprecated and will be removed in a future version of Stimulus.`);\n }\n return element;\n }\n get guide() {\n return this.scope.guide;\n }\n}\n\nclass OutletSet {\n constructor(scope, controllerElement) {\n this.scope = scope;\n this.controllerElement = controllerElement;\n }\n get element() {\n return this.scope.element;\n }\n get identifier() {\n return this.scope.identifier;\n }\n get schema() {\n return this.scope.schema;\n }\n has(outletName) {\n return this.find(outletName) != null;\n }\n find(...outletNames) {\n return outletNames.reduce((outlet, outletName) => outlet || this.findOutlet(outletName), undefined);\n }\n findAll(...outletNames) {\n return outletNames.reduce((outlets, outletName) => [...outlets, ...this.findAllOutlets(outletName)], []);\n }\n getSelectorForOutletName(outletName) {\n const attributeName = this.schema.outletAttributeForScope(this.identifier, outletName);\n return this.controllerElement.getAttribute(attributeName);\n }\n findOutlet(outletName) {\n const selector = this.getSelectorForOutletName(outletName);\n if (selector)\n return this.findElement(selector, outletName);\n }\n findAllOutlets(outletName) {\n const selector = this.getSelectorForOutletName(outletName);\n return selector ? this.findAllElements(selector, outletName) : [];\n }\n findElement(selector, outletName) {\n const elements = this.scope.queryElements(selector);\n return elements.filter((element) => this.matchesElement(element, selector, outletName))[0];\n }\n findAllElements(selector, outletName) {\n const elements = this.scope.queryElements(selector);\n return elements.filter((element) => this.matchesElement(element, selector, outletName));\n }\n matchesElement(element, selector, outletName) {\n const controllerAttribute = element.getAttribute(this.scope.schema.controllerAttribute) || \"\";\n return element.matches(selector) && controllerAttribute.split(\" \").includes(outletName);\n }\n}\n\nclass Scope {\n constructor(schema, element, identifier, logger) {\n this.targets = new TargetSet(this);\n this.classes = new ClassMap(this);\n this.data = new DataMap(this);\n this.containsElement = (element) => {\n return element.closest(this.controllerSelector) === this.element;\n };\n this.schema = schema;\n this.element = element;\n this.identifier = identifier;\n this.guide = new Guide(logger);\n this.outlets = new OutletSet(this.documentScope, element);\n }\n findElement(selector) {\n return this.element.matches(selector) ? this.element : this.queryElements(selector).find(this.containsElement);\n }\n findAllElements(selector) {\n return [\n ...(this.element.matches(selector) ? [this.element] : []),\n ...this.queryElements(selector).filter(this.containsElement),\n ];\n }\n queryElements(selector) {\n return Array.from(this.element.querySelectorAll(selector));\n }\n get controllerSelector() {\n return attributeValueContainsToken(this.schema.controllerAttribute, this.identifier);\n }\n get isDocumentScope() {\n return this.element === document.documentElement;\n }\n get documentScope() {\n return this.isDocumentScope\n ? this\n : new Scope(this.schema, document.documentElement, this.identifier, this.guide.logger);\n }\n}\n\nclass ScopeObserver {\n constructor(element, schema, delegate) {\n this.element = element;\n this.schema = schema;\n this.delegate = delegate;\n this.valueListObserver = new ValueListObserver(this.element, this.controllerAttribute, this);\n this.scopesByIdentifierByElement = new WeakMap();\n this.scopeReferenceCounts = new WeakMap();\n }\n start() {\n this.valueListObserver.start();\n }\n stop() {\n this.valueListObserver.stop();\n }\n get controllerAttribute() {\n return this.schema.controllerAttribute;\n }\n parseValueForToken(token) {\n const { element, content: identifier } = token;\n return this.parseValueForElementAndIdentifier(element, identifier);\n }\n parseValueForElementAndIdentifier(element, identifier) {\n const scopesByIdentifier = this.fetchScopesByIdentifierForElement(element);\n let scope = scopesByIdentifier.get(identifier);\n if (!scope) {\n scope = this.delegate.createScopeForElementAndIdentifier(element, identifier);\n scopesByIdentifier.set(identifier, scope);\n }\n return scope;\n }\n elementMatchedValue(element, value) {\n const referenceCount = (this.scopeReferenceCounts.get(value) || 0) + 1;\n this.scopeReferenceCounts.set(value, referenceCount);\n if (referenceCount == 1) {\n this.delegate.scopeConnected(value);\n }\n }\n elementUnmatchedValue(element, value) {\n const referenceCount = this.scopeReferenceCounts.get(value);\n if (referenceCount) {\n this.scopeReferenceCounts.set(value, referenceCount - 1);\n if (referenceCount == 1) {\n this.delegate.scopeDisconnected(value);\n }\n }\n }\n fetchScopesByIdentifierForElement(element) {\n let scopesByIdentifier = this.scopesByIdentifierByElement.get(element);\n if (!scopesByIdentifier) {\n scopesByIdentifier = new Map();\n this.scopesByIdentifierByElement.set(element, scopesByIdentifier);\n }\n return scopesByIdentifier;\n }\n}\n\nclass Router {\n constructor(application) {\n this.application = application;\n this.scopeObserver = new ScopeObserver(this.element, this.schema, this);\n this.scopesByIdentifier = new Multimap();\n this.modulesByIdentifier = new Map();\n }\n get element() {\n return this.application.element;\n }\n get schema() {\n return this.application.schema;\n }\n get logger() {\n return this.application.logger;\n }\n get controllerAttribute() {\n return this.schema.controllerAttribute;\n }\n get modules() {\n return Array.from(this.modulesByIdentifier.values());\n }\n get contexts() {\n return this.modules.reduce((contexts, module) => contexts.concat(module.contexts), []);\n }\n start() {\n this.scopeObserver.start();\n }\n stop() {\n this.scopeObserver.stop();\n }\n loadDefinition(definition) {\n this.unloadIdentifier(definition.identifier);\n const module = new Module(this.application, definition);\n this.connectModule(module);\n const afterLoad = definition.controllerConstructor.afterLoad;\n if (afterLoad) {\n afterLoad.call(definition.controllerConstructor, definition.identifier, this.application);\n }\n }\n unloadIdentifier(identifier) {\n const module = this.modulesByIdentifier.get(identifier);\n if (module) {\n this.disconnectModule(module);\n }\n }\n getContextForElementAndIdentifier(element, identifier) {\n const module = this.modulesByIdentifier.get(identifier);\n if (module) {\n return module.contexts.find((context) => context.element == element);\n }\n }\n proposeToConnectScopeForElementAndIdentifier(element, identifier) {\n const scope = this.scopeObserver.parseValueForElementAndIdentifier(element, identifier);\n if (scope) {\n this.scopeObserver.elementMatchedValue(scope.element, scope);\n }\n else {\n console.error(`Couldn't find or create scope for identifier: \"${identifier}\" and element:`, element);\n }\n }\n handleError(error, message, detail) {\n this.application.handleError(error, message, detail);\n }\n createScopeForElementAndIdentifier(element, identifier) {\n return new Scope(this.schema, element, identifier, this.logger);\n }\n scopeConnected(scope) {\n this.scopesByIdentifier.add(scope.identifier, scope);\n const module = this.modulesByIdentifier.get(scope.identifier);\n if (module) {\n module.connectContextForScope(scope);\n }\n }\n scopeDisconnected(scope) {\n this.scopesByIdentifier.delete(scope.identifier, scope);\n const module = this.modulesByIdentifier.get(scope.identifier);\n if (module) {\n module.disconnectContextForScope(scope);\n }\n }\n connectModule(module) {\n this.modulesByIdentifier.set(module.identifier, module);\n const scopes = this.scopesByIdentifier.getValuesForKey(module.identifier);\n scopes.forEach((scope) => module.connectContextForScope(scope));\n }\n disconnectModule(module) {\n this.modulesByIdentifier.delete(module.identifier);\n const scopes = this.scopesByIdentifier.getValuesForKey(module.identifier);\n scopes.forEach((scope) => module.disconnectContextForScope(scope));\n }\n}\n\nconst defaultSchema = {\n controllerAttribute: \"data-controller\",\n actionAttribute: \"data-action\",\n targetAttribute: \"data-target\",\n targetAttributeForScope: (identifier) => `data-${identifier}-target`,\n outletAttributeForScope: (identifier, outlet) => `data-${identifier}-${outlet}-outlet`,\n keyMappings: Object.assign(Object.assign({ enter: \"Enter\", tab: \"Tab\", esc: \"Escape\", space: \" \", up: \"ArrowUp\", down: \"ArrowDown\", left: \"ArrowLeft\", right: \"ArrowRight\", home: \"Home\", end: \"End\", page_up: \"PageUp\", page_down: \"PageDown\" }, objectFromEntries(\"abcdefghijklmnopqrstuvwxyz\".split(\"\").map((c) => [c, c]))), objectFromEntries(\"0123456789\".split(\"\").map((n) => [n, n]))),\n};\nfunction objectFromEntries(array) {\n return array.reduce((memo, [k, v]) => (Object.assign(Object.assign({}, memo), { [k]: v })), {});\n}\n\nclass Application {\n constructor(element = document.documentElement, schema = defaultSchema) {\n this.logger = console;\n this.debug = false;\n this.logDebugActivity = (identifier, functionName, detail = {}) => {\n if (this.debug) {\n this.logFormattedMessage(identifier, functionName, detail);\n }\n };\n this.element = element;\n this.schema = schema;\n this.dispatcher = new Dispatcher(this);\n this.router = new Router(this);\n this.actionDescriptorFilters = Object.assign({}, defaultActionDescriptorFilters);\n }\n static start(element, schema) {\n const application = new this(element, schema);\n application.start();\n return application;\n }\n async start() {\n await domReady();\n this.logDebugActivity(\"application\", \"starting\");\n this.dispatcher.start();\n this.router.start();\n this.logDebugActivity(\"application\", \"start\");\n }\n stop() {\n this.logDebugActivity(\"application\", \"stopping\");\n this.dispatcher.stop();\n this.router.stop();\n this.logDebugActivity(\"application\", \"stop\");\n }\n register(identifier, controllerConstructor) {\n this.load({ identifier, controllerConstructor });\n }\n registerActionOption(name, filter) {\n this.actionDescriptorFilters[name] = filter;\n }\n load(head, ...rest) {\n const definitions = Array.isArray(head) ? head : [head, ...rest];\n definitions.forEach((definition) => {\n if (definition.controllerConstructor.shouldLoad) {\n this.router.loadDefinition(definition);\n }\n });\n }\n unload(head, ...rest) {\n const identifiers = Array.isArray(head) ? head : [head, ...rest];\n identifiers.forEach((identifier) => this.router.unloadIdentifier(identifier));\n }\n get controllers() {\n return this.router.contexts.map((context) => context.controller);\n }\n getControllerForElementAndIdentifier(element, identifier) {\n const context = this.router.getContextForElementAndIdentifier(element, identifier);\n return context ? context.controller : null;\n }\n handleError(error, message, detail) {\n var _a;\n this.logger.error(`%s\\n\\n%o\\n\\n%o`, message, error, detail);\n (_a = window.onerror) === null || _a === void 0 ? void 0 : _a.call(window, message, \"\", 0, 0, error);\n }\n logFormattedMessage(identifier, functionName, detail = {}) {\n detail = Object.assign({ application: this }, detail);\n this.logger.groupCollapsed(`${identifier} #${functionName}`);\n this.logger.log(\"details:\", Object.assign({}, detail));\n this.logger.groupEnd();\n }\n}\nfunction domReady() {\n return new Promise((resolve) => {\n if (document.readyState == \"loading\") {\n document.addEventListener(\"DOMContentLoaded\", () => resolve());\n }\n else {\n resolve();\n }\n });\n}\n\nfunction ClassPropertiesBlessing(constructor) {\n const classes = readInheritableStaticArrayValues(constructor, \"classes\");\n return classes.reduce((properties, classDefinition) => {\n return Object.assign(properties, propertiesForClassDefinition(classDefinition));\n }, {});\n}\nfunction propertiesForClassDefinition(key) {\n return {\n [`${key}Class`]: {\n get() {\n const { classes } = this;\n if (classes.has(key)) {\n return classes.get(key);\n }\n else {\n const attribute = classes.getAttributeName(key);\n throw new Error(`Missing attribute \"${attribute}\"`);\n }\n },\n },\n [`${key}Classes`]: {\n get() {\n return this.classes.getAll(key);\n },\n },\n [`has${capitalize(key)}Class`]: {\n get() {\n return this.classes.has(key);\n },\n },\n };\n}\n\nfunction OutletPropertiesBlessing(constructor) {\n const outlets = readInheritableStaticArrayValues(constructor, \"outlets\");\n return outlets.reduce((properties, outletDefinition) => {\n return Object.assign(properties, propertiesForOutletDefinition(outletDefinition));\n }, {});\n}\nfunction getOutletController(controller, element, identifier) {\n return controller.application.getControllerForElementAndIdentifier(element, identifier);\n}\nfunction getControllerAndEnsureConnectedScope(controller, element, outletName) {\n let outletController = getOutletController(controller, element, outletName);\n if (outletController)\n return outletController;\n controller.application.router.proposeToConnectScopeForElementAndIdentifier(element, outletName);\n outletController = getOutletController(controller, element, outletName);\n if (outletController)\n return outletController;\n}\nfunction propertiesForOutletDefinition(name) {\n const camelizedName = namespaceCamelize(name);\n return {\n [`${camelizedName}Outlet`]: {\n get() {\n const outletElement = this.outlets.find(name);\n const selector = this.outlets.getSelectorForOutletName(name);\n if (outletElement) {\n const outletController = getControllerAndEnsureConnectedScope(this, outletElement, name);\n if (outletController)\n return outletController;\n throw new Error(`The provided outlet element is missing an outlet controller \"${name}\" instance for host controller \"${this.identifier}\"`);\n }\n throw new Error(`Missing outlet element \"${name}\" for host controller \"${this.identifier}\". Stimulus couldn't find a matching outlet element using selector \"${selector}\".`);\n },\n },\n [`${camelizedName}Outlets`]: {\n get() {\n const outlets = this.outlets.findAll(name);\n if (outlets.length > 0) {\n return outlets\n .map((outletElement) => {\n const outletController = getControllerAndEnsureConnectedScope(this, outletElement, name);\n if (outletController)\n return outletController;\n console.warn(`The provided outlet element is missing an outlet controller \"${name}\" instance for host controller \"${this.identifier}\"`, outletElement);\n })\n .filter((controller) => controller);\n }\n return [];\n },\n },\n [`${camelizedName}OutletElement`]: {\n get() {\n const outletElement = this.outlets.find(name);\n const selector = this.outlets.getSelectorForOutletName(name);\n if (outletElement) {\n return outletElement;\n }\n else {\n throw new Error(`Missing outlet element \"${name}\" for host controller \"${this.identifier}\". Stimulus couldn't find a matching outlet element using selector \"${selector}\".`);\n }\n },\n },\n [`${camelizedName}OutletElements`]: {\n get() {\n return this.outlets.findAll(name);\n },\n },\n [`has${capitalize(camelizedName)}Outlet`]: {\n get() {\n return this.outlets.has(name);\n },\n },\n };\n}\n\nfunction TargetPropertiesBlessing(constructor) {\n const targets = readInheritableStaticArrayValues(constructor, \"targets\");\n return targets.reduce((properties, targetDefinition) => {\n return Object.assign(properties, propertiesForTargetDefinition(targetDefinition));\n }, {});\n}\nfunction propertiesForTargetDefinition(name) {\n return {\n [`${name}Target`]: {\n get() {\n const target = this.targets.find(name);\n if (target) {\n return target;\n }\n else {\n throw new Error(`Missing target element \"${name}\" for \"${this.identifier}\" controller`);\n }\n },\n },\n [`${name}Targets`]: {\n get() {\n return this.targets.findAll(name);\n },\n },\n [`has${capitalize(name)}Target`]: {\n get() {\n return this.targets.has(name);\n },\n },\n };\n}\n\nfunction ValuePropertiesBlessing(constructor) {\n const valueDefinitionPairs = readInheritableStaticObjectPairs(constructor, \"values\");\n const propertyDescriptorMap = {\n valueDescriptorMap: {\n get() {\n return valueDefinitionPairs.reduce((result, valueDefinitionPair) => {\n const valueDescriptor = parseValueDefinitionPair(valueDefinitionPair, this.identifier);\n const attributeName = this.data.getAttributeNameForKey(valueDescriptor.key);\n return Object.assign(result, { [attributeName]: valueDescriptor });\n }, {});\n },\n },\n };\n return valueDefinitionPairs.reduce((properties, valueDefinitionPair) => {\n return Object.assign(properties, propertiesForValueDefinitionPair(valueDefinitionPair));\n }, propertyDescriptorMap);\n}\nfunction propertiesForValueDefinitionPair(valueDefinitionPair, controller) {\n const definition = parseValueDefinitionPair(valueDefinitionPair, controller);\n const { key, name, reader: read, writer: write } = definition;\n return {\n [name]: {\n get() {\n const value = this.data.get(key);\n if (value !== null) {\n return read(value);\n }\n else {\n return definition.defaultValue;\n }\n },\n set(value) {\n if (value === undefined) {\n this.data.delete(key);\n }\n else {\n this.data.set(key, write(value));\n }\n },\n },\n [`has${capitalize(name)}`]: {\n get() {\n return this.data.has(key) || definition.hasCustomDefaultValue;\n },\n },\n };\n}\nfunction parseValueDefinitionPair([token, typeDefinition], controller) {\n return valueDescriptorForTokenAndTypeDefinition({\n controller,\n token,\n typeDefinition,\n });\n}\nfunction parseValueTypeConstant(constant) {\n switch (constant) {\n case Array:\n return \"array\";\n case Boolean:\n return \"boolean\";\n case Number:\n return \"number\";\n case Object:\n return \"object\";\n case String:\n return \"string\";\n }\n}\nfunction parseValueTypeDefault(defaultValue) {\n switch (typeof defaultValue) {\n case \"boolean\":\n return \"boolean\";\n case \"number\":\n return \"number\";\n case \"string\":\n return \"string\";\n }\n if (Array.isArray(defaultValue))\n return \"array\";\n if (Object.prototype.toString.call(defaultValue) === \"[object Object]\")\n return \"object\";\n}\nfunction parseValueTypeObject(payload) {\n const { controller, token, typeObject } = payload;\n const hasType = isSomething(typeObject.type);\n const hasDefault = isSomething(typeObject.default);\n const fullObject = hasType && hasDefault;\n const onlyType = hasType && !hasDefault;\n const onlyDefault = !hasType && hasDefault;\n const typeFromObject = parseValueTypeConstant(typeObject.type);\n const typeFromDefaultValue = parseValueTypeDefault(payload.typeObject.default);\n if (onlyType)\n return typeFromObject;\n if (onlyDefault)\n return typeFromDefaultValue;\n if (typeFromObject !== typeFromDefaultValue) {\n const propertyPath = controller ? `${controller}.${token}` : token;\n throw new Error(`The specified default value for the Stimulus Value \"${propertyPath}\" must match the defined type \"${typeFromObject}\". The provided default value of \"${typeObject.default}\" is of type \"${typeFromDefaultValue}\".`);\n }\n if (fullObject)\n return typeFromObject;\n}\nfunction parseValueTypeDefinition(payload) {\n const { controller, token, typeDefinition } = payload;\n const typeObject = { controller, token, typeObject: typeDefinition };\n const typeFromObject = parseValueTypeObject(typeObject);\n const typeFromDefaultValue = parseValueTypeDefault(typeDefinition);\n const typeFromConstant = parseValueTypeConstant(typeDefinition);\n const type = typeFromObject || typeFromDefaultValue || typeFromConstant;\n if (type)\n return type;\n const propertyPath = controller ? `${controller}.${typeDefinition}` : token;\n throw new Error(`Unknown value type \"${propertyPath}\" for \"${token}\" value`);\n}\nfunction defaultValueForDefinition(typeDefinition) {\n const constant = parseValueTypeConstant(typeDefinition);\n if (constant)\n return defaultValuesByType[constant];\n const hasDefault = hasProperty(typeDefinition, \"default\");\n const hasType = hasProperty(typeDefinition, \"type\");\n const typeObject = typeDefinition;\n if (hasDefault)\n return typeObject.default;\n if (hasType) {\n const { type } = typeObject;\n const constantFromType = parseValueTypeConstant(type);\n if (constantFromType)\n return defaultValuesByType[constantFromType];\n }\n return typeDefinition;\n}\nfunction valueDescriptorForTokenAndTypeDefinition(payload) {\n const { token, typeDefinition } = payload;\n const key = `${dasherize(token)}-value`;\n const type = parseValueTypeDefinition(payload);\n return {\n type,\n key,\n name: camelize(key),\n get defaultValue() {\n return defaultValueForDefinition(typeDefinition);\n },\n get hasCustomDefaultValue() {\n return parseValueTypeDefault(typeDefinition) !== undefined;\n },\n reader: readers[type],\n writer: writers[type] || writers.default,\n };\n}\nconst defaultValuesByType = {\n get array() {\n return [];\n },\n boolean: false,\n number: 0,\n get object() {\n return {};\n },\n string: \"\",\n};\nconst readers = {\n array(value) {\n const array = JSON.parse(value);\n if (!Array.isArray(array)) {\n throw new TypeError(`expected value of type \"array\" but instead got value \"${value}\" of type \"${parseValueTypeDefault(array)}\"`);\n }\n return array;\n },\n boolean(value) {\n return !(value == \"0\" || String(value).toLowerCase() == \"false\");\n },\n number(value) {\n return Number(value.replace(/_/g, \"\"));\n },\n object(value) {\n const object = JSON.parse(value);\n if (object === null || typeof object != \"object\" || Array.isArray(object)) {\n throw new TypeError(`expected value of type \"object\" but instead got value \"${value}\" of type \"${parseValueTypeDefault(object)}\"`);\n }\n return object;\n },\n string(value) {\n return value;\n },\n};\nconst writers = {\n default: writeString,\n array: writeJSON,\n object: writeJSON,\n};\nfunction writeJSON(value) {\n return JSON.stringify(value);\n}\nfunction writeString(value) {\n return `${value}`;\n}\n\nclass Controller {\n constructor(context) {\n this.context = context;\n }\n static get shouldLoad() {\n return true;\n }\n static afterLoad(_identifier, _application) {\n return;\n }\n get application() {\n return this.context.application;\n }\n get scope() {\n return this.context.scope;\n }\n get element() {\n return this.scope.element;\n }\n get identifier() {\n return this.scope.identifier;\n }\n get targets() {\n return this.scope.targets;\n }\n get outlets() {\n return this.scope.outlets;\n }\n get classes() {\n return this.scope.classes;\n }\n get data() {\n return this.scope.data;\n }\n initialize() {\n }\n connect() {\n }\n disconnect() {\n }\n dispatch(eventName, { target = this.element, detail = {}, prefix = this.identifier, bubbles = true, cancelable = true, } = {}) {\n const type = prefix ? `${prefix}:${eventName}` : eventName;\n const event = new CustomEvent(type, { detail, bubbles, cancelable });\n target.dispatchEvent(event);\n return event;\n }\n}\nController.blessings = [\n ClassPropertiesBlessing,\n TargetPropertiesBlessing,\n ValuePropertiesBlessing,\n OutletPropertiesBlessing,\n];\nController.targets = [];\nController.outlets = [];\nController.values = {};\n\nexport { Application, AttributeObserver, Context, Controller, ElementObserver, IndexedMultimap, Multimap, SelectorObserver, StringMapObserver, TokenListObserver, ValueListObserver, add, defaultSchema, del, fetch, prune };\n", "export enum ADDRESS_PARTS {\n address_1 = 'address_1',\n address_2 = 'address_2',\n city = 'city',\n country_code = 'country_code',\n postal_code = 'postal_code',\n province = 'province',\n}\n\ntype AddressEnumKeys = keyof typeof ADDRESS_PARTS;\n\nconst DEFAULT_ADDRESS_FIELDS_ORDER = [\n ADDRESS_PARTS.address_1,\n ADDRESS_PARTS.address_2,\n ADDRESS_PARTS.city,\n ADDRESS_PARTS.province,\n ADDRESS_PARTS.postal_code,\n];\n\nexport type Address = {\n [key in AddressEnumKeys]: string;\n};\n\nconst DEFAULT_DELIMITER = ', ';\n\nexport class AutosuggestAddress {\n private address: Address;\n private delimiter: string;\n\n constructor(address: Address, delimiter?: string) {\n this.address = address;\n this.delimiter = delimiter ?? DEFAULT_DELIMITER;\n }\n\n parse(fields_order?: ADDRESS_PARTS[]): string {\n const order = fields_order ?? DEFAULT_ADDRESS_FIELDS_ORDER;\n return order.map((field) => this.address[field]).join(this.delimiter);\n }\n}\n", "export function debounce(\n function_: (arguments_: A) => R,\n ms: number,\n): (arguments_: A) => Promise {\n let timer: ReturnType;\n\n return (arguments_: A): Promise =>\n new Promise((resolve) => {\n if (timer) {\n clearTimeout(timer);\n }\n\n timer = setTimeout(() => {\n resolve(function_(arguments_));\n }, ms);\n });\n}\n", "import { Controller } from '@hotwired/stimulus';\nimport {\n ADDRESS_PARTS,\n Address,\n AutosuggestAddress,\n} from '../../utilities/address';\nimport { debounce } from '../../utilities/debounce';\n\nexport default class extends Controller {\n private readonly SUBMIT_DEBOUNCE_TIME = 300;\n private readonly MINIMUM_CHAR_REQUEST = 5;\n\n static readonly targets = [\n 'form',\n 'autosuggestContainer',\n 'autosuggestInput',\n 'autosuggestMenu',\n 'provinceField',\n ];\n\n static readonly classes = [\n 'hintOption',\n 'manualOption',\n 'addressStreetNumberOption',\n 'addressAddressNameOption',\n 'addressSecondaryOption',\n 'hidden',\n 'menuButtonElement',\n ];\n\n static readonly values = {\n useAutosuggest: Boolean,\n hintLabel: String,\n manualInputLabel: String,\n searchUrl: String,\n address2InputField: String,\n cityInputField: String,\n provinceSelectField: String,\n zipInputField: String,\n countryInputField: String,\n animation: String,\n address1Autocomplete: String,\n isAddressComplete: Boolean,\n toggleElements: String,\n };\n\n declare autosuggestContainerTarget: HTMLDivElement;\n declare formTargets: HTMLDivElement[];\n declare autosuggestInputTarget: HTMLInputElement;\n declare autosuggestMenuTarget: HTMLMenuElement;\n declare provinceFieldTarget: HTMLInputElement | HTMLSelectElement;\n\n declare hintOptionClasses: string[];\n declare manualOptionClasses: string[];\n declare addressStreetNumberOptionClasses: string[];\n declare addressAddressNameOptionClasses: string[];\n declare addressSecondaryOptionClasses: string[];\n declare hiddenClasses: string[];\n declare menuButtonElementClasses: string[];\n\n declare useAutosuggestValue: boolean;\n declare isAddressCompleteValue: boolean;\n declare hintLabelValue: string;\n declare manualInputLabelValue: string;\n declare searchUrlValue: string;\n declare address2InputFieldValue: string;\n declare cityInputFieldValue: string;\n declare provinceSelectFieldValue: string;\n declare hasProvinceSelectFieldValue: boolean;\n declare zipInputFieldValue: string;\n declare countryInputFieldValue: string;\n declare address1AutocompleteValue: string;\n declare toggleElementsValue: string;\n\n declare animationValue: string;\n\n declare hasHintLabelValue: boolean;\n declare hasManualInputLabelValue: boolean;\n\n private suggestions: Address[] = [];\n private previousInputValue: string = '';\n private currentOption: number = 0;\n private initialIndex: number = 0;\n\n initialize(): void {\n if (this.useAutosuggestValue) {\n if (!this.isAddressCompleteValue) {\n this.hideForm();\n }\n this.cleanMenuOptions();\n this.initialIndex = this.hasHintLabelValue ? 1 : 0;\n this.currentOption = this.initialIndex;\n }\n }\n\n connect(): void {\n if (this.useAutosuggestValue) {\n this.autosuggestInputTarget.addEventListener(\n 'focus',\n this.onAutosuggestInputFocus,\n );\n this.autosuggestContainerTarget.addEventListener(\n 'focusout',\n this.onClickOutside,\n );\n this.autosuggestInputTarget.addEventListener(\n 'input',\n debounce(this.onInput, this.SUBMIT_DEBOUNCE_TIME),\n );\n this.autosuggestInputTarget.addEventListener(\n 'keydown',\n this.onInputKeyPressed,\n );\n this.autosuggestMenuTarget.addEventListener(\n 'keydown',\n this.onMenuKeyPressed,\n );\n\n this.element.addEventListener('invalid', this.onManualInput, true);\n }\n }\n\n disconnect(): void {\n if (this.useAutosuggestValue) {\n this.autosuggestInputTarget.removeEventListener(\n 'focus',\n this.onAutosuggestInputFocus,\n );\n this.autosuggestContainerTarget.removeEventListener(\n 'click',\n this.onClickOutside,\n );\n this.autosuggestInputTarget.removeEventListener(\n 'input',\n debounce(this.onInput, this.SUBMIT_DEBOUNCE_TIME),\n );\n this.autosuggestInputTarget.removeEventListener(\n 'keydown',\n this.onMenuKeyPressed,\n );\n this.autosuggestMenuTarget.removeEventListener(\n 'keydown',\n this.onMenuKeyPressed,\n );\n\n this.element.removeEventListener('invalid', this.onManualInput, true);\n }\n }\n\n formatZip(event: Event): void {\n const element = event.currentTarget as HTMLInputElement;\n const value = element.value;\n let valueStripped = value.replaceAll(/\\D/g, '');\n\n if (valueStripped.length > 5) {\n valueStripped = [\n valueStripped.slice(0, 5),\n '-',\n valueStripped.slice(5),\n ].join('');\n }\n\n element.value = valueStripped;\n }\n\n fillFormElements(address: Address) {\n this.setAddressValue(address.address_1);\n this.saveActualInputValue();\n this.autosuggestInputTarget.dispatchEvent(\n new Event('change', { bubbles: true }),\n );\n this.setElementValueByName(this.address2InputFieldValue, address.address_2);\n this.setElementValueByName(this.cityInputFieldValue, address.city);\n if (this.hasProvinceSelectFieldValue) {\n this.setElementValueByName(\n this.provinceSelectFieldValue,\n address.province,\n );\n }\n\n this.setElementValueByName(this.zipInputFieldValue, address.postal_code);\n this.setElementValueByName(\n this.countryInputFieldValue,\n address.country_code,\n );\n }\n\n private onInputKeyPressed = (event: KeyboardEvent) => {\n const elementsQty = this.autosuggestMenuTarget.childNodes.length;\n switch (event.key) {\n case 'Escape': {\n this.hideMenu();\n break;\n }\n case 'ArrowUp': {\n event.preventDefault();\n this.saveActualInputValue();\n this.currentOption = elementsQty - 1;\n this.doElementFocus(this.currentOption);\n\n break;\n }\n case 'ArrowDown': {\n event.preventDefault();\n this.saveActualInputValue();\n this.currentOption = this.initialIndex;\n this.doElementFocus(this.currentOption);\n\n break;\n }\n default: {\n break;\n }\n }\n };\n\n private onMenuKeyPressed = (event: KeyboardEvent) => {\n const elementsQty = this.autosuggestMenuTarget.childNodes.length;\n switch (event.key) {\n case 'Escape': {\n this.hideMenu();\n this.restorePreviousInputValue();\n this.focusOnAutosuggestInput();\n\n break;\n }\n case 'ArrowUp': {\n this.removeElementFocus(this.currentOption);\n this.currentOption =\n this.currentOption == this.initialIndex\n ? elementsQty - 1\n : this.currentOption - 1;\n this.doElementFocus(this.currentOption);\n\n break;\n }\n case 'ArrowDown': {\n this.removeElementFocus(this.currentOption);\n this.currentOption =\n this.currentOption == elementsQty - 1\n ? this.initialIndex\n : this.currentOption + 1;\n this.doElementFocus(this.currentOption);\n\n break;\n }\n default: {\n break;\n }\n }\n };\n\n private onManualInput = () => {\n this.hideMenu();\n this.showForm();\n this.focusOnForm();\n };\n\n private onAutosuggestInputFocus = () => {\n this.showMenu();\n };\n\n private onClickOutside = (event: Event) => {\n if (\n !this.autosuggestContainerTarget.contains(\n (event as MouseEvent).relatedTarget as Node,\n )\n ) {\n this.hideMenu();\n if (this.currentOption !== this.initialIndex) {\n this.restorePreviousInputValue();\n }\n }\n };\n\n private onInput = (event: Event) => {\n event.preventDefault();\n const userInput = (event.target as HTMLInputElement).value.trim();\n this.toggleMainAddressAutocompleteStatus(userInput);\n this.showMenu();\n this.cleanMenuOptions();\n if (userInput.length >= this.MINIMUM_CHAR_REQUEST) {\n this.getOptions(userInput);\n }\n };\n\n private toggleMainAddressAutocompleteStatus(value: string) {\n // Autocomplete \"_off\" is a workaround to suppress browser autocomplete\n const autocompleteValue =\n value.length > 0 ? '_off' : this.address1AutocompleteValue;\n this.autosuggestInputTarget.setAttribute('autocomplete', autocompleteValue);\n }\n\n private onSelectOption = (event: Event) => {\n const index = Number.parseInt(\n (event.currentTarget as HTMLButtonElement).value,\n 10,\n );\n this.processOption(index);\n };\n\n private showMenu() {\n this.autosuggestMenuTarget.classList.remove(...this.hiddenClasses);\n }\n\n private hideMenu() {\n this.autosuggestMenuTarget.classList.add(...this.hiddenClasses);\n }\n\n private showForm() {\n for (const elementId of this.toggleElementsValue.split(',')) {\n document\n .querySelector(`[id=\"${elementId}\"]`)\n ?.classList.remove(...this.hiddenClasses);\n }\n for (const form of this.formTargets) {\n form.classList.remove(...this.hiddenClasses);\n }\n this.setElementDisabledByName(\n this.element,\n this.address2InputFieldValue,\n false,\n );\n this.setElementDisabledByName(\n this.element,\n this.cityInputFieldValue,\n false,\n );\n this.setElementDisabledByName(\n this.element,\n this.provinceSelectFieldValue,\n false,\n );\n this.setElementDisabledByName(this.element, this.zipInputFieldValue, false);\n }\n\n private hideForm() {\n for (const elementId of this.toggleElementsValue.split(',')) {\n document\n .querySelector(`[id=\"${elementId}\"]`)\n ?.classList.add(...this.hiddenClasses);\n }\n for (const form of this.formTargets) {\n form.classList.add(...this.hiddenClasses);\n }\n this.setElementDisabledByName(\n this.element,\n this.address2InputFieldValue,\n true,\n );\n this.setElementDisabledByName(this.element, this.cityInputFieldValue, true);\n this.setElementDisabledByName(\n this.element,\n this.provinceSelectFieldValue,\n true,\n );\n this.setElementDisabledByName(this.element, this.zipInputFieldValue, true);\n }\n\n private restorePreviousInputValue() {\n this.autosuggestInputTarget.value = this.previousInputValue;\n }\n\n private saveActualInputValue() {\n this.previousInputValue = this.autosuggestInputTarget.value;\n }\n\n private focusOnAutosuggestInput() {\n this.autosuggestInputTarget.focus();\n }\n\n private focusOnForm() {\n (\n this.element.querySelector(\n `[name=\"${this.address2InputFieldValue}\"]`,\n ) as HTMLInputElement\n ).focus();\n }\n\n private removeElementFocus(optionIndex: number) {\n const element = this.autosuggestMenuTarget.childNodes[optionIndex];\n const button = element.childNodes[0] as HTMLButtonElement;\n button.setAttribute('tabindex', '-1');\n }\n\n private doElementFocus(optionIndex: number) {\n const element = this.autosuggestMenuTarget.childNodes[optionIndex];\n const button = element.childNodes[0] as HTMLButtonElement;\n const index = Number.parseInt(button.value, 10);\n if (index == 0) {\n this.setAddressValue(this.previousInputValue);\n } else {\n const address = this.suggestions[index - 1];\n if (address) {\n this.setAddressValue(this.buildAddress(address));\n }\n }\n button.setAttribute('tabindex', '0');\n button.focus();\n }\n\n private processOption(index: number) {\n const address = this.suggestions[index - 1];\n this.saveActualInputValue();\n this.hideMenu();\n this.cleanMenuOptions();\n if (address) {\n this.suggestions = [address];\n this.processMenuOptions([address]);\n this.fillFormElements(address);\n }\n this.showForm();\n this.focusOnForm();\n }\n\n private setAddressValue(address: string) {\n this.autosuggestInputTarget.value = address;\n }\n\n private buildAddress(address: Address) {\n return new AutosuggestAddress(address).parse([\n ADDRESS_PARTS.address_1,\n ADDRESS_PARTS.address_2,\n ADDRESS_PARTS.city,\n ADDRESS_PARTS.province,\n ADDRESS_PARTS.postal_code,\n ]);\n }\n\n private async getOptions(searchValue: string) {\n const url = `${this.searchUrlValue}?address=${searchValue}`;\n const response = await fetch(url);\n if (response && response.ok) {\n const data = await response.json();\n this.suggestions = data.data as Address[];\n this.processMenuOptions(this.suggestions);\n }\n }\n\n private cleanMenuOptions() {\n const menuChildNodes = this.autosuggestMenuTarget.childNodes;\n menuChildNodes[1]?.removeEventListener('click', this.onManualInput);\n for (\n let index = this.firstAutosuggestEntry();\n index < menuChildNodes.length;\n index++\n ) {\n menuChildNodes[index].removeEventListener('click', this.onSelectOption);\n }\n this.autosuggestMenuTarget.innerHTML = '';\n this.addDefaultMenuOptions();\n this.suggestions = [];\n }\n\n private firstAutosuggestEntry() {\n let count: number = this.hasHintLabelValue ? 1 : 0;\n count += this.hasManualInputLabelValue ? 1 : 0;\n\n return count;\n }\n\n private addDefaultMenuOptions() {\n if (this.hasHintLabelValue) {\n this.autosuggestMenuTarget.append(this.createHintMenuOption());\n }\n if (this.hasManualInputLabelValue) {\n this.autosuggestMenuTarget.append(this.createManualInputMenuOption());\n }\n }\n\n private processMenuOptions(suggestions: Address[]) {\n if (suggestions) {\n suggestions.map((address, index) => {\n this.autosuggestMenuTarget.append(\n address && this.createAddressElement(address, index + 1),\n );\n });\n }\n }\n\n private createAddressElement(address: Address, index: number) {\n const { address_1, address_2, city, postal_code, province } = address;\n const mainElement = document.createElement('li');\n\n const buttonElement = document.createElement('button');\n buttonElement.type = 'button';\n buttonElement.addEventListener('click', this.onSelectOption);\n buttonElement.classList.add(...this.menuButtonElementClasses);\n buttonElement.value = index.toString();\n buttonElement.setAttribute('tabindex', '-1');\n buttonElement.dataset.ddPrivacy = 'mask';\n\n const firstRow = document.createElement('div');\n const streetNumberElement = document.createElement('span');\n const addressNameElement = document.createElement('span');\n\n const addressParts = address_1.split(' ');\n const streetNumber = addressParts[0];\n addressParts.shift();\n let addressName = addressParts.join(' ');\n if (address_2) {\n addressName = [addressName, address_2].join(' - ');\n }\n\n streetNumberElement.innerHTML = streetNumber;\n streetNumberElement.classList.add(...this.addressStreetNumberOptionClasses);\n addressNameElement.innerHTML = addressName;\n addressNameElement.classList.add(...this.addressAddressNameOptionClasses);\n firstRow.append(streetNumberElement);\n firstRow.append(addressNameElement);\n\n const secondRow = document.createElement('span');\n secondRow.innerHTML = `${city} ${province} ${postal_code}`;\n secondRow.classList.add(...this.addressSecondaryOptionClasses);\n\n buttonElement.append(firstRow);\n buttonElement.append(secondRow);\n mainElement.append(buttonElement);\n\n return mainElement;\n }\n\n private createManualInputMenuOption() {\n const manualElement = document.createElement('li');\n const buttonElement = document.createElement('button');\n buttonElement.type = 'button';\n buttonElement.classList.add(...this.manualOptionClasses);\n buttonElement.innerHTML = this.manualInputLabelValue;\n buttonElement.addEventListener('click', this.onManualInput);\n manualElement.append(buttonElement);\n buttonElement.value = '0';\n buttonElement.setAttribute('tabindex', '-1');\n\n return manualElement;\n }\n\n private createHintMenuOption() {\n const hintElement = document.createElement('li');\n const buttonElement = document.createElement('button');\n buttonElement.classList.add(...this.hintOptionClasses);\n buttonElement.innerHTML = this.hintLabelValue;\n buttonElement.setAttribute('tabindex', '-1');\n hintElement.append(buttonElement);\n\n return hintElement;\n }\n\n private setElementValueByName(name: string, value: string) {\n if (name && value) {\n for (const element_ of document.getElementsByName(name)) {\n const element = element_ as HTMLInputElement | HTMLSelectElement;\n element.value = value;\n element.dispatchEvent(new Event('input', { bubbles: true }));\n }\n }\n }\n\n private setElementDisabledByName(\n element: Element,\n name: string,\n value: boolean,\n ) {\n if (element && name && value) {\n for (const element_ of element.querySelectorAll(name)) {\n const element = element_ as HTMLInputElement | HTMLSelectElement;\n element.disabled = value;\n element.dispatchEvent(new Event('input', { bubbles: true }));\n }\n }\n }\n}\n", "import { Controller } from '@hotwired/stimulus';\n\nexport default class extends Controller {\n static readonly targets = ['selector', 'container'];\n static readonly classes = ['hidden'];\n static readonly values = {\n selectId: String,\n };\n\n declare selectIdValue: string;\n declare containerTargets: HTMLElement[];\n declare selectorTarget: HTMLElement;\n declare hiddenClasses: string[];\n\n onClick = (event: Event) => {\n const selectedElement = event.currentTarget as HTMLElement;\n this.toggleSelectForm(selectedElement.id);\n };\n\n private toggleSelectForm(selected: string) {\n for (const element of this.containerTargets) {\n if (element.id === selected) {\n element.classList.remove(this.hiddenClasses.join(' '));\n } else {\n element.classList.add(this.hiddenClasses.join(' '));\n }\n }\n }\n}\n", "import { Controller } from '@hotwired/stimulus';\nimport { AlertController } from '@elc-online/edl-components/js/alert';\n\nexport default class extends Controller {\n static readonly targets = ['close'];\n\n declare closeTarget: HTMLButtonElement;\n\n initialize(): void {\n new AlertController(\n {\n container: this.element,\n close: this.closeTarget,\n },\n {\n mode: 'auto',\n },\n );\n }\n}\n", "import { Controller } from '@hotwired/stimulus';\nimport { MinimalHeaderController } from '@elc-online/edl-components/js/minimal_header';\n\nexport default class extends Controller {\n static readonly targets = ['button'];\n declare buttonTarget: HTMLAnchorElement;\n private controller: MinimalHeaderController;\n\n initialize(): void {\n this.controller = new MinimalHeaderController(\n {\n back: this.buttonTarget,\n },\n {\n mode: 'auto',\n },\n );\n }\n\n connect() {\n this.controller.connect();\n }\n\n disconnect() {\n this.controller.disconnect();\n }\n}\n", "import { Controller } from '@hotwired/stimulus';\nimport { CarouselController } from '@elc-online/edl-components/js/carousel';\n\nexport default class extends Controller {\n static readonly targets = ['previous', 'next', 'items', 'navigation'];\n\n declare previousTarget: HTMLButtonElement;\n declare nextTarget: HTMLButtonElement;\n declare itemsTarget: HTMLElement;\n declare navigationTarget: HTMLElement;\n\n initialize(): void {\n new CarouselController(\n {\n previous: this.previousTarget,\n next: this.nextTarget,\n items: this.itemsTarget,\n navigation: this.navigationTarget,\n },\n { mode: 'auto' },\n );\n }\n}\n", "import { Controller } from '@hotwired/stimulus';\n\nexport default class extends Controller {\n static readonly targets = ['input', 'display'];\n\n declare inputTarget: HTMLTextAreaElement;\n declare displayTarget: HTMLElement;\n\n private get max() {\n return Number.parseInt(\n this.inputTarget.getAttribute('maxlength') ?? '0',\n 10,\n );\n }\n\n initialize() {\n this.count();\n }\n\n count() {\n if (this.max) {\n this.displayTarget.textContent = `${this.inputTarget.value.length}/${this.max}`;\n }\n }\n}\n", "export function afterNextRender(action: () => void) {\n // Delay action a few frames until after DOM changes are rendered\n requestAnimationFrame(() => requestAnimationFrame(() => action()));\n}\n", "import { afterNextRender } from './timing';\n\nexport type DateParts = Record;\nexport type Pattern = string[];\nexport type Blocks = number[];\nexport interface AutoFormatOptions {\n template: string;\n pattern?: Pattern;\n value?: string;\n delimiter?: string;\n}\n\ninterface ICompleteDate {\n [DAY]: number;\n [MONTH]: number;\n [YEAR]: number;\n}\n\nexport interface FormatOptions {\n blocks: Blocks;\n cursorPosition: number;\n pattern: Pattern;\n prevValue: string;\n value: string;\n delimiter: string;\n prevDate: DateParts;\n}\n\nexport interface BaseDateOptions {\n pattern: Pattern;\n parts: DateParts;\n}\n\nconst DAY = 'd';\nconst MONTH = 'm';\nconst YEAR = 'y';\nexport const DEFAULT_TEMPLATE: string = 'mm/dd';\n\nexport function parseISODate(date: string): DateParts {\n if (Number.isNaN(Date.parse(date)) || date.length <= 5) {\n // append year to make date valid and a leap year\n date = `${date}-2000`;\n }\n\n // using GMT to make sure its UTC date remains consistent\n // this should be OK as long as we don't care about timezones\n const dateObject = new Date(date.includes('T') ? date : `${date} GMT`);\n\n return {\n y: dateObject.getUTCFullYear().toString(),\n m: `${dateObject.getUTCMonth() + 1}`.padStart(2, '0'),\n d: `${dateObject.getUTCDate()}`.padStart(2, '0'),\n };\n}\n\nexport function toDefaultDateString(month: string, day: string) {\n return month || day ? `${month}/${day}` : '';\n}\n\nexport function toStrippedDateString({ pattern, parts }: BaseDateOptions) {\n return pattern.map((part) => parts[part]).join(',');\n}\n\nexport function defaultAutoFormatOptions(\n options: AutoFormatOptions,\n defaultTemplate: string,\n) {\n const template =\n options.template && options.template.length > 0\n ? options.template.toLowerCase()\n : defaultTemplate;\n const value = options.value ?? '';\n const delimiter = [...template].find((part) =>\n /^[^A-Za-z]+$/.test(part),\n ) as string;\n const pattern = template.split(delimiter).map((part) => part[0]);\n\n return {\n template,\n delimiter,\n pattern,\n value,\n };\n}\n\nexport function setCursorPosition(element: HTMLInputElement, position: number) {\n afterNextRender(() => element.setSelectionRange(position, position));\n}\n\nfunction isFullDate(\n { value, delimiter }: FormatOptions,\n template: string,\n delimiters: string,\n) {\n return (\n getCharCount(delimiter, value) == 2 ||\n (getDelimiterCountByArray(value, delimiters, 2) &&\n getCharCount(delimiter, template) == 1)\n );\n}\n\nfunction replaceDelimiters(\n value: string,\n delimiters: string,\n delimiter: string,\n) {\n const regExp = new RegExp(`[${delimiters}]`, 'g');\n\n return value.replaceAll(regExp, delimiter);\n}\n\nfunction getDelimiters(string: string) {\n const regExp = new RegExp(`[a-zA-Z0-9]`, 'g');\n\n return string.replaceAll(regExp, '');\n}\n\nfunction getDelimiterCountByArray(\n value: string,\n delimiters: string,\n qty: number,\n) {\n return [...delimiters].some(\n (delimiter) => getCharCount(delimiter, value) == qty,\n );\n}\n\nfunction escapeSpecialChar(string: string) {\n return string.replaceAll(/[$()*+.?[\\\\\\]^{|}]/g, '\\\\$&');\n}\n\nfunction getCharCount(char: string, string: string) {\n const escapedChar = escapeSpecialChar(char);\n return (string.match(new RegExp(escapedChar, 'g')) || []).length;\n}\n\nfunction stringToInt(value: string) {\n return Number.parseInt(value, 10);\n}\n\nfunction getFormattedDateParts(options: FormatOptions) {\n const { blocks, cursorPosition, pattern, value, delimiter } = options;\n let currentBlock: string = pattern[0];\n const chars = preFormatValue(value, currentBlock);\n let cursor = cursorPosition;\n const dateParts = pattern.reduce((accumulator, part) => {\n accumulator[part] = '';\n return accumulator;\n }, {} as DateParts);\n\n for (let index = 0; index < chars.length && currentBlock; index += 1) {\n if (chars[index] !== delimiter) {\n dateParts[currentBlock] += chars[index];\n }\n\n const formatted = formatDateBlock(\n currentBlock,\n dateParts[currentBlock],\n chars[index] === delimiter && cursorPosition > index,\n );\n\n cursor += getCursorOffset(\n cursorPosition,\n index,\n formatted.length - dateParts[currentBlock].length,\n );\n\n dateParts[currentBlock] = formatted;\n\n if (\n isDatePartComplete(\n dateParts[currentBlock],\n currentBlock,\n blocks,\n pattern,\n ) ||\n isBlockEndedByDelimiter(\n chars[index],\n dateParts[currentBlock],\n getNextBlock(currentBlock, pattern),\n delimiter,\n )\n ) {\n currentBlock = getNextBlock(currentBlock, pattern);\n }\n }\n\n return {\n formattedDateParts: dateParts,\n cursor,\n };\n}\n\nfunction getCursorOffset(cursor: number, index: number, value: number): number {\n if (cursor > index) {\n return value;\n }\n\n return 0;\n}\n\nfunction isDatePartComplete(\n datePart: string,\n block: string,\n blocks: Blocks,\n pattern: Pattern,\n): boolean {\n return datePart.length === blocks[pattern.indexOf(block)];\n}\n\nfunction isBlockEndedByDelimiter(\n currentChar: string,\n datePart: string,\n nextBlock: string,\n delimiter: string,\n) {\n return currentChar === delimiter && datePart.length > 0 && nextBlock;\n}\n\nfunction getNextBlock(current: string, pattern: Pattern): string {\n return pattern[pattern.indexOf(current) + 1];\n}\n\nfunction formatDateBlock(\n blockId: string,\n value: string,\n complete?: boolean,\n): string {\n const cleanValue = getSanitizedNumericString(value);\n\n if (!cleanValue) {\n return cleanValue;\n }\n\n switch (blockId) {\n case MONTH:\n return formatMonth(cleanValue, complete);\n\n case DAY:\n return formatDay(cleanValue, complete);\n\n default:\n return cleanValue;\n }\n}\n\nfunction formatDay(value: string, complete?: boolean): string {\n const numericValue = Number.parseInt(value, 10);\n\n if (value.length === 1) {\n if (complete || numericValue * 10 > 31) {\n return `0${Math.max(numericValue, 1)}`;\n }\n } else if (numericValue > 31) {\n return '31';\n } else if (numericValue < 1) {\n return '01';\n }\n\n return value;\n}\n\nfunction preFormatValue(value: string, type: string) {\n const chars = [...value];\n\n if (chars.length >= 2 && chars.length <= 3) {\n const part = value.slice(0, 2);\n const extra = chars.length <= 3 ? value[2] : '';\n const newValue: string =\n (type == MONTH && !isValidMonth(part)) ||\n (type == DAY && !isValidDay(part))\n ? `0${part}${extra}`\n : value;\n\n return [...newValue];\n }\n\n return chars;\n}\n\nfunction isValidMonth(month: string) {\n const m = Number.parseInt(month);\n\n return m >= 1 && m <= 12;\n}\n\nfunction isValidDay(day: string) {\n const d = Number.parseInt(day);\n\n return d >= 1 && d <= 31;\n}\n\nfunction formatMonth(value: string, complete?: boolean): string {\n const numericValue = Number.parseInt(value, 10);\n\n if (value.length === 1) {\n if (complete || numericValue * 10 > 12) {\n return `0${Math.max(numericValue, 1)}`;\n }\n } else if (numericValue > 12) {\n return '12';\n } else if (numericValue < 1) {\n return '01';\n }\n\n return value;\n}\n\nfunction getSanitizedNumericString(value: string): string {\n return value.replaceAll(/\\D/g, '');\n}\n\nfunction combineDateParts(\n dateParts: DateParts,\n pattern: Pattern,\n delimiter: string,\n): string {\n const blocks = getBlocks(pattern);\n\n return pattern\n .map((block) => {\n const nextBlock = getNextBlock(block, pattern);\n const blockIndex = pattern.indexOf(block);\n const insertDelimiter =\n nextBlock &&\n (dateParts[nextBlock] ||\n dateParts[block]?.length === blocks[blockIndex]);\n\n return insertDelimiter ? dateParts[block] + delimiter : dateParts[block];\n })\n .join('');\n}\n\nexport function getBlocks(pattern: Pattern): Blocks {\n const blocks: Blocks = [];\n\n for (const value of pattern) {\n if (value === YEAR) {\n blocks.push(4);\n } else {\n blocks.push(2);\n }\n }\n\n return blocks;\n}\n\nfunction getTemplate(\n pattern: Pattern,\n blocks: Blocks,\n delimiter: string,\n): string {\n return pattern\n .map((letter, index) => {\n const count = blocks[index];\n return letter.repeat(count).toUpperCase();\n })\n .join(delimiter);\n}\n\nfunction getCorrectedDateParts(dateParts: DateParts): DateParts {\n const correctedDay = correctDayForMonth({\n [DAY]: stringToInt(dateParts[DAY]),\n [MONTH]: stringToInt(dateParts[MONTH]),\n [YEAR]: stringToInt(dateParts[YEAR]),\n });\n\n return {\n [DAY]: formatDay(correctedDay.toString(), true),\n [MONTH]: dateParts[MONTH],\n [YEAR]: dateParts[YEAR],\n };\n}\n\nfunction correctDayForMonth({ d, m, y }: ICompleteDate) {\n const day = Math.min(d, 31);\n const month = Math.min(m, 12);\n const year = Number.parseInt(String(y || 0), 10);\n\n if ((month < 7 && month % 2 === 0) || (month > 8 && month % 2 === 1)) {\n const leapDay = isLeapYear(year) ? 29 : 28;\n return Math.min(day, month === 2 ? leapDay : 30);\n }\n\n return day;\n}\n\nfunction isLeapYear(year: number): boolean {\n return (year % 4 === 0 && year % 100 !== 0) || year % 400 === 0;\n}\n\nexport function formatDateInput(options: FormatOptions) {\n const {\n blocks,\n cursorPosition,\n pattern,\n prevValue,\n prevDate,\n value,\n delimiter,\n } = options;\n const template = getTemplate(pattern, blocks, delimiter);\n const delimiters = getDelimiters(value);\n\n if (isFullDate(options, template, delimiters)) {\n options.value = replaceDelimiters(value, delimiters, delimiter);\n } else if (prevValue?.length > value.length) {\n const { formattedDateParts } = getFormattedDateParts(options);\n const date =\n Object.values(formattedDateParts).join(delimiter).length ===\n template.length\n ? getCorrectedDateParts(formattedDateParts)\n : formattedDateParts;\n return {\n formattedDate: replaceDelimiters(value, delimiters, delimiter),\n cursorPosition,\n date,\n };\n } else if (value.length > template.length) {\n return {\n formattedDate: prevValue,\n cursorPosition: cursorPosition - (value.length - prevValue?.length),\n date: prevDate,\n };\n }\n\n const { formattedDateParts, cursor } = getFormattedDateParts(options);\n if (\n Object.values(formattedDateParts).join(delimiter).length === template.length\n ) {\n const correctedDateParts = getCorrectedDateParts(formattedDateParts);\n\n return {\n formattedDate: combineDateParts(correctedDateParts, pattern, delimiter),\n cursorPosition: cursor,\n date: correctedDateParts,\n };\n }\n\n return {\n formattedDate: combineDateParts(formattedDateParts, pattern, delimiter),\n cursorPosition: cursor,\n date: formattedDateParts,\n };\n}\n", "import { Controller } from '@hotwired/stimulus';\nimport {\n AutoFormatOptions,\n Blocks,\n DEFAULT_TEMPLATE,\n DateParts,\n Pattern,\n defaultAutoFormatOptions,\n formatDateInput,\n getBlocks,\n parseISODate,\n toStrippedDateString,\n} from '../../utilities/date';\n\nexport default class extends Controller {\n static readonly values = {\n template: String,\n date: String,\n };\n\n declare templateValue: string;\n declare dateValue: string;\n\n private formattedDate: string = '';\n private date: DateParts = {};\n private delimiter: string = '';\n private blocks: Blocks = [];\n private pattern: Pattern = [];\n\n initialize(): void {\n const options: AutoFormatOptions = {\n template: this.templateValue,\n value: this.element.innerHTML,\n };\n const { pattern, value, delimiter } = defaultAutoFormatOptions(\n options,\n DEFAULT_TEMPLATE,\n );\n this.pattern = pattern;\n this.formattedDate = value;\n this.delimiter = delimiter;\n this.blocks = getBlocks(pattern);\n if (this.dateValue) {\n const parts = parseISODate(this.dateValue);\n const strippedValue = toStrippedDateString({ parts, pattern });\n const { formattedDate, date } = formatDateInput({\n blocks: this.blocks,\n cursorPosition: 0,\n pattern: this.pattern,\n value: strippedValue,\n prevValue: strippedValue,\n delimiter: this.delimiter,\n prevDate: this.date,\n });\n this.date = date;\n this.formattedDate = formattedDate;\n }\n this.element.innerHTML = this.formattedDate;\n }\n}\n", "import { Controller } from '@hotwired/stimulus';\nimport {\n AutoFormatOptions,\n Blocks,\n DEFAULT_TEMPLATE,\n DateParts,\n Pattern,\n defaultAutoFormatOptions,\n formatDateInput,\n getBlocks,\n parseISODate,\n setCursorPosition,\n toDefaultDateString,\n toStrippedDateString,\n} from '../../utilities/date';\n\nexport default class extends Controller {\n // TESTED POSSIBILITIES: 'mm/dd/yyyy' | 'dd/mm/yyyy' | 'mm/dd' | 'dd/mm'\n static readonly targets = ['input', 'formattedInput'];\n static readonly values = {\n template: String,\n };\n\n declare inputTarget: HTMLInputElement;\n declare formattedInputTarget: HTMLInputElement;\n\n declare templateValue: string;\n\n private formattedDate: string = '';\n private date: DateParts = {};\n private delimiter: string = '';\n private blocks: Blocks = [];\n private pattern: Pattern = [];\n private intersectionObserver: IntersectionObserver | undefined = undefined;\n\n initialize(): void {\n const options: AutoFormatOptions = {\n template: this.templateValue,\n value: this.inputTarget.value,\n };\n const { pattern, value, delimiter } = defaultAutoFormatOptions(\n options,\n DEFAULT_TEMPLATE,\n );\n this.pattern = pattern;\n this.formattedDate = value;\n this.delimiter = delimiter;\n this.blocks = getBlocks(pattern);\n this.initValues();\n }\n\n initValues() {\n if (this.formattedInputTarget.value) {\n const parts = parseISODate(this.formattedInputTarget.value);\n const strippedValue = toStrippedDateString({\n parts,\n pattern: this.pattern,\n });\n const { formattedDate, date } = formatDateInput({\n blocks: this.blocks,\n cursorPosition: this.formattedInputTarget.value.length,\n pattern: this.pattern,\n value: strippedValue,\n prevValue: strippedValue,\n delimiter: this.delimiter,\n prevDate: this.date,\n });\n this.date = date;\n this.formattedDate = formattedDate;\n }\n this.setInputTargetValue(this.formattedDate);\n }\n\n connect(): void {\n this.onIntersectElement(this.element);\n this.inputTarget.addEventListener('input', this.onInput);\n this.inputTarget.addEventListener('focus', this.onFocus);\n }\n\n disconnect(): void {\n this.inputTarget.removeEventListener('input', this.onInput);\n this.inputTarget.removeEventListener('focus', this.onFocus);\n this.intersectionObserver?.disconnect();\n }\n\n private onInput = (event: Event) => {\n const target = event.target as HTMLInputElement;\n const userInput = target.value;\n const startingCursor = target.selectionStart ?? userInput.length;\n\n const { formattedDate, cursorPosition, date } = formatDateInput({\n blocks: this.blocks,\n cursorPosition: startingCursor,\n pattern: this.pattern,\n value: userInput,\n prevValue: this.formattedDate,\n delimiter: this.delimiter,\n prevDate: this.date,\n });\n\n this.formattedDate = formattedDate;\n this.date = date;\n if (startingCursor !== userInput.length) {\n setCursorPosition(target, cursorPosition);\n }\n this.setInputTargetValue(formattedDate);\n this.setFormattedInputTargetValue(date.m, date.d);\n };\n\n private onFocus = (event: Event) => {\n const target = event.target as HTMLInputElement;\n const userInput = target.value;\n const cursorPosition = userInput.length;\n const { formattedDate, date } = formatDateInput({\n blocks: this.blocks,\n cursorPosition,\n pattern: this.pattern,\n value: userInput,\n prevValue: this.formattedDate,\n delimiter: this.delimiter,\n prevDate: this.date,\n });\n this.formattedDate = formattedDate;\n this.date = date;\n this.setInputTargetValue(formattedDate);\n this.setFormattedInputTargetValue(date.m, date.d);\n };\n\n private setInputTargetValue(formattedDate: string) {\n this.inputTarget.value = formattedDate;\n }\n\n private setFormattedInputTargetValue(month: string, day: string) {\n this.formattedInputTarget.value = toDefaultDateString(month, day);\n }\n\n private onIntersectElement(node: Element) {\n this.intersectionObserver = new IntersectionObserver(this.onIntersection);\n this.intersectionObserver.observe(node);\n }\n\n private onIntersection = (entries: IntersectionObserverEntry[]) => {\n for (const entry of entries) {\n if (entry.isIntersecting) {\n this.initValues();\n }\n }\n };\n}\n", "import { Controller } from '@hotwired/stimulus';\n\nexport default class extends Controller {\n static readonly targets = ['trigger'];\n\n declare triggerTargets: HTMLElement[];\n\n initialize() {\n for (const element of this.triggerTargets) {\n element.removeAttribute('hidden');\n }\n }\n\n dismiss() {\n this.element.remove();\n }\n}\n", "import { Controller } from '@hotwired/stimulus';\nimport { DrawerController } from '@elc-online/edl-components/js/drawer';\n\nexport default class extends Controller {\n static readonly targets = [\n 'content',\n 'close',\n 'handle',\n 'trigger',\n 'container',\n 'form',\n ];\n static readonly values = { position: String };\n\n declare contentTarget: HTMLElement;\n declare closeTarget: HTMLButtonElement;\n declare handleTarget: HTMLElement;\n declare triggerTarget: HTMLButtonElement;\n declare hasTriggerTarget: boolean;\n\n private edlController: typeof DrawerController = null;\n\n initialize() {\n this.edlController = new DrawerController(\n {\n close: this.closeTarget,\n drawer: this.contentTarget,\n handle: this.handleTarget,\n trigger: this.triggerTarget,\n },\n { mode: 'auto' },\n );\n\n // TODO: Remove after EDL-135\n this.handleTarget.addEventListener('touchmove', (event) =>\n event.preventDefault(),\n );\n }\n\n // TODO: Remove after EDL-136\n hide = () => {\n this?.edlController?.close();\n };\n}\n", "import { Controller } from '@hotwired/stimulus';\nimport { debounce } from '../../utilities/debounce';\n\nexport default class extends Controller {\n private readonly FOCUS_DEBOUNCE_TIME = 50;\n\n initialize() {\n window.addEventListener(\n 'turbo:load',\n debounce(() => this.setFocus(), this.FOCUS_DEBOUNCE_TIME),\n { once: true },\n );\n }\n\n setFocus() {\n const targetElement = this.element.querySelector(\n ':invalid:enabled, [aria-invalid=\"true\"]',\n ) as HTMLElement;\n targetElement?.focus();\n }\n}\n", "import { Controller } from '@hotwired/stimulus';\nimport { debounce } from '../../utilities/debounce';\n\ntype Element = HTMLInputElement | HTMLSelectElement | HTMLButtonElement;\n\nexport default class extends Controller {\n private readonly SUBMIT_DEBOUNCE_TIME = 300;\n\n private readonly elementsToDisable = [\n 'input',\n 'button',\n 'textarea',\n 'select',\n ];\n\n initialize() {\n document.body.style.cursor = 'auto';\n super.initialize();\n\n this.element.addEventListener(\n 'change',\n debounce(this.submit.bind(this), this.SUBMIT_DEBOUNCE_TIME),\n );\n }\n\n disconnect() {\n this.element.removeEventListener(\n 'change',\n debounce(this.submit.bind(this), this.SUBMIT_DEBOUNCE_TIME),\n );\n }\n\n submit() {\n document.body.style.cursor = 'progress';\n (this.element as HTMLFormElement).requestSubmit();\n this.disableElements();\n }\n\n private disableElements() {\n const formElementTargets = this.element.querySelectorAll(\n this.elementsToDisable.join(', '),\n );\n for (const formElement of formElementTargets) {\n (formElement as Element).disabled = true;\n }\n }\n}\n", "import { Controller } from '@hotwired/stimulus';\n\nexport default class extends Controller {\n static readonly targets = ['checkbox', 'accordion', 'textarea'];\n\n declare checkboxTarget: HTMLInputElement;\n declare accordionTarget: HTMLDetailsElement;\n declare textareaTarget: HTMLTextAreaElement;\n\n get open() {\n return this.checkboxTarget.checked;\n }\n\n set open(value: boolean) {\n this.checkboxTarget.checked = value;\n }\n\n initialize() {\n this.accordionTarget.addEventListener('toggle', this.handleAccordionToggle);\n this.checkboxTarget.addEventListener('change', this.applyState);\n this.applyState();\n }\n\n private applyState = () => {\n if (!this.open) {\n this.accordionTarget.open = false;\n this.handleAccordionToggle();\n }\n };\n\n private handleAccordionToggle = () => {\n if (!this.accordionTarget.open) {\n this.cleanFields();\n }\n };\n\n private cleanFields() {\n this.textareaTarget.value = '';\n this.textareaTarget.dispatchEvent(new Event('input', { bubbles: true }));\n }\n}\n", "import { Controller } from '@hotwired/stimulus';\n\nexport default class extends Controller {\n static readonly targets = ['input', 'errorMessageContainer', 'errorMessage'];\n static readonly values = {\n message: String,\n };\n static readonly classes = ['hidden'];\n\n declare inputTarget: HTMLInputElement;\n declare errorMessageContainerTarget: HTMLElement;\n declare errorMessageTarget: HTMLElement;\n declare hasErrorMessageTarget: boolean;\n declare messageValue: string;\n declare hasMessageValue: boolean;\n declare hiddenClass: string;\n\n initialize() {\n this.inputTarget.addEventListener('input', this.onInput);\n\n if (this.hasErrorMessageTarget && this.messageValue) {\n this.inputTarget.setCustomValidity(this.messageValue);\n this.updateValidationMessage();\n }\n }\n\n updateValidationMessage() {\n const { validationMessage } = this.inputTarget;\n this.inputTarget.setCustomValidity(validationMessage);\n }\n\n get ariaValidity() {\n return this.inputTarget.getAttribute('aria-invalid') === 'true';\n }\n\n onInput = () => {\n // Clear custom validation on first change and allow native to take over\n this.inputTarget.setCustomValidity('');\n this.updateValidationMessage();\n\n if (this.ariaValidity) {\n this.errorMessageTarget.textContent = '';\n this.errorMessageContainerTarget.classList.add(this.hiddenClass);\n this.inputTarget.setAttribute('aria-invalid', 'false');\n }\n };\n}\n", "import { Controller } from '@hotwired/stimulus';\n\nexport default class extends Controller {\n static readonly targets = ['toggle', 'menuItem', 'subMenu'];\n\n declare toggleTarget: HTMLElement;\n\n declare menuItemTargets: HTMLElement[];\n\n declare subMenuTargets: HTMLElement[];\n\n private isMenuOpen = false;\n\n private currentMenuItem: HTMLElement | undefined;\n\n private currentSubMenu: HTMLElement | undefined;\n\n private keepSubMenuOpen = false;\n\n initialize() {\n this.currentMenuItem = this.menuItemTargets[0];\n this.currentSubMenu = this.subMenuTargets[0];\n\n this.element.addEventListener('focusout', (event) => {\n const focusEvent: FocusEvent = event as FocusEvent;\n if (!this.element.contains(focusEvent.relatedTarget as Node)) {\n this.currentMenuItem?.setAttribute('tabindex', '0');\n this.keepSubMenuOpen = false;\n this.toggleSubMenu(false);\n }\n });\n\n this.handleMenuKeypress();\n this.handleSubMenuKeypress();\n }\n\n toggleMenu() {\n this.isMenuOpen = !this.isMenuOpen;\n this.toggleTarget.setAttribute('aria-expanded', this.isMenuOpen.toString());\n }\n\n private handleMenuKeypress() {\n for (const [index, menuItem] of this.menuItemTargets.entries()) {\n menuItem.addEventListener('keydown', (event) => {\n switch (event.key) {\n case 'ArrowRight':\n case 'Right': {\n this.moveToRightMenuItem(index);\n this.focusNextMenuItem(event.currentTarget as HTMLElement);\n event.preventDefault();\n break;\n }\n case 'ArrowLeft':\n case 'Left': {\n this.moveToLeftMenuItem(index);\n this.focusNextMenuItem(event.currentTarget as HTMLElement);\n event.preventDefault();\n break;\n }\n case 'ArrowUp':\n case 'Up':\n case 'End':\n case 'PageDown': {\n this.keepSubMenuOpen = true;\n this.currentSubMenu = this.subMenuTargets[index];\n this.showSubMenu(true);\n event.preventDefault();\n break;\n }\n case 'ArrowDown':\n case 'Down':\n case 'Home':\n case 'PageUp':\n case ' ':\n case 'Enter': {\n this.keepSubMenuOpen = true;\n this.currentSubMenu = this.subMenuTargets[index];\n this.showSubMenu();\n event.preventDefault();\n break;\n }\n default: {\n break;\n }\n }\n });\n }\n }\n\n private handleSubMenuKeypress() {\n for (const [subMenuIndex, subMenu] of this.subMenuTargets.entries()) {\n const subMenuItems = this.getSubMenuItems(subMenu);\n for (const [subMenuItemIndex, subMenuItem] of subMenuItems.entries()) {\n subMenuItem.addEventListener('keydown', (event) => {\n switch (event.key) {\n case 'ArrowDown':\n case 'Down': {\n const nextSubMenuItem =\n subMenuItemIndex === subMenuItems.length - 1\n ? subMenuItems[0]\n : subMenuItems[subMenuItemIndex + 1];\n nextSubMenuItem.focus();\n event.preventDefault();\n break;\n }\n case 'ArrowUp':\n case 'Up': {\n const nextSubMenuItem =\n subMenuItemIndex === 0\n ? subMenuItems.at(-1)\n : subMenuItems[subMenuItemIndex - 1];\n nextSubMenuItem?.focus();\n event.preventDefault();\n break;\n }\n case 'ArrowRight':\n case 'Right': {\n const previousMenuItem = this.currentMenuItem;\n this.toggleSubMenu(false);\n this.moveToRightMenuItem(subMenuIndex);\n if (previousMenuItem) {\n this.focusNextMenuItem(previousMenuItem);\n }\n this.currentSubMenu =\n subMenuIndex === this.subMenuTargets.length - 1\n ? this.subMenuTargets[0]\n : this.subMenuTargets[subMenuIndex + 1];\n this.showSubMenu();\n event.preventDefault();\n break;\n }\n case 'ArrowLeft':\n case 'Left': {\n const previousMenuItem = this.currentMenuItem;\n this.toggleSubMenu(false);\n this.moveToLeftMenuItem(subMenuIndex);\n if (previousMenuItem) {\n this.focusNextMenuItem(previousMenuItem);\n }\n this.currentSubMenu =\n subMenuIndex === 0\n ? (this.subMenuTargets.at(-1) as HTMLElement)\n : this.subMenuTargets[subMenuIndex - 1];\n this.showSubMenu();\n event.preventDefault();\n break;\n }\n case 'Escape':\n case 'Esc': {\n this.keepSubMenuOpen = false;\n this.toggleSubMenu(false);\n this.currentMenuItem?.focus();\n event.preventDefault();\n break;\n }\n default: {\n break;\n }\n }\n });\n }\n }\n }\n\n private moveToRightMenuItem(menuItemIndex: number) {\n this.currentMenuItem =\n menuItemIndex === this.menuItemTargets.length - 1\n ? this.menuItemTargets[0]\n : this.menuItemTargets[menuItemIndex + 1];\n }\n\n private moveToLeftMenuItem(menuItemIndex: number) {\n this.currentMenuItem =\n menuItemIndex === 0\n ? (this.menuItemTargets.at(-1) as HTMLElement)\n : this.menuItemTargets[menuItemIndex - 1];\n }\n\n private focusNextMenuItem(previousMenuItem: HTMLElement) {\n previousMenuItem.setAttribute('tabindex', '-1');\n this.currentMenuItem?.focus();\n }\n\n private getSubMenuItems(subMenu: HTMLElement): HTMLElement[] {\n return [...subMenu.querySelectorAll('a[role=\"menuitem\"]')] as HTMLElement[];\n }\n\n private showSubMenu(showLastItem = false) {\n if (this.keepSubMenuOpen && this.currentSubMenu) {\n this.toggleSubMenu(true);\n this.currentMenuItem?.setAttribute('tabindex', '-1');\n const subMenuItems = this.getSubMenuItems(this.currentSubMenu);\n if (showLastItem) {\n subMenuItems?.at(-1)?.focus();\n } else {\n subMenuItems[0].focus();\n }\n }\n }\n\n private toggleSubMenu(isExpanded: boolean) {\n this.currentMenuItem?.setAttribute('aria-expanded', isExpanded.toString());\n }\n}\n", "import { Controller } from '@hotwired/stimulus';\n\ntype ItemElement = HTMLLIElement;\n\nexport default class extends Controller {\n static readonly targets = ['toggle', 'menuItem', 'menu'];\n\n declare toggleTarget: HTMLButtonElement;\n declare menuTarget: HTMLButtonElement;\n declare menuItemTargets: ItemElement[];\n\n private isMenuOpen = false;\n private currentMenuItem: ItemElement | undefined;\n\n initialize(): void {\n this.focusOnSelectedMenuItem();\n }\n\n connect(): void {\n this.handleMenuKeypress();\n this.handleFocusOnKeyPressed();\n this.handleItemOnBlur();\n this.onFocusOut();\n }\n\n toggle() {\n this.isMenuOpen = !this.isMenuOpen;\n this.toggleTarget.setAttribute('aria-expanded', String(this.isMenuOpen));\n if (this.isMenuOpen) {\n this.focusOnSelectedMenuItem();\n } else {\n this.toggleTarget.focus();\n }\n }\n\n close() {\n this.isMenuOpen = false;\n this.toggleTarget.setAttribute('aria-expanded', 'false');\n this.toggleTarget.focus();\n }\n\n private onFocusOut() {\n this.element.addEventListener('focusout', (event: Event) => {\n const node = (event as MouseEvent).relatedTarget as Node;\n if (this.isMenuOpen && !this.element.contains(node)) {\n this.toggle();\n }\n });\n }\n\n private handleMenuKeypress() {\n for (const [index, menuItem] of this.menuItemTargets.entries()) {\n menuItem.addEventListener('keydown', (event: KeyboardEvent) => {\n switch (event.key) {\n case 'ArrowUp':\n case 'Up': {\n this.moveToPreviousMenuItem(index);\n this.focusMenuItem();\n event.preventDefault();\n break;\n }\n case 'ArrowDown':\n case 'Down': {\n this.moveToNextMenuItem(index);\n this.focusMenuItem();\n event.preventDefault();\n break;\n }\n default: {\n break;\n }\n }\n });\n }\n }\n\n private handleItemOnBlur() {\n for (const menuItem of this.menuItemTargets) {\n menuItem.addEventListener('blur', (event) => {\n if (this.isMenuOpen) {\n (event.target as ItemElement).setAttribute('tabindex', '-1');\n }\n });\n }\n }\n\n private handleFocusOnKeyPressed() {\n this.toggleTarget.addEventListener('keydown', (event: KeyboardEvent) => {\n (event.target as ItemElement).focus();\n });\n }\n\n private moveToNextMenuItem(menuItemIndex: number) {\n this.currentMenuItem =\n menuItemIndex === this.menuItemTargets.length - 1\n ? this.menuItemTargets[0]\n : this.menuItemTargets[menuItemIndex + 1];\n }\n\n private moveToPreviousMenuItem(menuItemIndex: number) {\n this.currentMenuItem =\n menuItemIndex === 0\n ? (this.menuItemTargets.at(-1) as ItemElement)\n : this.menuItemTargets[menuItemIndex - 1];\n }\n\n private focusOnSelectedMenuItem() {\n let newFocusElement: ItemElement | undefined;\n for (const menuItem of this.menuItemTargets) {\n if (menuItem.ariaChecked === 'true') {\n newFocusElement = menuItem;\n break;\n }\n }\n this.currentMenuItem = newFocusElement ?? this.menuItemTargets[0];\n this.focusMenuItem();\n }\n\n private focusMenuItem() {\n this.currentMenuItem?.focus();\n this.currentMenuItem?.setAttribute('tabindex', '0');\n }\n}\n", "export function getFocusableElements(container: HTMLElement): HTMLElement[] {\n return [\n ...(container.querySelectorAll(\n [\n 'input:not(:disabled):not([type=\"hidden\"])',\n 'button:not(:disabled)',\n 'textarea:not(:disabled)',\n 'select:not(:disabled)',\n 'a[href]',\n '[tabindex]:not([tabindex=\"-1\"])',\n ].join(', '),\n ) as NodeListOf),\n ];\n}\n\nexport class FocusGuard {\n private container: HTMLElement;\n private focusableElements: HTMLElement[];\n private beforeGuard: HTMLElement = document.createElement('span');\n private afterGuard: HTMLElement = document.createElement('span');\n\n constructor(containerEl: HTMLElement) {\n this.container = containerEl;\n this.focusableElements = getFocusableElements(this.container);\n\n this.beforeGuard.addEventListener('focus', this.focusLast);\n this.beforeGuard.setAttribute('aria-hidden', 'true');\n\n this.afterGuard.addEventListener('focus', this.focusFirst);\n this.afterGuard.setAttribute('aria-hidden', 'true');\n\n this.container.prepend(this.beforeGuard);\n this.container.append(this.afterGuard);\n\n this.enable();\n }\n\n private focusFirst = () => {\n this.focusableElements[0]?.focus();\n };\n\n private focusLast = () => {\n this.focusableElements[this.focusableElements.length - 1]?.focus();\n };\n\n public enable = () => {\n this.beforeGuard.setAttribute('tabindex', '0');\n this.afterGuard.setAttribute('tabindex', '0');\n };\n\n public disable = () => {\n this.beforeGuard.setAttribute('tabindex', '-1');\n this.afterGuard.setAttribute('tabindex', '-1');\n };\n}\n", "import { Controller } from '@hotwired/stimulus';\nimport { FocusGuard, getFocusableElements } from '../../utilities/focus';\nimport { afterNextRender } from '@/global/scripts/utilities/timing';\n\nexport default class extends Controller {\n static readonly targets = ['modal', 'trigger'];\n declare modalTarget: HTMLElement;\n declare triggerTarget: HTMLElement;\n declare hasTriggerTarget: boolean;\n\n private focusGuard?: FocusGuard;\n\n initialize() {\n super.initialize();\n\n this.focusGuard = new FocusGuard(this.modalTarget);\n\n if (this.modalTarget.hidden) {\n this.focusGuard.disable();\n } else {\n this.show();\n }\n\n if (this.hasTriggerTarget) {\n this.triggerTarget.addEventListener('click', (event) => {\n event.stopImmediatePropagation();\n this.show();\n });\n }\n }\n\n get isConfirmation() {\n return this.modalTarget.dataset.isConfirmation === 'true';\n }\n\n set open(show: boolean) {\n this.modalTarget.hidden = !show;\n }\n\n get open() {\n return !this.modalTarget.hidden;\n }\n\n show = () => {\n const focusable = getFocusableElements(this.modalTarget);\n this.open = true;\n this.focusGuard?.enable();\n\n if (focusable.length > 0) {\n afterNextRender(() => focusable[0].focus());\n }\n };\n\n hide = (e: Event | undefined) => {\n e?.stopImmediatePropagation();\n if (this.open) {\n this.open = false;\n this.focusGuard?.disable();\n\n if (this.hasTriggerTarget) {\n this.triggerTarget.focus();\n }\n }\n };\n}\n", "import { Controller } from '@hotwired/stimulus';\n\ninterface OneTrust {\n InitializeBanner?: () => void;\n LoadBanner?: () => void;\n ToggleInfoDisplay?: () => void;\n}\n\ndeclare global {\n interface Window {\n OneTrust?: OneTrust;\n }\n}\n\nexport default class extends Controller {\n static afterLoad() {\n window.addEventListener('turbo:load', () => {\n if (!document.querySelector('#onetrust-consent-sdk')) {\n // Re-render and attach the OneTrust banner to DOM\n window.OneTrust?.InitializeBanner?.();\n window.OneTrust?.LoadBanner?.();\n }\n\n const button = document.querySelector('.optanon-show-settings');\n button?.addEventListener(\n 'click',\n () => {\n window.OneTrust?.ToggleInfoDisplay?.();\n },\n { once: true },\n );\n });\n }\n}\n", "import { Controller } from '@hotwired/stimulus';\n\nexport default class extends Controller {\n initialize(): void {\n window.ELCO.CSRF.refreshTokens();\n this.setELCOPageData();\n\n window.addEventListener('turbo:load', this.onTurboLoad);\n window.addEventListener('turbo:frame-load', this.onTurboFrameLoad);\n window.addEventListener('turbo:frame-missing', this.onTurboFrameMissing);\n\n window.addEventListener(\n 'page:loaded',\n ((e: CustomEvent) => {\n window.ELCO.Debug.debug('log', e.type, e.detail);\n }) as unknown as EventListener,\n { once: true },\n );\n\n window.addEventListener('page_data:updated', ((e: CustomEvent) => {\n window.ELCO.Debug.debug('log', e.type, e.detail);\n }) as unknown as EventListener);\n }\n\n disconnect(): void {\n window.removeEventListener('turbo:load', this.onTurboLoad);\n window.removeEventListener('turbo:frame-load', this.onTurboFrameLoad);\n window.removeEventListener('turbo:frame-missing', this.onTurboFrameMissing);\n }\n\n private onTurboLoad = () => {\n this.setELCOPageData();\n\n const pageLoaded = new CustomEvent('page:loaded', {\n detail: window.ELCO.Analytics.pageData(),\n });\n window.dispatchEvent(pageLoaded);\n };\n\n private onTurboFrameLoad = () => {\n this.setELCOPageData();\n\n const pageDataUpdated = new CustomEvent('page_data:updated', {\n detail: window.ELCO.Analytics.pageData(),\n });\n window.dispatchEvent(pageDataUpdated);\n };\n\n private setELCOPageData = () => {\n const element = document.querySelector('#page_data');\n window.__elco_page_data = element\n ? JSON.parse(element.innerHTML || '{}')\n : {};\n };\n\n private onTurboFrameMissing = () => {\n window.location.assign(window.location.href);\n };\n}\n", "import { Controller } from '@hotwired/stimulus';\nimport ToggleButtonController from './toggle-button-controller';\n\nexport default class extends Controller {\n static readonly targets = ['input'];\n static readonly outlets = [\"toggle-button\"];\n\n declare inputTarget: HTMLInputElement;\n declare toggleButtonOutlet: ToggleButtonController;\n declare hasToggleButtonOutlet: boolean;\n\n initialize() {\n this.setInputState();\n }\n\n toggle() { \n this.setInputState();\n }\n\n setInputState() {\n this.inputTarget.type = this.toggleButtonOutlet.isOn ? 'text' : 'password';\n }\n}\n", "import { Controller } from '@hotwired/stimulus';\n\nexport default class extends Controller {\n static readonly targets = [\n 'input',\n 'meter',\n 'requirement',\n 'validatorContainer',\n ];\n\n declare inputTarget: HTMLInputElement;\n declare meterTarget: HTMLInputElement;\n declare requirementTargets: HTMLElement[];\n declare validatorContainerTarget: HTMLDivElement;\n\n private passedRequirementCount = 0;\n\n initialize() {\n if (this.ariaValidity) {\n this.showValidator();\n }\n }\n\n showValidator() {\n this.validatorContainerTarget.setAttribute('aria-hidden', 'false');\n }\n\n get ariaValidity() {\n return this.inputTarget.getAttribute('aria-invalid') === 'true';\n }\n\n inputChange() {\n this.validateIndividualRequirements();\n this.setPassedRequirementCount();\n this.updateMeterValue();\n }\n\n validateIndividualRequirements() {\n for (const requirementTarget of this.requirementTargets) {\n if (\n new RegExp(requirementTarget.dataset.pattern as string).test(\n this.inputTarget.value,\n )\n ) {\n this.setSuccess(requirementTarget);\n } else {\n this.setFailure(requirementTarget);\n }\n }\n }\n\n setPassedRequirementCount() {\n this.passedRequirementCount = 0;\n for (const requirementTarget of this.requirementTargets) {\n if (requirementTarget.dataset.valid == 'true') {\n this.passedRequirementCount = this.passedRequirementCount + 1;\n }\n }\n }\n\n updateMeterValue() {\n let value = '0';\n switch (this.passedRequirementCount) {\n case 1:\n case 2: {\n value = '1';\n break;\n }\n case 3: {\n value = '2';\n break;\n }\n case 4: {\n value = '3';\n break;\n }\n }\n this.meterTarget.setAttribute('aria-valuenow', value);\n }\n\n setSuccess(requirementTarget: HTMLElement) {\n requirementTarget.dataset.valid = 'true';\n }\n\n setFailure(requirementTarget: HTMLElement) {\n requirementTarget.dataset.valid = 'false';\n }\n}\n", "import { Controller } from '@hotwired/stimulus';\n\nexport default class extends Controller {\n static readonly targets = ['input', 'content'];\n static readonly classes = ['hidden'];\n\n declare inputTargets: HTMLInputElement[];\n declare contentTargets: HTMLElement[];\n declare hiddenClass: string;\n\n private controllerAttributes: Map = new Map();\n\n connect(): void {\n for (const content of this.contentTargets) {\n // Create reference for payment methods data-attribute after page load\n this.controllerAttributes.set(\n content,\n content.dataset.controller as string,\n );\n }\n this.handleSelection();\n this.application.element.addEventListener(\n 'turbo:morph',\n this.handleSelection,\n );\n }\n\n disconnect() {\n this.application.element.removeEventListener(\n 'turbo:morph',\n this.handleSelection,\n );\n }\n\n handleSelection = () => {\n this.setCheckedFromQueryParam();\n this.toggle();\n };\n\n open = (event: MouseEvent) => {\n const element = event.currentTarget as HTMLElement;\n const input = element.querySelector('input[type=\"radio\"]') as HTMLInputElement;\n if (input) {\n input.checked = true;\n this.toggle();\n }\n };\n\n toggle = () => {\n for (const [index, input] of this.inputTargets.entries()) {\n const content = this.contentTargets[index];\n if (input.checked) {\n // Restore the original data-controller value when the radio button is selected\n content.dataset.controller = this.controllerAttributes.get(\n content,\n ) as string;\n content.classList.remove(this.hiddenClass);\n } else {\n // Remove the data-controller attribute when the radio button is not selected\n content.dataset.controller = '';\n content.classList.add(this.hiddenClass);\n }\n }\n };\n\n setCheckedFromQueryParam = () => {\n const urlParams = new URLSearchParams(window.location.search);\n const paymentMethod = urlParams.get('method');\n\n if (paymentMethod) {\n for (const input of this.inputTargets) {\n input.removeAttribute('checked');\n input.checked = input.value === paymentMethod;\n }\n }\n };\n}\n", "import { Controller } from '@hotwired/stimulus';\nimport { afterNextRender } from '../../utilities/timing';\n\nconst templates: Record = {\n '+1': '___-___-____',\n '+44': '____ ______',\n '+61': '___ ___ ___',\n};\n\nexport default class extends Controller {\n private readonly NUMBER_SYMBOL = '_';\n\n static readonly targets = ['input', 'country'];\n\n declare inputTarget: HTMLInputElement;\n declare countryTarget: HTMLSelectElement;\n declare hasCountryTarget: boolean;\n\n private template: string = '';\n\n get strippedValue() {\n return stripValue(this.inputTarget.value.slice(0, this.template.length));\n }\n\n initialize() {\n this.setTemplate();\n\n if (this.inputTarget.value && this.template) {\n this.inputTarget.value = maskPhoneNumber(\n this.template,\n this.strippedValue,\n this.NUMBER_SYMBOL,\n );\n }\n }\n\n connect() {\n this.inputTarget.addEventListener('input', this.onInput);\n this.countryTarget.addEventListener('change', this.setTemplate);\n }\n\n disconnect() {\n this.inputTarget.removeEventListener('input', this.onInput);\n this.countryTarget.removeEventListener('change', this.setTemplate);\n }\n\n get country() {\n return this.countryTarget.value;\n }\n\n private onInput = (event: Event) => {\n const inputEvent = event as InputEvent;\n const target = inputEvent.target as HTMLInputElement;\n const startingCursor =\n target.selectionStart ?? this.inputTarget.value.length;\n const deleteInputType = [\n 'deleteContentBackward',\n 'deleteContentForward',\n ].includes(inputEvent.inputType);\n\n if (!deleteInputType && this.template) {\n if (this.inputTarget.value.length >= this.template.length) {\n this.inputTarget.value = this.inputTarget.value.slice(\n 0,\n this.template.length,\n );\n }\n this.inputTarget.value = maskPhoneNumber(\n this.template,\n this.strippedValue,\n this.NUMBER_SYMBOL,\n );\n this.adjustCursorPosition(target, startingCursor);\n }\n };\n\n private setTemplate = () => {\n this.template = templates[this.country];\n\n if (this.template) {\n if (this.inputTarget.value) {\n // Don't use this.strippedValue here because we are switching templates and they are different lengths!\n this.inputTarget.value = maskPhoneNumber(\n this.template,\n stripValue(this.inputTarget.value),\n this.NUMBER_SYMBOL,\n );\n }\n\n this.inputTarget.maxLength = this.template.length;\n\n const digit_count =\n this.template.length -\n this.template.replaceAll(this.NUMBER_SYMBOL, '').length;\n this.inputTarget.pattern = `(\\\\d\\\\D*){${digit_count}}`;\n }\n };\n\n private adjustCursorPosition(\n target: HTMLInputElement,\n startingCursor: number,\n ) {\n const newPosition = findNewPositionByMaskAndIndex(\n this.template,\n startingCursor,\n this.NUMBER_SYMBOL,\n );\n setCursorPosition(target, newPosition);\n }\n}\n\nfunction findNewPositionByMaskAndIndex(\n template: string,\n currentIndex: number,\n numberSymbol: string,\n) {\n let newPosition = currentIndex;\n for (let index = currentIndex; index < template.length; index++) {\n if (template[index] === numberSymbol) {\n break;\n } else {\n newPosition += 1;\n }\n }\n\n return newPosition;\n}\n\nfunction maskPhoneNumber(\n mask: string,\n strippedValue: string,\n numberSymbol: string,\n): string {\n const result: string[] = [];\n const parsedValue = strippedValue;\n\n let parsedValueIndex = 0;\n for (const maskDigit of mask) {\n if (maskDigit !== numberSymbol) {\n result.push(maskDigit);\n } else if (parsedValueIndex < parsedValue.length) {\n result.push(parsedValue[parsedValueIndex]);\n parsedValueIndex += 1;\n } else {\n break;\n }\n }\n\n return result.join('');\n}\n\nfunction stripValue(value: string) {\n return value ? value.replaceAll(/\\D/g, '') : '';\n}\n\nfunction setCursorPosition(element: HTMLInputElement, position: number) {\n afterNextRender(() => element.setSelectionRange(position, position));\n}\n", "import { Controller } from '@hotwired/stimulus';\nimport { PopoverController } from '@elc-online/edl-components/js/popover';\n\nexport default class extends Controller {\n static readonly targets = ['popover', 'container', 'trigger'];\n\n declare popoverTarget: HTMLElement;\n declare containerTarget: HTMLElement;\n declare triggerTarget: HTMLButtonElement;\n\n initialize(): void {\n const placement = this.containerTarget.dataset.placement;\n const alignment = this.containerTarget.dataset.alignment;\n\n new PopoverController(\n {\n popover: this.popoverTarget,\n container: this.containerTarget,\n trigger: this.triggerTarget,\n },\n {\n mode: 'auto',\n },\n );\n }\n}\n", "import { Controller } from '@hotwired/stimulus';\n\nexport default class extends Controller {\n static readonly targets = ['wrapper'];\n static readonly values = {\n email: String,\n emailPlaceholder: String,\n portal: String,\n portalSelector: String,\n healthData: String,\n healthDataSelector: String,\n };\n\n declare wrapperTarget: HTMLDivElement;\n declare hasWrapperTarget: boolean;\n declare emailValue: string;\n declare emailPlaceholderValue: string;\n declare portalValue: string;\n declare portalSelectorValue: string;\n declare healthDataValue: string;\n declare healthDataSelectorValue: string;\n\n private observer: MutationObserver | undefined = undefined;\n\n initialize(): void {\n this.observer = new MutationObserver((mutationList) => {\n for (const mutation of mutationList) {\n if (mutation.type === 'childList') {\n if (this.hasWrapperTarget) {\n this.updateEmail();\n this.updateLinks(this.portalSelectorValue, this.portalValue);\n this.updateLinks(\n this.healthDataSelectorValue,\n this.healthDataValue,\n );\n }\n\n if (this.observer) {\n this.observer.disconnect();\n }\n }\n }\n });\n }\n\n connect(): void {\n if (this.observer) {\n this.observer.observe(this.wrapperTarget, { childList: true });\n }\n }\n\n disconnect(): void {\n if (this.observer) {\n this.observer.disconnect();\n }\n }\n\n private updateEmail() {\n const linkElement = document.createElement('a');\n linkElement.setAttribute('href', `mailto:${this.emailValue}`);\n linkElement.setAttribute('target', '_blank');\n linkElement.innerHTML = this.emailValue;\n const regex = new RegExp(this.emailPlaceholderValue, 'g');\n this.wrapperTarget.innerHTML = this.wrapperTarget.innerHTML.replace(\n regex,\n linkElement.outerHTML,\n );\n }\n\n private updateLinks(selector: string, value: string) {\n if (selector?.length) {\n const links = this.wrapperTarget.querySelectorAll(selector);\n\n for (const link of links) {\n link.setAttribute('href', value);\n link.setAttribute('target', '_blank');\n }\n }\n }\n}\n", "import { Controller } from '@hotwired/stimulus';\nimport TooltipController from './tooltip-controller';\n\nexport default class extends Controller {\n static readonly targets = ['input', 'decrement', 'increment'];\n static readonly outlets = ['tooltip'];\n\n declare inputTarget: HTMLInputElement;\n declare decrementTarget: HTMLButtonElement;\n declare incrementTarget: HTMLButtonElement;\n\n declare tooltipOutlet: TooltipController;\n declare hasTooltipOutlet: boolean;\n\n private quantity = 0;\n private min = 0;\n private max = 0;\n\n connect() {\n this.initializeValues();\n this.updateState();\n this.inputTarget.addEventListener('input', this.onInput);\n }\n\n private initializeValues() {\n this.quantity = Number.parseInt(this.inputTarget.value, 10) || 0;\n this.min = Number.parseInt(this.inputTarget.min, 10) || 0;\n this.max = Number.parseInt(this.inputTarget.max, 10) || 0;\n }\n\n private updateState() {\n this.quantity = Number.parseInt(this.inputTarget.value, 10);\n\n this.quantity = Math.min(this.quantity, this.max);\n this.quantity = Math.max(this.quantity, this.min);\n\n this.decrementTarget.disabled = this.quantity <= this.min;\n this.incrementTarget.disabled = this.quantity >= this.max;\n\n if (this.incrementTarget.disabled) {\n this.tooltipOutlet.enable();\n this.tooltipOutlet.show();\n } else {\n this.tooltipOutlet.disable();\n this.tooltipOutlet.hide();\n }\n }\n\n private onInput = () => {\n this.updateState();\n this.inputTarget.value = this.quantity.toString();\n };\n\n updateQuantity() {\n this.updateState();\n }\n\n decrementQuantity() {\n this.inputTarget.stepDown();\n this.inputTarget.dispatchEvent(new Event('change', { bubbles: true }));\n }\n\n incrementQuantity() {\n this.inputTarget.stepUp();\n this.inputTarget.dispatchEvent(new Event('change', { bubbles: true }));\n }\n}\n", "import { Controller } from '@hotwired/stimulus';\n\nexport default class extends Controller {\n static readonly targets = ['radio', 'target'];\n\n declare radioTargets: HTMLInputElement[];\n declare targetTargets: HTMLFieldSetElement[];\n\n get currentId() {\n for (const radio of this.radioTargets) {\n if (radio.checked) {\n return radio.value;\n }\n }\n return undefined;\n }\n\n initialize() {\n for (const radio of this.radioTargets) {\n radio.addEventListener('change', this.handleToggle);\n }\n\n this.handleToggle();\n }\n\n handleToggle = () => {\n const id = this.currentId;\n\n for (const target of this.targetTargets) {\n if (target.id === id) {\n this.show(target);\n } else {\n this.hide(target);\n }\n }\n };\n\n show(element: HTMLFieldSetElement) {\n element.hidden = false;\n element.disabled = false;\n }\n\n hide(element: HTMLFieldSetElement) {\n element.hidden = true;\n element.disabled = true;\n }\n}\n", "import { Controller } from '@hotwired/stimulus';\n\ntype ItemElement = HTMLLIElement;\n\nexport default class extends Controller {\n static readonly targets = ['item', 'display'];\n static readonly values = {\n inputFormFieldName: String,\n };\n\n declare displayTarget: HTMLButtonElement;\n declare itemTargets: ItemElement[];\n declare inputFormFieldNameValue: string;\n\n connect(): void {\n for (const item of this.itemTargets) {\n item.addEventListener('keydown', this.onKeypress);\n item.addEventListener('click', this.handleOnClick);\n }\n }\n\n private onKeypress = (event: KeyboardEvent) => {\n event.preventDefault();\n switch (event.key) {\n case 'Escape': {\n this.closeMenu();\n break;\n }\n case 'Enter':\n case ' ': {\n this.onClick(event.currentTarget as ItemElement);\n break;\n }\n }\n };\n\n private handleOnClick = (event: Event) => {\n event.preventDefault();\n this.onClick(event.currentTarget as ItemElement);\n };\n\n private onClick(element: ItemElement) {\n for (const itemTarget of this.itemTargets) {\n itemTarget.setAttribute('aria-checked', 'false');\n }\n element.setAttribute('aria-checked', 'true');\n this.changeDisplayedContent(element);\n this.changeFormInputValue(element);\n this.closeMenu();\n }\n\n private changeDisplayedContent(content: ItemElement) {\n this.displayTarget.textContent = '';\n for (const item of content.childNodes) {\n const clonedNode = item.cloneNode(true);\n if (clonedNode.nodeType == Node.ELEMENT_NODE) {\n (clonedNode as HTMLElement).classList.remove('!hidden');\n }\n this.displayTarget.append(clonedNode);\n }\n }\n\n private changeFormInputValue(content: ItemElement) {\n const selectedElementValue = content.dataset.addressId;\n if (selectedElementValue) {\n const input = document.querySelector(\n `[name=\"${this.inputFormFieldNameValue}\"]`,\n ) as HTMLInputElement;\n if (input) {\n input.value = selectedElementValue;\n }\n }\n }\n\n private closeMenu() {\n const trigger = new CustomEvent('close-menu');\n window.dispatchEvent(trigger);\n }\n}\n", "import { Controller } from '@hotwired/stimulus';\nimport { debounce } from '../../utilities/debounce';\n\nexport default class extends Controller {\n private readonly RESIZE_DEBOUNCE_TIME = 300;\n private documentBody: HTMLElement = document.body;\n static readonly targets = ['element'];\n\n declare elementTarget: HTMLElement;\n\n private setPadding = () => {\n const position = window.getComputedStyle(this.elementTarget).position;\n if (position === 'fixed') {\n const offsetHeight = this.elementTarget.offsetHeight;\n this.documentBody.style.paddingBottom = `${offsetHeight}px`;\n } else {\n this.resetPadding();\n }\n };\n\n private resetPadding = () => {\n this.documentBody.style.paddingBottom = '0';\n };\n\n connect(): void {\n this.setPadding();\n window.addEventListener(\n 'resize',\n debounce(this.setPadding, this.RESIZE_DEBOUNCE_TIME),\n );\n }\n\n disconnect(): void {\n this.resetPadding();\n window.removeEventListener(\n 'resize',\n debounce(this.setPadding, this.RESIZE_DEBOUNCE_TIME),\n );\n }\n}\n", "import { Controller } from '@hotwired/stimulus';\nimport { SwitchController } from '@elc-online/edl-components/js/switch';\n\nexport default class extends Controller {\n static readonly targets = ['button'];\n\n declare buttonTarget: HTMLButtonElement;\n\n initialize(): void {\n new SwitchController(\n {\n button: this.buttonTarget,\n },\n { mode: 'auto' },\n );\n }\n}\n", "import { Controller } from '@hotwired/stimulus';\n\nexport default class extends Controller {\n private readonly DISPLAY_DURATION = 4000;\n private dragStartPosition: number = 0;\n private dragPosition: number = 0;\n\n set open(show: boolean) {\n this.element.setAttribute('aria-hidden', String(!show));\n\n if (show) {\n this.onShow();\n } else {\n this.onHide();\n }\n }\n\n get open() {\n return this.element.getAttribute('aria-hidden') === 'false';\n }\n\n private touchPosition(event: TouchEvent & DragEvent) {\n const data = event.touches ? event.touches[0] : event;\n return data.pageY;\n }\n\n connect(): void {\n if (this.open) {\n this.onShow();\n }\n }\n\n show = () => {\n this.open = true;\n };\n\n hide = () => {\n this.open = false;\n };\n\n onShow() {\n setTimeout(this.hide, this.DISPLAY_DURATION);\n\n window.addEventListener('keydown', this.onKeypress);\n this.element.addEventListener('touchstart', this.onDragStart, {\n passive: true,\n });\n this.element.addEventListener('mousedown', this.onDragStart);\n }\n\n onHide() {\n window.removeEventListener('keydown', this.onKeypress);\n this.element.removeEventListener('touchstart', this.onDragStart);\n this.element.removeEventListener('mousedown', this.onDragStart);\n }\n\n onKeypress = (event: KeyboardEvent) => {\n if (event.key === 'Escape') {\n this.hide();\n }\n };\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n onDragStart = (event: any) => {\n this.dragStartPosition = this.touchPosition(event);\n this.dragPosition = this.dragStartPosition;\n\n window.addEventListener('mousemove', this.onDragMove);\n window.addEventListener('touchmove', this.onDragMove, { passive: true });\n window.addEventListener('mouseup', this.onDragEnd);\n window.addEventListener('touchend', this.onDragEnd);\n };\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n onDragMove = (event: any) => {\n if (this.dragStartPosition === undefined) return;\n\n this.dragPosition = this.touchPosition(event);\n\n if (this.dragPosition > this.dragStartPosition) {\n const deltaY = this.dragStartPosition - this.dragPosition;\n\n const element = this.element as HTMLElement;\n element.style.bottom = `${deltaY}px`;\n }\n };\n\n onDragEnd = () => {\n const element = this.element as HTMLElement;\n element.style.bottom = '';\n\n if (this.dragPosition > this.dragStartPosition) {\n this.hide();\n }\n\n window.removeEventListener('mousemove', this.onDragMove);\n window.removeEventListener('touchmove', this.onDragMove);\n window.removeEventListener('mouseup', this.onDragEnd);\n window.removeEventListener('touchend', this.onDragEnd);\n };\n}\n", "import { Controller } from '@hotwired/stimulus';\n\nexport default class extends Controller {\n\n static readonly classes = ['hidden'];\n\n declare hiddenClass: string;\n\n initialize() {\n this.element.classList.remove(this.hiddenClass);\n }\n\n get isOn() {\n return this.element.ariaPressed === 'true';\n }\n \n set isOn(value: boolean) {\n this.element.ariaPressed = value ? 'true' : 'false';\n }\n\n toggle() {\n this.isOn = !this.isOn;\n }\n}\n", "import { Controller } from '@hotwired/stimulus';\n\nexport default class extends Controller {\n static readonly targets = ['control', 'target'];\n static readonly values = {\n invert: Boolean,\n disableOnToggle: Boolean,\n };\n\n declare controlTarget: HTMLElement;\n declare targetTarget: HTMLElement;\n declare invertValue: boolean;\n declare disableOnToggleValue: boolean;\n\n private open = false;\n private invert = false;\n\n initialize() {\n if (!this.targetTarget.id) {\n this.targetTarget.id = crypto.randomUUID();\n }\n this.controlTarget.setAttribute('aria-controls', this.targetTarget.id);\n\n this.invert = this.invertValue ?? false;\n\n this.stateFromDom();\n }\n\n toggle() {\n this.open = !this.open;\n this.applyState();\n }\n\n private stateFromDom() {\n if (isCheckbox(this.controlTarget)) {\n const checkControl = this.controlTarget as HTMLInputElement;\n this.open = this.invert ? !checkControl.checked : checkControl.checked;\n } else {\n const value = this.controlTarget.dataset.expanded === 'true';\n this.open = value;\n }\n\n this.applyState();\n }\n\n private applyState() {\n this.controlTarget.dataset.expanded = this.open.toString();\n this.targetTarget.hidden = !this.open;\n\n // TODO: Refactor\n if (this.disableOnToggleValue && isFieldset(this.targetTarget)) {\n (this.targetTarget as HTMLFieldSetElement).disabled = !this.open;\n }\n }\n}\n\nfunction isCheckbox(element: HTMLElement) {\n return element instanceof HTMLInputElement && element.type === 'checkbox';\n}\n\nfunction isFieldset(element: HTMLElement) {\n return element instanceof HTMLFieldSetElement && element.type === 'fieldset';\n}\n", "import { Controller } from '@hotwired/stimulus';\n\nexport default class extends Controller {\n static readonly targets = ['display', 'form'];\n static readonly values = { editing: Boolean };\n static readonly classes = ['hidden'];\n\n declare displayTargets: HTMLElement[];\n declare formTargets: HTMLFormElement[];\n declare hiddenClasses: string[];\n\n declare editingValue: boolean;\n\n initialize() {\n this.onToggle();\n }\n\n toggle() {\n this.editingValue = !this.editingValue;\n this.onToggle();\n }\n\n edit() {\n this.editingValue = true;\n this.onToggle();\n }\n\n display() {\n this.editingValue = false;\n this.onToggle();\n }\n\n private onToggle() {\n if (this.editingValue) {\n for (const target of this.displayTargets) {\n target.classList.add(this.hiddenClasses.join(' '));\n setElementDisabled(target, true);\n }\n for (const target of this.formTargets) {\n target.classList.remove(this.hiddenClasses.join(' '));\n setElementDisabled(target, false);\n }\n } else {\n for (const target of this.displayTargets) {\n target.classList.remove(this.hiddenClasses.join(' '));\n setElementDisabled(target, false);\n }\n\n for (const target of this.formTargets) {\n target.classList.add(this.hiddenClasses.join(' '));\n setElementDisabled(target, true);\n }\n }\n }\n}\n\nfunction isFieldset(element: HTMLElement) {\n return element instanceof HTMLFieldSetElement && element.type === 'fieldset';\n}\n\nfunction setElementDisabled(element: HTMLElement, value: boolean) {\n if (isFieldset(element)) {\n (element as HTMLFieldSetElement).disabled = value;\n }\n}\n", "export default function getOverflowedEdges(target: HTMLElement) {\n const targetBoundaries = target.getBoundingClientRect();\n const overflowedEdges = {\n top: false,\n right: false,\n bottom: false,\n left: false,\n };\n\n if (targetBoundaries.top < 0) {\n overflowedEdges.top = true;\n }\n\n if (\n targetBoundaries.right >\n (window.visualViewport?.width || document.documentElement.clientWidth)\n ) {\n overflowedEdges.right = true;\n }\n\n if (\n targetBoundaries.bottom >\n (window.visualViewport?.height || document.documentElement.clientHeight)\n ) {\n overflowedEdges.bottom = true;\n }\n\n if (targetBoundaries.left < 0) {\n overflowedEdges.left = true;\n }\n\n return overflowedEdges;\n}\n", "export enum Positions {\n top = 'top',\n bottom = 'bottom',\n left = 'left',\n right = 'right',\n topLeft = 'top-left',\n topRight = 'top-right',\n bottomLeft = 'bottom-left',\n bottomRight = 'bottom-right',\n}\n\ntype CardinalPosition =\n | Positions.top\n | Positions.bottom\n | Positions.left\n | Positions.right;\n\nconst opposite = {\n [Positions.top]: Positions.bottom,\n [Positions.bottom]: Positions.top,\n [Positions.left]: Positions.right,\n [Positions.right]: Positions.left,\n};\n\nexport function flipPosition(\n startingPosition: Positions,\n targetSide: CardinalPosition,\n): Positions {\n const newPosition = startingPosition.replace(\n opposite[targetSide],\n targetSide,\n ) as Positions;\n\n // If new side isn't in the result (wasn't flipped), add it\n // Can assume new position is cardinal or it would contain `side` at this point\n if (!newPosition.includes(targetSide)) {\n return combineSides(targetSide, newPosition as CardinalPosition);\n }\n\n return newPosition;\n}\n\nexport function combineSides(sideA: CardinalPosition, sideB: CardinalPosition) {\n if (sideA === sideB || opposite[sideA] === sideB) {\n return sideA;\n }\n\n return sideA === Positions.top || sideA === Positions.bottom\n ? (`${sideA}-${sideB}` as Positions)\n : (`${sideB}-${sideA}` as Positions);\n}\n", "import { Controller } from '@hotwired/stimulus';\nimport getOverflowedEdges from '../../utilities/edge-detection';\nimport { afterNextRender } from '../../utilities/timing';\nimport { Positions, flipPosition } from '../../utilities/position';\nimport { getFocusableElements } from '@/global/scripts/utilities/focus';\n\nconst toolTipTriggerEvents = [\n 'mouseover',\n 'focusin',\n] as (keyof HTMLElementEventMap)[];\nconst toolTipDismissEvents = [\n 'mouseleave',\n 'focusout',\n] as (keyof HTMLElementEventMap)[];\n\nconst dialogTriggerEvents = ['click'] as (keyof HTMLElementEventMap)[];\n\nexport default class extends Controller {\n static readonly classes = [...Object.keys(Positions), 'hidden'];\n static readonly targets = ['trigger', 'tooltip'];\n static readonly values = {\n position: String,\n };\n\n declare hiddenClasses: string[];\n declare leftClasses: string[];\n declare rightClasses: string[];\n declare bottomClasses: string[];\n declare topClasses: string[];\n declare topLeftClasses: string[];\n declare topRightClasses: string[];\n declare bottomLeftClasses: string[];\n declare bottomRightClasses: string[];\n declare defaultClasses: string[];\n declare triggerTarget: HTMLElement;\n declare tooltipTarget: HTMLElement;\n declare positionValue: Positions;\n\n private isDialogRole = false;\n private isShown = false;\n\n initialize() {\n super.initialize();\n\n this.hide();\n this.isDialogRole = this.tooltipTarget.role == 'dialog';\n this.tooltipTarget.classList.add(\n ...this.getPositionClasses(this.positionValue),\n );\n\n if (this.isDialogRole) {\n this.makeDialog();\n } else {\n for (const eventType of toolTipTriggerEvents) {\n this.element.addEventListener(eventType, this.show);\n }\n\n for (const eventType of toolTipDismissEvents) {\n this.element.addEventListener(eventType, this.hide);\n }\n }\n\n afterNextRender(this.adjustAndApplyPosition);\n }\n\n get disabled() {\n if (this.isDialogRole) {\n return (this.triggerTarget as HTMLButtonElement).disabled;\n }\n\n return this.triggerTarget.getAttribute('tabindex') !== '0';\n }\n\n set disabled(disabled: boolean) {\n if (this.isDialogRole) {\n (this.triggerTarget as HTMLButtonElement).disabled = disabled;\n } else if (disabled) {\n this.triggerTarget.removeAttribute('tabindex');\n } else {\n this.triggerTarget.setAttribute('tabindex', '0');\n }\n }\n\n disable() {\n this.disabled = true;\n }\n\n enable() {\n this.disabled = false;\n }\n\n hide = () => {\n this.isShown = false;\n this.tooltipTarget.classList.add(...this.hiddenClasses);\n };\n\n show = () => {\n if (this.disabled) return false;\n\n this.isShown = true;\n afterNextRender(() => {\n this.tooltipTarget.classList.remove(...this.hiddenClasses);\n this.tooltipTarget.classList.add(\n ...this.getPositionClasses(this.positionValue),\n );\n\n afterNextRender(this.adjustAndApplyPosition);\n });\n };\n\n private adjustAndApplyPosition = () => {\n const oldPosition = this.positionValue;\n this.adjustPosition();\n this.tooltipTarget.classList.remove(\n ...this.getPositionClasses(oldPosition),\n );\n this.tooltipTarget.classList.add(\n ...this.getPositionClasses(this.positionValue),\n );\n };\n\n private getPositionClasses(position: Positions): string[] {\n let indexOfClass = Object.values(Positions).indexOf(position);\n indexOfClass = indexOfClass === -1 ? 0 : indexOfClass;\n const key = Object.keys(Positions)[indexOfClass];\n const classKey = `${key}Classes` as keyof typeof this;\n return this[classKey] as string[];\n }\n\n private adjustPosition() {\n const overflowedEdges = getOverflowedEdges(this.tooltipTarget);\n\n if (overflowedEdges.top) {\n this.positionValue = flipPosition(this.positionValue, Positions.bottom);\n } else if (overflowedEdges.bottom) {\n this.positionValue = flipPosition(this.positionValue, Positions.top);\n }\n\n if (overflowedEdges.right) {\n this.positionValue = flipPosition(this.positionValue, Positions.left);\n } else if (overflowedEdges.left) {\n this.positionValue = flipPosition(this.positionValue, Positions.right);\n }\n }\n\n private makeDialog() {\n const focusable = getFocusableElements(this.tooltipTarget);\n for (const eventType of dialogTriggerEvents) {\n this.triggerTarget.addEventListener(eventType, () => {\n if (this.isShown) {\n this.hide();\n this.triggerTarget.focus();\n this.triggerTarget.ariaExpanded = 'false';\n } else {\n this.show();\n this.triggerTarget.ariaExpanded = 'true';\n\n afterNextRender(() => {\n if (focusable.length > 0) {\n focusable[0].focus();\n }\n });\n }\n });\n }\n }\n}\n", "import { Controller } from '@hotwired/stimulus';\n\nexport default class extends Controller {\n static readonly targets = ['input'];\n static readonly values = {\n maxChars: Number,\n };\n\n declare inputTarget: HTMLInputElement;\n declare readonly maxCharsValue: number;\n\n onChange() {\n this.inputTarget.value = this.inputTarget.value.replaceAll(/\\D/g, '');\n if (this.inputTarget.value.length >= this.maxCharsValue) {\n this.submit();\n }\n }\n\n private submit() {\n // ENABLE THIS ONCE WE HAVE THE COMPLETE MAP, check submit URL on the form\n //this.inputTarget.readOnly = true;\n //(this.element as HTMLFormElement).requestSubmit();\n }\n}\n", "/*!\nTurbo 8.0.10\nCopyright \u00A9 2024 37signals LLC\n */\n/**\n * The MIT License (MIT)\n *\n * Copyright (c) 2019 Javan Makhmali\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in\n * all copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n * THE SOFTWARE.\n */\n\n(function (prototype) {\n if (typeof prototype.requestSubmit == \"function\") return\n\n prototype.requestSubmit = function (submitter) {\n if (submitter) {\n validateSubmitter(submitter, this);\n submitter.click();\n } else {\n submitter = document.createElement(\"input\");\n submitter.type = \"submit\";\n submitter.hidden = true;\n this.appendChild(submitter);\n submitter.click();\n this.removeChild(submitter);\n }\n };\n\n function validateSubmitter(submitter, form) {\n submitter instanceof HTMLElement || raise(TypeError, \"parameter 1 is not of type 'HTMLElement'\");\n submitter.type == \"submit\" || raise(TypeError, \"The specified element is not a submit button\");\n submitter.form == form ||\n raise(DOMException, \"The specified element is not owned by this form element\", \"NotFoundError\");\n }\n\n function raise(errorConstructor, message, name) {\n throw new errorConstructor(\"Failed to execute 'requestSubmit' on 'HTMLFormElement': \" + message + \".\", name)\n }\n})(HTMLFormElement.prototype);\n\nconst submittersByForm = new WeakMap();\n\nfunction findSubmitterFromClickTarget(target) {\n const element = target instanceof Element ? target : target instanceof Node ? target.parentElement : null;\n const candidate = element ? element.closest(\"input, button\") : null;\n return candidate?.type == \"submit\" ? candidate : null\n}\n\nfunction clickCaptured(event) {\n const submitter = findSubmitterFromClickTarget(event.target);\n\n if (submitter && submitter.form) {\n submittersByForm.set(submitter.form, submitter);\n }\n}\n\n(function () {\n if (\"submitter\" in Event.prototype) return\n\n let prototype = window.Event.prototype;\n // Certain versions of Safari 15 have a bug where they won't\n // populate the submitter. This hurts TurboDrive's enable/disable detection.\n // See https://bugs.webkit.org/show_bug.cgi?id=229660\n if (\"SubmitEvent\" in window) {\n const prototypeOfSubmitEvent = window.SubmitEvent.prototype;\n\n if (/Apple Computer/.test(navigator.vendor) && !(\"submitter\" in prototypeOfSubmitEvent)) {\n prototype = prototypeOfSubmitEvent;\n } else {\n return // polyfill not needed\n }\n }\n\n addEventListener(\"click\", clickCaptured, true);\n\n Object.defineProperty(prototype, \"submitter\", {\n get() {\n if (this.type == \"submit\" && this.target instanceof HTMLFormElement) {\n return submittersByForm.get(this.target)\n }\n }\n });\n})();\n\nconst FrameLoadingStyle = {\n eager: \"eager\",\n lazy: \"lazy\"\n};\n\n/**\n * Contains a fragment of HTML which is updated based on navigation within\n * it (e.g. via links or form submissions).\n *\n * @customElement turbo-frame\n * @example\n * \n * \n * Show all expanded messages in this frame.\n * \n *\n *
\n * Show response from this form within this frame.\n *
\n * \n */\nclass FrameElement extends HTMLElement {\n static delegateConstructor = undefined\n\n loaded = Promise.resolve()\n\n static get observedAttributes() {\n return [\"disabled\", \"loading\", \"src\"]\n }\n\n constructor() {\n super();\n this.delegate = new FrameElement.delegateConstructor(this);\n }\n\n connectedCallback() {\n this.delegate.connect();\n }\n\n disconnectedCallback() {\n this.delegate.disconnect();\n }\n\n reload() {\n return this.delegate.sourceURLReloaded()\n }\n\n attributeChangedCallback(name) {\n if (name == \"loading\") {\n this.delegate.loadingStyleChanged();\n } else if (name == \"src\") {\n this.delegate.sourceURLChanged();\n } else if (name == \"disabled\") {\n this.delegate.disabledChanged();\n }\n }\n\n /**\n * Gets the URL to lazily load source HTML from\n */\n get src() {\n return this.getAttribute(\"src\")\n }\n\n /**\n * Sets the URL to lazily load source HTML from\n */\n set src(value) {\n if (value) {\n this.setAttribute(\"src\", value);\n } else {\n this.removeAttribute(\"src\");\n }\n }\n\n /**\n * Gets the refresh mode for the frame.\n */\n get refresh() {\n return this.getAttribute(\"refresh\")\n }\n\n /**\n * Sets the refresh mode for the frame.\n */\n set refresh(value) {\n if (value) {\n this.setAttribute(\"refresh\", value);\n } else {\n this.removeAttribute(\"refresh\");\n }\n }\n\n get shouldReloadWithMorph() {\n return this.src && this.refresh === \"morph\"\n }\n\n /**\n * Determines if the element is loading\n */\n get loading() {\n return frameLoadingStyleFromString(this.getAttribute(\"loading\") || \"\")\n }\n\n /**\n * Sets the value of if the element is loading\n */\n set loading(value) {\n if (value) {\n this.setAttribute(\"loading\", value);\n } else {\n this.removeAttribute(\"loading\");\n }\n }\n\n /**\n * Gets the disabled state of the frame.\n *\n * If disabled, no requests will be intercepted by the frame.\n */\n get disabled() {\n return this.hasAttribute(\"disabled\")\n }\n\n /**\n * Sets the disabled state of the frame.\n *\n * If disabled, no requests will be intercepted by the frame.\n */\n set disabled(value) {\n if (value) {\n this.setAttribute(\"disabled\", \"\");\n } else {\n this.removeAttribute(\"disabled\");\n }\n }\n\n /**\n * Gets the autoscroll state of the frame.\n *\n * If true, the frame will be scrolled into view automatically on update.\n */\n get autoscroll() {\n return this.hasAttribute(\"autoscroll\")\n }\n\n /**\n * Sets the autoscroll state of the frame.\n *\n * If true, the frame will be scrolled into view automatically on update.\n */\n set autoscroll(value) {\n if (value) {\n this.setAttribute(\"autoscroll\", \"\");\n } else {\n this.removeAttribute(\"autoscroll\");\n }\n }\n\n /**\n * Determines if the element has finished loading\n */\n get complete() {\n return !this.delegate.isLoading\n }\n\n /**\n * Gets the active state of the frame.\n *\n * If inactive, source changes will not be observed.\n */\n get isActive() {\n return this.ownerDocument === document && !this.isPreview\n }\n\n /**\n * Sets the active state of the frame.\n *\n * If inactive, source changes will not be observed.\n */\n get isPreview() {\n return this.ownerDocument?.documentElement?.hasAttribute(\"data-turbo-preview\")\n }\n}\n\nfunction frameLoadingStyleFromString(style) {\n switch (style.toLowerCase()) {\n case \"lazy\":\n return FrameLoadingStyle.lazy\n default:\n return FrameLoadingStyle.eager\n }\n}\n\nconst drive = {\n enabled: true,\n progressBarDelay: 500,\n unvisitableExtensions: new Set(\n [\n \".7z\", \".aac\", \".apk\", \".avi\", \".bmp\", \".bz2\", \".css\", \".csv\", \".deb\", \".dmg\", \".doc\",\n \".docx\", \".exe\", \".gif\", \".gz\", \".heic\", \".heif\", \".ico\", \".iso\", \".jpeg\", \".jpg\",\n \".js\", \".json\", \".m4a\", \".mkv\", \".mov\", \".mp3\", \".mp4\", \".mpeg\", \".mpg\", \".msi\",\n \".ogg\", \".ogv\", \".pdf\", \".pkg\", \".png\", \".ppt\", \".pptx\", \".rar\", \".rtf\",\n \".svg\", \".tar\", \".tif\", \".tiff\", \".txt\", \".wav\", \".webm\", \".webp\", \".wma\", \".wmv\",\n \".xls\", \".xlsx\", \".xml\", \".zip\"\n ]\n )\n};\n\nfunction activateScriptElement(element) {\n if (element.getAttribute(\"data-turbo-eval\") == \"false\") {\n return element\n } else {\n const createdScriptElement = document.createElement(\"script\");\n const cspNonce = getMetaContent(\"csp-nonce\");\n if (cspNonce) {\n createdScriptElement.nonce = cspNonce;\n }\n createdScriptElement.textContent = element.textContent;\n createdScriptElement.async = false;\n copyElementAttributes(createdScriptElement, element);\n return createdScriptElement\n }\n}\n\nfunction copyElementAttributes(destinationElement, sourceElement) {\n for (const { name, value } of sourceElement.attributes) {\n destinationElement.setAttribute(name, value);\n }\n}\n\nfunction createDocumentFragment(html) {\n const template = document.createElement(\"template\");\n template.innerHTML = html;\n return template.content\n}\n\nfunction dispatch(eventName, { target, cancelable, detail } = {}) {\n const event = new CustomEvent(eventName, {\n cancelable,\n bubbles: true,\n composed: true,\n detail\n });\n\n if (target && target.isConnected) {\n target.dispatchEvent(event);\n } else {\n document.documentElement.dispatchEvent(event);\n }\n\n return event\n}\n\nfunction cancelEvent(event) {\n event.preventDefault();\n event.stopImmediatePropagation();\n}\n\nfunction nextRepaint() {\n if (document.visibilityState === \"hidden\") {\n return nextEventLoopTick()\n } else {\n return nextAnimationFrame()\n }\n}\n\nfunction nextAnimationFrame() {\n return new Promise((resolve) => requestAnimationFrame(() => resolve()))\n}\n\nfunction nextEventLoopTick() {\n return new Promise((resolve) => setTimeout(() => resolve(), 0))\n}\n\nfunction nextMicrotask() {\n return Promise.resolve()\n}\n\nfunction parseHTMLDocument(html = \"\") {\n return new DOMParser().parseFromString(html, \"text/html\")\n}\n\nfunction unindent(strings, ...values) {\n const lines = interpolate(strings, values).replace(/^\\n/, \"\").split(\"\\n\");\n const match = lines[0].match(/^\\s+/);\n const indent = match ? match[0].length : 0;\n return lines.map((line) => line.slice(indent)).join(\"\\n\")\n}\n\nfunction interpolate(strings, values) {\n return strings.reduce((result, string, i) => {\n const value = values[i] == undefined ? \"\" : values[i];\n return result + string + value\n }, \"\")\n}\n\nfunction uuid() {\n return Array.from({ length: 36 })\n .map((_, i) => {\n if (i == 8 || i == 13 || i == 18 || i == 23) {\n return \"-\"\n } else if (i == 14) {\n return \"4\"\n } else if (i == 19) {\n return (Math.floor(Math.random() * 4) + 8).toString(16)\n } else {\n return Math.floor(Math.random() * 15).toString(16)\n }\n })\n .join(\"\")\n}\n\nfunction getAttribute(attributeName, ...elements) {\n for (const value of elements.map((element) => element?.getAttribute(attributeName))) {\n if (typeof value == \"string\") return value\n }\n\n return null\n}\n\nfunction hasAttribute(attributeName, ...elements) {\n return elements.some((element) => element && element.hasAttribute(attributeName))\n}\n\nfunction markAsBusy(...elements) {\n for (const element of elements) {\n if (element.localName == \"turbo-frame\") {\n element.setAttribute(\"busy\", \"\");\n }\n element.setAttribute(\"aria-busy\", \"true\");\n }\n}\n\nfunction clearBusyState(...elements) {\n for (const element of elements) {\n if (element.localName == \"turbo-frame\") {\n element.removeAttribute(\"busy\");\n }\n\n element.removeAttribute(\"aria-busy\");\n }\n}\n\nfunction waitForLoad(element, timeoutInMilliseconds = 2000) {\n return new Promise((resolve) => {\n const onComplete = () => {\n element.removeEventListener(\"error\", onComplete);\n element.removeEventListener(\"load\", onComplete);\n resolve();\n };\n\n element.addEventListener(\"load\", onComplete, { once: true });\n element.addEventListener(\"error\", onComplete, { once: true });\n setTimeout(resolve, timeoutInMilliseconds);\n })\n}\n\nfunction getHistoryMethodForAction(action) {\n switch (action) {\n case \"replace\":\n return history.replaceState\n case \"advance\":\n case \"restore\":\n return history.pushState\n }\n}\n\nfunction isAction(action) {\n return action == \"advance\" || action == \"replace\" || action == \"restore\"\n}\n\nfunction getVisitAction(...elements) {\n const action = getAttribute(\"data-turbo-action\", ...elements);\n\n return isAction(action) ? action : null\n}\n\nfunction getMetaElement(name) {\n return document.querySelector(`meta[name=\"${name}\"]`)\n}\n\nfunction getMetaContent(name) {\n const element = getMetaElement(name);\n return element && element.content\n}\n\nfunction setMetaContent(name, content) {\n let element = getMetaElement(name);\n\n if (!element) {\n element = document.createElement(\"meta\");\n element.setAttribute(\"name\", name);\n\n document.head.appendChild(element);\n }\n\n element.setAttribute(\"content\", content);\n\n return element\n}\n\nfunction findClosestRecursively(element, selector) {\n if (element instanceof Element) {\n return (\n element.closest(selector) || findClosestRecursively(element.assignedSlot || element.getRootNode()?.host, selector)\n )\n }\n}\n\nfunction elementIsFocusable(element) {\n const inertDisabledOrHidden = \"[inert], :disabled, [hidden], details:not([open]), dialog:not([open])\";\n\n return !!element && element.closest(inertDisabledOrHidden) == null && typeof element.focus == \"function\"\n}\n\nfunction queryAutofocusableElement(elementOrDocumentFragment) {\n return Array.from(elementOrDocumentFragment.querySelectorAll(\"[autofocus]\")).find(elementIsFocusable)\n}\n\nasync function around(callback, reader) {\n const before = reader();\n\n callback();\n\n await nextAnimationFrame();\n\n const after = reader();\n\n return [before, after]\n}\n\nfunction doesNotTargetIFrame(name) {\n if (name === \"_blank\") {\n return false\n } else if (name) {\n for (const element of document.getElementsByName(name)) {\n if (element instanceof HTMLIFrameElement) return false\n }\n\n return true\n } else {\n return true\n }\n}\n\nfunction findLinkFromClickTarget(target) {\n return findClosestRecursively(target, \"a[href]:not([target^=_]):not([download])\")\n}\n\nfunction getLocationForLink(link) {\n return expandURL(link.getAttribute(\"href\") || \"\")\n}\n\nfunction debounce(fn, delay) {\n let timeoutId = null;\n\n return (...args) => {\n const callback = () => fn.apply(this, args);\n clearTimeout(timeoutId);\n timeoutId = setTimeout(callback, delay);\n }\n}\n\nconst submitter = {\n \"aria-disabled\": {\n beforeSubmit: submitter => {\n submitter.setAttribute(\"aria-disabled\", \"true\");\n submitter.addEventListener(\"click\", cancelEvent);\n },\n\n afterSubmit: submitter => {\n submitter.removeAttribute(\"aria-disabled\");\n submitter.removeEventListener(\"click\", cancelEvent);\n }\n },\n\n \"disabled\": {\n beforeSubmit: submitter => submitter.disabled = true,\n afterSubmit: submitter => submitter.disabled = false\n }\n};\n\nclass Config {\n #submitter = null\n\n constructor(config) {\n Object.assign(this, config);\n }\n\n get submitter() {\n return this.#submitter\n }\n\n set submitter(value) {\n this.#submitter = submitter[value] || value;\n }\n}\n\nconst forms = new Config({\n mode: \"on\",\n submitter: \"disabled\"\n});\n\nconst config = {\n drive,\n forms\n};\n\nfunction expandURL(locatable) {\n return new URL(locatable.toString(), document.baseURI)\n}\n\nfunction getAnchor(url) {\n let anchorMatch;\n if (url.hash) {\n return url.hash.slice(1)\n // eslint-disable-next-line no-cond-assign\n } else if ((anchorMatch = url.href.match(/#(.*)$/))) {\n return anchorMatch[1]\n }\n}\n\nfunction getAction$1(form, submitter) {\n const action = submitter?.getAttribute(\"formaction\") || form.getAttribute(\"action\") || form.action;\n\n return expandURL(action)\n}\n\nfunction getExtension(url) {\n return (getLastPathComponent(url).match(/\\.[^.]*$/) || [])[0] || \"\"\n}\n\nfunction isPrefixedBy(baseURL, url) {\n const prefix = getPrefix(url);\n return baseURL.href === expandURL(prefix).href || baseURL.href.startsWith(prefix)\n}\n\nfunction locationIsVisitable(location, rootLocation) {\n return isPrefixedBy(location, rootLocation) && !config.drive.unvisitableExtensions.has(getExtension(location))\n}\n\nfunction getRequestURL(url) {\n const anchor = getAnchor(url);\n return anchor != null ? url.href.slice(0, -(anchor.length + 1)) : url.href\n}\n\nfunction toCacheKey(url) {\n return getRequestURL(url)\n}\n\nfunction urlsAreEqual(left, right) {\n return expandURL(left).href == expandURL(right).href\n}\n\nfunction getPathComponents(url) {\n return url.pathname.split(\"/\").slice(1)\n}\n\nfunction getLastPathComponent(url) {\n return getPathComponents(url).slice(-1)[0]\n}\n\nfunction getPrefix(url) {\n return addTrailingSlash(url.origin + url.pathname)\n}\n\nfunction addTrailingSlash(value) {\n return value.endsWith(\"/\") ? value : value + \"/\"\n}\n\nclass FetchResponse {\n constructor(response) {\n this.response = response;\n }\n\n get succeeded() {\n return this.response.ok\n }\n\n get failed() {\n return !this.succeeded\n }\n\n get clientError() {\n return this.statusCode >= 400 && this.statusCode <= 499\n }\n\n get serverError() {\n return this.statusCode >= 500 && this.statusCode <= 599\n }\n\n get redirected() {\n return this.response.redirected\n }\n\n get location() {\n return expandURL(this.response.url)\n }\n\n get isHTML() {\n return this.contentType && this.contentType.match(/^(?:text\\/([^\\s;,]+\\b)?html|application\\/xhtml\\+xml)\\b/)\n }\n\n get statusCode() {\n return this.response.status\n }\n\n get contentType() {\n return this.header(\"Content-Type\")\n }\n\n get responseText() {\n return this.response.clone().text()\n }\n\n get responseHTML() {\n if (this.isHTML) {\n return this.response.clone().text()\n } else {\n return Promise.resolve(undefined)\n }\n }\n\n header(name) {\n return this.response.headers.get(name)\n }\n}\n\nclass LimitedSet extends Set {\n constructor(maxSize) {\n super();\n this.maxSize = maxSize;\n }\n\n add(value) {\n if (this.size >= this.maxSize) {\n const iterator = this.values();\n const oldestValue = iterator.next().value;\n this.delete(oldestValue);\n }\n super.add(value);\n }\n}\n\nconst recentRequests = new LimitedSet(20);\n\nconst nativeFetch = window.fetch;\n\nfunction fetchWithTurboHeaders(url, options = {}) {\n const modifiedHeaders = new Headers(options.headers || {});\n const requestUID = uuid();\n recentRequests.add(requestUID);\n modifiedHeaders.append(\"X-Turbo-Request-Id\", requestUID);\n\n return nativeFetch(url, {\n ...options,\n headers: modifiedHeaders\n })\n}\n\nfunction fetchMethodFromString(method) {\n switch (method.toLowerCase()) {\n case \"get\":\n return FetchMethod.get\n case \"post\":\n return FetchMethod.post\n case \"put\":\n return FetchMethod.put\n case \"patch\":\n return FetchMethod.patch\n case \"delete\":\n return FetchMethod.delete\n }\n}\n\nconst FetchMethod = {\n get: \"get\",\n post: \"post\",\n put: \"put\",\n patch: \"patch\",\n delete: \"delete\"\n};\n\nfunction fetchEnctypeFromString(encoding) {\n switch (encoding.toLowerCase()) {\n case FetchEnctype.multipart:\n return FetchEnctype.multipart\n case FetchEnctype.plain:\n return FetchEnctype.plain\n default:\n return FetchEnctype.urlEncoded\n }\n}\n\nconst FetchEnctype = {\n urlEncoded: \"application/x-www-form-urlencoded\",\n multipart: \"multipart/form-data\",\n plain: \"text/plain\"\n};\n\nclass FetchRequest {\n abortController = new AbortController()\n #resolveRequestPromise = (_value) => {}\n\n constructor(delegate, method, location, requestBody = new URLSearchParams(), target = null, enctype = FetchEnctype.urlEncoded) {\n const [url, body] = buildResourceAndBody(expandURL(location), method, requestBody, enctype);\n\n this.delegate = delegate;\n this.url = url;\n this.target = target;\n this.fetchOptions = {\n credentials: \"same-origin\",\n redirect: \"follow\",\n method: method.toUpperCase(),\n headers: { ...this.defaultHeaders },\n body: body,\n signal: this.abortSignal,\n referrer: this.delegate.referrer?.href\n };\n this.enctype = enctype;\n }\n\n get method() {\n return this.fetchOptions.method\n }\n\n set method(value) {\n const fetchBody = this.isSafe ? this.url.searchParams : this.fetchOptions.body || new FormData();\n const fetchMethod = fetchMethodFromString(value) || FetchMethod.get;\n\n this.url.search = \"\";\n\n const [url, body] = buildResourceAndBody(this.url, fetchMethod, fetchBody, this.enctype);\n\n this.url = url;\n this.fetchOptions.body = body;\n this.fetchOptions.method = fetchMethod.toUpperCase();\n }\n\n get headers() {\n return this.fetchOptions.headers\n }\n\n set headers(value) {\n this.fetchOptions.headers = value;\n }\n\n get body() {\n if (this.isSafe) {\n return this.url.searchParams\n } else {\n return this.fetchOptions.body\n }\n }\n\n set body(value) {\n this.fetchOptions.body = value;\n }\n\n get location() {\n return this.url\n }\n\n get params() {\n return this.url.searchParams\n }\n\n get entries() {\n return this.body ? Array.from(this.body.entries()) : []\n }\n\n cancel() {\n this.abortController.abort();\n }\n\n async perform() {\n const { fetchOptions } = this;\n this.delegate.prepareRequest(this);\n const event = await this.#allowRequestToBeIntercepted(fetchOptions);\n try {\n this.delegate.requestStarted(this);\n\n if (event.detail.fetchRequest) {\n this.response = event.detail.fetchRequest.response;\n } else {\n this.response = fetchWithTurboHeaders(this.url.href, fetchOptions);\n }\n\n const response = await this.response;\n return await this.receive(response)\n } catch (error) {\n if (error.name !== \"AbortError\") {\n if (this.#willDelegateErrorHandling(error)) {\n this.delegate.requestErrored(this, error);\n }\n throw error\n }\n } finally {\n this.delegate.requestFinished(this);\n }\n }\n\n async receive(response) {\n const fetchResponse = new FetchResponse(response);\n const event = dispatch(\"turbo:before-fetch-response\", {\n cancelable: true,\n detail: { fetchResponse },\n target: this.target\n });\n if (event.defaultPrevented) {\n this.delegate.requestPreventedHandlingResponse(this, fetchResponse);\n } else if (fetchResponse.succeeded) {\n this.delegate.requestSucceededWithResponse(this, fetchResponse);\n } else {\n this.delegate.requestFailedWithResponse(this, fetchResponse);\n }\n return fetchResponse\n }\n\n get defaultHeaders() {\n return {\n Accept: \"text/html, application/xhtml+xml\"\n }\n }\n\n get isSafe() {\n return isSafe(this.method)\n }\n\n get abortSignal() {\n return this.abortController.signal\n }\n\n acceptResponseType(mimeType) {\n this.headers[\"Accept\"] = [mimeType, this.headers[\"Accept\"]].join(\", \");\n }\n\n async #allowRequestToBeIntercepted(fetchOptions) {\n const requestInterception = new Promise((resolve) => (this.#resolveRequestPromise = resolve));\n const event = dispatch(\"turbo:before-fetch-request\", {\n cancelable: true,\n detail: {\n fetchOptions,\n url: this.url,\n resume: this.#resolveRequestPromise\n },\n target: this.target\n });\n this.url = event.detail.url;\n if (event.defaultPrevented) await requestInterception;\n\n return event\n }\n\n #willDelegateErrorHandling(error) {\n const event = dispatch(\"turbo:fetch-request-error\", {\n target: this.target,\n cancelable: true,\n detail: { request: this, error: error }\n });\n\n return !event.defaultPrevented\n }\n}\n\nfunction isSafe(fetchMethod) {\n return fetchMethodFromString(fetchMethod) == FetchMethod.get\n}\n\nfunction buildResourceAndBody(resource, method, requestBody, enctype) {\n const searchParams =\n Array.from(requestBody).length > 0 ? new URLSearchParams(entriesExcludingFiles(requestBody)) : resource.searchParams;\n\n if (isSafe(method)) {\n return [mergeIntoURLSearchParams(resource, searchParams), null]\n } else if (enctype == FetchEnctype.urlEncoded) {\n return [resource, searchParams]\n } else {\n return [resource, requestBody]\n }\n}\n\nfunction entriesExcludingFiles(requestBody) {\n const entries = [];\n\n for (const [name, value] of requestBody) {\n if (value instanceof File) continue\n else entries.push([name, value]);\n }\n\n return entries\n}\n\nfunction mergeIntoURLSearchParams(url, requestBody) {\n const searchParams = new URLSearchParams(entriesExcludingFiles(requestBody));\n\n url.search = searchParams.toString();\n\n return url\n}\n\nclass AppearanceObserver {\n started = false\n\n constructor(delegate, element) {\n this.delegate = delegate;\n this.element = element;\n this.intersectionObserver = new IntersectionObserver(this.intersect);\n }\n\n start() {\n if (!this.started) {\n this.started = true;\n this.intersectionObserver.observe(this.element);\n }\n }\n\n stop() {\n if (this.started) {\n this.started = false;\n this.intersectionObserver.unobserve(this.element);\n }\n }\n\n intersect = (entries) => {\n const lastEntry = entries.slice(-1)[0];\n if (lastEntry?.isIntersecting) {\n this.delegate.elementAppearedInViewport(this.element);\n }\n }\n}\n\nclass StreamMessage {\n static contentType = \"text/vnd.turbo-stream.html\"\n\n static wrap(message) {\n if (typeof message == \"string\") {\n return new this(createDocumentFragment(message))\n } else {\n return message\n }\n }\n\n constructor(fragment) {\n this.fragment = importStreamElements(fragment);\n }\n}\n\nfunction importStreamElements(fragment) {\n for (const element of fragment.querySelectorAll(\"turbo-stream\")) {\n const streamElement = document.importNode(element, true);\n\n for (const inertScriptElement of streamElement.templateElement.content.querySelectorAll(\"script\")) {\n inertScriptElement.replaceWith(activateScriptElement(inertScriptElement));\n }\n\n element.replaceWith(streamElement);\n }\n\n return fragment\n}\n\nconst PREFETCH_DELAY = 100;\n\nclass PrefetchCache {\n #prefetchTimeout = null\n #prefetched = null\n\n get(url) {\n if (this.#prefetched && this.#prefetched.url === url && this.#prefetched.expire > Date.now()) {\n return this.#prefetched.request\n }\n }\n\n setLater(url, request, ttl) {\n this.clear();\n\n this.#prefetchTimeout = setTimeout(() => {\n request.perform();\n this.set(url, request, ttl);\n this.#prefetchTimeout = null;\n }, PREFETCH_DELAY);\n }\n\n set(url, request, ttl) {\n this.#prefetched = { url, request, expire: new Date(new Date().getTime() + ttl) };\n }\n\n clear() {\n if (this.#prefetchTimeout) clearTimeout(this.#prefetchTimeout);\n this.#prefetched = null;\n }\n}\n\nconst cacheTtl = 10 * 1000;\nconst prefetchCache = new PrefetchCache();\n\nconst FormSubmissionState = {\n initialized: \"initialized\",\n requesting: \"requesting\",\n waiting: \"waiting\",\n receiving: \"receiving\",\n stopping: \"stopping\",\n stopped: \"stopped\"\n};\n\nclass FormSubmission {\n state = FormSubmissionState.initialized\n\n static confirmMethod(message) {\n return Promise.resolve(confirm(message))\n }\n\n constructor(delegate, formElement, submitter, mustRedirect = false) {\n const method = getMethod(formElement, submitter);\n const action = getAction(getFormAction(formElement, submitter), method);\n const body = buildFormData(formElement, submitter);\n const enctype = getEnctype(formElement, submitter);\n\n this.delegate = delegate;\n this.formElement = formElement;\n this.submitter = submitter;\n this.fetchRequest = new FetchRequest(this, method, action, body, formElement, enctype);\n this.mustRedirect = mustRedirect;\n }\n\n get method() {\n return this.fetchRequest.method\n }\n\n set method(value) {\n this.fetchRequest.method = value;\n }\n\n get action() {\n return this.fetchRequest.url.toString()\n }\n\n set action(value) {\n this.fetchRequest.url = expandURL(value);\n }\n\n get body() {\n return this.fetchRequest.body\n }\n\n get enctype() {\n return this.fetchRequest.enctype\n }\n\n get isSafe() {\n return this.fetchRequest.isSafe\n }\n\n get location() {\n return this.fetchRequest.url\n }\n\n // The submission process\n\n async start() {\n const { initialized, requesting } = FormSubmissionState;\n const confirmationMessage = getAttribute(\"data-turbo-confirm\", this.submitter, this.formElement);\n\n if (typeof confirmationMessage === \"string\") {\n const confirmMethod = typeof config.forms.confirm === \"function\" ?\n config.forms.confirm :\n FormSubmission.confirmMethod;\n\n const answer = await confirmMethod(confirmationMessage, this.formElement, this.submitter);\n if (!answer) {\n return\n }\n }\n\n if (this.state == initialized) {\n this.state = requesting;\n return this.fetchRequest.perform()\n }\n }\n\n stop() {\n const { stopping, stopped } = FormSubmissionState;\n if (this.state != stopping && this.state != stopped) {\n this.state = stopping;\n this.fetchRequest.cancel();\n return true\n }\n }\n\n // Fetch request delegate\n\n prepareRequest(request) {\n if (!request.isSafe) {\n const token = getCookieValue(getMetaContent(\"csrf-param\")) || getMetaContent(\"csrf-token\");\n if (token) {\n request.headers[\"X-CSRF-Token\"] = token;\n }\n }\n\n if (this.requestAcceptsTurboStreamResponse(request)) {\n request.acceptResponseType(StreamMessage.contentType);\n }\n }\n\n requestStarted(_request) {\n this.state = FormSubmissionState.waiting;\n if (this.submitter) config.forms.submitter.beforeSubmit(this.submitter);\n this.setSubmitsWith();\n markAsBusy(this.formElement);\n dispatch(\"turbo:submit-start\", {\n target: this.formElement,\n detail: { formSubmission: this }\n });\n this.delegate.formSubmissionStarted(this);\n }\n\n requestPreventedHandlingResponse(request, response) {\n prefetchCache.clear();\n\n this.result = { success: response.succeeded, fetchResponse: response };\n }\n\n requestSucceededWithResponse(request, response) {\n if (response.clientError || response.serverError) {\n this.delegate.formSubmissionFailedWithResponse(this, response);\n return\n }\n\n prefetchCache.clear();\n\n if (this.requestMustRedirect(request) && responseSucceededWithoutRedirect(response)) {\n const error = new Error(\"Form responses must redirect to another location\");\n this.delegate.formSubmissionErrored(this, error);\n } else {\n this.state = FormSubmissionState.receiving;\n this.result = { success: true, fetchResponse: response };\n this.delegate.formSubmissionSucceededWithResponse(this, response);\n }\n }\n\n requestFailedWithResponse(request, response) {\n this.result = { success: false, fetchResponse: response };\n this.delegate.formSubmissionFailedWithResponse(this, response);\n }\n\n requestErrored(request, error) {\n this.result = { success: false, error };\n this.delegate.formSubmissionErrored(this, error);\n }\n\n requestFinished(_request) {\n this.state = FormSubmissionState.stopped;\n if (this.submitter) config.forms.submitter.afterSubmit(this.submitter);\n this.resetSubmitterText();\n clearBusyState(this.formElement);\n dispatch(\"turbo:submit-end\", {\n target: this.formElement,\n detail: { formSubmission: this, ...this.result }\n });\n this.delegate.formSubmissionFinished(this);\n }\n\n // Private\n\n setSubmitsWith() {\n if (!this.submitter || !this.submitsWith) return\n\n if (this.submitter.matches(\"button\")) {\n this.originalSubmitText = this.submitter.innerHTML;\n this.submitter.innerHTML = this.submitsWith;\n } else if (this.submitter.matches(\"input\")) {\n const input = this.submitter;\n this.originalSubmitText = input.value;\n input.value = this.submitsWith;\n }\n }\n\n resetSubmitterText() {\n if (!this.submitter || !this.originalSubmitText) return\n\n if (this.submitter.matches(\"button\")) {\n this.submitter.innerHTML = this.originalSubmitText;\n } else if (this.submitter.matches(\"input\")) {\n const input = this.submitter;\n input.value = this.originalSubmitText;\n }\n }\n\n requestMustRedirect(request) {\n return !request.isSafe && this.mustRedirect\n }\n\n requestAcceptsTurboStreamResponse(request) {\n return !request.isSafe || hasAttribute(\"data-turbo-stream\", this.submitter, this.formElement)\n }\n\n get submitsWith() {\n return this.submitter?.getAttribute(\"data-turbo-submits-with\")\n }\n}\n\nfunction buildFormData(formElement, submitter) {\n const formData = new FormData(formElement);\n const name = submitter?.getAttribute(\"name\");\n const value = submitter?.getAttribute(\"value\");\n\n if (name) {\n formData.append(name, value || \"\");\n }\n\n return formData\n}\n\nfunction getCookieValue(cookieName) {\n if (cookieName != null) {\n const cookies = document.cookie ? document.cookie.split(\"; \") : [];\n const cookie = cookies.find((cookie) => cookie.startsWith(cookieName));\n if (cookie) {\n const value = cookie.split(\"=\").slice(1).join(\"=\");\n return value ? decodeURIComponent(value) : undefined\n }\n }\n}\n\nfunction responseSucceededWithoutRedirect(response) {\n return response.statusCode == 200 && !response.redirected\n}\n\nfunction getFormAction(formElement, submitter) {\n const formElementAction = typeof formElement.action === \"string\" ? formElement.action : null;\n\n if (submitter?.hasAttribute(\"formaction\")) {\n return submitter.getAttribute(\"formaction\") || \"\"\n } else {\n return formElement.getAttribute(\"action\") || formElementAction || \"\"\n }\n}\n\nfunction getAction(formAction, fetchMethod) {\n const action = expandURL(formAction);\n\n if (isSafe(fetchMethod)) {\n action.search = \"\";\n }\n\n return action\n}\n\nfunction getMethod(formElement, submitter) {\n const method = submitter?.getAttribute(\"formmethod\") || formElement.getAttribute(\"method\") || \"\";\n return fetchMethodFromString(method.toLowerCase()) || FetchMethod.get\n}\n\nfunction getEnctype(formElement, submitter) {\n return fetchEnctypeFromString(submitter?.getAttribute(\"formenctype\") || formElement.enctype)\n}\n\nclass Snapshot {\n constructor(element) {\n this.element = element;\n }\n\n get activeElement() {\n return this.element.ownerDocument.activeElement\n }\n\n get children() {\n return [...this.element.children]\n }\n\n hasAnchor(anchor) {\n return this.getElementForAnchor(anchor) != null\n }\n\n getElementForAnchor(anchor) {\n return anchor ? this.element.querySelector(`[id='${anchor}'], a[name='${anchor}']`) : null\n }\n\n get isConnected() {\n return this.element.isConnected\n }\n\n get firstAutofocusableElement() {\n return queryAutofocusableElement(this.element)\n }\n\n get permanentElements() {\n return queryPermanentElementsAll(this.element)\n }\n\n getPermanentElementById(id) {\n return getPermanentElementById(this.element, id)\n }\n\n getPermanentElementMapForSnapshot(snapshot) {\n const permanentElementMap = {};\n\n for (const currentPermanentElement of this.permanentElements) {\n const { id } = currentPermanentElement;\n const newPermanentElement = snapshot.getPermanentElementById(id);\n if (newPermanentElement) {\n permanentElementMap[id] = [currentPermanentElement, newPermanentElement];\n }\n }\n\n return permanentElementMap\n }\n}\n\nfunction getPermanentElementById(node, id) {\n return node.querySelector(`#${id}[data-turbo-permanent]`)\n}\n\nfunction queryPermanentElementsAll(node) {\n return node.querySelectorAll(\"[id][data-turbo-permanent]\")\n}\n\nclass FormSubmitObserver {\n started = false\n\n constructor(delegate, eventTarget) {\n this.delegate = delegate;\n this.eventTarget = eventTarget;\n }\n\n start() {\n if (!this.started) {\n this.eventTarget.addEventListener(\"submit\", this.submitCaptured, true);\n this.started = true;\n }\n }\n\n stop() {\n if (this.started) {\n this.eventTarget.removeEventListener(\"submit\", this.submitCaptured, true);\n this.started = false;\n }\n }\n\n submitCaptured = () => {\n this.eventTarget.removeEventListener(\"submit\", this.submitBubbled, false);\n this.eventTarget.addEventListener(\"submit\", this.submitBubbled, false);\n }\n\n submitBubbled = (event) => {\n if (!event.defaultPrevented) {\n const form = event.target instanceof HTMLFormElement ? event.target : undefined;\n const submitter = event.submitter || undefined;\n\n if (\n form &&\n submissionDoesNotDismissDialog(form, submitter) &&\n submissionDoesNotTargetIFrame(form, submitter) &&\n this.delegate.willSubmitForm(form, submitter)\n ) {\n event.preventDefault();\n event.stopImmediatePropagation();\n this.delegate.formSubmitted(form, submitter);\n }\n }\n }\n}\n\nfunction submissionDoesNotDismissDialog(form, submitter) {\n const method = submitter?.getAttribute(\"formmethod\") || form.getAttribute(\"method\");\n\n return method != \"dialog\"\n}\n\nfunction submissionDoesNotTargetIFrame(form, submitter) {\n const target = submitter?.getAttribute(\"formtarget\") || form.getAttribute(\"target\");\n\n return doesNotTargetIFrame(target)\n}\n\nclass View {\n #resolveRenderPromise = (_value) => {}\n #resolveInterceptionPromise = (_value) => {}\n\n constructor(delegate, element) {\n this.delegate = delegate;\n this.element = element;\n }\n\n // Scrolling\n\n scrollToAnchor(anchor) {\n const element = this.snapshot.getElementForAnchor(anchor);\n if (element) {\n this.scrollToElement(element);\n this.focusElement(element);\n } else {\n this.scrollToPosition({ x: 0, y: 0 });\n }\n }\n\n scrollToAnchorFromLocation(location) {\n this.scrollToAnchor(getAnchor(location));\n }\n\n scrollToElement(element) {\n element.scrollIntoView();\n }\n\n focusElement(element) {\n if (element instanceof HTMLElement) {\n if (element.hasAttribute(\"tabindex\")) {\n element.focus();\n } else {\n element.setAttribute(\"tabindex\", \"-1\");\n element.focus();\n element.removeAttribute(\"tabindex\");\n }\n }\n }\n\n scrollToPosition({ x, y }) {\n this.scrollRoot.scrollTo(x, y);\n }\n\n scrollToTop() {\n this.scrollToPosition({ x: 0, y: 0 });\n }\n\n get scrollRoot() {\n return window\n }\n\n // Rendering\n\n async render(renderer) {\n const { isPreview, shouldRender, willRender, newSnapshot: snapshot } = renderer;\n\n // A workaround to ignore tracked element mismatch reloads when performing\n // a promoted Visit from a frame navigation\n const shouldInvalidate = willRender;\n\n if (shouldRender) {\n try {\n this.renderPromise = new Promise((resolve) => (this.#resolveRenderPromise = resolve));\n this.renderer = renderer;\n await this.prepareToRenderSnapshot(renderer);\n\n const renderInterception = new Promise((resolve) => (this.#resolveInterceptionPromise = resolve));\n const options = { resume: this.#resolveInterceptionPromise, render: this.renderer.renderElement, renderMethod: this.renderer.renderMethod };\n const immediateRender = this.delegate.allowsImmediateRender(snapshot, options);\n if (!immediateRender) await renderInterception;\n\n await this.renderSnapshot(renderer);\n this.delegate.viewRenderedSnapshot(snapshot, isPreview, this.renderer.renderMethod);\n this.delegate.preloadOnLoadLinksForView(this.element);\n this.finishRenderingSnapshot(renderer);\n } finally {\n delete this.renderer;\n this.#resolveRenderPromise(undefined);\n delete this.renderPromise;\n }\n } else if (shouldInvalidate) {\n this.invalidate(renderer.reloadReason);\n }\n }\n\n invalidate(reason) {\n this.delegate.viewInvalidated(reason);\n }\n\n async prepareToRenderSnapshot(renderer) {\n this.markAsPreview(renderer.isPreview);\n await renderer.prepareToRender();\n }\n\n markAsPreview(isPreview) {\n if (isPreview) {\n this.element.setAttribute(\"data-turbo-preview\", \"\");\n } else {\n this.element.removeAttribute(\"data-turbo-preview\");\n }\n }\n\n markVisitDirection(direction) {\n this.element.setAttribute(\"data-turbo-visit-direction\", direction);\n }\n\n unmarkVisitDirection() {\n this.element.removeAttribute(\"data-turbo-visit-direction\");\n }\n\n async renderSnapshot(renderer) {\n await renderer.render();\n }\n\n finishRenderingSnapshot(renderer) {\n renderer.finishRendering();\n }\n}\n\nclass FrameView extends View {\n missing() {\n this.element.innerHTML = `Content missing`;\n }\n\n get snapshot() {\n return new Snapshot(this.element)\n }\n}\n\nclass LinkInterceptor {\n constructor(delegate, element) {\n this.delegate = delegate;\n this.element = element;\n }\n\n start() {\n this.element.addEventListener(\"click\", this.clickBubbled);\n document.addEventListener(\"turbo:click\", this.linkClicked);\n document.addEventListener(\"turbo:before-visit\", this.willVisit);\n }\n\n stop() {\n this.element.removeEventListener(\"click\", this.clickBubbled);\n document.removeEventListener(\"turbo:click\", this.linkClicked);\n document.removeEventListener(\"turbo:before-visit\", this.willVisit);\n }\n\n clickBubbled = (event) => {\n if (this.clickEventIsSignificant(event)) {\n this.clickEvent = event;\n } else {\n delete this.clickEvent;\n }\n }\n\n linkClicked = (event) => {\n if (this.clickEvent && this.clickEventIsSignificant(event)) {\n if (this.delegate.shouldInterceptLinkClick(event.target, event.detail.url, event.detail.originalEvent)) {\n this.clickEvent.preventDefault();\n event.preventDefault();\n this.delegate.linkClickIntercepted(event.target, event.detail.url, event.detail.originalEvent);\n }\n }\n delete this.clickEvent;\n }\n\n willVisit = (_event) => {\n delete this.clickEvent;\n }\n\n clickEventIsSignificant(event) {\n const target = event.composed ? event.target?.parentElement : event.target;\n const element = findLinkFromClickTarget(target) || target;\n\n return element instanceof Element && element.closest(\"turbo-frame, html\") == this.element\n }\n}\n\nclass LinkClickObserver {\n started = false\n\n constructor(delegate, eventTarget) {\n this.delegate = delegate;\n this.eventTarget = eventTarget;\n }\n\n start() {\n if (!this.started) {\n this.eventTarget.addEventListener(\"click\", this.clickCaptured, true);\n this.started = true;\n }\n }\n\n stop() {\n if (this.started) {\n this.eventTarget.removeEventListener(\"click\", this.clickCaptured, true);\n this.started = false;\n }\n }\n\n clickCaptured = () => {\n this.eventTarget.removeEventListener(\"click\", this.clickBubbled, false);\n this.eventTarget.addEventListener(\"click\", this.clickBubbled, false);\n }\n\n clickBubbled = (event) => {\n if (event instanceof MouseEvent && this.clickEventIsSignificant(event)) {\n const target = (event.composedPath && event.composedPath()[0]) || event.target;\n const link = findLinkFromClickTarget(target);\n if (link && doesNotTargetIFrame(link.target)) {\n const location = getLocationForLink(link);\n if (this.delegate.willFollowLinkToLocation(link, location, event)) {\n event.preventDefault();\n this.delegate.followedLinkToLocation(link, location);\n }\n }\n }\n }\n\n clickEventIsSignificant(event) {\n return !(\n (event.target && event.target.isContentEditable) ||\n event.defaultPrevented ||\n event.which > 1 ||\n event.altKey ||\n event.ctrlKey ||\n event.metaKey ||\n event.shiftKey\n )\n }\n}\n\nclass FormLinkClickObserver {\n constructor(delegate, element) {\n this.delegate = delegate;\n this.linkInterceptor = new LinkClickObserver(this, element);\n }\n\n start() {\n this.linkInterceptor.start();\n }\n\n stop() {\n this.linkInterceptor.stop();\n }\n\n // Link hover observer delegate\n\n canPrefetchRequestToLocation(link, location) {\n return false\n }\n\n prefetchAndCacheRequestToLocation(link, location) {\n return\n }\n\n // Link click observer delegate\n\n willFollowLinkToLocation(link, location, originalEvent) {\n return (\n this.delegate.willSubmitFormLinkToLocation(link, location, originalEvent) &&\n (link.hasAttribute(\"data-turbo-method\") || link.hasAttribute(\"data-turbo-stream\"))\n )\n }\n\n followedLinkToLocation(link, location) {\n const form = document.createElement(\"form\");\n\n const type = \"hidden\";\n for (const [name, value] of location.searchParams) {\n form.append(Object.assign(document.createElement(\"input\"), { type, name, value }));\n }\n\n const action = Object.assign(location, { search: \"\" });\n form.setAttribute(\"data-turbo\", \"true\");\n form.setAttribute(\"action\", action.href);\n form.setAttribute(\"hidden\", \"\");\n\n const method = link.getAttribute(\"data-turbo-method\");\n if (method) form.setAttribute(\"method\", method);\n\n const turboFrame = link.getAttribute(\"data-turbo-frame\");\n if (turboFrame) form.setAttribute(\"data-turbo-frame\", turboFrame);\n\n const turboAction = getVisitAction(link);\n if (turboAction) form.setAttribute(\"data-turbo-action\", turboAction);\n\n const turboConfirm = link.getAttribute(\"data-turbo-confirm\");\n if (turboConfirm) form.setAttribute(\"data-turbo-confirm\", turboConfirm);\n\n const turboStream = link.hasAttribute(\"data-turbo-stream\");\n if (turboStream) form.setAttribute(\"data-turbo-stream\", \"\");\n\n this.delegate.submittedFormLinkToLocation(link, location, form);\n\n document.body.appendChild(form);\n form.addEventListener(\"turbo:submit-end\", () => form.remove(), { once: true });\n requestAnimationFrame(() => form.requestSubmit());\n }\n}\n\nclass Bardo {\n static async preservingPermanentElements(delegate, permanentElementMap, callback) {\n const bardo = new this(delegate, permanentElementMap);\n bardo.enter();\n await callback();\n bardo.leave();\n }\n\n constructor(delegate, permanentElementMap) {\n this.delegate = delegate;\n this.permanentElementMap = permanentElementMap;\n }\n\n enter() {\n for (const id in this.permanentElementMap) {\n const [currentPermanentElement, newPermanentElement] = this.permanentElementMap[id];\n this.delegate.enteringBardo(currentPermanentElement, newPermanentElement);\n this.replaceNewPermanentElementWithPlaceholder(newPermanentElement);\n }\n }\n\n leave() {\n for (const id in this.permanentElementMap) {\n const [currentPermanentElement] = this.permanentElementMap[id];\n this.replaceCurrentPermanentElementWithClone(currentPermanentElement);\n this.replacePlaceholderWithPermanentElement(currentPermanentElement);\n this.delegate.leavingBardo(currentPermanentElement);\n }\n }\n\n replaceNewPermanentElementWithPlaceholder(permanentElement) {\n const placeholder = createPlaceholderForPermanentElement(permanentElement);\n permanentElement.replaceWith(placeholder);\n }\n\n replaceCurrentPermanentElementWithClone(permanentElement) {\n const clone = permanentElement.cloneNode(true);\n permanentElement.replaceWith(clone);\n }\n\n replacePlaceholderWithPermanentElement(permanentElement) {\n const placeholder = this.getPlaceholderById(permanentElement.id);\n placeholder?.replaceWith(permanentElement);\n }\n\n getPlaceholderById(id) {\n return this.placeholders.find((element) => element.content == id)\n }\n\n get placeholders() {\n return [...document.querySelectorAll(\"meta[name=turbo-permanent-placeholder][content]\")]\n }\n}\n\nfunction createPlaceholderForPermanentElement(permanentElement) {\n const element = document.createElement(\"meta\");\n element.setAttribute(\"name\", \"turbo-permanent-placeholder\");\n element.setAttribute(\"content\", permanentElement.id);\n return element\n}\n\nclass Renderer {\n #activeElement = null\n\n static renderElement(currentElement, newElement) {\n // Abstract method\n }\n\n constructor(currentSnapshot, newSnapshot, isPreview, willRender = true) {\n this.currentSnapshot = currentSnapshot;\n this.newSnapshot = newSnapshot;\n this.isPreview = isPreview;\n this.willRender = willRender;\n this.renderElement = this.constructor.renderElement;\n this.promise = new Promise((resolve, reject) => (this.resolvingFunctions = { resolve, reject }));\n }\n\n get shouldRender() {\n return true\n }\n\n get shouldAutofocus() {\n return true\n }\n\n get reloadReason() {\n return\n }\n\n prepareToRender() {\n return\n }\n\n render() {\n // Abstract method\n }\n\n finishRendering() {\n if (this.resolvingFunctions) {\n this.resolvingFunctions.resolve();\n delete this.resolvingFunctions;\n }\n }\n\n async preservingPermanentElements(callback) {\n await Bardo.preservingPermanentElements(this, this.permanentElementMap, callback);\n }\n\n focusFirstAutofocusableElement() {\n if (this.shouldAutofocus) {\n const element = this.connectedSnapshot.firstAutofocusableElement;\n if (element) {\n element.focus();\n }\n }\n }\n\n // Bardo delegate\n\n enteringBardo(currentPermanentElement) {\n if (this.#activeElement) return\n\n if (currentPermanentElement.contains(this.currentSnapshot.activeElement)) {\n this.#activeElement = this.currentSnapshot.activeElement;\n }\n }\n\n leavingBardo(currentPermanentElement) {\n if (currentPermanentElement.contains(this.#activeElement) && this.#activeElement instanceof HTMLElement) {\n this.#activeElement.focus();\n\n this.#activeElement = null;\n }\n }\n\n get connectedSnapshot() {\n return this.newSnapshot.isConnected ? this.newSnapshot : this.currentSnapshot\n }\n\n get currentElement() {\n return this.currentSnapshot.element\n }\n\n get newElement() {\n return this.newSnapshot.element\n }\n\n get permanentElementMap() {\n return this.currentSnapshot.getPermanentElementMapForSnapshot(this.newSnapshot)\n }\n\n get renderMethod() {\n return \"replace\"\n }\n}\n\nclass FrameRenderer extends Renderer {\n static renderElement(currentElement, newElement) {\n const destinationRange = document.createRange();\n destinationRange.selectNodeContents(currentElement);\n destinationRange.deleteContents();\n\n const frameElement = newElement;\n const sourceRange = frameElement.ownerDocument?.createRange();\n if (sourceRange) {\n sourceRange.selectNodeContents(frameElement);\n currentElement.appendChild(sourceRange.extractContents());\n }\n }\n\n constructor(delegate, currentSnapshot, newSnapshot, renderElement, isPreview, willRender = true) {\n super(currentSnapshot, newSnapshot, renderElement, isPreview, willRender);\n this.delegate = delegate;\n }\n\n get shouldRender() {\n return true\n }\n\n async render() {\n await nextRepaint();\n this.preservingPermanentElements(() => {\n this.loadFrameElement();\n });\n this.scrollFrameIntoView();\n await nextRepaint();\n this.focusFirstAutofocusableElement();\n await nextRepaint();\n this.activateScriptElements();\n }\n\n loadFrameElement() {\n this.delegate.willRenderFrame(this.currentElement, this.newElement);\n this.renderElement(this.currentElement, this.newElement);\n }\n\n scrollFrameIntoView() {\n if (this.currentElement.autoscroll || this.newElement.autoscroll) {\n const element = this.currentElement.firstElementChild;\n const block = readScrollLogicalPosition(this.currentElement.getAttribute(\"data-autoscroll-block\"), \"end\");\n const behavior = readScrollBehavior(this.currentElement.getAttribute(\"data-autoscroll-behavior\"), \"auto\");\n\n if (element) {\n element.scrollIntoView({ block, behavior });\n return true\n }\n }\n return false\n }\n\n activateScriptElements() {\n for (const inertScriptElement of this.newScriptElements) {\n const activatedScriptElement = activateScriptElement(inertScriptElement);\n inertScriptElement.replaceWith(activatedScriptElement);\n }\n }\n\n get newScriptElements() {\n return this.currentElement.querySelectorAll(\"script\")\n }\n}\n\nfunction readScrollLogicalPosition(value, defaultValue) {\n if (value == \"end\" || value == \"start\" || value == \"center\" || value == \"nearest\") {\n return value\n } else {\n return defaultValue\n }\n}\n\nfunction readScrollBehavior(value, defaultValue) {\n if (value == \"auto\" || value == \"smooth\") {\n return value\n } else {\n return defaultValue\n }\n}\n\n// base IIFE to define idiomorph\nvar Idiomorph = (function () {\n\n //=============================================================================\n // AND NOW IT BEGINS...\n //=============================================================================\n let EMPTY_SET = new Set();\n\n // default configuration values, updatable by users now\n let defaults = {\n morphStyle: \"outerHTML\",\n callbacks : {\n beforeNodeAdded: noOp,\n afterNodeAdded: noOp,\n beforeNodeMorphed: noOp,\n afterNodeMorphed: noOp,\n beforeNodeRemoved: noOp,\n afterNodeRemoved: noOp,\n beforeAttributeUpdated: noOp,\n\n },\n head: {\n style: 'merge',\n shouldPreserve: function (elt) {\n return elt.getAttribute(\"im-preserve\") === \"true\";\n },\n shouldReAppend: function (elt) {\n return elt.getAttribute(\"im-re-append\") === \"true\";\n },\n shouldRemove: noOp,\n afterHeadMorphed: noOp,\n }\n };\n\n //=============================================================================\n // Core Morphing Algorithm - morph, morphNormalizedContent, morphOldNodeTo, morphChildren\n //=============================================================================\n function morph(oldNode, newContent, config = {}) {\n\n if (oldNode instanceof Document) {\n oldNode = oldNode.documentElement;\n }\n\n if (typeof newContent === 'string') {\n newContent = parseContent(newContent);\n }\n\n let normalizedContent = normalizeContent(newContent);\n\n let ctx = createMorphContext(oldNode, normalizedContent, config);\n\n return morphNormalizedContent(oldNode, normalizedContent, ctx);\n }\n\n function morphNormalizedContent(oldNode, normalizedNewContent, ctx) {\n if (ctx.head.block) {\n let oldHead = oldNode.querySelector('head');\n let newHead = normalizedNewContent.querySelector('head');\n if (oldHead && newHead) {\n let promises = handleHeadElement(newHead, oldHead, ctx);\n // when head promises resolve, call morph again, ignoring the head tag\n Promise.all(promises).then(function () {\n morphNormalizedContent(oldNode, normalizedNewContent, Object.assign(ctx, {\n head: {\n block: false,\n ignore: true\n }\n }));\n });\n return;\n }\n }\n\n if (ctx.morphStyle === \"innerHTML\") {\n\n // innerHTML, so we are only updating the children\n morphChildren(normalizedNewContent, oldNode, ctx);\n return oldNode.children;\n\n } else if (ctx.morphStyle === \"outerHTML\" || ctx.morphStyle == null) {\n // otherwise find the best element match in the new content, morph that, and merge its siblings\n // into either side of the best match\n let bestMatch = findBestNodeMatch(normalizedNewContent, oldNode, ctx);\n\n // stash the siblings that will need to be inserted on either side of the best match\n let previousSibling = bestMatch?.previousSibling;\n let nextSibling = bestMatch?.nextSibling;\n\n // morph it\n let morphedNode = morphOldNodeTo(oldNode, bestMatch, ctx);\n\n if (bestMatch) {\n // if there was a best match, merge the siblings in too and return the\n // whole bunch\n return insertSiblings(previousSibling, morphedNode, nextSibling);\n } else {\n // otherwise nothing was added to the DOM\n return []\n }\n } else {\n throw \"Do not understand how to morph style \" + ctx.morphStyle;\n }\n }\n\n\n /**\n * @param possibleActiveElement\n * @param ctx\n * @returns {boolean}\n */\n function ignoreValueOfActiveElement(possibleActiveElement, ctx) {\n return ctx.ignoreActiveValue && possibleActiveElement === document.activeElement && possibleActiveElement !== document.body;\n }\n\n /**\n * @param oldNode root node to merge content into\n * @param newContent new content to merge\n * @param ctx the merge context\n * @returns {Element} the element that ended up in the DOM\n */\n function morphOldNodeTo(oldNode, newContent, ctx) {\n if (ctx.ignoreActive && oldNode === document.activeElement) ; else if (newContent == null) {\n if (ctx.callbacks.beforeNodeRemoved(oldNode) === false) return oldNode;\n\n oldNode.remove();\n ctx.callbacks.afterNodeRemoved(oldNode);\n return null;\n } else if (!isSoftMatch(oldNode, newContent)) {\n if (ctx.callbacks.beforeNodeRemoved(oldNode) === false) return oldNode;\n if (ctx.callbacks.beforeNodeAdded(newContent) === false) return oldNode;\n\n oldNode.parentElement.replaceChild(newContent, oldNode);\n ctx.callbacks.afterNodeAdded(newContent);\n ctx.callbacks.afterNodeRemoved(oldNode);\n return newContent;\n } else {\n if (ctx.callbacks.beforeNodeMorphed(oldNode, newContent) === false) return oldNode;\n\n if (oldNode instanceof HTMLHeadElement && ctx.head.ignore) ; else if (oldNode instanceof HTMLHeadElement && ctx.head.style !== \"morph\") {\n handleHeadElement(newContent, oldNode, ctx);\n } else {\n syncNodeFrom(newContent, oldNode, ctx);\n if (!ignoreValueOfActiveElement(oldNode, ctx)) {\n morphChildren(newContent, oldNode, ctx);\n }\n }\n ctx.callbacks.afterNodeMorphed(oldNode, newContent);\n return oldNode;\n }\n }\n\n /**\n * This is the core algorithm for matching up children. The idea is to use id sets to try to match up\n * nodes as faithfully as possible. We greedily match, which allows us to keep the algorithm fast, but\n * by using id sets, we are able to better match up with content deeper in the DOM.\n *\n * Basic algorithm is, for each node in the new content:\n *\n * - if we have reached the end of the old parent, append the new content\n * - if the new content has an id set match with the current insertion point, morph\n * - search for an id set match\n * - if id set match found, morph\n * - otherwise search for a \"soft\" match\n * - if a soft match is found, morph\n * - otherwise, prepend the new node before the current insertion point\n *\n * The two search algorithms terminate if competing node matches appear to outweigh what can be achieved\n * with the current node. See findIdSetMatch() and findSoftMatch() for details.\n *\n * @param {Element} newParent the parent element of the new content\n * @param {Element } oldParent the old content that we are merging the new content into\n * @param ctx the merge context\n */\n function morphChildren(newParent, oldParent, ctx) {\n\n let nextNewChild = newParent.firstChild;\n let insertionPoint = oldParent.firstChild;\n let newChild;\n\n // run through all the new content\n while (nextNewChild) {\n\n newChild = nextNewChild;\n nextNewChild = newChild.nextSibling;\n\n // if we are at the end of the exiting parent's children, just append\n if (insertionPoint == null) {\n if (ctx.callbacks.beforeNodeAdded(newChild) === false) return;\n\n oldParent.appendChild(newChild);\n ctx.callbacks.afterNodeAdded(newChild);\n removeIdsFromConsideration(ctx, newChild);\n continue;\n }\n\n // if the current node has an id set match then morph\n if (isIdSetMatch(newChild, insertionPoint, ctx)) {\n morphOldNodeTo(insertionPoint, newChild, ctx);\n insertionPoint = insertionPoint.nextSibling;\n removeIdsFromConsideration(ctx, newChild);\n continue;\n }\n\n // otherwise search forward in the existing old children for an id set match\n let idSetMatch = findIdSetMatch(newParent, oldParent, newChild, insertionPoint, ctx);\n\n // if we found a potential match, remove the nodes until that point and morph\n if (idSetMatch) {\n insertionPoint = removeNodesBetween(insertionPoint, idSetMatch, ctx);\n morphOldNodeTo(idSetMatch, newChild, ctx);\n removeIdsFromConsideration(ctx, newChild);\n continue;\n }\n\n // no id set match found, so scan forward for a soft match for the current node\n let softMatch = findSoftMatch(newParent, oldParent, newChild, insertionPoint, ctx);\n\n // if we found a soft match for the current node, morph\n if (softMatch) {\n insertionPoint = removeNodesBetween(insertionPoint, softMatch, ctx);\n morphOldNodeTo(softMatch, newChild, ctx);\n removeIdsFromConsideration(ctx, newChild);\n continue;\n }\n\n // abandon all hope of morphing, just insert the new child before the insertion point\n // and move on\n if (ctx.callbacks.beforeNodeAdded(newChild) === false) return;\n\n oldParent.insertBefore(newChild, insertionPoint);\n ctx.callbacks.afterNodeAdded(newChild);\n removeIdsFromConsideration(ctx, newChild);\n }\n\n // remove any remaining old nodes that didn't match up with new content\n while (insertionPoint !== null) {\n\n let tempNode = insertionPoint;\n insertionPoint = insertionPoint.nextSibling;\n removeNode(tempNode, ctx);\n }\n }\n\n //=============================================================================\n // Attribute Syncing Code\n //=============================================================================\n\n /**\n * @param attr {String} the attribute to be mutated\n * @param to {Element} the element that is going to be updated\n * @param updateType {(\"update\"|\"remove\")}\n * @param ctx the merge context\n * @returns {boolean} true if the attribute should be ignored, false otherwise\n */\n function ignoreAttribute(attr, to, updateType, ctx) {\n if(attr === 'value' && ctx.ignoreActiveValue && to === document.activeElement){\n return true;\n }\n return ctx.callbacks.beforeAttributeUpdated(attr, to, updateType) === false;\n }\n\n /**\n * syncs a given node with another node, copying over all attributes and\n * inner element state from the 'from' node to the 'to' node\n *\n * @param {Element} from the element to copy attributes & state from\n * @param {Element} to the element to copy attributes & state to\n * @param ctx the merge context\n */\n function syncNodeFrom(from, to, ctx) {\n let type = from.nodeType;\n\n // if is an element type, sync the attributes from the\n // new node into the new node\n if (type === 1 /* element type */) {\n const fromAttributes = from.attributes;\n const toAttributes = to.attributes;\n for (const fromAttribute of fromAttributes) {\n if (ignoreAttribute(fromAttribute.name, to, 'update', ctx)) {\n continue;\n }\n if (to.getAttribute(fromAttribute.name) !== fromAttribute.value) {\n to.setAttribute(fromAttribute.name, fromAttribute.value);\n }\n }\n // iterate backwards to avoid skipping over items when a delete occurs\n for (let i = toAttributes.length - 1; 0 <= i; i--) {\n const toAttribute = toAttributes[i];\n if (ignoreAttribute(toAttribute.name, to, 'remove', ctx)) {\n continue;\n }\n if (!from.hasAttribute(toAttribute.name)) {\n to.removeAttribute(toAttribute.name);\n }\n }\n }\n\n // sync text nodes\n if (type === 8 /* comment */ || type === 3 /* text */) {\n if (to.nodeValue !== from.nodeValue) {\n to.nodeValue = from.nodeValue;\n }\n }\n\n if (!ignoreValueOfActiveElement(to, ctx)) {\n // sync input values\n syncInputValue(from, to, ctx);\n }\n }\n\n /**\n * @param from {Element} element to sync the value from\n * @param to {Element} element to sync the value to\n * @param attributeName {String} the attribute name\n * @param ctx the merge context\n */\n function syncBooleanAttribute(from, to, attributeName, ctx) {\n if (from[attributeName] !== to[attributeName]) {\n let ignoreUpdate = ignoreAttribute(attributeName, to, 'update', ctx);\n if (!ignoreUpdate) {\n to[attributeName] = from[attributeName];\n }\n if (from[attributeName]) {\n if (!ignoreUpdate) {\n to.setAttribute(attributeName, from[attributeName]);\n }\n } else {\n if (!ignoreAttribute(attributeName, to, 'remove', ctx)) {\n to.removeAttribute(attributeName);\n }\n }\n }\n }\n\n /**\n * NB: many bothans died to bring us information:\n *\n * https://github.com/patrick-steele-idem/morphdom/blob/master/src/specialElHandlers.js\n * https://github.com/choojs/nanomorph/blob/master/lib/morph.jsL113\n *\n * @param from {Element} the element to sync the input value from\n * @param to {Element} the element to sync the input value to\n * @param ctx the merge context\n */\n function syncInputValue(from, to, ctx) {\n if (from instanceof HTMLInputElement &&\n to instanceof HTMLInputElement &&\n from.type !== 'file') {\n\n let fromValue = from.value;\n let toValue = to.value;\n\n // sync boolean attributes\n syncBooleanAttribute(from, to, 'checked', ctx);\n syncBooleanAttribute(from, to, 'disabled', ctx);\n\n if (!from.hasAttribute('value')) {\n if (!ignoreAttribute('value', to, 'remove', ctx)) {\n to.value = '';\n to.removeAttribute('value');\n }\n } else if (fromValue !== toValue) {\n if (!ignoreAttribute('value', to, 'update', ctx)) {\n to.setAttribute('value', fromValue);\n to.value = fromValue;\n }\n }\n } else if (from instanceof HTMLOptionElement) {\n syncBooleanAttribute(from, to, 'selected', ctx);\n } else if (from instanceof HTMLTextAreaElement && to instanceof HTMLTextAreaElement) {\n let fromValue = from.value;\n let toValue = to.value;\n if (ignoreAttribute('value', to, 'update', ctx)) {\n return;\n }\n if (fromValue !== toValue) {\n to.value = fromValue;\n }\n if (to.firstChild && to.firstChild.nodeValue !== fromValue) {\n to.firstChild.nodeValue = fromValue;\n }\n }\n }\n\n //=============================================================================\n // the HEAD tag can be handled specially, either w/ a 'merge' or 'append' style\n //=============================================================================\n function handleHeadElement(newHeadTag, currentHead, ctx) {\n\n let added = [];\n let removed = [];\n let preserved = [];\n let nodesToAppend = [];\n\n let headMergeStyle = ctx.head.style;\n\n // put all new head elements into a Map, by their outerHTML\n let srcToNewHeadNodes = new Map();\n for (const newHeadChild of newHeadTag.children) {\n srcToNewHeadNodes.set(newHeadChild.outerHTML, newHeadChild);\n }\n\n // for each elt in the current head\n for (const currentHeadElt of currentHead.children) {\n\n // If the current head element is in the map\n let inNewContent = srcToNewHeadNodes.has(currentHeadElt.outerHTML);\n let isReAppended = ctx.head.shouldReAppend(currentHeadElt);\n let isPreserved = ctx.head.shouldPreserve(currentHeadElt);\n if (inNewContent || isPreserved) {\n if (isReAppended) {\n // remove the current version and let the new version replace it and re-execute\n removed.push(currentHeadElt);\n } else {\n // this element already exists and should not be re-appended, so remove it from\n // the new content map, preserving it in the DOM\n srcToNewHeadNodes.delete(currentHeadElt.outerHTML);\n preserved.push(currentHeadElt);\n }\n } else {\n if (headMergeStyle === \"append\") {\n // we are appending and this existing element is not new content\n // so if and only if it is marked for re-append do we do anything\n if (isReAppended) {\n removed.push(currentHeadElt);\n nodesToAppend.push(currentHeadElt);\n }\n } else {\n // if this is a merge, we remove this content since it is not in the new head\n if (ctx.head.shouldRemove(currentHeadElt) !== false) {\n removed.push(currentHeadElt);\n }\n }\n }\n }\n\n // Push the remaining new head elements in the Map into the\n // nodes to append to the head tag\n nodesToAppend.push(...srcToNewHeadNodes.values());\n\n let promises = [];\n for (const newNode of nodesToAppend) {\n let newElt = document.createRange().createContextualFragment(newNode.outerHTML).firstChild;\n if (ctx.callbacks.beforeNodeAdded(newElt) !== false) {\n if (newElt.href || newElt.src) {\n let resolve = null;\n let promise = new Promise(function (_resolve) {\n resolve = _resolve;\n });\n newElt.addEventListener('load', function () {\n resolve();\n });\n promises.push(promise);\n }\n currentHead.appendChild(newElt);\n ctx.callbacks.afterNodeAdded(newElt);\n added.push(newElt);\n }\n }\n\n // remove all removed elements, after we have appended the new elements to avoid\n // additional network requests for things like style sheets\n for (const removedElement of removed) {\n if (ctx.callbacks.beforeNodeRemoved(removedElement) !== false) {\n currentHead.removeChild(removedElement);\n ctx.callbacks.afterNodeRemoved(removedElement);\n }\n }\n\n ctx.head.afterHeadMorphed(currentHead, {added: added, kept: preserved, removed: removed});\n return promises;\n }\n\n function noOp() {\n }\n\n /*\n Deep merges the config object and the Idiomoroph.defaults object to\n produce a final configuration object\n */\n function mergeDefaults(config) {\n let finalConfig = {};\n // copy top level stuff into final config\n Object.assign(finalConfig, defaults);\n Object.assign(finalConfig, config);\n\n // copy callbacks into final config (do this to deep merge the callbacks)\n finalConfig.callbacks = {};\n Object.assign(finalConfig.callbacks, defaults.callbacks);\n Object.assign(finalConfig.callbacks, config.callbacks);\n\n // copy head config into final config (do this to deep merge the head)\n finalConfig.head = {};\n Object.assign(finalConfig.head, defaults.head);\n Object.assign(finalConfig.head, config.head);\n return finalConfig;\n }\n\n function createMorphContext(oldNode, newContent, config) {\n config = mergeDefaults(config);\n return {\n target: oldNode,\n newContent: newContent,\n config: config,\n morphStyle: config.morphStyle,\n ignoreActive: config.ignoreActive,\n ignoreActiveValue: config.ignoreActiveValue,\n idMap: createIdMap(oldNode, newContent),\n deadIds: new Set(),\n callbacks: config.callbacks,\n head: config.head\n }\n }\n\n function isIdSetMatch(node1, node2, ctx) {\n if (node1 == null || node2 == null) {\n return false;\n }\n if (node1.nodeType === node2.nodeType && node1.tagName === node2.tagName) {\n if (node1.id !== \"\" && node1.id === node2.id) {\n return true;\n } else {\n return getIdIntersectionCount(ctx, node1, node2) > 0;\n }\n }\n return false;\n }\n\n function isSoftMatch(node1, node2) {\n if (node1 == null || node2 == null) {\n return false;\n }\n return node1.nodeType === node2.nodeType && node1.tagName === node2.tagName\n }\n\n function removeNodesBetween(startInclusive, endExclusive, ctx) {\n while (startInclusive !== endExclusive) {\n let tempNode = startInclusive;\n startInclusive = startInclusive.nextSibling;\n removeNode(tempNode, ctx);\n }\n removeIdsFromConsideration(ctx, endExclusive);\n return endExclusive.nextSibling;\n }\n\n //=============================================================================\n // Scans forward from the insertionPoint in the old parent looking for a potential id match\n // for the newChild. We stop if we find a potential id match for the new child OR\n // if the number of potential id matches we are discarding is greater than the\n // potential id matches for the new child\n //=============================================================================\n function findIdSetMatch(newContent, oldParent, newChild, insertionPoint, ctx) {\n\n // max id matches we are willing to discard in our search\n let newChildPotentialIdCount = getIdIntersectionCount(ctx, newChild, oldParent);\n\n let potentialMatch = null;\n\n // only search forward if there is a possibility of an id match\n if (newChildPotentialIdCount > 0) {\n let potentialMatch = insertionPoint;\n // if there is a possibility of an id match, scan forward\n // keep track of the potential id match count we are discarding (the\n // newChildPotentialIdCount must be greater than this to make it likely\n // worth it)\n let otherMatchCount = 0;\n while (potentialMatch != null) {\n\n // If we have an id match, return the current potential match\n if (isIdSetMatch(newChild, potentialMatch, ctx)) {\n return potentialMatch;\n }\n\n // computer the other potential matches of this new content\n otherMatchCount += getIdIntersectionCount(ctx, potentialMatch, newContent);\n if (otherMatchCount > newChildPotentialIdCount) {\n // if we have more potential id matches in _other_ content, we\n // do not have a good candidate for an id match, so return null\n return null;\n }\n\n // advanced to the next old content child\n potentialMatch = potentialMatch.nextSibling;\n }\n }\n return potentialMatch;\n }\n\n //=============================================================================\n // Scans forward from the insertionPoint in the old parent looking for a potential soft match\n // for the newChild. We stop if we find a potential soft match for the new child OR\n // if we find a potential id match in the old parents children OR if we find two\n // potential soft matches for the next two pieces of new content\n //=============================================================================\n function findSoftMatch(newContent, oldParent, newChild, insertionPoint, ctx) {\n\n let potentialSoftMatch = insertionPoint;\n let nextSibling = newChild.nextSibling;\n let siblingSoftMatchCount = 0;\n\n while (potentialSoftMatch != null) {\n\n if (getIdIntersectionCount(ctx, potentialSoftMatch, newContent) > 0) {\n // the current potential soft match has a potential id set match with the remaining new\n // content so bail out of looking\n return null;\n }\n\n // if we have a soft match with the current node, return it\n if (isSoftMatch(newChild, potentialSoftMatch)) {\n return potentialSoftMatch;\n }\n\n if (isSoftMatch(nextSibling, potentialSoftMatch)) {\n // the next new node has a soft match with this node, so\n // increment the count of future soft matches\n siblingSoftMatchCount++;\n nextSibling = nextSibling.nextSibling;\n\n // If there are two future soft matches, bail to allow the siblings to soft match\n // so that we don't consume future soft matches for the sake of the current node\n if (siblingSoftMatchCount >= 2) {\n return null;\n }\n }\n\n // advanced to the next old content child\n potentialSoftMatch = potentialSoftMatch.nextSibling;\n }\n\n return potentialSoftMatch;\n }\n\n function parseContent(newContent) {\n let parser = new DOMParser();\n\n // remove svgs to avoid false-positive matches on head, etc.\n let contentWithSvgsRemoved = newContent.replace(/]*>|>)([\\s\\S]*?)<\\/svg>/gim, '');\n\n // if the newContent contains a html, head or body tag, we can simply parse it w/o wrapping\n if (contentWithSvgsRemoved.match(/<\\/html>/) || contentWithSvgsRemoved.match(/<\\/head>/) || contentWithSvgsRemoved.match(/<\\/body>/)) {\n let content = parser.parseFromString(newContent, \"text/html\");\n // if it is a full HTML document, return the document itself as the parent container\n if (contentWithSvgsRemoved.match(/<\\/html>/)) {\n content.generatedByIdiomorph = true;\n return content;\n } else {\n // otherwise return the html element as the parent container\n let htmlElement = content.firstChild;\n if (htmlElement) {\n htmlElement.generatedByIdiomorph = true;\n return htmlElement;\n } else {\n return null;\n }\n }\n } else {\n // if it is partial HTML, wrap it in a template tag to provide a parent element and also to help\n // deal with touchy tags like tr, tbody, etc.\n let responseDoc = parser.parseFromString(\"\", \"text/html\");\n let content = responseDoc.body.querySelector('template').content;\n content.generatedByIdiomorph = true;\n return content\n }\n }\n\n function normalizeContent(newContent) {\n if (newContent == null) {\n // noinspection UnnecessaryLocalVariableJS\n const dummyParent = document.createElement('div');\n return dummyParent;\n } else if (newContent.generatedByIdiomorph) {\n // the template tag created by idiomorph parsing can serve as a dummy parent\n return newContent;\n } else if (newContent instanceof Node) {\n // a single node is added as a child to a dummy parent\n const dummyParent = document.createElement('div');\n dummyParent.append(newContent);\n return dummyParent;\n } else {\n // all nodes in the array or HTMLElement collection are consolidated under\n // a single dummy parent element\n const dummyParent = document.createElement('div');\n for (const elt of [...newContent]) {\n dummyParent.append(elt);\n }\n return dummyParent;\n }\n }\n\n function insertSiblings(previousSibling, morphedNode, nextSibling) {\n let stack = [];\n let added = [];\n while (previousSibling != null) {\n stack.push(previousSibling);\n previousSibling = previousSibling.previousSibling;\n }\n while (stack.length > 0) {\n let node = stack.pop();\n added.push(node); // push added preceding siblings on in order and insert\n morphedNode.parentElement.insertBefore(node, morphedNode);\n }\n added.push(morphedNode);\n while (nextSibling != null) {\n stack.push(nextSibling);\n added.push(nextSibling); // here we are going in order, so push on as we scan, rather than add\n nextSibling = nextSibling.nextSibling;\n }\n while (stack.length > 0) {\n morphedNode.parentElement.insertBefore(stack.pop(), morphedNode.nextSibling);\n }\n return added;\n }\n\n function findBestNodeMatch(newContent, oldNode, ctx) {\n let currentElement;\n currentElement = newContent.firstChild;\n let bestElement = currentElement;\n let score = 0;\n while (currentElement) {\n let newScore = scoreElement(currentElement, oldNode, ctx);\n if (newScore > score) {\n bestElement = currentElement;\n score = newScore;\n }\n currentElement = currentElement.nextSibling;\n }\n return bestElement;\n }\n\n function scoreElement(node1, node2, ctx) {\n if (isSoftMatch(node1, node2)) {\n return .5 + getIdIntersectionCount(ctx, node1, node2);\n }\n return 0;\n }\n\n function removeNode(tempNode, ctx) {\n removeIdsFromConsideration(ctx, tempNode);\n if (ctx.callbacks.beforeNodeRemoved(tempNode) === false) return;\n\n tempNode.remove();\n ctx.callbacks.afterNodeRemoved(tempNode);\n }\n\n //=============================================================================\n // ID Set Functions\n //=============================================================================\n\n function isIdInConsideration(ctx, id) {\n return !ctx.deadIds.has(id);\n }\n\n function idIsWithinNode(ctx, id, targetNode) {\n let idSet = ctx.idMap.get(targetNode) || EMPTY_SET;\n return idSet.has(id);\n }\n\n function removeIdsFromConsideration(ctx, node) {\n let idSet = ctx.idMap.get(node) || EMPTY_SET;\n for (const id of idSet) {\n ctx.deadIds.add(id);\n }\n }\n\n function getIdIntersectionCount(ctx, node1, node2) {\n let sourceSet = ctx.idMap.get(node1) || EMPTY_SET;\n let matchCount = 0;\n for (const id of sourceSet) {\n // a potential match is an id in the source and potentialIdsSet, but\n // that has not already been merged into the DOM\n if (isIdInConsideration(ctx, id) && idIsWithinNode(ctx, id, node2)) {\n ++matchCount;\n }\n }\n return matchCount;\n }\n\n /**\n * A bottom up algorithm that finds all elements with ids inside of the node\n * argument and populates id sets for those nodes and all their parents, generating\n * a set of ids contained within all nodes for the entire hierarchy in the DOM\n *\n * @param node {Element}\n * @param {Map>} idMap\n */\n function populateIdMapForNode(node, idMap) {\n let nodeParent = node.parentElement;\n // find all elements with an id property\n let idElements = node.querySelectorAll('[id]');\n for (const elt of idElements) {\n let current = elt;\n // walk up the parent hierarchy of that element, adding the id\n // of element to the parent's id set\n while (current !== nodeParent && current != null) {\n let idSet = idMap.get(current);\n // if the id set doesn't exist, create it and insert it in the map\n if (idSet == null) {\n idSet = new Set();\n idMap.set(current, idSet);\n }\n idSet.add(elt.id);\n current = current.parentElement;\n }\n }\n }\n\n /**\n * This function computes a map of nodes to all ids contained within that node (inclusive of the\n * node). This map can be used to ask if two nodes have intersecting sets of ids, which allows\n * for a looser definition of \"matching\" than tradition id matching, and allows child nodes\n * to contribute to a parent nodes matching.\n *\n * @param {Element} oldContent the old content that will be morphed\n * @param {Element} newContent the new content to morph to\n * @returns {Map>} a map of nodes to id sets for the\n */\n function createIdMap(oldContent, newContent) {\n let idMap = new Map();\n populateIdMapForNode(oldContent, idMap);\n populateIdMapForNode(newContent, idMap);\n return idMap;\n }\n\n //=============================================================================\n // This is what ends up becoming the Idiomorph global object\n //=============================================================================\n return {\n morph,\n defaults\n }\n })();\n\nfunction morphElements(currentElement, newElement, { callbacks, ...options } = {}) {\n Idiomorph.morph(currentElement, newElement, {\n ...options,\n callbacks: new DefaultIdiomorphCallbacks(callbacks)\n });\n}\n\nfunction morphChildren(currentElement, newElement) {\n morphElements(currentElement, newElement.children, {\n morphStyle: \"innerHTML\"\n });\n}\n\nclass DefaultIdiomorphCallbacks {\n #beforeNodeMorphed\n\n constructor({ beforeNodeMorphed } = {}) {\n this.#beforeNodeMorphed = beforeNodeMorphed || (() => true);\n }\n\n beforeNodeAdded = (node) => {\n return !(node.id && node.hasAttribute(\"data-turbo-permanent\") && document.getElementById(node.id))\n }\n\n beforeNodeMorphed = (currentElement, newElement) => {\n if (currentElement instanceof Element) {\n if (!currentElement.hasAttribute(\"data-turbo-permanent\") && this.#beforeNodeMorphed(currentElement, newElement)) {\n const event = dispatch(\"turbo:before-morph-element\", {\n cancelable: true,\n target: currentElement,\n detail: { currentElement, newElement }\n });\n\n return !event.defaultPrevented\n } else {\n return false\n }\n }\n }\n\n beforeAttributeUpdated = (attributeName, target, mutationType) => {\n const event = dispatch(\"turbo:before-morph-attribute\", {\n cancelable: true,\n target,\n detail: { attributeName, mutationType }\n });\n\n return !event.defaultPrevented\n }\n\n beforeNodeRemoved = (node) => {\n return this.beforeNodeMorphed(node)\n }\n\n afterNodeMorphed = (currentElement, newElement) => {\n if (currentElement instanceof Element) {\n dispatch(\"turbo:morph-element\", {\n target: currentElement,\n detail: { currentElement, newElement }\n });\n }\n }\n}\n\nclass MorphingFrameRenderer extends FrameRenderer {\n static renderElement(currentElement, newElement) {\n dispatch(\"turbo:before-frame-morph\", {\n target: currentElement,\n detail: { currentElement, newElement }\n });\n\n morphChildren(currentElement, newElement);\n }\n\n async preservingPermanentElements(callback) {\n return await callback()\n }\n}\n\nclass ProgressBar {\n static animationDuration = 300 /*ms*/\n\n static get defaultCSS() {\n return unindent`\n .turbo-progress-bar {\n position: fixed;\n display: block;\n top: 0;\n left: 0;\n height: 3px;\n background: #0076ff;\n z-index: 2147483647;\n transition:\n width ${ProgressBar.animationDuration}ms ease-out,\n opacity ${ProgressBar.animationDuration / 2}ms ${ProgressBar.animationDuration / 2}ms ease-in;\n transform: translate3d(0, 0, 0);\n }\n `\n }\n\n hiding = false\n value = 0\n visible = false\n\n constructor() {\n this.stylesheetElement = this.createStylesheetElement();\n this.progressElement = this.createProgressElement();\n this.installStylesheetElement();\n this.setValue(0);\n }\n\n show() {\n if (!this.visible) {\n this.visible = true;\n this.installProgressElement();\n this.startTrickling();\n }\n }\n\n hide() {\n if (this.visible && !this.hiding) {\n this.hiding = true;\n this.fadeProgressElement(() => {\n this.uninstallProgressElement();\n this.stopTrickling();\n this.visible = false;\n this.hiding = false;\n });\n }\n }\n\n setValue(value) {\n this.value = value;\n this.refresh();\n }\n\n // Private\n\n installStylesheetElement() {\n document.head.insertBefore(this.stylesheetElement, document.head.firstChild);\n }\n\n installProgressElement() {\n this.progressElement.style.width = \"0\";\n this.progressElement.style.opacity = \"1\";\n document.documentElement.insertBefore(this.progressElement, document.body);\n this.refresh();\n }\n\n fadeProgressElement(callback) {\n this.progressElement.style.opacity = \"0\";\n setTimeout(callback, ProgressBar.animationDuration * 1.5);\n }\n\n uninstallProgressElement() {\n if (this.progressElement.parentNode) {\n document.documentElement.removeChild(this.progressElement);\n }\n }\n\n startTrickling() {\n if (!this.trickleInterval) {\n this.trickleInterval = window.setInterval(this.trickle, ProgressBar.animationDuration);\n }\n }\n\n stopTrickling() {\n window.clearInterval(this.trickleInterval);\n delete this.trickleInterval;\n }\n\n trickle = () => {\n this.setValue(this.value + Math.random() / 100);\n }\n\n refresh() {\n requestAnimationFrame(() => {\n this.progressElement.style.width = `${10 + this.value * 90}%`;\n });\n }\n\n createStylesheetElement() {\n const element = document.createElement(\"style\");\n element.type = \"text/css\";\n element.textContent = ProgressBar.defaultCSS;\n if (this.cspNonce) {\n element.nonce = this.cspNonce;\n }\n return element\n }\n\n createProgressElement() {\n const element = document.createElement(\"div\");\n element.className = \"turbo-progress-bar\";\n return element\n }\n\n get cspNonce() {\n return getMetaContent(\"csp-nonce\")\n }\n}\n\nclass HeadSnapshot extends Snapshot {\n detailsByOuterHTML = this.children\n .filter((element) => !elementIsNoscript(element))\n .map((element) => elementWithoutNonce(element))\n .reduce((result, element) => {\n const { outerHTML } = element;\n const details =\n outerHTML in result\n ? result[outerHTML]\n : {\n type: elementType(element),\n tracked: elementIsTracked(element),\n elements: []\n };\n return {\n ...result,\n [outerHTML]: {\n ...details,\n elements: [...details.elements, element]\n }\n }\n }, {})\n\n get trackedElementSignature() {\n return Object.keys(this.detailsByOuterHTML)\n .filter((outerHTML) => this.detailsByOuterHTML[outerHTML].tracked)\n .join(\"\")\n }\n\n getScriptElementsNotInSnapshot(snapshot) {\n return this.getElementsMatchingTypeNotInSnapshot(\"script\", snapshot)\n }\n\n getStylesheetElementsNotInSnapshot(snapshot) {\n return this.getElementsMatchingTypeNotInSnapshot(\"stylesheet\", snapshot)\n }\n\n getElementsMatchingTypeNotInSnapshot(matchedType, snapshot) {\n return Object.keys(this.detailsByOuterHTML)\n .filter((outerHTML) => !(outerHTML in snapshot.detailsByOuterHTML))\n .map((outerHTML) => this.detailsByOuterHTML[outerHTML])\n .filter(({ type }) => type == matchedType)\n .map(({ elements: [element] }) => element)\n }\n\n get provisionalElements() {\n return Object.keys(this.detailsByOuterHTML).reduce((result, outerHTML) => {\n const { type, tracked, elements } = this.detailsByOuterHTML[outerHTML];\n if (type == null && !tracked) {\n return [...result, ...elements]\n } else if (elements.length > 1) {\n return [...result, ...elements.slice(1)]\n } else {\n return result\n }\n }, [])\n }\n\n getMetaValue(name) {\n const element = this.findMetaElementByName(name);\n return element ? element.getAttribute(\"content\") : null\n }\n\n findMetaElementByName(name) {\n return Object.keys(this.detailsByOuterHTML).reduce((result, outerHTML) => {\n const {\n elements: [element]\n } = this.detailsByOuterHTML[outerHTML];\n return elementIsMetaElementWithName(element, name) ? element : result\n }, undefined | undefined)\n }\n}\n\nfunction elementType(element) {\n if (elementIsScript(element)) {\n return \"script\"\n } else if (elementIsStylesheet(element)) {\n return \"stylesheet\"\n }\n}\n\nfunction elementIsTracked(element) {\n return element.getAttribute(\"data-turbo-track\") == \"reload\"\n}\n\nfunction elementIsScript(element) {\n const tagName = element.localName;\n return tagName == \"script\"\n}\n\nfunction elementIsNoscript(element) {\n const tagName = element.localName;\n return tagName == \"noscript\"\n}\n\nfunction elementIsStylesheet(element) {\n const tagName = element.localName;\n return tagName == \"style\" || (tagName == \"link\" && element.getAttribute(\"rel\") == \"stylesheet\")\n}\n\nfunction elementIsMetaElementWithName(element, name) {\n const tagName = element.localName;\n return tagName == \"meta\" && element.getAttribute(\"name\") == name\n}\n\nfunction elementWithoutNonce(element) {\n if (element.hasAttribute(\"nonce\")) {\n element.setAttribute(\"nonce\", \"\");\n }\n\n return element\n}\n\nclass PageSnapshot extends Snapshot {\n static fromHTMLString(html = \"\") {\n return this.fromDocument(parseHTMLDocument(html))\n }\n\n static fromElement(element) {\n return this.fromDocument(element.ownerDocument)\n }\n\n static fromDocument({ documentElement, body, head }) {\n return new this(documentElement, body, new HeadSnapshot(head))\n }\n\n constructor(documentElement, body, headSnapshot) {\n super(body);\n this.documentElement = documentElement;\n this.headSnapshot = headSnapshot;\n }\n\n clone() {\n const clonedElement = this.element.cloneNode(true);\n\n const selectElements = this.element.querySelectorAll(\"select\");\n const clonedSelectElements = clonedElement.querySelectorAll(\"select\");\n\n for (const [index, source] of selectElements.entries()) {\n const clone = clonedSelectElements[index];\n for (const option of clone.selectedOptions) option.selected = false;\n for (const option of source.selectedOptions) clone.options[option.index].selected = true;\n }\n\n for (const clonedPasswordInput of clonedElement.querySelectorAll('input[type=\"password\"]')) {\n clonedPasswordInput.value = \"\";\n }\n\n return new PageSnapshot(this.documentElement, clonedElement, this.headSnapshot)\n }\n\n get lang() {\n return this.documentElement.getAttribute(\"lang\")\n }\n\n get headElement() {\n return this.headSnapshot.element\n }\n\n get rootLocation() {\n const root = this.getSetting(\"root\") ?? \"/\";\n return expandURL(root)\n }\n\n get cacheControlValue() {\n return this.getSetting(\"cache-control\")\n }\n\n get isPreviewable() {\n return this.cacheControlValue != \"no-preview\"\n }\n\n get isCacheable() {\n return this.cacheControlValue != \"no-cache\"\n }\n\n get isVisitable() {\n return this.getSetting(\"visit-control\") != \"reload\"\n }\n\n get prefersViewTransitions() {\n return this.headSnapshot.getMetaValue(\"view-transition\") === \"same-origin\"\n }\n\n get shouldMorphPage() {\n return this.getSetting(\"refresh-method\") === \"morph\"\n }\n\n get shouldPreserveScrollPosition() {\n return this.getSetting(\"refresh-scroll\") === \"preserve\"\n }\n\n // Private\n\n getSetting(name) {\n return this.headSnapshot.getMetaValue(`turbo-${name}`)\n }\n}\n\nclass ViewTransitioner {\n #viewTransitionStarted = false\n #lastOperation = Promise.resolve()\n\n renderChange(useViewTransition, render) {\n if (useViewTransition && this.viewTransitionsAvailable && !this.#viewTransitionStarted) {\n this.#viewTransitionStarted = true;\n this.#lastOperation = this.#lastOperation.then(async () => {\n await document.startViewTransition(render).finished;\n });\n } else {\n this.#lastOperation = this.#lastOperation.then(render);\n }\n\n return this.#lastOperation\n }\n\n get viewTransitionsAvailable() {\n return document.startViewTransition\n }\n}\n\nconst defaultOptions = {\n action: \"advance\",\n historyChanged: false,\n visitCachedSnapshot: () => {},\n willRender: true,\n updateHistory: true,\n shouldCacheSnapshot: true,\n acceptsStreamResponse: false\n};\n\nconst TimingMetric = {\n visitStart: \"visitStart\",\n requestStart: \"requestStart\",\n requestEnd: \"requestEnd\",\n visitEnd: \"visitEnd\"\n};\n\nconst VisitState = {\n initialized: \"initialized\",\n started: \"started\",\n canceled: \"canceled\",\n failed: \"failed\",\n completed: \"completed\"\n};\n\nconst SystemStatusCode = {\n networkFailure: 0,\n timeoutFailure: -1,\n contentTypeMismatch: -2\n};\n\nconst Direction = {\n advance: \"forward\",\n restore: \"back\",\n replace: \"none\"\n};\n\nclass Visit {\n identifier = uuid() // Required by turbo-ios\n timingMetrics = {}\n\n followedRedirect = false\n historyChanged = false\n scrolled = false\n shouldCacheSnapshot = true\n acceptsStreamResponse = false\n snapshotCached = false\n state = VisitState.initialized\n viewTransitioner = new ViewTransitioner()\n\n constructor(delegate, location, restorationIdentifier, options = {}) {\n this.delegate = delegate;\n this.location = location;\n this.restorationIdentifier = restorationIdentifier || uuid();\n\n const {\n action,\n historyChanged,\n referrer,\n snapshot,\n snapshotHTML,\n response,\n visitCachedSnapshot,\n willRender,\n updateHistory,\n shouldCacheSnapshot,\n acceptsStreamResponse,\n direction\n } = {\n ...defaultOptions,\n ...options\n };\n this.action = action;\n this.historyChanged = historyChanged;\n this.referrer = referrer;\n this.snapshot = snapshot;\n this.snapshotHTML = snapshotHTML;\n this.response = response;\n this.isSamePage = this.delegate.locationWithActionIsSamePage(this.location, this.action);\n this.isPageRefresh = this.view.isPageRefresh(this);\n this.visitCachedSnapshot = visitCachedSnapshot;\n this.willRender = willRender;\n this.updateHistory = updateHistory;\n this.scrolled = !willRender;\n this.shouldCacheSnapshot = shouldCacheSnapshot;\n this.acceptsStreamResponse = acceptsStreamResponse;\n this.direction = direction || Direction[action];\n }\n\n get adapter() {\n return this.delegate.adapter\n }\n\n get view() {\n return this.delegate.view\n }\n\n get history() {\n return this.delegate.history\n }\n\n get restorationData() {\n return this.history.getRestorationDataForIdentifier(this.restorationIdentifier)\n }\n\n get silent() {\n return this.isSamePage\n }\n\n start() {\n if (this.state == VisitState.initialized) {\n this.recordTimingMetric(TimingMetric.visitStart);\n this.state = VisitState.started;\n this.adapter.visitStarted(this);\n this.delegate.visitStarted(this);\n }\n }\n\n cancel() {\n if (this.state == VisitState.started) {\n if (this.request) {\n this.request.cancel();\n }\n this.cancelRender();\n this.state = VisitState.canceled;\n }\n }\n\n complete() {\n if (this.state == VisitState.started) {\n this.recordTimingMetric(TimingMetric.visitEnd);\n this.adapter.visitCompleted(this);\n this.state = VisitState.completed;\n this.followRedirect();\n\n if (!this.followedRedirect) {\n this.delegate.visitCompleted(this);\n }\n }\n }\n\n fail() {\n if (this.state == VisitState.started) {\n this.state = VisitState.failed;\n this.adapter.visitFailed(this);\n this.delegate.visitCompleted(this);\n }\n }\n\n changeHistory() {\n if (!this.historyChanged && this.updateHistory) {\n const actionForHistory = this.location.href === this.referrer?.href ? \"replace\" : this.action;\n const method = getHistoryMethodForAction(actionForHistory);\n this.history.update(method, this.location, this.restorationIdentifier);\n this.historyChanged = true;\n }\n }\n\n issueRequest() {\n if (this.hasPreloadedResponse()) {\n this.simulateRequest();\n } else if (this.shouldIssueRequest() && !this.request) {\n this.request = new FetchRequest(this, FetchMethod.get, this.location);\n this.request.perform();\n }\n }\n\n simulateRequest() {\n if (this.response) {\n this.startRequest();\n this.recordResponse();\n this.finishRequest();\n }\n }\n\n startRequest() {\n this.recordTimingMetric(TimingMetric.requestStart);\n this.adapter.visitRequestStarted(this);\n }\n\n recordResponse(response = this.response) {\n this.response = response;\n if (response) {\n const { statusCode } = response;\n if (isSuccessful(statusCode)) {\n this.adapter.visitRequestCompleted(this);\n } else {\n this.adapter.visitRequestFailedWithStatusCode(this, statusCode);\n }\n }\n }\n\n finishRequest() {\n this.recordTimingMetric(TimingMetric.requestEnd);\n this.adapter.visitRequestFinished(this);\n }\n\n loadResponse() {\n if (this.response) {\n const { statusCode, responseHTML } = this.response;\n this.render(async () => {\n if (this.shouldCacheSnapshot) this.cacheSnapshot();\n if (this.view.renderPromise) await this.view.renderPromise;\n\n if (isSuccessful(statusCode) && responseHTML != null) {\n const snapshot = PageSnapshot.fromHTMLString(responseHTML);\n await this.renderPageSnapshot(snapshot, false);\n\n this.adapter.visitRendered(this);\n this.complete();\n } else {\n await this.view.renderError(PageSnapshot.fromHTMLString(responseHTML), this);\n this.adapter.visitRendered(this);\n this.fail();\n }\n });\n }\n }\n\n getCachedSnapshot() {\n const snapshot = this.view.getCachedSnapshotForLocation(this.location) || this.getPreloadedSnapshot();\n\n if (snapshot && (!getAnchor(this.location) || snapshot.hasAnchor(getAnchor(this.location)))) {\n if (this.action == \"restore\" || snapshot.isPreviewable) {\n return snapshot\n }\n }\n }\n\n getPreloadedSnapshot() {\n if (this.snapshotHTML) {\n return PageSnapshot.fromHTMLString(this.snapshotHTML)\n }\n }\n\n hasCachedSnapshot() {\n return this.getCachedSnapshot() != null\n }\n\n loadCachedSnapshot() {\n const snapshot = this.getCachedSnapshot();\n if (snapshot) {\n const isPreview = this.shouldIssueRequest();\n this.render(async () => {\n this.cacheSnapshot();\n if (this.isSamePage || this.isPageRefresh) {\n this.adapter.visitRendered(this);\n } else {\n if (this.view.renderPromise) await this.view.renderPromise;\n\n await this.renderPageSnapshot(snapshot, isPreview);\n\n this.adapter.visitRendered(this);\n if (!isPreview) {\n this.complete();\n }\n }\n });\n }\n }\n\n followRedirect() {\n if (this.redirectedToLocation && !this.followedRedirect && this.response?.redirected) {\n this.adapter.visitProposedToLocation(this.redirectedToLocation, {\n action: \"replace\",\n response: this.response,\n shouldCacheSnapshot: false,\n willRender: false\n });\n this.followedRedirect = true;\n }\n }\n\n goToSamePageAnchor() {\n if (this.isSamePage) {\n this.render(async () => {\n this.cacheSnapshot();\n this.performScroll();\n this.changeHistory();\n this.adapter.visitRendered(this);\n });\n }\n }\n\n // Fetch request delegate\n\n prepareRequest(request) {\n if (this.acceptsStreamResponse) {\n request.acceptResponseType(StreamMessage.contentType);\n }\n }\n\n requestStarted() {\n this.startRequest();\n }\n\n requestPreventedHandlingResponse(_request, _response) {}\n\n async requestSucceededWithResponse(request, response) {\n const responseHTML = await response.responseHTML;\n const { redirected, statusCode } = response;\n if (responseHTML == undefined) {\n this.recordResponse({\n statusCode: SystemStatusCode.contentTypeMismatch,\n redirected\n });\n } else {\n this.redirectedToLocation = response.redirected ? response.location : undefined;\n this.recordResponse({ statusCode: statusCode, responseHTML, redirected });\n }\n }\n\n async requestFailedWithResponse(request, response) {\n const responseHTML = await response.responseHTML;\n const { redirected, statusCode } = response;\n if (responseHTML == undefined) {\n this.recordResponse({\n statusCode: SystemStatusCode.contentTypeMismatch,\n redirected\n });\n } else {\n this.recordResponse({ statusCode: statusCode, responseHTML, redirected });\n }\n }\n\n requestErrored(_request, _error) {\n this.recordResponse({\n statusCode: SystemStatusCode.networkFailure,\n redirected: false\n });\n }\n\n requestFinished() {\n this.finishRequest();\n }\n\n // Scrolling\n\n performScroll() {\n if (!this.scrolled && !this.view.forceReloaded && !this.view.shouldPreserveScrollPosition(this)) {\n if (this.action == \"restore\") {\n this.scrollToRestoredPosition() || this.scrollToAnchor() || this.view.scrollToTop();\n } else {\n this.scrollToAnchor() || this.view.scrollToTop();\n }\n if (this.isSamePage) {\n this.delegate.visitScrolledToSamePageLocation(this.view.lastRenderedLocation, this.location);\n }\n\n this.scrolled = true;\n }\n }\n\n scrollToRestoredPosition() {\n const { scrollPosition } = this.restorationData;\n if (scrollPosition) {\n this.view.scrollToPosition(scrollPosition);\n return true\n }\n }\n\n scrollToAnchor() {\n const anchor = getAnchor(this.location);\n if (anchor != null) {\n this.view.scrollToAnchor(anchor);\n return true\n }\n }\n\n // Instrumentation\n\n recordTimingMetric(metric) {\n this.timingMetrics[metric] = new Date().getTime();\n }\n\n getTimingMetrics() {\n return { ...this.timingMetrics }\n }\n\n // Private\n\n getHistoryMethodForAction(action) {\n switch (action) {\n case \"replace\":\n return history.replaceState\n case \"advance\":\n case \"restore\":\n return history.pushState\n }\n }\n\n hasPreloadedResponse() {\n return typeof this.response == \"object\"\n }\n\n shouldIssueRequest() {\n if (this.isSamePage) {\n return false\n } else if (this.action == \"restore\") {\n return !this.hasCachedSnapshot()\n } else {\n return this.willRender\n }\n }\n\n cacheSnapshot() {\n if (!this.snapshotCached) {\n this.view.cacheSnapshot(this.snapshot).then((snapshot) => snapshot && this.visitCachedSnapshot(snapshot));\n this.snapshotCached = true;\n }\n }\n\n async render(callback) {\n this.cancelRender();\n await new Promise((resolve) => {\n this.frame =\n document.visibilityState === \"hidden\" ? setTimeout(() => resolve(), 0) : requestAnimationFrame(() => resolve());\n });\n await callback();\n delete this.frame;\n }\n\n async renderPageSnapshot(snapshot, isPreview) {\n await this.viewTransitioner.renderChange(this.view.shouldTransitionTo(snapshot), async () => {\n await this.view.renderPage(snapshot, isPreview, this.willRender, this);\n this.performScroll();\n });\n }\n\n cancelRender() {\n if (this.frame) {\n cancelAnimationFrame(this.frame);\n delete this.frame;\n }\n }\n}\n\nfunction isSuccessful(statusCode) {\n return statusCode >= 200 && statusCode < 300\n}\n\nclass BrowserAdapter {\n progressBar = new ProgressBar()\n\n constructor(session) {\n this.session = session;\n }\n\n visitProposedToLocation(location, options) {\n if (locationIsVisitable(location, this.navigator.rootLocation)) {\n this.navigator.startVisit(location, options?.restorationIdentifier || uuid(), options);\n } else {\n window.location.href = location.toString();\n }\n }\n\n visitStarted(visit) {\n this.location = visit.location;\n visit.loadCachedSnapshot();\n visit.issueRequest();\n visit.goToSamePageAnchor();\n }\n\n visitRequestStarted(visit) {\n this.progressBar.setValue(0);\n if (visit.hasCachedSnapshot() || visit.action != \"restore\") {\n this.showVisitProgressBarAfterDelay();\n } else {\n this.showProgressBar();\n }\n }\n\n visitRequestCompleted(visit) {\n visit.loadResponse();\n }\n\n visitRequestFailedWithStatusCode(visit, statusCode) {\n switch (statusCode) {\n case SystemStatusCode.networkFailure:\n case SystemStatusCode.timeoutFailure:\n case SystemStatusCode.contentTypeMismatch:\n return this.reload({\n reason: \"request_failed\",\n context: {\n statusCode\n }\n })\n default:\n return visit.loadResponse()\n }\n }\n\n visitRequestFinished(_visit) {}\n\n visitCompleted(_visit) {\n this.progressBar.setValue(1);\n this.hideVisitProgressBar();\n }\n\n pageInvalidated(reason) {\n this.reload(reason);\n }\n\n visitFailed(_visit) {\n this.progressBar.setValue(1);\n this.hideVisitProgressBar();\n }\n\n visitRendered(_visit) {}\n\n // Form Submission Delegate\n\n formSubmissionStarted(_formSubmission) {\n this.progressBar.setValue(0);\n this.showFormProgressBarAfterDelay();\n }\n\n formSubmissionFinished(_formSubmission) {\n this.progressBar.setValue(1);\n this.hideFormProgressBar();\n }\n\n // Private\n\n showVisitProgressBarAfterDelay() {\n this.visitProgressBarTimeout = window.setTimeout(this.showProgressBar, this.session.progressBarDelay);\n }\n\n hideVisitProgressBar() {\n this.progressBar.hide();\n if (this.visitProgressBarTimeout != null) {\n window.clearTimeout(this.visitProgressBarTimeout);\n delete this.visitProgressBarTimeout;\n }\n }\n\n showFormProgressBarAfterDelay() {\n if (this.formProgressBarTimeout == null) {\n this.formProgressBarTimeout = window.setTimeout(this.showProgressBar, this.session.progressBarDelay);\n }\n }\n\n hideFormProgressBar() {\n this.progressBar.hide();\n if (this.formProgressBarTimeout != null) {\n window.clearTimeout(this.formProgressBarTimeout);\n delete this.formProgressBarTimeout;\n }\n }\n\n showProgressBar = () => {\n this.progressBar.show();\n }\n\n reload(reason) {\n dispatch(\"turbo:reload\", { detail: reason });\n\n window.location.href = this.location?.toString() || window.location.href;\n }\n\n get navigator() {\n return this.session.navigator\n }\n}\n\nclass CacheObserver {\n selector = \"[data-turbo-temporary]\"\n deprecatedSelector = \"[data-turbo-cache=false]\"\n\n started = false\n\n start() {\n if (!this.started) {\n this.started = true;\n addEventListener(\"turbo:before-cache\", this.removeTemporaryElements, false);\n }\n }\n\n stop() {\n if (this.started) {\n this.started = false;\n removeEventListener(\"turbo:before-cache\", this.removeTemporaryElements, false);\n }\n }\n\n removeTemporaryElements = (_event) => {\n for (const element of this.temporaryElements) {\n element.remove();\n }\n }\n\n get temporaryElements() {\n return [...document.querySelectorAll(this.selector), ...this.temporaryElementsWithDeprecation]\n }\n\n get temporaryElementsWithDeprecation() {\n const elements = document.querySelectorAll(this.deprecatedSelector);\n\n if (elements.length) {\n console.warn(\n `The ${this.deprecatedSelector} selector is deprecated and will be removed in a future version. Use ${this.selector} instead.`\n );\n }\n\n return [...elements]\n }\n}\n\nclass FrameRedirector {\n constructor(session, element) {\n this.session = session;\n this.element = element;\n this.linkInterceptor = new LinkInterceptor(this, element);\n this.formSubmitObserver = new FormSubmitObserver(this, element);\n }\n\n start() {\n this.linkInterceptor.start();\n this.formSubmitObserver.start();\n }\n\n stop() {\n this.linkInterceptor.stop();\n this.formSubmitObserver.stop();\n }\n\n // Link interceptor delegate\n\n shouldInterceptLinkClick(element, _location, _event) {\n return this.#shouldRedirect(element)\n }\n\n linkClickIntercepted(element, url, event) {\n const frame = this.#findFrameElement(element);\n if (frame) {\n frame.delegate.linkClickIntercepted(element, url, event);\n }\n }\n\n // Form submit observer delegate\n\n willSubmitForm(element, submitter) {\n return (\n element.closest(\"turbo-frame\") == null &&\n this.#shouldSubmit(element, submitter) &&\n this.#shouldRedirect(element, submitter)\n )\n }\n\n formSubmitted(element, submitter) {\n const frame = this.#findFrameElement(element, submitter);\n if (frame) {\n frame.delegate.formSubmitted(element, submitter);\n }\n }\n\n #shouldSubmit(form, submitter) {\n const action = getAction$1(form, submitter);\n const meta = this.element.ownerDocument.querySelector(`meta[name=\"turbo-root\"]`);\n const rootLocation = expandURL(meta?.content ?? \"/\");\n\n return this.#shouldRedirect(form, submitter) && locationIsVisitable(action, rootLocation)\n }\n\n #shouldRedirect(element, submitter) {\n const isNavigatable =\n element instanceof HTMLFormElement\n ? this.session.submissionIsNavigatable(element, submitter)\n : this.session.elementIsNavigatable(element);\n\n if (isNavigatable) {\n const frame = this.#findFrameElement(element, submitter);\n return frame ? frame != element.closest(\"turbo-frame\") : false\n } else {\n return false\n }\n }\n\n #findFrameElement(element, submitter) {\n const id = submitter?.getAttribute(\"data-turbo-frame\") || element.getAttribute(\"data-turbo-frame\");\n if (id && id != \"_top\") {\n const frame = this.element.querySelector(`#${id}:not([disabled])`);\n if (frame instanceof FrameElement) {\n return frame\n }\n }\n }\n}\n\nclass History {\n location\n restorationIdentifier = uuid()\n restorationData = {}\n started = false\n pageLoaded = false\n currentIndex = 0\n\n constructor(delegate) {\n this.delegate = delegate;\n }\n\n start() {\n if (!this.started) {\n addEventListener(\"popstate\", this.onPopState, false);\n addEventListener(\"load\", this.onPageLoad, false);\n this.currentIndex = history.state?.turbo?.restorationIndex || 0;\n this.started = true;\n this.replace(new URL(window.location.href));\n }\n }\n\n stop() {\n if (this.started) {\n removeEventListener(\"popstate\", this.onPopState, false);\n removeEventListener(\"load\", this.onPageLoad, false);\n this.started = false;\n }\n }\n\n push(location, restorationIdentifier) {\n this.update(history.pushState, location, restorationIdentifier);\n }\n\n replace(location, restorationIdentifier) {\n this.update(history.replaceState, location, restorationIdentifier);\n }\n\n update(method, location, restorationIdentifier = uuid()) {\n if (method === history.pushState) ++this.currentIndex;\n\n const state = { turbo: { restorationIdentifier, restorationIndex: this.currentIndex } };\n method.call(history, state, \"\", location.href);\n this.location = location;\n this.restorationIdentifier = restorationIdentifier;\n }\n\n // Restoration data\n\n getRestorationDataForIdentifier(restorationIdentifier) {\n return this.restorationData[restorationIdentifier] || {}\n }\n\n updateRestorationData(additionalData) {\n const { restorationIdentifier } = this;\n const restorationData = this.restorationData[restorationIdentifier];\n this.restorationData[restorationIdentifier] = {\n ...restorationData,\n ...additionalData\n };\n }\n\n // Scroll restoration\n\n assumeControlOfScrollRestoration() {\n if (!this.previousScrollRestoration) {\n this.previousScrollRestoration = history.scrollRestoration ?? \"auto\";\n history.scrollRestoration = \"manual\";\n }\n }\n\n relinquishControlOfScrollRestoration() {\n if (this.previousScrollRestoration) {\n history.scrollRestoration = this.previousScrollRestoration;\n delete this.previousScrollRestoration;\n }\n }\n\n // Event handlers\n\n onPopState = (event) => {\n if (this.shouldHandlePopState()) {\n const { turbo } = event.state || {};\n if (turbo) {\n this.location = new URL(window.location.href);\n const { restorationIdentifier, restorationIndex } = turbo;\n this.restorationIdentifier = restorationIdentifier;\n const direction = restorationIndex > this.currentIndex ? \"forward\" : \"back\";\n this.delegate.historyPoppedToLocationWithRestorationIdentifierAndDirection(this.location, restorationIdentifier, direction);\n this.currentIndex = restorationIndex;\n }\n }\n }\n\n onPageLoad = async (_event) => {\n await nextMicrotask();\n this.pageLoaded = true;\n }\n\n // Private\n\n shouldHandlePopState() {\n // Safari dispatches a popstate event after window's load event, ignore it\n return this.pageIsLoaded()\n }\n\n pageIsLoaded() {\n return this.pageLoaded || document.readyState == \"complete\"\n }\n}\n\nclass LinkPrefetchObserver {\n started = false\n #prefetchedLink = null\n\n constructor(delegate, eventTarget) {\n this.delegate = delegate;\n this.eventTarget = eventTarget;\n }\n\n start() {\n if (this.started) return\n\n if (this.eventTarget.readyState === \"loading\") {\n this.eventTarget.addEventListener(\"DOMContentLoaded\", this.#enable, { once: true });\n } else {\n this.#enable();\n }\n }\n\n stop() {\n if (!this.started) return\n\n this.eventTarget.removeEventListener(\"mouseenter\", this.#tryToPrefetchRequest, {\n capture: true,\n passive: true\n });\n this.eventTarget.removeEventListener(\"mouseleave\", this.#cancelRequestIfObsolete, {\n capture: true,\n passive: true\n });\n\n this.eventTarget.removeEventListener(\"turbo:before-fetch-request\", this.#tryToUsePrefetchedRequest, true);\n this.started = false;\n }\n\n #enable = () => {\n this.eventTarget.addEventListener(\"mouseenter\", this.#tryToPrefetchRequest, {\n capture: true,\n passive: true\n });\n this.eventTarget.addEventListener(\"mouseleave\", this.#cancelRequestIfObsolete, {\n capture: true,\n passive: true\n });\n\n this.eventTarget.addEventListener(\"turbo:before-fetch-request\", this.#tryToUsePrefetchedRequest, true);\n this.started = true;\n }\n\n #tryToPrefetchRequest = (event) => {\n if (getMetaContent(\"turbo-prefetch\") === \"false\") return\n\n const target = event.target;\n const isLink = target.matches && target.matches(\"a[href]:not([target^=_]):not([download])\");\n\n if (isLink && this.#isPrefetchable(target)) {\n const link = target;\n const location = getLocationForLink(link);\n\n if (this.delegate.canPrefetchRequestToLocation(link, location)) {\n this.#prefetchedLink = link;\n\n const fetchRequest = new FetchRequest(\n this,\n FetchMethod.get,\n location,\n new URLSearchParams(),\n target\n );\n\n prefetchCache.setLater(location.toString(), fetchRequest, this.#cacheTtl);\n }\n }\n }\n\n #cancelRequestIfObsolete = (event) => {\n if (event.target === this.#prefetchedLink) this.#cancelPrefetchRequest();\n }\n\n #cancelPrefetchRequest = () => {\n prefetchCache.clear();\n this.#prefetchedLink = null;\n }\n\n #tryToUsePrefetchedRequest = (event) => {\n if (event.target.tagName !== \"FORM\" && event.detail.fetchOptions.method === \"GET\") {\n const cached = prefetchCache.get(event.detail.url.toString());\n\n if (cached) {\n // User clicked link, use cache response\n event.detail.fetchRequest = cached;\n }\n\n prefetchCache.clear();\n }\n }\n\n prepareRequest(request) {\n const link = request.target;\n\n request.headers[\"X-Sec-Purpose\"] = \"prefetch\";\n\n const turboFrame = link.closest(\"turbo-frame\");\n const turboFrameTarget = link.getAttribute(\"data-turbo-frame\") || turboFrame?.getAttribute(\"target\") || turboFrame?.id;\n\n if (turboFrameTarget && turboFrameTarget !== \"_top\") {\n request.headers[\"Turbo-Frame\"] = turboFrameTarget;\n }\n }\n\n // Fetch request interface\n\n requestSucceededWithResponse() {}\n\n requestStarted(fetchRequest) {}\n\n requestErrored(fetchRequest) {}\n\n requestFinished(fetchRequest) {}\n\n requestPreventedHandlingResponse(fetchRequest, fetchResponse) {}\n\n requestFailedWithResponse(fetchRequest, fetchResponse) {}\n\n get #cacheTtl() {\n return Number(getMetaContent(\"turbo-prefetch-cache-time\")) || cacheTtl\n }\n\n #isPrefetchable(link) {\n const href = link.getAttribute(\"href\");\n\n if (!href) return false\n\n if (unfetchableLink(link)) return false\n if (linkToTheSamePage(link)) return false\n if (linkOptsOut(link)) return false\n if (nonSafeLink(link)) return false\n if (eventPrevented(link)) return false\n\n return true\n }\n}\n\nconst unfetchableLink = (link) => {\n return link.origin !== document.location.origin || ![\"http:\", \"https:\"].includes(link.protocol) || link.hasAttribute(\"target\")\n};\n\nconst linkToTheSamePage = (link) => {\n return (link.pathname + link.search === document.location.pathname + document.location.search) || link.href.startsWith(\"#\")\n};\n\nconst linkOptsOut = (link) => {\n if (link.getAttribute(\"data-turbo-prefetch\") === \"false\") return true\n if (link.getAttribute(\"data-turbo\") === \"false\") return true\n\n const turboPrefetchParent = findClosestRecursively(link, \"[data-turbo-prefetch]\");\n if (turboPrefetchParent && turboPrefetchParent.getAttribute(\"data-turbo-prefetch\") === \"false\") return true\n\n return false\n};\n\nconst nonSafeLink = (link) => {\n const turboMethod = link.getAttribute(\"data-turbo-method\");\n if (turboMethod && turboMethod.toLowerCase() !== \"get\") return true\n\n if (isUJS(link)) return true\n if (link.hasAttribute(\"data-turbo-confirm\")) return true\n if (link.hasAttribute(\"data-turbo-stream\")) return true\n\n return false\n};\n\nconst isUJS = (link) => {\n return link.hasAttribute(\"data-remote\") || link.hasAttribute(\"data-behavior\") || link.hasAttribute(\"data-confirm\") || link.hasAttribute(\"data-method\")\n};\n\nconst eventPrevented = (link) => {\n const event = dispatch(\"turbo:before-prefetch\", { target: link, cancelable: true });\n return event.defaultPrevented\n};\n\nclass Navigator {\n constructor(delegate) {\n this.delegate = delegate;\n }\n\n proposeVisit(location, options = {}) {\n if (this.delegate.allowsVisitingLocationWithAction(location, options.action)) {\n this.delegate.visitProposedToLocation(location, options);\n }\n }\n\n startVisit(locatable, restorationIdentifier, options = {}) {\n this.stop();\n this.currentVisit = new Visit(this, expandURL(locatable), restorationIdentifier, {\n referrer: this.location,\n ...options\n });\n this.currentVisit.start();\n }\n\n submitForm(form, submitter) {\n this.stop();\n this.formSubmission = new FormSubmission(this, form, submitter, true);\n\n this.formSubmission.start();\n }\n\n stop() {\n if (this.formSubmission) {\n this.formSubmission.stop();\n delete this.formSubmission;\n }\n\n if (this.currentVisit) {\n this.currentVisit.cancel();\n delete this.currentVisit;\n }\n }\n\n get adapter() {\n return this.delegate.adapter\n }\n\n get view() {\n return this.delegate.view\n }\n\n get rootLocation() {\n return this.view.snapshot.rootLocation\n }\n\n get history() {\n return this.delegate.history\n }\n\n // Form submission delegate\n\n formSubmissionStarted(formSubmission) {\n // Not all adapters implement formSubmissionStarted\n if (typeof this.adapter.formSubmissionStarted === \"function\") {\n this.adapter.formSubmissionStarted(formSubmission);\n }\n }\n\n async formSubmissionSucceededWithResponse(formSubmission, fetchResponse) {\n if (formSubmission == this.formSubmission) {\n const responseHTML = await fetchResponse.responseHTML;\n if (responseHTML) {\n const shouldCacheSnapshot = formSubmission.isSafe;\n if (!shouldCacheSnapshot) {\n this.view.clearSnapshotCache();\n }\n\n const { statusCode, redirected } = fetchResponse;\n const action = this.#getActionForFormSubmission(formSubmission, fetchResponse);\n const visitOptions = {\n action,\n shouldCacheSnapshot,\n response: { statusCode, responseHTML, redirected }\n };\n this.proposeVisit(fetchResponse.location, visitOptions);\n }\n }\n }\n\n async formSubmissionFailedWithResponse(formSubmission, fetchResponse) {\n const responseHTML = await fetchResponse.responseHTML;\n\n if (responseHTML) {\n const snapshot = PageSnapshot.fromHTMLString(responseHTML);\n if (fetchResponse.serverError) {\n await this.view.renderError(snapshot, this.currentVisit);\n } else {\n await this.view.renderPage(snapshot, false, true, this.currentVisit);\n }\n if(!snapshot.shouldPreserveScrollPosition) {\n this.view.scrollToTop();\n }\n this.view.clearSnapshotCache();\n }\n }\n\n formSubmissionErrored(formSubmission, error) {\n console.error(error);\n }\n\n formSubmissionFinished(formSubmission) {\n // Not all adapters implement formSubmissionFinished\n if (typeof this.adapter.formSubmissionFinished === \"function\") {\n this.adapter.formSubmissionFinished(formSubmission);\n }\n }\n\n // Visit delegate\n\n visitStarted(visit) {\n this.delegate.visitStarted(visit);\n }\n\n visitCompleted(visit) {\n this.delegate.visitCompleted(visit);\n delete this.currentVisit;\n }\n\n locationWithActionIsSamePage(location, action) {\n const anchor = getAnchor(location);\n const currentAnchor = getAnchor(this.view.lastRenderedLocation);\n const isRestorationToTop = action === \"restore\" && typeof anchor === \"undefined\";\n\n return (\n action !== \"replace\" &&\n getRequestURL(location) === getRequestURL(this.view.lastRenderedLocation) &&\n (isRestorationToTop || (anchor != null && anchor !== currentAnchor))\n )\n }\n\n visitScrolledToSamePageLocation(oldURL, newURL) {\n this.delegate.visitScrolledToSamePageLocation(oldURL, newURL);\n }\n\n // Visits\n\n get location() {\n return this.history.location\n }\n\n get restorationIdentifier() {\n return this.history.restorationIdentifier\n }\n\n #getActionForFormSubmission(formSubmission, fetchResponse) {\n const { submitter, formElement } = formSubmission;\n return getVisitAction(submitter, formElement) || this.#getDefaultAction(fetchResponse)\n }\n\n #getDefaultAction(fetchResponse) {\n const sameLocationRedirect = fetchResponse.redirected && fetchResponse.location.href === this.location?.href;\n return sameLocationRedirect ? \"replace\" : \"advance\"\n }\n}\n\nconst PageStage = {\n initial: 0,\n loading: 1,\n interactive: 2,\n complete: 3\n};\n\nclass PageObserver {\n stage = PageStage.initial\n started = false\n\n constructor(delegate) {\n this.delegate = delegate;\n }\n\n start() {\n if (!this.started) {\n if (this.stage == PageStage.initial) {\n this.stage = PageStage.loading;\n }\n document.addEventListener(\"readystatechange\", this.interpretReadyState, false);\n addEventListener(\"pagehide\", this.pageWillUnload, false);\n this.started = true;\n }\n }\n\n stop() {\n if (this.started) {\n document.removeEventListener(\"readystatechange\", this.interpretReadyState, false);\n removeEventListener(\"pagehide\", this.pageWillUnload, false);\n this.started = false;\n }\n }\n\n interpretReadyState = () => {\n const { readyState } = this;\n if (readyState == \"interactive\") {\n this.pageIsInteractive();\n } else if (readyState == \"complete\") {\n this.pageIsComplete();\n }\n }\n\n pageIsInteractive() {\n if (this.stage == PageStage.loading) {\n this.stage = PageStage.interactive;\n this.delegate.pageBecameInteractive();\n }\n }\n\n pageIsComplete() {\n this.pageIsInteractive();\n if (this.stage == PageStage.interactive) {\n this.stage = PageStage.complete;\n this.delegate.pageLoaded();\n }\n }\n\n pageWillUnload = () => {\n this.delegate.pageWillUnload();\n }\n\n get readyState() {\n return document.readyState\n }\n}\n\nclass ScrollObserver {\n started = false\n\n constructor(delegate) {\n this.delegate = delegate;\n }\n\n start() {\n if (!this.started) {\n addEventListener(\"scroll\", this.onScroll, false);\n this.onScroll();\n this.started = true;\n }\n }\n\n stop() {\n if (this.started) {\n removeEventListener(\"scroll\", this.onScroll, false);\n this.started = false;\n }\n }\n\n onScroll = () => {\n this.updatePosition({ x: window.pageXOffset, y: window.pageYOffset });\n }\n\n // Private\n\n updatePosition(position) {\n this.delegate.scrollPositionChanged(position);\n }\n}\n\nclass StreamMessageRenderer {\n render({ fragment }) {\n Bardo.preservingPermanentElements(this, getPermanentElementMapForFragment(fragment), () => {\n withAutofocusFromFragment(fragment, () => {\n withPreservedFocus(() => {\n document.documentElement.appendChild(fragment);\n });\n });\n });\n }\n\n // Bardo delegate\n\n enteringBardo(currentPermanentElement, newPermanentElement) {\n newPermanentElement.replaceWith(currentPermanentElement.cloneNode(true));\n }\n\n leavingBardo() {}\n}\n\nfunction getPermanentElementMapForFragment(fragment) {\n const permanentElementsInDocument = queryPermanentElementsAll(document.documentElement);\n const permanentElementMap = {};\n for (const permanentElementInDocument of permanentElementsInDocument) {\n const { id } = permanentElementInDocument;\n\n for (const streamElement of fragment.querySelectorAll(\"turbo-stream\")) {\n const elementInStream = getPermanentElementById(streamElement.templateElement.content, id);\n\n if (elementInStream) {\n permanentElementMap[id] = [permanentElementInDocument, elementInStream];\n }\n }\n }\n\n return permanentElementMap\n}\n\nasync function withAutofocusFromFragment(fragment, callback) {\n const generatedID = `turbo-stream-autofocus-${uuid()}`;\n const turboStreams = fragment.querySelectorAll(\"turbo-stream\");\n const elementWithAutofocus = firstAutofocusableElementInStreams(turboStreams);\n let willAutofocusId = null;\n\n if (elementWithAutofocus) {\n if (elementWithAutofocus.id) {\n willAutofocusId = elementWithAutofocus.id;\n } else {\n willAutofocusId = generatedID;\n }\n\n elementWithAutofocus.id = willAutofocusId;\n }\n\n callback();\n await nextRepaint();\n\n const hasNoActiveElement = document.activeElement == null || document.activeElement == document.body;\n\n if (hasNoActiveElement && willAutofocusId) {\n const elementToAutofocus = document.getElementById(willAutofocusId);\n\n if (elementIsFocusable(elementToAutofocus)) {\n elementToAutofocus.focus();\n }\n if (elementToAutofocus && elementToAutofocus.id == generatedID) {\n elementToAutofocus.removeAttribute(\"id\");\n }\n }\n}\n\nasync function withPreservedFocus(callback) {\n const [activeElementBeforeRender, activeElementAfterRender] = await around(callback, () => document.activeElement);\n\n const restoreFocusTo = activeElementBeforeRender && activeElementBeforeRender.id;\n\n if (restoreFocusTo) {\n const elementToFocus = document.getElementById(restoreFocusTo);\n\n if (elementIsFocusable(elementToFocus) && elementToFocus != activeElementAfterRender) {\n elementToFocus.focus();\n }\n }\n}\n\nfunction firstAutofocusableElementInStreams(nodeListOfStreamElements) {\n for (const streamElement of nodeListOfStreamElements) {\n const elementWithAutofocus = queryAutofocusableElement(streamElement.templateElement.content);\n\n if (elementWithAutofocus) return elementWithAutofocus\n }\n\n return null\n}\n\nclass StreamObserver {\n sources = new Set()\n #started = false\n\n constructor(delegate) {\n this.delegate = delegate;\n }\n\n start() {\n if (!this.#started) {\n this.#started = true;\n addEventListener(\"turbo:before-fetch-response\", this.inspectFetchResponse, false);\n }\n }\n\n stop() {\n if (this.#started) {\n this.#started = false;\n removeEventListener(\"turbo:before-fetch-response\", this.inspectFetchResponse, false);\n }\n }\n\n connectStreamSource(source) {\n if (!this.streamSourceIsConnected(source)) {\n this.sources.add(source);\n source.addEventListener(\"message\", this.receiveMessageEvent, false);\n }\n }\n\n disconnectStreamSource(source) {\n if (this.streamSourceIsConnected(source)) {\n this.sources.delete(source);\n source.removeEventListener(\"message\", this.receiveMessageEvent, false);\n }\n }\n\n streamSourceIsConnected(source) {\n return this.sources.has(source)\n }\n\n inspectFetchResponse = (event) => {\n const response = fetchResponseFromEvent(event);\n if (response && fetchResponseIsStream(response)) {\n event.preventDefault();\n this.receiveMessageResponse(response);\n }\n }\n\n receiveMessageEvent = (event) => {\n if (this.#started && typeof event.data == \"string\") {\n this.receiveMessageHTML(event.data);\n }\n }\n\n async receiveMessageResponse(response) {\n const html = await response.responseHTML;\n if (html) {\n this.receiveMessageHTML(html);\n }\n }\n\n receiveMessageHTML(html) {\n this.delegate.receivedMessageFromStream(StreamMessage.wrap(html));\n }\n}\n\nfunction fetchResponseFromEvent(event) {\n const fetchResponse = event.detail?.fetchResponse;\n if (fetchResponse instanceof FetchResponse) {\n return fetchResponse\n }\n}\n\nfunction fetchResponseIsStream(response) {\n const contentType = response.contentType ?? \"\";\n return contentType.startsWith(StreamMessage.contentType)\n}\n\nclass ErrorRenderer extends Renderer {\n static renderElement(currentElement, newElement) {\n const { documentElement, body } = document;\n\n documentElement.replaceChild(newElement, body);\n }\n\n async render() {\n this.replaceHeadAndBody();\n this.activateScriptElements();\n }\n\n replaceHeadAndBody() {\n const { documentElement, head } = document;\n documentElement.replaceChild(this.newHead, head);\n this.renderElement(this.currentElement, this.newElement);\n }\n\n activateScriptElements() {\n for (const replaceableElement of this.scriptElements) {\n const parentNode = replaceableElement.parentNode;\n if (parentNode) {\n const element = activateScriptElement(replaceableElement);\n parentNode.replaceChild(element, replaceableElement);\n }\n }\n }\n\n get newHead() {\n return this.newSnapshot.headSnapshot.element\n }\n\n get scriptElements() {\n return document.documentElement.querySelectorAll(\"script\")\n }\n}\n\nclass PageRenderer extends Renderer {\n static renderElement(currentElement, newElement) {\n if (document.body && newElement instanceof HTMLBodyElement) {\n document.body.replaceWith(newElement);\n } else {\n document.documentElement.appendChild(newElement);\n }\n }\n\n get shouldRender() {\n return this.newSnapshot.isVisitable && this.trackedElementsAreIdentical\n }\n\n get reloadReason() {\n if (!this.newSnapshot.isVisitable) {\n return {\n reason: \"turbo_visit_control_is_reload\"\n }\n }\n\n if (!this.trackedElementsAreIdentical) {\n return {\n reason: \"tracked_element_mismatch\"\n }\n }\n }\n\n async prepareToRender() {\n this.#setLanguage();\n await this.mergeHead();\n }\n\n async render() {\n if (this.willRender) {\n await this.replaceBody();\n }\n }\n\n finishRendering() {\n super.finishRendering();\n if (!this.isPreview) {\n this.focusFirstAutofocusableElement();\n }\n }\n\n get currentHeadSnapshot() {\n return this.currentSnapshot.headSnapshot\n }\n\n get newHeadSnapshot() {\n return this.newSnapshot.headSnapshot\n }\n\n get newElement() {\n return this.newSnapshot.element\n }\n\n #setLanguage() {\n const { documentElement } = this.currentSnapshot;\n const { lang } = this.newSnapshot;\n\n if (lang) {\n documentElement.setAttribute(\"lang\", lang);\n } else {\n documentElement.removeAttribute(\"lang\");\n }\n }\n\n async mergeHead() {\n const mergedHeadElements = this.mergeProvisionalElements();\n const newStylesheetElements = this.copyNewHeadStylesheetElements();\n this.copyNewHeadScriptElements();\n\n await mergedHeadElements;\n await newStylesheetElements;\n\n if (this.willRender) {\n this.removeUnusedDynamicStylesheetElements();\n }\n }\n\n async replaceBody() {\n await this.preservingPermanentElements(async () => {\n this.activateNewBody();\n await this.assignNewBody();\n });\n }\n\n get trackedElementsAreIdentical() {\n return this.currentHeadSnapshot.trackedElementSignature == this.newHeadSnapshot.trackedElementSignature\n }\n\n async copyNewHeadStylesheetElements() {\n const loadingElements = [];\n\n for (const element of this.newHeadStylesheetElements) {\n loadingElements.push(waitForLoad(element));\n\n document.head.appendChild(element);\n }\n\n await Promise.all(loadingElements);\n }\n\n copyNewHeadScriptElements() {\n for (const element of this.newHeadScriptElements) {\n document.head.appendChild(activateScriptElement(element));\n }\n }\n\n removeUnusedDynamicStylesheetElements() {\n for (const element of this.unusedDynamicStylesheetElements) {\n document.head.removeChild(element);\n }\n }\n\n async mergeProvisionalElements() {\n const newHeadElements = [...this.newHeadProvisionalElements];\n\n for (const element of this.currentHeadProvisionalElements) {\n if (!this.isCurrentElementInElementList(element, newHeadElements)) {\n document.head.removeChild(element);\n }\n }\n\n for (const element of newHeadElements) {\n document.head.appendChild(element);\n }\n }\n\n isCurrentElementInElementList(element, elementList) {\n for (const [index, newElement] of elementList.entries()) {\n // if title element...\n if (element.tagName == \"TITLE\") {\n if (newElement.tagName != \"TITLE\") {\n continue\n }\n if (element.innerHTML == newElement.innerHTML) {\n elementList.splice(index, 1);\n return true\n }\n }\n\n // if any other element...\n if (newElement.isEqualNode(element)) {\n elementList.splice(index, 1);\n return true\n }\n }\n\n return false\n }\n\n removeCurrentHeadProvisionalElements() {\n for (const element of this.currentHeadProvisionalElements) {\n document.head.removeChild(element);\n }\n }\n\n copyNewHeadProvisionalElements() {\n for (const element of this.newHeadProvisionalElements) {\n document.head.appendChild(element);\n }\n }\n\n activateNewBody() {\n document.adoptNode(this.newElement);\n this.activateNewBodyScriptElements();\n }\n\n activateNewBodyScriptElements() {\n for (const inertScriptElement of this.newBodyScriptElements) {\n const activatedScriptElement = activateScriptElement(inertScriptElement);\n inertScriptElement.replaceWith(activatedScriptElement);\n }\n }\n\n async assignNewBody() {\n await this.renderElement(this.currentElement, this.newElement);\n }\n\n get unusedDynamicStylesheetElements() {\n return this.oldHeadStylesheetElements.filter((element) => {\n return element.getAttribute(\"data-turbo-track\") === \"dynamic\"\n })\n }\n\n get oldHeadStylesheetElements() {\n return this.currentHeadSnapshot.getStylesheetElementsNotInSnapshot(this.newHeadSnapshot)\n }\n\n get newHeadStylesheetElements() {\n return this.newHeadSnapshot.getStylesheetElementsNotInSnapshot(this.currentHeadSnapshot)\n }\n\n get newHeadScriptElements() {\n return this.newHeadSnapshot.getScriptElementsNotInSnapshot(this.currentHeadSnapshot)\n }\n\n get currentHeadProvisionalElements() {\n return this.currentHeadSnapshot.provisionalElements\n }\n\n get newHeadProvisionalElements() {\n return this.newHeadSnapshot.provisionalElements\n }\n\n get newBodyScriptElements() {\n return this.newElement.querySelectorAll(\"script\")\n }\n}\n\nclass MorphingPageRenderer extends PageRenderer {\n static renderElement(currentElement, newElement) {\n morphElements(currentElement, newElement, {\n callbacks: {\n beforeNodeMorphed: element => !canRefreshFrame(element)\n }\n });\n\n for (const frame of currentElement.querySelectorAll(\"turbo-frame\")) {\n if (canRefreshFrame(frame)) frame.reload();\n }\n\n dispatch(\"turbo:morph\", { detail: { currentElement, newElement } });\n }\n\n async preservingPermanentElements(callback) {\n return await callback()\n }\n\n get renderMethod() {\n return \"morph\"\n }\n\n get shouldAutofocus() {\n return false\n }\n}\n\nfunction canRefreshFrame(frame) {\n return frame instanceof FrameElement &&\n frame.src &&\n frame.refresh === \"morph\" &&\n !frame.closest(\"[data-turbo-permanent]\")\n}\n\nclass SnapshotCache {\n keys = []\n snapshots = {}\n\n constructor(size) {\n this.size = size;\n }\n\n has(location) {\n return toCacheKey(location) in this.snapshots\n }\n\n get(location) {\n if (this.has(location)) {\n const snapshot = this.read(location);\n this.touch(location);\n return snapshot\n }\n }\n\n put(location, snapshot) {\n this.write(location, snapshot);\n this.touch(location);\n return snapshot\n }\n\n clear() {\n this.snapshots = {};\n }\n\n // Private\n\n read(location) {\n return this.snapshots[toCacheKey(location)]\n }\n\n write(location, snapshot) {\n this.snapshots[toCacheKey(location)] = snapshot;\n }\n\n touch(location) {\n const key = toCacheKey(location);\n const index = this.keys.indexOf(key);\n if (index > -1) this.keys.splice(index, 1);\n this.keys.unshift(key);\n this.trim();\n }\n\n trim() {\n for (const key of this.keys.splice(this.size)) {\n delete this.snapshots[key];\n }\n }\n}\n\nclass PageView extends View {\n snapshotCache = new SnapshotCache(10)\n lastRenderedLocation = new URL(location.href)\n forceReloaded = false\n\n shouldTransitionTo(newSnapshot) {\n return this.snapshot.prefersViewTransitions && newSnapshot.prefersViewTransitions\n }\n\n renderPage(snapshot, isPreview = false, willRender = true, visit) {\n const shouldMorphPage = this.isPageRefresh(visit) && this.snapshot.shouldMorphPage;\n const rendererClass = shouldMorphPage ? MorphingPageRenderer : PageRenderer;\n\n const renderer = new rendererClass(this.snapshot, snapshot, isPreview, willRender);\n\n if (!renderer.shouldRender) {\n this.forceReloaded = true;\n } else {\n visit?.changeHistory();\n }\n\n return this.render(renderer)\n }\n\n renderError(snapshot, visit) {\n visit?.changeHistory();\n const renderer = new ErrorRenderer(this.snapshot, snapshot, false);\n return this.render(renderer)\n }\n\n clearSnapshotCache() {\n this.snapshotCache.clear();\n }\n\n async cacheSnapshot(snapshot = this.snapshot) {\n if (snapshot.isCacheable) {\n this.delegate.viewWillCacheSnapshot();\n const { lastRenderedLocation: location } = this;\n await nextEventLoopTick();\n const cachedSnapshot = snapshot.clone();\n this.snapshotCache.put(location, cachedSnapshot);\n return cachedSnapshot\n }\n }\n\n getCachedSnapshotForLocation(location) {\n return this.snapshotCache.get(location)\n }\n\n isPageRefresh(visit) {\n return !visit || (this.lastRenderedLocation.pathname === visit.location.pathname && visit.action === \"replace\")\n }\n\n shouldPreserveScrollPosition(visit) {\n return this.isPageRefresh(visit) && this.snapshot.shouldPreserveScrollPosition\n }\n\n get snapshot() {\n return PageSnapshot.fromElement(this.element)\n }\n}\n\nclass Preloader {\n selector = \"a[data-turbo-preload]\"\n\n constructor(delegate, snapshotCache) {\n this.delegate = delegate;\n this.snapshotCache = snapshotCache;\n }\n\n start() {\n if (document.readyState === \"loading\") {\n document.addEventListener(\"DOMContentLoaded\", this.#preloadAll);\n } else {\n this.preloadOnLoadLinksForView(document.body);\n }\n }\n\n stop() {\n document.removeEventListener(\"DOMContentLoaded\", this.#preloadAll);\n }\n\n preloadOnLoadLinksForView(element) {\n for (const link of element.querySelectorAll(this.selector)) {\n if (this.delegate.shouldPreloadLink(link)) {\n this.preloadURL(link);\n }\n }\n }\n\n async preloadURL(link) {\n const location = new URL(link.href);\n\n if (this.snapshotCache.has(location)) {\n return\n }\n\n const fetchRequest = new FetchRequest(this, FetchMethod.get, location, new URLSearchParams(), link);\n await fetchRequest.perform();\n }\n\n // Fetch request delegate\n\n prepareRequest(fetchRequest) {\n fetchRequest.headers[\"X-Sec-Purpose\"] = \"prefetch\";\n }\n\n async requestSucceededWithResponse(fetchRequest, fetchResponse) {\n try {\n const responseHTML = await fetchResponse.responseHTML;\n const snapshot = PageSnapshot.fromHTMLString(responseHTML);\n\n this.snapshotCache.put(fetchRequest.url, snapshot);\n } catch (_) {\n // If we cannot preload that is ok!\n }\n }\n\n requestStarted(fetchRequest) {}\n\n requestErrored(fetchRequest) {}\n\n requestFinished(fetchRequest) {}\n\n requestPreventedHandlingResponse(fetchRequest, fetchResponse) {}\n\n requestFailedWithResponse(fetchRequest, fetchResponse) {}\n\n #preloadAll = () => {\n this.preloadOnLoadLinksForView(document.body);\n }\n}\n\nclass Cache {\n constructor(session) {\n this.session = session;\n }\n\n clear() {\n this.session.clearCache();\n }\n\n resetCacheControl() {\n this.#setCacheControl(\"\");\n }\n\n exemptPageFromCache() {\n this.#setCacheControl(\"no-cache\");\n }\n\n exemptPageFromPreview() {\n this.#setCacheControl(\"no-preview\");\n }\n\n #setCacheControl(value) {\n setMetaContent(\"turbo-cache-control\", value);\n }\n}\n\nclass Session {\n navigator = new Navigator(this)\n history = new History(this)\n view = new PageView(this, document.documentElement)\n adapter = new BrowserAdapter(this)\n\n pageObserver = new PageObserver(this)\n cacheObserver = new CacheObserver()\n linkPrefetchObserver = new LinkPrefetchObserver(this, document)\n linkClickObserver = new LinkClickObserver(this, window)\n formSubmitObserver = new FormSubmitObserver(this, document)\n scrollObserver = new ScrollObserver(this)\n streamObserver = new StreamObserver(this)\n formLinkClickObserver = new FormLinkClickObserver(this, document.documentElement)\n frameRedirector = new FrameRedirector(this, document.documentElement)\n streamMessageRenderer = new StreamMessageRenderer()\n cache = new Cache(this)\n\n enabled = true\n started = false\n #pageRefreshDebouncePeriod = 150\n\n constructor(recentRequests) {\n this.recentRequests = recentRequests;\n this.preloader = new Preloader(this, this.view.snapshotCache);\n this.debouncedRefresh = this.refresh;\n this.pageRefreshDebouncePeriod = this.pageRefreshDebouncePeriod;\n }\n\n start() {\n if (!this.started) {\n this.pageObserver.start();\n this.cacheObserver.start();\n this.linkPrefetchObserver.start();\n this.formLinkClickObserver.start();\n this.linkClickObserver.start();\n this.formSubmitObserver.start();\n this.scrollObserver.start();\n this.streamObserver.start();\n this.frameRedirector.start();\n this.history.start();\n this.preloader.start();\n this.started = true;\n this.enabled = true;\n }\n }\n\n disable() {\n this.enabled = false;\n }\n\n stop() {\n if (this.started) {\n this.pageObserver.stop();\n this.cacheObserver.stop();\n this.linkPrefetchObserver.stop();\n this.formLinkClickObserver.stop();\n this.linkClickObserver.stop();\n this.formSubmitObserver.stop();\n this.scrollObserver.stop();\n this.streamObserver.stop();\n this.frameRedirector.stop();\n this.history.stop();\n this.preloader.stop();\n this.started = false;\n }\n }\n\n registerAdapter(adapter) {\n this.adapter = adapter;\n }\n\n visit(location, options = {}) {\n const frameElement = options.frame ? document.getElementById(options.frame) : null;\n\n if (frameElement instanceof FrameElement) {\n const action = options.action || getVisitAction(frameElement);\n\n frameElement.delegate.proposeVisitIfNavigatedWithAction(frameElement, action);\n frameElement.src = location.toString();\n } else {\n this.navigator.proposeVisit(expandURL(location), options);\n }\n }\n\n refresh(url, requestId) {\n const isRecentRequest = requestId && this.recentRequests.has(requestId);\n if (!isRecentRequest && !this.navigator.currentVisit) {\n this.visit(url, { action: \"replace\", shouldCacheSnapshot: false });\n }\n }\n\n connectStreamSource(source) {\n this.streamObserver.connectStreamSource(source);\n }\n\n disconnectStreamSource(source) {\n this.streamObserver.disconnectStreamSource(source);\n }\n\n renderStreamMessage(message) {\n this.streamMessageRenderer.render(StreamMessage.wrap(message));\n }\n\n clearCache() {\n this.view.clearSnapshotCache();\n }\n\n setProgressBarDelay(delay) {\n console.warn(\n \"Please replace `session.setProgressBarDelay(delay)` with `session.progressBarDelay = delay`. The function is deprecated and will be removed in a future version of Turbo.`\"\n );\n\n this.progressBarDelay = delay;\n }\n\n set progressBarDelay(delay) {\n config.drive.progressBarDelay = delay;\n }\n\n get progressBarDelay() {\n return config.drive.progressBarDelay\n }\n\n set drive(value) {\n config.drive.enabled = value;\n }\n\n get drive() {\n return config.drive.enabled\n }\n\n set formMode(value) {\n config.forms.mode = value;\n }\n\n get formMode() {\n return config.forms.mode\n }\n\n get location() {\n return this.history.location\n }\n\n get restorationIdentifier() {\n return this.history.restorationIdentifier\n }\n\n get pageRefreshDebouncePeriod() {\n return this.#pageRefreshDebouncePeriod\n }\n\n set pageRefreshDebouncePeriod(value) {\n this.refresh = debounce(this.debouncedRefresh.bind(this), value);\n this.#pageRefreshDebouncePeriod = value;\n }\n\n // Preloader delegate\n\n shouldPreloadLink(element) {\n const isUnsafe = element.hasAttribute(\"data-turbo-method\");\n const isStream = element.hasAttribute(\"data-turbo-stream\");\n const frameTarget = element.getAttribute(\"data-turbo-frame\");\n const frame = frameTarget == \"_top\" ?\n null :\n document.getElementById(frameTarget) || findClosestRecursively(element, \"turbo-frame:not([disabled])\");\n\n if (isUnsafe || isStream || frame instanceof FrameElement) {\n return false\n } else {\n const location = new URL(element.href);\n\n return this.elementIsNavigatable(element) && locationIsVisitable(location, this.snapshot.rootLocation)\n }\n }\n\n // History delegate\n\n historyPoppedToLocationWithRestorationIdentifierAndDirection(location, restorationIdentifier, direction) {\n if (this.enabled) {\n this.navigator.startVisit(location, restorationIdentifier, {\n action: \"restore\",\n historyChanged: true,\n direction\n });\n } else {\n this.adapter.pageInvalidated({\n reason: \"turbo_disabled\"\n });\n }\n }\n\n // Scroll observer delegate\n\n scrollPositionChanged(position) {\n this.history.updateRestorationData({ scrollPosition: position });\n }\n\n // Form click observer delegate\n\n willSubmitFormLinkToLocation(link, location) {\n return this.elementIsNavigatable(link) && locationIsVisitable(location, this.snapshot.rootLocation)\n }\n\n submittedFormLinkToLocation() {}\n\n // Link hover observer delegate\n\n canPrefetchRequestToLocation(link, location) {\n return (\n this.elementIsNavigatable(link) &&\n locationIsVisitable(location, this.snapshot.rootLocation)\n )\n }\n\n // Link click observer delegate\n\n willFollowLinkToLocation(link, location, event) {\n return (\n this.elementIsNavigatable(link) &&\n locationIsVisitable(location, this.snapshot.rootLocation) &&\n this.applicationAllowsFollowingLinkToLocation(link, location, event)\n )\n }\n\n followedLinkToLocation(link, location) {\n const action = this.getActionForLink(link);\n const acceptsStreamResponse = link.hasAttribute(\"data-turbo-stream\");\n\n this.visit(location.href, { action, acceptsStreamResponse });\n }\n\n // Navigator delegate\n\n allowsVisitingLocationWithAction(location, action) {\n return this.locationWithActionIsSamePage(location, action) || this.applicationAllowsVisitingLocation(location)\n }\n\n visitProposedToLocation(location, options) {\n extendURLWithDeprecatedProperties(location);\n this.adapter.visitProposedToLocation(location, options);\n }\n\n // Visit delegate\n\n visitStarted(visit) {\n if (!visit.acceptsStreamResponse) {\n markAsBusy(document.documentElement);\n this.view.markVisitDirection(visit.direction);\n }\n extendURLWithDeprecatedProperties(visit.location);\n if (!visit.silent) {\n this.notifyApplicationAfterVisitingLocation(visit.location, visit.action);\n }\n }\n\n visitCompleted(visit) {\n this.view.unmarkVisitDirection();\n clearBusyState(document.documentElement);\n this.notifyApplicationAfterPageLoad(visit.getTimingMetrics());\n }\n\n locationWithActionIsSamePage(location, action) {\n return this.navigator.locationWithActionIsSamePage(location, action)\n }\n\n visitScrolledToSamePageLocation(oldURL, newURL) {\n this.notifyApplicationAfterVisitingSamePageLocation(oldURL, newURL);\n }\n\n // Form submit observer delegate\n\n willSubmitForm(form, submitter) {\n const action = getAction$1(form, submitter);\n\n return (\n this.submissionIsNavigatable(form, submitter) &&\n locationIsVisitable(expandURL(action), this.snapshot.rootLocation)\n )\n }\n\n formSubmitted(form, submitter) {\n this.navigator.submitForm(form, submitter);\n }\n\n // Page observer delegate\n\n pageBecameInteractive() {\n this.view.lastRenderedLocation = this.location;\n this.notifyApplicationAfterPageLoad();\n }\n\n pageLoaded() {\n this.history.assumeControlOfScrollRestoration();\n }\n\n pageWillUnload() {\n this.history.relinquishControlOfScrollRestoration();\n }\n\n // Stream observer delegate\n\n receivedMessageFromStream(message) {\n this.renderStreamMessage(message);\n }\n\n // Page view delegate\n\n viewWillCacheSnapshot() {\n if (!this.navigator.currentVisit?.silent) {\n this.notifyApplicationBeforeCachingSnapshot();\n }\n }\n\n allowsImmediateRender({ element }, options) {\n const event = this.notifyApplicationBeforeRender(element, options);\n const {\n defaultPrevented,\n detail: { render }\n } = event;\n\n if (this.view.renderer && render) {\n this.view.renderer.renderElement = render;\n }\n\n return !defaultPrevented\n }\n\n viewRenderedSnapshot(_snapshot, _isPreview, renderMethod) {\n this.view.lastRenderedLocation = this.history.location;\n this.notifyApplicationAfterRender(renderMethod);\n }\n\n preloadOnLoadLinksForView(element) {\n this.preloader.preloadOnLoadLinksForView(element);\n }\n\n viewInvalidated(reason) {\n this.adapter.pageInvalidated(reason);\n }\n\n // Frame element\n\n frameLoaded(frame) {\n this.notifyApplicationAfterFrameLoad(frame);\n }\n\n frameRendered(fetchResponse, frame) {\n this.notifyApplicationAfterFrameRender(fetchResponse, frame);\n }\n\n // Application events\n\n applicationAllowsFollowingLinkToLocation(link, location, ev) {\n const event = this.notifyApplicationAfterClickingLinkToLocation(link, location, ev);\n return !event.defaultPrevented\n }\n\n applicationAllowsVisitingLocation(location) {\n const event = this.notifyApplicationBeforeVisitingLocation(location);\n return !event.defaultPrevented\n }\n\n notifyApplicationAfterClickingLinkToLocation(link, location, event) {\n return dispatch(\"turbo:click\", {\n target: link,\n detail: { url: location.href, originalEvent: event },\n cancelable: true\n })\n }\n\n notifyApplicationBeforeVisitingLocation(location) {\n return dispatch(\"turbo:before-visit\", {\n detail: { url: location.href },\n cancelable: true\n })\n }\n\n notifyApplicationAfterVisitingLocation(location, action) {\n return dispatch(\"turbo:visit\", { detail: { url: location.href, action } })\n }\n\n notifyApplicationBeforeCachingSnapshot() {\n return dispatch(\"turbo:before-cache\")\n }\n\n notifyApplicationBeforeRender(newBody, options) {\n return dispatch(\"turbo:before-render\", {\n detail: { newBody, ...options },\n cancelable: true\n })\n }\n\n notifyApplicationAfterRender(renderMethod) {\n return dispatch(\"turbo:render\", { detail: { renderMethod } })\n }\n\n notifyApplicationAfterPageLoad(timing = {}) {\n return dispatch(\"turbo:load\", {\n detail: { url: this.location.href, timing }\n })\n }\n\n notifyApplicationAfterVisitingSamePageLocation(oldURL, newURL) {\n dispatchEvent(\n new HashChangeEvent(\"hashchange\", {\n oldURL: oldURL.toString(),\n newURL: newURL.toString()\n })\n );\n }\n\n notifyApplicationAfterFrameLoad(frame) {\n return dispatch(\"turbo:frame-load\", { target: frame })\n }\n\n notifyApplicationAfterFrameRender(fetchResponse, frame) {\n return dispatch(\"turbo:frame-render\", {\n detail: { fetchResponse },\n target: frame,\n cancelable: true\n })\n }\n\n // Helpers\n\n submissionIsNavigatable(form, submitter) {\n if (config.forms.mode == \"off\") {\n return false\n } else {\n const submitterIsNavigatable = submitter ? this.elementIsNavigatable(submitter) : true;\n\n if (config.forms.mode == \"optin\") {\n return submitterIsNavigatable && form.closest('[data-turbo=\"true\"]') != null\n } else {\n return submitterIsNavigatable && this.elementIsNavigatable(form)\n }\n }\n }\n\n elementIsNavigatable(element) {\n const container = findClosestRecursively(element, \"[data-turbo]\");\n const withinFrame = findClosestRecursively(element, \"turbo-frame\");\n\n // Check if Drive is enabled on the session or we're within a Frame.\n if (config.drive.enabled || withinFrame) {\n // Element is navigatable by default, unless `data-turbo=\"false\"`.\n if (container) {\n return container.getAttribute(\"data-turbo\") != \"false\"\n } else {\n return true\n }\n } else {\n // Element isn't navigatable by default, unless `data-turbo=\"true\"`.\n if (container) {\n return container.getAttribute(\"data-turbo\") == \"true\"\n } else {\n return false\n }\n }\n }\n\n // Private\n\n getActionForLink(link) {\n return getVisitAction(link) || \"advance\"\n }\n\n get snapshot() {\n return this.view.snapshot\n }\n}\n\n// Older versions of the Turbo Native adapters referenced the\n// `Location#absoluteURL` property in their implementations of\n// the `Adapter#visitProposedToLocation()` and `#visitStarted()`\n// methods. The Location class has since been removed in favor\n// of the DOM URL API, and accordingly all Adapter methods now\n// receive URL objects.\n//\n// We alias #absoluteURL to #toString() here to avoid crashing\n// older adapters which do not expect URL objects. We should\n// consider removing this support at some point in the future.\n\nfunction extendURLWithDeprecatedProperties(url) {\n Object.defineProperties(url, deprecatedLocationPropertyDescriptors);\n}\n\nconst deprecatedLocationPropertyDescriptors = {\n absoluteURL: {\n get() {\n return this.toString()\n }\n }\n};\n\nconst session = new Session(recentRequests);\nconst { cache, navigator: navigator$1 } = session;\n\n/**\n * Starts the main session.\n * This initialises any necessary observers such as those to monitor\n * link interactions.\n */\nfunction start() {\n session.start();\n}\n\n/**\n * Registers an adapter for the main session.\n *\n * @param adapter Adapter to register\n */\nfunction registerAdapter(adapter) {\n session.registerAdapter(adapter);\n}\n\n/**\n * Performs an application visit to the given location.\n *\n * @param location Location to visit (a URL or path)\n * @param options Options to apply\n * @param options.action Type of history navigation to apply (\"restore\",\n * \"replace\" or \"advance\")\n * @param options.historyChanged Specifies whether the browser history has\n * already been changed for this visit or not\n * @param options.referrer Specifies the referrer of this visit such that\n * navigations to the same page will not result in a new history entry.\n * @param options.snapshotHTML Cached snapshot to render\n * @param options.response Response of the specified location\n */\nfunction visit(location, options) {\n session.visit(location, options);\n}\n\n/**\n * Connects a stream source to the main session.\n *\n * @param source Stream source to connect\n */\nfunction connectStreamSource(source) {\n session.connectStreamSource(source);\n}\n\n/**\n * Disconnects a stream source from the main session.\n *\n * @param source Stream source to disconnect\n */\nfunction disconnectStreamSource(source) {\n session.disconnectStreamSource(source);\n}\n\n/**\n * Renders a stream message to the main session by appending it to the\n * current document.\n *\n * @param message Message to render\n */\nfunction renderStreamMessage(message) {\n session.renderStreamMessage(message);\n}\n\n/**\n * Removes all entries from the Turbo Drive page cache.\n * Call this when state has changed on the server that may affect cached pages.\n *\n * @deprecated since version 7.2.0 in favor of `Turbo.cache.clear()`\n */\nfunction clearCache() {\n console.warn(\n \"Please replace `Turbo.clearCache()` with `Turbo.cache.clear()`. The top-level function is deprecated and will be removed in a future version of Turbo.`\"\n );\n session.clearCache();\n}\n\n/**\n * Sets the delay after which the progress bar will appear during navigation.\n *\n * The progress bar appears after 500ms by default.\n *\n * Note that this method has no effect when used with the iOS or Android\n * adapters.\n *\n * @param delay Time to delay in milliseconds\n */\nfunction setProgressBarDelay(delay) {\n console.warn(\n \"Please replace `Turbo.setProgressBarDelay(delay)` with `Turbo.config.drive.progressBarDelay = delay`. The top-level function is deprecated and will be removed in a future version of Turbo.`\"\n );\n config.drive.progressBarDelay = delay;\n}\n\nfunction setConfirmMethod(confirmMethod) {\n console.warn(\n \"Please replace `Turbo.setConfirmMethod(confirmMethod)` with `Turbo.config.forms.confirm = confirmMethod`. The top-level function is deprecated and will be removed in a future version of Turbo.`\"\n );\n config.forms.confirm = confirmMethod;\n}\n\nfunction setFormMode(mode) {\n console.warn(\n \"Please replace `Turbo.setFormMode(mode)` with `Turbo.config.forms.mode = mode`. The top-level function is deprecated and will be removed in a future version of Turbo.`\"\n );\n config.forms.mode = mode;\n}\n\nvar Turbo = /*#__PURE__*/Object.freeze({\n __proto__: null,\n navigator: navigator$1,\n session: session,\n cache: cache,\n PageRenderer: PageRenderer,\n PageSnapshot: PageSnapshot,\n FrameRenderer: FrameRenderer,\n fetch: fetchWithTurboHeaders,\n config: config,\n start: start,\n registerAdapter: registerAdapter,\n visit: visit,\n connectStreamSource: connectStreamSource,\n disconnectStreamSource: disconnectStreamSource,\n renderStreamMessage: renderStreamMessage,\n clearCache: clearCache,\n setProgressBarDelay: setProgressBarDelay,\n setConfirmMethod: setConfirmMethod,\n setFormMode: setFormMode\n});\n\nclass TurboFrameMissingError extends Error {}\n\nclass FrameController {\n fetchResponseLoaded = (_fetchResponse) => Promise.resolve()\n #currentFetchRequest = null\n #resolveVisitPromise = () => {}\n #connected = false\n #hasBeenLoaded = false\n #ignoredAttributes = new Set()\n #shouldMorphFrame = false\n action = null\n\n constructor(element) {\n this.element = element;\n this.view = new FrameView(this, this.element);\n this.appearanceObserver = new AppearanceObserver(this, this.element);\n this.formLinkClickObserver = new FormLinkClickObserver(this, this.element);\n this.linkInterceptor = new LinkInterceptor(this, this.element);\n this.restorationIdentifier = uuid();\n this.formSubmitObserver = new FormSubmitObserver(this, this.element);\n }\n\n // Frame delegate\n\n connect() {\n if (!this.#connected) {\n this.#connected = true;\n if (this.loadingStyle == FrameLoadingStyle.lazy) {\n this.appearanceObserver.start();\n } else {\n this.#loadSourceURL();\n }\n this.formLinkClickObserver.start();\n this.linkInterceptor.start();\n this.formSubmitObserver.start();\n }\n }\n\n disconnect() {\n if (this.#connected) {\n this.#connected = false;\n this.appearanceObserver.stop();\n this.formLinkClickObserver.stop();\n this.linkInterceptor.stop();\n this.formSubmitObserver.stop();\n }\n }\n\n disabledChanged() {\n if (this.loadingStyle == FrameLoadingStyle.eager) {\n this.#loadSourceURL();\n }\n }\n\n sourceURLChanged() {\n if (this.#isIgnoringChangesTo(\"src\")) return\n\n if (this.element.isConnected) {\n this.complete = false;\n }\n\n if (this.loadingStyle == FrameLoadingStyle.eager || this.#hasBeenLoaded) {\n this.#loadSourceURL();\n }\n }\n\n sourceURLReloaded() {\n const { refresh, src } = this.element;\n\n this.#shouldMorphFrame = src && refresh === \"morph\";\n\n this.element.removeAttribute(\"complete\");\n this.element.src = null;\n this.element.src = src;\n return this.element.loaded\n }\n\n loadingStyleChanged() {\n if (this.loadingStyle == FrameLoadingStyle.lazy) {\n this.appearanceObserver.start();\n } else {\n this.appearanceObserver.stop();\n this.#loadSourceURL();\n }\n }\n\n async #loadSourceURL() {\n if (this.enabled && this.isActive && !this.complete && this.sourceURL) {\n this.element.loaded = this.#visit(expandURL(this.sourceURL));\n this.appearanceObserver.stop();\n await this.element.loaded;\n this.#hasBeenLoaded = true;\n }\n }\n\n async loadResponse(fetchResponse) {\n if (fetchResponse.redirected || (fetchResponse.succeeded && fetchResponse.isHTML)) {\n this.sourceURL = fetchResponse.response.url;\n }\n\n try {\n const html = await fetchResponse.responseHTML;\n if (html) {\n const document = parseHTMLDocument(html);\n const pageSnapshot = PageSnapshot.fromDocument(document);\n\n if (pageSnapshot.isVisitable) {\n await this.#loadFrameResponse(fetchResponse, document);\n } else {\n await this.#handleUnvisitableFrameResponse(fetchResponse);\n }\n }\n } finally {\n this.#shouldMorphFrame = false;\n this.fetchResponseLoaded = () => Promise.resolve();\n }\n }\n\n // Appearance observer delegate\n\n elementAppearedInViewport(element) {\n this.proposeVisitIfNavigatedWithAction(element, getVisitAction(element));\n this.#loadSourceURL();\n }\n\n // Form link click observer delegate\n\n willSubmitFormLinkToLocation(link) {\n return this.#shouldInterceptNavigation(link)\n }\n\n submittedFormLinkToLocation(link, _location, form) {\n const frame = this.#findFrameElement(link);\n if (frame) form.setAttribute(\"data-turbo-frame\", frame.id);\n }\n\n // Link interceptor delegate\n\n shouldInterceptLinkClick(element, _location, _event) {\n return this.#shouldInterceptNavigation(element)\n }\n\n linkClickIntercepted(element, location) {\n this.#navigateFrame(element, location);\n }\n\n // Form submit observer delegate\n\n willSubmitForm(element, submitter) {\n return element.closest(\"turbo-frame\") == this.element && this.#shouldInterceptNavigation(element, submitter)\n }\n\n formSubmitted(element, submitter) {\n if (this.formSubmission) {\n this.formSubmission.stop();\n }\n\n this.formSubmission = new FormSubmission(this, element, submitter);\n const { fetchRequest } = this.formSubmission;\n this.prepareRequest(fetchRequest);\n this.formSubmission.start();\n }\n\n // Fetch request delegate\n\n prepareRequest(request) {\n request.headers[\"Turbo-Frame\"] = this.id;\n\n if (this.currentNavigationElement?.hasAttribute(\"data-turbo-stream\")) {\n request.acceptResponseType(StreamMessage.contentType);\n }\n }\n\n requestStarted(_request) {\n markAsBusy(this.element);\n }\n\n requestPreventedHandlingResponse(_request, _response) {\n this.#resolveVisitPromise();\n }\n\n async requestSucceededWithResponse(request, response) {\n await this.loadResponse(response);\n this.#resolveVisitPromise();\n }\n\n async requestFailedWithResponse(request, response) {\n await this.loadResponse(response);\n this.#resolveVisitPromise();\n }\n\n requestErrored(request, error) {\n console.error(error);\n this.#resolveVisitPromise();\n }\n\n requestFinished(_request) {\n clearBusyState(this.element);\n }\n\n // Form submission delegate\n\n formSubmissionStarted({ formElement }) {\n markAsBusy(formElement, this.#findFrameElement(formElement));\n }\n\n formSubmissionSucceededWithResponse(formSubmission, response) {\n const frame = this.#findFrameElement(formSubmission.formElement, formSubmission.submitter);\n\n frame.delegate.proposeVisitIfNavigatedWithAction(frame, getVisitAction(formSubmission.submitter, formSubmission.formElement, frame));\n frame.delegate.loadResponse(response);\n\n if (!formSubmission.isSafe) {\n session.clearCache();\n }\n }\n\n formSubmissionFailedWithResponse(formSubmission, fetchResponse) {\n this.element.delegate.loadResponse(fetchResponse);\n session.clearCache();\n }\n\n formSubmissionErrored(formSubmission, error) {\n console.error(error);\n }\n\n formSubmissionFinished({ formElement }) {\n clearBusyState(formElement, this.#findFrameElement(formElement));\n }\n\n // View delegate\n\n allowsImmediateRender({ element: newFrame }, options) {\n const event = dispatch(\"turbo:before-frame-render\", {\n target: this.element,\n detail: { newFrame, ...options },\n cancelable: true\n });\n\n const {\n defaultPrevented,\n detail: { render }\n } = event;\n\n if (this.view.renderer && render) {\n this.view.renderer.renderElement = render;\n }\n\n return !defaultPrevented\n }\n\n viewRenderedSnapshot(_snapshot, _isPreview, _renderMethod) {}\n\n preloadOnLoadLinksForView(element) {\n session.preloadOnLoadLinksForView(element);\n }\n\n viewInvalidated() {}\n\n // Frame renderer delegate\n\n willRenderFrame(currentElement, _newElement) {\n this.previousFrameElement = currentElement.cloneNode(true);\n }\n\n visitCachedSnapshot = ({ element }) => {\n const frame = element.querySelector(\"#\" + this.element.id);\n\n if (frame && this.previousFrameElement) {\n frame.replaceChildren(...this.previousFrameElement.children);\n }\n\n delete this.previousFrameElement;\n }\n\n // Private\n\n async #loadFrameResponse(fetchResponse, document) {\n const newFrameElement = await this.extractForeignFrameElement(document.body);\n const rendererClass = this.#shouldMorphFrame ? MorphingFrameRenderer : FrameRenderer;\n\n if (newFrameElement) {\n const snapshot = new Snapshot(newFrameElement);\n const renderer = new rendererClass(this, this.view.snapshot, snapshot, false, false);\n if (this.view.renderPromise) await this.view.renderPromise;\n this.changeHistory();\n\n await this.view.render(renderer);\n this.complete = true;\n session.frameRendered(fetchResponse, this.element);\n session.frameLoaded(this.element);\n await this.fetchResponseLoaded(fetchResponse);\n } else if (this.#willHandleFrameMissingFromResponse(fetchResponse)) {\n this.#handleFrameMissingFromResponse(fetchResponse);\n }\n }\n\n async #visit(url) {\n const request = new FetchRequest(this, FetchMethod.get, url, new URLSearchParams(), this.element);\n\n this.#currentFetchRequest?.cancel();\n this.#currentFetchRequest = request;\n\n return new Promise((resolve) => {\n this.#resolveVisitPromise = () => {\n this.#resolveVisitPromise = () => {};\n this.#currentFetchRequest = null;\n resolve();\n };\n request.perform();\n })\n }\n\n #navigateFrame(element, url, submitter) {\n const frame = this.#findFrameElement(element, submitter);\n\n frame.delegate.proposeVisitIfNavigatedWithAction(frame, getVisitAction(submitter, element, frame));\n\n this.#withCurrentNavigationElement(element, () => {\n frame.src = url;\n });\n }\n\n proposeVisitIfNavigatedWithAction(frame, action = null) {\n this.action = action;\n\n if (this.action) {\n const pageSnapshot = PageSnapshot.fromElement(frame).clone();\n const { visitCachedSnapshot } = frame.delegate;\n\n frame.delegate.fetchResponseLoaded = async (fetchResponse) => {\n if (frame.src) {\n const { statusCode, redirected } = fetchResponse;\n const responseHTML = await fetchResponse.responseHTML;\n const response = { statusCode, redirected, responseHTML };\n const options = {\n response,\n visitCachedSnapshot,\n willRender: false,\n updateHistory: false,\n restorationIdentifier: this.restorationIdentifier,\n snapshot: pageSnapshot\n };\n\n if (this.action) options.action = this.action;\n\n session.visit(frame.src, options);\n }\n };\n }\n }\n\n changeHistory() {\n if (this.action) {\n const method = getHistoryMethodForAction(this.action);\n session.history.update(method, expandURL(this.element.src || \"\"), this.restorationIdentifier);\n }\n }\n\n async #handleUnvisitableFrameResponse(fetchResponse) {\n console.warn(\n `The response (${fetchResponse.statusCode}) from is performing a full page visit due to turbo-visit-control.`\n );\n\n await this.#visitResponse(fetchResponse.response);\n }\n\n #willHandleFrameMissingFromResponse(fetchResponse) {\n this.element.setAttribute(\"complete\", \"\");\n\n const response = fetchResponse.response;\n const visit = async (url, options) => {\n if (url instanceof Response) {\n this.#visitResponse(url);\n } else {\n session.visit(url, options);\n }\n };\n\n const event = dispatch(\"turbo:frame-missing\", {\n target: this.element,\n detail: { response, visit },\n cancelable: true\n });\n\n return !event.defaultPrevented\n }\n\n #handleFrameMissingFromResponse(fetchResponse) {\n this.view.missing();\n this.#throwFrameMissingError(fetchResponse);\n }\n\n #throwFrameMissingError(fetchResponse) {\n 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.`;\n throw new TurboFrameMissingError(message)\n }\n\n async #visitResponse(response) {\n const wrapped = new FetchResponse(response);\n const responseHTML = await wrapped.responseHTML;\n const { location, redirected, statusCode } = wrapped;\n\n return session.visit(location, { response: { redirected, statusCode, responseHTML } })\n }\n\n #findFrameElement(element, submitter) {\n const id = getAttribute(\"data-turbo-frame\", submitter, element) || this.element.getAttribute(\"target\");\n return getFrameElementById(id) ?? this.element\n }\n\n async extractForeignFrameElement(container) {\n let element;\n const id = CSS.escape(this.id);\n\n try {\n element = activateElement(container.querySelector(`turbo-frame#${id}`), this.sourceURL);\n if (element) {\n return element\n }\n\n element = activateElement(container.querySelector(`turbo-frame[src][recurse~=${id}]`), this.sourceURL);\n if (element) {\n await element.loaded;\n return await this.extractForeignFrameElement(element)\n }\n } catch (error) {\n console.error(error);\n return new FrameElement()\n }\n\n return null\n }\n\n #formActionIsVisitable(form, submitter) {\n const action = getAction$1(form, submitter);\n\n return locationIsVisitable(expandURL(action), this.rootLocation)\n }\n\n #shouldInterceptNavigation(element, submitter) {\n const id = getAttribute(\"data-turbo-frame\", submitter, element) || this.element.getAttribute(\"target\");\n\n if (element instanceof HTMLFormElement && !this.#formActionIsVisitable(element, submitter)) {\n return false\n }\n\n if (!this.enabled || id == \"_top\") {\n return false\n }\n\n if (id) {\n const frameElement = getFrameElementById(id);\n if (frameElement) {\n return !frameElement.disabled\n }\n }\n\n if (!session.elementIsNavigatable(element)) {\n return false\n }\n\n if (submitter && !session.elementIsNavigatable(submitter)) {\n return false\n }\n\n return true\n }\n\n // Computed properties\n\n get id() {\n return this.element.id\n }\n\n get enabled() {\n return !this.element.disabled\n }\n\n get sourceURL() {\n if (this.element.src) {\n return this.element.src\n }\n }\n\n set sourceURL(sourceURL) {\n this.#ignoringChangesToAttribute(\"src\", () => {\n this.element.src = sourceURL ?? null;\n });\n }\n\n get loadingStyle() {\n return this.element.loading\n }\n\n get isLoading() {\n return this.formSubmission !== undefined || this.#resolveVisitPromise() !== undefined\n }\n\n get complete() {\n return this.element.hasAttribute(\"complete\")\n }\n\n set complete(value) {\n if (value) {\n this.element.setAttribute(\"complete\", \"\");\n } else {\n this.element.removeAttribute(\"complete\");\n }\n }\n\n get isActive() {\n return this.element.isActive && this.#connected\n }\n\n get rootLocation() {\n const meta = this.element.ownerDocument.querySelector(`meta[name=\"turbo-root\"]`);\n const root = meta?.content ?? \"/\";\n return expandURL(root)\n }\n\n #isIgnoringChangesTo(attributeName) {\n return this.#ignoredAttributes.has(attributeName)\n }\n\n #ignoringChangesToAttribute(attributeName, callback) {\n this.#ignoredAttributes.add(attributeName);\n callback();\n this.#ignoredAttributes.delete(attributeName);\n }\n\n #withCurrentNavigationElement(element, callback) {\n this.currentNavigationElement = element;\n callback();\n delete this.currentNavigationElement;\n }\n}\n\nfunction getFrameElementById(id) {\n if (id != null) {\n const element = document.getElementById(id);\n if (element instanceof FrameElement) {\n return element\n }\n }\n}\n\nfunction activateElement(element, currentURL) {\n if (element) {\n const src = element.getAttribute(\"src\");\n if (src != null && currentURL != null && urlsAreEqual(src, currentURL)) {\n throw new Error(`Matching element has a source URL which references itself`)\n }\n if (element.ownerDocument !== document) {\n element = document.importNode(element, true);\n }\n\n if (element instanceof FrameElement) {\n element.connectedCallback();\n element.disconnectedCallback();\n return element\n }\n }\n}\n\nconst StreamActions = {\n after() {\n this.targetElements.forEach((e) => e.parentElement?.insertBefore(this.templateContent, e.nextSibling));\n },\n\n append() {\n this.removeDuplicateTargetChildren();\n this.targetElements.forEach((e) => e.append(this.templateContent));\n },\n\n before() {\n this.targetElements.forEach((e) => e.parentElement?.insertBefore(this.templateContent, e));\n },\n\n prepend() {\n this.removeDuplicateTargetChildren();\n this.targetElements.forEach((e) => e.prepend(this.templateContent));\n },\n\n remove() {\n this.targetElements.forEach((e) => e.remove());\n },\n\n replace() {\n const method = this.getAttribute(\"method\");\n\n this.targetElements.forEach((targetElement) => {\n if (method === \"morph\") {\n morphElements(targetElement, this.templateContent);\n } else {\n targetElement.replaceWith(this.templateContent);\n }\n });\n },\n\n update() {\n const method = this.getAttribute(\"method\");\n\n this.targetElements.forEach((targetElement) => {\n if (method === \"morph\") {\n morphChildren(targetElement, this.templateContent);\n } else {\n targetElement.innerHTML = \"\";\n targetElement.append(this.templateContent);\n }\n });\n },\n\n refresh() {\n session.refresh(this.baseURI, this.requestId);\n }\n};\n\n//