@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
@@ -11,8 +11,12 @@ import {
11
11
  wrapper as _wrapper,
12
12
  create_null as _create_null,
13
13
  } from "./base.js"
14
+ import { register_element as _register_element } from "./register_element.js";
14
15
 
16
+ // Elements module.
15
17
  export namespace Elements {
18
+
19
+ export const register_element = _register_element;
16
20
 
17
21
  // Get by id.
18
22
  // @note: always use VElement as return type since this is most likely the case and avoids type casting for users.
@@ -67,39 +71,96 @@ export namespace Elements {
67
71
  }
68
72
  }
69
73
 
70
- // Register a custom type.
71
- /* @docs:
72
- @nav: Frontend
73
- @chapter: Elements
74
- @title: Register Custom Type
75
- @desc: Registers a custom element type.
76
- @param:
77
- @name: type
78
- @description The custom element type (class).
79
- @param:
80
- @name: tag
81
- @description Optional tag name to extend.
82
- */
83
- export function register_type(type: any, tag?: string): void {
84
- (type as any)._is_registered = true;
85
- // customElements.define(type.name, type, { extends: tag || (type as any).element_tag });
86
- customElements.define("v-" + type.name.toLowerCase(), type, { extends: tag || (type as any).element_tag });
74
+ // Create a new element class.
75
+ type Constructor<T = any> = new (...args: any[]) => T;
76
+ interface CreateOpts {
77
+ name: string; // The name to use for this element (will become the “v-…” tag)
78
+ tag?: string; // Optional host tag to extend (defaults to constructor.tag if set)
79
+ default_style?: Record<string, any>;
80
+ default_attributes?: Record<string, any>;
81
+ default_events?: Record<string, any>;
87
82
  }
83
+
84
+ /**
85
+ * Class decorator factory.
86
+ * @example
87
+ * @create({ name: "Foo", tag?: "section", base: HTMLElement })
88
+ * class Foo extends HTMLElement { … }
89
+ */
90
+ export function create(opts: CreateOpts): <T extends Constructor>(constructor: T) => T {
91
+
92
+ // Validate required options at factory time
93
+ if (typeof opts.name !== "string" || opts.name.trim() === "") {
94
+ throw new Error(`@Elements.create requires a non-empty string “name”`);
95
+ }
88
96
 
89
- // Register decorator.
90
- /* @docs:
91
- @nav: Frontend
92
- @chapter: Elements
93
- @title: Register Decorator
94
- @desc: Registers a class as a custom element.
95
- @param:
96
- @name: constructor
97
- @description The class constructor to register.
98
- */
99
- export function register<T extends { new(...args: any[]): {} }>(constructor: T): void {
100
- Elements.register_type(constructor);
97
+ // Factory function
98
+ return function <T extends Constructor>(constructor: T): T {
99
+ const any_ctor = constructor as any;
100
+
101
+ // Define readonly static attributes.
102
+ any_ctor.element_name = opts.name;
103
+ // Object.defineProperty(any_ctor, "element_name", { value: opts.name, writable: false, enumerable: true, configurable: false });
104
+ if (opts.tag != null) {
105
+ any_ctor.element_tag = opts.tag;
106
+ // Object.defineProperty(any_ctor, "element_tag", { value: opts.tag, writable: false, enumerable: true, configurable: false });
107
+ }
108
+ if (opts.default_style != null) {
109
+ any_ctor.default_style = opts.default_style;
110
+ // Object.defineProperty(any_ctor, "default_style", { value: opts.default_style, writable: false, enumerable: true, configurable: false });
111
+ }
112
+ if (opts.default_attributes != null) {
113
+ any_ctor.default_attributes = opts.default_attributes;
114
+ // Object.defineProperty(any_ctor, "default_attributes", { value: opts.default_attributes, writable: false, enumerable: true, configurable: false });
115
+ }
116
+ if (opts.default_events != null) {
117
+ any_ctor.default_events = opts.default_events;
118
+ // Object.defineProperty(any_ctor, "default_events", { value: opts.default_events, writable: false, enumerable: true, configurable: false });
119
+ }
120
+
121
+ // Register custom element exactly once
122
+ _register_element(constructor)
123
+
124
+ return constructor;
125
+ };
101
126
  }
102
127
 
128
+ // export function create<T extends { new(...args: any[]): {} }>(constructor: T): void {
129
+ // const any_con = constructor as any;
130
+
131
+ // // Register new html element.
132
+ // if (!any_con._volt_is_registered) {
133
+ // console.log({ type: constructor })
134
+ // if (!any_con.element_name) {
135
+ // throw new Error(`Static element attribute '${any_con.name}.element_name' should always be defined, create static attribute \"element_name: string\" and assign the name of the class to this attribute.`)
136
+ // }
137
+
138
+ // const name = any_con.element_name || any_con.name;
139
+
140
+ // let new_xml_name = "", count = 0;
141
+ // do {
142
+ // new_xml_name = "v-" + name.toLowerCase() + (count > 0 ? "-" + count : "");
143
+ // } while (registered_type_names.has(new_xml_name) && ++count);
144
+ // registered_type_names.add(new_xml_name);
145
+
146
+ // const ext = tag || any_con.element_tag;
147
+
148
+ // // @debug
149
+ // console.log("Registering custom element: ", {
150
+ // name,
151
+ // type: constructor,
152
+ // new_xml_name,
153
+ // extends: ext,
154
+ // element_name: any_con.element_name,
155
+ // });
156
+
157
+ // any_con._volt_is_registered = true;
158
+
159
+ // // customElements.define(type.name, type, { extends: tag || (type as any).element_tag });
160
+ // customElements.define(new_xml_name, any_con, { extends: ext });
161
+ // }
162
+ // }
163
+
103
164
  // Create a constructor wrapper.
104
165
  export const wrapper = _wrapper;
105
166
 
@@ -0,0 +1,24 @@
1
+ /** Separate file for register_element() method to prevent recursive imports from base.ts and module.ts */
2
+
3
+ export const registered_names = new Set<string>();
4
+ export function register_element(constructor: any): void {
5
+ // @warning dont use any caching on the constructor, it will break the element registration since the constructor can be used as base class.
6
+ const any_ctor = constructor as any;
7
+ if (!any_ctor.element_name) {
8
+ console.error("Error constructor:", constructor);
9
+ throw new Error("Static element attribute 'element_name' should always be defined, create static attribute \"element_name: string\" and assign the name of the class to this attribute.");
10
+ }
11
+ const base_name = any_ctor.element_name as string;
12
+ let new_tag = "";
13
+ let count = 0;
14
+ do {
15
+ new_tag = `v-${base_name.toLowerCase()}${count ? `-${count}` : ""}`;
16
+ count++;
17
+ } while (registered_names.has(new_tag));
18
+ registered_names.add(new_tag);
19
+
20
+ const extend_options = any_ctor.element_tag
21
+ ? { extends: any_ctor.element_tag }
22
+ : undefined;
23
+ customElements.define(new_tag, any_ctor, extend_options);
24
+ }
@@ -55,7 +55,7 @@ export namespace Auth {
55
55
  password: string,
56
56
  code?: string,
57
57
  }): Promise<Auth.SignInResponse> {
58
- return Utils.request({
58
+ return Utils.request_v1({
59
59
  method: "POST",
60
60
  url: "/volt/auth/signin",
61
61
  data: {
@@ -93,7 +93,7 @@ export namespace Auth {
93
93
  phone_number?: string,
94
94
  code?: string,
95
95
  }): Promise<Auth.SignUpResponse> {
96
- return Utils.request({
96
+ return Utils.request_v1({
97
97
  method: "POST",
98
98
  url: "/volt/auth/signup",
99
99
  data: {
@@ -117,7 +117,7 @@ export namespace Auth {
117
117
  @desc: Make a sign out request.
118
118
  */
119
119
  export function sign_out(): Promise<Auth.SignOutResponse> {
120
- return Utils.request({
120
+ return Utils.request_v1({
121
121
  method: "POST",
122
122
  url: "/volt/auth/signout",
123
123
  });
@@ -134,7 +134,7 @@ export namespace Auth {
134
134
  @description The user's email.
135
135
  */
136
136
  export function send_2fa(email: string): Promise<Auth.Send2FAResponse> {
137
- return Utils.request({
137
+ return Utils.request_v1({
138
138
  method: "GET",
139
139
  url: "/volt/auth/2fa",
140
140
  data: {
@@ -173,7 +173,7 @@ export namespace Auth {
173
173
  verify_password: string,
174
174
  code: string,
175
175
  }): Promise<Auth.ForgotPasswordResponse> {
176
- return Utils.request({
176
+ return Utils.request_v1({
177
177
  method: "POST",
178
178
  url: "/volt/auth/forgot_password",
179
179
  data: {
@@ -185,4 +185,5 @@ export namespace Auth {
185
185
  });
186
186
  }
187
187
 
188
- };
188
+ };
189
+ export { Auth as auth }; // also export as lowercase for compatibility.
@@ -0,0 +1,348 @@
1
+ import { Scheme } from "./scheme.js";
2
+
3
+ /**
4
+ * A utility class for color manipulation, conversion, and adjustment.
5
+ * Accepts colors in hex (e.g. "#ff0000"), RGB/RGBA strings (e.g. "rgb(255, 0, 0)" or "rgba(255,0,0,1)"),
6
+ * or as an array of numbers ([r, g, b] or [r, g, b, a]).
7
+ *
8
+ * All transformation methods (adjust_brightness, darken, lighten, interpolate, etc.) return a new Color instance,
9
+ * so they can be chained in a single line.
10
+ */
11
+ export class Color {
12
+ // ANSI color escape codes (foreground)
13
+ public static readonly black: string = "\u001b[30m";
14
+ public static readonly red: string = "\u001b[31m";
15
+ public static readonly red_bold: string = "\u001b[31m\u001b[1m";
16
+ public static readonly green: string = "\u001b[32m";
17
+ public static readonly yellow: string = "\u001b[33m";
18
+ public static readonly blue: string = "\u001b[34m";
19
+ public static readonly magenta: string = "\u001b[35m";
20
+ public static readonly cyan: string = "\u001b[36m";
21
+ public static readonly light_gray: string = "\u001b[37m";
22
+ public static readonly gray: string = "\u001b[90m";
23
+ public static readonly bold: string = "\u001b[1m";
24
+ public static readonly italic: string = "\u001b[3m";
25
+ public static readonly end: string = "\u001b[0m";
26
+ public static readonly purple: string = "\u001b[94m";
27
+
28
+ // ANSI background color objects
29
+ public static readonly bg: Record<'black' | 'red' | 'green' | 'yellow' | 'blue' | 'magenta' | 'cyan' | 'white', string> = {
30
+ black: "\u001b[40m",
31
+ red: "\u001b[41m",
32
+ green: "\u001b[42m",
33
+ yellow: "\u001b[43m",
34
+ blue: "\u001b[44m",
35
+ magenta: "\u001b[45m",
36
+ cyan: "\u001b[46m",
37
+ white: "\u001b[47m",
38
+ };
39
+
40
+ public static readonly bright_bg: Record<'black' | 'red' | 'green' | 'yellow' | 'blue' | 'magenta' | 'cyan' | 'white', string> = {
41
+ black: "\u001b[100m",
42
+ red: "\u001b[101m",
43
+ green: "\u001b[102m",
44
+ yellow: "\u001b[103m",
45
+ blue: "\u001b[104m",
46
+ magenta: "\u001b[105m",
47
+ cyan: "\u001b[106m",
48
+ white: "\u001b[107m",
49
+ };
50
+
51
+ // Internal RGBA representation
52
+ private readonly _rgba: { r: number; g: number; b: number; a: number };
53
+
54
+ /**
55
+ * Creates a new Color instance.
56
+ * @param input - A hex string, an "rgb(...)" / "rgba(...)" string, or an array of numbers ([r, g, b] or [r, g, b, a]).
57
+ */
58
+ constructor(input: string | number[]) {
59
+ this._rgba = Color._from_input(input);
60
+ }
61
+
62
+ /**
63
+ * Converts input into an RGBA object.
64
+ * @private
65
+ */
66
+ private static _from_input(input: string | number[]): { r: number; g: number; b: number; a: number } {
67
+ if (typeof input === "string") {
68
+ if (input.startsWith("#")) {
69
+ return Color.hex_to_rgb(input) as { r: number; g: number; b: number; a: number };
70
+ } else if (input.startsWith("rgb")) {
71
+ return Color.rgb_to_obj(input);
72
+ } else {
73
+ throw new Error(`Invalid color string "${input}"`);
74
+ }
75
+ } else if (Array.isArray(input)) {
76
+ return Color.array_to_rgba(input);
77
+ }
78
+ throw new Error(`Invalid color input "${input}" with type "${Scheme.value_type(input)}". Ensure the input is a hex or rgb(a) color.`);
79
+ }
80
+
81
+ /**
82
+ * Converts a numeric array to an RGBA object.
83
+ * @param array - An array of numbers representing [r, g, b] or [r, g, b, a].
84
+ */
85
+ public static array_to_rgba(array: number[]): { r: number; g: number; b: number; a: number } {
86
+ return {
87
+ r: isNaN(array[0]) ? 0 : array[0],
88
+ g: isNaN(array[1]) ? 0 : array[1],
89
+ b: isNaN(array[2]) ? 0 : array[2],
90
+ a: array.length < 4 ? 1.0 : isNaN(array[3]) ? 1.0 : array[3],
91
+ };
92
+ }
93
+
94
+ /**
95
+ * Converts a hex color string to an RGBA object or an array.
96
+ * @param hex - The hex color string (with or without "#").
97
+ * @param as_array - If true, returns an array [r, g, b, a]; otherwise an object.
98
+ */
99
+ public static hex_to_rgb(hex: string, as_array: true): number[];
100
+ public static hex_to_rgb(hex: string, as_array?: false): { r: number; g: number; b: number; a: number };
101
+ public static hex_to_rgb(hex: string, as_array: boolean = false): { r: number; g: number; b: number; a: number } | number[] {
102
+ let clean_hex = hex;
103
+ const index = clean_hex.indexOf("#");
104
+ if (index !== -1) {
105
+ clean_hex = clean_hex.substr(index + 1);
106
+ }
107
+ let r = parseInt(clean_hex.substring(0, 2), 16);
108
+ let g = parseInt(clean_hex.substring(2, 4), 16);
109
+ let b = parseInt(clean_hex.substring(4, 6), 16);
110
+ let a = 1;
111
+ if (clean_hex.length > 6) {
112
+ a = parseInt(clean_hex.substring(6, 8), 16) / 255;
113
+ }
114
+ if (isNaN(r)) { r = 0; }
115
+ if (isNaN(g)) { g = 0; }
116
+ if (isNaN(b)) { b = 0; }
117
+ if (isNaN(a)) { a = 1; }
118
+
119
+ if (as_array) {
120
+ return [r, g, b, a];
121
+ }
122
+ return { r, g, b, a };
123
+ }
124
+
125
+ /**
126
+ * Converts an "rgb(...)" or "rgba(...)" string to an RGBA object.
127
+ * @param color - The RGB(A) color string.
128
+ * @throws Error if the color format is invalid.
129
+ */
130
+ public static rgb_to_obj(color: string): { r: number; g: number; b: number; a: number } {
131
+ if (!color.startsWith("rgba(") && !color.startsWith("rgb(")) {
132
+ throw new Error("Invalid color format");
133
+ }
134
+ const content = color.trim().split("(")[1].slice(0, -1);
135
+ const split = content.split(",");
136
+ return {
137
+ r: parseInt(split[0].trim()),
138
+ g: parseInt(split[1].trim()),
139
+ b: parseInt(split[2].trim()),
140
+ a: split[3] ? parseFloat(split[3].trim()) : 1,
141
+ };
142
+ }
143
+
144
+ /**
145
+ * Converts RGBA values to a hex color string.
146
+ * @param r - Red channel value.
147
+ * @param g - Green channel value.
148
+ * @param b - Blue channel value.
149
+ * @param a - Alpha channel value (defaults to 1).
150
+ */
151
+ public static rgb_to_hex(r: number, g: number, b: number, a: number = 1): string {
152
+ const hex_r = Math.round(r).toString(16).padStart(2, "0");
153
+ const hex_g = Math.round(g).toString(16).padStart(2, "0");
154
+ const hex_b = Math.round(b).toString(16).padStart(2, "0");
155
+ const hex_a = a === 1 ? "" : Math.round(a * 255).toString(16).padStart(2, "0");
156
+ return `#${hex_r}${hex_g}${hex_b}${hex_a}`;
157
+ }
158
+
159
+ /**
160
+ * Converts RGBA values to an "rgb(...)" or "rgba(...)" string.
161
+ * @param r - Red channel.
162
+ * @param g - Green channel.
163
+ * @param b - Blue channel.
164
+ * @param a - Alpha channel (defaults to 1).
165
+ */
166
+ public static rgb_to_str(r: number, g: number, b: number, a: number = 1): string {
167
+ if (a !== 1) {
168
+ return `rgba(${isNaN(r) ? 0 : r}, ${isNaN(g) ? 0 : g}, ${isNaN(b) ? 0 : b}, ${isNaN(a) ? 1 : a})`;
169
+ }
170
+ return `rgb(${isNaN(r) ? 0 : r}, ${isNaN(g) ? 0 : g}, ${isNaN(b) ? 0 : b})`;
171
+ }
172
+
173
+
174
+ /**
175
+ * Returns the hex string representation of this Color.
176
+ */
177
+ public to_hex(): string {
178
+ return Color.rgb_to_hex(this._rgba.r, this._rgba.g, this._rgba.b, this._rgba.a);
179
+ }
180
+ public hex(): string {
181
+ return Color.rgb_to_hex(this._rgba.r, this._rgba.g, this._rgba.b, this._rgba.a);
182
+ }
183
+
184
+ /**
185
+ * Returns the RGB(A) string representation of this Color.
186
+ */
187
+ public str(): string {
188
+ return Color.rgb_to_str(this._rgba.r, this._rgba.g, this._rgba.b, this._rgba.a);
189
+ }
190
+ public to_str(): string {
191
+ return Color.rgb_to_str(this._rgba.r, this._rgba.g, this._rgba.b, this._rgba.a);
192
+ }
193
+ public to_rgb(): string {
194
+ return Color.rgb_to_str(this._rgba.r, this._rgba.g, this._rgba.b, this._rgba.a);
195
+ }
196
+ public rgb(): string {
197
+ return Color.rgb_to_str(this._rgba.r, this._rgba.g, this._rgba.b, this._rgba.a);
198
+ }
199
+
200
+ /**
201
+ * Returns the brightness of the color.
202
+ * Uses the formula: (0.299*R + 0.587*G + 0.114*B) / 255.
203
+ * @returns A number between 0 (bright) and 1 (dark).
204
+ */
205
+ private get_brightness(): number {
206
+ return (0.299 * this._rgba.r + 0.587 * this._rgba.g + 0.114 * this._rgba.b) / 255;
207
+ }
208
+
209
+ /**
210
+ * Adjusts the brightness of the color by adding a constant to each RGB channel.
211
+ * @param adjust - The value to add (can be negative).
212
+ * @returns A new Color instance with modified brightness.
213
+ */
214
+ public adjust_brightness(adjust: number): Color {
215
+ const new_rgba = {
216
+ r: this._rgba.r + adjust,
217
+ g: this._rgba.g + adjust,
218
+ b: this._rgba.b + adjust,
219
+ a: this._rgba.a,
220
+ };
221
+ return new Color([new_rgba.r, new_rgba.g, new_rgba.b, new_rgba.a]);
222
+ }
223
+
224
+ /** Get opacity. */
225
+ public get_opacity(): number {
226
+ return this._rgba.a;
227
+ }
228
+
229
+ /**
230
+ * Sets the opacity (alpha channel) of the color.
231
+ * @param opacity - A number between 0 and 1.
232
+ * @returns A new Color instance with the given opacity.
233
+ * @throws Error if the opacity is not within [0,1].
234
+ */
235
+ public opacity(opacity: number = 1.0): Color {
236
+ if (typeof opacity !== "number" || opacity < 0 || opacity > 1) {
237
+ throw new Error("Invalid opacity [0...1]: " + opacity + ".");
238
+ }
239
+ return new Color([this._rgba.r, this._rgba.g, this._rgba.b, opacity]);
240
+ }
241
+
242
+ /**
243
+ * Darkens the color by interpolating toward black.
244
+ * @param percent - The percentage to darken (between 0 and 1).
245
+ * @returns A new Color instance darkened by the specified percentage.
246
+ * @throws Error if the percentage is not within [0,1].
247
+ */
248
+ public darken(percent: number = 0.5): Color {
249
+ if (typeof percent !== "number" || percent < 0 || percent > 1) {
250
+ throw new Error("Invalid percentage [0...1]: " + percent + ".");
251
+ }
252
+ const new_rgba = {
253
+ r: Math.round(this._rgba.r * (1 - percent)),
254
+ g: Math.round(this._rgba.g * (1 - percent)),
255
+ b: Math.round(this._rgba.b * (1 - percent)),
256
+ a: this._rgba.a,
257
+ };
258
+ return new Color([new_rgba.r, new_rgba.g, new_rgba.b, new_rgba.a]);
259
+ }
260
+
261
+ /**
262
+ * Lightens the color by interpolating toward white.
263
+ * @param percent - The percentage to lighten (between 0 and 1).
264
+ * @returns A new Color instance lightened by the specified percentage.
265
+ * @throws Error if the percentage is not within [0,1].
266
+ */
267
+ public lighten(percent: number = 0.5): Color {
268
+ if (typeof percent !== "number" || percent < 0 || percent > 1) {
269
+ throw new Error("Invalid percentage [0...1]: " + percent + ".");
270
+ }
271
+ const new_rgba = {
272
+ r: Math.round(this._rgba.r + (255 - this._rgba.r) * percent),
273
+ g: Math.round(this._rgba.g + (255 - this._rgba.g) * percent),
274
+ b: Math.round(this._rgba.b + (255 - this._rgba.b) * percent),
275
+ a: this._rgba.a,
276
+ };
277
+ return new Color([new_rgba.r, new_rgba.g, new_rgba.b, new_rgba.a]);
278
+ }
279
+
280
+ /**
281
+ * Automatically darken when the color is bright or lighten when the color is dark.
282
+ *
283
+ * @param evaluation When the evaluation returns true the color will be darkened.
284
+ */
285
+ public auto_darken_lighten(percent: number = 0.5, evaluation: (brightness: number) => boolean = (b)=> b > 0.5): Color {
286
+ if (evaluation(this.get_brightness())) {
287
+ return this.darken(percent);
288
+ } else {
289
+ return this.lighten(percent);
290
+ }
291
+ }
292
+
293
+ /**
294
+ * Interpolates between this color and an end color.
295
+ * When percent is 0 the original color is returned, and when 1 the end color is returned.
296
+ * @param end - The target color (hex string, rgb(a) string, number array, or Color).
297
+ * @param percent - The interpolation factor (0 to 1).
298
+ * @param alpha - The resulting alpha value (0 to 1).
299
+ * @returns A new Color instance representing the interpolated color.
300
+ * @throws Error if percent or alpha are out of range.
301
+ */
302
+ public interpolate(end: string | number[] | Color, percent: number = 0.5, alpha: number = 1.0): Color {
303
+ if (typeof percent !== "number" || percent < 0 || percent > 1) {
304
+ throw new Error("Invalid percentage [0...1]: " + percent + ".");
305
+ }
306
+ if (typeof alpha !== "number" || alpha < 0 || alpha > 1) {
307
+ throw new Error("Invalid alpha [0...1]: " + alpha + ".");
308
+ }
309
+ const end_color: Color = end instanceof Color ? end : new Color(end);
310
+ const new_r = Math.round(this._rgba.r + (end_color._rgba.r - this._rgba.r) * percent);
311
+ const new_g = Math.round(this._rgba.g + (end_color._rgba.g - this._rgba.g) * percent);
312
+ const new_b = Math.round(this._rgba.b + (end_color._rgba.b - this._rgba.b) * percent);
313
+ return new Color([new_r, new_g, new_b, alpha]);
314
+ }
315
+
316
+ /**
317
+ * Returns the opposite (contrasting) color.
318
+ * Returns black ("#000000") if the color is bright, or white ("#ffffff") if it is dark.
319
+ * @returns A new Color instance that is either black or white.
320
+ */
321
+ public opposite(): Color {
322
+ return this.get_brightness() > 0.5 ? new Color("#000000") : new Color("#ffffff");
323
+ }
324
+ public static opposite_s(color: ConstructorParameters<typeof Color>[0]): Color {
325
+ return new Color(color).opposite();
326
+ }
327
+ public opposite_hex(): "#000000" | "#ffffff" {
328
+ return this.get_brightness() > 0.5 ? "#000000" : "#ffffff";
329
+ }
330
+ public static opposite_hex_s(color: ConstructorParameters<typeof Color>[0]): "#000000" | "#ffffff" {
331
+ return new Color(color).opposite_hex();
332
+ }
333
+
334
+ /**
335
+ * Returns a function reference: if the color is bright, returns a darken function;
336
+ * otherwise returns a lighten function.
337
+ * The returned function accepts an optional percentage.
338
+ * @returns A function that takes an optional percent and returns a new Color instance.
339
+ */
340
+ // public opposite_func(): (percent?: number) => Color {
341
+ // if (this.get_brightness() > 0.5) {
342
+ // return (percent: number = 0.5) => this.darken(percent);
343
+ // } else {
344
+ // return (percent: number = 0.5) => this.lighten(percent);
345
+ // }
346
+ // }
347
+ }
348
+ export { Color as color }; // also export as lowercase for compatibility.