@urso/core 0.8.23 → 0.8.25

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.
@@ -149,7 +149,7 @@ object-assign
149
149
  */
150
150
 
151
151
  /*!
152
- * GSAP 3.13.0
152
+ * GSAP 3.14.2
153
153
  * https://gsap.com
154
154
  *
155
155
  * @license Copyright 2008-2025, GreenSock. All rights reserved.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@urso/core",
3
- "version": "0.8.23",
3
+ "version": "0.8.25",
4
4
  "description": "HTML5 game engine",
5
5
  "main": "build/js/index.js",
6
6
  "author": "Megbrimef",
@@ -11,7 +11,8 @@ let ConfigMain = {
11
11
  fps: {
12
12
  limit: 60, //max fps limit
13
13
  optimizeLowPerformance: false //down to 30 fps if lower 60
14
- }
14
+ },
15
+ domParentSelector: false //or '#app-container' - div selector, to append canvas
15
16
  };
16
17
 
17
18
  module.exports = ConfigMain;
@@ -12,6 +12,7 @@ class ModulesObserverConfig {
12
12
  EXTRA_BROWSEREVENTS_POINTER_EVENT: 'extra.browserEvents.window.pointer.event',
13
13
  EXTRA_BROWSEREVENTS_WINDOW_PRE_RESIZE: 'extra.browserEvents.window.pre.resize',
14
14
  EXTRA_BROWSEREVENTS_WINDOW_RESIZE: 'extra.browserEvents.window.resize',
15
+ EXTRA_BROWSEREVENTS_PARENT_RESIZE: 'extra.browserEvents.parent.resize',
15
16
  EXTRA_BROWSEREVENTS_WINDOW_VISIBILITYCHANGE: 'extra.browserEvents.window.visibilitychange',
16
17
  MODULES_ASSETS_GROUP_LOADED: 'modules.assets.group.loaded',
17
18
  MODULES_ASSETS_LOAD_PROGRESS: 'modules.assets.load.progress',
@@ -35,7 +35,23 @@ class ModulesScenesPixiWrapper {
35
35
  //define renderer
36
36
  PIXI.utils.skipHello();
37
37
  this._renderer = new PIXI.Renderer({ preserveDrawingBuffer: true, width: 1, height: 1 });
38
- document.body.appendChild(this._renderer.view);
38
+ let parentContainer = document.body;
39
+
40
+ if (Urso.config.domParentSelector) {
41
+ const container = document.querySelector(Urso.config.domParentSelector);
42
+
43
+ if (container) {
44
+ parentContainer = container;
45
+ } else {
46
+ Urso.logger.warn(`No element found for domParentSelector: ${Urso.config.domParentSelector}`);
47
+ Urso.logger.warn(`waitForDomElement...`);
48
+ Urso.helper.waitForDomElement(Urso.config.domParentSelector).then(() => {
49
+ parentContainer.appendChild(this._renderer.view);
50
+ });
51
+ }
52
+ }
53
+
54
+ parentContainer.appendChild(this._renderer.view);
39
55
 
40
56
  //root and world
41
57
  this._root = new PIXI.Container();
@@ -10,6 +10,9 @@ class ModulesScenesResolutions {
10
10
  this.preResize = this.preResize.bind(this);
11
11
  this.refreshSceneSize();
12
12
 
13
+ this._customDomElementlatestWidth = 0;
14
+ this._customDomElementlatestHeight = 0;
15
+
13
16
  //TODO optimization (performance)
14
17
  /*if (devicePixelRatio > 2)
15
18
  devicePixelRatio = 2;*/ // when we are calculating canvas size
@@ -18,7 +21,52 @@ class ModulesScenesResolutions {
18
21
  _subscribeOnce() {
19
22
  this.addListener(Urso.events.EXTRA_BROWSEREVENTS_WINDOW_PRE_RESIZE, this.preResize, true);
20
23
  this.addListener(Urso.events.EXTRA_BROWSEREVENTS_WINDOW_RESIZE, this.refreshSceneSize, true);
24
+ this.addListener(Urso.events.EXTRA_BROWSEREVENTS_PARENT_RESIZE, this.refreshSceneSize, true);
21
25
  this.addListener(Urso.events.MODULES_SCENES_NEW_SCENE_INIT, this.refreshSceneSize, true);
26
+
27
+ if (Urso.config.domParentSelector) { this._observeCustomDomElementResize(); }
28
+ }
29
+
30
+ _observeCustomDomElementResize() {
31
+ const container = document.querySelector(Urso.config.domParentSelector);
32
+
33
+ if (!container) {
34
+ Urso.logger.warn(`No element found for domParentSelector: ${Urso.config.domParentSelector}`);
35
+ Urso.logger.warn(`waitForDomElement...`);
36
+ Urso.helper.waitForDomElement(Urso.config.domParentSelector).then(() => {
37
+ this._observeCustomDomElementResize();
38
+ });
39
+ return;
40
+ }
41
+
42
+ const ro = new ResizeObserver((entries) => {
43
+ for (const entry of entries) {
44
+ if (entry.target.resizeHandler) {
45
+ entry.target.resizeHandler(entry.target.clientHeight, entry.target.clientWidth);
46
+ }
47
+ }
48
+ });
49
+
50
+ container.resizeHandler = this._customDomElementResizeHandler.bind(this);
51
+ ro.observe(container);
52
+ }
53
+
54
+ _customDomElementResizeHandler(newHeight, newWidth) {
55
+ let needResize = false;
56
+
57
+ if (this._customDomElementlatestWidth !== newWidth) {
58
+ this._customDomElementlatestWidth = newWidth;
59
+ needResize = true;
60
+ }
61
+
62
+ if (this._customDomElementlatestHeight !== newHeight) {
63
+ this._customDomElementlatestHeight = newHeight;
64
+ needResize = true;
65
+ }
66
+
67
+ if (needResize) {
68
+ this.emit(Urso.events.EXTRA_BROWSEREVENTS_PARENT_RESIZE);
69
+ }
22
70
  }
23
71
 
24
72
  getTemplateSize() {
@@ -73,6 +121,17 @@ class ModulesScenesResolutions {
73
121
  height: window.innerHeight
74
122
  };
75
123
 
124
+ if (Urso.config.domParentSelector) {
125
+ const container = document.querySelector(Urso.config.domParentSelector);
126
+
127
+ if (container) {
128
+ windowSize = {
129
+ width: container.offsetWidth,
130
+ height: container.offsetHeight
131
+ };
132
+ }
133
+ }
134
+
76
135
  if (window.devicePixelRatio && window.devicePixelRatio !== 1) {
77
136
  windowSize.width *= window.devicePixelRatio;
78
137
  windowSize.height *= window.devicePixelRatio;