@wrnrlr/prelude 0.2.0 → 0.2.2

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/deno.jsonc CHANGED
@@ -1,10 +1,9 @@
1
1
  {
2
2
  "name": "@wrnrlr/prelude",
3
- "version": "0.2.0",
3
+ "version": "0.2.2",
4
4
  "exports": "./src/mod.ts",
5
5
  "compilerOptions": {
6
6
  "strict": true,
7
- // "checkJs": false,
8
7
  "lib": ["dom", "dom.iterable", "dom.asynciterable", "deno.ns"]
9
8
  },
10
9
  "imports": {
@@ -20,10 +19,7 @@
20
19
  "tasks": {
21
20
  "dev": "deno run -A npm:vite --config www/vite.config.js",
22
21
  "test": "deno test -A ./test/*.[jt]s",
23
- // "docs": "deno run -A npm:typedoc --options www/typedoc.json",
24
- // "build": "deno run -A npm:vite build --mode production --config www/vite.config.js",
25
- "release": "deno publish --allow-slow-types --allow-dirty && npm publish --access public",
26
- // "clean": "rm -rf dist/ www/dist www/docs"
22
+ "release": "deno publish --allow-slow-types --allow-dirty && npm publish --access public"
27
23
  },
28
24
  "lint": {
29
25
  "include": ["src"]
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@wrnrlr/prelude",
3
3
  "type": "module",
4
- "version": "0.2.0",
4
+ "version": "0.2.2",
5
5
  "author": "Werner Laurensse",
6
6
  "description": "A signal based frontend library with fine-grained reactivity",
7
7
  "main": "./src/mod.ts",
@@ -195,7 +195,6 @@ function listArray<T, U extends Mountable>(
195
195
  item!.valueSetter?.(newValueGetter)
196
196
  }
197
197
  function mapper(disposer: ()=>void) {
198
- const V = newValue
199
198
  const I = i
200
199
  const t = {value: newValue, index: I, disposer}
201
200
  items.push(t)
@@ -218,7 +217,7 @@ function listArray<T, U extends Mountable>(
218
217
  }
219
218
  }
220
219
 
221
- function disposeList(list:any[]) {
220
+ function disposeList(list:{disposer?:()=>unknown}[]) {
222
221
  for (let i = 0; i < list.length; i++) {
223
222
  list[i]?.disposer()
224
223
  }
@@ -22,12 +22,24 @@ export type View = {():void, [ELEMENT]?:boolean}
22
22
 
23
23
  export type TagParser = <T extends string>(s:T) => {name:string,id?:string,classes:string[],namespace?:string}
24
24
 
25
+ export type HyperScript = {
26
+ (first: Tag): View
27
+ <P>(first: Tag, second: P): View
28
+ <C extends Child>(first: Tag, second: C): View
29
+ <C extends Child, P>(first: Tag, second: P, third: C): View
30
+
31
+ (first: Component<Record<string,never>>): View
32
+ <P extends Record<string, unknown>>(first: Component<P>, second: P): View
33
+ <C>(first: Component<{children:C}>, second: C): View
34
+ <P extends Record<string, unknown>, C>(first: Component<P & {children:C}>, second:P, third:C): View
35
+ }
36
+
25
37
  /**
26
38
  @param r
27
39
  @param patch
28
40
  @group Hyperscript
29
41
  */
30
- export function hyperscript(r: Runtime, parseTag: TagParser = parseHtmlTag) {
42
+ export function hyperscript(r: Runtime, parseTag: TagParser = parseHtmlTag): HyperScript {
31
43
 
32
44
  function item(e: Element, c: Child, m?: null): void {
33
45
  if (c===null) return
@@ -45,17 +57,7 @@ export function hyperscript(r: Runtime, parseTag: TagParser = parseHtmlTag) {
45
57
  } else e.appendChild(r.text(c.toString()))
46
58
  }
47
59
 
48
- function h(first: Tag): View
49
- function h<P>(first: Tag, second: P): View
50
- function h<C extends Child>(first: Tag, second: C): View
51
- function h<C extends Child, P>(first: Tag, second: P, third: C): View
52
-
53
- function h(first: Component<Record<string,never>>): View
54
- function h<P extends Record<string, unknown>>(first: Component<P>, second: P): View
55
- function h<C>(first: Component<{children:C}>, second: C): View
56
- function h<P extends Record<string, unknown>, C>(first: Component<P & {children:C}>, second:P, third:C): View
57
-
58
- function h<P extends Record<string,unknown>, C = never>(
60
+ return function h<P extends Record<string,unknown>, C = never>(
59
61
  first: Tag | Component<P>,
60
62
  second?: P | C,
61
63
  third?: C
@@ -73,9 +75,8 @@ export function hyperscript(r: Runtime, parseTag: TagParser = parseHtmlTag) {
73
75
 
74
76
  let ret:View
75
77
 
76
- const t1 = typeof first
77
- if (t1 === 'string') {
78
- const tag = parseTag(first as Tag)
78
+ if (typeof first === 'string') {
79
+ const tag = parseTag(first)
79
80
  const multiExpression = detectMultiExpression(children) ? null : undefined
80
81
  const e = r.element(tag.name)
81
82
  const props2 = props as P & {class?: string|(()=>string)}
@@ -95,16 +96,16 @@ export function hyperscript(r: Runtime, parseTag: TagParser = parseHtmlTag) {
95
96
  dynamic = true
96
97
  } else if (d[k].get) dynamic = true
97
98
  }
98
- (dynamic ? r.spread : r.assign) (e, props2, !!(children as any)?.length)
99
+ (dynamic ? r.spread : r.assign) (e, props2, !!(children as {length?: number})?.length)
99
100
  item(e, children, multiExpression)
100
101
  ret = () => e
101
102
  } else {
102
103
  const d = Object.getOwnPropertyDescriptors(props)
103
- if (children) (props as any).children = children
104
+ if (children) (props as unknown as {children:unknown}).children = children
104
105
  for (const k in d) {
105
106
  if (isArray(d[k].value)) {
106
107
  const list = d[k].value;
107
- (props as any)[k] = () => {
108
+ (props as Record<string, ()=>unknown>)[k] = () => {
108
109
  for (let i = 0; i < list.length; i++)
109
110
  while (list[i][ELEMENT]) list[i] = list[i]()
110
111
  return list
@@ -120,8 +121,6 @@ export function hyperscript(r: Runtime, parseTag: TagParser = parseHtmlTag) {
120
121
  ret[ELEMENT] = true
121
122
  return ret
122
123
  }
123
-
124
- return h
125
124
  }
126
125
 
127
126
  function detectMultiExpression(children: Child): boolean {
package/src/mod.ts CHANGED
@@ -1,16 +1,15 @@
1
- // @ts-nocheck:
2
- export type {Getter,Setter,Fn,EqualsFn,ErrorFn,RootFn,UpdateFn} from './reactive.ts'
1
+ export type {Getter,Setter,Fn,EqualsFn,ErrorFn,RootFn,UpdateFn,Signal} from './reactive.ts'
3
2
  export {signal,effect,untrack,batch,memo,root,wrap,fuse,onMount,onCleanup} from './reactive.ts'
4
3
  export {nbsp} from './constants.ts'
5
4
  export {Show,List} from './controlflow.ts'
6
5
  export {runtime, type Runtime} from './runtime.ts'
7
6
  import {runtime, type Runtime} from './runtime.ts'
8
7
  export {hyperscript,type Child,type Tag,type View,type Component} from './hyperscript.ts'
9
- import {hyperscript, parseHtmlTag} from './hyperscript.ts'
8
+ import {hyperscript, parseHtmlTag, type HyperScript} from './hyperscript.ts'
10
9
  export {Router} from './router.js'
11
10
  export {resource,makeAbortable,abortable} from './resource.js'
12
11
 
13
- const r:Runtime = /*#__PURE__*/ (typeof window === 'object') ? runtime(window as any) : undefined as any
12
+ const r:Runtime = /*#__PURE__*/ (typeof window === 'object') ? runtime(window) : undefined as unknown as Runtime
14
13
 
15
14
  /** h
16
15
  @example Element with a single child
@@ -27,19 +26,14 @@ h(Input,{onInput:e => {}})
27
26
  ```
28
27
  @group Hyperscript
29
28
  */
30
- const h = /*#__PURE__*/ hyperscript(r, parseHtmlTag)
29
+ export const h: HyperScript = /*#__PURE__*/ hyperscript(r, parseHtmlTag)
31
30
 
32
- const render = /*#__PURE__*/ r?.render
31
+ /** render
33
32
 
34
- // import {signal,wrap} from './reactive.ts'
33
+ Render component to DOM element.
35
34
 
36
- // /**
37
- // @group Utils
38
- // */
39
- // export function $(a:any,b:any):any {
40
- // const t = typeof a
41
- // if (t==='function') return wrap(a,b)
42
- // else return signal(a,b)
43
- // }
44
-
45
- export {h,render}
35
+ ```js
36
+ render(()=>'hi', document.body)
37
+ ```
38
+ */
39
+ export const render:(code:()=>void, element:Element, init:unknown) => void = /*#__PURE__*/ r?.render
package/src/runtime.ts CHANGED
@@ -26,7 +26,7 @@ export type Mountable = HTMLElement | Document | ShadowRoot | DocumentFragment |
26
26
  */
27
27
  export type Runtime = {
28
28
  // window:Window
29
- render(code:()=>void, element:Element, init:any): any;
29
+ render(code:()=>void, element:Element, init:unknown): void;
30
30
  insert(parent:Mountable, accessor:any, marker?:Node|null, init?:any): any;
31
31
  spread(node:Element, accessor:any, skipChildren?: boolean): void;
32
32
  assign(node:Element, props:any, skipChildren?:boolean): void;
@@ -60,9 +60,7 @@ export function runtime(w:Window):Runtime {
60
60
  return untrack(fn)
61
61
  }
62
62
 
63
- function render(code: ()=>void, element:Element, init?:any): void
64
- function render(code: ()=>void, element:Document, init?:any): void
65
- function render(code: ()=>void, element:Element|Document, init?:any): void {
63
+ function render(code: ()=>void, element:Element|Document, init?: unknown): void {
66
64
  if (!element) throw new Error("The `element` passed to `render(..., element)` doesn't exist.");
67
65
  root(() => {
68
66
  if (element instanceof Document) code()
@@ -340,7 +338,7 @@ function setAttribute(node: Element, name: string, value?: string): undefined {
340
338
  value===undefined || value===null ? node.removeAttribute(name) : node.setAttribute(name, value)
341
339
  }
342
340
 
343
- function setAttributeNS(node:Node, ns:string, name:string, value?:string):any {
341
+ function setAttributeNS(node:Node, ns:string, name:string, value?:string):void {
344
342
  value ? node.setAttributeNS(ns, name, value) : node.removeAttributeNS(ns, name)
345
343
  }
346
344