@iobroker/adapter-react-v5 5.0.3 → 5.0.5

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 (54) hide show
  1. package/Components/ColorPicker.d.ts +0 -1
  2. package/Components/ColorPicker.js +1 -1
  3. package/Components/ComplexCron.js +20 -28
  4. package/Components/CopyToClipboard.js +0 -4
  5. package/Components/CustomModal.js +1 -5
  6. package/Components/FileBrowser.js +13 -18
  7. package/Components/FileViewer.js +4 -11
  8. package/Components/Icon.d.ts +2 -2
  9. package/Components/Icon.js +2 -2
  10. package/Components/IconSelector.js +2 -10
  11. package/Components/Image.js +3 -1
  12. package/Components/Loader.d.ts +2 -2
  13. package/Components/Loader.js +1 -1
  14. package/Components/Loaders/PT.d.ts +1 -1
  15. package/Components/Loaders/PT.js +1 -1
  16. package/Components/Loaders/Vendor.d.ts +1 -1
  17. package/Components/Loaders/Vendor.js +2 -2
  18. package/Components/Logo.js +1 -1
  19. package/Components/MDUtils.js +2 -0
  20. package/Components/ObjectBrowser.d.ts +526 -2
  21. package/Components/ObjectBrowser.js +100 -84
  22. package/Components/SaveCloseButtons.js +9 -18
  23. package/Components/Schedule.js +2 -2
  24. package/Components/SimpleCron/cron2text.js +5 -3
  25. package/Components/SimpleCron/cronText.js +1 -1
  26. package/Components/SimpleCron/index.js +29 -35
  27. package/Components/TableResize.d.ts +1 -1
  28. package/Components/TableResize.js +1 -1
  29. package/Components/TextWithIcon.js +1 -1
  30. package/Components/TreeTable.js +5 -4
  31. package/Components/Utils.d.ts +58 -60
  32. package/Components/Utils.js +239 -197
  33. package/Dialogs/ComplexCron.js +2 -10
  34. package/Dialogs/Confirm.d.ts +1 -1
  35. package/Dialogs/Confirm.js +2 -4
  36. package/Dialogs/Cron.js +1 -3
  37. package/Dialogs/Error.d.ts +1 -11
  38. package/Dialogs/Error.js +1 -7
  39. package/Dialogs/Message.d.ts +1 -12
  40. package/Dialogs/Message.js +1 -8
  41. package/Dialogs/SelectFile.js +1 -5
  42. package/Dialogs/SelectID.d.ts +1 -1
  43. package/Dialogs/SelectID.js +13 -7
  44. package/Dialogs/SimpleCron.js +1 -3
  45. package/Dialogs/TextInput.js +1 -5
  46. package/GenericApp.d.ts +2 -3
  47. package/GenericApp.js +11 -9
  48. package/LegacyConnection.d.ts +11 -12
  49. package/LegacyConnection.js +350 -222
  50. package/README.md +4 -1
  51. package/i18n.d.ts +1 -1
  52. package/i18n.js +6 -8
  53. package/package.json +2 -2
  54. package/types.d.ts +27 -27
@@ -8,7 +8,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
8
8
  *
9
9
  * MIT License
10
10
  *
11
- **/
11
+ * */
12
12
  const react_1 = __importDefault(require("react"));
13
13
  const CopyToClipboard_1 = __importDefault(require("./CopyToClipboard"));
14
14
  const i18n_1 = __importDefault(require("../i18n"));
