@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.
Files changed (290) hide show
  1. package/backend/dist/cjs/database.d.ts +41 -68
  2. package/backend/dist/cjs/database.js +136 -78
  3. package/backend/dist/cjs/endpoint.d.ts +23 -9
  4. package/backend/dist/cjs/endpoint.js +98 -21
  5. package/backend/dist/cjs/file_watcher.js +2 -2
  6. package/backend/dist/cjs/frontend.d.ts +0 -2
  7. package/backend/dist/cjs/frontend.js +9 -9
  8. package/backend/dist/cjs/image_endpoint.d.ts +3 -1
  9. package/backend/dist/cjs/image_endpoint.js +2 -1
  10. package/backend/dist/cjs/payments/paddle.js +10 -2
  11. package/backend/dist/cjs/plugins/css.d.ts +6 -5
  12. package/backend/dist/cjs/plugins/css.js +32 -7
  13. package/backend/dist/cjs/plugins/ts/compiler.d.ts +6 -1
  14. package/backend/dist/cjs/plugins/ts/compiler.js +26 -2
  15. package/backend/dist/cjs/plugins/ts/preprocessing.js +5 -3
  16. package/backend/dist/cjs/server.d.ts +7 -13
  17. package/backend/dist/cjs/server.js +184 -303
  18. package/backend/dist/cjs/status.d.ts +1 -0
  19. package/backend/dist/cjs/status.js +2 -1
  20. package/backend/dist/cjs/stream.d.ts +5 -3
  21. package/backend/dist/cjs/stream.js +13 -4
  22. package/backend/dist/cjs/users.d.ts +1 -1
  23. package/backend/dist/cjs/users.js +87 -72
  24. package/backend/dist/cjs/utils.d.ts +17 -9
  25. package/backend/dist/cjs/utils.js +22 -64
  26. package/backend/dist/cjs/view.d.ts +2 -2
  27. package/backend/dist/cjs/view.js +38 -40
  28. package/backend/dist/cjs/volt.d.ts +3 -2
  29. package/backend/dist/cjs/volt.js +2 -2
  30. package/backend/dist/css/volt.css +5 -0
  31. package/backend/dist/esm/database.d.ts +41 -68
  32. package/backend/dist/esm/database.js +137 -79
  33. package/backend/dist/esm/endpoint.d.ts +23 -9
  34. package/backend/dist/esm/endpoint.js +99 -22
  35. package/backend/dist/esm/file_watcher.js +2 -2
  36. package/backend/dist/esm/frontend.d.ts +0 -2
  37. package/backend/dist/esm/frontend.js +9 -9
  38. package/backend/dist/esm/image_endpoint.d.ts +3 -1
  39. package/backend/dist/esm/image_endpoint.js +2 -1
  40. package/backend/dist/esm/payments/paddle.js +11 -3
  41. package/backend/dist/esm/plugins/css.d.ts +6 -5
  42. package/backend/dist/esm/plugins/css.js +32 -6
  43. package/backend/dist/esm/plugins/ts/compiler.d.ts +6 -1
  44. package/backend/dist/esm/plugins/ts/compiler.js +26 -2
  45. package/backend/dist/esm/plugins/ts/preprocessing.js +5 -3
  46. package/backend/dist/esm/server.d.ts +7 -13
  47. package/backend/dist/esm/server.js +182 -301
  48. package/backend/dist/esm/status.d.ts +1 -0
  49. package/backend/dist/esm/status.js +1 -0
  50. package/backend/dist/esm/stream.d.ts +5 -3
  51. package/backend/dist/esm/stream.js +13 -4
  52. package/backend/dist/esm/users.d.ts +1 -1
  53. package/backend/dist/esm/users.js +87 -72
  54. package/backend/dist/esm/utils.d.ts +17 -9
  55. package/backend/dist/esm/utils.js +21 -62
  56. package/backend/dist/esm/view.d.ts +2 -2
  57. package/backend/dist/esm/view.js +38 -40
  58. package/backend/dist/esm/volt.d.ts +3 -2
  59. package/backend/dist/esm/volt.js +2 -1
  60. package/backend/dist/esm-dev/blacklist.js +1 -1
  61. package/backend/dist/esm-dev/cli.js +2 -2
  62. package/backend/dist/esm-dev/database.d.ts +41 -68
  63. package/backend/dist/esm-dev/database.js +138 -80
  64. package/backend/dist/esm-dev/endpoint.d.ts +23 -9
  65. package/backend/dist/esm-dev/endpoint.js +100 -23
  66. package/backend/dist/esm-dev/file_watcher.js +3 -3
  67. package/backend/dist/esm-dev/frontend.d.ts +0 -2
  68. package/backend/dist/esm-dev/frontend.js +9 -9
  69. package/backend/dist/esm-dev/image_endpoint.d.ts +3 -1
  70. package/backend/dist/esm-dev/image_endpoint.js +2 -1
  71. package/backend/dist/esm-dev/logger.js +1 -1
  72. package/backend/dist/esm-dev/payments/paddle.js +12 -4
  73. package/backend/dist/esm-dev/plugins/css.d.ts +6 -5
  74. package/backend/dist/esm-dev/plugins/css.js +33 -7
  75. package/backend/dist/esm-dev/plugins/ts/compiler.d.ts +6 -1
  76. package/backend/dist/esm-dev/plugins/ts/compiler.js +27 -3
  77. package/backend/dist/esm-dev/plugins/ts/preprocessing.js +7 -5
  78. package/backend/dist/esm-dev/rate_limit.js +1 -1
  79. package/backend/dist/esm-dev/server.d.ts +7 -13
  80. package/backend/dist/esm-dev/server.js +184 -303
  81. package/backend/dist/esm-dev/status.d.ts +1 -0
  82. package/backend/dist/esm-dev/status.js +1 -0
  83. package/backend/dist/esm-dev/stream.d.ts +5 -3
  84. package/backend/dist/esm-dev/stream.js +13 -4
  85. package/backend/dist/esm-dev/users.d.ts +1 -1
  86. package/backend/dist/esm-dev/users.js +88 -73
  87. package/backend/dist/esm-dev/utils.d.ts +17 -9
  88. package/backend/dist/esm-dev/utils.js +22 -63
  89. package/backend/dist/esm-dev/view.d.ts +2 -2
  90. package/backend/dist/esm-dev/view.js +39 -41
  91. package/backend/dist/esm-dev/volt.d.ts +3 -2
  92. package/backend/dist/esm-dev/volt.js +2 -1
  93. package/backend/src/database.ts +173 -155
  94. package/backend/src/endpoint.ts +123 -31
  95. package/backend/src/file_watcher.ts +2 -2
  96. package/backend/src/frontend.ts +9 -8
  97. package/backend/src/image_endpoint.ts +4 -0
  98. package/backend/src/payments/paddle.ts +11 -3
  99. package/backend/src/plugins/css.ts +36 -8
  100. package/backend/src/plugins/ts/compiler.ts +37 -1
  101. package/backend/src/plugins/ts/preprocessing.ts +5 -3
  102. package/backend/src/server.ts +167 -306
  103. package/backend/src/status.ts +1 -0
  104. package/backend/src/stream.ts +28 -8
  105. package/backend/src/users.ts +87 -72
  106. package/backend/src/utils.ts +58 -25
  107. package/backend/src/view.ts +30 -28
  108. package/backend/src/{volt.js → volt.ts} +2 -1
  109. package/backend/tsconfig.cjs.json +3 -3
  110. package/backend/tsconfig.esm.json +3 -3
  111. package/frontend/dist/elements/base.d.ts +414 -432
  112. package/frontend/dist/elements/base.js +566 -329
  113. package/frontend/dist/elements/module.d.ts +26 -12
  114. package/frontend/dist/elements/module.js +69 -32
  115. package/frontend/dist/elements/register_element.d.ts +3 -0
  116. package/frontend/dist/elements/register_element.js +22 -0
  117. package/frontend/dist/modules/auth.d.ts +1 -0
  118. package/frontend/dist/modules/auth.js +6 -5
  119. package/frontend/dist/modules/color.d.ts +159 -0
  120. package/frontend/dist/modules/color.js +315 -0
  121. package/frontend/dist/modules/colors.d.ts +1 -26
  122. package/frontend/dist/modules/colors.js +417 -340
  123. package/frontend/dist/modules/cookies.d.ts +1 -0
  124. package/frontend/dist/modules/cookies.js +1 -0
  125. package/frontend/dist/modules/events.d.ts +1 -0
  126. package/frontend/dist/modules/events.js +1 -0
  127. package/frontend/dist/modules/google.d.ts +1 -0
  128. package/frontend/dist/modules/google.js +1 -0
  129. package/frontend/dist/modules/meta.d.ts +1 -0
  130. package/frontend/dist/modules/meta.js +1 -0
  131. package/frontend/dist/modules/mutex.d.ts +1 -2
  132. package/frontend/dist/modules/mutex.js +3 -4
  133. package/frontend/dist/modules/paddle.d.ts +1 -0
  134. package/frontend/dist/modules/paddle.js +14 -13
  135. package/frontend/dist/modules/scheme.d.ts +1 -0
  136. package/frontend/dist/modules/scheme.js +5 -3
  137. package/frontend/dist/modules/statics.d.ts +1 -0
  138. package/frontend/dist/modules/statics.js +1 -0
  139. package/frontend/dist/modules/support.d.ts +1 -0
  140. package/frontend/dist/modules/support.js +3 -2
  141. package/frontend/dist/modules/theme.d.ts +56 -0
  142. package/frontend/dist/{ui → modules}/theme.js +186 -75
  143. package/frontend/dist/modules/themes.d.ts +1 -1
  144. package/frontend/dist/modules/themes.js +1 -0
  145. package/frontend/dist/modules/user.d.ts +1 -0
  146. package/frontend/dist/modules/user.js +11 -10
  147. package/frontend/dist/modules/utils.d.ts +23 -2
  148. package/frontend/dist/modules/utils.js +93 -1
  149. package/frontend/dist/types/gradient.js +4 -0
  150. package/frontend/dist/ui/border_button.d.ts +0 -25
  151. package/frontend/dist/ui/border_button.js +50 -51
  152. package/frontend/dist/ui/button.d.ts +0 -21
  153. package/frontend/dist/ui/button.js +41 -46
  154. package/frontend/dist/ui/canvas.js +15 -15
  155. package/frontend/dist/ui/checkbox.d.ts +3 -17
  156. package/frontend/dist/ui/checkbox.js +36 -30
  157. package/frontend/dist/ui/code.d.ts +15 -82
  158. package/frontend/dist/ui/code.js +150 -125
  159. package/frontend/dist/ui/color.d.ts +0 -1
  160. package/frontend/dist/ui/color.js +1 -1
  161. package/frontend/dist/ui/context_menu.d.ts +4 -2
  162. package/frontend/dist/ui/context_menu.js +16 -17
  163. package/frontend/dist/ui/css.js +2 -0
  164. package/frontend/dist/ui/divider.d.ts +0 -7
  165. package/frontend/dist/ui/divider.js +21 -25
  166. package/frontend/dist/ui/dropdown.d.ts +13 -7
  167. package/frontend/dist/ui/dropdown.js +65 -30
  168. package/frontend/dist/ui/for_each.d.ts +0 -5
  169. package/frontend/dist/ui/for_each.js +17 -22
  170. package/frontend/dist/ui/form.d.ts +17 -12
  171. package/frontend/dist/ui/form.js +21 -18
  172. package/frontend/dist/ui/frame_modes.d.ts +9 -12
  173. package/frontend/dist/ui/frame_modes.js +8 -10
  174. package/frontend/dist/ui/google_map.d.ts +0 -11
  175. package/frontend/dist/ui/google_map.js +23 -28
  176. package/frontend/dist/ui/gradient.d.ts +0 -5
  177. package/frontend/dist/ui/gradient.js +17 -22
  178. package/frontend/dist/ui/image.d.ts +27 -58
  179. package/frontend/dist/ui/image.js +99 -93
  180. package/frontend/dist/ui/input.d.ts +20 -97
  181. package/frontend/dist/ui/input.js +192 -170
  182. package/frontend/dist/ui/link.d.ts +0 -18
  183. package/frontend/dist/ui/link.js +42 -48
  184. package/frontend/dist/ui/list.js +36 -37
  185. package/frontend/dist/ui/loader_button.d.ts +4 -19
  186. package/frontend/dist/ui/loader_button.js +35 -37
  187. package/frontend/dist/ui/loaders.d.ts +0 -8
  188. package/frontend/dist/ui/loaders.js +20 -25
  189. package/frontend/dist/ui/popup.d.ts +11 -8
  190. package/frontend/dist/ui/popup.js +183 -24
  191. package/frontend/dist/ui/pseudo.d.ts +3 -3
  192. package/frontend/dist/ui/pseudo.js +14 -17
  193. package/frontend/dist/ui/scroller.d.ts +10 -48
  194. package/frontend/dist/ui/scroller.js +306 -300
  195. package/frontend/dist/ui/slider.d.ts +9 -3
  196. package/frontend/dist/ui/slider.js +31 -17
  197. package/frontend/dist/ui/spacer.d.ts +0 -9
  198. package/frontend/dist/ui/spacer.js +21 -26
  199. package/frontend/dist/ui/span.js +13 -15
  200. package/frontend/dist/ui/stack.d.ts +14 -75
  201. package/frontend/dist/ui/stack.js +166 -169
  202. package/frontend/dist/ui/steps.d.ts +10 -23
  203. package/frontend/dist/ui/steps.js +47 -34
  204. package/frontend/dist/ui/style.d.ts +4 -3
  205. package/frontend/dist/ui/style.js +13 -18
  206. package/frontend/dist/ui/switch.d.ts +10 -4
  207. package/frontend/dist/ui/switch.js +24 -16
  208. package/frontend/dist/ui/table.d.ts +0 -23
  209. package/frontend/dist/ui/table.js +113 -119
  210. package/frontend/dist/ui/tabs.d.ts +3 -19
  211. package/frontend/dist/ui/tabs.js +35 -29
  212. package/frontend/dist/ui/text.d.ts +0 -8
  213. package/frontend/dist/ui/text.js +20 -25
  214. package/frontend/dist/ui/title.d.ts +0 -15
  215. package/frontend/dist/ui/title.js +39 -45
  216. package/frontend/dist/ui/ui.d.ts +0 -2
  217. package/frontend/dist/ui/ui.js +0 -2
  218. package/frontend/dist/ui/view.d.ts +3 -17
  219. package/frontend/dist/ui/view.js +27 -32
  220. package/frontend/dist/volt.d.ts +2 -1
  221. package/frontend/dist/volt.js +3 -1
  222. package/frontend/examples/dashboard/dashboard.ts +774 -0
  223. package/frontend/examples/theme/theme.ts +58 -0
  224. package/frontend/src/css/volt.css +5 -0
  225. package/frontend/src/elements/base.ts +767 -545
  226. package/frontend/src/elements/module.ts +90 -29
  227. package/frontend/src/elements/register_element.ts +24 -0
  228. package/frontend/src/modules/auth.ts +7 -6
  229. package/frontend/src/modules/color.ts +348 -0
  230. package/frontend/src/modules/colors.ts +468 -449
  231. package/frontend/src/modules/cookies.ts +1 -0
  232. package/frontend/src/modules/events.ts +1 -0
  233. package/frontend/src/modules/google.ts +1 -0
  234. package/frontend/src/modules/meta.ts +2 -1
  235. package/frontend/src/modules/mutex.ts +2 -4
  236. package/frontend/src/modules/paddle.ts +21 -20
  237. package/frontend/src/modules/scheme.ts +5 -4
  238. package/frontend/src/modules/statics.ts +2 -1
  239. package/frontend/src/modules/support.ts +3 -2
  240. package/frontend/src/modules/theme.ts +413 -0
  241. package/frontend/src/modules/themes.ts +2 -1
  242. package/frontend/src/modules/user.ts +12 -11
  243. package/frontend/src/modules/utils.ts +125 -2
  244. package/frontend/src/ui/border_button.ts +41 -37
  245. package/frontend/src/ui/button.ts +33 -32
  246. package/frontend/src/ui/canvas.ts +5 -2
  247. package/frontend/src/ui/checkbox.ts +21 -22
  248. package/frontend/src/ui/code.ts +92 -86
  249. package/frontend/src/ui/context_menu.ts +7 -5
  250. package/frontend/src/ui/css.ts +1 -1
  251. package/frontend/src/ui/divider.ts +15 -10
  252. package/frontend/src/ui/dropdown.ts +38 -21
  253. package/frontend/src/ui/for_each.ts +9 -8
  254. package/frontend/src/ui/form.ts +26 -21
  255. package/frontend/src/ui/frame_modes.ts +13 -17
  256. package/frontend/src/ui/google_map.ts +15 -13
  257. package/frontend/src/ui/gradient.ts +9 -8
  258. package/frontend/src/ui/image.ts +108 -86
  259. package/frontend/src/ui/input.ts +145 -144
  260. package/frontend/src/ui/link.ts +25 -23
  261. package/frontend/src/ui/list.ts +12 -6
  262. package/frontend/src/ui/loader_button.ts +26 -25
  263. package/frontend/src/ui/loaders.ts +12 -11
  264. package/frontend/src/ui/popup.ts +168 -14
  265. package/frontend/src/ui/pseudo.ts +5 -3
  266. package/frontend/src/ui/scroller.ts +303 -294
  267. package/frontend/src/ui/slider.ts +15 -10
  268. package/frontend/src/ui/spacer.ts +14 -11
  269. package/frontend/src/ui/span.ts +6 -2
  270. package/frontend/src/ui/stack.ts +196 -183
  271. package/frontend/src/ui/steps.ts +38 -22
  272. package/frontend/src/ui/style.ts +7 -4
  273. package/frontend/src/ui/switch.ts +16 -11
  274. package/frontend/src/ui/table.ts +42 -34
  275. package/frontend/src/ui/tabs.ts +20 -19
  276. package/frontend/src/ui/text.ts +12 -11
  277. package/frontend/src/ui/title.ts +22 -20
  278. package/frontend/src/ui/ui.ts +0 -2
  279. package/frontend/src/ui/view.ts +20 -19
  280. package/frontend/src/volt.ts +3 -1
  281. package/frontend/{compile.js → tools/compile.old.js} +2 -2
  282. package/frontend/tools/embed_scripts.js +69 -0
  283. package/frontend/tsconfig.json +26 -0
  284. package/package.json +7 -6
  285. package/frontend/dist/ui/theme.d.ts +0 -25
  286. package/frontend/exports.json +0 -1340
  287. package/frontend/src/modules/date.js +0 -535
  288. package/frontend/src/ui/color.ts +0 -117
  289. package/frontend/src/ui/theme.ts +0 -279
  290. /package/backend/src/{vinc.dev.js → vinc.dev.ts} +0 -0
