pgbus 0.17.1 → 0.17.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (156) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +42 -0
  3. data/README.md +83 -13
  4. data/Rakefile +26 -0
  5. data/app/assets/javascripts/pgbus/stream_source_element.js +34 -2
  6. data/app/assets/javascripts/pgbus/stream_source_element.min.js +6 -0
  7. data/app/assets/javascripts/pgbus/stream_source_element.min.js.map +1 -0
  8. data/app/controllers/concerns/pgbus/job_listing.rb +37 -0
  9. data/app/controllers/concerns/pgbus/process_listing.rb +17 -0
  10. data/app/controllers/pgbus/application_controller.rb +5 -2
  11. data/app/controllers/pgbus/batches_controller.rb +4 -1
  12. data/app/controllers/pgbus/dashboard_controller.rb +20 -6
  13. data/app/controllers/pgbus/dead_letter_controller.rb +27 -3
  14. data/app/controllers/pgbus/events_controller.rb +52 -3
  15. data/app/controllers/pgbus/frontends_controller.rb +25 -11
  16. data/app/controllers/pgbus/insights_controller.rb +19 -1
  17. data/app/controllers/pgbus/jobs_controller.rb +45 -26
  18. data/app/controllers/pgbus/locks_controller.rb +7 -2
  19. data/app/controllers/pgbus/outbox_controller.rb +4 -1
  20. data/app/controllers/pgbus/processes_controller.rb +3 -1
  21. data/app/controllers/pgbus/queues_controller.rb +16 -4
  22. data/app/controllers/pgbus/recurring_tasks_controller.rb +5 -7
  23. data/app/frontend/pgbus/application.min.js +2 -0
  24. data/app/frontend/pgbus/application.min.js.map +1 -0
  25. data/app/frontend/pgbus/modules/charts.js +137 -77
  26. data/app/frontend/pgbus/modules/charts.min.js +2 -0
  27. data/app/frontend/pgbus/modules/charts.min.js.map +1 -0
  28. data/app/frontend/pgbus/style.css +1 -1
  29. data/app/frontend/pgbus/tailwind.css +18 -0
  30. data/app/frontend/pgbus/vendor/turbo.min.js +54 -0
  31. data/app/frontend/pgbus/vendor/turbo.min.js.map +1 -0
  32. data/app/helpers/pgbus/application_helper.rb +155 -113
  33. data/app/helpers/pgbus/button_helper.rb +88 -0
  34. data/app/helpers/pgbus/dashboard_helper.rb +157 -0
  35. data/app/helpers/pgbus/events_helper.rb +40 -0
  36. data/app/helpers/pgbus/insights_helper.rb +39 -0
  37. data/app/helpers/pgbus/processes_helper.rb +79 -0
  38. data/app/views/layouts/pgbus/application.html.erb +0 -1
  39. data/app/views/pgbus/batches/_batches_table.html.erb +16 -13
  40. data/app/views/pgbus/batches/show.html.erb +3 -4
  41. data/app/views/pgbus/dashboard/_processes_table.html.erb +11 -11
  42. data/app/views/pgbus/dashboard/_queue_health.html.erb +42 -51
  43. data/app/views/pgbus/dashboard/_queues_table.html.erb +18 -16
  44. data/app/views/pgbus/dashboard/_recent_failures.html.erb +16 -12
  45. data/app/views/pgbus/dashboard/_stats_cards.html.erb +70 -36
  46. data/app/views/pgbus/dashboard/show.html.erb +1 -1
  47. data/app/views/pgbus/dead_letter/_error.html.erb +13 -0
  48. data/app/views/pgbus/dead_letter/_messages_table.html.erb +37 -96
  49. data/app/views/pgbus/dead_letter/_row.html.erb +75 -0
  50. data/app/views/pgbus/dead_letter/index.html.erb +6 -9
  51. data/app/views/pgbus/dead_letter/show.html.erb +37 -21
  52. data/app/views/pgbus/events/_list.html.erb +55 -0
  53. data/app/views/pgbus/events/_processed_table.html.erb +45 -0
  54. data/app/views/pgbus/events/_replay.html.erb +10 -0
  55. data/app/views/pgbus/events/_row.html.erb +162 -0
  56. data/app/views/pgbus/events/_tabs.html.erb +13 -0
  57. data/app/views/pgbus/events/index.html.erb +27 -48
  58. data/app/views/pgbus/events/show.html.erb +25 -7
  59. data/app/views/pgbus/insights/_chart_card.html.erb +21 -0
  60. data/app/views/pgbus/insights/_latency_table.html.erb +20 -0
  61. data/app/views/pgbus/insights/_status_table.html.erb +19 -0
  62. data/app/views/pgbus/insights/_throughput_table.html.erb +18 -0
  63. data/app/views/pgbus/insights/show.html.erb +83 -100
  64. data/app/views/pgbus/jobs/_list.html.erb +64 -0
  65. data/app/views/pgbus/jobs/_row.html.erb +107 -0
  66. data/app/views/pgbus/jobs/_tabs.html.erb +14 -0
  67. data/app/views/pgbus/jobs/index.html.erb +10 -10
  68. data/app/views/pgbus/jobs/show.html.erb +18 -20
  69. data/app/views/pgbus/locks/_concurrency.html.erb +25 -23
  70. data/app/views/pgbus/locks/_uniqueness.html.erb +20 -22
  71. data/app/views/pgbus/outbox/index.html.erb +30 -27
  72. data/app/views/pgbus/processes/_processes_table.html.erb +6 -25
  73. data/app/views/pgbus/processes/_row.html.erb +48 -0
  74. data/app/views/pgbus/processes/_status.html.erb +4 -0
  75. data/app/views/pgbus/queues/_queues_list.html.erb +28 -32
  76. data/app/views/pgbus/queues/show.html.erb +69 -118
  77. data/app/views/pgbus/recurring_tasks/_tasks_table.html.erb +75 -76
  78. data/app/views/pgbus/recurring_tasks/index.html.erb +1 -1
  79. data/app/views/pgbus/recurring_tasks/show.html.erb +45 -51
  80. data/app/views/pgbus/shared/_empty_row.html.erb +2 -0
  81. data/app/views/pgbus/shared/_pager.html.erb +34 -0
  82. data/config/i18n-tasks.yml +11 -2
  83. data/config/locales/da.yml +405 -113
  84. data/config/locales/de.yml +405 -113
  85. data/config/locales/en.yml +405 -113
  86. data/config/locales/es.yml +404 -112
  87. data/config/locales/fi.yml +404 -112
  88. data/config/locales/fr.yml +406 -114
  89. data/config/locales/it.yml +405 -113
  90. data/config/locales/ja.yml +405 -113
  91. data/config/locales/nb.yml +405 -113
  92. data/config/locales/nl.yml +405 -113
  93. data/config/locales/pt.yml +406 -114
  94. data/config/locales/sv.yml +404 -112
  95. data/config/routes.rb +1 -1
  96. data/lib/generators/pgbus/add_presence_generator.rb +2 -1
  97. data/lib/generators/pgbus/add_presence_seats_generator.rb +45 -0
  98. data/lib/generators/pgbus/templates/add_presence.rb.erb +32 -7
  99. data/lib/generators/pgbus/templates/add_presence_seats.rb.erb +38 -0
  100. data/lib/generators/pgbus/templates/initializer.rb.erb +4 -0
  101. data/lib/pgbus/active_job/executor.rb +16 -6
  102. data/lib/pgbus/cli/dlq.rb +32 -5
  103. data/lib/pgbus/client.rb +4 -2
  104. data/lib/pgbus/configuration/presence_settings.rb +103 -0
  105. data/lib/pgbus/configuration.rb +51 -2
  106. data/lib/pgbus/dead_letter_header.rb +129 -0
  107. data/lib/pgbus/doctor.rb +8 -4
  108. data/lib/pgbus/engine.rb +13 -7
  109. data/lib/pgbus/event_bus/handler.rb +18 -11
  110. data/lib/pgbus/event_bus/registry.rb +6 -0
  111. data/lib/pgbus/failed_event_recorder.rb +34 -0
  112. data/lib/pgbus/generators/migration_detector.rb +9 -1
  113. data/lib/pgbus/instrumentation.rb +2 -1
  114. data/lib/pgbus/mcp/base_tool.rb +25 -0
  115. data/lib/pgbus/mcp/tools/concurrency_tool.rb +23 -4
  116. data/lib/pgbus/mcp/tools/dlq_detail_tool.rb +4 -2
  117. data/lib/pgbus/mcp/tools/dlq_tool.rb +10 -4
  118. data/lib/pgbus/mcp/tools/locks_tool.rb +23 -5
  119. data/lib/pgbus/mcp/tools/recurring_tool.rb +33 -4
  120. data/lib/pgbus/outbox/poller.rb +1 -1
  121. data/lib/pgbus/process/consumer.rb +53 -3
  122. data/lib/pgbus/process/dispatcher.rb +1 -1
  123. data/lib/pgbus/process/supervisor.rb +32 -11
  124. data/lib/pgbus/process/worker.rb +45 -8
  125. data/lib/pgbus/recurring/scheduler.rb +2 -1
  126. data/lib/pgbus/streams/presence.rb +317 -81
  127. data/lib/pgbus/version.rb +1 -1
  128. data/lib/pgbus/web/data_source/dashboard_signals.rb +170 -0
  129. data/lib/pgbus/web/data_source/dead_letter.rb +142 -0
  130. data/lib/pgbus/web/data_source/event_list.rb +161 -0
  131. data/lib/pgbus/web/data_source/job_list.rb +323 -0
  132. data/lib/pgbus/web/data_source/list_counts.rb +80 -0
  133. data/lib/pgbus/web/data_source/process_list.rb +69 -0
  134. data/lib/pgbus/web/data_source/queue_summary.rb +122 -0
  135. data/lib/pgbus/web/data_source.rb +132 -254
  136. data/lib/pgbus/web/dead_letter_reason.rb +81 -0
  137. data/lib/pgbus/web/event_state.rb +71 -0
  138. data/lib/pgbus/web/health_app.rb +7 -3
  139. data/lib/pgbus/web/health_verdict.rb +78 -0
  140. data/lib/pgbus/web/insights_charts.rb +84 -0
  141. data/lib/pgbus/web/job_state.rb +111 -0
  142. data/lib/pgbus/web/process_activity.rb +97 -0
  143. data/lib/pgbus/web/process_state.rb +187 -0
  144. data/lib/pgbus/web/queue_summary.rb +104 -0
  145. data/lib/pgbus/web/stream_app.rb +18 -6
  146. data/lib/pgbus/web/streamer/connection.rb +7 -1
  147. data/lib/pgbus/web/streamer/falcon_connection.rb +7 -1
  148. data/lib/pgbus/web/streamer/heartbeat.rb +9 -3
  149. data/lib/pgbus/web/streamer/instance.rb +2 -1
  150. data/lib/pgbus/web/streamer/presence_tracker.rb +155 -0
  151. data/lib/pgbus/web/streamer/stream_event_dispatcher.rb +8 -37
  152. data/lib/pgbus/web/time_format.rb +128 -0
  153. metadata +55 -4
  154. data/app/views/pgbus/events/_pending_table.html.erb +0 -169
  155. data/app/views/pgbus/jobs/_enqueued_table.html.erb +0 -118
  156. data/app/views/pgbus/jobs/_failed_table.html.erb +0 -76
