@vpmedia/phaser 1.122.0 → 1.123.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vpmedia/phaser",
3
- "version": "1.122.0",
3
+ "version": "1.123.0",
4
4
  "description": "@vpmedia/phaser is the modern ECMAScript port of the popular Phaser game engine v2.6.2",
5
5
  "author": "Andras Csizmadia <andras@vpmedia.hu> (www.vpmedia.hu)",
6
6
  "license": "MIT",
@@ -61,6 +61,13 @@ describe('canvas util', () => {
61
61
  expect(canvas.parentElement).toBe(document.body);
62
62
  });
63
63
 
64
+ // An empty id used to build the selector `#`, which throws before the body fallback is reached.
65
+ it('falls back to the body for an empty id', () => {
66
+ const canvas = createCanvas();
67
+ addToDOM(canvas, '');
68
+ expect(canvas.parentElement).toBe(document.body);
69
+ });
70
+
64
71
  it('hides the parent overflow unless told not to', () => {
65
72
  const host = document.createElement('div');
66
73
  document.body.append(host);
@@ -83,10 +83,10 @@ export const addToDOM = (
83
83
  overflowHidden = true
84
84
  ): HTMLCanvasElement => {
85
85
  let target: HTMLElement | null = null;
86
- if (typeof parent === 'string') {
86
+ if (typeof parent === 'string' && parent !== '') {
87
87
  // hopefully an element ID
88
88
  target = document.querySelector<HTMLElement>(`#${CSS.escape(parent)}`);
89
- } else if (parent?.nodeType === 1) {
89
+ } else if (typeof parent === 'object' && parent?.nodeType === 1) {
90
90
  target = parent;
91
91
  }
92
92
  // Fallback, covers an invalid ID and a non HTMLelement object