ajo 0.0.18 → 0.0.20

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
@@ -92,29 +92,24 @@ const Fragment = ({ children }) => children, For = ({ is, each, by, children, re
92
92
  throw error;
93
93
  }, cleanup = (host, fn) => isFunction(fn) && (host.$cleanups ??= /* @__PURE__ */ new Set()).add(fn), clx = (o) => keys(o).filter((k) => o[k]).join(" ") || null, stx = (o) => entries(o).map((t) => t.join(":")).join(";") || null, keb = (o) => keys(o).reduce((r, k) => (r[k.replace(search, replace).toLowerCase()] = o[k], r), {});
94
94
  const { isArray, from } = Array, { keys, entries } = Object, isFunction = (v) => typeof v == "function", noop = () => {
95
- }, on = (host, type, v) => {
96
- let fn, map2;
97
- if (fn = (map2 = host.$on ??= {})[type]) {
98
- host.removeEventListener(type, fn, fn.options), map2[type] = null;
99
- }
100
- if (typeof (fn = (v = isArray(v) ? v : [v])[0]) == "function") {
101
- host.addEventListener(type, fn = map2[type] = fn.bind(null, v[1]), fn.options = v[2]);
102
- }
103
95
  }, map = (list) => list.reduce(set, /* @__PURE__ */ new Map()), set = (m, v, i) => (m.set(v, i), m), some = (a, b) => isArray(a) && isArray(b) ? a.some((v, i) => v !== b[i]) : a !== b, reduce = (v) => from(v).reduce(assign, {}), assign = (v, { name, value }) => (v[name] = value, v), create = (ns, name, key) => {
104
96
  const node = ns ? document.createElementNS(ns, name) : document.createElement(name);
105
97
  return node.$key = key, node;
106
98
  }, proxy = { firstChild: null, insertBefore: (node) => proxy.firstChild ??= node }, handler = {
107
99
  get(target, key) {
108
- const value = key == "nextSibling" ? null : target[key];
100
+ const value = key == "nextSibling" ? null : Reflect.get(target, key);
109
101
  return isFunction(value) ? value.bind(target) : value;
102
+ },
103
+ set(target, key, value) {
104
+ return Reflect.set(target, key, value);
110
105
  }
111
106
  }, search = /([a-z0-9])([A-Z])/g, replace = "$1-$2", normalize = function* (h2, buffer = { t: "" }, root = true) {
112
107
  let t;
113
108
  for (h2 of isArray(h2) ? h2 : [h2]) {
114
109
  if (h2 == null || typeof h2 == "boolean")
115
110
  continue;
116
- else if (typeof h2.nodeName == "string")
117
- t = buffer.t && (buffer.t = "", yield t), yield h2;
111
+ if (typeof h2.nodeName == "string")
112
+ (t = buffer.t) && (buffer.t = "", yield t), yield h2;
118
113
  else if (isFunction(h2.nodeName))
119
114
  yield* normalize(h2.nodeName(h2), buffer, false);
120
115
  else
@@ -125,9 +120,7 @@ const { isArray, from } = Array, { keys, entries } = Object, isFunction = (v) =>
125
120
  const prev = host.$props ??= host.hasAttributes() ? reduce(host.attributes) : {};
126
121
  for (const name in { ...prev, ...host.$props = props }) {
127
122
  let value = props[name];
128
- if (name.startsWith("on:")) {
129
- some(value, prev[name]) && on(host, name.slice(3), value);
130
- } else if (value !== prev[name])
123
+ if (value !== prev[name])
131
124
  if (name.startsWith("set:"))
132
125
  host[name.slice(4)] = value;
133
126
  else if (value == null || value === false)
@@ -155,7 +148,7 @@ const { isArray, from } = Array, { keys, entries } = Object, isFunction = (v) =>
155
148
  const item = each[index], key = by(item, index);
156
149
  child = clr ? a[index] : map2.get(key);
157
150
  proxy.firstChild = child ? new Proxy(child, handler) : null;
158
- render(fn(item), proxy);
151
+ render(fn(item, index), proxy);
159
152
  child ??= proxy.firstChild;
160
153
  proxy.firstChild = null;
161
154
  map2.set(child.$by = key, b[index] = child);
@@ -166,8 +159,7 @@ const { isArray, from } = Array, { keys, entries } = Object, isFunction = (v) =>
166
159
  const aLen = a.length, bLen = b.length;
167
160
  let aIndex = 0, bIndex = 0, aValue, bValue, aMap, bMap, i;
168
161
  while (aIndex !== aLen || bIndex !== bLen) {
169
- aValue = a[aIndex];
170
- bValue = b[bIndex];
162
+ aValue = a[aIndex], bValue = b[bIndex];
171
163
  if (aValue === null)
172
164
  aIndex++;
173
165
  else if (bLen <= bIndex)
@@ -177,8 +169,7 @@ const { isArray, from } = Array, { keys, entries } = Object, isFunction = (v) =>
177
169
  else if (aValue === bValue)
178
170
  aIndex++, bIndex++;
179
171
  else {
180
- aMap ??= map(a);
181
- bMap ??= map(b);
172
+ aMap ??= map(a), bMap ??= map(b);
182
173
  if (bMap.get(aValue) == null)
183
174
  aIndex++, dispose2(host.removeChild(aValue));
184
175
  else {
package/index.js CHANGED
@@ -87,18 +87,7 @@ export const
87
87
  const
88
88
  { isArray, from } = Array, { keys, entries } = Object,
89
89
 
90
- isFunction = v => typeof v == 'function', noop = () => { }, on = (host, type, v) => {
91
-
92
- let fn, map
93
-
94
- if (fn = (map = host.$on ??= {})[type]) {
95
- host.removeEventListener(type, fn, fn.options), map[type] = null
96
- }
97
-
98
- if (typeof (fn = (v = isArray(v) ? v : [v])[0]) == 'function') {
99
- host.addEventListener(type, fn = map[type] = fn.bind(null, v[1]), fn.options = v[2])
100
- }
101
- },
90
+ isFunction = v => typeof v == 'function', noop = () => { },
102
91
 
103
92
  map = list => list.reduce(set, new Map), set = (m, v, i) => (m.set(v, i), m),
104
93
 
@@ -113,9 +102,12 @@ const
113
102
 
114
103
  proxy = { firstChild: null, insertBefore: node => proxy.firstChild ??= node }, handler = {
115
104
  get(target, key) {
116
- const value = key == 'nextSibling' ? null : target[key]
105
+ const value = key == 'nextSibling' ? null : Reflect.get(target, key)
117
106
  return isFunction(value) ? value.bind(target) : value
118
107
  },
108
+ set(target, key, value) {
109
+ return Reflect.set(target, key, value)
110
+ }
119
111
  },
120
112
 
121
113
  search = /([a-z0-9])([A-Z])/g, replace = '$1-$2',
@@ -126,7 +118,7 @@ const
126
118
 
127
119
  for (h of isArray(h) ? h : [h]) {
128
120
  if (h == null || typeof h == 'boolean') continue
129
- else if (typeof h.nodeName == 'string') (t = buffer.t && (buffer.t = '', yield t)), yield h
121
+ if (typeof h.nodeName == 'string') ((t = buffer.t) && (buffer.t = '', yield t)), yield h
130
122
  else if (isFunction(h.nodeName)) yield* normalize(h.nodeName(h), buffer, false)
131
123
  else isArray(h) ? yield* normalize(h, buffer, false) : buffer.t += h
132
124
  }
@@ -142,9 +134,7 @@ const
142
134
 
143
135
  let value = props[name]
144
136
 
145
- if (name.startsWith('on:')) {
146
- some(value, prev[name]) && on(host, name.slice(3), value)
147
- } else if (value !== prev[name])
137
+ if (value !== prev[name])
148
138
  if (name.startsWith('set:')) host[name.slice(4)] = value
149
139
  else if (value == null || value === false) host.removeAttribute(name)
150
140
  else host.setAttribute(name, value === true ? '' : value)
@@ -188,7 +178,7 @@ const
188
178
  child = (clr ? a[index] : map.get(key))
189
179
 
190
180
  proxy.firstChild = child ? new Proxy(child, handler) : null
191
- render(fn(item), proxy)
181
+ render(fn(item, index), proxy)
192
182
 
193
183
  child ??= proxy.firstChild
194
184
  proxy.firstChild = null
@@ -208,8 +198,7 @@ const
208
198
 
209
199
  while (aIndex !== aLen || bIndex !== bLen) {
210
200
 
211
- aValue = a[aIndex]
212
- bValue = b[bIndex]
201
+ aValue = a[aIndex], bValue = b[bIndex]
213
202
 
214
203
  if (aValue === null) aIndex++
215
204
  else if (bLen <= bIndex) aIndex++, dispose(host.removeChild(aValue))
@@ -217,8 +206,7 @@ const
217
206
  else if (aValue === bValue) aIndex++, bIndex++
218
207
  else {
219
208
 
220
- aMap ??= map(a)
221
- bMap ??= map(b)
209
+ aMap ??= map(a), bMap ??= map(b)
222
210
 
223
211
  if (bMap.get(aValue) == null) aIndex++, dispose(host.removeChild(aValue))
224
212
  else {
package/index.min.js CHANGED
@@ -1 +1 @@
1
- var ajo=(()=>{var x=Object.defineProperty;var L=Object.getOwnPropertyDescriptor;var j=Object.getOwnPropertyNames;var B=Object.prototype.hasOwnProperty;var F=(e,n)=>{for(var i in n)x(e,i,{get:n[i],enumerable:!0})},T=(e,n,i,l)=>{if(n&&typeof n=="object"||typeof n=="function")for(let r of j(n))!B.call(e,r)&&r!==i&&x(e,r,{get:()=>n[r],enumerable:!(l=L(n,r))||l.enumerable});return e};var z=e=>T(x({},"__esModule",{value:!0}),e);var ae={};F(ae,{For:()=>I,Fragment:()=>D,cleanup:()=>P,clx:()=>R,component:()=>O,consume:()=>W,h:()=>b,intercept:()=>q,keb:()=>G,propagate:()=>k,provide:()=>V,refresh:()=>S,render:()=>g,stx:()=>Z});const D=({children:e})=>e,I=({is:e,each:n,by:i,children:l,ref:r,...o})=>b(e??"div",{...o,skip:!0,ref:t=>ie(t,n,i,l,r)}),b=(e,n,...i)=>{const{length:l}=i;return i=l==0?null:l==1?i[0]:i,{children:i,...n,nodeName:e}},g=(e,n,i)=>{let l=n.firstChild;for(e of y(e)){let r=l;if(e instanceof Node)r=e;else if(typeof e=="string"){for(;r&&r.nodeType!=3;)r=r.nextSibling;r?r.data!=e&&(r.data=e):r=document.createTextNode(e)}else{const{xmlns:o=i,nodeName:t,key:s,block:c,skip:f,children:p,ref:a,...d}=e;for(;r&&!(r.localName==t&&(r.$key??=s)==s);)r=r.nextSibling;r??=X(o,t,s),(c==null||E(r.$deps,r.$deps=c))&&(ee(d,r),f||g(p,r,o),u(a)&&a(r))}r==l?l=l.nextSibling:ne(n,r,l)}for(;l;){const r=l.nextSibling;n.removeChild(l),l=r}},O=e=>({is:n,props:i,ref:l,...r})=>b(n??e.is??"div",{...e.props,...i,skip:!0,ref:o=>re(o,e,r,l)}),S=e=>{try{g((e.$render??=e.$setup(e))(e.$params),e)}catch(n){k(e,n)}},V=(e,n,i)=>(e.$provisions??=new Map).set(n,i),W=(e,n,i)=>{for(let l;e;e=e.parentNode)if((l=e.$provisions)&&l.has(n))return l.get(n);return i},q=(e,n)=>u(n)&&(e.$interceptor=n),k=(e,n)=>{for(let i;e;e=e.parentNode)if(u(i=e.$interceptor))return g(i(n),e);throw n},P=(e,n)=>u(n)&&(e.$cleanups??=new Set).add(n),R=e=>M(e).filter(n=>e[n]).join(" ")||null,Z=e=>H(e).map(n=>n.join(":")).join(";")||null,G=e=>M(e).reduce((n,i)=>(n[i.replace(_,h).toLowerCase()]=e[i],n),{}),{isArray:m,from:A}=Array,{keys:M,entries:H}=Object,u=e=>typeof e=="function",w=()=>{},J=(e,n,i)=>{let l,r;(l=(r=e.$on??={})[n])&&(e.removeEventListener(n,l,l.options),r[n]=null),typeof(l=(i=m(i)?i:[i])[0])=="function"&&e.addEventListener(n,l=r[n]=l.bind(null,i[1]),l.options=i[2])},C=e=>e.reduce(K,new Map),K=(e,n,i)=>(e.set(n,i),e),E=(e,n)=>m(e)&&m(n)?e.some((i,l)=>i!==n[l]):e!==n,Q=e=>A(e).reduce(U,{}),U=(e,{name:n,value:i})=>(e[n]=i,e),X=(e,n,i)=>{const l=e?document.createElementNS(e,n):document.createElement(n);return l.$key=i,l},$={firstChild:null,insertBefore:e=>$.firstChild??=e},Y={get(e,n){const i=n=="nextSibling"?null:e[n];return u(i)?i.bind(e):i}},_=/([a-z0-9])([A-Z])/g,h="$1-$2",y=function*(e,n={t:""},i=!0){let l;for(e of m(e)?e:[e])e==null||typeof e=="boolean"||(typeof e.nodeName=="string"?(l=n.t&&(n.t="",yield l),yield e):u(e.nodeName)?yield*y(e.nodeName(e),n,!1):m(e)?yield*y(e,n,!1):n.t+=e);i&&(l=n.t)&&(yield l)},ee=(e,n)=>{const i=n.$props??=n.hasAttributes()?Q(n.attributes):{};for(const l in{...i,...n.$props=e}){let r=e[l];l.startsWith("on:")?E(r,i[l])&&J(n,l.slice(3),r):r!==i[l]&&(l.startsWith("set:")?n[l.slice(4)]=r:r==null||r===!1?n.removeAttribute(l):n.setAttribute(l,r===!0?"":r))}},ne=(e,n,i)=>{if(n.contains?.(document.activeElement)){const l=n.nextSibling;for(;i&&i!=n;){const r=i.nextSibling;e.insertBefore(i,l),i=r}}else e.insertBefore(n,i)},ie=(e,n,i,l,r)=>{n=m(n)?n:[],i=u(i)?i:a=>a,l=u(l)?l:w;const o=e.$for??=new Map,t=a=>o.delete(a.$by),s=n!==e.$each,c=(e.$each=n).length,f=A(e.childNodes),p=new Array(c);s&&o.clear();for(let a,d=0;d<c;d++){const v=n[d],N=i(v,d);a=s?f[d]:o.get(N),$.firstChild=a?new Proxy(a,Y):null,g(l(v),$),a??=$.firstChild,$.firstChild=null,o.set(a.$by=N,p[d]=a)}le(e,f,p,t),u(r)&&r(e)},le=(e,n,i,l=w)=>{const r=n.length,o=i.length;let t=0,s=0,c,f,p,a,d;for(;t!==r||s!==o;)c=n[t],f=i[s],c===null?t++:o<=s?(t++,l(e.removeChild(c))):r<=t?(s++,e.appendChild(f)):c===f?(t++,s++):(p??=C(n),a??=C(i),a.get(c)==null?(t++,l(e.removeChild(c))):(e.insertBefore(f,c),s++,(d=p.get(f))!=null&&(d>t+1&&t++,n[d]=null)))},re=(e,n,i,l)=>{e.$setup??=(e.addEventListener("DOMNodeRemovedFromDocument",te),u(n)?n:w),e.$params={...n.params,...i},S(e),u(l)&&l(e)},te=({target:e})=>{(globalThis.queueMicrotask??(n=>n()))(()=>{if(!document.contains(e)&&"$cleanups"in e)try{for(const n of e.$cleanups)n(e)}finally{e.$cleanups.clear()}})};return z(ae);})();
1
+ var ajo=(()=>{var y=Object.defineProperty;var j=Object.getOwnPropertyDescriptor;var B=Object.getOwnPropertyNames;var E=Object.prototype.hasOwnProperty;var F=(e,n)=>{for(var l in n)y(e,l,{get:n[l],enumerable:!0})},L=(e,n,l,i)=>{if(n&&typeof n=="object"||typeof n=="function")for(let t of B(n))!E.call(e,t)&&t!==l&&y(e,t,{get:()=>n[t],enumerable:!(i=j(n,t))||i.enumerable});return e};var R=e=>L(y({},"__esModule",{value:!0}),e);var re={};F(re,{For:()=>z,Fragment:()=>T,cleanup:()=>q,clx:()=>P,component:()=>D,consume:()=>O,h:()=>v,intercept:()=>V,keb:()=>Z,propagate:()=>k,provide:()=>I,refresh:()=>S,render:()=>g,stx:()=>W});const T=({children:e})=>e,z=({is:e,each:n,by:l,children:i,ref:t,...o})=>v(e??"div",{...o,skip:!0,ref:r=>ne(r,n,l,i,t)}),v=(e,n,...l)=>{const{length:i}=l;return l=i==0?null:i==1?l[0]:l,{children:l,...n,nodeName:e}},g=(e,n,l)=>{let i=n.firstChild;for(e of x(e)){let t=i;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:o=l,nodeName:r,key:s,block:c,skip:u,children:f,ref:a,...d}=e;for(;t&&!(t.localName==r&&(t.$key??=s)==s);)t=t.nextSibling;t??=U(o,r,s),(c==null||J(t.$deps,t.$deps=c))&&(h(d,t),u||g(f,t,o),p(a)&&a(t))}t==i?i=i.nextSibling:ee(n,t,i)}for(;i;){const t=i.nextSibling;n.removeChild(i),i=t}},D=e=>({is:n,props:l,ref:i,...t})=>v(n??e.is??"div",{...e.props,...l,skip:!0,ref:o=>ie(o,e,t,i)}),S=e=>{try{g((e.$render??=e.$setup(e))(e.$params),e)}catch(n){k(e,n)}},I=(e,n,l)=>(e.$provisions??=new Map).set(n,l),O=(e,n,l)=>{for(let i;e;e=e.parentNode)if((i=e.$provisions)&&i.has(n))return i.get(n);return l},V=(e,n)=>p(n)&&(e.$interceptor=n),k=(e,n)=>{for(let l;e;e=e.parentNode)if(p(l=e.$interceptor))return g(l(n),e);throw n},q=(e,n)=>p(n)&&(e.$cleanups??=new Set).add(n),P=e=>M(e).filter(n=>e[n]).join(" ")||null,W=e=>G(e).map(n=>n.join(":")).join(";")||null,Z=e=>M(e).reduce((n,l)=>(n[l.replace(Y,_).toLowerCase()]=e[l],n),{}),{isArray:$,from:A}=Array,{keys:M,entries:G}=Object,p=e=>typeof e=="function",b=()=>{},C=e=>e.reduce(H,new Map),H=(e,n,l)=>(e.set(n,l),e),J=(e,n)=>$(e)&&$(n)?e.some((l,i)=>l!==n[i]):e!==n,K=e=>A(e).reduce(Q,{}),Q=(e,{name:n,value:l})=>(e[n]=l,e),U=(e,n,l)=>{const i=e?document.createElementNS(e,n):document.createElement(n);return i.$key=l,i},m={firstChild:null,insertBefore:e=>m.firstChild??=e},X={get(e,n){const l=n=="nextSibling"?null:Reflect.get(e,n);return p(l)?l.bind(e):l},set(e,n,l){return Reflect.set(e,n,l)}},Y=/([a-z0-9])([A-Z])/g,_="$1-$2",x=function*(e,n={t:""},l=!0){let i;for(e of $(e)?e:[e])e==null||typeof e=="boolean"||(typeof e.nodeName=="string"?((i=n.t)&&(n.t="",yield i),yield e):p(e.nodeName)?yield*x(e.nodeName(e),n,!1):$(e)?yield*x(e,n,!1):n.t+=e);l&&(i=n.t)&&(yield i)},h=(e,n)=>{const l=n.$props??=n.hasAttributes()?K(n.attributes):{};for(const i in{...l,...n.$props=e}){let t=e[i];t!==l[i]&&(i.startsWith("set:")?n[i.slice(4)]=t:t==null||t===!1?n.removeAttribute(i):n.setAttribute(i,t===!0?"":t))}},ee=(e,n,l)=>{if(n.contains?.(document.activeElement)){const i=n.nextSibling;for(;l&&l!=n;){const t=l.nextSibling;e.insertBefore(l,i),l=t}}else e.insertBefore(n,l)},ne=(e,n,l,i,t)=>{n=$(n)?n:[],l=p(l)?l:a=>a,i=p(i)?i:b;const o=e.$for??=new Map,r=a=>o.delete(a.$by),s=n!==e.$each,c=(e.$each=n).length,u=A(e.childNodes),f=new Array(c);s&&o.clear();for(let a,d=0;d<c;d++){const w=n[d],N=l(w,d);a=s?u[d]:o.get(N),m.firstChild=a?new Proxy(a,X):null,g(i(w,d),m),a??=m.firstChild,m.firstChild=null,o.set(a.$by=N,f[d]=a)}le(e,u,f,r),p(t)&&t(e)},le=(e,n,l,i=b)=>{const t=n.length,o=l.length;let r=0,s=0,c,u,f,a,d;for(;r!==t||s!==o;)c=n[r],u=l[s],c===null?r++:o<=s?(r++,i(e.removeChild(c))):t<=r?(s++,e.appendChild(u)):c===u?(r++,s++):(f??=C(n),a??=C(l),a.get(c)==null?(r++,i(e.removeChild(c))):(e.insertBefore(u,c),s++,(d=f.get(u))!=null&&(d>r+1&&r++,n[d]=null)))},ie=(e,n,l,i)=>{e.$setup??=(e.addEventListener("DOMNodeRemovedFromDocument",te),p(n)?n:b),e.$params={...n.params,...l},S(e),p(i)&&i(e)},te=({target:e})=>{(globalThis.queueMicrotask??(n=>n()))(()=>{if(!document.contains(e)&&"$cleanups"in e)try{for(const n of e.$cleanups)n(e)}finally{e.$cleanups.clear()}})};return R(re);})();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ajo",
3
- "version": "0.0.18",
3
+ "version": "0.0.20",
4
4
  "description": "ajo is a JavaScript view library for building user interfaces",
5
5
  "type": "module",
6
6
  "module": "index.js",
@@ -38,7 +38,7 @@
38
38
  "homepage": "https://github.com/cristianfalcone/ajo#readme",
39
39
  "devDependencies": {
40
40
  "backdom": "^0.0.8",
41
- "esbuild": "^0.15.7",
41
+ "esbuild": "^0.15.9",
42
42
  "uvu": "^0.5.6"
43
43
  }
44
44
  }