ziko 0.52.0 → 0.54.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": "ziko",
3
- "version": "0.52.0",
3
+ "version": "0.54.0",
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,18 +1,5 @@
1
- import{
2
- cos,
3
- sin,
4
- tan,
5
- pow,
6
- floor,
7
- hypot,
8
- cosh,
9
- sinh,
10
- sqrtn,
11
- atan2,
12
- sqrt,
13
- ln
14
- }from "../functions/index.js"
15
- import {sum,prod,deg2rad} from "../utils/index.js";
1
+ // import {sum,prod,deg2rad} from "../utils/index.js";
2
+ // Should avoid CD
16
3
  class Complex{
17
4
  constructor(a = 0, b = 0) {
18
5
  if(a instanceof Complex){
@@ -21,33 +8,33 @@ class Complex{
21
8
  }
22
9
  else if(typeof(a)==="object"){
23
10
  if(("a" in a && "b" in a)){
24
- this.a=a.a;
25
- this.b=a.b;
11
+ this.a = a.a;
12
+ this.b = a.b;
26
13
  }
27
14
  else if(("a" in a && "z" in a)){
28
- this.a=a.a;
29
- this.b=sqrt((a.z**2)-(a.a**2));
15
+ this.a = a.a;
16
+ this.b = Math.sqrt((a.z**2)-(a.a**2));
30
17
  }
31
18
  else if(("a" in a && "phi" in a)){
32
- this.a=a.a;
33
- this.b=a.a*tan(a.phi);
19
+ this.a = a.a;
20
+ this.b = a.a * Math.tan(a.phi);
34
21
  }
35
22
  else if(("b" in a && "z" in a)){
36
- this.b=a.b;
37
- this.a=sqrt((a.z**2)-(a.b**2));
23
+ this.b = a.b;
24
+ this.a = Math.sqrt((a.z**2)-(a.b**2));
38
25
  }
39
26
  else if(("b" in a && "phi" in a)){
40
- this.b=b;
41
- this.a=a.b/tan(a.phi);
27
+ this.b = b;
28
+ this.a = a.b / Math.tan(a.phi);
42
29
  }
43
30
  else if(("z" in a && "phi" in a)){
44
- this.a = +a.z*cos(a.phi).toFixed(15);
45
- this.b = +a.z*sin(a.phi).toFixed(15);
31
+ this.a = + a.z * Math.cos(a.phi).toFixed(15);
32
+ this.b = + a.z * Math.sin(a.phi).toFixed(15);
46
33
  }
47
34
  }
48
- else if(typeof(a)==="number"&&typeof(b)==="number"){
49
- this.a = +a.toFixed(32);
50
- this.b = +b.toFixed(32);
35
+ else if(typeof(a)==="number" && typeof(b)==="number"){
36
+ this.a = + a.toFixed(32);
37
+ this.b = + b.toFixed(32);
51
38
  }
52
39
  }
53
40
  get __mapfun__(){
@@ -69,14 +56,14 @@ class Complex{
69
56
  return str;
70
57
  }
71
58
 
72
- get clone() {
59
+ clone() {
73
60
  return new Complex(this.a, this.b);
74
61
  }
75
62
  get z(){
76
- return hypot(this.a,this.b);
63
+ return Math.hypot(this.a,this.b);
77
64
  }
78
65
  get phi(){
79
- return atan2(this.b , this.a);
66
+ return Math.atan2(this.b , this.a);
80
67
  }
81
68
  static Zero() {
82
69
  return new Complex(0, 0);
@@ -85,54 +72,54 @@ class Complex{
85
72
  return new Complex(this.a, -this.b);
86
73
  }
87
74
  get inv() {
88
- return new Complex(this.a / (pow(this.a, 2) + pow(this.b, 2)), -this.b / (pow(this.a, 2) + pow(this.b, 2)));
89
- }
90
- add(...z) {
91
- for (let i = 0; i < z.length; i++) {
92
- if (typeof z[i] === "number") z[i] = new Complex(z[i], 0);
75
+ return new Complex(
76
+ this.a / Math.hypot(this.a, this.b),
77
+ -this.b / Math.hypot(this.a, this.b)
78
+ );
79
+ }
80
+ add(...c) {
81
+ for (let i = 0; i < c.length; i++) {
82
+ if (typeof c[i] === "number") c[i] = new Complex(c[i], 0);
83
+ this.a += c[i].a;
84
+ this.b += c[i].b;
93
85
  }
94
- let re = z.map((n) => n.a);
95
- let im = z.map((n) => n.b);
96
- this.a+=+sum(...re).toFixed(15);
97
- this.b+=+sum(...im).toFixed(15);
98
86
  return this;
99
87
  }
100
- sub(...z) {
101
- for (let i = 0; i < z.length; i++) {
102
- if (typeof z[i] === "number") z[i] = new Complex(z[i], 0);
88
+ sub(...c) {
89
+ for (let i = 0; i < c.length; i++) {
90
+ if (typeof c[i] === "number") c[i] = new Complex(c[i], 0);
91
+ this.a -= c[i].a;
92
+ this.b -= c[i].b;
103
93
  }
104
- let re = z.map((n) => n.a);
105
- let im = z.map((n) => n.b);
106
- this.a-=+sum(...re).toFixed(15);
107
- this.b-=+sum(...im).toFixed(15);
108
94
  return this;
109
95
  }
110
- mul(...z){
111
- for (let i = 0; i < z.length; i++) {
112
- if (typeof z[i] === "number") z[i] = new Complex(z[i], 0);
96
+ mul(...c){
97
+ let {z, phi} = this;
98
+ for (let i = 0; i < c.length; i++) {
99
+ if (typeof c[i] === "number") c[i] = new Complex(c[i], 0);
100
+ z *= c[i].z;
101
+ phi += c[i].z;
113
102
  }
114
- let Z=+prod(this.z,...z.map(n=>n.z)).toFixed(15);
115
- let phi=+sum(this.phi,...z.map(n=>n.phi)).toFixed(15);
116
- this.a=+(Z*cos(phi).toFixed(15)).toFixed(14);
117
- this.b=+(Z*sin(phi).toFixed(15)).toFixed(14);
103
+ this.a = z*Math.cos(phi)
104
+ this.b = z*Math.sin(phi)
118
105
  return this;
119
106
  }
120
- div(...z) {
121
- for (let i = 0; i < z.length; i++) {
122
- if (typeof z[i] === "number") z[i] = new Complex(z[i], 0);
107
+ div(...c){
108
+ let {z, phi} = this;
109
+ for (let i = 0; i < c.length; i++) {
110
+ if (typeof c[i] === "number") c[i] = new Complex(c[i], 0);
111
+ z /= c[i].z;
112
+ phi -= c[i].z;
123
113
  }
124
- let Z=+(this.z/prod(...z.map(n=>n.z))).toFixed(15);
125
- let phi=+(this.phi-sum(...z.map(n=>n.phi))).toFixed(15);
126
- this.a=+(Z*cos(phi).toFixed(15)).toFixed(15);
127
- this.b=+(Z*sin(phi).toFixed(15)).toFixed(15);
114
+ this.a = z*Math.cos(phi)
115
+ this.b = z*Math.sin(phi)
128
116
  return this;
129
117
  }
130
- pow(n) {
131
- if (floor(n) === n && n > 0) {
132
- let z=+(this.z**n).toFixed(15);
133
- let phi=+(this.phi*n).toFixed(15);
134
- this.a=+(z*cos(phi).toFixed(15)).toFixed(15);
135
- this.b=+(z*sin(phi).toFixed(15)).toFixed(15);
118
+ modulo(...c) {
119
+ for (let i = 0; i < c.length; i++) {
120
+ if (typeof c[i] === "number") c[i] = new Complex(c[i], 0);
121
+ this.a %= c[i].a;
122
+ this.b %= c[i].b;
136
123
  }
137
124
  return this;
138
125
  }
@@ -146,41 +133,48 @@ class Complex{
146
133
  return [this.z, this.phi];
147
134
  }
148
135
  static add(c,...z) {
149
- return c.clone.add(...z);
136
+ return c.clone().add(...z);
150
137
  }
151
138
  static sub(c,...z) {
152
- return c.clone.sub(...z);
139
+ return c.clone().sub(...z);
153
140
  }
154
141
  static mul(c,...z) {
155
- return c.clone.mul(...z);
142
+ return c.clone().mul(...z);
156
143
  }
157
144
  static div(c,...z) {
158
- return c.clone.div(...z);
159
- }
160
- static pow(z,n){
161
- return z.clone.pow(n);
145
+ return c.clone().div(...z);
162
146
  }
163
- static xpowZ(x){
164
- return complex((x**this.a)*cos(this.b*ln(x)),(x**this.a)*sin(this.b*ln(x)));
165
- }
166
- sqrtn(n=2){
167
- return complex(sqrtn(this.z,n)*cos(this.phi/n),sqrtn(this.z,n)*sin(this.phi/n));
147
+
148
+ nthr(n=2){
149
+ return complex({z: this.z ** (1/n), phi: this.phi / n});
168
150
  }
169
151
  get sqrt(){
170
- return this.sqrtn(2);
152
+ return this.nrth(2);
153
+ }
154
+ get cbrt(){
155
+ return this.nrth(3);
171
156
  }
172
157
  get log(){
173
- return complex(this.z,this.phi);
158
+ return complex(this.z, this.phi);
174
159
  }
175
160
  get cos(){
176
- return complex(cos(this.a)*cosh(this.b),sin(this.a)*sinh(this.b))
161
+ return complex(
162
+ Math.cos(this.a) * Math.cosh(this.b),
163
+ Math.sin(this.a) * Math.sinh(this.b)
164
+ )
177
165
  }
178
166
  get sin(){
179
- return complex(sin(this.a)*cosh(this.b),cos(this.a)*sinh(this.b))
167
+ return complex(
168
+ Math.sin(this.a) * Math.cosh(this.b),
169
+ Math.cos(this.a) * Math.sinh(this.b)
170
+ )
180
171
  }
181
172
  get tan(){
182
- const de=cos(this.a*2)+cosh(this.b*2);
183
- return complex(sin(2*this.a)/de,sinh(2*this.b)/de);
173
+ const D=cos(this.a*2)+cosh(this.b*2);
174
+ return complex(
175
+ Math.sin(2 * this.a) / D,
176
+ Math.sinh(2 * this.b) / D
177
+ );
184
178
  }
185
179
  }
186
180
  const complex=(a,b)=>{
@@ -0,0 +1,82 @@
1
+ const _add = (x, y) =>{
2
+ if(typeof x === 'number'){
3
+ if(typeof y === 'number') return x + y;
4
+ if(y.isComplex?.()) {
5
+ return y.clone().add(x);
6
+ }
7
+ }
8
+ if(x.isComplex?.()){
9
+ if(typeof y === 'number' || y.isComplex?.()) return new x.clone().add(y);
10
+ }
11
+ }
12
+
13
+ const _sub = (x, y) =>{
14
+ if(typeof x === 'number'){
15
+ if(typeof y === 'number') return x - y;
16
+ if(y.isComplex?.()) return new y.constructor(x - y.a, y.b);
17
+ }
18
+ if(x.isComplex?.()){
19
+ if(typeof y === 'number' || y.isComplex?.()) return new x.clone().sub(y);
20
+ }
21
+ }
22
+
23
+ const _mul = (x, y) =>{
24
+ if(typeof x === 'number'){
25
+ if(typeof y === 'number') return x * y;
26
+ if(y.isComplex?.()) return y.clone().mul(x);
27
+ }
28
+ if(x.isComplex?.()){
29
+ if(typeof y === 'number' || y.isComplex?.()) return new x.clone().mul(y);
30
+ }
31
+ }
32
+
33
+ const _div = (x, y) =>{
34
+ if(typeof x === 'number'){
35
+ if(typeof y === 'number') return x / y;
36
+ if(y.isComplex?.()) return new y.constructor(x, 0).div(y)
37
+ }
38
+ if(x.isComplex?.()){
39
+ if(typeof y === 'number' || y.isComplex?.()) return new x.clone().mul(y);
40
+ }
41
+ }
42
+
43
+ const _modulo = (x, y) =>{
44
+ if(typeof x === 'number'){
45
+ if(typeof y === 'number') return x % y;
46
+ if(y.isComplex?.()) return new y.constructor(x, 0).modulo(y)
47
+ }
48
+ if(x.isComplex?.()){
49
+ if(typeof y === 'number' || y.isComplex?.()) return new x.clone().modulo(y);
50
+ }
51
+ }
52
+
53
+ export const add=(a,...b)=>{
54
+ let res = a;
55
+ for(let i=0; i<b.length; i++)
56
+ res = _add(res, b[i])
57
+ return res;
58
+ }
59
+ export const sub=(a,...b)=>{
60
+ let res = a;
61
+ for(let i=0; i<b.length; i++)
62
+ res = _sub(res, b[i])
63
+ return res;
64
+ }
65
+ export const mul=(a,...b)=>{
66
+ let res = a;
67
+ for(let i=0; i<b.length; i++)
68
+ res = _mul(res, b[i])
69
+ return res;
70
+ }
71
+ export const div=(a,...b)=>{
72
+ let res = a;
73
+ for(let i=0; i<b.length; i++)
74
+ res = _div(res, b[i])
75
+ return res;
76
+ }
77
+ export const modulo=(a,...b)=>{
78
+ let res = a;
79
+ for(let i=0; i<b.length; i++)
80
+ res = _modulo(res, b[i])
81
+ return res;
82
+ }
@@ -1,155 +1,41 @@
1
- import { Fixed } from "./helper.js";
2
- import { mapfun } from "../mapfun/index.js";
3
- import {
4
- min,
5
- max
6
- }
7
- from "../statistics/index.js";
1
+ export * from './mapfun/index.js'
2
+ export * from './nested/index.js'
3
+ export * from './arithmetic/index.js'
4
+ export * from './utils/index.js'
5
+ // export const atan2=(x,y,rad=true)=>{
6
+ // if(typeof x === "number"){
7
+ // if(typeof y === "number")return rad?Math.atan2(x,y):Math.atan2(x,y)*180/Math.PI;
8
+ // else return mapfun(a=>atan2(x,a,rad),...y);
9
+ // }
10
+ // // else if(x.isComplex?.()){
11
+ // // if(typeof n === "number")return x.constructor.fromExpo(x.z**n,x.phi*n);
12
+ // // else return mapfun(a=>pow(x,a),...n);
13
+ // // }
14
+ // else if(x instanceof Array){
15
+ // if(typeof y === "number") return mapfun(a=>atan2(a,y,rad),...x);
16
+ // else if(y instanceof Array){
17
+ // const Y=[];
18
+ // for(let i=0;i<x.length;i++){
19
+ // Y.push(mapfun(a=>pow(x[i],a,rad),...y))
20
+ // }
21
+ // return Y;
22
+ // }
23
+ // }
24
+ // }
25
+ // export const fact=(...x)=>mapfun(n=> {
26
+ // let i,
27
+ // y = 1;
28
+ // if (n == 0) y = 1;
29
+ // else if (n > 0) for (i = 1; i <= n; i++) y *= i;
30
+ // else y = NaN;
31
+ // return y;
32
+ // },...x);
8
33
 
9
- const abs=(...x)=>mapfun(Math.abs,...x);
10
- const sqrt=(...x)=>mapfun(Math.sqrt,...x);
11
- const pow=(x,n)=>{
12
- if(typeof x === "number"){
13
- if(typeof n === "number")return Math.pow(x,n);
14
- else if(n?.isComplex?.())return n.constructor.fromExpo(x**n.a,n.b*ln(x))
15
- else return mapfun(a=>pow(x,a),...n);
16
- }
17
- else if(x.isComplex?.()){
18
- if(typeof n === "number")return x.constructor.fromExpo(x.z**n,x.phi*n);
19
- else if(n.isComplex?.())return x.constructor.fromExpo(
20
- x.z**n.a*e(-x.phi*n.b),
21
- ln(x.z)*n.b+n.a*x.phi
22
- )
23
- else return mapfun(a=>pow(x,a),...n);
24
- }
25
- else if(x instanceof Array){
26
- if(typeof n === "number") return mapfun(a=>pow(a,n),...x);
27
- else if(n instanceof Array){
28
- const Y=[];
29
- for(let i=0;i<x.length;i++){
30
- Y.push(mapfun(a=>pow(x[i],a),...n))
31
- }
32
- return Y;
33
- }
34
- }
35
- }
36
- const sqrtn=(x,n)=>{
37
- if(typeof x === "number"){
38
- if(typeof n === "number")return Math.pow(x,1/n);
39
- else return mapfun(a=>sqrtn(x,a),...n);
40
- }
41
- else if(x.isComplex?.()){
42
- if(typeof n === "number")return x.constructor.fromExpo(sqrtn(x.z,n),x.phi/n);
43
- else return mapfun(a=>sqrtn(x,a),...n);
44
- }
45
- else if(x instanceof Array){
46
- if(typeof n === "number") return mapfun(a=>sqrtn(a,n),...x);
47
- else if(n instanceof Array){
48
- const Y=[];
49
- for(let i=0;i<x.length;i++){
50
- Y.push(mapfun(a=>sqrtn(x[i],a),...n))
51
- }
52
- return Y;
53
- }
54
- }
55
- }
56
- const e=(...x) => mapfun(Math.exp,...x);
57
- const ln=(...x) => mapfun(Math.log,...x);
58
- const cos=(...x) => mapfun(Fixed.cos,...x);
59
- const sin=(...x) => mapfun(Fixed.sin,...x);
60
- const tan=(...x) => mapfun(Fixed.tan,...x);
61
- const sec=(...x) => mapfun(Fixed.sec,...x);
62
- const sinc=(...x) => mapfun(Fixed.sinc,...x)
63
- const csc=(...x) => mapfun(Fixed.csc,...x);
64
- const cot=(...x) => mapfun(Fixed.cot,...x);
65
- const acos=(...x) => mapfun(Fixed.acos,...x);
66
- const asin=(...x) => mapfun(Fixed.asin,...x);
67
- const atan=(...x) => mapfun(Fixed.atan,...x);
68
- const acot=(...x) => mapfun(Fixed.acot,...x);
69
- const cosh=(...x) => mapfun(Fixed.cosh,...x);
70
- const sinh=(...x) => mapfun(Fixed.sinh,...x);
71
- const tanh=(...x) => mapfun(Fixed.tanh,...x);
72
- const coth=(...x) => mapfun(Fixed.coth,...x);
73
- const acosh=(...x) => mapfun(Fixed.acosh,...x);
74
- const asinh=(...x) => mapfun(Fixed.asinh,...x);
75
- const atanh=(...x) => mapfun(Fixed.atanh,...x);
76
- const ceil=(...x) => mapfun(Math.ceil,...x);
77
- const floor=(...x) => mapfun(Math.floor,...x);
78
- const round=(...x) => mapfun(Math.round,...x);
79
- const atan2=(x,y,rad=true)=>{
80
- if(typeof x === "number"){
81
- if(typeof y === "number")return rad?Math.atan2(x,y):Math.atan2(x,y)*180/Math.PI;
82
- else return mapfun(a=>atan2(x,a,rad),...y);
83
- }
84
- // else if(x.isComplex?.()){
85
- // if(typeof n === "number")return x.constructor.fromExpo(x.z**n,x.phi*n);
86
- // else return mapfun(a=>pow(x,a),...n);
87
- // }
88
- else if(x instanceof Array){
89
- if(typeof y === "number") return mapfun(a=>atan2(a,y,rad),...x);
90
- else if(y instanceof Array){
91
- const Y=[];
92
- for(let i=0;i<x.length;i++){
93
- Y.push(mapfun(a=>pow(x[i],a,rad),...y))
94
- }
95
- return Y;
96
- }
97
- }
98
- }
99
- const fact=(...x)=>mapfun(n=> {
100
- let i,
101
- y = 1;
102
- if (n == 0) y = 1;
103
- else if (n > 0) for (i = 1; i <= n; i++) y *= i;
104
- else y = NaN;
105
- return y;
106
- },...x);
107
- const sign=(...x)=>mapfun(Math.sign,...x);
34
+ // export const hypot=(...x)=>{
35
+ // if(x.every(n=>typeof n === "number"))return Math.hypot(...x);
36
+ // if(x.every(n=>n instanceof Array))return mapfun(
37
+ // Math.hypot,
38
+ // ...x
39
+ // )
40
+ // }
108
41
 
109
- const sig=(...x)=>mapfun(n=>1/(1+e(-n)),...x);
110
-
111
- const hypot=(...x)=>{
112
- if(x.every(n=>typeof n === "number"))return Math.hypot(...x);
113
- if(x.every(n=>n instanceof Array))return mapfun(
114
- Math.hypot,
115
- ...x
116
- )
117
- }
118
-
119
- export{
120
- cos,
121
- sin,
122
- tan,
123
- sinc,
124
- cot,
125
- sec,
126
- csc,
127
- abs,
128
- sqrt,
129
- pow,
130
- sqrtn,
131
- e,
132
- ln,
133
- acos,
134
- asin,
135
- atan,
136
- acot,
137
- cosh,
138
- sinh,
139
- tanh,
140
- coth,
141
- acosh,
142
- asinh,
143
- atanh,
144
- min,
145
- max,
146
- sign,
147
- floor,
148
- ceil,
149
- round,
150
- fact,
151
- hypot,
152
- sig,
153
- atan2
154
- };
155
-
@@ -1,4 +1,4 @@
1
- import { is_primitive } from "../../helpers/checkers/index.js";
1
+ import { is_primitive } from "../../../helpers/checkers/index.js";
2
2
  export const mapfun=(fun,...X)=>{
3
3
  const Y=X.map(x=>{
4
4
  if(is_primitive(x) || x?.__mapfun__) return fun(x)