@knighted/jsx 1.13.1 → 1.13.2-rc.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.
@@ -102,6 +102,21 @@ const evaluateReactJsxChildren = (children, ctx) => {
102
102
  const createReactElement = (type, props, children) => {
103
103
  return (0, react_1.createElement)(type, props, ...children);
104
104
  };
105
+ const reactMemoSymbol = Symbol.for('react.memo');
106
+ const reactForwardRefSymbol = Symbol.for('react.forward_ref');
107
+ const reactLazySymbol = Symbol.for('react.lazy');
108
+ const isReactTagBindingValue = (value) => {
109
+ if (typeof value === 'function') {
110
+ return true;
111
+ }
112
+ if (typeof value !== 'object' || value === null) {
113
+ return false;
114
+ }
115
+ const candidate = value;
116
+ return (candidate.$$typeof === reactMemoSymbol ||
117
+ candidate.$$typeof === reactForwardRefSymbol ||
118
+ candidate.$$typeof === reactLazySymbol);
119
+ };
105
120
  const evaluateReactJsxElement = (element, ctx) => {
106
121
  const opening = element.openingElement;
107
122
  const tagName = (0, shared_js_1.getIdentifierName)(opening.name);
@@ -124,7 +139,9 @@ const evaluateReactJsxNode = (node, ctx) => {
124
139
  return evaluateReactJsxElement(node, ctx);
125
140
  };
126
141
  const reactJsx = (templates, ...values) => {
127
- const build = (0, shared_js_1.buildTemplate)(templates, values);
142
+ const build = (0, shared_js_1.buildTemplate)(templates, values, {
143
+ isTagNameBindingValue: isReactTagBindingValue,
144
+ });
128
145
  const result = (0, oxc_parser_1.parseSync)('inline.jsx', build.source, shared_js_1.parserOptions);
129
146
  if (result.errors.length > 0) {
130
147
  throw new Error((0, shared_js_1.formatTaggedTemplateParserError)('reactJsx', templates, build.diagnostics, result.errors[0]));
@@ -170,7 +170,7 @@ const ensureBinding = (value, bindings, bindingLookup) => {
170
170
  return binding;
171
171
  };
172
172
  exports.ensureBinding = ensureBinding;
173
- const buildTemplate = (strings, values) => {
173
+ const buildTemplate = (strings, values, options) => {
174
174
  const raw = strings.raw ?? strings;
175
175
  const placeholders = new Map();
176
176
  const bindings = [];
@@ -179,19 +179,24 @@ const buildTemplate = (strings, values) => {
179
179
  const templateId = invocationCounter++;
180
180
  let placeholderIndex = 0;
181
181
  const expressionRanges = [];
182
+ const isTagNameBindingValue = options?.isTagNameBindingValue ??
183
+ ((value) => typeof value === 'function');
182
184
  for (let idx = 0; idx < values.length; idx++) {
183
185
  const chunk = raw[idx] ?? '';
184
186
  const nextChunk = raw[idx + 1] ?? '';
185
187
  const value = values[idx];
186
188
  const isTagNamePosition = OPEN_TAG_RE.test(chunk) || CLOSE_TAG_RE.test(chunk);
187
189
  let insertion;
188
- if (isTagNamePosition && typeof value === 'function') {
190
+ if (isTagNamePosition && isTagNameBindingValue(value)) {
189
191
  const binding = (0, exports.ensureBinding)(value, bindings, bindingLookup);
190
192
  insertion = binding.name;
191
193
  }
192
194
  else if (isTagNamePosition && typeof value === 'string') {
193
195
  insertion = value;
194
196
  }
197
+ else if (isTagNamePosition) {
198
+ throw new Error('Invalid tag interpolation value. Expected a component, class, or string tag name.');
199
+ }
195
200
  else {
196
201
  const placeholder = `${exports.PLACEHOLDER_PREFIX}${templateId}_${placeholderIndex++}__`;
197
202
  placeholders.set(placeholder, value);
@@ -22,6 +22,9 @@ export type TemplateBuildResult<TComponent extends TemplateComponent> = {
22
22
  bindings: BindingEntry<TComponent>[];
23
23
  diagnostics: TemplateDiagnostics;
24
24
  };
25
+ export type TemplateBuildOptions<TComponent extends TemplateComponent> = {
26
+ isTagNameBindingValue?: (value: unknown) => value is TComponent;
27
+ };
25
28
  export type TemplateContext<TComponent extends TemplateComponent> = {
26
29
  source: string;
27
30
  placeholders: Map<string, unknown>;
@@ -40,4 +43,4 @@ export declare const collectPlaceholderNames: <TComponent extends TemplateCompon
40
43
  export declare const evaluateExpression: <TComponent extends TemplateComponent>(expression: Expression | JSXElement | JSXFragment, ctx: TemplateContext<TComponent>, evaluateJsxNode: (node: JSXElement | JSXFragment) => unknown) => unknown;
41
44
  export declare const sanitizeIdentifier: (value: string) => string;
42
45
  export declare const ensureBinding: <TComponent extends TemplateComponent>(value: TComponent, bindings: BindingEntry<TComponent>[], bindingLookup: Map<TComponent, BindingEntry<TComponent>>) => BindingEntry<TComponent>;
43
- export declare const buildTemplate: <TComponent extends TemplateComponent>(strings: TemplateStringsArray, values: unknown[]) => TemplateBuildResult<TComponent>;
46
+ export declare const buildTemplate: <TComponent extends TemplateComponent>(strings: TemplateStringsArray, values: unknown[], options?: TemplateBuildOptions<TComponent>) => TemplateBuildResult<TComponent>;
@@ -1,8 +1,8 @@
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+=`
1
+ import {parseSync}from'oxc-parser';import {find,svg,html}from'property-information';var C=null,L=e=>{C=e;},ue=e=>{C?.warnLowercaseEventProp?.(e);},de=e=>{C?.ensureValidDangerouslySetInnerHTML?.(e);},I=e=>{let{getIdentifierName:t,evaluateExpressionWithNamespace:n}=e;return (r,s,o)=>{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,s,o);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,s,o));}}),a}};var B=null,W=e=>{B=e;},_="Capture",H=e=>e.endsWith(_)?{eventName:e.slice(0,-_.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",ge=e=>{if(!e||typeof e!="object"||!("handler"in e))return false;let t=e.handler;return typeof t=="function"?true:U(t)},fe=(e,t)=>{B?.onInvalidHandler?.(e,t);},z=(e,t)=>{if(typeof t=="function"||U(t))return {listener:t};if(!ge(t))return fe(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 xe="@knighted/jsx",K=e=>`${xe}: ${e}`,v=()=>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(K(e)),G=(e,t=false)=>{!t&&!v()||typeof console<"u"&&typeof console.warn=="function"&&console.warn(K(e));};var Ee=e=>e>="a"&&e<="z",S="env",A=()=>S==="always"||S==="env"&&v(),ye=()=>S==="always",he={warnLowercaseEventProp(e){if(!A()||!e.startsWith("on")||e.startsWith("on:")||e.length<3)return;let t=e[2]??"";if(!Ee(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}"?`,ye());},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 ${k(t)}.`)}},be={onInvalidHandler(e,t){if(A())throw b(`The "${e}" prop expects a function, EventListenerObject, or descriptor ({ handler }) but received ${k(t)}.`)}},Z=e=>{S=e?.mode,L(he),W(be);};var q=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 Se="oxc-parser",Je=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}},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)},we=(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},Q=(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}},Ce=e=>{let t=[],n=0;return e.forEach((r,s)=>{t.push(n),n+=r.length,s<e.length-1&&(n+=1);}),t},ve=(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),d=Math.max(1,p-i);return " ".repeat(l)+"^".repeat(d)}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 ""},ke=(e,t,n,r,s)=>{if(!e.length)return "";let o=e.split(`
2
+ `),a=Ce(o),c=Math.max(1,r-1),i=Math.min(o.length,s+1),p=String(i).length,l=[];for(let d=c;d<=i;d++){let m=o[d-1]??"",u=String(d).padStart(p," ");l.push(`${u} | ${m}`);let g=ve(d,m,a[d-1]??0,t,n,r,s);g&&l.push(`${" ".repeat(p)} | ${g}`);}return l.join(`
3
+ `)},R=(e,t,n,r,s)=>{let o=Se,a=`[${o}] ${r.message}`,c=r.labels?.[0];if(!c)return a;let{source:i,spans:p}=Je(t),l=Te(n,p),d=h=>we(typeof h=="number"?h:0,l,i.length),m=d(c.start),u=d(c.end);u<=m&&(u=Math.min(i.length,m+1));let g=Q(i,m),x=Q(i,Math.max(m,u-1)),E=ke(i,m,u,g.line,x.line),f=`[${o}] ${r.message}`;return f+=`
4
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 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};
5
+ ${c.message}`),E&&(f+=`
6
+ ${E}`),r.helpMessage&&(f+=`
7
+ ${r.helpMessage}`),f};var Ae=/<\s*$/,Re=/<\/\s*$/,ee="__KX_EXPR__",Y=new RegExp(`${ee}\\d+_\\d+__`,"g"),De=0;var te={lang:"jsx",sourceType:"module",range:true,preserveParens:true},ne=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 ""}},D=(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=>D(s,t));return}typeof r=="object"&&D(r,t);}}));},re=(e,t)=>{let n=q(e);if(!n)return [];let r=[];Y.lastIndex=0;let s=0,o;for(;o=Y.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},Ne=(e,t)=>{let n=new Set;return D(e,r=>{r.type==="Identifier"&&t.placeholders.has(r.name)&&n.add(r.name);}),Array.from(n)},oe=(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=Ne(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})}},Pe=e=>{let t=e.replace(/[^a-zA-Z0-9_$]/g,"");return t?/[A-Za-z_$]/.test(t[0])?t:`Component${t}`:"Component"},je=(e,t,n)=>{let r=n.get(e);if(r)return r;let s=e.displayName||e.name||`Component${t.length}`,o=Pe(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},se=(e,t,n)=>{let r=e.raw??e,s=new Map,o=[],a=new Map,c=r[0]??"",i=De++,p=0,l=[],d=(m=>typeof m=="function");for(let m=0;m<t.length;m++){let u=r[m]??"",g=r[m+1]??"",x=t[m],E=Ae.test(u)||Re.test(u),f;if(E&&d(x))f=je(x,o,a).name;else if(E&&typeof x=="string")f=x;else {if(E)throw new Error("Invalid tag interpolation value. Expected a component, class, or string tag name.");{let w=`${ee}${i}_${p++}__`;s.set(w,x),f=w;}}let h=c.length;c+=f;let F=c.length;l.push({index:m,sourceStart:h,sourceEnd:F}),c+=g;}return {source:c,placeholders:s,bindings:o,diagnostics:{expressionRanges:l}}};var N=Symbol.for("@knighted/jsx::Fragment"),T="__jsxNs",Xe=(e,t)=>t.length>0?t:Object.prototype.hasOwnProperty.call(e,"children")?[e.children]:[],Me=(e,t)=>{let n={...e};return t.length===1?n.children=t[0]:t.length>1?n.children=t:delete n.children,n},$e=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.`)},ae=({ensureDomAvailable:e,appendChildValue:t,setDomProp:n,isPromiseLike:r})=>{function s(o,a,...c){e();let i=a?{...a}:{},p=Xe(i,c);if(o===N){let u=document.createDocumentFragment();return p.forEach(g=>t(u,g)),u}if(typeof o=="function"){let u=o(Me(i,p));if(r(u))throw new Error("Async jsx components are not supported.");return u}if(typeof o!="string")throw new Error(`Unsupported jsx createElement type: ${String(o)}`);delete i.children;let d=$e(i)??(o==="svg"?"svg":null),m=d==="svg"?document.createElementNS("http://www.w3.org/2000/svg",o):document.createElement(o);return Object.entries(i).forEach(([u,g])=>{u!=="key"&&n(m,u,g,d);}),p.forEach(u=>t(m,u)),m}return s};var pe=()=>{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,He=e=>!e||typeof e=="string"?false:typeof e[Symbol.iterator]=="function",M=e=>!e||typeof e!="object"&&typeof e!="function"?false:typeof e.then=="function",Be={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 Be[e]},We=e=>e==="svg"?svg:html,P=(e,t,n)=>{let r=ce(t.space),s=String(n);if(r){e.setAttributeNS(r,t.attribute,s);return}e.setAttribute(t.attribute,s);},ie=(e,t)=>{let n=ce(t.space);if(n){e.removeAttributeNS(n,t.attribute);return}e.removeAttribute(t.attribute);},j=(e,t)=>Array.isArray(e)?e.filter(Boolean).join(t):e,Ve=(e,t,n)=>t==="svg"||!n.property||n.property.includes(":")?false:n.property in e,le=(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 d=l;Object.entries(p).forEach(([m,u])=>{if(u!=null){if(m.startsWith("--")){l.setProperty(m,String(u));return}d[m]=u;}});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(We(r),t),a=e,c=Ve(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?P(e,o,""):ie(e,o);return}let i=n;if(o.spaceSeparated?i=j(n," "):o.commaSeparated?i=j(n,","):o.commaOrSpaceSeparated&&(i=j(n," ")),o.booleanish&&typeof i=="boolean"&&(i=i?"true":"false"),o.overloadedBoolean){if(i===false){ie(e,o);return}if(i===true){P(e,o,"");return}}if(c){a[o.property]=i;return}i!==false&&P(e,o,i);},y=(e,t)=>{if(t!=null&&typeof t!="boolean"){if(M(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(He(t)){for(let n of t)y(e,n);return}if(_e(t)){e.appendChild(t);return}e.appendChild(document.createTextNode(String(t)));}},X=(e,t,n)=>oe(e,t,r=>O(r,t,n)),me=I({getIdentifierName:J,evaluateExpressionWithNamespace:X}),Ue=(e,t,n,r)=>{let s=me(t,n,r);Object.entries(s).forEach(([o,a])=>{if(o!=="key"){if(o==="children"){y(e,a);return}le(e,o,a,r);}});},$=(e,t,n)=>{let r=[];return e.forEach(s=>{switch(s.type){case "JSXText":{re(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(O(s,t,n));break}}}),r},ze=(e,t,n,r)=>{let s=me(e.openingElement.attributes,t,r),o=$(e.children,t,r);o.length===1?s.children=o[0]:o.length>1&&(s.children=o);let a=n(s);if(M(a))throw new Error("Async jsx components are not supported.");return a},Ke=(e,t,n)=>{let r=e.openingElement,s=J(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,c=s==="foreignObject"?null:a,i=a==="svg"?document.createElementNS("http://www.w3.org/2000/svg",s):document.createElement(s);return Ue(i,r.attributes,t,a),$(e.children,t,c).forEach(l=>y(i,l)),i},O=(e,t,n)=>{if(e.type==="JSXFragment"){let r=document.createDocumentFragment();return $(e.children,t,n).forEach(o=>y(r,o)),r}return Ke(e,t,n)},Ge=ae({ensureDomAvailable:pe,appendChildValue:y,setDomProp:le,isPromiseLike:M}),Ze=(e,...t)=>{pe();let n=se(e,t),r=parseSync("inline.jsx",n.source,te);if(r.errors.length>0)throw new Error(R("jsx",e,n.diagnostics,r.errors[0]));let s=ne(r.program),o={source:n.source,placeholders:n.placeholders,components:new Map(n.bindings.map(a=>[a.name,a.value]))};return O(s,o,null)},qe=Object.assign(Ze,{createElement:Ge,Fragment:N});Z({mode:"always"});
8
+ export{qe as jsx};
@@ -1,8 +1,8 @@
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+=`
1
+ import {parseSync}from'oxc-parser';import {find,svg,html}from'property-information';var j=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 te="oxc-parser",ne=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}},re=(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)},oe=(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},D=(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}},se=e=>{let t=[],n=0;return e.forEach((r,s)=>{t.push(n),n+=r.length,s<e.length-1&&(n+=1);}),t},ae=(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),d=Math.max(1,p-i);return " ".repeat(c)+"^".repeat(d)}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 ""},ie=(e,t,n,r,s)=>{if(!e.length)return "";let o=e.split(`
2
+ `),a=se(o),l=Math.max(1,r-1),i=Math.min(o.length,s+1),p=String(i).length,c=[];for(let d=l;d<=i;d++){let m=o[d-1]??"",u=String(d).padStart(p," ");c.push(`${u} | ${m}`);let g=ae(d,m,a[d-1]??0,t,n,r,s);g&&c.push(`${" ".repeat(p)} | ${g}`);}return c.join(`
3
+ `)},T=(e,t,n,r,s)=>{let o=te,a=`[${o}] ${r.message}`,l=r.labels?.[0];if(!l)return a;let{source:i,spans:p}=ne(t),c=re(n,p),d=h=>oe(typeof h=="number"?h:0,c,i.length),m=d(l.start),u=d(l.end);u<=m&&(u=Math.min(i.length,m+1));let g=D(i,m),x=D(i,Math.max(m,u-1)),E=ie(i,m,u,g.line,x.line),f=`[${o}] ${r.message}`;return f+=`
4
4
  --> ${e} template:${g.line}:${g.column}`,l.message&&(f+=`
5
- ${l.message}`),h&&(f+=`
6
- ${h}`),r.helpMessage&&(f+=`
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};
5
+ ${l.message}`),E&&(f+=`
6
+ ${E}`),r.helpMessage&&(f+=`
7
+ ${r.helpMessage}`),f};var pe=/<\s*$/,le=/<\/\s*$/,O="__KX_EXPR__",F=new RegExp(`${O}\\d+_\\d+__`,"g"),ce=0;var M={lang:"jsx",sourceType:"module",range:true,preserveParens:true},L=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 ""}},w=(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=>w(s,t));return}typeof r=="object"&&w(r,t);}}));},I=(e,t)=>{let n=j(e);if(!n)return [];let r=[];F.lastIndex=0;let s=0,o;for(;o=F.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},me=(e,t)=>{let n=new Set;return w(e,r=>{r.type==="Identifier"&&t.placeholders.has(r.name)&&n.add(r.name);}),Array.from(n)},$=(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=me(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})}},ue=e=>{let t=e.replace(/[^a-zA-Z0-9_$]/g,"");return t?/[A-Za-z_$]/.test(t[0])?t:`Component${t}`:"Component"},de=(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,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,n)=>{let r=e.raw??e,s=new Map,o=[],a=new Map,l=r[0]??"",i=ce++,p=0,c=[],d=(m=>typeof m=="function");for(let m=0;m<t.length;m++){let u=r[m]??"",g=r[m+1]??"",x=t[m],E=pe.test(u)||le.test(u),f;if(E&&d(x))f=de(x,o,a).name;else if(E&&typeof x=="string")f=x;else {if(E)throw new Error("Invalid tag interpolation value. Expected a component, class, or string tag name.");{let J=`${O}${i}_${p++}__`;s.set(J,x),f=J;}}let h=l.length;l+=f;let X=l.length;c.push({index:m,sourceStart:h,sourceEnd:X}),l+=g;}return {source:l,placeholders:s,bindings:o,diagnostics:{expressionRanges:c}}};var B=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 W="Capture",V=e=>e.endsWith(W)?{eventName:e.slice(0,-W.length),capture:true}:{eventName:e,capture:false},z=e=>{if(!e.startsWith("on"))return null;if(e.startsWith("on:")){let r=e.slice(3);if(!r)return null;let s=V(r);return s.eventName?s:null}let t=e.slice(2);if(!t)return null;let n=V(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",Ee=e=>{if(!e||typeof e!="object"||!("handler"in e))return false;let t=e.handler;return typeof t=="function"?true:U(t)},K=(e,t)=>{if(typeof t=="function"||U(t))return {listener:t};if(!Ee(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 C=Symbol.for("@knighted/jsx::Fragment"),S="__jsxNs",he=(e,t)=>t.length>0?t:Object.prototype.hasOwnProperty.call(e,"children")?[e.children]:[],be=(e,t)=>{let n={...e};return t.length===1?n.children=t[0]:t.length>1?n.children=t:delete n.children,n},Se=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.`)},Z=({ensureDomAvailable:e,appendChildValue:t,setDomProp:n,isPromiseLike:r})=>{function s(o,a,...l){e();let i=a?{...a}:{},p=he(i,l);if(o===C){let u=document.createDocumentFragment();return p.forEach(g=>t(u,g)),u}if(typeof o=="function"){let u=o(be(i,p));if(r(u))throw new Error("Async jsx components are not supported.");return u}if(typeof o!="string")throw new Error(`Unsupported jsx createElement type: ${String(o)}`);delete i.children;let d=Se(i)??(o==="svg"?"svg":null),m=d==="svg"?document.createElementNS("http://www.w3.org/2000/svg",o):document.createElement(o);return Object.entries(i).forEach(([u,g])=>{u!=="key"&&n(m,u,g,d);}),p.forEach(u=>t(m,u)),m}return s};var G=()=>{if(typeof document>"u"||typeof document.createElement!="function")throw new Error("The jsx template tag requires a DOM-like environment (document missing).")},ke=e=>typeof Node>"u"?false:e instanceof Node||e instanceof DocumentFragment,ve=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",Re={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 Re[e]},Ae=e=>e==="svg"?svg:html,k=(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);},q=(e,t)=>{let n=Q(t.space);if(n){e.removeAttributeNS(n,t.attribute);return}e.removeAttribute(t.attribute);},v=(e,t)=>Array.isArray(e)?e.filter(Boolean).join(t):e,Ne=(e,t,n)=>t==="svg"||!n.property||n.property.includes(":")?false:n.property in e,Y=(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 d=c;Object.entries(p).forEach(([m,u])=>{if(u!=null){if(m.startsWith("--")){c.setProperty(m,String(u));return}d[m]=u;}});return}let s=z(t);if(s){let p=K(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(Ae(r),t),a=e,l=Ne(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?k(e,o,""):q(e,o);return}let i=n;if(o.spaceSeparated?i=v(n," "):o.commaSeparated?i=v(n,","):o.commaOrSpaceSeparated&&(i=v(n," ")),o.booleanish&&typeof i=="boolean"&&(i=i?"true":"false"),o.overloadedBoolean){if(i===false){q(e,o);return}if(i===true){k(e,o,"");return}}if(l){a[o.property]=i;return}i!==false&&k(e,o,i);},y=(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=>y(e,n));return}if(ve(t)){for(let n of t)y(e,n);return}if(ke(t)){e.appendChild(t);return}e.appendChild(document.createTextNode(String(t)));}},R=(e,t,n)=>$(e,t,r=>P(r,t,n)),ee=B({getIdentifierName:b,evaluateExpressionWithNamespace:R}),Pe=(e,t,n,r)=>{let s=ee(t,n,r);Object.entries(s).forEach(([o,a])=>{if(o!=="key"){if(o==="children"){y(e,a);return}Y(e,o,a,r);}});},N=(e,t,n)=>{let r=[];return e.forEach(s=>{switch(s.type){case "JSXText":{I(s.value,t.placeholders).forEach(a=>{r.push(a);});break}case "JSXExpressionContainer":{if(s.expression.type==="JSXEmptyExpression")break;r.push(R(s.expression,t,n));break}case "JSXSpreadChild":{let o=R(s.expression,t,n);o!=null&&r.push(o);break}case "JSXElement":case "JSXFragment":{r.push(P(s,t,n));break}}}),r},Xe=(e,t,n,r)=>{let s=ee(e.openingElement.attributes,t,r),o=N(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},je=(e,t,n)=>{let r=e.openingElement,s=b(r.name),o=t.components.get(s);if(o)return Xe(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 Pe(i,r.attributes,t,a),N(e.children,t,l).forEach(c=>y(i,c)),i},P=(e,t,n)=>{if(e.type==="JSXFragment"){let r=document.createDocumentFragment();return N(e.children,t,n).forEach(o=>y(r,o)),r}return je(e,t,n)},De=Z({ensureDomAvailable:G,appendChildValue:y,setDomProp:Y,isPromiseLike:A}),Fe=(e,...t)=>{G();let n=_(e,t),r=parseSync("inline.jsx",n.source,M);if(r.errors.length>0)throw new Error(T("jsx",e,n.diagnostics,r.errors[0]));let s=L(r.program),o={source:n.source,placeholders:n.placeholders,components:new Map(n.bindings.map(a=>[a.name,a.value]))};return P(s,o,null)},Oe=Object.assign(Fe,{createElement:De,Fragment:C});
8
+ export{Oe 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;},Ee=e=>{T?.warnLowercaseEventProp?.(e);},he=e=>{T?.ensureValidDangerouslySetInnerHTML?.(e);},$=e=>{let{getIdentifierName:t,evaluateExpressionWithNamespace:n}=e;return (r,s,o)=>{let a={},c=(i,p)=>{i==="dangerouslySetInnerHTML"&&he(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",ye=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(!ye(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 Je=e=>e>="a"&&e<="z",S="env",v=()=>S==="always"||S==="env"&&C(),we=()=>S==="always",Te={warnLowercaseEventProp(e){if(!v()||!e.startsWith("on")||e.startsWith("on:")||e.length<3)return;let t=e[2]??"";if(!Je(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}"?`,we());},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)),y=Fe(i,d,m,g.line,x.line),f=`[${o}] ${r.message}`;return f+=`
1
+ import {createRequire}from'module';import {parseSync}from'oxc-parser';import {find,svg,html}from'property-information';var C=null,F=e=>{C=e;},ye=e=>{C?.warnLowercaseEventProp?.(e);},be=e=>{C?.ensureValidDangerouslySetInnerHTML?.(e);},H=e=>{let{getIdentifierName:t,evaluateExpressionWithNamespace:n}=e;return (r,s,o)=>{let a={},c=(i,p)=>{i==="dangerouslySetInnerHTML"&&be(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(ye(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 V=null,U=e=>{V=e;},W="Capture",B=e=>e.endsWith(W)?{eventName:e.slice(0,-W.length),capture:true}:{eventName:e,capture:false},z=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},q=e=>!e||typeof e!="object"?false:"handleEvent"in e&&typeof e.handleEvent=="function",Se=e=>{if(!e||typeof e!="object"||!("handler"in e))return false;let t=e.handler;return typeof t=="function"?true:q(t)},we=(e,t)=>{V?.onInvalidHandler?.(e,t);},G=(e,t)=>{if(typeof t=="function"||q(t))return {listener:t};if(!Se(t))return we(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 Je="@knighted/jsx",K=e=>`${Je}: ${e}`,k=()=>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(K(e)),Z=(e,t=false)=>{!t&&!k()||typeof console<"u"&&typeof console.warn=="function"&&console.warn(K(e));};var Te=e=>e>="a"&&e<="z",S="env",D=()=>S==="always"||S==="env"&&k(),Ce=()=>S==="always",ke={warnLowercaseEventProp(e){if(!D()||!e.startsWith("on")||e.startsWith("on:")||e.length<3)return;let t=e[2]??"";if(!Te(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}"?`,Ce());},ensureValidDangerouslySetInnerHTML(e){if(!D())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)}.`)}},ve={onInvalidHandler(e,t){if(D())throw b(`The "${e}" prop expects a function, EventListenerObject, or descriptor ({ handler }) but received ${v(t)}.`)}},Y=e=>{S=e?.mode,F(ke),U(ve);};var Re=createRequire(import.meta.url),ee=()=>Re,te="<!doctype html><html><body></body></html>",Ae=["window","self","document","HTMLElement","Element","Node","DocumentFragment","customElements","Text","Comment","MutationObserver","navigator"],Pe=()=>typeof document<"u"&&typeof document.createElement=="function",je=e=>{let t=globalThis,n=e;Ae.forEach(r=>{t[r]===void 0&&n[r]!==void 0&&(t[r]=n[r]);});},R=()=>{let{parseHTML:e}=ee()("linkedom"),{window:t}=e(te);return t},N=()=>{let{JSDOM:e}=ee()("jsdom"),{window:t}=new e(te);return t},Me=()=>{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"},Xe=()=>{let e=Me();return e==="linkedom"?[R,N]:e==="jsdom"?[N,R]:[R,N]},Le=()=>{let e=[];for(let n of Xe())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)},Q=false,ne=()=>{if(Pe()||Q)return;let e=Le();je(e),Q=true;};var re=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 Oe="oxc-parser",Ie=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}},_e=(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},oe=(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}},Fe=e=>{let t=[],n=0;return e.forEach((r,s)=>{t.push(n),n+=r.length,s<e.length-1&&(n+=1);}),t},He=(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),d=Math.max(1,p-i);return " ".repeat(l)+"^".repeat(d)}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 ""},We=(e,t,n,r,s)=>{if(!e.length)return "";let o=e.split(`
2
+ `),a=Fe(o),c=Math.max(1,r-1),i=Math.min(o.length,s+1),p=String(i).length,l=[];for(let d=c;d<=i;d++){let m=o[d-1]??"",u=String(d).padStart(p," ");l.push(`${u} | ${m}`);let g=He(d,m,a[d-1]??0,t,n,r,s);g&&l.push(`${" ".repeat(p)} | ${g}`);}return l.join(`
3
+ `)},A=(e,t,n,r,s)=>{let o=Oe,a=`[${o}] ${r.message}`,c=r.labels?.[0];if(!c)return a;let{source:i,spans:p}=Ie(t),l=_e(n,p),d=y=>$e(typeof y=="number"?y:0,l,i.length),m=d(c.start),u=d(c.end);u<=m&&(u=Math.min(i.length,m+1));let g=oe(i,m),x=oe(i,Math.max(m,u-1)),E=We(i,m,u,g.line,x.line),f=`[${o}] ${r.message}`;return f+=`
4
4
  --> ${e} template:${g.line}:${g.column}`,c.message&&(f+=`
5
- ${c.message}`),y&&(f+=`
6
- ${y}`),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.")},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 ""}},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 y=a.length;a+=x;let f=a.length;p.push({index:l,sourceStart:y,sourceEnd:f}),a+=d;}return {source:a,placeholders:r,bindings:s,diagnostics:{expressionRanges:p}}};var P=Symbol.for("@knighted/jsx::Fragment"),w="__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,w))return;let t=e[w];if(delete e[w],t==="svg"||t===null)return t;throw new Error(`${w} 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);},h=(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=>h(e,n));return}if(nt(t)){for(let n of t)h(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:J,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"){h(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=J(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=>h(i,l)),i},_=(e,t,n)=>{if(e.type==="JSXFragment"){let r=document.createDocumentFragment();return O(e.children,t,n).forEach(o=>h(r,o)),r}return pt(e,t,n)},ct=le({ensureDomAvailable:ue,appendChildValue:h,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};
5
+ ${c.message}`),E&&(f+=`
6
+ ${E}`),r.helpMessage&&(f+=`
7
+ ${r.helpMessage}`),f};var Be=/<\s*$/,Ve=/<\/\s*$/,ae="__KX_EXPR__",se=new RegExp(`${ae}\\d+_\\d+__`,"g"),Ue=0;var ie={lang:"jsx",sourceType:"module",range:true,preserveParens:true},pe=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 ""}},P=(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=>P(s,t));return}typeof r=="object"&&P(r,t);}}));},ce=(e,t)=>{let n=re(e);if(!n)return [];let r=[];se.lastIndex=0;let s=0,o;for(;o=se.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},ze=(e,t)=>{let n=new Set;return P(e,r=>{r.type==="Identifier"&&t.placeholders.has(r.name)&&n.add(r.name);}),Array.from(n)},le=(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=ze(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})}},qe=e=>{let t=e.replace(/[^a-zA-Z0-9_$]/g,"");return t?/[A-Za-z_$]/.test(t[0])?t:`Component${t}`:"Component"},Ge=(e,t,n)=>{let r=n.get(e);if(r)return r;let s=e.displayName||e.name||`Component${t.length}`,o=qe(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},me=(e,t,n)=>{let r=e.raw??e,s=new Map,o=[],a=new Map,c=r[0]??"",i=Ue++,p=0,l=[],d=(m=>typeof m=="function");for(let m=0;m<t.length;m++){let u=r[m]??"",g=r[m+1]??"",x=t[m],E=Be.test(u)||Ve.test(u),f;if(E&&d(x))f=Ge(x,o,a).name;else if(E&&typeof x=="string")f=x;else {if(E)throw new Error("Invalid tag interpolation value. Expected a component, class, or string tag name.");{let T=`${ae}${i}_${p++}__`;s.set(T,x),f=T;}}let y=c.length;c+=f;let $=c.length;l.push({index:m,sourceStart:y,sourceEnd:$}),c+=g;}return {source:c,placeholders:s,bindings:o,diagnostics:{expressionRanges:l}}};var j=Symbol.for("@knighted/jsx::Fragment"),J="__jsxNs",Ke=(e,t)=>t.length>0?t:Object.prototype.hasOwnProperty.call(e,"children")?[e.children]:[],Ze=(e,t)=>{let n={...e};return t.length===1?n.children=t[0]:t.length>1?n.children=t:delete n.children,n},Ye=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.`)},ue=({ensureDomAvailable:e,appendChildValue:t,setDomProp:n,isPromiseLike:r})=>{function s(o,a,...c){e();let i=a?{...a}:{},p=Ke(i,c);if(o===j){let u=document.createDocumentFragment();return p.forEach(g=>t(u,g)),u}if(typeof o=="function"){let u=o(Ze(i,p));if(r(u))throw new Error("Async jsx components are not supported.");return u}if(typeof o!="string")throw new Error(`Unsupported jsx createElement type: ${String(o)}`);delete i.children;let d=Ye(i)??(o==="svg"?"svg":null),m=d==="svg"?document.createElementNS("http://www.w3.org/2000/svg",o):document.createElement(o);return Object.entries(i).forEach(([u,g])=>{u!=="key"&&n(m,u,g,d);}),p.forEach(u=>t(m,u)),m}return s};var ge=()=>{if(typeof document>"u"||typeof document.createElement!="function")throw new Error("The jsx template tag requires a DOM-like environment (document missing).")},rt=e=>typeof Node>"u"?false:e instanceof Node||e instanceof DocumentFragment,ot=e=>!e||typeof e=="string"?false:typeof e[Symbol.iterator]=="function",O=e=>!e||typeof e!="object"&&typeof e!="function"?false:typeof e.then=="function",st={xlink:"http://www.w3.org/1999/xlink",xml:"http://www.w3.org/XML/1998/namespace",xmlns:"http://www.w3.org/2000/xmlns/"},fe=e=>{if(!(!e||e==="html"||e==="svg"))return st[e]},at=e=>e==="svg"?svg:html,M=(e,t,n)=>{let r=fe(t.space),s=String(n);if(r){e.setAttributeNS(r,t.attribute,s);return}e.setAttribute(t.attribute,s);},de=(e,t)=>{let n=fe(t.space);if(n){e.removeAttributeNS(n,t.attribute);return}e.removeAttribute(t.attribute);},X=(e,t)=>Array.isArray(e)?e.filter(Boolean).join(t):e,it=(e,t,n)=>t==="svg"||!n.property||n.property.includes(":")?false:n.property in e,xe=(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 d=l;Object.entries(p).forEach(([m,u])=>{if(u!=null){if(m.startsWith("--")){l.setProperty(m,String(u));return}d[m]=u;}});return}let s=z(t);if(s){let p=G(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(at(r),t),a=e,c=it(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?M(e,o,""):de(e,o);return}let i=n;if(o.spaceSeparated?i=X(n," "):o.commaSeparated?i=X(n,","):o.commaOrSpaceSeparated&&(i=X(n," ")),o.booleanish&&typeof i=="boolean"&&(i=i?"true":"false"),o.overloadedBoolean){if(i===false){de(e,o);return}if(i===true){M(e,o,"");return}}if(c){a[o.property]=i;return}i!==false&&M(e,o,i);},h=(e,t)=>{if(t!=null&&typeof t!="boolean"){if(O(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(ot(t)){for(let n of t)h(e,n);return}if(rt(t)){e.appendChild(t);return}e.appendChild(document.createTextNode(String(t)));}},L=(e,t,n)=>le(e,t,r=>_(r,t,n)),Ee=H({getIdentifierName:w,evaluateExpressionWithNamespace:L}),pt=(e,t,n,r)=>{let s=Ee(t,n,r);Object.entries(s).forEach(([o,a])=>{if(o!=="key"){if(o==="children"){h(e,a);return}xe(e,o,a,r);}});},I=(e,t,n)=>{let r=[];return e.forEach(s=>{switch(s.type){case "JSXText":{ce(s.value,t.placeholders).forEach(a=>{r.push(a);});break}case "JSXExpressionContainer":{if(s.expression.type==="JSXEmptyExpression")break;r.push(L(s.expression,t,n));break}case "JSXSpreadChild":{let o=L(s.expression,t,n);o!=null&&r.push(o);break}case "JSXElement":case "JSXFragment":{r.push(_(s,t,n));break}}}),r},ct=(e,t,n,r)=>{let s=Ee(e.openingElement.attributes,t,r),o=I(e.children,t,r);o.length===1?s.children=o[0]:o.length>1&&(s.children=o);let a=n(s);if(O(a))throw new Error("Async jsx components are not supported.");return a},lt=(e,t,n)=>{let r=e.openingElement,s=w(r.name),o=t.components.get(s);if(o)return ct(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 pt(i,r.attributes,t,a),I(e.children,t,c).forEach(l=>h(i,l)),i},_=(e,t,n)=>{if(e.type==="JSXFragment"){let r=document.createDocumentFragment();return I(e.children,t,n).forEach(o=>h(r,o)),r}return lt(e,t,n)},mt=ue({ensureDomAvailable:ge,appendChildValue:h,setDomProp:xe,isPromiseLike:O}),ut=(e,...t)=>{ge();let n=me(e,t),r=parseSync("inline.jsx",n.source,ie);if(r.errors.length>0)throw new Error(A("jsx",e,n.diagnostics,r.errors[0]));let s=pe(r.program),o={source:n.source,placeholders:n.placeholders,components:new Map(n.bindings.map(a=>[a.name,a.value]))};return _(s,o,null)},he=Object.assign(ut,{createElement:mt,Fragment:j});Y({mode:"always"});ne();var It=he;
8
+ export{It as jsx};
@@ -1,8 +1,8 @@
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
- ${y}`),r.helpMessage&&(g+=`
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
+ import {createRequire}from'module';import {parseSync}from'oxc-parser';import {find,svg,html}from'property-information';var le=createRequire(import.meta.url),L=()=>le,O="<!doctype html><html><body></body></html>",me=["window","self","document","HTMLElement","Element","Node","DocumentFragment","customElements","Text","Comment","MutationObserver","navigator"],ue=()=>typeof document<"u"&&typeof document.createElement=="function",de=e=>{let t=globalThis,n=e;me.forEach(r=>{t[r]===void 0&&n[r]!==void 0&&(t[r]=n[r]);});},J=()=>{let{parseHTML:e}=L()("linkedom"),{window:t}=e(O);return t},w=()=>{let{JSDOM:e}=L()("jsdom"),{window:t}=new e(O);return t},ge=()=>{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"},fe=()=>{let e=ge();return e==="linkedom"?[J,w]:e==="jsdom"?[w,J]:[J,w]},xe=()=>{let e=[];for(let n of fe())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)},M=false,F=()=>{if(ue()||M)return;let e=xe();de(e),M=true;};var I=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 Ee="oxc-parser",he=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}},ye=(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)},be=(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},_=(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}},Se=e=>{let t=[],n=0;return e.forEach((r,s)=>{t.push(n),n+=r.length,s<e.length-1&&(n+=1);}),t},Te=(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),d=Math.max(1,p-i);return " ".repeat(c)+"^".repeat(d)}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 ""},Je=(e,t,n,r,s)=>{if(!e.length)return "";let o=e.split(`
2
+ `),a=Se(o),l=Math.max(1,r-1),i=Math.min(o.length,s+1),p=String(i).length,c=[];for(let d=l;d<=i;d++){let m=o[d-1]??"",u=String(d).padStart(p," ");c.push(`${u} | ${m}`);let g=Te(d,m,a[d-1]??0,t,n,r,s);g&&c.push(`${" ".repeat(p)} | ${g}`);}return c.join(`
3
+ `)},C=(e,t,n,r,s)=>{let o=Ee,a=`[${o}] ${r.message}`,l=r.labels?.[0];if(!l)return a;let{source:i,spans:p}=he(t),c=ye(n,p),d=y=>be(typeof y=="number"?y:0,c,i.length),m=d(l.start),u=d(l.end);u<=m&&(u=Math.min(i.length,m+1));let g=_(i,m),x=_(i,Math.max(m,u-1)),E=Je(i,m,u,g.line,x.line),f=`[${o}] ${r.message}`;return f+=`
4
+ --> ${e} template:${g.line}:${g.column}`,l.message&&(f+=`
5
+ ${l.message}`),E&&(f+=`
6
+ ${E}`),r.helpMessage&&(f+=`
7
+ ${r.helpMessage}`),f};var we=/<\s*$/,Ce=/<\/\s*$/,H="__KX_EXPR__",$=new RegExp(`${H}\\d+_\\d+__`,"g"),ke=0;var B={lang:"jsx",sourceType:"module",range:true,preserveParens:true},W=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 ""}},k=(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=>k(s,t));return}typeof r=="object"&&k(r,t);}}));},V=(e,t)=>{let n=I(e);if(!n)return [];let r=[];$.lastIndex=0;let s=0,o;for(;o=$.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},ve=(e,t)=>{let n=new Set;return k(e,r=>{r.type==="Identifier"&&t.placeholders.has(r.name)&&n.add(r.name);}),Array.from(n)},z=(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 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})}},Ne=e=>{let t=e.replace(/[^a-zA-Z0-9_$]/g,"");return t?/[A-Za-z_$]/.test(t[0])?t:`Component${t}`:"Component"},Re=(e,t,n)=>{let r=n.get(e);if(r)return r;let s=e.displayName||e.name||`Component${t.length}`,o=Ne(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},U=(e,t,n)=>{let r=e.raw??e,s=new Map,o=[],a=new Map,l=r[0]??"",i=ke++,p=0,c=[],d=(m=>typeof m=="function");for(let m=0;m<t.length;m++){let u=r[m]??"",g=r[m+1]??"",x=t[m],E=we.test(u)||Ce.test(u),f;if(E&&d(x))f=Re(x,o,a).name;else if(E&&typeof x=="string")f=x;else {if(E)throw new Error("Invalid tag interpolation value. Expected a component, class, or string tag name.");{let T=`${H}${i}_${p++}__`;s.set(T,x),f=T;}}let y=l.length;l+=f;let X=l.length;c.push({index:m,sourceStart:y,sourceEnd:X}),l+=g;}return {source:l,placeholders:s,bindings:o,diagnostics:{expressionRanges:c}}};var K=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 G="Capture",Z=e=>e.endsWith(G)?{eventName:e.slice(0,-G.length),capture:true}:{eventName:e,capture:false},Y=e=>{if(!e.startsWith("on"))return null;if(e.startsWith("on:")){let r=e.slice(3);if(!r)return null;let s=Z(r);return s.eventName?s:null}let t=e.slice(2);if(!t)return null;let n=Z(t);return n.eventName?{eventName:n.eventName.toLowerCase(),capture:n.capture}:null},Q=e=>!e||typeof e!="object"?false:"handleEvent"in e&&typeof e.handleEvent=="function",De=e=>{if(!e||typeof e!="object"||!("handler"in e))return false;let t=e.handler;return typeof t=="function"?true:Q(t)},ee=(e,t)=>{if(typeof t=="function"||Q(t))return {listener:t};if(!De(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 v=Symbol.for("@knighted/jsx::Fragment"),S="__jsxNs",Me=(e,t)=>t.length>0?t:Object.prototype.hasOwnProperty.call(e,"children")?[e.children]:[],Le=(e,t)=>{let n={...e};return t.length===1?n.children=t[0]:t.length>1?n.children=t:delete n.children,n},Oe=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.`)},te=({ensureDomAvailable:e,appendChildValue:t,setDomProp:n,isPromiseLike:r})=>{function s(o,a,...l){e();let i=a?{...a}:{},p=Me(i,l);if(o===v){let u=document.createDocumentFragment();return p.forEach(g=>t(u,g)),u}if(typeof o=="function"){let u=o(Le(i,p));if(r(u))throw new Error("Async jsx components are not supported.");return u}if(typeof o!="string")throw new Error(`Unsupported jsx createElement type: ${String(o)}`);delete i.children;let d=Oe(i)??(o==="svg"?"svg":null),m=d==="svg"?document.createElementNS("http://www.w3.org/2000/svg",o):document.createElement(o);return Object.entries(i).forEach(([u,g])=>{u!=="key"&&n(m,u,g,d);}),p.forEach(u=>t(m,u)),m}return s};var re=()=>{if(typeof document>"u"||typeof document.createElement!="function")throw new Error("The jsx template tag requires a DOM-like environment (document missing).")},He=e=>typeof Node>"u"?false:e instanceof Node||e instanceof DocumentFragment,Be=e=>!e||typeof e=="string"?false:typeof e[Symbol.iterator]=="function",P=e=>!e||typeof e!="object"&&typeof e!="function"?false:typeof e.then=="function",We={xlink:"http://www.w3.org/1999/xlink",xml:"http://www.w3.org/XML/1998/namespace",xmlns:"http://www.w3.org/2000/xmlns/"},oe=e=>{if(!(!e||e==="html"||e==="svg"))return We[e]},Ve=e=>e==="svg"?svg:html,N=(e,t,n)=>{let r=oe(t.space),s=String(n);if(r){e.setAttributeNS(r,t.attribute,s);return}e.setAttribute(t.attribute,s);},ne=(e,t)=>{let n=oe(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,ze=(e,t,n)=>t==="svg"||!n.property||n.property.includes(":")?false:n.property in e,se=(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 d=c;Object.entries(p).forEach(([m,u])=>{if(u!=null){if(m.startsWith("--")){c.setProperty(m,String(u));return}d[m]=u;}});return}let s=Y(t);if(s){let p=ee(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=ze(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?N(e,o,""):ne(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){ne(e,o);return}if(i===true){N(e,o,"");return}}if(l){a[o.property]=i;return}i!==false&&N(e,o,i);},h=(e,t)=>{if(t!=null&&typeof t!="boolean"){if(P(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(Be(t)){for(let n of t)h(e,n);return}if(He(t)){e.appendChild(t);return}e.appendChild(document.createTextNode(String(t)));}},A=(e,t,n)=>z(e,t,r=>D(r,t,n)),ae=K({getIdentifierName:b,evaluateExpressionWithNamespace:A}),Ue=(e,t,n,r)=>{let s=ae(t,n,r);Object.entries(s).forEach(([o,a])=>{if(o!=="key"){if(o==="children"){h(e,a);return}se(e,o,a,r);}});},j=(e,t,n)=>{let r=[];return e.forEach(s=>{switch(s.type){case "JSXText":{V(s.value,t.placeholders).forEach(a=>{r.push(a);});break}case "JSXExpressionContainer":{if(s.expression.type==="JSXEmptyExpression")break;r.push(A(s.expression,t,n));break}case "JSXSpreadChild":{let o=A(s.expression,t,n);o!=null&&r.push(o);break}case "JSXElement":case "JSXFragment":{r.push(D(s,t,n));break}}}),r},qe=(e,t,n,r)=>{let s=ae(e.openingElement.attributes,t,r),o=j(e.children,t,r);o.length===1?s.children=o[0]:o.length>1&&(s.children=o);let a=n(s);if(P(a))throw new Error("Async jsx components are not supported.");return a},Ke=(e,t,n)=>{let r=e.openingElement,s=b(r.name),o=t.components.get(s);if(o)return qe(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 Ue(i,r.attributes,t,a),j(e.children,t,l).forEach(c=>h(i,c)),i},D=(e,t,n)=>{if(e.type==="JSXFragment"){let r=document.createDocumentFragment();return j(e.children,t,n).forEach(o=>h(r,o)),r}return Ke(e,t,n)},Ge=te({ensureDomAvailable:re,appendChildValue:h,setDomProp:se,isPromiseLike:P}),Ze=(e,...t)=>{re();let n=U(e,t),r=parseSync("inline.jsx",n.source,B);if(r.errors.length>0)throw new Error(C("jsx",e,n.diagnostics,r.errors[0]));let s=W(r.program),o={source:n.source,placeholders:n.placeholders,components:new Map(n.bindings.map(a=>[a.name,a.value]))};return D(s,o,null)},ie=Object.assign(Ze,{createElement:Ge,Fragment:v});F();var Et=ie;
8
+ export{Et as jsx};
@@ -1,7 +1,7 @@
1
- import {parseSync}from'oxc-parser';import {createElement,Fragment}from'react';var R=e=>{let r=e.replace(/\r/g,"").replace(/\n\s+/g," "),n=e.match(/^\s*/)?.[0]??"",t=e.match(/\s*$/)?.[0]??"",o=/\n/.test(n),s=/\n/.test(t),a=r;return o&&(a=a.replace(/^\s+/,"")),s&&(a=a.replace(/\s+$/,"")),a.length===0||a.trim().length===0?null:a};var _="oxc-parser",j=e=>{let r=e.raw??e,n=r[0]??"",t=[];for(let o=0;o<r.length-1;o++){let s="${expr#"+o+"}",a=n.length;n+=s;let p=n.length;t.push({index:o,templateStart:a,templateEnd:p,label:s}),n+=r[o+1]??"";}return {source:n,spans:t}},D=(e,r)=>{let n=new Map;return r.forEach(t=>{n.set(t.index,t);}),e.expressionRanges.map(t=>{let o=n.get(t.index);if(!o)return null;let s=Math.max(0,t.sourceEnd-t.sourceStart),a=Math.max(0,o.templateEnd-o.templateStart);return {sourceStart:t.sourceStart,sourceEnd:t.sourceEnd,templateStart:o.templateStart,templateEnd:o.templateEnd,delta:a-s}}).filter(t=>!!t).sort((t,o)=>t.sourceStart-o.sourceStart)},L=(e,r,n)=>{if(!Number.isFinite(e)||e<=0)return 0;let t=0;for(let s of r){if(e<s.sourceStart)break;if(e<s.sourceEnd){let a=Math.max(0,e-s.sourceStart),p=Math.max(0,s.templateEnd-s.templateStart);if(p===0)return s.templateStart;let i=Math.min(a,Math.max(0,p-1));return s.templateStart+i}t+=s.delta;}let o=e+t;return o<=0?0:o>=n?n:o},w=(e,r)=>{let n=Math.max(0,Math.min(r,e.length)),t=1,o=1;for(let s=0;s<n;s++){if(e.charCodeAt(s)===10){t++,o=1;continue}o++;}return {line:t,column:o}},B=e=>{let r=[],n=0;return e.forEach((t,o)=>{r.push(n),n+=t.length,o<e.length-1&&(n+=1);}),r},v=(e,r,n,t,o,s,a)=>{let p=n+r.length,i=Math.max(t,n),c=Math.min(o,p);if(c>i){let m=Math.max(0,i-n),l=Math.max(1,c-i);return " ".repeat(m)+"^".repeat(l)}if(r.length===0&&e>=s&&e<=a)return "^";if(e===s){let m=Math.max(0,t-n);return " ".repeat(Math.min(m,r.length))+"^"}return ""},z=(e,r,n,t,o)=>{if(!e.length)return "";let s=e.split(`
2
- `),a=B(s),p=Math.max(1,t-1),i=Math.min(s.length,o+1),c=String(i).length,m=[];for(let l=p;l<=i;l++){let g=s[l-1]??"",u=String(l).padStart(c," ");m.push(`${u} | ${g}`);let d=v(l,g,a[l-1]??0,r,n,t,o);d&&m.push(`${" ".repeat(c)} | ${d}`);}return m.join(`
3
- `)},J=(e,r,n,t,o)=>{let s=_,a=`[${s}] ${t.message}`,p=t.labels?.[0];if(!p)return a;let{source:i,spans:c}=j(r),m=D(n,c),l=y=>L(typeof y=="number"?y:0,m,i.length),g=l(p.start),u=l(p.end);u<=g&&(u=Math.min(i.length,g+1));let d=w(i,g),f=w(i,Math.max(g,u-1)),h=z(i,g,u,d.line,f.line),x=`[${s}] ${t.message}`;return x+=`
4
- --> ${e} template:${d.line}:${d.column}`,p.message&&(x+=`
5
- ${p.message}`),h&&(x+=`
6
- ${h}`),t.helpMessage&&(x+=`
7
- ${t.helpMessage}`),x};var W=/<\s*$/,H=/<\/\s*$/,A="__KX_EXPR__",X=new RegExp(`${A}\\d+_\\d+__`,"g"),U=0;var k={lang:"jsx",sourceType:"module",range:true,preserveParens:true},$=e=>{for(let r of e.body)if(r.type==="ExpressionStatement"){let n=r.expression;if(n.type==="JSXElement"||n.type==="JSXFragment")return n}throw new Error("The jsx template must contain a single JSX element or fragment.")},S=e=>{switch(e.type){case "JSXIdentifier":return e.name;case "JSXNamespacedName":return `${e.namespace.name}:${e.name.name}`;case "JSXMemberExpression":return `${S(e.object)}.${e.property.name}`;default:return ""}},b=(e,r)=>{if(!e||typeof e!="object")return;let n=e;typeof n.type=="string"&&(r(n),Object.values(n).forEach(t=>{if(t){if(Array.isArray(t)){t.forEach(o=>b(o,r));return}typeof t=="object"&&b(t,r);}}));},M=(e,r)=>{let n=R(e);if(!n)return [];let t=[];X.lastIndex=0;let o=0,s;for(;s=X.exec(n);){let p=s.index,i=n.slice(o,p);i&&t.push(i);let c=s[0];r.has(c)?t.push(r.get(c)):t.push(c),o=p+c.length;}let a=n.slice(o);return a&&t.push(a),t},V=(e,r)=>{let n=new Set;return b(e,t=>{t.type==="Identifier"&&r.placeholders.has(t.name)&&n.add(t.name);}),Array.from(n)},N=(e,r,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[t,o]=e.range,s=r.source.slice(t,o),a=V(e,r);try{let p=new Function(...a,`"use strict"; return (${s});`),i=a.map(c=>r.placeholders.get(c));return p(...i)}catch(p){throw new Error(`Failed to evaluate expression ${s}: ${p.message}`,{cause:p})}},Z=e=>{let r=e.replace(/[^a-zA-Z0-9_$]/g,"");return r?/[A-Za-z_$]/.test(r[0])?r:`Component${r}`:"Component"},G=(e,r,n)=>{let t=n.get(e);if(t)return t;let o=e.displayName||e.name||`Component${r.length}`,s=Z(o??""),a=s,p=1;for(;r.some(c=>c.name===a);)a=`${s}${p++}`;let i={name:a,value:e};return r.push(i),n.set(e,i),i},F=(e,r)=>{let n=e.raw??e,t=new Map,o=[],s=new Map,a=n[0]??"",p=U++,i=0,c=[];for(let m=0;m<r.length;m++){let l=n[m]??"",g=n[m+1]??"",u=r[m],d=W.test(l)||H.test(l),f;if(d&&typeof u=="function")f=G(u,o,s).name;else if(d&&typeof u=="string")f=u;else {let y=`${A}${p}_${i++}__`;t.set(y,u),f=y;}let h=a.length;a+=f;let x=a.length;c.push({index:m,sourceStart:h,sourceEnd:x}),a+=g;}return {source:a,placeholders:t,bindings:o,diagnostics:{expressionRanges:c}}};var Q=e=>!e||typeof e=="string"?false:typeof e[Symbol.iterator]=="function",Y=e=>!e||typeof e!="object"&&typeof e!="function"?false:typeof e.then=="function",E=(e,r)=>{if(r!=null&&typeof r!="boolean"){if(Y(r))throw new Error("Async values are not supported inside reactJsx template results.");if(Array.isArray(r)){r.forEach(n=>E(e,n));return}if(Q(r)){for(let n of r)E(e,n);return}e.push(r);}},T=(e,r)=>N(e,r,n=>C(n,r)),ee=(e,r)=>{let n={};return e.forEach(t=>{if(t.type==="JSXSpreadAttribute"){let s=T(t.argument,r);s&&typeof s=="object"&&!Array.isArray(s)&&Object.assign(n,s);return}let o=S(t.name);if(!t.value){n[o]=true;return}if(t.value.type==="Literal"){n[o]=t.value.value;return}if(t.value.type==="JSXExpressionContainer"){if(t.value.expression.type==="JSXEmptyExpression")return;n[o]=T(t.value.expression,r);}}),n},O=(e,r)=>{let n=[];return e.forEach(t=>{switch(t.type){case "JSXText":{M(t.value,r.placeholders).forEach(s=>E(n,s));break}case "JSXExpressionContainer":{if(t.expression.type==="JSXEmptyExpression")break;E(n,T(t.expression,r));break}case "JSXSpreadChild":{let o=T(t.expression,r);o!=null&&E(n,o);break}case "JSXElement":case "JSXFragment":{n.push(C(t,r));break}}}),n},I=(e,r,n)=>createElement(e,r,...n),te=(e,r)=>{let n=e.openingElement,t=S(n.name),o=r.components.get(t),s=ee(n.attributes,r),a=O(e.children,r);if(o)return I(o,s,a);if(/[A-Z]/.test(t[0]??""))throw new Error(`Unknown component "${t}". Did you interpolate it with the template literal?`);return I(t,s,a)},C=(e,r)=>{if(e.type==="JSXFragment"){let n=O(e.children,r);return createElement(Fragment,null,...n)}return te(e,r)},ne=(e,...r)=>{let n=F(e,r),t=parseSync("inline.jsx",n.source,k);if(t.errors.length>0)throw new Error(J("reactJsx",e,n.diagnostics,t.errors[0]));let o=$(t.program),s={source:n.source,placeholders:n.placeholders,components:new Map(n.bindings.map(a=>[a.name,a.value]))};return C(o,s)};export{ne as reactJsx};
1
+ import {parseSync}from'oxc-parser';import {createElement,Fragment}from'react';var X=e=>{let n=e.replace(/\r/g,"").replace(/\n\s+/g," "),r=e.match(/^\s*/)?.[0]??"",t=e.match(/\s*$/)?.[0]??"",o=/\n/.test(r),s=/\n/.test(t),a=n;return o&&(a=a.replace(/^\s+/,"")),s&&(a=a.replace(/\s+$/,"")),a.length===0||a.trim().length===0?null:a};var j="oxc-parser",L=e=>{let n=e.raw??e,r=n[0]??"",t=[];for(let o=0;o<n.length-1;o++){let s="${expr#"+o+"}",a=r.length;r+=s;let p=r.length;t.push({index:o,templateStart:a,templateEnd:p,label:s}),r+=n[o+1]??"";}return {source:r,spans:t}},D=(e,n)=>{let r=new Map;return n.forEach(t=>{r.set(t.index,t);}),e.expressionRanges.map(t=>{let o=r.get(t.index);if(!o)return null;let s=Math.max(0,t.sourceEnd-t.sourceStart),a=Math.max(0,o.templateEnd-o.templateStart);return {sourceStart:t.sourceStart,sourceEnd:t.sourceEnd,templateStart:o.templateStart,templateEnd:o.templateEnd,delta:a-s}}).filter(t=>!!t).sort((t,o)=>t.sourceStart-o.sourceStart)},v=(e,n,r)=>{if(!Number.isFinite(e)||e<=0)return 0;let t=0;for(let s of n){if(e<s.sourceStart)break;if(e<s.sourceEnd){let a=Math.max(0,e-s.sourceStart),p=Math.max(0,s.templateEnd-s.templateStart);if(p===0)return s.templateStart;let i=Math.min(a,Math.max(0,p-1));return s.templateStart+i}t+=s.delta;}let o=e+t;return o<=0?0:o>=r?r:o},$=(e,n)=>{let r=Math.max(0,Math.min(n,e.length)),t=1,o=1;for(let s=0;s<r;s++){if(e.charCodeAt(s)===10){t++,o=1;continue}o++;}return {line:t,column:o}},z=e=>{let n=[],r=0;return e.forEach((t,o)=>{n.push(r),r+=t.length,o<e.length-1&&(r+=1);}),n},V=(e,n,r,t,o,s,a)=>{let p=r+n.length,i=Math.max(t,r),c=Math.min(o,p);if(c>i){let u=Math.max(0,i-r),l=Math.max(1,c-i);return " ".repeat(u)+"^".repeat(l)}if(n.length===0&&e>=s&&e<=a)return "^";if(e===s){let u=Math.max(0,t-r);return " ".repeat(Math.min(u,n.length))+"^"}return ""},W=(e,n,r,t,o)=>{if(!e.length)return "";let s=e.split(`
2
+ `),a=z(s),p=Math.max(1,t-1),i=Math.min(s.length,o+1),c=String(i).length,u=[];for(let l=p;l<=i;l++){let m=s[l-1]??"",d=String(l).padStart(c," ");u.push(`${d} | ${m}`);let x=V(l,m,a[l-1]??0,n,r,t,o);x&&u.push(`${" ".repeat(c)} | ${x}`);}return u.join(`
3
+ `)},J=(e,n,r,t,o)=>{let s=j,a=`[${s}] ${t.message}`,p=t.labels?.[0];if(!p)return a;let{source:i,spans:c}=L(n),u=D(r,c),l=h=>v(typeof h=="number"?h:0,u,i.length),m=l(p.start),d=l(p.end);d<=m&&(d=Math.min(i.length,m+1));let x=$(i,m),f=$(i,Math.max(m,d-1)),y=W(i,m,d,x.line,f.line),g=`[${s}] ${t.message}`;return g+=`
4
+ --> ${e} template:${x.line}:${x.column}`,p.message&&(g+=`
5
+ ${p.message}`),y&&(g+=`
6
+ ${y}`),t.helpMessage&&(g+=`
7
+ ${t.helpMessage}`),g};var H=/<\s*$/,U=/<\/\s*$/,A="__KX_EXPR__",k=new RegExp(`${A}\\d+_\\d+__`,"g"),Z=0;var M={lang:"jsx",sourceType:"module",range:true,preserveParens:true},N=e=>{for(let n of e.body)if(n.type==="ExpressionStatement"){let r=n.expression;if(r.type==="JSXElement"||r.type==="JSXFragment")return r}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 ""}},b=(e,n)=>{if(!e||typeof e!="object")return;let r=e;typeof r.type=="string"&&(n(r),Object.values(r).forEach(t=>{if(t){if(Array.isArray(t)){t.forEach(o=>b(o,n));return}typeof t=="object"&&b(t,n);}}));},F=(e,n)=>{let r=X(e);if(!r)return [];let t=[];k.lastIndex=0;let o=0,s;for(;s=k.exec(r);){let p=s.index,i=r.slice(o,p);i&&t.push(i);let c=s[0];n.has(c)?t.push(n.get(c)):t.push(c),o=p+c.length;}let a=r.slice(o);return a&&t.push(a),t},G=(e,n)=>{let r=new Set;return b(e,t=>{t.type==="Identifier"&&n.placeholders.has(t.name)&&r.add(t.name);}),Array.from(r)},I=(e,n,r)=>{if(e.type==="JSXElement"||e.type==="JSXFragment")return r(e);if(!("range"in e)||!e.range)throw new Error("Unable to evaluate expression: missing source range information.");let[t,o]=e.range,s=n.source.slice(t,o),a=G(e,n);try{let p=new Function(...a,`"use strict"; return (${s});`),i=a.map(c=>n.placeholders.get(c));return p(...i)}catch(p){throw new Error(`Failed to evaluate expression ${s}: ${p.message}`,{cause:p})}},K=e=>{let n=e.replace(/[^a-zA-Z0-9_$]/g,"");return n?/[A-Za-z_$]/.test(n[0])?n:`Component${n}`:"Component"},q=(e,n,r)=>{let t=r.get(e);if(t)return t;let o=e.displayName||e.name||`Component${n.length}`,s=K(o??""),a=s,p=1;for(;n.some(c=>c.name===a);)a=`${s}${p++}`;let i={name:a,value:e};return n.push(i),r.set(e,i),i},P=(e,n,r)=>{let t=e.raw??e,o=new Map,s=[],a=new Map,p=t[0]??"",i=Z++,c=0,u=[],l=r?.isTagNameBindingValue??(m=>typeof m=="function");for(let m=0;m<n.length;m++){let d=t[m]??"",x=t[m+1]??"",f=n[m],y=H.test(d)||U.test(d),g;if(y&&l(f))g=q(f,s,a).name;else if(y&&typeof f=="string")g=f;else {if(y)throw new Error("Invalid tag interpolation value. Expected a component, class, or string tag name.");{let C=`${A}${i}_${c++}__`;o.set(C,f),g=C;}}let h=p.length;p+=g;let w=p.length;u.push({index:m,sourceStart:h,sourceEnd:w}),p+=x;}return {source:p,placeholders:o,bindings:s,diagnostics:{expressionRanges:u}}};var ee=e=>!e||typeof e=="string"?false:typeof e[Symbol.iterator]=="function",te=e=>!e||typeof e!="object"&&typeof e!="function"?false:typeof e.then=="function",E=(e,n)=>{if(n!=null&&typeof n!="boolean"){if(te(n))throw new Error("Async values are not supported inside reactJsx template results.");if(Array.isArray(n)){n.forEach(r=>E(e,r));return}if(ee(n)){for(let r of n)E(e,r);return}e.push(n);}},S=(e,n)=>I(e,n,r=>R(r,n)),ne=(e,n)=>{let r={};return e.forEach(t=>{if(t.type==="JSXSpreadAttribute"){let s=S(t.argument,n);s&&typeof s=="object"&&!Array.isArray(s)&&Object.assign(r,s);return}let o=T(t.name);if(!t.value){r[o]=true;return}if(t.value.type==="Literal"){r[o]=t.value.value;return}if(t.value.type==="JSXExpressionContainer"){if(t.value.expression.type==="JSXEmptyExpression")return;r[o]=S(t.value.expression,n);}}),r},B=(e,n)=>{let r=[];return e.forEach(t=>{switch(t.type){case "JSXText":{F(t.value,n.placeholders).forEach(s=>E(r,s));break}case "JSXExpressionContainer":{if(t.expression.type==="JSXEmptyExpression")break;E(r,S(t.expression,n));break}case "JSXSpreadChild":{let o=S(t.expression,n);o!=null&&E(r,o);break}case "JSXElement":case "JSXFragment":{r.push(R(t,n));break}}}),r},O=(e,n,r)=>createElement(e,n,...r),re=Symbol.for("react.memo"),oe=Symbol.for("react.forward_ref"),se=Symbol.for("react.lazy"),ae=e=>{if(typeof e=="function")return true;if(typeof e!="object"||e===null)return false;let n=e;return n.$$typeof===re||n.$$typeof===oe||n.$$typeof===se},pe=(e,n)=>{let r=e.openingElement,t=T(r.name),o=n.components.get(t),s=ne(r.attributes,n),a=B(e.children,n);if(o)return O(o,s,a);if(/[A-Z]/.test(t[0]??""))throw new Error(`Unknown component "${t}". Did you interpolate it with the template literal?`);return O(t,s,a)},R=(e,n)=>{if(e.type==="JSXFragment"){let r=B(e.children,n);return createElement(Fragment,null,...r)}return pe(e,n)},ie=(e,...n)=>{let r=P(e,n,{isTagNameBindingValue:ae}),t=parseSync("inline.jsx",r.source,M);if(t.errors.length>0)throw new Error(J("reactJsx",e,r.diagnostics,t.errors[0]));let o=N(t.program),s={source:r.source,placeholders:r.placeholders,components:new Map(r.bindings.map(a=>[a.name,a.value]))};return R(o,s)};export{ie as reactJsx};
@@ -1,7 +1,7 @@
1
- import {parseSync}from'oxc-parser';import {createElement,Fragment}from'react';var C=e=>{let r=e.replace(/\r/g,"").replace(/\n\s+/g," "),n=e.match(/^\s*/)?.[0]??"",t=e.match(/\s*$/)?.[0]??"",o=/\n/.test(n),s=/\n/.test(t),a=r;return o&&(a=a.replace(/^\s+/,"")),s&&(a=a.replace(/\s+$/,"")),a.length===0||a.trim().length===0?null:a};var _="oxc-parser",D=e=>{let r=e.raw??e,n=r[0]??"",t=[];for(let o=0;o<r.length-1;o++){let s="${expr#"+o+"}",a=n.length;n+=s;let p=n.length;t.push({index:o,templateStart:a,templateEnd:p,label:s}),n+=r[o+1]??"";}return {source:n,spans:t}},j=(e,r)=>{let n=new Map;return r.forEach(t=>{n.set(t.index,t);}),e.expressionRanges.map(t=>{let o=n.get(t.index);if(!o)return null;let s=Math.max(0,t.sourceEnd-t.sourceStart),a=Math.max(0,o.templateEnd-o.templateStart);return {sourceStart:t.sourceStart,sourceEnd:t.sourceEnd,templateStart:o.templateStart,templateEnd:o.templateEnd,delta:a-s}}).filter(t=>!!t).sort((t,o)=>t.sourceStart-o.sourceStart)},L=(e,r,n)=>{if(!Number.isFinite(e)||e<=0)return 0;let t=0;for(let s of r){if(e<s.sourceStart)break;if(e<s.sourceEnd){let a=Math.max(0,e-s.sourceStart),p=Math.max(0,s.templateEnd-s.templateStart);if(p===0)return s.templateStart;let i=Math.min(a,Math.max(0,p-1));return s.templateStart+i}t+=s.delta;}let o=e+t;return o<=0?0:o>=n?n:o},w=(e,r)=>{let n=Math.max(0,Math.min(r,e.length)),t=1,o=1;for(let s=0;s<n;s++){if(e.charCodeAt(s)===10){t++,o=1;continue}o++;}return {line:t,column:o}},v=e=>{let r=[],n=0;return e.forEach((t,o)=>{r.push(n),n+=t.length,o<e.length-1&&(n+=1);}),r},B=(e,r,n,t,o,s,a)=>{let p=n+r.length,i=Math.max(t,n),c=Math.min(o,p);if(c>i){let m=Math.max(0,i-n),l=Math.max(1,c-i);return " ".repeat(m)+"^".repeat(l)}if(r.length===0&&e>=s&&e<=a)return "^";if(e===s){let m=Math.max(0,t-n);return " ".repeat(Math.min(m,r.length))+"^"}return ""},z=(e,r,n,t,o)=>{if(!e.length)return "";let s=e.split(`
2
- `),a=v(s),p=Math.max(1,t-1),i=Math.min(s.length,o+1),c=String(i).length,m=[];for(let l=p;l<=i;l++){let g=s[l-1]??"",u=String(l).padStart(c," ");m.push(`${u} | ${g}`);let x=B(l,g,a[l-1]??0,r,n,t,o);x&&m.push(`${" ".repeat(c)} | ${x}`);}return m.join(`
3
- `)},J=(e,r,n,t,o)=>{let s=_,a=`[${s}] ${t.message}`,p=t.labels?.[0];if(!p)return a;let{source:i,spans:c}=D(r),m=j(n,c),l=y=>L(typeof y=="number"?y:0,m,i.length),g=l(p.start),u=l(p.end);u<=g&&(u=Math.min(i.length,g+1));let x=w(i,g),f=w(i,Math.max(g,u-1)),h=z(i,g,u,x.line,f.line),d=`[${s}] ${t.message}`;return d+=`
4
- --> ${e} template:${x.line}:${x.column}`,p.message&&(d+=`
5
- ${p.message}`),h&&(d+=`
6
- ${h}`),t.helpMessage&&(d+=`
7
- ${t.helpMessage}`),d};var W=/<\s*$/,H=/<\/\s*$/,A="__KX_EXPR__",X=new RegExp(`${A}\\d+_\\d+__`,"g"),U=0;var k={lang:"jsx",sourceType:"module",range:true,preserveParens:true},$=e=>{for(let r of e.body)if(r.type==="ExpressionStatement"){let n=r.expression;if(n.type==="JSXElement"||n.type==="JSXFragment")return n}throw new Error("The jsx template must contain a single JSX element or fragment.")},S=e=>{switch(e.type){case "JSXIdentifier":return e.name;case "JSXNamespacedName":return `${e.namespace.name}:${e.name.name}`;case "JSXMemberExpression":return `${S(e.object)}.${e.property.name}`;default:return ""}},b=(e,r)=>{if(!e||typeof e!="object")return;let n=e;typeof n.type=="string"&&(r(n),Object.values(n).forEach(t=>{if(t){if(Array.isArray(t)){t.forEach(o=>b(o,r));return}typeof t=="object"&&b(t,r);}}));},M=(e,r)=>{let n=C(e);if(!n)return [];let t=[];X.lastIndex=0;let o=0,s;for(;s=X.exec(n);){let p=s.index,i=n.slice(o,p);i&&t.push(i);let c=s[0];r.has(c)?t.push(r.get(c)):t.push(c),o=p+c.length;}let a=n.slice(o);return a&&t.push(a),t},V=(e,r)=>{let n=new Set;return b(e,t=>{t.type==="Identifier"&&r.placeholders.has(t.name)&&n.add(t.name);}),Array.from(n)},N=(e,r,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[t,o]=e.range,s=r.source.slice(t,o),a=V(e,r);try{let p=new Function(...a,`"use strict"; return (${s});`),i=a.map(c=>r.placeholders.get(c));return p(...i)}catch(p){throw new Error(`Failed to evaluate expression ${s}: ${p.message}`,{cause:p})}},Z=e=>{let r=e.replace(/[^a-zA-Z0-9_$]/g,"");return r?/[A-Za-z_$]/.test(r[0])?r:`Component${r}`:"Component"},G=(e,r,n)=>{let t=n.get(e);if(t)return t;let o=e.displayName||e.name||`Component${r.length}`,s=Z(o??""),a=s,p=1;for(;r.some(c=>c.name===a);)a=`${s}${p++}`;let i={name:a,value:e};return r.push(i),n.set(e,i),i},I=(e,r)=>{let n=e.raw??e,t=new Map,o=[],s=new Map,a=n[0]??"",p=U++,i=0,c=[];for(let m=0;m<r.length;m++){let l=n[m]??"",g=n[m+1]??"",u=r[m],x=W.test(l)||H.test(l),f;if(x&&typeof u=="function")f=G(u,o,s).name;else if(x&&typeof u=="string")f=u;else {let y=`${A}${p}_${i++}__`;t.set(y,u),f=y;}let h=a.length;a+=f;let d=a.length;c.push({index:m,sourceStart:h,sourceEnd:d}),a+=g;}return {source:a,placeholders:t,bindings:o,diagnostics:{expressionRanges:c}}};var Q=e=>!e||typeof e=="string"?false:typeof e[Symbol.iterator]=="function",Y=e=>!e||typeof e!="object"&&typeof e!="function"?false:typeof e.then=="function",E=(e,r)=>{if(r!=null&&typeof r!="boolean"){if(Y(r))throw new Error("Async values are not supported inside reactJsx template results.");if(Array.isArray(r)){r.forEach(n=>E(e,n));return}if(Q(r)){for(let n of r)E(e,n);return}e.push(r);}},T=(e,r)=>N(e,r,n=>R(n,r)),ee=(e,r)=>{let n={};return e.forEach(t=>{if(t.type==="JSXSpreadAttribute"){let s=T(t.argument,r);s&&typeof s=="object"&&!Array.isArray(s)&&Object.assign(n,s);return}let o=S(t.name);if(!t.value){n[o]=true;return}if(t.value.type==="Literal"){n[o]=t.value.value;return}if(t.value.type==="JSXExpressionContainer"){if(t.value.expression.type==="JSXEmptyExpression")return;n[o]=T(t.value.expression,r);}}),n},O=(e,r)=>{let n=[];return e.forEach(t=>{switch(t.type){case "JSXText":{M(t.value,r.placeholders).forEach(s=>E(n,s));break}case "JSXExpressionContainer":{if(t.expression.type==="JSXEmptyExpression")break;E(n,T(t.expression,r));break}case "JSXSpreadChild":{let o=T(t.expression,r);o!=null&&E(n,o);break}case "JSXElement":case "JSXFragment":{n.push(R(t,r));break}}}),n},F=(e,r,n)=>createElement(e,r,...n),te=(e,r)=>{let n=e.openingElement,t=S(n.name),o=r.components.get(t),s=ee(n.attributes,r),a=O(e.children,r);if(o)return F(o,s,a);if(/[A-Z]/.test(t[0]??""))throw new Error(`Unknown component "${t}". Did you interpolate it with the template literal?`);return F(t,s,a)},R=(e,r)=>{if(e.type==="JSXFragment"){let n=O(e.children,r);return createElement(Fragment,null,...n)}return te(e,r)},ne=(e,...r)=>{let n=I(e,r),t=parseSync("inline.jsx",n.source,k);if(t.errors.length>0)throw new Error(J("reactJsx",e,n.diagnostics,t.errors[0]));let o=$(t.program),s={source:n.source,placeholders:n.placeholders,components:new Map(n.bindings.map(a=>[a.name,a.value]))};return R(o,s)};export{ne as reactJsx};
1
+ import {parseSync}from'oxc-parser';import {createElement,Fragment}from'react';var X=e=>{let n=e.replace(/\r/g,"").replace(/\n\s+/g," "),r=e.match(/^\s*/)?.[0]??"",t=e.match(/\s*$/)?.[0]??"",o=/\n/.test(r),s=/\n/.test(t),a=n;return o&&(a=a.replace(/^\s+/,"")),s&&(a=a.replace(/\s+$/,"")),a.length===0||a.trim().length===0?null:a};var j="oxc-parser",D=e=>{let n=e.raw??e,r=n[0]??"",t=[];for(let o=0;o<n.length-1;o++){let s="${expr#"+o+"}",a=r.length;r+=s;let p=r.length;t.push({index:o,templateStart:a,templateEnd:p,label:s}),r+=n[o+1]??"";}return {source:r,spans:t}},L=(e,n)=>{let r=new Map;return n.forEach(t=>{r.set(t.index,t);}),e.expressionRanges.map(t=>{let o=r.get(t.index);if(!o)return null;let s=Math.max(0,t.sourceEnd-t.sourceStart),a=Math.max(0,o.templateEnd-o.templateStart);return {sourceStart:t.sourceStart,sourceEnd:t.sourceEnd,templateStart:o.templateStart,templateEnd:o.templateEnd,delta:a-s}}).filter(t=>!!t).sort((t,o)=>t.sourceStart-o.sourceStart)},v=(e,n,r)=>{if(!Number.isFinite(e)||e<=0)return 0;let t=0;for(let s of n){if(e<s.sourceStart)break;if(e<s.sourceEnd){let a=Math.max(0,e-s.sourceStart),p=Math.max(0,s.templateEnd-s.templateStart);if(p===0)return s.templateStart;let i=Math.min(a,Math.max(0,p-1));return s.templateStart+i}t+=s.delta;}let o=e+t;return o<=0?0:o>=r?r:o},$=(e,n)=>{let r=Math.max(0,Math.min(n,e.length)),t=1,o=1;for(let s=0;s<r;s++){if(e.charCodeAt(s)===10){t++,o=1;continue}o++;}return {line:t,column:o}},z=e=>{let n=[],r=0;return e.forEach((t,o)=>{n.push(r),r+=t.length,o<e.length-1&&(r+=1);}),n},V=(e,n,r,t,o,s,a)=>{let p=r+n.length,i=Math.max(t,r),c=Math.min(o,p);if(c>i){let u=Math.max(0,i-r),l=Math.max(1,c-i);return " ".repeat(u)+"^".repeat(l)}if(n.length===0&&e>=s&&e<=a)return "^";if(e===s){let u=Math.max(0,t-r);return " ".repeat(Math.min(u,n.length))+"^"}return ""},W=(e,n,r,t,o)=>{if(!e.length)return "";let s=e.split(`
2
+ `),a=z(s),p=Math.max(1,t-1),i=Math.min(s.length,o+1),c=String(i).length,u=[];for(let l=p;l<=i;l++){let m=s[l-1]??"",x=String(l).padStart(c," ");u.push(`${x} | ${m}`);let d=V(l,m,a[l-1]??0,n,r,t,o);d&&u.push(`${" ".repeat(c)} | ${d}`);}return u.join(`
3
+ `)},C=(e,n,r,t,o)=>{let s=j,a=`[${s}] ${t.message}`,p=t.labels?.[0];if(!p)return a;let{source:i,spans:c}=D(n),u=L(r,c),l=h=>v(typeof h=="number"?h:0,u,i.length),m=l(p.start),x=l(p.end);x<=m&&(x=Math.min(i.length,m+1));let d=$(i,m),f=$(i,Math.max(m,x-1)),y=W(i,m,x,d.line,f.line),g=`[${s}] ${t.message}`;return g+=`
4
+ --> ${e} template:${d.line}:${d.column}`,p.message&&(g+=`
5
+ ${p.message}`),y&&(g+=`
6
+ ${y}`),t.helpMessage&&(g+=`
7
+ ${t.helpMessage}`),g};var H=/<\s*$/,U=/<\/\s*$/,A="__KX_EXPR__",k=new RegExp(`${A}\\d+_\\d+__`,"g"),Z=0;var M={lang:"jsx",sourceType:"module",range:true,preserveParens:true},N=e=>{for(let n of e.body)if(n.type==="ExpressionStatement"){let r=n.expression;if(r.type==="JSXElement"||r.type==="JSXFragment")return r}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 ""}},R=(e,n)=>{if(!e||typeof e!="object")return;let r=e;typeof r.type=="string"&&(n(r),Object.values(r).forEach(t=>{if(t){if(Array.isArray(t)){t.forEach(o=>R(o,n));return}typeof t=="object"&&R(t,n);}}));},F=(e,n)=>{let r=X(e);if(!r)return [];let t=[];k.lastIndex=0;let o=0,s;for(;s=k.exec(r);){let p=s.index,i=r.slice(o,p);i&&t.push(i);let c=s[0];n.has(c)?t.push(n.get(c)):t.push(c),o=p+c.length;}let a=r.slice(o);return a&&t.push(a),t},G=(e,n)=>{let r=new Set;return R(e,t=>{t.type==="Identifier"&&n.placeholders.has(t.name)&&r.add(t.name);}),Array.from(r)},I=(e,n,r)=>{if(e.type==="JSXElement"||e.type==="JSXFragment")return r(e);if(!("range"in e)||!e.range)throw new Error("Unable to evaluate expression: missing source range information.");let[t,o]=e.range,s=n.source.slice(t,o),a=G(e,n);try{let p=new Function(...a,`"use strict"; return (${s});`),i=a.map(c=>n.placeholders.get(c));return p(...i)}catch(p){throw new Error(`Failed to evaluate expression ${s}: ${p.message}`,{cause:p})}},K=e=>{let n=e.replace(/[^a-zA-Z0-9_$]/g,"");return n?/[A-Za-z_$]/.test(n[0])?n:`Component${n}`:"Component"},q=(e,n,r)=>{let t=r.get(e);if(t)return t;let o=e.displayName||e.name||`Component${n.length}`,s=K(o??""),a=s,p=1;for(;n.some(c=>c.name===a);)a=`${s}${p++}`;let i={name:a,value:e};return n.push(i),r.set(e,i),i},P=(e,n,r)=>{let t=e.raw??e,o=new Map,s=[],a=new Map,p=t[0]??"",i=Z++,c=0,u=[],l=r?.isTagNameBindingValue??(m=>typeof m=="function");for(let m=0;m<n.length;m++){let x=t[m]??"",d=t[m+1]??"",f=n[m],y=H.test(x)||U.test(x),g;if(y&&l(f))g=q(f,s,a).name;else if(y&&typeof f=="string")g=f;else {if(y)throw new Error("Invalid tag interpolation value. Expected a component, class, or string tag name.");{let J=`${A}${i}_${c++}__`;o.set(J,f),g=J;}}let h=p.length;p+=g;let w=p.length;u.push({index:m,sourceStart:h,sourceEnd:w}),p+=d;}return {source:p,placeholders:o,bindings:s,diagnostics:{expressionRanges:u}}};var ee=e=>!e||typeof e=="string"?false:typeof e[Symbol.iterator]=="function",te=e=>!e||typeof e!="object"&&typeof e!="function"?false:typeof e.then=="function",E=(e,n)=>{if(n!=null&&typeof n!="boolean"){if(te(n))throw new Error("Async values are not supported inside reactJsx template results.");if(Array.isArray(n)){n.forEach(r=>E(e,r));return}if(ee(n)){for(let r of n)E(e,r);return}e.push(n);}},S=(e,n)=>I(e,n,r=>b(r,n)),ne=(e,n)=>{let r={};return e.forEach(t=>{if(t.type==="JSXSpreadAttribute"){let s=S(t.argument,n);s&&typeof s=="object"&&!Array.isArray(s)&&Object.assign(r,s);return}let o=T(t.name);if(!t.value){r[o]=true;return}if(t.value.type==="Literal"){r[o]=t.value.value;return}if(t.value.type==="JSXExpressionContainer"){if(t.value.expression.type==="JSXEmptyExpression")return;r[o]=S(t.value.expression,n);}}),r},B=(e,n)=>{let r=[];return e.forEach(t=>{switch(t.type){case "JSXText":{F(t.value,n.placeholders).forEach(s=>E(r,s));break}case "JSXExpressionContainer":{if(t.expression.type==="JSXEmptyExpression")break;E(r,S(t.expression,n));break}case "JSXSpreadChild":{let o=S(t.expression,n);o!=null&&E(r,o);break}case "JSXElement":case "JSXFragment":{r.push(b(t,n));break}}}),r},O=(e,n,r)=>createElement(e,n,...r),re=Symbol.for("react.memo"),oe=Symbol.for("react.forward_ref"),se=Symbol.for("react.lazy"),ae=e=>{if(typeof e=="function")return true;if(typeof e!="object"||e===null)return false;let n=e;return n.$$typeof===re||n.$$typeof===oe||n.$$typeof===se},pe=(e,n)=>{let r=e.openingElement,t=T(r.name),o=n.components.get(t),s=ne(r.attributes,n),a=B(e.children,n);if(o)return O(o,s,a);if(/[A-Z]/.test(t[0]??""))throw new Error(`Unknown component "${t}". Did you interpolate it with the template literal?`);return O(t,s,a)},b=(e,n)=>{if(e.type==="JSXFragment"){let r=B(e.children,n);return createElement(Fragment,null,...r)}return pe(e,n)},ie=(e,...n)=>{let r=P(e,n,{isTagNameBindingValue:ae}),t=parseSync("inline.jsx",r.source,M);if(t.errors.length>0)throw new Error(C("reactJsx",e,r.diagnostics,t.errors[0]));let o=N(t.program),s={source:r.source,placeholders:r.placeholders,components:new Map(r.bindings.map(a=>[a.name,a.value]))};return b(o,s)};export{ie as reactJsx};
@@ -99,6 +99,21 @@ const evaluateReactJsxChildren = (children, ctx) => {
99
99
  const createReactElement = (type, props, children) => {
100
100
  return createElement(type, props, ...children);
101
101
  };
102
+ const reactMemoSymbol = Symbol.for('react.memo');
103
+ const reactForwardRefSymbol = Symbol.for('react.forward_ref');
104
+ const reactLazySymbol = Symbol.for('react.lazy');
105
+ const isReactTagBindingValue = (value) => {
106
+ if (typeof value === 'function') {
107
+ return true;
108
+ }
109
+ if (typeof value !== 'object' || value === null) {
110
+ return false;
111
+ }
112
+ const candidate = value;
113
+ return (candidate.$$typeof === reactMemoSymbol ||
114
+ candidate.$$typeof === reactForwardRefSymbol ||
115
+ candidate.$$typeof === reactLazySymbol);
116
+ };
102
117
  const evaluateReactJsxElement = (element, ctx) => {
103
118
  const opening = element.openingElement;
104
119
  const tagName = getIdentifierName(opening.name);
@@ -121,7 +136,9 @@ const evaluateReactJsxNode = (node, ctx) => {
121
136
  return evaluateReactJsxElement(node, ctx);
122
137
  };
123
138
  export const reactJsx = (templates, ...values) => {
124
- const build = buildTemplate(templates, values);
139
+ const build = buildTemplate(templates, values, {
140
+ isTagNameBindingValue: isReactTagBindingValue,
141
+ });
125
142
  const result = parseSync('inline.jsx', build.source, parserOptions);
126
143
  if (result.errors.length > 0) {
127
144
  throw new Error(formatTaggedTemplateParserError('reactJsx', templates, build.diagnostics, result.errors[0]));
@@ -22,6 +22,9 @@ export type TemplateBuildResult<TComponent extends TemplateComponent> = {
22
22
  bindings: BindingEntry<TComponent>[];
23
23
  diagnostics: TemplateDiagnostics;
24
24
  };
25
+ export type TemplateBuildOptions<TComponent extends TemplateComponent> = {
26
+ isTagNameBindingValue?: (value: unknown) => value is TComponent;
27
+ };
25
28
  export type TemplateContext<TComponent extends TemplateComponent> = {
26
29
  source: string;
27
30
  placeholders: Map<string, unknown>;
@@ -40,4 +43,4 @@ export declare const collectPlaceholderNames: <TComponent extends TemplateCompon
40
43
  export declare const evaluateExpression: <TComponent extends TemplateComponent>(expression: Expression | JSXElement | JSXFragment, ctx: TemplateContext<TComponent>, evaluateJsxNode: (node: JSXElement | JSXFragment) => unknown) => unknown;
41
44
  export declare const sanitizeIdentifier: (value: string) => string;
42
45
  export declare const ensureBinding: <TComponent extends TemplateComponent>(value: TComponent, bindings: BindingEntry<TComponent>[], bindingLookup: Map<TComponent, BindingEntry<TComponent>>) => BindingEntry<TComponent>;
43
- export declare const buildTemplate: <TComponent extends TemplateComponent>(strings: TemplateStringsArray, values: unknown[]) => TemplateBuildResult<TComponent>;
46
+ export declare const buildTemplate: <TComponent extends TemplateComponent>(strings: TemplateStringsArray, values: unknown[], options?: TemplateBuildOptions<TComponent>) => TemplateBuildResult<TComponent>;
@@ -157,7 +157,7 @@ export const ensureBinding = (value, bindings, bindingLookup) => {
157
157
  bindingLookup.set(value, binding);
158
158
  return binding;
159
159
  };
160
- export const buildTemplate = (strings, values) => {
160
+ export const buildTemplate = (strings, values, options) => {
161
161
  const raw = strings.raw ?? strings;
162
162
  const placeholders = new Map();
163
163
  const bindings = [];
@@ -166,19 +166,24 @@ export const buildTemplate = (strings, values) => {
166
166
  const templateId = invocationCounter++;
167
167
  let placeholderIndex = 0;
168
168
  const expressionRanges = [];
169
+ const isTagNameBindingValue = options?.isTagNameBindingValue ??
170
+ ((value) => typeof value === 'function');
169
171
  for (let idx = 0; idx < values.length; idx++) {
170
172
  const chunk = raw[idx] ?? '';
171
173
  const nextChunk = raw[idx + 1] ?? '';
172
174
  const value = values[idx];
173
175
  const isTagNamePosition = OPEN_TAG_RE.test(chunk) || CLOSE_TAG_RE.test(chunk);
174
176
  let insertion;
175
- if (isTagNamePosition && typeof value === 'function') {
177
+ if (isTagNamePosition && isTagNameBindingValue(value)) {
176
178
  const binding = ensureBinding(value, bindings, bindingLookup);
177
179
  insertion = binding.name;
178
180
  }
179
181
  else if (isTagNamePosition && typeof value === 'string') {
180
182
  insertion = value;
181
183
  }
184
+ else if (isTagNamePosition) {
185
+ throw new Error('Invalid tag interpolation value. Expected a component, class, or string tag name.');
186
+ }
182
187
  else {
183
188
  const placeholder = `${PLACEHOLDER_PREFIX}${templateId}_${placeholderIndex++}__`;
184
189
  placeholders.set(placeholder, value);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@knighted/jsx",
3
- "version": "1.13.1",
3
+ "version": "1.13.2-rc.0",
4
4
  "description": "Runtime JSX tagged template that renders DOM or React trees anywhere with or without a build step.",
5
5
  "keywords": [
6
6
  "jsx runtime",