UNPKG

jelenjs

Version:

Core runtime library for JelenJS - an experimental UI framework with fine-grained reactivity

3 lines (2 loc) 6.06 kB
const e="__JELENJS_REACTIVE_STATE__",t="undefined"!=typeof globalThis?(globalThis[e]||(globalThis[e]={currentEffect:null,currentContext:null,microtaskPending:!1,globalEffectId:0}),globalThis[e]):"undefined"!=typeof window?(window[e]||(window[e]={currentEffect:null,currentContext:null,microtaskPending:!1,globalEffectId:0}),window[e]):{currentEffect:null,currentContext:null,microtaskPending:!1,globalEffectId:0};let n=t.currentEffect,o=t.currentContext;function r(e){return t.currentEffect,t.currentEffect=e,n=e,t.currentEffect}t.microtaskPending,t.globalEffectId;const s="__JELENJS_SIGNAL_REGISTRY__",l="undefined"!=typeof globalThis?(globalThis[s]||(globalThis[s]=new Set),globalThis[s]):"undefined"!=typeof window?(window[s]||(window[s]=new Set),window[s]):new Set,i=Symbol("signalGetter");function c(e){return"function"==typeof e&&(!0===e[i]||l.has(e))}function u(e){const s=()=>{if(s.disposed)return void s.id;if(s.id,s.cleanupFns&&s.cleanupFns.length>0){s.id,s.cleanupFns.length;for(let e=0;e<s.cleanupFns.length;e++)s.cleanupFns[e]();s.cleanupFns=[]}if(s.sources&&s.sources.length>0){s.id,s.sources.length;for(let e=0;e<s.sources.length;e++)s.sources[e].subscribers.delete(s);s.sources.length=0,s.sourceSlots.length=0}if(s.running)return void s.id;s.running=!0;const t=n;r(s),s.id;try{const t=e();"function"==typeof t&&(s.id,s.cleanupFns.push(t))}catch(e){}finally{r(t),s.running=!1,s.id}};return s.id=(t.globalEffectId++,t.globalEffectId,t.globalEffectId,t.globalEffectId),s.disposed=!1,s.running=!1,s.state=0,s.cleanupFns=[],s.sources=[],s.sourceSlots=[],s.updatedAt=null,s.parentContext=o,s.id,o&&o.effects&&(o.effects.add(s),s.id),s.dispose=()=>{if(s.disposed)s.id;else{if(s.id,s.disposed=!0,s.cleanupFns.length>0){s.id,s.cleanupFns.length;for(let e=0;e<s.cleanupFns.length;e++)s.cleanupFns[e]();s.cleanupFns=[]}if(s.sources&&s.sources.length>0){s.id,s.sources.length;for(let e=0;e<s.sources.length;e++)s.sources[e].subscribers.delete(s);s.sources.length=0,s.sourceSlots.length=0}s.parentContext&&s.parentContext.effects&&(s.parentContext.effects.delete(s),s.id)}},s.id,s(),s.dispose}function a(e){return!(null==e||(!Array.isArray(e)||2!==e.length||"function"!=typeof e[0]||"function"!=typeof e[1])&&!c(e))}function f(e,t=!1){let n;if("function"==typeof e)try{n=e()}catch(t){n=e}else if(Array.isArray(e)&&"function"==typeof e[0])try{n=e[0]()}catch(t){n=e}else n=e;return t&&"boolean"==typeof n?n?"active":"":n}const d=new Map;function p(e,t){if(null!=t)if(Array.isArray(t))for(const n of t)p(e,n);else if(t instanceof Node)e.appendChild(t);else{if(null!=(n=t)&&"string"!=typeof n&&"number"!=typeof n&&"boolean"!=typeof n&&(a(n)||"function"==typeof n&&(c(n),1))){const n=document.createElement("span");return n.style.display="contents",e.appendChild(n),void u((()=>{let e;if(e="function"==typeof t?t():Array.isArray(t)&&"function"==typeof t[0]?t[0]():a(t)?f(t):t,n.innerHTML="",e instanceof Node)n.appendChild(e);else if(e instanceof Element)n.appendChild(e);else if(Array.isArray(e))for(const t of e)p(n,t);else!1===e||null==e||null!=e&&(n.textContent=String(e))}))}var n;e.appendChild(document.createTextNode(String(t)))}}function g(e,t,n){"class"===t||"className"===t?e.className=String(n):"style"===t&&"object"==typeof n?Object.assign(e.style,n):"disabled"===t||"checked"===t||"required"===t?n?e.setAttribute(t,""):e.removeAttribute(t):t.startsWith("data-")?e.setAttribute(t,String(n)):(e[t]=n,"object"!=typeof n&&void 0!==n&&e.setAttribute(t,String(n)))}const y="__JELENJS_COMPONENT_STATE__",h="undefined"!=typeof globalThis?(globalThis[y]||(globalThis[y]={currentComponent:null,mountCallbacks:new WeakMap,unmountCallbacks:new WeakMap}),globalThis[y]):"undefined"!=typeof window?(window[y]||(window[y]={currentComponent:null,mountCallbacks:new WeakMap,unmountCallbacks:new WeakMap}),window[y]):{currentComponent:null,mountCallbacks:new WeakMap,unmountCallbacks:new WeakMap};function b(e){h.currentComponent=e}function m(e){if("function"==typeof e)try{return e()}catch(t){return e}return a(e)?f(e):e}function w(e){return/\?\s*.*\s*:/.test(e)||/&&/.test(e)||/\|\|/.test(e)}function C(e){if("function"==typeof e)return e;if("string"==typeof e&&w(e))try{return new Function("count",`return ${e}`)}catch(t){return()=>e}return()=>e}function E(e){return null==e?[]:Array.isArray(e)?e.flatMap(E):"object"==typeof e&&null!==e&&("operator"in e&&"&&"===e.operator||"test"in e&&"consequent"in e&&"alternate"in e)?[()=>"operator"in e&&"&&"===e.operator?m(e.left)?e.right:null:"test"in e?m(e.test)?e.consequent:e.alternate:null]:"string"==typeof e&&w(e)?[C(e)]:("boolean"==typeof e||"function"==typeof e||a(e),[e])}function T(e,t={}){const{children:n,...o}=t;if("function"==typeof e){const t=e;b(t);try{const r=e({...o,children:n});return setTimeout((()=>{!function(e){const t=h.mountCallbacks.get(e);t&&(t.forEach((e=>{try{e()}catch(e){}})),h.mountCallbacks.delete(e))}(t)}),0),r}finally{b(null)}}return function(e,t,...n){const o=document.createElement(e);if(t)for(const[e,n]of Object.entries(t))if("style"===e&&"object"==typeof n)Object.assign(o.style,n);else if(e.startsWith("on")&&"function"==typeof n){const t=e.slice(2).toLowerCase();o.addEventListener(t,n)}else if(a(n)){const t=f(n);g(o,e,t),d.has(o)||d.set(o,new Map),d.get(o).set(e,n),u((()=>{const t=f(n);g(o,e,t)}))}else"class"===e||"className"===e?o.className=String(n):e.startsWith("data-")?o.setAttribute(e,String(n)):o[e]=n;for(const e of n)p(o,e);return o}(e,o,...void 0===n?[]:E(n))}const S=T,A=e=>{if(!e.children)return document.createDocumentFragment();const t=document.createDocumentFragment(),n=E(e.children);for(const e of n)if(e instanceof Node||e instanceof Element)t.appendChild(e);else if("function"==typeof e){const n=document.createElement("span");n.style.display="contents",t.appendChild(n),u((()=>{try{const t=e();n.innerHTML="",t instanceof Node?n.appendChild(t):null!=t&&(n.textContent=String(t))}catch(e){}}))}else null!=e&&t.appendChild(document.createTextNode(String(e)));return t};export{A as Fragment,T as jsx,S as jsxs}; //# sourceMappingURL=jsx-runtime.min.js.map