@schukai/monster 1.24.0 → 1.27.0

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 (214) hide show
  1. package/CHANGELOG +47 -0
  2. package/README.md +4 -4
  3. package/dist/modules/constants.js +2 -2
  4. package/dist/modules/constraints/abstract.js +1 -1
  5. package/dist/modules/constraints/abstractoperator.js +1 -1
  6. package/dist/modules/constraints/andoperator.js +1 -1
  7. package/dist/modules/constraints/invalid.js +1 -1
  8. package/dist/modules/constraints/isarray.js +1 -1
  9. package/dist/modules/constraints/isobject.js +1 -1
  10. package/dist/modules/constraints/namespace.js +1 -1
  11. package/dist/modules/constraints/oroperator.js +1 -1
  12. package/dist/modules/constraints/valid.js +1 -1
  13. package/dist/modules/data/buildmap.js +2 -2
  14. package/dist/modules/data/buildtree.js +2 -0
  15. package/dist/modules/data/datasource/namespace.js +1 -1
  16. package/dist/modules/data/datasource/restapi/writeerror.js +1 -1
  17. package/dist/modules/data/datasource/restapi.js +1 -1
  18. package/dist/modules/data/datasource/storage/localstorage.js +1 -1
  19. package/dist/modules/data/datasource/storage/namespace.js +1 -1
  20. package/dist/modules/data/datasource/storage/sessionstorage.js +1 -1
  21. package/dist/modules/data/datasource/storage.js +1 -1
  22. package/dist/modules/data/datasource.js +1 -1
  23. package/dist/modules/data/diff.js +1 -1
  24. package/dist/modules/data/extend.js +1 -1
  25. package/dist/modules/data/namespace.js +1 -1
  26. package/dist/modules/data/pathfinder.js +1 -1
  27. package/dist/modules/data/pipe.js +1 -1
  28. package/dist/modules/data/transformer.js +2 -2
  29. package/dist/modules/dom/assembler.js +1 -1
  30. package/dist/modules/dom/attributes.js +2 -2
  31. package/dist/modules/dom/constants.js +2 -2
  32. package/dist/modules/dom/customcontrol.js +1 -1
  33. package/dist/modules/dom/customelement.js +1 -1
  34. package/dist/modules/dom/events.js +1 -1
  35. package/dist/modules/dom/focusmanager.js +2 -0
  36. package/dist/modules/dom/locale.js +1 -1
  37. package/dist/modules/dom/namespace.js +1 -1
  38. package/dist/modules/dom/resource/data.js +2 -0
  39. package/dist/modules/dom/resource/link/stylesheet.js +2 -0
  40. package/dist/modules/dom/resource/link.js +2 -0
  41. package/dist/modules/dom/resource/script.js +2 -0
  42. package/dist/modules/dom/resource.js +2 -0
  43. package/dist/modules/dom/resourcemanager.js +2 -0
  44. package/dist/modules/dom/template.js +2 -2
  45. package/dist/modules/dom/theme.js +1 -1
  46. package/dist/modules/dom/updater.js +2 -2
  47. package/dist/modules/dom/util.js +1 -1
  48. package/dist/modules/dom/worker/factory.js +2 -0
  49. package/dist/modules/i18n/formatter.js +2 -0
  50. package/dist/modules/i18n/locale.js +1 -1
  51. package/dist/modules/i18n/namespace.js +1 -1
  52. package/dist/modules/i18n/provider.js +1 -1
  53. package/dist/modules/i18n/providers/fetch.js +1 -1
  54. package/dist/modules/i18n/providers/namespace.js +1 -1
  55. package/dist/modules/i18n/translations.js +1 -1
  56. package/dist/modules/logging/handler/console.js +1 -1
  57. package/dist/modules/logging/handler/namespace.js +1 -1
  58. package/dist/modules/logging/handler.js +1 -1
  59. package/dist/modules/logging/logentry.js +1 -1
  60. package/dist/modules/logging/logger.js +1 -1
  61. package/dist/modules/logging/namespace.js +1 -1
  62. package/dist/modules/math/namespace.js +1 -1
  63. package/dist/modules/math/random.js +2 -2
  64. package/dist/modules/monster.js +1 -1
  65. package/dist/modules/namespace.js +1 -1
  66. package/dist/modules/text/formatter.js +2 -2
  67. package/dist/modules/text/namespace.js +1 -1
  68. package/dist/modules/types/base.js +1 -1
  69. package/dist/modules/types/basewithoptions.js +1 -1
  70. package/dist/modules/types/binary.js +1 -1
  71. package/dist/modules/types/dataurl.js +1 -1
  72. package/dist/modules/types/global.js +1 -1
  73. package/dist/modules/types/id.js +1 -1
  74. package/dist/modules/types/is.js +2 -2
  75. package/dist/modules/types/mediatype.js +1 -1
  76. package/dist/modules/types/namespace.js +1 -1
  77. package/dist/modules/types/node.js +2 -0
  78. package/dist/modules/types/nodelist.js +2 -0
  79. package/dist/modules/types/noderecursiveiterator.js +2 -0
  80. package/dist/modules/types/observer.js +1 -1
  81. package/dist/modules/types/observerlist.js +1 -1
  82. package/dist/modules/types/proxyobserver.js +1 -1
  83. package/dist/modules/types/queue.js +1 -1
  84. package/dist/modules/types/randomid.js +1 -1
  85. package/dist/modules/types/regex.js +2 -0
  86. package/dist/modules/types/stack.js +1 -1
  87. package/dist/modules/types/tokenlist.js +1 -1
  88. package/dist/modules/types/typeof.js +1 -1
  89. package/dist/modules/types/uniquequeue.js +1 -1
  90. package/dist/modules/types/uuid.js +2 -0
  91. package/dist/modules/types/validate.js +1 -1
  92. package/dist/modules/types/version.js +2 -2
  93. package/dist/modules/util/clone.js +1 -1
  94. package/dist/modules/util/comparator.js +1 -1
  95. package/dist/modules/util/freeze.js +1 -1
  96. package/dist/modules/util/namespace.js +1 -1
  97. package/dist/modules/util/processing.js +1 -1
  98. package/dist/modules/util/trimspaces.js +1 -1
  99. package/dist/monster.dev.js +1528 -770
  100. package/dist/monster.dev.js.map +1 -1
  101. package/dist/monster.js +2 -2
  102. package/package.json +13 -2
  103. package/source/constants.js +11 -2
  104. package/source/constraints/abstract.js +5 -0
  105. package/source/constraints/abstractoperator.js +5 -0
  106. package/source/constraints/andoperator.js +10 -5
  107. package/source/constraints/invalid.js +8 -3
  108. package/source/constraints/isarray.js +9 -4
  109. package/source/constraints/isobject.js +8 -3
  110. package/source/constraints/oroperator.js +10 -5
  111. package/source/constraints/valid.js +8 -3
  112. package/source/data/buildmap.js +25 -9
  113. package/source/data/buildtree.js +95 -0
  114. package/source/data/datasource/restapi.js +3 -3
  115. package/source/data/datasource/storage/localstorage.js +2 -2
  116. package/source/data/datasource/storage/sessionstorage.js +2 -2
  117. package/source/data/datasource/storage.js +3 -3
  118. package/source/data/datasource.js +3 -3
  119. package/source/data/diff.js +3 -3
  120. package/source/data/extend.js +2 -2
  121. package/source/data/pathfinder.js +4 -4
  122. package/source/data/pipe.js +3 -3
  123. package/source/data/transformer.js +7 -5
  124. package/source/dom/assembler.js +2 -2
  125. package/source/dom/attributes.js +111 -28
  126. package/source/dom/constants.js +287 -10
  127. package/source/dom/customcontrol.js +1 -1
  128. package/source/dom/customelement.js +1 -1
  129. package/source/dom/events.js +6 -7
  130. package/source/dom/focusmanager.js +250 -0
  131. package/source/dom/locale.js +10 -5
  132. package/source/dom/resource/data.js +170 -0
  133. package/source/dom/resource/link/stylesheet.js +54 -0
  134. package/source/dom/resource/link.js +125 -0
  135. package/source/dom/resource/script.js +112 -0
  136. package/source/dom/resource.js +268 -0
  137. package/source/dom/resourcemanager.js +214 -0
  138. package/source/dom/template.js +86 -16
  139. package/source/dom/theme.js +3 -3
  140. package/source/dom/updater.js +138 -90
  141. package/source/dom/util.js +6 -6
  142. package/source/dom/worker/factory.js +134 -0
  143. package/source/i18n/formatter.js +140 -0
  144. package/source/i18n/locale.js +6 -4
  145. package/source/i18n/provider.js +2 -2
  146. package/source/i18n/providers/fetch.js +18 -3
  147. package/source/i18n/translations.js +18 -9
  148. package/source/logging/handler/console.js +2 -2
  149. package/source/logging/handler.js +2 -2
  150. package/source/logging/logentry.js +2 -2
  151. package/source/logging/logger.js +2 -2
  152. package/source/math/random.js +9 -5
  153. package/source/namespace.js +1 -1
  154. package/source/text/formatter.js +190 -48
  155. package/source/types/base.js +4 -4
  156. package/source/types/basewithoptions.js +2 -2
  157. package/source/types/binary.js +4 -4
  158. package/source/types/dataurl.js +4 -4
  159. package/source/types/global.js +4 -4
  160. package/source/types/id.js +6 -3
  161. package/source/types/is.js +103 -85
  162. package/source/types/mediatype.js +4 -4
  163. package/source/types/node.js +179 -0
  164. package/source/types/nodelist.js +125 -0
  165. package/source/types/noderecursiveiterator.js +126 -0
  166. package/source/types/observer.js +3 -3
  167. package/source/types/observerlist.js +2 -2
  168. package/source/types/proxyobserver.js +5 -5
  169. package/source/types/queue.js +4 -4
  170. package/source/types/randomid.js +2 -2
  171. package/source/types/regex.js +49 -0
  172. package/source/types/stack.js +2 -2
  173. package/source/types/tokenlist.js +2 -2
  174. package/source/types/typeof.js +3 -3
  175. package/source/types/uniquequeue.js +2 -2
  176. package/source/types/uuid.js +102 -0
  177. package/source/types/validate.js +20 -20
  178. package/source/types/version.js +6 -6
  179. package/source/util/clone.js +2 -2
  180. package/source/util/comparator.js +4 -4
  181. package/source/util/freeze.js +5 -5
  182. package/source/util/processing.js +3 -3
  183. package/source/util/trimspaces.js +3 -3
  184. package/test/cases/data/buildtree.js +149 -0
  185. package/test/cases/data/datasource/restapi.js +1 -1
  186. package/test/cases/data/transformer.js +2 -0
  187. package/test/cases/dom/attributes.js +46 -19
  188. package/test/cases/dom/customelement.js +0 -3
  189. package/test/cases/dom/focusmanager.js +111 -0
  190. package/test/cases/dom/locale.js +1 -4
  191. package/test/cases/dom/resource/data.js +129 -0
  192. package/test/cases/dom/resource/link/stylesheet.js +101 -0
  193. package/test/cases/dom/resource/link.js +101 -0
  194. package/test/cases/dom/resource/script.js +115 -0
  195. package/test/cases/dom/resourcemanager.js +118 -0
  196. package/test/cases/dom/template.js +72 -14
  197. package/test/cases/dom/updater.js +102 -75
  198. package/test/cases/dom/worker/factory.js +63 -0
  199. package/test/cases/i18n/formatter.js +66 -0
  200. package/test/cases/monster.js +1 -1
  201. package/test/cases/text/formatter.js +36 -5
  202. package/test/cases/types/node.js +196 -0
  203. package/test/cases/types/nodelist.js +64 -0
  204. package/test/cases/types/noderecursiveiterator.js +54 -0
  205. package/test/cases/types/regex.js +32 -0
  206. package/test/cases/types/uuid.js +42 -0
  207. package/test/cases/util/freeze.js +30 -4
  208. package/test/util/cleanupdom.js +48 -0
  209. package/test/util/jsdom.js +22 -9
  210. package/test/web/import.js +14 -0
  211. package/test/web/monster-dev.html +3 -3
  212. package/test/web/monster.html +2 -2
  213. package/test/web/test.html +3 -3
  214. package/test/web/tests.js +7 -7
