@tempots/dom 19.3.1 → 20.0.1

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": "19.3.1",
3
+ "version": "20.0.1",
4
4
  "type": "module",
5
5
  "main": "./index.cjs",
6
6
  "module": "./index.js",
@@ -1,5 +1,4 @@
1
1
  import { Renderable, TNode } from '../types/domain';
2
-
3
2
  /**
4
3
  * Options for the `Async` component.
5
4
  * @typeParam T - The type of the value.
@@ -1,5 +1,4 @@
1
1
  import { NValue, Renderable, Value } from '../types/domain';
2
-
3
2
  /**
4
3
  * The `attr` object allows to create any HTML attribute. Either a literal value
5
4
  * or `Signal<?>` can be passed as a value. The type of the value is inferred
@@ -1,7 +1,6 @@
1
1
  import { Prop } from '../std/signal';
2
2
  import { Renderable } from '../types/domain';
3
3
  import { on } from './handler';
4
-
5
4
  /**
6
5
  * Binds a `Date` property to an input element. The binding is two-way.
7
6
  * Changes to the input element will update the property but will only be
@@ -1,7 +1,6 @@
1
1
  import { Signal } from '../std/signal';
2
2
  import { Renderable, TNode } from '../types/domain';
3
3
  import { ElementPosition } from '../std/position';
4
-
5
4
  /**
6
5
  * Options for configuring a conjunction.
7
6
  * @public
@@ -1,5 +1,4 @@
1
1
  import { TNode, Renderable, ProviderMark } from '../types/domain';
2
-
3
2
  /**
4
3
  * Converts a tuple type `T` into an array of `ProviderMark` types.
5
4
  * If `T` is an empty tuple, returns an empty array.
@@ -1,5 +1,4 @@
1
1
  import { Renderable } from '../types/domain';
2
-
3
2
  /**
4
3
  * Creates a renderable DOM node.
5
4
  *
@@ -1,5 +1,4 @@
1
1
  import { TNode, Renderable } from '../types/domain';
2
-
3
2
  /**
4
3
  * Converts a TNode into a Renderable.
5
4
  * @param child - The TNode to convert.
@@ -1,5 +1,4 @@
1
1
  import { Renderable } from '../types/domain';
2
-
3
2
  /**
4
3
  * Represents an empty renderable function.
5
4
  * @returns A renderable function that does nothing.
@@ -1,6 +1,5 @@
1
1
  import { TNode, Renderable } from '../types/domain';
2
2
  import { Signal } from '../std/signal';
3
-
4
3
  /**
5
4
  * Represents a function that ensures a signal has a value before rendering a TNode.
6
5
  *
@@ -1,7 +1,6 @@
1
1
  import { TNode, Renderable } from '../types/domain';
2
2
  import { Signal } from '../std/signal';
3
3
  import { ElementPosition } from '../std/position';
4
-
5
4
  /**
6
5
  * Renders a list of items based on a signal of arrays.
7
6
  *
@@ -1,5 +1,4 @@
1
1
  import { TNode, Renderable } from '../types/domain';
2
-
3
2
  /**
4
3
  * Creates a fragment renderable that represents a collection of child renderables.
5
4
  *
@@ -1,5 +1,4 @@
1
1
  import { Renderable } from '../types/domain';
2
-
3
2
  /**
4
3
  * Attaches an event handler to the 'click' event that triggers when a checkbox is checked or unchecked.
5
4
  * @param fn - The callback function to be executed when the checkbox is clicked.
@@ -1,6 +1,5 @@
1
1
  import { Renderable } from '../types/domain';
2
2
  import { Signal } from '../std/signal';
3
-
4
3
  /**
5
4
  * Maps the values emitted by a signal to a renderable function and returns a new renderable function.
6
5
  *
@@ -1,6 +1,5 @@
1
1
  import { Signal } from '../std/signal';
2
2
  import { Renderable } from '../types/domain';
3
-
4
3
  /**
5
4
  * Returns a renderable component that displays the given `display` component
6
5
  * when the `signal` contains a non-empty array, and the `whenEmpty` component
@@ -1,6 +1,5 @@
1
1
  import { DOMContext } from '../dom/dom-context';
2
2
  import { Clear, Renderable } from '../types/domain';
3
-
4
3
  /**
5
4
  * Returns a renderable function that executes the given function with the current DOMContext as argument.
6
5
  *
@@ -1,6 +1,5 @@
1
1
  import { Signal } from '../std/signal';
2
2
  import { Renderable, TNode } from '../types/domain';
3
-
4
3
  /**
5
4
  * Represents a set of options for a one-of type.
6
5
  * @typeParam T - The type of the options.
@@ -1,5 +1,4 @@
1
1
  import { Clear, Renderable } from '../types/domain';
2
-
3
2
  /**
4
3
  * Executes a callback function when the parent element is mounted in the DOM.
5
4
  *
@@ -1,6 +1,5 @@
1
1
  import { Renderable } from '../types/domain';
2
2
  import { DOMContext } from '../dom/dom-context';
3
-
4
3
  /**
5
4
  * Creates a renderable function that will be called when the component is unmounted.
6
5
  * @param fn - The function to be called when the component is unmounted.
@@ -1,5 +1,4 @@
1
1
  import { Renderable, TNode } from '../types/domain';
2
-
3
2
  /**
4
3
  * Renders the given `node` into a DOM element selected by the provided `selector`.
5
4
  * Throws an error if the element cannot be found.
@@ -1,5 +1,4 @@
1
1
  import { TNode, Renderable, ProviderMark } from '../types/domain';
2
-
3
2
  /**
4
3
  * Represents a provider function that takes a `TNode` and returns a `Renderable`.
5
4
  * @param node - The node to be rendered.
@@ -1,6 +1,5 @@
1
1
  import { Renderable } from '../types/domain';
2
2
  import { DOMContext } from '../dom/dom-context';
3
-
4
3
  /**
5
4
  * Renders the given `renderable` with the provided `ctx` DOM context.
6
5
  *
@@ -1,7 +1,6 @@
1
1
  import { ElementPosition } from '../std/position';
2
2
  import { Signal } from '../std/signal';
3
3
  import { TNode, Renderable } from '../types/domain';
4
-
5
4
  /**
6
5
  * Creates a renderable function that repeats a given element a specified number of times.
7
6
  *
@@ -1,5 +1,4 @@
1
1
  import { NValue, Renderable } from '../types/domain';
2
-
3
2
  /**
4
3
  * A collection of functions to create style renderables.
5
4
  * @public
@@ -1,5 +1,4 @@
1
1
  import { TNode, Renderable } from '../types/domain';
2
-
3
2
  /**
4
3
  * Represents the options for a task.
5
4
  *
@@ -1,6 +1,5 @@
1
1
  import { Renderable, Value } from '../types/domain';
2
2
  import { Signal } from '../std/signal';
3
-
4
3
  /**
5
4
  * @internal
6
5
  */
