sigment 1.0.9 → 1.1.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": "sigment",
3
- "version": "1.0.9",
3
+ "version": "1.1.0",
4
4
  "description": "A lightweight reactive JavaScript framework built with signals and vanilla JS — no virtual DOM, no JSX, no transpilation.",
5
5
  "main": "./dist/index.js",
6
6
  "repository": {
package/types/index.d.ts CHANGED
@@ -64,26 +64,30 @@ export function memoizeFunc<
64
64
  options?: MemoizeOptions
65
65
  ): F & { clear(): void };
66
66
 
67
+
68
+
69
+
70
+ export type Route = {
71
+ loader: () => Promise<any>;
72
+ urlParam?: string;
73
+ guard?: (params?: Record<string, any>) => boolean | Promise<boolean>;
74
+ logic?: () => void;
75
+ cacheExpiration?: number;
76
+ };
77
+
78
+ export type RoutesMap = Record<string, Route | string>;
79
+
67
80
  /**
68
81
  * Parses a path given a user-defined routes object.
69
82
  */
70
83
  export declare function parsePath(
71
- componentImports: Record<
72
- string,
73
- | {
74
- loader: () => Promise<any>;
75
- urlParam?: string;
76
- guard?: (params: Record<string, any>) => Promise<boolean>;
77
- logic?: () => void;
78
- cacheExpiration?: number;
79
- }
80
- | string // fallback route as string route name
81
- >
84
+ componentImports: RoutesMap
82
85
  ): {
83
86
  componentName: string;
84
87
  params: any | object;
85
88
  };
86
89
 
90
+
87
91
  /**
88
92
  * Loads a component and optionally runs logic, returning an HTMLElement.
89
93
  */
