x4js 1.6.5 → 2.0.1

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 (282) hide show
  1. package/README.md +3 -14
  2. package/lib/README.txt +3 -14
  3. package/lib/src/assets/house-light.svg +1 -0
  4. package/lib/src/assets/radio.svg +4 -0
  5. package/lib/src/components/base.scss +26 -0
  6. package/lib/src/components/boxes/boxes.module.scss +37 -0
  7. package/lib/src/components/boxes/boxes.ts +125 -0
  8. package/lib/src/components/btngroup/btngroup.module.scss +29 -0
  9. package/lib/src/components/btngroup/btngroup.ts +106 -0
  10. package/lib/src/components/button/button.module.scss +154 -0
  11. package/lib/src/components/button/button.ts +117 -0
  12. package/lib/src/components/calendar/calendar-check-sharp-light.svg +1 -0
  13. package/lib/src/components/calendar/calendar.module.scss +163 -0
  14. package/lib/src/{calendar.ts → components/calendar/calendar.ts} +81 -83
  15. package/lib/src/components/calendar/chevron-left-sharp-light.svg +1 -0
  16. package/lib/src/components/calendar/chevron-right-sharp-light.svg +1 -0
  17. package/lib/src/components/checkbox/check.svg +4 -0
  18. package/lib/src/components/checkbox/checkbox.module.scss +142 -0
  19. package/lib/src/components/checkbox/checkbox.ts +125 -0
  20. package/lib/src/components/colorinput/colorinput.module.scss +65 -0
  21. package/lib/src/components/colorinput/colorinput.ts +88 -0
  22. package/lib/src/components/colorinput/crosshairs-simple-sharp-light.svg +1 -0
  23. package/lib/src/components/colorpicker/colorpicker.module.scss +133 -0
  24. package/lib/src/components/colorpicker/colorpicker.ts +477 -0
  25. package/lib/src/components/combobox/combobox.module.scss +121 -0
  26. package/lib/src/components/combobox/combobox.ts +190 -0
  27. package/lib/src/components/combobox/updown.svg +4 -0
  28. package/lib/src/components/dialog/dialog.module.scss +71 -0
  29. package/lib/src/components/dialog/dialog.ts +91 -0
  30. package/lib/src/components/dialog/xmark-sharp-light.svg +1 -0
  31. package/lib/src/components/form/form.module.scss +34 -0
  32. package/lib/src/components/form/form.ts +36 -0
  33. package/lib/src/components/header/header.module.scss +40 -0
  34. package/lib/src/components/header/header.ts +124 -0
  35. package/lib/src/components/icon/icon.module.scss +30 -0
  36. package/lib/src/components/icon/icon.ts +134 -0
  37. package/lib/src/components/image/image.module.scss +21 -0
  38. package/lib/src/components/image/image.ts +67 -0
  39. package/lib/src/components/input/input.module.scss +69 -0
  40. package/lib/src/components/input/input.ts +274 -0
  41. package/lib/src/components/label/label.module.scss +52 -0
  42. package/lib/src/components/label/label.ts +55 -0
  43. package/lib/src/components/listbox/listbox.module.scss +103 -0
  44. package/lib/src/components/listbox/listbox.ts +427 -0
  45. package/lib/src/components/menu/caret-right-solid.svg +1 -0
  46. package/lib/src/components/menu/menu.module.scss +108 -0
  47. package/lib/src/components/menu/menu.ts +168 -0
  48. package/lib/src/components/messages/circle-exclamation.svg +1 -0
  49. package/lib/src/components/messages/messages.module.scss +47 -0
  50. package/lib/src/components/messages/messages.ts +64 -0
  51. package/lib/src/components/normalize.scss +386 -0
  52. package/lib/src/components/notification/circle-check-solid.svg +1 -0
  53. package/lib/src/components/notification/circle-exclamation-solid.svg +1 -0
  54. package/lib/src/components/notification/circle-notch-light.svg +1 -0
  55. package/lib/src/components/notification/notification.module.scss +82 -0
  56. package/lib/src/components/notification/notification.ts +108 -0
  57. package/lib/src/components/notification/xmark-sharp-light.svg +1 -0
  58. package/lib/src/components/panel/panel.module.scss +48 -0
  59. package/lib/src/components/panel/panel.ts +57 -0
  60. package/lib/src/components/popup/popup.module.scss +43 -0
  61. package/lib/src/components/popup/popup.ts +395 -0
  62. package/lib/src/components/progress/progress.module.scss +57 -0
  63. package/lib/src/components/progress/progress.ts +43 -0
  64. package/lib/src/components/rating/rating.module.scss +23 -0
  65. package/lib/src/components/rating/rating.ts +125 -0
  66. package/lib/src/components/rating/star-sharp-light.svg +1 -0
  67. package/lib/src/components/rating/star-sharp-solid.svg +1 -0
  68. package/lib/src/components/shared.scss +76 -0
  69. package/lib/src/components/sizers/sizer.module.scss +90 -0
  70. package/lib/src/components/sizers/sizer.ts +120 -0
  71. package/lib/src/components/slider/slider.module.scss +71 -0
  72. package/lib/src/components/slider/slider.ts +143 -0
  73. package/lib/src/components/switch/switch.module.scss +127 -0
  74. package/lib/src/components/switch/switch.ts +56 -0
  75. package/lib/src/components/tabs/tabs.module.scss +46 -0
  76. package/lib/src/components/tabs/tabs.ts +157 -0
  77. package/lib/src/components/textarea/textarea.module.scss +59 -0
  78. package/lib/src/components/textarea/textarea.ts +54 -0
  79. package/lib/src/components/textedit/textedit.module.scss +114 -0
  80. package/lib/src/components/textedit/textedit.ts +82 -0
  81. package/lib/src/components/themes.scss +77 -0
  82. package/lib/src/components/tooltips/circle-info-sharp-light.svg +1 -0
  83. package/lib/src/components/tooltips/tooltips.scss +51 -0
  84. package/lib/src/components/tooltips/tooltips.ts +103 -0
  85. package/lib/src/components/treeview/chevron-down-light.svg +1 -0
  86. package/lib/src/components/treeview/treeview.module.scss +116 -0
  87. package/lib/src/components/treeview/treeview.ts +403 -0
  88. package/lib/src/components/viewport/viewport.module.scss +25 -0
  89. package/lib/src/components/viewport/viewport.ts +38 -0
  90. package/lib/src/core/component.ts +979 -0
  91. package/lib/src/core/core_colors.ts +250 -0
  92. package/lib/src/{dom_events.ts → core/core_dom.ts} +195 -39
  93. package/lib/src/{drag_manager.ts → core/core_dragdrop.ts} +29 -44
  94. package/lib/src/core/core_element.ts +98 -0
  95. package/lib/src/core/core_events.ts +149 -0
  96. package/lib/src/{i18n.ts → core/core_i18n.ts} +43 -42
  97. package/lib/src/{router.ts → core/core_router.ts} +27 -40
  98. package/lib/src/core/core_styles.ts +215 -0
  99. package/lib/src/core/core_svg.ts +550 -0
  100. package/lib/src/core/core_tools.ts +673 -0
  101. package/lib/src/main.scss +21 -0
  102. package/lib/src/main.tsx +323 -0
  103. package/lib/src/x4.scss +19 -0
  104. package/lib/types/x4.d.ts +2624 -0
  105. package/package.json +67 -59
  106. package/scripts/build.mjs +351 -0
  107. package/scripts/prepack.mjs +15 -0
  108. package/src/assets/house-light.svg +1 -0
  109. package/src/assets/radio.svg +4 -0
  110. package/src/components/base.scss +26 -0
  111. package/src/components/boxes/boxes.module.scss +37 -0
  112. package/src/components/boxes/boxes.ts +125 -0
  113. package/src/components/btngroup/btngroup.module.scss +29 -0
  114. package/src/components/btngroup/btngroup.ts +106 -0
  115. package/src/components/button/button.module.scss +154 -0
  116. package/src/components/button/button.ts +117 -0
  117. package/src/components/calendar/calendar-check-sharp-light.svg +1 -0
  118. package/src/components/calendar/calendar.module.scss +163 -0
  119. package/src/components/calendar/calendar.ts +326 -0
  120. package/src/components/calendar/chevron-left-sharp-light.svg +1 -0
  121. package/src/components/calendar/chevron-right-sharp-light.svg +1 -0
  122. package/src/components/checkbox/check.svg +4 -0
  123. package/src/components/checkbox/checkbox.module.scss +142 -0
  124. package/src/components/checkbox/checkbox.ts +125 -0
  125. package/src/components/colorinput/colorinput.module.scss +65 -0
  126. package/src/components/colorinput/colorinput.ts +88 -0
  127. package/src/components/colorinput/crosshairs-simple-sharp-light.svg +1 -0
  128. package/src/components/colorpicker/colorpicker.module.scss +133 -0
  129. package/src/components/colorpicker/colorpicker.ts +477 -0
  130. package/src/components/combobox/combobox.module.scss +121 -0
  131. package/src/components/combobox/combobox.ts +190 -0
  132. package/src/components/combobox/updown.svg +4 -0
  133. package/src/components/dialog/dialog.module.scss +71 -0
  134. package/src/components/dialog/dialog.ts +91 -0
  135. package/src/components/dialog/xmark-sharp-light.svg +1 -0
  136. package/src/components/form/form.module.scss +34 -0
  137. package/src/components/form/form.ts +36 -0
  138. package/src/components/header/header.module.scss +40 -0
  139. package/src/components/header/header.ts +124 -0
  140. package/src/components/icon/icon.module.scss +30 -0
  141. package/src/components/icon/icon.ts +134 -0
  142. package/src/components/image/image.module.scss +21 -0
  143. package/src/components/image/image.ts +67 -0
  144. package/src/components/input/input.module.scss +69 -0
  145. package/src/components/input/input.ts +274 -0
  146. package/src/components/label/label.module.scss +52 -0
  147. package/src/components/label/label.ts +55 -0
  148. package/src/components/listbox/listbox.module.scss +103 -0
  149. package/src/components/listbox/listbox.ts +427 -0
  150. package/src/components/menu/caret-right-solid.svg +1 -0
  151. package/src/components/menu/menu.module.scss +108 -0
  152. package/src/components/menu/menu.ts +168 -0
  153. package/src/components/messages/circle-exclamation.svg +1 -0
  154. package/src/components/messages/messages.module.scss +47 -0
  155. package/src/components/messages/messages.ts +64 -0
  156. package/src/components/normalize.scss +386 -0
  157. package/src/components/notification/circle-check-solid.svg +1 -0
  158. package/src/components/notification/circle-exclamation-solid.svg +1 -0
  159. package/src/components/notification/circle-notch-light.svg +1 -0
  160. package/src/components/notification/notification.module.scss +82 -0
  161. package/src/components/notification/notification.ts +108 -0
  162. package/src/components/notification/xmark-sharp-light.svg +1 -0
  163. package/src/components/panel/panel.module.scss +48 -0
  164. package/src/components/panel/panel.ts +57 -0
  165. package/src/components/popup/popup.module.scss +43 -0
  166. package/src/components/popup/popup.ts +395 -0
  167. package/src/components/progress/progress.module.scss +57 -0
  168. package/src/components/progress/progress.ts +43 -0
  169. package/src/components/rating/rating.module.scss +23 -0
  170. package/src/components/rating/rating.ts +125 -0
  171. package/src/components/rating/star-sharp-light.svg +1 -0
  172. package/src/components/rating/star-sharp-solid.svg +1 -0
  173. package/src/components/shared.scss +76 -0
  174. package/src/components/sizers/sizer.module.scss +90 -0
  175. package/src/components/sizers/sizer.ts +120 -0
  176. package/src/components/slider/slider.module.scss +71 -0
  177. package/src/components/slider/slider.ts +143 -0
  178. package/src/components/switch/switch.module.scss +127 -0
  179. package/src/components/switch/switch.ts +56 -0
  180. package/src/components/tabs/tabs.module.scss +46 -0
  181. package/src/components/tabs/tabs.ts +157 -0
  182. package/src/components/textarea/textarea.module.scss +59 -0
  183. package/src/components/textarea/textarea.ts +54 -0
  184. package/src/components/textedit/textedit.module.scss +114 -0
  185. package/src/components/textedit/textedit.ts +82 -0
  186. package/src/components/themes.scss +77 -0
  187. package/src/components/tooltips/circle-info-sharp-light.svg +1 -0
  188. package/src/components/tooltips/tooltips.scss +51 -0
  189. package/src/components/tooltips/tooltips.ts +103 -0
  190. package/src/components/treeview/chevron-down-light.svg +1 -0
  191. package/src/components/treeview/treeview.module.scss +116 -0
  192. package/src/components/treeview/treeview.ts +403 -0
  193. package/src/components/viewport/viewport.module.scss +25 -0
  194. package/src/components/viewport/viewport.ts +38 -0
  195. package/src/core/component.ts +979 -0
  196. package/src/core/core_colors.ts +250 -0
  197. package/src/core/core_dom.ts +471 -0
  198. package/src/core/core_dragdrop.ts +201 -0
  199. package/src/core/core_element.ts +98 -0
  200. package/src/core/core_events.ts +149 -0
  201. package/src/core/core_i18n.ts +377 -0
  202. package/src/core/core_router.ts +221 -0
  203. package/src/core/core_styles.ts +215 -0
  204. package/src/core/core_svg.ts +550 -0
  205. package/src/core/core_tools.ts +673 -0
  206. package/src/main.scss +21 -0
  207. package/src/main.tsx +323 -0
  208. package/src/x4.scss +19 -0
  209. package/tsconfig.json +14 -0
  210. package/types/scss.d.ts +4 -0
  211. package/types/svg.d.ts +4 -0
  212. package/types/x4react.d.ts +9 -0
  213. package/lib/changelog.txt +0 -23
  214. package/lib/cjs/x4js.js +0 -39
  215. package/lib/cjs/x4js.js.map +0 -7
  216. package/lib/esm/x4js.mjs +0 -15972
  217. package/lib/esm/x4js.mjs.map +0 -7
  218. package/lib/licence.md +0 -21
  219. package/lib/src/MIT-license.md +0 -14
  220. package/lib/src/action.ts +0 -88
  221. package/lib/src/alpha.jpg +0 -0
  222. package/lib/src/app_sockets.ts +0 -81
  223. package/lib/src/application.ts +0 -262
  224. package/lib/src/autocomplete.ts +0 -232
  225. package/lib/src/base64.ts +0 -166
  226. package/lib/src/base_component.ts +0 -152
  227. package/lib/src/button.ts +0 -355
  228. package/lib/src/canvas.ts +0 -510
  229. package/lib/src/cardview.ts +0 -228
  230. package/lib/src/checkbox.ts +0 -188
  231. package/lib/src/color.ts +0 -752
  232. package/lib/src/colorpicker.ts +0 -1649
  233. package/lib/src/combobox.ts +0 -512
  234. package/lib/src/component.ts +0 -2367
  235. package/lib/src/copyright.txt +0 -27
  236. package/lib/src/datastore.ts +0 -1302
  237. package/lib/src/dialog.ts +0 -656
  238. package/lib/src/drawtext.ts +0 -355
  239. package/lib/src/fileupload.ts +0 -213
  240. package/lib/src/form.ts +0 -413
  241. package/lib/src/formatters.ts +0 -105
  242. package/lib/src/gridview.ts +0 -1185
  243. package/lib/src/icon.ts +0 -362
  244. package/lib/src/image.ts +0 -225
  245. package/lib/src/index.ts +0 -89
  246. package/lib/src/input.ts +0 -297
  247. package/lib/src/label.ts +0 -153
  248. package/lib/src/layout.ts +0 -442
  249. package/lib/src/link.ts +0 -86
  250. package/lib/src/listview.ts +0 -765
  251. package/lib/src/md5.ts +0 -438
  252. package/lib/src/menu.ts +0 -425
  253. package/lib/src/messagebox.ts +0 -224
  254. package/lib/src/panel.ts +0 -86
  255. package/lib/src/popup.ts +0 -494
  256. package/lib/src/property_editor.ts +0 -337
  257. package/lib/src/radiobtn.ts +0 -197
  258. package/lib/src/rating.ts +0 -135
  259. package/lib/src/request.ts +0 -300
  260. package/lib/src/settings.ts +0 -77
  261. package/lib/src/sidebarview.ts +0 -108
  262. package/lib/src/spreadsheet.ts +0 -1449
  263. package/lib/src/styles.ts +0 -343
  264. package/lib/src/svgcomponent.ts +0 -592
  265. package/lib/src/tabbar.ts +0 -151
  266. package/lib/src/tabview.ts +0 -110
  267. package/lib/src/textarea.ts +0 -235
  268. package/lib/src/textedit.ts +0 -533
  269. package/lib/src/toaster.ts +0 -80
  270. package/lib/src/tools.ts +0 -1473
  271. package/lib/src/tooltips.ts +0 -191
  272. package/lib/src/treeview.ts +0 -716
  273. package/lib/src/version.ts +0 -30
  274. package/lib/src/x4.less +0 -2242
  275. package/lib/src/x4dom.ts +0 -57
  276. package/lib/src/x4events.ts +0 -585
  277. package/lib/src/x4js.ts +0 -89
  278. package/lib/src/x4react.ts +0 -90
  279. package/lib/styles/x4.css +0 -1785
  280. package/lib/styles/x4.less +0 -2242
  281. package/lib/types/x4js.d.ts +0 -6728
  282. package/license.md +0 -21
