melonjs 10.12.0 → 11.0.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.
@@ -2806,11 +2806,12 @@ export class Light2d extends Renderable {
2806
2806
  /**
2807
2807
  * @param {number} x - The horizontal position of the light.
2808
2808
  * @param {number} y - The vertical position of the light.
2809
- * @param {number} radius - The radius of the light.
2809
+ * @param {number} radiusX - The horizontal radius of the light.
2810
+ * @param {number} [radiusY=radiusX] - The vertical radius of the light.
2810
2811
  * @param {Color|string} [color="#FFF"] the color of the light
2811
2812
  * @param {number} [intensity=0.7] - The intensity of the light.
2812
2813
  */
2813
- constructor(x: number, y: number, radius: number, color?: Color | string, intensity?: number);
2814
+ constructor(x: number, y: number, radiusX: number, radiusY?: number, color?: Color | string, intensity?: number);
2814
2815
  /**
2815
2816
  * the color of the light
2816
2817
  * @type {Color}
@@ -2818,10 +2819,15 @@ export class Light2d extends Renderable {
2818
2819
  */
2819
2820
  color: Color;
2820
2821
  /**
2821
- * The radius of the light
2822
+ * The horizontal radius of the light
2822
2823
  * @type {number}
2823
2824
  */
2824
- radius: number;
2825
+ radiusX: number;
2826
+ /**
2827
+ * The vertical radius of the light
2828
+ * @type {number}
2829
+ */
2830
+ radiusY: number;
2825
2831
  /**
2826
2832
  * The intensity of the light
2827
2833
  * @type {number}
@@ -9759,6 +9765,7 @@ export namespace device {
9759
9765
  }
9760
9766
  export var event: Readonly<{
9761
9767
  __proto__: any;
9768
+ DOM_READY: string;
9762
9769
  BOOT: string;
9763
9770
  STATE_PAUSE: string;
9764
9771
  STATE_RESUME: string;
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * melonJS Game Engine - v10.12.0
2
+ * melonJS Game Engine - v11.0.0
3
3
  * http://www.melonjs.org
4
4
  * melonjs is licensed under the MIT License.
5
5
  * http://www.opensource.org/licenses/mit-license
@@ -309,10 +309,10 @@ var store$2 = sharedStore;
309
309
  (shared$3.exports = function (key, value) {
310
310
  return store$2[key] || (store$2[key] = value !== undefined ? value : {});
311
311
  })('versions', []).push({
312
- version: '3.23.1',
312
+ version: '3.23.2',
313
313
  mode: 'global',
314
314
  copyright: '© 2014-2022 Denis Pushkarev (zloirock.ru)',
315
- license: 'https://github.com/zloirock/core-js/blob/v3.23.1/LICENSE',
315
+ license: 'https://github.com/zloirock/core-js/blob/v3.23.2/LICENSE',
316
316
  source: 'https://github.com/zloirock/core-js'
317
317
  });
318
318
 
@@ -4337,6 +4337,17 @@ var EventEmitter = eventemitter3.exports;
4337
4337
  // internal instance of the event emiter
4338
4338
  var eventEmitter = new EventEmitter();
4339
4339
 
4340
+ /**
4341
+ * event when the DOM is Ready is booting
4342
+ * @public
4343
+ * @constant
4344
+ * @type {string}
4345
+ * @name DOM_READY
4346
+ * @memberof event
4347
+ * @see event.on
4348
+ */
4349
+ const DOM_READY = "dom_ready";
4350
+
4340
4351
  /**
4341
4352
  * event when the system is booting
4342
4353
  * @public
@@ -4843,6 +4854,7 @@ function off(eventName, listener) {
4843
4854
 
4844
4855
  var event = /*#__PURE__*/Object.freeze({
4845
4856
  __proto__: null,
4857
+ DOM_READY: DOM_READY,
4846
4858
  BOOT: BOOT,
4847
4859
  STATE_PAUSE: STATE_PAUSE,
4848
4860
  STATE_RESUME: STATE_RESUME,
@@ -28375,33 +28387,17 @@ var save = {
28375
28387
  }
28376
28388
  };
28377
28389
 
28378
- // private properties
28379
- let accelInitialized = false;
28380
- let deviceOrientationInitialized = false;
28390
+ // track if DOMContentLoaded was called already
28391
+ let readyBound = false;
28381
28392
 
28382
- // swipe utility fn & flag
28383
- let swipeEnabled = true;
28393
+ // is the DOM ready ?
28394
+ let isDOMReady = false;
28384
28395
 
28385
- /**
28386
- * @ignore
28387
- */
28388
- function _disableSwipeFn(e) {
28389
- e.preventDefault();
28390
- if (typeof globalThis.scroll === "function") {
28391
- globalThis.scroll(0, 0);
28392
- }
28393
- return false;
28394
- }
28395
- // DOM loading stuff
28396
- let readyBound = false, isReady = false, readyList = [];
28397
-
28398
- /**
28399
- * // called to check if the device is ready
28400
- * @ignore
28401
- */
28396
+ // check if the dom is ready
28402
28397
  function _domReady() {
28398
+
28403
28399
  // Make sure that the DOM is not already loaded
28404
- if (!isReady) {
28400
+ if (!isDOMReady) {
28405
28401
  // be sure document.body is there
28406
28402
  if (typeof globalThis.document !== "undefined" && !globalThis.document.body) {
28407
28403
  return setTimeout(_domReady, 13);
@@ -28411,7 +28407,7 @@ function _domReady() {
28411
28407
  if (typeof globalThis.document !== "undefined" && typeof globalThis.document.removeEventListener === "function") {
28412
28408
  globalThis.document.removeEventListener(
28413
28409
  "DOMContentLoaded",
28414
- this._domReady,
28410
+ _domReady,
28415
28411
  false
28416
28412
  );
28417
28413
  }
@@ -28422,13 +28418,58 @@ function _domReady() {
28422
28418
  }
28423
28419
 
28424
28420
  // execute all callbacks
28425
- while (readyList.length) {
28426
- readyList.shift().call(globalThis, []);
28427
- }
28421
+ emit(DOM_READY);
28428
28422
 
28429
28423
  // Remember that the DOM is ready
28430
- isReady = true;
28424
+ isDOMReady = true;
28425
+ }
28426
+ }
28427
+ // https://developer.mozilla.org/en-US/docs/Web/API/Window/DOMContentLoaded_event
28428
+ function DOMContentLoaded(fn) {
28429
+ // If the DOM is already ready
28430
+ if (isDOMReady) {
28431
+ // Execute the function immediately
28432
+ fn.call(globalThis, []);
28433
+ }
28434
+ else {
28435
+ // else add the function to the DOM_READY event
28436
+ once(DOM_READY, fn, globalThis);
28437
+ // bind dom load event if not done yet
28438
+ if (!readyBound) {
28439
+ // directly call domReady if document is already "ready"
28440
+ if (((typeof process !== "undefined") && (process.release.name === "node")) || (typeof globalThis.document !== "undefined" && globalThis.document.readyState === "complete")) {
28441
+ // defer the fn call to ensure our script is fully loaded
28442
+ globalThis.setTimeout(_domReady, 0);
28443
+ }
28444
+ else {
28445
+ if (typeof globalThis.document !== "undefined" && typeof globalThis.document.addEventListener === "function") {
28446
+ // Use the handy event callback
28447
+ globalThis.document.addEventListener("DOMContentLoaded", _domReady, false);
28448
+ }
28449
+ // A fallback to globalThis.onload, that will always work
28450
+ globalThis.addEventListener("load", _domReady, false);
28451
+ }
28452
+ readyBound = true;
28453
+ }
28454
+ }
28455
+ }
28456
+
28457
+ // private properties
28458
+ let accelInitialized = false;
28459
+ let deviceOrientationInitialized = false;
28460
+
28461
+ // swipe utility fn & flag
28462
+ let swipeEnabled = true;
28463
+
28464
+ /**
28465
+ * @ignore
28466
+ */
28467
+ function _disableSwipeFn(e) {
28468
+ e.preventDefault();
28469
+ if (typeof globalThis.scroll === "function") {
28470
+ globalThis.scroll(0, 0);
28431
28471
  }
28472
+ return false;
28432
28473
  }
28433
28474
  // a cache DOMRect object
28434
28475
  let _domRect = {left: 0, top: 0, x: 0, y: 0, width: 0, height: 0, right: 0, bottom: 0};
@@ -28784,7 +28825,7 @@ let device = {
28784
28825
  * @readonly
28785
28826
  * @name nodeJS
28786
28827
  */
28787
- nodeJS : (typeof process !== "undefined") && (process.release.name === "node"),
28828
+ nodeJS : (typeof globalThis.process !== "undefined") && (typeof globalThis.process.release !== "undefined") && (globalThis.process.release.name === "node"),
28788
28829
 
28789
28830
  /**
28790
28831
  * equals to true if the device is running on ChromeOS.
@@ -28972,33 +29013,7 @@ let device = {
28972
29013
  * });
28973
29014
  */
28974
29015
  onReady(fn) {
28975
- // If the DOM is already ready
28976
- if (isReady) {
28977
- // Execute the function immediately
28978
- fn.call(globalThis, []);
28979
- }
28980
- else {
28981
- // Add the function to the wait list
28982
- readyList.push(fn);
28983
-
28984
- // attach listeners if not yet done
28985
- if (!readyBound) {
28986
- // directly call domReady if document is already "ready"
28987
- if (device.nodeJS === true || (typeof globalThis.document !== "undefined" && globalThis.document.readyState === "complete")) {
28988
- // defer the fn call to ensure our script is fully loaded
28989
- globalThis.setTimeout(_domReady, 0);
28990
- }
28991
- else {
28992
- if (typeof globalThis.document !== "undefined" && typeof globalThis.document.addEventListener === "function") {
28993
- // Use the handy event callback
28994
- globalThis.document.addEventListener("DOMContentLoaded", _domReady, false);
28995
- }
28996
- // A fallback to globalThis.onload, that will always work
28997
- globalThis.addEventListener("load", _domReady, false);
28998
- }
28999
- readyBound = true;
29000
- }
29001
- }
29016
+ DOMContentLoaded(fn);
29002
29017
  },
29003
29018
 
29004
29019
  /**
@@ -32800,10 +32815,10 @@ class BasePlugin {
32800
32815
  * this can be overridden by the plugin
32801
32816
  * @public
32802
32817
  * @type {string}
32803
- * @default "10.12.0"
32818
+ * @default "11.0.0"
32804
32819
  * @name plugin.Base#version
32805
32820
  */
32806
- this.version = "10.12.0";
32821
+ this.version = "11.0.0";
32807
32822
  }
32808
32823
  }
32809
32824
 
@@ -36102,19 +36117,41 @@ class Trigger extends Renderable {
36102
36117
  /** @ignore */
36103
36118
  function createGradient(light) {
36104
36119
  var context = light.texture.context;
36105
- var x1 = light.texture.width / 2;
36106
- var y1 = light.texture.height / 2;
36107
- var gradient = context.createRadialGradient(x1, y1, 0, x1, y1, light.radius);
36120
+
36121
+ var x1 = light.texture.width / 2,
36122
+ y1 = light.texture.height / 2;
36123
+
36124
+ var radiusX = light.radiusX,
36125
+ radiusY = light.radiusY;
36126
+
36127
+ var scaleX, scaleY, invScaleX, invScaleY;
36128
+ var gradient;
36129
+
36108
36130
 
36109
36131
  light.texture.clear();
36110
36132
 
36133
+ if (radiusX >= radiusY) {
36134
+ scaleX = 1;
36135
+ invScaleX = 1;
36136
+ scaleY = radiusY/radiusX;
36137
+ invScaleY = radiusX/radiusY;
36138
+ gradient = context.createRadialGradient(x1, y1 * invScaleY, 0, x1, radiusY * invScaleY, radiusX);
36139
+ }
36140
+ else {
36141
+ scaleY = 1;
36142
+ invScaleY = 1;
36143
+ scaleX = radiusX/radiusY;
36144
+ invScaleX = radiusY/radiusX;
36145
+ gradient = context.createRadialGradient(x1 * invScaleX, y1, 0, x1 * invScaleX, y1, radiusY);
36146
+ }
36147
+
36111
36148
  gradient.addColorStop( 0, light.color.toRGBA(light.intensity));
36112
36149
  gradient.addColorStop( 1, light.color.toRGBA(0.0));
36113
36150
 
36114
- context.beginPath();
36115
36151
  context.fillStyle = gradient;
36116
- context.arc(x1, y1, light.radius, 0, Math.PI * 2, false);
36117
- context.fill();
36152
+
36153
+ context.setTransform(scaleX, 0, 0, scaleY, 0, 0);
36154
+ context.fillRect(0, 0, light.texture.width * invScaleX, light.texture.height * invScaleY);
36118
36155
  }
36119
36156
 
36120
36157
  /**
@@ -36129,13 +36166,14 @@ class Light2d extends Renderable {
36129
36166
  /**
36130
36167
  * @param {number} x - The horizontal position of the light.
36131
36168
  * @param {number} y - The vertical position of the light.
36132
- * @param {number} radius - The radius of the light.
36169
+ * @param {number} radiusX - The horizontal radius of the light.
36170
+ * @param {number} [radiusY=radiusX] - The vertical radius of the light.
36133
36171
  * @param {Color|string} [color="#FFF"] the color of the light
36134
36172
  * @param {number} [intensity=0.7] - The intensity of the light.
36135
36173
  */
36136
- constructor(x, y, radius, color = "#FFF", intensity = 0.7) {
36174
+ constructor(x, y, radiusX, radiusY = radiusX, color = "#FFF", intensity = 0.7) {
36137
36175
  // call the parent constructor
36138
- super(x, y, radius * 2, radius * 2);
36176
+ super(x, y, radiusX * 2, radiusY * 2);
36139
36177
 
36140
36178
  /**
36141
36179
  * the color of the light
@@ -36145,10 +36183,16 @@ class Light2d extends Renderable {
36145
36183
  this.color = pool.pull("Color").parseCSS(color);
36146
36184
 
36147
36185
  /**
36148
- * The radius of the light
36186
+ * The horizontal radius of the light
36149
36187
  * @type {number}
36150
36188
  */
36151
- this.radius = radius;
36189
+ this.radiusX = radiusX;
36190
+
36191
+ /**
36192
+ * The vertical radius of the light
36193
+ * @type {number}
36194
+ */
36195
+ this.radiusY = radiusY;
36152
36196
 
36153
36197
  /**
36154
36198
  * The intensity of the light
@@ -37526,7 +37570,7 @@ class DroptargetEntity extends DropTarget {
37526
37570
  * @name version
37527
37571
  * @type {string}
37528
37572
  */
37529
- const version = "10.12.0";
37573
+ const version = "11.0.0";
37530
37574
 
37531
37575
 
37532
37576
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "melonjs",
3
- "version": "10.12.0",
3
+ "version": "11.0.0",
4
4
  "description": "melonJS Game Engine",
5
5
  "homepage": "http://www.melonjs.org/",
6
6
  "keywords": [
@@ -55,7 +55,7 @@
55
55
  ],
56
56
  "dependencies": {
57
57
  "@teppeis/multimaps": "^2.0.0",
58
- "core-js": "^3.23.1",
58
+ "core-js": "^3.23.2",
59
59
  "earcut": "2.2.3",
60
60
  "eventemitter3": "^4.0.7",
61
61
  "howler": "2.2.3"
@@ -77,7 +77,7 @@
77
77
  "karma-html-detailed-reporter": "^2.1.0",
78
78
  "karma-jasmine": "^5.1.0",
79
79
  "karma-nyan-reporter": "0.2.5",
80
- "rollup": "^2.75.6",
80
+ "rollup": "^2.75.7",
81
81
  "rollup-plugin-bundle-size": "^1.0.3",
82
82
  "rollup-plugin-string": "^3.0.0",
83
83
  "terser": "^5.14.1",
@@ -90,7 +90,7 @@
90
90
  "lint": "eslint src rollup.config.js",
91
91
  "test": "npm run test-node && karma start tests/karma.conf.cjs",
92
92
  "test-node": "node build/melonjs.module.js",
93
- "doc": "mkdirp docs && webdoc --quiet --site-root docs -R README.md",
93
+ "doc": "mkdirp docs && webdoc --quiet --site-root melonJS/docs -R README.md",
94
94
  "serve": "python3 -m http.server",
95
95
  "prepublishOnly": "npm run dist && npm run test",
96
96
  "clean": "del-cli --force build/*.js dist/*.js dist/*.d.ts docs src/**/*.d.ts",
@@ -4,19 +4,41 @@ import Renderable from "./renderable.js";
4
4
  /** @ignore */
5
5
  function createGradient(light) {
6
6
  var context = light.texture.context;
7
- var x1 = light.texture.width / 2;
8
- var y1 = light.texture.height / 2;
9
- var gradient = context.createRadialGradient(x1, y1, 0, x1, y1, light.radius);
7
+
8
+ var x1 = light.texture.width / 2,
9
+ y1 = light.texture.height / 2;
10
+
11
+ var radiusX = light.radiusX,
12
+ radiusY = light.radiusY;
13
+
14
+ var scaleX, scaleY, invScaleX, invScaleY;
15
+ var gradient;
16
+
10
17
 
11
18
  light.texture.clear();
12
19
 
20
+ if (radiusX >= radiusY) {
21
+ scaleX = 1;
22
+ invScaleX = 1;
23
+ scaleY = radiusY/radiusX;
24
+ invScaleY = radiusX/radiusY;
25
+ gradient = context.createRadialGradient(x1, y1 * invScaleY, 0, x1, radiusY * invScaleY, radiusX);
26
+ }
27
+ else {
28
+ scaleY = 1;
29
+ invScaleY = 1;
30
+ scaleX = radiusX/radiusY;
31
+ invScaleX = radiusY/radiusX;
32
+ gradient = context.createRadialGradient(x1 * invScaleX, y1, 0, x1 * invScaleX, y1, radiusY);
33
+ }
34
+
13
35
  gradient.addColorStop( 0, light.color.toRGBA(light.intensity));
14
36
  gradient.addColorStop( 1, light.color.toRGBA(0.0));
15
37
 
16
- context.beginPath();
17
38
  context.fillStyle = gradient;
18
- context.arc(x1, y1, light.radius, 0, Math.PI * 2, false);
19
- context.fill();
39
+
40
+ context.setTransform(scaleX, 0, 0, scaleY, 0, 0);
41
+ context.fillRect(0, 0, light.texture.width * invScaleX, light.texture.height * invScaleY);
20
42
  }
21
43
 
22
44
  /**
@@ -31,13 +53,14 @@ class Light2d extends Renderable {
31
53
  /**
32
54
  * @param {number} x - The horizontal position of the light.
33
55
  * @param {number} y - The vertical position of the light.
34
- * @param {number} radius - The radius of the light.
56
+ * @param {number} radiusX - The horizontal radius of the light.
57
+ * @param {number} [radiusY=radiusX] - The vertical radius of the light.
35
58
  * @param {Color|string} [color="#FFF"] the color of the light
36
59
  * @param {number} [intensity=0.7] - The intensity of the light.
37
60
  */
38
- constructor(x, y, radius, color = "#FFF", intensity = 0.7) {
61
+ constructor(x, y, radiusX, radiusY = radiusX, color = "#FFF", intensity = 0.7) {
39
62
  // call the parent constructor
40
- super(x, y, radius * 2, radius * 2);
63
+ super(x, y, radiusX * 2, radiusY * 2);
41
64
 
42
65
  /**
43
66
  * the color of the light
@@ -47,10 +70,16 @@ class Light2d extends Renderable {
47
70
  this.color = pool.pull("Color").parseCSS(color);
48
71
 
49
72
  /**
50
- * The radius of the light
73
+ * The horizontal radius of the light
74
+ * @type {number}
75
+ */
76
+ this.radiusX = radiusX;
77
+
78
+ /**
79
+ * The vertical radius of the light
51
80
  * @type {number}
52
81
  */
53
- this.radius = radius;
82
+ this.radiusY = radiusY;
54
83
 
55
84
  /**
56
85
  * The intensity of the light
@@ -4,6 +4,7 @@ import save from "./save.js";
4
4
  import { prefixed } from "./../utils/agent.js";
5
5
  import state from "./../state/state.js";
6
6
  import * as event from "./event.js";
7
+ import { DOMContentLoaded } from "./dom.js";
7
8
 
8
9
  // private properties
9
10
  let accelInitialized = false;
@@ -23,45 +24,6 @@ function _disableSwipeFn(e) {
23
24
  return false;
24
25
  };
25
26
 
26
- // DOM loading stuff
27
- let readyBound = false, isReady = false, readyList = [];
28
-
29
- /**
30
- * // called to check if the device is ready
31
- * @ignore
32
- */
33
- function _domReady() {
34
- // Make sure that the DOM is not already loaded
35
- if (!isReady) {
36
- // be sure document.body is there
37
- if (typeof globalThis.document !== "undefined" && !globalThis.document.body) {
38
- return setTimeout(_domReady, 13);
39
- }
40
-
41
- // clean up loading event
42
- if (typeof globalThis.document !== "undefined" && typeof globalThis.document.removeEventListener === "function") {
43
- globalThis.document.removeEventListener(
44
- "DOMContentLoaded",
45
- this._domReady,
46
- false
47
- );
48
- }
49
-
50
- if (typeof globalThis.removeEventListener === "function") {
51
- // remove the event on globalThis.onload (always added in `onReady`)
52
- globalThis.removeEventListener("load", _domReady, false);
53
- }
54
-
55
- // execute all callbacks
56
- while (readyList.length) {
57
- readyList.shift().call(globalThis, []);
58
- }
59
-
60
- // Remember that the DOM is ready
61
- isReady = true;
62
- }
63
- };
64
-
65
27
  // a cache DOMRect object
66
28
  let _domRect = {left: 0, top: 0, x: 0, y: 0, width: 0, height: 0, right: 0, bottom: 0};
67
29
 
@@ -418,7 +380,7 @@ let device = {
418
380
  * @readonly
419
381
  * @name nodeJS
420
382
  */
421
- nodeJS : (typeof process !== "undefined") && (process.release.name === "node"),
383
+ nodeJS : (typeof globalThis.process !== "undefined") && (typeof globalThis.process.release !== "undefined") && (globalThis.process.release.name === "node"),
422
384
 
423
385
  /**
424
386
  * equals to true if the device is running on ChromeOS.
@@ -606,33 +568,7 @@ let device = {
606
568
  * });
607
569
  */
608
570
  onReady(fn) {
609
- // If the DOM is already ready
610
- if (isReady) {
611
- // Execute the function immediately
612
- fn.call(globalThis, []);
613
- }
614
- else {
615
- // Add the function to the wait list
616
- readyList.push(fn);
617
-
618
- // attach listeners if not yet done
619
- if (!readyBound) {
620
- // directly call domReady if document is already "ready"
621
- if (device.nodeJS === true || (typeof globalThis.document !== "undefined" && globalThis.document.readyState === "complete")) {
622
- // defer the fn call to ensure our script is fully loaded
623
- globalThis.setTimeout(_domReady, 0);
624
- }
625
- else {
626
- if (typeof globalThis.document !== "undefined" && typeof globalThis.document.addEventListener === "function") {
627
- // Use the handy event callback
628
- globalThis.document.addEventListener("DOMContentLoaded", _domReady, false);
629
- }
630
- // A fallback to globalThis.onload, that will always work
631
- globalThis.addEventListener("load", _domReady, false);
632
- }
633
- readyBound = true;
634
- }
635
- }
571
+ DOMContentLoaded(fn);
636
572
  },
637
573
 
638
574
  /**
@@ -0,0 +1,69 @@
1
+ import * as event from "./event.js";
2
+
3
+ // track if DOMContentLoaded was called already
4
+ let readyBound = false;
5
+
6
+ // is the DOM ready ?
7
+ let isDOMReady = false;
8
+
9
+ // check if the dom is ready
10
+ function _domReady() {
11
+
12
+ // Make sure that the DOM is not already loaded
13
+ if (!isDOMReady) {
14
+ // be sure document.body is there
15
+ if (typeof globalThis.document !== "undefined" && !globalThis.document.body) {
16
+ return setTimeout(_domReady, 13);
17
+ }
18
+
19
+ // clean up loading event
20
+ if (typeof globalThis.document !== "undefined" && typeof globalThis.document.removeEventListener === "function") {
21
+ globalThis.document.removeEventListener(
22
+ "DOMContentLoaded",
23
+ _domReady,
24
+ false
25
+ );
26
+ }
27
+
28
+ if (typeof globalThis.removeEventListener === "function") {
29
+ // remove the event on globalThis.onload (always added in `onReady`)
30
+ globalThis.removeEventListener("load", _domReady, false);
31
+ }
32
+
33
+ // execute all callbacks
34
+ event.emit(event.DOM_READY);
35
+
36
+ // Remember that the DOM is ready
37
+ isDOMReady = true;
38
+ }
39
+ };
40
+
41
+ // https://developer.mozilla.org/en-US/docs/Web/API/Window/DOMContentLoaded_event
42
+ export function DOMContentLoaded(fn) {
43
+ // If the DOM is already ready
44
+ if (isDOMReady) {
45
+ // Execute the function immediately
46
+ fn.call(globalThis, []);
47
+ }
48
+ else {
49
+ // else add the function to the DOM_READY event
50
+ event.once(event.DOM_READY, fn, globalThis);
51
+ // bind dom load event if not done yet
52
+ if (!readyBound) {
53
+ // directly call domReady if document is already "ready"
54
+ if (((typeof process !== "undefined") && (process.release.name === "node")) || (typeof globalThis.document !== "undefined" && globalThis.document.readyState === "complete")) {
55
+ // defer the fn call to ensure our script is fully loaded
56
+ globalThis.setTimeout(_domReady, 0);
57
+ }
58
+ else {
59
+ if (typeof globalThis.document !== "undefined" && typeof globalThis.document.addEventListener === "function") {
60
+ // Use the handy event callback
61
+ globalThis.document.addEventListener("DOMContentLoaded", _domReady, false);
62
+ }
63
+ // A fallback to globalThis.onload, that will always work
64
+ globalThis.addEventListener("load", _domReady, false);
65
+ }
66
+ readyBound = true;
67
+ }
68
+ }
69
+ }
@@ -8,6 +8,17 @@ import EventEmitter from "eventemitter3";
8
8
  // internal instance of the event emiter
9
9
  var eventEmitter = new EventEmitter();
10
10
 
11
+ /**
12
+ * event when the DOM is Ready is booting
13
+ * @public
14
+ * @constant
15
+ * @type {string}
16
+ * @name DOM_READY
17
+ * @memberof event
18
+ * @see event.on
19
+ */
20
+ export const DOM_READY = "dom_ready";
21
+
11
22
  /**
12
23
  * event when the system is booting
13
24
  * @public