ziko 0.0.31 → 0.33.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ziko",
3
- "version": "0.0.31",
3
+ "version": "0.33.0",
4
4
  "description": "a versatile javaScript framework offering a rich set of UI components, advanced mathematical utilities, reactivity, animations, client side routing and graphics capabilities",
5
5
  "keywords": [
6
6
  "front-end",
@@ -0,0 +1,28 @@
1
+ export function composeClass(Class, mixin) {
2
+ const descriptors = Object.getOwnPropertyDescriptors(mixin);
3
+
4
+ class Composed extends Class {
5
+ constructor(...args) {
6
+ super(...args);
7
+ for (const key of Reflect.ownKeys(descriptors)) {
8
+ const desc = descriptors[key];
9
+
10
+ if (typeof desc.value === 'function') {
11
+ this[key] = desc.value.bind(this);
12
+ }
13
+ }
14
+ }
15
+ }
16
+
17
+ for (const key of Reflect.ownKeys(descriptors)) {
18
+ const desc = descriptors[key];
19
+
20
+ if ('get' in desc || 'set' in desc) {
21
+ Object.defineProperty(Composed.prototype, key, desc);
22
+ } else if (typeof desc.value !== 'function') {
23
+ Object.defineProperty(Composed.prototype, key, desc);
24
+ }
25
+ }
26
+
27
+ return Composed;
28
+ }
@@ -0,0 +1,15 @@
1
+ export function composeInstance(instance, mixin) {
2
+ const descriptors = Object.getOwnPropertyDescriptors(mixin);
3
+
4
+ for (const key of Reflect.ownKeys(descriptors)) {
5
+ const desc = descriptors[key];
6
+
7
+ if ('get' in desc || 'set' in desc) {
8
+ Object.defineProperty(instance, key, desc);
9
+ } else if (typeof desc.value === 'function') {
10
+ instance[key] = desc.value.bind(instance);
11
+ } else {
12
+ instance[key] = desc.value;
13
+ }
14
+ }
15
+ }
@@ -0,0 +1,11 @@
1
+ import { composeClass } from "./compose-class.js";
2
+ import { composeInstance } from "./compose-instance.js";
3
+ export function compose(target, ...mixin) {
4
+ if (typeof target === 'function') {
5
+ return mixin.forEach(item =>composeClass(target, item));
6
+ } else if (typeof target === 'object') {
7
+ mixin.forEach(item =>composeInstance(target, item));
8
+ } else {
9
+ throw new TypeError("compose: target must be a class or instance");
10
+ }
11
+ }
@@ -0,0 +1,3 @@
1
+ export * from "./compose.js";
2
+ export * from "./compose-class.js";
3
+ export * from "./compose-instance.js"
@@ -16,7 +16,7 @@ const __RemoveAll__ =(obj)=> {
16
16
  }
17
17
  }
18
18
  }
