sigpro 2.0.4 → 2.0.7

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/sigpro.d.ts CHANGED
@@ -1,13 +1,8 @@
1
1
  /**
2
2
  * SigPro — Type Definitions
3
3
  *
4
- * A minimal reactive library built on an alien-signals-class push-pull core
5
- * with a thin, direct-to-DOM rendering layer.
6
- *
7
- * - Explicit API: `signal()`, `computed()`, `effect()`
8
- * - Lazy computeds with checkDirty verification
9
- * - Atomic updates: no virtual DOM, no diffing
10
- * - Built-in: hash router, i18n, localStorage signals, DI, fetch helper
4
+ * Minimal reactive library: alien-signals-class push-pull core + direct-to-DOM
5
+ * rendering. No VDOM, no diffing, no build step.
11
6
  */
12
7
 
13
8
  // ============================================================================
@@ -15,67 +10,35 @@
15
10
  // ============================================================================
16
11
 
17
12
  /**
18
- * A reactive signal. Call with no args to read, with a value or an updater
19
- * function to write.
20
- *
21
- * @example
22
- * const count = signal(0);
23
- * count(); // read → 0
24
- * count(1); // write
25
- * count(c => c + 1);// updater
13
+ * A reactive signal. Call with no args to read, with a value to write.
26
14
  */
27
15
  export interface Signal<T> {
28
16
  (): T;
29
- (value: T | ((prev: T) => T)): void;
17
+ (value: T): void;
30
18
  }
31
19
 
32
- /**
33
- * Creates a reactive signal with an initial value.
34
- */
35
20
  export function signal<T>(initialValue: T): Signal<T>;
36
21
 
37
- /**
38
- * A read-only derived value. Call with no args to read.
39
- */
22
+ /** A read-only derived value. Call with no args to read. */
40
23
  export type ReadonlySignal<T> = () => T;
41
24
 
42
- /**
43
- * Creates a derived value computed lazily from dependencies.
44
- * Recomputed on read only when dependencies have actually changed.
45
- */
46
25
  export function computed<T>(getter: (oldValue?: T) => T): ReadonlySignal<T>;
47
26
 
48
27
  /**
49
- * Runs `fn` reactively. Re-executes when its tracked dependencies change.
50
- * `fn` may return a cleanup function, run before the next re-execution and
51
- * on stop.
52
- *
53
- * @returns A function that stops the effect.
28
+ * Runs `fn` reactively. Re-executes when tracked deps change. `fn` may
29
+ * return a cleanup function, run before the next re-execution and on stop.
54
30
  */
55
31
  export function effect(fn: () => void | (() => void)): () => void;
56
32
 
57
- /**
58
- * Creates a scope that groups child effects. Does not track dependencies
59
- * and does not re-execute. Returns a function that disposes all effects
60
- * created inside.
61
- */
62
- export function effectScope(fn: () => void): () => void;
63
-
64
- /**
65
- * Runs `fn` without tracking signal reads as dependencies.
66
- */
33
+ /** Runs `fn` without tracking reads as dependencies. */
67
34
  export function untrack<T>(fn: () => T): T;
68
35
 
69
- /**
70
- * Batches multiple signal writes into a single flush.
71
- */
36
+ /** Batches multiple signal writes into a single flush. */
72
37
  export function batch<T>(fn: () => T): T;
73
38
 
74
39
  /**
75
- * Watches a signal or getter and calls `cb` when the value changes.
76
- * Skips the initial run by default. Set `immediate` to call once on setup.
77
- *
78
- * @returns A function that stops the watcher.
40
+ * Watches a signal/getter and calls `cb` when the value changes. Skips the
41
+ * initial run by default; pass `{ immediate: true }` to fire once on setup.
79
42
  */