@@ -0,0 +1,250 @@
1
+ /**
2
+ * ___ ___ __
3
+ * \ \/ / / _
4
+ * \ / /_| |_
5
+ * / \____ _|
6
+ * /__/\__\ |_|
7
+ *
8
+ * @file core_colors.ts
9
+ * @author Etienne Cochard
10
+ *
11
+ * @copyright (c) 2024 R-libre ingenierie
12
+ *
13
+ * Use of this source code is governed by an MIT-style license
14
+ * that can be found in the LICENSE file or at https://opensource.org/licenses/MIT.
15
+ **/
16
+
17
+ import { clamp, isString } from './core_tools';
18
+
19
+
20
+ function hx( v: number ) {
21
+ const hex = v.toString( 16 );
22
+ return hex.padStart( 2, '0' );
23
+ }
24
+
25
+ function round( v: number ) {
26
+ return Math.round(v);
27
+ }
28
+
29
+
30
+ export interface Rgb {
31
+ red: number;
32
+ green: number;
33
+ blue: number;
34
+ alpha: number;
35
+ }
36
+
37
+ export interface Hsv {
38
+ hue: number;
39
+ saturation: number;
40
+ value: number;
41
+ alpha: number;
42
+ }
43
+
44
+
45
+ export class Color {
46
+
47
+ private rgb: [red:number,green:number,blue:number,alpha:number] = [0,0,0,1];
48
+ private invalid = false;
49
+
50
+ constructor( value: string );
51
+ constructor( r: number, g: number, b: number, a?: number );
52
+ constructor( ...args: any[] ) {
53
+ if( isString(args[0] ) ) {
54
+ this.setValue( args[0] );
55
+ }
56
+ else {
57
+ this.setRgb( args[0], args[1], args[2], args[3] );
58
+ }
59
+ }
60
+
61
+ /**
62
+ * accepts:
63
+ * #aaa
64
+ * #ababab
65
+ * #ababab55
66
+ * rgb(a,b,c)
67
+ * rgba(a,b,c,d)
68
+ * var( --color-5 )
69
+ */
70
+
71
+ setValue( value: string ): this {
72
+
73
+ this.invalid = false;
74
+
75
+ if( value.length==4 && /#[0-9a-fA-F]{3}/.test(value) ) {
76
+ const r1 = parseInt( value[1], 16 );
77
+ const g1 = parseInt( value[2], 16 );
78
+ const b1 = parseInt( value[3], 16 );
79
+ return this.setRgb( r1<<4|r1, g1<<4|g1, b1<<4|b1, 1.0 );
80
+ }
81
+
82
+ if( value.length==7 && /#[0-9a-fA-F]{6}/.test(value) ) {
83
+ const r1 = parseInt( value[1], 16 );
84
+ const r2 = parseInt( value[2], 16 );
85
+ const g1 = parseInt( value[3], 16 );
86
+ const g2 = parseInt( value[4], 16 );
87
+ const b1 = parseInt( value[5], 16 );
88
+ const b2 = parseInt( value[6], 16 );
89
+ return this.setRgb( r1<<4|r2, g1<<4|g2, b1<<4|b2, 1.0 );
90
+ }
91
+
92
+ if( value.length==9 && /#[0-9a-fA-F]{8}/.test(value) ) {
93
+ const r1 = parseInt( value[1], 16 );
94
+ const r2 = parseInt( value[2], 16 );
95
+ const g1 = parseInt( value[3], 16 );
96
+ const g2 = parseInt( value[4], 16 );
97
+ const b1 = parseInt( value[5], 16 );
98
+ const b2 = parseInt( value[6], 16 );
99
+ const a1 = parseInt( value[7], 16 );
100
+ const a2 = parseInt( value[8], 16 );
101
+ return this.setRgb( r1<<4|r2, g1<<4|g2, b1<<4|b2, (a1<<4|a2) / 255.0 );
102
+ }
103
+
104
+ if( value.startsWith('rgba') ) {
105
+ const re = /rgba\s*\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*,\s*((\d+)|(\d*\.\d+)|(\.\d+))\s*\)/;
106
+ const m = re.exec( value );
107
+ if( m ) {
108
+ return this.setRgb( parseInt(m[1]), parseInt(m[2]), parseInt(m[3]), parseFloat(m[4]) );
109
+ }
110
+ }
111
+ else if( value.startsWith('rgb') ) {
112
+ const re = /rgb\s*\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*\)/;
113
+ const m = re.exec( value );
114
+ if( m ) {
115
+ return this.setRgb( parseInt(m[1]), parseInt(m[2]), parseInt(m[3]), 1.0 );
116
+ }
117
+ }
118
+ else if( value.startsWith("var") ) {
119
+ const re = /var\s*\(([^)]*)\)/;
120
+ const m = re.exec( value );
121
+ if( m ) {
122
+ const expr = m[1].trim( );
123
+ const style = getComputedStyle( document.documentElement );
124
+ const value = style.getPropertyValue( expr );
125
+ return this.setValue( value );
126
+ }
127
+ }
128
+
129
+ this.invalid = true;
130
+ return this.setRgb(255,0,0,1);
131
+ }
132
+
133
+ setHsv( h: number, s: number, v: number, a = 1.0 ): this {
134
+
135
+ let i = Math.min(5, Math.floor(h * 6)),
136
+ f = h * 6 - i,
137
+ p = v * (1 - s),
138
+ q = v * (1 - f * s),
139
+ t = v * (1 - (1 - f) * s);
140
+
141
+ let R, G, B;
142
+
143
+ switch (i) {
144
+ case 0:
145
+ R = v;
146
+ G = t;
147
+ B = p;
148
+ break;
149
+ case 1:
150
+ R = q;
151
+ G = v;
152
+ B = p;
153
+ break;
154
+ case 2:
155
+ R = p;
156
+ G = v;
157
+ B = t;
158
+ break;
159
+ case 3:
160
+ R = p;
161
+ G = q;
162
+ B = v;
163
+ break;
164
+ case 4:
165
+ R = t;
166
+ G = p;
167
+ B = v;
168
+ break;
169
+ case 5:
170
+ R = v;
171
+ G = p;
172
+ B = q;
173
+ break;
174
+ }
175
+
176
+ return this.setRgb( R*255, G*255, B*255, a );
177
+ }
178
+
179
+
180
+ setRgb( r: number, g: number, b: number, a: number ): this {
181
+ this.rgb = [clamp(r,0,255),clamp(g,0,255),clamp(b,0,255),clamp(a,0,1)];
182
+ return this;
183
+ }
184
+
185
+ toRgbString( withAlpha?: boolean ): string {
186
+ const _ = this.rgb;
187
+ return withAlpha===false || _[3]==1 ? `rgb(${round(_[0])},${round(_[1])},${round(_[2])})` : `rgba(${round(_[0])},${round(_[1])},${round(_[2])},${_[3].toFixed(3)})`
188
+ }
189
+
190
+ toHexString( ): string {
191
+ const _ = this.rgb;
192
+ return _[3]==1 ? `#(${hx(_[0])},${hx(_[1])},${hx(_[2])})` : `rgba(${hx(_[0])},${hx(_[1])},${hx(_[2])},${hx(_[3]*255)})`
193
+ }
194
+
195
+ toRgb( ): Rgb {
196
+ const _ = this.rgb;
197
+ return { red: _[0], green: _[1], blue: _[2], alpha: _[3] };
198
+ }
199
+
200
+ toHsv( ): Hsv {
201
+
202
+ let el = this.toRgb( );
203
+
204
+ el.red /= 255.0;
205
+ el.green /= 255.0;
206
+ el.blue /= 255.0;
207
+
208
+ const max = Math.max(el.red, el.green, el.blue);
209
+ const min = Math.min(el.red, el.green, el.blue);
210
+ const delta = max - min;
211
+ const saturation = (max === 0) ? 0 : (delta / max);
212
+ const value = max;
213
+
214
+ let hue;
215
+
216
+ if (delta === 0) {
217
+ hue = 0;
218
+ }
219
+ else {
220
+ switch (max) {
221
+ case el.red:
222
+ hue = (el.green - el.blue) / delta / 6 + (el.green < el.blue ? 1 : 0);
223
+ break;
224
+
225
+ case el.green:
226
+ hue = (el.blue - el.red) / delta / 6 + 1 / 3;
227
+ break;
228
+
229
+ case el.blue:
230
+ hue = (el.red - el.green) / delta / 6 + 2 / 3;
231
+ break;
232
+ }
233
+ }
234
+
235
+ return { hue, saturation, value, alpha: el.alpha };
236
+ }
237
+
238
+ getAlpha( ) {
239
+ return this.rgb[3];
240
+ }
241
+
242
+ setAlpha( a: number ): this {
243
+ this.rgb[3] = clamp( a, 0, 1 );
244
+ return this;
245
+ }
246
+
247
+ isInvalid( ) {
248
+ return this.invalid;
249
+ }
250
+ }
@@ -0,0 +1,471 @@
1
+ /**
2
+ * ___ ___ __
3
+ * \ \/ / / _
4
+ * \ / /_| |_
5
+ * / \____ _|
6
+ * /__/\__\ |_|
7
+ *
8
+ * @file core_dom.ts
9
+ * @author Etienne Cochard
10
+ *
11
+ * @copyright (c) 2024 R-libre ingenierie
12
+ *
13
+ * Use of this source code is governed by an MIT-style license
14
+ * that can be found in the LICENSE file or at https://opensource.org/licenses/MIT.
15
+ **/
16
+
17
+ /** @ignore this events must be defined on domNode (do not bubble) */
18
+ export const unbubbleEvents = {
19
+ mouseleave: 1, mouseenter: 1, load: 1, unload: 1, scroll: 1, focus: 1, blur: 1, rowexit: 1, beforeunload: 1, stop: 1,
20
+ dragdrop: 1, dragenter: 1, dragexit: 1, draggesture: 1, dragover: 1, contextmenu: 1, created: 2, removed: 2, sizechange: 2
21
+ };
22
+
23
+ export type DOMEventHandler = ( ev: Event ) => void;
24
+ type EventEntry = Record<string,DOMEventHandler | DOMEventHandler[]>;
25
+
26
+ const event_handlers = new WeakMap<Node,EventEntry>( );
27
+
28
+ /**
29
+ * handle dom mutations
30
+ */
31
+
32
+ let mutObserver: MutationObserver = null;
33
+
34
+ const observeMutation = (mutations: MutationRecord[], observer: MutationObserver): void => {
35
+
36
+ const sendEvent = ( node: Node, code: "created" | "removed" ) => {
37
+ // console.log( "notify", node, code );
38
+
39
+ const store = event_handlers.get( node );
40
+ if ( store && store[code] ) {
41
+ node.dispatchEvent( new Event( code, {} ) );
42
+ }
43
+ }
44
+
45
+ const notify = ( node: Node, create: boolean ) => {
46
+
47
+ if( create ) {
48
+ sendEvent( node, "created" );
49
+ }
50
+
51
+ for( let c=node.firstChild; c; c=c.nextSibling ) {
52
+ notify( c, create );
53
+ }
54
+
55
+ if( !create ) {
56
+ sendEvent( node, "removed" );
57
+ }
58
+ }
59
+
60
+
61
+ for (const mutation of mutations) {
62
+ if( mutation.type=="childList" ) {
63
+ if( mutation.addedNodes ) {
64
+ mutation.addedNodes.forEach( node => {
65
+ notify( node, true );
66
+ } );
67
+ }
68
+
69
+ if( mutation.removedNodes ) {
70
+ mutation.removedNodes.forEach( node => {
71
+ notify( node, false );
72
+ } );
73
+ }
74
+ }
75
+ }
76
+ }
77
+
78
+
79
+
80
+ /**
81
+ *
82
+ */
83
+
84
+ let sizeObserver: ResizeObserver = null;
85
+
86
+ function observeSize(entries: ResizeObserverEntry[]) {
87
+ entries.forEach((entry) => {
88
+ let dom = entry.target as HTMLElement;
89
+ if (dom.offsetParent !== null) {
90
+ dom.dispatchEvent( new Event('resized') );
91
+ }
92
+ });
93
+ }
94
+
95
+ /**
96
+ *
97
+ */
98
+
99
+ export function dispatchEvent(ev: Event) {
100
+
101
+ let target = ev.target as Node,
102
+ noup = (unbubbleEvents as any)[ev.type] === 2;
103
+
104
+ while (target) {
105
+ const store = event_handlers.get( target );
106
+ if ( store ) {
107
+ const callback = store[ev.type];
108
+ if( callback ) {
109
+ if( Array.isArray(callback) ) {
110
+ callback.some( c => c( ev ) );
111
+ }
112
+ else {
113
+ callback( ev );
114
+ }
115
+
116
+ if (ev.stopPropagation || ev.defaultPrevented || noup) {
117
+ break;
118
+ }
119
+ }
120
+ }
121
+
122
+ target = target.parentNode;
123
+
124
+ // no need to go above
125
+ if (target == document) {
126
+ break;
127
+ }
128
+ }
129
+ }
130
+
131
+ /**
132
+ *
133
+ */
134
+
135
+ export function addEvent( node: Node, name: string, handler: DOMEventHandler, prepend = false ) {
136
+
137
+ if( name=="removed" || name=="created" ) {
138
+ if( !mutObserver ) {
139
+ mutObserver = new MutationObserver( observeMutation )
140
+ mutObserver.observe( document.body, {childList: true,subtree: true} );
141
+ }
142
+ }
143
+ else if( name=="resized" ) {
144
+ if (!sizeObserver) {
145
+ sizeObserver = new ResizeObserver( observeSize );
146
+ }
147
+
148
+ sizeObserver.observe( node as Element );
149
+ }
150
+
151
+
152
+ let store = event_handlers.get( node );
153
+ if( !store ) {
154
+ store = {}
155
+ event_handlers.set( node, store );
156
+ }
157
+
158
+ if( !store[name] ) {
159
+ store[name] = handler;
160
+ node.addEventListener( name, dispatchEvent );
161
+ }
162
+ else {
163
+ const entry = store[name];
164
+ if( Array.isArray(entry) ) {
165
+ entry.push( handler );
166
+ }
167
+ else {
168
+ store[name] = [entry,handler];
169
+ }
170
+ }
171
+ }
172
+
173
+ /**
174
+ *
175
+ */
176
+
177
+ export interface GlobalDOMEvents {
178
+
179
+ /**
180
+ * Fires when the user aborts the download.
181
+ * @param ev The event.
182
+ */
183
+
184
+ abort?: (ev: UIEvent) => any;
185
+ animationcancel?: (ev: AnimationEvent) => any;
186
+ animationend?: (ev: AnimationEvent) => any;
187
+ animationiteration?: (ev: AnimationEvent) => any;
188
+ animationstart?: (ev: AnimationEvent) => any;
189
+ auxclick?: (ev: MouseEvent) => any;
190
+
191
+ /**
192
+ * Fires when the object loses the input focus.
193
+ * @param ev The focus event.
194
+ */
195
+ blur?: (ev: FocusEvent) => any;
196
+ cancel?: (ev: Event) => any;
197
+
198
+ /**
199
+ * Occurs when playback is possible, but would require further buffering.
200
+ * @param ev The event.
201
+ */
202
+ canplay?: (ev: Event) => any;
203
+ canplaythrough?: (ev: Event) => any;
204
+ /**
205
+ * Fires when the contents of the object or selection have changed.
206
+ * @param ev The event.
207
+ */
208
+ change?: (ev: Event) => any;
209
+ /**
210
+ * Fires when the user clicks the left mouse button on the object
211
+ * @param ev The mouse event.
212
+ */
213
+ click?: (ev: MouseEvent) => any;
214
+ close?: (ev: Event) => any;
215
+ /**
216
+ * Fires when the user clicks the right mouse button in the client area, opening the context menu.
217
+ * @param ev The mouse event.
218
+ */
219
+ contextmenu?: (ev: MouseEvent) => any;
220
+ cuechange?: (ev: Event) => any;
221
+ /**
222
+ * Fires when the user double-clicks the object.
223
+ * @param ev The mouse event.
224
+ */
225
+ dblclick?: (ev: MouseEvent) => any;
226
+ /**
227
+ * Fires on the source object continuously during a drag operation.
228
+ * @param ev The event.
229
+ */
230
+ drag?: (ev: DragEvent) => any;
231
+ /**
232
+ * Fires on the source object when the user releases the mouse at the close of a drag operation.
233
+ * @param ev The event.
234
+ */
235
+ dragend?: (ev: DragEvent) => any;
236
+ /**
237
+ * Fires on the target element when the user drags the object to a valid drop target.
238
+ * @param ev The drag event.
239
+ */
240
+ dragenter?: (ev: DragEvent) => any;
241
+ dragexit?: (ev: Event) => any;
242
+ /**
243
+ * Fires on the target object when the user moves the mouse out of a valid drop target during a drag operation.
244
+ * @param ev The drag event.
245
+ */
246
+ dragleave?: (ev: DragEvent) => any;
247
+ /**
248
+ * Fires on the target element continuously while the user drags the object over a valid drop target.
249
+ * @param ev The event.
250
+ */
251
+ dragover?: (ev: DragEvent) => any;
252
+ /**
253
+ * Fires on the source object when the user starts to drag a text selection or selected object.
254
+ * @param ev The event.
255
+ */
256
+ dragstart?: (ev: DragEvent) => any;
257
+ drop?: (ev: DragEvent) => any;
258
+ /**
259
+ * Occurs when the duration attribute is updated.
260
+ * @param ev The event.
261
+ */
262
+ durationchange?: (ev: Event) => any;
263
+ /**
264
+ * Occurs when the media element is reset to its initial state.
265
+ * @param ev The event.
266
+ */
267
+ emptied?: (ev: Event) => any;
268
+ /**
269
+ * Occurs when the end of playback is reached.
270
+ * @param ev The event
271
+ */
272
+ ended?: (ev: Event) => any;
273
+ /**
274
+ * Fires when an error occurs during object loading.
275
+ * @param ev The event.
276
+ */
277
+ error?: OnErrorEventHandler;
278
+ /**
279
+ * Fires when the object receives focus.
280
+ * @param ev The event.
281
+ */
282
+ focusin?: (ev: FocusEvent) => any;
283
+ focusout?: (ev: FocusEvent) => any;
284
+ focus?: (ev: FocusEvent) => any;
285
+ gotpointercapture?: (ev: PointerEvent) => any;
286
+ input?: (ev: Event) => any;
287
+ invalid?: (ev: Event) => any;
288
+ /**
289
+ * Fires when the user presses a key.
290
+ * @param ev The keyboard event
291
+ */
292
+ keydown?: (ev: KeyboardEvent) => any;
293
+ /**
294
+ * Fires when the user presses an alphanumeric key.
295
+ * @param ev The event.
296
+ */
297
+ keypress?: (ev: KeyboardEvent) => any;
298
+ /**
299
+ * Fires when the user releases a key.
300
+ * @param ev The keyboard event
301
+ */
302
+ keyup?: (ev: KeyboardEvent) => any;
303
+ /**
304
+ * Fires immediately after the browser loads the object.
305
+ * @param ev The event.
306
+ */
307
+ load?: (ev: Event) => any;
308
+ /**
309
+ * Occurs when media data is loaded at the current playback position.
310
+ * @param ev The event.
311
+ */
312
+ loadeddata?: (ev: Event) => any;
313
+ /**
314
+ * Occurs when the duration and dimensions of the media have been determined.
315
+ * @param ev The event.
316
+ */
317
+ loadedmetadata?: (ev: Event) => any;
318
+ /**
319
+ * Occurs when Internet Explorer begins looking for media data.
320
+ * @param ev The event.
321
+ */
322
+ loadstart?: (ev: Event) => any;
323
+ lostpointercapture?: (ev: PointerEvent) => any;
324
+ /**
325
+ * Fires when the user clicks the object with either mouse button.
326
+ * @param ev The mouse event.
327
+ */
328
+ mousedown?: (ev: MouseEvent) => any;
329
+ mouseenter?: (ev: MouseEvent) => any;
330
+ mouseleave?: (ev: MouseEvent) => any;
331
+ /**
332
+ * Fires when the user moves the mouse over the object.
333
+ * @param ev The mouse event.
334
+ */
335
+ mousemove?: (ev: MouseEvent) => any;
336
+ /**
337
+ * Fires when the user moves the mouse pointer outside the boundaries of the object.
338
+ * @param ev The mouse event.
339
+ */
340
+ mouseout?: (ev: MouseEvent) => any;
341
+ /**
342
+ * Fires when the user moves the mouse pointer into the object.
343
+ * @param ev The mouse event.
344
+ */
345
+ mouseover?: (ev: MouseEvent) => any;
346
+ /**
347
+ * Fires when the user releases a mouse button while the mouse is over the object.
348
+ * @param ev The mouse event.
349
+ */
350
+ mouseup?: (ev: MouseEvent) => any;
351
+ /**
352
+ * Occurs when playback is paused.
353
+ * @param ev The event.
354
+ */
355
+ pause?: (ev: Event) => any;
356
+ /**
357
+ * Occurs when the play method is requested.
358
+ * @param ev The event.
359
+ */
360
+ play?: (ev: Event) => any;
361
+ /**
362
+ * Occurs when the audio or video has started playing.
363
+ * @param ev The event.
364
+ */
365
+ playing?: (ev: Event) => any;
366
+ pointercancel?: (ev: PointerEvent) => any;
367
+ pointerdown?: (ev: PointerEvent) => any;
368
+ pointerenter?: (ev: PointerEvent) => any;
369
+ pointerleave?: (ev: PointerEvent) => any;
370
+ pointermove?: (ev: PointerEvent) => any;
371
+ pointerout?: (ev: PointerEvent) => any;
372
+ pointerover?: (ev: PointerEvent) => any;
373
+ pointerup?: (ev: PointerEvent) => any;
374
+ /**
375
+ * Occurs to indicate progress while downloading media data.
376
+ * @param ev The event.
377
+ */
378
+ progress?: (ev: ProgressEvent) => any;
379
+ /**
380
+ * Occurs when the playback rate is increased or decreased.
381
+ * @param ev The event.
382
+ */
383
+ ratechange?: (ev: Event) => any;
384
+ /**
385
+ * Fires when the user resets a form.
386
+ * @param ev The event.
387
+ */
388
+ reset?: (ev: Event) => any;
389
+ //resize?: (ev: UIEvent) => any; remove to avoid errors with sizechange event
390
+
391
+ /**
392
+ * Fires when the user repositions the scroll box in the scroll bar on the object.
393
+ * @param ev The event.
394
+ */
395
+ scroll?: (ev: Event) => any;
396
+ securitypolicyviolation?: (ev: SecurityPolicyViolationEvent) => any;
397
+ /**
398
+ * Occurs when the seek operation ends.
399
+ * @param ev The event.
400
+ */
401
+ seeked?: (ev: Event) => any;
402
+ /**
403
+ * Occurs when the current playback position is moved.
404
+ * @param ev The event.
405
+ */
406
+ seeking?: (ev: Event) => any;
407
+ /**
408
+ * Fires when the current selection changes.
409
+ * @param ev The event.
410
+ */
411
+ select?: (ev: Event) => any;
412
+ selectionchange?: (ev: Event) => any;
413
+ selectstart?: (ev: Event) => any;
414
+ /**
415
+ * Occurs when the download has stopped.
416
+ * @param ev The event.
417
+ */
418
+ stalled?: (ev: Event) => any;
419
+ submit?: (ev: Event) => any;
420
+
421
+ /**
422
+ * Occurs if the load operation has been intentionally halted.
423
+ * @param ev The event.
424
+ */
425
+ suspend?: (ev: Event) => any;
426
+
427
+ /**
428
+ * Occurs to indicate the current playback position.
429
+ * @param ev The event.
430
+ */
431
+ timeupdate?: (ev: Event) => any;
432
+ toggle?: (ev: Event) => any;
433
+ touchcancel?: (ev: TouchEvent) => any;
434
+ touchend?: (ev: TouchEvent) => any;
435
+ touchmove?: (ev: TouchEvent) => any;
436
+ touchstart?: (ev: TouchEvent) => any;
437
+ transitioncancel?: (ev: TransitionEvent) => any;
438
+ transitionend?: (ev: TransitionEvent) => any;
439
+ transitionrun?: (ev: TransitionEvent) => any;
440
+ transitionstart?: (ev: TransitionEvent) => any;
441
+
442
+ /**
443
+ * Occurs when the volume is changed, or playback is muted or unmuted.
444
+ * @param ev The event.
445
+ */
446
+ volumechange?: (ev: Event) => any;
447
+
448
+ /**
449
+ * Occurs when playback stops because the next frame of a video resource is not available.
450
+ * @param ev The event.
451
+ */
452
+ waiting?: (ev: Event) => any;
453
+ wheel?: (ev: WheelEvent) => any;
454
+
455
+ /**
456
+ * custom x4 events
457
+ */
458
+
459
+ resized?: (ev: Event) => void; // occurs when size changed
460
+ created?: ( ev: Event ) => void; // occurs when inserted in the dom
461
+ removed?: ( ev: Event ) => void; // occurs when removed from dom
462
+ }
463
+
464
+
465
+
466
+
467
+
468
+
469
+
470
+
471
+