@iobroker/gui-components 8.0.1

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 (368) hide show
  1. package/LICENSE +22 -0
  2. package/README.md +1450 -0
  3. package/build/AdminConnection.d.ts +1 -0
  4. package/build/AdminConnection.js +2 -0
  5. package/build/AdminConnection.js.map +1 -0
  6. package/build/Components/404.d.ts +4 -0
  7. package/build/Components/404.js +97 -0
  8. package/build/Components/404.js.map +1 -0
  9. package/build/Components/ColorPicker.d.ts +86 -0
  10. package/build/Components/ColorPicker.js +222 -0
  11. package/build/Components/ColorPicker.js.map +1 -0
  12. package/build/Components/ComplexCron.d.ts +40 -0
  13. package/build/Components/ComplexCron.js +401 -0
  14. package/build/Components/ComplexCron.js.map +1 -0
  15. package/build/Components/CopyToClipboard.d.ts +14 -0
  16. package/build/Components/CopyToClipboard.js +160 -0
  17. package/build/Components/CopyToClipboard.js.map +1 -0
  18. package/build/Components/CustomModal.d.ts +26 -0
  19. package/build/Components/CustomModal.js +62 -0
  20. package/build/Components/CustomModal.js.map +1 -0
  21. package/build/Components/DeviceType/DeviceTypeIcon.d.ts +29 -0
  22. package/build/Components/DeviceType/DeviceTypeIcon.js +108 -0
  23. package/build/Components/DeviceType/DeviceTypeIcon.js.map +1 -0
  24. package/build/Components/DeviceType/DeviceTypeOptions.d.ts +2 -0
  25. package/build/Components/DeviceType/DeviceTypeOptions.js +69 -0
  26. package/build/Components/DeviceType/DeviceTypeOptions.js.map +1 -0
  27. package/build/Components/DeviceType/DeviceTypeSelector.d.ts +20 -0
  28. package/build/Components/DeviceType/DeviceTypeSelector.js +83 -0
  29. package/build/Components/DeviceType/DeviceTypeSelector.js.map +1 -0
  30. package/build/Components/DeviceType/deviceTypeTranslations.d.ts +1 -0
  31. package/build/Components/DeviceType/deviceTypeTranslations.js +30 -0
  32. package/build/Components/DeviceType/deviceTypeTranslations.js.map +1 -0
  33. package/build/Components/DeviceType/i18n/de.json +46 -0
  34. package/build/Components/DeviceType/i18n/en.json +46 -0
  35. package/build/Components/DeviceType/i18n/fr.json +46 -0
  36. package/build/Components/DeviceType/i18n/it.json +46 -0
  37. package/build/Components/DeviceType/i18n/nl.json +46 -0
  38. package/build/Components/DeviceType/i18n/pl.json +46 -0
  39. package/build/Components/DeviceType/i18n/pt.json +46 -0
  40. package/build/Components/DeviceType/i18n/ru.json +46 -0
  41. package/build/Components/DeviceType/i18n/uk.json +46 -0
  42. package/build/Components/DeviceType/i18n/zh-cn.json +46 -0
  43. package/build/Components/DeviceType/icons/Cleaner.d.ts +3 -0
  44. package/build/Components/DeviceType/icons/Cleaner.js +14 -0
  45. package/build/Components/DeviceType/icons/Cleaner.js.map +1 -0
  46. package/build/Components/DeviceType/icons/DoorClosed.d.ts +3 -0
  47. package/build/Components/DeviceType/icons/DoorClosed.js +7 -0
  48. package/build/Components/DeviceType/icons/DoorClosed.js.map +1 -0
  49. package/build/Components/DeviceType/icons/DoorOpened.d.ts +3 -0
  50. package/build/Components/DeviceType/icons/DoorOpened.js +7 -0
  51. package/build/Components/DeviceType/icons/DoorOpened.js.map +1 -0
  52. package/build/Components/DeviceType/icons/FireOff.d.ts +3 -0
  53. package/build/Components/DeviceType/icons/FireOff.js +8 -0
  54. package/build/Components/DeviceType/icons/FireOff.js.map +1 -0
  55. package/build/Components/DeviceType/icons/FireOn.d.ts +3 -0
  56. package/build/Components/DeviceType/icons/FireOn.js +14 -0
  57. package/build/Components/DeviceType/icons/FireOn.js.map +1 -0
  58. package/build/Components/DeviceType/icons/FloodOff.d.ts +3 -0
  59. package/build/Components/DeviceType/icons/FloodOff.js +11 -0
  60. package/build/Components/DeviceType/icons/FloodOff.js.map +1 -0
  61. package/build/Components/DeviceType/icons/FloodOn.d.ts +3 -0
  62. package/build/Components/DeviceType/icons/FloodOn.js +18 -0
  63. package/build/Components/DeviceType/icons/FloodOn.js.map +1 -0
  64. package/build/Components/DeviceType/icons/Gate.d.ts +3 -0
  65. package/build/Components/DeviceType/icons/Gate.js +8 -0
  66. package/build/Components/DeviceType/icons/Gate.js.map +1 -0
  67. package/build/Components/DeviceType/icons/HeatValve.d.ts +3 -0
  68. package/build/Components/DeviceType/icons/HeatValve.js +6 -0
  69. package/build/Components/DeviceType/icons/HeatValve.js.map +1 -0
  70. package/build/Components/DeviceType/icons/Home.d.ts +3 -0
  71. package/build/Components/DeviceType/icons/Home.js +6 -0
  72. package/build/Components/DeviceType/icons/Home.js.map +1 -0
  73. package/build/Components/DeviceType/icons/Humidity.d.ts +3 -0
  74. package/build/Components/DeviceType/icons/Humidity.js +8 -0
  75. package/build/Components/DeviceType/icons/Humidity.js.map +1 -0
  76. package/build/Components/DeviceType/icons/IconHome.d.ts +5 -0
  77. package/build/Components/DeviceType/icons/IconHome.js +21 -0
  78. package/build/Components/DeviceType/icons/IconHome.js.map +1 -0
  79. package/build/Components/DeviceType/icons/Jalousie.d.ts +3 -0
  80. package/build/Components/DeviceType/icons/Jalousie.js +7 -0
  81. package/build/Components/DeviceType/icons/Jalousie.js.map +1 -0
  82. package/build/Components/DeviceType/icons/Material.d.ts +3 -0
  83. package/build/Components/DeviceType/icons/Material.js +8 -0
  84. package/build/Components/DeviceType/icons/Material.js.map +1 -0
  85. package/build/Components/DeviceType/icons/MotionOff.d.ts +3 -0
  86. package/build/Components/DeviceType/icons/MotionOff.js +11 -0
  87. package/build/Components/DeviceType/icons/MotionOff.js.map +1 -0
  88. package/build/Components/DeviceType/icons/MotionOn.d.ts +3 -0
  89. package/build/Components/DeviceType/icons/MotionOn.js +7 -0
  90. package/build/Components/DeviceType/icons/MotionOn.js.map +1 -0
  91. package/build/Components/DeviceType/icons/PushButton.d.ts +3 -0
  92. package/build/Components/DeviceType/icons/PushButton.js +9 -0
  93. package/build/Components/DeviceType/icons/PushButton.js.map +1 -0
  94. package/build/Components/DeviceType/icons/RGB.d.ts +3 -0
  95. package/build/Components/DeviceType/icons/RGB.js +43 -0
  96. package/build/Components/DeviceType/icons/RGB.js.map +1 -0
  97. package/build/Components/DeviceType/icons/RepairExpert.d.ts +3 -0
  98. package/build/Components/DeviceType/icons/RepairExpert.js +6 -0
  99. package/build/Components/DeviceType/icons/RepairExpert.js.map +1 -0
  100. package/build/Components/DeviceType/icons/Socket.d.ts +3 -0
  101. package/build/Components/DeviceType/icons/Socket.js +8 -0
  102. package/build/Components/DeviceType/icons/Socket.js.map +1 -0
  103. package/build/Components/DeviceType/icons/Thermometer.d.ts +3 -0
  104. package/build/Components/DeviceType/icons/Thermometer.js +7 -0
  105. package/build/Components/DeviceType/icons/Thermometer.js.map +1 -0
  106. package/build/Components/DeviceType/icons/ThermometerSimple.d.ts +3 -0
  107. package/build/Components/DeviceType/icons/ThermometerSimple.js +8 -0
  108. package/build/Components/DeviceType/icons/ThermometerSimple.js.map +1 -0
  109. package/build/Components/DeviceType/icons/Thermostat.d.ts +3 -0
  110. package/build/Components/DeviceType/icons/Thermostat.js +9 -0
  111. package/build/Components/DeviceType/icons/Thermostat.js.map +1 -0
  112. package/build/Components/DeviceType/icons/Valve.d.ts +3 -0
  113. package/build/Components/DeviceType/icons/Valve.js +7 -0
  114. package/build/Components/DeviceType/icons/Valve.js.map +1 -0
  115. package/build/Components/DeviceType/icons/WindowClosed.d.ts +3 -0
  116. package/build/Components/DeviceType/icons/WindowClosed.js +8 -0
  117. package/build/Components/DeviceType/icons/WindowClosed.js.map +1 -0
  118. package/build/Components/DeviceType/icons/WindowOpened.d.ts +3 -0
  119. package/build/Components/DeviceType/icons/WindowOpened.js +9 -0
  120. package/build/Components/DeviceType/icons/WindowOpened.js.map +1 -0
  121. package/build/Components/DeviceType/icons/WindowTilted.d.ts +3 -0
  122. package/build/Components/DeviceType/icons/WindowTilted.js +8 -0
  123. package/build/Components/DeviceType/icons/WindowTilted.js.map +1 -0
  124. package/build/Components/DeviceType/icons/index.d.ts +28 -0
  125. package/build/Components/DeviceType/icons/index.js +28 -0
  126. package/build/Components/DeviceType/icons/index.js.map +1 -0
  127. package/build/Components/FileBrowser.d.ts +187 -0
  128. package/build/Components/FileBrowser.js +1711 -0
  129. package/build/Components/FileBrowser.js.map +1 -0
  130. package/build/Components/FileViewer.d.ts +49 -0
  131. package/build/Components/FileViewer.js +247 -0
  132. package/build/Components/FileViewer.js.map +1 -0
  133. package/build/Components/Icon.d.ts +35 -0
  134. package/build/Components/Icon.js +140 -0
  135. package/build/Components/Icon.js.map +1 -0
  136. package/build/Components/IconPicker.d.ts +25 -0
  137. package/build/Components/IconPicker.js +72 -0
  138. package/build/Components/IconPicker.js.map +1 -0
  139. package/build/Components/IconSelector.d.ts +33 -0
  140. package/build/Components/IconSelector.js +2086 -0
  141. package/build/Components/IconSelector.js.map +1 -0
  142. package/build/Components/Image.d.ts +31 -0
  143. package/build/Components/Image.js +126 -0
  144. package/build/Components/Image.js.map +1 -0
  145. package/build/Components/InfoBox.d.ts +37 -0
  146. package/build/Components/InfoBox.js +115 -0
  147. package/build/Components/InfoBox.js.map +1 -0
  148. package/build/Components/IobUri.d.ts +14 -0
  149. package/build/Components/IobUri.js +168 -0
  150. package/build/Components/IobUri.js.map +1 -0
  151. package/build/Components/Loader.d.ts +31 -0
  152. package/build/Components/Loader.js +265 -0
  153. package/build/Components/Loader.js.map +1 -0
  154. package/build/Components/Loaders/MV.d.ts +17 -0
  155. package/build/Components/Loaders/MV.js +61 -0
  156. package/build/Components/Loaders/MV.js.map +1 -0
  157. package/build/Components/Loaders/PT.d.ts +27 -0
  158. package/build/Components/Loaders/PT.js +150 -0
  159. package/build/Components/Loaders/PT.js.map +1 -0
  160. package/build/Components/Loaders/Vendor.d.ts +22 -0
  161. package/build/Components/Loaders/Vendor.js +52 -0
  162. package/build/Components/Loaders/Vendor.js.map +1 -0
  163. package/build/Components/Logo.d.ts +18 -0
  164. package/build/Components/Logo.js +109 -0
  165. package/build/Components/Logo.js.map +1 -0
  166. package/build/Components/MDUtils.d.ts +11 -0
  167. package/build/Components/MDUtils.js +99 -0
  168. package/build/Components/MDUtils.js.map +1 -0
  169. package/build/Components/ObjectBrowser.d.ts +665 -0
  170. package/build/Components/ObjectBrowser.js +6245 -0
  171. package/build/Components/ObjectBrowser.js.map +1 -0
  172. package/build/Components/Router.d.ts +21 -0
  173. package/build/Components/Router.js +77 -0
  174. package/build/Components/Router.js.map +1 -0
  175. package/build/Components/SaveCloseButtons.d.ts +20 -0
  176. package/build/Components/SaveCloseButtons.js +65 -0
  177. package/build/Components/SaveCloseButtons.js.map +1 -0
  178. package/build/Components/Schedule.d.ts +62 -0
  179. package/build/Components/Schedule.js +1266 -0
  180. package/build/Components/Schedule.js.map +1 -0
  181. package/build/Components/SelectWithIcon.d.ts +37 -0
  182. package/build/Components/SelectWithIcon.js +139 -0
  183. package/build/Components/SelectWithIcon.js.map +1 -0
  184. package/build/Components/SimpleCron/cronText.d.ts +10 -0
  185. package/build/Components/SimpleCron/cronText.js +14 -0
  186. package/build/Components/SimpleCron/cronText.js.map +1 -0
  187. package/build/Components/SimpleCron/index.d.ts +55 -0
  188. package/build/Components/SimpleCron/index.js +698 -0
  189. package/build/Components/SimpleCron/index.js.map +1 -0
  190. package/build/Components/TabContainer.d.ts +15 -0
  191. package/build/Components/TabContainer.js +23 -0
  192. package/build/Components/TabContainer.js.map +1 -0
  193. package/build/Components/TabContent.d.ts +11 -0
  194. package/build/Components/TabContent.js +20 -0
  195. package/build/Components/TabContent.js.map +1 -0
  196. package/build/Components/TabHeader.d.ts +6 -0
  197. package/build/Components/TabHeader.js +6 -0
  198. package/build/Components/TabHeader.js.map +1 -0
  199. package/build/Components/TableResize.d.ts +45 -0
  200. package/build/Components/TableResize.js +204 -0
  201. package/build/Components/TableResize.js.map +1 -0
  202. package/build/Components/TextWithIcon.d.ts +21 -0
  203. package/build/Components/TextWithIcon.js +113 -0
  204. package/build/Components/TextWithIcon.js.map +1 -0
  205. package/build/Components/ToggleThemeMenu.d.ts +12 -0
  206. package/build/Components/ToggleThemeMenu.js +13 -0
  207. package/build/Components/ToggleThemeMenu.js.map +1 -0
  208. package/build/Components/TreeTable.d.ts +79 -0
  209. package/build/Components/TreeTable.js +538 -0
  210. package/build/Components/TreeTable.js.map +1 -0
  211. package/build/Components/UploadImage.d.ts +23 -0
  212. package/build/Components/UploadImage.js +516 -0
  213. package/build/Components/UploadImage.js.map +1 -0
  214. package/build/Components/Utils.d.ts +331 -0
  215. package/build/Components/Utils.js +1605 -0
  216. package/build/Components/Utils.js.map +1 -0
  217. package/build/Components/withWidth.d.ts +2 -0
  218. package/build/Components/withWidth.js +22 -0
  219. package/build/Components/withWidth.js.map +1 -0
  220. package/build/Connection.d.ts +1 -0
  221. package/build/Connection.js +2 -0
  222. package/build/Connection.js.map +1 -0
  223. package/build/Dialogs/ComplexCron.d.ts +24 -0
  224. package/build/Dialogs/ComplexCron.js +85 -0
  225. package/build/Dialogs/ComplexCron.js.map +1 -0
  226. package/build/Dialogs/Confirm.d.ts +39 -0
  227. package/build/Dialogs/Confirm.js +83 -0
  228. package/build/Dialogs/Confirm.js.map +1 -0
  229. package/build/Dialogs/Cron.d.ts +29 -0
  230. package/build/Dialogs/Cron.js +72 -0
  231. package/build/Dialogs/Cron.js.map +1 -0
  232. package/build/Dialogs/Error.d.ts +18 -0
  233. package/build/Dialogs/Error.js +27 -0
  234. package/build/Dialogs/Error.js.map +1 -0
  235. package/build/Dialogs/Message.d.ts +20 -0
  236. package/build/Dialogs/Message.js +29 -0
  237. package/build/Dialogs/Message.js.map +1 -0
  238. package/build/Dialogs/SelectFile.d.ts +85 -0
  239. package/build/Dialogs/SelectFile.js +115 -0
  240. package/build/Dialogs/SelectFile.js.map +1 -0
  241. package/build/Dialogs/SelectID.d.ts +102 -0
  242. package/build/Dialogs/SelectID.js +151 -0
  243. package/build/Dialogs/SelectID.js.map +1 -0
  244. package/build/Dialogs/SimpleCron.d.ts +19 -0
  245. package/build/Dialogs/SimpleCron.js +46 -0
  246. package/build/Dialogs/SimpleCron.js.map +1 -0
  247. package/build/Dialogs/TextInput.d.ts +2 -0
  248. package/build/Dialogs/TextInput.js +31 -0
  249. package/build/Dialogs/TextInput.js.map +1 -0
  250. package/build/GenericApp.d.ts +209 -0
  251. package/build/GenericApp.js +842 -0
  252. package/build/GenericApp.js.map +1 -0
  253. package/build/LegacyConnection.d.ts +938 -0
  254. package/build/LegacyConnection.js +2849 -0
  255. package/build/LegacyConnection.js.map +1 -0
  256. package/build/Prompt.d.ts +5 -0
  257. package/build/Prompt.js +19 -0
  258. package/build/Prompt.js.map +1 -0
  259. package/build/Theme.d.ts +5 -0
  260. package/build/Theme.js +344 -0
  261. package/build/Theme.js.map +1 -0
  262. package/build/assets/devices/parseNames.d.ts +0 -0
  263. package/build/assets/devices/parseNames.js +35 -0
  264. package/build/assets/devices/parseNames.js.map +1 -0
  265. package/build/assets/devices.json +1 -0
  266. package/build/assets/lamp_ceiling.svg +9 -0
  267. package/build/assets/lamp_table.svg +8 -0
  268. package/build/assets/no_icon.svg +9 -0
  269. package/build/assets/rooms/parseNames.d.ts +0 -0
  270. package/build/assets/rooms/parseNames.js +35 -0
  271. package/build/assets/rooms/parseNames.js.map +1 -0
  272. package/build/assets/rooms.json +1 -0
  273. package/build/dictionary.d.ts +1 -0
  274. package/build/dictionary.js +25 -0
  275. package/build/dictionary.js.map +1 -0
  276. package/build/globals.d.ts +19 -0
  277. package/build/i18n/de.json +480 -0
  278. package/build/i18n/en.json +480 -0
  279. package/build/i18n/es.json +480 -0
  280. package/build/i18n/fr.json +480 -0
  281. package/build/i18n/it.json +475 -0
  282. package/build/i18n/nl.json +475 -0
  283. package/build/i18n/pl.json +475 -0
  284. package/build/i18n/pt.json +475 -0
  285. package/build/i18n/ru.json +475 -0
  286. package/build/i18n/uk.json +475 -0
  287. package/build/i18n/zh-cn.json +475 -0
  288. package/build/i18n.d.ts +84 -0
  289. package/build/i18n.js +224 -0
  290. package/build/i18n.js.map +1 -0
  291. package/build/icons/IconAdapter.d.ts +3 -0
  292. package/build/icons/IconAdapter.js +7 -0
  293. package/build/icons/IconAdapter.js.map +1 -0
  294. package/build/icons/IconAlias.d.ts +3 -0
  295. package/build/icons/IconAlias.js +7 -0
  296. package/build/icons/IconAlias.js.map +1 -0
  297. package/build/icons/IconButtonImage.d.ts +3 -0
  298. package/build/icons/IconButtonImage.js +9 -0
  299. package/build/icons/IconButtonImage.js.map +1 -0
  300. package/build/icons/IconChannel.d.ts +3 -0
  301. package/build/icons/IconChannel.js +10 -0
  302. package/build/icons/IconChannel.js.map +1 -0
  303. package/build/icons/IconClearFilter.d.ts +3 -0
  304. package/build/icons/IconClearFilter.js +8 -0
  305. package/build/icons/IconClearFilter.js.map +1 -0
  306. package/build/icons/IconClosed.d.ts +3 -0
  307. package/build/icons/IconClosed.js +7 -0
  308. package/build/icons/IconClosed.js.map +1 -0
  309. package/build/icons/IconCopy.d.ts +3 -0
  310. package/build/icons/IconCopy.js +6 -0
  311. package/build/icons/IconCopy.js.map +1 -0
  312. package/build/icons/IconDevice.d.ts +3 -0
  313. package/build/icons/IconDevice.js +16 -0
  314. package/build/icons/IconDevice.js.map +1 -0
  315. package/build/icons/IconDocument.d.ts +3 -0
  316. package/build/icons/IconDocument.js +7 -0
  317. package/build/icons/IconDocument.js.map +1 -0
  318. package/build/icons/IconDocumentReadOnly.d.ts +3 -0
  319. package/build/icons/IconDocumentReadOnly.js +8 -0
  320. package/build/icons/IconDocumentReadOnly.js.map +1 -0
  321. package/build/icons/IconExpert.d.ts +3 -0
  322. package/build/icons/IconExpert.js +7 -0
  323. package/build/icons/IconExpert.js.map +1 -0
  324. package/build/icons/IconFx.d.ts +3 -0
  325. package/build/icons/IconFx.js +6 -0
  326. package/build/icons/IconFx.js.map +1 -0
  327. package/build/icons/IconInstance.d.ts +3 -0
  328. package/build/icons/IconInstance.js +7 -0
  329. package/build/icons/IconInstance.js.map +1 -0
  330. package/build/icons/IconLogout.d.ts +3 -0
  331. package/build/icons/IconLogout.js +7 -0
  332. package/build/icons/IconLogout.js.map +1 -0
  333. package/build/icons/IconNoIcon.d.ts +3 -0
  334. package/build/icons/IconNoIcon.js +6 -0
  335. package/build/icons/IconNoIcon.js.map +1 -0
  336. package/build/icons/IconOpen.d.ts +3 -0
  337. package/build/icons/IconOpen.js +7 -0
  338. package/build/icons/IconOpen.js.map +1 -0
  339. package/build/icons/IconState.d.ts +3 -0
  340. package/build/icons/IconState.js +7 -0
  341. package/build/icons/IconState.js.map +1 -0
  342. package/build/icons/IconVacuum.d.ts +3 -0
  343. package/build/icons/IconVacuum.js +12 -0
  344. package/build/icons/IconVacuum.js.map +1 -0
  345. package/build/index.css +56 -0
  346. package/build/index.d.ts +87 -0
  347. package/build/index.js +85 -0
  348. package/build/index.js.map +1 -0
  349. package/build/modulefederation.admin.config.d.ts +13 -0
  350. package/build/modulefederation.admin.config.js +45 -0
  351. package/build/modulefederation.admin.config.js.map +1 -0
  352. package/build/types.d.ts +236 -0
  353. package/i18n/de.json +480 -0
  354. package/i18n/en.json +480 -0
  355. package/i18n/es.json +480 -0
  356. package/i18n/fr.json +480 -0
  357. package/i18n/it.json +475 -0
  358. package/i18n/nl.json +475 -0
  359. package/i18n/pl.json +475 -0
  360. package/i18n/pt.json +475 -0
  361. package/i18n/ru.json +475 -0
  362. package/i18n/uk.json +475 -0
  363. package/i18n/zh-cn.json +475 -0
  364. package/index.css +56 -0
  365. package/modulefederation.admin.config.d.ts +20 -0
  366. package/modulefederation.admin.config.js +54 -0
  367. package/package.json +86 -0
  368. package/tasksExample.js +91 -0