@@ -5,29 +5,29 @@ import {Monster} from '../namespace.js';
5
5
  * @author schukai GmbH
6
6
  */
7
7
 
8
+
8
9
  /**
10
+ * default theme
9
11
  * @memberOf Monster.DOM
10
- * @since 1.8.0
11
12
  * @type {string}
12
13
  */
13
- const ATTRIBUTE_PREFIX = 'data-monster-';
14
+ const DEFAULT_THEME = 'monster';
14
15
 
15
16
  /**
16
- * This is the name of the attribute to pass options to a control
17
- *
18
17
  * @memberOf Monster.DOM
19
18
  * @since 1.8.0
20
19
  * @type {string}
21
20
  */
22
- const ATTRIBUTE_OPTIONS = ATTRIBUTE_PREFIX + 'options';
23
-
21
+ const ATTRIBUTE_PREFIX = 'data-monster-';
24
22
 
25
23
  /**
26
- * default theme
24
+ * This is the name of the attribute to pass options to a control
25
+ *
27
26
  * @memberOf Monster.DOM
27
+ * @since 1.8.0
28
28
  * @type {string}
29
29
  */
30
- const DEFAULT_THEME = 'monster';
30
+ const ATTRIBUTE_OPTIONS = ATTRIBUTE_PREFIX + 'options';
31
31
 
