{ "version": 3, "sources": ["../javascript/rails/rails-ujs.js", "../javascript/rails/activestorage.js", "../../../node_modules/@rails/actioncable/src/adapters.js", "../../../node_modules/@rails/actioncable/src/logger.js", "../../../node_modules/@rails/actioncable/src/connection_monitor.js", "../../../node_modules/@rails/actioncable/src/internal.js", "../../../node_modules/@rails/actioncable/src/connection.js", "../../../node_modules/@rails/actioncable/src/subscription.js", "../../../node_modules/@rails/actioncable/src/subscription_guarantor.js", "../../../node_modules/@rails/actioncable/src/subscriptions.js", "../../../node_modules/@rails/actioncable/src/consumer.js", "../../../node_modules/@rails/actioncable/src/index.js", "../../../node_modules/blueimp-load-image/js/load-image.js", "../../../node_modules/cropperjs/dist/cropper.js", "../../../node_modules/glider-js/glider.js", "../../../node_modules/clipboard/dist/clipboard.js", "../javascript/rails/trix.js", "../javascript/rails/actiontext.js", "../javascript/chunks/trix.js", "../../../node_modules/smoothscroll-polyfill/dist/smoothscroll.js", "../../../node_modules/eventlistener-polyfill/index.js", "../../../node_modules/lozad/dist/lozad.min.js", "../javascript/internal.js", "../../../node_modules/@hotwired/turbo/dist/turbo.es2017-esm.js", "../../../node_modules/@hotwired/turbo-rails/app/javascript/turbo/cable.js", "../../../node_modules/@hotwired/turbo-rails/app/javascript/turbo/snakeize.js", "../../../node_modules/@hotwired/turbo-rails/app/javascript/turbo/cable_stream_source_element.js", "../../../node_modules/@hotwired/turbo-rails/app/javascript/turbo/fetch_requests.js", "../../../node_modules/@hotwired/turbo-rails/app/javascript/turbo/index.js", "../../../node_modules/@hotwired/stimulus/dist/stimulus.js", "../javascript/controllers/application.js", "../javascript/controllers/shared/address_controller.js", "../javascript/lib/direct_upload.js", "../javascript/controllers/shared/ajax_controller.js", "../javascript/controllers/shared/application_controller.js", "../javascript/controllers/shared/maps/places_controller.js", "../javascript/controllers/shared/maps/routes_controller.js", "../javascript/controllers/shared/menu_controller.js", "../javascript/lib/resizer.js", "../javascript/controllers/shared/resizer_controller.js", "../javascript/controllers/shared/zipcodes_controller.js", "../javascript/lib/enums.js", "../javascript/lib/parser.js", "../javascript/lib/formatter.js", "../javascript/lib/text.js", "../javascript/controllers/shared/secondary_zipcodes_controller.js", "../javascript/lib/dom.js", "../javascript/controllers/shared/steppers_controller.js", "../javascript/controllers/shared/util_controller.js", "../javascript/controllers/shared/index.js", "../javascript/controllers/internal/addition_controller.js", "../javascript/controllers/internal/ajax_controller.js", "../javascript/controllers/internal/alerts_controller.js", "../javascript/controllers/internal/animation_controller.js", "../javascript/controllers/internal/async_render_controller.js", "../javascript/controllers/internal/avatar_photo_editor_controller.js", "../javascript/controllers/internal/binder_controller.js", "../javascript/controllers/internal/blend/navigation_controller.js", "../javascript/controllers/internal/carousel_controller.js", "../javascript/controllers/internal/clipboard_controller.js", "../javascript/controllers/internal/color_picker_controller.js", "../javascript/controllers/internal/confirmation_controller.js", "../javascript/controllers/internal/consumption_controller.js", "../javascript/controllers/internal/countdown_controller.js", "../javascript/controllers/internal/direct_upload_controller.js", "../javascript/controllers/internal/dynaform/calendar_controller.js", "../javascript/controllers/internal/dynaform/parent_controller.js", "../javascript/controllers/internal/dynaform/display_controller.js", "../javascript/controllers/internal/dynaform/navigation_controller.js", "../javascript/controllers/internal/dynaform/progress_controller.js", "../javascript/controllers/internal/dynaform/time_controller.js", "../javascript/lib/validator.js", "../javascript/controllers/internal/dynaform/validation_controller.js", "../javascript/controllers/internal/dynaform_controller.js", "../javascript/controllers/internal/enabler_controller.js", "../javascript/controllers/internal/expandable_controller.js", "../javascript/lib/util.js", "../javascript/controllers/internal/filters_controller.js", "../javascript/controllers/internal/flash_controller.js", "../javascript/controllers/internal/form_controller.js", "../javascript/controllers/internal/full_photo_editor_controller.js", "../javascript/controllers/internal/gift_registry_controller.js", "../javascript/controllers/internal/image_preview_loader_controller.js", "../javascript/controllers/internal/imager_controller.js", "../javascript/controllers/internal/intersector_controller.js", "../javascript/controllers/internal/modal_controller.js", "../javascript/controllers/internal/models/cart_controller.js", "../javascript/controllers/internal/models/cart_item_controller.js", "../javascript/controllers/internal/models/rsvp_controller.js", "../javascript/controllers/internal/moz_controller.js", "../javascript/controllers/internal/multiplication_controller.js", "../javascript/controllers/internal/navigation_controller.js", "../javascript/controllers/internal/pagarme_controller.js", "../javascript/controllers/internal/tuna_controller.js", "../javascript/lib/url.js", "../javascript/controllers/internal/paypal_controller.js", "../javascript/controllers/internal/photo_editor_controller.js", "../javascript/controllers/internal/receipts_controller.js", "../javascript/controllers/internal/remote_anchor_controller.js", "../javascript/controllers/internal/remote_form_controller.js", "../javascript/controllers/internal/remote_input_controller.js", "../javascript/controllers/internal/remote_modal_controller.js", "../javascript/lib/social.js", "../javascript/controllers/internal/send_message_controller.js", "../javascript/controllers/internal/setout/editor_controller.js", "../javascript/controllers/internal/setout/lib/draggable.js", "../javascript/controllers/internal/setout/fragment_controller.js", "../javascript/controllers/internal/setout/slider_controller.js", "../javascript/controllers/internal/setout/splicer_controller.js", "../javascript/controllers/internal/setout_pdf/fragment_controller.js", "../javascript/controllers/internal/setout_pdf/template_controller.js", "../javascript/controllers/internal/share_controller.js", "../javascript/controllers/internal/slider_controller.js", "../javascript/controllers/internal/slideshow_controller.js", "../javascript/controllers/internal/tabs_controller.js", "../javascript/controllers/internal/text_editor_controller.js", "../javascript/lib/numeric.js", "../javascript/controllers/internal/third_party/digipix_controller.js", "../javascript/controllers/internal/toggler_controller.js", "../javascript/controllers/internal/virtual_room_controller.js", "../javascript/controllers/internal/index.js", "../javascript/lib/polyfills.js", "../javascript/lib/image_lazy_loading.js", "../javascript/lib/binder.js", "../javascript/elements/invitations.js", "../javascript/lib/minimal_analytics.js"], "sourcesContent": ["/* eslint-disable */\n/*\nUnobtrusive JavaScript\nhttps://github.com/rails/rails/blob/main/actionview/app/javascript\nReleased under the MIT license\n */\n(function(global, factory) {\n typeof exports === \"object\" && typeof module !== \"undefined\" ? module.exports = factory() : typeof define === \"function\" && define.amd ? define(factory) : (global = typeof globalThis !== \"undefined\" ? globalThis : global || self, \n global.Rails = factory());\n})(this, (function() {\n \"use strict\";\n const linkClickSelector = \"a[data-confirm], a[data-method], a[data-remote]:not([disabled]), a[data-disable-with], a[data-disable]\";\n const buttonClickSelector = {\n selector: \"button[data-remote]:not([form]), button[data-confirm]:not([form])\",\n exclude: \"form button\"\n };\n const inputChangeSelector = \"select[data-remote], input[data-remote], textarea[data-remote]\";\n const formSubmitSelector = \"form:not([data-turbo=true])\";\n const formInputClickSelector = \"form:not([data-turbo=true]) input[type=submit], form:not([data-turbo=true]) input[type=image], form:not([data-turbo=true]) button[type=submit], form:not([data-turbo=true]) button:not([type]), input[type=submit][form], input[type=image][form], button[type=submit][form], button[form]:not([type])\";\n const formDisableSelector = \"input[data-disable-with]:enabled, button[data-disable-with]:enabled, textarea[data-disable-with]:enabled, input[data-disable]:enabled, button[data-disable]:enabled, textarea[data-disable]:enabled\";\n const formEnableSelector = \"input[data-disable-with]:disabled, button[data-disable-with]:disabled, textarea[data-disable-with]:disabled, input[data-disable]:disabled, button[data-disable]:disabled, textarea[data-disable]:disabled\";\n const fileInputSelector = \"input[name][type=file]:not([disabled])\";\n const linkDisableSelector = \"a[data-disable-with], a[data-disable]\";\n const buttonDisableSelector = \"button[data-remote][data-disable-with], button[data-remote][data-disable]\";\n let nonce = null;\n const loadCSPNonce = () => {\n const metaTag = document.querySelector(\"meta[name=csp-nonce]\");\n return nonce = metaTag && metaTag.content;\n };\n const cspNonce = () => nonce || loadCSPNonce();\n const m = Element.prototype.matches || Element.prototype.matchesSelector || Element.prototype.mozMatchesSelector || Element.prototype.msMatchesSelector || Element.prototype.oMatchesSelector || Element.prototype.webkitMatchesSelector;\n const matches = function(element, selector) {\n if (selector.exclude) {\n return m.call(element, selector.selector) && !m.call(element, selector.exclude);\n } else {\n return m.call(element, selector);\n }\n };\n const EXPANDO = \"_ujsData\";\n const getData = (element, key) => element[EXPANDO] ? element[EXPANDO][key] : undefined;\n const setData = function(element, key, value) {\n if (!element[EXPANDO]) {\n element[EXPANDO] = {};\n }\n return element[EXPANDO][key] = value;\n };\n const $ = selector => Array.prototype.slice.call(document.querySelectorAll(selector));\n const isContentEditable = function(element) {\n var isEditable = false;\n do {\n if (element.isContentEditable) {\n isEditable = true;\n break;\n }\n element = element.parentElement;\n } while (element);\n return isEditable;\n };\n const csrfToken = () => {\n const meta = document.querySelector(\"meta[name=csrf-token]\");\n return meta && meta.content;\n };\n const csrfParam = () => {\n const meta = document.querySelector(\"meta[name=csrf-param]\");\n return meta && meta.content;\n };\n const CSRFProtection = xhr => {\n const token = csrfToken();\n if (token) {\n return xhr.setRequestHeader(\"X-CSRF-Token\", token);\n }\n };\n const refreshCSRFTokens = () => {\n const token = csrfToken();\n const param = csrfParam();\n if (token && param) {\n return $('form input[name=\"' + param + '\"]').forEach((input => input.value = token));\n }\n };\n const AcceptHeaders = {\n \"*\": \"*/*\",\n text: \"text/plain\",\n html: \"text/html\",\n xml: \"application/xml, text/xml\",\n json: \"application/json, text/javascript\",\n script: \"text/javascript, application/javascript, application/ecmascript, application/x-ecmascript\"\n };\n const ajax = options => {\n options = prepareOptions(options);\n var xhr = createXHR(options, (function() {\n const response = processResponse(xhr.response != null ? xhr.response : xhr.responseText, xhr.getResponseHeader(\"Content-Type\"));\n if (Math.floor(xhr.status / 100) === 2) {\n if (typeof options.success === \"function\") {\n options.success(response, xhr.statusText, xhr);\n }\n } else {\n if (typeof options.error === \"function\") {\n options.error(response, xhr.statusText, xhr);\n }\n }\n return typeof options.complete === \"function\" ? options.complete(xhr, xhr.statusText) : undefined;\n }));\n if (options.beforeSend && !options.beforeSend(xhr, options)) {\n return false;\n }\n if (xhr.readyState === XMLHttpRequest.OPENED) {\n return xhr.send(options.data);\n }\n };\n var prepareOptions = function(options) {\n options.url = options.url || location.href;\n options.type = options.type.toUpperCase();\n if (options.type === \"GET\" && options.data) {\n if (options.url.indexOf(\"?\") < 0) {\n options.url += \"?\" + options.data;\n } else {\n options.url += \"&\" + options.data;\n }\n }\n if (!(options.dataType in AcceptHeaders)) {\n options.dataType = \"*\";\n }\n options.accept = AcceptHeaders[options.dataType];\n if (options.dataType !== \"*\") {\n options.accept += \", */*; q=0.01\";\n }\n return options;\n };\n var createXHR = function(options, done) {\n const xhr = new XMLHttpRequest;\n xhr.open(options.type, options.url, true);\n xhr.setRequestHeader(\"Accept\", options.accept);\n if (typeof options.data === \"string\") {\n xhr.setRequestHeader(\"Content-Type\", \"application/x-www-form-urlencoded; charset=UTF-8\");\n }\n if (!options.crossDomain) {\n xhr.setRequestHeader(\"X-Requested-With\", \"XMLHttpRequest\");\n CSRFProtection(xhr);\n }\n xhr.withCredentials = !!options.withCredentials;\n xhr.onreadystatechange = function() {\n if (xhr.readyState === XMLHttpRequest.DONE) {\n return done(xhr);\n }\n };\n return xhr;\n };\n var processResponse = function(response, type) {\n if (typeof response === \"string\" && typeof type === \"string\") {\n if (type.match(/\\bjson\\b/)) {\n try {\n response = JSON.parse(response);\n } catch (error) {}\n } else if (type.match(/\\b(?:java|ecma)script\\b/)) {\n const script = document.createElement(\"script\");\n script.setAttribute(\"nonce\", cspNonce());\n script.text = response;\n document.head.appendChild(script).parentNode.removeChild(script);\n } else if (type.match(/\\b(xml|html|svg)\\b/)) {\n const parser = new DOMParser;\n type = type.replace(/;.+/, \"\");\n try {\n response = parser.parseFromString(response, type);\n } catch (error1) {}\n }\n }\n return response;\n };\n const href = element => element.href;\n const isCrossDomain = function(url) {\n const originAnchor = document.createElement(\"a\");\n originAnchor.href = location.href;\n const urlAnchor = document.createElement(\"a\");\n try {\n urlAnchor.href = url;\n return !((!urlAnchor.protocol || urlAnchor.protocol === \":\") && !urlAnchor.host || originAnchor.protocol + \"//\" + originAnchor.host === urlAnchor.protocol + \"//\" + urlAnchor.host);\n } catch (e) {\n return true;\n }\n };\n let preventDefault;\n let {CustomEvent: CustomEvent} = window;\n if (typeof CustomEvent !== \"function\") {\n CustomEvent = function(event, params) {\n const evt = document.createEvent(\"CustomEvent\");\n evt.initCustomEvent(event, params.bubbles, params.cancelable, params.detail);\n return evt;\n };\n CustomEvent.prototype = window.Event.prototype;\n ({preventDefault: preventDefault} = CustomEvent.prototype);\n CustomEvent.prototype.preventDefault = function() {\n const result = preventDefault.call(this);\n if (this.cancelable && !this.defaultPrevented) {\n Object.defineProperty(this, \"defaultPrevented\", {\n get() {\n return true;\n }\n });\n }\n return result;\n };\n }\n const fire = (obj, name, data) => {\n const event = new CustomEvent(name, {\n bubbles: true,\n cancelable: true,\n detail: data\n });\n obj.dispatchEvent(event);\n return !event.defaultPrevented;\n };\n const stopEverything = e => {\n fire(e.target, \"ujs:everythingStopped\");\n e.preventDefault();\n e.stopPropagation();\n e.stopImmediatePropagation();\n };\n const delegate = (element, selector, eventType, handler) => element.addEventListener(eventType, (function(e) {\n let {target: target} = e;\n while (!!(target instanceof Element) && !matches(target, selector)) {\n target = target.parentNode;\n }\n if (target instanceof Element && handler.call(target, e) === false) {\n e.preventDefault();\n e.stopPropagation();\n }\n }));\n const toArray = e => Array.prototype.slice.call(e);\n const serializeElement = (element, additionalParam) => {\n let inputs = [ element ];\n if (matches(element, \"form\")) {\n inputs = toArray(element.elements);\n }\n const params = [];\n inputs.forEach((function(input) {\n if (!input.name || input.disabled) {\n return;\n }\n if (matches(input, \"fieldset[disabled] *\")) {\n return;\n }\n if (matches(input, \"select\")) {\n toArray(input.options).forEach((function(option) {\n if (option.selected) {\n params.push({\n name: input.name,\n value: option.value\n });\n }\n }));\n } else if (input.checked || [ \"radio\", \"checkbox\", \"submit\" ].indexOf(input.type) === -1) {\n params.push({\n name: input.name,\n value: input.value\n });\n }\n }));\n if (additionalParam) {\n params.push(additionalParam);\n }\n return params.map((function(param) {\n if (param.name) {\n return `${encodeURIComponent(param.name)}=${encodeURIComponent(param.value)}`;\n } else {\n return param;\n }\n })).join(\"&\");\n };\n const formElements = (form, selector) => {\n if (matches(form, \"form\")) {\n return toArray(form.elements).filter((el => matches(el, selector)));\n } else {\n return toArray(form.querySelectorAll(selector));\n }\n };\n const handleConfirmWithRails = rails => function(e) {\n if (!allowAction(this, rails)) {\n stopEverything(e);\n }\n };\n const confirm = (message, element) => window.confirm(message);\n var allowAction = function(element, rails) {\n let callback;\n const message = element.getAttribute(\"data-confirm\");\n if (!message) {\n return true;\n }\n let answer = false;\n if (fire(element, \"confirm\")) {\n try {\n answer = rails.confirm(message, element);\n } catch (error) {}\n callback = fire(element, \"confirm:complete\", [ answer ]);\n }\n return answer && callback;\n };\n const handleDisabledElement = function(e) {\n const element = this;\n if (element.disabled) {\n stopEverything(e);\n }\n };\n const enableElement = e => {\n let element;\n if (e instanceof Event) {\n if (isXhrRedirect(e)) {\n return;\n }\n element = e.target;\n } else {\n element = e;\n }\n if (isContentEditable(element)) {\n return;\n }\n if (matches(element, linkDisableSelector)) {\n return enableLinkElement(element);\n } else if (matches(element, buttonDisableSelector) || matches(element, formEnableSelector)) {\n return enableFormElement(element);\n } else if (matches(element, formSubmitSelector)) {\n return enableFormElements(element);\n }\n };\n const disableElement = e => {\n const element = e instanceof Event ? e.target : e;\n if (isContentEditable(element)) {\n return;\n }\n if (matches(element, linkDisableSelector)) {\n return disableLinkElement(element);\n } else if (matches(element, buttonDisableSelector) || matches(element, formDisableSelector)) {\n return disableFormElement(element);\n } else if (matches(element, formSubmitSelector)) {\n return disableFormElements(element);\n }\n };\n var disableLinkElement = function(element) {\n if (getData(element, \"ujs:disabled\")) {\n return;\n }\n const replacement = element.getAttribute(\"data-disable-with\");\n if (replacement != null) {\n setData(element, \"ujs:enable-with\", element.innerHTML);\n element.innerHTML = replacement;\n }\n element.addEventListener(\"click\", stopEverything);\n return setData(element, \"ujs:disabled\", true);\n };\n var enableLinkElement = function(element) {\n const originalText = getData(element, \"ujs:enable-with\");\n if (originalText != null) {\n element.innerHTML = originalText;\n setData(element, \"ujs:enable-with\", null);\n }\n element.removeEventListener(\"click\", stopEverything);\n return setData(element, \"ujs:disabled\", null);\n };\n var disableFormElements = form => formElements(form, formDisableSelector).forEach(disableFormElement);\n var disableFormElement = function(element) {\n if (getData(element, \"ujs:disabled\")) {\n return;\n }\n const replacement = element.getAttribute(\"data-disable-with\");\n if (replacement != null) {\n if (matches(element, \"button\")) {\n setData(element, \"ujs:enable-with\", element.innerHTML);\n element.innerHTML = replacement;\n } else {\n setData(element, \"ujs:enable-with\", element.value);\n element.value = replacement;\n }\n }\n element.disabled = true;\n return setData(element, \"ujs:disabled\", true);\n };\n var enableFormElements = form => formElements(form, formEnableSelector).forEach((element => enableFormElement(element)));\n var enableFormElement = function(element) {\n const originalText = getData(element, \"ujs:enable-with\");\n if (originalText != null) {\n if (matches(element, \"button\")) {\n element.innerHTML = originalText;\n } else {\n element.value = originalText;\n }\n setData(element, \"ujs:enable-with\", null);\n }\n element.disabled = false;\n return setData(element, \"ujs:disabled\", null);\n };\n var isXhrRedirect = function(event) {\n const xhr = event.detail ? event.detail[0] : undefined;\n return xhr && xhr.getResponseHeader(\"X-Xhr-Redirect\");\n };\n const handleMethodWithRails = rails => function(e) {\n const link = this;\n const method = link.getAttribute(\"data-method\");\n if (!method) {\n return;\n }\n if (isContentEditable(this)) {\n return;\n }\n const href = rails.href(link);\n const csrfToken$1 = csrfToken();\n const csrfParam$1 = csrfParam();\n const form = document.createElement(\"form\");\n let formContent = ``;\n if (csrfParam$1 && csrfToken$1 && !isCrossDomain(href)) {\n formContent += ``;\n }\n formContent += '';\n form.method = \"post\";\n form.action = href;\n form.target = link.target;\n form.innerHTML = formContent;\n form.style.display = \"none\";\n document.body.appendChild(form);\n form.querySelector('[type=\"submit\"]').click();\n stopEverything(e);\n };\n const isRemote = function(element) {\n const value = element.getAttribute(\"data-remote\");\n return value != null && value !== \"false\";\n };\n const handleRemoteWithRails = rails => function(e) {\n let data, method, url;\n const element = this;\n if (!isRemote(element)) {\n return true;\n }\n if (!fire(element, \"ajax:before\")) {\n fire(element, \"ajax:stopped\");\n return false;\n }\n if (isContentEditable(element)) {\n fire(element, \"ajax:stopped\");\n return false;\n }\n const withCredentials = element.getAttribute(\"data-with-credentials\");\n const dataType = element.getAttribute(\"data-type\") || \"script\";\n if (matches(element, formSubmitSelector)) {\n const button = getData(element, \"ujs:submit-button\");\n method = getData(element, \"ujs:submit-button-formmethod\") || element.getAttribute(\"method\") || \"get\";\n url = getData(element, \"ujs:submit-button-formaction\") || element.getAttribute(\"action\") || location.href;\n if (method.toUpperCase() === \"GET\") {\n url = url.replace(/\\?.*$/, \"\");\n }\n if (element.enctype === \"multipart/form-data\") {\n data = new FormData(element);\n if (button != null) {\n data.append(button.name, button.value);\n }\n } else {\n data = serializeElement(element, button);\n }\n setData(element, \"ujs:submit-button\", null);\n setData(element, \"ujs:submit-button-formmethod\", null);\n setData(element, \"ujs:submit-button-formaction\", null);\n } else if (matches(element, buttonClickSelector) || matches(element, inputChangeSelector)) {\n method = element.getAttribute(\"data-method\");\n url = element.getAttribute(\"data-url\");\n data = serializeElement(element, element.getAttribute(\"data-params\"));\n } else {\n method = element.getAttribute(\"data-method\");\n url = rails.href(element);\n data = element.getAttribute(\"data-params\");\n }\n ajax({\n type: method || \"GET\",\n url: url,\n data: data,\n dataType: dataType,\n beforeSend(xhr, options) {\n if (fire(element, \"ajax:beforeSend\", [ xhr, options ])) {\n return fire(element, \"ajax:send\", [ xhr ]);\n } else {\n fire(element, \"ajax:stopped\");\n return false;\n }\n },\n success(...args) {\n return fire(element, \"ajax:success\", args);\n },\n error(...args) {\n return fire(element, \"ajax:error\", args);\n },\n complete(...args) {\n return fire(element, \"ajax:complete\", args);\n },\n crossDomain: isCrossDomain(url),\n withCredentials: withCredentials != null && withCredentials !== \"false\"\n });\n stopEverything(e);\n };\n const formSubmitButtonClick = function(e) {\n const button = this;\n const {form: form} = button;\n if (!form) {\n return;\n }\n if (button.name) {\n setData(form, \"ujs:submit-button\", {\n name: button.name,\n value: button.value\n });\n }\n setData(form, \"ujs:formnovalidate-button\", button.formNoValidate);\n setData(form, \"ujs:submit-button-formaction\", button.getAttribute(\"formaction\"));\n return setData(form, \"ujs:submit-button-formmethod\", button.getAttribute(\"formmethod\"));\n };\n const preventInsignificantClick = function(e) {\n const link = this;\n const method = (link.getAttribute(\"data-method\") || \"GET\").toUpperCase();\n const data = link.getAttribute(\"data-params\");\n const metaClick = e.metaKey || e.ctrlKey;\n const insignificantMetaClick = metaClick && method === \"GET\" && !data;\n const nonPrimaryMouseClick = e.button != null && e.button !== 0;\n if (nonPrimaryMouseClick || insignificantMetaClick) {\n e.stopImmediatePropagation();\n }\n };\n const Rails = {\n $: $,\n ajax: ajax,\n buttonClickSelector: buttonClickSelector,\n buttonDisableSelector: buttonDisableSelector,\n confirm: confirm,\n cspNonce: cspNonce,\n csrfToken: csrfToken,\n csrfParam: csrfParam,\n CSRFProtection: CSRFProtection,\n delegate: delegate,\n disableElement: disableElement,\n enableElement: enableElement,\n fileInputSelector: fileInputSelector,\n fire: fire,\n formElements: formElements,\n formEnableSelector: formEnableSelector,\n formDisableSelector: formDisableSelector,\n formInputClickSelector: formInputClickSelector,\n formSubmitButtonClick: formSubmitButtonClick,\n formSubmitSelector: formSubmitSelector,\n getData: getData,\n handleDisabledElement: handleDisabledElement,\n href: href,\n inputChangeSelector: inputChangeSelector,\n isCrossDomain: isCrossDomain,\n linkClickSelector: linkClickSelector,\n linkDisableSelector: linkDisableSelector,\n loadCSPNonce: loadCSPNonce,\n matches: matches,\n preventInsignificantClick: preventInsignificantClick,\n refreshCSRFTokens: refreshCSRFTokens,\n serializeElement: serializeElement,\n setData: setData,\n stopEverything: stopEverything\n };\n const handleConfirm = handleConfirmWithRails(Rails);\n Rails.handleConfirm = handleConfirm;\n const handleMethod = handleMethodWithRails(Rails);\n Rails.handleMethod = handleMethod;\n const handleRemote = handleRemoteWithRails(Rails);\n Rails.handleRemote = handleRemote;\n const start = function() {\n if (window._rails_loaded) {\n throw new Error(\"rails-ujs has already been loaded!\");\n }\n window.addEventListener(\"pageshow\", (function() {\n $(formEnableSelector).forEach((function(el) {\n if (getData(el, \"ujs:disabled\")) {\n enableElement(el);\n }\n }));\n $(linkDisableSelector).forEach((function(el) {\n if (getData(el, \"ujs:disabled\")) {\n enableElement(el);\n }\n }));\n }));\n delegate(document, linkDisableSelector, \"ajax:complete\", enableElement);\n delegate(document, linkDisableSelector, \"ajax:stopped\", enableElement);\n delegate(document, buttonDisableSelector, \"ajax:complete\", enableElement);\n delegate(document, buttonDisableSelector, \"ajax:stopped\", enableElement);\n delegate(document, linkClickSelector, \"click\", preventInsignificantClick);\n delegate(document, linkClickSelector, \"click\", handleDisabledElement);\n delegate(document, linkClickSelector, \"click\", handleConfirm);\n delegate(document, linkClickSelector, \"click\", disableElement);\n delegate(document, linkClickSelector, \"click\", handleRemote);\n delegate(document, linkClickSelector, \"click\", handleMethod);\n delegate(document, buttonClickSelector, \"click\", preventInsignificantClick);\n delegate(document, buttonClickSelector, \"click\", handleDisabledElement);\n delegate(document, buttonClickSelector, \"click\", handleConfirm);\n delegate(document, buttonClickSelector, \"click\", disableElement);\n delegate(document, buttonClickSelector, \"click\", handleRemote);\n delegate(document, inputChangeSelector, \"change\", handleDisabledElement);\n delegate(document, inputChangeSelector, \"change\", handleConfirm);\n delegate(document, inputChangeSelector, \"change\", handleRemote);\n delegate(document, formSubmitSelector, \"submit\", handleDisabledElement);\n delegate(document, formSubmitSelector, \"submit\", handleConfirm);\n delegate(document, formSubmitSelector, \"submit\", handleRemote);\n delegate(document, formSubmitSelector, \"submit\", (e => setTimeout((() => disableElement(e)), 13)));\n delegate(document, formSubmitSelector, \"ajax:send\", disableElement);\n delegate(document, formSubmitSelector, \"ajax:complete\", enableElement);\n delegate(document, formInputClickSelector, \"click\", preventInsignificantClick);\n delegate(document, formInputClickSelector, \"click\", handleDisabledElement);\n delegate(document, formInputClickSelector, \"click\", handleConfirm);\n delegate(document, formInputClickSelector, \"click\", formSubmitButtonClick);\n document.addEventListener(\"DOMContentLoaded\", refreshCSRFTokens);\n document.addEventListener(\"DOMContentLoaded\", loadCSPNonce);\n return window._rails_loaded = true;\n };\n Rails.start = start;\n if (typeof jQuery !== \"undefined\" && jQuery && jQuery.ajax) {\n if (jQuery.rails) {\n throw new Error(\"If you load both jquery_ujs and rails-ujs, use rails-ujs only.\");\n }\n jQuery.rails = Rails;\n jQuery.ajaxPrefilter((function(options, originalOptions, xhr) {\n if (!options.crossDomain) {\n return CSRFProtection(xhr);\n }\n }));\n }\n if (typeof exports !== \"object\" && typeof module === \"undefined\") {\n window.Rails = Rails;\n if (fire(document, \"rails:attachBindings\")) {\n start();\n }\n }\n return Rails;\n}));\n/* eslint-enable */\n", "/* eslint-disable */\n(function(global, factory) {\n typeof exports === \"object\" && typeof module !== \"undefined\" ? factory(exports) : typeof define === \"function\" && define.amd ? define([ \"exports\" ], factory) : (global = typeof globalThis !== \"undefined\" ? globalThis : global || self,\n factory(global.ActiveStorage = {}));\n})(this, (function(exports) {\n \"use strict\";\n var sparkMd5 = {\n exports: {}\n };\n (function(module, exports) {\n (function(factory) {\n {\n module.exports = factory();\n }\n })((function(undefined$1) {\n var hex_chr = [ \"0\", \"1\", \"2\", \"3\", \"4\", \"5\", \"6\", \"7\", \"8\", \"9\", \"a\", \"b\", \"c\", \"d\", \"e\", \"f\" ];\n function md5cycle(x, k) {\n var a = x[0], b = x[1], c = x[2], d = x[3];\n a += (b & c | ~b & d) + k[0] - 680876936 | 0;\n a = (a << 7 | a >>> 25) + b | 0;\n d += (a & b | ~a & c) + k[1] - 389564586 | 0;\n d = (d << 12 | d >>> 20) + a | 0;\n c += (d & a | ~d & b) + k[2] + 606105819 | 0;\n c = (c << 17 | c >>> 15) + d | 0;\n b += (c & d | ~c & a) + k[3] - 1044525330 | 0;\n b = (b << 22 | b >>> 10) + c | 0;\n a += (b & c | ~b & d) + k[4] - 176418897 | 0;\n a = (a << 7 | a >>> 25) + b | 0;\n d += (a & b | ~a & c) + k[5] + 1200080426 | 0;\n d = (d << 12 | d >>> 20) + a | 0;\n c += (d & a | ~d & b) + k[6] - 1473231341 | 0;\n c = (c << 17 | c >>> 15) + d | 0;\n b += (c & d | ~c & a) + k[7] - 45705983 | 0;\n b = (b << 22 | b >>> 10) + c | 0;\n a += (b & c | ~b & d) + k[8] + 1770035416 | 0;\n a = (a << 7 | a >>> 25) + b | 0;\n d += (a & b | ~a & c) + k[9] - 1958414417 | 0;\n d = (d << 12 | d >>> 20) + a | 0;\n c += (d & a | ~d & b) + k[10] - 42063 | 0;\n c = (c << 17 | c >>> 15) + d | 0;\n b += (c & d | ~c & a) + k[11] - 1990404162 | 0;\n b = (b << 22 | b >>> 10) + c | 0;\n a += (b & c | ~b & d) + k[12] + 1804603682 | 0;\n a = (a << 7 | a >>> 25) + b | 0;\n d += (a & b | ~a & c) + k[13] - 40341101 | 0;\n d = (d << 12 | d >>> 20) + a | 0;\n c += (d & a | ~d & b) + k[14] - 1502002290 | 0;\n c = (c << 17 | c >>> 15) + d | 0;\n b += (c & d | ~c & a) + k[15] + 1236535329 | 0;\n b = (b << 22 | b >>> 10) + c | 0;\n a += (b & d | c & ~d) + k[1] - 165796510 | 0;\n a = (a << 5 | a >>> 27) + b | 0;\n d += (a & c | b & ~c) + k[6] - 1069501632 | 0;\n d = (d << 9 | d >>> 23) + a | 0;\n c += (d & b | a & ~b) + k[11] + 643717713 | 0;\n c = (c << 14 | c >>> 18) + d | 0;\n b += (c & a | d & ~a) + k[0] - 373897302 | 0;\n b = (b << 20 | b >>> 12) + c | 0;\n a += (b & d | c & ~d) + k[5] - 701558691 | 0;\n a = (a << 5 | a >>> 27) + b | 0;\n d += (a & c | b & ~c) + k[10] + 38016083 | 0;\n d = (d << 9 | d >>> 23) + a | 0;\n c += (d & b | a & ~b) + k[15] - 660478335 | 0;\n c = (c << 14 | c >>> 18) + d | 0;\n b += (c & a | d & ~a) + k[4] - 405537848 | 0;\n b = (b << 20 | b >>> 12) + c | 0;\n a += (b & d | c & ~d) + k[9] + 568446438 | 0;\n a = (a << 5 | a >>> 27) + b | 0;\n d += (a & c | b & ~c) + k[14] - 1019803690 | 0;\n d = (d << 9 | d >>> 23) + a | 0;\n c += (d & b | a & ~b) + k[3] - 187363961 | 0;\n c = (c << 14 | c >>> 18) + d | 0;\n b += (c & a | d & ~a) + k[8] + 1163531501 | 0;\n b = (b << 20 | b >>> 12) + c | 0;\n a += (b & d | c & ~d) + k[13] - 1444681467 | 0;\n a = (a << 5 | a >>> 27) + b | 0;\n d += (a & c | b & ~c) + k[2] - 51403784 | 0;\n d = (d << 9 | d >>> 23) + a | 0;\n c += (d & b | a & ~b) + k[7] + 1735328473 | 0;\n c = (c << 14 | c >>> 18) + d | 0;\n b += (c & a | d & ~a) + k[12] - 1926607734 | 0;\n b = (b << 20 | b >>> 12) + c | 0;\n a += (b ^ c ^ d) + k[5] - 378558 | 0;\n a = (a << 4 | a >>> 28) + b | 0;\n d += (a ^ b ^ c) + k[8] - 2022574463 | 0;\n d = (d << 11 | d >>> 21) + a | 0;\n c += (d ^ a ^ b) + k[11] + 1839030562 | 0;\n c = (c << 16 | c >>> 16) + d | 0;\n b += (c ^ d ^ a) + k[14] - 35309556 | 0;\n b = (b << 23 | b >>> 9) + c | 0;\n a += (b ^ c ^ d) + k[1] - 1530992060 | 0;\n a = (a << 4 | a >>> 28) + b | 0;\n d += (a ^ b ^ c) + k[4] + 1272893353 | 0;\n d = (d << 11 | d >>> 21) + a | 0;\n c += (d ^ a ^ b) + k[7] - 155497632 | 0;\n c = (c << 16 | c >>> 16) + d | 0;\n b += (c ^ d ^ a) + k[10] - 1094730640 | 0;\n b = (b << 23 | b >>> 9) + c | 0;\n a += (b ^ c ^ d) + k[13] + 681279174 | 0;\n a = (a << 4 | a >>> 28) + b | 0;\n d += (a ^ b ^ c) + k[0] - 358537222 | 0;\n d = (d << 11 | d >>> 21) + a | 0;\n c += (d ^ a ^ b) + k[3] - 722521979 | 0;\n c = (c << 16 | c >>> 16) + d | 0;\n b += (c ^ d ^ a) + k[6] + 76029189 | 0;\n b = (b << 23 | b >>> 9) + c | 0;\n a += (b ^ c ^ d) + k[9] - 640364487 | 0;\n a = (a << 4 | a >>> 28) + b | 0;\n d += (a ^ b ^ c) + k[12] - 421815835 | 0;\n d = (d << 11 | d >>> 21) + a | 0;\n c += (d ^ a ^ b) + k[15] + 530742520 | 0;\n c = (c << 16 | c >>> 16) + d | 0;\n b += (c ^ d ^ a) + k[2] - 995338651 | 0;\n b = (b << 23 | b >>> 9) + c | 0;\n a += (c ^ (b | ~d)) + k[0] - 198630844 | 0;\n a = (a << 6 | a >>> 26) + b | 0;\n d += (b ^ (a | ~c)) + k[7] + 1126891415 | 0;\n d = (d << 10 | d >>> 22) + a | 0;\n c += (a ^ (d | ~b)) + k[14] - 1416354905 | 0;\n c = (c << 15 | c >>> 17) + d | 0;\n b += (d ^ (c | ~a)) + k[5] - 57434055 | 0;\n b = (b << 21 | b >>> 11) + c | 0;\n a += (c ^ (b | ~d)) + k[12] + 1700485571 | 0;\n a = (a << 6 | a >>> 26) + b | 0;\n d += (b ^ (a | ~c)) + k[3] - 1894986606 | 0;\n d = (d << 10 | d >>> 22) + a | 0;\n c += (a ^ (d | ~b)) + k[10] - 1051523 | 0;\n c = (c << 15 | c >>> 17) + d | 0;\n b += (d ^ (c | ~a)) + k[1] - 2054922799 | 0;\n b = (b << 21 | b >>> 11) + c | 0;\n a += (c ^ (b | ~d)) + k[8] + 1873313359 | 0;\n a = (a << 6 | a >>> 26) + b | 0;\n d += (b ^ (a | ~c)) + k[15] - 30611744 | 0;\n d = (d << 10 | d >>> 22) + a | 0;\n c += (a ^ (d | ~b)) + k[6] - 1560198380 | 0;\n c = (c << 15 | c >>> 17) + d | 0;\n b += (d ^ (c | ~a)) + k[13] + 1309151649 | 0;\n b = (b << 21 | b >>> 11) + c | 0;\n a += (c ^ (b | ~d)) + k[4] - 145523070 | 0;\n a = (a << 6 | a >>> 26) + b | 0;\n d += (b ^ (a | ~c)) + k[11] - 1120210379 | 0;\n d = (d << 10 | d >>> 22) + a | 0;\n c += (a ^ (d | ~b)) + k[2] + 718787259 | 0;\n c = (c << 15 | c >>> 17) + d | 0;\n b += (d ^ (c | ~a)) + k[9] - 343485551 | 0;\n b = (b << 21 | b >>> 11) + c | 0;\n x[0] = a + x[0] | 0;\n x[1] = b + x[1] | 0;\n x[2] = c + x[2] | 0;\n x[3] = d + x[3] | 0;\n }\n function md5blk(s) {\n var md5blks = [], i;\n for (i = 0; i < 64; i += 4) {\n md5blks[i >> 2] = s.charCodeAt(i) + (s.charCodeAt(i + 1) << 8) + (s.charCodeAt(i + 2) << 16) + (s.charCodeAt(i + 3) << 24);\n }\n return md5blks;\n }\n function md5blk_array(a) {\n var md5blks = [], i;\n for (i = 0; i < 64; i += 4) {\n md5blks[i >> 2] = a[i] + (a[i + 1] << 8) + (a[i + 2] << 16) + (a[i + 3] << 24);\n }\n return md5blks;\n }\n function md51(s) {\n var n = s.length, state = [ 1732584193, -271733879, -1732584194, 271733878 ], i, length, tail, tmp, lo, hi;\n for (i = 64; i <= n; i += 64) {\n md5cycle(state, md5blk(s.substring(i - 64, i)));\n }\n s = s.substring(i - 64);\n length = s.length;\n tail = [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ];\n for (i = 0; i < length; i += 1) {\n tail[i >> 2] |= s.charCodeAt(i) << (i % 4 << 3);\n }\n tail[i >> 2] |= 128 << (i % 4 << 3);\n if (i > 55) {\n md5cycle(state, tail);\n for (i = 0; i < 16; i += 1) {\n tail[i] = 0;\n }\n }\n tmp = n * 8;\n tmp = tmp.toString(16).match(/(.*?)(.{0,8})$/);\n lo = parseInt(tmp[2], 16);\n hi = parseInt(tmp[1], 16) || 0;\n tail[14] = lo;\n tail[15] = hi;\n md5cycle(state, tail);\n return state;\n }\n function md51_array(a) {\n var n = a.length, state = [ 1732584193, -271733879, -1732584194, 271733878 ], i, length, tail, tmp, lo, hi;\n for (i = 64; i <= n; i += 64) {\n md5cycle(state, md5blk_array(a.subarray(i - 64, i)));\n }\n a = i - 64 < n ? a.subarray(i - 64) : new Uint8Array(0);\n length = a.length;\n tail = [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ];\n for (i = 0; i < length; i += 1) {\n tail[i >> 2] |= a[i] << (i % 4 << 3);\n }\n tail[i >> 2] |= 128 << (i % 4 << 3);\n if (i > 55) {\n md5cycle(state, tail);\n for (i = 0; i < 16; i += 1) {\n tail[i] = 0;\n }\n }\n tmp = n * 8;\n tmp = tmp.toString(16).match(/(.*?)(.{0,8})$/);\n lo = parseInt(tmp[2], 16);\n hi = parseInt(tmp[1], 16) || 0;\n tail[14] = lo;\n tail[15] = hi;\n md5cycle(state, tail);\n return state;\n }\n function rhex(n) {\n var s = \"\", j;\n for (j = 0; j < 4; j += 1) {\n s += hex_chr[n >> j * 8 + 4 & 15] + hex_chr[n >> j * 8 & 15];\n }\n return s;\n }\n function hex(x) {\n var i;\n for (i = 0; i < x.length; i += 1) {\n x[i] = rhex(x[i]);\n }\n return x.join(\"\");\n }\n if (hex(md51(\"hello\")) !== \"5d41402abc4b2a76b9719d911017c592\") ;\n if (typeof ArrayBuffer !== \"undefined\" && !ArrayBuffer.prototype.slice) {\n (function() {\n function clamp(val, length) {\n val = val | 0 || 0;\n if (val < 0) {\n return Math.max(val + length, 0);\n }\n return Math.min(val, length);\n }\n ArrayBuffer.prototype.slice = function(from, to) {\n var length = this.byteLength, begin = clamp(from, length), end = length, num, target, targetArray, sourceArray;\n if (to !== undefined$1) {\n end = clamp(to, length);\n }\n if (begin > end) {\n return new ArrayBuffer(0);\n }\n num = end - begin;\n target = new ArrayBuffer(num);\n targetArray = new Uint8Array(target);\n sourceArray = new Uint8Array(this, begin, num);\n targetArray.set(sourceArray);\n return target;\n };\n })();\n }\n function toUtf8(str) {\n if (/[\\u0080-\\uFFFF]/.test(str)) {\n str = unescape(encodeURIComponent(str));\n }\n return str;\n }\n function utf8Str2ArrayBuffer(str, returnUInt8Array) {\n var length = str.length, buff = new ArrayBuffer(length), arr = new Uint8Array(buff), i;\n for (i = 0; i < length; i += 1) {\n arr[i] = str.charCodeAt(i);\n }\n return returnUInt8Array ? arr : buff;\n }\n function arrayBuffer2Utf8Str(buff) {\n return String.fromCharCode.apply(null, new Uint8Array(buff));\n }\n function concatenateArrayBuffers(first, second, returnUInt8Array) {\n var result = new Uint8Array(first.byteLength + second.byteLength);\n result.set(new Uint8Array(first));\n result.set(new Uint8Array(second), first.byteLength);\n return returnUInt8Array ? result : result.buffer;\n }\n function hexToBinaryString(hex) {\n var bytes = [], length = hex.length, x;\n for (x = 0; x < length - 1; x += 2) {\n bytes.push(parseInt(hex.substr(x, 2), 16));\n }\n return String.fromCharCode.apply(String, bytes);\n }\n function SparkMD5() {\n this.reset();\n }\n SparkMD5.prototype.append = function(str) {\n this.appendBinary(toUtf8(str));\n return this;\n };\n SparkMD5.prototype.appendBinary = function(contents) {\n this._buff += contents;\n this._length += contents.length;\n var length = this._buff.length, i;\n for (i = 64; i <= length; i += 64) {\n md5cycle(this._hash, md5blk(this._buff.substring(i - 64, i)));\n }\n this._buff = this._buff.substring(i - 64);\n return this;\n };\n SparkMD5.prototype.end = function(raw) {\n var buff = this._buff, length = buff.length, i, tail = [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ], ret;\n for (i = 0; i < length; i += 1) {\n tail[i >> 2] |= buff.charCodeAt(i) << (i % 4 << 3);\n }\n this._finish(tail, length);\n ret = hex(this._hash);\n if (raw) {\n ret = hexToBinaryString(ret);\n }\n this.reset();\n return ret;\n };\n SparkMD5.prototype.reset = function() {\n this._buff = \"\";\n this._length = 0;\n this._hash = [ 1732584193, -271733879, -1732584194, 271733878 ];\n return this;\n };\n SparkMD5.prototype.getState = function() {\n return {\n buff: this._buff,\n length: this._length,\n hash: this._hash.slice()\n };\n };\n SparkMD5.prototype.setState = function(state) {\n this._buff = state.buff;\n this._length = state.length;\n this._hash = state.hash;\n return this;\n };\n SparkMD5.prototype.destroy = function() {\n delete this._hash;\n delete this._buff;\n delete this._length;\n };\n SparkMD5.prototype._finish = function(tail, length) {\n var i = length, tmp, lo, hi;\n tail[i >> 2] |= 128 << (i % 4 << 3);\n if (i > 55) {\n md5cycle(this._hash, tail);\n for (i = 0; i < 16; i += 1) {\n tail[i] = 0;\n }\n }\n tmp = this._length * 8;\n tmp = tmp.toString(16).match(/(.*?)(.{0,8})$/);\n lo = parseInt(tmp[2], 16);\n hi = parseInt(tmp[1], 16) || 0;\n tail[14] = lo;\n tail[15] = hi;\n md5cycle(this._hash, tail);\n };\n SparkMD5.hash = function(str, raw) {\n return SparkMD5.hashBinary(toUtf8(str), raw);\n };\n SparkMD5.hashBinary = function(content, raw) {\n var hash = md51(content), ret = hex(hash);\n return raw ? hexToBinaryString(ret) : ret;\n };\n SparkMD5.ArrayBuffer = function() {\n this.reset();\n };\n SparkMD5.ArrayBuffer.prototype.append = function(arr) {\n var buff = concatenateArrayBuffers(this._buff.buffer, arr, true), length = buff.length, i;\n this._length += arr.byteLength;\n for (i = 64; i <= length; i += 64) {\n md5cycle(this._hash, md5blk_array(buff.subarray(i - 64, i)));\n }\n this._buff = i - 64 < length ? new Uint8Array(buff.buffer.slice(i - 64)) : new Uint8Array(0);\n return this;\n };\n SparkMD5.ArrayBuffer.prototype.end = function(raw) {\n var buff = this._buff, length = buff.length, tail = [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ], i, ret;\n for (i = 0; i < length; i += 1) {\n tail[i >> 2] |= buff[i] << (i % 4 << 3);\n }\n this._finish(tail, length);\n ret = hex(this._hash);\n if (raw) {\n ret = hexToBinaryString(ret);\n }\n this.reset();\n return ret;\n };\n SparkMD5.ArrayBuffer.prototype.reset = function() {\n this._buff = new Uint8Array(0);\n this._length = 0;\n this._hash = [ 1732584193, -271733879, -1732584194, 271733878 ];\n return this;\n };\n SparkMD5.ArrayBuffer.prototype.getState = function() {\n var state = SparkMD5.prototype.getState.call(this);\n state.buff = arrayBuffer2Utf8Str(state.buff);\n return state;\n };\n SparkMD5.ArrayBuffer.prototype.setState = function(state) {\n state.buff = utf8Str2ArrayBuffer(state.buff, true);\n return SparkMD5.prototype.setState.call(this, state);\n };\n SparkMD5.ArrayBuffer.prototype.destroy = SparkMD5.prototype.destroy;\n SparkMD5.ArrayBuffer.prototype._finish = SparkMD5.prototype._finish;\n SparkMD5.ArrayBuffer.hash = function(arr, raw) {\n var hash = md51_array(new Uint8Array(arr)), ret = hex(hash);\n return raw ? hexToBinaryString(ret) : ret;\n };\n return SparkMD5;\n }));\n })(sparkMd5);\n var SparkMD5 = sparkMd5.exports;\n const fileSlice = File.prototype.slice || File.prototype.mozSlice || File.prototype.webkitSlice;\n class FileChecksum {\n static create(file, callback) {\n const instance = new FileChecksum(file);\n instance.create(callback);\n }\n constructor(file) {\n this.file = file;\n this.chunkSize = 2097152;\n this.chunkCount = Math.ceil(this.file.size / this.chunkSize);\n this.chunkIndex = 0;\n }\n create(callback) {\n this.callback = callback;\n this.md5Buffer = new SparkMD5.ArrayBuffer;\n this.fileReader = new FileReader;\n this.fileReader.addEventListener(\"load\", (event => this.fileReaderDidLoad(event)));\n this.fileReader.addEventListener(\"error\", (event => this.fileReaderDidError(event)));\n this.readNextChunk();\n }\n fileReaderDidLoad(event) {\n this.md5Buffer.append(event.target.result);\n if (!this.readNextChunk()) {\n const binaryDigest = this.md5Buffer.end(true);\n const base64digest = btoa(binaryDigest);\n this.callback(null, base64digest);\n }\n }\n fileReaderDidError(event) {\n this.callback(`Error reading ${this.file.name}`);\n }\n readNextChunk() {\n if (this.chunkIndex < this.chunkCount || this.chunkIndex == 0 && this.chunkCount == 0) {\n const start = this.chunkIndex * this.chunkSize;\n const end = Math.min(start + this.chunkSize, this.file.size);\n const bytes = fileSlice.call(this.file, start, end);\n this.fileReader.readAsArrayBuffer(bytes);\n this.chunkIndex++;\n return true;\n } else {\n return false;\n }\n }\n }\n function getMetaValue(name) {\n const element = findElement(document.head, `meta[name=\"${name}\"]`);\n if (element) {\n return element.getAttribute(\"content\");\n }\n }\n function findElements(root, selector) {\n if (typeof root == \"string\") {\n selector = root;\n root = document;\n }\n const elements = root.querySelectorAll(selector);\n return toArray(elements);\n }\n function findElement(root, selector) {\n if (typeof root == \"string\") {\n selector = root;\n root = document;\n }\n return root.querySelector(selector);\n }\n function dispatchEvent(element, type, eventInit = {}) {\n const {disabled: disabled} = element;\n const {bubbles: bubbles, cancelable: cancelable, detail: detail} = eventInit;\n const event = document.createEvent(\"Event\");\n event.initEvent(type, bubbles || true, cancelable || true);\n event.detail = detail || {};\n try {\n element.disabled = false;\n element.dispatchEvent(event);\n } finally {\n element.disabled = disabled;\n }\n return event;\n }\n function toArray(value) {\n if (Array.isArray(value)) {\n return value;\n } else if (Array.from) {\n return Array.from(value);\n } else {\n return [].slice.call(value);\n }\n }\n class BlobRecord {\n constructor(file, checksum, url, customHeaders = {}) {\n this.file = file;\n this.attributes = {\n filename: file.name,\n content_type: file.type || \"application/octet-stream\",\n byte_size: file.size,\n checksum: checksum\n };\n this.xhr = new XMLHttpRequest;\n this.xhr.open(\"POST\", url, true);\n this.xhr.responseType = \"json\";\n this.xhr.setRequestHeader(\"Content-Type\", \"application/json\");\n this.xhr.setRequestHeader(\"Accept\", \"application/json\");\n this.xhr.setRequestHeader(\"X-Requested-With\", \"XMLHttpRequest\");\n Object.keys(customHeaders).forEach((headerKey => {\n this.xhr.setRequestHeader(headerKey, customHeaders[headerKey]);\n }));\n const csrfToken = getMetaValue(\"csrf-token\");\n if (csrfToken != undefined) {\n this.xhr.setRequestHeader(\"X-CSRF-Token\", csrfToken);\n }\n this.xhr.addEventListener(\"load\", (event => this.requestDidLoad(event)));\n this.xhr.addEventListener(\"error\", (event => this.requestDidError(event)));\n }\n get status() {\n return this.xhr.status;\n }\n get response() {\n const {responseType: responseType, response: response} = this.xhr;\n if (responseType == \"json\") {\n return response;\n } else {\n return JSON.parse(response);\n }\n }\n create(callback) {\n this.callback = callback;\n this.xhr.send(JSON.stringify({\n blob: this.attributes\n }));\n }\n requestDidLoad(event) {\n if (this.status >= 200 && this.status < 300) {\n const {response: response} = this;\n const {direct_upload: direct_upload} = response;\n delete response.direct_upload;\n this.attributes = response;\n this.directUploadData = direct_upload;\n this.callback(null, this.toJSON());\n } else {\n this.requestDidError(event);\n }\n }\n requestDidError(event) {\n this.callback(`Error creating Blob for \"${this.file.name}\". Status: ${this.status}`);\n }\n toJSON() {\n const result = {};\n for (const key in this.attributes) {\n result[key] = this.attributes[key];\n }\n return result;\n }\n }\n class BlobUpload {\n constructor(blob) {\n this.blob = blob;\n this.file = blob.file;\n const {url: url, headers: headers} = blob.directUploadData;\n this.xhr = new XMLHttpRequest;\n this.xhr.open(\"PUT\", url, true);\n this.xhr.responseType = \"text\";\n for (const key in headers) {\n this.xhr.setRequestHeader(key, headers[key]);\n }\n this.xhr.addEventListener(\"load\", (event => this.requestDidLoad(event)));\n this.xhr.addEventListener(\"error\", (event => this.requestDidError(event)));\n }\n create(callback) {\n this.callback = callback;\n this.xhr.send(this.file.slice());\n }\n requestDidLoad(event) {\n const {status: status, response: response} = this.xhr;\n if (status >= 200 && status < 300) {\n this.callback(null, response);\n } else {\n this.requestDidError(event);\n }\n }\n requestDidError(event) {\n this.callback(`Error storing \"${this.file.name}\". Status: ${this.xhr.status}`);\n }\n }\n let id = 0;\n class DirectUpload {\n constructor(file, url, delegate, customHeaders = {}) {\n this.id = ++id;\n this.file = file;\n this.url = url;\n this.delegate = delegate;\n this.customHeaders = customHeaders;\n }\n create(callback) {\n FileChecksum.create(this.file, ((error, checksum) => {\n if (error) {\n callback(error);\n return;\n }\n const blob = new BlobRecord(this.file, checksum, this.url, this.customHeaders);\n notify(this.delegate, \"directUploadWillCreateBlobWithXHR\", blob.xhr);\n blob.create((error => {\n if (error) {\n callback(error);\n } else {\n const upload = new BlobUpload(blob);\n notify(this.delegate, \"directUploadWillStoreFileWithXHR\", upload.xhr);\n upload.create((error => {\n if (error) {\n callback(error);\n } else {\n callback(null, blob.toJSON());\n }\n }));\n }\n }));\n }));\n }\n }\n function notify(object, methodName, ...messages) {\n if (object && typeof object[methodName] == \"function\") {\n return object[methodName](...messages);\n }\n }\n class DirectUploadController {\n constructor(input, file) {\n this.input = input;\n this.file = file;\n this.directUpload = new DirectUpload(this.file, this.url, this);\n this.dispatch(\"initialize\");\n }\n start(callback) {\n const hiddenInput = document.createElement(\"input\");\n hiddenInput.type = \"hidden\";\n hiddenInput.name = this.input.name;\n this.input.insertAdjacentElement(\"beforebegin\", hiddenInput);\n this.dispatch(\"start\");\n this.directUpload.create(((error, attributes) => {\n if (error) {\n hiddenInput.parentNode.removeChild(hiddenInput);\n this.dispatchError(error);\n } else {\n hiddenInput.value = attributes.signed_id;\n }\n this.dispatch(\"end\");\n callback(error);\n }));\n }\n uploadRequestDidProgress(event) {\n const progress = event.loaded / event.total * 100;\n if (progress) {\n this.dispatch(\"progress\", {\n progress: progress\n });\n }\n }\n get url() {\n return this.input.getAttribute(\"data-direct-upload-url\");\n }\n dispatch(name, detail = {}) {\n detail.file = this.file;\n detail.id = this.directUpload.id;\n return dispatchEvent(this.input, `direct-upload:${name}`, {\n detail: detail\n });\n }\n dispatchError(error) {\n const event = this.dispatch(\"error\", {\n error: error\n });\n if (!event.defaultPrevented) {\n alert(error);\n }\n }\n directUploadWillCreateBlobWithXHR(xhr) {\n this.dispatch(\"before-blob-request\", {\n xhr: xhr\n });\n }\n directUploadWillStoreFileWithXHR(xhr) {\n this.dispatch(\"before-storage-request\", {\n xhr: xhr\n });\n xhr.upload.addEventListener(\"progress\", (event => this.uploadRequestDidProgress(event)));\n }\n }\n const inputSelector = \"input[type=file][data-direct-upload-url]:not([disabled])\";\n class DirectUploadsController {\n constructor(form) {\n this.form = form;\n this.inputs = findElements(form, inputSelector).filter((input => input.files.length));\n }\n start(callback) {\n const controllers = this.createDirectUploadControllers();\n const startNextController = () => {\n const controller = controllers.shift();\n if (controller) {\n controller.start((error => {\n if (error) {\n callback(error);\n this.dispatch(\"end\");\n } else {\n startNextController();\n }\n }));\n } else {\n callback();\n this.dispatch(\"end\");\n }\n };\n this.dispatch(\"start\");\n startNextController();\n }\n createDirectUploadControllers() {\n const controllers = [];\n this.inputs.forEach((input => {\n toArray(input.files).forEach((file => {\n const controller = new DirectUploadController(input, file);\n controllers.push(controller);\n }));\n }));\n return controllers;\n }\n dispatch(name, detail = {}) {\n return dispatchEvent(this.form, `direct-uploads:${name}`, {\n detail: detail\n });\n }\n }\n const processingAttribute = \"data-direct-uploads-processing\";\n const submitButtonsByForm = new WeakMap;\n let started = false;\n function start() {\n if (!started) {\n started = true;\n document.addEventListener(\"click\", didClick, true);\n document.addEventListener(\"submit\", didSubmitForm, true);\n document.addEventListener(\"ajax:before\", didSubmitRemoteElement);\n }\n }\n function didClick(event) {\n const button = event.target.closest(\"button, input\");\n if (button && button.type === \"submit\" && button.form) {\n submitButtonsByForm.set(button.form, button);\n }\n }\n function didSubmitForm(event) {\n handleFormSubmissionEvent(event);\n }\n function didSubmitRemoteElement(event) {\n if (event.target.tagName == \"FORM\") {\n handleFormSubmissionEvent(event);\n }\n }\n function handleFormSubmissionEvent(event) {\n const form = event.target;\n if (form.hasAttribute(processingAttribute)) {\n event.preventDefault();\n return;\n }\n const controller = new DirectUploadsController(form);\n const {inputs: inputs} = controller;\n if (inputs.length) {\n event.preventDefault();\n form.setAttribute(processingAttribute, \"\");\n inputs.forEach(disable);\n controller.start((error => {\n form.removeAttribute(processingAttribute);\n if (error) {\n inputs.forEach(enable);\n } else {\n submitForm(form);\n }\n }));\n }\n }\n function submitForm(form) {\n let button = submitButtonsByForm.get(form) || findElement(form, \"input[type=submit], button[type=submit]\");\n if (button) {\n const {disabled: disabled} = button;\n button.disabled = false;\n button.focus();\n button.click();\n button.disabled = disabled;\n } else {\n button = document.createElement(\"input\");\n button.type = \"submit\";\n button.style.display = \"none\";\n form.appendChild(button);\n button.click();\n form.removeChild(button);\n }\n submitButtonsByForm.delete(form);\n }\n function disable(input) {\n input.disabled = true;\n }\n function enable(input) {\n input.disabled = false;\n }\n function autostart() {\n if (window.ActiveStorage) {\n start();\n }\n }\n setTimeout(autostart, 1);\n exports.DirectUpload = DirectUpload;\n exports.DirectUploadController = DirectUploadController;\n exports.DirectUploadsController = DirectUploadsController;\n exports.dispatchEvent = dispatchEvent;\n exports.start = start;\n Object.defineProperty(exports, \"__esModule\", {\n value: true\n });\n}));\n/* eslint-enable */\n", "export default {\n logger: typeof console !== \"undefined\" ? console : undefined,\n WebSocket: typeof WebSocket !== \"undefined\" ? WebSocket : undefined,\n}\n", "import adapters from \"./adapters\"\n\n// The logger is disabled by default. You can enable it with:\n//\n// ActionCable.logger.enabled = true\n//\n// Example:\n//\n// import * as ActionCable from '@rails/actioncable'\n//\n// ActionCable.logger.enabled = true\n// ActionCable.logger.log('Connection Established.')\n//\n\nexport default {\n log(...messages) {\n if (this.enabled) {\n messages.push(Date.now())\n adapters.logger.log(\"[ActionCable]\", ...messages)\n }\n },\n}\n", "import logger from \"./logger\"\n\n// Responsible for ensuring the cable connection is in good health by validating the heartbeat pings sent from the server, and attempting\n// revival reconnections if things go astray. Internal class, not intended for direct user manipulation.\n\nconst now = () => new Date().getTime()\n\nconst secondsSince = time => (now() - time) / 1000\n\nclass ConnectionMonitor {\n constructor(connection) {\n this.visibilityDidChange = this.visibilityDidChange.bind(this)\n this.connection = connection\n this.reconnectAttempts = 0\n }\n\n start() {\n if (!this.isRunning()) {\n this.startedAt = now()\n delete this.stoppedAt\n this.startPolling()\n addEventListener(\"visibilitychange\", this.visibilityDidChange)\n logger.log(`ConnectionMonitor started. stale threshold = ${this.constructor.staleThreshold} s`)\n }\n }\n\n stop() {\n if (this.isRunning()) {\n this.stoppedAt = now()\n this.stopPolling()\n removeEventListener(\"visibilitychange\", this.visibilityDidChange)\n logger.log(\"ConnectionMonitor stopped\")\n }\n }\n\n isRunning() {\n return this.startedAt && !this.stoppedAt\n }\n\n recordMessage() {\n this.pingedAt = now()\n }\n\n recordConnect() {\n this.reconnectAttempts = 0\n delete this.disconnectedAt\n logger.log(\"ConnectionMonitor recorded connect\")\n }\n\n recordDisconnect() {\n this.disconnectedAt = now()\n logger.log(\"ConnectionMonitor recorded disconnect\")\n }\n\n // Private\n\n startPolling() {\n this.stopPolling()\n this.poll()\n }\n\n stopPolling() {\n clearTimeout(this.pollTimeout)\n }\n\n poll() {\n this.pollTimeout = setTimeout(() => {\n this.reconnectIfStale()\n this.poll()\n }\n , this.getPollInterval())\n }\n\n getPollInterval() {\n const { staleThreshold, reconnectionBackoffRate } = this.constructor\n const backoff = Math.pow(1 + reconnectionBackoffRate, Math.min(this.reconnectAttempts, 10))\n const jitterMax = this.reconnectAttempts === 0 ? 1.0 : reconnectionBackoffRate\n const jitter = jitterMax * Math.random()\n return staleThreshold * 1000 * backoff * (1 + jitter)\n }\n\n reconnectIfStale() {\n if (this.connectionIsStale()) {\n logger.log(`ConnectionMonitor detected stale connection. reconnectAttempts = ${this.reconnectAttempts}, time stale = ${secondsSince(this.refreshedAt)} s, stale threshold = ${this.constructor.staleThreshold} s`)\n this.reconnectAttempts++\n if (this.disconnectedRecently()) {\n logger.log(`ConnectionMonitor skipping reopening recent disconnect. time disconnected = ${secondsSince(this.disconnectedAt)} s`)\n } else {\n logger.log(\"ConnectionMonitor reopening\")\n this.connection.reopen()\n }\n }\n }\n\n get refreshedAt() {\n return this.pingedAt ? this.pingedAt : this.startedAt\n }\n\n connectionIsStale() {\n return secondsSince(this.refreshedAt) > this.constructor.staleThreshold\n }\n\n disconnectedRecently() {\n return this.disconnectedAt && (secondsSince(this.disconnectedAt) < this.constructor.staleThreshold)\n }\n\n visibilityDidChange() {\n if (document.visibilityState === \"visible\") {\n setTimeout(() => {\n if (this.connectionIsStale() || !this.connection.isOpen()) {\n logger.log(`ConnectionMonitor reopening stale connection on visibilitychange. visibilityState = ${document.visibilityState}`)\n this.connection.reopen()\n }\n }\n , 200)\n }\n }\n\n}\n\nConnectionMonitor.staleThreshold = 6 // Server::Connections::BEAT_INTERVAL * 2 (missed two pings)\nConnectionMonitor.reconnectionBackoffRate = 0.15\n\nexport default ConnectionMonitor\n", "export default {\n \"message_types\": {\n \"welcome\": \"welcome\",\n \"disconnect\": \"disconnect\",\n \"ping\": \"ping\",\n \"confirmation\": \"confirm_subscription\",\n \"rejection\": \"reject_subscription\"\n },\n \"disconnect_reasons\": {\n \"unauthorized\": \"unauthorized\",\n \"invalid_request\": \"invalid_request\",\n \"server_restart\": \"server_restart\",\n \"remote\": \"remote\"\n },\n \"default_mount_path\": \"/cable\",\n \"protocols\": [\n \"actioncable-v1-json\",\n \"actioncable-unsupported\"\n ]\n}\n", "import adapters from \"./adapters\"\nimport ConnectionMonitor from \"./connection_monitor\"\nimport INTERNAL from \"./internal\"\nimport logger from \"./logger\"\n\n// Encapsulate the cable connection held by the consumer. This is an internal class not intended for direct user manipulation.\n\nconst {message_types, protocols} = INTERNAL\nconst supportedProtocols = protocols.slice(0, protocols.length - 1)\n\nconst indexOf = [].indexOf\n\nclass Connection {\n constructor(consumer) {\n this.open = this.open.bind(this)\n this.consumer = consumer\n this.subscriptions = this.consumer.subscriptions\n this.monitor = new ConnectionMonitor(this)\n this.disconnected = true\n }\n\n send(data) {\n if (this.isOpen()) {\n this.webSocket.send(JSON.stringify(data))\n return true\n } else {\n return false\n }\n }\n\n open() {\n if (this.isActive()) {\n logger.log(`Attempted to open WebSocket, but existing socket is ${this.getState()}`)\n return false\n } else {\n const socketProtocols = [...protocols, ...this.consumer.subprotocols || []]\n logger.log(`Opening WebSocket, current state is ${this.getState()}, subprotocols: ${socketProtocols}`)\n if (this.webSocket) { this.uninstallEventHandlers() }\n this.webSocket = new adapters.WebSocket(this.consumer.url, socketProtocols)\n this.installEventHandlers()\n this.monitor.start()\n return true\n }\n }\n\n close({allowReconnect} = {allowReconnect: true}) {\n if (!allowReconnect) { this.monitor.stop() }\n // Avoid closing websockets in a \"connecting\" state due to Safari 15.1+ bug. See: https://github.com/rails/rails/issues/43835#issuecomment-1002288478\n if (this.isOpen()) {\n return this.webSocket.close()\n }\n }\n\n reopen() {\n logger.log(`Reopening WebSocket, current state is ${this.getState()}`)\n if (this.isActive()) {\n try {\n return this.close()\n } catch (error) {\n logger.log(\"Failed to reopen WebSocket\", error)\n }\n finally {\n logger.log(`Reopening WebSocket in ${this.constructor.reopenDelay}ms`)\n setTimeout(this.open, this.constructor.reopenDelay)\n }\n } else {\n return this.open()\n }\n }\n\n getProtocol() {\n if (this.webSocket) {\n return this.webSocket.protocol\n }\n }\n\n isOpen() {\n return this.isState(\"open\")\n }\n\n isActive() {\n return this.isState(\"open\", \"connecting\")\n }\n\n triedToReconnect() {\n return this.monitor.reconnectAttempts > 0\n }\n\n // Private\n\n isProtocolSupported() {\n return indexOf.call(supportedProtocols, this.getProtocol()) >= 0\n }\n\n isState(...states) {\n return indexOf.call(states, this.getState()) >= 0\n }\n\n getState() {\n if (this.webSocket) {\n for (let state in adapters.WebSocket) {\n if (adapters.WebSocket[state] === this.webSocket.readyState) {\n return state.toLowerCase()\n }\n }\n }\n return null\n }\n\n installEventHandlers() {\n for (let eventName in this.events) {\n const handler = this.events[eventName].bind(this)\n this.webSocket[`on${eventName}`] = handler\n }\n }\n\n uninstallEventHandlers() {\n for (let eventName in this.events) {\n this.webSocket[`on${eventName}`] = function() {}\n }\n }\n\n}\n\nConnection.reopenDelay = 500\n\nConnection.prototype.events = {\n message(event) {\n if (!this.isProtocolSupported()) { return }\n const {identifier, message, reason, reconnect, type} = JSON.parse(event.data)\n this.monitor.recordMessage()\n switch (type) {\n case message_types.welcome:\n if (this.triedToReconnect()) {\n this.reconnectAttempted = true\n }\n this.monitor.recordConnect()\n return this.subscriptions.reload()\n case message_types.disconnect:\n logger.log(`Disconnecting. Reason: ${reason}`)\n return this.close({allowReconnect: reconnect})\n case message_types.ping:\n return null\n case message_types.confirmation:\n this.subscriptions.confirmSubscription(identifier)\n if (this.reconnectAttempted) {\n this.reconnectAttempted = false\n return this.subscriptions.notify(identifier, \"connected\", {reconnected: true})\n } else {\n return this.subscriptions.notify(identifier, \"connected\", {reconnected: false})\n }\n case message_types.rejection:\n return this.subscriptions.reject(identifier)\n default:\n return this.subscriptions.notify(identifier, \"received\", message)\n }\n },\n\n open() {\n logger.log(`WebSocket onopen event, using '${this.getProtocol()}' subprotocol`)\n this.disconnected = false\n if (!this.isProtocolSupported()) {\n logger.log(\"Protocol is unsupported. Stopping monitor and disconnecting.\")\n return this.close({allowReconnect: false})\n }\n },\n\n close(event) {\n logger.log(\"WebSocket onclose event\")\n if (this.disconnected) { return }\n this.disconnected = true\n this.monitor.recordDisconnect()\n return this.subscriptions.notifyAll(\"disconnected\", {willAttemptReconnect: this.monitor.isRunning()})\n },\n\n error() {\n logger.log(\"WebSocket onerror event\")\n }\n}\n\nexport default Connection\n", "// A new subscription is created through the ActionCable.Subscriptions instance available on the consumer.\n// It provides a number of callbacks and a method for calling remote procedure calls on the corresponding\n// Channel instance on the server side.\n//\n// An example demonstrates the basic functionality:\n//\n// App.appearance = App.cable.subscriptions.create(\"AppearanceChannel\", {\n// connected() {\n// // Called once the subscription has been successfully completed\n// },\n//\n// disconnected({ willAttemptReconnect: boolean }) {\n// // Called when the client has disconnected with the server.\n// // The object will have an `willAttemptReconnect` property which\n// // says whether the client has the intention of attempting\n// // to reconnect.\n// },\n//\n// appear() {\n// this.perform('appear', {appearing_on: this.appearingOn()})\n// },\n//\n// away() {\n// this.perform('away')\n// },\n//\n// appearingOn() {\n// $('main').data('appearing-on')\n// }\n// })\n//\n// The methods #appear and #away forward their intent to the remote AppearanceChannel instance on the server\n// by calling the `perform` method with the first parameter being the action (which maps to AppearanceChannel#appear/away).\n// The second parameter is a hash that'll get JSON encoded and made available on the server in the data parameter.\n//\n// This is how the server component would look:\n//\n// class AppearanceChannel < ApplicationActionCable::Channel\n// def subscribed\n// current_user.appear\n// end\n//\n// def unsubscribed\n// current_user.disappear\n// end\n//\n// def appear(data)\n// current_user.appear on: data['appearing_on']\n// end\n//\n// def away\n// current_user.away\n// end\n// end\n//\n// The \"AppearanceChannel\" name is automatically mapped between the client-side subscription creation and the server-side Ruby class name.\n// The AppearanceChannel#appear/away public methods are exposed automatically to client-side invocation through the perform method.\n\nconst extend = function(object, properties) {\n if (properties != null) {\n for (let key in properties) {\n const value = properties[key]\n object[key] = value\n }\n }\n return object\n}\n\nexport default class Subscription {\n constructor(consumer, params = {}, mixin) {\n this.consumer = consumer\n this.identifier = JSON.stringify(params)\n extend(this, mixin)\n }\n\n // Perform a channel action with the optional data passed as an attribute\n perform(action, data = {}) {\n data.action = action\n return this.send(data)\n }\n\n send(data) {\n return this.consumer.send({command: \"message\", identifier: this.identifier, data: JSON.stringify(data)})\n }\n\n unsubscribe() {\n return this.consumer.subscriptions.remove(this)\n }\n}\n", "import logger from \"./logger\"\n\n// Responsible for ensuring channel subscribe command is confirmed, retrying until confirmation is received.\n// Internal class, not intended for direct user manipulation.\n\nclass SubscriptionGuarantor {\n constructor(subscriptions) {\n this.subscriptions = subscriptions\n this.pendingSubscriptions = []\n }\n\n guarantee(subscription) {\n if(this.pendingSubscriptions.indexOf(subscription) == -1){ \n logger.log(`SubscriptionGuarantor guaranteeing ${subscription.identifier}`)\n this.pendingSubscriptions.push(subscription) \n }\n else {\n logger.log(`SubscriptionGuarantor already guaranteeing ${subscription.identifier}`)\n }\n this.startGuaranteeing()\n }\n\n forget(subscription) {\n logger.log(`SubscriptionGuarantor forgetting ${subscription.identifier}`)\n this.pendingSubscriptions = (this.pendingSubscriptions.filter((s) => s !== subscription))\n }\n\n startGuaranteeing() {\n this.stopGuaranteeing()\n this.retrySubscribing()\n }\n \n stopGuaranteeing() {\n clearTimeout(this.retryTimeout)\n }\n\n retrySubscribing() {\n this.retryTimeout = setTimeout(() => {\n if (this.subscriptions && typeof(this.subscriptions.subscribe) === \"function\") {\n this.pendingSubscriptions.map((subscription) => {\n logger.log(`SubscriptionGuarantor resubscribing ${subscription.identifier}`)\n this.subscriptions.subscribe(subscription)\n })\n }\n }\n , 500)\n }\n}\n\nexport default SubscriptionGuarantor", "import Subscription from \"./subscription\"\nimport SubscriptionGuarantor from \"./subscription_guarantor\"\nimport logger from \"./logger\"\n\n// Collection class for creating (and internally managing) channel subscriptions.\n// The only method intended to be triggered by the user is ActionCable.Subscriptions#create,\n// and it should be called through the consumer like so:\n//\n// App = {}\n// App.cable = ActionCable.createConsumer(\"ws://example.com/accounts/1\")\n// App.appearance = App.cable.subscriptions.create(\"AppearanceChannel\")\n//\n// For more details on how you'd configure an actual channel subscription, see ActionCable.Subscription.\n\nexport default class Subscriptions {\n constructor(consumer) {\n this.consumer = consumer\n this.guarantor = new SubscriptionGuarantor(this)\n this.subscriptions = []\n }\n\n create(channelName, mixin) {\n const channel = channelName\n const params = typeof channel === \"object\" ? channel : {channel}\n const subscription = new Subscription(this.consumer, params, mixin)\n return this.add(subscription)\n }\n\n // Private\n\n add(subscription) {\n this.subscriptions.push(subscription)\n this.consumer.ensureActiveConnection()\n this.notify(subscription, \"initialized\")\n this.subscribe(subscription)\n return subscription\n }\n\n remove(subscription) {\n this.forget(subscription)\n if (!this.findAll(subscription.identifier).length) {\n this.sendCommand(subscription, \"unsubscribe\")\n }\n return subscription\n }\n\n reject(identifier) {\n return this.findAll(identifier).map((subscription) => {\n this.forget(subscription)\n this.notify(subscription, \"rejected\")\n return subscription\n })\n }\n\n forget(subscription) {\n this.guarantor.forget(subscription)\n this.subscriptions = (this.subscriptions.filter((s) => s !== subscription))\n return subscription\n }\n\n findAll(identifier) {\n return this.subscriptions.filter((s) => s.identifier === identifier)\n }\n\n reload() {\n return this.subscriptions.map((subscription) =>\n this.subscribe(subscription))\n }\n\n notifyAll(callbackName, ...args) {\n return this.subscriptions.map((subscription) =>\n this.notify(subscription, callbackName, ...args))\n }\n\n notify(subscription, callbackName, ...args) {\n let subscriptions\n if (typeof subscription === \"string\") {\n subscriptions = this.findAll(subscription)\n } else {\n subscriptions = [subscription]\n }\n\n return subscriptions.map((subscription) =>\n (typeof subscription[callbackName] === \"function\" ? subscription[callbackName](...args) : undefined))\n }\n\n subscribe(subscription) {\n if (this.sendCommand(subscription, \"subscribe\")) {\n this.guarantor.guarantee(subscription)\n }\n }\n\n confirmSubscription(identifier) {\n logger.log(`Subscription confirmed ${identifier}`)\n this.findAll(identifier).map((subscription) =>\n this.guarantor.forget(subscription))\n }\n\n sendCommand(subscription, command) {\n const {identifier} = subscription\n return this.consumer.send({command, identifier})\n }\n}\n", "import Connection from \"./connection\"\nimport Subscriptions from \"./subscriptions\"\n\n// The ActionCable.Consumer establishes the connection to a server-side Ruby Connection object. Once established,\n// the ActionCable.ConnectionMonitor will ensure that its properly maintained through heartbeats and checking for stale updates.\n// The Consumer instance is also the gateway to establishing subscriptions to desired channels through the #createSubscription\n// method.\n//\n// The following example shows how this can be set up:\n//\n// App = {}\n// App.cable = ActionCable.createConsumer(\"ws://example.com/accounts/1\")\n// App.appearance = App.cable.subscriptions.create(\"AppearanceChannel\")\n//\n// For more details on how you'd configure an actual channel subscription, see ActionCable.Subscription.\n//\n// When a consumer is created, it automatically connects with the server.\n//\n// To disconnect from the server, call\n//\n// App.cable.disconnect()\n//\n// and to restart the connection:\n//\n// App.cable.connect()\n//\n// Any channel subscriptions which existed prior to disconnecting will\n// automatically resubscribe.\n\nexport default class Consumer {\n constructor(url) {\n this._url = url\n this.subscriptions = new Subscriptions(this)\n this.connection = new Connection(this)\n this.subprotocols = []\n }\n\n get url() {\n return createWebSocketURL(this._url)\n }\n\n send(data) {\n return this.connection.send(data)\n }\n\n connect() {\n return this.connection.open()\n }\n\n disconnect() {\n return this.connection.close({allowReconnect: false})\n }\n\n ensureActiveConnection() {\n if (!this.connection.isActive()) {\n return this.connection.open()\n }\n }\n\n addSubProtocol(subprotocol) {\n this.subprotocols = [...this.subprotocols, subprotocol]\n }\n}\n\nexport function createWebSocketURL(url) {\n if (typeof url === \"function\") {\n url = url()\n }\n\n if (url && !/^wss?:/i.test(url)) {\n const a = document.createElement(\"a\")\n a.href = url\n // Fix populating Location properties in IE. Otherwise, protocol will be blank.\n a.href = a.href\n a.protocol = a.protocol.replace(\"http\", \"ws\")\n return a.href\n } else {\n return url\n }\n}\n", "import Connection from \"./connection\"\nimport ConnectionMonitor from \"./connection_monitor\"\nimport Consumer, { createWebSocketURL } from \"./consumer\"\nimport INTERNAL from \"./internal\"\nimport Subscription from \"./subscription\"\nimport Subscriptions from \"./subscriptions\"\nimport SubscriptionGuarantor from \"./subscription_guarantor\"\nimport adapters from \"./adapters\"\nimport logger from \"./logger\"\n\nexport {\n Connection,\n ConnectionMonitor,\n Consumer,\n INTERNAL,\n Subscription,\n Subscriptions,\n SubscriptionGuarantor,\n adapters,\n createWebSocketURL,\n logger,\n}\n\nexport function createConsumer(url = getConfig(\"url\") || INTERNAL.default_mount_path) {\n return new Consumer(url)\n}\n\nexport function getConfig(name) {\n const element = document.head.querySelector(`meta[name='action-cable-${name}']`)\n if (element) {\n return element.getAttribute(\"content\")\n }\n}\n", "/*\n * JavaScript Load Image\n * https://github.com/blueimp/JavaScript-Load-Image\n *\n * Copyright 2011, Sebastian Tschan\n * https://blueimp.net\n *\n * Licensed under the MIT license:\n * https://opensource.org/licenses/MIT\n */\n\n/* global define, module, Promise */\n\n;(function ($) {\n 'use strict'\n\n var urlAPI = $.URL || $.webkitURL\n\n /**\n * Creates an object URL for a given File object.\n *\n * @param {Blob} blob Blob object\n * @returns {string|boolean} Returns object URL if API exists, else false.\n */\n function createObjectURL(blob) {\n return urlAPI ? urlAPI.createObjectURL(blob) : false\n }\n\n /**\n * Revokes a given object URL.\n *\n * @param {string} url Blob object URL\n * @returns {undefined|boolean} Returns undefined if API exists, else false.\n */\n function revokeObjectURL(url) {\n return urlAPI ? urlAPI.revokeObjectURL(url) : false\n }\n\n /**\n * Helper function to revoke an object URL\n *\n * @param {string} url Blob Object URL\n * @param {object} [options] Options object\n */\n function revokeHelper(url, options) {\n if (url && url.slice(0, 5) === 'blob:' && !(options && options.noRevoke)) {\n revokeObjectURL(url)\n }\n }\n\n /**\n * Loads a given File object via FileReader interface.\n *\n * @param {Blob} file Blob object\n * @param {Function} onload Load event callback\n * @param {Function} [onerror] Error/Abort event callback\n * @param {string} [method=readAsDataURL] FileReader method\n * @returns {FileReader|boolean} Returns FileReader if API exists, else false.\n */\n function readFile(file, onload, onerror, method) {\n if (!$.FileReader) return false\n var reader = new FileReader()\n reader.onload = function () {\n onload.call(reader, this.result)\n }\n if (onerror) {\n reader.onabort = reader.onerror = function () {\n onerror.call(reader, this.error)\n }\n }\n var readerMethod = reader[method || 'readAsDataURL']\n if (readerMethod) {\n readerMethod.call(reader, file)\n return reader\n }\n }\n\n /**\n * Cross-frame instanceof check.\n *\n * @param {string} type Instance type\n * @param {object} obj Object instance\n * @returns {boolean} Returns true if the object is of the given instance.\n */\n function isInstanceOf(type, obj) {\n // Cross-frame instanceof check\n return Object.prototype.toString.call(obj) === '[object ' + type + ']'\n }\n\n /**\n * @typedef { HTMLImageElement|HTMLCanvasElement } Result\n */\n\n /**\n * Loads an image for a given File object.\n *\n * @param {Blob|string} file Blob object or image URL\n * @param {Function|object} [callback] Image load event callback or options\n * @param {object} [options] Options object\n * @returns {HTMLImageElement|FileReader|Promise} Object\n */\n function loadImage(file, callback, options) {\n /**\n * Promise executor\n *\n * @param {Function} resolve Resolution function\n * @param {Function} reject Rejection function\n * @returns {HTMLImageElement|FileReader} Object\n */\n function executor(resolve, reject) {\n var img = document.createElement('img')\n var url\n /**\n * Callback for the fetchBlob call.\n *\n * @param {HTMLImageElement|HTMLCanvasElement} img Error object\n * @param {object} data Data object\n * @returns {undefined} Undefined\n */\n function resolveWrapper(img, data) {\n if (resolve === reject) {\n // Not using Promises\n if (resolve) resolve(img, data)\n return\n } else if (img instanceof Error) {\n reject(img)\n return\n }\n data = data || {} // eslint-disable-line no-param-reassign\n data.image = img\n resolve(data)\n }\n /**\n * Callback for the fetchBlob call.\n *\n * @param {Blob} blob Blob object\n * @param {Error} err Error object\n */\n function fetchBlobCallback(blob, err) {\n if (err && $.console) console.log(err) // eslint-disable-line no-console\n if (blob && isInstanceOf('Blob', blob)) {\n file = blob // eslint-disable-line no-param-reassign\n url = createObjectURL(file)\n } else {\n url = file\n if (options && options.crossOrigin) {\n img.crossOrigin = options.crossOrigin\n }\n }\n img.src = url\n }\n img.onerror = function (event) {\n revokeHelper(url, options)\n if (reject) reject.call(img, event)\n }\n img.onload = function () {\n revokeHelper(url, options)\n var data = {\n originalWidth: img.naturalWidth || img.width,\n originalHeight: img.naturalHeight || img.height\n }\n try {\n loadImage.transform(img, options, resolveWrapper, file, data)\n } catch (error) {\n if (reject) reject(error)\n }\n }\n if (typeof file === 'string') {\n if (loadImage.requiresMetaData(options)) {\n loadImage.fetchBlob(file, fetchBlobCallback, options)\n } else {\n fetchBlobCallback()\n }\n return img\n } else if (isInstanceOf('Blob', file) || isInstanceOf('File', file)) {\n url = createObjectURL(file)\n if (url) {\n img.src = url\n return img\n }\n return readFile(\n file,\n function (url) {\n img.src = url\n },\n reject\n )\n }\n }\n if ($.Promise && typeof callback !== 'function') {\n options = callback // eslint-disable-line no-param-reassign\n return new Promise(executor)\n }\n return executor(callback, callback)\n }\n\n // Determines if metadata should be loaded automatically.\n // Requires the load image meta extension to load metadata.\n loadImage.requiresMetaData = function (options) {\n return options && options.meta\n }\n\n // If the callback given to this function returns a blob, it is used as image\n // source instead of the original url and overrides the file argument used in\n // the onload and onerror event callbacks:\n loadImage.fetchBlob = function (url, callback) {\n callback()\n }\n\n loadImage.transform = function (img, options, callback, file, data) {\n callback(img, data)\n }\n\n loadImage.global = $\n loadImage.readFile = readFile\n loadImage.isInstanceOf = isInstanceOf\n loadImage.createObjectURL = createObjectURL\n loadImage.revokeObjectURL = revokeObjectURL\n\n if (typeof define === 'function' && define.amd) {\n define(function () {\n return loadImage\n })\n } else if (typeof module === 'object' && module.exports) {\n module.exports = loadImage\n } else {\n $.loadImage = loadImage\n }\n})((typeof window !== 'undefined' && window) || this)\n", "/*!\n * Cropper.js v1.6.2\n * https://fengyuanchen.github.io/cropperjs\n *\n * Copyright 2015-present Chen Fengyuan\n * Released under the MIT license\n *\n * Date: 2024-04-21T07:43:05.335Z\n */\n\n(function (global, factory) {\n typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :\n typeof define === 'function' && define.amd ? define(factory) :\n (global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.Cropper = factory());\n})(this, (function () { 'use strict';\n\n function ownKeys(e, r) {\n var t = Object.keys(e);\n if (Object.getOwnPropertySymbols) {\n var o = Object.getOwnPropertySymbols(e);\n r && (o = o.filter(function (r) {\n return Object.getOwnPropertyDescriptor(e, r).enumerable;\n })), t.push.apply(t, o);\n }\n return t;\n }\n function _objectSpread2(e) {\n for (var r = 1; r < arguments.length; r++) {\n var t = null != arguments[r] ? arguments[r] : {};\n r % 2 ? ownKeys(Object(t), !0).forEach(function (r) {\n _defineProperty(e, r, t[r]);\n }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) {\n Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r));\n });\n }\n return e;\n }\n function _toPrimitive(t, r) {\n if (\"object\" != typeof t || !t) return t;\n var e = t[Symbol.toPrimitive];\n if (void 0 !== e) {\n var i = e.call(t, r || \"default\");\n if (\"object\" != typeof i) return i;\n throw new TypeError(\"@@toPrimitive must return a primitive value.\");\n }\n return (\"string\" === r ? String : Number)(t);\n }\n function _toPropertyKey(t) {\n var i = _toPrimitive(t, \"string\");\n return \"symbol\" == typeof i ? i : i + \"\";\n }\n function _typeof(o) {\n \"@babel/helpers - typeof\";\n\n return _typeof = \"function\" == typeof Symbol && \"symbol\" == typeof Symbol.iterator ? function (o) {\n return typeof o;\n } : function (o) {\n return o && \"function\" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? \"symbol\" : typeof o;\n }, _typeof(o);\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 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, _toPropertyKey(descriptor.key), descriptor);\n }\n }\n function _createClass(Constructor, protoProps, staticProps) {\n if (protoProps) _defineProperties(Constructor.prototype, protoProps);\n if (staticProps) _defineProperties(Constructor, staticProps);\n Object.defineProperty(Constructor, \"prototype\", {\n writable: false\n });\n return Constructor;\n }\n function _defineProperty(obj, key, value) {\n key = _toPropertyKey(key);\n if (key in obj) {\n Object.defineProperty(obj, key, {\n value: value,\n enumerable: true,\n configurable: true,\n writable: true\n });\n } else {\n obj[key] = value;\n }\n return obj;\n }\n function _toConsumableArray(arr) {\n return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread();\n }\n function _arrayWithoutHoles(arr) {\n if (Array.isArray(arr)) return _arrayLikeToArray(arr);\n }\n function _iterableToArray(iter) {\n if (typeof Symbol !== \"undefined\" && iter[Symbol.iterator] != null || iter[\"@@iterator\"] != null) return Array.from(iter);\n }\n function _unsupportedIterableToArray(o, minLen) {\n if (!o) return;\n if (typeof o === \"string\") return _arrayLikeToArray(o, minLen);\n var n = Object.prototype.toString.call(o).slice(8, -1);\n if (n === \"Object\" && o.constructor) n = o.constructor.name;\n if (n === \"Map\" || n === \"Set\") return Array.from(o);\n if (n === \"Arguments\" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);\n }\n function _arrayLikeToArray(arr, len) {\n if (len == null || len > arr.length) len = arr.length;\n for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];\n return arr2;\n }\n function _nonIterableSpread() {\n throw new TypeError(\"Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.\");\n }\n\n var IS_BROWSER = typeof window !== 'undefined' && typeof window.document !== 'undefined';\n var WINDOW = IS_BROWSER ? window : {};\n var IS_TOUCH_DEVICE = IS_BROWSER && WINDOW.document.documentElement ? 'ontouchstart' in WINDOW.document.documentElement : false;\n var HAS_POINTER_EVENT = IS_BROWSER ? 'PointerEvent' in WINDOW : false;\n var NAMESPACE = 'cropper';\n\n // Actions\n var ACTION_ALL = 'all';\n var ACTION_CROP = 'crop';\n var ACTION_MOVE = 'move';\n var ACTION_ZOOM = 'zoom';\n var ACTION_EAST = 'e';\n var ACTION_WEST = 'w';\n var ACTION_SOUTH = 's';\n var ACTION_NORTH = 'n';\n var ACTION_NORTH_EAST = 'ne';\n var ACTION_NORTH_WEST = 'nw';\n var ACTION_SOUTH_EAST = 'se';\n var ACTION_SOUTH_WEST = 'sw';\n\n // Classes\n var CLASS_CROP = \"\".concat(NAMESPACE, \"-crop\");\n var CLASS_DISABLED = \"\".concat(NAMESPACE, \"-disabled\");\n var CLASS_HIDDEN = \"\".concat(NAMESPACE, \"-hidden\");\n var CLASS_HIDE = \"\".concat(NAMESPACE, \"-hide\");\n var CLASS_INVISIBLE = \"\".concat(NAMESPACE, \"-invisible\");\n var CLASS_MODAL = \"\".concat(NAMESPACE, \"-modal\");\n var CLASS_MOVE = \"\".concat(NAMESPACE, \"-move\");\n\n // Data keys\n var DATA_ACTION = \"\".concat(NAMESPACE, \"Action\");\n var DATA_PREVIEW = \"\".concat(NAMESPACE, \"Preview\");\n\n // Drag modes\n var DRAG_MODE_CROP = 'crop';\n var DRAG_MODE_MOVE = 'move';\n var DRAG_MODE_NONE = 'none';\n\n // Events\n var EVENT_CROP = 'crop';\n var EVENT_CROP_END = 'cropend';\n var EVENT_CROP_MOVE = 'cropmove';\n var EVENT_CROP_START = 'cropstart';\n var EVENT_DBLCLICK = 'dblclick';\n var EVENT_TOUCH_START = IS_TOUCH_DEVICE ? 'touchstart' : 'mousedown';\n var EVENT_TOUCH_MOVE = IS_TOUCH_DEVICE ? 'touchmove' : 'mousemove';\n var EVENT_TOUCH_END = IS_TOUCH_DEVICE ? 'touchend touchcancel' : 'mouseup';\n var EVENT_POINTER_DOWN = HAS_POINTER_EVENT ? 'pointerdown' : EVENT_TOUCH_START;\n var EVENT_POINTER_MOVE = HAS_POINTER_EVENT ? 'pointermove' : EVENT_TOUCH_MOVE;\n var EVENT_POINTER_UP = HAS_POINTER_EVENT ? 'pointerup pointercancel' : EVENT_TOUCH_END;\n var EVENT_READY = 'ready';\n var EVENT_RESIZE = 'resize';\n var EVENT_WHEEL = 'wheel';\n var EVENT_ZOOM = 'zoom';\n\n // Mime types\n var MIME_TYPE_JPEG = 'image/jpeg';\n\n // RegExps\n var REGEXP_ACTIONS = /^e|w|s|n|se|sw|ne|nw|all|crop|move|zoom$/;\n var REGEXP_DATA_URL = /^data:/;\n var REGEXP_DATA_URL_JPEG = /^data:image\\/jpeg;base64,/;\n var REGEXP_TAG_NAME = /^img|canvas$/i;\n\n // Misc\n // Inspired by the default width and height of a canvas element.\n var MIN_CONTAINER_WIDTH = 200;\n var MIN_CONTAINER_HEIGHT = 100;\n\n var DEFAULTS = {\n // Define the view mode of the cropper\n viewMode: 0,\n // 0, 1, 2, 3\n\n // Define the dragging mode of the cropper\n dragMode: DRAG_MODE_CROP,\n // 'crop', 'move' or 'none'\n\n // Define the initial aspect ratio of the crop box\n initialAspectRatio: NaN,\n // Define the aspect ratio of the crop box\n aspectRatio: NaN,\n // An object with the previous cropping result data\n data: null,\n // A selector for adding extra containers to preview\n preview: '',\n // Re-render the cropper when resize the window\n responsive: true,\n // Restore the cropped area after resize the window\n restore: true,\n // Check if the current image is a cross-origin image\n checkCrossOrigin: true,\n // Check the current image's Exif Orientation information\n checkOrientation: true,\n // Show the black modal\n modal: true,\n // Show the dashed lines for guiding\n guides: true,\n // Show the center indicator for guiding\n center: true,\n // Show the white modal to highlight the crop box\n highlight: true,\n // Show the grid background\n background: true,\n // Enable to crop the image automatically when initialize\n autoCrop: true,\n // Define the percentage of automatic cropping area when initializes\n autoCropArea: 0.8,\n // Enable to move the image\n movable: true,\n // Enable to rotate the image\n rotatable: true,\n // Enable to scale the image\n scalable: true,\n // Enable to zoom the image\n zoomable: true,\n // Enable to zoom the image by dragging touch\n zoomOnTouch: true,\n // Enable to zoom the image by wheeling mouse\n zoomOnWheel: true,\n // Define zoom ratio when zoom the image by wheeling mouse\n wheelZoomRatio: 0.1,\n // Enable to move the crop box\n cropBoxMovable: true,\n // Enable to resize the crop box\n cropBoxResizable: true,\n // Toggle drag mode between \"crop\" and \"move\" when click twice on the cropper\n toggleDragModeOnDblclick: true,\n // Size limitation\n minCanvasWidth: 0,\n minCanvasHeight: 0,\n minCropBoxWidth: 0,\n minCropBoxHeight: 0,\n minContainerWidth: MIN_CONTAINER_WIDTH,\n minContainerHeight: MIN_CONTAINER_HEIGHT,\n // Shortcuts of events\n ready: null,\n cropstart: null,\n cropmove: null,\n cropend: null,\n crop: null,\n zoom: null\n };\n\n var TEMPLATE = '
' + '
' + '
' + '
' + '
' + '
' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '
' + '
';\n\n /**\n * Check if the given value is not a number.\n */\n var isNaN = Number.isNaN || WINDOW.isNaN;\n\n /**\n * Check if the given value is a number.\n * @param {*} value - The value to check.\n * @returns {boolean} Returns `true` if the given value is a number, else `false`.\n */\n function isNumber(value) {\n return typeof value === 'number' && !isNaN(value);\n }\n\n /**\n * Check if the given value is a positive number.\n * @param {*} value - The value to check.\n * @returns {boolean} Returns `true` if the given value is a positive number, else `false`.\n */\n var isPositiveNumber = function isPositiveNumber(value) {\n return value > 0 && value < Infinity;\n };\n\n /**\n * Check if the given value is undefined.\n * @param {*} value - The value to check.\n * @returns {boolean} Returns `true` if the given value is undefined, else `false`.\n */\n function isUndefined(value) {\n return typeof value === 'undefined';\n }\n\n /**\n * Check if the given value is an object.\n * @param {*} value - The value to check.\n * @returns {boolean} Returns `true` if the given value is an object, else `false`.\n */\n function isObject(value) {\n return _typeof(value) === 'object' && value !== null;\n }\n var hasOwnProperty = Object.prototype.hasOwnProperty;\n\n /**\n * Check if the given value is a plain object.\n * @param {*} value - The value to check.\n * @returns {boolean} Returns `true` if the given value is a plain object, else `false`.\n */\n function isPlainObject(value) {\n if (!isObject(value)) {\n return false;\n }\n try {\n var _constructor = value.constructor;\n var prototype = _constructor.prototype;\n return _constructor && prototype && hasOwnProperty.call(prototype, 'isPrototypeOf');\n } catch (error) {\n return false;\n }\n }\n\n /**\n * Check if the given value is a function.\n * @param {*} value - The value to check.\n * @returns {boolean} Returns `true` if the given value is a function, else `false`.\n */\n function isFunction(value) {\n return typeof value === 'function';\n }\n var slice = Array.prototype.slice;\n\n /**\n * Convert array-like or iterable object to an array.\n * @param {*} value - The value to convert.\n * @returns {Array} Returns a new array.\n */\n function toArray(value) {\n return Array.from ? Array.from(value) : slice.call(value);\n }\n\n /**\n * Iterate the given data.\n * @param {*} data - The data to iterate.\n * @param {Function} callback - The process function for each element.\n * @returns {*} The original data.\n */\n function forEach(data, callback) {\n if (data && isFunction(callback)) {\n if (Array.isArray(data) || isNumber(data.length) /* array-like */) {\n toArray(data).forEach(function (value, key) {\n callback.call(data, value, key, data);\n });\n } else if (isObject(data)) {\n Object.keys(data).forEach(function (key) {\n callback.call(data, data[key], key, data);\n });\n }\n }\n return data;\n }\n\n /**\n * Extend the given object.\n * @param {*} target - The target object to extend.\n * @param {*} args - The rest objects for merging to the target object.\n * @returns {Object} The extended object.\n */\n var assign = Object.assign || function assign(target) {\n for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {\n args[_key - 1] = arguments[_key];\n }\n if (isObject(target) && args.length > 0) {\n args.forEach(function (arg) {\n if (isObject(arg)) {\n Object.keys(arg).forEach(function (key) {\n target[key] = arg[key];\n });\n }\n });\n }\n return target;\n };\n var REGEXP_DECIMALS = /\\.\\d*(?:0|9){12}\\d*$/;\n\n /**\n * Normalize decimal number.\n * Check out {@link https://0.30000000000000004.com/}\n * @param {number} value - The value to normalize.\n * @param {number} [times=100000000000] - The times for normalizing.\n * @returns {number} Returns the normalized number.\n */\n function normalizeDecimalNumber(value) {\n var times = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 100000000000;\n return REGEXP_DECIMALS.test(value) ? Math.round(value * times) / times : value;\n }\n var REGEXP_SUFFIX = /^width|height|left|top|marginLeft|marginTop$/;\n\n /**\n * Apply styles to the given element.\n * @param {Element} element - The target element.\n * @param {Object} styles - The styles for applying.\n */\n function setStyle(element, styles) {\n var style = element.style;\n forEach(styles, function (value, property) {\n if (REGEXP_SUFFIX.test(property) && isNumber(value)) {\n value = \"\".concat(value, \"px\");\n }\n style[property] = value;\n });\n }\n\n /**\n * Check if the given element has a special class.\n * @param {Element} element - The element to check.\n * @param {string} value - The class to search.\n * @returns {boolean} Returns `true` if the special class was found.\n */\n function hasClass(element, value) {\n return element.classList ? element.classList.contains(value) : element.className.indexOf(value) > -1;\n }\n\n /**\n * Add classes to the given element.\n * @param {Element} element - The target element.\n * @param {string} value - The classes to be added.\n */\n function addClass(element, value) {\n if (!value) {\n return;\n }\n if (isNumber(element.length)) {\n forEach(element, function (elem) {\n addClass(elem, value);\n });\n return;\n }\n if (element.classList) {\n element.classList.add(value);\n return;\n }\n var className = element.className.trim();\n if (!className) {\n element.className = value;\n } else if (className.indexOf(value) < 0) {\n element.className = \"\".concat(className, \" \").concat(value);\n }\n }\n\n /**\n * Remove classes from the given element.\n * @param {Element} element - The target element.\n * @param {string} value - The classes to be removed.\n */\n function removeClass(element, value) {\n if (!value) {\n return;\n }\n if (isNumber(element.length)) {\n forEach(element, function (elem) {\n removeClass(elem, value);\n });\n return;\n }\n if (element.classList) {\n element.classList.remove(value);\n return;\n }\n if (element.className.indexOf(value) >= 0) {\n element.className = element.className.replace(value, '');\n }\n }\n\n /**\n * Add or remove classes from the given element.\n * @param {Element} element - The target element.\n * @param {string} value - The classes to be toggled.\n * @param {boolean} added - Add only.\n */\n function toggleClass(element, value, added) {\n if (!value) {\n return;\n }\n if (isNumber(element.length)) {\n forEach(element, function (elem) {\n toggleClass(elem, value, added);\n });\n return;\n }\n\n // IE10-11 doesn't support the second parameter of `classList.toggle`\n if (added) {\n addClass(element, value);\n } else {\n removeClass(element, value);\n }\n }\n var REGEXP_CAMEL_CASE = /([a-z\\d])([A-Z])/g;\n\n /**\n * Transform the given string from camelCase to kebab-case\n * @param {string} value - The value to transform.\n * @returns {string} The transformed value.\n */\n function toParamCase(value) {\n return value.replace(REGEXP_CAMEL_CASE, '$1-$2').toLowerCase();\n }\n\n /**\n * Get data from the given element.\n * @param {Element} element - The target element.\n * @param {string} name - The data key to get.\n * @returns {string} The data value.\n */\n function getData(element, name) {\n if (isObject(element[name])) {\n return element[name];\n }\n if (element.dataset) {\n return element.dataset[name];\n }\n return element.getAttribute(\"data-\".concat(toParamCase(name)));\n }\n\n /**\n * Set data to the given element.\n * @param {Element} element - The target element.\n * @param {string} name - The data key to set.\n * @param {string} data - The data value.\n */\n function setData(element, name, data) {\n if (isObject(data)) {\n element[name] = data;\n } else if (element.dataset) {\n element.dataset[name] = data;\n } else {\n element.setAttribute(\"data-\".concat(toParamCase(name)), data);\n }\n }\n\n /**\n * Remove data from the given element.\n * @param {Element} element - The target element.\n * @param {string} name - The data key to remove.\n */\n function removeData(element, name) {\n if (isObject(element[name])) {\n try {\n delete element[name];\n } catch (error) {\n element[name] = undefined;\n }\n } else if (element.dataset) {\n // #128 Safari not allows to delete dataset property\n try {\n delete element.dataset[name];\n } catch (error) {\n element.dataset[name] = undefined;\n }\n } else {\n element.removeAttribute(\"data-\".concat(toParamCase(name)));\n }\n }\n var REGEXP_SPACES = /\\s\\s*/;\n var onceSupported = function () {\n var supported = false;\n if (IS_BROWSER) {\n var once = false;\n var listener = function listener() {};\n var options = Object.defineProperty({}, 'once', {\n get: function get() {\n supported = true;\n return once;\n },\n /**\n * This setter can fix a `TypeError` in strict mode\n * {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Errors/Getter_only}\n * @param {boolean} value - The value to set\n */\n set: function set(value) {\n once = value;\n }\n });\n WINDOW.addEventListener('test', listener, options);\n WINDOW.removeEventListener('test', listener, options);\n }\n return supported;\n }();\n\n /**\n * Remove event listener from the target element.\n * @param {Element} element - The event target.\n * @param {string} type - The event type(s).\n * @param {Function} listener - The event listener.\n * @param {Object} options - The event options.\n */\n function removeListener(element, type, listener) {\n var options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};\n var handler = listener;\n type.trim().split(REGEXP_SPACES).forEach(function (event) {\n if (!onceSupported) {\n var listeners = element.listeners;\n if (listeners && listeners[event] && listeners[event][listener]) {\n handler = listeners[event][listener];\n delete listeners[event][listener];\n if (Object.keys(listeners[event]).length === 0) {\n delete listeners[event];\n }\n if (Object.keys(listeners).length === 0) {\n delete element.listeners;\n }\n }\n }\n element.removeEventListener(event, handler, options);\n });\n }\n\n /**\n * Add event listener to the target element.\n * @param {Element} element - The event target.\n * @param {string} type - The event type(s).\n * @param {Function} listener - The event listener.\n * @param {Object} options - The event options.\n */\n function addListener(element, type, listener) {\n var options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};\n var _handler = listener;\n type.trim().split(REGEXP_SPACES).forEach(function (event) {\n if (options.once && !onceSupported) {\n var _element$listeners = element.listeners,\n listeners = _element$listeners === void 0 ? {} : _element$listeners;\n _handler = function handler() {\n delete listeners[event][listener];\n element.removeEventListener(event, _handler, options);\n for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {\n args[_key2] = arguments[_key2];\n }\n listener.apply(element, args);\n };\n if (!listeners[event]) {\n listeners[event] = {};\n }\n if (listeners[event][listener]) {\n element.removeEventListener(event, listeners[event][listener], options);\n }\n listeners[event][listener] = _handler;\n element.listeners = listeners;\n }\n element.addEventListener(event, _handler, options);\n });\n }\n\n /**\n * Dispatch event on the target element.\n * @param {Element} element - The event target.\n * @param {string} type - The event type(s).\n * @param {Object} data - The additional event data.\n * @returns {boolean} Indicate if the event is default prevented or not.\n */\n function dispatchEvent(element, type, data) {\n var event;\n\n // Event and CustomEvent on IE9-11 are global objects, not constructors\n if (isFunction(Event) && isFunction(CustomEvent)) {\n event = new CustomEvent(type, {\n detail: data,\n bubbles: true,\n cancelable: true\n });\n } else {\n event = document.createEvent('CustomEvent');\n event.initCustomEvent(type, true, true, data);\n }\n return element.dispatchEvent(event);\n }\n\n /**\n * Get the offset base on the document.\n * @param {Element} element - The target element.\n * @returns {Object} The offset data.\n */\n function getOffset(element) {\n var box = element.getBoundingClientRect();\n return {\n left: box.left + (window.pageXOffset - document.documentElement.clientLeft),\n top: box.top + (window.pageYOffset - document.documentElement.clientTop)\n };\n }\n var location = WINDOW.location;\n var REGEXP_ORIGINS = /^(\\w+:)\\/\\/([^:/?#]*):?(\\d*)/i;\n\n /**\n * Check if the given URL is a cross origin URL.\n * @param {string} url - The target URL.\n * @returns {boolean} Returns `true` if the given URL is a cross origin URL, else `false`.\n */\n function isCrossOriginURL(url) {\n var parts = url.match(REGEXP_ORIGINS);\n return parts !== null && (parts[1] !== location.protocol || parts[2] !== location.hostname || parts[3] !== location.port);\n }\n\n /**\n * Add timestamp to the given URL.\n * @param {string} url - The target URL.\n * @returns {string} The result URL.\n */\n function addTimestamp(url) {\n var timestamp = \"timestamp=\".concat(new Date().getTime());\n return url + (url.indexOf('?') === -1 ? '?' : '&') + timestamp;\n }\n\n /**\n * Get transforms base on the given object.\n * @param {Object} obj - The target object.\n * @returns {string} A string contains transform values.\n */\n function getTransforms(_ref) {\n var rotate = _ref.rotate,\n scaleX = _ref.scaleX,\n scaleY = _ref.scaleY,\n translateX = _ref.translateX,\n translateY = _ref.translateY;\n var values = [];\n if (isNumber(translateX) && translateX !== 0) {\n values.push(\"translateX(\".concat(translateX, \"px)\"));\n }\n if (isNumber(translateY) && translateY !== 0) {\n values.push(\"translateY(\".concat(translateY, \"px)\"));\n }\n\n // Rotate should come first before scale to match orientation transform\n if (isNumber(rotate) && rotate !== 0) {\n values.push(\"rotate(\".concat(rotate, \"deg)\"));\n }\n if (isNumber(scaleX) && scaleX !== 1) {\n values.push(\"scaleX(\".concat(scaleX, \")\"));\n }\n if (isNumber(scaleY) && scaleY !== 1) {\n values.push(\"scaleY(\".concat(scaleY, \")\"));\n }\n var transform = values.length ? values.join(' ') : 'none';\n return {\n WebkitTransform: transform,\n msTransform: transform,\n transform: transform\n };\n }\n\n /**\n * Get the max ratio of a group of pointers.\n * @param {string} pointers - The target pointers.\n * @returns {number} The result ratio.\n */\n function getMaxZoomRatio(pointers) {\n var pointers2 = _objectSpread2({}, pointers);\n var maxRatio = 0;\n forEach(pointers, function (pointer, pointerId) {\n delete pointers2[pointerId];\n forEach(pointers2, function (pointer2) {\n var x1 = Math.abs(pointer.startX - pointer2.startX);\n var y1 = Math.abs(pointer.startY - pointer2.startY);\n var x2 = Math.abs(pointer.endX - pointer2.endX);\n var y2 = Math.abs(pointer.endY - pointer2.endY);\n var z1 = Math.sqrt(x1 * x1 + y1 * y1);\n var z2 = Math.sqrt(x2 * x2 + y2 * y2);\n var ratio = (z2 - z1) / z1;\n if (Math.abs(ratio) > Math.abs(maxRatio)) {\n maxRatio = ratio;\n }\n });\n });\n return maxRatio;\n }\n\n /**\n * Get a pointer from an event object.\n * @param {Object} event - The target event object.\n * @param {boolean} endOnly - Indicates if only returns the end point coordinate or not.\n * @returns {Object} The result pointer contains start and/or end point coordinates.\n */\n function getPointer(_ref2, endOnly) {\n var pageX = _ref2.pageX,\n pageY = _ref2.pageY;\n var end = {\n endX: pageX,\n endY: pageY\n };\n return endOnly ? end : _objectSpread2({\n startX: pageX,\n startY: pageY\n }, end);\n }\n\n /**\n * Get the center point coordinate of a group of pointers.\n * @param {Object} pointers - The target pointers.\n * @returns {Object} The center point coordinate.\n */\n function getPointersCenter(pointers) {\n var pageX = 0;\n var pageY = 0;\n var count = 0;\n forEach(pointers, function (_ref3) {\n var startX = _ref3.startX,\n startY = _ref3.startY;\n pageX += startX;\n pageY += startY;\n count += 1;\n });\n pageX /= count;\n pageY /= count;\n return {\n pageX: pageX,\n pageY: pageY\n };\n }\n\n /**\n * Get the max sizes in a rectangle under the given aspect ratio.\n * @param {Object} data - The original sizes.\n * @param {string} [type='contain'] - The adjust type.\n * @returns {Object} The result sizes.\n */\n function getAdjustedSizes(_ref4) {\n var aspectRatio = _ref4.aspectRatio,\n height = _ref4.height,\n width = _ref4.width;\n var type = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'contain';\n var isValidWidth = isPositiveNumber(width);\n var isValidHeight = isPositiveNumber(height);\n if (isValidWidth && isValidHeight) {\n var adjustedWidth = height * aspectRatio;\n if (type === 'contain' && adjustedWidth > width || type === 'cover' && adjustedWidth < width) {\n height = width / aspectRatio;\n } else {\n width = height * aspectRatio;\n }\n } else if (isValidWidth) {\n height = width / aspectRatio;\n } else if (isValidHeight) {\n width = height * aspectRatio;\n }\n return {\n width: width,\n height: height\n };\n }\n\n /**\n * Get the new sizes of a rectangle after rotated.\n * @param {Object} data - The original sizes.\n * @returns {Object} The result sizes.\n */\n function getRotatedSizes(_ref5) {\n var width = _ref5.width,\n height = _ref5.height,\n degree = _ref5.degree;\n degree = Math.abs(degree) % 180;\n if (degree === 90) {\n return {\n width: height,\n height: width\n };\n }\n var arc = degree % 90 * Math.PI / 180;\n var sinArc = Math.sin(arc);\n var cosArc = Math.cos(arc);\n var newWidth = width * cosArc + height * sinArc;\n var newHeight = width * sinArc + height * cosArc;\n return degree > 90 ? {\n width: newHeight,\n height: newWidth\n } : {\n width: newWidth,\n height: newHeight\n };\n }\n\n /**\n * Get a canvas which drew the given image.\n * @param {HTMLImageElement} image - The image for drawing.\n * @param {Object} imageData - The image data.\n * @param {Object} canvasData - The canvas data.\n * @param {Object} options - The options.\n * @returns {HTMLCanvasElement} The result canvas.\n */\n function getSourceCanvas(image, _ref6, _ref7, _ref8) {\n var imageAspectRatio = _ref6.aspectRatio,\n imageNaturalWidth = _ref6.naturalWidth,\n imageNaturalHeight = _ref6.naturalHeight,\n _ref6$rotate = _ref6.rotate,\n rotate = _ref6$rotate === void 0 ? 0 : _ref6$rotate,\n _ref6$scaleX = _ref6.scaleX,\n scaleX = _ref6$scaleX === void 0 ? 1 : _ref6$scaleX,\n _ref6$scaleY = _ref6.scaleY,\n scaleY = _ref6$scaleY === void 0 ? 1 : _ref6$scaleY;\n var aspectRatio = _ref7.aspectRatio,\n naturalWidth = _ref7.naturalWidth,\n naturalHeight = _ref7.naturalHeight;\n var _ref8$fillColor = _ref8.fillColor,\n fillColor = _ref8$fillColor === void 0 ? 'transparent' : _ref8$fillColor,\n _ref8$imageSmoothingE = _ref8.imageSmoothingEnabled,\n imageSmoothingEnabled = _ref8$imageSmoothingE === void 0 ? true : _ref8$imageSmoothingE,\n _ref8$imageSmoothingQ = _ref8.imageSmoothingQuality,\n imageSmoothingQuality = _ref8$imageSmoothingQ === void 0 ? 'low' : _ref8$imageSmoothingQ,\n _ref8$maxWidth = _ref8.maxWidth,\n maxWidth = _ref8$maxWidth === void 0 ? Infinity : _ref8$maxWidth,\n _ref8$maxHeight = _ref8.maxHeight,\n maxHeight = _ref8$maxHeight === void 0 ? Infinity : _ref8$maxHeight,\n _ref8$minWidth = _ref8.minWidth,\n minWidth = _ref8$minWidth === void 0 ? 0 : _ref8$minWidth,\n _ref8$minHeight = _ref8.minHeight,\n minHeight = _ref8$minHeight === void 0 ? 0 : _ref8$minHeight;\n var canvas = document.createElement('canvas');\n var context = canvas.getContext('2d');\n var maxSizes = getAdjustedSizes({\n aspectRatio: aspectRatio,\n width: maxWidth,\n height: maxHeight\n });\n var minSizes = getAdjustedSizes({\n aspectRatio: aspectRatio,\n width: minWidth,\n height: minHeight\n }, 'cover');\n var width = Math.min(maxSizes.width, Math.max(minSizes.width, naturalWidth));\n var height = Math.min(maxSizes.height, Math.max(minSizes.height, naturalHeight));\n\n // Note: should always use image's natural sizes for drawing as\n // imageData.naturalWidth === canvasData.naturalHeight when rotate % 180 === 90\n var destMaxSizes = getAdjustedSizes({\n aspectRatio: imageAspectRatio,\n width: maxWidth,\n height: maxHeight\n });\n var destMinSizes = getAdjustedSizes({\n aspectRatio: imageAspectRatio,\n width: minWidth,\n height: minHeight\n }, 'cover');\n var destWidth = Math.min(destMaxSizes.width, Math.max(destMinSizes.width, imageNaturalWidth));\n var destHeight = Math.min(destMaxSizes.height, Math.max(destMinSizes.height, imageNaturalHeight));\n var params = [-destWidth / 2, -destHeight / 2, destWidth, destHeight];\n canvas.width = normalizeDecimalNumber(width);\n canvas.height = normalizeDecimalNumber(height);\n context.fillStyle = fillColor;\n context.fillRect(0, 0, width, height);\n context.save();\n context.translate(width / 2, height / 2);\n context.rotate(rotate * Math.PI / 180);\n context.scale(scaleX, scaleY);\n context.imageSmoothingEnabled = imageSmoothingEnabled;\n context.imageSmoothingQuality = imageSmoothingQuality;\n context.drawImage.apply(context, [image].concat(_toConsumableArray(params.map(function (param) {\n return Math.floor(normalizeDecimalNumber(param));\n }))));\n context.restore();\n return canvas;\n }\n var fromCharCode = String.fromCharCode;\n\n /**\n * Get string from char code in data view.\n * @param {DataView} dataView - The data view for read.\n * @param {number} start - The start index.\n * @param {number} length - The read length.\n * @returns {string} The read result.\n */\n function getStringFromCharCode(dataView, start, length) {\n var str = '';\n length += start;\n for (var i = start; i < length; i += 1) {\n str += fromCharCode(dataView.getUint8(i));\n }\n return str;\n }\n var REGEXP_DATA_URL_HEAD = /^data:.*,/;\n\n /**\n * Transform Data URL to array buffer.\n * @param {string} dataURL - The Data URL to transform.\n * @returns {ArrayBuffer} The result array buffer.\n */\n function dataURLToArrayBuffer(dataURL) {\n var base64 = dataURL.replace(REGEXP_DATA_URL_HEAD, '');\n var binary = atob(base64);\n var arrayBuffer = new ArrayBuffer(binary.length);\n var uint8 = new Uint8Array(arrayBuffer);\n forEach(uint8, function (value, i) {\n uint8[i] = binary.charCodeAt(i);\n });\n return arrayBuffer;\n }\n\n /**\n * Transform array buffer to Data URL.\n * @param {ArrayBuffer} arrayBuffer - The array buffer to transform.\n * @param {string} mimeType - The mime type of the Data URL.\n * @returns {string} The result Data URL.\n */\n function arrayBufferToDataURL(arrayBuffer, mimeType) {\n var chunks = [];\n\n // Chunk Typed Array for better performance (#435)\n var chunkSize = 8192;\n var uint8 = new Uint8Array(arrayBuffer);\n while (uint8.length > 0) {\n // XXX: Babel's `toConsumableArray` helper will throw error in IE or Safari 9\n // eslint-disable-next-line prefer-spread\n chunks.push(fromCharCode.apply(null, toArray(uint8.subarray(0, chunkSize))));\n uint8 = uint8.subarray(chunkSize);\n }\n return \"data:\".concat(mimeType, \";base64,\").concat(btoa(chunks.join('')));\n }\n\n /**\n * Get orientation value from given array buffer.\n * @param {ArrayBuffer} arrayBuffer - The array buffer to read.\n * @returns {number} The read orientation value.\n */\n function resetAndGetOrientation(arrayBuffer) {\n var dataView = new DataView(arrayBuffer);\n var orientation;\n\n // Ignores range error when the image does not have correct Exif information\n try {\n var littleEndian;\n var app1Start;\n var ifdStart;\n\n // Only handle JPEG image (start by 0xFFD8)\n if (dataView.getUint8(0) === 0xFF && dataView.getUint8(1) === 0xD8) {\n var length = dataView.byteLength;\n var offset = 2;\n while (offset + 1 < length) {\n if (dataView.getUint8(offset) === 0xFF && dataView.getUint8(offset + 1) === 0xE1) {\n app1Start = offset;\n break;\n }\n offset += 1;\n }\n }\n if (app1Start) {\n var exifIDCode = app1Start + 4;\n var tiffOffset = app1Start + 10;\n if (getStringFromCharCode(dataView, exifIDCode, 4) === 'Exif') {\n var endianness = dataView.getUint16(tiffOffset);\n littleEndian = endianness === 0x4949;\n if (littleEndian || endianness === 0x4D4D /* bigEndian */) {\n if (dataView.getUint16(tiffOffset + 2, littleEndian) === 0x002A) {\n var firstIFDOffset = dataView.getUint32(tiffOffset + 4, littleEndian);\n if (firstIFDOffset >= 0x00000008) {\n ifdStart = tiffOffset + firstIFDOffset;\n }\n }\n }\n }\n }\n if (ifdStart) {\n var _length = dataView.getUint16(ifdStart, littleEndian);\n var _offset;\n var i;\n for (i = 0; i < _length; i += 1) {\n _offset = ifdStart + i * 12 + 2;\n if (dataView.getUint16(_offset, littleEndian) === 0x0112 /* Orientation */) {\n // 8 is the offset of the current tag's value\n _offset += 8;\n\n // Get the original orientation value\n orientation = dataView.getUint16(_offset, littleEndian);\n\n // Override the orientation with its default value\n dataView.setUint16(_offset, 1, littleEndian);\n break;\n }\n }\n }\n } catch (error) {\n orientation = 1;\n }\n return orientation;\n }\n\n /**\n * Parse Exif Orientation value.\n * @param {number} orientation - The orientation to parse.\n * @returns {Object} The parsed result.\n */\n function parseOrientation(orientation) {\n var rotate = 0;\n var scaleX = 1;\n var scaleY = 1;\n switch (orientation) {\n // Flip horizontal\n case 2:\n scaleX = -1;\n break;\n\n // Rotate left 180\u00B0\n case 3:\n rotate = -180;\n break;\n\n // Flip vertical\n case 4:\n scaleY = -1;\n break;\n\n // Flip vertical and rotate right 90\u00B0\n case 5:\n rotate = 90;\n scaleY = -1;\n break;\n\n // Rotate right 90\u00B0\n case 6:\n rotate = 90;\n break;\n\n // Flip horizontal and rotate right 90\u00B0\n case 7:\n rotate = 90;\n scaleX = -1;\n break;\n\n // Rotate left 90\u00B0\n case 8:\n rotate = -90;\n break;\n }\n return {\n rotate: rotate,\n scaleX: scaleX,\n scaleY: scaleY\n };\n }\n\n var render = {\n render: function render() {\n this.initContainer();\n this.initCanvas();\n this.initCropBox();\n this.renderCanvas();\n if (this.cropped) {\n this.renderCropBox();\n }\n },\n initContainer: function initContainer() {\n var element = this.element,\n options = this.options,\n container = this.container,\n cropper = this.cropper;\n var minWidth = Number(options.minContainerWidth);\n var minHeight = Number(options.minContainerHeight);\n addClass(cropper, CLASS_HIDDEN);\n removeClass(element, CLASS_HIDDEN);\n var containerData = {\n width: Math.max(container.offsetWidth, minWidth >= 0 ? minWidth : MIN_CONTAINER_WIDTH),\n height: Math.max(container.offsetHeight, minHeight >= 0 ? minHeight : MIN_CONTAINER_HEIGHT)\n };\n this.containerData = containerData;\n setStyle(cropper, {\n width: containerData.width,\n height: containerData.height\n });\n addClass(element, CLASS_HIDDEN);\n removeClass(cropper, CLASS_HIDDEN);\n },\n // Canvas (image wrapper)\n initCanvas: function initCanvas() {\n var containerData = this.containerData,\n imageData = this.imageData;\n var viewMode = this.options.viewMode;\n var rotated = Math.abs(imageData.rotate) % 180 === 90;\n var naturalWidth = rotated ? imageData.naturalHeight : imageData.naturalWidth;\n var naturalHeight = rotated ? imageData.naturalWidth : imageData.naturalHeight;\n var aspectRatio = naturalWidth / naturalHeight;\n var canvasWidth = containerData.width;\n var canvasHeight = containerData.height;\n if (containerData.height * aspectRatio > containerData.width) {\n if (viewMode === 3) {\n canvasWidth = containerData.height * aspectRatio;\n } else {\n canvasHeight = containerData.width / aspectRatio;\n }\n } else if (viewMode === 3) {\n canvasHeight = containerData.width / aspectRatio;\n } else {\n canvasWidth = containerData.height * aspectRatio;\n }\n var canvasData = {\n aspectRatio: aspectRatio,\n naturalWidth: naturalWidth,\n naturalHeight: naturalHeight,\n width: canvasWidth,\n height: canvasHeight\n };\n this.canvasData = canvasData;\n this.limited = viewMode === 1 || viewMode === 2;\n this.limitCanvas(true, true);\n canvasData.width = Math.min(Math.max(canvasData.width, canvasData.minWidth), canvasData.maxWidth);\n canvasData.height = Math.min(Math.max(canvasData.height, canvasData.minHeight), canvasData.maxHeight);\n canvasData.left = (containerData.width - canvasData.width) / 2;\n canvasData.top = (containerData.height - canvasData.height) / 2;\n canvasData.oldLeft = canvasData.left;\n canvasData.oldTop = canvasData.top;\n this.initialCanvasData = assign({}, canvasData);\n },\n limitCanvas: function limitCanvas(sizeLimited, positionLimited) {\n var options = this.options,\n containerData = this.containerData,\n canvasData = this.canvasData,\n cropBoxData = this.cropBoxData;\n var viewMode = options.viewMode;\n var aspectRatio = canvasData.aspectRatio;\n var cropped = this.cropped && cropBoxData;\n if (sizeLimited) {\n var minCanvasWidth = Number(options.minCanvasWidth) || 0;\n var minCanvasHeight = Number(options.minCanvasHeight) || 0;\n if (viewMode > 1) {\n minCanvasWidth = Math.max(minCanvasWidth, containerData.width);\n minCanvasHeight = Math.max(minCanvasHeight, containerData.height);\n if (viewMode === 3) {\n if (minCanvasHeight * aspectRatio > minCanvasWidth) {\n minCanvasWidth = minCanvasHeight * aspectRatio;\n } else {\n minCanvasHeight = minCanvasWidth / aspectRatio;\n }\n }\n } else if (viewMode > 0) {\n if (minCanvasWidth) {\n minCanvasWidth = Math.max(minCanvasWidth, cropped ? cropBoxData.width : 0);\n } else if (minCanvasHeight) {\n minCanvasHeight = Math.max(minCanvasHeight, cropped ? cropBoxData.height : 0);\n } else if (cropped) {\n minCanvasWidth = cropBoxData.width;\n minCanvasHeight = cropBoxData.height;\n if (minCanvasHeight * aspectRatio > minCanvasWidth) {\n minCanvasWidth = minCanvasHeight * aspectRatio;\n } else {\n minCanvasHeight = minCanvasWidth / aspectRatio;\n }\n }\n }\n var _getAdjustedSizes = getAdjustedSizes({\n aspectRatio: aspectRatio,\n width: minCanvasWidth,\n height: minCanvasHeight\n });\n minCanvasWidth = _getAdjustedSizes.width;\n minCanvasHeight = _getAdjustedSizes.height;\n canvasData.minWidth = minCanvasWidth;\n canvasData.minHeight = minCanvasHeight;\n canvasData.maxWidth = Infinity;\n canvasData.maxHeight = Infinity;\n }\n if (positionLimited) {\n if (viewMode > (cropped ? 0 : 1)) {\n var newCanvasLeft = containerData.width - canvasData.width;\n var newCanvasTop = containerData.height - canvasData.height;\n canvasData.minLeft = Math.min(0, newCanvasLeft);\n canvasData.minTop = Math.min(0, newCanvasTop);\n canvasData.maxLeft = Math.max(0, newCanvasLeft);\n canvasData.maxTop = Math.max(0, newCanvasTop);\n if (cropped && this.limited) {\n canvasData.minLeft = Math.min(cropBoxData.left, cropBoxData.left + (cropBoxData.width - canvasData.width));\n canvasData.minTop = Math.min(cropBoxData.top, cropBoxData.top + (cropBoxData.height - canvasData.height));\n canvasData.maxLeft = cropBoxData.left;\n canvasData.maxTop = cropBoxData.top;\n if (viewMode === 2) {\n if (canvasData.width >= containerData.width) {\n canvasData.minLeft = Math.min(0, newCanvasLeft);\n canvasData.maxLeft = Math.max(0, newCanvasLeft);\n }\n if (canvasData.height >= containerData.height) {\n canvasData.minTop = Math.min(0, newCanvasTop);\n canvasData.maxTop = Math.max(0, newCanvasTop);\n }\n }\n }\n } else {\n canvasData.minLeft = -canvasData.width;\n canvasData.minTop = -canvasData.height;\n canvasData.maxLeft = containerData.width;\n canvasData.maxTop = containerData.height;\n }\n }\n },\n renderCanvas: function renderCanvas(changed, transformed) {\n var canvasData = this.canvasData,\n imageData = this.imageData;\n if (transformed) {\n var _getRotatedSizes = getRotatedSizes({\n width: imageData.naturalWidth * Math.abs(imageData.scaleX || 1),\n height: imageData.naturalHeight * Math.abs(imageData.scaleY || 1),\n degree: imageData.rotate || 0\n }),\n naturalWidth = _getRotatedSizes.width,\n naturalHeight = _getRotatedSizes.height;\n var width = canvasData.width * (naturalWidth / canvasData.naturalWidth);\n var height = canvasData.height * (naturalHeight / canvasData.naturalHeight);\n canvasData.left -= (width - canvasData.width) / 2;\n canvasData.top -= (height - canvasData.height) / 2;\n canvasData.width = width;\n canvasData.height = height;\n canvasData.aspectRatio = naturalWidth / naturalHeight;\n canvasData.naturalWidth = naturalWidth;\n canvasData.naturalHeight = naturalHeight;\n this.limitCanvas(true, false);\n }\n if (canvasData.width > canvasData.maxWidth || canvasData.width < canvasData.minWidth) {\n canvasData.left = canvasData.oldLeft;\n }\n if (canvasData.height > canvasData.maxHeight || canvasData.height < canvasData.minHeight) {\n canvasData.top = canvasData.oldTop;\n }\n canvasData.width = Math.min(Math.max(canvasData.width, canvasData.minWidth), canvasData.maxWidth);\n canvasData.height = Math.min(Math.max(canvasData.height, canvasData.minHeight), canvasData.maxHeight);\n this.limitCanvas(false, true);\n canvasData.left = Math.min(Math.max(canvasData.left, canvasData.minLeft), canvasData.maxLeft);\n canvasData.top = Math.min(Math.max(canvasData.top, canvasData.minTop), canvasData.maxTop);\n canvasData.oldLeft = canvasData.left;\n canvasData.oldTop = canvasData.top;\n setStyle(this.canvas, assign({\n width: canvasData.width,\n height: canvasData.height\n }, getTransforms({\n translateX: canvasData.left,\n translateY: canvasData.top\n })));\n this.renderImage(changed);\n if (this.cropped && this.limited) {\n this.limitCropBox(true, true);\n }\n },\n renderImage: function renderImage(changed) {\n var canvasData = this.canvasData,\n imageData = this.imageData;\n var width = imageData.naturalWidth * (canvasData.width / canvasData.naturalWidth);\n var height = imageData.naturalHeight * (canvasData.height / canvasData.naturalHeight);\n assign(imageData, {\n width: width,\n height: height,\n left: (canvasData.width - width) / 2,\n top: (canvasData.height - height) / 2\n });\n setStyle(this.image, assign({\n width: imageData.width,\n height: imageData.height\n }, getTransforms(assign({\n translateX: imageData.left,\n translateY: imageData.top\n }, imageData))));\n if (changed) {\n this.output();\n }\n },\n initCropBox: function initCropBox() {\n var options = this.options,\n canvasData = this.canvasData;\n var aspectRatio = options.aspectRatio || options.initialAspectRatio;\n var autoCropArea = Number(options.autoCropArea) || 0.8;\n var cropBoxData = {\n width: canvasData.width,\n height: canvasData.height\n };\n if (aspectRatio) {\n if (canvasData.height * aspectRatio > canvasData.width) {\n cropBoxData.height = cropBoxData.width / aspectRatio;\n } else {\n cropBoxData.width = cropBoxData.height * aspectRatio;\n }\n }\n this.cropBoxData = cropBoxData;\n this.limitCropBox(true, true);\n\n // Initialize auto crop area\n cropBoxData.width = Math.min(Math.max(cropBoxData.width, cropBoxData.minWidth), cropBoxData.maxWidth);\n cropBoxData.height = Math.min(Math.max(cropBoxData.height, cropBoxData.minHeight), cropBoxData.maxHeight);\n\n // The width/height of auto crop area must large than \"minWidth/Height\"\n cropBoxData.width = Math.max(cropBoxData.minWidth, cropBoxData.width * autoCropArea);\n cropBoxData.height = Math.max(cropBoxData.minHeight, cropBoxData.height * autoCropArea);\n cropBoxData.left = canvasData.left + (canvasData.width - cropBoxData.width) / 2;\n cropBoxData.top = canvasData.top + (canvasData.height - cropBoxData.height) / 2;\n cropBoxData.oldLeft = cropBoxData.left;\n cropBoxData.oldTop = cropBoxData.top;\n this.initialCropBoxData = assign({}, cropBoxData);\n },\n limitCropBox: function limitCropBox(sizeLimited, positionLimited) {\n var options = this.options,\n containerData = this.containerData,\n canvasData = this.canvasData,\n cropBoxData = this.cropBoxData,\n limited = this.limited;\n var aspectRatio = options.aspectRatio;\n if (sizeLimited) {\n var minCropBoxWidth = Number(options.minCropBoxWidth) || 0;\n var minCropBoxHeight = Number(options.minCropBoxHeight) || 0;\n var maxCropBoxWidth = limited ? Math.min(containerData.width, canvasData.width, canvasData.width + canvasData.left, containerData.width - canvasData.left) : containerData.width;\n var maxCropBoxHeight = limited ? Math.min(containerData.height, canvasData.height, canvasData.height + canvasData.top, containerData.height - canvasData.top) : containerData.height;\n\n // The min/maxCropBoxWidth/Height must be less than container's width/height\n minCropBoxWidth = Math.min(minCropBoxWidth, containerData.width);\n minCropBoxHeight = Math.min(minCropBoxHeight, containerData.height);\n if (aspectRatio) {\n if (minCropBoxWidth && minCropBoxHeight) {\n if (minCropBoxHeight * aspectRatio > minCropBoxWidth) {\n minCropBoxHeight = minCropBoxWidth / aspectRatio;\n } else {\n minCropBoxWidth = minCropBoxHeight * aspectRatio;\n }\n } else if (minCropBoxWidth) {\n minCropBoxHeight = minCropBoxWidth / aspectRatio;\n } else if (minCropBoxHeight) {\n minCropBoxWidth = minCropBoxHeight * aspectRatio;\n }\n if (maxCropBoxHeight * aspectRatio > maxCropBoxWidth) {\n maxCropBoxHeight = maxCropBoxWidth / aspectRatio;\n } else {\n maxCropBoxWidth = maxCropBoxHeight * aspectRatio;\n }\n }\n\n // The minWidth/Height must be less than maxWidth/Height\n cropBoxData.minWidth = Math.min(minCropBoxWidth, maxCropBoxWidth);\n cropBoxData.minHeight = Math.min(minCropBoxHeight, maxCropBoxHeight);\n cropBoxData.maxWidth = maxCropBoxWidth;\n cropBoxData.maxHeight = maxCropBoxHeight;\n }\n if (positionLimited) {\n if (limited) {\n cropBoxData.minLeft = Math.max(0, canvasData.left);\n cropBoxData.minTop = Math.max(0, canvasData.top);\n cropBoxData.maxLeft = Math.min(containerData.width, canvasData.left + canvasData.width) - cropBoxData.width;\n cropBoxData.maxTop = Math.min(containerData.height, canvasData.top + canvasData.height) - cropBoxData.height;\n } else {\n cropBoxData.minLeft = 0;\n cropBoxData.minTop = 0;\n cropBoxData.maxLeft = containerData.width - cropBoxData.width;\n cropBoxData.maxTop = containerData.height - cropBoxData.height;\n }\n }\n },\n renderCropBox: function renderCropBox() {\n var options = this.options,\n containerData = this.containerData,\n cropBoxData = this.cropBoxData;\n if (cropBoxData.width > cropBoxData.maxWidth || cropBoxData.width < cropBoxData.minWidth) {\n cropBoxData.left = cropBoxData.oldLeft;\n }\n if (cropBoxData.height > cropBoxData.maxHeight || cropBoxData.height < cropBoxData.minHeight) {\n cropBoxData.top = cropBoxData.oldTop;\n }\n cropBoxData.width = Math.min(Math.max(cropBoxData.width, cropBoxData.minWidth), cropBoxData.maxWidth);\n cropBoxData.height = Math.min(Math.max(cropBoxData.height, cropBoxData.minHeight), cropBoxData.maxHeight);\n this.limitCropBox(false, true);\n cropBoxData.left = Math.min(Math.max(cropBoxData.left, cropBoxData.minLeft), cropBoxData.maxLeft);\n cropBoxData.top = Math.min(Math.max(cropBoxData.top, cropBoxData.minTop), cropBoxData.maxTop);\n cropBoxData.oldLeft = cropBoxData.left;\n cropBoxData.oldTop = cropBoxData.top;\n if (options.movable && options.cropBoxMovable) {\n // Turn to move the canvas when the crop box is equal to the container\n setData(this.face, DATA_ACTION, cropBoxData.width >= containerData.width && cropBoxData.height >= containerData.height ? ACTION_MOVE : ACTION_ALL);\n }\n setStyle(this.cropBox, assign({\n width: cropBoxData.width,\n height: cropBoxData.height\n }, getTransforms({\n translateX: cropBoxData.left,\n translateY: cropBoxData.top\n })));\n if (this.cropped && this.limited) {\n this.limitCanvas(true, true);\n }\n if (!this.disabled) {\n this.output();\n }\n },\n output: function output() {\n this.preview();\n dispatchEvent(this.element, EVENT_CROP, this.getData());\n }\n };\n\n var preview = {\n initPreview: function initPreview() {\n var element = this.element,\n crossOrigin = this.crossOrigin;\n var preview = this.options.preview;\n var url = crossOrigin ? this.crossOriginUrl : this.url;\n var alt = element.alt || 'The image to preview';\n var image = document.createElement('img');\n if (crossOrigin) {\n image.crossOrigin = crossOrigin;\n }\n image.src = url;\n image.alt = alt;\n this.viewBox.appendChild(image);\n this.viewBoxImage = image;\n if (!preview) {\n return;\n }\n var previews = preview;\n if (typeof preview === 'string') {\n previews = element.ownerDocument.querySelectorAll(preview);\n } else if (preview.querySelector) {\n previews = [preview];\n }\n this.previews = previews;\n forEach(previews, function (el) {\n var img = document.createElement('img');\n\n // Save the original size for recover\n setData(el, DATA_PREVIEW, {\n width: el.offsetWidth,\n height: el.offsetHeight,\n html: el.innerHTML\n });\n if (crossOrigin) {\n img.crossOrigin = crossOrigin;\n }\n img.src = url;\n img.alt = alt;\n\n /**\n * Override img element styles\n * Add `display:block` to avoid margin top issue\n * Add `height:auto` to override `height` attribute on IE8\n * (Occur only when margin-top <= -height)\n */\n img.style.cssText = 'display:block;' + 'width:100%;' + 'height:auto;' + 'min-width:0!important;' + 'min-height:0!important;' + 'max-width:none!important;' + 'max-height:none!important;' + 'image-orientation:0deg!important;\"';\n el.innerHTML = '';\n el.appendChild(img);\n });\n },\n resetPreview: function resetPreview() {\n forEach(this.previews, function (element) {\n var data = getData(element, DATA_PREVIEW);\n setStyle(element, {\n width: data.width,\n height: data.height\n });\n element.innerHTML = data.html;\n removeData(element, DATA_PREVIEW);\n });\n },\n preview: function preview() {\n var imageData = this.imageData,\n canvasData = this.canvasData,\n cropBoxData = this.cropBoxData;\n var cropBoxWidth = cropBoxData.width,\n cropBoxHeight = cropBoxData.height;\n var width = imageData.width,\n height = imageData.height;\n var left = cropBoxData.left - canvasData.left - imageData.left;\n var top = cropBoxData.top - canvasData.top - imageData.top;\n if (!this.cropped || this.disabled) {\n return;\n }\n setStyle(this.viewBoxImage, assign({\n width: width,\n height: height\n }, getTransforms(assign({\n translateX: -left,\n translateY: -top\n }, imageData))));\n forEach(this.previews, function (element) {\n var data = getData(element, DATA_PREVIEW);\n var originalWidth = data.width;\n var originalHeight = data.height;\n var newWidth = originalWidth;\n var newHeight = originalHeight;\n var ratio = 1;\n if (cropBoxWidth) {\n ratio = originalWidth / cropBoxWidth;\n newHeight = cropBoxHeight * ratio;\n }\n if (cropBoxHeight && newHeight > originalHeight) {\n ratio = originalHeight / cropBoxHeight;\n newWidth = cropBoxWidth * ratio;\n newHeight = originalHeight;\n }\n setStyle(element, {\n width: newWidth,\n height: newHeight\n });\n setStyle(element.getElementsByTagName('img')[0], assign({\n width: width * ratio,\n height: height * ratio\n }, getTransforms(assign({\n translateX: -left * ratio,\n translateY: -top * ratio\n }, imageData))));\n });\n }\n };\n\n var events = {\n bind: function bind() {\n var element = this.element,\n options = this.options,\n cropper = this.cropper;\n if (isFunction(options.cropstart)) {\n addListener(element, EVENT_CROP_START, options.cropstart);\n }\n if (isFunction(options.cropmove)) {\n addListener(element, EVENT_CROP_MOVE, options.cropmove);\n }\n if (isFunction(options.cropend)) {\n addListener(element, EVENT_CROP_END, options.cropend);\n }\n if (isFunction(options.crop)) {\n addListener(element, EVENT_CROP, options.crop);\n }\n if (isFunction(options.zoom)) {\n addListener(element, EVENT_ZOOM, options.zoom);\n }\n addListener(cropper, EVENT_POINTER_DOWN, this.onCropStart = this.cropStart.bind(this));\n if (options.zoomable && options.zoomOnWheel) {\n addListener(cropper, EVENT_WHEEL, this.onWheel = this.wheel.bind(this), {\n passive: false,\n capture: true\n });\n }\n if (options.toggleDragModeOnDblclick) {\n addListener(cropper, EVENT_DBLCLICK, this.onDblclick = this.dblclick.bind(this));\n }\n addListener(element.ownerDocument, EVENT_POINTER_MOVE, this.onCropMove = this.cropMove.bind(this));\n addListener(element.ownerDocument, EVENT_POINTER_UP, this.onCropEnd = this.cropEnd.bind(this));\n if (options.responsive) {\n addListener(window, EVENT_RESIZE, this.onResize = this.resize.bind(this));\n }\n },\n unbind: function unbind() {\n var element = this.element,\n options = this.options,\n cropper = this.cropper;\n if (isFunction(options.cropstart)) {\n removeListener(element, EVENT_CROP_START, options.cropstart);\n }\n if (isFunction(options.cropmove)) {\n removeListener(element, EVENT_CROP_MOVE, options.cropmove);\n }\n if (isFunction(options.cropend)) {\n removeListener(element, EVENT_CROP_END, options.cropend);\n }\n if (isFunction(options.crop)) {\n removeListener(element, EVENT_CROP, options.crop);\n }\n if (isFunction(options.zoom)) {\n removeListener(element, EVENT_ZOOM, options.zoom);\n }\n removeListener(cropper, EVENT_POINTER_DOWN, this.onCropStart);\n if (options.zoomable && options.zoomOnWheel) {\n removeListener(cropper, EVENT_WHEEL, this.onWheel, {\n passive: false,\n capture: true\n });\n }\n if (options.toggleDragModeOnDblclick) {\n removeListener(cropper, EVENT_DBLCLICK, this.onDblclick);\n }\n removeListener(element.ownerDocument, EVENT_POINTER_MOVE, this.onCropMove);\n removeListener(element.ownerDocument, EVENT_POINTER_UP, this.onCropEnd);\n if (options.responsive) {\n removeListener(window, EVENT_RESIZE, this.onResize);\n }\n }\n };\n\n var handlers = {\n resize: function resize() {\n if (this.disabled) {\n return;\n }\n var options = this.options,\n container = this.container,\n containerData = this.containerData;\n var ratioX = container.offsetWidth / containerData.width;\n var ratioY = container.offsetHeight / containerData.height;\n var ratio = Math.abs(ratioX - 1) > Math.abs(ratioY - 1) ? ratioX : ratioY;\n\n // Resize when width changed or height changed\n if (ratio !== 1) {\n var canvasData;\n var cropBoxData;\n if (options.restore) {\n canvasData = this.getCanvasData();\n cropBoxData = this.getCropBoxData();\n }\n this.render();\n if (options.restore) {\n this.setCanvasData(forEach(canvasData, function (n, i) {\n canvasData[i] = n * ratio;\n }));\n this.setCropBoxData(forEach(cropBoxData, function (n, i) {\n cropBoxData[i] = n * ratio;\n }));\n }\n }\n },\n dblclick: function dblclick() {\n if (this.disabled || this.options.dragMode === DRAG_MODE_NONE) {\n return;\n }\n this.setDragMode(hasClass(this.dragBox, CLASS_CROP) ? DRAG_MODE_MOVE : DRAG_MODE_CROP);\n },\n wheel: function wheel(event) {\n var _this = this;\n var ratio = Number(this.options.wheelZoomRatio) || 0.1;\n var delta = 1;\n if (this.disabled) {\n return;\n }\n event.preventDefault();\n\n // Limit wheel speed to prevent zoom too fast (#21)\n if (this.wheeling) {\n return;\n }\n this.wheeling = true;\n setTimeout(function () {\n _this.wheeling = false;\n }, 50);\n if (event.deltaY) {\n delta = event.deltaY > 0 ? 1 : -1;\n } else if (event.wheelDelta) {\n delta = -event.wheelDelta / 120;\n } else if (event.detail) {\n delta = event.detail > 0 ? 1 : -1;\n }\n this.zoom(-delta * ratio, event);\n },\n cropStart: function cropStart(event) {\n var buttons = event.buttons,\n button = event.button;\n if (this.disabled\n\n // Handle mouse event and pointer event and ignore touch event\n || (event.type === 'mousedown' || event.type === 'pointerdown' && event.pointerType === 'mouse') && (\n // No primary button (Usually the left button)\n isNumber(buttons) && buttons !== 1 || isNumber(button) && button !== 0\n\n // Open context menu\n || event.ctrlKey)) {\n return;\n }\n var options = this.options,\n pointers = this.pointers;\n var action;\n if (event.changedTouches) {\n // Handle touch event\n forEach(event.changedTouches, function (touch) {\n pointers[touch.identifier] = getPointer(touch);\n });\n } else {\n // Handle mouse event and pointer event\n pointers[event.pointerId || 0] = getPointer(event);\n }\n if (Object.keys(pointers).length > 1 && options.zoomable && options.zoomOnTouch) {\n action = ACTION_ZOOM;\n } else {\n action = getData(event.target, DATA_ACTION);\n }\n if (!REGEXP_ACTIONS.test(action)) {\n return;\n }\n if (dispatchEvent(this.element, EVENT_CROP_START, {\n originalEvent: event,\n action: action\n }) === false) {\n return;\n }\n\n // This line is required for preventing page zooming in iOS browsers\n event.preventDefault();\n this.action = action;\n this.cropping = false;\n if (action === ACTION_CROP) {\n this.cropping = true;\n addClass(this.dragBox, CLASS_MODAL);\n }\n },\n cropMove: function cropMove(event) {\n var action = this.action;\n if (this.disabled || !action) {\n return;\n }\n var pointers = this.pointers;\n event.preventDefault();\n if (dispatchEvent(this.element, EVENT_CROP_MOVE, {\n originalEvent: event,\n action: action\n }) === false) {\n return;\n }\n if (event.changedTouches) {\n forEach(event.changedTouches, function (touch) {\n // The first parameter should not be undefined (#432)\n assign(pointers[touch.identifier] || {}, getPointer(touch, true));\n });\n } else {\n assign(pointers[event.pointerId || 0] || {}, getPointer(event, true));\n }\n this.change(event);\n },\n cropEnd: function cropEnd(event) {\n if (this.disabled) {\n return;\n }\n var action = this.action,\n pointers = this.pointers;\n if (event.changedTouches) {\n forEach(event.changedTouches, function (touch) {\n delete pointers[touch.identifier];\n });\n } else {\n delete pointers[event.pointerId || 0];\n }\n if (!action) {\n return;\n }\n event.preventDefault();\n if (!Object.keys(pointers).length) {\n this.action = '';\n }\n if (this.cropping) {\n this.cropping = false;\n toggleClass(this.dragBox, CLASS_MODAL, this.cropped && this.options.modal);\n }\n dispatchEvent(this.element, EVENT_CROP_END, {\n originalEvent: event,\n action: action\n });\n }\n };\n\n var change = {\n change: function change(event) {\n var options = this.options,\n canvasData = this.canvasData,\n containerData = this.containerData,\n cropBoxData = this.cropBoxData,\n pointers = this.pointers;\n var action = this.action;\n var aspectRatio = options.aspectRatio;\n var left = cropBoxData.left,\n top = cropBoxData.top,\n width = cropBoxData.width,\n height = cropBoxData.height;\n var right = left + width;\n var bottom = top + height;\n var minLeft = 0;\n var minTop = 0;\n var maxWidth = containerData.width;\n var maxHeight = containerData.height;\n var renderable = true;\n var offset;\n\n // Locking aspect ratio in \"free mode\" by holding shift key\n if (!aspectRatio && event.shiftKey) {\n aspectRatio = width && height ? width / height : 1;\n }\n if (this.limited) {\n minLeft = cropBoxData.minLeft;\n minTop = cropBoxData.minTop;\n maxWidth = minLeft + Math.min(containerData.width, canvasData.width, canvasData.left + canvasData.width);\n maxHeight = minTop + Math.min(containerData.height, canvasData.height, canvasData.top + canvasData.height);\n }\n var pointer = pointers[Object.keys(pointers)[0]];\n var range = {\n x: pointer.endX - pointer.startX,\n y: pointer.endY - pointer.startY\n };\n var check = function check(side) {\n switch (side) {\n case ACTION_EAST:\n if (right + range.x > maxWidth) {\n range.x = maxWidth - right;\n }\n break;\n case ACTION_WEST:\n if (left + range.x < minLeft) {\n range.x = minLeft - left;\n }\n break;\n case ACTION_NORTH:\n if (top + range.y < minTop) {\n range.y = minTop - top;\n }\n break;\n case ACTION_SOUTH:\n if (bottom + range.y > maxHeight) {\n range.y = maxHeight - bottom;\n }\n break;\n }\n };\n switch (action) {\n // Move crop box\n case ACTION_ALL:\n left += range.x;\n top += range.y;\n break;\n\n // Resize crop box\n case ACTION_EAST:\n if (range.x >= 0 && (right >= maxWidth || aspectRatio && (top <= minTop || bottom >= maxHeight))) {\n renderable = false;\n break;\n }\n check(ACTION_EAST);\n width += range.x;\n if (width < 0) {\n action = ACTION_WEST;\n width = -width;\n left -= width;\n }\n if (aspectRatio) {\n height = width / aspectRatio;\n top += (cropBoxData.height - height) / 2;\n }\n break;\n case ACTION_NORTH:\n if (range.y <= 0 && (top <= minTop || aspectRatio && (left <= minLeft || right >= maxWidth))) {\n renderable = false;\n break;\n }\n check(ACTION_NORTH);\n height -= range.y;\n top += range.y;\n if (height < 0) {\n action = ACTION_SOUTH;\n height = -height;\n top -= height;\n }\n if (aspectRatio) {\n width = height * aspectRatio;\n left += (cropBoxData.width - width) / 2;\n }\n break;\n case ACTION_WEST:\n if (range.x <= 0 && (left <= minLeft || aspectRatio && (top <= minTop || bottom >= maxHeight))) {\n renderable = false;\n break;\n }\n check(ACTION_WEST);\n width -= range.x;\n left += range.x;\n if (width < 0) {\n action = ACTION_EAST;\n width = -width;\n left -= width;\n }\n if (aspectRatio) {\n height = width / aspectRatio;\n top += (cropBoxData.height - height) / 2;\n }\n break;\n case ACTION_SOUTH:\n if (range.y >= 0 && (bottom >= maxHeight || aspectRatio && (left <= minLeft || right >= maxWidth))) {\n renderable = false;\n break;\n }\n check(ACTION_SOUTH);\n height += range.y;\n if (height < 0) {\n action = ACTION_NORTH;\n height = -height;\n top -= height;\n }\n if (aspectRatio) {\n width = height * aspectRatio;\n left += (cropBoxData.width - width) / 2;\n }\n break;\n case ACTION_NORTH_EAST:\n if (aspectRatio) {\n if (range.y <= 0 && (top <= minTop || right >= maxWidth)) {\n renderable = false;\n break;\n }\n check(ACTION_NORTH);\n height -= range.y;\n top += range.y;\n width = height * aspectRatio;\n } else {\n check(ACTION_NORTH);\n check(ACTION_EAST);\n if (range.x >= 0) {\n if (right < maxWidth) {\n width += range.x;\n } else if (range.y <= 0 && top <= minTop) {\n renderable = false;\n }\n } else {\n width += range.x;\n }\n if (range.y <= 0) {\n if (top > minTop) {\n height -= range.y;\n top += range.y;\n }\n } else {\n height -= range.y;\n top += range.y;\n }\n }\n if (width < 0 && height < 0) {\n action = ACTION_SOUTH_WEST;\n height = -height;\n width = -width;\n top -= height;\n left -= width;\n } else if (width < 0) {\n action = ACTION_NORTH_WEST;\n width = -width;\n left -= width;\n } else if (height < 0) {\n action = ACTION_SOUTH_EAST;\n height = -height;\n top -= height;\n }\n break;\n case ACTION_NORTH_WEST:\n if (aspectRatio) {\n if (range.y <= 0 && (top <= minTop || left <= minLeft)) {\n renderable = false;\n break;\n }\n check(ACTION_NORTH);\n height -= range.y;\n top += range.y;\n width = height * aspectRatio;\n left += cropBoxData.width - width;\n } else {\n check(ACTION_NORTH);\n check(ACTION_WEST);\n if (range.x <= 0) {\n if (left > minLeft) {\n width -= range.x;\n left += range.x;\n } else if (range.y <= 0 && top <= minTop) {\n renderable = false;\n }\n } else {\n width -= range.x;\n left += range.x;\n }\n if (range.y <= 0) {\n if (top > minTop) {\n height -= range.y;\n top += range.y;\n }\n } else {\n height -= range.y;\n top += range.y;\n }\n }\n if (width < 0 && height < 0) {\n action = ACTION_SOUTH_EAST;\n height = -height;\n width = -width;\n top -= height;\n left -= width;\n } else if (width < 0) {\n action = ACTION_NORTH_EAST;\n width = -width;\n left -= width;\n } else if (height < 0) {\n action = ACTION_SOUTH_WEST;\n height = -height;\n top -= height;\n }\n break;\n case ACTION_SOUTH_WEST:\n if (aspectRatio) {\n if (range.x <= 0 && (left <= minLeft || bottom >= maxHeight)) {\n renderable = false;\n break;\n }\n check(ACTION_WEST);\n width -= range.x;\n left += range.x;\n height = width / aspectRatio;\n } else {\n check(ACTION_SOUTH);\n check(ACTION_WEST);\n if (range.x <= 0) {\n if (left > minLeft) {\n width -= range.x;\n left += range.x;\n } else if (range.y >= 0 && bottom >= maxHeight) {\n renderable = false;\n }\n } else {\n width -= range.x;\n left += range.x;\n }\n if (range.y >= 0) {\n if (bottom < maxHeight) {\n height += range.y;\n }\n } else {\n height += range.y;\n }\n }\n if (width < 0 && height < 0) {\n action = ACTION_NORTH_EAST;\n height = -height;\n width = -width;\n top -= height;\n left -= width;\n } else if (width < 0) {\n action = ACTION_SOUTH_EAST;\n width = -width;\n left -= width;\n } else if (height < 0) {\n action = ACTION_NORTH_WEST;\n height = -height;\n top -= height;\n }\n break;\n case ACTION_SOUTH_EAST:\n if (aspectRatio) {\n if (range.x >= 0 && (right >= maxWidth || bottom >= maxHeight)) {\n renderable = false;\n break;\n }\n check(ACTION_EAST);\n width += range.x;\n height = width / aspectRatio;\n } else {\n check(ACTION_SOUTH);\n check(ACTION_EAST);\n if (range.x >= 0) {\n if (right < maxWidth) {\n width += range.x;\n } else if (range.y >= 0 && bottom >= maxHeight) {\n renderable = false;\n }\n } else {\n width += range.x;\n }\n if (range.y >= 0) {\n if (bottom < maxHeight) {\n height += range.y;\n }\n } else {\n height += range.y;\n }\n }\n if (width < 0 && height < 0) {\n action = ACTION_NORTH_WEST;\n height = -height;\n width = -width;\n top -= height;\n left -= width;\n } else if (width < 0) {\n action = ACTION_SOUTH_WEST;\n width = -width;\n left -= width;\n } else if (height < 0) {\n action = ACTION_NORTH_EAST;\n height = -height;\n top -= height;\n }\n break;\n\n // Move canvas\n case ACTION_MOVE:\n this.move(range.x, range.y);\n renderable = false;\n break;\n\n // Zoom canvas\n case ACTION_ZOOM:\n this.zoom(getMaxZoomRatio(pointers), event);\n renderable = false;\n break;\n\n // Create crop box\n case ACTION_CROP:\n if (!range.x || !range.y) {\n renderable = false;\n break;\n }\n offset = getOffset(this.cropper);\n left = pointer.startX - offset.left;\n top = pointer.startY - offset.top;\n width = cropBoxData.minWidth;\n height = cropBoxData.minHeight;\n if (range.x > 0) {\n action = range.y > 0 ? ACTION_SOUTH_EAST : ACTION_NORTH_EAST;\n } else if (range.x < 0) {\n left -= width;\n action = range.y > 0 ? ACTION_SOUTH_WEST : ACTION_NORTH_WEST;\n }\n if (range.y < 0) {\n top -= height;\n }\n\n // Show the crop box if is hidden\n if (!this.cropped) {\n removeClass(this.cropBox, CLASS_HIDDEN);\n this.cropped = true;\n if (this.limited) {\n this.limitCropBox(true, true);\n }\n }\n break;\n }\n if (renderable) {\n cropBoxData.width = width;\n cropBoxData.height = height;\n cropBoxData.left = left;\n cropBoxData.top = top;\n this.action = action;\n this.renderCropBox();\n }\n\n // Override\n forEach(pointers, function (p) {\n p.startX = p.endX;\n p.startY = p.endY;\n });\n }\n };\n\n var methods = {\n // Show the crop box manually\n crop: function crop() {\n if (this.ready && !this.cropped && !this.disabled) {\n this.cropped = true;\n this.limitCropBox(true, true);\n if (this.options.modal) {\n addClass(this.dragBox, CLASS_MODAL);\n }\n removeClass(this.cropBox, CLASS_HIDDEN);\n this.setCropBoxData(this.initialCropBoxData);\n }\n return this;\n },\n // Reset the image and crop box to their initial states\n reset: function reset() {\n if (this.ready && !this.disabled) {\n this.imageData = assign({}, this.initialImageData);\n this.canvasData = assign({}, this.initialCanvasData);\n this.cropBoxData = assign({}, this.initialCropBoxData);\n this.renderCanvas();\n if (this.cropped) {\n this.renderCropBox();\n }\n }\n return this;\n },\n // Clear the crop box\n clear: function clear() {\n if (this.cropped && !this.disabled) {\n assign(this.cropBoxData, {\n left: 0,\n top: 0,\n width: 0,\n height: 0\n });\n this.cropped = false;\n this.renderCropBox();\n this.limitCanvas(true, true);\n\n // Render canvas after crop box rendered\n this.renderCanvas();\n removeClass(this.dragBox, CLASS_MODAL);\n addClass(this.cropBox, CLASS_HIDDEN);\n }\n return this;\n },\n /**\n * Replace the image's src and rebuild the cropper\n * @param {string} url - The new URL.\n * @param {boolean} [hasSameSize] - Indicate if the new image has the same size as the old one.\n * @returns {Cropper} this\n */\n replace: function replace(url) {\n var hasSameSize = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;\n if (!this.disabled && url) {\n if (this.isImg) {\n this.element.src = url;\n }\n if (hasSameSize) {\n this.url = url;\n this.image.src = url;\n if (this.ready) {\n this.viewBoxImage.src = url;\n forEach(this.previews, function (element) {\n element.getElementsByTagName('img')[0].src = url;\n });\n }\n } else {\n if (this.isImg) {\n this.replaced = true;\n }\n this.options.data = null;\n this.uncreate();\n this.load(url);\n }\n }\n return this;\n },\n // Enable (unfreeze) the cropper\n enable: function enable() {\n if (this.ready && this.disabled) {\n this.disabled = false;\n removeClass(this.cropper, CLASS_DISABLED);\n }\n return this;\n },\n // Disable (freeze) the cropper\n disable: function disable() {\n if (this.ready && !this.disabled) {\n this.disabled = true;\n addClass(this.cropper, CLASS_DISABLED);\n }\n return this;\n },\n /**\n * Destroy the cropper and remove the instance from the image\n * @returns {Cropper} this\n */\n destroy: function destroy() {\n var element = this.element;\n if (!element[NAMESPACE]) {\n return this;\n }\n element[NAMESPACE] = undefined;\n if (this.isImg && this.replaced) {\n element.src = this.originalUrl;\n }\n this.uncreate();\n return this;\n },\n /**\n * Move the canvas with relative offsets\n * @param {number} offsetX - The relative offset distance on the x-axis.\n * @param {number} [offsetY=offsetX] - The relative offset distance on the y-axis.\n * @returns {Cropper} this\n */\n move: function move(offsetX) {\n var offsetY = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : offsetX;\n var _this$canvasData = this.canvasData,\n left = _this$canvasData.left,\n top = _this$canvasData.top;\n return this.moveTo(isUndefined(offsetX) ? offsetX : left + Number(offsetX), isUndefined(offsetY) ? offsetY : top + Number(offsetY));\n },\n /**\n * Move the canvas to an absolute point\n * @param {number} x - The x-axis coordinate.\n * @param {number} [y=x] - The y-axis coordinate.\n * @returns {Cropper} this\n */\n moveTo: function moveTo(x) {\n var y = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : x;\n var canvasData = this.canvasData;\n var changed = false;\n x = Number(x);\n y = Number(y);\n if (this.ready && !this.disabled && this.options.movable) {\n if (isNumber(x)) {\n canvasData.left = x;\n changed = true;\n }\n if (isNumber(y)) {\n canvasData.top = y;\n changed = true;\n }\n if (changed) {\n this.renderCanvas(true);\n }\n }\n return this;\n },\n /**\n * Zoom the canvas with a relative ratio\n * @param {number} ratio - The target ratio.\n * @param {Event} _originalEvent - The original event if any.\n * @returns {Cropper} this\n */\n zoom: function zoom(ratio, _originalEvent) {\n var canvasData = this.canvasData;\n ratio = Number(ratio);\n if (ratio < 0) {\n ratio = 1 / (1 - ratio);\n } else {\n ratio = 1 + ratio;\n }\n return this.zoomTo(canvasData.width * ratio / canvasData.naturalWidth, null, _originalEvent);\n },\n /**\n * Zoom the canvas to an absolute ratio\n * @param {number} ratio - The target ratio.\n * @param {Object} pivot - The zoom pivot point coordinate.\n * @param {Event} _originalEvent - The original event if any.\n * @returns {Cropper} this\n */\n zoomTo: function zoomTo(ratio, pivot, _originalEvent) {\n var options = this.options,\n canvasData = this.canvasData;\n var width = canvasData.width,\n height = canvasData.height,\n naturalWidth = canvasData.naturalWidth,\n naturalHeight = canvasData.naturalHeight;\n ratio = Number(ratio);\n if (ratio >= 0 && this.ready && !this.disabled && options.zoomable) {\n var newWidth = naturalWidth * ratio;\n var newHeight = naturalHeight * ratio;\n if (dispatchEvent(this.element, EVENT_ZOOM, {\n ratio: ratio,\n oldRatio: width / naturalWidth,\n originalEvent: _originalEvent\n }) === false) {\n return this;\n }\n if (_originalEvent) {\n var pointers = this.pointers;\n var offset = getOffset(this.cropper);\n var center = pointers && Object.keys(pointers).length ? getPointersCenter(pointers) : {\n pageX: _originalEvent.pageX,\n pageY: _originalEvent.pageY\n };\n\n // Zoom from the triggering point of the event\n canvasData.left -= (newWidth - width) * ((center.pageX - offset.left - canvasData.left) / width);\n canvasData.top -= (newHeight - height) * ((center.pageY - offset.top - canvasData.top) / height);\n } else if (isPlainObject(pivot) && isNumber(pivot.x) && isNumber(pivot.y)) {\n canvasData.left -= (newWidth - width) * ((pivot.x - canvasData.left) / width);\n canvasData.top -= (newHeight - height) * ((pivot.y - canvasData.top) / height);\n } else {\n // Zoom from the center of the canvas\n canvasData.left -= (newWidth - width) / 2;\n canvasData.top -= (newHeight - height) / 2;\n }\n canvasData.width = newWidth;\n canvasData.height = newHeight;\n this.renderCanvas(true);\n }\n return this;\n },\n /**\n * Rotate the canvas with a relative degree\n * @param {number} degree - The rotate degree.\n * @returns {Cropper} this\n */\n rotate: function rotate(degree) {\n return this.rotateTo((this.imageData.rotate || 0) + Number(degree));\n },\n /**\n * Rotate the canvas to an absolute degree\n * @param {number} degree - The rotate degree.\n * @returns {Cropper} this\n */\n rotateTo: function rotateTo(degree) {\n degree = Number(degree);\n if (isNumber(degree) && this.ready && !this.disabled && this.options.rotatable) {\n this.imageData.rotate = degree % 360;\n this.renderCanvas(true, true);\n }\n return this;\n },\n /**\n * Scale the image on the x-axis.\n * @param {number} scaleX - The scale ratio on the x-axis.\n * @returns {Cropper} this\n */\n scaleX: function scaleX(_scaleX) {\n var scaleY = this.imageData.scaleY;\n return this.scale(_scaleX, isNumber(scaleY) ? scaleY : 1);\n },\n /**\n * Scale the image on the y-axis.\n * @param {number} scaleY - The scale ratio on the y-axis.\n * @returns {Cropper} this\n */\n scaleY: function scaleY(_scaleY) {\n var scaleX = this.imageData.scaleX;\n return this.scale(isNumber(scaleX) ? scaleX : 1, _scaleY);\n },\n /**\n * Scale the image\n * @param {number} scaleX - The scale ratio on the x-axis.\n * @param {number} [scaleY=scaleX] - The scale ratio on the y-axis.\n * @returns {Cropper} this\n */\n scale: function scale(scaleX) {\n var scaleY = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : scaleX;\n var imageData = this.imageData;\n var transformed = false;\n scaleX = Number(scaleX);\n scaleY = Number(scaleY);\n if (this.ready && !this.disabled && this.options.scalable) {\n if (isNumber(scaleX)) {\n imageData.scaleX = scaleX;\n transformed = true;\n }\n if (isNumber(scaleY)) {\n imageData.scaleY = scaleY;\n transformed = true;\n }\n if (transformed) {\n this.renderCanvas(true, true);\n }\n }\n return this;\n },\n /**\n * Get the cropped area position and size data (base on the original image)\n * @param {boolean} [rounded=false] - Indicate if round the data values or not.\n * @returns {Object} The result cropped data.\n */\n getData: function getData() {\n var rounded = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;\n var options = this.options,\n imageData = this.imageData,\n canvasData = this.canvasData,\n cropBoxData = this.cropBoxData;\n var data;\n if (this.ready && this.cropped) {\n data = {\n x: cropBoxData.left - canvasData.left,\n y: cropBoxData.top - canvasData.top,\n width: cropBoxData.width,\n height: cropBoxData.height\n };\n var ratio = imageData.width / imageData.naturalWidth;\n forEach(data, function (n, i) {\n data[i] = n / ratio;\n });\n if (rounded) {\n // In case rounding off leads to extra 1px in right or bottom border\n // we should round the top-left corner and the dimension (#343).\n var bottom = Math.round(data.y + data.height);\n var right = Math.round(data.x + data.width);\n data.x = Math.round(data.x);\n data.y = Math.round(data.y);\n data.width = right - data.x;\n data.height = bottom - data.y;\n }\n } else {\n data = {\n x: 0,\n y: 0,\n width: 0,\n height: 0\n };\n }\n if (options.rotatable) {\n data.rotate = imageData.rotate || 0;\n }\n if (options.scalable) {\n data.scaleX = imageData.scaleX || 1;\n data.scaleY = imageData.scaleY || 1;\n }\n return data;\n },\n /**\n * Set the cropped area position and size with new data\n * @param {Object} data - The new data.\n * @returns {Cropper} this\n */\n setData: function setData(data) {\n var options = this.options,\n imageData = this.imageData,\n canvasData = this.canvasData;\n var cropBoxData = {};\n if (this.ready && !this.disabled && isPlainObject(data)) {\n var transformed = false;\n if (options.rotatable) {\n if (isNumber(data.rotate) && data.rotate !== imageData.rotate) {\n imageData.rotate = data.rotate;\n transformed = true;\n }\n }\n if (options.scalable) {\n if (isNumber(data.scaleX) && data.scaleX !== imageData.scaleX) {\n imageData.scaleX = data.scaleX;\n transformed = true;\n }\n if (isNumber(data.scaleY) && data.scaleY !== imageData.scaleY) {\n imageData.scaleY = data.scaleY;\n transformed = true;\n }\n }\n if (transformed) {\n this.renderCanvas(true, true);\n }\n var ratio = imageData.width / imageData.naturalWidth;\n if (isNumber(data.x)) {\n cropBoxData.left = data.x * ratio + canvasData.left;\n }\n if (isNumber(data.y)) {\n cropBoxData.top = data.y * ratio + canvasData.top;\n }\n if (isNumber(data.width)) {\n cropBoxData.width = data.width * ratio;\n }\n if (isNumber(data.height)) {\n cropBoxData.height = data.height * ratio;\n }\n this.setCropBoxData(cropBoxData);\n }\n return this;\n },\n /**\n * Get the container size data.\n * @returns {Object} The result container data.\n */\n getContainerData: function getContainerData() {\n return this.ready ? assign({}, this.containerData) : {};\n },\n /**\n * Get the image position and size data.\n * @returns {Object} The result image data.\n */\n getImageData: function getImageData() {\n return this.sized ? assign({}, this.imageData) : {};\n },\n /**\n * Get the canvas position and size data.\n * @returns {Object} The result canvas data.\n */\n getCanvasData: function getCanvasData() {\n var canvasData = this.canvasData;\n var data = {};\n if (this.ready) {\n forEach(['left', 'top', 'width', 'height', 'naturalWidth', 'naturalHeight'], function (n) {\n data[n] = canvasData[n];\n });\n }\n return data;\n },\n /**\n * Set the canvas position and size with new data.\n * @param {Object} data - The new canvas data.\n * @returns {Cropper} this\n */\n setCanvasData: function setCanvasData(data) {\n var canvasData = this.canvasData;\n var aspectRatio = canvasData.aspectRatio;\n if (this.ready && !this.disabled && isPlainObject(data)) {\n if (isNumber(data.left)) {\n canvasData.left = data.left;\n }\n if (isNumber(data.top)) {\n canvasData.top = data.top;\n }\n if (isNumber(data.width)) {\n canvasData.width = data.width;\n canvasData.height = data.width / aspectRatio;\n } else if (isNumber(data.height)) {\n canvasData.height = data.height;\n canvasData.width = data.height * aspectRatio;\n }\n this.renderCanvas(true);\n }\n return this;\n },\n /**\n * Get the crop box position and size data.\n * @returns {Object} The result crop box data.\n */\n getCropBoxData: function getCropBoxData() {\n var cropBoxData = this.cropBoxData;\n var data;\n if (this.ready && this.cropped) {\n data = {\n left: cropBoxData.left,\n top: cropBoxData.top,\n width: cropBoxData.width,\n height: cropBoxData.height\n };\n }\n return data || {};\n },\n /**\n * Set the crop box position and size with new data.\n * @param {Object} data - The new crop box data.\n * @returns {Cropper} this\n */\n setCropBoxData: function setCropBoxData(data) {\n var cropBoxData = this.cropBoxData;\n var aspectRatio = this.options.aspectRatio;\n var widthChanged;\n var heightChanged;\n if (this.ready && this.cropped && !this.disabled && isPlainObject(data)) {\n if (isNumber(data.left)) {\n cropBoxData.left = data.left;\n }\n if (isNumber(data.top)) {\n cropBoxData.top = data.top;\n }\n if (isNumber(data.width) && data.width !== cropBoxData.width) {\n widthChanged = true;\n cropBoxData.width = data.width;\n }\n if (isNumber(data.height) && data.height !== cropBoxData.height) {\n heightChanged = true;\n cropBoxData.height = data.height;\n }\n if (aspectRatio) {\n if (widthChanged) {\n cropBoxData.height = cropBoxData.width / aspectRatio;\n } else if (heightChanged) {\n cropBoxData.width = cropBoxData.height * aspectRatio;\n }\n }\n this.renderCropBox();\n }\n return this;\n },\n /**\n * Get a canvas drawn the cropped image.\n * @param {Object} [options={}] - The config options.\n * @returns {HTMLCanvasElement} - The result canvas.\n */\n getCroppedCanvas: function getCroppedCanvas() {\n var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};\n if (!this.ready || !window.HTMLCanvasElement) {\n return null;\n }\n var canvasData = this.canvasData;\n var source = getSourceCanvas(this.image, this.imageData, canvasData, options);\n\n // Returns the source canvas if it is not cropped.\n if (!this.cropped) {\n return source;\n }\n var _this$getData = this.getData(options.rounded),\n initialX = _this$getData.x,\n initialY = _this$getData.y,\n initialWidth = _this$getData.width,\n initialHeight = _this$getData.height;\n var ratio = source.width / Math.floor(canvasData.naturalWidth);\n if (ratio !== 1) {\n initialX *= ratio;\n initialY *= ratio;\n initialWidth *= ratio;\n initialHeight *= ratio;\n }\n var aspectRatio = initialWidth / initialHeight;\n var maxSizes = getAdjustedSizes({\n aspectRatio: aspectRatio,\n width: options.maxWidth || Infinity,\n height: options.maxHeight || Infinity\n });\n var minSizes = getAdjustedSizes({\n aspectRatio: aspectRatio,\n width: options.minWidth || 0,\n height: options.minHeight || 0\n }, 'cover');\n var _getAdjustedSizes = getAdjustedSizes({\n aspectRatio: aspectRatio,\n width: options.width || (ratio !== 1 ? source.width : initialWidth),\n height: options.height || (ratio !== 1 ? source.height : initialHeight)\n }),\n width = _getAdjustedSizes.width,\n height = _getAdjustedSizes.height;\n width = Math.min(maxSizes.width, Math.max(minSizes.width, width));\n height = Math.min(maxSizes.height, Math.max(minSizes.height, height));\n var canvas = document.createElement('canvas');\n var context = canvas.getContext('2d');\n canvas.width = normalizeDecimalNumber(width);\n canvas.height = normalizeDecimalNumber(height);\n context.fillStyle = options.fillColor || 'transparent';\n context.fillRect(0, 0, width, height);\n var _options$imageSmoothi = options.imageSmoothingEnabled,\n imageSmoothingEnabled = _options$imageSmoothi === void 0 ? true : _options$imageSmoothi,\n imageSmoothingQuality = options.imageSmoothingQuality;\n context.imageSmoothingEnabled = imageSmoothingEnabled;\n if (imageSmoothingQuality) {\n context.imageSmoothingQuality = imageSmoothingQuality;\n }\n\n // https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D.drawImage\n var sourceWidth = source.width;\n var sourceHeight = source.height;\n\n // Source canvas parameters\n var srcX = initialX;\n var srcY = initialY;\n var srcWidth;\n var srcHeight;\n\n // Destination canvas parameters\n var dstX;\n var dstY;\n var dstWidth;\n var dstHeight;\n if (srcX <= -initialWidth || srcX > sourceWidth) {\n srcX = 0;\n srcWidth = 0;\n dstX = 0;\n dstWidth = 0;\n } else if (srcX <= 0) {\n dstX = -srcX;\n srcX = 0;\n srcWidth = Math.min(sourceWidth, initialWidth + srcX);\n dstWidth = srcWidth;\n } else if (srcX <= sourceWidth) {\n dstX = 0;\n srcWidth = Math.min(initialWidth, sourceWidth - srcX);\n dstWidth = srcWidth;\n }\n if (srcWidth <= 0 || srcY <= -initialHeight || srcY > sourceHeight) {\n srcY = 0;\n srcHeight = 0;\n dstY = 0;\n dstHeight = 0;\n } else if (srcY <= 0) {\n dstY = -srcY;\n srcY = 0;\n srcHeight = Math.min(sourceHeight, initialHeight + srcY);\n dstHeight = srcHeight;\n } else if (srcY <= sourceHeight) {\n dstY = 0;\n srcHeight = Math.min(initialHeight, sourceHeight - srcY);\n dstHeight = srcHeight;\n }\n var params = [srcX, srcY, srcWidth, srcHeight];\n\n // Avoid \"IndexSizeError\"\n if (dstWidth > 0 && dstHeight > 0) {\n var scale = width / initialWidth;\n params.push(dstX * scale, dstY * scale, dstWidth * scale, dstHeight * scale);\n }\n\n // All the numerical parameters should be integer for `drawImage`\n // https://github.com/fengyuanchen/cropper/issues/476\n context.drawImage.apply(context, [source].concat(_toConsumableArray(params.map(function (param) {\n return Math.floor(normalizeDecimalNumber(param));\n }))));\n return canvas;\n },\n /**\n * Change the aspect ratio of the crop box.\n * @param {number} aspectRatio - The new aspect ratio.\n * @returns {Cropper} this\n */\n setAspectRatio: function setAspectRatio(aspectRatio) {\n var options = this.options;\n if (!this.disabled && !isUndefined(aspectRatio)) {\n // 0 -> NaN\n options.aspectRatio = Math.max(0, aspectRatio) || NaN;\n if (this.ready) {\n this.initCropBox();\n if (this.cropped) {\n this.renderCropBox();\n }\n }\n }\n return this;\n },\n /**\n * Change the drag mode.\n * @param {string} mode - The new drag mode.\n * @returns {Cropper} this\n */\n setDragMode: function setDragMode(mode) {\n var options = this.options,\n dragBox = this.dragBox,\n face = this.face;\n if (this.ready && !this.disabled) {\n var croppable = mode === DRAG_MODE_CROP;\n var movable = options.movable && mode === DRAG_MODE_MOVE;\n mode = croppable || movable ? mode : DRAG_MODE_NONE;\n options.dragMode = mode;\n setData(dragBox, DATA_ACTION, mode);\n toggleClass(dragBox, CLASS_CROP, croppable);\n toggleClass(dragBox, CLASS_MOVE, movable);\n if (!options.cropBoxMovable) {\n // Sync drag mode to crop box when it is not movable\n setData(face, DATA_ACTION, mode);\n toggleClass(face, CLASS_CROP, croppable);\n toggleClass(face, CLASS_MOVE, movable);\n }\n }\n return this;\n }\n };\n\n var AnotherCropper = WINDOW.Cropper;\n var Cropper = /*#__PURE__*/function () {\n /**\n * Create a new Cropper.\n * @param {Element} element - The target element for cropping.\n * @param {Object} [options={}] - The configuration options.\n */\n function Cropper(element) {\n var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};\n _classCallCheck(this, Cropper);\n if (!element || !REGEXP_TAG_NAME.test(element.tagName)) {\n throw new Error('The first argument is required and must be an or element.');\n }\n this.element = element;\n this.options = assign({}, DEFAULTS, isPlainObject(options) && options);\n this.cropped = false;\n this.disabled = false;\n this.pointers = {};\n this.ready = false;\n this.reloading = false;\n this.replaced = false;\n this.sized = false;\n this.sizing = false;\n this.init();\n }\n return _createClass(Cropper, [{\n key: \"init\",\n value: function init() {\n var element = this.element;\n var tagName = element.tagName.toLowerCase();\n var url;\n if (element[NAMESPACE]) {\n return;\n }\n element[NAMESPACE] = this;\n if (tagName === 'img') {\n this.isImg = true;\n\n // e.g.: \"img/picture.jpg\"\n url = element.getAttribute('src') || '';\n this.originalUrl = url;\n\n // Stop when it's a blank image\n if (!url) {\n return;\n }\n\n // e.g.: \"https://example.com/img/picture.jpg\"\n url = element.src;\n } else if (tagName === 'canvas' && window.HTMLCanvasElement) {\n url = element.toDataURL();\n }\n this.load(url);\n }\n }, {\n key: \"load\",\n value: function load(url) {\n var _this = this;\n if (!url) {\n return;\n }\n this.url = url;\n this.imageData = {};\n var element = this.element,\n options = this.options;\n if (!options.rotatable && !options.scalable) {\n options.checkOrientation = false;\n }\n\n // Only IE10+ supports Typed Arrays\n if (!options.checkOrientation || !window.ArrayBuffer) {\n this.clone();\n return;\n }\n\n // Detect the mime type of the image directly if it is a Data URL\n if (REGEXP_DATA_URL.test(url)) {\n // Read ArrayBuffer from Data URL of JPEG images directly for better performance\n if (REGEXP_DATA_URL_JPEG.test(url)) {\n this.read(dataURLToArrayBuffer(url));\n } else {\n // Only a JPEG image may contains Exif Orientation information,\n // the rest types of Data URLs are not necessary to check orientation at all.\n this.clone();\n }\n return;\n }\n\n // 1. Detect the mime type of the image by a XMLHttpRequest.\n // 2. Load the image as ArrayBuffer for reading orientation if its a JPEG image.\n var xhr = new XMLHttpRequest();\n var clone = this.clone.bind(this);\n this.reloading = true;\n this.xhr = xhr;\n\n // 1. Cross origin requests are only supported for protocol schemes:\n // http, https, data, chrome, chrome-extension.\n // 2. Access to XMLHttpRequest from a Data URL will be blocked by CORS policy\n // in some browsers as IE11 and Safari.\n xhr.onabort = clone;\n xhr.onerror = clone;\n xhr.ontimeout = clone;\n xhr.onprogress = function () {\n // Abort the request directly if it not a JPEG image for better performance\n if (xhr.getResponseHeader('content-type') !== MIME_TYPE_JPEG) {\n xhr.abort();\n }\n };\n xhr.onload = function () {\n _this.read(xhr.response);\n };\n xhr.onloadend = function () {\n _this.reloading = false;\n _this.xhr = null;\n };\n\n // Bust cache when there is a \"crossOrigin\" property to avoid browser cache error\n if (options.checkCrossOrigin && isCrossOriginURL(url) && element.crossOrigin) {\n url = addTimestamp(url);\n }\n\n // The third parameter is required for avoiding side-effect (#682)\n xhr.open('GET', url, true);\n xhr.responseType = 'arraybuffer';\n xhr.withCredentials = element.crossOrigin === 'use-credentials';\n xhr.send();\n }\n }, {\n key: \"read\",\n value: function read(arrayBuffer) {\n var options = this.options,\n imageData = this.imageData;\n\n // Reset the orientation value to its default value 1\n // as some iOS browsers will render image with its orientation\n var orientation = resetAndGetOrientation(arrayBuffer);\n var rotate = 0;\n var scaleX = 1;\n var scaleY = 1;\n if (orientation > 1) {\n // Generate a new URL which has the default orientation value\n this.url = arrayBufferToDataURL(arrayBuffer, MIME_TYPE_JPEG);\n var _parseOrientation = parseOrientation(orientation);\n rotate = _parseOrientation.rotate;\n scaleX = _parseOrientation.scaleX;\n scaleY = _parseOrientation.scaleY;\n }\n if (options.rotatable) {\n imageData.rotate = rotate;\n }\n if (options.scalable) {\n imageData.scaleX = scaleX;\n imageData.scaleY = scaleY;\n }\n this.clone();\n }\n }, {\n key: \"clone\",\n value: function clone() {\n var element = this.element,\n url = this.url;\n var crossOrigin = element.crossOrigin;\n var crossOriginUrl = url;\n if (this.options.checkCrossOrigin && isCrossOriginURL(url)) {\n if (!crossOrigin) {\n crossOrigin = 'anonymous';\n }\n\n // Bust cache when there is not a \"crossOrigin\" property (#519)\n crossOriginUrl = addTimestamp(url);\n }\n this.crossOrigin = crossOrigin;\n this.crossOriginUrl = crossOriginUrl;\n var image = document.createElement('img');\n if (crossOrigin) {\n image.crossOrigin = crossOrigin;\n }\n image.src = crossOriginUrl || url;\n image.alt = element.alt || 'The image to crop';\n this.image = image;\n image.onload = this.start.bind(this);\n image.onerror = this.stop.bind(this);\n addClass(image, CLASS_HIDE);\n element.parentNode.insertBefore(image, element.nextSibling);\n }\n }, {\n key: \"start\",\n value: function start() {\n var _this2 = this;\n var image = this.image;\n image.onload = null;\n image.onerror = null;\n this.sizing = true;\n\n // Match all browsers that use WebKit as the layout engine in iOS devices,\n // such as Safari for iOS, Chrome for iOS, and in-app browsers.\n var isIOSWebKit = WINDOW.navigator && /(?:iPad|iPhone|iPod).*?AppleWebKit/i.test(WINDOW.navigator.userAgent);\n var done = function done(naturalWidth, naturalHeight) {\n assign(_this2.imageData, {\n naturalWidth: naturalWidth,\n naturalHeight: naturalHeight,\n aspectRatio: naturalWidth / naturalHeight\n });\n _this2.initialImageData = assign({}, _this2.imageData);\n _this2.sizing = false;\n _this2.sized = true;\n _this2.build();\n };\n\n // Most modern browsers (excepts iOS WebKit)\n if (image.naturalWidth && !isIOSWebKit) {\n done(image.naturalWidth, image.naturalHeight);\n return;\n }\n var sizingImage = document.createElement('img');\n var body = document.body || document.documentElement;\n this.sizingImage = sizingImage;\n sizingImage.onload = function () {\n done(sizingImage.width, sizingImage.height);\n if (!isIOSWebKit) {\n body.removeChild(sizingImage);\n }\n };\n sizingImage.src = image.src;\n\n // iOS WebKit will convert the image automatically\n // with its orientation once append it into DOM (#279)\n if (!isIOSWebKit) {\n sizingImage.style.cssText = 'left:0;' + 'max-height:none!important;' + 'max-width:none!important;' + 'min-height:0!important;' + 'min-width:0!important;' + 'opacity:0;' + 'position:absolute;' + 'top:0;' + 'z-index:-1;';\n body.appendChild(sizingImage);\n }\n }\n }, {\n key: \"stop\",\n value: function stop() {\n var image = this.image;\n image.onload = null;\n image.onerror = null;\n image.parentNode.removeChild(image);\n this.image = null;\n }\n }, {\n key: \"build\",\n value: function build() {\n if (!this.sized || this.ready) {\n return;\n }\n var element = this.element,\n options = this.options,\n image = this.image;\n\n // Create cropper elements\n var container = element.parentNode;\n var template = document.createElement('div');\n template.innerHTML = TEMPLATE;\n var cropper = template.querySelector(\".\".concat(NAMESPACE, \"-container\"));\n var canvas = cropper.querySelector(\".\".concat(NAMESPACE, \"-canvas\"));\n var dragBox = cropper.querySelector(\".\".concat(NAMESPACE, \"-drag-box\"));\n var cropBox = cropper.querySelector(\".\".concat(NAMESPACE, \"-crop-box\"));\n var face = cropBox.querySelector(\".\".concat(NAMESPACE, \"-face\"));\n this.container = container;\n this.cropper = cropper;\n this.canvas = canvas;\n this.dragBox = dragBox;\n this.cropBox = cropBox;\n this.viewBox = cropper.querySelector(\".\".concat(NAMESPACE, \"-view-box\"));\n this.face = face;\n canvas.appendChild(image);\n\n // Hide the original image\n addClass(element, CLASS_HIDDEN);\n\n // Inserts the cropper after to the current image\n container.insertBefore(cropper, element.nextSibling);\n\n // Show the hidden image\n removeClass(image, CLASS_HIDE);\n this.initPreview();\n this.bind();\n options.initialAspectRatio = Math.max(0, options.initialAspectRatio) || NaN;\n options.aspectRatio = Math.max(0, options.aspectRatio) || NaN;\n options.viewMode = Math.max(0, Math.min(3, Math.round(options.viewMode))) || 0;\n addClass(cropBox, CLASS_HIDDEN);\n if (!options.guides) {\n addClass(cropBox.getElementsByClassName(\"\".concat(NAMESPACE, \"-dashed\")), CLASS_HIDDEN);\n }\n if (!options.center) {\n addClass(cropBox.getElementsByClassName(\"\".concat(NAMESPACE, \"-center\")), CLASS_HIDDEN);\n }\n if (options.background) {\n addClass(cropper, \"\".concat(NAMESPACE, \"-bg\"));\n }\n if (!options.highlight) {\n addClass(face, CLASS_INVISIBLE);\n }\n if (options.cropBoxMovable) {\n addClass(face, CLASS_MOVE);\n setData(face, DATA_ACTION, ACTION_ALL);\n }\n if (!options.cropBoxResizable) {\n addClass(cropBox.getElementsByClassName(\"\".concat(NAMESPACE, \"-line\")), CLASS_HIDDEN);\n addClass(cropBox.getElementsByClassName(\"\".concat(NAMESPACE, \"-point\")), CLASS_HIDDEN);\n }\n this.render();\n this.ready = true;\n this.setDragMode(options.dragMode);\n if (options.autoCrop) {\n this.crop();\n }\n this.setData(options.data);\n if (isFunction(options.ready)) {\n addListener(element, EVENT_READY, options.ready, {\n once: true\n });\n }\n dispatchEvent(element, EVENT_READY);\n }\n }, {\n key: \"unbuild\",\n value: function unbuild() {\n if (!this.ready) {\n return;\n }\n this.ready = false;\n this.unbind();\n this.resetPreview();\n var parentNode = this.cropper.parentNode;\n if (parentNode) {\n parentNode.removeChild(this.cropper);\n }\n removeClass(this.element, CLASS_HIDDEN);\n }\n }, {\n key: \"uncreate\",\n value: function uncreate() {\n if (this.ready) {\n this.unbuild();\n this.ready = false;\n this.cropped = false;\n } else if (this.sizing) {\n this.sizingImage.onload = null;\n this.sizing = false;\n this.sized = false;\n } else if (this.reloading) {\n this.xhr.onabort = null;\n this.xhr.abort();\n } else if (this.image) {\n this.stop();\n }\n }\n\n /**\n * Get the no conflict cropper class.\n * @returns {Cropper} The cropper class.\n */\n }], [{\n key: \"noConflict\",\n value: function noConflict() {\n window.Cropper = AnotherCropper;\n return Cropper;\n }\n\n /**\n * Change the default options.\n * @param {Object} options - The new default options.\n */\n }, {\n key: \"setDefaults\",\n value: function setDefaults(options) {\n assign(DEFAULTS, isPlainObject(options) && options);\n }\n }]);\n }();\n assign(Cropper.prototype, render, preview, events, handlers, change, methods);\n\n return Cropper;\n\n}));\n", "/* @preserve\n _____ __ _ __ _\n / ___// /(_)___/ /___ ____ (_)___\n / (_ // // // _ // -_)/ __/_ / /(_-<\n \\___//_//_/ \\_,_/ \\__//_/ (_)__/ //___/\n |___/\n\n Version: 1.7.4\n Author: Nick Piscitelli (pickykneee)\n Website: https://nickpiscitelli.com\n Documentation: http://nickpiscitelli.github.io/Glider.js\n License: MIT License\n Release Date: October 25th, 2018\n\n*/\n\n/* global define */\n\n(function (factory) {\n typeof define === 'function' && define.amd\n ? define(factory)\n : typeof exports === 'object'\n ? (module.exports = factory())\n : factory()\n})(function () {\n ('use strict') // eslint-disable-line no-unused-expressions\n\n /* globals window:true */\n var _window = typeof window !== 'undefined' ? window : this\n\n var Glider = (_window.Glider = function (element, settings) {\n var _ = this\n\n if (element._glider) return element._glider\n\n _.ele = element\n _.ele.classList.add('glider')\n\n // expose glider object to its DOM element\n _.ele._glider = _\n\n // merge user setting with defaults\n _.opt = Object.assign(\n {},\n {\n slidesToScroll: 1,\n slidesToShow: 1,\n resizeLock: true,\n duration: 0.5,\n passiveListeners: false,\n // easeInQuad\n easing: function (x, t, b, c, d) {\n return c * (t /= d) * t + b\n }\n },\n settings\n )\n\n // set defaults\n _.animate_id = _.page = _.slide = 0\n _.arrows = {}\n\n // preserve original options to\n // extend breakpoint settings\n _._opt = _.opt\n\n if (_.opt.skipTrack) {\n // first and only child is the track\n _.track = _.ele.children[0]\n } else {\n // create track and wrap slides\n _.track = document.createElement('div')\n _.ele.appendChild(_.track)\n while (_.ele.children.length !== 1) {\n _.track.appendChild(_.ele.children[0])\n }\n }\n\n _.track.classList.add('glider-track')\n\n // start glider\n _.init()\n\n // set events\n _.resize = _.init.bind(_, true)\n _.event(\n _.ele,\n 'add',\n {\n scroll: _.updateControls.bind(_)\n },\n { passive: _.opt.passiveListeners }\n )\n _.event(_window, 'add', {\n resize: _.resize\n })\n })\n\n var gliderPrototype = Glider.prototype\n gliderPrototype.init = function (refresh, paging) {\n var _ = this\n\n var width = 0\n\n var height = 0\n\n _.slides = _.track.children;\n\n [].forEach.call(_.slides, function (_, i) {\n _.classList.add('glider-slide')\n _.setAttribute('data-gslide', i)\n })\n\n _.containerWidth = _.ele.clientWidth\n\n var breakpointChanged = _.settingsBreakpoint()\n if (!paging) paging = breakpointChanged\n\n if (\n _.opt.slidesToShow === 'auto' ||\n typeof _.opt._autoSlide !== 'undefined'\n ) {\n var slideCount = _.containerWidth / _.opt.itemWidth\n\n _.opt._autoSlide = _.opt.slidesToShow = _.opt.exactWidth\n ? slideCount\n : Math.max(1, Math.floor(slideCount))\n }\n if (_.opt.slidesToScroll === 'auto') {\n _.opt.slidesToScroll = Math.floor(_.opt.slidesToShow)\n }\n\n _.itemWidth = _.opt.exactWidth\n ? _.opt.itemWidth\n : _.containerWidth / _.opt.slidesToShow;\n\n // set slide dimensions\n [].forEach.call(_.slides, function (__) {\n __.style.height = 'auto'\n __.style.width = _.itemWidth + 'px'\n width += _.itemWidth\n height = Math.max(__.offsetHeight, height)\n })\n\n _.track.style.width = width + 'px'\n _.trackWidth = width\n _.isDrag = false\n _.preventClick = false\n _.move = false\n\n _.opt.resizeLock && _.scrollTo(_.slide * _.itemWidth, 0)\n\n if (breakpointChanged || paging) {\n _.bindArrows()\n _.buildDots()\n _.bindDrag()\n }\n\n _.updateControls()\n\n _.emit(refresh ? 'refresh' : 'loaded')\n }\n\n gliderPrototype.bindDrag = function () {\n var _ = this\n _.mouse = _.mouse || _.handleMouse.bind(_)\n\n var mouseup = function () {\n _.mouseDown = undefined\n _.ele.classList.remove('drag')\n if (_.isDrag) {\n _.preventClick = true\n }\n _.isDrag = false\n }\n\n const move = function () {\n _.move = true\n }\n\n var events = {\n mouseup: mouseup,\n mouseleave: mouseup,\n mousedown: function (e) {\n e.preventDefault()\n e.stopPropagation()\n _.mouseDown = e.clientX\n _.ele.classList.add('drag')\n _.move = false\n setTimeout(move, 300)\n },\n touchstart: function (e) {\n _.ele.classList.add('drag')\n _.move = false\n setTimeout(move, 300)\n },\n mousemove: _.mouse,\n click: function (e) {\n if (_.preventClick && _.move) {\n e.preventDefault()\n e.stopPropagation()\n }\n _.preventClick = false\n _.move = false\n }\n }\n\n _.ele.classList.toggle('draggable', _.opt.draggable === true)\n _.event(_.ele, 'remove', events)\n if (_.opt.draggable) {\n _.event(_.ele, 'add', events, {\n passive: _.opt.passiveListeners\n })\n }\n }\n\n gliderPrototype.buildDots = function () {\n var _ = this\n\n if (!_.opt.dots) {\n if (_.dots) _.dots.innerHTML = ''\n return\n }\n\n if (typeof _.opt.dots === 'string') {\n _.dots = document.querySelector(_.opt.dots)\n } else _.dots = _.opt.dots\n if (!_.dots) return\n\n _.dots.innerHTML = ''\n _.dots.setAttribute('role', 'tablist')\n _.dots.classList.add('glider-dots')\n\n for (var i = 0; i < Math.ceil(_.slides.length / _.opt.slidesToShow); ++i) {\n var dot = document.createElement('button')\n dot.dataset.index = i\n dot.setAttribute('aria-label', 'Page ' + (i + 1))\n dot.setAttribute('role', 'tab')\n dot.className = 'glider-dot ' + (i ? '' : 'active')\n _.event(dot, 'add', {\n click: _.scrollItem.bind(_, i, true)\n })\n _.dots.appendChild(dot)\n }\n }\n\n gliderPrototype.bindArrows = function () {\n var _ = this\n if (!_.opt.arrows) {\n Object.keys(_.arrows).forEach(function (direction) {\n var element = _.arrows[direction]\n _.event(element, 'remove', { click: element._func })\n })\n return\n }\n ['prev', 'next'].forEach(function (direction) {\n var arrow = _.opt.arrows[direction]\n if (arrow) {\n if (typeof arrow === 'string') arrow = document.querySelector(arrow)\n if (arrow) {\n arrow._func = arrow._func || _.scrollItem.bind(_, direction)\n _.event(arrow, 'remove', {\n click: arrow._func\n })\n _.event(arrow, 'add', {\n click: arrow._func\n })\n _.arrows[direction] = arrow\n }\n }\n })\n }\n\n gliderPrototype.updateControls = function (event) {\n var _ = this\n\n if (event && !_.opt.scrollPropagate) {\n event.stopPropagation()\n }\n\n var disableArrows = _.containerWidth >= _.trackWidth\n\n if (!_.opt.rewind) {\n if (_.arrows.prev) {\n _.arrows.prev.classList.toggle(\n 'disabled',\n _.ele.scrollLeft <= 0 || disableArrows\n )\n\n _.arrows.prev.setAttribute(\n 'aria-disabled',\n _.arrows.prev.classList.contains('disabled')\n )\n }\n if (_.arrows.next) {\n _.arrows.next.classList.toggle(\n 'disabled',\n Math.ceil(_.ele.scrollLeft + _.containerWidth) >=\n Math.floor(_.trackWidth) || disableArrows\n )\n\n _.arrows.next.setAttribute(\n 'aria-disabled',\n _.arrows.next.classList.contains('disabled')\n )\n }\n }\n\n _.slide = Math.round(_.ele.scrollLeft / _.itemWidth)\n _.page = Math.round(_.ele.scrollLeft / _.containerWidth)\n\n var middle = _.slide + Math.floor(Math.floor(_.opt.slidesToShow) / 2)\n\n var extraMiddle = Math.floor(_.opt.slidesToShow) % 2 ? 0 : middle + 1\n if (Math.floor(_.opt.slidesToShow) === 1) {\n extraMiddle = 0\n }\n\n // the last page may be less than one half of a normal page width so\n // the page is rounded down. when at the end, force the page to turn\n if (_.ele.scrollLeft + _.containerWidth >= Math.floor(_.trackWidth)) {\n _.page = _.dots ? _.dots.children.length - 1 : 0\n }\n\n [].forEach.call(_.slides, function (slide, index) {\n var slideClasses = slide.classList\n\n var wasVisible = slideClasses.contains('visible')\n\n var start = _.ele.scrollLeft\n\n var end = _.ele.scrollLeft + _.containerWidth\n\n var itemStart = _.itemWidth * index\n\n var itemEnd = itemStart + _.itemWidth;\n\n [].forEach.call(slideClasses, function (className) {\n /^left|right/.test(className) && slideClasses.remove(className)\n })\n slideClasses.toggle('active', _.slide === index)\n if (middle === index || (extraMiddle && extraMiddle === index)) {\n slideClasses.add('center')\n } else {\n slideClasses.remove('center')\n slideClasses.add(\n [\n index < middle ? 'left' : 'right',\n Math.abs(index - (index < middle ? middle : extraMiddle || middle))\n ].join('-')\n )\n }\n\n var isVisible =\n Math.ceil(itemStart) >= Math.floor(start) &&\n Math.floor(itemEnd) <= Math.ceil(end)\n slideClasses.toggle('visible', isVisible)\n if (isVisible !== wasVisible) {\n _.emit('slide-' + (isVisible ? 'visible' : 'hidden'), {\n slide: index\n })\n }\n })\n if (_.dots) {\n [].forEach.call(_.dots.children, function (dot, index) {\n dot.classList.toggle('active', _.page === index)\n })\n }\n\n if (event && _.opt.scrollLock) {\n clearTimeout(_.scrollLock)\n _.scrollLock = setTimeout(function () {\n clearTimeout(_.scrollLock)\n // dont attempt to scroll less than a pixel fraction - causes looping\n if (Math.abs(_.ele.scrollLeft / _.itemWidth - _.slide) > 0.02) {\n if (!_.mouseDown) {\n // Only scroll if not at the end (#94)\n if (_.trackWidth > _.containerWidth + _.ele.scrollLeft) {\n _.scrollItem(_.getCurrentSlide())\n }\n }\n }\n }, _.opt.scrollLockDelay || 250)\n }\n }\n\n gliderPrototype.getCurrentSlide = function () {\n var _ = this\n return _.round(_.ele.scrollLeft / _.itemWidth)\n }\n\n gliderPrototype.scrollItem = function (slide, dot, e) {\n if (e) e.preventDefault()\n\n var _ = this\n\n var originalSlide = slide\n ++_.animate_id\n\n var prevSlide = _.slide\n var position\n\n if (dot === true) {\n slide = Math.round((slide * _.containerWidth) / _.itemWidth)\n position = slide * _.itemWidth\n } else {\n if (typeof slide === 'string') {\n var backwards = slide === 'prev'\n\n // use precise location if fractional slides are on\n if (_.opt.slidesToScroll % 1 || _.opt.slidesToShow % 1) {\n slide = _.getCurrentSlide()\n } else {\n slide = _.slide\n }\n\n if (backwards) slide -= _.opt.slidesToScroll\n else slide += _.opt.slidesToScroll\n\n if (_.opt.rewind) {\n var scrollLeft = _.ele.scrollLeft\n slide =\n backwards && !scrollLeft\n ? _.slides.length\n : !backwards &&\n scrollLeft + _.containerWidth >= Math.floor(_.trackWidth)\n ? 0\n : slide\n }\n }\n\n slide = Math.max(Math.min(slide, _.slides.length), 0)\n\n _.slide = slide\n position = _.itemWidth * slide\n }\n\n _.emit('scroll-item', { prevSlide, slide })\n\n _.scrollTo(\n position,\n _.opt.duration * Math.abs(_.ele.scrollLeft - position),\n function () {\n _.updateControls()\n _.emit('animated', {\n value: originalSlide,\n type:\n typeof originalSlide === 'string' ? 'arrow' : dot ? 'dot' : 'slide'\n })\n }\n )\n\n return false\n }\n\n gliderPrototype.settingsBreakpoint = function () {\n var _ = this\n\n var resp = _._opt.responsive\n\n if (resp) {\n // Sort the breakpoints in mobile first order\n resp.sort(function (a, b) {\n return b.breakpoint - a.breakpoint\n })\n\n for (var i = 0; i < resp.length; ++i) {\n var size = resp[i]\n if (_window.innerWidth >= size.breakpoint) {\n if (_.breakpoint !== size.breakpoint) {\n _.opt = Object.assign({}, _._opt, size.settings)\n _.breakpoint = size.breakpoint\n return true\n }\n return false\n }\n }\n }\n // set back to defaults in case they were overriden\n var breakpointChanged = _.breakpoint !== 0\n _.opt = Object.assign({}, _._opt)\n _.breakpoint = 0\n return breakpointChanged\n }\n\n gliderPrototype.scrollTo = function (scrollTarget, scrollDuration, callback) {\n var _ = this\n\n var start = new Date().getTime()\n\n var animateIndex = _.animate_id\n\n var animate = function () {\n var now = new Date().getTime() - start\n _.ele.scrollLeft =\n _.ele.scrollLeft +\n (scrollTarget - _.ele.scrollLeft) *\n _.opt.easing(0, now, 0, 1, scrollDuration)\n if (now < scrollDuration && animateIndex === _.animate_id) {\n _window.requestAnimationFrame(animate)\n } else {\n _.ele.scrollLeft = scrollTarget\n callback && callback.call(_)\n }\n }\n\n _window.requestAnimationFrame(animate)\n }\n\n gliderPrototype.removeItem = function (index) {\n var _ = this\n\n if (_.slides.length) {\n _.track.removeChild(_.slides[index])\n _.refresh(true)\n _.emit('remove')\n }\n }\n\n gliderPrototype.addItem = function (ele) {\n var _ = this\n\n _.track.appendChild(ele)\n _.refresh(true)\n _.emit('add')\n }\n\n gliderPrototype.handleMouse = function (e) {\n var _ = this\n if (_.mouseDown) {\n _.isDrag = true\n _.ele.scrollLeft +=\n (_.mouseDown - e.clientX) * (_.opt.dragVelocity || 3.3)\n _.mouseDown = e.clientX\n }\n }\n\n // used to round to the nearest 0.XX fraction\n gliderPrototype.round = function (double) {\n var _ = this\n var step = _.opt.slidesToScroll % 1 || 1\n var inv = 1.0 / step\n return Math.round(double * inv) / inv\n }\n\n gliderPrototype.refresh = function (paging) {\n var _ = this\n _.init(true, paging)\n }\n\n gliderPrototype.setOption = function (opt, global) {\n var _ = this\n\n if (_.breakpoint && !global) {\n _._opt.responsive.forEach(function (v) {\n if (v.breakpoint === _.breakpoint) {\n v.settings = Object.assign({}, v.settings, opt)\n }\n })\n } else {\n _._opt = Object.assign({}, _._opt, opt)\n }\n\n _.breakpoint = 0\n _.settingsBreakpoint()\n }\n\n gliderPrototype.destroy = function () {\n var _ = this\n\n var replace = _.ele.cloneNode(true)\n\n var clear = function (ele) {\n ele.removeAttribute('style');\n [].forEach.call(ele.classList, function (className) {\n /^glider/.test(className) && ele.classList.remove(className)\n })\n }\n // remove track if it was created by glider\n if (!_.opt.skipTrack) {\n replace.children[0].outerHTML = replace.children[0].innerHTML\n }\n clear(replace);\n [].forEach.call(replace.getElementsByTagName('*'), clear)\n _.ele.parentNode.replaceChild(replace, _.ele)\n _.event(_window, 'remove', {\n resize: _.resize\n })\n _.emit('destroy')\n }\n\n gliderPrototype.emit = function (name, arg) {\n var _ = this\n\n var e = new _window.CustomEvent('glider-' + name, {\n bubbles: !_.opt.eventPropagate,\n detail: arg\n })\n _.ele.dispatchEvent(e)\n }\n\n gliderPrototype.event = function (ele, type, args) {\n var eventHandler = ele[type + 'EventListener'].bind(ele)\n Object.keys(args).forEach(function (k) {\n eventHandler(k, args[k])\n })\n }\n\n return Glider\n})\n", "/*!\n * clipboard.js v2.0.11\n * https://clipboardjs.com/\n *\n * Licensed MIT \u00A9 Zeno Rocha\n */\n(function webpackUniversalModuleDefinition(root, factory) {\n\tif(typeof exports === 'object' && typeof module === 'object')\n\t\tmodule.exports = factory();\n\telse if(typeof define === 'function' && define.amd)\n\t\tdefine([], factory);\n\telse if(typeof exports === 'object')\n\t\texports[\"ClipboardJS\"] = factory();\n\telse\n\t\troot[\"ClipboardJS\"] = factory();\n})(this, function() {\nreturn /******/ (function() { // webpackBootstrap\n/******/ \tvar __webpack_modules__ = ({\n\n/***/ 686:\n/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {\n\n\"use strict\";\n\n// EXPORTS\n__webpack_require__.d(__webpack_exports__, {\n \"default\": function() { return /* binding */ clipboard; }\n});\n\n// EXTERNAL MODULE: ./node_modules/tiny-emitter/index.js\nvar tiny_emitter = __webpack_require__(279);\nvar tiny_emitter_default = /*#__PURE__*/__webpack_require__.n(tiny_emitter);\n// EXTERNAL MODULE: ./node_modules/good-listener/src/listen.js\nvar listen = __webpack_require__(370);\nvar listen_default = /*#__PURE__*/__webpack_require__.n(listen);\n// EXTERNAL MODULE: ./node_modules/select/src/select.js\nvar src_select = __webpack_require__(817);\nvar select_default = /*#__PURE__*/__webpack_require__.n(src_select);\n;// CONCATENATED MODULE: ./src/common/command.js\n/**\n * Executes a given operation type.\n * @param {String} type\n * @return {Boolean}\n */\nfunction command(type) {\n try {\n return document.execCommand(type);\n } catch (err) {\n return false;\n }\n}\n;// CONCATENATED MODULE: ./src/actions/cut.js\n\n\n/**\n * Cut action wrapper.\n * @param {String|HTMLElement} target\n * @return {String}\n */\n\nvar ClipboardActionCut = function ClipboardActionCut(target) {\n var selectedText = select_default()(target);\n command('cut');\n return selectedText;\n};\n\n/* harmony default export */ var actions_cut = (ClipboardActionCut);\n;// CONCATENATED MODULE: ./src/common/create-fake-element.js\n/**\n * Creates a fake textarea element with a value.\n * @param {String} value\n * @return {HTMLElement}\n */\nfunction createFakeElement(value) {\n var isRTL = document.documentElement.getAttribute('dir') === 'rtl';\n var fakeElement = document.createElement('textarea'); // Prevent zooming on iOS\n\n fakeElement.style.fontSize = '12pt'; // Reset box model\n\n fakeElement.style.border = '0';\n fakeElement.style.padding = '0';\n fakeElement.style.margin = '0'; // Move element out of screen horizontally\n\n fakeElement.style.position = 'absolute';\n fakeElement.style[isRTL ? 'right' : 'left'] = '-9999px'; // Move element to the same position vertically\n\n var yPosition = window.pageYOffset || document.documentElement.scrollTop;\n fakeElement.style.top = \"\".concat(yPosition, \"px\");\n fakeElement.setAttribute('readonly', '');\n fakeElement.value = value;\n return fakeElement;\n}\n;// CONCATENATED MODULE: ./src/actions/copy.js\n\n\n\n/**\n * Create fake copy action wrapper using a fake element.\n * @param {String} target\n * @param {Object} options\n * @return {String}\n */\n\nvar fakeCopyAction = function fakeCopyAction(value, options) {\n var fakeElement = createFakeElement(value);\n options.container.appendChild(fakeElement);\n var selectedText = select_default()(fakeElement);\n command('copy');\n fakeElement.remove();\n return selectedText;\n};\n/**\n * Copy action wrapper.\n * @param {String|HTMLElement} target\n * @param {Object} options\n * @return {String}\n */\n\n\nvar ClipboardActionCopy = function ClipboardActionCopy(target) {\n var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {\n container: document.body\n };\n var selectedText = '';\n\n if (typeof target === 'string') {\n selectedText = fakeCopyAction(target, options);\n } else if (target instanceof HTMLInputElement && !['text', 'search', 'url', 'tel', 'password'].includes(target === null || target === void 0 ? void 0 : target.type)) {\n // If input type doesn't support `setSelectionRange`. Simulate it. https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement/setSelectionRange\n selectedText = fakeCopyAction(target.value, options);\n } else {\n selectedText = select_default()(target);\n command('copy');\n }\n\n return selectedText;\n};\n\n/* harmony default export */ var actions_copy = (ClipboardActionCopy);\n;// CONCATENATED MODULE: ./src/actions/default.js\nfunction _typeof(obj) { \"@babel/helpers - typeof\"; if (typeof Symbol === \"function\" && typeof Symbol.iterator === \"symbol\") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === \"function\" && obj.constructor === Symbol && obj !== Symbol.prototype ? \"symbol\" : typeof obj; }; } return _typeof(obj); }\n\n\n\n/**\n * Inner function which performs selection from either `text` or `target`\n * properties and then executes copy or cut operations.\n * @param {Object} options\n */\n\nvar ClipboardActionDefault = function ClipboardActionDefault() {\n var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};\n // Defines base properties passed from constructor.\n var _options$action = options.action,\n action = _options$action === void 0 ? 'copy' : _options$action,\n container = options.container,\n target = options.target,\n text = options.text; // Sets the `action` to be performed which can be either 'copy' or 'cut'.\n\n if (action !== 'copy' && action !== 'cut') {\n throw new Error('Invalid \"action\" value, use either \"copy\" or \"cut\"');\n } // Sets the `target` property using an element that will be have its content copied.\n\n\n if (target !== undefined) {\n if (target && _typeof(target) === 'object' && target.nodeType === 1) {\n if (action === 'copy' && target.hasAttribute('disabled')) {\n throw new Error('Invalid \"target\" attribute. Please use \"readonly\" instead of \"disabled\" attribute');\n }\n\n if (action === 'cut' && (target.hasAttribute('readonly') || target.hasAttribute('disabled'))) {\n throw new Error('Invalid \"target\" attribute. You can\\'t cut text from elements with \"readonly\" or \"disabled\" attributes');\n }\n } else {\n throw new Error('Invalid \"target\" value, use a valid Element');\n }\n } // Define selection strategy based on `text` property.\n\n\n if (text) {\n return actions_copy(text, {\n container: container\n });\n } // Defines which selection strategy based on `target` property.\n\n\n if (target) {\n return action === 'cut' ? actions_cut(target) : actions_copy(target, {\n container: container\n });\n }\n};\n\n/* harmony default export */ var actions_default = (ClipboardActionDefault);\n;// CONCATENATED MODULE: ./src/clipboard.js\nfunction clipboard_typeof(obj) { \"@babel/helpers - typeof\"; if (typeof Symbol === \"function\" && typeof Symbol.iterator === \"symbol\") { clipboard_typeof = function _typeof(obj) { return typeof obj; }; } else { clipboard_typeof = function _typeof(obj) { return obj && typeof Symbol === \"function\" && obj.constructor === Symbol && obj !== Symbol.prototype ? \"symbol\" : typeof obj; }; } return clipboard_typeof(obj); }\n\nfunction _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError(\"Cannot call a class as a function\"); } }\n\nfunction _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if (\"value\" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }\n\nfunction _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }\n\nfunction _inherits(subClass, superClass) { if (typeof superClass !== \"function\" && superClass !== null) { throw new TypeError(\"Super expression must either be null or a function\"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }\n\nfunction _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }\n\nfunction _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }\n\nfunction _possibleConstructorReturn(self, call) { if (call && (clipboard_typeof(call) === \"object\" || typeof call === \"function\")) { return call; } return _assertThisInitialized(self); }\n\nfunction _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError(\"this hasn't been initialised - super() hasn't been called\"); } return self; }\n\nfunction _isNativeReflectConstruct() { if (typeof Reflect === \"undefined\" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === \"function\") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }\n\nfunction _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }\n\n\n\n\n\n\n/**\n * Helper function to retrieve attribute value.\n * @param {String} suffix\n * @param {Element} element\n */\n\nfunction getAttributeValue(suffix, element) {\n var attribute = \"data-clipboard-\".concat(suffix);\n\n if (!element.hasAttribute(attribute)) {\n return;\n }\n\n return element.getAttribute(attribute);\n}\n/**\n * Base class which takes one or more elements, adds event listeners to them,\n * and instantiates a new `ClipboardAction` on each click.\n */\n\n\nvar Clipboard = /*#__PURE__*/function (_Emitter) {\n _inherits(Clipboard, _Emitter);\n\n var _super = _createSuper(Clipboard);\n\n /**\n * @param {String|HTMLElement|HTMLCollection|NodeList} trigger\n * @param {Object} options\n */\n function Clipboard(trigger, options) {\n var _this;\n\n _classCallCheck(this, Clipboard);\n\n _this = _super.call(this);\n\n _this.resolveOptions(options);\n\n _this.listenClick(trigger);\n\n return _this;\n }\n /**\n * Defines if attributes would be resolved using internal setter functions\n * or custom functions that were passed in the constructor.\n * @param {Object} options\n */\n\n\n _createClass(Clipboard, [{\n key: \"resolveOptions\",\n value: function resolveOptions() {\n var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};\n this.action = typeof options.action === 'function' ? options.action : this.defaultAction;\n this.target = typeof options.target === 'function' ? options.target : this.defaultTarget;\n this.text = typeof options.text === 'function' ? options.text : this.defaultText;\n this.container = clipboard_typeof(options.container) === 'object' ? options.container : document.body;\n }\n /**\n * Adds a click event listener to the passed trigger.\n * @param {String|HTMLElement|HTMLCollection|NodeList} trigger\n */\n\n }, {\n key: \"listenClick\",\n value: function listenClick(trigger) {\n var _this2 = this;\n\n this.listener = listen_default()(trigger, 'click', function (e) {\n return _this2.onClick(e);\n });\n }\n /**\n * Defines a new `ClipboardAction` on each click event.\n * @param {Event} e\n */\n\n }, {\n key: \"onClick\",\n value: function onClick(e) {\n var trigger = e.delegateTarget || e.currentTarget;\n var action = this.action(trigger) || 'copy';\n var text = actions_default({\n action: action,\n container: this.container,\n target: this.target(trigger),\n text: this.text(trigger)\n }); // Fires an event based on the copy operation result.\n\n this.emit(text ? 'success' : 'error', {\n action: action,\n text: text,\n trigger: trigger,\n clearSelection: function clearSelection() {\n if (trigger) {\n trigger.focus();\n }\n\n window.getSelection().removeAllRanges();\n }\n });\n }\n /**\n * Default `action` lookup function.\n * @param {Element} trigger\n */\n\n }, {\n key: \"defaultAction\",\n value: function defaultAction(trigger) {\n return getAttributeValue('action', trigger);\n }\n /**\n * Default `target` lookup function.\n * @param {Element} trigger\n */\n\n }, {\n key: \"defaultTarget\",\n value: function defaultTarget(trigger) {\n var selector = getAttributeValue('target', trigger);\n\n if (selector) {\n return document.querySelector(selector);\n }\n }\n /**\n * Allow fire programmatically a copy action\n * @param {String|HTMLElement} target\n * @param {Object} options\n * @returns Text copied.\n */\n\n }, {\n key: \"defaultText\",\n\n /**\n * Default `text` lookup function.\n * @param {Element} trigger\n */\n value: function defaultText(trigger) {\n return getAttributeValue('text', trigger);\n }\n /**\n * Destroy lifecycle.\n */\n\n }, {\n key: \"destroy\",\n value: function destroy() {\n this.listener.destroy();\n }\n }], [{\n key: \"copy\",\n value: function copy(target) {\n var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {\n container: document.body\n };\n return actions_copy(target, options);\n }\n /**\n * Allow fire programmatically a cut action\n * @param {String|HTMLElement} target\n * @returns Text cutted.\n */\n\n }, {\n key: \"cut\",\n value: function cut(target) {\n return actions_cut(target);\n }\n /**\n * Returns the support of the given action, or all actions if no action is\n * given.\n * @param {String} [action]\n */\n\n }, {\n key: \"isSupported\",\n value: function isSupported() {\n var action = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : ['copy', 'cut'];\n var actions = typeof action === 'string' ? [action] : action;\n var support = !!document.queryCommandSupported;\n actions.forEach(function (action) {\n support = support && !!document.queryCommandSupported(action);\n });\n return support;\n }\n }]);\n\n return Clipboard;\n}((tiny_emitter_default()));\n\n/* harmony default export */ var clipboard = (Clipboard);\n\n/***/ }),\n\n/***/ 828:\n/***/ (function(module) {\n\nvar DOCUMENT_NODE_TYPE = 9;\n\n/**\n * A polyfill for Element.matches()\n */\nif (typeof Element !== 'undefined' && !Element.prototype.matches) {\n var proto = Element.prototype;\n\n proto.matches = proto.matchesSelector ||\n proto.mozMatchesSelector ||\n proto.msMatchesSelector ||\n proto.oMatchesSelector ||\n proto.webkitMatchesSelector;\n}\n\n/**\n * Finds the closest parent that matches a selector.\n *\n * @param {Element} element\n * @param {String} selector\n * @return {Function}\n */\nfunction closest (element, selector) {\n while (element && element.nodeType !== DOCUMENT_NODE_TYPE) {\n if (typeof element.matches === 'function' &&\n element.matches(selector)) {\n return element;\n }\n element = element.parentNode;\n }\n}\n\nmodule.exports = closest;\n\n\n/***/ }),\n\n/***/ 438:\n/***/ (function(module, __unused_webpack_exports, __webpack_require__) {\n\nvar closest = __webpack_require__(828);\n\n/**\n * Delegates event to a selector.\n *\n * @param {Element} element\n * @param {String} selector\n * @param {String} type\n * @param {Function} callback\n * @param {Boolean} useCapture\n * @return {Object}\n */\nfunction _delegate(element, selector, type, callback, useCapture) {\n var listenerFn = listener.apply(this, arguments);\n\n element.addEventListener(type, listenerFn, useCapture);\n\n return {\n destroy: function() {\n element.removeEventListener(type, listenerFn, useCapture);\n }\n }\n}\n\n/**\n * Delegates event to a selector.\n *\n * @param {Element|String|Array} [elements]\n * @param {String} selector\n * @param {String} type\n * @param {Function} callback\n * @param {Boolean} useCapture\n * @return {Object}\n */\nfunction delegate(elements, selector, type, callback, useCapture) {\n // Handle the regular Element usage\n if (typeof elements.addEventListener === 'function') {\n return _delegate.apply(null, arguments);\n }\n\n // Handle Element-less usage, it defaults to global delegation\n if (typeof type === 'function') {\n // Use `document` as the first parameter, then apply arguments\n // This is a short way to .unshift `arguments` without running into deoptimizations\n return _delegate.bind(null, document).apply(null, arguments);\n }\n\n // Handle Selector-based usage\n if (typeof elements === 'string') {\n elements = document.querySelectorAll(elements);\n }\n\n // Handle Array-like based usage\n return Array.prototype.map.call(elements, function (element) {\n return _delegate(element, selector, type, callback, useCapture);\n });\n}\n\n/**\n * Finds closest match and invokes callback.\n *\n * @param {Element} element\n * @param {String} selector\n * @param {String} type\n * @param {Function} callback\n * @return {Function}\n */\nfunction listener(element, selector, type, callback) {\n return function(e) {\n e.delegateTarget = closest(e.target, selector);\n\n if (e.delegateTarget) {\n callback.call(element, e);\n }\n }\n}\n\nmodule.exports = delegate;\n\n\n/***/ }),\n\n/***/ 879:\n/***/ (function(__unused_webpack_module, exports) {\n\n/**\n * Check if argument is a HTML element.\n *\n * @param {Object} value\n * @return {Boolean}\n */\nexports.node = function(value) {\n return value !== undefined\n && value instanceof HTMLElement\n && value.nodeType === 1;\n};\n\n/**\n * Check if argument is a list of HTML elements.\n *\n * @param {Object} value\n * @return {Boolean}\n */\nexports.nodeList = function(value) {\n var type = Object.prototype.toString.call(value);\n\n return value !== undefined\n && (type === '[object NodeList]' || type === '[object HTMLCollection]')\n && ('length' in value)\n && (value.length === 0 || exports.node(value[0]));\n};\n\n/**\n * Check if argument is a string.\n *\n * @param {Object} value\n * @return {Boolean}\n */\nexports.string = function(value) {\n return typeof value === 'string'\n || value instanceof String;\n};\n\n/**\n * Check if argument is a function.\n *\n * @param {Object} value\n * @return {Boolean}\n */\nexports.fn = function(value) {\n var type = Object.prototype.toString.call(value);\n\n return type === '[object Function]';\n};\n\n\n/***/ }),\n\n/***/ 370:\n/***/ (function(module, __unused_webpack_exports, __webpack_require__) {\n\nvar is = __webpack_require__(879);\nvar delegate = __webpack_require__(438);\n\n/**\n * Validates all params and calls the right\n * listener function based on its target type.\n *\n * @param {String|HTMLElement|HTMLCollection|NodeList} target\n * @param {String} type\n * @param {Function} callback\n * @return {Object}\n */\nfunction listen(target, type, callback) {\n if (!target && !type && !callback) {\n throw new Error('Missing required arguments');\n }\n\n if (!is.string(type)) {\n throw new TypeError('Second argument must be a String');\n }\n\n if (!is.fn(callback)) {\n throw new TypeError('Third argument must be a Function');\n }\n\n if (is.node(target)) {\n return listenNode(target, type, callback);\n }\n else if (is.nodeList(target)) {\n return listenNodeList(target, type, callback);\n }\n else if (is.string(target)) {\n return listenSelector(target, type, callback);\n }\n else {\n throw new TypeError('First argument must be a String, HTMLElement, HTMLCollection, or NodeList');\n }\n}\n\n/**\n * Adds an event listener to a HTML element\n * and returns a remove listener function.\n *\n * @param {HTMLElement} node\n * @param {String} type\n * @param {Function} callback\n * @return {Object}\n */\nfunction listenNode(node, type, callback) {\n node.addEventListener(type, callback);\n\n return {\n destroy: function() {\n node.removeEventListener(type, callback);\n }\n }\n}\n\n/**\n * Add an event listener to a list of HTML elements\n * and returns a remove listener function.\n *\n * @param {NodeList|HTMLCollection} nodeList\n * @param {String} type\n * @param {Function} callback\n * @return {Object}\n */\nfunction listenNodeList(nodeList, type, callback) {\n Array.prototype.forEach.call(nodeList, function(node) {\n node.addEventListener(type, callback);\n });\n\n return {\n destroy: function() {\n Array.prototype.forEach.call(nodeList, function(node) {\n node.removeEventListener(type, callback);\n });\n }\n }\n}\n\n/**\n * Add an event listener to a selector\n * and returns a remove listener function.\n *\n * @param {String} selector\n * @param {String} type\n * @param {Function} callback\n * @return {Object}\n */\nfunction listenSelector(selector, type, callback) {\n return delegate(document.body, selector, type, callback);\n}\n\nmodule.exports = listen;\n\n\n/***/ }),\n\n/***/ 817:\n/***/ (function(module) {\n\nfunction select(element) {\n var selectedText;\n\n if (element.nodeName === 'SELECT') {\n element.focus();\n\n selectedText = element.value;\n }\n else if (element.nodeName === 'INPUT' || element.nodeName === 'TEXTAREA') {\n var isReadOnly = element.hasAttribute('readonly');\n\n if (!isReadOnly) {\n element.setAttribute('readonly', '');\n }\n\n element.select();\n element.setSelectionRange(0, element.value.length);\n\n if (!isReadOnly) {\n element.removeAttribute('readonly');\n }\n\n selectedText = element.value;\n }\n else {\n if (element.hasAttribute('contenteditable')) {\n element.focus();\n }\n\n var selection = window.getSelection();\n var range = document.createRange();\n\n range.selectNodeContents(element);\n selection.removeAllRanges();\n selection.addRange(range);\n\n selectedText = selection.toString();\n }\n\n return selectedText;\n}\n\nmodule.exports = select;\n\n\n/***/ }),\n\n/***/ 279:\n/***/ (function(module) {\n\nfunction E () {\n // Keep this empty so it's easier to inherit from\n // (via https://github.com/lipsmack from https://github.com/scottcorgan/tiny-emitter/issues/3)\n}\n\nE.prototype = {\n on: function (name, callback, ctx) {\n var e = this.e || (this.e = {});\n\n (e[name] || (e[name] = [])).push({\n fn: callback,\n ctx: ctx\n });\n\n return this;\n },\n\n once: function (name, callback, ctx) {\n var self = this;\n function listener () {\n self.off(name, listener);\n callback.apply(ctx, arguments);\n };\n\n listener._ = callback\n return this.on(name, listener, ctx);\n },\n\n emit: function (name) {\n var data = [].slice.call(arguments, 1);\n var evtArr = ((this.e || (this.e = {}))[name] || []).slice();\n var i = 0;\n var len = evtArr.length;\n\n for (i; i < len; i++) {\n evtArr[i].fn.apply(evtArr[i].ctx, data);\n }\n\n return this;\n },\n\n off: function (name, callback) {\n var e = this.e || (this.e = {});\n var evts = e[name];\n var liveEvents = [];\n\n if (evts && callback) {\n for (var i = 0, len = evts.length; i < len; i++) {\n if (evts[i].fn !== callback && evts[i].fn._ !== callback)\n liveEvents.push(evts[i]);\n }\n }\n\n // Remove event from queue to prevent memory leak\n // Suggested by https://github.com/lazd\n // Ref: https://github.com/scottcorgan/tiny-emitter/commit/c6ebfaa9bc973b33d110a84a307742b7cf94c953#commitcomment-5024910\n\n (liveEvents.length)\n ? e[name] = liveEvents\n : delete e[name];\n\n return this;\n }\n};\n\nmodule.exports = E;\nmodule.exports.TinyEmitter = E;\n\n\n/***/ })\n\n/******/ \t});\n/************************************************************************/\n/******/ \t// The module cache\n/******/ \tvar __webpack_module_cache__ = {};\n/******/ \t\n/******/ \t// The require function\n/******/ \tfunction __webpack_require__(moduleId) {\n/******/ \t\t// Check if module is in cache\n/******/ \t\tif(__webpack_module_cache__[moduleId]) {\n/******/ \t\t\treturn __webpack_module_cache__[moduleId].exports;\n/******/ \t\t}\n/******/ \t\t// Create a new module (and put it into the cache)\n/******/ \t\tvar module = __webpack_module_cache__[moduleId] = {\n/******/ \t\t\t// no module.id needed\n/******/ \t\t\t// no module.loaded needed\n/******/ \t\t\texports: {}\n/******/ \t\t};\n/******/ \t\n/******/ \t\t// Execute the module function\n/******/ \t\t__webpack_modules__[moduleId](module, module.exports, __webpack_require__);\n/******/ \t\n/******/ \t\t// Return the exports of the module\n/******/ \t\treturn module.exports;\n/******/ \t}\n/******/ \t\n/************************************************************************/\n/******/ \t/* webpack/runtime/compat get default export */\n/******/ \t!function() {\n/******/ \t\t// getDefaultExport function for compatibility with non-harmony modules\n/******/ \t\t__webpack_require__.n = function(module) {\n/******/ \t\t\tvar getter = module && module.__esModule ?\n/******/ \t\t\t\tfunction() { return module['default']; } :\n/******/ \t\t\t\tfunction() { return module; };\n/******/ \t\t\t__webpack_require__.d(getter, { a: getter });\n/******/ \t\t\treturn getter;\n/******/ \t\t};\n/******/ \t}();\n/******/ \t\n/******/ \t/* webpack/runtime/define property getters */\n/******/ \t!function() {\n/******/ \t\t// define getter functions for harmony exports\n/******/ \t\t__webpack_require__.d = function(exports, definition) {\n/******/ \t\t\tfor(var key in definition) {\n/******/ \t\t\t\tif(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {\n/******/ \t\t\t\t\tObject.defineProperty(exports, key, { enumerable: true, get: definition[key] });\n/******/ \t\t\t\t}\n/******/ \t\t\t}\n/******/ \t\t};\n/******/ \t}();\n/******/ \t\n/******/ \t/* webpack/runtime/hasOwnProperty shorthand */\n/******/ \t!function() {\n/******/ \t\t__webpack_require__.o = function(obj, prop) { return Object.prototype.hasOwnProperty.call(obj, prop); }\n/******/ \t}();\n/******/ \t\n/************************************************************************/\n/******/ \t// module exports must be returned from runtime so entry inlining is disabled\n/******/ \t// startup\n/******/ \t// Load entry module and return exports\n/******/ \treturn __webpack_require__(686);\n/******/ })()\n.default;\n});", "/* eslint-disable */\n/*\nTrix 2.1.10\nCopyright \u00A9 2024 37signals, LLC\n */\n(function (global, factory) {\n typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :\n typeof define === 'function' && define.amd ? define(factory) :\n (global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.Trix = factory());\n})(this, (function () { 'use strict';\n\n var name = \"trix\";\n var version = \"2.1.10\";\n var description = \"A rich text editor for everyday writing\";\n var main = \"dist/trix.umd.min.js\";\n var module = \"dist/trix.esm.min.js\";\n var style = \"dist/trix.css\";\n var files = [\n \t\"dist/*.css\",\n \t\"dist/*.js\",\n \t\"dist/*.map\",\n \t\"src/{inspector,trix}/*.js\"\n ];\n var repository = {\n \ttype: \"git\",\n \turl: \"git+https://github.com/basecamp/trix.git\"\n };\n var keywords = [\n \t\"rich text\",\n \t\"wysiwyg\",\n \t\"editor\"\n ];\n var author = \"37signals, LLC\";\n var license = \"MIT\";\n var bugs = {\n \turl: \"https://github.com/basecamp/trix/issues\"\n };\n var homepage = \"https://trix-editor.org/\";\n var devDependencies = {\n \t\"@babel/core\": \"^7.16.0\",\n \t\"@babel/preset-env\": \"^7.16.4\",\n \t\"@rollup/plugin-babel\": \"^5.3.0\",\n \t\"@rollup/plugin-commonjs\": \"^22.0.2\",\n \t\"@rollup/plugin-json\": \"^4.1.0\",\n \t\"@rollup/plugin-node-resolve\": \"^13.3.0\",\n \t\"@web/dev-server\": \"^0.1.34\",\n \t\"babel-eslint\": \"^10.1.0\",\n \tconcurrently: \"^7.4.0\",\n \teslint: \"^7.32.0\",\n \tesm: \"^3.2.25\",\n \tkarma: \"6.4.1\",\n \t\"karma-chrome-launcher\": \"3.2.0\",\n \t\"karma-qunit\": \"^4.1.2\",\n \t\"karma-sauce-launcher\": \"^4.3.6\",\n \t\"node-sass\": \"^7.0.1\",\n \tqunit: \"2.19.1\",\n \trangy: \"^1.3.0\",\n \trollup: \"^2.56.3\",\n \t\"rollup-plugin-includepaths\": \"^0.2.4\",\n \t\"rollup-plugin-terser\": \"^7.0.2\",\n \tsvgo: \"^2.8.0\",\n \twebdriverio: \"^7.19.5\"\n };\n var resolutions = {\n \twebdriverio: \"^7.19.5\"\n };\n var scripts = {\n \t\"build-css\": \"node-sass --functions=./assets/trix/stylesheets/functions assets/trix.scss dist/trix.css\",\n \t\"build-js\": \"rollup -c\",\n \t\"build-assets\": \"cp -f assets/*.html dist/\",\n \tbuild: \"yarn run build-js && yarn run build-css && yarn run build-assets\",\n \twatch: \"rollup -c -w\",\n \tlint: \"eslint .\",\n \tpretest: \"yarn run lint && yarn run build\",\n \ttest: \"karma start\",\n \tprerelease: \"yarn version && yarn test\",\n \trelease: \"npm adduser && npm publish\",\n \tpostrelease: \"git push && git push --tags\",\n \tdev: \"web-dev-server --app-index index.html --root-dir dist --node-resolve --open\",\n \tstart: \"yarn build-assets && concurrently --kill-others --names js,css,dev-server 'yarn watch' 'yarn build-css --watch' 'yarn dev'\"\n };\n var dependencies = {\n \tdompurify: \"^3.2.3\"\n };\n var _package = {\n \tname: name,\n \tversion: version,\n \tdescription: description,\n \tmain: main,\n \tmodule: module,\n \tstyle: style,\n \tfiles: files,\n \trepository: repository,\n \tkeywords: keywords,\n \tauthor: author,\n \tlicense: license,\n \tbugs: bugs,\n \thomepage: homepage,\n \tdevDependencies: devDependencies,\n \tresolutions: resolutions,\n \tscripts: scripts,\n \tdependencies: dependencies\n };\n\n const attachmentSelector = \"[data-trix-attachment]\";\n const attachments = {\n preview: {\n presentation: \"gallery\",\n caption: {\n name: true,\n size: true\n }\n },\n file: {\n caption: {\n size: true\n }\n }\n };\n\n const attributes = {\n default: {\n tagName: \"div\",\n parse: false\n },\n quote: {\n tagName: \"blockquote\",\n nestable: true\n },\n heading1: {\n tagName: \"h1\",\n terminal: true,\n breakOnReturn: true,\n group: false\n },\n code: {\n tagName: \"pre\",\n terminal: true,\n htmlAttributes: [\"language\"],\n text: {\n plaintext: true\n }\n },\n bulletList: {\n tagName: \"ul\",\n parse: false\n },\n bullet: {\n tagName: \"li\",\n listAttribute: \"bulletList\",\n group: false,\n nestable: true,\n test(element) {\n return tagName$1(element.parentNode) === attributes[this.listAttribute].tagName;\n }\n },\n numberList: {\n tagName: \"ol\",\n parse: false\n },\n number: {\n tagName: \"li\",\n listAttribute: \"numberList\",\n group: false,\n nestable: true,\n test(element) {\n return tagName$1(element.parentNode) === attributes[this.listAttribute].tagName;\n }\n },\n attachmentGallery: {\n tagName: \"div\",\n exclusive: true,\n terminal: true,\n parse: false,\n group: false\n }\n };\n const tagName$1 = element => {\n var _element$tagName;\n return element === null || element === void 0 || (_element$tagName = element.tagName) === null || _element$tagName === void 0 ? void 0 : _element$tagName.toLowerCase();\n };\n\n const androidVersionMatch = navigator.userAgent.match(/android\\s([0-9]+.*Chrome)/i);\n const androidVersion = androidVersionMatch && parseInt(androidVersionMatch[1]);\n var browser$1 = {\n // Android emits composition events when moving the cursor through existing text\n // Introduced in Chrome 65: https://bugs.chromium.org/p/chromium/issues/detail?id=764439#c9\n composesExistingText: /Android.*Chrome/.test(navigator.userAgent),\n // Android 13, especially on Samsung keyboards, emits extra compositionend and beforeinput events\n // that can make the input handler lose the current selection or enter an infinite input -> render -> input\n // loop.\n recentAndroid: androidVersion && androidVersion > 12,\n samsungAndroid: androidVersion && navigator.userAgent.match(/Android.*SM-/),\n // IE 11 activates resizing handles on editable elements that have \"layout\"\n forcesObjectResizing: /Trident.*rv:11/.test(navigator.userAgent),\n // https://www.w3.org/TR/input-events-1/ + https://www.w3.org/TR/input-events-2/\n supportsInputEvents: typeof InputEvent !== \"undefined\" && [\"data\", \"getTargetRanges\", \"inputType\"].every(prop => prop in InputEvent.prototype)\n };\n\n var css$3 = {\n attachment: \"attachment\",\n attachmentCaption: \"attachment__caption\",\n attachmentCaptionEditor: \"attachment__caption-editor\",\n attachmentMetadata: \"attachment__metadata\",\n attachmentMetadataContainer: \"attachment__metadata-container\",\n attachmentName: \"attachment__name\",\n attachmentProgress: \"attachment__progress\",\n attachmentSize: \"attachment__size\",\n attachmentToolbar: \"attachment__toolbar\",\n attachmentGallery: \"attachment-gallery\"\n };\n\n var lang$1 = {\n attachFiles: \"Attach Files\",\n bold: \"Bold\",\n bullets: \"Bullets\",\n byte: \"Byte\",\n bytes: \"Bytes\",\n captionPlaceholder: \"Add a caption\u2026\",\n code: \"Code\",\n heading1: \"Heading\",\n indent: \"Increase Level\",\n italic: \"Italic\",\n link: \"Link\",\n numbers: \"Numbers\",\n outdent: \"Decrease Level\",\n quote: \"Quote\",\n redo: \"Redo\",\n remove: \"Remove\",\n strike: \"Strikethrough\",\n undo: \"Undo\",\n unlink: \"Unlink\",\n url: \"URL\",\n urlPlaceholder: \"Enter a URL\u2026\",\n GB: \"GB\",\n KB: \"KB\",\n MB: \"MB\",\n PB: \"PB\",\n TB: \"TB\"\n };\n\n /* eslint-disable\n no-case-declarations,\n */\n const sizes = [lang$1.bytes, lang$1.KB, lang$1.MB, lang$1.GB, lang$1.TB, lang$1.PB];\n var file_size_formatting = {\n prefix: \"IEC\",\n precision: 2,\n formatter(number) {\n switch (number) {\n case 0:\n return \"0 \".concat(lang$1.bytes);\n case 1:\n return \"1 \".concat(lang$1.byte);\n default:\n let base;\n if (this.prefix === \"SI\") {\n base = 1000;\n } else if (this.prefix === \"IEC\") {\n base = 1024;\n }\n const exp = Math.floor(Math.log(number) / Math.log(base));\n const humanSize = number / Math.pow(base, exp);\n const string = humanSize.toFixed(this.precision);\n const withoutInsignificantZeros = string.replace(/0*$/, \"\").replace(/\\.$/, \"\");\n return \"\".concat(withoutInsignificantZeros, \" \").concat(sizes[exp]);\n }\n }\n };\n\n const ZERO_WIDTH_SPACE = \"\\uFEFF\";\n const NON_BREAKING_SPACE = \"\\u00A0\";\n const OBJECT_REPLACEMENT_CHARACTER = \"\\uFFFC\";\n\n const extend = function (properties) {\n for (const key in properties) {\n const value = properties[key];\n this[key] = value;\n }\n return this;\n };\n\n const html$2 = document.documentElement;\n const match = html$2.matches;\n const handleEvent = function (eventName) {\n let {\n onElement,\n matchingSelector,\n withCallback,\n inPhase,\n preventDefault,\n times\n } = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};\n const element = onElement ? onElement : html$2;\n const selector = matchingSelector;\n const useCapture = inPhase === \"capturing\";\n const handler = function (event) {\n if (times != null && --times === 0) {\n handler.destroy();\n }\n const target = findClosestElementFromNode(event.target, {\n matchingSelector: selector\n });\n if (target != null) {\n withCallback === null || withCallback === void 0 || withCallback.call(target, event, target);\n if (preventDefault) {\n event.preventDefault();\n }\n }\n };\n handler.destroy = () => element.removeEventListener(eventName, handler, useCapture);\n element.addEventListener(eventName, handler, useCapture);\n return handler;\n };\n const handleEventOnce = function (eventName) {\n let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};\n options.times = 1;\n return handleEvent(eventName, options);\n };\n const triggerEvent = function (eventName) {\n let {\n onElement,\n bubbles,\n cancelable,\n attributes\n } = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};\n const element = onElement != null ? onElement : html$2;\n bubbles = bubbles !== false;\n cancelable = cancelable !== false;\n const event = document.createEvent(\"Events\");\n event.initEvent(eventName, bubbles, cancelable);\n if (attributes != null) {\n extend.call(event, attributes);\n }\n return element.dispatchEvent(event);\n };\n const elementMatchesSelector = function (element, selector) {\n if ((element === null || element === void 0 ? void 0 : element.nodeType) === 1) {\n return match.call(element, selector);\n }\n };\n const findClosestElementFromNode = function (node) {\n let {\n matchingSelector,\n untilNode\n } = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};\n while (node && node.nodeType !== Node.ELEMENT_NODE) {\n node = node.parentNode;\n }\n if (node == null) {\n return;\n }\n if (matchingSelector != null) {\n if (node.closest && untilNode == null) {\n return node.closest(matchingSelector);\n } else {\n while (node && node !== untilNode) {\n if (elementMatchesSelector(node, matchingSelector)) {\n return node;\n }\n node = node.parentNode;\n }\n }\n } else {\n return node;\n }\n };\n const findInnerElement = function (element) {\n while ((_element = element) !== null && _element !== void 0 && _element.firstElementChild) {\n var _element;\n element = element.firstElementChild;\n }\n return element;\n };\n const innerElementIsActive = element => document.activeElement !== element && elementContainsNode(element, document.activeElement);\n const elementContainsNode = function (element, node) {\n if (!element || !node) {\n return;\n }\n while (node) {\n if (node === element) {\n return true;\n }\n node = node.parentNode;\n }\n };\n const findNodeFromContainerAndOffset = function (container, offset) {\n if (!container) {\n return;\n }\n if (container.nodeType === Node.TEXT_NODE) {\n return container;\n } else if (offset === 0) {\n return container.firstChild != null ? container.firstChild : container;\n } else {\n return container.childNodes.item(offset - 1);\n }\n };\n const findElementFromContainerAndOffset = function (container, offset) {\n const node = findNodeFromContainerAndOffset(container, offset);\n return findClosestElementFromNode(node);\n };\n const findChildIndexOfNode = function (node) {\n var _node;\n if (!((_node = node) !== null && _node !== void 0 && _node.parentNode)) {\n return;\n }\n let childIndex = 0;\n node = node.previousSibling;\n while (node) {\n childIndex++;\n node = node.previousSibling;\n }\n return childIndex;\n };\n const removeNode = node => {\n var _node$parentNode;\n return node === null || node === void 0 || (_node$parentNode = node.parentNode) === null || _node$parentNode === void 0 ? void 0 : _node$parentNode.removeChild(node);\n };\n const walkTree = function (tree) {\n let {\n onlyNodesOfType,\n usingFilter,\n expandEntityReferences\n } = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};\n const whatToShow = (() => {\n switch (onlyNodesOfType) {\n case \"element\":\n return NodeFilter.SHOW_ELEMENT;\n case \"text\":\n return NodeFilter.SHOW_TEXT;\n case \"comment\":\n return NodeFilter.SHOW_COMMENT;\n default:\n return NodeFilter.SHOW_ALL;\n }\n })();\n return document.createTreeWalker(tree, whatToShow, usingFilter != null ? usingFilter : null, expandEntityReferences === true);\n };\n const tagName = element => {\n var _element$tagName;\n return element === null || element === void 0 || (_element$tagName = element.tagName) === null || _element$tagName === void 0 ? void 0 : _element$tagName.toLowerCase();\n };\n const makeElement = function (tag) {\n let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};\n let key, value;\n if (typeof tag === \"object\") {\n options = tag;\n tag = options.tagName;\n } else {\n options = {\n attributes: options\n };\n }\n const element = document.createElement(tag);\n if (options.editable != null) {\n if (options.attributes == null) {\n options.attributes = {};\n }\n options.attributes.contenteditable = options.editable;\n }\n if (options.attributes) {\n for (key in options.attributes) {\n value = options.attributes[key];\n element.setAttribute(key, value);\n }\n }\n if (options.style) {\n for (key in options.style) {\n value = options.style[key];\n element.style[key] = value;\n }\n }\n if (options.data) {\n for (key in options.data) {\n value = options.data[key];\n element.dataset[key] = value;\n }\n }\n if (options.className) {\n options.className.split(\" \").forEach(className => {\n element.classList.add(className);\n });\n }\n if (options.textContent) {\n element.textContent = options.textContent;\n }\n if (options.childNodes) {\n [].concat(options.childNodes).forEach(childNode => {\n element.appendChild(childNode);\n });\n }\n return element;\n };\n let blockTagNames = undefined;\n const getBlockTagNames = function () {\n if (blockTagNames != null) {\n return blockTagNames;\n }\n blockTagNames = [];\n for (const key in attributes) {\n const attributes$1 = attributes[key];\n if (attributes$1.tagName) {\n blockTagNames.push(attributes$1.tagName);\n }\n }\n return blockTagNames;\n };\n const nodeIsBlockContainer = node => nodeIsBlockStartComment(node === null || node === void 0 ? void 0 : node.firstChild);\n const nodeProbablyIsBlockContainer = function (node) {\n return getBlockTagNames().includes(tagName(node)) && !getBlockTagNames().includes(tagName(node.firstChild));\n };\n const nodeIsBlockStart = function (node) {\n let {\n strict\n } = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {\n strict: true\n };\n if (strict) {\n return nodeIsBlockStartComment(node);\n } else {\n return nodeIsBlockStartComment(node) || !nodeIsBlockStartComment(node.firstChild) && nodeProbablyIsBlockContainer(node);\n }\n };\n const nodeIsBlockStartComment = node => nodeIsCommentNode(node) && (node === null || node === void 0 ? void 0 : node.data) === \"block\";\n const nodeIsCommentNode = node => (node === null || node === void 0 ? void 0 : node.nodeType) === Node.COMMENT_NODE;\n const nodeIsCursorTarget = function (node) {\n let {\n name\n } = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};\n if (!node) {\n return;\n }\n if (nodeIsTextNode(node)) {\n if (node.data === ZERO_WIDTH_SPACE) {\n if (name) {\n return node.parentNode.dataset.trixCursorTarget === name;\n } else {\n return true;\n }\n }\n } else {\n return nodeIsCursorTarget(node.firstChild);\n }\n };\n const nodeIsAttachmentElement = node => elementMatchesSelector(node, attachmentSelector);\n const nodeIsEmptyTextNode = node => nodeIsTextNode(node) && (node === null || node === void 0 ? void 0 : node.data) === \"\";\n const nodeIsTextNode = node => (node === null || node === void 0 ? void 0 : node.nodeType) === Node.TEXT_NODE;\n\n const input = {\n level2Enabled: true,\n getLevel() {\n if (this.level2Enabled && browser$1.supportsInputEvents) {\n return 2;\n } else {\n return 0;\n }\n },\n pickFiles(callback) {\n const input = makeElement(\"input\", {\n type: \"file\",\n multiple: true,\n hidden: true,\n id: this.fileInputId\n });\n input.addEventListener(\"change\", () => {\n callback(input.files);\n removeNode(input);\n });\n removeNode(document.getElementById(this.fileInputId));\n document.body.appendChild(input);\n input.click();\n }\n };\n\n var key_names = {\n 8: \"backspace\",\n 9: \"tab\",\n 13: \"return\",\n 27: \"escape\",\n 37: \"left\",\n 39: \"right\",\n 46: \"delete\",\n 68: \"d\",\n 72: \"h\",\n 79: \"o\"\n };\n\n var parser = {\n removeBlankTableCells: false,\n tableCellSeparator: \" | \",\n tableRowSeparator: \"\\n\"\n };\n\n var text_attributes = {\n bold: {\n tagName: \"strong\",\n inheritable: true,\n parser(element) {\n const style = window.getComputedStyle(element);\n return style.fontWeight === \"bold\" || style.fontWeight >= 600;\n }\n },\n italic: {\n tagName: \"em\",\n inheritable: true,\n parser(element) {\n const style = window.getComputedStyle(element);\n return style.fontStyle === \"italic\";\n }\n },\n href: {\n groupTagName: \"a\",\n parser(element) {\n const matchingSelector = \"a:not(\".concat(attachmentSelector, \")\");\n const link = element.closest(matchingSelector);\n if (link) {\n return link.getAttribute(\"href\");\n }\n }\n },\n strike: {\n tagName: \"del\",\n inheritable: true\n },\n frozen: {\n style: {\n backgroundColor: \"highlight\"\n }\n }\n };\n\n var toolbar = {\n getDefaultHTML() {\n return \"
\\n \\n \\n \\n \\n \\n \\n\\n \\n \\n \\n \\n \\n \\n \\n \\n \\n\\n \\n \\n \\n\\n \\n\\n \\n \\n \\n \\n
\\n\\n
\\n
\\n \\n
\\n
\");\n }\n };\n\n const undo = {\n interval: 5000\n };\n\n var config = /*#__PURE__*/Object.freeze({\n __proto__: null,\n attachments: attachments,\n blockAttributes: attributes,\n browser: browser$1,\n css: css$3,\n fileSize: file_size_formatting,\n input: input,\n keyNames: key_names,\n lang: lang$1,\n parser: parser,\n textAttributes: text_attributes,\n toolbar: toolbar,\n undo: undo\n });\n\n class BasicObject {\n static proxyMethod(expression) {\n const {\n name,\n toMethod,\n toProperty,\n optional\n } = parseProxyMethodExpression(expression);\n this.prototype[name] = function () {\n let subject;\n let object;\n if (toMethod) {\n if (optional) {\n var _this$toMethod;\n object = (_this$toMethod = this[toMethod]) === null || _this$toMethod === void 0 ? void 0 : _this$toMethod.call(this);\n } else {\n object = this[toMethod]();\n }\n } else if (toProperty) {\n object = this[toProperty];\n }\n if (optional) {\n var _object;\n subject = (_object = object) === null || _object === void 0 ? void 0 : _object[name];\n if (subject) {\n return apply$1.call(subject, object, arguments);\n }\n } else {\n subject = object[name];\n return apply$1.call(subject, object, arguments);\n }\n };\n }\n }\n const parseProxyMethodExpression = function (expression) {\n const match = expression.match(proxyMethodExpressionPattern);\n if (!match) {\n throw new Error(\"can't parse @proxyMethod expression: \".concat(expression));\n }\n const args = {\n name: match[4]\n };\n if (match[2] != null) {\n args.toMethod = match[1];\n } else {\n args.toProperty = match[1];\n }\n if (match[3] != null) {\n args.optional = true;\n }\n return args;\n };\n const {\n apply: apply$1\n } = Function.prototype;\n const proxyMethodExpressionPattern = new RegExp(\"\\\n^\\\n(.+?)\\\n(\\\\(\\\\))?\\\n(\\\\?)?\\\n\\\\.\\\n(.+?)\\\n$\\\n\");\n\n var _Array$from, _$codePointAt$1, _$1, _String$fromCodePoint;\n class UTF16String extends BasicObject {\n static box() {\n let value = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : \"\";\n if (value instanceof this) {\n return value;\n } else {\n return this.fromUCS2String(value === null || value === void 0 ? void 0 : value.toString());\n }\n }\n static fromUCS2String(ucs2String) {\n return new this(ucs2String, ucs2decode(ucs2String));\n }\n static fromCodepoints(codepoints) {\n return new this(ucs2encode(codepoints), codepoints);\n }\n constructor(ucs2String, codepoints) {\n super(...arguments);\n this.ucs2String = ucs2String;\n this.codepoints = codepoints;\n this.length = this.codepoints.length;\n this.ucs2Length = this.ucs2String.length;\n }\n offsetToUCS2Offset(offset) {\n return ucs2encode(this.codepoints.slice(0, Math.max(0, offset))).length;\n }\n offsetFromUCS2Offset(ucs2Offset) {\n return ucs2decode(this.ucs2String.slice(0, Math.max(0, ucs2Offset))).length;\n }\n slice() {\n return this.constructor.fromCodepoints(this.codepoints.slice(...arguments));\n }\n charAt(offset) {\n return this.slice(offset, offset + 1);\n }\n isEqualTo(value) {\n return this.constructor.box(value).ucs2String === this.ucs2String;\n }\n toJSON() {\n return this.ucs2String;\n }\n getCacheKey() {\n return this.ucs2String;\n }\n toString() {\n return this.ucs2String;\n }\n }\n const hasArrayFrom = ((_Array$from = Array.from) === null || _Array$from === void 0 ? void 0 : _Array$from.call(Array, \"\\ud83d\\udc7c\").length) === 1;\n const hasStringCodePointAt$1 = ((_$codePointAt$1 = (_$1 = \" \").codePointAt) === null || _$codePointAt$1 === void 0 ? void 0 : _$codePointAt$1.call(_$1, 0)) != null;\n const hasStringFromCodePoint = ((_String$fromCodePoint = String.fromCodePoint) === null || _String$fromCodePoint === void 0 ? void 0 : _String$fromCodePoint.call(String, 32, 128124)) === \" \\ud83d\\udc7c\";\n\n // UCS-2 conversion helpers ported from Mathias Bynens' Punycode.js:\n // https://github.com/bestiejs/punycode.js#punycodeucs2\n\n let ucs2decode, ucs2encode;\n\n // Creates an array containing the numeric code points of each Unicode\n // character in the string. While JavaScript uses UCS-2 internally,\n // this function will convert a pair of surrogate halves (each of which\n // UCS-2 exposes as separate characters) into a single code point,\n // matching UTF-16.\n if (hasArrayFrom && hasStringCodePointAt$1) {\n ucs2decode = string => Array.from(string).map(char => char.codePointAt(0));\n } else {\n ucs2decode = function (string) {\n const output = [];\n let counter = 0;\n const {\n length\n } = string;\n while (counter < length) {\n let value = string.charCodeAt(counter++);\n if (0xd800 <= value && value <= 0xdbff && counter < length) {\n // high surrogate, and there is a next character\n const extra = string.charCodeAt(counter++);\n if ((extra & 0xfc00) === 0xdc00) {\n // low surrogate\n value = ((value & 0x3ff) << 10) + (extra & 0x3ff) + 0x10000;\n } else {\n // unmatched surrogate; only append this code unit, in case the\n // next code unit is the high surrogate of a surrogate pair\n counter--;\n }\n }\n output.push(value);\n }\n return output;\n };\n }\n\n // Creates a string based on an array of numeric code points.\n if (hasStringFromCodePoint) {\n ucs2encode = array => String.fromCodePoint(...Array.from(array || []));\n } else {\n ucs2encode = function (array) {\n const characters = (() => {\n const result = [];\n Array.from(array).forEach(value => {\n let output = \"\";\n if (value > 0xffff) {\n value -= 0x10000;\n output += String.fromCharCode(value >>> 10 & 0x3ff | 0xd800);\n value = 0xdc00 | value & 0x3ff;\n }\n result.push(output + String.fromCharCode(value));\n });\n return result;\n })();\n return characters.join(\"\");\n };\n }\n\n let id$2 = 0;\n class TrixObject extends BasicObject {\n static fromJSONString(jsonString) {\n return this.fromJSON(JSON.parse(jsonString));\n }\n constructor() {\n super(...arguments);\n this.id = ++id$2;\n }\n hasSameConstructorAs(object) {\n return this.constructor === (object === null || object === void 0 ? void 0 : object.constructor);\n }\n isEqualTo(object) {\n return this === object;\n }\n inspect() {\n const parts = [];\n const contents = this.contentsForInspection() || {};\n for (const key in contents) {\n const value = contents[key];\n parts.push(\"\".concat(key, \"=\").concat(value));\n }\n return \"#<\".concat(this.constructor.name, \":\").concat(this.id).concat(parts.length ? \" \".concat(parts.join(\", \")) : \"\", \">\");\n }\n contentsForInspection() {}\n toJSONString() {\n return JSON.stringify(this);\n }\n toUTF16String() {\n return UTF16String.box(this);\n }\n getCacheKey() {\n return this.id.toString();\n }\n }\n\n /* eslint-disable\n id-length,\n */\n const arraysAreEqual = function () {\n let a = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];\n let b = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];\n if (a.length !== b.length) {\n return false;\n }\n for (let index = 0; index < a.length; index++) {\n const value = a[index];\n if (value !== b[index]) {\n return false;\n }\n }\n return true;\n };\n const arrayStartsWith = function () {\n let a = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];\n let b = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];\n return arraysAreEqual(a.slice(0, b.length), b);\n };\n const spliceArray = function (array) {\n const result = array.slice(0);\n for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {\n args[_key - 1] = arguments[_key];\n }\n result.splice(...args);\n return result;\n };\n const summarizeArrayChange = function () {\n let oldArray = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];\n let newArray = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];\n const added = [];\n const removed = [];\n const existingValues = new Set();\n oldArray.forEach(value => {\n existingValues.add(value);\n });\n const currentValues = new Set();\n newArray.forEach(value => {\n currentValues.add(value);\n if (!existingValues.has(value)) {\n added.push(value);\n }\n });\n oldArray.forEach(value => {\n if (!currentValues.has(value)) {\n removed.push(value);\n }\n });\n return {\n added,\n removed\n };\n };\n\n // https://github.com/mathiasbynens/unicode-2.1.8/blob/master/Bidi_Class/Right_To_Left/regex.js\n const RTL_PATTERN = /[\\u05BE\\u05C0\\u05C3\\u05D0-\\u05EA\\u05F0-\\u05F4\\u061B\\u061F\\u0621-\\u063A\\u0640-\\u064A\\u066D\\u0671-\\u06B7\\u06BA-\\u06BE\\u06C0-\\u06CE\\u06D0-\\u06D5\\u06E5\\u06E6\\u200F\\u202B\\u202E\\uFB1F-\\uFB28\\uFB2A-\\uFB36\\uFB38-\\uFB3C\\uFB3E\\uFB40\\uFB41\\uFB43\\uFB44\\uFB46-\\uFBB1\\uFBD3-\\uFD3D\\uFD50-\\uFD8F\\uFD92-\\uFDC7\\uFDF0-\\uFDFB\\uFE70-\\uFE72\\uFE74\\uFE76-\\uFEFC]/;\n const getDirection = function () {\n const input = makeElement(\"input\", {\n dir: \"auto\",\n name: \"x\",\n dirName: \"x.dir\"\n });\n const textArea = makeElement(\"textarea\", {\n dir: \"auto\",\n name: \"y\",\n dirName: \"y.dir\"\n });\n const form = makeElement(\"form\");\n form.appendChild(input);\n form.appendChild(textArea);\n const supportsDirName = function () {\n try {\n return new FormData(form).has(textArea.dirName);\n } catch (error) {\n return false;\n }\n }();\n const supportsDirSelector = function () {\n try {\n return input.matches(\":dir(ltr),:dir(rtl)\");\n } catch (error) {\n return false;\n }\n }();\n if (supportsDirName) {\n return function (string) {\n textArea.value = string;\n return new FormData(form).get(textArea.dirName);\n };\n } else if (supportsDirSelector) {\n return function (string) {\n input.value = string;\n if (input.matches(\":dir(rtl)\")) {\n return \"rtl\";\n } else {\n return \"ltr\";\n }\n };\n } else {\n return function (string) {\n const char = string.trim().charAt(0);\n if (RTL_PATTERN.test(char)) {\n return \"rtl\";\n } else {\n return \"ltr\";\n }\n };\n }\n }();\n\n let allAttributeNames = null;\n let blockAttributeNames = null;\n let textAttributeNames = null;\n let listAttributeNames = null;\n const getAllAttributeNames = () => {\n if (!allAttributeNames) {\n allAttributeNames = getTextAttributeNames().concat(getBlockAttributeNames());\n }\n return allAttributeNames;\n };\n const getBlockConfig = attributeName => attributes[attributeName];\n const getBlockAttributeNames = () => {\n if (!blockAttributeNames) {\n blockAttributeNames = Object.keys(attributes);\n }\n return blockAttributeNames;\n };\n const getTextConfig = attributeName => text_attributes[attributeName];\n const getTextAttributeNames = () => {\n if (!textAttributeNames) {\n textAttributeNames = Object.keys(text_attributes);\n }\n return textAttributeNames;\n };\n const getListAttributeNames = () => {\n if (!listAttributeNames) {\n listAttributeNames = [];\n for (const key in attributes) {\n const {\n listAttribute\n } = attributes[key];\n if (listAttribute != null) {\n listAttributeNames.push(listAttribute);\n }\n }\n }\n return listAttributeNames;\n };\n\n /* eslint-disable\n */\n const installDefaultCSSForTagName = function (tagName, defaultCSS) {\n const styleElement = insertStyleElementForTagName(tagName);\n styleElement.textContent = defaultCSS.replace(/%t/g, tagName);\n };\n const insertStyleElementForTagName = function (tagName) {\n const element = document.createElement(\"style\");\n element.setAttribute(\"type\", \"text/css\");\n element.setAttribute(\"data-tag-name\", tagName.toLowerCase());\n const nonce = getCSPNonce();\n if (nonce) {\n element.setAttribute(\"nonce\", nonce);\n }\n document.head.insertBefore(element, document.head.firstChild);\n return element;\n };\n const getCSPNonce = function () {\n const element = getMetaElement(\"trix-csp-nonce\") || getMetaElement(\"csp-nonce\");\n if (element) {\n const {\n nonce,\n content\n } = element;\n return nonce == \"\" ? content : nonce;\n }\n };\n const getMetaElement = name => document.head.querySelector(\"meta[name=\".concat(name, \"]\"));\n\n const testTransferData = {\n \"application/x-trix-feature-detection\": \"test\"\n };\n const dataTransferIsPlainText = function (dataTransfer) {\n const text = dataTransfer.getData(\"text/plain\");\n const html = dataTransfer.getData(\"text/html\");\n if (text && html) {\n const {\n body\n } = new DOMParser().parseFromString(html, \"text/html\");\n if (body.textContent === text) {\n return !body.querySelector(\"*\");\n }\n } else {\n return text === null || text === void 0 ? void 0 : text.length;\n }\n };\n const dataTransferIsMsOfficePaste = _ref => {\n let {\n dataTransfer\n } = _ref;\n return dataTransfer.types.includes(\"Files\") && dataTransfer.types.includes(\"text/html\") && dataTransfer.getData(\"text/html\").includes(\"urn:schemas-microsoft-com:office:office\");\n };\n const dataTransferIsWritable = function (dataTransfer) {\n if (!(dataTransfer !== null && dataTransfer !== void 0 && dataTransfer.setData)) return false;\n for (const key in testTransferData) {\n const value = testTransferData[key];\n try {\n dataTransfer.setData(key, value);\n if (!dataTransfer.getData(key) === value) return false;\n } catch (error) {\n return false;\n }\n }\n return true;\n };\n const keyEventIsKeyboardCommand = function () {\n if (/Mac|^iP/.test(navigator.platform)) {\n return event => event.metaKey;\n } else {\n return event => event.ctrlKey;\n }\n }();\n function shouldRenderInmmediatelyToDealWithIOSDictation(inputEvent) {\n if (/iPhone|iPad/.test(navigator.userAgent)) {\n // Handle garbled content and duplicated newlines when using dictation on iOS 18+. Upon dictation completion, iOS sends\n // the list of insertText / insertParagraph events in a quick sequence. If we don't render\n // the editor synchronously, the internal range fails to update and results in garbled content or duplicated newlines.\n //\n // This workaround is necessary because iOS doesn't send composing events as expected while dictating:\n // https://bugs.webkit.org/show_bug.cgi?id=261764\n return !inputEvent.inputType || inputEvent.inputType === \"insertParagraph\";\n } else {\n return false;\n }\n }\n\n const defer = fn => setTimeout(fn, 1);\n\n /* eslint-disable\n id-length,\n */\n const copyObject = function () {\n let object = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};\n const result = {};\n for (const key in object) {\n const value = object[key];\n result[key] = value;\n }\n return result;\n };\n const objectsAreEqual = function () {\n let a = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};\n let b = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};\n if (Object.keys(a).length !== Object.keys(b).length) {\n return false;\n }\n for (const key in a) {\n const value = a[key];\n if (value !== b[key]) {\n return false;\n }\n }\n return true;\n };\n\n const normalizeRange = function (range) {\n if (range == null) return;\n if (!Array.isArray(range)) {\n range = [range, range];\n }\n return [copyValue(range[0]), copyValue(range[1] != null ? range[1] : range[0])];\n };\n const rangeIsCollapsed = function (range) {\n if (range == null) return;\n const [start, end] = normalizeRange(range);\n return rangeValuesAreEqual(start, end);\n };\n const rangesAreEqual = function (leftRange, rightRange) {\n if (leftRange == null || rightRange == null) return;\n const [leftStart, leftEnd] = normalizeRange(leftRange);\n const [rightStart, rightEnd] = normalizeRange(rightRange);\n return rangeValuesAreEqual(leftStart, rightStart) && rangeValuesAreEqual(leftEnd, rightEnd);\n };\n const copyValue = function (value) {\n if (typeof value === \"number\") {\n return value;\n } else {\n return copyObject(value);\n }\n };\n const rangeValuesAreEqual = function (left, right) {\n if (typeof left === \"number\") {\n return left === right;\n } else {\n return objectsAreEqual(left, right);\n }\n };\n\n class SelectionChangeObserver extends BasicObject {\n constructor() {\n super(...arguments);\n this.update = this.update.bind(this);\n this.selectionManagers = [];\n }\n start() {\n if (!this.started) {\n this.started = true;\n document.addEventListener(\"selectionchange\", this.update, true);\n }\n }\n stop() {\n if (this.started) {\n this.started = false;\n return document.removeEventListener(\"selectionchange\", this.update, true);\n }\n }\n registerSelectionManager(selectionManager) {\n if (!this.selectionManagers.includes(selectionManager)) {\n this.selectionManagers.push(selectionManager);\n return this.start();\n }\n }\n unregisterSelectionManager(selectionManager) {\n this.selectionManagers = this.selectionManagers.filter(sm => sm !== selectionManager);\n if (this.selectionManagers.length === 0) {\n return this.stop();\n }\n }\n notifySelectionManagersOfSelectionChange() {\n return this.selectionManagers.map(selectionManager => selectionManager.selectionDidChange());\n }\n update() {\n this.notifySelectionManagersOfSelectionChange();\n }\n reset() {\n this.update();\n }\n }\n const selectionChangeObserver = new SelectionChangeObserver();\n const getDOMSelection = function () {\n const selection = window.getSelection();\n if (selection.rangeCount > 0) {\n return selection;\n }\n };\n const getDOMRange = function () {\n var _getDOMSelection;\n const domRange = (_getDOMSelection = getDOMSelection()) === null || _getDOMSelection === void 0 ? void 0 : _getDOMSelection.getRangeAt(0);\n if (domRange) {\n if (!domRangeIsPrivate(domRange)) {\n return domRange;\n }\n }\n };\n const setDOMRange = function (domRange) {\n const selection = window.getSelection();\n selection.removeAllRanges();\n selection.addRange(domRange);\n return selectionChangeObserver.update();\n };\n\n // In Firefox, clicking certain elements changes the selection to a\n // private element used to draw its UI. Attempting to access properties of those\n // elements throws an error.\n // https://bugzilla.mozilla.org/show_bug.cgi?id=208427\n const domRangeIsPrivate = domRange => nodeIsPrivate(domRange.startContainer) || nodeIsPrivate(domRange.endContainer);\n const nodeIsPrivate = node => !Object.getPrototypeOf(node);\n\n /* eslint-disable\n id-length,\n no-useless-escape,\n */\n const normalizeSpaces = string => string.replace(new RegExp(\"\".concat(ZERO_WIDTH_SPACE), \"g\"), \"\").replace(new RegExp(\"\".concat(NON_BREAKING_SPACE), \"g\"), \" \");\n const normalizeNewlines = string => string.replace(/\\r\\n?/g, \"\\n\");\n const breakableWhitespacePattern = new RegExp(\"[^\\\\S\".concat(NON_BREAKING_SPACE, \"]\"));\n const squishBreakableWhitespace = string => string\n // Replace all breakable whitespace characters with a space\n .replace(new RegExp(\"\".concat(breakableWhitespacePattern.source), \"g\"), \" \")\n // Replace two or more spaces with a single space\n .replace(/\\ {2,}/g, \" \");\n const summarizeStringChange = function (oldString, newString) {\n let added, removed;\n oldString = UTF16String.box(oldString);\n newString = UTF16String.box(newString);\n if (newString.length < oldString.length) {\n [removed, added] = utf16StringDifferences(oldString, newString);\n } else {\n [added, removed] = utf16StringDifferences(newString, oldString);\n }\n return {\n added,\n removed\n };\n };\n const utf16StringDifferences = function (a, b) {\n if (a.isEqualTo(b)) {\n return [\"\", \"\"];\n }\n const diffA = utf16StringDifference(a, b);\n const {\n length\n } = diffA.utf16String;\n let diffB;\n if (length) {\n const {\n offset\n } = diffA;\n const codepoints = a.codepoints.slice(0, offset).concat(a.codepoints.slice(offset + length));\n diffB = utf16StringDifference(b, UTF16String.fromCodepoints(codepoints));\n } else {\n diffB = utf16StringDifference(b, a);\n }\n return [diffA.utf16String.toString(), diffB.utf16String.toString()];\n };\n const utf16StringDifference = function (a, b) {\n let leftIndex = 0;\n let rightIndexA = a.length;\n let rightIndexB = b.length;\n while (leftIndex < rightIndexA && a.charAt(leftIndex).isEqualTo(b.charAt(leftIndex))) {\n leftIndex++;\n }\n while (rightIndexA > leftIndex + 1 && a.charAt(rightIndexA - 1).isEqualTo(b.charAt(rightIndexB - 1))) {\n rightIndexA--;\n rightIndexB--;\n }\n return {\n utf16String: a.slice(leftIndex, rightIndexA),\n offset: leftIndex\n };\n };\n\n class Hash extends TrixObject {\n static fromCommonAttributesOfObjects() {\n let objects = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];\n if (!objects.length) {\n return new this();\n }\n let hash = box(objects[0]);\n let keys = hash.getKeys();\n objects.slice(1).forEach(object => {\n keys = hash.getKeysCommonToHash(box(object));\n hash = hash.slice(keys);\n });\n return hash;\n }\n static box(values) {\n return box(values);\n }\n constructor() {\n let values = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};\n super(...arguments);\n this.values = copy(values);\n }\n add(key, value) {\n return this.merge(object(key, value));\n }\n remove(key) {\n return new Hash(copy(this.values, key));\n }\n get(key) {\n return this.values[key];\n }\n has(key) {\n return key in this.values;\n }\n merge(values) {\n return new Hash(merge(this.values, unbox(values)));\n }\n slice(keys) {\n const values = {};\n Array.from(keys).forEach(key => {\n if (this.has(key)) {\n values[key] = this.values[key];\n }\n });\n return new Hash(values);\n }\n getKeys() {\n return Object.keys(this.values);\n }\n getKeysCommonToHash(hash) {\n hash = box(hash);\n return this.getKeys().filter(key => this.values[key] === hash.values[key]);\n }\n isEqualTo(values) {\n return arraysAreEqual(this.toArray(), box(values).toArray());\n }\n isEmpty() {\n return this.getKeys().length === 0;\n }\n toArray() {\n if (!this.array) {\n const result = [];\n for (const key in this.values) {\n const value = this.values[key];\n result.push(result.push(key, value));\n }\n this.array = result.slice(0);\n }\n return this.array;\n }\n toObject() {\n return copy(this.values);\n }\n toJSON() {\n return this.toObject();\n }\n contentsForInspection() {\n return {\n values: JSON.stringify(this.values)\n };\n }\n }\n const object = function (key, value) {\n const result = {};\n result[key] = value;\n return result;\n };\n const merge = function (object, values) {\n const result = copy(object);\n for (const key in values) {\n const value = values[key];\n result[key] = value;\n }\n return result;\n };\n const copy = function (object, keyToRemove) {\n const result = {};\n const sortedKeys = Object.keys(object).sort();\n sortedKeys.forEach(key => {\n if (key !== keyToRemove) {\n result[key] = object[key];\n }\n });\n return result;\n };\n const box = function (object) {\n if (object instanceof Hash) {\n return object;\n } else {\n return new Hash(object);\n }\n };\n const unbox = function (object) {\n if (object instanceof Hash) {\n return object.values;\n } else {\n return object;\n }\n };\n\n class ObjectGroup {\n static groupObjects() {\n let ungroupedObjects = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];\n let {\n depth,\n asTree\n } = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};\n let group;\n if (asTree) {\n if (depth == null) {\n depth = 0;\n }\n }\n const objects = [];\n Array.from(ungroupedObjects).forEach(object => {\n var _object$canBeGrouped2;\n if (group) {\n var _object$canBeGrouped, _group$canBeGroupedWi, _group;\n if ((_object$canBeGrouped = object.canBeGrouped) !== null && _object$canBeGrouped !== void 0 && _object$canBeGrouped.call(object, depth) && (_group$canBeGroupedWi = (_group = group[group.length - 1]).canBeGroupedWith) !== null && _group$canBeGroupedWi !== void 0 && _group$canBeGroupedWi.call(_group, object, depth)) {\n group.push(object);\n return;\n } else {\n objects.push(new this(group, {\n depth,\n asTree\n }));\n group = null;\n }\n }\n if ((_object$canBeGrouped2 = object.canBeGrouped) !== null && _object$canBeGrouped2 !== void 0 && _object$canBeGrouped2.call(object, depth)) {\n group = [object];\n } else {\n objects.push(object);\n }\n });\n if (group) {\n objects.push(new this(group, {\n depth,\n asTree\n }));\n }\n return objects;\n }\n constructor() {\n let objects = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];\n let {\n depth,\n asTree\n } = arguments.length > 1 ? arguments[1] : undefined;\n this.objects = objects;\n if (asTree) {\n this.depth = depth;\n this.objects = this.constructor.groupObjects(this.objects, {\n asTree,\n depth: this.depth + 1\n });\n }\n }\n getObjects() {\n return this.objects;\n }\n getDepth() {\n return this.depth;\n }\n getCacheKey() {\n const keys = [\"objectGroup\"];\n Array.from(this.getObjects()).forEach(object => {\n keys.push(object.getCacheKey());\n });\n return keys.join(\"/\");\n }\n }\n\n class ObjectMap extends BasicObject {\n constructor() {\n let objects = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];\n super(...arguments);\n this.objects = {};\n Array.from(objects).forEach(object => {\n const hash = JSON.stringify(object);\n if (this.objects[hash] == null) {\n this.objects[hash] = object;\n }\n });\n }\n find(object) {\n const hash = JSON.stringify(object);\n return this.objects[hash];\n }\n }\n\n class ElementStore {\n constructor(elements) {\n this.reset(elements);\n }\n add(element) {\n const key = getKey(element);\n this.elements[key] = element;\n }\n remove(element) {\n const key = getKey(element);\n const value = this.elements[key];\n if (value) {\n delete this.elements[key];\n return value;\n }\n }\n reset() {\n let elements = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];\n this.elements = {};\n Array.from(elements).forEach(element => {\n this.add(element);\n });\n return elements;\n }\n }\n const getKey = element => element.dataset.trixStoreKey;\n\n class Operation extends BasicObject {\n isPerforming() {\n return this.performing === true;\n }\n hasPerformed() {\n return this.performed === true;\n }\n hasSucceeded() {\n return this.performed && this.succeeded;\n }\n hasFailed() {\n return this.performed && !this.succeeded;\n }\n getPromise() {\n if (!this.promise) {\n this.promise = new Promise((resolve, reject) => {\n this.performing = true;\n return this.perform((succeeded, result) => {\n this.succeeded = succeeded;\n this.performing = false;\n this.performed = true;\n if (this.succeeded) {\n resolve(result);\n } else {\n reject(result);\n }\n });\n });\n }\n return this.promise;\n }\n perform(callback) {\n return callback(false);\n }\n release() {\n var _this$promise, _this$promise$cancel;\n (_this$promise = this.promise) === null || _this$promise === void 0 || (_this$promise$cancel = _this$promise.cancel) === null || _this$promise$cancel === void 0 || _this$promise$cancel.call(_this$promise);\n this.promise = null;\n this.performing = null;\n this.performed = null;\n this.succeeded = null;\n }\n }\n Operation.proxyMethod(\"getPromise().then\");\n Operation.proxyMethod(\"getPromise().catch\");\n\n class ObjectView extends BasicObject {\n constructor(object) {\n let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};\n super(...arguments);\n this.object = object;\n this.options = options;\n this.childViews = [];\n this.rootView = this;\n }\n getNodes() {\n if (!this.nodes) {\n this.nodes = this.createNodes();\n }\n return this.nodes.map(node => node.cloneNode(true));\n }\n invalidate() {\n var _this$parentView;\n this.nodes = null;\n this.childViews = [];\n return (_this$parentView = this.parentView) === null || _this$parentView === void 0 ? void 0 : _this$parentView.invalidate();\n }\n invalidateViewForObject(object) {\n var _this$findViewForObje;\n return (_this$findViewForObje = this.findViewForObject(object)) === null || _this$findViewForObje === void 0 ? void 0 : _this$findViewForObje.invalidate();\n }\n findOrCreateCachedChildView(viewClass, object, options) {\n let view = this.getCachedViewForObject(object);\n if (view) {\n this.recordChildView(view);\n } else {\n view = this.createChildView(...arguments);\n this.cacheViewForObject(view, object);\n }\n return view;\n }\n createChildView(viewClass, object) {\n let options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};\n if (object instanceof ObjectGroup) {\n options.viewClass = viewClass;\n viewClass = ObjectGroupView;\n }\n const view = new viewClass(object, options);\n return this.recordChildView(view);\n }\n recordChildView(view) {\n view.parentView = this;\n view.rootView = this.rootView;\n this.childViews.push(view);\n return view;\n }\n getAllChildViews() {\n let views = [];\n this.childViews.forEach(childView => {\n views.push(childView);\n views = views.concat(childView.getAllChildViews());\n });\n return views;\n }\n findElement() {\n return this.findElementForObject(this.object);\n }\n findElementForObject(object) {\n const id = object === null || object === void 0 ? void 0 : object.id;\n if (id) {\n return this.rootView.element.querySelector(\"[data-trix-id='\".concat(id, \"']\"));\n }\n }\n findViewForObject(object) {\n for (const view of this.getAllChildViews()) {\n if (view.object === object) {\n return view;\n }\n }\n }\n getViewCache() {\n if (this.rootView === this) {\n if (this.isViewCachingEnabled()) {\n if (!this.viewCache) {\n this.viewCache = {};\n }\n return this.viewCache;\n }\n } else {\n return this.rootView.getViewCache();\n }\n }\n isViewCachingEnabled() {\n return this.shouldCacheViews !== false;\n }\n enableViewCaching() {\n this.shouldCacheViews = true;\n }\n disableViewCaching() {\n this.shouldCacheViews = false;\n }\n getCachedViewForObject(object) {\n var _this$getViewCache;\n return (_this$getViewCache = this.getViewCache()) === null || _this$getViewCache === void 0 ? void 0 : _this$getViewCache[object.getCacheKey()];\n }\n cacheViewForObject(view, object) {\n const cache = this.getViewCache();\n if (cache) {\n cache[object.getCacheKey()] = view;\n }\n }\n garbageCollectCachedViews() {\n const cache = this.getViewCache();\n if (cache) {\n const views = this.getAllChildViews().concat(this);\n const objectKeys = views.map(view => view.object.getCacheKey());\n for (const key in cache) {\n if (!objectKeys.includes(key)) {\n delete cache[key];\n }\n }\n }\n }\n }\n class ObjectGroupView extends ObjectView {\n constructor() {\n super(...arguments);\n this.objectGroup = this.object;\n this.viewClass = this.options.viewClass;\n delete this.options.viewClass;\n }\n getChildViews() {\n if (!this.childViews.length) {\n Array.from(this.objectGroup.getObjects()).forEach(object => {\n this.findOrCreateCachedChildView(this.viewClass, object, this.options);\n });\n }\n return this.childViews;\n }\n createNodes() {\n const element = this.createContainerElement();\n this.getChildViews().forEach(view => {\n Array.from(view.getNodes()).forEach(node => {\n element.appendChild(node);\n });\n });\n return [element];\n }\n createContainerElement() {\n let depth = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : this.objectGroup.getDepth();\n return this.getChildViews()[0].createContainerElement(depth);\n }\n }\n\n /*! @license DOMPurify 3.2.3 | (c) Cure53 and other contributors | Released under the Apache license 2.0 and Mozilla Public License 2.0 | github.com/cure53/DOMPurify/blob/3.2.3/LICENSE */\n\n const {\n entries,\n setPrototypeOf,\n isFrozen,\n getPrototypeOf,\n getOwnPropertyDescriptor\n } = Object;\n let {\n freeze,\n seal,\n create\n } = Object; // eslint-disable-line import/no-mutable-exports\n let {\n apply,\n construct\n } = typeof Reflect !== 'undefined' && Reflect;\n if (!freeze) {\n freeze = function freeze(x) {\n return x;\n };\n }\n if (!seal) {\n seal = function seal(x) {\n return x;\n };\n }\n if (!apply) {\n apply = function apply(fun, thisValue, args) {\n return fun.apply(thisValue, args);\n };\n }\n if (!construct) {\n construct = function construct(Func, args) {\n return new Func(...args);\n };\n }\n const arrayForEach = unapply(Array.prototype.forEach);\n const arrayPop = unapply(Array.prototype.pop);\n const arrayPush = unapply(Array.prototype.push);\n const stringToLowerCase = unapply(String.prototype.toLowerCase);\n const stringToString = unapply(String.prototype.toString);\n const stringMatch = unapply(String.prototype.match);\n const stringReplace = unapply(String.prototype.replace);\n const stringIndexOf = unapply(String.prototype.indexOf);\n const stringTrim = unapply(String.prototype.trim);\n const objectHasOwnProperty = unapply(Object.prototype.hasOwnProperty);\n const regExpTest = unapply(RegExp.prototype.test);\n const typeErrorCreate = unconstruct(TypeError);\n /**\n * Creates a new function that calls the given function with a specified thisArg and arguments.\n *\n * @param func - The function to be wrapped and called.\n * @returns A new function that calls the given function with a specified thisArg and arguments.\n */\n function unapply(func) {\n return function (thisArg) {\n for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {\n args[_key - 1] = arguments[_key];\n }\n return apply(func, thisArg, args);\n };\n }\n /**\n * Creates a new function that constructs an instance of the given constructor function with the provided arguments.\n *\n * @param func - The constructor function to be wrapped and called.\n * @returns A new function that constructs an instance of the given constructor function with the provided arguments.\n */\n function unconstruct(func) {\n return function () {\n for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {\n args[_key2] = arguments[_key2];\n }\n return construct(func, args);\n };\n }\n /**\n * Add properties to a lookup table\n *\n * @param set - The set to which elements will be added.\n * @param array - The array containing elements to be added to the set.\n * @param transformCaseFunc - An optional function to transform the case of each element before adding to the set.\n * @returns The modified set with added elements.\n */\n function addToSet(set, array) {\n let transformCaseFunc = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : stringToLowerCase;\n if (setPrototypeOf) {\n // Make 'in' and truthy checks like Boolean(set.constructor)\n // independent of any properties defined on Object.prototype.\n // Prevent prototype setters from intercepting set as a this value.\n setPrototypeOf(set, null);\n }\n let l = array.length;\n while (l--) {\n let element = array[l];\n if (typeof element === 'string') {\n const lcElement = transformCaseFunc(element);\n if (lcElement !== element) {\n // Config presets (e.g. tags.js, attrs.js) are immutable.\n if (!isFrozen(array)) {\n array[l] = lcElement;\n }\n element = lcElement;\n }\n }\n set[element] = true;\n }\n return set;\n }\n /**\n * Clean up an array to harden against CSPP\n *\n * @param array - The array to be cleaned.\n * @returns The cleaned version of the array\n */\n function cleanArray(array) {\n for (let index = 0; index < array.length; index++) {\n const isPropertyExist = objectHasOwnProperty(array, index);\n if (!isPropertyExist) {\n array[index] = null;\n }\n }\n return array;\n }\n /**\n * Shallow clone an object\n *\n * @param object - The object to be cloned.\n * @returns A new object that copies the original.\n */\n function clone(object) {\n const newObject = create(null);\n for (const [property, value] of entries(object)) {\n const isPropertyExist = objectHasOwnProperty(object, property);\n if (isPropertyExist) {\n if (Array.isArray(value)) {\n newObject[property] = cleanArray(value);\n } else if (value && typeof value === 'object' && value.constructor === Object) {\n newObject[property] = clone(value);\n } else {\n newObject[property] = value;\n }\n }\n }\n return newObject;\n }\n /**\n * This method automatically checks if the prop is function or getter and behaves accordingly.\n *\n * @param object - The object to look up the getter function in its prototype chain.\n * @param prop - The property name for which to find the getter function.\n * @returns The getter function found in the prototype chain or a fallback function.\n */\n function lookupGetter(object, prop) {\n while (object !== null) {\n const desc = getOwnPropertyDescriptor(object, prop);\n if (desc) {\n if (desc.get) {\n return unapply(desc.get);\n }\n if (typeof desc.value === 'function') {\n return unapply(desc.value);\n }\n }\n object = getPrototypeOf(object);\n }\n function fallbackValue() {\n return null;\n }\n return fallbackValue;\n }\n const html$1 = freeze(['a', 'abbr', 'acronym', 'address', 'area', 'article', 'aside', 'audio', 'b', 'bdi', 'bdo', 'big', 'blink', 'blockquote', 'body', 'br', 'button', 'canvas', 'caption', 'center', 'cite', 'code', 'col', 'colgroup', 'content', 'data', 'datalist', 'dd', 'decorator', 'del', 'details', 'dfn', 'dialog', 'dir', 'div', 'dl', 'dt', 'element', 'em', 'fieldset', 'figcaption', 'figure', 'font', 'footer', 'form', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'head', 'header', 'hgroup', 'hr', 'html', 'i', 'img', 'input', 'ins', 'kbd', 'label', 'legend', 'li', 'main', 'map', 'mark', 'marquee', 'menu', 'menuitem', 'meter', 'nav', 'nobr', 'ol', 'optgroup', 'option', 'output', 'p', 'picture', 'pre', 'progress', 'q', 'rp', 'rt', 'ruby', 's', 'samp', 'section', 'select', 'shadow', 'small', 'source', 'spacer', 'span', 'strike', 'strong', 'style', 'sub', 'summary', 'sup', 'table', 'tbody', 'td', 'template', 'textarea', 'tfoot', 'th', 'thead', 'time', 'tr', 'track', 'tt', 'u', 'ul', 'var', 'video', 'wbr']);\n const svg$1 = freeze(['svg', 'a', 'altglyph', 'altglyphdef', 'altglyphitem', 'animatecolor', 'animatemotion', 'animatetransform', 'circle', 'clippath', 'defs', 'desc', 'ellipse', 'filter', 'font', 'g', 'glyph', 'glyphref', 'hkern', 'image', 'line', 'lineargradient', 'marker', 'mask', 'metadata', 'mpath', 'path', 'pattern', 'polygon', 'polyline', 'radialgradient', 'rect', 'stop', 'style', 'switch', 'symbol', 'text', 'textpath', 'title', 'tref', 'tspan', 'view', 'vkern']);\n const svgFilters = freeze(['feBlend', 'feColorMatrix', 'feComponentTransfer', 'feComposite', 'feConvolveMatrix', 'feDiffuseLighting', 'feDisplacementMap', 'feDistantLight', 'feDropShadow', 'feFlood', 'feFuncA', 'feFuncB', 'feFuncG', 'feFuncR', 'feGaussianBlur', 'feImage', 'feMerge', 'feMergeNode', 'feMorphology', 'feOffset', 'fePointLight', 'feSpecularLighting', 'feSpotLight', 'feTile', 'feTurbulence']);\n // List of SVG elements that are disallowed by default.\n // We still need to know them so that we can do namespace\n // checks properly in case one wants to add them to\n // allow-list.\n const svgDisallowed = freeze(['animate', 'color-profile', 'cursor', 'discard', 'font-face', 'font-face-format', 'font-face-name', 'font-face-src', 'font-face-uri', 'foreignobject', 'hatch', 'hatchpath', 'mesh', 'meshgradient', 'meshpatch', 'meshrow', 'missing-glyph', 'script', 'set', 'solidcolor', 'unknown', 'use']);\n const mathMl$1 = freeze(['math', 'menclose', 'merror', 'mfenced', 'mfrac', 'mglyph', 'mi', 'mlabeledtr', 'mmultiscripts', 'mn', 'mo', 'mover', 'mpadded', 'mphantom', 'mroot', 'mrow', 'ms', 'mspace', 'msqrt', 'mstyle', 'msub', 'msup', 'msubsup', 'mtable', 'mtd', 'mtext', 'mtr', 'munder', 'munderover', 'mprescripts']);\n // Similarly to SVG, we want to know all MathML elements,\n // even those that we disallow by default.\n const mathMlDisallowed = freeze(['maction', 'maligngroup', 'malignmark', 'mlongdiv', 'mscarries', 'mscarry', 'msgroup', 'mstack', 'msline', 'msrow', 'semantics', 'annotation', 'annotation-xml', 'mprescripts', 'none']);\n const text = freeze(['#text']);\n const html = freeze(['accept', 'action', 'align', 'alt', 'autocapitalize', 'autocomplete', 'autopictureinpicture', 'autoplay', 'background', 'bgcolor', 'border', 'capture', 'cellpadding', 'cellspacing', 'checked', 'cite', 'class', 'clear', 'color', 'cols', 'colspan', 'controls', 'controlslist', 'coords', 'crossorigin', 'datetime', 'decoding', 'default', 'dir', 'disabled', 'disablepictureinpicture', 'disableremoteplayback', 'download', 'draggable', 'enctype', 'enterkeyhint', 'face', 'for', 'headers', 'height', 'hidden', 'high', 'href', 'hreflang', 'id', 'inputmode', 'integrity', 'ismap', 'kind', 'label', 'lang', 'list', 'loading', 'loop', 'low', 'max', 'maxlength', 'media', 'method', 'min', 'minlength', 'multiple', 'muted', 'name', 'nonce', 'noshade', 'novalidate', 'nowrap', 'open', 'optimum', 'pattern', 'placeholder', 'playsinline', 'popover', 'popovertarget', 'popovertargetaction', 'poster', 'preload', 'pubdate', 'radiogroup', 'readonly', 'rel', 'required', 'rev', 'reversed', 'role', 'rows', 'rowspan', 'spellcheck', 'scope', 'selected', 'shape', 'size', 'sizes', 'span', 'srclang', 'start', 'src', 'srcset', 'step', 'style', 'summary', 'tabindex', 'title', 'translate', 'type', 'usemap', 'valign', 'value', 'width', 'wrap', 'xmlns', 'slot']);\n const svg = freeze(['accent-height', 'accumulate', 'additive', 'alignment-baseline', 'amplitude', 'ascent', 'attributename', 'attributetype', 'azimuth', 'basefrequency', 'baseline-shift', 'begin', 'bias', 'by', 'class', 'clip', 'clippathunits', 'clip-path', 'clip-rule', 'color', 'color-interpolation', 'color-interpolation-filters', 'color-profile', 'color-rendering', 'cx', 'cy', 'd', 'dx', 'dy', 'diffuseconstant', 'direction', 'display', 'divisor', 'dur', 'edgemode', 'elevation', 'end', 'exponent', 'fill', 'fill-opacity', 'fill-rule', 'filter', 'filterunits', 'flood-color', 'flood-opacity', 'font-family', 'font-size', 'font-size-adjust', 'font-stretch', 'font-style', 'font-variant', 'font-weight', 'fx', 'fy', 'g1', 'g2', 'glyph-name', 'glyphref', 'gradientunits', 'gradienttransform', 'height', 'href', 'id', 'image-rendering', 'in', 'in2', 'intercept', 'k', 'k1', 'k2', 'k3', 'k4', 'kerning', 'keypoints', 'keysplines', 'keytimes', 'lang', 'lengthadjust', 'letter-spacing', 'kernelmatrix', 'kernelunitlength', 'lighting-color', 'local', 'marker-end', 'marker-mid', 'marker-start', 'markerheight', 'markerunits', 'markerwidth', 'maskcontentunits', 'maskunits', 'max', 'mask', 'media', 'method', 'mode', 'min', 'name', 'numoctaves', 'offset', 'operator', 'opacity', 'order', 'orient', 'orientation', 'origin', 'overflow', 'paint-order', 'path', 'pathlength', 'patterncontentunits', 'patterntransform', 'patternunits', 'points', 'preservealpha', 'preserveaspectratio', 'primitiveunits', 'r', 'rx', 'ry', 'radius', 'refx', 'refy', 'repeatcount', 'repeatdur', 'restart', 'result', 'rotate', 'scale', 'seed', 'shape-rendering', 'slope', 'specularconstant', 'specularexponent', 'spreadmethod', 'startoffset', 'stddeviation', 'stitchtiles', 'stop-color', 'stop-opacity', 'stroke-dasharray', 'stroke-dashoffset', 'stroke-linecap', 'stroke-linejoin', 'stroke-miterlimit', 'stroke-opacity', 'stroke', 'stroke-width', 'style', 'surfacescale', 'systemlanguage', 'tabindex', 'tablevalues', 'targetx', 'targety', 'transform', 'transform-origin', 'text-anchor', 'text-decoration', 'text-rendering', 'textlength', 'type', 'u1', 'u2', 'unicode', 'values', 'viewbox', 'visibility', 'version', 'vert-adv-y', 'vert-origin-x', 'vert-origin-y', 'width', 'word-spacing', 'wrap', 'writing-mode', 'xchannelselector', 'ychannelselector', 'x', 'x1', 'x2', 'xmlns', 'y', 'y1', 'y2', 'z', 'zoomandpan']);\n const mathMl = freeze(['accent', 'accentunder', 'align', 'bevelled', 'close', 'columnsalign', 'columnlines', 'columnspan', 'denomalign', 'depth', 'dir', 'display', 'displaystyle', 'encoding', 'fence', 'frame', 'height', 'href', 'id', 'largeop', 'length', 'linethickness', 'lspace', 'lquote', 'mathbackground', 'mathcolor', 'mathsize', 'mathvariant', 'maxsize', 'minsize', 'movablelimits', 'notation', 'numalign', 'open', 'rowalign', 'rowlines', 'rowspacing', 'rowspan', 'rspace', 'rquote', 'scriptlevel', 'scriptminsize', 'scriptsizemultiplier', 'selection', 'separator', 'separators', 'stretchy', 'subscriptshift', 'supscriptshift', 'symmetric', 'voffset', 'width', 'xmlns']);\n const xml = freeze(['xlink:href', 'xml:id', 'xlink:title', 'xml:space', 'xmlns:xlink']);\n\n // eslint-disable-next-line unicorn/better-regex\n const MUSTACHE_EXPR = seal(/\\{\\{[\\w\\W]*|[\\w\\W]*\\}\\}/gm); // Specify template detection regex for SAFE_FOR_TEMPLATES mode\n const ERB_EXPR = seal(/<%[\\w\\W]*|[\\w\\W]*%>/gm);\n const TMPLIT_EXPR = seal(/\\$\\{[\\w\\W]*}/gm); // eslint-disable-line unicorn/better-regex\n const DATA_ATTR = seal(/^data-[\\-\\w.\\u00B7-\\uFFFF]+$/); // eslint-disable-line no-useless-escape\n const ARIA_ATTR = seal(/^aria-[\\-\\w]+$/); // eslint-disable-line no-useless-escape\n const IS_ALLOWED_URI = seal(/^(?:(?:(?:f|ht)tps?|mailto|tel|callto|sms|cid|xmpp):|[^a-z]|[a-z+.\\-]+(?:[^a-z+.\\-:]|$))/i // eslint-disable-line no-useless-escape\n );\n\n const IS_SCRIPT_OR_DATA = seal(/^(?:\\w+script|data):/i);\n const ATTR_WHITESPACE = seal(/[\\u0000-\\u0020\\u00A0\\u1680\\u180E\\u2000-\\u2029\\u205F\\u3000]/g // eslint-disable-line no-control-regex\n );\n\n const DOCTYPE_NAME = seal(/^html$/i);\n const CUSTOM_ELEMENT = seal(/^[a-z][.\\w]*(-[.\\w]+)+$/i);\n var EXPRESSIONS = /*#__PURE__*/Object.freeze({\n __proto__: null,\n ARIA_ATTR: ARIA_ATTR,\n ATTR_WHITESPACE: ATTR_WHITESPACE,\n CUSTOM_ELEMENT: CUSTOM_ELEMENT,\n DATA_ATTR: DATA_ATTR,\n DOCTYPE_NAME: DOCTYPE_NAME,\n ERB_EXPR: ERB_EXPR,\n IS_ALLOWED_URI: IS_ALLOWED_URI,\n IS_SCRIPT_OR_DATA: IS_SCRIPT_OR_DATA,\n MUSTACHE_EXPR: MUSTACHE_EXPR,\n TMPLIT_EXPR: TMPLIT_EXPR\n });\n\n /* eslint-disable @typescript-eslint/indent */\n // https://developer.mozilla.org/en-US/docs/Web/API/Node/nodeType\n const NODE_TYPE = {\n element: 1,\n attribute: 2,\n text: 3,\n cdataSection: 4,\n entityReference: 5,\n // Deprecated\n entityNode: 6,\n // Deprecated\n progressingInstruction: 7,\n comment: 8,\n document: 9,\n documentType: 10,\n documentFragment: 11,\n notation: 12 // Deprecated\n };\n\n const getGlobal = function getGlobal() {\n return typeof window === 'undefined' ? null : window;\n };\n /**\n * Creates a no-op policy for internal use only.\n * Don't export this function outside this module!\n * @param trustedTypes The policy factory.\n * @param purifyHostElement The Script element used to load DOMPurify (to determine policy name suffix).\n * @return The policy created (or null, if Trusted Types\n * are not supported or creating the policy failed).\n */\n const _createTrustedTypesPolicy = function _createTrustedTypesPolicy(trustedTypes, purifyHostElement) {\n if (typeof trustedTypes !== 'object' || typeof trustedTypes.createPolicy !== 'function') {\n return null;\n }\n // Allow the callers to control the unique policy name\n // by adding a data-tt-policy-suffix to the script element with the DOMPurify.\n // Policy creation with duplicate names throws in Trusted Types.\n let suffix = null;\n const ATTR_NAME = 'data-tt-policy-suffix';\n if (purifyHostElement && purifyHostElement.hasAttribute(ATTR_NAME)) {\n suffix = purifyHostElement.getAttribute(ATTR_NAME);\n }\n const policyName = 'dompurify' + (suffix ? '#' + suffix : '');\n try {\n return trustedTypes.createPolicy(policyName, {\n createHTML(html) {\n return html;\n },\n createScriptURL(scriptUrl) {\n return scriptUrl;\n }\n });\n } catch (_) {\n // Policy creation failed (most likely another DOMPurify script has\n // already run). Skip creating the policy, as this will only cause errors\n // if TT are enforced.\n console.warn('TrustedTypes policy ' + policyName + ' could not be created.');\n return null;\n }\n };\n const _createHooksMap = function _createHooksMap() {\n return {\n afterSanitizeAttributes: [],\n afterSanitizeElements: [],\n afterSanitizeShadowDOM: [],\n beforeSanitizeAttributes: [],\n beforeSanitizeElements: [],\n beforeSanitizeShadowDOM: [],\n uponSanitizeAttribute: [],\n uponSanitizeElement: [],\n uponSanitizeShadowNode: []\n };\n };\n function createDOMPurify() {\n let window = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : getGlobal();\n const DOMPurify = root => createDOMPurify(root);\n DOMPurify.version = '3.2.3';\n DOMPurify.removed = [];\n if (!window || !window.document || window.document.nodeType !== NODE_TYPE.document) {\n // Not running in a browser, provide a factory function\n // so that you can pass your own Window\n DOMPurify.isSupported = false;\n return DOMPurify;\n }\n let {\n document\n } = window;\n const originalDocument = document;\n const currentScript = originalDocument.currentScript;\n const {\n DocumentFragment,\n HTMLTemplateElement,\n Node,\n Element,\n NodeFilter,\n NamedNodeMap = window.NamedNodeMap || window.MozNamedAttrMap,\n HTMLFormElement,\n DOMParser,\n trustedTypes\n } = window;\n const ElementPrototype = Element.prototype;\n const cloneNode = lookupGetter(ElementPrototype, 'cloneNode');\n const remove = lookupGetter(ElementPrototype, 'remove');\n const getNextSibling = lookupGetter(ElementPrototype, 'nextSibling');\n const getChildNodes = lookupGetter(ElementPrototype, 'childNodes');\n const getParentNode = lookupGetter(ElementPrototype, 'parentNode');\n // As per issue #47, the web-components registry is inherited by a\n // new document created via createHTMLDocument. As per the spec\n // (http://w3c.github.io/webcomponents/spec/custom/#creating-and-passing-registries)\n // a new empty registry is used when creating a template contents owner\n // document, so we use that as our parent document to ensure nothing\n // is inherited.\n if (typeof HTMLTemplateElement === 'function') {\n const template = document.createElement('template');\n if (template.content && template.content.ownerDocument) {\n document = template.content.ownerDocument;\n }\n }\n let trustedTypesPolicy;\n let emptyHTML = '';\n const {\n implementation,\n createNodeIterator,\n createDocumentFragment,\n getElementsByTagName\n } = document;\n const {\n importNode\n } = originalDocument;\n let hooks = _createHooksMap();\n /**\n * Expose whether this browser supports running the full DOMPurify.\n */\n DOMPurify.isSupported = typeof entries === 'function' && typeof getParentNode === 'function' && implementation && implementation.createHTMLDocument !== undefined;\n const {\n MUSTACHE_EXPR,\n ERB_EXPR,\n TMPLIT_EXPR,\n DATA_ATTR,\n ARIA_ATTR,\n IS_SCRIPT_OR_DATA,\n ATTR_WHITESPACE,\n CUSTOM_ELEMENT\n } = EXPRESSIONS;\n let {\n IS_ALLOWED_URI: IS_ALLOWED_URI$1\n } = EXPRESSIONS;\n /**\n * We consider the elements and attributes below to be safe. Ideally\n * don't add any new ones but feel free to remove unwanted ones.\n */\n /* allowed element names */\n let ALLOWED_TAGS = null;\n const DEFAULT_ALLOWED_TAGS = addToSet({}, [...html$1, ...svg$1, ...svgFilters, ...mathMl$1, ...text]);\n /* Allowed attribute names */\n let ALLOWED_ATTR = null;\n const DEFAULT_ALLOWED_ATTR = addToSet({}, [...html, ...svg, ...mathMl, ...xml]);\n /*\n * Configure how DOMPurify should handle custom elements and their attributes as well as customized built-in elements.\n * @property {RegExp|Function|null} tagNameCheck one of [null, regexPattern, predicate]. Default: `null` (disallow any custom elements)\n * @property {RegExp|Function|null} attributeNameCheck one of [null, regexPattern, predicate]. Default: `null` (disallow any attributes not on the allow list)\n * @property {boolean} allowCustomizedBuiltInElements allow custom elements derived from built-ins if they pass CUSTOM_ELEMENT_HANDLING.tagNameCheck. Default: `false`.\n */\n let CUSTOM_ELEMENT_HANDLING = Object.seal(create(null, {\n tagNameCheck: {\n writable: true,\n configurable: false,\n enumerable: true,\n value: null\n },\n attributeNameCheck: {\n writable: true,\n configurable: false,\n enumerable: true,\n value: null\n },\n allowCustomizedBuiltInElements: {\n writable: true,\n configurable: false,\n enumerable: true,\n value: false\n }\n }));\n /* Explicitly forbidden tags (overrides ALLOWED_TAGS/ADD_TAGS) */\n let FORBID_TAGS = null;\n /* Explicitly forbidden attributes (overrides ALLOWED_ATTR/ADD_ATTR) */\n let FORBID_ATTR = null;\n /* Decide if ARIA attributes are okay */\n let ALLOW_ARIA_ATTR = true;\n /* Decide if custom data attributes are okay */\n let ALLOW_DATA_ATTR = true;\n /* Decide if unknown protocols are okay */\n let ALLOW_UNKNOWN_PROTOCOLS = false;\n /* Decide if self-closing tags in attributes are allowed.\n * Usually removed due to a mXSS issue in jQuery 3.0 */\n let ALLOW_SELF_CLOSE_IN_ATTR = true;\n /* Output should be safe for common template engines.\n * This means, DOMPurify removes data attributes, mustaches and ERB\n */\n let SAFE_FOR_TEMPLATES = false;\n /* Output should be safe even for XML used within HTML and alike.\n * This means, DOMPurify removes comments when containing risky content.\n */\n let SAFE_FOR_XML = true;\n /* Decide if document with ... should be returned */\n let WHOLE_DOCUMENT = false;\n /* Track whether config is already set on this instance of DOMPurify. */\n let SET_CONFIG = false;\n /* Decide if all elements (e.g. style, script) must be children of\n * document.body. By default, browsers might move them to document.head */\n let FORCE_BODY = false;\n /* Decide if a DOM `HTMLBodyElement` should be returned, instead of a html\n * string (or a TrustedHTML object if Trusted Types are supported).\n * If `WHOLE_DOCUMENT` is enabled a `HTMLHtmlElement` will be returned instead\n */\n let RETURN_DOM = false;\n /* Decide if a DOM `DocumentFragment` should be returned, instead of a html\n * string (or a TrustedHTML object if Trusted Types are supported) */\n let RETURN_DOM_FRAGMENT = false;\n /* Try to return a Trusted Type object instead of a string, return a string in\n * case Trusted Types are not supported */\n let RETURN_TRUSTED_TYPE = false;\n /* Output should be free from DOM clobbering attacks?\n * This sanitizes markups named with colliding, clobberable built-in DOM APIs.\n */\n let SANITIZE_DOM = true;\n /* Achieve full DOM Clobbering protection by isolating the namespace of named\n * properties and JS variables, mitigating attacks that abuse the HTML/DOM spec rules.\n *\n * HTML/DOM spec rules that enable DOM Clobbering:\n * - Named Access on Window (\u00A77.3.3)\n * - DOM Tree Accessors (\u00A73.1.5)\n * - Form Element Parent-Child Relations (\u00A74.10.3)\n * - Iframe srcdoc / Nested WindowProxies (\u00A74.8.5)\n * - HTMLCollection (\u00A74.2.10.2)\n *\n * Namespace isolation is implemented by prefixing `id` and `name` attributes\n * with a constant string, i.e., `user-content-`\n */\n let SANITIZE_NAMED_PROPS = false;\n const SANITIZE_NAMED_PROPS_PREFIX = 'user-content-';\n /* Keep element content when removing element? */\n let KEEP_CONTENT = true;\n /* If a `Node` is passed to sanitize(), then performs sanitization in-place instead\n * of importing it into a new Document and returning a sanitized copy */\n let IN_PLACE = false;\n /* Allow usage of profiles like html, svg and mathMl */\n let USE_PROFILES = {};\n /* Tags to ignore content of when KEEP_CONTENT is true */\n let FORBID_CONTENTS = null;\n const DEFAULT_FORBID_CONTENTS = addToSet({}, ['annotation-xml', 'audio', 'colgroup', 'desc', 'foreignobject', 'head', 'iframe', 'math', 'mi', 'mn', 'mo', 'ms', 'mtext', 'noembed', 'noframes', 'noscript', 'plaintext', 'script', 'style', 'svg', 'template', 'thead', 'title', 'video', 'xmp']);\n /* Tags that are safe for data: URIs */\n let DATA_URI_TAGS = null;\n const DEFAULT_DATA_URI_TAGS = addToSet({}, ['audio', 'video', 'img', 'source', 'image', 'track']);\n /* Attributes safe for values like \"javascript:\" */\n let URI_SAFE_ATTRIBUTES = null;\n const DEFAULT_URI_SAFE_ATTRIBUTES = addToSet({}, ['alt', 'class', 'for', 'id', 'label', 'name', 'pattern', 'placeholder', 'role', 'summary', 'title', 'value', 'style', 'xmlns']);\n const MATHML_NAMESPACE = 'http://www.w3.org/1998/Math/MathML';\n const SVG_NAMESPACE = 'http://www.w3.org/2000/svg';\n const HTML_NAMESPACE = 'http://www.w3.org/1999/xhtml';\n /* Document namespace */\n let NAMESPACE = HTML_NAMESPACE;\n let IS_EMPTY_INPUT = false;\n /* Allowed XHTML+XML namespaces */\n let ALLOWED_NAMESPACES = null;\n const DEFAULT_ALLOWED_NAMESPACES = addToSet({}, [MATHML_NAMESPACE, SVG_NAMESPACE, HTML_NAMESPACE], stringToString);\n let MATHML_TEXT_INTEGRATION_POINTS = addToSet({}, ['mi', 'mo', 'mn', 'ms', 'mtext']);\n let HTML_INTEGRATION_POINTS = addToSet({}, ['annotation-xml']);\n // Certain elements are allowed in both SVG and HTML\n // namespace. We need to specify them explicitly\n // so that they don't get erroneously deleted from\n // HTML namespace.\n const COMMON_SVG_AND_HTML_ELEMENTS = addToSet({}, ['title', 'style', 'font', 'a', 'script']);\n /* Parsing of strict XHTML documents */\n let PARSER_MEDIA_TYPE = null;\n const SUPPORTED_PARSER_MEDIA_TYPES = ['application/xhtml+xml', 'text/html'];\n const DEFAULT_PARSER_MEDIA_TYPE = 'text/html';\n let transformCaseFunc = null;\n /* Keep a reference to config to pass to hooks */\n let CONFIG = null;\n /* Ideally, do not touch anything below this line */\n /* ______________________________________________ */\n const formElement = document.createElement('form');\n const isRegexOrFunction = function isRegexOrFunction(testValue) {\n return testValue instanceof RegExp || testValue instanceof Function;\n };\n /**\n * _parseConfig\n *\n * @param cfg optional config literal\n */\n // eslint-disable-next-line complexity\n const _parseConfig = function _parseConfig() {\n let cfg = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};\n if (CONFIG && CONFIG === cfg) {\n return;\n }\n /* Shield configuration object from tampering */\n if (!cfg || typeof cfg !== 'object') {\n cfg = {};\n }\n /* Shield configuration object from prototype pollution */\n cfg = clone(cfg);\n PARSER_MEDIA_TYPE =\n // eslint-disable-next-line unicorn/prefer-includes\n SUPPORTED_PARSER_MEDIA_TYPES.indexOf(cfg.PARSER_MEDIA_TYPE) === -1 ? DEFAULT_PARSER_MEDIA_TYPE : cfg.PARSER_MEDIA_TYPE;\n // HTML tags and attributes are not case-sensitive, converting to lowercase. Keeping XHTML as is.\n transformCaseFunc = PARSER_MEDIA_TYPE === 'application/xhtml+xml' ? stringToString : stringToLowerCase;\n /* Set configuration parameters */\n ALLOWED_TAGS = objectHasOwnProperty(cfg, 'ALLOWED_TAGS') ? addToSet({}, cfg.ALLOWED_TAGS, transformCaseFunc) : DEFAULT_ALLOWED_TAGS;\n ALLOWED_ATTR = objectHasOwnProperty(cfg, 'ALLOWED_ATTR') ? addToSet({}, cfg.ALLOWED_ATTR, transformCaseFunc) : DEFAULT_ALLOWED_ATTR;\n ALLOWED_NAMESPACES = objectHasOwnProperty(cfg, 'ALLOWED_NAMESPACES') ? addToSet({}, cfg.ALLOWED_NAMESPACES, stringToString) : DEFAULT_ALLOWED_NAMESPACES;\n URI_SAFE_ATTRIBUTES = objectHasOwnProperty(cfg, 'ADD_URI_SAFE_ATTR') ? addToSet(clone(DEFAULT_URI_SAFE_ATTRIBUTES), cfg.ADD_URI_SAFE_ATTR, transformCaseFunc) : DEFAULT_URI_SAFE_ATTRIBUTES;\n DATA_URI_TAGS = objectHasOwnProperty(cfg, 'ADD_DATA_URI_TAGS') ? addToSet(clone(DEFAULT_DATA_URI_TAGS), cfg.ADD_DATA_URI_TAGS, transformCaseFunc) : DEFAULT_DATA_URI_TAGS;\n FORBID_CONTENTS = objectHasOwnProperty(cfg, 'FORBID_CONTENTS') ? addToSet({}, cfg.FORBID_CONTENTS, transformCaseFunc) : DEFAULT_FORBID_CONTENTS;\n FORBID_TAGS = objectHasOwnProperty(cfg, 'FORBID_TAGS') ? addToSet({}, cfg.FORBID_TAGS, transformCaseFunc) : {};\n FORBID_ATTR = objectHasOwnProperty(cfg, 'FORBID_ATTR') ? addToSet({}, cfg.FORBID_ATTR, transformCaseFunc) : {};\n USE_PROFILES = objectHasOwnProperty(cfg, 'USE_PROFILES') ? cfg.USE_PROFILES : false;\n ALLOW_ARIA_ATTR = cfg.ALLOW_ARIA_ATTR !== false; // Default true\n ALLOW_DATA_ATTR = cfg.ALLOW_DATA_ATTR !== false; // Default true\n ALLOW_UNKNOWN_PROTOCOLS = cfg.ALLOW_UNKNOWN_PROTOCOLS || false; // Default false\n ALLOW_SELF_CLOSE_IN_ATTR = cfg.ALLOW_SELF_CLOSE_IN_ATTR !== false; // Default true\n SAFE_FOR_TEMPLATES = cfg.SAFE_FOR_TEMPLATES || false; // Default false\n SAFE_FOR_XML = cfg.SAFE_FOR_XML !== false; // Default true\n WHOLE_DOCUMENT = cfg.WHOLE_DOCUMENT || false; // Default false\n RETURN_DOM = cfg.RETURN_DOM || false; // Default false\n RETURN_DOM_FRAGMENT = cfg.RETURN_DOM_FRAGMENT || false; // Default false\n RETURN_TRUSTED_TYPE = cfg.RETURN_TRUSTED_TYPE || false; // Default false\n FORCE_BODY = cfg.FORCE_BODY || false; // Default false\n SANITIZE_DOM = cfg.SANITIZE_DOM !== false; // Default true\n SANITIZE_NAMED_PROPS = cfg.SANITIZE_NAMED_PROPS || false; // Default false\n KEEP_CONTENT = cfg.KEEP_CONTENT !== false; // Default true\n IN_PLACE = cfg.IN_PLACE || false; // Default false\n IS_ALLOWED_URI$1 = cfg.ALLOWED_URI_REGEXP || IS_ALLOWED_URI;\n NAMESPACE = cfg.NAMESPACE || HTML_NAMESPACE;\n MATHML_TEXT_INTEGRATION_POINTS = cfg.MATHML_TEXT_INTEGRATION_POINTS || MATHML_TEXT_INTEGRATION_POINTS;\n HTML_INTEGRATION_POINTS = cfg.HTML_INTEGRATION_POINTS || HTML_INTEGRATION_POINTS;\n CUSTOM_ELEMENT_HANDLING = cfg.CUSTOM_ELEMENT_HANDLING || {};\n if (cfg.CUSTOM_ELEMENT_HANDLING && isRegexOrFunction(cfg.CUSTOM_ELEMENT_HANDLING.tagNameCheck)) {\n CUSTOM_ELEMENT_HANDLING.tagNameCheck = cfg.CUSTOM_ELEMENT_HANDLING.tagNameCheck;\n }\n if (cfg.CUSTOM_ELEMENT_HANDLING && isRegexOrFunction(cfg.CUSTOM_ELEMENT_HANDLING.attributeNameCheck)) {\n CUSTOM_ELEMENT_HANDLING.attributeNameCheck = cfg.CUSTOM_ELEMENT_HANDLING.attributeNameCheck;\n }\n if (cfg.CUSTOM_ELEMENT_HANDLING && typeof cfg.CUSTOM_ELEMENT_HANDLING.allowCustomizedBuiltInElements === 'boolean') {\n CUSTOM_ELEMENT_HANDLING.allowCustomizedBuiltInElements = cfg.CUSTOM_ELEMENT_HANDLING.allowCustomizedBuiltInElements;\n }\n if (SAFE_FOR_TEMPLATES) {\n ALLOW_DATA_ATTR = false;\n }\n if (RETURN_DOM_FRAGMENT) {\n RETURN_DOM = true;\n }\n /* Parse profile info */\n if (USE_PROFILES) {\n ALLOWED_TAGS = addToSet({}, text);\n ALLOWED_ATTR = [];\n if (USE_PROFILES.html === true) {\n addToSet(ALLOWED_TAGS, html$1);\n addToSet(ALLOWED_ATTR, html);\n }\n if (USE_PROFILES.svg === true) {\n addToSet(ALLOWED_TAGS, svg$1);\n addToSet(ALLOWED_ATTR, svg);\n addToSet(ALLOWED_ATTR, xml);\n }\n if (USE_PROFILES.svgFilters === true) {\n addToSet(ALLOWED_TAGS, svgFilters);\n addToSet(ALLOWED_ATTR, svg);\n addToSet(ALLOWED_ATTR, xml);\n }\n if (USE_PROFILES.mathMl === true) {\n addToSet(ALLOWED_TAGS, mathMl$1);\n addToSet(ALLOWED_ATTR, mathMl);\n addToSet(ALLOWED_ATTR, xml);\n }\n }\n /* Merge configuration parameters */\n if (cfg.ADD_TAGS) {\n if (ALLOWED_TAGS === DEFAULT_ALLOWED_TAGS) {\n ALLOWED_TAGS = clone(ALLOWED_TAGS);\n }\n addToSet(ALLOWED_TAGS, cfg.ADD_TAGS, transformCaseFunc);\n }\n if (cfg.ADD_ATTR) {\n if (ALLOWED_ATTR === DEFAULT_ALLOWED_ATTR) {\n ALLOWED_ATTR = clone(ALLOWED_ATTR);\n }\n addToSet(ALLOWED_ATTR, cfg.ADD_ATTR, transformCaseFunc);\n }\n if (cfg.ADD_URI_SAFE_ATTR) {\n addToSet(URI_SAFE_ATTRIBUTES, cfg.ADD_URI_SAFE_ATTR, transformCaseFunc);\n }\n if (cfg.FORBID_CONTENTS) {\n if (FORBID_CONTENTS === DEFAULT_FORBID_CONTENTS) {\n FORBID_CONTENTS = clone(FORBID_CONTENTS);\n }\n addToSet(FORBID_CONTENTS, cfg.FORBID_CONTENTS, transformCaseFunc);\n }\n /* Add #text in case KEEP_CONTENT is set to true */\n if (KEEP_CONTENT) {\n ALLOWED_TAGS['#text'] = true;\n }\n /* Add html, head and body to ALLOWED_TAGS in case WHOLE_DOCUMENT is true */\n if (WHOLE_DOCUMENT) {\n addToSet(ALLOWED_TAGS, ['html', 'head', 'body']);\n }\n /* Add tbody to ALLOWED_TAGS in case tables are permitted, see #286, #365 */\n if (ALLOWED_TAGS.table) {\n addToSet(ALLOWED_TAGS, ['tbody']);\n delete FORBID_TAGS.tbody;\n }\n if (cfg.TRUSTED_TYPES_POLICY) {\n if (typeof cfg.TRUSTED_TYPES_POLICY.createHTML !== 'function') {\n throw typeErrorCreate('TRUSTED_TYPES_POLICY configuration option must provide a \"createHTML\" hook.');\n }\n if (typeof cfg.TRUSTED_TYPES_POLICY.createScriptURL !== 'function') {\n throw typeErrorCreate('TRUSTED_TYPES_POLICY configuration option must provide a \"createScriptURL\" hook.');\n }\n // Overwrite existing TrustedTypes policy.\n trustedTypesPolicy = cfg.TRUSTED_TYPES_POLICY;\n // Sign local variables required by `sanitize`.\n emptyHTML = trustedTypesPolicy.createHTML('');\n } else {\n // Uninitialized policy, attempt to initialize the internal dompurify policy.\n if (trustedTypesPolicy === undefined) {\n trustedTypesPolicy = _createTrustedTypesPolicy(trustedTypes, currentScript);\n }\n // If creating the internal policy succeeded sign internal variables.\n if (trustedTypesPolicy !== null && typeof emptyHTML === 'string') {\n emptyHTML = trustedTypesPolicy.createHTML('');\n }\n }\n // Prevent further manipulation of configuration.\n // Not available in IE8, Safari 5, etc.\n if (freeze) {\n freeze(cfg);\n }\n CONFIG = cfg;\n };\n /* Keep track of all possible SVG and MathML tags\n * so that we can perform the namespace checks\n * correctly. */\n const ALL_SVG_TAGS = addToSet({}, [...svg$1, ...svgFilters, ...svgDisallowed]);\n const ALL_MATHML_TAGS = addToSet({}, [...mathMl$1, ...mathMlDisallowed]);\n /**\n * @param element a DOM element whose namespace is being checked\n * @returns Return false if the element has a\n * namespace that a spec-compliant parser would never\n * return. Return true otherwise.\n */\n const _checkValidNamespace = function _checkValidNamespace(element) {\n let parent = getParentNode(element);\n // In JSDOM, if we're inside shadow DOM, then parentNode\n // can be null. We just simulate parent in this case.\n if (!parent || !parent.tagName) {\n parent = {\n namespaceURI: NAMESPACE,\n tagName: 'template'\n };\n }\n const tagName = stringToLowerCase(element.tagName);\n const parentTagName = stringToLowerCase(parent.tagName);\n if (!ALLOWED_NAMESPACES[element.namespaceURI]) {\n return false;\n }\n if (element.namespaceURI === SVG_NAMESPACE) {\n // The only way to switch from HTML namespace to SVG\n // is via . If it happens via any other tag, then\n // it should be killed.\n if (parent.namespaceURI === HTML_NAMESPACE) {\n return tagName === 'svg';\n }\n // The only way to switch from MathML to SVG is via`\n // svg if parent is either or MathML\n // text integration points.\n if (parent.namespaceURI === MATHML_NAMESPACE) {\n return tagName === 'svg' && (parentTagName === 'annotation-xml' || MATHML_TEXT_INTEGRATION_POINTS[parentTagName]);\n }\n // We only allow elements that are defined in SVG\n // spec. All others are disallowed in SVG namespace.\n return Boolean(ALL_SVG_TAGS[tagName]);\n }\n if (element.namespaceURI === MATHML_NAMESPACE) {\n // The only way to switch from HTML namespace to MathML\n // is via . If it happens via any other tag, then\n // it should be killed.\n if (parent.namespaceURI === HTML_NAMESPACE) {\n return tagName === 'math';\n }\n // The only way to switch from SVG to MathML is via\n // and HTML integration points\n if (parent.namespaceURI === SVG_NAMESPACE) {\n return tagName === 'math' && HTML_INTEGRATION_POINTS[parentTagName];\n }\n // We only allow elements that are defined in MathML\n // spec. All others are disallowed in MathML namespace.\n return Boolean(ALL_MATHML_TAGS[tagName]);\n }\n if (element.namespaceURI === HTML_NAMESPACE) {\n // The only way to switch from SVG to HTML is via\n // HTML integration points, and from MathML to HTML\n // is via MathML text integration points\n if (parent.namespaceURI === SVG_NAMESPACE && !HTML_INTEGRATION_POINTS[parentTagName]) {\n return false;\n }\n if (parent.namespaceURI === MATHML_NAMESPACE && !MATHML_TEXT_INTEGRATION_POINTS[parentTagName]) {\n return false;\n }\n // We disallow tags that are specific for MathML\n // or SVG and should never appear in HTML namespace\n return !ALL_MATHML_TAGS[tagName] && (COMMON_SVG_AND_HTML_ELEMENTS[tagName] || !ALL_SVG_TAGS[tagName]);\n }\n // For XHTML and XML documents that support custom namespaces\n if (PARSER_MEDIA_TYPE === 'application/xhtml+xml' && ALLOWED_NAMESPACES[element.namespaceURI]) {\n return true;\n }\n // The code should never reach this place (this means\n // that the element somehow got namespace that is not\n // HTML, SVG, MathML or allowed via ALLOWED_NAMESPACES).\n // Return false just in case.\n return false;\n };\n /**\n * _forceRemove\n *\n * @param node a DOM node\n */\n const _forceRemove = function _forceRemove(node) {\n arrayPush(DOMPurify.removed, {\n element: node\n });\n try {\n // eslint-disable-next-line unicorn/prefer-dom-node-remove\n getParentNode(node).removeChild(node);\n } catch (_) {\n remove(node);\n }\n };\n /**\n * _removeAttribute\n *\n * @param name an Attribute name\n * @param element a DOM node\n */\n const _removeAttribute = function _removeAttribute(name, element) {\n try {\n arrayPush(DOMPurify.removed, {\n attribute: element.getAttributeNode(name),\n from: element\n });\n } catch (_) {\n arrayPush(DOMPurify.removed, {\n attribute: null,\n from: element\n });\n }\n element.removeAttribute(name);\n // We void attribute values for unremovable \"is\" attributes\n if (name === 'is') {\n if (RETURN_DOM || RETURN_DOM_FRAGMENT) {\n try {\n _forceRemove(element);\n } catch (_) {}\n } else {\n try {\n element.setAttribute(name, '');\n } catch (_) {}\n }\n }\n };\n /**\n * _initDocument\n *\n * @param dirty - a string of dirty markup\n * @return a DOM, filled with the dirty markup\n */\n const _initDocument = function _initDocument(dirty) {\n /* Create a HTML document */\n let doc = null;\n let leadingWhitespace = null;\n if (FORCE_BODY) {\n dirty = '' + dirty;\n } else {\n /* If FORCE_BODY isn't used, leading whitespace needs to be preserved manually */\n const matches = stringMatch(dirty, /^[\\r\\n\\t ]+/);\n leadingWhitespace = matches && matches[0];\n }\n if (PARSER_MEDIA_TYPE === 'application/xhtml+xml' && NAMESPACE === HTML_NAMESPACE) {\n // Root of XHTML doc must contain xmlns declaration (see https://www.w3.org/TR/xhtml1/normative.html#strict)\n dirty = '' + dirty + '';\n }\n const dirtyPayload = trustedTypesPolicy ? trustedTypesPolicy.createHTML(dirty) : dirty;\n /*\n * Use the DOMParser API by default, fallback later if needs be\n * DOMParser not work for svg when has multiple root element.\n */\n if (NAMESPACE === HTML_NAMESPACE) {\n try {\n doc = new DOMParser().parseFromString(dirtyPayload, PARSER_MEDIA_TYPE);\n } catch (_) {}\n }\n /* Use createHTMLDocument in case DOMParser is not available */\n if (!doc || !doc.documentElement) {\n doc = implementation.createDocument(NAMESPACE, 'template', null);\n try {\n doc.documentElement.innerHTML = IS_EMPTY_INPUT ? emptyHTML : dirtyPayload;\n } catch (_) {\n // Syntax error if dirtyPayload is invalid xml\n }\n }\n const body = doc.body || doc.documentElement;\n if (dirty && leadingWhitespace) {\n body.insertBefore(document.createTextNode(leadingWhitespace), body.childNodes[0] || null);\n }\n /* Work on whole document or just its body */\n if (NAMESPACE === HTML_NAMESPACE) {\n return getElementsByTagName.call(doc, WHOLE_DOCUMENT ? 'html' : 'body')[0];\n }\n return WHOLE_DOCUMENT ? doc.documentElement : body;\n };\n /**\n * Creates a NodeIterator object that you can use to traverse filtered lists of nodes or elements in a document.\n *\n * @param root The root element or node to start traversing on.\n * @return The created NodeIterator\n */\n const _createNodeIterator = function _createNodeIterator(root) {\n return createNodeIterator.call(root.ownerDocument || root, root,\n // eslint-disable-next-line no-bitwise\n NodeFilter.SHOW_ELEMENT | NodeFilter.SHOW_COMMENT | NodeFilter.SHOW_TEXT | NodeFilter.SHOW_PROCESSING_INSTRUCTION | NodeFilter.SHOW_CDATA_SECTION, null);\n };\n /**\n * _isClobbered\n *\n * @param element element to check for clobbering attacks\n * @return true if clobbered, false if safe\n */\n const _isClobbered = function _isClobbered(element) {\n return element instanceof HTMLFormElement && (typeof element.nodeName !== 'string' || typeof element.textContent !== 'string' || typeof element.removeChild !== 'function' || !(element.attributes instanceof NamedNodeMap) || typeof element.removeAttribute !== 'function' || typeof element.setAttribute !== 'function' || typeof element.namespaceURI !== 'string' || typeof element.insertBefore !== 'function' || typeof element.hasChildNodes !== 'function');\n };\n /**\n * Checks whether the given object is a DOM node.\n *\n * @param value object to check whether it's a DOM node\n * @return true is object is a DOM node\n */\n const _isNode = function _isNode(value) {\n return typeof Node === 'function' && value instanceof Node;\n };\n function _executeHooks(hooks, currentNode, data) {\n arrayForEach(hooks, hook => {\n hook.call(DOMPurify, currentNode, data, CONFIG);\n });\n }\n /**\n * _sanitizeElements\n *\n * @protect nodeName\n * @protect textContent\n * @protect removeChild\n * @param currentNode to check for permission to exist\n * @return true if node was killed, false if left alive\n */\n const _sanitizeElements = function _sanitizeElements(currentNode) {\n let content = null;\n /* Execute a hook if present */\n _executeHooks(hooks.beforeSanitizeElements, currentNode, null);\n /* Check if element is clobbered or can clobber */\n if (_isClobbered(currentNode)) {\n _forceRemove(currentNode);\n return true;\n }\n /* Now let's check the element's type and name */\n const tagName = transformCaseFunc(currentNode.nodeName);\n /* Execute a hook if present */\n _executeHooks(hooks.uponSanitizeElement, currentNode, {\n tagName,\n allowedTags: ALLOWED_TAGS\n });\n /* Detect mXSS attempts abusing namespace confusion */\n if (currentNode.hasChildNodes() && !_isNode(currentNode.firstElementChild) && regExpTest(/<[/\\w]/g, currentNode.innerHTML) && regExpTest(/<[/\\w]/g, currentNode.textContent)) {\n _forceRemove(currentNode);\n return true;\n }\n /* Remove any occurrence of processing instructions */\n if (currentNode.nodeType === NODE_TYPE.progressingInstruction) {\n _forceRemove(currentNode);\n return true;\n }\n /* Remove any kind of possibly harmful comments */\n if (SAFE_FOR_XML && currentNode.nodeType === NODE_TYPE.comment && regExpTest(/<[/\\w]/g, currentNode.data)) {\n _forceRemove(currentNode);\n return true;\n }\n /* Remove element if anything forbids its presence */\n if (!ALLOWED_TAGS[tagName] || FORBID_TAGS[tagName]) {\n /* Check if we have a custom element to handle */\n if (!FORBID_TAGS[tagName] && _isBasicCustomElement(tagName)) {\n if (CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof RegExp && regExpTest(CUSTOM_ELEMENT_HANDLING.tagNameCheck, tagName)) {\n return false;\n }\n if (CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof Function && CUSTOM_ELEMENT_HANDLING.tagNameCheck(tagName)) {\n return false;\n }\n }\n /* Keep content except for bad-listed elements */\n if (KEEP_CONTENT && !FORBID_CONTENTS[tagName]) {\n const parentNode = getParentNode(currentNode) || currentNode.parentNode;\n const childNodes = getChildNodes(currentNode) || currentNode.childNodes;\n if (childNodes && parentNode) {\n const childCount = childNodes.length;\n for (let i = childCount - 1; i >= 0; --i) {\n const childClone = cloneNode(childNodes[i], true);\n childClone.__removalCount = (currentNode.__removalCount || 0) + 1;\n parentNode.insertBefore(childClone, getNextSibling(currentNode));\n }\n }\n }\n _forceRemove(currentNode);\n return true;\n }\n /* Check whether element has a valid namespace */\n if (currentNode instanceof Element && !_checkValidNamespace(currentNode)) {\n _forceRemove(currentNode);\n return true;\n }\n /* Make sure that older browsers don't get fallback-tag mXSS */\n if ((tagName === 'noscript' || tagName === 'noembed' || tagName === 'noframes') && regExpTest(/<\\/no(script|embed|frames)/i, currentNode.innerHTML)) {\n _forceRemove(currentNode);\n return true;\n }\n /* Sanitize element content to be template-safe */\n if (SAFE_FOR_TEMPLATES && currentNode.nodeType === NODE_TYPE.text) {\n /* Get the element's text content */\n content = currentNode.textContent;\n arrayForEach([MUSTACHE_EXPR, ERB_EXPR, TMPLIT_EXPR], expr => {\n content = stringReplace(content, expr, ' ');\n });\n if (currentNode.textContent !== content) {\n arrayPush(DOMPurify.removed, {\n element: currentNode.cloneNode()\n });\n currentNode.textContent = content;\n }\n }\n /* Execute a hook if present */\n _executeHooks(hooks.afterSanitizeElements, currentNode, null);\n return false;\n };\n /**\n * _isValidAttribute\n *\n * @param lcTag Lowercase tag name of containing element.\n * @param lcName Lowercase attribute name.\n * @param value Attribute value.\n * @return Returns true if `value` is valid, otherwise false.\n */\n // eslint-disable-next-line complexity\n const _isValidAttribute = function _isValidAttribute(lcTag, lcName, value) {\n /* Make sure attribute cannot clobber */\n if (SANITIZE_DOM && (lcName === 'id' || lcName === 'name') && (value in document || value in formElement)) {\n return false;\n }\n /* Allow valid data-* attributes: At least one character after \"-\"\n (https://html.spec.whatwg.org/multipage/dom.html#embedding-custom-non-visible-data-with-the-data-*-attributes)\n XML-compatible (https://html.spec.whatwg.org/multipage/infrastructure.html#xml-compatible and http://www.w3.org/TR/xml/#d0e804)\n We don't need to check the value; it's always URI safe. */\n if (ALLOW_DATA_ATTR && !FORBID_ATTR[lcName] && regExpTest(DATA_ATTR, lcName)) ;else if (ALLOW_ARIA_ATTR && regExpTest(ARIA_ATTR, lcName)) ;else if (!ALLOWED_ATTR[lcName] || FORBID_ATTR[lcName]) {\n if (\n // First condition does a very basic check if a) it's basically a valid custom element tagname AND\n // b) if the tagName passes whatever the user has configured for CUSTOM_ELEMENT_HANDLING.tagNameCheck\n // and c) if the attribute name passes whatever the user has configured for CUSTOM_ELEMENT_HANDLING.attributeNameCheck\n _isBasicCustomElement(lcTag) && (CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof RegExp && regExpTest(CUSTOM_ELEMENT_HANDLING.tagNameCheck, lcTag) || CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof Function && CUSTOM_ELEMENT_HANDLING.tagNameCheck(lcTag)) && (CUSTOM_ELEMENT_HANDLING.attributeNameCheck instanceof RegExp && regExpTest(CUSTOM_ELEMENT_HANDLING.attributeNameCheck, lcName) || CUSTOM_ELEMENT_HANDLING.attributeNameCheck instanceof Function && CUSTOM_ELEMENT_HANDLING.attributeNameCheck(lcName)) ||\n // Alternative, second condition checks if it's an `is`-attribute, AND\n // the value passes whatever the user has configured for CUSTOM_ELEMENT_HANDLING.tagNameCheck\n lcName === 'is' && CUSTOM_ELEMENT_HANDLING.allowCustomizedBuiltInElements && (CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof RegExp && regExpTest(CUSTOM_ELEMENT_HANDLING.tagNameCheck, value) || CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof Function && CUSTOM_ELEMENT_HANDLING.tagNameCheck(value))) ;else {\n return false;\n }\n /* Check value is safe. First, is attr inert? If so, is safe */\n } else if (URI_SAFE_ATTRIBUTES[lcName]) ;else if (regExpTest(IS_ALLOWED_URI$1, stringReplace(value, ATTR_WHITESPACE, ''))) ;else if ((lcName === 'src' || lcName === 'xlink:href' || lcName === 'href') && lcTag !== 'script' && stringIndexOf(value, 'data:') === 0 && DATA_URI_TAGS[lcTag]) ;else if (ALLOW_UNKNOWN_PROTOCOLS && !regExpTest(IS_SCRIPT_OR_DATA, stringReplace(value, ATTR_WHITESPACE, ''))) ;else if (value) {\n return false;\n } else ;\n return true;\n };\n /**\n * _isBasicCustomElement\n * checks if at least one dash is included in tagName, and it's not the first char\n * for more sophisticated checking see https://github.com/sindresorhus/validate-element-name\n *\n * @param tagName name of the tag of the node to sanitize\n * @returns Returns true if the tag name meets the basic criteria for a custom element, otherwise false.\n */\n const _isBasicCustomElement = function _isBasicCustomElement(tagName) {\n return tagName !== 'annotation-xml' && stringMatch(tagName, CUSTOM_ELEMENT);\n };\n /**\n * _sanitizeAttributes\n *\n * @protect attributes\n * @protect nodeName\n * @protect removeAttribute\n * @protect setAttribute\n *\n * @param currentNode to sanitize\n */\n const _sanitizeAttributes = function _sanitizeAttributes(currentNode) {\n /* Execute a hook if present */\n _executeHooks(hooks.beforeSanitizeAttributes, currentNode, null);\n const {\n attributes\n } = currentNode;\n /* Check if we have attributes; if not we might have a text node */\n if (!attributes || _isClobbered(currentNode)) {\n return;\n }\n const hookEvent = {\n attrName: '',\n attrValue: '',\n keepAttr: true,\n allowedAttributes: ALLOWED_ATTR,\n forceKeepAttr: undefined\n };\n let l = attributes.length;\n /* Go backwards over all attributes; safely remove bad ones */\n while (l--) {\n const attr = attributes[l];\n const {\n name,\n namespaceURI,\n value: attrValue\n } = attr;\n const lcName = transformCaseFunc(name);\n let value = name === 'value' ? attrValue : stringTrim(attrValue);\n /* Execute a hook if present */\n hookEvent.attrName = lcName;\n hookEvent.attrValue = value;\n hookEvent.keepAttr = true;\n hookEvent.forceKeepAttr = undefined; // Allows developers to see this is a property they can set\n _executeHooks(hooks.uponSanitizeAttribute, currentNode, hookEvent);\n value = hookEvent.attrValue;\n /* Full DOM Clobbering protection via namespace isolation,\n * Prefix id and name attributes with `user-content-`\n */\n if (SANITIZE_NAMED_PROPS && (lcName === 'id' || lcName === 'name')) {\n // Remove the attribute with this value\n _removeAttribute(name, currentNode);\n // Prefix the value and later re-create the attribute with the sanitized value\n value = SANITIZE_NAMED_PROPS_PREFIX + value;\n }\n /* Work around a security issue with comments inside attributes */\n if (SAFE_FOR_XML && regExpTest(/((--!?|])>)|<\\/(style|title)/i, value)) {\n _removeAttribute(name, currentNode);\n continue;\n }\n /* Did the hooks approve of the attribute? */\n if (hookEvent.forceKeepAttr) {\n continue;\n }\n /* Remove attribute */\n _removeAttribute(name, currentNode);\n /* Did the hooks approve of the attribute? */\n if (!hookEvent.keepAttr) {\n continue;\n }\n /* Work around a security issue in jQuery 3.0 */\n if (!ALLOW_SELF_CLOSE_IN_ATTR && regExpTest(/\\/>/i, value)) {\n _removeAttribute(name, currentNode);\n continue;\n }\n /* Sanitize attribute content to be template-safe */\n if (SAFE_FOR_TEMPLATES) {\n arrayForEach([MUSTACHE_EXPR, ERB_EXPR, TMPLIT_EXPR], expr => {\n value = stringReplace(value, expr, ' ');\n });\n }\n /* Is `value` valid for this attribute? */\n const lcTag = transformCaseFunc(currentNode.nodeName);\n if (!_isValidAttribute(lcTag, lcName, value)) {\n continue;\n }\n /* Handle attributes that require Trusted Types */\n if (trustedTypesPolicy && typeof trustedTypes === 'object' && typeof trustedTypes.getAttributeType === 'function') {\n if (namespaceURI) ;else {\n switch (trustedTypes.getAttributeType(lcTag, lcName)) {\n case 'TrustedHTML':\n {\n value = trustedTypesPolicy.createHTML(value);\n break;\n }\n case 'TrustedScriptURL':\n {\n value = trustedTypesPolicy.createScriptURL(value);\n break;\n }\n }\n }\n }\n /* Handle invalid data-* attribute set by try-catching it */\n try {\n if (namespaceURI) {\n currentNode.setAttributeNS(namespaceURI, name, value);\n } else {\n /* Fallback to setAttribute() for browser-unrecognized namespaces e.g. \"x-schema\". */\n currentNode.setAttribute(name, value);\n }\n if (_isClobbered(currentNode)) {\n _forceRemove(currentNode);\n } else {\n arrayPop(DOMPurify.removed);\n }\n } catch (_) {}\n }\n /* Execute a hook if present */\n _executeHooks(hooks.afterSanitizeAttributes, currentNode, null);\n };\n /**\n * _sanitizeShadowDOM\n *\n * @param fragment to iterate over recursively\n */\n const _sanitizeShadowDOM = function _sanitizeShadowDOM(fragment) {\n let shadowNode = null;\n const shadowIterator = _createNodeIterator(fragment);\n /* Execute a hook if present */\n _executeHooks(hooks.beforeSanitizeShadowDOM, fragment, null);\n while (shadowNode = shadowIterator.nextNode()) {\n /* Execute a hook if present */\n _executeHooks(hooks.uponSanitizeShadowNode, shadowNode, null);\n /* Sanitize tags and elements */\n _sanitizeElements(shadowNode);\n /* Check attributes next */\n _sanitizeAttributes(shadowNode);\n /* Deep shadow DOM detected */\n if (shadowNode.content instanceof DocumentFragment) {\n _sanitizeShadowDOM(shadowNode.content);\n }\n }\n /* Execute a hook if present */\n _executeHooks(hooks.afterSanitizeShadowDOM, fragment, null);\n };\n // eslint-disable-next-line complexity\n DOMPurify.sanitize = function (dirty) {\n let cfg = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};\n let body = null;\n let importedNode = null;\n let currentNode = null;\n let returnNode = null;\n /* Make sure we have a string to sanitize.\n DO NOT return early, as this will return the wrong type if\n the user has requested a DOM object rather than a string */\n IS_EMPTY_INPUT = !dirty;\n if (IS_EMPTY_INPUT) {\n dirty = '';\n }\n /* Stringify, in case dirty is an object */\n if (typeof dirty !== 'string' && !_isNode(dirty)) {\n if (typeof dirty.toString === 'function') {\n dirty = dirty.toString();\n if (typeof dirty !== 'string') {\n throw typeErrorCreate('dirty is not a string, aborting');\n }\n } else {\n throw typeErrorCreate('toString is not a function');\n }\n }\n /* Return dirty HTML if DOMPurify cannot run */\n if (!DOMPurify.isSupported) {\n return dirty;\n }\n /* Assign config vars */\n if (!SET_CONFIG) {\n _parseConfig(cfg);\n }\n /* Clean up removed elements */\n DOMPurify.removed = [];\n /* Check if dirty is correctly typed for IN_PLACE */\n if (typeof dirty === 'string') {\n IN_PLACE = false;\n }\n if (IN_PLACE) {\n /* Do some early pre-sanitization to avoid unsafe root nodes */\n if (dirty.nodeName) {\n const tagName = transformCaseFunc(dirty.nodeName);\n if (!ALLOWED_TAGS[tagName] || FORBID_TAGS[tagName]) {\n throw typeErrorCreate('root node is forbidden and cannot be sanitized in-place');\n }\n }\n } else if (dirty instanceof Node) {\n /* If dirty is a DOM element, append to an empty document to avoid\n elements being stripped by the parser */\n body = _initDocument('');\n importedNode = body.ownerDocument.importNode(dirty, true);\n if (importedNode.nodeType === NODE_TYPE.element && importedNode.nodeName === 'BODY') {\n /* Node is already a body, use as is */\n body = importedNode;\n } else if (importedNode.nodeName === 'HTML') {\n body = importedNode;\n } else {\n // eslint-disable-next-line unicorn/prefer-dom-node-append\n body.appendChild(importedNode);\n }\n } else {\n /* Exit directly if we have nothing to do */\n if (!RETURN_DOM && !SAFE_FOR_TEMPLATES && !WHOLE_DOCUMENT &&\n // eslint-disable-next-line unicorn/prefer-includes\n dirty.indexOf('<') === -1) {\n return trustedTypesPolicy && RETURN_TRUSTED_TYPE ? trustedTypesPolicy.createHTML(dirty) : dirty;\n }\n /* Initialize the document to work on */\n body = _initDocument(dirty);\n /* Check we have a DOM node from the data */\n if (!body) {\n return RETURN_DOM ? null : RETURN_TRUSTED_TYPE ? emptyHTML : '';\n }\n }\n /* Remove first element node (ours) if FORCE_BODY is set */\n if (body && FORCE_BODY) {\n _forceRemove(body.firstChild);\n }\n /* Get node iterator */\n const nodeIterator = _createNodeIterator(IN_PLACE ? dirty : body);\n /* Now start iterating over the created document */\n while (currentNode = nodeIterator.nextNode()) {\n /* Sanitize tags and elements */\n _sanitizeElements(currentNode);\n /* Check attributes next */\n _sanitizeAttributes(currentNode);\n /* Shadow DOM detected, sanitize it */\n if (currentNode.content instanceof DocumentFragment) {\n _sanitizeShadowDOM(currentNode.content);\n }\n }\n /* If we sanitized `dirty` in-place, return it. */\n if (IN_PLACE) {\n return dirty;\n }\n /* Return sanitized string or DOM */\n if (RETURN_DOM) {\n if (RETURN_DOM_FRAGMENT) {\n returnNode = createDocumentFragment.call(body.ownerDocument);\n while (body.firstChild) {\n // eslint-disable-next-line unicorn/prefer-dom-node-append\n returnNode.appendChild(body.firstChild);\n }\n } else {\n returnNode = body;\n }\n if (ALLOWED_ATTR.shadowroot || ALLOWED_ATTR.shadowrootmode) {\n /*\n AdoptNode() is not used because internal state is not reset\n (e.g. the past names map of a HTMLFormElement), this is safe\n in theory but we would rather not risk another attack vector.\n The state that is cloned by importNode() is explicitly defined\n by the specs.\n */\n returnNode = importNode.call(originalDocument, returnNode, true);\n }\n return returnNode;\n }\n let serializedHTML = WHOLE_DOCUMENT ? body.outerHTML : body.innerHTML;\n /* Serialize doctype if allowed */\n if (WHOLE_DOCUMENT && ALLOWED_TAGS['!doctype'] && body.ownerDocument && body.ownerDocument.doctype && body.ownerDocument.doctype.name && regExpTest(DOCTYPE_NAME, body.ownerDocument.doctype.name)) {\n serializedHTML = '\\n' + serializedHTML;\n }\n /* Sanitize final string template-safe */\n if (SAFE_FOR_TEMPLATES) {\n arrayForEach([MUSTACHE_EXPR, ERB_EXPR, TMPLIT_EXPR], expr => {\n serializedHTML = stringReplace(serializedHTML, expr, ' ');\n });\n }\n return trustedTypesPolicy && RETURN_TRUSTED_TYPE ? trustedTypesPolicy.createHTML(serializedHTML) : serializedHTML;\n };\n DOMPurify.setConfig = function () {\n let cfg = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};\n _parseConfig(cfg);\n SET_CONFIG = true;\n };\n DOMPurify.clearConfig = function () {\n CONFIG = null;\n SET_CONFIG = false;\n };\n DOMPurify.isValidAttribute = function (tag, attr, value) {\n /* Initialize shared config vars if necessary. */\n if (!CONFIG) {\n _parseConfig({});\n }\n const lcTag = transformCaseFunc(tag);\n const lcName = transformCaseFunc(attr);\n return _isValidAttribute(lcTag, lcName, value);\n };\n DOMPurify.addHook = function (entryPoint, hookFunction) {\n if (typeof hookFunction !== 'function') {\n return;\n }\n arrayPush(hooks[entryPoint], hookFunction);\n };\n DOMPurify.removeHook = function (entryPoint) {\n return arrayPop(hooks[entryPoint]);\n };\n DOMPurify.removeHooks = function (entryPoint) {\n hooks[entryPoint] = [];\n };\n DOMPurify.removeAllHooks = function () {\n hooks = _createHooksMap();\n };\n return DOMPurify;\n }\n var purify = createDOMPurify();\n\n const DEFAULT_ALLOWED_ATTRIBUTES = \"style href src width height language class\".split(\" \");\n const DEFAULT_FORBIDDEN_PROTOCOLS = \"javascript:\".split(\" \");\n const DEFAULT_FORBIDDEN_ELEMENTS = \"script iframe form noscript\".split(\" \");\n class HTMLSanitizer extends BasicObject {\n static setHTML(element, html) {\n const sanitizedElement = new this(html).sanitize();\n const sanitizedHtml = sanitizedElement.getHTML ? sanitizedElement.getHTML() : sanitizedElement.outerHTML;\n element.innerHTML = sanitizedHtml;\n }\n static sanitize(html, options) {\n const sanitizer = new this(html, options);\n sanitizer.sanitize();\n return sanitizer;\n }\n constructor(html) {\n let {\n allowedAttributes,\n forbiddenProtocols,\n forbiddenElements\n } = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};\n super(...arguments);\n this.allowedAttributes = allowedAttributes || DEFAULT_ALLOWED_ATTRIBUTES;\n this.forbiddenProtocols = forbiddenProtocols || DEFAULT_FORBIDDEN_PROTOCOLS;\n this.forbiddenElements = forbiddenElements || DEFAULT_FORBIDDEN_ELEMENTS;\n this.body = createBodyElementForHTML(html);\n }\n sanitize() {\n this.sanitizeElements();\n this.normalizeListElementNesting();\n return purify.sanitize(this.body, {\n ADD_ATTR: [\"language\"],\n RETURN_DOM: true\n });\n }\n getHTML() {\n return this.body.innerHTML;\n }\n getBody() {\n return this.body;\n }\n\n // Private\n\n sanitizeElements() {\n const walker = walkTree(this.body);\n const nodesToRemove = [];\n while (walker.nextNode()) {\n const node = walker.currentNode;\n switch (node.nodeType) {\n case Node.ELEMENT_NODE:\n if (this.elementIsRemovable(node)) {\n nodesToRemove.push(node);\n } else {\n this.sanitizeElement(node);\n }\n break;\n case Node.COMMENT_NODE:\n nodesToRemove.push(node);\n break;\n }\n }\n nodesToRemove.forEach(node => removeNode(node));\n return this.body;\n }\n sanitizeElement(element) {\n if (element.hasAttribute(\"href\")) {\n if (this.forbiddenProtocols.includes(element.protocol)) {\n element.removeAttribute(\"href\");\n }\n }\n Array.from(element.attributes).forEach(_ref => {\n let {\n name\n } = _ref;\n if (!this.allowedAttributes.includes(name) && name.indexOf(\"data-trix\") !== 0) {\n element.removeAttribute(name);\n }\n });\n return element;\n }\n normalizeListElementNesting() {\n Array.from(this.body.querySelectorAll(\"ul,ol\")).forEach(listElement => {\n const previousElement = listElement.previousElementSibling;\n if (previousElement) {\n if (tagName(previousElement) === \"li\") {\n previousElement.appendChild(listElement);\n }\n }\n });\n return this.body;\n }\n elementIsRemovable(element) {\n if ((element === null || element === void 0 ? void 0 : element.nodeType) !== Node.ELEMENT_NODE) return;\n return this.elementIsForbidden(element) || this.elementIsntSerializable(element);\n }\n elementIsForbidden(element) {\n return this.forbiddenElements.includes(tagName(element));\n }\n elementIsntSerializable(element) {\n return element.getAttribute(\"data-trix-serialize\") === \"false\" && !nodeIsAttachmentElement(element);\n }\n }\n const createBodyElementForHTML = function () {\n let html = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : \"\";\n // Remove everything after \n html = html.replace(/<\\/html[^>]*>[^]*$/i, \"\");\n const doc = document.implementation.createHTMLDocument(\"\");\n doc.documentElement.innerHTML = html;\n Array.from(doc.head.querySelectorAll(\"style\")).forEach(element => {\n doc.body.appendChild(element);\n });\n return doc.body;\n };\n\n const {\n css: css$2\n } = config;\n class AttachmentView extends ObjectView {\n constructor() {\n super(...arguments);\n this.attachment = this.object;\n this.attachment.uploadProgressDelegate = this;\n this.attachmentPiece = this.options.piece;\n }\n createContentNodes() {\n return [];\n }\n createNodes() {\n let innerElement;\n const figure = innerElement = makeElement({\n tagName: \"figure\",\n className: this.getClassName(),\n data: this.getData(),\n editable: false\n });\n const href = this.getHref();\n if (href) {\n innerElement = makeElement({\n tagName: \"a\",\n editable: false,\n attributes: {\n href,\n tabindex: -1\n }\n });\n figure.appendChild(innerElement);\n }\n if (this.attachment.hasContent()) {\n HTMLSanitizer.setHTML(innerElement, this.attachment.getContent());\n } else {\n this.createContentNodes().forEach(node => {\n innerElement.appendChild(node);\n });\n }\n innerElement.appendChild(this.createCaptionElement());\n if (this.attachment.isPending()) {\n this.progressElement = makeElement({\n tagName: \"progress\",\n attributes: {\n class: css$2.attachmentProgress,\n value: this.attachment.getUploadProgress(),\n max: 100\n },\n data: {\n trixMutable: true,\n trixStoreKey: [\"progressElement\", this.attachment.id].join(\"/\")\n }\n });\n figure.appendChild(this.progressElement);\n }\n return [createCursorTarget(\"left\"), figure, createCursorTarget(\"right\")];\n }\n createCaptionElement() {\n const figcaption = makeElement({\n tagName: \"figcaption\",\n className: css$2.attachmentCaption\n });\n const caption = this.attachmentPiece.getCaption();\n if (caption) {\n figcaption.classList.add(\"\".concat(css$2.attachmentCaption, \"--edited\"));\n figcaption.textContent = caption;\n } else {\n let name, size;\n const captionConfig = this.getCaptionConfig();\n if (captionConfig.name) {\n name = this.attachment.getFilename();\n }\n if (captionConfig.size) {\n size = this.attachment.getFormattedFilesize();\n }\n if (name) {\n const nameElement = makeElement({\n tagName: \"span\",\n className: css$2.attachmentName,\n textContent: name\n });\n figcaption.appendChild(nameElement);\n }\n if (size) {\n if (name) {\n figcaption.appendChild(document.createTextNode(\" \"));\n }\n const sizeElement = makeElement({\n tagName: \"span\",\n className: css$2.attachmentSize,\n textContent: size\n });\n figcaption.appendChild(sizeElement);\n }\n }\n return figcaption;\n }\n getClassName() {\n const names = [css$2.attachment, \"\".concat(css$2.attachment, \"--\").concat(this.attachment.getType())];\n const extension = this.attachment.getExtension();\n if (extension) {\n names.push(\"\".concat(css$2.attachment, \"--\").concat(extension));\n }\n return names.join(\" \");\n }\n getData() {\n const data = {\n trixAttachment: JSON.stringify(this.attachment),\n trixContentType: this.attachment.getContentType(),\n trixId: this.attachment.id\n };\n const {\n attributes\n } = this.attachmentPiece;\n if (!attributes.isEmpty()) {\n data.trixAttributes = JSON.stringify(attributes);\n }\n if (this.attachment.isPending()) {\n data.trixSerialize = false;\n }\n return data;\n }\n getHref() {\n if (!htmlContainsTagName(this.attachment.getContent(), \"a\")) {\n return this.attachment.getHref();\n }\n }\n getCaptionConfig() {\n var _config$attachments$t;\n const type = this.attachment.getType();\n const captionConfig = copyObject((_config$attachments$t = attachments[type]) === null || _config$attachments$t === void 0 ? void 0 : _config$attachments$t.caption);\n if (type === \"file\") {\n captionConfig.name = true;\n }\n return captionConfig;\n }\n findProgressElement() {\n var _this$findElement;\n return (_this$findElement = this.findElement()) === null || _this$findElement === void 0 ? void 0 : _this$findElement.querySelector(\"progress\");\n }\n\n // Attachment delegate\n\n attachmentDidChangeUploadProgress() {\n const value = this.attachment.getUploadProgress();\n const progressElement = this.findProgressElement();\n if (progressElement) {\n progressElement.value = value;\n }\n }\n }\n const createCursorTarget = name => makeElement({\n tagName: \"span\",\n textContent: ZERO_WIDTH_SPACE,\n data: {\n trixCursorTarget: name,\n trixSerialize: false\n }\n });\n const htmlContainsTagName = function (html, tagName) {\n const div = makeElement(\"div\");\n HTMLSanitizer.setHTML(div, html || \"\");\n return div.querySelector(tagName);\n };\n\n class PreviewableAttachmentView extends AttachmentView {\n constructor() {\n super(...arguments);\n this.attachment.previewDelegate = this;\n }\n createContentNodes() {\n this.image = makeElement({\n tagName: \"img\",\n attributes: {\n src: \"\"\n },\n data: {\n trixMutable: true\n }\n });\n this.refresh(this.image);\n return [this.image];\n }\n createCaptionElement() {\n const figcaption = super.createCaptionElement(...arguments);\n if (!figcaption.textContent) {\n figcaption.setAttribute(\"data-trix-placeholder\", lang$1.captionPlaceholder);\n }\n return figcaption;\n }\n refresh(image) {\n if (!image) {\n var _this$findElement;\n image = (_this$findElement = this.findElement()) === null || _this$findElement === void 0 ? void 0 : _this$findElement.querySelector(\"img\");\n }\n if (image) {\n return this.updateAttributesForImage(image);\n }\n }\n updateAttributesForImage(image) {\n const url = this.attachment.getURL();\n const previewURL = this.attachment.getPreviewURL();\n image.src = previewURL || url;\n if (previewURL === url) {\n image.removeAttribute(\"data-trix-serialized-attributes\");\n } else {\n const serializedAttributes = JSON.stringify({\n src: url\n });\n image.setAttribute(\"data-trix-serialized-attributes\", serializedAttributes);\n }\n const width = this.attachment.getWidth();\n const height = this.attachment.getHeight();\n if (width != null) {\n image.width = width;\n }\n if (height != null) {\n image.height = height;\n }\n const storeKey = [\"imageElement\", this.attachment.id, image.src, image.width, image.height].join(\"/\");\n image.dataset.trixStoreKey = storeKey;\n }\n\n // Attachment delegate\n\n attachmentDidChangeAttributes() {\n this.refresh(this.image);\n return this.refresh();\n }\n }\n\n /* eslint-disable\n no-useless-escape,\n no-var,\n */\n class PieceView extends ObjectView {\n constructor() {\n super(...arguments);\n this.piece = this.object;\n this.attributes = this.piece.getAttributes();\n this.textConfig = this.options.textConfig;\n this.context = this.options.context;\n if (this.piece.attachment) {\n this.attachment = this.piece.attachment;\n } else {\n this.string = this.piece.toString();\n }\n }\n createNodes() {\n let nodes = this.attachment ? this.createAttachmentNodes() : this.createStringNodes();\n const element = this.createElement();\n if (element) {\n const innerElement = findInnerElement(element);\n Array.from(nodes).forEach(node => {\n innerElement.appendChild(node);\n });\n nodes = [element];\n }\n return nodes;\n }\n createAttachmentNodes() {\n const constructor = this.attachment.isPreviewable() ? PreviewableAttachmentView : AttachmentView;\n const view = this.createChildView(constructor, this.piece.attachment, {\n piece: this.piece\n });\n return view.getNodes();\n }\n createStringNodes() {\n var _this$textConfig;\n if ((_this$textConfig = this.textConfig) !== null && _this$textConfig !== void 0 && _this$textConfig.plaintext) {\n return [document.createTextNode(this.string)];\n } else {\n const nodes = [];\n const iterable = this.string.split(\"\\n\");\n for (let index = 0; index < iterable.length; index++) {\n const substring = iterable[index];\n if (index > 0) {\n const element = makeElement(\"br\");\n nodes.push(element);\n }\n if (substring.length) {\n const node = document.createTextNode(this.preserveSpaces(substring));\n nodes.push(node);\n }\n }\n return nodes;\n }\n }\n createElement() {\n let element, key, value;\n const styles = {};\n for (key in this.attributes) {\n value = this.attributes[key];\n const config = getTextConfig(key);\n if (config) {\n if (config.tagName) {\n var innerElement;\n const pendingElement = makeElement(config.tagName);\n if (innerElement) {\n innerElement.appendChild(pendingElement);\n innerElement = pendingElement;\n } else {\n element = innerElement = pendingElement;\n }\n }\n if (config.styleProperty) {\n styles[config.styleProperty] = value;\n }\n if (config.style) {\n for (key in config.style) {\n value = config.style[key];\n styles[key] = value;\n }\n }\n }\n }\n if (Object.keys(styles).length) {\n if (!element) {\n element = makeElement(\"span\");\n }\n for (key in styles) {\n value = styles[key];\n element.style[key] = value;\n }\n }\n return element;\n }\n createContainerElement() {\n for (const key in this.attributes) {\n const value = this.attributes[key];\n const config = getTextConfig(key);\n if (config) {\n if (config.groupTagName) {\n const attributes = {};\n attributes[key] = value;\n return makeElement(config.groupTagName, attributes);\n }\n }\n }\n }\n preserveSpaces(string) {\n if (this.context.isLast) {\n string = string.replace(/\\ $/, NON_BREAKING_SPACE);\n }\n string = string.replace(/(\\S)\\ {3}(\\S)/g, \"$1 \".concat(NON_BREAKING_SPACE, \" $2\")).replace(/\\ {2}/g, \"\".concat(NON_BREAKING_SPACE, \" \")).replace(/\\ {2}/g, \" \".concat(NON_BREAKING_SPACE));\n if (this.context.isFirst || this.context.followsWhitespace) {\n string = string.replace(/^\\ /, NON_BREAKING_SPACE);\n }\n return string;\n }\n }\n\n /* eslint-disable\n no-var,\n */\n class TextView extends ObjectView {\n constructor() {\n super(...arguments);\n this.text = this.object;\n this.textConfig = this.options.textConfig;\n }\n createNodes() {\n const nodes = [];\n const pieces = ObjectGroup.groupObjects(this.getPieces());\n const lastIndex = pieces.length - 1;\n for (let index = 0; index < pieces.length; index++) {\n const piece = pieces[index];\n const context = {};\n if (index === 0) {\n context.isFirst = true;\n }\n if (index === lastIndex) {\n context.isLast = true;\n }\n if (endsWithWhitespace(previousPiece)) {\n context.followsWhitespace = true;\n }\n const view = this.findOrCreateCachedChildView(PieceView, piece, {\n textConfig: this.textConfig,\n context\n });\n nodes.push(...Array.from(view.getNodes() || []));\n var previousPiece = piece;\n }\n return nodes;\n }\n getPieces() {\n return Array.from(this.text.getPieces()).filter(piece => !piece.hasAttribute(\"blockBreak\"));\n }\n }\n const endsWithWhitespace = piece => /\\s$/.test(piece === null || piece === void 0 ? void 0 : piece.toString());\n\n const {\n css: css$1\n } = config;\n class BlockView extends ObjectView {\n constructor() {\n super(...arguments);\n this.block = this.object;\n this.attributes = this.block.getAttributes();\n }\n createNodes() {\n const comment = document.createComment(\"block\");\n const nodes = [comment];\n if (this.block.isEmpty()) {\n nodes.push(makeElement(\"br\"));\n } else {\n var _getBlockConfig;\n const textConfig = (_getBlockConfig = getBlockConfig(this.block.getLastAttribute())) === null || _getBlockConfig === void 0 ? void 0 : _getBlockConfig.text;\n const textView = this.findOrCreateCachedChildView(TextView, this.block.text, {\n textConfig\n });\n nodes.push(...Array.from(textView.getNodes() || []));\n if (this.shouldAddExtraNewlineElement()) {\n nodes.push(makeElement(\"br\"));\n }\n }\n if (this.attributes.length) {\n return nodes;\n } else {\n let attributes$1;\n const {\n tagName\n } = attributes.default;\n if (this.block.isRTL()) {\n attributes$1 = {\n dir: \"rtl\"\n };\n }\n const element = makeElement({\n tagName,\n attributes: attributes$1\n });\n nodes.forEach(node => element.appendChild(node));\n return [element];\n }\n }\n createContainerElement(depth) {\n const attributes = {};\n let className;\n const attributeName = this.attributes[depth];\n const {\n tagName,\n htmlAttributes = []\n } = getBlockConfig(attributeName);\n if (depth === 0 && this.block.isRTL()) {\n Object.assign(attributes, {\n dir: \"rtl\"\n });\n }\n if (attributeName === \"attachmentGallery\") {\n const size = this.block.getBlockBreakPosition();\n className = \"\".concat(css$1.attachmentGallery, \" \").concat(css$1.attachmentGallery, \"--\").concat(size);\n }\n Object.entries(this.block.htmlAttributes).forEach(_ref => {\n let [name, value] = _ref;\n if (htmlAttributes.includes(name)) {\n attributes[name] = value;\n }\n });\n return makeElement({\n tagName,\n className,\n attributes\n });\n }\n\n // A single
at the end of a block element has no visual representation\n // so add an extra one.\n shouldAddExtraNewlineElement() {\n return /\\n\\n$/.test(this.block.toString());\n }\n }\n\n class DocumentView extends ObjectView {\n static render(document) {\n const element = makeElement(\"div\");\n const view = new this(document, {\n element\n });\n view.render();\n view.sync();\n return element;\n }\n constructor() {\n super(...arguments);\n this.element = this.options.element;\n this.elementStore = new ElementStore();\n this.setDocument(this.object);\n }\n setDocument(document) {\n if (!document.isEqualTo(this.document)) {\n this.document = this.object = document;\n }\n }\n render() {\n this.childViews = [];\n this.shadowElement = makeElement(\"div\");\n if (!this.document.isEmpty()) {\n const objects = ObjectGroup.groupObjects(this.document.getBlocks(), {\n asTree: true\n });\n Array.from(objects).forEach(object => {\n const view = this.findOrCreateCachedChildView(BlockView, object);\n Array.from(view.getNodes()).map(node => this.shadowElement.appendChild(node));\n });\n }\n }\n isSynced() {\n return elementsHaveEqualHTML(this.shadowElement, this.element);\n }\n sync() {\n const fragment = this.createDocumentFragmentForSync();\n while (this.element.lastChild) {\n this.element.removeChild(this.element.lastChild);\n }\n this.element.appendChild(fragment);\n return this.didSync();\n }\n\n // Private\n\n didSync() {\n this.elementStore.reset(findStoredElements(this.element));\n return defer(() => this.garbageCollectCachedViews());\n }\n createDocumentFragmentForSync() {\n const fragment = document.createDocumentFragment();\n Array.from(this.shadowElement.childNodes).forEach(node => {\n fragment.appendChild(node.cloneNode(true));\n });\n Array.from(findStoredElements(fragment)).forEach(element => {\n const storedElement = this.elementStore.remove(element);\n if (storedElement) {\n element.parentNode.replaceChild(storedElement, element);\n }\n });\n return fragment;\n }\n }\n const findStoredElements = element => element.querySelectorAll(\"[data-trix-store-key]\");\n const elementsHaveEqualHTML = (element, otherElement) => ignoreSpaces(element.innerHTML) === ignoreSpaces(otherElement.innerHTML);\n const ignoreSpaces = html => html.replace(/ /g, \" \");\n\n function _AsyncGenerator(e) {\n var r, t;\n function resume(r, t) {\n try {\n var n = e[r](t),\n o = n.value,\n u = o instanceof _OverloadYield;\n Promise.resolve(u ? o.v : o).then(function (t) {\n if (u) {\n var i = \"return\" === r ? \"return\" : \"next\";\n if (!o.k || t.done) return resume(i, t);\n t = e[i](t).value;\n }\n settle(n.done ? \"return\" : \"normal\", t);\n }, function (e) {\n resume(\"throw\", e);\n });\n } catch (e) {\n settle(\"throw\", e);\n }\n }\n function settle(e, n) {\n switch (e) {\n case \"return\":\n r.resolve({\n value: n,\n done: !0\n });\n break;\n case \"throw\":\n r.reject(n);\n break;\n default:\n r.resolve({\n value: n,\n done: !1\n });\n }\n (r = r.next) ? resume(r.key, r.arg) : t = null;\n }\n this._invoke = function (e, n) {\n return new Promise(function (o, u) {\n var i = {\n key: e,\n arg: n,\n resolve: o,\n reject: u,\n next: null\n };\n t ? t = t.next = i : (r = t = i, resume(e, n));\n });\n }, \"function\" != typeof e.return && (this.return = void 0);\n }\n _AsyncGenerator.prototype[\"function\" == typeof Symbol && Symbol.asyncIterator || \"@@asyncIterator\"] = function () {\n return this;\n }, _AsyncGenerator.prototype.next = function (e) {\n return this._invoke(\"next\", e);\n }, _AsyncGenerator.prototype.throw = function (e) {\n return this._invoke(\"throw\", e);\n }, _AsyncGenerator.prototype.return = function (e) {\n return this._invoke(\"return\", e);\n };\n function _OverloadYield(t, e) {\n this.v = t, this.k = e;\n }\n function old_createMetadataMethodsForProperty(e, t, a, r) {\n return {\n getMetadata: function (o) {\n old_assertNotFinished(r, \"getMetadata\"), old_assertMetadataKey(o);\n var i = e[o];\n if (void 0 !== i) if (1 === t) {\n var n = i.public;\n if (void 0 !== n) return n[a];\n } else if (2 === t) {\n var l = i.private;\n if (void 0 !== l) return l.get(a);\n } else if (Object.hasOwnProperty.call(i, \"constructor\")) return i.constructor;\n },\n setMetadata: function (o, i) {\n old_assertNotFinished(r, \"setMetadata\"), old_assertMetadataKey(o);\n var n = e[o];\n if (void 0 === n && (n = e[o] = {}), 1 === t) {\n var l = n.public;\n void 0 === l && (l = n.public = {}), l[a] = i;\n } else if (2 === t) {\n var s = n.priv;\n void 0 === s && (s = n.private = new Map()), s.set(a, i);\n } else n.constructor = i;\n }\n };\n }\n function old_convertMetadataMapToFinal(e, t) {\n var a = e[Symbol.metadata || Symbol.for(\"Symbol.metadata\")],\n r = Object.getOwnPropertySymbols(t);\n if (0 !== r.length) {\n for (var o = 0; o < r.length; o++) {\n var i = r[o],\n n = t[i],\n l = a ? a[i] : null,\n s = n.public,\n c = l ? l.public : null;\n s && c && Object.setPrototypeOf(s, c);\n var d = n.private;\n if (d) {\n var u = Array.from(d.values()),\n f = l ? l.private : null;\n f && (u = u.concat(f)), n.private = u;\n }\n l && Object.setPrototypeOf(n, l);\n }\n a && Object.setPrototypeOf(t, a), e[Symbol.metadata || Symbol.for(\"Symbol.metadata\")] = t;\n }\n }\n function old_createAddInitializerMethod(e, t) {\n return function (a) {\n old_assertNotFinished(t, \"addInitializer\"), old_assertCallable(a, \"An initializer\"), e.push(a);\n };\n }\n function old_memberDec(e, t, a, r, o, i, n, l, s) {\n var c;\n switch (i) {\n case 1:\n c = \"accessor\";\n break;\n case 2:\n c = \"method\";\n break;\n case 3:\n c = \"getter\";\n break;\n case 4:\n c = \"setter\";\n break;\n default:\n c = \"field\";\n }\n var d,\n u,\n f = {\n kind: c,\n name: l ? \"#\" + t : t,\n isStatic: n,\n isPrivate: l\n },\n p = {\n v: !1\n };\n if (0 !== i && (f.addInitializer = old_createAddInitializerMethod(o, p)), l) {\n d = 2, u = Symbol(t);\n var v = {};\n 0 === i ? (v.get = a.get, v.set = a.set) : 2 === i ? v.get = function () {\n return a.value;\n } : (1 !== i && 3 !== i || (v.get = function () {\n return a.get.call(this);\n }), 1 !== i && 4 !== i || (v.set = function (e) {\n a.set.call(this, e);\n })), f.access = v;\n } else d = 1, u = t;\n try {\n return e(s, Object.assign(f, old_createMetadataMethodsForProperty(r, d, u, p)));\n } finally {\n p.v = !0;\n }\n }\n function old_assertNotFinished(e, t) {\n if (e.v) throw new Error(\"attempted to call \" + t + \" after decoration was finished\");\n }\n function old_assertMetadataKey(e) {\n if (\"symbol\" != typeof e) throw new TypeError(\"Metadata keys must be symbols, received: \" + e);\n }\n function old_assertCallable(e, t) {\n if (\"function\" != typeof e) throw new TypeError(t + \" must be a function\");\n }\n function old_assertValidReturnValue(e, t) {\n var a = typeof t;\n if (1 === e) {\n if (\"object\" !== a || null === t) throw new TypeError(\"accessor decorators must return an object with get, set, or init properties or void 0\");\n void 0 !== t.get && old_assertCallable(t.get, \"accessor.get\"), void 0 !== t.set && old_assertCallable(t.set, \"accessor.set\"), void 0 !== t.init && old_assertCallable(t.init, \"accessor.init\"), void 0 !== t.initializer && old_assertCallable(t.initializer, \"accessor.initializer\");\n } else if (\"function\" !== a) {\n var r;\n throw r = 0 === e ? \"field\" : 10 === e ? \"class\" : \"method\", new TypeError(r + \" decorators must return a function or void 0\");\n }\n }\n function old_getInit(e) {\n var t;\n return null == (t = e.init) && (t = e.initializer) && \"undefined\" != typeof console && console.warn(\".initializer has been renamed to .init as of March 2022\"), t;\n }\n function old_applyMemberDec(e, t, a, r, o, i, n, l, s) {\n var c,\n d,\n u,\n f,\n p,\n v,\n h = a[0];\n if (n ? c = 0 === o || 1 === o ? {\n get: a[3],\n set: a[4]\n } : 3 === o ? {\n get: a[3]\n } : 4 === o ? {\n set: a[3]\n } : {\n value: a[3]\n } : 0 !== o && (c = Object.getOwnPropertyDescriptor(t, r)), 1 === o ? u = {\n get: c.get,\n set: c.set\n } : 2 === o ? u = c.value : 3 === o ? u = c.get : 4 === o && (u = c.set), \"function\" == typeof h) void 0 !== (f = old_memberDec(h, r, c, l, s, o, i, n, u)) && (old_assertValidReturnValue(o, f), 0 === o ? d = f : 1 === o ? (d = old_getInit(f), p = f.get || u.get, v = f.set || u.set, u = {\n get: p,\n set: v\n }) : u = f);else for (var y = h.length - 1; y >= 0; y--) {\n var b;\n if (void 0 !== (f = old_memberDec(h[y], r, c, l, s, o, i, n, u))) old_assertValidReturnValue(o, f), 0 === o ? b = f : 1 === o ? (b = old_getInit(f), p = f.get || u.get, v = f.set || u.set, u = {\n get: p,\n set: v\n }) : u = f, void 0 !== b && (void 0 === d ? d = b : \"function\" == typeof d ? d = [d, b] : d.push(b));\n }\n if (0 === o || 1 === o) {\n if (void 0 === d) d = function (e, t) {\n return t;\n };else if (\"function\" != typeof d) {\n var g = d;\n d = function (e, t) {\n for (var a = t, r = 0; r < g.length; r++) a = g[r].call(e, a);\n return a;\n };\n } else {\n var m = d;\n d = function (e, t) {\n return m.call(e, t);\n };\n }\n e.push(d);\n }\n 0 !== o && (1 === o ? (c.get = u.get, c.set = u.set) : 2 === o ? c.value = u : 3 === o ? c.get = u : 4 === o && (c.set = u), n ? 1 === o ? (e.push(function (e, t) {\n return u.get.call(e, t);\n }), e.push(function (e, t) {\n return u.set.call(e, t);\n })) : 2 === o ? e.push(u) : e.push(function (e, t) {\n return u.call(e, t);\n }) : Object.defineProperty(t, r, c));\n }\n function old_applyMemberDecs(e, t, a, r, o) {\n for (var i, n, l = new Map(), s = new Map(), c = 0; c < o.length; c++) {\n var d = o[c];\n if (Array.isArray(d)) {\n var u,\n f,\n p,\n v = d[1],\n h = d[2],\n y = d.length > 3,\n b = v >= 5;\n if (b ? (u = t, f = r, 0 !== (v -= 5) && (p = n = n || [])) : (u = t.prototype, f = a, 0 !== v && (p = i = i || [])), 0 !== v && !y) {\n var g = b ? s : l,\n m = g.get(h) || 0;\n if (!0 === m || 3 === m && 4 !== v || 4 === m && 3 !== v) throw new Error(\"Attempted to decorate a public method/accessor that has the same name as a previously decorated public method/accessor. This is not currently supported by the decorators plugin. Property name was: \" + h);\n !m && v > 2 ? g.set(h, v) : g.set(h, !0);\n }\n old_applyMemberDec(e, u, d, h, v, b, y, f, p);\n }\n }\n old_pushInitializers(e, i), old_pushInitializers(e, n);\n }\n function old_pushInitializers(e, t) {\n t && e.push(function (e) {\n for (var a = 0; a < t.length; a++) t[a].call(e);\n return e;\n });\n }\n function old_applyClassDecs(e, t, a, r) {\n if (r.length > 0) {\n for (var o = [], i = t, n = t.name, l = r.length - 1; l >= 0; l--) {\n var s = {\n v: !1\n };\n try {\n var c = Object.assign({\n kind: \"class\",\n name: n,\n addInitializer: old_createAddInitializerMethod(o, s)\n }, old_createMetadataMethodsForProperty(a, 0, n, s)),\n d = r[l](i, c);\n } finally {\n s.v = !0;\n }\n void 0 !== d && (old_assertValidReturnValue(10, d), i = d);\n }\n e.push(i, function () {\n for (var e = 0; e < o.length; e++) o[e].call(i);\n });\n }\n }\n function _applyDecs(e, t, a) {\n var r = [],\n o = {},\n i = {};\n return old_applyMemberDecs(r, e, i, o, t), old_convertMetadataMapToFinal(e.prototype, i), old_applyClassDecs(r, e, o, a), old_convertMetadataMapToFinal(e, o), r;\n }\n function applyDecs2203Factory() {\n function createAddInitializerMethod(e, t) {\n return function (r) {\n !function (e, t) {\n if (e.v) throw new Error(\"attempted to call \" + t + \" after decoration was finished\");\n }(t, \"addInitializer\"), assertCallable(r, \"An initializer\"), e.push(r);\n };\n }\n function memberDec(e, t, r, a, n, i, s, o) {\n var c;\n switch (n) {\n case 1:\n c = \"accessor\";\n break;\n case 2:\n c = \"method\";\n break;\n case 3:\n c = \"getter\";\n break;\n case 4:\n c = \"setter\";\n break;\n default:\n c = \"field\";\n }\n var l,\n u,\n f = {\n kind: c,\n name: s ? \"#\" + t : t,\n static: i,\n private: s\n },\n p = {\n v: !1\n };\n 0 !== n && (f.addInitializer = createAddInitializerMethod(a, p)), 0 === n ? s ? (l = r.get, u = r.set) : (l = function () {\n return this[t];\n }, u = function (e) {\n this[t] = e;\n }) : 2 === n ? l = function () {\n return r.value;\n } : (1 !== n && 3 !== n || (l = function () {\n return r.get.call(this);\n }), 1 !== n && 4 !== n || (u = function (e) {\n r.set.call(this, e);\n })), f.access = l && u ? {\n get: l,\n set: u\n } : l ? {\n get: l\n } : {\n set: u\n };\n try {\n return e(o, f);\n } finally {\n p.v = !0;\n }\n }\n function assertCallable(e, t) {\n if (\"function\" != typeof e) throw new TypeError(t + \" must be a function\");\n }\n function assertValidReturnValue(e, t) {\n var r = typeof t;\n if (1 === e) {\n if (\"object\" !== r || null === t) throw new TypeError(\"accessor decorators must return an object with get, set, or init properties or void 0\");\n void 0 !== t.get && assertCallable(t.get, \"accessor.get\"), void 0 !== t.set && assertCallable(t.set, \"accessor.set\"), void 0 !== t.init && assertCallable(t.init, \"accessor.init\");\n } else if (\"function\" !== r) {\n var a;\n throw a = 0 === e ? \"field\" : 10 === e ? \"class\" : \"method\", new TypeError(a + \" decorators must return a function or void 0\");\n }\n }\n function applyMemberDec(e, t, r, a, n, i, s, o) {\n var c,\n l,\n u,\n f,\n p,\n d,\n h = r[0];\n if (s ? c = 0 === n || 1 === n ? {\n get: r[3],\n set: r[4]\n } : 3 === n ? {\n get: r[3]\n } : 4 === n ? {\n set: r[3]\n } : {\n value: r[3]\n } : 0 !== n && (c = Object.getOwnPropertyDescriptor(t, a)), 1 === n ? u = {\n get: c.get,\n set: c.set\n } : 2 === n ? u = c.value : 3 === n ? u = c.get : 4 === n && (u = c.set), \"function\" == typeof h) void 0 !== (f = memberDec(h, a, c, o, n, i, s, u)) && (assertValidReturnValue(n, f), 0 === n ? l = f : 1 === n ? (l = f.init, p = f.get || u.get, d = f.set || u.set, u = {\n get: p,\n set: d\n }) : u = f);else for (var v = h.length - 1; v >= 0; v--) {\n var g;\n if (void 0 !== (f = memberDec(h[v], a, c, o, n, i, s, u))) assertValidReturnValue(n, f), 0 === n ? g = f : 1 === n ? (g = f.init, p = f.get || u.get, d = f.set || u.set, u = {\n get: p,\n set: d\n }) : u = f, void 0 !== g && (void 0 === l ? l = g : \"function\" == typeof l ? l = [l, g] : l.push(g));\n }\n if (0 === n || 1 === n) {\n if (void 0 === l) l = function (e, t) {\n return t;\n };else if (\"function\" != typeof l) {\n var y = l;\n l = function (e, t) {\n for (var r = t, a = 0; a < y.length; a++) r = y[a].call(e, r);\n return r;\n };\n } else {\n var m = l;\n l = function (e, t) {\n return m.call(e, t);\n };\n }\n e.push(l);\n }\n 0 !== n && (1 === n ? (c.get = u.get, c.set = u.set) : 2 === n ? c.value = u : 3 === n ? c.get = u : 4 === n && (c.set = u), s ? 1 === n ? (e.push(function (e, t) {\n return u.get.call(e, t);\n }), e.push(function (e, t) {\n return u.set.call(e, t);\n })) : 2 === n ? e.push(u) : e.push(function (e, t) {\n return u.call(e, t);\n }) : Object.defineProperty(t, a, c));\n }\n function pushInitializers(e, t) {\n t && e.push(function (e) {\n for (var r = 0; r < t.length; r++) t[r].call(e);\n return e;\n });\n }\n return function (e, t, r) {\n var a = [];\n return function (e, t, r) {\n for (var a, n, i = new Map(), s = new Map(), o = 0; o < r.length; o++) {\n var c = r[o];\n if (Array.isArray(c)) {\n var l,\n u,\n f = c[1],\n p = c[2],\n d = c.length > 3,\n h = f >= 5;\n if (h ? (l = t, 0 != (f -= 5) && (u = n = n || [])) : (l = t.prototype, 0 !== f && (u = a = a || [])), 0 !== f && !d) {\n var v = h ? s : i,\n g = v.get(p) || 0;\n if (!0 === g || 3 === g && 4 !== f || 4 === g && 3 !== f) throw new Error(\"Attempted to decorate a public method/accessor that has the same name as a previously decorated public method/accessor. This is not currently supported by the decorators plugin. Property name was: \" + p);\n !g && f > 2 ? v.set(p, f) : v.set(p, !0);\n }\n applyMemberDec(e, l, c, p, f, h, d, u);\n }\n }\n pushInitializers(e, a), pushInitializers(e, n);\n }(a, e, t), function (e, t, r) {\n if (r.length > 0) {\n for (var a = [], n = t, i = t.name, s = r.length - 1; s >= 0; s--) {\n var o = {\n v: !1\n };\n try {\n var c = r[s](n, {\n kind: \"class\",\n name: i,\n addInitializer: createAddInitializerMethod(a, o)\n });\n } finally {\n o.v = !0;\n }\n void 0 !== c && (assertValidReturnValue(10, c), n = c);\n }\n e.push(n, function () {\n for (var e = 0; e < a.length; e++) a[e].call(n);\n });\n }\n }(a, e, r), a;\n };\n }\n var applyDecs2203Impl;\n function _applyDecs2203(e, t, r) {\n return (applyDecs2203Impl = applyDecs2203Impl || applyDecs2203Factory())(e, t, r);\n }\n function applyDecs2203RFactory() {\n function createAddInitializerMethod(e, t) {\n return function (r) {\n !function (e, t) {\n if (e.v) throw new Error(\"attempted to call \" + t + \" after decoration was finished\");\n }(t, \"addInitializer\"), assertCallable(r, \"An initializer\"), e.push(r);\n };\n }\n function memberDec(e, t, r, n, a, i, s, o) {\n var c;\n switch (a) {\n case 1:\n c = \"accessor\";\n break;\n case 2:\n c = \"method\";\n break;\n case 3:\n c = \"getter\";\n break;\n case 4:\n c = \"setter\";\n break;\n default:\n c = \"field\";\n }\n var l,\n u,\n f = {\n kind: c,\n name: s ? \"#\" + t : t,\n static: i,\n private: s\n },\n p = {\n v: !1\n };\n 0 !== a && (f.addInitializer = createAddInitializerMethod(n, p)), 0 === a ? s ? (l = r.get, u = r.set) : (l = function () {\n return this[t];\n }, u = function (e) {\n this[t] = e;\n }) : 2 === a ? l = function () {\n return r.value;\n } : (1 !== a && 3 !== a || (l = function () {\n return r.get.call(this);\n }), 1 !== a && 4 !== a || (u = function (e) {\n r.set.call(this, e);\n })), f.access = l && u ? {\n get: l,\n set: u\n } : l ? {\n get: l\n } : {\n set: u\n };\n try {\n return e(o, f);\n } finally {\n p.v = !0;\n }\n }\n function assertCallable(e, t) {\n if (\"function\" != typeof e) throw new TypeError(t + \" must be a function\");\n }\n function assertValidReturnValue(e, t) {\n var r = typeof t;\n if (1 === e) {\n if (\"object\" !== r || null === t) throw new TypeError(\"accessor decorators must return an object with get, set, or init properties or void 0\");\n void 0 !== t.get && assertCallable(t.get, \"accessor.get\"), void 0 !== t.set && assertCallable(t.set, \"accessor.set\"), void 0 !== t.init && assertCallable(t.init, \"accessor.init\");\n } else if (\"function\" !== r) {\n var n;\n throw n = 0 === e ? \"field\" : 10 === e ? \"class\" : \"method\", new TypeError(n + \" decorators must return a function or void 0\");\n }\n }\n function applyMemberDec(e, t, r, n, a, i, s, o) {\n var c,\n l,\n u,\n f,\n p,\n d,\n h = r[0];\n if (s ? c = 0 === a || 1 === a ? {\n get: r[3],\n set: r[4]\n } : 3 === a ? {\n get: r[3]\n } : 4 === a ? {\n set: r[3]\n } : {\n value: r[3]\n } : 0 !== a && (c = Object.getOwnPropertyDescriptor(t, n)), 1 === a ? u = {\n get: c.get,\n set: c.set\n } : 2 === a ? u = c.value : 3 === a ? u = c.get : 4 === a && (u = c.set), \"function\" == typeof h) void 0 !== (f = memberDec(h, n, c, o, a, i, s, u)) && (assertValidReturnValue(a, f), 0 === a ? l = f : 1 === a ? (l = f.init, p = f.get || u.get, d = f.set || u.set, u = {\n get: p,\n set: d\n }) : u = f);else for (var v = h.length - 1; v >= 0; v--) {\n var g;\n if (void 0 !== (f = memberDec(h[v], n, c, o, a, i, s, u))) assertValidReturnValue(a, f), 0 === a ? g = f : 1 === a ? (g = f.init, p = f.get || u.get, d = f.set || u.set, u = {\n get: p,\n set: d\n }) : u = f, void 0 !== g && (void 0 === l ? l = g : \"function\" == typeof l ? l = [l, g] : l.push(g));\n }\n if (0 === a || 1 === a) {\n if (void 0 === l) l = function (e, t) {\n return t;\n };else if (\"function\" != typeof l) {\n var y = l;\n l = function (e, t) {\n for (var r = t, n = 0; n < y.length; n++) r = y[n].call(e, r);\n return r;\n };\n } else {\n var m = l;\n l = function (e, t) {\n return m.call(e, t);\n };\n }\n e.push(l);\n }\n 0 !== a && (1 === a ? (c.get = u.get, c.set = u.set) : 2 === a ? c.value = u : 3 === a ? c.get = u : 4 === a && (c.set = u), s ? 1 === a ? (e.push(function (e, t) {\n return u.get.call(e, t);\n }), e.push(function (e, t) {\n return u.set.call(e, t);\n })) : 2 === a ? e.push(u) : e.push(function (e, t) {\n return u.call(e, t);\n }) : Object.defineProperty(t, n, c));\n }\n function applyMemberDecs(e, t) {\n for (var r, n, a = [], i = new Map(), s = new Map(), o = 0; o < t.length; o++) {\n var c = t[o];\n if (Array.isArray(c)) {\n var l,\n u,\n f = c[1],\n p = c[2],\n d = c.length > 3,\n h = f >= 5;\n if (h ? (l = e, 0 !== (f -= 5) && (u = n = n || [])) : (l = e.prototype, 0 !== f && (u = r = r || [])), 0 !== f && !d) {\n var v = h ? s : i,\n g = v.get(p) || 0;\n if (!0 === g || 3 === g && 4 !== f || 4 === g && 3 !== f) throw new Error(\"Attempted to decorate a public method/accessor that has the same name as a previously decorated public method/accessor. This is not currently supported by the decorators plugin. Property name was: \" + p);\n !g && f > 2 ? v.set(p, f) : v.set(p, !0);\n }\n applyMemberDec(a, l, c, p, f, h, d, u);\n }\n }\n return pushInitializers(a, r), pushInitializers(a, n), a;\n }\n function pushInitializers(e, t) {\n t && e.push(function (e) {\n for (var r = 0; r < t.length; r++) t[r].call(e);\n return e;\n });\n }\n return function (e, t, r) {\n return {\n e: applyMemberDecs(e, t),\n get c() {\n return function (e, t) {\n if (t.length > 0) {\n for (var r = [], n = e, a = e.name, i = t.length - 1; i >= 0; i--) {\n var s = {\n v: !1\n };\n try {\n var o = t[i](n, {\n kind: \"class\",\n name: a,\n addInitializer: createAddInitializerMethod(r, s)\n });\n } finally {\n s.v = !0;\n }\n void 0 !== o && (assertValidReturnValue(10, o), n = o);\n }\n return [n, function () {\n for (var e = 0; e < r.length; e++) r[e].call(n);\n }];\n }\n }(e, r);\n }\n };\n };\n }\n function _applyDecs2203R(e, t, r) {\n return (_applyDecs2203R = applyDecs2203RFactory())(e, t, r);\n }\n function applyDecs2301Factory() {\n function createAddInitializerMethod(e, t) {\n return function (r) {\n !function (e, t) {\n if (e.v) throw new Error(\"attempted to call \" + t + \" after decoration was finished\");\n }(t, \"addInitializer\"), assertCallable(r, \"An initializer\"), e.push(r);\n };\n }\n function assertInstanceIfPrivate(e, t) {\n if (!e(t)) throw new TypeError(\"Attempted to access private element on non-instance\");\n }\n function memberDec(e, t, r, n, a, i, s, o, c) {\n var u;\n switch (a) {\n case 1:\n u = \"accessor\";\n break;\n case 2:\n u = \"method\";\n break;\n case 3:\n u = \"getter\";\n break;\n case 4:\n u = \"setter\";\n break;\n default:\n u = \"field\";\n }\n var l,\n f,\n p = {\n kind: u,\n name: s ? \"#\" + t : t,\n static: i,\n private: s\n },\n d = {\n v: !1\n };\n if (0 !== a && (p.addInitializer = createAddInitializerMethod(n, d)), s || 0 !== a && 2 !== a) {\n if (2 === a) l = function (e) {\n return assertInstanceIfPrivate(c, e), r.value;\n };else {\n var h = 0 === a || 1 === a;\n (h || 3 === a) && (l = s ? function (e) {\n return assertInstanceIfPrivate(c, e), r.get.call(e);\n } : function (e) {\n return r.get.call(e);\n }), (h || 4 === a) && (f = s ? function (e, t) {\n assertInstanceIfPrivate(c, e), r.set.call(e, t);\n } : function (e, t) {\n r.set.call(e, t);\n });\n }\n } else l = function (e) {\n return e[t];\n }, 0 === a && (f = function (e, r) {\n e[t] = r;\n });\n var v = s ? c.bind() : function (e) {\n return t in e;\n };\n p.access = l && f ? {\n get: l,\n set: f,\n has: v\n } : l ? {\n get: l,\n has: v\n } : {\n set: f,\n has: v\n };\n try {\n return e(o, p);\n } finally {\n d.v = !0;\n }\n }\n function assertCallable(e, t) {\n if (\"function\" != typeof e) throw new TypeError(t + \" must be a function\");\n }\n function assertValidReturnValue(e, t) {\n var r = typeof t;\n if (1 === e) {\n if (\"object\" !== r || null === t) throw new TypeError(\"accessor decorators must return an object with get, set, or init properties or void 0\");\n void 0 !== t.get && assertCallable(t.get, \"accessor.get\"), void 0 !== t.set && assertCallable(t.set, \"accessor.set\"), void 0 !== t.init && assertCallable(t.init, \"accessor.init\");\n } else if (\"function\" !== r) {\n var n;\n throw n = 0 === e ? \"field\" : 10 === e ? \"class\" : \"method\", new TypeError(n + \" decorators must return a function or void 0\");\n }\n }\n function curryThis2(e) {\n return function (t) {\n e(this, t);\n };\n }\n function applyMemberDec(e, t, r, n, a, i, s, o, c) {\n var u,\n l,\n f,\n p,\n d,\n h,\n v,\n g = r[0];\n if (s ? u = 0 === a || 1 === a ? {\n get: (p = r[3], function () {\n return p(this);\n }),\n set: curryThis2(r[4])\n } : 3 === a ? {\n get: r[3]\n } : 4 === a ? {\n set: r[3]\n } : {\n value: r[3]\n } : 0 !== a && (u = Object.getOwnPropertyDescriptor(t, n)), 1 === a ? f = {\n get: u.get,\n set: u.set\n } : 2 === a ? f = u.value : 3 === a ? f = u.get : 4 === a && (f = u.set), \"function\" == typeof g) void 0 !== (d = memberDec(g, n, u, o, a, i, s, f, c)) && (assertValidReturnValue(a, d), 0 === a ? l = d : 1 === a ? (l = d.init, h = d.get || f.get, v = d.set || f.set, f = {\n get: h,\n set: v\n }) : f = d);else for (var y = g.length - 1; y >= 0; y--) {\n var m;\n if (void 0 !== (d = memberDec(g[y], n, u, o, a, i, s, f, c))) assertValidReturnValue(a, d), 0 === a ? m = d : 1 === a ? (m = d.init, h = d.get || f.get, v = d.set || f.set, f = {\n get: h,\n set: v\n }) : f = d, void 0 !== m && (void 0 === l ? l = m : \"function\" == typeof l ? l = [l, m] : l.push(m));\n }\n if (0 === a || 1 === a) {\n if (void 0 === l) l = function (e, t) {\n return t;\n };else if (\"function\" != typeof l) {\n var b = l;\n l = function (e, t) {\n for (var r = t, n = 0; n < b.length; n++) r = b[n].call(e, r);\n return r;\n };\n } else {\n var I = l;\n l = function (e, t) {\n return I.call(e, t);\n };\n }\n e.push(l);\n }\n 0 !== a && (1 === a ? (u.get = f.get, u.set = f.set) : 2 === a ? u.value = f : 3 === a ? u.get = f : 4 === a && (u.set = f), s ? 1 === a ? (e.push(function (e, t) {\n return f.get.call(e, t);\n }), e.push(function (e, t) {\n return f.set.call(e, t);\n })) : 2 === a ? e.push(f) : e.push(function (e, t) {\n return f.call(e, t);\n }) : Object.defineProperty(t, n, u));\n }\n function applyMemberDecs(e, t, r) {\n for (var n, a, i, s = [], o = new Map(), c = new Map(), u = 0; u < t.length; u++) {\n var l = t[u];\n if (Array.isArray(l)) {\n var f,\n p,\n d = l[1],\n h = l[2],\n v = l.length > 3,\n g = d >= 5,\n y = r;\n if (g ? (f = e, 0 !== (d -= 5) && (p = a = a || []), v && !i && (i = function (t) {\n return _checkInRHS(t) === e;\n }), y = i) : (f = e.prototype, 0 !== d && (p = n = n || [])), 0 !== d && !v) {\n var m = g ? c : o,\n b = m.get(h) || 0;\n if (!0 === b || 3 === b && 4 !== d || 4 === b && 3 !== d) throw new Error(\"Attempted to decorate a public method/accessor that has the same name as a previously decorated public method/accessor. This is not currently supported by the decorators plugin. Property name was: \" + h);\n !b && d > 2 ? m.set(h, d) : m.set(h, !0);\n }\n applyMemberDec(s, f, l, h, d, g, v, p, y);\n }\n }\n return pushInitializers(s, n), pushInitializers(s, a), s;\n }\n function pushInitializers(e, t) {\n t && e.push(function (e) {\n for (var r = 0; r < t.length; r++) t[r].call(e);\n return e;\n });\n }\n return function (e, t, r, n) {\n return {\n e: applyMemberDecs(e, t, n),\n get c() {\n return function (e, t) {\n if (t.length > 0) {\n for (var r = [], n = e, a = e.name, i = t.length - 1; i >= 0; i--) {\n var s = {\n v: !1\n };\n try {\n var o = t[i](n, {\n kind: \"class\",\n name: a,\n addInitializer: createAddInitializerMethod(r, s)\n });\n } finally {\n s.v = !0;\n }\n void 0 !== o && (assertValidReturnValue(10, o), n = o);\n }\n return [n, function () {\n for (var e = 0; e < r.length; e++) r[e].call(n);\n }];\n }\n }(e, r);\n }\n };\n };\n }\n function _applyDecs2301(e, t, r, n) {\n return (_applyDecs2301 = applyDecs2301Factory())(e, t, r, n);\n }\n function createAddInitializerMethod(e, t) {\n return function (r) {\n assertNotFinished(t, \"addInitializer\"), assertCallable(r, \"An initializer\"), e.push(r);\n };\n }\n function assertInstanceIfPrivate(e, t) {\n if (!e(t)) throw new TypeError(\"Attempted to access private element on non-instance\");\n }\n function memberDec(e, t, r, a, n, i, s, o, c, l, u) {\n var f;\n switch (i) {\n case 1:\n f = \"accessor\";\n break;\n case 2:\n f = \"method\";\n break;\n case 3:\n f = \"getter\";\n break;\n case 4:\n f = \"setter\";\n break;\n default:\n f = \"field\";\n }\n var d,\n p,\n h = {\n kind: f,\n name: o ? \"#\" + r : r,\n static: s,\n private: o,\n metadata: u\n },\n v = {\n v: !1\n };\n if (0 !== i && (h.addInitializer = createAddInitializerMethod(n, v)), o || 0 !== i && 2 !== i) {\n if (2 === i) d = function (e) {\n return assertInstanceIfPrivate(l, e), a.value;\n };else {\n var y = 0 === i || 1 === i;\n (y || 3 === i) && (d = o ? function (e) {\n return assertInstanceIfPrivate(l, e), a.get.call(e);\n } : function (e) {\n return a.get.call(e);\n }), (y || 4 === i) && (p = o ? function (e, t) {\n assertInstanceIfPrivate(l, e), a.set.call(e, t);\n } : function (e, t) {\n a.set.call(e, t);\n });\n }\n } else d = function (e) {\n return e[r];\n }, 0 === i && (p = function (e, t) {\n e[r] = t;\n });\n var m = o ? l.bind() : function (e) {\n return r in e;\n };\n h.access = d && p ? {\n get: d,\n set: p,\n has: m\n } : d ? {\n get: d,\n has: m\n } : {\n set: p,\n has: m\n };\n try {\n return e.call(t, c, h);\n } finally {\n v.v = !0;\n }\n }\n function assertNotFinished(e, t) {\n if (e.v) throw new Error(\"attempted to call \" + t + \" after decoration was finished\");\n }\n function assertCallable(e, t) {\n if (\"function\" != typeof e) throw new TypeError(t + \" must be a function\");\n }\n function assertValidReturnValue(e, t) {\n var r = typeof t;\n if (1 === e) {\n if (\"object\" !== r || null === t) throw new TypeError(\"accessor decorators must return an object with get, set, or init properties or void 0\");\n void 0 !== t.get && assertCallable(t.get, \"accessor.get\"), void 0 !== t.set && assertCallable(t.set, \"accessor.set\"), void 0 !== t.init && assertCallable(t.init, \"accessor.init\");\n } else if (\"function\" !== r) {\n var a;\n throw a = 0 === e ? \"field\" : 5 === e ? \"class\" : \"method\", new TypeError(a + \" decorators must return a function or void 0\");\n }\n }\n function curryThis1(e) {\n return function () {\n return e(this);\n };\n }\n function curryThis2(e) {\n return function (t) {\n e(this, t);\n };\n }\n function applyMemberDec(e, t, r, a, n, i, s, o, c, l, u) {\n var f,\n d,\n p,\n h,\n v,\n y,\n m = r[0];\n a || Array.isArray(m) || (m = [m]), o ? f = 0 === i || 1 === i ? {\n get: curryThis1(r[3]),\n set: curryThis2(r[4])\n } : 3 === i ? {\n get: r[3]\n } : 4 === i ? {\n set: r[3]\n } : {\n value: r[3]\n } : 0 !== i && (f = Object.getOwnPropertyDescriptor(t, n)), 1 === i ? p = {\n get: f.get,\n set: f.set\n } : 2 === i ? p = f.value : 3 === i ? p = f.get : 4 === i && (p = f.set);\n for (var g = a ? 2 : 1, b = m.length - 1; b >= 0; b -= g) {\n var I;\n if (void 0 !== (h = memberDec(m[b], a ? m[b - 1] : void 0, n, f, c, i, s, o, p, l, u))) assertValidReturnValue(i, h), 0 === i ? I = h : 1 === i ? (I = h.init, v = h.get || p.get, y = h.set || p.set, p = {\n get: v,\n set: y\n }) : p = h, void 0 !== I && (void 0 === d ? d = I : \"function\" == typeof d ? d = [d, I] : d.push(I));\n }\n if (0 === i || 1 === i) {\n if (void 0 === d) d = function (e, t) {\n return t;\n };else if (\"function\" != typeof d) {\n var w = d;\n d = function (e, t) {\n for (var r = t, a = w.length - 1; a >= 0; a--) r = w[a].call(e, r);\n return r;\n };\n } else {\n var M = d;\n d = function (e, t) {\n return M.call(e, t);\n };\n }\n e.push(d);\n }\n 0 !== i && (1 === i ? (f.get = p.get, f.set = p.set) : 2 === i ? f.value = p : 3 === i ? f.get = p : 4 === i && (f.set = p), o ? 1 === i ? (e.push(function (e, t) {\n return p.get.call(e, t);\n }), e.push(function (e, t) {\n return p.set.call(e, t);\n })) : 2 === i ? e.push(p) : e.push(function (e, t) {\n return p.call(e, t);\n }) : Object.defineProperty(t, n, f));\n }\n function applyMemberDecs(e, t, r, a) {\n for (var n, i, s, o = [], c = new Map(), l = new Map(), u = 0; u < t.length; u++) {\n var f = t[u];\n if (Array.isArray(f)) {\n var d,\n p,\n h = f[1],\n v = f[2],\n y = f.length > 3,\n m = 16 & h,\n g = !!(8 & h),\n b = r;\n if (h &= 7, g ? (d = e, 0 !== h && (p = i = i || []), y && !s && (s = function (t) {\n return _checkInRHS(t) === e;\n }), b = s) : (d = e.prototype, 0 !== h && (p = n = n || [])), 0 !== h && !y) {\n var I = g ? l : c,\n w = I.get(v) || 0;\n if (!0 === w || 3 === w && 4 !== h || 4 === w && 3 !== h) throw new Error(\"Attempted to decorate a public method/accessor that has the same name as a previously decorated public method/accessor. This is not currently supported by the decorators plugin. Property name was: \" + v);\n I.set(v, !(!w && h > 2) || h);\n }\n applyMemberDec(o, d, f, m, v, h, g, y, p, b, a);\n }\n }\n return pushInitializers(o, n), pushInitializers(o, i), o;\n }\n function pushInitializers(e, t) {\n t && e.push(function (e) {\n for (var r = 0; r < t.length; r++) t[r].call(e);\n return e;\n });\n }\n function applyClassDecs(e, t, r, a) {\n if (t.length) {\n for (var n = [], i = e, s = e.name, o = r ? 2 : 1, c = t.length - 1; c >= 0; c -= o) {\n var l = {\n v: !1\n };\n try {\n var u = t[c].call(r ? t[c - 1] : void 0, i, {\n kind: \"class\",\n name: s,\n addInitializer: createAddInitializerMethod(n, l),\n metadata: a\n });\n } finally {\n l.v = !0;\n }\n void 0 !== u && (assertValidReturnValue(5, u), i = u);\n }\n return [defineMetadata(i, a), function () {\n for (var e = 0; e < n.length; e++) n[e].call(i);\n }];\n }\n }\n function defineMetadata(e, t) {\n return Object.defineProperty(e, Symbol.metadata || Symbol.for(\"Symbol.metadata\"), {\n configurable: !0,\n enumerable: !0,\n value: t\n });\n }\n function _applyDecs2305(e, t, r, a, n, i) {\n if (arguments.length >= 6) var s = i[Symbol.metadata || Symbol.for(\"Symbol.metadata\")];\n var o = Object.create(void 0 === s ? null : s),\n c = applyMemberDecs(e, t, n, o);\n return r.length || defineMetadata(e, o), {\n e: c,\n get c() {\n return applyClassDecs(e, r, a, o);\n }\n };\n }\n function _asyncGeneratorDelegate(t) {\n var e = {},\n n = !1;\n function pump(e, r) {\n return n = !0, r = new Promise(function (n) {\n n(t[e](r));\n }), {\n done: !1,\n value: new _OverloadYield(r, 1)\n };\n }\n return e[\"undefined\" != typeof Symbol && Symbol.iterator || \"@@iterator\"] = function () {\n return this;\n }, e.next = function (t) {\n return n ? (n = !1, t) : pump(\"next\", t);\n }, \"function\" == typeof t.throw && (e.throw = function (t) {\n if (n) throw n = !1, t;\n return pump(\"throw\", t);\n }), \"function\" == typeof t.return && (e.return = function (t) {\n return n ? (n = !1, t) : pump(\"return\", t);\n }), e;\n }\n function _asyncIterator(r) {\n var n,\n t,\n o,\n e = 2;\n for (\"undefined\" != typeof Symbol && (t = Symbol.asyncIterator, o = Symbol.iterator); e--;) {\n if (t && null != (n = r[t])) return n.call(r);\n if (o && null != (n = r[o])) return new AsyncFromSyncIterator(n.call(r));\n t = \"@@asyncIterator\", o = \"@@iterator\";\n }\n throw new TypeError(\"Object is not async iterable\");\n }\n function AsyncFromSyncIterator(r) {\n function AsyncFromSyncIteratorContinuation(r) {\n if (Object(r) !== r) return Promise.reject(new TypeError(r + \" is not an object.\"));\n var n = r.done;\n return Promise.resolve(r.value).then(function (r) {\n return {\n value: r,\n done: n\n };\n });\n }\n return AsyncFromSyncIterator = function (r) {\n this.s = r, this.n = r.next;\n }, AsyncFromSyncIterator.prototype = {\n s: null,\n n: null,\n next: function () {\n return AsyncFromSyncIteratorContinuation(this.n.apply(this.s, arguments));\n },\n return: function (r) {\n var n = this.s.return;\n return void 0 === n ? Promise.resolve({\n value: r,\n done: !0\n }) : AsyncFromSyncIteratorContinuation(n.apply(this.s, arguments));\n },\n throw: function (r) {\n var n = this.s.return;\n return void 0 === n ? Promise.reject(r) : AsyncFromSyncIteratorContinuation(n.apply(this.s, arguments));\n }\n }, new AsyncFromSyncIterator(r);\n }\n function _awaitAsyncGenerator(e) {\n return new _OverloadYield(e, 0);\n }\n function _checkInRHS(e) {\n if (Object(e) !== e) throw TypeError(\"right-hand side of 'in' should be an object, got \" + (null !== e ? typeof e : \"null\"));\n return e;\n }\n function _defineAccessor(e, r, n, t) {\n var c = {\n configurable: !0,\n enumerable: !0\n };\n return c[e] = t, Object.defineProperty(r, n, c);\n }\n function dispose_SuppressedError(r, e) {\n return \"undefined\" != typeof SuppressedError ? dispose_SuppressedError = SuppressedError : (dispose_SuppressedError = function (r, e) {\n this.suppressed = r, this.error = e, this.stack = new Error().stack;\n }, dispose_SuppressedError.prototype = Object.create(Error.prototype, {\n constructor: {\n value: dispose_SuppressedError,\n writable: !0,\n configurable: !0\n }\n })), new dispose_SuppressedError(r, e);\n }\n function _dispose(r, e, s) {\n function next() {\n for (; r.length > 0;) try {\n var o = r.pop(),\n p = o.d.call(o.v);\n if (o.a) return Promise.resolve(p).then(next, err);\n } catch (r) {\n return err(r);\n }\n if (s) throw e;\n }\n function err(r) {\n return e = s ? new dispose_SuppressedError(r, e) : r, s = !0, next();\n }\n return next();\n }\n function _importDeferProxy(e) {\n var t = null,\n constValue = function (e) {\n return function () {\n return e;\n };\n },\n proxy = function (r) {\n return function (n, o, f) {\n return null === t && (t = e()), r(t, o, f);\n };\n };\n return new Proxy({}, {\n defineProperty: constValue(!1),\n deleteProperty: constValue(!1),\n get: proxy(Reflect.get),\n getOwnPropertyDescriptor: proxy(Reflect.getOwnPropertyDescriptor),\n getPrototypeOf: constValue(null),\n isExtensible: constValue(!1),\n has: proxy(Reflect.has),\n ownKeys: proxy(Reflect.ownKeys),\n preventExtensions: constValue(!0),\n set: constValue(!1),\n setPrototypeOf: constValue(!1)\n });\n }\n function _iterableToArrayLimit(r, l) {\n var t = null == r ? null : \"undefined\" != typeof Symbol && r[Symbol.iterator] || r[\"@@iterator\"];\n if (null != t) {\n var e,\n n,\n i,\n u,\n a = [],\n f = !0,\n o = !1;\n try {\n if (i = (t = t.call(r)).next, 0 === l) {\n if (Object(t) !== t) return;\n f = !1;\n } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0);\n } catch (r) {\n o = !0, n = r;\n } finally {\n try {\n if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return;\n } finally {\n if (o) throw n;\n }\n }\n return a;\n }\n }\n function _iterableToArrayLimitLoose(e, r) {\n var t = e && (\"undefined\" != typeof Symbol && e[Symbol.iterator] || e[\"@@iterator\"]);\n if (null != t) {\n var o,\n l = [];\n for (t = t.call(e); e.length < r && !(o = t.next()).done;) l.push(o.value);\n return l;\n }\n }\n var REACT_ELEMENT_TYPE;\n function _jsx(e, r, E, l) {\n REACT_ELEMENT_TYPE || (REACT_ELEMENT_TYPE = \"function\" == typeof Symbol && Symbol.for && Symbol.for(\"react.element\") || 60103);\n var o = e && e.defaultProps,\n n = arguments.length - 3;\n if (r || 0 === n || (r = {\n children: void 0\n }), 1 === n) r.children = l;else if (n > 1) {\n for (var t = new Array(n), f = 0; f < n; f++) t[f] = arguments[f + 3];\n r.children = t;\n }\n if (r && o) for (var i in o) void 0 === r[i] && (r[i] = o[i]);else r || (r = o || {});\n return {\n $$typeof: REACT_ELEMENT_TYPE,\n type: e,\n key: void 0 === E ? null : \"\" + E,\n ref: null,\n props: r,\n _owner: null\n };\n }\n function ownKeys(e, r) {\n var t = Object.keys(e);\n if (Object.getOwnPropertySymbols) {\n var o = Object.getOwnPropertySymbols(e);\n r && (o = o.filter(function (r) {\n return Object.getOwnPropertyDescriptor(e, r).enumerable;\n })), t.push.apply(t, o);\n }\n return t;\n }\n function _objectSpread2(e) {\n for (var r = 1; r < arguments.length; r++) {\n var t = null != arguments[r] ? arguments[r] : {};\n r % 2 ? ownKeys(Object(t), !0).forEach(function (r) {\n _defineProperty(e, r, t[r]);\n }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) {\n Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r));\n });\n }\n return e;\n }\n function _regeneratorRuntime() {\n \"use strict\"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */\n _regeneratorRuntime = function () {\n return e;\n };\n var t,\n e = {},\n r = Object.prototype,\n n = r.hasOwnProperty,\n o = Object.defineProperty || function (t, e, r) {\n t[e] = r.value;\n },\n i = \"function\" == typeof Symbol ? Symbol : {},\n a = i.iterator || \"@@iterator\",\n c = i.asyncIterator || \"@@asyncIterator\",\n u = i.toStringTag || \"@@toStringTag\";\n function define(t, e, r) {\n return Object.defineProperty(t, e, {\n value: r,\n enumerable: !0,\n configurable: !0,\n writable: !0\n }), t[e];\n }\n try {\n define({}, \"\");\n } catch (t) {\n define = function (t, e, r) {\n return t[e] = r;\n };\n }\n function wrap(t, e, r, n) {\n var i = e && e.prototype instanceof Generator ? e : Generator,\n a = Object.create(i.prototype),\n c = new Context(n || []);\n return o(a, \"_invoke\", {\n value: makeInvokeMethod(t, r, c)\n }), a;\n }\n function tryCatch(t, e, r) {\n try {\n return {\n type: \"normal\",\n arg: t.call(e, r)\n };\n } catch (t) {\n return {\n type: \"throw\",\n arg: t\n };\n }\n }\n e.wrap = wrap;\n var h = \"suspendedStart\",\n l = \"suspendedYield\",\n f = \"executing\",\n s = \"completed\",\n y = {};\n function Generator() {}\n function GeneratorFunction() {}\n function GeneratorFunctionPrototype() {}\n var p = {};\n define(p, a, function () {\n return this;\n });\n var d = Object.getPrototypeOf,\n v = d && d(d(values([])));\n v && v !== r && n.call(v, a) && (p = v);\n var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p);\n function defineIteratorMethods(t) {\n [\"next\", \"throw\", \"return\"].forEach(function (e) {\n define(t, e, function (t) {\n return this._invoke(e, t);\n });\n });\n }\n function AsyncIterator(t, e) {\n function invoke(r, o, i, a) {\n var c = tryCatch(t[r], t, o);\n if (\"throw\" !== c.type) {\n var u = c.arg,\n h = u.value;\n return h && \"object\" == typeof h && n.call(h, \"__await\") ? e.resolve(h.__await).then(function (t) {\n invoke(\"next\", t, i, a);\n }, function (t) {\n invoke(\"throw\", t, i, a);\n }) : e.resolve(h).then(function (t) {\n u.value = t, i(u);\n }, function (t) {\n return invoke(\"throw\", t, i, a);\n });\n }\n a(c.arg);\n }\n var r;\n o(this, \"_invoke\", {\n value: function (t, n) {\n function callInvokeWithMethodAndArg() {\n return new e(function (e, r) {\n invoke(t, n, e, r);\n });\n }\n return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg();\n }\n });\n }\n function makeInvokeMethod(e, r, n) {\n var o = h;\n return function (i, a) {\n if (o === f) throw new Error(\"Generator is already running\");\n if (o === s) {\n if (\"throw\" === i) throw a;\n return {\n value: t,\n done: !0\n };\n }\n for (n.method = i, n.arg = a;;) {\n var c = n.delegate;\n if (c) {\n var u = maybeInvokeDelegate(c, n);\n if (u) {\n if (u === y) continue;\n return u;\n }\n }\n if (\"next\" === n.method) n.sent = n._sent = n.arg;else if (\"throw\" === n.method) {\n if (o === h) throw o = s, n.arg;\n n.dispatchException(n.arg);\n } else \"return\" === n.method && n.abrupt(\"return\", n.arg);\n o = f;\n var p = tryCatch(e, r, n);\n if (\"normal\" === p.type) {\n if (o = n.done ? s : l, p.arg === y) continue;\n return {\n value: p.arg,\n done: n.done\n };\n }\n \"throw\" === p.type && (o = s, n.method = \"throw\", n.arg = p.arg);\n }\n };\n }\n function maybeInvokeDelegate(e, r) {\n var n = r.method,\n o = e.iterator[n];\n if (o === t) return r.delegate = null, \"throw\" === n && e.iterator.return && (r.method = \"return\", r.arg = t, maybeInvokeDelegate(e, r), \"throw\" === r.method) || \"return\" !== n && (r.method = \"throw\", r.arg = new TypeError(\"The iterator does not provide a '\" + n + \"' method\")), y;\n var i = tryCatch(o, e.iterator, r.arg);\n if (\"throw\" === i.type) return r.method = \"throw\", r.arg = i.arg, r.delegate = null, y;\n var a = i.arg;\n return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, \"return\" !== r.method && (r.method = \"next\", r.arg = t), r.delegate = null, y) : a : (r.method = \"throw\", r.arg = new TypeError(\"iterator result is not an object\"), r.delegate = null, y);\n }\n function pushTryEntry(t) {\n var e = {\n tryLoc: t[0]\n };\n 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e);\n }\n function resetTryEntry(t) {\n var e = t.completion || {};\n e.type = \"normal\", delete e.arg, t.completion = e;\n }\n function Context(t) {\n this.tryEntries = [{\n tryLoc: \"root\"\n }], t.forEach(pushTryEntry, this), this.reset(!0);\n }\n function values(e) {\n if (e || \"\" === e) {\n var r = e[a];\n if (r) return r.call(e);\n if (\"function\" == typeof e.next) return e;\n if (!isNaN(e.length)) {\n var o = -1,\n i = function next() {\n for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next;\n return next.value = t, next.done = !0, next;\n };\n return i.next = i;\n }\n }\n throw new TypeError(typeof e + \" is not iterable\");\n }\n return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, \"constructor\", {\n value: GeneratorFunctionPrototype,\n configurable: !0\n }), o(GeneratorFunctionPrototype, \"constructor\", {\n value: GeneratorFunction,\n configurable: !0\n }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, \"GeneratorFunction\"), e.isGeneratorFunction = function (t) {\n var e = \"function\" == typeof t && t.constructor;\n return !!e && (e === GeneratorFunction || \"GeneratorFunction\" === (e.displayName || e.name));\n }, e.mark = function (t) {\n return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, \"GeneratorFunction\")), t.prototype = Object.create(g), t;\n }, e.awrap = function (t) {\n return {\n __await: t\n };\n }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () {\n return this;\n }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) {\n void 0 === i && (i = Promise);\n var a = new AsyncIterator(wrap(t, r, n, o), i);\n return e.isGeneratorFunction(r) ? a : a.next().then(function (t) {\n return t.done ? t.value : a.next();\n });\n }, defineIteratorMethods(g), define(g, u, \"Generator\"), define(g, a, function () {\n return this;\n }), define(g, \"toString\", function () {\n return \"[object Generator]\";\n }), e.keys = function (t) {\n var e = Object(t),\n r = [];\n for (var n in e) r.push(n);\n return r.reverse(), function next() {\n for (; r.length;) {\n var t = r.pop();\n if (t in e) return next.value = t, next.done = !1, next;\n }\n return next.done = !0, next;\n };\n }, e.values = values, Context.prototype = {\n constructor: Context,\n reset: function (e) {\n if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = \"next\", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) \"t\" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t);\n },\n stop: function () {\n this.done = !0;\n var t = this.tryEntries[0].completion;\n if (\"throw\" === t.type) throw t.arg;\n return this.rval;\n },\n dispatchException: function (e) {\n if (this.done) throw e;\n var r = this;\n function handle(n, o) {\n return a.type = \"throw\", a.arg = e, r.next = n, o && (r.method = \"next\", r.arg = t), !!o;\n }\n for (var o = this.tryEntries.length - 1; o >= 0; --o) {\n var i = this.tryEntries[o],\n a = i.completion;\n if (\"root\" === i.tryLoc) return handle(\"end\");\n if (i.tryLoc <= this.prev) {\n var c = n.call(i, \"catchLoc\"),\n u = n.call(i, \"finallyLoc\");\n if (c && u) {\n if (this.prev < i.catchLoc) return handle(i.catchLoc, !0);\n if (this.prev < i.finallyLoc) return handle(i.finallyLoc);\n } else if (c) {\n if (this.prev < i.catchLoc) return handle(i.catchLoc, !0);\n } else {\n if (!u) throw new Error(\"try statement without catch or finally\");\n if (this.prev < i.finallyLoc) return handle(i.finallyLoc);\n }\n }\n }\n },\n abrupt: function (t, e) {\n for (var r = this.tryEntries.length - 1; r >= 0; --r) {\n var o = this.tryEntries[r];\n if (o.tryLoc <= this.prev && n.call(o, \"finallyLoc\") && this.prev < o.finallyLoc) {\n var i = o;\n break;\n }\n }\n i && (\"break\" === t || \"continue\" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null);\n var a = i ? i.completion : {};\n return a.type = t, a.arg = e, i ? (this.method = \"next\", this.next = i.finallyLoc, y) : this.complete(a);\n },\n complete: function (t, e) {\n if (\"throw\" === t.type) throw t.arg;\n return \"break\" === t.type || \"continue\" === t.type ? this.next = t.arg : \"return\" === t.type ? (this.rval = this.arg = t.arg, this.method = \"return\", this.next = \"end\") : \"normal\" === t.type && e && (this.next = e), y;\n },\n finish: function (t) {\n for (var e = this.tryEntries.length - 1; e >= 0; --e) {\n var r = this.tryEntries[e];\n if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y;\n }\n },\n catch: function (t) {\n for (var e = this.tryEntries.length - 1; e >= 0; --e) {\n var r = this.tryEntries[e];\n if (r.tryLoc === t) {\n var n = r.completion;\n if (\"throw\" === n.type) {\n var o = n.arg;\n resetTryEntry(r);\n }\n return o;\n }\n }\n throw new Error(\"illegal catch attempt\");\n },\n delegateYield: function (e, r, n) {\n return this.delegate = {\n iterator: values(e),\n resultName: r,\n nextLoc: n\n }, \"next\" === this.method && (this.arg = t), y;\n }\n }, e;\n }\n function _typeof(o) {\n \"@babel/helpers - typeof\";\n\n return _typeof = \"function\" == typeof Symbol && \"symbol\" == typeof Symbol.iterator ? function (o) {\n return typeof o;\n } : function (o) {\n return o && \"function\" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? \"symbol\" : typeof o;\n }, _typeof(o);\n }\n function _using(o, e, n) {\n if (null == e) return e;\n if (\"object\" != typeof e) throw new TypeError(\"using declarations can only be used with objects, null, or undefined.\");\n if (n) var r = e[Symbol.asyncDispose || Symbol.for(\"Symbol.asyncDispose\")];\n if (null == r && (r = e[Symbol.dispose || Symbol.for(\"Symbol.dispose\")]), \"function\" != typeof r) throw new TypeError(\"Property [Symbol.dispose] is not a function.\");\n return o.push({\n v: e,\n d: r,\n a: n\n }), e;\n }\n function _wrapRegExp() {\n _wrapRegExp = function (e, r) {\n return new BabelRegExp(e, void 0, r);\n };\n var e = RegExp.prototype,\n r = new WeakMap();\n function BabelRegExp(e, t, p) {\n var o = new RegExp(e, t);\n return r.set(o, p || r.get(e)), _setPrototypeOf(o, BabelRegExp.prototype);\n }\n function buildGroups(e, t) {\n var p = r.get(t);\n return Object.keys(p).reduce(function (r, t) {\n var o = p[t];\n if (\"number\" == typeof o) r[t] = e[o];else {\n for (var i = 0; void 0 === e[o[i]] && i + 1 < o.length;) i++;\n r[t] = e[o[i]];\n }\n return r;\n }, Object.create(null));\n }\n return _inherits(BabelRegExp, RegExp), BabelRegExp.prototype.exec = function (r) {\n var t = e.exec.call(this, r);\n if (t) {\n t.groups = buildGroups(t, this);\n var p = t.indices;\n p && (p.groups = buildGroups(p, this));\n }\n return t;\n }, BabelRegExp.prototype[Symbol.replace] = function (t, p) {\n if (\"string\" == typeof p) {\n var o = r.get(this);\n return e[Symbol.replace].call(this, t, p.replace(/\\$<([^>]+)>/g, function (e, r) {\n var t = o[r];\n return \"$\" + (Array.isArray(t) ? t.join(\"$\") : t);\n }));\n }\n if (\"function\" == typeof p) {\n var i = this;\n return e[Symbol.replace].call(this, t, function () {\n var e = arguments;\n return \"object\" != typeof e[e.length - 1] && (e = [].slice.call(e)).push(buildGroups(e, i)), p.apply(this, e);\n });\n }\n return e[Symbol.replace].call(this, t, p);\n }, _wrapRegExp.apply(this, arguments);\n }\n function _AwaitValue(value) {\n this.wrapped = value;\n }\n function _wrapAsyncGenerator(fn) {\n return function () {\n return new _AsyncGenerator(fn.apply(this, arguments));\n };\n }\n function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {\n try {\n var info = gen[key](arg);\n var value = info.value;\n } catch (error) {\n reject(error);\n return;\n }\n if (info.done) {\n resolve(value);\n } else {\n Promise.resolve(value).then(_next, _throw);\n }\n }\n function _asyncToGenerator(fn) {\n return function () {\n var self = this,\n args = arguments;\n return new Promise(function (resolve, reject) {\n var gen = fn.apply(self, args);\n function _next(value) {\n asyncGeneratorStep(gen, resolve, reject, _next, _throw, \"next\", value);\n }\n function _throw(err) {\n asyncGeneratorStep(gen, resolve, reject, _next, _throw, \"throw\", err);\n }\n _next(undefined);\n });\n };\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 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, _toPropertyKey(descriptor.key), descriptor);\n }\n }\n function _createClass(Constructor, protoProps, staticProps) {\n if (protoProps) _defineProperties(Constructor.prototype, protoProps);\n if (staticProps) _defineProperties(Constructor, staticProps);\n Object.defineProperty(Constructor, \"prototype\", {\n writable: false\n });\n return Constructor;\n }\n function _defineEnumerableProperties(obj, descs) {\n for (var key in descs) {\n var desc = descs[key];\n desc.configurable = desc.enumerable = true;\n if (\"value\" in desc) desc.writable = true;\n Object.defineProperty(obj, key, desc);\n }\n if (Object.getOwnPropertySymbols) {\n var objectSymbols = Object.getOwnPropertySymbols(descs);\n for (var i = 0; i < objectSymbols.length; i++) {\n var sym = objectSymbols[i];\n var desc = descs[sym];\n desc.configurable = desc.enumerable = true;\n if (\"value\" in desc) desc.writable = true;\n Object.defineProperty(obj, sym, desc);\n }\n }\n return obj;\n }\n function _defaults(obj, defaults) {\n var keys = Object.getOwnPropertyNames(defaults);\n for (var i = 0; i < keys.length; i++) {\n var key = keys[i];\n var value = Object.getOwnPropertyDescriptor(defaults, key);\n if (value && value.configurable && obj[key] === undefined) {\n Object.defineProperty(obj, key, value);\n }\n }\n return obj;\n }\n function _defineProperty(obj, key, value) {\n key = _toPropertyKey(key);\n if (key in obj) {\n Object.defineProperty(obj, key, {\n value: value,\n enumerable: true,\n configurable: true,\n writable: true\n });\n } else {\n obj[key] = value;\n }\n return obj;\n }\n function _extends() {\n _extends = Object.assign ? Object.assign.bind() : function (target) {\n for (var i = 1; i < arguments.length; i++) {\n var source = arguments[i];\n for (var key in source) {\n if (Object.prototype.hasOwnProperty.call(source, key)) {\n target[key] = source[key];\n }\n }\n }\n return target;\n };\n return _extends.apply(this, arguments);\n }\n function _objectSpread(target) {\n for (var i = 1; i < arguments.length; i++) {\n var source = arguments[i] != null ? Object(arguments[i]) : {};\n var ownKeys = Object.keys(source);\n if (typeof Object.getOwnPropertySymbols === 'function') {\n ownKeys.push.apply(ownKeys, Object.getOwnPropertySymbols(source).filter(function (sym) {\n return Object.getOwnPropertyDescriptor(source, sym).enumerable;\n }));\n }\n ownKeys.forEach(function (key) {\n _defineProperty(target, key, source[key]);\n });\n }\n return target;\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 subClass.prototype = Object.create(superClass && superClass.prototype, {\n constructor: {\n value: subClass,\n writable: true,\n configurable: true\n }\n });\n Object.defineProperty(subClass, \"prototype\", {\n writable: false\n });\n if (superClass) _setPrototypeOf(subClass, superClass);\n }\n function _inheritsLoose(subClass, superClass) {\n subClass.prototype = Object.create(superClass.prototype);\n subClass.prototype.constructor = subClass;\n _setPrototypeOf(subClass, superClass);\n }\n function _getPrototypeOf(o) {\n _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) {\n return o.__proto__ || Object.getPrototypeOf(o);\n };\n return _getPrototypeOf(o);\n }\n function _setPrototypeOf(o, p) {\n _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) {\n o.__proto__ = p;\n return o;\n };\n return _setPrototypeOf(o, p);\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 try {\n Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {}));\n return true;\n } catch (e) {\n return false;\n }\n }\n function _construct(Parent, args, Class) {\n if (_isNativeReflectConstruct()) {\n _construct = Reflect.construct.bind();\n } else {\n _construct = function _construct(Parent, args, Class) {\n var a = [null];\n a.push.apply(a, args);\n var Constructor = Function.bind.apply(Parent, a);\n var instance = new Constructor();\n if (Class) _setPrototypeOf(instance, Class.prototype);\n return instance;\n };\n }\n return _construct.apply(null, arguments);\n }\n function _isNativeFunction(fn) {\n return Function.toString.call(fn).indexOf(\"[native code]\") !== -1;\n }\n function _wrapNativeSuper(Class) {\n var _cache = typeof Map === \"function\" ? new Map() : undefined;\n _wrapNativeSuper = function _wrapNativeSuper(Class) {\n if (Class === null || !_isNativeFunction(Class)) return Class;\n if (typeof Class !== \"function\") {\n throw new TypeError(\"Super expression must either be null or a function\");\n }\n if (typeof _cache !== \"undefined\") {\n if (_cache.has(Class)) return _cache.get(Class);\n _cache.set(Class, Wrapper);\n }\n function Wrapper() {\n return _construct(Class, arguments, _getPrototypeOf(this).constructor);\n }\n Wrapper.prototype = Object.create(Class.prototype, {\n constructor: {\n value: Wrapper,\n enumerable: false,\n writable: true,\n configurable: true\n }\n });\n return _setPrototypeOf(Wrapper, Class);\n };\n return _wrapNativeSuper(Class);\n }\n function _instanceof(left, right) {\n if (right != null && typeof Symbol !== \"undefined\" && right[Symbol.hasInstance]) {\n return !!right[Symbol.hasInstance](left);\n } else {\n return left instanceof right;\n }\n }\n function _interopRequireDefault(obj) {\n return obj && obj.__esModule ? obj : {\n default: obj\n };\n }\n function _getRequireWildcardCache(nodeInterop) {\n if (typeof WeakMap !== \"function\") return null;\n var cacheBabelInterop = new WeakMap();\n var cacheNodeInterop = new WeakMap();\n return (_getRequireWildcardCache = function (nodeInterop) {\n return nodeInterop ? cacheNodeInterop : cacheBabelInterop;\n })(nodeInterop);\n }\n function _interopRequireWildcard(obj, nodeInterop) {\n if (!nodeInterop && obj && obj.__esModule) {\n return obj;\n }\n if (obj === null || typeof obj !== \"object\" && typeof obj !== \"function\") {\n return {\n default: obj\n };\n }\n var cache = _getRequireWildcardCache(nodeInterop);\n if (cache && cache.has(obj)) {\n return cache.get(obj);\n }\n var newObj = {};\n var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;\n for (var key in obj) {\n if (key !== \"default\" && Object.prototype.hasOwnProperty.call(obj, key)) {\n var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;\n if (desc && (desc.get || desc.set)) {\n Object.defineProperty(newObj, key, desc);\n } else {\n newObj[key] = obj[key];\n }\n }\n }\n newObj.default = obj;\n if (cache) {\n cache.set(obj, newObj);\n }\n return newObj;\n }\n function _newArrowCheck(innerThis, boundThis) {\n if (innerThis !== boundThis) {\n throw new TypeError(\"Cannot instantiate an arrow function\");\n }\n }\n function _objectDestructuringEmpty(obj) {\n if (obj == null) throw new TypeError(\"Cannot destructure \" + obj);\n }\n function _objectWithoutPropertiesLoose(source, excluded) {\n if (source == null) return {};\n var target = {};\n var sourceKeys = Object.keys(source);\n var key, i;\n for (i = 0; i < sourceKeys.length; i++) {\n key = sourceKeys[i];\n if (excluded.indexOf(key) >= 0) continue;\n target[key] = source[key];\n }\n return target;\n }\n function _objectWithoutProperties(source, excluded) {\n if (source == null) return {};\n var target = _objectWithoutPropertiesLoose(source, excluded);\n var key, i;\n if (Object.getOwnPropertySymbols) {\n var sourceSymbolKeys = Object.getOwnPropertySymbols(source);\n for (i = 0; i < sourceSymbolKeys.length; i++) {\n key = sourceSymbolKeys[i];\n if (excluded.indexOf(key) >= 0) continue;\n if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue;\n target[key] = source[key];\n }\n }\n return target;\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 return self;\n }\n function _possibleConstructorReturn(self, call) {\n if (call && (typeof call === \"object\" || typeof call === \"function\")) {\n return call;\n } else if (call !== void 0) {\n throw new TypeError(\"Derived constructors may only return object or undefined\");\n }\n return _assertThisInitialized(self);\n }\n function _createSuper(Derived) {\n var hasNativeReflectConstruct = _isNativeReflectConstruct();\n return function _createSuperInternal() {\n var Super = _getPrototypeOf(Derived),\n result;\n if (hasNativeReflectConstruct) {\n var NewTarget = _getPrototypeOf(this).constructor;\n result = Reflect.construct(Super, arguments, NewTarget);\n } else {\n result = Super.apply(this, arguments);\n }\n return _possibleConstructorReturn(this, result);\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 return object;\n }\n function _get() {\n if (typeof Reflect !== \"undefined\" && Reflect.get) {\n _get = Reflect.get.bind();\n } else {\n _get = function _get(target, property, receiver) {\n var base = _superPropBase(target, property);\n if (!base) return;\n var desc = Object.getOwnPropertyDescriptor(base, property);\n if (desc.get) {\n return desc.get.call(arguments.length < 3 ? target : receiver);\n }\n return desc.value;\n };\n }\n return _get.apply(this, arguments);\n }\n function set(target, property, value, receiver) {\n if (typeof Reflect !== \"undefined\" && Reflect.set) {\n set = Reflect.set;\n } else {\n set = function set(target, property, value, receiver) {\n var base = _superPropBase(target, property);\n var desc;\n if (base) {\n desc = Object.getOwnPropertyDescriptor(base, property);\n if (desc.set) {\n desc.set.call(receiver, value);\n return true;\n } else if (!desc.writable) {\n return false;\n }\n }\n desc = Object.getOwnPropertyDescriptor(receiver, property);\n if (desc) {\n if (!desc.writable) {\n return false;\n }\n desc.value = value;\n Object.defineProperty(receiver, property, desc);\n } else {\n _defineProperty(receiver, property, value);\n }\n return true;\n };\n }\n return set(target, property, value, receiver);\n }\n function _set(target, property, value, receiver, isStrict) {\n var s = set(target, property, value, receiver || target);\n if (!s && isStrict) {\n throw new TypeError('failed to set property');\n }\n return value;\n }\n function _taggedTemplateLiteral(strings, raw) {\n if (!raw) {\n raw = strings.slice(0);\n }\n return Object.freeze(Object.defineProperties(strings, {\n raw: {\n value: Object.freeze(raw)\n }\n }));\n }\n function _taggedTemplateLiteralLoose(strings, raw) {\n if (!raw) {\n raw = strings.slice(0);\n }\n strings.raw = raw;\n return strings;\n }\n function _readOnlyError(name) {\n throw new TypeError(\"\\\"\" + name + \"\\\" is read-only\");\n }\n function _writeOnlyError(name) {\n throw new TypeError(\"\\\"\" + name + \"\\\" is write-only\");\n }\n function _classNameTDZError(name) {\n throw new ReferenceError(\"Class \\\"\" + name + \"\\\" cannot be referenced in computed property keys.\");\n }\n function _temporalUndefined() {}\n function _tdz(name) {\n throw new ReferenceError(name + \" is not defined - temporal dead zone\");\n }\n function _temporalRef(val, name) {\n return val === _temporalUndefined ? _tdz(name) : val;\n }\n function _slicedToArray(arr, i) {\n return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest();\n }\n function _slicedToArrayLoose(arr, i) {\n return _arrayWithHoles(arr) || _iterableToArrayLimitLoose(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest();\n }\n function _toArray(arr) {\n return _arrayWithHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableRest();\n }\n function _toConsumableArray(arr) {\n return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread();\n }\n function _arrayWithoutHoles(arr) {\n if (Array.isArray(arr)) return _arrayLikeToArray(arr);\n }\n function _arrayWithHoles(arr) {\n if (Array.isArray(arr)) return arr;\n }\n function _maybeArrayLike(next, arr, i) {\n if (arr && !Array.isArray(arr) && typeof arr.length === \"number\") {\n var len = arr.length;\n return _arrayLikeToArray(arr, i !== void 0 && i < len ? i : len);\n }\n return next(arr, i);\n }\n function _iterableToArray(iter) {\n if (typeof Symbol !== \"undefined\" && iter[Symbol.iterator] != null || iter[\"@@iterator\"] != null) return Array.from(iter);\n }\n function _unsupportedIterableToArray(o, minLen) {\n if (!o) return;\n if (typeof o === \"string\") return _arrayLikeToArray(o, minLen);\n var n = Object.prototype.toString.call(o).slice(8, -1);\n if (n === \"Object\" && o.constructor) n = o.constructor.name;\n if (n === \"Map\" || n === \"Set\") return Array.from(o);\n if (n === \"Arguments\" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);\n }\n function _arrayLikeToArray(arr, len) {\n if (len == null || len > arr.length) len = arr.length;\n for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];\n return arr2;\n }\n function _nonIterableSpread() {\n throw new TypeError(\"Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.\");\n }\n function _nonIterableRest() {\n throw new TypeError(\"Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.\");\n }\n function _createForOfIteratorHelper(o, allowArrayLike) {\n var it = typeof Symbol !== \"undefined\" && o[Symbol.iterator] || o[\"@@iterator\"];\n if (!it) {\n if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === \"number\") {\n if (it) o = it;\n var i = 0;\n var F = function () {};\n return {\n s: F,\n n: function () {\n if (i >= o.length) return {\n done: true\n };\n return {\n done: false,\n value: o[i++]\n };\n },\n e: function (e) {\n throw e;\n },\n f: F\n };\n }\n throw new TypeError(\"Invalid attempt to iterate non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.\");\n }\n var normalCompletion = true,\n didErr = false,\n err;\n return {\n s: function () {\n it = it.call(o);\n },\n n: function () {\n var step = it.next();\n normalCompletion = step.done;\n return step;\n },\n e: function (e) {\n didErr = true;\n err = e;\n },\n f: function () {\n try {\n if (!normalCompletion && it.return != null) it.return();\n } finally {\n if (didErr) throw err;\n }\n }\n };\n }\n function _createForOfIteratorHelperLoose(o, allowArrayLike) {\n var it = typeof Symbol !== \"undefined\" && o[Symbol.iterator] || o[\"@@iterator\"];\n if (it) return (it = it.call(o)).next.bind(it);\n if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === \"number\") {\n if (it) o = it;\n var i = 0;\n return function () {\n if (i >= o.length) return {\n done: true\n };\n return {\n done: false,\n value: o[i++]\n };\n };\n }\n throw new TypeError(\"Invalid attempt to iterate non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.\");\n }\n function _skipFirstGeneratorNext(fn) {\n return function () {\n var it = fn.apply(this, arguments);\n it.next();\n return it;\n };\n }\n function _toPrimitive(input, hint) {\n if (typeof input !== \"object\" || input === null) return input;\n var prim = input[Symbol.toPrimitive];\n if (prim !== undefined) {\n var res = prim.call(input, hint || \"default\");\n if (typeof res !== \"object\") return res;\n throw new TypeError(\"@@toPrimitive must return a primitive value.\");\n }\n return (hint === \"string\" ? String : Number)(input);\n }\n function _toPropertyKey(arg) {\n var key = _toPrimitive(arg, \"string\");\n return typeof key === \"symbol\" ? key : String(key);\n }\n function _initializerWarningHelper(descriptor, context) {\n throw new Error('Decorating class property failed. Please ensure that ' + 'transform-class-properties is enabled and runs after the decorators transform.');\n }\n function _initializerDefineProperty(target, property, descriptor, context) {\n if (!descriptor) return;\n Object.defineProperty(target, property, {\n enumerable: descriptor.enumerable,\n configurable: descriptor.configurable,\n writable: descriptor.writable,\n value: descriptor.initializer ? descriptor.initializer.call(context) : void 0\n });\n }\n function _applyDecoratedDescriptor(target, property, decorators, descriptor, context) {\n var desc = {};\n Object.keys(descriptor).forEach(function (key) {\n desc[key] = descriptor[key];\n });\n desc.enumerable = !!desc.enumerable;\n desc.configurable = !!desc.configurable;\n if ('value' in desc || desc.initializer) {\n desc.writable = true;\n }\n desc = decorators.slice().reverse().reduce(function (desc, decorator) {\n return decorator(target, property, desc) || desc;\n }, desc);\n if (context && desc.initializer !== void 0) {\n desc.value = desc.initializer ? desc.initializer.call(context) : void 0;\n desc.initializer = undefined;\n }\n if (desc.initializer === void 0) {\n Object.defineProperty(target, property, desc);\n desc = null;\n }\n return desc;\n }\n var id$1 = 0;\n function _classPrivateFieldLooseKey(name) {\n return \"__private_\" + id$1++ + \"_\" + name;\n }\n function _classPrivateFieldLooseBase(receiver, privateKey) {\n if (!Object.prototype.hasOwnProperty.call(receiver, privateKey)) {\n throw new TypeError(\"attempted to use private field on non-instance\");\n }\n return receiver;\n }\n function _classPrivateFieldGet(receiver, privateMap) {\n var descriptor = _classExtractFieldDescriptor(receiver, privateMap, \"get\");\n return _classApplyDescriptorGet(receiver, descriptor);\n }\n function _classPrivateFieldSet(receiver, privateMap, value) {\n var descriptor = _classExtractFieldDescriptor(receiver, privateMap, \"set\");\n _classApplyDescriptorSet(receiver, descriptor, value);\n return value;\n }\n function _classPrivateFieldDestructureSet(receiver, privateMap) {\n var descriptor = _classExtractFieldDescriptor(receiver, privateMap, \"set\");\n return _classApplyDescriptorDestructureSet(receiver, descriptor);\n }\n function _classExtractFieldDescriptor(receiver, privateMap, action) {\n if (!privateMap.has(receiver)) {\n throw new TypeError(\"attempted to \" + action + \" private field on non-instance\");\n }\n return privateMap.get(receiver);\n }\n function _classStaticPrivateFieldSpecGet(receiver, classConstructor, descriptor) {\n _classCheckPrivateStaticAccess(receiver, classConstructor);\n _classCheckPrivateStaticFieldDescriptor(descriptor, \"get\");\n return _classApplyDescriptorGet(receiver, descriptor);\n }\n function _classStaticPrivateFieldSpecSet(receiver, classConstructor, descriptor, value) {\n _classCheckPrivateStaticAccess(receiver, classConstructor);\n _classCheckPrivateStaticFieldDescriptor(descriptor, \"set\");\n _classApplyDescriptorSet(receiver, descriptor, value);\n return value;\n }\n function _classStaticPrivateMethodGet(receiver, classConstructor, method) {\n _classCheckPrivateStaticAccess(receiver, classConstructor);\n return method;\n }\n function _classStaticPrivateMethodSet() {\n throw new TypeError(\"attempted to set read only static private field\");\n }\n function _classApplyDescriptorGet(receiver, descriptor) {\n if (descriptor.get) {\n return descriptor.get.call(receiver);\n }\n return descriptor.value;\n }\n function _classApplyDescriptorSet(receiver, descriptor, value) {\n if (descriptor.set) {\n descriptor.set.call(receiver, value);\n } else {\n if (!descriptor.writable) {\n throw new TypeError(\"attempted to set read only private field\");\n }\n descriptor.value = value;\n }\n }\n function _classApplyDescriptorDestructureSet(receiver, descriptor) {\n if (descriptor.set) {\n if (!(\"__destrObj\" in descriptor)) {\n descriptor.__destrObj = {\n set value(v) {\n descriptor.set.call(receiver, v);\n }\n };\n }\n return descriptor.__destrObj;\n } else {\n if (!descriptor.writable) {\n throw new TypeError(\"attempted to set read only private field\");\n }\n return descriptor;\n }\n }\n function _classStaticPrivateFieldDestructureSet(receiver, classConstructor, descriptor) {\n _classCheckPrivateStaticAccess(receiver, classConstructor);\n _classCheckPrivateStaticFieldDescriptor(descriptor, \"set\");\n return _classApplyDescriptorDestructureSet(receiver, descriptor);\n }\n function _classCheckPrivateStaticAccess(receiver, classConstructor) {\n if (receiver !== classConstructor) {\n throw new TypeError(\"Private static access of wrong provenance\");\n }\n }\n function _classCheckPrivateStaticFieldDescriptor(descriptor, action) {\n if (descriptor === undefined) {\n throw new TypeError(\"attempted to \" + action + \" private static field before its declaration\");\n }\n }\n function _decorate(decorators, factory, superClass, mixins) {\n var api = _getDecoratorsApi();\n if (mixins) {\n for (var i = 0; i < mixins.length; i++) {\n api = mixins[i](api);\n }\n }\n var r = factory(function initialize(O) {\n api.initializeInstanceElements(O, decorated.elements);\n }, superClass);\n var decorated = api.decorateClass(_coalesceClassElements(r.d.map(_createElementDescriptor)), decorators);\n api.initializeClassElements(r.F, decorated.elements);\n return api.runClassFinishers(r.F, decorated.finishers);\n }\n function _getDecoratorsApi() {\n _getDecoratorsApi = function () {\n return api;\n };\n var api = {\n elementsDefinitionOrder: [[\"method\"], [\"field\"]],\n initializeInstanceElements: function (O, elements) {\n [\"method\", \"field\"].forEach(function (kind) {\n elements.forEach(function (element) {\n if (element.kind === kind && element.placement === \"own\") {\n this.defineClassElement(O, element);\n }\n }, this);\n }, this);\n },\n initializeClassElements: function (F, elements) {\n var proto = F.prototype;\n [\"method\", \"field\"].forEach(function (kind) {\n elements.forEach(function (element) {\n var placement = element.placement;\n if (element.kind === kind && (placement === \"static\" || placement === \"prototype\")) {\n var receiver = placement === \"static\" ? F : proto;\n this.defineClassElement(receiver, element);\n }\n }, this);\n }, this);\n },\n defineClassElement: function (receiver, element) {\n var descriptor = element.descriptor;\n if (element.kind === \"field\") {\n var initializer = element.initializer;\n descriptor = {\n enumerable: descriptor.enumerable,\n writable: descriptor.writable,\n configurable: descriptor.configurable,\n value: initializer === void 0 ? void 0 : initializer.call(receiver)\n };\n }\n Object.defineProperty(receiver, element.key, descriptor);\n },\n decorateClass: function (elements, decorators) {\n var newElements = [];\n var finishers = [];\n var placements = {\n static: [],\n prototype: [],\n own: []\n };\n elements.forEach(function (element) {\n this.addElementPlacement(element, placements);\n }, this);\n elements.forEach(function (element) {\n if (!_hasDecorators(element)) return newElements.push(element);\n var elementFinishersExtras = this.decorateElement(element, placements);\n newElements.push(elementFinishersExtras.element);\n newElements.push.apply(newElements, elementFinishersExtras.extras);\n finishers.push.apply(finishers, elementFinishersExtras.finishers);\n }, this);\n if (!decorators) {\n return {\n elements: newElements,\n finishers: finishers\n };\n }\n var result = this.decorateConstructor(newElements, decorators);\n finishers.push.apply(finishers, result.finishers);\n result.finishers = finishers;\n return result;\n },\n addElementPlacement: function (element, placements, silent) {\n var keys = placements[element.placement];\n if (!silent && keys.indexOf(element.key) !== -1) {\n throw new TypeError(\"Duplicated element (\" + element.key + \")\");\n }\n keys.push(element.key);\n },\n decorateElement: function (element, placements) {\n var extras = [];\n var finishers = [];\n for (var decorators = element.decorators, i = decorators.length - 1; i >= 0; i--) {\n var keys = placements[element.placement];\n keys.splice(keys.indexOf(element.key), 1);\n var elementObject = this.fromElementDescriptor(element);\n var elementFinisherExtras = this.toElementFinisherExtras((0, decorators[i])(elementObject) || elementObject);\n element = elementFinisherExtras.element;\n this.addElementPlacement(element, placements);\n if (elementFinisherExtras.finisher) {\n finishers.push(elementFinisherExtras.finisher);\n }\n var newExtras = elementFinisherExtras.extras;\n if (newExtras) {\n for (var j = 0; j < newExtras.length; j++) {\n this.addElementPlacement(newExtras[j], placements);\n }\n extras.push.apply(extras, newExtras);\n }\n }\n return {\n element: element,\n finishers: finishers,\n extras: extras\n };\n },\n decorateConstructor: function (elements, decorators) {\n var finishers = [];\n for (var i = decorators.length - 1; i >= 0; i--) {\n var obj = this.fromClassDescriptor(elements);\n var elementsAndFinisher = this.toClassDescriptor((0, decorators[i])(obj) || obj);\n if (elementsAndFinisher.finisher !== undefined) {\n finishers.push(elementsAndFinisher.finisher);\n }\n if (elementsAndFinisher.elements !== undefined) {\n elements = elementsAndFinisher.elements;\n for (var j = 0; j < elements.length - 1; j++) {\n for (var k = j + 1; k < elements.length; k++) {\n if (elements[j].key === elements[k].key && elements[j].placement === elements[k].placement) {\n throw new TypeError(\"Duplicated element (\" + elements[j].key + \")\");\n }\n }\n }\n }\n }\n return {\n elements: elements,\n finishers: finishers\n };\n },\n fromElementDescriptor: function (element) {\n var obj = {\n kind: element.kind,\n key: element.key,\n placement: element.placement,\n descriptor: element.descriptor\n };\n var desc = {\n value: \"Descriptor\",\n configurable: true\n };\n Object.defineProperty(obj, Symbol.toStringTag, desc);\n if (element.kind === \"field\") obj.initializer = element.initializer;\n return obj;\n },\n toElementDescriptors: function (elementObjects) {\n if (elementObjects === undefined) return;\n return _toArray(elementObjects).map(function (elementObject) {\n var element = this.toElementDescriptor(elementObject);\n this.disallowProperty(elementObject, \"finisher\", \"An element descriptor\");\n this.disallowProperty(elementObject, \"extras\", \"An element descriptor\");\n return element;\n }, this);\n },\n toElementDescriptor: function (elementObject) {\n var kind = String(elementObject.kind);\n if (kind !== \"method\" && kind !== \"field\") {\n throw new TypeError('An element descriptor\\'s .kind property must be either \"method\" or' + ' \"field\", but a decorator created an element descriptor with' + ' .kind \"' + kind + '\"');\n }\n var key = _toPropertyKey(elementObject.key);\n var placement = String(elementObject.placement);\n if (placement !== \"static\" && placement !== \"prototype\" && placement !== \"own\") {\n throw new TypeError('An element descriptor\\'s .placement property must be one of \"static\",' + ' \"prototype\" or \"own\", but a decorator created an element descriptor' + ' with .placement \"' + placement + '\"');\n }\n var descriptor = elementObject.descriptor;\n this.disallowProperty(elementObject, \"elements\", \"An element descriptor\");\n var element = {\n kind: kind,\n key: key,\n placement: placement,\n descriptor: Object.assign({}, descriptor)\n };\n if (kind !== \"field\") {\n this.disallowProperty(elementObject, \"initializer\", \"A method descriptor\");\n } else {\n this.disallowProperty(descriptor, \"get\", \"The property descriptor of a field descriptor\");\n this.disallowProperty(descriptor, \"set\", \"The property descriptor of a field descriptor\");\n this.disallowProperty(descriptor, \"value\", \"The property descriptor of a field descriptor\");\n element.initializer = elementObject.initializer;\n }\n return element;\n },\n toElementFinisherExtras: function (elementObject) {\n var element = this.toElementDescriptor(elementObject);\n var finisher = _optionalCallableProperty(elementObject, \"finisher\");\n var extras = this.toElementDescriptors(elementObject.extras);\n return {\n element: element,\n finisher: finisher,\n extras: extras\n };\n },\n fromClassDescriptor: function (elements) {\n var obj = {\n kind: \"class\",\n elements: elements.map(this.fromElementDescriptor, this)\n };\n var desc = {\n value: \"Descriptor\",\n configurable: true\n };\n Object.defineProperty(obj, Symbol.toStringTag, desc);\n return obj;\n },\n toClassDescriptor: function (obj) {\n var kind = String(obj.kind);\n if (kind !== \"class\") {\n throw new TypeError('A class descriptor\\'s .kind property must be \"class\", but a decorator' + ' created a class descriptor with .kind \"' + kind + '\"');\n }\n this.disallowProperty(obj, \"key\", \"A class descriptor\");\n this.disallowProperty(obj, \"placement\", \"A class descriptor\");\n this.disallowProperty(obj, \"descriptor\", \"A class descriptor\");\n this.disallowProperty(obj, \"initializer\", \"A class descriptor\");\n this.disallowProperty(obj, \"extras\", \"A class descriptor\");\n var finisher = _optionalCallableProperty(obj, \"finisher\");\n var elements = this.toElementDescriptors(obj.elements);\n return {\n elements: elements,\n finisher: finisher\n };\n },\n runClassFinishers: function (constructor, finishers) {\n for (var i = 0; i < finishers.length; i++) {\n var newConstructor = (0, finishers[i])(constructor);\n if (newConstructor !== undefined) {\n if (typeof newConstructor !== \"function\") {\n throw new TypeError(\"Finishers must return a constructor.\");\n }\n constructor = newConstructor;\n }\n }\n return constructor;\n },\n disallowProperty: function (obj, name, objectType) {\n if (obj[name] !== undefined) {\n throw new TypeError(objectType + \" can't have a .\" + name + \" property.\");\n }\n }\n };\n return api;\n }\n function _createElementDescriptor(def) {\n var key = _toPropertyKey(def.key);\n var descriptor;\n if (def.kind === \"method\") {\n descriptor = {\n value: def.value,\n writable: true,\n configurable: true,\n enumerable: false\n };\n } else if (def.kind === \"get\") {\n descriptor = {\n get: def.value,\n configurable: true,\n enumerable: false\n };\n } else if (def.kind === \"set\") {\n descriptor = {\n set: def.value,\n configurable: true,\n enumerable: false\n };\n } else if (def.kind === \"field\") {\n descriptor = {\n configurable: true,\n writable: true,\n enumerable: true\n };\n }\n var element = {\n kind: def.kind === \"field\" ? \"field\" : \"method\",\n key: key,\n placement: def.static ? \"static\" : def.kind === \"field\" ? \"own\" : \"prototype\",\n descriptor: descriptor\n };\n if (def.decorators) element.decorators = def.decorators;\n if (def.kind === \"field\") element.initializer = def.value;\n return element;\n }\n function _coalesceGetterSetter(element, other) {\n if (element.descriptor.get !== undefined) {\n other.descriptor.get = element.descriptor.get;\n } else {\n other.descriptor.set = element.descriptor.set;\n }\n }\n function _coalesceClassElements(elements) {\n var newElements = [];\n var isSameElement = function (other) {\n return other.kind === \"method\" && other.key === element.key && other.placement === element.placement;\n };\n for (var i = 0; i < elements.length; i++) {\n var element = elements[i];\n var other;\n if (element.kind === \"method\" && (other = newElements.find(isSameElement))) {\n if (_isDataDescriptor(element.descriptor) || _isDataDescriptor(other.descriptor)) {\n if (_hasDecorators(element) || _hasDecorators(other)) {\n throw new ReferenceError(\"Duplicated methods (\" + element.key + \") can't be decorated.\");\n }\n other.descriptor = element.descriptor;\n } else {\n if (_hasDecorators(element)) {\n if (_hasDecorators(other)) {\n throw new ReferenceError(\"Decorators can't be placed on different accessors with for \" + \"the same property (\" + element.key + \").\");\n }\n other.decorators = element.decorators;\n }\n _coalesceGetterSetter(element, other);\n }\n } else {\n newElements.push(element);\n }\n }\n return newElements;\n }\n function _hasDecorators(element) {\n return element.decorators && element.decorators.length;\n }\n function _isDataDescriptor(desc) {\n return desc !== undefined && !(desc.value === undefined && desc.writable === undefined);\n }\n function _optionalCallableProperty(obj, name) {\n var value = obj[name];\n if (value !== undefined && typeof value !== \"function\") {\n throw new TypeError(\"Expected '\" + name + \"' to be a function\");\n }\n return value;\n }\n function _classPrivateMethodGet(receiver, privateSet, fn) {\n if (!privateSet.has(receiver)) {\n throw new TypeError(\"attempted to get private field on non-instance\");\n }\n return fn;\n }\n function _checkPrivateRedeclaration(obj, privateCollection) {\n if (privateCollection.has(obj)) {\n throw new TypeError(\"Cannot initialize the same private elements twice on an object\");\n }\n }\n function _classPrivateFieldInitSpec(obj, privateMap, value) {\n _checkPrivateRedeclaration(obj, privateMap);\n privateMap.set(obj, value);\n }\n function _classPrivateMethodInitSpec(obj, privateSet) {\n _checkPrivateRedeclaration(obj, privateSet);\n privateSet.add(obj);\n }\n function _classPrivateMethodSet() {\n throw new TypeError(\"attempted to reassign private method\");\n }\n function _identity(x) {\n return x;\n }\n function _nullishReceiverError(r) {\n throw new TypeError(\"Cannot set property of null or undefined.\");\n }\n\n class Piece extends TrixObject {\n static registerType(type, constructor) {\n constructor.type = type;\n this.types[type] = constructor;\n }\n static fromJSON(pieceJSON) {\n const constructor = this.types[pieceJSON.type];\n if (constructor) {\n return constructor.fromJSON(pieceJSON);\n }\n }\n constructor(value) {\n let attributes = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};\n super(...arguments);\n this.attributes = Hash.box(attributes);\n }\n copyWithAttributes(attributes) {\n return new this.constructor(this.getValue(), attributes);\n }\n copyWithAdditionalAttributes(attributes) {\n return this.copyWithAttributes(this.attributes.merge(attributes));\n }\n copyWithoutAttribute(attribute) {\n return this.copyWithAttributes(this.attributes.remove(attribute));\n }\n copy() {\n return this.copyWithAttributes(this.attributes);\n }\n getAttribute(attribute) {\n return this.attributes.get(attribute);\n }\n getAttributesHash() {\n return this.attributes;\n }\n getAttributes() {\n return this.attributes.toObject();\n }\n hasAttribute(attribute) {\n return this.attributes.has(attribute);\n }\n hasSameStringValueAsPiece(piece) {\n return piece && this.toString() === piece.toString();\n }\n hasSameAttributesAsPiece(piece) {\n return piece && (this.attributes === piece.attributes || this.attributes.isEqualTo(piece.attributes));\n }\n isBlockBreak() {\n return false;\n }\n isEqualTo(piece) {\n return super.isEqualTo(...arguments) || this.hasSameConstructorAs(piece) && this.hasSameStringValueAsPiece(piece) && this.hasSameAttributesAsPiece(piece);\n }\n isEmpty() {\n return this.length === 0;\n }\n isSerializable() {\n return true;\n }\n toJSON() {\n return {\n type: this.constructor.type,\n attributes: this.getAttributes()\n };\n }\n contentsForInspection() {\n return {\n type: this.constructor.type,\n attributes: this.attributes.inspect()\n };\n }\n\n // Grouping\n\n canBeGrouped() {\n return this.hasAttribute(\"href\");\n }\n canBeGroupedWith(piece) {\n return this.getAttribute(\"href\") === piece.getAttribute(\"href\");\n }\n\n // Splittable\n\n getLength() {\n return this.length;\n }\n canBeConsolidatedWith(piece) {\n return false;\n }\n }\n _defineProperty(Piece, \"types\", {});\n\n class ImagePreloadOperation extends Operation {\n constructor(url) {\n super(...arguments);\n this.url = url;\n }\n perform(callback) {\n const image = new Image();\n image.onload = () => {\n image.width = this.width = image.naturalWidth;\n image.height = this.height = image.naturalHeight;\n return callback(true, image);\n };\n image.onerror = () => callback(false);\n image.src = this.url;\n }\n }\n\n class Attachment extends TrixObject {\n static attachmentForFile(file) {\n const attributes = this.attributesForFile(file);\n const attachment = new this(attributes);\n attachment.setFile(file);\n return attachment;\n }\n static attributesForFile(file) {\n return new Hash({\n filename: file.name,\n filesize: file.size,\n contentType: file.type\n });\n }\n static fromJSON(attachmentJSON) {\n return new this(attachmentJSON);\n }\n constructor() {\n let attributes = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};\n super(attributes);\n this.releaseFile = this.releaseFile.bind(this);\n this.attributes = Hash.box(attributes);\n this.didChangeAttributes();\n }\n getAttribute(attribute) {\n return this.attributes.get(attribute);\n }\n hasAttribute(attribute) {\n return this.attributes.has(attribute);\n }\n getAttributes() {\n return this.attributes.toObject();\n }\n setAttributes() {\n let attributes = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};\n const newAttributes = this.attributes.merge(attributes);\n if (!this.attributes.isEqualTo(newAttributes)) {\n var _this$previewDelegate, _this$previewDelegate2, _this$delegate, _this$delegate$attach;\n this.attributes = newAttributes;\n this.didChangeAttributes();\n (_this$previewDelegate = this.previewDelegate) === null || _this$previewDelegate === void 0 || (_this$previewDelegate2 = _this$previewDelegate.attachmentDidChangeAttributes) === null || _this$previewDelegate2 === void 0 || _this$previewDelegate2.call(_this$previewDelegate, this);\n return (_this$delegate = this.delegate) === null || _this$delegate === void 0 || (_this$delegate$attach = _this$delegate.attachmentDidChangeAttributes) === null || _this$delegate$attach === void 0 ? void 0 : _this$delegate$attach.call(_this$delegate, this);\n }\n }\n didChangeAttributes() {\n if (this.isPreviewable()) {\n return this.preloadURL();\n }\n }\n isPending() {\n return this.file != null && !(this.getURL() || this.getHref());\n }\n isPreviewable() {\n if (this.attributes.has(\"previewable\")) {\n return this.attributes.get(\"previewable\");\n } else {\n return Attachment.previewablePattern.test(this.getContentType());\n }\n }\n getType() {\n if (this.hasContent()) {\n return \"content\";\n } else if (this.isPreviewable()) {\n return \"preview\";\n } else {\n return \"file\";\n }\n }\n getURL() {\n return this.attributes.get(\"url\");\n }\n getHref() {\n return this.attributes.get(\"href\");\n }\n getFilename() {\n return this.attributes.get(\"filename\") || \"\";\n }\n getFilesize() {\n return this.attributes.get(\"filesize\");\n }\n getFormattedFilesize() {\n const filesize = this.attributes.get(\"filesize\");\n if (typeof filesize === \"number\") {\n return file_size_formatting.formatter(filesize);\n } else {\n return \"\";\n }\n }\n getExtension() {\n var _this$getFilename$mat;\n return (_this$getFilename$mat = this.getFilename().match(/\\.(\\w+)$/)) === null || _this$getFilename$mat === void 0 ? void 0 : _this$getFilename$mat[1].toLowerCase();\n }\n getContentType() {\n return this.attributes.get(\"contentType\");\n }\n hasContent() {\n return this.attributes.has(\"content\");\n }\n getContent() {\n return this.attributes.get(\"content\");\n }\n getWidth() {\n return this.attributes.get(\"width\");\n }\n getHeight() {\n return this.attributes.get(\"height\");\n }\n getFile() {\n return this.file;\n }\n setFile(file) {\n this.file = file;\n if (this.isPreviewable()) {\n return this.preloadFile();\n }\n }\n releaseFile() {\n this.releasePreloadedFile();\n this.file = null;\n }\n getUploadProgress() {\n return this.uploadProgress != null ? this.uploadProgress : 0;\n }\n setUploadProgress(value) {\n if (this.uploadProgress !== value) {\n var _this$uploadProgressD, _this$uploadProgressD2;\n this.uploadProgress = value;\n return (_this$uploadProgressD = this.uploadProgressDelegate) === null || _this$uploadProgressD === void 0 || (_this$uploadProgressD2 = _this$uploadProgressD.attachmentDidChangeUploadProgress) === null || _this$uploadProgressD2 === void 0 ? void 0 : _this$uploadProgressD2.call(_this$uploadProgressD, this);\n }\n }\n toJSON() {\n return this.getAttributes();\n }\n getCacheKey() {\n return [super.getCacheKey(...arguments), this.attributes.getCacheKey(), this.getPreviewURL()].join(\"/\");\n }\n\n // Previewable\n\n getPreviewURL() {\n return this.previewURL || this.preloadingURL;\n }\n setPreviewURL(url) {\n if (url !== this.getPreviewURL()) {\n var _this$previewDelegate3, _this$previewDelegate4, _this$delegate2, _this$delegate2$attac;\n this.previewURL = url;\n (_this$previewDelegate3 = this.previewDelegate) === null || _this$previewDelegate3 === void 0 || (_this$previewDelegate4 = _this$previewDelegate3.attachmentDidChangeAttributes) === null || _this$previewDelegate4 === void 0 || _this$previewDelegate4.call(_this$previewDelegate3, this);\n return (_this$delegate2 = this.delegate) === null || _this$delegate2 === void 0 || (_this$delegate2$attac = _this$delegate2.attachmentDidChangePreviewURL) === null || _this$delegate2$attac === void 0 ? void 0 : _this$delegate2$attac.call(_this$delegate2, this);\n }\n }\n preloadURL() {\n return this.preload(this.getURL(), this.releaseFile);\n }\n preloadFile() {\n if (this.file) {\n this.fileObjectURL = URL.createObjectURL(this.file);\n return this.preload(this.fileObjectURL);\n }\n }\n releasePreloadedFile() {\n if (this.fileObjectURL) {\n URL.revokeObjectURL(this.fileObjectURL);\n this.fileObjectURL = null;\n }\n }\n preload(url, callback) {\n if (url && url !== this.getPreviewURL()) {\n this.preloadingURL = url;\n const operation = new ImagePreloadOperation(url);\n return operation.then(_ref => {\n let {\n width,\n height\n } = _ref;\n if (!this.getWidth() || !this.getHeight()) {\n this.setAttributes({\n width,\n height\n });\n }\n this.preloadingURL = null;\n this.setPreviewURL(url);\n return callback === null || callback === void 0 ? void 0 : callback();\n }).catch(() => {\n this.preloadingURL = null;\n return callback === null || callback === void 0 ? void 0 : callback();\n });\n }\n }\n }\n _defineProperty(Attachment, \"previewablePattern\", /^image(\\/(gif|png|webp|jpe?g)|$)/);\n\n class AttachmentPiece extends Piece {\n static fromJSON(pieceJSON) {\n return new this(Attachment.fromJSON(pieceJSON.attachment), pieceJSON.attributes);\n }\n constructor(attachment) {\n super(...arguments);\n this.attachment = attachment;\n this.length = 1;\n this.ensureAttachmentExclusivelyHasAttribute(\"href\");\n if (!this.attachment.hasContent()) {\n this.removeProhibitedAttributes();\n }\n }\n ensureAttachmentExclusivelyHasAttribute(attribute) {\n if (this.hasAttribute(attribute)) {\n if (!this.attachment.hasAttribute(attribute)) {\n this.attachment.setAttributes(this.attributes.slice([attribute]));\n }\n this.attributes = this.attributes.remove(attribute);\n }\n }\n removeProhibitedAttributes() {\n const attributes = this.attributes.slice(AttachmentPiece.permittedAttributes);\n if (!attributes.isEqualTo(this.attributes)) {\n this.attributes = attributes;\n }\n }\n getValue() {\n return this.attachment;\n }\n isSerializable() {\n return !this.attachment.isPending();\n }\n getCaption() {\n return this.attributes.get(\"caption\") || \"\";\n }\n isEqualTo(piece) {\n var _piece$attachment;\n return super.isEqualTo(piece) && this.attachment.id === (piece === null || piece === void 0 || (_piece$attachment = piece.attachment) === null || _piece$attachment === void 0 ? void 0 : _piece$attachment.id);\n }\n toString() {\n return OBJECT_REPLACEMENT_CHARACTER;\n }\n toJSON() {\n const json = super.toJSON(...arguments);\n json.attachment = this.attachment;\n return json;\n }\n getCacheKey() {\n return [super.getCacheKey(...arguments), this.attachment.getCacheKey()].join(\"/\");\n }\n toConsole() {\n return JSON.stringify(this.toString());\n }\n }\n _defineProperty(AttachmentPiece, \"permittedAttributes\", [\"caption\", \"presentation\"]);\n Piece.registerType(\"attachment\", AttachmentPiece);\n\n class StringPiece extends Piece {\n static fromJSON(pieceJSON) {\n return new this(pieceJSON.string, pieceJSON.attributes);\n }\n constructor(string) {\n super(...arguments);\n this.string = normalizeNewlines(string);\n this.length = this.string.length;\n }\n getValue() {\n return this.string;\n }\n toString() {\n return this.string.toString();\n }\n isBlockBreak() {\n return this.toString() === \"\\n\" && this.getAttribute(\"blockBreak\") === true;\n }\n toJSON() {\n const result = super.toJSON(...arguments);\n result.string = this.string;\n return result;\n }\n\n // Splittable\n\n canBeConsolidatedWith(piece) {\n return piece && this.hasSameConstructorAs(piece) && this.hasSameAttributesAsPiece(piece);\n }\n consolidateWith(piece) {\n return new this.constructor(this.toString() + piece.toString(), this.attributes);\n }\n splitAtOffset(offset) {\n let left, right;\n if (offset === 0) {\n left = null;\n right = this;\n } else if (offset === this.length) {\n left = this;\n right = null;\n } else {\n left = new this.constructor(this.string.slice(0, offset), this.attributes);\n right = new this.constructor(this.string.slice(offset), this.attributes);\n }\n return [left, right];\n }\n toConsole() {\n let {\n string\n } = this;\n if (string.length > 15) {\n string = string.slice(0, 14) + \"\u2026\";\n }\n return JSON.stringify(string.toString());\n }\n }\n Piece.registerType(\"string\", StringPiece);\n\n /* eslint-disable\n prefer-const,\n */\n class SplittableList extends TrixObject {\n static box(objects) {\n if (objects instanceof this) {\n return objects;\n } else {\n return new this(objects);\n }\n }\n constructor() {\n let objects = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];\n super(...arguments);\n this.objects = objects.slice(0);\n this.length = this.objects.length;\n }\n indexOf(object) {\n return this.objects.indexOf(object);\n }\n splice() {\n for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {\n args[_key] = arguments[_key];\n }\n return new this.constructor(spliceArray(this.objects, ...args));\n }\n eachObject(callback) {\n return this.objects.map((object, index) => callback(object, index));\n }\n insertObjectAtIndex(object, index) {\n return this.splice(index, 0, object);\n }\n insertSplittableListAtIndex(splittableList, index) {\n return this.splice(index, 0, ...splittableList.objects);\n }\n insertSplittableListAtPosition(splittableList, position) {\n const [objects, index] = this.splitObjectAtPosition(position);\n return new this.constructor(objects).insertSplittableListAtIndex(splittableList, index);\n }\n editObjectAtIndex(index, callback) {\n return this.replaceObjectAtIndex(callback(this.objects[index]), index);\n }\n replaceObjectAtIndex(object, index) {\n return this.splice(index, 1, object);\n }\n removeObjectAtIndex(index) {\n return this.splice(index, 1);\n }\n getObjectAtIndex(index) {\n return this.objects[index];\n }\n getSplittableListInRange(range) {\n const [objects, leftIndex, rightIndex] = this.splitObjectsAtRange(range);\n return new this.constructor(objects.slice(leftIndex, rightIndex + 1));\n }\n selectSplittableList(test) {\n const objects = this.objects.filter(object => test(object));\n return new this.constructor(objects);\n }\n removeObjectsInRange(range) {\n const [objects, leftIndex, rightIndex] = this.splitObjectsAtRange(range);\n return new this.constructor(objects).splice(leftIndex, rightIndex - leftIndex + 1);\n }\n transformObjectsInRange(range, transform) {\n const [objects, leftIndex, rightIndex] = this.splitObjectsAtRange(range);\n const transformedObjects = objects.map((object, index) => leftIndex <= index && index <= rightIndex ? transform(object) : object);\n return new this.constructor(transformedObjects);\n }\n splitObjectsAtRange(range) {\n let rightOuterIndex;\n let [objects, leftInnerIndex, offset] = this.splitObjectAtPosition(startOfRange(range));\n [objects, rightOuterIndex] = new this.constructor(objects).splitObjectAtPosition(endOfRange(range) + offset);\n return [objects, leftInnerIndex, rightOuterIndex - 1];\n }\n getObjectAtPosition(position) {\n const {\n index\n } = this.findIndexAndOffsetAtPosition(position);\n return this.objects[index];\n }\n splitObjectAtPosition(position) {\n let splitIndex, splitOffset;\n const {\n index,\n offset\n } = this.findIndexAndOffsetAtPosition(position);\n const objects = this.objects.slice(0);\n if (index != null) {\n if (offset === 0) {\n splitIndex = index;\n splitOffset = 0;\n } else {\n const object = this.getObjectAtIndex(index);\n const [leftObject, rightObject] = object.splitAtOffset(offset);\n objects.splice(index, 1, leftObject, rightObject);\n splitIndex = index + 1;\n splitOffset = leftObject.getLength() - offset;\n }\n } else {\n splitIndex = objects.length;\n splitOffset = 0;\n }\n return [objects, splitIndex, splitOffset];\n }\n consolidate() {\n const objects = [];\n let pendingObject = this.objects[0];\n this.objects.slice(1).forEach(object => {\n var _pendingObject$canBeC, _pendingObject;\n if ((_pendingObject$canBeC = (_pendingObject = pendingObject).canBeConsolidatedWith) !== null && _pendingObject$canBeC !== void 0 && _pendingObject$canBeC.call(_pendingObject, object)) {\n pendingObject = pendingObject.consolidateWith(object);\n } else {\n objects.push(pendingObject);\n pendingObject = object;\n }\n });\n if (pendingObject) {\n objects.push(pendingObject);\n }\n return new this.constructor(objects);\n }\n consolidateFromIndexToIndex(startIndex, endIndex) {\n const objects = this.objects.slice(0);\n const objectsInRange = objects.slice(startIndex, endIndex + 1);\n const consolidatedInRange = new this.constructor(objectsInRange).consolidate().toArray();\n return this.splice(startIndex, objectsInRange.length, ...consolidatedInRange);\n }\n findIndexAndOffsetAtPosition(position) {\n let index;\n let currentPosition = 0;\n for (index = 0; index < this.objects.length; index++) {\n const object = this.objects[index];\n const nextPosition = currentPosition + object.getLength();\n if (currentPosition <= position && position < nextPosition) {\n return {\n index,\n offset: position - currentPosition\n };\n }\n currentPosition = nextPosition;\n }\n return {\n index: null,\n offset: null\n };\n }\n findPositionAtIndexAndOffset(index, offset) {\n let position = 0;\n for (let currentIndex = 0; currentIndex < this.objects.length; currentIndex++) {\n const object = this.objects[currentIndex];\n if (currentIndex < index) {\n position += object.getLength();\n } else if (currentIndex === index) {\n position += offset;\n break;\n }\n }\n return position;\n }\n getEndPosition() {\n if (this.endPosition == null) {\n this.endPosition = 0;\n this.objects.forEach(object => this.endPosition += object.getLength());\n }\n return this.endPosition;\n }\n toString() {\n return this.objects.join(\"\");\n }\n toArray() {\n return this.objects.slice(0);\n }\n toJSON() {\n return this.toArray();\n }\n isEqualTo(splittableList) {\n return super.isEqualTo(...arguments) || objectArraysAreEqual(this.objects, splittableList === null || splittableList === void 0 ? void 0 : splittableList.objects);\n }\n contentsForInspection() {\n return {\n objects: \"[\".concat(this.objects.map(object => object.inspect()).join(\", \"), \"]\")\n };\n }\n }\n const objectArraysAreEqual = function (left) {\n let right = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];\n if (left.length !== right.length) {\n return false;\n }\n let result = true;\n for (let index = 0; index < left.length; index++) {\n const object = left[index];\n if (result && !object.isEqualTo(right[index])) {\n result = false;\n }\n }\n return result;\n };\n const startOfRange = range => range[0];\n const endOfRange = range => range[1];\n\n class Text extends TrixObject {\n static textForAttachmentWithAttributes(attachment, attributes) {\n const piece = new AttachmentPiece(attachment, attributes);\n return new this([piece]);\n }\n static textForStringWithAttributes(string, attributes) {\n const piece = new StringPiece(string, attributes);\n return new this([piece]);\n }\n static fromJSON(textJSON) {\n const pieces = Array.from(textJSON).map(pieceJSON => Piece.fromJSON(pieceJSON));\n return new this(pieces);\n }\n constructor() {\n let pieces = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];\n super(...arguments);\n const notEmpty = pieces.filter(piece => !piece.isEmpty());\n this.pieceList = new SplittableList(notEmpty);\n }\n copy() {\n return this.copyWithPieceList(this.pieceList);\n }\n copyWithPieceList(pieceList) {\n return new this.constructor(pieceList.consolidate().toArray());\n }\n copyUsingObjectMap(objectMap) {\n const pieces = this.getPieces().map(piece => objectMap.find(piece) || piece);\n return new this.constructor(pieces);\n }\n appendText(text) {\n return this.insertTextAtPosition(text, this.getLength());\n }\n insertTextAtPosition(text, position) {\n return this.copyWithPieceList(this.pieceList.insertSplittableListAtPosition(text.pieceList, position));\n }\n removeTextAtRange(range) {\n return this.copyWithPieceList(this.pieceList.removeObjectsInRange(range));\n }\n replaceTextAtRange(text, range) {\n return this.removeTextAtRange(range).insertTextAtPosition(text, range[0]);\n }\n moveTextFromRangeToPosition(range, position) {\n if (range[0] <= position && position <= range[1]) return;\n const text = this.getTextAtRange(range);\n const length = text.getLength();\n if (range[0] < position) {\n position -= length;\n }\n return this.removeTextAtRange(range).insertTextAtPosition(text, position);\n }\n addAttributeAtRange(attribute, value, range) {\n const attributes = {};\n attributes[attribute] = value;\n return this.addAttributesAtRange(attributes, range);\n }\n addAttributesAtRange(attributes, range) {\n return this.copyWithPieceList(this.pieceList.transformObjectsInRange(range, piece => piece.copyWithAdditionalAttributes(attributes)));\n }\n removeAttributeAtRange(attribute, range) {\n return this.copyWithPieceList(this.pieceList.transformObjectsInRange(range, piece => piece.copyWithoutAttribute(attribute)));\n }\n setAttributesAtRange(attributes, range) {\n return this.copyWithPieceList(this.pieceList.transformObjectsInRange(range, piece => piece.copyWithAttributes(attributes)));\n }\n getAttributesAtPosition(position) {\n var _this$pieceList$getOb;\n return ((_this$pieceList$getOb = this.pieceList.getObjectAtPosition(position)) === null || _this$pieceList$getOb === void 0 ? void 0 : _this$pieceList$getOb.getAttributes()) || {};\n }\n getCommonAttributes() {\n const objects = Array.from(this.pieceList.toArray()).map(piece => piece.getAttributes());\n return Hash.fromCommonAttributesOfObjects(objects).toObject();\n }\n getCommonAttributesAtRange(range) {\n return this.getTextAtRange(range).getCommonAttributes() || {};\n }\n getExpandedRangeForAttributeAtOffset(attributeName, offset) {\n let right;\n let left = right = offset;\n const length = this.getLength();\n while (left > 0 && this.getCommonAttributesAtRange([left - 1, right])[attributeName]) {\n left--;\n }\n while (right < length && this.getCommonAttributesAtRange([offset, right + 1])[attributeName]) {\n right++;\n }\n return [left, right];\n }\n getTextAtRange(range) {\n return this.copyWithPieceList(this.pieceList.getSplittableListInRange(range));\n }\n getStringAtRange(range) {\n return this.pieceList.getSplittableListInRange(range).toString();\n }\n getStringAtPosition(position) {\n return this.getStringAtRange([position, position + 1]);\n }\n startsWithString(string) {\n return this.getStringAtRange([0, string.length]) === string;\n }\n endsWithString(string) {\n const length = this.getLength();\n return this.getStringAtRange([length - string.length, length]) === string;\n }\n getAttachmentPieces() {\n return this.pieceList.toArray().filter(piece => !!piece.attachment);\n }\n getAttachments() {\n return this.getAttachmentPieces().map(piece => piece.attachment);\n }\n getAttachmentAndPositionById(attachmentId) {\n let position = 0;\n for (const piece of this.pieceList.toArray()) {\n var _piece$attachment;\n if (((_piece$attachment = piece.attachment) === null || _piece$attachment === void 0 ? void 0 : _piece$attachment.id) === attachmentId) {\n return {\n attachment: piece.attachment,\n position\n };\n }\n position += piece.length;\n }\n return {\n attachment: null,\n position: null\n };\n }\n getAttachmentById(attachmentId) {\n const {\n attachment\n } = this.getAttachmentAndPositionById(attachmentId);\n return attachment;\n }\n getRangeOfAttachment(attachment) {\n const attachmentAndPosition = this.getAttachmentAndPositionById(attachment.id);\n const position = attachmentAndPosition.position;\n attachment = attachmentAndPosition.attachment;\n if (attachment) {\n return [position, position + 1];\n }\n }\n updateAttributesForAttachment(attributes, attachment) {\n const range = this.getRangeOfAttachment(attachment);\n if (range) {\n return this.addAttributesAtRange(attributes, range);\n } else {\n return this;\n }\n }\n getLength() {\n return this.pieceList.getEndPosition();\n }\n isEmpty() {\n return this.getLength() === 0;\n }\n isEqualTo(text) {\n var _text$pieceList;\n return super.isEqualTo(text) || (text === null || text === void 0 || (_text$pieceList = text.pieceList) === null || _text$pieceList === void 0 ? void 0 : _text$pieceList.isEqualTo(this.pieceList));\n }\n isBlockBreak() {\n return this.getLength() === 1 && this.pieceList.getObjectAtIndex(0).isBlockBreak();\n }\n eachPiece(callback) {\n return this.pieceList.eachObject(callback);\n }\n getPieces() {\n return this.pieceList.toArray();\n }\n getPieceAtPosition(position) {\n return this.pieceList.getObjectAtPosition(position);\n }\n contentsForInspection() {\n return {\n pieceList: this.pieceList.inspect()\n };\n }\n toSerializableText() {\n const pieceList = this.pieceList.selectSplittableList(piece => piece.isSerializable());\n return this.copyWithPieceList(pieceList);\n }\n toString() {\n return this.pieceList.toString();\n }\n toJSON() {\n return this.pieceList.toJSON();\n }\n toConsole() {\n return JSON.stringify(this.pieceList.toArray().map(piece => JSON.parse(piece.toConsole())));\n }\n\n // BIDI\n\n getDirection() {\n return getDirection(this.toString());\n }\n isRTL() {\n return this.getDirection() === \"rtl\";\n }\n }\n\n class Block extends TrixObject {\n static fromJSON(blockJSON) {\n const text = Text.fromJSON(blockJSON.text);\n return new this(text, blockJSON.attributes, blockJSON.htmlAttributes);\n }\n constructor(text, attributes, htmlAttributes) {\n super(...arguments);\n this.text = applyBlockBreakToText(text || new Text());\n this.attributes = attributes || [];\n this.htmlAttributes = htmlAttributes || {};\n }\n isEmpty() {\n return this.text.isBlockBreak();\n }\n isEqualTo(block) {\n if (super.isEqualTo(block)) return true;\n return this.text.isEqualTo(block === null || block === void 0 ? void 0 : block.text) && arraysAreEqual(this.attributes, block === null || block === void 0 ? void 0 : block.attributes) && objectsAreEqual(this.htmlAttributes, block === null || block === void 0 ? void 0 : block.htmlAttributes);\n }\n copyWithText(text) {\n return new Block(text, this.attributes, this.htmlAttributes);\n }\n copyWithoutText() {\n return this.copyWithText(null);\n }\n copyWithAttributes(attributes) {\n return new Block(this.text, attributes, this.htmlAttributes);\n }\n copyWithoutAttributes() {\n return this.copyWithAttributes(null);\n }\n copyUsingObjectMap(objectMap) {\n const mappedText = objectMap.find(this.text);\n if (mappedText) {\n return this.copyWithText(mappedText);\n } else {\n return this.copyWithText(this.text.copyUsingObjectMap(objectMap));\n }\n }\n addAttribute(attribute) {\n const attributes = this.attributes.concat(expandAttribute(attribute));\n return this.copyWithAttributes(attributes);\n }\n addHTMLAttribute(attribute, value) {\n const htmlAttributes = Object.assign({}, this.htmlAttributes, {\n [attribute]: value\n });\n return new Block(this.text, this.attributes, htmlAttributes);\n }\n removeAttribute(attribute) {\n const {\n listAttribute\n } = getBlockConfig(attribute);\n const attributes = removeLastValue(removeLastValue(this.attributes, attribute), listAttribute);\n return this.copyWithAttributes(attributes);\n }\n removeLastAttribute() {\n return this.removeAttribute(this.getLastAttribute());\n }\n getLastAttribute() {\n return getLastElement(this.attributes);\n }\n getAttributes() {\n return this.attributes.slice(0);\n }\n getAttributeLevel() {\n return this.attributes.length;\n }\n getAttributeAtLevel(level) {\n return this.attributes[level - 1];\n }\n hasAttribute(attributeName) {\n return this.attributes.includes(attributeName);\n }\n hasAttributes() {\n return this.getAttributeLevel() > 0;\n }\n getLastNestableAttribute() {\n return getLastElement(this.getNestableAttributes());\n }\n getNestableAttributes() {\n return this.attributes.filter(attribute => getBlockConfig(attribute).nestable);\n }\n getNestingLevel() {\n return this.getNestableAttributes().length;\n }\n decreaseNestingLevel() {\n const attribute = this.getLastNestableAttribute();\n if (attribute) {\n return this.removeAttribute(attribute);\n } else {\n return this;\n }\n }\n increaseNestingLevel() {\n const attribute = this.getLastNestableAttribute();\n if (attribute) {\n const index = this.attributes.lastIndexOf(attribute);\n const attributes = spliceArray(this.attributes, index + 1, 0, ...expandAttribute(attribute));\n return this.copyWithAttributes(attributes);\n } else {\n return this;\n }\n }\n getListItemAttributes() {\n return this.attributes.filter(attribute => getBlockConfig(attribute).listAttribute);\n }\n isListItem() {\n var _getBlockConfig;\n return (_getBlockConfig = getBlockConfig(this.getLastAttribute())) === null || _getBlockConfig === void 0 ? void 0 : _getBlockConfig.listAttribute;\n }\n isTerminalBlock() {\n var _getBlockConfig2;\n return (_getBlockConfig2 = getBlockConfig(this.getLastAttribute())) === null || _getBlockConfig2 === void 0 ? void 0 : _getBlockConfig2.terminal;\n }\n breaksOnReturn() {\n var _getBlockConfig3;\n return (_getBlockConfig3 = getBlockConfig(this.getLastAttribute())) === null || _getBlockConfig3 === void 0 ? void 0 : _getBlockConfig3.breakOnReturn;\n }\n findLineBreakInDirectionFromPosition(direction, position) {\n const string = this.toString();\n let result;\n switch (direction) {\n case \"forward\":\n result = string.indexOf(\"\\n\", position);\n break;\n case \"backward\":\n result = string.slice(0, position).lastIndexOf(\"\\n\");\n }\n if (result !== -1) {\n return result;\n }\n }\n contentsForInspection() {\n return {\n text: this.text.inspect(),\n attributes: this.attributes\n };\n }\n toString() {\n return this.text.toString();\n }\n toJSON() {\n return {\n text: this.text,\n attributes: this.attributes,\n htmlAttributes: this.htmlAttributes\n };\n }\n\n // BIDI\n\n getDirection() {\n return this.text.getDirection();\n }\n isRTL() {\n return this.text.isRTL();\n }\n\n // Splittable\n\n getLength() {\n return this.text.getLength();\n }\n canBeConsolidatedWith(block) {\n return !this.hasAttributes() && !block.hasAttributes() && this.getDirection() === block.getDirection();\n }\n consolidateWith(block) {\n const newlineText = Text.textForStringWithAttributes(\"\\n\");\n const text = this.getTextWithoutBlockBreak().appendText(newlineText);\n return this.copyWithText(text.appendText(block.text));\n }\n splitAtOffset(offset) {\n let left, right;\n if (offset === 0) {\n left = null;\n right = this;\n } else if (offset === this.getLength()) {\n left = this;\n right = null;\n } else {\n left = this.copyWithText(this.text.getTextAtRange([0, offset]));\n right = this.copyWithText(this.text.getTextAtRange([offset, this.getLength()]));\n }\n return [left, right];\n }\n getBlockBreakPosition() {\n return this.text.getLength() - 1;\n }\n getTextWithoutBlockBreak() {\n if (textEndsInBlockBreak(this.text)) {\n return this.text.getTextAtRange([0, this.getBlockBreakPosition()]);\n } else {\n return this.text.copy();\n }\n }\n\n // Grouping\n\n canBeGrouped(depth) {\n return this.attributes[depth];\n }\n canBeGroupedWith(otherBlock, depth) {\n const otherAttributes = otherBlock.getAttributes();\n const otherAttribute = otherAttributes[depth];\n const attribute = this.attributes[depth];\n return attribute === otherAttribute && !(getBlockConfig(attribute).group === false && !getListAttributeNames().includes(otherAttributes[depth + 1])) && (this.getDirection() === otherBlock.getDirection() || otherBlock.isEmpty());\n }\n }\n\n // Block breaks\n\n const applyBlockBreakToText = function (text) {\n text = unmarkExistingInnerBlockBreaksInText(text);\n text = addBlockBreakToText(text);\n return text;\n };\n const unmarkExistingInnerBlockBreaksInText = function (text) {\n let modified = false;\n const pieces = text.getPieces();\n let innerPieces = pieces.slice(0, pieces.length - 1);\n const lastPiece = pieces[pieces.length - 1];\n if (!lastPiece) return text;\n innerPieces = innerPieces.map(piece => {\n if (piece.isBlockBreak()) {\n modified = true;\n return unmarkBlockBreakPiece(piece);\n } else {\n return piece;\n }\n });\n if (modified) {\n return new Text([...innerPieces, lastPiece]);\n } else {\n return text;\n }\n };\n const blockBreakText = Text.textForStringWithAttributes(\"\\n\", {\n blockBreak: true\n });\n const addBlockBreakToText = function (text) {\n if (textEndsInBlockBreak(text)) {\n return text;\n } else {\n return text.appendText(blockBreakText);\n }\n };\n const textEndsInBlockBreak = function (text) {\n const length = text.getLength();\n if (length === 0) {\n return false;\n }\n const endText = text.getTextAtRange([length - 1, length]);\n return endText.isBlockBreak();\n };\n const unmarkBlockBreakPiece = piece => piece.copyWithoutAttribute(\"blockBreak\");\n\n // Attributes\n\n const expandAttribute = function (attribute) {\n const {\n listAttribute\n } = getBlockConfig(attribute);\n if (listAttribute) {\n return [listAttribute, attribute];\n } else {\n return [attribute];\n }\n };\n\n // Array helpers\n\n const getLastElement = array => array.slice(-1)[0];\n const removeLastValue = function (array, value) {\n const index = array.lastIndexOf(value);\n if (index === -1) {\n return array;\n } else {\n return spliceArray(array, index, 1);\n }\n };\n\n class Document extends TrixObject {\n static fromJSON(documentJSON) {\n const blocks = Array.from(documentJSON).map(blockJSON => Block.fromJSON(blockJSON));\n return new this(blocks);\n }\n static fromString(string, textAttributes) {\n const text = Text.textForStringWithAttributes(string, textAttributes);\n return new this([new Block(text)]);\n }\n constructor() {\n let blocks = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];\n super(...arguments);\n if (blocks.length === 0) {\n blocks = [new Block()];\n }\n this.blockList = SplittableList.box(blocks);\n }\n isEmpty() {\n const block = this.getBlockAtIndex(0);\n return this.blockList.length === 1 && block.isEmpty() && !block.hasAttributes();\n }\n copy() {\n let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};\n const blocks = options.consolidateBlocks ? this.blockList.consolidate().toArray() : this.blockList.toArray();\n return new this.constructor(blocks);\n }\n copyUsingObjectsFromDocument(sourceDocument) {\n const objectMap = new ObjectMap(sourceDocument.getObjects());\n return this.copyUsingObjectMap(objectMap);\n }\n copyUsingObjectMap(objectMap) {\n const blocks = this.getBlocks().map(block => {\n const mappedBlock = objectMap.find(block);\n return mappedBlock || block.copyUsingObjectMap(objectMap);\n });\n return new this.constructor(blocks);\n }\n copyWithBaseBlockAttributes() {\n let blockAttributes = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];\n const blocks = this.getBlocks().map(block => {\n const attributes = blockAttributes.concat(block.getAttributes());\n return block.copyWithAttributes(attributes);\n });\n return new this.constructor(blocks);\n }\n replaceBlock(oldBlock, newBlock) {\n const index = this.blockList.indexOf(oldBlock);\n if (index === -1) {\n return this;\n }\n return new this.constructor(this.blockList.replaceObjectAtIndex(newBlock, index));\n }\n insertDocumentAtRange(document, range) {\n const {\n blockList\n } = document;\n range = normalizeRange(range);\n let [position] = range;\n const {\n index,\n offset\n } = this.locationFromPosition(position);\n let result = this;\n const block = this.getBlockAtPosition(position);\n if (rangeIsCollapsed(range) && block.isEmpty() && !block.hasAttributes()) {\n result = new this.constructor(result.blockList.removeObjectAtIndex(index));\n } else if (block.getBlockBreakPosition() === offset) {\n position++;\n }\n result = result.removeTextAtRange(range);\n return new this.constructor(result.blockList.insertSplittableListAtPosition(blockList, position));\n }\n mergeDocumentAtRange(document, range) {\n let formattedDocument, result;\n range = normalizeRange(range);\n const [startPosition] = range;\n const startLocation = this.locationFromPosition(startPosition);\n const blockAttributes = this.getBlockAtIndex(startLocation.index).getAttributes();\n const baseBlockAttributes = document.getBaseBlockAttributes();\n const trailingBlockAttributes = blockAttributes.slice(-baseBlockAttributes.length);\n if (arraysAreEqual(baseBlockAttributes, trailingBlockAttributes)) {\n const leadingBlockAttributes = blockAttributes.slice(0, -baseBlockAttributes.length);\n formattedDocument = document.copyWithBaseBlockAttributes(leadingBlockAttributes);\n } else {\n formattedDocument = document.copy({\n consolidateBlocks: true\n }).copyWithBaseBlockAttributes(blockAttributes);\n }\n const blockCount = formattedDocument.getBlockCount();\n const firstBlock = formattedDocument.getBlockAtIndex(0);\n if (arraysAreEqual(blockAttributes, firstBlock.getAttributes())) {\n const firstText = firstBlock.getTextWithoutBlockBreak();\n result = this.insertTextAtRange(firstText, range);\n if (blockCount > 1) {\n formattedDocument = new this.constructor(formattedDocument.getBlocks().slice(1));\n const position = startPosition + firstText.getLength();\n result = result.insertDocumentAtRange(formattedDocument, position);\n }\n } else {\n result = this.insertDocumentAtRange(formattedDocument, range);\n }\n return result;\n }\n insertTextAtRange(text, range) {\n range = normalizeRange(range);\n const [startPosition] = range;\n const {\n index,\n offset\n } = this.locationFromPosition(startPosition);\n const document = this.removeTextAtRange(range);\n return new this.constructor(document.blockList.editObjectAtIndex(index, block => block.copyWithText(block.text.insertTextAtPosition(text, offset))));\n }\n removeTextAtRange(range) {\n let blocks;\n range = normalizeRange(range);\n const [leftPosition, rightPosition] = range;\n if (rangeIsCollapsed(range)) {\n return this;\n }\n const [leftLocation, rightLocation] = Array.from(this.locationRangeFromRange(range));\n const leftIndex = leftLocation.index;\n const leftOffset = leftLocation.offset;\n const leftBlock = this.getBlockAtIndex(leftIndex);\n const rightIndex = rightLocation.index;\n const rightOffset = rightLocation.offset;\n const rightBlock = this.getBlockAtIndex(rightIndex);\n const removeRightNewline = rightPosition - leftPosition === 1 && leftBlock.getBlockBreakPosition() === leftOffset && rightBlock.getBlockBreakPosition() !== rightOffset && rightBlock.text.getStringAtPosition(rightOffset) === \"\\n\";\n if (removeRightNewline) {\n blocks = this.blockList.editObjectAtIndex(rightIndex, block => block.copyWithText(block.text.removeTextAtRange([rightOffset, rightOffset + 1])));\n } else {\n let block;\n const leftText = leftBlock.text.getTextAtRange([0, leftOffset]);\n const rightText = rightBlock.text.getTextAtRange([rightOffset, rightBlock.getLength()]);\n const text = leftText.appendText(rightText);\n const removingLeftBlock = leftIndex !== rightIndex && leftOffset === 0;\n const useRightBlock = removingLeftBlock && leftBlock.getAttributeLevel() >= rightBlock.getAttributeLevel();\n if (useRightBlock) {\n block = rightBlock.copyWithText(text);\n } else {\n block = leftBlock.copyWithText(text);\n }\n const affectedBlockCount = rightIndex + 1 - leftIndex;\n blocks = this.blockList.splice(leftIndex, affectedBlockCount, block);\n }\n return new this.constructor(blocks);\n }\n moveTextFromRangeToPosition(range, position) {\n let text;\n range = normalizeRange(range);\n const [startPosition, endPosition] = range;\n if (startPosition <= position && position <= endPosition) {\n return this;\n }\n let document = this.getDocumentAtRange(range);\n let result = this.removeTextAtRange(range);\n const movingRightward = startPosition < position;\n if (movingRightward) {\n position -= document.getLength();\n }\n const [firstBlock, ...blocks] = document.getBlocks();\n if (blocks.length === 0) {\n text = firstBlock.getTextWithoutBlockBreak();\n if (movingRightward) {\n position += 1;\n }\n } else {\n text = firstBlock.text;\n }\n result = result.insertTextAtRange(text, position);\n if (blocks.length === 0) {\n return result;\n }\n document = new this.constructor(blocks);\n position += text.getLength();\n return result.insertDocumentAtRange(document, position);\n }\n addAttributeAtRange(attribute, value, range) {\n let {\n blockList\n } = this;\n this.eachBlockAtRange(range, (block, textRange, index) => blockList = blockList.editObjectAtIndex(index, function () {\n if (getBlockConfig(attribute)) {\n return block.addAttribute(attribute, value);\n } else {\n if (textRange[0] === textRange[1]) {\n return block;\n } else {\n return block.copyWithText(block.text.addAttributeAtRange(attribute, value, textRange));\n }\n }\n }));\n return new this.constructor(blockList);\n }\n addAttribute(attribute, value) {\n let {\n blockList\n } = this;\n this.eachBlock((block, index) => blockList = blockList.editObjectAtIndex(index, () => block.addAttribute(attribute, value)));\n return new this.constructor(blockList);\n }\n removeAttributeAtRange(attribute, range) {\n let {\n blockList\n } = this;\n this.eachBlockAtRange(range, function (block, textRange, index) {\n if (getBlockConfig(attribute)) {\n blockList = blockList.editObjectAtIndex(index, () => block.removeAttribute(attribute));\n } else if (textRange[0] !== textRange[1]) {\n blockList = blockList.editObjectAtIndex(index, () => block.copyWithText(block.text.removeAttributeAtRange(attribute, textRange)));\n }\n });\n return new this.constructor(blockList);\n }\n updateAttributesForAttachment(attributes, attachment) {\n const range = this.getRangeOfAttachment(attachment);\n const [startPosition] = Array.from(range);\n const {\n index\n } = this.locationFromPosition(startPosition);\n const text = this.getTextAtIndex(index);\n return new this.constructor(this.blockList.editObjectAtIndex(index, block => block.copyWithText(text.updateAttributesForAttachment(attributes, attachment))));\n }\n removeAttributeForAttachment(attribute, attachment) {\n const range = this.getRangeOfAttachment(attachment);\n return this.removeAttributeAtRange(attribute, range);\n }\n setHTMLAttributeAtPosition(position, name, value) {\n const block = this.getBlockAtPosition(position);\n const updatedBlock = block.addHTMLAttribute(name, value);\n return this.replaceBlock(block, updatedBlock);\n }\n insertBlockBreakAtRange(range) {\n let blocks;\n range = normalizeRange(range);\n const [startPosition] = range;\n const {\n offset\n } = this.locationFromPosition(startPosition);\n const document = this.removeTextAtRange(range);\n if (offset === 0) {\n blocks = [new Block()];\n }\n return new this.constructor(document.blockList.insertSplittableListAtPosition(new SplittableList(blocks), startPosition));\n }\n applyBlockAttributeAtRange(attributeName, value, range) {\n const expanded = this.expandRangeToLineBreaksAndSplitBlocks(range);\n let document = expanded.document;\n range = expanded.range;\n const blockConfig = getBlockConfig(attributeName);\n if (blockConfig.listAttribute) {\n document = document.removeLastListAttributeAtRange(range, {\n exceptAttributeName: attributeName\n });\n const converted = document.convertLineBreaksToBlockBreaksInRange(range);\n document = converted.document;\n range = converted.range;\n } else if (blockConfig.exclusive) {\n document = document.removeBlockAttributesAtRange(range);\n } else if (blockConfig.terminal) {\n document = document.removeLastTerminalAttributeAtRange(range);\n } else {\n document = document.consolidateBlocksAtRange(range);\n }\n return document.addAttributeAtRange(attributeName, value, range);\n }\n removeLastListAttributeAtRange(range) {\n let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};\n let {\n blockList\n } = this;\n this.eachBlockAtRange(range, function (block, textRange, index) {\n const lastAttributeName = block.getLastAttribute();\n if (!lastAttributeName) {\n return;\n }\n if (!getBlockConfig(lastAttributeName).listAttribute) {\n return;\n }\n if (lastAttributeName === options.exceptAttributeName) {\n return;\n }\n blockList = blockList.editObjectAtIndex(index, () => block.removeAttribute(lastAttributeName));\n });\n return new this.constructor(blockList);\n }\n removeLastTerminalAttributeAtRange(range) {\n let {\n blockList\n } = this;\n this.eachBlockAtRange(range, function (block, textRange, index) {\n const lastAttributeName = block.getLastAttribute();\n if (!lastAttributeName) {\n return;\n }\n if (!getBlockConfig(lastAttributeName).terminal) {\n return;\n }\n blockList = blockList.editObjectAtIndex(index, () => block.removeAttribute(lastAttributeName));\n });\n return new this.constructor(blockList);\n }\n removeBlockAttributesAtRange(range) {\n let {\n blockList\n } = this;\n this.eachBlockAtRange(range, function (block, textRange, index) {\n if (block.hasAttributes()) {\n blockList = blockList.editObjectAtIndex(index, () => block.copyWithoutAttributes());\n }\n });\n return new this.constructor(blockList);\n }\n expandRangeToLineBreaksAndSplitBlocks(range) {\n let position;\n range = normalizeRange(range);\n let [startPosition, endPosition] = range;\n const startLocation = this.locationFromPosition(startPosition);\n const endLocation = this.locationFromPosition(endPosition);\n let document = this;\n const startBlock = document.getBlockAtIndex(startLocation.index);\n startLocation.offset = startBlock.findLineBreakInDirectionFromPosition(\"backward\", startLocation.offset);\n if (startLocation.offset != null) {\n position = document.positionFromLocation(startLocation);\n document = document.insertBlockBreakAtRange([position, position + 1]);\n endLocation.index += 1;\n endLocation.offset -= document.getBlockAtIndex(startLocation.index).getLength();\n startLocation.index += 1;\n }\n startLocation.offset = 0;\n if (endLocation.offset === 0 && endLocation.index > startLocation.index) {\n endLocation.index -= 1;\n endLocation.offset = document.getBlockAtIndex(endLocation.index).getBlockBreakPosition();\n } else {\n const endBlock = document.getBlockAtIndex(endLocation.index);\n if (endBlock.text.getStringAtRange([endLocation.offset - 1, endLocation.offset]) === \"\\n\") {\n endLocation.offset -= 1;\n } else {\n endLocation.offset = endBlock.findLineBreakInDirectionFromPosition(\"forward\", endLocation.offset);\n }\n if (endLocation.offset !== endBlock.getBlockBreakPosition()) {\n position = document.positionFromLocation(endLocation);\n document = document.insertBlockBreakAtRange([position, position + 1]);\n }\n }\n startPosition = document.positionFromLocation(startLocation);\n endPosition = document.positionFromLocation(endLocation);\n range = normalizeRange([startPosition, endPosition]);\n return {\n document,\n range\n };\n }\n convertLineBreaksToBlockBreaksInRange(range) {\n range = normalizeRange(range);\n let [position] = range;\n const string = this.getStringAtRange(range).slice(0, -1);\n let document = this;\n string.replace(/.*?\\n/g, function (match) {\n position += match.length;\n document = document.insertBlockBreakAtRange([position - 1, position]);\n });\n return {\n document,\n range\n };\n }\n consolidateBlocksAtRange(range) {\n range = normalizeRange(range);\n const [startPosition, endPosition] = range;\n const startIndex = this.locationFromPosition(startPosition).index;\n const endIndex = this.locationFromPosition(endPosition).index;\n return new this.constructor(this.blockList.consolidateFromIndexToIndex(startIndex, endIndex));\n }\n getDocumentAtRange(range) {\n range = normalizeRange(range);\n const blocks = this.blockList.getSplittableListInRange(range).toArray();\n return new this.constructor(blocks);\n }\n getStringAtRange(range) {\n let endIndex;\n const array = range = normalizeRange(range),\n endPosition = array[array.length - 1];\n if (endPosition !== this.getLength()) {\n endIndex = -1;\n }\n return this.getDocumentAtRange(range).toString().slice(0, endIndex);\n }\n getBlockAtIndex(index) {\n return this.blockList.getObjectAtIndex(index);\n }\n getBlockAtPosition(position) {\n const {\n index\n } = this.locationFromPosition(position);\n return this.getBlockAtIndex(index);\n }\n getTextAtIndex(index) {\n var _this$getBlockAtIndex;\n return (_this$getBlockAtIndex = this.getBlockAtIndex(index)) === null || _this$getBlockAtIndex === void 0 ? void 0 : _this$getBlockAtIndex.text;\n }\n getTextAtPosition(position) {\n const {\n index\n } = this.locationFromPosition(position);\n return this.getTextAtIndex(index);\n }\n getPieceAtPosition(position) {\n const {\n index,\n offset\n } = this.locationFromPosition(position);\n return this.getTextAtIndex(index).getPieceAtPosition(offset);\n }\n getCharacterAtPosition(position) {\n const {\n index,\n offset\n } = this.locationFromPosition(position);\n return this.getTextAtIndex(index).getStringAtRange([offset, offset + 1]);\n }\n getLength() {\n return this.blockList.getEndPosition();\n }\n getBlocks() {\n return this.blockList.toArray();\n }\n getBlockCount() {\n return this.blockList.length;\n }\n getEditCount() {\n return this.editCount;\n }\n eachBlock(callback) {\n return this.blockList.eachObject(callback);\n }\n eachBlockAtRange(range, callback) {\n let block, textRange;\n range = normalizeRange(range);\n const [startPosition, endPosition] = range;\n const startLocation = this.locationFromPosition(startPosition);\n const endLocation = this.locationFromPosition(endPosition);\n if (startLocation.index === endLocation.index) {\n block = this.getBlockAtIndex(startLocation.index);\n textRange = [startLocation.offset, endLocation.offset];\n return callback(block, textRange, startLocation.index);\n } else {\n for (let index = startLocation.index; index <= endLocation.index; index++) {\n block = this.getBlockAtIndex(index);\n if (block) {\n switch (index) {\n case startLocation.index:\n textRange = [startLocation.offset, block.text.getLength()];\n break;\n case endLocation.index:\n textRange = [0, endLocation.offset];\n break;\n default:\n textRange = [0, block.text.getLength()];\n }\n callback(block, textRange, index);\n }\n }\n }\n }\n getCommonAttributesAtRange(range) {\n range = normalizeRange(range);\n const [startPosition] = range;\n if (rangeIsCollapsed(range)) {\n return this.getCommonAttributesAtPosition(startPosition);\n } else {\n const textAttributes = [];\n const blockAttributes = [];\n this.eachBlockAtRange(range, function (block, textRange) {\n if (textRange[0] !== textRange[1]) {\n textAttributes.push(block.text.getCommonAttributesAtRange(textRange));\n return blockAttributes.push(attributesForBlock(block));\n }\n });\n return Hash.fromCommonAttributesOfObjects(textAttributes).merge(Hash.fromCommonAttributesOfObjects(blockAttributes)).toObject();\n }\n }\n getCommonAttributesAtPosition(position) {\n let key, value;\n const {\n index,\n offset\n } = this.locationFromPosition(position);\n const block = this.getBlockAtIndex(index);\n if (!block) {\n return {};\n }\n const commonAttributes = attributesForBlock(block);\n const attributes = block.text.getAttributesAtPosition(offset);\n const attributesLeft = block.text.getAttributesAtPosition(offset - 1);\n const inheritableAttributes = Object.keys(text_attributes).filter(key => {\n return text_attributes[key].inheritable;\n });\n for (key in attributesLeft) {\n value = attributesLeft[key];\n if (value === attributes[key] || inheritableAttributes.includes(key)) {\n commonAttributes[key] = value;\n }\n }\n return commonAttributes;\n }\n getRangeOfCommonAttributeAtPosition(attributeName, position) {\n const {\n index,\n offset\n } = this.locationFromPosition(position);\n const text = this.getTextAtIndex(index);\n const [startOffset, endOffset] = Array.from(text.getExpandedRangeForAttributeAtOffset(attributeName, offset));\n const start = this.positionFromLocation({\n index,\n offset: startOffset\n });\n const end = this.positionFromLocation({\n index,\n offset: endOffset\n });\n return normalizeRange([start, end]);\n }\n getBaseBlockAttributes() {\n let baseBlockAttributes = this.getBlockAtIndex(0).getAttributes();\n for (let blockIndex = 1; blockIndex < this.getBlockCount(); blockIndex++) {\n const blockAttributes = this.getBlockAtIndex(blockIndex).getAttributes();\n const lastAttributeIndex = Math.min(baseBlockAttributes.length, blockAttributes.length);\n baseBlockAttributes = (() => {\n const result = [];\n for (let index = 0; index < lastAttributeIndex; index++) {\n if (blockAttributes[index] !== baseBlockAttributes[index]) {\n break;\n }\n result.push(blockAttributes[index]);\n }\n return result;\n })();\n }\n return baseBlockAttributes;\n }\n getAttachmentById(attachmentId) {\n for (const attachment of this.getAttachments()) {\n if (attachment.id === attachmentId) {\n return attachment;\n }\n }\n }\n getAttachmentPieces() {\n let attachmentPieces = [];\n this.blockList.eachObject(_ref => {\n let {\n text\n } = _ref;\n return attachmentPieces = attachmentPieces.concat(text.getAttachmentPieces());\n });\n return attachmentPieces;\n }\n getAttachments() {\n return this.getAttachmentPieces().map(piece => piece.attachment);\n }\n getRangeOfAttachment(attachment) {\n let position = 0;\n const iterable = this.blockList.toArray();\n for (let index = 0; index < iterable.length; index++) {\n const {\n text\n } = iterable[index];\n const textRange = text.getRangeOfAttachment(attachment);\n if (textRange) {\n return normalizeRange([position + textRange[0], position + textRange[1]]);\n }\n position += text.getLength();\n }\n }\n getLocationRangeOfAttachment(attachment) {\n const range = this.getRangeOfAttachment(attachment);\n return this.locationRangeFromRange(range);\n }\n getAttachmentPieceForAttachment(attachment) {\n for (const piece of this.getAttachmentPieces()) {\n if (piece.attachment === attachment) {\n return piece;\n }\n }\n }\n findRangesForBlockAttribute(attributeName) {\n let position = 0;\n const ranges = [];\n this.getBlocks().forEach(block => {\n const length = block.getLength();\n if (block.hasAttribute(attributeName)) {\n ranges.push([position, position + length]);\n }\n position += length;\n });\n return ranges;\n }\n findRangesForTextAttribute(attributeName) {\n let {\n withValue\n } = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};\n let position = 0;\n let range = [];\n const ranges = [];\n const match = function (piece) {\n if (withValue) {\n return piece.getAttribute(attributeName) === withValue;\n } else {\n return piece.hasAttribute(attributeName);\n }\n };\n this.getPieces().forEach(piece => {\n const length = piece.getLength();\n if (match(piece)) {\n if (range[1] === position) {\n range[1] = position + length;\n } else {\n ranges.push(range = [position, position + length]);\n }\n }\n position += length;\n });\n return ranges;\n }\n locationFromPosition(position) {\n const location = this.blockList.findIndexAndOffsetAtPosition(Math.max(0, position));\n if (location.index != null) {\n return location;\n } else {\n const blocks = this.getBlocks();\n return {\n index: blocks.length - 1,\n offset: blocks[blocks.length - 1].getLength()\n };\n }\n }\n positionFromLocation(location) {\n return this.blockList.findPositionAtIndexAndOffset(location.index, location.offset);\n }\n locationRangeFromPosition(position) {\n return normalizeRange(this.locationFromPosition(position));\n }\n locationRangeFromRange(range) {\n range = normalizeRange(range);\n if (!range) return;\n const [startPosition, endPosition] = Array.from(range);\n const startLocation = this.locationFromPosition(startPosition);\n const endLocation = this.locationFromPosition(endPosition);\n return normalizeRange([startLocation, endLocation]);\n }\n rangeFromLocationRange(locationRange) {\n let rightPosition;\n locationRange = normalizeRange(locationRange);\n const leftPosition = this.positionFromLocation(locationRange[0]);\n if (!rangeIsCollapsed(locationRange)) {\n rightPosition = this.positionFromLocation(locationRange[1]);\n }\n return normalizeRange([leftPosition, rightPosition]);\n }\n isEqualTo(document) {\n return this.blockList.isEqualTo(document === null || document === void 0 ? void 0 : document.blockList);\n }\n getTexts() {\n return this.getBlocks().map(block => block.text);\n }\n getPieces() {\n const pieces = [];\n Array.from(this.getTexts()).forEach(text => {\n pieces.push(...Array.from(text.getPieces() || []));\n });\n return pieces;\n }\n getObjects() {\n return this.getBlocks().concat(this.getTexts()).concat(this.getPieces());\n }\n toSerializableDocument() {\n const blocks = [];\n this.blockList.eachObject(block => blocks.push(block.copyWithText(block.text.toSerializableText())));\n return new this.constructor(blocks);\n }\n toString() {\n return this.blockList.toString();\n }\n toJSON() {\n return this.blockList.toJSON();\n }\n toConsole() {\n return JSON.stringify(this.blockList.toArray().map(block => JSON.parse(block.text.toConsole())));\n }\n }\n const attributesForBlock = function (block) {\n const attributes = {};\n const attributeName = block.getLastAttribute();\n if (attributeName) {\n attributes[attributeName] = true;\n }\n return attributes;\n };\n\n /* eslint-disable\n no-case-declarations,\n no-irregular-whitespace,\n */\n const pieceForString = function (string) {\n let attributes = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};\n const type = \"string\";\n string = normalizeSpaces(string);\n return {\n string,\n attributes,\n type\n };\n };\n const pieceForAttachment = function (attachment) {\n let attributes = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};\n const type = \"attachment\";\n return {\n attachment,\n attributes,\n type\n };\n };\n const blockForAttributes = function () {\n let attributes = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};\n let htmlAttributes = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};\n const text = [];\n return {\n text,\n attributes,\n htmlAttributes\n };\n };\n const parseTrixDataAttribute = (element, name) => {\n try {\n return JSON.parse(element.getAttribute(\"data-trix-\".concat(name)));\n } catch (error) {\n return {};\n }\n };\n const getImageDimensions = element => {\n const width = element.getAttribute(\"width\");\n const height = element.getAttribute(\"height\");\n const dimensions = {};\n if (width) {\n dimensions.width = parseInt(width, 10);\n }\n if (height) {\n dimensions.height = parseInt(height, 10);\n }\n return dimensions;\n };\n class HTMLParser extends BasicObject {\n static parse(html, options) {\n const parser = new this(html, options);\n parser.parse();\n return parser;\n }\n constructor(html) {\n let {\n referenceElement\n } = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};\n super(...arguments);\n this.html = html;\n this.referenceElement = referenceElement;\n this.blocks = [];\n this.blockElements = [];\n this.processedElements = [];\n }\n getDocument() {\n return Document.fromJSON(this.blocks);\n }\n\n // HTML parsing\n\n parse() {\n try {\n this.createHiddenContainer();\n HTMLSanitizer.setHTML(this.containerElement, this.html);\n const walker = walkTree(this.containerElement, {\n usingFilter: nodeFilter\n });\n while (walker.nextNode()) {\n this.processNode(walker.currentNode);\n }\n return this.translateBlockElementMarginsToNewlines();\n } finally {\n this.removeHiddenContainer();\n }\n }\n createHiddenContainer() {\n if (this.referenceElement) {\n this.containerElement = this.referenceElement.cloneNode(false);\n this.containerElement.removeAttribute(\"id\");\n this.containerElement.setAttribute(\"data-trix-internal\", \"\");\n this.containerElement.style.display = \"none\";\n return this.referenceElement.parentNode.insertBefore(this.containerElement, this.referenceElement.nextSibling);\n } else {\n this.containerElement = makeElement({\n tagName: \"div\",\n style: {\n display: \"none\"\n }\n });\n return document.body.appendChild(this.containerElement);\n }\n }\n removeHiddenContainer() {\n return removeNode(this.containerElement);\n }\n processNode(node) {\n switch (node.nodeType) {\n case Node.TEXT_NODE:\n if (!this.isInsignificantTextNode(node)) {\n this.appendBlockForTextNode(node);\n return this.processTextNode(node);\n }\n break;\n case Node.ELEMENT_NODE:\n this.appendBlockForElement(node);\n return this.processElement(node);\n }\n }\n appendBlockForTextNode(node) {\n const element = node.parentNode;\n if (element === this.currentBlockElement && this.isBlockElement(node.previousSibling)) {\n return this.appendStringWithAttributes(\"\\n\");\n } else if (element === this.containerElement || this.isBlockElement(element)) {\n var _this$currentBlock;\n const attributes = this.getBlockAttributes(element);\n const htmlAttributes = this.getBlockHTMLAttributes(element);\n if (!arraysAreEqual(attributes, (_this$currentBlock = this.currentBlock) === null || _this$currentBlock === void 0 ? void 0 : _this$currentBlock.attributes)) {\n this.currentBlock = this.appendBlockForAttributesWithElement(attributes, element, htmlAttributes);\n this.currentBlockElement = element;\n }\n }\n }\n appendBlockForElement(element) {\n const elementIsBlockElement = this.isBlockElement(element);\n const currentBlockContainsElement = elementContainsNode(this.currentBlockElement, element);\n if (elementIsBlockElement && !this.isBlockElement(element.firstChild)) {\n if (!this.isInsignificantTextNode(element.firstChild) || !this.isBlockElement(element.firstElementChild)) {\n const attributes = this.getBlockAttributes(element);\n const htmlAttributes = this.getBlockHTMLAttributes(element);\n if (element.firstChild) {\n if (!(currentBlockContainsElement && arraysAreEqual(attributes, this.currentBlock.attributes))) {\n this.currentBlock = this.appendBlockForAttributesWithElement(attributes, element, htmlAttributes);\n this.currentBlockElement = element;\n } else {\n return this.appendStringWithAttributes(\"\\n\");\n }\n }\n }\n } else if (this.currentBlockElement && !currentBlockContainsElement && !elementIsBlockElement) {\n const parentBlockElement = this.findParentBlockElement(element);\n if (parentBlockElement) {\n return this.appendBlockForElement(parentBlockElement);\n } else {\n this.currentBlock = this.appendEmptyBlock();\n this.currentBlockElement = null;\n }\n }\n }\n findParentBlockElement(element) {\n let {\n parentElement\n } = element;\n while (parentElement && parentElement !== this.containerElement) {\n if (this.isBlockElement(parentElement) && this.blockElements.includes(parentElement)) {\n return parentElement;\n } else {\n parentElement = parentElement.parentElement;\n }\n }\n return null;\n }\n processTextNode(node) {\n let string = node.data;\n if (!elementCanDisplayPreformattedText(node.parentNode)) {\n var _node$previousSibling;\n string = squishBreakableWhitespace(string);\n if (stringEndsWithWhitespace((_node$previousSibling = node.previousSibling) === null || _node$previousSibling === void 0 ? void 0 : _node$previousSibling.textContent)) {\n string = leftTrimBreakableWhitespace(string);\n }\n }\n return this.appendStringWithAttributes(string, this.getTextAttributes(node.parentNode));\n }\n processElement(element) {\n let attributes;\n if (nodeIsAttachmentElement(element)) {\n attributes = parseTrixDataAttribute(element, \"attachment\");\n if (Object.keys(attributes).length) {\n const textAttributes = this.getTextAttributes(element);\n this.appendAttachmentWithAttributes(attributes, textAttributes);\n // We have everything we need so avoid processing inner nodes\n element.innerHTML = \"\";\n }\n return this.processedElements.push(element);\n } else {\n switch (tagName(element)) {\n case \"br\":\n if (!this.isExtraBR(element) && !this.isBlockElement(element.nextSibling)) {\n this.appendStringWithAttributes(\"\\n\", this.getTextAttributes(element));\n }\n return this.processedElements.push(element);\n case \"img\":\n attributes = {\n url: element.getAttribute(\"src\"),\n contentType: \"image\"\n };\n const object = getImageDimensions(element);\n for (const key in object) {\n const value = object[key];\n attributes[key] = value;\n }\n this.appendAttachmentWithAttributes(attributes, this.getTextAttributes(element));\n return this.processedElements.push(element);\n case \"tr\":\n if (this.needsTableSeparator(element)) {\n return this.appendStringWithAttributes(parser.tableRowSeparator);\n }\n break;\n case \"td\":\n if (this.needsTableSeparator(element)) {\n return this.appendStringWithAttributes(parser.tableCellSeparator);\n }\n break;\n }\n }\n }\n\n // Document construction\n\n appendBlockForAttributesWithElement(attributes, element) {\n let htmlAttributes = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};\n this.blockElements.push(element);\n const block = blockForAttributes(attributes, htmlAttributes);\n this.blocks.push(block);\n return block;\n }\n appendEmptyBlock() {\n return this.appendBlockForAttributesWithElement([], null);\n }\n appendStringWithAttributes(string, attributes) {\n return this.appendPiece(pieceForString(string, attributes));\n }\n appendAttachmentWithAttributes(attachment, attributes) {\n return this.appendPiece(pieceForAttachment(attachment, attributes));\n }\n appendPiece(piece) {\n if (this.blocks.length === 0) {\n this.appendEmptyBlock();\n }\n return this.blocks[this.blocks.length - 1].text.push(piece);\n }\n appendStringToTextAtIndex(string, index) {\n const {\n text\n } = this.blocks[index];\n const piece = text[text.length - 1];\n if ((piece === null || piece === void 0 ? void 0 : piece.type) === \"string\") {\n piece.string += string;\n } else {\n return text.push(pieceForString(string));\n }\n }\n prependStringToTextAtIndex(string, index) {\n const {\n text\n } = this.blocks[index];\n const piece = text[0];\n if ((piece === null || piece === void 0 ? void 0 : piece.type) === \"string\") {\n piece.string = string + piece.string;\n } else {\n return text.unshift(pieceForString(string));\n }\n }\n\n // Attribute parsing\n\n getTextAttributes(element) {\n let value;\n const attributes = {};\n for (const attribute in text_attributes) {\n const configAttr = text_attributes[attribute];\n if (configAttr.tagName && findClosestElementFromNode(element, {\n matchingSelector: configAttr.tagName,\n untilNode: this.containerElement\n })) {\n attributes[attribute] = true;\n } else if (configAttr.parser) {\n value = configAttr.parser(element);\n if (value) {\n let attributeInheritedFromBlock = false;\n for (const blockElement of this.findBlockElementAncestors(element)) {\n if (configAttr.parser(blockElement) === value) {\n attributeInheritedFromBlock = true;\n break;\n }\n }\n if (!attributeInheritedFromBlock) {\n attributes[attribute] = value;\n }\n }\n } else if (configAttr.styleProperty) {\n value = element.style[configAttr.styleProperty];\n if (value) {\n attributes[attribute] = value;\n }\n }\n }\n if (nodeIsAttachmentElement(element)) {\n const object = parseTrixDataAttribute(element, \"attributes\");\n for (const key in object) {\n value = object[key];\n attributes[key] = value;\n }\n }\n return attributes;\n }\n getBlockAttributes(element) {\n const attributes$1 = [];\n while (element && element !== this.containerElement) {\n for (const attribute in attributes) {\n const attrConfig = attributes[attribute];\n if (attrConfig.parse !== false) {\n if (tagName(element) === attrConfig.tagName) {\n var _attrConfig$test;\n if ((_attrConfig$test = attrConfig.test) !== null && _attrConfig$test !== void 0 && _attrConfig$test.call(attrConfig, element) || !attrConfig.test) {\n attributes$1.push(attribute);\n if (attrConfig.listAttribute) {\n attributes$1.push(attrConfig.listAttribute);\n }\n }\n }\n }\n }\n element = element.parentNode;\n }\n return attributes$1.reverse();\n }\n getBlockHTMLAttributes(element) {\n const attributes$1 = {};\n const blockConfig = Object.values(attributes).find(settings => settings.tagName === tagName(element));\n const allowedAttributes = (blockConfig === null || blockConfig === void 0 ? void 0 : blockConfig.htmlAttributes) || [];\n allowedAttributes.forEach(attribute => {\n if (element.hasAttribute(attribute)) {\n attributes$1[attribute] = element.getAttribute(attribute);\n }\n });\n return attributes$1;\n }\n findBlockElementAncestors(element) {\n const ancestors = [];\n while (element && element !== this.containerElement) {\n const tag = tagName(element);\n if (getBlockTagNames().includes(tag)) {\n ancestors.push(element);\n }\n element = element.parentNode;\n }\n return ancestors;\n }\n\n // Element inspection\n\n isBlockElement(element) {\n if ((element === null || element === void 0 ? void 0 : element.nodeType) !== Node.ELEMENT_NODE) return;\n if (nodeIsAttachmentElement(element)) return;\n if (findClosestElementFromNode(element, {\n matchingSelector: \"td\",\n untilNode: this.containerElement\n })) return;\n return getBlockTagNames().includes(tagName(element)) || window.getComputedStyle(element).display === \"block\";\n }\n isInsignificantTextNode(node) {\n if ((node === null || node === void 0 ? void 0 : node.nodeType) !== Node.TEXT_NODE) return;\n if (!stringIsAllBreakableWhitespace(node.data)) return;\n const {\n parentNode,\n previousSibling,\n nextSibling\n } = node;\n if (nodeEndsWithNonWhitespace(parentNode.previousSibling) && !this.isBlockElement(parentNode.previousSibling)) return;\n if (elementCanDisplayPreformattedText(parentNode)) return;\n return !previousSibling || this.isBlockElement(previousSibling) || !nextSibling || this.isBlockElement(nextSibling);\n }\n isExtraBR(element) {\n return tagName(element) === \"br\" && this.isBlockElement(element.parentNode) && element.parentNode.lastChild === element;\n }\n needsTableSeparator(element) {\n if (parser.removeBlankTableCells) {\n var _element$previousSibl;\n const content = (_element$previousSibl = element.previousSibling) === null || _element$previousSibl === void 0 ? void 0 : _element$previousSibl.textContent;\n return content && /\\S/.test(content);\n } else {\n return element.previousSibling;\n }\n }\n\n // Margin translation\n\n translateBlockElementMarginsToNewlines() {\n const defaultMargin = this.getMarginOfDefaultBlockElement();\n for (let index = 0; index < this.blocks.length; index++) {\n const margin = this.getMarginOfBlockElementAtIndex(index);\n if (margin) {\n if (margin.top > defaultMargin.top * 2) {\n this.prependStringToTextAtIndex(\"\\n\", index);\n }\n if (margin.bottom > defaultMargin.bottom * 2) {\n this.appendStringToTextAtIndex(\"\\n\", index);\n }\n }\n }\n }\n getMarginOfBlockElementAtIndex(index) {\n const element = this.blockElements[index];\n if (element) {\n if (element.textContent) {\n if (!getBlockTagNames().includes(tagName(element)) && !this.processedElements.includes(element)) {\n return getBlockElementMargin(element);\n }\n }\n }\n }\n getMarginOfDefaultBlockElement() {\n const element = makeElement(attributes.default.tagName);\n this.containerElement.appendChild(element);\n return getBlockElementMargin(element);\n }\n }\n\n //\u00A0Helpers\n\n const elementCanDisplayPreformattedText = function (element) {\n const {\n whiteSpace\n } = window.getComputedStyle(element);\n return [\"pre\", \"pre-wrap\", \"pre-line\"].includes(whiteSpace);\n };\n const nodeEndsWithNonWhitespace = node => node && !stringEndsWithWhitespace(node.textContent);\n const getBlockElementMargin = function (element) {\n const style = window.getComputedStyle(element);\n if (style.display === \"block\") {\n return {\n top: parseInt(style.marginTop),\n bottom: parseInt(style.marginBottom)\n };\n }\n };\n const nodeFilter = function (node) {\n if (tagName(node) === \"style\") {\n return NodeFilter.FILTER_REJECT;\n } else {\n return NodeFilter.FILTER_ACCEPT;\n }\n };\n\n // Whitespace\n\n const leftTrimBreakableWhitespace = string => string.replace(new RegExp(\"^\".concat(breakableWhitespacePattern.source, \"+\")), \"\");\n const stringIsAllBreakableWhitespace = string => new RegExp(\"^\".concat(breakableWhitespacePattern.source, \"*$\")).test(string);\n const stringEndsWithWhitespace = string => /\\s$/.test(string);\n\n /* eslint-disable\n no-empty,\n */\n const unserializableElementSelector = \"[data-trix-serialize=false]\";\n const unserializableAttributeNames = [\"contenteditable\", \"data-trix-id\", \"data-trix-store-key\", \"data-trix-mutable\", \"data-trix-placeholder\", \"tabindex\"];\n const serializedAttributesAttribute = \"data-trix-serialized-attributes\";\n const serializedAttributesSelector = \"[\".concat(serializedAttributesAttribute, \"]\");\n const blockCommentPattern = new RegExp(\"\", \"g\");\n const serializers = {\n \"application/json\": function (serializable) {\n let document;\n if (serializable instanceof Document) {\n document = serializable;\n } else if (serializable instanceof HTMLElement) {\n document = HTMLParser.parse(serializable.innerHTML).getDocument();\n } else {\n throw new Error(\"unserializable object\");\n }\n return document.toSerializableDocument().toJSONString();\n },\n \"text/html\": function (serializable) {\n let element;\n if (serializable instanceof Document) {\n element = DocumentView.render(serializable);\n } else if (serializable instanceof HTMLElement) {\n element = serializable.cloneNode(true);\n } else {\n throw new Error(\"unserializable object\");\n }\n\n // Remove unserializable elements\n Array.from(element.querySelectorAll(unserializableElementSelector)).forEach(el => {\n removeNode(el);\n });\n\n // Remove unserializable attributes\n unserializableAttributeNames.forEach(attribute => {\n Array.from(element.querySelectorAll(\"[\".concat(attribute, \"]\"))).forEach(el => {\n el.removeAttribute(attribute);\n });\n });\n\n // Rewrite elements with serialized attribute overrides\n Array.from(element.querySelectorAll(serializedAttributesSelector)).forEach(el => {\n try {\n const attributes = JSON.parse(el.getAttribute(serializedAttributesAttribute));\n el.removeAttribute(serializedAttributesAttribute);\n for (const name in attributes) {\n const value = attributes[name];\n el.setAttribute(name, value);\n }\n } catch (error) {}\n });\n return element.innerHTML.replace(blockCommentPattern, \"\");\n }\n };\n const deserializers = {\n \"application/json\": function (string) {\n return Document.fromJSONString(string);\n },\n \"text/html\": function (string) {\n return HTMLParser.parse(string).getDocument();\n }\n };\n const serializeToContentType = function (serializable, contentType) {\n const serializer = serializers[contentType];\n if (serializer) {\n return serializer(serializable);\n } else {\n throw new Error(\"unknown content type: \".concat(contentType));\n }\n };\n const deserializeFromContentType = function (string, contentType) {\n const deserializer = deserializers[contentType];\n if (deserializer) {\n return deserializer(string);\n } else {\n throw new Error(\"unknown content type: \".concat(contentType));\n }\n };\n\n var core = /*#__PURE__*/Object.freeze({\n __proto__: null\n });\n\n class ManagedAttachment extends BasicObject {\n constructor(attachmentManager, attachment) {\n super(...arguments);\n this.attachmentManager = attachmentManager;\n this.attachment = attachment;\n this.id = this.attachment.id;\n this.file = this.attachment.file;\n }\n remove() {\n return this.attachmentManager.requestRemovalOfAttachment(this.attachment);\n }\n }\n ManagedAttachment.proxyMethod(\"attachment.getAttribute\");\n ManagedAttachment.proxyMethod(\"attachment.hasAttribute\");\n ManagedAttachment.proxyMethod(\"attachment.setAttribute\");\n ManagedAttachment.proxyMethod(\"attachment.getAttributes\");\n ManagedAttachment.proxyMethod(\"attachment.setAttributes\");\n ManagedAttachment.proxyMethod(\"attachment.isPending\");\n ManagedAttachment.proxyMethod(\"attachment.isPreviewable\");\n ManagedAttachment.proxyMethod(\"attachment.getURL\");\n ManagedAttachment.proxyMethod(\"attachment.getHref\");\n ManagedAttachment.proxyMethod(\"attachment.getFilename\");\n ManagedAttachment.proxyMethod(\"attachment.getFilesize\");\n ManagedAttachment.proxyMethod(\"attachment.getFormattedFilesize\");\n ManagedAttachment.proxyMethod(\"attachment.getExtension\");\n ManagedAttachment.proxyMethod(\"attachment.getContentType\");\n ManagedAttachment.proxyMethod(\"attachment.getFile\");\n ManagedAttachment.proxyMethod(\"attachment.setFile\");\n ManagedAttachment.proxyMethod(\"attachment.releaseFile\");\n ManagedAttachment.proxyMethod(\"attachment.getUploadProgress\");\n ManagedAttachment.proxyMethod(\"attachment.setUploadProgress\");\n\n class AttachmentManager extends BasicObject {\n constructor() {\n let attachments = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];\n super(...arguments);\n this.managedAttachments = {};\n Array.from(attachments).forEach(attachment => {\n this.manageAttachment(attachment);\n });\n }\n getAttachments() {\n const result = [];\n for (const id in this.managedAttachments) {\n const attachment = this.managedAttachments[id];\n result.push(attachment);\n }\n return result;\n }\n manageAttachment(attachment) {\n if (!this.managedAttachments[attachment.id]) {\n this.managedAttachments[attachment.id] = new ManagedAttachment(this, attachment);\n }\n return this.managedAttachments[attachment.id];\n }\n attachmentIsManaged(attachment) {\n return attachment.id in this.managedAttachments;\n }\n requestRemovalOfAttachment(attachment) {\n if (this.attachmentIsManaged(attachment)) {\n var _this$delegate, _this$delegate$attach;\n return (_this$delegate = this.delegate) === null || _this$delegate === void 0 || (_this$delegate$attach = _this$delegate.attachmentManagerDidRequestRemovalOfAttachment) === null || _this$delegate$attach === void 0 ? void 0 : _this$delegate$attach.call(_this$delegate, attachment);\n }\n }\n unmanageAttachment(attachment) {\n const managedAttachment = this.managedAttachments[attachment.id];\n delete this.managedAttachments[attachment.id];\n return managedAttachment;\n }\n }\n\n class LineBreakInsertion {\n constructor(composition) {\n this.composition = composition;\n this.document = this.composition.document;\n const selectedRange = this.composition.getSelectedRange();\n this.startPosition = selectedRange[0];\n this.endPosition = selectedRange[1];\n this.startLocation = this.document.locationFromPosition(this.startPosition);\n this.endLocation = this.document.locationFromPosition(this.endPosition);\n this.block = this.document.getBlockAtIndex(this.endLocation.index);\n this.breaksOnReturn = this.block.breaksOnReturn();\n this.previousCharacter = this.block.text.getStringAtPosition(this.endLocation.offset - 1);\n this.nextCharacter = this.block.text.getStringAtPosition(this.endLocation.offset);\n }\n shouldInsertBlockBreak() {\n if (this.block.hasAttributes() && this.block.isListItem() && !this.block.isEmpty()) {\n return this.startLocation.offset !== 0;\n } else {\n return this.breaksOnReturn && this.nextCharacter !== \"\\n\";\n }\n }\n shouldBreakFormattedBlock() {\n return this.block.hasAttributes() && !this.block.isListItem() && (this.breaksOnReturn && this.nextCharacter === \"\\n\" || this.previousCharacter === \"\\n\");\n }\n shouldDecreaseListLevel() {\n return this.block.hasAttributes() && this.block.isListItem() && this.block.isEmpty();\n }\n shouldPrependListItem() {\n return this.block.isListItem() && this.startLocation.offset === 0 && !this.block.isEmpty();\n }\n shouldRemoveLastBlockAttribute() {\n return this.block.hasAttributes() && !this.block.isListItem() && this.block.isEmpty();\n }\n }\n\n const PLACEHOLDER = \" \";\n class Composition extends BasicObject {\n constructor() {\n super(...arguments);\n this.document = new Document();\n this.attachments = [];\n this.currentAttributes = {};\n this.revision = 0;\n }\n setDocument(document) {\n if (!document.isEqualTo(this.document)) {\n var _this$delegate, _this$delegate$compos;\n this.document = document;\n this.refreshAttachments();\n this.revision++;\n return (_this$delegate = this.delegate) === null || _this$delegate === void 0 || (_this$delegate$compos = _this$delegate.compositionDidChangeDocument) === null || _this$delegate$compos === void 0 ? void 0 : _this$delegate$compos.call(_this$delegate, document);\n }\n }\n\n // Snapshots\n\n getSnapshot() {\n return {\n document: this.document,\n selectedRange: this.getSelectedRange()\n };\n }\n loadSnapshot(_ref) {\n var _this$delegate2, _this$delegate2$compo, _this$delegate3, _this$delegate3$compo;\n let {\n document,\n selectedRange\n } = _ref;\n (_this$delegate2 = this.delegate) === null || _this$delegate2 === void 0 || (_this$delegate2$compo = _this$delegate2.compositionWillLoadSnapshot) === null || _this$delegate2$compo === void 0 || _this$delegate2$compo.call(_this$delegate2);\n this.setDocument(document != null ? document : new Document());\n this.setSelection(selectedRange != null ? selectedRange : [0, 0]);\n return (_this$delegate3 = this.delegate) === null || _this$delegate3 === void 0 || (_this$delegate3$compo = _this$delegate3.compositionDidLoadSnapshot) === null || _this$delegate3$compo === void 0 ? void 0 : _this$delegate3$compo.call(_this$delegate3);\n }\n\n // Responder protocol\n\n insertText(text) {\n let {\n updatePosition\n } = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {\n updatePosition: true\n };\n const selectedRange = this.getSelectedRange();\n this.setDocument(this.document.insertTextAtRange(text, selectedRange));\n const startPosition = selectedRange[0];\n const endPosition = startPosition + text.getLength();\n if (updatePosition) {\n this.setSelection(endPosition);\n }\n return this.notifyDelegateOfInsertionAtRange([startPosition, endPosition]);\n }\n insertBlock() {\n let block = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : new Block();\n const document = new Document([block]);\n return this.insertDocument(document);\n }\n insertDocument() {\n let document = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : new Document();\n const selectedRange = this.getSelectedRange();\n this.setDocument(this.document.insertDocumentAtRange(document, selectedRange));\n const startPosition = selectedRange[0];\n const endPosition = startPosition + document.getLength();\n this.setSelection(endPosition);\n return this.notifyDelegateOfInsertionAtRange([startPosition, endPosition]);\n }\n insertString(string, options) {\n const attributes = this.getCurrentTextAttributes();\n const text = Text.textForStringWithAttributes(string, attributes);\n return this.insertText(text, options);\n }\n insertBlockBreak() {\n const selectedRange = this.getSelectedRange();\n this.setDocument(this.document.insertBlockBreakAtRange(selectedRange));\n const startPosition = selectedRange[0];\n const endPosition = startPosition + 1;\n this.setSelection(endPosition);\n return this.notifyDelegateOfInsertionAtRange([startPosition, endPosition]);\n }\n insertLineBreak() {\n const insertion = new LineBreakInsertion(this);\n if (insertion.shouldDecreaseListLevel()) {\n this.decreaseListLevel();\n return this.setSelection(insertion.startPosition);\n } else if (insertion.shouldPrependListItem()) {\n const document = new Document([insertion.block.copyWithoutText()]);\n return this.insertDocument(document);\n } else if (insertion.shouldInsertBlockBreak()) {\n return this.insertBlockBreak();\n } else if (insertion.shouldRemoveLastBlockAttribute()) {\n return this.removeLastBlockAttribute();\n } else if (insertion.shouldBreakFormattedBlock()) {\n return this.breakFormattedBlock(insertion);\n } else {\n return this.insertString(\"\\n\");\n }\n }\n insertHTML(html) {\n const document = HTMLParser.parse(html).getDocument();\n const selectedRange = this.getSelectedRange();\n this.setDocument(this.document.mergeDocumentAtRange(document, selectedRange));\n const startPosition = selectedRange[0];\n const endPosition = startPosition + document.getLength() - 1;\n this.setSelection(endPosition);\n return this.notifyDelegateOfInsertionAtRange([startPosition, endPosition]);\n }\n replaceHTML(html) {\n const document = HTMLParser.parse(html).getDocument().copyUsingObjectsFromDocument(this.document);\n const locationRange = this.getLocationRange({\n strict: false\n });\n const selectedRange = this.document.rangeFromLocationRange(locationRange);\n this.setDocument(document);\n return this.setSelection(selectedRange);\n }\n insertFile(file) {\n return this.insertFiles([file]);\n }\n insertFiles(files) {\n const attachments = [];\n Array.from(files).forEach(file => {\n var _this$delegate4;\n if ((_this$delegate4 = this.delegate) !== null && _this$delegate4 !== void 0 && _this$delegate4.compositionShouldAcceptFile(file)) {\n const attachment = Attachment.attachmentForFile(file);\n attachments.push(attachment);\n }\n });\n return this.insertAttachments(attachments);\n }\n insertAttachment(attachment) {\n return this.insertAttachments([attachment]);\n }\n insertAttachments(attachments$1) {\n let text = new Text();\n Array.from(attachments$1).forEach(attachment => {\n var _config$attachments$t;\n const type = attachment.getType();\n const presentation = (_config$attachments$t = attachments[type]) === null || _config$attachments$t === void 0 ? void 0 : _config$attachments$t.presentation;\n const attributes = this.getCurrentTextAttributes();\n if (presentation) {\n attributes.presentation = presentation;\n }\n const attachmentText = Text.textForAttachmentWithAttributes(attachment, attributes);\n text = text.appendText(attachmentText);\n });\n return this.insertText(text);\n }\n shouldManageDeletingInDirection(direction) {\n const locationRange = this.getLocationRange();\n if (rangeIsCollapsed(locationRange)) {\n if (direction === \"backward\" && locationRange[0].offset === 0) {\n return true;\n }\n if (this.shouldManageMovingCursorInDirection(direction)) {\n return true;\n }\n } else {\n if (locationRange[0].index !== locationRange[1].index) {\n return true;\n }\n }\n return false;\n }\n deleteInDirection(direction) {\n let {\n length\n } = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};\n let attachment, deletingIntoPreviousBlock, selectionSpansBlocks;\n const locationRange = this.getLocationRange();\n let range = this.getSelectedRange();\n const selectionIsCollapsed = rangeIsCollapsed(range);\n if (selectionIsCollapsed) {\n deletingIntoPreviousBlock = direction === \"backward\" && locationRange[0].offset === 0;\n } else {\n selectionSpansBlocks = locationRange[0].index !== locationRange[1].index;\n }\n if (deletingIntoPreviousBlock) {\n if (this.canDecreaseBlockAttributeLevel()) {\n const block = this.getBlock();\n if (block.isListItem()) {\n this.decreaseListLevel();\n } else {\n this.decreaseBlockAttributeLevel();\n }\n this.setSelection(range[0]);\n if (block.isEmpty()) {\n return false;\n }\n }\n }\n if (selectionIsCollapsed) {\n range = this.getExpandedRangeInDirection(direction, {\n length\n });\n if (direction === \"backward\") {\n attachment = this.getAttachmentAtRange(range);\n }\n }\n if (attachment) {\n this.editAttachment(attachment);\n return false;\n } else {\n this.setDocument(this.document.removeTextAtRange(range));\n this.setSelection(range[0]);\n if (deletingIntoPreviousBlock || selectionSpansBlocks) {\n return false;\n }\n }\n }\n moveTextFromRange(range) {\n const [position] = Array.from(this.getSelectedRange());\n this.setDocument(this.document.moveTextFromRangeToPosition(range, position));\n return this.setSelection(position);\n }\n removeAttachment(attachment) {\n const range = this.document.getRangeOfAttachment(attachment);\n if (range) {\n this.stopEditingAttachment();\n this.setDocument(this.document.removeTextAtRange(range));\n return this.setSelection(range[0]);\n }\n }\n removeLastBlockAttribute() {\n const [startPosition, endPosition] = Array.from(this.getSelectedRange());\n const block = this.document.getBlockAtPosition(endPosition);\n this.removeCurrentAttribute(block.getLastAttribute());\n return this.setSelection(startPosition);\n }\n insertPlaceholder() {\n this.placeholderPosition = this.getPosition();\n return this.insertString(PLACEHOLDER);\n }\n selectPlaceholder() {\n if (this.placeholderPosition != null) {\n this.setSelectedRange([this.placeholderPosition, this.placeholderPosition + PLACEHOLDER.length]);\n return this.getSelectedRange();\n }\n }\n forgetPlaceholder() {\n this.placeholderPosition = null;\n }\n\n // Current attributes\n\n hasCurrentAttribute(attributeName) {\n const value = this.currentAttributes[attributeName];\n return value != null && value !== false;\n }\n toggleCurrentAttribute(attributeName) {\n const value = !this.currentAttributes[attributeName];\n if (value) {\n return this.setCurrentAttribute(attributeName, value);\n } else {\n return this.removeCurrentAttribute(attributeName);\n }\n }\n canSetCurrentAttribute(attributeName) {\n if (getBlockConfig(attributeName)) {\n return this.canSetCurrentBlockAttribute(attributeName);\n } else {\n return this.canSetCurrentTextAttribute(attributeName);\n }\n }\n canSetCurrentTextAttribute(attributeName) {\n const document = this.getSelectedDocument();\n if (!document) return;\n for (const attachment of Array.from(document.getAttachments())) {\n if (!attachment.hasContent()) {\n return false;\n }\n }\n return true;\n }\n canSetCurrentBlockAttribute(attributeName) {\n const block = this.getBlock();\n if (!block) return;\n return !block.isTerminalBlock();\n }\n setCurrentAttribute(attributeName, value) {\n if (getBlockConfig(attributeName)) {\n return this.setBlockAttribute(attributeName, value);\n } else {\n this.setTextAttribute(attributeName, value);\n this.currentAttributes[attributeName] = value;\n return this.notifyDelegateOfCurrentAttributesChange();\n }\n }\n setHTMLAtributeAtPosition(position, attributeName, value) {\n var _getBlockConfig;\n const block = this.document.getBlockAtPosition(position);\n const allowedHTMLAttributes = (_getBlockConfig = getBlockConfig(block.getLastAttribute())) === null || _getBlockConfig === void 0 ? void 0 : _getBlockConfig.htmlAttributes;\n if (block && allowedHTMLAttributes !== null && allowedHTMLAttributes !== void 0 && allowedHTMLAttributes.includes(attributeName)) {\n const newDocument = this.document.setHTMLAttributeAtPosition(position, attributeName, value);\n this.setDocument(newDocument);\n }\n }\n setTextAttribute(attributeName, value) {\n const selectedRange = this.getSelectedRange();\n if (!selectedRange) return;\n const [startPosition, endPosition] = Array.from(selectedRange);\n if (startPosition === endPosition) {\n if (attributeName === \"href\") {\n const text = Text.textForStringWithAttributes(value, {\n href: value\n });\n return this.insertText(text);\n }\n } else {\n return this.setDocument(this.document.addAttributeAtRange(attributeName, value, selectedRange));\n }\n }\n setBlockAttribute(attributeName, value) {\n const selectedRange = this.getSelectedRange();\n if (this.canSetCurrentAttribute(attributeName)) {\n this.setDocument(this.document.applyBlockAttributeAtRange(attributeName, value, selectedRange));\n return this.setSelection(selectedRange);\n }\n }\n removeCurrentAttribute(attributeName) {\n if (getBlockConfig(attributeName)) {\n this.removeBlockAttribute(attributeName);\n return this.updateCurrentAttributes();\n } else {\n this.removeTextAttribute(attributeName);\n delete this.currentAttributes[attributeName];\n return this.notifyDelegateOfCurrentAttributesChange();\n }\n }\n removeTextAttribute(attributeName) {\n const selectedRange = this.getSelectedRange();\n if (!selectedRange) return;\n return this.setDocument(this.document.removeAttributeAtRange(attributeName, selectedRange));\n }\n removeBlockAttribute(attributeName) {\n const selectedRange = this.getSelectedRange();\n if (!selectedRange) return;\n return this.setDocument(this.document.removeAttributeAtRange(attributeName, selectedRange));\n }\n canDecreaseNestingLevel() {\n var _this$getBlock;\n return ((_this$getBlock = this.getBlock()) === null || _this$getBlock === void 0 ? void 0 : _this$getBlock.getNestingLevel()) > 0;\n }\n canIncreaseNestingLevel() {\n var _getBlockConfig2;\n const block = this.getBlock();\n if (!block) return;\n if ((_getBlockConfig2 = getBlockConfig(block.getLastNestableAttribute())) !== null && _getBlockConfig2 !== void 0 && _getBlockConfig2.listAttribute) {\n const previousBlock = this.getPreviousBlock();\n if (previousBlock) {\n return arrayStartsWith(previousBlock.getListItemAttributes(), block.getListItemAttributes());\n }\n } else {\n return block.getNestingLevel() > 0;\n }\n }\n decreaseNestingLevel() {\n const block = this.getBlock();\n if (!block) return;\n return this.setDocument(this.document.replaceBlock(block, block.decreaseNestingLevel()));\n }\n increaseNestingLevel() {\n const block = this.getBlock();\n if (!block) return;\n return this.setDocument(this.document.replaceBlock(block, block.increaseNestingLevel()));\n }\n canDecreaseBlockAttributeLevel() {\n var _this$getBlock2;\n return ((_this$getBlock2 = this.getBlock()) === null || _this$getBlock2 === void 0 ? void 0 : _this$getBlock2.getAttributeLevel()) > 0;\n }\n decreaseBlockAttributeLevel() {\n var _this$getBlock3;\n const attribute = (_this$getBlock3 = this.getBlock()) === null || _this$getBlock3 === void 0 ? void 0 : _this$getBlock3.getLastAttribute();\n if (attribute) {\n return this.removeCurrentAttribute(attribute);\n }\n }\n decreaseListLevel() {\n let [startPosition] = Array.from(this.getSelectedRange());\n const {\n index\n } = this.document.locationFromPosition(startPosition);\n let endIndex = index;\n const attributeLevel = this.getBlock().getAttributeLevel();\n let block = this.document.getBlockAtIndex(endIndex + 1);\n while (block) {\n if (!block.isListItem() || block.getAttributeLevel() <= attributeLevel) {\n break;\n }\n endIndex++;\n block = this.document.getBlockAtIndex(endIndex + 1);\n }\n startPosition = this.document.positionFromLocation({\n index,\n offset: 0\n });\n const endPosition = this.document.positionFromLocation({\n index: endIndex,\n offset: 0\n });\n return this.setDocument(this.document.removeLastListAttributeAtRange([startPosition, endPosition]));\n }\n updateCurrentAttributes() {\n const selectedRange = this.getSelectedRange({\n ignoreLock: true\n });\n if (selectedRange) {\n const currentAttributes = this.document.getCommonAttributesAtRange(selectedRange);\n Array.from(getAllAttributeNames()).forEach(attributeName => {\n if (!currentAttributes[attributeName]) {\n if (!this.canSetCurrentAttribute(attributeName)) {\n currentAttributes[attributeName] = false;\n }\n }\n });\n if (!objectsAreEqual(currentAttributes, this.currentAttributes)) {\n this.currentAttributes = currentAttributes;\n return this.notifyDelegateOfCurrentAttributesChange();\n }\n }\n }\n getCurrentAttributes() {\n return extend.call({}, this.currentAttributes);\n }\n getCurrentTextAttributes() {\n const attributes = {};\n for (const key in this.currentAttributes) {\n const value = this.currentAttributes[key];\n if (value !== false) {\n if (getTextConfig(key)) {\n attributes[key] = value;\n }\n }\n }\n return attributes;\n }\n\n // Selection freezing\n\n freezeSelection() {\n return this.setCurrentAttribute(\"frozen\", true);\n }\n thawSelection() {\n return this.removeCurrentAttribute(\"frozen\");\n }\n hasFrozenSelection() {\n return this.hasCurrentAttribute(\"frozen\");\n }\n setSelection(selectedRange) {\n var _this$delegate5;\n const locationRange = this.document.locationRangeFromRange(selectedRange);\n return (_this$delegate5 = this.delegate) === null || _this$delegate5 === void 0 ? void 0 : _this$delegate5.compositionDidRequestChangingSelectionToLocationRange(locationRange);\n }\n getSelectedRange() {\n const locationRange = this.getLocationRange();\n if (locationRange) {\n return this.document.rangeFromLocationRange(locationRange);\n }\n }\n setSelectedRange(selectedRange) {\n const locationRange = this.document.locationRangeFromRange(selectedRange);\n return this.getSelectionManager().setLocationRange(locationRange);\n }\n getPosition() {\n const locationRange = this.getLocationRange();\n if (locationRange) {\n return this.document.positionFromLocation(locationRange[0]);\n }\n }\n getLocationRange(options) {\n if (this.targetLocationRange) {\n return this.targetLocationRange;\n } else {\n return this.getSelectionManager().getLocationRange(options) || normalizeRange({\n index: 0,\n offset: 0\n });\n }\n }\n withTargetLocationRange(locationRange, fn) {\n let result;\n this.targetLocationRange = locationRange;\n try {\n result = fn();\n } finally {\n this.targetLocationRange = null;\n }\n return result;\n }\n withTargetRange(range, fn) {\n const locationRange = this.document.locationRangeFromRange(range);\n return this.withTargetLocationRange(locationRange, fn);\n }\n withTargetDOMRange(domRange, fn) {\n const locationRange = this.createLocationRangeFromDOMRange(domRange, {\n strict: false\n });\n return this.withTargetLocationRange(locationRange, fn);\n }\n getExpandedRangeInDirection(direction) {\n let {\n length\n } = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};\n let [startPosition, endPosition] = Array.from(this.getSelectedRange());\n if (direction === \"backward\") {\n if (length) {\n startPosition -= length;\n } else {\n startPosition = this.translateUTF16PositionFromOffset(startPosition, -1);\n }\n } else {\n if (length) {\n endPosition += length;\n } else {\n endPosition = this.translateUTF16PositionFromOffset(endPosition, 1);\n }\n }\n return normalizeRange([startPosition, endPosition]);\n }\n shouldManageMovingCursorInDirection(direction) {\n if (this.editingAttachment) {\n return true;\n }\n const range = this.getExpandedRangeInDirection(direction);\n return this.getAttachmentAtRange(range) != null;\n }\n moveCursorInDirection(direction) {\n let canEditAttachment, range;\n if (this.editingAttachment) {\n range = this.document.getRangeOfAttachment(this.editingAttachment);\n } else {\n const selectedRange = this.getSelectedRange();\n range = this.getExpandedRangeInDirection(direction);\n canEditAttachment = !rangesAreEqual(selectedRange, range);\n }\n if (direction === \"backward\") {\n this.setSelectedRange(range[0]);\n } else {\n this.setSelectedRange(range[1]);\n }\n if (canEditAttachment) {\n const attachment = this.getAttachmentAtRange(range);\n if (attachment) {\n return this.editAttachment(attachment);\n }\n }\n }\n expandSelectionInDirection(direction) {\n let {\n length\n } = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};\n const range = this.getExpandedRangeInDirection(direction, {\n length\n });\n return this.setSelectedRange(range);\n }\n expandSelectionForEditing() {\n if (this.hasCurrentAttribute(\"href\")) {\n return this.expandSelectionAroundCommonAttribute(\"href\");\n }\n }\n expandSelectionAroundCommonAttribute(attributeName) {\n const position = this.getPosition();\n const range = this.document.getRangeOfCommonAttributeAtPosition(attributeName, position);\n return this.setSelectedRange(range);\n }\n selectionContainsAttachments() {\n var _this$getSelectedAtta;\n return ((_this$getSelectedAtta = this.getSelectedAttachments()) === null || _this$getSelectedAtta === void 0 ? void 0 : _this$getSelectedAtta.length) > 0;\n }\n selectionIsInCursorTarget() {\n return this.editingAttachment || this.positionIsCursorTarget(this.getPosition());\n }\n positionIsCursorTarget(position) {\n const location = this.document.locationFromPosition(position);\n if (location) {\n return this.locationIsCursorTarget(location);\n }\n }\n positionIsBlockBreak(position) {\n var _this$document$getPie;\n return (_this$document$getPie = this.document.getPieceAtPosition(position)) === null || _this$document$getPie === void 0 ? void 0 : _this$document$getPie.isBlockBreak();\n }\n getSelectedDocument() {\n const selectedRange = this.getSelectedRange();\n if (selectedRange) {\n return this.document.getDocumentAtRange(selectedRange);\n }\n }\n getSelectedAttachments() {\n var _this$getSelectedDocu;\n return (_this$getSelectedDocu = this.getSelectedDocument()) === null || _this$getSelectedDocu === void 0 ? void 0 : _this$getSelectedDocu.getAttachments();\n }\n\n // Attachments\n\n getAttachments() {\n return this.attachments.slice(0);\n }\n refreshAttachments() {\n const attachments = this.document.getAttachments();\n const {\n added,\n removed\n } = summarizeArrayChange(this.attachments, attachments);\n this.attachments = attachments;\n Array.from(removed).forEach(attachment => {\n var _this$delegate6, _this$delegate6$compo;\n attachment.delegate = null;\n (_this$delegate6 = this.delegate) === null || _this$delegate6 === void 0 || (_this$delegate6$compo = _this$delegate6.compositionDidRemoveAttachment) === null || _this$delegate6$compo === void 0 || _this$delegate6$compo.call(_this$delegate6, attachment);\n });\n return (() => {\n const result = [];\n Array.from(added).forEach(attachment => {\n var _this$delegate7, _this$delegate7$compo;\n attachment.delegate = this;\n result.push((_this$delegate7 = this.delegate) === null || _this$delegate7 === void 0 || (_this$delegate7$compo = _this$delegate7.compositionDidAddAttachment) === null || _this$delegate7$compo === void 0 ? void 0 : _this$delegate7$compo.call(_this$delegate7, attachment));\n });\n return result;\n })();\n }\n\n // Attachment delegate\n\n attachmentDidChangeAttributes(attachment) {\n var _this$delegate8, _this$delegate8$compo;\n this.revision++;\n return (_this$delegate8 = this.delegate) === null || _this$delegate8 === void 0 || (_this$delegate8$compo = _this$delegate8.compositionDidEditAttachment) === null || _this$delegate8$compo === void 0 ? void 0 : _this$delegate8$compo.call(_this$delegate8, attachment);\n }\n attachmentDidChangePreviewURL(attachment) {\n var _this$delegate9, _this$delegate9$compo;\n this.revision++;\n return (_this$delegate9 = this.delegate) === null || _this$delegate9 === void 0 || (_this$delegate9$compo = _this$delegate9.compositionDidChangeAttachmentPreviewURL) === null || _this$delegate9$compo === void 0 ? void 0 : _this$delegate9$compo.call(_this$delegate9, attachment);\n }\n\n // Attachment editing\n\n editAttachment(attachment, options) {\n var _this$delegate10, _this$delegate10$comp;\n if (attachment === this.editingAttachment) return;\n this.stopEditingAttachment();\n this.editingAttachment = attachment;\n return (_this$delegate10 = this.delegate) === null || _this$delegate10 === void 0 || (_this$delegate10$comp = _this$delegate10.compositionDidStartEditingAttachment) === null || _this$delegate10$comp === void 0 ? void 0 : _this$delegate10$comp.call(_this$delegate10, this.editingAttachment, options);\n }\n stopEditingAttachment() {\n var _this$delegate11, _this$delegate11$comp;\n if (!this.editingAttachment) return;\n (_this$delegate11 = this.delegate) === null || _this$delegate11 === void 0 || (_this$delegate11$comp = _this$delegate11.compositionDidStopEditingAttachment) === null || _this$delegate11$comp === void 0 || _this$delegate11$comp.call(_this$delegate11, this.editingAttachment);\n this.editingAttachment = null;\n }\n updateAttributesForAttachment(attributes, attachment) {\n return this.setDocument(this.document.updateAttributesForAttachment(attributes, attachment));\n }\n removeAttributeForAttachment(attribute, attachment) {\n return this.setDocument(this.document.removeAttributeForAttachment(attribute, attachment));\n }\n\n // Private\n\n breakFormattedBlock(insertion) {\n let {\n document\n } = insertion;\n const {\n block\n } = insertion;\n let position = insertion.startPosition;\n let range = [position - 1, position];\n if (block.getBlockBreakPosition() === insertion.startLocation.offset) {\n if (block.breaksOnReturn() && insertion.nextCharacter === \"\\n\") {\n position += 1;\n } else {\n document = document.removeTextAtRange(range);\n }\n range = [position, position];\n } else if (insertion.nextCharacter === \"\\n\") {\n if (insertion.previousCharacter === \"\\n\") {\n range = [position - 1, position + 1];\n } else {\n range = [position, position + 1];\n position += 1;\n }\n } else if (insertion.startLocation.offset - 1 !== 0) {\n position += 1;\n }\n const newDocument = new Document([block.removeLastAttribute().copyWithoutText()]);\n this.setDocument(document.insertDocumentAtRange(newDocument, range));\n return this.setSelection(position);\n }\n getPreviousBlock() {\n const locationRange = this.getLocationRange();\n if (locationRange) {\n const {\n index\n } = locationRange[0];\n if (index > 0) {\n return this.document.getBlockAtIndex(index - 1);\n }\n }\n }\n getBlock() {\n const locationRange = this.getLocationRange();\n if (locationRange) {\n return this.document.getBlockAtIndex(locationRange[0].index);\n }\n }\n getAttachmentAtRange(range) {\n const document = this.document.getDocumentAtRange(range);\n if (document.toString() === \"\".concat(OBJECT_REPLACEMENT_CHARACTER, \"\\n\")) {\n return document.getAttachments()[0];\n }\n }\n notifyDelegateOfCurrentAttributesChange() {\n var _this$delegate12, _this$delegate12$comp;\n return (_this$delegate12 = this.delegate) === null || _this$delegate12 === void 0 || (_this$delegate12$comp = _this$delegate12.compositionDidChangeCurrentAttributes) === null || _this$delegate12$comp === void 0 ? void 0 : _this$delegate12$comp.call(_this$delegate12, this.currentAttributes);\n }\n notifyDelegateOfInsertionAtRange(range) {\n var _this$delegate13, _this$delegate13$comp;\n return (_this$delegate13 = this.delegate) === null || _this$delegate13 === void 0 || (_this$delegate13$comp = _this$delegate13.compositionDidPerformInsertionAtRange) === null || _this$delegate13$comp === void 0 ? void 0 : _this$delegate13$comp.call(_this$delegate13, range);\n }\n translateUTF16PositionFromOffset(position, offset) {\n const utf16string = this.document.toUTF16String();\n const utf16position = utf16string.offsetFromUCS2Offset(position);\n return utf16string.offsetToUCS2Offset(utf16position + offset);\n }\n }\n Composition.proxyMethod(\"getSelectionManager().getPointRange\");\n Composition.proxyMethod(\"getSelectionManager().setLocationRangeFromPointRange\");\n Composition.proxyMethod(\"getSelectionManager().createLocationRangeFromDOMRange\");\n Composition.proxyMethod(\"getSelectionManager().locationIsCursorTarget\");\n Composition.proxyMethod(\"getSelectionManager().selectionIsExpanded\");\n Composition.proxyMethod(\"delegate?.getSelectionManager\");\n\n class UndoManager extends BasicObject {\n constructor(composition) {\n super(...arguments);\n this.composition = composition;\n this.undoEntries = [];\n this.redoEntries = [];\n }\n recordUndoEntry(description) {\n let {\n context,\n consolidatable\n } = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};\n const previousEntry = this.undoEntries.slice(-1)[0];\n if (!consolidatable || !entryHasDescriptionAndContext(previousEntry, description, context)) {\n const undoEntry = this.createEntry({\n description,\n context\n });\n this.undoEntries.push(undoEntry);\n this.redoEntries = [];\n }\n }\n undo() {\n const undoEntry = this.undoEntries.pop();\n if (undoEntry) {\n const redoEntry = this.createEntry(undoEntry);\n this.redoEntries.push(redoEntry);\n return this.composition.loadSnapshot(undoEntry.snapshot);\n }\n }\n redo() {\n const redoEntry = this.redoEntries.pop();\n if (redoEntry) {\n const undoEntry = this.createEntry(redoEntry);\n this.undoEntries.push(undoEntry);\n return this.composition.loadSnapshot(redoEntry.snapshot);\n }\n }\n canUndo() {\n return this.undoEntries.length > 0;\n }\n canRedo() {\n return this.redoEntries.length > 0;\n }\n\n // Private\n\n createEntry() {\n let {\n description,\n context\n } = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};\n return {\n description: description === null || description === void 0 ? void 0 : description.toString(),\n context: JSON.stringify(context),\n snapshot: this.composition.getSnapshot()\n };\n }\n }\n const entryHasDescriptionAndContext = (entry, description, context) => (entry === null || entry === void 0 ? void 0 : entry.description) === (description === null || description === void 0 ? void 0 : description.toString()) && (entry === null || entry === void 0 ? void 0 : entry.context) === JSON.stringify(context);\n\n const BLOCK_ATTRIBUTE_NAME = \"attachmentGallery\";\n const TEXT_ATTRIBUTE_NAME = \"presentation\";\n const TEXT_ATTRIBUTE_VALUE = \"gallery\";\n class Filter {\n constructor(snapshot) {\n this.document = snapshot.document;\n this.selectedRange = snapshot.selectedRange;\n }\n perform() {\n this.removeBlockAttribute();\n return this.applyBlockAttribute();\n }\n getSnapshot() {\n return {\n document: this.document,\n selectedRange: this.selectedRange\n };\n }\n\n // Private\n\n removeBlockAttribute() {\n return this.findRangesOfBlocks().map(range => this.document = this.document.removeAttributeAtRange(BLOCK_ATTRIBUTE_NAME, range));\n }\n applyBlockAttribute() {\n let offset = 0;\n this.findRangesOfPieces().forEach(range => {\n if (range[1] - range[0] > 1) {\n range[0] += offset;\n range[1] += offset;\n if (this.document.getCharacterAtPosition(range[1]) !== \"\\n\") {\n this.document = this.document.insertBlockBreakAtRange(range[1]);\n if (range[1] < this.selectedRange[1]) {\n this.moveSelectedRangeForward();\n }\n range[1]++;\n offset++;\n }\n if (range[0] !== 0) {\n if (this.document.getCharacterAtPosition(range[0] - 1) !== \"\\n\") {\n this.document = this.document.insertBlockBreakAtRange(range[0]);\n if (range[0] < this.selectedRange[0]) {\n this.moveSelectedRangeForward();\n }\n range[0]++;\n offset++;\n }\n }\n this.document = this.document.applyBlockAttributeAtRange(BLOCK_ATTRIBUTE_NAME, true, range);\n }\n });\n }\n findRangesOfBlocks() {\n return this.document.findRangesForBlockAttribute(BLOCK_ATTRIBUTE_NAME);\n }\n findRangesOfPieces() {\n return this.document.findRangesForTextAttribute(TEXT_ATTRIBUTE_NAME, {\n withValue: TEXT_ATTRIBUTE_VALUE\n });\n }\n moveSelectedRangeForward() {\n this.selectedRange[0] += 1;\n this.selectedRange[1] += 1;\n }\n }\n\n const attachmentGalleryFilter = function (snapshot) {\n const filter = new Filter(snapshot);\n filter.perform();\n return filter.getSnapshot();\n };\n\n const DEFAULT_FILTERS = [attachmentGalleryFilter];\n class Editor {\n constructor(composition, selectionManager, element) {\n this.insertFiles = this.insertFiles.bind(this);\n this.composition = composition;\n this.selectionManager = selectionManager;\n this.element = element;\n this.undoManager = new UndoManager(this.composition);\n this.filters = DEFAULT_FILTERS.slice(0);\n }\n loadDocument(document) {\n return this.loadSnapshot({\n document,\n selectedRange: [0, 0]\n });\n }\n loadHTML() {\n let html = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : \"\";\n const document = HTMLParser.parse(html, {\n referenceElement: this.element\n }).getDocument();\n return this.loadDocument(document);\n }\n loadJSON(_ref) {\n let {\n document,\n selectedRange\n } = _ref;\n document = Document.fromJSON(document);\n return this.loadSnapshot({\n document,\n selectedRange\n });\n }\n loadSnapshot(snapshot) {\n this.undoManager = new UndoManager(this.composition);\n return this.composition.loadSnapshot(snapshot);\n }\n getDocument() {\n return this.composition.document;\n }\n getSelectedDocument() {\n return this.composition.getSelectedDocument();\n }\n getSnapshot() {\n return this.composition.getSnapshot();\n }\n toJSON() {\n return this.getSnapshot();\n }\n\n // Document manipulation\n\n deleteInDirection(direction) {\n return this.composition.deleteInDirection(direction);\n }\n insertAttachment(attachment) {\n return this.composition.insertAttachment(attachment);\n }\n insertAttachments(attachments) {\n return this.composition.insertAttachments(attachments);\n }\n insertDocument(document) {\n return this.composition.insertDocument(document);\n }\n insertFile(file) {\n return this.composition.insertFile(file);\n }\n insertFiles(files) {\n return this.composition.insertFiles(files);\n }\n insertHTML(html) {\n return this.composition.insertHTML(html);\n }\n insertString(string) {\n return this.composition.insertString(string);\n }\n insertText(text) {\n return this.composition.insertText(text);\n }\n insertLineBreak() {\n return this.composition.insertLineBreak();\n }\n\n // Selection\n\n getSelectedRange() {\n return this.composition.getSelectedRange();\n }\n getPosition() {\n return this.composition.getPosition();\n }\n getClientRectAtPosition(position) {\n const locationRange = this.getDocument().locationRangeFromRange([position, position + 1]);\n return this.selectionManager.getClientRectAtLocationRange(locationRange);\n }\n expandSelectionInDirection(direction) {\n return this.composition.expandSelectionInDirection(direction);\n }\n moveCursorInDirection(direction) {\n return this.composition.moveCursorInDirection(direction);\n }\n setSelectedRange(selectedRange) {\n return this.composition.setSelectedRange(selectedRange);\n }\n\n // Attributes\n\n activateAttribute(name) {\n let value = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;\n return this.composition.setCurrentAttribute(name, value);\n }\n attributeIsActive(name) {\n return this.composition.hasCurrentAttribute(name);\n }\n canActivateAttribute(name) {\n return this.composition.canSetCurrentAttribute(name);\n }\n deactivateAttribute(name) {\n return this.composition.removeCurrentAttribute(name);\n }\n\n // HTML attributes\n setHTMLAtributeAtPosition(position, name, value) {\n this.composition.setHTMLAtributeAtPosition(position, name, value);\n }\n\n // Nesting level\n\n canDecreaseNestingLevel() {\n return this.composition.canDecreaseNestingLevel();\n }\n canIncreaseNestingLevel() {\n return this.composition.canIncreaseNestingLevel();\n }\n decreaseNestingLevel() {\n if (this.canDecreaseNestingLevel()) {\n return this.composition.decreaseNestingLevel();\n }\n }\n increaseNestingLevel() {\n if (this.canIncreaseNestingLevel()) {\n return this.composition.increaseNestingLevel();\n }\n }\n\n // Undo/redo\n\n canRedo() {\n return this.undoManager.canRedo();\n }\n canUndo() {\n return this.undoManager.canUndo();\n }\n recordUndoEntry(description) {\n let {\n context,\n consolidatable\n } = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};\n return this.undoManager.recordUndoEntry(description, {\n context,\n consolidatable\n });\n }\n redo() {\n if (this.canRedo()) {\n return this.undoManager.redo();\n }\n }\n undo() {\n if (this.canUndo()) {\n return this.undoManager.undo();\n }\n }\n }\n\n /* eslint-disable\n no-var,\n prefer-const,\n */\n class LocationMapper {\n constructor(element) {\n this.element = element;\n }\n findLocationFromContainerAndOffset(container, offset) {\n let {\n strict\n } = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {\n strict: true\n };\n let childIndex = 0;\n let foundBlock = false;\n const location = {\n index: 0,\n offset: 0\n };\n const attachmentElement = this.findAttachmentElementParentForNode(container);\n if (attachmentElement) {\n container = attachmentElement.parentNode;\n offset = findChildIndexOfNode(attachmentElement);\n }\n const walker = walkTree(this.element, {\n usingFilter: rejectAttachmentContents\n });\n while (walker.nextNode()) {\n const node = walker.currentNode;\n if (node === container && nodeIsTextNode(container)) {\n if (!nodeIsCursorTarget(node)) {\n location.offset += offset;\n }\n break;\n } else {\n if (node.parentNode === container) {\n if (childIndex++ === offset) {\n break;\n }\n } else if (!elementContainsNode(container, node)) {\n if (childIndex > 0) {\n break;\n }\n }\n if (nodeIsBlockStart(node, {\n strict\n })) {\n if (foundBlock) {\n location.index++;\n }\n location.offset = 0;\n foundBlock = true;\n } else {\n location.offset += nodeLength(node);\n }\n }\n }\n return location;\n }\n findContainerAndOffsetFromLocation(location) {\n let container, offset;\n if (location.index === 0 && location.offset === 0) {\n container = this.element;\n offset = 0;\n while (container.firstChild) {\n container = container.firstChild;\n if (nodeIsBlockContainer(container)) {\n offset = 1;\n break;\n }\n }\n return [container, offset];\n }\n let [node, nodeOffset] = this.findNodeAndOffsetFromLocation(location);\n if (!node) return;\n if (nodeIsTextNode(node)) {\n if (nodeLength(node) === 0) {\n container = node.parentNode.parentNode;\n offset = findChildIndexOfNode(node.parentNode);\n if (nodeIsCursorTarget(node, {\n name: \"right\"\n })) {\n offset++;\n }\n } else {\n container = node;\n offset = location.offset - nodeOffset;\n }\n } else {\n container = node.parentNode;\n if (!nodeIsBlockStart(node.previousSibling)) {\n if (!nodeIsBlockContainer(container)) {\n while (node === container.lastChild) {\n node = container;\n container = container.parentNode;\n if (nodeIsBlockContainer(container)) {\n break;\n }\n }\n }\n }\n offset = findChildIndexOfNode(node);\n if (location.offset !== 0) {\n offset++;\n }\n }\n return [container, offset];\n }\n findNodeAndOffsetFromLocation(location) {\n let node, nodeOffset;\n let offset = 0;\n for (const currentNode of this.getSignificantNodesForIndex(location.index)) {\n const length = nodeLength(currentNode);\n if (location.offset <= offset + length) {\n if (nodeIsTextNode(currentNode)) {\n node = currentNode;\n nodeOffset = offset;\n if (location.offset === nodeOffset && nodeIsCursorTarget(node)) {\n break;\n }\n } else if (!node) {\n node = currentNode;\n nodeOffset = offset;\n }\n }\n offset += length;\n if (offset > location.offset) {\n break;\n }\n }\n return [node, nodeOffset];\n }\n\n // Private\n\n findAttachmentElementParentForNode(node) {\n while (node && node !== this.element) {\n if (nodeIsAttachmentElement(node)) {\n return node;\n }\n node = node.parentNode;\n }\n }\n getSignificantNodesForIndex(index) {\n const nodes = [];\n const walker = walkTree(this.element, {\n usingFilter: acceptSignificantNodes\n });\n let recordingNodes = false;\n while (walker.nextNode()) {\n const node = walker.currentNode;\n if (nodeIsBlockStartComment(node)) {\n var blockIndex;\n if (blockIndex != null) {\n blockIndex++;\n } else {\n blockIndex = 0;\n }\n if (blockIndex === index) {\n recordingNodes = true;\n } else if (recordingNodes) {\n break;\n }\n } else if (recordingNodes) {\n nodes.push(node);\n }\n }\n return nodes;\n }\n }\n const nodeLength = function (node) {\n if (node.nodeType === Node.TEXT_NODE) {\n if (nodeIsCursorTarget(node)) {\n return 0;\n } else {\n const string = node.textContent;\n return string.length;\n }\n } else if (tagName(node) === \"br\" || nodeIsAttachmentElement(node)) {\n return 1;\n } else {\n return 0;\n }\n };\n const acceptSignificantNodes = function (node) {\n if (rejectEmptyTextNodes(node) === NodeFilter.FILTER_ACCEPT) {\n return rejectAttachmentContents(node);\n } else {\n return NodeFilter.FILTER_REJECT;\n }\n };\n const rejectEmptyTextNodes = function (node) {\n if (nodeIsEmptyTextNode(node)) {\n return NodeFilter.FILTER_REJECT;\n } else {\n return NodeFilter.FILTER_ACCEPT;\n }\n };\n const rejectAttachmentContents = function (node) {\n if (nodeIsAttachmentElement(node.parentNode)) {\n return NodeFilter.FILTER_REJECT;\n } else {\n return NodeFilter.FILTER_ACCEPT;\n }\n };\n\n /* eslint-disable\n id-length,\n no-empty,\n */\n class PointMapper {\n createDOMRangeFromPoint(_ref) {\n let {\n x,\n y\n } = _ref;\n let domRange;\n if (document.caretPositionFromPoint) {\n const {\n offsetNode,\n offset\n } = document.caretPositionFromPoint(x, y);\n domRange = document.createRange();\n domRange.setStart(offsetNode, offset);\n return domRange;\n } else if (document.caretRangeFromPoint) {\n return document.caretRangeFromPoint(x, y);\n } else if (document.body.createTextRange) {\n const originalDOMRange = getDOMRange();\n try {\n // IE 11 throws \"Unspecified error\" when using moveToPoint\n // during a drag-and-drop operation.\n const textRange = document.body.createTextRange();\n textRange.moveToPoint(x, y);\n textRange.select();\n } catch (error) {}\n domRange = getDOMRange();\n setDOMRange(originalDOMRange);\n return domRange;\n }\n }\n getClientRectsForDOMRange(domRange) {\n const array = Array.from(domRange.getClientRects());\n const start = array[0];\n const end = array[array.length - 1];\n return [start, end];\n }\n }\n\n /* eslint-disable\n */\n class SelectionManager extends BasicObject {\n constructor(element) {\n super(...arguments);\n this.didMouseDown = this.didMouseDown.bind(this);\n this.selectionDidChange = this.selectionDidChange.bind(this);\n this.element = element;\n this.locationMapper = new LocationMapper(this.element);\n this.pointMapper = new PointMapper();\n this.lockCount = 0;\n handleEvent(\"mousedown\", {\n onElement: this.element,\n withCallback: this.didMouseDown\n });\n }\n getLocationRange() {\n let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};\n if (options.strict === false) {\n return this.createLocationRangeFromDOMRange(getDOMRange());\n } else if (options.ignoreLock) {\n return this.currentLocationRange;\n } else if (this.lockedLocationRange) {\n return this.lockedLocationRange;\n } else {\n return this.currentLocationRange;\n }\n }\n setLocationRange(locationRange) {\n if (this.lockedLocationRange) return;\n locationRange = normalizeRange(locationRange);\n const domRange = this.createDOMRangeFromLocationRange(locationRange);\n if (domRange) {\n setDOMRange(domRange);\n this.updateCurrentLocationRange(locationRange);\n }\n }\n setLocationRangeFromPointRange(pointRange) {\n pointRange = normalizeRange(pointRange);\n const startLocation = this.getLocationAtPoint(pointRange[0]);\n const endLocation = this.getLocationAtPoint(pointRange[1]);\n this.setLocationRange([startLocation, endLocation]);\n }\n getClientRectAtLocationRange(locationRange) {\n const domRange = this.createDOMRangeFromLocationRange(locationRange);\n if (domRange) {\n return this.getClientRectsForDOMRange(domRange)[1];\n }\n }\n locationIsCursorTarget(location) {\n const node = Array.from(this.findNodeAndOffsetFromLocation(location))[0];\n return nodeIsCursorTarget(node);\n }\n lock() {\n if (this.lockCount++ === 0) {\n this.updateCurrentLocationRange();\n this.lockedLocationRange = this.getLocationRange();\n }\n }\n unlock() {\n if (--this.lockCount === 0) {\n const {\n lockedLocationRange\n } = this;\n this.lockedLocationRange = null;\n if (lockedLocationRange != null) {\n return this.setLocationRange(lockedLocationRange);\n }\n }\n }\n clearSelection() {\n var _getDOMSelection;\n return (_getDOMSelection = getDOMSelection()) === null || _getDOMSelection === void 0 ? void 0 : _getDOMSelection.removeAllRanges();\n }\n selectionIsCollapsed() {\n var _getDOMRange;\n return ((_getDOMRange = getDOMRange()) === null || _getDOMRange === void 0 ? void 0 : _getDOMRange.collapsed) === true;\n }\n selectionIsExpanded() {\n return !this.selectionIsCollapsed();\n }\n createLocationRangeFromDOMRange(domRange, options) {\n if (domRange == null || !this.domRangeWithinElement(domRange)) return;\n const start = this.findLocationFromContainerAndOffset(domRange.startContainer, domRange.startOffset, options);\n if (!start) return;\n const end = domRange.collapsed ? undefined : this.findLocationFromContainerAndOffset(domRange.endContainer, domRange.endOffset, options);\n return normalizeRange([start, end]);\n }\n didMouseDown() {\n return this.pauseTemporarily();\n }\n pauseTemporarily() {\n let resumeHandlers;\n this.paused = true;\n const resume = () => {\n this.paused = false;\n clearTimeout(resumeTimeout);\n Array.from(resumeHandlers).forEach(handler => {\n handler.destroy();\n });\n if (elementContainsNode(document, this.element)) {\n return this.selectionDidChange();\n }\n };\n const resumeTimeout = setTimeout(resume, 200);\n resumeHandlers = [\"mousemove\", \"keydown\"].map(eventName => handleEvent(eventName, {\n onElement: document,\n withCallback: resume\n }));\n }\n selectionDidChange() {\n if (!this.paused && !innerElementIsActive(this.element)) {\n return this.updateCurrentLocationRange();\n }\n }\n updateCurrentLocationRange(locationRange) {\n if (locationRange != null ? locationRange : locationRange = this.createLocationRangeFromDOMRange(getDOMRange())) {\n if (!rangesAreEqual(locationRange, this.currentLocationRange)) {\n var _this$delegate, _this$delegate$locati;\n this.currentLocationRange = locationRange;\n return (_this$delegate = this.delegate) === null || _this$delegate === void 0 || (_this$delegate$locati = _this$delegate.locationRangeDidChange) === null || _this$delegate$locati === void 0 ? void 0 : _this$delegate$locati.call(_this$delegate, this.currentLocationRange.slice(0));\n }\n }\n }\n createDOMRangeFromLocationRange(locationRange) {\n const rangeStart = this.findContainerAndOffsetFromLocation(locationRange[0]);\n const rangeEnd = rangeIsCollapsed(locationRange) ? rangeStart : this.findContainerAndOffsetFromLocation(locationRange[1]) || rangeStart;\n if (rangeStart != null && rangeEnd != null) {\n const domRange = document.createRange();\n domRange.setStart(...Array.from(rangeStart || []));\n domRange.setEnd(...Array.from(rangeEnd || []));\n return domRange;\n }\n }\n getLocationAtPoint(point) {\n const domRange = this.createDOMRangeFromPoint(point);\n if (domRange) {\n var _this$createLocationR;\n return (_this$createLocationR = this.createLocationRangeFromDOMRange(domRange)) === null || _this$createLocationR === void 0 ? void 0 : _this$createLocationR[0];\n }\n }\n domRangeWithinElement(domRange) {\n if (domRange.collapsed) {\n return elementContainsNode(this.element, domRange.startContainer);\n } else {\n return elementContainsNode(this.element, domRange.startContainer) && elementContainsNode(this.element, domRange.endContainer);\n }\n }\n }\n SelectionManager.proxyMethod(\"locationMapper.findLocationFromContainerAndOffset\");\n SelectionManager.proxyMethod(\"locationMapper.findContainerAndOffsetFromLocation\");\n SelectionManager.proxyMethod(\"locationMapper.findNodeAndOffsetFromLocation\");\n SelectionManager.proxyMethod(\"pointMapper.createDOMRangeFromPoint\");\n SelectionManager.proxyMethod(\"pointMapper.getClientRectsForDOMRange\");\n\n var models = /*#__PURE__*/Object.freeze({\n __proto__: null,\n Attachment: Attachment,\n AttachmentManager: AttachmentManager,\n AttachmentPiece: AttachmentPiece,\n Block: Block,\n Composition: Composition,\n Document: Document,\n Editor: Editor,\n HTMLParser: HTMLParser,\n HTMLSanitizer: HTMLSanitizer,\n LineBreakInsertion: LineBreakInsertion,\n LocationMapper: LocationMapper,\n ManagedAttachment: ManagedAttachment,\n Piece: Piece,\n PointMapper: PointMapper,\n SelectionManager: SelectionManager,\n SplittableList: SplittableList,\n StringPiece: StringPiece,\n Text: Text,\n UndoManager: UndoManager\n });\n\n var views = /*#__PURE__*/Object.freeze({\n __proto__: null,\n ObjectView: ObjectView,\n AttachmentView: AttachmentView,\n BlockView: BlockView,\n DocumentView: DocumentView,\n PieceView: PieceView,\n PreviewableAttachmentView: PreviewableAttachmentView,\n TextView: TextView\n });\n\n const {\n lang,\n css,\n keyNames: keyNames$1\n } = config;\n const undoable = function (fn) {\n return function () {\n const commands = fn.apply(this, arguments);\n commands.do();\n if (!this.undos) {\n this.undos = [];\n }\n this.undos.push(commands.undo);\n };\n };\n class AttachmentEditorController extends BasicObject {\n constructor(attachmentPiece, _element, container) {\n let options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};\n super(...arguments);\n // Installing and uninstalling\n _defineProperty(this, \"makeElementMutable\", undoable(() => {\n return {\n do: () => {\n this.element.dataset.trixMutable = true;\n },\n undo: () => delete this.element.dataset.trixMutable\n };\n }));\n _defineProperty(this, \"addToolbar\", undoable(() => {\n //
\n //
\n // \n // \n // \n //
\n //
\n const element = makeElement({\n tagName: \"div\",\n className: css.attachmentToolbar,\n data: {\n trixMutable: true\n },\n childNodes: makeElement({\n tagName: \"div\",\n className: \"trix-button-row\",\n childNodes: makeElement({\n tagName: \"span\",\n className: \"trix-button-group trix-button-group--actions\",\n childNodes: makeElement({\n tagName: \"button\",\n className: \"trix-button trix-button--remove\",\n textContent: lang.remove,\n attributes: {\n title: lang.remove\n },\n data: {\n trixAction: \"remove\"\n }\n })\n })\n })\n });\n if (this.attachment.isPreviewable()) {\n //
\n // \n // #{name}\n // #{size}\n // \n //
\n element.appendChild(makeElement({\n tagName: \"div\",\n className: css.attachmentMetadataContainer,\n childNodes: makeElement({\n tagName: \"span\",\n className: css.attachmentMetadata,\n childNodes: [makeElement({\n tagName: \"span\",\n className: css.attachmentName,\n textContent: this.attachment.getFilename(),\n attributes: {\n title: this.attachment.getFilename()\n }\n }), makeElement({\n tagName: \"span\",\n className: css.attachmentSize,\n textContent: this.attachment.getFormattedFilesize()\n })]\n })\n }));\n }\n handleEvent(\"click\", {\n onElement: element,\n withCallback: this.didClickToolbar\n });\n handleEvent(\"click\", {\n onElement: element,\n matchingSelector: \"[data-trix-action]\",\n withCallback: this.didClickActionButton\n });\n triggerEvent(\"trix-attachment-before-toolbar\", {\n onElement: this.element,\n attributes: {\n toolbar: element,\n attachment: this.attachment\n }\n });\n return {\n do: () => this.element.appendChild(element),\n undo: () => removeNode(element)\n };\n }));\n _defineProperty(this, \"installCaptionEditor\", undoable(() => {\n const textarea = makeElement({\n tagName: \"textarea\",\n className: css.attachmentCaptionEditor,\n attributes: {\n placeholder: lang.captionPlaceholder\n },\n data: {\n trixMutable: true\n }\n });\n textarea.value = this.attachmentPiece.getCaption();\n const textareaClone = textarea.cloneNode();\n textareaClone.classList.add(\"trix-autoresize-clone\");\n textareaClone.tabIndex = -1;\n const autoresize = function () {\n textareaClone.value = textarea.value;\n textarea.style.height = textareaClone.scrollHeight + \"px\";\n };\n handleEvent(\"input\", {\n onElement: textarea,\n withCallback: autoresize\n });\n handleEvent(\"input\", {\n onElement: textarea,\n withCallback: this.didInputCaption\n });\n handleEvent(\"keydown\", {\n onElement: textarea,\n withCallback: this.didKeyDownCaption\n });\n handleEvent(\"change\", {\n onElement: textarea,\n withCallback: this.didChangeCaption\n });\n handleEvent(\"blur\", {\n onElement: textarea,\n withCallback: this.didBlurCaption\n });\n const figcaption = this.element.querySelector(\"figcaption\");\n const editingFigcaption = figcaption.cloneNode();\n return {\n do: () => {\n figcaption.style.display = \"none\";\n editingFigcaption.appendChild(textarea);\n editingFigcaption.appendChild(textareaClone);\n editingFigcaption.classList.add(\"\".concat(css.attachmentCaption, \"--editing\"));\n figcaption.parentElement.insertBefore(editingFigcaption, figcaption);\n autoresize();\n if (this.options.editCaption) {\n return defer(() => textarea.focus());\n }\n },\n undo() {\n removeNode(editingFigcaption);\n figcaption.style.display = null;\n }\n };\n }));\n this.didClickToolbar = this.didClickToolbar.bind(this);\n this.didClickActionButton = this.didClickActionButton.bind(this);\n this.didKeyDownCaption = this.didKeyDownCaption.bind(this);\n this.didInputCaption = this.didInputCaption.bind(this);\n this.didChangeCaption = this.didChangeCaption.bind(this);\n this.didBlurCaption = this.didBlurCaption.bind(this);\n this.attachmentPiece = attachmentPiece;\n this.element = _element;\n this.container = container;\n this.options = options;\n this.attachment = this.attachmentPiece.attachment;\n if (tagName(this.element) === \"a\") {\n this.element = this.element.firstChild;\n }\n this.install();\n }\n install() {\n this.makeElementMutable();\n this.addToolbar();\n if (this.attachment.isPreviewable()) {\n this.installCaptionEditor();\n }\n }\n uninstall() {\n var _this$delegate;\n let undo = this.undos.pop();\n this.savePendingCaption();\n while (undo) {\n undo();\n undo = this.undos.pop();\n }\n (_this$delegate = this.delegate) === null || _this$delegate === void 0 || _this$delegate.didUninstallAttachmentEditor(this);\n }\n\n // Private\n\n savePendingCaption() {\n if (this.pendingCaption != null) {\n const caption = this.pendingCaption;\n this.pendingCaption = null;\n if (caption) {\n var _this$delegate2, _this$delegate2$attac;\n (_this$delegate2 = this.delegate) === null || _this$delegate2 === void 0 || (_this$delegate2$attac = _this$delegate2.attachmentEditorDidRequestUpdatingAttributesForAttachment) === null || _this$delegate2$attac === void 0 || _this$delegate2$attac.call(_this$delegate2, {\n caption\n }, this.attachment);\n } else {\n var _this$delegate3, _this$delegate3$attac;\n (_this$delegate3 = this.delegate) === null || _this$delegate3 === void 0 || (_this$delegate3$attac = _this$delegate3.attachmentEditorDidRequestRemovingAttributeForAttachment) === null || _this$delegate3$attac === void 0 || _this$delegate3$attac.call(_this$delegate3, \"caption\", this.attachment);\n }\n }\n }\n // Event handlers\n\n didClickToolbar(event) {\n event.preventDefault();\n return event.stopPropagation();\n }\n didClickActionButton(event) {\n var _this$delegate4;\n const action = event.target.getAttribute(\"data-trix-action\");\n switch (action) {\n case \"remove\":\n return (_this$delegate4 = this.delegate) === null || _this$delegate4 === void 0 ? void 0 : _this$delegate4.attachmentEditorDidRequestRemovalOfAttachment(this.attachment);\n }\n }\n didKeyDownCaption(event) {\n if (keyNames$1[event.keyCode] === \"return\") {\n var _this$delegate5, _this$delegate5$attac;\n event.preventDefault();\n this.savePendingCaption();\n return (_this$delegate5 = this.delegate) === null || _this$delegate5 === void 0 || (_this$delegate5$attac = _this$delegate5.attachmentEditorDidRequestDeselectingAttachment) === null || _this$delegate5$attac === void 0 ? void 0 : _this$delegate5$attac.call(_this$delegate5, this.attachment);\n }\n }\n didInputCaption(event) {\n this.pendingCaption = event.target.value.replace(/\\s/g, \" \").trim();\n }\n didChangeCaption(event) {\n return this.savePendingCaption();\n }\n didBlurCaption(event) {\n return this.savePendingCaption();\n }\n }\n\n class CompositionController extends BasicObject {\n constructor(element, composition) {\n super(...arguments);\n this.didFocus = this.didFocus.bind(this);\n this.didBlur = this.didBlur.bind(this);\n this.didClickAttachment = this.didClickAttachment.bind(this);\n this.element = element;\n this.composition = composition;\n this.documentView = new DocumentView(this.composition.document, {\n element: this.element\n });\n handleEvent(\"focus\", {\n onElement: this.element,\n withCallback: this.didFocus\n });\n handleEvent(\"blur\", {\n onElement: this.element,\n withCallback: this.didBlur\n });\n handleEvent(\"click\", {\n onElement: this.element,\n matchingSelector: \"a[contenteditable=false]\",\n preventDefault: true\n });\n handleEvent(\"mousedown\", {\n onElement: this.element,\n matchingSelector: attachmentSelector,\n withCallback: this.didClickAttachment\n });\n handleEvent(\"click\", {\n onElement: this.element,\n matchingSelector: \"a\".concat(attachmentSelector),\n preventDefault: true\n });\n }\n didFocus(event) {\n var _this$blurPromise;\n const perform = () => {\n if (!this.focused) {\n var _this$delegate, _this$delegate$compos;\n this.focused = true;\n return (_this$delegate = this.delegate) === null || _this$delegate === void 0 || (_this$delegate$compos = _this$delegate.compositionControllerDidFocus) === null || _this$delegate$compos === void 0 ? void 0 : _this$delegate$compos.call(_this$delegate);\n }\n };\n return ((_this$blurPromise = this.blurPromise) === null || _this$blurPromise === void 0 ? void 0 : _this$blurPromise.then(perform)) || perform();\n }\n didBlur(event) {\n this.blurPromise = new Promise(resolve => {\n return defer(() => {\n if (!innerElementIsActive(this.element)) {\n var _this$delegate2, _this$delegate2$compo;\n this.focused = null;\n (_this$delegate2 = this.delegate) === null || _this$delegate2 === void 0 || (_this$delegate2$compo = _this$delegate2.compositionControllerDidBlur) === null || _this$delegate2$compo === void 0 || _this$delegate2$compo.call(_this$delegate2);\n }\n this.blurPromise = null;\n return resolve();\n });\n });\n }\n didClickAttachment(event, target) {\n var _this$delegate3, _this$delegate3$compo;\n const attachment = this.findAttachmentForElement(target);\n const editCaption = !!findClosestElementFromNode(event.target, {\n matchingSelector: \"figcaption\"\n });\n return (_this$delegate3 = this.delegate) === null || _this$delegate3 === void 0 || (_this$delegate3$compo = _this$delegate3.compositionControllerDidSelectAttachment) === null || _this$delegate3$compo === void 0 ? void 0 : _this$delegate3$compo.call(_this$delegate3, attachment, {\n editCaption\n });\n }\n getSerializableElement() {\n if (this.isEditingAttachment()) {\n return this.documentView.shadowElement;\n } else {\n return this.element;\n }\n }\n render() {\n var _this$delegate6, _this$delegate6$compo;\n if (this.revision !== this.composition.revision) {\n this.documentView.setDocument(this.composition.document);\n this.documentView.render();\n this.revision = this.composition.revision;\n }\n if (this.canSyncDocumentView() && !this.documentView.isSynced()) {\n var _this$delegate4, _this$delegate4$compo, _this$delegate5, _this$delegate5$compo;\n (_this$delegate4 = this.delegate) === null || _this$delegate4 === void 0 || (_this$delegate4$compo = _this$delegate4.compositionControllerWillSyncDocumentView) === null || _this$delegate4$compo === void 0 || _this$delegate4$compo.call(_this$delegate4);\n this.documentView.sync();\n (_this$delegate5 = this.delegate) === null || _this$delegate5 === void 0 || (_this$delegate5$compo = _this$delegate5.compositionControllerDidSyncDocumentView) === null || _this$delegate5$compo === void 0 || _this$delegate5$compo.call(_this$delegate5);\n }\n return (_this$delegate6 = this.delegate) === null || _this$delegate6 === void 0 || (_this$delegate6$compo = _this$delegate6.compositionControllerDidRender) === null || _this$delegate6$compo === void 0 ? void 0 : _this$delegate6$compo.call(_this$delegate6);\n }\n rerenderViewForObject(object) {\n this.invalidateViewForObject(object);\n return this.render();\n }\n invalidateViewForObject(object) {\n return this.documentView.invalidateViewForObject(object);\n }\n isViewCachingEnabled() {\n return this.documentView.isViewCachingEnabled();\n }\n enableViewCaching() {\n return this.documentView.enableViewCaching();\n }\n disableViewCaching() {\n return this.documentView.disableViewCaching();\n }\n refreshViewCache() {\n return this.documentView.garbageCollectCachedViews();\n }\n\n // Attachment editor management\n\n isEditingAttachment() {\n return !!this.attachmentEditor;\n }\n installAttachmentEditorForAttachment(attachment, options) {\n var _this$attachmentEdito;\n if (((_this$attachmentEdito = this.attachmentEditor) === null || _this$attachmentEdito === void 0 ? void 0 : _this$attachmentEdito.attachment) === attachment) return;\n const element = this.documentView.findElementForObject(attachment);\n if (!element) return;\n this.uninstallAttachmentEditor();\n const attachmentPiece = this.composition.document.getAttachmentPieceForAttachment(attachment);\n this.attachmentEditor = new AttachmentEditorController(attachmentPiece, element, this.element, options);\n this.attachmentEditor.delegate = this;\n }\n uninstallAttachmentEditor() {\n var _this$attachmentEdito2;\n return (_this$attachmentEdito2 = this.attachmentEditor) === null || _this$attachmentEdito2 === void 0 ? void 0 : _this$attachmentEdito2.uninstall();\n }\n\n // Attachment controller delegate\n\n didUninstallAttachmentEditor() {\n this.attachmentEditor = null;\n return this.render();\n }\n attachmentEditorDidRequestUpdatingAttributesForAttachment(attributes, attachment) {\n var _this$delegate7, _this$delegate7$compo;\n (_this$delegate7 = this.delegate) === null || _this$delegate7 === void 0 || (_this$delegate7$compo = _this$delegate7.compositionControllerWillUpdateAttachment) === null || _this$delegate7$compo === void 0 || _this$delegate7$compo.call(_this$delegate7, attachment);\n return this.composition.updateAttributesForAttachment(attributes, attachment);\n }\n attachmentEditorDidRequestRemovingAttributeForAttachment(attribute, attachment) {\n var _this$delegate8, _this$delegate8$compo;\n (_this$delegate8 = this.delegate) === null || _this$delegate8 === void 0 || (_this$delegate8$compo = _this$delegate8.compositionControllerWillUpdateAttachment) === null || _this$delegate8$compo === void 0 || _this$delegate8$compo.call(_this$delegate8, attachment);\n return this.composition.removeAttributeForAttachment(attribute, attachment);\n }\n attachmentEditorDidRequestRemovalOfAttachment(attachment) {\n var _this$delegate9, _this$delegate9$compo;\n return (_this$delegate9 = this.delegate) === null || _this$delegate9 === void 0 || (_this$delegate9$compo = _this$delegate9.compositionControllerDidRequestRemovalOfAttachment) === null || _this$delegate9$compo === void 0 ? void 0 : _this$delegate9$compo.call(_this$delegate9, attachment);\n }\n attachmentEditorDidRequestDeselectingAttachment(attachment) {\n var _this$delegate10, _this$delegate10$comp;\n return (_this$delegate10 = this.delegate) === null || _this$delegate10 === void 0 || (_this$delegate10$comp = _this$delegate10.compositionControllerDidRequestDeselectingAttachment) === null || _this$delegate10$comp === void 0 ? void 0 : _this$delegate10$comp.call(_this$delegate10, attachment);\n }\n\n // Private\n\n canSyncDocumentView() {\n return !this.isEditingAttachment();\n }\n findAttachmentForElement(element) {\n return this.composition.document.getAttachmentById(parseInt(element.dataset.trixId, 10));\n }\n }\n\n class Controller extends BasicObject {}\n\n const mutableAttributeName = \"data-trix-mutable\";\n const mutableSelector = \"[\".concat(mutableAttributeName, \"]\");\n const options = {\n attributes: true,\n childList: true,\n characterData: true,\n characterDataOldValue: true,\n subtree: true\n };\n class MutationObserver extends BasicObject {\n constructor(element) {\n super(element);\n this.didMutate = this.didMutate.bind(this);\n this.element = element;\n this.observer = new window.MutationObserver(this.didMutate);\n this.start();\n }\n start() {\n this.reset();\n return this.observer.observe(this.element, options);\n }\n stop() {\n return this.observer.disconnect();\n }\n didMutate(mutations) {\n this.mutations.push(...Array.from(this.findSignificantMutations(mutations) || []));\n if (this.mutations.length) {\n var _this$delegate, _this$delegate$elemen;\n (_this$delegate = this.delegate) === null || _this$delegate === void 0 || (_this$delegate$elemen = _this$delegate.elementDidMutate) === null || _this$delegate$elemen === void 0 || _this$delegate$elemen.call(_this$delegate, this.getMutationSummary());\n return this.reset();\n }\n }\n\n // Private\n\n reset() {\n this.mutations = [];\n }\n findSignificantMutations(mutations) {\n return mutations.filter(mutation => {\n return this.mutationIsSignificant(mutation);\n });\n }\n mutationIsSignificant(mutation) {\n if (this.nodeIsMutable(mutation.target)) {\n return false;\n }\n for (const node of Array.from(this.nodesModifiedByMutation(mutation))) {\n if (this.nodeIsSignificant(node)) return true;\n }\n return false;\n }\n nodeIsSignificant(node) {\n return node !== this.element && !this.nodeIsMutable(node) && !nodeIsEmptyTextNode(node);\n }\n nodeIsMutable(node) {\n return findClosestElementFromNode(node, {\n matchingSelector: mutableSelector\n });\n }\n nodesModifiedByMutation(mutation) {\n const nodes = [];\n switch (mutation.type) {\n case \"attributes\":\n if (mutation.attributeName !== mutableAttributeName) {\n nodes.push(mutation.target);\n }\n break;\n case \"characterData\":\n // Changes to text nodes should consider the parent element\n nodes.push(mutation.target.parentNode);\n nodes.push(mutation.target);\n break;\n case \"childList\":\n // Consider each added or removed node\n nodes.push(...Array.from(mutation.addedNodes || []));\n nodes.push(...Array.from(mutation.removedNodes || []));\n break;\n }\n return nodes;\n }\n getMutationSummary() {\n return this.getTextMutationSummary();\n }\n getTextMutationSummary() {\n const {\n additions,\n deletions\n } = this.getTextChangesFromCharacterData();\n const textChanges = this.getTextChangesFromChildList();\n Array.from(textChanges.additions).forEach(addition => {\n if (!Array.from(additions).includes(addition)) {\n additions.push(addition);\n }\n });\n deletions.push(...Array.from(textChanges.deletions || []));\n const summary = {};\n const added = additions.join(\"\");\n if (added) {\n summary.textAdded = added;\n }\n const deleted = deletions.join(\"\");\n if (deleted) {\n summary.textDeleted = deleted;\n }\n return summary;\n }\n getMutationsByType(type) {\n return Array.from(this.mutations).filter(mutation => mutation.type === type);\n }\n getTextChangesFromChildList() {\n let textAdded, textRemoved;\n const addedNodes = [];\n const removedNodes = [];\n Array.from(this.getMutationsByType(\"childList\")).forEach(mutation => {\n addedNodes.push(...Array.from(mutation.addedNodes || []));\n removedNodes.push(...Array.from(mutation.removedNodes || []));\n });\n const singleBlockCommentRemoved = addedNodes.length === 0 && removedNodes.length === 1 && nodeIsBlockStartComment(removedNodes[0]);\n if (singleBlockCommentRemoved) {\n textAdded = [];\n textRemoved = [\"\\n\"];\n } else {\n textAdded = getTextForNodes(addedNodes);\n textRemoved = getTextForNodes(removedNodes);\n }\n const additions = textAdded.filter((text, index) => text !== textRemoved[index]).map(normalizeSpaces);\n const deletions = textRemoved.filter((text, index) => text !== textAdded[index]).map(normalizeSpaces);\n return {\n additions,\n deletions\n };\n }\n getTextChangesFromCharacterData() {\n let added, removed;\n const characterMutations = this.getMutationsByType(\"characterData\");\n if (characterMutations.length) {\n const startMutation = characterMutations[0],\n endMutation = characterMutations[characterMutations.length - 1];\n const oldString = normalizeSpaces(startMutation.oldValue);\n const newString = normalizeSpaces(endMutation.target.data);\n const summarized = summarizeStringChange(oldString, newString);\n added = summarized.added;\n removed = summarized.removed;\n }\n return {\n additions: added ? [added] : [],\n deletions: removed ? [removed] : []\n };\n }\n }\n const getTextForNodes = function () {\n let nodes = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];\n const text = [];\n for (const node of Array.from(nodes)) {\n switch (node.nodeType) {\n case Node.TEXT_NODE:\n text.push(node.data);\n break;\n case Node.ELEMENT_NODE:\n if (tagName(node) === \"br\") {\n text.push(\"\\n\");\n } else {\n text.push(...Array.from(getTextForNodes(node.childNodes) || []));\n }\n break;\n }\n }\n return text;\n };\n\n /* eslint-disable\n no-empty,\n */\n class FileVerificationOperation extends Operation {\n constructor(file) {\n super(...arguments);\n this.file = file;\n }\n perform(callback) {\n const reader = new FileReader();\n reader.onerror = () => callback(false);\n reader.onload = () => {\n reader.onerror = null;\n try {\n reader.abort();\n } catch (error) {}\n return callback(true, this.file);\n };\n return reader.readAsArrayBuffer(this.file);\n }\n }\n\n // Each software keyboard on Android emits its own set of events and some of them can be buggy.\n // This class detects when some buggy events are being emitted and lets know the input controller\n // that they should be ignored.\n class FlakyAndroidKeyboardDetector {\n constructor(element) {\n this.element = element;\n }\n shouldIgnore(event) {\n if (!browser$1.samsungAndroid) return false;\n this.previousEvent = this.event;\n this.event = event;\n this.checkSamsungKeyboardBuggyModeStart();\n this.checkSamsungKeyboardBuggyModeEnd();\n return this.buggyMode;\n }\n\n // private\n\n // The Samsung keyboard on Android can enter a buggy state in which it emits a flurry of confused events that,\n // if processed, corrupts the editor. The buggy mode always starts with an insertText event, right after a\n // keydown event with for an \"Unidentified\" key, with the same text as the editor element, except for a few\n // extra whitespace, or exotic utf8, characters.\n checkSamsungKeyboardBuggyModeStart() {\n if (this.insertingLongTextAfterUnidentifiedChar() && differsInWhitespace(this.element.innerText, this.event.data)) {\n this.buggyMode = true;\n this.event.preventDefault();\n }\n }\n\n // The flurry of buggy events are always insertText. If we see any other type, it means it's over.\n checkSamsungKeyboardBuggyModeEnd() {\n if (this.buggyMode && this.event.inputType !== \"insertText\") {\n this.buggyMode = false;\n }\n }\n insertingLongTextAfterUnidentifiedChar() {\n var _this$event$data;\n return this.isBeforeInputInsertText() && this.previousEventWasUnidentifiedKeydown() && ((_this$event$data = this.event.data) === null || _this$event$data === void 0 ? void 0 : _this$event$data.length) > 50;\n }\n isBeforeInputInsertText() {\n return this.event.type === \"beforeinput\" && this.event.inputType === \"insertText\";\n }\n previousEventWasUnidentifiedKeydown() {\n var _this$previousEvent, _this$previousEvent2;\n return ((_this$previousEvent = this.previousEvent) === null || _this$previousEvent === void 0 ? void 0 : _this$previousEvent.type) === \"keydown\" && ((_this$previousEvent2 = this.previousEvent) === null || _this$previousEvent2 === void 0 ? void 0 : _this$previousEvent2.key) === \"Unidentified\";\n }\n }\n const differsInWhitespace = (text1, text2) => {\n return normalize(text1) === normalize(text2);\n };\n const whiteSpaceNormalizerRegexp = new RegExp(\"(\".concat(OBJECT_REPLACEMENT_CHARACTER, \"|\").concat(ZERO_WIDTH_SPACE, \"|\").concat(NON_BREAKING_SPACE, \"|\\\\s)+\"), \"g\");\n const normalize = text => text.replace(whiteSpaceNormalizerRegexp, \" \").trim();\n\n class InputController extends BasicObject {\n constructor(element) {\n super(...arguments);\n this.element = element;\n this.mutationObserver = new MutationObserver(this.element);\n this.mutationObserver.delegate = this;\n this.flakyKeyboardDetector = new FlakyAndroidKeyboardDetector(this.element);\n for (const eventName in this.constructor.events) {\n handleEvent(eventName, {\n onElement: this.element,\n withCallback: this.handlerFor(eventName)\n });\n }\n }\n elementDidMutate(mutationSummary) {}\n editorWillSyncDocumentView() {\n return this.mutationObserver.stop();\n }\n editorDidSyncDocumentView() {\n return this.mutationObserver.start();\n }\n requestRender() {\n var _this$delegate, _this$delegate$inputC;\n return (_this$delegate = this.delegate) === null || _this$delegate === void 0 || (_this$delegate$inputC = _this$delegate.inputControllerDidRequestRender) === null || _this$delegate$inputC === void 0 ? void 0 : _this$delegate$inputC.call(_this$delegate);\n }\n requestReparse() {\n var _this$delegate2, _this$delegate2$input;\n (_this$delegate2 = this.delegate) === null || _this$delegate2 === void 0 || (_this$delegate2$input = _this$delegate2.inputControllerDidRequestReparse) === null || _this$delegate2$input === void 0 || _this$delegate2$input.call(_this$delegate2);\n return this.requestRender();\n }\n attachFiles(files) {\n const operations = Array.from(files).map(file => new FileVerificationOperation(file));\n return Promise.all(operations).then(files => {\n this.handleInput(function () {\n var _this$delegate3, _this$responder;\n (_this$delegate3 = this.delegate) === null || _this$delegate3 === void 0 || _this$delegate3.inputControllerWillAttachFiles();\n (_this$responder = this.responder) === null || _this$responder === void 0 || _this$responder.insertFiles(files);\n return this.requestRender();\n });\n });\n }\n\n // Private\n\n handlerFor(eventName) {\n return event => {\n if (!event.defaultPrevented) {\n this.handleInput(() => {\n if (!innerElementIsActive(this.element)) {\n if (this.flakyKeyboardDetector.shouldIgnore(event)) return;\n this.eventName = eventName;\n this.constructor.events[eventName].call(this, event);\n }\n });\n }\n };\n }\n handleInput(callback) {\n try {\n var _this$delegate4;\n (_this$delegate4 = this.delegate) === null || _this$delegate4 === void 0 || _this$delegate4.inputControllerWillHandleInput();\n callback.call(this);\n } finally {\n var _this$delegate5;\n (_this$delegate5 = this.delegate) === null || _this$delegate5 === void 0 || _this$delegate5.inputControllerDidHandleInput();\n }\n }\n createLinkHTML(href, text) {\n const link = document.createElement(\"a\");\n link.href = href;\n link.textContent = text ? text : href;\n return link.outerHTML;\n }\n }\n _defineProperty(InputController, \"events\", {});\n\n var _$codePointAt, _;\n const {\n browser,\n keyNames\n } = config;\n let pastedFileCount = 0;\n class Level0InputController extends InputController {\n constructor() {\n super(...arguments);\n this.resetInputSummary();\n }\n setInputSummary() {\n let summary = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};\n this.inputSummary.eventName = this.eventName;\n for (const key in summary) {\n const value = summary[key];\n this.inputSummary[key] = value;\n }\n return this.inputSummary;\n }\n resetInputSummary() {\n this.inputSummary = {};\n }\n reset() {\n this.resetInputSummary();\n return selectionChangeObserver.reset();\n }\n\n // Mutation observer delegate\n\n elementDidMutate(mutationSummary) {\n if (this.isComposing()) {\n var _this$delegate, _this$delegate$inputC;\n return (_this$delegate = this.delegate) === null || _this$delegate === void 0 || (_this$delegate$inputC = _this$delegate.inputControllerDidAllowUnhandledInput) === null || _this$delegate$inputC === void 0 ? void 0 : _this$delegate$inputC.call(_this$delegate);\n } else {\n return this.handleInput(function () {\n if (this.mutationIsSignificant(mutationSummary)) {\n if (this.mutationIsExpected(mutationSummary)) {\n this.requestRender();\n } else {\n this.requestReparse();\n }\n }\n return this.reset();\n });\n }\n }\n mutationIsExpected(_ref) {\n let {\n textAdded,\n textDeleted\n } = _ref;\n if (this.inputSummary.preferDocument) {\n return true;\n }\n const mutationAdditionMatchesSummary = textAdded != null ? textAdded === this.inputSummary.textAdded : !this.inputSummary.textAdded;\n const mutationDeletionMatchesSummary = textDeleted != null ? this.inputSummary.didDelete : !this.inputSummary.didDelete;\n const unexpectedNewlineAddition = [\"\\n\", \" \\n\"].includes(textAdded) && !mutationAdditionMatchesSummary;\n const unexpectedNewlineDeletion = textDeleted === \"\\n\" && !mutationDeletionMatchesSummary;\n const singleUnexpectedNewline = unexpectedNewlineAddition && !unexpectedNewlineDeletion || unexpectedNewlineDeletion && !unexpectedNewlineAddition;\n if (singleUnexpectedNewline) {\n const range = this.getSelectedRange();\n if (range) {\n var _this$responder;\n const offset = unexpectedNewlineAddition ? textAdded.replace(/\\n$/, \"\").length || -1 : (textAdded === null || textAdded === void 0 ? void 0 : textAdded.length) || 1;\n if ((_this$responder = this.responder) !== null && _this$responder !== void 0 && _this$responder.positionIsBlockBreak(range[1] + offset)) {\n return true;\n }\n }\n }\n return mutationAdditionMatchesSummary && mutationDeletionMatchesSummary;\n }\n mutationIsSignificant(mutationSummary) {\n var _this$compositionInpu;\n const textChanged = Object.keys(mutationSummary).length > 0;\n const composedEmptyString = ((_this$compositionInpu = this.compositionInput) === null || _this$compositionInpu === void 0 ? void 0 : _this$compositionInpu.getEndData()) === \"\";\n return textChanged || !composedEmptyString;\n }\n\n // Private\n\n getCompositionInput() {\n if (this.isComposing()) {\n return this.compositionInput;\n } else {\n this.compositionInput = new CompositionInput(this);\n }\n }\n isComposing() {\n return this.compositionInput && !this.compositionInput.isEnded();\n }\n deleteInDirection(direction, event) {\n var _this$responder2;\n if (((_this$responder2 = this.responder) === null || _this$responder2 === void 0 ? void 0 : _this$responder2.deleteInDirection(direction)) === false) {\n if (event) {\n event.preventDefault();\n return this.requestRender();\n }\n } else {\n return this.setInputSummary({\n didDelete: true\n });\n }\n }\n serializeSelectionToDataTransfer(dataTransfer) {\n var _this$responder3;\n if (!dataTransferIsWritable(dataTransfer)) return;\n const document = (_this$responder3 = this.responder) === null || _this$responder3 === void 0 ? void 0 : _this$responder3.getSelectedDocument().toSerializableDocument();\n dataTransfer.setData(\"application/x-trix-document\", JSON.stringify(document));\n dataTransfer.setData(\"text/html\", DocumentView.render(document).innerHTML);\n dataTransfer.setData(\"text/plain\", document.toString().replace(/\\n$/, \"\"));\n return true;\n }\n canAcceptDataTransfer(dataTransfer) {\n const types = {};\n Array.from((dataTransfer === null || dataTransfer === void 0 ? void 0 : dataTransfer.types) || []).forEach(type => {\n types[type] = true;\n });\n return types.Files || types[\"application/x-trix-document\"] || types[\"text/html\"] || types[\"text/plain\"];\n }\n getPastedHTMLUsingHiddenElement(callback) {\n const selectedRange = this.getSelectedRange();\n const style = {\n position: \"absolute\",\n left: \"\".concat(window.pageXOffset, \"px\"),\n top: \"\".concat(window.pageYOffset, \"px\"),\n opacity: 0\n };\n const element = makeElement({\n style,\n tagName: \"div\",\n editable: true\n });\n document.body.appendChild(element);\n element.focus();\n return requestAnimationFrame(() => {\n const html = element.innerHTML;\n removeNode(element);\n this.setSelectedRange(selectedRange);\n return callback(html);\n });\n }\n }\n _defineProperty(Level0InputController, \"events\", {\n keydown(event) {\n if (!this.isComposing()) {\n this.resetInputSummary();\n }\n this.inputSummary.didInput = true;\n const keyName = keyNames[event.keyCode];\n if (keyName) {\n var _context2;\n let context = this.keys;\n [\"ctrl\", \"alt\", \"shift\", \"meta\"].forEach(modifier => {\n if (event[\"\".concat(modifier, \"Key\")]) {\n var _context;\n if (modifier === \"ctrl\") {\n modifier = \"control\";\n }\n context = (_context = context) === null || _context === void 0 ? void 0 : _context[modifier];\n }\n });\n if (((_context2 = context) === null || _context2 === void 0 ? void 0 : _context2[keyName]) != null) {\n this.setInputSummary({\n keyName\n });\n selectionChangeObserver.reset();\n context[keyName].call(this, event);\n }\n }\n if (keyEventIsKeyboardCommand(event)) {\n const character = String.fromCharCode(event.keyCode).toLowerCase();\n if (character) {\n var _this$delegate3;\n const keys = [\"alt\", \"shift\"].map(modifier => {\n if (event[\"\".concat(modifier, \"Key\")]) {\n return modifier;\n }\n }).filter(key => key);\n keys.push(character);\n if ((_this$delegate3 = this.delegate) !== null && _this$delegate3 !== void 0 && _this$delegate3.inputControllerDidReceiveKeyboardCommand(keys)) {\n event.preventDefault();\n }\n }\n }\n },\n keypress(event) {\n if (this.inputSummary.eventName != null) return;\n if (event.metaKey) return;\n if (event.ctrlKey && !event.altKey) return;\n const string = stringFromKeyEvent(event);\n if (string) {\n var _this$delegate4, _this$responder9;\n (_this$delegate4 = this.delegate) === null || _this$delegate4 === void 0 || _this$delegate4.inputControllerWillPerformTyping();\n (_this$responder9 = this.responder) === null || _this$responder9 === void 0 || _this$responder9.insertString(string);\n return this.setInputSummary({\n textAdded: string,\n didDelete: this.selectionIsExpanded()\n });\n }\n },\n textInput(event) {\n // Handle autocapitalization\n const {\n data\n } = event;\n const {\n textAdded\n } = this.inputSummary;\n if (textAdded && textAdded !== data && textAdded.toUpperCase() === data) {\n var _this$responder10;\n const range = this.getSelectedRange();\n this.setSelectedRange([range[0], range[1] + textAdded.length]);\n (_this$responder10 = this.responder) === null || _this$responder10 === void 0 || _this$responder10.insertString(data);\n this.setInputSummary({\n textAdded: data\n });\n return this.setSelectedRange(range);\n }\n },\n dragenter(event) {\n event.preventDefault();\n },\n dragstart(event) {\n var _this$delegate5, _this$delegate5$input;\n this.serializeSelectionToDataTransfer(event.dataTransfer);\n this.draggedRange = this.getSelectedRange();\n return (_this$delegate5 = this.delegate) === null || _this$delegate5 === void 0 || (_this$delegate5$input = _this$delegate5.inputControllerDidStartDrag) === null || _this$delegate5$input === void 0 ? void 0 : _this$delegate5$input.call(_this$delegate5);\n },\n dragover(event) {\n if (this.draggedRange || this.canAcceptDataTransfer(event.dataTransfer)) {\n event.preventDefault();\n const draggingPoint = {\n x: event.clientX,\n y: event.clientY\n };\n if (!objectsAreEqual(draggingPoint, this.draggingPoint)) {\n var _this$delegate6, _this$delegate6$input;\n this.draggingPoint = draggingPoint;\n return (_this$delegate6 = this.delegate) === null || _this$delegate6 === void 0 || (_this$delegate6$input = _this$delegate6.inputControllerDidReceiveDragOverPoint) === null || _this$delegate6$input === void 0 ? void 0 : _this$delegate6$input.call(_this$delegate6, this.draggingPoint);\n }\n }\n },\n dragend(event) {\n var _this$delegate7, _this$delegate7$input;\n (_this$delegate7 = this.delegate) === null || _this$delegate7 === void 0 || (_this$delegate7$input = _this$delegate7.inputControllerDidCancelDrag) === null || _this$delegate7$input === void 0 || _this$delegate7$input.call(_this$delegate7);\n this.draggedRange = null;\n this.draggingPoint = null;\n },\n drop(event) {\n var _event$dataTransfer, _this$responder11;\n event.preventDefault();\n const files = (_event$dataTransfer = event.dataTransfer) === null || _event$dataTransfer === void 0 ? void 0 : _event$dataTransfer.files;\n const documentJSON = event.dataTransfer.getData(\"application/x-trix-document\");\n const point = {\n x: event.clientX,\n y: event.clientY\n };\n (_this$responder11 = this.responder) === null || _this$responder11 === void 0 || _this$responder11.setLocationRangeFromPointRange(point);\n if (files !== null && files !== void 0 && files.length) {\n this.attachFiles(files);\n } else if (this.draggedRange) {\n var _this$delegate8, _this$responder12;\n (_this$delegate8 = this.delegate) === null || _this$delegate8 === void 0 || _this$delegate8.inputControllerWillMoveText();\n (_this$responder12 = this.responder) === null || _this$responder12 === void 0 || _this$responder12.moveTextFromRange(this.draggedRange);\n this.draggedRange = null;\n this.requestRender();\n } else if (documentJSON) {\n var _this$responder13;\n const document = Document.fromJSONString(documentJSON);\n (_this$responder13 = this.responder) === null || _this$responder13 === void 0 || _this$responder13.insertDocument(document);\n this.requestRender();\n }\n this.draggedRange = null;\n this.draggingPoint = null;\n },\n cut(event) {\n var _this$responder14;\n if ((_this$responder14 = this.responder) !== null && _this$responder14 !== void 0 && _this$responder14.selectionIsExpanded()) {\n var _this$delegate9;\n if (this.serializeSelectionToDataTransfer(event.clipboardData)) {\n event.preventDefault();\n }\n (_this$delegate9 = this.delegate) === null || _this$delegate9 === void 0 || _this$delegate9.inputControllerWillCutText();\n this.deleteInDirection(\"backward\");\n if (event.defaultPrevented) {\n return this.requestRender();\n }\n }\n },\n copy(event) {\n var _this$responder15;\n if ((_this$responder15 = this.responder) !== null && _this$responder15 !== void 0 && _this$responder15.selectionIsExpanded()) {\n if (this.serializeSelectionToDataTransfer(event.clipboardData)) {\n event.preventDefault();\n }\n }\n },\n paste(event) {\n const clipboard = event.clipboardData || event.testClipboardData;\n const paste = {\n clipboard\n };\n if (!clipboard || pasteEventIsCrippledSafariHTMLPaste(event)) {\n this.getPastedHTMLUsingHiddenElement(html => {\n var _this$delegate10, _this$responder16, _this$delegate11;\n paste.type = \"text/html\";\n paste.html = html;\n (_this$delegate10 = this.delegate) === null || _this$delegate10 === void 0 || _this$delegate10.inputControllerWillPaste(paste);\n (_this$responder16 = this.responder) === null || _this$responder16 === void 0 || _this$responder16.insertHTML(paste.html);\n this.requestRender();\n return (_this$delegate11 = this.delegate) === null || _this$delegate11 === void 0 ? void 0 : _this$delegate11.inputControllerDidPaste(paste);\n });\n return;\n }\n const href = clipboard.getData(\"URL\");\n const html = clipboard.getData(\"text/html\");\n const name = clipboard.getData(\"public.url-name\");\n if (href) {\n var _this$delegate12, _this$responder17, _this$delegate13;\n let string;\n paste.type = \"text/html\";\n if (name) {\n string = squishBreakableWhitespace(name).trim();\n } else {\n string = href;\n }\n paste.html = this.createLinkHTML(href, string);\n (_this$delegate12 = this.delegate) === null || _this$delegate12 === void 0 || _this$delegate12.inputControllerWillPaste(paste);\n this.setInputSummary({\n textAdded: string,\n didDelete: this.selectionIsExpanded()\n });\n (_this$responder17 = this.responder) === null || _this$responder17 === void 0 || _this$responder17.insertHTML(paste.html);\n this.requestRender();\n (_this$delegate13 = this.delegate) === null || _this$delegate13 === void 0 || _this$delegate13.inputControllerDidPaste(paste);\n } else if (dataTransferIsPlainText(clipboard)) {\n var _this$delegate14, _this$responder18, _this$delegate15;\n paste.type = \"text/plain\";\n paste.string = clipboard.getData(\"text/plain\");\n (_this$delegate14 = this.delegate) === null || _this$delegate14 === void 0 || _this$delegate14.inputControllerWillPaste(paste);\n this.setInputSummary({\n textAdded: paste.string,\n didDelete: this.selectionIsExpanded()\n });\n (_this$responder18 = this.responder) === null || _this$responder18 === void 0 || _this$responder18.insertString(paste.string);\n this.requestRender();\n (_this$delegate15 = this.delegate) === null || _this$delegate15 === void 0 || _this$delegate15.inputControllerDidPaste(paste);\n } else if (html) {\n var _this$delegate16, _this$responder19, _this$delegate17;\n paste.type = \"text/html\";\n paste.html = html;\n (_this$delegate16 = this.delegate) === null || _this$delegate16 === void 0 || _this$delegate16.inputControllerWillPaste(paste);\n (_this$responder19 = this.responder) === null || _this$responder19 === void 0 || _this$responder19.insertHTML(paste.html);\n this.requestRender();\n (_this$delegate17 = this.delegate) === null || _this$delegate17 === void 0 || _this$delegate17.inputControllerDidPaste(paste);\n } else if (Array.from(clipboard.types).includes(\"Files\")) {\n var _clipboard$items, _clipboard$items$getA;\n const file = (_clipboard$items = clipboard.items) === null || _clipboard$items === void 0 || (_clipboard$items = _clipboard$items[0]) === null || _clipboard$items === void 0 || (_clipboard$items$getA = _clipboard$items.getAsFile) === null || _clipboard$items$getA === void 0 ? void 0 : _clipboard$items$getA.call(_clipboard$items);\n if (file) {\n var _this$delegate18, _this$responder20, _this$delegate19;\n const extension = extensionForFile(file);\n if (!file.name && extension) {\n file.name = \"pasted-file-\".concat(++pastedFileCount, \".\").concat(extension);\n }\n paste.type = \"File\";\n paste.file = file;\n (_this$delegate18 = this.delegate) === null || _this$delegate18 === void 0 || _this$delegate18.inputControllerWillAttachFiles();\n (_this$responder20 = this.responder) === null || _this$responder20 === void 0 || _this$responder20.insertFile(paste.file);\n this.requestRender();\n (_this$delegate19 = this.delegate) === null || _this$delegate19 === void 0 || _this$delegate19.inputControllerDidPaste(paste);\n }\n }\n event.preventDefault();\n },\n compositionstart(event) {\n return this.getCompositionInput().start(event.data);\n },\n compositionupdate(event) {\n return this.getCompositionInput().update(event.data);\n },\n compositionend(event) {\n return this.getCompositionInput().end(event.data);\n },\n beforeinput(event) {\n this.inputSummary.didInput = true;\n },\n input(event) {\n this.inputSummary.didInput = true;\n return event.stopPropagation();\n }\n });\n _defineProperty(Level0InputController, \"keys\", {\n backspace(event) {\n var _this$delegate20;\n (_this$delegate20 = this.delegate) === null || _this$delegate20 === void 0 || _this$delegate20.inputControllerWillPerformTyping();\n return this.deleteInDirection(\"backward\", event);\n },\n delete(event) {\n var _this$delegate21;\n (_this$delegate21 = this.delegate) === null || _this$delegate21 === void 0 || _this$delegate21.inputControllerWillPerformTyping();\n return this.deleteInDirection(\"forward\", event);\n },\n return(event) {\n var _this$delegate22, _this$responder21;\n this.setInputSummary({\n preferDocument: true\n });\n (_this$delegate22 = this.delegate) === null || _this$delegate22 === void 0 || _this$delegate22.inputControllerWillPerformTyping();\n return (_this$responder21 = this.responder) === null || _this$responder21 === void 0 ? void 0 : _this$responder21.insertLineBreak();\n },\n tab(event) {\n var _this$responder22;\n if ((_this$responder22 = this.responder) !== null && _this$responder22 !== void 0 && _this$responder22.canIncreaseNestingLevel()) {\n var _this$responder23;\n (_this$responder23 = this.responder) === null || _this$responder23 === void 0 || _this$responder23.increaseNestingLevel();\n this.requestRender();\n event.preventDefault();\n }\n },\n left(event) {\n if (this.selectionIsInCursorTarget()) {\n var _this$responder24;\n event.preventDefault();\n return (_this$responder24 = this.responder) === null || _this$responder24 === void 0 ? void 0 : _this$responder24.moveCursorInDirection(\"backward\");\n }\n },\n right(event) {\n if (this.selectionIsInCursorTarget()) {\n var _this$responder25;\n event.preventDefault();\n return (_this$responder25 = this.responder) === null || _this$responder25 === void 0 ? void 0 : _this$responder25.moveCursorInDirection(\"forward\");\n }\n },\n control: {\n d(event) {\n var _this$delegate23;\n (_this$delegate23 = this.delegate) === null || _this$delegate23 === void 0 || _this$delegate23.inputControllerWillPerformTyping();\n return this.deleteInDirection(\"forward\", event);\n },\n h(event) {\n var _this$delegate24;\n (_this$delegate24 = this.delegate) === null || _this$delegate24 === void 0 || _this$delegate24.inputControllerWillPerformTyping();\n return this.deleteInDirection(\"backward\", event);\n },\n o(event) {\n var _this$delegate25, _this$responder26;\n event.preventDefault();\n (_this$delegate25 = this.delegate) === null || _this$delegate25 === void 0 || _this$delegate25.inputControllerWillPerformTyping();\n (_this$responder26 = this.responder) === null || _this$responder26 === void 0 || _this$responder26.insertString(\"\\n\", {\n updatePosition: false\n });\n return this.requestRender();\n }\n },\n shift: {\n return(event) {\n var _this$delegate26, _this$responder27;\n (_this$delegate26 = this.delegate) === null || _this$delegate26 === void 0 || _this$delegate26.inputControllerWillPerformTyping();\n (_this$responder27 = this.responder) === null || _this$responder27 === void 0 || _this$responder27.insertString(\"\\n\");\n this.requestRender();\n event.preventDefault();\n },\n tab(event) {\n var _this$responder28;\n if ((_this$responder28 = this.responder) !== null && _this$responder28 !== void 0 && _this$responder28.canDecreaseNestingLevel()) {\n var _this$responder29;\n (_this$responder29 = this.responder) === null || _this$responder29 === void 0 || _this$responder29.decreaseNestingLevel();\n this.requestRender();\n event.preventDefault();\n }\n },\n left(event) {\n if (this.selectionIsInCursorTarget()) {\n event.preventDefault();\n return this.expandSelectionInDirection(\"backward\");\n }\n },\n right(event) {\n if (this.selectionIsInCursorTarget()) {\n event.preventDefault();\n return this.expandSelectionInDirection(\"forward\");\n }\n }\n },\n alt: {\n backspace(event) {\n var _this$delegate27;\n this.setInputSummary({\n preferDocument: false\n });\n return (_this$delegate27 = this.delegate) === null || _this$delegate27 === void 0 ? void 0 : _this$delegate27.inputControllerWillPerformTyping();\n }\n },\n meta: {\n backspace(event) {\n var _this$delegate28;\n this.setInputSummary({\n preferDocument: false\n });\n return (_this$delegate28 = this.delegate) === null || _this$delegate28 === void 0 ? void 0 : _this$delegate28.inputControllerWillPerformTyping();\n }\n }\n });\n Level0InputController.proxyMethod(\"responder?.getSelectedRange\");\n Level0InputController.proxyMethod(\"responder?.setSelectedRange\");\n Level0InputController.proxyMethod(\"responder?.expandSelectionInDirection\");\n Level0InputController.proxyMethod(\"responder?.selectionIsInCursorTarget\");\n Level0InputController.proxyMethod(\"responder?.selectionIsExpanded\");\n const extensionForFile = file => {\n var _file$type;\n return (_file$type = file.type) === null || _file$type === void 0 || (_file$type = _file$type.match(/\\/(\\w+)$/)) === null || _file$type === void 0 ? void 0 : _file$type[1];\n };\n const hasStringCodePointAt = !!((_$codePointAt = (_ = \" \").codePointAt) !== null && _$codePointAt !== void 0 && _$codePointAt.call(_, 0));\n const stringFromKeyEvent = function (event) {\n if (event.key && hasStringCodePointAt && event.key.codePointAt(0) === event.keyCode) {\n return event.key;\n } else {\n let code;\n if (event.which === null) {\n code = event.keyCode;\n } else if (event.which !== 0 && event.charCode !== 0) {\n code = event.charCode;\n }\n if (code != null && keyNames[code] !== \"escape\") {\n return UTF16String.fromCodepoints([code]).toString();\n }\n }\n };\n const pasteEventIsCrippledSafariHTMLPaste = function (event) {\n const paste = event.clipboardData;\n if (paste) {\n if (paste.types.includes(\"text/html\")) {\n // Answer is yes if there's any possibility of Paste and Match Style in Safari,\n // which is nearly impossible to detect confidently: https://bugs.webkit.org/show_bug.cgi?id=174165\n for (const type of paste.types) {\n const hasPasteboardFlavor = /^CorePasteboardFlavorType/.test(type);\n const hasReadableDynamicData = /^dyn\\./.test(type) && paste.getData(type);\n const mightBePasteAndMatchStyle = hasPasteboardFlavor || hasReadableDynamicData;\n if (mightBePasteAndMatchStyle) {\n return true;\n }\n }\n return false;\n } else {\n const isExternalHTMLPaste = paste.types.includes(\"com.apple.webarchive\");\n const isExternalRichTextPaste = paste.types.includes(\"com.apple.flat-rtfd\");\n return isExternalHTMLPaste || isExternalRichTextPaste;\n }\n }\n };\n class CompositionInput extends BasicObject {\n constructor(inputController) {\n super(...arguments);\n this.inputController = inputController;\n this.responder = this.inputController.responder;\n this.delegate = this.inputController.delegate;\n this.inputSummary = this.inputController.inputSummary;\n this.data = {};\n }\n start(data) {\n this.data.start = data;\n if (this.isSignificant()) {\n var _this$responder5;\n if (this.inputSummary.eventName === \"keypress\" && this.inputSummary.textAdded) {\n var _this$responder4;\n (_this$responder4 = this.responder) === null || _this$responder4 === void 0 || _this$responder4.deleteInDirection(\"left\");\n }\n if (!this.selectionIsExpanded()) {\n this.insertPlaceholder();\n this.requestRender();\n }\n this.range = (_this$responder5 = this.responder) === null || _this$responder5 === void 0 ? void 0 : _this$responder5.getSelectedRange();\n }\n }\n update(data) {\n this.data.update = data;\n if (this.isSignificant()) {\n const range = this.selectPlaceholder();\n if (range) {\n this.forgetPlaceholder();\n this.range = range;\n }\n }\n }\n end(data) {\n this.data.end = data;\n if (this.isSignificant()) {\n this.forgetPlaceholder();\n if (this.canApplyToDocument()) {\n var _this$delegate2, _this$responder6, _this$responder7, _this$responder8;\n this.setInputSummary({\n preferDocument: true,\n didInput: false\n });\n (_this$delegate2 = this.delegate) === null || _this$delegate2 === void 0 || _this$delegate2.inputControllerWillPerformTyping();\n (_this$responder6 = this.responder) === null || _this$responder6 === void 0 || _this$responder6.setSelectedRange(this.range);\n (_this$responder7 = this.responder) === null || _this$responder7 === void 0 || _this$responder7.insertString(this.data.end);\n return (_this$responder8 = this.responder) === null || _this$responder8 === void 0 ? void 0 : _this$responder8.setSelectedRange(this.range[0] + this.data.end.length);\n } else if (this.data.start != null || this.data.update != null) {\n this.requestReparse();\n return this.inputController.reset();\n }\n } else {\n return this.inputController.reset();\n }\n }\n getEndData() {\n return this.data.end;\n }\n isEnded() {\n return this.getEndData() != null;\n }\n isSignificant() {\n if (browser.composesExistingText) {\n return this.inputSummary.didInput;\n } else {\n return true;\n }\n }\n\n // Private\n\n canApplyToDocument() {\n var _this$data$start, _this$data$end;\n return ((_this$data$start = this.data.start) === null || _this$data$start === void 0 ? void 0 : _this$data$start.length) === 0 && ((_this$data$end = this.data.end) === null || _this$data$end === void 0 ? void 0 : _this$data$end.length) > 0 && this.range;\n }\n }\n CompositionInput.proxyMethod(\"inputController.setInputSummary\");\n CompositionInput.proxyMethod(\"inputController.requestRender\");\n CompositionInput.proxyMethod(\"inputController.requestReparse\");\n CompositionInput.proxyMethod(\"responder?.selectionIsExpanded\");\n CompositionInput.proxyMethod(\"responder?.insertPlaceholder\");\n CompositionInput.proxyMethod(\"responder?.selectPlaceholder\");\n CompositionInput.proxyMethod(\"responder?.forgetPlaceholder\");\n\n class Level2InputController extends InputController {\n constructor() {\n super(...arguments);\n this.render = this.render.bind(this);\n }\n elementDidMutate() {\n if (this.scheduledRender) {\n if (this.composing) {\n var _this$delegate, _this$delegate$inputC;\n return (_this$delegate = this.delegate) === null || _this$delegate === void 0 || (_this$delegate$inputC = _this$delegate.inputControllerDidAllowUnhandledInput) === null || _this$delegate$inputC === void 0 ? void 0 : _this$delegate$inputC.call(_this$delegate);\n }\n } else {\n return this.reparse();\n }\n }\n scheduleRender() {\n return this.scheduledRender ? this.scheduledRender : this.scheduledRender = requestAnimationFrame(this.render);\n }\n render() {\n var _this$afterRender;\n cancelAnimationFrame(this.scheduledRender);\n this.scheduledRender = null;\n if (!this.composing) {\n var _this$delegate2;\n (_this$delegate2 = this.delegate) === null || _this$delegate2 === void 0 || _this$delegate2.render();\n }\n (_this$afterRender = this.afterRender) === null || _this$afterRender === void 0 || _this$afterRender.call(this);\n this.afterRender = null;\n }\n reparse() {\n var _this$delegate3;\n return (_this$delegate3 = this.delegate) === null || _this$delegate3 === void 0 ? void 0 : _this$delegate3.reparse();\n }\n\n // Responder helpers\n\n insertString() {\n var _this$delegate4;\n let string = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : \"\";\n let options = arguments.length > 1 ? arguments[1] : undefined;\n (_this$delegate4 = this.delegate) === null || _this$delegate4 === void 0 || _this$delegate4.inputControllerWillPerformTyping();\n return this.withTargetDOMRange(function () {\n var _this$responder;\n return (_this$responder = this.responder) === null || _this$responder === void 0 ? void 0 : _this$responder.insertString(string, options);\n });\n }\n toggleAttributeIfSupported(attributeName) {\n if (getAllAttributeNames().includes(attributeName)) {\n var _this$delegate5;\n (_this$delegate5 = this.delegate) === null || _this$delegate5 === void 0 || _this$delegate5.inputControllerWillPerformFormatting(attributeName);\n return this.withTargetDOMRange(function () {\n var _this$responder2;\n return (_this$responder2 = this.responder) === null || _this$responder2 === void 0 ? void 0 : _this$responder2.toggleCurrentAttribute(attributeName);\n });\n }\n }\n activateAttributeIfSupported(attributeName, value) {\n if (getAllAttributeNames().includes(attributeName)) {\n var _this$delegate6;\n (_this$delegate6 = this.delegate) === null || _this$delegate6 === void 0 || _this$delegate6.inputControllerWillPerformFormatting(attributeName);\n return this.withTargetDOMRange(function () {\n var _this$responder3;\n return (_this$responder3 = this.responder) === null || _this$responder3 === void 0 ? void 0 : _this$responder3.setCurrentAttribute(attributeName, value);\n });\n }\n }\n deleteInDirection(direction) {\n let {\n recordUndoEntry\n } = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {\n recordUndoEntry: true\n };\n if (recordUndoEntry) {\n var _this$delegate7;\n (_this$delegate7 = this.delegate) === null || _this$delegate7 === void 0 || _this$delegate7.inputControllerWillPerformTyping();\n }\n const perform = () => {\n var _this$responder4;\n return (_this$responder4 = this.responder) === null || _this$responder4 === void 0 ? void 0 : _this$responder4.deleteInDirection(direction);\n };\n const domRange = this.getTargetDOMRange({\n minLength: this.composing ? 1 : 2\n });\n if (domRange) {\n return this.withTargetDOMRange(domRange, perform);\n } else {\n return perform();\n }\n }\n\n // Selection helpers\n\n withTargetDOMRange(domRange, fn) {\n if (typeof domRange === \"function\") {\n fn = domRange;\n domRange = this.getTargetDOMRange();\n }\n if (domRange) {\n var _this$responder5;\n return (_this$responder5 = this.responder) === null || _this$responder5 === void 0 ? void 0 : _this$responder5.withTargetDOMRange(domRange, fn.bind(this));\n } else {\n selectionChangeObserver.reset();\n return fn.call(this);\n }\n }\n getTargetDOMRange() {\n var _this$event$getTarget, _this$event;\n let {\n minLength\n } = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {\n minLength: 0\n };\n const targetRanges = (_this$event$getTarget = (_this$event = this.event).getTargetRanges) === null || _this$event$getTarget === void 0 ? void 0 : _this$event$getTarget.call(_this$event);\n if (targetRanges) {\n if (targetRanges.length) {\n const domRange = staticRangeToRange(targetRanges[0]);\n if (minLength === 0 || domRange.toString().length >= minLength) {\n return domRange;\n }\n }\n }\n }\n withEvent(event, fn) {\n let result;\n this.event = event;\n try {\n result = fn.call(this);\n } finally {\n this.event = null;\n }\n return result;\n }\n }\n _defineProperty(Level2InputController, \"events\", {\n keydown(event) {\n if (keyEventIsKeyboardCommand(event)) {\n var _this$delegate8;\n const command = keyboardCommandFromKeyEvent(event);\n if ((_this$delegate8 = this.delegate) !== null && _this$delegate8 !== void 0 && _this$delegate8.inputControllerDidReceiveKeyboardCommand(command)) {\n event.preventDefault();\n }\n } else {\n let name = event.key;\n if (event.altKey) {\n name += \"+Alt\";\n }\n if (event.shiftKey) {\n name += \"+Shift\";\n }\n const handler = this.constructor.keys[name];\n if (handler) {\n return this.withEvent(event, handler);\n }\n }\n },\n // Handle paste event to work around beforeinput.insertFromPaste browser bugs.\n // Safe to remove each condition once fixed upstream.\n paste(event) {\n var _event$clipboardData;\n // https://bugs.webkit.org/show_bug.cgi?id=194921\n let paste;\n const href = (_event$clipboardData = event.clipboardData) === null || _event$clipboardData === void 0 ? void 0 : _event$clipboardData.getData(\"URL\");\n if (pasteEventHasFilesOnly(event)) {\n event.preventDefault();\n return this.attachFiles(event.clipboardData.files);\n\n // https://bugs.chromium.org/p/chromium/issues/detail?id=934448\n } else if (pasteEventHasPlainTextOnly(event)) {\n var _this$delegate9, _this$responder6, _this$delegate10;\n event.preventDefault();\n paste = {\n type: \"text/plain\",\n string: event.clipboardData.getData(\"text/plain\")\n };\n (_this$delegate9 = this.delegate) === null || _this$delegate9 === void 0 || _this$delegate9.inputControllerWillPaste(paste);\n (_this$responder6 = this.responder) === null || _this$responder6 === void 0 || _this$responder6.insertString(paste.string);\n this.render();\n return (_this$delegate10 = this.delegate) === null || _this$delegate10 === void 0 ? void 0 : _this$delegate10.inputControllerDidPaste(paste);\n\n // https://bugs.webkit.org/show_bug.cgi?id=196702\n } else if (href) {\n var _this$delegate11, _this$responder7, _this$delegate12;\n event.preventDefault();\n paste = {\n type: \"text/html\",\n html: this.createLinkHTML(href)\n };\n (_this$delegate11 = this.delegate) === null || _this$delegate11 === void 0 || _this$delegate11.inputControllerWillPaste(paste);\n (_this$responder7 = this.responder) === null || _this$responder7 === void 0 || _this$responder7.insertHTML(paste.html);\n this.render();\n return (_this$delegate12 = this.delegate) === null || _this$delegate12 === void 0 ? void 0 : _this$delegate12.inputControllerDidPaste(paste);\n }\n },\n beforeinput(event) {\n const handler = this.constructor.inputTypes[event.inputType];\n const immmediateRender = shouldRenderInmmediatelyToDealWithIOSDictation(event);\n if (handler) {\n this.withEvent(event, handler);\n if (!immmediateRender) {\n this.scheduleRender();\n }\n }\n if (immmediateRender) {\n this.render();\n }\n },\n input(event) {\n selectionChangeObserver.reset();\n },\n dragstart(event) {\n var _this$responder8;\n if ((_this$responder8 = this.responder) !== null && _this$responder8 !== void 0 && _this$responder8.selectionContainsAttachments()) {\n var _this$responder9;\n event.dataTransfer.setData(\"application/x-trix-dragging\", true);\n this.dragging = {\n range: (_this$responder9 = this.responder) === null || _this$responder9 === void 0 ? void 0 : _this$responder9.getSelectedRange(),\n point: pointFromEvent(event)\n };\n }\n },\n dragenter(event) {\n if (dragEventHasFiles(event)) {\n event.preventDefault();\n }\n },\n dragover(event) {\n if (this.dragging) {\n event.preventDefault();\n const point = pointFromEvent(event);\n if (!objectsAreEqual(point, this.dragging.point)) {\n var _this$responder10;\n this.dragging.point = point;\n return (_this$responder10 = this.responder) === null || _this$responder10 === void 0 ? void 0 : _this$responder10.setLocationRangeFromPointRange(point);\n }\n } else if (dragEventHasFiles(event)) {\n event.preventDefault();\n }\n },\n drop(event) {\n if (this.dragging) {\n var _this$delegate13, _this$responder11;\n event.preventDefault();\n (_this$delegate13 = this.delegate) === null || _this$delegate13 === void 0 || _this$delegate13.inputControllerWillMoveText();\n (_this$responder11 = this.responder) === null || _this$responder11 === void 0 || _this$responder11.moveTextFromRange(this.dragging.range);\n this.dragging = null;\n return this.scheduleRender();\n } else if (dragEventHasFiles(event)) {\n var _this$responder12;\n event.preventDefault();\n const point = pointFromEvent(event);\n (_this$responder12 = this.responder) === null || _this$responder12 === void 0 || _this$responder12.setLocationRangeFromPointRange(point);\n return this.attachFiles(event.dataTransfer.files);\n }\n },\n dragend() {\n if (this.dragging) {\n var _this$responder13;\n (_this$responder13 = this.responder) === null || _this$responder13 === void 0 || _this$responder13.setSelectedRange(this.dragging.range);\n this.dragging = null;\n }\n },\n compositionend(event) {\n if (this.composing) {\n this.composing = false;\n if (!browser$1.recentAndroid) this.scheduleRender();\n }\n }\n });\n _defineProperty(Level2InputController, \"keys\", {\n ArrowLeft() {\n var _this$responder14;\n if ((_this$responder14 = this.responder) !== null && _this$responder14 !== void 0 && _this$responder14.shouldManageMovingCursorInDirection(\"backward\")) {\n var _this$responder15;\n this.event.preventDefault();\n return (_this$responder15 = this.responder) === null || _this$responder15 === void 0 ? void 0 : _this$responder15.moveCursorInDirection(\"backward\");\n }\n },\n ArrowRight() {\n var _this$responder16;\n if ((_this$responder16 = this.responder) !== null && _this$responder16 !== void 0 && _this$responder16.shouldManageMovingCursorInDirection(\"forward\")) {\n var _this$responder17;\n this.event.preventDefault();\n return (_this$responder17 = this.responder) === null || _this$responder17 === void 0 ? void 0 : _this$responder17.moveCursorInDirection(\"forward\");\n }\n },\n Backspace() {\n var _this$responder18;\n if ((_this$responder18 = this.responder) !== null && _this$responder18 !== void 0 && _this$responder18.shouldManageDeletingInDirection(\"backward\")) {\n var _this$delegate14, _this$responder19;\n this.event.preventDefault();\n (_this$delegate14 = this.delegate) === null || _this$delegate14 === void 0 || _this$delegate14.inputControllerWillPerformTyping();\n (_this$responder19 = this.responder) === null || _this$responder19 === void 0 || _this$responder19.deleteInDirection(\"backward\");\n return this.render();\n }\n },\n Tab() {\n var _this$responder20;\n if ((_this$responder20 = this.responder) !== null && _this$responder20 !== void 0 && _this$responder20.canIncreaseNestingLevel()) {\n var _this$responder21;\n this.event.preventDefault();\n (_this$responder21 = this.responder) === null || _this$responder21 === void 0 || _this$responder21.increaseNestingLevel();\n return this.render();\n }\n },\n \"Tab+Shift\"() {\n var _this$responder22;\n if ((_this$responder22 = this.responder) !== null && _this$responder22 !== void 0 && _this$responder22.canDecreaseNestingLevel()) {\n var _this$responder23;\n this.event.preventDefault();\n (_this$responder23 = this.responder) === null || _this$responder23 === void 0 || _this$responder23.decreaseNestingLevel();\n return this.render();\n }\n }\n });\n _defineProperty(Level2InputController, \"inputTypes\", {\n deleteByComposition() {\n return this.deleteInDirection(\"backward\", {\n recordUndoEntry: false\n });\n },\n deleteByCut() {\n return this.deleteInDirection(\"backward\");\n },\n deleteByDrag() {\n this.event.preventDefault();\n return this.withTargetDOMRange(function () {\n var _this$responder24;\n this.deleteByDragRange = (_this$responder24 = this.responder) === null || _this$responder24 === void 0 ? void 0 : _this$responder24.getSelectedRange();\n });\n },\n deleteCompositionText() {\n return this.deleteInDirection(\"backward\", {\n recordUndoEntry: false\n });\n },\n deleteContent() {\n return this.deleteInDirection(\"backward\");\n },\n deleteContentBackward() {\n return this.deleteInDirection(\"backward\");\n },\n deleteContentForward() {\n return this.deleteInDirection(\"forward\");\n },\n deleteEntireSoftLine() {\n return this.deleteInDirection(\"forward\");\n },\n deleteHardLineBackward() {\n return this.deleteInDirection(\"backward\");\n },\n deleteHardLineForward() {\n return this.deleteInDirection(\"forward\");\n },\n deleteSoftLineBackward() {\n return this.deleteInDirection(\"backward\");\n },\n deleteSoftLineForward() {\n return this.deleteInDirection(\"forward\");\n },\n deleteWordBackward() {\n return this.deleteInDirection(\"backward\");\n },\n deleteWordForward() {\n return this.deleteInDirection(\"forward\");\n },\n formatBackColor() {\n return this.activateAttributeIfSupported(\"backgroundColor\", this.event.data);\n },\n formatBold() {\n return this.toggleAttributeIfSupported(\"bold\");\n },\n formatFontColor() {\n return this.activateAttributeIfSupported(\"color\", this.event.data);\n },\n formatFontName() {\n return this.activateAttributeIfSupported(\"font\", this.event.data);\n },\n formatIndent() {\n var _this$responder25;\n if ((_this$responder25 = this.responder) !== null && _this$responder25 !== void 0 && _this$responder25.canIncreaseNestingLevel()) {\n return this.withTargetDOMRange(function () {\n var _this$responder26;\n return (_this$responder26 = this.responder) === null || _this$responder26 === void 0 ? void 0 : _this$responder26.increaseNestingLevel();\n });\n }\n },\n formatItalic() {\n return this.toggleAttributeIfSupported(\"italic\");\n },\n formatJustifyCenter() {\n return this.toggleAttributeIfSupported(\"justifyCenter\");\n },\n formatJustifyFull() {\n return this.toggleAttributeIfSupported(\"justifyFull\");\n },\n formatJustifyLeft() {\n return this.toggleAttributeIfSupported(\"justifyLeft\");\n },\n formatJustifyRight() {\n return this.toggleAttributeIfSupported(\"justifyRight\");\n },\n formatOutdent() {\n var _this$responder27;\n if ((_this$responder27 = this.responder) !== null && _this$responder27 !== void 0 && _this$responder27.canDecreaseNestingLevel()) {\n return this.withTargetDOMRange(function () {\n var _this$responder28;\n return (_this$responder28 = this.responder) === null || _this$responder28 === void 0 ? void 0 : _this$responder28.decreaseNestingLevel();\n });\n }\n },\n formatRemove() {\n this.withTargetDOMRange(function () {\n for (const attributeName in (_this$responder29 = this.responder) === null || _this$responder29 === void 0 ? void 0 : _this$responder29.getCurrentAttributes()) {\n var _this$responder29, _this$responder30;\n (_this$responder30 = this.responder) === null || _this$responder30 === void 0 || _this$responder30.removeCurrentAttribute(attributeName);\n }\n });\n },\n formatSetBlockTextDirection() {\n return this.activateAttributeIfSupported(\"blockDir\", this.event.data);\n },\n formatSetInlineTextDirection() {\n return this.activateAttributeIfSupported(\"textDir\", this.event.data);\n },\n formatStrikeThrough() {\n return this.toggleAttributeIfSupported(\"strike\");\n },\n formatSubscript() {\n return this.toggleAttributeIfSupported(\"sub\");\n },\n formatSuperscript() {\n return this.toggleAttributeIfSupported(\"sup\");\n },\n formatUnderline() {\n return this.toggleAttributeIfSupported(\"underline\");\n },\n historyRedo() {\n var _this$delegate15;\n return (_this$delegate15 = this.delegate) === null || _this$delegate15 === void 0 ? void 0 : _this$delegate15.inputControllerWillPerformRedo();\n },\n historyUndo() {\n var _this$delegate16;\n return (_this$delegate16 = this.delegate) === null || _this$delegate16 === void 0 ? void 0 : _this$delegate16.inputControllerWillPerformUndo();\n },\n insertCompositionText() {\n this.composing = true;\n return this.insertString(this.event.data);\n },\n insertFromComposition() {\n this.composing = false;\n return this.insertString(this.event.data);\n },\n insertFromDrop() {\n const range = this.deleteByDragRange;\n if (range) {\n var _this$delegate17;\n this.deleteByDragRange = null;\n (_this$delegate17 = this.delegate) === null || _this$delegate17 === void 0 || _this$delegate17.inputControllerWillMoveText();\n return this.withTargetDOMRange(function () {\n var _this$responder31;\n return (_this$responder31 = this.responder) === null || _this$responder31 === void 0 ? void 0 : _this$responder31.moveTextFromRange(range);\n });\n }\n },\n insertFromPaste() {\n const {\n dataTransfer\n } = this.event;\n const paste = {\n dataTransfer\n };\n const href = dataTransfer.getData(\"URL\");\n const html = dataTransfer.getData(\"text/html\");\n if (href) {\n var _this$delegate18;\n let string;\n this.event.preventDefault();\n paste.type = \"text/html\";\n const name = dataTransfer.getData(\"public.url-name\");\n if (name) {\n string = squishBreakableWhitespace(name).trim();\n } else {\n string = href;\n }\n paste.html = this.createLinkHTML(href, string);\n (_this$delegate18 = this.delegate) === null || _this$delegate18 === void 0 || _this$delegate18.inputControllerWillPaste(paste);\n this.withTargetDOMRange(function () {\n var _this$responder32;\n return (_this$responder32 = this.responder) === null || _this$responder32 === void 0 ? void 0 : _this$responder32.insertHTML(paste.html);\n });\n this.afterRender = () => {\n var _this$delegate19;\n return (_this$delegate19 = this.delegate) === null || _this$delegate19 === void 0 ? void 0 : _this$delegate19.inputControllerDidPaste(paste);\n };\n } else if (dataTransferIsPlainText(dataTransfer)) {\n var _this$delegate20;\n paste.type = \"text/plain\";\n paste.string = dataTransfer.getData(\"text/plain\");\n (_this$delegate20 = this.delegate) === null || _this$delegate20 === void 0 || _this$delegate20.inputControllerWillPaste(paste);\n this.withTargetDOMRange(function () {\n var _this$responder33;\n return (_this$responder33 = this.responder) === null || _this$responder33 === void 0 ? void 0 : _this$responder33.insertString(paste.string);\n });\n this.afterRender = () => {\n var _this$delegate21;\n return (_this$delegate21 = this.delegate) === null || _this$delegate21 === void 0 ? void 0 : _this$delegate21.inputControllerDidPaste(paste);\n };\n } else if (processableFilePaste(this.event)) {\n var _this$delegate22;\n paste.type = \"File\";\n paste.file = dataTransfer.files[0];\n (_this$delegate22 = this.delegate) === null || _this$delegate22 === void 0 || _this$delegate22.inputControllerWillPaste(paste);\n this.withTargetDOMRange(function () {\n var _this$responder34;\n return (_this$responder34 = this.responder) === null || _this$responder34 === void 0 ? void 0 : _this$responder34.insertFile(paste.file);\n });\n this.afterRender = () => {\n var _this$delegate23;\n return (_this$delegate23 = this.delegate) === null || _this$delegate23 === void 0 ? void 0 : _this$delegate23.inputControllerDidPaste(paste);\n };\n } else if (html) {\n var _this$delegate24;\n this.event.preventDefault();\n paste.type = \"text/html\";\n paste.html = html;\n (_this$delegate24 = this.delegate) === null || _this$delegate24 === void 0 || _this$delegate24.inputControllerWillPaste(paste);\n this.withTargetDOMRange(function () {\n var _this$responder35;\n return (_this$responder35 = this.responder) === null || _this$responder35 === void 0 ? void 0 : _this$responder35.insertHTML(paste.html);\n });\n this.afterRender = () => {\n var _this$delegate25;\n return (_this$delegate25 = this.delegate) === null || _this$delegate25 === void 0 ? void 0 : _this$delegate25.inputControllerDidPaste(paste);\n };\n }\n },\n insertFromYank() {\n return this.insertString(this.event.data);\n },\n insertLineBreak() {\n return this.insertString(\"\\n\");\n },\n insertLink() {\n return this.activateAttributeIfSupported(\"href\", this.event.data);\n },\n insertOrderedList() {\n return this.toggleAttributeIfSupported(\"number\");\n },\n insertParagraph() {\n var _this$delegate26;\n (_this$delegate26 = this.delegate) === null || _this$delegate26 === void 0 || _this$delegate26.inputControllerWillPerformTyping();\n return this.withTargetDOMRange(function () {\n var _this$responder36;\n return (_this$responder36 = this.responder) === null || _this$responder36 === void 0 ? void 0 : _this$responder36.insertLineBreak();\n });\n },\n insertReplacementText() {\n const replacement = this.event.dataTransfer.getData(\"text/plain\");\n const domRange = this.event.getTargetRanges()[0];\n this.withTargetDOMRange(domRange, () => {\n this.insertString(replacement, {\n updatePosition: false\n });\n });\n },\n insertText() {\n var _this$event$dataTrans;\n return this.insertString(this.event.data || ((_this$event$dataTrans = this.event.dataTransfer) === null || _this$event$dataTrans === void 0 ? void 0 : _this$event$dataTrans.getData(\"text/plain\")));\n },\n insertTranspose() {\n return this.insertString(this.event.data);\n },\n insertUnorderedList() {\n return this.toggleAttributeIfSupported(\"bullet\");\n }\n });\n const staticRangeToRange = function (staticRange) {\n const range = document.createRange();\n range.setStart(staticRange.startContainer, staticRange.startOffset);\n range.setEnd(staticRange.endContainer, staticRange.endOffset);\n return range;\n };\n\n // Event helpers\n\n const dragEventHasFiles = event => {\n var _event$dataTransfer;\n return Array.from(((_event$dataTransfer = event.dataTransfer) === null || _event$dataTransfer === void 0 ? void 0 : _event$dataTransfer.types) || []).includes(\"Files\");\n };\n const processableFilePaste = event => {\n var _event$dataTransfer$f;\n // Paste events that only have files are handled by the paste event handler,\n // to work around Safari not supporting beforeinput.insertFromPaste for files.\n\n // MS Office text pastes include a file with a screenshot of the text, but we should\n // handle them as text pastes.\n return ((_event$dataTransfer$f = event.dataTransfer.files) === null || _event$dataTransfer$f === void 0 ? void 0 : _event$dataTransfer$f[0]) && !pasteEventHasFilesOnly(event) && !dataTransferIsMsOfficePaste(event);\n };\n const pasteEventHasFilesOnly = function (event) {\n const clipboard = event.clipboardData;\n if (clipboard) {\n const fileTypes = Array.from(clipboard.types).filter(type => type.match(/file/i)); // \"Files\", \"application/x-moz-file\"\n return fileTypes.length === clipboard.types.length && clipboard.files.length >= 1;\n }\n };\n const pasteEventHasPlainTextOnly = function (event) {\n const clipboard = event.clipboardData;\n if (clipboard) {\n return clipboard.types.includes(\"text/plain\") && clipboard.types.length === 1;\n }\n };\n const keyboardCommandFromKeyEvent = function (event) {\n const command = [];\n if (event.altKey) {\n command.push(\"alt\");\n }\n if (event.shiftKey) {\n command.push(\"shift\");\n }\n command.push(event.key);\n return command;\n };\n const pointFromEvent = event => ({\n x: event.clientX,\n y: event.clientY\n });\n\n const attributeButtonSelector = \"[data-trix-attribute]\";\n const actionButtonSelector = \"[data-trix-action]\";\n const toolbarButtonSelector = \"\".concat(attributeButtonSelector, \", \").concat(actionButtonSelector);\n const dialogSelector = \"[data-trix-dialog]\";\n const activeDialogSelector = \"\".concat(dialogSelector, \"[data-trix-active]\");\n const dialogButtonSelector = \"\".concat(dialogSelector, \" [data-trix-method]\");\n const dialogInputSelector = \"\".concat(dialogSelector, \" [data-trix-input]\");\n const getInputForDialog = (element, attributeName) => {\n if (!attributeName) {\n attributeName = getAttributeName(element);\n }\n return element.querySelector(\"[data-trix-input][name='\".concat(attributeName, \"']\"));\n };\n const getActionName = element => element.getAttribute(\"data-trix-action\");\n const getAttributeName = element => {\n return element.getAttribute(\"data-trix-attribute\") || element.getAttribute(\"data-trix-dialog-attribute\");\n };\n const getDialogName = element => element.getAttribute(\"data-trix-dialog\");\n class ToolbarController extends BasicObject {\n constructor(element) {\n super(element);\n this.didClickActionButton = this.didClickActionButton.bind(this);\n this.didClickAttributeButton = this.didClickAttributeButton.bind(this);\n this.didClickDialogButton = this.didClickDialogButton.bind(this);\n this.didKeyDownDialogInput = this.didKeyDownDialogInput.bind(this);\n this.element = element;\n this.attributes = {};\n this.actions = {};\n this.resetDialogInputs();\n handleEvent(\"mousedown\", {\n onElement: this.element,\n matchingSelector: actionButtonSelector,\n withCallback: this.didClickActionButton\n });\n handleEvent(\"mousedown\", {\n onElement: this.element,\n matchingSelector: attributeButtonSelector,\n withCallback: this.didClickAttributeButton\n });\n handleEvent(\"click\", {\n onElement: this.element,\n matchingSelector: toolbarButtonSelector,\n preventDefault: true\n });\n handleEvent(\"click\", {\n onElement: this.element,\n matchingSelector: dialogButtonSelector,\n withCallback: this.didClickDialogButton\n });\n handleEvent(\"keydown\", {\n onElement: this.element,\n matchingSelector: dialogInputSelector,\n withCallback: this.didKeyDownDialogInput\n });\n }\n\n // Event handlers\n\n didClickActionButton(event, element) {\n var _this$delegate;\n (_this$delegate = this.delegate) === null || _this$delegate === void 0 || _this$delegate.toolbarDidClickButton();\n event.preventDefault();\n const actionName = getActionName(element);\n if (this.getDialog(actionName)) {\n return this.toggleDialog(actionName);\n } else {\n var _this$delegate2;\n return (_this$delegate2 = this.delegate) === null || _this$delegate2 === void 0 ? void 0 : _this$delegate2.toolbarDidInvokeAction(actionName, element);\n }\n }\n didClickAttributeButton(event, element) {\n var _this$delegate3;\n (_this$delegate3 = this.delegate) === null || _this$delegate3 === void 0 || _this$delegate3.toolbarDidClickButton();\n event.preventDefault();\n const attributeName = getAttributeName(element);\n if (this.getDialog(attributeName)) {\n this.toggleDialog(attributeName);\n } else {\n var _this$delegate4;\n (_this$delegate4 = this.delegate) === null || _this$delegate4 === void 0 || _this$delegate4.toolbarDidToggleAttribute(attributeName);\n }\n return this.refreshAttributeButtons();\n }\n didClickDialogButton(event, element) {\n const dialogElement = findClosestElementFromNode(element, {\n matchingSelector: dialogSelector\n });\n const method = element.getAttribute(\"data-trix-method\");\n return this[method].call(this, dialogElement);\n }\n didKeyDownDialogInput(event, element) {\n if (event.keyCode === 13) {\n // Enter key\n event.preventDefault();\n const attribute = element.getAttribute(\"name\");\n const dialog = this.getDialog(attribute);\n this.setAttribute(dialog);\n }\n if (event.keyCode === 27) {\n // Escape key\n event.preventDefault();\n return this.hideDialog();\n }\n }\n\n // Action buttons\n\n updateActions(actions) {\n this.actions = actions;\n return this.refreshActionButtons();\n }\n refreshActionButtons() {\n return this.eachActionButton((element, actionName) => {\n element.disabled = this.actions[actionName] === false;\n });\n }\n eachActionButton(callback) {\n return Array.from(this.element.querySelectorAll(actionButtonSelector)).map(element => callback(element, getActionName(element)));\n }\n\n // Attribute buttons\n\n updateAttributes(attributes) {\n this.attributes = attributes;\n return this.refreshAttributeButtons();\n }\n refreshAttributeButtons() {\n return this.eachAttributeButton((element, attributeName) => {\n element.disabled = this.attributes[attributeName] === false;\n if (this.attributes[attributeName] || this.dialogIsVisible(attributeName)) {\n element.setAttribute(\"data-trix-active\", \"\");\n return element.classList.add(\"trix-active\");\n } else {\n element.removeAttribute(\"data-trix-active\");\n return element.classList.remove(\"trix-active\");\n }\n });\n }\n eachAttributeButton(callback) {\n return Array.from(this.element.querySelectorAll(attributeButtonSelector)).map(element => callback(element, getAttributeName(element)));\n }\n applyKeyboardCommand(keys) {\n const keyString = JSON.stringify(keys.sort());\n for (const button of Array.from(this.element.querySelectorAll(\"[data-trix-key]\"))) {\n const buttonKeys = button.getAttribute(\"data-trix-key\").split(\"+\");\n const buttonKeyString = JSON.stringify(buttonKeys.sort());\n if (buttonKeyString === keyString) {\n triggerEvent(\"mousedown\", {\n onElement: button\n });\n return true;\n }\n }\n return false;\n }\n\n // Dialogs\n\n dialogIsVisible(dialogName) {\n const element = this.getDialog(dialogName);\n if (element) {\n return element.hasAttribute(\"data-trix-active\");\n }\n }\n toggleDialog(dialogName) {\n if (this.dialogIsVisible(dialogName)) {\n return this.hideDialog();\n } else {\n return this.showDialog(dialogName);\n }\n }\n showDialog(dialogName) {\n var _this$delegate5, _this$delegate6;\n this.hideDialog();\n (_this$delegate5 = this.delegate) === null || _this$delegate5 === void 0 || _this$delegate5.toolbarWillShowDialog();\n const element = this.getDialog(dialogName);\n element.setAttribute(\"data-trix-active\", \"\");\n element.classList.add(\"trix-active\");\n Array.from(element.querySelectorAll(\"input[disabled]\")).forEach(disabledInput => {\n disabledInput.removeAttribute(\"disabled\");\n });\n const attributeName = getAttributeName(element);\n if (attributeName) {\n const input = getInputForDialog(element, dialogName);\n if (input) {\n input.value = this.attributes[attributeName] || \"\";\n input.select();\n }\n }\n return (_this$delegate6 = this.delegate) === null || _this$delegate6 === void 0 ? void 0 : _this$delegate6.toolbarDidShowDialog(dialogName);\n }\n setAttribute(dialogElement) {\n const attributeName = getAttributeName(dialogElement);\n const input = getInputForDialog(dialogElement, attributeName);\n if (input.willValidate && !input.checkValidity()) {\n input.setAttribute(\"data-trix-validate\", \"\");\n input.classList.add(\"trix-validate\");\n return input.focus();\n } else {\n var _this$delegate7;\n (_this$delegate7 = this.delegate) === null || _this$delegate7 === void 0 || _this$delegate7.toolbarDidUpdateAttribute(attributeName, input.value);\n return this.hideDialog();\n }\n }\n removeAttribute(dialogElement) {\n var _this$delegate8;\n const attributeName = getAttributeName(dialogElement);\n (_this$delegate8 = this.delegate) === null || _this$delegate8 === void 0 || _this$delegate8.toolbarDidRemoveAttribute(attributeName);\n return this.hideDialog();\n }\n hideDialog() {\n const element = this.element.querySelector(activeDialogSelector);\n if (element) {\n var _this$delegate9;\n element.removeAttribute(\"data-trix-active\");\n element.classList.remove(\"trix-active\");\n this.resetDialogInputs();\n return (_this$delegate9 = this.delegate) === null || _this$delegate9 === void 0 ? void 0 : _this$delegate9.toolbarDidHideDialog(getDialogName(element));\n }\n }\n resetDialogInputs() {\n Array.from(this.element.querySelectorAll(dialogInputSelector)).forEach(input => {\n input.setAttribute(\"disabled\", \"disabled\");\n input.removeAttribute(\"data-trix-validate\");\n input.classList.remove(\"trix-validate\");\n });\n }\n getDialog(dialogName) {\n return this.element.querySelector(\"[data-trix-dialog=\".concat(dialogName, \"]\"));\n }\n }\n\n const snapshotsAreEqual = (a, b) => rangesAreEqual(a.selectedRange, b.selectedRange) && a.document.isEqualTo(b.document);\n class EditorController extends Controller {\n constructor(_ref) {\n let {\n editorElement,\n document,\n html\n } = _ref;\n super(...arguments);\n this.editorElement = editorElement;\n this.selectionManager = new SelectionManager(this.editorElement);\n this.selectionManager.delegate = this;\n this.composition = new Composition();\n this.composition.delegate = this;\n this.attachmentManager = new AttachmentManager(this.composition.getAttachments());\n this.attachmentManager.delegate = this;\n this.inputController = input.getLevel() === 2 ? new Level2InputController(this.editorElement) : new Level0InputController(this.editorElement);\n this.inputController.delegate = this;\n this.inputController.responder = this.composition;\n this.compositionController = new CompositionController(this.editorElement, this.composition);\n this.compositionController.delegate = this;\n this.toolbarController = new ToolbarController(this.editorElement.toolbarElement);\n this.toolbarController.delegate = this;\n this.editor = new Editor(this.composition, this.selectionManager, this.editorElement);\n if (document) {\n this.editor.loadDocument(document);\n } else {\n this.editor.loadHTML(html);\n }\n }\n registerSelectionManager() {\n return selectionChangeObserver.registerSelectionManager(this.selectionManager);\n }\n unregisterSelectionManager() {\n return selectionChangeObserver.unregisterSelectionManager(this.selectionManager);\n }\n render() {\n return this.compositionController.render();\n }\n reparse() {\n return this.composition.replaceHTML(this.editorElement.innerHTML);\n }\n\n // Composition delegate\n\n compositionDidChangeDocument(document) {\n this.notifyEditorElement(\"document-change\");\n if (!this.handlingInput) {\n return this.render();\n }\n }\n compositionDidChangeCurrentAttributes(currentAttributes) {\n this.currentAttributes = currentAttributes;\n this.toolbarController.updateAttributes(this.currentAttributes);\n this.updateCurrentActions();\n return this.notifyEditorElement(\"attributes-change\", {\n attributes: this.currentAttributes\n });\n }\n compositionDidPerformInsertionAtRange(range) {\n if (this.pasting) {\n this.pastedRange = range;\n }\n }\n compositionShouldAcceptFile(file) {\n return this.notifyEditorElement(\"file-accept\", {\n file\n });\n }\n compositionDidAddAttachment(attachment) {\n const managedAttachment = this.attachmentManager.manageAttachment(attachment);\n return this.notifyEditorElement(\"attachment-add\", {\n attachment: managedAttachment\n });\n }\n compositionDidEditAttachment(attachment) {\n this.compositionController.rerenderViewForObject(attachment);\n const managedAttachment = this.attachmentManager.manageAttachment(attachment);\n this.notifyEditorElement(\"attachment-edit\", {\n attachment: managedAttachment\n });\n return this.notifyEditorElement(\"change\");\n }\n compositionDidChangeAttachmentPreviewURL(attachment) {\n this.compositionController.invalidateViewForObject(attachment);\n return this.notifyEditorElement(\"change\");\n }\n compositionDidRemoveAttachment(attachment) {\n const managedAttachment = this.attachmentManager.unmanageAttachment(attachment);\n return this.notifyEditorElement(\"attachment-remove\", {\n attachment: managedAttachment\n });\n }\n compositionDidStartEditingAttachment(attachment, options) {\n this.attachmentLocationRange = this.composition.document.getLocationRangeOfAttachment(attachment);\n this.compositionController.installAttachmentEditorForAttachment(attachment, options);\n return this.selectionManager.setLocationRange(this.attachmentLocationRange);\n }\n compositionDidStopEditingAttachment(attachment) {\n this.compositionController.uninstallAttachmentEditor();\n this.attachmentLocationRange = null;\n }\n compositionDidRequestChangingSelectionToLocationRange(locationRange) {\n if (this.loadingSnapshot && !this.isFocused()) return;\n this.requestedLocationRange = locationRange;\n this.compositionRevisionWhenLocationRangeRequested = this.composition.revision;\n if (!this.handlingInput) {\n return this.render();\n }\n }\n compositionWillLoadSnapshot() {\n this.loadingSnapshot = true;\n }\n compositionDidLoadSnapshot() {\n this.compositionController.refreshViewCache();\n this.render();\n this.loadingSnapshot = false;\n }\n getSelectionManager() {\n return this.selectionManager;\n }\n\n // Attachment manager delegate\n\n attachmentManagerDidRequestRemovalOfAttachment(attachment) {\n return this.removeAttachment(attachment);\n }\n\n // Document controller delegate\n\n compositionControllerWillSyncDocumentView() {\n this.inputController.editorWillSyncDocumentView();\n this.selectionManager.lock();\n return this.selectionManager.clearSelection();\n }\n compositionControllerDidSyncDocumentView() {\n this.inputController.editorDidSyncDocumentView();\n this.selectionManager.unlock();\n this.updateCurrentActions();\n return this.notifyEditorElement(\"sync\");\n }\n compositionControllerDidRender() {\n if (this.requestedLocationRange) {\n if (this.compositionRevisionWhenLocationRangeRequested === this.composition.revision) {\n this.selectionManager.setLocationRange(this.requestedLocationRange);\n }\n this.requestedLocationRange = null;\n this.compositionRevisionWhenLocationRangeRequested = null;\n }\n if (this.renderedCompositionRevision !== this.composition.revision) {\n this.runEditorFilters();\n this.composition.updateCurrentAttributes();\n this.notifyEditorElement(\"render\");\n }\n this.renderedCompositionRevision = this.composition.revision;\n }\n compositionControllerDidFocus() {\n if (this.isFocusedInvisibly()) {\n this.setLocationRange({\n index: 0,\n offset: 0\n });\n }\n this.toolbarController.hideDialog();\n return this.notifyEditorElement(\"focus\");\n }\n compositionControllerDidBlur() {\n return this.notifyEditorElement(\"blur\");\n }\n compositionControllerDidSelectAttachment(attachment, options) {\n this.toolbarController.hideDialog();\n return this.composition.editAttachment(attachment, options);\n }\n compositionControllerDidRequestDeselectingAttachment(attachment) {\n const locationRange = this.attachmentLocationRange || this.composition.document.getLocationRangeOfAttachment(attachment);\n return this.selectionManager.setLocationRange(locationRange[1]);\n }\n compositionControllerWillUpdateAttachment(attachment) {\n return this.editor.recordUndoEntry(\"Edit Attachment\", {\n context: attachment.id,\n consolidatable: true\n });\n }\n compositionControllerDidRequestRemovalOfAttachment(attachment) {\n return this.removeAttachment(attachment);\n }\n\n // Input controller delegate\n\n inputControllerWillHandleInput() {\n this.handlingInput = true;\n this.requestedRender = false;\n }\n inputControllerDidRequestRender() {\n this.requestedRender = true;\n }\n inputControllerDidHandleInput() {\n this.handlingInput = false;\n if (this.requestedRender) {\n this.requestedRender = false;\n return this.render();\n }\n }\n inputControllerDidAllowUnhandledInput() {\n return this.notifyEditorElement(\"change\");\n }\n inputControllerDidRequestReparse() {\n return this.reparse();\n }\n inputControllerWillPerformTyping() {\n return this.recordTypingUndoEntry();\n }\n inputControllerWillPerformFormatting(attributeName) {\n return this.recordFormattingUndoEntry(attributeName);\n }\n inputControllerWillCutText() {\n return this.editor.recordUndoEntry(\"Cut\");\n }\n inputControllerWillPaste(paste) {\n this.editor.recordUndoEntry(\"Paste\");\n this.pasting = true;\n return this.notifyEditorElement(\"before-paste\", {\n paste\n });\n }\n inputControllerDidPaste(paste) {\n paste.range = this.pastedRange;\n this.pastedRange = null;\n this.pasting = null;\n return this.notifyEditorElement(\"paste\", {\n paste\n });\n }\n inputControllerWillMoveText() {\n return this.editor.recordUndoEntry(\"Move\");\n }\n inputControllerWillAttachFiles() {\n return this.editor.recordUndoEntry(\"Drop Files\");\n }\n inputControllerWillPerformUndo() {\n return this.editor.undo();\n }\n inputControllerWillPerformRedo() {\n return this.editor.redo();\n }\n inputControllerDidReceiveKeyboardCommand(keys) {\n return this.toolbarController.applyKeyboardCommand(keys);\n }\n inputControllerDidStartDrag() {\n this.locationRangeBeforeDrag = this.selectionManager.getLocationRange();\n }\n inputControllerDidReceiveDragOverPoint(point) {\n return this.selectionManager.setLocationRangeFromPointRange(point);\n }\n inputControllerDidCancelDrag() {\n this.selectionManager.setLocationRange(this.locationRangeBeforeDrag);\n this.locationRangeBeforeDrag = null;\n }\n\n // Selection manager delegate\n\n locationRangeDidChange(locationRange) {\n this.composition.updateCurrentAttributes();\n this.updateCurrentActions();\n if (this.attachmentLocationRange && !rangesAreEqual(this.attachmentLocationRange, locationRange)) {\n this.composition.stopEditingAttachment();\n }\n return this.notifyEditorElement(\"selection-change\");\n }\n\n // Toolbar controller delegate\n\n toolbarDidClickButton() {\n if (!this.getLocationRange()) {\n return this.setLocationRange({\n index: 0,\n offset: 0\n });\n }\n }\n toolbarDidInvokeAction(actionName, invokingElement) {\n return this.invokeAction(actionName, invokingElement);\n }\n toolbarDidToggleAttribute(attributeName) {\n this.recordFormattingUndoEntry(attributeName);\n this.composition.toggleCurrentAttribute(attributeName);\n this.render();\n if (!this.selectionFrozen) {\n return this.editorElement.focus();\n }\n }\n toolbarDidUpdateAttribute(attributeName, value) {\n this.recordFormattingUndoEntry(attributeName);\n this.composition.setCurrentAttribute(attributeName, value);\n this.render();\n if (!this.selectionFrozen) {\n return this.editorElement.focus();\n }\n }\n toolbarDidRemoveAttribute(attributeName) {\n this.recordFormattingUndoEntry(attributeName);\n this.composition.removeCurrentAttribute(attributeName);\n this.render();\n if (!this.selectionFrozen) {\n return this.editorElement.focus();\n }\n }\n toolbarWillShowDialog(dialogElement) {\n this.composition.expandSelectionForEditing();\n return this.freezeSelection();\n }\n toolbarDidShowDialog(dialogName) {\n return this.notifyEditorElement(\"toolbar-dialog-show\", {\n dialogName\n });\n }\n toolbarDidHideDialog(dialogName) {\n this.thawSelection();\n this.editorElement.focus();\n return this.notifyEditorElement(\"toolbar-dialog-hide\", {\n dialogName\n });\n }\n\n // Selection\n\n freezeSelection() {\n if (!this.selectionFrozen) {\n this.selectionManager.lock();\n this.composition.freezeSelection();\n this.selectionFrozen = true;\n return this.render();\n }\n }\n thawSelection() {\n if (this.selectionFrozen) {\n this.composition.thawSelection();\n this.selectionManager.unlock();\n this.selectionFrozen = false;\n return this.render();\n }\n }\n canInvokeAction(actionName) {\n if (this.actionIsExternal(actionName)) {\n return true;\n } else {\n var _this$actions$actionN;\n return !!((_this$actions$actionN = this.actions[actionName]) !== null && _this$actions$actionN !== void 0 && (_this$actions$actionN = _this$actions$actionN.test) !== null && _this$actions$actionN !== void 0 && _this$actions$actionN.call(this));\n }\n }\n invokeAction(actionName, invokingElement) {\n if (this.actionIsExternal(actionName)) {\n return this.notifyEditorElement(\"action-invoke\", {\n actionName,\n invokingElement\n });\n } else {\n var _this$actions$actionN2;\n return (_this$actions$actionN2 = this.actions[actionName]) === null || _this$actions$actionN2 === void 0 || (_this$actions$actionN2 = _this$actions$actionN2.perform) === null || _this$actions$actionN2 === void 0 ? void 0 : _this$actions$actionN2.call(this);\n }\n }\n actionIsExternal(actionName) {\n return /^x-./.test(actionName);\n }\n getCurrentActions() {\n const result = {};\n for (const actionName in this.actions) {\n result[actionName] = this.canInvokeAction(actionName);\n }\n return result;\n }\n updateCurrentActions() {\n const currentActions = this.getCurrentActions();\n if (!objectsAreEqual(currentActions, this.currentActions)) {\n this.currentActions = currentActions;\n this.toolbarController.updateActions(this.currentActions);\n return this.notifyEditorElement(\"actions-change\", {\n actions: this.currentActions\n });\n }\n }\n\n // Editor filters\n\n runEditorFilters() {\n let snapshot = this.composition.getSnapshot();\n Array.from(this.editor.filters).forEach(filter => {\n const {\n document,\n selectedRange\n } = snapshot;\n snapshot = filter.call(this.editor, snapshot) || {};\n if (!snapshot.document) {\n snapshot.document = document;\n }\n if (!snapshot.selectedRange) {\n snapshot.selectedRange = selectedRange;\n }\n });\n if (!snapshotsAreEqual(snapshot, this.composition.getSnapshot())) {\n return this.composition.loadSnapshot(snapshot);\n }\n }\n\n // Private\n\n updateInputElement() {\n const element = this.compositionController.getSerializableElement();\n const value = serializeToContentType(element, \"text/html\");\n return this.editorElement.setFormValue(value);\n }\n notifyEditorElement(message, data) {\n switch (message) {\n case \"document-change\":\n this.documentChangedSinceLastRender = true;\n break;\n case \"render\":\n if (this.documentChangedSinceLastRender) {\n this.documentChangedSinceLastRender = false;\n this.notifyEditorElement(\"change\");\n }\n break;\n case \"change\":\n case \"attachment-add\":\n case \"attachment-edit\":\n case \"attachment-remove\":\n this.updateInputElement();\n break;\n }\n return this.editorElement.notify(message, data);\n }\n removeAttachment(attachment) {\n this.editor.recordUndoEntry(\"Delete Attachment\");\n this.composition.removeAttachment(attachment);\n return this.render();\n }\n recordFormattingUndoEntry(attributeName) {\n const blockConfig = getBlockConfig(attributeName);\n const locationRange = this.selectionManager.getLocationRange();\n if (blockConfig || !rangeIsCollapsed(locationRange)) {\n return this.editor.recordUndoEntry(\"Formatting\", {\n context: this.getUndoContext(),\n consolidatable: true\n });\n }\n }\n recordTypingUndoEntry() {\n return this.editor.recordUndoEntry(\"Typing\", {\n context: this.getUndoContext(this.currentAttributes),\n consolidatable: true\n });\n }\n getUndoContext() {\n for (var _len = arguments.length, context = new Array(_len), _key = 0; _key < _len; _key++) {\n context[_key] = arguments[_key];\n }\n return [this.getLocationContext(), this.getTimeContext(), ...Array.from(context)];\n }\n getLocationContext() {\n const locationRange = this.selectionManager.getLocationRange();\n if (rangeIsCollapsed(locationRange)) {\n return locationRange[0].index;\n } else {\n return locationRange;\n }\n }\n getTimeContext() {\n if (undo.interval > 0) {\n return Math.floor(new Date().getTime() / undo.interval);\n } else {\n return 0;\n }\n }\n isFocused() {\n var _this$editorElement$o;\n return this.editorElement === ((_this$editorElement$o = this.editorElement.ownerDocument) === null || _this$editorElement$o === void 0 ? void 0 : _this$editorElement$o.activeElement);\n }\n\n // Detect \"Cursor disappears sporadically\" Firefox bug.\n // - https://bugzilla.mozilla.org/show_bug.cgi?id=226301\n isFocusedInvisibly() {\n return this.isFocused() && !this.getLocationRange();\n }\n get actions() {\n return this.constructor.actions;\n }\n }\n _defineProperty(EditorController, \"actions\", {\n undo: {\n test() {\n return this.editor.canUndo();\n },\n perform() {\n return this.editor.undo();\n }\n },\n redo: {\n test() {\n return this.editor.canRedo();\n },\n perform() {\n return this.editor.redo();\n }\n },\n link: {\n test() {\n return this.editor.canActivateAttribute(\"href\");\n }\n },\n increaseNestingLevel: {\n test() {\n return this.editor.canIncreaseNestingLevel();\n },\n perform() {\n return this.editor.increaseNestingLevel() && this.render();\n }\n },\n decreaseNestingLevel: {\n test() {\n return this.editor.canDecreaseNestingLevel();\n },\n perform() {\n return this.editor.decreaseNestingLevel() && this.render();\n }\n },\n attachFiles: {\n test() {\n return true;\n },\n perform() {\n return input.pickFiles(this.editor.insertFiles);\n }\n }\n });\n EditorController.proxyMethod(\"getSelectionManager().setLocationRange\");\n EditorController.proxyMethod(\"getSelectionManager().getLocationRange\");\n\n var controllers = /*#__PURE__*/Object.freeze({\n __proto__: null,\n AttachmentEditorController: AttachmentEditorController,\n CompositionController: CompositionController,\n Controller: Controller,\n EditorController: EditorController,\n InputController: InputController,\n Level0InputController: Level0InputController,\n Level2InputController: Level2InputController,\n ToolbarController: ToolbarController\n });\n\n var observers = /*#__PURE__*/Object.freeze({\n __proto__: null,\n MutationObserver: MutationObserver,\n SelectionChangeObserver: SelectionChangeObserver\n });\n\n var operations = /*#__PURE__*/Object.freeze({\n __proto__: null,\n FileVerificationOperation: FileVerificationOperation,\n ImagePreloadOperation: ImagePreloadOperation\n });\n\n installDefaultCSSForTagName(\"trix-toolbar\", \"%t {\\n display: block;\\n}\\n\\n%t {\\n white-space: nowrap;\\n}\\n\\n%t [data-trix-dialog] {\\n display: none;\\n}\\n\\n%t [data-trix-dialog][data-trix-active] {\\n display: block;\\n}\\n\\n%t [data-trix-dialog] [data-trix-validate]:invalid {\\n background-color: #ffdddd;\\n}\");\n class TrixToolbarElement extends HTMLElement {\n // Element lifecycle\n\n connectedCallback() {\n if (this.innerHTML === \"\") {\n this.innerHTML = toolbar.getDefaultHTML();\n }\n }\n }\n\n let id = 0;\n\n // Contenteditable support helpers\n\n const autofocus = function (element) {\n if (!document.querySelector(\":focus\")) {\n if (element.hasAttribute(\"autofocus\") && document.querySelector(\"[autofocus]\") === element) {\n return element.focus();\n }\n }\n };\n const makeEditable = function (element) {\n if (element.hasAttribute(\"contenteditable\")) {\n return;\n }\n element.setAttribute(\"contenteditable\", \"\");\n return handleEventOnce(\"focus\", {\n onElement: element,\n withCallback() {\n return configureContentEditable(element);\n }\n });\n };\n const configureContentEditable = function (element) {\n disableObjectResizing(element);\n return setDefaultParagraphSeparator(element);\n };\n const disableObjectResizing = function (element) {\n var _document$queryComman, _document;\n if ((_document$queryComman = (_document = document).queryCommandSupported) !== null && _document$queryComman !== void 0 && _document$queryComman.call(_document, \"enableObjectResizing\")) {\n document.execCommand(\"enableObjectResizing\", false, false);\n return handleEvent(\"mscontrolselect\", {\n onElement: element,\n preventDefault: true\n });\n }\n };\n const setDefaultParagraphSeparator = function (element) {\n var _document$queryComman2, _document2;\n if ((_document$queryComman2 = (_document2 = document).queryCommandSupported) !== null && _document$queryComman2 !== void 0 && _document$queryComman2.call(_document2, \"DefaultParagraphSeparator\")) {\n const {\n tagName\n } = attributes.default;\n if ([\"div\", \"p\"].includes(tagName)) {\n return document.execCommand(\"DefaultParagraphSeparator\", false, tagName);\n }\n }\n };\n\n // Accessibility helpers\n\n const addAccessibilityRole = function (element) {\n if (element.hasAttribute(\"role\")) {\n return;\n }\n return element.setAttribute(\"role\", \"textbox\");\n };\n const ensureAriaLabel = function (element) {\n if (element.hasAttribute(\"aria-label\") || element.hasAttribute(\"aria-labelledby\")) {\n return;\n }\n const update = function () {\n const texts = Array.from(element.labels).map(label => {\n if (!label.contains(element)) return label.textContent;\n }).filter(text => text);\n const text = texts.join(\" \");\n if (text) {\n return element.setAttribute(\"aria-label\", text);\n } else {\n return element.removeAttribute(\"aria-label\");\n }\n };\n update();\n return handleEvent(\"focus\", {\n onElement: element,\n withCallback: update\n });\n };\n\n // Style\n\n const cursorTargetStyles = function () {\n if (browser$1.forcesObjectResizing) {\n return {\n display: \"inline\",\n width: \"auto\"\n };\n } else {\n return {\n display: \"inline-block\",\n width: \"1px\"\n };\n }\n }();\n installDefaultCSSForTagName(\"trix-editor\", \"%t {\\n display: block;\\n}\\n\\n%t:empty::before {\\n content: attr(placeholder);\\n color: graytext;\\n cursor: text;\\n pointer-events: none;\\n white-space: pre-line;\\n}\\n\\n%t a[contenteditable=false] {\\n cursor: text;\\n}\\n\\n%t img {\\n max-width: 100%;\\n height: auto;\\n}\\n\\n%t \".concat(attachmentSelector, \" figcaption textarea {\\n resize: none;\\n}\\n\\n%t \").concat(attachmentSelector, \" figcaption textarea.trix-autoresize-clone {\\n position: absolute;\\n left: -9999px;\\n max-height: 0px;\\n}\\n\\n%t \").concat(attachmentSelector, \" figcaption[data-trix-placeholder]:empty::before {\\n content: attr(data-trix-placeholder);\\n color: graytext;\\n}\\n\\n%t [data-trix-cursor-target] {\\n display: \").concat(cursorTargetStyles.display, \" !important;\\n width: \").concat(cursorTargetStyles.width, \" !important;\\n padding: 0 !important;\\n margin: 0 !important;\\n border: none !important;\\n}\\n\\n%t [data-trix-cursor-target=left] {\\n vertical-align: top !important;\\n margin-left: -1px !important;\\n}\\n\\n%t [data-trix-cursor-target=right] {\\n vertical-align: bottom !important;\\n margin-right: -1px !important;\\n}\"));\n var _internals = /*#__PURE__*/new WeakMap();\n var _validate = /*#__PURE__*/new WeakSet();\n class ElementInternalsDelegate {\n constructor(element) {\n _classPrivateMethodInitSpec(this, _validate);\n _classPrivateFieldInitSpec(this, _internals, {\n writable: true,\n value: void 0\n });\n this.element = element;\n _classPrivateFieldSet(this, _internals, element.attachInternals());\n }\n connectedCallback() {\n _classPrivateMethodGet(this, _validate, _validate2).call(this);\n }\n disconnectedCallback() {}\n get labels() {\n return _classPrivateFieldGet(this, _internals).labels;\n }\n get disabled() {\n var _this$element$inputEl;\n return (_this$element$inputEl = this.element.inputElement) === null || _this$element$inputEl === void 0 ? void 0 : _this$element$inputEl.disabled;\n }\n set disabled(value) {\n this.element.toggleAttribute(\"disabled\", value);\n }\n get required() {\n return this.element.hasAttribute(\"required\");\n }\n set required(value) {\n this.element.toggleAttribute(\"required\", value);\n _classPrivateMethodGet(this, _validate, _validate2).call(this);\n }\n get validity() {\n return _classPrivateFieldGet(this, _internals).validity;\n }\n get validationMessage() {\n return _classPrivateFieldGet(this, _internals).validationMessage;\n }\n get willValidate() {\n return _classPrivateFieldGet(this, _internals).willValidate;\n }\n setFormValue(value) {\n _classPrivateMethodGet(this, _validate, _validate2).call(this);\n }\n checkValidity() {\n return _classPrivateFieldGet(this, _internals).checkValidity();\n }\n reportValidity() {\n return _classPrivateFieldGet(this, _internals).reportValidity();\n }\n setCustomValidity(validationMessage) {\n _classPrivateMethodGet(this, _validate, _validate2).call(this, validationMessage);\n }\n }\n function _validate2() {\n let customValidationMessage = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : \"\";\n const {\n required,\n value\n } = this.element;\n const valueMissing = required && !value;\n const customError = !!customValidationMessage;\n const input = makeElement(\"input\", {\n required\n });\n const validationMessage = customValidationMessage || input.validationMessage;\n _classPrivateFieldGet(this, _internals).setValidity({\n valueMissing,\n customError\n }, validationMessage);\n }\n var _focusHandler = /*#__PURE__*/new WeakMap();\n var _resetBubbled = /*#__PURE__*/new WeakMap();\n var _clickBubbled = /*#__PURE__*/new WeakMap();\n class LegacyDelegate {\n constructor(element) {\n _classPrivateFieldInitSpec(this, _focusHandler, {\n writable: true,\n value: void 0\n });\n _classPrivateFieldInitSpec(this, _resetBubbled, {\n writable: true,\n value: event => {\n if (event.defaultPrevented) return;\n if (event.target !== this.element.form) return;\n this.element.reset();\n }\n });\n _classPrivateFieldInitSpec(this, _clickBubbled, {\n writable: true,\n value: event => {\n if (event.defaultPrevented) return;\n if (this.element.contains(event.target)) return;\n const label = findClosestElementFromNode(event.target, {\n matchingSelector: \"label\"\n });\n if (!label) return;\n if (!Array.from(this.labels).includes(label)) return;\n this.element.focus();\n }\n });\n this.element = element;\n }\n connectedCallback() {\n _classPrivateFieldSet(this, _focusHandler, ensureAriaLabel(this.element));\n window.addEventListener(\"reset\", _classPrivateFieldGet(this, _resetBubbled), false);\n window.addEventListener(\"click\", _classPrivateFieldGet(this, _clickBubbled), false);\n }\n disconnectedCallback() {\n var _classPrivateFieldGet2;\n (_classPrivateFieldGet2 = _classPrivateFieldGet(this, _focusHandler)) === null || _classPrivateFieldGet2 === void 0 || _classPrivateFieldGet2.destroy();\n window.removeEventListener(\"reset\", _classPrivateFieldGet(this, _resetBubbled), false);\n window.removeEventListener(\"click\", _classPrivateFieldGet(this, _clickBubbled), false);\n }\n get labels() {\n const labels = [];\n if (this.element.id && this.element.ownerDocument) {\n labels.push(...Array.from(this.element.ownerDocument.querySelectorAll(\"label[for='\".concat(this.element.id, \"']\")) || []));\n }\n const label = findClosestElementFromNode(this.element, {\n matchingSelector: \"label\"\n });\n if (label) {\n if ([this.element, null].includes(label.control)) {\n labels.push(label);\n }\n }\n return labels;\n }\n get disabled() {\n console.warn(\"This browser does not support the [disabled] attribute for trix-editor elements.\");\n return false;\n }\n set disabled(value) {\n console.warn(\"This browser does not support the [disabled] attribute for trix-editor elements.\");\n }\n get required() {\n console.warn(\"This browser does not support the [required] attribute for trix-editor elements.\");\n return false;\n }\n set required(value) {\n console.warn(\"This browser does not support the [required] attribute for trix-editor elements.\");\n }\n get validity() {\n console.warn(\"This browser does not support the validity property for trix-editor elements.\");\n return null;\n }\n get validationMessage() {\n console.warn(\"This browser does not support the validationMessage property for trix-editor elements.\");\n return \"\";\n }\n get willValidate() {\n console.warn(\"This browser does not support the willValidate property for trix-editor elements.\");\n return false;\n }\n setFormValue(value) {}\n checkValidity() {\n console.warn(\"This browser does not support checkValidity() for trix-editor elements.\");\n return true;\n }\n reportValidity() {\n console.warn(\"This browser does not support reportValidity() for trix-editor elements.\");\n return true;\n }\n setCustomValidity(validationMessage) {\n console.warn(\"This browser does not support setCustomValidity(validationMessage) for trix-editor elements.\");\n }\n }\n var _delegate = /*#__PURE__*/new WeakMap();\n class TrixEditorElement extends HTMLElement {\n constructor() {\n super();\n _classPrivateFieldInitSpec(this, _delegate, {\n writable: true,\n value: void 0\n });\n _classPrivateFieldSet(this, _delegate, this.constructor.formAssociated ? new ElementInternalsDelegate(this) : new LegacyDelegate(this));\n }\n\n // Properties\n\n get trixId() {\n if (this.hasAttribute(\"trix-id\")) {\n return this.getAttribute(\"trix-id\");\n } else {\n this.setAttribute(\"trix-id\", ++id);\n return this.trixId;\n }\n }\n get labels() {\n return _classPrivateFieldGet(this, _delegate).labels;\n }\n get disabled() {\n return _classPrivateFieldGet(this, _delegate).disabled;\n }\n set disabled(value) {\n _classPrivateFieldGet(this, _delegate).disabled = value;\n }\n get required() {\n return _classPrivateFieldGet(this, _delegate).required;\n }\n set required(value) {\n _classPrivateFieldGet(this, _delegate).required = value;\n }\n get validity() {\n return _classPrivateFieldGet(this, _delegate).validity;\n }\n get validationMessage() {\n return _classPrivateFieldGet(this, _delegate).validationMessage;\n }\n get willValidate() {\n return _classPrivateFieldGet(this, _delegate).willValidate;\n }\n get type() {\n return this.localName;\n }\n get toolbarElement() {\n if (this.hasAttribute(\"toolbar\")) {\n var _this$ownerDocument;\n return (_this$ownerDocument = this.ownerDocument) === null || _this$ownerDocument === void 0 ? void 0 : _this$ownerDocument.getElementById(this.getAttribute(\"toolbar\"));\n } else if (this.parentNode) {\n const toolbarId = \"trix-toolbar-\".concat(this.trixId);\n this.setAttribute(\"toolbar\", toolbarId);\n const element = makeElement(\"trix-toolbar\", {\n id: toolbarId\n });\n this.parentNode.insertBefore(element, this);\n return element;\n } else {\n return undefined;\n }\n }\n get form() {\n var _this$inputElement;\n return (_this$inputElement = this.inputElement) === null || _this$inputElement === void 0 ? void 0 : _this$inputElement.form;\n }\n get inputElement() {\n if (this.hasAttribute(\"input\")) {\n var _this$ownerDocument2;\n return (_this$ownerDocument2 = this.ownerDocument) === null || _this$ownerDocument2 === void 0 ? void 0 : _this$ownerDocument2.getElementById(this.getAttribute(\"input\"));\n } else if (this.parentNode) {\n const inputId = \"trix-input-\".concat(this.trixId);\n this.setAttribute(\"input\", inputId);\n const element = makeElement(\"input\", {\n type: \"hidden\",\n id: inputId\n });\n this.parentNode.insertBefore(element, this.nextElementSibling);\n return element;\n } else {\n return undefined;\n }\n }\n get editor() {\n var _this$editorControlle;\n return (_this$editorControlle = this.editorController) === null || _this$editorControlle === void 0 ? void 0 : _this$editorControlle.editor;\n }\n get name() {\n var _this$inputElement2;\n return (_this$inputElement2 = this.inputElement) === null || _this$inputElement2 === void 0 ? void 0 : _this$inputElement2.name;\n }\n get value() {\n var _this$inputElement3;\n return (_this$inputElement3 = this.inputElement) === null || _this$inputElement3 === void 0 ? void 0 : _this$inputElement3.value;\n }\n set value(defaultValue) {\n var _this$editor;\n this.defaultValue = defaultValue;\n (_this$editor = this.editor) === null || _this$editor === void 0 || _this$editor.loadHTML(this.defaultValue);\n }\n\n // Controller delegate methods\n\n notify(message, data) {\n if (this.editorController) {\n return triggerEvent(\"trix-\".concat(message), {\n onElement: this,\n attributes: data\n });\n }\n }\n setFormValue(value) {\n if (this.inputElement) {\n this.inputElement.value = value;\n _classPrivateFieldGet(this, _delegate).setFormValue(value);\n }\n }\n\n // Element lifecycle\n\n connectedCallback() {\n if (!this.hasAttribute(\"data-trix-internal\")) {\n makeEditable(this);\n addAccessibilityRole(this);\n if (!this.editorController) {\n triggerEvent(\"trix-before-initialize\", {\n onElement: this\n });\n this.editorController = new EditorController({\n editorElement: this,\n html: this.defaultValue = this.value\n });\n requestAnimationFrame(() => triggerEvent(\"trix-initialize\", {\n onElement: this\n }));\n }\n this.editorController.registerSelectionManager();\n _classPrivateFieldGet(this, _delegate).connectedCallback();\n autofocus(this);\n }\n }\n disconnectedCallback() {\n var _this$editorControlle2;\n (_this$editorControlle2 = this.editorController) === null || _this$editorControlle2 === void 0 || _this$editorControlle2.unregisterSelectionManager();\n _classPrivateFieldGet(this, _delegate).disconnectedCallback();\n }\n\n // Form support\n\n checkValidity() {\n return _classPrivateFieldGet(this, _delegate).checkValidity();\n }\n reportValidity() {\n return _classPrivateFieldGet(this, _delegate).reportValidity();\n }\n setCustomValidity(validationMessage) {\n _classPrivateFieldGet(this, _delegate).setCustomValidity(validationMessage);\n }\n formDisabledCallback(disabled) {\n if (this.inputElement) {\n this.inputElement.disabled = disabled;\n }\n this.toggleAttribute(\"contenteditable\", !disabled);\n }\n formResetCallback() {\n this.reset();\n }\n reset() {\n this.value = this.defaultValue;\n }\n }\n _defineProperty(TrixEditorElement, \"formAssociated\", \"ElementInternals\" in window);\n\n var elements = /*#__PURE__*/Object.freeze({\n __proto__: null,\n TrixEditorElement: TrixEditorElement,\n TrixToolbarElement: TrixToolbarElement\n });\n\n var filters = /*#__PURE__*/Object.freeze({\n __proto__: null,\n Filter: Filter,\n attachmentGalleryFilter: attachmentGalleryFilter\n });\n\n const Trix = {\n VERSION: version,\n config,\n core,\n models,\n views,\n controllers,\n observers,\n operations,\n elements,\n filters\n };\n\n // Expose models under the Trix constant for compatibility with v1\n Object.assign(Trix, models);\n function start() {\n if (!customElements.get(\"trix-toolbar\")) {\n customElements.define(\"trix-toolbar\", TrixToolbarElement);\n }\n if (!customElements.get(\"trix-editor\")) {\n customElements.define(\"trix-editor\", TrixEditorElement);\n }\n }\n window.Trix = Trix;\n setTimeout(start, 0);\n\n return Trix;\n\n}));\n/* eslint-enable */\n", "/* eslint-disable */\n(function(factory) {\n typeof define === \"function\" && define.amd ? define(factory) : factory();\n})((function() {\n \"use strict\";\n var sparkMd5 = {\n exports: {}\n };\n (function(module, exports) {\n (function(factory) {\n {\n module.exports = factory();\n }\n })((function(undefined$1) {\n var hex_chr = [ \"0\", \"1\", \"2\", \"3\", \"4\", \"5\", \"6\", \"7\", \"8\", \"9\", \"a\", \"b\", \"c\", \"d\", \"e\", \"f\" ];\n function md5cycle(x, k) {\n var a = x[0], b = x[1], c = x[2], d = x[3];\n a += (b & c | ~b & d) + k[0] - 680876936 | 0;\n a = (a << 7 | a >>> 25) + b | 0;\n d += (a & b | ~a & c) + k[1] - 389564586 | 0;\n d = (d << 12 | d >>> 20) + a | 0;\n c += (d & a | ~d & b) + k[2] + 606105819 | 0;\n c = (c << 17 | c >>> 15) + d | 0;\n b += (c & d | ~c & a) + k[3] - 1044525330 | 0;\n b = (b << 22 | b >>> 10) + c | 0;\n a += (b & c | ~b & d) + k[4] - 176418897 | 0;\n a = (a << 7 | a >>> 25) + b | 0;\n d += (a & b | ~a & c) + k[5] + 1200080426 | 0;\n d = (d << 12 | d >>> 20) + a | 0;\n c += (d & a | ~d & b) + k[6] - 1473231341 | 0;\n c = (c << 17 | c >>> 15) + d | 0;\n b += (c & d | ~c & a) + k[7] - 45705983 | 0;\n b = (b << 22 | b >>> 10) + c | 0;\n a += (b & c | ~b & d) + k[8] + 1770035416 | 0;\n a = (a << 7 | a >>> 25) + b | 0;\n d += (a & b | ~a & c) + k[9] - 1958414417 | 0;\n d = (d << 12 | d >>> 20) + a | 0;\n c += (d & a | ~d & b) + k[10] - 42063 | 0;\n c = (c << 17 | c >>> 15) + d | 0;\n b += (c & d | ~c & a) + k[11] - 1990404162 | 0;\n b = (b << 22 | b >>> 10) + c | 0;\n a += (b & c | ~b & d) + k[12] + 1804603682 | 0;\n a = (a << 7 | a >>> 25) + b | 0;\n d += (a & b | ~a & c) + k[13] - 40341101 | 0;\n d = (d << 12 | d >>> 20) + a | 0;\n c += (d & a | ~d & b) + k[14] - 1502002290 | 0;\n c = (c << 17 | c >>> 15) + d | 0;\n b += (c & d | ~c & a) + k[15] + 1236535329 | 0;\n b = (b << 22 | b >>> 10) + c | 0;\n a += (b & d | c & ~d) + k[1] - 165796510 | 0;\n a = (a << 5 | a >>> 27) + b | 0;\n d += (a & c | b & ~c) + k[6] - 1069501632 | 0;\n d = (d << 9 | d >>> 23) + a | 0;\n c += (d & b | a & ~b) + k[11] + 643717713 | 0;\n c = (c << 14 | c >>> 18) + d | 0;\n b += (c & a | d & ~a) + k[0] - 373897302 | 0;\n b = (b << 20 | b >>> 12) + c | 0;\n a += (b & d | c & ~d) + k[5] - 701558691 | 0;\n a = (a << 5 | a >>> 27) + b | 0;\n d += (a & c | b & ~c) + k[10] + 38016083 | 0;\n d = (d << 9 | d >>> 23) + a | 0;\n c += (d & b | a & ~b) + k[15] - 660478335 | 0;\n c = (c << 14 | c >>> 18) + d | 0;\n b += (c & a | d & ~a) + k[4] - 405537848 | 0;\n b = (b << 20 | b >>> 12) + c | 0;\n a += (b & d | c & ~d) + k[9] + 568446438 | 0;\n a = (a << 5 | a >>> 27) + b | 0;\n d += (a & c | b & ~c) + k[14] - 1019803690 | 0;\n d = (d << 9 | d >>> 23) + a | 0;\n c += (d & b | a & ~b) + k[3] - 187363961 | 0;\n c = (c << 14 | c >>> 18) + d | 0;\n b += (c & a | d & ~a) + k[8] + 1163531501 | 0;\n b = (b << 20 | b >>> 12) + c | 0;\n a += (b & d | c & ~d) + k[13] - 1444681467 | 0;\n a = (a << 5 | a >>> 27) + b | 0;\n d += (a & c | b & ~c) + k[2] - 51403784 | 0;\n d = (d << 9 | d >>> 23) + a | 0;\n c += (d & b | a & ~b) + k[7] + 1735328473 | 0;\n c = (c << 14 | c >>> 18) + d | 0;\n b += (c & a | d & ~a) + k[12] - 1926607734 | 0;\n b = (b << 20 | b >>> 12) + c | 0;\n a += (b ^ c ^ d) + k[5] - 378558 | 0;\n a = (a << 4 | a >>> 28) + b | 0;\n d += (a ^ b ^ c) + k[8] - 2022574463 | 0;\n d = (d << 11 | d >>> 21) + a | 0;\n c += (d ^ a ^ b) + k[11] + 1839030562 | 0;\n c = (c << 16 | c >>> 16) + d | 0;\n b += (c ^ d ^ a) + k[14] - 35309556 | 0;\n b = (b << 23 | b >>> 9) + c | 0;\n a += (b ^ c ^ d) + k[1] - 1530992060 | 0;\n a = (a << 4 | a >>> 28) + b | 0;\n d += (a ^ b ^ c) + k[4] + 1272893353 | 0;\n d = (d << 11 | d >>> 21) + a | 0;\n c += (d ^ a ^ b) + k[7] - 155497632 | 0;\n c = (c << 16 | c >>> 16) + d | 0;\n b += (c ^ d ^ a) + k[10] - 1094730640 | 0;\n b = (b << 23 | b >>> 9) + c | 0;\n a += (b ^ c ^ d) + k[13] + 681279174 | 0;\n a = (a << 4 | a >>> 28) + b | 0;\n d += (a ^ b ^ c) + k[0] - 358537222 | 0;\n d = (d << 11 | d >>> 21) + a | 0;\n c += (d ^ a ^ b) + k[3] - 722521979 | 0;\n c = (c << 16 | c >>> 16) + d | 0;\n b += (c ^ d ^ a) + k[6] + 76029189 | 0;\n b = (b << 23 | b >>> 9) + c | 0;\n a += (b ^ c ^ d) + k[9] - 640364487 | 0;\n a = (a << 4 | a >>> 28) + b | 0;\n d += (a ^ b ^ c) + k[12] - 421815835 | 0;\n d = (d << 11 | d >>> 21) + a | 0;\n c += (d ^ a ^ b) + k[15] + 530742520 | 0;\n c = (c << 16 | c >>> 16) + d | 0;\n b += (c ^ d ^ a) + k[2] - 995338651 | 0;\n b = (b << 23 | b >>> 9) + c | 0;\n a += (c ^ (b | ~d)) + k[0] - 198630844 | 0;\n a = (a << 6 | a >>> 26) + b | 0;\n d += (b ^ (a | ~c)) + k[7] + 1126891415 | 0;\n d = (d << 10 | d >>> 22) + a | 0;\n c += (a ^ (d | ~b)) + k[14] - 1416354905 | 0;\n c = (c << 15 | c >>> 17) + d | 0;\n b += (d ^ (c | ~a)) + k[5] - 57434055 | 0;\n b = (b << 21 | b >>> 11) + c | 0;\n a += (c ^ (b | ~d)) + k[12] + 1700485571 | 0;\n a = (a << 6 | a >>> 26) + b | 0;\n d += (b ^ (a | ~c)) + k[3] - 1894986606 | 0;\n d = (d << 10 | d >>> 22) + a | 0;\n c += (a ^ (d | ~b)) + k[10] - 1051523 | 0;\n c = (c << 15 | c >>> 17) + d | 0;\n b += (d ^ (c | ~a)) + k[1] - 2054922799 | 0;\n b = (b << 21 | b >>> 11) + c | 0;\n a += (c ^ (b | ~d)) + k[8] + 1873313359 | 0;\n a = (a << 6 | a >>> 26) + b | 0;\n d += (b ^ (a | ~c)) + k[15] - 30611744 | 0;\n d = (d << 10 | d >>> 22) + a | 0;\n c += (a ^ (d | ~b)) + k[6] - 1560198380 | 0;\n c = (c << 15 | c >>> 17) + d | 0;\n b += (d ^ (c | ~a)) + k[13] + 1309151649 | 0;\n b = (b << 21 | b >>> 11) + c | 0;\n a += (c ^ (b | ~d)) + k[4] - 145523070 | 0;\n a = (a << 6 | a >>> 26) + b | 0;\n d += (b ^ (a | ~c)) + k[11] - 1120210379 | 0;\n d = (d << 10 | d >>> 22) + a | 0;\n c += (a ^ (d | ~b)) + k[2] + 718787259 | 0;\n c = (c << 15 | c >>> 17) + d | 0;\n b += (d ^ (c | ~a)) + k[9] - 343485551 | 0;\n b = (b << 21 | b >>> 11) + c | 0;\n x[0] = a + x[0] | 0;\n x[1] = b + x[1] | 0;\n x[2] = c + x[2] | 0;\n x[3] = d + x[3] | 0;\n }\n function md5blk(s) {\n var md5blks = [], i;\n for (i = 0; i < 64; i += 4) {\n md5blks[i >> 2] = s.charCodeAt(i) + (s.charCodeAt(i + 1) << 8) + (s.charCodeAt(i + 2) << 16) + (s.charCodeAt(i + 3) << 24);\n }\n return md5blks;\n }\n function md5blk_array(a) {\n var md5blks = [], i;\n for (i = 0; i < 64; i += 4) {\n md5blks[i >> 2] = a[i] + (a[i + 1] << 8) + (a[i + 2] << 16) + (a[i + 3] << 24);\n }\n return md5blks;\n }\n function md51(s) {\n var n = s.length, state = [ 1732584193, -271733879, -1732584194, 271733878 ], i, length, tail, tmp, lo, hi;\n for (i = 64; i <= n; i += 64) {\n md5cycle(state, md5blk(s.substring(i - 64, i)));\n }\n s = s.substring(i - 64);\n length = s.length;\n tail = [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ];\n for (i = 0; i < length; i += 1) {\n tail[i >> 2] |= s.charCodeAt(i) << (i % 4 << 3);\n }\n tail[i >> 2] |= 128 << (i % 4 << 3);\n if (i > 55) {\n md5cycle(state, tail);\n for (i = 0; i < 16; i += 1) {\n tail[i] = 0;\n }\n }\n tmp = n * 8;\n tmp = tmp.toString(16).match(/(.*?)(.{0,8})$/);\n lo = parseInt(tmp[2], 16);\n hi = parseInt(tmp[1], 16) || 0;\n tail[14] = lo;\n tail[15] = hi;\n md5cycle(state, tail);\n return state;\n }\n function md51_array(a) {\n var n = a.length, state = [ 1732584193, -271733879, -1732584194, 271733878 ], i, length, tail, tmp, lo, hi;\n for (i = 64; i <= n; i += 64) {\n md5cycle(state, md5blk_array(a.subarray(i - 64, i)));\n }\n a = i - 64 < n ? a.subarray(i - 64) : new Uint8Array(0);\n length = a.length;\n tail = [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ];\n for (i = 0; i < length; i += 1) {\n tail[i >> 2] |= a[i] << (i % 4 << 3);\n }\n tail[i >> 2] |= 128 << (i % 4 << 3);\n if (i > 55) {\n md5cycle(state, tail);\n for (i = 0; i < 16; i += 1) {\n tail[i] = 0;\n }\n }\n tmp = n * 8;\n tmp = tmp.toString(16).match(/(.*?)(.{0,8})$/);\n lo = parseInt(tmp[2], 16);\n hi = parseInt(tmp[1], 16) || 0;\n tail[14] = lo;\n tail[15] = hi;\n md5cycle(state, tail);\n return state;\n }\n function rhex(n) {\n var s = \"\", j;\n for (j = 0; j < 4; j += 1) {\n s += hex_chr[n >> j * 8 + 4 & 15] + hex_chr[n >> j * 8 & 15];\n }\n return s;\n }\n function hex(x) {\n var i;\n for (i = 0; i < x.length; i += 1) {\n x[i] = rhex(x[i]);\n }\n return x.join(\"\");\n }\n if (hex(md51(\"hello\")) !== \"5d41402abc4b2a76b9719d911017c592\") ;\n if (typeof ArrayBuffer !== \"undefined\" && !ArrayBuffer.prototype.slice) {\n (function() {\n function clamp(val, length) {\n val = val | 0 || 0;\n if (val < 0) {\n return Math.max(val + length, 0);\n }\n return Math.min(val, length);\n }\n ArrayBuffer.prototype.slice = function(from, to) {\n var length = this.byteLength, begin = clamp(from, length), end = length, num, target, targetArray, sourceArray;\n if (to !== undefined$1) {\n end = clamp(to, length);\n }\n if (begin > end) {\n return new ArrayBuffer(0);\n }\n num = end - begin;\n target = new ArrayBuffer(num);\n targetArray = new Uint8Array(target);\n sourceArray = new Uint8Array(this, begin, num);\n targetArray.set(sourceArray);\n return target;\n };\n })();\n }\n function toUtf8(str) {\n if (/[\\u0080-\\uFFFF]/.test(str)) {\n str = unescape(encodeURIComponent(str));\n }\n return str;\n }\n function utf8Str2ArrayBuffer(str, returnUInt8Array) {\n var length = str.length, buff = new ArrayBuffer(length), arr = new Uint8Array(buff), i;\n for (i = 0; i < length; i += 1) {\n arr[i] = str.charCodeAt(i);\n }\n return returnUInt8Array ? arr : buff;\n }\n function arrayBuffer2Utf8Str(buff) {\n return String.fromCharCode.apply(null, new Uint8Array(buff));\n }\n function concatenateArrayBuffers(first, second, returnUInt8Array) {\n var result = new Uint8Array(first.byteLength + second.byteLength);\n result.set(new Uint8Array(first));\n result.set(new Uint8Array(second), first.byteLength);\n return returnUInt8Array ? result : result.buffer;\n }\n function hexToBinaryString(hex) {\n var bytes = [], length = hex.length, x;\n for (x = 0; x < length - 1; x += 2) {\n bytes.push(parseInt(hex.substr(x, 2), 16));\n }\n return String.fromCharCode.apply(String, bytes);\n }\n function SparkMD5() {\n this.reset();\n }\n SparkMD5.prototype.append = function(str) {\n this.appendBinary(toUtf8(str));\n return this;\n };\n SparkMD5.prototype.appendBinary = function(contents) {\n this._buff += contents;\n this._length += contents.length;\n var length = this._buff.length, i;\n for (i = 64; i <= length; i += 64) {\n md5cycle(this._hash, md5blk(this._buff.substring(i - 64, i)));\n }\n this._buff = this._buff.substring(i - 64);\n return this;\n };\n SparkMD5.prototype.end = function(raw) {\n var buff = this._buff, length = buff.length, i, tail = [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ], ret;\n for (i = 0; i < length; i += 1) {\n tail[i >> 2] |= buff.charCodeAt(i) << (i % 4 << 3);\n }\n this._finish(tail, length);\n ret = hex(this._hash);\n if (raw) {\n ret = hexToBinaryString(ret);\n }\n this.reset();\n return ret;\n };\n SparkMD5.prototype.reset = function() {\n this._buff = \"\";\n this._length = 0;\n this._hash = [ 1732584193, -271733879, -1732584194, 271733878 ];\n return this;\n };\n SparkMD5.prototype.getState = function() {\n return {\n buff: this._buff,\n length: this._length,\n hash: this._hash.slice()\n };\n };\n SparkMD5.prototype.setState = function(state) {\n this._buff = state.buff;\n this._length = state.length;\n this._hash = state.hash;\n return this;\n };\n SparkMD5.prototype.destroy = function() {\n delete this._hash;\n delete this._buff;\n delete this._length;\n };\n SparkMD5.prototype._finish = function(tail, length) {\n var i = length, tmp, lo, hi;\n tail[i >> 2] |= 128 << (i % 4 << 3);\n if (i > 55) {\n md5cycle(this._hash, tail);\n for (i = 0; i < 16; i += 1) {\n tail[i] = 0;\n }\n }\n tmp = this._length * 8;\n tmp = tmp.toString(16).match(/(.*?)(.{0,8})$/);\n lo = parseInt(tmp[2], 16);\n hi = parseInt(tmp[1], 16) || 0;\n tail[14] = lo;\n tail[15] = hi;\n md5cycle(this._hash, tail);\n };\n SparkMD5.hash = function(str, raw) {\n return SparkMD5.hashBinary(toUtf8(str), raw);\n };\n SparkMD5.hashBinary = function(content, raw) {\n var hash = md51(content), ret = hex(hash);\n return raw ? hexToBinaryString(ret) : ret;\n };\n SparkMD5.ArrayBuffer = function() {\n this.reset();\n };\n SparkMD5.ArrayBuffer.prototype.append = function(arr) {\n var buff = concatenateArrayBuffers(this._buff.buffer, arr, true), length = buff.length, i;\n this._length += arr.byteLength;\n for (i = 64; i <= length; i += 64) {\n md5cycle(this._hash, md5blk_array(buff.subarray(i - 64, i)));\n }\n this._buff = i - 64 < length ? new Uint8Array(buff.buffer.slice(i - 64)) : new Uint8Array(0);\n return this;\n };\n SparkMD5.ArrayBuffer.prototype.end = function(raw) {\n var buff = this._buff, length = buff.length, tail = [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ], i, ret;\n for (i = 0; i < length; i += 1) {\n tail[i >> 2] |= buff[i] << (i % 4 << 3);\n }\n this._finish(tail, length);\n ret = hex(this._hash);\n if (raw) {\n ret = hexToBinaryString(ret);\n }\n this.reset();\n return ret;\n };\n SparkMD5.ArrayBuffer.prototype.reset = function() {\n this._buff = new Uint8Array(0);\n this._length = 0;\n this._hash = [ 1732584193, -271733879, -1732584194, 271733878 ];\n return this;\n };\n SparkMD5.ArrayBuffer.prototype.getState = function() {\n var state = SparkMD5.prototype.getState.call(this);\n state.buff = arrayBuffer2Utf8Str(state.buff);\n return state;\n };\n SparkMD5.ArrayBuffer.prototype.setState = function(state) {\n state.buff = utf8Str2ArrayBuffer(state.buff, true);\n return SparkMD5.prototype.setState.call(this, state);\n };\n SparkMD5.ArrayBuffer.prototype.destroy = SparkMD5.prototype.destroy;\n SparkMD5.ArrayBuffer.prototype._finish = SparkMD5.prototype._finish;\n SparkMD5.ArrayBuffer.hash = function(arr, raw) {\n var hash = md51_array(new Uint8Array(arr)), ret = hex(hash);\n return raw ? hexToBinaryString(ret) : ret;\n };\n return SparkMD5;\n }));\n })(sparkMd5);\n var SparkMD5 = sparkMd5.exports;\n const fileSlice = File.prototype.slice || File.prototype.mozSlice || File.prototype.webkitSlice;\n class FileChecksum {\n static create(file, callback) {\n const instance = new FileChecksum(file);\n instance.create(callback);\n }\n constructor(file) {\n this.file = file;\n this.chunkSize = 2097152;\n this.chunkCount = Math.ceil(this.file.size / this.chunkSize);\n this.chunkIndex = 0;\n }\n create(callback) {\n this.callback = callback;\n this.md5Buffer = new SparkMD5.ArrayBuffer;\n this.fileReader = new FileReader;\n this.fileReader.addEventListener(\"load\", (event => this.fileReaderDidLoad(event)));\n this.fileReader.addEventListener(\"error\", (event => this.fileReaderDidError(event)));\n this.readNextChunk();\n }\n fileReaderDidLoad(event) {\n this.md5Buffer.append(event.target.result);\n if (!this.readNextChunk()) {\n const binaryDigest = this.md5Buffer.end(true);\n const base64digest = btoa(binaryDigest);\n this.callback(null, base64digest);\n }\n }\n fileReaderDidError(event) {\n this.callback(`Error reading ${this.file.name}`);\n }\n readNextChunk() {\n if (this.chunkIndex < this.chunkCount || this.chunkIndex == 0 && this.chunkCount == 0) {\n const start = this.chunkIndex * this.chunkSize;\n const end = Math.min(start + this.chunkSize, this.file.size);\n const bytes = fileSlice.call(this.file, start, end);\n this.fileReader.readAsArrayBuffer(bytes);\n this.chunkIndex++;\n return true;\n } else {\n return false;\n }\n }\n }\n function getMetaValue(name) {\n const element = findElement(document.head, `meta[name=\"${name}\"]`);\n if (element) {\n return element.getAttribute(\"content\");\n }\n }\n function findElements(root, selector) {\n if (typeof root == \"string\") {\n selector = root;\n root = document;\n }\n const elements = root.querySelectorAll(selector);\n return toArray(elements);\n }\n function findElement(root, selector) {\n if (typeof root == \"string\") {\n selector = root;\n root = document;\n }\n return root.querySelector(selector);\n }\n function dispatchEvent(element, type, eventInit = {}) {\n const {disabled: disabled} = element;\n const {bubbles: bubbles, cancelable: cancelable, detail: detail} = eventInit;\n const event = document.createEvent(\"Event\");\n event.initEvent(type, bubbles || true, cancelable || true);\n event.detail = detail || {};\n try {\n element.disabled = false;\n element.dispatchEvent(event);\n } finally {\n element.disabled = disabled;\n }\n return event;\n }\n function toArray(value) {\n if (Array.isArray(value)) {\n return value;\n } else if (Array.from) {\n return Array.from(value);\n } else {\n return [].slice.call(value);\n }\n }\n class BlobRecord {\n constructor(file, checksum, url, customHeaders = {}) {\n this.file = file;\n this.attributes = {\n filename: file.name,\n content_type: file.type || \"application/octet-stream\",\n byte_size: file.size,\n checksum: checksum\n };\n this.xhr = new XMLHttpRequest;\n this.xhr.open(\"POST\", url, true);\n this.xhr.responseType = \"json\";\n this.xhr.setRequestHeader(\"Content-Type\", \"application/json\");\n this.xhr.setRequestHeader(\"Accept\", \"application/json\");\n this.xhr.setRequestHeader(\"X-Requested-With\", \"XMLHttpRequest\");\n Object.keys(customHeaders).forEach((headerKey => {\n this.xhr.setRequestHeader(headerKey, customHeaders[headerKey]);\n }));\n const csrfToken = getMetaValue(\"csrf-token\");\n if (csrfToken != undefined) {\n this.xhr.setRequestHeader(\"X-CSRF-Token\", csrfToken);\n }\n this.xhr.addEventListener(\"load\", (event => this.requestDidLoad(event)));\n this.xhr.addEventListener(\"error\", (event => this.requestDidError(event)));\n }\n get status() {\n return this.xhr.status;\n }\n get response() {\n const {responseType: responseType, response: response} = this.xhr;\n if (responseType == \"json\") {\n return response;\n } else {\n return JSON.parse(response);\n }\n }\n create(callback) {\n this.callback = callback;\n this.xhr.send(JSON.stringify({\n blob: this.attributes\n }));\n }\n requestDidLoad(event) {\n if (this.status >= 200 && this.status < 300) {\n const {response: response} = this;\n const {direct_upload: direct_upload} = response;\n delete response.direct_upload;\n this.attributes = response;\n this.directUploadData = direct_upload;\n this.callback(null, this.toJSON());\n } else {\n this.requestDidError(event);\n }\n }\n requestDidError(event) {\n this.callback(`Error creating Blob for \"${this.file.name}\". Status: ${this.status}`);\n }\n toJSON() {\n const result = {};\n for (const key in this.attributes) {\n result[key] = this.attributes[key];\n }\n return result;\n }\n }\n class BlobUpload {\n constructor(blob) {\n this.blob = blob;\n this.file = blob.file;\n const {url: url, headers: headers} = blob.directUploadData;\n this.xhr = new XMLHttpRequest;\n this.xhr.open(\"PUT\", url, true);\n this.xhr.responseType = \"text\";\n for (const key in headers) {\n this.xhr.setRequestHeader(key, headers[key]);\n }\n this.xhr.addEventListener(\"load\", (event => this.requestDidLoad(event)));\n this.xhr.addEventListener(\"error\", (event => this.requestDidError(event)));\n }\n create(callback) {\n this.callback = callback;\n this.xhr.send(this.file.slice());\n }\n requestDidLoad(event) {\n const {status: status, response: response} = this.xhr;\n if (status >= 200 && status < 300) {\n this.callback(null, response);\n } else {\n this.requestDidError(event);\n }\n }\n requestDidError(event) {\n this.callback(`Error storing \"${this.file.name}\". Status: ${this.xhr.status}`);\n }\n }\n let id = 0;\n class DirectUpload {\n constructor(file, url, delegate, customHeaders = {}) {\n this.id = ++id;\n this.file = file;\n this.url = url;\n this.delegate = delegate;\n this.customHeaders = customHeaders;\n }\n create(callback) {\n FileChecksum.create(this.file, ((error, checksum) => {\n if (error) {\n callback(error);\n return;\n }\n const blob = new BlobRecord(this.file, checksum, this.url, this.customHeaders);\n notify(this.delegate, \"directUploadWillCreateBlobWithXHR\", blob.xhr);\n blob.create((error => {\n if (error) {\n callback(error);\n } else {\n const upload = new BlobUpload(blob);\n notify(this.delegate, \"directUploadWillStoreFileWithXHR\", upload.xhr);\n upload.create((error => {\n if (error) {\n callback(error);\n } else {\n callback(null, blob.toJSON());\n }\n }));\n }\n }));\n }));\n }\n }\n function notify(object, methodName, ...messages) {\n if (object && typeof object[methodName] == \"function\") {\n return object[methodName](...messages);\n }\n }\n class DirectUploadController {\n constructor(input, file) {\n this.input = input;\n this.file = file;\n this.directUpload = new DirectUpload(this.file, this.url, this);\n this.dispatch(\"initialize\");\n }\n start(callback) {\n const hiddenInput = document.createElement(\"input\");\n hiddenInput.type = \"hidden\";\n hiddenInput.name = this.input.name;\n this.input.insertAdjacentElement(\"beforebegin\", hiddenInput);\n this.dispatch(\"start\");\n this.directUpload.create(((error, attributes) => {\n if (error) {\n hiddenInput.parentNode.removeChild(hiddenInput);\n this.dispatchError(error);\n } else {\n hiddenInput.value = attributes.signed_id;\n }\n this.dispatch(\"end\");\n callback(error);\n }));\n }\n uploadRequestDidProgress(event) {\n const progress = event.loaded / event.total * 100;\n if (progress) {\n this.dispatch(\"progress\", {\n progress: progress\n });\n }\n }\n get url() {\n return this.input.getAttribute(\"data-direct-upload-url\");\n }\n dispatch(name, detail = {}) {\n detail.file = this.file;\n detail.id = this.directUpload.id;\n return dispatchEvent(this.input, `direct-upload:${name}`, {\n detail: detail\n });\n }\n dispatchError(error) {\n const event = this.dispatch(\"error\", {\n error: error\n });\n if (!event.defaultPrevented) {\n alert(error);\n }\n }\n directUploadWillCreateBlobWithXHR(xhr) {\n this.dispatch(\"before-blob-request\", {\n xhr: xhr\n });\n }\n directUploadWillStoreFileWithXHR(xhr) {\n this.dispatch(\"before-storage-request\", {\n xhr: xhr\n });\n xhr.upload.addEventListener(\"progress\", (event => this.uploadRequestDidProgress(event)));\n }\n }\n const inputSelector = \"input[type=file][data-direct-upload-url]:not([disabled])\";\n class DirectUploadsController {\n constructor(form) {\n this.form = form;\n this.inputs = findElements(form, inputSelector).filter((input => input.files.length));\n }\n start(callback) {\n const controllers = this.createDirectUploadControllers();\n const startNextController = () => {\n const controller = controllers.shift();\n if (controller) {\n controller.start((error => {\n if (error) {\n callback(error);\n this.dispatch(\"end\");\n } else {\n startNextController();\n }\n }));\n } else {\n callback();\n this.dispatch(\"end\");\n }\n };\n this.dispatch(\"start\");\n startNextController();\n }\n createDirectUploadControllers() {\n const controllers = [];\n this.inputs.forEach((input => {\n toArray(input.files).forEach((file => {\n const controller = new DirectUploadController(input, file);\n controllers.push(controller);\n }));\n }));\n return controllers;\n }\n dispatch(name, detail = {}) {\n return dispatchEvent(this.form, `direct-uploads:${name}`, {\n detail: detail\n });\n }\n }\n const processingAttribute = \"data-direct-uploads-processing\";\n const submitButtonsByForm = new WeakMap;\n let started = false;\n function start() {\n if (!started) {\n started = true;\n document.addEventListener(\"click\", didClick, true);\n document.addEventListener(\"submit\", didSubmitForm, true);\n document.addEventListener(\"ajax:before\", didSubmitRemoteElement);\n }\n }\n function didClick(event) {\n const button = event.target.closest(\"button, input\");\n if (button && button.type === \"submit\" && button.form) {\n submitButtonsByForm.set(button.form, button);\n }\n }\n function didSubmitForm(event) {\n handleFormSubmissionEvent(event);\n }\n function didSubmitRemoteElement(event) {\n if (event.target.tagName == \"FORM\") {\n handleFormSubmissionEvent(event);\n }\n }\n function handleFormSubmissionEvent(event) {\n const form = event.target;\n if (form.hasAttribute(processingAttribute)) {\n event.preventDefault();\n return;\n }\n const controller = new DirectUploadsController(form);\n const {inputs: inputs} = controller;\n if (inputs.length) {\n event.preventDefault();\n form.setAttribute(processingAttribute, \"\");\n inputs.forEach(disable);\n controller.start((error => {\n form.removeAttribute(processingAttribute);\n if (error) {\n inputs.forEach(enable);\n } else {\n submitForm(form);\n }\n }));\n }\n }\n function submitForm(form) {\n let button = submitButtonsByForm.get(form) || findElement(form, \"input[type=submit], button[type=submit]\");\n if (button) {\n const {disabled: disabled} = button;\n button.disabled = false;\n button.focus();\n button.click();\n button.disabled = disabled;\n } else {\n button = document.createElement(\"input\");\n button.type = \"submit\";\n button.style.display = \"none\";\n form.appendChild(button);\n button.click();\n form.removeChild(button);\n }\n submitButtonsByForm.delete(form);\n }\n function disable(input) {\n input.disabled = true;\n }\n function enable(input) {\n input.disabled = false;\n }\n function autostart() {\n if (window.ActiveStorage) {\n start();\n }\n }\n setTimeout(autostart, 1);\n class AttachmentUpload {\n constructor(attachment, element) {\n this.attachment = attachment;\n this.element = element;\n this.directUpload = new DirectUpload(attachment.file, this.directUploadUrl, this);\n }\n start() {\n this.directUpload.create(this.directUploadDidComplete.bind(this));\n this.dispatch(\"start\");\n }\n directUploadWillStoreFileWithXHR(xhr) {\n xhr.upload.addEventListener(\"progress\", (event => {\n const progress = event.loaded / event.total * 100;\n this.attachment.setUploadProgress(progress);\n if (progress) {\n this.dispatch(\"progress\", {\n progress: progress\n });\n }\n }));\n }\n directUploadDidComplete(error, attributes) {\n if (error) {\n this.dispatchError(error);\n } else {\n this.attachment.setAttributes({\n sgid: attributes.attachable_sgid,\n url: this.createBlobUrl(attributes.signed_id, attributes.filename)\n });\n this.dispatch(\"end\");\n }\n }\n createBlobUrl(signedId, filename) {\n return this.blobUrlTemplate.replace(\":signed_id\", signedId).replace(\":filename\", encodeURIComponent(filename));\n }\n dispatch(name, detail = {}) {\n detail.attachment = this.attachment;\n return dispatchEvent(this.element, `direct-upload:${name}`, {\n detail: detail\n });\n }\n dispatchError(error) {\n const event = this.dispatch(\"error\", {\n error: error\n });\n if (!event.defaultPrevented) {\n alert(error);\n }\n }\n get directUploadUrl() {\n return this.element.dataset.directUploadUrl;\n }\n get blobUrlTemplate() {\n return this.element.dataset.blobUrlTemplate;\n }\n }\n addEventListener(\"trix-attachment-add\", (event => {\n const {attachment: attachment, target: target} = event;\n if (attachment.file) {\n const upload = new AttachmentUpload(attachment, target);\n upload.start();\n }\n }));\n}));\n/* eslint-enable */\n", "import Trix from '../rails/trix'\nimport '../rails/actiontext'\n\nconst Clipboard = {\n start () {\n document.addEventListener('trix-initialize', () => {\n this.setToolbar()\n this.setLanguage()\n this.setAttachmentsConfig()\n })\n },\n\n setToolbar () {\n const toolbars = document.getElementsByTagName('trix-toolbar')\n const { lang } = Trix.config\n\n toolbars.forEach(toolbar => {\n toolbar.innerHTML = `
\n \n \n \n \n \n \n \n \n
`\n })\n },\n\n setAttachmentsConfig () {\n const { attachments } = Trix.config\n\n attachments.preview.caption.name = false\n attachments.preview.caption.size = false\n },\n\n setLanguage () {\n const { lang } = Trix.config\n\n lang.bold = 'Negrito'\n lang.italic = 'It\u00E1lico'\n lang.attachFiles = 'Adicionar fotos'\n lang.undo = 'Desfazer'\n lang.redo = 'Refazer'\n lang.captionPlaceholder = 'Adicionar legenda...'\n lang.bullets = 'Lista de itens'\n }\n}\n\nexport default Clipboard\n", "/* smoothscroll v0.4.4 - 2019 - Dustan Kasten, Jeremias Menichelli - MIT License */\n(function () {\n 'use strict';\n\n // polyfill\n function polyfill() {\n // aliases\n var w = window;\n var d = document;\n\n // return if scroll behavior is supported and polyfill is not forced\n if (\n 'scrollBehavior' in d.documentElement.style &&\n w.__forceSmoothScrollPolyfill__ !== true\n ) {\n return;\n }\n\n // globals\n var Element = w.HTMLElement || w.Element;\n var SCROLL_TIME = 468;\n\n // object gathering original scroll methods\n var original = {\n scroll: w.scroll || w.scrollTo,\n scrollBy: w.scrollBy,\n elementScroll: Element.prototype.scroll || scrollElement,\n scrollIntoView: Element.prototype.scrollIntoView\n };\n\n // define timing method\n var now =\n w.performance && w.performance.now\n ? w.performance.now.bind(w.performance)\n : Date.now;\n\n /**\n * indicates if a the current browser is made by Microsoft\n * @method isMicrosoftBrowser\n * @param {String} userAgent\n * @returns {Boolean}\n */\n function isMicrosoftBrowser(userAgent) {\n var userAgentPatterns = ['MSIE ', 'Trident/', 'Edge/'];\n\n return new RegExp(userAgentPatterns.join('|')).test(userAgent);\n }\n\n /*\n * IE has rounding bug rounding down clientHeight and clientWidth and\n * rounding up scrollHeight and scrollWidth causing false positives\n * on hasScrollableSpace\n */\n var ROUNDING_TOLERANCE = isMicrosoftBrowser(w.navigator.userAgent) ? 1 : 0;\n\n /**\n * changes scroll position inside an element\n * @method scrollElement\n * @param {Number} x\n * @param {Number} y\n * @returns {undefined}\n */\n function scrollElement(x, y) {\n this.scrollLeft = x;\n this.scrollTop = y;\n }\n\n /**\n * returns result of applying ease math function to a number\n * @method ease\n * @param {Number} k\n * @returns {Number}\n */\n function ease(k) {\n return 0.5 * (1 - Math.cos(Math.PI * k));\n }\n\n /**\n * indicates if a smooth behavior should be applied\n * @method shouldBailOut\n * @param {Number|Object} firstArg\n * @returns {Boolean}\n */\n function shouldBailOut(firstArg) {\n if (\n firstArg === null ||\n typeof firstArg !== 'object' ||\n firstArg.behavior === undefined ||\n firstArg.behavior === 'auto' ||\n firstArg.behavior === 'instant'\n ) {\n // first argument is not an object/null\n // or behavior is auto, instant or undefined\n return true;\n }\n\n if (typeof firstArg === 'object' && firstArg.behavior === 'smooth') {\n // first argument is an object and behavior is smooth\n return false;\n }\n\n // throw error when behavior is not supported\n throw new TypeError(\n 'behavior member of ScrollOptions ' +\n firstArg.behavior +\n ' is not a valid value for enumeration ScrollBehavior.'\n );\n }\n\n /**\n * indicates if an element has scrollable space in the provided axis\n * @method hasScrollableSpace\n * @param {Node} el\n * @param {String} axis\n * @returns {Boolean}\n */\n function hasScrollableSpace(el, axis) {\n if (axis === 'Y') {\n return el.clientHeight + ROUNDING_TOLERANCE < el.scrollHeight;\n }\n\n if (axis === 'X') {\n return el.clientWidth + ROUNDING_TOLERANCE < el.scrollWidth;\n }\n }\n\n /**\n * indicates if an element has a scrollable overflow property in the axis\n * @method canOverflow\n * @param {Node} el\n * @param {String} axis\n * @returns {Boolean}\n */\n function canOverflow(el, axis) {\n var overflowValue = w.getComputedStyle(el, null)['overflow' + axis];\n\n return overflowValue === 'auto' || overflowValue === 'scroll';\n }\n\n /**\n * indicates if an element can be scrolled in either axis\n * @method isScrollable\n * @param {Node} el\n * @param {String} axis\n * @returns {Boolean}\n */\n function isScrollable(el) {\n var isScrollableY = hasScrollableSpace(el, 'Y') && canOverflow(el, 'Y');\n var isScrollableX = hasScrollableSpace(el, 'X') && canOverflow(el, 'X');\n\n return isScrollableY || isScrollableX;\n }\n\n /**\n * finds scrollable parent of an element\n * @method findScrollableParent\n * @param {Node} el\n * @returns {Node} el\n */\n function findScrollableParent(el) {\n while (el !== d.body && isScrollable(el) === false) {\n el = el.parentNode || el.host;\n }\n\n return el;\n }\n\n /**\n * self invoked function that, given a context, steps through scrolling\n * @method step\n * @param {Object} context\n * @returns {undefined}\n */\n function step(context) {\n var time = now();\n var value;\n var currentX;\n var currentY;\n var elapsed = (time - context.startTime) / SCROLL_TIME;\n\n // avoid elapsed times higher than one\n elapsed = elapsed > 1 ? 1 : elapsed;\n\n // apply easing to elapsed time\n value = ease(elapsed);\n\n currentX = context.startX + (context.x - context.startX) * value;\n currentY = context.startY + (context.y - context.startY) * value;\n\n context.method.call(context.scrollable, currentX, currentY);\n\n // scroll more if we have not reached our destination\n if (currentX !== context.x || currentY !== context.y) {\n w.requestAnimationFrame(step.bind(w, context));\n }\n }\n\n /**\n * scrolls window or element with a smooth behavior\n * @method smoothScroll\n * @param {Object|Node} el\n * @param {Number} x\n * @param {Number} y\n * @returns {undefined}\n */\n function smoothScroll(el, x, y) {\n var scrollable;\n var startX;\n var startY;\n var method;\n var startTime = now();\n\n // define scroll context\n if (el === d.body) {\n scrollable = w;\n startX = w.scrollX || w.pageXOffset;\n startY = w.scrollY || w.pageYOffset;\n method = original.scroll;\n } else {\n scrollable = el;\n startX = el.scrollLeft;\n startY = el.scrollTop;\n method = scrollElement;\n }\n\n // scroll looping over a frame\n step({\n scrollable: scrollable,\n method: method,\n startTime: startTime,\n startX: startX,\n startY: startY,\n x: x,\n y: y\n });\n }\n\n // ORIGINAL METHODS OVERRIDES\n // w.scroll and w.scrollTo\n w.scroll = w.scrollTo = function() {\n // avoid action when no arguments are passed\n if (arguments[0] === undefined) {\n return;\n }\n\n // avoid smooth behavior if not required\n if (shouldBailOut(arguments[0]) === true) {\n original.scroll.call(\n w,\n arguments[0].left !== undefined\n ? arguments[0].left\n : typeof arguments[0] !== 'object'\n ? arguments[0]\n : w.scrollX || w.pageXOffset,\n // use top prop, second argument if present or fallback to scrollY\n arguments[0].top !== undefined\n ? arguments[0].top\n : arguments[1] !== undefined\n ? arguments[1]\n : w.scrollY || w.pageYOffset\n );\n\n return;\n }\n\n // LET THE SMOOTHNESS BEGIN!\n smoothScroll.call(\n w,\n d.body,\n arguments[0].left !== undefined\n ? ~~arguments[0].left\n : w.scrollX || w.pageXOffset,\n arguments[0].top !== undefined\n ? ~~arguments[0].top\n : w.scrollY || w.pageYOffset\n );\n };\n\n // w.scrollBy\n w.scrollBy = function() {\n // avoid action when no arguments are passed\n if (arguments[0] === undefined) {\n return;\n }\n\n // avoid smooth behavior if not required\n if (shouldBailOut(arguments[0])) {\n original.scrollBy.call(\n w,\n arguments[0].left !== undefined\n ? arguments[0].left\n : typeof arguments[0] !== 'object' ? arguments[0] : 0,\n arguments[0].top !== undefined\n ? arguments[0].top\n : arguments[1] !== undefined ? arguments[1] : 0\n );\n\n return;\n }\n\n // LET THE SMOOTHNESS BEGIN!\n smoothScroll.call(\n w,\n d.body,\n ~~arguments[0].left + (w.scrollX || w.pageXOffset),\n ~~arguments[0].top + (w.scrollY || w.pageYOffset)\n );\n };\n\n // Element.prototype.scroll and Element.prototype.scrollTo\n Element.prototype.scroll = Element.prototype.scrollTo = function() {\n // avoid action when no arguments are passed\n if (arguments[0] === undefined) {\n return;\n }\n\n // avoid smooth behavior if not required\n if (shouldBailOut(arguments[0]) === true) {\n // if one number is passed, throw error to match Firefox implementation\n if (typeof arguments[0] === 'number' && arguments[1] === undefined) {\n throw new SyntaxError('Value could not be converted');\n }\n\n original.elementScroll.call(\n this,\n // use left prop, first number argument or fallback to scrollLeft\n arguments[0].left !== undefined\n ? ~~arguments[0].left\n : typeof arguments[0] !== 'object' ? ~~arguments[0] : this.scrollLeft,\n // use top prop, second argument or fallback to scrollTop\n arguments[0].top !== undefined\n ? ~~arguments[0].top\n : arguments[1] !== undefined ? ~~arguments[1] : this.scrollTop\n );\n\n return;\n }\n\n var left = arguments[0].left;\n var top = arguments[0].top;\n\n // LET THE SMOOTHNESS BEGIN!\n smoothScroll.call(\n this,\n this,\n typeof left === 'undefined' ? this.scrollLeft : ~~left,\n typeof top === 'undefined' ? this.scrollTop : ~~top\n );\n };\n\n // Element.prototype.scrollBy\n Element.prototype.scrollBy = function() {\n // avoid action when no arguments are passed\n if (arguments[0] === undefined) {\n return;\n }\n\n // avoid smooth behavior if not required\n if (shouldBailOut(arguments[0]) === true) {\n original.elementScroll.call(\n this,\n arguments[0].left !== undefined\n ? ~~arguments[0].left + this.scrollLeft\n : ~~arguments[0] + this.scrollLeft,\n arguments[0].top !== undefined\n ? ~~arguments[0].top + this.scrollTop\n : ~~arguments[1] + this.scrollTop\n );\n\n return;\n }\n\n this.scroll({\n left: ~~arguments[0].left + this.scrollLeft,\n top: ~~arguments[0].top + this.scrollTop,\n behavior: arguments[0].behavior\n });\n };\n\n // Element.prototype.scrollIntoView\n Element.prototype.scrollIntoView = function() {\n // avoid smooth behavior if not required\n if (shouldBailOut(arguments[0]) === true) {\n original.scrollIntoView.call(\n this,\n arguments[0] === undefined ? true : arguments[0]\n );\n\n return;\n }\n\n // LET THE SMOOTHNESS BEGIN!\n var scrollableParent = findScrollableParent(this);\n var parentRects = scrollableParent.getBoundingClientRect();\n var clientRects = this.getBoundingClientRect();\n\n if (scrollableParent !== d.body) {\n // reveal element inside parent\n smoothScroll.call(\n this,\n scrollableParent,\n scrollableParent.scrollLeft + clientRects.left - parentRects.left,\n scrollableParent.scrollTop + clientRects.top - parentRects.top\n );\n\n // reveal parent in viewport unless is fixed\n if (w.getComputedStyle(scrollableParent).position !== 'fixed') {\n w.scrollBy({\n left: parentRects.left,\n top: parentRects.top,\n behavior: 'smooth'\n });\n }\n } else {\n // reveal element in viewport\n w.scrollBy({\n left: clientRects.left,\n top: clientRects.top,\n behavior: 'smooth'\n });\n }\n };\n }\n\n if (typeof exports === 'object' && typeof module !== 'undefined') {\n // commonjs\n module.exports = { polyfill: polyfill };\n } else {\n // global\n polyfill();\n }\n\n}());\n", "(function(f){if(typeof exports===\"object\"&&typeof module!==\"undefined\"){module.exports=f()}else if(typeof define===\"function\"&&define.amd){define([],f)}else{var g;if(typeof window!==\"undefined\"){g=window}else if(typeof global!==\"undefined\"){g=global}else if(typeof self!==\"undefined\"){g=self}else{g=this}g.polyfillEventTarget = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require==\"function\"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error(\"Cannot find module '\"+o+\"'\");throw f.code=\"MODULE_NOT_FOUND\",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require==\"function\"&&require;for(var o=0;o\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 = getCspNonce();\n if (cspNonce) {\n createdScriptElement.nonce = cspNonce;\n }\n createdScriptElement.textContent = element.textContent;\n createdScriptElement.async = false;\n copyElementAttributes(createdScriptElement, element);\n return createdScriptElement\n }\n}\n\nfunction copyElementAttributes(destinationElement, sourceElement) {\n for (const { name, value } of sourceElement.attributes) {\n destinationElement.setAttribute(name, value);\n }\n}\n\nfunction createDocumentFragment(html) {\n const template = document.createElement(\"template\");\n template.innerHTML = html;\n return template.content\n}\n\nfunction dispatch(eventName, { target, cancelable, detail } = {}) {\n const event = new CustomEvent(eventName, {\n cancelable,\n bubbles: true,\n composed: true,\n detail\n });\n\n if (target && target.isConnected) {\n target.dispatchEvent(event);\n } else {\n document.documentElement.dispatchEvent(event);\n }\n\n return event\n}\n\nfunction cancelEvent(event) {\n event.preventDefault();\n event.stopImmediatePropagation();\n}\n\nfunction nextRepaint() {\n if (document.visibilityState === \"hidden\") {\n return nextEventLoopTick()\n } else {\n return nextAnimationFrame()\n }\n}\n\nfunction nextAnimationFrame() {\n return new Promise((resolve) => requestAnimationFrame(() => resolve()))\n}\n\nfunction nextEventLoopTick() {\n return new Promise((resolve) => setTimeout(() => resolve(), 0))\n}\n\nfunction nextMicrotask() {\n return Promise.resolve()\n}\n\nfunction parseHTMLDocument(html = \"\") {\n return new DOMParser().parseFromString(html, \"text/html\")\n}\n\nfunction unindent(strings, ...values) {\n const lines = interpolate(strings, values).replace(/^\\n/, \"\").split(\"\\n\");\n const match = lines[0].match(/^\\s+/);\n const indent = match ? match[0].length : 0;\n return lines.map((line) => line.slice(indent)).join(\"\\n\")\n}\n\nfunction interpolate(strings, values) {\n return strings.reduce((result, string, i) => {\n const value = values[i] == undefined ? \"\" : values[i];\n return result + string + value\n }, \"\")\n}\n\nfunction uuid() {\n return Array.from({ length: 36 })\n .map((_, i) => {\n if (i == 8 || i == 13 || i == 18 || i == 23) {\n return \"-\"\n } else if (i == 14) {\n return \"4\"\n } else if (i == 19) {\n return (Math.floor(Math.random() * 4) + 8).toString(16)\n } else {\n return Math.floor(Math.random() * 15).toString(16)\n }\n })\n .join(\"\")\n}\n\nfunction getAttribute(attributeName, ...elements) {\n for (const value of elements.map((element) => element?.getAttribute(attributeName))) {\n if (typeof value == \"string\") return value\n }\n\n return null\n}\n\nfunction hasAttribute(attributeName, ...elements) {\n return elements.some((element) => element && element.hasAttribute(attributeName))\n}\n\nfunction markAsBusy(...elements) {\n for (const element of elements) {\n if (element.localName == \"turbo-frame\") {\n element.setAttribute(\"busy\", \"\");\n }\n element.setAttribute(\"aria-busy\", \"true\");\n }\n}\n\nfunction clearBusyState(...elements) {\n for (const element of elements) {\n if (element.localName == \"turbo-frame\") {\n element.removeAttribute(\"busy\");\n }\n\n element.removeAttribute(\"aria-busy\");\n }\n}\n\nfunction waitForLoad(element, timeoutInMilliseconds = 2000) {\n return new Promise((resolve) => {\n const onComplete = () => {\n element.removeEventListener(\"error\", onComplete);\n element.removeEventListener(\"load\", onComplete);\n resolve();\n };\n\n element.addEventListener(\"load\", onComplete, { once: true });\n element.addEventListener(\"error\", onComplete, { once: true });\n setTimeout(resolve, timeoutInMilliseconds);\n })\n}\n\nfunction getHistoryMethodForAction(action) {\n switch (action) {\n case \"replace\":\n return history.replaceState\n case \"advance\":\n case \"restore\":\n return history.pushState\n }\n}\n\nfunction isAction(action) {\n return action == \"advance\" || action == \"replace\" || action == \"restore\"\n}\n\nfunction getVisitAction(...elements) {\n const action = getAttribute(\"data-turbo-action\", ...elements);\n\n return isAction(action) ? action : null\n}\n\nfunction getMetaElement(name) {\n return document.querySelector(`meta[name=\"${name}\"]`)\n}\n\nfunction getMetaContent(name) {\n const element = getMetaElement(name);\n return element && element.content\n}\n\nfunction getCspNonce() {\n const element = getMetaElement(\"csp-nonce\");\n\n if (element) {\n const { nonce, content } = element;\n return nonce == \"\" ? content : nonce\n }\n}\n\nfunction setMetaContent(name, content) {\n let element = getMetaElement(name);\n\n if (!element) {\n element = document.createElement(\"meta\");\n element.setAttribute(\"name\", name);\n\n document.head.appendChild(element);\n }\n\n element.setAttribute(\"content\", content);\n\n return element\n}\n\nfunction findClosestRecursively(element, selector) {\n if (element instanceof Element) {\n return (\n element.closest(selector) || findClosestRecursively(element.assignedSlot || element.getRootNode()?.host, selector)\n )\n }\n}\n\nfunction elementIsFocusable(element) {\n const inertDisabledOrHidden = \"[inert], :disabled, [hidden], details:not([open]), dialog:not([open])\";\n\n return !!element && element.closest(inertDisabledOrHidden) == null && typeof element.focus == \"function\"\n}\n\nfunction queryAutofocusableElement(elementOrDocumentFragment) {\n return Array.from(elementOrDocumentFragment.querySelectorAll(\"[autofocus]\")).find(elementIsFocusable)\n}\n\nasync function around(callback, reader) {\n const before = reader();\n\n callback();\n\n await nextAnimationFrame();\n\n const after = reader();\n\n return [before, after]\n}\n\nfunction doesNotTargetIFrame(name) {\n if (name === \"_blank\") {\n return false\n } else if (name) {\n for (const element of document.getElementsByName(name)) {\n if (element instanceof HTMLIFrameElement) return false\n }\n\n return true\n } else {\n return true\n }\n}\n\nfunction findLinkFromClickTarget(target) {\n return findClosestRecursively(target, \"a[href]:not([target^=_]):not([download])\")\n}\n\nfunction getLocationForLink(link) {\n return expandURL(link.getAttribute(\"href\") || \"\")\n}\n\nfunction debounce(fn, delay) {\n let timeoutId = null;\n\n return (...args) => {\n const callback = () => fn.apply(this, args);\n clearTimeout(timeoutId);\n timeoutId = setTimeout(callback, delay);\n }\n}\n\nconst submitter = {\n \"aria-disabled\": {\n beforeSubmit: submitter => {\n submitter.setAttribute(\"aria-disabled\", \"true\");\n submitter.addEventListener(\"click\", cancelEvent);\n },\n\n afterSubmit: submitter => {\n submitter.removeAttribute(\"aria-disabled\");\n submitter.removeEventListener(\"click\", cancelEvent);\n }\n },\n\n \"disabled\": {\n beforeSubmit: submitter => submitter.disabled = true,\n afterSubmit: submitter => submitter.disabled = false\n }\n};\n\nclass Config {\n #submitter = null\n\n constructor(config) {\n Object.assign(this, config);\n }\n\n get submitter() {\n return this.#submitter\n }\n\n set submitter(value) {\n this.#submitter = submitter[value] || value;\n }\n}\n\nconst forms = new Config({\n mode: \"on\",\n submitter: \"disabled\"\n});\n\nconst config = {\n drive,\n forms\n};\n\nfunction expandURL(locatable) {\n return new URL(locatable.toString(), document.baseURI)\n}\n\nfunction getAnchor(url) {\n let anchorMatch;\n if (url.hash) {\n return url.hash.slice(1)\n // eslint-disable-next-line no-cond-assign\n } else if ((anchorMatch = url.href.match(/#(.*)$/))) {\n return anchorMatch[1]\n }\n}\n\nfunction getAction$1(form, submitter) {\n const action = submitter?.getAttribute(\"formaction\") || form.getAttribute(\"action\") || form.action;\n\n return expandURL(action)\n}\n\nfunction getExtension(url) {\n return (getLastPathComponent(url).match(/\\.[^.]*$/) || [])[0] || \"\"\n}\n\nfunction isPrefixedBy(baseURL, url) {\n const prefix = getPrefix(url);\n return baseURL.href === expandURL(prefix).href || baseURL.href.startsWith(prefix)\n}\n\nfunction locationIsVisitable(location, rootLocation) {\n return isPrefixedBy(location, rootLocation) && !config.drive.unvisitableExtensions.has(getExtension(location))\n}\n\nfunction getRequestURL(url) {\n const anchor = getAnchor(url);\n return anchor != null ? url.href.slice(0, -(anchor.length + 1)) : url.href\n}\n\nfunction toCacheKey(url) {\n return getRequestURL(url)\n}\n\nfunction urlsAreEqual(left, right) {\n return expandURL(left).href == expandURL(right).href\n}\n\nfunction getPathComponents(url) {\n return url.pathname.split(\"/\").slice(1)\n}\n\nfunction getLastPathComponent(url) {\n return getPathComponents(url).slice(-1)[0]\n}\n\nfunction getPrefix(url) {\n return addTrailingSlash(url.origin + url.pathname)\n}\n\nfunction addTrailingSlash(value) {\n return value.endsWith(\"/\") ? value : value + \"/\"\n}\n\nclass FetchResponse {\n constructor(response) {\n this.response = response;\n }\n\n get succeeded() {\n return this.response.ok\n }\n\n get failed() {\n return !this.succeeded\n }\n\n get clientError() {\n return this.statusCode >= 400 && this.statusCode <= 499\n }\n\n get serverError() {\n return this.statusCode >= 500 && this.statusCode <= 599\n }\n\n get redirected() {\n return this.response.redirected\n }\n\n get location() {\n return expandURL(this.response.url)\n }\n\n get isHTML() {\n return this.contentType && this.contentType.match(/^(?:text\\/([^\\s;,]+\\b)?html|application\\/xhtml\\+xml)\\b/)\n }\n\n get statusCode() {\n return this.response.status\n }\n\n get contentType() {\n return this.header(\"Content-Type\")\n }\n\n get responseText() {\n return this.response.clone().text()\n }\n\n get responseHTML() {\n if (this.isHTML) {\n return this.response.clone().text()\n } else {\n return Promise.resolve(undefined)\n }\n }\n\n header(name) {\n return this.response.headers.get(name)\n }\n}\n\nclass LimitedSet extends Set {\n constructor(maxSize) {\n super();\n this.maxSize = maxSize;\n }\n\n add(value) {\n if (this.size >= this.maxSize) {\n const iterator = this.values();\n const oldestValue = iterator.next().value;\n this.delete(oldestValue);\n }\n super.add(value);\n }\n}\n\nconst recentRequests = new LimitedSet(20);\n\nconst nativeFetch = window.fetch;\n\nfunction fetchWithTurboHeaders(url, options = {}) {\n const modifiedHeaders = new Headers(options.headers || {});\n const requestUID = uuid();\n recentRequests.add(requestUID);\n modifiedHeaders.append(\"X-Turbo-Request-Id\", requestUID);\n\n return nativeFetch(url, {\n ...options,\n headers: modifiedHeaders\n })\n}\n\nfunction fetchMethodFromString(method) {\n switch (method.toLowerCase()) {\n case \"get\":\n return FetchMethod.get\n case \"post\":\n return FetchMethod.post\n case \"put\":\n return FetchMethod.put\n case \"patch\":\n return FetchMethod.patch\n case \"delete\":\n return FetchMethod.delete\n }\n}\n\nconst FetchMethod = {\n get: \"get\",\n post: \"post\",\n put: \"put\",\n patch: \"patch\",\n delete: \"delete\"\n};\n\nfunction fetchEnctypeFromString(encoding) {\n switch (encoding.toLowerCase()) {\n case FetchEnctype.multipart:\n return FetchEnctype.multipart\n case FetchEnctype.plain:\n return FetchEnctype.plain\n default:\n return FetchEnctype.urlEncoded\n }\n}\n\nconst FetchEnctype = {\n urlEncoded: \"application/x-www-form-urlencoded\",\n multipart: \"multipart/form-data\",\n plain: \"text/plain\"\n};\n\nclass FetchRequest {\n abortController = new AbortController()\n #resolveRequestPromise = (_value) => {}\n\n constructor(delegate, method, location, requestBody = new URLSearchParams(), target = null, enctype = FetchEnctype.urlEncoded) {\n const [url, body] = buildResourceAndBody(expandURL(location), method, requestBody, enctype);\n\n this.delegate = delegate;\n this.url = url;\n this.target = target;\n this.fetchOptions = {\n credentials: \"same-origin\",\n redirect: \"follow\",\n method: method.toUpperCase(),\n headers: { ...this.defaultHeaders },\n body: body,\n signal: this.abortSignal,\n referrer: this.delegate.referrer?.href\n };\n this.enctype = enctype;\n }\n\n get method() {\n return this.fetchOptions.method\n }\n\n set method(value) {\n const fetchBody = this.isSafe ? this.url.searchParams : this.fetchOptions.body || new FormData();\n const fetchMethod = fetchMethodFromString(value) || FetchMethod.get;\n\n this.url.search = \"\";\n\n const [url, body] = buildResourceAndBody(this.url, fetchMethod, fetchBody, this.enctype);\n\n this.url = url;\n this.fetchOptions.body = body;\n this.fetchOptions.method = fetchMethod.toUpperCase();\n }\n\n get headers() {\n return this.fetchOptions.headers\n }\n\n set headers(value) {\n this.fetchOptions.headers = value;\n }\n\n get body() {\n if (this.isSafe) {\n return this.url.searchParams\n } else {\n return this.fetchOptions.body\n }\n }\n\n set body(value) {\n this.fetchOptions.body = value;\n }\n\n get location() {\n return this.url\n }\n\n get params() {\n return this.url.searchParams\n }\n\n get entries() {\n return this.body ? Array.from(this.body.entries()) : []\n }\n\n cancel() {\n this.abortController.abort();\n }\n\n async perform() {\n const { fetchOptions } = this;\n this.delegate.prepareRequest(this);\n const event = await this.#allowRequestToBeIntercepted(fetchOptions);\n try {\n this.delegate.requestStarted(this);\n\n if (event.detail.fetchRequest) {\n this.response = event.detail.fetchRequest.response;\n } else {\n this.response = fetchWithTurboHeaders(this.url.href, fetchOptions);\n }\n\n const response = await this.response;\n return await this.receive(response)\n } catch (error) {\n if (error.name !== \"AbortError\") {\n if (this.#willDelegateErrorHandling(error)) {\n this.delegate.requestErrored(this, error);\n }\n throw error\n }\n } finally {\n this.delegate.requestFinished(this);\n }\n }\n\n async receive(response) {\n const fetchResponse = new FetchResponse(response);\n const event = dispatch(\"turbo:before-fetch-response\", {\n cancelable: true,\n detail: { fetchResponse },\n target: this.target\n });\n if (event.defaultPrevented) {\n this.delegate.requestPreventedHandlingResponse(this, fetchResponse);\n } else if (fetchResponse.succeeded) {\n this.delegate.requestSucceededWithResponse(this, fetchResponse);\n } else {\n this.delegate.requestFailedWithResponse(this, fetchResponse);\n }\n return fetchResponse\n }\n\n get defaultHeaders() {\n return {\n Accept: \"text/html, application/xhtml+xml\"\n }\n }\n\n get isSafe() {\n return isSafe(this.method)\n }\n\n get abortSignal() {\n return this.abortController.signal\n }\n\n acceptResponseType(mimeType) {\n this.headers[\"Accept\"] = [mimeType, this.headers[\"Accept\"]].join(\", \");\n }\n\n async #allowRequestToBeIntercepted(fetchOptions) {\n const requestInterception = new Promise((resolve) => (this.#resolveRequestPromise = resolve));\n const event = dispatch(\"turbo:before-fetch-request\", {\n cancelable: true,\n detail: {\n fetchOptions,\n url: this.url,\n resume: this.#resolveRequestPromise\n },\n target: this.target\n });\n this.url = event.detail.url;\n if (event.defaultPrevented) await requestInterception;\n\n return event\n }\n\n #willDelegateErrorHandling(error) {\n const event = dispatch(\"turbo:fetch-request-error\", {\n target: this.target,\n cancelable: true,\n detail: { request: this, error: error }\n });\n\n return !event.defaultPrevented\n }\n}\n\nfunction isSafe(fetchMethod) {\n return fetchMethodFromString(fetchMethod) == FetchMethod.get\n}\n\nfunction buildResourceAndBody(resource, method, requestBody, enctype) {\n const searchParams =\n Array.from(requestBody).length > 0 ? new URLSearchParams(entriesExcludingFiles(requestBody)) : resource.searchParams;\n\n if (isSafe(method)) {\n return [mergeIntoURLSearchParams(resource, searchParams), null]\n } else if (enctype == FetchEnctype.urlEncoded) {\n return [resource, searchParams]\n } else {\n return [resource, requestBody]\n }\n}\n\nfunction entriesExcludingFiles(requestBody) {\n const entries = [];\n\n for (const [name, value] of requestBody) {\n if (value instanceof File) continue\n else entries.push([name, value]);\n }\n\n return entries\n}\n\nfunction mergeIntoURLSearchParams(url, requestBody) {\n const searchParams = new URLSearchParams(entriesExcludingFiles(requestBody));\n\n url.search = searchParams.toString();\n\n return url\n}\n\nclass AppearanceObserver {\n started = false\n\n constructor(delegate, element) {\n this.delegate = delegate;\n this.element = element;\n this.intersectionObserver = new IntersectionObserver(this.intersect);\n }\n\n start() {\n if (!this.started) {\n this.started = true;\n this.intersectionObserver.observe(this.element);\n }\n }\n\n stop() {\n if (this.started) {\n this.started = false;\n this.intersectionObserver.unobserve(this.element);\n }\n }\n\n intersect = (entries) => {\n const lastEntry = entries.slice(-1)[0];\n if (lastEntry?.isIntersecting) {\n this.delegate.elementAppearedInViewport(this.element);\n }\n }\n}\n\nclass StreamMessage {\n static contentType = \"text/vnd.turbo-stream.html\"\n\n static wrap(message) {\n if (typeof message == \"string\") {\n return new this(createDocumentFragment(message))\n } else {\n return message\n }\n }\n\n constructor(fragment) {\n this.fragment = importStreamElements(fragment);\n }\n}\n\nfunction importStreamElements(fragment) {\n for (const element of fragment.querySelectorAll(\"turbo-stream\")) {\n const streamElement = document.importNode(element, true);\n\n for (const inertScriptElement of streamElement.templateElement.content.querySelectorAll(\"script\")) {\n inertScriptElement.replaceWith(activateScriptElement(inertScriptElement));\n }\n\n element.replaceWith(streamElement);\n }\n\n return fragment\n}\n\nconst PREFETCH_DELAY = 100;\n\nclass PrefetchCache {\n #prefetchTimeout = null\n #prefetched = null\n\n get(url) {\n if (this.#prefetched && this.#prefetched.url === url && this.#prefetched.expire > Date.now()) {\n return this.#prefetched.request\n }\n }\n\n setLater(url, request, ttl) {\n this.clear();\n\n this.#prefetchTimeout = setTimeout(() => {\n request.perform();\n this.set(url, request, ttl);\n this.#prefetchTimeout = null;\n }, PREFETCH_DELAY);\n }\n\n set(url, request, ttl) {\n this.#prefetched = { url, request, expire: new Date(new Date().getTime() + ttl) };\n }\n\n clear() {\n if (this.#prefetchTimeout) clearTimeout(this.#prefetchTimeout);\n this.#prefetched = null;\n }\n}\n\nconst cacheTtl = 10 * 1000;\nconst prefetchCache = new PrefetchCache();\n\nconst FormSubmissionState = {\n initialized: \"initialized\",\n requesting: \"requesting\",\n waiting: \"waiting\",\n receiving: \"receiving\",\n stopping: \"stopping\",\n stopped: \"stopped\"\n};\n\nclass FormSubmission {\n state = FormSubmissionState.initialized\n\n static confirmMethod(message) {\n return Promise.resolve(confirm(message))\n }\n\n constructor(delegate, formElement, submitter, mustRedirect = false) {\n const method = getMethod(formElement, submitter);\n const action = getAction(getFormAction(formElement, submitter), method);\n const body = buildFormData(formElement, submitter);\n const enctype = getEnctype(formElement, submitter);\n\n this.delegate = delegate;\n this.formElement = formElement;\n this.submitter = submitter;\n this.fetchRequest = new FetchRequest(this, method, action, body, formElement, enctype);\n this.mustRedirect = mustRedirect;\n }\n\n get method() {\n return this.fetchRequest.method\n }\n\n set method(value) {\n this.fetchRequest.method = value;\n }\n\n get action() {\n return this.fetchRequest.url.toString()\n }\n\n set action(value) {\n this.fetchRequest.url = expandURL(value);\n }\n\n get body() {\n return this.fetchRequest.body\n }\n\n get enctype() {\n return this.fetchRequest.enctype\n }\n\n get isSafe() {\n return this.fetchRequest.isSafe\n }\n\n get location() {\n return this.fetchRequest.url\n }\n\n // The submission process\n\n async start() {\n const { initialized, requesting } = FormSubmissionState;\n const confirmationMessage = getAttribute(\"data-turbo-confirm\", this.submitter, this.formElement);\n\n if (typeof confirmationMessage === \"string\") {\n const confirmMethod = typeof config.forms.confirm === \"function\" ?\n config.forms.confirm :\n FormSubmission.confirmMethod;\n\n const answer = await confirmMethod(confirmationMessage, this.formElement, this.submitter);\n if (!answer) {\n return\n }\n }\n\n if (this.state == initialized) {\n this.state = requesting;\n return this.fetchRequest.perform()\n }\n }\n\n stop() {\n const { stopping, stopped } = FormSubmissionState;\n if (this.state != stopping && this.state != stopped) {\n this.state = stopping;\n this.fetchRequest.cancel();\n return true\n }\n }\n\n // Fetch request delegate\n\n prepareRequest(request) {\n if (!request.isSafe) {\n const token = getCookieValue(getMetaContent(\"csrf-param\")) || getMetaContent(\"csrf-token\");\n if (token) {\n request.headers[\"X-CSRF-Token\"] = token;\n }\n }\n\n if (this.requestAcceptsTurboStreamResponse(request)) {\n request.acceptResponseType(StreamMessage.contentType);\n }\n }\n\n requestStarted(_request) {\n this.state = FormSubmissionState.waiting;\n if (this.submitter) config.forms.submitter.beforeSubmit(this.submitter);\n this.setSubmitsWith();\n markAsBusy(this.formElement);\n dispatch(\"turbo:submit-start\", {\n target: this.formElement,\n detail: { formSubmission: this }\n });\n this.delegate.formSubmissionStarted(this);\n }\n\n requestPreventedHandlingResponse(request, response) {\n prefetchCache.clear();\n\n this.result = { success: response.succeeded, fetchResponse: response };\n }\n\n requestSucceededWithResponse(request, response) {\n if (response.clientError || response.serverError) {\n this.delegate.formSubmissionFailedWithResponse(this, response);\n return\n }\n\n prefetchCache.clear();\n\n if (this.requestMustRedirect(request) && responseSucceededWithoutRedirect(response)) {\n const error = new Error(\"Form responses must redirect to another location\");\n this.delegate.formSubmissionErrored(this, error);\n } else {\n this.state = FormSubmissionState.receiving;\n this.result = { success: true, fetchResponse: response };\n this.delegate.formSubmissionSucceededWithResponse(this, response);\n }\n }\n\n requestFailedWithResponse(request, response) {\n this.result = { success: false, fetchResponse: response };\n this.delegate.formSubmissionFailedWithResponse(this, response);\n }\n\n requestErrored(request, error) {\n this.result = { success: false, error };\n this.delegate.formSubmissionErrored(this, error);\n }\n\n requestFinished(_request) {\n this.state = FormSubmissionState.stopped;\n if (this.submitter) config.forms.submitter.afterSubmit(this.submitter);\n this.resetSubmitterText();\n clearBusyState(this.formElement);\n dispatch(\"turbo:submit-end\", {\n target: this.formElement,\n detail: { formSubmission: this, ...this.result }\n });\n this.delegate.formSubmissionFinished(this);\n }\n\n // Private\n\n setSubmitsWith() {\n if (!this.submitter || !this.submitsWith) return\n\n if (this.submitter.matches(\"button\")) {\n this.originalSubmitText = this.submitter.innerHTML;\n this.submitter.innerHTML = this.submitsWith;\n } else if (this.submitter.matches(\"input\")) {\n const input = this.submitter;\n this.originalSubmitText = input.value;\n input.value = this.submitsWith;\n }\n }\n\n resetSubmitterText() {\n if (!this.submitter || !this.originalSubmitText) return\n\n if (this.submitter.matches(\"button\")) {\n this.submitter.innerHTML = this.originalSubmitText;\n } else if (this.submitter.matches(\"input\")) {\n const input = this.submitter;\n input.value = this.originalSubmitText;\n }\n }\n\n requestMustRedirect(request) {\n return !request.isSafe && this.mustRedirect\n }\n\n requestAcceptsTurboStreamResponse(request) {\n return !request.isSafe || hasAttribute(\"data-turbo-stream\", this.submitter, this.formElement)\n }\n\n get submitsWith() {\n return this.submitter?.getAttribute(\"data-turbo-submits-with\")\n }\n}\n\nfunction buildFormData(formElement, submitter) {\n const formData = new FormData(formElement);\n const name = submitter?.getAttribute(\"name\");\n const value = submitter?.getAttribute(\"value\");\n\n if (name) {\n formData.append(name, value || \"\");\n }\n\n return formData\n}\n\nfunction getCookieValue(cookieName) {\n if (cookieName != null) {\n const cookies = document.cookie ? document.cookie.split(\"; \") : [];\n const cookie = cookies.find((cookie) => cookie.startsWith(cookieName));\n if (cookie) {\n const value = cookie.split(\"=\").slice(1).join(\"=\");\n return value ? decodeURIComponent(value) : undefined\n }\n }\n}\n\nfunction responseSucceededWithoutRedirect(response) {\n return response.statusCode == 200 && !response.redirected\n}\n\nfunction getFormAction(formElement, submitter) {\n const formElementAction = typeof formElement.action === \"string\" ? formElement.action : null;\n\n if (submitter?.hasAttribute(\"formaction\")) {\n return submitter.getAttribute(\"formaction\") || \"\"\n } else {\n return formElement.getAttribute(\"action\") || formElementAction || \"\"\n }\n}\n\nfunction getAction(formAction, fetchMethod) {\n const action = expandURL(formAction);\n\n if (isSafe(fetchMethod)) {\n action.search = \"\";\n }\n\n return action\n}\n\nfunction getMethod(formElement, submitter) {\n const method = submitter?.getAttribute(\"formmethod\") || formElement.getAttribute(\"method\") || \"\";\n return fetchMethodFromString(method.toLowerCase()) || FetchMethod.get\n}\n\nfunction getEnctype(formElement, submitter) {\n return fetchEnctypeFromString(submitter?.getAttribute(\"formenctype\") || formElement.enctype)\n}\n\nclass Snapshot {\n constructor(element) {\n this.element = element;\n }\n\n get activeElement() {\n return this.element.ownerDocument.activeElement\n }\n\n get children() {\n return [...this.element.children]\n }\n\n hasAnchor(anchor) {\n return this.getElementForAnchor(anchor) != null\n }\n\n getElementForAnchor(anchor) {\n return anchor ? this.element.querySelector(`[id='${anchor}'], a[name='${anchor}']`) : null\n }\n\n get isConnected() {\n return this.element.isConnected\n }\n\n get firstAutofocusableElement() {\n return queryAutofocusableElement(this.element)\n }\n\n get permanentElements() {\n return queryPermanentElementsAll(this.element)\n }\n\n getPermanentElementById(id) {\n return getPermanentElementById(this.element, id)\n }\n\n getPermanentElementMapForSnapshot(snapshot) {\n const permanentElementMap = {};\n\n for (const currentPermanentElement of this.permanentElements) {\n const { id } = currentPermanentElement;\n const newPermanentElement = snapshot.getPermanentElementById(id);\n if (newPermanentElement) {\n permanentElementMap[id] = [currentPermanentElement, newPermanentElement];\n }\n }\n\n return permanentElementMap\n }\n}\n\nfunction getPermanentElementById(node, id) {\n return node.querySelector(`#${id}[data-turbo-permanent]`)\n}\n\nfunction queryPermanentElementsAll(node) {\n return node.querySelectorAll(\"[id][data-turbo-permanent]\")\n}\n\nclass FormSubmitObserver {\n started = false\n\n constructor(delegate, eventTarget) {\n this.delegate = delegate;\n this.eventTarget = eventTarget;\n }\n\n start() {\n if (!this.started) {\n this.eventTarget.addEventListener(\"submit\", this.submitCaptured, true);\n this.started = true;\n }\n }\n\n stop() {\n if (this.started) {\n this.eventTarget.removeEventListener(\"submit\", this.submitCaptured, true);\n this.started = false;\n }\n }\n\n submitCaptured = () => {\n this.eventTarget.removeEventListener(\"submit\", this.submitBubbled, false);\n this.eventTarget.addEventListener(\"submit\", this.submitBubbled, false);\n }\n\n submitBubbled = (event) => {\n if (!event.defaultPrevented) {\n const form = event.target instanceof HTMLFormElement ? event.target : undefined;\n const submitter = event.submitter || undefined;\n\n if (\n form &&\n submissionDoesNotDismissDialog(form, submitter) &&\n submissionDoesNotTargetIFrame(form, submitter) &&\n this.delegate.willSubmitForm(form, submitter)\n ) {\n event.preventDefault();\n event.stopImmediatePropagation();\n this.delegate.formSubmitted(form, submitter);\n }\n }\n }\n}\n\nfunction submissionDoesNotDismissDialog(form, submitter) {\n const method = submitter?.getAttribute(\"formmethod\") || form.getAttribute(\"method\");\n\n return method != \"dialog\"\n}\n\nfunction submissionDoesNotTargetIFrame(form, submitter) {\n const target = submitter?.getAttribute(\"formtarget\") || form.getAttribute(\"target\");\n\n return doesNotTargetIFrame(target)\n}\n\nclass View {\n #resolveRenderPromise = (_value) => {}\n #resolveInterceptionPromise = (_value) => {}\n\n constructor(delegate, element) {\n this.delegate = delegate;\n this.element = element;\n }\n\n // Scrolling\n\n scrollToAnchor(anchor) {\n const element = this.snapshot.getElementForAnchor(anchor);\n if (element) {\n this.scrollToElement(element);\n this.focusElement(element);\n } else {\n this.scrollToPosition({ x: 0, y: 0 });\n }\n }\n\n scrollToAnchorFromLocation(location) {\n this.scrollToAnchor(getAnchor(location));\n }\n\n scrollToElement(element) {\n element.scrollIntoView();\n }\n\n focusElement(element) {\n if (element instanceof HTMLElement) {\n if (element.hasAttribute(\"tabindex\")) {\n element.focus();\n } else {\n element.setAttribute(\"tabindex\", \"-1\");\n element.focus();\n element.removeAttribute(\"tabindex\");\n }\n }\n }\n\n scrollToPosition({ x, y }) {\n this.scrollRoot.scrollTo(x, y);\n }\n\n scrollToTop() {\n this.scrollToPosition({ x: 0, y: 0 });\n }\n\n get scrollRoot() {\n return window\n }\n\n // Rendering\n\n async render(renderer) {\n const { isPreview, shouldRender, willRender, newSnapshot: snapshot } = renderer;\n\n // A workaround to ignore tracked element mismatch reloads when performing\n // a promoted Visit from a frame navigation\n const shouldInvalidate = willRender;\n\n if (shouldRender) {\n try {\n this.renderPromise = new Promise((resolve) => (this.#resolveRenderPromise = resolve));\n this.renderer = renderer;\n await this.prepareToRenderSnapshot(renderer);\n\n const renderInterception = new Promise((resolve) => (this.#resolveInterceptionPromise = resolve));\n const options = { resume: this.#resolveInterceptionPromise, render: this.renderer.renderElement, renderMethod: this.renderer.renderMethod };\n const immediateRender = this.delegate.allowsImmediateRender(snapshot, options);\n if (!immediateRender) await renderInterception;\n\n await this.renderSnapshot(renderer);\n this.delegate.viewRenderedSnapshot(snapshot, isPreview, this.renderer.renderMethod);\n this.delegate.preloadOnLoadLinksForView(this.element);\n this.finishRenderingSnapshot(renderer);\n } finally {\n delete this.renderer;\n this.#resolveRenderPromise(undefined);\n delete this.renderPromise;\n }\n } else if (shouldInvalidate) {\n this.invalidate(renderer.reloadReason);\n }\n }\n\n invalidate(reason) {\n this.delegate.viewInvalidated(reason);\n }\n\n async prepareToRenderSnapshot(renderer) {\n this.markAsPreview(renderer.isPreview);\n await renderer.prepareToRender();\n }\n\n markAsPreview(isPreview) {\n if (isPreview) {\n this.element.setAttribute(\"data-turbo-preview\", \"\");\n } else {\n this.element.removeAttribute(\"data-turbo-preview\");\n }\n }\n\n markVisitDirection(direction) {\n this.element.setAttribute(\"data-turbo-visit-direction\", direction);\n }\n\n unmarkVisitDirection() {\n this.element.removeAttribute(\"data-turbo-visit-direction\");\n }\n\n async renderSnapshot(renderer) {\n await renderer.render();\n }\n\n finishRenderingSnapshot(renderer) {\n renderer.finishRendering();\n }\n}\n\nclass FrameView extends View {\n missing() {\n this.element.innerHTML = `Content missing`;\n }\n\n get snapshot() {\n return new Snapshot(this.element)\n }\n}\n\nclass LinkInterceptor {\n constructor(delegate, element) {\n this.delegate = delegate;\n this.element = element;\n }\n\n start() {\n this.element.addEventListener(\"click\", this.clickBubbled);\n document.addEventListener(\"turbo:click\", this.linkClicked);\n document.addEventListener(\"turbo:before-visit\", this.willVisit);\n }\n\n stop() {\n this.element.removeEventListener(\"click\", this.clickBubbled);\n document.removeEventListener(\"turbo:click\", this.linkClicked);\n document.removeEventListener(\"turbo:before-visit\", this.willVisit);\n }\n\n clickBubbled = (event) => {\n if (this.clickEventIsSignificant(event)) {\n this.clickEvent = event;\n } else {\n delete this.clickEvent;\n }\n }\n\n linkClicked = (event) => {\n if (this.clickEvent && this.clickEventIsSignificant(event)) {\n if (this.delegate.shouldInterceptLinkClick(event.target, event.detail.url, event.detail.originalEvent)) {\n this.clickEvent.preventDefault();\n event.preventDefault();\n this.delegate.linkClickIntercepted(event.target, event.detail.url, event.detail.originalEvent);\n }\n }\n delete this.clickEvent;\n }\n\n willVisit = (_event) => {\n delete this.clickEvent;\n }\n\n clickEventIsSignificant(event) {\n const target = event.composed ? event.target?.parentElement : event.target;\n const element = findLinkFromClickTarget(target) || target;\n\n return element instanceof Element && element.closest(\"turbo-frame, html\") == this.element\n }\n}\n\nclass LinkClickObserver {\n started = false\n\n constructor(delegate, eventTarget) {\n this.delegate = delegate;\n this.eventTarget = eventTarget;\n }\n\n start() {\n if (!this.started) {\n this.eventTarget.addEventListener(\"click\", this.clickCaptured, true);\n this.started = true;\n }\n }\n\n stop() {\n if (this.started) {\n this.eventTarget.removeEventListener(\"click\", this.clickCaptured, true);\n this.started = false;\n }\n }\n\n clickCaptured = () => {\n this.eventTarget.removeEventListener(\"click\", this.clickBubbled, false);\n this.eventTarget.addEventListener(\"click\", this.clickBubbled, false);\n }\n\n clickBubbled = (event) => {\n if (event instanceof MouseEvent && this.clickEventIsSignificant(event)) {\n const target = (event.composedPath && event.composedPath()[0]) || event.target;\n const link = findLinkFromClickTarget(target);\n if (link && doesNotTargetIFrame(link.target)) {\n const location = getLocationForLink(link);\n if (this.delegate.willFollowLinkToLocation(link, location, event)) {\n event.preventDefault();\n this.delegate.followedLinkToLocation(link, location);\n }\n }\n }\n }\n\n clickEventIsSignificant(event) {\n return !(\n (event.target && event.target.isContentEditable) ||\n event.defaultPrevented ||\n event.which > 1 ||\n event.altKey ||\n event.ctrlKey ||\n event.metaKey ||\n event.shiftKey\n )\n }\n}\n\nclass FormLinkClickObserver {\n constructor(delegate, element) {\n this.delegate = delegate;\n this.linkInterceptor = new LinkClickObserver(this, element);\n }\n\n start() {\n this.linkInterceptor.start();\n }\n\n stop() {\n this.linkInterceptor.stop();\n }\n\n // Link hover observer delegate\n\n canPrefetchRequestToLocation(link, location) {\n return false\n }\n\n prefetchAndCacheRequestToLocation(link, location) {\n return\n }\n\n // Link click observer delegate\n\n willFollowLinkToLocation(link, location, originalEvent) {\n return (\n this.delegate.willSubmitFormLinkToLocation(link, location, originalEvent) &&\n (link.hasAttribute(\"data-turbo-method\") || link.hasAttribute(\"data-turbo-stream\"))\n )\n }\n\n followedLinkToLocation(link, location) {\n const form = document.createElement(\"form\");\n\n const type = \"hidden\";\n for (const [name, value] of location.searchParams) {\n form.append(Object.assign(document.createElement(\"input\"), { type, name, value }));\n }\n\n const action = Object.assign(location, { search: \"\" });\n form.setAttribute(\"data-turbo\", \"true\");\n form.setAttribute(\"action\", action.href);\n form.setAttribute(\"hidden\", \"\");\n\n const method = link.getAttribute(\"data-turbo-method\");\n if (method) form.setAttribute(\"method\", method);\n\n const turboFrame = link.getAttribute(\"data-turbo-frame\");\n if (turboFrame) form.setAttribute(\"data-turbo-frame\", turboFrame);\n\n const turboAction = getVisitAction(link);\n if (turboAction) form.setAttribute(\"data-turbo-action\", turboAction);\n\n const turboConfirm = link.getAttribute(\"data-turbo-confirm\");\n if (turboConfirm) form.setAttribute(\"data-turbo-confirm\", turboConfirm);\n\n const turboStream = link.hasAttribute(\"data-turbo-stream\");\n if (turboStream) form.setAttribute(\"data-turbo-stream\", \"\");\n\n this.delegate.submittedFormLinkToLocation(link, location, form);\n\n document.body.appendChild(form);\n form.addEventListener(\"turbo:submit-end\", () => form.remove(), { once: true });\n requestAnimationFrame(() => form.requestSubmit());\n }\n}\n\nclass Bardo {\n static async preservingPermanentElements(delegate, permanentElementMap, callback) {\n const bardo = new this(delegate, permanentElementMap);\n bardo.enter();\n await callback();\n bardo.leave();\n }\n\n constructor(delegate, permanentElementMap) {\n this.delegate = delegate;\n this.permanentElementMap = permanentElementMap;\n }\n\n enter() {\n for (const id in this.permanentElementMap) {\n const [currentPermanentElement, newPermanentElement] = this.permanentElementMap[id];\n this.delegate.enteringBardo(currentPermanentElement, newPermanentElement);\n this.replaceNewPermanentElementWithPlaceholder(newPermanentElement);\n }\n }\n\n leave() {\n for (const id in this.permanentElementMap) {\n const [currentPermanentElement] = this.permanentElementMap[id];\n this.replaceCurrentPermanentElementWithClone(currentPermanentElement);\n this.replacePlaceholderWithPermanentElement(currentPermanentElement);\n this.delegate.leavingBardo(currentPermanentElement);\n }\n }\n\n replaceNewPermanentElementWithPlaceholder(permanentElement) {\n const placeholder = createPlaceholderForPermanentElement(permanentElement);\n permanentElement.replaceWith(placeholder);\n }\n\n replaceCurrentPermanentElementWithClone(permanentElement) {\n const clone = permanentElement.cloneNode(true);\n permanentElement.replaceWith(clone);\n }\n\n replacePlaceholderWithPermanentElement(permanentElement) {\n const placeholder = this.getPlaceholderById(permanentElement.id);\n placeholder?.replaceWith(permanentElement);\n }\n\n getPlaceholderById(id) {\n return this.placeholders.find((element) => element.content == id)\n }\n\n get placeholders() {\n return [...document.querySelectorAll(\"meta[name=turbo-permanent-placeholder][content]\")]\n }\n}\n\nfunction createPlaceholderForPermanentElement(permanentElement) {\n const element = document.createElement(\"meta\");\n element.setAttribute(\"name\", \"turbo-permanent-placeholder\");\n element.setAttribute(\"content\", permanentElement.id);\n return element\n}\n\nclass Renderer {\n #activeElement = null\n\n static renderElement(currentElement, newElement) {\n // Abstract method\n }\n\n constructor(currentSnapshot, newSnapshot, isPreview, willRender = true) {\n this.currentSnapshot = currentSnapshot;\n this.newSnapshot = newSnapshot;\n this.isPreview = isPreview;\n this.willRender = willRender;\n this.renderElement = this.constructor.renderElement;\n this.promise = new Promise((resolve, reject) => (this.resolvingFunctions = { resolve, reject }));\n }\n\n get shouldRender() {\n return true\n }\n\n get shouldAutofocus() {\n return true\n }\n\n get reloadReason() {\n return\n }\n\n prepareToRender() {\n return\n }\n\n render() {\n // Abstract method\n }\n\n finishRendering() {\n if (this.resolvingFunctions) {\n this.resolvingFunctions.resolve();\n delete this.resolvingFunctions;\n }\n }\n\n async preservingPermanentElements(callback) {\n await Bardo.preservingPermanentElements(this, this.permanentElementMap, callback);\n }\n\n focusFirstAutofocusableElement() {\n if (this.shouldAutofocus) {\n const element = this.connectedSnapshot.firstAutofocusableElement;\n if (element) {\n element.focus();\n }\n }\n }\n\n // Bardo delegate\n\n enteringBardo(currentPermanentElement) {\n if (this.#activeElement) return\n\n if (currentPermanentElement.contains(this.currentSnapshot.activeElement)) {\n this.#activeElement = this.currentSnapshot.activeElement;\n }\n }\n\n leavingBardo(currentPermanentElement) {\n if (currentPermanentElement.contains(this.#activeElement) && this.#activeElement instanceof HTMLElement) {\n this.#activeElement.focus();\n\n this.#activeElement = null;\n }\n }\n\n get connectedSnapshot() {\n return this.newSnapshot.isConnected ? this.newSnapshot : this.currentSnapshot\n }\n\n get currentElement() {\n return this.currentSnapshot.element\n }\n\n get newElement() {\n return this.newSnapshot.element\n }\n\n get permanentElementMap() {\n return this.currentSnapshot.getPermanentElementMapForSnapshot(this.newSnapshot)\n }\n\n get renderMethod() {\n return \"replace\"\n }\n}\n\nclass FrameRenderer extends Renderer {\n static renderElement(currentElement, newElement) {\n const destinationRange = document.createRange();\n destinationRange.selectNodeContents(currentElement);\n destinationRange.deleteContents();\n\n const frameElement = newElement;\n const sourceRange = frameElement.ownerDocument?.createRange();\n if (sourceRange) {\n sourceRange.selectNodeContents(frameElement);\n currentElement.appendChild(sourceRange.extractContents());\n }\n }\n\n constructor(delegate, currentSnapshot, newSnapshot, renderElement, isPreview, willRender = true) {\n super(currentSnapshot, newSnapshot, renderElement, isPreview, willRender);\n this.delegate = delegate;\n }\n\n get shouldRender() {\n return true\n }\n\n async render() {\n await nextRepaint();\n this.preservingPermanentElements(() => {\n this.loadFrameElement();\n });\n this.scrollFrameIntoView();\n await nextRepaint();\n this.focusFirstAutofocusableElement();\n await nextRepaint();\n this.activateScriptElements();\n }\n\n loadFrameElement() {\n this.delegate.willRenderFrame(this.currentElement, this.newElement);\n this.renderElement(this.currentElement, this.newElement);\n }\n\n scrollFrameIntoView() {\n if (this.currentElement.autoscroll || this.newElement.autoscroll) {\n const element = this.currentElement.firstElementChild;\n const block = readScrollLogicalPosition(this.currentElement.getAttribute(\"data-autoscroll-block\"), \"end\");\n const behavior = readScrollBehavior(this.currentElement.getAttribute(\"data-autoscroll-behavior\"), \"auto\");\n\n if (element) {\n element.scrollIntoView({ block, behavior });\n return true\n }\n }\n return false\n }\n\n activateScriptElements() {\n for (const inertScriptElement of this.newScriptElements) {\n const activatedScriptElement = activateScriptElement(inertScriptElement);\n inertScriptElement.replaceWith(activatedScriptElement);\n }\n }\n\n get newScriptElements() {\n return this.currentElement.querySelectorAll(\"script\")\n }\n}\n\nfunction readScrollLogicalPosition(value, defaultValue) {\n if (value == \"end\" || value == \"start\" || value == \"center\" || value == \"nearest\") {\n return value\n } else {\n return defaultValue\n }\n}\n\nfunction readScrollBehavior(value, defaultValue) {\n if (value == \"auto\" || value == \"smooth\") {\n return value\n } else {\n return defaultValue\n }\n}\n\n// base IIFE to define idiomorph\nvar Idiomorph = (function () {\n\n //=============================================================================\n // AND NOW IT BEGINS...\n //=============================================================================\n let EMPTY_SET = new Set();\n\n // default configuration values, updatable by users now\n let defaults = {\n morphStyle: \"outerHTML\",\n callbacks : {\n beforeNodeAdded: noOp,\n afterNodeAdded: noOp,\n beforeNodeMorphed: noOp,\n afterNodeMorphed: noOp,\n beforeNodeRemoved: noOp,\n afterNodeRemoved: noOp,\n beforeAttributeUpdated: noOp,\n\n },\n head: {\n style: 'merge',\n shouldPreserve: function (elt) {\n return elt.getAttribute(\"im-preserve\") === \"true\";\n },\n shouldReAppend: function (elt) {\n return elt.getAttribute(\"im-re-append\") === \"true\";\n },\n shouldRemove: noOp,\n afterHeadMorphed: noOp,\n }\n };\n\n //=============================================================================\n // Core Morphing Algorithm - morph, morphNormalizedContent, morphOldNodeTo, morphChildren\n //=============================================================================\n function morph(oldNode, newContent, config = {}) {\n\n if (oldNode instanceof Document) {\n oldNode = oldNode.documentElement;\n }\n\n if (typeof newContent === 'string') {\n newContent = parseContent(newContent);\n }\n\n let normalizedContent = normalizeContent(newContent);\n\n let ctx = createMorphContext(oldNode, normalizedContent, config);\n\n return morphNormalizedContent(oldNode, normalizedContent, ctx);\n }\n\n function morphNormalizedContent(oldNode, normalizedNewContent, ctx) {\n if (ctx.head.block) {\n let oldHead = oldNode.querySelector('head');\n let newHead = normalizedNewContent.querySelector('head');\n if (oldHead && newHead) {\n let promises = handleHeadElement(newHead, oldHead, ctx);\n // when head promises resolve, call morph again, ignoring the head tag\n Promise.all(promises).then(function () {\n morphNormalizedContent(oldNode, normalizedNewContent, Object.assign(ctx, {\n head: {\n block: false,\n ignore: true\n }\n }));\n });\n return;\n }\n }\n\n if (ctx.morphStyle === \"innerHTML\") {\n\n // innerHTML, so we are only updating the children\n morphChildren(normalizedNewContent, oldNode, ctx);\n return oldNode.children;\n\n } else if (ctx.morphStyle === \"outerHTML\" || ctx.morphStyle == null) {\n // otherwise find the best element match in the new content, morph that, and merge its siblings\n // into either side of the best match\n let bestMatch = findBestNodeMatch(normalizedNewContent, oldNode, ctx);\n\n // stash the siblings that will need to be inserted on either side of the best match\n let previousSibling = bestMatch?.previousSibling;\n let nextSibling = bestMatch?.nextSibling;\n\n // morph it\n let morphedNode = morphOldNodeTo(oldNode, bestMatch, ctx);\n\n if (bestMatch) {\n // if there was a best match, merge the siblings in too and return the\n // whole bunch\n return insertSiblings(previousSibling, morphedNode, nextSibling);\n } else {\n // otherwise nothing was added to the DOM\n return []\n }\n } else {\n throw \"Do not understand how to morph style \" + ctx.morphStyle;\n }\n }\n\n\n /**\n * @param possibleActiveElement\n * @param ctx\n * @returns {boolean}\n */\n function ignoreValueOfActiveElement(possibleActiveElement, ctx) {\n return ctx.ignoreActiveValue && possibleActiveElement === document.activeElement && possibleActiveElement !== document.body;\n }\n\n /**\n * @param oldNode root node to merge content into\n * @param newContent new content to merge\n * @param ctx the merge context\n * @returns {Element} the element that ended up in the DOM\n */\n function morphOldNodeTo(oldNode, newContent, ctx) {\n if (ctx.ignoreActive && oldNode === document.activeElement) ; else if (newContent == null) {\n if (ctx.callbacks.beforeNodeRemoved(oldNode) === false) return oldNode;\n\n oldNode.remove();\n ctx.callbacks.afterNodeRemoved(oldNode);\n return null;\n } else if (!isSoftMatch(oldNode, newContent)) {\n if (ctx.callbacks.beforeNodeRemoved(oldNode) === false) return oldNode;\n if (ctx.callbacks.beforeNodeAdded(newContent) === false) return oldNode;\n\n oldNode.parentElement.replaceChild(newContent, oldNode);\n ctx.callbacks.afterNodeAdded(newContent);\n ctx.callbacks.afterNodeRemoved(oldNode);\n return newContent;\n } else {\n if (ctx.callbacks.beforeNodeMorphed(oldNode, newContent) === false) return oldNode;\n\n if (oldNode instanceof HTMLHeadElement && ctx.head.ignore) ; else if (oldNode instanceof HTMLHeadElement && ctx.head.style !== \"morph\") {\n handleHeadElement(newContent, oldNode, ctx);\n } else {\n syncNodeFrom(newContent, oldNode, ctx);\n if (!ignoreValueOfActiveElement(oldNode, ctx)) {\n morphChildren(newContent, oldNode, ctx);\n }\n }\n ctx.callbacks.afterNodeMorphed(oldNode, newContent);\n return oldNode;\n }\n }\n\n /**\n * This is the core algorithm for matching up children. The idea is to use id sets to try to match up\n * nodes as faithfully as possible. We greedily match, which allows us to keep the algorithm fast, but\n * by using id sets, we are able to better match up with content deeper in the DOM.\n *\n * Basic algorithm is, for each node in the new content:\n *\n * - if we have reached the end of the old parent, append the new content\n * - if the new content has an id set match with the current insertion point, morph\n * - search for an id set match\n * - if id set match found, morph\n * - otherwise search for a \"soft\" match\n * - if a soft match is found, morph\n * - otherwise, prepend the new node before the current insertion point\n *\n * The two search algorithms terminate if competing node matches appear to outweigh what can be achieved\n * with the current node. See findIdSetMatch() and findSoftMatch() for details.\n *\n * @param {Element} newParent the parent element of the new content\n * @param {Element } oldParent the old content that we are merging the new content into\n * @param ctx the merge context\n */\n function morphChildren(newParent, oldParent, ctx) {\n\n let nextNewChild = newParent.firstChild;\n let insertionPoint = oldParent.firstChild;\n let newChild;\n\n // run through all the new content\n while (nextNewChild) {\n\n newChild = nextNewChild;\n nextNewChild = newChild.nextSibling;\n\n // if we are at the end of the exiting parent's children, just append\n if (insertionPoint == null) {\n if (ctx.callbacks.beforeNodeAdded(newChild) === false) return;\n\n oldParent.appendChild(newChild);\n ctx.callbacks.afterNodeAdded(newChild);\n removeIdsFromConsideration(ctx, newChild);\n continue;\n }\n\n // if the current node has an id set match then morph\n if (isIdSetMatch(newChild, insertionPoint, ctx)) {\n morphOldNodeTo(insertionPoint, newChild, ctx);\n insertionPoint = insertionPoint.nextSibling;\n removeIdsFromConsideration(ctx, newChild);\n continue;\n }\n\n // otherwise search forward in the existing old children for an id set match\n let idSetMatch = findIdSetMatch(newParent, oldParent, newChild, insertionPoint, ctx);\n\n // if we found a potential match, remove the nodes until that point and morph\n if (idSetMatch) {\n insertionPoint = removeNodesBetween(insertionPoint, idSetMatch, ctx);\n morphOldNodeTo(idSetMatch, newChild, ctx);\n removeIdsFromConsideration(ctx, newChild);\n continue;\n }\n\n // no id set match found, so scan forward for a soft match for the current node\n let softMatch = findSoftMatch(newParent, oldParent, newChild, insertionPoint, ctx);\n\n // if we found a soft match for the current node, morph\n if (softMatch) {\n insertionPoint = removeNodesBetween(insertionPoint, softMatch, ctx);\n morphOldNodeTo(softMatch, newChild, ctx);\n removeIdsFromConsideration(ctx, newChild);\n continue;\n }\n\n // abandon all hope of morphing, just insert the new child before the insertion point\n // and move on\n if (ctx.callbacks.beforeNodeAdded(newChild) === false) return;\n\n oldParent.insertBefore(newChild, insertionPoint);\n ctx.callbacks.afterNodeAdded(newChild);\n removeIdsFromConsideration(ctx, newChild);\n }\n\n // remove any remaining old nodes that didn't match up with new content\n while (insertionPoint !== null) {\n\n let tempNode = insertionPoint;\n insertionPoint = insertionPoint.nextSibling;\n removeNode(tempNode, ctx);\n }\n }\n\n //=============================================================================\n // Attribute Syncing Code\n //=============================================================================\n\n /**\n * @param attr {String} the attribute to be mutated\n * @param to {Element} the element that is going to be updated\n * @param updateType {(\"update\"|\"remove\")}\n * @param ctx the merge context\n * @returns {boolean} true if the attribute should be ignored, false otherwise\n */\n function ignoreAttribute(attr, to, updateType, ctx) {\n if(attr === 'value' && ctx.ignoreActiveValue && to === document.activeElement){\n return true;\n }\n return ctx.callbacks.beforeAttributeUpdated(attr, to, updateType) === false;\n }\n\n /**\n * syncs a given node with another node, copying over all attributes and\n * inner element state from the 'from' node to the 'to' node\n *\n * @param {Element} from the element to copy attributes & state from\n * @param {Element} to the element to copy attributes & state to\n * @param ctx the merge context\n */\n function syncNodeFrom(from, to, ctx) {\n let type = from.nodeType;\n\n // if is an element type, sync the attributes from the\n // new node into the new node\n if (type === 1 /* element type */) {\n const fromAttributes = from.attributes;\n const toAttributes = to.attributes;\n for (const fromAttribute of fromAttributes) {\n if (ignoreAttribute(fromAttribute.name, to, 'update', ctx)) {\n continue;\n }\n if (to.getAttribute(fromAttribute.name) !== fromAttribute.value) {\n to.setAttribute(fromAttribute.name, fromAttribute.value);\n }\n }\n // iterate backwards to avoid skipping over items when a delete occurs\n for (let i = toAttributes.length - 1; 0 <= i; i--) {\n const toAttribute = toAttributes[i];\n if (ignoreAttribute(toAttribute.name, to, 'remove', ctx)) {\n continue;\n }\n if (!from.hasAttribute(toAttribute.name)) {\n to.removeAttribute(toAttribute.name);\n }\n }\n }\n\n // sync text nodes\n if (type === 8 /* comment */ || type === 3 /* text */) {\n if (to.nodeValue !== from.nodeValue) {\n to.nodeValue = from.nodeValue;\n }\n }\n\n if (!ignoreValueOfActiveElement(to, ctx)) {\n // sync input values\n syncInputValue(from, to, ctx);\n }\n }\n\n /**\n * @param from {Element} element to sync the value from\n * @param to {Element} element to sync the value to\n * @param attributeName {String} the attribute name\n * @param ctx the merge context\n */\n function syncBooleanAttribute(from, to, attributeName, ctx) {\n if (from[attributeName] !== to[attributeName]) {\n let ignoreUpdate = ignoreAttribute(attributeName, to, 'update', ctx);\n if (!ignoreUpdate) {\n to[attributeName] = from[attributeName];\n }\n if (from[attributeName]) {\n if (!ignoreUpdate) {\n to.setAttribute(attributeName, from[attributeName]);\n }\n } else {\n if (!ignoreAttribute(attributeName, to, 'remove', ctx)) {\n to.removeAttribute(attributeName);\n }\n }\n }\n }\n\n /**\n * NB: many bothans died to bring us information:\n *\n * https://github.com/patrick-steele-idem/morphdom/blob/master/src/specialElHandlers.js\n * https://github.com/choojs/nanomorph/blob/master/lib/morph.jsL113\n *\n * @param from {Element} the element to sync the input value from\n * @param to {Element} the element to sync the input value to\n * @param ctx the merge context\n */\n function syncInputValue(from, to, ctx) {\n if (from instanceof HTMLInputElement &&\n to instanceof HTMLInputElement &&\n from.type !== 'file') {\n\n let fromValue = from.value;\n let toValue = to.value;\n\n // sync boolean attributes\n syncBooleanAttribute(from, to, 'checked', ctx);\n syncBooleanAttribute(from, to, 'disabled', ctx);\n\n if (!from.hasAttribute('value')) {\n if (!ignoreAttribute('value', to, 'remove', ctx)) {\n to.value = '';\n to.removeAttribute('value');\n }\n } else if (fromValue !== toValue) {\n if (!ignoreAttribute('value', to, 'update', ctx)) {\n to.setAttribute('value', fromValue);\n to.value = fromValue;\n }\n }\n } else if (from instanceof HTMLOptionElement) {\n syncBooleanAttribute(from, to, 'selected', ctx);\n } else if (from instanceof HTMLTextAreaElement && to instanceof HTMLTextAreaElement) {\n let fromValue = from.value;\n let toValue = to.value;\n if (ignoreAttribute('value', to, 'update', ctx)) {\n return;\n }\n if (fromValue !== toValue) {\n to.value = fromValue;\n }\n if (to.firstChild && to.firstChild.nodeValue !== fromValue) {\n to.firstChild.nodeValue = fromValue;\n }\n }\n }\n\n //=============================================================================\n // the HEAD tag can be handled specially, either w/ a 'merge' or 'append' style\n //=============================================================================\n function handleHeadElement(newHeadTag, currentHead, ctx) {\n\n let added = [];\n let removed = [];\n let preserved = [];\n let nodesToAppend = [];\n\n let headMergeStyle = ctx.head.style;\n\n // put all new head elements into a Map, by their outerHTML\n let srcToNewHeadNodes = new Map();\n for (const newHeadChild of newHeadTag.children) {\n srcToNewHeadNodes.set(newHeadChild.outerHTML, newHeadChild);\n }\n\n // for each elt in the current head\n for (const currentHeadElt of currentHead.children) {\n\n // If the current head element is in the map\n let inNewContent = srcToNewHeadNodes.has(currentHeadElt.outerHTML);\n let isReAppended = ctx.head.shouldReAppend(currentHeadElt);\n let isPreserved = ctx.head.shouldPreserve(currentHeadElt);\n if (inNewContent || isPreserved) {\n if (isReAppended) {\n // remove the current version and let the new version replace it and re-execute\n removed.push(currentHeadElt);\n } else {\n // this element already exists and should not be re-appended, so remove it from\n // the new content map, preserving it in the DOM\n srcToNewHeadNodes.delete(currentHeadElt.outerHTML);\n preserved.push(currentHeadElt);\n }\n } else {\n if (headMergeStyle === \"append\") {\n // we are appending and this existing element is not new content\n // so if and only if it is marked for re-append do we do anything\n if (isReAppended) {\n removed.push(currentHeadElt);\n nodesToAppend.push(currentHeadElt);\n }\n } else {\n // if this is a merge, we remove this content since it is not in the new head\n if (ctx.head.shouldRemove(currentHeadElt) !== false) {\n removed.push(currentHeadElt);\n }\n }\n }\n }\n\n // Push the remaining new head elements in the Map into the\n // nodes to append to the head tag\n nodesToAppend.push(...srcToNewHeadNodes.values());\n\n let promises = [];\n for (const newNode of nodesToAppend) {\n let newElt = document.createRange().createContextualFragment(newNode.outerHTML).firstChild;\n if (ctx.callbacks.beforeNodeAdded(newElt) !== false) {\n if (newElt.href || newElt.src) {\n let resolve = null;\n let promise = new Promise(function (_resolve) {\n resolve = _resolve;\n });\n newElt.addEventListener('load', function () {\n resolve();\n });\n promises.push(promise);\n }\n currentHead.appendChild(newElt);\n ctx.callbacks.afterNodeAdded(newElt);\n added.push(newElt);\n }\n }\n\n // remove all removed elements, after we have appended the new elements to avoid\n // additional network requests for things like style sheets\n for (const removedElement of removed) {\n if (ctx.callbacks.beforeNodeRemoved(removedElement) !== false) {\n currentHead.removeChild(removedElement);\n ctx.callbacks.afterNodeRemoved(removedElement);\n }\n }\n\n ctx.head.afterHeadMorphed(currentHead, {added: added, kept: preserved, removed: removed});\n return promises;\n }\n\n function noOp() {\n }\n\n /*\n Deep merges the config object and the Idiomoroph.defaults object to\n produce a final configuration object\n */\n function mergeDefaults(config) {\n let finalConfig = {};\n // copy top level stuff into final config\n Object.assign(finalConfig, defaults);\n Object.assign(finalConfig, config);\n\n // copy callbacks into final config (do this to deep merge the callbacks)\n finalConfig.callbacks = {};\n Object.assign(finalConfig.callbacks, defaults.callbacks);\n Object.assign(finalConfig.callbacks, config.callbacks);\n\n // copy head config into final config (do this to deep merge the head)\n finalConfig.head = {};\n Object.assign(finalConfig.head, defaults.head);\n Object.assign(finalConfig.head, config.head);\n return finalConfig;\n }\n\n function createMorphContext(oldNode, newContent, config) {\n config = mergeDefaults(config);\n return {\n target: oldNode,\n newContent: newContent,\n config: config,\n morphStyle: config.morphStyle,\n ignoreActive: config.ignoreActive,\n ignoreActiveValue: config.ignoreActiveValue,\n idMap: createIdMap(oldNode, newContent),\n deadIds: new Set(),\n callbacks: config.callbacks,\n head: config.head\n }\n }\n\n function isIdSetMatch(node1, node2, ctx) {\n if (node1 == null || node2 == null) {\n return false;\n }\n if (node1.nodeType === node2.nodeType && node1.tagName === node2.tagName) {\n if (node1.id !== \"\" && node1.id === node2.id) {\n return true;\n } else {\n return getIdIntersectionCount(ctx, node1, node2) > 0;\n }\n }\n return false;\n }\n\n function isSoftMatch(node1, node2) {\n if (node1 == null || node2 == null) {\n return false;\n }\n return node1.nodeType === node2.nodeType && node1.tagName === node2.tagName\n }\n\n function removeNodesBetween(startInclusive, endExclusive, ctx) {\n while (startInclusive !== endExclusive) {\n let tempNode = startInclusive;\n startInclusive = startInclusive.nextSibling;\n removeNode(tempNode, ctx);\n }\n removeIdsFromConsideration(ctx, endExclusive);\n return endExclusive.nextSibling;\n }\n\n //=============================================================================\n // Scans forward from the insertionPoint in the old parent looking for a potential id match\n // for the newChild. We stop if we find a potential id match for the new child OR\n // if the number of potential id matches we are discarding is greater than the\n // potential id matches for the new child\n //=============================================================================\n function findIdSetMatch(newContent, oldParent, newChild, insertionPoint, ctx) {\n\n // max id matches we are willing to discard in our search\n let newChildPotentialIdCount = getIdIntersectionCount(ctx, newChild, oldParent);\n\n let potentialMatch = null;\n\n // only search forward if there is a possibility of an id match\n if (newChildPotentialIdCount > 0) {\n let potentialMatch = insertionPoint;\n // if there is a possibility of an id match, scan forward\n // keep track of the potential id match count we are discarding (the\n // newChildPotentialIdCount must be greater than this to make it likely\n // worth it)\n let otherMatchCount = 0;\n while (potentialMatch != null) {\n\n // If we have an id match, return the current potential match\n if (isIdSetMatch(newChild, potentialMatch, ctx)) {\n return potentialMatch;\n }\n\n // computer the other potential matches of this new content\n otherMatchCount += getIdIntersectionCount(ctx, potentialMatch, newContent);\n if (otherMatchCount > newChildPotentialIdCount) {\n // if we have more potential id matches in _other_ content, we\n // do not have a good candidate for an id match, so return null\n return null;\n }\n\n // advanced to the next old content child\n potentialMatch = potentialMatch.nextSibling;\n }\n }\n return potentialMatch;\n }\n\n //=============================================================================\n // Scans forward from the insertionPoint in the old parent looking for a potential soft match\n // for the newChild. We stop if we find a potential soft match for the new child OR\n // if we find a potential id match in the old parents children OR if we find two\n // potential soft matches for the next two pieces of new content\n //=============================================================================\n function findSoftMatch(newContent, oldParent, newChild, insertionPoint, ctx) {\n\n let potentialSoftMatch = insertionPoint;\n let nextSibling = newChild.nextSibling;\n let siblingSoftMatchCount = 0;\n\n while (potentialSoftMatch != null) {\n\n if (getIdIntersectionCount(ctx, potentialSoftMatch, newContent) > 0) {\n // the current potential soft match has a potential id set match with the remaining new\n // content so bail out of looking\n return null;\n }\n\n // if we have a soft match with the current node, return it\n if (isSoftMatch(newChild, potentialSoftMatch)) {\n return potentialSoftMatch;\n }\n\n if (isSoftMatch(nextSibling, potentialSoftMatch)) {\n // the next new node has a soft match with this node, so\n // increment the count of future soft matches\n siblingSoftMatchCount++;\n nextSibling = nextSibling.nextSibling;\n\n // If there are two future soft matches, bail to allow the siblings to soft match\n // so that we don't consume future soft matches for the sake of the current node\n if (siblingSoftMatchCount >= 2) {\n return null;\n }\n }\n\n // advanced to the next old content child\n potentialSoftMatch = potentialSoftMatch.nextSibling;\n }\n\n return potentialSoftMatch;\n }\n\n function parseContent(newContent) {\n let parser = new DOMParser();\n\n // remove svgs to avoid false-positive matches on head, etc.\n let contentWithSvgsRemoved = newContent.replace(/]*>|>)([\\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 const cspNonce = getCspNonce();\n if (cspNonce) {\n element.nonce = 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\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//