@hkdigital/lib-core 0.5.31 → 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.
@@ -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
@@ -182,38 +189,35 @@
182
189
  });
183
190
  }
184
191
 
185
- if (availWidth > availHeight) {
186
- gameWidthOnLandscape = getGameWidthOnLandscape({
187
- windowWidth: availWidth,
188
- windowHeight: availHeight,
189
- aspectOnLandscape
190
- });
191
-
192
- if( aspectOnLandscape )
193
- {
194
- gameHeightOnLandscape = gameWidthOnLandscape / aspectOnLandscape;
195
- }
196
- else {
197
- gameHeightOnLandscape = availHeight;
198
- }
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
+ });
199
200
 
200
- isLandscape = true;
201
- } else {
202
- gameWidthOnPortrait = getGameWidthOnPortrait({
203
- windowWidth: availWidth,
204
- windowHeight: availHeight,
205
- aspectOnPortrait
206
- });
201
+ if( aspectOnLandscape )
202
+ {
203
+ gameHeightOnLandscape = gameWidthOnLandscape / aspectOnLandscape;
204
+ }
205
+ else {
206
+ gameHeightOnLandscape = availHeight;
207
+ }
207
208
 
208
- if( aspectOnPortrait )
209
- {
210
- gameHeightOnPortrait = gameWidthOnPortrait / aspectOnPortrait;
211
- }
212
- else {
213
- gameHeightOnPortrait = availHeight;
214
- }
209
+ gameWidthOnPortrait = getGameWidthOnPortrait({
210
+ windowWidth: availWidth,
211
+ windowHeight: availHeight,
212
+ aspectOnPortrait
213
+ });
215
214
 
216
- isLandscape = false;
215
+ if( aspectOnPortrait )
216
+ {
217
+ gameHeightOnPortrait = gameWidthOnPortrait / aspectOnPortrait;
218
+ }
219
+ else {
220
+ gameHeightOnPortrait = availHeight;
217
221
  }
218
222
  });
219
223
 
@@ -234,6 +238,10 @@
234
238
  if (isPwa && isAppleMobile) {
235
239
  const angle = screen.orientation.angle;
236
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
+
237
245
  // Use window.inner dimensions instead of screen dimensions
238
246
  // because screen.width/height don't rotate on iOS PWA
239
247
  if (angle === 90 || angle === 270) {
@@ -248,6 +256,7 @@
248
256
  {
249
257
  console.debug('updateIosWidthHeight', {
250
258
  angle,
259
+ isLandscape,
251
260
  'window.innerWidth': window.innerWidth,
252
261
  'window.innerHeight': window.innerHeight,
253
262
  iosWindowWidth,
@@ -275,11 +284,12 @@
275
284
  // Listen for orientation changes using matchMedia (works on all iOS)
276
285
  const portraitMediaQuery = window.matchMedia('(orientation: portrait)');
277
286
  const handleOrientationChange = (e) => {
278
- isLandscape = !e.matches;
279
-
280
287
  // Update iOS dimensions if needed
281
288
  if (isPwa && isAppleMobile) {
282
289
  updateIosWidthHeight();
290
+ } else {
291
+ // For non-iOS, matchMedia is reliable
292
+ isLandscape = !e.matches;
283
293
  }
284
294
  };
285
295
  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.32",
4
4
  "author": {
5
5
  "name": "HKdigital",
6
6
  "url": "https://hkdigital.nl"