@@ -1,6 +1,5 @@
1
1
  import { Renderable, TNode } from '../types/domain';
2
2
  import { Signal } from '../std/signal';
3
-
4
3
  /**
5
4
  * Renders the `then` node if the `condition` is true, otherwise renders the `otherwise` node.
6
5
  *
@@ -1,6 +1,5 @@
1
1
  import { RemoveSignals, Value } from '../types/domain';
2
2
  import { AnySignal, Computed, Prop, Signal } from './signal';
3
-
4
3
  /**
5
4
  * Represents a memory store that stores key-value pairs.
6
5
  *
package/std/signal.d.ts CHANGED
@@ -1,5 +1,4 @@
1
- import { Value } from '../types/domain';
2
-
1
+ import { GetValueTypes, Value } from '../types/domain';
3
2
  /**
4
3
  * Represents any type of signal.
5
4
  * It can be a Signal, Prop, or Computed.
@@ -190,10 +189,14 @@ export declare class Signal<T> {
190
189
  */
191
190
  readonly at: <K extends keyof T>(key: K) => Signal<T[K]>;
192
191
  /**
193
- * Represents a collection of signals for each key in the value of the signal.
192
+ * @internal
193
+ */
194
+ private _$;
195
+ /**
196
+ * Represents a collection of signals mapping to each key/field in the wrapped value.
194
197
  * @typeParam T - The type of the signals.
195
198
  */
