ziko 0.50.2 → 0.51.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.
Files changed (44) hide show
  1. package/dist/ziko.js +1515 -1398
  2. package/dist/ziko.mjs +1515 -1398
  3. package/package.json +1 -1
  4. package/src/__helpers__/checkers/index.js +1 -0
  5. package/src/data/converter/csv.js +1 -1
  6. package/src/events/binders/coordinates-based-event.js +25 -0
  7. package/src/events/binders/index.js +11 -6
  8. package/src/events/customizers/normalise-coordinates.js +0 -0
  9. package/src/events/details-setter/index.js +3 -1
  10. package/src/events/details-setter/mouse.js +35 -0
  11. package/src/events/details-setter/pointer.js +33 -31
  12. package/src/events/details-setter/touch.js +37 -0
  13. package/src/math/complex/index.js +2 -3
  14. package/src/math/discret/Conversion/index.js +1 -1
  15. package/src/math/discret/Logic/index.js +1 -1
  16. package/src/math/functions/index.js +8 -9
  17. package/src/math/matrix/helpers/det.js +36 -0
  18. package/src/math/matrix/helpers/index.js +3 -0
  19. package/src/math/matrix/helpers/inverse.js +52 -0
  20. package/src/math/matrix/helpers/stack.js +24 -0
  21. package/src/math/matrix/index.js +1 -1
  22. package/src/math/matrix/matrix.js +601 -0
  23. package/src/math/random/index.js +88 -92
  24. package/src/math/signal/functions.js +23 -25
  25. package/src/math/utils/arithmetic.js +15 -17
  26. package/src/math/utils/mapfun.js +3 -7
  27. package/src/router/file-based-router/index.js +46 -0
  28. package/src/router/index.js +2 -0
  29. package/src/router/utils/dynamic-routes-parser.js +76 -0
  30. package/src/router/utils/get-root.js +16 -0
  31. package/src/router/utils/index.js +5 -0
  32. package/src/router/utils/normalize-path.js +17 -0
  33. package/src/router/utils/routes-grouper.js +22 -0
  34. package/src/router/utils/routes-matcher.js +60 -0
  35. package/types/index.d.ts +1 -0
  36. package/types/router/file-based-router/index.d.ts +20 -0
  37. package/types/router/index.d.ts +2 -0
  38. package/types/router/utils/dynamic-routes-parser.d.ts +14 -0
  39. package/types/router/utils/get-root.d.ts +11 -0
  40. package/types/router/utils/index.d.ts +5 -0
  41. package/types/router/utils/normalize-path.d.ts +15 -0
  42. package/types/router/utils/routes-grouper.d.ts +29 -0
  43. package/types/router/utils/routes-matcher.d.ts +1 -0
  44. package/src/math/matrix/Matrix.js +0 -675
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ziko",
3
- "version": "0.50.2",
3
+ "version": "0.51.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",
@@ -1 +1,2 @@
1
1
  export const is_primitive = value => typeof value !== 'object' && typeof value !== 'function' || value === null;
2
+ export const is_async = fn => fn && fn.constructor && fn.constructor.name === "AsyncFunction";
@@ -1,4 +1,4 @@
1
- import { Matrix } from "../../math/matrix/Matrix.js"
1
+ import { Matrix } from "../../math/matrix/matrix.js"
2
2
  const csv2arr = (csv, delimiter = ",")=>csv.trim().trimEnd().split("\n").map(n=>n.split(delimiter));
3
3
  const csv2matrix = (csv, delimiter = ",")=>new Matrix(csv2arr(csv,delimiter));
