ziko 2.0.0-beta.10 → 2.0.0-beta.12
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": "2.0.0-beta.
|
|
3
|
+
"version": "2.0.0-beta.12",
|
|
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,11 +1,11 @@
|
|
|
1
1
|
import { UIElement as UIElementCore } from "../../mini-dom/UIElement/index.js";
|
|
2
2
|
import { register_to_class } from "../../internal-utils/register/register-to-class.js";
|
|
3
3
|
import {
|
|
4
|
-
LifecycleMethods,
|
|
4
|
+
// LifecycleMethods,
|
|
5
5
|
AttrsMethods,
|
|
6
6
|
DomMethods,
|
|
7
|
-
IndexingMethods,
|
|
8
|
-
StyleMethods,
|
|
7
|
+
// IndexingMethods,
|
|
8
|
+
// StyleMethods,
|
|
9
9
|
} from "../../mini-dom/mixins/index.js";
|
|
10
10
|
|
|
11
11
|
import {
|
|
@@ -15,6 +15,7 @@ import {
|
|
|
15
15
|
KeyListeners,
|
|
16
16
|
ViewListeners,
|
|
17
17
|
} from '../../events/index.js'
|
|
18
|
+
import { isStateGetter } from "../../hooks/use-state.js";
|
|
18
19
|
class UIElement extends UIElementCore{
|
|
19
20
|
constructor({element, name ='', type = 'html', render = __Ziko__.__Config__.default.render, props}={}){
|
|
20
21
|
super()
|
|
@@ -25,11 +26,11 @@ class UIElement extends UIElementCore{
|
|
|
25
26
|
}
|
|
26
27
|
register_to_class(
|
|
27
28
|
this,
|
|
28
|
-
LifecycleMethods,
|
|
29
|
+
// LifecycleMethods,
|
|
29
30
|
AttrsMethods,
|
|
30
31
|
DomMethods,
|
|
31
|
-
StyleMethods,
|
|
32
|
-
IndexingMethods,
|
|
32
|
+
// StyleMethods,
|
|
33
|
+
// IndexingMethods,
|
|
33
34
|
PtrListeners,
|
|
34
35
|
ClickListeners,
|
|
35
36
|
KeyListeners,
|
|
@@ -57,7 +58,7 @@ class UIElement extends UIElementCore{
|
|
|
57
58
|
});
|
|
58
59
|
return this;
|
|
59
60
|
}
|
|
60
|
-
|
|
61
|
+
off(event, category = 'global'){
|
|
61
62
|
this.exp.events[category].removeListener(event);
|
|
62
63
|
return this
|
|
63
64
|
}
|
|
@@ -108,24 +109,92 @@ class UIElement extends UIElementCore{
|
|
|
108
109
|
get parent(){
|
|
109
110
|
return this.cache.parent;
|
|
110
111
|
}
|
|
111
|
-
get
|
|
112
|
-
return this.element.getBoundingClientRect()
|
|
112
|
+
get rect(){
|
|
113
|
+
return this.element.getBoundingClientRect()
|
|
113
114
|
}
|
|
114
|
-
get
|
|
115
|
-
|
|
115
|
+
// get width(){
|
|
116
|
+
// return this.element.getBoundingClientRect().width;
|
|
117
|
+
// }
|
|
118
|
+
// get height(){
|
|
119
|
+
// return this.element.getBoundingClientRect().height;
|
|
120
|
+
// }
|
|
121
|
+
// get top(){
|
|
122
|
+
// return this.element.getBoundingClientRect().top;
|
|
123
|
+
// }
|
|
124
|
+
// get right(){
|
|
125
|
+
// return this.element.getBoundingClientRect().right;
|
|
126
|
+
// }
|
|
127
|
+
// get bottom(){
|
|
128
|
+
// return this.element.getBoundingClientRect().bottom;
|
|
129
|
+
// }
|
|
130
|
+
// get left(){
|
|
131
|
+
// return this.element.getBoundingClientRect().left;
|
|
132
|
+
// }
|
|
133
|
+
|
|
134
|
+
// Lifecycle
|
|
135
|
+
|
|
136
|
+
mount(target = this.target, delay = 0) {
|
|
137
|
+
if (this.isBody) return this;
|
|
138
|
+
if (target?.isUIElement) target = target.element;
|
|
139
|
+
this.target = target;
|
|
140
|
+
this.target?.appendChild(this.element);
|
|
141
|
+
return this;
|
|
142
|
+
}
|
|
143
|
+
unmount() {
|
|
144
|
+
if (this.cache.parent) {
|
|
145
|
+
this.cache.parent.remove(this);
|
|
146
|
+
}
|
|
147
|
+
else if (
|
|
148
|
+
this.target?.children?.length &&
|
|
149
|
+
[...this.target.children].includes(this.element)
|
|
150
|
+
)this.target.removeChild(this.element);
|
|
151
|
+
return this;
|
|
116
152
|
}
|
|
117
|
-
|
|
118
|
-
|
|
153
|
+
|
|
154
|
+
// Indexing
|
|
155
|
+
|
|
156
|
+
at(index) {
|
|
157
|
+
return this.items.at(index);
|
|
119
158
|
}
|
|
120
|
-
|
|
121
|
-
|
|
159
|
+
forEach(callback) {
|
|
160
|
+
this.items.forEach(callback);
|
|
161
|
+
return this;
|
|
122
162
|
}
|
|
123
|
-
|
|
124
|
-
return this.
|
|
163
|
+
map(callback) {
|
|
164
|
+
return this.items.map(callback);
|
|
165
|
+
}
|
|
166
|
+
find(condition) {
|
|
167
|
+
return this.items.filter(condition);
|
|
168
|
+
}
|
|
169
|
+
// Styling
|
|
170
|
+
style(styles){
|
|
171
|
+
if(!this.element?.style) return this;
|
|
172
|
+
for(let key in styles){
|
|
173
|
+
const value = styles[key];
|
|
174
|
+
if(isStateGetter(value)){
|
|
175
|
+
const getter = value()
|
|
176
|
+
Object.assign(this.element.style, {[key] : getter.value})
|
|
177
|
+
getter._subscribe(
|
|
178
|
+
(newValue) => {
|
|
179
|
+
Object.assign(this.element.style, {[key] : newValue})
|
|
180
|
+
},
|
|
181
|
+
// this
|
|
182
|
+
);
|
|
183
|
+
}
|
|
184
|
+
else Object.assign(this.element.style, {[key] : value})
|
|
185
|
+
}
|
|
186
|
+
return this;
|
|
125
187
|
}
|
|
126
|
-
|
|
127
|
-
return this.
|
|
188
|
+
size(width, height){
|
|
189
|
+
return this.style({width, height})
|
|
128
190
|
}
|
|
191
|
+
hide(){
|
|
192
|
+
|
|
193
|
+
}
|
|
194
|
+
show(){
|
|
195
|
+
|
|
196
|
+
}
|
|
197
|
+
|
|
129
198
|
|
|
130
199
|
}
|
|
131
200
|
export { UIElement }
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { text } from "../../mini-dom/text/index.js";
|
|
2
|
+
import { isStateGetter } from "../../hooks/use-state.js";
|
|
3
|
+
// export function append(...ele) {
|
|
4
|
+
// __addItems__.call(this, "append", "push", ...ele);
|
|
5
|
+
// return this;
|
|
6
|
+
// }
|
|
7
|
+
// export function prepend(...ele) {
|
|
8
|
+
// this.__addItems__.call(this, "prepend", "unshift", ...ele);
|
|
9
|
+
// return this;
|
|
10
|
+
// }
|
|
11
|
+
// export function insertAt(index, ...ele) {
|
|
12
|
+
// const target = this.itemsTarget;
|
|
13
|
+
// if (index >= target.items.length) return this.append(...ele);
|
|
14
|
+
// for (let i = 0; i < ele.length; i++) {
|
|
15
|
+
// if (["number", "string"].includes(typeof ele[i]))
|
|
16
|
+
// ele[i] = text(ele[i]);
|
|
17
|
+
// target.element?.insertBefore(
|
|
18
|
+
// ele[i].element,
|
|
19
|
+
// target.items[index].element
|
|
20
|
+
// );
|
|
21
|
+
// target.items.splice(index, 0, ele[i]);
|
|
22
|
+
// }
|
|
23
|
+
// target.maintain();
|
|
24
|
+
// return this;
|
|
25
|
+
// }
|
|
26
|
+
// export function remove(...ele) {
|
|
27
|
+
// const remove = (ele) => {
|
|
28
|
+
// if (typeof ele === "number") ele = this.items[ele];
|
|
29
|
+
// if (ele?.isUIElement) this.itemsTarget.element?.removeChild(ele.element);
|
|
30
|
+
// this.items = this.items.filter((n) => n !== ele);
|
|
31
|
+
// };
|
|
32
|
+
// for (let i = 0; i < ele.length; i++) remove(ele[i]);
|
|
33
|
+
// for (let i = 0; i < this.items.length; i++)
|
|
34
|
+
// Object.assign(this, { [[i]]: this.items[i] });
|
|
35
|
+
// // Remove from item
|
|
36
|
+
// return this;
|
|
37
|
+
// }
|
|
38
|
+
// export function clear(){
|
|
39
|
+
// this?.items?.forEach(n=>n.unmount());
|
|
40
|
+
// this.itemsTarget.element.innerHTML = '';
|
|
41
|
+
// return this;
|
|
42
|
+
// }
|
|
43
|
+
// export function replaceElementWith(new_element){
|
|
44
|
+
// this.cache.element.replaceWith(new_element)
|
|
45
|
+
// this.cache.element = new_element;
|
|
46
|
+
// // To do : Dispose Events and States
|
|
47
|
+
// return this
|
|
48
|
+
// }
|
|
49
|
+
// export function after(ui){
|
|
50
|
+
// if(ui?.isUIElement) ui = ui.element;
|
|
51
|
+
// this.itemsTarget.element?.after(ui)
|
|
52
|
+
// return this;
|
|
53
|
+
// }
|
|
54
|
+
// export function before(ui){
|
|
55
|
+
// if(ui?.isUIElement) ui = ui.element;
|
|
56
|
+
// this.itemsTarget.element?.before(ui)
|
|
57
|
+
// return this;
|
|
58
|
+
// }
|
|
59
|
+
|
|
60
|
+
export async function __addItem__(adder, pusher, item, referenceNode = null, index = null) {
|
|
61
|
+
const { element: itemsTargetEl, items } = this.itemsTarget;
|
|
62
|
+
if (["number", "string"].includes(typeof item)) item = text(item);
|
|
63
|
+
if (typeof item === "function" && isStateGetter(item)) {
|
|
64
|
+
const getter = item();
|
|
65
|
+
item = text(getter.value);
|
|
66
|
+
getter._subscribe(
|
|
67
|
+
(newValue) => { item.element.textContent = newValue; },
|
|
68
|
+
item
|
|
69
|
+
);
|
|
70
|
+
}
|
|
71
|
+
if (typeof globalThis?.Node === "function" && item instanceof globalThis.Node)
|
|
72
|
+
item = new this.constructor(item);
|
|
73
|
+
if (item instanceof Promise) item = await item;
|
|
74
|
+
if (item?.isUINode) {
|
|
75
|
+
item.cache.parent = this;
|
|
76
|
+
item.target = itemsTargetEl;
|
|
77
|
+
if (adder === "insertBefore" && itemsTargetEl)
|
|
78
|
+
itemsTargetEl.insertBefore(item.element, referenceNode);
|
|
79
|
+
else if (typeof itemsTargetEl?.[adder] === "function")
|
|
80
|
+
itemsTargetEl[adder](item.element);
|
|
81
|
+
if (pusher === "splice" && index !== null) items.splice(index, 0, item);
|
|
82
|
+
else if (typeof items?.[pusher] === "function") items[pusher](item);
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
export async function __addItems__(adder, pusher, ...elements) {
|
|
88
|
+
for (const item of elements) {
|
|
89
|
+
await __addItem__(adder, pusher, item);
|
|
90
|
+
}
|
|
91
|
+
this.maintain();
|
|
92
|
+
return this;
|
|
93
|
+
}
|
package/src/math/mapfun/index.js
CHANGED
|
@@ -32,16 +32,65 @@ export function setContentEditable(bool = true) {
|
|
|
32
32
|
}
|
|
33
33
|
|
|
34
34
|
|
|
35
|
-
export function _set_attrs_(name, value){
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
35
|
+
// export function _set_attrs_(name, value){
|
|
36
|
+
// if(globalThis.SVGAElement && this.element instanceof globalThis.SVGAElement) name = is_camelcase(name) ? camel2hyphencase(name) : name;
|
|
37
|
+
// if(this?.attr[name] && this?.attr[name]===value) return;
|
|
38
|
+
// if(isStateGetter(value)){
|
|
39
|
+
// const getter = value()
|
|
40
|
+
// getter._subscribe(
|
|
41
|
+
// (newValue) => this.element?.setAttribute(name, newValue),
|
|
42
|
+
// this
|
|
43
|
+
// );
|
|
44
|
+
// }
|
|
45
|
+
// else this.element?.setAttribute(name, value)
|
|
46
|
+
// Object.assign(this.cache.attributes, {[name]:value});
|
|
47
|
+
// }
|
|
48
|
+
|
|
49
|
+
function _set_attrs_(name, value) {
|
|
50
|
+
if (!this?.element || name == null)
|
|
51
|
+
return;
|
|
52
|
+
// Normalize SVG attribute names
|
|
53
|
+
if (
|
|
54
|
+
globalThis.SVGAElement &&
|
|
55
|
+
this.element instanceof globalThis.SVGAElement
|
|
56
|
+
) {
|
|
57
|
+
name = is_camelcase(name)
|
|
58
|
+
? camel2hyphencase(name)
|
|
59
|
+
: name;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// Ensure internal attribute storage exists
|
|
63
|
+
this.attr ??= {};
|
|
64
|
+
this.cache ??= {};
|
|
65
|
+
this.cache.attributes ??= {};
|
|
66
|
+
|
|
67
|
+
// Skip unchanged attributes
|
|
68
|
+
if (
|
|
69
|
+
Object.prototype.hasOwnProperty.call(this.attr, name) &&
|
|
70
|
+
this.attr[name] === value
|
|
71
|
+
) {
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// Reactive/state attribute
|
|
76
|
+
if (isStateGetter(value)) {
|
|
77
|
+
const state = value();
|
|
78
|
+
|
|
79
|
+
state?._subscribe(
|
|
80
|
+
(newValue) => {
|
|
81
|
+
this.element?.setAttribute(name, newValue);
|
|
82
|
+
this.cache.attributes[name] = newValue;
|
|
83
|
+
this.attr[name] = newValue;
|
|
84
|
+
},
|
|
85
|
+
this
|
|
43
86
|
);
|
|
87
|
+
|
|
88
|
+
return;
|
|
44
89
|
}
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
90
|
+
|
|
91
|
+
// Normal attribute
|
|
92
|
+
this.element.setAttribute(name, value);
|
|
93
|
+
|
|
94
|
+
this.attr[name] = value;
|
|
95
|
+
this.cache.attributes[name] = value;
|
|
96
|
+
}
|
|
@@ -3,10 +3,10 @@ export const camel2snakecase = (text = '') => text.replace(/[A-Z]/g, match => '_
|
|
|
3
3
|
export const camel2pascalcase = (text = '') => text.charAt(0).toUpperCase() + text.slice(1);
|
|
4
4
|
export const camel2constantcase = (text = '') => text.replace(/[A-Z]/g, match => '_' + match).toUpperCase();
|
|
5
5
|
|
|
6
|
-
export const pascal2snakecase = (text = '') => text.replace(/([A-Z])/g, (match, offset) => offset ? '_' + match.toLowerCase() : match.toLowerCase());
|
|
7
|
-
export const pascal2hyphencase = (text = '') => text.replace(/([A-Z])/g, (match, offset) => offset ? '-' + match.toLowerCase() : match.toLowerCase());
|
|
6
|
+
export const pascal2snakecase = (text = '') => text.replace(/([A-Z])/g, (match, _, offset) => offset ? '_' + match.toLowerCase() : match.toLowerCase());
|
|
7
|
+
export const pascal2hyphencase = (text = '') => text.replace(/([A-Z])/g, (match, _, offset) => offset ? '-' + match.toLowerCase() : match.toLowerCase());
|
|
8
|
+
export const pascal2constantcase = (text = '') => text.replace(/([A-Z])/g, (match, _, offset) => offset ? '_' + match : match).toUpperCase();
|
|
8
9
|
export const pascal2camelcase = (text = '') => text.charAt(0).toLowerCase() + text.slice(1);
|
|
9
|
-
export const pascal2constantcase = (text = '') => text.replace(/([A-Z])/g, (match, offset) => offset ? '_' + match : match).toUpperCase();
|
|
10
10
|
|
|
11
11
|
export const snake2camelcase = (text = '') => text.replace(/(_\w)/g, match => match[1].toUpperCase());
|
|
12
12
|
export const snake2hyphencase = (text = '') => text.replace(/_/g, "-");
|