32
32
  /**
33
33
  * @memberOf Monster.DOM
@@ -84,6 +84,13 @@ const ATTRIBUTE_UPDATER_REMOVE = ATTRIBUTE_PREFIX + 'remove';
84
84
  */
85
85
  const ATTRIBUTE_UPDATER_BIND = ATTRIBUTE_PREFIX + 'bind';
86
86
 
87
+ /**
88
+ * @memberOf Monster.DOM
89
+ * @type {string}
90
+ * @since 1.27.0
91
+ */
92
+ const ATTRIBUTE_TEMPLATE_PREFIX = ATTRIBUTE_PREFIX + 'template-prefix';
93
+
87
94
  /**
88
95
  * @memberOf Monster.DOM
89
96
  * @type {string}
@@ -126,9 +133,278 @@ const ATTRIBUTE_ERRORMESSAGE = ATTRIBUTE_PREFIX + 'error';
126
133
  */
127
134
  const objectUpdaterLinkSymbol = Symbol('monsterUpdater');
128
135
 
136
+ /**
137
+ * @memberOf Monster.DOM
138
+ * @type {string}
139
+ * @since 1.25.0
140
+ */
141
+ const TAG_SCRIPT = 'script';
142
+
143
+ /**
144
+ * @memberOf Monster.DOM
145
+ * @type {string}
146
+ * @since 1.25.0
147
+ */
148
+ const TAG_STYLE = 'style';
149
+
150
+ /**
151
+ * @memberOf Monster.DOM
152
+ * @type {string}
153
+ * @since 1.25.0
154
+ */
155
+ const TAG_LINK = 'link';
156
+
157
+ /**
158
+ * @memberOf Monster.DOM
159
+ * @type {string}
160
+ * @since 1.25.0
161
+ */
162
+
163
+ const ATTRIBUTE_ID = 'id';
164
+
165
+ /**
166
+ * @memberOf Monster.DOM
167
+ * @type {string}
168
+ * @since 1.25.0
169
+ */
170
+
171
+ const ATTRIBUTE_CLASS = 'class';
172
+
173
+ /**
174
+ * @memberOf Monster.DOM
175
+ * @type {string}
176
+ * @since 1.25.0
177
+ */
178
+ const ATTRIBUTE_TITLE = 'title';
179
+
180
+ /**
181
+ * @memberOf Monster.DOM
182
+ * @type {string}
183
+ * @since 1.25.0
184
+ */
185
+ const ATTRIBUTE_SRC = 'src';
186
+ /**
187
+ * @memberOf Monster.DOM
188
+ * @type {string}
189
+ * @since 1.25.0
190
+ */
191
+ const ATTRIBUTE_HREF = 'href';
192
+
193
+ /**
194
+ * @memberOf Monster.DOM
195
+ * @type {string}
196
+ * @since 1.25.0
197
+ */
198
+ const ATTRIBUTE_TYPE = 'type';
199
+
200
+ /**
201
+ * @memberOf Monster.DOM
202
+ * @type {string}
203
+ * @since 1.25.0
204
+ */
205
+ const ATTRIBUTE_NONCE = 'nonce';
206
+
207
+ /**
208
+ * @memberOf Monster.DOM
209
+ * @type {string}
210
+ * @since 1.25.0
211
+ */
212
+ const ATTRIBUTE_TRANSLATE = 'translate';
213
+
214
+
215
+ /**
216
+ * @memberOf Monster.DOM
217
+ * @type {string}
218
+ * @since 1.25.0
219
+ */
220
+ const ATTRIBUTE_TABINDEX = 'tabindex';
221
+
222
+
223
+ /**
224
+ * @memberOf Monster.DOM
225
+ * @type {string}
226
+ * @since 1.25.0
227
+ */
228
+ const ATTRIBUTE_SPELLCHECK = 'spellcheck';
229
+
230
+
231
+ /**
232
+ * @memberOf Monster.DOM
233
+ * @type {string}
234
+ * @since 1.25.0
235
+ */
236
+ const ATTRIBUTE_SLOT = 'slot';
237
+
238
+
239
+ /**
240
+ * @memberOf Monster.DOM
241
+ * @type {string}
242
+ * @since 1.25.0
243
+ */
244
+ const ATTRIBUTE_PART = 'part';
245
+
246
+
247
+ /**
248
+ * @memberOf Monster.DOM
249
+ * @type {string}
250
+ * @since 1.25.0
251
+ */
252
+ const ATTRIBUTE_LANG = 'lang';
253
+
254
+
255
+ /**
256
+ * @memberOf Monster.DOM
257
+ * @type {string}
258
+ * @since 1.25.0
259
+ */
260
+ const ATTRIBUTE_ITEMTYPE = 'itemtype';
261
+
262
+
263
+ /**
264
+ * @memberOf Monster.DOM
265
+ * @type {string}
266
+ * @since 1.25.0
267
+ */
268
+ const ATTRIBUTE_ITEMSCOPE = 'itemscope';
269
+
270
+
271
+ /**
272
+ * @memberOf Monster.DOM
273
+ * @type {string}
274
+ * @since 1.25.0
275
+ */
276
+ const ATTRIBUTE_ITEMREF = 'itemref';
277
+
278
+
279
+ /**
280
+ * @memberOf Monster.DOM
281
+ * @type {string}
282
+ * @since 1.25.0
283
+ */
284
+ const ATTRIBUTE_ITEMID = 'itemid';
285
+
286
+
287
+ /**
288
+ * @memberOf Monster.DOM
289
+ * @type {string}
290
+ * @since 1.25.0
291
+ */
292
+ const ATTRIBUTE_ITEMPROP = 'itemprop';
293
+
294
+
295
+ /**
296
+ * @memberOf Monster.DOM
297
+ * @type {string}
298
+ * @since 1.25.0
299
+ */
300
+ const ATTRIBUTE_IS = 'is';
301
+
302
+
303
+ /**
304
+ * @memberOf Monster.DOM
305
+ * @type {string}
306
+ * @since 1.25.0
307
+ */
308
+ const ATTRIBUTE_INPUTMODE = 'inputmode';
309
+
310
+
311
+ /**
312
+ * @memberOf Monster.DOM
313
+ * @type {string}
314
+ * @since 1.25.0
315
+ */
316
+ const ATTRIBUTE_ACCESSKEY = 'accesskey';
317
+
318
+ /**
319
+ * @memberOf Monster.DOM
320
+ * @type {string}
321
+ * @since 1.25.0
322
+ */
323
+ const ATTRIBUTE_AUTOCAPITALIZE = 'autocapitalize';
324
+
325
+ /**
326
+ * @memberOf Monster.DOM
327
+ * @type {string}
328
+ * @since 1.25.0
329
+ */
330
+ const ATTRIBUTE_AUTOFOCUS = 'autofocus';
331
+
332
+ /**
333
+ * @memberOf Monster.DOM
334
+ * @type {string}
335
+ * @since 1.25.0
336
+ */
337
+ const ATTRIBUTE_CONTENTEDITABLE = 'contenteditable';
338
+
339
+ /**
340
+ * @memberOf Monster.DOM
341
+ * @type {string}
342
+ * @since 1.25.0
343
+ */
344
+ const ATTRIBUTE_DIR = 'dir';
345
+
346
+ /**
347
+ * @memberOf Monster.DOM
348
+ * @type {string}
349
+ * @since 1.25.0
350
+ */
351
+ const ATTRIBUTE_DRAGGABLE = 'draggable';
352
+
353
+
354
+ /**
355
+ * @memberOf Monster.DOM
356
+ * @type {string}
357
+ * @since 1.25.0
358
+ */
359
+ const ATTRIBUTE_ENTERKEYHINT = 'enterkeyhint';
360
+ /**
361
+ * @memberOf Monster.DOM
362
+ * @type {string}
363
+ * @since 1.25.0
364
+ */
365
+ const ATTRIBUTE_EXPORTPARTS = 'exportparts';
366
+ /**
367
+ * @memberOf Monster.DOM
368
+ * @type {string}
369
+ * @since 1.25.0
370
+ */
371
+ const ATTRIBUTE_HIDDEN = 'hidden';
372
+
129
373
 