@@ -47,7 +47,8 @@ class Utils {
47
47
  * Capitalize words.
48
48
  */
49
49
  static CapitalWords(name) {
50
- return (name || '').split(/[\s_]/)
50
+ return (name || '')
51
+ .split(/[\s_]/)
51
52
  .filter(item => item)
52
53
  .map(word => (word ? word[0].toUpperCase() + word.substring(1).toLowerCase() : ''))
53
54
  .join(' ');
@@ -55,51 +56,73 @@ class Utils {
55
56
  static formatSeconds(seconds) {
56
57
  const days_ = Math.floor(seconds / (3600 * 24));
57
58
  seconds %= 3600 * 24;
58
- const hours = Math.floor(seconds / 3600);
59
+ const hours = Math.floor(seconds / 3600)
60
+ .toString()
61
+ .padStart(2, '0');
59
62
  seconds %= 3600;
60
- const minutes = Math.floor(seconds / 60);
63
+ const minutes = Math.floor(seconds / 60)
64
+ .toString()
65
+ .padStart(2, '0');
61
66
  seconds %= 60;
62
- seconds = Math.floor(seconds);
67
+ const secondsStr = Math.floor(seconds).toString().padStart(2, '0');
63
68
  let text = '';
64
69
  if (days_) {
65
70
  text += `${days_} ${i18n_1.default.t('ra_daysShortText')} `;
66
71
  }
67
- text += `${hours < 10 ? `0${hours}` : hours}:${minutes < 10 ? `0${minutes}` : minutes}:${seconds < 10 ? `0${seconds}` : seconds}`;
72
+ text += `${hours}:${minutes}:${secondsStr}`;
68
73
  return text;
69
74
  }
70
75
  /**
71
76
  * Get the name of the object by id from the name or description.
72
- * @param objects
73
- * @param id
74
- * @param settings
75
- * @param options
76
- * @param isDesc Set to true to get the description.
77
77
  */
78
- static getObjectName(objects, id, settings, options, isDesc) {
78
+ static getObjectName(objects, id, settings, options,
79
+ /** Set to true to get the description. */
80
+ isDesc) {
81
+ var _a;
79
82
  const item = objects[id];
80
83
  let text;
81
- const attr = isDesc ? 'desc' : 'name';
82
84
  if (typeof settings === 'string' && !options) {
83
85
  options = { language: settings };
84
86
  settings = null;
85
87
  }
86
88
  options = options || {};
87
89
  if (!options.language) {
88
- options.language = (objects['system.config'] && objects['system.config'].common && objects['system.config'].common.language) || window.sysLang || 'en';
90
+ options.language =
91
+ (objects['system.config'] &&
92
+ objects['system.config'].common &&
93
+ objects['system.config'].common.language) ||
94
+ window.sysLang ||
95
+ 'en';
89
96
  }
90
97
  if (settings === null || settings === void 0 ? void 0 : settings.name) {
91
- text = settings.name;
92
- if (typeof text === 'object') {
93
- text = (options.language && text[options.language]) || text.en;
98
+ const textObj = settings.name;
99
+ if (typeof textObj === 'object') {
100
+ text = (options.language && textObj[options.language]) || textObj.en;
101
+ }
102
+ else {
103
+ text = textObj;
94
104
  }
95
105
  }
96
- else if (item && item.common && item.common[attr]) {
97
- text = item.common[attr];
98
- if (attr !== 'desc' && !text && item.common.desc) {
99
- text = item.common.desc;
106
+ else if (isDesc && ((_a = item === null || item === void 0 ? void 0 : item.common) === null || _a === void 0 ? void 0 : _a.desc)) {
107
+ const textObj = item.common.desc;
108
+ if (typeof textObj === 'object') {
109
+ text = (options.language && textObj[options.language]) || textObj.en || textObj.de || textObj.ru || '';
100
110
  }
101
- if (typeof text === 'object') {
102
- text = (options.language && text[options.language]) || text.en || text.de || text.ru || '';
111
+ else {
112
+ text = textObj;
113
+ }
114
+ text = (text || '').toString().replace(/[_.]/g, ' ');
115
+ if (text === text.toUpperCase()) {
116
+ text = text[0] + text.substring(1).toLowerCase();
117
+ }
118
+ }
119
+ else if (!isDesc && item.common) {
120
+ const textObj = item.common.name || item.common.desc;
121
+ if (textObj && typeof textObj === 'object') {
122
+ text = (options.language && textObj[options.language]) || textObj.en || textObj.de || textObj.ru || '';
123
+ }
124
+ else {
125
+ text = textObj;
103
126
  }
104
127
  text = (text || '').toString().replace(/[_.]/g, ' ');
105
128
  if (text === text.toUpperCase()) {
@@ -115,40 +138,54 @@ class Utils {
115
138
  }
116
139
  /**
117
140
  * Get the name of the object from the name or description.
118
- * @param obj
119
- * @param settings or language
120
- * @param options
121
- * @param isDesc Set to true to get the description.
122
- * @param noTrim Allow to use spaces in name (by edit)
123
141
  */
124
- static getObjectNameFromObj(obj, settings, options, isDesc, noTrim) {
142
+ static getObjectNameFromObj(obj,
143
+ /** settings or language */
144
+ settings, options,
145
+ /** Set to true to get the description. */
146
+ isDesc,
147
+ /** Allow using spaces in name (by edit) */
148
+ noTrim) {
149
+ var _a, _b;
125
150
  const item = obj;
126
151
  let text = (obj && obj._id) || '';
127
- const attr = isDesc ? 'desc' : 'name';
128
152
  if (typeof settings === 'string' && !options) {
129
153
  options = { language: settings };
130
154
  settings = null;
131
155
  }
132
156
  options = options || {};
133
157
  if (settings === null || settings === void 0 ? void 0 : settings.name) {
134
- const textOrTranslation = settings.name;
135
- if (textOrTranslation && typeof textOrTranslation === 'object') {
136
- text = (options.language && textOrTranslation[options.language]) || textOrTranslation.en;
158
+ const name = settings.name;
159
+ if (typeof name === 'object') {
160
+ text = (options.language && name[options.language]) || name.en;
137
161
  }
138
162
  else {
139
- text = textOrTranslation;
163
+ text = name;
140
164
  }
141
165
  }
142
- else if ((item === null || item === void 0 ? void 0 : item.common) && item.common[attr]) {
143
- let textOrTranslation = item.common[attr];
144
- if (attr !== 'desc' && !textOrTranslation && item.common.desc) {
145
- textOrTranslation = item.common.desc;
166
+ else if (isDesc && ((_a = item === null || item === void 0 ? void 0 : item.common) === null || _a === void 0 ? void 0 : _a.desc)) {
167
+ const desc = item.common.desc;
168
+ if (typeof desc === 'object') {
169
+ text = (options.language && desc[options.language]) || desc.en;
146
170
  }
147
- if (typeof textOrTranslation === 'object') {
148
- text = (options.language && textOrTranslation[options.language]) || textOrTranslation.en;
171
+ else {
172
+ text = desc;
173
+ }
174
+ text = (text || '').toString().replace(/[_.]/g, ' ');
175
+ if (text === text.toUpperCase()) {
176
+ text = text[0] + text.substring(1).toLowerCase();
177
+ }
178
+ }
179
+ else if (!isDesc && ((_b = item === null || item === void 0 ? void 0 : item.common) === null || _b === void 0 ? void 0 : _b.name)) {
180
+ let name = item.common.name;
181
+ if (!name && item.common.desc) {
182
+ name = item.common.desc;
183
+ }
184
+ if (typeof name === 'object') {
185
+ text = (options.language && name[options.language]) || name.en;
149
186
  }
150
187
  else {
151
- text = textOrTranslation;
188
+ text = name;
152
189
  }
153
190
  text = (text || '').toString().replace(/[_.]/g, ' ');
154
191
  if (text === text.toUpperCase()) {
@@ -237,7 +274,10 @@ class Utils {
237
274
  }
238
275
  if (common === null || common === void 0 ? void 0 : common.custom) {
239
276
  settings = common.custom;
240
- settings = settings[NAMESPACE] && settings[NAMESPACE][options.user || 'admin'] ? JSON.parse(JSON.stringify(settings[NAMESPACE][options.user || 'admin'])) : { enabled: true };
277
+ settings =
278
+ settings[NAMESPACE] && settings[NAMESPACE][options.user || 'admin']
279
+ ? JSON.parse(JSON.stringify(settings[NAMESPACE][options.user || 'admin']))
280
+ : { enabled: true };
241
281
  }
242
282
  else {
243
283
  settings = { enabled: defaultEnabling === undefined ? true : defaultEnabling, useCustom: false };
@@ -245,11 +285,6 @@ class Utils {
245
285
  if (!Object.prototype.hasOwnProperty.call(settings, 'enabled')) {
246
286
  settings.enabled = defaultEnabling === undefined ? true : defaultEnabling;
247
287
  }
248
- // if (false && settings.useCommon) {
249
- // if (obj.color) settings.color = obj.color;
250
- // if (obj.icon) settings.icon = obj.icon;
251
- // if (obj.name) settings.name = obj.name;
252
- // } else {
253
288
  if (options) {
254
289
  if (!settings.name && options.name) {
255
290
  settings.name = options.name;
@@ -262,9 +297,15 @@ class Utils {
262
297
  }
263
298
  }
264
299
  if (common) {
265
- settings.color = settings.color || common.color;
266
- settings.icon = settings.icon || common.icon;
267
- settings.name = settings.name || common.name;
300
+ if (!settings.color && common.color) {
301
+ settings.color = common.color;
302
+ }
303
+ if (!settings.icon && common.icon) {
304
+ settings.icon = common.icon;
305
+ }
306
+ if (!settings.name && common.name) {
307
+ settings.name = common.name;
308
+ }
268
309
  }
269
310
  if (typeof settings.name === 'object') {
270
311
  settings.name = (options.language && settings.name[options.language]) || settings.name.en;
@@ -318,7 +359,7 @@ class Utils {
318
359
  * Get the icon for the given settings.
319
360
  */
320
361
  static getIcon(settings, style) {
321
- if (settings && settings.icon) {
362
+ if (settings === null || settings === void 0 ? void 0 : settings.icon) {
322
363
  // If UTF-8 icon
323
364
  if (settings.icon.length <= 2) {
324
365
  return react_1.default.createElement("span", { style: style || {} }, settings.icon);
@@ -335,12 +376,13 @@ class Utils {
335
376
  * Get the icon for the given object.
336
377
  */
337
378
  static getObjectIcon(id, obj) {
379
+ var _a;
338
380
  // If id is Object
339
381
  if (typeof id === 'object') {
340
382
  obj = id;
341
383
  id = obj === null || obj === void 0 ? void 0 : obj._id;
342
384
  }
343
- if (obj && obj.common && obj.common.icon) {
385
+ if ((_a = obj === null || obj === void 0 ? void 0 : obj.common) === null || _a === void 0 ? void 0 : _a.icon) {
344
386
  let icon = obj.common.icon;
345
387
  // If UTF-8 icon
346
388
  if (typeof icon === 'string' && icon.length <= 2) {
@@ -370,7 +412,7 @@ class Utils {
370
412
  return null;
371
413
  }
372
414
  /**
373
- * Splits CamelCase into words.
415
+ * Converts word1_word2 to word1Word2.
374
416
  */
375
417
  static splitCamelCase(text) {
376
418
  // if (false && text !== text.toUpperCase()) {
@@ -446,29 +488,30 @@ class Utils {
446
488
  b = parseInt(color.slice(4, 6), 16);
447
489
  }
448
490
  // http://stackoverflow.com/a/3943023/112731
449
- return (r * 0.299 + g * 0.587 + b * 0.114) <= 186;
491
+ return r * 0.299 + g * 0.587 + b * 0.114 <= 186;
450
492
  }
451
493
  /**
452
494
  * Get the time string in the format 00:00.
453
495
  */
454
496
  static getTimeString(seconds) {
455
- seconds = parseFloat(seconds.toString());
497
+ seconds = parseFloat(seconds);
456
498
  if (Number.isNaN(seconds)) {
457
499
  return '--:--';
458
500
  }
459
501
  const hours = Math.floor(seconds / 3600);
460
- const minutes = Math.floor((seconds % 3600) / 60);
461
- const secs = seconds % 60;
502
+ const minutes = Math.floor((seconds % 3600) / 60).toString().padStart(2, '0');
503
+ const secs = (seconds % 60).toString().padStart(2, '0');
462
504
  if (hours) {
463
- return `${hours}:${minutes < 10 ? `0${minutes}` : minutes}:${secs < 10 ? `0${secs}` : secs}`;
505
+ return `${hours}:${minutes}:${secs}`;
464
506
  }
465
- return `${minutes < 10 ? `0${minutes}` : minutes}:${secs < 10 ? `0${secs}` : secs}`;
507
+ return `${minutes}:${secs}`;
466
508
  }
467
509
  /**
468
510
  * Gets the wind direction with the given angle (degrees).
469
- * @param angle in degrees.
470
511
  */
471
- static getWindDirection(angle) {
512
+ static getWindDirection(
513
+ /** angle in degrees from 0° to 360° */
514
+ angle) {
472
515
  if (angle >= 0 && angle < 11.25) {
473
516
  return 'N';
474
517
  }
@@ -632,7 +675,7 @@ class Utils {
632
675
  // eslint-disable-next-line
633
676
  result.push(react_1.default.createElement("a", { key: `a${key++}`, href: href ? href[1] : '', target: target ? target[1] : '_blank', rel: rel ? rel[1] : '', style: { color: 'inherit' } }, title ? title[1] : ''));
634
677
  }
635
- m = text ? text.match(/<a [^<]+<\/a>|<br\s?\/?>|<b>[^<]+<\/b>|<i>[^<]+<\/i>/) : null;
678
+ m = text ? text.match(/<a [^<]+<\/a>|<br\/?>|<b>[^<]+<\/b>|<i>[^<]+<\/i>/) : null;
636
679
  if (!m) {
637
680
  text && result.push(react_1.default.createElement("span", { key: `a${key++}` }, text));
638
681
  }
@@ -674,7 +717,7 @@ class Utils {
674
717
  * Get the smart name from a state.
675
718
  */
676
719
  static getSmartNameFromObj(obj, instanceId, noCommon) {
677
- var _a;
720
+ var _a, _b;
678
721
  if (!noCommon) {
679
722
  if (!obj.common) {
680
723
  return obj.smartName;
@@ -687,8 +730,8 @@ class Utils {
687
730
  if (obj && !obj.common) {
688
731
  return obj.smartName;
689
732
  }
690
- return ((_a = obj === null || obj === void 0 ? void 0 : obj.common) === null || _a === void 0 ? void 0 : _a.custom) && obj.common.custom[instanceId] ?
691
- obj.common.custom[instanceId].smartName : undefined;
733
+ const custom = (_b = (_a = obj === null || obj === void 0 ? void 0 : obj.common) === null || _a === void 0 ? void 0 : _a.custom) === null || _b === void 0 ? void 0 : _b[instanceId];
734
+ return custom ? custom.smartName : undefined;
692
735
  }
693
736
  /**
694
737
  * Enable smart name for a state.
@@ -717,7 +760,7 @@ class Utils {
717
760
  }
718
761
  }
719
762
  /**
720
- * Update the smartname of a state.
763
+ * Update the smart name of a state.
721
764
  */
722
765
  static updateSmartName(obj, newSmartName, byON, smartType, instanceId, noCommon) {
723
766
  const language = i18n_1.default.getLanguage();
@@ -731,12 +774,11 @@ class Utils {
731
774
  if (obj.native && obj.native.byON) {
732
775
  delete obj.native.byON;
733
776
  let _smartName = obj.common.smartName;
734
- if (!_smartName) {
735
- _smartName = {};
736
- }
737
- else if (typeof _smartName !== 'object') {
738
- _smartName = { en: _smartName };
739
- _smartName[language] = _smartName.en;
777
+ if (_smartName && typeof _smartName !== 'object') {
778
+ _smartName = {
779
+ en: _smartName,
780
+ [language]: _smartName,
781
+ };
740
782
  }
741
783
  obj.common.smartName = _smartName;
742
784
  }
@@ -755,9 +797,11 @@ class Utils {
755
797
  else {
756
798
  obj.common.smartName = obj.common.smartName || {};
757
799
  if (!smartType) {
800
+ // @ts-expect-error fixed in js-controller
758
801
  delete obj.common.smartName.smartType;
759
802
  }
760
803
  else {
804
+ // @ts-expect-error fixed in js-controller
761
805
  obj.common.smartName.smartType = smartType;
762
806
  }
763
807
  }
@@ -771,6 +815,7 @@ class Utils {
771
815
  }
772
816
  else {
773
817
  obj.common.smartName = obj.common.smartName || {};
818
+ // @ts-expect-error fixed in js-controller
774
819
  obj.common.smartName.byON = byON;
775
820
  }
776
821
  }
@@ -788,9 +833,10 @@ class Utils {
788
833
  }
789
834
  smartName[language] = newSmartName;
790
835
  // If smart name deleted
791
- if (smartName && (!smartName[language] ||
792
- (smartName[language] === obj.common.name &&
793
- (!obj.common.role || obj.common.role.includes('button'))))) {
836
+ if (smartName &&
837
+ (!smartName[language] ||
838
+ (smartName[language] === obj.common.name &&
839
+ (!obj.common.role || obj.common.role.includes('button'))))) {
794
840
  delete smartName[language];
795
841
  let empty = true;
796
842
  // Check if the structure has any definitions
@@ -819,20 +865,21 @@ class Utils {
819
865
  delete obj.common.custom[instanceId].uk;
820
866
  delete obj.common.custom[instanceId]['zh-cn'];
821
867
  }
822
- // @ts-expect-error
868
+ // @ts-expect-error fixed in js-controller
823
869
  }
824
870
  else if (obj.common.smartName && obj.common.smartName.byON !== undefined) {
825
- delete obj.common.smartName.en;
826
- delete obj.common.smartName.de;
827
- delete obj.common.smartName.ru;
828
- delete obj.common.smartName.nl;
829
- delete obj.common.smartName.pl;
830
- delete obj.common.smartName.it;
831
- delete obj.common.smartName.fr;
832
- delete obj.common.smartName.pt;
833
- delete obj.common.smartName.es;
834
- delete obj.common.smartName.uk;
835
- delete obj.common.smartName['zh-cn'];
871
+ const _smartName = obj.common.smartName;
872
+ delete _smartName.en;
873
+ delete _smartName.de;
874
+ delete _smartName.ru;
875
+ delete _smartName.nl;
876
+ delete _smartName.pl;
877
+ delete _smartName.it;
878
+ delete _smartName.fr;
879
+ delete _smartName.pt;
880
+ delete _smartName.es;
881
+ delete _smartName.uk;
882
+ delete _smartName['zh-cn'];
836
883
  }
837
884
  else {
838
885
  obj.common.smartName = null;
@@ -879,10 +926,11 @@ class Utils {
879
926
  /**
880
927
  * Format number of bytes as a string with B, KB, MB or GB.
881
928
  * The base for all calculations is 1024.
882
- * @param bytes The number of bytes.
883
929
  * @returns The formatted string (e.g. '723.5 KB')
884
930
  */
885
- static formatBytes(bytes) {
931
+ static formatBytes(
932
+ /** The number of bytes. */
933
+ bytes) {
886
934
  if (Math.abs(bytes) < 1024) {
887
935
  return `${bytes} B`;
888
936
  }
@@ -897,11 +945,12 @@ class Utils {
897
945
  }
898
946
  /**
899
947
  * Invert the given color according to a theme type to get the inverted text color for background
900
- * @param color Color in the format '#rrggbb' or '#rgb' (or without a hash)
901
- * @param themeType theme type
902
- * @param invert dark theme has light color in control or light theme has light color in control
903
948
  */
904
- static getInvertedColor(color, themeType, invert) {
949
+ static getInvertedColor(
950
+ /** Color in the format '#rrggbb' or '#rgb' (or without a hash) */
951
+ color, themeType,
952
+ /** dark theme has light color in control, or light theme has light color in control */
953
+ invert) {
905
954
  if (!color) {
906
955
  return undefined;
907
956
  }
@@ -927,17 +976,19 @@ class Utils {
927
976
  if (hex.startsWith('rgba')) {
928
977
  const m = hex.match(/rgba?\((\d+),\s*(\d+),\s*(\d+),\s*([.\d]+)\)/);
929
978
  if (m) {
930
- hex = parseInt(m[1], 10).toString(16).padStart(2, '0') +
931
- parseInt(m[2], 10).toString(16).padStart(2, '0') +
932
- parseInt(m[2], 10).toString(16).padStart(2, '0');
979
+ hex =
980
+ parseInt(m[1], 10).toString(16).padStart(2, '0') +
981
+ parseInt(m[2], 10).toString(16).padStart(2, '0') +
982
+ parseInt(m[2], 10).toString(16).padStart(2, '0');
933
983
  }
934
984
  }
935
985
  else if (hex.startsWith('rgb')) {
936
986
  const m = hex.match(/rgb?\((\d+),\s*(\d+),\s*(\d+)\)/);
937
987
  if (m) {
938
- hex = parseInt(m[1], 10).toString(16).padStart(2, '0') +
939
- parseInt(m[2], 10).toString(16).padStart(2, '0') +
940
- parseInt(m[2], 10).toString(16).padStart(2, '0');
988
+ hex =
989
+ parseInt(m[1], 10).toString(16).padStart(2, '0') +
990
+ parseInt(m[2], 10).toString(16).padStart(2, '0') +
991
+ parseInt(m[2], 10).toString(16).padStart(2, '0');
941
992
  }
942
993
  }
943
994
  else if (hex.startsWith('#')) {
@@ -961,7 +1012,7 @@ class Utils {
961
1012
  const b = parseInt(hex.slice(4, 6), 16);
962
1013
  if (bw) {
963
1014
  // http://stackoverflow.com/a/3943023/112731
964
- return (r * 0.299 + g * 0.587 + b * 0.114) > 186
1015
+ return r * 0.299 + g * 0.587 + b * 0.114 > 186
965
1016
  ? `#000000${alfa || ''}`
966
1017
  : `#FFFFFF${alfa || ''}`;
967
1018
  }
@@ -979,22 +1030,24 @@ class Utils {
979
1030
  */
980
1031
  static color2rgb(hex) {
981
1032
  if (hex === undefined || hex === null || hex === '' || typeof hex !== 'string') {
982
- return '';
1033
+ return false;
983
1034
  }
984
1035
  if (hex.startsWith('rgba')) {
985
1036
  const m = hex.match(/rgba?\((\d+),\s*(\d+),\s*(\d+),\s*([.\d]+)\)/);
986
1037
  if (m) {
987
- hex = parseInt(m[1], 10).toString(16).padStart(2, '0') +
988
- parseInt(m[2], 10).toString(16).padStart(2, '0') +
989
- parseInt(m[2], 10).toString(16).padStart(2, '0');
1038
+ hex =
1039
+ parseInt(m[1], 10).toString(16).padStart(2, '0') +
1040
+ parseInt(m[2], 10).toString(16).padStart(2, '0') +
1041
+ parseInt(m[2], 10).toString(16).padStart(2, '0');
990
1042
  }
991
1043
  }
992
1044
  else if (hex.startsWith('rgb')) {
993
1045
  const m = hex.match(/rgb?\((\d+),\s*(\d+),\s*(\d+)\)/);
994
1046
  if (m) {
995
- hex = parseInt(m[1], 10).toString(16).padStart(2, '0') +
996
- parseInt(m[2], 10).toString(16).padStart(2, '0') +
997
- parseInt(m[2], 10).toString(16).padStart(2, '0');
1047
+ hex =
1048
+ parseInt(m[1], 10).toString(16).padStart(2, '0') +
1049
+ parseInt(m[2], 10).toString(16).padStart(2, '0') +
1050
+ parseInt(m[2], 10).toString(16).padStart(2, '0');
998
1051
  }
999
1052
  }
1000
1053
  else if (hex.startsWith('#')) {
@@ -1024,16 +1077,16 @@ class Utils {
1024
1077
  let r = rgb[0] / 255;
1025
1078
  let g = rgb[1] / 255;
1026
1079
  let b = rgb[2] / 255;
1027
- r = (r > 0.04045) ? ((r + 0.055) / 1.055) ** 2.4 : r / 12.92;
1028
- g = (g > 0.04045) ? ((g + 0.055) / 1.055) ** 2.4 : g / 12.92;
1029
- b = (b > 0.04045) ? ((b + 0.055) / 1.055) ** 2.4 : b / 12.92;
1080
+ r = r > 0.04045 ? ((r + 0.055) / 1.055) ** 2.4 : r / 12.92;
1081
+ g = g > 0.04045 ? ((g + 0.055) / 1.055) ** 2.4 : g / 12.92;
1082
+ b = b > 0.04045 ? ((b + 0.055) / 1.055) ** 2.4 : b / 12.92;
1030
1083
  let x = (r * 0.4124 + g * 0.3576 + b * 0.1805) / 0.95047;
1031
- let y = (r * 0.2126 + g * 0.7152 + b * 0.0722); /* / 1.00000; */
1084
+ let y = r * 0.2126 + g * 0.7152 + b * 0.0722; /* / 1.00000; */
1032
1085
  let z = (r * 0.0193 + g * 0.1192 + b * 0.9505) / 1.08883;
1033
- x = (x > 0.008856) ? x ** 0.33333333 : (7.787 * x) + 0.137931; // 16 / 116;
1034
- y = (y > 0.008856) ? y ** 0.33333333 : (7.787 * y) + 0.137931; // 16 / 116;
1035
- z = (z > 0.008856) ? z ** 0.33333333 : (7.787 * z) + 0.137931; // 16 / 116;
1036
- return [(116 * y) - 16, 500 * (x - y), 200 * (y - z)];
1086
+ x = x > 0.008856 ? x ** 0.33333333 : 7.787 * x + 0.137931; // 16 / 116;
1087
+ y = y > 0.008856 ? y ** 0.33333333 : 7.787 * y + 0.137931; // 16 / 116;
1088
+ z = z > 0.008856 ? z ** 0.33333333 : 7.787 * z + 0.137931; // 16 / 116;
1089
+ return [116 * y - 16, 500 * (x - y), 200 * (y - z)];
1037
1090
  }
1038
1091
  /**
1039
1092
  * Calculate the distance between two colors in LAB color space in the range 0-100^2
@@ -1133,8 +1186,11 @@ class Utils {
1133
1186
  if (window.vendorPrefix && window.vendorPrefix !== '@@vendorPrefix@@' && window.vendorPrefix !== 'MV') {
1134
1187
  return window.vendorPrefix;
1135
1188
  }
1136
- return themeName || ((window._localStorage || window.localStorage).getItem('App.themeName') ?
1137
- (window._localStorage || window.localStorage).getItem('App.themeName') : window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'colored');
1189
+ themeName = (window._localStorage || window.localStorage).getItem('App.themeName');
1190
+ if (themeName) {
1191
+ return themeName;
1192
+ }
1193
+ return window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'colored';
1138
1194
  }
1139
1195
  /**
1140
1196
  * Get the type of theme.
@@ -1194,7 +1250,6 @@ class Utils {
1194
1250
  */
1195
1251
  static parseQuery(query) {
1196
1252
  query = (query || '').toString().replace(/^\?/, '');
1197
- /** @type {Record<string, string | boolean | number>} */
1198
1253
  const result = {};
1199
1254
  query.split('&').forEach(part => {
1200
1255
  part = part.trim();
@@ -1202,18 +1257,21 @@ class Utils {
1202
1257
  const parts = part.split('=');
1203
1258
  const attr = decodeURIComponent(parts[0]).trim();
1204
1259
  if (parts.length > 1) {
1205
- result[attr] = decodeURIComponent(parts[1]);
1206
- if (result[attr] === 'true') {
1260
+ const value = decodeURIComponent(parts[1]);
1261
+ if (value === 'true') {
1207
1262
  result[attr] = true;
1208
1263
  }
1209
- else if (result[attr] === 'false') {
1264
+ else if (value === 'false') {
1210
1265
  result[attr] = false;
1211
1266
  }
1212
- else if (result[attr]) {
1213
- const f = parseFloat(result[attr].toString());
1214
- if (f.toString() === result[attr]) {
1267
+ else {
1268
+ const f = parseFloat(value);
1269
+ if (f.toString() === value) {
1215
1270
  result[attr] = f;
1216
1271
  }
1272
+ else {
1273
+ result[attr] = value;
1274
+ }
1217
1275
  }
1218
1276
  }
1219
1277
  else {
@@ -1241,46 +1299,23 @@ class Utils {
1241
1299
  return '';
1242
1300
  }
1243
1301
  let text;
1244
- const mm = dateObj.getMonth() + 1;
1245
- const dd = dateObj.getDate();
1302
+ const mm = (dateObj.getMonth() + 1).toString().padStart(2, '0');
1303
+ const dd = dateObj.getDate().toString().padStart(2, '0');
1246
1304
  if (dateFormat === 'MM/DD/YYYY') {
1247
- text = `${mm < 10 ? `0${mm}` : mm}/${dd < 10 ? `0${dd}` : dd}/${dateObj.getFullYear()}`;
1305
+ text = `${mm}/${dd}/${dateObj.getFullYear()}`;
1248
1306
  }
1249
1307
  else {
1250
1308
  text = `${dateObj.getFullYear()}-${mm}-${dd}`;
1251
1309
  }
1252
1310
  // time
1253
- let v = dateObj.getHours();
1254
- if (v < 10) {
1255
- text += ` 0${v}`;
1256
- }
1257
- else {
1258
- text += ` ${v}`;
1259
- }
1260
- v = dateObj.getMinutes();
1261
- if (v < 10) {
1262
- text += `:0${v}`;
1263
- }
1264
- else {
1265
- text += `:${v}`;
1266
- }
1267
- v = dateObj.getSeconds();
1268
- if (v < 10) {
1269
- text += `:0${v}`;
1270
- }
1271
- else {
1272
- text += `:${v}`;
1273
- }
1274
- v = dateObj.getMilliseconds();
1275
- if (v < 10) {
1276
- text += `.00${v}`;
1277
- }
1278
- else if (v < 100) {
1279
- text += `.0${v}`;
1280
- }
1281
- else {
1282
- text += `.${v}`;
1283
- }
1311
+ let v = dateObj.getHours().toString().padStart(2, '0');
1312
+ text += ` ${v}`;
1313
+ v = dateObj.getMinutes().toString().toString();
1314
+ text += `:${v}`;
1315
+ v = dateObj.getSeconds().toString().padStart(2, '0');
1316
+ text += `:${v}`;
1317
+ v = dateObj.getMilliseconds().toString().padStart(3, '0');
1318
+ text += `.${v}`;
1284
1319
  return text;
1285
1320
  }
1286
1321
  /*
@@ -1308,7 +1343,11 @@ class Utils {
1308
1343
  if (m) {
1309
1344
  text = text.replace(m[0], m[0].replace(/\s/, '&nbsp;'));
1310
1345
  }
1311
- return text.replace(/[^a-zA-Zа-яА-Я0-9]/g, '').trim().replace(/\s/g, '').toLowerCase();
1346
+ return text
1347
+ .replace(/[^a-zA-Zа-яА-Я0-9]/g, '')
1348
+ .trim()
1349
+ .replace(/\s/g, '')
1350
+ .toLowerCase();
1312
1351
  }
1313
1352
  /*
1314
1353
  Open url link in the new target window
@@ -1324,6 +1363,7 @@ class Utils {
1324
1363
  }
1325
1364
  }
1326
1365
  static MDgetTitle(text) {
1366
+ var _a;
1327
1367
  const result = Utils.MDextractHeader(text);
1328
1368
  const header = result.header;
1329
1369
  let body = result.body;
@@ -1339,7 +1379,7 @@ class Utils {
1339
1379
  }
1340
1380
  return '';
1341
1381
  }
1342
- return header.title ? header.title.toString() : '';
1382
+ return ((_a = header.title) === null || _a === void 0 ? void 0 : _a.toString()) || '';
1343
1383
  }
1344
1384
  static MDextractHeader(text) {
1345
1385
  const attrs = {};
@@ -1355,19 +1395,19 @@ class Utils {
1355
1395
  const pos_ = line.indexOf(':');
1356
1396
  if (pos_ !== -1) {
1357
1397
  const attr = line.substring(0, pos_).trim();
1358
- let val = line.substring(pos_ + 1).trim();
1359
- val = val.replace(/^['"]|['"]$/g, '');
1360
- if (val === 'true') {
1398
+ let value = line.substring(pos_ + 1).trim();
1399
+ value = value.replace(/^['"]|['"]$/g, '');
1400
+ if (value === 'true') {
1361
1401
  attrs[attr] = true;
1362
1402
  }
1363
- else if (val === 'false') {
1403
+ else if (value === 'false') {
1364
1404
  attrs[attr] = false;
1365
1405
  }
1366
- else if (parseFloat(val).toString() === val) {
1367
- attrs[attr] = parseFloat(val);
1406
+ else if (parseFloat(value).toString() === attrs[attr]) {
1407
+ attrs[attr] = parseFloat(value);
1368
1408
  }
1369
1409
  else {
1370
- attrs[attr] = val;
1410
+ attrs[attr] = value;
1371
1411
  }
1372
1412
  }
1373
1413
  else {
@@ -1382,17 +1422,16 @@ class Utils {
1382
1422
  static MDremoveDocsify(text) {
1383
1423
  const m = text.match(/{docsify-[^}]*}/g);
1384
1424
  if (m) {
1385
- m.forEach(doc => text = text.replace(doc, ''));
1425
+ m.forEach(doc => (text = text.replace(doc, '')));
1386
1426
  }
1387
1427
  return text;
1388
1428
  }
1389
1429
  /**
1390
- * Generate the json file on the file for download.
1391
- * @param fileName file name
1392
- * @param json file data
1393
- * @returns {object} json structure (not stringified)
1430
+ * Generate the file for download from JSON object.
1394
1431
  */
1395
- static generateFile(fileName, json) {
1432
+ static generateFile(fileName,
1433
+ /** json file data */
1434
+ json) {
1396
1435
  const el = document.createElement('a');
1397
1436
  el.setAttribute('href', `data:application/json;charset=utf-8,${encodeURIComponent(JSON.stringify(json, null, 2))}`);
1398
1437
  el.setAttribute('download', fileName);
@@ -1444,42 +1483,45 @@ class Utils {
1444
1483
  */
1445
1484
  static getStates(obj) {
1446
1485
  var _a;
1447
- let states = (_a = obj === null || obj === void 0 ? void 0 : obj.common) === null || _a === void 0 ? void 0 : _a.states;
1486
+ const states = (_a = obj === null || obj === void 0 ? void 0 : obj.common) === null || _a === void 0 ? void 0 : _a.states;
1487
+ let result;
1448
1488
  if (states) {
1449
1489
  if (typeof states === 'string' && states[0] === '{') {
1450
1490
  try {
1451
- states = JSON.parse(states);
1491
+ result = JSON.parse(states);
1452
1492
  }
1453
1493
  catch (ex) {
1454
1494
  console.error(`Cannot parse states: ${states}`);
1455
- states = null;
1495
+ result = null;
1456
1496
  }
1457
1497
  }
1458
1498
  else if (typeof states === 'string') {
1459
1499
  // if old format val1:text1;val2:text2
1460
1500
  const parts = states.split(';');
1461
- states = {};
1501
+ result = {};
1462
1502
  for (let p = 0; p < parts.length; p++) {
1463
1503
  const s = parts[p].split(':');
1464
- states[s[0]] = s[1];
1504
+ result[s[0]] = s[1];
1465
1505
  }
1466
1506
  }
1467
1507
  else if (Array.isArray(states)) {
1468
- const result = {};
1508
+ result = {};
1469
1509
  if ((obj === null || obj === void 0 ? void 0 : obj.common.type) === 'number') {
1470
- states.forEach((value, key) => result[key] = value);
1510
+ states.forEach((value, key) => (result[key] = value));
1471
1511
  }
1472
1512
  else if ((obj === null || obj === void 0 ? void 0 : obj.common.type) === 'string') {
1473
- states.forEach(value => result[value] = value);
1513
+ states.forEach(value => (result[value] = value));
1474
1514
  }
1475
1515
  else if ((obj === null || obj === void 0 ? void 0 : obj.common.type) === 'boolean') {
1476
1516
  result.false = states[0];
1477
1517
  result.true = states[1];
1478
1518
  }
1479
- return result;
1519
+ }
1520
+ else if (typeof states === 'object') {
1521
+ result = states;
1480
1522
  }
1481
1523
  }
1482
- return states ? states : null;
1524
+ return result || null;
1483
1525
  }
1484
1526
  /**
1485
1527
  * Get svg file as text
@@ -1489,7 +1531,7 @@ class Utils {
1489
1531
  static async getSvg(url) {
1490
1532
  const response = await fetch(url);
1491
1533
  const blob = await response.blob();
1492
- return await new Promise(resolve => {
1534
+ return new Promise(resolve => {
1493
1535
  const reader = new FileReader();
1494
1536
  // eslint-disable-next-line func-names
1495
1537
  reader.onload = function () {
@@ -1501,19 +1543,20 @@ class Utils {
1501
1543
  }
1502
1544
  /**
1503
1545
  * Detect file extension by its content
1504
- * @param {string} base64 Base64 encoded binary file
1505
- * @returns {string} Detected extension, like 'jpg'
1546
+ * @returns Detected extension, like 'jpg'
1506
1547
  */
1507
- static detectMimeType(base64) {
1548
+ static detectMimeType(
1549
+ /** Base64 encoded binary file */
1550
+ base64) {
1508
1551
  const signature = Object.keys(SIGNATURES).find(s => base64.startsWith(s));
1509
1552
  return signature ? SIGNATURES[signature] : null;
1510
1553
  }
1511
1554
  /**
1512
1555
  * Check if configured repository is the stable repository
1513
- *
1514
- * @param activeRepo current configured repository or multi repository
1515
1556
  */
1516
- static isStableRepository(activeRepo) {
1557
+ static isStableRepository(
1558
+ /** current configured repository or multi repository */
1559
+ activeRepo) {
1517
1560
  return !!((typeof activeRepo === 'string' &&
1518
1561
  activeRepo.toLowerCase().startsWith('stable'))
1519
1562
  ||
@@ -1523,20 +1566,19 @@ class Utils {
1523
1566
  }
1524
1567
  /**
1525
1568
  * Check if a given string is an integer
1526
- *
1527
- * @param str string to check
1528
1569
  */
1529
1570
  static isStringInteger(str) {
1530
- return parseInt(str).toString() === str;
1571
+ if (typeof str === 'number') {
1572
+ return Math.round(str) === str;
1573
+ }
1574
+ return parseInt(str, 10).toString() === str;
1531
1575
  }
1532
1576
  /**
1533
1577
  * Check if the date is valid
1534
- *
1535
- * @param {Date} date
1536
- * @return {boolean}
1537
1578
  */
1538
1579
  static isValidDate(date) {
1539
- return date instanceof Date && !isNaN(date.getTime());
1580
+ // eslint-disable-next-line no-restricted-globals
1581
+ return date instanceof Date && !isNaN(date);
1540
1582
  }
1541
1583
  }
1542
1584
  Utils.namespace = NAMESPACE;