@schukai/monster 3.5.0 → 3.7.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 (106) hide show
  1. package/package.json +1 -1
  2. package/source/constants.mjs +4 -9
  3. package/source/constraints/abstract.mjs +4 -6
  4. package/source/constraints/abstractoperator.mjs +6 -12
  5. package/source/constraints/andoperator.mjs +3 -6
  6. package/source/constraints/invalid.mjs +3 -6
  7. package/source/constraints/isarray.mjs +6 -9
  8. package/source/constraints/isobject.mjs +4 -7
  9. package/source/constraints/namespace.mjs +1 -3
  10. package/source/constraints/oroperator.mjs +26 -25
  11. package/source/constraints/valid.mjs +3 -6
  12. package/source/data/buildmap.mjs +20 -36
  13. package/source/data/buildtree.mjs +29 -29
  14. package/source/data/datasource/namespace.mjs +1 -1
  15. package/source/data/datasource/server/restapi/writeerror.mjs +6 -6
  16. package/source/data/datasource/server/restapi.mjs +51 -65
  17. package/source/data/datasource/server/webconnect.mjs +26 -35
  18. package/source/data/datasource/server.mjs +16 -20
  19. package/source/data/datasource/storage/localstorage.mjs +8 -11
  20. package/source/data/datasource/storage/sessionstorage.mjs +8 -10
  21. package/source/data/datasource/storage.mjs +18 -22
  22. package/source/data/datasource.mjs +27 -43
  23. package/source/data/diff.mjs +20 -32
  24. package/source/data/extend.mjs +20 -14
  25. package/source/data/namespace.mjs +1 -3
  26. package/source/data/pathfinder.mjs +40 -67
  27. package/source/data/pipe.mjs +6 -10
  28. package/source/data/transformer.mjs +141 -157
  29. package/source/dom/assembler.mjs +6 -9
  30. package/source/dom/attributes.mjs +36 -48
  31. package/source/dom/constants.mjs +55 -71
  32. package/source/dom/customcontrol.mjs +16 -21
  33. package/source/dom/customelement.mjs +140 -164
  34. package/source/dom/events.mjs +17 -24
  35. package/source/dom/focusmanager.mjs +30 -48
  36. package/source/dom/locale.mjs +16 -19
  37. package/source/dom/namespace.mjs +1 -1
  38. package/source/dom/ready.mjs +7 -10
  39. package/source/dom/resource/data.mjs +38 -46
  40. package/source/dom/resource/link/namespace.mjs +1 -3
  41. package/source/dom/resource/link/stylesheet.mjs +7 -11
  42. package/source/dom/resource/link.mjs +36 -17
  43. package/source/dom/resource/namespace.mjs +1 -1
  44. package/source/dom/resource/script.mjs +23 -13
  45. package/source/dom/resource.mjs +47 -60
  46. package/source/dom/resourcemanager.mjs +36 -43
  47. package/source/dom/template.mjs +17 -24
  48. package/source/dom/theme.mjs +8 -12
  49. package/source/dom/updater.mjs +150 -196
  50. package/source/dom/util.mjs +11 -12
  51. package/source/dom/worker/factory.mjs +21 -25
  52. package/source/dom/worker/namespace.mjs +1 -1
  53. package/source/i18n/formatter.mjs +20 -24
  54. package/source/i18n/locale.mjs +40 -42
  55. package/source/i18n/namespace.mjs +1 -1
  56. package/source/i18n/provider.mjs +4 -7
  57. package/source/i18n/providers/embed.mjs +16 -26
  58. package/source/i18n/providers/fetch.mjs +30 -36
  59. package/source/i18n/translations.mjs +15 -22
  60. package/source/logging/handler/console.mjs +6 -10
  61. package/source/logging/handler.mjs +15 -18
  62. package/source/logging/logentry.mjs +8 -9
  63. package/source/logging/logger.mjs +73 -55
  64. package/source/logging/namespace.mjs +1 -1
  65. package/source/math/namespace.mjs +1 -1
  66. package/source/math/random.mjs +13 -14
  67. package/source/monster.mjs +132 -100
  68. package/source/net/namespace.mjs +1 -3
  69. package/source/net/webconnect/message.mjs +6 -8
  70. package/source/net/webconnect/namespace.mjs +1 -3
  71. package/source/net/webconnect.mjs +28 -39
  72. package/source/text/formatter.mjs +44 -55
  73. package/source/types/base.mjs +16 -26
  74. package/source/types/basewithoptions.mjs +8 -14
  75. package/source/types/binary.mjs +4 -5
  76. package/source/types/dataurl.mjs +19 -27
  77. package/source/types/global.mjs +14 -26
  78. package/source/types/id.mjs +4 -6
  79. package/source/types/is.mjs +11 -16
  80. package/source/types/mediatype.mjs +29 -44
  81. package/source/types/namespace.mjs +0 -1
  82. package/source/types/node.mjs +16 -22
  83. package/source/types/nodelist.mjs +10 -14
  84. package/source/types/noderecursiveiterator.mjs +11 -14
  85. package/source/types/observablequeue.mjs +13 -16
  86. package/source/types/observer.mjs +16 -23
  87. package/source/types/observerlist.mjs +18 -21
  88. package/source/types/proxyobserver.mjs +24 -37
  89. package/source/types/queue.mjs +8 -13
  90. package/source/types/randomid.mjs +10 -10
  91. package/source/types/regex.mjs +3 -5
  92. package/source/types/stack.mjs +4 -8
  93. package/source/types/tokenlist.mjs +24 -31
  94. package/source/types/typeof.mjs +5 -7
  95. package/source/types/uniquequeue.mjs +8 -13
  96. package/source/types/uuid.mjs +18 -25
  97. package/source/types/validate.mjs +26 -27
  98. package/source/types/version.mjs +17 -25
  99. package/source/util/clone.mjs +23 -32
  100. package/source/util/comparator.mjs +7 -15
  101. package/source/util/deadmansswitch.mjs +16 -23
  102. package/source/util/freeze.mjs +5 -7
  103. package/source/util/namespace.mjs +1 -1
  104. package/source/util/processing.mjs +33 -39
  105. package/source/util/trimspaces.mjs +17 -24
  106. package/test/cases/monster.mjs +1 -1