196
- readonly $: AtGetter<T>;
199
+ get $(): AtGetter<T>;
197
200
  readonly filter: (fn: (value: T) => boolean, startValue?: T) => Computed<T>;
198
201
  /**
199
202
  * Returns a new Computed object that applies the provided mapping function to the value of this Signal,
@@ -419,6 +422,16 @@ export declare class Prop<T> extends Signal<T> {
419
422
  * @public
420
423
  */
421
424
  export declare const makeComputed: <T>(fn: () => T, dependencies: Array<AnySignal>, equals?: (a: T, b: T) => boolean) => Computed<T>;
425
+ /**
426
+ * Creates a computed signal that depends on other signals or literal values and updates when any of the dependencies change.
427
+ *
428
+ * @typeParam T - The type of the argument values.
429
+ * @param fn - The function that computes the value.
430
+ * @param equals - The equality function used to compare the previous and current computed values.
431
+ * @returns - The computed signal.
432
+ * @public
433
+ */
434
+ export declare const makeComputedOf: <T extends Value<unknown>[]>(...args: T) => <O>(fn: (...args: GetValueTypes<T>) => O, equals?: (a: O, b: O) => boolean) => Computed<O>;
422
435
  /**
423
436
  * Executes the provided function `fn` whenever any of the signals in the `signals` array change.
424
437
  * Returns a disposable object that can be used to stop the effect.
@@ -429,6 +442,14 @@ export declare const makeComputed: <T>(fn: () => T, dependencies: Array<AnySigna
429
442
  * @public
430
443
  */
431
444
  export declare const makeEffect: (fn: () => void, signals: Array<AnySignal>) => () => void;
445
+ /**
446
+ * Creates an effect that depends on other signals or literal values and updates when any of the dependencies change.
447
+ *
448
+ * @param args - The array of signals or literal values that the effect depends on.
449
+ * @returns A disposable object that can be used to stop the effect.
450
+ * @public
451
+ */
452
+ export declare const makeEffectOf: <T extends Value<unknown>[]>(...args: T) => (fn: (...args: GetValueTypes<T>) => void) => void;
432
453
  /**
433
454
  * Creates a new Prop object with the specified value and equality function.
434
455
  *
package/types/domain.d.ts CHANGED
@@ -1,6 +1,5 @@
1
1
  import { DOMContext } from '../dom/dom-context';
2
2
  import { Signal } from '../std/signal';
3
-
4
3
  /**
5
4
  * Represents a function that can be rendered in the DOM.
6
5
  * @param ctx - The DOM context for rendering.
@@ -67,6 +66,13 @@ export type NValue<T> = Value<T> | Value<T | null> | Value<T | undefined> | Valu
67
66
  * @public
68
67
  */
69
68
  export type GetValueType<T> = T extends Signal<infer V> ? V : T;