130
374
  export {
131
375
  Monster,
376
+ ATTRIBUTE_HIDDEN,
377
+ ATTRIBUTE_EXPORTPARTS,
378
+ ATTRIBUTE_ENTERKEYHINT,
379
+ ATTRIBUTE_DRAGGABLE,
380
+ ATTRIBUTE_DIR,
381
+ ATTRIBUTE_CONTENTEDITABLE,
382
+ ATTRIBUTE_AUTOFOCUS,
383
+ ATTRIBUTE_AUTOCAPITALIZE,
384
+ ATTRIBUTE_ACCESSKEY,
385
+ TAG_SCRIPT,
386
+ TAG_LINK,
387
+ ATTRIBUTE_INPUTMODE,
388
+ ATTRIBUTE_IS,
389
+ ATTRIBUTE_ITEMPROP,
390
+ ATTRIBUTE_ITEMID,
391
+ ATTRIBUTE_ITEMREF,
392
+ ATTRIBUTE_ITEMSCOPE,
393
+ TAG_STYLE,
394
+ ATTRIBUTE_ITEMTYPE,
395
+ ATTRIBUTE_HREF,
396
+ ATTRIBUTE_LANG,
397
+ ATTRIBUTE_PART,
398
+ ATTRIBUTE_SLOT,
399
+ ATTRIBUTE_SPELLCHECK,
400
+ ATTRIBUTE_SRC,
401
+ ATTRIBUTE_TABINDEX,
402
+ ATTRIBUTE_TRANSLATE,
403
+ ATTRIBUTE_NONCE,
404
+ ATTRIBUTE_TYPE,
405
+ ATTRIBUTE_TITLE,
406
+ ATTRIBUTE_CLASS,
407
+ ATTRIBUTE_ID,
132
408
  ATTRIBUTE_PREFIX,
133
409
  ATTRIBUTE_OPTIONS,
134
410
  DEFAULT_THEME,
@@ -145,5 +421,6 @@ export {
145
421
  ATTRIBUTE_DISABLED,
146
422
  ATTRIBUTE_ERRORMESSAGE,
147
423
  ATTRIBUTE_VALUE,
148
- objectUpdaterLinkSymbol
149
- }
424
+ objectUpdaterLinkSymbol,
425
+ ATTRIBUTE_TEMPLATE_PREFIX
426
+ }
@@ -30,7 +30,7 @@ const attachedInternalSymbol = Symbol('attachedInternal');
30
30
  *