@@ -3,9 +3,9 @@
3
3
  * Copyright: © 2022 - 2024 Daan van den Bergh.
4
4
  */
5
5
  // Imports.
6
- import { Elements } from "../elements/module.js";
7
- import { Colors } from "../modules/colors";
8
- import { Themes as ThemesModule } from "../modules/themes";
6
+ import { Color } from "./color.js";
7
+ import { Themes as ThemesModule } from "./themes.js";
8
+ const ThemeIdList = ["dark", "light"];
9
9
  // Themes class.
10
10
  /* @docs:
11
11
  @nav: Frontend
@@ -29,12 +29,17 @@ import { Themes as ThemesModule } from "../modules/themes";
29
29
  When theme attributes are retrieved, by default they will be the active theme's attribute as a css variable. So this can be passed to an element.
30
30
  However, some element functions do not accept css variables, in this case the `value()` function can be used to retrieve the raw value. Do not forget to apply an `on_theme_update()` callback on the elements where you use this.
31
31
  */
32
- export class ThemeClass {
33
- constructor(id, themes = {}) {
32
+ export class Theme {
33
+ // helper: union of all keys across all themes
34
+ // Attributes.
35
+ active_id;
36
+ active;
37
+ _attrs;
38
+ _css_vars;
39
+ _id;
40
+ _on_activate_callback;
41
+ constructor(id, themes) {
34
42
  // Attributes.
35
- this.active_id = undefined;
36
- this.active = undefined;
37
- this._theme_ids = [];
38
43
  this._attrs = [];
39
44
  this._css_vars = {};
40
45
  this._id = id;
@@ -42,7 +47,6 @@ export class ThemeClass {
42
47
  Object.keys(themes).iterate((theme) => {
43
48
  // Initialize.
44
49
  const theme_style = themes[theme];
45
- this._theme_ids.append(theme);
46
50
  this[theme] = theme_style;
47
51
  // Activate first theme.
48
52
  if (this.active_id === undefined) {
@@ -57,7 +61,68 @@ export class ThemeClass {
57
61
  this._add_attr(id, theme);
58
62
  });
59
63
  });
64
+ // Ensure type.
65
+ if (this.active_id == null || this.active == null) {
66
+ throw new Error("No themes were specified in parameter \"themes\".");
67
+ }
68
+ }
69
+ /**
70
+ * Initialize a specific theme.
71
+ * @note This function should be called after the constructor to ensure the most recent theme is activated, argument "id" can be left undefined.
72
+ */
73
+ initialize(id) {
74
+ if (id == null) {
75
+ id = (localStorage.getItem(this._id) ?? undefined);
76
+ }
77
+ if (id != null && ThemeIdList.includes(id)) {
78
+ this.activate(id);
79
+ }
80
+ return this;
81
+ }
82
+ // ---------------------------------------------------------------------
83
+ // Theme selection methods.
84
+ /** Get full active theme id. */
85
+ get id() {
86
+ return `${this._id}.${String(this.active_id)}`;
87
+ }
88
+ // Get cached active subtheme id.
89
+ get_active_id_cached() {
90
+ return localStorage.getItem(this._id) ?? "";
91
+ }
92
+ // Activate a theme.
93
+ activate(id, apply_theme_update = true) {
94
+ if (ThemeIdList.includes(id) === false || this[id] === undefined) {
95
+ throw Error(`Theme "${id}" does not exist.`);
96
+ }
97
+ this.active_id = id;
98
+ this.active = this[id];
99
+ Object.keys(this.active).iterate((id) => {
100
+ document.documentElement.style.setProperty(`--${this._id}_${id}`, this.active[id] ?? "");
101
+ });
102
+ if (this._on_activate_callback != null) {
103
+ this._on_activate_callback(this, this.active_id);
104
+ }
105
+ if (apply_theme_update) {
106
+ ThemesModule.apply_theme_update();
107
+ }
108
+ localStorage.setItem(this._id, String(this.active_id));
109
+ return this;
110
+ }
111
+ on_activate(callback) {
112
+ if (callback == null) {
113
+ return this._on_activate_callback;
114
+ }
115
+ this._on_activate_callback = callback;
116
+ return this;
60
117
  }
118
+ // Toggle themes.
119
+ toggle(apply_theme_update = true) {
120
+ const other = this.active_id === "dark" ? "light" : "dark";
121
+ this.activate(other, apply_theme_update);
122
+ return this;
123
+ }
124
+ // ---------------------------------------------------------------------
125
+ // Adding values.
61
126
  // Add a new attribute.
62
127
  _add_attr(id, theme) {
63
128
  if (theme == null) {
@@ -112,18 +177,8 @@ export class ThemeClass {
112
177
  // Response.
113
178
  return this;
114
179
  }
115
- get id() {
116
- return `${this._id}.${this.active_id}`;
117
- }
118
- // Initialize by cached.
119
- initialize(id) {
120
- if (id == null) {
121
- id = localStorage.getItem(this._id) ?? undefined;
122
- }
123
- if (id != null && this._theme_ids.includes(id)) {
124
- this.activate(id);
125
- }
126
- return this;
180
+ get raw() {
181
+ return this.active;
127
182
  }
128
183
  // Get raw value.
129
184
  value(id) {
@@ -132,16 +187,65 @@ export class ThemeClass {
132
187
  }
133
188
  return this.active[id];
134
189
  }
190
+ // ---------------------------------------------------------------------
191
+ // Color manipulation methods.
192
+ // Create a new color for each theme.
193
+ create(id, create_theme_value) {
194
+ // Already created.
195
+ if (this._css_vars[id]) {
196
+ throw new Error(`Color "${id}" already exists.`);
197
+ }
198
+ // Iterate.
199
+ let index = 0;
200
+ for (const theme_id of ThemeIdList) {
201
+ const theme = this[theme_id];
202
+ const value = create_theme_value(theme_id, theme);
203
+ theme[id] = value;
204
+ // Add attribute to document on first call.
205
+ if (index === 0) {
206
+ this._add_attr(id);
207
+ }
208
+ // Set property.
209
+ if (this.active_id === theme_id) {
210
+ document.documentElement.style.setProperty(`--${this._id}_${id}`, theme[id]);
211
+ }
212
+ // Incr index
213
+ ++index;
214
+ }
215
+ }
216
+ /**
217
+ * Auto darken lighten a color from the theme
218
+ * Safe to call multiple times, caching is implemented.
219
+ *
220
+ * @warning The input color must be a hex / rgb(a) string.
221
+ * @param theme_attr The name of the original theme color.
222
+ * @param percent Percentage between 0. and 1.0.
223
+ */
224
+ auto_darken_lighten(theme_attr, percent = 0.5, reversed = false) {
225
+ let full_id = `${String(theme_attr)}_adl_${percent}`;
226
+ full_id = full_id.replaceAll(".", "_");
227
+ if (this._css_vars[full_id]) {
228
+ return this._css_vars[full_id];
229
+ }
230
+ const process = reversed === true ? (x => x < 0.5) : (x => x > 0.5);
231
+ this.create(full_id, (theme_id, theme) => {
232
+ if (!theme[theme_attr]) {
233
+ throw new Error(`Theme attribute "${String(theme_attr)}" does not exist.`);
234
+ }
235
+ return new Color(theme[theme_attr]).auto_darken_lighten(percent, process).str();
236
+ });
237
+ return this._css_vars[full_id];
238
+ }
135
239
  // Opacity.
136
240
  // Opacity must be a number `0.0` till `1.0`, and may also be an object with opacity pet theme `{dark: 0.2, light: 0.35}`.
137
- opacity(id, opacity = 1.0) {
241
+ opacity(theme_attr, opacity = 1.0) {
138
242
  // Create full id.
139
243
  let full_id;
140
244
  if (typeof opacity === "number") {
141
- full_id = `${id}_opac_${opacity}`;
245
+ full_id = `${String(theme_attr)}_opac_${opacity}`;
142
246
  }
143
247
  else {
144
- full_id = `${id}_opac_${Object.values(opacity).join("_")}`;
248
+ full_id = `${String(theme_attr)}_opac_${Object.values(opacity).join("_")}`;
145
249
  }
146
250
  full_id = full_id.replaceAll(".", "_");
147
251
  // Already created.
@@ -150,26 +254,26 @@ export class ThemeClass {
150
254
  }
151
255
  // Iterate.
152
256
  let index = 0;
153
- for (const theme_id of this._theme_ids) {
257
+ for (const theme_id of ThemeIdList) {
154
258
  const theme = this[theme_id];
155
259
  // Checks.
156
- if (theme[id] == null) {
157
- console.error(new Error(`Theme attribute "${id}" does not exist.`));
260
+ if (theme[theme_attr] == null) {
261
+ console.error(new Error(`Theme attribute "${String(theme_attr)}" does not exist.`));
158
262
  return "";
159
263
  }
160
- if (theme[id]._is_gradient) {
161
- console.error(new Error(`Unable to set the opacity on gradient color "${id}".`));
264
+ if (theme[theme_attr]._is_gradient) {
265
+ console.error(new Error(`Unable to set the opacity on gradient color "${String(theme_attr)}".`));
162
266
  return "";
163
267
  }
164
268
  // Create new color.
165
269
  let theme_opac = opacity;
166
270
  if (typeof theme_opac === "object") {
167
- theme_opac = theme_opac[this._theme_ids[index]];
271
+ theme_opac = theme_opac[theme_attr];
168
272
  if (theme_opac === undefined) {
169
- console.error(new Error(`Unable to find the opacity on for theme id "${this._theme_ids[index]}".`));
273
+ console.error(new Error(`Unable to find the opacity on for theme id "${theme_attr}".`));
170
274
  }
171
275
  }
172
- theme[full_id] = Colors.set_opacity(theme[id], theme_opac);
276
+ theme[full_id] = new Color(theme[theme_attr]).opacity(theme_opac).rgb();
173
277
  // Add css var.
174
278
  if (index === 0) {
175
279
  this._add_attr(full_id);
@@ -183,55 +287,62 @@ export class ThemeClass {
183
287
  }
184
288
  return this._css_vars[full_id];
185
289
  }
186
- // Activate a theme.
187
- activate(id, apply_theme_update = true) {
188
- if (this._theme_ids.includes(id) === false || this[id] === undefined) {
189
- throw Error(`Theme "${id}" does not exist.`);
290
+ // ---------------------------------------------------------------------
291
+ // Font size manipulation methods.
292
+ /**
293
+ * Create a new value by multiplying a numeric attribute.
294
+ * @warning argument `id` should be the name of a numeric theme attribute.
295
+ * @param theme_attr The name of a numeric attribute
296
+ * @param x The number by which to multiply the attribute, `attribute * x`.
297
+ */
298
+ multiply(theme_attr, x = 1.0) {
299
+ let full_id = `${String(theme_attr)}_fsr_${x}`;
300
+ full_id = full_id.replaceAll(".", "_");
301
+ if (this._css_vars[full_id]) {
302
+ return this._css_vars[full_id];
190
303
  }
191
- this.active_id = id;
192
- this.active = this[id];
193
- Object.keys(this.active).iterate((id) => {
194
- document.documentElement.style.setProperty(`--${this._id}_${id}`, this.active[id] ?? "");
304
+ const process = (x => x < 0.5);
305
+ this.create(full_id, (_, theme) => {
306
+ if (!theme[theme_attr]) {
307
+ throw new Error(`Theme attribute "${String(theme_attr)}" does not exist.`);
308
+ }
309
+ if (typeof theme[theme_attr] !== "number") {
310
+ throw new Error(`Theme attribute "${String(theme_attr)}" is not a number.`);
311
+ }
312
+ return theme[theme_attr] * x;
195
313
  });
196
- if (this._on_activate_callback != null) {
197
- this._on_activate_callback(this, this.active_id);
198
- }
199
- if (apply_theme_update) {
200
- ThemesModule.apply_theme_update();
201
- }
202
- localStorage.setItem(this._id, this.active_id);
203
- return this;
314
+ return this._css_vars[full_id];
204
315
  }
205
- on_activate(callback) {
206
- if (callback == null) {
207
- return this._on_activate_callback;
208
- }
209
- this._on_activate_callback = callback;
316
+ // ---------------------------------------------------------------------
317
+ // Animation methods.
318
+ /** Function to disable all transition attributes on all elements. */
319
+ disable_transitions() {
320
+ // const style = document.createElement('style');
321
+ // style.id = '__libris_thme_disable_transitions__';
322
+ // style.innerHTML = `
323
+ // * { transition: none !important; }
324
+ // *::after { transition: none !important; }
325
+ // *::before { transition: none !important; }
326
+ // `.dedent();
327
+ // document.head.appendChild(style);
328
+ document.body.classList.add("notransition");
329
+ // Force a reflow to apply the new styles immediately
330
+ // document.head.getBoundingClientRect();
331
+ void document.body.offsetHeight;
210
332
  return this;
211
333
  }
212
- // Get cached active subtheme id.
213
- get_active_id_cached() {
214
- return localStorage.getItem(this._id) ?? "";
215
- }
216
- // Toggle themes.
217
- toggle(apply_theme_update = true) {
218
- if (this._theme_ids.length > 1) {
219
- let active_index = -1;
220
- for (let i = 0; i < this._theme_ids.length; i++) {
221
- if (this._theme_ids[i] === this.active_id) {
222
- active_index = i;
223
- break;
224
- }
225
- }
226
- if (active_index !== -1 && active_index + 1 < this._theme_ids.length) {
227
- this.activate(this._theme_ids[active_index + 1], apply_theme_update);
228
- }
229
- else {
230
- this.activate(this._theme_ids[0], apply_theme_update);
231
- }
334
+ /** Function to re-enable all transition attributes on all elements. */
335
+ enable_transitions(delay = 0) {
336
+ if (delay > 0) {
337
+ setTimeout(() => this.enable_transitions(0), delay);
338
+ return this;
232
339
  }
340
+ document.body.classList.remove("notransition");
341
+ // const style = document.getElementById('__libris_thme_disable_transitions__');
342
+ // if (style) {
343
+ // style.remove();
344
+ // }
345
+ document.head.getBoundingClientRect();
233
346
  return this;
234
347
  }
235
348
  }
236
- export const Theme = Elements.wrapper(ThemeClass);
237
- export const NullTheme = Elements.create_null(ThemeClass); //@todo duplicate name from Themes
@@ -5,4 +5,4 @@ export declare const Themes: {
5
5
  theme_elements: ThemeElement[];
6
6
  apply_theme_update(): void;
7
7
  };
8
- export {};
8
+ export { Themes as themes };
@@ -15,3 +15,4 @@ export const Themes = {
15
15
  });
16
16
  }
17
17
  };
18
+ export { Themes as themes }; // also export as lowercase for compatibility.
@@ -56,3 +56,4 @@ export declare namespace User {
56
56
  function save(path?: string, data?: Record<string, any>): Promise<any>;
57
57
  function load_protected(path: string, def?: string): Promise<any>;
58
58
  }
59
+ export { User as user };
@@ -110,7 +110,7 @@ export var User;
110
110
  * @type: boolean
111
111
  */
112
112
  async function get() {
113
- return Utils.request({
113
+ return Utils.request_v1({
114
114
  method: "GET",
115
115
  url: "/volt/user/",
116
116
  data: {
@@ -128,7 +128,7 @@ export var User;
128
128
  * @return: Returns a promise with a successful update response or a request error on a failed request.
129
129
  */
130
130
  async function set(user) {
131
- return Utils.request({
131
+ return Utils.request_v1({
132
132
  method: "POST",
133
133
  url: "/volt/user/",
134
134
  data: user,
@@ -144,7 +144,7 @@ export var User;
144
144
  * @return: Returns a promise with a successful update response or a request error on a failed request.
145
145
  */
146
146
  async function activate(code = "") {
147
- return Utils.request({
147
+ return Utils.request_v1({
148
148
  method: "POST",
149
149
  url: "/volt/auth/activate",
150
150
  data: {
@@ -162,7 +162,7 @@ export var User;
162
162
  * @return: Returns a promise with a successful update response or a request error on a failed request.
163
163
  */
164
164
  async function change_password({ current_password = "", password = "", verify_password = "", }) {
165
- return Utils.request({
165
+ return Utils.request_v1({
166
166
  method: "POST",
167
167
  url: "/volt/user/change_password",
168
168
  data: {
@@ -182,7 +182,7 @@ export var User;
182
182
  * @return: Returns a promise with a successful update response or a request error on a failed request.
183
183
  */
184
184
  async function delete_account() {
185
- return Utils.request({
185
+ return Utils.request_v1({
186
186
  method: "DELETE",
187
187
  url: "/volt/user",
188
188
  });
@@ -197,7 +197,7 @@ export var User;
197
197
  * @return: Returns a promise with a successful update response with the newly generated API key as an attribute or a request error on a failed request.
198
198
  */
199
199
  async function generate_api_key() {
200
- return Utils.request({
200
+ return Utils.request_v1({
201
201
  method: "POST",
202
202
  url: "/volt/user/api_key",
203
203
  });
@@ -212,7 +212,7 @@ export var User;
212
212
  * @return: Returns a promise with a successful update response or a request error on a failed request.
213
213
  */
214
214
  async function revoke_api_key() {
215
- return Utils.request({
215
+ return Utils.request_v1({
216
216
  method: "DELETE",
217
217
  url: "/volt/user/api_key",
218
218
  });
@@ -227,7 +227,7 @@ export var User;
227
227
  * @return: Returns a promise with the loaded user's data or a request error on a failed request.
228
228
  */
229
229
  async function load(path, def = "") {
230
- return Utils.request({
230
+ return Utils.request_v1({
231
231
  method: "GET",
232
232
  url: "/volt/user/data",
233
233
  data: {
@@ -246,7 +246,7 @@ export var User;
246
246
  * @return: Returns a promise with a successful update response or a request error on a failed request.
247
247
  */
248
248
  async function save(path = "", data = {}) {
249
- return Utils.request({
249
+ return Utils.request_v1({
250
250
  method: "POST",
251
251
  url: "/volt/user/data",
252
252
  data: {
@@ -265,7 +265,7 @@ export var User;
265
265
  * @return: Returns a promise with the loaded user's data or a request error on a failed request.
266
266
  */
267
267
  async function load_protected(path, def = "") {
268
- return Utils.request({
268
+ return Utils.request_v1({
269
269
  method: "GET",
270
270
  url: "/volt/user/data/protected",
271
271
  data: {
@@ -277,3 +277,4 @@ export var User;
277
277
  User.load_protected = load_protected;
278
278
  })(User || (User = {}));
279
279
  ;
280
+ export { User as user }; // also export as lowercase for compatibility.
@@ -1,3 +1,4 @@
1
+ import { AnyElement } from "../ui/any_element";
1
2
  declare const Utils: {
2
3
  is_apple: boolean;
3
4
  is_safari: boolean;
@@ -30,7 +31,26 @@ declare const Utils: {
30
31
  a: number;
31
32
  };
32
33
  deep_copy(obj: any): any;
33
- request(options: {
34
+ /** New request method. */
35
+ request<Data = any>(options: {
36
+ method?: string;
37
+ url?: string | null;
38
+ data?: any;
39
+ json?: boolean;
40
+ credentials?: RequestCredentials;
41
+ headers?: Record<string, string>;
42
+ }): Promise<{
43
+ error?: {
44
+ message: string;
45
+ type?: string;
46
+ invalid_fields?: {
47
+ [name: string]: string;
48
+ };
49
+ };
50
+ status: number;
51
+ data?: Data;
52
+ }>;
53
+ request_v1(options: {
34
54
  method?: string;
35
55
  url?: string | null;
36
56
  data?: any;
@@ -38,7 +58,7 @@ declare const Utils: {
38
58
  credentials?: "include" | "same-origin" | "omit";
39
59
  headers?: Record<string, string>;
40
60
  }): Promise<any>;
41
- on_load(func: () => HTMLElement | Promise<HTMLElement> | null): Promise<void>;
61
+ on_load(func: () => HTMLElement | AnyElement | Promise<HTMLElement | AnyElement> | null | undefined): Promise<void>;
42
62
  unix_to_date(unix: number, mseconds?: boolean | null): string;
43
63
  fuzzy_search({ query, targets, limit, case_match, allow_exceeding_chars, get_matches, key, nested_key, }: {
44
64
  query: string;
@@ -56,3 +76,4 @@ declare const Utils: {
56
76
  on_resize_observer: ResizeObserver;
57
77
  };
58
78
  export { Utils };
79
+ export { Utils as utils };
@@ -524,6 +524,97 @@ const Utils = {
524
524
  return obj;
525
525
  }
526
526
  },
527
+ /** New request method. */
528
+ async request(options) {
529
+ const { method = 'GET', url = null, data = null, json = true, credentials = "same-origin", headers = {}, } = options;
530
+ // — prepare headers —
531
+ if (json && data != null && !headers['Content-Type']) {
532
+ headers['Content-Type'] = 'application/json';
533
+ }
534
+ // — build URL + body —
535
+ let finalUrl = url;
536
+ let body;
537
+ if (data != null && typeof data === 'object') {
538
+ if (method.toUpperCase() === 'GET') {
539
+ finalUrl = `${url}?${new URLSearchParams(data).toString()}`;
540
+ }
541
+ else {
542
+ body = JSON.stringify(data);
543
+ }
544
+ }
545
+ else if (data != null) {
546
+ body = String(data);
547
+ }
548
+ const init = { method, credentials, headers };
549
+ if (body !== undefined)
550
+ init.body = body;
551
+ try {
552
+ const response = await fetch(finalUrl, init);
553
+ const status = response.status;
554
+ // — parse payload once —
555
+ let payload;
556
+ const clone = response.clone(); // @dev.
557
+ if (json) {
558
+ try {
559
+ payload = await response.json();
560
+ }
561
+ catch (e) {
562
+ // malformed JSON still counts as a “success” fetch
563
+ console.log("[debug] Unable to parse a json from response:", await clone.text(), "- Error: ", JSON.stringify(e, null, 4));
564
+ console.log("rsponse:", response);
565
+ return {
566
+ status,
567
+ error: { message: `Failed to parse JSON response: ${e.message}` },
568
+ };
569
+ }
570
+ }
571
+ else {
572
+ try {
573
+ payload = await response.text();
574
+ }
575
+ catch (e) {
576
+ return {
577
+ status,
578
+ error: { message: `Failed to parse text response: ${e.message}` },
579
+ };
580
+ }
581
+ }
582
+ console.log("Payload", json, payload);
583
+ // — handle HTTP errors (4xx/5xx) by resolving with an error object —
584
+ if (!response.ok) {
585
+ // if server wrapped its error in { error: { message, type?, invalid_fields? }, … }
586
+ if (payload &&
587
+ typeof payload === 'object' &&
588
+ typeof payload.error === 'object' &&
589
+ typeof payload.error.message === 'string') {
590
+ return {
591
+ status,
592
+ error: {
593
+ message: payload.error.message,
594
+ type: payload.error.type,
595
+ invalid_fields: payload.error.invalid_fields,
596
+ },
597
+ data: payload.data,
598
+ };
599
+ }
600
+ // otherwise fall back to a generic single‐message error
601
+ const msg = typeof payload === 'string'
602
+ ? payload
603
+ : payload?.error?.toString() ?? JSON.stringify(payload);
604
+ return {
605
+ status,
606
+ error: { message: msg },
607
+ };
608
+ }
609
+ // — 2xx: success —
610
+ return { status, data: payload };
611
+ }
612
+ catch (networkErr) {
613
+ // genuine network / system failure
614
+ throw networkErr;
615
+ }
616
+ },
617
+ // @deprecated.
527
618
  /* @docs:
528
619
  @nav: Frontend
529
620
  @chapter: Utils
@@ -544,7 +635,7 @@ const Utils = {
544
635
  @desc: A Promise that resolves with the response data.
545
636
  @type: Promise<any>
546
637
  */
547
- request(options) {
638
+ request_v1(options) {
548
639
  const { method = "GET", url = null, data = null, json = true, credentials = "same-origin", headers = {}, } = options;
549
640
  // Set headers.
550
641
  // Host and User-Agent headers are restricted and set by the browser itself.
@@ -1157,3 +1248,4 @@ const Utils = {
1157
1248
  };
1158
1249
  // Export.
1159
1250
  export { Utils };
1251
+ export { Utils as utils }; // also export as lowercase for compatibility.
@@ -20,6 +20,10 @@
20
20
  * Or the arguments can be as `new GradientType("linear", "black", "0%", "white", "100%")`.
21
21
  */
22
22
  export class GradientType {
23
+ gradient;
24
+ type;
25
+ degree;
26
+ colors;
23
27
  constructor(...args) {
24
28
  if (args.length === 1) {
25
29
  this.gradient = args[0];
@@ -4,31 +4,6 @@ import { VDivElement, VElementTagMap } from "../elements/module.js";
4
4
  * Warning: this class is still experimental and may be subject to future change.
5
5
  */
6
6
  export declare class BorderButtonElement extends VElementTagMap.a {
7
- static default_style: {
8
- margin: string;
9
- display: string;
10
- color: string;
11
- "text-align": string;
12
- cursor: string;
13
- position: string;
14
- "z-index": string;
15
- background: string;
16
- "user-select": string;
17
- outline: string;
18
- border: string;
19
- "text-decoration": string;
20
- "--child-color": string;
21
- "--child-background": string;
22
- "--child-border-width": string;
23
- "--child-border-radius": string;
24
- "--child-padding": string;
25
- };
26
- static default_events: {
27
- onmousedown: (this: any) => void;
28
- onmouseover: (this: any) => void;
29
- onmouseup: (this: any) => void;
30
- onmouseout: (this: any) => void;
31
- };
32
7
  nodes: {
33
8
  border: VDivElement;
34
9
  text: VDivElement;