@schukai/monster 3.51.5 → 3.52.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (361) hide show
  1. package/CHANGELOG.md +25 -0
  2. package/README.md +15 -12
  3. package/example/components/form/button.mjs +10 -0
  4. package/example/components/form/select.mjs +25 -0
  5. package/example/components/form/tree-select.mjs +27 -0
  6. package/example/components/host/host.mjs +0 -0
  7. package/example/components/notify/message.mjs +4 -0
  8. package/example/components/notify/notify.mjs +4 -0
  9. package/example/components/state/log.mjs +0 -0
  10. package/example/components/state/state.mjs +0 -0
  11. package/example/data/datasource/server/restapi.mjs +7 -1
  12. package/package.json +6 -2
  13. package/source/components/constants.mjs +132 -0
  14. package/source/components/datatable/columnbar.mjs +310 -0
  15. package/source/components/datatable/constants.mjs +121 -0
  16. package/source/components/datatable/dataset.mjs +219 -0
  17. package/source/components/datatable/datasource/dom.mjs +186 -0
  18. package/source/components/datatable/datasource/namespace.mjs +13 -0
  19. package/source/components/datatable/datasource/rest.mjs +400 -0
  20. package/source/components/datatable/datasource.mjs +102 -0
  21. package/source/components/datatable/datatable/header.mjs +268 -0
  22. package/source/components/datatable/datatable/namespace.mjs +13 -0
  23. package/source/components/datatable/datatable.mjs +789 -0
  24. package/source/components/datatable/embedded-pagination.mjs +113 -0
  25. package/source/components/datatable/filter/abstract-base.mjs +31 -0
  26. package/source/components/datatable/filter/date-range.mjs +1041 -0
  27. package/source/components/datatable/filter/input.mjs +175 -0
  28. package/source/components/datatable/filter/namespace.mjs +13 -0
  29. package/source/components/datatable/filter/range.mjs +671 -0
  30. package/source/components/datatable/filter/select.mjs +65 -0
  31. package/source/components/datatable/filter/settings.mjs +116 -0
  32. package/source/components/datatable/filter-button.mjs +98 -0
  33. package/source/components/datatable/filter.mjs +929 -0
  34. package/source/components/datatable/namespace.mjs +11 -0
  35. package/source/components/datatable/pagination.mjs +456 -0
  36. package/source/components/datatable/style/column-bar.pcss +123 -0
  37. package/source/components/datatable/style/dataset.pcss +13 -0
  38. package/source/components/datatable/style/datasource.pcss +16 -0
  39. package/source/components/datatable/style/datatable.pcss +239 -0
  40. package/source/components/datatable/style/embedded-pagination.pcss +101 -0
  41. package/source/components/datatable/style/filter-button.pcss +22 -0
  42. package/source/components/datatable/style/filter-controls-defaults.pcss +46 -0
  43. package/source/components/datatable/style/filter-date-range.pcss +9 -0
  44. package/source/components/datatable/style/filter-range.pcss +5 -0
  45. package/source/components/datatable/style/filter.pcss +156 -0
  46. package/source/components/datatable/style/pagination.pcss +59 -0
  47. package/source/components/datatable/style/select-filter.pcss +27 -0
  48. package/source/components/datatable/stylesheet/column-bar.mjs +27 -0
  49. package/source/components/datatable/stylesheet/dataset.mjs +27 -0
  50. package/source/components/datatable/stylesheet/datasource.mjs +27 -0
  51. package/source/components/datatable/stylesheet/datatable.mjs +27 -0
  52. package/source/components/datatable/stylesheet/embedded-pagination.mjs +27 -0
  53. package/source/components/datatable/stylesheet/filter-button.mjs +27 -0
  54. package/source/components/datatable/stylesheet/filter-controls-defaults.mjs +27 -0
  55. package/source/components/datatable/stylesheet/filter-date-range.mjs +27 -0
  56. package/source/components/datatable/stylesheet/filter-range.mjs +27 -0
  57. package/source/components/datatable/stylesheet/filter.mjs +27 -0
  58. package/source/components/datatable/stylesheet/namespace.mjs +13 -0
  59. package/source/components/datatable/stylesheet/pagination.mjs +27 -0
  60. package/source/components/datatable/stylesheet/select-filter.mjs +27 -0
  61. package/source/components/datatable/util.mjs +60 -0
  62. package/source/components/form/action-button.mjs +262 -0
  63. package/source/components/form/api-button.mjs +515 -0
  64. package/source/components/form/button-bar.mjs +739 -0
  65. package/source/components/form/button.mjs +350 -0
  66. package/source/components/form/confirm-button.mjs +330 -0
  67. package/source/components/form/constants.mjs +111 -0
  68. package/source/components/form/context-help.mjs +123 -0
  69. package/source/components/form/events.mjs +84 -0
  70. package/source/components/form/form.mjs +601 -0
  71. package/source/components/form/message-state-button.mjs +396 -0
  72. package/source/components/form/namespace.mjs +13 -0
  73. package/source/components/form/popper-button.mjs +435 -0
  74. package/source/components/form/popper.mjs +487 -0
  75. package/source/components/form/reload.mjs +360 -0
  76. package/source/components/form/select.mjs +2314 -0
  77. package/source/components/form/shadow-reload.mjs +137 -0
  78. package/source/components/form/state-button.mjs +182 -0
  79. package/source/components/form/style/action-button.pcss +41 -0
  80. package/source/components/form/style/api-button.pcss +0 -0
  81. package/source/components/form/style/button-bar.pcss +51 -0
  82. package/source/components/form/style/button.pcss +8 -0
  83. package/source/components/form/style/confirm-button.pcss +17 -0
  84. package/source/components/form/style/context-help.pcss +16 -0
  85. package/source/components/form/style/form.pcss +10 -0
  86. package/source/components/form/style/message-state-button.pcss +10 -0
  87. package/source/components/form/style/popper-button.pcss +16 -0
  88. package/source/components/form/style/popper.pcss +8 -0
  89. package/source/components/form/style/select.pcss +265 -0
  90. package/source/components/form/style/state-button.pcss +116 -0
  91. package/source/components/form/style/tabs.pcss +173 -0
  92. package/source/components/form/style/tree-select.pcss +81 -0
  93. package/source/components/form/stylesheet/action-button.mjs +27 -0
  94. package/source/components/form/stylesheet/api-button.mjs +27 -0
  95. package/source/components/form/stylesheet/button-bar.mjs +27 -0
  96. package/source/components/form/stylesheet/button.mjs +27 -0
  97. package/source/components/form/stylesheet/confirm-button.mjs +27 -0
  98. package/source/components/form/stylesheet/context-help.mjs +27 -0
  99. package/source/components/form/stylesheet/form.mjs +27 -0
  100. package/source/components/form/stylesheet/message-state-button.mjs +27 -0
  101. package/source/components/form/stylesheet/namespace.mjs +13 -0
  102. package/source/components/form/stylesheet/popper-button.mjs +27 -0
  103. package/source/components/form/stylesheet/popper.mjs +27 -0
  104. package/source/components/form/stylesheet/select.mjs +27 -0
  105. package/source/components/form/stylesheet/state-button.mjs +27 -0
  106. package/source/components/form/stylesheet/tabs.mjs +27 -0
  107. package/source/components/form/stylesheet/tree-select.mjs +27 -0
  108. package/source/components/form/tabs.mjs +1029 -0
  109. package/source/components/form/template.mjs +373 -0
  110. package/source/components/form/tree-select.mjs +527 -0
  111. package/source/components/form/types/namespace.mjs +13 -0
  112. package/source/components/form/types/state.mjs +93 -0
  113. package/source/components/form/util/fetch.mjs +133 -0
  114. package/source/components/form/util/floating-ui.mjs +245 -0
  115. package/source/components/form/util/namespace.mjs +13 -0
  116. package/source/components/form/util/popper.mjs +49 -0
  117. package/source/components/host/call-button.mjs +236 -0
  118. package/source/components/host/collapse.mjs +526 -0
  119. package/source/components/host/config-manager.mjs +304 -0
  120. package/source/components/host/constants.mjs +18 -0
  121. package/source/components/host/details.mjs +268 -0
  122. package/source/components/host/events.mjs +131 -0
  123. package/source/components/host/host.mjs +420 -0
  124. package/source/components/host/namespace.mjs +13 -0
  125. package/source/components/host/overlay.mjs +339 -0
  126. package/source/components/host/style/call-button.pcss +36 -0
  127. package/source/components/host/style/collapse.pcss +67 -0
  128. package/source/components/host/style/config-manager.pcss +5 -0
  129. package/source/components/host/style/details.pcss +68 -0
  130. package/source/components/host/style/host.pcss +43 -0
  131. package/source/components/host/style/overlay.pcss +73 -0
  132. package/source/components/host/style/toggle-button.pcss +36 -0
  133. package/source/components/host/style/viewer.pcss +13 -0
  134. package/source/components/host/stylesheet/call-button.mjs +27 -0
  135. package/source/components/host/stylesheet/collapse.mjs +27 -0
  136. package/source/components/host/stylesheet/config-manager.mjs +27 -0
  137. package/source/components/host/stylesheet/details.mjs +27 -0
  138. package/source/components/host/stylesheet/host.mjs +27 -0
  139. package/source/components/host/stylesheet/namespace.mjs +13 -0
  140. package/source/components/host/stylesheet/overlay.mjs +27 -0
  141. package/source/components/host/stylesheet/toggle-button.mjs +27 -0
  142. package/source/components/host/stylesheet/viewer.mjs +27 -0
  143. package/source/components/host/toggle-button.mjs +88 -0
  144. package/source/components/host/util.mjs +23 -0
  145. package/source/components/host/viewer.mjs +309 -0
  146. package/source/components/namespace.mjs +14 -0
  147. package/source/components/notify/constants.mjs +15 -0
  148. package/source/components/notify/events.mjs +15 -0
  149. package/source/components/notify/message.mjs +374 -0
  150. package/source/components/notify/namespace.mjs +15 -0
  151. package/source/components/notify/notify.mjs +236 -0
  152. package/source/components/notify/style/message.pcss +57 -0
  153. package/source/components/notify/style/notify.pcss +118 -0
  154. package/source/components/notify/stylesheet/message.mjs +27 -0
  155. package/source/components/notify/stylesheet/namespace.mjs +15 -0
  156. package/source/components/notify/stylesheet/notify.mjs +27 -0
  157. package/source/components/state/log/entry.mjs +126 -0
  158. package/source/components/state/log/namespace.mjs +13 -0
  159. package/source/components/state/log.mjs +275 -0
  160. package/source/components/state/namespace.mjs +13 -0
  161. package/source/components/state/state.mjs +131 -0
  162. package/source/components/state/style/log.pcss +111 -0
  163. package/source/components/state/style/state.pcss +113 -0
  164. package/source/components/state/stylesheet/log.mjs +27 -0
  165. package/source/components/state/stylesheet/state.mjs +27 -0
  166. package/source/components/style/badge.pcss +92 -0
  167. package/source/components/style/border.pcss +77 -0
  168. package/source/components/style/button.pcss +105 -0
  169. package/source/components/style/card.pcss +108 -0
  170. package/source/components/style/color.pcss +257 -0
  171. package/source/components/style/common.pcss +105 -0
  172. package/source/components/style/control.pcss +11 -0
  173. package/source/components/style/data-grid.pcss +43 -0
  174. package/source/components/style/display.pcss +42 -0
  175. package/source/components/style/floating-ui.pcss +33 -0
  176. package/source/components/style/form.pcss +5 -0
  177. package/source/components/style/host.pcss +15 -0
  178. package/source/components/style/link.pcss +63 -0
  179. package/source/components/style/mixin/badge.pcss +18 -0
  180. package/source/components/style/mixin/button.pcss +52 -0
  181. package/source/components/style/mixin/form.pcss +247 -0
  182. package/source/components/style/mixin/hover.pcss +8 -0
  183. package/source/components/style/mixin/media.pcss +107 -0
  184. package/source/components/style/mixin/property.pcss +292 -0
  185. package/source/components/style/mixin/skeleton.pcss +26 -0
  186. package/source/components/style/mixin/spinner.pcss +24 -0
  187. package/source/components/style/mixin/typography.pcss +52 -0
  188. package/source/components/style/normalize.pcss +14 -0
  189. package/source/components/style/popper.pcss +78 -0
  190. package/source/components/style/property.pcss +17 -0
  191. package/source/components/style/ripple.pcss +14 -0
  192. package/source/components/style/skeleton.pcss +28 -0
  193. package/source/components/style/space.pcss +47 -0
  194. package/source/components/style/spinner.pcss +6 -0
  195. package/source/components/style/table.pcss +46 -0
  196. package/source/components/style/theme.pcss +119 -0
  197. package/source/components/style/typography.pcss +131 -0
  198. package/source/components/stylesheet/badge.mjs +27 -0
  199. package/source/components/stylesheet/border.mjs +27 -0
  200. package/source/components/stylesheet/button.mjs +27 -0
  201. package/source/components/stylesheet/card.mjs +27 -0
  202. package/source/components/stylesheet/color.mjs +27 -0
  203. package/source/components/stylesheet/common.mjs +27 -0
  204. package/source/components/stylesheet/control.mjs +27 -0
  205. package/source/components/stylesheet/data-grid.mjs +27 -0
  206. package/source/components/stylesheet/display.mjs +27 -0
  207. package/source/components/stylesheet/floating-ui.mjs +27 -0
  208. package/source/components/stylesheet/form.mjs +27 -0
  209. package/source/components/stylesheet/host.mjs +27 -0
  210. package/source/components/stylesheet/link.mjs +27 -0
  211. package/source/components/stylesheet/namespace.mjs +13 -0
  212. package/source/components/stylesheet/normalize.mjs +27 -0
  213. package/source/components/stylesheet/popper.mjs +27 -0
  214. package/source/components/stylesheet/property.mjs +27 -0
  215. package/source/components/stylesheet/ripple.mjs +27 -0
  216. package/source/components/stylesheet/skeleton.mjs +27 -0
  217. package/source/components/stylesheet/space.mjs +27 -0
  218. package/source/components/stylesheet/spinner.mjs +27 -0
  219. package/source/components/stylesheet/table.mjs +27 -0
  220. package/source/components/stylesheet/theme.mjs +27 -0
  221. package/source/components/stylesheet/tree-menu.mjs +33 -0
  222. package/source/components/stylesheet/typography.mjs +27 -0
  223. package/source/components/tree-menu/namespace.mjs +13 -0
  224. package/source/components/tree-menu/style/tree-menu.pcss +107 -0
  225. package/source/components/tree-menu/stylesheet/namespace.mjs +13 -0
  226. package/source/components/tree-menu/stylesheet/tree-menu.mjs +27 -0
  227. package/source/components/tree-menu/tree-menu.mjs +660 -0
  228. package/source/constraints/abstract.mjs +17 -24
  229. package/source/constraints/abstractoperator.mjs +27 -22
  230. package/source/constraints/andoperator.mjs +20 -17
  231. package/source/constraints/invalid.mjs +17 -17
  232. package/source/constraints/isarray.mjs +20 -20
  233. package/source/constraints/isobject.mjs +20 -20
  234. package/source/constraints/oroperator.mjs +45 -45
  235. package/source/constraints/valid.mjs +17 -17
  236. package/source/data/buildmap.mjs +108 -103
  237. package/source/data/buildtree.mjs +59 -57
  238. package/source/data/datasource/dom.mjs +80 -84
  239. package/source/data/datasource/namespace.mjs +1 -1
  240. package/source/data/datasource/server/restapi/data-fetch-error.mjs +27 -25
  241. package/source/data/datasource/server/restapi/writeerror.mjs +35 -32
  242. package/source/data/datasource/server/restapi.mjs +176 -177
  243. package/source/data/datasource/server/webconnect.mjs +150 -156
  244. package/source/data/datasource/server.mjs +62 -63
  245. package/source/data/datasource/storage/localstorage.mjs +25 -24
  246. package/source/data/datasource/storage/sessionstorage.mjs +28 -25
  247. package/source/data/datasource/storage.mjs +74 -73
  248. package/source/data/datasource.mjs +177 -168
  249. package/source/data/diff.mjs +98 -97
  250. package/source/data/extend.mjs +42 -42
  251. package/source/data/pathfinder.mjs +301 -288
  252. package/source/data/pipe.mjs +36 -36
  253. package/source/data/transformer.mjs +742 -726
  254. package/source/dom/assembler.mjs +44 -44
  255. package/source/dom/attributes.mjs +142 -122
  256. package/source/dom/constants.mjs +62 -58
  257. package/source/dom/customcontrol.mjs +299 -299
  258. package/source/dom/customelement.mjs +843 -806
  259. package/source/dom/dimension.mjs +56 -46
  260. package/source/dom/events.mjs +74 -69
  261. package/source/dom/focusmanager.mjs +175 -175
  262. package/source/dom/locale.mjs +28 -28
  263. package/source/dom/ready.mjs +13 -13
  264. package/source/dom/resource/data.mjs +117 -111
  265. package/source/dom/resource/link/stylesheet.mjs +16 -16
  266. package/source/dom/resource/link.mjs +94 -96
  267. package/source/dom/resource/script.mjs +72 -74
  268. package/source/dom/resource.mjs +174 -172
  269. package/source/dom/resourcemanager.mjs +152 -156
  270. package/source/dom/slotted.mjs +78 -80
  271. package/source/dom/template.mjs +126 -112
  272. package/source/dom/theme.mjs +35 -35
  273. package/source/dom/updater.mjs +673 -651
  274. package/source/dom/util/extract-keys.mjs +34 -22
  275. package/source/dom/util/init-options-from-attributes.mjs +46 -38
  276. package/source/dom/util/namespace.mjs +13 -0
  277. package/source/dom/util/set-option-from-attribute.mjs +35 -29
  278. package/source/dom/util.mjs +112 -81
  279. package/source/dom/worker/factory.mjs +83 -83
  280. package/source/i18n/formatter.mjs +75 -73
  281. package/source/i18n/locale.mjs +146 -144
  282. package/source/i18n/provider.mjs +70 -64
  283. package/source/i18n/providers/embed.mjs +136 -127
  284. package/source/i18n/providers/fetch.mjs +84 -76
  285. package/source/i18n/translations.mjs +205 -195
  286. package/source/logging/handler/console.mjs +36 -36
  287. package/source/logging/handler.mjs +140 -140
  288. package/source/logging/logentry.mjs +25 -25
  289. package/source/logging/logger.mjs +177 -175
  290. package/source/math/random.mjs +63 -59
  291. package/source/monster.mjs +223 -103
  292. package/source/net/webconnect/message.mjs +31 -31
  293. package/source/net/webconnect.mjs +278 -271
  294. package/source/text/bracketed-key-value-hash.mjs +182 -179
  295. package/source/text/formatter.mjs +235 -210
  296. package/source/text/generate-range-comparison-expression.mjs +56 -34
  297. package/source/text/namespace.mjs +1 -1
  298. package/source/types/base.mjs +69 -61
  299. package/source/types/basewithoptions.mjs +46 -46
  300. package/source/types/binary.mjs +20 -20
  301. package/source/types/dataurl.mjs +96 -90
  302. package/source/types/global.mjs +45 -39
  303. package/source/types/id.mjs +25 -25
  304. package/source/types/internal.mjs +115 -114
  305. package/source/types/is.mjs +56 -40
  306. package/source/types/mediatype.mjs +119 -119
  307. package/source/types/namespace.mjs +1 -1
  308. package/source/types/node.mjs +160 -150
  309. package/source/types/nodelist.mjs +94 -96
  310. package/source/types/noderecursiveiterator.mjs +50 -50
  311. package/source/types/observablequeue.mjs +73 -73
  312. package/source/types/observer.mjs +114 -106
  313. package/source/types/observerlist.mjs +66 -66
  314. package/source/types/proxyobserver.mjs +210 -210
  315. package/source/types/queue.mjs +63 -63
  316. package/source/types/randomid.mjs +13 -13
  317. package/source/types/regex.mjs +3 -1
  318. package/source/types/stack.mjs +64 -64
  319. package/source/types/tokenlist.mjs +206 -205
  320. package/source/types/typeof.mjs +12 -10
  321. package/source/types/uniquequeue.mjs +48 -48
  322. package/source/types/uuid.mjs +32 -32
  323. package/source/types/validate.mjs +67 -67
  324. package/source/types/version.mjs +115 -105
  325. package/source/util/clone.mjs +103 -91
  326. package/source/util/comparator.mjs +97 -97
  327. package/source/util/deadmansswitch.mjs +40 -44
  328. package/source/util/freeze.mjs +10 -9
  329. package/source/util/namespace.mjs +1 -1
  330. package/source/util/processing.mjs +104 -105
  331. package/source/util/runtime.mjs +56 -44
  332. package/source/util/trimspaces.mjs +24 -24
  333. package/test/cases/components/form/button.mjs +122 -0
  334. package/test/cases/components/form/confirm-button.mjs +127 -0
  335. package/test/cases/components/form/form.mjs +317 -0
  336. package/test/cases/components/form/reload.mjs +188 -0
  337. package/test/cases/components/form/select.mjs +229 -0
  338. package/test/cases/components/form/state-button.mjs +130 -0
  339. package/test/cases/components/form/tabs.mjs +98 -0
  340. package/test/cases/components/form/template.mjs +189 -0
  341. package/test/cases/components/form/tree-select.mjs +216 -0
  342. package/test/cases/components/host/details.mjs +68 -0
  343. package/test/cases/components/host/host.mjs +70 -0
  344. package/test/cases/components/host/overlay.mjs +60 -0
  345. package/test/cases/components/host/util.mjs +79 -0
  346. package/test/cases/components/notify/message.mjs +39 -0
  347. package/test/cases/components/notify/notify.mjs +89 -0
  348. package/test/cases/dom/customcontrol.mjs +5 -4
  349. package/test/cases/math/random.mjs +0 -1
  350. package/test/cases/monster.mjs +1 -1
  351. package/test/cases/net/webconnect/message.mjs +0 -1
  352. package/test/cases/types/node.mjs +1 -1
  353. package/test/util/chai-dom.mjs +2 -2
  354. package/test/util/intersection-mock.mjs +69 -0
  355. package/test/util/jsdom.mjs +41 -25
  356. package/test/util/localstorage.mjs +1 -0
  357. package/test/util/resize-observer.mjs +29 -0
  358. package/test/util/websocket.mjs +4 -1
  359. package/test/web/import.js +16 -1
  360. package/test/web/test.html +28 -5
  361. package/test/web/tests.js +30398 -17879
