@knighted/jsx 1.7.9 → 1.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,8 +1,8 @@
1
- import {parseSync}from'oxc-parser';import {find,svg,html}from'property-information';var w=null,$=e=>{w=e;},se=e=>{w?.warnLowercaseEventProp?.(e);},ae=e=>{w?.ensureValidDangerouslySetInnerHTML?.(e);},P=e=>{let{getIdentifierName:t,evaluateExpressionWithNamespace:n}=e;return (r,o,s)=>{let a={},c=(i,p)=>{i==="dangerouslySetInnerHTML"&&ae(p),a[i]=p;};return r.forEach(i=>{if(i.type==="JSXSpreadAttribute"){let l=n(i.argument,o,s);l&&typeof l=="object"&&!Array.isArray(l)&&Object.assign(a,l);return}let p=t(i.name);if(se(p),!i.value){c(p,true);return}if(i.value.type==="Literal"){c(p,i.value.value);return}if(i.value.type==="JSXExpressionContainer"){if(i.value.expression.type==="JSXEmptyExpression")return;c(p,n(i.value.expression,o,s));}}),a}};var L=null,O=e=>{L=e;},j="Capture",I=e=>e.endsWith(j)?{eventName:e.slice(0,-j.length),capture:true}:{eventName:e,capture:false},_=e=>{if(!e.startsWith("on"))return null;if(e.startsWith("on:")){let r=e.slice(3);if(!r)return null;let o=I(r);return o.eventName?o:null}let t=e.slice(2);if(!t)return null;let n=I(t);return n.eventName?{eventName:n.eventName.toLowerCase(),capture:n.capture}:null},H=e=>!e||typeof e!="object"?false:"handleEvent"in e&&typeof e.handleEvent=="function",ie=e=>{if(!e||typeof e!="object"||!("handler"in e))return false;let t=e.handler;return typeof t=="function"?true:H(t)},pe=(e,t)=>{L?.onInvalidHandler?.(e,t);},F=(e,t)=>{if(typeof t=="function"||H(t))return {listener:t};if(!ie(t))return pe(e,t),null;let n=t,r=n.options?{...n.options}:void 0,o=(s,a)=>{a!=null&&(r||(r={}),r[s]=a);};return o("capture",n.capture),o("once",n.once),o("passive",n.passive),o("signal",n.signal??void 0),{listener:n.handler,options:r}};var ce="@knighted/jsx",B=e=>`${ce}: ${e}`,J=()=>typeof process<"u"&&process.env?.KNIGHTED_JSX_DEBUG==="1",C=e=>{if(e===null)return "null";if(e===void 0)return "undefined";if(typeof e=="function")return e.name?`function ${e.name}`:"function";if(Array.isArray(e))return "array";if(typeof e=="object"){let t=e.constructor;return t&&typeof t.name=="string"&&t.name&&t.name!=="Object"?`${t.name} instance`:"object"}return typeof e},b=e=>new Error(B(e)),W=(e,t=false)=>{!t&&!J()||typeof console<"u"&&typeof console.warn=="function"&&console.warn(B(e));};var le=e=>e>="a"&&e<="z",S="env",A=()=>S==="always"||S==="env"&&J(),me=()=>S==="always",ue={warnLowercaseEventProp(e){if(!A()||!e.startsWith("on")||e.startsWith("on:")||e.length<3)return;let t=e[2]??"";if(!le(t))return;let n=`${e.slice(0,2)}${t.toUpperCase()}${e.slice(3)}`;W(`Use camelCase DOM event props when targeting runtime jsx templates. Received "${e}"; did you mean "${n}"?`,me());},ensureValidDangerouslySetInnerHTML(e){if(!A())return;if(!e||typeof e!="object"||Array.isArray(e))throw b("dangerouslySetInnerHTML expects an object with a string __html field.");let t=e.__html;if(typeof t!="string")throw b(`dangerouslySetInnerHTML.__html must be a string but received ${C(t)}.`)}},de={onInvalidHandler(e,t){if(A())throw b(`The "${e}" prop expects a function, EventListenerObject, or descriptor ({ handler }) but received ${C(t)}.`)}},V=e=>{S=e?.mode,$(ue),O(de);};var z=e=>{let t=e.replace(/\r/g,"").replace(/\n\s+/g," "),n=e.match(/^\s*/)?.[0]??"",r=e.match(/\s*$/)?.[0]??"",o=/\n/.test(n),s=/\n/.test(r),a=t;return o&&(a=a.replace(/^\s+/,"")),s&&(a=a.replace(/\s+$/,"")),a.length===0||a.trim().length===0?null:a};var ge="oxc-parser",fe=e=>{let t=e.raw??e,n=t[0]??"",r=[];for(let o=0;o<t.length-1;o++){let s="${expr#"+o+"}",a=n.length;n+=s;let c=n.length;r.push({index:o,templateStart:a,templateEnd:c,label:s}),n+=t[o+1]??"";}return {source:n,spans:r}},xe=(e,t)=>{let n=new Map;return t.forEach(r=>{n.set(r.index,r);}),e.expressionRanges.map(r=>{let o=n.get(r.index);if(!o)return null;let s=Math.max(0,r.sourceEnd-r.sourceStart),a=Math.max(0,o.templateEnd-o.templateStart);return {sourceStart:r.sourceStart,sourceEnd:r.sourceEnd,templateStart:o.templateStart,templateEnd:o.templateEnd,delta:a-s}}).filter(r=>!!r).sort((r,o)=>r.sourceStart-o.sourceStart)},ye=(e,t,n)=>{if(!Number.isFinite(e)||e<=0)return 0;let r=0;for(let s of t){if(e<s.sourceStart)break;if(e<s.sourceEnd){let a=Math.max(0,e-s.sourceStart),c=Math.max(0,s.templateEnd-s.templateStart);if(c===0)return s.templateStart;let i=Math.min(a,Math.max(0,c-1));return s.templateStart+i}r+=s.delta;}let o=e+r;return o<=0?0:o>=n?n:o},U=(e,t)=>{let n=Math.max(0,Math.min(t,e.length)),r=1,o=1;for(let s=0;s<n;s++){if(e.charCodeAt(s)===10){r++,o=1;continue}o++;}return {line:r,column:o}},Ee=e=>{let t=[],n=0;return e.forEach((r,o)=>{t.push(n),n+=r.length,o<e.length-1&&(n+=1);}),t},he=(e,t,n,r,o,s,a)=>{let c=n+t.length,i=Math.max(r,n),p=Math.min(o,c);if(p>i){let l=Math.max(0,i-n),u=Math.max(1,p-i);return " ".repeat(l)+"^".repeat(u)}if(t.length===0&&e>=s&&e<=a)return "^";if(e===s){let l=Math.max(0,r-n);return " ".repeat(Math.min(l,t.length))+"^"}return ""},be=(e,t,n,r,o)=>{if(!e.length)return "";let s=e.split(`
2
- `),a=Ee(s),c=Math.max(1,r-1),i=Math.min(s.length,o+1),p=String(i).length,l=[];for(let u=c;u<=i;u++){let d=s[u-1]??"",m=String(u).padStart(p," ");l.push(`${m} | ${d}`);let g=he(u,d,a[u-1]??0,t,n,r,o);g&&l.push(`${" ".repeat(p)} | ${g}`);}return l.join(`
3
- `)},k=(e,t,n,r,o)=>{let s=ge,a=`[${s}] ${r.message}`,c=r.labels?.[0];if(!c)return a;let{source:i,spans:p}=fe(t),l=xe(n,p),u=y=>ye(typeof y=="number"?y:0,l,i.length),d=u(c.start),m=u(c.end);m<=d&&(m=Math.min(i.length,d+1));let g=U(i,d),x=U(i,Math.max(d,m-1)),h=be(i,d,m,g.line,x.line),f=`[${s}] ${r.message}`;return f+=`
1
+ import {parseSync}from'oxc-parser';import {find,svg,html}from'property-information';var w=null,O=e=>{w=e;},le=e=>{w?.warnLowercaseEventProp?.(e);},me=e=>{w?.ensureValidDangerouslySetInnerHTML?.(e);},F=e=>{let{getIdentifierName:t,evaluateExpressionWithNamespace:n}=e;return (r,s,o)=>{let a={},c=(i,p)=>{i==="dangerouslySetInnerHTML"&&me(p),a[i]=p;};return r.forEach(i=>{if(i.type==="JSXSpreadAttribute"){let l=n(i.argument,s,o);l&&typeof l=="object"&&!Array.isArray(l)&&Object.assign(a,l);return}let p=t(i.name);if(le(p),!i.value){c(p,true);return}if(i.value.type==="Literal"){c(p,i.value.value);return}if(i.value.type==="JSXExpressionContainer"){if(i.value.expression.type==="JSXEmptyExpression")return;c(p,n(i.value.expression,s,o));}}),a}};var _=null,H=e=>{_=e;},L="Capture",I=e=>e.endsWith(L)?{eventName:e.slice(0,-L.length),capture:true}:{eventName:e,capture:false},B=e=>{if(!e.startsWith("on"))return null;if(e.startsWith("on:")){let r=e.slice(3);if(!r)return null;let s=I(r);return s.eventName?s:null}let t=e.slice(2);if(!t)return null;let n=I(t);return n.eventName?{eventName:n.eventName.toLowerCase(),capture:n.capture}:null},W=e=>!e||typeof e!="object"?false:"handleEvent"in e&&typeof e.handleEvent=="function",ue=e=>{if(!e||typeof e!="object"||!("handler"in e))return false;let t=e.handler;return typeof t=="function"?true:W(t)},de=(e,t)=>{_?.onInvalidHandler?.(e,t);},V=(e,t)=>{if(typeof t=="function"||W(t))return {listener:t};if(!ue(t))return de(e,t),null;let n=t,r=n.options?{...n.options}:void 0,s=(o,a)=>{a!=null&&(r||(r={}),r[o]=a);};return s("capture",n.capture),s("once",n.once),s("passive",n.passive),s("signal",n.signal??void 0),{listener:n.handler,options:r}};var ge="@knighted/jsx",U=e=>`${ge}: ${e}`,C=()=>typeof process<"u"&&process.env?.KNIGHTED_JSX_DEBUG==="1",v=e=>{if(e===null)return "null";if(e===void 0)return "undefined";if(typeof e=="function")return e.name?`function ${e.name}`:"function";if(Array.isArray(e))return "array";if(typeof e=="object"){let t=e.constructor;return t&&typeof t.name=="string"&&t.name&&t.name!=="Object"?`${t.name} instance`:"object"}return typeof e},b=e=>new Error(U(e)),z=(e,t=false)=>{!t&&!C()||typeof console<"u"&&typeof console.warn=="function"&&console.warn(U(e));};var fe=e=>e>="a"&&e<="z",S="env",k=()=>S==="always"||S==="env"&&C(),xe=()=>S==="always",ye={warnLowercaseEventProp(e){if(!k()||!e.startsWith("on")||e.startsWith("on:")||e.length<3)return;let t=e[2]??"";if(!fe(t))return;let n=`${e.slice(0,2)}${t.toUpperCase()}${e.slice(3)}`;z(`Use camelCase DOM event props when targeting runtime jsx templates. Received "${e}"; did you mean "${n}"?`,xe());},ensureValidDangerouslySetInnerHTML(e){if(!k())return;if(!e||typeof e!="object"||Array.isArray(e))throw b("dangerouslySetInnerHTML expects an object with a string __html field.");let t=e.__html;if(typeof t!="string")throw b(`dangerouslySetInnerHTML.__html must be a string but received ${v(t)}.`)}},Ee={onInvalidHandler(e,t){if(k())throw b(`The "${e}" prop expects a function, EventListenerObject, or descriptor ({ handler }) but received ${v(t)}.`)}},K=e=>{S=e?.mode,O(ye),H(Ee);};var G=e=>{let t=e.replace(/\r/g,"").replace(/\n\s+/g," "),n=e.match(/^\s*/)?.[0]??"",r=e.match(/\s*$/)?.[0]??"",s=/\n/.test(n),o=/\n/.test(r),a=t;return s&&(a=a.replace(/^\s+/,"")),o&&(a=a.replace(/\s+$/,"")),a.length===0||a.trim().length===0?null:a};var he="oxc-parser",be=e=>{let t=e.raw??e,n=t[0]??"",r=[];for(let s=0;s<t.length-1;s++){let o="${expr#"+s+"}",a=n.length;n+=o;let c=n.length;r.push({index:s,templateStart:a,templateEnd:c,label:o}),n+=t[s+1]??"";}return {source:n,spans:r}},Se=(e,t)=>{let n=new Map;return t.forEach(r=>{n.set(r.index,r);}),e.expressionRanges.map(r=>{let s=n.get(r.index);if(!s)return null;let o=Math.max(0,r.sourceEnd-r.sourceStart),a=Math.max(0,s.templateEnd-s.templateStart);return {sourceStart:r.sourceStart,sourceEnd:r.sourceEnd,templateStart:s.templateStart,templateEnd:s.templateEnd,delta:a-o}}).filter(r=>!!r).sort((r,s)=>r.sourceStart-s.sourceStart)},Je=(e,t,n)=>{if(!Number.isFinite(e)||e<=0)return 0;let r=0;for(let o of t){if(e<o.sourceStart)break;if(e<o.sourceEnd){let a=Math.max(0,e-o.sourceStart),c=Math.max(0,o.templateEnd-o.templateStart);if(c===0)return o.templateStart;let i=Math.min(a,Math.max(0,c-1));return o.templateStart+i}r+=o.delta;}let s=e+r;return s<=0?0:s>=n?n:s},Z=(e,t)=>{let n=Math.max(0,Math.min(t,e.length)),r=1,s=1;for(let o=0;o<n;o++){if(e.charCodeAt(o)===10){r++,s=1;continue}s++;}return {line:r,column:s}},Te=e=>{let t=[],n=0;return e.forEach((r,s)=>{t.push(n),n+=r.length,s<e.length-1&&(n+=1);}),t},we=(e,t,n,r,s,o,a)=>{let c=n+t.length,i=Math.max(r,n),p=Math.min(s,c);if(p>i){let l=Math.max(0,i-n),u=Math.max(1,p-i);return " ".repeat(l)+"^".repeat(u)}if(t.length===0&&e>=o&&e<=a)return "^";if(e===o){let l=Math.max(0,r-n);return " ".repeat(Math.min(l,t.length))+"^"}return ""},Ce=(e,t,n,r,s)=>{if(!e.length)return "";let o=e.split(`
2
+ `),a=Te(o),c=Math.max(1,r-1),i=Math.min(o.length,s+1),p=String(i).length,l=[];for(let u=c;u<=i;u++){let d=o[u-1]??"",m=String(u).padStart(p," ");l.push(`${m} | ${d}`);let g=we(u,d,a[u-1]??0,t,n,r,s);g&&l.push(`${" ".repeat(p)} | ${g}`);}return l.join(`
3
+ `)},A=(e,t,n,r,s)=>{let o=he,a=`[${o}] ${r.message}`,c=r.labels?.[0];if(!c)return a;let{source:i,spans:p}=be(t),l=Se(n,p),u=y=>Je(typeof y=="number"?y:0,l,i.length),d=u(c.start),m=u(c.end);m<=d&&(m=Math.min(i.length,d+1));let g=Z(i,d),x=Z(i,Math.max(d,m-1)),h=Ce(i,d,m,g.line,x.line),f=`[${o}] ${r.message}`;return f+=`
4
4
  --> ${e} template:${g.line}:${g.column}`,c.message&&(f+=`
5
5
  ${c.message}`),h&&(f+=`
6
6
  ${h}`),r.helpMessage&&(f+=`
7
- ${r.helpMessage}`),f};var Se=/<\s*$/,Te=/<\/\s*$/,G="__KX_EXPR__",K=new RegExp(`${G}\\d+_\\d+__`,"g"),we=0;var Z={lang:"jsx",sourceType:"module",range:true,preserveParens:true},q=e=>{for(let t of e.body)if(t.type==="ExpressionStatement"){let n=t.expression;if(n.type==="JSXElement"||n.type==="JSXFragment")return n}throw new Error("The jsx template must contain a single JSX element or fragment.")},T=e=>{switch(e.type){case "JSXIdentifier":return e.name;case "JSXNamespacedName":return `${e.namespace.name}:${e.name.name}`;case "JSXMemberExpression":return `${T(e.object)}.${e.property.name}`;default:return ""}},v=(e,t)=>{if(!e||typeof e!="object")return;let n=e;typeof n.type=="string"&&(t(n),Object.values(n).forEach(r=>{if(r){if(Array.isArray(r)){r.forEach(o=>v(o,t));return}typeof r=="object"&&v(r,t);}}));},Q=(e,t)=>{let n=z(e);if(!n)return [];let r=[];K.lastIndex=0;let o=0,s;for(;s=K.exec(n);){let c=s.index,i=n.slice(o,c);i&&r.push(i);let p=s[0];t.has(p)?r.push(t.get(p)):r.push(p),o=c+p.length;}let a=n.slice(o);return a&&r.push(a),r},Je=(e,t)=>{let n=new Set;return v(e,r=>{r.type==="Identifier"&&t.placeholders.has(r.name)&&n.add(r.name);}),Array.from(n)},Y=(e,t,n)=>{if(e.type==="JSXElement"||e.type==="JSXFragment")return n(e);if(!("range"in e)||!e.range)throw new Error("Unable to evaluate expression: missing source range information.");let[r,o]=e.range,s=t.source.slice(r,o),a=Je(e,t);try{let c=new Function(...a,`"use strict"; return (${s});`),i=a.map(p=>t.placeholders.get(p));return c(...i)}catch(c){throw new Error(`Failed to evaluate expression ${s}: ${c.message}`,{cause:c})}},Ce=e=>{let t=e.replace(/[^a-zA-Z0-9_$]/g,"");return t?/[A-Za-z_$]/.test(t[0])?t:`Component${t}`:"Component"},Ae=(e,t,n)=>{let r=n.get(e);if(r)return r;let o=e.displayName||e.name||`Component${t.length}`,s=Ce(o??""),a=s,c=1;for(;t.some(p=>p.name===a);)a=`${s}${c++}`;let i={name:a,value:e};return t.push(i),n.set(e,i),i},ee=(e,t)=>{let n=e.raw??e,r=new Map,o=[],s=new Map,a=n[0]??"",c=we++,i=0,p=[];for(let l=0;l<t.length;l++){let u=n[l]??"",d=n[l+1]??"",m=t[l],g=Se.test(u)||Te.test(u),x;if(g&&typeof m=="function")x=Ae(m,o,s).name;else if(g&&typeof m=="string")x=m;else {let y=`${G}${c}_${i++}__`;r.set(y,m),x=y;}let h=a.length;a+=x;let f=a.length;p.push({index:l,sourceStart:h,sourceEnd:f}),a+=d;}return {source:a,placeholders:r,bindings:o,diagnostics:{expressionRanges:p}}};var Xe=()=>{if(typeof document>"u"||typeof document.createElement!="function")throw new Error("The jsx template tag requires a DOM-like environment (document missing).")},Re=e=>typeof Node>"u"?false:e instanceof Node||e instanceof DocumentFragment,Me=e=>!e||typeof e=="string"?false:typeof e[Symbol.iterator]=="function",ne=e=>!e||typeof e!="object"&&typeof e!="function"?false:typeof e.then=="function",$e={xlink:"http://www.w3.org/1999/xlink",xml:"http://www.w3.org/XML/1998/namespace",xmlns:"http://www.w3.org/2000/xmlns/"},re=e=>{if(!(!e||e==="html"||e==="svg"))return $e[e]},Pe=e=>e==="svg"?svg:html,D=(e,t,n)=>{let r=re(t.space),o=String(n);if(r){e.setAttributeNS(r,t.attribute,o);return}e.setAttribute(t.attribute,o);},te=(e,t)=>{let n=re(t.space);if(n){e.removeAttributeNS(n,t.attribute);return}e.removeAttribute(t.attribute);},N=(e,t)=>Array.isArray(e)?e.filter(Boolean).join(t):e,je=(e,t,n)=>t==="svg"||!n.property||n.property.includes(":")?false:n.property in e,Ie=(e,t,n,r)=>{if(n==null)return;if(t==="dangerouslySetInnerHTML"&&typeof n=="object"&&n&&"__html"in n){e.innerHTML=String(n.__html??"");return}if(t==="ref"){if(typeof n=="function"){n(e);return}if(n&&typeof n=="object"){n.current=e;return}}if(t==="style"&&typeof n=="object"&&n!==null){let p=n,l=e.style;if(!l)return;let u=l;Object.entries(p).forEach(([d,m])=>{if(m!=null){if(d.startsWith("--")){l.setProperty(d,String(m));return}u[d]=m;}});return}let o=_(t);if(o){let p=F(t,n);if(p){let l=p.options?{...p.options}:void 0;o.capture&&(l?l.capture=true:l={capture:true}),e.addEventListener(o.eventName,p.listener,l);return}}let s=find(Pe(r),t),a=e,c=je(e,r,s);if(s.mustUseProperty){let p=s.boolean?!!n:n;a[s.property]=p;return}if(s.boolean){let p=!!n;c&&(a[s.property]=p),p?D(e,s,""):te(e,s);return}let i=n;if(s.spaceSeparated?i=N(n," "):s.commaSeparated?i=N(n,","):s.commaOrSpaceSeparated&&(i=N(n," ")),s.booleanish&&typeof i=="boolean"&&(i=i?"true":"false"),s.overloadedBoolean){if(i===false){te(e,s);return}if(i===true){D(e,s,"");return}}if(c){a[s.property]=i;return}i!==false&&D(e,s,i);},E=(e,t)=>{if(t!=null&&typeof t!="boolean"){if(ne(t))throw new Error("Async values are not supported inside jsx template results.");if(Array.isArray(t)){t.forEach(n=>E(e,n));return}if(Me(t)){for(let n of t)E(e,n);return}if(Re(t)){e.appendChild(t);return}e.appendChild(document.createTextNode(String(t)));}},X=(e,t,n)=>Y(e,t,r=>M(r,t,n)),oe=P({getIdentifierName:T,evaluateExpressionWithNamespace:X}),Le=(e,t,n,r)=>{let o=oe(t,n,r);Object.entries(o).forEach(([s,a])=>{if(s!=="key"){if(s==="children"){E(e,a);return}Ie(e,s,a,r);}});},R=(e,t,n)=>{let r=[];return e.forEach(o=>{switch(o.type){case "JSXText":{Q(o.value,t.placeholders).forEach(a=>{r.push(a);});break}case "JSXExpressionContainer":{if(o.expression.type==="JSXEmptyExpression")break;r.push(X(o.expression,t,n));break}case "JSXSpreadChild":{let s=X(o.expression,t,n);s!=null&&r.push(s);break}case "JSXElement":case "JSXFragment":{r.push(M(o,t,n));break}}}),r},Oe=(e,t,n,r)=>{let o=oe(e.openingElement.attributes,t,r),s=R(e.children,t,r);s.length===1?o.children=s[0]:s.length>1&&(o.children=s);let a=n(o);if(ne(a))throw new Error("Async jsx components are not supported.");return a},_e=(e,t,n)=>{let r=e.openingElement,o=T(r.name),s=t.components.get(o);if(s)return Oe(e,t,s,n);if(/[A-Z]/.test(o[0]??""))throw new Error(`Unknown component "${o}". Did you interpolate it with the template literal?`);let a=o==="svg"?"svg":n,c=o==="foreignObject"?null:a,i=a==="svg"?document.createElementNS("http://www.w3.org/2000/svg",o):document.createElement(o);return Le(i,r.attributes,t,a),R(e.children,t,c).forEach(l=>E(i,l)),i},M=(e,t,n)=>{if(e.type==="JSXFragment"){let r=document.createDocumentFragment();return R(e.children,t,n).forEach(s=>E(r,s)),r}return _e(e,t,n)},He=(e,...t)=>{Xe();let n=ee(e,t),r=parseSync("inline.jsx",n.source,Z);if(r.errors.length>0)throw new Error(k("jsx",e,n.diagnostics,r.errors[0]));let o=q(r.program),s={source:n.source,placeholders:n.placeholders,components:new Map(n.bindings.map(a=>[a.name,a.value]))};return M(o,s,null)};V({mode:"always"});
8
- export{He as jsx};
7
+ ${r.helpMessage}`),f};var ve=/<\s*$/,ke=/<\/\s*$/,Q="__KX_EXPR__",q=new RegExp(`${Q}\\d+_\\d+__`,"g"),Ae=0;var Y={lang:"jsx",sourceType:"module",range:true,preserveParens:true},ee=e=>{for(let t of e.body)if(t.type==="ExpressionStatement"){let n=t.expression;if(n.type==="JSXElement"||n.type==="JSXFragment")return n}throw new Error("The jsx template must contain a single JSX element or fragment.")},J=e=>{switch(e.type){case "JSXIdentifier":return e.name;case "JSXNamespacedName":return `${e.namespace.name}:${e.name.name}`;case "JSXMemberExpression":return `${J(e.object)}.${e.property.name}`;default:return ""}},R=(e,t)=>{if(!e||typeof e!="object")return;let n=e;typeof n.type=="string"&&(t(n),Object.values(n).forEach(r=>{if(r){if(Array.isArray(r)){r.forEach(s=>R(s,t));return}typeof r=="object"&&R(r,t);}}));},te=(e,t)=>{let n=G(e);if(!n)return [];let r=[];q.lastIndex=0;let s=0,o;for(;o=q.exec(n);){let c=o.index,i=n.slice(s,c);i&&r.push(i);let p=o[0];t.has(p)?r.push(t.get(p)):r.push(p),s=c+p.length;}let a=n.slice(s);return a&&r.push(a),r},Re=(e,t)=>{let n=new Set;return R(e,r=>{r.type==="Identifier"&&t.placeholders.has(r.name)&&n.add(r.name);}),Array.from(n)},ne=(e,t,n)=>{if(e.type==="JSXElement"||e.type==="JSXFragment")return n(e);if(!("range"in e)||!e.range)throw new Error("Unable to evaluate expression: missing source range information.");let[r,s]=e.range,o=t.source.slice(r,s),a=Re(e,t);try{let c=new Function(...a,`"use strict"; return (${o});`),i=a.map(p=>t.placeholders.get(p));return c(...i)}catch(c){throw new Error(`Failed to evaluate expression ${o}: ${c.message}`,{cause:c})}},De=e=>{let t=e.replace(/[^a-zA-Z0-9_$]/g,"");return t?/[A-Za-z_$]/.test(t[0])?t:`Component${t}`:"Component"},Ne=(e,t,n)=>{let r=n.get(e);if(r)return r;let s=e.displayName||e.name||`Component${t.length}`,o=De(s??""),a=o,c=1;for(;t.some(p=>p.name===a);)a=`${o}${c++}`;let i={name:a,value:e};return t.push(i),n.set(e,i),i},re=(e,t)=>{let n=e.raw??e,r=new Map,s=[],o=new Map,a=n[0]??"",c=Ae++,i=0,p=[];for(let l=0;l<t.length;l++){let u=n[l]??"",d=n[l+1]??"",m=t[l],g=ve.test(u)||ke.test(u),x;if(g&&typeof m=="function")x=Ne(m,s,o).name;else if(g&&typeof m=="string")x=m;else {let y=`${Q}${c}_${i++}__`;r.set(y,m),x=y;}let h=a.length;a+=x;let f=a.length;p.push({index:l,sourceStart:h,sourceEnd:f}),a+=d;}return {source:a,placeholders:r,bindings:s,diagnostics:{expressionRanges:p}}};var D=Symbol.for("@knighted/jsx::Fragment"),T="__jsxNs",Pe=(e,t)=>t.length>0?t:Object.prototype.hasOwnProperty.call(e,"children")?[e.children]:[],je=(e,t)=>{let n={...e};return t.length===1?n.children=t[0]:t.length>1?n.children=t:delete n.children,n},Xe=e=>{if(!Object.prototype.hasOwnProperty.call(e,T))return;let t=e[T];if(delete e[T],t==="svg"||t===null)return t;throw new Error(`${T} must be "svg" or null when provided.`)},oe=({ensureDomAvailable:e,appendChildValue:t,setDomProp:n,isPromiseLike:r})=>{function s(o,a,...c){e();let i=a?{...a}:{},p=Pe(i,c);if(o===D){let m=document.createDocumentFragment();return p.forEach(g=>t(m,g)),m}if(typeof o=="function"){let m=o(je(i,p));if(r(m))throw new Error("Async jsx components are not supported.");return m}if(typeof o!="string")throw new Error(`Unsupported jsx createElement type: ${String(o)}`);delete i.children;let u=Xe(i)??(o==="svg"?"svg":null),d=u==="svg"?document.createElementNS("http://www.w3.org/2000/svg",o):document.createElement(o);return Object.entries(i).forEach(([m,g])=>{m!=="key"&&n(d,m,g,u);}),p.forEach(m=>t(d,m)),d}return s};var ae=()=>{if(typeof document>"u"||typeof document.createElement!="function")throw new Error("The jsx template tag requires a DOM-like environment (document missing).")},Le=e=>typeof Node>"u"?false:e instanceof Node||e instanceof DocumentFragment,Ie=e=>!e||typeof e=="string"?false:typeof e[Symbol.iterator]=="function",X=e=>!e||typeof e!="object"&&typeof e!="function"?false:typeof e.then=="function",_e={xlink:"http://www.w3.org/1999/xlink",xml:"http://www.w3.org/XML/1998/namespace",xmlns:"http://www.w3.org/2000/xmlns/"},ie=e=>{if(!(!e||e==="html"||e==="svg"))return _e[e]},He=e=>e==="svg"?svg:html,N=(e,t,n)=>{let r=ie(t.space),s=String(n);if(r){e.setAttributeNS(r,t.attribute,s);return}e.setAttribute(t.attribute,s);},se=(e,t)=>{let n=ie(t.space);if(n){e.removeAttributeNS(n,t.attribute);return}e.removeAttribute(t.attribute);},P=(e,t)=>Array.isArray(e)?e.filter(Boolean).join(t):e,Be=(e,t,n)=>t==="svg"||!n.property||n.property.includes(":")?false:n.property in e,pe=(e,t,n,r)=>{if(n==null)return;if(t==="dangerouslySetInnerHTML"&&typeof n=="object"&&n&&"__html"in n){e.innerHTML=String(n.__html??"");return}if(t==="ref"){if(typeof n=="function"){n(e);return}if(n&&typeof n=="object"){n.current=e;return}}if(t==="style"&&typeof n=="object"&&n!==null){let p=n,l=e.style;if(!l)return;let u=l;Object.entries(p).forEach(([d,m])=>{if(m!=null){if(d.startsWith("--")){l.setProperty(d,String(m));return}u[d]=m;}});return}let s=B(t);if(s){let p=V(t,n);if(p){let l=p.options?{...p.options}:void 0;s.capture&&(l?l.capture=true:l={capture:true}),e.addEventListener(s.eventName,p.listener,l);return}}let o=find(He(r),t),a=e,c=Be(e,r,o);if(o.mustUseProperty){let p=o.boolean?!!n:n;a[o.property]=p;return}if(o.boolean){let p=!!n;c&&(a[o.property]=p),p?N(e,o,""):se(e,o);return}let i=n;if(o.spaceSeparated?i=P(n," "):o.commaSeparated?i=P(n,","):o.commaOrSpaceSeparated&&(i=P(n," ")),o.booleanish&&typeof i=="boolean"&&(i=i?"true":"false"),o.overloadedBoolean){if(i===false){se(e,o);return}if(i===true){N(e,o,"");return}}if(c){a[o.property]=i;return}i!==false&&N(e,o,i);},E=(e,t)=>{if(t!=null&&typeof t!="boolean"){if(X(t))throw new Error("Async values are not supported inside jsx template results.");if(Array.isArray(t)){t.forEach(n=>E(e,n));return}if(Ie(t)){for(let n of t)E(e,n);return}if(Le(t)){e.appendChild(t);return}e.appendChild(document.createTextNode(String(t)));}},j=(e,t,n)=>ne(e,t,r=>$(r,t,n)),ce=F({getIdentifierName:J,evaluateExpressionWithNamespace:j}),We=(e,t,n,r)=>{let s=ce(t,n,r);Object.entries(s).forEach(([o,a])=>{if(o!=="key"){if(o==="children"){E(e,a);return}pe(e,o,a,r);}});},M=(e,t,n)=>{let r=[];return e.forEach(s=>{switch(s.type){case "JSXText":{te(s.value,t.placeholders).forEach(a=>{r.push(a);});break}case "JSXExpressionContainer":{if(s.expression.type==="JSXEmptyExpression")break;r.push(j(s.expression,t,n));break}case "JSXSpreadChild":{let o=j(s.expression,t,n);o!=null&&r.push(o);break}case "JSXElement":case "JSXFragment":{r.push($(s,t,n));break}}}),r},Ve=(e,t,n,r)=>{let s=ce(e.openingElement.attributes,t,r),o=M(e.children,t,r);o.length===1?s.children=o[0]:o.length>1&&(s.children=o);let a=n(s);if(X(a))throw new Error("Async jsx components are not supported.");return a},Ue=(e,t,n)=>{let r=e.openingElement,s=J(r.name),o=t.components.get(s);if(o)return Ve(e,t,o,n);if(/[A-Z]/.test(s[0]??""))throw new Error(`Unknown component "${s}". Did you interpolate it with the template literal?`);let a=s==="svg"?"svg":n,c=s==="foreignObject"?null:a,i=a==="svg"?document.createElementNS("http://www.w3.org/2000/svg",s):document.createElement(s);return We(i,r.attributes,t,a),M(e.children,t,c).forEach(l=>E(i,l)),i},$=(e,t,n)=>{if(e.type==="JSXFragment"){let r=document.createDocumentFragment();return M(e.children,t,n).forEach(o=>E(r,o)),r}return Ue(e,t,n)},ze=oe({ensureDomAvailable:ae,appendChildValue:E,setDomProp:pe,isPromiseLike:X}),Ke=(e,...t)=>{ae();let n=re(e,t),r=parseSync("inline.jsx",n.source,Y);if(r.errors.length>0)throw new Error(A("jsx",e,n.diagnostics,r.errors[0]));let s=ee(r.program),o={source:n.source,placeholders:n.placeholders,components:new Map(n.bindings.map(a=>[a.name,a.value]))};return $(s,o,null)},Ge=Object.assign(Ke,{createElement:ze,Fragment:D});K({mode:"always"});
8
+ export{Ge as jsx};
@@ -1,8 +1,8 @@
1
- import {parseSync}from'oxc-parser';import {find,svg,html}from'property-information';var N=e=>{let n=e.replace(/\r/g,"").replace(/\n\s+/g," "),t=e.match(/^\s*/)?.[0]??"",r=e.match(/\s*$/)?.[0]??"",o=/\n/.test(t),s=/\n/.test(r),a=n;return o&&(a=a.replace(/^\s+/,"")),s&&(a=a.replace(/\s+$/,"")),a.length===0||a.trim().length===0?null:a};var K="oxc-parser",Z=e=>{let n=e.raw??e,t=n[0]??"",r=[];for(let o=0;o<n.length-1;o++){let s="${expr#"+o+"}",a=t.length;t+=s;let c=t.length;r.push({index:o,templateStart:a,templateEnd:c,label:s}),t+=n[o+1]??"";}return {source:t,spans:r}},G=(e,n)=>{let t=new Map;return n.forEach(r=>{t.set(r.index,r);}),e.expressionRanges.map(r=>{let o=t.get(r.index);if(!o)return null;let s=Math.max(0,r.sourceEnd-r.sourceStart),a=Math.max(0,o.templateEnd-o.templateStart);return {sourceStart:r.sourceStart,sourceEnd:r.sourceEnd,templateStart:o.templateStart,templateEnd:o.templateEnd,delta:a-s}}).filter(r=>!!r).sort((r,o)=>r.sourceStart-o.sourceStart)},q=(e,n,t)=>{if(!Number.isFinite(e)||e<=0)return 0;let r=0;for(let s of n){if(e<s.sourceStart)break;if(e<s.sourceEnd){let a=Math.max(0,e-s.sourceStart),c=Math.max(0,s.templateEnd-s.templateStart);if(c===0)return s.templateStart;let i=Math.min(a,Math.max(0,c-1));return s.templateStart+i}r+=s.delta;}let o=e+r;return o<=0?0:o>=t?t:o},v=(e,n)=>{let t=Math.max(0,Math.min(n,e.length)),r=1,o=1;for(let s=0;s<t;s++){if(e.charCodeAt(s)===10){r++,o=1;continue}o++;}return {line:r,column:o}},Q=e=>{let n=[],t=0;return e.forEach((r,o)=>{n.push(t),t+=r.length,o<e.length-1&&(t+=1);}),n},Y=(e,n,t,r,o,s,a)=>{let c=t+n.length,i=Math.max(r,t),p=Math.min(o,c);if(p>i){let l=Math.max(0,i-t),u=Math.max(1,p-i);return " ".repeat(l)+"^".repeat(u)}if(n.length===0&&e>=s&&e<=a)return "^";if(e===s){let l=Math.max(0,r-t);return " ".repeat(Math.min(l,n.length))+"^"}return ""},ee=(e,n,t,r,o)=>{if(!e.length)return "";let s=e.split(`
2
- `),a=Q(s),c=Math.max(1,r-1),i=Math.min(s.length,o+1),p=String(i).length,l=[];for(let u=c;u<=i;u++){let d=s[u-1]??"",m=String(u).padStart(p," ");l.push(`${m} | ${d}`);let g=Y(u,d,a[u-1]??0,n,t,r,o);g&&l.push(`${" ".repeat(p)} | ${g}`);}return l.join(`
3
- `)},S=(e,n,t,r,o)=>{let s=K,a=`[${s}] ${r.message}`,c=r.labels?.[0];if(!c)return a;let{source:i,spans:p}=Z(n),l=G(t,p),u=y=>q(typeof y=="number"?y:0,l,i.length),d=u(c.start),m=u(c.end);m<=d&&(m=Math.min(i.length,d+1));let g=v(i,d),x=v(i,Math.max(d,m-1)),h=ee(i,d,m,g.line,x.line),f=`[${s}] ${r.message}`;return f+=`
4
- --> ${e} template:${g.line}:${g.column}`,c.message&&(f+=`
5
- ${c.message}`),h&&(f+=`
1
+ import {parseSync}from'oxc-parser';import {find,svg,html}from'property-information';var P=e=>{let t=e.replace(/\r/g,"").replace(/\n\s+/g," "),n=e.match(/^\s*/)?.[0]??"",r=e.match(/\s*$/)?.[0]??"",s=/\n/.test(n),o=/\n/.test(r),a=t;return s&&(a=a.replace(/^\s+/,"")),o&&(a=a.replace(/\s+$/,"")),a.length===0||a.trim().length===0?null:a};var Y="oxc-parser",ee=e=>{let t=e.raw??e,n=t[0]??"",r=[];for(let s=0;s<t.length-1;s++){let o="${expr#"+s+"}",a=n.length;n+=o;let l=n.length;r.push({index:s,templateStart:a,templateEnd:l,label:o}),n+=t[s+1]??"";}return {source:n,spans:r}},te=(e,t)=>{let n=new Map;return t.forEach(r=>{n.set(r.index,r);}),e.expressionRanges.map(r=>{let s=n.get(r.index);if(!s)return null;let o=Math.max(0,r.sourceEnd-r.sourceStart),a=Math.max(0,s.templateEnd-s.templateStart);return {sourceStart:r.sourceStart,sourceEnd:r.sourceEnd,templateStart:s.templateStart,templateEnd:s.templateEnd,delta:a-o}}).filter(r=>!!r).sort((r,s)=>r.sourceStart-s.sourceStart)},ne=(e,t,n)=>{if(!Number.isFinite(e)||e<=0)return 0;let r=0;for(let o of t){if(e<o.sourceStart)break;if(e<o.sourceEnd){let a=Math.max(0,e-o.sourceStart),l=Math.max(0,o.templateEnd-o.templateStart);if(l===0)return o.templateStart;let i=Math.min(a,Math.max(0,l-1));return o.templateStart+i}r+=o.delta;}let s=e+r;return s<=0?0:s>=n?n:s},X=(e,t)=>{let n=Math.max(0,Math.min(t,e.length)),r=1,s=1;for(let o=0;o<n;o++){if(e.charCodeAt(o)===10){r++,s=1;continue}s++;}return {line:r,column:s}},re=e=>{let t=[],n=0;return e.forEach((r,s)=>{t.push(n),n+=r.length,s<e.length-1&&(n+=1);}),t},oe=(e,t,n,r,s,o,a)=>{let l=n+t.length,i=Math.max(r,n),p=Math.min(s,l);if(p>i){let c=Math.max(0,i-n),u=Math.max(1,p-i);return " ".repeat(c)+"^".repeat(u)}if(t.length===0&&e>=o&&e<=a)return "^";if(e===o){let c=Math.max(0,r-n);return " ".repeat(Math.min(c,t.length))+"^"}return ""},se=(e,t,n,r,s)=>{if(!e.length)return "";let o=e.split(`
2
+ `),a=re(o),l=Math.max(1,r-1),i=Math.min(o.length,s+1),p=String(i).length,c=[];for(let u=l;u<=i;u++){let d=o[u-1]??"",m=String(u).padStart(p," ");c.push(`${m} | ${d}`);let g=oe(u,d,a[u-1]??0,t,n,r,s);g&&c.push(`${" ".repeat(p)} | ${g}`);}return c.join(`
3
+ `)},J=(e,t,n,r,s)=>{let o=Y,a=`[${o}] ${r.message}`,l=r.labels?.[0];if(!l)return a;let{source:i,spans:p}=ee(t),c=te(n,p),u=E=>ne(typeof E=="number"?E:0,c,i.length),d=u(l.start),m=u(l.end);m<=d&&(m=Math.min(i.length,d+1));let g=X(i,d),x=X(i,Math.max(d,m-1)),h=se(i,d,m,g.line,x.line),f=`[${o}] ${r.message}`;return f+=`
4
+ --> ${e} template:${g.line}:${g.column}`,l.message&&(f+=`
5
+ ${l.message}`),h&&(f+=`
6
6
  ${h}`),r.helpMessage&&(f+=`
7
- ${r.helpMessage}`),f};var te=/<\s*$/,ne=/<\/\s*$/,R="__KX_EXPR__",X=new RegExp(`${R}\\d+_\\d+__`,"g"),re=0;var P={lang:"jsx",sourceType:"module",range:true,preserveParens:true},M=e=>{for(let n of e.body)if(n.type==="ExpressionStatement"){let t=n.expression;if(t.type==="JSXElement"||t.type==="JSXFragment")return t}throw new Error("The jsx template must contain a single JSX element or fragment.")},b=e=>{switch(e.type){case "JSXIdentifier":return e.name;case "JSXNamespacedName":return `${e.namespace.name}:${e.name.name}`;case "JSXMemberExpression":return `${b(e.object)}.${e.property.name}`;default:return ""}},T=(e,n)=>{if(!e||typeof e!="object")return;let t=e;typeof t.type=="string"&&(n(t),Object.values(t).forEach(r=>{if(r){if(Array.isArray(r)){r.forEach(o=>T(o,n));return}typeof r=="object"&&T(r,n);}}));},D=(e,n)=>{let t=N(e);if(!t)return [];let r=[];X.lastIndex=0;let o=0,s;for(;s=X.exec(t);){let c=s.index,i=t.slice(o,c);i&&r.push(i);let p=s[0];n.has(p)?r.push(n.get(p)):r.push(p),o=c+p.length;}let a=t.slice(o);return a&&r.push(a),r},oe=(e,n)=>{let t=new Set;return T(e,r=>{r.type==="Identifier"&&n.placeholders.has(r.name)&&t.add(r.name);}),Array.from(t)},I=(e,n,t)=>{if(e.type==="JSXElement"||e.type==="JSXFragment")return t(e);if(!("range"in e)||!e.range)throw new Error("Unable to evaluate expression: missing source range information.");let[r,o]=e.range,s=n.source.slice(r,o),a=oe(e,n);try{let c=new Function(...a,`"use strict"; return (${s});`),i=a.map(p=>n.placeholders.get(p));return c(...i)}catch(c){throw new Error(`Failed to evaluate expression ${s}: ${c.message}`,{cause:c})}},se=e=>{let n=e.replace(/[^a-zA-Z0-9_$]/g,"");return n?/[A-Za-z_$]/.test(n[0])?n:`Component${n}`:"Component"},ae=(e,n,t)=>{let r=t.get(e);if(r)return r;let o=e.displayName||e.name||`Component${n.length}`,s=se(o??""),a=s,c=1;for(;n.some(p=>p.name===a);)a=`${s}${c++}`;let i={name:a,value:e};return n.push(i),t.set(e,i),i},L=(e,n)=>{let t=e.raw??e,r=new Map,o=[],s=new Map,a=t[0]??"",c=re++,i=0,p=[];for(let l=0;l<n.length;l++){let u=t[l]??"",d=t[l+1]??"",m=n[l],g=te.test(u)||ne.test(u),x;if(g&&typeof m=="function")x=ae(m,o,s).name;else if(g&&typeof m=="string")x=m;else {let y=`${R}${c}_${i++}__`;r.set(y,m),x=y;}let h=a.length;a+=x;let f=a.length;p.push({index:l,sourceStart:h,sourceEnd:f}),a+=d;}return {source:a,placeholders:r,bindings:o,diagnostics:{expressionRanges:p}}};var $=e=>{let{getIdentifierName:n,evaluateExpressionWithNamespace:t}=e;return (r,o,s)=>{let a={},c=(i,p)=>{a[i]=p;};return r.forEach(i=>{if(i.type==="JSXSpreadAttribute"){let l=t(i.argument,o,s);l&&typeof l=="object"&&!Array.isArray(l)&&Object.assign(a,l);return}let p=n(i.name);if(!i.value){c(p,true);return}if(i.value.type==="Literal"){c(p,i.value.value);return}if(i.value.type==="JSXExpressionContainer"){if(i.value.expression.type==="JSXEmptyExpression")return;c(p,t(i.value.expression,o,s));}}),a}};var O="Capture",F=e=>e.endsWith(O)?{eventName:e.slice(0,-O.length),capture:true}:{eventName:e,capture:false},_=e=>{if(!e.startsWith("on"))return null;if(e.startsWith("on:")){let r=e.slice(3);if(!r)return null;let o=F(r);return o.eventName?o:null}let n=e.slice(2);if(!n)return null;let t=F(n);return t.eventName?{eventName:t.eventName.toLowerCase(),capture:t.capture}:null},H=e=>!e||typeof e!="object"?false:"handleEvent"in e&&typeof e.handleEvent=="function",le=e=>{if(!e||typeof e!="object"||!("handler"in e))return false;let n=e.handler;return typeof n=="function"?true:H(n)},B=(e,n)=>{if(typeof n=="function"||H(n))return {listener:n};if(!le(n))return null;let t=n,r=t.options?{...t.options}:void 0,o=(s,a)=>{a!=null&&(r||(r={}),r[s]=a);};return o("capture",t.capture),o("once",t.once),o("passive",t.passive),o("signal",t.signal??void 0),{listener:t.handler,options:r}};var xe=()=>{if(typeof document>"u"||typeof document.createElement!="function")throw new Error("The jsx template tag requires a DOM-like environment (document missing).")},ye=e=>typeof Node>"u"?false:e instanceof Node||e instanceof DocumentFragment,Ee=e=>!e||typeof e=="string"?false:typeof e[Symbol.iterator]=="function",V=e=>!e||typeof e!="object"&&typeof e!="function"?false:typeof e.then=="function",he={xlink:"http://www.w3.org/1999/xlink",xml:"http://www.w3.org/XML/1998/namespace",xmlns:"http://www.w3.org/2000/xmlns/"},z=e=>{if(!(!e||e==="html"||e==="svg"))return he[e]},be=e=>e==="svg"?svg:html,w=(e,n,t)=>{let r=z(n.space),o=String(t);if(r){e.setAttributeNS(r,n.attribute,o);return}e.setAttribute(n.attribute,o);},W=(e,n)=>{let t=z(n.space);if(t){e.removeAttributeNS(t,n.attribute);return}e.removeAttribute(n.attribute);},C=(e,n)=>Array.isArray(e)?e.filter(Boolean).join(n):e,Se=(e,n,t)=>n==="svg"||!t.property||t.property.includes(":")?false:t.property in e,Te=(e,n,t,r)=>{if(t==null)return;if(n==="dangerouslySetInnerHTML"&&typeof t=="object"&&t&&"__html"in t){e.innerHTML=String(t.__html??"");return}if(n==="ref"){if(typeof t=="function"){t(e);return}if(t&&typeof t=="object"){t.current=e;return}}if(n==="style"&&typeof t=="object"&&t!==null){let p=t,l=e.style;if(!l)return;let u=l;Object.entries(p).forEach(([d,m])=>{if(m!=null){if(d.startsWith("--")){l.setProperty(d,String(m));return}u[d]=m;}});return}let o=_(n);if(o){let p=B(n,t);if(p){let l=p.options?{...p.options}:void 0;o.capture&&(l?l.capture=true:l={capture:true}),e.addEventListener(o.eventName,p.listener,l);return}}let s=find(be(r),n),a=e,c=Se(e,r,s);if(s.mustUseProperty){let p=s.boolean?!!t:t;a[s.property]=p;return}if(s.boolean){let p=!!t;c&&(a[s.property]=p),p?w(e,s,""):W(e,s);return}let i=t;if(s.spaceSeparated?i=C(t," "):s.commaSeparated?i=C(t,","):s.commaOrSpaceSeparated&&(i=C(t," ")),s.booleanish&&typeof i=="boolean"&&(i=i?"true":"false"),s.overloadedBoolean){if(i===false){W(e,s);return}if(i===true){w(e,s,"");return}}if(c){a[s.property]=i;return}i!==false&&w(e,s,i);},E=(e,n)=>{if(n!=null&&typeof n!="boolean"){if(V(n))throw new Error("Async values are not supported inside jsx template results.");if(Array.isArray(n)){n.forEach(t=>E(e,t));return}if(Ee(n)){for(let t of n)E(e,t);return}if(ye(n)){e.appendChild(n);return}e.appendChild(document.createTextNode(String(n)));}},J=(e,n,t)=>I(e,n,r=>k(r,n,t)),U=$({getIdentifierName:b,evaluateExpressionWithNamespace:J}),we=(e,n,t,r)=>{let o=U(n,t,r);Object.entries(o).forEach(([s,a])=>{if(s!=="key"){if(s==="children"){E(e,a);return}Te(e,s,a,r);}});},A=(e,n,t)=>{let r=[];return e.forEach(o=>{switch(o.type){case "JSXText":{D(o.value,n.placeholders).forEach(a=>{r.push(a);});break}case "JSXExpressionContainer":{if(o.expression.type==="JSXEmptyExpression")break;r.push(J(o.expression,n,t));break}case "JSXSpreadChild":{let s=J(o.expression,n,t);s!=null&&r.push(s);break}case "JSXElement":case "JSXFragment":{r.push(k(o,n,t));break}}}),r},Ce=(e,n,t,r)=>{let o=U(e.openingElement.attributes,n,r),s=A(e.children,n,r);s.length===1?o.children=s[0]:s.length>1&&(o.children=s);let a=t(o);if(V(a))throw new Error("Async jsx components are not supported.");return a},Je=(e,n,t)=>{let r=e.openingElement,o=b(r.name),s=n.components.get(o);if(s)return Ce(e,n,s,t);if(/[A-Z]/.test(o[0]??""))throw new Error(`Unknown component "${o}". Did you interpolate it with the template literal?`);let a=o==="svg"?"svg":t,c=o==="foreignObject"?null:a,i=a==="svg"?document.createElementNS("http://www.w3.org/2000/svg",o):document.createElement(o);return we(i,r.attributes,n,a),A(e.children,n,c).forEach(l=>E(i,l)),i},k=(e,n,t)=>{if(e.type==="JSXFragment"){let r=document.createDocumentFragment();return A(e.children,n,t).forEach(s=>E(r,s)),r}return Je(e,n,t)},Ae=(e,...n)=>{xe();let t=L(e,n),r=parseSync("inline.jsx",t.source,P);if(r.errors.length>0)throw new Error(S("jsx",e,t.diagnostics,r.errors[0]));let o=M(r.program),s={source:t.source,placeholders:t.placeholders,components:new Map(t.bindings.map(a=>[a.name,a.value]))};return k(o,s,null)};
8
- export{Ae as jsx};
7
+ ${r.helpMessage}`),f};var ae=/<\s*$/,ie=/<\/\s*$/,D="__KX_EXPR__",j=new RegExp(`${D}\\d+_\\d+__`,"g"),pe=0;var F={lang:"jsx",sourceType:"module",range:true,preserveParens:true},M=e=>{for(let t of e.body)if(t.type==="ExpressionStatement"){let n=t.expression;if(n.type==="JSXElement"||n.type==="JSXFragment")return n}throw new Error("The jsx template must contain a single JSX element or fragment.")},b=e=>{switch(e.type){case "JSXIdentifier":return e.name;case "JSXNamespacedName":return `${e.namespace.name}:${e.name.name}`;case "JSXMemberExpression":return `${b(e.object)}.${e.property.name}`;default:return ""}},T=(e,t)=>{if(!e||typeof e!="object")return;let n=e;typeof n.type=="string"&&(t(n),Object.values(n).forEach(r=>{if(r){if(Array.isArray(r)){r.forEach(s=>T(s,t));return}typeof r=="object"&&T(r,t);}}));},O=(e,t)=>{let n=P(e);if(!n)return [];let r=[];j.lastIndex=0;let s=0,o;for(;o=j.exec(n);){let l=o.index,i=n.slice(s,l);i&&r.push(i);let p=o[0];t.has(p)?r.push(t.get(p)):r.push(p),s=l+p.length;}let a=n.slice(s);return a&&r.push(a),r},le=(e,t)=>{let n=new Set;return T(e,r=>{r.type==="Identifier"&&t.placeholders.has(r.name)&&n.add(r.name);}),Array.from(n)},L=(e,t,n)=>{if(e.type==="JSXElement"||e.type==="JSXFragment")return n(e);if(!("range"in e)||!e.range)throw new Error("Unable to evaluate expression: missing source range information.");let[r,s]=e.range,o=t.source.slice(r,s),a=le(e,t);try{let l=new Function(...a,`"use strict"; return (${o});`),i=a.map(p=>t.placeholders.get(p));return l(...i)}catch(l){throw new Error(`Failed to evaluate expression ${o}: ${l.message}`,{cause:l})}},ce=e=>{let t=e.replace(/[^a-zA-Z0-9_$]/g,"");return t?/[A-Za-z_$]/.test(t[0])?t:`Component${t}`:"Component"},me=(e,t,n)=>{let r=n.get(e);if(r)return r;let s=e.displayName||e.name||`Component${t.length}`,o=ce(s??""),a=o,l=1;for(;t.some(p=>p.name===a);)a=`${o}${l++}`;let i={name:a,value:e};return t.push(i),n.set(e,i),i},$=(e,t)=>{let n=e.raw??e,r=new Map,s=[],o=new Map,a=n[0]??"",l=pe++,i=0,p=[];for(let c=0;c<t.length;c++){let u=n[c]??"",d=n[c+1]??"",m=t[c],g=ae.test(u)||ie.test(u),x;if(g&&typeof m=="function")x=me(m,s,o).name;else if(g&&typeof m=="string")x=m;else {let E=`${D}${l}_${i++}__`;r.set(E,m),x=E;}let h=a.length;a+=x;let f=a.length;p.push({index:c,sourceStart:h,sourceEnd:f}),a+=d;}return {source:a,placeholders:r,bindings:s,diagnostics:{expressionRanges:p}}};var _=e=>{let{getIdentifierName:t,evaluateExpressionWithNamespace:n}=e;return (r,s,o)=>{let a={},l=(i,p)=>{a[i]=p;};return r.forEach(i=>{if(i.type==="JSXSpreadAttribute"){let c=n(i.argument,s,o);c&&typeof c=="object"&&!Array.isArray(c)&&Object.assign(a,c);return}let p=t(i.name);if(!i.value){l(p,true);return}if(i.value.type==="Literal"){l(p,i.value.value);return}if(i.value.type==="JSXExpressionContainer"){if(i.value.expression.type==="JSXEmptyExpression")return;l(p,n(i.value.expression,s,o));}}),a}};var H="Capture",B=e=>e.endsWith(H)?{eventName:e.slice(0,-H.length),capture:true}:{eventName:e,capture:false},W=e=>{if(!e.startsWith("on"))return null;if(e.startsWith("on:")){let r=e.slice(3);if(!r)return null;let s=B(r);return s.eventName?s:null}let t=e.slice(2);if(!t)return null;let n=B(t);return n.eventName?{eventName:n.eventName.toLowerCase(),capture:n.capture}:null},V=e=>!e||typeof e!="object"?false:"handleEvent"in e&&typeof e.handleEvent=="function",fe=e=>{if(!e||typeof e!="object"||!("handler"in e))return false;let t=e.handler;return typeof t=="function"?true:V(t)},z=(e,t)=>{if(typeof t=="function"||V(t))return {listener:t};if(!fe(t))return null;let n=t,r=n.options?{...n.options}:void 0,s=(o,a)=>{a!=null&&(r||(r={}),r[o]=a);};return s("capture",n.capture),s("once",n.once),s("passive",n.passive),s("signal",n.signal??void 0),{listener:n.handler,options:r}};var w=Symbol.for("@knighted/jsx::Fragment"),S="__jsxNs",Ee=(e,t)=>t.length>0?t:Object.prototype.hasOwnProperty.call(e,"children")?[e.children]:[],ye=(e,t)=>{let n={...e};return t.length===1?n.children=t[0]:t.length>1?n.children=t:delete n.children,n},he=e=>{if(!Object.prototype.hasOwnProperty.call(e,S))return;let t=e[S];if(delete e[S],t==="svg"||t===null)return t;throw new Error(`${S} must be "svg" or null when provided.`)},U=({ensureDomAvailable:e,appendChildValue:t,setDomProp:n,isPromiseLike:r})=>{function s(o,a,...l){e();let i=a?{...a}:{},p=Ee(i,l);if(o===w){let m=document.createDocumentFragment();return p.forEach(g=>t(m,g)),m}if(typeof o=="function"){let m=o(ye(i,p));if(r(m))throw new Error("Async jsx components are not supported.");return m}if(typeof o!="string")throw new Error(`Unsupported jsx createElement type: ${String(o)}`);delete i.children;let u=he(i)??(o==="svg"?"svg":null),d=u==="svg"?document.createElementNS("http://www.w3.org/2000/svg",o):document.createElement(o);return Object.entries(i).forEach(([m,g])=>{m!=="key"&&n(d,m,g,u);}),p.forEach(m=>t(d,m)),d}return s};var Z=()=>{if(typeof document>"u"||typeof document.createElement!="function")throw new Error("The jsx template tag requires a DOM-like environment (document missing).")},we=e=>typeof Node>"u"?false:e instanceof Node||e instanceof DocumentFragment,Ce=e=>!e||typeof e=="string"?false:typeof e[Symbol.iterator]=="function",R=e=>!e||typeof e!="object"&&typeof e!="function"?false:typeof e.then=="function",ke={xlink:"http://www.w3.org/1999/xlink",xml:"http://www.w3.org/XML/1998/namespace",xmlns:"http://www.w3.org/2000/xmlns/"},q=e=>{if(!(!e||e==="html"||e==="svg"))return ke[e]},ve=e=>e==="svg"?svg:html,C=(e,t,n)=>{let r=q(t.space),s=String(n);if(r){e.setAttributeNS(r,t.attribute,s);return}e.setAttribute(t.attribute,s);},K=(e,t)=>{let n=q(t.space);if(n){e.removeAttributeNS(n,t.attribute);return}e.removeAttribute(t.attribute);},k=(e,t)=>Array.isArray(e)?e.filter(Boolean).join(t):e,Re=(e,t,n)=>t==="svg"||!n.property||n.property.includes(":")?false:n.property in e,G=(e,t,n,r)=>{if(n==null)return;if(t==="dangerouslySetInnerHTML"&&typeof n=="object"&&n&&"__html"in n){e.innerHTML=String(n.__html??"");return}if(t==="ref"){if(typeof n=="function"){n(e);return}if(n&&typeof n=="object"){n.current=e;return}}if(t==="style"&&typeof n=="object"&&n!==null){let p=n,c=e.style;if(!c)return;let u=c;Object.entries(p).forEach(([d,m])=>{if(m!=null){if(d.startsWith("--")){c.setProperty(d,String(m));return}u[d]=m;}});return}let s=W(t);if(s){let p=z(t,n);if(p){let c=p.options?{...p.options}:void 0;s.capture&&(c?c.capture=true:c={capture:true}),e.addEventListener(s.eventName,p.listener,c);return}}let o=find(ve(r),t),a=e,l=Re(e,r,o);if(o.mustUseProperty){let p=o.boolean?!!n:n;a[o.property]=p;return}if(o.boolean){let p=!!n;l&&(a[o.property]=p),p?C(e,o,""):K(e,o);return}let i=n;if(o.spaceSeparated?i=k(n," "):o.commaSeparated?i=k(n,","):o.commaOrSpaceSeparated&&(i=k(n," ")),o.booleanish&&typeof i=="boolean"&&(i=i?"true":"false"),o.overloadedBoolean){if(i===false){K(e,o);return}if(i===true){C(e,o,"");return}}if(l){a[o.property]=i;return}i!==false&&C(e,o,i);},y=(e,t)=>{if(t!=null&&typeof t!="boolean"){if(R(t))throw new Error("Async values are not supported inside jsx template results.");if(Array.isArray(t)){t.forEach(n=>y(e,n));return}if(Ce(t)){for(let n of t)y(e,n);return}if(we(t)){e.appendChild(t);return}e.appendChild(document.createTextNode(String(t)));}},v=(e,t,n)=>L(e,t,r=>N(r,t,n)),Q=_({getIdentifierName:b,evaluateExpressionWithNamespace:v}),Ae=(e,t,n,r)=>{let s=Q(t,n,r);Object.entries(s).forEach(([o,a])=>{if(o!=="key"){if(o==="children"){y(e,a);return}G(e,o,a,r);}});},A=(e,t,n)=>{let r=[];return e.forEach(s=>{switch(s.type){case "JSXText":{O(s.value,t.placeholders).forEach(a=>{r.push(a);});break}case "JSXExpressionContainer":{if(s.expression.type==="JSXEmptyExpression")break;r.push(v(s.expression,t,n));break}case "JSXSpreadChild":{let o=v(s.expression,t,n);o!=null&&r.push(o);break}case "JSXElement":case "JSXFragment":{r.push(N(s,t,n));break}}}),r},Ne=(e,t,n,r)=>{let s=Q(e.openingElement.attributes,t,r),o=A(e.children,t,r);o.length===1?s.children=o[0]:o.length>1&&(s.children=o);let a=n(s);if(R(a))throw new Error("Async jsx components are not supported.");return a},Pe=(e,t,n)=>{let r=e.openingElement,s=b(r.name),o=t.components.get(s);if(o)return Ne(e,t,o,n);if(/[A-Z]/.test(s[0]??""))throw new Error(`Unknown component "${s}". Did you interpolate it with the template literal?`);let a=s==="svg"?"svg":n,l=s==="foreignObject"?null:a,i=a==="svg"?document.createElementNS("http://www.w3.org/2000/svg",s):document.createElement(s);return Ae(i,r.attributes,t,a),A(e.children,t,l).forEach(c=>y(i,c)),i},N=(e,t,n)=>{if(e.type==="JSXFragment"){let r=document.createDocumentFragment();return A(e.children,t,n).forEach(o=>y(r,o)),r}return Pe(e,t,n)},Xe=U({ensureDomAvailable:Z,appendChildValue:y,setDomProp:G,isPromiseLike:R}),je=(e,...t)=>{Z();let n=$(e,t),r=parseSync("inline.jsx",n.source,F);if(r.errors.length>0)throw new Error(J("jsx",e,n.diagnostics,r.errors[0]));let s=M(r.program),o={source:n.source,placeholders:n.placeholders,components:new Map(n.bindings.map(a=>[a.name,a.value]))};return N(s,o,null)},De=Object.assign(je,{createElement:Xe,Fragment:w});
8
+ export{De as jsx};
@@ -1,8 +1,8 @@
1
- import {createRequire}from'module';import {parseSync}from'oxc-parser';import {find,svg,html}from'property-information';var T=null,I=e=>{T=e;},ue=e=>{T?.warnLowercaseEventProp?.(e);},de=e=>{T?.ensureValidDangerouslySetInnerHTML?.(e);},P=e=>{let{getIdentifierName:t,evaluateExpressionWithNamespace:n}=e;return (r,o,s)=>{let a={},c=(i,p)=>{i==="dangerouslySetInnerHTML"&&de(p),a[i]=p;};return r.forEach(i=>{if(i.type==="JSXSpreadAttribute"){let l=n(i.argument,o,s);l&&typeof l=="object"&&!Array.isArray(l)&&Object.assign(a,l);return}let p=t(i.name);if(ue(p),!i.value){c(p,true);return}if(i.value.type==="Literal"){c(p,i.value.value);return}if(i.value.type==="JSXExpressionContainer"){if(i.value.expression.type==="JSXEmptyExpression")return;c(p,n(i.value.expression,o,s));}}),a}};var _=null,H=e=>{_=e;},$="Capture",O=e=>e.endsWith($)?{eventName:e.slice(0,-$.length),capture:true}:{eventName:e,capture:false},F=e=>{if(!e.startsWith("on"))return null;if(e.startsWith("on:")){let r=e.slice(3);if(!r)return null;let o=O(r);return o.eventName?o:null}let t=e.slice(2);if(!t)return null;let n=O(t);return n.eventName?{eventName:n.eventName.toLowerCase(),capture:n.capture}:null},W=e=>!e||typeof e!="object"?false:"handleEvent"in e&&typeof e.handleEvent=="function",fe=e=>{if(!e||typeof e!="object"||!("handler"in e))return false;let t=e.handler;return typeof t=="function"?true:W(t)},ge=(e,t)=>{_?.onInvalidHandler?.(e,t);},B=(e,t)=>{if(typeof t=="function"||W(t))return {listener:t};if(!fe(t))return ge(e,t),null;let n=t,r=n.options?{...n.options}:void 0,o=(s,a)=>{a!=null&&(r||(r={}),r[s]=a);};return o("capture",n.capture),o("once",n.once),o("passive",n.passive),o("signal",n.signal??void 0),{listener:n.handler,options:r}};var xe="@knighted/jsx",V=e=>`${xe}: ${e}`,J=()=>typeof process<"u"&&process.env?.KNIGHTED_JSX_DEBUG==="1",C=e=>{if(e===null)return "null";if(e===void 0)return "undefined";if(typeof e=="function")return e.name?`function ${e.name}`:"function";if(Array.isArray(e))return "array";if(typeof e=="object"){let t=e.constructor;return t&&typeof t.name=="string"&&t.name&&t.name!=="Object"?`${t.name} instance`:"object"}return typeof e},b=e=>new Error(V(e)),U=(e,t=false)=>{!t&&!J()||typeof console<"u"&&typeof console.warn=="function"&&console.warn(V(e));};var ye=e=>e>="a"&&e<="z",S="env",k=()=>S==="always"||S==="env"&&J(),he=()=>S==="always",Ee={warnLowercaseEventProp(e){if(!k()||!e.startsWith("on")||e.startsWith("on:")||e.length<3)return;let t=e[2]??"";if(!ye(t))return;let n=`${e.slice(0,2)}${t.toUpperCase()}${e.slice(3)}`;U(`Use camelCase DOM event props when targeting runtime jsx templates. Received "${e}"; did you mean "${n}"?`,he());},ensureValidDangerouslySetInnerHTML(e){if(!k())return;if(!e||typeof e!="object"||Array.isArray(e))throw b("dangerouslySetInnerHTML expects an object with a string __html field.");let t=e.__html;if(typeof t!="string")throw b(`dangerouslySetInnerHTML.__html must be a string but received ${C(t)}.`)}},be={onInvalidHandler(e,t){if(k())throw b(`The "${e}" prop expects a function, EventListenerObject, or descriptor ({ handler }) but received ${C(t)}.`)}},z=e=>{S=e?.mode,I(Ee),H(be);};var we=createRequire(import.meta.url),K=()=>we,q="<!doctype html><html><body></body></html>",Je=["window","self","document","HTMLElement","Element","Node","DocumentFragment","customElements","Text","Comment","MutationObserver","navigator"],Ce=()=>typeof document<"u"&&typeof document.createElement=="function",ke=e=>{let t=globalThis,n=e;Je.forEach(r=>{t[r]===void 0&&n[r]!==void 0&&(t[r]=n[r]);});},D=()=>{let{parseHTML:e}=K()("linkedom"),{window:t}=e(q);return t},A=()=>{let{JSDOM:e}=K()("jsdom"),{window:t}=new e(q);return t},De=()=>{let e=typeof process<"u"&&process.env?.KNIGHTED_JSX_NODE_SHIM?process.env.KNIGHTED_JSX_NODE_SHIM.toLowerCase():void 0;return e==="linkedom"||e==="jsdom"?e:"auto"},Ae=()=>{let e=De();return e==="linkedom"?[D,A]:e==="jsdom"?[A,D]:[D,A]},ve=()=>{let e=[];for(let n of Ae())try{return n()}catch(r){e.push(r);}let t='Unable to bootstrap a DOM-like environment. Install "linkedom" or "jsdom" (both optional peer dependencies) or set KNIGHTED_JSX_NODE_SHIM to pick one explicitly.';throw new AggregateError(e,t)},G=false,Z=()=>{if(Ce()||G)return;let e=ve();ke(e),G=true;};var Y=e=>{let t=e.replace(/\r/g,"").replace(/\n\s+/g," "),n=e.match(/^\s*/)?.[0]??"",r=e.match(/\s*$/)?.[0]??"",o=/\n/.test(n),s=/\n/.test(r),a=t;return o&&(a=a.replace(/^\s+/,"")),s&&(a=a.replace(/\s+$/,"")),a.length===0||a.trim().length===0?null:a};var Ne="oxc-parser",Me=e=>{let t=e.raw??e,n=t[0]??"",r=[];for(let o=0;o<t.length-1;o++){let s="${expr#"+o+"}",a=n.length;n+=s;let c=n.length;r.push({index:o,templateStart:a,templateEnd:c,label:s}),n+=t[o+1]??"";}return {source:n,spans:r}},Re=(e,t)=>{let n=new Map;return t.forEach(r=>{n.set(r.index,r);}),e.expressionRanges.map(r=>{let o=n.get(r.index);if(!o)return null;let s=Math.max(0,r.sourceEnd-r.sourceStart),a=Math.max(0,o.templateEnd-o.templateStart);return {sourceStart:r.sourceStart,sourceEnd:r.sourceEnd,templateStart:o.templateStart,templateEnd:o.templateEnd,delta:a-s}}).filter(r=>!!r).sort((r,o)=>r.sourceStart-o.sourceStart)},Xe=(e,t,n)=>{if(!Number.isFinite(e)||e<=0)return 0;let r=0;for(let s of t){if(e<s.sourceStart)break;if(e<s.sourceEnd){let a=Math.max(0,e-s.sourceStart),c=Math.max(0,s.templateEnd-s.templateStart);if(c===0)return s.templateStart;let i=Math.min(a,Math.max(0,c-1));return s.templateStart+i}r+=s.delta;}let o=e+r;return o<=0?0:o>=n?n:o},Q=(e,t)=>{let n=Math.max(0,Math.min(t,e.length)),r=1,o=1;for(let s=0;s<n;s++){if(e.charCodeAt(s)===10){r++,o=1;continue}o++;}return {line:r,column:o}},Le=e=>{let t=[],n=0;return e.forEach((r,o)=>{t.push(n),n+=r.length,o<e.length-1&&(n+=1);}),t},je=(e,t,n,r,o,s,a)=>{let c=n+t.length,i=Math.max(r,n),p=Math.min(o,c);if(p>i){let l=Math.max(0,i-n),u=Math.max(1,p-i);return " ".repeat(l)+"^".repeat(u)}if(t.length===0&&e>=s&&e<=a)return "^";if(e===s){let l=Math.max(0,r-n);return " ".repeat(Math.min(l,t.length))+"^"}return ""},Ie=(e,t,n,r,o)=>{if(!e.length)return "";let s=e.split(`
2
- `),a=Le(s),c=Math.max(1,r-1),i=Math.min(s.length,o+1),p=String(i).length,l=[];for(let u=c;u<=i;u++){let d=s[u-1]??"",m=String(u).padStart(p," ");l.push(`${m} | ${d}`);let f=je(u,d,a[u-1]??0,t,n,r,o);f&&l.push(`${" ".repeat(p)} | ${f}`);}return l.join(`
3
- `)},v=(e,t,n,r,o)=>{let s=Ne,a=`[${s}] ${r.message}`,c=r.labels?.[0];if(!c)return a;let{source:i,spans:p}=Me(t),l=Re(n,p),u=y=>Xe(typeof y=="number"?y:0,l,i.length),d=u(c.start),m=u(c.end);m<=d&&(m=Math.min(i.length,d+1));let f=Q(i,d),x=Q(i,Math.max(d,m-1)),E=Ie(i,d,m,f.line,x.line),g=`[${s}] ${r.message}`;return g+=`
4
- --> ${e} template:${f.line}:${f.column}`,c.message&&(g+=`
5
- ${c.message}`),E&&(g+=`
6
- ${E}`),r.helpMessage&&(g+=`
7
- ${r.helpMessage}`),g};var Pe=/<\s*$/,$e=/<\/\s*$/,te="__KX_EXPR__",ee=new RegExp(`${te}\\d+_\\d+__`,"g"),Oe=0;var ne={lang:"jsx",sourceType:"module",range:true,preserveParens:true},re=e=>{for(let t of e.body)if(t.type==="ExpressionStatement"){let n=t.expression;if(n.type==="JSXElement"||n.type==="JSXFragment")return n}throw new Error("The jsx template must contain a single JSX element or fragment.")},w=e=>{switch(e.type){case "JSXIdentifier":return e.name;case "JSXNamespacedName":return `${e.namespace.name}:${e.name.name}`;case "JSXMemberExpression":return `${w(e.object)}.${e.property.name}`;default:return ""}},N=(e,t)=>{if(!e||typeof e!="object")return;let n=e;typeof n.type=="string"&&(t(n),Object.values(n).forEach(r=>{if(r){if(Array.isArray(r)){r.forEach(o=>N(o,t));return}typeof r=="object"&&N(r,t);}}));},oe=(e,t)=>{let n=Y(e);if(!n)return [];let r=[];ee.lastIndex=0;let o=0,s;for(;s=ee.exec(n);){let c=s.index,i=n.slice(o,c);i&&r.push(i);let p=s[0];t.has(p)?r.push(t.get(p)):r.push(p),o=c+p.length;}let a=n.slice(o);return a&&r.push(a),r},_e=(e,t)=>{let n=new Set;return N(e,r=>{r.type==="Identifier"&&t.placeholders.has(r.name)&&n.add(r.name);}),Array.from(n)},se=(e,t,n)=>{if(e.type==="JSXElement"||e.type==="JSXFragment")return n(e);if(!("range"in e)||!e.range)throw new Error("Unable to evaluate expression: missing source range information.");let[r,o]=e.range,s=t.source.slice(r,o),a=_e(e,t);try{let c=new Function(...a,`"use strict"; return (${s});`),i=a.map(p=>t.placeholders.get(p));return c(...i)}catch(c){throw new Error(`Failed to evaluate expression ${s}: ${c.message}`,{cause:c})}},He=e=>{let t=e.replace(/[^a-zA-Z0-9_$]/g,"");return t?/[A-Za-z_$]/.test(t[0])?t:`Component${t}`:"Component"},Fe=(e,t,n)=>{let r=n.get(e);if(r)return r;let o=e.displayName||e.name||`Component${t.length}`,s=He(o??""),a=s,c=1;for(;t.some(p=>p.name===a);)a=`${s}${c++}`;let i={name:a,value:e};return t.push(i),n.set(e,i),i},ae=(e,t)=>{let n=e.raw??e,r=new Map,o=[],s=new Map,a=n[0]??"",c=Oe++,i=0,p=[];for(let l=0;l<t.length;l++){let u=n[l]??"",d=n[l+1]??"",m=t[l],f=Pe.test(u)||$e.test(u),x;if(f&&typeof m=="function")x=Fe(m,o,s).name;else if(f&&typeof m=="string")x=m;else {let y=`${te}${c}_${i++}__`;r.set(y,m),x=y;}let E=a.length;a+=x;let g=a.length;p.push({index:l,sourceStart:E,sourceEnd:g}),a+=d;}return {source:a,placeholders:r,bindings:o,diagnostics:{expressionRanges:p}}};var ze=()=>{if(typeof document>"u"||typeof document.createElement!="function")throw new Error("The jsx template tag requires a DOM-like environment (document missing).")},Ge=e=>typeof Node>"u"?false:e instanceof Node||e instanceof DocumentFragment,Ke=e=>!e||typeof e=="string"?false:typeof e[Symbol.iterator]=="function",pe=e=>!e||typeof e!="object"&&typeof e!="function"?false:typeof e.then=="function",qe={xlink:"http://www.w3.org/1999/xlink",xml:"http://www.w3.org/XML/1998/namespace",xmlns:"http://www.w3.org/2000/xmlns/"},ce=e=>{if(!(!e||e==="html"||e==="svg"))return qe[e]},Ze=e=>e==="svg"?svg:html,M=(e,t,n)=>{let r=ce(t.space),o=String(n);if(r){e.setAttributeNS(r,t.attribute,o);return}e.setAttribute(t.attribute,o);},ie=(e,t)=>{let n=ce(t.space);if(n){e.removeAttributeNS(n,t.attribute);return}e.removeAttribute(t.attribute);},R=(e,t)=>Array.isArray(e)?e.filter(Boolean).join(t):e,Ye=(e,t,n)=>t==="svg"||!n.property||n.property.includes(":")?false:n.property in e,Qe=(e,t,n,r)=>{if(n==null)return;if(t==="dangerouslySetInnerHTML"&&typeof n=="object"&&n&&"__html"in n){e.innerHTML=String(n.__html??"");return}if(t==="ref"){if(typeof n=="function"){n(e);return}if(n&&typeof n=="object"){n.current=e;return}}if(t==="style"&&typeof n=="object"&&n!==null){let p=n,l=e.style;if(!l)return;let u=l;Object.entries(p).forEach(([d,m])=>{if(m!=null){if(d.startsWith("--")){l.setProperty(d,String(m));return}u[d]=m;}});return}let o=F(t);if(o){let p=B(t,n);if(p){let l=p.options?{...p.options}:void 0;o.capture&&(l?l.capture=true:l={capture:true}),e.addEventListener(o.eventName,p.listener,l);return}}let s=find(Ze(r),t),a=e,c=Ye(e,r,s);if(s.mustUseProperty){let p=s.boolean?!!n:n;a[s.property]=p;return}if(s.boolean){let p=!!n;c&&(a[s.property]=p),p?M(e,s,""):ie(e,s);return}let i=n;if(s.spaceSeparated?i=R(n," "):s.commaSeparated?i=R(n,","):s.commaOrSpaceSeparated&&(i=R(n," ")),s.booleanish&&typeof i=="boolean"&&(i=i?"true":"false"),s.overloadedBoolean){if(i===false){ie(e,s);return}if(i===true){M(e,s,"");return}}if(c){a[s.property]=i;return}i!==false&&M(e,s,i);},h=(e,t)=>{if(t!=null&&typeof t!="boolean"){if(pe(t))throw new Error("Async values are not supported inside jsx template results.");if(Array.isArray(t)){t.forEach(n=>h(e,n));return}if(Ke(t)){for(let n of t)h(e,n);return}if(Ge(t)){e.appendChild(t);return}e.appendChild(document.createTextNode(String(t)));}},X=(e,t,n)=>se(e,t,r=>j(r,t,n)),le=P({getIdentifierName:w,evaluateExpressionWithNamespace:X}),et=(e,t,n,r)=>{let o=le(t,n,r);Object.entries(o).forEach(([s,a])=>{if(s!=="key"){if(s==="children"){h(e,a);return}Qe(e,s,a,r);}});},L=(e,t,n)=>{let r=[];return e.forEach(o=>{switch(o.type){case "JSXText":{oe(o.value,t.placeholders).forEach(a=>{r.push(a);});break}case "JSXExpressionContainer":{if(o.expression.type==="JSXEmptyExpression")break;r.push(X(o.expression,t,n));break}case "JSXSpreadChild":{let s=X(o.expression,t,n);s!=null&&r.push(s);break}case "JSXElement":case "JSXFragment":{r.push(j(o,t,n));break}}}),r},tt=(e,t,n,r)=>{let o=le(e.openingElement.attributes,t,r),s=L(e.children,t,r);s.length===1?o.children=s[0]:s.length>1&&(o.children=s);let a=n(o);if(pe(a))throw new Error("Async jsx components are not supported.");return a},nt=(e,t,n)=>{let r=e.openingElement,o=w(r.name),s=t.components.get(o);if(s)return tt(e,t,s,n);if(/[A-Z]/.test(o[0]??""))throw new Error(`Unknown component "${o}". Did you interpolate it with the template literal?`);let a=o==="svg"?"svg":n,c=o==="foreignObject"?null:a,i=a==="svg"?document.createElementNS("http://www.w3.org/2000/svg",o):document.createElement(o);return et(i,r.attributes,t,a),L(e.children,t,c).forEach(l=>h(i,l)),i},j=(e,t,n)=>{if(e.type==="JSXFragment"){let r=document.createDocumentFragment();return L(e.children,t,n).forEach(s=>h(r,s)),r}return nt(e,t,n)},me=(e,...t)=>{ze();let n=ae(e,t),r=parseSync("inline.jsx",n.source,ne);if(r.errors.length>0)throw new Error(v("jsx",e,n.diagnostics,r.errors[0]));let o=re(r.program),s={source:n.source,placeholders:n.placeholders,components:new Map(n.bindings.map(a=>[a.name,a.value]))};return j(o,s,null)};z({mode:"always"});Z();var Dt=me;
8
- export{Dt as jsx};
1
+ import {createRequire}from'module';import {parseSync}from'oxc-parser';import {find,svg,html}from'property-information';var T=null,I=e=>{T=e;},Ee=e=>{T?.warnLowercaseEventProp?.(e);},ye=e=>{T?.ensureValidDangerouslySetInnerHTML?.(e);},$=e=>{let{getIdentifierName:t,evaluateExpressionWithNamespace:n}=e;return (r,s,o)=>{let a={},c=(i,p)=>{i==="dangerouslySetInnerHTML"&&ye(p),a[i]=p;};return r.forEach(i=>{if(i.type==="JSXSpreadAttribute"){let l=n(i.argument,s,o);l&&typeof l=="object"&&!Array.isArray(l)&&Object.assign(a,l);return}let p=t(i.name);if(Ee(p),!i.value){c(p,true);return}if(i.value.type==="Literal"){c(p,i.value.value);return}if(i.value.type==="JSXExpressionContainer"){if(i.value.expression.type==="JSXEmptyExpression")return;c(p,n(i.value.expression,s,o));}}),a}};var W=null,B=e=>{W=e;},F="Capture",H=e=>e.endsWith(F)?{eventName:e.slice(0,-F.length),capture:true}:{eventName:e,capture:false},V=e=>{if(!e.startsWith("on"))return null;if(e.startsWith("on:")){let r=e.slice(3);if(!r)return null;let s=H(r);return s.eventName?s:null}let t=e.slice(2);if(!t)return null;let n=H(t);return n.eventName?{eventName:n.eventName.toLowerCase(),capture:n.capture}:null},U=e=>!e||typeof e!="object"?false:"handleEvent"in e&&typeof e.handleEvent=="function",he=e=>{if(!e||typeof e!="object"||!("handler"in e))return false;let t=e.handler;return typeof t=="function"?true:U(t)},be=(e,t)=>{W?.onInvalidHandler?.(e,t);},z=(e,t)=>{if(typeof t=="function"||U(t))return {listener:t};if(!he(t))return be(e,t),null;let n=t,r=n.options?{...n.options}:void 0,s=(o,a)=>{a!=null&&(r||(r={}),r[o]=a);};return s("capture",n.capture),s("once",n.once),s("passive",n.passive),s("signal",n.signal??void 0),{listener:n.handler,options:r}};var Se="@knighted/jsx",q=e=>`${Se}: ${e}`,C=()=>typeof process<"u"&&process.env?.KNIGHTED_JSX_DEBUG==="1",k=e=>{if(e===null)return "null";if(e===void 0)return "undefined";if(typeof e=="function")return e.name?`function ${e.name}`:"function";if(Array.isArray(e))return "array";if(typeof e=="object"){let t=e.constructor;return t&&typeof t.name=="string"&&t.name&&t.name!=="Object"?`${t.name} instance`:"object"}return typeof e},b=e=>new Error(q(e)),G=(e,t=false)=>{!t&&!C()||typeof console<"u"&&typeof console.warn=="function"&&console.warn(q(e));};var we=e=>e>="a"&&e<="z",S="env",v=()=>S==="always"||S==="env"&&C(),Je=()=>S==="always",Te={warnLowercaseEventProp(e){if(!v()||!e.startsWith("on")||e.startsWith("on:")||e.length<3)return;let t=e[2]??"";if(!we(t))return;let n=`${e.slice(0,2)}${t.toUpperCase()}${e.slice(3)}`;G(`Use camelCase DOM event props when targeting runtime jsx templates. Received "${e}"; did you mean "${n}"?`,Je());},ensureValidDangerouslySetInnerHTML(e){if(!v())return;if(!e||typeof e!="object"||Array.isArray(e))throw b("dangerouslySetInnerHTML expects an object with a string __html field.");let t=e.__html;if(typeof t!="string")throw b(`dangerouslySetInnerHTML.__html must be a string but received ${k(t)}.`)}},Ce={onInvalidHandler(e,t){if(v())throw b(`The "${e}" prop expects a function, EventListenerObject, or descriptor ({ handler }) but received ${k(t)}.`)}},K=e=>{S=e?.mode,I(Te),B(Ce);};var ve=createRequire(import.meta.url),Y=()=>ve,Q="<!doctype html><html><body></body></html>",Re=["window","self","document","HTMLElement","Element","Node","DocumentFragment","customElements","Text","Comment","MutationObserver","navigator"],Ae=()=>typeof document<"u"&&typeof document.createElement=="function",Ne=e=>{let t=globalThis,n=e;Re.forEach(r=>{t[r]===void 0&&n[r]!==void 0&&(t[r]=n[r]);});},D=()=>{let{parseHTML:e}=Y()("linkedom"),{window:t}=e(Q);return t},R=()=>{let{JSDOM:e}=Y()("jsdom"),{window:t}=new e(Q);return t},Pe=()=>{let e=typeof process<"u"&&process.env?.KNIGHTED_JSX_NODE_SHIM?process.env.KNIGHTED_JSX_NODE_SHIM.toLowerCase():void 0;return e==="linkedom"||e==="jsdom"?e:"auto"},je=()=>{let e=Pe();return e==="linkedom"?[D,R]:e==="jsdom"?[R,D]:[D,R]},Me=()=>{let e=[];for(let n of je())try{return n()}catch(r){e.push(r);}let t='Unable to bootstrap a DOM-like environment. Install "linkedom" or "jsdom" (both optional peer dependencies) or set KNIGHTED_JSX_NODE_SHIM to pick one explicitly.';throw new AggregateError(e,t)},Z=false,ee=()=>{if(Ae()||Z)return;let e=Me();Ne(e),Z=true;};var te=e=>{let t=e.replace(/\r/g,"").replace(/\n\s+/g," "),n=e.match(/^\s*/)?.[0]??"",r=e.match(/\s*$/)?.[0]??"",s=/\n/.test(n),o=/\n/.test(r),a=t;return s&&(a=a.replace(/^\s+/,"")),o&&(a=a.replace(/\s+$/,"")),a.length===0||a.trim().length===0?null:a};var Xe="oxc-parser",Le=e=>{let t=e.raw??e,n=t[0]??"",r=[];for(let s=0;s<t.length-1;s++){let o="${expr#"+s+"}",a=n.length;n+=o;let c=n.length;r.push({index:s,templateStart:a,templateEnd:c,label:o}),n+=t[s+1]??"";}return {source:n,spans:r}},Oe=(e,t)=>{let n=new Map;return t.forEach(r=>{n.set(r.index,r);}),e.expressionRanges.map(r=>{let s=n.get(r.index);if(!s)return null;let o=Math.max(0,r.sourceEnd-r.sourceStart),a=Math.max(0,s.templateEnd-s.templateStart);return {sourceStart:r.sourceStart,sourceEnd:r.sourceEnd,templateStart:s.templateStart,templateEnd:s.templateEnd,delta:a-o}}).filter(r=>!!r).sort((r,s)=>r.sourceStart-s.sourceStart)},_e=(e,t,n)=>{if(!Number.isFinite(e)||e<=0)return 0;let r=0;for(let o of t){if(e<o.sourceStart)break;if(e<o.sourceEnd){let a=Math.max(0,e-o.sourceStart),c=Math.max(0,o.templateEnd-o.templateStart);if(c===0)return o.templateStart;let i=Math.min(a,Math.max(0,c-1));return o.templateStart+i}r+=o.delta;}let s=e+r;return s<=0?0:s>=n?n:s},ne=(e,t)=>{let n=Math.max(0,Math.min(t,e.length)),r=1,s=1;for(let o=0;o<n;o++){if(e.charCodeAt(o)===10){r++,s=1;continue}s++;}return {line:r,column:s}},Ie=e=>{let t=[],n=0;return e.forEach((r,s)=>{t.push(n),n+=r.length,s<e.length-1&&(n+=1);}),t},$e=(e,t,n,r,s,o,a)=>{let c=n+t.length,i=Math.max(r,n),p=Math.min(s,c);if(p>i){let l=Math.max(0,i-n),u=Math.max(1,p-i);return " ".repeat(l)+"^".repeat(u)}if(t.length===0&&e>=o&&e<=a)return "^";if(e===o){let l=Math.max(0,r-n);return " ".repeat(Math.min(l,t.length))+"^"}return ""},Fe=(e,t,n,r,s)=>{if(!e.length)return "";let o=e.split(`
2
+ `),a=Ie(o),c=Math.max(1,r-1),i=Math.min(o.length,s+1),p=String(i).length,l=[];for(let u=c;u<=i;u++){let d=o[u-1]??"",m=String(u).padStart(p," ");l.push(`${m} | ${d}`);let g=$e(u,d,a[u-1]??0,t,n,r,s);g&&l.push(`${" ".repeat(p)} | ${g}`);}return l.join(`
3
+ `)},A=(e,t,n,r,s)=>{let o=Xe,a=`[${o}] ${r.message}`,c=r.labels?.[0];if(!c)return a;let{source:i,spans:p}=Le(t),l=Oe(n,p),u=E=>_e(typeof E=="number"?E:0,l,i.length),d=u(c.start),m=u(c.end);m<=d&&(m=Math.min(i.length,d+1));let g=ne(i,d),x=ne(i,Math.max(d,m-1)),h=Fe(i,d,m,g.line,x.line),f=`[${o}] ${r.message}`;return f+=`
4
+ --> ${e} template:${g.line}:${g.column}`,c.message&&(f+=`
5
+ ${c.message}`),h&&(f+=`
6
+ ${h}`),r.helpMessage&&(f+=`
7
+ ${r.helpMessage}`),f};var He=/<\s*$/,We=/<\/\s*$/,oe="__KX_EXPR__",re=new RegExp(`${oe}\\d+_\\d+__`,"g"),Be=0;var se={lang:"jsx",sourceType:"module",range:true,preserveParens:true},ae=e=>{for(let t of e.body)if(t.type==="ExpressionStatement"){let n=t.expression;if(n.type==="JSXElement"||n.type==="JSXFragment")return n}throw new Error("The jsx template must contain a single JSX element or fragment.")},w=e=>{switch(e.type){case "JSXIdentifier":return e.name;case "JSXNamespacedName":return `${e.namespace.name}:${e.name.name}`;case "JSXMemberExpression":return `${w(e.object)}.${e.property.name}`;default:return ""}},N=(e,t)=>{if(!e||typeof e!="object")return;let n=e;typeof n.type=="string"&&(t(n),Object.values(n).forEach(r=>{if(r){if(Array.isArray(r)){r.forEach(s=>N(s,t));return}typeof r=="object"&&N(r,t);}}));},ie=(e,t)=>{let n=te(e);if(!n)return [];let r=[];re.lastIndex=0;let s=0,o;for(;o=re.exec(n);){let c=o.index,i=n.slice(s,c);i&&r.push(i);let p=o[0];t.has(p)?r.push(t.get(p)):r.push(p),s=c+p.length;}let a=n.slice(s);return a&&r.push(a),r},Ve=(e,t)=>{let n=new Set;return N(e,r=>{r.type==="Identifier"&&t.placeholders.has(r.name)&&n.add(r.name);}),Array.from(n)},pe=(e,t,n)=>{if(e.type==="JSXElement"||e.type==="JSXFragment")return n(e);if(!("range"in e)||!e.range)throw new Error("Unable to evaluate expression: missing source range information.");let[r,s]=e.range,o=t.source.slice(r,s),a=Ve(e,t);try{let c=new Function(...a,`"use strict"; return (${o});`),i=a.map(p=>t.placeholders.get(p));return c(...i)}catch(c){throw new Error(`Failed to evaluate expression ${o}: ${c.message}`,{cause:c})}},Ue=e=>{let t=e.replace(/[^a-zA-Z0-9_$]/g,"");return t?/[A-Za-z_$]/.test(t[0])?t:`Component${t}`:"Component"},ze=(e,t,n)=>{let r=n.get(e);if(r)return r;let s=e.displayName||e.name||`Component${t.length}`,o=Ue(s??""),a=o,c=1;for(;t.some(p=>p.name===a);)a=`${o}${c++}`;let i={name:a,value:e};return t.push(i),n.set(e,i),i},ce=(e,t)=>{let n=e.raw??e,r=new Map,s=[],o=new Map,a=n[0]??"",c=Be++,i=0,p=[];for(let l=0;l<t.length;l++){let u=n[l]??"",d=n[l+1]??"",m=t[l],g=He.test(u)||We.test(u),x;if(g&&typeof m=="function")x=ze(m,s,o).name;else if(g&&typeof m=="string")x=m;else {let E=`${oe}${c}_${i++}__`;r.set(E,m),x=E;}let h=a.length;a+=x;let f=a.length;p.push({index:l,sourceStart:h,sourceEnd:f}),a+=d;}return {source:a,placeholders:r,bindings:s,diagnostics:{expressionRanges:p}}};var P=Symbol.for("@knighted/jsx::Fragment"),J="__jsxNs",qe=(e,t)=>t.length>0?t:Object.prototype.hasOwnProperty.call(e,"children")?[e.children]:[],Ge=(e,t)=>{let n={...e};return t.length===1?n.children=t[0]:t.length>1?n.children=t:delete n.children,n},Ke=e=>{if(!Object.prototype.hasOwnProperty.call(e,J))return;let t=e[J];if(delete e[J],t==="svg"||t===null)return t;throw new Error(`${J} must be "svg" or null when provided.`)},le=({ensureDomAvailable:e,appendChildValue:t,setDomProp:n,isPromiseLike:r})=>{function s(o,a,...c){e();let i=a?{...a}:{},p=qe(i,c);if(o===P){let m=document.createDocumentFragment();return p.forEach(g=>t(m,g)),m}if(typeof o=="function"){let m=o(Ge(i,p));if(r(m))throw new Error("Async jsx components are not supported.");return m}if(typeof o!="string")throw new Error(`Unsupported jsx createElement type: ${String(o)}`);delete i.children;let u=Ke(i)??(o==="svg"?"svg":null),d=u==="svg"?document.createElementNS("http://www.w3.org/2000/svg",o):document.createElement(o);return Object.entries(i).forEach(([m,g])=>{m!=="key"&&n(d,m,g,u);}),p.forEach(m=>t(d,m)),d}return s};var ue=()=>{if(typeof document>"u"||typeof document.createElement!="function")throw new Error("The jsx template tag requires a DOM-like environment (document missing).")},tt=e=>typeof Node>"u"?false:e instanceof Node||e instanceof DocumentFragment,nt=e=>!e||typeof e=="string"?false:typeof e[Symbol.iterator]=="function",L=e=>!e||typeof e!="object"&&typeof e!="function"?false:typeof e.then=="function",rt={xlink:"http://www.w3.org/1999/xlink",xml:"http://www.w3.org/XML/1998/namespace",xmlns:"http://www.w3.org/2000/xmlns/"},de=e=>{if(!(!e||e==="html"||e==="svg"))return rt[e]},ot=e=>e==="svg"?svg:html,j=(e,t,n)=>{let r=de(t.space),s=String(n);if(r){e.setAttributeNS(r,t.attribute,s);return}e.setAttribute(t.attribute,s);},me=(e,t)=>{let n=de(t.space);if(n){e.removeAttributeNS(n,t.attribute);return}e.removeAttribute(t.attribute);},M=(e,t)=>Array.isArray(e)?e.filter(Boolean).join(t):e,st=(e,t,n)=>t==="svg"||!n.property||n.property.includes(":")?false:n.property in e,ge=(e,t,n,r)=>{if(n==null)return;if(t==="dangerouslySetInnerHTML"&&typeof n=="object"&&n&&"__html"in n){e.innerHTML=String(n.__html??"");return}if(t==="ref"){if(typeof n=="function"){n(e);return}if(n&&typeof n=="object"){n.current=e;return}}if(t==="style"&&typeof n=="object"&&n!==null){let p=n,l=e.style;if(!l)return;let u=l;Object.entries(p).forEach(([d,m])=>{if(m!=null){if(d.startsWith("--")){l.setProperty(d,String(m));return}u[d]=m;}});return}let s=V(t);if(s){let p=z(t,n);if(p){let l=p.options?{...p.options}:void 0;s.capture&&(l?l.capture=true:l={capture:true}),e.addEventListener(s.eventName,p.listener,l);return}}let o=find(ot(r),t),a=e,c=st(e,r,o);if(o.mustUseProperty){let p=o.boolean?!!n:n;a[o.property]=p;return}if(o.boolean){let p=!!n;c&&(a[o.property]=p),p?j(e,o,""):me(e,o);return}let i=n;if(o.spaceSeparated?i=M(n," "):o.commaSeparated?i=M(n,","):o.commaOrSpaceSeparated&&(i=M(n," ")),o.booleanish&&typeof i=="boolean"&&(i=i?"true":"false"),o.overloadedBoolean){if(i===false){me(e,o);return}if(i===true){j(e,o,"");return}}if(c){a[o.property]=i;return}i!==false&&j(e,o,i);},y=(e,t)=>{if(t!=null&&typeof t!="boolean"){if(L(t))throw new Error("Async values are not supported inside jsx template results.");if(Array.isArray(t)){t.forEach(n=>y(e,n));return}if(nt(t)){for(let n of t)y(e,n);return}if(tt(t)){e.appendChild(t);return}e.appendChild(document.createTextNode(String(t)));}},X=(e,t,n)=>pe(e,t,r=>_(r,t,n)),fe=$({getIdentifierName:w,evaluateExpressionWithNamespace:X}),at=(e,t,n,r)=>{let s=fe(t,n,r);Object.entries(s).forEach(([o,a])=>{if(o!=="key"){if(o==="children"){y(e,a);return}ge(e,o,a,r);}});},O=(e,t,n)=>{let r=[];return e.forEach(s=>{switch(s.type){case "JSXText":{ie(s.value,t.placeholders).forEach(a=>{r.push(a);});break}case "JSXExpressionContainer":{if(s.expression.type==="JSXEmptyExpression")break;r.push(X(s.expression,t,n));break}case "JSXSpreadChild":{let o=X(s.expression,t,n);o!=null&&r.push(o);break}case "JSXElement":case "JSXFragment":{r.push(_(s,t,n));break}}}),r},it=(e,t,n,r)=>{let s=fe(e.openingElement.attributes,t,r),o=O(e.children,t,r);o.length===1?s.children=o[0]:o.length>1&&(s.children=o);let a=n(s);if(L(a))throw new Error("Async jsx components are not supported.");return a},pt=(e,t,n)=>{let r=e.openingElement,s=w(r.name),o=t.components.get(s);if(o)return it(e,t,o,n);if(/[A-Z]/.test(s[0]??""))throw new Error(`Unknown component "${s}". Did you interpolate it with the template literal?`);let a=s==="svg"?"svg":n,c=s==="foreignObject"?null:a,i=a==="svg"?document.createElementNS("http://www.w3.org/2000/svg",s):document.createElement(s);return at(i,r.attributes,t,a),O(e.children,t,c).forEach(l=>y(i,l)),i},_=(e,t,n)=>{if(e.type==="JSXFragment"){let r=document.createDocumentFragment();return O(e.children,t,n).forEach(o=>y(r,o)),r}return pt(e,t,n)},ct=le({ensureDomAvailable:ue,appendChildValue:y,setDomProp:ge,isPromiseLike:L}),lt=(e,...t)=>{ue();let n=ce(e,t),r=parseSync("inline.jsx",n.source,se);if(r.errors.length>0)throw new Error(A("jsx",e,n.diagnostics,r.errors[0]));let s=ae(r.program),o={source:n.source,placeholders:n.placeholders,components:new Map(n.bindings.map(a=>[a.name,a.value]))};return _(s,o,null)},xe=Object.assign(lt,{createElement:ct,Fragment:P});K({mode:"always"});ee();var Ot=xe;
8
+ export{Ot as jsx};
@@ -1,8 +1,8 @@
1
- import {createRequire}from'module';import {parseSync}from'oxc-parser';import {find,svg,html}from'property-information';var ne=createRequire(import.meta.url),R=()=>ne,M="<!doctype html><html><body></body></html>",oe=["window","self","document","HTMLElement","Element","Node","DocumentFragment","customElements","Text","Comment","MutationObserver","navigator"],se=()=>typeof document<"u"&&typeof document.createElement=="function",ae=e=>{let n=globalThis,t=e;oe.forEach(r=>{n[r]===void 0&&t[r]!==void 0&&(n[r]=t[r]);});},S=()=>{let{parseHTML:e}=R()("linkedom"),{window:n}=e(M);return n},w=()=>{let{JSDOM:e}=R()("jsdom"),{window:n}=new e(M);return n},ie=()=>{let e=typeof process<"u"&&process.env?.KNIGHTED_JSX_NODE_SHIM?process.env.KNIGHTED_JSX_NODE_SHIM.toLowerCase():void 0;return e==="linkedom"||e==="jsdom"?e:"auto"},pe=()=>{let e=ie();return e==="linkedom"?[S,w]:e==="jsdom"?[w,S]:[S,w]},ce=()=>{let e=[];for(let t of pe())try{return t()}catch(r){e.push(r);}let n='Unable to bootstrap a DOM-like environment. Install "linkedom" or "jsdom" (both optional peer dependencies) or set KNIGHTED_JSX_NODE_SHIM to pick one explicitly.';throw new AggregateError(e,n)},X=false,D=()=>{if(se()||X)return;let e=ce();ae(e),X=true;};var L=e=>{let n=e.replace(/\r/g,"").replace(/\n\s+/g," "),t=e.match(/^\s*/)?.[0]??"",r=e.match(/\s*$/)?.[0]??"",o=/\n/.test(t),s=/\n/.test(r),a=n;return o&&(a=a.replace(/^\s+/,"")),s&&(a=a.replace(/\s+$/,"")),a.length===0||a.trim().length===0?null:a};var le="oxc-parser",me=e=>{let n=e.raw??e,t=n[0]??"",r=[];for(let o=0;o<n.length-1;o++){let s="${expr#"+o+"}",a=t.length;t+=s;let c=t.length;r.push({index:o,templateStart:a,templateEnd:c,label:s}),t+=n[o+1]??"";}return {source:t,spans:r}},ue=(e,n)=>{let t=new Map;return n.forEach(r=>{t.set(r.index,r);}),e.expressionRanges.map(r=>{let o=t.get(r.index);if(!o)return null;let s=Math.max(0,r.sourceEnd-r.sourceStart),a=Math.max(0,o.templateEnd-o.templateStart);return {sourceStart:r.sourceStart,sourceEnd:r.sourceEnd,templateStart:o.templateStart,templateEnd:o.templateEnd,delta:a-s}}).filter(r=>!!r).sort((r,o)=>r.sourceStart-o.sourceStart)},de=(e,n,t)=>{if(!Number.isFinite(e)||e<=0)return 0;let r=0;for(let s of n){if(e<s.sourceStart)break;if(e<s.sourceEnd){let a=Math.max(0,e-s.sourceStart),c=Math.max(0,s.templateEnd-s.templateStart);if(c===0)return s.templateStart;let i=Math.min(a,Math.max(0,c-1));return s.templateStart+i}r+=s.delta;}let o=e+r;return o<=0?0:o>=t?t:o},P=(e,n)=>{let t=Math.max(0,Math.min(n,e.length)),r=1,o=1;for(let s=0;s<t;s++){if(e.charCodeAt(s)===10){r++,o=1;continue}o++;}return {line:r,column:o}},fe=e=>{let n=[],t=0;return e.forEach((r,o)=>{n.push(t),t+=r.length,o<e.length-1&&(t+=1);}),n},ge=(e,n,t,r,o,s,a)=>{let c=t+n.length,i=Math.max(r,t),p=Math.min(o,c);if(p>i){let l=Math.max(0,i-t),u=Math.max(1,p-i);return " ".repeat(l)+"^".repeat(u)}if(n.length===0&&e>=s&&e<=a)return "^";if(e===s){let l=Math.max(0,r-t);return " ".repeat(Math.min(l,n.length))+"^"}return ""},xe=(e,n,t,r,o)=>{if(!e.length)return "";let s=e.split(`
2
- `),a=fe(s),c=Math.max(1,r-1),i=Math.min(s.length,o+1),p=String(i).length,l=[];for(let u=c;u<=i;u++){let d=s[u-1]??"",m=String(u).padStart(p," ");l.push(`${m} | ${d}`);let f=ge(u,d,a[u-1]??0,n,t,r,o);f&&l.push(`${" ".repeat(p)} | ${f}`);}return l.join(`
3
- `)},T=(e,n,t,r,o)=>{let s=le,a=`[${s}] ${r.message}`,c=r.labels?.[0];if(!c)return a;let{source:i,spans:p}=me(n),l=ue(t,p),u=h=>de(typeof h=="number"?h:0,l,i.length),d=u(c.start),m=u(c.end);m<=d&&(m=Math.min(i.length,d+1));let f=P(i,d),x=P(i,Math.max(d,m-1)),y=xe(i,d,m,f.line,x.line),g=`[${s}] ${r.message}`;return g+=`
4
- --> ${e} template:${f.line}:${f.column}`,c.message&&(g+=`
5
- ${c.message}`),y&&(g+=`
1
+ import {createRequire}from'module';import {parseSync}from'oxc-parser';import {find,svg,html}from'property-information';var ie=createRequire(import.meta.url),X=()=>ie,M="<!doctype html><html><body></body></html>",le=["window","self","document","HTMLElement","Element","Node","DocumentFragment","customElements","Text","Comment","MutationObserver","navigator"],ce=()=>typeof document<"u"&&typeof document.createElement=="function",me=e=>{let t=globalThis,n=e;le.forEach(r=>{t[r]===void 0&&n[r]!==void 0&&(t[r]=n[r]);});},J=()=>{let{parseHTML:e}=X()("linkedom"),{window:t}=e(M);return t},w=()=>{let{JSDOM:e}=X()("jsdom"),{window:t}=new e(M);return t},ue=()=>{let e=typeof process<"u"&&process.env?.KNIGHTED_JSX_NODE_SHIM?process.env.KNIGHTED_JSX_NODE_SHIM.toLowerCase():void 0;return e==="linkedom"||e==="jsdom"?e:"auto"},de=()=>{let e=ue();return e==="linkedom"?[J,w]:e==="jsdom"?[w,J]:[J,w]},fe=()=>{let e=[];for(let n of de())try{return n()}catch(r){e.push(r);}let t='Unable to bootstrap a DOM-like environment. Install "linkedom" or "jsdom" (both optional peer dependencies) or set KNIGHTED_JSX_NODE_SHIM to pick one explicitly.';throw new AggregateError(e,t)},D=false,L=()=>{if(ce()||D)return;let e=fe();me(e),D=true;};var O=e=>{let t=e.replace(/\r/g,"").replace(/\n\s+/g," "),n=e.match(/^\s*/)?.[0]??"",r=e.match(/\s*$/)?.[0]??"",s=/\n/.test(n),o=/\n/.test(r),a=t;return s&&(a=a.replace(/^\s+/,"")),o&&(a=a.replace(/\s+$/,"")),a.length===0||a.trim().length===0?null:a};var ge="oxc-parser",xe=e=>{let t=e.raw??e,n=t[0]??"",r=[];for(let s=0;s<t.length-1;s++){let o="${expr#"+s+"}",a=n.length;n+=o;let l=n.length;r.push({index:s,templateStart:a,templateEnd:l,label:o}),n+=t[s+1]??"";}return {source:n,spans:r}},Ee=(e,t)=>{let n=new Map;return t.forEach(r=>{n.set(r.index,r);}),e.expressionRanges.map(r=>{let s=n.get(r.index);if(!s)return null;let o=Math.max(0,r.sourceEnd-r.sourceStart),a=Math.max(0,s.templateEnd-s.templateStart);return {sourceStart:r.sourceStart,sourceEnd:r.sourceEnd,templateStart:s.templateStart,templateEnd:s.templateEnd,delta:a-o}}).filter(r=>!!r).sort((r,s)=>r.sourceStart-s.sourceStart)},he=(e,t,n)=>{if(!Number.isFinite(e)||e<=0)return 0;let r=0;for(let o of t){if(e<o.sourceStart)break;if(e<o.sourceEnd){let a=Math.max(0,e-o.sourceStart),l=Math.max(0,o.templateEnd-o.templateStart);if(l===0)return o.templateStart;let i=Math.min(a,Math.max(0,l-1));return o.templateStart+i}r+=o.delta;}let s=e+r;return s<=0?0:s>=n?n:s},F=(e,t)=>{let n=Math.max(0,Math.min(t,e.length)),r=1,s=1;for(let o=0;o<n;o++){if(e.charCodeAt(o)===10){r++,s=1;continue}s++;}return {line:r,column:s}},ye=e=>{let t=[],n=0;return e.forEach((r,s)=>{t.push(n),n+=r.length,s<e.length-1&&(n+=1);}),t},be=(e,t,n,r,s,o,a)=>{let l=n+t.length,i=Math.max(r,n),p=Math.min(s,l);if(p>i){let c=Math.max(0,i-n),u=Math.max(1,p-i);return " ".repeat(c)+"^".repeat(u)}if(t.length===0&&e>=o&&e<=a)return "^";if(e===o){let c=Math.max(0,r-n);return " ".repeat(Math.min(c,t.length))+"^"}return ""},Se=(e,t,n,r,s)=>{if(!e.length)return "";let o=e.split(`
2
+ `),a=ye(o),l=Math.max(1,r-1),i=Math.min(o.length,s+1),p=String(i).length,c=[];for(let u=l;u<=i;u++){let d=o[u-1]??"",m=String(u).padStart(p," ");c.push(`${m} | ${d}`);let f=be(u,d,a[u-1]??0,t,n,r,s);f&&c.push(`${" ".repeat(p)} | ${f}`);}return c.join(`
3
+ `)},T=(e,t,n,r,s)=>{let o=ge,a=`[${o}] ${r.message}`,l=r.labels?.[0];if(!l)return a;let{source:i,spans:p}=xe(t),c=Ee(n,p),u=E=>he(typeof E=="number"?E:0,c,i.length),d=u(l.start),m=u(l.end);m<=d&&(m=Math.min(i.length,d+1));let f=F(i,d),x=F(i,Math.max(d,m-1)),y=Se(i,d,m,f.line,x.line),g=`[${o}] ${r.message}`;return g+=`
4
+ --> ${e} template:${f.line}:${f.column}`,l.message&&(g+=`
5
+ ${l.message}`),y&&(g+=`
6
6
  ${y}`),r.helpMessage&&(g+=`
7
- ${r.helpMessage}`),g};var he=/<\s*$/,Ee=/<\/\s*$/,j="__KX_EXPR__",I=new RegExp(`${j}\\d+_\\d+__`,"g"),ye=0;var O={lang:"jsx",sourceType:"module",range:true,preserveParens:true},$=e=>{for(let n of e.body)if(n.type==="ExpressionStatement"){let t=n.expression;if(t.type==="JSXElement"||t.type==="JSXFragment")return t}throw new Error("The jsx template must contain a single JSX element or fragment.")},b=e=>{switch(e.type){case "JSXIdentifier":return e.name;case "JSXNamespacedName":return `${e.namespace.name}:${e.name.name}`;case "JSXMemberExpression":return `${b(e.object)}.${e.property.name}`;default:return ""}},J=(e,n)=>{if(!e||typeof e!="object")return;let t=e;typeof t.type=="string"&&(n(t),Object.values(t).forEach(r=>{if(r){if(Array.isArray(r)){r.forEach(o=>J(o,n));return}typeof r=="object"&&J(r,n);}}));},_=(e,n)=>{let t=L(e);if(!t)return [];let r=[];I.lastIndex=0;let o=0,s;for(;s=I.exec(t);){let c=s.index,i=t.slice(o,c);i&&r.push(i);let p=s[0];n.has(p)?r.push(n.get(p)):r.push(p),o=c+p.length;}let a=t.slice(o);return a&&r.push(a),r},be=(e,n)=>{let t=new Set;return J(e,r=>{r.type==="Identifier"&&n.placeholders.has(r.name)&&t.add(r.name);}),Array.from(t)},F=(e,n,t)=>{if(e.type==="JSXElement"||e.type==="JSXFragment")return t(e);if(!("range"in e)||!e.range)throw new Error("Unable to evaluate expression: missing source range information.");let[r,o]=e.range,s=n.source.slice(r,o),a=be(e,n);try{let c=new Function(...a,`"use strict"; return (${s});`),i=a.map(p=>n.placeholders.get(p));return c(...i)}catch(c){throw new Error(`Failed to evaluate expression ${s}: ${c.message}`,{cause:c})}},Se=e=>{let n=e.replace(/[^a-zA-Z0-9_$]/g,"");return n?/[A-Za-z_$]/.test(n[0])?n:`Component${n}`:"Component"},we=(e,n,t)=>{let r=t.get(e);if(r)return r;let o=e.displayName||e.name||`Component${n.length}`,s=Se(o??""),a=s,c=1;for(;n.some(p=>p.name===a);)a=`${s}${c++}`;let i={name:a,value:e};return n.push(i),t.set(e,i),i},H=(e,n)=>{let t=e.raw??e,r=new Map,o=[],s=new Map,a=t[0]??"",c=ye++,i=0,p=[];for(let l=0;l<n.length;l++){let u=t[l]??"",d=t[l+1]??"",m=n[l],f=he.test(u)||Ee.test(u),x;if(f&&typeof m=="function")x=we(m,o,s).name;else if(f&&typeof m=="string")x=m;else {let h=`${j}${c}_${i++}__`;r.set(h,m),x=h;}let y=a.length;a+=x;let g=a.length;p.push({index:l,sourceStart:y,sourceEnd:g}),a+=d;}return {source:a,placeholders:r,bindings:o,diagnostics:{expressionRanges:p}}};var B=e=>{let{getIdentifierName:n,evaluateExpressionWithNamespace:t}=e;return (r,o,s)=>{let a={},c=(i,p)=>{a[i]=p;};return r.forEach(i=>{if(i.type==="JSXSpreadAttribute"){let l=t(i.argument,o,s);l&&typeof l=="object"&&!Array.isArray(l)&&Object.assign(a,l);return}let p=n(i.name);if(!i.value){c(p,true);return}if(i.value.type==="Literal"){c(p,i.value.value);return}if(i.value.type==="JSXExpressionContainer"){if(i.value.expression.type==="JSXEmptyExpression")return;c(p,t(i.value.expression,o,s));}}),a}};var V="Capture",z=e=>e.endsWith(V)?{eventName:e.slice(0,-V.length),capture:true}:{eventName:e,capture:false},U=e=>{if(!e.startsWith("on"))return null;if(e.startsWith("on:")){let r=e.slice(3);if(!r)return null;let o=z(r);return o.eventName?o:null}let n=e.slice(2);if(!n)return null;let t=z(n);return t.eventName?{eventName:t.eventName.toLowerCase(),capture:t.capture}:null},q=e=>!e||typeof e!="object"?false:"handleEvent"in e&&typeof e.handleEvent=="function",ke=e=>{if(!e||typeof e!="object"||!("handler"in e))return false;let n=e.handler;return typeof n=="function"?true:q(n)},K=(e,n)=>{if(typeof n=="function"||q(n))return {listener:n};if(!ke(n))return null;let t=n,r=t.options?{...t.options}:void 0,o=(s,a)=>{a!=null&&(r||(r={}),r[s]=a);};return o("capture",t.capture),o("once",t.once),o("passive",t.passive),o("signal",t.signal??void 0),{listener:t.handler,options:r}};var Me=()=>{if(typeof document>"u"||typeof document.createElement!="function")throw new Error("The jsx template tag requires a DOM-like environment (document missing).")},De=e=>typeof Node>"u"?false:e instanceof Node||e instanceof DocumentFragment,Le=e=>!e||typeof e=="string"?false:typeof e[Symbol.iterator]=="function",Z=e=>!e||typeof e!="object"&&typeof e!="function"?false:typeof e.then=="function",Pe={xlink:"http://www.w3.org/1999/xlink",xml:"http://www.w3.org/XML/1998/namespace",xmlns:"http://www.w3.org/2000/xmlns/"},Y=e=>{if(!(!e||e==="html"||e==="svg"))return Pe[e]},Ie=e=>e==="svg"?svg:html,C=(e,n,t)=>{let r=Y(n.space),o=String(t);if(r){e.setAttributeNS(r,n.attribute,o);return}e.setAttribute(n.attribute,o);},G=(e,n)=>{let t=Y(n.space);if(t){e.removeAttributeNS(t,n.attribute);return}e.removeAttribute(n.attribute);},k=(e,n)=>Array.isArray(e)?e.filter(Boolean).join(n):e,je=(e,n,t)=>n==="svg"||!t.property||t.property.includes(":")?false:t.property in e,Oe=(e,n,t,r)=>{if(t==null)return;if(n==="dangerouslySetInnerHTML"&&typeof t=="object"&&t&&"__html"in t){e.innerHTML=String(t.__html??"");return}if(n==="ref"){if(typeof t=="function"){t(e);return}if(t&&typeof t=="object"){t.current=e;return}}if(n==="style"&&typeof t=="object"&&t!==null){let p=t,l=e.style;if(!l)return;let u=l;Object.entries(p).forEach(([d,m])=>{if(m!=null){if(d.startsWith("--")){l.setProperty(d,String(m));return}u[d]=m;}});return}let o=U(n);if(o){let p=K(n,t);if(p){let l=p.options?{...p.options}:void 0;o.capture&&(l?l.capture=true:l={capture:true}),e.addEventListener(o.eventName,p.listener,l);return}}let s=find(Ie(r),n),a=e,c=je(e,r,s);if(s.mustUseProperty){let p=s.boolean?!!t:t;a[s.property]=p;return}if(s.boolean){let p=!!t;c&&(a[s.property]=p),p?C(e,s,""):G(e,s);return}let i=t;if(s.spaceSeparated?i=k(t," "):s.commaSeparated?i=k(t,","):s.commaOrSpaceSeparated&&(i=k(t," ")),s.booleanish&&typeof i=="boolean"&&(i=i?"true":"false"),s.overloadedBoolean){if(i===false){G(e,s);return}if(i===true){C(e,s,"");return}}if(c){a[s.property]=i;return}i!==false&&C(e,s,i);},E=(e,n)=>{if(n!=null&&typeof n!="boolean"){if(Z(n))throw new Error("Async values are not supported inside jsx template results.");if(Array.isArray(n)){n.forEach(t=>E(e,t));return}if(Le(n)){for(let t of n)E(e,t);return}if(De(n)){e.appendChild(n);return}e.appendChild(document.createTextNode(String(n)));}},N=(e,n,t)=>F(e,n,r=>v(r,n,t)),Q=B({getIdentifierName:b,evaluateExpressionWithNamespace:N}),$e=(e,n,t,r)=>{let o=Q(n,t,r);Object.entries(o).forEach(([s,a])=>{if(s!=="key"){if(s==="children"){E(e,a);return}Oe(e,s,a,r);}});},A=(e,n,t)=>{let r=[];return e.forEach(o=>{switch(o.type){case "JSXText":{_(o.value,n.placeholders).forEach(a=>{r.push(a);});break}case "JSXExpressionContainer":{if(o.expression.type==="JSXEmptyExpression")break;r.push(N(o.expression,n,t));break}case "JSXSpreadChild":{let s=N(o.expression,n,t);s!=null&&r.push(s);break}case "JSXElement":case "JSXFragment":{r.push(v(o,n,t));break}}}),r},_e=(e,n,t,r)=>{let o=Q(e.openingElement.attributes,n,r),s=A(e.children,n,r);s.length===1?o.children=s[0]:s.length>1&&(o.children=s);let a=t(o);if(Z(a))throw new Error("Async jsx components are not supported.");return a},Fe=(e,n,t)=>{let r=e.openingElement,o=b(r.name),s=n.components.get(o);if(s)return _e(e,n,s,t);if(/[A-Z]/.test(o[0]??""))throw new Error(`Unknown component "${o}". Did you interpolate it with the template literal?`);let a=o==="svg"?"svg":t,c=o==="foreignObject"?null:a,i=a==="svg"?document.createElementNS("http://www.w3.org/2000/svg",o):document.createElement(o);return $e(i,r.attributes,n,a),A(e.children,n,c).forEach(l=>E(i,l)),i},v=(e,n,t)=>{if(e.type==="JSXFragment"){let r=document.createDocumentFragment();return A(e.children,n,t).forEach(s=>E(r,s)),r}return Fe(e,n,t)},ee=(e,...n)=>{Me();let t=H(e,n),r=parseSync("inline.jsx",t.source,O);if(r.errors.length>0)throw new Error(T("jsx",e,t.diagnostics,r.errors[0]));let o=$(r.program),s={source:t.source,placeholders:t.placeholders,components:new Map(t.bindings.map(a=>[a.name,a.value]))};return v(o,s,null)};D();var at=ee;
8
- export{at as jsx};
7
+ ${r.helpMessage}`),g};var Je=/<\s*$/,we=/<\/\s*$/,_="__KX_EXPR__",I=new RegExp(`${_}\\d+_\\d+__`,"g"),Te=0;var $={lang:"jsx",sourceType:"module",range:true,preserveParens:true},H=e=>{for(let t of e.body)if(t.type==="ExpressionStatement"){let n=t.expression;if(n.type==="JSXElement"||n.type==="JSXFragment")return n}throw new Error("The jsx template must contain a single JSX element or fragment.")},b=e=>{switch(e.type){case "JSXIdentifier":return e.name;case "JSXNamespacedName":return `${e.namespace.name}:${e.name.name}`;case "JSXMemberExpression":return `${b(e.object)}.${e.property.name}`;default:return ""}},C=(e,t)=>{if(!e||typeof e!="object")return;let n=e;typeof n.type=="string"&&(t(n),Object.values(n).forEach(r=>{if(r){if(Array.isArray(r)){r.forEach(s=>C(s,t));return}typeof r=="object"&&C(r,t);}}));},W=(e,t)=>{let n=O(e);if(!n)return [];let r=[];I.lastIndex=0;let s=0,o;for(;o=I.exec(n);){let l=o.index,i=n.slice(s,l);i&&r.push(i);let p=o[0];t.has(p)?r.push(t.get(p)):r.push(p),s=l+p.length;}let a=n.slice(s);return a&&r.push(a),r},Ce=(e,t)=>{let n=new Set;return C(e,r=>{r.type==="Identifier"&&t.placeholders.has(r.name)&&n.add(r.name);}),Array.from(n)},B=(e,t,n)=>{if(e.type==="JSXElement"||e.type==="JSXFragment")return n(e);if(!("range"in e)||!e.range)throw new Error("Unable to evaluate expression: missing source range information.");let[r,s]=e.range,o=t.source.slice(r,s),a=Ce(e,t);try{let l=new Function(...a,`"use strict"; return (${o});`),i=a.map(p=>t.placeholders.get(p));return l(...i)}catch(l){throw new Error(`Failed to evaluate expression ${o}: ${l.message}`,{cause:l})}},ke=e=>{let t=e.replace(/[^a-zA-Z0-9_$]/g,"");return t?/[A-Za-z_$]/.test(t[0])?t:`Component${t}`:"Component"},ve=(e,t,n)=>{let r=n.get(e);if(r)return r;let s=e.displayName||e.name||`Component${t.length}`,o=ke(s??""),a=o,l=1;for(;t.some(p=>p.name===a);)a=`${o}${l++}`;let i={name:a,value:e};return t.push(i),n.set(e,i),i},V=(e,t)=>{let n=e.raw??e,r=new Map,s=[],o=new Map,a=n[0]??"",l=Te++,i=0,p=[];for(let c=0;c<t.length;c++){let u=n[c]??"",d=n[c+1]??"",m=t[c],f=Je.test(u)||we.test(u),x;if(f&&typeof m=="function")x=ve(m,s,o).name;else if(f&&typeof m=="string")x=m;else {let E=`${_}${l}_${i++}__`;r.set(E,m),x=E;}let y=a.length;a+=x;let g=a.length;p.push({index:c,sourceStart:y,sourceEnd:g}),a+=d;}return {source:a,placeholders:r,bindings:s,diagnostics:{expressionRanges:p}}};var U=e=>{let{getIdentifierName:t,evaluateExpressionWithNamespace:n}=e;return (r,s,o)=>{let a={},l=(i,p)=>{a[i]=p;};return r.forEach(i=>{if(i.type==="JSXSpreadAttribute"){let c=n(i.argument,s,o);c&&typeof c=="object"&&!Array.isArray(c)&&Object.assign(a,c);return}let p=t(i.name);if(!i.value){l(p,true);return}if(i.value.type==="Literal"){l(p,i.value.value);return}if(i.value.type==="JSXExpressionContainer"){if(i.value.expression.type==="JSXEmptyExpression")return;l(p,n(i.value.expression,s,o));}}),a}};var q="Capture",K=e=>e.endsWith(q)?{eventName:e.slice(0,-q.length),capture:true}:{eventName:e,capture:false},G=e=>{if(!e.startsWith("on"))return null;if(e.startsWith("on:")){let r=e.slice(3);if(!r)return null;let s=K(r);return s.eventName?s:null}let t=e.slice(2);if(!t)return null;let n=K(t);return n.eventName?{eventName:n.eventName.toLowerCase(),capture:n.capture}:null},Z=e=>!e||typeof e!="object"?false:"handleEvent"in e&&typeof e.handleEvent=="function",Pe=e=>{if(!e||typeof e!="object"||!("handler"in e))return false;let t=e.handler;return typeof t=="function"?true:Z(t)},Y=(e,t)=>{if(typeof t=="function"||Z(t))return {listener:t};if(!Pe(t))return null;let n=t,r=n.options?{...n.options}:void 0,s=(o,a)=>{a!=null&&(r||(r={}),r[o]=a);};return s("capture",n.capture),s("once",n.once),s("passive",n.passive),s("signal",n.signal??void 0),{listener:n.handler,options:r}};var k=Symbol.for("@knighted/jsx::Fragment"),S="__jsxNs",De=(e,t)=>t.length>0?t:Object.prototype.hasOwnProperty.call(e,"children")?[e.children]:[],Xe=(e,t)=>{let n={...e};return t.length===1?n.children=t[0]:t.length>1?n.children=t:delete n.children,n},Me=e=>{if(!Object.prototype.hasOwnProperty.call(e,S))return;let t=e[S];if(delete e[S],t==="svg"||t===null)return t;throw new Error(`${S} must be "svg" or null when provided.`)},Q=({ensureDomAvailable:e,appendChildValue:t,setDomProp:n,isPromiseLike:r})=>{function s(o,a,...l){e();let i=a?{...a}:{},p=De(i,l);if(o===k){let m=document.createDocumentFragment();return p.forEach(f=>t(m,f)),m}if(typeof o=="function"){let m=o(Xe(i,p));if(r(m))throw new Error("Async jsx components are not supported.");return m}if(typeof o!="string")throw new Error(`Unsupported jsx createElement type: ${String(o)}`);delete i.children;let u=Me(i)??(o==="svg"?"svg":null),d=u==="svg"?document.createElementNS("http://www.w3.org/2000/svg",o):document.createElement(o);return Object.entries(i).forEach(([m,f])=>{m!=="key"&&n(d,m,f,u);}),p.forEach(m=>t(d,m)),d}return s};var te=()=>{if(typeof document>"u"||typeof document.createElement!="function")throw new Error("The jsx template tag requires a DOM-like environment (document missing).")},_e=e=>typeof Node>"u"?false:e instanceof Node||e instanceof DocumentFragment,$e=e=>!e||typeof e=="string"?false:typeof e[Symbol.iterator]=="function",A=e=>!e||typeof e!="object"&&typeof e!="function"?false:typeof e.then=="function",He={xlink:"http://www.w3.org/1999/xlink",xml:"http://www.w3.org/XML/1998/namespace",xmlns:"http://www.w3.org/2000/xmlns/"},ne=e=>{if(!(!e||e==="html"||e==="svg"))return He[e]},We=e=>e==="svg"?svg:html,v=(e,t,n)=>{let r=ne(t.space),s=String(n);if(r){e.setAttributeNS(r,t.attribute,s);return}e.setAttribute(t.attribute,s);},ee=(e,t)=>{let n=ne(t.space);if(n){e.removeAttributeNS(n,t.attribute);return}e.removeAttribute(t.attribute);},R=(e,t)=>Array.isArray(e)?e.filter(Boolean).join(t):e,Be=(e,t,n)=>t==="svg"||!n.property||n.property.includes(":")?false:n.property in e,re=(e,t,n,r)=>{if(n==null)return;if(t==="dangerouslySetInnerHTML"&&typeof n=="object"&&n&&"__html"in n){e.innerHTML=String(n.__html??"");return}if(t==="ref"){if(typeof n=="function"){n(e);return}if(n&&typeof n=="object"){n.current=e;return}}if(t==="style"&&typeof n=="object"&&n!==null){let p=n,c=e.style;if(!c)return;let u=c;Object.entries(p).forEach(([d,m])=>{if(m!=null){if(d.startsWith("--")){c.setProperty(d,String(m));return}u[d]=m;}});return}let s=G(t);if(s){let p=Y(t,n);if(p){let c=p.options?{...p.options}:void 0;s.capture&&(c?c.capture=true:c={capture:true}),e.addEventListener(s.eventName,p.listener,c);return}}let o=find(We(r),t),a=e,l=Be(e,r,o);if(o.mustUseProperty){let p=o.boolean?!!n:n;a[o.property]=p;return}if(o.boolean){let p=!!n;l&&(a[o.property]=p),p?v(e,o,""):ee(e,o);return}let i=n;if(o.spaceSeparated?i=R(n," "):o.commaSeparated?i=R(n,","):o.commaOrSpaceSeparated&&(i=R(n," ")),o.booleanish&&typeof i=="boolean"&&(i=i?"true":"false"),o.overloadedBoolean){if(i===false){ee(e,o);return}if(i===true){v(e,o,"");return}}if(l){a[o.property]=i;return}i!==false&&v(e,o,i);},h=(e,t)=>{if(t!=null&&typeof t!="boolean"){if(A(t))throw new Error("Async values are not supported inside jsx template results.");if(Array.isArray(t)){t.forEach(n=>h(e,n));return}if($e(t)){for(let n of t)h(e,n);return}if(_e(t)){e.appendChild(t);return}e.appendChild(document.createTextNode(String(t)));}},N=(e,t,n)=>B(e,t,r=>j(r,t,n)),oe=U({getIdentifierName:b,evaluateExpressionWithNamespace:N}),Ve=(e,t,n,r)=>{let s=oe(t,n,r);Object.entries(s).forEach(([o,a])=>{if(o!=="key"){if(o==="children"){h(e,a);return}re(e,o,a,r);}});},P=(e,t,n)=>{let r=[];return e.forEach(s=>{switch(s.type){case "JSXText":{W(s.value,t.placeholders).forEach(a=>{r.push(a);});break}case "JSXExpressionContainer":{if(s.expression.type==="JSXEmptyExpression")break;r.push(N(s.expression,t,n));break}case "JSXSpreadChild":{let o=N(s.expression,t,n);o!=null&&r.push(o);break}case "JSXElement":case "JSXFragment":{r.push(j(s,t,n));break}}}),r},ze=(e,t,n,r)=>{let s=oe(e.openingElement.attributes,t,r),o=P(e.children,t,r);o.length===1?s.children=o[0]:o.length>1&&(s.children=o);let a=n(s);if(A(a))throw new Error("Async jsx components are not supported.");return a},Ue=(e,t,n)=>{let r=e.openingElement,s=b(r.name),o=t.components.get(s);if(o)return ze(e,t,o,n);if(/[A-Z]/.test(s[0]??""))throw new Error(`Unknown component "${s}". Did you interpolate it with the template literal?`);let a=s==="svg"?"svg":n,l=s==="foreignObject"?null:a,i=a==="svg"?document.createElementNS("http://www.w3.org/2000/svg",s):document.createElement(s);return Ve(i,r.attributes,t,a),P(e.children,t,l).forEach(c=>h(i,c)),i},j=(e,t,n)=>{if(e.type==="JSXFragment"){let r=document.createDocumentFragment();return P(e.children,t,n).forEach(o=>h(r,o)),r}return Ue(e,t,n)},qe=Q({ensureDomAvailable:te,appendChildValue:h,setDomProp:re,isPromiseLike:A}),Ke=(e,...t)=>{te();let n=V(e,t),r=parseSync("inline.jsx",n.source,$);if(r.errors.length>0)throw new Error(T("jsx",e,n.diagnostics,r.errors[0]));let s=H(r.program),o={source:n.source,placeholders:n.placeholders,components:new Map(n.bindings.map(a=>[a.name,a.value]))};return j(s,o,null)},se=Object.assign(Ke,{createElement:qe,Fragment:k});L();var xt=se;
8
+ export{xt as jsx};
@@ -1,2 +1,6 @@
1
- export declare const jsx: (templates: TemplateStringsArray, ...values: unknown[]) => import("../../jsx.js").JsxRenderable;
1
+ export declare const jsx: {
2
+ (templates: TemplateStringsArray, ...values: unknown[]): import("../../jsx.js").JsxRenderable;
3
+ createElement: typeof import("../../jsx.js").createElement;
4
+ Fragment: import("../../internal/dom-create-element.js").JsxFragmentToken;
5
+ };
2
6
  export type { JsxRenderable, JsxComponent } from '../../jsx.js';
@@ -1,2 +1,6 @@
1
- export declare const jsx: (templates: TemplateStringsArray, ...values: unknown[]) => import("../jsx.js").JsxRenderable;
1
+ export declare const jsx: {
2
+ (templates: TemplateStringsArray, ...values: unknown[]): import("../jsx.js").JsxRenderable;
3
+ createElement: typeof import("../jsx.js").createElement;
4
+ Fragment: import("../internal/dom-create-element.js").JsxFragmentToken;
5
+ };
2
6
  export type { JsxRenderable, JsxComponent } from '../jsx.js';
@@ -0,0 +1,12 @@
1
+ type TranspileSourceType = 'module' | 'script';
2
+ export type TranspileJsxSourceOptions = {
3
+ sourceType?: TranspileSourceType;
4
+ createElement?: string;
5
+ fragment?: string;
6
+ };
7
+ export type TranspileJsxSourceResult = {
8
+ code: string;
9
+ changed: boolean;
10
+ };
11
+ export declare function transpileJsxSource(source: string, options?: TranspileJsxSourceOptions): TranspileJsxSourceResult;
12
+ export {};