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