4
4
  const csv2object = (csv, delimiter = ",") => {
@@ -0,0 +1,25 @@
1
+ import { ZikoEvent } from "../ziko-event.js";
2
+
3
+ export class CoordinatesBasedEvent extends ZikoEvent{
4
+ constructor(signature, target = null, Events = [], details_setter, customizer){
5
+ super(signature, target, Events, details_setter, customizer)
6
+ Object.assign(this.cache,{
7
+ useNormalisedCoordinates : false
8
+ })
9
+ this.isDown = false;
10
+ this.isMoving = false;
11
+ this.dx = 0;
12
+ this.dy = 0;
13
+ this.mx = 0;
14
+ this.my = 0;
15
+ this.ux = 0;
16
+ this.uy = 0;
17
+ }
18
+ get isDragging(){
19
+ return this.isDown && this.isMoving
20
+ }
21
+ useNormalisedCoordinates(enable = true){
22
+ this.cache.useNormalisedCoordinates = enable;
23
+ return this;
24
+ }
25
+ }
@@ -2,8 +2,13 @@ import { ZikoEvent } from "../ziko-event.js";
2
2
  import { EventsMap } from "../events-map/index.js";
3
3
  import {
4
4
  ptr_details_setter,
5
- key_details_setter
5
+ key_details_setter,
6
+ mouse_details_setter,
7
+ touch_details_setter
6
8
  } from '../details-setter/index.js'
9
+ import {
10
+ CoordinatesBasedEvent
11
+ } from './coordinates-based-event.js'
7
12
  import {
8
13
  register_click_away_event,
9
14
  register_view_event,
@@ -48,25 +53,25 @@ export const bind_key_event = (target, customizer) => new ZikoEvent(
48
53
  key_details_setter,
49
54
  customizer
50
55
  );
51
- export const bind_mouse_event = (target, customizer) => new ZikoEvent(
56
+ export const bind_mouse_event = (target, customizer) => new CoordinatesBasedEvent(
52
57
  'mouse',
53
58
  target,
54
59
  EventsMap.Mouse,
55
- null,
60
+ mouse_details_setter,
56
61
  customizer
57
62
  );
58
- export const bind_pointer_event = (target, customizer) => new ZikoEvent(
63
+ export const bind_pointer_event = (target, customizer) => new CoordinatesBasedEvent(
59
64
  'ptr',
60
65
  target,
61
66
  EventsMap.Ptr,
62
67
  ptr_details_setter,
63
68
  customizer
64
69
  );
65
- export const bind_touch_event = (target, customizer) => new ZikoEvent(
70
+ export const bind_touch_event = (target, customizer) => new CoordinatesBasedEvent(
66
71
  'touch',
67
72
  target,
68
73
  EventsMap.Touch,
69
- null,
74
+ touch_details_setter,
70
75
  customizer
71
76
  );
72
77
  export const bind_wheel_event = (target, customizer) => new ZikoEvent(
@@ -1,2 +1,4 @@
1
1
  export * from './key.js'
2
- export * from './pointer.js'
2
+ export * from './pointer.js'
3
+ export * from './mouse.js'
4
+ export * from './touch.js'
@@ -0,0 +1,35 @@
1
+ export function mouse_details_setter() {
2
+ const rect = this.targetElement.getBoundingClientRect();
3
+ const e = this.event;
4
+ let x = (e.clientX - rect.left) | 0;
5
+ let y = (e.clientY - rect.top) | 0;
6
+
7
+ if(this.cache.useNormalisedCoordinates){
8
+ const w = this.targetElement.clientWidth;
9
+ const h = this.targetElement.clientHeight;
10
+ x = +((x / w) * 2 - 1).toFixed(8);
11
+ y = +((y / h) * -2 + 1).toFixed(8);
12
+ }
13
+
14
+ switch (this.currentEvent) {
15
+
16
+ case "mousedown":
17
+ this.dx = x;
18
+ this.dy = y;
19
+ this.isDown = true;
20
+ break;
21
+
22
+ case "mousemove":
23
+ this.mx = x;
24
+ this.my = y;
25
+ this.isMoving = true;
26
+ break;
27
+
28
+ case "mouserup":
29
+ this.ux = x;
30
+ this.uy = y;
31
+ this.isDown = false;
32
+ this.isMoving = false;
33
+ break;
34
+ }
35
+ }
@@ -1,33 +1,35 @@
1
- export function ptr_details_setter(){
2
- switch(this.currentEvent){
3
- case "pointerdown" : {
4
- this.dx = parseInt(this.event.offsetX);
5
- this.dy = parseInt(this.event.offsetY);
6
- this.isDown = true
7
- }; break;
8
- case "pointermove" : {
9
- this.mx = parseInt(this.event.offsetX);
10
- this.my = parseInt(this.event.offsetY);
11
- this.isMoving = true
12
- }; break;
13
- case "pointerup" : {
14
- this.ux = parseInt(this.event.offsetX);
15
- this.uy = parseInt(this.event.offsetY);
1
+ export function ptr_details_setter() {
2
+ const rect = this.targetElement.getBoundingClientRect();
3
+ const e = this.event;
4
+ let x = (e.clientX - rect.left) | 0;
5
+ let y = (e.clientY - rect.top) | 0;
6
+
7
+ if(this.cache.useNormalisedCoordinates){
8
+ const w = this.targetElement.clientWidth;
9
+ const h = this.targetElement.clientHeight;
10
+ x = +((x / w) * 2 - 1).toFixed(8);
11
+ y = +((y / h) * -2 + 1).toFixed(8);
12
+ }
13
+ switch (this.currentEvent) {
14
+
15
+ case "pointerdown":
16
+ this.dx = x;
17
+ this.dy = y;
18
+ this.isDown = true;
19
+ break;
20
+
21
+ case "pointermove":
22
+ this.mx = x;
23
+ this.my = y;
24
+ this.isMoving = true;
25
+ break;
26
+
27
+ case "pointerup":
28
+ this.ux = x;
29
+ this.uy = y;
16
30
  this.isDown = false;
17
- console.log(this.target.width)
18
- const delta_x=(this.ux-this.dx)/this.target.width;
19
- const delta_y=(this.dy-this.uy)/this.target.height;
20
- const HORIZONTAL_SWIPPE=(delta_x<0)?"left":(delta_x>0)?"right":"none";
21
- const VERTICAL_SWIPPE=(delta_y<0)?"bottom":(delta_y>0)?"top":"none";
22
- this.swippe={
23
- h:HORIZONTAL_SWIPPE,
24
- v:VERTICAL_SWIPPE,
25
- delta_x,
26
- delta_y
27
- }
28
- }; break;
31
+ this.isMoving = false;
32
+ break;
29
33
  }
30
- // if(this.currentEvent==="click") this.dx = 0
31
- // else this.dx = 1
32
- // console.log(this.currentEvent)
33
- }
34
+ }
35
+
@@ -0,0 +1,37 @@
1
+ export function touch_details_setter() {
2
+ const e = this.event;
3
+ const touch = e.touches?.[0] || e.changedTouches?.[0];
4
+
5
+ if (!touch) return; // should never happen but safe
6
+
7
+ const rect = this.targetElement.getBoundingClientRect();
8
+ let x = touch.clientX - rect.left;
9
+ let y = touch.clientY - rect.top;
10
+
11
+ if(this.cache.useNormalisedCoordinates){
12
+ const w = this.targetElement.clientWidth;
13
+ const h = this.targetElement.clientHeight;
14
+ x = +((x / w) * 2 - 1).toFixed(8);
15
+ y = +((y / h) * -2 + 1).toFixed(8);
16
+ }
17
+
18
+ switch (this.currentEvent) {
19
+ case "touchstart":
20
+ this.dx = x;
21
+ this.dy = y;
22
+ this.isDown = true;
23
+ break;
24
+
25
+ case "touchmove":
26
+ this.mx = x;
27
+ this.my = y;
28
+ this.isMoving = true;
29
+ break;
30
+
31
+ case "touchend":
32
+ this.ux = x;
33
+ this.uy = y;
34
+ this.isDown = false;
35
+ break;
36
+ }
37
+ }
@@ -12,7 +12,6 @@ import{
12
12
  sqrt,
13
13
  ln
14
14
  }from "../functions/index.js"
15
- import { Matrix } from "../matrix/index.js";
16
15
  import {sum,prod,deg2rad} from "../utils/index.js";
17
16
  class Complex{
18
17
  constructor(a = 0, b = 0) {
@@ -183,10 +182,10 @@ class Complex{
183
182
  }
184
183
  const complex=(a,b)=>{
185
184
  if((a instanceof Array||ArrayBuffer.isView(a)) && (b instanceof Array||ArrayBuffer.isView(a)))return a.map((n,i)=>complex(a[i],b[i]));
186
- if(a instanceof Matrix && b instanceof Matrix){
185
+ if(a.isMatrix?.() && b.isMatrix?.()){
187
186
  if((a.shape[0]!==b.shape[0])||(a.shape[1]!==b.shape[1]))return Error(0)
188
187
  const arr=a.arr.map((n,i)=>complex(a.arr[i],b.arr[i]))
189
- return new Matrix(a.rows,a.cols,...arr)
188
+ return new a.constructor(a.rows,a.cols,...arr)
190
189
  }
191
190
  return new Complex(a,b)
192
191
  }
@@ -1,5 +1,5 @@
1
1
  import { Complex } from "../../complex/index.js";
2
- import { Matrix } from "../../matrix/Matrix.js";
2
+ import { Matrix } from "../../matrix/matrix.js";
3
3
  const Base={
4
4
  _mode:Number,
5
5
  _map:function(func,number,toBase){
@@ -1,5 +1,5 @@
1
1
  import { Complex } from "../../complex/index.js";
2
- import { Matrix } from "../../matrix/Matrix.js";
2
+ import { Matrix } from "../../matrix/matrix.js";
3
3
  const Logic={
4
4
  _mode:Number,
5
5
  _map:function(func,a,b){
@@ -1,5 +1,4 @@
1
1
  import { Fixed } from "./helper.js";
2
- import { Complex } from "../complex/index.js";
3
2
  import { mapfun } from "../utils/mapfun.js";
4
3
  import {
5
4
  min,
@@ -11,12 +10,12 @@ const sqrt=(...x)=>mapfun(Math.sqrt,...x);
11
10
  const pow=(x,n)=>{
12
11
  if(typeof x === "number"){
13
12
  if(typeof n === "number")return Math.pow(x,n);
14
- else if(n instanceof Complex)return Complex.fromExpo(x**n.a,n.b*ln(x))
13
+ else if(n?.isComplex?.())return n.constructor.fromExpo(x**n.a,n.b*ln(x))
15
14
  else return mapfun(a=>pow(x,a),...n);
16
15
  }
17
- else if(x instanceof Complex){
18
- if(typeof n === "number")return Complex.fromExpo(x.z**n,x.phi*n);
19
- else if(n instanceof Complex)return Complex.fromExpo(
16
+ else if(x.isComplex?.()){
17
+ if(typeof n === "number")return x.constructor.fromExpo(x.z**n,x.phi*n);
18
+ else if(n.isComplex?.())return x.constructor.fromExpo(
20
19
  x.z**n.a*e(-x.phi*n.b),
21
20
  ln(x.z)*n.b+n.a*x.phi
22
21
  )
@@ -38,8 +37,8 @@ const sqrtn=(x,n)=>{
38
37
  if(typeof n === "number")return Math.pow(x,1/n);
39
38
  else return mapfun(a=>sqrtn(x,a),...n);
40
39
  }
41
- else if(x instanceof Complex){
42
- if(typeof n === "number")return Complex.fromExpo(sqrtn(x.z,n),x.phi/n);
40
+ else if(x.isComplex?.()){
41
+ if(typeof n === "number")return x.constructor.fromExpo(sqrtn(x.z,n),x.phi/n);
43
42
  else return mapfun(a=>sqrtn(x,a),...n);
44
43
  }
45
44
  else if(x instanceof Array){
@@ -81,8 +80,8 @@ const atan2=(x,y,rad=true)=>{
81
80
  if(typeof y === "number")return rad?Math.atan2(x,y):Math.atan2(x,y)*180/Math.PI;
82
81
  else return mapfun(a=>atan2(x,a,rad),...y);
83
82
  }
84
- // else if(x instanceof Complex){
85
- // if(typeof n === "number")return Complex.fromExpo(x.z**n,x.phi*n);
83
+ // else if(x.isComplex?.()){
84
+ // if(typeof n === "number")return x.constructor.fromExpo(x.z**n,x.phi*n);
86
85
  // else return mapfun(a=>pow(x,a),...n);
87
86
  // }
88
87
  else if(x instanceof Array){
@@ -0,0 +1,36 @@
1
+ import { add, sub, mul } from "../../utils/index.js";
2
+ import { pow } from "../../functions/index.js";
3
+ export function matrix_det(M) {
4
+ if (!M.isSquare) return new Error("is not square matrix");
5
+ if (M.rows == 1) return M.arr[0][0];
6
+ function determinat(M) {
7
+ if (M.length == 2) {
8
+ if (M.flat(1).some((n) => n?.isMatrix?.())) {
9
+ console.warn("Tensors are not completely supported yet ...");
10
+ return;
11
+ }
12
+ return sub(mul(M[0][0],M[1][1]),mul(M[0][1],M[1][0]))
13
+ }
14
+ var answer = 0;
15
+ for (var i = 0; i < M.length; i++) {
16
+ //console.log(M[0][i]);
17
+ /*answer = answer.add(
18
+ pow(-1, i)
19
+ .mul(M[0][i])
20
+ .mul(determinat(deleteRowAndColumn(M, i)))
21
+ );*/
22
+ //const to_be_added=add(mul(pow(-1, i),mul(M[0][i],determinat(deleteRowAndColumn(M, i)))));
23
+ const to_be_added=add(mul(pow(-1, i),mul(M[0][i],determinat(deleteRowAndColumn(M, i)))));
24
+ answer=add(answer,to_be_added)
25
+ }
26
+ return answer;
27
+ }
28
+ return determinat(M.arr);
29
+ }
30
+ function deleteRowAndColumn(M, index) {
31
+ var temp = [];
32
+ for (let i = 0; i < M.length; i++) temp.push(M[i].slice(0));
33
+ temp.splice(0, 1);
34
+ for (let i = 0; i < temp.length; i++) temp[i].splice(index, 1);
35
+ return temp;
36
+ }
@@ -0,0 +1,3 @@
1
+ export * from './inverse.js'
2
+ export * from './det.js'
3
+ export * from './stack.js'
@@ -0,0 +1,52 @@
1
+ export function matrix_inverse(M) {
2
+ if(M.row !== M.cols) throw Error('is not a square matrix"')
3
+ if (M.det === 0) throw Error("determinant should not equal 0");
4
+ const { arr } = M
5
+ if (arr.length !== arr[0].length) return;
6
+ var i = 0, ii = 0, j = 0, dim = arr.length, e = 0;
7
+ var I = [], C = [];
8
+ for (i = 0; i < dim; i += 1) {
9
+ I[I.length] = [];
10
+ C[C.length] = [];
11
+ for (j = 0; j < dim; j += 1) {
12
+ if (i == j) I[i][j] = 1;
13
+ else I[i][j] = 0;
14
+ C[i][j] = arr[i][j];
15
+ }
16
+ }
17
+ for (i = 0; i < dim; i += 1) {
18
+ e = C[i][i];
19
+ if (e == 0) {
20
+ for (ii = i + 1; ii < dim; ii += 1) {
21
+ if (C[ii][i] != 0) {
22
+ for (j = 0; j < dim; j++) {
23
+ e = C[i][j];
24
+ C[i][j] = C[ii][j];
25
+ C[ii][j] = e;
26
+ e = I[i][j];
27
+ I[i][j] = I[ii][j];
28
+ I[ii][j] = e;
29
+ }
30
+ break;
31
+ }
32
+ }
33
+ e = C[i][i];
34
+ if (e == 0) return;
35
+ }
36
+ for (j = 0; j < dim; j++) {
37
+ C[i][j] = C[i][j] / e;
38
+ I[i][j] = I[i][j] / e;
39
+ }
40
+ for (ii = 0; ii < dim; ii++) {
41
+ if (ii == i) {
42
+ continue;
43
+ }
44
+ e = C[ii][i];
45
+ for (j = 0; j < dim; j++) {
46
+ C[ii][j] -= e * C[i][j];
47
+ I[ii][j] -= e * I[i][j];
48
+ }
49
+ }
50
+ }
51
+ return new M.constructor(I);
52
+ }
@@ -0,0 +1,24 @@
1
+ export function hstack(M1, M2){
2
+ M1 = M1.clone()
3
+ M2 = M2.clone()
4
+ if (M1.rows !== M2.rows) return;
5
+ let newArr = M1.arr;
6
+ for (let i = 0; i < M1.rows; i++)
7
+ for (let j = M1.cols; j < M1.cols + M2.cols; j++)
8
+ newArr[i][j] = M2.arr[i][j - M1.cols];
9
+ M1.cols += M2.cols;
10
+ return new M1.constructor(M1.rows, M1.cols, newArr.flat(1));
11
+ }
12
+
13
+ export function vstack(M1, M2){
14
+ M1 = M1.clone()
15
+ M2 = M2.clone()
16
+ if (M1.cols !== M2.cols) return;
17
+ let newArr = M1.arr;
18
+ for (let i = M1.rows; i < M1.rows + M2.rows; i++) {
19
+ newArr[i] = [];
20
+ for (let j = 0; j < M1.cols; j++) newArr[i][j] = M2.arr[i - M1.rows][j];
21
+ }
22
+ M1.rows += M2.rows;
23
+ return new M1.constructor(M1.rows, M1.cols, newArr.flat(1));
24
+ }
@@ -1 +1 @@
1
- export * from "./Matrix.js"
1
+ export * from "./matrix.js"