{"version":3,"file":"Naja.js","sources":["../node_modules/abortcontroller-polyfill/dist/polyfill-patch-fetch.js","../node_modules/event-target-shim/dist/event-target-shim.mjs","../src/polyfills.js","../src/core/UIHandler.js","../src/core/FormsHandler.js","../src/core/RedirectHandler.js","../src/core/SnippetHandler.js","../src/core/HistoryHandler.js","../src/core/ScriptLoader.js","../src/Naja.js","../src/extensions/AbortExtension.js","../src/extensions/UniqueExtension.js","../src/index.js"],"sourcesContent":["(function (factory) {\n typeof define === 'function' && define.amd ? define(factory) :\n factory();\n}((function () { 'use strict';\n\n function _classCallCheck(instance, Constructor) {\n if (!(instance instanceof Constructor)) {\n throw new TypeError(\"Cannot call a class as a function\");\n }\n }\n\n function _defineProperties(target, props) {\n for (var i = 0; i < props.length; i++) {\n var descriptor = props[i];\n descriptor.enumerable = descriptor.enumerable || false;\n descriptor.configurable = true;\n if (\"value\" in descriptor) descriptor.writable = true;\n Object.defineProperty(target, descriptor.key, descriptor);\n }\n }\n\n function _createClass(Constructor, protoProps, staticProps) {\n if (protoProps) _defineProperties(Constructor.prototype, protoProps);\n if (staticProps) _defineProperties(Constructor, staticProps);\n return Constructor;\n }\n\n function _inherits(subClass, superClass) {\n if (typeof superClass !== \"function\" && superClass !== null) {\n throw new TypeError(\"Super expression must either be null or a function\");\n }\n\n subClass.prototype = Object.create(superClass && superClass.prototype, {\n constructor: {\n value: subClass,\n writable: true,\n configurable: true\n }\n });\n if (superClass) _setPrototypeOf(subClass, superClass);\n }\n\n function _getPrototypeOf(o) {\n _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) {\n return o.__proto__ || Object.getPrototypeOf(o);\n };\n return _getPrototypeOf(o);\n }\n\n function _setPrototypeOf(o, p) {\n _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) {\n o.__proto__ = p;\n return o;\n };\n\n return _setPrototypeOf(o, p);\n }\n\n function _isNativeReflectConstruct() {\n if (typeof Reflect === \"undefined\" || !Reflect.construct) return false;\n if (Reflect.construct.sham) return false;\n if (typeof Proxy === \"function\") return true;\n\n try {\n Date.prototype.toString.call(Reflect.construct(Date, [], function () {}));\n return true;\n } catch (e) {\n return false;\n }\n }\n\n function _assertThisInitialized(self) {\n if (self === void 0) {\n throw new ReferenceError(\"this hasn't been initialised - super() hasn't been called\");\n }\n\n return self;\n }\n\n function _possibleConstructorReturn(self, call) {\n if (call && (typeof call === \"object\" || typeof call === \"function\")) {\n return call;\n }\n\n return _assertThisInitialized(self);\n }\n\n function _createSuper(Derived) {\n var hasNativeReflectConstruct = _isNativeReflectConstruct();\n\n return function _createSuperInternal() {\n var Super = _getPrototypeOf(Derived),\n result;\n\n if (hasNativeReflectConstruct) {\n var NewTarget = _getPrototypeOf(this).constructor;\n\n result = Reflect.construct(Super, arguments, NewTarget);\n } else {\n result = Super.apply(this, arguments);\n }\n\n return _possibleConstructorReturn(this, result);\n };\n }\n\n function _superPropBase(object, property) {\n while (!Object.prototype.hasOwnProperty.call(object, property)) {\n object = _getPrototypeOf(object);\n if (object === null) break;\n }\n\n return object;\n }\n\n function _get(target, property, receiver) {\n if (typeof Reflect !== \"undefined\" && Reflect.get) {\n _get = Reflect.get;\n } else {\n _get = function _get(target, property, receiver) {\n var base = _superPropBase(target, property);\n\n if (!base) return;\n var desc = Object.getOwnPropertyDescriptor(base, property);\n\n if (desc.get) {\n return desc.get.call(receiver);\n }\n\n return desc.value;\n };\n }\n\n return _get(target, property, receiver || target);\n }\n\n var Emitter = /*#__PURE__*/function () {\n function Emitter() {\n _classCallCheck(this, Emitter);\n\n Object.defineProperty(this, 'listeners', {\n value: {},\n writable: true,\n configurable: true\n });\n }\n\n _createClass(Emitter, [{\n key: \"addEventListener\",\n value: function addEventListener(type, callback) {\n if (!(type in this.listeners)) {\n this.listeners[type] = [];\n }\n\n this.listeners[type].push(callback);\n }\n }, {\n key: \"removeEventListener\",\n value: function removeEventListener(type, callback) {\n if (!(type in this.listeners)) {\n return;\n }\n\n var stack = this.listeners[type];\n\n for (var i = 0, l = stack.length; i < l; i++) {\n if (stack[i] === callback) {\n stack.splice(i, 1);\n return;\n }\n }\n }\n }, {\n key: \"dispatchEvent\",\n value: function dispatchEvent(event) {\n var _this = this;\n\n if (!(event.type in this.listeners)) {\n return;\n }\n\n var debounce = function debounce(callback) {\n setTimeout(function () {\n return callback.call(_this, event);\n });\n };\n\n var stack = this.listeners[event.type];\n\n for (var i = 0, l = stack.length; i < l; i++) {\n debounce(stack[i]);\n }\n\n return !event.defaultPrevented;\n }\n }]);\n\n return Emitter;\n }();\n\n var AbortSignal = /*#__PURE__*/function (_Emitter) {\n _inherits(AbortSignal, _Emitter);\n\n var _super = _createSuper(AbortSignal);\n\n function AbortSignal() {\n var _this2;\n\n _classCallCheck(this, AbortSignal);\n\n _this2 = _super.call(this); // Some versions of babel does not transpile super() correctly for IE <= 10, if the parent\n // constructor has failed to run, then \"this.listeners\" will still be undefined and then we call\n // the parent constructor directly instead as a workaround. For general details, see babel bug:\n // https://github.com/babel/babel/issues/3041\n // This hack was added as a fix for the issue described here:\n // https://github.com/Financial-Times/polyfill-library/pull/59#issuecomment-477558042\n\n if (!_this2.listeners) {\n Emitter.call(_assertThisInitialized(_this2));\n } // Compared to assignment, Object.defineProperty makes properties non-enumerable by default and\n // we want Object.keys(new AbortController().signal) to be [] for compat with the native impl\n\n\n Object.defineProperty(_assertThisInitialized(_this2), 'aborted', {\n value: false,\n writable: true,\n configurable: true\n });\n Object.defineProperty(_assertThisInitialized(_this2), 'onabort', {\n value: null,\n writable: true,\n configurable: true\n });\n return _this2;\n }\n\n _createClass(AbortSignal, [{\n key: \"toString\",\n value: function toString() {\n return '[object AbortSignal]';\n }\n }, {\n key: \"dispatchEvent\",\n value: function dispatchEvent(event) {\n if (event.type === 'abort') {\n this.aborted = true;\n\n if (typeof this.onabort === 'function') {\n this.onabort.call(this, event);\n }\n }\n\n _get(_getPrototypeOf(AbortSignal.prototype), \"dispatchEvent\", this).call(this, event);\n }\n }]);\n\n return AbortSignal;\n }(Emitter);\n var AbortController = /*#__PURE__*/function () {\n function AbortController() {\n _classCallCheck(this, AbortController);\n\n // Compared to assignment, Object.defineProperty makes properties non-enumerable by default and\n // we want Object.keys(new AbortController()) to be [] for compat with the native impl\n Object.defineProperty(this, 'signal', {\n value: new AbortSignal(),\n writable: true,\n configurable: true\n });\n }\n\n _createClass(AbortController, [{\n key: \"abort\",\n value: function abort() {\n var event;\n\n try {\n event = new Event('abort');\n } catch (e) {\n if (typeof document !== 'undefined') {\n if (!document.createEvent) {\n // For Internet Explorer 8:\n event = document.createEventObject();\n event.type = 'abort';\n } else {\n // For Internet Explorer 11:\n event = document.createEvent('Event');\n event.initEvent('abort', false, false);\n }\n } else {\n // Fallback where document isn't available:\n event = {\n type: 'abort',\n bubbles: false,\n cancelable: false\n };\n }\n }\n\n this.signal.dispatchEvent(event);\n }\n }, {\n key: \"toString\",\n value: function toString() {\n return '[object AbortController]';\n }\n }]);\n\n return AbortController;\n }();\n\n if (typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n // These are necessary to make sure that we get correct output for:\n // Object.prototype.toString.call(new AbortController())\n AbortController.prototype[Symbol.toStringTag] = 'AbortController';\n AbortSignal.prototype[Symbol.toStringTag] = 'AbortSignal';\n }\n\n function polyfillNeeded(self) {\n if (self.__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL) {\n console.log('__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL=true is set, will force install polyfill');\n return true;\n } // Note that the \"unfetch\" minimal fetch polyfill defines fetch() without\n // defining window.Request, and this polyfill need to work on top of unfetch\n // so the below feature detection needs the !self.AbortController part.\n // The Request.prototype check is also needed because Safari versions 11.1.2\n // up to and including 12.1.x has a window.AbortController present but still\n // does NOT correctly implement abortable fetch:\n // https://bugs.webkit.org/show_bug.cgi?id=174980#c2\n\n\n return typeof self.Request === 'function' && !self.Request.prototype.hasOwnProperty('signal') || !self.AbortController;\n }\n\n /**\n * Note: the \"fetch.Request\" default value is available for fetch imported from\n * the \"node-fetch\" package and not in browsers. This is OK since browsers\n * will be importing umd-polyfill.js from that path \"self\" is passed the\n * decorator so the default value will not be used (because browsers that define\n * fetch also has Request). One quirky setup where self.fetch exists but\n * self.Request does not is when the \"unfetch\" minimal fetch polyfill is used\n * on top of IE11; for this case the browser will try to use the fetch.Request\n * default value which in turn will be undefined but then then \"if (Request)\"\n * will ensure that you get a patched fetch but still no Request (as expected).\n * @param {fetch, Request = fetch.Request}\n * @returns {fetch: abortableFetch, Request: AbortableRequest}\n */\n\n function abortableFetchDecorator(patchTargets) {\n if ('function' === typeof patchTargets) {\n patchTargets = {\n fetch: patchTargets\n };\n }\n\n var _patchTargets = patchTargets,\n fetch = _patchTargets.fetch,\n _patchTargets$Request = _patchTargets.Request,\n NativeRequest = _patchTargets$Request === void 0 ? fetch.Request : _patchTargets$Request,\n NativeAbortController = _patchTargets.AbortController,\n _patchTargets$__FORCE = _patchTargets.__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL,\n __FORCE_INSTALL_ABORTCONTROLLER_POLYFILL = _patchTargets$__FORCE === void 0 ? false : _patchTargets$__FORCE;\n\n if (!polyfillNeeded({\n fetch: fetch,\n Request: NativeRequest,\n AbortController: NativeAbortController,\n __FORCE_INSTALL_ABORTCONTROLLER_POLYFILL: __FORCE_INSTALL_ABORTCONTROLLER_POLYFILL\n })) {\n return {\n fetch: fetch,\n Request: Request\n };\n }\n\n var Request = NativeRequest; // Note that the \"unfetch\" minimal fetch polyfill defines fetch() without\n // defining window.Request, and this polyfill need to work on top of unfetch\n // hence we only patch it if it's available. Also we don't patch it if signal\n // is already available on the Request prototype because in this case support\n // is present and the patching below can cause a crash since it assigns to\n // request.signal which is technically a read-only property. This latter error\n // happens when you run the main5.js node-fetch example in the repo\n // \"abortcontroller-polyfill-examples\". The exact error is:\n // request.signal = init.signal;\n // ^\n // TypeError: Cannot set property signal of # which has only a getter\n\n if (Request && !Request.prototype.hasOwnProperty('signal') || __FORCE_INSTALL_ABORTCONTROLLER_POLYFILL) {\n Request = function Request(input, init) {\n var signal;\n\n if (init && init.signal) {\n signal = init.signal; // Never pass init.signal to the native Request implementation when the polyfill has\n // been installed because if we're running on top of a browser with a\n // working native AbortController (i.e. the polyfill was installed due to\n // __FORCE_INSTALL_ABORTCONTROLLER_POLYFILL being set), then passing our\n // fake AbortSignal to the native fetch will trigger:\n // TypeError: Failed to construct 'Request': member signal is not of type AbortSignal.\n\n delete init.signal;\n }\n\n var request = new NativeRequest(input, init);\n\n if (signal) {\n Object.defineProperty(request, 'signal', {\n writable: false,\n enumerable: false,\n configurable: true,\n value: signal\n });\n }\n\n return request;\n };\n\n Request.prototype = NativeRequest.prototype;\n }\n\n var realFetch = fetch;\n\n var abortableFetch = function abortableFetch(input, init) {\n var signal = Request && Request.prototype.isPrototypeOf(input) ? input.signal : init ? init.signal : undefined;\n\n if (signal) {\n var abortError;\n\n try {\n abortError = new DOMException('Aborted', 'AbortError');\n } catch (err) {\n // IE 11 does not support calling the DOMException constructor, use a\n // regular error object on it instead.\n abortError = new Error('Aborted');\n abortError.name = 'AbortError';\n } // Return early if already aborted, thus avoiding making an HTTP request\n\n\n if (signal.aborted) {\n return Promise.reject(abortError);\n } // Turn an event into a promise, reject it once `abort` is dispatched\n\n\n var cancellation = new Promise(function (_, reject) {\n signal.addEventListener('abort', function () {\n return reject(abortError);\n }, {\n once: true\n });\n });\n\n if (init && init.signal) {\n // Never pass .signal to the native implementation when the polyfill has\n // been installed because if we're running on top of a browser with a\n // working native AbortController (i.e. the polyfill was installed due to\n // __FORCE_INSTALL_ABORTCONTROLLER_POLYFILL being set), then passing our\n // fake AbortSignal to the native fetch will trigger:\n // TypeError: Failed to execute 'fetch' on 'Window': member signal is not of type AbortSignal.\n delete init.signal;\n } // Return the fastest promise (don't need to wait for request to finish)\n\n\n return Promise.race([cancellation, realFetch(input, init)]);\n }\n\n return realFetch(input, init);\n };\n\n return {\n fetch: abortableFetch,\n Request: Request\n };\n }\n\n (function (self) {\n\n if (!polyfillNeeded(self)) {\n return;\n }\n\n if (!self.fetch) {\n console.warn('fetch() is not available, cannot install abortcontroller-polyfill');\n return;\n }\n\n var _abortableFetch = abortableFetchDecorator(self),\n fetch = _abortableFetch.fetch,\n Request = _abortableFetch.Request;\n\n self.fetch = fetch;\n self.Request = Request;\n Object.defineProperty(self, 'AbortController', {\n writable: true,\n enumerable: false,\n configurable: true,\n value: AbortController\n });\n Object.defineProperty(self, 'AbortSignal', {\n writable: true,\n enumerable: false,\n configurable: true,\n value: AbortSignal\n });\n })(typeof self !== 'undefined' ? self : global);\n\n})));\n","/**\n * @author Toru Nagashima \n * @copyright 2015 Toru Nagashima. All rights reserved.\n * See LICENSE file in root directory for full license.\n */\n/**\n * @typedef {object} PrivateData\n * @property {EventTarget} eventTarget The event target.\n * @property {{type:string}} event The original event object.\n * @property {number} eventPhase The current event phase.\n * @property {EventTarget|null} currentTarget The current event target.\n * @property {boolean} canceled The flag to prevent default.\n * @property {boolean} stopped The flag to stop propagation.\n * @property {boolean} immediateStopped The flag to stop propagation immediately.\n * @property {Function|null} passiveListener The listener if the current listener is passive. Otherwise this is null.\n * @property {number} timeStamp The unix time.\n * @private\n */\n\n/**\n * Private data for event wrappers.\n * @type {WeakMap}\n * @private\n */\nconst privateData = new WeakMap();\n\n/**\n * Cache for wrapper classes.\n * @type {WeakMap}\n * @private\n */\nconst wrappers = new WeakMap();\n\n/**\n * Get private data.\n * @param {Event} event The event object to get private data.\n * @returns {PrivateData} The private data of the event.\n * @private\n */\nfunction pd(event) {\n const retv = privateData.get(event);\n console.assert(\n retv != null,\n \"'this' is expected an Event object, but got\",\n event\n );\n return retv\n}\n\n/**\n * https://dom.spec.whatwg.org/#set-the-canceled-flag\n * @param data {PrivateData} private data.\n */\nfunction setCancelFlag(data) {\n if (data.passiveListener != null) {\n if (\n typeof console !== \"undefined\" &&\n typeof console.error === \"function\"\n ) {\n console.error(\n \"Unable to preventDefault inside passive event listener invocation.\",\n data.passiveListener\n );\n }\n return\n }\n if (!data.event.cancelable) {\n return\n }\n\n data.canceled = true;\n if (typeof data.event.preventDefault === \"function\") {\n data.event.preventDefault();\n }\n}\n\n/**\n * @see https://dom.spec.whatwg.org/#interface-event\n * @private\n */\n/**\n * The event wrapper.\n * @constructor\n * @param {EventTarget} eventTarget The event target of this dispatching.\n * @param {Event|{type:string}} event The original event to wrap.\n */\nfunction Event(eventTarget, event) {\n privateData.set(this, {\n eventTarget,\n event,\n eventPhase: 2,\n currentTarget: eventTarget,\n canceled: false,\n stopped: false,\n immediateStopped: false,\n passiveListener: null,\n timeStamp: event.timeStamp || Date.now(),\n });\n\n // https://heycam.github.io/webidl/#Unforgeable\n Object.defineProperty(this, \"isTrusted\", { value: false, enumerable: true });\n\n // Define accessors\n const keys = Object.keys(event);\n for (let i = 0; i < keys.length; ++i) {\n const key = keys[i];\n if (!(key in this)) {\n Object.defineProperty(this, key, defineRedirectDescriptor(key));\n }\n }\n}\n\n// Should be enumerable, but class methods are not enumerable.\nEvent.prototype = {\n /**\n * The type of this event.\n * @type {string}\n */\n get type() {\n return pd(this).event.type\n },\n\n /**\n * The target of this event.\n * @type {EventTarget}\n */\n get target() {\n return pd(this).eventTarget\n },\n\n /**\n * The target of this event.\n * @type {EventTarget}\n */\n get currentTarget() {\n return pd(this).currentTarget\n },\n\n /**\n * @returns {EventTarget[]} The composed path of this event.\n */\n composedPath() {\n const currentTarget = pd(this).currentTarget;\n if (currentTarget == null) {\n return []\n }\n return [currentTarget]\n },\n\n /**\n * Constant of NONE.\n * @type {number}\n */\n get NONE() {\n return 0\n },\n\n /**\n * Constant of CAPTURING_PHASE.\n * @type {number}\n */\n get CAPTURING_PHASE() {\n return 1\n },\n\n /**\n * Constant of AT_TARGET.\n * @type {number}\n */\n get AT_TARGET() {\n return 2\n },\n\n /**\n * Constant of BUBBLING_PHASE.\n * @type {number}\n */\n get BUBBLING_PHASE() {\n return 3\n },\n\n /**\n * The target of this event.\n * @type {number}\n */\n get eventPhase() {\n return pd(this).eventPhase\n },\n\n /**\n * Stop event bubbling.\n * @returns {void}\n */\n stopPropagation() {\n const data = pd(this);\n\n data.stopped = true;\n if (typeof data.event.stopPropagation === \"function\") {\n data.event.stopPropagation();\n }\n },\n\n /**\n * Stop event bubbling.\n * @returns {void}\n */\n stopImmediatePropagation() {\n const data = pd(this);\n\n data.stopped = true;\n data.immediateStopped = true;\n if (typeof data.event.stopImmediatePropagation === \"function\") {\n data.event.stopImmediatePropagation();\n }\n },\n\n /**\n * The flag to be bubbling.\n * @type {boolean}\n */\n get bubbles() {\n return Boolean(pd(this).event.bubbles)\n },\n\n /**\n * The flag to be cancelable.\n * @type {boolean}\n */\n get cancelable() {\n return Boolean(pd(this).event.cancelable)\n },\n\n /**\n * Cancel this event.\n * @returns {void}\n */\n preventDefault() {\n setCancelFlag(pd(this));\n },\n\n /**\n * The flag to indicate cancellation state.\n * @type {boolean}\n */\n get defaultPrevented() {\n return pd(this).canceled\n },\n\n /**\n * The flag to be composed.\n * @type {boolean}\n */\n get composed() {\n return Boolean(pd(this).event.composed)\n },\n\n /**\n * The unix time of this event.\n * @type {number}\n */\n get timeStamp() {\n return pd(this).timeStamp\n },\n\n /**\n * The target of this event.\n * @type {EventTarget}\n * @deprecated\n */\n get srcElement() {\n return pd(this).eventTarget\n },\n\n /**\n * The flag to stop event bubbling.\n * @type {boolean}\n * @deprecated\n */\n get cancelBubble() {\n return pd(this).stopped\n },\n set cancelBubble(value) {\n if (!value) {\n return\n }\n const data = pd(this);\n\n data.stopped = true;\n if (typeof data.event.cancelBubble === \"boolean\") {\n data.event.cancelBubble = true;\n }\n },\n\n /**\n * The flag to indicate cancellation state.\n * @type {boolean}\n * @deprecated\n */\n get returnValue() {\n return !pd(this).canceled\n },\n set returnValue(value) {\n if (!value) {\n setCancelFlag(pd(this));\n }\n },\n\n /**\n * Initialize this event object. But do nothing under event dispatching.\n * @param {string} type The event type.\n * @param {boolean} [bubbles=false] The flag to be possible to bubble up.\n * @param {boolean} [cancelable=false] The flag to be possible to cancel.\n * @deprecated\n */\n initEvent() {\n // Do nothing.\n },\n};\n\n// `constructor` is not enumerable.\nObject.defineProperty(Event.prototype, \"constructor\", {\n value: Event,\n configurable: true,\n writable: true,\n});\n\n// Ensure `event instanceof window.Event` is `true`.\nif (typeof window !== \"undefined\" && typeof window.Event !== \"undefined\") {\n Object.setPrototypeOf(Event.prototype, window.Event.prototype);\n\n // Make association for wrappers.\n wrappers.set(window.Event.prototype, Event);\n}\n\n/**\n * Get the property descriptor to redirect a given property.\n * @param {string} key Property name to define property descriptor.\n * @returns {PropertyDescriptor} The property descriptor to redirect the property.\n * @private\n */\nfunction defineRedirectDescriptor(key) {\n return {\n get() {\n return pd(this).event[key]\n },\n set(value) {\n pd(this).event[key] = value;\n },\n configurable: true,\n enumerable: true,\n }\n}\n\n/**\n * Get the property descriptor to call a given method property.\n * @param {string} key Property name to define property descriptor.\n * @returns {PropertyDescriptor} The property descriptor to call the method property.\n * @private\n */\nfunction defineCallDescriptor(key) {\n return {\n value() {\n const event = pd(this).event;\n return event[key].apply(event, arguments)\n },\n configurable: true,\n enumerable: true,\n }\n}\n\n/**\n * Define new wrapper class.\n * @param {Function} BaseEvent The base wrapper class.\n * @param {Object} proto The prototype of the original event.\n * @returns {Function} The defined wrapper class.\n * @private\n */\nfunction defineWrapper(BaseEvent, proto) {\n const keys = Object.keys(proto);\n if (keys.length === 0) {\n return BaseEvent\n }\n\n /** CustomEvent */\n function CustomEvent(eventTarget, event) {\n BaseEvent.call(this, eventTarget, event);\n }\n\n CustomEvent.prototype = Object.create(BaseEvent.prototype, {\n constructor: { value: CustomEvent, configurable: true, writable: true },\n });\n\n // Define accessors.\n for (let i = 0; i < keys.length; ++i) {\n const key = keys[i];\n if (!(key in BaseEvent.prototype)) {\n const descriptor = Object.getOwnPropertyDescriptor(proto, key);\n const isFunc = typeof descriptor.value === \"function\";\n Object.defineProperty(\n CustomEvent.prototype,\n key,\n isFunc\n ? defineCallDescriptor(key)\n : defineRedirectDescriptor(key)\n );\n }\n }\n\n return CustomEvent\n}\n\n/**\n * Get the wrapper class of a given prototype.\n * @param {Object} proto The prototype of the original event to get its wrapper.\n * @returns {Function} The wrapper class.\n * @private\n */\nfunction getWrapper(proto) {\n if (proto == null || proto === Object.prototype) {\n return Event\n }\n\n let wrapper = wrappers.get(proto);\n if (wrapper == null) {\n wrapper = defineWrapper(getWrapper(Object.getPrototypeOf(proto)), proto);\n wrappers.set(proto, wrapper);\n }\n return wrapper\n}\n\n/**\n * Wrap a given event to management a dispatching.\n * @param {EventTarget} eventTarget The event target of this dispatching.\n * @param {Object} event The event to wrap.\n * @returns {Event} The wrapper instance.\n * @private\n */\nfunction wrapEvent(eventTarget, event) {\n const Wrapper = getWrapper(Object.getPrototypeOf(event));\n return new Wrapper(eventTarget, event)\n}\n\n/**\n * Get the immediateStopped flag of a given event.\n * @param {Event} event The event to get.\n * @returns {boolean} The flag to stop propagation immediately.\n * @private\n */\nfunction isStopped(event) {\n return pd(event).immediateStopped\n}\n\n/**\n * Set the current event phase of a given event.\n * @param {Event} event The event to set current target.\n * @param {number} eventPhase New event phase.\n * @returns {void}\n * @private\n */\nfunction setEventPhase(event, eventPhase) {\n pd(event).eventPhase = eventPhase;\n}\n\n/**\n * Set the current target of a given event.\n * @param {Event} event The event to set current target.\n * @param {EventTarget|null} currentTarget New current target.\n * @returns {void}\n * @private\n */\nfunction setCurrentTarget(event, currentTarget) {\n pd(event).currentTarget = currentTarget;\n}\n\n/**\n * Set a passive listener of a given event.\n * @param {Event} event The event to set current target.\n * @param {Function|null} passiveListener New passive listener.\n * @returns {void}\n * @private\n */\nfunction setPassiveListener(event, passiveListener) {\n pd(event).passiveListener = passiveListener;\n}\n\n/**\n * @typedef {object} ListenerNode\n * @property {Function} listener\n * @property {1|2|3} listenerType\n * @property {boolean} passive\n * @property {boolean} once\n * @property {ListenerNode|null} next\n * @private\n */\n\n/**\n * @type {WeakMap>}\n * @private\n */\nconst listenersMap = new WeakMap();\n\n// Listener types\nconst CAPTURE = 1;\nconst BUBBLE = 2;\nconst ATTRIBUTE = 3;\n\n/**\n * Check whether a given value is an object or not.\n * @param {any} x The value to check.\n * @returns {boolean} `true` if the value is an object.\n */\nfunction isObject(x) {\n return x !== null && typeof x === \"object\" //eslint-disable-line no-restricted-syntax\n}\n\n/**\n * Get listeners.\n * @param {EventTarget} eventTarget The event target to get.\n * @returns {Map} The listeners.\n * @private\n */\nfunction getListeners(eventTarget) {\n const listeners = listenersMap.get(eventTarget);\n if (listeners == null) {\n throw new TypeError(\n \"'this' is expected an EventTarget object, but got another value.\"\n )\n }\n return listeners\n}\n\n/**\n * Get the property descriptor for the event attribute of a given event.\n * @param {string} eventName The event name to get property descriptor.\n * @returns {PropertyDescriptor} The property descriptor.\n * @private\n */\nfunction defineEventAttributeDescriptor(eventName) {\n return {\n get() {\n const listeners = getListeners(this);\n let node = listeners.get(eventName);\n while (node != null) {\n if (node.listenerType === ATTRIBUTE) {\n return node.listener\n }\n node = node.next;\n }\n return null\n },\n\n set(listener) {\n if (typeof listener !== \"function\" && !isObject(listener)) {\n listener = null; // eslint-disable-line no-param-reassign\n }\n const listeners = getListeners(this);\n\n // Traverse to the tail while removing old value.\n let prev = null;\n let node = listeners.get(eventName);\n while (node != null) {\n if (node.listenerType === ATTRIBUTE) {\n // Remove old value.\n if (prev !== null) {\n prev.next = node.next;\n } else if (node.next !== null) {\n listeners.set(eventName, node.next);\n } else {\n listeners.delete(eventName);\n }\n } else {\n prev = node;\n }\n\n node = node.next;\n }\n\n // Add new value.\n if (listener !== null) {\n const newNode = {\n listener,\n listenerType: ATTRIBUTE,\n passive: false,\n once: false,\n next: null,\n };\n if (prev === null) {\n listeners.set(eventName, newNode);\n } else {\n prev.next = newNode;\n }\n }\n },\n configurable: true,\n enumerable: true,\n }\n}\n\n/**\n * Define an event attribute (e.g. `eventTarget.onclick`).\n * @param {Object} eventTargetPrototype The event target prototype to define an event attrbite.\n * @param {string} eventName The event name to define.\n * @returns {void}\n */\nfunction defineEventAttribute(eventTargetPrototype, eventName) {\n Object.defineProperty(\n eventTargetPrototype,\n `on${eventName}`,\n defineEventAttributeDescriptor(eventName)\n );\n}\n\n/**\n * Define a custom EventTarget with event attributes.\n * @param {string[]} eventNames Event names for event attributes.\n * @returns {EventTarget} The custom EventTarget.\n * @private\n */\nfunction defineCustomEventTarget(eventNames) {\n /** CustomEventTarget */\n function CustomEventTarget() {\n EventTarget.call(this);\n }\n\n CustomEventTarget.prototype = Object.create(EventTarget.prototype, {\n constructor: {\n value: CustomEventTarget,\n configurable: true,\n writable: true,\n },\n });\n\n for (let i = 0; i < eventNames.length; ++i) {\n defineEventAttribute(CustomEventTarget.prototype, eventNames[i]);\n }\n\n return CustomEventTarget\n}\n\n/**\n * EventTarget.\n *\n * - This is constructor if no arguments.\n * - This is a function which returns a CustomEventTarget constructor if there are arguments.\n *\n * For example:\n *\n * class A extends EventTarget {}\n * class B extends EventTarget(\"message\") {}\n * class C extends EventTarget(\"message\", \"error\") {}\n * class D extends EventTarget([\"message\", \"error\"]) {}\n */\nfunction EventTarget() {\n /*eslint-disable consistent-return */\n if (this instanceof EventTarget) {\n listenersMap.set(this, new Map());\n return\n }\n if (arguments.length === 1 && Array.isArray(arguments[0])) {\n return defineCustomEventTarget(arguments[0])\n }\n if (arguments.length > 0) {\n const types = new Array(arguments.length);\n for (let i = 0; i < arguments.length; ++i) {\n types[i] = arguments[i];\n }\n return defineCustomEventTarget(types)\n }\n throw new TypeError(\"Cannot call a class as a function\")\n /*eslint-enable consistent-return */\n}\n\n// Should be enumerable, but class methods are not enumerable.\nEventTarget.prototype = {\n /**\n * Add a given listener to this event target.\n * @param {string} eventName The event name to add.\n * @param {Function} listener The listener to add.\n * @param {boolean|{capture?:boolean,passive?:boolean,once?:boolean}} [options] The options for this listener.\n * @returns {void}\n */\n addEventListener(eventName, listener, options) {\n if (listener == null) {\n return\n }\n if (typeof listener !== \"function\" && !isObject(listener)) {\n throw new TypeError(\"'listener' should be a function or an object.\")\n }\n\n const listeners = getListeners(this);\n const optionsIsObj = isObject(options);\n const capture = optionsIsObj\n ? Boolean(options.capture)\n : Boolean(options);\n const listenerType = capture ? CAPTURE : BUBBLE;\n const newNode = {\n listener,\n listenerType,\n passive: optionsIsObj && Boolean(options.passive),\n once: optionsIsObj && Boolean(options.once),\n next: null,\n };\n\n // Set it as the first node if the first node is null.\n let node = listeners.get(eventName);\n if (node === undefined) {\n listeners.set(eventName, newNode);\n return\n }\n\n // Traverse to the tail while checking duplication..\n let prev = null;\n while (node != null) {\n if (\n node.listener === listener &&\n node.listenerType === listenerType\n ) {\n // Should ignore duplication.\n return\n }\n prev = node;\n node = node.next;\n }\n\n // Add it.\n prev.next = newNode;\n },\n\n /**\n * Remove a given listener from this event target.\n * @param {string} eventName The event name to remove.\n * @param {Function} listener The listener to remove.\n * @param {boolean|{capture?:boolean,passive?:boolean,once?:boolean}} [options] The options for this listener.\n * @returns {void}\n */\n removeEventListener(eventName, listener, options) {\n if (listener == null) {\n return\n }\n\n const listeners = getListeners(this);\n const capture = isObject(options)\n ? Boolean(options.capture)\n : Boolean(options);\n const listenerType = capture ? CAPTURE : BUBBLE;\n\n let prev = null;\n let node = listeners.get(eventName);\n while (node != null) {\n if (\n node.listener === listener &&\n node.listenerType === listenerType\n ) {\n if (prev !== null) {\n prev.next = node.next;\n } else if (node.next !== null) {\n listeners.set(eventName, node.next);\n } else {\n listeners.delete(eventName);\n }\n return\n }\n\n prev = node;\n node = node.next;\n }\n },\n\n /**\n * Dispatch a given event.\n * @param {Event|{type:string}} event The event to dispatch.\n * @returns {boolean} `false` if canceled.\n */\n dispatchEvent(event) {\n if (event == null || typeof event.type !== \"string\") {\n throw new TypeError('\"event.type\" should be a string.')\n }\n\n // If listeners aren't registered, terminate.\n const listeners = getListeners(this);\n const eventName = event.type;\n let node = listeners.get(eventName);\n if (node == null) {\n return true\n }\n\n // Since we cannot rewrite several properties, so wrap object.\n const wrappedEvent = wrapEvent(this, event);\n\n // This doesn't process capturing phase and bubbling phase.\n // This isn't participating in a tree.\n let prev = null;\n while (node != null) {\n // Remove this listener if it's once\n if (node.once) {\n if (prev !== null) {\n prev.next = node.next;\n } else if (node.next !== null) {\n listeners.set(eventName, node.next);\n } else {\n listeners.delete(eventName);\n }\n } else {\n prev = node;\n }\n\n // Call this listener\n setPassiveListener(\n wrappedEvent,\n node.passive ? node.listener : null\n );\n if (typeof node.listener === \"function\") {\n try {\n node.listener.call(this, wrappedEvent);\n } catch (err) {\n if (\n typeof console !== \"undefined\" &&\n typeof console.error === \"function\"\n ) {\n console.error(err);\n }\n }\n } else if (\n node.listenerType !== ATTRIBUTE &&\n typeof node.listener.handleEvent === \"function\"\n ) {\n node.listener.handleEvent(wrappedEvent);\n }\n\n // Break if `event.stopImmediatePropagation` was called.\n if (isStopped(wrappedEvent)) {\n break\n }\n\n node = node.next;\n }\n setPassiveListener(wrappedEvent, null);\n setEventPhase(wrappedEvent, 0);\n setCurrentTarget(wrappedEvent, null);\n\n return !wrappedEvent.defaultPrevented\n },\n};\n\n// `constructor` is not enumerable.\nObject.defineProperty(EventTarget.prototype, \"constructor\", {\n value: EventTarget,\n configurable: true,\n writable: true,\n});\n\n// Ensure `eventTarget instanceof window.EventTarget` is `true`.\nif (\n typeof window !== \"undefined\" &&\n typeof window.EventTarget !== \"undefined\"\n) {\n Object.setPrototypeOf(EventTarget.prototype, window.EventTarget.prototype);\n}\n\nexport default EventTarget;\nexport { defineEventAttribute, EventTarget };\n//# sourceMappingURL=event-target-shim.mjs.map\n","// https://bugs.webkit.org/show_bug.cgi?id=174980\nimport 'abortcontroller-polyfill/dist/polyfill-patch-fetch';\n\n// https://github.com/whatwg/dom/pull/467\nimport {EventTarget} from 'event-target-shim';\ntry {\n\tnew window.EventTarget();\n} catch (error) {\n\twindow.EventTarget = EventTarget;\n}\n","export class UIHandler extends EventTarget {\n\tselector = '.ajax';\n\tallowedOrigins = [window.location.origin];\n\thandler = this.handleUI.bind(this);\n\n\tconstructor(naja) {\n\t\tsuper();\n\t\tthis.naja = naja;\n\t\tnaja.addEventListener('init', this.initialize.bind(this));\n\t}\n\n\tinitialize() {\n\t\tthis.bindUI(window.document.body);\n\t\tthis.naja.snippetHandler.addEventListener('afterUpdate', (event) => {\n\t\t\tconst {snippet} = event.detail;\n\t\t\tthis.bindUI(snippet);\n\t\t});\n\t}\n\n\tbindUI(element) {\n\t\tconst selectors = [\n\t\t\t`a${this.selector}`,\n\t\t\t`input[type=\"submit\"]${this.selector}`,\n\t\t\t`input[type=\"image\"]${this.selector}`,\n\t\t\t`button[type=\"submit\"]${this.selector}`,\n\t\t\t`form${this.selector} input[type=\"submit\"]`,\n\t\t\t`form${this.selector} input[type=\"image\"]`,\n\t\t\t`form${this.selector} button[type=\"submit\"]`,\n\t\t].join(', ');\n\n\t\tconst bindElement = (element) => {\n\t\t\telement.removeEventListener('click', this.handler);\n\t\t\telement.addEventListener('click', this.handler);\n\t\t};\n\n\t\tconst elements = element.querySelectorAll(selectors);\n\t\tfor (let i = 0; i < elements.length; i++) {\n\t\t\tbindElement(elements.item(i));\n\t\t}\n\n\t\tif (element.matches(selectors)) {\n\t\t\tbindElement(element);\n\t\t}\n\n\t\tconst bindForm = (form) => {\n\t\t\tform.removeEventListener('submit', this.handler);\n\t\t\tform.addEventListener('submit', this.handler);\n\t\t};\n\n\t\tif (element.matches(`form${this.selector}`)) {\n\t\t\tbindForm(element);\n\t\t}\n\n\t\tconst forms = element.querySelectorAll(`form${this.selector}`);\n\t\tfor (let i = 0; i < forms.length; i++) {\n\t\t\tbindForm(forms.item(i));\n\t\t}\n\t}\n\n\thandleUI(event) {\n\t\tif (event.altKey || event.ctrlKey || event.shiftKey || event.metaKey || event.button) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst element = event.currentTarget;\n\t\tconst options = {};\n\n\t\tif (event.type === 'submit') {\n\t\t\tthis.submitForm(element, options, event);\n\n\t\t} else if (event.type === 'click') {\n\t\t\tthis.clickElement(element, options, event);\n\t\t}\n\t}\n\n\tclickElement(element, options = {}, event) {\n\t\tlet method, url, data;\n\n\t\tif ( ! this.dispatchEvent(new CustomEvent('interaction', {cancelable: true, detail: {element, originalEvent: event, options}}))) {\n\t\t\tif (event) {\n\t\t\t\tevent.preventDefault();\n\t\t\t}\n\n\t\t\treturn;\n\t\t}\n\n\t\tif (element.tagName === 'A') {\n\t\t\tmethod = 'GET';\n\t\t\turl = element.href;\n\t\t\tdata = null;\n\n\t\t} else if (element.tagName === 'INPUT' || element.tagName === 'BUTTON') {\n\t\t\tconst {form} = element;\n\t\t\t// eslint-disable-next-line no-nested-ternary,no-extra-parens\n\t\t\tmethod = element.hasAttribute('formmethod') ? element.getAttribute('formmethod').toUpperCase() : (form.hasAttribute('method') ? form.getAttribute('method').toUpperCase() : 'GET');\n\t\t\turl = element.getAttribute('formaction') || form.getAttribute('action') || window.location.pathname + window.location.search;\n\t\t\tdata = new FormData(form);\n\n\t\t\tif (element.type === 'submit' || element.tagName === 'BUTTON') {\n\t\t\t\tdata.append(element.name, element.value || '');\n\n\t\t\t} else if (element.type === 'image') {\n\t\t\t\tconst coords = element.getBoundingClientRect();\n\t\t\t\tdata.append(`${element.name}.x`, Math.max(0, Math.floor(event.pageX - coords.left)));\n\t\t\t\tdata.append(`${element.name}.y`, Math.max(0, Math.floor(event.pageY - coords.top)));\n\t\t\t}\n\t\t}\n\n\t\tif (this.isUrlAllowed(url)) {\n\t\t\tif (event) {\n\t\t\t\tevent.preventDefault();\n\t\t\t}\n\n\t\t\tthis.naja.makeRequest(method, url, data, options);\n\t\t}\n\t}\n\n\tsubmitForm(form, options = {}, event) {\n\t\tif ( ! this.dispatchEvent(new CustomEvent('interaction', {cancelable: true, detail: {element: form, originalEvent: event, options}}))) {\n\t\t\tif (event) {\n\t\t\t\tevent.preventDefault();\n\t\t\t}\n\n\t\t\treturn;\n\t\t}\n\n\t\tconst method = form.hasAttribute('method') ? form.getAttribute('method').toUpperCase() : 'GET';\n\t\tconst url = form.getAttribute('action') || window.location.pathname + window.location.search;\n\t\tconst data = new FormData(form);\n\n\t\tif (this.isUrlAllowed(url)) {\n\t\t\tif (event) {\n\t\t\t\tevent.preventDefault();\n\t\t\t}\n\n\t\t\tthis.naja.makeRequest(method, url, data, options);\n\t\t}\n\t}\n\n\tisUrlAllowed(url) {\n\t\t// ignore non-URL URIs (javascript:, data:, ...)\n\t\tif (/^(?!https?)[^:/?#]+:/i.test(url)) {\n\t\t\treturn false;\n\t\t}\n\n\t\treturn ! /^https?/i.test(url) || this.allowedOrigins.some((origin) => new RegExp(`^${origin}`, 'i').test(url));\n\t}\n}\n","export class FormsHandler {\n\tnetteForms;\n\n\tconstructor(naja) {\n\t\tthis.naja = naja;\n\t\tnaja.addEventListener('init', this.initialize.bind(this));\n\t\tnaja.uiHandler.addEventListener('interaction', this.processForm.bind(this));\n\t}\n\n\tinitialize() {\n\t\tthis.initForms(window.document.body);\n\t\tthis.naja.snippetHandler.addEventListener('afterUpdate', (event) => {\n\t\t\tconst {snippet} = event.detail;\n\t\t\tthis.initForms(snippet);\n\t\t});\n\t}\n\n\tinitForms(element) {\n\t\tconst netteForms = this.netteForms || window.Nette;\n\t\tif (netteForms) {\n\t\t\tif (element.tagName === 'form') {\n\t\t\t\tnetteForms.initForm(element);\n\t\t\t}\n\n\t\t\tconst forms = element.querySelectorAll('form');\n\t\t\tfor (let i = 0; i < forms.length; i++) {\n\t\t\t\tnetteForms.initForm(forms.item(i));\n\t\t\t}\n\t\t}\n\t}\n\n\tprocessForm(event) {\n\t\tconst {element, originalEvent} = event.detail;\n\n\t\tif (element.form) {\n\t\t\telement.form['nette-submittedBy'] = element;\n\t\t}\n\n\t\tconst netteForms = this.netteForms || window.Nette;\n\t\tif ((element.tagName === 'FORM' || element.form) && netteForms && ! netteForms.validateForm(element)) {\n\t\t\tif (originalEvent) {\n\t\t\t\toriginalEvent.stopImmediatePropagation();\n\t\t\t\toriginalEvent.preventDefault();\n\t\t\t}\n\n\t\t\tevent.preventDefault();\n\t\t}\n\t}\n}\n","export class RedirectHandler extends EventTarget {\n\tconstructor(naja) {\n\t\tsuper();\n\t\tthis.naja = naja;\n\n\t\tnaja.uiHandler.addEventListener('interaction', (event) => {\n\t\t\tconst {element, options} = event.detail;\n\t\t\tif ( ! element) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tif (element.hasAttribute('data-naja-force-redirect') || element.form?.hasAttribute('data-naja-force-redirect')) {\n\t\t\t\tconst value = element.getAttribute('data-naja-force-redirect') ?? element.form?.getAttribute('data-naja-force-redirect');\n\t\t\t\toptions.forceRedirect = value !== 'off';\n\t\t\t}\n\t\t});\n\n\t\tnaja.addEventListener('success', (event) => {\n\t\t\tconst {payload, options} = event.detail;\n\t\t\tif (payload.redirect) {\n\t\t\t\tthis.makeRedirect(payload.redirect, options.forceRedirect, options);\n\t\t\t\tevent.stopImmediatePropagation();\n\t\t\t}\n\t\t});\n\n\t\tthis.locationAdapter = {\n\t\t\tassign: (url) => window.location.assign(url),\n\t\t};\n\t}\n\n\tmakeRedirect(url, force, options = {}) {\n\t\tif (url instanceof URL) {\n\t\t\turl = url.href;\n\t\t}\n\n\t\tlet isHardRedirect = force || ! this.naja.uiHandler.isUrlAllowed(url);\n\t\tconst canRedirect = this.dispatchEvent(new CustomEvent('redirect', {\n\t\t\tcancelable: true,\n\t\t\tdetail: {\n\t\t\t\turl,\n\t\t\t\tisHardRedirect,\n\t\t\t\tsetHardRedirect(value) {\n\t\t\t\t\tisHardRedirect = !!value;\n\t\t\t\t},\n\t\t\t\toptions,\n\t\t\t},\n\t\t}));\n\n\t\tif ( ! canRedirect) {\n\t\t\treturn;\n\t\t}\n\n\t\tif (isHardRedirect) {\n\t\t\tthis.locationAdapter.assign(url);\n\n\t\t} else {\n\t\t\tthis.naja.makeRequest('GET', url, null, options);\n\t\t}\n\t}\n}\n","export class SnippetHandler extends EventTarget {\n\top = {\n\t\treplace: (snippet, content) => {\n\t\t\tsnippet.innerHTML = content;\n\t\t},\n\t\tprepend: (snippet, content) => snippet.insertAdjacentHTML('afterbegin', content),\n\t\tappend: (snippet, content) => snippet.insertAdjacentHTML('beforeend', content),\n\t};\n\n\tconstructor(naja) {\n\t\tsuper();\n\t\tnaja.addEventListener('success', (event) => {\n\t\t\tconst {options, payload} = event.detail;\n\t\t\tif (payload.snippets) {\n\t\t\t\tthis.updateSnippets(payload.snippets, false, options);\n\t\t\t}\n\t\t});\n\t}\n\n\tupdateSnippets(snippets, fromCache = false, options = {}) {\n\t\tObject.keys(snippets).forEach((id) => {\n\t\t\tconst snippet = document.getElementById(id);\n\t\t\tif (snippet) {\n\t\t\t\tthis.updateSnippet(snippet, snippets[id], fromCache, options);\n\t\t\t}\n\t\t});\n\t}\n\n\tupdateSnippet(snippet, content, fromCache, options) {\n\t\tlet operation = this.op.replace;\n\t\tif ((snippet.hasAttribute('data-naja-snippet-prepend') || snippet.hasAttribute('data-ajax-prepend')) && ! fromCache) {\n\t\t\toperation = this.op.prepend;\n\t\t} else if ((snippet.hasAttribute('data-naja-snippet-append') || snippet.hasAttribute('data-ajax-append')) && ! fromCache) {\n\t\t\toperation = this.op.append;\n\t\t}\n\n\t\tconst canUpdate = this.dispatchEvent(new CustomEvent('beforeUpdate', {\n\t\t\tcancelable: true,\n\t\t\tdetail: {\n\t\t\t\tsnippet,\n\t\t\t\tcontent,\n\t\t\t\tfromCache,\n\t\t\t\toperation,\n\t\t\t\tchangeOperation(value) {\n\t\t\t\t\toperation = value;\n\t\t\t\t},\n\t\t\t\toptions,\n\t\t\t},\n\t\t}));\n\n\t\tif ( ! canUpdate) {\n\t\t\treturn;\n\t\t}\n\n\t\tif (snippet.tagName.toLowerCase() === 'title') {\n\t\t\tdocument.title = content;\n\t\t} else {\n\t\t\toperation(snippet, content);\n\t\t}\n\n\t\tthis.dispatchEvent(new CustomEvent('afterUpdate', {\n\t\t\tcancelable: true,\n\t\t\tdetail: {\n\t\t\t\tsnippet,\n\t\t\t\tcontent,\n\t\t\t\tfromCache,\n\t\t\t\toperation,\n\t\t\t\toptions,\n\t\t\t},\n\t\t}));\n\t}\n}\n","export class HistoryHandler {\n\thref = null;\n\tuiCache = true;\n\n\tconstructor(naja) {\n\t\tthis.naja = naja;\n\n\t\tnaja.addEventListener('init', this.initialize.bind(this));\n\t\tnaja.addEventListener('before', this.saveUrl.bind(this));\n\t\tnaja.addEventListener('success', this.pushNewState.bind(this));\n\n\t\tnaja.uiHandler.addEventListener('interaction', this.configureMode.bind(this));\n\n\t\tthis.popStateHandler = this.handlePopState.bind(this);\n\t\tthis.historyAdapter = {\n\t\t\treplaceState: (data, title, url) => window.history.replaceState(data, title, url),\n\t\t\tpushState: (data, title, url) => window.history.pushState(data, title, url),\n\t\t};\n\t}\n\n\tinitialize(event) {\n\t\tconst {defaultOptions} = event.detail;\n\t\tif ('historyUiCache' in defaultOptions) {\n\t\t\tthis.uiCache = defaultOptions.historyUiCache;\n\t\t}\n\n\t\twindow.addEventListener('popstate', this.popStateHandler);\n\t\tthis.historyAdapter.replaceState(\n\t\t\tthis.buildState(window.location.href, this.uiCache),\n\t\t\twindow.document.title,\n\t\t\twindow.location.href,\n\t\t);\n\t}\n\n\thandlePopState(e) {\n\t\tif ( ! e.state) {\n\t\t\treturn;\n\t\t}\n\n\t\tif (e.state.ui) {\n\t\t\tthis.handleSnippets(e.state.ui);\n\t\t\tthis.handleTitle(e.state.title);\n\n\t\t} else if (e.state.ui === false) {\n\t\t\tthis.naja.makeRequest(\n\t\t\t\t'GET',\n\t\t\t\te.state.href,\n\t\t\t\tnull,\n\t\t\t\t{\n\t\t\t\t\thistory: false,\n\t\t\t\t\thistoryUiCache: false,\n\t\t\t\t},\n\t\t\t);\n\t\t}\n\t}\n\n\tsaveUrl(event) {\n\t\tconst {url} = event.detail;\n\t\tthis.href = url;\n\t}\n\n\tconfigureMode(event) {\n\t\tconst {element, options} = event.detail;\n\n\t\t// propagate mode to options\n\t\tif ( ! element) {\n\t\t\treturn;\n\t\t}\n\n\t\tif (element.hasAttribute('data-naja-history') || element.form?.hasAttribute('data-naja-history')) {\n\t\t\tconst value = element.getAttribute('data-naja-history') ?? element.form?.getAttribute('data-naja-history');\n\t\t\toptions.history = this.constructor.normalizeMode(value);\n\t\t}\n\n\t\tif (element.hasAttribute('data-naja-history-cache') || element.form?.hasAttribute('data-naja-history-nocache')) {\n\t\t\tconst value = element.getAttribute('data-naja-history-cache') ?? element.form?.getAttribute('data-naja-history-cache');\n\t\t\toptions.historyUiCache = value !== 'off';\n\t\t}\n\t}\n\n\tstatic normalizeMode(mode) {\n\t\tif (mode === 'off' || mode === false) {\n\t\t\treturn false;\n\n\t\t} else if (mode === 'replace') {\n\t\t\treturn 'replace';\n\t\t}\n\n\t\treturn true;\n\t}\n\n\tpushNewState(event) {\n\t\tconst {payload, options} = event.detail;\n\t\tconst mode = this.constructor.normalizeMode(options.history);\n\t\tif (mode === false) {\n\t\t\treturn;\n\t\t}\n\n\t\tif (payload.postGet && payload.url) {\n\t\t\tthis.href = payload.url;\n\t\t}\n\n\t\tconst method = mode === 'replace' ? 'replaceState' : 'pushState';\n\t\tconst uiCache = options.historyUiCache === true || (options.historyUiCache !== false && this.uiCache); // eslint-disable-line no-extra-parens\n\t\tthis.historyAdapter[method](\n\t\t\tthis.buildState(this.href, uiCache),\n\t\t\twindow.document.title,\n\t\t\tthis.href,\n\t\t);\n\n\t\tthis.href = null;\n\t}\n\n\tbuildState(href, uiCache) {\n\t\tconst state = {\n\t\t\thref,\n\t\t};\n\n\t\tif (uiCache) {\n\t\t\tstate.title = window.document.title;\n\t\t\tstate.ui = this.findSnippets();\n\n\t\t} else {\n\t\t\tstate.ui = false;\n\t\t}\n\n\t\treturn state;\n\t}\n\n\tfindSnippets() {\n\t\tconst result = {};\n\t\tconst snippets = window.document.querySelectorAll('[id^=\"snippet-\"]');\n\t\tfor (let i = 0; i < snippets.length; i++) {\n\t\t\tconst snippet = snippets.item(i);\n\t\t\tif (!snippet.hasAttribute('data-naja-history-nocache') && !snippet.hasAttribute('data-history-nocache')) {\n\t\t\t\tresult[snippet.id] = snippet.innerHTML;\n\t\t\t}\n\t\t}\n\n\t\treturn result;\n\t}\n\n\thandleSnippets(snippets) {\n\t\tthis.naja.snippetHandler.updateSnippets(snippets, true);\n\t\tthis.naja.scriptLoader.loadScripts(snippets);\n\t}\n\n\thandleTitle(title) {\n\t\twindow.document.title = title;\n\t}\n}\n","export class ScriptLoader {\n\tconstructor(naja) {\n\t\tnaja.addEventListener('success', (event) => {\n\t\t\tconst {payload} = event.detail;\n\t\t\tif (payload.snippets) {\n\t\t\t\tthis.loadScripts(payload.snippets);\n\t\t\t}\n\t\t});\n\t}\n\n\tloadScripts(snippets) {\n\t\tObject.keys(snippets).forEach((id) => {\n\t\t\tconst content = snippets[id];\n\t\t\tif ( ! /