@daz4126/helium 1.0.0-rc.3 → 1.0.0-rc.4
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.
- package/README.md +153 -33
- package/dist/helium-csp-sse.min.js +1 -1
- package/dist/helium-csp.min.js +1 -1
- package/dist/helium-lite.min.js +1 -1
- package/dist/helium-sse.min.js +1 -1
- package/dist/helium.min.js +1 -1
- package/helium-lite.js +132 -15
- package/helium.js +173 -18
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -18,7 +18,7 @@ It's really simple to use - just sprinkle the magic @attributes into your HTML a
|
|
|
18
18
|
|
|
19
19
|
Helium is designed for developers who want:
|
|
20
20
|
|
|
21
|
-
- **Lightweight** - About
|
|
21
|
+
- **Lightweight** - About 6.2–14.2KB minified and gzipped, depending on the build
|
|
22
22
|
- **Powerful** - Declarative JavaScript in your HTML
|
|
23
23
|
- **Zero build step** - Works directly in the browser with no compiling
|
|
24
24
|
- **Easy to learn** - If you know HTML and basic JavaScript, you're ready
|
|
@@ -113,11 +113,11 @@ import helium from "@daz4126/helium/csp"
|
|
|
113
113
|
| SSE | Add-on | ❌ | Add-on |
|
|
114
114
|
| Turbo integration | ✅ | ❌ | ✅ |
|
|
115
115
|
| CSP safe | ❌ | ❌ | ✅ |
|
|
116
|
-
| Approx. min+gzip size |
|
|
116
|
+
| Approx. min+gzip size | 9.62KB | 6.18KB | 13.75KB |
|
|
117
117
|
|
|
118
118
|
Sizes are enforced against the production Terser builds with gzip level 9. The
|
|
119
|
-
CSP figure includes its expression parser. Adding SSE produces
|
|
120
|
-
and
|
|
119
|
+
CSP figure includes its expression parser. Adding SSE produces 10.00KB Standard
|
|
120
|
+
and 14.12KB CSP bundles.
|
|
121
121
|
|
|
122
122
|
Lite is generated from the same global-state reactive core as Standard. It has
|
|
123
123
|
identical deep/shared reactivity, lifecycle, binding, and cleanup behavior for
|
|
@@ -1091,7 +1091,7 @@ The event object (available in event handlers):
|
|
|
1091
1091
|
```html
|
|
1092
1092
|
<div @click="console.log($event.timeStamp)">Log the timestamp</div>
|
|
1093
1093
|
<input @keydown="$event.key === 'Enter' && submit()">
|
|
1094
|
-
<form @submit="
|
|
1094
|
+
<form @submit.prevent="handleSubmit()">
|
|
1095
1095
|
```
|
|
1096
1096
|
|
|
1097
1097
|
### $dispatch
|
|
@@ -1157,6 +1157,36 @@ scope, in current DOM order:
|
|
|
1157
1157
|
<button @click="console.log($refs.item.length)">Log item count</button>
|
|
1158
1158
|
```
|
|
1159
1159
|
|
|
1160
|
+
## Expression Contract
|
|
1161
|
+
|
|
1162
|
+
Directive values are **single expressions**, in both Standard and CSP. Common
|
|
1163
|
+
expressions include property reads, assignments, function calls, object and
|
|
1164
|
+
array literals, ternaries, logical operators, and arrow functions:
|
|
1165
|
+
|
|
1166
|
+
```html
|
|
1167
|
+
<button @click="open = !open">Toggle</button>
|
|
1168
|
+
<button @click="save($data, $el)">Save</button>
|
|
1169
|
+
<p @text="loading ? 'Loading…' : message"></p>
|
|
1170
|
+
```
|
|
1171
|
+
|
|
1172
|
+
Top-level statement lists, declarations, and control-flow statements are not
|
|
1173
|
+
directive syntax. Prefer event modifiers and move multi-step behavior into a
|
|
1174
|
+
named function:
|
|
1175
|
+
|
|
1176
|
+
```html
|
|
1177
|
+
<!-- Not supported: two top-level statements -->
|
|
1178
|
+
<form @submit="$event.preventDefault(); save()"></form>
|
|
1179
|
+
|
|
1180
|
+
<!-- Preferred -->
|
|
1181
|
+
<form @submit.prevent="save($data)"></form>
|
|
1182
|
+
```
|
|
1183
|
+
|
|
1184
|
+
The Standard build uses the JavaScript expression grammar. The CSP build uses
|
|
1185
|
+
its restricted expression parser and additionally excludes `new` and some
|
|
1186
|
+
JavaScript expression forms; see the CSP build notes above. Functions declared inside
|
|
1187
|
+
an `@data` object or imported from a module are ordinary JavaScript functions
|
|
1188
|
+
and may contain statements internally.
|
|
1189
|
+
|
|
1160
1190
|
## Functions
|
|
1161
1191
|
|
|
1162
1192
|
Functions can be imported using `@import` or defined using the `@data` attribute.
|
|
@@ -1318,7 +1348,28 @@ Without keys, the entire list is re-rendered. With keys, only changed items are
|
|
|
1318
1348
|
|
|
1319
1349
|
### MutationObserver
|
|
1320
1350
|
|
|
1321
|
-
Helium automatically observes the DOM
|
|
1351
|
+
Helium automatically observes the DOM, processes new elements as they're added,
|
|
1352
|
+
and reconciles Helium directives when attributes on retained elements change.
|
|
1353
|
+
Adding, replacing, or removing an event, binding, ref, effect, initializer, or
|
|
1354
|
+
structural directive installs the new behavior and tears down the old behavior
|
|
1355
|
+
without rebuilding unrelated parts of the subtree.
|
|
1356
|
+
|
|
1357
|
+
For programmatic changes, use the `data-he-*` aliases: DOM `setAttribute()`
|
|
1358
|
+
rejects names such as `@click` in some browsers and DOM implementations even
|
|
1359
|
+
though the HTML parser accepts them.
|
|
1360
|
+
|
|
1361
|
+
```js
|
|
1362
|
+
button.setAttribute("data-he-click", "save()")
|
|
1363
|
+
button.setAttribute("data-he-click", "archive()") // replaces save
|
|
1364
|
+
button.removeAttribute("data-he-click") // removes the listener
|
|
1365
|
+
```
|
|
1366
|
+
|
|
1367
|
+
Changing local `data-he-data` recreates that local scope and re-tracks its
|
|
1368
|
+
descendant bindings. HTTP option attributes such as `data-he-target` are read
|
|
1369
|
+
when the request runs, so their current values are used automatically. Root
|
|
1370
|
+
selection and `@local-storage` remain mount-time configuration.
|
|
1371
|
+
|
|
1372
|
+
This means Helium works seamlessly with:
|
|
1322
1373
|
|
|
1323
1374
|
- Dynamically inserted content
|
|
1324
1375
|
- Content loaded via AJAX
|
|
@@ -1580,32 +1631,101 @@ intentionally absent (or still on the roadmap). Current gaps:
|
|
|
1580
1631
|
- **No transition helper** — use CSS transitions/classes directly with
|
|
1581
1632
|
`@hidden`, `@visible`, or `@if`.
|
|
1582
1633
|
|
|
1583
|
-
###
|
|
1584
|
-
|
|
1585
|
-
|
|
1586
|
-
|
|
1587
|
-
|
|
1588
|
-
|
|
1589
|
-
|
|
1590
|
-
|
|
1591
|
-
|
|
1592
|
-
|
|
1593
|
-
|
|
1594
|
-
|
|
1595
|
-
|
|
1596
|
-
|
|
1597
|
-
|
|
1598
|
-
|
|
1599
|
-
|
|
1600
|
-
|
|
1601
|
-
|
|
1602
|
-
|
|
1603
|
-
|
|
1604
|
-
|
|
1605
|
-
|
|
1606
|
-
|
|
1607
|
-
|
|
1608
|
-
|
|
1634
|
+
### Stimulus-parity roadmap
|
|
1635
|
+
|
|
1636
|
+
The goal is not to copy Stimulus's controller syntax. Simple behavior should
|
|
1637
|
+
remain local (`@click="open = !open"`, `@bind="name"`); the roadmap supplies the
|
|
1638
|
+
lifecycle and JavaScript escape hatches needed when behavior becomes complex.
|
|
1639
|
+
|
|
1640
|
+
#### P0 — 1.0 release foundations
|
|
1641
|
+
|
|
1642
|
+
- [x] **Define the expression and function-context contract.** Directive values
|
|
1643
|
+
are expressions; multi-step work belongs in named functions with `$data`,
|
|
1644
|
+
`$el`, refs, and other required context passed explicitly.
|
|
1645
|
+
- [x] **Reconcile directive attributes on retained elements.** Attribute add,
|
|
1646
|
+
replace, and removal now install and tear down bindings, events, refs,
|
|
1647
|
+
initializers, local data, and structural directives independently.
|
|
1648
|
+
- [x] **Run the production browser suite in Chromium, Firefox, and WebKit.** Keep
|
|
1649
|
+
the same CSP, Turbo, SSE, keyed identity, dynamic-directive, late-import,
|
|
1650
|
+
Lite, and entry-point checks in every engine.
|
|
1651
|
+
|
|
1652
|
+
#### P1 — complex-behavior escape hatches
|
|
1653
|
+
|
|
1654
|
+
1. **Formalize lifecycle modules over `@init`.** Document the existing
|
|
1655
|
+
`@import` + `@init` setup-function convention: imported setup receives its
|
|
1656
|
+
required element, state, refs, and dispatch context explicitly and returns
|
|
1657
|
+
cleanup. Keep ordinary behavior inline and move only complex imperative work
|
|
1658
|
+
into a lifecycle module.
|
|
1659
|
+
|
|
1660
|
+
```js
|
|
1661
|
+
export function connectFeature(element, data, refs) {
|
|
1662
|
+
// setup
|
|
1663
|
+
return () => {
|
|
1664
|
+
// cleanup
|
|
1665
|
+
}
|
|
1666
|
+
}
|
|
1667
|
+
```
|
|
1668
|
+
|
|
1669
|
+
2. **Formally support and test namespaced initializers.** Allow independent
|
|
1670
|
+
behaviors such as `@init:editor` and `@init:tooltip` on one element, with
|
|
1671
|
+
isolated replacement and cleanup when either attribute changes.
|
|
1672
|
+
|
|
1673
|
+
```html
|
|
1674
|
+
<div
|
|
1675
|
+
@init:editor="connectEditor($el, $data, $refs)"
|
|
1676
|
+
@init:tooltip="connectTooltip($el)"
|
|
1677
|
+
></div>
|
|
1678
|
+
```
|
|
1679
|
+
|
|
1680
|
+
3. **Add unified lifecycle error handling.** Route initializer setup, async
|
|
1681
|
+
rejection, cleanup, binding, event, import, and request failures through an
|
|
1682
|
+
instance-level `handleError(error, context)` hook and optional debug mode.
|
|
1683
|
+
4. **Add an initializer-scoped `AbortSignal`.** Give each initializer a signal
|
|
1684
|
+
that aborts when its attribute is replaced, removed, its element disconnects,
|
|
1685
|
+
or its Helium root unmounts, so listeners and pending external work can use
|
|
1686
|
+
native cancellation.
|
|
1687
|
+
5. **Support asynchronous setup and cleanup safely.** Recognize setup promises,
|
|
1688
|
+
avoid registering stale results after disconnection or replacement, run a
|
|
1689
|
+
cleanup returned asynchronously, and report rejected setup/cleanup through
|
|
1690
|
+
the lifecycle error hook.
|
|
1691
|
+
6. **Add programmatic `watch()`.** Let imported setup functions observe reactive
|
|
1692
|
+
state without exporting update functions or storing external instances in a
|
|
1693
|
+
module-level `WeakMap`; include current/previous values and lifecycle-bound
|
|
1694
|
+
cleanup. Keep middleware separate and lower priority.
|
|
1695
|
+
7. **Publish TypeScript declarations** for mounting, factories, expression
|
|
1696
|
+
engines, CSP globals, SSE, lifecycle errors, initializer context, signals,
|
|
1697
|
+
and watching.
|
|
1698
|
+
|
|
1699
|
+
#### P2 — lifecycle depth and application maturity
|
|
1700
|
+
|
|
1701
|
+
8. **Observe ref collections** so complex behaviors can react when matching
|
|
1702
|
+
refs connect, disconnect, or reorder; this covers Stimulus target callbacks
|
|
1703
|
+
without changing simple `$ref`/`$refs` usage.
|
|
1704
|
+
9. **Complete the HTTP lifecycle:** request cancellation with `AbortController`,
|
|
1705
|
+
explicit success/error hooks, consistent `@loading` restoration, and opt-in
|
|
1706
|
+
required-CSRF validation for state-changing same-origin requests.
|
|
1707
|
+
10. **Evaluate behavior lookup only after lifecycle modules are established.**
|
|
1708
|
+
Prefer `$dispatch` for loose coordination; add outlet-like instance lookup
|
|
1709
|
+
only if real applications require direct behavior-to-behavior calls.
|
|
1710
|
+
|
|
1711
|
+
#### P3 — evidence-driven conveniences
|
|
1712
|
+
|
|
1713
|
+
11. **Document complete validation and error-state patterns** covering native
|
|
1714
|
+
constraint validation, HTTP failure, retry, accessible messages, and stale
|
|
1715
|
+
error clearing before adding validation helpers.
|
|
1716
|
+
12. **Consider extensible event modifiers and structured action parameters.**
|
|
1717
|
+
Expressions already cover most cases, so add APIs only for repeated needs.
|
|
1718
|
+
13. **Revisit `@use`, debounced binding, middleware, transitions, and a shared
|
|
1719
|
+
store** only with concrete use cases and explicit size budgets. Event
|
|
1720
|
+
debouncing, CSS transitions, custom events, and independent roots cover the
|
|
1721
|
+
common forms today. Add `@use` only if lifecycle modules reveal a need for
|
|
1722
|
+
behavior registration, private instances, or package interoperability
|
|
1723
|
+
beyond namespaced `@init`.
|
|
1724
|
+
|
|
1725
|
+
This ordering moves the former HTTP/form-heavy roadmap behind lifecycle,
|
|
1726
|
+
diagnostics, watching, and types. The HTTP, CSRF, loading, validation, and error
|
|
1727
|
+
example work remains planned, but it does not by itself close the most important
|
|
1728
|
+
Stimulus-parity gaps.
|
|
1609
1729
|
|
|
1610
1730
|
## Contributing
|
|
1611
1731
|
|
|
@@ -1617,7 +1737,7 @@ Helium is open source! Contributions, issues, and feature requests are welcome.
|
|
|
1617
1737
|
|
|
1618
1738
|
Before submitting a change, run `npm run check`. It executes the full jsdom test
|
|
1619
1739
|
suite, creates the production bundles, smoke-tests them, and fails if any gzip
|
|
1620
|
-
size budget is exceeded. `npm run test:browser` runs the
|
|
1740
|
+
size budget is exceeded. `npm run test:browser` runs the cross-browser smoke suite
|
|
1621
1741
|
used by CI for CSP, Turbo, SSE, keyed focus preservation, late imports, Lite
|
|
1622
1742
|
generation, and browser entry imports. `npm run check:ci` runs both paths.
|
|
1623
1743
|
`npm run size` also reports raw, gzip, and Brotli sizes.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
var t=t=>{if("string"!=typeof t)return t;try{return JSON.parse(t)}catch{return t}},e=t=>{const e=String(t).trim(),n=+e;return e&&!isNaN(n)?n:t},n=t=>/^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(t),r=new Set(["undefined","null","true","false","NaN","Infinity","this","arguments"]),s={form:"submit",input:"input",textarea:"input",select:"change"},i={shift:"shiftKey",ctrl:"ctrlKey",alt:"altKey",meta:"metaKey"},o=new Set(["prevent","once","outside","document","window","self","capture","passive","stop"]),c=t=>!(o.has(t)||t.startsWith("debounce")||t.startsWith("throttle")||i[t]),a=new Set(["name","length","status","top","origin","event","closed","parent"]),l=t=>s[t.tagName.toLowerCase()]||"click",u=(t,e)=>{let n;const r=(...r)=>(clearTimeout(n),n=setTimeout(t,e,...r));return r.cancel=()=>clearTimeout(n),r},h=(t,e)=>{let n,r,s;const i=()=>{r=0,n=Date.now(),t(...s)},o=(...o)=>{if(null==n)return n=Date.now(),t(...o);s=o;const c=e-(Date.now()-n);if(c<=0)return clearTimeout(r),r=0,n=Date.now(),t(...o);r||(r=setTimeout(i,c))};return o.cancel=()=>{clearTimeout(r),r=0},o},f=t=>{if(!t||"object"!=typeof t)return!1;if(Array.isArray(t))return!0;const e=Object.getPrototypeOf(t);return e===Object.prototype||null===e},d=Symbol("raw"),p=t=>t&&"object"==typeof t&&t[d]||t,w=t=>{const e=t.match(/^\s*([\w$]+)(?:\s*,\s*([\w$]+))?\s+in\s+(.+)$/);return e&&n(e[1])&&(!e[2]||n(e[2]))?[e[1],e[2],e[3]]:null},m=null,$={diagnosticName:"standard",compile(t,e=!0){try{const n=new Function("$ctx",e?`with($ctx){with($ctx.$data){return(${t.trim()})}}`:`with($ctx){with($ctx.$data){${t.trim()}}}`);return{execute:t=>n(t),getIds:null}}catch(e){return{execute:()=>t,getIds:null,error:e}}},createScope:t=>({$:t.$,$data:t.state,$event:t.event,$el:t.el,$root:t.rootElement,$scope:t.scopeElement,$refs:t.pluralRefs,$dispatch:t.dispatch,$html:t.html,$get:t.get,$post:t.post,$put:t.put,$patch:t.patch,$delete:t.del,...t.refs})};function b(s={}){const o=s.engine??$,y=o.diagnosticName||"helium",g=s.sse,v=s.root,k=t=>{try{const e=o.compile(t,!0),n=o.createScope?o.createScope({state:{},el:null,event:{},refs:{},$:null,html:null,get:null,post:null,put:null,patch:null,del:null}):{};return e.execute(n)}catch{return t}},S=(t,...e)=>{const n=t.split(/[.:]/)[0];return":"!==n&&""!==n&&e.some(t=>n===`@${t}`||n==="data-he-"+t)};let x=null,I=0;return{helium:async function(s={}){const $=++I,b=()=>$===I,E=Symbol("all"),T=("string"==typeof v?document.querySelector(v):v)||document.querySelector("[\\@helium]")||document.querySelector("[data-helium]")||document.body;if(!T)throw Error("No root");const M=T.getAttribute("@local-storage")||T.getAttribute("data-he-local-storage");x&&(x.t?.disconnect(),x.i?.(x.root)),x={t:null,o:new Map,refs:new Map,listeners:new WeakMap,l:new WeakMap,u:new WeakSet,h:new WeakMap,p:new Map,m:new WeakMap,warnedCompiles:new Set,v:new WeakMap},x.root=T;const j=t=>Object.assign(document.createElement("template"),{innerHTML:String(t).trim()}).content.firstChild,N=(t,e,n,r,s=T)=>{if(!b())return[];const i=[];return(e||[]).forEach((e,o)=>{const c=e instanceof Node?e:st(s,e.trim())[0]||document.querySelector(e.trim());if(c){const e=r?r(t):t,s=n?.[o];if(s){const t=j(e);c["replace"==s?"replaceWith":s](t),i.push(t)}else c.innerHTML=e,i.push(c)}else K[e]=t}),i},O=(t,e,n={},r={},s=T)=>{if(n.loading){const t=N(n.loading,n.target,n.action,void 0,s);t.length&&(n.target=t)}const i=r instanceof FormData,o=document.querySelector('meta[name="csrf-token"]')?.content,c=new URL(t,window.location.href).origin===window.location.origin;let a=t;if("GET"===e&&!i&&r&&"object"==typeof r){const e=new URLSearchParams(r).toString();e&&(a+=(t.includes("?")?"&":"?")+e)}const l=t=>fetch(a,{method:e,headers:{Accept:"text/event-stream,text/vnd.turbo-stream.html,application/json,text/html",...!i&&"GET"!==e&&{"Content-Type":"application/json"},...c&&o?{"X-CSRF-Token":o}:{},...t?{"Last-Event-ID":t}:{}},body:"GET"===e?null:i?r:JSON.stringify(r),credentials:c?"same-origin":"omit"}).then(t=>{if(!1===t.ok){const e=new Error(`HTTP ${t.status}${t.statusText?" "+t.statusText:""}`);throw e.status=t.status,e.response=t,e}const e=t.headers.get("content-type")||"";if(e.includes("event-stream")){const e=g||m;if(!e)throw new Error("SSE support requires @daz4126/helium/sse");return e(t,n,l,(...t)=>N(...t,s),b)}return e.includes("turbo-stream")?t.text().then(t=>({turbo:!0,data:t})):e.includes("json")?t.json():t.text()}).then(t=>{if(void 0!==t)return t&&"object"==typeof t&&t.turbo&&window.Turbo?Turbo.renderStreamMessage(t.data):N(t,n.target,n.loading?(n.action||[]).map(t=>t&&"replace"):n.action,n.template,s)});return l(null)},_=t=>"string"==typeof t?{target:[t],action:[null]}:t,[R,D,A,P]=["POST","PUT","PATCH","DELETE"].map(t=>(e,n,r={},s=T)=>O(e,t,_(r),n,s)),L=new Set;let C=0;const H=new WeakMap,U=t=>{if((t.el===T||T.contains(t.el))&&!L.has(t)){L.add(t);try{dt(t)}finally{L.delete(t)}}};let F=new Set,z=new Set,W=!1;const G=()=>{let t=0;for(;F.size&&b();){if(++t>100){F.clear(),console.error("Helium: infinite update loop — bindings kept writing state for 100 consecutive passes");break}const e=F;F=new Set;const n=new Set;e.forEach(t=>x.o.get(t)?.forEach(t=>{(t.k||t.loop||t.cond)&&n.add(t)})),e.forEach(t=>x.o.get(t)?.forEach(t=>n.add(t))),n.forEach(U)}z.clear(),W=!1},J=t=>{t.forEach(t=>F.add(t)),F.add(E),W||(W=!0,queueMicrotask(G))},B={has:(t,e)=>!("string"==typeof e&&e.startsWith("$")||!Reflect.has(t,e)&&!a.has(e)&&void 0!==globalThis[e]),get(t,e,n){if(e===d)return t;const r=Reflect.get(t,e,n);if(!b()||!f(r))return r;let s=x.h.get(r);if(s||x.h.set(r,s=[]),s.some(n=>n.key===e&&n.parent===t)||s.push({key:e,parent:t}),x.m.has(r))return x.m.get(r);const i=new Proxy(r,B);return x.m.set(r,i),i},set:(t,e,n)=>{const r=!Object.is(Reflect.get(t,e),n),s=Reflect.set(t,e,n);if(!b()||!r)return s;const i=new Set([e]),o=new Set;z.add(t);let c=x.h.get(t)||[];for(;c.length;){const t=[];for(const{key:e,parent:n}of c)if(i.add(e),n&&!o.has(n)){o.add(n),z.add(n);const e=x.h.get(n);e&&t.push(...e)}c=t}return J(i),Z?.(),s}},K=new Proxy({},B),Z=M?u(()=>b()&&localStorage.setItem(M,JSON.stringify(K)),0):null;Object.assign(K,s);const q=(t,e)=>{const n=e?[e]:[];for(;t;t=t.parentNode){const e=x.v.get(t);e&&n.push(...e.slice().reverse())}return n},X=(t,e)=>t.find(t=>((t,e)=>Object.prototype.hasOwnProperty.call(t,e))(t.values,e)),V=(t,e)=>(t.tokens.has(e)||t.tokens.set(e,{scope:t,S:e}),t.tokens.get(e)),Q=t=>J([t]),Y=(t,e=null)=>{const n={values:null,tokens:new Map,I:e};return n.values=((t,e)=>{const n={...t},r=new WeakMap,s=new WeakMap,i=(t,n)=>{if(!f(t))return t;let o=s.get(t);if(o||s.set(t,o=new Set),o.add(n),r.has(t))return r.get(t);const c=new Proxy(t,{get(t,e,n){if(e===d)return p(t);let r=Reflect.get(t,e,n);return s.get(t).forEach(t=>r=i(r,t)),r},set(t,n,r,i){const o=Reflect.set(t,n,r,i);return z.add(p(t)),s.get(t).forEach(t=>Q(V(e,t))),o}});return r.set(t,c),c};return new Proxy(n,{get:(t,e,n)=>e===d?t:i(Reflect.get(t,e,n),e),set(t,n,r,s){const i=Reflect.set(t,n,r,s);return Q(V(e,n)),i}})})(t,n),n},tt=(t,e)=>x.v.set(t,[...x.v.get(t)||[],e]),et=(t,e,n)=>{const r=e.split(".").map(t=>t.trim()),s=r.pop();let i=K;const o=X(q(t),r[0]??s);o&&(i=o.values);for(const t of r)i=i?.[t];return i&&"object"==typeof i?Reflect.set(i,s,n):(console.error(`Helium: cannot set "${e}" — "${r.join(".")}" is not an object`),!1)},nt=t=>{for(let e=t;e&&e!==T.parentNode;e=e.parentNode){const t=x.v.get(e)||[];for(let e=t.length-1;e>=0;e--)if(t[e].I)return t[e].I;if(e===T)break}return T},rt=(t,e)=>[...x.refs.get(t)||[]].filter(t=>(t===T||T.contains(t))&&nt(t)===e).sort((t,e)=>t===e?0:t.compareDocumentPosition(e)&Node.DOCUMENT_POSITION_FOLLOWING?-1:1),st=(t,e)=>{const n=e.startsWith("$")?e:`$${e}`;for(const e of(t=>{const e=[];let n=nt(t);for(;n&&(e.push(n),n!==T);)n=nt(n.parentNode);return e})(t)){const t=rt(n,e);if(t.length)return t}return[]},it=new WeakMap,ot=t=>{const e=nt(t);if(it.has(e))return it.get(e);const n=t=>document.querySelector(t);return n.all=t=>[...document.querySelectorAll(t)],(n.root=t=>T.querySelector(t)).all=t=>[...T.querySelectorAll(t)],(n.scope=t=>e.querySelector(t)).all=t=>[...e.querySelectorAll(t)],it.set(e,n),n},ct=(t,e={},n=K,r,s)=>{let i=n;const c=q(t,r);c.length&&(i=new Proxy(n,{has:(t,e)=>!!X(c,e)||Reflect.has(t,e),get:(t,e,n)=>{const r=X(c,e);if(!r)return Reflect.get(t,e,n);const i=r.values[e];return s?.set(V(r,e),i),i},set:(t,e,n,r)=>{const s=X(c,e);return s?Reflect.set(s.values,e,n):Reflect.set(t,e,n,r)}}));const a=(t=>{const e=nt(t),n=H.get(e);if(n?.T===C)return n;const r={};for(const e of x.refs.keys()){const n=st(t,e);n.length&&(r[e]=n[0])}const s=new Proxy({},{get:(t,n)=>"string"==typeof n?st(e,n):void 0}),i={T:C,M:r,j:s};return H.set(e,i),i})(t);return o.createScope({$:ot(t),state:i,event:e,el:t,rootElement:T,scopeElement:nt(t),pluralRefs:a.j,dispatch:(e,n={},r={})=>{const s=new CustomEvent(e,{detail:n,bubbles:r.bubbles??!0,cancelable:r.cancelable??!0});return(r.target||t).dispatchEvent(s),s},html:j,get:(e,n)=>((t,e={},n=T)=>O(t,"GET",_(e),{},n))(e,n,t),post:(e,n,r)=>R(e,n,r,t),put:(e,n,r)=>D(e,n,r,t),patch:(e,n,r)=>A(e,n,r,t),del:(e,n,r)=>P(e,n,r,t),refs:a.M})},at=(t,e=!0,n)=>{const r=`${e}:${t}`,s=(t=>"string"==typeof t?{label:t}:t||{})(n);let i=x.p.get(r);return i||(i=o.compile(t,e),x.p.set(r,i)),((t,e,n)=>{if(!e.error||!n.strict&&!(t=>{const e=String(t).trim();return/=>|&&|\|\||\?\?/.test(e)||/[()[\]{}]/.test(e)||/(?:^|\s)[+\-*/%](?:\s|$)/.test(e)||/(?:^|\s)(?:={1,3}|!==?|<=?|>=?)(?:\s|$)/.test(e)||/\s\?\s/.test(e)||/^\s*[`'"]|[`'"]\s*$/.test(e)||/\b[$A-Za-z_][\w$]*\s*\.\s*(?:[$A-Za-z_][\w$]*|\s*$)/.test(e)||/^[+-]{2}|[+-]{2}$/.test(e)})(t))return;const r=(t=>[t.build||y,t.label].filter(Boolean).join(" "))(n),s=`${r}:${t}:${e.error.message}`;x.warnedCompiles.has(s)||(x.warnedCompiles.add(s),console.warn(`Helium expression compile warning${r?` [${r}]`:""}:`,t,e.error.message))})(t,i,s),i},lt=(t,e={},n=t.el)=>{const r=new Map,s=(t,e=null)=>new Proxy(t,{has:(t,n)=>null===e?B.has(t,n):Reflect.has(t,n),get(t,n,i){if(n===d)return p(t);const o=Reflect.get(t,n,i);return null!==e||"string"!=typeof n||r.has(n)||r.set(n,o),f(o)?s(o,e??n):o}});try{const i=t.N.execute(ct(n,e,s(K),null,r)),o=[...r].filter(([t,e])=>"string"!=typeof t?t.scope.values[t.S]===e:K[t]===e).map(([t])=>t);let c=t.keys||[];c=c.map(e=>{const n=X(q(t.el),e);return n?V(n,e):e});const a=t.keys?.includes("*")?[E]:o.concat(c);return((t,e)=>{const n=new Set(e);t.O?.forEach(e=>{if(n.has(e))return;const r=x.o.get(e)?.filter(e=>e!==t)||[];r.length?x.o.set(e,r):x.o.delete(e)}),n.forEach(e=>{if(t.O?.has(e))return;const n=x.o.get(e)||[];x.o.set(e,t.k||t.loop||t.cond?[t,...n]:[...n,t])}),t.O=n})(t,a),{ok:!0,result:i}}catch(t){return console.error("Helium expression error:",t.message),{ok:!1}}},ut=t=>{t.length&&mt(t).then(({o:t,_:e})=>{b()&&(t.forEach(U),wt(e))})},ht=(t,e)=>{const n=t.loop,r=n[4],s=new Map,i=p(e),o=i!==e?e:null,c=Array.from(i||[]),a=n[5],l=a?null:{values:null,tokens:new Map},u=a?null:ct(t.el,{},K,l),h=new Map;r.forEach(t=>h.set(t,h.size));const f=[];c.forEach((t,e)=>{const c=p(t),h={[n[0]]:c};let d;if(n[1]&&(h[n[1]]=e),a){d=h[a[0]];for(let t=1;t<a.length;t++)d=d?.[a[t]]}else l.values=h,d=n[2].execute(u);if(s.has(d))return void console.error("Duplicate key:",d);if(o&&c&&"object"==typeof c){let t=x.h.get(c);t||x.h.set(c,t=[]);const n=String(e);t.some(t=>t.key===n&&t.parent===i)||t.push({key:n,parent:i})}let w=r.get(d);if(w)(w.item!==c||z.has(c))&&(w.scope.values[n[0]]=o?o[e]:t),n[1]&&w.index!==e&&(w.scope.values[n[1]]=e);else{h[n[0]]=o?o[e]:t;const r=n[3].cloneNode(!0);w={nodes:[...r.childNodes],scope:Y(h)},w.nodes.forEach(t=>{1===t.nodeType&&(tt(t,w.scope),f.push(t))})}w.item=c,w.index=e,s.set(d,w)});const d=[];r.forEach((t,e)=>{s.has(e)||t.nodes.forEach(t=>{1===t.nodeType&&d.push(t),t.remove()})}),pt(d),n[4]=s;const w=[...s.values()],m=(t=>{const e=[],n=new Array(t.length).fill(-1);t.forEach((r,s)=>{if(-1===r)return;let i=0,o=e.length;for(;i<o;){const n=i+o>>1;t[e[n]]<r?i=n+1:o=n}i>0&&(n[s]=e[i-1]),e[i]=s});const r=new Set;for(let t=e.length?e[e.length-1]:-1;-1!==t;t=n[t])r.add(t);return r})(w.map(t=>h.get(t)??-1));let $=t.el;w.forEach((t,e)=>t.nodes.forEach(t=>{m.has(e)||$.nextSibling===t||$.after(t),$=t})),ut(f)},ft=(t,e)=>{const n=t.cond[1];if(e&&!n.length){const e=t.cond[1]=[...t.cond[0].cloneNode(!0).childNodes],n=x.v.get(t.el);let r=t.el;e.forEach(t=>{1===t.nodeType&&n&&x.v.set(t,[...n]),r.after(t),r=t}),ut(e.filter(t=>1===t.nodeType))}else!e&&n.length&&(pt(n.filter(t=>1===t.nodeType)),n.forEach(t=>t.remove()),t.cond[1]=[])};function dt(e,n={},r=e.el){const{el:s,S:i,k:o,R:c}=e,a=e.D||lt(e,n,r);if(delete e.D,!a.ok)return;const l=a.result;if(e.loop)return ht(e,l);if(e.cond)return ft(e,l);if(o&&et(s,o,l),"innerHTML"===i){const t=Array.isArray(l)?l.join``:l;return"object"==typeof Idiomorph?Idiomorph.morph(s,t,{morphStyle:"innerHTML"}):s.innerHTML=t}if("class"===i&&l&&"object"==typeof l){const t=new Set;return Object.entries(l).forEach(([e,n])=>e.split(/\s+/).filter(Boolean).forEach(e=>{t.add(e),s.classList.toggle(e,!!n)})),e.A?.forEach(e=>{t.has(e)||s.classList.remove(e)}),void(e.A=t)}if("style"===i&&l&&"object"==typeof l)return s.style.cssText=Object.entries(l).filter(([t,e])=>null!=e&&!1!==e).map(([t,e])=>`${t.replace(/[A-Z]/g,t=>"-"+t.toLowerCase())}:${e}`).join("; ");"hidden"!==i?i in s?"radio"===s.type&&"checked"!==i?s.checked=s.value===l:s[i]="textContent"===i?l??"":t(l):s.setAttribute(i,t(l)):s.hidden=c?!!l:!l}const pt=t=>{const e=new Set;if((Array.isArray(t)?t:[t]).forEach(t=>{e.add(t),t.querySelectorAll("*").forEach(t=>e.add(t))}),e.size){e.forEach(t=>{const e=x.l.get(t);x.l.delete(t),e?.forEach(t=>{try{t()}catch(t){console.error("Helium cleanup:",t)}}),x.listeners.get(t)?.forEach(({receiver:t,event:e,P:n,options:r})=>{n.cancel?.(),t.removeEventListener(e,n,r)}),x.listeners.delete(t),x.u.delete(t),x.v.delete(t)});for(const[t,n]of x.refs){let r=!1;for(const t of n)e.has(t)&&(r=n.delete(t)||r);n.size||x.refs.delete(t),r&&C++}x.o.forEach((t,n)=>{const r=t.filter(t=>!e.has(t.el));r.length?x.o.set(n,r):x.o.delete(n)})}},wt=t=>t.forEach(({N:t,el:e})=>{let n;try{n=t.execute(ct(e))}catch(t){return void console.error("Helium @init error:",t.message)}"function"==typeof n&&x.l.set(e,[...x.l.get(e)||[],n])});async function mt(t){const s=[],o=[],a=[],d=Array.isArray(t)?t:[t],p=d.flatMap(t=>[t,...t.querySelectorAll("*")]).filter(t=>{if(x.u.has(t))return!1;for(let e=0;e<t.attributes.length;e++){const n=t.attributes[e].name;if("@"===n[0]||":"===n[0]||n.startsWith("data-he"))return!0}return!1});d.forEach(t=>x.u.add(t));const m=[];return p.forEach(t=>{const e=t.getAttribute("@import")||t.getAttribute("data-he-import");e&&e.split(",").map(t=>t.trim()).forEach(t=>{const e=t.startsWith("http://")||t.startsWith("https://"),n=t.endsWith(".js"),r=t.startsWith("/")||t.startsWith("./")||t.startsWith("../"),s=e?t:new URL((e||r?"":"./")+t+(e||n?"":".js"),location.href).href;m.push(import(s).then(t=>{Object.keys(t).forEach(e=>K[e]=t[e])}).catch(t=>{console.error(`Failed to import module: ${s}`,t.message)}))})}),m.length>0&&await Promise.all(m),b()?(p.forEach(t=>{const s=t.getAttribute("@data")??t.getAttribute("data-he-data")??t.getAttribute("data-he");if(null!=s)try{const e=at(s,!0,{label:"@data",strict:!0}).execute(ct(t));!f(e)||Array.isArray(e)?console.warn("Helium @data expects an object:",s):t===T?Object.assign(K,e):tt(t,Y(e,t))}catch(t){console.warn("Helium @data error:",t.message)}x.u.add(t);const d=t.attributes,p=e=>{const n=at(e,!0,{label:"HTTP option",strict:!0}),r=ct(t);return n.execute(r)},m=t.type?.toLowerCase(),$="checkbox"==m,y="radio"==m,g="SELECT"==t.tagName,v=t.getAttribute("@for")??t.getAttribute("data-he-for");for(let s=0;s<d.length;s++){const{name:f,value:m}=d[s];if("@"!==f[0]&&":"!==f[0]&&!f.startsWith("data-he"))continue;if(":key"===f&&null!=v)continue;let I=!1;if(I=!!X(q(t),m),S(f,"text","html","bind")&&n(m)&&!r.has(m)&&!I&&null==K[m]&&(K[m]=S(f,"bind")?"checkbox"==t.type?t.checked:e(t.value):e(t.textContent)),!S(f,"data")&&"data-he"!==f)if(S(f,"for")){const e=w(m),n=t.getAttribute(":key");if("TEMPLATE"===t.tagName&&e&&n){const r=/^[\w$]+(\.[\w$]+)*$/.test(n.trim())?n.trim().split("."):null;o.push({el:t,S:null,N:at(e[2],!0,{label:"@for",strict:!0}),loop:[e[0],e[1],at(n,!0,{label:":key",strict:!0}),t.content.cloneNode(!0),new Map,!r||r[0]!==e[0]&&r[0]!==e[1]?null:r]})}else console.error("Invalid @for/:key")}else if(S(f,"if"))"TEMPLATE"!==t.tagName||null!=v?console.error("@if requires a <template> element without @for"):o.push({el:t,S:null,N:at(m,!0,{label:"@if",strict:!0}),cond:[t.content.cloneNode(!0),[]]});else{if(S(f,"for","if"))continue;if(f.startsWith(":")||f.startsWith("data-he-attr:")){const e=f.startsWith(":")?f.slice(1):f.slice(13);o.push({el:t,S:e,N:at(m,!0,{label:f})})}else if(S(f,"ref")){const e="$"+m;x.refs.has(e)||x.refs.set(e,new Set),x.refs.get(e).has(t)||(x.refs.get(e).add(t),C++)}else if(S(f,"text","html"))o.push({el:t,S:S(f,"text")?"textContent":"innerHTML",N:at(m,!0,{label:f})});else if(S(f,"bind")){const e=$||y||g||f.includes(".lazy")?"change":"input",n=$?"checked":"value",r=t=>(t=f.includes(".trim")?t.trim():t,f.includes(".number")&&""!==t&&!isNaN(+t)?+t:t),s=e=>et(t,m,$?e.target.checked:r(e.target.value));t.addEventListener(e,s),x.listeners.has(t)||x.listeners.set(t,[]),x.listeners.get(t).push({receiver:t,event:e,P:s}),o.push({el:t,S:n,N:at(m,!0,{label:f})}),$?t.checked=!!K[m]:y?t.checked=t.value==K[m]:t.value=K[m]??""}else if(S(f,"hidden","visible")){const e=S(f,"hidden");o.push({el:t,S:"hidden",N:at(m,!0,{label:f,strict:!0}),R:e})}else if(S(f,"calculate")){const e=f.split(":")[1];let n=null;n=X(q(t),e),n||e in K||(K[e]=void 0),o.push({el:t,k:e,S:null,N:at(m,!0,{label:f,strict:!0})})}else if(S(f,"effect"))o.push({el:t,S:null,N:at(m,!0,{label:f,strict:!0}),keys:f.split(":").slice(1)});else if(S(f,"init"))a.push({N:at(m,!0,{label:f,strict:!0}),el:t});else if(f.startsWith("@")||f.startsWith("data-he")){const e=f.startsWith("@")?f.slice(1):f.slice(8),[n,...r]=e.split(".");let s=n;const o=["get","post","put","patch","delete"].includes(n);if(o&&(s=l(t)),r.includes("passive")&&r.includes("prevent")){const t=`event-options:${f}`;x.warnedCompiles.has(t)||(x.warnedCompiles.add(t),console.warn(`Helium event modifier warning [${f}]: .passive and .prevent cannot be combined`));continue}const a=r.includes("outside")||r.includes("document")?document:r.includes("window")?window:t,d=r.find(t=>t.startsWith("debounce")),w=d?(t=>t&&!isNaN(t)?Number(t):300)(d.split(":")[1]):0,y=r.find(t=>t.startsWith("throttle")),g=y?(t=>t&&!isNaN(t)?Number(t):300)(y.split(":")[1]):0,v=r.includes("passive")?{passive:!0,capture:r.includes("capture")}:r.includes("capture"),S=e=>{if(o){const r=e=>t.getAttribute("data-he-"+e)||t.getAttribute("@"+e),s=r("target"),i=s?s.split(",").map(t=>t.split(":").map(t=>t.trim())):[],o=i.map(([t])=>t),c=i.map(([,t])=>t),a={...r("options")&&k(r("options")||"{}"),...s&&{target:o},...s&&{action:c},...r("template")&&{template:p(r("template"))},...r("loading")&&{loading:p(r("loading"))}};let l=r("params");if(!l&&t.hasAttribute("name")?l=t.getAttribute("name").match(/\w+/g).map(t=>`${t}:`).join``+($?"checked":"value"):l||(l="{}"),!l.trim().startsWith("{")&&l.includes(":")){const e=l.split(":").map(t=>t.trim());l=e.reduceRight((e,n,r)=>`{ ${n}: ${1==r?`'${t[e]}'`:e} }`)}const u=ct(t,e),h=at(l,!0,{label:"@params",strict:!0}).execute(u);O(m,n.toUpperCase(),a,h,t).catch(t=>console.error("AJAX:",t.message))}else{const n=ct(t,e),r=at(m,!0,{label:f,strict:!0}).execute(n);r&&"function"==typeof r.then&&r.catch(t=>console.error("AJAX:",t.message))}r.includes("once")&&a.removeEventListener(s,E,v)},I=w>0?u(S,w):g>0?h(S,g):S,E=e=>{if(b()){for(const[t,n]of Object.entries(i))if(r.includes(t)&&!e[n])return;if(["keydown","keyup","keypress"].includes(s)){const t=r.find(c);if(t&&(" "==e.key?"Space":"Escape"==e.key?"Esc":e.key).toLowerCase()!==t.toLowerCase())return}r.includes("outside")&&t.contains(e.target)||r.includes("self")&&e.target!==t||(r.includes("prevent")&&e.preventDefault(),r.includes("stop")&&e.stopPropagation(),I(e))}};E.cancel=I.cancel,a.addEventListener(s,E,v),x.listeners.has(t)||x.listeners.set(t,[]),x.listeners.get(t).push({receiver:a,event:s,P:E,options:v})}}}}),o.forEach(t=>{t.D=lt(t),t.k||t.loop||t.cond?s.unshift(t):s.push(t)}),{o:s,_:a}):{o:[],_:[]}}x.i=pt,x.t?.disconnect(),x.t=new MutationObserver(async t=>{if(!b())return;x.refs.size&&C++;const e=[];for(const n of t)n.removedNodes.forEach(t=>1===t.nodeType&&!T.contains(t)&&e.push(t));pt(e);for(const e of t)for(const t of e.addedNodes)if(1===t.nodeType&&T.contains(t)&&!x.u.has(t)){const{o:e,_:n}=await mt(t);if(!T.contains(t))continue;e.forEach(t=>dt(t)),wt(n)}}),x.t.observe(T,{childList:!0,subtree:!0});const $t=M?(()=>{try{return JSON.parse(localStorage.getItem(M))}catch{return null}})():null,{o:bt,_:yt}=await mt(T);return b()?($t&&Object.assign(K,$t),bt.forEach(t=>dt(t)),wt(yt),K):K},heliumTeardown:function(){I++,x?.t&&(x.t.disconnect(),x.i?.(x.root)),x=null},mount:async function(t,e){const n="string"==typeof t?document.querySelector(t):t;if(!n)throw Error("No root");const r=b({...s,root:n});return{state:await r.helium(e),unmount:r.heliumTeardown}}}}var{helium:y,heliumTeardown:g,mount:v}=b(),k=!1,S=!1,x=null;function I(){S=!0,null!==x&&(clearTimeout(x),x=null)}function E(t){return I(),y(t)}if(E.mount=function(t,e){return I(),v(t,e)},"undefined"!=typeof window&&(window.helium=E,window.heliumTeardown=function(){I(),g()}),"undefined"!=typeof document){const t=()=>{x=null,k||S||E()};"loading"===document.readyState?document.addEventListener("DOMContentLoaded",t,{once:!0}):x=setTimeout(t,0),document.addEventListener("turbo:before-render",t=>{k||(g(),S=!1)}),document.addEventListener("turbo:render",t=>!k&&E())}var T=["+","-","!"],M=["=","+","-","*","/","%","==","!=","===","!==",">","<",">=","<=","||","&&","??"],j={"!":0,":":0,",":0,")":0,"]":0,"}":0,"?":2,"??":3,"||":4,"&&":5,"!=":9,"==":9,"!==":9,"===":9,">=":10,">":10,"<=":10,"<":10,"+":11,"-":11,"%":12,"/":12,"*":12,"(":13,"[":13,".":13,"{":13},N=(t,e,n=0)=>({kind:t,value:e,precedence:n}),O=t=>9===t||10===t||13===t||32===t,_=t=>95===t||36===t||65<=(t&=-33)&&t<=90,R=t=>_(t)||D(t),D=t=>48<=t&&t<=57,A=class{constructor(t){this._input=t,this._index=-1,this._tokenStart=0,this._advance()}nextToken(){for(;O(this._next);)this._advance(!0);if(34===(t=this._next)||39===t)return this._tokenizeString();var t;if(_(this._next))return this._tokenizeIdentOrKeyword();if(D(this._next))return this._tokenizeNumber();if(46===this._next)return this._tokenizeDot();if(44===this._next)return this._tokenizeComma();if(58===this._next)return this._tokenizeColon();if((t=>43===t||45===t||42===t||47===t||33===t||38===t||37===t||60===t||61===t||62===t||63===t||94===t||124===t)(this._next))return this._tokenizeOperator();if((t=>40===t||41===t||91===t||93===t||123===t||125===t)(this._next))return this._tokenizeGrouper();if(this._advance(),void 0!==this._next)throw new Error(`Expected end of input, got ${this._next}`)}_advance(t){this._index++,this._index<this._input.length?(this._next=this._input.charCodeAt(this._index),t&&(this._tokenStart=this._index)):this._next=void 0}_getValue(t=0){const e=this._input.substring(this._tokenStart,this._index+t);return 0===t&&(this._tokenStart=this._index),e}_tokenizeString(){const t=this._next;for(this._advance(!0);this._next!==t;){if(void 0===this._next)throw new Error("unterminated string");if(92===this._next&&(this._advance(),void 0===this._next))throw new Error("unterminated string");this._advance()}const e=N(1,this._getValue().replace(/\\(.)/g,(t,e)=>{switch(e){case"n":return"\n";case"r":return"\r";case"t":return"\t";case"b":return"\b";case"f":return"\f";default:return e}}));return this._advance(),e}_tokenizeIdentOrKeyword(){do{this._advance()}while(R(this._next));const t=this._getValue();return N("this"===t?10:2,t)}_tokenizeNumber(){do{this._advance()}while(D(this._next));return 46===this._next?this._tokenizeDot():N(6,this._getValue())}_tokenizeDot(){return this._advance(),D(this._next)?this._tokenizeFraction():(this._tokenStart=this._index,N(3,".",13))}_tokenizeComma(){return this._advance(!0),N(4,",")}_tokenizeColon(){return this._advance(!0),N(5,":")}_tokenizeFraction(){do{this._advance()}while(D(this._next));return N(7,this._getValue())}_tokenizeOperator(){if(this._advance(),46===this._next&&63===this._input.charCodeAt(this._index-1))return this._advance(),this._tokenStart=this._index,N(3,".",13);let t=this._getValue(2);if(["===","!=="].includes(t))this._advance(),this._advance();else{if(t=this._getValue(1),"=>"===t)return this._advance(),N(11,t);["==","!=","<=",">=","||","&&","??"].includes(t)&&this._advance()}return t=this._getValue(),N(8,t,j[t])}_tokenizeGrouper(){const t=String.fromCharCode(this._next),e=N(9,t,j[t]);return this._advance(!0),e}},P=class{constructor(t,e){this._tokenizer=new A(t),this._ast=e}parse(){return this._advance(),this._parseExpression()}_advance(t,e){if(!this._matches(t,e))throw new Error(`Expected kind ${t} (${e}), was ${this._token?.kind} (${this._token?.value})`);const n=this._tokenizer.nextToken();this._token=n,this._kind=n?.kind,this._value=n?.value}_matches(t,e){return!(t&&this._kind!==t||e&&this._value!==e)}_parseExpression(){if(!this._token)return this._ast.empty();const t=this._parseUnary();return void 0===t?void 0:this._parsePrecedence(t,0)}_parsePrecedence(t,e){if(void 0===t)throw new Error("Expected left to be defined.");for(;this._token;)if(this._matches(9,"("))t=this._ast.invoke(t,void 0,this._parseArguments());else if(this._matches(9,"["))t=this._ast.index(t,this._parseIndex());else if(this._matches(3))this._advance(),t=this._makeInvokeOrGetter(t,this._parseUnary());else{if(this._matches(10))break;if(!(this._matches(8)&&this._token.precedence>=e))break;t="?"===this._value?this._parseTernary(t):this._parseBinary(t,this._token)}return t}_makeInvokeOrGetter(t,e){if(void 0===e)throw new Error("expected identifier");if("ID"===e.type)return this._ast.getter(t,e.value);if("Invoke"===e.type&&"ID"===e.receiver.type)return this._ast.invoke(t,e.receiver.value,e.arguments);throw new Error(`expected identifier: ${e}`)}_parseBinary(t,e){if(-1===M.indexOf(e.value))throw new Error(`unknown operator: ${e.value}`);this._advance();let n=this._parseUnary();for(;(8===this._kind||3===this._kind||9===this._kind)&&this._token.precedence>e.precedence;)n=this._parsePrecedence(n,this._token.precedence);return this._ast.binary(t,e.value,n)}_parseUnary(){if(this._matches(8)){const t=this._value;if(this._advance(),"+"===t||"-"===t){if(this._matches(6))return this._parseInteger(t);if(this._matches(7))return this._parseDecimal(t)}if(-1===T.indexOf(t))throw new Error(`unexpected token: ${t}`);return this._ast.unary(t,this._parsePrecedence(this._parsePrimary(),13))}return this._parsePrimary()}_parseTernary(t){this._advance(8,"?");const e=this._parseExpression();this._advance(5);const n=this._parseExpression();return this._ast.ternary(t,e,n)}_parsePrimary(){switch(this._kind){case 10:if("this"===this._value)return this._advance(),this._ast.id("this");throw new Error(`unexpected keyword: ${this._value}`);case 2:return this._parseInvokeOrIdentifier();case 1:return this._parseString();case 6:return this._parseInteger();case 7:return this._parseDecimal();case 9:return"("===this._value?this._parseParenOrFunction():"{"===this._value?this._parseMap():"["===this._value?this._parseList():void 0;case 5:throw new Error('unexpected token ":"');default:return}}_parseList(){const t=[];do{if(this._advance(),this._matches(9,"]"))break;t.push(this._parseExpression())}while(this._matches(4));return this._advance(9,"]"),this._ast.list(t)}_parseMap(){const t={};do{if(this._advance(),this._matches(9,"}"))break;const e=this._value;(this._matches(1)||this._matches(2))&&this._advance(),this._advance(5),t[e]=this._parseExpression()}while(this._matches(4));return this._advance(9,"}"),this._ast.map(t)}_parseInvokeOrIdentifier(){const t=this._value;if("true"===t)return this._advance(),this._ast.literal(!0);if("false"===t)return this._advance(),this._ast.literal(!1);if("null"===t)return this._advance(),this._ast.literal(null);if("undefined"===t)return this._advance(),this._ast.literal(void 0);const e=this._parseIdentifier();if(this._matches(11)){this._advance();const t=this._parseExpression();return this._ast.arrowFunction([e.value],t)}const n=this._parseArguments();return n?this._ast.invoke(e,void 0,n):e}_parseIdentifier(){if(!this._matches(2))throw new Error(`expected identifier: ${this._value}`);const t=this._value;return this._advance(),this._ast.id(t)}_parseArguments(){if(!this._matches(9,"("))return;const t=[];do{if(this._advance(),this._matches(9,")"))break;t.push(this._parseExpression())}while(this._matches(4));return this._advance(9,")"),t}_parseIndex(){this._advance();const t=this._parseExpression();return this._advance(9,"]"),t}_parseParenOrFunction(){const t=this._parseArguments();if(this._matches(11)){this._advance();const e=this._parseExpression(),n=t?.map(t=>t.value)??[];return this._ast.arrowFunction(n,e)}return this._ast.paren(t[0])}_parseString(){const t=this._ast.literal(this._value);return this._advance(),t}_parseInteger(t=""){const e=this._ast.literal(parseInt(`${t}${this._value}`,10));return this._advance(),e}_parseDecimal(t=""){const e=this._ast.literal(parseFloat(`${t}${this._value}`));return this._advance(),e}},L={"+":(t,e)=>t+e,"-":(t,e)=>t-e,"*":(t,e)=>t*e,"/":(t,e)=>t/e,"%":(t,e)=>t%e,"==":(t,e)=>t==e,"!=":(t,e)=>t!=e,"===":(t,e)=>t===e,"!==":(t,e)=>t!==e,">":(t,e)=>t>e,">=":(t,e)=>t>=e,"<":(t,e)=>t<e,"<=":(t,e)=>t<=e,"||":(t,e)=>t||e,"&&":(t,e)=>t&&e,"??":(t,e)=>t??e},C={"+":t=>t,"-":t=>-t,"!":t=>!t};k=!0,S=!0,null!==x&&clearTimeout(x),x=null,g();var H=new class{empty(){return{evaluate:t=>t,getIds:t=>t}}literal(t){return{value:t,evaluate(){return this.value},getIds:t=>t}}id(t){return{type:"ID",value:t,evaluate(t){return"this"===this.value?t:t?.[this.value]},getIds(t){return t.push(this.value),t}}}unary(t,e){const n=C[t];return{child:e,evaluate(t){return n(this.child.evaluate(t))},getIds(t){return this.child.getIds(t)}}}binary(t,e,n){const r=L[e];return{operator:e,left:t,right:n,evaluate(t){if("="===this.operator){if("ID"!==this.left.type&&"Getter"!==this.left.type&&"Index"!==this.left.type)throw new Error(`Invalid assignment target: ${this.left}`);const e=this.right.evaluate(t);let n,r;return"Getter"===this.left.type?(n=this.left.receiver.evaluate(t),r=this.left.name):"Index"===this.left.type?(n=this.left.receiver.evaluate(t),r=this.left.argument.evaluate(t)):(n=t,r=this.left.value),void 0===n?void 0:n[r]=e}return"&&"===this.operator?this.left.evaluate(t)&&this.right.evaluate(t):"||"===this.operator?this.left.evaluate(t)||this.right.evaluate(t):"??"===this.operator?this.left.evaluate(t)??this.right.evaluate(t):r(this.left.evaluate(t),this.right.evaluate(t))},getIds(t){return this.left.getIds(t),this.right.getIds(t),t}}}getter(t,e){return{type:"Getter",receiver:t,name:e,evaluate(t){return this.receiver.evaluate(t)?.[this.name]},getIds(t){return this.receiver.getIds(t)}}}invoke(t,e,n){return{type:"Invoke",receiver:t,method:e,arguments:n,evaluate(t){const e=this.receiver.evaluate(t),n=this.method?e:t?.this??t,r=this.method?e?.[this.method]:e,s=(this.arguments??[]).map(e=>e?.evaluate(t));return r?.apply?.(n,s)},getIds(t){return this.receiver.getIds(t),this.arguments?.forEach(e=>e?.getIds(t)),t}}}paren(t){return t}index(t,e){return{type:"Index",receiver:t,argument:e,evaluate(t){return this.receiver.evaluate(t)?.[this.argument.evaluate(t)]},getIds(t){return this.receiver.getIds(t)}}}ternary(t,e,n){return{condition:t,trueExpr:e,falseExpr:n,evaluate(t){return this.condition.evaluate(t)?this.trueExpr.evaluate(t):this.falseExpr.evaluate(t)},getIds(t){return this.condition.getIds(t),this.trueExpr.getIds(t),this.falseExpr.getIds(t),t}}}map(t){return{entries:t,evaluate(t){const e={};if(this.entries)for(const n in this.entries)this.entries[n]&&(e[n]=this.entries[n].evaluate(t));return e},getIds(t){if(this.entries)for(const e in this.entries)this.entries[e]&&this.entries[e].getIds(t);return t}}}list(t){return{items:t,evaluate(t){return this.items?.map(e=>e?.evaluate(t))},getIds(t){return this.items?.forEach(e=>e?.getIds(t)),t}}}arrowFunction(t,e){return{params:t,body:e,evaluate(t){const e=this.params,n=this.body;return function(...r){const s=Object.fromEntries(e.map((t,e)=>[t,r[e]])),i=new Proxy(t??{},{set:(t,e,n)=>(Object.hasOwn(s,e)&&(s[e]=n),t[e]=n),get:(t,e)=>Object.hasOwn(s,e)?s[e]:t[e]});return n.evaluate(i)}},getIds(t){return this.body.getIds(t).filter(t=>!this.params.includes(t))}}}},U=t=>{const e=t.trim();return e.startsWith("<")&&e.endsWith(">")?"'"+e.replace(/'/g,"\\'")+"'":((t,e)=>{let n="",r=0,s=0;for(;s<t.length;){const i=t[s];if("'"!==i&&'"'!==i){s++;continue}n+=e(t.slice(r,s));const o=s++;for(;s<t.length;)if("\\"!==t[s]){if(t[s++]===i)break}else s+=2;n+=t.slice(o,s),r=s}return n+e(t.slice(r))})(t=(t=>{const e=[];let n=0,r=null;for(let s=0;s<t.length;s++){const i=t[s],o=t[s-1];'"'!==i&&"'"!==i||"\\"===o?r||("("===i||"["===i||"{"===i?n++:")"===i||"]"===i||"}"===i?n--:","===i&&0===n&&e.push(s)):r===i?r=null:r||(r=i)}if(0===e.length)return t;const s=[];let i=0;for(const n of e)s.push(t.slice(i,n).trim()),i=n+1;return s.push(t.slice(i).trim()),`[${s.join(", ")}].pop()`})(t=(t=>{let e="",n=0;for(;n<t.length;)if("`"===t[n]){n++;let r=[],s="";for(;n<t.length&&"`"!==t[n];)if("$"===t[n]&&"{"===t[n+1]){(s||0===r.length)&&r.push(`'${s}'`),s="",n+=2;let e=1,i="";for(;n<t.length&&e>0;)"{"===t[n]?e++:"}"===t[n]&&e--,e>0&&(i+=t[n]),n++;r.push(`(${i})`)}else if("\\"===t[n]&&n+1<t.length){const e=t[n+1];s+="n"===e?"\\n":"t"===e?"\\t":"`"===e?"`":"$"===e?"$":"\\"===e?"\\\\":t[n+1],n+=2}else"'"===t[n]?s+="\\'":s+=t[n],n++;(s||0===r.length)&&r.push(`'${s}'`),n++,e+=r.join(" + ")}else e+=t[n],n++;return e})(t)),t=>t.replace(/\bnew\s+Date\b/g,"$Date").replace(/\bnew\s+FormData\b/g,"$FormData").replace(/(\$?\w+(?:\.\w+|\[\w+\])*)(\+\+)/g,"($1 = $1 + 1) - 1").replace(/(\$?\w+(?:\.\w+|\[\w+\])*)(\-\-)/g,"($1 = $1 - 1) + 1").replace(/\+\+(\$?\w+(?:\.\w+|\[\w+\])*)/g,"($1 = $1 + 1)").replace(/\-\-(\$?\w+(?:\.\w+|\[\w+\])*)/g,"($1 = $1 - 1)"))},F=new Map,z=new Set(["null","undefined","true","false","this","NaN","Infinity","Math","console","Object","Array","String","Number","Boolean","Date","JSON","Map","Set"]),W={},G=t=>{for(const[e,n]of Object.entries(t))void 0===n?delete W[e]:W[e]=n},J={diagnosticName:"csp",compile(t,e=!0){const n=U(t.trim()),r=`${e}:${n}`;if(F.has(r))return F.get(r);try{const t=(t=>new P(t,H).parse())(n),e={execute:e=>t?t.evaluate(e):void 0,getIds:()=>t?t.getIds([]).filter(t=>!z.has(t)):[]};return F.set(r,e),e}catch(e){const n={execute:()=>t,getIds:()=>[],error:e};return F.set(r,n),n}},createScope(t){const e={console,Math,Date,JSON,Object,Array,String,Number,Boolean,Map,Set,Promise,URL,URLSearchParams,parseInt,parseFloat,isNaN,isFinite,encodeURIComponent,decodeURIComponent,encodeURI,decodeURI,atob,btoa,...W,$:t.$,$el:t.el,$event:t.event,$data:t.state,$root:t.rootElement,$scope:t.scopeElement,$refs:t.pluralRefs,$dispatch:t.dispatch,$html:t.html,$Date:(...t)=>new Date(...t),$FormData:t=>new FormData(t),$get:t.get,$post:t.post,$put:t.put,$patch:t.patch,$delete:t.del,...t.refs};return new Proxy(e,{get:(e,n)=>n in e?e[n]:t.state[n],set:(e,n,r)=>(n in e?e[n]=r:t.state[n]=r,!0)})}},{helium:B,heliumTeardown:K,mount:Z}=b({engine:J}),q=!1,X=null,V=()=>{q=!0,null!==X&&clearTimeout(X),X=null},Q=t=>(V(),B(t));Q.mount=(t,e)=>(V(),Z(t,e)),Q.allowGlobals=G;var Y=()=>{V(),K()},tt=(t,e)=>J.compile(t).execute(e);if("undefined"!=typeof window&&(window.helium=Q,window.heliumTeardown=Y),"undefined"!=typeof document){const t=()=>{X=null,q||Q()};"loading"===document.readyState?document.addEventListener("DOMContentLoaded",t,{once:!0}):X=setTimeout(t,0),document.addEventListener("turbo:before-render",()=>{K(),q=!1}),document.addEventListener("turbo:render",()=>Q())}var et=async(t,e,n,r,s=()=>!0)=>{const i=t.body.getReader(),o=new TextDecoder;let c="",a=null,l=e.retry||3e3;const u=()=>{const t=c.split(/\r\n\r\n|\r\r|\n\n/);c=t.pop();for(const n of t){if(!n.trim())continue;let t="",i="",o=null;for(const e of n.split(/\r\n|\r|\n/))e.startsWith("data:")?t+=(t?"\n":"")+e.slice(5).trimStart():e.startsWith("event:")?i=e.slice(6).trim():e.startsWith("id:")?o=e.slice(3).trim():e.startsWith("retry:")&&(l=parseInt(e.slice(6).trim())||l);if(o&&(a=o),t&&s()){const n=e.target?.length?e.target:i?[i]:void 0;r(t,n,e.action,e.template)}}},h=()=>setTimeout(async()=>{if(s())try{await n(a)}catch(t){console.error("SSE:",t.message),"always"!==e.retryMode&&"error"!==e.retryMode||!s()||h()}},l);try{for(;s();){const{done:t,value:e}=await i.read();if(t)break;c+=o.decode(e,{stream:!0}),u()}c.trim()&&s()&&(c+="\n\n",u()),"always"===e.retryMode&&s()&&h()}catch(t){console.error("SSE:",t.message),"always"!==e.retryMode&&"error"!==e.retryMode||!s()||h()}};m=et;var nt=Q;export{G as allowGlobals,nt as default,tt as evaluate,et as handleSSE,Q as helium,Y as heliumTeardown,U as preprocess};
|
|
1
|
+
var t=t=>{if("string"!=typeof t)return t;try{return JSON.parse(t)}catch{return t}},e=t=>{const e=String(t).trim(),n=+e;return e&&!isNaN(n)?n:t},n=t=>/^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(t),r=new Set(["undefined","null","true","false","NaN","Infinity","this","arguments"]),s={form:"submit",input:"input",textarea:"input",select:"change"},i={shift:"shiftKey",ctrl:"ctrlKey",alt:"altKey",meta:"metaKey"},o=new Set(["prevent","once","outside","document","window","self","capture","passive","stop"]),a=new Set(["@target","@params","@template","@loading","@options","data-he-target","data-he-params","data-he-template","data-he-loading","data-he-options"]),c=new Set(["@helium","data-helium","@local-storage","data-he-local-storage"]),l=t=>!(o.has(t)||t.startsWith("debounce")||t.startsWith("throttle")||i[t]),u=new Set(["name","length","status","top","origin","event","closed","parent"]),h=t=>s[t.tagName.toLowerCase()]||"click",f=(t,e)=>{let n;const r=(...r)=>(clearTimeout(n),n=setTimeout(t,e,...r));return r.cancel=()=>clearTimeout(n),r},d=(t,e)=>{let n,r,s;const i=()=>{r=0,n=Date.now(),t(...s)},o=(...o)=>{if(null==n)return n=Date.now(),t(...o);s=o;const a=e-(Date.now()-n);if(a<=0)return clearTimeout(r),r=0,n=Date.now(),t(...o);r||(r=setTimeout(i,a))};return o.cancel=()=>{clearTimeout(r),r=0},o},p=t=>{if(!t||"object"!=typeof t)return!1;if(Array.isArray(t))return!0;const e=Object.getPrototypeOf(t);return e===Object.prototype||null===e},w=Symbol("raw"),m=t=>t&&"object"==typeof t&&t[w]||t,$=t=>{const e=t.match(/^\s*([\w$]+)(?:\s*,\s*([\w$]+))?\s+in\s+(.+)$/);return e&&n(e[1])&&(!e[2]||n(e[2]))?[e[1],e[2],e[3]]:null},b=null,y={diagnosticName:"standard",compile(t,e=!0){try{const n=new Function("$ctx",e?`with($ctx){with($ctx.$data){return(${t.trim()})}}`:`with($ctx){with($ctx.$data){${t.trim()}}}`);return{execute:t=>n(t),getIds:null}}catch(e){return{execute:()=>t,getIds:null,error:e}}},createScope:t=>({$:t.$,$data:t.state,$event:t.event,$el:t.el,$root:t.rootElement,$scope:t.scopeElement,$refs:t.pluralRefs,$dispatch:t.dispatch,$html:t.html,$get:t.get,$post:t.post,$put:t.put,$patch:t.patch,$delete:t.del,...t.refs})};function g(s={}){const o=s.engine??y,v=o.diagnosticName||"helium",k=s.sse,S=s.root,x=t=>{try{const e=o.compile(t,!0),n=o.createScope?o.createScope({state:{},el:null,event:{},refs:{},$:null,html:null,get:null,post:null,put:null,patch:null,del:null}):{};return e.execute(n)}catch{return t}},I=(t,...e)=>{const n=t.split(/[.:]/)[0];return":"!==n&&""!==n&&e.some(t=>n===`@${t}`||n==="data-he-"+t)};let E=null,T=0;return{helium:async function(s={}){const y=++T,g=()=>y===T,M=Symbol("all"),O=("string"==typeof S?document.querySelector(S):S)||document.querySelector("[\\@helium]")||document.querySelector("[data-helium]")||document.body;if(!O)throw Error("No root");const j=O.getAttribute("@local-storage")||O.getAttribute("data-he-local-storage");E&&(E.t?.disconnect(),E.i?.(E.root)),E={t:null,o:new Map,refs:new Map,listeners:new WeakMap,l:new WeakMap,u:new WeakSet,h:new WeakMap,p:new Map,m:new WeakMap,warnedCompiles:new Set,v:new WeakMap,k:new WeakMap,S:new WeakMap},E.root=O;const N=t=>Object.assign(document.createElement("template"),{innerHTML:String(t).trim()}).content.firstChild,R=(t,e,n,r,s=O)=>{if(!g())return[];const i=[];return(e||[]).forEach((e,o)=>{const a=e instanceof Node?e:ot(s,e.trim())[0]||document.querySelector(e.trim());if(a){const e=r?r(t):t,s=n?.[o];if(s){const t=N(e);a["replace"==s?"replaceWith":s](t),i.push(t)}else a.innerHTML=e,i.push(a)}else q[e]=t}),i},_=(t,e,n={},r={},s=O)=>{if(n.loading){const t=R(n.loading,n.target,n.action,void 0,s);t.length&&(n.target=t)}const i=r instanceof FormData,o=document.querySelector('meta[name="csrf-token"]')?.content,a=new URL(t,window.location.href).origin===window.location.origin;let c=t;if("GET"===e&&!i&&r&&"object"==typeof r){const e=new URLSearchParams(r).toString();e&&(c+=(t.includes("?")?"&":"?")+e)}const l=t=>fetch(c,{method:e,headers:{Accept:"text/event-stream,text/vnd.turbo-stream.html,application/json,text/html",...!i&&"GET"!==e&&{"Content-Type":"application/json"},...a&&o?{"X-CSRF-Token":o}:{},...t?{"Last-Event-ID":t}:{}},body:"GET"===e?null:i?r:JSON.stringify(r),credentials:a?"same-origin":"omit"}).then(t=>{if(!1===t.ok){const e=new Error(`HTTP ${t.status}${t.statusText?" "+t.statusText:""}`);throw e.status=t.status,e.response=t,e}const e=t.headers.get("content-type")||"";if(e.includes("event-stream")){const e=k||b;if(!e)throw new Error("SSE support requires @daz4126/helium/sse");return e(t,n,l,(...t)=>R(...t,s),g)}return e.includes("turbo-stream")?t.text().then(t=>({turbo:!0,data:t})):e.includes("json")?t.json():t.text()}).then(t=>{if(void 0!==t)return t&&"object"==typeof t&&t.turbo&&window.Turbo?Turbo.renderStreamMessage(t.data):R(t,n.target,n.loading?(n.action||[]).map(t=>t&&"replace"):n.action,n.template,s)});return l(null)},D=t=>"string"==typeof t?{target:[t],action:[null]}:t,[A,P,L,H]=["POST","PUT","PATCH","DELETE"].map(t=>(e,n,r={},s=O)=>_(e,t,D(r),n,s)),C=new Set;let U=0;const F=new WeakMap,z=t=>{if((t.el===O||O.contains(t.el))&&!C.has(t)){C.add(t);try{wt(t)}finally{C.delete(t)}}};let W=new Set,G=new Set,J=!1;const B=()=>{let t=0;for(;W.size&&g();){if(++t>100){W.clear(),console.error("Helium: infinite update loop — bindings kept writing state for 100 consecutive passes");break}const e=W;W=new Set;const n=new Set;e.forEach(t=>E.o.get(t)?.forEach(t=>{(t.I||t.loop||t.cond)&&n.add(t)})),e.forEach(t=>E.o.get(t)?.forEach(t=>n.add(t))),n.forEach(z)}G.clear(),J=!1},K=t=>{t.forEach(t=>W.add(t)),W.add(M),J||(J=!0,queueMicrotask(B))},Z={has:(t,e)=>!("string"==typeof e&&e.startsWith("$")||!Reflect.has(t,e)&&!u.has(e)&&void 0!==globalThis[e]),get(t,e,n){if(e===w)return t;const r=Reflect.get(t,e,n);if(!g()||!p(r))return r;let s=E.h.get(r);if(s||E.h.set(r,s=[]),s.some(n=>n.key===e&&n.parent===t)||s.push({key:e,parent:t}),E.m.has(r))return E.m.get(r);const i=new Proxy(r,Z);return E.m.set(r,i),i},set:(t,e,n)=>{const r=!Object.is(Reflect.get(t,e),n),s=Reflect.set(t,e,n);if(!g()||!r)return s;const i=new Set([e]),o=new Set;G.add(t);let a=E.h.get(t)||[];for(;a.length;){const t=[];for(const{key:e,parent:n}of a)if(i.add(e),n&&!o.has(n)){o.add(n),G.add(n);const e=E.h.get(n);e&&t.push(...e)}a=t}return K(i),X?.(),s},deleteProperty:(t,e)=>{if(!Reflect.has(t,e))return!0;const n=Reflect.deleteProperty(t,e);return n&&g()&&(K([e]),X?.()),n}},q=new Proxy({},Z),X=j?f(()=>g()&&localStorage.setItem(j,JSON.stringify(q)),0):null;Object.assign(q,s);const V=(t,e)=>{const n=e?[e]:[];for(;t;t=t.parentNode){const e=E.S.get(t);e&&n.push(...e.slice().reverse())}return n},Q=(t,e)=>t.find(t=>((t,e)=>Object.prototype.hasOwnProperty.call(t,e))(t.values,e)),Y=(t,e)=>(t.tokens.has(e)||t.tokens.set(e,{scope:t,T:e}),t.tokens.get(e)),tt=t=>K([t]),et=(t,e=null)=>{const n={values:null,tokens:new Map,M:e};return n.values=((t,e)=>{const n={...t},r=new WeakMap,s=new WeakMap,i=(t,n)=>{if(!p(t))return t;let o=s.get(t);if(o||s.set(t,o=new Set),o.add(n),r.has(t))return r.get(t);const a=new Proxy(t,{get(t,e,n){if(e===w)return m(t);let r=Reflect.get(t,e,n);return s.get(t).forEach(t=>r=i(r,t)),r},set(t,n,r,i){const o=Reflect.set(t,n,r,i);return G.add(m(t)),s.get(t).forEach(t=>tt(Y(e,t))),o}});return r.set(t,a),a};return new Proxy(n,{get:(t,e,n)=>e===w?t:i(Reflect.get(t,e,n),e),set(t,n,r,s){const i=Reflect.set(t,n,r,s);return tt(Y(e,n)),i}})})(t,n),n},nt=(t,e)=>E.S.set(t,[...E.S.get(t)||[],e]),rt=(t,e,n)=>{const r=e.split(".").map(t=>t.trim()),s=r.pop();let i=q;const o=Q(V(t),r[0]??s);o&&(i=o.values);for(const t of r)i=i?.[t];return i&&"object"==typeof i?Reflect.set(i,s,n):(console.error(`Helium: cannot set "${e}" — "${r.join(".")}" is not an object`),!1)},st=t=>{for(let e=t;e&&e!==O.parentNode;e=e.parentNode){const t=E.S.get(e)||[];for(let e=t.length-1;e>=0;e--)if(t[e].M)return t[e].M;if(e===O)break}return O},it=(t,e)=>[...E.refs.get(t)||[]].filter(t=>(t===O||O.contains(t))&&st(t)===e).sort((t,e)=>t===e?0:t.compareDocumentPosition(e)&Node.DOCUMENT_POSITION_FOLLOWING?-1:1),ot=(t,e)=>{const n=e.startsWith("$")?e:`$${e}`;for(const e of(t=>{const e=[];let n=st(t);for(;n&&(e.push(n),n!==O);)n=st(n.parentNode);return e})(t)){const t=it(n,e);if(t.length)return t}return[]},at=new WeakMap,ct=t=>{const e=st(t);if(at.has(e))return at.get(e);const n=t=>document.querySelector(t);return n.all=t=>[...document.querySelectorAll(t)],(n.root=t=>O.querySelector(t)).all=t=>[...O.querySelectorAll(t)],(n.scope=t=>e.querySelector(t)).all=t=>[...e.querySelectorAll(t)],at.set(e,n),n},lt=(t,e={},n=q,r,s)=>{let i=n;const a=V(t,r);a.length&&(i=new Proxy(n,{has:(t,e)=>!!Q(a,e)||Reflect.has(t,e),get:(t,e,n)=>{const r=Q(a,e);if(!r)return Reflect.get(t,e,n);const i=r.values[e];return s?.set(Y(r,e),i),i},set:(t,e,n,r)=>{const s=Q(a,e);return s?Reflect.set(s.values,e,n):Reflect.set(t,e,n,r)}}));const c=(t=>{const e=st(t),n=F.get(e);if(n?.O===U)return n;const r={};for(const e of E.refs.keys()){const n=ot(t,e);n.length&&(r[e]=n[0])}const s=new Proxy({},{get:(t,n)=>"string"==typeof n?ot(e,n):void 0}),i={O:U,j:r,N:s};return F.set(e,i),i})(t);return o.createScope({$:ct(t),state:i,event:e,el:t,rootElement:O,scopeElement:st(t),pluralRefs:c.N,dispatch:(e,n={},r={})=>{const s=new CustomEvent(e,{detail:n,bubbles:r.bubbles??!0,cancelable:r.cancelable??!0});return(r.target||t).dispatchEvent(s),s},html:N,get:(e,n)=>((t,e={},n=O)=>_(t,"GET",D(e),{},n))(e,n,t),post:(e,n,r)=>A(e,n,r,t),put:(e,n,r)=>P(e,n,r,t),patch:(e,n,r)=>L(e,n,r,t),del:(e,n,r)=>H(e,n,r,t),refs:c.j})},ut=(t,e=!0,n)=>{const r=`${e}:${t}`,s=(t=>"string"==typeof t?{label:t}:t||{})(n);let i=E.p.get(r);return i||(i=o.compile(t,e),E.p.set(r,i)),((t,e,n)=>{if(!e.error||!n.strict&&!(t=>{const e=String(t).trim();return/=>|&&|\|\||\?\?/.test(e)||/[()[\]{}]/.test(e)||/(?:^|\s)[+\-*/%](?:\s|$)/.test(e)||/(?:^|\s)(?:={1,3}|!==?|<=?|>=?)(?:\s|$)/.test(e)||/\s\?\s/.test(e)||/^\s*[`'"]|[`'"]\s*$/.test(e)||/\b[$A-Za-z_][\w$]*\s*\.\s*(?:[$A-Za-z_][\w$]*|\s*$)/.test(e)||/^[+-]{2}|[+-]{2}$/.test(e)})(t))return;const r=(t=>[t.build||v,t.label].filter(Boolean).join(" "))(n),s=`${r}:${t}:${e.error.message}`;E.warnedCompiles.has(s)||(E.warnedCompiles.add(s),console.warn(`Helium expression compile warning${r?` [${r}]`:""}:`,t,e.error.message))})(t,i,s),i},ht=(t,e={},n=t.el)=>{const r=new Map,s=(t,e=null)=>new Proxy(t,{has:(t,n)=>null===e?Z.has(t,n):Reflect.has(t,n),get(t,n,i){if(n===w)return m(t);const o=Reflect.get(t,n,i);return null!==e||"string"!=typeof n||r.has(n)||r.set(n,o),p(o)?s(o,e??n):o}});try{const i=t.R.execute(lt(n,e,s(q),null,r)),o=[...r].filter(([t,e])=>"string"!=typeof t?t.scope.values[t.T]===e:q[t]===e).map(([t])=>t);let a=t.keys||[];a=a.map(e=>{const n=Q(V(t.el),e);return n?Y(n,e):e});const c=t.keys?.includes("*")?[M]:o.concat(a);return((t,e)=>{const n=new Set(e);t._?.forEach(e=>{if(n.has(e))return;const r=E.o.get(e)?.filter(e=>e!==t)||[];r.length?E.o.set(e,r):E.o.delete(e)}),n.forEach(e=>{if(t._?.has(e))return;const n=E.o.get(e)||[];E.o.set(e,t.I||t.loop||t.cond?[t,...n]:[...n,t])}),t._=n})(t,c),{ok:!0,result:i}}catch(t){return console.error("Helium expression error:",t.message),{ok:!1}}},ft=t=>{t.length&&vt(t).then(({o:t,D:e})=>{g()&&(t.forEach(z),$t(e))})},dt=(t,e)=>{const n=t.loop,r=n[4],s=new Map,i=m(e),o=i!==e?e:null,a=Array.from(i||[]),c=n[5],l=c?null:{values:null,tokens:new Map},u=c?null:lt(t.el,{},q,l),h=new Map;r.forEach(t=>h.set(t,h.size));const f=[];a.forEach((t,e)=>{const a=m(t),h={[n[0]]:a};let d;if(n[1]&&(h[n[1]]=e),c){d=h[c[0]];for(let t=1;t<c.length;t++)d=d?.[c[t]]}else l.values=h,d=n[2].execute(u);if(s.has(d))return void console.error("Duplicate key:",d);if(o&&a&&"object"==typeof a){let t=E.h.get(a);t||E.h.set(a,t=[]);const n=String(e);t.some(t=>t.key===n&&t.parent===i)||t.push({key:n,parent:i})}let p=r.get(d);if(p)(p.item!==a||G.has(a))&&(p.scope.values[n[0]]=o?o[e]:t),n[1]&&p.index!==e&&(p.scope.values[n[1]]=e);else{h[n[0]]=o?o[e]:t;const r=n[3].cloneNode(!0);p={nodes:[...r.childNodes],scope:et(h)},p.nodes.forEach(t=>{1===t.nodeType&&(nt(t,p.scope),f.push(t))})}p.item=a,p.index=e,s.set(d,p)});const d=[];r.forEach((t,e)=>{s.has(e)||t.nodes.forEach(t=>{1===t.nodeType&&d.push(t),t.remove()})}),mt(d),n[4]=s;const p=[...s.values()],w=(t=>{const e=[],n=new Array(t.length).fill(-1);t.forEach((r,s)=>{if(-1===r)return;let i=0,o=e.length;for(;i<o;){const n=i+o>>1;t[e[n]]<r?i=n+1:o=n}i>0&&(n[s]=e[i-1]),e[i]=s});const r=new Set;for(let t=e.length?e[e.length-1]:-1;-1!==t;t=n[t])r.add(t);return r})(p.map(t=>h.get(t)??-1));let $=t.el;p.forEach((t,e)=>t.nodes.forEach(t=>{w.has(e)||$.nextSibling===t||$.after(t),$=t})),ft(f)},pt=(t,e)=>{const n=t.cond[1];if(e&&!n.length){const e=t.cond[1]=[...t.cond[0].cloneNode(!0).childNodes],n=E.S.get(t.el);let r=t.el;e.forEach(t=>{1===t.nodeType&&n&&E.S.set(t,[...n]),r.after(t),r=t}),ft(e.filter(t=>1===t.nodeType))}else!e&&n.length&&(mt(n.filter(t=>1===t.nodeType)),n.forEach(t=>t.remove()),t.cond[1]=[])};function wt(e,n={},r=e.el){const{el:s,T:i,I:o,A:a}=e,c=e.P||ht(e,n,r);if(delete e.P,!c.ok)return;const l=c.result;if(e.loop)return dt(e,l);if(e.cond)return pt(e,l);if(o&&rt(s,o,l),"innerHTML"===i){const t=Array.isArray(l)?l.join``:l;return"object"==typeof Idiomorph?Idiomorph.morph(s,t,{morphStyle:"innerHTML"}):s.innerHTML=t}if("class"===i&&l&&"object"==typeof l){const t=new Set;return Object.entries(l).forEach(([e,n])=>e.split(/\s+/).filter(Boolean).forEach(e=>{t.add(e),s.classList.toggle(e,!!n)})),e.L?.forEach(e=>{t.has(e)||s.classList.remove(e)}),void(e.L=t)}if("style"===i&&l&&"object"==typeof l)return s.style.cssText=Object.entries(l).filter(([t,e])=>null!=e&&!1!==e).map(([t,e])=>`${t.replace(/[A-Z]/g,t=>"-"+t.toLowerCase())}:${e}`).join("; ");"hidden"!==i?i in s?"radio"===s.type&&"checked"!==i?s.checked=s.value===l:s[i]="textContent"===i?l??"":t(l):s.setAttribute(i,t(l)):s.hidden=a?!!l:!l}const mt=t=>{const e=new Set;if((Array.isArray(t)?t:[t]).forEach(t=>{e.add(t),t.querySelectorAll("*").forEach(t=>e.add(t))}),e.size){e.forEach(t=>{const e=E.l.get(t);E.l.delete(t),e?.forEach(t=>{try{t.i()}catch(t){console.error("Helium cleanup:",t)}}),E.listeners.get(t)?.forEach(({receiver:t,event:e,H:n,options:r})=>{n.cancel?.(),t.removeEventListener(e,n,r)}),E.listeners.delete(t),E.u.delete(t),E.v.delete(t),E.k.delete(t),E.S.delete(t)});for(const[t,n]of E.refs){let r=!1;for(const t of n)e.has(t)&&(r=n.delete(t)||r);n.size||E.refs.delete(t),r&&U++}E.o.forEach((t,n)=>{const r=t.filter(t=>!e.has(t.el));r.length?E.o.set(n,r):E.o.delete(n)})}},$t=t=>t.forEach(({R:t,el:e,C:n})=>{let r;try{r=t.execute(lt(e))}catch(t){return void console.error("Helium @init error:",t.message)}"function"==typeof r&&E.l.set(e,[...E.l.get(e)||[],{i:r,C:n}])});E.i=mt;const bt=t=>{const e=new Set;return E.o.forEach(n=>n.forEach(n=>{t(n)&&e.add(n)})),e},yt=t=>{if(t.loop){const e=[...t.loop[4].values()].flatMap(t=>t.nodes);mt(e.filter(t=>1===t.nodeType)),e.forEach(t=>t.remove()),t.loop[4].clear()}if(t.cond?.[1].length){const e=t.cond[1];mt(e.filter(t=>1===t.nodeType)),e.forEach(t=>t.remove()),t.cond[1]=[]}E.o.forEach((e,n)=>{const r=e.filter(e=>e!==t);r.length?E.o.set(n,r):E.o.delete(n)})},gt=async(t,e,n)=>{if(!g()||t!==O&&!O.contains(t))return;if(a.has(e)||c.has(e))return;let r=e;if(":key"!==e||(r=t.hasAttribute("@for")?"@for":t.hasAttribute("data-he-for")?"data-he-for":null,r)){if(((t,e,n)=>{bt(n=>n.el===t&&n.C===e).forEach(yt);const r=E.listeners.get(t)||[],s=[];r.forEach(t=>{t.C===e?(t.H.cancel?.(),t.receiver.removeEventListener(t.event,t.H,t.options)):s.push(t)}),s.length?E.listeners.set(t,s):E.listeners.delete(t);const i=E.l.get(t)||[],o=[];if(i.forEach(t=>{if(t.C===e)try{t.i()}catch(t){console.error("Helium cleanup:",t)}else o.push(t)}),o.length?E.l.set(t,o):E.l.delete(t),I(e,"ref")&&null!=n){const e="$"+n,r=E.refs.get(e);r?.delete(t)&&U++,r&&!r.size&&E.refs.delete(e)}if(I(e,"data")||"data-he"===e){const e=E.v.get(t);if(t===O&&e){const n=E.k.get(t);e.keys.forEach(t=>{const e=n?.get(t);e?.present?q[t]=e.value:delete q[t]})}else{const e=(E.S.get(t)||[]).filter(e=>e.M!==t);e.length?E.S.set(t,e):E.S.delete(t)}E.v.delete(t)}})(t,r,":key"===e?t.getAttribute(r):n),t.hasAttribute(r)){const{o:e,D:n}=await vt(t,new Set([r]));if(!g()||t!==O&&!O.contains(t))return;e.forEach(z),$t(n)}(I(r,"data")||"data-he"===r)&&(t=>{bt(e=>e.el!==t&&t.contains(e.el)).forEach(z),U++})(t)}};async function vt(t,s=null){const o=[],u=[],w=[],b=Array.isArray(t)?t:[t],y=b.flatMap(t=>[t,...t.querySelectorAll("*")]).filter(t=>{if(s)return b.includes(t);if(E.u.has(t))return!1;for(let e=0;e<t.attributes.length;e++){const n=t.attributes[e].name;if("@"===n[0]||":"===n[0]||n.startsWith("data-he"))return!0}return!1});b.forEach(t=>E.u.add(t));const v=[];return y.forEach(t=>{const e=["@import","data-he-import"].find(e=>(!s||s.has(e))&&t.hasAttribute(e)),n=e?t.getAttribute(e):null;n&&n.split(",").map(t=>t.trim()).forEach(t=>{const e=t.startsWith("http://")||t.startsWith("https://"),n=t.endsWith(".js"),r=t.startsWith("/")||t.startsWith("./")||t.startsWith("../"),s=e?t:new URL((e||r?"":"./")+t+(e||n?"":".js"),location.href).href;v.push(import(s).then(t=>{Object.keys(t).forEach(e=>q[e]=t[e])}).catch(t=>{console.error(`Failed to import module: ${s}`,t.message)}))})}),v.length>0&&await Promise.all(v),g()?(y.forEach(t=>{const o=["@data","data-he-data","data-he"].find(e=>(!s||s.has(e))&&t.hasAttribute(e)),b=o?t.getAttribute(o):null;if(null!=b)try{const e=ut(b,!0,{label:"@data",strict:!0}).execute(lt(t));if(!p(e)||Array.isArray(e))console.warn("Helium @data expects an object:",b);else if(t===O){let n=E.k.get(t);n||E.k.set(t,n=new Map),Object.keys(e).forEach(t=>{n.has(t)||n.set(t,{present:Object.prototype.hasOwnProperty.call(q,t),value:m(q[t])})}),Object.assign(q,e)}else nt(t,et(e,t));E.v.set(t,{C:o,keys:new Set(Object.keys(e))})}catch(t){console.warn("Helium @data error:",t.message)}E.u.add(t);const y=t.attributes,v=e=>{const n=ut(e,!0,{label:"HTTP option",strict:!0}),r=lt(t);return n.execute(r)},k=t.type?.toLowerCase(),S="checkbox"==k,T="radio"==k,M="SELECT"==t.tagName,j=t.getAttribute("@for")??t.getAttribute("data-he-for");for(let o=0;o<y.length;o++){const{name:p,value:m}=y[o];if("@"!==p[0]&&":"!==p[0]&&!p.startsWith("data-he"))continue;if(s&&!s.has(p))continue;if(":key"===p&&null!=j)continue;let b=!1;if(b=!!Q(V(t),m),I(p,"text","html","bind")&&n(m)&&!r.has(m)&&!b&&null==q[m]&&(q[m]=I(p,"bind")?"checkbox"==t.type?t.checked:e(t.value):e(t.textContent)),!I(p,"data")&&"data-he"!==p&&!I(p,"import")&&!c.has(p))if(I(p,"for")){const e=$(m),n=t.getAttribute(":key");if("TEMPLATE"===t.tagName&&e&&n){const r=/^[\w$]+(\.[\w$]+)*$/.test(n.trim())?n.trim().split("."):null;u.push({el:t,C:p,T:null,R:ut(e[2],!0,{label:"@for",strict:!0}),loop:[e[0],e[1],ut(n,!0,{label:":key",strict:!0}),t.content.cloneNode(!0),new Map,!r||r[0]!==e[0]&&r[0]!==e[1]?null:r]})}else console.error("Invalid @for/:key")}else if(I(p,"if"))"TEMPLATE"!==t.tagName||null!=j?console.error("@if requires a <template> element without @for"):u.push({el:t,C:p,T:null,R:ut(m,!0,{label:"@if",strict:!0}),cond:[t.content.cloneNode(!0),[]]});else{if(I(p,"for","if"))continue;if(p.startsWith(":")||p.startsWith("data-he-attr:")){const e=p.startsWith(":")?p.slice(1):p.slice(13);u.push({el:t,C:p,T:e,R:ut(m,!0,{label:p})})}else if(I(p,"ref")){const e="$"+m;E.refs.has(e)||E.refs.set(e,new Set),E.refs.get(e).has(t)||(E.refs.get(e).add(t),U++)}else if(I(p,"text","html"))u.push({el:t,C:p,T:I(p,"text")?"textContent":"innerHTML",R:ut(m,!0,{label:p})});else if(I(p,"bind")){const e=S||T||M||p.includes(".lazy")?"change":"input",n=S?"checked":"value",r=t=>(t=p.includes(".trim")?t.trim():t,p.includes(".number")&&""!==t&&!isNaN(+t)?+t:t),s=e=>rt(t,m,S?e.target.checked:r(e.target.value));t.addEventListener(e,s),E.listeners.has(t)||E.listeners.set(t,[]),E.listeners.get(t).push({receiver:t,event:e,H:s,C:p}),u.push({el:t,C:p,T:n,R:ut(m,!0,{label:p})}),S?t.checked=!!q[m]:T?t.checked=t.value==q[m]:t.value=q[m]??""}else if(I(p,"hidden","visible")){const e=I(p,"hidden");u.push({el:t,C:p,T:"hidden",R:ut(m,!0,{label:p,strict:!0}),A:e})}else if(I(p,"calculate")){const e=p.split(":")[1];let n=null;n=Q(V(t),e),n||e in q||(q[e]=void 0),u.push({el:t,C:p,I:e,T:null,R:ut(m,!0,{label:p,strict:!0})})}else if(I(p,"effect"))u.push({el:t,C:p,T:null,R:ut(m,!0,{label:p,strict:!0}),keys:p.split(":").slice(1)});else if(I(p,"init"))w.push({R:ut(m,!0,{label:p,strict:!0}),el:t,C:p});else{if(a.has(p))continue;if(p.startsWith("@")||p.startsWith("data-he")){const e=p.startsWith("@")?p.slice(1):p.slice(8),[n,...r]=e.split(".");let s=n;const o=["get","post","put","patch","delete"].includes(n);if(o&&(s=h(t)),r.includes("passive")&&r.includes("prevent")){const t=`event-options:${p}`;E.warnedCompiles.has(t)||(E.warnedCompiles.add(t),console.warn(`Helium event modifier warning [${p}]: .passive and .prevent cannot be combined`));continue}const a=r.includes("outside")||r.includes("document")?document:r.includes("window")?window:t,c=r.find(t=>t.startsWith("debounce")),u=c?(t=>t&&!isNaN(t)?Number(t):300)(c.split(":")[1]):0,w=r.find(t=>t.startsWith("throttle")),$=w?(t=>t&&!isNaN(t)?Number(t):300)(w.split(":")[1]):0,b=r.includes("passive")?{passive:!0,capture:r.includes("capture")}:r.includes("capture"),y=e=>{if(o){const r=e=>t.getAttribute("data-he-"+e)||t.getAttribute("@"+e),s=r("target"),i=s?s.split(",").map(t=>t.split(":").map(t=>t.trim())):[],o=i.map(([t])=>t),a=i.map(([,t])=>t),c={...r("options")&&x(r("options")||"{}"),...s&&{target:o},...s&&{action:a},...r("template")&&{template:v(r("template"))},...r("loading")&&{loading:v(r("loading"))}};let l=r("params");if(!l&&t.hasAttribute("name")?l=t.getAttribute("name").match(/\w+/g).map(t=>`${t}:`).join``+(S?"checked":"value"):l||(l="{}"),!l.trim().startsWith("{")&&l.includes(":")){const e=l.split(":").map(t=>t.trim());l=e.reduceRight((e,n,r)=>`{ ${n}: ${1==r?`'${t[e]}'`:e} }`)}const u=lt(t,e),h=ut(l,!0,{label:"@params",strict:!0}).execute(u);_(m,n.toUpperCase(),c,h,t).catch(t=>console.error("AJAX:",t.message))}else{const n=lt(t,e),r=ut(m,!0,{label:p,strict:!0}).execute(n);r&&"function"==typeof r.then&&r.catch(t=>console.error("AJAX:",t.message))}r.includes("once")&&a.removeEventListener(s,I,b)},k=u>0?f(y,u):$>0?d(y,$):y,I=e=>{if(g()){for(const[t,n]of Object.entries(i))if(r.includes(t)&&!e[n])return;if(["keydown","keyup","keypress"].includes(s)){const t=r.find(l);if(t&&(" "==e.key?"Space":"Escape"==e.key?"Esc":e.key).toLowerCase()!==t.toLowerCase())return}r.includes("outside")&&t.contains(e.target)||r.includes("self")&&e.target!==t||(r.includes("prevent")&&e.preventDefault(),r.includes("stop")&&e.stopPropagation(),k(e))}};I.cancel=k.cancel,a.addEventListener(s,I,b),E.listeners.has(t)||E.listeners.set(t,[]),E.listeners.get(t).push({receiver:a,event:s,H:I,options:b,C:p})}}}}}),u.forEach(t=>{t.P=ht(t),t.I||t.loop||t.cond?o.unshift(t):o.push(t)}),{o,D:w}):{o:[],D:[]}}E.t?.disconnect(),E.t=new MutationObserver(async t=>{if(!g())return;E.refs.size&&U++;const e=[],n=[];for(const r of t)r.removedNodes.forEach(t=>1===t.nodeType&&!O.contains(t)&&e.push(t)),r.addedNodes.forEach(t=>1===t.nodeType&&O.contains(t)&&n.push(t));mt(e);for(const e of t)for(const t of e.addedNodes)if(1===t.nodeType&&O.contains(t)&&!E.u.has(t)){const{o:e,D:n}=await vt(t);if(!O.contains(t))continue;e.forEach(t=>wt(t)),$t(n)}const r=new Map;for(const e of t){if("attributes"!==e.type)continue;const t=e.target,s=e.attributeName;if(n.some(e=>e===t||e.contains(t)))continue;if("@"!==s[0]&&":"!==s[0]&&!s.startsWith("data-he"))continue;let i=r.get(t);i||r.set(t,i=new Map),i.has(s)||i.set(s,e.oldValue)}for(const[t,e]of r)for(const[n,r]of e)await gt(t,n,r)}),E.t.observe(O,{childList:!0,subtree:!0,attributes:!0,attributeOldValue:!0});const kt=j?(()=>{try{return JSON.parse(localStorage.getItem(j))}catch{return null}})():null,{o:St,D:xt}=await vt(O);return g()?(kt&&Object.assign(q,kt),St.forEach(t=>wt(t)),$t(xt),q):q},heliumTeardown:function(){T++,E?.t&&(E.t.disconnect(),E.i?.(E.root)),E=null},mount:async function(t,e){const n="string"==typeof t?document.querySelector(t):t;if(!n)throw Error("No root");const r=g({...s,root:n});return{state:await r.helium(e),unmount:r.heliumTeardown}}}}var{helium:v,heliumTeardown:k,mount:S}=g(),x=!1,I=!1,E=null;function T(){I=!0,null!==E&&(clearTimeout(E),E=null)}function M(t){return T(),v(t)}if(M.mount=function(t,e){return T(),S(t,e)},"undefined"!=typeof window&&(window.helium=M,window.heliumTeardown=function(){T(),k()}),"undefined"!=typeof document){const t=()=>{E=null,x||I||M()};"loading"===document.readyState?document.addEventListener("DOMContentLoaded",t,{once:!0}):E=setTimeout(t,0),document.addEventListener("turbo:before-render",t=>{x||(k(),I=!1)}),document.addEventListener("turbo:render",t=>!x&&M())}var O=["+","-","!"],j=["=","+","-","*","/","%","==","!=","===","!==",">","<",">=","<=","||","&&","??"],N={"!":0,":":0,",":0,")":0,"]":0,"}":0,"?":2,"??":3,"||":4,"&&":5,"!=":9,"==":9,"!==":9,"===":9,">=":10,">":10,"<=":10,"<":10,"+":11,"-":11,"%":12,"/":12,"*":12,"(":13,"[":13,".":13,"{":13},R=(t,e,n=0)=>({kind:t,value:e,precedence:n}),_=t=>9===t||10===t||13===t||32===t,D=t=>95===t||36===t||65<=(t&=-33)&&t<=90,A=t=>D(t)||P(t),P=t=>48<=t&&t<=57,L=class{constructor(t){this._input=t,this._index=-1,this._tokenStart=0,this._advance()}nextToken(){for(;_(this._next);)this._advance(!0);if(34===(t=this._next)||39===t)return this._tokenizeString();var t;if(D(this._next))return this._tokenizeIdentOrKeyword();if(P(this._next))return this._tokenizeNumber();if(46===this._next)return this._tokenizeDot();if(44===this._next)return this._tokenizeComma();if(58===this._next)return this._tokenizeColon();if((t=>43===t||45===t||42===t||47===t||33===t||38===t||37===t||60===t||61===t||62===t||63===t||94===t||124===t)(this._next))return this._tokenizeOperator();if((t=>40===t||41===t||91===t||93===t||123===t||125===t)(this._next))return this._tokenizeGrouper();if(this._advance(),void 0!==this._next)throw new Error(`Expected end of input, got ${this._next}`)}_advance(t){this._index++,this._index<this._input.length?(this._next=this._input.charCodeAt(this._index),t&&(this._tokenStart=this._index)):this._next=void 0}_getValue(t=0){const e=this._input.substring(this._tokenStart,this._index+t);return 0===t&&(this._tokenStart=this._index),e}_tokenizeString(){const t=this._next;for(this._advance(!0);this._next!==t;){if(void 0===this._next)throw new Error("unterminated string");if(92===this._next&&(this._advance(),void 0===this._next))throw new Error("unterminated string");this._advance()}const e=R(1,this._getValue().replace(/\\(.)/g,(t,e)=>{switch(e){case"n":return"\n";case"r":return"\r";case"t":return"\t";case"b":return"\b";case"f":return"\f";default:return e}}));return this._advance(),e}_tokenizeIdentOrKeyword(){do{this._advance()}while(A(this._next));const t=this._getValue();return R("this"===t?10:2,t)}_tokenizeNumber(){do{this._advance()}while(P(this._next));return 46===this._next?this._tokenizeDot():R(6,this._getValue())}_tokenizeDot(){return this._advance(),P(this._next)?this._tokenizeFraction():(this._tokenStart=this._index,R(3,".",13))}_tokenizeComma(){return this._advance(!0),R(4,",")}_tokenizeColon(){return this._advance(!0),R(5,":")}_tokenizeFraction(){do{this._advance()}while(P(this._next));return R(7,this._getValue())}_tokenizeOperator(){if(this._advance(),46===this._next&&63===this._input.charCodeAt(this._index-1))return this._advance(),this._tokenStart=this._index,R(3,".",13);let t=this._getValue(2);if(["===","!=="].includes(t))this._advance(),this._advance();else{if(t=this._getValue(1),"=>"===t)return this._advance(),R(11,t);["==","!=","<=",">=","||","&&","??"].includes(t)&&this._advance()}return t=this._getValue(),R(8,t,N[t])}_tokenizeGrouper(){const t=String.fromCharCode(this._next),e=R(9,t,N[t]);return this._advance(!0),e}},H=class{constructor(t,e){this._tokenizer=new L(t),this._ast=e}parse(){return this._advance(),this._parseExpression()}_advance(t,e){if(!this._matches(t,e))throw new Error(`Expected kind ${t} (${e}), was ${this._token?.kind} (${this._token?.value})`);const n=this._tokenizer.nextToken();this._token=n,this._kind=n?.kind,this._value=n?.value}_matches(t,e){return!(t&&this._kind!==t||e&&this._value!==e)}_parseExpression(){if(!this._token)return this._ast.empty();const t=this._parseUnary();return void 0===t?void 0:this._parsePrecedence(t,0)}_parsePrecedence(t,e){if(void 0===t)throw new Error("Expected left to be defined.");for(;this._token;)if(this._matches(9,"("))t=this._ast.invoke(t,void 0,this._parseArguments());else if(this._matches(9,"["))t=this._ast.index(t,this._parseIndex());else if(this._matches(3))this._advance(),t=this._makeInvokeOrGetter(t,this._parseUnary());else{if(this._matches(10))break;if(!(this._matches(8)&&this._token.precedence>=e))break;t="?"===this._value?this._parseTernary(t):this._parseBinary(t,this._token)}return t}_makeInvokeOrGetter(t,e){if(void 0===e)throw new Error("expected identifier");if("ID"===e.type)return this._ast.getter(t,e.value);if("Invoke"===e.type&&"ID"===e.receiver.type)return this._ast.invoke(t,e.receiver.value,e.arguments);throw new Error(`expected identifier: ${e}`)}_parseBinary(t,e){if(-1===j.indexOf(e.value))throw new Error(`unknown operator: ${e.value}`);this._advance();let n=this._parseUnary();for(;(8===this._kind||3===this._kind||9===this._kind)&&this._token.precedence>e.precedence;)n=this._parsePrecedence(n,this._token.precedence);return this._ast.binary(t,e.value,n)}_parseUnary(){if(this._matches(8)){const t=this._value;if(this._advance(),"+"===t||"-"===t){if(this._matches(6))return this._parseInteger(t);if(this._matches(7))return this._parseDecimal(t)}if(-1===O.indexOf(t))throw new Error(`unexpected token: ${t}`);return this._ast.unary(t,this._parsePrecedence(this._parsePrimary(),13))}return this._parsePrimary()}_parseTernary(t){this._advance(8,"?");const e=this._parseExpression();this._advance(5);const n=this._parseExpression();return this._ast.ternary(t,e,n)}_parsePrimary(){switch(this._kind){case 10:if("this"===this._value)return this._advance(),this._ast.id("this");throw new Error(`unexpected keyword: ${this._value}`);case 2:return this._parseInvokeOrIdentifier();case 1:return this._parseString();case 6:return this._parseInteger();case 7:return this._parseDecimal();case 9:return"("===this._value?this._parseParenOrFunction():"{"===this._value?this._parseMap():"["===this._value?this._parseList():void 0;case 5:throw new Error('unexpected token ":"');default:return}}_parseList(){const t=[];do{if(this._advance(),this._matches(9,"]"))break;t.push(this._parseExpression())}while(this._matches(4));return this._advance(9,"]"),this._ast.list(t)}_parseMap(){const t={};do{if(this._advance(),this._matches(9,"}"))break;const e=this._value;(this._matches(1)||this._matches(2))&&this._advance(),this._advance(5),t[e]=this._parseExpression()}while(this._matches(4));return this._advance(9,"}"),this._ast.map(t)}_parseInvokeOrIdentifier(){const t=this._value;if("true"===t)return this._advance(),this._ast.literal(!0);if("false"===t)return this._advance(),this._ast.literal(!1);if("null"===t)return this._advance(),this._ast.literal(null);if("undefined"===t)return this._advance(),this._ast.literal(void 0);const e=this._parseIdentifier();if(this._matches(11)){this._advance();const t=this._parseExpression();return this._ast.arrowFunction([e.value],t)}const n=this._parseArguments();return n?this._ast.invoke(e,void 0,n):e}_parseIdentifier(){if(!this._matches(2))throw new Error(`expected identifier: ${this._value}`);const t=this._value;return this._advance(),this._ast.id(t)}_parseArguments(){if(!this._matches(9,"("))return;const t=[];do{if(this._advance(),this._matches(9,")"))break;t.push(this._parseExpression())}while(this._matches(4));return this._advance(9,")"),t}_parseIndex(){this._advance();const t=this._parseExpression();return this._advance(9,"]"),t}_parseParenOrFunction(){const t=this._parseArguments();if(this._matches(11)){this._advance();const e=this._parseExpression(),n=t?.map(t=>t.value)??[];return this._ast.arrowFunction(n,e)}return this._ast.paren(t[0])}_parseString(){const t=this._ast.literal(this._value);return this._advance(),t}_parseInteger(t=""){const e=this._ast.literal(parseInt(`${t}${this._value}`,10));return this._advance(),e}_parseDecimal(t=""){const e=this._ast.literal(parseFloat(`${t}${this._value}`));return this._advance(),e}},C={"+":(t,e)=>t+e,"-":(t,e)=>t-e,"*":(t,e)=>t*e,"/":(t,e)=>t/e,"%":(t,e)=>t%e,"==":(t,e)=>t==e,"!=":(t,e)=>t!=e,"===":(t,e)=>t===e,"!==":(t,e)=>t!==e,">":(t,e)=>t>e,">=":(t,e)=>t>=e,"<":(t,e)=>t<e,"<=":(t,e)=>t<=e,"||":(t,e)=>t||e,"&&":(t,e)=>t&&e,"??":(t,e)=>t??e},U={"+":t=>t,"-":t=>-t,"!":t=>!t};x=!0,I=!0,null!==E&&clearTimeout(E),E=null,k();var F=new class{empty(){return{evaluate:t=>t,getIds:t=>t}}literal(t){return{value:t,evaluate(){return this.value},getIds:t=>t}}id(t){return{type:"ID",value:t,evaluate(t){return"this"===this.value?t:t?.[this.value]},getIds(t){return t.push(this.value),t}}}unary(t,e){const n=U[t];return{child:e,evaluate(t){return n(this.child.evaluate(t))},getIds(t){return this.child.getIds(t)}}}binary(t,e,n){const r=C[e];return{operator:e,left:t,right:n,evaluate(t){if("="===this.operator){if("ID"!==this.left.type&&"Getter"!==this.left.type&&"Index"!==this.left.type)throw new Error(`Invalid assignment target: ${this.left}`);const e=this.right.evaluate(t);let n,r;return"Getter"===this.left.type?(n=this.left.receiver.evaluate(t),r=this.left.name):"Index"===this.left.type?(n=this.left.receiver.evaluate(t),r=this.left.argument.evaluate(t)):(n=t,r=this.left.value),void 0===n?void 0:n[r]=e}return"&&"===this.operator?this.left.evaluate(t)&&this.right.evaluate(t):"||"===this.operator?this.left.evaluate(t)||this.right.evaluate(t):"??"===this.operator?this.left.evaluate(t)??this.right.evaluate(t):r(this.left.evaluate(t),this.right.evaluate(t))},getIds(t){return this.left.getIds(t),this.right.getIds(t),t}}}getter(t,e){return{type:"Getter",receiver:t,name:e,evaluate(t){return this.receiver.evaluate(t)?.[this.name]},getIds(t){return this.receiver.getIds(t)}}}invoke(t,e,n){return{type:"Invoke",receiver:t,method:e,arguments:n,evaluate(t){const e=this.receiver.evaluate(t),n=this.method?e:t?.this??t,r=this.method?e?.[this.method]:e,s=(this.arguments??[]).map(e=>e?.evaluate(t));return r?.apply?.(n,s)},getIds(t){return this.receiver.getIds(t),this.arguments?.forEach(e=>e?.getIds(t)),t}}}paren(t){return t}index(t,e){return{type:"Index",receiver:t,argument:e,evaluate(t){return this.receiver.evaluate(t)?.[this.argument.evaluate(t)]},getIds(t){return this.receiver.getIds(t)}}}ternary(t,e,n){return{condition:t,trueExpr:e,falseExpr:n,evaluate(t){return this.condition.evaluate(t)?this.trueExpr.evaluate(t):this.falseExpr.evaluate(t)},getIds(t){return this.condition.getIds(t),this.trueExpr.getIds(t),this.falseExpr.getIds(t),t}}}map(t){return{entries:t,evaluate(t){const e={};if(this.entries)for(const n in this.entries)this.entries[n]&&(e[n]=this.entries[n].evaluate(t));return e},getIds(t){if(this.entries)for(const e in this.entries)this.entries[e]&&this.entries[e].getIds(t);return t}}}list(t){return{items:t,evaluate(t){return this.items?.map(e=>e?.evaluate(t))},getIds(t){return this.items?.forEach(e=>e?.getIds(t)),t}}}arrowFunction(t,e){return{params:t,body:e,evaluate(t){const e=this.params,n=this.body;return function(...r){const s=Object.fromEntries(e.map((t,e)=>[t,r[e]])),i=new Proxy(t??{},{set:(t,e,n)=>(Object.hasOwn(s,e)&&(s[e]=n),t[e]=n),get:(t,e)=>Object.hasOwn(s,e)?s[e]:t[e]});return n.evaluate(i)}},getIds(t){return this.body.getIds(t).filter(t=>!this.params.includes(t))}}}},z=t=>{const e=t.trim();return e.startsWith("<")&&e.endsWith(">")?"'"+e.replace(/'/g,"\\'")+"'":((t,e)=>{let n="",r=0,s=0;for(;s<t.length;){const i=t[s];if("'"!==i&&'"'!==i){s++;continue}n+=e(t.slice(r,s));const o=s++;for(;s<t.length;)if("\\"!==t[s]){if(t[s++]===i)break}else s+=2;n+=t.slice(o,s),r=s}return n+e(t.slice(r))})(t=(t=>{const e=[];let n=0,r=null;for(let s=0;s<t.length;s++){const i=t[s],o=t[s-1];'"'!==i&&"'"!==i||"\\"===o?r||("("===i||"["===i||"{"===i?n++:")"===i||"]"===i||"}"===i?n--:","===i&&0===n&&e.push(s)):r===i?r=null:r||(r=i)}if(0===e.length)return t;const s=[];let i=0;for(const n of e)s.push(t.slice(i,n).trim()),i=n+1;return s.push(t.slice(i).trim()),`[${s.join(", ")}].pop()`})(t=(t=>{let e="",n=0;for(;n<t.length;)if("`"===t[n]){n++;let r=[],s="";for(;n<t.length&&"`"!==t[n];)if("$"===t[n]&&"{"===t[n+1]){(s||0===r.length)&&r.push(`'${s}'`),s="",n+=2;let e=1,i="";for(;n<t.length&&e>0;)"{"===t[n]?e++:"}"===t[n]&&e--,e>0&&(i+=t[n]),n++;r.push(`(${i})`)}else if("\\"===t[n]&&n+1<t.length){const e=t[n+1];s+="n"===e?"\\n":"t"===e?"\\t":"`"===e?"`":"$"===e?"$":"\\"===e?"\\\\":t[n+1],n+=2}else"'"===t[n]?s+="\\'":s+=t[n],n++;(s||0===r.length)&&r.push(`'${s}'`),n++,e+=r.join(" + ")}else e+=t[n],n++;return e})(t)),t=>t.replace(/\bnew\s+Date\b/g,"$Date").replace(/\bnew\s+FormData\b/g,"$FormData").replace(/(\$?\w+(?:\.\w+|\[\w+\])*)(\+\+)/g,"($1 = $1 + 1) - 1").replace(/(\$?\w+(?:\.\w+|\[\w+\])*)(\-\-)/g,"($1 = $1 - 1) + 1").replace(/\+\+(\$?\w+(?:\.\w+|\[\w+\])*)/g,"($1 = $1 + 1)").replace(/\-\-(\$?\w+(?:\.\w+|\[\w+\])*)/g,"($1 = $1 - 1)"))},W=new Map,G=new Set(["null","undefined","true","false","this","NaN","Infinity","Math","console","Object","Array","String","Number","Boolean","Date","JSON","Map","Set"]),J={},B=t=>{for(const[e,n]of Object.entries(t))void 0===n?delete J[e]:J[e]=n},K={diagnosticName:"csp",compile(t,e=!0){const n=z(t.trim()),r=`${e}:${n}`;if(W.has(r))return W.get(r);try{const t=(t=>new H(t,F).parse())(n),e={execute:e=>t?t.evaluate(e):void 0,getIds:()=>t?t.getIds([]).filter(t=>!G.has(t)):[]};return W.set(r,e),e}catch(e){const n={execute:()=>t,getIds:()=>[],error:e};return W.set(r,n),n}},createScope(t){const e={console,Math,Date,JSON,Object,Array,String,Number,Boolean,Map,Set,Promise,URL,URLSearchParams,parseInt,parseFloat,isNaN,isFinite,encodeURIComponent,decodeURIComponent,encodeURI,decodeURI,atob,btoa,...J,$:t.$,$el:t.el,$event:t.event,$data:t.state,$root:t.rootElement,$scope:t.scopeElement,$refs:t.pluralRefs,$dispatch:t.dispatch,$html:t.html,$Date:(...t)=>new Date(...t),$FormData:t=>new FormData(t),$get:t.get,$post:t.post,$put:t.put,$patch:t.patch,$delete:t.del,...t.refs};return new Proxy(e,{get:(e,n)=>n in e?e[n]:t.state[n],set:(e,n,r)=>(n in e?e[n]=r:t.state[n]=r,!0)})}},{helium:Z,heliumTeardown:q,mount:X}=g({engine:K}),V=!1,Q=null,Y=()=>{V=!0,null!==Q&&clearTimeout(Q),Q=null},tt=t=>(Y(),Z(t));tt.mount=(t,e)=>(Y(),X(t,e)),tt.allowGlobals=B;var et=()=>{Y(),q()},nt=(t,e)=>K.compile(t).execute(e);if("undefined"!=typeof window&&(window.helium=tt,window.heliumTeardown=et),"undefined"!=typeof document){const t=()=>{Q=null,V||tt()};"loading"===document.readyState?document.addEventListener("DOMContentLoaded",t,{once:!0}):Q=setTimeout(t,0),document.addEventListener("turbo:before-render",()=>{q(),V=!1}),document.addEventListener("turbo:render",()=>tt())}var rt=async(t,e,n,r,s=()=>!0)=>{const i=t.body.getReader(),o=new TextDecoder;let a="",c=null,l=e.retry||3e3;const u=()=>{const t=a.split(/\r\n\r\n|\r\r|\n\n/);a=t.pop();for(const n of t){if(!n.trim())continue;let t="",i="",o=null;for(const e of n.split(/\r\n|\r|\n/))e.startsWith("data:")?t+=(t?"\n":"")+e.slice(5).trimStart():e.startsWith("event:")?i=e.slice(6).trim():e.startsWith("id:")?o=e.slice(3).trim():e.startsWith("retry:")&&(l=parseInt(e.slice(6).trim())||l);if(o&&(c=o),t&&s()){const n=e.target?.length?e.target:i?[i]:void 0;r(t,n,e.action,e.template)}}},h=()=>setTimeout(async()=>{if(s())try{await n(c)}catch(t){console.error("SSE:",t.message),"always"!==e.retryMode&&"error"!==e.retryMode||!s()||h()}},l);try{for(;s();){const{done:t,value:e}=await i.read();if(t)break;a+=o.decode(e,{stream:!0}),u()}a.trim()&&s()&&(a+="\n\n",u()),"always"===e.retryMode&&s()&&h()}catch(t){console.error("SSE:",t.message),"always"!==e.retryMode&&"error"!==e.retryMode||!s()||h()}};b=rt;var st=tt;export{B as allowGlobals,st as default,nt as evaluate,rt as handleSSE,tt as helium,et as heliumTeardown,z as preprocess};
|