@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 • 4.69 kB
JavaScript
;Object.defineProperty(exports, "__esModule", {value: true}); function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }var _chunkJAV2JQW5cjs = require('./chunk-JAV2JQW5.cjs');var T="event",H=e=>e.type==="action"?t=>e.member(t):t=>console.log(e.member),L=(e,t)=>`${e}:${t}`,A=e=>{let t=e.split(_chunkJAV2JQW5cjs.b.options.attributes.seperators.handler),n={target:"element",eventName:t[0]};return t[0]&&t.length>1&&["document","body","head","window"].includes(t[0])&&(n.target=t[0],n.eventName=t[1]),n},x=e=>{switch(e.target){case"document":return document;case"body":return document.body;case"head":return document.head;case"window":return window;default:return document}},N=(e,t,n)=>{for(let o of e){let[r,i]=o,s=A(r);if(s.eventName)for(let a of i){let l=_chunkJAV2JQW5cjs.l.call(void 0, a);if(!l)continue;let f=L(r,a);n.has(f)||n.set(f,new Map);let c=n.get(f);if(c)if(s.target==="element"){let p=document.querySelectorAll(_chunkJAV2JQW5cjs.c.call(void 0, T,r,a));for(let m of p){if(c.has(m))continue;let b=H(l);m.addEventListener(s.eventName,b,{signal:_optionalChain([t, 'optionalAccess', _ => _.signal])}),c.set(m,b)}}else{let p=x(s);if(c.has(p))continue;let m=H(l);p.addEventListener(s.eventName,m,{signal:_optionalChain([t, 'optionalAccess', _2 => _2.signal])}),c.set(p,m)}}}},k={namespace:T,initialise:(e,t)=>{let n=new AbortController,o=new Map;return N(e,n,o),()=>{n.abort(),o.clear()}}},C= exports.events =k;var _solidjs = require('solid-js');var M="dom",S=(e,t)=>{let n=_chunkJAV2JQW5cjs.g.call(void 0, t);for(let o of e)o instanceof HTMLElement&&(o.innerText=n)},W=(e,t)=>{let n=_chunkJAV2JQW5cjs.g.call(void 0, t);for(let o of e)o instanceof HTMLElement&&(o.innerHTML=n)},D=(e,t)=>{let n=_chunkJAV2JQW5cjs.g.call(void 0, t);for(let o of e)(o instanceof HTMLInputElement||o instanceof HTMLTextAreaElement||o instanceof HTMLSelectElement)&&(o.value=n)},q=(e,t)=>{for(let n of e)if(n instanceof HTMLElement&&t===!0){setTimeout(()=>n.focus(),0);break}},B=(e,t)=>{for(let n of e)n instanceof HTMLElement&&t===!0&&n.blur()},I=(e,t)=>{for(let n of e)if(n instanceof HTMLElement&&t===!0){n.scrollIntoView({behavior:"smooth"});break}},R=e=>{switch(e){case"text":return S;case"html":return W;case"value":return D;case"focus":return q;case"blur":return B;case"scrollto":return I;default:return S}},F={namespace:M,initialise:e=>{let t;return _solidjs.createRoot.call(void 0, n=>{t=n;for(let o of e){let[r,i]=o;for(let s of i){let a=_chunkJAV2JQW5cjs.l.call(void 0, s);if(!a)continue;let l=document.querySelectorAll(_chunkJAV2JQW5cjs.c.call(void 0, M,r,s)),f=R(r);_solidjs.createEffect.call(void 0, async()=>{try{let c=await _chunkJAV2JQW5cjs.m.call(void 0, a);f(l,c)}catch(c){console.error(c)}})}}}),()=>t()}},K= exports.dom =F;var w="trap",[G,h]=_solidjs.createSignal.call(void 0, []),J=e=>{let t=[],n=document.body.children;for(let o=0;o<n.length;o++){let r=n[o];r instanceof HTMLElement&&r!==e&&!r.contains(e)&&!e.contains(r)&&t.push(r)}return t},P=(e,t,n)=>{if(t){let o=J(e),r=document.activeElement;h(i=>[...i,{element:e,previousActiveElement:r,siblingElements:o}]);for(let i of o)i.setAttribute("inert","");e.removeAttribute("inert"),e.focus(),document.body.style.overflow="hidden";return}h(o=>{let r=o.find(s=>s.element===e),i=o.filter(s=>s.element!==e);if(r){for(let s of r.siblingElements)s.removeAttribute("inert");i.length===0&&(_optionalChain([r, 'access', _3 => _3.previousActiveElement, 'optionalAccess', _4 => _4.focus, 'call', _5 => _5()]),document.body.style.overflow="")}return i}),n.trapBothWays&&e.setAttribute("inert","")},Q=e=>({trapBothWays:e.includes("both")}),U={namespace:w,initialise:e=>{let t;return _solidjs.createRoot.call(void 0, n=>{t=n;for(let[o,r]of e)for(let i of r){let s=_chunkJAV2JQW5cjs.l.call(void 0, i);if(!s)continue;let a=Q(o),l=document.querySelectorAll(_chunkJAV2JQW5cjs.c.call(void 0, w,o,i));_solidjs.createEffect.call(void 0, async()=>{let f=await _chunkJAV2JQW5cjs.m.call(void 0, s);for(let c of l)c instanceof HTMLElement&&P(c,!!f,a)})}}),()=>{for(let n of G())for(let o of n.siblingElements)o.removeAttribute("inert");document.body.style.overflow="",t()}}},X= exports.trap =U;exports.dom = K; exports.events = C; exports.trap = X;
//# sourceMappingURL=handlers.cjs.map