ziko 2.0.0-beta.14 → 2.0.0-beta.15.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": "ziko",
3
- "version": "2.0.0-beta.14",
3
+ "version": "2.0.0-beta.15.1",
4
4
  "description": "A versatile JavaScript library offering a rich set of Hyperscript Based UI components, advanced mathematical utilities, interactivity ,animations, client side routing and more ...",
5
5
  "keywords": [
6
6
  "front-end",
@@ -62,12 +62,17 @@ export async function __addItem__(adder, pusher, item, referenceNode = null, ind
62
62
  if (["number", "string"].includes(typeof item)) item = text(item);
63
63
  if (typeof item === "function" && isStateGetter(item)) {
64
64
  const getter = item();
65
- item = text(getter.value);
66
- getter._subscribe(
67
- (newValue) => { item.element.textContent = newValue; },
68
- item
69
- );
70
- }
65
+ item = getter.value;
66
+
67
+ getter._subscribe((newValue) => {
68
+ if (newValue?.isUIElement?.()) {
69
+ item.element.replaceWith(newValue.element);
70
+ item = newValue;
71
+ } else {
72
+ item.element.textContent = newValue;
73
+ }
74
+ });
75
+ }
71
76
  if (typeof globalThis?.Node === "function" && item instanceof globalThis.Node)
72
77
  item = new this.constructor(item);
73
78
  if (item instanceof Promise) item = await item;
@@ -1,24 +1,84 @@
1
- // createSPAFileBasedRouter.d.ts
2
-
3
1
  import { UIElement } from '../../dom/UIElement'
2
+ import type { UILayout } from '../../Layout'
3
+
4
+ export type Component<T = unknown> =
5
+ | ((params?: Record<string, string>) => T)
6
+ | T
7
+ | T[]
8
+
9
+ export type Renderer<TComponent = unknown, TTarget = unknown> = (
10
+ target: TTarget,
11
+ component: TComponent | TComponent[] | null,
12
+ params: Record<string, string>,
13
+ wrapper?: unknown
14
+ ) => void | Promise<void>
15
+
16
+ export interface CreateFileBasedRouterOptions<
17
+ TComponent = unknown,
18
+ TTarget = unknown
19
+ > {
20
+ pages?: Record<
21
+ string,
22
+ () => Promise<{
23
+ default: (params?: Record<string, string>) => TComponent
24
+ [key: string]: unknown
25
+ }>
26
+ >
27
+
28
+ target?: TTarget | null
29
+
30
+ extensions?: string[]
31
+
32
+ renderer?: Renderer<TComponent, TTarget>
33
+
34
+ wrapper?: unknown
35
+
36
+ lazy?: boolean
37
+
38
+ base?: string
39
+
40
+ url?: string
41
+
42
+ namedExportHandler?: Record<
43
+ string,
44
+ (
45
+ exportedFn: unknown,
46
+ context: {
47
+ route: string | null
48
+ mask: string | null
49
+ module: unknown
50
+ currentPath: string
51
+ params: Record<string, string>
52
+ }
53
+ ) => unknown | Promise<unknown>
54
+ >
55
+ }
56
+
57
+ export interface FileBasedRouterResult<TComponent = unknown> {
58
+ mask: string | null
59
+ component: TComponent | null
60
+ params: Record<string, string>
61
+ namedExports?: Record<string, unknown>
62
+ matched: boolean
63
+ error?: unknown
64
+ }
65
+
66
+ export declare function _createFileBasedRouter<
67
+ TComponent = unknown,
68
+ TTarget = unknown
69
+ >(
70
+ options?: CreateFileBasedRouterOptions<TComponent, TTarget>
71
+ ): Promise<FileBasedRouterResult<TComponent>>
72
+
73
+
74
+ export type ZikoComponent =
75
+ | UIElement
76
+ | UIElement[]
77
+ | UILayout
4
78
 
5
- /**
6
- * Creates a SPA (Single Page Application) file-based router.
7
- * Automatically loads and mounts the component corresponding to the current path.
8
- * Supports dynamic routes and parameter extraction.
9
- *
10
- * @param pages - An object mapping route paths to async module functions that return a component.
11
- * Example: { "/user/[id]": () => import("./pages/user/[id].js") }
12
- * @param target - Optional DOM element to mount the component. Defaults to `document.body`.
13
- */
14
- export function createSPAFileBasedRouter(
15
- options : {
16
- pages: Record<
17
- string,
18
- () => Promise<{ default: (param? : Record<string, string>) => UIElement | UIElement[]}>
19
- >,
20
- target?: HTMLElement | UIElement
21
- extensions : string[],
22
- wrapper : Function
23
- },
24
- ): Promise<void>;
79
+ export declare function createFileBasedRouter(
80
+ options?: CreateFileBasedRouterOptions<
81
+ ZikoComponent,
82
+ HTMLElement | UIElement
83
+ >
84
+ ): Promise<FileBasedRouterResult<ZikoComponent>>
@@ -161,7 +161,4 @@ export async function createFileBasedRouter({
161
161
  namedExports,
162
162
  matched: true
163
163
  };
164
- }
165
-
166
- // Backward-compatible alias for SPA usage
167
- export const createSPAFileBasedRouter = createFileBasedRouter;
164
+ }
@@ -1,24 +1,62 @@
1
- export const camel2hyphencase = (text = '') => text.replace(/[A-Z]/g, match => '-' + match.toLowerCase());
2
- export const camel2snakecase = (text = '') => text.replace(/[A-Z]/g, match => '_' + match.toLowerCase());
1
+ export const camel2hyphencase = (text = '') =>
2
+ text.replace(/[A-Z]/g, (match, index) =>
3
+ index ? `-${match.toLowerCase()}` : match.toLowerCase()
4
+ );
5
+ export const camel2snakecase = (text = '') =>
6
+ text.replace(/[A-Z]/g, (match, index) =>
7
+ index ? `_${match.toLowerCase()}` : match.toLowerCase()
8
+ );
3
9
  export const camel2pascalcase = (text = '') => text.charAt(0).toUpperCase() + text.slice(1);