@@ -5,18 +5,20 @@
5
5
  * License text available at https://www.gnu.org/licenses/agpl-3.0.en.html
6
6
  */
7
7
 
8
- import {extend} from "../../data/extend.mjs";
8
+ import { extend } from "../../data/extend.mjs";
9
9
  import {
10
10
  ATTRIBUTE_CLASS,
11
11
  ATTRIBUTE_HREF,
12
12
  ATTRIBUTE_ID,
13
- ATTRIBUTE_NONCE, ATTRIBUTE_SRC,
14
- ATTRIBUTE_TITLE, ATTRIBUTE_TYPE,
15
- TAG_LINK
13
+ ATTRIBUTE_NONCE,
14
+ ATTRIBUTE_SRC,
15
+ ATTRIBUTE_TITLE,
16
+ ATTRIBUTE_TYPE,
17
+ TAG_LINK,
16
18
  } from "../constants.mjs";
17
- import {KEY_DOCUMENT, referenceSymbol, Resource} from "../resource.mjs";
18
- import {instanceSymbol} from '../../constants.mjs';
19
- export {Link}
19
+ import { KEY_DOCUMENT, referenceSymbol, Resource } from "../resource.mjs";
20
+ import { instanceSymbol } from "../../constants.mjs";
21
+ export { Link };
20
22
 
21
23
  /**
22
24
  * This class is used by the resource manager to embed external resources.
@@ -29,7 +31,6 @@ export {Link}
29
31
  * @see https://developer.mozilla.org/en-US/docs/Web/HTML/Element/link
30
32
  */
