x4js 2.0.2 → 2.0.3

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 (221) hide show
  1. package/package.json +9 -7
  2. package/lib/README.txt +0 -15
  3. package/lib/esm/x4.css +0 -1
  4. package/lib/esm/x4.js +0 -1
  5. package/lib/src/assets/house-light.svg +0 -1
  6. package/lib/src/assets/radio.svg +0 -4
  7. package/lib/src/components/base.scss +0 -26
  8. package/lib/src/components/boxes/boxes.module.scss +0 -37
  9. package/lib/src/components/boxes/boxes.ts +0 -125
  10. package/lib/src/components/btngroup/btngroup.module.scss +0 -29
  11. package/lib/src/components/btngroup/btngroup.ts +0 -106
  12. package/lib/src/components/button/button.module.scss +0 -154
  13. package/lib/src/components/button/button.ts +0 -117
  14. package/lib/src/components/calendar/calendar-check-sharp-light.svg +0 -1
  15. package/lib/src/components/calendar/calendar.module.scss +0 -163
  16. package/lib/src/components/calendar/calendar.ts +0 -326
  17. package/lib/src/components/calendar/chevron-left-sharp-light.svg +0 -1
  18. package/lib/src/components/calendar/chevron-right-sharp-light.svg +0 -1
  19. package/lib/src/components/checkbox/check.svg +0 -4
  20. package/lib/src/components/checkbox/checkbox.module.scss +0 -142
  21. package/lib/src/components/checkbox/checkbox.ts +0 -125
  22. package/lib/src/components/colorinput/colorinput.module.scss +0 -65
  23. package/lib/src/components/colorinput/colorinput.ts +0 -88
  24. package/lib/src/components/colorinput/crosshairs-simple-sharp-light.svg +0 -1
  25. package/lib/src/components/colorpicker/colorpicker.module.scss +0 -133
  26. package/lib/src/components/colorpicker/colorpicker.ts +0 -477
  27. package/lib/src/components/combobox/combobox.module.scss +0 -121
  28. package/lib/src/components/combobox/combobox.ts +0 -190
  29. package/lib/src/components/combobox/updown.svg +0 -4
  30. package/lib/src/components/dialog/dialog.module.scss +0 -71
  31. package/lib/src/components/dialog/dialog.ts +0 -91
  32. package/lib/src/components/dialog/xmark-sharp-light.svg +0 -1
  33. package/lib/src/components/form/form.module.scss +0 -34
  34. package/lib/src/components/form/form.ts +0 -36
  35. package/lib/src/components/header/header.module.scss +0 -40
  36. package/lib/src/components/header/header.ts +0 -124
  37. package/lib/src/components/icon/icon.module.scss +0 -30
  38. package/lib/src/components/icon/icon.ts +0 -134
  39. package/lib/src/components/image/image.module.scss +0 -21
  40. package/lib/src/components/image/image.ts +0 -67
  41. package/lib/src/components/input/input.module.scss +0 -69
  42. package/lib/src/components/input/input.ts +0 -274
  43. package/lib/src/components/label/label.module.scss +0 -52
  44. package/lib/src/components/label/label.ts +0 -55
  45. package/lib/src/components/listbox/listbox.module.scss +0 -103
  46. package/lib/src/components/listbox/listbox.ts +0 -427
  47. package/lib/src/components/menu/caret-right-solid.svg +0 -1
  48. package/lib/src/components/menu/menu.module.scss +0 -108
  49. package/lib/src/components/menu/menu.ts +0 -168
  50. package/lib/src/components/messages/circle-exclamation.svg +0 -1
  51. package/lib/src/components/messages/messages.module.scss +0 -47
  52. package/lib/src/components/messages/messages.ts +0 -64
  53. package/lib/src/components/normalize.scss +0 -386
  54. package/lib/src/components/notification/circle-check-solid.svg +0 -1
  55. package/lib/src/components/notification/circle-exclamation-solid.svg +0 -1
  56. package/lib/src/components/notification/circle-notch-light.svg +0 -1
  57. package/lib/src/components/notification/notification.module.scss +0 -82
  58. package/lib/src/components/notification/notification.ts +0 -108
  59. package/lib/src/components/notification/xmark-sharp-light.svg +0 -1
  60. package/lib/src/components/panel/panel.module.scss +0 -48
  61. package/lib/src/components/panel/panel.ts +0 -57
  62. package/lib/src/components/popup/popup.module.scss +0 -43
  63. package/lib/src/components/popup/popup.ts +0 -395
  64. package/lib/src/components/progress/progress.module.scss +0 -57
  65. package/lib/src/components/progress/progress.ts +0 -43
  66. package/lib/src/components/rating/rating.module.scss +0 -23
  67. package/lib/src/components/rating/rating.ts +0 -125
  68. package/lib/src/components/rating/star-sharp-light.svg +0 -1
  69. package/lib/src/components/rating/star-sharp-solid.svg +0 -1
  70. package/lib/src/components/shared.scss +0 -76
  71. package/lib/src/components/sizers/sizer.module.scss +0 -90
  72. package/lib/src/components/sizers/sizer.ts +0 -120
  73. package/lib/src/components/slider/slider.module.scss +0 -71
  74. package/lib/src/components/slider/slider.ts +0 -143
  75. package/lib/src/components/switch/switch.module.scss +0 -127
  76. package/lib/src/components/switch/switch.ts +0 -56
  77. package/lib/src/components/tabs/tabs.module.scss +0 -46
  78. package/lib/src/components/tabs/tabs.ts +0 -157
  79. package/lib/src/components/textarea/textarea.module.scss +0 -59
  80. package/lib/src/components/textarea/textarea.ts +0 -54
  81. package/lib/src/components/textedit/textedit.module.scss +0 -114
  82. package/lib/src/components/textedit/textedit.ts +0 -82
  83. package/lib/src/components/themes.scss +0 -77
  84. package/lib/src/components/tooltips/circle-info-sharp-light.svg +0 -1
  85. package/lib/src/components/tooltips/tooltips.scss +0 -51
  86. package/lib/src/components/tooltips/tooltips.ts +0 -103
  87. package/lib/src/components/treeview/chevron-down-light.svg +0 -1
  88. package/lib/src/components/treeview/treeview.module.scss +0 -116
  89. package/lib/src/components/treeview/treeview.ts +0 -403
  90. package/lib/src/components/viewport/viewport.module.scss +0 -25
  91. package/lib/src/components/viewport/viewport.ts +0 -38
  92. package/lib/src/core/component.ts +0 -979
  93. package/lib/src/core/core_colors.ts +0 -250
  94. package/lib/src/core/core_dom.ts +0 -471
  95. package/lib/src/core/core_dragdrop.ts +0 -201
  96. package/lib/src/core/core_element.ts +0 -98
  97. package/lib/src/core/core_events.ts +0 -149
  98. package/lib/src/core/core_i18n.ts +0 -377
  99. package/lib/src/core/core_router.ts +0 -221
  100. package/lib/src/core/core_styles.ts +0 -215
  101. package/lib/src/core/core_svg.ts +0 -550
  102. package/lib/src/core/core_tools.ts +0 -673
  103. package/lib/src/demo/assets/house-light.svg +0 -1
  104. package/lib/src/demo/assets/radio.svg +0 -4
  105. package/lib/src/demo/index.html +0 -12
  106. package/lib/src/demo/main.scss +0 -21
  107. package/lib/src/demo/main.tsx +0 -323
  108. package/lib/src/main.scss +0 -21
  109. package/lib/src/main.tsx +0 -323
  110. package/lib/src/x4.scss +0 -19
  111. package/lib/src/x4.ts +0 -60
  112. package/lib/types/x4.d.ts +0 -26548
  113. package/scripts/build.mjs +0 -351
  114. package/scripts/prepack.mjs +0 -43
  115. package/src/components/base.scss +0 -26
  116. package/src/components/boxes/boxes.module.scss +0 -37
  117. package/src/components/boxes/boxes.ts +0 -125
  118. package/src/components/btngroup/btngroup.module.scss +0 -29
  119. package/src/components/btngroup/btngroup.ts +0 -106
  120. package/src/components/button/button.module.scss +0 -154
  121. package/src/components/button/button.ts +0 -117
  122. package/src/components/calendar/calendar-check-sharp-light.svg +0 -1
  123. package/src/components/calendar/calendar.module.scss +0 -163
  124. package/src/components/calendar/calendar.ts +0 -326
  125. package/src/components/calendar/chevron-left-sharp-light.svg +0 -1
  126. package/src/components/calendar/chevron-right-sharp-light.svg +0 -1
  127. package/src/components/checkbox/check.svg +0 -4
  128. package/src/components/checkbox/checkbox.module.scss +0 -142
  129. package/src/components/checkbox/checkbox.ts +0 -125
  130. package/src/components/colorinput/colorinput.module.scss +0 -65
  131. package/src/components/colorinput/colorinput.ts +0 -88
  132. package/src/components/colorinput/crosshairs-simple-sharp-light.svg +0 -1
  133. package/src/components/colorpicker/colorpicker.module.scss +0 -133
  134. package/src/components/colorpicker/colorpicker.ts +0 -477
  135. package/src/components/combobox/combobox.module.scss +0 -121
  136. package/src/components/combobox/combobox.ts +0 -190
  137. package/src/components/combobox/updown.svg +0 -4
  138. package/src/components/dialog/dialog.module.scss +0 -71
  139. package/src/components/dialog/dialog.ts +0 -91
  140. package/src/components/dialog/xmark-sharp-light.svg +0 -1
  141. package/src/components/form/form.module.scss +0 -34
  142. package/src/components/form/form.ts +0 -36
  143. package/src/components/header/header.module.scss +0 -40
  144. package/src/components/header/header.ts +0 -124
  145. package/src/components/icon/icon.module.scss +0 -30
  146. package/src/components/icon/icon.ts +0 -134
  147. package/src/components/image/image.module.scss +0 -21
  148. package/src/components/image/image.ts +0 -67
  149. package/src/components/input/input.module.scss +0 -69
  150. package/src/components/input/input.ts +0 -274
  151. package/src/components/label/label.module.scss +0 -52
  152. package/src/components/label/label.ts +0 -55
  153. package/src/components/listbox/listbox.module.scss +0 -103
  154. package/src/components/listbox/listbox.ts +0 -427
  155. package/src/components/menu/caret-right-solid.svg +0 -1
  156. package/src/components/menu/menu.module.scss +0 -108
  157. package/src/components/menu/menu.ts +0 -168
  158. package/src/components/messages/circle-exclamation.svg +0 -1
  159. package/src/components/messages/messages.module.scss +0 -47
  160. package/src/components/messages/messages.ts +0 -64
  161. package/src/components/normalize.scss +0 -386
  162. package/src/components/notification/circle-check-solid.svg +0 -1
  163. package/src/components/notification/circle-exclamation-solid.svg +0 -1
  164. package/src/components/notification/circle-notch-light.svg +0 -1
  165. package/src/components/notification/notification.module.scss +0 -82
  166. package/src/components/notification/notification.ts +0 -108
  167. package/src/components/notification/xmark-sharp-light.svg +0 -1
  168. package/src/components/panel/panel.module.scss +0 -48
  169. package/src/components/panel/panel.ts +0 -57
  170. package/src/components/popup/popup.module.scss +0 -43
  171. package/src/components/popup/popup.ts +0 -395
  172. package/src/components/progress/progress.module.scss +0 -57
  173. package/src/components/progress/progress.ts +0 -43
  174. package/src/components/rating/rating.module.scss +0 -23
  175. package/src/components/rating/rating.ts +0 -125
  176. package/src/components/rating/star-sharp-light.svg +0 -1
  177. package/src/components/rating/star-sharp-solid.svg +0 -1
  178. package/src/components/shared.scss +0 -76
  179. package/src/components/sizers/sizer.module.scss +0 -90
  180. package/src/components/sizers/sizer.ts +0 -120
  181. package/src/components/slider/slider.module.scss +0 -71
  182. package/src/components/slider/slider.ts +0 -143
  183. package/src/components/switch/switch.module.scss +0 -127
  184. package/src/components/switch/switch.ts +0 -56
  185. package/src/components/tabs/tabs.module.scss +0 -46
  186. package/src/components/tabs/tabs.ts +0 -157
  187. package/src/components/textarea/textarea.module.scss +0 -59
  188. package/src/components/textarea/textarea.ts +0 -54
  189. package/src/components/textedit/textedit.module.scss +0 -114
  190. package/src/components/textedit/textedit.ts +0 -82
  191. package/src/components/themes.scss +0 -77
  192. package/src/components/tooltips/circle-info-sharp-light.svg +0 -1
  193. package/src/components/tooltips/tooltips.scss +0 -51
  194. package/src/components/tooltips/tooltips.ts +0 -103
  195. package/src/components/treeview/chevron-down-light.svg +0 -1
  196. package/src/components/treeview/treeview.module.scss +0 -116
  197. package/src/components/treeview/treeview.ts +0 -403
  198. package/src/components/viewport/viewport.module.scss +0 -25
  199. package/src/components/viewport/viewport.ts +0 -38
  200. package/src/core/component.ts +0 -979
  201. package/src/core/core_colors.ts +0 -250
  202. package/src/core/core_dom.ts +0 -471
  203. package/src/core/core_dragdrop.ts +0 -201
  204. package/src/core/core_element.ts +0 -98
  205. package/src/core/core_events.ts +0 -149
  206. package/src/core/core_i18n.ts +0 -377
  207. package/src/core/core_router.ts +0 -221
  208. package/src/core/core_styles.ts +0 -215
  209. package/src/core/core_svg.ts +0 -550
  210. package/src/core/core_tools.ts +0 -673
  211. package/src/demo/assets/house-light.svg +0 -1
  212. package/src/demo/assets/radio.svg +0 -4
  213. package/src/demo/index.html +0 -12
  214. package/src/demo/main.scss +0 -21
  215. package/src/demo/main.tsx +0 -323
  216. package/src/x4.scss +0 -19
  217. package/src/x4.ts +0 -60
  218. package/tsconfig.json +0 -14
  219. package/types/scss.d.ts +0 -4
  220. package/types/svg.d.ts +0 -4
  221. package/types/x4react.d.ts +0 -9
