cedro 0.1.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.
@@ -0,0 +1,237 @@
1
+ import { ITheme, IThemeManager } from "../interfaces/themes.interface";
2
+
3
+ export class Theme implements ITheme {
4
+ name: string;
5
+ properties: Map<string, string>;
6
+ constructor(name: string) {
7
+ this.name = name;
8
+ this.properties = new Map<string, string>();
9
+ }
10
+
11
+ add(name: string, value: string): ITheme {
12
+ this.properties.set(name, value);
13
+ return this;
14
+ }
15
+ }
16
+
17
+ export const LightTheme = new Theme("light");
18
+ export const DarkTheme = new Theme("dark");
19
+
20
+ LightTheme.add("--palette-text-primary", "rgba(0, 0, 0, 0.87)")
21
+ .add("--palette-text-secondary", "rgba(0, 0, 0, 0.6)")
22
+ .add("--palette-text-disabled", "rgba(0, 0, 0, 0.38)")
23
+ .add("--palette-background-default", "#ffffff")
24
+ .add("--palette-background-paper", "#ffffff")
25
+ .add("--palette-action-active", "rgba(0, 0, 0, 0.54)")
26
+ .add("--palette-action-disabled", "rgba(0, 0, 0, 0.26)")
27
+ .add("--palette-action-hover", "#f5f5f5")
28
+ .add("--palette-action-selected", "rgba(0, 0, 0, 0.08)")
29
+ .add("--palette-action-disabled-bg", "rgba(0, 0, 0, 0.12)")
30
+
31
+ .add("--palette-divider", "rgba(0, 0, 0, 0.12)")
32
+
33
+ .add("--palette-link", "#1d79ee")
34
+ .add("--palette-link-hover", "#3393f2")
35
+
36
+ /*PRIMARY*/
37
+
38
+ .add("--palette-primary-main", "#90caf9")
39
+ .add("--palette-primary-dark", "#42a5f5")
40
+ .add("--palette-primary-light", "#e3f2fd")
41
+
42
+ .add("--palette-primary-text-main", "#2a3b49")
43
+ .add("--palette-primary-text-dark", "#133048")
44
+ .add("--palette-primary-text-light", "#43474b")
45
+
46
+ /*SECONDARY*/
47
+
48
+ .add("--palette-secondary-main", "#ce93d8")
49
+ .add("--palette-secondary-dark", "#ab47bc")
50
+ .add("--palette-secondary-light", "#f3e5f5")
51
+
52
+ .add("--palette-secondary-text-main", "#3d2b40")
53
+ .add("--palette-secondary-text-dark", "#e6c8eb")
54
+ .add("--palette-secondary-text-light", "#484348")
55
+
56
+ /*ERROR*/
57
+
58
+ .add("--palette-error-main", "#f44336")
59
+ .add("--palette-error-dark", "#d32f2f")
60
+ .add("--palette-error-light", "#e57373")
61
+
62
+ .add("--palette-error-text-main", "#fbc7c3")
63
+ .add("--palette-error-text-dark", "#f1c1c1")
64
+ .add("--palette-error-text-light", "#432222")
65
+
66
+ /*WARNING*/
67
+
68
+ .add("--palette-warning-main", "#ffa726")
69
+ .add("--palette-warning-dark", "#ffb74d")
70
+ .add("--palette-warning-light", "#f57c00")
71
+
72
+ .add("--palette-warning-text-main", "#4b310b")
73
+ .add("--palette-warning-text-dark", "#4b3616")
74
+ .add("--palette-warning-text-light", "#482400")
75
+
76
+ /*INFO*/
77
+
78
+ .add("--palette-info-main", "#29b6f6")
79
+ .add("--palette-info-dark", "#4fc3f7")
80
+ .add("--palette-info-light", "#0288d1")
81
+
82
+ .add("--palette-info-text-main", "#0c3649")
83
+ .add("--palette-info-text-dark", "#173949")
84
+ .add("--palette-info-text-light", "#b3dbf1")
85
+
86
+ /*SUCCESS*/
87
+
88
+ .add("--palette-success-main", "#66bb6a")
89
+ .add("--palette-success-dark", "#81c784")
90
+ .add("--palette-success-light", "#388e3c")
91
+
92
+ .add("--palette-success-text-main", "#1e371f")
93
+ .add("--palette-success-text-dark", "#263b27")
94
+ .add("--palette-success-text-light", "#c3ddc5");
95
+
96
+ DarkTheme.add("--palette-text-primary", "#cdd0d3")
97
+ .add("--palette-text-secondary", "#9aa0a6")
98
+ .add("--palette-text-disabled", "rgba(255, 255, 255, 0.5)")
99
+
100
+ .add("--palette-background-default", "#121212")
101
+ .add("--palette-background-paper", "#121212")
102
+
103
+ .add("--palette-action-active", "#ffffff")
104
+ .add("--palette-action-disabled", "rgba(255, 255, 255, 0.3)")
105
+ .add("--palette-action-hover", "#252525")
106
+ .add("--palette-action-selected", "rgba(255, 255, 255, 0.16)")
107
+ .add("--palette-action-disabled-bg", "rgba(255, 255, 255, 0.12)")
108
+
109
+ .add("--palette-divider", "rgba(255, 255, 255, 0.12)")
110
+
111
+ .add("--palette-link", "#90caf9")
112
+ .add("--palette-link-hover", "#e3f2fd")
113
+
114
+ /*PRIMARY*/
115
+ .add("--palette-primary-main", "#90caf9")
116
+ .add("--palette-primary-dark", "#42a5f5")
117
+ .add("--palette-primary-light", "#e3f2fd")
118
+
119
+ .add("--palette-primary-text-main", "#2a3b49")
120
+ .add("--palette-primary-text-dark", "#133048")
121
+ .add("--palette-primary-text-light", "#43474b")
122
+
123
+ /*SECONDARY*/
124
+
125
+ .add("--palette-secondary-main", "#ce93d8")
126
+ .add("--palette-secondary-dark", "#ab47bc")
127
+ .add("--palette-secondary-light", "#f3e5f5")
128
+
129
+ .add("--palette-secondary-text-main", "#3d2b40")
130
+ .add("--palette-secondary-text-dark", "#e6c8eb")
131
+ .add("--palette-secondary-text-light", "#484348")
132
+
133
+ /*ERROR*/
134
+
135
+ .add("--palette-error-main", "#f44336")
136
+ .add("--palette-error-dark", "#d32f2f")
137
+ .add("--palette-error-light", "#e57373")
138
+
139
+ .add("--palette-error-text-main", "#fbc7c3")
140
+ .add("--palette-error-text-dark", "#f1c1c1")
141
+ .add("--palette-error-text-light", "#432222")
142
+
143
+ /*WARNING*/
144
+
145
+ .add("--palette-warning-main", "#ffa726")
146
+ .add("--palette-warning-dark", "#ffb74d")
147
+ .add("--palette-warning-light", "#f57c00")
148
+
149
+ .add("--palette-warning-text-main", "#4b310b")
150
+ .add("--palette-warning-text-dark", "#4b3616")
151
+ .add("--palette-warning-text-light", "#482400")
152
+
153
+ /*INFO*/
154
+
155
+ .add("--palette-info-main", "#29b6f6")
156
+ .add("--palette-info-dark", "#4fc3f7")
157
+ .add("--palette-info-light", "#0288d1")
158
+
159
+ .add("--palette-info-text-main", "#0c3649")
160
+ .add("--palette-info-text-dark", "#173949")
161
+ .add("--palette-info-text-light", "#b3dbf1")
162
+
163
+ /*SUCCESS*/
164
+
165
+ .add("--palette-success-main", "#66bb6a")
166
+ .add("--palette-success-dark", "#81c784")
167
+ .add("--palette-success-light", "#388e3c")
168
+
169
+ .add("--palette-success-text-main", "#1e371f")
170
+ .add("--palette-success-text-dark", "#263b27")
171
+ .add("--palette-success-text-light", "#c3ddc5");
172
+
173
+ export class ThemeManager implements IThemeManager {
174
+ themes: ITheme[];
175
+ current: ITheme | null;
176
+
177
+ constructor() {
178
+ this.themes = [];
179
+ this.current = null;
180
+ }
181
+
182
+ public toggleTheme(): void {
183
+ if (this.current) {
184
+ if (this.current.name === "dark") {
185
+ this.setTheme("light");
186
+ return;
187
+ } else {
188
+ this.setTheme("dark");
189
+ return;
190
+ }
191
+ }
192
+ this.setTheme("light");
193
+ }
194
+
195
+ public load(): void {
196
+ const storageThemeName = localStorage.getItem("papertrade-theme");
197
+
198
+ if (storageThemeName) {
199
+ this.setTheme(storageThemeName);
200
+ return;
201
+ }
202
+ this.setTheme("light");
203
+ }
204
+
205
+ public add(theme: ITheme): void {
206
+ this.themes.push(theme);
207
+ }
208
+
209
+ public get(name: string): ITheme | null {
210
+ for (const theme of this.themes) {
211
+ if (theme.name === name) {
212
+ return theme;
213
+ }
214
+ }
215
+ return null;
216
+ }
217
+
218
+ public setTheme(name: string): void {
219
+ this.current = this.get(name);
220
+
221
+ if (!this.current) return;
222
+
223
+ var root = document.querySelector(":root") as HTMLElement;
224
+
225
+ for (const prop of this.current.properties) {
226
+ const [name, value] = prop;
227
+ root.style.setProperty(name, value);
228
+ }
229
+
230
+ localStorage.setItem("papertrade-theme", this.current.name);
231
+ }
232
+
233
+ public getTheme(): string {
234
+ if (this.current) return this.current.name;
235
+ return "light";
236
+ }
237
+ }
package/src/index.ts ADDED
@@ -0,0 +1,16 @@
1
+ import Application from "./core/application.core"
2
+ import {DOMcreateElement, DOMcreateFragment} from "./core/jsxsupport"
3
+ import {Widget, WidgetTypes, WidgetAlignTypes} from "./ui/widget.ui"
4
+ import {initWidgetCollection} from "./ui/widget.collection"
5
+
6
+ initWidgetCollection();
7
+
8
+ export{
9
+ Application,
10
+ Widget,
11
+ WidgetTypes,
12
+ WidgetAlignTypes,
13
+ DOMcreateElement,
14
+ DOMcreateFragment
15
+ }
16
+
@@ -0,0 +1,45 @@
1
+ import Navigo from "navigo";
2
+ import { IScreen } from "./screen.interface";
3
+ import { IWidget } from "./widget.interface";
4
+ import { Dialog } from "../ui/dialog";
5
+ import { Seo } from "../core/seo";
6
+ import { ThemeManager } from "../core/themes.core";
7
+
8
+ export interface IScreenSize {
9
+ minWidth: number;
10
+ maxWidth: number;
11
+ cb: (app: IApplication) => void;
12
+ }
13
+
14
+ export enum WUIThemes {
15
+ LIGHT = "light",
16
+ DARK = "dark",
17
+ }
18
+
19
+ export interface IApplication {
20
+ seo: Seo;
21
+ screen: IScreen;
22
+ root: IWidget;
23
+ router: Navigo;
24
+ alertDialog: Dialog;
25
+ confirmDialog: Dialog;
26
+ mediaQueries: Map<string, IScreenSize>;
27
+
28
+ theme: ThemeManager;
29
+
30
+ attachWidget(guest: IWidget, host: IWidget): void;
31
+
32
+ addMediaQuery(
33
+ query: string,
34
+ minWidth: number,
35
+ maxWidth: number,
36
+ cb: (app: IApplication) => void
37
+ ): void;
38
+
39
+ init(): void;
40
+ setRoot(root: IWidget): void;
41
+ getRoot(): IWidget;
42
+
43
+ confirm(msg: string): void;
44
+ alert(msg: string): void;
45
+ }
@@ -0,0 +1,17 @@
1
+ import { Vector2D } from "../types/vector2d.type";
2
+
3
+ export interface IScreen {
4
+ dimensions: Vector2D;
5
+
6
+ onResizeCB: () => void;
7
+
8
+ getWidth(): number;
9
+ getHeight(): number;
10
+
11
+ setWidth(width: number): void;
12
+ setHeight(height: number): void;
13
+ updateSize(): void;
14
+ populateSize(): void;
15
+
16
+ onResize(cb: () => void): void;
17
+ }
@@ -0,0 +1,19 @@
1
+ export interface ITheme {
2
+ name: string;
3
+ properties: Map<string, string>;
4
+ add(name: string, value: string): ITheme;
5
+ }
6
+
7
+ export interface IThemeManager {
8
+ themes: ITheme[];
9
+ current: ITheme | null;
10
+
11
+ toggleTheme(): void;
12
+
13
+ load(): void;
14
+ add(theme: ITheme): void;
15
+ get(name: string): ITheme | null;
16
+
17
+ setTheme(name: string): void;
18
+ getTheme(): string;
19
+ }
@@ -0,0 +1,123 @@
1
+ import { WidgetAlignTypes, WidgetTypes } from "../ui/widget.ui";
2
+ import { Vector2D } from "../types/vector2d.type";
3
+
4
+ export type WUIEvent =
5
+ | "click"
6
+ | "resize"
7
+ | "mousedown"
8
+ | "mouseup"
9
+ | "mousemove"
10
+ | "option-clicked";
11
+
12
+ export type WUICallback = {
13
+ event: WUIEvent;
14
+ then: (event: Event, wuie: IWidget) => void;
15
+ };
16
+
17
+ export interface IWidget {
18
+ readonly id: string;
19
+
20
+ subscribers: Map<string, WUICallback>;
21
+
22
+ padding: number;
23
+
24
+ left: number;
25
+ top: number;
26
+ width: number;
27
+ height: number;
28
+
29
+ initialWidth: number;
30
+ initialHeight: number;
31
+
32
+ fixedSize: number | null;
33
+
34
+ type: WidgetTypes;
35
+ align: WidgetAlignTypes;
36
+
37
+ visible: boolean;
38
+ enabled: boolean;
39
+
40
+ parent: IWidget | null;
41
+ childs: IWidget[];
42
+ bodyTagName: string;
43
+ body: HTMLElement;
44
+
45
+ overflow: boolean;
46
+
47
+ free: () => void;
48
+
49
+ subscribe: (cb: WUICallback) => void;
50
+ unsubscribe: (event: WUIEvent) => void;
51
+
52
+ setPadding(p: number): void;
53
+
54
+ setX(x: number): void;
55
+ setY(y: number): void;
56
+ setW(w: number): void;
57
+ setH(h: number): void;
58
+ setWH(w: number, h: number): void;
59
+
60
+ setInitialW(w: number): void;
61
+ setInitialH(h: number): void;
62
+
63
+ setFixedSize(s: number): void;
64
+
65
+ setType(type: WidgetTypes): void;
66
+ setAlign(align: WidgetAlignTypes): void;
67
+
68
+ setVisible(visible: boolean): void;
69
+ setEnabled(enabled: boolean): void;
70
+
71
+ setParent(parent: IWidget | null): void;
72
+ setBody(body: HTMLElement): void;
73
+ setChilds(childs: IWidget[]): void;
74
+
75
+ setOverflow(overflow: boolean): void;
76
+
77
+ addClass(cssClass: string): void;
78
+ deleteClass(cssClass: string): void;
79
+ deleteAllClasses(): void;
80
+
81
+ getPadding(): number;
82
+
83
+ getX(): number;
84
+ getY(): number;
85
+ getW(): number;
86
+ getH(): number;
87
+
88
+ getPosition(scroll: boolean): Vector2D;
89
+
90
+ getFixedSize(): number | null;
91
+
92
+ getType(): WidgetTypes;
93
+ getAlign(): WidgetAlignTypes;
94
+
95
+ getEnabled(): boolean;
96
+ getVisible(): boolean;
97
+
98
+ getParent(): IWidget | null;
99
+ getBody(): HTMLElement;
100
+ getChilds(): IWidget[];
101
+
102
+ getOverflow(): boolean;
103
+
104
+ addChild(child: IWidget | null): void;
105
+ disableSelection(): void;
106
+ display(): void;
107
+ enableSelection(): void;
108
+ hide(): void;
109
+ init(): void;
110
+ initPosition(): void;
111
+ render(): void;
112
+ resize(): void;
113
+ toggle(): void;
114
+
115
+ renderHTML(content: any): HTMLElement;
116
+
117
+ setZIndex(zIndex: number): void;
118
+ raisteTop(): void;
119
+ raiseBottom(): void;
120
+
121
+ attachWidget(guest: IWidget): void;
122
+ removeAllChilds(): void;
123
+ }
@@ -0,0 +1,4 @@
1
+ export type Vector2D = {
2
+ x: number;
3
+ y: number;
4
+ };
@@ -0,0 +1,70 @@
1
+ import { Colors } from "./colors.ui";
2
+ import { Widget } from "./widget.ui";
3
+
4
+ export type IconVariants =
5
+ | "Filled"
6
+ | "Outlined"
7
+ | "Round"
8
+ | "Sharp"
9
+ | "Two Tone";
10
+
11
+ export class Icon extends Widget {
12
+ variant: IconVariants;
13
+ color: Colors;
14
+ icon: string;
15
+
16
+ constructor(
17
+ id: string,
18
+ icon: string,
19
+ variant: IconVariants = "Filled",
20
+ parent: Widget
21
+ ) {
22
+ super(id, "span", parent);
23
+
24
+ this.variant = variant;
25
+ this.color = "primary";
26
+ this.icon = icon;
27
+
28
+ if (this.variant === "Filled") {
29
+ this.addClass("material-icons");
30
+ } else {
31
+ this.addClass(
32
+ "material-icons-" +
33
+ this.variant.toString().replace(" ", "-").toLowerCase()
34
+ );
35
+ }
36
+
37
+ this.setIcon(icon);
38
+
39
+ this.init();
40
+ }
41
+
42
+ public init(): void {
43
+ super.init();
44
+ }
45
+
46
+ setIcon(icon: string): void {
47
+ this.icon = icon;
48
+ this.body.innerHTML = icon;
49
+ }
50
+
51
+ setVariant(variant: IconVariants = "Filled"): void {
52
+ this.variant = variant;
53
+ }
54
+
55
+ setColor(color: Colors = "primary"): void {
56
+ this.color = color;
57
+ }
58
+
59
+ getVariant(): IconVariants {
60
+ return this.variant;
61
+ }
62
+
63
+ getColor(): Colors {
64
+ return this.color;
65
+ }
66
+
67
+ getIcon(): string {
68
+ return this.icon;
69
+ }
70
+ }
@@ -0,0 +1,70 @@
1
+ import "./styles/button.css";
2
+ import { Widget, WidgetTypes } from "./widget.ui";
3
+ import { Button } from "./button.ui";
4
+ import { Icon } from "./Icon.ui";
5
+ import { Label } from "./label.ui";
6
+
7
+ export class IconButton extends Button {
8
+ icon: Icon;
9
+ label: Label;
10
+
11
+ constructor(
12
+ id: string,
13
+ icon: string = "dark_mode",
14
+ parent: Widget | null = null
15
+ ) {
16
+ super(id, parent);
17
+
18
+ this.icon = new Icon(id + ".icon", icon, undefined, this);
19
+ this.label = new Label(id + ".label", undefined, this);
20
+
21
+ this.icon.setType(WidgetTypes.FREE);
22
+ this.label.setType(WidgetTypes.FREE);
23
+
24
+ this.init();
25
+ }
26
+
27
+ public init(): void {
28
+ super.init();
29
+ }
30
+
31
+ public render(): void {
32
+ super.render();
33
+
34
+ this.label.getBody().style.position = "absolute";
35
+ this.icon.getBody().style.position = "absolute";
36
+
37
+ const labelHeight = this.label.getBody().clientHeight;
38
+ const labelWidth = this.label.getBody().clientWidth;
39
+
40
+ //const iconHeight = this.icon.getBody().clientHeight;
41
+ const iconWidth = 24;
42
+
43
+ const startX =
44
+ this.getBody().clientWidth / 2 - (iconWidth + labelWidth) / 2;
45
+ const startY = this.getH() / 2 - 24 / 2;
46
+ const startLabelY = this.getH() / 2 - labelHeight / 2;
47
+
48
+ if (startX < 0 || startY < 0) {
49
+ setTimeout(() => {
50
+ this.render();
51
+ }, 500);
52
+ return;
53
+ }
54
+
55
+ this.icon.setX(startX);
56
+ this.label.setX(startX + iconWidth + 5);
57
+
58
+ this.icon.setY(startY);
59
+ this.label.setY(startLabelY);
60
+ }
61
+
62
+ public setText(text: string): void {
63
+ //super.setText(text);
64
+ this.label.setText(text);
65
+ }
66
+
67
+ public setIcon(icon: string): void {
68
+ this.icon.setIcon(icon);
69
+ }
70
+ }
@@ -0,0 +1,88 @@
1
+ import "./styles/button.css";
2
+ import { Colors } from "./colors.ui";
3
+ import { Widget } from "./widget.ui";
4
+
5
+ export type ButonVariants = "contained" | "outlined" | "text";
6
+ export type ButonSizes = "small" | "medium" | "large";
7
+
8
+ export class Button extends Widget {
9
+ variant: ButonVariants;
10
+ color: Colors;
11
+ fullWidth: boolean;
12
+ size: ButonSizes;
13
+ href: string;
14
+ text: string;
15
+
16
+ constructor(id: string, parent: Widget | null = null) {
17
+ super(id, "button", parent);
18
+
19
+ this.fullWidth = false;
20
+ //this.setType(WidgetTypes.CUSTOM);
21
+ this.variant = "text";
22
+ this.color = "primary"; //primary";
23
+ this.size = "medium";
24
+ this.href = "#";
25
+ this.text = "";
26
+
27
+ this.configureStyles();
28
+
29
+ this.init();
30
+ }
31
+
32
+ private configureStyles(): void {
33
+ this.deleteAllClasses();
34
+ this.addClass(`WUIButton-${this.variant}`);
35
+ this.addClass(`WUIButton-${this.variant}-color-${this.color}`);
36
+ }
37
+
38
+ public init(): void {
39
+ super.init();
40
+ }
41
+
42
+ setText(text: string): void {
43
+ this.text = text;
44
+ this.body.innerHTML = text;
45
+ }
46
+
47
+ setVariant(variant: ButonVariants = "contained"): void {
48
+ this.variant = variant;
49
+ this.configureStyles();
50
+ }
51
+
52
+ setColor(color: Colors = "primary"): void {
53
+ this.color = color;
54
+ this.configureStyles();
55
+ }
56
+
57
+ setFullWidth(fullWidth: boolean = false): void {
58
+ this.fullWidth = fullWidth;
59
+ }
60
+
61
+ setSize(size: ButonSizes = "medium"): void {
62
+ this.size = size;
63
+ }
64
+
65
+ setHref(href: string): void {
66
+ this.href = href;
67
+ }
68
+
69
+ getVariant(): ButonVariants {
70
+ return this.variant;
71
+ }
72
+
73
+ getColor(): Colors {
74
+ return this.color;
75
+ }
76
+
77
+ getSize(): ButonSizes {
78
+ return this.size;
79
+ }
80
+
81
+ getHref(): string {
82
+ return this.href;
83
+ }
84
+
85
+ getText(): string {
86
+ return this.text;
87
+ }
88
+ }
@@ -0,0 +1,7 @@
1
+ export type Colors =
2
+ | "primary"
3
+ | "secondary"
4
+ | "success"
5
+ | "error"
6
+ | "info"
7
+ | "warning";