x4js 1.6.4 → 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,673 @@
1
+ /**
2
+ * ___ ___ __
3
+ * \ \/ / / _
4
+ * \ / /_| |_
5
+ * / \____ _|
6
+ * /__/\__\ |_|
7
+ *
8
+ * @file core_tools.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 { _tr } from "./core_i18n.js";
18
+
19
+ /**
20
+ * @returns true if object is a string
21
+ */
22
+ export function isString(val: any): val is string {
23
+ return typeof val === 'string';
24
+ }
25
+
26
+ /**
27
+ * @returns true if object is a number
28
+ */
29
+
30
+ export function isNumber( v: any ): v is number {
31
+ return typeof v === 'number' && isFinite(v);
32
+ }
33
+
34
+ /**
35
+ * @returns true if object is an array
36
+ */
37
+ export function isArray(val: any): val is any[] {
38
+ return val instanceof Array;
39
+ }
40
+
41
+ /**
42
+ * @returns true if object is a function
43
+ */
44
+
45
+ export function isFunction(val: any): val is Function {
46
+ return val instanceof Function;
47
+ }
48
+
49
+ /**
50
+ * generic constructor
51
+ */
52
+
53
+ export type Constructor<P> = {
54
+ new(...params: any[]): P;
55
+ };
56
+
57
+
58
+ /**
59
+ * a way to explain that the given string may be unsafe but must be treated a sstring
60
+ * @example
61
+ * label.setText( unsafehtml`<b>Bold</b> text` );
62
+ * label.setText( new UnsafeHtml("<b>Bold</b> text`" ) );
63
+ */
64
+
65
+ export class UnsafeHtml extends String {
66
+ constructor( value: string ) {
67
+ super( value );
68
+ }
69
+ }
70
+
71
+ export function unsafeHtml( x: string ): UnsafeHtml {
72
+ return new UnsafeHtml( x );
73
+ }
74
+
75
+ /**
76
+ *
77
+ */
78
+
79
+ export function clamp<T>( v: T, min: T, max: T ) : T {
80
+ if( v<min ) { return min; }
81
+ if( v>max ) { return max; }
82
+ return v;
83
+ }
84
+
85
+
86
+ /**
87
+ * generic Rectangle
88
+ */
89
+
90
+ export interface IRect {
91
+ left: number;
92
+ top: number;
93
+ height: number;
94
+ width: number;
95
+ }
96
+
97
+ /**
98
+ *
99
+ */
100
+
101
+ export class Rect implements IRect {
102
+ left: number;
103
+ top: number;
104
+ height: number;
105
+ width: number;
106
+
107
+ constructor( );
108
+ constructor( l: number, t: number, w: number, h: number );
109
+ constructor( l: Rect );
110
+ constructor( l?: number | IRect, t?: number, w?: number, h?: number ) {
111
+ if( l!==undefined ) {
112
+ if( isNumber( l ) ) {
113
+ this.left = l;
114
+ this.top = t;
115
+ this.width = w;
116
+ this.height = h;
117
+ }
118
+ else {
119
+ Object.assign( this, l );
120
+ }
121
+ }
122
+ }
123
+
124
+ get right( ) {
125
+ return this.left+this.width;
126
+ }
127
+
128
+ get bottom( ) {
129
+ return this.top+this.height;
130
+ }
131
+ }
132
+
133
+
134
+ /**
135
+ * generic Point
136
+ */
137
+
138
+ export interface Point {
139
+ x: number;
140
+ y: number;
141
+ }
142
+
143
+ /**
144
+ *
145
+ */
146
+
147
+ export interface IComponentInterface {
148
+ }
149
+
150
+ // form-element
151
+ export interface IFormElement extends IComponentInterface {
152
+ getRawValue( ): any;
153
+ setRawValue( v: any ): void;
154
+ }
155
+
156
+ /**
157
+ *
158
+ */
159
+
160
+ interface Features {
161
+ eyedropper: 1,
162
+ }
163
+
164
+ export function isFeatureAvailable( name: keyof Features ): boolean {
165
+ switch( name ) {
166
+ case "eyedropper": return "EyeDropper" in window;
167
+ }
168
+
169
+ return false;
170
+ }
171
+
172
+ export class Timer {
173
+
174
+ protected _timers: Map<string,any>;
175
+
176
+ /**
177
+ *
178
+ */
179
+
180
+ setTimeout( name: string, time: number, callback: Function ) {
181
+ if( !this._timers ) {
182
+ this._timers = new Map( );
183
+ }
184
+ else {
185
+ this.clearTimeout( name );
186
+ }
187
+
188
+ const tm = setTimeout( callback, time );
189
+ this._timers.set( name, tm );
190
+
191
+ return tm;
192
+ }
193
+
194
+ clearTimeout( name: string ) {
195
+ if( this._timers && this._timers.has(name) ) {
196
+ clearTimeout( this._timers.get(name) );
197
+ this._timers.delete( name );
198
+ }
199
+ }
200
+
201
+ /**
202
+ *
203
+ */
204
+
205
+ setInterval( name: string, time: number, callback: Function ) {
206
+ if( !this._timers ) {
207
+ this._timers = new Map( );
208
+ }
209
+ else {
210
+ this.clearInterval( name );
211
+ }
212
+
213
+ const tm = setInterval( callback, time );
214
+ this._timers.set( name, tm );
215
+
216
+ return tm;
217
+ }
218
+
219
+ clearInterval( name: string ) {
220
+ if( this._timers && this._timers.has(name) ) {
221
+ clearInterval( this._timers.get(name) );
222
+ this._timers.delete( name );
223
+ }
224
+ }
225
+
226
+ clearAllTimeouts( ) {
227
+ this._timers?.forEach( t => {
228
+ clearTimeout( t );
229
+ } );
230
+
231
+ this._timers = null;
232
+ }
233
+ }
234
+
235
+ /**
236
+ *
237
+ */
238
+
239
+ export function asap( callback: ( ) => void ) {
240
+ return requestAnimationFrame( callback );
241
+ }
242
+
243
+
244
+ // :: STRING UTILS ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
245
+
246
+
247
+ /**
248
+ * prepend 0 to a value to a given length
249
+ * @param value
250
+ * @param length
251
+ */
252
+
253
+ export function pad(what: any, size: number, ch: string = '0') {
254
+
255
+ let value: string;
256
+
257
+ if (!isString(what)) {
258
+ value = '' + what;
259
+ }
260
+ else {
261
+ value = what;
262
+ }
263
+
264
+ if (size > 0) {
265
+ return value.padEnd(size, ch);
266
+ }
267
+ else {
268
+ return value.padStart(-size, ch);
269
+ }
270
+ }
271
+
272
+ /**
273
+ * replace {0..9} by given arguments
274
+ * @param format string
275
+ * @param args
276
+ *
277
+ * @example ```ts
278
+ *
279
+ * console.log( sprintf( 'here is arg 1 {1} and arg 0 {0}', 'argument 0', 'argument 1' ) )
280
+ */
281
+
282
+ export function sprintf( format: string, ...args:any[] ) {
283
+ return format.replace(/{(\d+)}/g, function (match, index) {
284
+ return typeof args[index] != 'undefined' ? args[index] : match;
285
+ });
286
+ }
287
+
288
+ /**
289
+ * inverse of camel case
290
+ * theThingToCase -> the-thing-to-case
291
+ * @param {String} str
292
+ */
293
+
294
+ export function pascalCase(string: string): string {
295
+
296
+ let result = string;
297
+
298
+ result = result.replace(/([a-z])([A-Z])/g, "$1 $2");
299
+ result = result.toLowerCase();
300
+ result = result.replace(/[^- a-z0-9]+/g, ' ');
301
+
302
+ if (result.indexOf(' ') < 0) {
303
+ return result;
304
+ }
305
+
306
+ result = result.trim();
307
+ return result.replace(/ /g, '-');
308
+ }
309
+
310
+ export function camelCase( text: string ) {
311
+ let result = text.toLowerCase( );
312
+ result = result.replace( /[^a-zA-Z0-9]+(.)/g, (m,chr) => {
313
+ return chr.toUpperCase();
314
+ } );
315
+ return result;
316
+ }
317
+
318
+ // :: DATES ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
319
+
320
+ let cur_locale: string = 'fr-FR';
321
+
322
+ /**
323
+ * change the current locale for misc translations (date...)
324
+ * @param locale
325
+ */
326
+
327
+ export function _date_set_locale(locale: string) {
328
+ cur_locale = locale;
329
+ }
330
+
331
+ /**
332
+ *
333
+ * @param date
334
+ * @param options
335
+ * @example
336
+ * let date = new Date( );
337
+ * let options = { day: 'numeric', month: 'numeric', year: 'numeric', hour: 'numeric', minute: 'numeric' };
338
+ * let text = date_format( date, options );
339
+ */
340
+
341
+ export function date_format(date: Date, options?: any): string {
342
+ //return new Intl.DateTimeFormat(cur_locale, options).format( date );
343
+ return formatIntlDate(date);
344
+ }
345
+
346
+ /**
347
+ *
348
+ * @param date
349
+ * @param options
350
+ */
351
+
352
+ export function date_diff(date1: Date, date2: Date, options?: any): string {
353
+
354
+ var dt = (date1.getTime() - date2.getTime()) / 1000;
355
+
356
+ // seconds
357
+ let sec = dt;
358
+ if (sec < 60) {
359
+ return sprintf(_tr.global.diff_date_seconds, Math.round(sec));
360
+ }
361
+
362
+ // minutes
363
+ let min = Math.floor(sec / 60);
364
+ if (min < 60) {
365
+ return sprintf(_tr.global.diff_date_minutes, Math.round(min));
366
+ }
367
+
368
+ // hours
369
+ let hrs = Math.floor(min / 60);
370
+ return sprintf(_tr.global.diff_date_hours, hrs, min % 60);
371
+ }
372
+
373
+ export function date_to_sql(date: Date, withHours: boolean) {
374
+
375
+ if (withHours) {
376
+ return formatIntlDate(date, 'Y-M-D H:I:S');
377
+ }
378
+ else {
379
+ return formatIntlDate(date, 'Y-M-D');
380
+ }
381
+ }
382
+
383
+ /**
384
+ * construct a date from an utc date time (sql format)
385
+ * YYYY-MM-DD HH:MM:SS
386
+ */
387
+
388
+ export function date_sql_utc(date: string): Date {
389
+ let result = new Date(date + ' GMT');
390
+ return result;
391
+ }
392
+
393
+
394
+
395
+ /**
396
+ * return a number that is a representation of the date
397
+ * this number can be compared with another hash
398
+ */
399
+
400
+ export function date_hash(date: Date): number {
401
+ return date.getFullYear() << 16 | date.getMonth() << 8 | date.getDate();
402
+ }
403
+
404
+ /**
405
+ * return a copy of a date
406
+ */
407
+
408
+ export function date_clone(date: Date): Date {
409
+ return new Date(date.getTime());
410
+ }
411
+
412
+ /**
413
+ * return the week number of a date
414
+ */
415
+
416
+ export function date_calc_weeknum(date: Date): number {
417
+ const firstDayOfYear = new Date(date.getFullYear(), 0, 1);
418
+ const pastDaysOfYear = (date.valueOf() - firstDayOfYear.valueOf()) / 86400000;
419
+ return Math.floor((pastDaysOfYear + firstDayOfYear.getDay() + 1) / 7);
420
+ }
421
+
422
+
423
+
424
+ /**
425
+ * parse a date according to the given format
426
+ * @param value - string date to parse
427
+ * @param fmts - format list - i18 tranlation by default
428
+ * allowed format specifiers:
429
+ * d or D: date (1 or 2 digits)
430
+ * m or M: month (1 or 2 digits)
431
+ * y or Y: year (2 or 4 digits)
432
+ * h or H: hours (1 or 2 digits)
433
+ * i or I: minutes (1 or 2 digits)
434
+ * s or S: seconds (1 or 2 digits)
435
+ * <space>: 1 or more spaces
436
+ * any other char: <0 or more spaces><the char><0 or more spaces>
437
+ * each specifiers is separated from other by a pipe (|)
438
+ * more specific at first
439
+ * @example
440
+ * 'd/m/y|d m Y|dmy|y-m-d h:i:s|y-m-d'
441
+ */
442
+
443
+ export function parseIntlDate(value: string, fmts: string = _tr.global.date_input_formats): Date {
444
+
445
+ let formats = fmts.split('|');
446
+ for (let fmatch of formats) {
447
+
448
+ //review: could do that only once & keep result
449
+ //review: add hours, minutes, seconds
450
+
451
+ let smatch = '';
452
+ for (let c of fmatch) {
453
+
454
+ if (c == 'd' || c == 'D') {
455
+ smatch += '(?<day>\\d{1,2})';
456
+ }
457
+ else if (c == 'm' || c == 'M') {
458
+ smatch += '(?<month>\\d{1,2})';
459
+ }
460
+ else if (c == 'y' || c == 'Y') {
461
+ smatch += '(?<year>\\d{1,4})';
462
+ }
463
+ else if (c == 'h' || c == 'H') {
464
+ smatch += '(?<hour>\\d{1,2})';
465
+ }
466
+ else if (c == 'i' || c == 'I') {
467
+ smatch += '(?<min>\\d{1,2})';
468
+ }
469
+ else if (c == 's' || c == 'S') {
470
+ smatch += '(?<sec>\\d{1,2})';
471
+ }
472
+ else if (c == ' ') {
473
+ smatch += '\\s+';
474
+ }
475
+ else {
476
+ smatch += '\\s*\\' + c + '\\s*';
477
+ }
478
+ }
479
+
480
+ let rematch = new RegExp('^' + smatch + '$', 'm');
481
+
482
+ let match = rematch.exec(value);
483
+
484
+ if (match) {
485
+ const now = new Date( );
486
+
487
+ let d = parseInt(match.groups.day ?? '1');
488
+ let m = parseInt(match.groups.month ?? '1');
489
+ let y = parseInt(match.groups.year ?? now.getFullYear()+'');
490
+ let h = parseInt(match.groups.hour ?? '0');
491
+ let i = parseInt(match.groups.min ?? '0');
492
+ let s = parseInt(match.groups.sec ?? '0');
493
+
494
+ if (y > 0 && y < 100) {
495
+ y += 2000;
496
+ }
497
+
498
+ let result = new Date(y, m - 1, d, h, i, s, 0);
499
+
500
+ // we test the vdate validity (without adjustments)
501
+ // without this test, date ( 0, 0, 0) is accepted and transformed to 1969/11/31 (not fun)
502
+ let ty = result.getFullYear(),
503
+ tm = result.getMonth() + 1,
504
+ td = result.getDate();
505
+
506
+ if (ty != y || tm != m || td != d) {
507
+ //debugger;
508
+ return null;
509
+ }
510
+
511
+ return result;
512
+ }
513
+ }
514
+
515
+ return null;
516
+ }
517
+
518
+ /**
519
+ * format a date as string
520
+ * @param date - date to format
521
+ * @param fmt - format
522
+ * format specifiers:
523
+ * d: date (no pad)
524
+ * D: 2 digits date padded with 0
525
+ * j: day of week short mode 'mon'
526
+ * J: day of week long mode 'monday'
527
+ * w: week number
528
+ * m: month (no pad)
529
+ * M: 2 digits month padded with 0
530
+ * o: month short mode 'jan'
531
+ * O: month long mode 'january'
532
+ * y or Y: year
533
+ * h: hour (24 format)
534
+ * H: 2 digits hour (24 format) padded with 0
535
+ * i: minutes
536
+ * I: 2 digits minutes padded with 0
537
+ * s: seconds
538
+ * S: 2 digits seconds padded with 0
539
+ * a: am or pm
540
+ * anything else is inserted
541
+ * if you need to insert some text, put it between {}
542
+ *
543
+ * @example
544
+ *
545
+ * 01/01/1970 11:25:00 with '{this is my demo date formatter: }H-i*M'
546
+ * "this is my demo date formatter: 11-25*january"
547
+ */
548
+
549
+ export function formatIntlDate(date: Date, fmt: string = _tr.global.date_format) {
550
+
551
+ if (!date) {
552
+ return '';
553
+ }
554
+
555
+ let now = {
556
+ year: date.getFullYear(),
557
+ month: date.getMonth() + 1,
558
+ day: date.getDate(),
559
+ wday: date.getDay(),
560
+ hours: date.getHours(),
561
+ minutes: date.getMinutes(),
562
+ seconds: date.getSeconds(),
563
+ milli: date.getMilliseconds()
564
+ };
565
+
566
+
567
+ let result = '';
568
+ let esc = 0;
569
+
570
+ for (let c of fmt) {
571
+
572
+ if (c == '{') {
573
+ if (++esc == 1) {
574
+ continue;
575
+ }
576
+ }
577
+ else if (c == '}') {
578
+ if (--esc == 0) {
579
+ continue;
580
+ }
581
+ }
582
+
583
+ if (esc) {
584
+ result += c;
585
+ continue;
586
+ }
587
+
588
+ if (c == 'd') {
589
+ result += now.day;
590
+ }
591
+ else if (c == 'D') {
592
+ result += pad(now.day, -2);
593
+ }
594
+ else if (c == 'j') { // day short
595
+ result += _tr.global.day_short[now.wday];
596
+ }
597
+ else if (c == 'J') { // day long
598
+ result += _tr.global.day_long[now.wday];
599
+ }
600
+ else if (c == 'w') { // week
601
+ result += date_calc_weeknum(date);
602
+ }
603
+ else if (c == 'W') { // week
604
+ result += pad(date_calc_weeknum(date), -2);
605
+ }
606
+ else if (c == 'm') {
607
+ result += now.month;
608
+ }
609
+ else if (c == 'M') {
610
+ result += pad(now.month, -2);
611
+ }
612
+ else if (c == 'o') { // month short
613
+ result += _tr.global.month_short[now.month - 1];
614
+ }
615
+ else if (c == 'O') { // month long
616
+ result += _tr.global.month_long[now.month - 1];
617
+ }
618
+ else if (c == 'y' || c == 'Y') {
619
+ result += pad(now.year, -4);
620
+ }
621
+ else if (c == 'a' || c == 'A') {
622
+ result += now.hours < 12 ? 'am' : 'pm';
623
+ }
624
+ else if (c == 'h') {
625
+ result += now.hours;
626
+ }
627
+ else if (c == 'H') {
628
+ result += pad(now.hours, -2);
629
+ }
630
+ else if (c == 'i') {
631
+ result += now.minutes;
632
+ }
633
+ else if (c == 'I') {
634
+ result += pad(now.minutes, -2);
635
+ }
636
+ else if (c == 's') {
637
+ result += now.seconds;
638
+ }
639
+ else if (c == 'S') {
640
+ result += pad(now.seconds, -2);
641
+ }
642
+ else if (c == 'l') {
643
+ result += now.milli;
644
+ }
645
+ else if (c == 'L') {
646
+ result += pad(now.milli, -3);
647
+ }
648
+ else {
649
+ result += c;
650
+ }
651
+ }
652
+
653
+ return result;
654
+ }
655
+
656
+ export function calcAge(birth: Date, ref?: Date) {
657
+ if (ref === undefined) {
658
+ ref = new Date();
659
+ }
660
+
661
+ if (!birth) {
662
+ return 0;
663
+ }
664
+
665
+ let age = ref.getFullYear() - birth.getFullYear();
666
+ if (ref.getMonth() < birth.getMonth() || (ref.getMonth() == birth.getMonth() && ref.getDate() < birth.getDate())) {
667
+ age--;
668
+ }
669
+
670
+ return age;
671
+ }
672
+
673
+
package/src/main.scss ADDED
@@ -0,0 +1,21 @@
1
+ /**
2
+ * ___ ___ __
3
+ * \ \/ / / _
4
+ * \ / /_| |_
5
+ * / \____ _|
6
+ * /__/\__\ |_|.2
7
+ *
8
+ * @file main.scss
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
+ @use "./x4.scss" ;
18
+
19
+ body {
20
+ padding: 16px;
21
+ }