@vielzeug/craftit 2.0.0 → 2.0.1

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/dist/craftit.cjs CHANGED
@@ -1,2 +1,2 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});let e=require(`@vielzeug/stateit`);var t=0,n=e=>{for(let t of e)t()},r=(e,t,n)=>{n==null||!1===n?e.removeAttribute(t):!0===n?e.setAttribute(t,``):e.setAttribute(t,String(n))},i=(e,t,n,r)=>{let i=n;return e.addEventListener(t,i,r),()=>e.removeEventListener(t,i,r)},a=e=>`${e?`${e}-`:`cft-`}${++t}`,o=e=>e.replace(/[A-Z]/g,e=>`-${e.toLowerCase()}`),s={"'":`&#39;`,'"':`&quot;`,"&":`&amp;`,"<":`&lt;`,">":`&gt;`},c=e=>String(e).replace(/[&<>"']/g,e=>s[e]),l=function(){return this.content},u=new Map,d=e=>{if(e instanceof CSSStyleSheet)return e;let t=typeof e==`string`?e:e.content,n=u.get(t);if(n)return n;let r=new CSSStyleSheet;try{r.replaceSync(t),u.set(t,r)}catch(e){console.error(`[craftit:E2] style replace failed`,e)}return r},f=[],p=()=>{let e=f[f.length-1];if(!e)throw Error(`[craftit:E1] lifecycle outside setup`);return e},m=e=>{p().onMount.push(e)},h=t=>{f.length>0?p().cleanups.push(t):(0,e.onCleanup)(t)},g=e=>{f.length>0&&h(e)},_=(t,n)=>{let r=(0,e.effect)(t,n);return g(r),r};function v(e,t,n,r){e&&(e.addEventListener(t,n,r),h(()=>e.removeEventListener(t,n,r)))}var y={bubbles:!0,cancelable:!0,composed:!0},b={basic:(e,t,n={})=>e.dispatchEvent(new Event(t,{...y,...n})),custom:(e,t,n={})=>e.dispatchEvent(new CustomEvent(t,{...y,...n})),event:(e,t)=>e.dispatchEvent(t),focus:(e,t,n={})=>e.dispatchEvent(new FocusEvent(t,{...y,...n})),keyboard:(e,t,n={})=>e.dispatchEvent(new KeyboardEvent(t,{...y,...n})),mouse:(e,t,n={})=>e.dispatchEvent(new MouseEvent(t,{...y,...n})),touch:(e,t,n={})=>typeof TouchEvent<`u`?e.dispatchEvent(new TouchEvent(t,{...y,...n})):e.dispatchEvent(new CustomEvent(t,{...y,...n}))},x=new WeakMap,S=new Set,C=(e,t,n)=>{let r=`${n}:${e.localName}:${t||`default`}`;S.has(r)||(S.add(r),console.warn(`[craftit:E10] ${n} could not find a matching <slot${t?` name="${t}"`:``}> in <${e.localName}>. Render the slot before using ${n}.`))};function w(e,t){for(let[n,r]of Object.entries(t))if(n===`classMap`)T(e,r);else if(n.startsWith(`on`)&&n.length>2&&typeof r==`function`){let t=n.slice(2);v(e,t[0].toLowerCase()+t.slice(1),r)}else ee(e,n,r)}function ee(e,t,n){typeof n==`function`?_(()=>r(e,t,n())):r(e,t,n)}function T(e,t){let n=new Set;_(()=>{let r=new Set(Object.entries(t()).filter(([,e])=>e).map(([e])=>e));for(let t of n)r.has(t)||e.classList.remove(t);for(let t of r)n.has(t)||e.classList.add(t);n=r})}function E(e,t=[]){return{__bindings:t,__html:e,toString:()=>e}}var D=Symbol(`craftit.eachSignal`),O=t=>(0,e.isSignal)(t)?t:typeof t==`function`?(0,e.computed)(t):void 0,te=t=>{if(!(0,e.isSignal)(t))return!1;let n=Object.getPrototypeOf(t);for(;n;){let e=Object.getOwnPropertyDescriptor(n,`value`);if(e)return typeof e.set==`function`;n=Object.getPrototypeOf(n)}return!1},k=(e,t)=>{if(!Object.is(e.value,t))try{e.value=t}catch{}},A=new Map,j=e=>(e=>{let t=A.get(e);if(!t){if(t=document.createElement(`template`),t.innerHTML=e,A.size>=1e3){let e=A.keys().next().value;e!==void 0&&A.delete(e)}A.set(e,t)}return t})(e).content.cloneNode(!0),M=(e,t)=>{if(e.nodeType===Node.COMMENT_NODE){let n=e.nodeValue;n&&t.comments.set(n,e);return}if(e.nodeType!==Node.ELEMENT_NODE)return;let n=e.getAttribute(`u`);n&&t.elements.set(n,e)},N=e=>{let t={comments:new Map,elements:new Map};for(let n of e){let e=document.createTreeWalker(n,NodeFilter.SHOW_COMMENT|NodeFilter.SHOW_ELEMENT);for(M(n,t);e.nextNode();)M(e.currentNode,t)}return t},P=e=>Array.from(j(e).childNodes),F=(e,t,n)=>{if(e.parentNode)for(let r of t)e.parentNode.insertBefore(r,n)},I=e=>Array.isArray(e)||typeof e==`object`&&!!e,L=(e,t,n)=>{n(_(()=>t(e.value)))},ne=(e,t,n)=>{let i=n=>{let i=Q.get(e)?.get(t.name);if(!i&&I(n))return void(e[t.name]=n);if(i&&!i.reflect||(t.mode===`bool`?e.toggleAttribute(t.name,!!n):r(e,t.name,n)),!i)return;let a=I(n)?n:i.parse(t.mode===`bool`?n?``:null:n==null||!1===n?null:String(n));Object.is(i.signal.peek(),a)||(i.signal.value=a)};t.signal?L(t.signal,i,n):i(t.value)},re=(e,t,n)=>{let r=n=>{e[t.name]=n};t.signal?L(t.signal,r,n):r(t.value),((e,t,n,r)=>{n&&(t===`value`?(e instanceof HTMLInputElement||e instanceof HTMLTextAreaElement||e instanceof HTMLSelectElement)&&r(i(e,e instanceof HTMLSelectElement?`change`:`input`,()=>{k(n,e.value)})):t===`checked`&&e instanceof HTMLInputElement&&r(i(e,`change`,()=>{k(n,e.checked)})))})(e,t.name,t.model,n)},ie=(e,t,n)=>{let{modifiers:r}=t,a=r?{capture:!!r.capture,once:!!r.once,passive:!!r.passive}:void 0;n(i(e,t.name,e=>{r?.self&&e.target!==e.currentTarget||(r?.stop&&e.stopPropagation(),r?.prevent&&!r?.passive&&e.preventDefault(),t.handler(e))},a))},ae=(e,t,n)=>{let{ref:r}=t;typeof r==`function`?(r(e),n(()=>r(null))):Array.isArray(r)?(r.push(e),n(()=>{let t=r.indexOf(e);t!==-1&&r.splice(t,1)})):(r.value=e,n(()=>{r.value=null}))},R=(e,t,n,r)=>{let i=new Map;for(let a of e){let e=a.uid;if(a.type===`text`){let r=n.comments.get(e);if(r){let i=document.createTextNode(``);r.replaceWith(i),n.comments.delete(e),L(a.signal,e=>{i.textContent=String(e)},t)}}else a.type===`html`?r?.onHtml?.(a):(i.has(e)||i.set(e,[]),i.get(e).push(a))}for(let[e,r]of i){let i=n.elements.get(e);if(i){i.removeAttribute(`u`),n.elements.delete(e);for(let e of r)switch(e.type){case`attr`:ne(i,e,t);break;case`callback`:e.apply(i,t);break;case`event`:ie(i,e,t);break;case`prop`:re(i,e,t);break;case`ref`:ae(i,e,t)}}}},z=(e,t,n,r)=>{let i=O(r);return i?{mode:e,name:t,signal:i,type:`attr`,uid:n}:{mode:e,name:t,type:`attr`,uid:n,value:r}},B=(e,t,n)=>{let r=O(n);return r?{model:te(n)?n:void 0,name:e,signal:r,type:`prop`,uid:t}:{name:e,type:`prop`,uid:t,value:n}},oe=RegExp(`u="([^"]+)"`,`g`),V=e=>typeof e==`object`&&!!e&&`__html`in e,se=[{kind:`event`,regex:/\s+@([a-zA-Z_][-a-zA-Z0-9_.]*)\s*=\s*["']?$/},{kind:`ref`,regex:/\s+ref\s*=\s*["']?$/},{kind:`specialAttr`,regex:/\s+([:?])([a-zA-Z_][-a-zA-Z0-9_]*)\s*=\s*["']?$/},{kind:`prop`,regex:/\.([a-zA-Z_][-a-zA-Z0-9_]*)\s*=\s*["']?$/},{kind:`plainAttr`,regex:/\s+([a-zA-Z_][-a-zA-Z0-9_]*)\s*=\s*["']?$/}],H=new WeakMap,ce=e=>{let[t,...n]=e.split(`.`),r={};for(let e of n)e===`capture`?r.capture=!0:e===`once`?r.once=!0:e===`passive`?r.passive=!0:e===`prevent`?r.prevent=!0:e===`self`?r.self=!0:e===`stop`&&(r.stop=!0);return{modifiers:Object.keys(r).length?r:void 0,name:t}},U=()=>{let e=0;return()=>String(e++)},W=(e,t)=>{let n=new Map,r=e=>{let r=n.get(e);if(r)return r;let i=t();return n.set(e,i),i};return{bindings:e.__bindings.map(e=>({...e,uid:r(e.uid)})),html:e.__html.replace(oe,(e,t)=>`u="${r(t)}"`).replace(/<!--(\d+)-->/g,(e,t)=>`\x3c!--${r(t)}--\x3e`)}},G=e=>typeof e==`string`?c(e):e==null?``:V(e)?e.__html:c(String(e)),le=(t,n)=>{let r=(e=>typeof e==`object`&&e&&D in e?e[D]:null)(t);if(r)return{keyed:!0,signal:r};if(typeof t==`function`&&!(0,e.isSignal)(t)){let{signal:r}=((t,n)=>{let r={bindings:[],html:``},i=(0,e.signal)(r);return n(()=>{let e=t(),n=Array.isArray(e)?e:[e],a=U(),o=``,s=[];for(let e of n)if(V(e)){let t=W(e,a);o+=t.html,s.push(...t.bindings)}else o+=G(e);let c=s.length!==r.bindings.length||s.some((e,t)=>e!==r.bindings[t]);(o!==r.html||c)&&(r={bindings:s,html:o},i.value=r)}),{bindings:[],signal:i}})(t,n);return{keyed:!1,signal:r}}return(0,e.isSignal)(t)&&V(t.value)?{keyed:!1,signal:(0,e.computed)(()=>{let e=t.value;if(!V(e))return{bindings:[],html:String(e)};let n=W(e,U());return{bindings:n.bindings,html:n.html}})}:null},K=e=>{n(e.cleanups);for(let t of e.nodes)t.remove()},q=(e,t,n=N(e))=>{let r=[];return R(t,e=>r.push(e),n),r},J=(t,r,i,a,o)=>{let s=((e,t)=>{let n=document.createTreeWalker(e,NodeFilter.SHOW_COMMENT);for(;n.nextNode();){let e=n.currentNode;if(e.nodeValue===t)return e}return null})(t,r.uid);if(!s)return;let c=document.createComment(`html-binding`);s.replaceWith(c);let l=[],u=e=>l.push(e),d=()=>{n(l),l=[]},f=null,p=[];i((0,e.effect)(()=>{(0,e.batch)(()=>{let i=r.signal.value;if(!r.keyed&&i.html===f)return;f=i.html,d();let{bindings:s,html:l,keys:m}=i;r.keyed&&!a.has(r.uid)&&a.set(r.uid,new Map);let h=r.keyed?a.get(r.uid):null,g=c.parentElement||t,_=!1;(0,e.untrack)(()=>{(0,e.batch)(()=>{if(h&&m?.length&&i.items?.length===m.length){if(_=!0,h.size===0&&p.length>0){for(let e of p)e.remove();p=[]}let e=new Map;for(let t=0;t<m.length;t++){let r=m[t],a=i.items[t],o=h.get(r),s=t>0?e.get(m[t-1])?.nodes:null,l=s?.length?s[s.length-1].nextSibling:c.nextSibling;if(o?.html===a.html){o.nodes[0]&&F(c,o.nodes,l),n(o.cleanups);let t=N(o.nodes),i=q(o.nodes,a.bindings,t);e.set(r,{...o,bindings:a.bindings,cleanups:i,targets:t})}else if(o){n(o.cleanups);let t=P(a.html),i=N(t);F(c,t,l);let s=q(t,a.bindings,i);e.set(r,{bindings:a.bindings,cleanups:s,html:a.html,nodes:t,targets:i});for(let e of o.nodes)e.remove()}else{let t=P(a.html),n=N(t);F(c,t,l);let i=q(t,a.bindings,n);e.set(r,{bindings:a.bindings,cleanups:i,html:a.html,nodes:t,targets:n})}}for(let[t,n]of h)e.has(t)||K(n);a.set(r.uid,e)}else{if(r.keyed&&h&&h.size>0)for(let[,e]of h)K(e);else for(let e of p)e.remove();let e=j(l);p=Array.from(e.childNodes),c.after(e),r.keyed&&a.set(r.uid,new Map)}}),_||o(g,s,u,{onHtml:e=>J(g,e,u,a,o)})})})})),i(d),r.keyed&&i(()=>a.delete(r.uid))},Y=(e,t,n,r)=>{R(t,n,(e=>{let t={comments:new Map,elements:new Map},n=document.createTreeWalker(e,NodeFilter.SHOW_COMMENT|NodeFilter.SHOW_ELEMENT);for(M(e,t);n.nextNode();)M(n.currentNode,t);return t})(e),r)},X=new WeakMap,Z=new WeakMap,ue=new Set([`default`,`omit`,`parse`,`reflect`,`type`]),de=e=>typeof e==`object`&&!!e&&`default`in e&&Object.keys(e).every(e=>ue.has(e)),Q=new WeakMap,$=(t,n,i)=>{let a=p(),o=a.el;Q.has(o)||Q.set(o,new Map);let s=i?.parse??(e=>i?.type===Boolean?e===``||e===`true`:typeof n==`boolean`?e!==null&&e!==`false`:e==null?n:i?.type===Number||typeof n==`number`?Number(e):e),c=(0,e.signal)(n),l=Object.prototype.hasOwnProperty.call(o,t),u=l?o[t]:void 0,d={parse:s,reflect:i?.reflect??!0,signal:c};if(l?(delete o[t],c.value=u):o.hasAttribute(t)&&(c.value=s(o.getAttribute(t))),Q.get(o).set(t,d),Object.defineProperty(o,t,{configurable:!0,enumerable:!0,get:()=>c.value,set:e=>{c.value=e}}),i?.reflect??1){let n=i?.omit??!1;a.onMount.push(()=>{a.cleanups.push((0,e.effect)(()=>{let e=c.value;e==null||!1===e||n&&e===``?o.removeAttribute(t):r(o,t,e)}))})}return c},fe=class extends HTMLElement{static _setup;static _options;static formAssociated=!1;static observedAttributes=[];shadow;_keyedStates=new Map;_mountFns=[];_template=null;_appliedHtmlBindings=new Set;_setupDone=!1;_runtime;constructor(){super();let e=this.constructor._options;this.shadow=this.attachShadow({mode:`open`,...e?.shadow}),this._runtime={cleanups:[],el:this,errorHandlers:[],onMount:[],styles:e?.styles}}connectedCallback(){this._setupDone||this._runSetup(),this._init()}attributeChangedCallback(e,t,n){if(t===n)return;let r=Q.get(this)?.get(e);if(!r)return;let i=r.parse(n);Object.is(r.signal.peek(),i)||(r.signal.value=i)}disconnectedCallback(){n(this._runtime.cleanups),this._runtime.cleanups=[],this._runtime.onMount=this._mountFns.slice(),this._appliedHtmlBindings.clear(),this._keyedStates.clear()}formAssociatedCallback(e){X.get(this)?.onAssociated?.(e)}formDisabledCallback(e){X.get(this)?.onDisabled?.(e)}formResetCallback(){X.get(this)?.onReset?.()}formStateRestoreCallback(e,t){X.get(this)?.onStateRestore?.(e,t)}_handleError(e){if(this._runtime.errorHandlers.length>0)for(let t of this._runtime.errorHandlers)t(e);else console.error(`[craftit:E3] <${this.localName}>`,e)}_runSetup(){this._setupDone=!0,f.push(this._runtime);try{let{host:e}=this.constructor._options??{};if(e)for(let[t,n]of Object.entries(e))typeof n==`boolean`?n?this.setAttribute(t,``):this.removeAttribute(t):this.setAttribute(t,String(n));let t=this.constructor._setup({host:this,shadow:this.shadow});(typeof t==`string`||typeof t==`object`&&t&&`__html`in t)&&(this._template=t)}catch(e){this._handleError(e)}finally{f.pop()}}_init(){let{styles:e}=this._runtime;if(e?.length&&(this.shadow.adoptedStyleSheets=e.map(d)),this._template){let e=typeof this._template==`string`?E(this._template):this._template;if(this.shadow.replaceChildren(j(e.__html)),e.__bindings.length){let t=e=>this._runtime.cleanups.push(e);Y(this.shadow,e.__bindings,t,{onHtml:e=>{this._appliedHtmlBindings.has(e.uid)||(this._appliedHtmlBindings.add(e.uid),((e,t,n,r)=>{J(e,t,n,r,Y)})(this.shadow,e,t,this._keyedStates))}})}}queueMicrotask(()=>{f.push(this._runtime);try{let e=this._runtime.onMount;this._mountFns=e.slice();for(let t of e){let e=t();typeof e==`function`&&this._runtime.cleanups.push(e)}}catch(e){this._handleError(e)}finally{f.pop(),this._runtime.onMount=[]}})}};exports.aria=function(e,t){let n=t===void 0?p().el:e,r=Object.entries(t===void 0?e:t).map(([e,t])=>_(()=>((e,t)=>{let r=`aria-${e}`,i=typeof t==`function`?t():t;i==null||!1===i?n.removeAttribute(r):n.setAttribute(r,String(i))})(e,t)));if(t!==void 0)return()=>{for(let e of r)e()}},exports.createContext=function(e){return Symbol(e)},exports.createFormIds=(e,t)=>{let n=`${e}-${t&&t.trim()?t:a(e)}`;return{errorId:`error-${n}`,fieldId:n,helperId:`helper-${n}`,labelId:`label-${n}`}},exports.createId=a,exports.css=(e,...t)=>{let n=``;for(let r=0;r<e.length;r++)if(n+=e[r],r<t.length){let e=t[r];n+=e&&typeof e==`object`&&`content`in e?e.content:e??``}return{content:n.trim(),toString:l}},exports.defineComponent=function(t){let{formAssociated:n,host:r,props:i,setup:a,shadow:s,styles:c,tag:l}=t;return function(e,t,n={}){if(!e)throw Error(`[craftit:E4] registerComponent(tag, ...) requires a tag name`);if(customElements.get(e))throw Error(`[craftit:E9] custom element already defined: ${e}`);class r extends fe{static _setup=t;static _options=n;static formAssociated=n.formAssociated??!1;static observedAttributes=n.observedAttrs??[]}return customElements.define(e,r),e}(l,t=>{let n=i?function(e){let t={};for(let[n,r]of Object.entries(e)){let e=de(r)?r:{default:r},i={reflect:!(typeof e.default==`object`&&e.default!==null||Array.isArray(e.default)),...e};t[n]=$(o(n),e.default,i)}return t}(i):{},r=(()=>{let e=p().el;return(t,...n)=>{b.custom(e,String(t),n.length>0?{detail:n[0]}:void 0)}})(),s=(()=>{let t=p().el,n=new Map;return{has:r=>(r=>{if(n.has(r))return n.get(r);let i=(0,e.signal)(!1);return n.set(r,i),m(()=>{let e=r?`slot[name="${r}"]`:`slot:not([name])`,n=t.shadowRoot?.querySelector(e);if(!n)return void C(t,r,`slots.has()`);let a=()=>{i.value=n.assignedNodes().length>0};return a(),n.addEventListener(`slotchange`,a),()=>n.removeEventListener(`slotchange`,a)}),i})(r===`default`?``:String(r))}})();return a({emit:r,host:t.host,props:n,reflect:e=>w(t.host,e),shadow:t.shadow,slots:s})},{formAssociated:n,host:r,observedAttrs:i?Object.keys(i).map(o):[],shadow:s,styles:c})},exports.defineField=(t,n)=>{let r=p().el;if(!r.constructor.formAssociated)throw Error(`[craftit:E8] defineField() requires defineComponent({ formAssociated: true })`);let i=Z.get(r)??r.attachInternals();Z.set(r,i);let a=t.toFormValue??(e=>e==null?``:String(e));return(0,e.effect)(()=>{i.setFormValue(a(t.value.value))}),t.disabled&&(0,e.effect)(()=>{t.disabled.value?i.states.add(`disabled`):i.states.delete(`disabled`)}),n&&X.set(r,{...X.get(r),...n}),{checkValidity:()=>i.checkValidity(),internals:i,reportValidity:()=>i.reportValidity(),setCustomValidity:e=>e?i.setValidity({customError:!0},e):i.setValidity({}),setValidity:i.setValidity.bind(i)}},exports.effect=_,exports.escapeHtml=c,exports.fire=b,exports.guard=(e,t)=>n=>{e()&&t(n)},exports.handle=v,exports.html=(t,...n)=>((t,n,r)=>{let i=(e=>{let t=H.get(e);return t||(t=(e=>{let t=[];for(let n=0;n<e.length-1;n++){let r=e[n],i=!1;for(let e of se){let n=e.regex.exec(r);if(!n)continue;let a=r.slice(0,-n[0].length);if(i=!0,e.kind===`event`){let e=ce(n[1]);t.push({kind:`event`,modifiers:e.modifiers,name:e.name,prefix:a,raw:r})}else e.kind===`ref`?t.push({kind:`ref`,prefix:a,raw:r}):e.kind===`specialAttr`?t.push({kind:`specialAttr`,mode:n[1]===`?`?`bool`:`attr`,name:n[2],prefix:a,raw:r}):e.kind===`prop`?t.push({kind:`prop`,name:n[1],prefix:a,raw:r}):e.kind===`plainAttr`&&t.push({kind:`plainAttr`,name:n[1],prefix:a,raw:r});break}i||t.push({kind:`node`,prefix:r,raw:r})}return{slots:t,tail:e[e.length-1]??``}})(e),H.set(e,t)),t})(t),a=``,o=[],s=null,c=U(),l=e=>(s&&!(e=>e.lastIndexOf(`<`)>e.lastIndexOf(`>`))(e)||(s=c()),s),u=()=>{s=null};for(let t=0;t<i.slots.length;t++){let s=i.slots[t],d=n[t];if(s.kind===`event`){if(typeof d==`function`){let e=l(s.prefix);a+=`${s.prefix} u="${e}"`,o.push({handler:d,modifiers:s.modifiers,name:s.name,type:`event`,uid:e})}else a+=s.raw;continue}if(s.kind===`ref`){if(d){let e=l(s.prefix);a+=`${s.prefix} u="${e}"`,o.push({ref:d,type:`ref`,uid:e})}else a+=s.raw;continue}if(s.kind===`specialAttr`){let e=l(s.prefix);a+=`${s.prefix} u="${e}"`,o.push(z(s.mode,s.name,e,d));continue}if(s.kind===`prop`){let e=l(s.prefix);a+=`${s.prefix} u="${e}"`,o.push(B(s.name,e,d));continue}if(s.kind===`plainAttr`){let e=l(s.prefix);a+=`${s.prefix} u="${e}"`,o.push(z(`attr`,s.name,e,d));continue}if(typeof d==`object`&&d&&(`mount`in d||`render`in d)){let t=`render`in d,n=t?c():l(s.raw);a+=t?`${s.raw}\x3c!--${n}--\x3e`:`${s.raw} u="${n}"`;let i=d.mount?.bind(d);if(i&&o.push({apply:(e,t)=>{i(e,{registerCleanup:t})},type:`callback`,uid:n}),t){let t=d.render.bind(d),i={bindings:[],html:``},a=(0,e.signal)(i);r(()=>{let e=t(),n=Array.isArray(e)?e:[e],r=U(),o=``,s=[];for(let e of n)if(V(e)){let t=W(e,r);o+=t.html,s.push(...t.bindings)}else o+=G(e);let c=s.length!==i.bindings.length||s.some((e,t)=>e!==i.bindings[t]);(o!==i.html||c)&&(i={bindings:s,html:o},a.value=i)}),o.push({keyed:!1,signal:a,type:`html`,uid:n})}continue}u();let f=le(d,r);if(f){let e=c();a+=`${s.raw}\x3c!--${e}--\x3e`,o.push({keyed:f.keyed,signal:f.signal,type:`html`,uid:e});continue}if(Array.isArray(d)){let e=``;for(let t of d)if(V(t)){let n=W(t,c);e+=n.html,o.push(...n.bindings)}else e+=G(t);a+=s.raw+e;continue}if((0,e.isSignal)(d)){let e=c();a+=`${s.raw}\x3c!--${e}--\x3e`,o.push({signal:d,type:`text`,uid:e})}else if(V(d)){let e=W(d,c);a+=s.raw+e.html,o.push(...e.bindings)}else a+=s.raw+G(d)}return a+=i.tail,E(a.replace(/>\s+</g,`><`).trim(),o)})(t,n,_),exports.inject=function(e,...t){let n=p().el;for(;n;){if(n instanceof HTMLElement){let t=x.get(n)?.get(e);if(t!==void 0)return t}let t=n.getRootNode();n=n.parentElement??(t instanceof ShadowRoot?t.host:null)}return t.length>0?t[0]:void 0},exports.observeResize=t=>{let n=(0,e.signal)({height:0,width:0}),r=new ResizeObserver(([e])=>{if(!e)return;let t=e.contentBoxSize[0];t&&(n.value={height:t.blockSize,width:t.inlineSize})});return r.observe(t),h(()=>r.disconnect()),n},exports.onCleanup=h,exports.onError=e=>{p().errorHandlers.push(e)},exports.onMount=m,exports.onSlotChange=(e,t)=>{let n=p().el,r=e===`default`?``:e,i=r?`slot[name="${r}"]`:`slot:not([name])`,a=n.shadowRoot?.querySelector(i);if(!a)return void C(n,r,`onSlotChange()`);let o=()=>t(a.assignedElements({flatten:!0}));o(),a.addEventListener(`slotchange`,o),h(()=>a.removeEventListener(`slotchange`,o))},exports.prop=$,exports.provide=(e,t)=>{let n=p().el;x.has(n)||x.set(n,new Map),x.get(n).set(e,t)},exports.ref=function(){return{value:null}},exports.reflect=w,exports.refs=function(){return[]},exports.syncContextProps=(e,t,n)=>{e&&m(()=>{_(()=>{for(let r of n){let n=e[r]?.value;n!==void 0&&(t[r].value=n)}})})},exports.toKebab=o,exports.typed=(e,t)=>({...t,default:e}),exports.watch=function(t,n,r){if(Array.isArray(t)){let i=r,a=!1,o=!1,s=(0,e.effect)(()=>{for(let e of t)e.value;if(a)(0,e.untrack)(n),i?.once&&s();else if(a=!0,i?.immediate&&((0,e.untrack)(n),i.once))return void(o=!0)});return g(s),o&&s(),s}let i=(0,e.watch)(t,n,r);return g(i),i},Object.keys(e).forEach(function(t){t===`default`||Object.prototype.hasOwnProperty.call(exports,t)||Object.defineProperty(exports,t,{enumerable:!0,get:function(){return e[t]}})});
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});let e=require(`@vielzeug/stateit`);var t=0,n=e=>{for(let t of e)t()},r=(e,t,n)=>{/^on/i.test(t)||n==null||!1===n?e.removeAttribute(t):!0===n?e.setAttribute(t,``):e.setAttribute(t,String(n))},i=(e,t,n,r)=>{let i=n;return e.addEventListener(t,i,r),()=>e.removeEventListener(t,i,r)},a=e=>`${e?`${e}-`:`cft-`}${++t}`,o=e=>e.replace(/[A-Z]/g,e=>`-${e.toLowerCase()}`),s={"'":`&#39;`,'"':`&quot;`,"&":`&amp;`,"<":`&lt;`,">":`&gt;`},c=e=>String(e).replace(/[&<>"']/g,e=>s[e]),l=function(){return this.content},u=new Map,d=e=>{if(e instanceof CSSStyleSheet)return e;let t=typeof e==`string`?e:e.content,n=u.get(t);if(n)return n;let r=new CSSStyleSheet;try{r.replaceSync(t),u.set(t,r)}catch(e){console.error(`[craftit:E2] style replace failed`,e)}return r},f=[],p=()=>{let e=f[f.length-1];if(!e)throw Error(`[craftit:E1] lifecycle outside setup`);return e},m=e=>{p().onMount.push(e)},h=t=>{f.length>0?p().cleanups.push(t):(0,e.onCleanup)(t)},g=e=>{f.length>0&&h(e)},_=(t,n)=>{let r=(0,e.effect)(t,n);return g(r),r};function v(e,t,n,r){e&&(e.addEventListener(t,n,r),h(()=>e.removeEventListener(t,n,r)))}var y={bubbles:!0,cancelable:!0,composed:!0},b={basic:(e,t,n={})=>e.dispatchEvent(new Event(t,{...y,...n})),custom:(e,t,n={})=>e.dispatchEvent(new CustomEvent(t,{...y,...n})),event:(e,t)=>e.dispatchEvent(t),focus:(e,t,n={})=>e.dispatchEvent(new FocusEvent(t,{...y,...n})),keyboard:(e,t,n={})=>e.dispatchEvent(new KeyboardEvent(t,{...y,...n})),mouse:(e,t,n={})=>e.dispatchEvent(new MouseEvent(t,{...y,...n})),touch:(e,t,n={})=>typeof TouchEvent<`u`?e.dispatchEvent(new TouchEvent(t,{...y,...n})):e.dispatchEvent(new CustomEvent(t,{...y,...n}))},x=new WeakMap,S=new Set,C=(e,t,n)=>{let r=`${n}:${e.localName}:${t||`default`}`;S.has(r)||(S.add(r),console.warn(`[craftit:E10] ${n} could not find a matching <slot${t?` name="${t}"`:``}> in <${e.localName}>. Render the slot before using ${n}.`))};function w(e,t){for(let[n,r]of Object.entries(t))if(n===`classMap`)te(e,r);else if(n.startsWith(`on`)&&n.length>2&&typeof r==`function`){let t=n.slice(2);v(e,t[0].toLowerCase()+t.slice(1),r)}else ee(e,n,r)}function ee(e,t,n){typeof n==`function`?_(()=>r(e,t,n())):r(e,t,n)}function te(e,t){let n=new Set;_(()=>{let r=new Set(Object.entries(t()).filter(([,e])=>e).map(([e])=>e));for(let t of n)r.has(t)||e.classList.remove(t);for(let t of r)n.has(t)||e.classList.add(t);n=r})}var T=Symbol(`craftit.htmlResultBrand`);function E(e,t=[]){let n={__bindings:t,__html:e,toString:()=>e};return Object.defineProperty(n,T,{configurable:!1,enumerable:!1,value:!0,writable:!1}),n}var D=e=>typeof e==`object`&&!!e&&!0===e[T],O=Symbol(`craftit.eachSignal`),k=t=>(0,e.isSignal)(t)?t:typeof t==`function`?(0,e.computed)(t):void 0,A=t=>{if(!(0,e.isSignal)(t))return!1;let n=Object.getPrototypeOf(t);for(;n;){let e=Object.getOwnPropertyDescriptor(n,`value`);if(e)return typeof e.set==`function`;n=Object.getPrototypeOf(n)}return!1},j=(e,t)=>{if(!Object.is(e.value,t))try{e.value=t}catch{}},M=new Map,N=e=>(e=>{let t=M.get(e);if(!t){if(t=document.createElement(`template`),t.innerHTML=e,M.size>=1e3){let e=M.keys().next().value;e!==void 0&&M.delete(e)}M.set(e,t)}return t})(e).content.cloneNode(!0),P=(e,t)=>{if(e.nodeType===Node.COMMENT_NODE){let n=e.nodeValue;n&&t.comments.set(n,e);return}if(e.nodeType!==Node.ELEMENT_NODE)return;let n=e.getAttribute(`u`);n&&t.elements.set(n,e)},F=e=>{let t={comments:new Map,elements:new Map};for(let n of e){let e=document.createTreeWalker(n,NodeFilter.SHOW_COMMENT|NodeFilter.SHOW_ELEMENT);for(P(n,t);e.nextNode();)P(e.currentNode,t)}return t},I=e=>Array.from(N(e).childNodes),L=(e,t,n)=>{if(e.parentNode)for(let r of t)e.parentNode.insertBefore(r,n)},R=e=>Array.isArray(e)||typeof e==`object`&&!!e,z=(e,t,n)=>{n(_(()=>t(e.value)))},ne=(e,t,n)=>{let i=n=>{let i=Q.get(e)?.get(t.name);if(!i&&R(n))return void(e[t.name]=n);if(i&&!i.reflect||(t.mode===`bool`?e.toggleAttribute(t.name,!!n):r(e,t.name,n)),!i)return;let a=R(n)?n:i.parse(t.mode===`bool`?n?``:null:n==null||!1===n?null:String(n));Object.is(i.signal.peek(),a)||(i.signal.value=a)};t.signal?z(t.signal,i,n):i(t.value)},re=(e,t,n)=>{let r=n=>{e[t.name]=n};t.signal?z(t.signal,r,n):r(t.value),((e,t,n,r)=>{n&&(t===`value`?(e instanceof HTMLInputElement||e instanceof HTMLTextAreaElement||e instanceof HTMLSelectElement)&&r(i(e,e instanceof HTMLSelectElement?`change`:`input`,()=>{j(n,e.value)})):t===`checked`&&e instanceof HTMLInputElement&&r(i(e,`change`,()=>{j(n,e.checked)})))})(e,t.name,t.model,n)},ie=(e,t,n)=>{let{modifiers:r}=t,a=r?{capture:!!r.capture,once:!!r.once,passive:!!r.passive}:void 0;n(i(e,t.name,e=>{r?.self&&e.target!==e.currentTarget||(r?.stop&&e.stopPropagation(),r?.prevent&&!r?.passive&&e.preventDefault(),t.handler(e))},a))},ae=(e,t,n)=>{let{ref:r}=t;typeof r==`function`?(r(e),n(()=>r(null))):Array.isArray(r)?(r.push(e),n(()=>{let t=r.indexOf(e);t!==-1&&r.splice(t,1)})):(r.value=e,n(()=>{r.value=null}))},B=(e,t,n,r)=>{let i=new Map;for(let a of e){let e=a.uid;if(a.type===`text`){let r=n.comments.get(e);if(r){let i=document.createTextNode(``);r.replaceWith(i),n.comments.delete(e),z(a.signal,e=>{i.textContent=String(e)},t)}}else a.type===`html`?r?.onHtml?.(a):(i.has(e)||i.set(e,[]),i.get(e).push(a))}for(let[e,r]of i){let i=n.elements.get(e);if(i){i.removeAttribute(`u`),n.elements.delete(e);for(let e of r)switch(e.type){case`attr`:ne(i,e,t);break;case`callback`:e.apply(i,t);break;case`event`:ie(i,e,t);break;case`prop`:re(i,e,t);break;case`ref`:ae(i,e,t)}}}},V=(e,t,n,r)=>{let i=k(r);return i?{mode:e,name:t,signal:i,type:`attr`,uid:n}:{mode:e,name:t,type:`attr`,uid:n,value:r}},oe=(e,t,n)=>{let r=k(n);return r?{model:A(n)?n:void 0,name:e,signal:r,type:`prop`,uid:t}:{name:e,type:`prop`,uid:t,value:n}},se=RegExp(`u="([^"]+)"`,`g`),ce=[{kind:`event`,regex:/\s+@([a-zA-Z_][-a-zA-Z0-9_.]*)\s*=\s*["']?$/},{kind:`ref`,regex:/\s+ref\s*=\s*["']?$/},{kind:`specialAttr`,regex:/\s+([:?])([a-zA-Z_][-a-zA-Z0-9_]*)\s*=\s*["']?$/},{kind:`prop`,regex:/\.([a-zA-Z_][-a-zA-Z0-9_]*)\s*=\s*["']?$/},{kind:`plainAttr`,regex:/\s+([a-zA-Z_][-a-zA-Z0-9_]*)\s*=\s*["']?$/}],H=new WeakMap,le=e=>{let[t,...n]=e.split(`.`),r={};for(let e of n)e===`capture`?r.capture=!0:e===`once`?r.once=!0:e===`passive`?r.passive=!0:e===`prevent`?r.prevent=!0:e===`self`?r.self=!0:e===`stop`&&(r.stop=!0);return{modifiers:Object.keys(r).length?r:void 0,name:t}},U=()=>{let e=0;return()=>String(e++)},W=(e,t)=>{let n=new Map,r=e=>{let r=n.get(e);if(r)return r;let i=t();return n.set(e,i),i};return{bindings:e.__bindings.map(e=>({...e,uid:r(e.uid)})),html:e.__html.replace(se,(e,t)=>`u="${r(t)}"`).replace(/<!--(\d+)-->/g,(e,t)=>`\x3c!--${r(t)}--\x3e`)}},G=e=>typeof e==`string`?c(e):e==null?``:D(e)?e.__html:c(String(e)),ue=(t,n)=>{let r=(e=>typeof e==`object`&&e&&O in e?e[O]:null)(t);if(r)return{keyed:!0,signal:r};if(typeof t==`function`&&!(0,e.isSignal)(t)){let{signal:r}=((t,n)=>{let r={bindings:[],html:``},i=(0,e.signal)(r);return n(()=>{let e=t(),n=Array.isArray(e)?e:[e],a=U(),o=``,s=[];for(let e of n)if(D(e)){let t=W(e,a);o+=t.html,s.push(...t.bindings)}else o+=G(e);let c=s.length!==r.bindings.length||s.some((e,t)=>e!==r.bindings[t]);(o!==r.html||c)&&(r={bindings:s,html:o},i.value=r)}),{bindings:[],signal:i}})(t,n);return{keyed:!1,signal:r}}return(0,e.isSignal)(t)&&D(t.value)?{keyed:!1,signal:(0,e.computed)(()=>{let e=t.value;if(!D(e))return{bindings:[],html:G(e)};let n=W(e,U());return{bindings:n.bindings,html:n.html}})}:null},K=e=>{n(e.cleanups);for(let t of e.nodes)t.remove()},q=(e,t,n=F(e))=>{let r=[];return B(t,e=>r.push(e),n),r},J=(t,r,i,a,o)=>{let s=((e,t)=>{let n=document.createTreeWalker(e,NodeFilter.SHOW_COMMENT);for(;n.nextNode();){let e=n.currentNode;if(e.nodeValue===t)return e}return null})(t,r.uid);if(!s)return;let c=document.createComment(`html-binding`);s.replaceWith(c);let l=[],u=e=>l.push(e),d=()=>{n(l),l=[]},f=null,p=[];i((0,e.effect)(()=>{(0,e.batch)(()=>{let i=r.signal.value;if(!r.keyed&&i.html===f)return;f=i.html,d();let{bindings:s,html:l,keys:m}=i;r.keyed&&!a.has(r.uid)&&a.set(r.uid,new Map);let h=r.keyed?a.get(r.uid):null,g=c.parentElement||t,_=!1;(0,e.untrack)(()=>{(0,e.batch)(()=>{if(h&&m?.length&&i.items?.length===m.length){if(_=!0,h.size===0&&p.length>0){for(let e of p)e.remove();p=[]}let e=new Map;for(let t=0;t<m.length;t++){let r=m[t],a=i.items[t],o=h.get(r),s=t>0?e.get(m[t-1])?.nodes:null,l=s?.length?s[s.length-1].nextSibling:c.nextSibling;if(o?.html===a.html){o.nodes[0]&&L(c,o.nodes,l),n(o.cleanups);let t=F(o.nodes),i=q(o.nodes,a.bindings,t);e.set(r,{...o,bindings:a.bindings,cleanups:i,targets:t})}else if(o){n(o.cleanups);let t=I(a.html),i=F(t);L(c,t,l);let s=q(t,a.bindings,i);e.set(r,{bindings:a.bindings,cleanups:s,html:a.html,nodes:t,targets:i});for(let e of o.nodes)e.remove()}else{let t=I(a.html),n=F(t);L(c,t,l);let i=q(t,a.bindings,n);e.set(r,{bindings:a.bindings,cleanups:i,html:a.html,nodes:t,targets:n})}}for(let[t,n]of h)e.has(t)||K(n);a.set(r.uid,e)}else{if(r.keyed&&h&&h.size>0)for(let[,e]of h)K(e);else for(let e of p)e.remove();let e=N(l);p=Array.from(e.childNodes),c.after(e),r.keyed&&a.set(r.uid,new Map)}}),_||o(g,s,u,{onHtml:e=>J(g,e,u,a,o)})})})})),i(d),r.keyed&&i(()=>a.delete(r.uid))},Y=(e,t,n,r)=>{B(t,n,(e=>{let t={comments:new Map,elements:new Map},n=document.createTreeWalker(e,NodeFilter.SHOW_COMMENT|NodeFilter.SHOW_ELEMENT);for(P(e,t);n.nextNode();)P(n.currentNode,t);return t})(e),r)},X=new WeakMap,Z=new WeakMap,de=new Set([`default`,`omit`,`parse`,`reflect`,`type`]),fe=e=>typeof e==`object`&&!!e&&`default`in e&&Object.keys(e).every(e=>de.has(e)),Q=new WeakMap,$=(t,n,i)=>{let a=p(),o=a.el;Q.has(o)||Q.set(o,new Map);let s=i?.parse??(e=>i?.type===Boolean?e===``||e===`true`:typeof n==`boolean`?e!==null&&e!==`false`:e==null?n:i?.type===Number||typeof n==`number`?Number(e):e),c=(0,e.signal)(n),l=Object.prototype.hasOwnProperty.call(o,t),u=l?o[t]:void 0,d={parse:s,reflect:i?.reflect??!0,signal:c};if(l?(delete o[t],c.value=u):o.hasAttribute(t)&&(c.value=s(o.getAttribute(t))),Q.get(o).set(t,d),Object.defineProperty(o,t,{configurable:!0,enumerable:!0,get:()=>c.value,set:e=>{c.value=e}}),i?.reflect??1){let n=i?.omit??!1;a.onMount.push(()=>{a.cleanups.push((0,e.effect)(()=>{let e=c.value;e==null||!1===e||n&&e===``?o.removeAttribute(t):r(o,t,e)}))})}return c},pe=class extends HTMLElement{static _setup;static _options;static formAssociated=!1;static observedAttributes=[];shadow;_keyedStates=new Map;_mountFns=[];_template=null;_appliedHtmlBindings=new Set;_setupDone=!1;_runtime;constructor(){super();let e=this.constructor._options;this.shadow=this.attachShadow({mode:`open`,...e?.shadow}),this._runtime={cleanups:[],el:this,errorHandlers:[],onMount:[],styles:e?.styles}}connectedCallback(){this._setupDone||this._runSetup(),this._init()}attributeChangedCallback(e,t,n){if(t===n)return;let r=Q.get(this)?.get(e);if(!r)return;let i=r.parse(n);Object.is(r.signal.peek(),i)||(r.signal.value=i)}disconnectedCallback(){n(this._runtime.cleanups),this._runtime.cleanups=[],this._runtime.onMount=this._mountFns.slice(),this._appliedHtmlBindings.clear(),this._keyedStates.clear()}formAssociatedCallback(e){X.get(this)?.onAssociated?.(e)}formDisabledCallback(e){X.get(this)?.onDisabled?.(e)}formResetCallback(){X.get(this)?.onReset?.()}formStateRestoreCallback(e,t){X.get(this)?.onStateRestore?.(e,t)}_handleError(e){if(this._runtime.errorHandlers.length>0)for(let t of this._runtime.errorHandlers)t(e);else console.error(`[craftit:E3] <${this.localName}>`,e)}_runSetup(){this._setupDone=!0,f.push(this._runtime);try{let{host:e}=this.constructor._options??{};if(e)for(let[t,n]of Object.entries(e))typeof n==`boolean`?n?this.setAttribute(t,``):this.removeAttribute(t):this.setAttribute(t,String(n));let t=this.constructor._setup({host:this,shadow:this.shadow});(typeof t==`string`||typeof t==`object`&&t&&`__html`in t)&&(this._template=t)}catch(e){this._handleError(e)}finally{f.pop()}}_init(){let{styles:e}=this._runtime;if(e?.length&&(this.shadow.adoptedStyleSheets=e.map(d)),this._template){let e=typeof this._template==`string`?E(this._template):this._template;if(this.shadow.replaceChildren(N(e.__html)),e.__bindings.length){let t=e=>this._runtime.cleanups.push(e);Y(this.shadow,e.__bindings,t,{onHtml:e=>{this._appliedHtmlBindings.has(e.uid)||(this._appliedHtmlBindings.add(e.uid),((e,t,n,r)=>{J(e,t,n,r,Y)})(this.shadow,e,t,this._keyedStates))}})}}queueMicrotask(()=>{f.push(this._runtime);try{let e=this._runtime.onMount;this._mountFns=e.slice();for(let t of e){let e=t();typeof e==`function`&&this._runtime.cleanups.push(e)}}catch(e){this._handleError(e)}finally{f.pop(),this._runtime.onMount=[]}})}};exports.aria=function(e,t){let n=t===void 0?p().el:e,r=Object.entries(t===void 0?e:t).map(([e,t])=>_(()=>((e,t)=>{let r=`aria-${e}`,i=typeof t==`function`?t():t;i==null||!1===i?n.removeAttribute(r):n.setAttribute(r,String(i))})(e,t)));if(t!==void 0)return()=>{for(let e of r)e()}},exports.createContext=function(e){return Symbol(e)},exports.createFormIds=(e,t)=>{let n=`${e}-${t&&t.trim()?t:a(e)}`;return{errorId:`error-${n}`,fieldId:n,helperId:`helper-${n}`,labelId:`label-${n}`}},exports.createId=a,exports.css=(e,...t)=>{let n=``;for(let r=0;r<e.length;r++)if(n+=e[r],r<t.length){let e=t[r];n+=e&&typeof e==`object`&&`content`in e?e.content:e??``}return{content:n.trim(),toString:l}},exports.defineComponent=function(t){let{formAssociated:n,host:r,props:i,setup:a,shadow:s,styles:c,tag:l}=t;return function(e,t,n={}){if(!e)throw Error(`[craftit:E4] registerComponent(tag, ...) requires a tag name`);if(customElements.get(e))throw Error(`[craftit:E9] custom element already defined: ${e}`);class r extends pe{static _setup=t;static _options=n;static formAssociated=n.formAssociated??!1;static observedAttributes=n.observedAttrs??[]}return customElements.define(e,r),e}(l,t=>{let n=i?function(e){let t={};for(let[n,r]of Object.entries(e)){let e=fe(r)?r:{default:r},i={reflect:!(typeof e.default==`object`&&e.default!==null||Array.isArray(e.default)),...e};t[n]=$(o(n),e.default,i)}return t}(i):{},r=(()=>{let e=p().el;return(t,...n)=>{b.custom(e,String(t),n.length>0?{detail:n[0]}:void 0)}})(),s=(()=>{let t=p().el,n=new Map;return{has:r=>(r=>{if(n.has(r))return n.get(r);let i=(0,e.signal)(!1);return n.set(r,i),m(()=>{let e=r?`slot[name="${r}"]`:`slot:not([name])`,n=t.shadowRoot?.querySelector(e);if(!n)return void C(t,r,`slots.has()`);let a=()=>{i.value=n.assignedNodes().length>0};return a(),n.addEventListener(`slotchange`,a),()=>n.removeEventListener(`slotchange`,a)}),i})(r===`default`?``:String(r))}})();return a({emit:r,host:t.host,props:n,reflect:e=>w(t.host,e),shadow:t.shadow,slots:s})},{formAssociated:n,host:r,observedAttrs:i?Object.keys(i).map(o):[],shadow:s,styles:c})},exports.defineField=(t,n)=>{let r=p().el;if(!r.constructor.formAssociated)throw Error(`[craftit:E8] defineField() requires defineComponent({ formAssociated: true })`);let i=Z.get(r)??r.attachInternals();Z.set(r,i);let a=t.toFormValue??(e=>e==null?``:String(e));return(0,e.effect)(()=>{i.setFormValue(a(t.value.value))}),t.disabled&&(0,e.effect)(()=>{t.disabled.value?i.states.add(`disabled`):i.states.delete(`disabled`)}),n&&X.set(r,{...X.get(r),...n}),{checkValidity:()=>i.checkValidity(),internals:i,reportValidity:()=>i.reportValidity(),setCustomValidity:e=>e?i.setValidity({customError:!0},e):i.setValidity({}),setValidity:i.setValidity.bind(i)}},exports.effect=_,exports.escapeHtml=c,exports.fire=b,exports.guard=(e,t)=>n=>{e()&&t(n)},exports.handle=v,exports.html=(t,...n)=>((t,n,r)=>{let i=(e=>{let t=H.get(e);return t||(t=(e=>{let t=[];for(let n=0;n<e.length-1;n++){let r=e[n],i=!1;for(let e of ce){let n=e.regex.exec(r);if(!n)continue;let a=r.slice(0,-n[0].length);if(i=!0,e.kind===`event`){let e=le(n[1]);t.push({kind:`event`,modifiers:e.modifiers,name:e.name,prefix:a,raw:r})}else e.kind===`ref`?t.push({kind:`ref`,prefix:a,raw:r}):e.kind===`specialAttr`?t.push({kind:`specialAttr`,mode:n[1]===`?`?`bool`:`attr`,name:n[2],prefix:a,raw:r}):e.kind===`prop`?t.push({kind:`prop`,name:n[1],prefix:a,raw:r}):e.kind===`plainAttr`&&t.push({kind:`plainAttr`,name:n[1],prefix:a,raw:r});break}i||t.push({kind:`node`,prefix:r,raw:r})}return{slots:t,tail:e[e.length-1]??``}})(e),H.set(e,t)),t})(t),a=``,o=[],s=null,c=U(),l=e=>(s&&!(e=>e.lastIndexOf(`<`)>e.lastIndexOf(`>`))(e)||(s=c()),s),u=()=>{s=null};for(let t=0;t<i.slots.length;t++){let s=i.slots[t],d=n[t];if(s.kind===`event`){if(typeof d==`function`){let e=l(s.prefix);a+=`${s.prefix} u="${e}"`,o.push({handler:d,modifiers:s.modifiers,name:s.name,type:`event`,uid:e})}else a+=s.raw;continue}if(s.kind===`ref`){if(d){let e=l(s.prefix);a+=`${s.prefix} u="${e}"`,o.push({ref:d,type:`ref`,uid:e})}else a+=s.raw;continue}if(s.kind===`specialAttr`){let e=l(s.prefix);a+=`${s.prefix} u="${e}"`,o.push(V(s.mode,s.name,e,d));continue}if(s.kind===`prop`){let e=l(s.prefix);a+=`${s.prefix} u="${e}"`,o.push(oe(s.name,e,d));continue}if(s.kind===`plainAttr`){let e=l(s.prefix);a+=`${s.prefix} u="${e}"`,o.push(V(`attr`,s.name,e,d));continue}if(typeof d==`object`&&d&&(`mount`in d||`render`in d)){let t=`render`in d,n=t?c():l(s.raw);a+=t?`${s.raw}\x3c!--${n}--\x3e`:`${s.raw} u="${n}"`;let i=d.mount?.bind(d);if(i&&o.push({apply:(e,t)=>{i(e,{registerCleanup:t})},type:`callback`,uid:n}),t){let t=d.render.bind(d),i={bindings:[],html:``},a=(0,e.signal)(i);r(()=>{let e=t(),n=Array.isArray(e)?e:[e],r=U(),o=``,s=[];for(let e of n)if(D(e)){let t=W(e,r);o+=t.html,s.push(...t.bindings)}else o+=G(e);let c=s.length!==i.bindings.length||s.some((e,t)=>e!==i.bindings[t]);(o!==i.html||c)&&(i={bindings:s,html:o},a.value=i)}),o.push({keyed:!1,signal:a,type:`html`,uid:n})}continue}u();let f=ue(d,r);if(f){let e=c();a+=`${s.raw}\x3c!--${e}--\x3e`,o.push({keyed:f.keyed,signal:f.signal,type:`html`,uid:e});continue}if(Array.isArray(d)){let e=``;for(let t of d)if(D(t)){let n=W(t,c);e+=n.html,o.push(...n.bindings)}else e+=G(t);a+=s.raw+e;continue}if((0,e.isSignal)(d)){let e=c();a+=`${s.raw}\x3c!--${e}--\x3e`,o.push({signal:d,type:`text`,uid:e})}else if(D(d)){let e=W(d,c);a+=s.raw+e.html,o.push(...e.bindings)}else a+=s.raw+G(d)}return a+=i.tail,E(a.replace(/>\s+</g,`><`).trim(),o)})(t,n,_),exports.inject=function(e,...t){let n=p().el;for(;n;){if(n instanceof HTMLElement){let t=x.get(n)?.get(e);if(t!==void 0)return t}let t=n.getRootNode();n=n.parentElement??(t instanceof ShadowRoot?t.host:null)}return t.length>0?t[0]:void 0},exports.observeResize=t=>{let n=(0,e.signal)({height:0,width:0}),r=new ResizeObserver(([e])=>{if(!e)return;let t=e.contentBoxSize[0];t&&(n.value={height:t.blockSize,width:t.inlineSize})});return r.observe(t),h(()=>r.disconnect()),n},exports.onCleanup=h,exports.onError=e=>{p().errorHandlers.push(e)},exports.onMount=m,exports.onSlotChange=(e,t)=>{let n=p().el,r=e===`default`?``:e,i=r?`slot[name="${r}"]`:`slot:not([name])`,a=n.shadowRoot?.querySelector(i);if(!a)return void C(n,r,`onSlotChange()`);let o=()=>t(a.assignedElements({flatten:!0}));o(),a.addEventListener(`slotchange`,o),h(()=>a.removeEventListener(`slotchange`,o))},exports.prop=$,exports.provide=(e,t)=>{let n=p().el;x.has(n)||x.set(n,new Map),x.get(n).set(e,t)},exports.ref=function(){return{value:null}},exports.reflect=w,exports.refs=function(){return[]},exports.syncContextProps=(e,t,n)=>{e&&m(()=>{_(()=>{for(let r of n){let n=e[r]?.value;n!==void 0&&(t[r].value=n)}})})},exports.toKebab=o,exports.typed=(e,t)=>({...t,default:e}),exports.watch=function(t,n,r){if(Array.isArray(t)){let i=r,a=!1,o=!1,s=(0,e.effect)(()=>{for(let e of t)e.value;if(a)(0,e.untrack)(n),i?.once&&s();else if(a=!0,i?.immediate&&((0,e.untrack)(n),i.once))return void(o=!0)});return g(s),o&&s(),s}let i=(0,e.watch)(t,n,r);return g(i),i},Object.keys(e).forEach(function(t){t===`default`||Object.prototype.hasOwnProperty.call(exports,t)||Object.defineProperty(exports,t,{enumerable:!0,get:function(){return e[t]}})});
2
2
  //# sourceMappingURL=craftit.cjs.map