ziko 0.0.1 → 0.0.4

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,8 +1,7 @@
1
1
  {
2
2
  "name": "ziko",
3
- "version": "0.0.1",
3
+ "version": "0.0.4",
4
4
  "description": "a versatile JavaScript library offering a rich set of UI components, advanced mathematical utilities,Reactivity,animations,client side routing and graphics capabilities",
5
- "main": "src/index.js",
6
5
  "keywords": [
7
6
  "Zikojs",
8
7
  "Math",
@@ -17,6 +16,8 @@
17
16
  ],
18
17
  "type": "module",
19
18
  "source": "src/index.js",
19
+ "main": "dist/ziko.cjs",
20
+ "module": "dist/ziko.mjs",
20
21
  "files": [
21
22
  "src",
22
23
  "dist",
@@ -30,7 +31,9 @@
30
31
  },
31
32
  "scripts": {
32
33
  "test": "node --watch test/index.js",
34
+ "test-link":"node _link/index.js",
33
35
  "lint": "eslint src/*/*/*",
36
+ "dev": "rollup -c rollup.config.js -w",
34
37
  "build": "rollup -c rollup.config.js"
35
38
  },
36
39
  "repository": {
@@ -50,6 +53,8 @@
50
53
  "@rollup/plugin-terser": "^0.4.4",
51
54
  "dir2tree": "^0.3.2",
52
55
  "eslint": "^8.52.0",
53
- "rollup": "^4.1.5"
56
+ "rollup": "^4.1.5",
57
+ "rollup-plugin-livereload": "^2.0.5",
58
+ "rollup-plugin-serve": "^1.1.1"
54
59
  }
55
60
  }
@@ -1,3 +1,3 @@
1
1
  var __Target__=null;
2
- if(document.body)__Target__=document.body;
2
+ if(globalThis?.document?.body)__Target__=document.body;
3
3
  export { __Target__}
package/src/App/app.js CHANGED
@@ -1,5 +1,6 @@
1
1
  import { ZikoUIFlex } from "../UI/CustomElement/Flex.js";
2
2
  import { Seo } from "./Seo/index.js";
