ziko 0.37.0 → 0.38.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 (130) hide show
  1. package/dist/ziko.cjs +1722 -3956
  2. package/dist/ziko.js +6150 -8384
  3. package/dist/ziko.min.js +2 -2
  4. package/dist/ziko.mjs +1713 -3840
  5. package/package.json +16 -13
  6. package/readme.md +79 -5
  7. package/src/__helpers__/composition-dep/compose-class.js +46 -0
  8. package/src/__helpers__/register/index.js +6 -0
  9. package/src/__helpers__/register/register-to-class.js +16 -0
  10. package/src/__helpers__/register/register-to-instance.js +18 -0
  11. package/src/__ziko__/__cache__.js +6 -0
  12. package/src/__ziko__/__config__.js +19 -0
  13. package/src/__ziko__/__hydration__.js +8 -0
  14. package/src/__ziko__/__ui__.js +22 -0
  15. package/src/__ziko__/index.js +17 -0
  16. package/src/__ziko__/params.js +40 -0
  17. package/src/app/globals.js +14 -0
  18. package/src/app/index.js +4 -4
  19. package/src/app/spa-file-based-routing.js +2 -2
  20. package/src/app/ziko-app.js +1 -1
  21. package/src/data/converter/svg.js +2 -2
  22. package/src/hooks/index.js +3 -0
  23. package/src/hooks/use-derived.js +61 -0
  24. package/src/hooks/use-reactive.js +7 -0
  25. package/src/hooks/use-state.js +52 -0
  26. package/src/index.js +1 -78
  27. package/src/math/complex/index.js +3 -0
  28. package/src/math/functions/index.js +23 -23
  29. package/src/math/functions/proxy.js +58 -0
  30. package/src/math/utils/mapfun.js +17 -21
  31. package/src/no-module.js +32 -0
  32. package/src/time/{animation.js → animation/index.js} +2 -2
  33. package/src/time/decorators/index.js +17 -0
  34. package/src/time/index.js +11 -12
  35. package/src/time/utils/index.js +0 -1
  36. package/src/ui/{methods → __methods__}/dom.js +15 -14
  37. package/src/ui/__methods__/index.js +4 -0
  38. package/src/ui/{utils → __utils__}/index.js +1 -1
  39. package/src/ui/constructors/{ziko-ui-element.js → ZikoUIElement.js} +17 -117
  40. package/src/ui/constructors/ZikoUIElementMethodesToBeMoved-dep.js +96 -0
  41. package/src/ui/{style → constructors/style}/index.js +3 -3
  42. package/src/ui/{elements/flex → flex}/index.js +1 -1
  43. package/src/{graphics/canvas/index.js → ui/graphics/canvas.js} +4 -5
  44. package/src/ui/graphics/index.js +2 -0
  45. package/src/{graphics/svg/index.js → ui/graphics/svg.js} +1 -1
  46. package/src/ui/{elements/grid → grid}/index.js +1 -1
  47. package/src/ui/index.js +9 -40
  48. package/src/ui/{elements/misc/suspense.js → suspense/index.js} +1 -15
  49. package/src/ui/tags/index.js +27 -17
  50. package/src/ui/text/index.js +15 -0
  51. package/src/ui/{elements/misc/xml-wrapper.js → wrapper/index.js} +1 -1
  52. package/src/use/index.js +3 -7
  53. package/src/__helpers__/composition/compose-class.js +0 -28
  54. package/src/graphics/canvas/_canvas_offscreen +0 -0
  55. package/src/graphics/canvas/utils/color.js +0 -8
  56. package/src/graphics/canvas/utils/floodFill.js +0 -57
  57. package/src/graphics/index.js +0 -10
  58. package/src/time/utils/decorators.js +0 -17
  59. package/src/ui/elements/embaded/html.js +0 -20
  60. package/src/ui/elements/embaded/index.js +0 -3
  61. package/src/ui/elements/embaded/pdf.js +0 -17
  62. package/src/ui/elements/embaded/youtube.js +0 -24
  63. package/src/ui/elements/hydrate.js +0 -0
  64. package/src/ui/elements/index.js +0 -10
  65. package/src/ui/elements/io/Form/index.js +0 -42
  66. package/src/ui/elements/io/Form/index.js.txt +0 -104
  67. package/src/ui/elements/io/Inputs/__helpers__.js +0 -52
  68. package/src/ui/elements/io/Inputs/index.js +0 -12
  69. package/src/ui/elements/io/Inputs/input/index.js +0 -99
  70. package/src/ui/elements/io/Inputs/input-camera/index.js +0 -26
  71. package/src/ui/elements/io/Inputs/input-checkbox/index.js +0 -26
  72. package/src/ui/elements/io/Inputs/input-color/index.js +0 -16
  73. package/src/ui/elements/io/Inputs/input-date-time/index.js +0 -3
  74. package/src/ui/elements/io/Inputs/input-date-time/input-date-time.js +0 -14
  75. package/src/ui/elements/io/Inputs/input-date-time/input-date.js +0 -14
  76. package/src/ui/elements/io/Inputs/input-date-time/input-time.js +0 -14
  77. package/src/ui/elements/io/Inputs/input-email-password/index.js +0 -2
  78. package/src/ui/elements/io/Inputs/input-email-password/input-email.js +0 -15
  79. package/src/ui/elements/io/Inputs/input-email-password/input-password.js +0 -14
  80. package/src/ui/elements/io/Inputs/input-file/index.js +0 -1
  81. package/src/ui/elements/io/Inputs/input-file/input-file.js +0 -0
  82. package/src/ui/elements/io/Inputs/input-file/input-image.js +0 -43
  83. package/src/ui/elements/io/Inputs/input-number/index.js +0 -37
  84. package/src/ui/elements/io/Inputs/input-radio/index.js +0 -26
  85. package/src/ui/elements/io/Inputs/input-search/index.js +0 -45
  86. package/src/ui/elements/io/Inputs/input-slider/index.js +0 -34
  87. package/src/ui/elements/io/Select/index.js +0 -20
  88. package/src/ui/elements/io/Textarea/index.js +0 -18
  89. package/src/ui/elements/io/index.js +0 -4
  90. package/src/ui/elements/list/elements.js +0 -0
  91. package/src/ui/elements/list/index.js +0 -138
  92. package/src/ui/elements/media/Audio/index.js +0 -17
  93. package/src/ui/elements/media/Image/figure.js +0 -19
  94. package/src/ui/elements/media/Image/image.js +0 -37
  95. package/src/ui/elements/media/Image/index.js +0 -2
  96. package/src/ui/elements/media/Video/index.js +0 -27
  97. package/src/ui/elements/media/__ZikoUIDynamicMediaELement__.js +0 -47
  98. package/src/ui/elements/media/index.js +0 -3
  99. package/src/ui/elements/misc/hyperscript.js +0 -144
  100. package/src/ui/elements/misc/index.js +0 -101
  101. package/src/ui/elements/semantic/index.js +0 -42
  102. package/src/ui/elements/table/elements.js +0 -94
  103. package/src/ui/elements/table/index.js +0 -3
  104. package/src/ui/elements/table/table.js +0 -115
  105. package/src/ui/elements/table/utils.js +0 -12
  106. package/src/ui/elements/text/__ZikoUIText__.js +0 -70
  107. package/src/ui/elements/text/heading.js +0 -36
  108. package/src/ui/elements/text/index.js +0 -3
  109. package/src/ui/elements/text/p.js +0 -26
  110. package/src/ui/elements/text/pre.js +0 -0
  111. package/src/ui/elements/text/text.js +0 -81
  112. package/src/use/use-debounce.js +0 -4
  113. package/src/use/use-state.js +0 -22
  114. package/src/use/use-throttle.js +0 -9
  115. /package/src/__helpers__/{composition → composition-dep}/compose-instance.js +0 -0
  116. /package/src/__helpers__/{composition → composition-dep}/compose.js +0 -0
  117. /package/src/__helpers__/{composition → composition-dep}/index.js +0 -0
  118. /package/src/reactivity/hooks/{Head → head}/_useCssText.js +0 -0
  119. /package/src/reactivity/hooks/{Head → head}/index.js +0 -0
  120. /package/src/reactivity/hooks/{Head → head}/useFavIcon.js +0 -0
  121. /package/src/reactivity/hooks/{Head → head}/useHead.js +0 -0
  122. /package/src/reactivity/hooks/{Head → head}/useMeta.js +0 -0
  123. /package/src/reactivity/hooks/{Head → head}/useTitle.js +0 -0
  124. /package/src/time/{loop.js → loop/index.js} +0 -0
  125. /package/src/ui/{methods → __methods__}/events.js +0 -0
  126. /package/src/ui/{methods → __methods__}/indexing.js +0 -0
  127. /package/src/ui/{methods → __methods__}/observer.js +0 -0
  128. /package/src/ui/{methods → __methods__}/style.js +0 -0
  129. /package/src/ui/constructors/{ziko-ui-node.js → ZikoUINode.js} +0 -0
  130. /package/src/ui/tags/{tags.js → tags-list.js} +0 -0
