tkeron 3.2.1 → 3.3.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
package/package.json
CHANGED
|
@@ -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,7 @@
|
|
|
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";
|
|
4
5
|
|
|
5
6
|
export interface TkeronElement {
|
|
6
7
|
htmlElement: HTMLElement;
|
|
@@ -12,6 +13,8 @@ export interface TkeronElement {
|
|
|
12
13
|
setHtml: (html: string) => TkeronElement;
|
|
13
14
|
setText: (text: string) => TkeronElement;
|
|
14
15
|
setAttribute: (attribute: string, value: string) => TkeronElement;
|
|
16
|
+
addClass: (...className) => TkeronElement;
|
|
17
|
+
removeClass: (...className) => TkeronElement;
|
|
15
18
|
}
|
|
16
19
|
|
|
17
20
|
export interface TkeronElementArguments {
|
|
@@ -19,14 +22,20 @@ export interface TkeronElementArguments {
|
|
|
19
22
|
childs: TkeronElement[];
|
|
20
23
|
}
|
|
21
24
|
|
|
22
|
-
export
|
|
25
|
+
export type TkeronElementConstructor = (
|
|
23
26
|
args?: Partial<TkeronElementArguments> | string
|
|
27
|
+
) => TkeronElement;
|
|
28
|
+
|
|
29
|
+
export type TkeronElementAuto = TkeronElement & TkeronElementConstructor;
|
|
30
|
+
|
|
31
|
+
export const tk = <TkeronElementAuto>((
|
|
32
|
+
tagOrArgs?: Partial<TkeronElementArguments> | string
|
|
24
33
|
): TkeronElement => {
|
|
25
|
-
if (!
|
|
34
|
+
if (!tagOrArgs) tagOrArgs = {};
|
|
26
35
|
|
|
27
|
-
let { tag, childs } = typeof
|
|
36
|
+
let { tag, childs } = typeof tagOrArgs === "object" ? tagOrArgs : <any>{};
|
|
28
37
|
|
|
29
|
-
if (typeof
|
|
38
|
+
if (typeof tagOrArgs === "string") tag = tagOrArgs;
|
|
30
39
|
|
|
31
40
|
if (!tag) tag = "div";
|
|
32
41
|
|
|
@@ -39,6 +48,8 @@ export const tk = (
|
|
|
39
48
|
setHtml(com);
|
|
40
49
|
setText(com);
|
|
41
50
|
setAttribute(com);
|
|
51
|
+
addClass(com);
|
|
52
|
+
removeClass(com);
|
|
42
53
|
|
|
43
54
|
if (childs)
|
|
44
55
|
for (const child of childs) {
|
|
@@ -46,4 +57,20 @@ export const tk = (
|
|
|
46
57
|
}
|
|
47
58
|
|
|
48
59
|
return com;
|
|
49
|
-
};
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
for (const attribute of [
|
|
63
|
+
"htmlElement",
|
|
64
|
+
"appendIn",
|
|
65
|
+
"setHtml",
|
|
66
|
+
"setText",
|
|
67
|
+
"setAttribute",
|
|
68
|
+
"addClass",
|
|
69
|
+
"removeClass",
|
|
70
|
+
]) {
|
|
71
|
+
Object.defineProperty(tk, attribute, {
|
|
72
|
+
get() {
|
|
73
|
+
return tk()[attribute];
|
|
74
|
+
},
|
|
75
|
+
});
|
|
76
|
+
}
|
package/tkeron_library/index.ts
CHANGED
|
@@ -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
|
/**
|