31
31
  * ```
32
32
  * <script type="module">
33
- * import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.24.0/dist/modules/dom/customcontrol.js';
33
+ * import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.27.0/dist/monster.js';
34
34
  * document.createElement('monster-')
35
35
  * </script>
36
36
  * ```
@@ -96,7 +96,7 @@ const attributeObserverSymbol = Symbol('attributeObserver');
96
96
  *
97
97
  * ```
98
98
  * <script type="module">
99
- * import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.24.0/dist/modules/dom/customelement.js';
99
+ * import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.27.0/dist/monster.js';
100
100
  * document.createElement('monster-')
101
101
  * </script>
102
102
  * ```
@@ -13,7 +13,7 @@ import {getDocument} from "./util.js";
13
13
  *
14
14
  * ```
15
15
  * <script type="module">
16
- * import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.24.0/dist/modules/dom/events.js';
16
+ * import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.27.0/dist/monster.js';
17
17
  * console.log(new Monster.DOM.fireEvent())
18
18
  * </script>
19
19
  * ```
@@ -22,7 +22,7 @@ import {getDocument} from "./util.js";
22
22
  *
23
23
  * ```
24
24
  * <script type="module">
25
- * import {fireEvent} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.24.0/dist/modules/dom/events.js';
25
+ * import {fireEvent} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.27.0/dist/modules/dom/events.js';
26
26
  * console.log(fireEvent())
27
27
  * </script>
28
28
  * ```
