From 0ac4bd9c2d3541c99d56d6eeca2ccc8ca15b2a6b Mon Sep 17 00:00:00 2001 From: Seth Trowbridge Date: Thu, 6 Feb 2025 12:38:10 -0500 Subject: [PATCH] parts --- .vscode/settings.json | 3 +++ app.js | 3 +++ deno.json | 16 ++++++++++++++ faux.d.ts | 2 ++ faux.js | 0 index.html | 38 ++++++++++++++++++++++++++++++++++ van.d.ts | 18 ++++++++++++++++ van.globals.d.ts.old | 10 +++++++++ van.js | 2 ++ van.types.d.ts | 47 ++++++++++++++++++++++++++++++++++++++++++ van.types.d.ts.old | 39 +++++++++++++++++++++++++++++++++++ van.x.globals.d.ts.old | 13 ++++++++++++ van.x.types.d.ts.old | 9 ++++++++ 13 files changed, 200 insertions(+) create mode 100644 .vscode/settings.json create mode 100644 app.js create mode 100644 deno.json create mode 100644 faux.d.ts create mode 100644 faux.js create mode 100644 index.html create mode 100644 van.d.ts create mode 100644 van.globals.d.ts.old create mode 100644 van.js create mode 100644 van.types.d.ts create mode 100644 van.types.d.ts.old create mode 100644 van.x.globals.d.ts.old create mode 100644 van.x.types.d.ts.old diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..b943dbc --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "deno.enable": true +} \ No newline at end of file diff --git a/app.js b/app.js new file mode 100644 index 0000000..8de5ed9 --- /dev/null +++ b/app.js @@ -0,0 +1,3 @@ +import {van, vanX} from "./van.js"; + +van.state \ No newline at end of file diff --git a/deno.json b/deno.json new file mode 100644 index 0000000..fdb2857 --- /dev/null +++ b/deno.json @@ -0,0 +1,16 @@ +{ + "compilerOptions": { + "checkJs": true, + "lib": [ + "dom", + "dom.iterable", + "dom.asynciterable", + "deno.ns", + "deno.unstable" + ] + }, + "imports": { + "test": "https://esm.sh/react", + "entry": "./app.js" + } +} diff --git a/faux.d.ts b/faux.d.ts new file mode 100644 index 0000000..ec94706 --- /dev/null +++ b/faux.d.ts @@ -0,0 +1,2 @@ +export declare type Member =(s:string)=>Array; +export declare const Member:Member; \ No newline at end of file diff --git a/faux.js b/faux.js new file mode 100644 index 0000000..e69de29 diff --git a/index.html b/index.html new file mode 100644 index 0000000..c2a0572 --- /dev/null +++ b/index.html @@ -0,0 +1,38 @@ + + + + + Document + + + + + + + + \ No newline at end of file diff --git a/van.d.ts b/van.d.ts new file mode 100644 index 0000000..4664907 --- /dev/null +++ b/van.d.ts @@ -0,0 +1,18 @@ + +export const van:{ + readonly state: (initVal: T)=> Van.State + readonly derive: (f: () => T) => Van.State + readonly add: (dom: Element, ...children: readonly Van.ChildDom[]) => Element + readonly tags: Van.Tags & ((namespaceURI: string) => Readonly>>) + readonly hydrate: (dom: T, f: (dom: T) => T | null | undefined) => T +} +export const vanX: { + readonly calc: (f: () => R) => R + readonly reactive: (obj: T) => T + readonly noreactive: (obj: T) => T + readonly stateFields: (obj: T) => VanX.StateOf + readonly raw: (obj: T) => T + readonly list: (container: (() => ElementType) | ElementType, items: T,itemFunc: (v: Van.State>, deleter: () => void, k: VanX.KeyType) => Node) => ElementType + readonly replace: (obj: T, replacement: VanX.ReplacementFunc | T) => T + readonly compact: (obj: T) => T +} diff --git a/van.globals.d.ts.old b/van.globals.d.ts.old new file mode 100644 index 0000000..e993a16 --- /dev/null +++ b/van.globals.d.ts.old @@ -0,0 +1,10 @@ +export {} +declare global { + const van:{ + readonly state: (initVal: T)=> Van.State + readonly derive: (f: () => T) => Van.State + readonly add: (dom: Element, ...children: readonly Van.ChildDom[]) => Element + readonly tags: Van.Tags & ((namespaceURI: string) => Readonly>>) + readonly hydrate: (dom: T, f: (dom: T) => T | null | undefined) => T + } +} diff --git a/van.js b/van.js new file mode 100644 index 0000000..8dcbaa3 --- /dev/null +++ b/van.js @@ -0,0 +1,2 @@ +export const van = globalThis.van; +export const vanX = globalThis.vanX; \ No newline at end of file diff --git a/van.types.d.ts b/van.types.d.ts new file mode 100644 index 0000000..5b3a385 --- /dev/null +++ b/van.types.d.ts @@ -0,0 +1,47 @@ + +declare namespace Van { + + interface State { + val: T + readonly oldVal: T + readonly rawVal: T + } + + // Defining readonly view of State for covariance. + // Basically we want StateView to implement StateView + type StateView = Readonly> + + type Val = State | T + + type Primitive = string | number | boolean | bigint + + // deno-lint-ignore no-explicit-any + type PropValue = Primitive | ((e: any) => void) | null + + type PropValueOrDerived = PropValue | StateView | (() => PropValue) + + type Props = Record & { class?: PropValueOrDerived; is?: string } + + type PropsWithKnownKeys = Partial<{[K in keyof ElementType]: PropValueOrDerived}> + + type ValidChildDomValue = Primitive | Node | null | undefined + + type BindingFunc = ((dom?: Node) => ValidChildDomValue) | ((dom?: Element) => Element) + + type ChildDom = ValidChildDomValue | StateView | BindingFunc | readonly ChildDom[] + + type TagFunc = (first?: Props & PropsWithKnownKeys | ChildDom, ...rest: readonly ChildDom[]) => Result + + type Tags = Readonly>> & { + [K in keyof HTMLElementTagNameMap]: TagFunc + } +} +declare namespace VanX +{ + type StateOf = { readonly [K in keyof T]: Van.State } + type ValueType = T extends (infer V)[] ? V : T[keyof T] + type KeyType = T extends unknown[] ? number : string + type ReplacementFunc = + T extends (infer V)[] ? (items: V[]) => readonly V[] : + (items: [string, T[keyof T]][]) => readonly [string, T[keyof T]][] +} \ No newline at end of file diff --git a/van.types.d.ts.old b/van.types.d.ts.old new file mode 100644 index 0000000..0c83f68 --- /dev/null +++ b/van.types.d.ts.old @@ -0,0 +1,39 @@ + +declare namespace Van { + + interface State { + val: T + readonly oldVal: T + readonly rawVal: T + } + + // Defining readonly view of State for covariance. + // Basically we want StateView to implement StateView + type StateView = Readonly> + + type Val = State | T + + type Primitive = string | number | boolean | bigint + + // deno-lint-ignore no-explicit-any + type PropValue = Primitive | ((e: any) => void) | null + + type PropValueOrDerived = PropValue | StateView | (() => PropValue) + + type Props = Record & { class?: PropValueOrDerived; is?: string } + + type PropsWithKnownKeys = Partial<{[K in keyof ElementType]: PropValueOrDerived}> + + type ValidChildDomValue = Primitive | Node | null | undefined + + type BindingFunc = ((dom?: Node) => ValidChildDomValue) | ((dom?: Element) => Element) + + type ChildDom = ValidChildDomValue | StateView | BindingFunc | readonly ChildDom[] + + type TagFunc = (first?: Props & PropsWithKnownKeys | ChildDom, ...rest: readonly ChildDom[]) => Result + + type Tags = Readonly>> & { + [K in keyof HTMLElementTagNameMap]: TagFunc + } + +} \ No newline at end of file diff --git a/van.x.globals.d.ts.old b/van.x.globals.d.ts.old new file mode 100644 index 0000000..81de377 --- /dev/null +++ b/van.x.globals.d.ts.old @@ -0,0 +1,13 @@ +export {}; +declare global { + const vanX: { + readonly calc: (f: () => R) => R + readonly reactive: (obj: T) => T + readonly noreactive: (obj: T) => T + readonly stateFields: (obj: T) => VanX.StateOf + readonly raw: (obj: T) => T + readonly list: (container: (() => ElementType) | ElementType, items: T,itemFunc: (v: Van.State>, deleter: () => void, k: VanX.KeyType) => Node) => ElementType + readonly replace: (obj: T, replacement: VanX.ReplacementFunc | T) => T + readonly compact: (obj: T) => T + } +} \ No newline at end of file diff --git a/van.x.types.d.ts.old b/van.x.types.d.ts.old new file mode 100644 index 0000000..1337f96 --- /dev/null +++ b/van.x.types.d.ts.old @@ -0,0 +1,9 @@ +declare namespace VanX +{ + type StateOf = { readonly [K in keyof T]: Van.State } + type ValueType = T extends (infer V)[] ? V : T[keyof T] + type KeyType = T extends unknown[] ? number : string + type ReplacementFunc = + T extends (infer V)[] ? (items: V[]) => readonly V[] : + (items: [string, T[keyof T]][]) => readonly [string, T[keyof T]][] +} \ No newline at end of file