jhx 0.1.3 → 0.1.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";var R=Object.defineProperty;var re=Object.getOwnPropertyDescriptor;var oe=Object.getOwnPropertyNames;var se=Object.prototype.hasOwnProperty;var S=(e,o)=>R(e,"name",{value:o,configurable:!0});var ne=(e,o)=>{for(var t in o)R(e,t,{get:o[t],enumerable:!0})},ie=(e,o,t,s)=>{if(o&&typeof o=="object"||typeof o=="function")for(let r of oe(o))!se.call(e,r)&&r!==t&&R(e,r,{get:()=>o[r],enumerable:!(s=re(o,r))||s.enumerable});return e};var ae=e=>ie(R({},"__esModule",{value:!0}),e);var de={};ne(de,{JhxComponent:()=>le,JhxErrorThrowable:()=>H,applyAttributes:()=>ue,attributesToString:()=>O,defaultConfig:()=>k,escapeAttributes:()=>L,htmx:()=>$,jhx:()=>D});module.exports=ae(de);var j={onAbort:"hx-on--abort",onAfterOnLoad:"hx-on--after-on-load",onAfterProcessNode:"hx-on--after-process-node",onAfterRequest:"hx-on--after-request",onAfterSettle:"hx-on--after-settle",onAfterSwap:"hx-on--after-swap",onBeforeCleanupElement:"hx-on--before-cleanup-element",onBeforeOnLoad:"hx-on--before-on-load",onBeforeProcessNode:"hx-on--before-process-node",onBeforeRequest:"hx-on--before-request",onBeforeSwap:"hx-on--before-swap",onBeforeSend:"hx-on--before-send",onBeforeTransition:"hx-on--before-transition",onConfigRequest:"hx-on--config-request",onConfirm:"hx-on--confirm",onHistoryCacheError:"hx-on--history-cache-error",onHistoryCacheHit:"hx-on--history-cache-hit",onHistoryCacheMiss:"hx-on--history-cache-miss",onHistoryCacheMissLoadError:"hx-on--history-cache-miss-load-error",onHistoryCacheMissLoad:"hx-on--history-cache-miss-load",onHistoryRestore:"hx-on--history-restore",onBeforeHistorySave:"hx-on--before-history-save",onLoad:"hx-on--load",onNoSSESourceError:"hx-on--no-sse-source-error",onOnLoadError:"hx-on--on-load-error",onOobAfterSwap:"hx-on--oob-after-swap",onOobBeforeSwap:"hx-on--oob-before-swap",onOobErrorNoTarget:"hx-on--oob-error-no-target",onPrompt:"hx-on--prompt",onPushedIntoHistory:"hx-on--pushed-into-history",onReplacedInHistory:"hx-on--replaced-in-history",onResponseError:"hx-on--response-error",onSendAbort:"hx-on--send-abort",onSendError:"hx-on--send-error",onSseError:"hx-on--sse-error",onSseOpen:"hx-on--sse-open",onSwapError:"hx-on--swap-error",onTargetError:"hx-on--target-error",onTimeout:"hx-on--timeout",onValidateUrl:"hx-on--validate-url",onValidationValidate:"hx-on--validation-validate",onValidationFailed:"hx-on--validation-failed",onValidationHalted:"hx-on--validation-halted",onXhrAbort:"hx-on--xhr-abort",onXhrLoadend:"hx-on--xhr-loadend",onXhrLoadstart:"hx-on--xhr-loadstart",onXhrProgress:"hx-on--xhr-progress"};var N={get:"hx-get",post:"hx-post",put:"hx-put",delete:"hx-delete",patch:"hx-patch",pushUrl:"hx-push-url",select:"hx-select",selectOob:"hx-select-oob",swap:"hx-swap",swapOob:"hx-swap-oob",target:"hx-target",trigger:"hx-trigger",vals:"hx-vals",boost:"hx-boost",confirm:"hx-confirm",disable:"hx-disable",disabledElt:"hx-disabled-elt",disinherit:"hx-disinherit",encoding:"hx-encoding",ext:"hx-ext",headers:"hx-headers",history:"hx-history",historyElt:"hx-history-elt",include:"hx-include",indicator:"hx-indicator",inherit:"hx-inherit",params:"hx-params",preserve:"hx-preserve",prompt:"hx-prompt",replaceUrl:"hx-replace-url",request:"hx-request",sync:"hx-sync",validate:"hx-validate",vars:"hx-vars",...j};var X={added:"htmx-added",indicator:"htmx-indicator",request:"htmx-request",settling:"htmx-settling",swapping:"htmx-swapping"};var M={addedClass:"hx-added",allowEval:!0,allowNestedOobSwaps:!0,allowScriptTags:!0,attributesToSettle:["class","style","width","height"],defaultFocusScroll:!1,defaultSettleDelay:20,defaultSwapDelay:0,defaultSwapStyle:"innerHTML",disableInheritance:!1,disableSelector:"[hx-disable], [data-hx-disable]",getCacheBusterParam:!1,globalViewTransitions:!1,historyCacheSize:10,historyEnabled:!0,historyRestoreAsHxRequest:!0,ignoreTitle:!1,includeIndicatorStyles:!0,indicatorClass:"hx-indicator",inlineScriptNonce:"",inlineStyleNonce:"",methodsThatUseUrlParams:["get","delete"],refreshOnHistoryMiss:!1,requestClass:"htmx-request",responseHandling:[{code:"204",swap:!1},{code:"[23]..",swap:!0},{code:"[45]..",swap:!1,error:!0}],scrollBehavior:"instant",scrollIntoViewOnBoost:!0,selfRequestsOnly:!0,settlingClass:"htmx-settling",swappingClass:"htmx-swapping",timeout:0,triggerSpecsCache:null,withCredentials:!1,wsBinaryType:"blob",wsReconnectDelay:"full-jitter"};var U={abort:"htmx:abort",afterOnLoad:"htmx:afterOnLoad",afterProcessNode:"htmx:afterProcessNode",afterRequest:"htmx:afterRequest",afterSettle:"htmx:afterSettle",afterSwap:"htmx:afterSwap",beforeCleanupElement:"htmx:beforeCleanupElement",beforeOnLoad:"htmx:beforeOnLoad",beforeProcessNode:"htmx:beforeProcessNode",beforeRequest:"htmx:beforeRequest",beforeSwap:"htmx:beforeSwap",beforeSend:"htmx:beforeSend",beforeTransition:"htmx:beforeTransition",configRequest:"htmx:configRequest",confirm:"htmx:confirm",historyCacheError:"htmx:historyCacheError",historyCacheHit:"htmx:historyCacheHit",historyCacheMiss:"htmx:historyCacheMiss",historyCacheMissLoadError:"htmx:historyCacheMissLoadError",historyCacheMissLoad:"htmx:historyCacheMissLoad",historyRestore:"htmx:historyRestore",beforeHistorySave:"htmx:beforeHistorySave",load:"htmx:load",noSSESourceError:"htmx:noSSESourceError",onLoadError:"htmx:onLoadError",oobAfterSwap:"htmx:oobAfterSwap",oobBeforeSwap:"htmx:oobBeforeSwap",oobErrorNoTarget:"htmx:oobErrorNoTarget",prompt:"htmx:prompt",pushedIntoHistory:"htmx:pushedIntoHistory",replacedInHistory:"htmx:replacedInHistory",responseError:"htmx:responseError",sendAbort:"htmx:sendAbort",sendError:"htmx:sendError",sseError:"htmx:sseError",sseOpen:"htmx:sseOpen",swapError:"htmx:swapError",targetError:"htmx:targetError",timeout:"htmx:timeout",validateUrl:"htmx:validateUrl",validationValidate:"htmx:validation:validate",validationFailed:"htmx:validation:failed",validationHalted:"htmx:validation:halted",xhrAbort:"htmx:xhr:abort",xhrLoadend:"htmx:xhr:loadend",xhrLoadstart:"htmx:xhr:loadstart",xhrProgress:"htmx:xhr:progress"};var F={headSupport:{name:"head-support",version:"2.0.5",npm:"htmx-ext-head-support",cdn:[{url:"https://cdn.jsdelivr.net/npm/htmx-ext-head-support@2.0.5",integrity:"sha384-cvMqHzjCJsOHgGuyB3sWXaUSv/Krm0BdzjuI1rtkjCbL1l1oHJx+cHyVRJhyuEz0"}]},htmx1Compat:{name:"htmx-1-compat",version:"2.0.2",npm:"htmx-ext-htmx-1-compat",cdn:[{url:"https://cdn.jsdelivr.net/npm/htmx-ext-htmx-1-compat@2.0.2",integrity:"sha384-lcvVWaNjF5zPPUeeWmC0OkJ2MLqoWLlkAabuGm+EuMSTfGo5WRyHrNaAp0cJr9Pg"}]},idiomorph:{name:"morph",version:"0.7.4",npm:"idiomorph",cdn:[{url:"https://unpkg.com/idiomorph@0.7.4/dist/idiomorph-ext.min.js",integrity:"sha384-SsScJKzATF/w6suEEdLbgYGsYFLzeKfOA6PY+/C5ZPxOSuA+ARquqtz/BZz9JWU8"}]},preload:{name:"preload",version:"2.1.2",npm:"htmx-ext-preload",cdn:[{url:"https://cdn.jsdelivr.net/npm/htmx-ext-preload@2.1.2",integrity:"sha384-PRIcY6hH1Y5784C76/Y8SqLyTanY9rnI3B8F3+hKZFNED55hsEqMJyqWhp95lgfk"}]},responseTargets:{name:"response-targets",version:"2.0.4",npm:"htmx-ext-response-targets",cdn:[{url:"https://cdn.jsdelivr.net/npm/htmx-ext-response-targets@2.0.4",integrity:"sha384-T41oglUPvXLGBVyRdZsVRxNWnOOqCynaPubjUVjxhsjFTKrFJGEMm3/0KGmNQ+Pg"}]},sse:{name:"sse",version:"2.2.4",npm:"htmx-ext-sse",cdn:[{url:"https://cdn.jsdelivr.net/npm/htmx-ext-sse@2.2.4",integrity:"sha384-A986SAtodyH8eg8x8irJnYUk7i9inVQqYigD6qZ9evobksGNIXfeFvDwLSHcp31N"}]},ws:{name:"ws",version:"2.0.4",npm:"htmx-ext-ws",cdn:[{url:"https://cdn.jsdelivr.net/npm/htmx-ext-ws@2.0.4",integrity:"sha384-1RwI/nvUSrMRuNj7hX1+27J8XDdCoSLf0EjEyF69nacuWyiJYoQ/j39RT1mSnd2G"}]}};var I={GET:"hx-get",POST:"hx-post",PUT:"hx-put",DELETE:"hx-delete",PATCH:"hx-patch",get:"hx-get",post:"hx-post",put:"hx-put",delete:"hx-delete",patch:"hx-patch"};var V={boosted:"HX-Boosted",currentUrl:"HX-Current-URL",historyRestoreRequest:"HX-History-Restore-Request",prompt:"HX-Prompt",request:"HX-Request",target:"HX-Target",triggerName:"HX-Trigger-Name",trigger:"HX-Trigger"};var W={location:"HX-Location",pushUrl:"HX-Push-URL",redirect:"HX-Redirect",refresh:"HX-Refresh",replaceUrl:"HX-Replace-URL",reswap:"HX-Reswap",retarget:"HX-Retarget",reselect:"HX-Reselect",trigger:"HX-Trigger",triggerAfterSettle:"HX-Trigger-After-Settle",triggerAfterSwap:"HX-Trigger-After-Swap"};var z={innerHTML:"innerHTML",outerHTML:"outerHTML",textContent:"textContent",beforeBegin:"beforebegin",afterBegin:"afterbegin",beforeEnd:"beforeend",afterEnd:"afterend",delete:"delete",none:"none"};var G={drop:"drop",abort:"abort",replace:"replace",queue:"queue",queueAll:"queue all",queueFirst:"queue first",queueLast:"queue last"};var $={attr:N,config:M,css:X,event:U,eventAttr:j,ext:F,method:I,res:W,req:V,swap:z,sync:G};var he=S(e=>{let o=/^(?:async\s*)?function\*?\s*(?:[A-z0-9]+)?\s*\(((?:[^)(]+|\((?:[^)(]+|\([^)(]*\))*\))*)\)\s*\{((?:[^}{]+|\{(?:[^}{]+|\{[^}{]*})*})*)}$/s,t=e.match(o);if(t&&t[2])return{fnType:"normal",fullMatch:t[0],paramStr:t[1]??"",bodyStr:`{ ${t[2].trim()} }`};let s=/^(?:async\s*)?(?:\(((?:[^)(]+|\((?:[^)(]+|\([^)(]*\))*\))*)\)|([^\s=()]+))\s*=>\s*(.*)$/s,r=e.match(s);if(r&&r[3]){let E=r[3].trim();return{fnType:"arrow",fullMatch:r[0],paramStr:r[1]??"",bodyStr:E.startsWith("{")&&(E.endsWith("}")||E.endsWith("};"))?E:`{ return ${E} }`}}return null},"matchFunctionString"),xe=S(e=>{if(!e)return[];let o=[],t=0,s=0,r=0,E=0;for(let T=0;T<e.length;T++){let A=e[T];A==="("?t++:A===")"?t--:A==="{"?s++:A==="}"?s--:A==="["?r++:A==="]"?r--:A===","&&t===0&&s===0&&r===0&&(o.push(e.substring(E,T).trim()),E=T+1)}return o.push(e.substring(E).trim()),o.filter(Boolean)},"splitParams"),J=S(e=>{if(typeof e!="function"||typeof e?.toString!="function")return null;let o=e.toString(),t=he(o);return t?{params:xe(t.paramStr),body:t.bodyStr}:null},"extractFunction");var Y=S(e=>{let o={};if(!e||typeof e!="object")return o;for(let t in e){if(t in j||!t.startsWith("on"))continue;let s=e[t];if(!s)continue;let r=J(s);r&&(o[t.toLowerCase()]=`((${r.params.join(",")}) => ${r.body})(${r.params.join(",")})`)}return o},"convertDomEventAttributes");var H=class e extends Error{static{S(this,"JhxErrorThrowable")}attribute;constructor(o,t){super(o),this.name="JhxError",this.attribute=t.attribute,t.stack&&(this.stack=t.stack),t.cause&&(this.cause=t.cause),Object.setPrototypeOf(this,e.prototype)}};var K=S((e,o)=>typeof o=="string"?`${e}:${o}`:"window"in o?`${e}:window:${o.position}`:"selector"in o?`${e}:${o.selector}:${o.position}`:"","processScrollOrShow"),q=S(e=>{if(!e)return;if(typeof e=="string")return e;let o=[];return e.style&&o.push(String(e.style)),e.swap&&o.push(`swap:${e.swap}`),e.settle&&o.push(`settle:${e.settle}`),typeof e.transition=="boolean"&&o.push(`transition:${e.transition}`),e.scroll&&o.push(K("scroll",e.scroll)),e.show&&o.push(K("show",e.show)),e.ignoreTitle&&o.push("ignoreTitle:true"),typeof e.focusScroll=="boolean"&&o.push(`focus-scroll:${e.focusScroll}`),o.filter(Boolean).join(" ")},"toJhxSwapAttribute");var C=S(e=>{if(!e)return;let o=Array.isArray(e)?e:[e],t=!1,s=o.map(r=>{if(typeof r!="object")return r;if(r.inherit!==void 0){if(!r.inherit)return;t=!0;return}if(r.position==="this"||r.position==="next"||r.position==="previous")return r.position;let E=[];return typeof r?.position=="string"&&E.push(r.position),typeof r.selector=="string"&&E.push(r.selector),E.join(" ")});return t&&s.unshift("inherit"),s.filter(r=>!!r).join(", ")},"toJhxTargetAttribute");var fe=S(e=>{if(e){if(typeof e=="object"){if(e.op==="this"||e.op==="document"||e.op==="window")return e.op;if(typeof e.selector=="string"&&typeof e.op=="string")return`${e.op} ${e.selector}`}return String(e)}},"toJhxFromAttribute"),Z=S(e=>typeof e=="string"?e:(Array.isArray(e)?e:[e]).map(t=>{if(typeof t=="string")return t;if(typeof t=="object"){let s=`${t.event||""}${t.filter?`[${t.filter}]`:""}`,r=[];return t.once===!0&&r.push("once"),t.changed===!0&&r.push("changed"),t.consume===!0&&r.push("consume"),t.delay&&r.push(`delay:${t.delay}`),t.from&&r.push(`from:${fe(t.from)}`),t.target&&r.push(`target:${C(t.target)}`),t.throttle&&r.push(`throttle:${t.throttle}`),t.queue&&r.push(`queue:${t.queue}`),s.concat(s?" ":"",r.join(" "))}return""}).filter(Boolean).join(", "),"toJhxTriggerAttribute");var pe=["get","post","put","patch","delete","route"],Q=S((e,o)=>{let t={};if(!e||typeof e!="object")return t;let s=pe.find(r=>!!e[r]);if(s)if(s==="route"){let r=e.method?.toLowerCase()||"get";t[`hx-${r}`]=String(e.route)}else t[`hx-${s}`]=String(e[s]);else e.method&&o.logger.warn("[jhx] The 'method' prop must be paired with a 'route' prop to generate a request attribute.");if(e.boost===!0&&(t["hx-boost"]="true"),e.confirm&&(t["hx-confirm"]=e.confirm),e.disable===!0&&(t["hx-disable"]="true"),e.disabledElt){let r=C(e.disabledElt);r&&(t["hx-disabled-elt"]=r)}if(e.disinherit&&(Array.isArray(e.disinherit)?t["hx-disinherit"]=e.disinherit.join(" "):t["hx-disinherit"]=e.disinherit),e.encoding&&(t["hx-encoding"]=e.encoding),e.ext){typeof e.ext=="string"&&(t["hx-ext"]=e.ext);let E=(Array.isArray(e.ext)?e.ext:[e.ext]).map(T=>typeof T=="object"?`${T?.name&&T.ignore===!0?"ignore:":""}${T?.name}`:T).filter(Boolean).join(",");E&&(t["hx-ext"]=E)}if(e.headers)if(typeof e.headers=="object")try{t["hx-headers"]=`${JSON.stringify(e.headers)}`}catch(r){throw o.logger.error("[jhx] Error while parsing the `hx-headers` object."),new H("[jhx] Error while parsing 'hx-request' object",{attribute:"hx-headers",cause:r,stack:r instanceof Error&&typeof r.stack=="string"?r.stack:void 0})}else if(typeof e.headers=="function"){let r=J(e.headers);if(r){let E=`((${r.params.join(",")}) => ${r.body})(${r.params.join(",")})`;t["hx-vals"]=`js:{...${E}}`}}else t["hx-headers"]=e.headers;if(e.history===!1&&(t["hx-history"]="false"),e.historyElt===!0&&(t["hx-history-elt"]="true"),e.indicator)if(typeof e.indicator=="object"){let r=e.indicator.inherit===!0?"inherit, ":"",E=e.indicator.closest===!0?"closest ":"";t["hx-indicator"]=`${r}${E}${e.indicator.selector}`}else t["hx-indicator"]=e.indicator;if(e.include){let r=C(e.include);r&&(t["hx-include"]=r)}if(e.inherit&&(Array.isArray(e.inherit)?t["hx-inherit"]=e.inherit.join(" "):t["hx-inherit"]=e.inherit),e.params&&(typeof e.params=="object"?e.params.include&&Array.isArray(e.params.include)?t["hx-params"]=`${e.params.include.join(",")}`:e.params.exclude&&Array.isArray(e.params.exclude)&&(t["hx-params"]=`not ${e.params.exclude.join(",")}`):t["hx-params"]=e.params),e.preserve===!0&&(t["hx-preserve"]="true"),e.prompt&&(t["hx-prompt"]=e.prompt),e.pushUrl&&(e.pushUrl===!0?t["hx-push-url"]="true":t["hx-push-url"]=e.pushUrl),(e.replaceUrl||e.replaceUrl===!1)&&(typeof e.replaceUrl=="boolean"?t["hx-replace-url"]=e.replaceUrl?"true":"false":t["hx-replace-url"]=e.replaceUrl),e.request)if(typeof e.request=="object")try{t["hx-request"]=`${JSON.stringify(e.request)}`}catch(r){throw new H("[jhx] Error while parsing 'hx-request' object",{attribute:"hx-request",cause:r,stack:r instanceof Error&&typeof r.stack=="string"?r.stack:void 0})}else if(typeof e.request=="function"){let r=J(e.request);if(r){let T=`(({ timeout, credentials, noHeaders }) => ({ timeout, credentials, noHeaders }))(${`((${r.params.join(",")}) => ${r.body})(${r.params.join(",")})`})`;t["hx-request"]=`js: ${T}`}}else t["hx-request"]=e.request;if(e.select&&(t["hx-select"]=e.select),e.selectOob)if(Array.isArray(e.selectOob))t["hx-select-oob"]=e.selectOob.map(r=>{if(typeof r=="string")return r;if(typeof r=="object"&&r.selector){let E=q(r.swap);return`${r.selector}${E?":"+E:""}`}return""}).filter(Boolean).join(",");else if(typeof e.selectOob=="object"){let r=q(e.selectOob.swap);t["hx-select-oob"]=`${e.selectOob.selector}${r?":"+r:""}`}else t["hx-select-oob"]=e.selectOob;if(e.swap){let r=q(e.swap);r&&(t["hx-swap"]=r)}if(e.swapOob)if(e.swapOob===!0)t["hx-swap-oob"]="true";else if(typeof e.swapOob=="object"){let r=q(e.swapOob.swap);r&&(t["hx-swap-oob"]=`${r}${e.swapOob.selector?":"+e.swapOob.selector:""}`)}else t["hx-swap-oob"]=e.swapOob;if(e.sync&&(typeof e.sync=="object"?e.sync.strategy&&e.sync.tag?t["hx-sync"]=`${e.sync.closest===!0?"closest ":""}${e.sync.tag}:${e.sync.strategy}`:e.sync.strategy&&(t["hx-sync"]=`this:${e.sync.strategy}`):t["hx-sync"]=e.sync),e.target){let r=C(e.target);r&&(t["hx-target"]=r)}if(e.trigger&&(t["hx-trigger"]=Z(e.trigger)),e.validate===!0&&(t["hx-validate"]="true"),e.vars&&(o.logger.warn("[jhx] The `hx-vars` attribute has been deprecated because of XSS vulnerabilities. Recommended to use the `hx-vals` attribute."),t["hx-vars"]=e.vars),e.vals)if(typeof e.vals=="object")try{t["hx-vals"]=`${JSON.stringify(e.vals)}`}catch(r){throw new H("[jhx] Error while parsing 'hx-vals' object",{attribute:"hx-vals",cause:r,stack:r instanceof Error&&typeof r.stack=="string"?r.stack:void 0})}else if(typeof e.vals=="function"){let r=J(e.vals);if(r){let E=`((${r.params.join(",")}) => ${r.body})(${r.params.join(",")})`;t["hx-vals"]=`js:{...${E}}`}}else t["hx-vals"]=e.vals;return t},"convertJhxAttributes");var _=S(e=>{let o={};if(!e||typeof e!="object")return o;for(let t in j)if(Object.prototype.hasOwnProperty.call(e,t)){let s=j[t],r=e[t];if(!r)continue;let E=J(r);if(!E)continue;o[s]=`((${E.params.join(",")}) => ${E.body})(${E.params.join(",")})`}return o},"convertJhxEventAttributes");var ce={"=":"&#61;","&":"&amp;",'"':"&quot;","'":"&#39;","`":"&#96;","<":"&lt;",">":"&gt;"},P=S(e=>String(e).replace(/[=&"'`<>]/g,o=>ce[o]??o),"escapeValue");var O=S((e,o=!0)=>Object.entries(e).map(([t,s])=>typeof s=="object"?`${t}="${JSON.stringify(s)}"`:`${t}="${typeof s=="string"&&o?P(s):s}"`).filter(Boolean).join(" "),"attributesToString");var k={logger:console,stringify:!1,escape:!0};var L=S(e=>{let o={};for(let[t,s]of Object.entries(e))o[t]=typeof s=="string"?P(s):s;return o},"escapeAttributes");function D(e,o){let t={...k,...o??{}},s={...Q(e,t),..._(e),...Y(e)};return t.stringify===!0?O(s,!!t.escape):t.escape===!0?L(s):s}S(D,"jhx");var me=S(e=>e.startsWith("hx-")||e in $.attr||e in $.eventAttr||e==="route"||e==="method","isJhxAttribute"),le=S(e=>{let{jhxConfig:o,as:t,children:s,...r}=e,E=t??"div",T={};for(let[B,te]of Object.entries(r))me(B)||(T[B]=te);let ee={...D(r,{...o,stringify:!1}),...T};return<E{...ee}>{s}</E>},"JhxComponent");var ue=S((e,o)=>{for(let[t,s]of Object.entries(o))typeof s=="object"?e.setAttribute(t,JSON.stringify(s)):e.setAttribute(t,String(s))},"applyAttributes");0&&(module.exports={JhxComponent,JhxErrorThrowable,applyAttributes,attributesToString,defaultConfig,escapeAttributes,htmx,jhx});
1
+ "use strict";var R=Object.defineProperty;var oe=Object.getOwnPropertyDescriptor;var se=Object.getOwnPropertyNames;var ne=Object.prototype.hasOwnProperty;var T=(e,o)=>R(e,"name",{value:o,configurable:!0});var ie=(e,o)=>{for(var t in o)R(e,t,{get:o[t],enumerable:!0})},ae=(e,o,t,s)=>{if(o&&typeof o=="object"||typeof o=="function")for(let r of se(o))!ne.call(e,r)&&r!==t&&R(e,r,{get:()=>o[r],enumerable:!(s=oe(o,r))||s.enumerable});return e};var he=e=>ae(R({},"__esModule",{value:!0}),e);var ye={};ie(ye,{JhxComponent:()=>ue,JhxErrorThrowable:()=>C,applyAttributes:()=>de,attributesToString:()=>k,defaultConfig:()=>L,escapeAttributes:()=>D,htmx:()=>P,jhx:()=>N});module.exports=he(ye);var J={onAbort:"hx-on--abort",onAfterOnLoad:"hx-on--after-on-load",onAfterProcessNode:"hx-on--after-process-node",onAfterRequest:"hx-on--after-request",onAfterSettle:"hx-on--after-settle",onAfterSwap:"hx-on--after-swap",onBeforeCleanupElement:"hx-on--before-cleanup-element",onBeforeOnLoad:"hx-on--before-on-load",onBeforeProcessNode:"hx-on--before-process-node",onBeforeRequest:"hx-on--before-request",onBeforeSwap:"hx-on--before-swap",onBeforeSend:"hx-on--before-send",onBeforeTransition:"hx-on--before-transition",onConfigRequest:"hx-on--config-request",onConfirm:"hx-on--confirm",onHistoryCacheError:"hx-on--history-cache-error",onHistoryCacheHit:"hx-on--history-cache-hit",onHistoryCacheMiss:"hx-on--history-cache-miss",onHistoryCacheMissLoadError:"hx-on--history-cache-miss-load-error",onHistoryCacheMissLoad:"hx-on--history-cache-miss-load",onHistoryRestore:"hx-on--history-restore",onBeforeHistorySave:"hx-on--before-history-save",onLoad:"hx-on--load",onNoSSESourceError:"hx-on--no-sse-source-error",onOnLoadError:"hx-on--on-load-error",onOobAfterSwap:"hx-on--oob-after-swap",onOobBeforeSwap:"hx-on--oob-before-swap",onOobErrorNoTarget:"hx-on--oob-error-no-target",onPrompt:"hx-on--prompt",onPushedIntoHistory:"hx-on--pushed-into-history",onReplacedInHistory:"hx-on--replaced-in-history",onResponseError:"hx-on--response-error",onSendAbort:"hx-on--send-abort",onSendError:"hx-on--send-error",onSseError:"hx-on--sse-error",onSseOpen:"hx-on--sse-open",onSwapError:"hx-on--swap-error",onTargetError:"hx-on--target-error",onTimeout:"hx-on--timeout",onValidateUrl:"hx-on--validate-url",onValidationValidate:"hx-on--validation-validate",onValidationFailed:"hx-on--validation-failed",onValidationHalted:"hx-on--validation-halted",onXhrAbort:"hx-on--xhr-abort",onXhrLoadend:"hx-on--xhr-loadend",onXhrLoadstart:"hx-on--xhr-loadstart",onXhrProgress:"hx-on--xhr-progress"};var X={get:"hx-get",post:"hx-post",put:"hx-put",delete:"hx-delete",patch:"hx-patch",pushUrl:"hx-push-url",select:"hx-select",selectOob:"hx-select-oob",swap:"hx-swap",swapOob:"hx-swap-oob",target:"hx-target",trigger:"hx-trigger",vals:"hx-vals",boost:"hx-boost",confirm:"hx-confirm",disable:"hx-disable",disabledElt:"hx-disabled-elt",disinherit:"hx-disinherit",encoding:"hx-encoding",ext:"hx-ext",headers:"hx-headers",history:"hx-history",historyElt:"hx-history-elt",include:"hx-include",indicator:"hx-indicator",inherit:"hx-inherit",params:"hx-params",preserve:"hx-preserve",prompt:"hx-prompt",replaceUrl:"hx-replace-url",request:"hx-request",sync:"hx-sync",validate:"hx-validate",vars:"hx-vars",...J};var M={added:"htmx-added",indicator:"htmx-indicator",request:"htmx-request",settling:"htmx-settling",swapping:"htmx-swapping"};var U={addedClass:"hx-added",allowEval:!0,allowNestedOobSwaps:!0,allowScriptTags:!0,attributesToSettle:["class","style","width","height"],defaultFocusScroll:!1,defaultSettleDelay:20,defaultSwapDelay:0,defaultSwapStyle:"innerHTML",disableInheritance:!1,disableSelector:"[hx-disable], [data-hx-disable]",getCacheBusterParam:!1,globalViewTransitions:!1,historyCacheSize:10,historyEnabled:!0,historyRestoreAsHxRequest:!0,ignoreTitle:!1,includeIndicatorStyles:!0,indicatorClass:"hx-indicator",inlineScriptNonce:"",inlineStyleNonce:"",methodsThatUseUrlParams:["get","delete"],refreshOnHistoryMiss:!1,requestClass:"htmx-request",responseHandling:[{code:"204",swap:!1},{code:"[23]..",swap:!0},{code:"[45]..",swap:!1,error:!0}],scrollBehavior:"instant",scrollIntoViewOnBoost:!0,selfRequestsOnly:!0,settlingClass:"htmx-settling",swappingClass:"htmx-swapping",timeout:0,triggerSpecsCache:null,withCredentials:!1,wsBinaryType:"blob",wsReconnectDelay:"full-jitter"};var F={abort:"htmx:abort",afterOnLoad:"htmx:afterOnLoad",afterProcessNode:"htmx:afterProcessNode",afterRequest:"htmx:afterRequest",afterSettle:"htmx:afterSettle",afterSwap:"htmx:afterSwap",beforeCleanupElement:"htmx:beforeCleanupElement",beforeOnLoad:"htmx:beforeOnLoad",beforeProcessNode:"htmx:beforeProcessNode",beforeRequest:"htmx:beforeRequest",beforeSwap:"htmx:beforeSwap",beforeSend:"htmx:beforeSend",beforeTransition:"htmx:beforeTransition",configRequest:"htmx:configRequest",confirm:"htmx:confirm",historyCacheError:"htmx:historyCacheError",historyCacheHit:"htmx:historyCacheHit",historyCacheMiss:"htmx:historyCacheMiss",historyCacheMissLoadError:"htmx:historyCacheMissLoadError",historyCacheMissLoad:"htmx:historyCacheMissLoad",historyRestore:"htmx:historyRestore",beforeHistorySave:"htmx:beforeHistorySave",load:"htmx:load",noSSESourceError:"htmx:noSSESourceError",onLoadError:"htmx:onLoadError",oobAfterSwap:"htmx:oobAfterSwap",oobBeforeSwap:"htmx:oobBeforeSwap",oobErrorNoTarget:"htmx:oobErrorNoTarget",prompt:"htmx:prompt",pushedIntoHistory:"htmx:pushedIntoHistory",replacedInHistory:"htmx:replacedInHistory",responseError:"htmx:responseError",sendAbort:"htmx:sendAbort",sendError:"htmx:sendError",sseError:"htmx:sseError",sseOpen:"htmx:sseOpen",swapError:"htmx:swapError",targetError:"htmx:targetError",timeout:"htmx:timeout",validateUrl:"htmx:validateUrl",validationValidate:"htmx:validation:validate",validationFailed:"htmx:validation:failed",validationHalted:"htmx:validation:halted",xhrAbort:"htmx:xhr:abort",xhrLoadend:"htmx:xhr:loadend",xhrLoadstart:"htmx:xhr:loadstart",xhrProgress:"htmx:xhr:progress"};var I={headSupport:{name:"head-support",version:"2.0.5",npm:"htmx-ext-head-support",cdn:[{url:"https://cdn.jsdelivr.net/npm/htmx-ext-head-support@2.0.5",integrity:"sha384-cvMqHzjCJsOHgGuyB3sWXaUSv/Krm0BdzjuI1rtkjCbL1l1oHJx+cHyVRJhyuEz0"}]},htmx1Compat:{name:"htmx-1-compat",version:"2.0.2",npm:"htmx-ext-htmx-1-compat",cdn:[{url:"https://cdn.jsdelivr.net/npm/htmx-ext-htmx-1-compat@2.0.2",integrity:"sha384-lcvVWaNjF5zPPUeeWmC0OkJ2MLqoWLlkAabuGm+EuMSTfGo5WRyHrNaAp0cJr9Pg"}]},idiomorph:{name:"morph",version:"0.7.4",npm:"idiomorph",cdn:[{url:"https://unpkg.com/idiomorph@0.7.4/dist/idiomorph-ext.min.js",integrity:"sha384-SsScJKzATF/w6suEEdLbgYGsYFLzeKfOA6PY+/C5ZPxOSuA+ARquqtz/BZz9JWU8"}]},preload:{name:"preload",version:"2.1.2",npm:"htmx-ext-preload",cdn:[{url:"https://cdn.jsdelivr.net/npm/htmx-ext-preload@2.1.2",integrity:"sha384-PRIcY6hH1Y5784C76/Y8SqLyTanY9rnI3B8F3+hKZFNED55hsEqMJyqWhp95lgfk"}]},responseTargets:{name:"response-targets",version:"2.0.4",npm:"htmx-ext-response-targets",cdn:[{url:"https://cdn.jsdelivr.net/npm/htmx-ext-response-targets@2.0.4",integrity:"sha384-T41oglUPvXLGBVyRdZsVRxNWnOOqCynaPubjUVjxhsjFTKrFJGEMm3/0KGmNQ+Pg"}]},sse:{name:"sse",version:"2.2.4",npm:"htmx-ext-sse",cdn:[{url:"https://cdn.jsdelivr.net/npm/htmx-ext-sse@2.2.4",integrity:"sha384-A986SAtodyH8eg8x8irJnYUk7i9inVQqYigD6qZ9evobksGNIXfeFvDwLSHcp31N"}]},ws:{name:"ws",version:"2.0.4",npm:"htmx-ext-ws",cdn:[{url:"https://cdn.jsdelivr.net/npm/htmx-ext-ws@2.0.4",integrity:"sha384-1RwI/nvUSrMRuNj7hX1+27J8XDdCoSLf0EjEyF69nacuWyiJYoQ/j39RT1mSnd2G"}]}};var V={GET:"hx-get",POST:"hx-post",PUT:"hx-put",DELETE:"hx-delete",PATCH:"hx-patch",get:"hx-get",post:"hx-post",put:"hx-put",delete:"hx-delete",patch:"hx-patch"};var W={boosted:"HX-Boosted",currentUrl:"HX-Current-URL",historyRestoreRequest:"HX-History-Restore-Request",prompt:"HX-Prompt",request:"HX-Request",target:"HX-Target",triggerName:"HX-Trigger-Name",trigger:"HX-Trigger"};var z={location:"HX-Location",pushUrl:"HX-Push-URL",redirect:"HX-Redirect",refresh:"HX-Refresh",replaceUrl:"HX-Replace-URL",reswap:"HX-Reswap",retarget:"HX-Retarget",reselect:"HX-Reselect",trigger:"HX-Trigger",triggerAfterSettle:"HX-Trigger-After-Settle",triggerAfterSwap:"HX-Trigger-After-Swap"};var G={innerHTML:"innerHTML",outerHTML:"outerHTML",textContent:"textContent",beforeBegin:"beforebegin",afterBegin:"afterbegin",beforeEnd:"beforeend",afterEnd:"afterend",delete:"delete",none:"none"};var Y={drop:"drop",abort:"abort",replace:"replace",queue:"queue",queueAll:"queue all",queueFirst:"queue first",queueLast:"queue last"};var P={attr:X,config:U,css:M,event:F,eventAttr:J,ext:I,method:V,res:z,req:W,swap:G,sync:Y};var K=T(e=>{let o=[],t=0;for(;t<e.length;){let s=e[t];if(s==="`"){let r=t;for(t++;t<e.length;)if(e[t]==="\\")t+=2;else if(e[t]==="`"){t++;break}else t++;o.push(e.slice(r,t));continue}if(s==='"'){t++;let r=[],E=!1;for(;t<e.length;)if(e[t]==="\\"){let S=e[t+1];r.push(e[t],S??""),t+=2}else if(e[t]==='"'){t++;break}else e[t]==="$"&&e[t+1]==="{"&&(E=!0),r.push(e[t]),t++;let j=r.join("");if(E){o.push("`");for(let S=0;S<j.length;S++)if(j[S]==="\\"){let A=j[S+1];A==='"'?(o.push('"'),S++):A==="`"?(o.push("\\`"),S++):(o.push(j[S],A??""),S++)}else j[S]==="`"?o.push("\\`"):o.push(j[S]);o.push("`")}else{o.push("'");for(let S=0;S<j.length;S++)if(j[S]==="\\"){let A=j[S+1];A==='"'?(o.push('"'),S++):A==="'"?(o.push("\\'"),S++):(o.push(j[S],A??""),S++)}else j[S]==="'"?o.push("\\'"):o.push(j[S]);o.push("'")}continue}if(s==="'"){let r=t;for(t++;t<e.length;)if(e[t]==="\\")t+=2;else if(e[t]==="'"){t++;break}else t++;o.push(e.slice(r,t));continue}if(s==="/"&&t>0){let r=e.slice(0,t).trimEnd().slice(-1);if(["=","(",",","[","!","&","|",":",";","{","}","?"].includes(r)){let j=t;t++;let S=!1;for(;t<e.length;)if(e[t]==="\\")t+=2;else if(e[t]==="[")S=!0,t++;else if(e[t]==="]")S=!1,t++;else if(e[t]==="/"&&!S){for(t++;t<e.length&&/[gimsuy]/.test(e[t]);)t++;break}else t++;o.push(e.slice(j,t));continue}}o.push(s),t++}return o.join("")},"normalizeStringQuotes");var fe=T(e=>{let o=/^(?:async\s*)?function\*?\s*(?:[A-z0-9]+)?\s*\(((?:[^)(]+|\((?:[^)(]+|\([^)(]*\))*\))*)\)\s*\{((?:[^}{]+|\{(?:[^}{]+|\{[^}{]*})*})*)}$/s,t=e.match(o);if(t&&t[2])return{fnType:"normal",fullMatch:t[0],paramStr:t[1]??"",bodyStr:`{ ${t[2].trim()} }`};let s=/^(?:async\s*)?(?:\(((?:[^)(]+|\((?:[^)(]+|\([^)(]*\))*\))*)\)|([^\s=()]+))\s*=>\s*(.*)$/s,r=e.match(s);if(r&&r[3]){let E=r[3].trim();return{fnType:"arrow",fullMatch:r[0],paramStr:r[1]??"",bodyStr:E.startsWith("{")&&(E.endsWith("}")||E.endsWith("};"))?E:`{ return ${E} }`}}return null},"matchFunctionString"),xe=T(e=>{if(!e)return[];let o=[],t=0,s=0,r=0,E=0;for(let j=0;j<e.length;j++){let S=e[j];S==="("?t++:S===")"?t--:S==="{"?s++:S==="}"?s--:S==="["?r++:S==="]"?r--:S===","&&t===0&&s===0&&r===0&&(o.push(e.substring(E,j).trim()),E=j+1)}return o.push(e.substring(E).trim()),o.filter(Boolean)},"splitParams"),H=T(e=>{if(typeof e!="function"||typeof e?.toString!="function")return null;let o=e.toString().replaceAll("void 0","undefined"),t=fe(o);return t?{params:xe(t.paramStr),body:K(t.bodyStr)}:null},"extractFunction");var Q=T(e=>{let o={};if(!e||typeof e!="object")return o;for(let t in e){if(t in J||!t.startsWith("on"))continue;let s=e[t];if(!s)continue;let r=H(s);r&&(o[t.toLowerCase()]=`((${r.params.join(",")}) => ${r.body})(${r.params.join(",")})`)}return o},"convertDomEventAttributes");var C=class e extends Error{static{T(this,"JhxErrorThrowable")}attribute;constructor(o,t){super(o),this.name="JhxError",this.attribute=t.attribute,t.stack&&(this.stack=t.stack),t.cause&&(this.cause=t.cause),Object.setPrototypeOf(this,e.prototype)}};var Z=T((e,o)=>typeof o=="string"?`${e}:${o}`:"window"in o?`${e}:window:${o.position}`:"selector"in o?`${e}:${o.selector}:${o.position}`:"","processScrollOrShow"),$=T(e=>{if(!e)return;if(typeof e=="string")return e;let o=[];return e.style&&o.push(String(e.style)),e.swap&&o.push(`swap:${e.swap}`),e.settle&&o.push(`settle:${e.settle}`),typeof e.transition=="boolean"&&o.push(`transition:${e.transition}`),e.scroll&&o.push(Z("scroll",e.scroll)),e.show&&o.push(Z("show",e.show)),e.ignoreTitle&&o.push("ignoreTitle:true"),typeof e.focusScroll=="boolean"&&o.push(`focus-scroll:${e.focusScroll}`),o.filter(Boolean).join(" ")},"toJhxSwapAttribute");var q=T(e=>{if(!e)return;let o=Array.isArray(e)?e:[e],t=!1,s=o.map(r=>{if(typeof r!="object")return r;if(r.inherit!==void 0){if(!r.inherit)return;t=!0;return}if(r.position==="this"||r.position==="next"||r.position==="previous")return r.position;let E=[];return typeof r?.position=="string"&&E.push(r.position),typeof r.selector=="string"&&E.push(r.selector),E.join(" ")});return t&&s.unshift("inherit"),s.filter(r=>!!r).join(", ")},"toJhxTargetAttribute");var pe=T(e=>{if(e){if(typeof e=="object"){if(e.op==="this"||e.op==="document"||e.op==="window")return e.op;if(typeof e.selector=="string"&&typeof e.op=="string")return`${e.op} ${e.selector}`}return String(e)}},"toJhxFromAttribute"),_=T(e=>typeof e=="string"?e:(Array.isArray(e)?e:[e]).map(t=>{if(typeof t=="string")return t;if(typeof t=="object"){let s=`${t.event||""}${t.filter?`[${t.filter}]`:""}`,r=[];return t.once===!0&&r.push("once"),t.changed===!0&&r.push("changed"),t.consume===!0&&r.push("consume"),t.delay&&r.push(`delay:${t.delay}`),t.from&&r.push(`from:${pe(t.from)}`),t.target&&r.push(`target:${q(t.target)}`),t.throttle&&r.push(`throttle:${t.throttle}`),t.queue&&r.push(`queue:${t.queue}`),s.concat(s?" ":"",r.join(" "))}return""}).filter(Boolean).join(", "),"toJhxTriggerAttribute");var ce=["get","post","put","patch","delete","route"],ee=T((e,o)=>{let t={};if(!e||typeof e!="object")return t;let s=ce.find(r=>!!e[r]);if(s)if(s==="route"){let r=e.method?.toLowerCase()||"get";t[`hx-${r}`]=String(e.route)}else t[`hx-${s}`]=String(e[s]);else e.method&&o.logger.warn("[jhx] The 'method' prop must be paired with a 'route' prop to generate a request attribute.");if(e.boost===!0&&(t["hx-boost"]="true"),e.confirm&&(t["hx-confirm"]=e.confirm),e.disable===!0&&(t["hx-disable"]="true"),e.disabledElt){let r=q(e.disabledElt);r&&(t["hx-disabled-elt"]=r)}if(e.disinherit&&(Array.isArray(e.disinherit)?t["hx-disinherit"]=e.disinherit.join(" "):t["hx-disinherit"]=e.disinherit),e.encoding&&(t["hx-encoding"]=e.encoding),e.ext){typeof e.ext=="string"&&(t["hx-ext"]=e.ext);let E=(Array.isArray(e.ext)?e.ext:[e.ext]).map(j=>typeof j=="object"?`${j?.name&&j.ignore===!0?"ignore:":""}${j?.name}`:j).filter(Boolean).join(",");E&&(t["hx-ext"]=E)}if(e.headers)if(typeof e.headers=="object")try{t["hx-headers"]=`${JSON.stringify(e.headers)}`}catch(r){throw o.logger.error("[jhx] Error while parsing the `hx-headers` object."),new C("[jhx] Error while parsing 'hx-request' object",{attribute:"hx-headers",cause:r,stack:r instanceof Error&&typeof r.stack=="string"?r.stack:void 0})}else if(typeof e.headers=="function"){let r=H(e.headers);if(r){let E=`((${r.params.join(",")}) => ${r.body})(${r.params.join(",")})`;t["hx-vals"]=`js:{...${E}}`}}else t["hx-headers"]=e.headers;if(e.history===!1&&(t["hx-history"]="false"),e.historyElt===!0&&(t["hx-history-elt"]="true"),e.indicator)if(typeof e.indicator=="object"){let r=e.indicator.inherit===!0?"inherit, ":"",E=e.indicator.closest===!0?"closest ":"";t["hx-indicator"]=`${r}${E}${e.indicator.selector}`}else t["hx-indicator"]=e.indicator;if(e.include){let r=q(e.include);r&&(t["hx-include"]=r)}if(e.inherit&&(Array.isArray(e.inherit)?t["hx-inherit"]=e.inherit.join(" "):t["hx-inherit"]=e.inherit),e.params&&(typeof e.params=="object"?e.params.include&&Array.isArray(e.params.include)?t["hx-params"]=`${e.params.include.join(",")}`:e.params.exclude&&Array.isArray(e.params.exclude)&&(t["hx-params"]=`not ${e.params.exclude.join(",")}`):t["hx-params"]=e.params),e.preserve===!0&&(t["hx-preserve"]="true"),e.prompt&&(t["hx-prompt"]=e.prompt),e.pushUrl&&(e.pushUrl===!0?t["hx-push-url"]="true":t["hx-push-url"]=e.pushUrl),(e.replaceUrl||e.replaceUrl===!1)&&(typeof e.replaceUrl=="boolean"?t["hx-replace-url"]=e.replaceUrl?"true":"false":t["hx-replace-url"]=e.replaceUrl),e.request)if(typeof e.request=="object")try{t["hx-request"]=`${JSON.stringify(e.request)}`}catch(r){throw new C("[jhx] Error while parsing 'hx-request' object",{attribute:"hx-request",cause:r,stack:r instanceof Error&&typeof r.stack=="string"?r.stack:void 0})}else if(typeof e.request=="function"){let r=H(e.request);if(r){let j=`(({ timeout, credentials, noHeaders }) => ({ timeout, credentials, noHeaders }))(${`((${r.params.join(",")}) => ${r.body})(${r.params.join(",")})`})`;t["hx-request"]=`js: ${j}`}}else t["hx-request"]=e.request;if(e.select&&(t["hx-select"]=e.select),e.selectOob)if(Array.isArray(e.selectOob))t["hx-select-oob"]=e.selectOob.map(r=>{if(typeof r=="string")return r;if(typeof r=="object"&&r.selector){let E=$(r.swap);return`${r.selector}${E?":"+E:""}`}return""}).filter(Boolean).join(",");else if(typeof e.selectOob=="object"){let r=$(e.selectOob.swap);t["hx-select-oob"]=`${e.selectOob.selector}${r?":"+r:""}`}else t["hx-select-oob"]=e.selectOob;if(e.swap){let r=$(e.swap);r&&(t["hx-swap"]=r)}if(e.swapOob)if(e.swapOob===!0)t["hx-swap-oob"]="true";else if(typeof e.swapOob=="object"){let r=$(e.swapOob.swap);r&&(t["hx-swap-oob"]=`${r}${e.swapOob.selector?":"+e.swapOob.selector:""}`)}else t["hx-swap-oob"]=e.swapOob;if(e.sync&&(typeof e.sync=="object"?e.sync.strategy&&e.sync.tag?t["hx-sync"]=`${e.sync.closest===!0?"closest ":""}${e.sync.tag}:${e.sync.strategy}`:e.sync.strategy&&(t["hx-sync"]=`this:${e.sync.strategy}`):t["hx-sync"]=e.sync),e.target){let r=q(e.target);r&&(t["hx-target"]=r)}if(e.trigger&&(t["hx-trigger"]=_(e.trigger)),e.validate===!0&&(t["hx-validate"]="true"),e.vars&&(o.logger.warn("[jhx] The `hx-vars` attribute has been deprecated because of XSS vulnerabilities. Recommended to use the `hx-vals` attribute."),t["hx-vars"]=e.vars),e.vals)if(typeof e.vals=="object")try{t["hx-vals"]=`${JSON.stringify(e.vals)}`}catch(r){throw new C("[jhx] Error while parsing 'hx-vals' object",{attribute:"hx-vals",cause:r,stack:r instanceof Error&&typeof r.stack=="string"?r.stack:void 0})}else if(typeof e.vals=="function"){let r=H(e.vals);if(r){let E=`((${r.params.join(",")}) => ${r.body})(${r.params.join(",")})`;t["hx-vals"]=`js:{...${E}}`}}else t["hx-vals"]=e.vals;return t},"convertJhxAttributes");var te=T(e=>{let o={};if(!e||typeof e!="object")return o;for(let t in J)if(Object.prototype.hasOwnProperty.call(e,t)){let s=J[t],r=e[t];if(!r)continue;let E=H(r);if(!E)continue;o[s]=`((${E.params.join(",")}) => ${E.body})(${E.params.join(",")})`}return o},"convertJhxEventAttributes");var me={'"':"&quot;","<":"&lt;",">":"&gt;"},O=T(e=>String(e).replace(/["<>]/g,o=>me[o]??o),"escapeValue");var k=T((e,o=!0)=>Object.entries(e).map(([t,s])=>typeof s=="object"?`${t}="${JSON.stringify(s)}"`:`${t}="${typeof s=="string"&&o?O(s):s}"`).filter(Boolean).join(" "),"attributesToString");var L={logger:console,stringify:!1,escape:!0};var D=T(e=>{let o={};for(let[t,s]of Object.entries(e))o[t]=typeof s=="string"?O(s):s;return o},"escapeAttributes");function N(e,o){let t={...L,...o??{}},s={...ee(e,t),...te(e),...Q(e)};return t.stringify===!0?k(s,!!t.escape):t.escape===!0?D(s):s}T(N,"jhx");var le=T(e=>e.startsWith("hx-")||e in P.attr||e in P.eventAttr||e==="route"||e==="method","isJhxAttribute"),ue=T(e=>{let{jhxConfig:o,as:t,children:s,...r}=e,E=t??"div",j={};for(let[B,re]of Object.entries(r))le(B)||(j[B]=re);let A={...N(r,{...o,stringify:!1}),...j};return<E{...A}>{s}</E>},"JhxComponent");var de=T((e,o)=>{for(let[t,s]of Object.entries(o))typeof s=="object"?e.setAttribute(t,JSON.stringify(s)):e.setAttribute(t,String(s))},"applyAttributes");0&&(module.exports={JhxComponent,JhxErrorThrowable,applyAttributes,attributesToString,defaultConfig,escapeAttributes,htmx,jhx});
package/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { HttpVerb, HtmxResponseHandlingConfig as HtmxResponseHandlingConfig$1, HtmxSettleInfo as HtmxSettleInfo$1, HtmxAjaxHelperContext, HtmxExtension as HtmxExtension$1, HtmxSwapSpecification, SwapOptions, ConditionalFunction as ConditionalFunction$1 } from 'htmx.org';
2
- import { DOMAttributes, ElementType, ComponentPropsWithoutRef, PropsWithChildren, JSX } from 'react';
2
+ import { DOMAttributes, ElementType, PropsWithChildren, ComponentPropsWithoutRef, JSX } from 'react';
3
3
 
4
4
  /**
5
5
  * @see https://htmx.org/reference/
@@ -1731,7 +1731,7 @@ type JhxAttribute = HtmxAttribute | HtmxEventAttribute | Lowercase<keyof DomEven
1731
1731
  * - If the value is a `function`, it is evaluated client-side when triggered.
1732
1732
  * @template TDom Type for additional parameters received from the DOM.
1733
1733
  */
1734
- type JhxEvaluableAttribute<TBaseDom extends object = object> = (<TDom extends TBaseDom | object = object>(dom: DomObjects & TDom) => Record<string, any> | object) | Record<string, any> | object | string;
1734
+ type JhxEvaluableAttribute<TBaseDom extends object = object> = (<TDom extends TBaseDom | object = TBaseDom>(dom: DomObjects & TBaseDom & TDom) => Record<string, any> | object) | Record<string, any> | object | string;
1735
1735
 
1736
1736
  type JhxExtensionAttribute = Array<string | {
1737
1737
  /** The name of the HTMX extension. */
@@ -1774,7 +1774,7 @@ interface JhxRequestArgs {
1774
1774
  */
1775
1775
  type JhxRequestAttribute<
1776
1776
  /** Type for additional parameters received from the DOM. */
1777
- TDom extends object = object> = ((dom: DomObjects & TDom) => JhxRequestArgs) | JhxRequestArgs | string;
1777
+ TBaseDom extends object = object> = (<TDom extends TBaseDom | object = TBaseDom>(dom: DomObjects & TBaseDom & TDom) => JhxRequestArgs) | JhxRequestArgs | string;
1778
1778
 
1779
1779
  type JhxSelectOobAttribute = Array<string | {
1780
1780
  selector: string;
package/index.js CHANGED
@@ -1 +1 @@
1
- var te=Object.defineProperty;var S=(e,o)=>te(e,"name",{value:o,configurable:!0});var j={onAbort:"hx-on--abort",onAfterOnLoad:"hx-on--after-on-load",onAfterProcessNode:"hx-on--after-process-node",onAfterRequest:"hx-on--after-request",onAfterSettle:"hx-on--after-settle",onAfterSwap:"hx-on--after-swap",onBeforeCleanupElement:"hx-on--before-cleanup-element",onBeforeOnLoad:"hx-on--before-on-load",onBeforeProcessNode:"hx-on--before-process-node",onBeforeRequest:"hx-on--before-request",onBeforeSwap:"hx-on--before-swap",onBeforeSend:"hx-on--before-send",onBeforeTransition:"hx-on--before-transition",onConfigRequest:"hx-on--config-request",onConfirm:"hx-on--confirm",onHistoryCacheError:"hx-on--history-cache-error",onHistoryCacheHit:"hx-on--history-cache-hit",onHistoryCacheMiss:"hx-on--history-cache-miss",onHistoryCacheMissLoadError:"hx-on--history-cache-miss-load-error",onHistoryCacheMissLoad:"hx-on--history-cache-miss-load",onHistoryRestore:"hx-on--history-restore",onBeforeHistorySave:"hx-on--before-history-save",onLoad:"hx-on--load",onNoSSESourceError:"hx-on--no-sse-source-error",onOnLoadError:"hx-on--on-load-error",onOobAfterSwap:"hx-on--oob-after-swap",onOobBeforeSwap:"hx-on--oob-before-swap",onOobErrorNoTarget:"hx-on--oob-error-no-target",onPrompt:"hx-on--prompt",onPushedIntoHistory:"hx-on--pushed-into-history",onReplacedInHistory:"hx-on--replaced-in-history",onResponseError:"hx-on--response-error",onSendAbort:"hx-on--send-abort",onSendError:"hx-on--send-error",onSseError:"hx-on--sse-error",onSseOpen:"hx-on--sse-open",onSwapError:"hx-on--swap-error",onTargetError:"hx-on--target-error",onTimeout:"hx-on--timeout",onValidateUrl:"hx-on--validate-url",onValidationValidate:"hx-on--validation-validate",onValidationFailed:"hx-on--validation-failed",onValidationHalted:"hx-on--validation-halted",onXhrAbort:"hx-on--xhr-abort",onXhrLoadend:"hx-on--xhr-loadend",onXhrLoadstart:"hx-on--xhr-loadstart",onXhrProgress:"hx-on--xhr-progress"};var O={get:"hx-get",post:"hx-post",put:"hx-put",delete:"hx-delete",patch:"hx-patch",pushUrl:"hx-push-url",select:"hx-select",selectOob:"hx-select-oob",swap:"hx-swap",swapOob:"hx-swap-oob",target:"hx-target",trigger:"hx-trigger",vals:"hx-vals",boost:"hx-boost",confirm:"hx-confirm",disable:"hx-disable",disabledElt:"hx-disabled-elt",disinherit:"hx-disinherit",encoding:"hx-encoding",ext:"hx-ext",headers:"hx-headers",history:"hx-history",historyElt:"hx-history-elt",include:"hx-include",indicator:"hx-indicator",inherit:"hx-inherit",params:"hx-params",preserve:"hx-preserve",prompt:"hx-prompt",replaceUrl:"hx-replace-url",request:"hx-request",sync:"hx-sync",validate:"hx-validate",vars:"hx-vars",...j};var k={added:"htmx-added",indicator:"htmx-indicator",request:"htmx-request",settling:"htmx-settling",swapping:"htmx-swapping"};var L={addedClass:"hx-added",allowEval:!0,allowNestedOobSwaps:!0,allowScriptTags:!0,attributesToSettle:["class","style","width","height"],defaultFocusScroll:!1,defaultSettleDelay:20,defaultSwapDelay:0,defaultSwapStyle:"innerHTML",disableInheritance:!1,disableSelector:"[hx-disable], [data-hx-disable]",getCacheBusterParam:!1,globalViewTransitions:!1,historyCacheSize:10,historyEnabled:!0,historyRestoreAsHxRequest:!0,ignoreTitle:!1,includeIndicatorStyles:!0,indicatorClass:"hx-indicator",inlineScriptNonce:"",inlineStyleNonce:"",methodsThatUseUrlParams:["get","delete"],refreshOnHistoryMiss:!1,requestClass:"htmx-request",responseHandling:[{code:"204",swap:!1},{code:"[23]..",swap:!0},{code:"[45]..",swap:!1,error:!0}],scrollBehavior:"instant",scrollIntoViewOnBoost:!0,selfRequestsOnly:!0,settlingClass:"htmx-settling",swappingClass:"htmx-swapping",timeout:0,triggerSpecsCache:null,withCredentials:!1,wsBinaryType:"blob",wsReconnectDelay:"full-jitter"};var D={abort:"htmx:abort",afterOnLoad:"htmx:afterOnLoad",afterProcessNode:"htmx:afterProcessNode",afterRequest:"htmx:afterRequest",afterSettle:"htmx:afterSettle",afterSwap:"htmx:afterSwap",beforeCleanupElement:"htmx:beforeCleanupElement",beforeOnLoad:"htmx:beforeOnLoad",beforeProcessNode:"htmx:beforeProcessNode",beforeRequest:"htmx:beforeRequest",beforeSwap:"htmx:beforeSwap",beforeSend:"htmx:beforeSend",beforeTransition:"htmx:beforeTransition",configRequest:"htmx:configRequest",confirm:"htmx:confirm",historyCacheError:"htmx:historyCacheError",historyCacheHit:"htmx:historyCacheHit",historyCacheMiss:"htmx:historyCacheMiss",historyCacheMissLoadError:"htmx:historyCacheMissLoadError",historyCacheMissLoad:"htmx:historyCacheMissLoad",historyRestore:"htmx:historyRestore",beforeHistorySave:"htmx:beforeHistorySave",load:"htmx:load",noSSESourceError:"htmx:noSSESourceError",onLoadError:"htmx:onLoadError",oobAfterSwap:"htmx:oobAfterSwap",oobBeforeSwap:"htmx:oobBeforeSwap",oobErrorNoTarget:"htmx:oobErrorNoTarget",prompt:"htmx:prompt",pushedIntoHistory:"htmx:pushedIntoHistory",replacedInHistory:"htmx:replacedInHistory",responseError:"htmx:responseError",sendAbort:"htmx:sendAbort",sendError:"htmx:sendError",sseError:"htmx:sseError",sseOpen:"htmx:sseOpen",swapError:"htmx:swapError",targetError:"htmx:targetError",timeout:"htmx:timeout",validateUrl:"htmx:validateUrl",validationValidate:"htmx:validation:validate",validationFailed:"htmx:validation:failed",validationHalted:"htmx:validation:halted",xhrAbort:"htmx:xhr:abort",xhrLoadend:"htmx:xhr:loadend",xhrLoadstart:"htmx:xhr:loadstart",xhrProgress:"htmx:xhr:progress"};var B={headSupport:{name:"head-support",version:"2.0.5",npm:"htmx-ext-head-support",cdn:[{url:"https://cdn.jsdelivr.net/npm/htmx-ext-head-support@2.0.5",integrity:"sha384-cvMqHzjCJsOHgGuyB3sWXaUSv/Krm0BdzjuI1rtkjCbL1l1oHJx+cHyVRJhyuEz0"}]},htmx1Compat:{name:"htmx-1-compat",version:"2.0.2",npm:"htmx-ext-htmx-1-compat",cdn:[{url:"https://cdn.jsdelivr.net/npm/htmx-ext-htmx-1-compat@2.0.2",integrity:"sha384-lcvVWaNjF5zPPUeeWmC0OkJ2MLqoWLlkAabuGm+EuMSTfGo5WRyHrNaAp0cJr9Pg"}]},idiomorph:{name:"morph",version:"0.7.4",npm:"idiomorph",cdn:[{url:"https://unpkg.com/idiomorph@0.7.4/dist/idiomorph-ext.min.js",integrity:"sha384-SsScJKzATF/w6suEEdLbgYGsYFLzeKfOA6PY+/C5ZPxOSuA+ARquqtz/BZz9JWU8"}]},preload:{name:"preload",version:"2.1.2",npm:"htmx-ext-preload",cdn:[{url:"https://cdn.jsdelivr.net/npm/htmx-ext-preload@2.1.2",integrity:"sha384-PRIcY6hH1Y5784C76/Y8SqLyTanY9rnI3B8F3+hKZFNED55hsEqMJyqWhp95lgfk"}]},responseTargets:{name:"response-targets",version:"2.0.4",npm:"htmx-ext-response-targets",cdn:[{url:"https://cdn.jsdelivr.net/npm/htmx-ext-response-targets@2.0.4",integrity:"sha384-T41oglUPvXLGBVyRdZsVRxNWnOOqCynaPubjUVjxhsjFTKrFJGEMm3/0KGmNQ+Pg"}]},sse:{name:"sse",version:"2.2.4",npm:"htmx-ext-sse",cdn:[{url:"https://cdn.jsdelivr.net/npm/htmx-ext-sse@2.2.4",integrity:"sha384-A986SAtodyH8eg8x8irJnYUk7i9inVQqYigD6qZ9evobksGNIXfeFvDwLSHcp31N"}]},ws:{name:"ws",version:"2.0.4",npm:"htmx-ext-ws",cdn:[{url:"https://cdn.jsdelivr.net/npm/htmx-ext-ws@2.0.4",integrity:"sha384-1RwI/nvUSrMRuNj7hX1+27J8XDdCoSLf0EjEyF69nacuWyiJYoQ/j39RT1mSnd2G"}]}};var N={GET:"hx-get",POST:"hx-post",PUT:"hx-put",DELETE:"hx-delete",PATCH:"hx-patch",get:"hx-get",post:"hx-post",put:"hx-put",delete:"hx-delete",patch:"hx-patch"};var X={boosted:"HX-Boosted",currentUrl:"HX-Current-URL",historyRestoreRequest:"HX-History-Restore-Request",prompt:"HX-Prompt",request:"HX-Request",target:"HX-Target",triggerName:"HX-Trigger-Name",trigger:"HX-Trigger"};var M={location:"HX-Location",pushUrl:"HX-Push-URL",redirect:"HX-Redirect",refresh:"HX-Refresh",replaceUrl:"HX-Replace-URL",reswap:"HX-Reswap",retarget:"HX-Retarget",reselect:"HX-Reselect",trigger:"HX-Trigger",triggerAfterSettle:"HX-Trigger-After-Settle",triggerAfterSwap:"HX-Trigger-After-Swap"};var U={innerHTML:"innerHTML",outerHTML:"outerHTML",textContent:"textContent",beforeBegin:"beforebegin",afterBegin:"afterbegin",beforeEnd:"beforeend",afterEnd:"afterend",delete:"delete",none:"none"};var F={drop:"drop",abort:"abort",replace:"replace",queue:"queue",queueAll:"queue all",queueFirst:"queue first",queueLast:"queue last"};var $={attr:O,config:L,css:k,event:D,eventAttr:j,ext:B,method:N,res:M,req:X,swap:U,sync:F};var re=S(e=>{let o=/^(?:async\s*)?function\*?\s*(?:[A-z0-9]+)?\s*\(((?:[^)(]+|\((?:[^)(]+|\([^)(]*\))*\))*)\)\s*\{((?:[^}{]+|\{(?:[^}{]+|\{[^}{]*})*})*)}$/s,t=e.match(o);if(t&&t[2])return{fnType:"normal",fullMatch:t[0],paramStr:t[1]??"",bodyStr:`{ ${t[2].trim()} }`};let s=/^(?:async\s*)?(?:\(((?:[^)(]+|\((?:[^)(]+|\([^)(]*\))*\))*)\)|([^\s=()]+))\s*=>\s*(.*)$/s,r=e.match(s);if(r&&r[3]){let E=r[3].trim();return{fnType:"arrow",fullMatch:r[0],paramStr:r[1]??"",bodyStr:E.startsWith("{")&&(E.endsWith("}")||E.endsWith("};"))?E:`{ return ${E} }`}}return null},"matchFunctionString"),oe=S(e=>{if(!e)return[];let o=[],t=0,s=0,r=0,E=0;for(let T=0;T<e.length;T++){let A=e[T];A==="("?t++:A===")"?t--:A==="{"?s++:A==="}"?s--:A==="["?r++:A==="]"?r--:A===","&&t===0&&s===0&&r===0&&(o.push(e.substring(E,T).trim()),E=T+1)}return o.push(e.substring(E).trim()),o.filter(Boolean)},"splitParams"),J=S(e=>{if(typeof e!="function"||typeof e?.toString!="function")return null;let o=e.toString(),t=re(o);return t?{params:oe(t.paramStr),body:t.bodyStr}:null},"extractFunction");var I=S(e=>{let o={};if(!e||typeof e!="object")return o;for(let t in e){if(t in j||!t.startsWith("on"))continue;let s=e[t];if(!s)continue;let r=J(s);r&&(o[t.toLowerCase()]=`((${r.params.join(",")}) => ${r.body})(${r.params.join(",")})`)}return o},"convertDomEventAttributes");var H=class e extends Error{static{S(this,"JhxErrorThrowable")}attribute;constructor(o,t){super(o),this.name="JhxError",this.attribute=t.attribute,t.stack&&(this.stack=t.stack),t.cause&&(this.cause=t.cause),Object.setPrototypeOf(this,e.prototype)}};var V=S((e,o)=>typeof o=="string"?`${e}:${o}`:"window"in o?`${e}:window:${o.position}`:"selector"in o?`${e}:${o.selector}:${o.position}`:"","processScrollOrShow"),q=S(e=>{if(!e)return;if(typeof e=="string")return e;let o=[];return e.style&&o.push(String(e.style)),e.swap&&o.push(`swap:${e.swap}`),e.settle&&o.push(`settle:${e.settle}`),typeof e.transition=="boolean"&&o.push(`transition:${e.transition}`),e.scroll&&o.push(V("scroll",e.scroll)),e.show&&o.push(V("show",e.show)),e.ignoreTitle&&o.push("ignoreTitle:true"),typeof e.focusScroll=="boolean"&&o.push(`focus-scroll:${e.focusScroll}`),o.filter(Boolean).join(" ")},"toJhxSwapAttribute");var C=S(e=>{if(!e)return;let o=Array.isArray(e)?e:[e],t=!1,s=o.map(r=>{if(typeof r!="object")return r;if(r.inherit!==void 0){if(!r.inherit)return;t=!0;return}if(r.position==="this"||r.position==="next"||r.position==="previous")return r.position;let E=[];return typeof r?.position=="string"&&E.push(r.position),typeof r.selector=="string"&&E.push(r.selector),E.join(" ")});return t&&s.unshift("inherit"),s.filter(r=>!!r).join(", ")},"toJhxTargetAttribute");var se=S(e=>{if(e){if(typeof e=="object"){if(e.op==="this"||e.op==="document"||e.op==="window")return e.op;if(typeof e.selector=="string"&&typeof e.op=="string")return`${e.op} ${e.selector}`}return String(e)}},"toJhxFromAttribute"),W=S(e=>typeof e=="string"?e:(Array.isArray(e)?e:[e]).map(t=>{if(typeof t=="string")return t;if(typeof t=="object"){let s=`${t.event||""}${t.filter?`[${t.filter}]`:""}`,r=[];return t.once===!0&&r.push("once"),t.changed===!0&&r.push("changed"),t.consume===!0&&r.push("consume"),t.delay&&r.push(`delay:${t.delay}`),t.from&&r.push(`from:${se(t.from)}`),t.target&&r.push(`target:${C(t.target)}`),t.throttle&&r.push(`throttle:${t.throttle}`),t.queue&&r.push(`queue:${t.queue}`),s.concat(s?" ":"",r.join(" "))}return""}).filter(Boolean).join(", "),"toJhxTriggerAttribute");var ne=["get","post","put","patch","delete","route"],z=S((e,o)=>{let t={};if(!e||typeof e!="object")return t;let s=ne.find(r=>!!e[r]);if(s)if(s==="route"){let r=e.method?.toLowerCase()||"get";t[`hx-${r}`]=String(e.route)}else t[`hx-${s}`]=String(e[s]);else e.method&&o.logger.warn("[jhx] The 'method' prop must be paired with a 'route' prop to generate a request attribute.");if(e.boost===!0&&(t["hx-boost"]="true"),e.confirm&&(t["hx-confirm"]=e.confirm),e.disable===!0&&(t["hx-disable"]="true"),e.disabledElt){let r=C(e.disabledElt);r&&(t["hx-disabled-elt"]=r)}if(e.disinherit&&(Array.isArray(e.disinherit)?t["hx-disinherit"]=e.disinherit.join(" "):t["hx-disinherit"]=e.disinherit),e.encoding&&(t["hx-encoding"]=e.encoding),e.ext){typeof e.ext=="string"&&(t["hx-ext"]=e.ext);let E=(Array.isArray(e.ext)?e.ext:[e.ext]).map(T=>typeof T=="object"?`${T?.name&&T.ignore===!0?"ignore:":""}${T?.name}`:T).filter(Boolean).join(",");E&&(t["hx-ext"]=E)}if(e.headers)if(typeof e.headers=="object")try{t["hx-headers"]=`${JSON.stringify(e.headers)}`}catch(r){throw o.logger.error("[jhx] Error while parsing the `hx-headers` object."),new H("[jhx] Error while parsing 'hx-request' object",{attribute:"hx-headers",cause:r,stack:r instanceof Error&&typeof r.stack=="string"?r.stack:void 0})}else if(typeof e.headers=="function"){let r=J(e.headers);if(r){let E=`((${r.params.join(",")}) => ${r.body})(${r.params.join(",")})`;t["hx-vals"]=`js:{...${E}}`}}else t["hx-headers"]=e.headers;if(e.history===!1&&(t["hx-history"]="false"),e.historyElt===!0&&(t["hx-history-elt"]="true"),e.indicator)if(typeof e.indicator=="object"){let r=e.indicator.inherit===!0?"inherit, ":"",E=e.indicator.closest===!0?"closest ":"";t["hx-indicator"]=`${r}${E}${e.indicator.selector}`}else t["hx-indicator"]=e.indicator;if(e.include){let r=C(e.include);r&&(t["hx-include"]=r)}if(e.inherit&&(Array.isArray(e.inherit)?t["hx-inherit"]=e.inherit.join(" "):t["hx-inherit"]=e.inherit),e.params&&(typeof e.params=="object"?e.params.include&&Array.isArray(e.params.include)?t["hx-params"]=`${e.params.include.join(",")}`:e.params.exclude&&Array.isArray(e.params.exclude)&&(t["hx-params"]=`not ${e.params.exclude.join(",")}`):t["hx-params"]=e.params),e.preserve===!0&&(t["hx-preserve"]="true"),e.prompt&&(t["hx-prompt"]=e.prompt),e.pushUrl&&(e.pushUrl===!0?t["hx-push-url"]="true":t["hx-push-url"]=e.pushUrl),(e.replaceUrl||e.replaceUrl===!1)&&(typeof e.replaceUrl=="boolean"?t["hx-replace-url"]=e.replaceUrl?"true":"false":t["hx-replace-url"]=e.replaceUrl),e.request)if(typeof e.request=="object")try{t["hx-request"]=`${JSON.stringify(e.request)}`}catch(r){throw new H("[jhx] Error while parsing 'hx-request' object",{attribute:"hx-request",cause:r,stack:r instanceof Error&&typeof r.stack=="string"?r.stack:void 0})}else if(typeof e.request=="function"){let r=J(e.request);if(r){let T=`(({ timeout, credentials, noHeaders }) => ({ timeout, credentials, noHeaders }))(${`((${r.params.join(",")}) => ${r.body})(${r.params.join(",")})`})`;t["hx-request"]=`js: ${T}`}}else t["hx-request"]=e.request;if(e.select&&(t["hx-select"]=e.select),e.selectOob)if(Array.isArray(e.selectOob))t["hx-select-oob"]=e.selectOob.map(r=>{if(typeof r=="string")return r;if(typeof r=="object"&&r.selector){let E=q(r.swap);return`${r.selector}${E?":"+E:""}`}return""}).filter(Boolean).join(",");else if(typeof e.selectOob=="object"){let r=q(e.selectOob.swap);t["hx-select-oob"]=`${e.selectOob.selector}${r?":"+r:""}`}else t["hx-select-oob"]=e.selectOob;if(e.swap){let r=q(e.swap);r&&(t["hx-swap"]=r)}if(e.swapOob)if(e.swapOob===!0)t["hx-swap-oob"]="true";else if(typeof e.swapOob=="object"){let r=q(e.swapOob.swap);r&&(t["hx-swap-oob"]=`${r}${e.swapOob.selector?":"+e.swapOob.selector:""}`)}else t["hx-swap-oob"]=e.swapOob;if(e.sync&&(typeof e.sync=="object"?e.sync.strategy&&e.sync.tag?t["hx-sync"]=`${e.sync.closest===!0?"closest ":""}${e.sync.tag}:${e.sync.strategy}`:e.sync.strategy&&(t["hx-sync"]=`this:${e.sync.strategy}`):t["hx-sync"]=e.sync),e.target){let r=C(e.target);r&&(t["hx-target"]=r)}if(e.trigger&&(t["hx-trigger"]=W(e.trigger)),e.validate===!0&&(t["hx-validate"]="true"),e.vars&&(o.logger.warn("[jhx] The `hx-vars` attribute has been deprecated because of XSS vulnerabilities. Recommended to use the `hx-vals` attribute."),t["hx-vars"]=e.vars),e.vals)if(typeof e.vals=="object")try{t["hx-vals"]=`${JSON.stringify(e.vals)}`}catch(r){throw new H("[jhx] Error while parsing 'hx-vals' object",{attribute:"hx-vals",cause:r,stack:r instanceof Error&&typeof r.stack=="string"?r.stack:void 0})}else if(typeof e.vals=="function"){let r=J(e.vals);if(r){let E=`((${r.params.join(",")}) => ${r.body})(${r.params.join(",")})`;t["hx-vals"]=`js:{...${E}}`}}else t["hx-vals"]=e.vals;return t},"convertJhxAttributes");var G=S(e=>{let o={};if(!e||typeof e!="object")return o;for(let t in j)if(Object.prototype.hasOwnProperty.call(e,t)){let s=j[t],r=e[t];if(!r)continue;let E=J(r);if(!E)continue;o[s]=`((${E.params.join(",")}) => ${E.body})(${E.params.join(",")})`}return o},"convertJhxEventAttributes");var ie={"=":"&#61;","&":"&amp;",'"':"&quot;","'":"&#39;","`":"&#96;","<":"&lt;",">":"&gt;"},R=S(e=>String(e).replace(/[=&"'`<>]/g,o=>ie[o]??o),"escapeValue");var Y=S((e,o=!0)=>Object.entries(e).map(([t,s])=>typeof s=="object"?`${t}="${JSON.stringify(s)}"`:`${t}="${typeof s=="string"&&o?R(s):s}"`).filter(Boolean).join(" "),"attributesToString");var K={logger:console,stringify:!1,escape:!0};var Z=S(e=>{let o={};for(let[t,s]of Object.entries(e))o[t]=typeof s=="string"?R(s):s;return o},"escapeAttributes");function Q(e,o){let t={...K,...o??{}},s={...z(e,t),...G(e),...I(e)};return t.stringify===!0?Y(s,!!t.escape):t.escape===!0?Z(s):s}S(Q,"jhx");var ae=S(e=>e.startsWith("hx-")||e in $.attr||e in $.eventAttr||e==="route"||e==="method","isJhxAttribute"),ho=S(e=>{let{jhxConfig:o,as:t,children:s,...r}=e,E=t??"div",T={};for(let[P,ee]of Object.entries(r))ae(P)||(T[P]=ee);let _={...Q(r,{...o,stringify:!1}),...T};return<E{..._}>{s}</E>},"JhxComponent");var po=S((e,o)=>{for(let[t,s]of Object.entries(o))typeof s=="object"?e.setAttribute(t,JSON.stringify(s)):e.setAttribute(t,String(s))},"applyAttributes");export{ho as JhxComponent,H as JhxErrorThrowable,po as applyAttributes,Y as attributesToString,K as defaultConfig,Z as escapeAttributes,$ as htmx,Q as jhx};
1
+ var re=Object.defineProperty;var T=(e,o)=>re(e,"name",{value:o,configurable:!0});var J={onAbort:"hx-on--abort",onAfterOnLoad:"hx-on--after-on-load",onAfterProcessNode:"hx-on--after-process-node",onAfterRequest:"hx-on--after-request",onAfterSettle:"hx-on--after-settle",onAfterSwap:"hx-on--after-swap",onBeforeCleanupElement:"hx-on--before-cleanup-element",onBeforeOnLoad:"hx-on--before-on-load",onBeforeProcessNode:"hx-on--before-process-node",onBeforeRequest:"hx-on--before-request",onBeforeSwap:"hx-on--before-swap",onBeforeSend:"hx-on--before-send",onBeforeTransition:"hx-on--before-transition",onConfigRequest:"hx-on--config-request",onConfirm:"hx-on--confirm",onHistoryCacheError:"hx-on--history-cache-error",onHistoryCacheHit:"hx-on--history-cache-hit",onHistoryCacheMiss:"hx-on--history-cache-miss",onHistoryCacheMissLoadError:"hx-on--history-cache-miss-load-error",onHistoryCacheMissLoad:"hx-on--history-cache-miss-load",onHistoryRestore:"hx-on--history-restore",onBeforeHistorySave:"hx-on--before-history-save",onLoad:"hx-on--load",onNoSSESourceError:"hx-on--no-sse-source-error",onOnLoadError:"hx-on--on-load-error",onOobAfterSwap:"hx-on--oob-after-swap",onOobBeforeSwap:"hx-on--oob-before-swap",onOobErrorNoTarget:"hx-on--oob-error-no-target",onPrompt:"hx-on--prompt",onPushedIntoHistory:"hx-on--pushed-into-history",onReplacedInHistory:"hx-on--replaced-in-history",onResponseError:"hx-on--response-error",onSendAbort:"hx-on--send-abort",onSendError:"hx-on--send-error",onSseError:"hx-on--sse-error",onSseOpen:"hx-on--sse-open",onSwapError:"hx-on--swap-error",onTargetError:"hx-on--target-error",onTimeout:"hx-on--timeout",onValidateUrl:"hx-on--validate-url",onValidationValidate:"hx-on--validation-validate",onValidationFailed:"hx-on--validation-failed",onValidationHalted:"hx-on--validation-halted",onXhrAbort:"hx-on--xhr-abort",onXhrLoadend:"hx-on--xhr-loadend",onXhrLoadstart:"hx-on--xhr-loadstart",onXhrProgress:"hx-on--xhr-progress"};var k={get:"hx-get",post:"hx-post",put:"hx-put",delete:"hx-delete",patch:"hx-patch",pushUrl:"hx-push-url",select:"hx-select",selectOob:"hx-select-oob",swap:"hx-swap",swapOob:"hx-swap-oob",target:"hx-target",trigger:"hx-trigger",vals:"hx-vals",boost:"hx-boost",confirm:"hx-confirm",disable:"hx-disable",disabledElt:"hx-disabled-elt",disinherit:"hx-disinherit",encoding:"hx-encoding",ext:"hx-ext",headers:"hx-headers",history:"hx-history",historyElt:"hx-history-elt",include:"hx-include",indicator:"hx-indicator",inherit:"hx-inherit",params:"hx-params",preserve:"hx-preserve",prompt:"hx-prompt",replaceUrl:"hx-replace-url",request:"hx-request",sync:"hx-sync",validate:"hx-validate",vars:"hx-vars",...J};var L={added:"htmx-added",indicator:"htmx-indicator",request:"htmx-request",settling:"htmx-settling",swapping:"htmx-swapping"};var D={addedClass:"hx-added",allowEval:!0,allowNestedOobSwaps:!0,allowScriptTags:!0,attributesToSettle:["class","style","width","height"],defaultFocusScroll:!1,defaultSettleDelay:20,defaultSwapDelay:0,defaultSwapStyle:"innerHTML",disableInheritance:!1,disableSelector:"[hx-disable], [data-hx-disable]",getCacheBusterParam:!1,globalViewTransitions:!1,historyCacheSize:10,historyEnabled:!0,historyRestoreAsHxRequest:!0,ignoreTitle:!1,includeIndicatorStyles:!0,indicatorClass:"hx-indicator",inlineScriptNonce:"",inlineStyleNonce:"",methodsThatUseUrlParams:["get","delete"],refreshOnHistoryMiss:!1,requestClass:"htmx-request",responseHandling:[{code:"204",swap:!1},{code:"[23]..",swap:!0},{code:"[45]..",swap:!1,error:!0}],scrollBehavior:"instant",scrollIntoViewOnBoost:!0,selfRequestsOnly:!0,settlingClass:"htmx-settling",swappingClass:"htmx-swapping",timeout:0,triggerSpecsCache:null,withCredentials:!1,wsBinaryType:"blob",wsReconnectDelay:"full-jitter"};var N={abort:"htmx:abort",afterOnLoad:"htmx:afterOnLoad",afterProcessNode:"htmx:afterProcessNode",afterRequest:"htmx:afterRequest",afterSettle:"htmx:afterSettle",afterSwap:"htmx:afterSwap",beforeCleanupElement:"htmx:beforeCleanupElement",beforeOnLoad:"htmx:beforeOnLoad",beforeProcessNode:"htmx:beforeProcessNode",beforeRequest:"htmx:beforeRequest",beforeSwap:"htmx:beforeSwap",beforeSend:"htmx:beforeSend",beforeTransition:"htmx:beforeTransition",configRequest:"htmx:configRequest",confirm:"htmx:confirm",historyCacheError:"htmx:historyCacheError",historyCacheHit:"htmx:historyCacheHit",historyCacheMiss:"htmx:historyCacheMiss",historyCacheMissLoadError:"htmx:historyCacheMissLoadError",historyCacheMissLoad:"htmx:historyCacheMissLoad",historyRestore:"htmx:historyRestore",beforeHistorySave:"htmx:beforeHistorySave",load:"htmx:load",noSSESourceError:"htmx:noSSESourceError",onLoadError:"htmx:onLoadError",oobAfterSwap:"htmx:oobAfterSwap",oobBeforeSwap:"htmx:oobBeforeSwap",oobErrorNoTarget:"htmx:oobErrorNoTarget",prompt:"htmx:prompt",pushedIntoHistory:"htmx:pushedIntoHistory",replacedInHistory:"htmx:replacedInHistory",responseError:"htmx:responseError",sendAbort:"htmx:sendAbort",sendError:"htmx:sendError",sseError:"htmx:sseError",sseOpen:"htmx:sseOpen",swapError:"htmx:swapError",targetError:"htmx:targetError",timeout:"htmx:timeout",validateUrl:"htmx:validateUrl",validationValidate:"htmx:validation:validate",validationFailed:"htmx:validation:failed",validationHalted:"htmx:validation:halted",xhrAbort:"htmx:xhr:abort",xhrLoadend:"htmx:xhr:loadend",xhrLoadstart:"htmx:xhr:loadstart",xhrProgress:"htmx:xhr:progress"};var B={headSupport:{name:"head-support",version:"2.0.5",npm:"htmx-ext-head-support",cdn:[{url:"https://cdn.jsdelivr.net/npm/htmx-ext-head-support@2.0.5",integrity:"sha384-cvMqHzjCJsOHgGuyB3sWXaUSv/Krm0BdzjuI1rtkjCbL1l1oHJx+cHyVRJhyuEz0"}]},htmx1Compat:{name:"htmx-1-compat",version:"2.0.2",npm:"htmx-ext-htmx-1-compat",cdn:[{url:"https://cdn.jsdelivr.net/npm/htmx-ext-htmx-1-compat@2.0.2",integrity:"sha384-lcvVWaNjF5zPPUeeWmC0OkJ2MLqoWLlkAabuGm+EuMSTfGo5WRyHrNaAp0cJr9Pg"}]},idiomorph:{name:"morph",version:"0.7.4",npm:"idiomorph",cdn:[{url:"https://unpkg.com/idiomorph@0.7.4/dist/idiomorph-ext.min.js",integrity:"sha384-SsScJKzATF/w6suEEdLbgYGsYFLzeKfOA6PY+/C5ZPxOSuA+ARquqtz/BZz9JWU8"}]},preload:{name:"preload",version:"2.1.2",npm:"htmx-ext-preload",cdn:[{url:"https://cdn.jsdelivr.net/npm/htmx-ext-preload@2.1.2",integrity:"sha384-PRIcY6hH1Y5784C76/Y8SqLyTanY9rnI3B8F3+hKZFNED55hsEqMJyqWhp95lgfk"}]},responseTargets:{name:"response-targets",version:"2.0.4",npm:"htmx-ext-response-targets",cdn:[{url:"https://cdn.jsdelivr.net/npm/htmx-ext-response-targets@2.0.4",integrity:"sha384-T41oglUPvXLGBVyRdZsVRxNWnOOqCynaPubjUVjxhsjFTKrFJGEMm3/0KGmNQ+Pg"}]},sse:{name:"sse",version:"2.2.4",npm:"htmx-ext-sse",cdn:[{url:"https://cdn.jsdelivr.net/npm/htmx-ext-sse@2.2.4",integrity:"sha384-A986SAtodyH8eg8x8irJnYUk7i9inVQqYigD6qZ9evobksGNIXfeFvDwLSHcp31N"}]},ws:{name:"ws",version:"2.0.4",npm:"htmx-ext-ws",cdn:[{url:"https://cdn.jsdelivr.net/npm/htmx-ext-ws@2.0.4",integrity:"sha384-1RwI/nvUSrMRuNj7hX1+27J8XDdCoSLf0EjEyF69nacuWyiJYoQ/j39RT1mSnd2G"}]}};var X={GET:"hx-get",POST:"hx-post",PUT:"hx-put",DELETE:"hx-delete",PATCH:"hx-patch",get:"hx-get",post:"hx-post",put:"hx-put",delete:"hx-delete",patch:"hx-patch"};var M={boosted:"HX-Boosted",currentUrl:"HX-Current-URL",historyRestoreRequest:"HX-History-Restore-Request",prompt:"HX-Prompt",request:"HX-Request",target:"HX-Target",triggerName:"HX-Trigger-Name",trigger:"HX-Trigger"};var U={location:"HX-Location",pushUrl:"HX-Push-URL",redirect:"HX-Redirect",refresh:"HX-Refresh",replaceUrl:"HX-Replace-URL",reswap:"HX-Reswap",retarget:"HX-Retarget",reselect:"HX-Reselect",trigger:"HX-Trigger",triggerAfterSettle:"HX-Trigger-After-Settle",triggerAfterSwap:"HX-Trigger-After-Swap"};var F={innerHTML:"innerHTML",outerHTML:"outerHTML",textContent:"textContent",beforeBegin:"beforebegin",afterBegin:"afterbegin",beforeEnd:"beforeend",afterEnd:"afterend",delete:"delete",none:"none"};var I={drop:"drop",abort:"abort",replace:"replace",queue:"queue",queueAll:"queue all",queueFirst:"queue first",queueLast:"queue last"};var P={attr:k,config:D,css:L,event:N,eventAttr:J,ext:B,method:X,res:U,req:M,swap:F,sync:I};var V=T(e=>{let o=[],t=0;for(;t<e.length;){let s=e[t];if(s==="`"){let r=t;for(t++;t<e.length;)if(e[t]==="\\")t+=2;else if(e[t]==="`"){t++;break}else t++;o.push(e.slice(r,t));continue}if(s==='"'){t++;let r=[],E=!1;for(;t<e.length;)if(e[t]==="\\"){let S=e[t+1];r.push(e[t],S??""),t+=2}else if(e[t]==='"'){t++;break}else e[t]==="$"&&e[t+1]==="{"&&(E=!0),r.push(e[t]),t++;let j=r.join("");if(E){o.push("`");for(let S=0;S<j.length;S++)if(j[S]==="\\"){let A=j[S+1];A==='"'?(o.push('"'),S++):A==="`"?(o.push("\\`"),S++):(o.push(j[S],A??""),S++)}else j[S]==="`"?o.push("\\`"):o.push(j[S]);o.push("`")}else{o.push("'");for(let S=0;S<j.length;S++)if(j[S]==="\\"){let A=j[S+1];A==='"'?(o.push('"'),S++):A==="'"?(o.push("\\'"),S++):(o.push(j[S],A??""),S++)}else j[S]==="'"?o.push("\\'"):o.push(j[S]);o.push("'")}continue}if(s==="'"){let r=t;for(t++;t<e.length;)if(e[t]==="\\")t+=2;else if(e[t]==="'"){t++;break}else t++;o.push(e.slice(r,t));continue}if(s==="/"&&t>0){let r=e.slice(0,t).trimEnd().slice(-1);if(["=","(",",","[","!","&","|",":",";","{","}","?"].includes(r)){let j=t;t++;let S=!1;for(;t<e.length;)if(e[t]==="\\")t+=2;else if(e[t]==="[")S=!0,t++;else if(e[t]==="]")S=!1,t++;else if(e[t]==="/"&&!S){for(t++;t<e.length&&/[gimsuy]/.test(e[t]);)t++;break}else t++;o.push(e.slice(j,t));continue}}o.push(s),t++}return o.join("")},"normalizeStringQuotes");var oe=T(e=>{let o=/^(?:async\s*)?function\*?\s*(?:[A-z0-9]+)?\s*\(((?:[^)(]+|\((?:[^)(]+|\([^)(]*\))*\))*)\)\s*\{((?:[^}{]+|\{(?:[^}{]+|\{[^}{]*})*})*)}$/s,t=e.match(o);if(t&&t[2])return{fnType:"normal",fullMatch:t[0],paramStr:t[1]??"",bodyStr:`{ ${t[2].trim()} }`};let s=/^(?:async\s*)?(?:\(((?:[^)(]+|\((?:[^)(]+|\([^)(]*\))*\))*)\)|([^\s=()]+))\s*=>\s*(.*)$/s,r=e.match(s);if(r&&r[3]){let E=r[3].trim();return{fnType:"arrow",fullMatch:r[0],paramStr:r[1]??"",bodyStr:E.startsWith("{")&&(E.endsWith("}")||E.endsWith("};"))?E:`{ return ${E} }`}}return null},"matchFunctionString"),se=T(e=>{if(!e)return[];let o=[],t=0,s=0,r=0,E=0;for(let j=0;j<e.length;j++){let S=e[j];S==="("?t++:S===")"?t--:S==="{"?s++:S==="}"?s--:S==="["?r++:S==="]"?r--:S===","&&t===0&&s===0&&r===0&&(o.push(e.substring(E,j).trim()),E=j+1)}return o.push(e.substring(E).trim()),o.filter(Boolean)},"splitParams"),H=T(e=>{if(typeof e!="function"||typeof e?.toString!="function")return null;let o=e.toString().replaceAll("void 0","undefined"),t=oe(o);return t?{params:se(t.paramStr),body:V(t.bodyStr)}:null},"extractFunction");var W=T(e=>{let o={};if(!e||typeof e!="object")return o;for(let t in e){if(t in J||!t.startsWith("on"))continue;let s=e[t];if(!s)continue;let r=H(s);r&&(o[t.toLowerCase()]=`((${r.params.join(",")}) => ${r.body})(${r.params.join(",")})`)}return o},"convertDomEventAttributes");var C=class e extends Error{static{T(this,"JhxErrorThrowable")}attribute;constructor(o,t){super(o),this.name="JhxError",this.attribute=t.attribute,t.stack&&(this.stack=t.stack),t.cause&&(this.cause=t.cause),Object.setPrototypeOf(this,e.prototype)}};var z=T((e,o)=>typeof o=="string"?`${e}:${o}`:"window"in o?`${e}:window:${o.position}`:"selector"in o?`${e}:${o.selector}:${o.position}`:"","processScrollOrShow"),$=T(e=>{if(!e)return;if(typeof e=="string")return e;let o=[];return e.style&&o.push(String(e.style)),e.swap&&o.push(`swap:${e.swap}`),e.settle&&o.push(`settle:${e.settle}`),typeof e.transition=="boolean"&&o.push(`transition:${e.transition}`),e.scroll&&o.push(z("scroll",e.scroll)),e.show&&o.push(z("show",e.show)),e.ignoreTitle&&o.push("ignoreTitle:true"),typeof e.focusScroll=="boolean"&&o.push(`focus-scroll:${e.focusScroll}`),o.filter(Boolean).join(" ")},"toJhxSwapAttribute");var q=T(e=>{if(!e)return;let o=Array.isArray(e)?e:[e],t=!1,s=o.map(r=>{if(typeof r!="object")return r;if(r.inherit!==void 0){if(!r.inherit)return;t=!0;return}if(r.position==="this"||r.position==="next"||r.position==="previous")return r.position;let E=[];return typeof r?.position=="string"&&E.push(r.position),typeof r.selector=="string"&&E.push(r.selector),E.join(" ")});return t&&s.unshift("inherit"),s.filter(r=>!!r).join(", ")},"toJhxTargetAttribute");var ne=T(e=>{if(e){if(typeof e=="object"){if(e.op==="this"||e.op==="document"||e.op==="window")return e.op;if(typeof e.selector=="string"&&typeof e.op=="string")return`${e.op} ${e.selector}`}return String(e)}},"toJhxFromAttribute"),G=T(e=>typeof e=="string"?e:(Array.isArray(e)?e:[e]).map(t=>{if(typeof t=="string")return t;if(typeof t=="object"){let s=`${t.event||""}${t.filter?`[${t.filter}]`:""}`,r=[];return t.once===!0&&r.push("once"),t.changed===!0&&r.push("changed"),t.consume===!0&&r.push("consume"),t.delay&&r.push(`delay:${t.delay}`),t.from&&r.push(`from:${ne(t.from)}`),t.target&&r.push(`target:${q(t.target)}`),t.throttle&&r.push(`throttle:${t.throttle}`),t.queue&&r.push(`queue:${t.queue}`),s.concat(s?" ":"",r.join(" "))}return""}).filter(Boolean).join(", "),"toJhxTriggerAttribute");var ie=["get","post","put","patch","delete","route"],Y=T((e,o)=>{let t={};if(!e||typeof e!="object")return t;let s=ie.find(r=>!!e[r]);if(s)if(s==="route"){let r=e.method?.toLowerCase()||"get";t[`hx-${r}`]=String(e.route)}else t[`hx-${s}`]=String(e[s]);else e.method&&o.logger.warn("[jhx] The 'method' prop must be paired with a 'route' prop to generate a request attribute.");if(e.boost===!0&&(t["hx-boost"]="true"),e.confirm&&(t["hx-confirm"]=e.confirm),e.disable===!0&&(t["hx-disable"]="true"),e.disabledElt){let r=q(e.disabledElt);r&&(t["hx-disabled-elt"]=r)}if(e.disinherit&&(Array.isArray(e.disinherit)?t["hx-disinherit"]=e.disinherit.join(" "):t["hx-disinherit"]=e.disinherit),e.encoding&&(t["hx-encoding"]=e.encoding),e.ext){typeof e.ext=="string"&&(t["hx-ext"]=e.ext);let E=(Array.isArray(e.ext)?e.ext:[e.ext]).map(j=>typeof j=="object"?`${j?.name&&j.ignore===!0?"ignore:":""}${j?.name}`:j).filter(Boolean).join(",");E&&(t["hx-ext"]=E)}if(e.headers)if(typeof e.headers=="object")try{t["hx-headers"]=`${JSON.stringify(e.headers)}`}catch(r){throw o.logger.error("[jhx] Error while parsing the `hx-headers` object."),new C("[jhx] Error while parsing 'hx-request' object",{attribute:"hx-headers",cause:r,stack:r instanceof Error&&typeof r.stack=="string"?r.stack:void 0})}else if(typeof e.headers=="function"){let r=H(e.headers);if(r){let E=`((${r.params.join(",")}) => ${r.body})(${r.params.join(",")})`;t["hx-vals"]=`js:{...${E}}`}}else t["hx-headers"]=e.headers;if(e.history===!1&&(t["hx-history"]="false"),e.historyElt===!0&&(t["hx-history-elt"]="true"),e.indicator)if(typeof e.indicator=="object"){let r=e.indicator.inherit===!0?"inherit, ":"",E=e.indicator.closest===!0?"closest ":"";t["hx-indicator"]=`${r}${E}${e.indicator.selector}`}else t["hx-indicator"]=e.indicator;if(e.include){let r=q(e.include);r&&(t["hx-include"]=r)}if(e.inherit&&(Array.isArray(e.inherit)?t["hx-inherit"]=e.inherit.join(" "):t["hx-inherit"]=e.inherit),e.params&&(typeof e.params=="object"?e.params.include&&Array.isArray(e.params.include)?t["hx-params"]=`${e.params.include.join(",")}`:e.params.exclude&&Array.isArray(e.params.exclude)&&(t["hx-params"]=`not ${e.params.exclude.join(",")}`):t["hx-params"]=e.params),e.preserve===!0&&(t["hx-preserve"]="true"),e.prompt&&(t["hx-prompt"]=e.prompt),e.pushUrl&&(e.pushUrl===!0?t["hx-push-url"]="true":t["hx-push-url"]=e.pushUrl),(e.replaceUrl||e.replaceUrl===!1)&&(typeof e.replaceUrl=="boolean"?t["hx-replace-url"]=e.replaceUrl?"true":"false":t["hx-replace-url"]=e.replaceUrl),e.request)if(typeof e.request=="object")try{t["hx-request"]=`${JSON.stringify(e.request)}`}catch(r){throw new C("[jhx] Error while parsing 'hx-request' object",{attribute:"hx-request",cause:r,stack:r instanceof Error&&typeof r.stack=="string"?r.stack:void 0})}else if(typeof e.request=="function"){let r=H(e.request);if(r){let j=`(({ timeout, credentials, noHeaders }) => ({ timeout, credentials, noHeaders }))(${`((${r.params.join(",")}) => ${r.body})(${r.params.join(",")})`})`;t["hx-request"]=`js: ${j}`}}else t["hx-request"]=e.request;if(e.select&&(t["hx-select"]=e.select),e.selectOob)if(Array.isArray(e.selectOob))t["hx-select-oob"]=e.selectOob.map(r=>{if(typeof r=="string")return r;if(typeof r=="object"&&r.selector){let E=$(r.swap);return`${r.selector}${E?":"+E:""}`}return""}).filter(Boolean).join(",");else if(typeof e.selectOob=="object"){let r=$(e.selectOob.swap);t["hx-select-oob"]=`${e.selectOob.selector}${r?":"+r:""}`}else t["hx-select-oob"]=e.selectOob;if(e.swap){let r=$(e.swap);r&&(t["hx-swap"]=r)}if(e.swapOob)if(e.swapOob===!0)t["hx-swap-oob"]="true";else if(typeof e.swapOob=="object"){let r=$(e.swapOob.swap);r&&(t["hx-swap-oob"]=`${r}${e.swapOob.selector?":"+e.swapOob.selector:""}`)}else t["hx-swap-oob"]=e.swapOob;if(e.sync&&(typeof e.sync=="object"?e.sync.strategy&&e.sync.tag?t["hx-sync"]=`${e.sync.closest===!0?"closest ":""}${e.sync.tag}:${e.sync.strategy}`:e.sync.strategy&&(t["hx-sync"]=`this:${e.sync.strategy}`):t["hx-sync"]=e.sync),e.target){let r=q(e.target);r&&(t["hx-target"]=r)}if(e.trigger&&(t["hx-trigger"]=G(e.trigger)),e.validate===!0&&(t["hx-validate"]="true"),e.vars&&(o.logger.warn("[jhx] The `hx-vars` attribute has been deprecated because of XSS vulnerabilities. Recommended to use the `hx-vals` attribute."),t["hx-vars"]=e.vars),e.vals)if(typeof e.vals=="object")try{t["hx-vals"]=`${JSON.stringify(e.vals)}`}catch(r){throw new C("[jhx] Error while parsing 'hx-vals' object",{attribute:"hx-vals",cause:r,stack:r instanceof Error&&typeof r.stack=="string"?r.stack:void 0})}else if(typeof e.vals=="function"){let r=H(e.vals);if(r){let E=`((${r.params.join(",")}) => ${r.body})(${r.params.join(",")})`;t["hx-vals"]=`js:{...${E}}`}}else t["hx-vals"]=e.vals;return t},"convertJhxAttributes");var K=T(e=>{let o={};if(!e||typeof e!="object")return o;for(let t in J)if(Object.prototype.hasOwnProperty.call(e,t)){let s=J[t],r=e[t];if(!r)continue;let E=H(r);if(!E)continue;o[s]=`((${E.params.join(",")}) => ${E.body})(${E.params.join(",")})`}return o},"convertJhxEventAttributes");var ae={'"':"&quot;","<":"&lt;",">":"&gt;"},R=T(e=>String(e).replace(/["<>]/g,o=>ae[o]??o),"escapeValue");var Q=T((e,o=!0)=>Object.entries(e).map(([t,s])=>typeof s=="object"?`${t}="${JSON.stringify(s)}"`:`${t}="${typeof s=="string"&&o?R(s):s}"`).filter(Boolean).join(" "),"attributesToString");var Z={logger:console,stringify:!1,escape:!0};var _=T(e=>{let o={};for(let[t,s]of Object.entries(e))o[t]=typeof s=="string"?R(s):s;return o},"escapeAttributes");function ee(e,o){let t={...Z,...o??{}},s={...Y(e,t),...K(e),...W(e)};return t.stringify===!0?Q(s,!!t.escape):t.escape===!0?_(s):s}T(ee,"jhx");var he=T(e=>e.startsWith("hx-")||e in P.attr||e in P.eventAttr||e==="route"||e==="method","isJhxAttribute"),co=T(e=>{let{jhxConfig:o,as:t,children:s,...r}=e,E=t??"div",j={};for(let[O,te]of Object.entries(r))he(O)||(j[O]=te);let A={...ee(r,{...o,stringify:!1}),...j};return<E{...A}>{s}</E>},"JhxComponent");var uo=T((e,o)=>{for(let[t,s]of Object.entries(o))typeof s=="object"?e.setAttribute(t,JSON.stringify(s)):e.setAttribute(t,String(s))},"applyAttributes");export{co as JhxComponent,C as JhxErrorThrowable,uo as applyAttributes,Q as attributesToString,Z as defaultConfig,_ as escapeAttributes,P as htmx,ee as jhx};
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "jhx",
3
3
  "description": "HTMX helper with type-safe attribute mapping. Converts props into `hx-*` attributes for templating.",
4
- "version": "0.1.3",
4
+ "version": "0.1.5",
5
5
  "author": "nick-hio",
6
6
  "homepage": "https://github.com/nick-hio/jhx/tree/main/packages/jhx#readme",
7
7
  "repository": {
@@ -40,24 +40,22 @@
40
40
  }
41
41
  }
42
42
  },
43
- "dependencies": {
44
- "htmx.org": "^2.0.8"
45
- },
46
43
  "peerDependencies": {
44
+ "htmx.org": "2.0.8",
47
45
  "react": "^17.0.2 || ^18.0.0 || ^19.0.0",
48
46
  "react-dom": "^17.0.2 || ^18.0.0 || ^19.0.0"
49
47
  },
50
48
  "devDependencies": {
51
- "@types/bun": "^1.3.2",
52
- "@types/node": "^24.10.1",
53
- "@types/react": "^19.2.5",
49
+ "@types/bun": "^1.3.8",
50
+ "@types/node": "^24.10.9",
51
+ "@types/react": "^19.2.10",
54
52
  "@types/react-dom": "^19.2.3",
55
53
  "esbuild": "^0.25.12",
56
- "eslint": "^9.39.1",
57
- "prettier": "^3.6.2",
58
- "react": "^19.2.0",
59
- "react-dom": "^19.2.0",
60
- "rollup": "^4.53.2",
54
+ "eslint": "^9.39.2",
55
+ "prettier": "^3.8.1",
56
+ "react": "^19.2.4",
57
+ "react-dom": "^19.2.4",
58
+ "rollup": "^4.57.1",
61
59
  "typescript": "^5.9.3"
62
60
  }
63
61
  }