@@ -73,8 +73,8 @@ function fireEvent(element, type) {
73
73
  *
74
74
  * ```
75
75
  * <script type="module">
76
- * import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.24.0/dist/modules/dom/events.js';
77
- * console.log(new Monster.DOM.findTargetElementFromEvent())
76
+ * import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.27.0/dist/monster.js';
77
+ * new Monster.DOM.findTargetElementFromEvent()
78
78
  * </script>
79
79
  * ```
80
80
  *
@@ -82,8 +82,8 @@ function fireEvent(element, type) {
82
82
  *
83
83
  * ```
84
84
  * <script type="module">
85
- * import {findTargetElementFromEvent} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.24.0/dist/modules/dom/events.js';
86
- * console.log(findTargetElementFromEvent())
85
+ * import {findTargetElementFromEvent} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.27.0/dist/modules/dom/events.js';
86
+ * findTargetElementFromEvent()
87
87
  * </script>
88
88
  * ```
89
89
  *
@@ -105,7 +105,6 @@ function findTargetElementFromEvent(event, attributeName, attributeValue) {
105
105
  }
106
106
 
107
107
  const path = event.composedPath();
108
- const element = path?.[0];
109
108
 
110
109
  // closest cannot be used here, because closest is not correct for slotted elements
111
110
  if (isArray(path)) {
@@ -0,0 +1,250 @@
1
+ 'use strict';
2
+
3
+
4
+ /**
5
+ * @author schukai GmbH
6
+ */
7
+
8
+
9
+ import {extend} from "../data/extend.js";
10
+ import {assignToNamespace} from "../namespace.js";
11
+ import {BaseWithOptions} from "../types/basewithoptions.js";
12
+ import {getGlobalObject} from "../types/global.js";
13
+ import {isArray} from "../types/is.js";
14
+ import {Stack} from "../types/stack.js";
15
+ import {validateInstance, validateString} from "../types/validate.js";
16
+
17
+ /**
18
+ * @private
19
+ * @type {string}
20
+ */
21
+ const KEY_DOCUMENT = 'document';
22
+
23
+ /**
24
+ * @private
25
+ * @type {string}
26
+ */
27
+ const KEY_CONTEXT = 'context';
28
+
29
+
30
+ /**
31
+ * @private
32
+ * @type {Symbol}
33
+ */
34
+ const stackSymbol = Symbol('stack');
35
+
36
+
37
+ /**
38
+ * With the focusmanager the focus can be stored in a document, recalled and moved.
39
+ *
40
+ * You can create the object via the monster namespace `new Monster.DOM.FocusManager()`.
41
+ *
42
+ * ```
43
+ * <script type="module">
44
+ * import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.27.0/dist/monster.js';
45
+ * new Monster.DOM.FocusManager()
46
+ * </script>
47
+ * ```
48
+ *
49
+ * Alternatively, you can also integrate this object individually.
50
+ *
51
+ * ```
52
+ * <script type="module">
53
+ * import {FocusManager} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.27.0/dist/modules/dom/focusmanager.js';
54
+ * new FocusManager()
55
+ * </script>
56
+ * ```
57
+ *
58
+ * @since 1.25.0
59
+ * @copyright schukai GmbH
60
+ * @memberOf Monster.DOM
61
+ * @throws {Error} unsupported locale
62
+ * @summary Handle the focus
63
+ */
64
+ class FocusManager extends BaseWithOptions {
65
+
66
+ /**
67
+ *
68
+ * @param {Object|undefined} options
69
+ */
70
+ constructor(options) {
71
+ super(options);
72
+ validateInstance(this.getOption(KEY_DOCUMENT), HTMLDocument);
73
+
74
+ this[stackSymbol] = new Stack();
75
+ }
76
+
77
+ /**
78
+ * @property {HTMLDocument} document the document object into which the node is to be appended
79
+ */
80
+ get defaults() {
81
+ return extend({}, super.defaults, {
82
+ [KEY_DOCUMENT]: getGlobalObject('document'),
83
+ [KEY_CONTEXT]: undefined,
84
+ })
85
+ }
86
+
87
+ /**
88
+ * Remembers the current focus on a stack.
89
+ * Several focus can be stored.
90
+ *
91
+ * @return {Monster.DOM.FocusManager}
92
+ */
93
+ storeFocus() {
94
+
95
+ const active = this.getActive();
96
+ if (active instanceof Node) {
97
+ this[stackSymbol].push(active)
98
+ }
99
+ return this;
100
+ }
101
+
102
+ /**
103
+ * The last focus on the stack is set again
104
+ *
105
+ * @return {Monster.DOM.FocusManager}
106
+ */
107
+ restoreFocus() {
108
+
109
+ const last = this[stackSymbol].pop();
110
+ if (last instanceof Node) {
111
+ this.focus(last);
112
+ }
113
+
114
+ return this;
115
+ }
116
+
117
+ /**
118
+ *
119
+ * @param {Node} element
120
+ * @param {boolean} preventScroll
121
+ * @throws {TypeError} value is not an instance of
122
+ * @return {Monster.DOM.FocusManager}
123
+ */
124
+ focus(element, preventScroll) {
125
+
126
+ validateInstance(element, Node)
127
+
128
+ element.focus({
129
+ preventScroll: preventScroll ?? false
130
+ })
131
+
132
+ return this;
133
+ }
134
+
135
+ /**
136
+ *
137
+ * @return {Element}
138
+ */
139
+ getActive() {
140
+ return this.getOption(KEY_DOCUMENT).activeElement;
141
+ }
142
+
143
+ /**
144
+ * Select all elements that can be focused
145
+ *
146
+ * @param {string|undefined} query
147
+ * @return {array}
148
+ * @throws {TypeError} value is not an instance of
149
+ */
150
+ getFocusable(query) {
151
+
152
+ let contextElement = this.getOption(KEY_CONTEXT);
153
+ if (contextElement === undefined) {
154
+ contextElement = this.getOption(KEY_DOCUMENT);
155
+ }
156
+
157
+ validateInstance(contextElement, Node)
158
+
159
+ if (query !== undefined) {
160
+ validateString(query);
161
+ }
162
+
163
+ return [...contextElement.querySelectorAll(
164
+ 'details, button, input, [tabindex]:not([tabindex="-1"]), select, textarea, a[href], body'
165
+ )].filter((element) => {
166
+
167
+ if (query !== undefined && !element.matches(query)) {
168
+ return false;
169
+ }
170
+
171
+ if (element.hasAttribute('disabled')) return false;
172
+ if (element.getAttribute("aria-hidden") === 'true') return false;
173
+
174
+ const rect = element.getBoundingClientRect();
175
+ if(rect.width===0) return false;
176
+ if(rect.height===0) return false;
177
+
178
+ return true;
179
+ });
180
+ }
181
+
182
+ /**
183
+ * @param {string} query
184
+ * @return {Monster.DOM.FocusManager}
185
+ */
186
+ focusNext(query) {
187
+
188
+ const current = this.getActive();
189
+ const focusable = this.getFocusable(query);
190
+
191
+ if (!isArray(focusable) || focusable.length === 0) {
192
+ return this;
193
+ }
194
+
195
+ if (current instanceof Node) {
196
+ let index = focusable.indexOf(current);
197
+
198
+ if (index > -1) {
199
+ this.focus(focusable[index + 1] || focusable[0]);
200
+ } else {
201
+ this.focus(focusable[0]);
202
+ }
203
+ } else {
204
+ this.focus(focusable[0])
205
+ }
206
+
207
+ return this;
208
+ }
209
+
210
+ /**
211
+ * @param {string} query
212
+ * @return {Monster.DOM.FocusManager}
213
+ */
214
+ focusPrev(query) {
215
+
216
+ const current = this.getActive();
217
+ const focusable = this.getFocusable(query);
218
+
219
+ if (!isArray(focusable) || focusable.length === 0) {
220
+ return this;
221
+ }
222
+
223
+ if (current instanceof Node) {
224
+ let index = focusable.indexOf(current);
225
+
226
+ if (index > -1) {
227
+ this.focus(focusable[index - 1] || focusable[focusable.length - 1]);
228
+ } else {
229
+ this.focus(focusable[focusable.length - 1]);
230
+ }
231
+ } else {
232
+ this.focus(focusable[focusable.length - 1])
233
+ }
234
+
235
+ return this;
236
+ }
237
+
238
+
239
+ }
240
+
241
+
242
+ assignToNamespace('Monster.DOM', FocusManager);
243
+ export {FocusManager}
244
+
245
+
246
+
247
+
248
+
249
+
250
+
@@ -1,9 +1,10 @@
1
1
  'use strict';
2
2
 
3
- import {parseLocale} from "../i18n/locale.js";
4
3
  /**
5
4
  * @author schukai GmbH
6
5
  */
6
+
7
+ import {parseLocale} from "../i18n/locale.js";
7
8
  import {assignToNamespace, Monster} from '../namespace.js';
8
9
  import {getDocument} from "./util.js";
9
10
 
@@ -16,13 +17,17 @@ const DEFAULT_LANGUAGE = 'en';
16
17
  /**
17
18
  * With this function you can read the language version set by the document.
18
19
  * For this the attribute `lang` in the html tag is read. If no attribute is set, `en` is used as default.
20
+ *
21
+ * ```html
22
+ * <html lang="en">
23
+ * ```
19
24
  *
20
25
  * You can call the function via the monster namespace `new Monster.DOM.getLocaleOfDocument()`.
21
26
  *
22
27
  * ```
23
28
  * <script type="module">
24
- * import {getLocaleOfDocument} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.24.0/dist/modules/dom/locale.js';
25
- * console.log(new Monster.DOM.getLocaleOfDocument())
29
+ * import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.27.0/dist/monster.js';
30
+ * new Monster.DOM.getLocaleOfDocument()
26
31
  * </script>
27
32
  * ```
28
33
  *
@@ -30,8 +35,8 @@ const DEFAULT_LANGUAGE = 'en';
30
35
  *
31
36
  * ```
32
37
  * <script type="module">
33
- * import {getLocaleOfDocument} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.24.0/dist/modules/dom/locale.js';
34
- * console.log(new getLocaleOfDocument())
38
+ * import {getLocaleOfDocument} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.27.0/dist/modules/dom/locale.js';
39
+ * new getLocaleOfDocument()
35
40
  * </script>
36
41
  * ```
37
42
  *