ziko 0.68.0 → 0.68.2

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.
@@ -0,0 +1,24 @@
1
+ import { register_view_event } from '../custom-events-registry/view.js';
2
+ const CATEGORY = 'view';
3
+ export const ViewListeners = {
4
+ onEnterView(callback){
5
+ if(!this.exp.events?.[CATEGORY]) register_view_event(this.element);
6
+ return this.on(
7
+ 'enterview', callback,
8
+ { category : CATEGORY, isCustom : true})
9
+ },
10
+ onExitView(callback){
11
+ if(!this.exp.events?.[CATEGORY]) register_view_event(this.element);
12
+ return this.on(
13
+ 'exitview', callback,
14
+ { category : CATEGORY, isCustom : true})
15
+ },
16
+ onResizeView(callback){
17
+ if(!this.exp.events?.[CATEGORY]) register_view_event(this.element);
18
+ return this.on(
19
+ 'resizeview', callback,
20
+ { category : CATEGORY, isCustom : true})
21
+ },
22
+ }
23
+
24
+
@@ -5,15 +5,15 @@ import {
5
5
  AttrsMethods,
6
6
  DomMethods,
7
7
  IndexingMethods,
8
- // EventsMethodes,
9
8
  StyleMethods,
10
- PtrListeners,
11
- ClickListeners,
12
- KeyListeners,
13
9
  } from "./mixins/index.js";
14
10
 
15
11
  import {
16
- EventController
12
+ EventController,
13
+ PtrListeners,
14
+ ClickListeners,
15
+ KeyListeners,
16
+ ViewListeners,
17
17
  } from '../../events/index.js'
18
18
  class UIElement extends UIElementCore{
19
19
  constructor({element, name ='', type='html', render = __Ziko__.__Config__.default.render}={}){
@@ -29,24 +29,26 @@ class UIElement extends UIElementCore{
29
29
  AttrsMethods,
30
30
  DomMethods,
31
31
  StyleMethods,
32
- IndexingMethods,
32
+ IndexingMethods,
33
33
  PtrListeners,
34
34
  ClickListeners,
35
- KeyListeners
35
+ KeyListeners,
36
+ ViewListeners,
36
37
  );
37
38
 
38
39
  if(element)this.init(element, name, type, render)
39
40
  }
40
- _on(event, callback, {details_setter, category = 'global', preventDefault = false} = {}){
41
+ on(event_name, callback, {details_setter, category = 'global', isCustom = false,preventDefault = false} = {}){
41
42
  if(category && !this.exp.events.hasOwnProperty(category)) this.exp.events[category] = new EventController(this, category);
42
- const EVENT = this.exp.events[category]
43
- EVENT.addListener(event, (e)=>{
43
+ isCustom && this.exp.events[category].cache.customEvents.add(event_name)
44
+ const EVENT = this.exp.events[category];
45
+ EVENT.addListener(event_name, (e)=>{
44
46
  if(details_setter) details_setter(EVENT);
45
47
  callback(e)
46
48
  },{
47
49
  preventDefault
48
50
  });
49
-
51
+ return this;
50
52
  }
51
53
  _off(event, category = 'global'){
52
54
  this.exp.events[category].removeListener(event)
@@ -7,8 +7,6 @@ export * as AttrsMethods from './attrs.js'
7
7
  export * from './dom.js'
8
8
  export * as DomMethods from './dom.js'
9
9
 
10
- // export * from './events.js'
11
-
12
10
  export * from './indexing.js'
13
11
  export * as IndexingMethods from './indexing.js'
14
12
 
@@ -16,4 +14,3 @@ export * as IndexingMethods from './indexing.js'
16
14
  export * from './style.js'
17
15
  export * as StyleMethods from './style.js'
18
16
 
19
- export * from './events/index.js'
@@ -1,4 +0,0 @@
1
- export * from './key.js'
2
- export * from './pointer.js'
3
- export * from './mouse.js'
4
- export * from './touch.js'
@@ -1,14 +0,0 @@
1
- export function key_details_setter(){
2
- switch(this.currentEvent){
3
- case "keydown" : {
4
- this.kd = this.event.key
5
- }; break;
6
- case "keypress" : {
7
- this.kp = this.event.key
8
- }; break;
9
- case "keyup" : {
10
- this.ku = this.event.key
11
- }; break;
12
-
13
- }
14
- }
@@ -1,35 +0,0 @@
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,35 +0,0 @@
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;
30
- this.isDown = false;
31
- this.isMoving = false;
32
- break;
33
- }
34
- }
35
-
@@ -1,37 +0,0 @@
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
- }
@@ -1,22 +0,0 @@
1
- const CATEGORY = 'click';
2
- import {register_click_away_event} from '../../../../events/custom-events-registry/click-away.js'
3
- export const ClickListeners = {
4
- onClick(callback){
5
- this._on(
6
- 'click', callback,
7
- { category : CATEGORY })
8
- },
9
- onDblClick(callback){
10
- this._on(
11
- 'dblclick', callback,
12
- { category : CATEGORY})
13
- },
14
- onClickAway(callback){
15
- register_click_away_event(this.element)
16
- this._on(
17
- 'clickaway', callback,
18
- { category : CATEGORY})
19
- },
20
- }
21
-
22
-
@@ -1,3 +0,0 @@
1
- export * from './click.js'
2
- export * from './ptr.js'
3
- export * from './key.js'