ajo 0.1.13 → 0.1.14

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.
Files changed (2) hide show
  1. package/package.json +7 -5
  2. package/types.ts +69 -0
package/package.json CHANGED
@@ -1,10 +1,11 @@
1
1
  {
2
2
  "name": "ajo",
3
- "version": "0.1.13",
3
+ "version": "0.1.14",
4
4
  "description": "ajo is a JavaScript view library for building user interfaces",
5
5
  "type": "module",
6
6
  "module": "./dist/index.js",
7
7
  "main": "./dist/index.cjs",
8
+ "types": "./types.ts",
8
9
  "exports": {
9
10
  ".": {
10
11
  "import": "./dist/index.js",
@@ -16,12 +17,13 @@
16
17
  }
17
18
  },
18
19
  "files": [
19
- "dist"
20
+ "dist",
21
+ "types.ts"
20
22
  ],
21
23
  "devDependencies": {
22
- "jsdom": "^23.0.1",
23
- "vite": "^5.0.10",
24
- "vitest": "^1.0.4"
24
+ "jsdom": "24.0.0",
25
+ "vite": "5.0.12",
26
+ "vitest": "1.2.1"
25
27
  },
26
28
  "keywords": [
27
29
  "ui",
package/types.ts ADDED
@@ -0,0 +1,69 @@
1
+ declare namespace Ajo {
2
+
3
+ interface VNode<TTag = Tag> extends Partial<AjoProps<ElementType<TTag>>> {
4
+ nodeName: TTag,
5
+ [key: string]: unknown,
6
+ }
7
+
8
+ type Child = null | undefined | boolean | bigint | number | string | symbol | Node | VNode | Iterable<Child>
9
+
10
+ type Tag = keyof (HTMLElementTagNameMap & SVGElementTagNameMap)
11
+
12
+ type ElementType<TTag> =
13
+ TTag extends keyof HTMLElementTagNameMap
14
+ ? HTMLElementTagNameMap[TTag]
15
+ : TTag extends keyof SVGElementTagNameMap
16
+ ? SVGElementTagNameMap[TTag]
17
+ : HTMLElement
18
+
19
+ type AjoProps<TElement> = {
20
+ key: unknown,
21
+ skip: boolean,
22
+ memo: unknown,
23
+ ref: (el: TElement | null) => void,
24
+ children: Child,
25
+ }
26
+
27
+ type SetProps<TTag> = {
28
+ [K in keyof ElementType<TTag> as `set:${Exclude<K, symbol>}`]: ElementType<TTag>[K]
29
+ }
30
+
31
+ type AttrProps<T> = {
32
+ [K in keyof T as `attr:${Exclude<K, symbol>}`]: T[K]
33
+ }
34
+
35
+ type Context<TArgs> = {
36
+ $args: TArgs
37
+ next: () => void
38
+ throw: (error?: unknown) => void
39
+ return: () => void
40
+ refresh: () => void
41
+ [Symbol.iterator]: () => Generator<TArgs, void, TArgs>
42
+ }
43
+
44
+ type Function<TArgs = {}> = (args: TArgs) => Child
45
+
46
+ type Component<TArgs = {}, TTag extends Tag = 'div'> = {
47
+ (this: ElementType<TTag> & Context<TArgs>, args: TArgs): Generator<Child, void, Child>
48
+ } & (TTag extends 'div' ? { is?: TTag } : { is: TTag })
49
+ }
50
+
51
+ declare namespace JSX {
52
+
53
+ type IntrinsicElements = {
54
+ [TTag in Ajo.Tag]: Partial<Ajo.SetProps<TTag> & Ajo.AjoProps<Ajo.ElementType<TTag>>>
55
+ }
56
+
57
+ type IntrinsicAttributes = Partial<Ajo.AttrProps<any> & Omit<Ajo.AjoProps<any>, "skip" | "ref">>
58
+ }
59
+
60
+ declare namespace React {
61
+ export const createElement: typeof import('ajo').h
62
+ export const Fragment: typeof import('ajo').Fragment
63
+ }
64
+
65
+ declare module 'ajo' {
66
+ function Fragment({ children }: { children: Ajo.Child }): typeof children
67
+ function h<TProps = {}>(type: Ajo.Tag | Ajo.Function<TProps> | Ajo.Component<TProps>, props?: TProps | null, ...children: Ajo.Child[]): Ajo.VNode<typeof type>
68
+ function render(h: Ajo.Child, el: Element): void
69
+ }