@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
|
|
144
|
-
//
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
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
|
-
|
|
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
|
|
153
|
-
|
|
154
|
-
|
|
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
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
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
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
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
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
gameHeightOnPortrait = availHeight;
|
|
202
|
-
}
|
|
209
|
+
gameWidthOnPortrait = getGameWidthOnPortrait({
|
|
210
|
+
windowWidth: availWidth,
|
|
211
|
+
windowHeight: availHeight,
|
|
212
|
+
aspectOnPortrait
|
|
213
|
+
});
|
|
203
214
|
|
|
204
|
-
|
|
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
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
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
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
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
|
}, {}, "">;
|