31
33
  class Link extends Resource {
32
-
33
34
  /**
34
35
  * @property {string} as {@link https://developer.mozilla.org/en-US/docs/Web/HTML/Element/link#attr-as}
35
36
  * @property {string} crossOrigin=anonymous {@link https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script#attr-crossorigin}
@@ -50,7 +51,7 @@ class Link extends Resource {
50
51
  get defaults() {
51
52
  return extend({}, super.defaults, {
52
53
  as: undefined,
53
- crossOrigin: 'anonymous',
54
+ crossOrigin: "anonymous",
54
55
  disabled: undefined,
55
56
  href: undefined,
56
57
  hreflang: undefined,
@@ -63,8 +64,8 @@ class Link extends Resource {
63
64
  rel: undefined,
64
65
  sizes: undefined,
65
66
  type: undefined,
66
- nonce: undefined
67
- })
67
+ nonce: undefined,
68
+ });
68
69
  }
69
70
 
70
71
  /**
@@ -76,7 +77,6 @@ class Link extends Resource {
76
77
  return Symbol.for("@schukai/monster/dom/resource/link");
77
78
  }
78
79
 
79
-
80
80
  /**
81
81
  *
82
82
  * @return {Monster.DOM.Resource.Link}
@@ -90,9 +90,8 @@ class Link extends Resource {
90
90
  * @return {string}
91
91
  */
92
92
  static getURLAttribute() {
93
- return ATTRIBUTE_HREF
93
+ return ATTRIBUTE_HREF;
94
94
  }
95
-
96
95
  }
97
96
 
98
97
  /**
@@ -105,11 +104,31 @@ function createElement() {
105
104
  const document = self.getOption(KEY_DOCUMENT);
106
105
  self[referenceSymbol] = document.createElement(TAG_LINK);
107
106
 
108
- 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]) {
107
+ for (let key of [
108
+ "as",
109
+ "crossOrigin",
110
+ "disabled",
111
+ "href",
112
+ "hreflang",
113
+ "imagesizes",
114
+ "imagesrcset",
115
+ "integrity",
116
+ "media",
117
+ "prefetch",
118
+ "referrerpolicy",
119
+ "sizes",
120
+ "rel",
121
+ "type",
122
+ ATTRIBUTE_HREF,
123
+ ATTRIBUTE_ID,
124
+ ATTRIBUTE_CLASS,
125
+ ATTRIBUTE_TITLE,
126
+ ATTRIBUTE_NONCE,
127
+ ]) {
109
128
  if (self.getOption(key) !== undefined) {
110
129
  self[referenceSymbol][key] = self.getOption(key);
111
130
  }
112
- }
113
-
131
+ }
132
+
114
133
  return self;
115
134
  }
@@ -4,7 +4,7 @@
4
4
  */
5
5
 
6
6
  /**
7
- * In this namespace you will find classes and methods for handling resources.
7
+ * In this namespace you will find classes and methods for handling resources.
8
8
  *
9
9
  * @namespace Monster.DOM.Resource
10
10
  * @memberOf Monster
@@ -5,7 +5,7 @@
5
5
  * License text available at https://www.gnu.org/licenses/agpl-3.0.en.html
6
6
  */
7
7
 