3
+ import { HashEvent } from "../Reactivity/index.js";
3
4
  class ZikoUIApp extends ZikoUIFlex{
4
5
  constructor(){
5
6
  super("main");
@@ -7,6 +8,9 @@ class ZikoUIApp extends ZikoUIFlex{
7
8
  this.head=null;
8
9
  this.#init();
9
10
  this.seo=Seo(this);
11
+ Object.assign(this.events,{
12
+ hash:null
13
+ })
10
14
  Object.assign(this.cache,{
11
15
  theme:null,
12
16
  isRoot:true
@@ -32,6 +36,11 @@ class ZikoUIApp extends ZikoUIFlex{
32
36
  description(){
33
37
 
34
38
  }
39
+ onHashChange(...callbacks){
40
+ if(!this.events.hash)this.events.hash = HashEvent(this);
41
+ this.events.hash.onChange(...callbacks);
42
+ return this;
43
+ }
35
44
  }
36
45
  const App=(...UIElement)=>new ZikoUIApp().append(...UIElement)
37
46
  export {App};
@@ -16,8 +16,8 @@ import svgGroupe from "./Elements/groupe.js";
16
16
  super();
17
17
  this.element=document.createElementNS("http://www.w3.org/2000/svg", "svg");
18
18
  //this.cache={};
19
- this.setAttribute("width",w);
20
- this.setAttribute("height",h);
19
+ this.setAttr("width",w);
20
+ this.setAttr("height",h);
21
21
  this.style({border:"1px black solid"});
22
22
  //this.view(-w/2,-h/2,w/2,h/2)
23
23
  //this.view(-10,-10,10,10);
@@ -27,7 +27,7 @@ import svgGroupe from "./Elements/groupe.js";
27
27
  let width=Math.abs(x2-x1);
28
28
  let height=Math.abs(y2-y1);
29
29
  //this.element.style.transform="scale("+Math.sign(x2-x1)+","+(-Math.sign(y2-y1))+")";
30
- this.element.setAttribute("viewBox",[x1,y1,width,height].join(" "));
30
+ this.setAttr("viewBox",[x1,y1,width,height].join(" "));
31
31
  //console.log({width:width,height:height})
32
32
  return this;
33
33
 
@@ -49,5 +49,5 @@ class ZikoCustomEvent extends ZikoEvent{
49
49
  return this;
50
50
  }
51
51
  }
52
- const CustomEvent=Target=>new ZikoCustomEvent(Target);
53
- export default CustomEvent;
52
+ const customEvent=Target=>new customEvent(Target);
53
+ export default customEvent;
@@ -0,0 +1,230 @@
1
+ import {ZikoEvent,EVENT_CONTROLLER} from "../ZikoEvent.js";
2
+ class ZikoEventMouse extends ZikoEvent{
3
+ constructor(target){
4
+ super(target);
5
+ this.event=null;
6
+ this.dx=0;
7
+ this.dy=0;
8
+ this.dt=0;
9
+ this.mx=0;
10
+ this.my=0;
11
+ this.mt=0;
12
+ this.ux=0;
13
+ this.uy=0;
14
+ this.ut=0;
15
+ this.swippe={
16
+ h:null,
17
+ v:null,
18
+ delta_x:0,
19
+ delta_y:0
20
+ }
21
+ this.isMoving=false;
22
+ this.isDown=false;
23
+ this.cache={
24
+ prefixe:"mouse",
25
+ preventDefault:{
26
+ down:false,
27
+ move:false,
28
+ up:false,
29
+ enter:false,
30
+ out:false,
31
+ leave:false,
32
+ over:false,
33
+ },
34
+ paused:{
35
+ down:false,
36
+ move:false,
37
+ up:false,
38
+ enter:false,
39
+ out:false,
40
+ leave:false,
41
+ over:false,
42
+ },
43
+ stream:{
44
+ enabled:{
45
+ down:false,
46
+ move:false,
47
+ up:false,
48
+ enter:false,
49
+ out:false,
50
+ leave:false,
51
+ over:false,
52
+ },
53
+ clear:{
54
+ down:false,
55
+ move:false,
56
+ up:false,
57
+ enter:false,
58
+ out:false,
59
+ leave:false,
60
+ over:false,
61
+ },
62
+ history:{
63
+ down:[],
64
+ move:[],
65
+ up:[],
66
+ enter:[],
67
+ out:[],
68
+ leave:[],
69
+ over:[]
70
+ }
71
+ },
72
+ callbacks:{
73
+ down:[(self)=>console.log({dx:self.dx,dy:self.dy,down:self.down,move:self.move,t:self.dt})],
74
+ move:[(self)=>console.log({mx:self.mx,my:self.my,down:self.down,move:self.move,t:self.dt})],
75
+ up:[(self)=>console.log({ux:self.ux,uy:self.uy,down:self.down,move:self.move,t:self.dt})],
76
+ enter:[(self)=>console.log({dx:self.dx,dy:self.dy,down:self.down,move:self.move,t:self.dt})],
77
+ out:[(self)=>console.log({mx:self.mx,my:self.my,down:self.down,move:self.move,t:self.dt})],
78
+ leave:[(self)=>console.log({ux:self.ux,uy:self.uy,down:self.down,move:self.move,t:self.dt})],
79
+ over:[(self)=>console.log({ux:self.ux,uy:self.uy,down:self.down,move:self.move,t:self.dt})]
80
+ }
81
+ }
82
+ this.__controller={
83
+ down:mousedown_controller.bind(this),
84
+ move:mousemove_controller.bind(this),
85
+ up:mouseup_controller.bind(this),
86
+ enter:mouseenter_controller.bind(this),
87
+ out:mouseout_controller.bind(this),
88
+ leave:mouseleave_controller.bind(this),
89
+ over:mouseover_controller.bind(this),
90
+ }
91
+ }
92
+ onDown(...callbacks){
93
+ if(callbacks.length===0)callbacks=[()=>{}];
94
+ this.__onEvent("down",{down:true,move:false,up:false,enter:false,out:false,leave:false,over:false},...callbacks)
95
+ return this;
96
+ }
97
+ onMove(...callbacks){
98
+ if(callbacks.length===0)callbacks=[()=>{}];
99
+ this.__onEvent("move",{down:false,move:true,up:false,enter:false,out:false,leave:false,over:false},...callbacks)
100
+ return this;
101
+ }
102
+ onUp(...callbacks){
103
+ if(callbacks.length===0)callbacks=[()=>{}];
104
+ this.__onEvent("up",{down:false,move:false,up:true,enter:false,out:false,leave:false,over:false},...callbacks)
105
+ return this;
106
+ }
107
+ onEnter(...callbacks){
108
+ if(callbacks.length===0)callbacks=[()=>{}];
109
+ this.__onEvent("enter",{down:false,move:false,up:false,enter:true,out:false,leave:false,over:false},...callbacks)
110
+ return this;
111
+ }
112
+ onOut(...callbacks){
113
+ if(callbacks.length===0)callbacks=[()=>{}];
114
+ this.__onEvent("out",{down:false,move:false,up:false,enter:false,out:true,leave:false,over:false},...callbacks)
115
+ return this;
116
+ }
117
+ onLeave(...callbacks){
118
+ if(callbacks.length===0)callbacks=[()=>{}];
119
+ this.__onEvent("leave",{down:false,move:false,up:false,enter:false,out:false,leave:true,over:false},...callbacks)
120
+ return this;
121
+ }
122
+ onOver(...callbacks){
123
+ if(callbacks.length===0)callbacks=[()=>{}];
124
+ this.__onEvent("over",{down:false,move:false,up:false,enter:false,out:false,leave:false,over:true},...callbacks)
125
+ return this;
126
+ }
127
+ }
128
+ function mousedown_controller(e){
129
+ EVENT_CONTROLLER.call(
130
+ this,
131
+ e,
132
+ "down",
133
+ ()=>{
134
+ this.dx=parseInt(e.offsetX);
135
+ this.dy=parseInt(e.offsetY);
136
+ this.isDown=true;
137
+ },
138
+ {
139
+ x:this.dx,
140
+ y:this.dy,
141
+ t:Date.now()-this.cache.stream.t0
142
+ }
143
+ )
144
+ }
145
+ function mousemove_controller(e){
146
+ EVENT_CONTROLLER.call(
147
+ this,
148
+ e,
149
+ "move",
150
+ ()=>{
151
+ this.mx=parseInt(e.offsetX);
152
+ this.my=parseInt(e.offsetY);
153
+ this.isMoving=true;
154
+ },
155
+ {
156
+ x:this.mx,
157
+ y:this.my,
158
+ t:Date.now()-this.cache.stream.t0
159
+ }
160
+ )
161
+ }
162
+ function mouseup_controller(e){
163
+ EVENT_CONTROLLER.call(
164
+ this,
165
+ e,
166
+ "up",
167
+ ()=>{
168
+ this.ux=parseInt(e.offsetX);
169
+ this.uy=parseInt(e.offsetY);
170
+ this.isDown=false;
171
+ const dx=this.dx;
172
+ const dy=this.dy;
173
+ const ux=this.ux;
174
+ const uy=this.uy;
175
+ const delta_x=(ux-dx)/this.target.Width;
176
+ const delta_y=(dy-uy)/this.target.Height;
177
+ const HORIZONTAL_SWIPPE=(delta_x<0)?"left":(delta_x>0)?"right":"none";
178
+ const VERTICAL_SWIPPE=(delta_y<0)?"bottom":(delta_y>0)?"top":"none";
179
+ this.swippe={
180
+ h:HORIZONTAL_SWIPPE,
181
+ v:VERTICAL_SWIPPE,
182
+ delta_x,
183
+ delta_y
184
+ }
185
+ },
186
+ {
187
+ x:this.ux,
188
+ y:this.uy,
189
+ t:Date.now()-this.cache.stream.t0
190
+ }
191
+ )
192
+ }
193
+ function mouseenter_controller(e){
194
+ EVENT_CONTROLLER.call(
195
+ this,
196
+ e,
197
+ "enter",
198
+ null,
199
+ null
200
+ )
201
+ }
202
+ function mouseleave_controller(e){
203
+ EVENT_CONTROLLER.call(
204
+ this,
205
+ e,
206
+ "leave",
207
+ null,
208
+ null
209
+ )
210
+ }
211
+ function mouseout_controller(e){
212
+ EVENT_CONTROLLER.call(
213
+ this,
214
+ e,
215
+ "out",
216
+ null,
217
+ null
218
+ )
219
+ }
220
+ function mouseover_controller(e){
221
+ EVENT_CONTROLLER.call(
222
+ this,
223
+ e,
224
+ "out",
225
+ null,
226
+ null
227
+ )
228
+ }
229
+ const Mouse=target=>new ZikoEventMouse(target);
230
+ export default Mouse;
File without changes
@@ -0,0 +1,44 @@
1
+ import { ZikoEvent , EVENT_CONTROLLER } from "../ZikoEvent.js";
2
+ function wheel_controller(e){
3
+ EVENT_CONTROLLER.call(this,e,"wheel",null,null)
4
+ }
5
+ class ZikoEventWheel extends ZikoEvent{
6
+ constructor(target){
7
+ super(target);
8
+ this.event=null;
9
+ this.cache={
10
+ prefixe:"",
11
+ preventDefault:{
12
+ wheel:false,
13
+ },
14
+ paused:{
15
+ wheel:false,
16
+ },
17
+ stream:{
18
+ enabled:{
19
+ wheel:false,
20
+
21
+ },
22
+ clear:{
23
+ wheel:false,
24
+
25
+ },
26
+ history:{
27
+ wheel:[],
28
+ }
29
+ },
30
+ callbacks:{
31
+ click:[],
32
+ }
33
+ }
34
+ this.__controller={
35
+ wheel:wheel_controller.bind(this),
36
+ }
37
+ }
38
+ onWheel(...callbacks){
39
+ this.__onEvent("wheel",{},...callbacks)
40
+ return this;
41
+ }
42
+ }
43
+ const Wheel=Target=>new ZikoEventWheel(Target);
44
+ export default Wheel
@@ -0,0 +1,44 @@
1
+ import { ZikoEvent , EVENT_CONTROLLER } from "../ZikoEvent.js";
2
+ function hashchange_controller(e){
3
+ EVENT_CONTROLLER.call(this,e,"hashchange",null,null)
4
+ }
5
+ class ZikoEventHash extends ZikoEvent{
6
+ constructor(target){
7
+ super(target);
8
+ this.event=null;
9
+ this.cache={
10
+ prefixe:"",
11
+ preventDefault:{
12
+ hashchange:false,
13
+ },
14
+ paused:{
15
+ hashchange:false,
16
+ },
17
+ stream:{
18
+ enabled:{
19
+ hashchange:false,
20
+
21
+ },
22
+ clear:{
23
+ hashchange:false,
24
+
25
+ },
26
+ history:{
27
+ hashchange:[],
28
+ }
29
+ },
30
+ callbacks:{
31
+ hashchange:[],
32
+ }
33
+ }
34
+ this.__controller={
35
+ hashchange:hashchange_controller.bind(this),
36
+ }
37
+ }
38
+ onChange(...callbacks){
39
+ this.__onEvent("hashchange",{},...callbacks)
40
+ return this;
41
+ }
42
+ }
43
+ const HashEvent=Target=>new ZikoEventHash(Target);
44
+ export default HashEvent
@@ -0,0 +1 @@
1
+ // Timeupdate
@@ -1,13 +1,18 @@
1
1
  import Pointer from "./Global/Pointer.js";
2
+ import Mouse from "./Global/Mouse.js";
3
+ import Wheel from "./Global/Wheel.js";
2
4
  import Key from "./Global/Key.js";
3
5
  import {Drag,Drop} from "./Global/Drag.js";
4
6
  import Click from "./Global/Click.js";
5
7
  import Clipboard from "./Global/Clipboard.js";
6
8
  import Focus from "./Global/Focus.js";
7
9
  import Input from "./Partiel/Input.js";
8
- import CustomEvent from "./Global/CustomEvent.js";
10
+ import HashEvent from "./Partiel/Hash.js";
11
+ import customEvent from "./Global/CustomEvent.js";
9
12
  const Events={
10
13
  Pointer,
14
+ Mouse,
15
+ Wheel,
11
16
  Key,
12
17
  Drag,
13
18
  Drop,
@@ -15,6 +20,7 @@ const Events={
15
20
  Clipboard,
16
21
  Focus,
17
22
  Input,
23
+ HashEvent,
18
24
  CustomEvent,
19
25
  ExtractAll: function () {
20
26
  const keys = Object.keys(this);
@@ -39,6 +45,8 @@ const Events={
39
45
  }
40
46
  export {
41
47
  Pointer,
48
+ Mouse,
49
+ Wheel,
42
50
  Key,
43
51
  Drag,
44
52
  Drop,
@@ -46,6 +54,7 @@ export {
46
54
  Clipboard,
47
55
  Focus,
48
56
  Input,
49
- CustomEvent
57
+ HashEvent,
58
+ customEvent
50
59
  }
51
60
  export default Events
@@ -1,27 +1,7 @@
1
1
  import ZikoUIElement from "../ZikoUIElement.js"
2
- function set_vertical(direction){
3
- direction == 1
4
- ? this.style({ flexDirection: "column" })
5
- : direction == -1 && this.style({ flexDirection: "column-reverse" });
6
- return this;
7
- }
8
- function set_horizontal(direction){
9
- direction == 1
10
- ? this.style({ flexDirection: "row" })
11
- : direction == -1 && this.style({ flexDirection: "row-reverse" });
12
- return this;
13
- }
14
- function map_pos_x(align){
15
- let pos = ["flex-start", "center", "flex-end"];
16
- if (typeof align === "number") align = pos[align + 1];
17
- return align;
18
- }
19
- function map_pos_y(align){
20
- return map_pos_x(-align);
21
- }
22
2
  class ZikoUIFlex extends ZikoUIElement {
23
- constructor(tag , w = "100%", h = "100%") {
24
- super(tag,"Flex");
3
+ constructor(tag = "div", w = "100%", h = "100%") {
4
+ super(tag ,"Flex");
25
5
  this.direction = "cols";
26
6
  if (typeof w == "number") w += "%";
27
7
  if (typeof h == "number") h += "%";
@@ -94,4 +74,24 @@ const Flex = (...ZikoUIElement) =>{
94
74
  }
95
75
  return new ZikoUIFlex(tag).append(...ZikoUIElement);
96
76
  }
77
+ function set_vertical(direction){
78
+ direction == 1
79
+ ? this.style({ flexDirection: "column" })
80
+ : direction == -1 && this.style({ flexDirection: "column-reverse" });
81
+ return this;
82
+ }
83
+ function set_horizontal(direction){
84
+ direction == 1
85
+ ? this.style({ flexDirection: "row" })
86
+ : direction == -1 && this.style({ flexDirection: "row-reverse" });
87
+ return this;
88
+ }
89
+ function map_pos_x(align){
90
+ let pos = ["flex-start", "center", "flex-end"];
91
+ if (typeof align === "number") align = pos[align + 1];
92
+ return align;
93
+ }
94
+ function map_pos_y(align){
95
+ return map_pos_x(-align);
96
+ }
97
97
  export{Flex,ZikoUIFlex}
@@ -4,7 +4,10 @@ class ZikoUIAudio extends ZikoUIElement {
4
4
  super("audio","audio");
5
5
  this.element.setAttribute("src", src);
6
6
  this.render();
7
- this.controls();
7
+ this.useControls();
8
+ }
9
+ get t(){
10
+ return this.element.currentTime;
8
11
  }
9
12
  useControls(enabled = true) {
10
13
  this.element.controls = enabled;
@@ -18,6 +21,16 @@ class ZikoUIAudio extends ZikoUIElement {
18
21
  this.element.pause();
19
22
  return this;
20
23
  }
24
+ seekTo(time) {
25
+ this.element.currentTime = time;
26
+ return this;
27
+ }
28
+ onPlay(){
29
+
30
+ }
31
+ onPause(){
32
+
33
+ }
21
34
  }
22
35
  const audio = (src) => new ZikoUIAudio(src);
23
36
  export {
@@ -9,6 +9,9 @@ class ZikoUIVideo extends ZikoUIElement {
9
9
  this.style({ width: w, height: h });
10
10
  this.render();
11
11
  }
12
+ get t(){
13
+ return this.element.currentTime;
14
+ }
12
15
  useControls(enabled = true) {
13
16
  this.element.controls = enabled;
14
17
  return this;
@@ -29,6 +32,16 @@ class ZikoUIVideo extends ZikoUIElement {
29
32
  this.element.requestPictureInPicture(e);
30
33
  return this;
31
34
  }
35
+ seekTo(time) {
36
+ this.element.currentTime = time;
37
+ return this;
38
+ }
39
+ onPlay(){
40
+
41
+ }
42
+ onPause(){
43
+
44
+ }
32
45
  }
33
46
  const video = (src, width, height) => new ZikoUIVideo(src, width, height);
34
47
  export {