ziko 1.0.0 → 1.1.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": "1.0.0",
3
+ "version": "1.1.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",
package/src/app/params.js CHANGED
@@ -1,10 +1,7 @@
1
1
  function parseQueryParams(queryString) {
2
- const params = {};
3
- queryString.replace(/[A-Z0-9]+?=([\w|:|\/\.]*)/gi, (match) => {
4
- const [key, value] = match.split('=');
5
- params[key] = value;
6
- });
7
- return params;
2
+ return Object.fromEntries(
3
+ new URLSearchParams(location.search)
4
+ );
8
5
  }
9
6
 
10
7
  function defineParamsGetter(target ){
@@ -1,5 +1,5 @@
1
1
  import { SPA } from "./spa.js";
2
- import { tags } from "../ui/index.js";
2
+ import { tags } from "../dom/index.js";
3
3
  // import.meta.glob('./src/pages/**/*.js')
4
4
  async function FileBasedRouting(pages /* use import.meta.glob */){
5
5
  const routes = Object.keys(pages)
package/src/app/spa.js CHANGED
@@ -1,4 +1,4 @@
1
- import { text } from "../ui/index.js";
1
+ import { text } from "../dom/index.js";
2
2
  import { dynamicRoutesParser,routesMatcher,isDynamic } from "./routes.js";
3
3
  import { ZikoApp } from "./ziko-app.js";
4
4
  class ZikoSPA extends ZikoApp{
@@ -22,12 +22,12 @@
22
22
  svg2imgUrl,
23
23
  svg2img
24
24
  } from "./svg.js";
25
- export{
26
- obj2str
27
- } from "./object.js"
28
- export{
29
- arr2str
30
- } from "./array.js"
25
+ // export{
26
+ // obj2str
27
+ // } from "./object.js"
28
+ // export{
29
+ // arr2str
30
+ // } from "./array.js"
31
31
  export{
32
32
  json2css
33
33
  } from "./css.js"
@@ -1,5 +1,9 @@
1
- import { arr2str } from "../index.js";
2
- import { Complex, mapfun, Matrix } from "../../math/index.js";
1
+ // import { arr2str } from "../index.js";
2
+ // import { Complex, mapfun, Matrix } from "../../math/index.js";
3
+
4
+ import { Complex } from "../../math/complex/index.js";
5
+ import { Matrix } from "../../math/matrix/index.js";
6
+ import { mapfun } from "../../math/functions/utils/mapfun.js";
3
7
 
4
8
  // const obj2str=(object)=>{
5
9
  // const recursiveToString = (obj) => {
@@ -1,4 +1,4 @@
1
- import { tags } from "../../ui"
1
+ import { tags } from "../../dom"
2
2
  const svg2str=svg=>(new XMLSerializer()).serializeToString(svg);
3
3
  const svg2ascii=svg=>btoa(svg2str(svg));
4
4
  const svg2imgUrl=svg=>'data:image/svg+xml;base64,'+svg2ascii(svg);
@@ -8,4 +8,5 @@ export type * from './use-event-emitter.d.ts'
8
8
  export type * from './use-media-query.d.ts'
9
9
  export type * from './use-title.d.ts'
10
10
  export type * from './use-favicon.d.ts'
11
- export type * from './use-root.d.ts'
11
+ export type * from './use-root.d.ts'
12
+ export type * from './use-query-params.d.ts'
@@ -10,4 +10,6 @@ export * from './use-thread.js'
10
10
  export * from './use-event-emitter.js'
11
11
  export * from './use-media-query.js'
12
12
  export * from './use-title.js'
13
- export * from './use-root.js'
13
+ export * from './use-root.js'
14
+
15
+ export * from './use-query-params.js'
@@ -0,0 +1,31 @@
1
+ export type QueryParams = Record<string, string>;
2
+
3
+ export type SetQueryParams = (
4
+ updates:
5
+ | QueryParams
6
+ | ((current: QueryParams) => QueryParams),
7
+ merge?: boolean
8
+ ) => void;
9
+
10
+ export type GetQueryParams = () => QueryParams;
11
+
12
+ /**
13
+ * Reactive query params hook-like utility
14
+ * Returns:
15
+ * - getParams: function that returns current query params
16
+ * - setParams: function to update query params
17
+ */
18
+ export function useQueryParams(): [
19
+ GetQueryParams,
20
+ SetQueryParams
21
+ ];
22
+
23
+ /**
24
+ * Watches URL query parameters changes.
25
+ * Calls callback only when params actually change.
26
+ *
27
+ * Returns an unsubscribe function.
28
+ */
29
+ export function watchQueryParams(
30
+ callback: (params: QueryParams) => void
31
+ ): () => void;
@@ -0,0 +1,71 @@
1
+ import { useState } from "./use-state.js";
2
+ const parseQueryParams = queryString => Object.fromEntries(new URLSearchParams(globalThis?.location?.search))
3
+
4
+ export function useQueryParams() {
5
+ const getParams = () =>
6
+ parseQueryParams(window.location.search);
7
+
8
+ const setParams = (updates, merge = true) => {
9
+ const current = getParams();
10
+
11
+ const next =
12
+ typeof updates === "function"
13
+ ? updates(current)
14
+ : updates;
15
+
16
+ const finalParams = merge
17
+ ? { ...current, ...next }
18
+ : next;
19
+
20
+ const search = new URLSearchParams(finalParams).toString();
21
+
22
+ window.history.pushState(
23
+ {},
24
+ "",
25
+ `${window.location.pathname}${search ? `?${search}` : ""}`
26
+ );
27
+
28
+ window.dispatchEvent(
29
+ new CustomEvent("queryparamschange", {
30
+ detail: finalParams
31
+ })
32
+ );
33
+ };
34
+
35
+ return [getParams, setParams];
36
+ }
37
+
38
+ export function watchQueryParams(callback) {
39
+ let previousSearch = location.search;
40
+
41
+ const notify = () => {
42
+ const currentSearch = location.search;
43
+
44
+ if (currentSearch === previousSearch) {
45
+ return;
46
+ }
47
+
48
+ previousSearch = currentSearch;
49
+ callback(parseQueryParams(currentSearch));
50
+ };
51
+
52
+ window.addEventListener("popstate", notify);
53
+
54
+ const pushState = history.pushState;
55
+ history.pushState = function (...args) {
56
+ pushState.apply(this, args);
57
+ notify();
58
+ };
59
+
60
+ const replaceState = history.replaceState;
61
+ history.replaceState = function (...args) {
62
+ replaceState.apply(this, args);
63
+ notify();
64
+ };
65
+
66
+ callback(parseQueryParams(location.search));
67
+
68
+ return () => {
69
+ window.removeEventListener("popstate", notify);
70
+ };
71
+ }
@@ -1,4 +1,4 @@
1
- import { mapfun } from '../math/index.js'
1
+ import { mapfun } from '../math/utils/mapfun.js'
2
2
  import { useState } from './use-state.js'
3
3
 
4
4
  const useReactive = (nested_value) => mapfun(
package/src/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  export * from "./math/index.js";
2
- export * from "./ui/index.js";
2
+ export * from "./dom/index.js";
3
3
  export * from "./time/index.js";
4
4
  export * from "./data/index.js";
5
5
  // export * from "./reactivity/index.js"
@@ -1,4 +1,4 @@
1
- import { Complex } from "../../../src/math/index.js";
1
+ import { Complex } from "../../../src/math/Complex/index.js";
2
2
  import { Matrix } from "../../../src/math/matrix/index.js";
3
3
 
4
4
  /**
@@ -0,0 +1,5 @@
1
+ export type * from './complex/index.d.ts'
2
+ // export type * from './time'
3
+ // export type * from './router'
4
+ // export type * from './hooks'
5
+ // export type * from './data'
package/src/math/index.js CHANGED
@@ -16,11 +16,11 @@
16
16
  // }
17
17
  export * from "./const.js"
18
18
  export * from "./functions/index.js"
19
- export * from "./complex"
20
- export * from "./matrix"
19
+ export * from "./complex/index.js"
20
+ export * from "./matrix/index.js"
21
21
  // export * from "./discret"
22
- export * from "./random"
23
- export * from "./utils"
22
+ export * from "./random/index.js"
23
+ // export * from "./utils/index.js" // To Check
24
24
  // export * from "./statistics"
25
25
  // export default Math;
26
26
 
@@ -1,102 +1,108 @@
1
- // import { mapfun } from "../mapfun/index.js";
2
- // import {
3
- // add,
4
- // sub,
5
- // mul,
6
- // div,
7
- // modulo
8
- // } from "./arithmetic.js";
9
- import {
10
- zeros,
11
- ones,
12
- nums,
13
- // norm,
14
- // lerp,
15
- // map,
16
- // clamp,
17
- arange,
18
- linspace,
19
- logspace,
20
- geomspace
21
- } from "../signal/functions.js"
1
+ export * from './arithmetic.js'
2
+ export * from './checkers.js'
3
+ export * from './comparaison.js'
4
+ export * from './conversions.js'
5
+ export * from './discret.js'
6
+ // export * from './mapfun.js'
7
+ // // import { mapfun } from "../mapfun/index.js";
8
+ // // import {
9
+ // // add,
10
+ // // sub,
11
+ // // mul,
12
+ // // div,
13
+ // // modulo
14
+ // // } from "./arithmetic.js";
22
15
  // import {
23
- // deg2rad,
24
- // rad2deg
25
- // } from "./conversions.js"
16
+ // zeros,
17
+ // ones,
18
+ // nums,
19
+ // // norm,
20
+ // // lerp,
21
+ // // map,
22
+ // // clamp,
23
+ // arange,
24
+ // linspace,
25
+ // logspace,
26
+ // geomspace
27
+ // } from "../signal/functions.js"
28
+ // // import {
29
+ // // deg2rad,
30
+ // // rad2deg
31
+ // // } from "./conversions.js"
32
+ // // import{
33
+ // // sum,
34
+ // // prod,
35
+ // // accum
36
+ // // } from "../statistics/index.js"
26
37
  // import{
27
- // sum,
28
- // prod,
29
- // accum
30
- // } from "../statistics/index.js"
31
- import{
32
- inRange,
33
- isApproximatlyEqual
34
- } from "./checkers.js"
35
- import{
36
- cartesianProduct,
37
- ppcm,
38
- pgcd
39
- } from "./discret.js"
40
- const Utils={
41
- // add,
42
- // sub,
43
- // mul,
44
- // div,
45
- // modulo,
38
+ // inRange,
39
+ // isApproximatlyEqual
40
+ // } from "./checkers.js"
41
+ // import{
42
+ // cartesianProduct,
43
+ // ppcm,
44
+ // pgcd
45
+ // } from "./discret.js"
46
+ // const Utils={
47
+ // // add,
48
+ // // sub,
49
+ // // mul,
50
+ // // div,
51
+ // // modulo,
46
52
 
47
- zeros,
48
- ones,
49
- nums,
50
- // norm,
51
- // lerp,
52
- // map,
53
- // clamp,
54
- arange,
55
- linspace,
56
- logspace,
57
- geomspace,
53
+ // zeros,
54
+ // ones,
55
+ // nums,
56
+ // // norm,
57
+ // // lerp,
58
+ // // map,
59
+ // // clamp,
60
+ // arange,
61
+ // linspace,
62
+ // logspace,
63
+ // geomspace,
58
64
 
59
- // sum,
60
- // prod,
61
- // accum,
65
+ // // sum,
66
+ // // prod,
67
+ // // accum,
62
68
 
63
- cartesianProduct,
64
- ppcm,
65
- pgcd,
69
+ // cartesianProduct,
70
+ // ppcm,
71
+ // pgcd,
66
72
 
67
- // deg2rad,
68
- // rad2deg,
73
+ // // deg2rad,
74
+ // // rad2deg,
69
75
 
70
- inRange,
71
- isApproximatlyEqual
72
- }
73
- export {
74
- // mapfun,
75
- Utils,
76
- zeros,
77
- ones,
78
- nums,
79
- // sum,
80
- // prod,
81
- // add,
82
- // mul,
83
- // sub,
84
- // div,
85
- // modulo,
86
- // rad2deg,
87
- // deg2rad,
88
- arange,
89
- linspace,
90
- logspace,
91
- geomspace,
92
- // norm,
93
- // lerp,
94
- // map,
95
- // clamp,
96
- pgcd,
97
- ppcm,
98
- isApproximatlyEqual,
99
- inRange,
100
- cartesianProduct,
101
- };
76
+ // inRange,
77
+ // isApproximatlyEqual
78
+ // }
79
+ // export {
80
+ // // mapfun,
81
+ // Utils,
82
+ // zeros,
83
+ // ones,
84
+ // nums,
85
+ // // sum,
86
+ // // prod,
87
+ // // add,
88
+ // // mul,
89
+ // // sub,
90
+ // // div,
91
+ // // modulo,
92
+ // // rad2deg,
93
+ // // deg2rad,
94
+ // arange,
95
+ // linspace,
96
+ // logspace,
97
+ // geomspace,
98
+ // // norm,
99
+ // // lerp,
100
+ // // map,
101
+ // // clamp,
102
+ // pgcd,
103
+ // ppcm,
104
+ // isApproximatlyEqual,
105
+ // inRange,
106
+ // cartesianProduct,
107
+ // };
102
108
 
@@ -1,4 +1,4 @@
1
- const mapfun=(fun,...X)=>{
1
+ export const mapfun=(fun,...X)=>{
2
2
  const Y=X.map(x=>{
3
3
  if(
4
4
  x===null||
@@ -40,4 +40,3 @@ const mapfun=(fun,...X)=>{
40
40
  });
41
41
  return Y.length==1? Y[0]: Y;
42
42
  }
43
- export {mapfun}
@@ -1,5 +0,0 @@
1
- export type * from './math'
2
- export type * from './time'
3
- export type * from './router'
4
- export type * from './hooks'
5
- export type * from './data'