@vandenberghinc/volt 1.1.4 → 1.1.6
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/backend/dist/cjs/database.d.ts +41 -68
- package/backend/dist/cjs/database.js +136 -78
- package/backend/dist/cjs/endpoint.d.ts +23 -9
- package/backend/dist/cjs/endpoint.js +98 -21
- package/backend/dist/cjs/file_watcher.js +2 -2
- package/backend/dist/cjs/frontend.d.ts +0 -2
- package/backend/dist/cjs/frontend.js +9 -9
- package/backend/dist/cjs/image_endpoint.d.ts +3 -1
- package/backend/dist/cjs/image_endpoint.js +2 -1
- package/backend/dist/cjs/payments/paddle.js +10 -2
- package/backend/dist/cjs/plugins/css.d.ts +6 -5
- package/backend/dist/cjs/plugins/css.js +32 -7
- package/backend/dist/cjs/plugins/ts/compiler.d.ts +6 -1
- package/backend/dist/cjs/plugins/ts/compiler.js +26 -2
- package/backend/dist/cjs/plugins/ts/preprocessing.js +5 -3
- package/backend/dist/cjs/server.d.ts +7 -13
- package/backend/dist/cjs/server.js +184 -303
- package/backend/dist/cjs/status.d.ts +1 -0
- package/backend/dist/cjs/status.js +2 -1
- package/backend/dist/cjs/stream.d.ts +5 -3
- package/backend/dist/cjs/stream.js +13 -4
- package/backend/dist/cjs/users.d.ts +1 -1
- package/backend/dist/cjs/users.js +87 -72
- package/backend/dist/cjs/utils.d.ts +17 -9
- package/backend/dist/cjs/utils.js +22 -64
- package/backend/dist/cjs/view.d.ts +2 -2
- package/backend/dist/cjs/view.js +38 -40
- package/backend/dist/cjs/volt.d.ts +3 -2
- package/backend/dist/cjs/volt.js +2 -2
- package/backend/dist/css/volt.css +5 -0
- package/backend/dist/esm/database.d.ts +41 -68
- package/backend/dist/esm/database.js +137 -79
- package/backend/dist/esm/endpoint.d.ts +23 -9
- package/backend/dist/esm/endpoint.js +99 -22
- package/backend/dist/esm/file_watcher.js +2 -2
- package/backend/dist/esm/frontend.d.ts +0 -2
- package/backend/dist/esm/frontend.js +9 -9
- package/backend/dist/esm/image_endpoint.d.ts +3 -1
- package/backend/dist/esm/image_endpoint.js +2 -1
- package/backend/dist/esm/payments/paddle.js +11 -3
- package/backend/dist/esm/plugins/css.d.ts +6 -5
- package/backend/dist/esm/plugins/css.js +32 -6
- package/backend/dist/esm/plugins/ts/compiler.d.ts +6 -1
- package/backend/dist/esm/plugins/ts/compiler.js +26 -2
- package/backend/dist/esm/plugins/ts/preprocessing.js +5 -3
- package/backend/dist/esm/server.d.ts +7 -13
- package/backend/dist/esm/server.js +182 -301
- package/backend/dist/esm/status.d.ts +1 -0
- package/backend/dist/esm/status.js +1 -0
- package/backend/dist/esm/stream.d.ts +5 -3
- package/backend/dist/esm/stream.js +13 -4
- package/backend/dist/esm/users.d.ts +1 -1
- package/backend/dist/esm/users.js +87 -72
- package/backend/dist/esm/utils.d.ts +17 -9
- package/backend/dist/esm/utils.js +21 -62
- package/backend/dist/esm/view.d.ts +2 -2
- package/backend/dist/esm/view.js +38 -40
- package/backend/dist/esm/volt.d.ts +3 -2
- package/backend/dist/esm/volt.js +2 -1
- package/backend/dist/esm-dev/blacklist.js +1 -1
- package/backend/dist/esm-dev/cli.js +2 -2
- package/backend/dist/esm-dev/database.d.ts +41 -68
- package/backend/dist/esm-dev/database.js +138 -80
- package/backend/dist/esm-dev/endpoint.d.ts +23 -9
- package/backend/dist/esm-dev/endpoint.js +100 -23
- package/backend/dist/esm-dev/file_watcher.js +3 -3
- package/backend/dist/esm-dev/frontend.d.ts +0 -2
- package/backend/dist/esm-dev/frontend.js +9 -9
- package/backend/dist/esm-dev/image_endpoint.d.ts +3 -1
- package/backend/dist/esm-dev/image_endpoint.js +2 -1
- package/backend/dist/esm-dev/logger.js +1 -1
- package/backend/dist/esm-dev/payments/paddle.js +12 -4
- package/backend/dist/esm-dev/plugins/css.d.ts +6 -5
- package/backend/dist/esm-dev/plugins/css.js +33 -7
- package/backend/dist/esm-dev/plugins/ts/compiler.d.ts +6 -1
- package/backend/dist/esm-dev/plugins/ts/compiler.js +27 -3
- package/backend/dist/esm-dev/plugins/ts/preprocessing.js +7 -5
- package/backend/dist/esm-dev/rate_limit.js +1 -1
- package/backend/dist/esm-dev/server.d.ts +7 -13
- package/backend/dist/esm-dev/server.js +184 -303
- package/backend/dist/esm-dev/status.d.ts +1 -0
- package/backend/dist/esm-dev/status.js +1 -0
- package/backend/dist/esm-dev/stream.d.ts +5 -3
- package/backend/dist/esm-dev/stream.js +13 -4
- package/backend/dist/esm-dev/users.d.ts +1 -1
- package/backend/dist/esm-dev/users.js +88 -73
- package/backend/dist/esm-dev/utils.d.ts +17 -9
- package/backend/dist/esm-dev/utils.js +22 -63
- package/backend/dist/esm-dev/view.d.ts +2 -2
- package/backend/dist/esm-dev/view.js +39 -41
- package/backend/dist/esm-dev/volt.d.ts +3 -2
- package/backend/dist/esm-dev/volt.js +2 -1
- package/backend/src/database.ts +173 -155
- package/backend/src/endpoint.ts +123 -31
- package/backend/src/file_watcher.ts +2 -2
- package/backend/src/frontend.ts +9 -8
- package/backend/src/image_endpoint.ts +4 -0
- package/backend/src/payments/paddle.ts +11 -3
- package/backend/src/plugins/css.ts +36 -8
- package/backend/src/plugins/ts/compiler.ts +37 -1
- package/backend/src/plugins/ts/preprocessing.ts +5 -3
- package/backend/src/server.ts +167 -306
- package/backend/src/status.ts +1 -0
- package/backend/src/stream.ts +28 -8
- package/backend/src/users.ts +87 -72
- package/backend/src/utils.ts +58 -25
- package/backend/src/view.ts +30 -28
- package/backend/src/{volt.js → volt.ts} +2 -1
- package/backend/tsconfig.cjs.json +3 -3
- package/backend/tsconfig.esm.json +3 -3
- package/frontend/dist/elements/base.d.ts +414 -432
- package/frontend/dist/elements/base.js +566 -329
- package/frontend/dist/elements/module.d.ts +26 -12
- package/frontend/dist/elements/module.js +69 -32
- package/frontend/dist/elements/register_element.d.ts +3 -0
- package/frontend/dist/elements/register_element.js +22 -0
- package/frontend/dist/modules/auth.d.ts +1 -0
- package/frontend/dist/modules/auth.js +6 -5
- package/frontend/dist/modules/color.d.ts +159 -0
- package/frontend/dist/modules/color.js +315 -0
- package/frontend/dist/modules/colors.d.ts +1 -26
- package/frontend/dist/modules/colors.js +417 -340
- package/frontend/dist/modules/cookies.d.ts +1 -0
- package/frontend/dist/modules/cookies.js +1 -0
- package/frontend/dist/modules/events.d.ts +1 -0
- package/frontend/dist/modules/events.js +1 -0
- package/frontend/dist/modules/google.d.ts +1 -0
- package/frontend/dist/modules/google.js +1 -0
- package/frontend/dist/modules/meta.d.ts +1 -0
- package/frontend/dist/modules/meta.js +1 -0
- package/frontend/dist/modules/mutex.d.ts +1 -2
- package/frontend/dist/modules/mutex.js +3 -4
- package/frontend/dist/modules/paddle.d.ts +1 -0
- package/frontend/dist/modules/paddle.js +14 -13
- package/frontend/dist/modules/scheme.d.ts +1 -0
- package/frontend/dist/modules/scheme.js +5 -3
- package/frontend/dist/modules/statics.d.ts +1 -0
- package/frontend/dist/modules/statics.js +1 -0
- package/frontend/dist/modules/support.d.ts +1 -0
- package/frontend/dist/modules/support.js +3 -2
- package/frontend/dist/modules/theme.d.ts +56 -0
- package/frontend/dist/{ui → modules}/theme.js +186 -75
- package/frontend/dist/modules/themes.d.ts +1 -1
- package/frontend/dist/modules/themes.js +1 -0
- package/frontend/dist/modules/user.d.ts +1 -0
- package/frontend/dist/modules/user.js +11 -10
- package/frontend/dist/modules/utils.d.ts +23 -2
- package/frontend/dist/modules/utils.js +93 -1
- package/frontend/dist/types/gradient.js +4 -0
- package/frontend/dist/ui/border_button.d.ts +0 -25
- package/frontend/dist/ui/border_button.js +50 -51
- package/frontend/dist/ui/button.d.ts +0 -21
- package/frontend/dist/ui/button.js +41 -46
- package/frontend/dist/ui/canvas.js +15 -15
- package/frontend/dist/ui/checkbox.d.ts +3 -17
- package/frontend/dist/ui/checkbox.js +36 -30
- package/frontend/dist/ui/code.d.ts +15 -82
- package/frontend/dist/ui/code.js +150 -125
- package/frontend/dist/ui/color.d.ts +0 -1
- package/frontend/dist/ui/color.js +1 -1
- package/frontend/dist/ui/context_menu.d.ts +4 -2
- package/frontend/dist/ui/context_menu.js +16 -17
- package/frontend/dist/ui/css.js +2 -0
- package/frontend/dist/ui/divider.d.ts +0 -7
- package/frontend/dist/ui/divider.js +21 -25
- package/frontend/dist/ui/dropdown.d.ts +13 -7
- package/frontend/dist/ui/dropdown.js +65 -30
- package/frontend/dist/ui/for_each.d.ts +0 -5
- package/frontend/dist/ui/for_each.js +17 -22
- package/frontend/dist/ui/form.d.ts +17 -12
- package/frontend/dist/ui/form.js +21 -18
- package/frontend/dist/ui/frame_modes.d.ts +9 -12
- package/frontend/dist/ui/frame_modes.js +8 -10
- package/frontend/dist/ui/google_map.d.ts +0 -11
- package/frontend/dist/ui/google_map.js +23 -28
- package/frontend/dist/ui/gradient.d.ts +0 -5
- package/frontend/dist/ui/gradient.js +17 -22
- package/frontend/dist/ui/image.d.ts +27 -58
- package/frontend/dist/ui/image.js +99 -93
- package/frontend/dist/ui/input.d.ts +20 -97
- package/frontend/dist/ui/input.js +192 -170
- package/frontend/dist/ui/link.d.ts +0 -18
- package/frontend/dist/ui/link.js +42 -48
- package/frontend/dist/ui/list.js +36 -37
- package/frontend/dist/ui/loader_button.d.ts +4 -19
- package/frontend/dist/ui/loader_button.js +35 -37
- package/frontend/dist/ui/loaders.d.ts +0 -8
- package/frontend/dist/ui/loaders.js +20 -25
- package/frontend/dist/ui/popup.d.ts +11 -8
- package/frontend/dist/ui/popup.js +183 -24
- package/frontend/dist/ui/pseudo.d.ts +3 -3
- package/frontend/dist/ui/pseudo.js +14 -17
- package/frontend/dist/ui/scroller.d.ts +10 -48
- package/frontend/dist/ui/scroller.js +306 -300
- package/frontend/dist/ui/slider.d.ts +9 -3
- package/frontend/dist/ui/slider.js +31 -17
- package/frontend/dist/ui/spacer.d.ts +0 -9
- package/frontend/dist/ui/spacer.js +21 -26
- package/frontend/dist/ui/span.js +13 -15
- package/frontend/dist/ui/stack.d.ts +14 -75
- package/frontend/dist/ui/stack.js +166 -169
- package/frontend/dist/ui/steps.d.ts +10 -23
- package/frontend/dist/ui/steps.js +47 -34
- package/frontend/dist/ui/style.d.ts +4 -3
- package/frontend/dist/ui/style.js +13 -18
- package/frontend/dist/ui/switch.d.ts +10 -4
- package/frontend/dist/ui/switch.js +24 -16
- package/frontend/dist/ui/table.d.ts +0 -23
- package/frontend/dist/ui/table.js +113 -119
- package/frontend/dist/ui/tabs.d.ts +3 -19
- package/frontend/dist/ui/tabs.js +35 -29
- package/frontend/dist/ui/text.d.ts +0 -8
- package/frontend/dist/ui/text.js +20 -25
- package/frontend/dist/ui/title.d.ts +0 -15
- package/frontend/dist/ui/title.js +39 -45
- package/frontend/dist/ui/ui.d.ts +0 -2
- package/frontend/dist/ui/ui.js +0 -2
- package/frontend/dist/ui/view.d.ts +3 -17
- package/frontend/dist/ui/view.js +27 -32
- package/frontend/dist/volt.d.ts +2 -1
- package/frontend/dist/volt.js +3 -1
- package/frontend/examples/dashboard/dashboard.ts +774 -0
- package/frontend/examples/theme/theme.ts +58 -0
- package/frontend/src/css/volt.css +5 -0
- package/frontend/src/elements/base.ts +767 -545
- package/frontend/src/elements/module.ts +90 -29
- package/frontend/src/elements/register_element.ts +24 -0
- package/frontend/src/modules/auth.ts +7 -6
- package/frontend/src/modules/color.ts +348 -0
- package/frontend/src/modules/colors.ts +468 -449
- package/frontend/src/modules/cookies.ts +1 -0
- package/frontend/src/modules/events.ts +1 -0
- package/frontend/src/modules/google.ts +1 -0
- package/frontend/src/modules/meta.ts +2 -1
- package/frontend/src/modules/mutex.ts +2 -4
- package/frontend/src/modules/paddle.ts +21 -20
- package/frontend/src/modules/scheme.ts +5 -4
- package/frontend/src/modules/statics.ts +2 -1
- package/frontend/src/modules/support.ts +3 -2
- package/frontend/src/modules/theme.ts +413 -0
- package/frontend/src/modules/themes.ts +2 -1
- package/frontend/src/modules/user.ts +12 -11
- package/frontend/src/modules/utils.ts +125 -2
- package/frontend/src/ui/border_button.ts +41 -37
- package/frontend/src/ui/button.ts +33 -32
- package/frontend/src/ui/canvas.ts +5 -2
- package/frontend/src/ui/checkbox.ts +21 -22
- package/frontend/src/ui/code.ts +92 -86
- package/frontend/src/ui/context_menu.ts +7 -5
- package/frontend/src/ui/css.ts +1 -1
- package/frontend/src/ui/divider.ts +15 -10
- package/frontend/src/ui/dropdown.ts +38 -21
- package/frontend/src/ui/for_each.ts +9 -8
- package/frontend/src/ui/form.ts +26 -21
- package/frontend/src/ui/frame_modes.ts +13 -17
- package/frontend/src/ui/google_map.ts +15 -13
- package/frontend/src/ui/gradient.ts +9 -8
- package/frontend/src/ui/image.ts +108 -86
- package/frontend/src/ui/input.ts +145 -144
- package/frontend/src/ui/link.ts +25 -23
- package/frontend/src/ui/list.ts +12 -6
- package/frontend/src/ui/loader_button.ts +26 -25
- package/frontend/src/ui/loaders.ts +12 -11
- package/frontend/src/ui/popup.ts +168 -14
- package/frontend/src/ui/pseudo.ts +5 -3
- package/frontend/src/ui/scroller.ts +303 -294
- package/frontend/src/ui/slider.ts +15 -10
- package/frontend/src/ui/spacer.ts +14 -11
- package/frontend/src/ui/span.ts +6 -2
- package/frontend/src/ui/stack.ts +196 -183
- package/frontend/src/ui/steps.ts +38 -22
- package/frontend/src/ui/style.ts +7 -4
- package/frontend/src/ui/switch.ts +16 -11
- package/frontend/src/ui/table.ts +42 -34
- package/frontend/src/ui/tabs.ts +20 -19
- package/frontend/src/ui/text.ts +12 -11
- package/frontend/src/ui/title.ts +22 -20
- package/frontend/src/ui/ui.ts +0 -2
- package/frontend/src/ui/view.ts +20 -19
- package/frontend/src/volt.ts +3 -1
- package/frontend/{compile.js → tools/compile.old.js} +2 -2
- package/frontend/tools/embed_scripts.js +69 -0
- package/frontend/tsconfig.json +26 -0
- package/package.json +7 -6
- package/frontend/dist/ui/theme.d.ts +0 -25
- package/frontend/exports.json +0 -1340
- package/frontend/src/modules/date.js +0 -535
- package/frontend/src/ui/color.ts +0 -117
- package/frontend/src/ui/theme.ts +0 -279
- /package/backend/src/{vinc.dev.js → vinc.dev.ts} +0 -0
|
@@ -0,0 +1,315 @@
|
|
|
1
|
+
import { Scheme } from "./scheme.js";
|
|
2
|
+
/**
|
|
3
|
+
* A utility class for color manipulation, conversion, and adjustment.
|
|
4
|
+
* Accepts colors in hex (e.g. "#ff0000"), RGB/RGBA strings (e.g. "rgb(255, 0, 0)" or "rgba(255,0,0,1)"),
|
|
5
|
+
* or as an array of numbers ([r, g, b] or [r, g, b, a]).
|
|
6
|
+
*
|
|
7
|
+
* All transformation methods (adjust_brightness, darken, lighten, interpolate, etc.) return a new Color instance,
|
|
8
|
+
* so they can be chained in a single line.
|
|
9
|
+
*/
|
|
10
|
+
export class Color {
|
|
11
|
+
// ANSI color escape codes (foreground)
|
|
12
|
+
static black = "\u001b[30m";
|
|
13
|
+
static red = "\u001b[31m";
|
|
14
|
+
static red_bold = "\u001b[31m\u001b[1m";
|
|
15
|
+
static green = "\u001b[32m";
|
|
16
|
+
static yellow = "\u001b[33m";
|
|
17
|
+
static blue = "\u001b[34m";
|
|
18
|
+
static magenta = "\u001b[35m";
|
|
19
|
+
static cyan = "\u001b[36m";
|
|
20
|
+
static light_gray = "\u001b[37m";
|
|
21
|
+
static gray = "\u001b[90m";
|
|
22
|
+
static bold = "\u001b[1m";
|
|
23
|
+
static italic = "\u001b[3m";
|
|
24
|
+
static end = "\u001b[0m";
|
|
25
|
+
static purple = "\u001b[94m";
|
|
26
|
+
// ANSI background color objects
|
|
27
|
+
static bg = {
|
|
28
|
+
black: "\u001b[40m",
|
|
29
|
+
red: "\u001b[41m",
|
|
30
|
+
green: "\u001b[42m",
|
|
31
|
+
yellow: "\u001b[43m",
|
|
32
|
+
blue: "\u001b[44m",
|
|
33
|
+
magenta: "\u001b[45m",
|
|
34
|
+
cyan: "\u001b[46m",
|
|
35
|
+
white: "\u001b[47m",
|
|
36
|
+
};
|
|
37
|
+
static bright_bg = {
|
|
38
|
+
black: "\u001b[100m",
|
|
39
|
+
red: "\u001b[101m",
|
|
40
|
+
green: "\u001b[102m",
|
|
41
|
+
yellow: "\u001b[103m",
|
|
42
|
+
blue: "\u001b[104m",
|
|
43
|
+
magenta: "\u001b[105m",
|
|
44
|
+
cyan: "\u001b[106m",
|
|
45
|
+
white: "\u001b[107m",
|
|
46
|
+
};
|
|
47
|
+
// Internal RGBA representation
|
|
48
|
+
_rgba;
|
|
49
|
+
/**
|
|
50
|
+
* Creates a new Color instance.
|
|
51
|
+
* @param input - A hex string, an "rgb(...)" / "rgba(...)" string, or an array of numbers ([r, g, b] or [r, g, b, a]).
|
|
52
|
+
*/
|
|
53
|
+
constructor(input) {
|
|
54
|
+
this._rgba = Color._from_input(input);
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Converts input into an RGBA object.
|
|
58
|
+
* @private
|
|
59
|
+
*/
|
|
60
|
+
static _from_input(input) {
|
|
61
|
+
if (typeof input === "string") {
|
|
62
|
+
if (input.startsWith("#")) {
|
|
63
|
+
return Color.hex_to_rgb(input);
|
|
64
|
+
}
|
|
65
|
+
else if (input.startsWith("rgb")) {
|
|
66
|
+
return Color.rgb_to_obj(input);
|
|
67
|
+
}
|
|
68
|
+
else {
|
|
69
|
+
throw new Error(`Invalid color string "${input}"`);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
else if (Array.isArray(input)) {
|
|
73
|
+
return Color.array_to_rgba(input);
|
|
74
|
+
}
|
|
75
|
+
throw new Error(`Invalid color input "${input}" with type "${Scheme.value_type(input)}". Ensure the input is a hex or rgb(a) color.`);
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Converts a numeric array to an RGBA object.
|
|
79
|
+
* @param array - An array of numbers representing [r, g, b] or [r, g, b, a].
|
|
80
|
+
*/
|
|
81
|
+
static array_to_rgba(array) {
|
|
82
|
+
return {
|
|
83
|
+
r: isNaN(array[0]) ? 0 : array[0],
|
|
84
|
+
g: isNaN(array[1]) ? 0 : array[1],
|
|
85
|
+
b: isNaN(array[2]) ? 0 : array[2],
|
|
86
|
+
a: array.length < 4 ? 1.0 : isNaN(array[3]) ? 1.0 : array[3],
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
static hex_to_rgb(hex, as_array = false) {
|
|
90
|
+
let clean_hex = hex;
|
|
91
|
+
const index = clean_hex.indexOf("#");
|
|
92
|
+
if (index !== -1) {
|
|
93
|
+
clean_hex = clean_hex.substr(index + 1);
|
|
94
|
+
}
|
|
95
|
+
let r = parseInt(clean_hex.substring(0, 2), 16);
|
|
96
|
+
let g = parseInt(clean_hex.substring(2, 4), 16);
|
|
97
|
+
let b = parseInt(clean_hex.substring(4, 6), 16);
|
|
98
|
+
let a = 1;
|
|
99
|
+
if (clean_hex.length > 6) {
|
|
100
|
+
a = parseInt(clean_hex.substring(6, 8), 16) / 255;
|
|
101
|
+
}
|
|
102
|
+
if (isNaN(r)) {
|
|
103
|
+
r = 0;
|
|
104
|
+
}
|
|
105
|
+
if (isNaN(g)) {
|
|
106
|
+
g = 0;
|
|
107
|
+
}
|
|
108
|
+
if (isNaN(b)) {
|
|
109
|
+
b = 0;
|
|
110
|
+
}
|
|
111
|
+
if (isNaN(a)) {
|
|
112
|
+
a = 1;
|
|
113
|
+
}
|
|
114
|
+
if (as_array) {
|
|
115
|
+
return [r, g, b, a];
|
|
116
|
+
}
|
|
117
|
+
return { r, g, b, a };
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Converts an "rgb(...)" or "rgba(...)" string to an RGBA object.
|
|
121
|
+
* @param color - The RGB(A) color string.
|
|
122
|
+
* @throws Error if the color format is invalid.
|
|
123
|
+
*/
|
|
124
|
+
static rgb_to_obj(color) {
|
|
125
|
+
if (!color.startsWith("rgba(") && !color.startsWith("rgb(")) {
|
|
126
|
+
throw new Error("Invalid color format");
|
|
127
|
+
}
|
|
128
|
+
const content = color.trim().split("(")[1].slice(0, -1);
|
|
129
|
+
const split = content.split(",");
|
|
130
|
+
return {
|
|
131
|
+
r: parseInt(split[0].trim()),
|
|
132
|
+
g: parseInt(split[1].trim()),
|
|
133
|
+
b: parseInt(split[2].trim()),
|
|
134
|
+
a: split[3] ? parseFloat(split[3].trim()) : 1,
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Converts RGBA values to a hex color string.
|
|
139
|
+
* @param r - Red channel value.
|
|
140
|
+
* @param g - Green channel value.
|
|
141
|
+
* @param b - Blue channel value.
|
|
142
|
+
* @param a - Alpha channel value (defaults to 1).
|
|
143
|
+
*/
|
|
144
|
+
static rgb_to_hex(r, g, b, a = 1) {
|
|
145
|
+
const hex_r = Math.round(r).toString(16).padStart(2, "0");
|
|
146
|
+
const hex_g = Math.round(g).toString(16).padStart(2, "0");
|
|
147
|
+
const hex_b = Math.round(b).toString(16).padStart(2, "0");
|
|
148
|
+
const hex_a = a === 1 ? "" : Math.round(a * 255).toString(16).padStart(2, "0");
|
|
149
|
+
return `#${hex_r}${hex_g}${hex_b}${hex_a}`;
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Converts RGBA values to an "rgb(...)" or "rgba(...)" string.
|
|
153
|
+
* @param r - Red channel.
|
|
154
|
+
* @param g - Green channel.
|
|
155
|
+
* @param b - Blue channel.
|
|
156
|
+
* @param a - Alpha channel (defaults to 1).
|
|
157
|
+
*/
|
|
158
|
+
static rgb_to_str(r, g, b, a = 1) {
|
|
159
|
+
if (a !== 1) {
|
|
160
|
+
return `rgba(${isNaN(r) ? 0 : r}, ${isNaN(g) ? 0 : g}, ${isNaN(b) ? 0 : b}, ${isNaN(a) ? 1 : a})`;
|
|
161
|
+
}
|
|
162
|
+
return `rgb(${isNaN(r) ? 0 : r}, ${isNaN(g) ? 0 : g}, ${isNaN(b) ? 0 : b})`;
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* Returns the hex string representation of this Color.
|
|
166
|
+
*/
|
|
167
|
+
to_hex() {
|
|
168
|
+
return Color.rgb_to_hex(this._rgba.r, this._rgba.g, this._rgba.b, this._rgba.a);
|
|
169
|
+
}
|
|
170
|
+
hex() {
|
|
171
|
+
return Color.rgb_to_hex(this._rgba.r, this._rgba.g, this._rgba.b, this._rgba.a);
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* Returns the RGB(A) string representation of this Color.
|
|
175
|
+
*/
|
|
176
|
+
str() {
|
|
177
|
+
return Color.rgb_to_str(this._rgba.r, this._rgba.g, this._rgba.b, this._rgba.a);
|
|
178
|
+
}
|
|
179
|
+
to_str() {
|
|
180
|
+
return Color.rgb_to_str(this._rgba.r, this._rgba.g, this._rgba.b, this._rgba.a);
|
|
181
|
+
}
|
|
182
|
+
to_rgb() {
|
|
183
|
+
return Color.rgb_to_str(this._rgba.r, this._rgba.g, this._rgba.b, this._rgba.a);
|
|
184
|
+
}
|
|
185
|
+
rgb() {
|
|
186
|
+
return Color.rgb_to_str(this._rgba.r, this._rgba.g, this._rgba.b, this._rgba.a);
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* Returns the brightness of the color.
|
|
190
|
+
* Uses the formula: (0.299*R + 0.587*G + 0.114*B) / 255.
|
|
191
|
+
* @returns A number between 0 (bright) and 1 (dark).
|
|
192
|
+
*/
|
|
193
|
+
get_brightness() {
|
|
194
|
+
return (0.299 * this._rgba.r + 0.587 * this._rgba.g + 0.114 * this._rgba.b) / 255;
|
|
195
|
+
}
|
|
196
|
+
/**
|
|
197
|
+
* Adjusts the brightness of the color by adding a constant to each RGB channel.
|
|
198
|
+
* @param adjust - The value to add (can be negative).
|
|
199
|
+
* @returns A new Color instance with modified brightness.
|
|
200
|
+
*/
|
|
201
|
+
adjust_brightness(adjust) {
|
|
202
|
+
const new_rgba = {
|
|
203
|
+
r: this._rgba.r + adjust,
|
|
204
|
+
g: this._rgba.g + adjust,
|
|
205
|
+
b: this._rgba.b + adjust,
|
|
206
|
+
a: this._rgba.a,
|
|
207
|
+
};
|
|
208
|
+
return new Color([new_rgba.r, new_rgba.g, new_rgba.b, new_rgba.a]);
|
|
209
|
+
}
|
|
210
|
+
/** Get opacity. */
|
|
211
|
+
get_opacity() {
|
|
212
|
+
return this._rgba.a;
|
|
213
|
+
}
|
|
214
|
+
/**
|
|
215
|
+
* Sets the opacity (alpha channel) of the color.
|
|
216
|
+
* @param opacity - A number between 0 and 1.
|
|
217
|
+
* @returns A new Color instance with the given opacity.
|
|
218
|
+
* @throws Error if the opacity is not within [0,1].
|
|
219
|
+
*/
|
|
220
|
+
opacity(opacity = 1.0) {
|
|
221
|
+
if (typeof opacity !== "number" || opacity < 0 || opacity > 1) {
|
|
222
|
+
throw new Error("Invalid opacity [0...1]: " + opacity + ".");
|
|
223
|
+
}
|
|
224
|
+
return new Color([this._rgba.r, this._rgba.g, this._rgba.b, opacity]);
|
|
225
|
+
}
|
|
226
|
+
/**
|
|
227
|
+
* Darkens the color by interpolating toward black.
|
|
228
|
+
* @param percent - The percentage to darken (between 0 and 1).
|
|
229
|
+
* @returns A new Color instance darkened by the specified percentage.
|
|
230
|
+
* @throws Error if the percentage is not within [0,1].
|
|
231
|
+
*/
|
|
232
|
+
darken(percent = 0.5) {
|
|
233
|
+
if (typeof percent !== "number" || percent < 0 || percent > 1) {
|
|
234
|
+
throw new Error("Invalid percentage [0...1]: " + percent + ".");
|
|
235
|
+
}
|
|
236
|
+
const new_rgba = {
|
|
237
|
+
r: Math.round(this._rgba.r * (1 - percent)),
|
|
238
|
+
g: Math.round(this._rgba.g * (1 - percent)),
|
|
239
|
+
b: Math.round(this._rgba.b * (1 - percent)),
|
|
240
|
+
a: this._rgba.a,
|
|
241
|
+
};
|
|
242
|
+
return new Color([new_rgba.r, new_rgba.g, new_rgba.b, new_rgba.a]);
|
|
243
|
+
}
|
|
244
|
+
/**
|
|
245
|
+
* Lightens the color by interpolating toward white.
|
|
246
|
+
* @param percent - The percentage to lighten (between 0 and 1).
|
|
247
|
+
* @returns A new Color instance lightened by the specified percentage.
|
|
248
|
+
* @throws Error if the percentage is not within [0,1].
|
|
249
|
+
*/
|
|
250
|
+
lighten(percent = 0.5) {
|
|
251
|
+
if (typeof percent !== "number" || percent < 0 || percent > 1) {
|
|
252
|
+
throw new Error("Invalid percentage [0...1]: " + percent + ".");
|
|
253
|
+
}
|
|
254
|
+
const new_rgba = {
|
|
255
|
+
r: Math.round(this._rgba.r + (255 - this._rgba.r) * percent),
|
|
256
|
+
g: Math.round(this._rgba.g + (255 - this._rgba.g) * percent),
|
|
257
|
+
b: Math.round(this._rgba.b + (255 - this._rgba.b) * percent),
|
|
258
|
+
a: this._rgba.a,
|
|
259
|
+
};
|
|
260
|
+
return new Color([new_rgba.r, new_rgba.g, new_rgba.b, new_rgba.a]);
|
|
261
|
+
}
|
|
262
|
+
/**
|
|
263
|
+
* Automatically darken when the color is bright or lighten when the color is dark.
|
|
264
|
+
*
|
|
265
|
+
* @param evaluation When the evaluation returns true the color will be darkened.
|
|
266
|
+
*/
|
|
267
|
+
auto_darken_lighten(percent = 0.5, evaluation = (b) => b > 0.5) {
|
|
268
|
+
if (evaluation(this.get_brightness())) {
|
|
269
|
+
return this.darken(percent);
|
|
270
|
+
}
|
|
271
|
+
else {
|
|
272
|
+
return this.lighten(percent);
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
/**
|
|
276
|
+
* Interpolates between this color and an end color.
|
|
277
|
+
* When percent is 0 the original color is returned, and when 1 the end color is returned.
|
|
278
|
+
* @param end - The target color (hex string, rgb(a) string, number array, or Color).
|
|
279
|
+
* @param percent - The interpolation factor (0 to 1).
|
|
280
|
+
* @param alpha - The resulting alpha value (0 to 1).
|
|
281
|
+
* @returns A new Color instance representing the interpolated color.
|
|
282
|
+
* @throws Error if percent or alpha are out of range.
|
|
283
|
+
*/
|
|
284
|
+
interpolate(end, percent = 0.5, alpha = 1.0) {
|
|
285
|
+
if (typeof percent !== "number" || percent < 0 || percent > 1) {
|
|
286
|
+
throw new Error("Invalid percentage [0...1]: " + percent + ".");
|
|
287
|
+
}
|
|
288
|
+
if (typeof alpha !== "number" || alpha < 0 || alpha > 1) {
|
|
289
|
+
throw new Error("Invalid alpha [0...1]: " + alpha + ".");
|
|
290
|
+
}
|
|
291
|
+
const end_color = end instanceof Color ? end : new Color(end);
|
|
292
|
+
const new_r = Math.round(this._rgba.r + (end_color._rgba.r - this._rgba.r) * percent);
|
|
293
|
+
const new_g = Math.round(this._rgba.g + (end_color._rgba.g - this._rgba.g) * percent);
|
|
294
|
+
const new_b = Math.round(this._rgba.b + (end_color._rgba.b - this._rgba.b) * percent);
|
|
295
|
+
return new Color([new_r, new_g, new_b, alpha]);
|
|
296
|
+
}
|
|
297
|
+
/**
|
|
298
|
+
* Returns the opposite (contrasting) color.
|
|
299
|
+
* Returns black ("#000000") if the color is bright, or white ("#ffffff") if it is dark.
|
|
300
|
+
* @returns A new Color instance that is either black or white.
|
|
301
|
+
*/
|
|
302
|
+
opposite() {
|
|
303
|
+
return this.get_brightness() > 0.5 ? new Color("#000000") : new Color("#ffffff");
|
|
304
|
+
}
|
|
305
|
+
static opposite_s(color) {
|
|
306
|
+
return new Color(color).opposite();
|
|
307
|
+
}
|
|
308
|
+
opposite_hex() {
|
|
309
|
+
return this.get_brightness() > 0.5 ? "#000000" : "#ffffff";
|
|
310
|
+
}
|
|
311
|
+
static opposite_hex_s(color) {
|
|
312
|
+
return new Color(color).opposite_hex();
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
export { Color as color }; // also export as lowercase for compatibility.
|
|
@@ -1,26 +1 @@
|
|
|
1
|
-
|
|
2
|
-
r: number;
|
|
3
|
-
g: number;
|
|
4
|
-
b: number;
|
|
5
|
-
a?: number;
|
|
6
|
-
}
|
|
7
|
-
type ColorObject = Record<'black' | 'red' | 'green' | 'yellow' | 'blue' | 'magenta' | 'cyan' | 'white', string>;
|
|
8
|
-
declare const Colors: any;
|
|
9
|
-
export { Colors };
|
|
10
|
-
type Hex = string;
|
|
11
|
-
type RGBArray = number[];
|
|
12
|
-
interface RGBObject {
|
|
13
|
-
r: number;
|
|
14
|
-
g: number;
|
|
15
|
-
b: number;
|
|
16
|
-
a: number;
|
|
17
|
-
}
|
|
18
|
-
export declare class ColorRangeClass {
|
|
19
|
-
start: RGBObject;
|
|
20
|
-
end: RGBObject;
|
|
21
|
-
constructor(start: Hex | RGBArray, end: Hex | RGBArray);
|
|
22
|
-
array_to_rgba(array: RGBArray): RGBObject;
|
|
23
|
-
interpolate(percent?: number, alpha?: number): Hex;
|
|
24
|
-
}
|
|
25
|
-
export declare const ColorRange: <Extensions extends object = {}>(start: string | RGBArray, end: string | RGBArray) => ColorRangeClass & Extensions;
|
|
26
|
-
export declare const NullColorRange: <Extensions extends object = {}>() => ColorRangeClass & Extensions;
|
|
1
|
+
/** @deprecated Use `Color` from modules/color.ts instead */
|