package/src/index.js CHANGED
@@ -1,94 +1,17 @@
1
- import { __ExtractAll__,__RemoveAll__ } from "./__helpers__/index.js";
2
- import Math from "./math/index.js";
3
- import UI from "./ui/index.js";
4
- import Time from "./time/index.js";
5
- import Data from "./data/index.js";
6
- import Reactivity from "./reactivity/index.js";
7
- import Graphics from "./graphics/index.js";
8
-
9
- // import * as Events from "./events/index.js"
10
- // import * as Use from "./use/index.js"
11
-
12
- import App,{__UI__,__HYDRATION_MAP__, __Config__, __CACHE__, defineParamsGetter, __HYDRATION__} from "./app";
13
-
14
1
  export * from "./math/index.js";
15
2
  export * from "./ui/index.js";
16
3
  export * from "./time/index.js";
17
4
  export * from "./data/index.js";
18
5
  export * from "./reactivity/index.js"
19
- export * from "./graphics/index.js";
20
6
  export * from "./app/index.js";
21
7
 
22
8
  export * from "./events/index.js";
23
9
  export * from "./use/index.js";
24
10
 
25
- [
26
- App,
27
- Math,
28
- UI,
29
- Time,
30
- Data,
31
- Reactivity,
32
- Graphics,
33
- ].forEach(n=>Object.assign(n,{
34
- ExtractAll:()=>__ExtractAll__(n),
35
- RemoveAll:()=>__RemoveAll__(n)
36
- }))
37
-
38
- const Ziko={
39
- App,
40
- Math,
41
- UI,
42
- Time,
43
- Data,
44
- Reactivity,
45
- Graphics
46
- }
47
-
48
- if ( globalThis.__Ziko__ ) {
49
- console.warn( 'WARNING: Multiple instances of Ziko.js being imported.' );
50
- } else {
51
- globalThis.__Ziko__={
52
- ...Ziko,
53
- __UI__,
54
- __HYDRATION__,
55
- __HYDRATION_MAP__,
56
- __Config__,
57
- __CACHE__,
58
- ExtractAll,
59
- RemoveAll
60
- };
61
- defineParamsGetter(__Ziko__)
62
- }
63
- // globalThis.__Ziko__={
64
- // ...Ziko,
65
- // __UI__,
66
- // __Config__,
67
- // ExtractAll,
68
- // RemoveAll
69
- // };
70
11
  if(globalThis?.document){
71
12
  document?.addEventListener("DOMContentLoaded", __Ziko__.__Config__.init());
72
13
  }
