UNPKG

flexium

Version:

A lightweight, signals-based UI framework with cross-platform renderers

2 lines 10.4 kB
import {a,e,g,c,b as b$2,d as d$1}from'./chunk-H3V4FX7A.mjs';import {b as b$1,h,d,e as e$1,i,f}from'./chunk-Z7JNAX53.mjs';var L=a(null);function te(i){let t=b$1(0),o={registerPromise:n=>{f(()=>{t.value++,n.then(()=>{t.value--;},()=>{t.value--;});});}};return ()=>t.value>0?i.fallback:e(L.Provider,{value:o},i.children)}var G=new Set,O=new Set(["focus","blur","mouseenter","mouseleave","load","unload","scroll"]),R=new WeakMap;function $(i){let t=i.target,e=i.type.toLowerCase(),o=!O.has(e);for(;t&&t!==document;){let n=R.get(t);if(n&&n.has(e)){let r=n.get(e);if(r&&(r(i),i.cancelBubble))break}if(!o)break;t=t.parentNode;}}function q(i){if(!G.has(i)){let t=O.has(i);document.addEventListener(i,$,{capture:t}),G.add(i);}}var _={on(i,t,e){let o=t.toLowerCase(),n=R.get(i);n||(n=new Map,R.set(i,n)),n.set(o,e),q(o);},off(i,t){let e=t.toLowerCase(),o=R.get(i);o&&o.delete(e);}};var K={Row:"div",Column:"div",Stack:"div",Text:"span",Button:"button",Input:"input",View:"div",Container:"div"},v={onPress:"click",onHover:"mouseenter",onChange:"input",onFocus:"focus",onBlur:"blur"},X=new Set(["children","key","ref","className","style","width","height","padding","paddingTop","paddingRight","paddingBottom","paddingLeft","margin","marginTop","marginRight","marginBottom","marginLeft","gap","flex","flexDirection","flexWrap","justifyContent","alignItems","alignSelf","align","justify","bg","color","borderRadius","borderWidth","borderColor","opacity","fontSize","fontWeight","fontFamily","lineHeight","textAlign"]);function m(i){return typeof i=="number"?`${i}px`:i}function J(i,t,e){let o=i.style,n=t.style,r=e.style;if(n!==r){if(n&&typeof n=="object")for(let f in n)(!r||!(f in r))&&o[f]!==""&&(o[f]="");if(r&&typeof r=="object")for(let f in r){let a=r[f];(!n||n[f]!==a)&&(o[f]=a);}}let d=(f,a)=>{a===void 0?o[f]!==""&&(o[f]=""):o[f]!==a&&(o[f]=a);};t.width!==e.width&&d("width",e.width!==void 0?m(e.width):void 0),t.height!==e.height&&d("height",e.height!==void 0?m(e.height):void 0);let l=i.getAttribute("data-flexium-type");(e.flexDirection||e.justifyContent||e.alignItems||e.flexWrap||e.gap!==void 0||e.justify||e.align||l==="Row"||l==="Column"||l==="Stack")&&(o.display!=="flex"&&(o.display="flex"),l==="Row"&&o.flexDirection!=="row"&&(o.flexDirection="row"),l==="Column"&&o.flexDirection!=="column"&&(o.flexDirection="column")),t.flexDirection!==e.flexDirection&&d("flexDirection",e.flexDirection),t.justifyContent!==e.justifyContent&&d("justifyContent",e.justifyContent),t.alignItems!==e.alignItems&&d("alignItems",e.alignItems),t.alignSelf!==e.alignSelf&&d("alignSelf",e.alignSelf),t.flexWrap!==e.flexWrap&&d("flexWrap",e.flexWrap),t.flex!==e.flex&&d("flex",e.flex!==void 0?String(e.flex):void 0),t.gap!==e.gap&&d("gap",e.gap!==void 0?m(e.gap):void 0),t.justify!==e.justify&&d("justifyContent",e.justify),t.align!==e.align&&d("alignItems",e.align),t.bg!==e.bg&&d("backgroundColor",e.bg),t.color!==e.color&&d("color",e.color),t.borderRadius!==e.borderRadius&&d("borderRadius",e.borderRadius!==void 0?m(e.borderRadius):void 0),t.borderWidth!==e.borderWidth&&(d("borderWidth",e.borderWidth!==void 0?m(e.borderWidth):void 0),e.borderWidth!==void 0&&o.borderStyle!=="solid"&&(o.borderStyle="solid")),t.borderColor!==e.borderColor&&d("borderColor",e.borderColor),t.opacity!==e.opacity&&d("opacity",e.opacity!==void 0?String(e.opacity):void 0),t.fontSize!==e.fontSize&&d("fontSize",e.fontSize!==void 0?m(e.fontSize):void 0),t.fontWeight!==e.fontWeight&&d("fontWeight",e.fontWeight!==void 0?String(e.fontWeight):void 0),t.fontFamily!==e.fontFamily&&d("fontFamily",e.fontFamily),t.lineHeight!==e.lineHeight&&d("lineHeight",e.lineHeight!==void 0?String(e.lineHeight):void 0),t.textAlign!==e.textAlign&&d("textAlign",e.textAlign),t.padding!==e.padding&&d("padding",e.padding!==void 0?m(e.padding):void 0),t.paddingTop!==e.paddingTop&&d("paddingTop",e.paddingTop!==void 0?m(e.paddingTop):void 0),t.paddingRight!==e.paddingRight&&d("paddingRight",e.paddingRight!==void 0?m(e.paddingRight):void 0),t.paddingBottom!==e.paddingBottom&&d("paddingBottom",e.paddingBottom!==void 0?m(e.paddingBottom):void 0),t.paddingLeft!==e.paddingLeft&&d("paddingLeft",e.paddingLeft!==void 0?m(e.paddingLeft):void 0),t.margin!==e.margin&&d("margin",e.margin!==void 0?m(e.margin):void 0),t.marginTop!==e.marginTop&&d("marginTop",e.marginTop!==void 0?m(e.marginTop):void 0),t.marginRight!==e.marginRight&&d("marginRight",e.marginRight!==void 0?m(e.marginRight):void 0),t.marginBottom!==e.marginBottom&&d("marginBottom",e.marginBottom!==void 0?m(e.marginBottom):void 0),t.marginLeft!==e.marginLeft&&d("marginLeft",e.marginLeft!==void 0?m(e.marginLeft):void 0);}function U(i){return typeof i=="string"?i:Array.isArray(i)?i.map(U).filter(Boolean).join(" "):typeof i=="object"&&i!==null?Object.keys(i).filter(t=>i[t]).join(" "):""}var B=class{createNode(t,e){let o=K[t]||t,n=document.createElement(o);return K[t]&&n.setAttribute("data-flexium-type",t),this.updateNode(n,{},e),n}updateNode(t,e,o){o.className!==e.className&&(t.className=U(o.className)),J(t,e,o);for(let n in e)if(!(n in o))if(n.startsWith("on")){let r=v[n]||n.slice(2).toLowerCase();this.removeEventListener(t,r,e[n]);}else X.has(n)||t.removeAttribute(n);for(let n in o){let r=o[n],d=e[n];if(r!==d)if(n.startsWith("on")){let l=v[n]||n.slice(2).toLowerCase();d&&this.removeEventListener(t,l,d),r&&this.addEventListener(t,l,r);}else X.has(n)||(r==null||r===false?t.removeAttribute(n):r===true?t.setAttribute(n,""):t.setAttribute(n,String(r)));}}appendChild(t,e){t.appendChild(e);}insertBefore(t,e,o){t.insertBefore(e,o);}nextSibling(t){return t.nextSibling}removeChild(t,e){t.removeChild(e);}createTextNode(t){return document.createTextNode(t)}updateTextNode(t,e){t.textContent=e;}addEventListener(t,e,o){let n=v[e]||e;_.on(t,n,o);}removeEventListener(t,e,o){let n=v[e]||e;_.off(t,n);}},u=new B;function k(i,t,e,o){let n=0,r=t.length-1,d=0,l=e.length-1,c=t[0],f=t[r],a=e[0],s=e[l],x;for(;n<=r&&d<=l;)if(c==null)c=t[++n];else if(f==null)f=t[--r];else if(E(c,a))S(c,a),c=t[++n],a=e[++d];else if(E(f,s))S(f,s),f=t[--r],s=e[--l];else if(E(c,s))S(c,s),u.insertBefore(i,c._node,u.nextSibling(f._node)),c=t[++n],s=e[--l];else if(E(f,a))S(f,a),u.insertBefore(i,f._node,c._node),f=t[--r],a=e[++d];else {x||(x=Q(t,n,r));let h=a.key,g=h!=null?x.get(h):void 0;if(g===void 0){let y=p(a,void 0);y&&(a._node=y,u.insertBefore(i,y,c._node));}else {let y=t[g];S(y,a),t[g]=void 0,u.insertBefore(i,y._node,c._node);}a=e[++d];}if(n>r){let h=e[l+1]==null?o:e[l+1]._node;for(let g=d;g<=l;g++){let y=p(e[g],void 0);y&&(e[g]._node=y,u.insertBefore(i,y,h));}}else if(d>l)for(let h=n;h<=r;h++){let g=t[h];g&&g._node&&(b(g._node),u.removeChild(i,g._node));}}function E(i,t){return i.key===t.key&&i.type===t.type}function Q(i,t,e){let o=new Map;for(let n=t;n<=e;n++){let r=i[n].key;r!=null&&o.set(r,n);}return o}function S(i,t){let e=i._node;if(e&&(t._node=e,typeof t.type=="string")){u.updateNode(e,i.props,t.props);let o=i.children||[],n=t.children||[];if(o.length>0||n.length>0){if(n.length===1&&(typeof n[0]=="string"||typeof n[0]=="number")&&e.firstChild&&e.firstChild.nodeType===Node.TEXT_NODE&&e.childNodes.length===1){String(o[0])!==String(n[0])&&u.updateTextNode(e.firstChild,String(n[0]));return}k(e,o,n,null);}}}var N=new WeakMap;function p(i,t){if(i==null)return null;if(h(i)||typeof i=="function"){let e=document.createTextNode(""),o=document.createDocumentFragment();o.appendChild(e);let n=e,r=null,d$1=[],l=d(()=>{let a=h(i)?i.value:i();if(Array.isArray(a)){let s=a.filter(h=>h!=null),x=n&&n.parentNode?n.parentNode:t;if(x){if(d$1.length>0&&x!==o){let h=n.nextSibling;k(x,d$1,s,h);}else {n&&n!==e&&!d$1.length&&n.parentNode&&u.removeChild(n.parentNode,n);let h=document.createDocumentFragment();for(let g of s){let y=p(g,h);y&&typeof g=="object"&&(g._node=y);}e.parentNode&&e.parentNode.insertBefore(h,e.nextSibling);}d$1=s,r=a,n=e;}return}if(d$1.length>0){let s=e.parentNode;if(s)for(let x of d$1)x._node&&u.removeChild(s,x._node);d$1=[];}if(a!==r){if((typeof a=="string"||typeof a=="number")&&n&&n.nodeType===Node.TEXT_NODE&&n!==e)u.updateTextNode(n,String(a));else {let s=p(a);s?(n&&n!==e&&n.parentNode?n.parentNode.replaceChild(s,n):e.parentNode&&e.parentNode.insertBefore(s,e.nextSibling),n=s):(n&&n!==e&&n.parentNode&&u.removeChild(n.parentNode,n),n=e);}r=a;}}),c=n||e;c&&(N.has(c)||N.set(c,new Set),N.get(c).add(l));let f=n!==e&&n?n:o;return t&&u.appendChild(t,f),f===o?e:f}if(Array.isArray(i)){let e=document.createDocumentFragment();for(let o of i)p(o,e);return t&&u.appendChild(t,e),e}if(typeof i=="string"||typeof i=="number")return u.createTextNode(String(i));if(g(i)){if(typeof i.type=="function"){let n=i.type,r=null,d$2=d(()=>{let l=n._contextId;l&&c(l,i.props.value);try{let c;try{c=n({...i.props,children:i.children});}catch(f){if(f instanceof Promise){let a=b$2(L);if(a)a.registerPromise(f),a.registerPromise(f),c="";else throw f}else throw f}if(r){let f=p(c);f&&t&&(t.replaceChild(f,r),b(r),r=f);}else r=p(c,t);}finally{l&&d$1(l);}});return r&&(N.has(r)||N.set(r,new Set),N.get(r).add(d$2)),r}if(i.type==="fragment"){let n=document.createDocumentFragment();for(let r of i.children){let d=p(r,n);d&&n.appendChild(d);}return n}let e=u.createNode(i.type,i.props),o=Y(e,i.props);o.length>0&&N.set(e,new Set(o));for(let n of i.children){let r=p(n,e);r&&u.appendChild(e,r);}return t&&u.appendChild(t,e),e}return null}function Y(i,t){let e=[];for(let o in t){let n=t[o];if(!o.startsWith("on")){if(h(n)){let r=d(()=>{let d=n.value,l={[o]:void 0},c={[o]:d};u.updateNode(i,l,c);});e.push(r);continue}if(typeof n=="function"){let r=d(()=>{try{let d=n(),l={[o]:void 0},c={[o]:d};u.updateNode(i,l,c);}catch{}});e.push(r);}}}return e}function b(i){let t=N.get(i);t&&(t.forEach(e=>e()),N.delete(i)),i.childNodes&&i.childNodes.forEach(e=>b(e));}function Z(i,t){for(;t.firstChild;)b(t.firstChild),t.removeChild(t.firstChild);let e=p(i,t);return e&&t.appendChild(e),e}function he(i){let t=null;return {render(e){e$1(()=>{t&&t(),t=d(()=>{Z(e,i);});});},unmount(){for(t&&(t(),t=null);i.firstChild;)b(i.firstChild),i.removeChild(i.firstChild);}}}function Ne(i$1){let t=i$1.mount||document.body,e=document.createComment("portal"),o=null;return o=p(i$1.children,t),i(()=>{o&&(b(o),o.parentNode===t&&t.removeChild(o));}),e}export{te as a,B as b,u as c,p as d,Z as e,he as f,Ne as g};//# sourceMappingURL=chunk-JV5YLJIQ.mjs.map //# sourceMappingURL=chunk-JV5YLJIQ.mjs.map