ajo 0.1.10 → 0.1.11
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/index.cjs +1 -1
- package/dist/index.js +78 -87
- package/package.json +1 -1
- package/readme.md +3 -3
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const{isArray:
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const{isArray:p,prototype:{slice:k}}=Array,{keys:A,assign:w,hasOwn:O,setPrototypeOf:$,getPrototypeOf:h}=Object,x=e=>typeof e!="string"&&typeof(e==null?void 0:e[Symbol.iterator])=="function",C=({children:e})=>e,F=function(e,t){const{length:n}=arguments;return(t??(t={})).nodeName=e,"children"in t||n<3||(t.children=n===3?arguments[2]:k.call(arguments,2)),t},a=(e,t)=>{let n=t.firstChild;for(e of d(e)){let i=n;if(typeof e=="string"){for(;i&&i.nodeType!=3;)i=i.nextSibling;i?i.data!=e&&(i.data=e):i=document.createTextNode(e)}else if(e instanceof Node)i=e;else{const{nodeName:o,key:c,skip:N,memo:m,ref:y,children:b}=e;for(;i&&!(i.localName===o&&(i.$key??(i.$key=c))==c);)i=i.nextSibling;if(i??(i=w(document.createElementNS(e.xmlns??o==="svg"?"http://www.w3.org/2000/svg":t.namespaceURI,o),{$key:c})),m==null||P(i.$memo,i.$memo=m)){const{$props:f}=i,g={};let u;for(const s in w({},f,e)){if(j.has(s))continue;if(s.startsWith("arg:")){(u??(u={}))[s.slice(4)]=e[s];continue}const l=g[s]=e[s];l!==(f==null?void 0:f[s])&&(s.startsWith("set:")?i[s.slice(4)]=l:l==null||l===!1?i.removeAttribute(s):i.setAttribute(s,l===!0?"":l))}u&&(i.$args=u),i.$props=g,N||a(b,i),typeof y=="function"&&(i.$ref=y)(i)}}i===n?n=n.nextSibling:B(t,i,n)}for(;n;){const i=n.nextSibling;n.nodeType===1&&S(n),t.removeChild(n),n=i}},d=function*(e,t={value:""},n=!0){for(e of x(e)?e:[e])if(!(e==null||typeof e=="boolean"))if(O(e,"nodeName")){const{value:i}=t,{nodeName:o}=e,c=typeof o;i&&(yield i,t.value=""),c==="function"?o.constructor.name==="GeneratorFunction"?(e.nodeName=o.is??"div",e.skip=!0,e.ref=T.bind(null,o,e.ref),"children"in e&&(e["arg:children"]=e.children,delete e.children),yield e):(delete e.nodeName,yield*d(o(e),t,!1)):c==="string"&&(yield e)}else x(e)?yield*d(e,t,!1):t.value+=e;n&&t.value&&(yield t.value)},T=(e,t,n)=>{n&&(n.$gen??(n.$gen=(new E(n),e)),n.$ref=q.bind(null,n,t),n.next())},q=(e,t,n)=>{n||e.return(),typeof t=="function"&&t(n)},P=(e,t)=>p(e)&&p(t)?e.some((n,i)=>n!==t[i]):e!==t,j=new Set("nodeName,key,skip,memo,ref,children".split(",")),B=(e,t,n)=>{if(t.contains(document.activeElement)){const i=t.nextSibling;for(;n&&n!=t;){const o=n.nextSibling;e.insertBefore(n,i),n=o}}else e.insertBefore(t,n)},S=e=>{for(const n of e.children)S(n);const{$ref:t}=e;typeof t=="function"&&t(null);for(const n of A(e))e[n]=null};class E{constructor(t){$(t,$(h(this),h(t)))}*[Symbol.iterator](){for(;;)yield this.$args??{}}refresh(){I(this)}next(){try{a((this.$it??(this.$it=this.$gen.call(this,this.$args??{}))).next().value,this),typeof this.$ref=="function"&&this.$ref(this)}catch(t){this.throw(t)}}throw(t){var n;for(let i=this;i;i=i.parentNode)if(typeof((n=i.$it)==null?void 0:n.throw)=="function")try{return a(i.$it.throw(t).value,i)}catch{}throw t}return(){var t;try{(t=this.$it)==null||t.return()}catch(n){this.throw(n)}finally{this.$it=null}}}let r,v;const I=e=>{(r??(r=new Set)).has(e)&&r.delete(e);for(const t of r){if(t.contains(e))return;e.contains(t)&&r.delete(t)}r.add(e),v??(v=requestAnimationFrame(W))},W=()=>{for(const e of r)e.isConnected&&e.next();r.clear(),v=null};exports.Fragment=C;exports.h=F;exports.render=a;
|
package/dist/index.js
CHANGED
|
@@ -1,136 +1,127 @@
|
|
|
1
|
-
const { isArray:
|
|
2
|
-
const { length:
|
|
3
|
-
return (
|
|
4
|
-
},
|
|
5
|
-
let
|
|
1
|
+
const { isArray: p, prototype: { slice: b } } = Array, { keys: A, assign: w, hasOwn: C, setPrototypeOf: $, getPrototypeOf: x } = Object, h = (e) => typeof e != "string" && typeof (e == null ? void 0 : e[Symbol.iterator]) == "function", W = ({ children: e }) => e, j = function(e, t) {
|
|
2
|
+
const { length: n } = arguments;
|
|
3
|
+
return (t ?? (t = {})).nodeName = e, "children" in t || n < 3 || (t.children = n === 3 ? arguments[2] : b.call(arguments, 2)), t;
|
|
4
|
+
}, u = (e, t) => {
|
|
5
|
+
let n = t.firstChild;
|
|
6
6
|
for (e of d(e)) {
|
|
7
|
-
let
|
|
7
|
+
let i = n;
|
|
8
8
|
if (typeof e == "string") {
|
|
9
|
-
for (;
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
for (; i && i.nodeType != 3; )
|
|
10
|
+
i = i.nextSibling;
|
|
11
|
+
i ? i.data != e && (i.data = e) : i = document.createTextNode(e);
|
|
12
12
|
} else if (e instanceof Node)
|
|
13
|
-
|
|
13
|
+
i = e;
|
|
14
14
|
else {
|
|
15
|
-
const { nodeName: o, key: c, skip:
|
|
16
|
-
for (;
|
|
17
|
-
|
|
18
|
-
if (
|
|
19
|
-
const { $props:
|
|
20
|
-
|
|
21
|
-
|
|
15
|
+
const { nodeName: o, key: c, skip: S, memo: m, ref: y, children: k } = e;
|
|
16
|
+
for (; i && !(i.localName === o && (i.$key ?? (i.$key = c)) == c); )
|
|
17
|
+
i = i.nextSibling;
|
|
18
|
+
if (i ?? (i = w(document.createElementNS(e.xmlns ?? o === "svg" ? "http://www.w3.org/2000/svg" : t.namespaceURI, o), { $key: c })), m == null || F(i.$memo, i.$memo = m)) {
|
|
19
|
+
const { $props: f } = i, g = {};
|
|
20
|
+
let a;
|
|
21
|
+
for (const s in w({}, f, e)) {
|
|
22
|
+
if (T.has(s))
|
|
22
23
|
continue;
|
|
23
24
|
if (s.startsWith("arg:")) {
|
|
24
|
-
|
|
25
|
+
(a ?? (a = {}))[s.slice(4)] = e[s];
|
|
25
26
|
continue;
|
|
26
27
|
}
|
|
27
28
|
const l = g[s] = e[s];
|
|
28
|
-
l !== (
|
|
29
|
+
l !== (f == null ? void 0 : f[s]) && (s.startsWith("set:") ? i[s.slice(4)] = l : l == null || l === !1 ? i.removeAttribute(s) : i.setAttribute(s, l === !0 ? "" : l));
|
|
29
30
|
}
|
|
30
|
-
|
|
31
|
+
a && (i.$args = a), i.$props = g, S || u(k, i), typeof y == "function" && (i.$ref = y)(i);
|
|
31
32
|
}
|
|
32
33
|
}
|
|
33
|
-
|
|
34
|
+
i === n ? n = n.nextSibling : B(t, i, n);
|
|
34
35
|
}
|
|
35
|
-
for (;
|
|
36
|
-
const
|
|
37
|
-
|
|
36
|
+
for (; n; ) {
|
|
37
|
+
const i = n.nextSibling;
|
|
38
|
+
n.nodeType === 1 && N(n), t.removeChild(n), n = i;
|
|
38
39
|
}
|
|
39
|
-
}, d = function* (e,
|
|
40
|
+
}, d = function* (e, t = { value: "" }, n = !0) {
|
|
40
41
|
for (e of h(e) ? e : [e])
|
|
41
42
|
if (!(e == null || typeof e == "boolean"))
|
|
42
|
-
if (
|
|
43
|
-
const { value:
|
|
44
|
-
|
|
45
|
-
if (o.constructor.name === "GeneratorFunction") {
|
|
46
|
-
const { is: a = o.is ?? "div", ref: f } = e;
|
|
47
|
-
e.nodeName = a, delete e.is, e.skip = !0, e.ref = T.bind(null, o, a, f), "children" in e && (e["arg:children"] = e.children, delete e.children), yield e;
|
|
48
|
-
} else
|
|
49
|
-
delete e.nodeName, yield* d(o(e), n, !1);
|
|
50
|
-
else
|
|
51
|
-
c === "string" && (yield e);
|
|
43
|
+
if (C(e, "nodeName")) {
|
|
44
|
+
const { value: i } = t, { nodeName: o } = e, c = typeof o;
|
|
45
|
+
i && (yield i, t.value = ""), c === "function" ? o.constructor.name === "GeneratorFunction" ? (e.nodeName = o.is ?? "div", e.skip = !0, e.ref = O.bind(null, o, e.ref), "children" in e && (e["arg:children"] = e.children, delete e.children), yield e) : (delete e.nodeName, yield* d(o(e), t, !1)) : c === "string" && (yield e);
|
|
52
46
|
} else
|
|
53
|
-
h(e) ? yield* d(e,
|
|
54
|
-
|
|
55
|
-
},
|
|
56
|
-
|
|
57
|
-
},
|
|
58
|
-
|
|
59
|
-
},
|
|
60
|
-
if (
|
|
61
|
-
const
|
|
62
|
-
for (;
|
|
63
|
-
const o =
|
|
64
|
-
e.insertBefore(
|
|
47
|
+
h(e) ? yield* d(e, t, !1) : t.value += e;
|
|
48
|
+
n && t.value && (yield t.value);
|
|
49
|
+
}, O = (e, t, n) => {
|
|
50
|
+
n && (n.$gen ?? (n.$gen = (new E(n), e)), n.$ref = q.bind(null, n, t), n.next());
|
|
51
|
+
}, q = (e, t, n) => {
|
|
52
|
+
n || e.return(), typeof t == "function" && t(n);
|
|
53
|
+
}, F = (e, t) => p(e) && p(t) ? e.some((n, i) => n !== t[i]) : e !== t, T = new Set("nodeName,key,skip,memo,ref,children".split(",")), B = (e, t, n) => {
|
|
54
|
+
if (t.contains(document.activeElement)) {
|
|
55
|
+
const i = t.nextSibling;
|
|
56
|
+
for (; n && n != t; ) {
|
|
57
|
+
const o = n.nextSibling;
|
|
58
|
+
e.insertBefore(n, i), n = o;
|
|
65
59
|
}
|
|
66
60
|
} else
|
|
67
|
-
e.insertBefore(
|
|
68
|
-
},
|
|
69
|
-
for (const
|
|
70
|
-
|
|
71
|
-
const { $ref:
|
|
72
|
-
typeof
|
|
73
|
-
for (const
|
|
74
|
-
e[
|
|
61
|
+
e.insertBefore(t, n);
|
|
62
|
+
}, N = (e) => {
|
|
63
|
+
for (const n of e.children)
|
|
64
|
+
N(n);
|
|
65
|
+
const { $ref: t } = e;
|
|
66
|
+
typeof t == "function" && t(null);
|
|
67
|
+
for (const n of A(e))
|
|
68
|
+
e[n] = null;
|
|
75
69
|
};
|
|
76
|
-
class
|
|
77
|
-
constructor(
|
|
78
|
-
|
|
70
|
+
class E {
|
|
71
|
+
constructor(t) {
|
|
72
|
+
$(t, $(x(this), x(t)));
|
|
79
73
|
}
|
|
80
74
|
*[Symbol.iterator]() {
|
|
81
75
|
for (; ; )
|
|
82
|
-
yield this.$args;
|
|
76
|
+
yield this.$args ?? {};
|
|
83
77
|
}
|
|
84
78
|
refresh() {
|
|
85
|
-
|
|
79
|
+
I(this);
|
|
86
80
|
}
|
|
87
81
|
next() {
|
|
88
82
|
try {
|
|
89
|
-
|
|
90
|
-
} catch (
|
|
91
|
-
this.throw(
|
|
83
|
+
u((this.$it ?? (this.$it = this.$gen.call(this, this.$args ?? {}))).next().value, this), typeof this.$ref == "function" && this.$ref(this);
|
|
84
|
+
} catch (t) {
|
|
85
|
+
this.throw(t);
|
|
92
86
|
}
|
|
93
87
|
}
|
|
94
|
-
throw(
|
|
95
|
-
var
|
|
96
|
-
for (let
|
|
97
|
-
if (typeof ((
|
|
88
|
+
throw(t) {
|
|
89
|
+
var n;
|
|
90
|
+
for (let i = this; i; i = i.parentNode)
|
|
91
|
+
if (typeof ((n = i.$it) == null ? void 0 : n.throw) == "function")
|
|
98
92
|
try {
|
|
99
|
-
return
|
|
93
|
+
return u(i.$it.throw(t).value, i);
|
|
100
94
|
} catch {
|
|
101
95
|
}
|
|
102
|
-
throw
|
|
96
|
+
throw t;
|
|
103
97
|
}
|
|
104
98
|
return() {
|
|
105
|
-
var
|
|
99
|
+
var t;
|
|
106
100
|
try {
|
|
107
|
-
(
|
|
108
|
-
} catch (
|
|
109
|
-
this.throw(
|
|
101
|
+
(t = this.$it) == null || t.return();
|
|
102
|
+
} catch (n) {
|
|
103
|
+
this.throw(n);
|
|
110
104
|
} finally {
|
|
111
105
|
this.$it = null;
|
|
112
106
|
}
|
|
113
107
|
}
|
|
114
108
|
}
|
|
115
|
-
let
|
|
116
|
-
const
|
|
117
|
-
let i = (N ?? (N = /* @__PURE__ */ new Map())).get(n);
|
|
118
|
-
return i || ({ constructor: i } = document.createElementNS(e.namespaceURI, n), N.set(n, i === HTMLUnknownElement ? i = HTMLElement : i)), i;
|
|
119
|
-
}, U = (e) => {
|
|
109
|
+
let r, v;
|
|
110
|
+
const I = (e) => {
|
|
120
111
|
(r ?? (r = /* @__PURE__ */ new Set())).has(e) && r.delete(e);
|
|
121
|
-
for (const
|
|
122
|
-
if (
|
|
112
|
+
for (const t of r) {
|
|
113
|
+
if (t.contains(e))
|
|
123
114
|
return;
|
|
124
|
-
e.contains(
|
|
115
|
+
e.contains(t) && r.delete(t);
|
|
125
116
|
}
|
|
126
|
-
r.add(e),
|
|
127
|
-
},
|
|
117
|
+
r.add(e), v ?? (v = requestAnimationFrame(P));
|
|
118
|
+
}, P = () => {
|
|
128
119
|
for (const e of r)
|
|
129
120
|
e.isConnected && e.next();
|
|
130
|
-
r.clear(),
|
|
121
|
+
r.clear(), v = null;
|
|
131
122
|
};
|
|
132
123
|
export {
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
124
|
+
W as Fragment,
|
|
125
|
+
j as h,
|
|
126
|
+
u as render
|
|
136
127
|
};
|
package/package.json
CHANGED
package/readme.md
CHANGED
|
@@ -218,7 +218,7 @@ The `set:` prefix in Ajo allows you to directly set properties on DOM elements f
|
|
|
218
218
|
```jsx
|
|
219
219
|
function* MyComponent() {
|
|
220
220
|
const text = "Hello, Ajo!"
|
|
221
|
-
yield <div set:textContent={text} skip></div>
|
|
221
|
+
while (true) yield <div set:textContent={text} skip></div>
|
|
222
222
|
}
|
|
223
223
|
```
|
|
224
224
|
> Here, `set:textContent` directly sets the `textContent` property of the `div`'s DOM node. `skip` is used to prevent Ajo from overriding the `div`'s children.
|
|
@@ -227,7 +227,7 @@ function* MyComponent() {
|
|
|
227
227
|
```jsx
|
|
228
228
|
function* MyComponent() {
|
|
229
229
|
const html = "<p>Hello, Ajo!</p>"
|
|
230
|
-
yield <div set:innerHTML={html} skip></div>
|
|
230
|
+
while (true) yield <div set:innerHTML={html} skip></div>
|
|
231
231
|
}
|
|
232
232
|
```
|
|
233
233
|
> In this case, `set:innerHTML` is used to set the `innerHTML` property of the `div`'s DOM element. `skip` is used to prevent Ajo from overriding the `div`'s children.
|
|
@@ -236,7 +236,7 @@ function* MyComponent() {
|
|
|
236
236
|
```jsx
|
|
237
237
|
function* MyComponent() {
|
|
238
238
|
const handleClick = () => console.log('Clicked')
|
|
239
|
-
yield <button set:onclick={handleClick}>Click Me</button>
|
|
239
|
+
while (true) yield <button set:onclick={handleClick}>Click Me</button>
|
|
240
240
|
}
|
|
241
241
|
```
|
|
242
242
|
> `set:onclick` assigns the `handleClick` function as the click event listener for the button.
|