73
- function ExtractAll(){
74
- UI.ExtractAll();
75
- Math.ExtractAll();
76
- Time.ExtractAll();
77
- Reactivity.ExtractAll();
78
- Graphics.ExtractAll();
79
- Data.ExtractAll()
80
- return this;
81
- }
82
- function RemoveAll(){
83
- UI.RemoveAll();
84
- Math.RemoveAll();
85
- Time.RemoveAll();
86
- Reactivity.RemoveAll();
87
- Graphics.RemoveAll();
88
- Data.RemoveAll()
89
- }
90
-
91
- export default Ziko;
92
14
 
15
+ import './math/functions/proxy.js'
93
16
 
94
17
 
@@ -53,6 +53,9 @@ class Complex extends ZikoMath{
53
53
  this.b = +b.toFixed(32);
54
54
  }
55
55
  }
56
+ isComplex(){
57
+ return true
58
+ }
56
59
  toString(){
57
60
  let str = "";
58
61
  if (this.a !== 0)
@@ -58,29 +58,29 @@ const sqrtn=(x,n)=>{
58
58
  }
59
59
  }
60
60
  }
61
- const e=(...x)=>mapfun(Math.exp,...x);
62
- const ln=(...x)=>mapfun(Math.log,...x);
63
- const cos=(...x)=>mapfun(Fixed.cos,...x);
64
- const sin=(...x)=>mapfun(Fixed.sin,...x);
65
- const tan=(...x)=>mapfun(Fixed.tan,...x);
66
- const sec=(...x)=>mapfun(Fixed.sec,...x);
67
- const sinc=(...x)=>mapfun(Fixed.sinc,...x)
68
- const csc=(...x)=>mapfun(Fixed.csc,...x);
69
- const cot=(...x)=>mapfun(Fixed.cot,...x);
70
- const acos=(...x)=>mapfun(Fixed.acos,...x);
71
- const asin=(...x)=>mapfun(Fixed.asin,...x);
72
- const atan=(...x)=>mapfun(Fixed.atan,...x);
73
- const acot=(...x)=>mapfun(Fixed.acot,...x);
74
- const cosh=(...x)=>mapfun(Fixed.cosh,...x);
75
- const sinh=(...x)=>mapfun(Fixed.sinh,...x);
76
- const tanh=(...x)=>mapfun(Fixed.tanh,...x);
77
- const coth=(...x)=>mapfun(Fixed.coth,...x);
78
- const acosh=(...x)=>mapfun(Fixed.acosh,...x);
79
- const asinh=(...x)=>mapfun(Fixed.asinh,...x);
80
- const atanh=(...x)=>mapfun(Fixed.atanh,...x);
81
- const ceil=(...x)=>mapfun(Math.ceil,...x);
82
- const floor=(...x)=>mapfun(Math.floor,...x);
83
- const round=(...x)=>mapfun(Math.round,...x);
61
+ const e=(...x) => mapfun(Math.exp,...x);
62
+ const ln=(...x) => mapfun(Math.log,...x);
63
+ const cos=(...x) => mapfun(Fixed.cos,...x);
64
+ const sin=(...x) => mapfun(Fixed.sin,...x);
65
+ const tan=(...x) => mapfun(Fixed.tan,...x);
66
+ const sec=(...x) => mapfun(Fixed.sec,...x);
67
+ const sinc=(...x) => mapfun(Fixed.sinc,...x)
68
+ const csc=(...x) => mapfun(Fixed.csc,...x);
69
+ const cot=(...x) => mapfun(Fixed.cot,...x);
70
+ const acos=(...x) => mapfun(Fixed.acos,...x);
71
+ const asin=(...x) => mapfun(Fixed.asin,...x);
72
+ const atan=(...x) => mapfun(Fixed.atan,...x);
73
+ const acot=(...x) => mapfun(Fixed.acot,...x);
74
+ const cosh=(...x) => mapfun(Fixed.cosh,...x);
75
+ const sinh=(...x) => mapfun(Fixed.sinh,...x);
76
+ const tanh=(...x) => mapfun(Fixed.tanh,...x);
77
+ const coth=(...x) => mapfun(Fixed.coth,...x);
78
+ const acosh=(...x) => mapfun(Fixed.acosh,...x);
79
+ const asinh=(...x) => mapfun(Fixed.asinh,...x);
80
+ const atanh=(...x) => mapfun(Fixed.atanh,...x);
81
+ const ceil=(...x) => mapfun(Math.ceil,...x);
82
+ const floor=(...x) => mapfun(Math.floor,...x);
83
+ const round=(...x) => mapfun(Math.round,...x);
84
84
  const atan2=(x,y,rad=true)=>{
85
85
  if(typeof x === "number"){
86
86
  if(typeof y === "number")return rad?Math.atan2(x,y):Math.atan2(x,y)*180/Math.PI;
@@ -0,0 +1,58 @@
1
+ let {abs, sqrt, cos, sin, tan, exp, log, cosh, sinh, tanh} = Math;
2
+ // Math.abs = new Proxy(Math.abs, {
3
+ // apply(target, thisArg, args) {
4
+ // const x = args[0]
5
+ // if(typeof x === 'number') return target.apply(thisArg, args);
6
+ // if(x?.isComplex?.()){
7
+ // const {a, b, z, phi} = x
8
+ // const complex = (a, b) => new x.constructor(a, b)
9
+ // switch(target.name){
10
+ // case 'abs' : return a.z;
11
+ // case 'sqrt' : return complex(sqrt(z)*cos(phi/2),sqrt(z)*sin(phi/2));
12
+ // }
13
+ // }
14
+
15
+ // }
16
+ // });
17
+
18
+
19
+ for (const key of Object.getOwnPropertyNames(Math)) {
20
+ const fn = Math[key];
21
+ if (typeof fn === "function") {
22
+ Math[key] = new Proxy(fn, {
23
+ apply(target, thisArg, args) {
24
+ // console.log(target)
25
+ const x = args[0]
26
+ if(typeof x === 'number' || args.length === 0) return target.apply(thisArg, args);
27
+ if(x?.isComplex?.()){
28
+ const {a, b, z, phi} = x
29
+ const complex = (a, b) => new x.constructor(a, b);
30
+ switch(target.name){
31
+ case 'abs' : return x.z;
32
+ case 'sqrt' : return complex(sqrt(z)*cos(phi/2),sqrt(z)*sin(phi/2));
33
+ case 'log' : return complex(log(z), phi);
34
+ case 'exp' : return complex(exp(a)*cos(b),exp(a)*sin(b));
35
+ case 'cos' : return complex(cos(a)*cosh(b),-(sin(a)*sinh(b)));
36
+ case 'sin' : return complex(sin(a)*cosh(b),cos(a)*sinh(b));
37
+ case 'tan' : {
38
+ const DEN = cos(2*a)+cosh(2*b);
39
+ return complex(sin(2*a) /DEN, sinh(2*b)/DEN);
40
+ }
41
+ case 'cosh' : return complex(cosh(a)*cos(b),sinh(a)*sin(b));
42
+ case 'sinh' : return complex(sinh(a)*cos(b),cosh(a)*sin(b));
43
+ case 'tanh' : {
44
+ const DEN=cosh(2*a)+cos(2*b);
45
+ return complex(sinh(2*a)/DEN,sin(2*b)/DEN)
46
+ }
47
+ default : return target.apply(thisArg, args)
48
+ }
49
+ }
50
+ // if( x.isMatrix?.()){
51
+ // const {rows, cols, arr} = x
52
+ // // return new x.constructor(rows, cols, arr.flat(1).map(n=>));
53
+ // }
54
+ throw new TypeError(`Math.${key} expects only numbers`);
55
+ }
56
+ });
57
+ }
58
+ }
@@ -1,36 +1,31 @@
1
- /** @module Math */
2
1
  import { Matrix } from "../matrix/index.js";
3
2
  import { Complex , complex } from "../complex/index.js";
4
3
  import {ln,e,cos,sin,sqrt,cosh,sinh} from "../functions/index.js";
5
4
  import { Fixed } from "../functions/helper.js";
6
- /**
7
- * map a function to ...X
8
- * @param {function} fun
9
- * @param {...any} X
10
- * @returns {any|any[]}
11
- */
5
+ // To generalise
6
+
12
7
  const mapfun=(fun,...X)=>{
13
8
  const Y=X.map(x=>{
14
- if(x===null)return fun(null);
15
- if(["number","string","boolean","bigint","undefined"].includes(typeof x))return fun(x);
16
- if(x instanceof Array)return x.map(n=>mapfun(fun,n));
17
- if(ArrayBuffer.isView(x))return x.map(n=>fun(n));
18
- if(x instanceof Set)return new Set(mapfun(fun,...[...x]));
19
- if(x instanceof Map)return new Map([...x].map(n=>[n[0],mapfun(fun,n[1])]));
9
+ if(x===null) return fun(null);
10
+ if(["number","string","boolean","bigint","undefined"].includes(typeof x)) return fun(x);
11
+ if(x instanceof Array) return x.map(n=>mapfun(fun,n));
12
+ if(ArrayBuffer.isView(x)) return x.map(n=>fun(n));
13
+ if(x instanceof Set) return new Set(mapfun(fun,...[...x]));
14
+ if(x instanceof Map) return new Map([...x].map(n=>[n[0],mapfun(fun,n[1])]));
20
15
  if(x instanceof Matrix){
21
- return new Matrix(x.rows,x.cols,mapfun(x.arr.flat(1)))
16
+ return new Matrix(x.rows,x.cols, mapfun(x.arr.flat(1)))
22
17
  }
23
18
  if(x instanceof Complex){
24
19
  const [a,b,z,phi]=[x.a,x.b,x.z,x.phi];
25
20
  switch(fun){
26
- case Math.log:return complex(ln(z),phi); // Done
27
- case Math.exp:return complex(e(a)*cos(b),e(a)*sin(b)); // Done
28
- case Math.abs:return z; // Done
29
- case Math.sqrt:return complex(sqrt(z)*cos(phi/2),sqrt(z)*sin(phi/2)); // Done
30
- case Fixed.cos:return complex(cos(a)*cosh(b),-(sin(a)*sinh(b)));
31
- case Fixed.sin:return complex(sin(a)*cosh(b),cos(a)*sinh(b));
21
+ case Math.log: return complex(ln(z),phi); // Done
22
+ case Math.exp: return complex(e(a)*cos(b),e(a)*sin(b)); // Done
23
+ case Math.abs: return z; // Done
24
+ case Math.sqrt: return complex(sqrt(z)*cos(phi/2),sqrt(z)*sin(phi/2)); // Done
25
+ case Fixed.cos: return complex(cos(a)*cosh(b),-(sin(a)*sinh(b)));
26
+ case Fixed.sin: return complex(sin(a)*cosh(b),cos(a)*sinh(b));
32
27
  case Fixed.tan:{
33
- const DEN=cos(2*a)+cosh(2*b);
28
+ const DEN = cos(2*a)+cosh(2*b);
34
29
  return complex(sin(2*a)/DEN,sinh(2*b)/DEN);
35
30
  }
36
31
  case Fixed.cosh:return complex(cosh(a)*cos(b),sinh(a)*sin(b));
@@ -43,6 +38,7 @@ const mapfun=(fun,...X)=>{
43
38
  }
44
39
  }
45
40
  else if(x instanceof Object){
41
+ return Object.fromEntries(Object.entries(x).map(n=>n=[n[0],mapfun(fun,n[1])]))
46
42
  return fun(Object) || Object.fromEntries(Object.entries(x).map(n=>n=[n[0],mapfun(fun,n[1])]))
47
43
  }
48
44
  });
@@ -0,0 +1,32 @@
1
+ // import { __ExtractAll__,__RemoveAll__ } from "./__helpers__/index.js";
2
+
3
+ // [
4
+ // App,
5
+ // Math,
6
+ // UI,
7
+ // Time,
8
+ // Data,
9
+ // Reactivity,
10
+ // Graphics,
11
+ // ].forEach(n=>Object.assign(n,{
12
+ // ExtractAll:()=>__ExtractAll__(n),
13
+ // RemoveAll:()=>__RemoveAll__(n)
14
+ // }))
15
+
16
+ // function ExtractAll(){
17
+ // UI.ExtractAll();
18
+ // Math.ExtractAll();
19
+ // Time.ExtractAll();
20
+ // Reactivity.ExtractAll();
21
+ // Graphics.ExtractAll();
22
+ // Data.ExtractAll()
23
+ // return this;
24
+ // }
25
+ // function RemoveAll(){
26
+ // UI.RemoveAll();
27
+ // Math.RemoveAll();
28
+ // Time.RemoveAll();
29
+ // Reactivity.RemoveAll();
30
+ // Graphics.RemoveAll();
31
+ // Data.RemoveAll()
32
+ // }
@@ -1,5 +1,5 @@
1
- import { Ease } from "./utils";
2
- import { map } from "../math/utils"
1
+ import { Ease } from "../utils";
2
+ import { map } from "../../math/utils"
3
3
  class ZikoTimeAnimation{
4
4
  constructor(callback,ease=Ease.Linear,step=50,{t=[0,null],start=true,duration=3000}={}){
5
5
  this.cache={
@@ -0,0 +1,17 @@
1
+ const debounce=(fn,delay=1000)=>{
2
+ let id;
3
+ return(...args) => id ? clearTimeout(id) : setTimeout(()=>fn(...args),delay);
4
+ }
5
+ const throttle=(fn,delay)=>{
6
+ let lastTime=0;
7
+ return (...args) => {
8
+ const now = new Date().getTime()
9
+ if(now-lastTime < delay) return;
10
+ lastTime = now;
11
+ fn(...args);
12
+ }
13
+ }
14
+ export{
15
+ debounce,
16
+ throttle
17
+ }
package/src/time/index.js CHANGED
@@ -1,12 +1,11 @@
1
- export * from "./loop.js"
2
- export * from "./animation.js"
3
- export * from "./utils";
4
- import * as Loop from "./loop.js";
5
- import * as Animation from "./loop.js";
6
- import * as Utils from "./utils"
7
- const Time = {
8
- ...Loop,
9
- ...Animation,
10
- ...Utils
11
- }
12
- export default Time
1
+ export * from './loop/index.js'
2
+ export * from './animation/index.js'
3
+ export * from './utils/index.js';
4
+ export * from './decorators/index.js';
5
+ // import * as Utils from './utils'
6
+ // const Time = {
7
+ // ...Loop,
8
+ // ...Animation,
9
+ // ...Utils
10
+ // }
11
+ // export default Time
@@ -13,6 +13,5 @@ export{
13
13
  timeTaken,
14
14
  Ease
15
15
  }
16
- export * from "./decorators.js";
17
16
  export * from "./performance.js";
18
17
  export * from "./ui.js"
@@ -1,4 +1,4 @@
1
- import { text } from "../elements/text/text.js";
1
+ import { text } from "../text/index.js";
2
2
  export const DomMethods = {
3
3
  append(...ele) {
4
4
  __addItem__.call(this, "append", "push", ...ele);
@@ -75,24 +75,25 @@ function __addItem__(adder, pusher, ...ele) {
75
75
  }
76
76
  for (let i = 0; i < ele.length; i++) {
77
77
  if (["number", "string"].includes(typeof ele[i])) ele[i] = text(ele[i]);
78
- if (typeof globalThis?.Node === "function" && ele[i] instanceof globalThis?.Node) ele[i] = new this.constructor(ele[i]);
79
- if (ele[i]?.isZikoUIElement) {
80
- ele[i].cache.parent = this;
81
- this.element[adder](ele[i].element);
82
- ele[i].target = this.element;
83
- this.items[pusher](ele[i]);
84
- }
85
- // Fix Items Latter
86
- if( ele[i] instanceof Function){
87
- const getter = ele[i]();
78
+ // Fix Items Latter
79
+ if (ele[i] instanceof Function) {
80
+ const getter = ele[i]();
88
81
  if (getter.isStateGetter) {
89
- const textNode = document?.createTextNode(getter.value);
90
- this.element.appendChild(textNode);
82
+ ele[i] = text(getter.value);
91
83
  getter._subscribe(
92
- (newValue) => (textNode.textContent = newValue),
84
+ (newValue) => (ele[i].element.textContent = newValue),
85
+ ele[i]
93
86
  );
87
+ // this.element.appendChild(textNode);
94
88
  }
95
89
  }
90
+ if (typeof globalThis?.Node === "function" && ele[i] instanceof globalThis?.Node) ele[i] = new this.constructor(ele[i]);
91
+ if (ele[i]?.isZikoUINode) {
92
+ ele[i].cache.parent = this;
93
+ this.element?.[adder](ele[i].element);
94
+ ele[i].target = this.element;
95
+ this.items[pusher](ele[i]);
96
+ }
96
97
  else if (ele[i] instanceof Object) {
97
98
  if (ele[i]?.style) this.style(ele[i]?.style);
98
99
  if (ele[i]?.attr) {
@@ -0,0 +1,4 @@
1
+ export * from './dom.js'
2
+ export * from './events.js'
3
+ export * from './indexing.js'
4
+ // export * from './style.js'
@@ -1,4 +1,4 @@
1
- import ZikoUIElement from "../constructors/ziko-ui-element.js";
1
+ import ZikoUIElement from "../constructors/ZikoUIElement.js";
2
2
  const Id = (a) => document.getElementById(a);
3
3
  const Class = (a) => [...document.getElementsByClassName(a)];
4
4
  const $=(...selector)=>{
@@ -1,10 +1,13 @@
1
- import ZikoUINode from "./ziko-ui-node.js";
2
- import { compose } from "../../__helpers__/index.js";
3
- import { DomMethods } from "../methods/dom.js";
4
- import { IndexingMethods } from "../methods/indexing.js";
5
- import { EventsMethodes } from "../methods/events.js";
1
+ import ZikoUINode from "./ZikoUINode.js";
2
+ import { register } from "../../__helpers__/register/index.js";
3
+ import {
4
+ DomMethods,
5
+ IndexingMethods,
6
+ EventsMethodes
7
+ } from "../__methods__/index.js";
6
8
  import { ZikoUseStyle } from "../../reactivity/hooks/UI/useStyle.js";
7
- import { ZikoUIElementStyle } from "../style/index.js";
9
+ import { ZikoUIElementStyle } from "./style/index.js";
10
+
8
11
  import {
9
12
  useCustomEvent,
10
13
  useSwipeEvent,
@@ -15,12 +18,14 @@ import {
15
18
  } from "../../reactivity/index.js"
16
19
  import { Random } from "../../math/index.js";
17
20
  import { Str } from "../../data/index.js";
21
+ import {__init__global__} from '../../__ziko__/index.js';
22
+ __init__global__()
18
23
  class ZikoUIElement extends ZikoUINode{
19
- constructor(element, name="", {el_type="html", useDefaultStyle=false}={}){
24
+ constructor(element, name="", {type="html", useDefaultStyle=false}={}){
20
25
  super()
21
26
  this.target = globalThis.__Ziko__.__Config__.default.target||globalThis?.document?.body;
22
27
  if(typeof element === "string") {
23
- switch(el_type){
28
+ switch(type){
24
29
  case "html" : element = globalThis?.document?.createElement(element); break;
25
30
  case "svg" : element = globalThis?.document?.createElementNS("http://www.w3.org/2000/svg", element);
26
31
  default : throw Error("Not supported")
@@ -29,18 +34,7 @@ class ZikoUIElement extends ZikoUINode{
29
34
  else{
30
35
  this.target = element.parentElement;
31
36
  }
32
- // if(element)this.__ele__ = element;
33
- compose(
34
- this,
35
- DomMethods,
36
- IndexingMethods,
37
- EventsMethodes
38
- )
39
- // if(false){
40
- // import("../methods/tree.js").then(({ default: ExternalMethods }) => {
41
- // compose(this, ExternalMethods);
42
- // });
43
- // }
37
+ register(this, DomMethods, IndexingMethods, EventsMethodes);
44
38
  Object.assign(this.cache, {
45
39
  name,
46
40
  isInteractive : [true, false][Math.floor(2*Math.random())],
@@ -105,14 +99,9 @@ class ZikoUIElement extends ZikoUINode{
105
99
  isInteractive(){
106
100
  return this.cache.isInteractive;
107
101
  }
108
- // Remove get
109
102
  isZikoUIElement(){
110
103
  return true;
111
104
  }
112
- register(){
113
-
114
- return this;
115
- }
116
105
  get st(){
117
106
  return this.cache.style;
118
107
  }
@@ -183,82 +172,6 @@ class ZikoUIElement extends ZikoUINode{
183
172
  });
184
173
  }
185
174
  }
186
- filter(condition_callback, if_callback = () => {}, else_callback = () => {}) {
187
- const FilterItems = this.items.filter(condition_callback);
188
- FilterItems.forEach(if_callback);
189
- this.items
190
- .filter((item) => !FilterItems.includes(item))
191
- .forEach(else_callback);
192
- return this;
193
- }
194
- filterByTextContent(text, exactMatch = false) {
195
- this.items.forEach((n) => n.render());
196
- this.filter(
197
- (n) => !(exactMatch ? n.text === text : n.text.includes(text)),
198
- (e) => e.unrender(),
199
- );
200
- // this.items.filter(n=>{
201
- // const content=n.element.textContent;
202
- // return !(exactMatch?content===text:content.includes(text))
203
- // }).map(n=>n.unrender());
204
- // return this;
205
- }
206
- filterByClass(value) {
207
- this.items.map((n) => n.render());
208
- this.items
209
- .filter((n) => !n.classes.includes(value))
210
- .map((n) => n.unrender());
211
- return this;
212
- }
213
- sortByTextContent(value, displays) {
214
- let item = this.children;
215
- item
216
- .filter((n) => !n.textContent.toLowerCase().includes(value.toLowerCase()))
217
- .map((n) => {
218
- n.style.display = "none";
219
- });
220
- item
221
- .filter((n) => n.textContent.toLowerCase().includes(value.toLowerCase()))
222
- .map((n, i) => (n.style.display = displays[i]));
223
- //return item.filter(n=>n.style.display!="none")
224
- item.filter((n) => n.style.display != "none");
225
- return this;
226
- }
227
- get #SwitchedStyleRTL_LTR(){
228
- const CalculedStyle = globalThis.getComputedStyle(this.element);
229
- const SwitchedStyle = {}
230
- if(CalculedStyle.marginRight!=="0px")Object.assign(SwitchedStyle, {marginLeft: CalculedStyle.marginRight});
231
- if(CalculedStyle.marginLeft!=="0px")Object.assign(SwitchedStyle, {marginRight: CalculedStyle.marginLeft});
232
- if(CalculedStyle.paddingRight!=="0px")Object.assign(SwitchedStyle, {paddingLeft: CalculedStyle.paddingRight});
233
- if(CalculedStyle.paddingLeft!=="0px")Object.assign(SwitchedStyle, {paddingRight: CalculedStyle.paddingLeft});
234
- if(CalculedStyle.left!=="0px")Object.assign(SwitchedStyle, {right: CalculedStyle.left});
235
- if(CalculedStyle.right!=="0px")Object.assign(SwitchedStyle, {left: CalculedStyle.right});
236
- if(CalculedStyle.textAlign === "right")Object.assign(SwitchedStyle, {textAlign: "left"});
237
- if(CalculedStyle.textAlign === "left")Object.assign(SwitchedStyle, {textAlign: "right"});
238
- if(CalculedStyle.float === "right")Object.assign(SwitchedStyle, {float: "left"});
239
- if(CalculedStyle.float === "left")Object.assign(SwitchedStyle, {float: "right"});
240
- if(CalculedStyle.borderRadiusLeft!=="0px")Object.assign(SwitchedStyle, {right: CalculedStyle.borderRadiusRight});
241
- if(CalculedStyle.borderRadiusRight!=="0px")Object.assign(SwitchedStyle, {right: CalculedStyle.borderRadiusLeft});
242
- if(["flex","inline-flex"].includes(CalculedStyle.display)){
243
- if(CalculedStyle.justifyContent === "flex-end")Object.assign(SwitchedStyle, {justifyContent: "flex-start"});
244
- if(CalculedStyle.justifyContent === "flex-start")Object.assign(SwitchedStyle, {justifyContent: "flex-end"});
245
- }
246
- return SwitchedStyle;
247
- }
248
- useRtl(switchAll = false){
249
- switchAll ? this.style({
250
- ...this.#SwitchedStyleRTL_LTR,
251
- direction : "rtl"
252
- }) : this.style({direction : "rtl"});
253
- return this;
254
- }
255
- useLtr(switchAll = false){
256
- switchAll ? this.style({
257
- ...this.#SwitchedStyleRTL_LTR,
258
- direction : "ltr"
259
- }) : this.style({direction : "ltr"});
260
- return this;
261
- }
262
175
  freeze(freeze){
263
176
  this.cache.isFrozzen=freeze;
264
177
  return this;
@@ -280,9 +193,9 @@ class ZikoUIElement extends ZikoUINode{
280
193
  }
281
194
  // Attributes
282
195
  #setAttr(name, value){
283
- if(this.element.tagName !== "svg") name = Str.isCamelCase(name) ? Str.camel2hyphencase(name) : name;
196
+ if(this.element?.tagName !== "svg") name = Str.isCamelCase(name) ? Str.camel2hyphencase(name) : name;
284
197
  if(this?.attr[name] && this?.attr[name]===value) return;
285
- this.element.setAttribute(name, value)
198
+ this.element?.setAttribute(name, value)
286
199
  Object.assign(this.cache.attributes, {[name]:value});
287
200
  }
288
201
  setAttr(name, value) {
@@ -380,19 +293,6 @@ class ZikoUIElement extends ZikoUINode{
380
293
  this.observer.intersection.start();
381
294
  return this;
382
295
  }
383
- // setFullScreen(set = true, e) {
384
- // if(!this.element.requestFullscreen){
385
- // console.error("Fullscreen API is not supported in this browser.");
386
- // return this;
387
- // }
388
- // if (set) this.element.requestFullscreen(e);
389
- // else globalThis.document.exitFullscreen();
390
- // return this;
391
- // }
392
- // toggleFullScreen(e) {
393
- // if (!globalThis.document.fullscreenElement) this.element.requestFullscreen(e);
394
- // else globalThis.document.exitFullscreen();
395
- // return this;
396
- // }
296
+
397
297
  }
398
298
  export default ZikoUIElement;