ziko 0.45.0 → 0.45.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.
Files changed (54) hide show
  1. package/dist/ziko.js +647 -696
  2. package/dist/ziko.mjs +636 -678
  3. package/package.json +1 -1
  4. package/src/__helpers__/register/index.js +3 -1
  5. package/src/__helpers__/register/register-to-instance.js +17 -5
  6. package/src/app/spa-file-based-routing.js +3 -2
  7. package/src/app/spa.js +3 -3
  8. package/src/app/ziko-app.js +1 -1
  9. package/src/events/__Events__.js +2 -1
  10. package/src/events/binders/click.js +20 -0
  11. package/src/events/binders/clipboard.js +16 -0
  12. package/src/events/{custom-event.js → binders/custom-event.js} +1 -1
  13. package/src/events/binders/drag.js +16 -0
  14. package/src/events/binders/focus.js +16 -0
  15. package/src/events/{hash.js → binders/hash.js} +2 -2
  16. package/src/events/binders/index.js +16 -0
  17. package/src/events/{key.js → binders/key.js} +4 -4
  18. package/src/events/binders/mouse.js +16 -0
  19. package/src/events/{pointer.js → binders/pointer.js} +4 -4
  20. package/src/events/{touch.js → binders/touch.js} +2 -2
  21. package/src/events/binders/wheel.js +16 -0
  22. package/src/events/custom-events/click-away.js +1 -0
  23. package/src/events/index.js +2 -16
  24. package/src/events/types/clipboard.d.ts +2 -2
  25. package/src/events/types/focus.d.ts +2 -2
  26. package/src/events/types/pointer.d.ts +2 -2
  27. package/src/hooks/use-state.js +2 -2
  28. package/src/lite.js +2 -0
  29. package/src/ui/__methods__/attrs.js +29 -45
  30. package/src/ui/__methods__/dom.js +65 -111
  31. package/src/ui/__methods__/events.js +17 -17
  32. package/src/ui/__methods__/index.js +10 -1
  33. package/src/ui/__methods__/indexing.js +14 -15
  34. package/src/ui/__methods__/style.js +28 -30
  35. package/src/ui/__methods__/utils/index.js +64 -0
  36. package/src/ui/constructors/UIElement-lite.js +10 -0
  37. package/src/ui/constructors/UIElement.js +89 -155
  38. package/src/ui/constructors/UIElementCore.js +235 -0
  39. package/src/ui/index.js +3 -3
  40. package/src/ui/suspense/index.js +1 -1
  41. package/src/ui/tags/index.js +9 -3
  42. package/src/ui/tags/tags-list.js +0 -1
  43. package/src/ui/wrappers/html/index.js +26 -0
  44. package/src/ui/wrappers/index.js +2 -0
  45. package/src/ui/wrappers/svg/index.js +46 -0
  46. package/src/events/click.js +0 -18
  47. package/src/events/clipboard.js +0 -16
  48. package/src/events/drag.js +0 -16
  49. package/src/events/focus.js +0 -16
  50. package/src/events/mouse.js +0 -16
  51. package/src/events/wheel.js +0 -16
  52. package/src/ui/__methods__/observer.js +0 -0
  53. package/src/ui/wrapper/index.js +0 -42
  54. /package/src/ui/constructors/{ZikoUIElementMethodesToBeMoved-dep.js → _m.js.txt} +0 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ziko",
3
- "version": "0.45.0",
3
+ "version": "0.45.2",
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,6 +1,8 @@
1
1
  import { register_to_class } from "./register-to-class.js";
2
- import { register_to_instance } from "./register-to-instance";
2
+ import { register_to_instance } from "./register-to-instance"; // Not Overridable
3
3
  export const register = (target, ...mixins) => {
4
+ console.log(target)
5
+ // return register_to_class(target, ...mixins)
4
6
  if(typeof target === 'function') register_to_class(target, ...mixins)
5
7
  else register_to_instance(target, ...mixins)
6
8
  }
@@ -1,18 +1,30 @@
1
1
  export function register_to_instance(target, ...mixins){
2
+ console.log('register to instance')
2
3
  mixins.forEach(n => _register_to_instance_(target, n))
3
4
  }