@@ -0,0 +1,1605 @@
1
+ /**
2
+ * Copyright 2018-2024 Denis Haev <dogafox@gmail.com>
3
+ *
4
+ * MIT License
5
+ *
6
+ */
7
+ import React from 'react';
8
+ import { copy } from './CopyToClipboard';
9
+ import { I18n } from '../i18n';
10
+ const NAMESPACE = 'material';
11
+ const days = ['Su', 'Mo', 'Tu', 'We', 'Th', 'Fr', 'Sa'];
12
+ const months = ['Jan', 'Feb', 'Mar', 'Apr', 'Mai', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
13
+ const QUALITY_BITS = {
14
+ 0x00: '0x00 - good',
15
+ 0x01: '0x01 - general problem',
16
+ 0x02: '0x02 - no connection problem',
17
+ 0x10: '0x10 - substitute value from controller',
18
+ 0x20: '0x20 - substitute initial value',
19
+ 0x40: '0x40 - substitute value from device or instance',
20
+ 0x80: '0x80 - substitute value from sensor',
21
+ 0x11: '0x11 - general problem by instance',
22
+ 0x41: '0x41 - general problem by device',
23
+ 0x81: '0x81 - general problem by sensor',
24
+ 0x12: '0x12 - instance not connected',
25
+ 0x42: '0x42 - device not connected',
26
+ 0x82: '0x82 - sensor not connected',
27
+ 0x44: '0x44 - device reports error',
28
+ 0x84: '0x84 - sensor reports error',
29
+ };
30
+ const SIGNATURES = {
31
+ JVBERi0: 'pdf',
32
+ R0lGODdh: 'gif',
33
+ R0lGODlh: 'gif',
34
+ iVBORw0KGgo: 'png',
35
+ '/9j/': 'jpg',
36
+ PHN2Zw: 'svg',
37
+ Qk1: 'bmp',
38
+ AAABAA: 'ico', // 00 00 01 00 according to https://en.wikipedia.org/wiki/List_of_file_signatures
39
+ };
40
+ export class Utils {
41
+ static namespace = NAMESPACE;
42
+ static INSTANCES = 'instances';
43
+ static dateFormat = ['DD', 'MM'];
44
+ static FORBIDDEN_CHARS = /[^._\-/ :!#$%&()+=@^{}|~\p{Ll}\p{Lu}\p{Nd}]+/gu;
45
+ /**
46
+ * Capitalize words.
47
+ */
48
+ static CapitalWords(name) {
49
+ return (name || '')
50
+ .split(/[\s_]/)
51
+ .filter(item => item)
52
+ .map(word => (word ? word[0].toUpperCase() + word.substring(1).toLowerCase() : ''))
53
+ .join(' ');
54
+ }
55
+ static formatSeconds(seconds) {
56
+ const days_ = Math.floor(seconds / (3600 * 24));
57
+ seconds %= 3600 * 24;
58
+ const hours = Math.floor(seconds / 3600)
59
+ .toString()
60
+ .padStart(2, '0');
61
+ seconds %= 3600;
62
+ const minutes = Math.floor(seconds / 60)
63
+ .toString()
64
+ .padStart(2, '0');
65
+ seconds %= 60;
66
+ const secondsStr = Math.floor(seconds).toString().padStart(2, '0');
67
+ let text = '';
68
+ if (days_) {
69
+ text += `${days_} ${I18n.t('ra_daysShortText')} `;
70
+ }
71
+ text += `${hours}:${minutes}:${secondsStr}`;
72
+ return text;
73
+ }
74
+ /**
75
+ * Get the name of the object by id from the name or description.
76
+ */
77
+ static getObjectName(objects, id, settings, options,
78
+ /** Set to true to get the description. */
79
+ isDesc) {
80
+ const item = objects[id];
81
+ let text;
82
+ if (typeof settings === 'string' && !options) {
83
+ options = { language: settings };
84
+ settings = null;
85
+ }
86
+ options = options || {};
87
+ if (!options.language) {
88
+ options.language =
89
+ (objects['system.config'] &&
90
+ objects['system.config'].common &&
91
+ objects['system.config'].common.language) ||
92
+ window.sysLang ||
93
+ 'en';
94
+ }
95
+ if (settings?.name) {
96
+ const textObj = settings.name;
97
+ if (typeof textObj === 'object') {
98
+ text = (options.language && textObj[options.language]) || textObj.en;
99
+ }
100
+ else {
101
+ text = textObj;
102
+ }
103
+ }
104
+ else if (isDesc && item?.common?.desc) {
105
+ const textObj = item.common.desc;
106
+ if (typeof textObj === 'object') {
107
+ text = (options.language && textObj[options.language]) || textObj.en || textObj.de || textObj.ru || '';
108
+ }
109
+ else {
110
+ text = textObj;
111
+ }
112
+ text = (text || '').toString().replace(/[_.]/g, ' ');
113
+ if (text === text.toUpperCase()) {
114
+ text = text[0] + text.substring(1).toLowerCase();
115
+ }
116
+ }
117
+ else if (!isDesc && item?.common) {
118
+ const textObj = item.common.name || item.common.desc;
119
+ if (textObj && typeof textObj === 'object') {
120
+ text = (options.language && textObj[options.language]) || textObj.en || textObj.de || textObj.ru || '';
121
+ }
122
+ else {
123
+ text = textObj;
124
+ }
125
+ text = (text || '').toString().replace(/[_.]/g, ' ');
126
+ if (text === text.toUpperCase()) {
127
+ text = text[0] + text.substring(1).toLowerCase();
128
+ }
129
+ }
130
+ else {
131
+ const pos = id.lastIndexOf('.');
132
+ text = id.substring(pos + 1).replace(/[_.]/g, ' ');
133
+ text = Utils.CapitalWords(text);
134
+ }
135
+ return text?.trim() || '';
136
+ }
137
+ /**
138
+ * Get the name of the object from the name or description.
139
+ */
140
+ static getObjectNameFromObj(obj,
141
+ /** settings or language */
142
+ settings, options,
143
+ /** Set to true to get the description. */
144
+ isDesc,
145
+ /** Allow using spaces in name (by edit) */
146
+ noTrim) {
147
+ const item = obj;
148
+ let text = obj?._id || '';
149
+ if (typeof settings === 'string' && !options) {
150
+ options = { language: settings };
151
+ settings = null;
152
+ }
153
+ options = options || {};
154
+ if (settings?.name) {
155
+ const name = settings.name;
156
+ if (typeof name === 'object') {
157
+ text = (options.language && name[options.language]) || name.en;
158
+ }
159
+ else {
160
+ text = name;
161
+ }
162
+ }
163
+ else if (isDesc && item?.common?.desc) {
164
+ const desc = item.common.desc;
165
+ if (typeof desc === 'object') {
166
+ text = (options.language && desc[options.language]) || desc.en;
167
+ }
168
+ else {
169
+ text = desc;
170
+ }
171
+ text = (text || '').toString().replace(/[_.]/g, ' ');
172
+ if (text === text.toUpperCase()) {
173
+ text = text[0] + text.substring(1).toLowerCase();
174
+ }
175
+ }
176
+ else if (!isDesc && item?.common?.name) {
177
+ let name = item.common.name;
178
+ if (!name && item.common.desc) {
179
+ name = item.common.desc;
180
+ }
181
+ if (typeof name === 'object') {
182
+ text = (options.language && name[options.language]) || name.en;
183
+ }
184
+ else {
185
+ text = name;
186
+ }
187
+ text = (text || '').toString().replace(/[_.]/g, ' ');
188
+ if (text === text.toUpperCase()) {
189
+ text = text[0] + text.substring(1).toLowerCase();
190
+ }
191
+ }
192
+ return noTrim ? text : text.trim();
193
+ }
194
+ /**
195
+ * Extracts from the object material settings, depends on username
196
+ */
197
+ static getSettingsOrder(obj, forEnumId, options) {
198
+ let common;
199
+ if (obj && Object.prototype.hasOwnProperty.call(obj, 'common')) {
200
+ common = obj.common;
201
+ }
202
+ else {
203
+ common = obj;
204
+ }
205
+ let settings;
206
+ if (common?.custom) {
207
+ settings = common.custom[NAMESPACE];
208
+ const user = options.user || 'admin';
209
+ if (settings && settings[user]) {
210
+ if (forEnumId) {
211
+ if (settings[user].subOrder && settings[user].subOrder[forEnumId]) {
212
+ return JSON.parse(JSON.stringify(settings[user].subOrder[forEnumId]));
213
+ }
214
+ }
215
+ else if (settings[user].order) {
216
+ return JSON.parse(JSON.stringify(settings[user].order));
217
+ }
218
+ }
219
+ }
220
+ return null;
221
+ }
222
+ /**
223
+ Used in material
224
+ */
225
+ static getSettingsCustomURLs(obj, forEnumId, options) {
226
+ let common;
227
+ if (obj && Object.prototype.hasOwnProperty.call(obj, 'common')) {
228
+ common = obj.common;
229
+ }
230
+ else {
231
+ common = obj;
232
+ }
233
+ let settings;
234
+ if (common?.custom) {
235
+ settings = common.custom[NAMESPACE];
236
+ const user = options.user || 'admin';
237
+ if (settings && settings[user]) {
238
+ if (forEnumId) {
239
+ if (settings[user].subURLs && settings[user].subURLs[forEnumId]) {
240
+ return JSON.parse(JSON.stringify(settings[user].subURLs[forEnumId]));
241
+ }
242
+ }
243
+ else if (settings[user].URLs) {
244
+ return JSON.parse(JSON.stringify(settings[user].URLs));
245
+ }
246
+ }
247
+ }
248
+ return null;
249
+ }
250
+ /**
251
+ * Reorder the array items in list between source and dest.
252
+ */
253
+ static reorder(list, source, dest) {
254
+ const result = Array.from(list);
255
+ const [removed] = result.splice(source, 1);
256
+ result.splice(dest, 0, removed);
257
+ return result;
258
+ }
259
+ /**
260
+ Get smart name settings for the given object.
261
+ */
262
+ static getSettings(obj, options, defaultEnabling) {
263
+ let settings;
264
+ const id = obj?._id || options?.id;
265
+ let common;
266
+ if (obj && Object.prototype.hasOwnProperty.call(obj, 'common')) {
267
+ common = obj.common;
268
+ }
269
+ else {
270
+ common = obj;
271
+ }
272
+ if (common?.custom) {
273
+ settings = common.custom;
274
+ settings =
275
+ settings[NAMESPACE] && settings[NAMESPACE][options.user || 'admin']
276
+ ? JSON.parse(JSON.stringify(settings[NAMESPACE][options.user || 'admin']))
277
+ : { enabled: true };
278
+ }
279
+ else {
280
+ settings = { enabled: defaultEnabling === undefined ? true : defaultEnabling, useCustom: false };
281
+ }
282
+ if (!Object.prototype.hasOwnProperty.call(settings, 'enabled')) {
283
+ settings.enabled = defaultEnabling === undefined ? true : defaultEnabling;
284
+ }
285
+ if (options) {
286
+ if (!settings.name && options.name) {
287
+ settings.name = options.name;
288
+ }
289
+ if (!settings.icon && options.icon) {
290
+ settings.icon = options.icon;
291
+ }
292
+ if (!settings.color && options.color) {
293
+ settings.color = options.color;
294
+ }
295
+ }
296
+ if (common) {
297
+ if (!settings.color && common.color) {
298
+ settings.color = common.color;
299
+ }
300
+ if (!settings.icon && common.icon) {
301
+ settings.icon = common.icon;
302
+ }
303
+ if (!settings.name && common.name) {
304
+ settings.name = common.name;
305
+ }
306
+ }
307
+ if (typeof settings.name === 'object') {
308
+ settings.name = (options.language && settings.name[options.language]) || settings.name.en;
309
+ settings.name = (settings.name || '').toString().replace(/_/g, ' ');
310
+ if (settings.name === settings.name.toUpperCase()) {
311
+ settings.name = settings.name[0] + settings.name.substring(1).toLowerCase();
312
+ }
313
+ }
314
+ if (!settings.name && id) {
315
+ const pos = id.lastIndexOf('.');
316
+ settings.name = id.substring(pos + 1).replace(/[_.]/g, ' ');
317
+ settings.name = (settings.name || '').toString().replace(/_/g, ' ');
318
+ settings.name = Utils.CapitalWords(settings.name);
319
+ }
320
+ return settings;
321
+ }
322
+ /**
323
+ Sets smartName settings for the given object.
324
+ */
325
+ static setSettings(obj, settings, options) {
326
+ if (obj) {
327
+ obj.common = obj.common || {};
328
+ obj.common.custom = obj.common.custom || {};
329
+ obj.common.custom[NAMESPACE] = obj.common.custom[NAMESPACE] || {};
330
+ obj.common.custom[NAMESPACE][options.user || 'admin'] = settings;
331
+ const s = obj.common.custom[NAMESPACE][options.user || 'admin'];
332
+ if (s.useCommon) {
333
+ if (s.color !== undefined) {
334
+ obj.common.color = s.color;
335
+ delete s.color;
336
+ }
337
+ if (s.icon !== undefined) {
338
+ obj.common.icon = s.icon;
339
+ delete s.icon;
340
+ }
341
+ if (s.name !== undefined) {
342
+ if (typeof obj.common.name !== 'object' && options.language) {
343
+ obj.common.name = { [options.language]: s.name };
344
+ }
345
+ else if (typeof obj.common.name === 'object' && options.language) {
346
+ obj.common.name[options.language] = s.name;
347
+ }
348
+ delete s.name;
349
+ }
350
+ }
351
+ return true;
352
+ }
353
+ return false;
354
+ }
355
+ /**
356
+ * Get the icon for the given settings.
357
+ */
358
+ static getIcon(settings, style) {
359
+ if (settings?.icon) {
360
+ // If UTF-8 icon
361
+ if (settings.icon.length <= 2) {
362
+ return React.createElement("span", { style: style || {} }, settings.icon);
363
+ }
364
+ if (settings.icon.startsWith('data:image')) {
365
+ return (React.createElement("img", { alt: settings.name, src: settings.icon, style: style || {} }));
366
+ }
367
+ // maybe later some changes for a second type
368
+ return (React.createElement("img", { alt: settings.name, src: (settings.prefix || '') + settings.icon, style: style }));
369
+ }
370
+ return null;
371
+ }
372
+ /**
373
+ * Get the icon for the given object.
374
+ */
375
+ static getObjectIcon(id, obj) {
376
+ // If id is Object
377
+ if (typeof id === 'object') {
378
+ obj = id;
379
+ id = obj?._id;
380
+ }
381
+ if (obj?.common?.icon) {
382
+ let icon = obj.common.icon;
383
+ // If UTF-8 icon
384
+ if (typeof icon === 'string' && icon.length <= 2) {
385
+ return icon;
386
+ }
387
+ if (icon.startsWith('data:image')) {
388
+ return icon;
389
+ }
390
+ const parts = id.split('.');
391
+ if (parts[0] === 'system') {
392
+ icon = `adapter/${parts[2]}${icon.startsWith('/') ? '' : '/'}${icon}`;
393
+ }
394
+ else {
395
+ icon = `adapter/${parts[0]}${icon.startsWith('/') ? '' : '/'}${icon}`;
396
+ }
397
+ if (window.location.pathname.match(/adapter\/[^/]+\/[^/]+\.html/)) {
398
+ icon = `../../${icon}`;
399
+ }
400
+ else if (window.location.pathname.match(/material\/[.\d]+/)) {
401
+ icon = `../../${icon}`;
402
+ }
403
+ else if (window.location.pathname.match(/material\//)) {
404
+ icon = `../${icon}`;
405
+ }
406
+ return icon;
407
+ }
408
+ return null;
409
+ }
410
+ /**
411
+ * Converts word1_word2 to word1Word2.
412
+ */
413
+ static splitCamelCase(text) {
414
+ // if (false && text !== text.toUpperCase()) {
415
+ // const words = text.split(/\s+/);
416
+ // for (let i = 0; i < words.length; i++) {
417
+ // const word = words[i];
418
+ // if (word.toLowerCase() !== word && word.toUpperCase() !== word) {
419
+ // let z = 0;
420
+ // const ww = [];
421
+ // let start = 0;
422
+ // while (z < word.length) {
423
+ // if (word[z].match(/[A-ZÜÄÖА-Я]/)) {
424
+ // ww.push(word.substring(start, z));
425
+ // start = z;
426
+ // }
427
+ // z++;
428
+ // }
429
+ // if (start !== z) {
430
+ // ww.push(word.substring(start, z));
431
+ // }
432
+ // for (let k = 0; k < ww.length; k++) {
433
+ // words.splice(i + k, 0, ww[k]);
434
+ // }
435
+ // i += ww.length;
436
+ // }
437
+ // }
438
+ //
439
+ // return words.map(w => {
440
+ // w = w.trim();
441
+ // if (w) {
442
+ // return w[0].toUpperCase() + w.substring(1).toLowerCase();
443
+ // }
444
+ // return '';
445
+ // }).join(' ');
446
+ // }
447
+ return text ? Utils.CapitalWords(text) : '';
448
+ }
449
+ /**
450
+ * Check if the given color is bright.
451
+ * https://stackoverflow.com/questions/35969656/how-can-i-generate-the-opposite-color-according-to-current-color
452
+ */
453
+ static isUseBright(color, defaultValue) {
454
+ if (!color) {
455
+ return defaultValue === undefined ? true : defaultValue;
456
+ }
457
+ color = color.toString();
458
+ if (color.startsWith('#')) {
459
+ color = color.slice(1);
460
+ }
461
+ let r;
462
+ let g;
463
+ let b;
464
+ const rgb = color.match(/^rgba?[\s+]?\([\s+]?(\d+)[\s+]?,[\s+]?(\d+)[\s+]?,[\s+]?(\d+)[\s+]?/i);
465
+ if (rgb && rgb.length === 4) {
466
+ r = parseInt(rgb[1], 10);
467
+ g = parseInt(rgb[2], 10);
468
+ b = parseInt(rgb[3], 10);
469
+ }
470
+ else {
471
+ // convert 3-digit hex to 6-digits.
472
+ if (color.length === 3) {
473
+ color = color[0] + color[0] + color[1] + color[1] + color[2] + color[2];
474
+ }
475
+ // remove alfa channel
476
+ if (color.length === 8) {
477
+ color = color.substring(0, 6);
478
+ }
479
+ else if (color.length !== 6) {
480
+ return false;
481
+ }
482
+ r = parseInt(color.slice(0, 2), 16);
483
+ g = parseInt(color.slice(2, 4), 16);
484
+ b = parseInt(color.slice(4, 6), 16);
485
+ }
486
+ // http://stackoverflow.com/a/3943023/112731
487
+ return r * 0.299 + g * 0.587 + b * 0.114 <= 186;
488
+ }
489
+ /**
490
+ * Get the time string in the format 00:00.
491
+ */
492
+ static getTimeString(seconds) {
493
+ seconds = parseFloat(seconds);
494
+ if (Number.isNaN(seconds)) {
495
+ return '--:--';
496
+ }
497
+ const hours = Math.floor(seconds / 3600);
498
+ const minutes = Math.floor((seconds % 3600) / 60)
499
+ .toString()
500
+ .padStart(2, '0');
501
+ const secs = (seconds % 60).toString().padStart(2, '0');
502
+ if (hours) {
503
+ return `${hours}:${minutes}:${secs}`;
504
+ }
505
+ return `${minutes}:${secs}`;
506
+ }
507
+ /**
508
+ * Gets the wind direction with the given angle (degrees).
509
+ */
510
+ static getWindDirection(
511
+ /** angle in degrees from 0° to 360° */
512
+ angle) {
513
+ if (angle >= 0 && angle < 11.25) {
514
+ return 'N';
515
+ }
516
+ if (angle >= 11.25 && angle < 33.75) {
517
+ return 'NNE';
518
+ }
519
+ if (angle >= 33.75 && angle < 56.25) {
520
+ return 'NE';
521
+ }
522
+ if (angle >= 56.25 && angle < 78.75) {
523
+ return 'ENE';
524
+ }
525
+ if (angle >= 78.75 && angle < 101.25) {
526
+ return 'E';
527
+ }
528
+ if (angle >= 101.25 && angle < 123.75) {
529
+ return 'ESE';
530
+ }
531
+ if (angle >= 123.75 && angle < 146.25) {
532
+ return 'SE';
533
+ }
534
+ if (angle >= 146.25 && angle < 168.75) {
535
+ return 'SSE';
536
+ }
537
+ if (angle >= 168.75 && angle < 191.25) {
538
+ return 'S';
539
+ }
540
+ if (angle >= 191.25 && angle < 213.75) {
541
+ return 'SSW';
542
+ }
543
+ if (angle >= 213.75 && angle < 236.25) {
544
+ return 'SW';
545
+ }
546
+ if (angle >= 236.25 && angle < 258.75) {
547
+ return 'WSW';
548
+ }
549
+ if (angle >= 258.75 && angle < 281.25) {
550
+ return 'W';
551
+ }
552
+ if (angle >= 281.25 && angle < 303.75) {
553
+ return 'WNW';
554
+ }
555
+ if (angle >= 303.75 && angle < 326.25) {
556
+ return 'NW';
557
+ }
558
+ if (angle >= 326.25 && angle < 348.75) {
559
+ return 'NNW';
560
+ }
561
+ // if (angle >= 348.75) {
562
+ return 'N';
563
+ }
564
+ /**
565
+ * Pad the given number with a zero if it's not two digits long.
566
+ */
567
+ static padding(num) {
568
+ if (typeof num === 'string') {
569
+ if (num.length < 2) {
570
+ return `0${num}`;
571
+ }
572
+ return num;
573
+ }
574
+ if (num < 10) {
575
+ return `0${num}`;
576
+ }
577
+ return num.toString();
578
+ }
579
+ /**
580
+ * Sets the date format.
581
+ */
582
+ static setDataFormat(format) {
583
+ if (format) {
584
+ Utils.dateFormat = format.toUpperCase().split(/[.-/]/);
585
+ Utils.dateFormat.splice(Utils.dateFormat.indexOf('YYYY'), 1);
586
+ }
587
+ }
588
+ /**
589
+ * Converts the date to a string.
590
+ */
591
+ static date2string(now) {
592
+ if (typeof now === 'string') {
593
+ now = now.trim();
594
+ if (!now) {
595
+ return '';
596
+ }
597
+ // only letters
598
+ if (now.match(/^[\w\s]+$/)) {
599
+ // Day of the week
600
+ return now;
601
+ }
602
+ const m = now.match(/(\d{1,4})[-./](\d{1,2})[-./](\d{1,4})/);
603
+ if (m) {
604
+ const a = [parseInt(m[1], 10), parseInt(m[2], 10), parseInt(m[3], 10)];
605
+ // We now have 3 numbers. Let's try to detect where is year, where is day and where is month
606
+ const year = a.find(y => y > 31);
607
+ if (year !== undefined) {
608
+ a.splice(a.indexOf(year), 1);
609
+ const day = a.find(mm => mm > 12);
610
+ if (day) {
611
+ a.splice(a.indexOf(day), 1);
612
+ now = new Date(year, a[0] - 1, day);
613
+ }
614
+ else if (Utils.dateFormat[0][0] === 'M' && Utils.dateFormat[1][0] === 'D') {
615
+ // MM DD
616
+ now = new Date(year, a[0] - 1, a[1]);
617
+ if (Math.abs(now.getTime() - Date.now()) > 3600000 * 24 * 10) {
618
+ now = new Date(year, a[1] - 1, a[0]);
619
+ }
620
+ }
621
+ else if (Utils.dateFormat[0][0] === 'D' && Utils.dateFormat[1][0] === 'M') {
622
+ // DD MM
623
+ now = new Date(year, a[1] - 1, a[0]);
624
+ if (Math.abs(now.getTime() - Date.now()) > 3600000 * 24 * 10) {
625
+ now = new Date(year, a[0] - 1, a[1]);
626
+ }
627
+ }
628
+ else {
629
+ now = new Date(now);
630
+ }
631
+ }
632
+ else {
633
+ now = new Date(now);
634
+ }
635
+ }
636
+ else {
637
+ now = new Date(now);
638
+ }
639
+ }
640
+ else {
641
+ now = new Date(now);
642
+ }
643
+ let date = I18n.t(`ra_dow_${days[now.getDay()]}`).replace('ra_dow_', '');
644
+ date += `. ${now.getDate()} ${I18n.t(`ra_month_${months[now.getMonth()]}`).replace('ra_month_', '')}`;
645
+ return date;
646
+ }
647
+ /**
648
+ * Render a text as a link.
649
+ */
650
+ static renderTextWithA(text) {
651
+ let m = text.match(/<a [^<]+<\/a>|<br\s?\/?>|<b>[^<]+<\/b>|<i>[^<]+<\/i>/);
652
+ if (m) {
653
+ const result = [];
654
+ let key = 1;
655
+ do {
656
+ const start = text.substring(0, m.index);
657
+ text = text.substring((m.index || 0) + m[0].length);
658
+ start && result.push(React.createElement("span", { key: `a${key++}` }, start));
659
+ if (m[0].startsWith('<b>')) {
660
+ result.push(React.createElement("b", { key: `a${key++}` }, m[0].substring(3, m[0].length - 4)));
661
+ }
662
+ else if (m[0].startsWith('<i>')) {
663
+ result.push(React.createElement("i", { key: `a${key++}` }, m[0].substring(3, m[0].length - 4)));
664
+ }
665
+ else if (m[0].startsWith('<br')) {
666
+ result.push(React.createElement("br", { key: `a${key++}` }));
667
+ }
668
+ else {
669
+ const href = m[0].match(/href="([^"]+)"/) || m[0].match(/href='([^']+)'/);
670
+ const target = m[0].match(/target="([^"]+)"/) || m[0].match(/target='([^']+)'/);
671
+ const rel = m[0].match(/rel="([^"]+)"/) || m[0].match(/rel='([^']+)'/);
672
+ const title = m[0].match(/>([^<]*)</);
673
+ result.push(
674
+ // eslint-disable-next-line react/jsx-no-target-blank
675
+ React.createElement("a", { key: `a${key++}`, href: href ? href[1] : '', target: target ? target[1] : '_blank', rel: rel ? rel[1] : 'noreferrer', style: { color: 'inherit' } }, title ? title[1] : ''));
676
+ }
677
+ m = text ? text.match(/<a [^<]+<\/a>|<br\s?\/?>|<b>[^<]+<\/b>|<i>[^<]+<\/i>/) : null;
678
+ if (!m && text) {
679
+ // put the rest text
680
+ result.push(React.createElement("span", { key: `a${key++}` }, text));
681
+ }
682
+ } while (m);
683
+ return result;
684
+ }
685
+ return text;
686
+ }
687
+ /**
688
+ * Get the smart name of the given state.
689
+ */
690
+ static getSmartName(states, id, instanceId, noCommon) {
691
+ if (!id) {
692
+ if (!noCommon) {
693
+ if (!states.common) {
694
+ return states.smartName;
695
+ }
696
+ if (states && !states.common) {
697
+ return states.smartName;
698
+ }
699
+ return states.common.smartName;
700
+ }
701
+ if (states && !states.common) {
702
+ return states.smartName;
703
+ }
704
+ const obj = states;
705
+ return obj?.common?.custom && obj.common.custom[instanceId]
706
+ ? obj.common.custom[instanceId].smartName
707
+ : undefined;
708
+ }
709
+ if (!noCommon) {
710
+ return states[id].common.smartName;
711
+ }
712
+ const obj = states[id];
713
+ return obj?.common?.custom && obj.common.custom[instanceId]
714
+ ? obj.common.custom[instanceId].smartName || null
715
+ : null;
716
+ }
717
+ /**
718
+ * Get the smart name from a state.
719
+ */
720
+ static getSmartNameFromObj(obj, instanceId, noCommon) {
721
+ if (!noCommon) {
722
+ if (!obj.common) {
723
+ return obj.smartName;
724
+ }
725
+ if (obj && !obj.common) {
726
+ return obj.smartName;
727
+ }
728
+ return obj.common.smartName;
729
+ }
730
+ if (obj && !obj.common) {
731
+ return obj.smartName;
732
+ }
733
+ const custom = obj?.common?.custom?.[instanceId];
734
+ return custom ? custom.smartName : undefined;
735
+ }
736
+ /**
737
+ * Enable smart name for a state.
738
+ */
739
+ static enableSmartName(obj, instanceId, noCommon) {
740
+ // Typing must be fixed in js-controller
741
+ const sureStateObject = obj;
742
+ if (noCommon) {
743
+ sureStateObject.common.custom ||= {};
744
+ sureStateObject.common.custom[instanceId] ||= {};
745
+ sureStateObject.common.custom[instanceId].smartName = {};
746
+ }
747
+ else {
748
+ sureStateObject.common.smartName = {};
749
+ }
750
+ }
751
+ /**
752
+ * Completely remove smart name from a state.
753
+ */
754
+ static removeSmartName(obj, instanceId, noCommon) {
755
+ // Typing must be fixed in js-controller
756
+ const sureStateObject = obj;
757
+ if (noCommon) {
758
+ if (sureStateObject?.common?.custom?.[instanceId]) {
759
+ sureStateObject.common.custom[instanceId] = null;
760
+ }
761
+ }
762
+ else {
763
+ sureStateObject.common.smartName = null;
764
+ }
765
+ }
766
+ /**
767
+ * Update the smart name of a state.
768
+ */
769
+ static updateSmartName(obj, newSmartName, byON, smartType, instanceId, noCommon) {
770
+ const language = I18n.getLanguage();
771
+ // Typing must be fixed in js-controller
772
+ const sureStateObject = obj;
773
+ // convert the old format
774
+ if (typeof sureStateObject.common.smartName === 'string') {
775
+ const nnn = sureStateObject.common.smartName;
776
+ sureStateObject.common.smartName = {};
777
+ sureStateObject.common.smartName[language] = nnn;
778
+ }
779
+ // convert the old settings
780
+ if (sureStateObject.native?.byON) {
781
+ delete sureStateObject.native.byON;
782
+ let _smartName = sureStateObject.common.smartName;
783
+ if (_smartName && typeof _smartName !== 'object') {
784
+ _smartName = {
785
+ en: _smartName,
786
+ [language]: _smartName,
787
+ };
788
+ }
789
+ sureStateObject.common.smartName = _smartName;
790
+ }
791
+ if (smartType !== undefined) {
792
+ if (noCommon) {
793
+ sureStateObject.common.custom ||= {};
794
+ sureStateObject.common.custom[instanceId] ||= {};
795
+ sureStateObject.common.custom[instanceId].smartName ||= {};
796
+ if (!smartType) {
797
+ delete sureStateObject.common.custom[instanceId].smartName.smartType;
798
+ }
799
+ else {
800
+ sureStateObject.common.custom[instanceId].smartName.smartType = smartType;
801
+ }
802
+ }
803
+ else {
804
+ sureStateObject.common.smartName ||= {};
805
+ if (!smartType) {
806
+ delete sureStateObject.common.smartName.smartType;
807
+ }
808
+ else {
809
+ sureStateObject.common.smartName.smartType = smartType;
810
+ }
811
+ }
812
+ }
813
+ if (byON !== undefined) {
814
+ if (noCommon) {
815
+ sureStateObject.common.custom ||= {};
816
+ sureStateObject.common.custom[instanceId] ||= {};
817
+ sureStateObject.common.custom[instanceId].smartName ||= {};
818
+ sureStateObject.common.custom[instanceId].smartName.byON = byON;
819
+ }
820
+ else {
821
+ sureStateObject.common.smartName ||= {};
822
+ sureStateObject.common.smartName.byON = byON;
823
+ }
824
+ }
825
+ if (newSmartName !== undefined) {
826
+ let smartName;
827
+ if (noCommon) {
828
+ sureStateObject.common.custom ||= {};
829
+ sureStateObject.common.custom[instanceId] ||= {};
830
+ sureStateObject.common.custom[instanceId].smartName ||= {};
831
+ smartName = sureStateObject.common.custom[instanceId].smartName;
832
+ }
833
+ else {
834
+ sureStateObject.common.smartName ||= {};
835
+ smartName = sureStateObject.common.smartName;
836
+ }
837
+ smartName[language] = newSmartName;
838
+ // If smart name deleted
839
+ if (smartName &&
840
+ (!smartName[language] ||
841
+ (smartName[language] === sureStateObject.common.name && !sureStateObject.common.role))) {
842
+ delete smartName[language];
843
+ let empty = true;
844
+ // Check if the structure has any definitions
845
+ for (const key in smartName) {
846
+ if (Object.prototype.hasOwnProperty.call(smartName, key)) {
847
+ empty = false;
848
+ break;
849
+ }
850
+ }
851
+ // If empty => delete smartName completely
852
+ if (empty) {
853
+ if (noCommon && sureStateObject.common.custom?.[instanceId]) {
854
+ if (sureStateObject.common.custom[instanceId].smartName.byON === undefined) {
855
+ delete sureStateObject.common.custom[instanceId];
856
+ }
857
+ else {
858
+ delete sureStateObject.common.custom[instanceId].en;
859
+ delete sureStateObject.common.custom[instanceId].de;
860
+ delete sureStateObject.common.custom[instanceId].ru;
861
+ delete sureStateObject.common.custom[instanceId].nl;
862
+ delete sureStateObject.common.custom[instanceId].pl;
863
+ delete sureStateObject.common.custom[instanceId].it;
864
+ delete sureStateObject.common.custom[instanceId].fr;
865
+ delete sureStateObject.common.custom[instanceId].pt;
866
+ delete sureStateObject.common.custom[instanceId].es;
867
+ delete sureStateObject.common.custom[instanceId].uk;
868
+ delete sureStateObject.common.custom[instanceId]['zh-cn'];
869
+ }
870
+ }
871
+ else if (sureStateObject.common.smartName &&
872
+ sureStateObject.common.smartName.byON !== undefined) {
873
+ const _smartName = sureStateObject.common
874
+ .smartName;
875
+ delete _smartName.en;
876
+ delete _smartName.de;
877
+ delete _smartName.ru;
878
+ delete _smartName.nl;
879
+ delete _smartName.pl;
880
+ delete _smartName.it;
881
+ delete _smartName.fr;
882
+ delete _smartName.pt;
883
+ delete _smartName.es;
884
+ delete _smartName.uk;
885
+ delete _smartName['zh-cn'];
886
+ }
887
+ else {
888
+ sureStateObject.common.smartName = null;
889
+ }
890
+ }
891
+ }
892
+ }
893
+ }
894
+ /**
895
+ * Disable the smart name of a state.
896
+ */
897
+ static disableSmartName(obj, instanceId, noCommon) {
898
+ // Typing must be fixed in js-controller
899
+ const sureStateObject = obj;
900
+ if (noCommon) {
901
+ sureStateObject.common.custom ||= {};
902
+ sureStateObject.common.custom[instanceId] ||= {};
903
+ sureStateObject.common.custom[instanceId].smartName = false;
904
+ }
905
+ else {
906
+ sureStateObject.common.smartName = false;
907
+ }
908
+ }
909
+ /**
910
+ * Copy text to the clipboard.
911
+ */
912
+ static copyToClipboard(text, e) {
913
+ if (e) {
914
+ e.stopPropagation();
915
+ e.preventDefault();
916
+ }
917
+ return copy(text);
918
+ }
919
+ /**
920
+ * Gets the extension of a file name.
921
+ *
922
+ * @param fileName the file name.
923
+ * @returns The extension in lower case.
924
+ */
925
+ static getFileExtension(fileName) {
926
+ const pos = (fileName || '').lastIndexOf('.');
927
+ if (pos !== -1) {
928
+ return fileName.substring(pos + 1).toLowerCase();
929
+ }
930
+ return null;
931
+ }
932
+ /**
933
+ * Format number of bytes as a string with B, KB, MB or GB.
934
+ * The base for all calculations is 1024.
935
+ *
936
+ * @param bytes The number of bytes.
937
+ * @returns The formatted string (e.g. '723.5 KB')
938
+ */
939
+ static formatBytes(bytes) {
940
+ if (Math.abs(bytes) < 1024) {
941
+ return `${bytes} B`;
942
+ }
943
+ const units = ['KB', 'MB', 'GB'];
944
+ // const units = ['KiB','MiB','GiB','TiB','PiB','EiB','ZiB','YiB'];
945
+ let u = -1;
946
+ do {
947
+ bytes /= 1024;
948
+ ++u;
949
+ } while (Math.abs(bytes) >= 1024 && u < units.length - 1);
950
+ return `${bytes.toFixed(1)} ${units[u]}`;
951
+ }
952
+ /**
953
+ * Invert the given color according to a theme type to get the inverted text color for background
954
+ *
955
+ * @param color Color in the format '#rrggbb' or '#rgb' (or without a hash)
956
+ * @param themeType 'light' or 'dark'
957
+ * @param invert If true, the dark theme has a light color in the control, or the dark theme has a light color in the control
958
+ */
959
+ static getInvertedColor(color, themeType, invert) {
960
+ if (!color) {
961
+ return undefined;
962
+ }
963
+ const invertedColor = Utils.invertColor(color, true);
964
+ if (invertedColor === '#FFFFFF' && (themeType === 'dark' || (invert && themeType === 'light'))) {
965
+ return '#DDD';
966
+ }
967
+ if (invertedColor === '#000000' && (themeType === 'light' || (invert && themeType === 'dark'))) {
968
+ return '#222';
969
+ }
970
+ return undefined;
971
+ }
972
+ // Big thanks to: https://stackoverflow.com/questions/35969656/how-can-i-generate-the-opposite-color-according-to-current-color
973
+ /**
974
+ * Invert the given color
975
+ *
976
+ * @param hex Color in the format '#rrggbb' or '#rgb' (or without a hash)
977
+ * @param bw Set to black or white.
978
+ */
979
+ static invertColor(hex, bw) {
980
+ if (!hex || typeof hex !== 'string') {
981
+ return '';
982
+ }
983
+ if (hex.startsWith('rgba')) {
984
+ const m = hex.match(/rgba?\((\d+),\s*(\d+),\s*(\d+),\s*([.\d]+)\)/);
985
+ if (m) {
986
+ hex =
987
+ 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');
990
+ }
991
+ }
992
+ else if (hex.startsWith('rgb')) {
993
+ const m = hex.match(/rgb?\((\d+),\s*(\d+),\s*(\d+)\)/);
994
+ if (m) {
995
+ hex =
996
+ parseInt(m[1], 10).toString(16).padStart(2, '0') +
997
+ parseInt(m[2], 10).toString(16).padStart(2, '0') +
998
+ parseInt(m[2], 10).toString(16).padStart(2, '0');
999
+ }
1000
+ }
1001
+ else if (hex.startsWith('#')) {
1002
+ hex = hex.slice(1);
1003
+ }
1004
+ // convert 3-digit hex to 6-digits.
1005
+ if (hex.length === 3) {
1006
+ hex = hex[0] + hex[0] + hex[1] + hex[1] + hex[2] + hex[2];
1007
+ }
1008
+ let alfa = null;
1009
+ if (hex.length === 8) {
1010
+ alfa = hex.substring(6, 8);
1011
+ hex = hex.substring(0, 6);
1012
+ }
1013
+ else if (hex.length !== 6) {
1014
+ console.warn(`Cannot invert color: ${hex}`);
1015
+ return hex;
1016
+ }
1017
+ const r = parseInt(hex.slice(0, 2), 16);
1018
+ const g = parseInt(hex.slice(2, 4), 16);
1019
+ const b = parseInt(hex.slice(4, 6), 16);
1020
+ if (bw) {
1021
+ // http://stackoverflow.com/a/3943023/112731
1022
+ return r * 0.299 + g * 0.587 + b * 0.114 > 186 ? `#000000${alfa || ''}` : `#FFFFFF${alfa || ''}`;
1023
+ }
1024
+ // invert color components
1025
+ const rs = (255 - r).toString(16);
1026
+ const gs = (255 - g).toString(16);
1027
+ const bd = (255 - b).toString(16);
1028
+ // pad each with zeros and return
1029
+ return `#${rs.padStart(2, '0')}${gs.padStart(2, '0')}${bd.padStart(2, '0')}${alfa || ''}`;
1030
+ }
1031
+ /**
1032
+ * Convert RGB to array [r, g, b]
1033
+ *
1034
+ * @param hex Color in the format '#rrggbb' or '#rgb' (or without hash) or rgb(r,g,b) or rgba(r,g,b,a)
1035
+ * @returns Array with 3 elements [r, g, b]
1036
+ */
1037
+ static color2rgb(hex) {
1038
+ if (hex === undefined || hex === null || hex === '' || typeof hex !== 'string') {
1039
+ return false;
1040
+ }
1041
+ if (hex.startsWith('rgba')) {
1042
+ const m = hex.match(/rgba?\((\d+),\s*(\d+),\s*(\d+),\s*([.\d]+)\)/);
1043
+ if (m) {
1044
+ hex =
1045
+ parseInt(m[1], 10).toString(16).padStart(2, '0') +
1046
+ parseInt(m[2], 10).toString(16).padStart(2, '0') +
1047
+ parseInt(m[2], 10).toString(16).padStart(2, '0');
1048
+ }
1049
+ }
1050
+ else if (hex.startsWith('rgb')) {
1051
+ const m = hex.match(/rgb?\((\d+),\s*(\d+),\s*(\d+)\)/);
1052
+ if (m) {
1053
+ hex =
1054
+ parseInt(m[1], 10).toString(16).padStart(2, '0') +
1055
+ parseInt(m[2], 10).toString(16).padStart(2, '0') +
1056
+ parseInt(m[2], 10).toString(16).padStart(2, '0');
1057
+ }
1058
+ }
1059
+ else if (hex.startsWith('#')) {
1060
+ hex = hex.slice(1);
1061
+ }
1062
+ // convert 3-digit hex to 6-digits.
1063
+ if (hex.length === 3) {
1064
+ hex = hex[0] + hex[0] + hex[1] + hex[1] + hex[2] + hex[2];
1065
+ }
1066
+ if (hex.length !== 6 && hex.length !== 8) {
1067
+ console.warn(`Cannot invert color: ${hex}`);
1068
+ return false;
1069
+ }
1070
+ return [parseInt(hex.slice(0, 2), 16), parseInt(hex.slice(2, 4), 16), parseInt(hex.slice(4, 6), 16)];
1071
+ }
1072
+ // Big thanks to: https://github.com/antimatter15/rgb-lab
1073
+ /**
1074
+ * Convert RGB to LAB
1075
+ *
1076
+ * @param rgb color in format [r,g,b]
1077
+ * @returns lab color in format [l,a,b]
1078
+ */
1079
+ static rgb2lab(rgb) {
1080
+ let r = rgb[0] / 255;
1081
+ let g = rgb[1] / 255;
1082
+ let b = rgb[2] / 255;
1083
+ r = r > 0.04045 ? ((r + 0.055) / 1.055) ** 2.4 : r / 12.92;
1084
+ g = g > 0.04045 ? ((g + 0.055) / 1.055) ** 2.4 : g / 12.92;
1085
+ b = b > 0.04045 ? ((b + 0.055) / 1.055) ** 2.4 : b / 12.92;
1086
+ let x = (r * 0.4124 + g * 0.3576 + b * 0.1805) / 0.95047;
1087
+ let y = r * 0.2126 + g * 0.7152 + b * 0.0722; /* / 1.00000; */
1088
+ let z = (r * 0.0193 + g * 0.1192 + b * 0.9505) / 1.08883;
1089
+ x = x > 0.008856 ? x ** 0.33333333 : 7.787 * x + 0.137931; // 16 / 116;
1090
+ y = y > 0.008856 ? y ** 0.33333333 : 7.787 * y + 0.137931; // 16 / 116;
1091
+ z = z > 0.008856 ? z ** 0.33333333 : 7.787 * z + 0.137931; // 16 / 116;
1092
+ return [116 * y - 16, 500 * (x - y), 200 * (y - z)];
1093
+ }
1094
+ /**
1095
+ * Calculate the distance between two colors in LAB color space in the range 0-100^2
1096
+ * If the distance is less than 1000, the colors are similar
1097
+ *
1098
+ * @param color1 Color in the format '#rrggbb' or '#rgb' (or without hash) or rgb(r,g,b) or rgba(r,g,b,a)
1099
+ * @param color2 Color in the format '#rrggbb' or '#rgb' (or without hash) or rgb(r,g,b) or rgba(r,g,b,a)
1100
+ * @returns distance in the range 0-100^2
1101
+ */
1102
+ static colorDistance(color1, color2) {
1103
+ const rgb1 = Utils.color2rgb(color1);
1104
+ const rgb2 = Utils.color2rgb(color2);
1105
+ if (!rgb1 || !rgb2) {
1106
+ return 0;
1107
+ }
1108
+ const lab1 = Utils.rgb2lab(rgb1);
1109
+ const lab2 = Utils.rgb2lab(rgb2);
1110
+ const dltL = lab1[0] - lab2[0];
1111
+ const dltA = lab1[1] - lab2[1];
1112
+ const dltB = lab1[2] - lab2[2];
1113
+ const c1 = Math.sqrt(lab1[1] * lab1[1] + lab1[2] * lab1[2]);
1114
+ const c2 = Math.sqrt(lab2[1] * lab2[1] + lab2[2] * lab2[2]);
1115
+ const dltC = c1 - c2;
1116
+ let dltH = dltA * dltA + dltB * dltB - dltC * dltC;
1117
+ dltH = dltH < 0 ? 0 : Math.sqrt(dltH);
1118
+ const sc = 1.0 + 0.045 * c1;
1119
+ const sh = 1.0 + 0.015 * c1;
1120
+ const dltLKlsl = dltL;
1121
+ const dltCkcsc = dltC / sc;
1122
+ const dltHkhsh = dltH / sh;
1123
+ const i = dltLKlsl * dltLKlsl + dltCkcsc * dltCkcsc + dltHkhsh * dltHkhsh;
1124
+ return i < 0 ? 0 : i;
1125
+ }
1126
+ // https://github.com/lukeed/clsx/blob/master/src/index.js
1127
+ // License
1128
+ // MIT © Luke Edwards
1129
+ static _toVal(mix) {
1130
+ let y;
1131
+ let str = '';
1132
+ if (typeof mix === 'string' || typeof mix === 'number') {
1133
+ str += mix;
1134
+ }
1135
+ else if (typeof mix === 'object') {
1136
+ if (Array.isArray(mix)) {
1137
+ for (let k = 0; k < mix.length; k++) {
1138
+ if (mix[k]) {
1139
+ y = Utils._toVal(mix[k]);
1140
+ if (y) {
1141
+ str && (str += ' ');
1142
+ str += y;
1143
+ }
1144
+ }
1145
+ }
1146
+ }
1147
+ else {
1148
+ for (const k in mix) {
1149
+ if (mix[k]) {
1150
+ str && (str += ' ');
1151
+ str += k;
1152
+ }
1153
+ }
1154
+ }
1155
+ }
1156
+ return str;
1157
+ }
1158
+ // https://github.com/lukeed/clsx/blob/master/src/index.js
1159
+ // License
1160
+ // MIT © Luke Edwards
1161
+ /**
1162
+ * Convert any object to a string with its values.
1163
+ */
1164
+ static clsx(...inputs) {
1165
+ let i = 0;
1166
+ let tmp;
1167
+ let x;
1168
+ let str = '';
1169
+ while (i < inputs.length) {
1170
+ tmp = inputs[i++];
1171
+ if (tmp) {
1172
+ x = Utils._toVal(tmp);
1173
+ if (x) {
1174
+ str && (str += ' ');
1175
+ str += x;
1176
+ }
1177
+ }
1178
+ }
1179
+ return str;
1180
+ }
1181
+ /**
1182
+ * Get the current theme name (either from local storage or the browser settings).
1183
+ */
1184
+ static getThemeName(themeName) {
1185
+ if (window.vendorPrefix &&
1186
+ window.vendorPrefix !== '@@vendorPrefix@@' &&
1187
+ window.vendorPrefix !== 'MV') {
1188
+ return window.vendorPrefix;
1189
+ }
1190
+ themeName = (window._localStorage || window.localStorage).getItem('App.themeName');
1191
+ if (themeName) {
1192
+ return themeName;
1193
+ }
1194
+ return window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light';
1195
+ }
1196
+ /**
1197
+ * Get the type of theme.
1198
+ */
1199
+ static getThemeType(themeName) {
1200
+ if (window.vendorPrefix && window.vendorPrefix !== '@@vendorPrefix@@') {
1201
+ return 'light';
1202
+ }
1203
+ themeName = themeName || Utils.getThemeName();
1204
+ return themeName === 'dark' || themeName === 'blue' ? 'dark' : 'light';
1205
+ }
1206
+ /**
1207
+ * Set the theme name and theme type.
1208
+ */
1209
+ static setThemeName(themeName) {
1210
+ const vendorPrefix = window.vendorPrefix;
1211
+ if (vendorPrefix && vendorPrefix !== '@@vendorPrefix@@' && vendorPrefix !== 'MV') {
1212
+ return; // ignore
1213
+ }
1214
+ (window._localStorage || window.localStorage).setItem('App.themeName', themeName);
1215
+ (window._localStorage || window.localStorage).setItem('App.theme', themeName === 'dark' || themeName === 'blue' ? 'dark' : 'light');
1216
+ }
1217
+ /**
1218
+ * Toggle the theme name between 'dark' and 'colored'.
1219
+ *
1220
+ * @returns the new theme name.
1221
+ */
1222
+ static toggleTheme(themeName) {
1223
+ if (window.vendorPrefix &&
1224
+ window.vendorPrefix !== '@@vendorPrefix@@' &&
1225
+ window.vendorPrefix !== 'MV') {
1226
+ return window.vendorPrefix;
1227
+ }
1228
+ themeName =
1229
+ themeName || (window._localStorage || window.localStorage).getItem('App.themeName') || 'light';
1230
+ // dark => blue => colored => light => dark
1231
+ const themes = Utils.getThemeNames();
1232
+ const pos = themeName ? themes.indexOf(themeName) : -1;
1233
+ let newTheme;
1234
+ if (pos !== -1) {
1235
+ newTheme = themes[(pos + 1) % themes.length];
1236
+ }
1237
+ else {
1238
+ newTheme = themes[0];
1239
+ }
1240
+ Utils.setThemeName(newTheme);
1241
+ return newTheme;
1242
+ }
1243
+ /**
1244
+ * Get the list of themes
1245
+ *
1246
+ * @returns list of possible themes
1247
+ */
1248
+ static getThemeNames() {
1249
+ if (window.vendorPrefix &&
1250
+ window.vendorPrefix !== '@@vendorPrefix@@' &&
1251
+ window.vendorPrefix !== 'MV') {
1252
+ return [window.vendorPrefix];
1253
+ }
1254
+ return ['light', 'dark'];
1255
+ }
1256
+ /**
1257
+ * Parse a query string into its parts.
1258
+ */
1259
+ static parseQuery(query) {
1260
+ query = (query || '').toString().replace(/^\?/, '');
1261
+ const result = {};
1262
+ query.split('&').forEach(part => {
1263
+ part = part.trim();
1264
+ if (part) {
1265
+ const parts = part.split('=');
1266
+ const attr = decodeURIComponent(parts[0]).trim();
1267
+ if (parts.length > 1) {
1268
+ const value = decodeURIComponent(parts[1]);
1269
+ if (value === 'true') {
1270
+ result[attr] = true;
1271
+ }
1272
+ else if (value === 'false') {
1273
+ result[attr] = false;
1274
+ }
1275
+ else {
1276
+ const f = parseFloat(value);
1277
+ if (f.toString() === value) {
1278
+ result[attr] = f;
1279
+ }
1280
+ else {
1281
+ result[attr] = value;
1282
+ }
1283
+ }
1284
+ }
1285
+ else {
1286
+ result[attr] = true;
1287
+ }
1288
+ }
1289
+ });
1290
+ return result;
1291
+ }
1292
+ /**
1293
+ * Returns parent ID.
1294
+ *
1295
+ * @returns parent ID or null if no parent
1296
+ */
1297
+ static getParentId(id) {
1298
+ const p = (id || '').toString().split('.');
1299
+ if (p.length > 1) {
1300
+ p.pop();
1301
+ return p.join('.');
1302
+ }
1303
+ return null;
1304
+ }
1305
+ static formatDate(dateObj, dateFormat) {
1306
+ // format could be DD.MM.YYYY, YYYY.MM.DD or MM/DD/YYYY
1307
+ if (!dateObj) {
1308
+ return '';
1309
+ }
1310
+ let text;
1311
+ const mm = (dateObj.getMonth() + 1).toString().padStart(2, '0');
1312
+ const dd = dateObj.getDate().toString().padStart(2, '0');
1313
+ if (dateFormat === 'MM/DD/YYYY') {
1314
+ text = `${mm}/${dd}/${dateObj.getFullYear()}`;
1315
+ }
1316
+ else {
1317
+ text = `${dateObj.getFullYear()}-${mm}-${dd}`;
1318
+ }
1319
+ // time
1320
+ text += ` ${dateObj.getHours().toString().padStart(2, '0')}:${dateObj.getMinutes().toString().padStart(2, '0')}:${dateObj.getSeconds().toString().padStart(2, '0')}.${dateObj.getMilliseconds().toString().padStart(3, '0')}`;
1321
+ return text;
1322
+ }
1323
+ /**
1324
+ * Format seconds to string like 'h:mm:ss' or 'd.hh:mm:ss'
1325
+ */
1326
+ static formatTime(seconds) {
1327
+ if (seconds) {
1328
+ seconds = Math.round(seconds);
1329
+ const d = Math.floor(seconds / (3600 * 24));
1330
+ const h = Math.floor((seconds % (3600 * 24)) / 3600);
1331
+ const m = Math.floor((seconds % 3600) / 60);
1332
+ const s = seconds % 60;
1333
+ if (d) {
1334
+ return `${d}.${h.toString().padStart(2, '0')}:${m.toString().padStart(2, '0')}:${s.toString().padStart(2, '0')}`;
1335
+ }
1336
+ if (h) {
1337
+ return `${h}:${m.toString().padStart(2, '0')}:${s.toString().padStart(2, '0')}`;
1338
+ }
1339
+ return `0:${m.toString().padStart(2, '0')}:${s.toString().padStart(2, '0')}`;
1340
+ }
1341
+ return '0:00:00';
1342
+ }
1343
+ static MDtext2link(text) {
1344
+ const m = text.match(/\d+\.\)\s/);
1345
+ if (m) {
1346
+ text = text.replace(m[0], m[0].replace(/\s/, '&nbsp;'));
1347
+ }
1348
+ return text
1349
+ .replace(/[^a-zA-Zа-яА-Я0-9]/g, '')
1350
+ .trim()
1351
+ .replace(/\s/g, '')
1352
+ .toLowerCase();
1353
+ }
1354
+ /**
1355
+ * Open url link in the new target window
1356
+ */
1357
+ static openLink(url, target) {
1358
+ // replace IPv6 Address with [ipv6]:port
1359
+ url = url.replace(/\/\/([0-9a-f]*:[0-9a-f]*:[0-9a-f]*:[0-9a-f]*:[0-9a-f]*:[0-9a-f]*)(:\d+)?\//i, '//[$1]$2/');
1360
+ if (target === 'this') {
1361
+ window.location.href = url;
1362
+ }
1363
+ else {
1364
+ window.open(url, target || '_blank');
1365
+ }
1366
+ }
1367
+ static MDgetTitle(text) {
1368
+ const result = Utils.MDextractHeader(text);
1369
+ const header = result.header;
1370
+ let body = result.body;
1371
+ if (!header.title) {
1372
+ // remove {docsify-bla}
1373
+ body = body.replace(/{[^}]*}/g, '');
1374
+ body = body.trim();
1375
+ const lines = body.replace(/\r/g, '').split('\n');
1376
+ for (let i = 0; i < lines.length; i++) {
1377
+ if (lines[i].startsWith('# ')) {
1378
+ return lines[i].substring(2).trim();
1379
+ }
1380
+ }
1381
+ return '';
1382
+ }
1383
+ return header.title?.toString() || '';
1384
+ }
1385
+ static MDextractHeader(text) {
1386
+ const attrs = {};
1387
+ if (text.substring(0, 3) === '---') {
1388
+ const pos = text.substring(3).indexOf('\n---');
1389
+ if (pos !== -1) {
1390
+ const _header = text.substring(3, pos + 3);
1391
+ const lines = _header.replace(/\r/g, '').split('\n');
1392
+ lines.forEach(line => {
1393
+ if (!line.trim()) {
1394
+ return;
1395
+ }
1396
+ const pos_ = line.indexOf(':');
1397
+ if (pos_ !== -1) {
1398
+ const attr = line.substring(0, pos_).trim();
1399
+ let value = line.substring(pos_ + 1).trim();
1400
+ value = value.replace(/^['"]|['"]$/g, '');
1401
+ if (value === 'true') {
1402
+ attrs[attr] = true;
1403
+ }
1404
+ else if (value === 'false') {
1405
+ attrs[attr] = false;
1406
+ }
1407
+ else if (parseFloat(value).toString() === attrs[attr]) {
1408
+ attrs[attr] = parseFloat(value);
1409
+ }
1410
+ else {
1411
+ attrs[attr] = value;
1412
+ }
1413
+ }
1414
+ else {
1415
+ attrs[line.trim()] = true;
1416
+ }
1417
+ });
1418
+ text = text.substring(pos + 7);
1419
+ }
1420
+ }
1421
+ return { header: attrs, body: text };
1422
+ }
1423
+ static MDremoveDocsify(text) {
1424
+ const m = text.match(/{docsify-[^}]*}/g);
1425
+ if (m) {
1426
+ m.forEach(doc => (text = text.replace(doc, '')));
1427
+ }
1428
+ return text;
1429
+ }
1430
+ /**
1431
+ * Generate the file for download from JSON object.
1432
+ */
1433
+ static generateFile(fileName,
1434
+ /** json file data */
1435
+ json) {
1436
+ const el = document.createElement('a');
1437
+ el.setAttribute('href', `data:application/json;charset=utf-8,${encodeURIComponent(JSON.stringify(json, null, 2))}`);
1438
+ el.setAttribute('download', fileName);
1439
+ el.style.display = 'none';
1440
+ document.body.appendChild(el);
1441
+ el.click();
1442
+ document.body.removeChild(el);
1443
+ }
1444
+ /**
1445
+ * Convert quality code into text
1446
+ *
1447
+ * @returns lines that decode quality
1448
+ */
1449
+ static quality2text(quality) {
1450
+ const custom = quality & 0xffff0000;
1451
+ const text = QUALITY_BITS[quality];
1452
+ let result;
1453
+ if (text) {
1454
+ result = [text];
1455
+ }
1456
+ else if (quality & 0x01) {
1457
+ result = [QUALITY_BITS[0x01], `0x${(quality & (0xffff & ~1)).toString(16)}`];
1458
+ }
1459
+ else if (quality & 0x02) {
1460
+ result = [QUALITY_BITS[0x02], `0x${(quality & (0xffff & ~2)).toString(16)}`];
1461
+ }
1462
+ else {
1463
+ result = [`0x${quality.toString(16)}`];
1464
+ }
1465
+ if (custom) {
1466
+ result.push(`0x${(custom >> 16).toString(16).toUpperCase()}`);
1467
+ }
1468
+ return result;
1469
+ }
1470
+ /**
1471
+ * Deep copy object
1472
+ */
1473
+ static clone(object) {
1474
+ return JSON.parse(JSON.stringify(object));
1475
+ }
1476
+ /**
1477
+ * Get states of object
1478
+ *
1479
+ * @returns states as an object in form {"value1": "label1", "value2": "label2"} or null
1480
+ */
1481
+ static getStates(obj) {
1482
+ const states = obj?.common?.states;
1483
+ let result;
1484
+ if (states) {
1485
+ if (typeof states === 'string' && states[0] === '{') {
1486
+ try {
1487
+ result = JSON.parse(states);
1488
+ }
1489
+ catch {
1490
+ console.error(`Cannot parse states: ${states}`);
1491
+ result = null;
1492
+ }
1493
+ }
1494
+ else if (typeof states === 'string') {
1495
+ // if old format val1:text1;val2:text2
1496
+ const parts = states.split(';');
1497
+ result = {};
1498
+ for (let p = 0; p < parts.length; p++) {
1499
+ const s = parts[p].split(':');
1500
+ result[s[0]] = s[1];
1501
+ }
1502
+ }
1503
+ else if (Array.isArray(states)) {
1504
+ result = {};
1505
+ if (obj?.common.type === 'number') {
1506
+ states.forEach((value, key) => (result[key] = value));
1507
+ }
1508
+ else if (obj?.common.type === 'string') {
1509
+ states.forEach(value => (result[value] = value));
1510
+ }
1511
+ else if (obj?.common.type === 'boolean') {
1512
+ result.false = states[0];
1513
+ result.true = states[1];
1514
+ }
1515
+ }
1516
+ else if (typeof states === 'object') {
1517
+ result = states;
1518
+ }
1519
+ }
1520
+ return result || null;
1521
+ }
1522
+ /**
1523
+ * Get svg file as text
1524
+ *
1525
+ * @param url URL of SVG file
1526
+ * @returns Promise with "data:image..."
1527
+ */
1528
+ static async getSvg(url) {
1529
+ const response = await fetch(url);
1530
+ const blob = await response.blob();
1531
+ return new Promise(resolve => {
1532
+ const reader = new FileReader();
1533
+ // eslint-disable-next-line @typescript-eslint/no-base-to-string
1534
+ reader.onload = () => resolve(reader.result?.toString() || '');
1535
+ reader.readAsDataURL(blob);
1536
+ });
1537
+ }
1538
+ /**
1539
+ * Detect a file extension by its content
1540
+ *
1541
+ * @returns The detected extension, like 'jpg'
1542
+ */
1543
+ static detectMimeType(
1544
+ /** Base64 encoded binary file */
1545
+ base64) {
1546
+ const signature = Object.keys(SIGNATURES).find(s => base64.startsWith(s));
1547
+ return signature ? SIGNATURES[signature] : null;
1548
+ }
1549
+ /**
1550
+ * Check if configured repository is the stable repository
1551
+ */
1552
+ static isStableRepository(
1553
+ /** current configured repository or multi repository */
1554
+ activeRepo) {
1555
+ return !!((typeof activeRepo === 'string' && activeRepo.toLowerCase().startsWith('stable')) ||
1556
+ (activeRepo && typeof activeRepo !== 'string' && activeRepo.find(r => r.toLowerCase().startsWith('stable'))));
1557
+ }
1558
+ /**
1559
+ * Check if a given string is an integer
1560
+ */
1561
+ static isStringInteger(str) {
1562
+ if (typeof str === 'number') {
1563
+ return Math.round(str) === str;
1564
+ }
1565
+ return parseInt(str, 10).toString() === str;
1566
+ }
1567
+ /**
1568
+ * Check if the date is valid
1569
+ */
1570
+ static isValidDate(date) {
1571
+ return date instanceof Date && !isNaN(date);
1572
+ }
1573
+ static getStyle(theme, ...args) {
1574
+ const result = {};
1575
+ for (let a = 0; a < args.length; a++) {
1576
+ if (typeof args[a] === 'function') {
1577
+ Object.assign(result, args[a](theme));
1578
+ }
1579
+ else if (args[a] && typeof args[a] === 'object') {
1580
+ Object.keys(args[a]).forEach((attr) => {
1581
+ if (typeof args[a][attr] === 'function') {
1582
+ result[attr] = args[a][attr](theme);
1583
+ }
1584
+ else if (typeof args[a][attr] === 'object') {
1585
+ const obj = args[a][attr];
1586
+ result[attr] = {};
1587
+ Object.keys(obj).forEach((attr1) => {
1588
+ if (typeof obj[attr1] === 'function') {
1589
+ result[attr][attr1] = obj(theme);
1590
+ }
1591
+ else if (obj[attr1] || obj[attr1] === 0) {
1592
+ result[attr][attr1] = obj[attr1];
1593
+ }
1594
+ });
1595
+ }
1596
+ else if (args[a][attr] || args[a][attr] === 0) {
1597
+ result[attr] = args[a][attr];
1598
+ }
1599
+ });
1600
+ }
1601
+ }
1602
+ return result;
1603
+ }
1604
+ }
1605
+ //# sourceMappingURL=Utils.js.map