@@ -28,131 +28,140 @@ export { Embed };
28
28
  * @tutorial i18n-locale-and-formatter
29
29
  */
30
30
  class Embed extends Provider {
31
- /**
32
- * ```html
33
- * <script id="translations" type="application/json">
34
- * {
35
- * "hello": "Hallo"
36
- * }
37
- * </script>
38
- * ```
39
- *
40
- *
41
- * ```javascript
42
- * new Embed('translations')
43
- * ```
44
- *
45
- * @param {HTMLElement|string} elementOrId
46
- * @param {Object} options
47
- */
48
- constructor(elementOrId, options) {
49
- super(options);
50
-
51
- if (options === undefined) {
52
- options = {};
53
- }
54
-
55
- if (elementOrId instanceof HTMLElement) {
56
- /**
57
- * @property {HTMLElement|string}
58
- */
59
- this.translateElement = elementOrId;
60
- } else {
61
- /**
62
- * @property {HTMLElement|string}
63
- */
64
- this.translateElement = getDocument().getElementById(validateString(elementOrId));
65
- }
66
-
67
- /**
68
- * @private
69
- * @property {Object} options
70
- */
71
- this[internalSymbol] = extend({}, super.defaults, this.defaults, validateObject(options));
72
- }
73
-
74
- /**
75
- * Defaults
76
- *
77
- * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API}
78
- */
79
- get defaults() {
80
- return extend({}, super.defaults);
81
- }
82
-
83
- /**
84
- *
85
- * @param {Locale|string} locale
86
- * @return {Promise}
87
- */
88
- getTranslations(locale) {
89
- if (isString(locale)) {
90
- locale = parseLocale(locale);
91
- }
92
-
93
- return new Promise((resolve, reject) => {
94
- if (this.translateElement === null) {
95
- reject(new Error("Text not found"));
96
- return;
97
- }
98
-
99
- if (!(this.translateElement instanceof HTMLScriptElement)) {
100
- reject(new Error("Element is not a script tag"));
101
- return;
102
- }
103
-
104
- if (this.translateElement.type !== "application/json") {
105
- reject(new Error("Element is not a script tag with type application/json"));
106
- return;
107
- }
108
-
109
- let translations = null;
110
- try {
111
- translations = JSON.parse(this.translateElement.innerHTML.trim());
112
- } catch (e) {
113
- reject(e);
114
- return;
115
- }
116
-
117
- if (translations === null) {
118
- reject(new Error("Translations not found or invalid"));
119
- return;
120
- }
121
-
122
- const t = new Translations(locale);
123
- t.assignTranslations(translations);
124
-
125
- resolve(t);
126
- });
127
- }
128
-
129
- /**
130
- * Initializes the translations for the current document.
131
- *
132
- * `script[data-monster-role=translations]` is searched for and the translations are assigned to the element.
133
- *
134
- * @param element
135
- * @returns {Promise<unknown[]>}
136
- */
137
- static assignTranslationsToElement(element) {
138
- const d = getDocument();
139
-
140
- if (!(element instanceof HTMLElement)) {
141
- element = d.querySelector("body");
142
- }
143
-
144
- const list = d.querySelectorAll("script[data-monster-role=translations]");
145
- if (list === null) {
146
- return;
147
- }
148
-
149
- const promises = [];
150
-
151
- list.forEach((translationElement) => {
152
- const p = new Embed(translationElement);
153
- promises.push(p.assignToElement(undefined, element));
154
- });
155
-
156
- return Promise.all(promises);
157
- }
31
+ /**
32
+ * ```html
33
+ * <script id="translations" type="application/json">
34
+ * {
35
+ * "hello": "Hallo"
36
+ * }
37
+ * </script>
38
+ * ```
39
+ *
40
+ *
41
+ * ```javascript
42
+ * new Embed('translations')
43
+ * ```
44
+ *
45
+ * @param {HTMLElement|string} elementOrId
46
+ * @param {Object} options
47
+ */
48
+ constructor(elementOrId, options) {
49
+ super(options);
50
+
51
+ if (options === undefined) {
52
+ options = {};
53
+ }
54
+
55
+ if (elementOrId instanceof HTMLElement) {
56
+ /**
57
+ * @property {HTMLElement|string}
58
+ */
59
+ this.translateElement = elementOrId;
60
+ } else {
61
+ /**
62
+ * @property {HTMLElement|string}
63
+ */
64
+ this.translateElement = getDocument().getElementById(
65
+ validateString(elementOrId),
66
+ );
67
+ }
68
+
69
+ /**
70
+ * @private
71
+ * @property {Object} options
72
+ */
73
+ this[internalSymbol] = extend(
74
+ {},
75
+ super.defaults,
76
+ this.defaults,
77
+ validateObject(options),
78
+ );
79
+ }
80
+
81
+ /**
82
+ * Defaults
83
+ *
84
+ * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API}
85
+ */
86
+ get defaults() {
87
+ return extend({}, super.defaults);
88
+ }
89
+
90
+ /**
91
+ *
92
+ * @param {Locale|string} locale
93
+ * @return {Promise}
94
+ */
95
+ getTranslations(locale) {
96
+ if (isString(locale)) {
97
+ locale = parseLocale(locale);
98
+ }
99
+
100
+ return new Promise((resolve, reject) => {
101
+ if (this.translateElement === null) {
102
+ reject(new Error("Text not found"));
103
+ return;
104
+ }
105
+
106
+ if (!(this.translateElement instanceof HTMLScriptElement)) {
107
+ reject(new Error("Element is not a script tag"));
108
+ return;
109
+ }
110
+
111
+ if (this.translateElement.type !== "application/json") {
112
+ reject(
113
+ new Error("Element is not a script tag with type application/json"),
114
+ );
115
+ return;
116
+ }
117
+
118
+ let translations = null;
119
+ try {
120
+ translations = JSON.parse(this.translateElement.innerHTML.trim());
121
+ } catch (e) {
122
+ reject(e);
123
+ return;
124
+ }
125
+
126
+ if (translations === null) {
127
+ reject(new Error("Translations not found or invalid"));
128
+ return;
129
+ }
130
+
131
+ const t = new Translations(locale);
132
+ t.assignTranslations(translations);
133
+
134
+ resolve(t);
135
+ });
136
+ }
137
+
138
+ /**
139
+ * Initializes the translations for the current document.
140
+ *
141
+ * `script[data-monster-role=translations]` is searched for and the translations are assigned to the element.
142
+ *
143
+ * @param element
144
+ * @returns {Promise<unknown[]>}
145
+ */
146
+ static assignTranslationsToElement(element) {
147
+ const d = getDocument();
148
+
149
+ if (!(element instanceof HTMLElement)) {
150
+ element = d.querySelector("body");
151
+ }
152
+
153
+ const list = d.querySelectorAll("script[data-monster-role=translations]");
154
+ if (list === null) {
155
+ return;
156
+ }
157
+
158
+ const promises = [];
159
+
160
+ list.forEach((translationElement) => {
161
+ const p = new Embed(translationElement);
162
+ promises.push(p.assignToElement(undefined, element));
163
+ });
164
+
165
+ return Promise.all(promises);
166
+ }
158
167
  }