4
5
  function _register_to_instance_(instance, mixin) {
5
6
  const descriptors = Object.getOwnPropertyDescriptors(mixin);
6
-
7
7
  for (const key of Reflect.ownKeys(descriptors)) {
8
8
  const desc = descriptors[key];
9
-
10
9
  if ('get' in desc || 'set' in desc) {
11
- Object.defineProperty(instance, key, desc);
10
+ Object.defineProperty(instance, key, {
11
+ ...desc,
12
+ configurable: true // 🔑 make it replaceable
13
+ });
12
14
  } else if (typeof desc.value === 'function') {
13
- instance[key] = desc.value.bind(instance);
15
+ Object.defineProperty(instance, key, {
16
+ value: desc.value.bind(instance),
17
+ writable: true, // 🔑 allow reassignment
18
+ configurable: true, // 🔑 allow redefinition
19
+ enumerable: false
20
+ });
14
21
  } else {
15
- instance[key] = desc.value;
22
+ Object.defineProperty(instance, key, {
23
+ value: desc.value,
24
+ writable: true,
25
+ configurable: true,
26
+ enumerable: true
27
+ });
16
28
  }
17
29
  }
18
30
  }
@@ -24,11 +24,12 @@ function customPath(inputPath, root = './src/pages', extensions = ['js', 'ts'])
24
24
  const normalizedPath = inputPath.replace(/\\/g, '/').replace(/\[(\w+)\]/g, '$1/:$1');
25
25
  const parts = normalizedPath.split('/');
26
26
  const rootParts = root.split('/');
