@tempots/dom 16.0.0 → 18.0.0

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tempots/dom",
3
- "version": "16.0.0",
3
+ "version": "18.0.0",
4
4
  "type": "module",
5
5
  "main": "./index.cjs",
6
6
  "module": "./index.js",
@@ -1,12 +1,12 @@
1
- import { Renderable } from '../types/domain';
2
- import { Value, NValue } from '../std/signal';
1
+ import { NValue, Renderable, Value } from '../types/domain';
3
2
 
4
3
  /**
5
4
  * The `attr` object allows to create any HTML attribute. Either a literal value
6
5
  * or `Signal<?>` can be passed as a value. The type of the value is inferred
7
6
  * from the attribute name.
8
7
  *
9
- * Example
8
+ * @remarks
9
+ * @example
10
10
  * ```ts
11
11
  * const button = html.button(
12
12
  * attr.type('button'),
@@ -136,7 +136,8 @@ export declare const dataAttr: {
136
136
  /**
137
137
  * An object that provides a convenient way to create mountable attributes for ARIA properties.
138
138
  *
139
- * Example
139
+ * @remarks
140
+ * @example
140
141
  * ```ts
141
142
  * const button = html.button(
142
143
  * aria.label('Click me!'),
@@ -453,7 +454,8 @@ export declare const svgAttr: {
453
454
  /**
454
455
  * An object that provides attribute functions for MathML tags.
455
456
  *
456
- * Example
457
+ * @remarks
458
+ * @example
457
459
  * ```ts
458
460
  * const math = html.math(
459
461
  * mathAttr.mathvariant('bold'),
@@ -0,0 +1,3 @@
1
+ import { DOMContext } from '../dom/dom-context';
2
+
3
+ export declare const DOMNode: (node: Node) => (ctx: DOMContext) => (removeTree: boolean) => void;
@@ -1,6 +1,9 @@
1
1
  import { Renderable } from '../types/domain';
2
2
 
3
3
  export declare const OnChecked: (fn: (event: boolean) => void) => Renderable;
4
+ /**
5
+ * Represents a collection of HTML event handlers that can be attached to an element.
6
+ */
4
7
  export declare const on: {
5
8
  abort: (handler: (event: Event) => void) => Renderable;
6
9
  animationcancel: (handler: (event: AnimationEvent) => void) => Renderable;
@@ -1,5 +1,4 @@
1
- import { Renderable } from '../types/domain';
2
- import { NValue } from '../std/signal';
1
+ import { NValue, Renderable } from '../types/domain';
3
2
 
4
3
  export declare const style: {
5
4
  all: (value: NValue<string>) => Renderable;
@@ -1,5 +1,5 @@
1
- import { Renderable } from '../types/domain';
2
- import { Signal, Value } from '../std/signal';
1
+ import { Renderable, Value } from '../types/domain';
2
+ import { Signal } from '../std/signal';
3
3
 
4
4
  export declare const staticText: (text: string) => Renderable;
5
5
  export declare const signalText: (signal: Signal<string>) => Renderable;
@@ -0,0 +1,50 @@
1
+ import { RemoveSignals, Value } from '../types/domain';
2
+ import { AnySignal, Computed, Prop, Signal } from './signal';
3
+
4
+ export declare class MemoryStore {
5
+ private readonly _store;
6
+ getItem: (key: string) => string | null;
7
+ setItem: (key: string, value: string) => void;
8
+ }
9
+ export declare function storedProp<T>({ key, defaultValue, store, serialize, deserialize, equals, onLoad, }: {
10
+ key: string;
11
+ defaultValue: T | (() => T);
12
+ store: {
13
+ getItem: (key: string) => string | null;
14
+ setItem: (key: string, value: string) => void;
15
+ };
16
+ serialize?: (v: T) => string;
17
+ deserialize?: (v: string) => T;
18
+ equals?: (a: T, b: T) => boolean;
19
+ onLoad?: (value: T) => T;
20
+ }): Prop<T>;
21
+ export declare function localStorageProp<T>(options: {
22
+ key: string;
23
+ defaultValue: T | (() => T);
24
+ serialize?: (v: T) => string;
25
+ deserialize?: (v: string) => T;
26
+ equals?: (a: T, b: T) => boolean;
27
+ onLoad?: (value: T) => T;
28
+ }): Prop<T>;
29
+ export declare function sessionStorageProp<T>(options: {
30
+ key: string;
31
+ defaultValue: T | (() => T);
32
+ serialize?: (v: T) => string;
33
+ deserialize?: (v: string) => T;
34
+ equals?: (a: T, b: T) => boolean;
35
+ onLoad?: (value: T) => T;
36
+ }): Prop<T>;
37
+ export declare function animateSignals<T>(initialValue: T, fn: () => T, dependencies: Array<AnySignal>, options?: {
38
+ interpolate?: (start: T, end: T, delta: number) => T;
39
+ duration?: Value<number>;
40
+ easing?: (t: number) => number;
41
+ equals?: (a: T, b: T) => boolean;
42
+ }): Prop<T>;
43
+ export declare function animateSignal<T>(signal: Signal<T>, options?: {
44
+ initialValue?: T;
45
+ interpolate?: (start: T, end: T, delta: number) => T;
46
+ duration?: number;
47
+ easing?: (t: number) => number;
48
+ equals?: (a: T, b: T) => boolean;
49
+ }): Prop<T>;
50
+ export declare function computedRecord<T extends Record<string, Value<unknown>>, U>(record: T, fn: (value: RemoveSignals<T>) => U): Computed<U>;
package/std/signal.d.ts CHANGED
@@ -1,10 +1,9 @@
1
+ import { Value } from '../types/domain';
2
+
1
3
  declare const $isSignal = "$__signal__";
2
4
  declare const $isProp = "$__prop__";
3
5
  declare const $isComputed = "$__computed__";
4
6
  export type AnySignal<T = any> = Signal<T> | Prop<T> | Computed<T>;
5
- /**
6
- * @category Signal Implementation
7
- */
8
7
  export declare class Signal<T> {
9
8
  readonly equals: (a: T, b: T) => boolean;
10
9
  static ofPromise<T>(promise: Promise<T>, init: T, recover?: (error: unknown) => T, equals?: (a: T, b: T) => boolean): Signal<T>;
@@ -42,9 +41,6 @@ export declare class Signal<T> {
42
41
  readonly count: () => Computed<number>;
43
42
  readonly setDerivative: <U>(computed: Computed<U>) => void;
44
43
  }
45
- /**
46
- * @category Signal Implementation
47
- */
48
44
  export declare class Computed<T> extends Signal<T> {
49
45
  private readonly _fn;
50
46
  static is<T = unknown>(value: unknown): value is Computed<T>;
@@ -54,7 +50,9 @@ export declare class Computed<T> extends Signal<T> {
54
50
  readonly setDirty: () => void;
55
51
  protected _scheduleCount: number;
56
52
  protected readonly scheduleNotify: () => void;
53
+ /** {@inheritDoc Signal.get} */
57
54
  readonly get: () => T;
55
+ /** {@inheritDoc Signal.value} */
58
56
  get value(): T;
59
57
  }
60
58
  export type ReducerEffect<S, A> = (data: {
@@ -63,9 +61,6 @@ export type ReducerEffect<S, A> = (data: {
63
61
  action: A;
64
62
  dispatch: (action: A) => void;
65
63
  }) => void;
66
- /**
67
- * @category Signal Implementation
68
- */
69
64
  export declare class Prop<T> extends Signal<T> {
70
65
  static is<T = unknown>(value: unknown): value is Prop<T>;
71
66
  protected readonly [$isProp] = true;
@@ -74,64 +69,12 @@ export declare class Prop<T> extends Signal<T> {
74
69
  readonly reducer: <A>(fn: (acc: T, value: A) => T, ...effects: ReducerEffect<T, A>[]) => (action: A) => void;
75
70
  readonly iso: <U>(to: (value: T) => U, from: (value: U) => T, equals?: (a: U, b: U) => boolean) => Prop<U>;
76
71
  readonly atProp: <K extends keyof T>(key: K) => Prop<T[K]>;
72
+ /** {@inheritDoc Signal.get} */
77
73
  get value(): T;
78
74
  set value(value: T);
79
75
  }
80
- export declare function computed<T>(fn: () => T, signals: Array<AnySignal>, equals?: (a: T, b: T) => boolean): Computed<T>;
81
- export declare function effect(fn: () => void, signals: Array<AnySignal>): () => void;
82
- export declare function prop<T>(value: T, equals?: (a: T, b: T) => boolean): Prop<T>;
83
- export declare function signal<T>(value: T, equals?: (a: T, b: T) => boolean): Signal<T>;
84
- export declare class MemoryStore {
85
- private readonly _store;
86
- getItem: (key: string) => string | null;
87
- setItem: (key: string, value: string) => void;
88
- }
89
- export declare function propOfStorage<T>({ key, defaultValue, store, serialize, deserialize, equals, onLoad, }: {
90
- key: string;
91
- defaultValue: T | (() => T);
92
- store: {
93
- getItem: (key: string) => string | null;
94
- setItem: (key: string, value: string) => void;
95
- };
96
- serialize?: (v: T) => string;
97
- deserialize?: (v: string) => T;
98
- equals?: (a: T, b: T) => boolean;
99
- onLoad?: (value: T) => T;
100
- }): Prop<T>;
101
- export declare function propOfLocalStorage<T>(options: {
102
- key: string;
103
- defaultValue: T | (() => T);
104
- serialize?: (v: T) => string;
105
- deserialize?: (v: string) => T;
106
- equals?: (a: T, b: T) => boolean;
107
- onLoad?: (value: T) => T;
108
- }): Prop<T>;
109
- export declare function propOfSessionStorage<T>(options: {
110
- key: string;
111
- defaultValue: T | (() => T);
112
- serialize?: (v: T) => string;
113
- deserialize?: (v: string) => T;
114
- equals?: (a: T, b: T) => boolean;
115
- onLoad?: (value: T) => T;
116
- }): Prop<T>;
117
- export declare function animate<T>(initialValue: T, fn: () => T, signals: Array<AnySignal>, options?: {
118
- interpolate?: (start: T, end: T, delta: number) => T;
119
- duration?: Value<number>;
120
- easing?: (t: number) => number;
121
- equals?: (a: T, b: T) => boolean;
122
- }): Prop<T>;
123
- export declare function animateOne<T>(signal: Signal<T>, options?: {
124
- initialValue?: T;
125
- interpolate?: (start: T, end: T, delta: number) => T;
126
- duration?: number;
127
- easing?: (t: number) => number;
128
- equals?: (a: T, b: T) => boolean;
129
- }): Prop<T>;
130
- export type Value<T> = Signal<T> | T;
131
- export type NValue<T> = Value<T> | Value<T | null> | Value<T | undefined> | Value<T | null | undefined> | null | undefined;
132
- export type GetValueType<T> = T extends Signal<infer V> ? V : T;
133
- export type RemoveSignals<T extends Record<string | number | symbol, Value<unknown>>, K extends (string | number | symbol) & keyof T = keyof T> = {
134
- [k in K]: GetValueType<T[k]>;
135
- };
136
- export declare function computedRecord<T extends Record<string, Value<unknown>>, U>(record: T, fn: (value: RemoveSignals<T>) => U): Computed<U>;
76
+ export declare function useComputed<T>(fn: () => T, dependencies: Array<AnySignal>, equals?: (a: T, b: T) => boolean): Computed<T>;
77
+ export declare function useEffect(fn: () => void, signals: Array<AnySignal>): () => void;
78
+ export declare function useProp<T>(value: T, equals?: (a: T, b: T) => boolean): Prop<T>;
79
+ export declare function useSignal<T>(value: T, equals?: (a: T, b: T) => boolean): Signal<T>;
137
80
  export {};
package/types/domain.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { DOMContext } from '../dom/dom-context';
2
- import { Value } from '../std/signal';
2
+ import { Signal } from '../std/signal';
3
3
 
4
4
  export type Renderable = (ctx: DOMContext) => Clear;
5
5
  export type TNode = Renderable | Value<string> | undefined | null | Renderable[];
@@ -12,3 +12,9 @@ export interface Size {
12
12
  readonly width: number;
13
13
  readonly height: number;
14
14
  }
15
+ export type Value<T> = Signal<T> | T;
16
+ export type NValue<T> = Value<T> | Value<T | null> | Value<T | undefined> | Value<T | null | undefined> | null | undefined;
17
+ export type GetValueType<T> = T extends Signal<infer V> ? V : T;
18
+ export type RemoveSignals<T extends Record<string | number | symbol, Value<unknown>>, K extends (string | number | symbol) & keyof T = keyof T> = {
19
+ [k in K]: GetValueType<T[k]>;
20
+ };
@@ -1,3 +0,0 @@
1
- import { DOMContext } from '../dom/dom-context';
2
-
3
- export declare const DOMEl: (element: Element) => (ctx: DOMContext) => (removeTree: boolean) => void;