UNPKG

@lucidclient/elements

Version:

A lightweight, reactive UI library that bridges HTML and JavaScript through attributes, powered by SolidJS. Adds reactive state and dynamic behaviors to markup while maintaining simplicity.

2 lines 3.69 kB
var w={prefix:"[Elements]",defaults:{debug:!1,attributes:{prefix:"data-",selectors:{store:"store",ref:"ref",state:"state--",bind:"bind--",effect:"effect",handler:"handler--",loop:"loop"},seperators:{scope:":",handler:"."},denote:{action:"@",state:"$",index:":index:",index1:":indexOne:"}},specifier:""}},u=w;var A={options:{debug:u.defaults.debug,attributes:u.defaults.attributes},started:!1,handlers:new Map,stores:new Map,storeModules:new Map,syncedElements:new Map},i=A;var E=(e,r,t)=>{let n=`${i.options.attributes.prefix}${i.options.attributes.selectors.handler}${e}`,a=r===""?"":`\\.${r.replace(/\./g,"\\.")}`;return`[${n}${a}="${t}"]`},j=E;var V=(e,r,t)=>{let n=[],a=p=>r.length===0?!0:r.some(d=>p.name.startsWith(d));function f(p,d){if(d!==!0)for(let l of p.attributes)a(l)&&n.push(l);for(let l of p.children)f(l)}return f(e,t),n},C=V;var I=(e,r)=>!e||!r?void 0:r.split(".").reduce((n,a)=>{let f=a.match(/([^\[\]]+)|\[(\d+)\]/g);return f&&n.push(...f.map(p=>p.replace(/[\[\]]/g,""))),n},[]).slice(1).reduce((n,a)=>{if(n!=null&&typeof n=="object")return n[a]},e),m=I;var N=e=>typeof e=="string"?"string":e===null?"null":e===void 0?"undefined":typeof e=="object"?Array.isArray(e)?"array":"object":typeof e=="boolean"?"boolean":typeof e=="number"?"number":"unknown",b=N;var R=e=>{try{return typeof e=="string"?e:e===null?"null":e===void 0?"undefined":typeof e=="object"?JSON.stringify(e):String(e)}catch{return String(e)}},O=R;var H=e=>{if(!e)return null;if(e==="true")return!0;if(e==="false")return!1;if(e==="null")return null;if(e!=="undefined"){if(!Number.isNaN(Number(e)))return Number(e);if(e.trim().match(/^[{\[]/))try{return JSON.parse(e)}catch{return e}return e}},P=H;var T=e=>`${i.options.attributes.prefix}${e}`,B=T;var K=(e,r)=>`${e}${i.options.attributes.seperators.scope}${r}`,g=K;var J=(e,r)=>r.startsWith(`${e}${i.options.attributes.seperators.scope}`),S=J;var W=e=>e.split(i.options.attributes.seperators.scope)?.[1]??e,h=W;var D=e=>e.split(i.options.attributes.seperators.scope),k=D;var q=e=>e.includes(i.options.attributes.seperators.scope),$=q;var z={scopeValue:g,valueIsScoped:S,removeScope:h,splitValue:k,valueHasScope:$},M=z;var F=e=>{let[r,t]=M.splitValue(e);if(!r||!t)return null;if(t.includes(u.defaults.attributes.denote.action))return{type:"action",scope:r,key:t.replace(u.defaults.attributes.denote.action,"")};if(t.includes(u.defaults.attributes.denote.state)){let n=t.replace(u.defaults.attributes.denote.state,"");return{type:"state",scope:r,key:x(n)}}return{type:"basic",scope:r,key:t}},y=F;var G=(e,r)=>{let t=y(e);if(t===null)return null;let n=a=>{if(a[0].key===t.scope){if(t.type==="action"){let f=a[0].actions[t.key];return f===void 0?(c.warn(`Cannot find an action with the key of "${t.key}" on store "${t.scope}".`),null):{type:t.type,member:f,key:e}}if(t.type==="state"){let f=a[0].state[t.key];return f===void 0?(c.warn(`Cannot find state with the key of "${t.key}" on store "${t.scope}".`),null):{type:t.type,member:f,key:e}}}return null};if(r)return n(r);for(let a of i.stores.values()){let f=n(a);if(f!==null)return f}return null},L=G;var Q=async(e,r)=>{if(e.type==="action"){let a=e.member();return await Promise.resolve(a)}let t=e.member[0]();if(r)return t;let n=b(t);return n==="object"||n==="array"?m(t,e.key):t},U=Q;var X=e=>{let r=e.indexOf("."),t=e.indexOf("[");return r===-1&&t===-1?e:t===-1||r!==-1&&r<t?e.split(".")[0]??e:e.split("[")[0]??e},x=X;var Y=(e,r)=>i.options.debug||r?console.debug(`${u.prefix} ${e}`):void 0,Z=e=>console.warn(`${u.prefix} ${e}`),c={debug:Y,warn:Z};export{u as a,i as b,j as c,C as d,m as e,b as f,O as g,P as h,B as i,M as j,y as k,L as l,U as m,x as n,c as o}; //# sourceMappingURL=chunk-OSNUUW4P.js.map