@unsetsoft/ryunixjs 1.1.4-nightly.3 → 1.1.4-nightly.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/Ryunix.js +1 -1
- package/package.json +1 -1
- package/src/lib/createElement.js +3 -5
package/dist/Ryunix.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
!function(e,o){"object"==typeof exports&&"undefined"!=typeof module?o(exports,require("lodash")):"function"==typeof define&&define.amd?define(["exports","lodash"],o):o((e="undefined"!=typeof globalThis?globalThis:e||self).Ryunix={},e.lodash)}(this,(function(e,o){"use strict";const t={containerRoot:void 0,nextUnitOfWork:void 0,currentRoot:void 0,wipRoot:void 0,deletions:void 0,wipFiber:void 0,hookIndex:void 0},r=/[A-Z]/g,n=Object.freeze({TEXT_ELEMENT:Symbol("text.element"),Ryunix_ELEMENT:Symbol("ryunix.element"),RYUNIX_EFFECT:Symbol("ryunix.effect"),RYUNIX_MEMO:Symbol("ryunix.memo"),RYUNIX_URL_QUERY:Symbol("ryunix.urlQuery"),RYUNIX_REF:Symbol("ryunix.ref")}),i=Object.freeze({object:"object",function:"function",style:"ryunix-style",className:"ryunix-class",children:"children",boolean:"boolean"}),s=Object.freeze({style:"style",className:"className"}),a=Object.freeze({PLACEMENT:Symbol(),UPDATE:Symbol(),DELETION:Symbol()}),l=e=>e.children,c=(e,o)=>(o=o||[],null==e||typeof e==i.boolean||(Array.isArray(e)?e.some((e=>{c(e,o)})):o.push(e)),o),p=(e,o={},...t)=>{try{t=c(t,[]);const r=o.key?o.key:`${n.Ryunix_ELEMENT.toString()}-${Math.random().toString(36).substring(2,9)}`;if(!e||"string"!=typeof e&&"function"!=typeof e)throw new Error(`Invalid element type: ${e}. Expected a string (for HTML elements) or a function (for components).`);return{type:e,props:{...o,key:r,children:t.map((e=>typeof e===i.object?e:u(e)))}}}catch(e){return console.error("Error rendering element:",e),p("div",{style:{color:"red",padding:"10px",border:"1px solid red",background:"#ffe6e6"},children:p("p",{
|
|
1
|
+
!function(e,o){"object"==typeof exports&&"undefined"!=typeof module?o(exports,require("lodash")):"function"==typeof define&&define.amd?define(["exports","lodash"],o):o((e="undefined"!=typeof globalThis?globalThis:e||self).Ryunix={},e.lodash)}(this,(function(e,o){"use strict";const t={containerRoot:void 0,nextUnitOfWork:void 0,currentRoot:void 0,wipRoot:void 0,deletions:void 0,wipFiber:void 0,hookIndex:void 0},r=/[A-Z]/g,n=Object.freeze({TEXT_ELEMENT:Symbol("text.element"),Ryunix_ELEMENT:Symbol("ryunix.element"),RYUNIX_EFFECT:Symbol("ryunix.effect"),RYUNIX_MEMO:Symbol("ryunix.memo"),RYUNIX_URL_QUERY:Symbol("ryunix.urlQuery"),RYUNIX_REF:Symbol("ryunix.ref")}),i=Object.freeze({object:"object",function:"function",style:"ryunix-style",className:"ryunix-class",children:"children",boolean:"boolean"}),s=Object.freeze({style:"style",className:"className"}),a=Object.freeze({PLACEMENT:Symbol(),UPDATE:Symbol(),DELETION:Symbol()}),l=e=>e.children,c=(e,o)=>(o=o||[],null==e||typeof e==i.boolean||(Array.isArray(e)?e.some((e=>{c(e,o)})):o.push(e)),o),p=(e,o={},...t)=>{try{t=c(t,[]);const r=o.key?o.key:`${n.Ryunix_ELEMENT.toString()}-${Math.random().toString(36).substring(2,9)}`;if(!e||"string"!=typeof e&&"function"!=typeof e)throw new Error(`Invalid element type: ${e}. Expected a string (for HTML elements) or a function (for components).`);return{type:e,props:{...o,key:r,children:t.map((e=>typeof e===i.object?e:u(e)))}}}catch(e){return console.error("Error rendering element:",e),p("div",{style:{color:"red",padding:"10px",border:"1px solid red",background:"#ffe6e6"},children:p("p",{children:`An error occurred while rendering this component. [ERROR] ${e.message}`})})}},u=e=>({type:n.TEXT_ELEMENT,props:{nodeValue:e,children:[]}}),d=(e,o)=>{t.wipRoot={dom:t.containerRoot||o,props:{children:[e]},alternate:t.currentRoot},t.deletions=[],t.nextUnitOfWork=t.wipRoot},f=e=>{const o=t.wipFiber.alternate&&t.wipFiber.alternate.hooks&&t.wipFiber.alternate.hooks[t.hookIndex],r={state:o?o.state:e,queue:o?[...o.queue]:[]};r.queue.forEach((e=>{r.state=typeof e===i.function?e(r.state):e})),r.queue=[];return t.wipFiber&&t.wipFiber.hooks&&(t.wipFiber.hooks.push(r),t.hookIndex++),[r.state,e=>{r.queue.push(e),t.wipRoot={dom:t.currentRoot.dom,props:t.currentRoot.props,alternate:t.currentRoot},t.nextUnitOfWork=t.wipRoot,t.deletions=[]}]},m=(e,r)=>{const i=t.wipFiber.alternate&&t.wipFiber.alternate.hooks&&t.wipFiber.alternate.hooks[t.hookIndex],s={type:n.RYUNIX_EFFECT,deps:r};i&&o.isEqual(i.deps,s.deps)||e(),t.wipFiber.hooks&&(t.wipFiber.hooks.push(s),t.hookIndex++)},h=(e,r)=>{const i=t.wipFiber.alternate&&t.wipFiber.alternate.hooks&&t.wipFiber.alternate.hooks[t.hookIndex],s={type:n.RYUNIX_MEMO,value:null,deps:r};return i&&o.isEqual(i.deps,s.deps)?s.value=i.value:s.value=e(),t.wipFiber.hooks&&(t.wipFiber.hooks.push(s),t.hookIndex++),s.value},y=()=>{const e=new URLSearchParams(window.location.search),o={};for(let[t,r]of e.entries())o[t]=r;return o},b=e=>e.startsWith("on"),E=e=>e!==i.children&&!b(e),w=(e,o)=>t=>e[t]!==o[t],k=e=>o=>!(o in e),R=e=>{e.hooks&&e.hooks.filter((e=>e.tag===n.RYUNIX_EFFECT&&e.cancel)).forEach((e=>{e.cancel()}))},x=e=>{e.hooks&&e.hooks.filter((e=>e.tag===n.RYUNIX_EFFECT&&e.effect)).forEach((e=>{e.cancel=e.effect()}))},F=e=>{const o=e.type==n.TEXT_ELEMENT?document.createTextNode(""):document.createElement(e.type);return v(o,{},e.props),o},v=(e,o,t)=>{Object.keys(o).filter(b).filter((e=>k(t)(e)||w(o,t)(e))).forEach((t=>{const r=t.toLowerCase().substring(2);e.removeEventListener(r,o[t])})),Object.keys(o).filter(E).filter(k(t)).forEach((o=>{e[o]=""})),Object.keys(t).filter(E).filter(w(o,t)).forEach((r=>{if(r===i.style)_(e,t["ryunix-style"]);else if(r===s.style)_(e,t.style);else if(r===i.className){if(""===t["ryunix-class"])throw new Error("data-class cannot be empty.");o["ryunix-class"]&&e.classList.remove(...o["ryunix-class"].split(/\s+/)),e.classList.add(...t["ryunix-class"].split(/\s+/))}else if(r===s.className){if(""===t.className)throw new Error("className cannot be empty.");o.className&&e.classList.remove(...o.className.split(/\s+/)),e.classList.add(...t.className.split(/\s+/))}else e[r]=t[r]})),Object.keys(t).filter(b).filter(w(o,t)).forEach((o=>{const r=o.toLowerCase().substring(2);e.addEventListener(r,t[o])}))},_=(e,o)=>{e.style=Object.keys(o).reduce(((e,t)=>e+=`${t.replace(r,(function(e){return"-"+e.toLowerCase()}))}: ${o[t]};`),"")};var g=Object.freeze({__proto__:null,DomStyle:_,createDom:F,updateDom:v});const N=()=>{t.deletions.forEach(T),t.wipRoot&&t.wipRoot.child&&(T(t.wipRoot.child),t.currentRoot=t.wipRoot),t.wipRoot=void 0},T=e=>{if(!e)return;let o=e.parent;for(;!o.dom;)o=o.parent;const t=o.dom;if(e.effectTag===a.PLACEMENT&&(null!=e.dom&&t.appendChild(e.dom),x(e)),e.effectTag===a.UPDATE&&(R(e),null!=e.dom&&v(e.dom,e.alternate.props,e.props),x(e)),e.effectTag===a.DELETION)return O(e,t),void R(e);T(e.child),T(e.sibling)},O=(e,o)=>{e.dom?o.removeChild(e.dom):O(e.child,o)};var L=Object.freeze({__proto__:null,commitDeletion:O,commitRoot:N,commitWork:T});const I=(e,o)=>{let r=0,n=e.alternate&&e.alternate.child,i=null;const s=new Map;for(;n;){const e=n.props.key||n.type;s.set(e,n),n=n.sibling}for(;r<o.length;){const n=o[r],l=n.props.key||n.type,c=s.get(l);let p;c&&n&&n.type===c.type?(p={type:c.type,props:n.props,dom:c.dom,parent:e,alternate:c,effectTag:a.UPDATE},s.delete(l)):n&&(p={type:n.type,props:n.props,dom:void 0,parent:e,alternate:void 0,effectTag:a.PLACEMENT}),s.forEach((e=>{e.effectTag=a.DELETION,t.deletions.push(e)})),0===r?e.child=p:i&&(i.sibling=p),i=p,r++}};var U=Object.freeze({__proto__:null,reconcileChildren:I});const C=e=>{t.wipFiber=e,t.hookIndex=0,t.wipFiber.hooks=[];const o=e.type(e.props);let r=[];r=Array.isArray(o)?[...o]:[o],I(e,r)},j=e=>{e.dom||(e.dom=F(e)),I(e,e.props.children)};var M=Object.freeze({__proto__:null,updateFunctionComponent:C,updateHostComponent:j});const S=e=>{let o=!1;for(;t.nextUnitOfWork&&!o;)t.nextUnitOfWork=A(t.nextUnitOfWork),o=e.timeRemaining()<1;!t.nextUnitOfWork&&t.wipRoot&&N(),requestIdleCallback(S)};requestIdleCallback(S);const A=e=>{if(e.type instanceof Function?C(e):j(e),e.child)return e.child;let o=e;for(;o;){if(o.sibling)return o.sibling;o=o.parent}};var D={createElement:p,render:d,init:(e,o="__ryunix")=>{t.containerRoot=document.getElementById(o),d(e,t.containerRoot)},Fragment:l,Dom:g,Workers:Object.freeze({__proto__:null,performUnitOfWork:A,workLoop:S}),Reconciler:U,Components:M,Commits:L};window.Ryunix=D,e.Fragment=l,e.default=D,e.useCallback=(e,o)=>h((()=>e),o),e.useEffect=m,e.useMemo=h,e.useQuery=y,e.useRef=e=>{const o=t.wipFiber.alternate&&t.wipFiber.alternate.hooks&&t.wipFiber.alternate.hooks[t.hookIndex],r={type:n.RYUNIX_REF,value:o?o.value:{current:e}};return t.wipFiber.hooks&&(t.wipFiber.hooks.push(r),t.hookIndex++),r.value},e.useRouter=e=>{const[o,t]=f(window.location.pathname),r=e=>{window.history.pushState({},"",e),n(e)},n=e=>{t(e.split("?")[0])};m((()=>{const e=()=>n(window.location.pathname);return window.addEventListener("popstate",e),()=>window.removeEventListener("popstate",e)}),[]);const i=((e,o)=>{const t=o.split("?")[0];for(const{path:o,component:r}of e){if(!o)continue;const e=[],n=new RegExp(`^${o.replace(/:\w+/g,(o=>(e.push(o.substring(1)),"([^/]+)")))}$`),i=t.match(n);if(i){return{route:{component:r},params:e.reduce(((e,o,t)=>(e[o]=i[t+1],e)),{})}}}const r=e.find((e=>e.NotFound));return r?{route:{component:r.NotFound},params:{}}:{route:{component:null},params:{}}})(e,o);return{Children:()=>{const e=y();return i.route.component?i.route.component({params:i.params,query:e}):null},NavLink:({to:e,...o})=>p("a",{href:e,onClick:o=>{o.preventDefault(),r(e)},...o},o.children),navigate:r}},e.useStore=f,Object.defineProperty(e,"__esModule",{value:!0})}));
|
package/package.json
CHANGED
package/src/lib/createElement.js
CHANGED
|
@@ -79,11 +79,9 @@ const createElement = (type, props = {}, ...children) => {
|
|
|
79
79
|
border: '1px solid red',
|
|
80
80
|
background: '#ffe6e6',
|
|
81
81
|
},
|
|
82
|
-
children: createElement(
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
`An error occurred while rendering this component. [ERROR] ${error.message}`,
|
|
86
|
-
),
|
|
82
|
+
children: createElement('p', {
|
|
83
|
+
children: `An error occurred while rendering this component. [ERROR] ${error.message}`,
|
|
84
|
+
}),
|
|
87
85
|
})
|
|
88
86
|
}
|
|
89
87
|
}
|