8
- import {extend} from "../../data/extend.mjs";
8
+ import { extend } from "../../data/extend.mjs";
9
9
  import {
10
10
  ATTRIBUTE_CLASS,
11
11
  ATTRIBUTE_ID,
@@ -13,11 +13,11 @@ import {
13
13
  ATTRIBUTE_SRC,
14
14
  ATTRIBUTE_TITLE,
15
15
  ATTRIBUTE_TYPE,
16
- TAG_SCRIPT
16
+ TAG_SCRIPT,
17
17
  } from "../constants.mjs";
18
- import {KEY_DOCUMENT, referenceSymbol, Resource} from "../resource.mjs";
19
- import {instanceSymbol} from '../../constants.mjs';
20
- export {Script}
18
+ import { KEY_DOCUMENT, referenceSymbol, Resource } from "../resource.mjs";
19
+ import { instanceSymbol } from "../../constants.mjs";
20
+ export { Script };
21
21
 
22
22
  /**
23
23
  * This class is used by the resource manager to embed scripts.
@@ -29,7 +29,6 @@ export {Script}
29
29
  * @summary A Resource class
30
30
  */
31
31
  class Script extends Resource {
32
-
33
32
  /**
34
33
  * @property {boolean} async=true {@link https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script#attr-async}
35
34
  * @property {string} crossOrigin=anonymous {@link https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script#attr-crossorigin}
@@ -43,14 +42,14 @@ class Script extends Resource {
43
42
  get defaults() {
44
43
  return extend({}, super.defaults, {
45
44
  async: true,
46
- crossOrigin: 'anonymous',
45
+ crossOrigin: "anonymous",
47
46
  defer: false,
48
47
  integrity: undefined,
49
48
  nomodule: false,
50
49
  nonce: undefined,
51
50
  referrerpolicy: undefined,
52
- type: 'text/javascript',
53
- })
51
+ type: "text/javascript",
52
+ });
54
53
  }
55
54
 
56
55
  /**
@@ -75,9 +74,8 @@ class Script extends Resource {
75
74
  * @return {string}
76
75
  */
77
76
  static getURLAttribute() {
78
- return ATTRIBUTE_SRC
77
+ return ATTRIBUTE_SRC;
79
78
  }
80
-
81
79
  }
82
80
 
83
81
  /**
@@ -90,12 +88,24 @@ function createElement() {
90
88
  const document = self.getOption(KEY_DOCUMENT);
91
89
  self[referenceSymbol] = document.createElement(TAG_SCRIPT);
92
90
 
93
- for (let key of ['crossOrigin', 'defer', 'async', 'integrity', 'nomodule', ATTRIBUTE_NONCE, 'referrerpolicy', ATTRIBUTE_TYPE, ATTRIBUTE_SRC, ATTRIBUTE_ID, ATTRIBUTE_CLASS, ATTRIBUTE_TITLE]) {
91
+ for (let key of [
92
+ "crossOrigin",
93
+ "defer",
94
+ "async",
95
+ "integrity",
96
+ "nomodule",
97
+ ATTRIBUTE_NONCE,
98
+ "referrerpolicy",
99
+ ATTRIBUTE_TYPE,
100
+ ATTRIBUTE_SRC,
101
+ ATTRIBUTE_ID,
102
+ ATTRIBUTE_CLASS,
103
+ ATTRIBUTE_TITLE,
104
+ ]) {
94
105
  if (self.getOption(key) !== undefined) {
95
106
  self[referenceSymbol][key] = self.getOption(key);
96
107
  }
97
108
  }
98
109
 
99
-
100
110
  return self;
101
111
  }
@@ -5,42 +5,42 @@
5
5
  * License text available at https://www.gnu.org/licenses/agpl-3.0.en.html
6
6
  */
7
7
 
8
- import {internalStateSymbol, internalSymbol,} from "../constants.mjs";
9
- import {extend} from "../data/extend.mjs";
10
- import {BaseWithOptions} from "../types/basewithoptions.mjs";
11
- import {getGlobalObject} from "../types/global.mjs";
12
- import {ID} from "../types/id.mjs";
13
- import {isString} from "../types/is.mjs";
14
- import {Observer} from "../types/observer.mjs";
15
- import {ProxyObserver} from "../types/proxyobserver.mjs";
16
- import {ATTRIBUTE_CLASS, ATTRIBUTE_ID, ATTRIBUTE_TITLE} from "./constants.mjs";
17
- import {instanceSymbol} from "../constants.mjs";
18
-
19
- export {Resource, KEY_DOCUMENT, KEY_QUERY, referenceSymbol}
8
+ import { internalStateSymbol, internalSymbol } from "../constants.mjs";
9
+ import { extend } from "../data/extend.mjs";
10
+ import { BaseWithOptions } from "../types/basewithoptions.mjs";
11
+ import { getGlobalObject } from "../types/global.mjs";
12
+ import { ID } from "../types/id.mjs";
13
+ import { isString } from "../types/is.mjs";
14
+ import { Observer } from "../types/observer.mjs";
15
+ import { ProxyObserver } from "../types/proxyobserver.mjs";
16
+ import { ATTRIBUTE_CLASS, ATTRIBUTE_ID, ATTRIBUTE_TITLE } from "./constants.mjs";
17
+ import { instanceSymbol } from "../constants.mjs";
18
+
19
+ export { Resource, KEY_DOCUMENT, KEY_QUERY, referenceSymbol };
20
20
 
21
21
  /**
22
22
  * @private
23
23
  * @type {string}
24
24
  */
25
- const KEY_DOCUMENT = 'document';
25
+ const KEY_DOCUMENT = "document";
26
26
 
27
27
  /**
28
28
  * @private
29
29
  * @type {string}
30
30
  */
31
- const KEY_QUERY = 'query';
31
+ const KEY_QUERY = "query";
32
32
 
33
33
  /**
34
34
  * @private
35
35
  * @type {string}
36
36
  */
37
- const KEY_TIMEOUT = 'timeout';
37
+ const KEY_TIMEOUT = "timeout";
38
38
 
39
39
  /**
40
40
  * @private
41
41
  * @type {symbol}
42
42
  */
43
- const referenceSymbol = Symbol('reference');
43
+ const referenceSymbol = Symbol("reference");
44
44
 
45
45
  /**
46
46
  * This class is the base class for all resources to be loaded.
@@ -52,7 +52,6 @@ const referenceSymbol = Symbol('reference');
52
52
  * @summary A Resource class
53
53
  */
54
54
  class Resource extends BaseWithOptions {
55
-
56
55
  /**
57
56
  *
58
57
  * @param {Object|undefined} options
@@ -63,28 +62,26 @@ class Resource extends BaseWithOptions {
63
62
  let uri = this.getOption(this.constructor.getURLAttribute());
64
63
 
65
64
  if (uri === undefined) {
66
- throw new Error('missing source')
65
+ throw new Error("missing source");
67
66
  } else if (uri instanceof URL) {
68
67
  uri = uri.toString();
69
68
  } else if (!isString(uri)) {
70
- throw new Error('unsupported url type')
69
+ throw new Error("unsupported url type");
71
70
  }
72
71
 
73
72
  this[internalSymbol][this.constructor.getURLAttribute()] = uri;
74
73
  this[internalStateSymbol] = new ProxyObserver({
75
74
  loaded: false,
76
75
  error: undefined,
77
- })
76
+ });
78
77
 
79
78
  this[referenceSymbol] = undefined;
80
-
81
79
  }
82
80
 
83
81
  /**
84
82
  * @return {boolean}
85
83
  */
86
84
  isConnected() {
87
-
88
85
  if (this[referenceSymbol] instanceof HTMLElement) {
89
86
  return this[referenceSymbol].isConnected;
90
87
  }
@@ -111,7 +108,6 @@ class Resource extends BaseWithOptions {
111
108
  * @return {Monster.DOM.Resource}
112
109
  */
113
110
  connect() {
114
-
115
111
  if (!(this[referenceSymbol] instanceof HTMLElement)) {
116
112
  this.create();
117
113
  }
@@ -132,13 +128,13 @@ class Resource extends BaseWithOptions {
132
128
  get defaults() {
133
129
  return extend({}, super.defaults, {
134
130
  [this.constructor.getURLAttribute()]: undefined,
135
- [KEY_DOCUMENT]: getGlobalObject('document'),
136
- [KEY_QUERY]: 'head',
131
+ [KEY_DOCUMENT]: getGlobalObject("document"),
132
+ [KEY_QUERY]: "head",
137
133
  [KEY_TIMEOUT]: 10000,
138
- [ATTRIBUTE_ID]: (new ID('resource')).toString(),
134
+ [ATTRIBUTE_ID]: new ID("resource").toString(),
139
135
  [ATTRIBUTE_CLASS]: undefined,
140
- [ATTRIBUTE_TITLE]: undefined
141
- })
136
+ [ATTRIBUTE_TITLE]: undefined,
137
+ });
142
138
  }
143
139
 
144
140
  /**
@@ -150,40 +146,35 @@ class Resource extends BaseWithOptions {
150
146
  available() {
151
147
  const self = this;
152
148
  if (!(self[referenceSymbol] instanceof HTMLElement)) {
153
- return Promise.reject('no element')
149
+ return Promise.reject("no element");
154
150
  }
155
151
 
156
152
  if (!self.isConnected()) {
157
- return Promise.reject('element not connected')
153
+ return Promise.reject("element not connected");
158
154
  }
159
155
 
160
- if (self[internalStateSymbol].getSubject()['loaded'] === true) {
161
-
162
- if (self[internalStateSymbol].getSubject()['error'] !== undefined) {
163
- return Promise.reject(self[internalStateSymbol].getSubject()['error']);
156
+ if (self[internalStateSymbol].getSubject()["loaded"] === true) {
157
+ if (self[internalStateSymbol].getSubject()["error"] !== undefined) {
158
+ return Promise.reject(self[internalStateSymbol].getSubject()["error"]);
164
159
  }
165
160
 
166
161
  return Promise.resolve();
167
-
168
162
  }
169
163
 
170
164
  return new Promise(function (resolve, reject) {
171
-
172
165
  const timeout = setTimeout(() => {
173
- reject('timeout');
174
- }, self.getOption('timeout'))
166
+ reject("timeout");
167
+ }, self.getOption("timeout"));
175
168
 
176
169
  const observer = new Observer(() => {
177
170
  clearTimeout(timeout);
178
171
  self[internalStateSymbol].detachObserver(observer);
179
172
  resolve();
180
- })
173
+ });
181
174
 
182
175
  self[internalStateSymbol].attachObserver(observer);
183
-
184
176
  });
185
-
186
- };
177
+ }
187
178
 
188
179
  /**
189
180
  * @return {string}
@@ -191,17 +182,15 @@ class Resource extends BaseWithOptions {
191
182
  static getURLAttribute() {
192
183
  throw new Error("this method must be implemented by derived classes");
193
184
  }
194
-
185
+
195
186
  /**
196
187
  * @return {symbol}
197
188
  */
198
189
  static get [instanceSymbol]() {
199
190
  return Symbol.for("@schukai/monster/dom/resource");
200
191
  }
201
-
202
192
  }
203
193
 
204
-
205
194
  /**
206
195
  * @private
207
196
  * @return {Promise}
@@ -210,9 +199,9 @@ class Resource extends BaseWithOptions {
210
199
  function appendToDocument() {
211
200
  const self = this;
212
201
 
213
- const targetNode = document.querySelector(self.getOption(KEY_QUERY, 'head'))
202
+ const targetNode = document.querySelector(self.getOption(KEY_QUERY, "head"));
214
203
  if (!(targetNode instanceof HTMLElement)) {
215
- throw new Error('target not found')
204
+ throw new Error("target not found");
216
205
  }
217
206
 
218
207
  addEvents.call(self);
@@ -229,28 +218,26 @@ function addEvents() {
229
218
  const self = this;
230
219
 
231
220
  const onError = () => {
232
-
233
- self[referenceSymbol].removeEventListener('error', onError);
234
- self[referenceSymbol].removeEventListener('load', onLoad);
221
+ self[referenceSymbol].removeEventListener("error", onError);
222
+ self[referenceSymbol].removeEventListener("load", onLoad);
235
223
 
236
224
  self[internalStateSymbol].setSubject({
237
225
  loaded: true,
238
- error: self[referenceSymbol][self.constructor.getURLAttribute()] + ' is not available',
239
- })
226
+ error: `${self[referenceSymbol][self.constructor.getURLAttribute()]} is not available`,
227
+ });
240
228
 
241
229
  return;
242
- }
230
+ };
243
231
 
244
232
  const onLoad = () => {
245
- self[referenceSymbol].removeEventListener('error', onError);
246
- self[referenceSymbol].removeEventListener('load', onLoad);
247
- self[internalStateSymbol].getSubject()['loaded'] = true;
233
+ self[referenceSymbol].removeEventListener("error", onError);
234
+ self[referenceSymbol].removeEventListener("load", onLoad);
235
+ self[internalStateSymbol].getSubject()["loaded"] = true;
248
236
  return;
249
- }
237
+ };
250
238
 
251
- self[referenceSymbol].addEventListener('load', onLoad, false);
252
- self[referenceSymbol].addEventListener('error', onError, false);
239
+ self[referenceSymbol].addEventListener("load", onLoad, false);
240
+ self[referenceSymbol].addEventListener("error", onError, false);
253
241
 
254
242
  return self;
255
-
256
243
  }
@@ -5,17 +5,17 @@
5
5
  * License text available at https://www.gnu.org/licenses/agpl-3.0.en.html
6
6
  */
7
7
 
8
- import {extend} from "../data/extend.mjs";
9
- import {BaseWithOptions} from "../types/basewithoptions.mjs";
10
- import {getGlobalObject} from "../types/global.mjs";
11
- import {isArray} from "../types/is.mjs";
12
- import {ATTRIBUTE_HREF, ATTRIBUTE_SRC} from "./constants.mjs";
13
- import {Resource} from "./resource.mjs";
14
- import {Data} from "./resource/data.mjs";
15
- import {Stylesheet} from "./resource/link/stylesheet.mjs";
16
- import {Script} from "./resource/script.mjs";
17
-
18
- export {ResourceManager}
8
+ import { extend } from "../data/extend.mjs";
9
+ import { BaseWithOptions } from "../types/basewithoptions.mjs";
10
+ import { getGlobalObject } from "../types/global.mjs";
11
+ import { isArray } from "../types/is.mjs";
12
+ import { ATTRIBUTE_HREF, ATTRIBUTE_SRC } from "./constants.mjs";
13
+ import { Resource } from "./resource.mjs";
14
+ import { Data } from "./resource/data.mjs";
15
+ import { Stylesheet } from "./resource/link/stylesheet.mjs";
16
+ import { Script } from "./resource/script.mjs";
17
+
18
+ export { ResourceManager };
19
19
 
20
20
  /**
21
21
  * The ResourceManager is a singleton that manages all resources.
@@ -26,8 +26,7 @@ export {ResourceManager}
26
26
  * @memberOf Monster.DOM
27
27
  * @summary A Resource class
28
28
  */
29
- class ResourceManager extends BaseWithOptions {
30
-
29
+ class ResourceManager extends BaseWithOptions {
31
30
  /**
32
31
  *
33
32
  * @param {Object} options
@@ -36,18 +35,16 @@ export {ResourceManager}
36
35
  constructor(options) {
37
36
  super(options);
38
37
 
39
- if (!(this.getOption('document') instanceof Document)) {
40
- throw new Error('unsupported document type')
38
+ if (!(this.getOption("document") instanceof Document)) {
39
+ throw new Error("unsupported document type");
41
40
  }
42
-
43
-
44
41
  }
45
42
 
46
43
  /**
47
44
  * @property {string} baseurl
48
45
  */
49
46
  getBaseURL() {
50
- this.getOption('document')?.baseURL;
47
+ this.getOption("document")?.baseURL;
51
48
  }
52
49
 
53
50
  /**
@@ -60,13 +57,13 @@ export {ResourceManager}
60
57
  */
61
58
  get defaults() {
62
59
  return Object.assign({}, super.defaults, {
63
- document: getGlobalObject('document'),
60
+ document: getGlobalObject("document"),
64
61
  resources: {
65
62
  scripts: [],
66
63
  stylesheets: [],
67
- data: []
68
- }
69
- })
64
+ data: [],
65
+ },
66
+ });
70
67
  }
71
68
 
72
69
  /**
@@ -76,7 +73,7 @@ export {ResourceManager}
76
73
  * @throws {Error} unsupported resource definition
77
74
  */
78
75
  connect() {
79
- runResourceMethod.call(this, 'connect');
76
+ runResourceMethod.call(this, "connect");
80
77
  return this;
81
78
  }
82
79
 
@@ -87,7 +84,7 @@ export {ResourceManager}
87
84
  * @throws {Error} unsupported resource definition
88
85
  */
89
86
  available() {
90
- return Promise.all(runResourceMethod.call(this, 'available'));
87
+ return Promise.all(runResourceMethod.call(this, "available"));
91
88
  }
92
89
 
93
90
  /**
@@ -99,10 +96,9 @@ export {ResourceManager}
99
96
  * @see Monster.DOM.Resource.Script
100
97
  */
101
98
  addScript(url, options) {
102
- return addResource.call(this, 'scripts', url, options);
99
+ return addResource.call(this, "scripts", url, options);
103
100
  }
104
101
 
105
-
106
102
  /**
107
103
  * Add Stylesheet
108
104
  *
@@ -112,7 +108,7 @@ export {ResourceManager}
112
108
  * @see Monster.DOM.Resource.Link.Stylesheet
113
109
  */
114
110
  addStylesheet(url, options) {
115
- return addResource.call(this, 'stylesheets', url, options);
111
+ return addResource.call(this, "stylesheets", url, options);
116
112
  }
117
113
 
118
114
  /**
@@ -124,10 +120,8 @@ export {ResourceManager}
124
120
  * @see Monster.DOM.Resource.Data
125
121
  */
126
122
  addData(url, options) {
127
- return addResource.call(this, 'data', url, options);
123
+ return addResource.call(this, "data", url, options);
128
124
  }
129
-
130
-
131
125
  }
132
126
 
133
127
  /**
@@ -140,20 +134,19 @@ function runResourceMethod(method) {
140
134
 
141
135
  const result = [];
142
136
 
143
- for (const type of ['scripts', 'stylesheets', 'data']) {
144
- const resources = self.getOption('resources.' + type);
137
+ for (const type of ["scripts", "stylesheets", "data"]) {
138
+ const resources = self.getOption(`resources.${type}`);
145
139
  if (!isArray(resources)) {
146
140
  continue;
147
141
  }
148
142
 
149
143
  for (const resource of resources) {
150
144
  if (!(resource instanceof Resource)) {
151
- throw new Error('unsupported resource definition')
145
+ throw new Error("unsupported resource definition");
152
146
  }
153
147
 
154
148
  result.push(resource[method]());
155
149
  }
156
-
157
150
  }
158
151
 
159
152
  return result;
@@ -174,23 +167,23 @@ function addResource(type, url, options) {
174
167
  url = url.toString();
175
168
  }
176
169
 
177
- options = options || {}
170
+ options = options || {};
178
171
 
179
172
  let resource;
180
173
  switch (type) {
181
- case 'scripts':
182
- resource = new Script(extend({}, options, {[ATTRIBUTE_SRC]: url}))
174
+ case "scripts":
175
+ resource = new Script(extend({}, options, { [ATTRIBUTE_SRC]: url }));
183
176
  break;
184
- case 'stylesheets':
185
- resource = new Stylesheet(extend({}, options, {[ATTRIBUTE_HREF]: url}))
177
+ case "stylesheets":
178
+ resource = new Stylesheet(extend({}, options, { [ATTRIBUTE_HREF]: url }));
186
179
  break;
187
- case 'data':
188
- resource = new Data(extend({}, options, {[ATTRIBUTE_SRC]: url}))
180
+ case "data":
181
+ resource = new Data(extend({}, options, { [ATTRIBUTE_SRC]: url }));
189
182
  break;
190
183
  default:
191
- throw new Error('unsupported type ' + type)
184
+ throw new Error(`unsupported type ${type}`);
192
185
  }
193
186
 
194
- (self.getOption('resources')?.[type]).push(resource);
187
+ self.getOption("resources")?.[type].push(resource);
195
188
  return self;
196
189
  }