@hkdigital/lib-core 0.5.30 → 0.5.32

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.
@@ -53,6 +53,7 @@
53
53
  * snippetPortrait?: GameBoxSnippet,
54
54
  * snippetRequireFullscreen?: GameBoxSnippet,
55
55
  * snippetInstallOnHomeScreen?: GameBoxSnippet,
56
+ * debug?: boolean,
56
57
  * [attr: string]: any
57
58
  * }}
58
59
  */
@@ -84,7 +85,9 @@
84
85
  snippetLandscape,
85
86
  snippetPortrait,
86
87
  snippetRequireFullscreen,
87
- snippetInstallOnHomeScreen
88
+ snippetInstallOnHomeScreen,
89
+
90
+ debug = false
88
91
  } = $props();
89
92
 
90
93
  // > Game dimensions and state
@@ -140,18 +143,31 @@
140
143
  });
141
144
 
142
145
  $effect(() => {
143
- // Use matchMedia for orientation detection (works on all iOS versions)
144
- // This is more reliable than screen.orientation.angle
145
- const isPortraitMedia =
146
- typeof window !== 'undefined' &&
147
- window.matchMedia('(orientation: portrait)').matches;
146
+ // Use matchMedia as a trigger for orientation changes
147
+ // The actual orientation is determined in updateIosWidthHeight()
148
+ if (typeof window !== 'undefined') {
149
+ const isPortraitMedia =
150
+ window.matchMedia('(orientation: portrait)').matches;
148
151
 
149
- isLandscape = !isPortraitMedia;
152
+ // Trigger iOS dimension update when orientation might have changed
153
+ if (isPwa && isAppleMobile) {
154
+ updateIosWidthHeight();
155
+ } else {
156
+ // For non-iOS, matchMedia is reliable
157
+ isLandscape = !isPortraitMedia;
158
+ }
159
+ }
150
160
  });
151
161
 
152
- // $inspect('isLandscape', isLandscape);
153
- // $inspect('windowWidth/Height', windowWidth, windowHeight);
154
- // $inspect('iosWindowWidth/Height', iosWindowWidth, iosWindowHeight);
162
+ // Use $effect for conditional debugging instead of $inspect
163
+ $effect(() => {
164
+ if (debug) {
165
+ console.log('[GameBox] isLandscape:', isLandscape);
166
+ console.log('[GameBox] windowWidth/Height:', windowWidth, windowHeight);
167
+ console.log('[GameBox] iosWindowWidth/Height:',
168
+ iosWindowWidth, iosWindowHeight);
169
+ }
170
+ });
155
171
 
156
172
  // Update game dimensions based on window size and orientation