@@ -29,89 +29,97 @@ export { Fetch };
29
29
  * @tutorial i18n-locale-and-formatter
30
30
  */
31
31
  class Fetch extends Provider {
32
- /**
33
- * As options the key `fetch` can be passed. This config object is passed to the fetch method as init.
34
- *
35
- * The url may contain placeholders (language, script, region, variants, extlang, privateUse), so you can specify one url for all translations.
36
- *
37
- * ```
38
- * new Fetch('https://www.example.com/assets/${language}.json')
39
- * ```
40
- *
41
- * @param {string|URL} url
42
- * @param {Object} options see {@link Monster.I18n.Providers.Fetch#defaults}
43
- * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/fetch}
44
- */
45
- constructor(url, options) {
46
- super(options);
32
+ /**
33
+ * As options the key `fetch` can be passed. This config object is passed to the fetch method as init.
34
+ *
35
+ * The url may contain placeholders (language, script, region, variants, extlang, privateUse), so you can specify one url for all translations.
36
+ *
37
+ * ```
38
+ * new Fetch('https://www.example.com/assets/${language}.json')
39
+ * ```
40
+ *
41
+ * @param {string|URL} url
42
+ * @param {Object} options see {@link Monster.I18n.Providers.Fetch#defaults}
43
+ * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/fetch}
44
+ */
45
+ constructor(url, options) {
46
+ super(options);
47
47
 
48
- if (isInstance(url, URL)) {
49
- url = url.toString();
50
- }
48
+ if (isInstance(url, URL)) {
49
+ url = url.toString();
50
+ }
51
51
 
52
- if (options === undefined) {
53
- options = {};
54
- }
52
+ if (options === undefined) {
53
+ options = {};
54
+ }
55
55
 
56
- validateString(url);
56
+ validateString(url);
57
57
 
58
- /**
59
- * @property {string}
60
- */
61
- this.url = url;
58
+ /**
59
+ * @property {string}
60
+ */
61
+ this.url = url;
62
62
 
63
- /**
64
- * @private
65
- * @property {Object} options
66
- */
67
- this[internalSymbol] = extend({}, super.defaults, this.defaults, validateObject(options));
68
- }
63
+ /**
64
+ * @private
65
+ * @property {Object} options
66
+ */
67
+ this[internalSymbol] = extend(
68
+ {},
69
+ super.defaults,
70
+ this.defaults,
71
+ validateObject(options),
72
+ );
73
+ }
69
74
 
70
- /**
71
- * Defaults
72
- *
73
- * @property {Object} fetch
74
- * @property {String} fetch.method=GET
75
- * @property {String} fetch.mode=cors
76
- * @property {String} fetch.cache=no-cache
77
- * @property {String} fetch.credentials=omit
78
- * @property {String} fetch.redirect=follow
79
- * @property {String} fetch.referrerPolicy=no-referrer
80
- *
81
- * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API}
82
- */
83
- get defaults() {
84
- return extend(
85
- {
86
- fetch: {
87
- method: "GET", // *GET, POST, PUT, DELETE, etc.
88
- mode: "cors", // no-cors, *cors, same-origin
89
- cache: "no-cache", // *default, no-cache, reload, force-cache, only-if-cached
90
- credentials: "omit", // include, *same-origin, omit
91
- redirect: "follow", // manual, *follow, error
92
- referrerPolicy: "no-referrer", // no-referrer, *no-referrer-when-downgrade, origin, origin-when-cross-origin, same-origin, strict-origin, strict-origin-when-cross-origin, unsafe-url
93
- },
94
- },
95
- super.defaults,
96
- );
97
- }
75
+ /**
76
+ * Defaults
77
+ *
78
+ * @property {Object} fetch
79
+ * @property {String} fetch.method=GET
80
+ * @property {String} fetch.mode=cors
81
+ * @property {String} fetch.cache=no-cache
82
+ * @property {String} fetch.credentials=omit
83
+ * @property {String} fetch.redirect=follow
84
+ * @property {String} fetch.referrerPolicy=no-referrer
85
+ *
86
+ * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API}
87
+ */
88
+ get defaults() {
89
+ return extend(
90
+ {
91
+ fetch: {
92
+ method: "GET", // *GET, POST, PUT, DELETE, etc.
93
+ mode: "cors", // no-cors, *cors, same-origin
94
+ cache: "no-cache", // *default, no-cache, reload, force-cache, only-if-cached
95
+ credentials: "omit", // include, *same-origin, omit
96
+ redirect: "follow", // manual, *follow, error
97
+ referrerPolicy: "no-referrer", // no-referrer, *no-referrer-when-downgrade, origin, origin-when-cross-origin, same-origin, strict-origin, strict-origin-when-cross-origin, unsafe-url
98
+ },
99
+ },
100
+ super.defaults,
101
+ );
102
+ }
98
103
 
99
- /**
100
- *
101
- * @param {Locale|string} locale
102
- * @return {Promise}
103
- */
104
- getTranslations(locale) {
105
- if (isString(locale)) {
106
- locale = parseLocale(locale);
107
- }
104
+ /**
105
+ *
106
+ * @param {Locale|string} locale
107
+ * @return {Promise}
108
+ */
109
+ getTranslations(locale) {
110
+ if (isString(locale)) {
111
+ locale = parseLocale(locale);
112
+ }
108
113
 
109
- let formatter = new Formatter(locale.getMap());
114
+ const formatter = new Formatter(locale.getMap());
110
115
 
111
- return getGlobalFunction("fetch")(formatter.format(this.url), this.getOption("fetch", {}))
112
- .then((response) => response.json())
113
- .then((data) => {
114
- return new Translations(locale).assignTranslations(data);
115
- });
116
- }
116
+ return getGlobalFunction("fetch")(
117
+ formatter.format(this.url),
118
+ this.getOption("fetch", {}),
119
+ )
120
+ .then((response) => response.json())
121
+ .then((data) => {
122
+ return new Translations(locale).assignTranslations(data);
123
+ });
124
+ }
117
125
  }