rage-pulse 0.1.0

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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 3f8c1e37c4b45343f052ffc5d7ddfbb8902ec96b29c67e91916b5de697d28b25
4
+ data.tar.gz: 3edbd204b83490a6140648bc537e8810b91d6aff892f9554efe9a3c24e24968e
5
+ SHA512:
6
+ metadata.gz: 2ed45c0df23d75e5cf492eb9be941f9978c55d443e634863684ef6fe23674e51f0ec51e76ae182b958d9eb8b81ec756640eedfb6f3f21bfd7b78eac82bf30660
7
+ data.tar.gz: bab77386e29cf4e55d8c8e8d4dec17271d3b0ab872ee088ee40d744a4123ecb476ca075c032ebc635e066a4b8360843fbf480723d0fbd6134db872528eaa2849
data/.dockerignore ADDED
@@ -0,0 +1,6 @@
1
+ # flyctl launch added from .gitignore
2
+ **/Gemfile.lock
3
+ **/.DS_Store
4
+ **/storage
5
+ **/.claude
6
+ fly.toml
data/.standard.yml ADDED
@@ -0,0 +1,2 @@
1
+ ignore:
2
+ - demo/**/*
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.1.0] - 2026-11-24
4
+
5
+ - Initial release
@@ -0,0 +1,10 @@
1
+ # Code of Conduct
2
+
3
+ "pulse" follows [The Ruby Community Conduct Guideline](https://www.ruby-lang.org/en/conduct) in all "collaborative space", which is defined as community communications channels (such as mailing lists, submitted patches, commit comments, etc.):
4
+
5
+ * Participants will be tolerant of opposing views.
6
+ * Participants must ensure that their language and actions are free of personal attacks and disparaging personal remarks.
7
+ * When interpreting the words and actions of others, participants should always assume good intentions.
8
+ * Behaviour which can be reasonably considered harassment will not be tolerated.
9
+
10
+ If you have any concerns about behaviour within this project, please contact us at ["2270393+rsamoilov@users.noreply.github.com"](mailto:"2270393+rsamoilov@users.noreply.github.com").
data/Dockerfile ADDED
@@ -0,0 +1,42 @@
1
+ ARG RUBY_VERSION=3.3.10
2
+ FROM ruby:$RUBY_VERSION-slim as base
3
+
4
+ # Rack app lives here
5
+ WORKDIR /app
6
+
7
+ # Update gems and bundler
8
+ RUN gem update --system --no-document && \
9
+ gem install -N bundler
10
+
11
+
12
+ # Throw-away build stage to reduce size of final image
13
+ FROM base as build
14
+
15
+ # Install packages needed to build gems
16
+ RUN apt-get update -qq && \
17
+ apt-get install --no-install-recommends -y build-essential git libyaml-dev
18
+
19
+ # Install application gems
20
+ COPY Gemfile* .
21
+ RUN bundle install
22
+
23
+
24
+ # Final stage for app image
25
+ FROM base
26
+
27
+ # Run and own the application files as a non-root user for security
28
+ RUN useradd ruby --home /app --shell /bin/bash
29
+ USER ruby:ruby
30
+
31
+ # Copy built artifacts: gems, application
32
+ COPY --from=build /usr/local/bundle /usr/local/bundle
33
+ COPY --from=build --chown=ruby:ruby /app /app
34
+
35
+ # Copy application code
36
+ COPY --chown=ruby:ruby . .
37
+
38
+ RUN RAGE_ENV=production bundle exec rage db:setup
39
+
40
+ # Start the server
41
+ EXPOSE 8080
42
+ CMD ["bundle", "exec", "rage", "s", "-b", "0.0.0.0", "-p", "8080", "-e", "production"]
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2026 Roman Samoilov
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,353 @@
1
+ # Pulse
2
+
3
+ Stateful, reactive, server-rendered views for Ruby, built with [Phlex](https://github.com/yippee-fun/phlex) and [Rage](https://github.com/rage-rb/rage).
4
+
5
+ > [!NOTE]
6
+ > **Pulse is in active development. Its API may change.**
7
+
8
+ Pulse keeps Phlex component instances alive for the lifetime of a WebSocket connection. Browser events call ordinary Ruby methods, transient UI state stays in the component, and updates are rendered as HTML and morphed into the page.
9
+
10
+ ```ruby
11
+ # app/controllers/articles_controller.rb
12
+ class ArticlesController < ApplicationController
13
+ def show
14
+ article = Article.find(params[:id])
15
+ render phlex: Articles::Card, article: article # <-- render the component
16
+ end
17
+ end
18
+
19
+ # app/views/articles/card.rb
20
+ class Articles::Card < Pulse::Component
21
+ def initialize(article:)
22
+ @article = article
23
+ @expanded = false
24
+ end
25
+
26
+ def view_template
27
+ div do
28
+ button(click: :toggle_details) do # <-- set up the event handler
29
+ @expanded ? "Show less" : "Show more"
30
+ end
31
+
32
+ p { @expanded ? @article.body : @article.body.truncate(150) }
33
+ end
34
+ end
35
+
36
+ def toggle_details
37
+ @expanded = !@expanded # <-- update local state and re-render
38
+ end
39
+ end
40
+ ```
41
+
42
+ Clicking the button calls `toggle_details` on that exact `Articles::Card` instance, then Pulse re-renders and patches the component in place. `@expanded` is a plain instance variable: it stays in the component for as long as the user keeps the page open.
43
+
44
+ No database column, query parameter, JSON API, or hand-written JavaScript is needed to remember whether the article is expanded.
45
+
46
+ ## Why Pulse?
47
+
48
+ - **State is instance variables.** Instance variables hold the state, and public methods handle events.
49
+ - **Views are Phlex components.** Composition, inheritance, private methods, and ordinary Ruby all work as expected.
50
+ - **One fiber per connection.** Rage runs each WebSocket connection in its own fiber. Components live in that fiber.
51
+ - **Works with your controllers.** Links and forms still go to regular controller actions. Use components for view logic and controllers for business logic, or build everything in components. Both work.
52
+
53
+ Pulse preserves standard Phlex syntax. Event handlers are element attributes such as `click: :toggle`, and `key:` is available when rendering nested components whose identity must survive a parent re-render.
54
+
55
+ ## Quick start
56
+
57
+ ### Add the client to the page
58
+
59
+ Call `pulse_scripts` once in the component that renders the full HTML document:
60
+
61
+ ```ruby
62
+ class Layout < Pulse::Component
63
+ def view_template
64
+ doctype
65
+
66
+ html do
67
+ head do
68
+ title { "My application" }
69
+ end
70
+
71
+ body do
72
+ main { yield }
73
+ pulse_scripts
74
+ end
75
+ end
76
+ end
77
+ end
78
+ ```
79
+
80
+ The helper loads Pulse's fingerprinted client bundle. The client opens the WebSocket, enhances same-origin navigation, and applies HTML updates from the server.
81
+
82
+ ### Render a component from a controller
83
+
84
+ Pulse uses Rage's `phlex` renderer:
85
+
86
+ ```ruby
87
+ class ArticlesController < ApplicationController
88
+ def index
89
+ render phlex: Articles::Index, articles: Article.order(id: :desc)
90
+ end
91
+ end
92
+ ```
93
+
94
+ The rendered class can compose a layout and other components in normal Phlex code:
95
+
96
+ ```ruby
97
+ class Articles::Index < Pulse::Component
98
+ def initialize(articles:)
99
+ @articles = articles
100
+ end
101
+
102
+ def view_template
103
+ render Layout.new do
104
+ div do
105
+ h1 { "Articles" }
106
+
107
+ @articles.each do |article|
108
+ render Articles::Card.new(article: article), key: article.id
109
+ end
110
+ end
111
+ end
112
+ end
113
+ end
114
+ ```
115
+
116
+ ## Components and events
117
+
118
+ Event handlers are public methods defined on a `Pulse::Component`. After a handler returns, Pulse automatically replaces that component unless the handler performed another targeted update itself.
119
+
120
+ ```ruby
121
+ class Search < Pulse::Component
122
+ def initialize
123
+ @query = ""
124
+ end
125
+
126
+ def view_template
127
+ input(
128
+ type: "search",
129
+ value: @query,
130
+ input: :set_query,
131
+ placeholder: "Search articles…"
132
+ )
133
+ end
134
+
135
+ def set_query(event)
136
+ @query = event.value
137
+ end
138
+ end
139
+ ```
140
+
141
+ Pulse supports `click`, `input`, `change`, `submit`, `keydown`, and `keyup` handlers. A handler can take an optional event argument:
142
+
143
+ ```ruby
144
+ def search(event)
145
+ @query = event.value
146
+ end
147
+ ```
148
+
149
+ | Method | Returns |
150
+ | ------------------- | --------------------------------------------- |
151
+ | `event.value` | the element's value |
152
+ | `event.checked?` | whether a checkbox or radio is checked |
153
+ | `event.form_data` | parsed form fields |
154
+
155
+ ## Controllers, links, and forms
156
+
157
+ Business operations don't have to live in components. Same-origin links and forms are sent through the WebSocket and dispatched to the same Rage routes and controllers as ordinary HTTP requests.
158
+
159
+ ```ruby
160
+ # app/controllers/articles_controller.rb
161
+ class ArticlesController < ApplicationController
162
+ def create
163
+ article = Article.create!(title: params[:title], body: params[:body])
164
+ redirect_to "/articles/#{article.id}"
165
+ end
166
+ end
167
+
168
+ # app/views/articles/create.rb
169
+ class Articles::Create < Pulse::Component
170
+ def view_template
171
+ render Layout.new do
172
+ div do
173
+ h1 { "New article" }
174
+
175
+ form(method: "post", action: "/articles") do # <-- goes to ArticlesController#create
176
+ label(for: "title") { "Title" }
177
+ input(type: "text", id: "title", name: "title")
178
+
179
+ label(for: "body") { "Body" }
180
+ textarea(id: "body", name: "body")
181
+
182
+ button(type: "submit") { "Create article" }
183
+ end
184
+ end
185
+ end
186
+ end
187
+ end
188
+ ```
189
+
190
+ The controller doesn't know anything about Pulse. It reads `params`, does its job, then renders or redirects as usual, and Pulse updates the page without a full reload.
191
+
192
+ ## Nested components and keys
193
+
194
+ Pulse can preserve unchanged nested component instances when their parent re-renders. When rendering multiple components of the same class, pass a stable `key` to `render` so Pulse can associate each new declaration with the existing component:
195
+
196
+ ```ruby
197
+ class Articles::MostViewed < Pulse::Component
198
+ def initialize(articles:)
199
+ @articles = articles
200
+ end
201
+
202
+ def view_template
203
+ div do
204
+ @articles.each do |article|
205
+ render Articles::Card.new(article: article), key: article.id
206
+ end
207
+ end
208
+ end
209
+ end
210
+ ```
211
+
212
+ ## Shared state
213
+
214
+ Use `Pulse::Store` to share state between components. Components that `watch` a store re-render automatically when it changes:
215
+
216
+ ```ruby
217
+ # app/stores/theme_store.rb
218
+ class ThemeStore < Pulse::Store
219
+ attribute :value, default: "light"
220
+
221
+ def toggle
222
+ self.value = value == "light" ? "dark" : "light"
223
+ end
224
+ end
225
+
226
+ # app/views/layout.rb
227
+ class Layout < Pulse::Component
228
+ def initialize
229
+ @theme = watch(ThemeStore)
230
+ end
231
+
232
+ def view_template
233
+ doctype
234
+ html do
235
+ body do
236
+ render Navbar.new
237
+ main(class: "theme-#{@theme.value}") do # <-- read the value
238
+ yield
239
+ end
240
+ pulse_scripts
241
+ end
242
+ end
243
+ end
244
+ end
245
+
246
+ # app/views/navbar.rb
247
+ class Navbar < Pulse::Component
248
+ def initialize
249
+ @theme = watch(ThemeStore)
250
+ end
251
+
252
+ def view_template
253
+ nav { button(click: :toggle_theme) { "Toggle theme" } }
254
+ end
255
+
256
+ def toggle_theme
257
+ @theme.toggle # <-- update the value
258
+ end
259
+ end
260
+ ```
261
+
262
+ Clicking the button in `Navbar` re-renders both `Navbar` and `Layout`. Each connection gets its own store instance, so one user's theme doesn't affect other users.
263
+
264
+ ### Live model updates
265
+
266
+ `watch` also works with Active Record models. Call `Pulse.broadcast` when a model changes, and every component watching that record re-renders:
267
+
268
+ ```ruby
269
+ # app/models/article.rb
270
+ class Article < ApplicationRecord
271
+ after_commit :broadcast_upvotes, if: :saved_change_to_upvotes?
272
+
273
+ private
274
+
275
+ def broadcast_upvotes
276
+ Pulse.broadcast(self)
277
+ end
278
+ end
279
+
280
+ # app/views/articles/card.rb
281
+ class Articles::Card < Pulse::Component
282
+ def initialize(article:)
283
+ @article = watch(article)
284
+ end
285
+
286
+ def view_template
287
+ div do
288
+ h1 { @article.title }
289
+ p { @article.body }
290
+ p { "Upvotes: #{@article.upvotes}" }
291
+ end
292
+ end
293
+ end
294
+ ```
295
+
296
+ Pulse reloads the record and re-renders every connected component watching it. `watch` also accepts a block that runs with the reloaded record before the component is replaced:
297
+
298
+ ```ruby
299
+ @article = watch(article) do |article|
300
+ @flash = "#{article.title} was updated"
301
+ end
302
+ ```
303
+
304
+ ## The page object
305
+
306
+ Components can inspect the current page, update query parameters and local storage, or navigate through the live connection:
307
+
308
+ ```ruby
309
+ page.query[:theme] = "dark"
310
+ page.local_storage[:theme] = "dark"
311
+ page.navigate("/articles")
312
+ ```
313
+
314
+ | Method | Description |
315
+ | --------------------- | ------------------------------------------------------------- |
316
+ | `page.path` | the current path |
317
+ | `page.url` | the current path with the query string |
318
+ | `page.query` | query parameters; writing to it updates the URL |
319
+ | `page.local_storage` | browser local storage, kept across page loads and reconnects |
320
+ | `page.navigate(url)` | navigates to `url` |
321
+
322
+ ## Targeted updates
323
+
324
+ An event normally ends with an automatic `replace`, but components can choose another operation:
325
+
326
+ ```ruby
327
+ replace # re-render this component in place
328
+ append(to: "#notifications") # add to the end of the matching element
329
+ prepend(to: "#notifications") # add to the start of the matching element
330
+ remove # remove this component from the page
331
+ ```
332
+
333
+ ## Demo
334
+
335
+ The application in `demo/` is a small article CMS demonstrating controller-backed forms, transient state, stores, model broadcasts, keyed nested components, and targeted updates.
336
+
337
+ ```sh
338
+ rake install
339
+ cd demo
340
+ bundle install
341
+ rage db:prepare
342
+ rage s
343
+ ```
344
+
345
+ Open `http://localhost:3000` in two tabs. Expanding an article is local to each connection, while publishing or unpublishing it persists to the database and broadcasts to the other tab.
346
+
347
+ ## Contributing
348
+
349
+ Bug reports, design feedback, and pull requests are welcome. Because Pulse is still experimental, please open an issue before investing in a large change so the approach can be discussed first.
350
+
351
+ ## License
352
+
353
+ Pulse is available under the [MIT License](LICENSE.txt).
data/Rakefile ADDED
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ require "standard/rake"
9
+
10
+ JAVASCRIPT_BUNDLE = "lib/pulse/assets/pulse.min.js"
11
+ JAVASCRIPT_INPUTS = Rake::FileList[
12
+ "js/src/**/*.ts",
13
+ "js/package.json",
14
+ "js/package-lock.json",
15
+ "js/tsconfig.json"
16
+ ]
17
+
18
+ file JAVASCRIPT_BUNDLE => JAVASCRIPT_INPUTS do
19
+ mkdir_p File.dirname(JAVASCRIPT_BUNDLE)
20
+
21
+ Dir.chdir("js") do
22
+ sh "npm", "ci"
23
+ sh "npm", "run", "build"
24
+ end
25
+ end
26
+
27
+ task build: JAVASCRIPT_BUNDLE
28
+
29
+ # make `rake clean` remove the bundle
30
+ CLEAN.include(JAVASCRIPT_BUNDLE)
31
+
32
+ task default: %i[spec standard]
data/fly.toml ADDED
@@ -0,0 +1,22 @@
1
+ # fly.toml app configuration file generated for phlex-live-eae0373a0ce7 on 2026-04-20T14:35:24+01:00
2
+ #
3
+ # See https://fly.io/docs/reference/configuration/ for information about how to use this file.
4
+ #
5
+
6
+ app = 'phlex-live-eae0373a0ce7'
7
+ primary_region = 'lhr'
8
+
9
+ [build]
10
+
11
+ [http_service]
12
+ internal_port = 8080
13
+ force_https = true
14
+ auto_stop_machines = "suspend"
15
+ auto_start_machines = true
16
+ min_machines_running = 0
17
+ processes = ['app']
18
+
19
+ [[vm]]
20
+ memory = '512mb'
21
+ cpus = 1
22
+ memory_mb = 512
@@ -0,0 +1,3 @@
1
+ "use strict";(()=>{function Mt(){return window.location.pathname+window.location.search}function ke(t,e=window.location.href){let n=new URL(t,e);return n.protocol==="http:"?n.protocol="ws:":n.protocol==="https:"&&(n.protocol="wss:"),n.href}function be(){return{query:window.location.search.slice(1),hash:window.location.hash}}var Yn=1e3,zn="/__pulse/cable/view",It=class{options;socket=null;reconnectTimer=null;stopped=!1;constructor(e){this.options=e}get isOpen(){return this.socket?.readyState===WebSocket.OPEN}connect(){this.stopped=!1;let e=new WebSocket(ke(zn));this.socket=e,e.addEventListener("open",()=>this.options.onOpen()),e.addEventListener("message",n=>this.receive(n.data)),e.addEventListener("close",()=>{this.socket===e&&(this.socket=null,this.scheduleReconnect())})}send(e){return!this.socket||!this.isOpen?!1:(this.socket.send(JSON.stringify(e)),!0)}close(){this.stopped=!0,this.reconnectTimer&&(clearTimeout(this.reconnectTimer),this.reconnectTimer=null);let e=this.socket;this.socket=null,e?.close()}scheduleReconnect(){this.stopped||(this.reconnectTimer=setTimeout(()=>{this.reconnectTimer=null,this.connect()},Yn))}receive(e){let n;try{n=JSON.parse(String(e))}catch{console.error("[pulse] Ignoring malformed message",e);return}this.options.onMessage(n)}};var le=typeof Element<"u"&&"moveBefore"in Element.prototype,an="HTMLSelectedContentElement"in globalThis,at=1,ae=3,qt=9,un=11,B="http://www.w3.org/1999/xhtml",jn="http://www.w3.org/2000/svg",Xn="http://www.w3.org/1998/Math/MathML",ie="morphlex-clobber",Z="morphlex-dirty",Zn=1<<20,Oe="[Morphlex] Cannot replace a detached node. It needs a parent.",Qn=[[!1,!0,!0,!0],[!1,!0,!0,!1],[!1,!0,!1,!0],[!1,!0,!1,!1],[!1,!1,!0,!0],[!1,!1,!0,!1],[!1,!1,!1,!0],[!1,!1,!1,!1],[!0,!0,!0,!0],[!0,!0,!0,!1],[!0,!0,!1,!0],[!0,!0,!1,!1],[!0,!1,!0,!0],[!0,!1,!0,!1],[!0,!1,!1,!0],[!0,!1,!1,!1]],Te=["class","style"],ti=["open"],ei=new Set(["src","href","srcdoc"]),ni=new Set(["script","source"]),$={EqualNode:0,SameElement:1,SameNode:2};function hn(t,e,n){typeof e=="string"&&(e=Sn(e)),ue($t(t),$t(e),n)}function ue(t,e,n={}){typeof e=="string"&&(e=Ei(t,e)),ii(t,e,si(e),n,i=>i.morph(t,e))}var Gt=[];function ii(t,e,n,i,s){let o=st(t),r=Gt.flat().filter(a=>X(a,Z)),c=[];Gt.push(c);try{Ft(t)&&oi(t,i.preserveChanges?e:null,c);let a=new Ti(i,n,c,N(t)&&U(t)?t:o);o&&a.setEnclosingSelect(o,yn(o)),s(a)}finally{Gt.pop(),mi(c);for(let a of r)X(a,Z)||ye(a,Z,"")}}function si(t){let e=null,n=ge(t)?t:[t];for(let i=0;i<n.length;i++){let s=n[i];if(_(s)!==at)continue;let o=s;Ce(o)&&(e??=new Set).add(o);for(let r of x(o,`[${ie}], [${Z}]`))Ce(r)&&(e??=new Set).add(r)}return e}function Ce(t){return At(t,Z),X(t,ie)?(At(t,ie),!0):!1}function oi(t,e,n){let i=null,s=[],o=[...x(t,e?"input, option, textarea, details, dialog":"input, option, textarea")];N(t)&&o.unshift(t);for(let r of o){let c=!1;me(r)?s.push(r):F(r)?c=fn(r):G(r)?(i??=fi(t),c=li(r,i)):dt(r)&&(c=mn(r)),c&&Me(r,n)}if(e&&s.length){let r=new Set,c=new Set;for(let u of s)(ot(u,null,"open")?r:c).add(O(u));let a=[];for(let u of ge(e)?e:[e])_(u)===at&&a.push(u);let h=u=>a.some(d=>ve(d,u)||St(d,u)!==null),l=[...new Set([...r,...c])].filter(u=>(r.has(u)||h(`${u}[open]`))&&(c.has(u)||h(`${u}:not([open])`)));for(let u of s)l.includes(O(u))&&Me(u,n)}}function Me(t,e){e.push(t),ye(t,Z,"")}function fn(t){return t.type==="checkbox"||t.type==="radio"?t.checked!==t.defaultChecked:t.value!==t.defaultValue&&pn(t)}var Ie=null;function dn(t){return Ie??=Wi(t.ownerDocument).createHTMLDocument(""),Ie.importNode(t)}function pn(t){if(t.type==="file")return t.value!=="";let e=dn(t);e.type="text";let n=e.value==="a"?"b":"a";return e.defaultValue=n,e.value!==n}var ri=["min","max","step","multiple"];function ci(t,e,n,i){if(pn(t))return!1;if(ri.some(o=>t.getAttribute(o)!==L(e,o)))return!0;let s=dn(t);return Le(s,n),s.value!==i?!1:(Le(t,n),!0)}function Le(t,e){e===null?(t.setAttribute("value",""),t.removeAttribute("value")):t.setAttribute("value",e)}function mn(t){return t.value!==t.defaultValue.replace(/\r\n?/g,`
2
+ `)}function li(t,e){let n=e.get(t);return n===void 0?t.selected!==t.defaultSelected:t.selected!==(t===n)}function he(t){let e=t.options,n=null;for(let i=e.length-1;i>=0;i--){let s=e[i];if(s.hasAttribute("selected"))return s;ui(s)||(n=s)}return fe(t)>1?null:n??(ai(t.ownerDocument)?e[0]??null:null)}var Jt;function ai(t){if(Jt===void 0){let e=kt(t,"select"),n=kt(t,"option");n.disabled=!0,e.append(n),Jt=e.selectedIndex===0}return Jt}function De(t){return!t.multiple&&fe(t)<=1}function fe(t){let e=/^[\t\n\f\r ]*\+?(\d+)/.exec(t.getAttribute("size")??"");return e?Number(e[1]):1}function ui(t){if(t.disabled)return!0;for(let e=t.parentElement;!U(e);e=D(e))if(O(e)==="optgroup"&&T(e)===B)return e.disabled;return!1}function hi(t,e){if(_(t)!==at||_(e)!==at||Ut(t)&&lt(t)===lt(e))return;let n=t;if(U(n)||!G(n)&&!Nt(n)||!U(e)&&!st(e))return;let i=null;if(G(n)?Re(n)&&(i=[n]):gn(n,s=>{Re(s)&&(i??=[]).push(s)}),!!i){xt(n);for(let s of i)s.selected=!1}}function Re(t){return t.selected&&!t.hasAttribute("selected")}function gn(t,e){for(let n=Nt(t);n;n=In(n))G(n)?e(n):U(n)||gn(n,e)}function En(t,e){return U(t)||!St(t,"option")?!1:st(t)!==e}function Yt(t){return N(t)&&U(t)?t:st(t)}function st(t){for(let e=D(t);e;e=D(e))if(U(e))return e;return null}function fi(t){let e=new Map,n=st(t);n&&zt(e,n),N(t)&&U(t)&&zt(e,t);for(let i of x(t,"select"))U(i)&&zt(e,i);return e}function zt(t,e){let n=e.multiple?void 0:he(e);for(let i of e.options)t.set(i,n)}function yn(t){return t.multiple?[...Array.from(t.options).filter(e=>e.hasAttribute("selected")),null,...t.selectedOptions]:[he(t),t.options[t.selectedIndex]??null]}var de=new WeakSet,vn=!1;typeof document<"u"&&EventTarget.prototype.addEventListener.call(document,"input",t=>{let e=t.composedPath()[0],n=D(e);!t.isTrusted||!Ht(e)||n instanceof HTMLElement&&Ht(n)||(de.add(e),vn=!0)},!0);function xe(t){if(!vn)return null;for(let e=t;e;e=D(e)){if(de.has(e))return e;if(T(e)===B&&!Ht(e))return null}return null}function Pe(t){let e=_t(J(t));return!e||e.shadowRoot?.activeElement?null:T(e)===B&&Ht(e)?e:null}function di(t){if(!an||!wn(t))return!1;let e=st(t);return e!==null&&!e.multiple}function wn(t){return O(t)==="selectedcontent"&&T(t)===B}function pi(t,e){let n=et(t),i=e&&et(e);for(;n&&i;n=W(n),i=W(i))if(!z(n,i))return!1;return n===i}function mi(t){for(let e=0;e<t.length;e++)At(t[e],Z)}var gi=new Set(["script","style","textarea","title","xmp","iframe","noembed","noframes","noscript","plaintext"]);function Ei(t,e){if(N(t)&&T(t)===B){let s=O(t);if(s==="html"||s==="head"||s==="body"){let o=Sn(e);return s==="html"?$t(o):s==="head"?Ki(o):Ee(o)}}let n=R(t);if(n&&N(n)&&T(n)===B&&gi.has(O(n))){let s=kt(document,O(n));return Pt(s,e),s.childNodes}let i=vi(e,yi(t));return xi(i),i.childNodes}function yi(t){let e=R(t);if(e&&N(e))return T(e)===B?null:e;let n=N(t)?T(t):null;return n===jn?cn(document,n,"svg"):n===Xn?cn(document,n,"math"):null}function vi(t,e=null){let n=kt(document,"template");if(e){let i=ji(n.content.ownerDocument,e);for(Pt(i,t);i.firstChild;)n.content.appendChild(i.firstChild)}else Pt(n,t);return wi()||pe(n.content),n.content}function Pt(t,e){t.setHTMLUnsafe?t.setHTMLUnsafe(e):t.innerHTML=e}function Sn(t){let e=Ri(t),n=Document.parseHTMLUnsafe?Document.parseHTMLUnsafe(e):new DOMParser().parseFromString(e,"text/html");return pe(n),n}var jt;function wi(){if(jt===void 0){let t=kt(document,"template");Pt(t,"<noscript><p></p></noscript>"),jt=_(t.content.firstChild.firstChild)===ae}return jt}function pe(t){let e=x(t,"noscript");for(let i=0;i<e.length;i++){let s=e[i];T(s)===B&&(s.textContent=s.innerHTML)}let n=x(t,"template");for(let i=0;i<n.length;i++){let s=n[i];it(s)&&pe(s.content)}}function Si(t,e,n){if(e!==n){if(R(e)===t){if(W(e)===n)return;if(le){Vt(t).moveBefore.call(t,e,n);return}}wt(t,e,n)}}function Nn(t){if(!N(t)||!ct(t)&&!Nt(t))return null;let e=null,n=ct(t)?[t]:Et(t,"form");for(let i=0;i<n.length;i++){let s=n[i];b(s)!==""&&ct(s)&&(e??=new Set).add(b(s))}return e}function Xt(t){let e=Nn(t);if(!e)return null;let n=null,i=x(J(t),'input[form][name]:not([name=""])');for(let s=0;s<i.length;s++){let o=i[s];ut(o)&&e.has(L(o,"form"))&&((n??=[]).push([o,L(o,"name")]),At(o,"name"))}return n}function Zt(t){if(t)for(let[e,n]of t)ye(e,"name",n)}var Lt=new WeakMap;function _e(t,e,n){if(le&&Ut(e)&&Ut(t))try{Vt(t).moveBefore.call(t,e,n);return}catch{}wt(t,e,n)}function An(t){let e=_t(J(t));if(!e)return null;let n=lt(e);if(e===Ee(n)&&!e.isContentEditable)return null;for(;e.shadowRoot?.activeElement;)e=e.shadowRoot.activeElement;let i=null,s=null;if((F(e)||dt(e))&&e.selectionStart!==null)i=[e.selectionStart,e.selectionEnd,e.selectionDirection];else{let{anchorNode:o,anchorOffset:r,focusNode:c,focusOffset:a}=Rn(n)??{};o&&c&&P(e,o)&&P(e,c)&&(s=[o,r,c,a])}return{element:e,selection:i,range:s,taken:!1,document:n}}function Ni(t){let e=An(t);return e&&kn(e).has(t)?e:null}function Be(t){let e=An(t);if(!e)return null;let n=kn(e);return n.has(t)?n:null}function kn({element:t,range:e}){let n=new Set;for(let i of e?[t,e[0],e[2]]:[t])for(let s=i;s;s=ki(s))n.add(s);return n}function Fe(t){let{element:e,selection:n,range:i}=t,s=J(e),o=lt(e);if(_t(s)!==e){if(t.taken||!He(o))return!1;if(Ai(e),_t(s)!==e)return!t.taken&&He(o)}try{if(n){let r=e,[c,a,h]=n;(r.selectionStart!==c||r.selectionEnd!==a||r.selectionDirection!==h)&&r.setSelectionRange(c,a,h)}else i&&P(e,i[0])&&P(e,i[2])&&(Ji(e),Rn(o).setBaseAndExtent(...i))}catch{}return!1}function Ai(t){let e=t;for(let n=Object.getPrototypeOf(t);n;n=Object.getPrototypeOf(n))Object.hasOwn(n,"focus")&&(e=n);Reflect.apply(Reflect.get(e,"focus"),t,[{preventScroll:!0}])}function He(t){let e=Ln(t);return e===null||e===(Ee(t)??$t(t))}function _t(t){return _(t)===qt?Ln(t):t.activeElement??null}function ki(t){return R(t)??(_(t)===un?t.host:null)}var bi=class{from;to;candidateNodes=[];candidateElements=[];candidateElementsById=new Map;whitespace=[];unmatchedNodes=[];unmatchedElements=[];candidateActive;unmatchedActive;matches=[];op=[];dirtyCandidatesByShape=null;displaced=[];#e=new Map;#t;choices=null;#n=[];#i=[];#h=[];#f=[];shapeOf(t){let e=this.#e.get(t);return e===void 0&&this.#e.set(t,e=re(t,this.#t)),e}constructor(t,e,n){this.#t=n,this.from=We(pt(t)),this.to=We(pt(e)),this.candidateActive=new Uint8Array(this.from.length),this.unmatchedActive=new Uint8Array(this.to.length);for(let i=0;i<this.from.length;i++){let s=this.from[i];if(N(s)){this.candidateActive[i]=1,this.#n[i]=O(s),this.#i[i]=T(s);let o=b(s);o===""?this.candidateElements.push(i):nt(this.candidateElementsById,o,i)}else rt(s)?this.whitespace.push(i):(this.candidateActive[i]=1,this.candidateNodes.push(i))}for(let i=0;i<this.to.length;i++){let s=this.to[i];N(s)?(this.unmatchedActive[i]=1,this.#h[i]=O(s),this.#f[i]=T(s),this.unmatchedElements.push(i)):rt(s)||(this.unmatchedActive[i]=1,this.unmatchedNodes.push(i))}}sameKind(t,e){return this.#h[t]===this.#n[e]&&this.#f[t]===this.#i[e]}manyPairs(){let{candidateElements:t,unmatchedElements:e,candidateActive:n,unmatchedActive:i}=this;if(t.length*e.length<=1024)return null;let s=t.filter(r=>n[r]),o=0;for(let r of e)o+=i[r];return s.length*o>1024?s:null}take(t,e,n){this.matches[t]=e,this.op[t]=n,this.candidateActive[e]=0,this.unmatchedActive[t]=0}},Oi=class{owners=new Map;#e;#t;#n;#i;#h;#f=[];#w=[];#l=new Map;#A=new Map;#E=new Set;#d=new Set;#c=[];constructor(t,e,n,i){this.#e=t,this.#t=new Map(t.map((s,o)=>[s,o])),this.#n=e,this.#i=n,this.#h=i}#a(t){let e=this.#f[t];if(!e){e=this.#f[t]=this.#i(t);for(let n of e)this.#l.has(n)||this.#l.set(n,this.#l.size)}return e}#o(t){return this.#w[t]??=this.#h(t)}assignFree(t){let e=this.#a(t);if(!e.length)return;let n=this.#o(t),i=this.#A.get(n);i||this.#A.set(n,i=new Map);let s=[];for(let r of e){let c=i.get(r)??0;for(;c<r.length&&this.owners.has(r[c]);)c++;s.push(c)}let o=!1;for(;!o;){let r;for(let c=0;c<e.length;c++){let a=e[c][s[c]];a!==void 0&&(r===void 0||this.#t.get(a)<this.#t.get(r))&&(r=a)}if(r===void 0)break;for(let c=0;c<e.length;c++)e[c][s[c]]===r&&(s[c]=s[c]+1);this.owners.has(r)||!this.#n(t,r)||(this.owners.set(r,t),o=!0)}for(let r=0;r<e.length;r++)i.set(e[r],s[r]);o||this.#c.push(t)}assignRest(){for(let t of this.#c){if(this.owners.size===this.#e.length)break;this.#s(t)}}#s(t){let e=`${this.#o(t)} ${this.#a(t).map(r=>this.#l.get(r)).join(" ")}`;if(this.#d.has(e))return;let n=new Map,i=new Map,s=new Set,o=[t];for(let r=0;r<o.length;r++){let c=o[r];for(let a of this.#a(c)){let h=`${this.#o(c)} ${this.#l.get(a)}`;if(!s.has(h)){s.add(h);for(let l of a){if(n.has(l)||this.#E.has(l)||!this.#n(c,l))continue;n.set(l,c);let u=this.owners.get(l);if(u!==void 0){i.set(u,l),o.push(u);continue}for(let d=l;d!==void 0;){let f=n.get(d);this.owners.set(d,f),d=i.get(f)}this.#E.clear(),this.#d.clear();return}}}}for(let r of n.keys())this.#E.add(r);this.#d.add(e)}},Ti=class{#e;#t;#n=null;#i=null;#h=null;#f=null;#w=new Set;#l=null;#A=null;#E=null;#d=null;#c;#a=null;#o=null;#s=null;#R=new Set;#x=[];#pt=!1;#mt=new Map;#gt;#z=new Map;#y=new WeakMap;#P=new WeakMap;#p=new Map;#Et=new Map;#yt=new Map;#j=null;#_=null;#B=null;#S=new Map;#F=new Set;#vt=new Map;#X=null;#wt=null;#k=null;#St=!1;#m=null;#H=null;#b=null;#U=!1;#Z=!1;#$=null;#O=!1;#Q=null;#q=null;#T=null;#C=null;#V=null;#tt=null;#K=[];constructor(t={},e=null,n=null,i=null){if(this.#e=t,this.#gt=i,this.#c=e,this.#t=t.preserveChanges??!1,n?.length){let s=new Set;for(let o of n){this.#R.add(o),_i(o)&&this.#x.push(o);for(let r=o;r&&!s.has(r);r=D(r))s.add(r)}this.#s=s}}morph(t,e){this.#n=t,this.#Q=Be(t),this.#q=Pe(t),this.#T=N(t)?xe(t):null,this.#i=R(t)??t,this.#h=Vi(t),this.#f=W(t),this.#l=Bt(R(t)),Ft(t)&&this.#Gt(t);let n=ge(e)?[...e]:[e];for(let i of n)this.#w.add(i),Ft(i)&&this.#Wt(i);this.#O&&en(n),this.#zt(t,n),this.#et()}morphChildren(t,e){this.#n=t,this.#Q=Be(t),this.#q=Pe(t),this.#T=N(t)?xe(t):null,this.#i=t,this.#l=Bt(t),this.#A=e,this.#w.add(e),this.#Gt(t),this.#Wt(e,!1),this.#O&&en(pt(e)),N(t)?this.visitChildNodes(t,e):this.#ie(t,e),this.#et()}#u(t){t===this.#n&&this.#et()}#et(){this.#Yt();let t=this.#j;if(t){for(let h=0;h<t.length;h++){let l=t[h];this.#p.has(b(l))&&this.#J(l,!0)}this.#j=null}let e=this.#_;if(e){for(let h=0;h<e.length;h++){let l=e[h];this.#Pt(l),this.#e.afterNodeRemoved?.(l)}this.#_=null}let n=this.#X;if(n){let h=this.#t;this.#t=!1;for(let l of n)this.#rt(l);this.#t=h,this.#X=null}let i=this.#b;i&&(this.#b=null,this.#Ae(i));let s=this.#H;if(s){this.#H=null;let h=new Map;for(let l of s)l.checked||!(l.hasAttribute("checked")||this.#L(l))||mt(l,h).some(u=>u.checked&&this.#L(u))||(l.checked=!0,(this.#m??=new Set).add(l))}let o=this.#m;o&&(this.#m=null,this.#ke(o));let r=this.#$;r&&(this.#$=null,this.#Jt(r));let c=this.#k?.[0];this.#ve(),c&&this.#It(c);for(let h of this.#z.values())this.#It(h);let a=this.#C;if(a){this.#C=null,ee(a.document,"focusin",this.#ot);let h=this.#V;if(h){this.#V=null;let[l,u]=h,[d,f,p,w]=a.range;a.range=[...sn(a.element,l,d,f),...sn(a.element,u,p,w)]}Fe(a)}}#Jt(t){let e=[];for(let n of t.keys())!ot(n,null,"open")&&this.#I(n)&&e.push(n);e.sort((n,i)=>te(n,i)&Node.DOCUMENT_POSITION_FOLLOWING?-1:1);for(let n of e)tn(n).length===0&&gt(n,null,"open",t.get(n))}#Yt(){for(let t=this.#B;t;t=this.#B){this.#B=null;for(let e=0;e<t.length;e++)this.#$t(t[e])}}#zt(t,e){let n=e.length;if(n===0)this.#J(t);else if(n===1)this.#N(t,e[0]);else{let i=R(t);if(!i)throw new Error(Oe);let[s,...o]=e,r=W(t);for(let c=0;c<o.length;c++)this.#Ut(i,o[c],r);this.#N(t,s)}}#N(t,e){t!==e&&(z(t,e)||this.#nt(t,e,N(t)&&N(e)&&ht(t,e)))}#nt(t,e,n){if(!(this.#e.beforeNodeVisited?.(t,e)??!0)){this.#Y(t);return}n?this.#jt(t,e):!N(t)&&_(t)===_(e)&&t.nodeName===e.nodeName&&t.nodeValue!==null&&e.nodeValue!==null?(t.nodeValue=e.nodeValue,this.#u(t)):this.#Me(t,e),this.#e.afterNodeVisited?.(t,e)}#jt(t,e){let n=this.#t,i=this.#o;n&&this.#c?.has(e)&&(this.#t=!1,this.#o=t),this.#t&&U(t)&&!De(t)&&t.selectedIndex<0&&(this.#wt??=new Set).add(t),(rn(t)||rn(e))&&this.#Xt(t,e),on(t)||on(e)||it(t)?this.visitChildNodes(t,e):dt(t)&&this.#kt(t),this.#u(t),this.#t=n,this.#o=i}#Xt(t,e){At(t,Z);let n=tt(t),i=n?j(t,null,"open"):null,s=this.#t&&me(t),o=vt(e),r=null,c=!0;for(let a=0;a<o.length;a++){let h=o[a];h.namespaceURI===null&&ei.has(h.name)?(h.name==="srcdoc"?(r??=[]).unshift(h):(r??=[]).push(h),j(t,null,h.name)!==h.value&&(c=!1)):this.#Nt(t,h,s,n)||(c=!1)}if(!(c&&vt(t).length===o.length)&&Ci(t,e)){for(let{name:a,localName:h,value:l,namespaceURI:u}of Array.from(vt(t)))if(!ot(e,u,h)){if(s&&a==="open"&&u===null)continue;if(this.#e.beforeAttributeUpdated?.(t,a,null)??!0){if(a==="open"&&u===null&&Tn(t))t.close();else{let d=u?null:this.#Rt(t,a,null);xn(t,u,h),this.#r(d),a==="checked"&&this.#b?.delete(t)}this.#e.afterAttributeUpdated?.(t,a,l)}else this.#Ht(t,a,u)}}if(r)for(let a of r)this.#Nt(t,a,s,n);n&&this.#Qt(t,e,i),this.#t||this.#ne(t,e)}#Nt(t,e,n,i){let{name:s,localName:o,value:r,namespaceURI:c}=e;if(n&&s==="open"&&c===null&&!ot(t,null,"open"))return!1;let a=j(t,c,o);if(a===r)return!0;if(this.#e.beforeAttributeUpdated?.(t,s,r)??!0){let h=c?null:this.#Rt(t,s,r),l=s==="checked"&&c===null&&ut(t)&&!t.checked?Ze(t):null,u=c===null&&(s==="checked"||s==="selected")?this.#At():null,d=Yi(t,c,o);d?d.value=r:i&&s==="open"&&c===null?this.#te(t,r):zi(t,e.cloneNode()),this.#r(h),l&&this.#ct(l,t),u&&Xe(u),this.#e.afterAttributeUpdated?.(t,s,a)}else this.#Ht(t,s,c);return!1}#At(){return!this.#t||(this.#pt||(this.#pt=!0,this.#x.push(...Bi(this.#n))),!this.#x.length)?null:this.#x.filter(t=>bn(t)&&!this.#Zt(t))}#Zt(t){let e=this.#_;if(!e)return!1;for(let n=t;n;n=D(n)){if(this.#S.has(n))return!1;if(e.includes(n))return!0}return!1}#Qt(t,e,n){let i=this.#d?.has(t)??!1,s=j(e,null,"open");i?s=n:this.#t&&(s=n===null?null:s??n),s!==null&&(this.#$??=new Map).set(t,s)}#te(t,e){let n=j(t,null,"name");n&&tn(t).length>0?(gt(t,null,"name",""),gt(t,null,"open",e),gt(t,null,"name",n)):gt(t,null,"open",e)}#ee(t){let e=this.#$??=new Map,n=tt(t)?j(t,null,"open"):null;n!==null&&e.set(t,n);let i=Et(t,"details");for(let s=0;s<i.length;s++){let o=i[s],r=j(o,null,"open");r!==null&&tt(o)&&e.set(o,r)}}#ne(t,e){if(F(t)){let n=X(e,"checked");if(X(t,"checked")===n&&this.#b?.delete(t),t.checked!==n&&X(t,"checked")===n){let r=n&&t.type==="radio"&&t.hasAttribute("form")?Ze(t):null;t.checked=n,r&&this.#ct(r,t),t.type==="radio"&&(this.#m??=new Set).add(t)}else n&&t.type==="radio"&&(this.#m??=new Set).add(t);let i=t.type,s=L(e,"value"),o=e;if(i!=="file"&&i!=="checkbox"&&i!=="radio"&&i===o.type&&L(t,"value")===s){let r=fn(o)?s??"":o.value;t.value!==r&&!ci(t,e,s,r)&&(t.value=r)}}else if(G(t)){let n=X(e,"selected");t.selected!==n&&X(t,"selected")===n&&(t.selected=n,this.#k?.[0].options[t.index]===t&&(this.#St=!0))}}#kt(t){!this.#t&&mn(t)&&(t.value=t.defaultValue)}visitChildNodes(t,e){if(!(this.#e.beforeChildrenVisited?.(t)??!0)){this.#Y(t),this.#u(t);return}de.has(t)&&(this.#T=t);let n=this.#t&&(this.#q!==null&&P(this.#q,t)||this.#T!==null&&P(this.#T,t))&&!this.#g(e);if(n&&this.#Y(t),n||di(t)){this.#u(t),this.#e.afterChildrenVisited?.(t);return}if(it(t)&&it(e)){this.#Ce(t,e),this.#u(t),this.#e.afterChildrenVisited?.(t);return}U(t)&&U(e)&&this.#z.set(e,t);let i=dt(t)?yt(e):null;this.#bt(t,e),dt(t)&&yt(t)===i&&this.#kt(t),U(t)&&this.#rt(t),this.#u(t),this.#e.afterChildrenVisited?.(t)}#ie(t,e){this.#e.beforeChildrenVisited?.(t)??!0?(this.#bt(t,e),this.#u(t),this.#e.afterChildrenVisited?.(t)):(this.#Y(t),this.#u(t))}#bt(t,e){let n=Ke(t),i=n&&Ke(e);if(n&&i&&rt(n)===rt(i))this.#N(n,i);else if(this.#se(t,e)){let s=et(t),o=et(e);z(s,o)||this.#nt(s,o,Rt(s,o))}else{let s=new bi(t,e,this.#t);this.#Ot(s),this.#oe(s),this.#ce(s),this.#le(s,t),this.#ae(s),this.#t&&this.#s&&this.#ue(s),this.#s&&(this.#he(s),this.#re(s)),this.#fe(s),this.#de(s),this.#me(s),this.#ge(s),this.#pe(s);let o=null;for(let r=0;r<s.from.length;r++){if(!s.candidateActive[r])continue;let c=s.from[r],a=this.#J(c);R(c)===t&&(o??=new Map).set(c,a)}this.#Ee(t,s,o)}}#se(t,e){if(this.#s)return!1;let n=Ve(t),i=n&&Ve(e);return!!i&&N(n)&&N(i)&&O(n)===O(i)&&T(n)===T(i)&&Q(n)&&Q(i)}#Ot(t){let{from:e,to:n,candidateElements:i,unmatchedElements:s,candidateActive:o,unmatchedActive:r}=t,c=this.#s,a=i.length*s.length>1024?new qe(t,i):null;for(let h=0;h<s.length;h++){let l=s[h];if(!r[l])continue;let u=n[l],d=i,f=0;if(a){let p=a.get(u);if(p===void 0)continue;d=p,f=a.firstActive(p,o)}for(;f<d.length;f++){let p=d[f];if(!o[p]||!t.sameKind(l,p))continue;let w=e[p];if(!c?.has(w)){if(z(w,u)){t.take(l,p,$.EqualNode);break}a?.fail(d)}}}}#oe(t){let e=this.#s;if(!e)return;let{from:n,to:i,candidateElements:s,unmatchedElements:o,candidateActive:r,unmatchedActive:c}=t,a=t.dirtyCandidatesByShape=Dt(t,s.filter(l=>r[l]&&e.has(n[l]))),h=new Map;for(let l=0;a.size&&l<o.length;l++){let u=o[l];if(!c[u])continue;let d=i[u],f=a.get(t.shapeOf(d));if(!f||this.#g(d))continue;let p=h.get(f)??0;for(;p<f.length&&!r[f[p]];)p++;h.set(f,p);let w=f[p];w!==void 0&&t.take(u,w,$.SameElement)}}#re(t){let{from:e,to:n,candidateElements:i,unmatchedElements:s,candidateActive:o,unmatchedActive:r}=t,c=this.#s,a=new Set,h=new Set;for(let y of[...t.dirtyCandidatesByShape.values(),t.displaced])for(let m of y){if(!o[m])continue;let A=e[m];a.add(ft(A)),h.add(O(A))}if(!h.size)return;let l=new Map;for(let y of i){if(!o[y])continue;let m=e[y];if(!h.has(O(m)))continue;let A=ft(m);a.has(A)&&nt(l,A,y)}let u=[],d=new Map,f=new Set,p=new Map;for(let y of l.values())p.set(y,y.filter(m=>!c.has(e[m])).length);for(let y=0;y<s.length;y++){let m=s[y];if(!r[m])continue;let A=n[m];if(!h.has(O(A)))continue;let g=l.get(ft(A));if(!g||!p.get(g)&&this.#g(A))continue;u.push([m,g]);let S=d.get(g)??0;for(let E=0;E<g.length;E++){let v=g[(S+E)%g.length];if(!f.has(v)&&this.#Tt(A,v,t)){f.add(v),d.set(g,S+1),c.has(e[v])||p.set(g,p.get(g)-1);break}}}for(let[y,m]of d)m>=y.length||y.sort((A,g)=>Number(c.has(e[g]))-Number(c.has(e[A]))||A-g);let w=new Map;for(let[y,m]of u){let A=n[y],g=w.get(m)??0;for(;g<m.length&&!o[m[g]];)g++;w.set(m,g);for(let S=g;S<m.length;S++){let E=m[S];if(o[E]&&this.#Tt(A,E,t)){t.take(y,E,$.SameElement);break}}}}#Tt(t,e,n){let i=n.from[e];return!this.#ut(i,t,n)&&(!this.#s.has(i)||!this.#g(t))&&(Q(t)&&Q(i)||Qe(t,i)&&ht(i,t))}#ce(t){let{to:e,candidateElementsById:n,unmatchedElements:i,candidateActive:s,unmatchedActive:o}=t;for(let r=0;r<i.length;r++){let c=i[r];if(!o[c])continue;let a=b(e[c]);if(a==="")continue;let h=n.get(a);if(h!==void 0)for(let l=0;l<h.length;l++){let u=h[l];if(s[u]&&t.sameKind(c,u)){t.take(c,u,$.SameElement);break}}}}#le(t,e){let{to:n,unmatchedElements:i,unmatchedActive:s}=t;for(let o=0;o<i.length;o++){let r=i[o];s[r]&&this.#Vt(n[r],e)&&(s[r]=0)}}#ae(t){let{from:e,to:n,candidateElements:i,unmatchedElements:s,candidateActive:o,unmatchedActive:r}=t;for(let c=0;c<s.length;c++){let a=s[c];if(!r[a])continue;let h=this.#y.get(n[a]);if(h)t:for(let l=0;l<i.length;l++){let u=i[l];if(!o[u]||!t.sameKind(a,u))continue;let d=this.#P.get(e[u]);if(d){for(let f=0;f<h.length;f++)if(d.has(h[f])){t.take(a,u,$.SameElement);break t}}}}}#ue(t){let{from:e,to:n,candidateElements:i,unmatchedElements:s,candidateActive:o,unmatchedActive:r}=t,c=[];for(let l=0;l<i.length;l++){let u=i[l];if(!o[u])continue;let d=e[u],f=this.#Te(d);f&&(this.#at(d)||Q(d))&&c.push([u,f.choices,f.picked])}if(!c.length)return;c.sort((l,u)=>u[1].length-l[1].length);let a=new Map,h=(l,u,d)=>{if(!d)return u;let f=a.get(l);return f===void 0&&a.set(l,f=oe(l,Te)),`${f}
3
+ ${u}`};for(let[l,u,d,f]of Qn){let p=E=>c[E][f?2:1],w=(E,v)=>{let M=c[E][0];if(!t.sameKind(v,M))return!1;let q=e[M],H=n[v];return Rt(q,H)&&l===(this.#at(q)?this.#y.has(H):!Q(H))&&this.#be(p(E),H,d)},y=s.filter(E=>r[E]);d&&y.sort((E,v)=>this.#D(n[E]).size-this.#D(n[v]).size);let m=new Map;for(let E of y){let v=n[E];for(let M of this.#D(v).counts.keys())nt(m,h(v,M,u),E)}let A=E=>{let v=e[c[E][0]],M=[];for(let q of new Set(p(E))){let H=m.get(h(v,q,u));if(H)M.push(H);else if(d)return[]}return d&&M.length&&(M=[M.reduce((q,H)=>H.length<q.length?H:q)]),M},g=E=>{let v=e[c[E][0]];return JSON.stringify([T(v),O(v),L(v,"is"),this.#at(v),d&&[...p(E)].sort(),u&&h(v,"",!0)])},S=new Oi(y,w,A,g);for(let E=0;E<c.length;E++)o[c[E][0]]&&p(E).length&&S.assignFree(E);S.assignRest();for(let[E,v]of S.owners)t.take(E,c[v][0],$.SameElement)}}#he(t){let{to:e,unmatchedElements:n,candidateActive:i,matches:s,op:o}=t,r=null,c=new Map;for(let[a,h]of t.dirtyCandidatesByShape)for(let l of h){if(!i[l])continue;r||(r=Dt(t,n.filter(p=>o[p]===$.EqualNode&&!this.#g(e[p])),e));let u=r.get(a);if(!u)continue;let d=c.get(u)??0,f=u[d];f!==void 0&&(c.set(u,d+1),i[s[f]]=1,t.displaced.push(s[f]),t.take(f,l,$.SameElement))}t.displaced.length&&this.#Ot(t)}#fe(t){let e,n=i=>{if(e===void 0){let s=t.manyPairs();e=s&&Hi(t.from,s)}return e?Ui(e,i):t.candidateElements};this.#Ct(t,!0,n)&&this.#Ct(t,!1,n)}#Ct(t,e,n){let{from:i,to:s,unmatchedElements:o,candidateActive:r,unmatchedActive:c}=t,a=!1;for(let h=0;h<o.length;h++){let l=o[h];if(!c[l])continue;let u=s[l];if(!$i(u))continue;let d=n(u);for(let f=0;f<d.length;f++){let p=d[f];if(!r[p]||!t.sameKind(l,p))continue;let w=i[p];if(!this.#ut(w,u,t)&&Qe(u,w)){if(e&&!ht(w,u)){a=!0;continue}t.take(l,p,$.SameElement);break}}}return a}#de(t){let{from:e,to:n,candidateElements:i,unmatchedElements:s,candidateActive:o,unmatchedActive:r}=t,c=0;for(let a=0;a<s.length;a++){let h=s[a];if(!r[h])continue;let l=n[h];if(Q(l)){for(;c<i.length&&!o[i[c]];)c++;for(let u=c;u<i.length;u++){let d=i[u];if(!o[d])continue;let f=e[d];if(Q(f)&&t.sameKind(h,d)&&!this.#ut(f,l,t)){t.take(h,d,$.SameElement);break}}}}}#pe(t){let{from:e,to:n,unmatchedElements:i,matches:s,op:o,candidateActive:r}=t,c=this.#s;if(c){let d=[],f=[],p=[];for(let w=0;w<i.length;w++){let y=i[w],m=s[y];if(m===void 0)continue;let A=c.has(e[m]);A&&this.#g(n[y])||(A&&f.push(m),d.push(m),p[m]=y)}if(f.length){let w=k=>`${O(e[k])} ${yt(e[k])}`,y=new Set(f.map(w)),m=new Map;for(let k of d){if(!y.has(w(k)))continue;let C=n[p[k]],V=[...this.#D(C).counts].map(([Y,Ot])=>`${Ot} ${Y}`).sort();V.length&&V.push(oe(C,Te)),nt(m,t.shapeOf(e[k])+ft(C)+JSON.stringify(V),k)}let A=s.slice(),g=!1,S=k=>c.has(e[k]),E=Dt(t,t.candidateElements.filter(k=>r[k]&&!S(k)&&y.has(w(k)))),v=[...m.values()].filter(k=>k.some(S)),M=v.map(k=>E.size?E.get(t.shapeOf(e[k[0]])):void 0),q=v.map((k,C)=>C).sort((k,C)=>+!!M[k]-+!!M[C]),H=v.map(k=>k.map(C=>p[C]).sort((C,V)=>C-V)),Wt=(k,C)=>!S(k)||!this.#g(n[C]),Ne=Zn;for(let k of[...q,...q.filter(C=>M[C])]){let C=v[k],V=H[k],Y=M[k],Ot=Y?.length?(C.length+Y.length+1)*(Y.length+1)+A.length:0;if(Y?.length&&Ot<=Ne){Ne-=Ot;let K=new Set(C);C=v[k]=Ii([...C,...Y],V,A,S,K,Wt);let Tt=new Set(C);for(let Ct of[...K,...Y])r[Ct]=Tt.has(Ct)?0:1;Y.splice(0,Y.length,...[...K,...Y].filter(Ct=>!Tt.has(Ct)))}else C.sort((K,Tt)=>K-Tt);let Ae=Mi(C,V,S,K=>this.#g(n[K]));for(let K=0;K<V.length;K++)A[V[K]]!==Ae[K]&&(A[V[K]]=Ae[K],g=!0)}if(g)for(let k=0;k<i.length;k++){let C=i[k],V=s[C]=A[C];V!==void 0&&c.has(e[V])&&(o[C]=$.SameElement)}}}let{candidateElementsById:a}=t,h=[],l=[],u=[];for(let d=0;d<i.length;d++){let f=i[d],p=s[f];if(p===void 0||c?.has(e[p]))continue;let w=b(e[p]);w!==""&&a.get(w).length===1||(h.push(p),u[p]=f,o[f]!==$.EqualNode&&l.push(p))}if(l.length){let d=l.length*h.length>1024?new qe(t,h):null,f=w=>{let y=d?d.get(e[w]):h,m=y.filter(A=>A===w||z(e[A],e[w]));return d?.fail(y,y.length-m.length),m},p=s.slice();if(Li(p,l,u,f)&&ne(p).length>ne(s).length)for(let w=0;w<p.length;w++)s[w]=p[w]}}#me(t){let{from:e,to:n,candidateNodes:i,unmatchedNodes:s,candidateActive:o}=t;for(let r=0;r<s.length;r++){let c=s[r],a=n[c];for(let h=0;h<i.length;h++){let l=i[h];if(o[l]&&z(e[l],a)){t.take(c,l,$.EqualNode);break}}}}#ge(t){let{from:e,to:n,candidateNodes:i,unmatchedNodes:s,candidateActive:o,unmatchedActive:r}=t;for(let c=0;c<s.length;c++){let a=s[c];if(!r[a])continue;let h=_(n[a]);for(let l=0;l<i.length;l++){let u=i[l];if(o[u]&&h===_(e[u])){t.take(a,u,$.SameNode);break}}}}#Ee(t,e,n){let{from:i,to:s,matches:o,op:r}=e,c=ne(this.#ye(t,e)),a=new Array(i.length);for(let f=0;f<c.length;f++)a[o[c[f]]]=!0;let h=e.whitespace.length?new Set:null;for(let f=0;f<e.whitespace.length;f++)h.add(i[e.whitespace[f]]);let l=null;if(n){l=new Set;for(let f=0;f<s.length;f++){let p=o[f];p!==void 0&&!a[p]&&l.add(i[p])}}let u=et(t),d=[];for(let f=0;f<s.length;f++){if(u&&R(u)!==t){u=et(t);for(let m=d.length-1;m>=0;m--)if(R(d[m])===t){u=W(d[m]);break}}let p=s[f],w=o[f],y=rt(p);if(n&&!(y&&u&&h?.has(u))&&(u=ln(u,n,l,h)),y&&u&&h?.has(u)){let m=u;h.delete(m),d.push(m),u=W(m),this.#N(m,p)}else if(w!==void 0){let m=i[w],A=r[f];if(!a[w]){let g=this.#M(m,J(m)),S=this.#W(m),E=Xt(m),v=this.#it(m,t);Si(t,m,u),Zt(E),v&&this.#st(v),this.#r(g),this.#r(S,!0)}R(m)===t&&(u=W(m)),A===$.EqualNode||(A===$.SameElement?z(m,p)||this.#nt(m,p,Rt(m,p)):this.#N(m,p)),d.push(R(m)===t?m:p)}else{let m=this.#Ut(t,p,u);m&&d.push(m),m===p&&R(p)===t&&(u=W(p))}}if(n&&h&&u&&R(u)===t&&ln(u,n,l,h),h)for(let f of h)R(f)===t&&this.#J(f)}#it(t,e){let n=Ni(t);if(!n)return null;let i=_(e)===qt?e:lt(e);this.#tt=n,this.#K=i===n.document?[i]:[n.document,i];for(let s of this.#K)EventTarget.prototype.addEventListener.call(s,"focusin",this.#Mt,!0);return n}#Mt=t=>{let e=this.#tt;t.composedPath()[0]!==e.element&&(e.taken=!0)};#st(t){let e=Fe(t);for(let s of this.#K)ee(s,"focusin",this.#Mt);if(this.#tt=null,this.#K=[],!e)return;let n=this.#C;n&&ee(n.document,"focusin",this.#ot),t.document=lt(t.element);let i=t.range;try{this.#V=i&&[nn(t.document,i[0],i[1]),nn(t.document,i[2],i[3])]}catch{this.#V=null}this.#C=t,EventTarget.prototype.addEventListener.call(t.document,"focusin",this.#ot,{capture:!0,once:!0})}#ot=()=>{this.#C=null};#ye(t,e){let{from:n,matches:i}=e,s=this.#Q;if(le||!s?.has(t))return i;let o=i.findIndex(c=>c!==void 0&&s.has(n[c]));if(o===-1)return i;let r=i[o];return i.map((c,a)=>(a<o?c<r:!(a>o)||c>r)?c:void 0)}setEnclosingSelect(t,e){this.#k=[t,e]}#It(t){if(!an||t.multiple)return;let e=Et(t,"selectedcontent"),n=t.options[t.selectedIndex]??null;for(let i=0;i<e.length;i++){let s=e[i];wn(s)&&!pi(s,n)&&!this.#L(s)&&wt(R(s),s,W(s))}}#ve(){let t=this.#k;if(!t)return;this.#k=null;let[e,n]=t;if(this.#t)return;let i=yn(e);i.length===n.length&&i.every((s,o)=>s===n[o])&&!this.#St||this.#rt(e)}#rt(t){if(this.#t&&!(this.#wt?.has(t)&&De(t)))return;let e=t.options,n=t.multiple?null:he(t),i=s=>t.multiple?s.hasAttribute("selected"):s===n;if(this.#d||this.#E)for(let s=0;s<e.length;s++){let o=e[s];if(o.selected!==i(o)&&(t.multiple||o.selected)&&this.#L(o))return}for(let s=0;s<e.length;s++){let o=e[s],r=i(o);o.selected!==r&&(o.selected=r)}(this.#X??=new Set).add(t)}#we(t){let e=F(t)?[t]:Et(t,"input");for(let n=0;n<e.length;n++){let i=e[n];F(i)&&i.type==="radio"&&(i.checked||i.hasAttribute("checked"))&&(this.#m??=new Set).add(i)}}#Se(t){let e=F(t)?[t]:x(t,"input"),n=new Map;for(let i=0;i<e.length;i++){let s=e[i];if(F(s)&&s.type==="radio"){let o=this.#m??=new Set;for(let r of mt(s,n))o.add(r)}}}#Ne(t,e){let n=this.#M(t,J(t)),i=F(t)?[t]:x(t,"input");for(let s=0;s<i.length;s++){let o=i[s];Qt(o)&&o.form!==Fi(o,t,e)&&(this.#t?(this.#G(o),(n??=[]).push(o)):(o.checked=!1,(this.#H??=new Set).add(o)))}return n}#M(t,e,n=!1){let i=Nn(t);return i&&this.#Dt(i,e,n?null:t)}#W(t){return!N(t)||!ct(t)&&(!Nt(t)||Et(t,"form").length===0)?null:this.#Lt(t)}#Lt(t){let e=null,n=F(t)?[t]:x(t,"input[form]:checked");for(let i=0;i<n.length;i++){let s=n[i];Qt(s)&&s.hasAttribute("form")&&(this.#G(s,!0),(e??=[]).push(s))}return e}#Dt(t,e,n){let i=null,s=x(e,"input[form]:checked, input[form][checked]");for(let o=0;o<s.length;o++){let r=s[o];!ut(r)||!t.has(r.getAttribute("form"))||n&&P(n,r)||(r.checked?(this.#G(r),(i??=[]).push(r)):this.#lt(r)&&(this.#m??=new Set).add(r))}return i}#Rt(t,e,n){if((e==="form"||e==="name")&&Qt(t)||e==="type"&&n?.toLowerCase()==="radio"&&F(t)&&t.type!=="radio"&&t.checked)return this.#G(t),[t];if(e==="id"&&ct(t)){let i=new Set(n===null||n===""?[b(t)]:[b(t),n]);return this.#Dt(i,J(t),null)}return null}#G(t,e=!1){let n=!e&&this.#lt(t)?null:t.getAttribute("checked");if(n!==null){if(t.removeAttribute("checked"),!t.checked){Lt.set(t,n);return}t.setAttribute("checked",n)}t.checked=!1}#r(t,e=!1){if(!t)return;let n=new Map;for(let i=0;i<t.length;i++){let s=t[i];if(!e&&this.#lt(s)&&!Lt.has(s)){(this.#H??=new Set).add(s);continue}let o=mt(s,n),r=this.#I(s)?void 0:o.find(h=>h.checked&&this.#I(h)),c=o.filter(h=>h.checked),a=Lt.get(s);a!==void 0?(Lt.delete(s),s.setAttribute("checked",a),s.checked||(s.checked=!0)):s.checked=!0,r&&(r.checked=!0,this.#xt(s,r)),this.#ct(c,s)}}#ct(t,e){for(let n=0;n<t.length;n++){let i=t[n];i.checked||this.#xt(i,e)}}#xt(t,e){let n=this.#b??=new Map;n.delete(t),n.set(t,e)}#Ae(t){let e=new Map;for(let[n,i]of Array.from(t).reverse()){let s=mt(n,e);if(i.checked&&s.includes(i)||s.some(r=>r.checked))continue;let o=n.getAttribute("checked");o!==null&&(n.removeAttribute("checked"),n.setAttribute("checked",o)),n.checked||(n.checked=!0)}}#lt(t){if(this.#t)return!1;let e=this.#o;return e?P(e,t):this.#I(t)}#Pt(t){let e=this.#M(t,J(t)),n=this.#W(t);xt(t),this.#r(e),this.#r(n,!0)}#ke(t){let e=new Set,n=new Map;for(let i of t){if(e.has(i))continue;let s=mt(i,n).filter(r=>this.#I(r));for(let r of s)e.add(r);if(s.some(r=>this.#L(r)))continue;let o=null;for(let r of s)r.hasAttribute("checked")&&(o=r);for(let r of s){let c=r===o;r.checked!==c&&(r.checked=c)}}}#I(t){if(!P(this.#i,t))return!1;let e=this.#h,n=this.#f;return!(e&&(P(e,t)||!(te(e,t)&Node.DOCUMENT_POSITION_FOLLOWING))||n&&(P(n,t)||!(te(n,t)&Node.DOCUMENT_POSITION_PRECEDING)))}#L(t){if(this.#d?.has(t))return!0;let e=this.#E;if(e){for(let n=0;n<e.length;n++)if(P(e[n],t))return!0}return!1}#at(t){return this.#R.has(t)||U(t)}#ut(t,e,n){return this.#t&&this.#R.has(t)&&!this.#c?.has(e)&&this.#_t(n,t)!==this.#_t(n,e)}#_t(t,e){let n=t.choices??=new Map,i=n.get(e);return i===void 0&&n.set(e,i=this.#ht(e)),i}#be(t,e,n){let i=this.#D(e).counts;if(!n)return t.some(s=>i.has(s));for(let[s,o]of ze(t))if((i.get(s)??0)<o)return!1;return!0}#D(t){let e=this.#mt.get(t);if(!e){let n=[];for(let i of[t,...x(t,"input, option")]){if(this.#Oe(i,t)||this.#Bt(i,t))continue;let s=this.#ht(i);s!==null&&n.push(Ye(i,t)+s)}e={counts:ze(n),size:n.length},this.#mt.set(t,e)}return e}#Bt(t,e){for(let n=t;n!==e;n=D(n)){let i=this.#v(b(n)),s=i&&this.#yt.get(b(n));if(s&&ht(i,s))return!0}return!1}#g(t){let e=this.#c;if(!e)return!1;if(!this.#a){this.#a=new Set;for(let n of e)for(let i=n;i&&!this.#a.has(i);i=D(i))this.#a.add(i)}return this.#a.has(t)}#Oe(t,e){let n=this.#c;if(!n)return!1;for(let i=t;i;i=i===e?null:D(i))if(n.has(i))return!0;return!1}#ht(t){if(!G(t))return Ge(t,null,this.#Ft(t));let e=null;for(let n=t,i=D(n);i&&n!==this.#n&&!this.#w.has(n);n=i,i=D(i)){if(O(i)==="datalist"&&T(i)===B)return null;if(U(i)){e=i;break}}return e??=this.#gt,e=(e&&this.#z.get(e))??e,Ge(t,e,e&&this.#Ft(e))}#Ft(t){for(let e=t;e;e=D(e)){if(ct(e)&&e!==this.#A)return e;if(this.#w.has(e))return this.#l}return null}#Te(t){if(!this.#s?.has(t))return null;let e=[],n=[];for(let i of[t,...x(t,"input, option")]){let s=this.#R.has(i)&&!this.#Bt(i,t)?this.#ht(i):null;if(s===null)continue;let o=Ye(i,t)+s;e.push(o),(i===t||!Pi(i))&&n.push(o)}return e.length?{choices:e,picked:n}:null}#Ht(t,e,n){n===null&&(e==="selected"&&G(t)||e==="checked"&&F(t)||e==="open"&&tt(t))&&(this.#d??=new Set).add(t)}#Ce(t,e){z(t.content,e.content)||t.content.replaceChildren(e.content)}#Ut(t,e,n){let i=N(e)?this.#dt(e,t):null;return i?(wt(t,i,n),i):this.#ft(t,e,n)?e:null}#ft(t,e,n,i=!1){if(!i&&!(this.#e.beforeNodeAdded?.(t,e,n)??!0))return!1;let s=Ut(e),o=this.#Z&&N(e)?this.#At():null,r=s?this.#M(e,J(e),!0):null,c=s?Xt(e):null,a=this.#it(e,t);hi(e,t),this.#Re(e,t),this.#O&&N(e)&&this.#ee(e);let h=this.#M(e,J(t)),l=this.#U&&N(e)?this.#Lt(e):s?this.#W(e):null;return _e(t,e,n),Zt(c),a&&this.#st(a),this.#r(h),this.#r(r,!0),this.#r(l,!0),o&&Xe(o),this.#U&&!this.#t&&N(e)&&this.#we(e),this.#e.afterNodeAdded?.(e),!0}#$t(t){let{live:e,target:n,placeholder:i,preserveChanges:s,approved:o}=t;if(!this.#S.has(e)||this.#F.has(t))return;this.#F.add(t);let r=!1;for(let l=D(e);l&&!r;){let u=this.#S.get(l)??this.#De(l);u?this.#F.has(u)?r=!0:(this.#$t(u),l=D(e)):l=D(l)}this.#F.delete(t),this.#S.delete(e);let c=R(i);if(!c)return;let a=this.#t,h=this.#o;if(this.#t=s,!s&&this.#e.preserveChanges&&(this.#o=e),!r&&this.#p.get(b(n))===e&&!P(e,c)){this.#p.delete(b(n));let l=this.#Ne(e,c),u=this.#W(e),d=Xt(e),f=this.#it(e,c);_e(c,e,i),Zt(d),f&&this.#st(f),xt(i),this.#r(l),this.#r(u,!0),this.#t||this.#Se(e),this.#N(e,n)}else this.#ft(c,n,i,o),xt(i);this.#t=a,this.#o=h}#Me(t,e){let n=R(t);if(!n)throw new Error(Oe);let i=t;if((this.#e.beforeNodeRemoved?.(t)??!0)&&(this.#e.beforeNodeAdded?.(n,e,i)??!0)){let s=N(e)?this.#dt(e,n,void 0,!0):null;s?wt(n,s,i):this.#ft(n,e,i,!0),this.#qt(t)}this.#u(t)}#J(t,e=!1){return!e&&N(t)&&this.#v(b(t))===t?((this.#j??=[]).push(t),!1):this.#e.beforeNodeRemoved?.(t)??!0?(this.#qt(t,e),!1):!0}#qt(t,e=!1){!e&&this.#Ie(t)?(this.#_??=[]).push(t):(this.#Pt(t),this.#e.afterNodeRemoved?.(t))}#Y(t){(this.#E??=[]).push(t);let e=this.#P.get(t);if(e)for(let n of e){let i=this.#p.get(n);i&&i!==t&&this.#p.set(n,null)}}#v(t){if(t===""||this.#Et.get(t)!==1)return null;let e=this.#p.get(t);return!e||G(e)||qi(e)?null:e}#Ie(t){let e=this.#P.get(t);if(!e)return!1;for(let n of e){let i=this.#v(n);if(i&&i!==t&&P(t,i))return!0}return!1}#Vt(t,e,n){let i=this.#v(b(t));return i===null||!ht(i,t)||P(i,e)?!1:(n===void 0&&(n=Yt(e)),!this.#Le(i,t,n)&&!En(i,n))}#Le(t,e,n){let i=this.#y.get(e);if(!i)return!1;for(let s=D(t);s;s=D(s)){let o=b(s);if(o!==""&&this.#v(o)===s&&i.includes(o)&&Ue(s,e,n))return!0}return!1}#dt(t,e,n,i=!1){if(!this.#Vt(t,e,n))return null;let s=this.#p.get(b(t));n===void 0&&(n=Yt(e));let o=Xi(lt(s),""),r={live:s,target:t,placeholder:o,preserveChanges:this.#t&&!this.#c?.has(t),approved:i,select:n};(this.#B??=[]).push(r),this.#S.set(s,r);let c=this.#y.get(t);if(c)for(let a of c)this.#vt.set(a,r);return o}#De(t){if(this.#v(b(t))!==t)return;let e=this.#vt.get(b(t));return e&&this.#S.has(e.live)&&Ue(t,e.target,e.select)?e:void 0}#Re(t,e){N(t)&&this.#y.get(t)?.some(n=>n!==b(t)&&this.#v(n))&&this.#Kt(t,Yt(e))}#Kt(t,e){let n=this.#t;n&&this.#c?.has(t)&&(this.#t=!1);let i=U(t)?t:e,s=Nt(t);for(;s;){let o=In(s);if(this.#y.has(s)){let r=this.#dt(s,t,i);r?Gi(t,r,s):this.#Kt(s,i)}s=o}this.#t=n}#Wt(t,e=!0){let n=this.#y;this.#U||(this.#U=N(t)&&F(t)?X(t,"checked"):St(t,"input[checked]")!==null),this.#Z||(this.#Z=N(t)&&ve(t,je)||St(t,je)!==null),this.#O||(this.#O=N(t)&&tt(t)&&ot(t,null,"open")||St(t,"details[open]")!==null);let i=this.#Et;e&&N(t)&&b(t)!==""&&i.set(b(t),(i.get(b(t))??0)+1),$e(t,s=>{let o=b(s);i.set(o,(i.get(o)??0)+1),this.#yt.set(o,s);let r=s;for(;r;){let c=n.get(r);if(c?c.push(o):n.set(r,[o]),r===t)break;r=D(r)}})}#Gt(t){let e=this.#P,n=this.#p;N(t)&&b(t)!==""&&n.set(b(t),null),$e(t,i=>{let s=b(i);n.set(s,n.has(s)?null:i);let o=i;for(;o;){let r=e.get(o);if(r?r.add(s):e.set(o,new Set([s])),o===t)break;o=D(o)}})}};function Ue(t,e,n){let i=Array.from(x(e,"[id]")).find(o=>b(o)===b(t)),s=st(i);return ht(t,i)&&!En(t,s&&P(e,s)?s:n)}function $e(t,e){for(let n of x(t,"[id]"))b(n)!==""&&e(n)}function Ci(t,e){let n=vt(t);for(let i=0;i<n.length;i++){let{localName:s,namespaceURI:o}=n[i];if(!ot(e,o,s))return!0}return!1}function Mi(t,e,n,i){let s=e.filter(i).length;if(!s)return t;let o=t.filter(h=>!n(h)).length,r=new Set,c=[0,0,0],a=h=>{let l=c[h];for(;r.has(t[l])||h===1&&n(t[l])||h===2&&!n(t[l]);)l++;return c[h]=l,t[l]};return e.map(h=>{let l;return s&&i(h)?(l=a(1),s--):l=a(o>s?0:2),r.add(l),n(l)||o--,l})}function Ii(t,e,n,i,s,o){t.sort((g,S)=>g-S);let r=t.length,c=r-e.length,a=c+1,h=new Set(e),l=[];for(let g=0;g<n.length;g++){let S=n[g];S!==void 0&&!h.has(g)&&l.push([S,g])}l.sort((g,S)=>g[0]-S[0]);let u=e.length*l.length+1,d=g=>i(g)?u:1,f=new Float64Array(n.length+1);for(let[g,S]of l)f[S+1]+=d(g);for(let g=0;g<n.length;g++)f[g+1]+=f[g];let p=new Float64Array(n.length+1),w=g=>{let S=0;for(let E=g;E>0;E-=E&-E)S+=p[E];return S},y=new Float64Array((r+1)*a).fill(1/0);y[0]=0;let m=0;for(let g=1,S=0;g<=r;g++){let E=t[g-1];for(;S<l.length&&l[S][0]<E;S++){let v=d(l[S][0]);m+=v;for(let M=l[S][1]+1;M<=n.length;M+=M&-M)p[M]+=v}for(let v=0;v<=c&&v<=g;v++){let M=g-v;if(M>e.length)continue;let q=1/0;v>0&&!i(E)&&(q=y[(g-1)*a+v-1]+(s.has(E)?1:0));let H=e[M-1];if(H!==void 0&&v<g&&o(E,H)){let Wt=m-2*w(H)+f[H];q=Math.min(q,y[(g-1)*a+v]+Wt*d(E)*(r+1))}y[g*a+v]=q}}if(y[r*a+c]===1/0)return t.filter(g=>s.has(g));let A=[];for(let g=r,S=c;g>0;g--){let E=t[g-1];S>0&&!i(E)&&y[g*a+S]===y[(g-1)*a+S-1]+(s.has(E)?1:0)?S--:A.push(E)}return A.reverse()}function Li(t,e,n,i){let s=new Set,o=!1;for(let r=0;r<e.length;r++){let c=e[r];if(s.has(c))continue;let a=i(c);if(a.length<2)continue;a.sort((l,u)=>l-u);let h=a.map(l=>n[l]).sort((l,u)=>l-u);for(let l=0;l<a.length;l++)s.add(a[l]),t[h[l]]!==a[l]&&(t[h[l]]=a[l],o=!0)}return o}var qe=class{#e;#t;#n=new Map;constructor(t,e){this.#e=t,this.#t=Di(t.from,e)}get(t){let e=this.#t.get(yt(t)),n=e&&e.length>1&&this.#n.get(e);return!n||n.failures<=e.length?e:(n.byShape??=Dt(this.#e,e),n.byShape.get(this.#e.shapeOf(t)))}firstActive(t,e){if(t.length===1)return 0;let n=this.#i(t);for(;n.taken<t.length&&!e[t[n.taken]];)n.taken++;return n.taken}fail(t,e=1){t.length>1&&(this.#i(t).failures+=e)}#i(t){let e=this.#n.get(t);return e||this.#n.set(t,e={taken:0,failures:0}),e}};function nt(t,e,n){let i=t.get(e);i?i.push(n):t.set(e,[n])}function Dt(t,e,n=t.from){let i=new Map;for(let s of e)nt(i,t.shapeOf(n[s]),s);return i}function Di(t,e){let n=new Map;for(let i=0;i<e.length;i++){let s=e[i];nt(n,yt(t[s]),s)}return n}function Ve(t){let e=et(t);return e&&!W(e)?e:null}function Ke(t){let e=et(t);return e&&_(e)===ae&&!W(e)?e:null}function We(t){let e=t.length,n=new Array(e);for(let i=0;i<e;i++)n[i]=t[i];return n}function rt(t){if(_(t)!==ae)return!1;let e=t.nodeValue;if(!e)return!0;for(let n=0;n<e.length;n++)if(!se(e.charCodeAt(n)))return!1;return!0}function se(t){return t===32||t===9||t===10||t===13||t===12}function Ri(t){let e=0,n=t.length;for(;e<n&&se(t.charCodeAt(e));)e++;for(;n>e&&se(t.charCodeAt(n-1));)n--;return t.slice(e,n)}function xi(t){if(t.firstElementChild){for(;t.firstChild&&rt(t.firstChild);)t.firstChild.remove();for(;t.lastChild&&rt(t.lastChild);)t.lastChild.remove()}}function Ge(t,e,n){return G(t)?JSON.stringify([e?.getAttribute("name")??"",e&&Je(e,n),e&&(e.hasAttribute("multiple")?2:fe(e)>1?1:0),t.value,L(t,"is")]):F(t)&&(t.type==="checkbox"||t.type==="radio")?JSON.stringify([t.type,t.name,t.value,Je(t,n),L(t,"is")]):null}function Je(t,e){let n=L(t,"form");return n&&e&&n===b(e)?null:n}function Ye(t,e){let n=[];for(let i=t;i!==e;)i=D(i),i!==e&&n.push([T(i),O(i),L(i,"is")]);return JSON.stringify(n)}function ze(t){let e=new Map;for(let n of t)e.set(n,(e.get(n)??0)+1);return e}function oe(t,e){let n=[];for(let{namespaceURI:i,localName:s,value:o}of vt(t))(i!==null||s!==Z&&!e.includes(s))&&n.push(JSON.stringify([i,s,o]));return JSON.stringify(n.sort())}function Pi(t){return G(t)?!t.selected:F(t)&&t.type==="radio"&&!t.checked}function re(t,e){if(!N(t))return JSON.stringify([_(t),t.nodeName,t.nodeValue]);let n=oe(t,e&&me(t)?ti:[]),i="";for(let s of pt(t))i+=re(s,e);if(it(t)){i+="<#content";for(let s of t.content.childNodes)i+=re(s,e);i+=">"}return`<${JSON.stringify([T(t),Mn(t),O(t)])}${n}${i}>`}function ft(t){if(!N(t))return JSON.stringify([_(t),t.nodeName,t.nodeValue]);let e="";if(!dt(t))for(let n of pt(t))e+=ft(n);if(it(t)){e+="<#content";for(let n of t.content.childNodes)e+=ft(n);e+=">"}return`<${JSON.stringify([T(t),Mn(t),O(t),L(t,"is")])}${e}>`}function z(t,e){if(!Node.prototype.isEqualNode.call(t,e))return!1;if(!Ft(t))return!0;if(N(t)&&it(t)&&!z(t.content,e.content))return!1;let n=x(t,"template");if(n.length===0)return!0;let i=x(e,"template");for(let s=0;s<n.length;s++){let o=n[s];if(it(o)&&!z(o.content,i[s].content))return!1}return!0}function it(t){return O(t)==="template"&&T(t)===B}var je="input[checked], option[selected]";function _i(t){if(ut(t))return t.checked;if(!G(t)||!t.selected)return!1;let e=st(t);return e!==null&&!e.multiple}function Bi(t){let e=[];for(let n of x(J(t),"input:checked"))ut(n)&&n.name!==""&&!n.defaultChecked&&!P(t,n)&&e.push(n);return e}function bn(t){return G(t)?t.selected:t.checked}function Xe(t){for(let e of t)bn(e)||(G(e)?e.selected=!0:e.checked=!0)}function mt(t,e){if(t.name==="")return[t];let n=t.form,i=n??t.getRootNode(),s=e.get(i);if(!s){s=new Map,e.set(i,s);let o=n?Dn(n):x(i,"input");for(let r=0;r<o.length;r++){let c=o[r];F(c)&&c.type==="radio"&&c.form===n&&nt(s,c.name,c)}}return s.get(t.name)??[]}function Fi(t,e,n){if(X(t,"form"))return t.form;let i=Bt(R(t));return i&&P(e,i)?i:Bt(n)}function Bt(t){for(;t;t=R(t))if(N(t)&&ct(t))return t;return null}function ct(t){return O(t)==="form"&&T(t)===B}function Qt(t){return ut(t)&&t.checked}function ut(t){return F(t)&&t.type==="radio"}function Ze(t){if(t.name==="")return[];let e=t.form,n=[];if(e){let s=Dn(e).namedItem(t.name);s&&"length"in s&&(n=s)}else n=x(t.getRootNode(),"input:checked");let i=[];for(let s=0;s<n.length;s++){let o=n[s];ut(o)&&o.checked&&o.name===t.name&&o.form===e&&i.push(o)}return i}function F(t){return O(t)==="input"&&T(t)===B}function dt(t){return O(t)==="textarea"&&T(t)===B}function Rt(t,e){return L(t,"is")===L(e,"is")}function ht(t,e){if(O(t)!==O(e)||T(t)!==T(e)||!Rt(t,e))return!1;if(ce(t)&&ce(e)){let n=b(t),i=b(e);if((n!==""||i!=="")&&n!==i)return!1}return F(t)&&F(e)?t.type===e.type:!0}function Q(t){return b(t)===""&&!ce(t)&&!L(t,"name")&&!(ni.has(O(t))&&(L(t,"src")||L(t,"href")))}function Qe(t,e){for(let n of["name","href","src"]){let i=L(t,n);if(i&&i===L(e,n))return!0}return!1}function On(t){let e=[];for(let n of["name","href","src"]){let i=L(t,n);i&&e.push(`${n} ${i}`)}return e}function Hi(t,e){let n=new Map;for(let i of e)for(let s of On(t[i]))nt(n,s,i);return n}function Ui(t,e){let n=On(e).map(i=>t.get(i)??[]);return n.length===1?n[0]:[...new Set(n.flat())].sort((i,s)=>i-s)}function $i(t){return!!(L(t,"name")||L(t,"href")||L(t,"src"))}function ce(t){if(T(t)!==B)return!1;let e=O(t);return e==="input"||e==="textarea"||e==="select"||e.includes("-")&&t.constructor.formAssociated===!0}function Tn(t){return O(t)==="dialog"&&T(t)===B}function tt(t){return O(t)==="details"&&T(t)===B}function me(t){return Tn(t)||tt(t)}function tn(t){let e=j(t,null,"name");if(!e)return[];let n=J(t);return[...Cn(n)?Zi(n,e):x(n,"details[open][name]")].filter(i=>i!==t&&j(i,null,"name")===e&&ot(i,null,"open")&&tt(i))}function en(t){let e=new Set;for(let n=0;n<t.length;n++){let i=t[n];if(!N(i))continue;let s=[...x(i,"details[open]")];ve(i,"details[open]")&&s.unshift(i);for(let o of s){let r=j(o,null,"name");!r||!tt(o)||(e.has(r)?xn(o,null,"open"):e.add(r))}}}function U(t){return O(t)==="select"&&T(t)===B}function qi(t){return O(t)==="optgroup"&&T(t)===B}function G(t){return O(t)==="option"&&T(t)===B}function N(t){return _(t)===at}function Cn(t){return _(t)===qt}function Ft(t){let e=_(t);return e===at||e===qt||e===un}function ge(t){return Object.prototype.toString.call(t)==="[object NodeList]"}function I(t,e){let n;return i=>(n??=Object.getOwnPropertyDescriptor(t(),e)).get.call(i)}var _=I(()=>Node.prototype,"nodeType"),R=I(()=>Node.prototype,"parentNode"),D=I(()=>Node.prototype,"parentElement"),pt=I(()=>Node.prototype,"childNodes"),et=I(()=>Node.prototype,"firstChild"),Vi=I(()=>Node.prototype,"previousSibling"),W=I(()=>Node.prototype,"nextSibling"),lt=I(()=>Node.prototype,"ownerDocument"),Ht=I(()=>HTMLElement.prototype,"isContentEditable"),Ut=I(()=>Node.prototype,"isConnected"),yt=I(()=>Node.prototype,"textContent"),b=I(()=>Element.prototype,"id"),O=I(()=>Element.prototype,"localName"),T=I(()=>Element.prototype,"namespaceURI"),Mn=I(()=>Element.prototype,"prefix"),vt=I(()=>Element.prototype,"attributes"),Nt=I(()=>Element.prototype,"firstElementChild"),In=I(()=>Element.prototype,"nextElementSibling"),$t=I(()=>Document.prototype,"documentElement"),Ki=I(()=>Document.prototype,"head"),Ee=I(()=>Document.prototype,"body"),Ln=I(()=>Document.prototype,"activeElement"),Wi=I(()=>Document.prototype,"implementation"),Dn=I(()=>HTMLFormElement.prototype,"elements");function wt(t,e,n){Node.prototype.insertBefore.call(t,e,n)}function Gi(t,e,n){Node.prototype.replaceChild.call(t,e,n)}function xt(t){let e=R(t);e&&Node.prototype.removeChild.call(e,t)}function nn(t,e,n){let i=Document.prototype.createRange.call(t);return i.setStart(e,n),i}function sn(t,e,n,i){if(P(t,e.startContainer)||!P(t,n))return[e.startContainer,e.startOffset];let s=_(n)===at?pt(n).length:n.length;return[n,Math.min(i,s)]}function P(t,e){return Node.prototype.contains.call(t,e)}function te(t,e){return Node.prototype.compareDocumentPosition.call(t,e)}function on(t){return Node.prototype.hasChildNodes.call(t)}function J(t){return Node.prototype.getRootNode.call(t)}function Ji(t){return Element.prototype.getBoundingClientRect.call(t)}function Rn(t){return Document.prototype.getSelection.call(t)}function ee(t,e,n){EventTarget.prototype.removeEventListener.call(t,e,n,!0)}function L(t,e){return Element.prototype.getAttribute.call(t,e)}function j(t,e,n){return Element.prototype.getAttributeNS.call(t,e,n)}function Yi(t,e,n){return Element.prototype.getAttributeNodeNS.call(t,e,n)}function X(t,e){return Element.prototype.hasAttribute.call(t,e)}function ot(t,e,n){return Element.prototype.hasAttributeNS.call(t,e,n)}function rn(t){return Element.prototype.hasAttributes.call(t)}function ye(t,e,n){Element.prototype.setAttribute.call(t,e,n)}function gt(t,e,n,i){Element.prototype.setAttributeNS.call(t,e,n,i)}function zi(t,e){Element.prototype.setAttributeNodeNS.call(t,e)}function At(t,e){Element.prototype.removeAttribute.call(t,e)}function xn(t,e,n){Element.prototype.removeAttributeNS.call(t,e,n)}function ve(t,e){return Element.prototype.matches.call(t,e)}function Et(t,e){return Element.prototype.getElementsByTagName.call(t,e)}function Vt(t){return N(t)?Element.prototype:Cn(t)?Document.prototype:DocumentFragment.prototype}function St(t,e){return Vt(t).querySelector.call(t,e)}function x(t,e){return Vt(t).querySelectorAll.call(t,e)}function kt(t,e){return Document.prototype.createElement.call(t,e)}function cn(t,e,n){return Document.prototype.createElementNS.call(t,e,n)}function ji(t,e){return Document.prototype.importNode.call(t,e,!1)}function Xi(t,e){return Document.prototype.createComment.call(t,e)}function Zi(t,e){return Document.prototype.getElementsByName.call(t,e)}function ln(t,e,n,i){let s=t;for(let o=t;o;){let r=W(o),c=e.get(o);if(c!==void 0){if(c)for(let a=s;a!==o;a=W(a))i?.delete(a);s=r}else if(!n.has(o)&&!i?.has(o))break;o=r}return s}function ne(t){let e=t.length,n=new Array(e),i=new Array(e),s=new Int32Array(e),o=0;for(let a=0;a<e;a++){let h=t[a];if(h===void 0)continue;let l=0,u=o;for(;l<u;){let d=Math.floor((l+u)/2);n[d]<h?l=d+1:u=d}s[a]=l>0?i[l-1]:-1,n[l]=h,i[l]=a,l===o&&o++}let r=new Array(o),c=i[o-1];for(let a=o-1;a>=0;a--)r[a]=c,c=s[c];return r}var bt="data-pulse-stub",_n={preserveChanges:!0},Qi={..._n,beforeNodeVisited:(t,e)=>!Pn(e),beforeNodeAdded:(t,e)=>{if(Pn(e))return!1;if(e instanceof Element)for(let n of e.querySelectorAll(`[${bt}]`))n.remove();return!0}};function Bn(t){hn(document,t,_n)}function we(t){let e=ts(t);if(!e?.id)return!1;let n=document.getElementById(e.id);return n?(ue(n,es(n,e),Qi),!0):!1}function Se(t,e,n){let i;try{i=document.querySelectorAll(t)}catch{return console.warn("[pulse] Invalid target selector",t),!1}return i.length!==1?(console.warn("[pulse] Target selector must match exactly one element",t,i.length),!1):(i[0].insertAdjacentHTML(e,n),!0)}function Fn(t){let e=document.getElementById(t);return e?(e.remove(),!0):!1}function ts(t){let e=t.trim();if(/^<body(?:\s|>)/i.test(e))return new DOMParser().parseFromString(e,"text/html").body;let n=document.createElement("template");return n.innerHTML=e,n.content.firstElementChild}function es(t,e){let n=e,i=[e,...e.querySelectorAll(`[${bt}]`)];for(let s of i){if(!s.hasAttribute(bt))continue;let o=is(t,n,s);o&&!s.id&&(s.id=o.id);let r=o?ns(s,o):s;if(s===n&&(n=r),!!ss(r)&&(r.removeAttribute(bt),o))for(let{name:c,value:a}of o.attributes)r.setAttribute(c,a)}return n}function ns(t,e){if(t.localName===e.localName&&t.namespaceURI===e.namespaceURI)return t;let n=t.ownerDocument.createElementNS(e.namespaceURI,e.localName);for(let{name:i,value:s}of t.attributes)n.setAttribute(i,s);return n.append(...t.childNodes),t.replaceWith(n),n}function Hn(t,e){if(!e)return null;let n=document.getElementById(e);return n&&t.contains(n)?n:null}function is(t,e,n){if(n.id)return Hn(t,n.id);let i=Un(t,e,n);return i?.id?i:null}function Un(t,e,n){if(n===e)return t;let i=n.parentElement;if(!i)return null;let s=i.id?Hn(t,i.id):Un(t,e,i);if(!s)return null;let o=[...i.children].indexOf(n);return o<0?null:s.children.item(o)}function Pn(t){return t.nodeType===Node.ELEMENT_NODE&&t.hasAttribute(bt)}function ss(t){return[...t.childNodes].some(e=>e.nodeType!==Node.TEXT_NODE||(e.nodeValue??"").trim()!=="")}var qn="pulseStorage",Kt=class{connection;constructor(){this.connection=new It({onOpen:()=>{let e=os();e!==void 0&&this.connection.send({type:"page",local_storage:e}),this.navigate(window.location.pathname)},onMessage:e=>this.applyAction(e)}),this.connection.connect()}applyAction(e){if(Array.isArray(e)){let n=e.find(i=>i.action==="page"&&i.url!==void 0);n?this.applyAction(n):e.forEach(i=>this.applyAction(i));return}switch(e.action){case"update":Bn(e.html),e.url&&e.url!==Mt()&&history.pushState(null,"",e.url);break;case"replace":Array.isArray(e.html)?e.html.forEach(n=>we(n)):we(e.html);break;case"append":Se(e.selector,"beforeend",e.html);break;case"prepend":Se(e.selector,"afterbegin",e.html);break;case"remove":Fn(e.id);break;case"navigate":this.visit(e.url);break;case"page":if(e.local_storage!==void 0&&rs(e.local_storage),e.url!==void 0)this.visit(e.url,e.history??"push");else if(e.query!==void 0){let n=new URL(window.location.href);n.search=e.query,$n(n.href,e.history??"replace")}break;default:console.warn("[pulse] Ignoring unknown action",e.action)}}navigate(e,n=be()){this.connection.send({type:"navigate",url:e,...n})}visit(e,n="push"){let i=new URL(e,window.location.href);if(i.origin!==window.location.origin){n==="replace"?window.location.replace(i.href):window.location.assign(i.href);return}$n(i.href,n),this.navigate(i.pathname,{query:i.search.slice(1),hash:i.hash})}sendEvent(e,n,i){this.connection.send({type:"event",id:e,event:n,data:i})}};function os(){let t=localStorage.getItem(qn);if(t!==null)return t}function rs(t){localStorage.setItem(qn,t)}function $n(t,e){t!==window.location.href&&(e==="push"?history.pushState(null,"",t):history.replaceState(null,"",t))}var Wn="application/x-www-form-urlencoded",cs=`${Wn};charset=UTF-8`,ls=["click","input","change","submit","keydown","keyup"];function Gn(t){let e=ls.map(o=>{let r=c=>as(c,o,t);return document.addEventListener(o,r),[o,r]}),n=o=>Es(o,t),i=o=>ys(o,t),s=()=>t.navigate(window.location.pathname);return document.addEventListener("click",n),document.addEventListener("submit",i),window.addEventListener("popstate",s),()=>{e.forEach(([o,r])=>document.removeEventListener(o,r)),document.removeEventListener("click",n),document.removeEventListener("submit",i),window.removeEventListener("popstate",s)}}function as(t,e,n){if(t.defaultPrevented||!(t.target instanceof Element))return;let i=us(t,e);if(!i)return;(e==="submit"||e==="click"&&fs(t.target))&&t.preventDefault();let s=i.dataset.pulseComponentId;if(!s){console.warn(`[pulse] Ignoring data-pulse-${e} without data-pulse-component-id`,i);return}let o=i.getAttribute(`data-pulse-${e}`),r=i.getAttribute(`data-pulse-${e}-payload`),c=ds(t,e,i);gs(i,e,()=>{let a=c();r!==null&&((a??={}).payload=r),n.sendEvent(s,o,a)})}function us(t,e){let n=t.target.closest(`[data-pulse-${e}]`);if(t instanceof KeyboardEvent)for(;n&&!hs(t,n.getAttribute(`data-pulse-${e}-key`));)n=n.parentElement?.closest(`[data-pulse-${e}]`)??null;return n}function hs(t,e){return e===null||t.key.toLowerCase()===e.toLowerCase()}function fs(t){return t instanceof Element&&t.closest("a[href], button, input[type=submit], input[type=image], input[type=reset]")!==null}function ds(t,e,n){switch(e){case"keydown":case"keyup":{let i=t.key;return()=>({key:i})}case"submit":{let i=t.target,s=t.submitter;return()=>({form:Vn(i,s)})}case"input":case"change":{if(n instanceof HTMLFormElement)return()=>({form:Vn(n)});let i=t.target;return()=>ps(i)?ms(i):void 0}default:return()=>{}}}function ps(t){return t instanceof HTMLInputElement||t instanceof HTMLSelectElement||t instanceof HTMLTextAreaElement}function ms(t){return t instanceof HTMLInputElement&&(t.type==="checkbox"||t.type==="radio")?{value:t.value,checked:t.checked}:t instanceof HTMLSelectElement&&t.multiple?{value:Array.from(t.selectedOptions,e=>e.value)}:{value:t.value}}function Vn(t,e){if(t instanceof HTMLFormElement)return Jn(new FormData(t,e))}var Kn=new WeakMap;function gs(t,e,n){let i=Number(t.getAttribute(`data-pulse-${e}-debounce`)),s=Number(t.getAttribute(`data-pulse-${e}-throttle`));if(!(i>0)&&!(s>0)){n();return}let o=Kn.get(t);o||Kn.set(t,o=new Map);let r=o.get(e);r||o.set(e,r={});let c=r;if(i>0){clearTimeout(c.timer),c.timer=setTimeout(()=>{c.timer=void 0,n()},i);return}let a=h=>{h(),c.timer=setTimeout(()=>{c.timer=void 0;let l=c.pending;c.pending=void 0,l&&a(l)},s)};c.timer?c.pending=n:a(n)}function Es(t,e){if(t.defaultPrevented||!(t.target instanceof Element))return;let n=t.target.closest("a[href]");n instanceof HTMLAnchorElement&&vs(n,t)&&(t.preventDefault(),e.visit(n.href))}function ys(t,e){if(t.defaultPrevented)return;let n=t.target;if(!(n instanceof HTMLFormElement))return;let i=new URL(n.getAttribute("action")??"",window.location.href);if(i.origin!==window.location.origin||n.querySelector('input[type="file"]'))return;let s=new FormData(n,t.submitter),o=s.get("_method"),r=(typeof o=="string"&&o?o:n.method).toUpperCase(),c=t.submitter?.getAttribute("formenctype")||n.enctype;if(r!=="GET"&&c!==Wn)return;let a=Jn(s);t.preventDefault(),r==="GET"?e.navigate(i.pathname,{method:r,query:a,hash:i.hash}):e.navigate(i.pathname,{method:r,body:a,contentType:cs,query:i.search.slice(1),hash:i.hash})}function vs(t,e){return!(e.button!==0||e.metaKey||e.ctrlKey||e.shiftKey||e.altKey||t.target&&t.target!=="_self"||t.hasAttribute("download")||t.origin!==window.location.origin||t.hash&&t.pathname+t.search===Mt())}function Jn(t){let e=new URLSearchParams;for(let[n,i]of t)typeof i=="string"&&e.append(n,i);return e.toString()}function ws(){if(window.__pulse)return;let t=new Kt;return Gn(t),window.__pulse=t,t}ws();})();