x4js 1.5.17 → 1.5.20

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 (242) hide show
  1. package/lib/{README.md → README.txt} +0 -0
  2. package/lib/cjs/index.js +39 -103
  3. package/lib/cjs/index.js.map +7 -0
  4. package/lib/esm/index.mjs +39 -87
  5. package/lib/esm/index.mjs.map +7 -0
  6. package/lib/{license.md → licence.md} +0 -0
  7. package/lib/src/MIT-license.md +14 -0
  8. package/lib/{types/action.d.ts → src/action.ts} +64 -33
  9. package/lib/src/alpha.jpg +0 -0
  10. package/lib/src/app_sockets.ts +81 -0
  11. package/lib/src/application.ts +251 -0
  12. package/lib/src/autocomplete.ts +197 -0
  13. package/lib/src/base64.ts +166 -0
  14. package/lib/src/base_component.ts +152 -0
  15. package/lib/src/button.ts +355 -0
  16. package/lib/src/calendar.ts +328 -0
  17. package/lib/src/canvas.ts +505 -0
  18. package/lib/src/cardview.ts +227 -0
  19. package/lib/src/checkbox.ts +188 -0
  20. package/lib/src/color.ts +752 -0
  21. package/lib/src/colorpicker.ts +1639 -0
  22. package/lib/src/combobox.ts +465 -0
  23. package/lib/src/component.ts +2329 -0
  24. package/lib/{esm/dom_events.js → src/copyright.txt} +27 -29
  25. package/lib/src/datastore.ts +1322 -0
  26. package/lib/src/dialog.ts +656 -0
  27. package/lib/src/dom_events.ts +315 -0
  28. package/lib/src/drag_manager.ts +199 -0
  29. package/lib/src/drawtext.ts +355 -0
  30. package/lib/src/fileupload.ts +213 -0
  31. package/lib/src/form.ts +375 -0
  32. package/lib/src/formatters.ts +105 -0
  33. package/lib/src/gridview.ts +1185 -0
  34. package/lib/src/i18n.ts +346 -0
  35. package/lib/src/icon.ts +335 -0
  36. package/lib/src/image.ts +204 -0
  37. package/lib/src/index.ts +89 -0
  38. package/lib/src/input.ts +249 -0
  39. package/lib/src/label.ts +128 -0
  40. package/lib/src/layout.ts +430 -0
  41. package/lib/src/link.ts +86 -0
  42. package/lib/src/listview.ts +765 -0
  43. package/lib/{esm/md5.js → src/md5.ts} +438 -403
  44. package/lib/src/menu.ts +425 -0
  45. package/lib/src/messagebox.ts +224 -0
  46. package/lib/src/panel.ts +86 -0
  47. package/lib/src/popup.ts +494 -0
  48. package/lib/src/property_editor.ts +337 -0
  49. package/lib/src/radiobtn.ts +197 -0
  50. package/lib/src/rating.ts +135 -0
  51. package/lib/src/request.ts +300 -0
  52. package/lib/src/router.ts +185 -0
  53. package/lib/src/settings.ts +77 -0
  54. package/lib/src/sidebarview.ts +103 -0
  55. package/lib/src/spreadsheet.ts +1449 -0
  56. package/lib/src/styles.ts +343 -0
  57. package/lib/src/svgcomponent.ts +577 -0
  58. package/lib/src/tabbar.ts +151 -0
  59. package/lib/src/tabview.ts +110 -0
  60. package/lib/src/textarea.ts +235 -0
  61. package/lib/src/textedit.ts +544 -0
  62. package/lib/src/toaster.ts +80 -0
  63. package/lib/src/tools.ts +1473 -0
  64. package/lib/src/tooltips.ts +191 -0
  65. package/lib/src/treeview.ts +716 -0
  66. package/lib/{esm/version.js → src/version.ts} +30 -29
  67. package/lib/{styles → src}/x4.less +0 -0
  68. package/lib/src/x4dom.ts +57 -0
  69. package/lib/src/x4events.ts +585 -0
  70. package/lib/src/x4react.ts +90 -0
  71. package/package.json +52 -49
  72. package/lib/cjs/action.js +0 -58
  73. package/lib/cjs/app_sockets.js +0 -74
  74. package/lib/cjs/application.js +0 -182
  75. package/lib/cjs/autocomplete.js +0 -155
  76. package/lib/cjs/base_component.js +0 -124
  77. package/lib/cjs/button.js +0 -263
  78. package/lib/cjs/calendar.js +0 -254
  79. package/lib/cjs/canvas.js +0 -361
  80. package/lib/cjs/cardview.js +0 -161
  81. package/lib/cjs/checkbox.js +0 -139
  82. package/lib/cjs/color.js +0 -591
  83. package/lib/cjs/colorpicker.js +0 -1468
  84. package/lib/cjs/combobox.js +0 -349
  85. package/lib/cjs/component.js +0 -1719
  86. package/lib/cjs/datastore.js +0 -985
  87. package/lib/cjs/dialog.js +0 -478
  88. package/lib/cjs/dom_events.js +0 -30
  89. package/lib/cjs/drag_manager.js +0 -145
  90. package/lib/cjs/drawtext.js +0 -276
  91. package/lib/cjs/fileupload.js +0 -167
  92. package/lib/cjs/form.js +0 -304
  93. package/lib/cjs/formatters.js +0 -90
  94. package/lib/cjs/gridview.js +0 -881
  95. package/lib/cjs/i18n.js +0 -266
  96. package/lib/cjs/icon.js +0 -272
  97. package/lib/cjs/image.js +0 -157
  98. package/lib/cjs/input.js +0 -174
  99. package/lib/cjs/label.js +0 -95
  100. package/lib/cjs/layout.js +0 -322
  101. package/lib/cjs/link.js +0 -64
  102. package/lib/cjs/listview.js +0 -546
  103. package/lib/cjs/md5.js +0 -403
  104. package/lib/cjs/menu.js +0 -301
  105. package/lib/cjs/messagebox.js +0 -177
  106. package/lib/cjs/panel.js +0 -68
  107. package/lib/cjs/popup.js +0 -383
  108. package/lib/cjs/property_editor.js +0 -252
  109. package/lib/cjs/radiobtn.js +0 -140
  110. package/lib/cjs/rating.js +0 -102
  111. package/lib/cjs/request.js +0 -246
  112. package/lib/cjs/router.js +0 -139
  113. package/lib/cjs/settings.js +0 -69
  114. package/lib/cjs/sidebarview.js +0 -82
  115. package/lib/cjs/spreadsheet.js +0 -1084
  116. package/lib/cjs/styles.js +0 -275
  117. package/lib/cjs/svgcomponent.js +0 -447
  118. package/lib/cjs/tabbar.js +0 -111
  119. package/lib/cjs/tabview.js +0 -85
  120. package/lib/cjs/textarea.js +0 -165
  121. package/lib/cjs/textedit.js +0 -415
  122. package/lib/cjs/toaster.js +0 -64
  123. package/lib/cjs/tools.js +0 -1197
  124. package/lib/cjs/tooltips.js +0 -157
  125. package/lib/cjs/treeview.js +0 -535
  126. package/lib/cjs/version.js +0 -32
  127. package/lib/cjs/x4dom.js +0 -32
  128. package/lib/cjs/x4events.js +0 -384
  129. package/lib/cjs/x4react.js +0 -72
  130. package/lib/esm/action.js +0 -53
  131. package/lib/esm/app_sockets.js +0 -70
  132. package/lib/esm/application.js +0 -184
  133. package/lib/esm/autocomplete.js +0 -155
  134. package/lib/esm/base_component.js +0 -107
  135. package/lib/esm/button.js +0 -257
  136. package/lib/esm/calendar.js +0 -249
  137. package/lib/esm/canvas.js +0 -358
  138. package/lib/esm/cardview.js +0 -159
  139. package/lib/esm/checkbox.js +0 -134
  140. package/lib/esm/color.js +0 -588
  141. package/lib/esm/colorpicker.js +0 -1475
  142. package/lib/esm/combobox.js +0 -351
  143. package/lib/esm/component.js +0 -1711
  144. package/lib/esm/datastore.js +0 -990
  145. package/lib/esm/dialog.js +0 -490
  146. package/lib/esm/drag_manager.js +0 -147
  147. package/lib/esm/drawtext.js +0 -271
  148. package/lib/esm/fileupload.js +0 -163
  149. package/lib/esm/form.js +0 -304
  150. package/lib/esm/formatters.js +0 -81
  151. package/lib/esm/gridview.js +0 -889
  152. package/lib/esm/i18n.js +0 -257
  153. package/lib/esm/icon.js +0 -261
  154. package/lib/esm/image.js +0 -154
  155. package/lib/esm/input.js +0 -182
  156. package/lib/esm/label.js +0 -90
  157. package/lib/esm/layout.js +0 -310
  158. package/lib/esm/link.js +0 -59
  159. package/lib/esm/listview.js +0 -534
  160. package/lib/esm/menu.js +0 -300
  161. package/lib/esm/messagebox.js +0 -161
  162. package/lib/esm/panel.js +0 -65
  163. package/lib/esm/popup.js +0 -379
  164. package/lib/esm/property_editor.js +0 -251
  165. package/lib/esm/radiobtn.js +0 -136
  166. package/lib/esm/rating.js +0 -97
  167. package/lib/esm/request.js +0 -224
  168. package/lib/esm/router.js +0 -136
  169. package/lib/esm/settings.js +0 -66
  170. package/lib/esm/sidebarview.js +0 -79
  171. package/lib/esm/spreadsheet.js +0 -1097
  172. package/lib/esm/styles.js +0 -270
  173. package/lib/esm/svgcomponent.js +0 -450
  174. package/lib/esm/tabbar.js +0 -107
  175. package/lib/esm/tabview.js +0 -83
  176. package/lib/esm/textarea.js +0 -160
  177. package/lib/esm/textedit.js +0 -412
  178. package/lib/esm/toaster.js +0 -62
  179. package/lib/esm/tools.js +0 -1158
  180. package/lib/esm/tooltips.js +0 -153
  181. package/lib/esm/treeview.js +0 -527
  182. package/lib/esm/x4dom.js +0 -29
  183. package/lib/esm/x4events.js +0 -376
  184. package/lib/esm/x4react.js +0 -71
  185. package/lib/types/app_sockets.d.ts +0 -29
  186. package/lib/types/application.d.ts +0 -104
  187. package/lib/types/autocomplete.d.ts +0 -58
  188. package/lib/types/base_component.d.ts +0 -88
  189. package/lib/types/button.d.ts +0 -151
  190. package/lib/types/calendar.d.ts +0 -82
  191. package/lib/types/canvas.d.ts +0 -92
  192. package/lib/types/cardview.d.ts +0 -87
  193. package/lib/types/checkbox.d.ts +0 -77
  194. package/lib/types/color.d.ts +0 -148
  195. package/lib/types/colorpicker.d.ts +0 -107
  196. package/lib/types/combobox.d.ts +0 -107
  197. package/lib/types/component.d.ts +0 -601
  198. package/lib/types/datastore.d.ts +0 -396
  199. package/lib/types/dialog.d.ts +0 -175
  200. package/lib/types/dom_events.d.ts +0 -302
  201. package/lib/types/drag_manager.d.ts +0 -54
  202. package/lib/types/drawtext.d.ts +0 -48
  203. package/lib/types/fileupload.d.ts +0 -64
  204. package/lib/types/form.d.ts +0 -133
  205. package/lib/types/formatters.d.ts +0 -35
  206. package/lib/types/gridview.d.ts +0 -175
  207. package/lib/types/i18n.d.ts +0 -73
  208. package/lib/types/icon.d.ts +0 -64
  209. package/lib/types/image.d.ts +0 -55
  210. package/lib/types/index.d.ts +0 -84
  211. package/lib/types/input.d.ts +0 -91
  212. package/lib/types/label.d.ts +0 -58
  213. package/lib/types/layout.d.ts +0 -87
  214. package/lib/types/link.d.ts +0 -50
  215. package/lib/types/listview.d.ts +0 -178
  216. package/lib/types/md5.d.ts +0 -61
  217. package/lib/types/menu.d.ts +0 -130
  218. package/lib/types/messagebox.d.ts +0 -69
  219. package/lib/types/panel.d.ts +0 -47
  220. package/lib/types/popup.d.ts +0 -75
  221. package/lib/types/property_editor.d.ts +0 -71
  222. package/lib/types/radiobtn.d.ts +0 -73
  223. package/lib/types/rating.d.ts +0 -53
  224. package/lib/types/request.d.ts +0 -52
  225. package/lib/types/router.d.ts +0 -42
  226. package/lib/types/settings.d.ts +0 -37
  227. package/lib/types/sidebarview.d.ts +0 -49
  228. package/lib/types/spreadsheet.d.ts +0 -222
  229. package/lib/types/styles.d.ts +0 -85
  230. package/lib/types/svgcomponent.d.ts +0 -215
  231. package/lib/types/tabbar.d.ts +0 -58
  232. package/lib/types/tabview.d.ts +0 -49
  233. package/lib/types/textarea.d.ts +0 -77
  234. package/lib/types/textedit.d.ts +0 -123
  235. package/lib/types/toaster.d.ts +0 -42
  236. package/lib/types/tools.d.ts +0 -394
  237. package/lib/types/tooltips.d.ts +0 -46
  238. package/lib/types/treeview.d.ts +0 -144
  239. package/lib/types/version.d.ts +0 -29
  240. package/lib/types/x4dom.d.ts +0 -49
  241. package/lib/types/x4events.d.ts +0 -269
  242. package/lib/types/x4react.d.ts +0 -41
