ziko 1.4.0 → 1.6.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.
Files changed (34) hide show
  1. package/dist/ziko.cjs +396 -117
  2. package/dist/ziko.js +396 -117
  3. package/dist/ziko.min.js +2 -2
  4. package/dist/ziko.mjs +369 -118
  5. package/package.json +1 -1
  6. package/src/dom/components/for/index.js +17 -0
  7. package/src/dom/components/index.js +2 -1
  8. package/src/dom/components/swap/index.js +3 -3
  9. package/src/dom/constructors/UIElement.js +23 -4
  10. package/src/dom/constructors/UIElementCore.js +2 -1
  11. package/src/dom/constructors/mixins/dom.js +31 -22
  12. package/src/math/complex/index.d.ts +207 -30
  13. package/src/math/functions/arithmetic/index.d.ts +95 -0
  14. package/src/math/functions/conversions/index.d.ts +101 -0
  15. package/src/math/functions/index.d.ts +97 -90
  16. package/src/math/functions/logic/index.d.ts +50 -8
  17. package/src/math/functions/logic/index.js +1 -1
  18. package/src/math/functions/mapfun/index.d.ts +46 -80
  19. package/src/math/functions/mapfun/index.d.ts.txt +162 -0
  20. package/src/math/functions/signal/index.d.ts +146 -0
  21. package/src/math/functions/stats/index.js +33 -33
  22. package/src/math/functions/ufunc/index.d.ts +96 -0
  23. package/src/math/functions/utils/index.d.ts +118 -1
  24. package/src/math/index.d.ts +4 -0
  25. package/src/math/index.js +1 -16
  26. package/src/math/random/index.d.ts +162 -0
  27. package/src/math/random/index.js +4 -4
  28. package/src/math/stats/accum/index.d.ts +43 -0
  29. package/src/math/stats/average/index.d.ts +123 -0
  30. package/src/math/stats/index.d.ts +5 -0
  31. package/src/math/stats/percentile/index.d.ts +66 -0
  32. package/src/math/stats/rolling/index.d.ts +47 -0
  33. package/src/math/stats/variability/index.d.ts +93 -0
  34. package/src/math/index.d.ts.txt +0 -5
@@ -0,0 +1,17 @@
1
+ import { Fragment, UIFragment } from "../fragment/index.js";
2
+
3
+ class UIFor extends UIFragment{
4
+ constructor({each, fallback, mapFn = () => {}} = {}){
5
+ super()
6
+ this.config = {
7
+ each,
8
+ fallback,
9
+ mapFn
10
+ }
11
+ this.append(
12
+ ...this.config.each.map((n,i) => this.config.mapFn(n, i))
13
+ )
14
+ }
15
+ }
16
+
17
+ export const For = ({each, fallback, mapFn} = {}) => new UIFor({each, fallback, mapFn})
@@ -1,2 +1,3 @@
1
1
  export * from './swap/index.js'
2
- export * from './fragment/index.js'
2
+ export * from './fragment/index.js'
3
+ export * from './for/index.js'
@@ -12,14 +12,14 @@ export class UISwap extends UIElement {
12
12
  };
13
13
 
14
14
  this.append(...items);
15
- this.#setup();
15
+ this.render();
16
16
  }
17
17
  get activeItem(){
18
18
  return this.items[this.states.activeIndex]
19
19
  }