4
- export const camel2constantcase = (text = '') => text.replace(/[A-Z]/g, match => '_' + match).toUpperCase();
10
+ export const camel2constantcase = (text = '') => text
11
+ .replace(/[A-Z]/g, (match, index) =>
12
+ index ? `_${match}` : match
13
+ )
14
+ .toUpperCase();
5
15
 
6
- export const pascal2snakecase = (text = '') => text.replace(/([A-Z])/g, (match, _, offset) => offset ? '_' + match.toLowerCase() : match.toLowerCase());
7
- export const pascal2hyphencase = (text = '') => text.replace(/([A-Z])/g, (match, _, offset) => offset ? '-' + match.toLowerCase() : match.toLowerCase());
8
- export const pascal2constantcase = (text = '') => text.replace(/([A-Z])/g, (match, _, offset) => offset ? '_' + match : match).toUpperCase();
16
+
17
+ export const pascal2snakecase = (text = '') =>
18
+ text.replace(/[A-Z]/g, (match, offset) =>
19
+ offset === 0
20
+ ? match.toLowerCase()
21
+ : `_${match.toLowerCase()}`
22
+ );
23
+
24
+ export const pascal2hyphencase = (text = '') =>
25
+ text.replace(/[A-Z]/g, (match, offset) =>
26
+ offset === 0
27
+ ? match.toLowerCase()
28
+ : `-${match.toLowerCase()}`
29
+ );
30
+
31
+ export const pascal2constantcase = (text = '') =>
32
+ text
33
+ .replace(/[A-Z]/g, (match, offset) =>
34
+ offset === 0 ? match : `_${match}`
35
+ )
36
+ .toUpperCase();
9
37
  export const pascal2camelcase = (text = '') => text.charAt(0).toLowerCase() + text.slice(1);
10
38
 
11
- export const snake2camelcase = (text = '') => text.replace(/(_\w)/g, match => match[1].toUpperCase());
12
- export const snake2hyphencase = (text = '') => text.replace(/_/g, "-");
13
- export const snake2pascalcase = (text = '') => text.split('_').map(word => word.charAt(0).toUpperCase() + word.slice(1)).join('');
39
+ export const snake2camelcase = (text = '') => text.replace(/_([a-zA-Z])/g, (_, char) => char.toUpperCase());
40
+ export const snake2hyphencase = (text = '') => text.replace(/_/g, '-');
41
+ export const snake2pascalcase = (text = '') => text
42
+ .split('_')
43
+ .map(word => word.charAt(0).toUpperCase() + word.slice(1))
44
+ .join('');
14
45
  export const snake2constantcase = (text = '') => text.toUpperCase();
15
46
 
16
- export const hyphen2camelcase = (text = '') => text.replace(/-([a-z])/g, match => match[1].toUpperCase());
47
+ export const hyphen2camelcase = (text = '') => text.replace(/-([a-zA-Z])/g, (_, char) => char.toUpperCase());
17
48
  export const hyphen2snakecase = (text = '') => text.replace(/-/g, '_');
18
- export const hyphen2pascalcase = (text = '') => text.split('-').map(word => word.charAt(0).toUpperCase() + word.slice(1)).join('');
49
+ export const hyphen2pascalcase = (text = '') => text
50
+ .split('-')
51
+ .map(word => word.charAt(0).toUpperCase() + word.slice(1))
52
+ .join('');
19
53
  export const hyphen2constantcase = (text = '') => text.replace(/-/g, '_').toUpperCase();
20
54
 
21
- export const constant2camelcase = (text = '') => text.toLowerCase().replace(/_([a-z])/g, match => match[1].toUpperCase());
55
+ export const constant2camelcase = (text = '') => text.toLowerCase().replace(/_([a-z])/g, (_, char) => char.toUpperCase());
22
56
  export const constant2snakecase = (text = '') => text.toLowerCase();
23
- export const constant2pascalcase = (text = '') => text.toLowerCase().split('_').map(word => word.charAt(0).toUpperCase() + word.slice(1)).join('');
57
+ export const constant2pascalcase = (text = '') => text
58
+ .toLowerCase()
59
+ .split('_')
60
+ .map(word => word.charAt(0).toUpperCase() + word.slice(1))
61
+ .join('');
24
62
  export const constant2hyphencase = (text = '') => text.toLowerCase().replace(/_/g, '-');