ilha 0.8.1 → 0.8.2
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.
|
@@ -217,7 +217,14 @@ interface EffectEntry<TInput, TStateMap extends Record<string, unknown>, TDerive
|
|
|
217
217
|
/** Where the error originated. `"on"` covers sync throws and async rejections
|
|
218
218
|
* from `.on()` handlers; `"effect"` covers sync throws from `.effect()` runs
|
|
219
219
|
* (async work spawned inside an effect is not awaited by the runtime). */
|
|
220
|
-
type ErrorSource = "on" | "effect";
|
|
220
|
+
type ErrorSource = "on" | "effect" | "mount" | "transition";
|
|
221
|
+
/**
|
|
222
|
+
* Register a global error handler invoked when any island reports an error
|
|
223
|
+
* (from .on, .effect, .onMount, or transitions) and has no local .onError()
|
|
224
|
+
* handler. Returns an unsubscribe function. Islands with their own .onError()
|
|
225
|
+
* are handled locally and do not reach the global sink.
|
|
226
|
+
*/
|
|
227
|
+
declare function onUncaughtError(fn: (error: Error, source: ErrorSource) => void): () => void;
|
|
221
228
|
type ErrorContext<TInput, TStateMap extends Record<string, unknown>, TDerivedMap extends Record<string, unknown> = Record<never, never>> = {
|
|
222
229
|
error: Error;
|
|
223
230
|
source: ErrorSource;
|
|
@@ -284,6 +291,7 @@ declare const ilha: IlhaBuilder<Record<string, unknown>, Record<never, never>, R
|
|
|
284
291
|
signal: typeof ilhaSignal;
|
|
285
292
|
batch: typeof batch;
|
|
286
293
|
untrack: typeof untrack;
|
|
294
|
+
onUncaughtError: typeof onUncaughtError;
|
|
287
295
|
};
|
|
288
296
|
/** @internal Used by the separate JSX runtime entry to preserve island slot composition. */
|
|
289
297
|
declare function __ilhaJsxSlot(island: unknown, props: Record<string, unknown> | undefined, key: string | undefined): RawHtml;
|
|
@@ -294,4 +302,4 @@ declare const mount: typeof mountAll;
|
|
|
294
302
|
declare const from: typeof ilhaFrom;
|
|
295
303
|
declare const context: typeof ilhaContext;
|
|
296
304
|
//#endregion
|
|
297
|
-
export {
|
|
305
|
+
export { raw as A, css as C, ilhaSignal as D, ilha as E, mount as O, context as S, html as T, OnMountContext as _, ErrorSource as a, __ilhaJsxSlot as b, HandlerContextFor as c, Island as d, IslandDerived as f, MountResult as g, MountOptions as h, ErrorContext as i, untrack as j, onUncaughtError as k, HydratableOptions as l, KeyedIsland as m, DerivedValue as n, ExternalSignal as o, IslandState as p, EffectContext as r, HandlerContext as s, DerivedAccessor as t, ISLAND_MOUNT_INTERNAL as u, RawHtml as v, from as w, batch as x, SignalAccessor as y };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { A as
|
|
2
|
-
export { DerivedAccessor, DerivedValue, EffectContext, ErrorContext, ErrorSource, ExternalSignal, HandlerContext, HandlerContextFor, HydratableOptions, ISLAND_MOUNT_INTERNAL, Island, IslandDerived, IslandState, KeyedIsland, MountOptions, MountResult, OnMountContext, RawHtml, SignalAccessor, __ilhaJsxSlot, batch, context, css, ilha as default, from, html, ilhaSignal, ilhaSignal as signal, mount, raw, untrack };
|
|
1
|
+
import { A as raw, C as css, D as ilhaSignal, E as ilha, O as mount, S as context, T as html, _ as OnMountContext, a as ErrorSource, b as __ilhaJsxSlot, c as HandlerContextFor, d as Island, f as IslandDerived, g as MountResult, h as MountOptions, i as ErrorContext, j as untrack, k as onUncaughtError, l as HydratableOptions, m as KeyedIsland, n as DerivedValue, o as ExternalSignal, p as IslandState, r as EffectContext, s as HandlerContext, t as DerivedAccessor, u as ISLAND_MOUNT_INTERNAL, v as RawHtml, w as from, x as batch, y as SignalAccessor } from "./index-D8LU_XMC.js";
|
|
2
|
+
export { DerivedAccessor, DerivedValue, EffectContext, ErrorContext, ErrorSource, ExternalSignal, HandlerContext, HandlerContextFor, HydratableOptions, ISLAND_MOUNT_INTERNAL, Island, IslandDerived, IslandState, KeyedIsland, MountOptions, MountResult, OnMountContext, RawHtml, SignalAccessor, __ilhaJsxSlot, batch, context, css, ilha as default, from, html, ilhaSignal, ilhaSignal as signal, mount, onUncaughtError, raw, untrack };
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import{effect as e,endBatch as t,setActiveSub as n,signal as r,startBatch as i}from"alien-signals";const a=typeof
|
|
2
|
-
`)}`);return n.value}const
|
|
1
|
+
import{effect as e,endBatch as t,setActiveSub as n,signal as r,startBatch as i}from"alien-signals";const a=256*1024;function o(e,t){if(t>32)return!0;if(typeof e!=`object`||!e)return!1;if(Array.isArray(e)){for(let n of e)if(o(n,t+1))return!0;return!1}for(let n in e)if(Object.prototype.hasOwnProperty.call(e,n)&&o(e[n],t+1))return!0;return!1}function s(e,t){if(e.length>a){`${t}${a}`;return}let n;try{n=JSON.parse(e)}catch{`${t}`;return}if(o(n,1)){`${t}`;return}if(typeof n!=`object`||!n||Array.isArray(n)){`${t}`;return}return n}function c(e,t){if(Object.is(e,t))return!0;if(typeof e!=`object`||!e||typeof t!=`object`||!t)return!1;let n=Object.keys(e),r=Object.keys(t);if(n.length!==r.length)return!1;for(let r of n)if(!Object.prototype.hasOwnProperty.call(t,r)||!Object.is(e[r],t[r]))return!1;return!0}function l(e){if(typeof document>`u`)return[];let t=document.createElement(`template`);t.innerHTML=e;let n=t.content,r=[];for(let e of n.querySelectorAll(`[data-ilha-slot]`)){if(!(e instanceof Element))continue;let t=e.parentElement??e.parentNode,i=!1;for(;t&&t!==n;){if(t instanceof Element&&t.hasAttribute(`data-ilha-slot`)){i=!0;break}t=t instanceof Element?t.parentElement??t.parentNode:t.parentNode}i||r.push(e.getAttribute(`data-ilha-slot`))}return r}function u(e,t){let n=t.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`),r=RegExp(`<[a-z][a-z0-9-]*\\s[^>]*data-ilha-slot="${n}"[^>]*data-ilha-props='([^']*)'`,`i`),i=e.match(r);if(i)return i[1];let a=RegExp(`<[a-z][a-z0-9-]*\\s[^>]*data-ilha-slot="${n}"`,`i`);return e.match(a)?``:null}const d=/^[a-z][a-z0-9-]*$/i;function f(e){let t=e.trim();if(t.length===0)throw Error(`island.as() requires a non-empty HTML tag name.`);if(!d.test(t))throw Error(`island.as() tag must be a valid HTML element name (got "${e}"). Use names like "span", "div", or "li".`);return t.toLowerCase()}function p(e){let t=e[O];return typeof t==`string`&&t.length>0?t:`div`}function m(e,t,n,r){return`<${e} ${k}="${x(t)}"${n}>${r}</${e}>`}function ee(e,t,n){let r=l(e),i=l(t);if(r.length!==i.length||r.some((e,t)=>e!==i[t]))return!1;for(let r of n){let n=u(e,r),i=u(t,r);if(n===null||i===null||n!==i)return!1}return!0}function te(e){return e===void 0?``:JSON.stringify(e)}const h=new Set([`data-checked`,`data-unchecked`,`data-indeterminate`,`aria-checked`,`data-open`,`data-closed`,`data-state`,`aria-expanded`,`aria-hidden`,`data-selected`,`data-panel-open`]);function g(e,t){return e.matches(`[data-slot]`)&&h.has(t)}function _(e,t){for(let{name:n,value:r}of t.attributes)g(e,n)||e.getAttribute(n)!==r&&e.setAttribute(n,r);for(let{name:n}of Array.from(e.attributes))g(e,n)||t.hasAttribute(n)||e.removeAttribute(n)}function v(e,t){let n=Array.from(e.childNodes),r=Array.from(t.childNodes);for(let e=n.length-1;e>=r.length;e--)n[e].remove();for(let t=0;t<r.length;t++){let i=r[t],a=n[t];if(!a){e.appendChild(i.cloneNode(!0));continue}if(a.nodeType!==i.nodeType){e.replaceChild(i.cloneNode(!0),a);continue}if(a.nodeType===3||a.nodeType===8){a.nodeValue!==i.nodeValue&&(a.nodeValue=i.nodeValue);continue}if(a.nodeType===1){let t=a,n=i;if(t.localName!==n.localName||t.namespaceURI!==n.namespaceURI){e.replaceChild(n.cloneNode(!0),t);continue}if(t.localName===`input`&&t.type!==n.type){e.replaceChild(n.cloneNode(!0),t);continue}if(_(t,n),t.localName===`textarea`){let e=n.textContent??``;t.textContent!==e&&(t.textContent=e),t.value=t.defaultValue}else v(t,n)}}}function ne(e,t){if(e.localName!==t.localName||e.namespaceURI!==t.namespaceURI)throw Error(`[ilha] morph: elements must match`);v(e,t)}function y(e,t){let n=e[`~standard`].validate(t);if(n instanceof Promise)throw Error(`[ilha] Async schemas are not supported.`);if(n.issues)throw Error(`[ilha] Validation failed:\n${n.issues.map(e=>` - ${e.message}`).join(`
|
|
2
|
+
`)}`);return n.value}const b={"&":`&`,"<":`<`,">":`>`,'"':`"`,"'":`'`};function x(e){return String(e).replace(/[&<>"']/g,e=>b[e])}function S(e){if(e.length===0||e[0]!==`
|
|
3
3
|
`)return e;let t=e.split(`
|
|
4
4
|
`);for(;t.length&&t[0].trim()===``;)t.shift();for(;t.length&&t[t.length-1].trim()===``;)t.pop();if(!t.length)return``;let n=Math.min(...t.filter(e=>e.trim()!==``).map(e=>e.match(/^(\s*)/)[1].length));return t.map(e=>e.slice(n)).join(`
|
|
5
|
-
`)}const x=Symbol.for(`ilha.raw`),S=Symbol.for(`ilha.signalAccessor`),C=Symbol.for(`ilha.island`),w=Symbol.for(`ilha.islandCall`),ie=Symbol.for(`ilha.islandMountInternal`),T=Symbol.for(`ilha.islandSlotTag`),E=`data-ilha-slot`,D=`data-ilha-props`,ae=`data-ilha-state`;function oe(e){return`<style data-ilha-css>@scope (:scope) to ([data-ilha]){${e}}</style>`}const O=[];function k(e,t){let n={slots:new Map,positional:0,liveHost:e,pending:t?new Map:void 0,binds:[],slotTags:new Map};return O.push(n),n}function A(){O.pop()}function j(){return O[O.length-1]}function M(e){return typeof e==`function`?C in e?!0:Object.getOwnPropertySymbols(e).some(e=>e.description===`ilha.island`):!1}function N(e){if(e==null||typeof e!=`object`&&typeof e!=`function`)return!1;if(w in e||Object.getOwnPropertySymbols(e).some(e=>e.description===`ilha.islandCall`))return!0;if(typeof e==`object`&&`island`in e){let t=e.island;return typeof t==`function`&&(C in t||Object.getOwnPropertySymbols(t).some(e=>e.description===`ilha.island`))}return!1}function P(e,t,n){let r=j(),i;n===void 0?i=r?`p:${r.positional++}`:`p:0`:(i=`k:${n}`,r&&a&&r.slots.has(i)&&o(`Duplicate slot key "${n}" — two children with the same key in a single render will collide. Each .key() call must be unique.`)),r&&r.slots.set(i,{island:e,props:t});let s=f(e);r&&r.slotTags.set(i,s);let c=t?` ${D}='${y(JSON.stringify(t))}'`:``;if(r?.liveHost)return p(s,i,c,``);if(r?.pending){A();try{let n=e(t);return n instanceof Promise?(r.pending.set(i,n.then(String)),p(s,i,c,``)):p(s,i,c,String(n))}finally{O.push(r)}}let l=e.toString(t);return p(s,i,c,l)}async function se(e,t){for(let[n,r]of t.pending){let i=await r,a=t.slotTags.get(n)??`div`,o=y(n);if(o.length>500)throw Error(`Slot id exceeds safe length for regex replacement (${o.length} > 500).`);let s=o.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`),c=a.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`),l=RegExp(`<${c}\\s[^>]*${E}="${s}"[^>]*></${c}>`,`g`);e=e.replace(l,e=>{let t=`></${a}>`;return e.slice(0,-t.length)+`>${i}</${a}>`})}return e}function F(e){e[S]=!0;let t=e;return t.select=e=>le(t,e),t}function I(e){return typeof e==`function`?S in e?!0:Object.getOwnPropertySymbols(e).some(e=>e.description===`ilha.signalAccessor`):!1}function L(e,t){let n=e;for(let e of t){if(n==null)return;n=n[e]}return n}function R(e,t,n){if(t.length===0)return n;let[r,...i]=t;if(Array.isArray(e)){let t=r;if(t<0||t>=e.length)return e;let a=e[t],o=i.length===0?n:R(a,i,n);if(Object.is(a,o))return e;let s=e.slice();return s[t]=o,s}if(typeof e==`object`&&e){let t=e,a=String(r),o=t[a],s=i.length===0?n:R(o,i,n);if(i.length===0){if(Object.is(o,n))return e}else if(Object.is(o,s))return e;return{...t,[a]:s}}return i.length===0?n:R(void 0,i,n)}function z(e){return typeof e==`symbol`||e===`length`?null:/^\d+$/.test(e)?Number(e):e}function ce(e,t){let n=[],r=e=>e===null||typeof e!=`object`&&typeof e!=`function`?e:new Proxy(e,{get(e,t,i){let a=z(t);a!=null&&n.push(a);let o=Reflect.get(e,t,i);return a!=null&&typeof o==`object`&&o?r(o):o}});return t(r(e)),n}function le(e,t){let n=ce(e(),t),r=t(e()),i=n.length===0?e():L(e(),n);if(!Object.is(r,i)){let e=`select(): selector must only traverse nested properties or array indexes — derived or transformed values are not supported.`;throw a&&o(e),Error(e)}return a&&n.length===0&&o(`select(): selector did not traverse nested state — bind writes may replace the entire root value.`),F((...r)=>{if(r.length===0)return n.length===0?t(e()):L(e(),n);let i=n.length===0?r[0]:R(e(),n,r[0]);Object.is(e(),i)||e(i)})}function B(e){return{[x]:!0,value:e}}function V(e,...t){if(typeof e==`string`)return e;let n=``;for(let r=0;r<e.length;r++)n+=e[r],r<t.length&&(n+=String(t[r]));return n}function H(e){if(e==null||e===!0||e===!1)return``;if(Array.isArray(e))return e.map(H).join(``);if(Y(e))return e.value;if(N(e)){let t=typeof e==`function`?e():e;return P(t.island,t.props,t.key)}return M(e)?P(e,void 0,void 0):I(e)||typeof e==`function`?y(e()):y(e)}const U=new Set([`value`,`checked`,`valueAsNumber`,`valueAsDate`,`files`,`open`,`group`,`this`]),W=/\bbind:([a-zA-Z]+)\s*=\s*("|')?$/;function G(e){if(e instanceof Date){if(isNaN(e.getTime()))return a&&o(`bind:valueAsDate received an invalid Date object — value attribute will be empty.`),``;let t=e=>String(e).padStart(2,`0`);return`${e.getFullYear()}-${t(e.getMonth()+1)}-${t(e.getDate())}`}return``}function K(e){let t=e.lastIndexOf(`<`);if(t===-1)return null;let n=e.slice(t);if(n.includes(`>`))return null;let r=n.match(/\bvalue\s*=\s*("([^"]*)"|'([^']*)'|([^\s>]+))/);return r?r[2]??r[3]??r[4]??null:null}function q(e,t,n,r){let i=`${e}:${t}`,a;try{a=n()}catch{a=void 0}switch(e){case`value`:return[` value="${y(a??``)}"`,i];case`valueAsNumber`:return[` value="${y(a==null?``:String(a))}"`,i];case`valueAsDate`:return[` value="${y(G(a))}"`,i];case`checked`:return[a?` checked`:``,i];case`open`:return[a?` open`:``,i];case`files`:return[``,i];case`this`:return[``,i];case`group`:{let e=K(r);return e==null?[``,i]:[(Array.isArray(a)?a.map(String).includes(e):a!=null&&String(a)===e)?` checked`:``,i]}}}function J(e,...t){let n=``,r=null,i=``,s=j();for(let c=0;c<e.length;c++){let l=e[c];if(r!==null&&(l.startsWith(r)&&(l=l.slice(1)),r=null),i!==``){let e=l.indexOf(`>`);e!==-1&&(l=l.slice(0,e)+` data-ilha-bind="${i}">`+l.slice(e+1),i=``)}if(c>=t.length){n+=l;continue}let u=t[c],d=l.match(W);if(d&&I(u)){let e=d[1],t=d[2]??null;if(!U.has(e)){a&&o(`Unknown bind:${e} — supported bindings are ${[...U].map(e=>`bind:${e}`).join(`, `)}.`),n+=l+H(u);continue}if(!s){a&&o(`bind:${e} used outside an island render — bindings only work in .render(). The value is reflected once but not wired.`);let i=l.slice(0,l.length-d[0].length),s=t??`"`;n+=i+e+`=`+s+H(u)+s,t&&(r=t);continue}let c=l.length-d[0].length,f=l.slice(0,c).replace(/\s+$/,``),p=s.binds.length;s.binds.push({kind:e,accessor:u});let[m,ee]=q(e,p,u,f);n+=f+m,i+=(i?`,`:``)+ee,t&&(r=t);continue}d&&a&&o(`bind:${d[1]} requires a signal accessor — got ${typeof u}. Use ilha.signal() or a .state() accessor.`),n+=l+H(u)}return i!==``&&(n+=` data-ilha-bind="${i}"`),{[x]:!0,value:b(n)}}function Y(e){return typeof e!=`object`||!e||!(`value`in e)||typeof e.value!=`string`?!1:x in e?!0:Object.getOwnPropertySymbols(e).some(e=>e.description===`ilha.raw`)}function ue(e){return Y(e)?e.value:e}const X=new Map;function Z(e,t){if(X.has(e))return X.get(e);let n=r(t),i=(...e)=>{if(e.length===0)return n();n(e[0])};return X.set(e,i),i}function de(e){let t=r(e);return F((...e)=>{if(e.length===0)return t();t(e[0])})}function fe(e){let t=n(void 0);try{return e()}finally{n(t)}}function pe(e){i();try{return e()}finally{t()}}function me(e,t){let n=F((...n)=>{if(n.length>0){t?t(n[0]):a&&o(`derived values are read-only`);return}return e().value});return new Proxy(n,{get(t,n,r){return n===`loading`||n===`value`||n===`error`?e()[n]:Reflect.get(t,n,r)}})}function he(){return me(()=>({loading:!1,value:void 0,error:void 0}))}function ge(e){let t=new Map;for(let[n,r]of Object.entries(e))t.set(n,me(()=>r,e=>{r.loading=!1,r.value=e,r.error=void 0}));return new Proxy({},{get(e,n){return t.get(n)??he()}})}function _e(t,i,a,o){let s=new Map;for(let e of t){let t;if(o!=null&&e.key in o)t={...o[e.key]};else if(e.fn.constructor.name===`AsyncFunction`||e.fn.constructor.name===`AsyncGeneratorFunction`)t={loading:!0,value:void 0,error:void 0};else{let n=new AbortController;try{let r=e.fn({state:i,input:a,signal:n.signal});r instanceof Promise?(t={loading:!0,value:void 0,error:void 0},r.catch(()=>{})):t={loading:!1,value:r,error:void 0}}catch(e){t={loading:!1,value:void 0,error:e instanceof Error?e:Error(String(e))}}finally{n.abort()}}let n=r(t);s.set(e.key,n)}let c=new Map;for(let e of t){let t=s.get(e.key);c.set(e.key,me(()=>t(),e=>{let r=n(void 0);t({loading:!1,value:e,error:void 0}),n(r)}))}return{proxy:new Proxy({},{get(e,t){return c.get(t)??he()}}),setup:()=>{let r=[];for(let c of t){let t=s.get(c.key),l=new AbortController,u=o!=null&&c.key in o,d=e(()=>{l.abort(),l=new AbortController;let e=l,r;try{r=c.fn({state:i,input:a,signal:e.signal})}catch(e){if(u){u=!1;return}let r=n(void 0);t({loading:!1,value:void 0,error:e instanceof Error?e:Error(String(e))}),n(r);return}if(u){u=!1,r instanceof Promise&&r.catch(()=>{});return}if(!(r instanceof Promise)){let e=n(void 0);t({loading:!1,value:r,error:void 0}),n(e);return}let o=n(void 0);t({loading:!0,value:t().value,error:void 0}),n(o),r.then(n=>{e.signal.aborted||t({loading:!1,value:n,error:void 0})}).catch(n=>{e.signal.aborted||t({loading:!1,value:void 0,error:n instanceof Error?n:Error(String(n))})})});r.push(()=>{d(),l.abort()})}return()=>r.forEach(e=>e())}}}const Q=`data-ilha-bind`;function ve(e){let t=[];for(let n of e.split(`,`)){let[e,r]=n.split(`:`);if(!e||!r)continue;let i=Number(r);!Number.isInteger(i)||i<0||t.push({kind:e,index:i})}return t}function ye(e,t){let n=e;switch(t){case`value`:return{event:e.tagName===`SELECT`?`change`:`input`,read:e=>e.value,write:(e,t)=>e.value=t==null?``:String(t)};case`valueAsNumber`:return{event:`input`,read:e=>{let t=e.valueAsNumber;return Number.isNaN(t)?null:t},write:(e,t)=>e.value=t==null||Number.isNaN(t)?``:String(t)};case`valueAsDate`:return{event:`input`,read:e=>e.valueAsDate,write:(e,t)=>{e.value=G(t)}};case`checked`:return{event:`change`,read:e=>e.checked,write:(e,t)=>e.checked=!!t};case`files`:return{event:`change`,read:e=>e.files,write:()=>{}};case`open`:return{event:`toggle`,read:e=>e.open,write:(e,t)=>e.open=!!t};case`this`:return{event:null,read:()=>void 0,write:()=>{}};case`group`:{let e=n.type===`checkbox`;return{event:`change`,read:t=>{let n=t;return e?{__ilhaGroup:!0,value:n.value,checked:n.checked}:n.checked?n.value:void 0},write:(t,n)=>{let r=t;e?r.checked=(Array.isArray(n)?n.map(String):[]).includes(r.value):r.checked=n!=null&&String(n)===r.value}}}}}function be(e,t){if(t.length===0)return()=>{};let n=[],r=[];e.hasAttribute(Q)&&r.push(e);for(let t of e.querySelectorAll(`[${Q}]`))r.push(t);for(let e of r){let r=ve(e.getAttribute(Q));for(let i of r){let r=t[i.index];if(!r){a&&o(`bind:${i.kind} index ${i.index} not found in render — the data-ilha-bind sentinel may have been hand-edited or survived a stale render.`);continue}if(r.kind!==i.kind){a&&o(`bind:${i.kind} sentinel points at a binding registered as bind:${r.kind}. Sentinel may be stale.`);continue}let{event:s,read:c,write:l}=ye(e,i.kind),u=r.accessor;if(i.kind===`this`){u(e),n.push(()=>u(null));continue}try{l(e,u())}catch(e){a&&console.error(`[ilha] bind:${i.kind} write failed:`,e)}if(s===null)continue;let d=()=>{let t=c(e);if(i.kind===`group`){let e=t;if(e===void 0)return;if(typeof e==`object`&&e.__ilhaGroup){let t=u(),n=Array.isArray(t)?[...t]:[],r=n.findIndex(t=>String(t)===e.value);if(e.checked&&r===-1){let r=e.value,i=Array.isArray(t)&&t.length>0?t[0]:void 0;if(i!==void 0)if(typeof i==`number`){let e=Number(r);r=Number.isNaN(e)?r:e}else typeof i==`boolean`&&(r=!!r);n.push(r)}else !e.checked&&r!==-1&&n.splice(r,1);u(n);return}let n=u(),r=e;if(typeof n==`number`&&typeof e==`string`){let t=Number(e);r=Number.isNaN(t)?0:t}else typeof n==`boolean`&&(r=!!e);u(r);return}let n=u(),r=t;if(typeof n==`number`&&typeof t==`string`){let e=Number(t);r=Number.isNaN(e)?0:e}else typeof n==`boolean`&&(r=!!t);u(r)};e.addEventListener(s,d),n.push(()=>e.removeEventListener(s,d))}}return()=>n.forEach(e=>e())}function xe(e){let t=e.lastIndexOf(`@`),n=t===-1?``:e.slice(0,t),r=(t===-1?e:e.slice(t+1)).split(`:`),i=r[0],a=new Set(r.slice(1));return{selector:n,eventType:i,options:{once:a.has(`once`),capture:a.has(`capture`),passive:a.has(`passive`)},abortable:a.has(`abortable`)}}function Se(e){if(typeof AbortSignal.any==`function`)return AbortSignal.any(e);let t=new AbortController,n=[];for(let r of e){if(r.aborted)return t.abort(r.reason),n.forEach(e=>e()),t.signal;let e=()=>t.abort(r.reason);r.addEventListener(`abort`,e,{once:!0}),n.push(()=>r.removeEventListener(`abort`,e))}return t.signal.aborted||t.signal.addEventListener(`abort`,()=>{n.forEach(e=>e())}),t.signal}const $=a?new WeakSet:null;var Ce=class c{_cfg;constructor(e){this._cfg=e}input(e){return new c({schema:e??null,states:[],deriveds:[],ons:[],effects:[],onMounts:[],onErrors:[],transition:null,css:null,as:null})}as(e){return new c({...this._cfg,as:d(e)})}state(e,t){let n=this._cfg;return new c({...n,states:[...n.states,{key:e,init:t}]})}derived(e,t){let n=this._cfg;return new c({...n,deriveds:[...n.deriveds,{key:e,fn:t}]})}on(e,t){let n=xe(e);return new c({...this._cfg,ons:[...this._cfg.ons,{selector:n.selector,event:n.eventType,options:n.options,abortable:n.abortable,handler:t}]})}effect(e){return new c({...this._cfg,effects:[...this._cfg.effects,{fn:e}]})}onMount(e){return new c({...this._cfg,onMounts:[...this._cfg.onMounts,{fn:e}]})}onError(e){return new c({...this._cfg,onErrors:[...this._cfg.onErrors,{fn:e}]})}transition(e){return new c({...this._cfg,transition:e})}css(e,...t){let n;if(typeof e==`string`)n=e;else{let r=``;for(let n=0;n<e.length;n++)r+=e[n],n<t.length&&(r+=String(t[n]));n=r}return a&&this._cfg.css!==null&&o(`css(): called more than once on the same builder chain. The previous stylesheet has been discarded. Compose styles into a single .css() call instead.`),new c({...this._cfg,css:n})}render(c){let{schema:l,states:u,deriveds:f,ons:p,effects:te,onMounts:h,onErrors:ne,transition:g,css:v,as:b}=this._cfg,x=v==null?``:oe(v),S=b??`div`;function O(e){let t=e??{};return l?_(l,t):t}function M(e,t,n){let r=k(t,n),i=!1;try{let t=ue(e());return r.pending&&r.pending.size>0?(i=!0,(async()=>{try{return{html:await se(t,r),slots:r.slots,binds:r.binds}}finally{A()}})()):{html:t,slots:r.slots,binds:r.binds}}finally{i||A()}}function N(e){let t={};for(let n of u){let r=typeof n.init==`function`?n.init(e):n.init,i=F((...e)=>{if(e.length===0)return r});t[n.key]=i}return t}function P(e,t){let n={};for(let i of u){let a=r(t&&i.key in t?t[i.key]:typeof i.init==`function`?i.init(e):i.init),o=F((...e)=>{if(e.length===0)return a();a(e[0])});n[i.key]=o}return n}function I(e,t=!1){let r=O(e),i=N(r),a=f.map(e=>{let t=n(void 0);try{return{key:e.key,result:e.fn({state:i,input:r,signal:new AbortController().signal})}}catch(t){return{key:e.key,result:Promise.reject(t)}}finally{n(t)}});if(!a.some(e=>e.result instanceof Promise)||t){let e={};for(let t of a)t.result instanceof Promise?e[t.key]={loading:!0,value:void 0,error:void 0}:e[t.key]={loading:!1,value:t.result,error:void 0};let t=ge(e),o=n(void 0);try{let{html:e}=M(()=>c({state:i,derived:t,input:r}));return x+e}finally{n(o)}}return Promise.all(a.map(async e=>{try{return{key:e.key,envelope:{loading:!1,value:await Promise.resolve(e.result),error:void 0}}}catch(t){return{key:e.key,envelope:{loading:!1,value:void 0,error:t instanceof Error?t:Error(String(t))}}}})).then(async e=>{let t={};for(let n of e)t[n.key]=n.envelope;let a=ge(t),o=n(void 0);try{let{html:e}=await M(()=>c({state:i,derived:a,input:r}),void 0,!0);return x+e}finally{n(o)}})}function L(e,t){return R(e,t).unmount}function R(l,u){let d={unmount:()=>{},updateProps:()=>{}};if(a&&$){if($.has(l))return o(`mount(): this element is already mounted. Call the previous unmount() first to avoid memory leaks and duplicate event listeners.
|
|
6
|
-
Element: ${l.outerHTML.slice(0,120)}`),d;$.add(l)}if(u===void 0){let e=l.getAttribute(D);if(e)try{u=JSON.parse(e)}catch{o(`Failed to parse data-ilha-props — invalid JSON, falling back to empty props.`)}}let _=r(O(u)),v=new Proxy({},{get(e,t){return _()[t]},has(e,t){return t in _()},ownKeys(){let e=n(void 0);try{return Reflect.ownKeys(_())}finally{n(e)}},getOwnPropertyDescriptor(e,t){let r=n(void 0);try{return Reflect.getOwnPropertyDescriptor(_(),t)}finally{n(r)}}}),y,b=l.getAttribute(ae);if(b)try{y=JSON.parse(b)}catch{o(`Failed to parse data-ilha-state — invalid JSON, snapshot ignored.`)}let S=y?Object.fromEntries(Object.entries(y).filter(([e])=>e!==`_derived`&&e!==`_skipOnMount`)):void 0,C=y?._derived,w;if(C){w={};for(let[e,t]of Object.entries(C))t.error&&!(t.error instanceof Error)?w[e]={...t,error:Error(String(t.error))}:w[e]=t}let T=y!=null,oe=T&&y?._skipOnMount===!0,k=P(v,S),A=[],j=new AbortController;if(A.push(()=>j.abort()),g?.enter){let e=g.enter(l);e instanceof Promise&&e.catch(console.error)}let{proxy:N,setup:se}=_e(f,k,v,w),F=()=>{};function I(e,t){let n=e instanceof Error?e:Error(String(e));if(ne.length===0){console.error(n);return}for(let e of ne)try{e.fn({error:n,source:t,state:k,derived:N,input:v,host:l})}catch(e){console.error(e)}}let L=new Map,R=new Map;function z(e,t){L.delete(e);let n=Symbol(),r=t.unmount(),i=t=>{let r=R.get(e);!r||r.token!==n||(r.el.remove(),t?.remove(),R.delete(e))};if(r instanceof Promise)return R.set(e,{el:t.el,token:n}),r.finally(()=>i());t.el.remove()}function ce(e){let t=new Set([...R.values()].map(e=>e.el)),n=typeof CSS<`u`&&CSS.escape?CSS.escape(e):e.replace(/["\\]/g,`\\$&`),r=l.querySelectorAll(`[${E}="${n}"]`);for(let e of r){if(t.has(e))continue;let n=e;for(;n&&n!==l&&!n.hasAttribute(`data-ilha`);)n=n.parentElement;if(n===l)return e}return null}function le(e){for(let[t,n]of L)e.has(t)||z(t,n);for(let[t,{island:r,props:i}]of e){let e=L.get(t);if(e){e.updateProps(i);continue}let a=ce(t);if(!a)continue;let s=i;if(s===void 0){let e=a.getAttribute(D)??a.getAttribute(`data-props`);if(e)try{s=JSON.parse(e)}catch{o(`Failed to parse props on [${E}="${t}"] — invalid JSON ignored.`)}}let c=n(void 0),l;try{let e=r[ie];l=e?e(a,s):{unmount:r.mount(a,s),updateProps:()=>{}}}finally{n(c)}L.set(t,{el:a,...l})}}let B=[],V=new Set,H=new WeakMap;function U(){for(let e of p){if(e.options.once&&V.has(e))continue;let n=e.selector===``?[l]:Array.from(l.querySelectorAll(e.selector));a&&e.selector!==``&&n.length===0&&o(`on(): selector "${e.selector}" matched no elements at mount time. If the element is rendered later, this is expected — otherwise check your selector.`),n.forEach(n=>{let r=r=>{if(e.options.once){V.add(e);for(let t of B.filter(t=>t.entry===e))t.target.removeEventListener(t.type,t.fn,t.options);B.splice(0,B.length,...B.filter(t=>t.entry!==e))}let a=r.target instanceof Element?r.target:n,o=e.selector===``?a:n,s;if(e.abortable){let t=H.get(e);t||(t=new WeakMap,H.set(e,t));let r=t.get(n);r&&r.abort();let i=new AbortController;t.set(n,i),s=Se([j.signal,i.signal])}else s=j.signal;let c;i();try{c=e.handler({state:k,derived:N,input:v,host:l,target:o,event:r,signal:s})}catch(e){I(e,`on`),t();return}t(),c instanceof Promise&&c.catch(e=>{e&&e.name===`AbortError`||I(e,`on`)})},a={...e.options,once:!1};n.addEventListener(e.event,r,a),B.push({target:n,type:e.event,fn:r,options:a,entry:e})})}}function W(){for(let e of B)e.target.removeEventListener(e.type,e.fn,e.options);B.length=0}let G=T&&l.childNodes.length>0,K=M(()=>c({state:k,derived:N,input:v}),G?l:void 0);G||(l.innerHTML=x+K.html);let q=be(l,K.binds);if(A.push(()=>q()),le(K.slots),A.push(()=>L.forEach(e=>e.unmount())),U(),!oe)for(let e of h){let t=n(void 0),r;try{r=e.fn({state:k,derived:N,input:v,host:l,hydrated:T})}finally{n(t)}r&&A.push(r)}for(let n of te){let r,a=null,o=e(()=>{if(r){try{r()}catch(e){I(e,`effect`)}r=void 0}a&&a.abort(),a=new AbortController;let e=Se([j.signal,a.signal]);i();try{r=n.fn({state:k,derived:N,input:v,host:l,signal:e})}catch(e){I(e,`effect`)}finally{t()}});A.push(()=>{if(o(),r)try{r()}catch(e){I(e,`effect`)}a&&a.abort()})}F=se(),A.push(F);let J=!1,Y=K.html,ue=0,X=e(()=>{let e=++ue,{html:t,slots:n,binds:r}=M(()=>c({state:k,derived:N,input:v}),l),i=x+t;if(!J&&(J=!0,t===Y||L.size>0&&L.size===n.size&&[...n.keys()].every(e=>L.has(e))&&m(Y,t,n.keys())))return;W(),q();let a=L.size,o=[];for(let[e,t]of L)if(!n.has(e)){let n=z(e,t);n instanceof Promise&&o.push(n)}let s=()=>{if(e!==ue)return;let t=new Map,o=n.size<a;for(let[e,r]of L){if(!n.has(e)||!r.el.isConnected)continue;if(o&&e.startsWith(`p:`)){z(e,r);continue}let i=r.el.tagName.toLowerCase(),a=document.createElement(i);a.setAttribute(E,e);let s=ee(n.get(e)?.props);s!==``&&a.setAttribute(D,s),r.el.replaceWith(a),t.set(e,r.el)}let s=document.createElement(`template`),c=l.tagName.toLowerCase();s.innerHTML=`<${c}>${i}</${c}>`,re(l,s.content.firstElementChild);for(let[e,n]of t){let t=ce(e);t&&t.replaceWith(n)}U(),q=be(l,r),le(n)};o.length>0?Promise.allSettled(o).then(e=>{for(let t of e)t.status===`rejected`&&console.error(t.reason);s()}):s()}),Z=!1;return{unmount:()=>{if(Z)return;Z=!0,a&&$&&$.delete(l),X(),W();let e=[];for(let[,t]of L){let n=t.unmount();n instanceof Promise&&e.push(n)}if(g?.leave){let t=g.leave(l);t instanceof Promise&&e.push(t)}let t=()=>{for(let e of A)e()};if(e.length>0)return Promise.all(e).then(t).catch(e=>{console.error(e),t()});t()},updateProps:e=>{if(Z)return;let t=O(e);s(_(),t)||_(t)}}}let z=function(e){return j()?{[w]:!0,island:z,props:e,key:void 0}:I(e)};return z.toString=e=>I(e,!0),z.mount=(e,t)=>L(e,t),z[ie]=(e,t)=>R(e,t),z[T]=S,z.key=e=>{if(typeof e!=`string`||e.trim().length===0)throw Error(`island.key() requires a non-empty string.`);if(e.includes(`:`))throw Error(`island.key() key cannot contain the slot separator ":" (got "${e}").`);let t=(t=>({[w]:!0,island:z,props:t,key:e}));return t[w]=!0,t},z[C]=!0,z.hydratable=async(e,t)=>{let{name:r,as:i=`div`,snapshot:a=!1,skipOnMount:o}=t,s=d(i),c=e??{},l=await I(c),p=y(JSON.stringify(c)),m=``;if(a!==!1){let e=a===!0||a.state!==!1,t=a===!0||a.derived!==!1,r=o??(e||t),i={},s=O(c),l=N(s);if(e)for(let e of u)i[e.key]=l[e.key]();if(t){let e={};for(let t of f){let r=n(void 0),i,a,o=!1;try{i=t.fn({state:l,input:s,signal:new AbortController().signal})}catch(e){o=!0,a=e}finally{n(r)}if(o){e[t.key]={loading:!1,value:void 0,error:a instanceof Error?a.message:String(a)};continue}try{let n=await Promise.resolve(i);e[t.key]={loading:!1,value:n,error:void 0}}catch(n){e[t.key]={loading:!1,value:void 0,error:n instanceof Error?n.message:String(n)}}}i._derived=e}r&&(i._skipOnMount=!0),m=` ${ae}='${y(JSON.stringify(i))}'`}return`<${s} data-ilha="${y(r)}" ${D}='${p}'${m}>${l}</${s}>`},z}};function we(e,t,n){let r=typeof e==`string`?document.querySelector(e):e;return r?t.mount(r,n):(console.warn(`[ilha] from(): element not found: ${e}`),null)}function Te(e,t={}){let n=t.root??document.body,r=t.lazy??!1,i=[];function a(t){let n=t.getAttribute(`data-ilha`);if(!n)return;let r=e[n];if(!r){o(`mount(): no island registered under the name "${n}". Available names: [${Object.keys(e).join(`, `)}]. Check the data-ilha attribute on the element.`);return}let a={},s=t.getAttribute(D);if(s)try{a=JSON.parse(s)}catch{o(`Failed to parse ${D} on [data-ilha="${n}"] — invalid JSON ignored.`)}i.push(r.mount(t,a))}let s=Array.from(n.querySelectorAll(`[data-ilha]`));if(r&&typeof IntersectionObserver<`u`){let e=!1,t=new IntersectionObserver(n=>{if(!e)for(let e of n)e.isIntersecting&&(a(e.target),t.unobserve(e.target))});s.forEach(e=>t.observe(e)),i.push(()=>{e=!0,t.disconnect()})}else s.forEach(a);return{unmount:()=>{let e=[];for(let t of i){let n=t();n instanceof Promise&&e.push(n)}if(e.length>0)return Promise.all(e).then(()=>{})}}}const Ee=new Ce({schema:null,states:[],deriveds:[],ons:[],effects:[],onMounts:[],onErrors:[],transition:null,css:null,as:null}),De=Object.assign(Ee,{html:J,raw:B,mount:Te,from:we,context:Z,signal:de,batch:pe,untrack:fe});function Oe(e,t,n){return B(P(e,t,n))}const ke=J,Ae=B,je=V,Me=Te,Ne=we,Pe=Z;export{ie as ISLAND_MOUNT_INTERNAL,Oe as __ilhaJsxSlot,pe as batch,Pe as context,je as css,De as default,Ne as from,ke as html,de as ilhaSignal,de as signal,Me as mount,Ae as raw,fe as untrack};
|
|
5
|
+
`)}const C=Symbol.for(`ilha.raw`),w=Symbol.for(`ilha.signalAccessor`),T=Symbol.for(`ilha.island`),E=Symbol.for(`ilha.islandCall`),D=Symbol.for(`ilha.islandMountInternal`),O=Symbol.for(`ilha.islandSlotTag`),k=`data-ilha-slot`,A=`data-ilha-props`,j=`data-ilha-state`;function M(e){return`<style data-ilha-css>@scope (:scope) to ([data-ilha]){${e.replace(/<\/style/gi,`<\\/style`)}}</style>`}const N=[];function P(e,t){let n={slots:new Map,positional:0,liveHost:e,pending:t?new Map:void 0,binds:[],slotTags:new Map};return N.push(n),n}function F(){N.pop()}function I(){return N[N.length-1]}function re(e){return typeof e==`function`?T in e?!0:Object.getOwnPropertySymbols(e).some(e=>e.description===`ilha.island`):!1}function L(e){if(e==null||typeof e!=`object`&&typeof e!=`function`)return!1;if(E in e||Object.getOwnPropertySymbols(e).some(e=>e.description===`ilha.islandCall`))return!0;if(typeof e==`object`&&`island`in e){let t=e.island;return typeof t==`function`&&(T in t||Object.getOwnPropertySymbols(t).some(e=>e.description===`ilha.island`))}return!1}function R(e,t,n){let r=I(),i;i=n===void 0?r?`p:${r.positional++}`:`p:0`:`k:${n}`,r&&r.slots.set(i,{island:e,props:t});let a=p(e);r&&r.slotTags.set(i,a);let o=t?` ${A}='${x(JSON.stringify(t))}'`:``;if(r?.liveHost)return m(a,i,o,``);if(r?.pending){F();try{let n=e(t);return n instanceof Promise?(r.pending.set(i,n.then(String)),m(a,i,o,``)):m(a,i,o,String(n))}finally{N.push(r)}}let s=e.toString(t);return m(a,i,o,s)}async function z(e,t){for(let[n,r]of t.pending){let i=await r,a=t.slotTags.get(n)??`div`,o=x(n);if(o.length>500)throw Error(`Slot id exceeds safe length for regex replacement (${o.length} > 500).`);let s=o.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`),c=a.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`),l=RegExp(`<${c}\\s[^>]*${k}="${s}"[^>]*></${c}>`,`g`);e=e.replace(l,e=>{let t=`></${a}>`;return e.slice(0,-t.length)+`>${i}</${a}>`})}return e}function B(e){e[w]=!0;let t=e;return t.select=e=>K(t,e),t}function V(e){return typeof e==`function`?w in e?!0:Object.getOwnPropertySymbols(e).some(e=>e.description===`ilha.signalAccessor`):!1}function H(e,t){let n=e;for(let e of t){if(n==null)return;n=n[e]}return n}function U(e,t,n){if(t.length===0)return n;let[r,...i]=t;if(Array.isArray(e)){let t=r;if(t<0||t>=e.length)return e;let a=e[t],o=i.length===0?n:U(a,i,n);if(Object.is(a,o))return e;let s=e.slice();return s[t]=o,s}if(typeof e==`object`&&e){let t=e,a=String(r),o=t[a],s=i.length===0?n:U(o,i,n);if(i.length===0){if(Object.is(o,n))return e}else if(Object.is(o,s))return e;return{...t,[a]:s}}return i.length===0?n:U(void 0,i,n)}function W(e){return typeof e==`symbol`||e===`length`?null:/^\d+$/.test(e)?Number(e):e}function G(e,t){let n=[],r=e=>e===null||typeof e!=`object`&&typeof e!=`function`?e:new Proxy(e,{get(e,t,i){let a=W(t);a!=null&&n.push(a);let o=Reflect.get(e,t,i);return a!=null&&typeof o==`object`&&o?r(o):o}});return t(r(e)),n}function K(e,t){let n=G(e(),t),r=t(e()),i=n.length===0?e():H(e(),n);if(!Object.is(r,i))throw Error(`select(): selector must only traverse nested properties or array indexes — derived or transformed values are not supported.`);return B((...r)=>{if(r.length===0)return n.length===0?t(e()):H(e(),n);let i=n.length===0?r[0]:U(e(),n,r[0]);Object.is(e(),i)||e(i)})}function q(e){return{[C]:!0,value:e}}function ie(e,...t){if(typeof e==`string`)return e;let n=``;for(let r=0;r<e.length;r++)n+=e[r],r<t.length&&(n+=String(t[r]));return n}function J(e){if(e==null||e===!0||e===!1)return``;if(Array.isArray(e))return e.map(J).join(``);if(ce(e))return e.value;if(L(e)){let t=typeof e==`function`?e():e;return R(t.island,t.props,t.key)}return re(e)?R(e,void 0,void 0):V(e)||typeof e==`function`?x(e()):x(e)}const ae=new Set([`value`,`checked`,`valueAsNumber`,`valueAsDate`,`files`,`open`,`group`,`this`]),Y=/\bbind:([a-zA-Z]+)\s*=\s*("|')?$/;function X(e){if(e instanceof Date){if(isNaN(e.getTime()))return``;let t=e=>String(e).padStart(2,`0`);return`${e.getFullYear()}-${t(e.getMonth()+1)}-${t(e.getDate())}`}return``}function oe(e){let t=e.lastIndexOf(`<`);if(t===-1)return null;let n=e.slice(t);if(n.includes(`>`))return null;let r=n.match(/\bvalue\s*=\s*("([^"]*)"|'([^']*)'|([^\s>]+))/);return r?r[2]??r[3]??r[4]??null:null}function se(e,t,n,r){let i=`${e}:${t}`,a;try{a=n()}catch{a=void 0}switch(e){case`value`:return[` value="${x(a??``)}"`,i];case`valueAsNumber`:return[` value="${x(a==null?``:String(a))}"`,i];case`valueAsDate`:return[` value="${x(X(a))}"`,i];case`checked`:return[a?` checked`:``,i];case`open`:return[a?` open`:``,i];case`files`:return[``,i];case`this`:return[``,i];case`group`:{let e=oe(r);return e==null?[``,i]:[(Array.isArray(a)?a.map(String).includes(e):a!=null&&String(a)===e)?` checked`:``,i]}}}function Z(e,...t){let n=``,r=null,i=``,a=I();for(let o=0;o<e.length;o++){let s=e[o];if(r!==null&&(s.startsWith(r)&&(s=s.slice(1)),r=null),i!==``){let e=s.indexOf(`>`);e!==-1&&(s=s.slice(0,e)+` data-ilha-bind="${i}">`+s.slice(e+1),i=``)}if(o>=t.length){n+=s;continue}let c=t[o],l=s.match(Y);if(l&&V(c)){let e=l[1],t=l[2]??null;if(!ae.has(e)){n+=s+J(c);continue}if(!a){let i=s.slice(0,s.length-l[0].length),a=t??`"`;n+=i+e+`=`+a+J(c)+a,t&&(r=t);continue}let o=s.length-l[0].length,u=s.slice(0,o).replace(/\s+$/,``),d=a.binds.length;a.binds.push({kind:e,accessor:c});let[f,p]=se(e,d,c,u);n+=u+f,i+=(i?`,`:``)+p,t&&(r=t);continue}n+=s+J(c)}return i!==``&&(n+=` data-ilha-bind="${i}"`),{[C]:!0,value:S(n)}}function ce(e){return typeof e!=`object`||!e||!(`value`in e)||typeof e.value!=`string`?!1:C in e?!0:Object.getOwnPropertySymbols(e).some(e=>e.description===`ilha.raw`)}function Q(e){return ce(e)?e.value:e}const le=new Map;function ue(e,t){if(le.has(e))return le.get(e);let n=r(t),i=(...e)=>{if(e.length===0)return n();n(e[0])};return le.set(e,i),i}function de(e){let t=r(e);return B((...e)=>{if(e.length===0)return t();t(e[0])})}function fe(e){let t=n(void 0);try{return e()}finally{n(t)}}function pe(e){i();try{return e()}finally{t()}}function me(e,t){let n=B((...n)=>{if(n.length>0){t&&t(n[0]);return}return e().value});return new Proxy(n,{get(t,n,r){return n===`loading`||n===`value`||n===`error`?e()[n]:Reflect.get(t,n,r)}})}function he(){return me(()=>({loading:!1,value:void 0,error:void 0}))}function ge(e){let t=new Map;for(let[n,r]of Object.entries(e))t.set(n,me(()=>r,e=>{r.loading=!1,r.value=e,r.error=void 0}));return new Proxy({},{get(e,n){return t.get(n)??he()}})}function _e(t,i,a,o){let s=new Map;for(let e of t){let t;if(o!=null&&e.key in o)t={...o[e.key]};else if(e.fn.constructor.name===`AsyncFunction`||e.fn.constructor.name===`AsyncGeneratorFunction`)t={loading:!0,value:void 0,error:void 0};else{let n=new AbortController;try{let r=e.fn({state:i,input:a,signal:n.signal});r instanceof Promise?(t={loading:!0,value:void 0,error:void 0},r.catch(()=>{})):t={loading:!1,value:r,error:void 0}}catch(e){t={loading:!1,value:void 0,error:e instanceof Error?e:Error(String(e))}}finally{n.abort()}}let n=r(t);s.set(e.key,n)}let c=new Map;for(let e of t){let t=s.get(e.key);c.set(e.key,me(()=>t(),e=>{let r=n(void 0);t({loading:!1,value:e,error:void 0}),n(r)}))}return{proxy:new Proxy({},{get(e,t){return c.get(t)??he()}}),setup:()=>{let r=[];for(let c of t){let t=s.get(c.key),l=new AbortController,u=o!=null&&c.key in o,d=e(()=>{l.abort(),l=new AbortController;let e=l,r;try{r=c.fn({state:i,input:a,signal:e.signal})}catch(e){if(u){u=!1;return}let r=n(void 0);t({loading:!1,value:void 0,error:e instanceof Error?e:Error(String(e))}),n(r);return}if(u){u=!1,r instanceof Promise&&r.catch(()=>{});return}if(!(r instanceof Promise)){let e=n(void 0);t({loading:!1,value:r,error:void 0}),n(e);return}let o=n(void 0);t({loading:!0,value:t().value,error:void 0}),n(o),r.then(n=>{e.signal.aborted||t({loading:!1,value:n,error:void 0})}).catch(n=>{e.signal.aborted||t({loading:!1,value:void 0,error:n instanceof Error?n:Error(String(n))})})});r.push(()=>{d(),l.abort()})}return()=>r.forEach(e=>e())}}}const ve=`data-ilha-bind`;function ye(e){let t=[];for(let n of e.split(`,`)){let[e,r]=n.split(`:`);if(!e||!r)continue;let i=Number(r);!Number.isInteger(i)||i<0||t.push({kind:e,index:i})}return t}function be(e,t){let n=e;switch(t){case`value`:return{event:e.tagName===`SELECT`?`change`:`input`,read:e=>e.value,write:(e,t)=>e.value=t==null?``:String(t)};case`valueAsNumber`:return{event:`input`,read:e=>{let t=e.valueAsNumber;return Number.isNaN(t)?null:t},write:(e,t)=>e.value=t==null||Number.isNaN(t)?``:String(t)};case`valueAsDate`:return{event:`input`,read:e=>e.valueAsDate,write:(e,t)=>{e.value=X(t)}};case`checked`:return{event:`change`,read:e=>e.checked,write:(e,t)=>e.checked=!!t};case`files`:return{event:`change`,read:e=>e.files,write:()=>{}};case`open`:return{event:`toggle`,read:e=>e.open,write:(e,t)=>e.open=!!t};case`this`:return{event:null,read:()=>void 0,write:()=>{}};case`group`:{let e=n.type===`checkbox`;return{event:`change`,read:t=>{let n=t;return e?{__ilhaGroup:!0,value:n.value,checked:n.checked}:n.checked?n.value:void 0},write:(t,n)=>{let r=t;e?r.checked=(Array.isArray(n)?n.map(String):[]).includes(r.value):r.checked=n!=null&&String(n)===r.value}}}}}function xe(e,t){if(t.length===0)return()=>{};let n=[],r=[];e.hasAttribute(ve)&&r.push(e);for(let t of e.querySelectorAll(`[${ve}]`))r.push(t);for(let e of r){let r=ye(e.getAttribute(ve));for(let i of r){let r=t[i.index];if(!r||r.kind!==i.kind)continue;let{event:a,read:o,write:s}=be(e,i.kind),c=r.accessor;if(i.kind===`this`){c(e),n.push(()=>c(null));continue}try{s(e,c())}catch{}if(a===null)continue;let l=()=>{let t=o(e);if(i.kind===`group`){let e=t;if(e===void 0)return;if(typeof e==`object`&&e.__ilhaGroup){let t=c(),n=Array.isArray(t)?[...t]:[],r=n.findIndex(t=>String(t)===e.value);if(e.checked&&r===-1){let r=e.value,i=Array.isArray(t)&&t.length>0?t[0]:void 0;if(i!==void 0)if(typeof i==`number`){let e=Number(r);r=Number.isNaN(e)?r:e}else typeof i==`boolean`&&(r=!!r);n.push(r)}else !e.checked&&r!==-1&&n.splice(r,1);c(n);return}let n=c(),r=e;if(typeof n==`number`&&typeof e==`string`){let t=Number(e);r=Number.isNaN(t)?0:t}else typeof n==`boolean`&&(r=!!e);c(r);return}let n=c(),r=t;if(typeof n==`number`&&typeof t==`string`){let e=Number(t);r=Number.isNaN(e)?0:e}else typeof n==`boolean`&&(r=!!t);c(r)};e.addEventListener(a,l),n.push(()=>e.removeEventListener(a,l))}}return()=>n.forEach(e=>e())}function Se(e){let t=e.lastIndexOf(`@`),n=t===-1?``:e.slice(0,t),r=(t===-1?e:e.slice(t+1)).split(`:`),i=r[0],a=new Set(r.slice(1));return{selector:n,eventType:i,options:{once:a.has(`once`),capture:a.has(`capture`),passive:a.has(`passive`)},abortable:a.has(`abortable`)}}function Ce(e){if(typeof AbortSignal.any==`function`)return AbortSignal.any(e);let t=new AbortController,n=[];for(let r of e){if(r.aborted)return t.abort(r.reason),n.forEach(e=>e()),t.signal;let e=()=>t.abort(r.reason);r.addEventListener(`abort`,e,{once:!0}),n.push(()=>r.removeEventListener(`abort`,e))}return t.signal.aborted||t.signal.addEventListener(`abort`,()=>{n.forEach(e=>e())}),t.signal}const $=new Set;function we(e,t){if($.size===0)return!1;for(let n of $)try{n(e,t)}catch(e){console.error(e)}return!0}function Te(e){return $.add(e),()=>{$.delete(e)}}var Ee=class a{_cfg;constructor(e){this._cfg=e}input(e){return new a({schema:e??null,states:[],deriveds:[],ons:[],effects:[],onMounts:[],onErrors:[],transition:null,css:null,as:null})}as(e){return new a({...this._cfg,as:f(e)})}state(e,t){let n=this._cfg;return new a({...n,states:[...n.states,{key:e,init:t}]})}derived(e,t){let n=this._cfg;return new a({...n,deriveds:[...n.deriveds,{key:e,fn:t}]})}on(e,t){let n=Se(e);return new a({...this._cfg,ons:[...this._cfg.ons,{selector:n.selector,event:n.eventType,options:n.options,abortable:n.abortable,handler:t}]})}effect(e){return new a({...this._cfg,effects:[...this._cfg.effects,{fn:e}]})}onMount(e){return new a({...this._cfg,onMounts:[...this._cfg.onMounts,{fn:e}]})}onError(e){return new a({...this._cfg,onErrors:[...this._cfg.onErrors,{fn:e}]})}transition(e){return new a({...this._cfg,transition:e})}css(e,...t){let n;if(typeof e==`string`)n=e;else{let r=``;for(let n=0;n<e.length;n++)r+=e[n],n<t.length&&(r+=String(t[n]));n=r}return new a({...this._cfg,css:n})}render(a){let{schema:o,states:l,deriveds:u,ons:d,effects:p,onMounts:m,onErrors:h,transition:g,css:_,as:v}=this._cfg,b=_==null?``:M(_),S=v??`div`;function C(e){let t=e??{};return o?y(o,t):t}function w(e,t,n){let r=P(t,n);try{let t=Q(e()),n=r.slots,i=r.binds;if(r.pending&&r.pending.size>0){let e=r.pending,a=r.slotTags;return(async()=>({html:await z(t,{pending:e,slotTags:a}),slots:n,binds:i}))()}return{html:t,slots:n,binds:i}}finally{F()}}function N(e){let t={};for(let n of l){let r=typeof n.init==`function`?n.init(e):n.init,i=B((...e)=>{if(e.length===0)return r});t[n.key]=i}return t}function re(e,t){let n={};for(let i of l){let a=r(t&&i.key in t?t[i.key]:typeof i.init==`function`?i.init(e):i.init),o=B((...e)=>{if(e.length===0)return a();a(e[0])});n[i.key]=o}return n}function L(e,t=!1){let r=C(e),i=N(r),o=u.map(e=>{let t=n(void 0);try{return{key:e.key,result:e.fn({state:i,input:r,signal:new AbortController().signal})}}catch(t){return{key:e.key,result:Promise.reject(t)}}finally{n(t)}});if(!o.some(e=>e.result instanceof Promise)||t){let e={};for(let t of o)t.result instanceof Promise?e[t.key]={loading:!0,value:void 0,error:void 0}:e[t.key]={loading:!1,value:t.result,error:void 0};let t=ge(e),s=n(void 0);try{let{html:e}=w(()=>a({state:i,derived:t,input:r}));return b+e}finally{n(s)}}return Promise.all(o.map(async e=>{try{return{key:e.key,envelope:{loading:!1,value:await Promise.resolve(e.result),error:void 0}}}catch(t){return{key:e.key,envelope:{loading:!1,value:void 0,error:t instanceof Error?t:Error(String(t))}}}})).then(async e=>{let t={};for(let n of e)t[n.key]=n.envelope;let o=ge(t),s=n(void 0);try{let{html:e}=await w(()=>a({state:i,derived:o,input:r}),void 0,!0);return b+e}finally{n(s)}})}function R(e,t){return V(e,t).unmount}function V(o,l){if(l===void 0){let e=o.getAttribute(A);if(e){let t=s(e,A);t!==void 0&&(l=t)}}let f=r(C(l)),_=new Proxy({},{get(e,t){return f()[t]},has(e,t){return t in f()},ownKeys(){let e=n(void 0);try{return Reflect.ownKeys(f())}finally{n(e)}},getOwnPropertyDescriptor(e,t){let r=n(void 0);try{return Reflect.getOwnPropertyDescriptor(f(),t)}finally{n(r)}}}),v,y=o.getAttribute(j);if(y){let e=s(y,j);e!==void 0&&(v=e)}let x=v?Object.fromEntries(Object.entries(v).filter(([e])=>e!==`_derived`&&e!==`_skipOnMount`)):void 0,S=v?._derived,T;if(S){T={};for(let[e,t]of Object.entries(S))t.error&&!(t.error instanceof Error)?T[e]={...t,error:Error(String(t.error))}:T[e]=t}let E=v!=null,O=E&&v?._skipOnMount===!0,M=re(_,x),N=[],P=new AbortController;N.push(()=>P.abort());let{proxy:F,setup:I}=_e(u,M,_,T),L=()=>{};function R(e,t){let n=e instanceof Error?e:Error(String(e));if(h.length===0){we(n,t)||console.error(n);return}for(let e of h)try{e.fn({error:n,source:t,state:M,derived:F,input:_,host:o})}catch(e){console.error(e)}}if(g?.enter)try{let e=g.enter(o);e instanceof Promise&&e.catch(e=>R(e,`transition`))}catch(e){R(e,`transition`)}let z=new Map,B=new Map;function V(e,t){z.delete(e);let n=Symbol(),r=t.unmount(),i=t=>{let r=B.get(e);!r||r.token!==n||(r.el.remove(),t?.remove(),B.delete(e))};if(r instanceof Promise)return B.set(e,{el:t.el,token:n}),r.finally(()=>i());t.el.remove()}function H(e){let t=e;for(;t&&t!==o;){if(t.hasAttribute(`data-ilha`))return!1;t=t.parentElement}return t===o}function U(){let e=new Set([...B.values()].map(e=>e.el)),t=new Map;for(let n of o.querySelectorAll(`[${k}]`)){if(e.has(n))continue;let r=n.getAttribute(k);r===null||t.has(r)||H(n)&&t.set(r,n)}return t}function W(e){for(let[t,n]of z)e.has(t)||V(t,n);let t=null;for(let[r,{island:i,props:a}]of e){let e=z.get(r);if(e){e.updateProps(a);continue}t===null&&(t=U());let o=t.get(r)??null;if(!o)continue;let c=a;if(c===void 0){let e=o.getAttribute(A)??o.getAttribute(`data-props`);if(e){let t=s(e,`props on [${k}="${r}"]`);t!==void 0&&(c=t)}}let l=n(void 0),u;try{let e=i[D];u=e?e(o,c):{unmount:i.mount(o,c),updateProps:()=>{}}}finally{n(l)}z.set(r,{el:o,...u})}}let G=[],K=new Set,q=new WeakMap;function ie(){for(let e of d)e.options.once&&K.has(e)||(e.selector===``?[o]:Array.from(o.querySelectorAll(e.selector))).forEach(n=>{let r=r=>{if(e.options.once){K.add(e);for(let t of G.filter(t=>t.entry===e))t.target.removeEventListener(t.type,t.fn,t.options);G.splice(0,G.length,...G.filter(t=>t.entry!==e))}let a=r.target instanceof Element?r.target:n,s=e.selector===``?a:n,c;if(e.abortable){let t=q.get(e);t||(t=new WeakMap,q.set(e,t));let r=t.get(n);r&&r.abort();let i=new AbortController;t.set(n,i),c=Ce([P.signal,i.signal])}else c=P.signal;let l;i();try{l=e.handler({state:M,derived:F,input:_,host:o,target:s,event:r,signal:c})}catch(e){R(e,`on`),t();return}t(),l instanceof Promise&&l.catch(e=>{e&&e.name===`AbortError`||R(e,`on`)})},a={...e.options,once:!1};n.addEventListener(e.event,r,a),G.push({target:n,type:e.event,fn:r,options:a,entry:e})})}function J(){for(let e of G)e.target.removeEventListener(e.type,e.fn,e.options);G.length=0}let ae=E&&o.childNodes.length>0,Y=w(()=>a({state:M,derived:F,input:_}),ae?o:void 0);ae||(o.innerHTML=b+Y.html);let X=xe(o,Y.binds);if(N.push(()=>X()),W(Y.slots),N.push(()=>z.forEach(e=>e.unmount())),ie(),!O)for(let e of m){let t=n(void 0),r;try{r=e.fn({state:M,derived:F,input:_,host:o,hydrated:E})}catch(e){R(e,`mount`)}finally{n(t)}if(r){let e=r;N.push(()=>{try{e()}catch(e){R(e,`mount`)}})}}for(let n of p){let r,a=null,s=e(()=>{if(r){try{r()}catch(e){R(e,`effect`)}r=void 0}a&&a.abort(),a=new AbortController;let e=Ce([P.signal,a.signal]);i();try{r=n.fn({state:M,derived:F,input:_,host:o,signal:e})}catch(e){R(e,`effect`)}finally{t()}});N.push(()=>{if(s(),r)try{r()}catch(e){R(e,`effect`)}a&&a.abort()})}L=I(),N.push(L);let oe=!1,se=Y.html,Z=0,ce=e(()=>{let e=++Z,{html:t,slots:n,binds:r}=w(()=>a({state:M,derived:F,input:_}),o),i=b+t;if(!oe&&(oe=!0,t===se||z.size>0&&z.size===n.size&&[...n.keys()].every(e=>z.has(e))&&ee(se,t,n.keys())))return;J(),X();let s=z.size,c=[];for(let[e,t]of z)if(!n.has(e)){let n=V(e,t);n instanceof Promise&&c.push(n)}let l=()=>{if(e!==Z)return;let t=new Map,a=n.size<s;for(let[e,r]of z){if(!n.has(e)||!r.el.isConnected)continue;if(a&&e.startsWith(`p:`)){V(e,r);continue}let i=r.el.tagName.toLowerCase(),o=document.createElement(i);o.setAttribute(k,e);let s=te(n.get(e)?.props);s!==``&&o.setAttribute(A,s),r.el.replaceWith(o),t.set(e,r.el)}let c=document.createElement(`template`),l=o.tagName.toLowerCase();if(c.innerHTML=`<${l}>${i}</${l}>`,ne(o,c.content.firstElementChild),t.size>0){let e=U();for(let[n,r]of t){let t=e.get(n);t&&t.replaceWith(r)}}ie(),X=xe(o,r),W(n)};c.length>0?Promise.allSettled(c).then(e=>{for(let t of e)t.status===`rejected`&&console.error(t.reason);l()}):l()}),Q=!1;return{unmount:()=>{if(Q)return;Q=!0,ce(),J();let e=[];for(let[,t]of z){let n=t.unmount();n instanceof Promise&&e.push(n)}if(g?.leave)try{let t=g.leave(o);t instanceof Promise&&e.push(t)}catch(e){R(e,`transition`)}let t=()=>{for(let e of N)e()};if(e.length>0)return Promise.all(e).then(t).catch(e=>{R(e,`transition`),t()});t()},updateProps:e=>{if(Q)return;let t=C(e);c(f(),t)||f(t)}}}let H=function(e){return I()?{[E]:!0,island:H,props:e,key:void 0}:L(e)};return H.toString=e=>L(e,!0),H.mount=(e,t)=>R(e,t),H[D]=(e,t)=>V(e,t),H[O]=S,H.key=e=>{if(typeof e!=`string`||e.trim().length===0)throw Error(`island.key() requires a non-empty string.`);if(e.includes(`:`))throw Error(`island.key() key cannot contain the slot separator ":" (got "${e}").`);let t=(t=>({[E]:!0,island:H,props:t,key:e}));return t[E]=!0,t},H[T]=!0,H.hydratable=async(e,t)=>{let{name:r,as:i=`div`,snapshot:a=!1,skipOnMount:o}=t,s=f(i),c=e??{},d=await L(c),p=x(JSON.stringify(c)),m=``;if(a!==!1){let e=a===!0||a.state!==!1,t=a===!0||a.derived!==!1,r=o??(e||t),i={},s=C(c),d=N(s);if(e)for(let e of l)i[e.key]=d[e.key]();if(t){let e={};for(let t of u){let r=n(void 0),i,a,o=!1;try{i=t.fn({state:d,input:s,signal:new AbortController().signal})}catch(e){o=!0,a=e}finally{n(r)}if(o){e[t.key]={loading:!1,value:void 0,error:a instanceof Error?a.message:String(a)};continue}try{let n=await Promise.resolve(i);e[t.key]={loading:!1,value:n,error:void 0}}catch(n){e[t.key]={loading:!1,value:void 0,error:n instanceof Error?n.message:String(n)}}}i._derived=e}r&&(i._skipOnMount=!0),m=` ${j}='${x(JSON.stringify(i))}'`}return`<${s} data-ilha="${x(r)}" ${A}='${p}'${m}>${d}</${s}>`},H}};function De(e,t,n){let r=typeof e==`string`?document.querySelector(e):e;return r?t.mount(r,n):(console.warn(`[ilha] from(): element not found: ${e}`),null)}function Oe(e,t={}){let n=t.root??document.body,r=t.lazy??!1,i=[];function a(t){let n=t.getAttribute(`data-ilha`);if(!n)return;let r=e[n];if(!r){`${n}${Object.keys(e).join(`, `)}`;return}let a={},o=t.getAttribute(A);if(o){let e=s(o,`${A} on [data-ilha="${n}"]`);e!==void 0&&(a=e)}i.push(r.mount(t,a))}let o=Array.from(n.querySelectorAll(`[data-ilha]`));if(r&&typeof IntersectionObserver<`u`){let e=!1,t=new IntersectionObserver(n=>{if(!e)for(let e of n)e.isIntersecting&&(a(e.target),t.unobserve(e.target))});o.forEach(e=>t.observe(e)),i.push(()=>{e=!0,t.disconnect()})}else o.forEach(a);return{unmount:()=>{let e=[];for(let t of i){let n=t();n instanceof Promise&&e.push(n)}if(e.length>0)return Promise.all(e).then(()=>{})}}}const ke=new Ee({schema:null,states:[],deriveds:[],ons:[],effects:[],onMounts:[],onErrors:[],transition:null,css:null,as:null}),Ae=Object.assign(ke,{html:Z,raw:q,mount:Oe,from:De,context:ue,signal:de,batch:pe,untrack:fe,onUncaughtError:Te});function je(e,t,n){return q(R(e,t,n))}const Me=Z,Ne=q,Pe=ie,Fe=Oe,Ie=De,Le=ue;export{D as ISLAND_MOUNT_INTERNAL,je as __ilhaJsxSlot,pe as batch,Le as context,Pe as css,Ae as default,Ie as from,Me as html,de as ilhaSignal,de as signal,Fe as mount,Te as onUncaughtError,Ne as raw,fe as untrack};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as JSX, r as jsxDEV, t as Fragment } from "./jsx-runtime-
|
|
1
|
+
import { a as JSX, r as jsxDEV, t as Fragment } from "./jsx-runtime-eKC9uK0J.js";
|
|
2
2
|
export { Fragment, type JSX, jsxDEV };
|
package/dist/jsx-runtime.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as JSX, i as jsxs, n as jsx, r as jsxDEV, t as Fragment } from "./jsx-runtime-
|
|
1
|
+
import { a as JSX, i as jsxs, n as jsx, r as jsxDEV, t as Fragment } from "./jsx-runtime-eKC9uK0J.js";
|
|
2
2
|
export { Fragment, JSX, jsx, jsxDEV, jsxs };
|