ziko 2.0.0-beta.0 → 2.0.0-beta.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ziko",
3
- "version": "2.0.0-beta.0",
3
+ "version": "2.0.0-beta.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",
@@ -0,0 +1,38 @@
1
+ import type { UIElement } from "../../dom/UIElement";
2
+ export interface UILayoutOptions {
3
+ title?: string;
4
+ icon?: string;
5
+ description?: string;
6
+ lang?: string;
7
+ links?: Record<string, any>[];
8
+ script?: Record<string, any>[];
9
+ meta?: Record<string, any>[];
10
+ }
11
+
12
+ export class UILayout {
13
+ options: UILayoutOptions;
14
+ ui: UIElement[];
15
+
16
+ constructor(
17
+ options?: UILayoutOptions,
18
+ ...ui: UIElement[]
19
+ );
20
+
21
+ render(): void | {
22
+ title?: string;
23
+ icon?: string;
24
+ description?: string;
25
+ lang?: string;
26
+ links: Record<string, any>[];
27
+ meta: Record<string, any>[];
28
+ script: Record<string, any>[];
29
+ body: UIElement[];
30
+ };
31
+
32
+ mount(target: Element): this;
33
+ }
34
+
35
+ export function Layout(
36
+ options?: UILayoutOptions,
37
+ ...ui: UIElement[]
38
+ ): UILayout;
@@ -0,0 +1,98 @@
1
+ import { tags } from '../../dom/tags/index.js'
2
+ import { call_with_optional_props } from '../../dom/internal-utils'
3
+
4
+ const { meta, link, script } = tags;
5
+
6
+ export class UILayout {
7
+
8
+ constructor(
9
+ {
10
+ title,
11
+ icon,
12
+ description,
13
+ lang,
14
+ links = [],
15
+ script: scripts = [],
16
+ meta: metas = [],
17
+ } = {},
18
+ ...ui
19
+ ) {
20
+ this.options = {
21
+ title,
22
+ icon,
23
+ description,
24
+ lang,
25
+ links,
26
+ meta: metas,
27
+ script: scripts,
28
+ };
29
+
30
+ this.ui = ui;
31
+ this.render()
32
+ }
33
+
34
+ render() {
35
+ if (typeof document === "undefined") {
36
+ return {
37
+ ...this.options,
38
+ body: this.ui,
39
+ };
40
+ }
41
+
42
+ const {
43
+ title,
44
+ icon,
45
+ description,
46
+ lang,
47
+ links,
48
+ meta: metas,
49
+ script: scripts,
50
+ } = this.options;
51
+
52
+ if (title) {
53
+ document.title = title;
54
+ }
55
+
56
+ if (lang) {
57
+ document.documentElement.lang = lang;
58
+ }
59
+
60
+ if (icon) {
61
+ document.head.appendChild(
62
+ link({
63
+ rel: "icon",
64
+ href: icon,
65
+ })
66
+ );
67
+ }
68
+
69
+ if (description) {
70
+ document.head.appendChild(
71
+ meta({
72
+ name: "description",
73
+ content: description,
74
+ })
75
+ );
76
+ }
77
+
78
+ for (const attrs of links) {
79
+ document.head.appendChild(link(attrs));
80
+ }
81
+
82
+ for (const attrs of metas) {
83
+ document.head.appendChild(meta(attrs));
84
+ }
85
+
86
+ for (const attrs of scripts) {
87
+ document.head.appendChild(script(attrs));
88
+ }
89
+ }
90
+
91
+ mount(target){
92
+ this.ui.forEach(el => el.mount(target));
93
+ return this
94
+ }
95
+
96
+ }
97
+
98
+ export const Layout = call_with_optional_props(UILayout)
@@ -0,0 +1,7 @@
1
+ import type { UIElement } from "../../dom/UIElement";
2
+ import type { UILayout, UILayoutOptions } from "../Layout/index.d.ts";
3
+
4
+ export function Page(
5
+ options?: UILayoutOptions,
6
+ ...ui: UIElement[]
7
+ ): () => UILayout;
@@ -0,0 +1,5 @@
1
+ import { UILayout } from '../Layout/index.js';
2
+
3
+ export function Page(options, ...ui){
4
+ return () => new UILayout(options, ...ui)
5
+ }
@@ -0,0 +1,2 @@
1
+ export type * from './Layout/index.d.ts'
2
+ export type * from './Page/index.d.ts'
@@ -0,0 +1,2 @@
1
+ export * from './Layout/index.js'
2
+ export * from './Page/index.js'
@@ -1,5 +1,5 @@
1
1
  import { isStateGetter } from '../../hooks/use-state.js'
2
- import { UIElement } from '../constructors/UIElement.js'
2
+ import { UIElement } from '../UIElement/index.js'
3
3
 
4
4
  export const is_ui_item = item => {
5
5
  return (
@@ -36,4 +36,7 @@ export declare const UIELEMENT: unique symbol;
36
36
  * Used by hooks and UI components to recognize state getters without
37
37
  * importing the state implementation.
38
38
  */
39
- export declare const STATE_GETTER: unique symbol;
39
+ export declare const STATE_GETTER: unique symbol;
40
+
41
+ export declare const LAYOUT: unique symbol;
42
+ export declare const PAGE: unique symbol;
@@ -3,3 +3,5 @@ export const COMPLEX = Symbol.for('ziko/math/COMPLEX');
3
3
  export const MATRIX = Symbol.for('ziko/math/MATRIX');
4
4
  export const UIELEMENT = Symbol.for('ziko/dom/UIELEMENT');
5
5
  export const STATE_GETTER = Symbol.for("ziko/hooks/STATE_GETTER");
6
+ export const LAYOUT = Symbol.for("ziko/app/LAYOUT");
7
+ export const PAGE = Symbol.for("ziko/app/Page");
@@ -1,7 +1,13 @@
1
+ import { UILayout } from "../../app";
2
+
1
3
  export const renderer = async (target, component, props, wrapper) =>{
2
4
  if(!component) return;
3
5
  let mounted = await component(props);
4
6
  if(wrapper) mounted = wrapper(mounted);
7
+
8
+ if(mounted instanceof UILayout)
9
+ return mounted.ui.forEach(el => el.mount(target))
10
+
5
11
  mounted instanceof Array
6
12
  ? mounted.forEach(el => el.mount(target))
7
13
  : mounted.mount(target);