ajo 0.0.19 → 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 +8 -17
- package/index.js +9 -21
- package/index.min.js +1 -1
- package/package.json +2 -2
package/index.cjs
CHANGED
|
@@ -92,21 +92,16 @@ 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
|
|
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;
|
|
@@ -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
|
|
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 = () => { },
|
|
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
|
|
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',
|
|
@@ -142,9 +134,7 @@ const
|
|
|
142
134
|
|
|
143
135
|
let value = props[name]
|
|
144
136
|
|
|
145
|
-
if (name
|
|
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
|
|
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.
|
|
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.
|
|
41
|
+
"esbuild": "^0.15.9",
|
|
42
42
|
"uvu": "^0.5.6"
|
|
43
43
|
}
|
|
44
44
|
}
|