@hkdigital/lib-core 0.5.31 → 0.5.33

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.
@@ -143,13 +143,20 @@
143
143
  });
144
144
 
145
145
  $effect(() => {
146
- // Use matchMedia for orientation detection (works on all iOS versions)
147
- // This is more reliable than screen.orientation.angle
148
- const isPortraitMedia =
149
- typeof window !== 'undefined' &&
150
- 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;
151
151
 
152
- 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
+ }
153
160
  });
154
161
 
155
162
  // Use $effect for conditional debugging instead of $inspect
@@ -183,6 +190,9 @@
183
190
  }
184
191
 
185
192
  if (availWidth > availHeight) {
193
+ // Calculate game dimensions for both orientations
194
+ // Orientation is determined by matchMedia/screen.orientation.angle,
195
+ // not by dimension comparison
186
196
  gameWidthOnLandscape = getGameWidthOnLandscape({
187
197
  windowWidth: availWidth,
188
198
  windowHeight: availHeight,
@@ -196,9 +206,8 @@
196
206
  else {
197
207
  gameHeightOnLandscape = availHeight;
198
208
  }
199
-
200
- isLandscape = true;
201
- } else {
209
+ }
210
+ else {
202
211
  gameWidthOnPortrait = getGameWidthOnPortrait({
203
212
  windowWidth: availWidth,
204
213
  windowHeight: availHeight,
@@ -212,9 +221,8 @@
212
221
  else {
213
222
  gameHeightOnPortrait = availHeight;
214
223
  }
215
-
216
- isLandscape = false;
217
224
  }
225
+
218
226
  });
219
227
 
220
228
  let show = $state(false);
@@ -234,6 +242,10 @@
234
242
  if (isPwa && isAppleMobile) {
235
243
  const angle = screen.orientation.angle;
236
244
 
245
+ // Use screen.orientation.angle as the source of truth
246
+ // angle 90/270 = landscape, angle 0/180 = portrait
247
+ isLandscape = (angle === 90 || angle === 270);
248
+
237
249
  // Use window.inner dimensions instead of screen dimensions
238
250
  // because screen.width/height don't rotate on iOS PWA
239
251
  if (angle === 90 || angle === 270) {
@@ -248,6 +260,7 @@
248
260
  {
249
261
  console.debug('updateIosWidthHeight', {
250
262
  angle,
263
+ isLandscape,
251
264
  'window.innerWidth': window.innerWidth,
252
265
  'window.innerHeight': window.innerHeight,
253
266
  iosWindowWidth,
@@ -275,11 +288,12 @@
275
288
  // Listen for orientation changes using matchMedia (works on all iOS)
276
289
  const portraitMediaQuery = window.matchMedia('(orientation: portrait)');
277
290
  const handleOrientationChange = (e) => {
278
- isLandscape = !e.matches;
279
-
280
291
  // Update iOS dimensions if needed
281
292
  if (isPwa && isAppleMobile) {
282
293
  updateIosWidthHeight();
294
+ } else {
295
+ // For non-iOS, matchMedia is reliable
296
+ isLandscape = !e.matches;
283
297
  }
284
298
  };
285
299
  portraitMediaQuery.addEventListener('change', handleOrientationChange);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hkdigital/lib-core",
3
- "version": "0.5.31",
3
+ "version": "0.5.33",
4
4
  "author": {
5
5
  "name": "HKdigital",
6
6
  "url": "https://hkdigital.nl"