ajo 0.1.13 → 0.1.15

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 CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const b=({children:e})=>e,A=function(e,t){const{length:i}=arguments;return(t??(t=C(null))).nodeName=e,"children"in t||i<3||(t.children=i===3?arguments[2]:O.call(arguments,2)),t},y=(e,t)=>{let i=t.firstChild;for(e of p(e)){let n=i;if(typeof e=="string"){for(;n&&n.nodeType!=3;)n=n.nextSibling;n?n.data!=e&&(n.data=e):n=document.createTextNode(e)}else if(e instanceof Node)n=e;else{const{nodeName:o,key:a,skip:m,memo:r,ref:s,children:u}=e;for(;n&&!(n.localName===o&&(n.$key??(n.$key=a))==a);)n=n.nextSibling;if(n??(n=g(document.createElementNS(e.xmlns??o==="svg"?T:t.namespaceURI,o),{$key:a})),r==null||P(n.$memo,n.$memo=r)){const{$props:d}=n,w={};for(const c of h(g({},d,e))){if(q.has(c))continue;const f=w[c]=e[c];f!==(d==null?void 0:d[c])&&(c.startsWith("set:")?n[c.slice(4)]=f:f==null||f===!1?n.removeAttribute(c):n.setAttribute(c,f===!0?"":f))}n.$props=w,m||y(u,n),typeof s=="function"&&(n.$ref=s)(n)}}n===i?i=i.nextSibling:E(t,n,i)}for(;i;){const n=i.nextSibling;i.nodeType===1&&N(i),t.removeChild(i),i=n}},{isArray:$,prototype:{slice:O}}=Array,{create:C,keys:h,assign:g,hasOwn:F,setPrototypeOf:x,getPrototypeOf:v}=Object,T="http://www.w3.org/2000/svg",q=new Set("nodeName,key,skip,memo,ref,children".split(",")),S=e=>typeof e!="string"&&typeof(e==null?void 0:e[Symbol.iterator])=="function",P=(e,t)=>$(e)&&$(t)?e.some((i,n)=>i!==t[n]):e!==t,p=function*(e,t={value:""},i=!0){for(e of S(e)?e:[e])if(!(e==null||typeof e=="boolean"))if(F(e,"nodeName")){const{value:n}=t,{nodeName:o}=e,a=typeof o;if(n&&(yield n,t.value=""),a==="function")if(delete e.nodeName,o.constructor.name==="GeneratorFunction"){const m={},r=g({},o.attrs);for(const s of h(e)){const u=e[s];s.startsWith("attr:")&&(r[s.slice(5)]=u),s==="key"||s==="memo"?r[s]=u:m[s]=u}r.nodeName=o.is??"div",r.skip=!0,r.ref=j.bind(null,o,m),yield r}else yield*p(o(e),t,!1);else a==="string"&&(yield e)}else S(e)?yield*p(e,t,!1):t.value+=e;i&&t.value&&(yield t.value)},j=(e,t,i)=>{i&&(i.$gen??(i.$gen=(new I(i),e)),i.$ref=B.bind(null,i),i.$args=t,i.next())},B=(e,t)=>t??e.return(),E=(e,t,i)=>{if(t.contains(document.activeElement)){const n=t.nextSibling;for(;i&&i!=t;){const o=i.nextSibling;e.insertBefore(i,n),i=o}}else e.insertBefore(t,i)},N=e=>{for(const i of e.children)N(i);const{$ref:t}=e;typeof t=="function"&&t(null);for(const i of h(e))e[i]=null};class I{constructor(t){x(t,x(v(this),v(t)))}*[Symbol.iterator](){for(;;)yield this.$args??{}}refresh(){W(this)}next(){try{y((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 i;for(let n=this;n;n=n.parentNode)if(typeof((i=n.$it)==null?void 0:i.throw)=="function")try{return y(n.$it.throw(t).value,n)}catch{}throw t}return(){var t;try{(t=this.$it)==null||t.return()}catch(i){this.throw(i)}finally{this.$it=null}}}let l,k;const W=e=>{(l??(l=new Set)).has(e)&&l.delete(e);for(const t of l){if(t.contains(e))return;e.contains(t)&&l.delete(t)}l.add(e),k??(k=requestAnimationFrame(z))},z=()=>{for(const e of l)e.isConnected&&e.next();l.clear(),k=null};exports.Fragment=b;exports.h=A;exports.render=y;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const b=({children:e})=>e,A=function(e,t){const{length:i}=arguments;return(t??(t=C(null))).nodeName=e,"children"in t||i<3||(t.children=i===3?arguments[2]:O.call(arguments,2)),t},d=(e,t)=>{let i=t.firstChild;for(e of h(e)){let n=i;if(typeof e=="string"){for(;n&&n.nodeType!=3;)n=n.nextSibling;n?n.data!=e&&(n.data=e):n=document.createTextNode(e)}else if(e instanceof Node)n=e;else{const{nodeName:o,key:a,skip:m,memo:r,ref:s,children:u}=e;for(;n&&!(n.localName===o&&(n.$key??(n.$key=a))==a);)n=n.nextSibling;if(n??(n=g(document.createElementNS(e.xmlns??o==="svg"?T:t.namespaceURI,o),{$key:a})),r==null||P(n.$memo,n.$memo=r)){const{$props:y}=n,w={};for(const l of p(g({},y,e))){if(q.has(l))continue;const f=w[l]=e[l];f!==(y==null?void 0:y[l])&&(l.startsWith("set:")?n[l.slice(4)]=f:f==null||f===!1?n.removeAttribute(l):n.setAttribute(l,f===!0?"":f))}n.$props=w,m||d(u,n),typeof s=="function"&&(n.$ref=s)(n)}}n===i?i=i.nextSibling:E(t,n,i)}for(;i;){const n=i.nextSibling;i.nodeType===1&&N(i),t.removeChild(i),i=n}},{isArray:$,prototype:{slice:O}}=Array,{create:C,keys:p,assign:g,hasOwn:F,setPrototypeOf:x,getPrototypeOf:v}=Object,T="http://www.w3.org/2000/svg",q=new Set("nodeName,key,skip,memo,ref,children".split(",")),S=e=>typeof e!="string"&&typeof(e==null?void 0:e[Symbol.iterator])=="function",P=(e,t)=>$(e)&&$(t)?e.some((i,n)=>i!==t[n]):e!==t,h=function*(e,t={value:""},i=!0){for(e of S(e)?e:[e])if(!(e==null||typeof e=="boolean"))if(F(e,"nodeName")){const{value:n}=t,{nodeName:o}=e,a=typeof o;if(n&&(yield n,t.value=""),a==="function")if(delete e.nodeName,o.constructor.name==="GeneratorFunction"){const m={},r=g({},o.attrs);for(const s of p(e)){const u=e[s];s.startsWith("attr:")&&(r[s.slice(5)]=u),s==="key"||s==="memo"?r[s]=u:m[s]=u}r.nodeName=o.is??"div",r.skip=!0,r.ref=j.bind(null,o,m),yield r}else yield*h(o(e),t,!1);else a==="string"&&(yield e)}else S(e)?yield*h(e,t,!1):t.value+=e;i&&t.value&&(yield t.value)},j=(e,t,i)=>{i&&(i.$gen??(i.$gen=(new W(i),e)),i.$ref=B.bind(null,i),i.$args=t,i.next())},B=(e,t)=>t??e.return(),E=(e,t,i)=>{if(t.contains(document.activeElement)){const n=t.nextSibling;for(;i&&i!=t;){const o=i.nextSibling;e.insertBefore(i,n),i=o}}else e.insertBefore(t,i)},N=e=>{for(const i of e.children)N(i);const{$ref:t}=e;typeof t=="function"&&t(null);for(const i of p(e))e[i]=null};let c,k;const I=()=>{for(const e of c)e.isConnected&&e.next();c.clear(),k=null};class W{constructor(t){x(t,x(v(this),v(t)))}*[Symbol.iterator](){for(;;)yield this.$args??{}}refresh(){(c??(c=new Set)).has(this)&&c.delete(this);for(const t of c){if(t.contains(this))return;this.contains(t)&&c.delete(t)}c.add(this),k??(k=requestAnimationFrame(I))}next(){try{d((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 i;for(let n=this;n;n=n.parentNode)if(typeof((i=n.$it)==null?void 0:i.throw)=="function")try{return d(n.$it.throw(t).value,n)}catch{}throw t}return(){var t;try{(t=this.$it)==null||t.return()}catch(i){this.throw(i)}finally{this.$it=null}}}exports.Fragment=b;exports.h=A;exports.render=d;
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- const j = ({ children: e }) => e, z = function(e, t) {
1
+ const W = ({ children: e }) => e, j = function(e, t) {
2
2
  const { length: i } = arguments;
3
3
  return (t ?? (t = A(null))).nodeName = e, "children" in t || i < 3 || (t.children = i === 3 ? arguments[2] : b.call(arguments, 2)), t;
4
4
  }, d = (e, t) => {
@@ -16,14 +16,14 @@ const j = ({ children: e }) => e, z = function(e, t) {
16
16
  for (; n && !(n.localName === o && (n.$key ?? (n.$key = a)) == a); )
17
17
  n = n.nextSibling;
18
18
  if (n ?? (n = g(document.createElementNS(e.xmlns ?? o === "svg" ? O : t.namespaceURI, o), { $key: a })), r == null || F(n.$memo, n.$memo = r)) {
19
- const { $props: y } = n, $ = {};
20
- for (const c of w(g({}, y, e))) {
21
- if (q.has(c))
19
+ const { $props: y } = n, w = {};
20
+ for (const l of h(g({}, y, e))) {
21
+ if (q.has(l))
22
22
  continue;
23
- const f = $[c] = e[c];
24
- f !== (y == null ? void 0 : y[c]) && (c.startsWith("set:") ? n[c.slice(4)] = f : f == null || f === !1 ? n.removeAttribute(c) : n.setAttribute(c, f === !0 ? "" : f));
23
+ const f = w[l] = e[l];
24
+ f !== (y == null ? void 0 : y[l]) && (l.startsWith("set:") ? n[l.slice(4)] = f : f == null || f === !1 ? n.removeAttribute(l) : n.setAttribute(l, f === !0 ? "" : f));
25
25
  }
26
- n.$props = $, m || d(u, n), typeof s == "function" && (n.$ref = s)(n);
26
+ n.$props = w, m || d(u, n), typeof s == "function" && (n.$ref = s)(n);
27
27
  }
28
28
  }
29
29
  n === i ? i = i.nextSibling : E(t, n, i);
@@ -32,7 +32,7 @@ const j = ({ children: e }) => e, z = function(e, t) {
32
32
  const n = i.nextSibling;
33
33
  i.nodeType === 1 && k(i), t.removeChild(i), i = n;
34
34
  }
35
- }, { isArray: h, prototype: { slice: b } } = Array, { create: A, keys: w, assign: g, hasOwn: C, setPrototypeOf: x, getPrototypeOf: v } = Object, O = "http://www.w3.org/2000/svg", q = new Set("nodeName,key,skip,memo,ref,children".split(",")), N = (e) => typeof e != "string" && typeof (e == null ? void 0 : e[Symbol.iterator]) == "function", F = (e, t) => h(e) && h(t) ? e.some((i, n) => i !== t[n]) : e !== t, p = function* (e, t = { value: "" }, i = !0) {
35
+ }, { isArray: $, prototype: { slice: b } } = Array, { create: A, keys: h, assign: g, hasOwn: C, setPrototypeOf: x, getPrototypeOf: v } = Object, O = "http://www.w3.org/2000/svg", q = new Set("nodeName,key,skip,memo,ref,children".split(",")), N = (e) => typeof e != "string" && typeof (e == null ? void 0 : e[Symbol.iterator]) == "function", F = (e, t) => $(e) && $(t) ? e.some((i, n) => i !== t[n]) : e !== t, p = function* (e, t = { value: "" }, i = !0) {
36
36
  for (e of N(e) ? e : [e])
37
37
  if (!(e == null || typeof e == "boolean"))
38
38
  if (C(e, "nodeName")) {
@@ -40,7 +40,7 @@ const j = ({ children: e }) => e, z = function(e, t) {
40
40
  if (n && (yield n, t.value = ""), a === "function")
41
41
  if (delete e.nodeName, o.constructor.name === "GeneratorFunction") {
42
42
  const m = {}, r = g({}, o.attrs);
43
- for (const s of w(e)) {
43
+ for (const s of h(e)) {
44
44
  const u = e[s];
45
45
  s.startsWith("attr:") && (r[s.slice(5)] = u), s === "key" || s === "memo" ? r[s] = u : m[s] = u;
46
46
  }
@@ -53,7 +53,7 @@ const j = ({ children: e }) => e, z = function(e, t) {
53
53
  N(e) ? yield* p(e, t, !1) : t.value += e;
54
54
  i && t.value && (yield t.value);
55
55
  }, T = (e, t, i) => {
56
- i && (i.$gen ?? (i.$gen = (new I(i), e)), i.$ref = B.bind(null, i), i.$args = t, i.next());
56
+ i && (i.$gen ?? (i.$gen = (new P(i), e)), i.$ref = B.bind(null, i), i.$args = t, i.next());
57
57
  }, B = (e, t) => t ?? e.return(), E = (e, t, i) => {
58
58
  if (t.contains(document.activeElement)) {
59
59
  const n = t.nextSibling;
@@ -68,10 +68,16 @@ const j = ({ children: e }) => e, z = function(e, t) {
68
68
  k(i);
69
69
  const { $ref: t } = e;
70
70
  typeof t == "function" && t(null);
71
- for (const i of w(e))
71
+ for (const i of h(e))
72
72
  e[i] = null;
73
73
  };
74
- class I {
74
+ let c, S;
75
+ const I = () => {
76
+ for (const e of c)
77
+ e.isConnected && e.next();
78
+ c.clear(), S = null;
79
+ };
80
+ class P {
75
81
  constructor(t) {
76
82
  x(t, x(v(this), v(t)));
77
83
  }
@@ -80,7 +86,13 @@ class I {
80
86
  yield this.$args ?? {};
81
87
  }
82
88
  refresh() {
83
- P(this);
89
+ (c ?? (c = /* @__PURE__ */ new Set())).has(this) && c.delete(this);
90
+ for (const t of c) {
91
+ if (t.contains(this))
92
+ return;
93
+ this.contains(t) && c.delete(t);
94
+ }
95
+ c.add(this), S ?? (S = requestAnimationFrame(I));
84
96
  }
85
97
  next() {
86
98
  try {
@@ -110,22 +122,8 @@ class I {
110
122
  }
111
123
  }
112
124
  }
113
- let l, S;
114
- const P = (e) => {
115
- (l ?? (l = /* @__PURE__ */ new Set())).has(e) && l.delete(e);
116
- for (const t of l) {
117
- if (t.contains(e))
118
- return;
119
- e.contains(t) && l.delete(t);
120
- }
121
- l.add(e), S ?? (S = requestAnimationFrame(W));
122
- }, W = () => {
123
- for (const e of l)
124
- e.isConnected && e.next();
125
- l.clear(), S = null;
126
- };
127
125
  export {
128
- j as Fragment,
129
- z as h,
126
+ W as Fragment,
127
+ j as h,
130
128
  d as render
131
129
  };
package/package.json CHANGED
@@ -1,27 +1,29 @@
1
1
  {
2
2
  "name": "ajo",
3
- "version": "0.1.13",
3
+ "version": "0.1.15",
4
4
  "description": "ajo is a JavaScript view library for building user interfaces",
5
5
  "type": "module",
6
- "module": "./dist/index.js",
7
- "main": "./dist/index.cjs",
8
6
  "exports": {
9
7
  ".": {
10
8
  "import": "./dist/index.js",
11
- "require": "./dist/index.cjs"
9
+ "require": "./dist/index.cjs",
10
+ "types": "./types.ts"
12
11
  },
13
12
  "./html": {
14
13
  "import": "./dist/html.js",
15
- "require": "./dist/html.umd.cjs"
14
+ "require": "./dist/html.cjs",
15
+ "types": "./types.ts"
16
16
  }
17
17
  },
18
18
  "files": [
19
- "dist"
19
+ "dist",
20
+ "types.ts"
20
21
  ],
21
22
  "devDependencies": {
22
- "jsdom": "^23.0.1",
23
- "vite": "^5.0.10",
24
- "vitest": "^1.0.4"
23
+ "@types/node": "^20.12.7",
24
+ "jsdom": "24.0.0",
25
+ "vite": "5.2.8",
26
+ "vitest": "1.5.0"
25
27
  },
26
28
  "keywords": [
27
29
  "ui",
package/types.ts ADDED
@@ -0,0 +1,82 @@
1
+ declare module 'ajo' {
2
+
3
+ type Tag = keyof (HTMLElementTagNameMap & SVGElementTagNameMap)
4
+
5
+ type Props = Record<string, unknown>
6
+
7
+ type AjoNode<TTag = Tag> = { nodeName: TTag } & AjoProps<ElementType<TTag>> & Props
8
+
9
+ type Children =
10
+ | null
11
+ | undefined
12
+ | boolean
13
+ | bigint
14
+ | number
15
+ | string
16
+ | symbol
17
+ | Node
18
+ | AjoNode
19
+ | Iterable<Children>
20
+
21
+ type ElementType<TTag = Tag> = TTag extends keyof HTMLElementTagNameMap
22
+ ? HTMLElementTagNameMap[TTag]
23
+ : TTag extends keyof SVGElementTagNameMap
24
+ ? SVGElementTagNameMap[TTag]
25
+ : never
26
+
27
+ type AjoProps<TElement> = {
28
+ key: unknown
29
+ skip: boolean
30
+ memo: unknown
31
+ ref: (el: TElement | null) => void
32
+ } & ElementChildrenAttribute
33
+
34
+ type SetProps<TTag = Tag> = {
35
+ [K in keyof ElementType<TTag> as `set:${Exclude<K, symbol>}`]: ElementType<TTag>[K]
36
+ }
37
+
38
+ type AttrProps<TAttribute = Props> = {
39
+ [K in keyof TAttribute as `attr:${Exclude<K, symbol>}`]: TAttribute[K]
40
+ }
41
+
42
+ type Context<TArguments = Props> = {
43
+ $args: TArguments
44
+ next: () => void
45
+ throw: (value?: unknown) => void
46
+ return: () => void
47
+ refresh: () => void
48
+ [Symbol.iterator]: () => Generator<TArguments, unknown, unknown>
49
+ }
50
+
51
+ type Function<TArguments = Props> = (args: TArguments) => Children
52
+
53
+ type Component<TArguments = Props, TTag extends Tag = 'div'> = {
54
+ (this: ComponentElement<TArguments, TTag>, args: TArguments): Generator<Children, unknown, unknown>
55
+ } & (TTag extends 'div' ? { is?: TTag } : { is: TTag })
56
+
57
+ type ComponentElement<TArguments = Props, TTag = Tag> = Context<TArguments> & ElementType<TTag>
58
+
59
+ type IntrinsicElements = {
60
+ [TTag in Tag]: Partial<SetProps<TTag> & AjoProps<ElementType<TTag>>> & Props
61
+ }
62
+
63
+ type IntrinsicAttributes = Partial<Omit<AjoProps<ElementType<Tag>>, 'skip' | 'ref'>> & AttrProps
64
+
65
+ type ElementChildrenAttribute = { children: Children }
66
+
67
+ function Fragment({ children }: ElementChildrenAttribute): typeof children
68
+ function h<TProps = Props>(type: Tag | Function<TProps> | Component<TProps>, props?: TProps | null, ...children: Children[]): AjoNode<typeof type>
69
+ function render(h: Children, el: Element): void
70
+ }
71
+
72
+ declare namespace JSX {
73
+ type ElementChildrenAttribute = import('ajo').ElementChildrenAttribute
74
+ type IntrinsicElements = import('ajo').IntrinsicElements
75
+ type IntrinsicAttributes = import('ajo').IntrinsicAttributes
76
+ }
77
+
78
+ declare namespace React {
79
+ const createElement: typeof import('ajo').h
80
+ const Fragment: typeof import('ajo').Fragment
81
+ type ReactNode = import('ajo').Children
82
+ }