nuclo 0.1.96 → 0.1.97

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,7 +1,7 @@
1
1
  {
2
2
  "name": "nuclo",
3
3
  "private": false,
4
- "version": "0.1.96",
4
+ "version": "0.1.97",
5
5
  "type": "module",
6
6
  "main": "./dist/nuclo.cjs",
7
7
  "module": "./dist/nuclo.js",
@@ -1,8 +1,22 @@
1
1
  declare global {
2
- // Dynamic list function types
3
- export type ListRenderFunction<T> = (item: T, index: number) => ExpandedElement<any> | NodeModFn<any>;
4
- export type ListItemsProvider<T> = () => T[];
5
- export function list<T>(itemsProvider: ListItemsProvider<T>, render: ListRenderFunction<T>): NodeModFn<any>;
2
+ // Dynamic list function types - supports both HTML and SVG elements
3
+ export type ListRenderFunction<T, TTagName extends ElementTagName = ElementTagName> = (
4
+ item: T,
5
+ index: number
6
+ ) => ExpandedElement<TTagName>
7
+ | NodeModFn<TTagName>
8
+ | Node
9
+ | null
10
+ | ((parent?: ExpandedElement<TTagName>, index?: number) => ExpandedElement<TTagName> | SVGElement | Node); // Support functions with optional params (like SVG builders)
11
+
12
+ export type ListItemsProvider<T> = () => readonly T[];
13
+
14
+ // List returns a function typed to be compatible with both HTML (NodeModFn) and SVG (SVGElementModifierFn) contexts
15
+ // Note: The implementation allows optional parameters, but the type signature matches the stricter requirement
16
+ export function list<T, TTagName extends ElementTagName = ElementTagName>(
17
+ itemsProvider: ListItemsProvider<T>,
18
+ render: ListRenderFunction<T, TTagName>
19
+ ): (parent: ExpandedElement<TTagName>, index: number) => Comment;
6
20
  }
7
21
 
8
22
  export {};
@@ -2,72 +2,75 @@ declare global {
2
2
  // SVG attribute types that accept string values for all SVG properties
3
3
  // This is needed because SVG DOM properties like 'width' are SVGAnimatedLength,
4
4
  // but we set them as strings using setAttribute()
5
+ // Supports reactive values (functions) for dynamic attributes
5
6
  export type SVGAttributes = {
6
7
  // Common SVG attributes
7
- width?: string | number;
8
- height?: string | number;
9
- viewBox?: string;
10
- fill?: string;
11
- stroke?: string;
12
- "stroke-width"?: string | number;
13
- "stroke-linecap"?: "butt" | "round" | "square";
14
- "stroke-linejoin"?: "miter" | "round" | "bevel";
15
- "stroke-dasharray"?: string;
16
- "stroke-dashoffset"?: string | number;
17
- opacity?: string | number;
18
- "fill-opacity"?: string | number;
19
- "stroke-opacity"?: string | number;
20
- transform?: string;
21
- className?: string;
22
- id?: string;
8
+ width?: string | number | (() => string | number);
9
+ height?: string | number | (() => string | number);
10
+ viewBox?: string | (() => string);
11
+ fill?: string | (() => string);
12
+ stroke?: string | (() => string);
13
+ "stroke-width"?: string | number | (() => string | number);
14
+ "stroke-linecap"?: "butt" | "round" | "square" | (() => "butt" | "round" | "square");
15
+ "stroke-linejoin"?: "miter" | "round" | "bevel" | (() => "miter" | "round" | "bevel");
16
+ "stroke-dasharray"?: string | (() => string);
17
+ "stroke-dashoffset"?: string | number | (() => string | number);
18
+ opacity?: string | number | (() => string | number);
19
+ "fill-opacity"?: string | number | (() => string | number);
20
+ "stroke-opacity"?: string | number | (() => string | number);
21
+ transform?: string | (() => string);
22
+ className?: string | (() => string);
23
+ id?: string | (() => string);
23
24
 
24
25
  // Path attributes
25
- d?: string;
26
+ d?: string | (() => string);
26
27
 
27
28
  // Circle/Ellipse attributes
28
- cx?: string | number;
29
- cy?: string | number;
30
- r?: string | number;
31
- rx?: string | number;
32
- ry?: string | number;
29
+ cx?: string | number | (() => string | number);
30
+ cy?: string | number | (() => string | number);
31
+ r?: string | number | (() => string | number);
32
+ rx?: string | number | (() => string | number);
33
+ ry?: string | number | (() => string | number);
33
34
 
34
35
  // Line attributes
35
- x1?: string | number;
36
- y1?: string | number;
37
- x2?: string | number;
38
- y2?: string | number;
36
+ x1?: string | number | (() => string | number);
37
+ y1?: string | number | (() => string | number);
38
+ x2?: string | number | (() => string | number);
39
+ y2?: string | number | (() => string | number);
39
40
 
40
41
  // Rect attributes
41
- x?: string | number;
42
- y?: string | number;
42
+ x?: string | number | (() => string | number);
43
+ y?: string | number | (() => string | number);
43
44
 
44
45
  // Polygon/Polyline attributes
45
- points?: string;
46
+ points?: string | (() => string);
46
47
 
47
48
  // Text attributes
48
- "text-anchor"?: "start" | "middle" | "end";
49
- "dominant-baseline"?: string;
50
- "font-family"?: string;
51
- "font-size"?: string | number;
52
- "font-weight"?: string | number;
49
+ "text-anchor"?: "start" | "middle" | "end" | (() => "start" | "middle" | "end");
50
+ "dominant-baseline"?: string | (() => string);
51
+ "font-family"?: string | (() => string);
52
+ "font-size"?: string | number | (() => string | number);
53
+ "font-weight"?: string | number | (() => string | number);
53
54
 
54
55
  // Gradient attributes
55
- offset?: string;
56
- "stop-color"?: string;
57
- "stop-opacity"?: string | number;
56
+ offset?: string | (() => string);
57
+ "stop-color"?: string | (() => string);
58
+ "stop-opacity"?: string | number | (() => string | number);
58
59
 
59
60
  // Use element
60
- href?: string;
61
+ href?: string | (() => string);
61
62
 
62
63
  // Filter attributes
63
- filter?: string;
64
+ filter?: string | (() => string);
64
65
 
65
66
  // Clipping and masking
66
- "clip-path"?: string;
67
- mask?: string;
67
+ "clip-path"?: string | (() => string);
68
+ mask?: string | (() => string);
68
69
 
69
- // Allow any other string attributes
70
- [key: string]: string | number | undefined;
70
+ // Allow any other string attributes (including reactive functions)
71
+ // Using a more restrictive type to maintain type safety
72
+ } & {
73
+ [K in string]?: string | number | (() => string) | (() => number);
71
74
  };
72
75
 
73
76
  // SVG element modifier types
@@ -77,12 +80,13 @@ declare global {
77
80
  | SVGAttributes
78
81
  | SVGElementTagNameMap[TTagName]
79
82
  | SVGElement // Allow any SVG element as a child
80
- | ((parent: SVGElementTagNameMap[TTagName], index: number) => SVGElement); // Allow SVG element builders as children
83
+ | Node // Allow any DOM Node (including Comment, Text, etc.)
84
+ | ((parent: SVGElementTagNameMap[TTagName], index: number) => SVGElement | Node); // Allow SVG element and Node builders as children
81
85
 
82
86
  export type SVGElementModifierFn<TTagName extends keyof SVGElementTagNameMap = keyof SVGElementTagNameMap> = (
83
87
  parent: SVGElementTagNameMap[TTagName],
84
88
  index: number,
85
- ) => SVGElementModifier<TTagName> | void;
89
+ ) => SVGElementModifier<TTagName> | Node | void;
86
90
 
87
91
  // SVG builder type - returns a NodeModFn-compatible function
88
92
  // Parameters are optional to allow standalone usage (e.g., svg()() for creating detached SVG)