69
+ /**
70
+ * Gets the value types of a given array of Value types.
71
+ * @public
72
+ */
73
+ export type GetValueTypes<T extends Value<unknown>[]> = {
74
+ [K in keyof T]: GetValueType<T[K]>;
75
+ };
70
76
  /**
71
77
  * Removes signals from a given object type and returns a new object type
72
78
  * with only the non-signal properties.
@@ -1,79 +0,0 @@
1
- export type AnimatableProps = {
2
- width?: number;
3
- maxWidth?: number;
4
- minWidth?: number;
5
- height?: number;
6
- maxHeight?: number;
7
- minHeight?: number;
8
- lineHeight?: number;
9
- opacity?: number;
10
- top?: number;
11
- left?: number;
12
- right?: number;
13
- bottom?: number;
14
- padding?: number;
15
- paddingTop?: number;
16
- paddingBottom?: number;
17
- paddingLeft?: number;
18
- paddingRight?: number;
19
- margin?: number;
20
- marginTop?: number;
21
- marginBottom?: number;
22
- marginLeft?: number;
23
- marginRight?: number;
24
- fontSize?: number;
25
- letterSpacing?: number;
26
- color?: string;
27
- backgroundColor?: string;
28
- borderColor?: string;
29
- borderWidth?: number;
30
- borderRadius?: number;
31
- boxShadow?: string;
32
- textShadow?: string;
33
- outlineWidth?: number;
34
- outlineColor?: string;
35
- translateX?: number;
36
- translateY?: number;
37
- translateZ?: number;
38
- rotateX?: number;
39
- rotateY?: number;
40
- rotateZ?: number;
41
- scaleX?: number;
42
- scaleY?: number;
43
- scaleZ?: number;
44
- skewX?: number;
45
- skewY?: number;
46
- grayScale?: number;
47
- sepia?: number;
48
- saturate?: number;
49
- hueRotate?: number;
50
- invert?: number;
51
- brightness?: number;
52
- contrast?: number;
53
- blur?: number;
54
- };
55
- export type ColorChannels = [
56
- number,
57
- number,
58
- number,
59
- number,
60
- 'rgba' | 'hex' | 'hsla'
61
- ];
62
- export declare const parseColorChannels: (color: string) => ColorChannels;
63
- export interface BoxShadow {
64
- inset: boolean;
65
- x: number;
66
- y: number;
67
- blur: number;
68
- spread: number;
69
- color: string;
70
- }
71
- export declare const colorChannelsToString: (channels: ColorChannels) => string;
72
- export declare const interpolateColor: (startColor: string, endColor: string) => ((t: number) => string);
73
- export declare const interpolateShadow: (startShadow: string, endShadow: string) => ((t: number) => string);
74
- export declare const getComputedAnimatableProp: (styles: CSSStyleDeclaration, key: keyof AnimatableProps) => AnimatableProps[typeof key];
75
- export declare const getComputedAnimatable: (el: HTMLElement, styles: AnimatableProps) => AnimatableProps;
76
- export declare const applyAnimatableProp: (el: HTMLElement, key: keyof AnimatableProps, value: AnimatableProps[typeof key]) => void;
77
- export declare const applyInterpolatedAnimatableProp: (el: HTMLElement, key: keyof AnimatableProps, from: AnimatableProps[typeof key], to: AnimatableProps[typeof key], progress: number) => void;
78
- export declare const applyInterpolatedAnimatable: (el: HTMLElement, from: AnimatableProps, to: AnimatableProps, progress: number) => void;
79
- export declare const applyAnimatable: (el: HTMLElement, styles: AnimatableProps) => void;
@@ -1,25 +0,0 @@
1
- /**
2
- * Options for handling anchor click events.
3
- * @public
4
- */
5
- export type HandleAnchorClickOptions = {
6
- /**
7
- * A boolean indicating whether to check the anchor's href for a file extension.
8
- */
9
- checkExtension?: boolean | string[];
10
- /**
11
- * A boolean indicating whether to check if the anchor's href points to an external URL.
12
- */
13
- checkExternalUrl?: boolean;
14
- };
15
- /**
16
- * Handles anchor click events, optionally checking for external URLs and file extensions.
17
- *
18
- * @param callback - A function that is called when the anchor click should be handled. The function should return a boolean indicating whether the default anchor click behavior should be prevented.
19
- * @param options - An optional object with the following properties:
20
- * - `checkExtension`: A boolean indicating whether to check the anchor's href for a file extension. Defaults to `true`.
21
- * - `checkExternalUrl`: A boolean indicating whether to check if the anchor's href points to an external URL. Defaults to `true`.
22
- * @returns A function that handles the anchor click event, calling the provided callback and preventing the default behavior if the callback returns `true`.
23
- * @public
24
- */
25
- export declare const handleAnchorClick: (callback: () => boolean, { checkExtension, checkExternalUrl, }?: HandleAnchorClickOptions) => (e: MouseEvent) => void;