UNPKG

fluxel

Version:

An ultra-lightweight, high-performance library for efficient DOM building and dynamic web UIs

13 lines (12 loc) 11.5 kB
/** * fluxel-jsx-runtime v0.6.5 * * Copyright (c) 2026 mtripg6666tdr * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * * @see https://github.com/mtripg6666tdr/fluxel * @license MIT */ "use strict";var FluxelJSXRuntime=(()=>{var P=Object.defineProperty;var Q=Object.getOwnPropertyDescriptor;var X=Object.getOwnPropertyNames;var Y=Object.prototype.hasOwnProperty;var Z=(e,t)=>{for(var n in t)P(e,n,{get:t[n],enumerable:!0})},k=(e,t,n,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of X(t))!Y.call(e,o)&&o!==n&&P(e,o,{get:()=>t[o],enumerable:!(r=Q(t,o))||r.enumerable});return e};var ee=e=>k(P({},"__esModule",{value:!0}),e);var ue={};Z(ue,{Fragment:()=>K,jsx:()=>fe,jsxDEV:()=>fe,jsxs:()=>fe});var C=new WeakMap;function L(e){var t;(t=C.get(e))===null||t===void 0||t.forEach(n=>n()),C.delete(e),e.childNodes.forEach(n=>L(n))}function H(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}var v=class _{get value(){return this._accessor.get()}set value(t){this._accessor.set(t)}derive(t){let n={get:()=>t(this.value),set:r=>{throw new TypeError("Cannot set value of derived dependency")}};return new _(n,this.addDependency)}constructor(t,n){H(this,"_accessor",void 0),H(this,"addDependency",void 0),this._accessor=t,this.addDependency=n}};var te=["object","a","abbr","address","area","article","aside","audio","b","base","bdi","bdo","blockquote","body","br","button","canvas","caption","cite","code","col","colgroup","data","datalist","dd","del","details","dfn","dialog","div","dl","dt","em","embed","fieldset","figcaption","figure","footer","form","h1","h2","h3","h4","h5","h6","head","header","hgroup","hr","html","i","iframe","img","input","ins","kbd","label","legend","li","link","main","map","mark","menu","meta","meter","nav","noscript","ol","optgroup","option","output","p","picture","pre","progress","q","rp","rt","ruby","s","samp","script","search","section","select","slot","small","source","span","strong","style","sub","summary","sup","table","tbody","td","template","textarea","tfoot","th","thead","time","title","tr","track","u","ul","var","video","wbr"],B=te;function F(){return typeof window<"u"&&"fluxelH"in window?window.fluxelH:null}function b(e,t){if(typeof e!="string")throw new TypeError("Expected string for tagName, got ".concat(typeof e));let n=F(),r=n?n.getElementByEid("".concat(n.count++)):document.createElement(e);return D(r,t)}function D(e,t){let n=!!F(),r=null,o=null,l=null,p=!1,a=null;if(t)if(typeof t=="string"||Array.isArray(t)||t instanceof Node||t instanceof v){o=t;let s=O(t);l=s.children,p=s.variableChildrenLength,a=s.reactiveIndex}else{if(r=Object.assign(Object.create(null),t),"textContent"in r)throw new TypeError("textContent is not allowed");if("children"in r&&r.children!==null&&r.children!==void 0){o=r.children;let s=O(r.children);l=s.children,p=s.variableChildrenLength,a=s.reactiveIndex,delete r.children}}r=r||{},l=l||null;let f=new Map;for(let s in r)if(s.startsWith("on")&&r[s]){let i=s.slice(2).toLowerCase(),d=f.get(i)||[];f.set(i,d);let c=r[s];if(Array.isArray(c))c.forEach(h=>{if(typeof h=="function")d.push(h);else throw new TypeError("Expected function for event handler ".concat(s,", got ").concat(typeof h))});else if(typeof c=="function")d.push(c);else throw new TypeError("Expected function for event handler ".concat(s,", got ").concat(typeof c));delete r[s]}let u=Object.assign(Object.create(null),"style"in r?r.style:null);if(u&&typeof u=="object"&&!Array.isArray(u)){for(let s in u)if(u[s]instanceof v){let i=u[s];i.addDependency(e,()=>{s.startsWith("--")?e.style.setProperty(s,i.value):e.style[s]=i.value}),u[s]=i.value}}delete r.style;let g=new Set,x=s=>{if(!s)return;let i=s.trim();i&&g.add(i)};if(e.classList.forEach(s=>x(s)),r.classList){let s=c=>{if(typeof c=="string")x(c);else if("forEach"in c)c.forEach(h=>x(h));else if(c instanceof v){let h=c;h.addDependency(e,()=>{e.className="",g.clear(),s(h.value),g.forEach(m=>e.classList.add(m))}),s(h.value)}else throw new TypeError("Expected string or iterable for 'classList', got ".concat(typeof r.classList))},i=r.classList,d=Array.isArray(i)&&i.some(c=>c instanceof v)?new v({get:()=>i.map(c=>c instanceof v?c.value:c),set:()=>{throw new TypeError("Cannot set value of classList directly")}},(c,h)=>{i.forEach(m=>m instanceof v&&m.addDependency(c,h))}):r.classList;s(d),delete r.classList}"className"in r&&delete r.className;let w=r.dataset||null;if(w&&typeof w=="object"&&!Array.isArray(w)){for(let s in w)if(w[s]instanceof v){let i=w[s];i.addDependency(e,()=>{e.dataset[s]=i.value}),w[s]=i.value}}delete r.dataset;for(let s in r)if(r[s]instanceof v){let i=r[s];i.addDependency(e,()=>{e[s]=i.value}),n||(e[s]=i.value),delete r[s]}if(n||(Object.assign(e,r),e.style&&u&&(Object.assign(e.style,u),Object.keys(u).forEach(s=>{s.startsWith("--")&&e.style.setProperty(s,u[s])})),e.dataset&&w&&Object.assign(e.dataset,w),g.size>0&&g.forEach(s=>e.classList.add(s))),p&&o&&o instanceof v)o.addDependency(e,()=>{let s=se(e.childNodes),i=O(o).children,d=W(s),c=W(i);if(s.length===i.length&&s.every((y,E)=>y.isSameNode(i[E])))return;let h=s.reduce((y,E,R)=>{var N;let $=(N=c.get(E))!==null&&N!==void 0?N:-1;if($<0)return y;let M=new Set([R]),z=R;for(let A=$+1;A<i.length;A++){var S;let I=(S=d.get(i[A]))!==null&&S!==void 0?S:-1;I<z||(M.add(I),z=I)}return M.size>y.size?M:y},new Set),m=new Set;if(h.size!==s.length){for(let y=s.length-1;y>=0;y--)if(!h.has(y)){let E=s[y];e.removeChild(E),m.add(E)}}e.childNodes.length!==i.length&&(i.forEach((y,E)=>{m.delete(y),e.childNodes[E]?e.childNodes[E]!==y&&e.insertBefore(y,e.childNodes[E]):e.appendChild(y)}),m.forEach(y=>L(y)))});else if(a&&a.length>0&&o)for(let s of a){let i=o instanceof v?o:o[s];i instanceof v&&(i.addDependency(e,()=>{let d=O(i.value).children[0],c=e.childNodes[s];c!==d&&(e.replaceChild(d,c),L(c))}),l[s]=i.value)}return l&&(n?l.forEach((s,i)=>{s instanceof Text&&(e.childNodes[i]&&e.childNodes[i]instanceof Text?e.replaceChild(s,e.childNodes[i]):e.insertBefore(s,e.childNodes[i]))}):e.append(...l)),f.forEach((s,i)=>{s.forEach(d=>{e.addEventListener(i,d)})}),e}function O(e){let t=!1,n=[],r=(o,l=0,p=-1)=>{if(l>1)throw new TypeError("Children cannot be nested more than one level deep");if(typeof o=="string")return[document.createTextNode(o)];if(Array.isArray(o)){o=o.flat(1/0);let a=o.length;return o.flatMap((u,g)=>r(u,l+(a===1?0:1),g))}else{if(o instanceof Node)return[o];if(o instanceof v){let a=o.value;if(Array.isArray(a))return l===0&&(t=!0),a.flat(1/0).flatMap((f,u)=>r(f,l+1,u));if(a instanceof Node)return l===0&&(t=!0),n.push(p),[a];{let f=document.createTextNode(a);return o.addDependency(f,()=>{f.textContent=String(o.value)}),[f]}}else return[]}};return{children:r(e),variableChildrenLength:t,reactiveIndex:n}}b.fragment=function(e,t){let n=O(e),r=n.children,o=n.variableChildrenLength,l=n.reactiveIndex;if(o&&e instanceof v)return e.derive(p=>{let a=O(p).children;return a.forEach(f=>D(f,t)),a});{let p=r;if(p.forEach(a=>{a instanceof HTMLElement&&D(a,t)}),l.length>0)for(let a of l)p[a]=e[a].derive(f=>D(f,t));return p}};function ne(){let e=document.querySelector("style[data-fluxel]");if(e)return e;let t=document.createElement("style");return t.dataset.fluxel="true",document.head.appendChild(t),t}b.forwardStyle=function(e){F()||b.forwardStyleCache.includes(e)||(b.forwardStyleCache.push(e),typeof window<"u"&&(ne().textContent+=e))};b.forwardStyleCache=[];function re(){return"".concat(Date.now().toString(36)).concat(Math.random().toString(36).substring(2))}function se(e){if(typeof Array.from=="function")return Array.from(e);let t=[];for(let n=0;n<e.length;n++)t.push(e[n]);return t}function W(e){let t=new Map;return e.forEach((n,r)=>{t.set(n,r)}),t}b.useUniqueString=function(e){let t=re();return e(t)};b.createComponent=function(e){return(t={})=>e(t)};b.createElement=b;var q=b;B.forEach(e=>{q[e]=t=>b(e,t)});var T=q;function ie(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function oe(e){for(var t=1;t<arguments.length;t++){var n=arguments[t]!=null?arguments[t]:{},r=Object.keys(n);typeof Object.getOwnPropertySymbols=="function"&&(r=r.concat(Object.getOwnPropertySymbols(n).filter(function(o){return Object.getOwnPropertyDescriptor(n,o).enumerable}))),r.forEach(function(o){ie(e,o,n[o])})}return e}function ae(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter(function(o){return Object.getOwnPropertyDescriptor(e,o).enumerable})),n.push.apply(n,r)}return n}function le(e,t){return t=t!=null?t:{},Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(t)):ae(Object(t)).forEach(function(n){Object.defineProperty(e,n,Object.getOwnPropertyDescriptor(t,n))}),e}var j=T,ce=["render","use","useWithMemo","listenTarget"];j.reactive=function(e,t){let n=Object.create(null),r=le(oe({},e),{render:(l,p=!1)=>{if(!p&&l&&r.listenTarget.dispatchEvent(new CustomEvent(l,{detail:{newValue:r[l]}})),l){var a;(a=n[l])===null||a===void 0||a.listeners.forEach(f=>f.call(null))}else for(let f in n)n[f].listeners.forEach(u=>u.call(null))},use:(l,p)=>{let a=-1,f=-1,u=[],g=new Map,x=new Map,w=(i,d,c=!1)=>{if(c){let h=JSON.stringify(d);if(x.has(h)){let y=x.get(h);return g.set(h,y),y}let m=i();return g.set(h,m),m}if(u[a]){if(u[a].deps.every((m,y)=>m===d[y]))return u[a++].memoValue;u[a].deps=d;let h=u[a].memoValue=i();return a++,h}else return u.push({deps:d,memoValue:i()}),u[a++].memoValue},s=p?i=>{a===-1&&f!==-1&&(f=a),a=0,g=new Map;let d=p(i,w);if(f!==-1&&f!==a)throw new TypeError("Memoization count mismatch");return x=g,d}:void 0;if(Array.isArray(l)){let i=l.map(d=>[d,r.use(d)]);return new v({get:()=>Object.fromEntries(i.map(d=>[d[0],d[1].value])),set:d=>{throw new TypeError("Invalid")}},(d,c)=>{let h=U(c);i.forEach(m=>m[1].addDependency(d,h))}).derive(s)}else{let i;return n[l]?i=n[l].dep:r[l]instanceof v?i=r[l]:(i=new v({get:()=>r[l],set:d=>{r[l]=d}},function(c,h){if(!n[l].listeners.includes(h)){n[l].listeners.push(h);let m=()=>{n[l].listeners=n[l].listeners.filter(y=>y!==h)};C.has(c)?C.get(c).add(m):C.set(c,new Set([m]))}}),n[l]={dep:i,listeners:[]}),s?i.derive(s):i}},useWithMemo:l=>{let p=null,a=r.use(l,(f,u)=>(p=u,f));return a.value,[a,p]},listenTarget:new EventTarget}),o=new Proxy(r,{set(l,p,a){if(ce.includes(p))throw new TypeError("Cannot set the specified property: ".concat(String(p)));let f=l[p];return f===a||(l[p]=a,l.listenTarget.dispatchEvent(new CustomEvent(p,{detail:{oldValue:f,newValue:a}})),l.render(p)),!0}});return t(o)};j.schedule=function(e){typeof window<"u"&&setTimeout(e,0)};j.mergeDependencies=function(...e){return new v({get:()=>e.map(t=>t.value),set:t=>{throw new TypeError("Invalid operation")}},(t,n)=>{let r=U(n);e.forEach(o=>o.addDependency(t,r))})};function U(e){let t=!1;return()=>{t||(t=!0,window.setTimeout(()=>{t=!1,e()},0))}}var J=j;var V=J;V.createStatefulComponent=function(e,t){return(n={})=>V.reactive(typeof t=="function"?t(n):t||{},r=>e(n,r))};var G=V;var de=T.createComponent(e=>{let t=Object.assign({},e),n=t.children;return delete t.children,T.fragment(n,t)}),K=de;function fe(e,t,n){if(t!=null&&t.className){var r,o;(o=(r=t).classList)!==null&&o!==void 0||(r.classList=[]),t.classList.push(t.className.split(" ").filter(Boolean)),delete t.className}return typeof e=="string"?G.createElement(e,t):e(t)}return ee(ue);})();