157
173
  $effect(() => {
@@ -163,45 +179,45 @@
163
179
  const availWidth = width - marginLeft - marginRight;
164
180
  const availHeight = height - marginTop - marginBottom;
165
181
 
166
- // console.debug('GameBox margins:', {
167
- // marginLeft,
168
- // marginRight,
169
- // marginTop,
170
- // marginBottom
171
- // });
172
-
173
- if (availWidth > availHeight) {
174
- gameWidthOnLandscape = getGameWidthOnLandscape({
175
- windowWidth: availWidth,
176
- windowHeight: availHeight,
177
- aspectOnLandscape
182
+ if( debug )
183
+ {
184
+ console.debug('GameBox margins:', {
185
+ marginLeft,
186
+ marginRight,
187
+ marginTop,
188
+ marginBottom
178
189
  });
190
+ }
179
191
 
180
- if( aspectOnLandscape )
181
- {
182
- gameHeightOnLandscape = gameWidthOnLandscape / aspectOnLandscape;
183
- }
184
- else {
185
- gameHeightOnLandscape = availHeight;
186
- }
187
-
188
- isLandscape = true;
189
- } else {
190
- gameWidthOnPortrait = getGameWidthOnPortrait({
191
- windowWidth: availWidth,
192
- windowHeight: availHeight,
193
- aspectOnPortrait
194
- });
192
+ // Calculate game dimensions for both orientations
193
+ // Orientation is determined by matchMedia/screen.orientation.angle,
194
+ // not by dimension comparison
195
+ gameWidthOnLandscape = getGameWidthOnLandscape({
196
+ windowWidth: availWidth,
197
+ windowHeight: availHeight,
198
+ aspectOnLandscape
199
+ });
200
+
201
+ if( aspectOnLandscape )
202
+ {
203
+ gameHeightOnLandscape = gameWidthOnLandscape / aspectOnLandscape;
204
+ }
205
+ else {
206
+ gameHeightOnLandscape = availHeight;
207
+ }
195
208
 
196
- if( aspectOnPortrait )
197
- {
198
- gameHeightOnPortrait = gameWidthOnPortrait / aspectOnPortrait;
199
- }
200
- else {
201
- gameHeightOnPortrait = availHeight;
202
- }
209
+ gameWidthOnPortrait = getGameWidthOnPortrait({
210
+ windowWidth: availWidth,
211
+ windowHeight: availHeight,
212
+ aspectOnPortrait
213
+ });
203
214
 
204
- isLandscape = false;
215
+ if( aspectOnPortrait )
216
+ {
217
+ gameHeightOnPortrait = gameWidthOnPortrait / aspectOnPortrait;
218
+ }
219
+ else {
220
+ gameHeightOnPortrait = availHeight;
205
221
  }
206
222
  });
207
223
 
@@ -222,6 +238,10 @@
222
238
  if (isPwa && isAppleMobile) {
223
239
  const angle = screen.orientation.angle;
224
240
 
241
+ // Use screen.orientation.angle as the source of truth
242
+ // angle 90/270 = landscape, angle 0/180 = portrait
243
+ isLandscape = (angle === 90 || angle === 270);
244
+
225
245
  // Use window.inner dimensions instead of screen dimensions
226
246
  // because screen.width/height don't rotate on iOS PWA
227
247
  if (angle === 90 || angle === 270) {
@@ -231,13 +251,18 @@
231
251
  iosWindowWidth = window.innerWidth;
232
252
  iosWindowHeight = window.innerHeight;
233
253
  }
234
- // console.debug('updateIosWidthHeight', {
235
- // angle,
236
- // 'window.innerWidth': window.innerWidth,
237
- // 'window.innerHeight': window.innerHeight,
238
- // iosWindowWidth,
239
- // iosWindowHeight
240
- // });
254
+
255
+ if( debug )
256
+ {
257
+ console.debug('updateIosWidthHeight', {
258
+ angle,
259
+ isLandscape,
260
+ 'window.innerWidth': window.innerWidth,
261
+ 'window.innerHeight': window.innerHeight,
262
+ iosWindowWidth,
263
+ iosWindowHeight
264
+ });
265
+ }
241
266
  }
242
267
  }
243
268
 
@@ -259,11 +284,12 @@
259
284
  // Listen for orientation changes using matchMedia (works on all iOS)
260
285
  const portraitMediaQuery = window.matchMedia('(orientation: portrait)');
261
286
  const handleOrientationChange = (e) => {
262
- isLandscape = !e.matches;
263
-
264
287
  // Update iOS dimensions if needed
265
288
  if (isPwa && isAppleMobile) {
266
289
  updateIosWidthHeight();
290
+ } else {
291
+ // For non-iOS, matchMedia is reliable
292
+ isLandscape = !e.matches;
267
293
  }
268
294
  };
269
295
  portraitMediaQuery.addEventListener('change', handleOrientationChange);
@@ -271,21 +297,24 @@
271
297
  // App visibility detection for iOS debugging
272
298
  const handleVisibilityChange = () => {
273
299
  if (document.visibilityState === 'visible') {
274
- // console.log('App became visible:', {
275
- // 'window.innerWidth': window.innerWidth,
276
- // 'window.innerHeight': window.innerHeight,
277
- // 'screen.width': screen.width,
278
- // 'screen.height': screen.height,
279
- // 'screen.orientation.angle': screen.orientation.angle,
280
- // 'screen.orientation.type': screen.orientation.type,
281
- // 'matchMedia portrait':
282
- // window.matchMedia('(orientation: portrait)').matches,
283
- // 'isLandscape': isLandscape,
284
- // 'gameWidth': gameWidth,
285
- // 'gameHeight': gameHeight,
286
- // 'iosWindowWidth': iosWindowWidth,
287
- // 'iosWindowHeight': iosWindowHeight
288
- // });
300
+
301
+ if( debug ) {
302
+ console.log('App became visible:', {
303
+ 'window.innerWidth': window.innerWidth,
304
+ 'window.innerHeight': window.innerHeight,
305
+ 'screen.width': screen.width,
306
+ 'screen.height': screen.height,
307
+ 'screen.orientation.angle': screen.orientation.angle,
308
+ 'screen.orientation.type': screen.orientation.type,
309
+ 'matchMedia portrait':
310
+ window.matchMedia('(orientation: portrait)').matches,
311
+ 'isLandscape': isLandscape,
312
+ 'gameWidth': gameWidth,
313
+ 'gameHeight': gameHeight,
314
+ 'iosWindowWidth': iosWindowWidth,
315
+ 'iosWindowHeight': iosWindowHeight
316
+ });
317
+ }
289
318
 
290
319
  // Force iOS dimension update when app becomes visible
291
320
  if (isPwa && isAppleMobile) {
@@ -45,6 +45,7 @@ type GameBox = {
45
45
  snippetPortrait?: Snippet<[SnippetParams]> | undefined;
46
46
  snippetRequireFullscreen?: Snippet<[SnippetParams]> | undefined;
47
47
  snippetInstallOnHomeScreen?: Snippet<[SnippetParams]> | undefined;
48
+ debug?: boolean | undefined;
48
49
  }>): void;
49
50
  };
50
51
  declare const GameBox: import("svelte").Component<{
@@ -91,4 +92,5 @@ declare const GameBox: import("svelte").Component<{
91
92
  snippetPortrait?: import("svelte").Snippet<[import("./typedef.js").SnippetParams]>;
92
93
  snippetRequireFullscreen?: import("svelte").Snippet<[import("./typedef.js").SnippetParams]>;
93
94
  snippetInstallOnHomeScreen?: import("svelte").Snippet<[import("./typedef.js").SnippetParams]>;
95
+ debug?: boolean;
94
96
  }, {}, "">;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hkdigital/lib-core",
3
- "version": "0.5.30",
3
+ "version": "0.5.32",
4
4
  "author": {
5
5
  "name": "HKdigital",
6
6
  "url": "https://hkdigital.nl"