19
- const mixin = (target, ...sources) => {
19
+ export const mixin = (target, ...sources) => {
20
20
  sources.forEach(source => {
21
21
  Object.getOwnPropertyNames(source.prototype).forEach(name => {
22
22
  if (name !== 'constructor') {
@@ -55,7 +55,9 @@ class B{
55
55
 
56
56
  // ab=new AB()
57
57
  export{
58
- mixin,
59
58
  __ExtractAll__,
60
59
  __RemoveAll__
61
60
  }
61
+
62
+
63
+ export * from "./composition/index.js"
package/src/compose.js ADDED
@@ -0,0 +1,89 @@
1
+ function composeInstance(instance, mixin) {
2
+ const descriptors = Object.getOwnPropertyDescriptors(mixin);
3
+
4
+ for (const key of Reflect.ownKeys(descriptors)) {
5
+ const desc = descriptors[key];
6
+
7
+ if ('get' in desc || 'set' in desc) {
8
+ Object.defineProperty(instance, key, desc);
9
+ } else if (typeof desc.value === 'function') {
10
+ instance[key] = desc.value.bind(instance); // override-safe
11
+ } else {
12
+ instance[key] = desc.value;
13
+ }
14
+ }
15
+ }
16
+
17
+ function composeClass(Base, mixin) {
18
+ const descriptors = Object.getOwnPropertyDescriptors(mixin);
19
+
20
+ return class extends Base {
21
+ constructor(...args) {
22
+ super(...args);
23
+ for (const key of Reflect.ownKeys(descriptors)) {
24
+ const desc = descriptors[key];
25
+ if (typeof desc.value === 'function') {
26
+ this[key] = desc.value.bind(this); // override-safe
27
+ }
28
+ }
29
+ }
30
+ };
31
+ }
32
+
33
+
34
+ function defineAccessorsAndData(proto, mixin) {
35
+ const descriptors = Object.getOwnPropertyDescriptors(mixin);
36
+ for (const key of Reflect.ownKeys(descriptors)) {
37
+ const desc = descriptors[key];
38
+ if ('get' in desc || 'set' in desc || typeof desc.value !== 'function') {
39
+ Object.defineProperty(proto, key, desc);
40
+ }
41
+ }
42
+ }
43
+
44
+
45
+ function compose(target, mixin) {
46
+ if (typeof target === 'function') {
47
+ const Composed = composeClass(target, mixin);
48
+ defineAccessorsAndData(Composed.prototype, mixin); // this order ensures overriding
49
+ return Composed;
50
+ } else if (typeof target === 'object' && target !== null) {
51
+ composeInstance(target, mixin);
52
+ } else {
53
+ throw new TypeError("compose: target must be a class or instance");
54
+ }
55
+ }
56
+ const mixin = {
57
+ greet() { return `Hello from mixin, ${this.name}`; },
58
+ get upperName() { return this.name.toUpperCase(); }
59
+ };
60
+
61
+ class Person {
62
+ constructor(name) {
63
+ this.name = name;
64
+ }
65
+ greet() {
66
+ return `Hello from class, ${this.name}`;
67
+ }
68
+ }
69
+
70
+ // CLASS MODE
71
+ const ComposedPerson = compose(Person, mixin);
72
+ const p1 = new ComposedPerson("Zak");
73
+ console.log(p1.greet()); // Hello from mixin, Zak
74
+ console.log(p1.upperName); // ZAK
75
+
76
+ // INSTANCE MODE
77
+ class Animal {
78
+ constructor(name) {
79
+ this.name = name;
80
+ compose(this, mixin);
81
+ }
82
+
83
+ greet() {
84
+ return `Animal says hi, ${this.name}`;
85
+ }
86
+ }
87
+ const a = new Animal("Milo");
88
+ console.log(a.greet()); // Hello from mixin, Milo
89
+ console.log(a.upperName); // MILO
@@ -1,3 +1,6 @@
1
+ import { compose } from "../../__helpers__/index.js";
2
+ import { DomMethods } from "../methods/dom.js";
3
+ import { IndexingMethods } from "../methods/indexing.js";
1
4
  import { ZikoUseStyle } from "../../reactivity/hooks/UI/useStyle.js";
2
5
  import { ZikoUIElementStyle } from "../style/index.js";
3
6
  import {
@@ -19,7 +22,7 @@ import {
19
22
  } from "../../reactivity/index.js"
20
23
  import { Random } from "../../math/index.js";
21
24
  import { Str } from "../../data/index.js";
22
- import { text } from "./text/text.js";
25
+ // import { text } from "./text/text.js";
23
26
  class ZikoUIElement {
24
27
  constructor(element, name="", {el_type="html", useDefaultStyle=false}={}){
25
28
  this.target = globalThis.__Ziko__.__Config__.default.target||globalThis?.document?.body;
@@ -34,6 +37,11 @@ class ZikoUIElement {
34
37
  this.target = element.parentElement;
35
38
  }
36
39
  if(element)this.__ele__ = element;
40
+ compose(
41
+ this,
42
+ DomMethods,
43
+ IndexingMethods
44
+ )
37
45
  this.cache = {
38
46
  name,
39
47
  parent:null,
@@ -99,6 +107,10 @@ class ZikoUIElement {
99
107
  get isZikoUIElement(){
100
108
  return true;
101
109
  }
110
+ register(){
111
+
112
+ return this;
113
+ }
102
114
  get st(){
103
115
  return this.cache.style;
104
116
  }
@@ -162,75 +174,6 @@ class ZikoUIElement {
162
174
  this.length = this.items.length;
163
175
  return this;
164
176
  }
165
- at(index) {
166
- return this.items.at(index);
167
- }
168
- #addItem(adder, pusher, ...ele) {
169
- if (this.cache.isFrozzen) {
170
- console.warn("You can't append new item to frozzen element");
171
- return this;
172
- }
173
- for (let i = 0; i < ele.length; i++) {
174
- if (["number", "string"].includes(typeof ele[i])) ele[i] = text(ele[i]);
175
- if(ele[i] instanceof Node) ele[i] = new ZikoUIElement(ele[i]);
176
- if (ele[i]?.isZikoUIElement) {
177
- ele[i].cache.parent = this;
178
- this.element[adder](ele[i].element);
179
- ele[i].target = this.element;
180
- this.items[pusher](ele[i]);
181
- }
182
- else if (ele[i] instanceof Object) {
183
- if (ele[i]?.style) this.style(ele[i]?.style);
184
- if (ele[i]?.attr) {
185
- Object.entries(ele[i].attr).forEach((n) =>
186
- this.setAttr("" + n[0], n[1]),
187
- );
188
- }
189
- }
190
- }
191
- this.maintain();
192
- return this;
193
- }
194
- append(...ele) {
195
- this.#addItem("append", "push", ...ele);
196
- return this;
197
- }
198
- prepend(...ele) {
199
- this.#addItem("prepend", "unshift", ...ele);
200
- return this;
201
- }
202
- insertAt(index, ...ele) {
203
- if (index >= this.element.children.length) this.append(...ele);
204
- else
205
- for (let i = 0; i < ele.length; i++) {
206
- if (["number", "string"].includes(typeof ele[i])) ele[i] = text(ele[i]);
207
- this.element?.insertBefore(ele[i].element, this.items[index].element);
208
- this.items.splice(index, 0, ele[i]);
209
- }
210
- return this;
211
- }
212
- remove(...ele) {
213
- const remove = (ele) => {
214
- if (typeof ele === "number") ele = this.items[ele];
215
- if (ele?.isZikoUIElement) this.element?.removeChild(ele.element);
216
- this.items = this.items.filter((n) => n !== ele);
217
- };
218
- for (let i = 0; i < ele.length; i++) remove(ele[i]);
219
- for (let i = 0; i < this.items.length; i++)
220
- Object.assign(this, { [[i]]: this.items[i] });
221
- // Remove from item
222
- return this;
223
- }
224
- forEach(callback) {
225
- this.items.forEach(callback);
226
- return this;
227
- }
228
- map(callback) {
229
- return this.items.map(callback);
230
- }
231
- find(condition) {
232
- return this.items.filter(condition);
233
- }
234
177
  filter(condition_callback, if_callback = () => {}, else_callback = () => {}) {
235
178
  const FilterItems = this.items.filter(condition_callback);
236
179
  FilterItems.forEach(if_callback);
@@ -322,41 +265,6 @@ class ZikoUIElement {
322
265
  describe(label){
323
266
  if(label)this.setAttr("aria-label",label)
324
267
  }
325
- clear(){
326
- this?.items?.forEach(n=>n.unrender());
327
- this.element.innerHTML = "";
328
- return this;
329
- }
330
- render(target = this.target) {
331
- if(this.isBody)return ;
332
- if(target?.isZikoUIElement)target=target.element;
333
- this.target=target;
334
- this.target?.appendChild(this.element);
335
- return this;
336
- }
337
- unrender(){
338
- if(this.cache.parent)this.cache.parent.remove(this);
339
- else if(this.target?.children?.length && [...this.target?.children].includes(this.element)) this.target.removeChild(this.element);
340
- return this;
341
- }
342
- renderAfter(t = 1) {
343
- setTimeout(() => this.render(), t);
344
- return this;
345
- }
346
- unrenderAfter(t = 1) {
347
- setTimeout(() => this.unrender(), t);
348
- return this;
349
- }
350
- after(ui){
351
- if(ui?.isZikoUIElement) ui=ui.element;
352
- this.element?.after(ui)
353
- return this;
354
- }
355
- before(ui){
356
- if(ui?.isZikoUIElement) ui=ui.element;
357
- this.element?.before(ui)
358
- return this;
359
- }
360
268
  animate(keyframe, {duration=1000, iterations=1, easing="ease"}={}){
361
269
  this.element?.animate(keyframe,{duration, iterations, easing});
362
270
  return this;
@@ -616,11 +524,5 @@ class ZikoUIElement {
616
524
  else globalThis.document.exitFullscreen();
617
525
  return this;
618
526
  }
619
- toPdf(){
620
- if(__ZikoPdf__){
621
-
622
- }
623
- return this;
624
- }
625
527
  }
626
528
  export default ZikoUIElement;
@@ -0,0 +1,99 @@
1
+ import { text } from "../elements/text/text.js";
2
+ export const DomMethods = {
3
+ append(...ele) {
4
+ __addItem__.call(this, "append", "push", ...ele);
5
+ return this;
6
+ },
7
+ prepend(...ele) {
8
+ this.__addItem__.call(this, "prepend", "unshift", ...ele);
9
+ return this;
10
+ },
11
+ insertAt(index, ...ele) {
12
+ if (index >= this.element.children.length) this.append(...ele);
13
+ else
14
+ for (let i = 0; i < ele.length; i++) {
15
+ if (["number", "string"].includes(typeof ele[i])) ele[i] = text(ele[i]);
16
+ this.element?.insertBefore(ele[i].element, this.items[index].element);
17
+ this.items.splice(index, 0, ele[i]);
18
+ }
19
+ return this;
20
+ },
21
+ remove(...ele) {
22
+ const remove = (ele) => {
23
+ if (typeof ele === "number") ele = this.items[ele];
24
+ if (ele?.isZikoUIElement) this.element?.removeChild(ele.element);
25
+ this.items = this.items.filter((n) => n !== ele);
26
+ };
27
+ for (let i = 0; i < ele.length; i++) remove(ele[i]);
28
+ for (let i = 0; i < this.items.length; i++)
29
+ Object.assign(this, { [[i]]: this.items[i] });
30
+ // Remove from item
31
+ return this;
32
+ },
33
+ clear(){
34
+ this?.items?.forEach(n=>n.unrender());
35
+ this.element.innerHTML = "";
36
+ return this;
37
+ },
38
+ render(target = this.target) {
39
+ if(this.isBody)return ;
40
+ if(target?.isZikoUIElement)target=target.element;
41
+ this.target=target;
42
+ this.target?.appendChild(this.element);
43
+ return this;
44
+ },
45
+ unrender(){
46
+ if(this.cache.parent)this.cache.parent.remove(this);
47
+ else if(this.target?.children?.length && [...this.target?.children].includes(this.element)) this.target.removeChild(this.element);
48
+ return this;
49
+ },
50
+ renderAfter(t = 1) {
51
+ setTimeout(() => this.render(), t);
52
+ return this;
53
+ },
54
+ unrenderAfter(t = 1) {
55
+ setTimeout(() => this.unrender(), t);
56
+ return this;
57
+ },
58
+ after(ui){
59
+ if(ui?.isZikoUIElement) ui=ui.element;
60
+ this.element?.after(ui)
61
+ return this;
62
+ },
63
+ before(ui){
64
+ if(ui?.isZikoUIElement) ui=ui.element;
65
+ this.element?.before(ui)
66
+ return this;
67
+ }
68
+
69
+ };
70
+
71
+ function __addItem__(adder, pusher, ...ele) {
72
+ if (this.cache.isFrozzen) {
73
+ console.warn("You can't append new item to frozzen element");
74
+ return this;
75
+ }
76
+ for (let i = 0; i < ele.length; i++) {
77
+ if (["number", "string"].includes(typeof ele[i])) ele[i] = text(ele[i]);
78
+ if (
79
+ typeof globalThis?.Node === "function" &&
80
+ ele[i] instanceof globalThis?.Node
81
+ )
82
+ ele[i] = new this.constructor(ele[i]);
83
+ if (ele[i]?.isZikoUIElement) {
84
+ ele[i].cache.parent = this;
85
+ this.element[adder](ele[i].element);
86
+ ele[i].target = this.element;
87
+ this.items[pusher](ele[i]);
88
+ } else if (ele[i] instanceof Object) {
89
+ if (ele[i]?.style) this.style(ele[i]?.style);
90
+ if (ele[i]?.attr) {
91
+ Object.entries(ele[i].attr).forEach((n) =>
92
+ this.setAttr("" + n[0], n[1]),
93
+ );
94
+ }
95
+ }
96
+ }
97
+ this.maintain();
98
+ return this;
99
+ }
File without changes
@@ -0,0 +1,15 @@
1
+ export const IndexingMethods = {
2
+ at(index) {
3
+ return this.items.at(index);
4
+ },
5
+ forEach(callback) {
6
+ this.items.forEach(callback);
7
+ return this;
8
+ },
9
+ map(callback) {
10
+ return this.items.map(callback);
11
+ },
12
+ find(condition) {
13
+ return this.items.filter(condition);
14
+ },
15
+ };
File without changes
File without changes
@@ -1,18 +1,46 @@
1
1
  import ZikoUIElement from "../elements/ZikoUIElement.js";
2
+ import { HTMLTags, SVGTags } from "./tags.js";
3
+ const _h=(tag, type, attributes, ...children)=>{
4
+ const { name, style, ...attrs } = attributes;
5
+ let element = new ZikoUIElement(tag, name, type);
6
+ style && element.style(style);
7
+ attrs && element.setAttr(attrs);
8
+ children && element.append(...children);
9
+ return element;
10
+ }
11
+ const h=(tag, attributes = {}, ...children)=> _h(tag, "html", attributes, ...children);
12
+ const s=(tag, attributes = {}, ...children)=> _h(tag, "svg", attributes, ...children);
13
+
2
14
  const tags = new Proxy({}, {
3
15
  get(target, prop) {
4
16
  if (typeof prop !== 'string') return undefined;
5
17
  let tag = prop.replaceAll("_","-").toLowerCase();
6
- switch(tag){
7
- case "html" : globalThis?.document?.createElement("html")
8
- case "head" :
9
- case "style" :
10
- case "link" :
11
- case "meta" :
12
- case "srcipt":
13
- case "body" : return null; break;
14
- default : return new ZikoUIElement(tag);
18
+ if(HTMLTags.includes(tag)) return (...args)=>{
19
+ if(!(args[0] instanceof ZikoUIElement) && args[0] instanceof Object){
20
+ let attributes = args.shift()
21
+ console.log(args)
22
+ return new ZikoUIElement(tag).setAttr(attributes).append(...args)
23
+ }
24
+ return new ZikoUIElement(tag).append(...args);
25
+ }
26
+ if(SVGTags.includes(tag)) return (...args)=>new ZikoUIElement(tag,"",{el_type : "svg"}).append(...args);
27
+ return (...args)=>{
28
+ if(!(args[0] instanceof ZikoUIElement) && args[0] instanceof Object){
29
+ let attributes = args.shift()
30
+ return new ZikoUIElement(tag).setAttr(attributes).append(...args)
31
+ }
32
+ return new ZikoUIElement(tag).append(...args);
15
33
  }
34
+ // switch(tag){
35
+ // case "html" : globalThis?.document?.createElement("html")
36
+ // case "head" :
37
+ // case "style" :
38
+ // case "link" :
39
+ // case "meta" :
40
+ // case "srcipt":
41
+ // case "body" : return null; break;
42
+ // default : return new ZikoUIElement(tag);
43
+ // }
16
44
  }
17
45
  });
18
46
 
@@ -0,0 +1,126 @@
1
+ const HTMLTags = [
2
+ 'a',
3
+ 'abb',
4
+ 'address',
5
+ 'area',
6
+ 'article',
7
+ 'aside',
8
+ 'audio',
9
+ 'b',
10
+ 'base',
11
+ 'bdi',
12
+ 'bdo',
13
+ 'blockquote',
14
+ 'br',
15
+ 'button',
16
+ 'canvas',
17
+ 'caption',
18
+ 'cite',
19
+ 'code',
20
+ 'col',
21
+ 'colgroup',
22
+ 'data',
23
+ 'datalist',
24
+ 'dd',
25
+ 'del',
26
+ 'details',
27
+ 'dfn',
28
+ 'dialog',
29
+ 'div',
30
+ 'dl',
31
+ 'dt',
32
+ 'em',
33
+ 'embed',
34
+ 'fieldset',
35
+ 'figcaption',
36
+ 'figure',
37
+ 'footer',
38
+ 'form',
39
+ 'h1',
40
+ 'h2',
41
+ 'h3',
42
+ 'h4',
43
+ 'h5',
44
+ 'h6',
45
+ 'header',
46
+ 'hgroup',
47
+ 'hr',
48
+ 'i',
49
+ 'iframe',
50
+ 'img',
51
+ 'ipnut',
52
+ 'ins',
53
+ 'kbd',
54
+ 'label',
55
+ 'legend',
56
+ 'li',
57
+ 'main',
58
+ 'map',
59
+ 'mark',
60
+ 'menu',
61
+ 'meter',
62
+ 'nav',
63
+ 'object',
64
+ 'ol',
65
+ 'optgroup',
66
+ 'option',
67
+ 'output',
68
+ 'p',
69
+ 'param',
70
+ 'picture',
71
+ 'pre',
72
+ 'progress',
73
+ 'q',
74
+ 'rp',
75
+ 'rt',
76
+ 'ruby',
77
+ 's',
78
+ 'samp',
79
+ 'search',
80
+ 'section',
81
+ 'select',
82
+ 'small',
83
+ 'source',
84
+ 'span',
85
+ 'strong',
86
+ 'sub',
87
+ 'summary',
88
+ 'sup',
89
+ 'svg',
90
+ 'table',
91
+ 'tbody',
92
+ 'td',
93
+ 'template',
94
+ 'textarea',
95
+ 'tfoot',
96
+ 'th',
97
+ 'thead',
98
+ 'time',
99
+ 'title',
100
+ 'tr',
101
+ 'track',
102
+ 'u',
103
+ 'ul',
104
+ 'var',
105
+ 'video',
106
+ 'wbr'
107
+ ];
108
+
109
+ const SVGTags = [
110
+ "svg", "g", "defs", "symbol", "use", "image", "switch",
111
+ "rect", "circle", "ellipse", "line", "polyline", "polygon", "path",
112
+ "text", "tspan", "textPath", "altGlyph", "altGlyphDef", "altGlyphItem", "glyph", "glyphRef",
113
+ "linearGradient", "radialGradient", "pattern", "solidColor",
114
+ "filter", "feBlend", "feColorMatrix", "feComponentTransfer", "feComposite", "feConvolveMatrix",
115
+ "feDiffuseLighting", "feDisplacementMap", "feDropShadow", "feFlood", "feFuncA", "feFuncR", "feFuncG", "feFuncB",
116
+ "feGaussianBlur", "feImage", "feMerge", "feMergeNode", "feMorphology", "feOffset", "feSpecularLighting",
117
+ "feTile", "feTurbulence",
118
+ "animate", "animateMotion", "animateTransform", "set",
119
+ "script",
120
+ "desc", "title", "metadata", "foreignObject"
121
+ ];
122
+
123
+ export{
124
+ HTMLTags,
125
+ SVGTags
126
+ }
File without changes