x4js 2.0.1 → 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 (211) hide show
  1. package/package.json +12 -9
  2. package/lib/README.txt +0 -15
  3. package/lib/src/assets/house-light.svg +0 -1
  4. package/lib/src/assets/radio.svg +0 -4
  5. package/lib/src/components/base.scss +0 -26
  6. package/lib/src/components/boxes/boxes.module.scss +0 -37
  7. package/lib/src/components/boxes/boxes.ts +0 -125
  8. package/lib/src/components/btngroup/btngroup.module.scss +0 -29
  9. package/lib/src/components/btngroup/btngroup.ts +0 -106
  10. package/lib/src/components/button/button.module.scss +0 -154
  11. package/lib/src/components/button/button.ts +0 -117
  12. package/lib/src/components/calendar/calendar-check-sharp-light.svg +0 -1
  13. package/lib/src/components/calendar/calendar.module.scss +0 -163
  14. package/lib/src/components/calendar/calendar.ts +0 -326
  15. package/lib/src/components/calendar/chevron-left-sharp-light.svg +0 -1
  16. package/lib/src/components/calendar/chevron-right-sharp-light.svg +0 -1
  17. package/lib/src/components/checkbox/check.svg +0 -4
  18. package/lib/src/components/checkbox/checkbox.module.scss +0 -142
  19. package/lib/src/components/checkbox/checkbox.ts +0 -125
  20. package/lib/src/components/colorinput/colorinput.module.scss +0 -65
  21. package/lib/src/components/colorinput/colorinput.ts +0 -88
  22. package/lib/src/components/colorinput/crosshairs-simple-sharp-light.svg +0 -1
  23. package/lib/src/components/colorpicker/colorpicker.module.scss +0 -133
  24. package/lib/src/components/colorpicker/colorpicker.ts +0 -477
  25. package/lib/src/components/combobox/combobox.module.scss +0 -121
  26. package/lib/src/components/combobox/combobox.ts +0 -190
  27. package/lib/src/components/combobox/updown.svg +0 -4
  28. package/lib/src/components/dialog/dialog.module.scss +0 -71
  29. package/lib/src/components/dialog/dialog.ts +0 -91
  30. package/lib/src/components/dialog/xmark-sharp-light.svg +0 -1
  31. package/lib/src/components/form/form.module.scss +0 -34
  32. package/lib/src/components/form/form.ts +0 -36
  33. package/lib/src/components/header/header.module.scss +0 -40
  34. package/lib/src/components/header/header.ts +0 -124
  35. package/lib/src/components/icon/icon.module.scss +0 -30
  36. package/lib/src/components/icon/icon.ts +0 -134
  37. package/lib/src/components/image/image.module.scss +0 -21
  38. package/lib/src/components/image/image.ts +0 -67
  39. package/lib/src/components/input/input.module.scss +0 -69
  40. package/lib/src/components/input/input.ts +0 -274
  41. package/lib/src/components/label/label.module.scss +0 -52
  42. package/lib/src/components/label/label.ts +0 -55
  43. package/lib/src/components/listbox/listbox.module.scss +0 -103
  44. package/lib/src/components/listbox/listbox.ts +0 -427
  45. package/lib/src/components/menu/caret-right-solid.svg +0 -1
  46. package/lib/src/components/menu/menu.module.scss +0 -108
  47. package/lib/src/components/menu/menu.ts +0 -168
  48. package/lib/src/components/messages/circle-exclamation.svg +0 -1
  49. package/lib/src/components/messages/messages.module.scss +0 -47
  50. package/lib/src/components/messages/messages.ts +0 -64
  51. package/lib/src/components/normalize.scss +0 -386
  52. package/lib/src/components/notification/circle-check-solid.svg +0 -1
  53. package/lib/src/components/notification/circle-exclamation-solid.svg +0 -1
  54. package/lib/src/components/notification/circle-notch-light.svg +0 -1
  55. package/lib/src/components/notification/notification.module.scss +0 -82
  56. package/lib/src/components/notification/notification.ts +0 -108
  57. package/lib/src/components/notification/xmark-sharp-light.svg +0 -1
  58. package/lib/src/components/panel/panel.module.scss +0 -48
  59. package/lib/src/components/panel/panel.ts +0 -57
  60. package/lib/src/components/popup/popup.module.scss +0 -43
  61. package/lib/src/components/popup/popup.ts +0 -395
  62. package/lib/src/components/progress/progress.module.scss +0 -57
  63. package/lib/src/components/progress/progress.ts +0 -43
  64. package/lib/src/components/rating/rating.module.scss +0 -23
  65. package/lib/src/components/rating/rating.ts +0 -125
  66. package/lib/src/components/rating/star-sharp-light.svg +0 -1
  67. package/lib/src/components/rating/star-sharp-solid.svg +0 -1
  68. package/lib/src/components/shared.scss +0 -76
  69. package/lib/src/components/sizers/sizer.module.scss +0 -90
  70. package/lib/src/components/sizers/sizer.ts +0 -120
  71. package/lib/src/components/slider/slider.module.scss +0 -71
  72. package/lib/src/components/slider/slider.ts +0 -143
  73. package/lib/src/components/switch/switch.module.scss +0 -127
  74. package/lib/src/components/switch/switch.ts +0 -56
  75. package/lib/src/components/tabs/tabs.module.scss +0 -46
  76. package/lib/src/components/tabs/tabs.ts +0 -157
  77. package/lib/src/components/textarea/textarea.module.scss +0 -59
  78. package/lib/src/components/textarea/textarea.ts +0 -54
  79. package/lib/src/components/textedit/textedit.module.scss +0 -114
  80. package/lib/src/components/textedit/textedit.ts +0 -82
  81. package/lib/src/components/themes.scss +0 -77
  82. package/lib/src/components/tooltips/circle-info-sharp-light.svg +0 -1
  83. package/lib/src/components/tooltips/tooltips.scss +0 -51
  84. package/lib/src/components/tooltips/tooltips.ts +0 -103
  85. package/lib/src/components/treeview/chevron-down-light.svg +0 -1
  86. package/lib/src/components/treeview/treeview.module.scss +0 -116
  87. package/lib/src/components/treeview/treeview.ts +0 -403
  88. package/lib/src/components/viewport/viewport.module.scss +0 -25
  89. package/lib/src/components/viewport/viewport.ts +0 -38
  90. package/lib/src/core/component.ts +0 -979
  91. package/lib/src/core/core_colors.ts +0 -250
  92. package/lib/src/core/core_dom.ts +0 -471
  93. package/lib/src/core/core_dragdrop.ts +0 -201
  94. package/lib/src/core/core_element.ts +0 -98
  95. package/lib/src/core/core_events.ts +0 -149
  96. package/lib/src/core/core_i18n.ts +0 -377
  97. package/lib/src/core/core_router.ts +0 -221
  98. package/lib/src/core/core_styles.ts +0 -215
  99. package/lib/src/core/core_svg.ts +0 -550
  100. package/lib/src/core/core_tools.ts +0 -673
  101. package/lib/src/main.scss +0 -21
  102. package/lib/src/main.tsx +0 -323
  103. package/lib/src/x4.scss +0 -19
  104. package/lib/types/x4.d.ts +0 -2624
  105. package/scripts/build.mjs +0 -351
  106. package/scripts/prepack.mjs +0 -15
  107. package/src/assets/house-light.svg +0 -1
  108. package/src/assets/radio.svg +0 -4
  109. package/src/components/base.scss +0 -26
  110. package/src/components/boxes/boxes.module.scss +0 -37
  111. package/src/components/boxes/boxes.ts +0 -125
  112. package/src/components/btngroup/btngroup.module.scss +0 -29
  113. package/src/components/btngroup/btngroup.ts +0 -106
  114. package/src/components/button/button.module.scss +0 -154
  115. package/src/components/button/button.ts +0 -117
  116. package/src/components/calendar/calendar-check-sharp-light.svg +0 -1
  117. package/src/components/calendar/calendar.module.scss +0 -163
  118. package/src/components/calendar/calendar.ts +0 -326
  119. package/src/components/calendar/chevron-left-sharp-light.svg +0 -1
  120. package/src/components/calendar/chevron-right-sharp-light.svg +0 -1
  121. package/src/components/checkbox/check.svg +0 -4
  122. package/src/components/checkbox/checkbox.module.scss +0 -142
  123. package/src/components/checkbox/checkbox.ts +0 -125
  124. package/src/components/colorinput/colorinput.module.scss +0 -65
  125. package/src/components/colorinput/colorinput.ts +0 -88
  126. package/src/components/colorinput/crosshairs-simple-sharp-light.svg +0 -1
  127. package/src/components/colorpicker/colorpicker.module.scss +0 -133
  128. package/src/components/colorpicker/colorpicker.ts +0 -477
  129. package/src/components/combobox/combobox.module.scss +0 -121
  130. package/src/components/combobox/combobox.ts +0 -190
  131. package/src/components/combobox/updown.svg +0 -4
  132. package/src/components/dialog/dialog.module.scss +0 -71
  133. package/src/components/dialog/dialog.ts +0 -91
  134. package/src/components/dialog/xmark-sharp-light.svg +0 -1
  135. package/src/components/form/form.module.scss +0 -34
  136. package/src/components/form/form.ts +0 -36
  137. package/src/components/header/header.module.scss +0 -40
  138. package/src/components/header/header.ts +0 -124
  139. package/src/components/icon/icon.module.scss +0 -30
  140. package/src/components/icon/icon.ts +0 -134
  141. package/src/components/image/image.module.scss +0 -21
  142. package/src/components/image/image.ts +0 -67
  143. package/src/components/input/input.module.scss +0 -69
  144. package/src/components/input/input.ts +0 -274
  145. package/src/components/label/label.module.scss +0 -52
  146. package/src/components/label/label.ts +0 -55
  147. package/src/components/listbox/listbox.module.scss +0 -103
  148. package/src/components/listbox/listbox.ts +0 -427
  149. package/src/components/menu/caret-right-solid.svg +0 -1
  150. package/src/components/menu/menu.module.scss +0 -108
  151. package/src/components/menu/menu.ts +0 -168
  152. package/src/components/messages/circle-exclamation.svg +0 -1
  153. package/src/components/messages/messages.module.scss +0 -47
  154. package/src/components/messages/messages.ts +0 -64
  155. package/src/components/normalize.scss +0 -386
  156. package/src/components/notification/circle-check-solid.svg +0 -1
  157. package/src/components/notification/circle-exclamation-solid.svg +0 -1
  158. package/src/components/notification/circle-notch-light.svg +0 -1
  159. package/src/components/notification/notification.module.scss +0 -82
  160. package/src/components/notification/notification.ts +0 -108
  161. package/src/components/notification/xmark-sharp-light.svg +0 -1
  162. package/src/components/panel/panel.module.scss +0 -48
  163. package/src/components/panel/panel.ts +0 -57
  164. package/src/components/popup/popup.module.scss +0 -43
  165. package/src/components/popup/popup.ts +0 -395
  166. package/src/components/progress/progress.module.scss +0 -57
  167. package/src/components/progress/progress.ts +0 -43
  168. package/src/components/rating/rating.module.scss +0 -23
  169. package/src/components/rating/rating.ts +0 -125
  170. package/src/components/rating/star-sharp-light.svg +0 -1
  171. package/src/components/rating/star-sharp-solid.svg +0 -1
  172. package/src/components/shared.scss +0 -76
  173. package/src/components/sizers/sizer.module.scss +0 -90
  174. package/src/components/sizers/sizer.ts +0 -120
  175. package/src/components/slider/slider.module.scss +0 -71
  176. package/src/components/slider/slider.ts +0 -143
  177. package/src/components/switch/switch.module.scss +0 -127
  178. package/src/components/switch/switch.ts +0 -56
  179. package/src/components/tabs/tabs.module.scss +0 -46
  180. package/src/components/tabs/tabs.ts +0 -157
  181. package/src/components/textarea/textarea.module.scss +0 -59
  182. package/src/components/textarea/textarea.ts +0 -54
  183. package/src/components/textedit/textedit.module.scss +0 -114
  184. package/src/components/textedit/textedit.ts +0 -82
  185. package/src/components/themes.scss +0 -77
  186. package/src/components/tooltips/circle-info-sharp-light.svg +0 -1
  187. package/src/components/tooltips/tooltips.scss +0 -51
  188. package/src/components/tooltips/tooltips.ts +0 -103
  189. package/src/components/treeview/chevron-down-light.svg +0 -1
  190. package/src/components/treeview/treeview.module.scss +0 -116
  191. package/src/components/treeview/treeview.ts +0 -403
  192. package/src/components/viewport/viewport.module.scss +0 -25
  193. package/src/components/viewport/viewport.ts +0 -38
  194. package/src/core/component.ts +0 -979
  195. package/src/core/core_colors.ts +0 -250
  196. package/src/core/core_dom.ts +0 -471
  197. package/src/core/core_dragdrop.ts +0 -201
  198. package/src/core/core_element.ts +0 -98
  199. package/src/core/core_events.ts +0 -149
  200. package/src/core/core_i18n.ts +0 -377
  201. package/src/core/core_router.ts +0 -221
  202. package/src/core/core_styles.ts +0 -215
  203. package/src/core/core_svg.ts +0 -550
  204. package/src/core/core_tools.ts +0 -673
  205. package/src/main.scss +0 -21
  206. package/src/main.tsx +0 -323
  207. package/src/x4.scss +0 -19
  208. package/tsconfig.json +0 -14
  209. package/types/scss.d.ts +0 -4
  210. package/types/svg.d.ts +0 -4
  211. 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
-
package/lib/src/main.scss DELETED
@@ -1,21 +0,0 @@
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
- }