@@ -0,0 +1,54 @@
1
+ /*!
2
+ Turbo 8.0.12
3
+ Copyright © 2024 37signals LLC
4
+ */
5
+ /**
6
+ * The MIT License (MIT)
7
+ *
8
+ * Copyright (c) 2019 Javan Makhmali
9
+ *
10
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
11
+ * of this software and associated documentation files (the "Software"), to deal
12
+ * in the Software without restriction, including without limitation the rights
13
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14
+ * copies of the Software, and to permit persons to whom the Software is
15
+ * furnished to do so, subject to the following conditions:
16
+ *
17
+ * The above copyright notice and this permission notice shall be included in
18
+ * all copies or substantial portions of the Software.
19
+ *
20
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
26
+ * THE SOFTWARE.
27
+ */
28
+ (function(e){if(typeof e.requestSubmit=="function")return;e.requestSubmit=function(r){if(r)t(r,this),r.click();else r=document.createElement("input"),r.type="submit",r.hidden=!0,this.appendChild(r),r.click(),this.removeChild(r)};function t(r,a){r instanceof HTMLElement||s(TypeError,"parameter 1 is not of type 'HTMLElement'"),r.type=="submit"||s(TypeError,"The specified element is not a submit button"),r.form==a||s(DOMException,"The specified element is not owned by this form element","NotFoundError")}function s(r,a,u){throw new r("Failed to execute 'requestSubmit' on 'HTMLFormElement': "+a+".",u)}})(HTMLFormElement.prototype);var We=new WeakMap;function Xt(e){let t=e instanceof Element?e:e instanceof Node?e.parentElement:null,s=t?t.closest("input, button"):null;return s?.type=="submit"?s:null}function Yt(e){let t=Xt(e.target);if(t&&t.form)We.set(t.form,t)}(function(){if("submitter"in Event.prototype)return;let e=window.Event.prototype;if("SubmitEvent"in window){let t=window.SubmitEvent.prototype;if(/Apple Computer/.test(navigator.vendor)&&!("submitter"in t))e=t;else return}addEventListener("click",Yt,!0),Object.defineProperty(e,"submitter",{get(){if(this.type=="submit"&&this.target instanceof HTMLFormElement)return We.get(this.target)}})})();var _={eager:"eager",lazy:"lazy"};class L extends HTMLElement{static delegateConstructor=void 0;loaded=Promise.resolve();static get observedAttributes(){return["disabled","loading","src"]}constructor(){super();this.delegate=new L.delegateConstructor(this)}connectedCallback(){this.delegate.connect()}disconnectedCallback(){this.delegate.disconnect()}reload(){return this.delegate.sourceURLReloaded()}attributeChangedCallback(e){if(e=="loading")this.delegate.loadingStyleChanged();else if(e=="src")this.delegate.sourceURLChanged();else if(e=="disabled")this.delegate.disabledChanged()}get src(){return this.getAttribute("src")}set src(e){if(e)this.setAttribute("src",e);else this.removeAttribute("src")}get refresh(){return this.getAttribute("refresh")}set refresh(e){if(e)this.setAttribute("refresh",e);else this.removeAttribute("refresh")}get shouldReloadWithMorph(){return this.src&&this.refresh==="morph"}get loading(){return Jt(this.getAttribute("loading")||"")}set loading(e){if(e)this.setAttribute("loading",e);else this.removeAttribute("loading")}get disabled(){return this.hasAttribute("disabled")}set disabled(e){if(e)this.setAttribute("disabled","");else this.removeAttribute("disabled")}get autoscroll(){return this.hasAttribute("autoscroll")}set autoscroll(e){if(e)this.setAttribute("autoscroll","");else this.removeAttribute("autoscroll")}get complete(){return!this.delegate.isLoading}get isActive(){return this.ownerDocument===document&&!this.isPreview}get isPreview(){return this.ownerDocument?.documentElement?.hasAttribute("data-turbo-preview")}}function Jt(e){switch(e.toLowerCase()){case"lazy":return _.lazy;default:return _.eager}}var Qt={enabled:!0,progressBarDelay:500,unvisitableExtensions:new Set([".7z",".aac",".apk",".avi",".bmp",".bz2",".css",".csv",".deb",".dmg",".doc",".docx",".exe",".gif",".gz",".heic",".heif",".ico",".iso",".jpeg",".jpg",".js",".json",".m4a",".mkv",".mov",".mp3",".mp4",".mpeg",".mpg",".msi",".ogg",".ogv",".pdf",".pkg",".png",".ppt",".pptx",".rar",".rtf",".svg",".tar",".tif",".tiff",".txt",".wav",".webm",".webp",".wma",".wmv",".xls",".xlsx",".xml",".zip"])};function Q(e){if(e.getAttribute("data-turbo-eval")=="false")return e;else{let t=document.createElement("script"),s=ze();if(s)t.nonce=s;return t.textContent=e.textContent,t.async=!1,Gt(t,e),t}}function Gt(e,t){for(let{name:s,value:r}of t.attributes)e.setAttribute(s,r)}function Zt(e){let t=document.createElement("template");return t.innerHTML=e,t.content}function p(e,{target:t,cancelable:s,detail:r}={}){let a=new CustomEvent(e,{cancelable:s,bubbles:!0,composed:!0,detail:r});if(t&&t.isConnected)t.dispatchEvent(a);else document.documentElement.dispatchEvent(a);return a}function Fe(e){e.preventDefault(),e.stopImmediatePropagation()}function J(){if(document.visibilityState==="hidden")return Ue();else return _e()}function _e(){return new Promise((e)=>requestAnimationFrame(()=>e()))}function Ue(){return new Promise((e)=>setTimeout(()=>e(),0))}function es(){return Promise.resolve()}function xe(e=""){return new DOMParser().parseFromString(e,"text/html")}function je(e,...t){let s=ts(e,t).replace(/^\n/,"").split(`
29
+ `),r=s[0].match(/^\s+/),a=r?r[0].length:0;return s.map((u)=>u.slice(a)).join(`
30
+ `)}function ts(e,t){return e.reduce((s,r,a)=>{let u=t[a]==null?"":t[a];return s+r+u},"")}function I(){return Array.from({length:36}).map((e,t)=>{if(t==8||t==13||t==18||t==23)return"-";else if(t==14)return"4";else if(t==19)return(Math.floor(Math.random()*4)+8).toString(16);else return Math.floor(Math.random()*15).toString(16)}).join("")}function re(e,...t){for(let s of t.map((r)=>r?.getAttribute(e)))if(typeof s=="string")return s;return null}function ss(e,...t){return t.some((s)=>s&&s.hasAttribute(e))}function ie(...e){for(let t of e){if(t.localName=="turbo-frame")t.setAttribute("busy","");t.setAttribute("aria-busy","true")}}function ne(...e){for(let t of e){if(t.localName=="turbo-frame")t.removeAttribute("busy");t.removeAttribute("aria-busy")}}function rs(e,t=2000){return new Promise((s)=>{let r=()=>{e.removeEventListener("error",r),e.removeEventListener("load",r),s()};e.addEventListener("load",r,{once:!0}),e.addEventListener("error",r,{once:!0}),setTimeout(s,t)})}function $e(e){switch(e){case"replace":return history.replaceState;case"advance":case"restore":return history.pushState}}function is(e){return e=="advance"||e=="replace"||e=="restore"}function D(...e){let t=re("data-turbo-action",...e);return is(t)?t:null}function be(e){return document.querySelector(`meta[name="${e}"]`)}function oe(e){let t=be(e);return t&&t.content}function ze(){let e=be("csp-nonce");if(e){let{nonce:t,content:s}=e;return t==""?s:t}}function ns(e,t){let s=be(e);if(!s)s=document.createElement("meta"),s.setAttribute("name",e),document.head.appendChild(s);return s.setAttribute("content",t),s}function x(e,t){if(e instanceof Element)return e.closest(t)||x(e.assignedSlot||e.getRootNode()?.host,t)}function ve(e){return!!e&&e.closest("[inert], :disabled, [hidden], details:not([open]), dialog:not([open])")==null&&typeof e.focus=="function"}function Ke(e){return Array.from(e.querySelectorAll("[autofocus]")).find(ve)}async function os(e,t){let s=t();e(),await _e();let r=t();return[s,r]}function Xe(e){if(e==="_blank")return!1;else if(e){for(let t of document.getElementsByName(e))if(t instanceof HTMLIFrameElement)return!1;return!0}else return!0}function Ye(e){return x(e,"a[href]:not([target^=_]):not([download])")}function Je(e){return w(e.getAttribute("href")||"")}function as(e,t){let s=null;return(...r)=>{let a=()=>e.apply(this,r);clearTimeout(s),s=setTimeout(a,t)}}var ls={"aria-disabled":{beforeSubmit:(e)=>{e.setAttribute("aria-disabled","true"),e.addEventListener("click",Fe)},afterSubmit:(e)=>{e.removeAttribute("aria-disabled"),e.removeEventListener("click",Fe)}},disabled:{beforeSubmit:(e)=>e.disabled=!0,afterSubmit:(e)=>e.disabled=!1}};class Qe{#e=null;constructor(e){Object.assign(this,e)}get submitter(){return this.#e}set submitter(e){this.#e=ls[e]||e}}var cs=new Qe({mode:"on",submitter:"disabled"}),S={drive:Qt,forms:cs};function w(e){return new URL(e.toString(),document.baseURI)}function V(e){let t;if(e.hash)return e.hash.slice(1);else if(t=e.href.match(/#(.*)$/))return t[1]}function Se(e,t){let s=t?.getAttribute("formaction")||e.getAttribute("action")||e.action;return w(s)}function hs(e){return(fs(e).match(/\.[^.]*$/)||[])[0]||""}function us(e,t){let s=ps(t);return e.href===w(s).href||e.href.startsWith(s)}function k(e,t){return us(e,t)&&!S.drive.unvisitableExtensions.has(hs(e))}function ge(e){let t=V(e);return t!=null?e.href.slice(0,-(t.length+1)):e.href}function te(e){return ge(e)}function ds(e,t){return w(e).href==w(t).href}function ms(e){return e.pathname.split("/").slice(1)}function fs(e){return ms(e).slice(-1)[0]}function ps(e){return gs(e.origin+e.pathname)}function gs(e){return e.endsWith("/")?e:e+"/"}class ae{constructor(e){this.response=e}get succeeded(){return this.response.ok}get failed(){return!this.succeeded}get clientError(){return this.statusCode>=400&&this.statusCode<=499}get serverError(){return this.statusCode>=500&&this.statusCode<=599}get redirected(){return this.response.redirected}get location(){return w(this.response.url)}get isHTML(){return this.contentType&&this.contentType.match(/^(?:text\/([^\s;,]+\b)?html|application\/xhtml\+xml)\b/)}get statusCode(){return this.response.status}get contentType(){return this.header("Content-Type")}get responseText(){return this.response.clone().text()}get responseHTML(){if(this.isHTML)return this.response.clone().text();else return Promise.resolve(void 0)}header(e){return this.response.headers.get(e)}}class Ge extends Set{constructor(e){super();this.maxSize=e}add(e){if(this.size>=this.maxSize){let s=this.values().next().value;this.delete(s)}super.add(e)}}var Ze=new Ge(20),bs=window.fetch;function et(e,t={}){let s=new Headers(t.headers||{}),r=I();return Ze.add(r),s.append("X-Turbo-Request-Id",r),bs(e,{...t,headers:s})}function we(e){switch(e.toLowerCase()){case"get":return E.get;case"post":return E.post;case"put":return E.put;case"patch":return E.patch;case"delete":return E.delete}}var E={get:"get",post:"post",put:"put",patch:"patch",delete:"delete"};function vs(e){switch(e.toLowerCase()){case O.multipart:return O.multipart;case O.plain:return O.plain;default:return O.urlEncoded}}var O={urlEncoded:"application/x-www-form-urlencoded",multipart:"multipart/form-data",plain:"text/plain"};class z{abortController=new AbortController;#e=(e)=>{};constructor(e,t,s,r=new URLSearchParams,a=null,u=O.urlEncoded){let[f,m]=He(w(s),t,r,u);this.delegate=e,this.url=f,this.target=a,this.fetchOptions={credentials:"same-origin",redirect:"follow",method:t.toUpperCase(),headers:{...this.defaultHeaders},body:m,signal:this.abortSignal,referrer:this.delegate.referrer?.href},this.enctype=u}get method(){return this.fetchOptions.method}set method(e){let t=this.isSafe?this.url.searchParams:this.fetchOptions.body||new FormData,s=we(e)||E.get;this.url.search="";let[r,a]=He(this.url,s,t,this.enctype);this.url=r,this.fetchOptions.body=a,this.fetchOptions.method=s.toUpperCase()}get headers(){return this.fetchOptions.headers}set headers(e){this.fetchOptions.headers=e}get body(){if(this.isSafe)return this.url.searchParams;else return this.fetchOptions.body}set body(e){this.fetchOptions.body=e}get location(){return this.url}get params(){return this.url.searchParams}get entries(){return this.body?Array.from(this.body.entries()):[]}cancel(){this.abortController.abort()}async perform(){let{fetchOptions:e}=this;this.delegate.prepareRequest(this);let t=await this.#t(e);try{if(this.delegate.requestStarted(this),t.detail.fetchRequest)this.response=t.detail.fetchRequest.response;else this.response=et(this.url.href,e);let s=await this.response;return await this.receive(s)}catch(s){if(s.name!=="AbortError"){if(this.#s(s))this.delegate.requestErrored(this,s);throw s}}finally{this.delegate.requestFinished(this)}}async receive(e){let t=new ae(e);if(p("turbo:before-fetch-response",{cancelable:!0,detail:{fetchResponse:t},target:this.target}).defaultPrevented)this.delegate.requestPreventedHandlingResponse(this,t);else if(t.succeeded)this.delegate.requestSucceededWithResponse(this,t);else this.delegate.requestFailedWithResponse(this,t);return t}get defaultHeaders(){return{Accept:"text/html, application/xhtml+xml"}}get isSafe(){return ye(this.method)}get abortSignal(){return this.abortController.signal}acceptResponseType(e){this.headers.Accept=[e,this.headers.Accept].join(", ")}async#t(e){let t=new Promise((r)=>this.#e=r),s=p("turbo:before-fetch-request",{cancelable:!0,detail:{fetchOptions:e,url:this.url,resume:this.#e},target:this.target});if(this.url=s.detail.url,s.defaultPrevented)await t;return s}#s(e){return!p("turbo:fetch-request-error",{target:this.target,cancelable:!0,detail:{request:this,error:e}}).defaultPrevented}}function ye(e){return we(e)==E.get}function He(e,t,s,r){let a=Array.from(s).length>0?new URLSearchParams(tt(s)):e.searchParams;if(ye(t))return[Ss(e,a),null];else if(r==O.urlEncoded)return[e,a];else return[e,s]}function tt(e){let t=[];for(let[s,r]of e)if(r instanceof File)continue;else t.push([s,r]);return t}function Ss(e,t){let s=new URLSearchParams(tt(t));return e.search=s.toString(),e}class st{started=!1;constructor(e,t){this.delegate=e,this.element=t,this.intersectionObserver=new IntersectionObserver(this.intersect)}start(){if(!this.started)this.started=!0,this.intersectionObserver.observe(this.element)}stop(){if(this.started)this.started=!1,this.intersectionObserver.unobserve(this.element)}intersect=(e)=>{if(e.slice(-1)[0]?.isIntersecting)this.delegate.elementAppearedInViewport(this.element)}}class N{static contentType="text/vnd.turbo-stream.html";static wrap(e){if(typeof e=="string")return new this(Zt(e));else return e}constructor(e){this.fragment=ws(e)}}function ws(e){for(let t of e.querySelectorAll("turbo-stream")){let s=document.importNode(t,!0);for(let r of s.templateElement.content.querySelectorAll("script"))r.replaceWith(Q(r));t.replaceWith(s)}return e}var ys=100;class rt{#e=null;#t=null;get(e){if(this.#t&&this.#t.url===e&&this.#t.expire>Date.now())return this.#t.request}setLater(e,t,s){this.clear(),this.#e=setTimeout(()=>{t.perform(),this.set(e,t,s),this.#e=null},ys)}set(e,t,s){this.#t={url:e,request:t,expire:new Date(new Date().getTime()+s)}}clear(){if(this.#e)clearTimeout(this.#e);this.#t=null}}var Es=1e4,U=new rt,W={initialized:"initialized",requesting:"requesting",waiting:"waiting",receiving:"receiving",stopping:"stopping",stopped:"stopped"};class le{state=W.initialized;static confirmMethod(e){return Promise.resolve(confirm(e))}constructor(e,t,s,r=!1){let a=Cs(t,s),u=Ps(Rs(t,s),a),f=As(t,s),m=Ms(t,s);this.delegate=e,this.formElement=t,this.submitter=s,this.fetchRequest=new z(this,a,u,f,t,m),this.mustRedirect=r}get method(){return this.fetchRequest.method}set method(e){this.fetchRequest.method=e}get action(){return this.fetchRequest.url.toString()}set action(e){this.fetchRequest.url=w(e)}get body(){return this.fetchRequest.body}get enctype(){return this.fetchRequest.enctype}get isSafe(){return this.fetchRequest.isSafe}get location(){return this.fetchRequest.url}async start(){let{initialized:e,requesting:t}=W,s=re("data-turbo-confirm",this.submitter,this.formElement);if(typeof s==="string"){if(!await(typeof S.forms.confirm==="function"?S.forms.confirm:le.confirmMethod)(s,this.formElement,this.submitter))return}if(this.state==e)return this.state=t,this.fetchRequest.perform()}stop(){let{stopping:e,stopped:t}=W;if(this.state!=e&&this.state!=t)return this.state=e,this.fetchRequest.cancel(),!0}prepareRequest(e){if(!e.isSafe){let t=Ts(oe("csrf-param"))||oe("csrf-token");if(t)e.headers["X-CSRF-Token"]=t}if(this.requestAcceptsTurboStreamResponse(e))e.acceptResponseType(N.contentType)}requestStarted(e){if(this.state=W.waiting,this.submitter)S.forms.submitter.beforeSubmit(this.submitter);this.setSubmitsWith(),ie(this.formElement),p("turbo:submit-start",{target:this.formElement,detail:{formSubmission:this}}),this.delegate.formSubmissionStarted(this)}requestPreventedHandlingResponse(e,t){U.clear(),this.result={success:t.succeeded,fetchResponse:t}}requestSucceededWithResponse(e,t){if(t.clientError||t.serverError){this.delegate.formSubmissionFailedWithResponse(this,t);return}if(U.clear(),this.requestMustRedirect(e)&&Ls(t)){let s=Error("Form responses must redirect to another location");this.delegate.formSubmissionErrored(this,s)}else this.state=W.receiving,this.result={success:!0,fetchResponse:t},this.delegate.formSubmissionSucceededWithResponse(this,t)}requestFailedWithResponse(e,t){this.result={success:!1,fetchResponse:t},this.delegate.formSubmissionFailedWithResponse(this,t)}requestErrored(e,t){this.result={success:!1,error:t},this.delegate.formSubmissionErrored(this,t)}requestFinished(e){if(this.state=W.stopped,this.submitter)S.forms.submitter.afterSubmit(this.submitter);this.resetSubmitterText(),ne(this.formElement),p("turbo:submit-end",{target:this.formElement,detail:{formSubmission:this,...this.result}}),this.delegate.formSubmissionFinished(this)}setSubmitsWith(){if(!this.submitter||!this.submitsWith)return;if(this.submitter.matches("button"))this.originalSubmitText=this.submitter.innerHTML,this.submitter.innerHTML=this.submitsWith;else if(this.submitter.matches("input")){let e=this.submitter;this.originalSubmitText=e.value,e.value=this.submitsWith}}resetSubmitterText(){if(!this.submitter||!this.originalSubmitText)return;if(this.submitter.matches("button"))this.submitter.innerHTML=this.originalSubmitText;else if(this.submitter.matches("input")){let e=this.submitter;e.value=this.originalSubmitText}}requestMustRedirect(e){return!e.isSafe&&this.mustRedirect}requestAcceptsTurboStreamResponse(e){return!e.isSafe||ss("data-turbo-stream",this.submitter,this.formElement)}get submitsWith(){return this.submitter?.getAttribute("data-turbo-submits-with")}}function As(e,t){let s=new FormData(e),r=t?.getAttribute("name"),a=t?.getAttribute("value");if(r)s.append(r,a||"");return s}function Ts(e){if(e!=null){let s=(document.cookie?document.cookie.split("; "):[]).find((r)=>r.startsWith(e));if(s){let r=s.split("=").slice(1).join("=");return r?decodeURIComponent(r):void 0}}}function Ls(e){return e.statusCode==200&&!e.redirected}function Rs(e,t){let s=typeof e.action==="string"?e.action:null;if(t?.hasAttribute("formaction"))return t.getAttribute("formaction")||"";else return e.getAttribute("action")||s||""}function Ps(e,t){let s=w(e);if(ye(t))s.search="";return s}function Cs(e,t){let s=t?.getAttribute("formmethod")||e.getAttribute("method")||"";return we(s.toLowerCase())||E.get}function Ms(e,t){return vs(t?.getAttribute("formenctype")||e.enctype)}class G{constructor(e){this.element=e}get activeElement(){return this.element.ownerDocument.activeElement}get children(){return[...this.element.children]}hasAnchor(e){return this.getElementForAnchor(e)!=null}getElementForAnchor(e){return e?this.element.querySelector(`[id='${e}'], a[name='${e}']`):null}get isConnected(){return this.element.isConnected}get firstAutofocusableElement(){return Ke(this.element)}get permanentElements(){return nt(this.element)}getPermanentElementById(e){return it(this.element,e)}getPermanentElementMapForSnapshot(e){let t={};for(let s of this.permanentElements){let{id:r}=s,a=e.getPermanentElementById(r);if(a)t[r]=[s,a]}return t}}function it(e,t){return e.querySelector(`#${t}[data-turbo-permanent]`)}function nt(e){return e.querySelectorAll("[id][data-turbo-permanent]")}class ce{started=!1;constructor(e,t){this.delegate=e,this.eventTarget=t}start(){if(!this.started)this.eventTarget.addEventListener("submit",this.submitCaptured,!0),this.started=!0}stop(){if(this.started)this.eventTarget.removeEventListener("submit",this.submitCaptured,!0),this.started=!1}submitCaptured=()=>{this.eventTarget.removeEventListener("submit",this.submitBubbled,!1),this.eventTarget.addEventListener("submit",this.submitBubbled,!1)};submitBubbled=(e)=>{if(!e.defaultPrevented){let t=e.target instanceof HTMLFormElement?e.target:void 0,s=e.submitter||void 0;if(t&&ks(t,s)&&Is(t,s)&&this.delegate.willSubmitForm(t,s))e.preventDefault(),e.stopImmediatePropagation(),this.delegate.formSubmitted(t,s)}}}function ks(e,t){return(t?.getAttribute("formmethod")||e.getAttribute("method"))!="dialog"}function Is(e,t){let s=t?.getAttribute("formtarget")||e.getAttribute("target");return Xe(s)}class Ee{#e=(e)=>{};#t=(e)=>{};constructor(e,t){this.delegate=e,this.element=t}scrollToAnchor(e){let t=this.snapshot.getElementForAnchor(e);if(t)this.scrollToElement(t),this.focusElement(t);else this.scrollToPosition({x:0,y:0})}scrollToAnchorFromLocation(e){this.scrollToAnchor(V(e))}scrollToElement(e){e.scrollIntoView()}focusElement(e){if(e instanceof HTMLElement)if(e.hasAttribute("tabindex"))e.focus();else e.setAttribute("tabindex","-1"),e.focus(),e.removeAttribute("tabindex")}scrollToPosition({x:e,y:t}){this.scrollRoot.scrollTo(e,t)}scrollToTop(){this.scrollToPosition({x:0,y:0})}get scrollRoot(){return window}async render(e){let{isPreview:t,shouldRender:s,willRender:r,newSnapshot:a}=e,u=r;if(s)try{this.renderPromise=new Promise((y)=>this.#e=y),this.renderer=e,await this.prepareToRenderSnapshot(e);let f=new Promise((y)=>this.#t=y),m={resume:this.#t,render:this.renderer.renderElement,renderMethod:this.renderer.renderMethod};if(!this.delegate.allowsImmediateRender(a,m))await f;await this.renderSnapshot(e),this.delegate.viewRenderedSnapshot(a,t,this.renderer.renderMethod),this.delegate.preloadOnLoadLinksForView(this.element),this.finishRenderingSnapshot(e)}finally{delete this.renderer,this.#e(void 0),delete this.renderPromise}else if(u)this.invalidate(e.reloadReason)}invalidate(e){this.delegate.viewInvalidated(e)}async prepareToRenderSnapshot(e){this.markAsPreview(e.isPreview),await e.prepareToRender()}markAsPreview(e){if(e)this.element.setAttribute("data-turbo-preview","");else this.element.removeAttribute("data-turbo-preview")}markVisitDirection(e){this.element.setAttribute("data-turbo-visit-direction",e)}unmarkVisitDirection(){this.element.removeAttribute("data-turbo-visit-direction")}async renderSnapshot(e){await e.render()}finishRenderingSnapshot(e){e.finishRendering()}}class ot extends Ee{missing(){this.element.innerHTML='<strong class="turbo-frame-error">Content missing</strong>'}get snapshot(){return new G(this.element)}}class Ae{constructor(e,t){this.delegate=e,this.element=t}start(){this.element.addEventListener("click",this.clickBubbled),document.addEventListener("turbo:click",this.linkClicked),document.addEventListener("turbo:before-visit",this.willVisit)}stop(){this.element.removeEventListener("click",this.clickBubbled),document.removeEventListener("turbo:click",this.linkClicked),document.removeEventListener("turbo:before-visit",this.willVisit)}clickBubbled=(e)=>{if(this.clickEventIsSignificant(e))this.clickEvent=e;else delete this.clickEvent};linkClicked=(e)=>{if(this.clickEvent&&this.clickEventIsSignificant(e)){if(this.delegate.shouldInterceptLinkClick(e.target,e.detail.url,e.detail.originalEvent))this.clickEvent.preventDefault(),e.preventDefault(),this.delegate.linkClickIntercepted(e.target,e.detail.url,e.detail.originalEvent)}delete this.clickEvent};willVisit=(e)=>{delete this.clickEvent};clickEventIsSignificant(e){let t=e.composed?e.target?.parentElement:e.target,s=Ye(t)||t;return s instanceof Element&&s.closest("turbo-frame, html")==this.element}}class Te{started=!1;constructor(e,t){this.delegate=e,this.eventTarget=t}start(){if(!this.started)this.eventTarget.addEventListener("click",this.clickCaptured,!0),this.started=!0}stop(){if(this.started)this.eventTarget.removeEventListener("click",this.clickCaptured,!0),this.started=!1}clickCaptured=()=>{this.eventTarget.removeEventListener("click",this.clickBubbled,!1),this.eventTarget.addEventListener("click",this.clickBubbled,!1)};clickBubbled=(e)=>{if(e instanceof MouseEvent&&this.clickEventIsSignificant(e)){let t=e.composedPath&&e.composedPath()[0]||e.target,s=Ye(t);if(s&&Xe(s.target)){let r=Je(s);if(this.delegate.willFollowLinkToLocation(s,r,e))e.preventDefault(),this.delegate.followedLinkToLocation(s,r)}}};clickEventIsSignificant(e){return!(e.target&&e.target.isContentEditable||e.defaultPrevented||e.which>1||e.altKey||e.ctrlKey||e.metaKey||e.shiftKey)}}class Le{constructor(e,t){this.delegate=e,this.linkInterceptor=new Te(this,t)}start(){this.linkInterceptor.start()}stop(){this.linkInterceptor.stop()}canPrefetchRequestToLocation(e,t){return!1}prefetchAndCacheRequestToLocation(e,t){return}willFollowLinkToLocation(e,t,s){return this.delegate.willSubmitFormLinkToLocation(e,t,s)&&(e.hasAttribute("data-turbo-method")||e.hasAttribute("data-turbo-stream"))}followedLinkToLocation(e,t){let s=document.createElement("form"),r="hidden";for(let[K,q]of t.searchParams)s.append(Object.assign(document.createElement("input"),{type:"hidden",name:K,value:q}));let a=Object.assign(t,{search:""});s.setAttribute("data-turbo","true"),s.setAttribute("action",a.href),s.setAttribute("hidden","");let u=e.getAttribute("data-turbo-method");if(u)s.setAttribute("method",u);let f=e.getAttribute("data-turbo-frame");if(f)s.setAttribute("data-turbo-frame",f);let m=D(e);if(m)s.setAttribute("data-turbo-action",m);let C=e.getAttribute("data-turbo-confirm");if(C)s.setAttribute("data-turbo-confirm",C);if(e.hasAttribute("data-turbo-stream"))s.setAttribute("data-turbo-stream","");this.delegate.submittedFormLinkToLocation(e,t,s),document.body.appendChild(s),s.addEventListener("turbo:submit-end",()=>s.remove(),{once:!0}),requestAnimationFrame(()=>s.requestSubmit())}}class Re{static async preservingPermanentElements(e,t,s){let r=new this(e,t);r.enter(),await s(),r.leave()}constructor(e,t){this.delegate=e,this.permanentElementMap=t}enter(){for(let e in this.permanentElementMap){let[t,s]=this.permanentElementMap[e];this.delegate.enteringBardo(t,s),this.replaceNewPermanentElementWithPlaceholder(s)}}leave(){for(let e in this.permanentElementMap){let[t]=this.permanentElementMap[e];this.replaceCurrentPermanentElementWithClone(t),this.replacePlaceholderWithPermanentElement(t),this.delegate.leavingBardo(t)}}replaceNewPermanentElementWithPlaceholder(e){let t=qs(e);e.replaceWith(t)}replaceCurrentPermanentElementWithClone(e){let t=e.cloneNode(!0);e.replaceWith(t)}replacePlaceholderWithPermanentElement(e){this.getPlaceholderById(e.id)?.replaceWith(e)}getPlaceholderById(e){return this.placeholders.find((t)=>t.content==e)}get placeholders(){return[...document.querySelectorAll("meta[name=turbo-permanent-placeholder][content]")]}}function qs(e){let t=document.createElement("meta");return t.setAttribute("name","turbo-permanent-placeholder"),t.setAttribute("content",e.id),t}class he{#e=null;static renderElement(e,t){}constructor(e,t,s,r=!0){this.currentSnapshot=e,this.newSnapshot=t,this.isPreview=s,this.willRender=r,this.renderElement=this.constructor.renderElement,this.promise=new Promise((a,u)=>this.resolvingFunctions={resolve:a,reject:u})}get shouldRender(){return!0}get shouldAutofocus(){return!0}get reloadReason(){return}prepareToRender(){return}render(){}finishRendering(){if(this.resolvingFunctions)this.resolvingFunctions.resolve(),delete this.resolvingFunctions}async preservingPermanentElements(e){await Re.preservingPermanentElements(this,this.permanentElementMap,e)}focusFirstAutofocusableElement(){if(this.shouldAutofocus){let e=this.connectedSnapshot.firstAutofocusableElement;if(e)e.focus()}}enteringBardo(e){if(this.#e)return;if(e.contains(this.currentSnapshot.activeElement))this.#e=this.currentSnapshot.activeElement}leavingBardo(e){if(e.contains(this.#e)&&this.#e instanceof HTMLElement)this.#e.focus(),this.#e=null}get connectedSnapshot(){return this.newSnapshot.isConnected?this.newSnapshot:this.currentSnapshot}get currentElement(){return this.currentSnapshot.element}get newElement(){return this.newSnapshot.element}get permanentElementMap(){return this.currentSnapshot.getPermanentElementMapForSnapshot(this.newSnapshot)}get renderMethod(){return"replace"}}class ue extends he{static renderElement(e,t){let s=document.createRange();s.selectNodeContents(e),s.deleteContents();let r=t,a=r.ownerDocument?.createRange();if(a)a.selectNodeContents(r),e.appendChild(a.extractContents())}constructor(e,t,s,r,a,u=!0){super(t,s,r,a,u);this.delegate=e}get shouldRender(){return!0}async render(){await J(),this.preservingPermanentElements(()=>{this.loadFrameElement()}),this.scrollFrameIntoView(),await J(),this.focusFirstAutofocusableElement(),await J(),this.activateScriptElements()}loadFrameElement(){this.delegate.willRenderFrame(this.currentElement,this.newElement),this.renderElement(this.currentElement,this.newElement)}scrollFrameIntoView(){if(this.currentElement.autoscroll||this.newElement.autoscroll){let e=this.currentElement.firstElementChild,t=Fs(this.currentElement.getAttribute("data-autoscroll-block"),"end"),s=Hs(this.currentElement.getAttribute("data-autoscroll-behavior"),"auto");if(e)return e.scrollIntoView({block:t,behavior:s}),!0}return!1}activateScriptElements(){for(let e of this.newScriptElements){let t=Q(e);e.replaceWith(t)}}get newScriptElements(){return this.currentElement.querySelectorAll("script")}}function Fs(e,t){if(e=="end"||e=="start"||e=="center"||e=="nearest")return e;else return t}function Hs(e,t){if(e=="auto"||e=="smooth")return e;else return t}var Bs=function(){let e=new Set,t={morphStyle:"outerHTML",callbacks:{beforeNodeAdded:A,afterNodeAdded:A,beforeNodeMorphed:A,afterNodeMorphed:A,beforeNodeRemoved:A,afterNodeRemoved:A,beforeAttributeUpdated:A},head:{style:"merge",shouldPreserve:function(i){return i.getAttribute("im-preserve")==="true"},shouldReAppend:function(i){return i.getAttribute("im-re-append")==="true"},shouldRemove:A,afterHeadMorphed:A}};function s(i,n,o={}){if(i instanceof Document)i=i.documentElement;if(typeof n==="string")n=Nt(n);let l=Wt(n),c=fe(i,l,o);return r(i,l,c)}function r(i,n,o){if(o.head.block){let l=i.querySelector("head"),c=n.querySelector("head");if(l&&c){let h=q(c,l,o);Promise.all(h).then(function(){r(i,n,Object.assign(o,{head:{block:!1,ignore:!0}}))});return}}if(o.morphStyle==="innerHTML")return f(n,i,o),i.children;else if(o.morphStyle==="outerHTML"||o.morphStyle==null){let l=Ut(n,i,o),c=l?.previousSibling,h=l?.nextSibling,d=u(i,l,o);if(l)return _t(c,d,h);else return[]}else throw"Do not understand how to morph style "+o.morphStyle}function a(i,n){return n.ignoreActiveValue&&i===document.activeElement&&i!==document.body}function u(i,n,o){if(o.ignoreActive&&i===document.activeElement);else if(n==null){if(o.callbacks.beforeNodeRemoved(i)===!1)return i;return i.remove(),o.callbacks.afterNodeRemoved(i),null}else if(!ee(i,n)){if(o.callbacks.beforeNodeRemoved(i)===!1)return i;if(o.callbacks.beforeNodeAdded(n)===!1)return i;return i.parentElement.replaceChild(n,i),o.callbacks.afterNodeAdded(n),o.callbacks.afterNodeRemoved(i),n}else{if(o.callbacks.beforeNodeMorphed(i,n)===!1)return i;if(i instanceof HTMLHeadElement&&o.head.ignore);else if(i instanceof HTMLHeadElement&&o.head.style!=="morph")q(n,i,o);else if(C(n,i,o),!a(i,o))f(n,i,o);return o.callbacks.afterNodeMorphed(i,n),i}}function f(i,n,o){let l=i.firstChild,c=n.firstChild,h;while(l){if(h=l,l=h.nextSibling,c==null){if(o.callbacks.beforeNodeAdded(h)===!1)return;n.appendChild(h),o.callbacks.afterNodeAdded(h),F(o,h);continue}if(Z(h,c,o)){u(c,h,o),c=c.nextSibling,F(o,h);continue}let d=Dt(i,n,h,c,o);if(d){c=Me(c,d,o),u(d,h,o),F(o,h);continue}let b=Vt(i,n,h,c,o);if(b){c=Me(c,b,o),u(b,h,o),F(o,h);continue}if(o.callbacks.beforeNodeAdded(h)===!1)return;n.insertBefore(h,c),o.callbacks.afterNodeAdded(h),F(o,h)}while(c!==null){let d=c;c=c.nextSibling,ke(d,o)}}function m(i,n,o,l){if(i==="value"&&l.ignoreActiveValue&&n===document.activeElement)return!0;return l.callbacks.beforeAttributeUpdated(i,n,o)===!1}function C(i,n,o){let l=i.nodeType;if(l===1){let c=i.attributes,h=n.attributes;for(let d of c){if(m(d.name,n,"update",o))continue;if(n.getAttribute(d.name)!==d.value)n.setAttribute(d.name,d.value)}for(let d=h.length-1;0<=d;d--){let b=h[d];if(m(b.name,n,"remove",o))continue;if(!i.hasAttribute(b.name))n.removeAttribute(b.name)}}if(l===8||l===3){if(n.nodeValue!==i.nodeValue)n.nodeValue=i.nodeValue}if(!a(n,o))K(i,n,o)}function y(i,n,o,l){if(i[o]!==n[o]){let c=m(o,n,"update",l);if(!c)n[o]=i[o];if(i[o]){if(!c)n.setAttribute(o,i[o])}else if(!m(o,n,"remove",l))n.removeAttribute(o)}}function K(i,n,o){if(i instanceof HTMLInputElement&&n instanceof HTMLInputElement&&i.type!=="file"){let l=i.value,c=n.value;if(y(i,n,"checked",o),y(i,n,"disabled",o),!i.hasAttribute("value")){if(!m("value",n,"remove",o))n.value="",n.removeAttribute("value")}else if(l!==c){if(!m("value",n,"update",o))n.setAttribute("value",l),n.value=l}}else if(i instanceof HTMLOptionElement)y(i,n,"selected",o);else if(i instanceof HTMLTextAreaElement&&n instanceof HTMLTextAreaElement){let l=i.value,c=n.value;if(m("value",n,"update",o))return;if(l!==c)n.value=l;if(n.firstChild&&n.firstChild.nodeValue!==l)n.firstChild.nodeValue=l}}function q(i,n,o){let l=[],c=[],h=[],d=[],b=o.head.style,H=new Map;for(let v of i.children)H.set(v.outerHTML,v);for(let v of n.children){let R=H.has(v.outerHTML),Y=o.head.shouldReAppend(v),pe=o.head.shouldPreserve(v);if(R||pe)if(Y)c.push(v);else H.delete(v.outerHTML),h.push(v);else if(b==="append"){if(Y)c.push(v),d.push(v)}else if(o.head.shouldRemove(v)!==!1)c.push(v)}d.push(...H.values());let qe=[];for(let v of d){let R=document.createRange().createContextualFragment(v.outerHTML).firstChild;if(o.callbacks.beforeNodeAdded(R)!==!1){if(R.href||R.src){let Y=null,pe=new Promise(function(Kt){Y=Kt});R.addEventListener("load",function(){Y()}),qe.push(pe)}n.appendChild(R),o.callbacks.afterNodeAdded(R),l.push(R)}}for(let v of c)if(o.callbacks.beforeNodeRemoved(v)!==!1)n.removeChild(v),o.callbacks.afterNodeRemoved(v);return o.head.afterHeadMorphed(n,{added:l,kept:h,removed:c}),qe}function A(){}function me(i){let n={};return Object.assign(n,t),Object.assign(n,i),n.callbacks={},Object.assign(n.callbacks,t.callbacks),Object.assign(n.callbacks,i.callbacks),n.head={},Object.assign(n.head,t.head),Object.assign(n.head,i.head),n}function fe(i,n,o){return o=me(o),{target:i,newContent:n,config:o,morphStyle:o.morphStyle,ignoreActive:o.ignoreActive,ignoreActiveValue:o.ignoreActiveValue,idMap:zt(i,n),deadIds:new Set,callbacks:o.callbacks,head:o.head}}function Z(i,n,o){if(i==null||n==null)return!1;if(i.nodeType===n.nodeType&&i.tagName===n.tagName)if(i.id!==""&&i.id===n.id)return!0;else return X(o,i,n)>0;return!1}function ee(i,n){if(i==null||n==null)return!1;return i.nodeType===n.nodeType&&i.tagName===n.tagName}function Me(i,n,o){while(i!==n){let l=i;i=i.nextSibling,ke(l,o)}return F(o,n),n.nextSibling}function Dt(i,n,o,l,c){let h=X(c,o,n),d=null;if(h>0){let b=l,H=0;while(b!=null){if(Z(o,b,c))return b;if(H+=X(c,b,i),H>h)return null;b=b.nextSibling}}return d}function Vt(i,n,o,l,c){let h=l,d=o.nextSibling,b=0;while(h!=null){if(X(c,h,i)>0)return null;if(ee(o,h))return h;if(ee(d,h)){if(b++,d=d.nextSibling,b>=2)return null}h=h.nextSibling}return h}function Nt(i){let n=new DOMParser,o=i.replace(/<svg(\s[^>]*>|>)([\s\S]*?)<\/svg>/gim,"");if(o.match(/<\/html>/)||o.match(/<\/head>/)||o.match(/<\/body>/)){let l=n.parseFromString(i,"text/html");if(o.match(/<\/html>/))return l.generatedByIdiomorph=!0,l;else{let c=l.firstChild;if(c)return c.generatedByIdiomorph=!0,c;else return null}}else{let c=n.parseFromString("<body><template>"+i+"</template></body>","text/html").body.querySelector("template").content;return c.generatedByIdiomorph=!0,c}}function Wt(i){if(i==null)return document.createElement("div");else if(i.generatedByIdiomorph)return i;else if(i instanceof Node){let n=document.createElement("div");return n.append(i),n}else{let n=document.createElement("div");for(let o of[...i])n.append(o);return n}}function _t(i,n,o){let l=[],c=[];while(i!=null)l.push(i),i=i.previousSibling;while(l.length>0){let h=l.pop();c.push(h),n.parentElement.insertBefore(h,n)}c.push(n);while(o!=null)l.push(o),c.push(o),o=o.nextSibling;while(l.length>0)n.parentElement.insertBefore(l.pop(),n.nextSibling);return c}function Ut(i,n,o){let l;l=i.firstChild;let c=l,h=0;while(l){let d=xt(l,n,o);if(d>h)c=l,h=d;l=l.nextSibling}return c}function xt(i,n,o){if(ee(i,n))return 0.5+X(o,i,n);return 0}function ke(i,n){if(F(n,i),n.callbacks.beforeNodeRemoved(i)===!1)return;i.remove(),n.callbacks.afterNodeRemoved(i)}function jt(i,n){return!i.deadIds.has(n)}function $t(i,n,o){return(i.idMap.get(o)||e).has(n)}function F(i,n){let o=i.idMap.get(n)||e;for(let l of o)i.deadIds.add(l)}function X(i,n,o){let l=i.idMap.get(n)||e,c=0;for(let h of l)if(jt(i,h)&&$t(i,h,o))++c;return c}function Ie(i,n){let o=i.parentElement,l=i.querySelectorAll("[id]");for(let c of l){let h=c;while(h!==o&&h!=null){let d=n.get(h);if(d==null)d=new Set,n.set(h,d);d.add(c.id),h=h.parentElement}}}function zt(i,n){let o=new Map;return Ie(i,o),Ie(n,o),o}return{morph:s,defaults:t}}();function Pe(e,t,{callbacks:s,...r}={}){Bs.morph(e,t,{...r,callbacks:new lt(s)})}function at(e,t){Pe(e,t.children,{morphStyle:"innerHTML"})}class lt{#e;constructor({beforeNodeMorphed:e}={}){this.#e=e||(()=>!0)}beforeNodeAdded=(e)=>!(e.id&&e.hasAttribute("data-turbo-permanent")&&document.getElementById(e.id));beforeNodeMorphed=(e,t)=>{if(e instanceof Element)if(!e.hasAttribute("data-turbo-permanent")&&this.#e(e,t))return!p("turbo:before-morph-element",{cancelable:!0,target:e,detail:{currentElement:e,newElement:t}}).defaultPrevented;else return!1};beforeAttributeUpdated=(e,t,s)=>!p("turbo:before-morph-attribute",{cancelable:!0,target:t,detail:{attributeName:e,mutationType:s}}).defaultPrevented;beforeNodeRemoved=(e)=>this.beforeNodeMorphed(e);afterNodeMorphed=(e,t)=>{if(e instanceof Element)p("turbo:morph-element",{target:e,detail:{currentElement:e,newElement:t}})}}class ct extends ue{static renderElement(e,t){p("turbo:before-frame-morph",{target:e,detail:{currentElement:e,newElement:t}}),at(e,t)}async preservingPermanentElements(e){return await e()}}class M{static animationDuration=300;static get defaultCSS(){return je`
31
+ .turbo-progress-bar {
32
+ position: fixed;
33
+ display: block;
34
+ top: 0;
35
+ left: 0;
36
+ height: 3px;
37
+ background: #0076ff;
38
+ z-index: 2147483647;
39
+ transition:
40
+ width ${M.animationDuration}ms ease-out,
41
+ opacity ${M.animationDuration/2}ms ${M.animationDuration/2}ms ease-in;
42
+ transform: translate3d(0, 0, 0);
43
+ }
44
+ `}hiding=!1;value=0;visible=!1;constructor(){this.stylesheetElement=this.createStylesheetElement(),this.progressElement=this.createProgressElement(),this.installStylesheetElement(),this.setValue(0)}show(){if(!this.visible)this.visible=!0,this.installProgressElement(),this.startTrickling()}hide(){if(this.visible&&!this.hiding)this.hiding=!0,this.fadeProgressElement(()=>{this.uninstallProgressElement(),this.stopTrickling(),this.visible=!1,this.hiding=!1})}setValue(e){this.value=e,this.refresh()}installStylesheetElement(){document.head.insertBefore(this.stylesheetElement,document.head.firstChild)}installProgressElement(){this.progressElement.style.width="0",this.progressElement.style.opacity="1",document.documentElement.insertBefore(this.progressElement,document.body),this.refresh()}fadeProgressElement(e){this.progressElement.style.opacity="0",setTimeout(e,M.animationDuration*1.5)}uninstallProgressElement(){if(this.progressElement.parentNode)document.documentElement.removeChild(this.progressElement)}startTrickling(){if(!this.trickleInterval)this.trickleInterval=window.setInterval(this.trickle,M.animationDuration)}stopTrickling(){window.clearInterval(this.trickleInterval),delete this.trickleInterval}trickle=()=>{this.setValue(this.value+Math.random()/100)};refresh(){requestAnimationFrame(()=>{this.progressElement.style.width=`${10+this.value*90}%`})}createStylesheetElement(){let e=document.createElement("style");e.type="text/css",e.textContent=M.defaultCSS;let t=ze();if(t)e.nonce=t;return e}createProgressElement(){let e=document.createElement("div");return e.className="turbo-progress-bar",e}}class ht extends G{detailsByOuterHTML=this.children.filter((e)=>!Ns(e)).map((e)=>Us(e)).reduce((e,t)=>{let{outerHTML:s}=t,r=s in e?e[s]:{type:Os(t),tracked:Ds(t),elements:[]};return{...e,[s]:{...r,elements:[...r.elements,t]}}},{});get trackedElementSignature(){return Object.keys(this.detailsByOuterHTML).filter((e)=>this.detailsByOuterHTML[e].tracked).join("")}getScriptElementsNotInSnapshot(e){return this.getElementsMatchingTypeNotInSnapshot("script",e)}getStylesheetElementsNotInSnapshot(e){return this.getElementsMatchingTypeNotInSnapshot("stylesheet",e)}getElementsMatchingTypeNotInSnapshot(e,t){return Object.keys(this.detailsByOuterHTML).filter((s)=>!(s in t.detailsByOuterHTML)).map((s)=>this.detailsByOuterHTML[s]).filter(({type:s})=>s==e).map(({elements:[s]})=>s)}get provisionalElements(){return Object.keys(this.detailsByOuterHTML).reduce((e,t)=>{let{type:s,tracked:r,elements:a}=this.detailsByOuterHTML[t];if(s==null&&!r)return[...e,...a];else if(a.length>1)return[...e,...a.slice(1)];else return e},[])}getMetaValue(e){let t=this.findMetaElementByName(e);return t?t.getAttribute("content"):null}findMetaElementByName(e){return Object.keys(this.detailsByOuterHTML).reduce((t,s)=>{let{elements:[r]}=this.detailsByOuterHTML[s];return _s(r,e)?r:t},void 0|void 0)}}function Os(e){if(Vs(e))return"script";else if(Ws(e))return"stylesheet"}function Ds(e){return e.getAttribute("data-turbo-track")=="reload"}function Vs(e){return e.localName=="script"}function Ns(e){return e.localName=="noscript"}function Ws(e){let t=e.localName;return t=="style"||t=="link"&&e.getAttribute("rel")=="stylesheet"}function _s(e,t){return e.localName=="meta"&&e.getAttribute("name")==t}function Us(e){if(e.hasAttribute("nonce"))e.setAttribute("nonce","");return e}class T extends G{static fromHTMLString(e=""){return this.fromDocument(xe(e))}static fromElement(e){return this.fromDocument(e.ownerDocument)}static fromDocument({documentElement:e,body:t,head:s}){return new this(e,t,new ht(s))}constructor(e,t,s){super(t);this.documentElement=e,this.headSnapshot=s}clone(){let e=this.element.cloneNode(!0),t=this.element.querySelectorAll("select"),s=e.querySelectorAll("select");for(let[r,a]of t.entries()){let u=s[r];for(let f of u.selectedOptions)f.selected=!1;for(let f of a.selectedOptions)u.options[f.index].selected=!0}for(let r of e.querySelectorAll('input[type="password"]'))r.value="";return new T(this.documentElement,e,this.headSnapshot)}get lang(){return this.documentElement.getAttribute("lang")}get headElement(){return this.headSnapshot.element}get rootLocation(){let e=this.getSetting("root")??"/";return w(e)}get cacheControlValue(){return this.getSetting("cache-control")}get isPreviewable(){return this.cacheControlValue!="no-preview"}get isCacheable(){return this.cacheControlValue!="no-cache"}get isVisitable(){return this.getSetting("visit-control")!="reload"}get prefersViewTransitions(){return this.headSnapshot.getMetaValue("view-transition")==="same-origin"}get shouldMorphPage(){return this.getSetting("refresh-method")==="morph"}get shouldPreserveScrollPosition(){return this.getSetting("refresh-scroll")==="preserve"}getSetting(e){return this.headSnapshot.getMetaValue(`turbo-${e}`)}}class ut{#e=!1;#t=Promise.resolve();renderChange(e,t){if(e&&this.viewTransitionsAvailable&&!this.#e)this.#e=!0,this.#t=this.#t.then(async()=>{await document.startViewTransition(t).finished});else this.#t=this.#t.then(t);return this.#t}get viewTransitionsAvailable(){return document.startViewTransition}}var xs={action:"advance",historyChanged:!1,visitCachedSnapshot:()=>{},willRender:!0,updateHistory:!0,shouldCacheSnapshot:!0,acceptsStreamResponse:!1},se={visitStart:"visitStart",requestStart:"requestStart",requestEnd:"requestEnd",visitEnd:"visitEnd"},P={initialized:"initialized",started:"started",canceled:"canceled",failed:"failed",completed:"completed"},j={networkFailure:0,timeoutFailure:-1,contentTypeMismatch:-2},js={advance:"forward",restore:"back",replace:"none"};class dt{identifier=I();timingMetrics={};followedRedirect=!1;historyChanged=!1;scrolled=!1;shouldCacheSnapshot=!0;acceptsStreamResponse=!1;snapshotCached=!1;state=P.initialized;viewTransitioner=new ut;constructor(e,t,s,r={}){this.delegate=e,this.location=t,this.restorationIdentifier=s||I();let{action:a,historyChanged:u,referrer:f,snapshot:m,snapshotHTML:C,response:y,visitCachedSnapshot:K,willRender:q,updateHistory:A,shouldCacheSnapshot:me,acceptsStreamResponse:fe,direction:Z}={...xs,...r};this.action=a,this.historyChanged=u,this.referrer=f,this.snapshot=m,this.snapshotHTML=C,this.response=y,this.isSamePage=this.delegate.locationWithActionIsSamePage(this.location,this.action),this.isPageRefresh=this.view.isPageRefresh(this),this.visitCachedSnapshot=K,this.willRender=q,this.updateHistory=A,this.scrolled=!q,this.shouldCacheSnapshot=me,this.acceptsStreamResponse=fe,this.direction=Z||js[a]}get adapter(){return this.delegate.adapter}get view(){return this.delegate.view}get history(){return this.delegate.history}get restorationData(){return this.history.getRestorationDataForIdentifier(this.restorationIdentifier)}get silent(){return this.isSamePage}start(){if(this.state==P.initialized)this.recordTimingMetric(se.visitStart),this.state=P.started,this.adapter.visitStarted(this),this.delegate.visitStarted(this)}cancel(){if(this.state==P.started){if(this.request)this.request.cancel();this.cancelRender(),this.state=P.canceled}}complete(){if(this.state==P.started){if(this.recordTimingMetric(se.visitEnd),this.adapter.visitCompleted(this),this.state=P.completed,this.followRedirect(),!this.followedRedirect)this.delegate.visitCompleted(this)}}fail(){if(this.state==P.started)this.state=P.failed,this.adapter.visitFailed(this),this.delegate.visitCompleted(this)}changeHistory(){if(!this.historyChanged&&this.updateHistory){let e=this.location.href===this.referrer?.href?"replace":this.action,t=$e(e);this.history.update(t,this.location,this.restorationIdentifier),this.historyChanged=!0}}issueRequest(){if(this.hasPreloadedResponse())this.simulateRequest();else if(this.shouldIssueRequest()&&!this.request)this.request=new z(this,E.get,this.location),this.request.perform()}simulateRequest(){if(this.response)this.startRequest(),this.recordResponse(),this.finishRequest()}startRequest(){this.recordTimingMetric(se.requestStart),this.adapter.visitRequestStarted(this)}recordResponse(e=this.response){if(this.response=e,e){let{statusCode:t}=e;if(Be(t))this.adapter.visitRequestCompleted(this);else this.adapter.visitRequestFailedWithStatusCode(this,t)}}finishRequest(){this.recordTimingMetric(se.requestEnd),this.adapter.visitRequestFinished(this)}loadResponse(){if(this.response){let{statusCode:e,responseHTML:t}=this.response;this.render(async()=>{if(this.shouldCacheSnapshot)this.cacheSnapshot();if(this.view.renderPromise)await this.view.renderPromise;if(Be(e)&&t!=null){let s=T.fromHTMLString(t);await this.renderPageSnapshot(s,!1),this.adapter.visitRendered(this),this.complete()}else await this.view.renderError(T.fromHTMLString(t),this),this.adapter.visitRendered(this),this.fail()})}}getCachedSnapshot(){let e=this.view.getCachedSnapshotForLocation(this.location)||this.getPreloadedSnapshot();if(e&&(!V(this.location)||e.hasAnchor(V(this.location)))){if(this.action=="restore"||e.isPreviewable)return e}}getPreloadedSnapshot(){if(this.snapshotHTML)return T.fromHTMLString(this.snapshotHTML)}hasCachedSnapshot(){return this.getCachedSnapshot()!=null}loadCachedSnapshot(){let e=this.getCachedSnapshot();if(e){let t=this.shouldIssueRequest();this.render(async()=>{if(this.cacheSnapshot(),this.isSamePage||this.isPageRefresh)this.adapter.visitRendered(this);else{if(this.view.renderPromise)await this.view.renderPromise;if(await this.renderPageSnapshot(e,t),this.adapter.visitRendered(this),!t)this.complete()}})}}followRedirect(){if(this.redirectedToLocation&&!this.followedRedirect&&this.response?.redirected)this.adapter.visitProposedToLocation(this.redirectedToLocation,{action:"replace",response:this.response,shouldCacheSnapshot:!1,willRender:!1}),this.followedRedirect=!0}goToSamePageAnchor(){if(this.isSamePage)this.render(async()=>{this.cacheSnapshot(),this.performScroll(),this.changeHistory(),this.adapter.visitRendered(this)})}prepareRequest(e){if(this.acceptsStreamResponse)e.acceptResponseType(N.contentType)}requestStarted(){this.startRequest()}requestPreventedHandlingResponse(e,t){}async requestSucceededWithResponse(e,t){let s=await t.responseHTML,{redirected:r,statusCode:a}=t;if(s==null)this.recordResponse({statusCode:j.contentTypeMismatch,redirected:r});else this.redirectedToLocation=t.redirected?t.location:void 0,this.recordResponse({statusCode:a,responseHTML:s,redirected:r})}async requestFailedWithResponse(e,t){let s=await t.responseHTML,{redirected:r,statusCode:a}=t;if(s==null)this.recordResponse({statusCode:j.contentTypeMismatch,redirected:r});else this.recordResponse({statusCode:a,responseHTML:s,redirected:r})}requestErrored(e,t){this.recordResponse({statusCode:j.networkFailure,redirected:!1})}requestFinished(){this.finishRequest()}performScroll(){if(!this.scrolled&&!this.view.forceReloaded&&!this.view.shouldPreserveScrollPosition(this)){if(this.action=="restore")this.scrollToRestoredPosition()||this.scrollToAnchor()||this.view.scrollToTop();else this.scrollToAnchor()||this.view.scrollToTop();if(this.isSamePage)this.delegate.visitScrolledToSamePageLocation(this.view.lastRenderedLocation,this.location);this.scrolled=!0}}scrollToRestoredPosition(){let{scrollPosition:e}=this.restorationData;if(e)return this.view.scrollToPosition(e),!0}scrollToAnchor(){let e=V(this.location);if(e!=null)return this.view.scrollToAnchor(e),!0}recordTimingMetric(e){this.timingMetrics[e]=new Date().getTime()}getTimingMetrics(){return{...this.timingMetrics}}getHistoryMethodForAction(e){switch(e){case"replace":return history.replaceState;case"advance":case"restore":return history.pushState}}hasPreloadedResponse(){return typeof this.response=="object"}shouldIssueRequest(){if(this.isSamePage)return!1;else if(this.action=="restore")return!this.hasCachedSnapshot();else return this.willRender}cacheSnapshot(){if(!this.snapshotCached)this.view.cacheSnapshot(this.snapshot).then((e)=>e&&this.visitCachedSnapshot(e)),this.snapshotCached=!0}async render(e){this.cancelRender(),await new Promise((t)=>{this.frame=document.visibilityState==="hidden"?setTimeout(()=>t(),0):requestAnimationFrame(()=>t())}),await e(),delete this.frame}async renderPageSnapshot(e,t){await this.viewTransitioner.renderChange(this.view.shouldTransitionTo(e),async()=>{await this.view.renderPage(e,t,this.willRender,this),this.performScroll()})}cancelRender(){if(this.frame)cancelAnimationFrame(this.frame),delete this.frame}}function Be(e){return e>=200&&e<300}class mt{progressBar=new M;constructor(e){this.session=e}visitProposedToLocation(e,t){if(k(e,this.navigator.rootLocation))this.navigator.startVisit(e,t?.restorationIdentifier||I(),t);else window.location.href=e.toString()}visitStarted(e){this.location=e.location,e.loadCachedSnapshot(),e.issueRequest(),e.goToSamePageAnchor()}visitRequestStarted(e){if(this.progressBar.setValue(0),e.hasCachedSnapshot()||e.action!="restore")this.showVisitProgressBarAfterDelay();else this.showProgressBar()}visitRequestCompleted(e){e.loadResponse()}visitRequestFailedWithStatusCode(e,t){switch(t){case j.networkFailure:case j.timeoutFailure:case j.contentTypeMismatch:return this.reload({reason:"request_failed",context:{statusCode:t}});default:return e.loadResponse()}}visitRequestFinished(e){}visitCompleted(e){this.progressBar.setValue(1),this.hideVisitProgressBar()}pageInvalidated(e){this.reload(e)}visitFailed(e){this.progressBar.setValue(1),this.hideVisitProgressBar()}visitRendered(e){}formSubmissionStarted(e){this.progressBar.setValue(0),this.showFormProgressBarAfterDelay()}formSubmissionFinished(e){this.progressBar.setValue(1),this.hideFormProgressBar()}showVisitProgressBarAfterDelay(){this.visitProgressBarTimeout=window.setTimeout(this.showProgressBar,this.session.progressBarDelay)}hideVisitProgressBar(){if(this.progressBar.hide(),this.visitProgressBarTimeout!=null)window.clearTimeout(this.visitProgressBarTimeout),delete this.visitProgressBarTimeout}showFormProgressBarAfterDelay(){if(this.formProgressBarTimeout==null)this.formProgressBarTimeout=window.setTimeout(this.showProgressBar,this.session.progressBarDelay)}hideFormProgressBar(){if(this.progressBar.hide(),this.formProgressBarTimeout!=null)window.clearTimeout(this.formProgressBarTimeout),delete this.formProgressBarTimeout}showProgressBar=()=>{this.progressBar.show()};reload(e){p("turbo:reload",{detail:e}),window.location.href=this.location?.toString()||window.location.href}get navigator(){return this.session.navigator}}class ft{selector="[data-turbo-temporary]";deprecatedSelector="[data-turbo-cache=false]";started=!1;start(){if(!this.started)this.started=!0,addEventListener("turbo:before-cache",this.removeTemporaryElements,!1)}stop(){if(this.started)this.started=!1,removeEventListener("turbo:before-cache",this.removeTemporaryElements,!1)}removeTemporaryElements=(e)=>{for(let t of this.temporaryElements)t.remove()};get temporaryElements(){return[...document.querySelectorAll(this.selector),...this.temporaryElementsWithDeprecation]}get temporaryElementsWithDeprecation(){let e=document.querySelectorAll(this.deprecatedSelector);if(e.length)console.warn(`The ${this.deprecatedSelector} selector is deprecated and will be removed in a future version. Use ${this.selector} instead.`);return[...e]}}class pt{constructor(e,t){this.session=e,this.element=t,this.linkInterceptor=new Ae(this,t),this.formSubmitObserver=new ce(this,t)}start(){this.linkInterceptor.start(),this.formSubmitObserver.start()}stop(){this.linkInterceptor.stop(),this.formSubmitObserver.stop()}shouldInterceptLinkClick(e,t,s){return this.#t(e)}linkClickIntercepted(e,t,s){let r=this.#s(e);if(r)r.delegate.linkClickIntercepted(e,t,s)}willSubmitForm(e,t){return e.closest("turbo-frame")==null&&this.#e(e,t)&&this.#t(e,t)}formSubmitted(e,t){let s=this.#s(e,t);if(s)s.delegate.formSubmitted(e,t)}#e(e,t){let s=Se(e,t),r=this.element.ownerDocument.querySelector('meta[name="turbo-root"]'),a=w(r?.content??"/");return this.#t(e,t)&&k(s,a)}#t(e,t){if(e instanceof HTMLFormElement?this.session.submissionIsNavigatable(e,t):this.session.elementIsNavigatable(e)){let r=this.#s(e,t);return r?r!=e.closest("turbo-frame"):!1}else return!1}#s(e,t){let s=t?.getAttribute("data-turbo-frame")||e.getAttribute("data-turbo-frame");if(s&&s!="_top"){let r=this.element.querySelector(`#${s}:not([disabled])`);if(r instanceof L)return r}}}class gt{location;restorationIdentifier=I();restorationData={};started=!1;pageLoaded=!1;currentIndex=0;constructor(e){this.delegate=e}start(){if(!this.started)addEventListener("popstate",this.onPopState,!1),addEventListener("load",this.onPageLoad,!1),this.currentIndex=history.state?.turbo?.restorationIndex||0,this.started=!0,this.replace(new URL(window.location.href))}stop(){if(this.started)removeEventListener("popstate",this.onPopState,!1),removeEventListener("load",this.onPageLoad,!1),this.started=!1}push(e,t){this.update(history.pushState,e,t)}replace(e,t){this.update(history.replaceState,e,t)}update(e,t,s=I()){if(e===history.pushState)++this.currentIndex;let r={turbo:{restorationIdentifier:s,restorationIndex:this.currentIndex}};e.call(history,r,"",t.href),this.location=t,this.restorationIdentifier=s}getRestorationDataForIdentifier(e){return this.restorationData[e]||{}}updateRestorationData(e){let{restorationIdentifier:t}=this,s=this.restorationData[t];this.restorationData[t]={...s,...e}}assumeControlOfScrollRestoration(){if(!this.previousScrollRestoration)this.previousScrollRestoration=history.scrollRestoration??"auto",history.scrollRestoration="manual"}relinquishControlOfScrollRestoration(){if(this.previousScrollRestoration)history.scrollRestoration=this.previousScrollRestoration,delete this.previousScrollRestoration}onPopState=(e)=>{if(this.shouldHandlePopState()){let{turbo:t}=e.state||{};if(t){this.location=new URL(window.location.href);let{restorationIdentifier:s,restorationIndex:r}=t;this.restorationIdentifier=s;let a=r>this.currentIndex?"forward":"back";this.delegate.historyPoppedToLocationWithRestorationIdentifierAndDirection(this.location,s,a),this.currentIndex=r}}};onPageLoad=async(e)=>{await es(),this.pageLoaded=!0};shouldHandlePopState(){return this.pageIsLoaded()}pageIsLoaded(){return this.pageLoaded||document.readyState=="complete"}}class bt{started=!1;#e=null;constructor(e,t){this.delegate=e,this.eventTarget=t}start(){if(this.started)return;if(this.eventTarget.readyState==="loading")this.eventTarget.addEventListener("DOMContentLoaded",this.#t,{once:!0});else this.#t()}stop(){if(!this.started)return;this.eventTarget.removeEventListener("mouseenter",this.#s,{capture:!0,passive:!0}),this.eventTarget.removeEventListener("mouseleave",this.#n,{capture:!0,passive:!0}),this.eventTarget.removeEventListener("turbo:before-fetch-request",this.#i,!0),this.started=!1}#t=()=>{this.eventTarget.addEventListener("mouseenter",this.#s,{capture:!0,passive:!0}),this.eventTarget.addEventListener("mouseleave",this.#n,{capture:!0,passive:!0}),this.eventTarget.addEventListener("turbo:before-fetch-request",this.#i,!0),this.started=!0};#s=(e)=>{if(oe("turbo-prefetch")==="false")return;let t=e.target;if(t.matches&&t.matches("a[href]:not([target^=_]):not([download])")&&this.#l(t)){let r=t,a=Je(r);if(this.delegate.canPrefetchRequestToLocation(r,a)){this.#e=r;let u=new z(this,E.get,a,new URLSearchParams,t);U.setLater(a.toString(),u,this.#r)}}};#n=(e)=>{if(e.target===this.#e)this.#o()};#o=()=>{U.clear(),this.#e=null};#i=(e)=>{if(e.target.tagName!=="FORM"&&e.detail.fetchOptions.method==="GET"){let t=U.get(e.detail.url.toString());if(t)e.detail.fetchRequest=t;U.clear()}};prepareRequest(e){let t=e.target;e.headers["X-Sec-Purpose"]="prefetch";let s=t.closest("turbo-frame"),r=t.getAttribute("data-turbo-frame")||s?.getAttribute("target")||s?.id;if(r&&r!=="_top")e.headers["Turbo-Frame"]=r}requestSucceededWithResponse(){}requestStarted(e){}requestErrored(e){}requestFinished(e){}requestPreventedHandlingResponse(e,t){}requestFailedWithResponse(e,t){}get#r(){return Number(oe("turbo-prefetch-cache-time"))||Es}#l(e){if(!e.getAttribute("href"))return!1;if($s(e))return!1;if(zs(e))return!1;if(Ks(e))return!1;if(Xs(e))return!1;if(Js(e))return!1;return!0}}var $s=(e)=>e.origin!==document.location.origin||!["http:","https:"].includes(e.protocol)||e.hasAttribute("target"),zs=(e)=>e.pathname+e.search===document.location.pathname+document.location.search||e.href.startsWith("#"),Ks=(e)=>{if(e.getAttribute("data-turbo-prefetch")==="false")return!0;if(e.getAttribute("data-turbo")==="false")return!0;let t=x(e,"[data-turbo-prefetch]");if(t&&t.getAttribute("data-turbo-prefetch")==="false")return!0;return!1},Xs=(e)=>{let t=e.getAttribute("data-turbo-method");if(t&&t.toLowerCase()!=="get")return!0;if(Ys(e))return!0;if(e.hasAttribute("data-turbo-confirm"))return!0;if(e.hasAttribute("data-turbo-stream"))return!0;return!1},Ys=(e)=>e.hasAttribute("data-remote")||e.hasAttribute("data-behavior")||e.hasAttribute("data-confirm")||e.hasAttribute("data-method"),Js=(e)=>p("turbo:before-prefetch",{target:e,cancelable:!0}).defaultPrevented;class vt{constructor(e){this.delegate=e}proposeVisit(e,t={}){if(this.delegate.allowsVisitingLocationWithAction(e,t.action))this.delegate.visitProposedToLocation(e,t)}startVisit(e,t,s={}){this.stop(),this.currentVisit=new dt(this,w(e),t,{referrer:this.location,...s}),this.currentVisit.start()}submitForm(e,t){this.stop(),this.formSubmission=new le(this,e,t,!0),this.formSubmission.start()}stop(){if(this.formSubmission)this.formSubmission.stop(),delete this.formSubmission;if(this.currentVisit)this.currentVisit.cancel(),delete this.currentVisit}get adapter(){return this.delegate.adapter}get view(){return this.delegate.view}get rootLocation(){return this.view.snapshot.rootLocation}get history(){return this.delegate.history}formSubmissionStarted(e){if(typeof this.adapter.formSubmissionStarted==="function")this.adapter.formSubmissionStarted(e)}async formSubmissionSucceededWithResponse(e,t){if(e==this.formSubmission){let s=await t.responseHTML;if(s){let r=e.isSafe;if(!r)this.view.clearSnapshotCache();let{statusCode:a,redirected:u}=t,m={action:this.#e(e,t),shouldCacheSnapshot:r,response:{statusCode:a,responseHTML:s,redirected:u}};this.proposeVisit(t.location,m)}}}async formSubmissionFailedWithResponse(e,t){let s=await t.responseHTML;if(s){let r=T.fromHTMLString(s);if(t.serverError)await this.view.renderError(r,this.currentVisit);else await this.view.renderPage(r,!1,!0,this.currentVisit);if(!r.shouldPreserveScrollPosition)this.view.scrollToTop();this.view.clearSnapshotCache()}}formSubmissionErrored(e,t){console.error(t)}formSubmissionFinished(e){if(typeof this.adapter.formSubmissionFinished==="function")this.adapter.formSubmissionFinished(e)}visitStarted(e){this.delegate.visitStarted(e)}visitCompleted(e){this.delegate.visitCompleted(e),delete this.currentVisit}locationWithActionIsSamePage(e,t){let s=V(e),r=V(this.view.lastRenderedLocation),a=t==="restore"&&typeof s>"u";return t!=="replace"&&ge(e)===ge(this.view.lastRenderedLocation)&&(a||s!=null&&s!==r)}visitScrolledToSamePageLocation(e,t){this.delegate.visitScrolledToSamePageLocation(e,t)}get location(){return this.history.location}get restorationIdentifier(){return this.history.restorationIdentifier}#e(e,t){let{submitter:s,formElement:r}=e;return D(s,r)||this.#t(t)}#t(e){return e.redirected&&e.location.href===this.location?.href?"replace":"advance"}}var B={initial:0,loading:1,interactive:2,complete:3};class St{stage=B.initial;started=!1;constructor(e){this.delegate=e}start(){if(!this.started){if(this.stage==B.initial)this.stage=B.loading;document.addEventListener("readystatechange",this.interpretReadyState,!1),addEventListener("pagehide",this.pageWillUnload,!1),this.started=!0}}stop(){if(this.started)document.removeEventListener("readystatechange",this.interpretReadyState,!1),removeEventListener("pagehide",this.pageWillUnload,!1),this.started=!1}interpretReadyState=()=>{let{readyState:e}=this;if(e=="interactive")this.pageIsInteractive();else if(e=="complete")this.pageIsComplete()};pageIsInteractive(){if(this.stage==B.loading)this.stage=B.interactive,this.delegate.pageBecameInteractive()}pageIsComplete(){if(this.pageIsInteractive(),this.stage==B.interactive)this.stage=B.complete,this.delegate.pageLoaded()}pageWillUnload=()=>{this.delegate.pageWillUnload()};get readyState(){return document.readyState}}class wt{started=!1;constructor(e){this.delegate=e}start(){if(!this.started)addEventListener("scroll",this.onScroll,!1),this.onScroll(),this.started=!0}stop(){if(this.started)removeEventListener("scroll",this.onScroll,!1),this.started=!1}onScroll=()=>{this.updatePosition({x:window.pageXOffset,y:window.pageYOffset})};updatePosition(e){this.delegate.scrollPositionChanged(e)}}class yt{render({fragment:e}){Re.preservingPermanentElements(this,Qs(e),()=>{Gs(e,()=>{Zs(()=>{document.documentElement.appendChild(e)})})})}enteringBardo(e,t){t.replaceWith(e.cloneNode(!0))}leavingBardo(){}}function Qs(e){let t=nt(document.documentElement),s={};for(let r of t){let{id:a}=r;for(let u of e.querySelectorAll("turbo-stream")){let f=it(u.templateElement.content,a);if(f)s[a]=[r,f]}}return s}async function Gs(e,t){let s=`turbo-stream-autofocus-${I()}`,r=e.querySelectorAll("turbo-stream"),a=er(r),u=null;if(a){if(a.id)u=a.id;else u=s;a.id=u}if(t(),await J(),(document.activeElement==null||document.activeElement==document.body)&&u){let m=document.getElementById(u);if(ve(m))m.focus();if(m&&m.id==s)m.removeAttribute("id")}}async function Zs(e){let[t,s]=await os(e,()=>document.activeElement),r=t&&t.id;if(r){let a=document.getElementById(r);if(ve(a)&&a!=s)a.focus()}}function er(e){for(let t of e){let s=Ke(t.templateElement.content);if(s)return s}return null}class Et{sources=new Set;#e=!1;constructor(e){this.delegate=e}start(){if(!this.#e)this.#e=!0,addEventListener("turbo:before-fetch-response",this.inspectFetchResponse,!1)}stop(){if(this.#e)this.#e=!1,removeEventListener("turbo:before-fetch-response",this.inspectFetchResponse,!1)}connectStreamSource(e){if(!this.streamSourceIsConnected(e))this.sources.add(e),e.addEventListener("message",this.receiveMessageEvent,!1)}disconnectStreamSource(e){if(this.streamSourceIsConnected(e))this.sources.delete(e),e.removeEventListener("message",this.receiveMessageEvent,!1)}streamSourceIsConnected(e){return this.sources.has(e)}inspectFetchResponse=(e)=>{let t=tr(e);if(t&&sr(t))e.preventDefault(),this.receiveMessageResponse(t)};receiveMessageEvent=(e)=>{if(this.#e&&typeof e.data=="string")this.receiveMessageHTML(e.data)};async receiveMessageResponse(e){let t=await e.responseHTML;if(t)this.receiveMessageHTML(t)}receiveMessageHTML(e){this.delegate.receivedMessageFromStream(N.wrap(e))}}function tr(e){let t=e.detail?.fetchResponse;if(t instanceof ae)return t}function sr(e){return(e.contentType??"").startsWith(N.contentType)}class At extends he{static renderElement(e,t){let{documentElement:s,body:r}=document;s.replaceChild(t,r)}async render(){this.replaceHeadAndBody(),this.activateScriptElements()}replaceHeadAndBody(){let{documentElement:e,head:t}=document;e.replaceChild(this.newHead,t),this.renderElement(this.currentElement,this.newElement)}activateScriptElements(){for(let e of this.scriptElements){let t=e.parentNode;if(t){let s=Q(e);t.replaceChild(s,e)}}}get newHead(){return this.newSnapshot.headSnapshot.element}get scriptElements(){return document.documentElement.querySelectorAll("script")}}class de extends he{static renderElement(e,t){if(document.body&&t instanceof HTMLBodyElement)document.body.replaceWith(t);else document.documentElement.appendChild(t)}get shouldRender(){return this.newSnapshot.isVisitable&&this.trackedElementsAreIdentical}get reloadReason(){if(!this.newSnapshot.isVisitable)return{reason:"turbo_visit_control_is_reload"};if(!this.trackedElementsAreIdentical)return{reason:"tracked_element_mismatch"}}async prepareToRender(){this.#e(),await this.mergeHead()}async render(){if(this.willRender)await this.replaceBody()}finishRendering(){if(super.finishRendering(),!this.isPreview)this.focusFirstAutofocusableElement()}get currentHeadSnapshot(){return this.currentSnapshot.headSnapshot}get newHeadSnapshot(){return this.newSnapshot.headSnapshot}get newElement(){return this.newSnapshot.element}#e(){let{documentElement:e}=this.currentSnapshot,{lang:t}=this.newSnapshot;if(t)e.setAttribute("lang",t);else e.removeAttribute("lang")}async mergeHead(){let e=this.mergeProvisionalElements(),t=this.copyNewHeadStylesheetElements();if(this.copyNewHeadScriptElements(),await e,await t,this.willRender)this.removeUnusedDynamicStylesheetElements()}async replaceBody(){await this.preservingPermanentElements(async()=>{this.activateNewBody(),await this.assignNewBody()})}get trackedElementsAreIdentical(){return this.currentHeadSnapshot.trackedElementSignature==this.newHeadSnapshot.trackedElementSignature}async copyNewHeadStylesheetElements(){let e=[];for(let t of this.newHeadStylesheetElements)e.push(rs(t)),document.head.appendChild(t);await Promise.all(e)}copyNewHeadScriptElements(){for(let e of this.newHeadScriptElements)document.head.appendChild(Q(e))}removeUnusedDynamicStylesheetElements(){for(let e of this.unusedDynamicStylesheetElements)document.head.removeChild(e)}async mergeProvisionalElements(){let e=[...this.newHeadProvisionalElements];for(let t of this.currentHeadProvisionalElements)if(!this.isCurrentElementInElementList(t,e))document.head.removeChild(t);for(let t of e)document.head.appendChild(t)}isCurrentElementInElementList(e,t){for(let[s,r]of t.entries()){if(e.tagName=="TITLE"){if(r.tagName!="TITLE")continue;if(e.innerHTML==r.innerHTML)return t.splice(s,1),!0}if(r.isEqualNode(e))return t.splice(s,1),!0}return!1}removeCurrentHeadProvisionalElements(){for(let e of this.currentHeadProvisionalElements)document.head.removeChild(e)}copyNewHeadProvisionalElements(){for(let e of this.newHeadProvisionalElements)document.head.appendChild(e)}activateNewBody(){document.adoptNode(this.newElement),this.activateNewBodyScriptElements()}activateNewBodyScriptElements(){for(let e of this.newBodyScriptElements){let t=Q(e);e.replaceWith(t)}}async assignNewBody(){await this.renderElement(this.currentElement,this.newElement)}get unusedDynamicStylesheetElements(){return this.oldHeadStylesheetElements.filter((e)=>e.getAttribute("data-turbo-track")==="dynamic")}get oldHeadStylesheetElements(){return this.currentHeadSnapshot.getStylesheetElementsNotInSnapshot(this.newHeadSnapshot)}get newHeadStylesheetElements(){return this.newHeadSnapshot.getStylesheetElementsNotInSnapshot(this.currentHeadSnapshot)}get newHeadScriptElements(){return this.newHeadSnapshot.getScriptElementsNotInSnapshot(this.currentHeadSnapshot)}get currentHeadProvisionalElements(){return this.currentHeadSnapshot.provisionalElements}get newHeadProvisionalElements(){return this.newHeadSnapshot.provisionalElements}get newBodyScriptElements(){return this.newElement.querySelectorAll("script")}}class Tt extends de{static renderElement(e,t){Pe(e,t,{callbacks:{beforeNodeMorphed:(s)=>!Oe(s)}});for(let s of e.querySelectorAll("turbo-frame"))if(Oe(s))s.reload();p("turbo:morph",{detail:{currentElement:e,newElement:t}})}async preservingPermanentElements(e){return await e()}get renderMethod(){return"morph"}get shouldAutofocus(){return!1}}function Oe(e){return e instanceof L&&e.src&&e.refresh==="morph"&&!e.closest("[data-turbo-permanent]")}class Lt{keys=[];snapshots={};constructor(e){this.size=e}has(e){return te(e)in this.snapshots}get(e){if(this.has(e)){let t=this.read(e);return this.touch(e),t}}put(e,t){return this.write(e,t),this.touch(e),t}clear(){this.snapshots={}}read(e){return this.snapshots[te(e)]}write(e,t){this.snapshots[te(e)]=t}touch(e){let t=te(e),s=this.keys.indexOf(t);if(s>-1)this.keys.splice(s,1);this.keys.unshift(t),this.trim()}trim(){for(let e of this.keys.splice(this.size))delete this.snapshots[e]}}class Rt extends Ee{snapshotCache=new Lt(10);lastRenderedLocation=new URL(location.href);forceReloaded=!1;shouldTransitionTo(e){return this.snapshot.prefersViewTransitions&&e.prefersViewTransitions}renderPage(e,t=!1,s=!0,r){let f=new(this.isPageRefresh(r)&&this.snapshot.shouldMorphPage?Tt:de)(this.snapshot,e,t,s);if(!f.shouldRender)this.forceReloaded=!0;else r?.changeHistory();return this.render(f)}renderError(e,t){t?.changeHistory();let s=new At(this.snapshot,e,!1);return this.render(s)}clearSnapshotCache(){this.snapshotCache.clear()}async cacheSnapshot(e=this.snapshot){if(e.isCacheable){this.delegate.viewWillCacheSnapshot();let{lastRenderedLocation:t}=this;await Ue();let s=e.clone();return this.snapshotCache.put(t,s),s}}getCachedSnapshotForLocation(e){return this.snapshotCache.get(e)}isPageRefresh(e){return!e||this.lastRenderedLocation.pathname===e.location.pathname&&e.action==="replace"}shouldPreserveScrollPosition(e){return this.isPageRefresh(e)&&this.snapshot.shouldPreserveScrollPosition}get snapshot(){return T.fromElement(this.element)}}class Pt{selector="a[data-turbo-preload]";constructor(e,t){this.delegate=e,this.snapshotCache=t}start(){if(document.readyState==="loading")document.addEventListener("DOMContentLoaded",this.#e);else this.preloadOnLoadLinksForView(document.body)}stop(){document.removeEventListener("DOMContentLoaded",this.#e)}preloadOnLoadLinksForView(e){for(let t of e.querySelectorAll(this.selector))if(this.delegate.shouldPreloadLink(t))this.preloadURL(t)}async preloadURL(e){let t=new URL(e.href);if(this.snapshotCache.has(t))return;await new z(this,E.get,t,new URLSearchParams,e).perform()}prepareRequest(e){e.headers["X-Sec-Purpose"]="prefetch"}async requestSucceededWithResponse(e,t){try{let s=await t.responseHTML,r=T.fromHTMLString(s);this.snapshotCache.put(e.url,r)}catch(s){}}requestStarted(e){}requestErrored(e){}requestFinished(e){}requestPreventedHandlingResponse(e,t){}requestFailedWithResponse(e,t){}#e=()=>{this.preloadOnLoadLinksForView(document.body)}}class Ct{constructor(e){this.session=e}clear(){this.session.clearCache()}resetCacheControl(){this.#e("")}exemptPageFromCache(){this.#e("no-cache")}exemptPageFromPreview(){this.#e("no-preview")}#e(e){ns("turbo-cache-control",e)}}class Mt{navigator=new vt(this);history=new gt(this);view=new Rt(this,document.documentElement);adapter=new mt(this);pageObserver=new St(this);cacheObserver=new ft;linkPrefetchObserver=new bt(this,document);linkClickObserver=new Te(this,window);formSubmitObserver=new ce(this,document);scrollObserver=new wt(this);streamObserver=new Et(this);formLinkClickObserver=new Le(this,document.documentElement);frameRedirector=new pt(this,document.documentElement);streamMessageRenderer=new yt;cache=new Ct(this);enabled=!0;started=!1;#e=150;constructor(e){this.recentRequests=e,this.preloader=new Pt(this,this.view.snapshotCache),this.debouncedRefresh=this.refresh,this.pageRefreshDebouncePeriod=this.pageRefreshDebouncePeriod}start(){if(!this.started)this.pageObserver.start(),this.cacheObserver.start(),this.linkPrefetchObserver.start(),this.formLinkClickObserver.start(),this.linkClickObserver.start(),this.formSubmitObserver.start(),this.scrollObserver.start(),this.streamObserver.start(),this.frameRedirector.start(),this.history.start(),this.preloader.start(),this.started=!0,this.enabled=!0}disable(){this.enabled=!1}stop(){if(this.started)this.pageObserver.stop(),this.cacheObserver.stop(),this.linkPrefetchObserver.stop(),this.formLinkClickObserver.stop(),this.linkClickObserver.stop(),this.formSubmitObserver.stop(),this.scrollObserver.stop(),this.streamObserver.stop(),this.frameRedirector.stop(),this.history.stop(),this.preloader.stop(),this.started=!1}registerAdapter(e){this.adapter=e}visit(e,t={}){let s=t.frame?document.getElementById(t.frame):null;if(s instanceof L){let r=t.action||D(s);s.delegate.proposeVisitIfNavigatedWithAction(s,r),s.src=e.toString()}else this.navigator.proposeVisit(w(e),t)}refresh(e,t){if(!(t&&this.recentRequests.has(t))&&!this.navigator.currentVisit)this.visit(e,{action:"replace",shouldCacheSnapshot:!1})}connectStreamSource(e){this.streamObserver.connectStreamSource(e)}disconnectStreamSource(e){this.streamObserver.disconnectStreamSource(e)}renderStreamMessage(e){this.streamMessageRenderer.render(N.wrap(e))}clearCache(){this.view.clearSnapshotCache()}setProgressBarDelay(e){console.warn("Please replace `session.setProgressBarDelay(delay)` with `session.progressBarDelay = delay`. The function is deprecated and will be removed in a future version of Turbo.`"),this.progressBarDelay=e}set progressBarDelay(e){S.drive.progressBarDelay=e}get progressBarDelay(){return S.drive.progressBarDelay}set drive(e){S.drive.enabled=e}get drive(){return S.drive.enabled}set formMode(e){S.forms.mode=e}get formMode(){return S.forms.mode}get location(){return this.history.location}get restorationIdentifier(){return this.history.restorationIdentifier}get pageRefreshDebouncePeriod(){return this.#e}set pageRefreshDebouncePeriod(e){this.refresh=as(this.debouncedRefresh.bind(this),e),this.#e=e}shouldPreloadLink(e){let t=e.hasAttribute("data-turbo-method"),s=e.hasAttribute("data-turbo-stream"),r=e.getAttribute("data-turbo-frame"),a=r=="_top"?null:document.getElementById(r)||x(e,"turbo-frame:not([disabled])");if(t||s||a instanceof L)return!1;else{let u=new URL(e.href);return this.elementIsNavigatable(e)&&k(u,this.snapshot.rootLocation)}}historyPoppedToLocationWithRestorationIdentifierAndDirection(e,t,s){if(this.enabled)this.navigator.startVisit(e,t,{action:"restore",historyChanged:!0,direction:s});else this.adapter.pageInvalidated({reason:"turbo_disabled"})}scrollPositionChanged(e){this.history.updateRestorationData({scrollPosition:e})}willSubmitFormLinkToLocation(e,t){return this.elementIsNavigatable(e)&&k(t,this.snapshot.rootLocation)}submittedFormLinkToLocation(){}canPrefetchRequestToLocation(e,t){return this.elementIsNavigatable(e)&&k(t,this.snapshot.rootLocation)}willFollowLinkToLocation(e,t,s){return this.elementIsNavigatable(e)&&k(t,this.snapshot.rootLocation)&&this.applicationAllowsFollowingLinkToLocation(e,t,s)}followedLinkToLocation(e,t){let s=this.getActionForLink(e),r=e.hasAttribute("data-turbo-stream");this.visit(t.href,{action:s,acceptsStreamResponse:r})}allowsVisitingLocationWithAction(e,t){return this.locationWithActionIsSamePage(e,t)||this.applicationAllowsVisitingLocation(e)}visitProposedToLocation(e,t){De(e),this.adapter.visitProposedToLocation(e,t)}visitStarted(e){if(!e.acceptsStreamResponse)ie(document.documentElement),this.view.markVisitDirection(e.direction);if(De(e.location),!e.silent)this.notifyApplicationAfterVisitingLocation(e.location,e.action)}visitCompleted(e){this.view.unmarkVisitDirection(),ne(document.documentElement),this.notifyApplicationAfterPageLoad(e.getTimingMetrics())}locationWithActionIsSamePage(e,t){return this.navigator.locationWithActionIsSamePage(e,t)}visitScrolledToSamePageLocation(e,t){this.notifyApplicationAfterVisitingSamePageLocation(e,t)}willSubmitForm(e,t){let s=Se(e,t);return this.submissionIsNavigatable(e,t)&&k(w(s),this.snapshot.rootLocation)}formSubmitted(e,t){this.navigator.submitForm(e,t)}pageBecameInteractive(){this.view.lastRenderedLocation=this.location,this.notifyApplicationAfterPageLoad()}pageLoaded(){this.history.assumeControlOfScrollRestoration()}pageWillUnload(){this.history.relinquishControlOfScrollRestoration()}receivedMessageFromStream(e){this.renderStreamMessage(e)}viewWillCacheSnapshot(){if(!this.navigator.currentVisit?.silent)this.notifyApplicationBeforeCachingSnapshot()}allowsImmediateRender({element:e},t){let s=this.notifyApplicationBeforeRender(e,t),{defaultPrevented:r,detail:{render:a}}=s;if(this.view.renderer&&a)this.view.renderer.renderElement=a;return!r}viewRenderedSnapshot(e,t,s){this.view.lastRenderedLocation=this.history.location,this.notifyApplicationAfterRender(s)}preloadOnLoadLinksForView(e){this.preloader.preloadOnLoadLinksForView(e)}viewInvalidated(e){this.adapter.pageInvalidated(e)}frameLoaded(e){this.notifyApplicationAfterFrameLoad(e)}frameRendered(e,t){this.notifyApplicationAfterFrameRender(e,t)}applicationAllowsFollowingLinkToLocation(e,t,s){return!this.notifyApplicationAfterClickingLinkToLocation(e,t,s).defaultPrevented}applicationAllowsVisitingLocation(e){return!this.notifyApplicationBeforeVisitingLocation(e).defaultPrevented}notifyApplicationAfterClickingLinkToLocation(e,t,s){return p("turbo:click",{target:e,detail:{url:t.href,originalEvent:s},cancelable:!0})}notifyApplicationBeforeVisitingLocation(e){return p("turbo:before-visit",{detail:{url:e.href},cancelable:!0})}notifyApplicationAfterVisitingLocation(e,t){return p("turbo:visit",{detail:{url:e.href,action:t}})}notifyApplicationBeforeCachingSnapshot(){return p("turbo:before-cache")}notifyApplicationBeforeRender(e,t){return p("turbo:before-render",{detail:{newBody:e,...t},cancelable:!0})}notifyApplicationAfterRender(e){return p("turbo:render",{detail:{renderMethod:e}})}notifyApplicationAfterPageLoad(e={}){return p("turbo:load",{detail:{url:this.location.href,timing:e}})}notifyApplicationAfterVisitingSamePageLocation(e,t){dispatchEvent(new HashChangeEvent("hashchange",{oldURL:e.toString(),newURL:t.toString()}))}notifyApplicationAfterFrameLoad(e){return p("turbo:frame-load",{target:e})}notifyApplicationAfterFrameRender(e,t){return p("turbo:frame-render",{detail:{fetchResponse:e},target:t,cancelable:!0})}submissionIsNavigatable(e,t){if(S.forms.mode=="off")return!1;else{let s=t?this.elementIsNavigatable(t):!0;if(S.forms.mode=="optin")return s&&e.closest('[data-turbo="true"]')!=null;else return s&&this.elementIsNavigatable(e)}}elementIsNavigatable(e){let t=x(e,"[data-turbo]"),s=x(e,"turbo-frame");if(S.drive.enabled||s)if(t)return t.getAttribute("data-turbo")!="false";else return!0;else if(t)return t.getAttribute("data-turbo")=="true";else return!1}getActionForLink(e){return D(e)||"advance"}get snapshot(){return this.view.snapshot}}function De(e){Object.defineProperties(e,rr)}var rr={absoluteURL:{get(){return this.toString()}}},g=new Mt(Ze),{cache:ir,navigator:nr}=g;function kt(){g.start()}function or(e){g.registerAdapter(e)}function ar(e,t){g.visit(e,t)}function It(e){g.connectStreamSource(e)}function qt(e){g.disconnectStreamSource(e)}function lr(e){g.renderStreamMessage(e)}function cr(){console.warn("Please replace `Turbo.clearCache()` with `Turbo.cache.clear()`. The top-level function is deprecated and will be removed in a future version of Turbo.`"),g.clearCache()}function hr(e){console.warn("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.`"),S.drive.progressBarDelay=e}function ur(e){console.warn("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.`"),S.forms.confirm=e}function dr(e){console.warn("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.`"),S.forms.mode=e}var mr=Object.freeze({__proto__:null,navigator:nr,session:g,cache:ir,PageRenderer:de,PageSnapshot:T,FrameRenderer:ue,fetch:et,config:S,start:kt,registerAdapter:or,visit:ar,connectStreamSource:It,disconnectStreamSource:qt,renderStreamMessage:lr,clearCache:cr,setProgressBarDelay:hr,setConfirmMethod:ur,setFormMode:dr});class Ft extends Error{}class Ht{fetchResponseLoaded=(e)=>Promise.resolve();#e=null;#t=()=>{};#s=!1;#n=!1;#o=new Set;#i=!1;action=null;constructor(e){this.element=e,this.view=new ot(this,this.element),this.appearanceObserver=new st(this,this.element),this.formLinkClickObserver=new Le(this,this.element),this.linkInterceptor=new Ae(this,this.element),this.restorationIdentifier=I(),this.formSubmitObserver=new ce(this,this.element)}connect(){if(!this.#s){if(this.#s=!0,this.loadingStyle==_.lazy)this.appearanceObserver.start();else this.#r();this.formLinkClickObserver.start(),this.linkInterceptor.start(),this.formSubmitObserver.start()}}disconnect(){if(this.#s)this.#s=!1,this.appearanceObserver.stop(),this.formLinkClickObserver.stop(),this.linkInterceptor.stop(),this.formSubmitObserver.stop()}disabledChanged(){if(this.loadingStyle==_.eager)this.#r()}sourceURLChanged(){if(this.#v("src"))return;if(this.element.isConnected)this.complete=!1;if(this.loadingStyle==_.eager||this.#n)this.#r()}sourceURLReloaded(){let{refresh:e,src:t}=this.element;return this.#i=t&&e==="morph",this.element.removeAttribute("complete"),this.element.src=null,this.element.src=t,this.element.loaded}loadingStyleChanged(){if(this.loadingStyle==_.lazy)this.appearanceObserver.start();else this.appearanceObserver.stop(),this.#r()}async#r(){if(this.enabled&&this.isActive&&!this.complete&&this.sourceURL)this.element.loaded=this.#u(w(this.sourceURL)),this.appearanceObserver.stop(),await this.element.loaded,this.#n=!0}async loadResponse(e){if(e.redirected||e.succeeded&&e.isHTML)this.sourceURL=e.response.url;try{let t=await e.responseHTML;if(t){let s=xe(t);if(T.fromDocument(s).isVisitable)await this.#l(e,s);else await this.#m(e)}}finally{this.#i=!1,this.fetchResponseLoaded=()=>Promise.resolve()}}elementAppearedInViewport(e){this.proposeVisitIfNavigatedWithAction(e,D(e)),this.#r()}willSubmitFormLinkToLocation(e){return this.#c(e)}submittedFormLinkToLocation(e,t,s){let r=this.#a(e);if(r)s.setAttribute("data-turbo-frame",r.id)}shouldInterceptLinkClick(e,t,s){return this.#c(e)}linkClickIntercepted(e,t){this.#d(e,t)}willSubmitForm(e,t){return e.closest("turbo-frame")==this.element&&this.#c(e,t)}formSubmitted(e,t){if(this.formSubmission)this.formSubmission.stop();this.formSubmission=new le(this,e,t);let{fetchRequest:s}=this.formSubmission;this.prepareRequest(s),this.formSubmission.start()}prepareRequest(e){if(e.headers["Turbo-Frame"]=this.id,this.currentNavigationElement?.hasAttribute("data-turbo-stream"))e.acceptResponseType(N.contentType)}requestStarted(e){ie(this.element)}requestPreventedHandlingResponse(e,t){this.#t()}async requestSucceededWithResponse(e,t){await this.loadResponse(t),this.#t()}async requestFailedWithResponse(e,t){await this.loadResponse(t),this.#t()}requestErrored(e,t){console.error(t),this.#t()}requestFinished(e){ne(this.element)}formSubmissionStarted({formElement:e}){ie(e,this.#a(e))}formSubmissionSucceededWithResponse(e,t){let s=this.#a(e.formElement,e.submitter);if(s.delegate.proposeVisitIfNavigatedWithAction(s,D(e.submitter,e.formElement,s)),s.delegate.loadResponse(t),!e.isSafe)g.clearCache()}formSubmissionFailedWithResponse(e,t){this.element.delegate.loadResponse(t),g.clearCache()}formSubmissionErrored(e,t){console.error(t)}formSubmissionFinished({formElement:e}){ne(e,this.#a(e))}allowsImmediateRender({element:e},t){let s=p("turbo:before-frame-render",{target:this.element,detail:{newFrame:e,...t},cancelable:!0}),{defaultPrevented:r,detail:{render:a}}=s;if(this.view.renderer&&a)this.view.renderer.renderElement=a;return!r}viewRenderedSnapshot(e,t,s){}preloadOnLoadLinksForView(e){g.preloadOnLoadLinksForView(e)}viewInvalidated(){}willRenderFrame(e,t){this.previousFrameElement=e.cloneNode(!0)}visitCachedSnapshot=({element:e})=>{let t=e.querySelector("#"+this.element.id);if(t&&this.previousFrameElement)t.replaceChildren(...this.previousFrameElement.children);delete this.previousFrameElement};async#l(e,t){let s=await this.extractForeignFrameElement(t.body),r=this.#i?ct:ue;if(s){let a=new G(s),u=new r(this,this.view.snapshot,a,!1,!1);if(this.view.renderPromise)await this.view.renderPromise;this.changeHistory(),await this.view.render(u),this.complete=!0,g.frameRendered(e,this.element),g.frameLoaded(this.element),await this.fetchResponseLoaded(e)}else if(this.#f(e))this.#p(e)}async#u(e){let t=new z(this,E.get,e,new URLSearchParams,this.element);return this.#e?.cancel(),this.#e=t,new Promise((s)=>{this.#t=()=>{this.#t=()=>{},this.#e=null,s()},t.perform()})}#d(e,t,s){let r=this.#a(e,s);r.delegate.proposeVisitIfNavigatedWithAction(r,D(s,e,r)),this.#w(e,()=>{r.src=t})}proposeVisitIfNavigatedWithAction(e,t=null){if(this.action=t,this.action){let s=T.fromElement(e).clone(),{visitCachedSnapshot:r}=e.delegate;e.delegate.fetchResponseLoaded=async(a)=>{if(e.src){let{statusCode:u,redirected:f}=a,m=await a.responseHTML,y={response:{statusCode:u,redirected:f,responseHTML:m},visitCachedSnapshot:r,willRender:!1,updateHistory:!1,restorationIdentifier:this.restorationIdentifier,snapshot:s};if(this.action)y.action=this.action;g.visit(e.src,y)}}}}changeHistory(){if(this.action){let e=$e(this.action);g.history.update(e,w(this.element.src||""),this.restorationIdentifier)}}async#m(e){console.warn(`The response (${e.statusCode}) from <turbo-frame id="${this.element.id}"> is performing a full page visit due to turbo-visit-control.`),await this.#h(e.response)}#f(e){this.element.setAttribute("complete","");let t=e.response,s=async(a,u)=>{if(a instanceof Response)this.#h(a);else g.visit(a,u)};return!p("turbo:frame-missing",{target:this.element,detail:{response:t,visit:s},cancelable:!0}).defaultPrevented}#p(e){this.view.missing(),this.#g(e)}#g(e){let t=`The response (${e.statusCode}) did not contain the expected <turbo-frame id="${this.element.id}"> and will be ignored. To perform a full page visit instead, set turbo-visit-control to reload.`;throw new Ft(t)}async#h(e){let t=new ae(e),s=await t.responseHTML,{location:r,redirected:a,statusCode:u}=t;return g.visit(r,{response:{redirected:a,statusCode:u,responseHTML:s}})}#a(e,t){let s=re("data-turbo-frame",t,e)||this.element.getAttribute("target");return Ve(s)??this.element}async extractForeignFrameElement(e){let t,s=CSS.escape(this.id);try{if(t=Ne(e.querySelector(`turbo-frame#${s}`),this.sourceURL),t)return t;if(t=Ne(e.querySelector(`turbo-frame[src][recurse~=${s}]`),this.sourceURL),t)return await t.loaded,await this.extractForeignFrameElement(t)}catch(r){return console.error(r),new L}return null}#b(e,t){let s=Se(e,t);return k(w(s),this.rootLocation)}#c(e,t){let s=re("data-turbo-frame",t,e)||this.element.getAttribute("target");if(e instanceof HTMLFormElement&&!this.#b(e,t))return!1;if(!this.enabled||s=="_top")return!1;if(s){let r=Ve(s);if(r)return!r.disabled}if(!g.elementIsNavigatable(e))return!1;if(t&&!g.elementIsNavigatable(t))return!1;return!0}get id(){return this.element.id}get enabled(){return!this.element.disabled}get sourceURL(){if(this.element.src)return this.element.src}set sourceURL(e){this.#S("src",()=>{this.element.src=e??null})}get loadingStyle(){return this.element.loading}get isLoading(){return this.formSubmission!==void 0||this.#t()!==void 0}get complete(){return this.element.hasAttribute("complete")}set complete(e){if(e)this.element.setAttribute("complete","");else this.element.removeAttribute("complete")}get isActive(){return this.element.isActive&&this.#s}get rootLocation(){let t=this.element.ownerDocument.querySelector('meta[name="turbo-root"]')?.content??"/";return w(t)}#v(e){return this.#o.has(e)}#S(e,t){this.#o.add(e),t(),this.#o.delete(e)}#w(e,t){this.currentNavigationElement=e,t(),delete this.currentNavigationElement}}function Ve(e){if(e!=null){let t=document.getElementById(e);if(t instanceof L)return t}}function Ne(e,t){if(e){let s=e.getAttribute("src");if(s!=null&&t!=null&&ds(s,t))throw Error(`Matching <turbo-frame id="${e.id}"> element has a source URL which references itself`);if(e.ownerDocument!==document)e=document.importNode(e,!0);if(e instanceof L)return e.connectedCallback(),e.disconnectedCallback(),e}}var Bt={after(){this.targetElements.forEach((e)=>e.parentElement?.insertBefore(this.templateContent,e.nextSibling))},append(){this.removeDuplicateTargetChildren(),this.targetElements.forEach((e)=>e.append(this.templateContent))},before(){this.targetElements.forEach((e)=>e.parentElement?.insertBefore(this.templateContent,e))},prepend(){this.removeDuplicateTargetChildren(),this.targetElements.forEach((e)=>e.prepend(this.templateContent))},remove(){this.targetElements.forEach((e)=>e.remove())},replace(){let e=this.getAttribute("method");this.targetElements.forEach((t)=>{if(e==="morph")Pe(t,this.templateContent);else t.replaceWith(this.templateContent)})},update(){let e=this.getAttribute("method");this.targetElements.forEach((t)=>{if(e==="morph")at(t,this.templateContent);else t.innerHTML="",t.append(this.templateContent)})},refresh(){g.refresh(this.baseURI,this.requestId)}};class Ce extends HTMLElement{static async renderElement(e){await e.performAction()}async connectedCallback(){try{await this.render()}catch(e){console.error(e)}finally{this.disconnect()}}async render(){return this.renderPromise??=(async()=>{let e=this.beforeRenderEvent;if(this.dispatchEvent(e))await J(),await e.detail.render(this)})()}disconnect(){try{this.remove()}catch{}}removeDuplicateTargetChildren(){this.duplicateChildren.forEach((e)=>e.remove())}get duplicateChildren(){let e=this.targetElements.flatMap((s)=>[...s.children]).filter((s)=>!!s.id),t=[...this.templateContent?.children||[]].filter((s)=>!!s.id).map((s)=>s.id);return e.filter((s)=>t.includes(s.id))}get performAction(){if(this.action){let e=Bt[this.action];if(e)return e;this.#e("unknown action")}this.#e("action attribute is missing")}get targetElements(){if(this.target)return this.targetElementsById;else if(this.targets)return this.targetElementsByQuery;else this.#e("target or targets attribute is missing")}get templateContent(){return this.templateElement.content.cloneNode(!0)}get templateElement(){if(this.firstElementChild===null){let e=this.ownerDocument.createElement("template");return this.appendChild(e),e}else if(this.firstElementChild instanceof HTMLTemplateElement)return this.firstElementChild;this.#e("first child element must be a <template> element")}get action(){return this.getAttribute("action")}get target(){return this.getAttribute("target")}get targets(){return this.getAttribute("targets")}get requestId(){return this.getAttribute("request-id")}#e(e){throw Error(`${this.description}: ${e}`)}get description(){return(this.outerHTML.match(/<[^>]+>/)??[])[0]??"<turbo-stream>"}get beforeRenderEvent(){return new CustomEvent("turbo:before-stream-render",{bubbles:!0,cancelable:!0,detail:{newStream:this,render:Ce.renderElement}})}get targetElementsById(){let e=this.ownerDocument?.getElementById(this.target);if(e!==null)return[e];else return[]}get targetElementsByQuery(){let e=this.ownerDocument?.querySelectorAll(this.targets);if(e.length!==0)return Array.prototype.slice.call(e);else return[]}}class Ot extends HTMLElement{streamSource=null;connectedCallback(){this.streamSource=this.src.match(/^ws{1,2}:/)?new WebSocket(this.src):new EventSource(this.src),It(this.streamSource)}disconnectedCallback(){if(this.streamSource)this.streamSource.close(),qt(this.streamSource)}get src(){return this.getAttribute("src")||""}}L.delegateConstructor=Ht;if(customElements.get("turbo-frame")===void 0)customElements.define("turbo-frame",L);if(customElements.get("turbo-stream")===void 0)customElements.define("turbo-stream",Ce);if(customElements.get("turbo-stream-source")===void 0)customElements.define("turbo-stream-source",Ot);(()=>{let e=document.currentScript;if(!e)return;if(e.hasAttribute("data-turbo-suppress-warning"))return;e=e.parentElement;while(e){if(e==document.body)return console.warn(je`
45
+ You are loading Turbo from a <script> element inside the <body> element. This is probably not what you meant to do!
46
+
47
+ Load your application’s JavaScript bundle inside the <head> element instead. <script> elements in <body> are evaluated with each page change.
48
+
49
+ For more information, see: https://turbo.hotwired.dev/handbook/building#working-with-script-elements
50
+
51
+ ——
52
+ Suppress this warning by adding a "data-turbo-suppress-warning" attribute to: %s
53
+ `,e.outerHTML);e=e.parentElement}})();window.Turbo={...mr,StreamActions:Bt};kt();export{O as FetchEnctype,E as FetchMethod,z as FetchRequest,ae as FetchResponse,L as FrameElement,_ as FrameLoadingStyle,ue as FrameRenderer,de as PageRenderer,T as PageSnapshot,Bt as StreamActions,Ce as StreamElement,Ot as StreamSourceElement,ir as cache,cr as clearCache,S as config,It as connectStreamSource,qt as disconnectStreamSource,et as fetch,vs as fetchEnctypeFromString,we as fetchMethodFromString,ye as isSafe,nr as navigator,or as registerAdapter,lr as renderStreamMessage,g as session,ur as setConfirmMethod,dr as setFormMode,hr as setProgressBarDelay,kt as start,ar as visit};
54
+ //# sourceMappingURL=turbo.map