ajo 0.0.23 → 0.0.25

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/index.cjs CHANGED
@@ -155,34 +155,19 @@ const { isArray, from } = Array, { is } = Object, noop = () => {
155
155
  }
156
156
  hooks[0]++;
157
157
  }, schedule = (host) => {
158
- if (host.$idleId)
158
+ if (host.$idle)
159
159
  return;
160
160
  if (globalThis.navigator?.scheduling?.isInputPending()) {
161
- if (!host.$idle) {
162
- host.$idle = true;
163
- idleCount++;
164
- }
165
- host.$idleId = requestIdleCallback(() => {
166
- host.$idleId = null;
167
- schedule(host);
168
- });
161
+ idleQueue.add(host);
162
+ host.$idle = true;
163
+ idleId ??= requestIdleCallback(runIdle);
169
164
  return;
170
165
  }
171
- runComponent(host);
172
- }, runMutations = (host) => {
173
- if (host.$queued)
174
- return;
175
- host.$queued = true;
176
- microtask(() => {
177
- host.$queued = false;
178
- runComponent(host);
179
- });
180
- }, runComponent = (host) => {
181
- if (host.$idleId) {
182
- cancelIdleCallback(host.$idleId);
183
- host.$idleId = null;
166
+ run(host);
167
+ }, run = (host) => {
168
+ if (host.$idle) {
169
+ idleQueue.delete(host);
184
170
  host.$idle = false;
185
- idleCount--;
186
171
  }
187
172
  current = host;
188
173
  if (current.$hooks)
@@ -193,18 +178,30 @@ const { isArray, from } = Array, { is } = Object, noop = () => {
193
178
  propagate(value, host.parentNode);
194
179
  } finally {
195
180
  current = null;
196
- layoutsQueue.add(host);
197
- if (host.$idle) {
198
- host.$idle = false;
199
- if (--idleCount)
200
- return;
201
- }
202
- layoutsId ??= task(runLayouts);
181
+ layoutQueue.add(host);
182
+ host.$layoutQueued = true;
183
+ layoutId ??= task(runLayouts);
184
+ }
185
+ }, runIdle = () => {
186
+ idleId = null;
187
+ for (const host of from(idleQueue)) {
188
+ idleQueue.delete(host);
189
+ host.$idle = false;
190
+ schedule(host);
203
191
  }
192
+ }, runMutations = (host) => {
193
+ if (host.$runQueued)
194
+ return;
195
+ host.$runQueued = true;
196
+ microtask(() => {
197
+ host.$runQueued = false;
198
+ run(host);
199
+ });
204
200
  }, runLayouts = () => {
205
- layoutsId = null;
206
- for (const host of layoutsQueue) {
207
- layoutsQueue.delete(host);
201
+ layoutId = null;
202
+ for (const host of layoutQueue) {
203
+ layoutQueue.delete(host);
204
+ host.$layoutQueued = false;
208
205
  try {
209
206
  render(host.$h, host);
210
207
  host.$h = null;
@@ -212,14 +209,16 @@ const { isArray, from } = Array, { is } = Object, noop = () => {
212
209
  propagate(value, host);
213
210
  } finally {
214
211
  runFx(host, "$layout");
215
- effectsQueue.add(host);
216
- effectsId ??= task(runEffects);
212
+ effectQueue.add(host);
213
+ host.$effectQueued = true;
214
+ effectId ??= task(runEffects);
217
215
  }
218
216
  }
219
217
  }, runEffects = () => {
220
- effectsId = null;
221
- for (const host of effectsQueue) {
222
- effectsQueue.delete(host);
218
+ effectId = null;
219
+ for (const host of effectQueue) {
220
+ effectQueue.delete(host);
221
+ host.$effectQueued = false;
223
222
  runFx(host, "$effect");
224
223
  }
225
224
  }, runFx = (host, key) => {
@@ -248,8 +247,18 @@ const { isArray, from } = Array, { is } = Object, noop = () => {
248
247
  host.$ref.current = null;
249
248
  if (!host.$fn)
250
249
  return;
251
- layoutsQueue.delete(host);
252
- effectsQueue.delete(host);
250
+ if (host.$idle) {
251
+ idleQueue.delete(host);
252
+ host.$idle = false;
253
+ }
254
+ if (host.$layoutQueued) {
255
+ layoutQueue.delete(host);
256
+ host.$layoutQueued = false;
257
+ }
258
+ if (host.$effectQueued) {
259
+ effectQueue.delete(host);
260
+ host.$effectQueued = false;
261
+ }
253
262
  for (const key of ["$layout", "$effect"])
254
263
  if (host[key]) {
255
264
  for (const fx of host[key]) {
@@ -270,4 +279,4 @@ const { isArray, from } = Array, { is } = Object, noop = () => {
270
279
  return void fn(value);
271
280
  throw value;
272
281
  };
273
- let idleCount = 0, layoutsQueue = /* @__PURE__ */ new Set(), effectsQueue = /* @__PURE__ */ new Set(), layoutsId = null, effectsId = null, current = null;
282
+ let current = null, layoutQueue = /* @__PURE__ */ new Set(), effectQueue = /* @__PURE__ */ new Set(), idleQueue = /* @__PURE__ */ new Set(), layoutId = null, effectId = null, idleId = null;
package/index.js CHANGED
@@ -197,44 +197,23 @@ const
197
197
 
198
198
  schedule = host => {
199
199
 
200
- if (host.$idleId) return
200
+ if (host.$idle) return
201
201
 
202
202
  if (globalThis.navigator?.scheduling?.isInputPending()) {
203
-
204
- if (!host.$idle) {
205
- host.$idle = true
206
- idleCount++
207
- }
208
-
209
- host.$idleId = requestIdleCallback(() => {
210
- host.$idleId = null
211
- schedule(host)
212
- })
213
-
203
+ idleQueue.add(host)
204
+ host.$idle = true
205
+ idleId ??= requestIdleCallback(runIdle)
214
206
  return
215
207
  }
216
208
 
217
- runComponent(host)
209
+ run(host)
218
210
  },
219
211
 
220
- runMutations = host => {
221
-
222
- if (host.$queued) return
212
+ run = host => {
223
213
 
224
- host.$queued = true
225
- microtask(() => {
226
- host.$queued = false
227
- runComponent(host)
228
- })
229
- },
230
-
231
- runComponent = host => {
232
-
233
- if (host.$idleId) {
234
- cancelIdleCallback(host.$idleId)
235
- host.$idleId = null
214
+ if (host.$idle) {
215
+ idleQueue.delete(host)
236
216
  host.$idle = false
237
- idleCount--
238
217
  }
239
218
 
240
219
  current = host
@@ -247,24 +226,42 @@ const
247
226
  propagate(value, host.parentNode)
248
227
  } finally {
249
228
  current = null
250
- layoutsQueue.add(host)
229
+ layoutQueue.add(host)
230
+ host.$layoutQueued = true
231
+ layoutId ??= task(runLayouts)
232
+ }
233
+ },
251
234
 
252
- if (host.$idle) {
253
- host.$idle = false
254
- if (--idleCount) return
255
- }
235
+ runIdle = () => {
256
236
 
257
- layoutsId ??= task(runLayouts)
237
+ idleId = null
238
+
239
+ for (const host of from(idleQueue)) {
240
+ idleQueue.delete(host)
241
+ host.$idle = false
242
+ schedule(host)
258
243
  }
259
244
  },
260
245
 
246
+ runMutations = host => {
247
+
248
+ if (host.$runQueued) return
249
+
250
+ host.$runQueued = true
251
+ microtask(() => {
252
+ host.$runQueued = false
253
+ run(host)
254
+ })
255
+ },
256
+
261
257
  runLayouts = () => {
262
258
 
263
- layoutsId = null
259
+ layoutId = null
264
260
 
265
- for (const host of layoutsQueue) {
261
+ for (const host of layoutQueue) {
266
262
 
267
- layoutsQueue.delete(host)
263
+ layoutQueue.delete(host)
264
+ host.$layoutQueued = false
268
265
 
269
266
  try {
270
267
  render(host.$h, host)
@@ -273,18 +270,20 @@ const
273
270
  propagate(value, host)
274
271
  } finally {
275
272
  runFx(host, '$layout')
276
- effectsQueue.add(host)
277
- effectsId ??= task(runEffects)
273
+ effectQueue.add(host)
274
+ host.$effectQueued = true
275
+ effectId ??= task(runEffects)
278
276
  }
279
277
  }
280
278
  },
281
279
 
282
280
  runEffects = () => {
283
281
 
284
- effectsId = null
282
+ effectId = null
285
283
 
286
- for (const host of effectsQueue) {
287
- effectsQueue.delete(host)
284
+ for (const host of effectQueue) {
285
+ effectQueue.delete(host)
286
+ host.$effectQueued = false
288
287
  runFx(host, '$effect')
289
288
  }
290
289
  },
@@ -319,8 +318,20 @@ const
319
318
 
320
319
  if (!host.$fn) return
321
320
 
322
- layoutsQueue.delete(host)
323
- effectsQueue.delete(host)
321
+ if (host.$idle) {
322
+ idleQueue.delete(host)
323
+ host.$idle = false
324
+ }
325
+
326
+ if (host.$layoutQueued) {
327
+ layoutQueue.delete(host)
328
+ host.$layoutQueued = false
329
+ }
330
+
331
+ if (host.$effectQueued) {
332
+ effectQueue.delete(host)
333
+ host.$effectQueued = false
334
+ }
324
335
 
325
336
  for (const key of ['$layout', '$effect']) if (host[key]) {
326
337
 
@@ -346,9 +357,10 @@ const
346
357
  }
347
358
 
348
359
  let
349
- idleCount = 0,
350
- layoutsQueue = new Set,
351
- effectsQueue = new Set,
352
- layoutsId = null,
353
- effectsId = null,
354
- current = null
360
+ current = null,
361
+ layoutQueue = new Set,
362
+ effectQueue = new Set,
363
+ idleQueue = new Set,
364
+ layoutId = null,
365
+ effectId = null,
366
+ idleId = null
package/index.min.js CHANGED
@@ -1 +1 @@
1
- var ajo=(()=>{var k=Object.defineProperty;var z=Object.getOwnPropertyDescriptor;var P=Object.getOwnPropertyNames;var V=Object.prototype.hasOwnProperty;var W=(e,n)=>{for(var i in n)k(e,i,{get:n[i],enumerable:!0})},D=(e,n,i,l)=>{if(n&&typeof n=="object"||typeof n=="function")for(let t of P(n))!V.call(e,t)&&t!==i&&k(e,t,{get:()=>n[t],enumerable:!(l=z(n,t))||l.enumerable});return e};var G=e=>D(k({},"__esModule",{value:!0}),e);var se={};W(se,{Fragment:()=>J,component:()=>K,h:()=>q,render:()=>N,useCallback:()=>Z,useCatch:()=>U,useEffect:()=>h,useHost:()=>m,useLayout:()=>_,useMemo:()=>I,useReducer:()=>S,useRef:()=>Y,useState:()=>X});const J=({children:e})=>e,q=(e,n,...i)=>{const{length:l}=i;return i=l==0?null:l==1?i[0]:i,{children:i,...n,nodeName:e}},N=(e,n,i)=>{let l=n.firstChild;for(e of x(e)){let t=l;if(e instanceof Node)t=e;else if(typeof e=="string"){for(;t&&t.nodeType!=3;)t=t.nextSibling;t?t.data!=e&&(t.data=e):t=document.createTextNode(e)}else{const{xmlns:r=i,nodeName:a,key:u,ref:f,memo:C,children:Q,[A]:v,...R}=e;for(;t&&!(t.localName==a&&d(t.$key??=u,u));)t=t.nextSibling;t??=re(r,a,u),te(f)&&(f.current=t,t.$ref=f),(C==null||w(t.$deps,t.$deps=C))&&(ae(R,t),o(v)?v(t):N(Q,t,r))}t==l?l=l.nextSibling:ue(n,t,l)}for(;l;){const t=l.nextSibling;H(l),n.removeChild(l),l=t}},K=e=>({nodeName:n,as:i,props:l,key:t,ref:r,memo:a,...u})=>q(i??e?.as??"c-host",{...e?.props,...l,key:t,ref:r,memo:a,[A]:f=>{f.$fn=o(e)?e:ne,f.$args={...e?.args,...u},j(f)}}),S=(e,n)=>{const i=m(),l=p(),[t,r]=l;return t==r.length&&(r[t]=[o(n)?n():n,a=>{const u=r[t][0],f=o(a)?a(u):a;d(u,r[t][0]=o(e)?e(u,f):f)||oe(i)}]),r[l[0]++]},I=(e,n)=>{const i=p(),[l,t]=i;return(l==t.length||n==null||w(n,t[l][1]))&&(t[l]=[e(),n]),t[i[0]++][0]},U=e=>{const n=m(),[i,l]=S(),t=p(),[r,a]=t;return a[t[0]++]=e,n.$catch??=u=>{o(a[r])&&a[r](u),l(u)},[i,()=>l()]},m=()=>c,X=e=>S(null,e),Y=e=>I(()=>({current:e}),[]),Z=(e,n)=>I(()=>e,n),_=(e,n)=>E(e,n,"$layout"),h=(e,n)=>E(e,n,"$effect"),{isArray:s,from:ee}=Array,{is:d}=Object,ne=()=>{},A=Symbol(),te=e=>e&&typeof e=="object",o=e=>typeof e=="function",w=(e,n)=>s(e)&&s(n)?e.some((i,l)=>!d(i,n[l])):!d(e,n),le=e=>ee(e).reduce(ie,{}),ie=(e,{name:n,value:i})=>(e[n]=i,e),F=globalThis.queueMicrotask??(e=>e()),T=globalThis.requestAnimationFrame??F,re=(e,n,i)=>{const l=e?document.createElementNS(e,n):document.createElement(n);return l.$key=i,l},x=function*(e,n={data:""},i=!0){let l;for(e of s(e)?e:[e])e==null||typeof e=="boolean"||(typeof e.nodeName=="string"?((l=n.data)&&(n.data="",yield l),yield e):o(e.nodeName)?yield*x(e.nodeName(e),n,!1):s(e)?yield*x(e,n,!1):n.data+=e);i&&(l=n.data)&&(yield l)},ae=(e,n)=>{const i=n.$props??=n.hasAttributes()?le(n.attributes):{};for(const l in{...i,...n.$props=e}){let t=e[l];t!==i[l]&&(l.startsWith("set:")?n[l.slice(4)]=t:t==null||t===!1?n.removeAttribute(l):n.setAttribute(l,t===!0?"":t))}},ue=(e,n,i)=>{if(n.contains?.(document.activeElement)){const l=n.nextSibling;for(;i&&i!=n;){const t=i.nextSibling;e.insertBefore(i,l),i=t}}else e.insertBefore(n,i)},p=()=>c.$hooks??=[0,[]],E=(e,n,i)=>{const l=m(),t=p(),[r,a]=t;r==a.length?(l[i]??=new Set).add(a[r]=[null,e,n]):(n==null||w(n,a[r][2]))&&(a[r][1]=e,a[r][2]=n),t[0]++},j=e=>{if(!e.$idleId){if(globalThis.navigator?.scheduling?.isInputPending()){e.$idle||(e.$idle=!0,b++),e.$idleId=requestIdleCallback(()=>{e.$idleId=null,j(e)});return}M(e)}},oe=e=>{e.$queued||(e.$queued=!0,F(()=>{e.$queued=!1,M(e)}))},M=e=>{e.$idleId&&(cancelIdleCallback(e.$idleId),e.$idleId=null,e.$idle=!1,b--),c=e,c.$hooks&&(c.$hooks[0]=0);try{e.$h=e.$fn(e.$args)}catch(n){g(n,e.parentNode)}finally{if(c=null,$.add(e),e.$idle&&(e.$idle=!1,--b))return;L??=T(fe)}},fe=()=>{L=null;for(const e of $){$.delete(e);try{N(e.$h,e),e.$h=null}catch(n){g(n,e)}finally{B(e,"$layout"),y.add(e),O??=T(ce)}}},ce=()=>{O=null;for(const e of y)y.delete(e),B(e,"$effect")},B=(e,n)=>{if(e[n])for(const i of e[n]){const[l,t]=i;if(o(t))try{o(l)&&l(),i[0]=t()}catch(r){i[0]=null,g(r,e.parentNode)}finally{i[1]=null}}},H=e=>{if(e.nodeType==1){for(const n of e.children)H(n);if(e.$ref&&(e.$ref.current=null),!!e.$fn){$.delete(e),y.delete(e);for(const n of["$layout","$effect"])if(e[n])for(const i of e[n]){e[n].delete(i);try{const[l]=i;o(l)&&l()}catch(l){g(l,e.parentNode)}finally{i[0]=i[1]=null}}}}},g=(e,n)=>{for(let i;n;n=n.parentNode)if(o(i=n.$catch))return void i(e);throw e};let b=0,$=new Set,y=new Set,L=null,O=null,c=null;return G(se);})();
1
+ var ajo=(()=>{var x=Object.defineProperty;var V=Object.getOwnPropertyDescriptor;var W=Object.getOwnPropertyNames;var D=Object.prototype.hasOwnProperty;var G=(e,t)=>{for(var u in t)x(e,u,{get:t[u],enumerable:!0})},J=(e,t,u,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let l of W(t))!D.call(e,l)&&l!==u&&x(e,l,{get:()=>t[l],enumerable:!(n=V(t,l))||n.enumerable});return e};var K=e=>J(x({},"__esModule",{value:!0}),e);var $e={};G($e,{Fragment:()=>U,component:()=>X,h:()=>F,render:()=>N,useCallback:()=>h,useCatch:()=>Y,useEffect:()=>te,useHost:()=>p,useLayout:()=>ee,useMemo:()=>S,useReducer:()=>Q,useRef:()=>_,useState:()=>Z});const U=({children:e})=>e,F=(e,t,...u)=>{const{length:n}=u;return u=n==0?null:n==1?u[0]:u,{children:u,...t,nodeName:e}},N=(e,t,u)=>{let n=t.firstChild;for(e of b(e)){let l=n;if(e instanceof Node)l=e;else if(typeof e=="string"){for(;l&&l.nodeType!=3;)l=l.nextSibling;l?l.data!=e&&(l.data=e):l=document.createTextNode(e)}else{const{xmlns:a=u,nodeName:r,key:i,ref:o,memo:v,children:z,[T]:A,...P}=e;for(;l&&!(l.localName==r&&$(l.$key??=i,i));)l=l.nextSibling;l??=re(a,r,i),ne(o)&&(o.current=l,l.$ref=o),(v==null||w(l.$deps,l.$deps=v))&&(ie(P,l),f(A)?A(l):N(z,l,a))}l==n?n=n.nextSibling:fe(t,l,n)}for(;n;){const l=n.nextSibling;H(n),t.removeChild(n),n=l}},X=e=>({nodeName:t,as:u,props:n,key:l,ref:a,memo:r,...i})=>F(u??e?.as??"c-host",{...e?.props,...n,key:l,ref:a,memo:r,[T]:o=>{o.$fn=f(e)?e:le,o.$args={...e?.args,...i},q(o)}}),Q=(e,t)=>{const u=p(),n=g(),[l,a]=n;return l==a.length&&(a[l]=[f(t)?t():t,r=>{const i=a[l][0],o=f(r)?r(i):r;$(i,a[l][0]=f(e)?e(i,o):o)||ce(u)}]),a[n[0]++]},S=(e,t)=>{const u=g(),[n,l]=u;return(n==l.length||t==null||w(t,l[n][1]))&&(l[n]=[e(),t]),l[u[0]++][0]},Y=e=>{const t=p(),[u,n]=Q(),l=g(),[a,r]=l;return r[l[0]++]=e,t.$catch??=i=>{f(r[a])&&r[a](i),n(i)},[u,()=>n()]},p=()=>c,Z=e=>Q(null,e),_=e=>S(()=>({current:e}),[]),h=(e,t)=>S(()=>e,t),ee=(e,t)=>j(e,t,"$layout"),te=(e,t)=>j(e,t,"$effect"),{isArray:s,from:I}=Array,{is:$}=Object,le=()=>{},T=Symbol(),ne=e=>e&&typeof e=="object",f=e=>typeof e=="function",w=(e,t)=>s(e)&&s(t)?e.some((u,n)=>!$(u,t[n])):!$(e,t),ue=e=>I(e).reduce(ae,{}),ae=(e,{name:t,value:u})=>(e[t]=u,e),C=globalThis.queueMicrotask??(e=>e()),E=globalThis.requestAnimationFrame??C,re=(e,t,u)=>{const n=e?document.createElementNS(e,t):document.createElement(t);return n.$key=u,n},b=function*(e,t={data:""},u=!0){let n;for(e of s(e)?e:[e])e==null||typeof e=="boolean"||(typeof e.nodeName=="string"?((n=t.data)&&(t.data="",yield n),yield e):f(e.nodeName)?yield*b(e.nodeName(e),t,!1):s(e)?yield*b(e,t,!1):t.data+=e);u&&(n=t.data)&&(yield n)},ie=(e,t)=>{const u=t.$props??=t.hasAttributes()?ue(t.attributes):{};for(const n in{...u,...t.$props=e}){let l=e[n];l!==u[n]&&(n.startsWith("set:")?t[n.slice(4)]=l:l==null||l===!1?t.removeAttribute(n):t.setAttribute(n,l===!0?"":l))}},fe=(e,t,u)=>{if(t.contains?.(document.activeElement)){const n=t.nextSibling;for(;u&&u!=t;){const l=u.nextSibling;e.insertBefore(u,n),u=l}}else e.insertBefore(t,u)},g=()=>c.$hooks??=[0,[]],j=(e,t,u)=>{const n=p(),l=g(),[a,r]=l;a==r.length?(n[u]??=new Set).add(r[a]=[null,e,t]):(t==null||w(t,r[a][2]))&&(r[a][1]=e,r[a][2]=t),l[0]++},q=e=>{if(!e.$idle){if(globalThis.navigator?.scheduling?.isInputPending()){d.add(e),e.$idle=!0,R??=requestIdleCallback(oe);return}M(e)}},M=e=>{e.$idle&&(d.delete(e),e.$idle=!1),c=e,c.$hooks&&(c.$hooks[0]=0);try{e.$h=e.$fn(e.$args)}catch(t){k(t,e.parentNode)}finally{c=null,y.add(e),e.$layoutQueued=!0,L??=E(de)}},oe=()=>{R=null;for(const e of I(d))d.delete(e),e.$idle=!1,q(e)},ce=e=>{e.$runQueued||(e.$runQueued=!0,C(()=>{e.$runQueued=!1,M(e)}))},de=()=>{L=null;for(const e of y){y.delete(e),e.$layoutQueued=!1;try{N(e.$h,e),e.$h=null}catch(t){k(t,e)}finally{B(e,"$layout"),m.add(e),e.$effectQueued=!0,O??=E(se)}}},se=()=>{O=null;for(const e of m)m.delete(e),e.$effectQueued=!1,B(e,"$effect")},B=(e,t)=>{if(e[t])for(const u of e[t]){const[n,l]=u;if(f(l))try{f(n)&&n(),u[0]=l()}catch(a){u[0]=null,k(a,e.parentNode)}finally{u[1]=null}}},H=e=>{if(e.nodeType==1){for(const t of e.children)H(t);if(e.$ref&&(e.$ref.current=null),!!e.$fn){e.$idle&&(d.delete(e),e.$idle=!1),e.$layoutQueued&&(y.delete(e),e.$layoutQueued=!1),e.$effectQueued&&(m.delete(e),e.$effectQueued=!1);for(const t of["$layout","$effect"])if(e[t])for(const u of e[t]){e[t].delete(u);try{const[n]=u;f(n)&&n()}catch(n){k(n,e.parentNode)}finally{u[0]=u[1]=null}}}}},k=(e,t)=>{for(let u;t;t=t.parentNode)if(f(u=t.$catch))return void u(e);throw e};let c=null,y=new Set,m=new Set,d=new Set,L=null,O=null,R=null;return K($e);})();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ajo",
3
- "version": "0.0.23",
3
+ "version": "0.0.25",
4
4
  "description": "ajo is a JavaScript view library for building user interfaces",
5
5
  "type": "module",
6
6
  "module": "index.js",