20
- #setup() {
20
+ render() {
21
21
  this.items.forEach((n, i) => {
22
- // Store initial display style (fallback to empty string or default)
22
+
23
23
  const initialDisplay = n.element?.style?.display || '';
24
24
  this.#DISPLAYS_MAP.set(n, initialDisplay);
25
25
 
@@ -36,9 +36,16 @@ class UIElement extends UIElementCore{
36
36
  ViewListeners,
37
37
  );
38
38
 
39
- if(element)this.init(element, name, type, render)
40
- }
41
- on(event_name, callback, {details_setter, category = 'global', isCustom = false,preventDefault = false} = {}){
39
+ if(element)this.init(element, name, type, render);
40
+ }
41
+ on(event_name, callback, {details_setter, category = 'global', isCustom = false, preventDefault = false} = {}){
42
+ if(event_name instanceof Array) event_name.forEach(
43
+ event => this.on(
44
+ event,
45
+ callback,
46
+ {details_setter, category, isCustom, preventDefault}
47
+ )
48
+ )
42
49
  if(category && !this.exp.events.hasOwnProperty(category)) this.exp.events[category] = new EventController(this, category);
43
50
  isCustom && this.exp.events[category].cache.customEvents.add(event_name)
44
51
  const EVENT = this.exp.events[category];
@@ -51,11 +58,23 @@ class UIElement extends UIElementCore{
51
58
  return this;
52
59
  }
53
60
  _off(event, category = 'global'){
54
- this.exp.events[category].removeListener(event)
61
+ this.exp.events[category].removeListener(event);
62
+ return this
55
63
  }
56
64
  get element(){
57
65
  return this.cache.element;
58
66
  }
67
+ get itemsTarget(){
68
+ return this.cache.itemsTarget;
69
+ }
70
+ get itemsTargetElement(){
71
+ return this.itemsTarget.element;
72
+ }
73
+ setItemsTarget(parent){
74
+ this.cache.itemsTarget = parent;
75
+ this.items = parent.items;
76
+ return this;
77
+ }
59
78
  isInteractive(){
60
79
  return this.cache.isInteractive;
61
80
  }
@@ -24,6 +24,7 @@ class UIElementCore extends UINode{
24
24
  else this.target = element?.parentElement;
25
25
  Object.assign(this.cache, {
26
26
  name,
27
+ itemsTarget : this,
27
28
  isInteractive : false,
28
29
  parent:null,
29
30
  isBody:false,
@@ -60,7 +61,7 @@ class UIElementCore extends UINode{
60
61
  get element(){
61
62
  return this.cache.element;
62
63
  }
63
- [Symbol.iterator]() {
64
+ [Symbol.iterator](){
64
65
  return this.items[Symbol.iterator]();
65
66
  }
66
67
  maintain() {
@@ -1,8 +1,3 @@
1
- // import { isStateGetter } from "../../../hooks/use-state.js";
2
- // import {
3
- // is_camelcase,
4
- // camel2hyphencase
5
- // } from '../../../data/string/index.js';
6
1
  import { text } from "../../text/index.js";
7
2
 
8
3
  export function append(...ele) {
@@ -14,19 +9,30 @@ export function prepend(...ele) {
14
9
  return this;
15
10
  }
16
11
  export function insertAt(index, ...ele) {
17
- if (index >= this.element.children.length) this.append(...ele);
18
- else
12
+ const target = this.itemsTarget;
13
+
14
+ if (index >= target.items.length) return this.append(...ele);
15
+
19
16
  for (let i = 0; i < ele.length; i++) {
20
- if (["number", "string"].includes(typeof ele[i])) ele[i] = text(ele[i]);
21
- this.element?.insertBefore(ele[i].element, this.items[index].element);
22
- this.items.splice(index, 0, ele[i]);
17
+ if (["number", "string"].includes(typeof ele[i]))
18
+ ele[i] = text(ele[i]);
19
+
20
+ target.element?.insertBefore(
21
+ ele[i].element,
22
+ target.items[index].element
23
+ );
24
+
25
+ target.items.splice(index, 0, ele[i]);
23
26
  }
24
- return this;
27
+
28
+ target.maintain();
29
+
30
+ return this;
25
31
  }
26
32
  export function remove(...ele) {
27
33
  const remove = (ele) => {
28
34
  if (typeof ele === "number") ele = this.items[ele];
29
- if (ele?.isUIElement) this.element?.removeChild(ele.element);
35
+ if (ele?.isUIElement) this.itemsTarget.element?.removeChild(ele.element);
30
36
  this.items = this.items.filter((n) => n !== ele);
31
37
  };
32
38
  for (let i = 0; i < ele.length; i++) remove(ele[i]);
@@ -37,7 +43,7 @@ export function remove(...ele) {
37
43
  }
38
44
  export function clear(){
39
45
  this?.items?.forEach(n=>n.unmount());
40
- this.element.innerHTML = "";
46
+ this.itemsTarget.element.innerHTML = '';
41
47
  return this;
42
48
  }
43
49
  export function replaceElementWith(new_element){
@@ -49,12 +55,12 @@ export function replaceElementWith(new_element){
49
55
  }
50
56
  export function after(ui){
51
57
  if(ui?.isUIElement) ui=ui.element;
52
- this.element?.after(ui)
58
+ this.itemsTarget.element?.after(ui)
53
59
  return this;
54
60
  }
55
61
  export function before(ui){
56
62
  if(ui?.isUIElement) ui=ui.element;
57
- this.element?.before(ui)
63
+ this.itemsTarget.element?.before(ui)
58
64
  return this;
59
65
  }
60
66
 
@@ -62,6 +68,9 @@ export function before(ui){
62
68
 
63
69
 
64
70
  export async function __addItem__(adder, pusher, ...ele) {
71
+ const itemsTarget_el = this.itemsTarget.element;
72
+ const itemsTarget = this.itemsTarget
73
+
65
74
  if (this.cache.isFrozzen) {
66
75
  console.warn("You can't append new item to frozzen element");
67
76
  return this;
@@ -77,22 +86,22 @@ export async function __addItem__(adder, pusher, ...ele) {
77
86
  (newValue) => (ele[i].element.textContent = newValue),
78
87
  ele[i]
79
88
  );
80
- // this.element.appendChild(textNode);
89
+ // this.itemsTarget.element.appendChild(textNode);
81
90
  }
82
91
  }
83
92
  if (typeof globalThis?.Node === "function" && ele[i] instanceof globalThis?.Node) ele[i] = new this.constructor(ele[i]);
84
93
  if (ele[i]?.isUINode) {
85
94
  ele[i].cache.parent = this;
86
- this.element?.[adder](ele[i].element);
87
- ele[i].target = this.element;
88
- this.items[pusher](ele[i]);
95
+ itemsTarget_el?.[adder](ele[i].element);
96
+ ele[i].target = this.itemsTarget.element;
97
+ itemsTarget.items[pusher](ele[i]);
89
98
  }
90
99
  else if(ele[i] instanceof Promise){
91
100
  const UIEle = await ele[i]
92
101
  UIEle.cache.parent = this;
93
- this.element?.[adder](UIEle.element);
94
- UIEle.target = this.element;
95
- this.items[pusher](UIEle)
102
+ itemsTarget_el?.[adder](UIEle.element);
103
+ UIEle.target = this.itemsTarget.element;
104
+ itemsTarget.items[pusher](UIEle)
96
105
  }
97
106
  else if (ele[i] instanceof Object) {
98
107
  if (ele[i]?.style) this.style(ele[i]?.style);
@@ -1,54 +1,231 @@
1
+ import type { Matrix } from "../matrix/index.js";
2
+
3
+ /**
4
+ * Represents a complex number.
5
+ *
6
+ * A complex number is represented as:
7
+ * a + bi
8
+ */
1
9
  export declare class Complex {
2
10
  a: number;
3
11
  b: number;
4
12
 
5
13
  constructor(a?: number, b?: number);
6
14
  constructor(c: Complex);
7
- constructor(a:
8
- { a: number; b: number } |
9
- { a: number; z: number } |
10
- { a: number; phi: number } |
11
- { b: number; z: number } |
12
- { b: number; phi: number } |
13
- { z: number; phi: number }
15
+ constructor(value:
16
+ | { a: number; b: number }
17
+ | { a: number; z: number }
18
+ | { a: number; phi: number }
19
+ | { b: number; z: number }
20
+ | { b: number; phi: number }
21
+ | { z: number; phi: number }
14
22
  );
15
- constructor();
16
23
 
24
+ /**
25
+ * Used by mapfun to identify complex values.
26
+ */
27
+ readonly __mapfun__: boolean;
28
+
29
+ /**
30
+ * Checks whether this value is a Complex instance.
31
+ */
17
32
  isComplex(): true;
33
+
34
+ /**
35
+ * Converts the complex number to a string.
36
+ */
18
37
  toString(): string;
19
- readonly __mapfun__ : boolean
20
- readonly clone: Complex;
38
+
39
+ /**
40
+ * Serializes the complex number.
41
+ */
42
+ serialize(): string;
43
+
44
+ /**
45
+ * Deserializes a serialized complex number.
46
+ */
47
+ static deserialize(json: string | object): Complex | TypeError;
48
+
49
+ /**
50
+ * Rounds real and imaginary parts.
51
+ *
52
+ * @param n Number of decimal digits.
53
+ */
54
+ toFixed(n: number): this;
55
+
56
+ /**
57
+ * Formats real and imaginary parts with precision.
58
+ *
59
+ * @param n Number of significant digits.
60
+ */
61
+ toPrecision(n: number): this;
62
+
63
+ /**
64
+ * Creates a copy of this complex number.
65
+ */
66
+ clone(): Complex;
67
+
68
+ /**
69
+ * Magnitude of the complex number.
70
+ */
21
71
  readonly z: number;
72
+
73
+ /**
74
+ * Phase angle in radians.
75
+ */
22
76
  readonly phi: number;
77
+
78
+ /**
79
+ * Complex conjugate.
80
+ */
23
81
  readonly conj: Complex;
82
+
83
+ /**
84
+ * Multiplicative inverse.
85
+ */
24
86
  readonly inv: Complex;
87
+
88
+ /**
89
+ * Exponential representation [magnitude, phase].
90
+ */
91
+ readonly expo: [number, number];
92
+
93
+ /**
94
+ * Adds complex numbers.
95
+ */
96
+ add(...c: (number | Complex)[]): this;
97
+
98
+ /**
99
+ * Subtracts complex numbers.
100
+ */
101
+ sub(...c: (number | Complex)[]): this;
102
+
103
+ /**
104
+ * Multiplies complex numbers.
105
+ */
106
+ mul(...c: (number | Complex)[]): this;
107
+
108
+ /**
109
+ * Divides complex numbers.
110
+ */
111
+ div(...c: (number | Complex)[]): this;
112
+
113
+ /**
114
+ * Computes modulo.
115
+ */
116
+ modulo(...c: (number | Complex)[]): this;
117
+
118
+ /**
119
+ * Raises the complex number to a power.
120
+ */
121
+ pow(...c: (number | Complex)[]): this;
122
+
123
+ /**
124
+ * Calculates the nth root.
125
+ */
126
+ nthr(n?: number): Complex;
127
+
128
+ /**
129
+ * Square root.
130
+ */
25
131
  readonly sqrt: Complex;
132
+
133
+ /**
134
+ * Cube root.
135
+ */
26
136
  readonly cbrt: Complex;
137
+
138
+ /**
139
+ * Complex logarithm.
140
+ */
27
141
  readonly log: Complex;
142
+
143
+ /**
144
+ * Complex cosine.
145
+ */
28
146
  readonly cos: Complex;
147
+
148
+ /**
149
+ * Complex sine.
150
+ */
29
151
  readonly sin: Complex;
30
- readonly tan: Complex;
31
- expo: [number, number];
32
152
 
33
- add(...z: (number | Complex)[]): this;
34
- sub(...z: (number | Complex)[]): this;
35
- mul(...z: (number | Complex)[]): this;
36
- div(...z: (number | Complex)[]): this;
37
- pow(n: number): this;
38
- nthr(n?: number): Complex;
153
+ /**
154
+ * Complex tangent.
155
+ */
156
+ readonly tan: Complex;
39
157
 
158
+ /**
159
+ * Returns zero complex.
160
+ */
40
161
  static zero(): Complex;
41
- static twiddle(K : number, N : number): Complex;
42
- static fromPolar(z: number, phi: number): Complex;
43
-
44
- static add(c: Complex, ...z: (number | Complex)[]): Complex;
45
- static sub(c: Complex, ...z: (number | Complex)[]): Complex;
46
- static mul(c: Complex, ...z: (number | Complex)[]): Complex;
47
- static div(c: Complex, ...z: (number | Complex)[]): Complex;
48
- static pow(c: Complex, n: number): Complex;
162
+
163
+ /**
164
+ * Creates a complex number from polar coordinates.
165
+ *
166
+ * @param z Magnitude.
167
+ * @param phi Angle in radians.
168
+ */
169
+ static fromPolar(
170
+ z: number,
171
+ phi: number
172
+ ): Complex;
173
+
174
+ /**
175
+ * Creates FFT twiddle factor.
176
+ */
177
+ static twiddle(
178
+ K: number,
179
+ N: number
180
+ ): Complex;
181
+
182
+ /**
183
+ * Generates random complex numbers.
184
+ */
185
+ static readonly random: {
186
+ int(
187
+ a?: number,
188
+ b?: number
189
+ ): Complex;
190
+
191
+ float(
192
+ a?: number,
193
+ b?: number
194
+ ): Complex;
195
+ };
49
196
  }
50
197
 
51
- export declare function complex(a: number, b?: number): Complex;
52
- export declare function complex(a: Complex): Complex;
53
- export declare function complex(a: object): Complex;
54
- export declare function complex(): Complex;
198
+
199
+ /**
200
+ * Creates a complex number.
201
+ */
202
+ export declare function complex(
203
+ a?: number,
204
+ b?: number
205
+ ): Complex;
206
+
207
+ export declare function complex(
208
+ a: Complex
209
+ ): Complex;
210
+
211
+ export declare function complex(
212
+ a: object
213
+ ): Complex;
214
+
215
+
216
+ /**
217
+ * Creates arrays of complex numbers from two arrays.
218
+ */
219
+ export declare function complex(
220
+ a: number[] | ArrayLike<number>,
221
+ b: number[] | ArrayLike<number>
222
+ ): Complex[];
223
+
224
+
225
+ /**
226
+ * Creates a complex matrix by combining two matrices.
227
+ */
228
+ export declare function complex(
229
+ a: Matrix,
230
+ b: Matrix
231
+ ): Matrix;
@@ -0,0 +1,95 @@
1
+ /**
2
+ * Arithmetic operation compatible with numbers,
3
+ * complex numbers, and matrix-like objects.
4
+ */
5
+ export type ArithmeticValue = number | ComplexLike | MatrixLike;
6
+
7
+ /**
8
+ * Minimal interface for complex number objects.
9
+ */
10
+ export interface ComplexLike {
11
+ isComplex(): boolean;
12
+
13
+ clone(): this;
14
+
15
+ add(value: number | ComplexLike): this;
16
+ sub(value: number | ComplexLike): this;
17
+ mul(value: number | ComplexLike): this;
18
+ div(value: number | ComplexLike): this;
19
+ modulo(value: number | ComplexLike): this;
20
+ }
21
+
22
+ /**
23
+ * Minimal interface for matrix objects.
24
+ */
25
+ export interface MatrixLike {
26
+ rows: number;
27
+ cols: number;
28
+
29
+ isMatrix(): boolean;
30
+
31
+ clone(): this;
32
+
33
+ add(value: ArithmeticValue): this;
34
+ sub(value: ArithmeticValue): this;
35
+ mul(value: ArithmeticValue): this;
36
+ div(value: ArithmeticValue): this;
37
+ modulo(value: ArithmeticValue): this;
38
+ }
39
+
40
+ /**
41
+ * Adds values together.
42
+ *
43
+ * Supports numbers, complex numbers, and matrices.
44
+ *
45
+ * @example
46
+ * add(1, 2, 3) // 6
47
+ */
48
+ export declare function add<T extends ArithmeticValue>(
49
+ a: T,
50
+ ...b: ArithmeticValue[]
51
+ ): T;
52
+
53
+ /**
54
+ * Subtracts values sequentially.
55
+ *
56
+ * @example
57
+ * sub(10, 2, 3) // 5
58
+ */
59
+ export declare function sub<T extends ArithmeticValue>(
60
+ a: T,
61
+ ...b: ArithmeticValue[]
62
+ ): T;
63
+
64
+ /**
65
+ * Multiplies values sequentially.
66
+ *
67
+ * @example
68
+ * mul(2, 3, 4) // 24
69
+ */
70
+ export declare function mul<T extends ArithmeticValue>(
71
+ a: T,
72
+ ...b: ArithmeticValue[]
73
+ ): T;
74
+
75
+ /**
76
+ * Divides values sequentially.
77
+ *
78
+ * @example
79
+ * div(20, 2, 5) // 2
80
+ */
81
+ export declare function div<T extends ArithmeticValue>(
82
+ a: T,
83
+ ...b: ArithmeticValue[]
84
+ ): T;
85
+
86
+ /**
87
+ * Calculates modulo sequentially.
88
+ *
89
+ * @example
90
+ * modulo(20, 6) // 2
91
+ */
92
+ export declare function modulo<T extends ArithmeticValue>(
93
+ a: T,
94
+ ...b: ArithmeticValue[]
95
+ ): T;
@@ -0,0 +1,101 @@
1
+ /**
2
+ * Converts a value from one numerical base to another.
3
+ *
4
+ * Supported bases are between 2 and 36.
5
+ *
6
+ * @param value Value to convert.
7
+ * @param fromBase Source base.
8
+ * @param toBase Target base.
9
+ *
10
+ * @example
11
+ * base2base("1010", 2, 10) // "10"
12
+ */
13
+ export declare function base2base(
14
+ value: string | number,
15
+ fromBase: number,
16
+ toBase: number
17
+ ): string;
18
+
19
+ /**
20
+ * Converts binary values to octal.
21
+ */
22
+ export declare function bin2oct(
23
+ ...x: (string | number)[]
24
+ ): string[];
25
+
26
+ /**
27
+ * Converts binary values to decimal.
28
+ */
29
+ export declare function bin2dec(
30
+ ...x: (string | number)[]
31
+ ): string[];
32
+
33
+ /**
34
+ * Converts binary values to hexadecimal.
35
+ */
36
+ export declare function bin2hex(
37
+ ...x: (string | number)[]
38
+ ): string[];
39
+
40
+ /**
41
+ * Converts octal values to binary.
42
+ */
43
+ export declare function oct2bin(
44
+ ...x: (string | number)[]
45
+ ): string[];
46
+
47
+ /**
48
+ * Converts octal values to decimal.
49
+ */
50
+ export declare function oct2dec(
51
+ ...x: (string | number)[]
52
+ ): string[];
53
+
54
+ /**
55
+ * Converts octal values to hexadecimal.
56
+ */
57
+ export declare function oct2hex(
58
+ ...x: (string | number)[]
59
+ ): string[];
60
+
61
+ /**
62
+ * Converts decimal values to binary.
63
+ */
64
+ export declare function dec2bin(
65
+ ...x: (string | number)[]
66
+ ): string[];
67
+
68
+ /**
69
+ * Converts decimal values to octal.
70
+ */
71
+ export declare function dec2oct(
72
+ ...x: (string | number)[]
73
+ ): string[];
74
+
75
+ /**
76
+ * Converts decimal values to hexadecimal.
77
+ */
78
+ export declare function dec2hex(
79
+ ...x: (string | number)[]
80
+ ): string[];
81
+
82
+ /**
83
+ * Converts hexadecimal values to binary.
84
+ */
85
+ export declare function hex2bin(
86
+ ...x: (string | number)[]
87
+ ): string[];
88
+
89
+ /**
90
+ * Converts hexadecimal values to octal.
91
+ */
92
+ export declare function hex2oct(
93
+ ...x: (string | number)[]
94
+ ): string[];
95
+
96
+ /**
97
+ * Converts hexadecimal values to decimal.
98
+ */
99
+ export declare function hex2dec(
100
+ ...x: (string | number)[]
101
+ ): string[];