rip-lang 3.7.3 → 3.8.8

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.
@@ -0,0 +1,2 @@
1
+ var se,te,W,O,G,de,M,C,Z,I,H,ne,pe,he,F,J,me,ye,ge,B,ee,Ee,ve,re,Pe,N,oe,we,be,je,_e,xe,ie,Se;({__state:C,__effect:M,__batch:de}=globalThis.__rip);({setContext:je,getContext:Ee,hasContext:Pe}=globalThis.__ripComponent||{});G=Symbol("stash");O=Symbol("signals");W=Symbol("raw");te=new WeakMap;Z=0;ne=C(0);re=function(n,r){let o;if(!n[O])Object.defineProperty(n,O,{value:new Map,enumerable:!1});if(o=n[O].get(r),!o)o=C(n[r]),n[O].set(r,o);return o};N=function(n){return re(n,Symbol.for("keys"))};Se=function(n){let r;if(!(n!=null&&typeof n==="object"))return n;if(n[G])return n;if(n instanceof Date||n instanceof RegExp||n instanceof Map||n instanceof Set||n instanceof Promise)return n;if(r=te.get(n),r)return r;return oe(n)};oe=function(n){let r,o;return o=null,r={get:function(t,e){let i,u;if(e===G)return!0;if(e===W)return t;if(typeof e==="symbol")return Reflect.get(t,e);if(e==="length"&&Array.isArray(t))return N(t).value,t.length;if(e==="get")return function(a){return _e(o,a)};if(e==="set")return function(a,f){return xe(o,a,f)};if(i=re(t,e),u=i.value,u!=null&&typeof u==="object")return Se(u);return u},set:function(t,e,i){let u,a;if(u=t[e],a=i?.[W]?i[W]:i,a===u)return!0;if(t[e]=a,t[O]?.has(e))t[O].get(e).value=a;if(u===void 0&&a!==void 0)N(t).value=++Z;return ne.value++,!0},deleteProperty:function(t,e){let i;if(delete t[e],i=t[O]?.get(e),i)i.value=void 0;return N(t).value=++Z,!0},ownKeys:function(t){return N(t).value,Reflect.ownKeys(t)}},o=new Proxy(n,r),te.set(n,o),o};se=/([./][^./\[\s]+|\[[-+]?\d+\]|\[(?:"[^"]+"|'[^']+')\])/;ie=function(n){let r,o,t,e,i;t=("."+n).split(se),t.shift(),i=[],o=0;while(o<t.length){if(e=t[o],r=e[0],r==="."||r==="/")i.push(e.slice(1));else if(r==="[")if(e[1]==='"'||e[1]==="'")i.push(e.slice(2,-2));else i.push(+e.slice(1,-1));o+=2}return i};_e=function(n,r){let o,t;t=ie(r),o=n;for(let e of t){if(o==null)return;o=o[e]}return o};xe=function(n,r,o){let t,e;e=ie(r),t=n;for(let i=0;i<e.length;i++){let u=e[i];if(i===e.length-1)t[u]=o;else{if(t[u]==null)t[u]={};t=t[u]}}return o};H=function(n){return typeof n==="function"?n:function(){return n.value}};I=function(n,r){let o;return o={read:function(){return n.read()}},Object.defineProperty(o,"value",{get:function(){return n.value},set:function(t){return r.value=t}}),o};ge=function(n){let r;if(r=n.replace(/\.rip$/,""),r=r.replace(/\[\.\.\.(\w+)\]/g,"*$1"),r=r.replace(/\[(\w+)\]/g,":$1"),r==="index")return"/";return r=r.replace(/\/index$/,""),"/"+r};be=function(n){let r,o;return r=[],o=n.replace(/\*(\w+)/g,function(t,e){return r.push(e),"(.+)"}).replace(/:(\w+)/g,function(t,e){return r.push(e),"([^/]+)"}),{regex:new RegExp("^"+o+"$"),names:r}};we=function(n,r){let o,t;for(let e of r)if(o=n.match(e.regex.regex),o){t={};for(let i=0;i<e.regex.names.length;i++){let u=e.regex.names[i];t[u]=decodeURIComponent(o[i+1])}return{route:e,params:t}}return null};F=function(n,r="components"){let o,t,e,i,u,a,f,m;f=[],e=new Map,o=n.listAll(r);for(let c of o){if(a=c.slice(r.length+1),!a.endsWith(".rip"))continue;if(i=a.split("/").pop(),i==="_layout.rip"){t=a==="_layout.rip"?"":a.slice(0,-12),e.set(t,c);continue}if(i.startsWith("_"))continue;m=ge(a),u=be(m),f.push({pattern:m,regex:u,file:c,rel:a})}return f.sort(function(c,g){let p,x,y,d;if(x=(c.pattern.match(/:/g)||[]).length,d=(g.pattern.match(/:/g)||[]).length,p=c.pattern.includes("*")?1:0,y=g.pattern.includes("*")?1:0,p!==y)return p-y;if(x!==d)return x-d;return c.pattern.localeCompare(g.pattern)}),{routes:f,layouts:e}};ve=function(n,r,o){let t,e,i,u;if(t=[],i=n.slice(r.length+1),u=i.split("/"),e="",o.has(""))t.push(o.get(""));for(let a=0;a<u.length;a++){let f=u[a];if(a===u.length-1)break;if(e=e?e+"/"+f:f,o.has(e))t.push(o.get(e))}return t};pe=function(n,r){if(n.length!==r.length)return!1;for(let o=0;o<n.length;o++)if(n[o]!==r[o])return!1;return!0};ee=function(n){for(let r in n){let o=n[r];if(typeof o==="function"&&(o.prototype?.mount||o.prototype?._create))return o}return typeof n.default==="function"?n.default:void 0};B=function(n){let r;r={};for(let o in n){let t=n[o];if(typeof t==="function"&&(t.prototype?.mount||t.prototype?._create))r[o]=t}return r};ye=function(n){let r;return r=n.split("/").pop().replace(/\.rip$/,""),r.replace(/(^|[-_])([a-z])/g,function(o,t,e){return e.toUpperCase()})};he=function(n,r="components"){let o,t,e;t={};for(let i of n.listAll(r)){if(!i.endsWith(".rip"))continue;if(o=i.split("/").pop(),o.startsWith("_"))continue;if(e=ye(i),t[e])console.warn(`[Rip] Component name collision: ${e} (${t[e]} vs ${i})`);t[e]=i}return t};J=async function(n,r,o=null,t=null,e=null){let i,u,a,f,m,c,g,p,x,y,d;if(o&&t){if(u=o.getCompiled(t),u)return u}if(c=r(n),e){x={};for(let h in e.map){let v=e.map[h];if(v!==t&&c.includes(`new ${h}(`)){if(!e.classes[h]){if(f=o.read(v),f){a=await J(f,r,o,v,e),m=B(a);for(let S in m){let s=m[S];e.classes[S]=s}}}if(e.classes[h])x[h]=!0}}if(p=Object.keys(x),p.length>0)y=`const {${p.join(", ")}} = globalThis['${e.key}'];
2
+ `,c=y+c}i=new Blob([c],{type:"application/javascript"}),d=URL.createObjectURL(i);try{g=await import(d)}finally{URL.revokeObjectURL(d)}if(e){m=B(g);for(let h in m){let v=m[h];e.classes[h]=v}}if(o&&t)o.setCompiled(t,g);return g};me=function(n,r,o,t,e=""){let i,u,a;return a=1000,u=30000,i=function(){let f;return f=new EventSource(t),f.addEventListener("connected",function(){return a=1000,console.log("[Rip] Hot reload connected")}),f.addEventListener("changed",async function(m){let c,g,p,x,y;({paths:p}=JSON.parse(m.data));for(let d of p)n.del(d);if(r.rebuild(),c=r.current,y=p.filter(function(d){return d===c.route?.file||c.layouts?.includes(d)}),y.length>0){x=await Promise.allSettled(y.map(async function(d){let h,v;return v=await fetch(e+"/"+d),h=await v.text(),n.write(d,h)})),g=x.filter(function(d){return d.status==="rejected"});for(let d of g)console.error("[Rip] Hot reload fetch error:",d.reason);return o.remount()}}),f.onerror=function(){return f.close(),console.log(`[Rip] Hot reload reconnecting in ${a/1000}s...`),setTimeout(i,a),a=Math.min(a*2,u)}},i()};var ke=function(n={}){return oe(n)},Te=function(n){return n?.[W]?n[W]:n},Ae=function(n){return n?.[G]===!0},Ue=function(n,r={}){let o,t,e,i,u;if(o=C(r.initial||null),e=C(!1),t=C(null),i=async function(){let a;return e.value=!0,t.value=null,(async()=>{try{return a=await n(),o.value=a}catch(f){return t.value=f}finally{e.value=!1}})()},u={data:void 0,loading:void 0,error:void 0,refetch:i},Object.defineProperty(u,"data",{get:function(){return o.value}}),Object.defineProperty(u,"loading",{get:function(){return e.value}}),Object.defineProperty(u,"error",{get:function(){return t.value}}),!r.lazy)i();return u},$e=function(n,r){let o,t;return o=H(r),t=C(!!o()),M(function(){let e;if(o())return e=setTimeout(function(){return t.value=!0},n),function(){return clearTimeout(e)};else return t.value=!1}),typeof r!=="function"?I(t,r):t},We=function(n,r){let o,t;return o=H(r),t=C(o()),M(function(){let e,i;return i=o(),e=setTimeout(function(){return t.value=i},n),function(){return clearTimeout(e)}}),typeof r!=="function"?I(t,r):t},qe=function(n,r){let o,t,e;return o=H(r),e=C(o()),t=0,M(function(){let i,u,a,f;if(f=o(),i=Date.now(),u=n-(i-t),u<=0)return e.value=f,t=i;else return a=setTimeout(function(){return e.value=o(),t=Date.now()},u),function(){return clearTimeout(a)}}),typeof r!=="function"?I(e,r):e},De=function(n,r){let o,t;return o=H(r),t=C(!!o()),M(function(){let e;if(o())return t.value=!0;else return e=setTimeout(function(){return t.value=!1},n),function(){return clearTimeout(e)}}),typeof r!=="function"?I(t,r):t},Oe=function(){let n,r,o,t;return r=new Map,t=[],n=new Map,o=function(e,i){for(let u of t)u(e,i)},{read:function(e){return r.get(e)},write:function(e,i){let u;return u=!r.has(e),r.set(e,i),n.delete(e),o(u?"create":"change",e)},del:function(e){return r.delete(e),n.delete(e),o("delete",e)},exists:function(e){return r.has(e)},size:function(){return r.size},list:function(e=""){let i,u,a;a=[],i=e?e+"/":"";for(let[f]of r)if(f.startsWith(i)){if(u=f.slice(i.length),u.includes("/"))continue;a.push(f)}return a},listAll:function(e=""){let i,u;u=[],i=e?e+"/":"";for(let[a]of r)if(a.startsWith(i))u.push(a);return u},load:function(e){for(let i in e){let u=e[i];r.set(i,u)}},watch:function(e){return t.push(e),function(){return t.splice(t.indexOf(e),1)}},getCompiled:function(e){return n.get(e)},setCompiled:function(e,i){return n.set(e,i)}}},Le=function(n,r={}){let o,t,e,i,u,a,f,m,c,g,p,x,y,d,h,v,S,s,P,b,w;if(S=r.root||"components",c=r.base||"",g=r.hash||!1,y=r.onError||null,P=function(l){return c&&l.startsWith(c)?l.slice(c.length)||"/":l},m=function(l){return c?c+l:l},h=function(){let l;if(g){if(l=location.hash.slice(1),!l)return"/";return l[0]==="/"?l:"/"+l}else return location.pathname+location.search+location.hash},w=function(l){return g?l==="/"?location.pathname:"#"+l.slice(1):m(l)},u=C(P(g?h():location.pathname)),i=C({}),f=C(null),t=C([]),a=C({}),o=C(""),e=$e(100,C(!1)),b=F(n,S),p=new Set,n.watch(function(l,R){if(!R.startsWith(S+"/"))return;return b=F(n,S)}),v=function(l){let R,_,E,A,k;if(A=l.split("?")[0].split("#")[0],_=P(A),_=_[0]==="/"?_:"/"+_,E=l.split("?")[1]?.split("#")[0]||"",R=l.includes("#")?l.split("#")[1]:"",k=we(_,b.routes),k){de(function(){return u.value=_,i.value=k.params,f.value=k.route,t.value=ve(k.route.file,S,b.layouts),a.value=Object.fromEntries(new URLSearchParams(E)),o.value=R});for(let T of p)T(s.current);return!0}if(y)y({status:404,path:_});return!1},d=function(){return v(h())},typeof window<"u")window.addEventListener("popstate",d);if(x=function(l){let R,_,E;if(l.button!==0||l.metaKey||l.ctrlKey||l.shiftKey||l.altKey)return;_=l.target;while(_&&_.tagName!=="A")_=_.parentElement;if(!_?.href)return;if(E=new URL(_.href,location.origin),E.origin!==location.origin)return;if(_.target==="_blank"||_.hasAttribute("data-external"))return;return l.preventDefault(),R=g&&E.hash?E.hash.slice(1)||"/":E.pathname+E.search+E.hash,s.push(R)},typeof document<"u")document.addEventListener("click",x);return s={push:function(l){return v(l)?history.pushState(null,"",w(u.read())):void 0},replace:function(l){return v(l)?history.replaceState(null,"",w(u.read())):void 0},back:function(){return history.back()},forward:function(){return history.forward()},current:void 0,path:void 0,params:void 0,route:void 0,layouts:void 0,query:void 0,hash:void 0,navigating:void 0,onNavigate:function(l){return p.add(l),function(){return p.delete(l)}},rebuild:function(){return b=F(n,S)},routes:void 0,init:function(){return v(h()),s},destroy:function(){if(typeof window<"u")window.removeEventListener("popstate",d);if(typeof document<"u")document.removeEventListener("click",x);return p.clear()}},Object.defineProperty(s,"current",{get:function(){return{path:u.value,params:i.value,route:f.value,layouts:t.value,query:a.value,hash:o.value}}}),Object.defineProperty(s,"path",{get:function(){return u.value}}),Object.defineProperty(s,"params",{get:function(){return i.value}}),Object.defineProperty(s,"route",{get:function(){return f.value}}),Object.defineProperty(s,"layouts",{get:function(){return t.value}}),Object.defineProperty(s,"query",{get:function(){return a.value}}),Object.defineProperty(s,"hash",{get:function(){return o.value}}),Object.defineProperty(s,"navigating",{get:function(){return e.value},set:function(l){return e.value=l}}),Object.defineProperty(s,"routes",{get:function(){return b.routes}}),s},Me=function(n={}){let r,o,t,e,i,u,a,f,m,c,g,p,x,y,d,h,v,S,s,P,b;if({router:s,app:r,components:i,resolver:S,compile:t,target:P,onError:h}=n,u=typeof P==="string"?document.querySelector(P):P||document.getElementById("app"),!u)u=document.createElement("div"),u.id="app",document.body.appendChild(u);return u.style.opacity="0",a=null,m=null,f=[],p=[],y=u,g=0,c=null,e=new Map,x=n.cacheSize||10,o=function(){let w,l;if(a&&m){if(a.beforeUnmount)a.beforeUnmount();if(e.set(m,a),e.size>x){if(l=e.keys().next().value,w=e.get(l),w.unmounted)w.unmounted();e.delete(l)}return a=null,m=null}},b=function(){o();for(let w=p.length-1;w>=0;w--){let l=p[w];if(l.beforeUnmount)l.beforeUnmount();if(l.unmounted)l.unmounted();l._root?.remove()}return p=[],y=u},i.watch(function(w,l){let R;if(e.has(l)){if(R=e.get(l),R.unmounted)R.unmounted();return e.delete(l)}}),d=async function(w){let l,R,_,E,A,k,T,q,ue,V,D,ae,L,le,K,z,Ce,X,j,fe,Q,U;if({route:j,params:z,layouts:q,query:X}=w,!j)return;if(j.file===m)return;return E=++g,s.navigating=!0,(async()=>{try{if(Q=i.read(j.file),!Q){if(h)h({status:404,message:`File not found: ${j.file}`});s.navigating=!1;return}if(ae=await J(Q,t,i,j.file,S),E!==g){s.navigating=!1;return}if(l=ee(ae),!l){if(h)h({status:500,message:`No component found in ${j.file}`});s.navigating=!1;return}if(D=!pe(q,f),le=a?._root,D)b();else o();if(L=D?u:y,D&&q.length>0){u.innerHTML="",L=u;for(let $ of q){if(V=i.read($),!V)continue;if(ue=await J(V,t,i,$,S),E!==g){s.navigating=!1;return}if(R=ee(ue),!R)continue;if(k=new R({app:r,params:z,router:s}),k.beforeMount)k.beforeMount();U=document.createElement("div"),U.setAttribute("data-layout",$),L.appendChild(U),k.mount(U),p.push(k),fe=U.querySelector("#content")||U,L=fe}f=[...q],y=L}else if(D)u.innerHTML="",f=[],y=u;if(_=e.get(j.file),_)e.delete(j.file),L.appendChild(_._root),a=_,m=j.file;else{if(K=document.createElement("div"),K.setAttribute("data-component",j.file),L.appendChild(K),T=new l({app:r,params:z,query:X,router:s}),T.beforeMount)T.beforeMount();if(T.mount(K),a=T,m=j.file,T.load)await T.load(z,X)}return le?.remove(),s.navigating=!1,u.style.opacity==="0"?document.fonts.ready.then(function(){return requestAnimationFrame(function(){return u.style.transition="opacity 150ms ease-in",u.style.opacity="1"})}):void 0}catch($){if(s.navigating=!1,u.style.opacity="1",console.error(`Renderer: error mounting ${j.file}:`,$),h)h({status:500,message:$.message,error:$});A=!1;for(let Y=p.length-1;Y>=0;Y--){let ce=p[Y];if(ce.onError)try{ce.onError($),A=!0;break}catch(Re){console.error("Renderer: error boundary failed:",Re)}}return!A?u.appendChild(Ce):void 0}})()},v={start:function(){return c=M(function(){let w;return w=s.current,w.route?d(w):void 0}),s.init(),v},stop:function(){if(b(),c)c(),c=null;return u.innerHTML=""},remount:function(){let w;return w=s.current,w.route?d(w):void 0},cache:e},v},Ne=async function(n="",r={}){let o,t,e,i,u,a,f,m,c,g,p,x,y,d,h,v,S,s,P;if(n=n.replace(/\/+$/,""),P=r.target||"#app",c=r.compile||null,x=r.persist||!1,p=r.hash||!1,!c)c=globalThis?.compileToJS||null;if(typeof document<"u"&&!document.querySelector(P))g=document.createElement("div"),g.id=P.replace(/^#/,""),document.body.prepend(g);if(r.bundle)a=r.bundle;else{if(f=`${n}/bundle`,d=await fetch(f),!d.ok)throw Error(`launch: ${f} (${d.status})`);a=await d.json()}if(i=ke({components:{},routes:{},data:{}}),a.data)i.data=a.data;if(a.routes)i.routes=a.routes;if(x&&typeof sessionStorage<"u"){e=`__rip_${n}`,t=x==="local"?localStorage:sessionStorage;try{if(S=t.getItem(e),S){s=JSON.parse(S);for(let b in s){let w=s[b];i.data[b]=w}}}catch{}o=function(){return(()=>{try{return t.setItem(e,JSON.stringify(Te(i.data)))}catch{return null}})()},M(function(){let b;return ne.value,b=setTimeout(o,2000),function(){return clearTimeout(b)}}),window.addEventListener("beforeunload",o)}if(u=Oe(),a.components)u.load(a.components);if(m=`__rip_${n.replace(/\//g,"_")||"app"}`,h={map:he(u),classes:{},key:m},typeof globalThis<"u")globalThis[m]=h.classes;if(i.data.title&&typeof document<"u")document.title=i.data.title;if(v=Le(u,{root:"components",base:n,hash:p,onError:function(b){return console.error(`[Rip] Error ${b.status}: ${b.message||b.path}`)}}),y=Me({router:v,app:i,components:u,resolver:h,compile:c,target:P,onError:function(b){return console.error(`[Rip] ${b.message}`,b.error)}}),y.start(),a.data?.watch)me(u,v,y,`${n}/watch`,n);if(typeof window<"u")window.app=i,window.__RIP__={app:i,components:u,router:v,renderer:y,cache:y.cache,version:"0.3.0"};return{app:i,components:u,router:v,renderer:y}};export{qe as throttle,ke as stash,je as setContext,Te as raw,Ne as launch,Ae as isStash,De as hold,Pe as hasContext,Ee as getContext,$e as delay,We as debounce,Le as createRouter,Ue as createResource,Me as createRenderer,Oe as createComponents};
Binary file