27
- const rootIndex = parts.indexOf(rootParts[rootParts.length - 1]);
27
+ const rootIndex = parts.indexOf(rootParts.at(-1));
28
28
  if (rootIndex !== -1) {
29
29
  const subsequentParts = parts.slice(rootIndex + 1);
30
- const lastPart = subsequentParts[subsequentParts.length - 1];
30
+ const lastPart = parts.at(-1);
31
31
  const isIndexFile = lastPart === 'index.js' || lastPart === 'index.ts';
32
+ // console.log({extensions, subsequentParts, lastPart, isIndexFile, rootParts, rootIndex, parts})
32
33
  const hasValidExtension = extensions.some(ext => lastPart === `.${ext}` || lastPart.endsWith(`.${ext}`));
33
34
  if (isIndexFile) {
34
35
  return '/' + (subsequentParts.length > 1 ? subsequentParts.slice(0, -1).join('/') : '');
package/src/app/spa.js CHANGED
@@ -13,7 +13,7 @@ class ZikoSPA extends ZikoApp{
13
13
  }
14
14
  clear(){
15
15
  [...this.routes].forEach(n=>{
16
- !isDynamic(n[0]) && n[1]?.isZikoUIElement && n[1].unrender()
16
+ !isDynamic(n[0]) && n[1]?.isUIElement && n[1].unrender()
17
17
  })
18
18
  // this.wrapper.clear();
19
19
  return this;
@@ -26,10 +26,10 @@ class ZikoSPA extends ZikoApp{
26
26
  element = callback.call(this,params)
27
27
  }
28
28
  else {
29
- callback?.isZikoUIElement && callback.render(this.wrapper);
29
+ callback?.isUIElement && callback.render(this.wrapper);
30
30
  if(typeof callback === "function") element = callback();
31
31
  }
32
- if(element?.isZikoUIElement) element.render(this.wrapper);
32
+ if(element?.isUIElement) element.render(this.wrapper);
33
33
  // if(element?.isZikoApp) element.render(this.wrapper);
34
34
  if(element instanceof Promise){
35
35
  element.then(e=>e.render(this.wrapper))
@@ -21,7 +21,7 @@ class ZikoApp {
21
21
  return this;
22
22
  }
23
23
  setWrapper(wrapper){
24
- if(wrapper?.isZikoUIElement) this.wrapper = wrapper;
24
+ if(wrapper?.isUIElement) this.wrapper = wrapper;
25
25
  else if(typeof wrapper === "function") this.wrapper = wrapper();
26
26
  return this;
27
27
  }
@@ -1,7 +1,8 @@
1
1
  const Events = {
2
2
  'Click' : [
3
3
  'Click',
4
- 'DblClick'
4
+ 'DblClick',
5
+ 'ClickAway'
5
6
  ],
6
7
  'Ptr' : [
7
8
  'PtrMove',
@@ -0,0 +1,20 @@
1
+ import { __ZikoEvent__ } from "../__ZikoEvent__.js";
2
+ import { Events } from "../__Events__.js";
3
+ // import { register_click_away_event } from "./custom-events/click-away.js";
4
+ class ZikoEventClick extends __ZikoEvent__{
5
+ constructor(target, customizer){
6
+ super(target, Events.Click, details_setter, customizer);
7
+ // register_click_away_event(target.element)
8
+ }
9
+ }
10
+ function details_setter(){
11
+ if(this.currentEvent==="click") this.dx = 0
12
+ else this.dx = 1
13
+ // console.log(this.currentEvent)
14
+ }
15
+ const bind_click_event = (target, customizer) => new ZikoEventClick(target, customizer)
16
+
17
+ export{
18
+ bind_click_event,
19
+ ZikoEventClick
20
+ }
@@ -0,0 +1,16 @@
1
+ import { __ZikoEvent__ } from "../__ZikoEvent__.js";
2
+ import { Events } from "../__Events__.js";
3
+ class ZikoEventClipboard extends __ZikoEvent__{
4
+ constructor(target, customizer){
5
+ super(target, Events.Clipboard, details_setter, customizer)
6
+ }
7
+ }
8
+ function details_setter(){
9
+
10
+ }
11
+ const bind_clipboard_event = (target, customizer) => new ZikoEventClipboard(target, customizer)
12
+
13
+ export{
14
+ bind_clipboard_event,
15
+ ZikoEventClipboard
16
+ }
@@ -1,4 +1,4 @@
1
- import { __ZikoEvent__ } from "./__ZikoEvent__.js";
1
+ import { __ZikoEvent__ } from "../__ZikoEvent__.js";
2
2
  class ZikoEventCustom extends __ZikoEvent__{
3
3
  constructor(target, events, customizer){
4
4
  super(target, events, details_setter, customizer)
@@ -0,0 +1,16 @@
1
+ import { __ZikoEvent__ } from "../__ZikoEvent__.js";
2
+ import { Events } from "../__Events__.js";
3
+ class ZikoEventDrag extends __ZikoEvent__{
4
+ constructor(target, customizer){
5
+ super(target, Events.Drag, details_setter, customizer)
6
+ }
7
+ }
8
+ function details_setter(){
9
+
10
+ }
11
+ const bind_drag_event = (target, customizer) => new ZikoEventDrag(target, customizer)
12
+
13
+ export{
14
+ bind_drag_event,
15
+ ZikoEventDrag
16
+ }
@@ -0,0 +1,16 @@
1
+ import { __ZikoEvent__ } from "../__ZikoEvent__.js";
2
+ import { Events } from "../__Events__.js";
3
+ class ZikoEventFocus extends __ZikoEvent__{
4
+ constructor(target, customizer){
5
+ super(target, Events.Focus, details_setter, customizer)
6
+ }
7
+ }
8
+ function details_setter(){
9
+
10
+ }
11
+ const bind_focus_event = (target, customizer) => new ZikoEventFocus(target, customizer)
12
+
13
+ export{
14
+ bind_focus_event,
15
+ ZikoEventFocus
16
+ }
@@ -1,5 +1,5 @@
1
- import { __ZikoEvent__ } from "./__ZikoEvent__.js";
2
- import { Events } from "./__Events__.js";
1
+ import { __ZikoEvent__ } from "../__ZikoEvent__.js";
2
+ import { Events } from "../__Events__.js";
3
3
  class ZikoEventHash extends __ZikoEvent__{
4
4
  constructor(target, customizer){
5
5
  super(target, Events.Hash, details_setter, customizer)
@@ -0,0 +1,16 @@
1
+ export * from "./click.js";
2
+ export * from "./clipboard.js";
3
+ export * from "./custom-event.js";
4
+ export * from "./drag.js";
5
+ export * from "./focus.js";
6
+ export * from "./hash.js";
7
+ export * from "./key.js";
8
+ export * from "./mouse.js";
9
+ export * from "./pointer.js";
10
+ export * from "./touch.js";
11
+ export * from "./wheel.js";
12
+
13
+
14
+
15
+
16
+ export * from './custom-event.js'
@@ -1,5 +1,5 @@
1
- import { __ZikoEvent__ } from "./__ZikoEvent__.js";
2
- import { Events } from "./__Events__.js";
1
+ import { __ZikoEvent__ } from "../__ZikoEvent__.js";
2
+ import { Events } from "../__Events__.js";
3
3
  class ZikoEventKey extends __ZikoEvent__{
4
4
  constructor(target, customizer){
5
5
  super(target, Events.Key, details_setter, customizer)
@@ -19,9 +19,9 @@ function details_setter(){
19
19
 
20
20
  }
21
21
  }
22
- const bindKeyEvent = (target, customizer) => new ZikoEventKey(target, customizer)
22
+ const bind_key_event = (target, customizer) => new ZikoEventKey(target, customizer)
23
23
 
24
24
  export{
25
- bindKeyEvent,
25
+ bind_key_event,
26
26
  ZikoEventKey
27
27
  }
@@ -0,0 +1,16 @@
1
+ import { __ZikoEvent__ } from "../__ZikoEvent__.js";
2
+ import { Events } from "../__Events__.js";
3
+ class ZikoEventMouse extends __ZikoEvent__{
4
+ constructor(target, customizer){
5
+ super(target, Events.Mouse, details_setter, customizer)
6
+ }
7
+ }
8
+ function details_setter(){
9
+
10
+ }
11
+ const bind_mouse_event = (target, customizer) => new ZikoEventMouse(target, customizer)
12
+
13
+ export{
14
+ bind_mouse_event,
15
+ ZikoEventMouse
16
+ }
@@ -1,5 +1,5 @@
1
- import { __ZikoEvent__ } from "./__ZikoEvent__.js";
2
- import { Events } from "./__Events__.js";
1
+ import { __ZikoEvent__ } from "../__ZikoEvent__.js";
2
+ import { Events } from "../__Events__.js";
3
3
  class ZikoEventPointer extends __ZikoEvent__{
4
4
  constructor(target, customizer){
5
5
  super(target, Events.Ptr, details_setter, customizer);
@@ -39,9 +39,9 @@ function details_setter(){
39
39
  // else this.dx = 1
40
40
  // console.log(this.currentEvent)
41
41
  }
42
- const bindPointerEvent = (target, customizer) => new ZikoEventPointer(target, customizer)
42
+ const bind_pointer_event = (target, customizer) => new ZikoEventPointer(target, customizer)
43
43
 
44
44
  export{
45
- bindPointerEvent,
45
+ bind_pointer_event,
46
46
  ZikoEventPointer
47
47
  }
@@ -1,5 +1,5 @@
1
- import { __ZikoEvent__ } from "./__ZikoEvent__.js";
2
- import { Events } from "./__Events__.js";
1
+ import { __ZikoEvent__ } from "../__ZikoEvent__.js";
2
+ import { Events } from "../__Events__.js";
3
3
  class ZikoEventTouch extends __ZikoEvent__{
4
4
  constructor(target, customizer){
5
5
  super(target, Events.Touch, details_setter, customizer)
@@ -0,0 +1,16 @@
1
+ import { __ZikoEvent__ } from "../__ZikoEvent__.js";
2
+ import { Events } from "../__Events__.js";
3
+ class ZikoEventWheel extends __ZikoEvent__{
4
+ constructor(target, customizer){
5
+ super(target, Events.Wheel, details_setter, customizer)
6
+ }
7
+ }
8
+ function details_setter(){
9
+
10
+ }
11
+ const bind_wheel_event = (target, customizer) => new ZikoEventWheel(target, customizer)
12
+
13
+ export{
14
+ bind_wheel_event,
15
+ ZikoEventWheel
16
+ }
@@ -7,6 +7,7 @@ class ClickAwayEvent extends Event {
7
7
  }
8
8
 
9
9
  function register_click_away_event(element) {
10
+ console.log(element)
10
11
  function handler(e) {
11
12
  if (!element.contains(e.target)) {
12
13
  const clickAwayEvent = new ClickAwayEvent(e, element);
@@ -1,17 +1,3 @@
1
- export * from "./click.js";
2
- export * from "./clipboard.js";
3
- export * from "./custom-event.js";
4
- export * from "./drag.js";
5
- export * from "./focus.js";
6
- export * from "./hash.js";
7
- export * from "./key.js";
8
- export * from "./mouse.js";
9
- export * from "./pointer.js";
10
- export * from "./touch.js";
11
- export * from "./wheel.js";
12
-
1
+ export * from './binders/index.js'
13
2
  export * from "./__ZikoEvent__.js";
14
- export * from "./utils.js";
15
-
16
-
17
- export * from './custom-event.js'
3
+ export * from "./utils.js";
@@ -12,9 +12,9 @@ declare class ZikoEventClipboard extends __ZikoEvent__ {
12
12
 
13
13
  }
14
14
 
15
- declare const bindClipboardEvent: (target: UIElement, customizer?: Function) => ZikoEventClipboard;
15
+ declare const bind_clipboard_event: (target: UIElement, customizer?: Function) => ZikoEventClipboard;
16
16
 
17
17
  export {
18
18
  ZikoEventClipboard,
19
- bindClipboardEvent,
19
+ bind_clipboard_event,
20
20
  };
@@ -11,9 +11,9 @@ declare class ZikoEventFocus extends __ZikoEvent__ {
11
11
 
12
12
  }
13
13
 
14
- declare const bindFocusEvent: (target: UIElement, customizer?: Function) => ZikoEventFocus;
14
+ declare const bind_focus_event: (target: UIElement, customizer?: Function) => ZikoEventFocus;
15
15
 
16
16
  export {
17
17
  ZikoEventFocus,
18
- bindFocusEvent,
18
+ bind_focus_event,
19
19
  };
@@ -37,9 +37,9 @@ declare class ZikoEventPointer extends __ZikoEvent__ implements PointerEventMeth
37
37
 
38
38
  }
39
39
 
40
- declare const bindPointerEvent: (target: UIElement, customizer?: Function) => ZikoEventPointer;
40
+ declare const bind_pointer_event: (target: UIElement, customizer?: Function) => ZikoEventPointer;
41
41
 
42
42
  export {
43
43
  ZikoEventPointer,
44
- bindPointerEvent,
44
+ bind_pointer_event,
45
45
  };
@@ -2,8 +2,8 @@ import { __init__global__ } from "../__ziko__/index.js";
2
2
  if(!globalThis.__Ziko__) __init__global__()
3
3
 
4
4
  // HMR persistence
5
- if (import.meta.hot) {
6
- import.meta.hot.data.__Ziko__ = import.meta.hot.data.__Ziko__ || globalThis.__Ziko__;
5
+ if (import.meta.hot?.data) {
6
+ import.meta.hot.data.__Ziko__ = import.meta.hot.data?.__Ziko__ || globalThis?.__Ziko__;
7
7
  globalThis.__Ziko__ = import.meta.hot.data.__Ziko__;
8
8
  // import.meta.hot.accept(n=>console.log(n));
9
9
  // console.log(import.meta.hot.data.__Ziko__.__State__.store)
package/src/lite.js ADDED
@@ -0,0 +1,2 @@
1
+ export * from './ui/constructors/UIElement-lite'
2
+ export * from './ui/__methods__/index.js'
@@ -1,49 +1,33 @@
1
- import { isStateGetter } from "../../hooks/use-state.js";
2
- import {
3
- is_camelcase,
4
- camel2hyphencase
5
- } from '../../data/string/index.js'
1
+ import { _set_attrs_ } from "./utils/index.js";
2
+ // import {
3
+ // is_camelcase,
4
+ // camel2hyphencase
5
+ // } from '../../data/string/index.js'
6
6
 
7
- // To Do add getter, watchAttr
8
- export const AttrsMethods = {
9
- setAttr(name, value) {
10
- if(name instanceof Object){
11
- const [names,values]=[Object.keys(name),Object.values(name)];
12
- for(let i=0;i<names.length;i++){
13
- if(values[i] instanceof Array)value[i] = values[i].join(" ");
14
- _set_attrs_.call(this, names[i], values[i])
15
- }
7
+ export function setAttr(name, value) {
8
+ if(name instanceof Object){
9
+ const [names,values]=[Object.keys(name),Object.values(name)];
10
+ for(let i=0;i<names.length;i++){
11
+ if(values[i] instanceof Array)value[i] = values[i].join(" ");
12
+ _set_attrs_.call(this, names[i], values[i])
16
13
  }
17
- else{
18
- if(value instanceof Array) value = value.join(" ");
19
- _set_attrs_.call(this, name, value)
20
- }
21
- return this;
22
- },
23
- removeAttr(...names) {
24
- for(let i=0;i<names.length;i++)this.element?.removeAttribute(names[i]);
25
- return this;
26
- },
27
- getAttr(name){
28
- name = is_camelcase(name) ? camel2hyphencase(name) : name;
29
- return this.element.attributes[name].value;
30
- },
31
- setContentEditable(bool = true) {
32
- this.setAttr("contenteditable", bool);
33
- return this;
34
14
  }
35
- };
15
+ else{
16
+ if(value instanceof Array) value = value.join(" ");
17
+ _set_attrs_.call(this, name, value)
18
+ }
19
+ return this;
20
+ }
21
+ export function removeAttr(...names) {
22
+ for(let i=0;i<names.length;i++)this.element?.removeAttribute(names[i]);
23
+ return this;
24
+ }
25
+ export function getAttr(name){
26
+ name = is_camelcase(name) ? camel2hyphencase(name) : name;
27
+ return this.element.attributes[name].value;
28
+ }
29
+ export function setContentEditable(bool = true) {
30
+ this.setAttr("contenteditable", bool);
31
+ return this;
32
+ }
36
33
 
37
- function _set_attrs_(name, value){
38
- if(this.element?.tagName !== "svg") name = is_camelcase(name) ? camel2hyphencase(name) : name;
39
- if(this?.attr[name] && this?.attr[name]===value) return;
40
- if(isStateGetter(value)){
41
- const getter = value()
42
- getter._subscribe(
43
- (newValue) => this.element?.setAttribute(name, newValue),
44
- this
45
- );
46
- }
47
- else this.element?.setAttribute(name, value)
48
- Object.assign(this.cache.attributes, {[name]:value});
49
- }
@@ -1,115 +1,69 @@
1
1
  import { text } from "../text/index.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
- async 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
- // Fix Items Latter
79
- if (ele[i] instanceof Function) {
80
- const getter = ele[i]();
81
- if (getter.isStateGetter) {
82
- ele[i] = text(getter.value);
83
- getter._subscribe(
84
- (newValue) => (ele[i].element.textContent = newValue),
85
- ele[i]
86
- );
87
- // this.element.appendChild(textNode);
88
- }
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
- }
97
- else if(ele[i] instanceof Promise){
98
- const UIEle = await ele[i]
99
- UIEle.cache.parent = this;
100
- this.element?.[adder](UIEle.element);
101
- UIEle.target = this.element;
102
- this.items[pusher](UIEle)
103
- }
104
- else if (ele[i] instanceof Object) {
105
- if (ele[i]?.style) this.style(ele[i]?.style);
106
- if (ele[i]?.attr) {
107
- Object.entries(ele[i].attr).forEach((n) =>
108
- this.setAttr("" + n[0], n[1]),
109
- );
110
- }
2
+ import { __addItem__ } from "./utils/index.js";
3
+ export function append(...ele) {
4
+ __addItem__.call(this, "append", "push", ...ele);
5
+ return this;
6
+ }
7
+ export function prepend(...ele) {
8
+ this.__addItem__.call(this, "prepend", "unshift", ...ele);
9
+ return this;
10
+ }
11
+ export function 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]);
111
18
  }
112
- }
113
- this.maintain();
114
19
  return this;
115
20
  }
21
+ export function remove(...ele) {
22
+ const remove = (ele) => {
23
+ if (typeof ele === "number") ele = this.items[ele];
24
+ if (ele?.isUIElement) 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
+ export function clear(){
34
+ this?.items?.forEach(n=>n.unrender());
35
+ this.element.innerHTML = "";
36
+ return this;
37
+ }
38
+ export function render(target = this.target) {
39
+ if(this.isBody)return ;
40
+ if(target?.isUIElement)target=target.element;
41
+ this.target=target;
42
+ this.target?.appendChild(this.element);
43
+ return this;
44
+ }
45
+ export function 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
+ export function renderAfter(t = 1) {
51
+ setTimeout(() => this.render(), t);
52
+ return this;
53
+ }
54
+ export function unrenderAfter(t = 1) {
55
+ setTimeout(() => this.unrender(), t);
56
+ return this;
57
+ }
58
+ export function after(ui){
59
+ if(ui?.isUIElement) ui=ui.element;
60
+ this.element?.after(ui)
61
+ return this;
62
+ }
63
+ export function before(ui){
64
+ if(ui?.isUIElement) ui=ui.element;
65
+ this.element?.before(ui)
66
+ return this;
67
+ }
68
+
69
+