tkeron 3.2.1 → 3.4.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/changelog.md CHANGED
@@ -1,3 +1,17 @@
1
+ # v3.4.0
2
+
3
+ - update tkeron library
4
+ - Add childs property
5
+ - Add "addChilds" method
6
+
7
+ # v3.3.0
8
+
9
+ - update tkeron lilbrary
10
+ - Add and remove classes
11
+ - Refactor for quick "div" creation
12
+ - Add a simple CSS reset
13
+
14
+
1
15
  # v3.2.1
2
16
 
3
17
  - removed path entry to @tkeron.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tkeron",
3
- "version": "3.2.1",
3
+ "version": "3.4.0",
4
4
  "description": "Micro framework for developing web user interfaces with typescript.",
5
5
  "bin": {
6
6
  "tkeron": "dist/index.js",
@@ -0,0 +1,12 @@
1
+ import { TkeronElement } from "./element";
2
+
3
+ export const addChilds = (com: TkeronElement) => {
4
+ com.addChilds = (...elements) => {
5
+ for (const element of elements) {
6
+ com.childs.push(element);
7
+ com.htmlElement.appendChild(element.htmlElement);
8
+ }
9
+
10
+ return com;
11
+ };
12
+ };
@@ -0,0 +1,15 @@
1
+ import { TkeronElement } from "./element";
2
+
3
+ export const addClass = (com: TkeronElement) => {
4
+ com.addClass = (...className) => {
5
+ com.htmlElement.classList.add(...className);
6
+ return com;
7
+ };
8
+ };
9
+
10
+ export const removeClass = (com: TkeronElement) => {
11
+ com.removeClass = (...className) => {
12
+ com.htmlElement.classList.remove(...className);
13
+ return com;
14
+ };
15
+ };
@@ -1,6 +1,8 @@
1
1
  import { appendIn } from "./appendIn";
2
2
  import { setAttribute } from "./setAttribute";
3
3
  import { setHtml, setText } from "./setHtml_setText";
4
+ import { addClass, removeClass } from "./addClass_removeClass";
5
+ import { addChilds } from "./addChilds";
4
6
 
5
7
  export interface TkeronElement {
6
8
  htmlElement: HTMLElement;
@@ -12,6 +14,10 @@ export interface TkeronElement {
12
14
  setHtml: (html: string) => TkeronElement;
13
15
  setText: (text: string) => TkeronElement;
14
16
  setAttribute: (attribute: string, value: string) => TkeronElement;
17
+ addClass: (...className) => TkeronElement;
18
+ removeClass: (...className) => TkeronElement;
19
+ childs: TkeronElement[];
20
+ addChilds: (...childs: TkeronElement[]) => TkeronElement;
15
21
  }
16
22
 
17
23
  export interface TkeronElementArguments {
@@ -19,19 +25,26 @@ export interface TkeronElementArguments {
19
25
  childs: TkeronElement[];
20
26
  }
21
27
 
22
- export const tk = (
28
+ export type TkeronElementConstructor = (
23
29
  args?: Partial<TkeronElementArguments> | string
30
+ ) => TkeronElement;
31
+
32
+ export type TkeronElementAuto = TkeronElement & TkeronElementConstructor;
33
+
34
+ export const tk = <TkeronElementAuto>((
35
+ tagOrArgs?: Partial<TkeronElementArguments> | string
24
36
  ): TkeronElement => {
25
- if (!args) args = {};
37
+ if (!tagOrArgs) tagOrArgs = {};
26
38
 
27
- let { tag, childs } = typeof args === "object" ? args : <any>{};
39
+ let { tag, childs } = typeof tagOrArgs === "object" ? tagOrArgs : <any>{};
28
40
 
29
- if (typeof args === "string") tag = args;
41
+ if (typeof tagOrArgs === "string") tag = tagOrArgs;
30
42
 
31
43
  if (!tag) tag = "div";
32
44
 
33
45
  const com = <TkeronElement>{
34
46
  htmlElement: document.createElement(tag),
47
+ childs: childs || [],
35
48
  };
36
49
 
37
50
  //init chaining methods
@@ -39,11 +52,33 @@ export const tk = (
39
52
  setHtml(com);
40
53
  setText(com);
41
54
  setAttribute(com);
55
+ addClass(com);
56
+ removeClass(com);
57
+ addChilds(com);
42
58
 
43
59
  if (childs)
44
60
  for (const child of childs) {
61
+ com.childs.push(child);
45
62
  com.htmlElement.appendChild(child.htmlElement);
46
63
  }
47
64
 
48
65
  return com;
49
- };
66
+ });
67
+
68
+ for (const attribute of [
69
+ "htmlElement",
70
+ "appendIn",
71
+ "setHtml",
72
+ "setText",
73
+ "setAttribute",
74
+ "addClass",
75
+ "removeClass",
76
+ "childs",
77
+ "addChilds"
78
+ ]) {
79
+ Object.defineProperty(tk, attribute, {
80
+ get() {
81
+ return tk()[attribute];
82
+ },
83
+ });
84
+ }
@@ -6,7 +6,29 @@ import { settings } from "./settings";
6
6
  * @param css {string} css code to append in style element
7
7
  */
8
8
  export const addCss = (css: string) => {
9
- tk({ tag: "style" });
9
+ tk({ tag: "style" }).setHtml(css).appendIn.head;
10
+ };
11
+
12
+ export const addCssReset = () => {
13
+ addCss(`
14
+ * {
15
+ box-sizing: border-box;
16
+ position: relative;
17
+ min-width: 0;
18
+ }
19
+
20
+ body {
21
+ min-height: 100dvh;
22
+ }
23
+
24
+ h1, h2, h3, h4 {
25
+ text-wrap: balance;
26
+ }
27
+
28
+ p {
29
+ text-wrap: pretty;
30
+ }
31
+ `);
10
32
  };
11
33
 
12
34
  /**
File without changes