@schukai/monster 1.24.0 → 1.27.0

Sign up to get free protection for your applications and to get access to all the features.
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
@@ -0,0 +1,170 @@
1
+ 'use strict';
2
+
3
+ /**
4
+ * @author schukai GmbH
5
+ */
6
+
7
+ import {internalStateSymbol} from "../../constants.js";
8
+ import {extend} from "../../data/extend.js";
9
+ import {assignToNamespace, Monster} from "../../namespace.js";
10
+ import {getGlobalFunction} from "../../types/global.js";
11
+ import {
12
+ ATTRIBUTE_CLASS,
13
+ ATTRIBUTE_ERRORMESSAGE,
14
+ ATTRIBUTE_ID,
15
+ ATTRIBUTE_SRC,
16
+ ATTRIBUTE_TITLE,
17
+ ATTRIBUTE_TYPE,
18
+ TAG_SCRIPT
19
+ } from "../constants.js";
20
+ import {KEY_DOCUMENT, KEY_QUERY, referenceSymbol, Resource} from "../resource.js";
21
+
22
+
23
+ /**
24
+ * This class is used by the resource manager to embed data.
25
+ *
26
+ * You can call the method via the monster namespace `new Monster.DOM.Resource.Data()`.
27
+ *
28
+ * ```
29
+ * <script type="module">
30
+ * import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.27.0/dist/monster.js';
31
+ * new Monster.DOM.Resource.Data()
32
+ * </script>
33
+ * ```
34
+ *
35
+ * Alternatively, you can also integrate this function individually.
36
+ *
37
+ * ```
38
+ * <script type="module">
39
+ * import {Data} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.27.0/dist/modules/dom/resource/data.js';
40
+ * new Data()
41
+ * </script>
42
+ * ```
43
+ *
44
+ * @since 1.25.0
45
+ * @copyright schukai GmbH
46
+ * @memberOf Monster.DOM.Resource
47
+ * @summary A Data Resource class
48
+ */
49
+ class Data extends Resource {
50
+
51
+ /**
52
+ * @property {string} mode=cors https://developer.mozilla.org/en-US/docs/Web/API/fetch
53
+ * @property {string} credentials=same-origin https://developer.mozilla.org/en-US/docs/Web/API/fetch
54
+ * @property {string} type=application/json {@link https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script#attr-type}
55
+ */
56
+ get defaults() {
57
+ return extend({}, super.defaults, {
58
+ mode: 'cors',
59
+ credentials: 'same-origin',
60
+ type: 'application/json',
61
+ })
62
+ }
63
+
64
+ /**
65
+ *
66
+ * @return {Monster.DOM.Resource.Data}
67
+ */
68
+ create() {
69
+ createElement.call(this);
70
+ return this;
71
+ }
72
+
73
+ /**
74
+ * This method appends the HTMLElement to the specified document
75
+ *
76
+ * throws {Error} target not found
77
+ * @return {Monster.DOM.Resource}
78
+ */
79
+ connect() {
80
+
81
+ if (!(this[referenceSymbol] instanceof HTMLElement)) {
82
+ this.create();
83
+ }
84
+
85
+ appendToDocument.call(this);
86
+ return this;
87
+ }
88
+
89
+ /**
90
+ * @return {string}
91
+ */
92
+ static getURLAttribute() {
93
+ return ATTRIBUTE_SRC
94
+ }
95
+
96
+ }
97
+
98
+ /**
99
+ * @private
100
+ * @return {Monster.DOM.Resource.Data}
101
+ */
102
+ function createElement() {
103
+ const self = this;
104
+
105
+ const document = self.getOption(KEY_DOCUMENT);
106
+ self[referenceSymbol] = document.createElement(TAG_SCRIPT);
107
+
108
+ for (let key of [ATTRIBUTE_TYPE, ATTRIBUTE_ID, ATTRIBUTE_CLASS, ATTRIBUTE_TITLE]) {
109
+ if (self.getOption(key) !== undefined) {
110
+ self[referenceSymbol][key] = self.getOption(key);
111
+ }
112
+ }
113
+
114
+ return self;
115
+ }
116
+
117
+
118
+ /**
119
+ * @private
120
+ * @return {Promise}
121
+ * throws {Error} target not found
122
+ */
123
+ function appendToDocument() {
124
+ const self = this;
125
+
126
+ const targetNode = document.querySelector(self.getOption(KEY_QUERY, 'head'))
127
+ if (!(targetNode instanceof HTMLElement)) {
128
+ throw new Error('target not found')
129
+ }
130
+
131
+ targetNode.appendChild(self[referenceSymbol]);
132
+
133
+ getGlobalFunction('fetch')(self.getOption(ATTRIBUTE_SRC), {
134
+ method: 'GET', // *GET, POST, PUT, DELETE, etc.
135
+ mode: self.getOption('mode', 'cors'), // no-cors, *cors, same-origin
136
+ cache: 'no-cache', // *default, no-cache, reload, force-cache, only-if-cached
137
+ credentials: self.getOption('credentials', 'same-origin'), // include, *same-origin, omit
138
+ headers: {
139
+ 'Accept': self.getOption('type', 'application/json')
140
+ },
141
+ redirect: 'follow', // manual, *follow, error
142
+ referrerPolicy: 'no-referrer', // no-referrer,
143
+ }).then(response => {
144
+
145
+ return response.text()
146
+
147
+
148
+ }).then(text => {
149
+
150
+ const textNode = document.createTextNode(text);
151
+ self[referenceSymbol].appendChild(textNode);
152
+
153
+ self[internalStateSymbol].getSubject()['loaded'] = true;
154
+
155
+
156
+ }).catch(e => {
157
+ self[internalStateSymbol].setSubject({
158
+ loaded: true,
159
+ error: e.toString(),
160
+ })
161
+
162
+ targetNode.setAttribute(ATTRIBUTE_ERRORMESSAGE, e.toString());
163
+ })
164
+
165
+ return self;
166
+ }
167
+
168
+
169
+ assignToNamespace('Monster.DOM.Resource', Data);
170
+ export {Monster, Data}
@@ -0,0 +1,54 @@
1
+ 'use strict';
2
+
3
+ /**
4
+ * @author schukai GmbH
5
+ */
6
+
7
+ import {extend} from "../../../data/extend.js";
8
+ import {assignToNamespace, Monster} from "../../../namespace.js";
9
+ import {Link} from "../link.js";
10
+
11
+
12
+ /**
13
+ * This class is used by the resource manager to embed external resources.
14
+ *
15
+ * You can call the method via the monster namespace `new Monster.DOM.Resource.Link.Stylesheet()`.
16
+ *
17
+ * ```
18
+ * <script type="module">
19
+ * import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.27.0/dist/monster.js';
20
+ * new Monster.DOM.Resource.Link.Stylesheet()
21
+ * </script>
22
+ * ```
23
+ *
24
+ * Alternatively, you can also integrate this function individually.
25
+ *
26
+ * ```
27
+ * <script type="module">
28
+ * import {Style} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.27.0/dist/modules/dom/resource/link/stylesheet.js';
29
+ * new Stylesheet()
30
+ * </script>
31
+ * ```
32
+ *
33
+ * @since 1.25.0
34
+ * @copyright schukai GmbH
35
+ * @memberOf Monster.DOM.Resource
36
+ * @summary A Resource class
37
+ * @see https://developer.mozilla.org/en-US/docs/Web/HTML/Element/link
38
+ */
39
+ class Stylesheet extends Link {
40
+
41
+ /**
42
+ * @property {string} rel {@link https://developer.mozilla.org/en-US/docs/Web/HTML/Element/link#attr-rel}
43
+ */
44
+ get defaults() {
45
+ return extend({}, super.defaults, {
46
+ rel: 'stylesheet'
47
+ })
48
+ }
49
+
50
+ }
51
+
52
+
53
+ assignToNamespace('Monster.DOM.Resource.Link', Stylesheet);
54
+ export {Monster, Stylesheet}
@@ -0,0 +1,125 @@
1
+ 'use strict';
2
+
3
+ /**
4
+ * @author schukai GmbH
5
+ */
6
+
7
+ import {extend} from "../../data/extend.js";
8
+ import {assignToNamespace, Monster} from "../../namespace.js";
9
+ import {
10
+ ATTRIBUTE_CLASS,
11
+ ATTRIBUTE_HREF,
12
+ ATTRIBUTE_ID,
13
+ ATTRIBUTE_NONCE, ATTRIBUTE_SRC,
14
+ ATTRIBUTE_TITLE, ATTRIBUTE_TYPE,
15
+ TAG_LINK
16
+ } from "../constants.js";
17
+ import {KEY_DOCUMENT, referenceSymbol, Resource} from "../resource.js";
18
+
19
+
20
+ /**
21
+ * This class is used by the resource manager to embed external resources.
22
+ *
23
+ * You can call the method via the monster namespace `new Monster.DOM.Resource.Link()`.
24
+ *
25
+ * ```
26
+ * <script type="module">
27
+ * import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.27.0/dist/monster.js';
28
+ * new Monster.DOM.Resource.Link()
29
+ * </script>
30
+ * ```
31
+ *
32
+ * Alternatively, you can also integrate this function individually.
33
+ *
34
+ * ```
35
+ * <script type="module">
36
+ * import {Link} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.27.0/dist/modules/dom/resource/link.js';
37
+ * new Link()
38
+ * </script>
39
+ * ```
40
+ *
41
+ * @since 1.25.0
42
+ * @copyright schukai GmbH
43
+ * @memberOf Monster.DOM.Resource
44
+ * @summary A Resource class
45
+ * @see https://developer.mozilla.org/en-US/docs/Web/HTML/Element/link
46
+ */
47
+ class Link extends Resource {
48
+
49
+ /**
50
+ * @property {string} as {@link https://developer.mozilla.org/en-US/docs/Web/HTML/Element/link#attr-as}
51
+ * @property {string} crossOrigin=anonymous {@link https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script#attr-crossorigin}
52
+ * @property {boolean} disabled
53
+ * @property {string} href {@link https://developer.mozilla.org/en-US/docs/Web/HTML/Element/link#attr-href}
54
+ * @property {string} hreflang {@link https://developer.mozilla.org/en-US/docs/Web/HTML/Element/link#attr-hreflang}
55
+ * @property {string} imagesizes {@link https://developer.mozilla.org/en-US/docs/Web/HTML/Element/link#attr-imagesizes}
56
+ * @property {string} imagesrcset {@link https://developer.mozilla.org/en-US/docs/Web/HTML/Element/link#attr-imagesrcset}
57
+ * @property {string} integrity {@link https://developer.mozilla.org/en-US/docs/Web/HTML/Element/link#attr-integrity}
58
+ * @property {string} media {@link https://developer.mozilla.org/en-US/docs/Web/HTML/Element/link#attr-media}
59
+ * @property {string} prefetch {@link https://developer.mozilla.org/en-US/docs/Web/HTML/Element/link#attr-prefetch}
60
+ * @property {string} referrerpolicy {@link https://developer.mozilla.org/en-US/docs/Web/HTML/Element/link#attr-referrerpolicy}
61
+ * @property {string} rel {@link https://developer.mozilla.org/en-US/docs/Web/HTML/Element/link#attr-rel}
62
+ * @property {string} type {@link https://developer.mozilla.org/en-US/docs/Web/HTML/Element/link#attr-type}
63
+ * @property {string} sizes {@link https://developer.mozilla.org/en-US/docs/Web/HTML/Element/link#attr-sizes}
64
+ * @property {string} nonce {@link https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script#attr-nonce}
65
+ */
66
+ get defaults() {
67
+ return extend({}, super.defaults, {
68
+ as: undefined,
69
+ crossOrigin: 'anonymous',
70
+ disabled: undefined,
71
+ href: undefined,
72
+ hreflang: undefined,
73
+ imagesizes: undefined,
74
+ imagesrcset: undefined,
75
+ integrity: undefined,
76
+ media: undefined,
77
+ prefetch: undefined,
78
+ referrerpolicy: undefined,
79
+ rel: undefined,
80
+ sizes: undefined,
81
+ type: undefined,
82
+ nonce: undefined
83
+ })
84
+ }
85
+
86
+ /**
87
+ *
88
+ * @return {Monster.DOM.Resource.Link}
89
+ */
90
+ create() {
91
+ createElement.call(this);
92
+ return this;
93
+ }
94
+
95
+ /**
96
+ * @return {string}
97
+ */
98
+ static getURLAttribute() {
99
+ return ATTRIBUTE_HREF
100
+ }
101
+
102
+ }
103
+
104
+ /**
105
+ * @private
106
+ * @return {Monster.DOM.Resource.Link}
107
+ */
108
+ function createElement() {
109
+ const self = this;
110
+
111
+ const document = self.getOption(KEY_DOCUMENT);
112
+ self[referenceSymbol] = document.createElement(TAG_LINK);
113
+
114
+ for (let key of ['as','crossOrigin','disabled','href','hreflang','imagesizes','imagesrcset','integrity','media','prefetch','referrerpolicy','sizes','rel','type',ATTRIBUTE_HREF,ATTRIBUTE_ID,ATTRIBUTE_CLASS,ATTRIBUTE_TITLE,ATTRIBUTE_NONCE]) {
115
+ if (self.getOption(key) !== undefined) {
116
+ self[referenceSymbol][key] = self.getOption(key);
117
+ }
118
+ }
119
+
120
+ return self;
121
+ }
122
+
123
+
124
+ assignToNamespace('Monster.DOM.Resource', Link);
125
+ export {Monster, Link}
@@ -0,0 +1,112 @@
1
+ 'use strict';
2
+
3
+ /**
4
+ * @author schukai GmbH
5
+ */
6
+
7
+ import {extend} from "../../data/extend.js";
8
+ import {assignToNamespace, Monster} from "../../namespace.js";
9
+ import {
10
+ ATTRIBUTE_CLASS,
11
+ ATTRIBUTE_ID,
12
+ ATTRIBUTE_NONCE,
13
+ ATTRIBUTE_SRC,
14
+ ATTRIBUTE_TITLE,
15
+ ATTRIBUTE_TYPE,
16
+ TAG_SCRIPT
17
+ } from "../constants.js";
18
+ import {KEY_DOCUMENT, referenceSymbol, Resource} from "../resource.js";
19
+
20
+
21
+ /**
22
+ * This class is used by the resource manager to embed scripts.
23
+ *
24
+ * You can call the method via the monster namespace `new Monster.DOM.Resource.Script()`.
25
+ *
26
+ * ```
27
+ * <script type="module">
28
+ * import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.27.0/dist/monster.js';
29
+ * new Monster.DOM.Resource.Script()
30
+ * </script>
31
+ * ```
32
+ *
33
+ * Alternatively, you can also integrate this function individually.
34
+ *
35
+ * ```
36
+ * <script type="module">
37
+ * import {Script} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.27.0/dist/modules/dom/resource/script.js';
38
+ * new Script()
39
+ * </script>
40
+ * ```
41
+ *
42
+ * @since 1.25.0
43
+ * @copyright schukai GmbH
44
+ * @memberOf Monster.DOM.Resource
45
+ * @summary A Resource class
46
+ */
47
+ class Script extends Resource {
48
+
49
+ /**
50
+ * @property {boolean} async=true {@link https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script#attr-async}
51
+ * @property {string} crossOrigin=anonymous {@link https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script#attr-crossorigin}
52
+ * @property {boolean} defer=false {@link https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script#attr-defer}
53
+ * @property {string} integrity {@link https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script#attr-integrity}
54
+ * @property {boolean} nomodule {@link https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script#attr-nomodule}
55
+ * @property {string} nonce {@link https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script#attr-nonce}
56
+ * @property {string} referrerpolicy {@link https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script#attr-referrerpolicy}
57
+ * @property {string} type {@link https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script#attr-type}
58
+ */
59
+ get defaults() {
60
+ return extend({}, super.defaults, {
61
+ async: true,
62
+ crossOrigin: 'anonymous',
63
+ defer: false,
64
+ integrity: undefined,
65
+ nomodule: false,
66
+ nonce: undefined,
67
+ referrerpolicy: undefined,
68
+ type: 'text/javascript',
69
+ })
70
+ }
71
+
72
+ /**
73
+ *
74
+ * @return {Monster.DOM.Resource.Script}
75
+ */
76
+ create() {
77
+ createElement.call(this);
78
+ return this;
79
+ }
80
+
81
+ /**
82
+ * @return {string}
83
+ */
84
+ static getURLAttribute() {
85
+ return ATTRIBUTE_SRC
86
+ }
87
+
88
+ }
89
+
90
+ /**
91
+ * @private
92
+ * @return {Monster.DOM.Resource.Script}
93
+ */
94
+ function createElement() {
95
+ const self = this;
96
+
97
+ const document = self.getOption(KEY_DOCUMENT);
98
+ self[referenceSymbol] = document.createElement(TAG_SCRIPT);
99
+
100
+ for (let key of ['crossOrigin', 'defer', 'async', 'integrity', 'nomodule', ATTRIBUTE_NONCE, 'referrerpolicy', ATTRIBUTE_TYPE, ATTRIBUTE_SRC, ATTRIBUTE_ID, ATTRIBUTE_CLASS, ATTRIBUTE_TITLE]) {
101
+ if (self.getOption(key) !== undefined) {
102
+ self[referenceSymbol][key] = self.getOption(key);
103
+ }
104
+ }
105
+
106
+
107
+ return self;
108
+ }
109
+
110
+
111
+ assignToNamespace('Monster.DOM.Resource', Script);
112
+ export {Monster, Script}