80
43
  export function watch<T>(
81
44
  source: Signal<T> | ReadonlySignal<T>,
@@ -84,59 +47,46 @@ export function watch<T>(
84
47
  ): () => void;
85
48
 
86
49
  /**
87
- * Creates a signal persisted to `localStorage` under `key`.
88
- * The value is JSON-serialized. Falls back to `initial` if unavailable
89
- * or if the stored value cannot be parsed.
50
+ * Signal persisted to `localStorage` under `key` (JSON-serialized).
51
+ * Falls back to `initial` if unavailable or unparseable.
90
52
  */
91
53
  export function local<T>(key: string, initial: T): Signal<T>;
92
54
 
93
- // ============================================================================
94
- // Dependency Injection
95
- // ============================================================================
96
-
97
- /**
98
- * Provides a value in the current effect/scope context.
99
- * Only visible to descendants.
100
- */
101
- export function provide<T = any>(key: string | symbol, value: T): void;
102
-
103
- /**
104
- * Injects the nearest value for `key` from an ancestor context.
105
- * Returns `fallback` if not found.
106
- */
107
- export function inject<T = any>(key: string | symbol, fallback?: T): T | undefined;
108
-
109
55
  // ============================================================================
110
56
  // DOM Creation
111
57
  // ============================================================================
112
58
 
113
- /**
114
- * A prop value may be static or a reactive getter.
115
- */
59
+ /** Static value or reactive getter. */
116
60
  export type PropValue<T = any> = T | (() => T);
117
61
 
118
62
  /**
119
- * Props accepted by `h` and all tag helpers.
63
+ * Props accepted by `h` and tag helpers.
120
64
  *
121
- * Special props:
122
- * - `ref`: function `(el) => void` or object with `.current`
123
- * - `html`: sets `innerHTML` reactively (skips `children` if present)
124
- * - `on*`: DOM event listeners (case-insensitive: `onclick`, `onInput`)
125
- * - any other: assigned to the element (property if it exists, otherwise attribute)
65
+ * Special keys:
66
+ * - `ref`: function or `{ current }` object
67
+ * - `on*`: DOM event listeners (e.g. `onclick`, `onInput`)
68
+ * - `class` / `className`: element class
69
+ * - `style`: CSS string or object of properties (camelCase keys,
70
+ * `--custom` keys go through `setProperty`)
71
+ * - anything else: assigned as property if present on the element,
72
+ * otherwise set as attribute
73
+ *
74
+ * For security, `innerHTML`, `outerHTML` and `srcdoc` are ignored.
75
+ * URL props (`href`, `src`, `action`, `formAction`, `poster`, `data`,
76
+ * `xlink:href`) are restricted to `http(s)`, `mailto`, `tel`, `blob`,
77
+ * and safe `data:image/*` for images.
126
78
  */
127
79
  export type Props = {
128
80
  ref?: ((el: Element) => void) | { current: Element | null };
129
- html?: PropValue<string | null | undefined>;
130
81
  class?: PropValue<string | null | undefined>;
131
82
  className?: PropValue<string | null | undefined>;
132
- style?: PropValue<string | null | undefined>;
83
+ style?: PropValue<
84
+ string | Record<string, string | number | null | false> | null | undefined
85
+ >;
133
86
  [key: string]: PropValue<any>;
134
87
  };
135
88
 
136
- /**
137
- * Any value accepted as a child: nodes, strings, numbers, arrays, or
138
- * reactive getter functions returning any of these.
139
- */
89
+ /** Any valid child: node, primitive, array, or a reactive getter. */
140
90
  export type Child =
141
91
  | Node
142
92
  | string
@@ -148,18 +98,15 @@ export type Child =
148
98
  | Child[];
149
99
 
150
100
  /**
151
- * Creates a DOM element from a tag name, or renders a component.
152
- *
153
- * - `tag` as string → creates HTML or SVG element (auto-detected).
154
- * - `tag` as function → treated as a component: `(props, children[]) => Node | Node[]`.
155
- * - First argument may be children if it is not a plain object.
156
- * - Multiple children may be passed variadically.
101
+ * Creates an HTML/SVG element (tag: string) or renders a component
102
+ * (tag: function). The first arg after `tag` may be children when it is not
103
+ * a plain object.
157
104
  */
158
105
  export function h(
159
106
  tag: string,
160
107
  props?: Props | Child | null,
161
108
  ...children: Child[]
162
- ): Element | SVGElement;
109
+ ): Element;
163
110
 