@@ -1,515 +0,0 @@
1
- // index.d.ts
2
-
3
- /**
4
- * The main app object with some properties and functions
5
- */
6
- export declare const MyApp: {
7
- cleanHtml: (flag: boolean) => void; // accepts boolean, returns void
8
- cleanhtml: true;
9
- setMaxCacheSize: (size: number) => void; // accepts number, returns void
10
- maxCacheSize: number;
11
- };
12
-
13
-
14
-
15
- /**
16
- * Creates a reactive effect that runs the given function and tracks dependencies.
17
- */
18
- export declare function createEffect(fn: () => void): void;
19
-
20
- /**
21
- * Creates an HTML element of the given tag name.
22
- * Returns void.
23
- */
24
- export declare function createSigment(name: string): void;
25
-
26
- /**
27
- * Creates an HTML element of the given tag name.
28
- * Returns void.
29
- */
30
- export declare function addSigment(name: string): void;
31
-
32
- /**
33
- * Fetches a URL with caching and TTL, returning parsed JSON.
34
- */
35
- export declare function fetchCache<T = any>(
36
- url: string,
37
- ttl?: number,
38
- options?: RequestInit
39
- ): Promise<T>;
40
-
41
- export interface MemoizeOptions {
42
- /**
43
- * Controls sorting of object keys before memoization cache key generation.
44
- * - true: Deep sort all nested object keys (default behavior).
45
- * - false: Shallow sort only top-level keys.
46
- * - undefined: No sorting (cache key uses raw arguments).
47
- */
48
- deepSort?: boolean;
49
- }
50
-
51
- /**
52
- * Memoizes the results of a function with optional TTL and key sorting.
53
- *
54
- * @param fn The function to memoize.
55
- * @param ttl Time to live for cache entries in milliseconds. Defaults to 5000ms.
56
- * @param options Optional memoization options.
57
- * @returns The memoized function with a `.clear()` method to clear the cache.
58
- */
59
- export function memoizeFunc<
60
- F extends (...args: any[]) => any
61
- >(
62
- fn: F,
63
- ttl?: number,
64
- options?: MemoizeOptions
65
- ): F & { clear(): void };
66
-
67
- /**
68
- * Parses a path given a user-defined routes object.
69
- */
70
- export declare function parsePath(
71
- componentImports: Record<
72
- string,
73
- | {
74
- loader: () => Promise<any>;
75
- urlParam?: string;
76
- guard?: (params?: Record<string, any>) => boolean | Promise<boolean>;
77
- logic?: () => void;
78
- cacheExpiration?: number;
79
- }
80
- | string // fallback route as string route name
81
- >
82
- ): {
83
- componentName: string;
84
- params: any | object;
85
- };
86
-
87
- /**
88
- * Loads a component and optionally runs logic, returning an HTMLElement.
89
- */
90
- export declare function loadRunFunc(
91
- componentMap: Record<
92
- string,
93
- | {
94
- loader: () => Promise<any>;
95
- urlParam?: string;
96
- guard?: (params: Record<string, any>) => Promise<boolean>;
97
- logic?: () => void;
98
- cacheExpiration?: number;
99
- }
100
- | string
101
- >,
102
- componentName: string,
103
- params?: Record<string, any> | null,
104
- logic?: (() => void) | null
105
- ): Promise<HTMLElement>;
106
-
107
- /**
108
- * Clears cached component for a given component name.
109
- */
110
- export declare function clearComponentCache(componentName: string): void;
111
-
112
- export declare function createGlobalSignal<T>(key: string, initialValue: T): [() => T, (v: T) => void];
113
-
114
- /**
115
- * Alias for createGlobalSignal.
116
- */
117
- export { createGlobalSignal as globalSignal };
118
-
119
-
120
-
121
- export declare function getGlobalSignal<T>(key: string): [() => T, (v: T) => void];
122
-
123
- /**
124
- * Alias for getGlobalSignal.
125
- */
126
-
127
- export { getGlobalSignal as useGlobalSignal };
128
-
129
-
130
- /**
131
- * Creates a reactive signal with getter and setter.
132
- * Setter optionally accepts a second argument 'force' (boolean).
133
- */
134
- export declare function createSignal<T = undefined>(
135
- initialValue?: T
136
- ): [() => T, (newValue: T, force?: boolean) => void];
137
-
138
-
139
- /**
140
- * Alias for createSignal.
141
- */
142
-
143
- export { createSignal as signal };
144
-
145
-
146
- /**
147
- * Function gve creates an HTML element with the given name.
148
- */
149
- export declare function gve(name: string): HTMLElement | null;
150
- export { gve as getVirtualElementById };
151
-
152
-
153
-
154
- export function gve(name: string): HTMLElement | null;
155
-
156
- export { gve as getVirtualElementById };
157
-
158
-
159
-
160
- /**
161
- * Sets a cookie; value can be string or object (will be JSON.stringified).
162
- */
163
- export declare function setCookie(k: string, v: any, t?: number): void;
164
-
165
- /**
166
- * Gets a cookie by key, returns string, parsed object, or null.
167
- */
168
- export declare function getCookie(k: string): any;
169
-
170
- /**
171
- * Sets localStorage item; value can be string, object, or HTMLElement (stored as outerHTML).
172
- */
173
- export declare function setStorage(key: string, value: any): void;
174
-
175
- /**
176
- * Gets localStorage item; parses JSON or returns string or HTMLElement-like object.
177
- */
178
- export declare function getStorage(key: string): any;
179
-
180
- /**
181
- * Hyperscript-style function to create elements or components.
182
- */
183
- export declare function h(
184
- tag: string | ((props?: Record<string, any>, ...children: any[]) => HTMLElement | any),
185
- ...args: (Record<string, any> | string | number | HTMLElement | (() => string | HTMLElement) | Array<any>)[]
186
- ): HTMLElement;
187
-
188
- /**
189
- * Groups and optionally executes components or HTML elements and metadata.
190
- */
191
- export declare function gvec(
192
- obj: {
193
- [key: string]: any;
194
- param?: string | any[] | Record<string, any>;
195
- },
196
- s?: boolean,
197
- o?: Record<string, any>
198
- ): any;
199
-
200
-
201
- /**
202
- * Checks if a value is undefined, null, or an empty string.
203
- *
204
- * @param v - The value to check.
205
- * @returns True if empty, otherwise false.
206
- */
207
- export declare function IsEmpty(v: any): boolean;
208
-
209
- /**
210
- * Pushes a new state to the browser's history (for navigation).
211
- *
212
- * @param path - The path to navigate to.
213
- */
214
- export declare function Navigate(path: string): void;
215
-
216
-
217
- /**
218
- * Loads a component module by name from a given map of dynamic import functions.
219
- *
220
- * @param componentImports - An object mapping names to dynamic import functions.
221
- * @param componentName - The name of the component to load.
222
- * @returns A promise that resolves to the loaded component.
223
- */
224
- export declare function loadFunc(
225
- componentImports: Record<string, () => Promise<any>>,
226
- componentName: string
227
- ): Promise<any>;
228
-
229
-
230
- /**
231
- * Executes an RPC call with a function and a params object.
232
- *
233
- * @param func - A function representing the RPC call body.
234
- * @param params - An object mapping method names to arrays of parameters.
235
- * @returns any
236
- */
237
- export declare function rpc(
238
- func: Function,
239
- params: Record<string, any[]>
240
- ): any;
241
-
242
- /**
243
- * Route function that checks if the current path matches the pattern and optional restrictions.
244
- *
245
- * @param pathPattern - The URL pattern string (e.g., "/admin/:id").
246
- * @param options - Optional object with passRestriction(s) functions.
247
- * @returns Promise resolving to boolean indicating match and restrictions pass.
248
- */
249
- export declare function Route(
250
- pathPattern: string,
251
- options?: {
252
- passRestriction?: Array<(() => boolean | Promise<boolean>)> | (() => boolean | Promise<boolean>);
253
- }
254
- ): Promise<boolean>;
255
-
256
-
257
-
258
-
259
- declare global {
260
-
261
- type Child =
262
- | string
263
- | number
264
- | boolean
265
- | null
266
- | undefined
267
- | HTMLElement
268
- | Text
269
- | DocumentFragment
270
- | (() => Child)
271
- | Child[];
272
-
273
- type Props = Partial<HTMLElement> & {
274
- [key: `data-${string}`]: string | number | boolean;
275
- [key: `aria-${string}`]: string | number | boolean;
276
- [key: string]: any; // allow fake attributes like fake-prop="123"
277
- };
278
-
279
- type TagFunction = {
280
- (props: Props, ...children: Child[]): HTMLElement;
281
- (...children: Child[]): HTMLElement;
282
- };
283
-
284
-
285
- const elements: string[];
286
-
287
- function createTagFunctions(tags: string[]): Record<string, TagFunction>;
288
-
289
- function a(props: Props, ...children: Child[]): HTMLElement;
290
- function a(...children: Child[]): HTMLElement;
291
- function abbr(props: Props, ...children: Child[]): HTMLElement;
292
- function abbr(...children: Child[]): HTMLElement;
293
- function area(props: Props, ...children: Child[]): HTMLElement;
294
- function area(...children: Child[]): HTMLElement;
295
- function article(props: Props, ...children: Child[]): HTMLElement;
296
- function article(...children: Child[]): HTMLElement;
297
- function aside(props: Props, ...children: Child[]): HTMLElement;
298
- function aside(...children: Child[]): HTMLElement;
299
- function audio(props: Props, ...children: Child[]): HTMLElement;
300
- function audio(...children: Child[]): HTMLElement;
301
- function base(props: Props, ...children: Child[]): HTMLElement;
302
- function base(...children: Child[]): HTMLElement;
303
- function b(props: Props, ...children: Child[]): HTMLElement;
304
- function b(...children: Child[]): HTMLElement;
305
- function bdi(props: Props, ...children: Child[]): HTMLElement;
306
- function bdi(...children: Child[]): HTMLElement;
307
- function bdo(props: Props, ...children: Child[]): HTMLElement;
308
- function bdo(...children: Child[]): HTMLElement;
309
- function blockquote(props: Props, ...children: Child[]): HTMLElement;
310
- function blockquote(...children: Child[]): HTMLElement;
311
- function body(props: Props, ...children: Child[]): HTMLElement;
312
- function body(...children: Child[]): HTMLElement;
313
- function br(props: Props, ...children: Child[]): HTMLElement;
314
- function br(...children: Child[]): HTMLElement;
315
- function button(props: Props, ...children: Child[]): HTMLElement;
316
- function button(...children: Child[]): HTMLElement;
317
- function canvas(props: Props, ...children: Child[]): HTMLElement;
318
- function canvas(...children: Child[]): HTMLElement;
319
- function cite(props: Props, ...children: Child[]): HTMLElement;
320
- function cite(...children: Child[]): HTMLElement;
321
- function code(props: Props, ...children: Child[]): HTMLElement;
322
- function code(...children: Child[]): HTMLElement;
323
- function col(props: Props, ...children: Child[]): HTMLElement;
324
- function col(...children: Child[]): HTMLElement;
325
- function colgroup(props: Props, ...children: Child[]): HTMLElement;
326
- function colgroup(...children: Child[]): HTMLElement;
327
- function data(props: Props, ...children: Child[]): HTMLElement;
328
- function data(...children: Child[]): HTMLElement;
329
- function datalist(props: Props, ...children: Child[]): HTMLElement;
330
- function datalist(...children: Child[]): HTMLElement;
331
- function dd(props: Props, ...children: Child[]): HTMLElement;
332
- function dd(...children: Child[]): HTMLElement;
333
- function del(props: Props, ...children: Child[]): HTMLElement;
334
- function del(...children: Child[]): HTMLElement;
335
- function details(props: Props, ...children: Child[]): HTMLElement;
336
- function details(...children: Child[]): HTMLElement;
337
- function dfn(props: Props, ...children: Child[]): HTMLElement;
338
- function dfn(...children: Child[]): HTMLElement;
339
- function dialog(props: Props, ...children: Child[]): HTMLElement;
340
- function dialog(...children: Child[]): HTMLElement;
341
- function div(props: Props, ...children: Child[]): HTMLElement;
342
- function div(...children: Child[]): HTMLElement;
343
- function dl(props: Props, ...children: Child[]): HTMLElement;
344
- function dl(...children: Child[]): HTMLElement;
345
- function dt(props: Props, ...children: Child[]): HTMLElement;
346
- function dt(...children: Child[]): HTMLElement;
347
- function em(props: Props, ...children: Child[]): HTMLElement;
348
- function em(...children: Child[]): HTMLElement;
349
- function embed(props: Props, ...children: Child[]): HTMLElement;
350
- function embed(...children: Child[]): HTMLElement;
351
- function fieldset(props: Props, ...children: Child[]): HTMLElement;
352
- function fieldset(...children: Child[]): HTMLElement;
353
- function figcaption(props: Props, ...children: Child[]): HTMLElement;
354
- function figcaption(...children: Child[]): HTMLElement;
355
- function figure(props: Props, ...children: Child[]): HTMLElement;
356
- function figure(...children: Child[]): HTMLElement;
357
- function footer(props: Props, ...children: Child[]): HTMLElement;
358
- function footer(...children: Child[]): HTMLElement;
359
- function form(props: Props, ...children: Child[]): HTMLElement;
360
- function form(...children: Child[]): HTMLElement;
361
- function h1(props: Props, ...children: Child[]): HTMLElement;
362
- function h1(...children: Child[]): HTMLElement;
363
- function h2(props: Props, ...children: Child[]): HTMLElement;
364
- function h2(...children: Child[]): HTMLElement;
365
- function h3(props: Props, ...children: Child[]): HTMLElement;
366
- function h3(...children: Child[]): HTMLElement;
367
- function h4(props: Props, ...children: Child[]): HTMLElement;
368
- function h4(...children: Child[]): HTMLElement;
369
- function h5(props: Props, ...children: Child[]): HTMLElement;
370
- function h5(...children: Child[]): HTMLElement;
371
- function h6(props: Props, ...children: Child[]): HTMLElement;
372
- function h6(...children: Child[]): HTMLElement;
373
- function head(props: Props, ...children: Child[]): HTMLElement;
374
- function head(...children: Child[]): HTMLElement;
375
- function header(props: Props, ...children: Child[]): HTMLElement;
376
- function header(...children: Child[]): HTMLElement;
377
- function hr(props: Props, ...children: Child[]): HTMLElement;
378
- function hr(...children: Child[]): HTMLElement;
379
- function html(props: Props, ...children: Child[]): HTMLElement;
380
- function html(...children: Child[]): HTMLElement;
381
- function i(props: Props, ...children: Child[]): HTMLElement;
382
- function i(...children: Child[]): HTMLElement;
383
- function iframe(props: Props, ...children: Child[]): HTMLElement;
384
- function iframe(...children: Child[]): HTMLElement;
385
- function img(props: Props, ...children: Child[]): HTMLElement;
386
- function img(...children: Child[]): HTMLElement;
387
- function input(props: Props, ...children: Child[]): HTMLElement;
388
- function input(...children: Child[]): HTMLElement;
389
- function ins(props: Props, ...children: Child[]): HTMLElement;
390
- function ins(...children: Child[]): HTMLElement;
391
- function kbd(props: Props, ...children: Child[]): HTMLElement;
392
- function kbd(...children: Child[]): HTMLElement;
393
- function label(props: Props, ...children: Child[]): HTMLElement;
394
- function label(...children: Child[]): HTMLElement;
395
- function legend(props: Props, ...children: Child[]): HTMLElement;
396
- function legend(...children: Child[]): HTMLElement;
397
- function li(props: Props, ...children: Child[]): HTMLElement;
398
- function li(...children: Child[]): HTMLElement;
399
- function link(props: Props, ...children: Child[]): HTMLElement;
400
- function link(...children: Child[]): HTMLElement;
401
- function main(props: Props, ...children: Child[]): HTMLElement;
402
- function main(...children: Child[]): HTMLElement;
403
- function map(props: Props, ...children: Child[]): HTMLElement;
404
- function map(...children: Child[]): HTMLElement;
405
- function mark(props: Props, ...children: Child[]): HTMLElement;
406
- function mark(...children: Child[]): HTMLElement;
407
- function menu(props: Props, ...children: Child[]): HTMLElement;
408
- function menu(...children: Child[]): HTMLElement;
409
- function meta(props: Props, ...children: Child[]): HTMLElement;
410
- function meta(...children: Child[]): HTMLElement;
411
- function meter(props: Props, ...children: Child[]): HTMLElement;
412
- function meter(...children: Child[]): HTMLElement;
413
- function nav(props: Props, ...children: Child[]): HTMLElement;
414
- function nav(...children: Child[]): HTMLElement;
415
- function noscript(props: Props, ...children: Child[]): HTMLElement;
416
- function noscript(...children: Child[]): HTMLElement;
417
- function object(props: Props, ...children: Child[]): HTMLElement;
418
- function object(...children: Child[]): HTMLElement;
419
- function ol(props: Props, ...children: Child[]): HTMLElement;
420
- function ol(...children: Child[]): HTMLElement;
421
- function optgroup(props: Props, ...children: Child[]): HTMLElement;
422
- function optgroup(...children: Child[]): HTMLElement;
423
- function option(props: Props, ...children: Child[]): HTMLElement;
424
- function option(...children: Child[]): HTMLElement;
425
- function output(props: Props, ...children: Child[]): HTMLElement;
426
- function output(...children: Child[]): HTMLElement;
427
- function p(props: Props, ...children: Child[]): HTMLElement;
428
- function p(...children: Child[]): HTMLElement;
429
- function param(props: Props, ...children: Child[]): HTMLElement;
430
- function param(...children: Child[]): HTMLElement;
431
- function picture(props: Props, ...children: Child[]): HTMLElement;
432
- function picture(...children: Child[]): HTMLElement;
433
- function pre(props: Props, ...children: Child[]): HTMLElement;
434
- function pre(...children: Child[]): HTMLElement;
435
- function progress(props: Props, ...children: Child[]): HTMLElement;
436
- function progress(...children: Child[]): HTMLElement;
437
- function q(props: Props, ...children: Child[]): HTMLElement;
438
- function q(...children: Child[]): HTMLElement;
439
- function rp(props: Props, ...children: Child[]): HTMLElement;
440
- function rp(...children: Child[]): HTMLElement;
441
- function rt(props: Props, ...children: Child[]): HTMLElement;
442
- function rt(...children: Child[]): HTMLElement;
443
- function ruby(props: Props, ...children: Child[]): HTMLElement;
444
- function ruby(...children: Child[]): HTMLElement;
445
- function s(props: Props, ...children: Child[]): HTMLElement;
446
- function s(...children: Child[]): HTMLElement;
447
- function samp(props: Props, ...children: Child[]): HTMLElement;
448
- function samp(...children: Child[]): HTMLElement;
449
- function script(props: Props, ...children: Child[]): HTMLElement;
450
- function script(...children: Child[]): HTMLElement;
451
- function section(props: Props, ...children: Child[]): HTMLElement;
452
- function section(...children: Child[]): HTMLElement;
453
- function select(props: Props, ...children: Child[]): HTMLElement;
454
- function select(...children: Child[]): HTMLElement;
455
- function slot(props: Props, ...children: Child[]): HTMLElement;
456
- function slot(...children: Child[]): HTMLElement;
457
- function small(props: Props, ...children: Child[]): HTMLElement;
458
- function small(...children: Child[]): HTMLElement;
459
- function source(props: Props, ...children: Child[]): HTMLElement;
460
- function source(...children: Child[]): HTMLElement;
461
- function span(props: Props, ...children: Child[]): HTMLElement;
462
- function span(...children: Child[]): HTMLElement;
463
- function strong(props: Props, ...children: Child[]): HTMLElement;
464
- function strong(...children: Child[]): HTMLElement;
465
- function style(props: Props, ...children: Child[]): HTMLElement;
466
- function style(...children: Child[]): HTMLElement;
467
- function sub(props: Props, ...children: Child[]): HTMLElement;
468
- function sub(...children: Child[]): HTMLElement;
469
- function summary(props: Props, ...children: Child[]): HTMLElement;
470
- function summary(...children: Child[]): HTMLElement;
471
- function sup(props: Props, ...children: Child[]): HTMLElement;
472
- function sup(...children: Child[]): HTMLElement;
473
- function table(props: Props, ...children: Child[]): HTMLElement;
474
- function table(...children: Child[]): HTMLElement;
475
- function tbody(props: Props, ...children: Child[]): HTMLElement;
476
- function tbody(...children: Child[]): HTMLElement;
477
- function td(props: Props, ...children: Child[]): HTMLElement;
478
- function td(...children: Child[]): HTMLElement;
479
- function template(props: Props, ...children: Child[]): HTMLElement;
480
- function template(...children: Child[]): HTMLElement;
481
- function textarea(props: Props, ...children: Child[]): HTMLElement;
482
- function textarea(...children: Child[]): HTMLElement;
483
- function tfoot(props: Props, ...children: Child[]): HTMLElement;
484
- function tfoot(...children: Child[]): HTMLElement;
485
- function th(props: Props, ...children: Child[]): HTMLElement;
486
- function th(...children: Child[]): HTMLElement;
487
- function thead(props: Props, ...children: Child[]): HTMLElement;
488
- function thead(...children: Child[]): HTMLElement;
489
- function time(props: Props, ...children: Child[]): HTMLElement;
490
- function time(...children: Child[]): HTMLElement;
491
- function title(props: Props, ...children: Child[]): HTMLElement;
492
- function title(...children: Child[]): HTMLElement;
493
- function tr(props: Props, ...children: Child[]): HTMLElement;
494
- function tr(...children: Child[]): HTMLElement;
495
- function track(props: Props, ...children: Child[]): HTMLElement;
496
- function track(...children: Child[]): HTMLElement;
497
- function u(props: Props, ...children: Child[]): HTMLElement;
498
- function u(...children: Child[]): HTMLElement;
499
- function ul(props: Props, ...children: Child[]): HTMLElement;
500
- function ul(...children: Child[]): HTMLElement;
501
- function var_(props: Props, ...children: Child[]): HTMLElement;
502
- function var_(...children: Child[]): HTMLElement;
503
- function video(props: Props, ...children: Child[]): HTMLElement;
504
- function video(...children: Child[]): HTMLElement;
505
- function wbr(props: Props, ...children: Child[]): HTMLElement;
506
- function wbr(...children: Child[]): HTMLElement;
507
- function fragment(props: Props, ...children: Child[]): DocumentFragment;
508
- function fragment(...children: Child[]): DocumentFragment;
509
-
510
-
511
- }
512
-
513
-
514
- export function createElement(tagName: string, ...args: (string | HTMLElement)[]): HTMLElement;
515
-