package/lib/cjs/tools.js DELETED
@@ -1,1197 +0,0 @@
1
- "use strict";
2
- /**
3
- * ___ ___ __
4
- * \ \_/ / / _
5
- * \ / /_| |_
6
- * / _ \____ _|
7
- * /__/ \__\ |_|
8
- *
9
- * @file tools.ts
10
- * @author Etienne Cochard
11
- *
12
- * Copyright (c) 2019-2022 R-libre ingenierie
13
- *
14
- * Permission is hereby granted, free of charge, to any person obtaining a copy
15
- * of this software and associated documentation files (the "Software"), to deal
16
- * in the Software without restriction, including without limitation the rights
17
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
18
- * of the Software, and to permit persons to whom the Software is furnished to do so,
19
- * subject to the following conditions:
20
- * The above copyright notice and this permission notice shall be included in all copies
21
- * or substantial portions of the Software.
22
- *
23
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
24
- * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
25
- * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
26
- * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
27
- * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
28
- * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29
- **/
30
- Object.defineProperty(exports, "__esModule", { value: true });
31
- exports.installHMR = exports.generatePassword = exports.classNames = exports.mix = exports.crc32 = exports.Clipboard = exports.isHtmlString = exports.html = exports.HtmlString = exports.clamp = exports.getMousePos = exports.NetworkError = exports.markdownToHtml = exports.asap = exports.deferCall = exports.waitFontLoading = exports.isNumber = exports.pad = exports.isLiteralObject = exports.isFunction = exports.isArray = exports.isString = exports.downloadData = exports.calcAge = exports.formatIntlDate = exports.parseIntlDate = exports.date_calc_weeknum = exports.date_clone = exports.date_hash = exports.date_sql_utc = exports.date_to_sql = exports.date_diff = exports.date_format = exports._date_set_locale = exports.removeHtmlTags = exports.escapeHtml = exports.sprintf = exports.Rect = exports.Size = exports.Point = exports.camelCase = exports.pascalCase = exports.parseIntlFloat = exports.roundTo = exports.isTouchDevice = void 0;
32
- const x4dom_1 = require("./x4dom");
33
- const i18n_1 = require("./i18n"); // you MUST create a file named translation.js
34
- // :: ENVIRONMENT ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
35
- /**
36
- * @return true is the device has touch
37
- */
38
- function isTouchDevice() {
39
- return 'ontouchstart' in window;
40
- }
41
- exports.isTouchDevice = isTouchDevice;
42
- // :: NUMBERS ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
43
- /**
44
- * round to a given number of decimals
45
- * @param num numbre to round
46
- * @param ndec number of decimals
47
- * @returns number rounded
48
- */
49
- function roundTo(num, ndec) {
50
- let mul = Math.pow(10, ndec);
51
- let res = Math.round(num * mul) / mul;
52
- if (Object.is(res, -0)) { // res===-0.0
53
- res = 0;
54
- }
55
- return res;
56
- }
57
- exports.roundTo = roundTo;
58
- /**
59
- * parse an intl formatted number
60
- * understand grouping and ',' separator
61
- * @review us format: grouping = ','
62
- * @param num
63
- */
64
- function parseIntlFloat(num) {
65
- num = num.replace(/\s*/g, ''); // group separator
66
- num = num.replace(',', '.'); // decimal separator
67
- // accept empty & return 0.0
68
- if (num.length == 0) {
69
- return 0.0;
70
- }
71
- return parseFloat(num);
72
- }
73
- exports.parseIntlFloat = parseIntlFloat;
74
- // :: STRING MANIP ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
75
- const RE_PCASE = /([a-z][A-Z])/g;
76
- const RE_PCASE2 = /[^-a-z0-9]+/g;
77
- /**
78
- * inverse of camel case
79
- * theThingToCase -> the-thing-to-case
80
- * @param {String} str
81
- */
82
- function pascalCase(string) {
83
- let result = string;
84
- result = result.replace(/([a-z])([A-Z])/g, "$1 $2");
85
- result = result.toLowerCase();
86
- result = result.replace(/[^- a-z0-9]+/g, ' ');
87
- if (result.indexOf(' ') < 0) {
88
- return result;
89
- }
90
- result = result.trim();
91
- return result.replace(/ /g, '-');
92
- }
93
- exports.pascalCase = pascalCase;
94
- function camelCase(text) {
95
- let result = text.toLowerCase();
96
- result = result.replace(/[^a-zA-Z0-9]+(.)/g, (m, chr) => {
97
- return chr.toUpperCase();
98
- });
99
- return result;
100
- }
101
- exports.camelCase = camelCase;
102
- class Point {
103
- constructor(x = 0, y = 0) {
104
- this.x = x;
105
- this.y = y;
106
- }
107
- }
108
- exports.Point = Point;
109
- class Size {
110
- constructor(w = 0, h = 0) {
111
- this.width = w;
112
- this.height = h;
113
- }
114
- }
115
- exports.Size = Size;
116
- class Rect {
117
- constructor(left, top, width, height) {
118
- if (left === undefined) {
119
- this.left = this.top = this.right = this.bottom = 0;
120
- }
121
- else if (left instanceof Rect || left instanceof DOMRect) {
122
- let rc = left;
123
- this.left = rc.left;
124
- this.top = rc.top;
125
- this.width = rc.width;
126
- this.height = rc.height;
127
- }
128
- else {
129
- this.left = left;
130
- this.top = top;
131
- this.width = width;
132
- this.height = height;
133
- }
134
- }
135
- set(left, top, width, height) {
136
- this.left = left;
137
- this.top = top;
138
- this.width = width;
139
- this.height = height;
140
- }
141
- get bottom() {
142
- return this.top + this.height;
143
- }
144
- set bottom(bottom) {
145
- this.height = bottom - this.top;
146
- }
147
- get right() {
148
- return this.left + this.width;
149
- }
150
- set right(right) {
151
- this.width = right - this.left;
152
- }
153
- get topLeft() {
154
- return new Point(this.left, this.top);
155
- }
156
- get bottomRight() {
157
- return new Point(this.right, this.bottom);
158
- }
159
- get size() {
160
- return new Size(this.width, this.height);
161
- }
162
- moveTo(left, top) {
163
- this.left = left;
164
- this.top = top;
165
- return this;
166
- }
167
- movedTo(left, top) {
168
- return new Rect(left, top, this.width, this.height);
169
- }
170
- moveBy(dx, dy) {
171
- this.left += dx;
172
- this.top += dy;
173
- return this;
174
- }
175
- movedBy(dx, dy) {
176
- return new Rect(this.left + dx, this.top + dy, this.width, this.height);
177
- }
178
- isEmpty() {
179
- return this.width == 0 && this.height == 0;
180
- }
181
- normalize() {
182
- let w = this.width, h = this.height;
183
- if (w < 0) {
184
- this.left += w;
185
- this.width = -w;
186
- }
187
- if (h < 0) {
188
- this.top += h;
189
- this.height = -h;
190
- }
191
- return this;
192
- }
193
- normalized() {
194
- let rc = new Rect(this);
195
- let w = rc.width, h = rc.height;
196
- if (w < 0) {
197
- rc.left += w;
198
- rc.width = -w;
199
- }
200
- if (h < 0) {
201
- rc.top += h;
202
- rc.height = -h;
203
- }
204
- return rc;
205
- }
206
- /**
207
- * @deprecated
208
- */
209
- containsPt(x, y) {
210
- return x >= this.left && x <= this.right && y >= this.top && y <= this.bottom;
211
- }
212
- contains(arg) {
213
- if (arg instanceof Rect) {
214
- return arg.left >= this.left && arg.right <= this.right && arg.top >= this.top && arg.bottom <= this.bottom;
215
- }
216
- else {
217
- return arg.x >= this.left && arg.x < this.right && arg.y >= this.top && arg.y < this.bottom;
218
- }
219
- }
220
- touches(rc) {
221
- if (this.left > rc.right || this.right < rc.left || this.top > rc.bottom || this.bottom < rc.top) {
222
- return false;
223
- }
224
- return true;
225
- }
226
- inflate(dx, dy) {
227
- if (dy === undefined) {
228
- dy = dx;
229
- }
230
- this.left -= dx;
231
- this.top -= dy;
232
- this.width += dx + dx;
233
- this.height += dy + dy;
234
- }
235
- inflatedBy(dx, dy) {
236
- if (dy === undefined) {
237
- dy = dx;
238
- }
239
- return new Rect(this.left - dx, this.top - dy, this.width + dx + dx, this.height + dy + dy);
240
- }
241
- combine(rc) {
242
- let left = Math.min(this.left, rc.left);
243
- let top = Math.min(this.top, rc.top);
244
- let right = Math.max(this.right, rc.right);
245
- let bottom = Math.max(this.bottom, rc.bottom);
246
- this.left = left;
247
- this.top = top;
248
- this.right = right;
249
- this.bottom = bottom;
250
- }
251
- }
252
- exports.Rect = Rect;
253
- /**
254
- * replace {0..9} by given arguments
255
- * @param format string
256
- * @param args
257
- *
258
- * @example ```ts
259
- *
260
- * console.log( sprintf( 'here is arg 1 {1} and arg 0 {0}', 'argument 0', 'argument 1' ) )
261
- */
262
- function sprintf(format, ...args) {
263
- return format.replace(/{(\d+)}/g, function (match, index) {
264
- return typeof args[index] != 'undefined' ? args[index] : match;
265
- });
266
- }
267
- exports.sprintf = sprintf;
268
- /**
269
- * replace special characters for display
270
- * @param unsafe
271
- *
272
- * console.log( escapeHtml('<div style="width:50px; height: 50px; background-color:red"></div>') );
273
- */
274
- function escapeHtml(unsafe, nl_br = false) {
275
- if (!unsafe || unsafe.length == 0) {
276
- return "";
277
- }
278
- let result = unsafe.replace(/[<>\&\"\']/g, function (c) {
279
- return '&#' + c.charCodeAt(0) + ';';
280
- });
281
- if (nl_br) {
282
- result = result.replace(/(\r\n|\n\r|\r|\n)/g, '<br/>');
283
- }
284
- return result;
285
- }
286
- exports.escapeHtml = escapeHtml;
287
- /**
288
- * replace special characters for display
289
- * @author Steven Levithan <http://slevithan.com/>
290
- * @param unsafe
291
- *
292
- * console.log( removeHtmlTags('<h1>sss</h1>') );
293
- */
294
- function removeHtmlTags(unsafe, nl_br = false) {
295
- if (unsafe === undefined || unsafe === null || !isString(unsafe) || unsafe.length == 0) {
296
- return "";
297
- }
298
- let ret_val = '';
299
- for (let i = 0; i < unsafe.length; i++) {
300
- const ch = unsafe.codePointAt(i);
301
- if (ch > 127) {
302
- ret_val += '&#' + ch + ';';
303
- }
304
- else if (ch == 60 /*<*/) {
305
- ret_val += '&lt;';
306
- }
307
- else {
308
- ret_val += unsafe.charAt(i);
309
- }
310
- }
311
- return ret_val;
312
- }
313
- exports.removeHtmlTags = removeHtmlTags;
314
- // :: DATES ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
315
- let cur_locale = 'fr-FR';
316
- /**
317
- * change the current locale for misc translations (date...)
318
- * @param locale
319
- */
320
- function _date_set_locale(locale) {
321
- cur_locale = locale;
322
- }
323
- exports._date_set_locale = _date_set_locale;
324
- /**
325
- *
326
- * @param date
327
- * @param options
328
- * @example
329
- * let date = new Date( );
330
- * let options = { day: 'numeric', month: 'numeric', year: 'numeric', hour: 'numeric', minute: 'numeric' };
331
- * let text = date_format( date, options );
332
- */
333
- function date_format(date, options) {
334
- //return new Intl.DateTimeFormat(cur_locale, options).format( date );
335
- return formatIntlDate(date);
336
- }
337
- exports.date_format = date_format;
338
- /**
339
- *
340
- * @param date
341
- * @param options
342
- */
343
- function date_diff(date1, date2, options) {
344
- var dt = (date1.getTime() - date2.getTime()) / 1000;
345
- // seconds
346
- let sec = dt;
347
- if (sec < 60) {
348
- return sprintf(i18n_1._tr.global.diff_date_seconds, Math.round(sec));
349
- }
350
- // minutes
351
- let min = Math.floor(sec / 60);
352
- if (min < 60) {
353
- return sprintf(i18n_1._tr.global.diff_date_minutes, Math.round(min));
354
- }
355
- // hours
356
- let hrs = Math.floor(min / 60);
357
- return sprintf(i18n_1._tr.global.diff_date_hours, hrs, min % 60);
358
- }
359
- exports.date_diff = date_diff;
360
- function date_to_sql(date, withHours) {
361
- if (withHours) {
362
- return formatIntlDate(date, 'Y-M-D H:I:S');
363
- }
364
- else {
365
- return formatIntlDate(date, 'Y-M-D');
366
- }
367
- }
368
- exports.date_to_sql = date_to_sql;
369
- /**
370
- * construct a date from an utc date time (sql format)
371
- * YYYY-MM-DD HH:MM:SS
372
- */
373
- function date_sql_utc(date) {
374
- let result = new Date(date + ' GMT');
375
- return result;
376
- }
377
- exports.date_sql_utc = date_sql_utc;
378
- /**
379
- * return a number that is a representation of the date
380
- * this number can be compared with another hash
381
- */
382
- function date_hash(date) {
383
- return date.getFullYear() << 16 | date.getMonth() << 8 | date.getDate();
384
- }
385
- exports.date_hash = date_hash;
386
- Date.prototype.hash = function () {
387
- return date_hash(this);
388
- };
389
- /**
390
- * return a copy of a date
391
- */
392
- function date_clone(date) {
393
- return new Date(date.getTime());
394
- }
395
- exports.date_clone = date_clone;
396
- /**
397
- * return the week number of a date
398
- */
399
- function date_calc_weeknum(date) {
400
- const firstDayOfYear = new Date(date.getFullYear(), 0, 1);
401
- const pastDaysOfYear = (date.valueOf() - firstDayOfYear.valueOf()) / 86400000;
402
- return Math.floor((pastDaysOfYear + firstDayOfYear.getDay() + 1) / 7);
403
- }
404
- exports.date_calc_weeknum = date_calc_weeknum;
405
- /**
406
- * parse a date according to the given format
407
- * @param value - string date to parse
408
- * @param fmts - format list - i18 tranlation by default
409
- * allowed format specifiers:
410
- * d or D: date (1 or 2 digits)
411
- * m or M: month (1 or 2 digits)
412
- * y or Y: year (2 or 4 digits)
413
- * h or H: hours (1 or 2 digits)
414
- * i or I: minutes (1 or 2 digits)
415
- * s or S: seconds (1 or 2 digits)
416
- * <space>: 1 or more spaces
417
- * any other char: <0 or more spaces><the char><0 or more spaces>
418
- * each specifiers is separated from other by a pipe (|)
419
- * more specific at first
420
- * @example
421
- * 'd/m/y|d m Y|dmy|y-m-d h:i:s|y-m-d'
422
- */
423
- function parseIntlDate(value, fmts = i18n_1._tr.global.date_input_formats) {
424
- var _a, _b, _c, _d, _e, _f;
425
- let formats = fmts.split('|');
426
- for (let fmatch of formats) {
427
- //review: could do that only once & keep result
428
- //review: add hours, minutes, seconds
429
- let smatch = '';
430
- for (let c of fmatch) {
431
- if (c == 'd' || c == 'D') {
432
- smatch += '(?<day>\\d{1,2})';
433
- }
434
- else if (c == 'm' || c == 'M') {
435
- smatch += '(?<month>\\d{1,2})';
436
- }
437
- else if (c == 'y' || c == 'Y') {
438
- smatch += '(?<year>\\d{1,4})';
439
- }
440
- else if (c == 'h' || c == 'H') {
441
- smatch += '(?<hour>\\d{1,2})';
442
- }
443
- else if (c == 'i' || c == 'I') {
444
- smatch += '(?<min>\\d{1,2})';
445
- }
446
- else if (c == 's' || c == 'S') {
447
- smatch += '(?<sec>\\d{1,2})';
448
- }
449
- else if (c == ' ') {
450
- smatch += '\\s+';
451
- }
452
- else {
453
- smatch += '\\s*\\' + c + '\\s*';
454
- }
455
- }
456
- let rematch = new RegExp('^' + smatch + '$', 'm');
457
- let match = rematch.exec(value);
458
- if (match) {
459
- const now = new Date();
460
- let d = parseInt((_a = match.groups.day) !== null && _a !== void 0 ? _a : '1');
461
- let m = parseInt((_b = match.groups.month) !== null && _b !== void 0 ? _b : '1');
462
- let y = parseInt((_c = match.groups.year) !== null && _c !== void 0 ? _c : now.getFullYear() + '');
463
- let h = parseInt((_d = match.groups.hour) !== null && _d !== void 0 ? _d : '0');
464
- let i = parseInt((_e = match.groups.min) !== null && _e !== void 0 ? _e : '0');
465
- let s = parseInt((_f = match.groups.sec) !== null && _f !== void 0 ? _f : '0');
466
- if (y > 0 && y < 100) {
467
- y += 2000;
468
- }
469
- let result = new Date(y, m - 1, d, h, i, s, 0);
470
- // we test the vdate validity (without adjustments)
471
- // without this test, date ( 0, 0, 0) is accepted and transformed to 1969/11/31 (not fun)
472
- let ty = result.getFullYear(), tm = result.getMonth() + 1, td = result.getDate();
473
- if (ty != y || tm != m || td != d) {
474
- //debugger;
475
- return null;
476
- }
477
- return result;
478
- }
479
- }
480
- return null;
481
- }
482
- exports.parseIntlDate = parseIntlDate;
483
- /**
484
- * format a date as string
485
- * @param date - date to format
486
- * @param fmt - format
487
- * format specifiers:
488
- * d: date
489
- * D: 2 digits date padded with 0
490
- * j: day of week short mode 'mon'
491
- * J: day of week long mode 'monday'
492
- * w: week number
493
- * m: month
494
- * M: 2 digits month padded with 0
495
- * o: month short mode 'jan'
496
- * O: month long mode 'january'
497
- * y or Y: year
498
- * h: hour (24 format)
499
- * H: 2 digits hour (24 format) padded with 0
500
- * i: minutes
501
- * I: 2 digits minutes padded with 0
502
- * s: seconds
503
- * S: 2 digits seconds padded with 0
504
- * a: am or pm
505
- * anything else is inserted
506
- * if you need to insert some text, put it between {}
507
- *
508
- * @example
509
- *
510
- * 01/01/1970 11:25:00 with '{this is my demo date formatter: }H-i*M'
511
- * "this is my demo date formatter: 11-25*january"
512
- */
513
- function formatIntlDate(date, fmt = i18n_1._tr.global.date_format) {
514
- if (!date) {
515
- return '';
516
- }
517
- let now = {
518
- year: date.getFullYear(),
519
- month: date.getMonth() + 1,
520
- day: date.getDate(),
521
- wday: date.getDay(),
522
- hours: date.getHours(),
523
- minutes: date.getMinutes(),
524
- seconds: date.getSeconds(),
525
- milli: date.getMilliseconds()
526
- };
527
- let result = '';
528
- let esc = 0;
529
- for (let c of fmt) {
530
- if (c == '{') {
531
- if (++esc == 1) {
532
- continue;
533
- }
534
- }
535
- else if (c == '}') {
536
- if (--esc == 0) {
537
- continue;
538
- }
539
- }
540
- if (esc) {
541
- result += c;
542
- continue;
543
- }
544
- if (c == 'd') {
545
- result += now.day;
546
- }
547
- else if (c == 'D') {
548
- result += pad(now.day, -2);
549
- }
550
- else if (c == 'j') { // day short
551
- result += i18n_1._tr.global.day_short[now.wday];
552
- }
553
- else if (c == 'J') { // day long
554
- result += i18n_1._tr.global.day_long[now.wday];
555
- }
556
- else if (c == 'w') { // week
557
- result += date_calc_weeknum(date);
558
- }
559
- else if (c == 'W') { // week
560
- result += pad(date_calc_weeknum(date), -2);
561
- }
562
- else if (c == 'm') {
563
- result += now.month;
564
- }
565
- else if (c == 'M') {
566
- result += pad(now.month, -2);
567
- }
568
- else if (c == 'o') { // month short
569
- result += i18n_1._tr.global.month_short[now.month - 1];
570
- }
571
- else if (c == 'O') { // month long
572
- result += i18n_1._tr.global.month_long[now.month - 1];
573
- }
574
- else if (c == 'y' || c == 'Y') {
575
- result += pad(now.year, -4);
576
- }
577
- else if (c == 'a' || c == 'A') {
578
- result += now.hours < 12 ? 'am' : 'pm';
579
- }
580
- else if (c == 'h') {
581
- result += now.hours;
582
- }
583
- else if (c == 'H') {
584
- result += pad(now.hours, -2);
585
- }
586
- else if (c == 'i') {
587
- result += now.minutes;
588
- }
589
- else if (c == 'I') {
590
- result += pad(now.minutes, -2);
591
- }
592
- else if (c == 's') {
593
- result += now.seconds;
594
- }
595
- else if (c == 'S') {
596
- result += pad(now.seconds, -2);
597
- }
598
- else if (c == 'l') {
599
- result += now.milli;
600
- }
601
- else if (c == 'L') {
602
- result += pad(now.milli, -3);
603
- }
604
- else {
605
- result += c;
606
- }
607
- }
608
- return result;
609
- }
610
- exports.formatIntlDate = formatIntlDate;
611
- function calcAge(birth, ref) {
612
- if (ref === undefined) {
613
- ref = new Date();
614
- }
615
- if (!birth) {
616
- return 0;
617
- }
618
- let age = ref.getFullYear() - birth.getFullYear();
619
- if (ref.getMonth() < birth.getMonth() || (ref.getMonth() == birth.getMonth() && ref.getDate() < birth.getDate())) {
620
- age--;
621
- }
622
- return age;
623
- }
624
- exports.calcAge = calcAge;
625
- Date.prototype.isSameDay = function (date) {
626
- return this.getDate() == date.getDate() && this.getMonth() == date.getMonth() && this.getFullYear() == date.getFullYear();
627
- };
628
- Date.prototype.hash = function () {
629
- return date_hash(this);
630
- };
631
- Date.prototype.clone = function () {
632
- return date_clone(this);
633
- };
634
- Date.prototype.weekNum = function () {
635
- return date_calc_weeknum(this);
636
- };
637
- Date.prototype.format = function (fmt) {
638
- return formatIntlDate(this, fmt);
639
- };
640
- Date.prototype.addDays = function (days) {
641
- this.setDate(this.getDate() + days);
642
- return this;
643
- };
644
- // :: FILE CREATION ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
645
- /**
646
- *
647
- * @param data data to export
648
- * @param mimetype - 'text/plain'
649
- */
650
- function downloadData(data, mimetype, filename) {
651
- //if (data !== null && navigator.msSaveBlob) {
652
- // return navigator.msSaveBlob(new Blob([data], { type: mimetype }), filename);
653
- //}
654
- let blob = new Blob([data], { type: mimetype });
655
- let url = window.URL.createObjectURL(blob);
656
- let a = x4dom_1.x4document.createElement("a");
657
- a.style['display'] = "none";
658
- a.href = url;
659
- a.download = filename;
660
- x4dom_1.x4document.body.appendChild(a);
661
- a.click();
662
- window.URL.revokeObjectURL(url);
663
- }
664
- exports.downloadData = downloadData;
665
- // :: MISC ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
666
- /**
667
- * check if a value is a string
668
- * @param val
669
- */
670
- function isString(val) {
671
- return typeof val === 'string';
672
- }
673
- exports.isString = isString;
674
- /**
675
- * check is a value is an array
676
- * @param val
677
- */
678
- function isArray(val) {
679
- return val instanceof Array;
680
- }
681
- exports.isArray = isArray;
682
- /**
683
- *
684
- */
685
- function isFunction(val) {
686
- return val instanceof Function;
687
- }
688
- exports.isFunction = isFunction;
689
- /**
690
- *
691
- */
692
- function isLiteralObject(val) {
693
- return (!!val) && (val.constructor === Object);
694
- }
695
- exports.isLiteralObject = isLiteralObject;
696
- ;
697
- /**
698
- * prepend 0 to a value to a given length
699
- * @param value
700
- * @param length
701
- */
702
- function pad(what, size, ch = '0') {
703
- let value;
704
- if (!isString(what)) {
705
- value = '' + what;
706
- }
707
- else {
708
- value = what;
709
- }
710
- if (size > 0) {
711
- return value.padEnd(size, ch);
712
- }
713
- else {
714
- return value.padStart(-size, ch);
715
- }
716
- }
717
- exports.pad = pad;
718
- /**
719
- * return true if val is a finite number
720
- */
721
- function isNumber(val) {
722
- return typeof val === 'number' && isFinite(val);
723
- }
724
- exports.isNumber = isNumber;
725
- /**
726
- *
727
- * @param name
728
- */
729
- function waitFontLoading(name) {
730
- // tip for waiting font loading:
731
- // by default, body is created invisible ((opacity = 0)
732
- // we create a div inside with the font we need to wait the loading
733
- // as soon as the font is loaded, it's size will change, the browser end font loading
734
- // we can remove the div.
735
- // pitfall: if the font is already loaded, ne never end.
736
- // @review that
737
- let ct = x4dom_1.x4document.createElement('div');
738
- ct.style.position = 'absolute';
739
- ct.style.fontFamily = name;
740
- ct.style.fontSize = '44px';
741
- ct.style.opacity = '0.001';
742
- ct.innerText = 'X';
743
- x4dom_1.x4document.body.appendChild(ct);
744
- return new Promise((resolve) => {
745
- let irc = ct.getBoundingClientRect();
746
- let tm = setInterval(() => {
747
- let nrc = ct.getBoundingClientRect();
748
- if (nrc.height != irc.height) {
749
- clearInterval(tm);
750
- x4dom_1.x4document.body.removeChild(ct);
751
- resolve();
752
- }
753
- }, 0);
754
- });
755
- }
756
- exports.waitFontLoading = waitFontLoading;
757
- /**
758
- *
759
- * @param fn
760
- * @param tm
761
- *
762
- * @example:
763
- *
764
- * defer( ( ) => {
765
- * console.log( x );
766
- * } )( );
767
- */
768
- function deferCall(fn, tm = 0, ...args) {
769
- setTimeout(fn, tm, ...args);
770
- }
771
- exports.deferCall = deferCall;
772
- /**
773
- *
774
- */
775
- function asap(cb) {
776
- requestAnimationFrame(cb);
777
- }
778
- exports.asap = asap;
779
- /**
780
- * micro md to html
781
- *
782
- * understand:
783
- * **bold**
784
- * *italic*
785
- *
786
- * > quote
787
- * - list
788
- * # title lvl 1
789
- * ## title lvl 2
790
- * ### title lvl 3 ...
791
- *
792
- */
793
- function markdownToHtml(text) {
794
- if (!text) {
795
- return '';
796
- }
797
- let lines = text.split('\n');
798
- let state = 'para';
799
- let div = 'p';
800
- let result = [];
801
- lines.forEach((l) => {
802
- let txt = l.trim();
803
- if (state == 'para') {
804
- // entree en mode list
805
- if (txt[0] == '-') {
806
- txt = txt.substr(1);
807
- result.push('<ul>');
808
- state = 'list';
809
- div = 'li';
810
- }
811
- else if (txt[0] == '>') {
812
- txt = txt.substr(1);
813
- result.push('<blockquote>');
814
- state = 'quote';
815
- div = 'p';
816
- }
817
- else if (txt[0] == '#') {
818
- let lvl = 0;
819
- do {
820
- txt = txt.substr(1);
821
- lvl++;
822
- } while (txt[0] == '#' && lvl < 5);
823
- div = 'h' + lvl;
824
- state = 'title';
825
- }
826
- }
827
- else if (state == 'list') {
828
- // sortie du mode list
829
- if (txt[0] != '-') {
830
- result.push('</ul>');
831
- state = 'para';
832
- div = 'p';
833
- }
834
- else {
835
- txt = txt.substr(1);
836
- }
837
- }
838
- else if (state == 'quote') {
839
- // sortie du mode blockquote
840
- if (txt[0] != '>') {
841
- result.push('</blockquote>');
842
- state = 'para';
843
- div = 'p';
844
- }
845
- else {
846
- txt = txt.substr(1);
847
- }
848
- }
849
- let reBold = /\*\*([^*]+)\*\*/gi;
850
- txt = escapeHtml(txt, false);
851
- txt = txt.replace(reBold, (sub, ...a) => {
852
- return '<b>' + sub.substr(2, sub.length - 4) + '</b>';
853
- });
854
- let reItalic = /\*([^*]+)\*/gi;
855
- txt = txt.replace(reItalic, (sub, ...a) => {
856
- return '<i>' + sub.substr(1, sub.length - 2) + '</i>';
857
- });
858
- // keep empty lines
859
- if (txt == '') {
860
- txt = '&nbsp;';
861
- }
862
- result.push(`<${div}>` + txt + `</${div}>`);
863
- if (state == 'title') {
864
- state = 'para';
865
- div = 'p';
866
- }
867
- });
868
- if (state == 'list') {
869
- result.push('</ul>');
870
- }
871
- else if (state == 'quote') {
872
- result.push('</blockquote>');
873
- }
874
- return result.join('');
875
- }
876
- exports.markdownToHtml = markdownToHtml;
877
- /**
878
- *
879
- */
880
- class NetworkError extends Error {
881
- constructor(a, b) {
882
- if (a instanceof Response) {
883
- super(a.statusText);
884
- this.m_code = a.status;
885
- }
886
- else {
887
- super(b);
888
- this.m_code = a;
889
- }
890
- }
891
- get code() {
892
- return this.m_code;
893
- }
894
- }
895
- exports.NetworkError = NetworkError;
896
- /**
897
- * return the mouse pos in client coordinates
898
- * handle correctly touch & mouse
899
- */
900
- function getMousePos(ev, fromDoc) {
901
- let x_name = 'offsetX', y_name = 'offsetY';
902
- if (fromDoc) {
903
- x_name = 'clientX';
904
- y_name = 'clientY';
905
- }
906
- if (ev.type == 'mousemove' || ev.type == 'mousedown' || ev.type == 'mouseup') {
907
- let em = ev;
908
- return new Point(em[x_name], em[y_name]);
909
- }
910
- else if (ev.type == 'pointermove' || ev.type == 'pointerdown' || ev.type == 'pointerup') {
911
- let em = ev;
912
- return new Point(em[x_name], em[y_name]);
913
- }
914
- else if (ev.type == 'touchmove' || ev.type == 'touchstart') {
915
- let et = ev;
916
- return new Point(et.touches[0][x_name], et.touches[0][y_name]);
917
- }
918
- else if (ev.type == 'contextmenu') {
919
- let em = ev;
920
- return new Point(em[x_name], em[y_name]);
921
- }
922
- else {
923
- return new Point(0, 0);
924
- }
925
- }
926
- exports.getMousePos = getMousePos;
927
- /**
928
- * clamp a value
929
- * @param v - value to clamp
930
- * @param min - min value
931
- * @param max - max value
932
- * @returns clamped value
933
- */
934
- function clamp(v, min, max) {
935
- return Math.min(Math.max(v, min), max);
936
- }
937
- exports.clamp = clamp;
938
- // :: HTML strings ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
939
- class HtmlString extends String {
940
- constructor(text) { super(text); }
941
- static from(text) {
942
- return new HtmlString(text);
943
- }
944
- }
945
- exports.HtmlString = HtmlString;
946
- function html(a, ...b) {
947
- return HtmlString.from(String.raw(a, ...b));
948
- }
949
- exports.html = html;
950
- function isHtmlString(val) {
951
- return val instanceof HtmlString;
952
- }
953
- exports.isHtmlString = isHtmlString;
954
- // :: CLIPBOARD ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
955
- class Clipboard {
956
- static copy(data) {
957
- if (navigator.clipboard) {
958
- navigator.clipboard.writeText(JSON.stringify(data));
959
- }
960
- }
961
- static paste(cb) {
962
- if (navigator.clipboard) {
963
- navigator.clipboard.readText().then(v => cb(v));
964
- }
965
- else {
966
- console.error('no clipboard, are you in https ?');
967
- }
968
- }
969
- }
970
- exports.Clipboard = Clipboard;
971
- // :: CRC32 ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
972
- /**
973
- * Calculates the CRC32 checksum of a string.
974
- * taken from: https://gist.github.com/wqli78/1330293/6d85cc967f32cccfcbad94ae7d088a3dcfc14bd9
975
- *
976
- * @param {String} str
977
- * @param {Boolean} hex
978
- * @return {String} checksum
979
- * @api public
980
- */
981
- function crc32(str) {
982
- let crc = ~0;
983
- let buf = Buffer.from(str);
984
- let i = 0, l = buf.length;
985
- while (i < l) {
986
- crc = (crc >>> 8) ^ crc32tab[(crc ^ buf[i]) & 0xff];
987
- i++;
988
- }
989
- return (crc ^ -1) >>> 0;
990
- }
991
- exports.crc32 = crc32;
992
- var crc32tab = new Int32Array([
993
- 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba,
994
- 0x076dc419, 0x706af48f, 0xe963a535, 0x9e6495a3,
995
- 0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988,
996
- 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07, 0x90bf1d91,
997
- 0x1db71064, 0x6ab020f2, 0xf3b97148, 0x84be41de,
998
- 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7,
999
- 0x136c9856, 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec,
1000
- 0x14015c4f, 0x63066cd9, 0xfa0f3d63, 0x8d080df5,
1001
- 0x3b6e20c8, 0x4c69105e, 0xd56041e4, 0xa2677172,
1002
- 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b,
1003
- 0x35b5a8fa, 0x42b2986c, 0xdbbbc9d6, 0xacbcf940,
1004
- 0x32d86ce3, 0x45df5c75, 0xdcd60dcf, 0xabd13d59,
1005
- 0x26d930ac, 0x51de003a, 0xc8d75180, 0xbfd06116,
1006
- 0x21b4f4b5, 0x56b3c423, 0xcfba9599, 0xb8bda50f,
1007
- 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924,
1008
- 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d,
1009
- 0x76dc4190, 0x01db7106, 0x98d220bc, 0xefd5102a,
1010
- 0x71b18589, 0x06b6b51f, 0x9fbfe4a5, 0xe8b8d433,
1011
- 0x7807c9a2, 0x0f00f934, 0x9609a88e, 0xe10e9818,
1012
- 0x7f6a0dbb, 0x086d3d2d, 0x91646c97, 0xe6635c01,
1013
- 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e,
1014
- 0x6c0695ed, 0x1b01a57b, 0x8208f4c1, 0xf50fc457,
1015
- 0x65b0d9c6, 0x12b7e950, 0x8bbeb8ea, 0xfcb9887c,
1016
- 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3, 0xfbd44c65,
1017
- 0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2,
1018
- 0x4adfa541, 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb,
1019
- 0x4369e96a, 0x346ed9fc, 0xad678846, 0xda60b8d0,
1020
- 0x44042d73, 0x33031de5, 0xaa0a4c5f, 0xdd0d7cc9,
1021
- 0x5005713c, 0x270241aa, 0xbe0b1010, 0xc90c2086,
1022
- 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f,
1023
- 0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4,
1024
- 0x59b33d17, 0x2eb40d81, 0xb7bd5c3b, 0xc0ba6cad,
1025
- 0xedb88320, 0x9abfb3b6, 0x03b6e20c, 0x74b1d29a,
1026
- 0xead54739, 0x9dd277af, 0x04db2615, 0x73dc1683,
1027
- 0xe3630b12, 0x94643b84, 0x0d6d6a3e, 0x7a6a5aa8,
1028
- 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1,
1029
- 0xf00f9344, 0x8708a3d2, 0x1e01f268, 0x6906c2fe,
1030
- 0xf762575d, 0x806567cb, 0x196c3671, 0x6e6b06e7,
1031
- 0xfed41b76, 0x89d32be0, 0x10da7a5a, 0x67dd4acc,
1032
- 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5,
1033
- 0xd6d6a3e8, 0xa1d1937e, 0x38d8c2c4, 0x4fdff252,
1034
- 0xd1bb67f1, 0xa6bc5767, 0x3fb506dd, 0x48b2364b,
1035
- 0xd80d2bda, 0xaf0a1b4c, 0x36034af6, 0x41047a60,
1036
- 0xdf60efc3, 0xa867df55, 0x316e8eef, 0x4669be79,
1037
- 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236,
1038
- 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f,
1039
- 0xc5ba3bbe, 0xb2bd0b28, 0x2bb45a92, 0x5cb36a04,
1040
- 0xc2d7ffa7, 0xb5d0cf31, 0x2cd99e8b, 0x5bdeae1d,
1041
- 0x9b64c2b0, 0xec63f226, 0x756aa39c, 0x026d930a,
1042
- 0x9c0906a9, 0xeb0e363f, 0x72076785, 0x05005713,
1043
- 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38,
1044
- 0x92d28e9b, 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21,
1045
- 0x86d3d2d4, 0xf1d4e242, 0x68ddb3f8, 0x1fda836e,
1046
- 0x81be16cd, 0xf6b9265b, 0x6fb077e1, 0x18b74777,
1047
- 0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c,
1048
- 0x8f659eff, 0xf862ae69, 0x616bffd3, 0x166ccf45,
1049
- 0xa00ae278, 0xd70dd2ee, 0x4e048354, 0x3903b3c2,
1050
- 0xa7672661, 0xd06016f7, 0x4969474d, 0x3e6e77db,
1051
- 0xaed16a4a, 0xd9d65adc, 0x40df0b66, 0x37d83bf0,
1052
- 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9,
1053
- 0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6,
1054
- 0xbad03605, 0xcdd70693, 0x54de5729, 0x23d967bf,
1055
- 0xb3667a2e, 0xc4614ab8, 0x5d681b02, 0x2a6f2b94,
1056
- 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d
1057
- ]);
1058
- // :: MIXINS ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
1059
- /**
1060
- * taken from this excellent article:
1061
- * https://justinfagnani.com/2015/12/21/real-mixins-with-javascript-classes/
1062
- *
1063
- * @example:
1064
- * class MyClass extends mix(MyBaseClass).with(Mixin1, Mixin2) {
1065
- * }
1066
- **/
1067
- const mix = (superclass) => new MixinBuilder(superclass);
1068
- exports.mix = mix;
1069
- class MixinBuilder {
1070
- constructor(superclass) {
1071
- this.superclass = superclass;
1072
- }
1073
- with(...mixins) {
1074
- return mixins.reduce((c, mixin) => mixin(c), this.superclass);
1075
- }
1076
- }
1077
- /**
1078
- * @example
1079
- *
1080
- * ```
1081
- * const cls = classNames( 'class1 class2', {
1082
- * 'class3': false,
1083
- * 'class4': true,
1084
- * });
1085
- *
1086
- * // even shorter
1087
- * const class1 = true, class2 = false;
1088
- * const cls = classNames( { class1, class2 } ); // cls = "class1"
1089
- *
1090
- * ```
1091
- *
1092
- * @returns
1093
- */
1094
- function classNames(...args) {
1095
- let result = '';
1096
- for (const cls of args) {
1097
- if (typeof cls === 'string') {
1098
- result += ' ' + cls;
1099
- }
1100
- else if (cls) {
1101
- for (const c in cls) {
1102
- if (cls[c])
1103
- result += ' ' + c;
1104
- }
1105
- }
1106
- }
1107
- return result;
1108
- }
1109
- exports.classNames = classNames;
1110
- function generatePassword(length, rules) {
1111
- if (!length || length == undefined) {
1112
- length = 8;
1113
- }
1114
- if (!rules) {
1115
- rules = [
1116
- { chars: "abcdefghijklmnopqrstuvwxyz", min: 3 },
1117
- { chars: "ABCDEFGHIJKLMNOPQRSTUVWXYZ", min: 2 },
1118
- { chars: "0123456789", min: 2 },
1119
- { chars: "!@#$*|%+-_.;", min: 2 } // At least 1 special char
1120
- ];
1121
- }
1122
- let allChars = "";
1123
- let allMin = 0;
1124
- rules.forEach(function (rule) {
1125
- allChars += rule.chars;
1126
- allMin += rule.min;
1127
- });
1128
- if (length < allMin) {
1129
- length = allMin;
1130
- }
1131
- rules.push({ chars: allChars, min: length - allMin });
1132
- let pswd = "";
1133
- rules.forEach(function (rule) {
1134
- if (rule.min > 0) {
1135
- pswd += shuffle(rule.chars, rule.min);
1136
- }
1137
- });
1138
- return shuffle(pswd);
1139
- }
1140
- exports.generatePassword = generatePassword;
1141
- function shuffle(str, maxlength) {
1142
- let shuffled = str.split('').sort(() => {
1143
- return 0.5 - Math.random();
1144
- }).join('');
1145
- if (maxlength > 0) {
1146
- shuffled = shuffled.substr(0, maxlength);
1147
- }
1148
- return shuffled;
1149
- }
1150
- /**
1151
- * taken from live-server
1152
- * https://github.com/tapio/live-server
1153
- * @param host
1154
- * @param port
1155
- */
1156
- function installHMR(host = "127.0.0.1", port = "9876", reloadCallback) {
1157
- let tm;
1158
- function refreshCSS() {
1159
- document.body.style.visibility = "hidden";
1160
- let sheets = [].slice.call(document.getElementsByTagName("link"));
1161
- let head = document.getElementsByTagName("head")[0];
1162
- for (let i = 0; i < sheets.length; ++i) {
1163
- let elem = sheets[i];
1164
- head.removeChild(elem);
1165
- let rel = elem.rel;
1166
- if (elem.href && typeof rel != "string" || rel.length == 0 || rel.toLowerCase() == "stylesheet") {
1167
- let url = elem.href.replace(/(&|\?)_cacheOverride=\d+/, '');
1168
- elem.href = url + (url.indexOf('?') >= 0 ? '&' : '?') + '_cacheOverride=' + (new Date().valueOf());
1169
- }
1170
- head.appendChild(elem);
1171
- }
1172
- if (tm) {
1173
- clearTimeout(tm);
1174
- }
1175
- tm = setTimeout(() => {
1176
- document.body.style.visibility = "unset";
1177
- }, 50);
1178
- }
1179
- const protocol = window.location.protocol === 'https:' ? 'wss://' : 'ws://';
1180
- const address = `${protocol}${host}:${port}/ws`;
1181
- const socket = new WebSocket(address);
1182
- socket.onmessage = function (msg) {
1183
- if (msg.data == 'reload') {
1184
- if (reloadCallback) {
1185
- reloadCallback();
1186
- }
1187
- else {
1188
- window.location.reload();
1189
- }
1190
- }
1191
- else if (msg.data == 'refreshcss') {
1192
- refreshCSS();
1193
- }
1194
- };
1195
- console.log('Live reload enabled.');
1196
- }
1197
- exports.installHMR = installHMR;