164
111
  export function h<P extends object>(
165
112
  tag: (props: P, children: Child[]) => Node | Node[] | null,
@@ -168,10 +115,8 @@ export function h<P extends object>(
168
115
  ): Node | Node[] | null;
169
116
 
170
117
  /**
171
- * Registers all standard HTML tag names as globals (`div`, `span`, `button`,
172
- * `input`, `textarea`, `svg`, etc.).
173
- *
174
- * Must be called once at startup. Defaults to `window`.
118
+ * Registers all standard HTML tag names as globals on `target` (default
119
+ * `window`). Call once at startup.
175
120
  */
176
121
  export function exposeTags(target?: any): void;
177
122
 
@@ -180,22 +125,17 @@ export function exposeTags(target?: any): void;
180
125
  // ============================================================================
181
126
 
182
127
  /**
183
- * Mounts a component into a DOM target.
184
- *
185
- * @param component - Component function or node.
186
- * @param target - CSS selector or DOM element.
187
- * @returns A function that stops the app scope and clears the target.
128
+ * Mounts a component or node into a target. Returns a disposer that stops
129
+ * the app scope and clears the target.
188
130
  */
189
131
  export function mount(
190
- component: (props?: any) => Node | Node[] | null,
132
+ component: ((props?: any) => Node | Node[] | null) | Node | string,
191
133
  target: string | Element
192
134
  ): () => void;
193
135
 
194
136
  /**
195
- * Recursively disposes scopes and removes tracked event listeners on a node
196
- * and its descendants, then detaches it from the DOM.
197
- *
198
- * Only needed when working with nodes created outside `h()`.
137
+ * Recursively disposes scopes, removes tracked event listeners, and detaches
138
+ * the node. Only needed for nodes created outside `h()`.
199
139
  */
200
140
  export function unmount(node: Node): void;
201
141
 
@@ -204,10 +144,11 @@ export function unmount(node: Node): void;
204
144
  // ============================================================================
205
145
 
206
146
  export interface RouteDefinition {
207
- /** Path pattern: `/`, `/user/:id`, `/blog/*`, or `*` for fallback. */
147
+ /** `/`, `/user/:id`, or `*` for fallback. */
208
148
  path: string;
209
- /** Component function receiving route params, or a static node. */
210
- component: ((params: Record<string, string>) => Node | Node[] | null) | Node;
149
+ component:
150
+ | ((params: Record<string, string>) => Node | Node[] | null)
151
+ | Node;
211
152
  }
212
153
 
213
154
  export interface RouterFn {
@@ -216,14 +157,11 @@ export interface RouterFn {
216
157
  to(path: string): void;
217
158
  /** Go back in browser history. */
218
159
  back(): void;
219
- /** Returns the current path (without leading `#`). */
160
+ /** Current path (without leading `#`). */
220
161
  path(): string;
221
162
  }
222
163
 
223
- /**
224
- * Creates a hash-based router. Returns a component that renders the
225
- * matched route and re-renders on navigation.
226
- */
164
+ /** Creates a hash-based router component. */
227
165
  export function router(routes: RouteDefinition[]): RouterFn;
228
166
 
229
167
  /** Current path as a reactive signal (without leading `#`). */
@@ -232,6 +170,9 @@ export const currentPath: Signal<string>;
232
170
  /** Current route params as a reactive signal. */
233
171
  export const routerParams: Signal<Record<string, string>>;
234
172
 
173
+ /** Increments on HMR page registration; read to force route refresh. */
174
+ export const hmrTick: Signal<number>;
175
+
235
176
  // ============================================================================
236
177
  // i18n
237
178
  // ============================================================================
@@ -245,7 +186,7 @@ export const currentLocale: Signal<string>;
245
186
  * @example
246
187
  * addLang({ en: { hello: "Hello" }, es: { hello: "Hola" } });
247
188
  */
248
- export function addLang(translations: Record<string, Record<string, string>>): void;
189
+ export function addLang(obj: Record<string, Record<string, string>>): void;
249
190
 
250
191
  /** Sets the active locale if it has been registered. */
251
192
  export function setLocale(locale: string): void;
@@ -253,34 +194,38 @@ export function setLocale(locale: string): void;
253
194
  /** Reactive translation getter for a key. */
254
195
  export function t(key: string): () => string;
255
196
 
256
- /** Imperative translation read for a key. */
257
- export function tt(key: string): string;
258
-
259
197
  // ============================================================================
260
198
  // HTTP Helper
261
199
  // ============================================================================
262
200
 
263
201
  /**
264
- * JSON fetch helper. POSTs when `data` is provided, GETs otherwise.
265
- * Calls `loading(true/false)` around the request if provided.
266
- * Pass an `AbortSignal` to cancel.
202
+ * Fetch helper. POSTs when `data` is provided, GETs otherwise. Calls
203
+ * `loading(true/false)` around the request. Pass `abortSignal` to cancel.
204
+ *
205
+ * `data` may be:
206
+ * - a plain object/array/primitive → sent as JSON
207
+ * - `FormData` → sent as multipart/form-data (browser sets Content-Type)
208
+ * - `Blob` / `File` → sent as binary (browser sets Content-Type)
209
+ * - `URLSearchParams` → sent as application/x-www-form-urlencoded
210
+ *
211
+ * On non-2xx responses the returned Error has `status` and `statusText`.
212
+ * Returns `null` for 204/205 responses. Parses the response as JSON.
267
213
  */
268
214
  export function db<T = any>(
269
215
  url: string,
270
216
  data?: any | null,
271
217
  loading?: ((loading: boolean) => void) | null,
272
- signal?: AbortSignal | null
218
+ abortSignal?: AbortSignal | null
273
219
  ): Promise<T>;
274
220
 
275
221
  // ============================================================================
276
222
  // Tag Helpers (registered by `exposeTags`)
277
223
  // ============================================================================
278
224
 
279
- /**
280
- * A tag helper: `div(props?, ...children)`.
281
- * Available on `window` after calling `exposeTags()`.
282
- */
283
- export type TagHelper = (props?: Props | Child | null, ...children: Child[]) => Element;
225
+ export type TagHelper = (
226
+ props?: Props | Child | null,
227
+ ...children: Child[]
228
+ ) => Element;
284
229
 
285
230
  export const a: TagHelper;
286
231
  export const abbr: TagHelper;
@@ -353,7 +298,6 @@ export const strong: TagHelper;
353
298
  export const sub: TagHelper;
354
299
  export const summary: TagHelper;
355
300
  export const sup: TagHelper;
356
- export const svg: TagHelper;
357
301
  export const table: TagHelper;
358
302
  export const tbody: TagHelper;
359
303
  export const td: TagHelper;
@@ -376,13 +320,10 @@ declare const SigPro: {
376
320
  signal: typeof signal;
377
321
  computed: typeof computed;
378
322
  effect: typeof effect;
379
- effectScope: typeof effectScope;
380
323
  untrack: typeof untrack;
381
324
  batch: typeof batch;
382
325
  watch: typeof watch;
383
326
  local: typeof local;
384
- provide: typeof provide;
385
- inject: typeof inject;
386
327
  h: typeof h;
387
328
  mount: typeof mount;
388
329
  unmount: typeof unmount;
@@ -390,18 +331,18 @@ declare const SigPro: {
390
331
  router: typeof router;
391
332
  currentPath: typeof currentPath;
392
333
  routerParams: typeof routerParams;
334
+ hmrTick: typeof hmrTick;
393
335
  currentLocale: typeof currentLocale;
394
336
  addLang: typeof addLang;
395
337
  setLocale: typeof setLocale;
396
338
  t: typeof t;
397
- tt: typeof tt;
398
339
  db: typeof db;
399
340
  };
400
341
 
401
342
  export default SigPro;
402
343
 
403
344
  // ============================================================================
404
- // Global augmentation for browser environments
345
+ // Global augmentation
405
346
  // ============================================================================
406
347
 
407
348
  declare global {
@@ -411,13 +352,10 @@ declare global {
411
352
  signal: typeof signal;
412
353
  computed: typeof computed;
413
354
  effect: typeof effect;
414
- effectScope: typeof effectScope;
415
355
  untrack: typeof untrack;
416
356
  batch: typeof batch;
417
357
  watch: typeof watch;
418
358
  local: typeof local;
419
- provide: typeof provide;
420
- inject: typeof inject;
421
359
  h: typeof h;
422
360
  mount: typeof mount;
423
361
  unmount: typeof unmount;
@@ -425,98 +363,33 @@ declare global {
425
363
  router: typeof router;
426
364
  currentPath: typeof currentPath;
427
365
  routerParams: typeof routerParams;
366
+ hmrTick: typeof hmrTick;
428
367
  currentLocale: typeof currentLocale;
429
368
  addLang: typeof addLang;
430
369
  setLocale: typeof setLocale;
431
370
  t: typeof t;
432
- tt: typeof tt;
433
371
  db: typeof db;
434
372
 
435
- // Tag helpers (lowercase)
436
- a: TagHelper;
437
- abbr: TagHelper;
438
- article: TagHelper;
439
- aside: TagHelper;
440
- audio: TagHelper;
441
- b: TagHelper;
442
- blockquote: TagHelper;
443
- br: TagHelper;
444
- button: TagHelper;
445
- canvas: TagHelper;
446
- caption: TagHelper;
447
- cite: TagHelper;
448
- code: TagHelper;
449
- col: TagHelper;
450
- colgroup: TagHelper;
451
- datalist: TagHelper;
452
- dd: TagHelper;
453
- del: TagHelper;
454
- details: TagHelper;
455
- dfn: TagHelper;
456
- dialog: TagHelper;
457
- div: TagHelper;
458
- dl: TagHelper;
459
- dt: TagHelper;
460
- em: TagHelper;
461
- embed: TagHelper;
462
- fieldset: TagHelper;
463
- figcaption: TagHelper;
464
- figure: TagHelper;
465
- footer: TagHelper;
466
- form: TagHelper;
467
- h1: TagHelper;
468
- h2: TagHelper;
469
- h3: TagHelper;
470
- h4: TagHelper;
471
- h5: TagHelper;
472
- h6: TagHelper;
473
- header: TagHelper;
474
- hr: TagHelper;
475
- i: TagHelper;
476
- iframe: TagHelper;
477
- img: TagHelper;
478
- input: TagHelper;
479
- ins: TagHelper;
480
- kbd: TagHelper;
481
- label: TagHelper;
482
- legend: TagHelper;
483
- li: TagHelper;
484
- main: TagHelper;
485
- mark: TagHelper;
486
- meter: TagHelper;
487
- nav: TagHelper;
488
- object: TagHelper;
489
- ol: TagHelper;
490
- optgroup: TagHelper;
491
- option: TagHelper;
492
- output: TagHelper;
493
- p: TagHelper;
494
- picture: TagHelper;
495
- pre: TagHelper;
496
- progress: TagHelper;
497
- section: TagHelper;
498
- select: TagHelper;
499
- slot: TagHelper;
500
- small: TagHelper;
501
- source: TagHelper;
502
- span: TagHelper;
503
- strong: TagHelper;
504
- sub: TagHelper;
505
- summary: TagHelper;
506
- sup: TagHelper;
507
- svg: TagHelper;
508
- table: TagHelper;
509
- tbody: TagHelper;
510
- td: TagHelper;
511
- template: TagHelper;
512
- textarea: TagHelper;
513
- tfoot: TagHelper;
514
- th: TagHelper;
515
- thead: TagHelper;
516
- time: TagHelper;
517
- tr: TagHelper;
518
- u: TagHelper;
519
- ul: TagHelper;
520
- video: TagHelper;
373
+ a: TagHelper; abbr: TagHelper; article: TagHelper; aside: TagHelper;
374
+ audio: TagHelper; b: TagHelper; blockquote: TagHelper; br: TagHelper;
375
+ button: TagHelper; canvas: TagHelper; caption: TagHelper; cite: TagHelper;
376
+ code: TagHelper; col: TagHelper; colgroup: TagHelper; datalist: TagHelper;
377
+ dd: TagHelper; del: TagHelper; details: TagHelper; dfn: TagHelper;
378
+ dialog: TagHelper; div: TagHelper; dl: TagHelper; dt: TagHelper;
379
+ em: TagHelper; embed: TagHelper; fieldset: TagHelper; figcaption: TagHelper;
380
+ figure: TagHelper; footer: TagHelper; form: TagHelper; h1: TagHelper;
381
+ h2: TagHelper; h3: TagHelper; h4: TagHelper; h5: TagHelper; h6: TagHelper;
382
+ header: TagHelper; hr: TagHelper; i: TagHelper; iframe: TagHelper;
383
+ img: TagHelper; input: TagHelper; ins: TagHelper; kbd: TagHelper;
384
+ label: TagHelper; legend: TagHelper; li: TagHelper; main: TagHelper;
385
+ mark: TagHelper; meter: TagHelper; nav: TagHelper; object: TagHelper;
386
+ ol: TagHelper; optgroup: TagHelper; option: TagHelper; output: TagHelper;
387
+ p: TagHelper; picture: TagHelper; pre: TagHelper; progress: TagHelper;
388
+ section: TagHelper; select: TagHelper; slot: TagHelper; small: TagHelper;
389
+ source: TagHelper; span: TagHelper; strong: TagHelper; sub: TagHelper;
390
+ summary: TagHelper; sup: TagHelper; table: TagHelper;
391
+ tbody: TagHelper; td: TagHelper; template: TagHelper; textarea: TagHelper;
392
+ tfoot: TagHelper; th: TagHelper; thead: TagHelper; time: TagHelper;
393
+ tr: TagHelper; u: TagHelper; ul: TagHelper; video: TagHelper;
521
394
  }
522
395
  }