@@ -1,673 +0,0 @@
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
-
@@ -1 +0,0 @@
1
- <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 576 512" fill="currentColor"><!--!Font Awesome Pro 6.6.0 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license (Commercial License) Copyright 2024 Fonticons, Inc.--><path d="M298.6 4c-6-5.3-15.1-5.3-21.2 0L5.4 244c-6.6 5.8-7.3 16-1.4 22.6s16 7.3 22.6 1.4L64 235l0 197c0 44.2 35.8 80 80 80l288 0c44.2 0 80-35.8 80-80l0-197 37.4 33c6.6 5.8 16.7 5.2 22.6-1.4s5.2-16.7-1.4-22.6L298.6 4zM96 432l0-225.3L288 37.3 480 206.7 480 432c0 26.5-21.5 48-48 48l-64 0 0-160c0-17.7-14.3-32-32-32l-96 0c-17.7 0-32 14.3-32 32l0 160-64 0c-26.5 0-48-21.5-48-48zm144 48l0-160 96 0 0 160-96 0z"/></svg>
@@ -1,4 +0,0 @@
1
- <svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 5 5" aria-hidden="true">
2
- <circle cx="2.5" cy="2.5" r="2.5" fill="currentColor"></circle>
3
- <circle cx="2.5" cy="2.5" r="1.25" fill="white"></circle>
4
- </svg>
@@ -1,12 +0,0 @@
1
- <!doctype html>
2
- <html lang="en">
3
- <head>
4
- <meta charset="UTF-8" />
5
- <meta name="viewport" content="width=device-width, initial-scale=1.0" />
6
- <link rel="stylesheet" href="./main.css">
7
- </head>
8
- <body>
9
- <noscript>JavaScript required</noscript>
10
- <script src="./main.js"></script>
11
- </body>
12
- </html>
@@ -1,21 +0,0 @@
1
- /**
2
- * ___ ___ __
3
- * \ \/ / / _
4
- * \ / /_| |_
5
- * / \____ _|
6
- * /__/\__\ |_|
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
- }