@hkdigital/lib-core 0.5.4 → 0.5.5
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.
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
getGameWidthOnPortrait
|
|
7
7
|
} from './gamebox.util.js';
|
|
8
8
|
|
|
9
|
-
import
|
|
9
|
+
import ScaledContainer from './ScaledContainer.svelte';
|
|
10
10
|
|
|
11
11
|
/**
|
|
12
12
|
* @typedef {{
|
|
@@ -193,9 +193,6 @@
|
|
|
193
193
|
$inspect('windowWidth/Height', windowWidth, windowHeight);
|
|
194
194
|
$inspect('iosWindowWidth/Height', iosWindowWidth, iosWindowHeight);
|
|
195
195
|
|
|
196
|
-
// Game container reference
|
|
197
|
-
let gameContainer = $state();
|
|
198
|
-
|
|
199
196
|
// Update game dimensions based on window size and orientation
|
|
200
197
|
$effect(() => {
|
|
201
198
|
const width = iosWindowWidth ?? windowWidth;
|
|
@@ -248,33 +245,6 @@
|
|
|
248
245
|
}
|
|
249
246
|
});
|
|
250
247
|
|
|
251
|
-
// Set up scaling if enabled, with orientation awareness
|
|
252
|
-
$effect(() => {
|
|
253
|
-
if (!enableScaling || !gameContainer || !gameWidth || !gameHeight) {
|
|
254
|
-
return () => {}; // No-op cleanup if scaling not enabled or required elements missing
|
|
255
|
-
}
|
|
256
|
-
|
|
257
|
-
// Select the appropriate design based on orientation
|
|
258
|
-
const activeDesign = isLandscape ? designLandscape : designPortrait;
|
|
259
|
-
|
|
260
|
-
// console.debug(
|
|
261
|
-
// `GameBox scaling [${isLandscape ? 'landscape' : 'portrait'}]:`,
|
|
262
|
-
// `game: ${gameWidth}x${gameHeight}`,
|
|
263
|
-
// `design: ${activeDesign.width}x${activeDesign.height}`
|
|
264
|
-
// );
|
|
265
|
-
|
|
266
|
-
// Apply scaling with the current design based on orientation
|
|
267
|
-
return enableContainerScaling({
|
|
268
|
-
container: gameContainer,
|
|
269
|
-
design: activeDesign,
|
|
270
|
-
clamping,
|
|
271
|
-
getDimensions: () => ({
|
|
272
|
-
width: gameWidth,
|
|
273
|
-
height: gameHeight
|
|
274
|
-
})
|
|
275
|
-
});
|
|
276
|
-
});
|
|
277
|
-
|
|
278
248
|
let show = $state(false);
|
|
279
249
|
|
|
280
250
|
let isPwa = $state(false);
|
|
@@ -460,7 +430,6 @@
|
|
|
460
430
|
<div
|
|
461
431
|
data-component="game-box"
|
|
462
432
|
data-orientation={isLandscape ? 'landscape' : 'portrait'}
|
|
463
|
-
bind:this={gameContainer}
|
|
464
433
|
class="{base} {bg} {classes}"
|
|
465
434
|
class:isMobile
|
|
466
435
|
style:width="{gameWidth}px"
|
|
@@ -476,10 +445,13 @@
|
|
|
476
445
|
<!-- Require fullscreen -->
|
|
477
446
|
{#if isFullscreen && !isDevMode}
|
|
478
447
|
<!-- Landscape content -->
|
|
479
|
-
<
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
448
|
+
<ScaledContainer
|
|
449
|
+
enableScaling={enableScaling}
|
|
450
|
+
design={designLandscape}
|
|
451
|
+
{clamping}
|
|
452
|
+
width={gameWidthOnLandscape}
|
|
453
|
+
height={gameHeightOnLandscape}
|
|
454
|
+
hidden={!isLandscape}
|
|
483
455
|
>
|
|
484
456
|
{@render snippetLandscape({
|
|
485
457
|
isLandscape,
|
|
@@ -495,12 +467,15 @@
|
|
|
495
467
|
gameWidth,
|
|
496
468
|
gameHeight
|
|
497
469
|
})}
|
|
498
|
-
</
|
|
470
|
+
</ScaledContainer>
|
|
499
471
|
<!-- Portrait content -->
|
|
500
|
-
<
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
472
|
+
<ScaledContainer
|
|
473
|
+
enableScaling={enableScaling}
|
|
474
|
+
design={designPortrait}
|
|
475
|
+
{clamping}
|
|
476
|
+
width={gameWidthOnPortrait}
|
|
477
|
+
height={gameHeightOnPortrait}
|
|
478
|
+
hidden={isLandscape}
|
|
504
479
|
>
|
|
505
480
|
{@render snippetPortrait({
|
|
506
481
|
isLandscape,
|
|
@@ -516,10 +491,16 @@
|
|
|
516
491
|
gameWidth,
|
|
517
492
|
gameHeight
|
|
518
493
|
})}
|
|
519
|
-
</
|
|
494
|
+
</ScaledContainer>
|
|
520
495
|
{:else if supportsFullscreen && !isDevMode}
|
|
521
496
|
<!-- Require fullscreen -->
|
|
522
|
-
<
|
|
497
|
+
<ScaledContainer
|
|
498
|
+
enableScaling={enableScaling}
|
|
499
|
+
design={isLandscape ? designLandscape : designPortrait}
|
|
500
|
+
{clamping}
|
|
501
|
+
width={gameWidth}
|
|
502
|
+
height={gameHeight}
|
|
503
|
+
>
|
|
523
504
|
{@render snippetRequireFullscreen({
|
|
524
505
|
isLandscape,
|
|
525
506
|
isPortrait: !isLandscape,
|
|
@@ -534,10 +515,16 @@
|
|
|
534
515
|
gameWidth,
|
|
535
516
|
gameHeight
|
|
536
517
|
})}
|
|
537
|
-
</
|
|
518
|
+
</ScaledContainer>
|
|
538
519
|
{:else if isMobile && snippetInstallOnHomeScreen && !isDevMode}
|
|
539
520
|
<!-- Require install on home screen on mobile -->
|
|
540
|
-
<
|
|
521
|
+
<ScaledContainer
|
|
522
|
+
enableScaling={enableScaling}
|
|
523
|
+
design={isLandscape ? designLandscape : designPortrait}
|
|
524
|
+
{clamping}
|
|
525
|
+
width={gameWidth}
|
|
526
|
+
height={gameHeight}
|
|
527
|
+
>
|
|
541
528
|
{@render snippetInstallOnHomeScreen({
|
|
542
529
|
isLandscape,
|
|
543
530
|
isPortrait: !isLandscape,
|
|
@@ -552,13 +539,16 @@
|
|
|
552
539
|
gameWidth,
|
|
553
540
|
gameHeight
|
|
554
541
|
})}
|
|
555
|
-
</
|
|
542
|
+
</ScaledContainer>
|
|
556
543
|
{:else}
|
|
557
544
|
<!-- Landscape content -->
|
|
558
|
-
<
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
545
|
+
<ScaledContainer
|
|
546
|
+
enableScaling={enableScaling}
|
|
547
|
+
design={designLandscape}
|
|
548
|
+
{clamping}
|
|
549
|
+
width={gameWidthOnLandscape}
|
|
550
|
+
height={gameHeightOnLandscape}
|
|
551
|
+
hidden={!isLandscape}
|
|
562
552
|
>
|
|
563
553
|
{@render snippetLandscape({
|
|
564
554
|
isLandscape,
|
|
@@ -574,12 +564,15 @@
|
|
|
574
564
|
gameWidth,
|
|
575
565
|
gameHeight
|
|
576
566
|
})}
|
|
577
|
-
</
|
|
567
|
+
</ScaledContainer>
|
|
578
568
|
<!-- Portrait content -->
|
|
579
|
-
<
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
569
|
+
<ScaledContainer
|
|
570
|
+
enableScaling={enableScaling}
|
|
571
|
+
design={designPortrait}
|
|
572
|
+
{clamping}
|
|
573
|
+
width={gameWidthOnPortrait}
|
|
574
|
+
height={gameHeightOnPortrait}
|
|
575
|
+
hidden={isLandscape}
|
|
583
576
|
>
|
|
584
577
|
{@render snippetPortrait({
|
|
585
578
|
isLandscape,
|
|
@@ -595,15 +588,18 @@
|
|
|
595
588
|
gameWidth,
|
|
596
589
|
gameHeight
|
|
597
590
|
})}
|
|
598
|
-
</
|
|
591
|
+
</ScaledContainer>
|
|
599
592
|
{/if}
|
|
600
593
|
{:else}
|
|
601
594
|
<!-- Do not require fullscreen -->
|
|
602
595
|
<!-- Landscape content -->
|
|
603
|
-
<
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
596
|
+
<ScaledContainer
|
|
597
|
+
enableScaling={enableScaling}
|
|
598
|
+
design={designLandscape}
|
|
599
|
+
{clamping}
|
|
600
|
+
width={gameWidthOnLandscape}
|
|
601
|
+
height={gameHeightOnLandscape}
|
|
602
|
+
hidden={!isLandscape}
|
|
607
603
|
>
|
|
608
604
|
{@render snippetLandscape({
|
|
609
605
|
isLandscape,
|
|
@@ -617,12 +613,15 @@
|
|
|
617
613
|
gameWidth,
|
|
618
614
|
gameHeight
|
|
619
615
|
})}
|
|
620
|
-
</
|
|
616
|
+
</ScaledContainer>
|
|
621
617
|
<!-- Portrait content -->
|
|
622
|
-
<
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
618
|
+
<ScaledContainer
|
|
619
|
+
enableScaling={enableScaling}
|
|
620
|
+
design={designPortrait}
|
|
621
|
+
{clamping}
|
|
622
|
+
width={gameWidthOnPortrait}
|
|
623
|
+
height={gameHeightOnPortrait}
|
|
624
|
+
hidden={isLandscape}
|
|
626
625
|
>
|
|
627
626
|
{@render snippetPortrait({
|
|
628
627
|
isLandscape,
|
|
@@ -636,7 +635,7 @@
|
|
|
636
635
|
gameWidth,
|
|
637
636
|
gameHeight
|
|
638
637
|
})}
|
|
639
|
-
</
|
|
638
|
+
</ScaledContainer>
|
|
640
639
|
{/if}
|
|
641
640
|
{/if}
|
|
642
641
|
</div>
|
|
@@ -653,10 +652,6 @@
|
|
|
653
652
|
/* border: solid 1px red;*/
|
|
654
653
|
}
|
|
655
654
|
|
|
656
|
-
.hidden {
|
|
657
|
-
visibility: hidden;
|
|
658
|
-
}
|
|
659
|
-
|
|
660
655
|
:global(html.game-box-no-scroll) {
|
|
661
656
|
overflow: clip;
|
|
662
657
|
scrollbar-width: none; /* Firefox */
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
<script>
|
|
2
|
+
import { enableContainerScaling } from '../../../design/index.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* @typedef {{
|
|
6
|
+
* enableScaling?: boolean,
|
|
7
|
+
* design?: {width: number, height: number},
|
|
8
|
+
* clamping?: {
|
|
9
|
+
* ui: {min: number, max: number},
|
|
10
|
+
* textBase: {min: number, max: number},
|
|
11
|
+
* textHeading: {min: number, max: number},
|
|
12
|
+
* textUi: {min: number, max: number}
|
|
13
|
+
* },
|
|
14
|
+
* width: number,
|
|
15
|
+
* height: number,
|
|
16
|
+
* hidden?: boolean,
|
|
17
|
+
* children: import('svelte').Snippet
|
|
18
|
+
* }}
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Wrapper component that applies container scaling to its children
|
|
23
|
+
*
|
|
24
|
+
* @type {{
|
|
25
|
+
* enableScaling?: boolean,
|
|
26
|
+
* design?: {width: number, height: number},
|
|
27
|
+
* clamping?: {
|
|
28
|
+
* ui: {min: number, max: number},
|
|
29
|
+
* textBase: {min: number, max: number},
|
|
30
|
+
* textHeading: {min: number, max: number},
|
|
31
|
+
* textUi: {min: number, max: number}
|
|
32
|
+
* },
|
|
33
|
+
* width: number,
|
|
34
|
+
* height: number,
|
|
35
|
+
* hidden?: boolean,
|
|
36
|
+
* children: import('svelte').Snippet
|
|
37
|
+
* }}
|
|
38
|
+
*/
|
|
39
|
+
let {
|
|
40
|
+
enableScaling = false,
|
|
41
|
+
design = undefined,
|
|
42
|
+
clamping = undefined,
|
|
43
|
+
width,
|
|
44
|
+
height,
|
|
45
|
+
hidden = false,
|
|
46
|
+
children
|
|
47
|
+
} = $props();
|
|
48
|
+
|
|
49
|
+
let container = $state();
|
|
50
|
+
|
|
51
|
+
// Apply container scaling when enabled and not hidden
|
|
52
|
+
$effect(() => {
|
|
53
|
+
if (
|
|
54
|
+
!enableScaling ||
|
|
55
|
+
!container ||
|
|
56
|
+
!width ||
|
|
57
|
+
!height ||
|
|
58
|
+
hidden ||
|
|
59
|
+
!design
|
|
60
|
+
) {
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
console.debug(`Enable scaling [${width},${height}]`);
|
|
65
|
+
|
|
66
|
+
return enableContainerScaling({
|
|
67
|
+
container,
|
|
68
|
+
design,
|
|
69
|
+
clamping,
|
|
70
|
+
getDimensions: () => ({ width, height })
|
|
71
|
+
});
|
|
72
|
+
});
|
|
73
|
+
</script>
|
|
74
|
+
|
|
75
|
+
<div
|
|
76
|
+
bind:this={container}
|
|
77
|
+
class:hidden
|
|
78
|
+
style:width="{width}px"
|
|
79
|
+
style:height="{height}px"
|
|
80
|
+
>
|
|
81
|
+
{@render children()}
|
|
82
|
+
</div>
|
|
83
|
+
|
|
84
|
+
<style>
|
|
85
|
+
.hidden {
|
|
86
|
+
visibility: hidden;
|
|
87
|
+
}
|
|
88
|
+
</style>
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
export default ScaledContainer;
|
|
2
|
+
type ScaledContainer = {
|
|
3
|
+
$on?(type: string, callback: (e: any) => void): () => void;
|
|
4
|
+
$set?(props: Partial<{
|
|
5
|
+
enableScaling?: boolean | undefined;
|
|
6
|
+
design?: {
|
|
7
|
+
width: number;
|
|
8
|
+
height: number;
|
|
9
|
+
} | undefined;
|
|
10
|
+
clamping?: {
|
|
11
|
+
ui: {
|
|
12
|
+
min: number;
|
|
13
|
+
max: number;
|
|
14
|
+
};
|
|
15
|
+
textBase: {
|
|
16
|
+
min: number;
|
|
17
|
+
max: number;
|
|
18
|
+
};
|
|
19
|
+
textHeading: {
|
|
20
|
+
min: number;
|
|
21
|
+
max: number;
|
|
22
|
+
};
|
|
23
|
+
textUi: {
|
|
24
|
+
min: number;
|
|
25
|
+
max: number;
|
|
26
|
+
};
|
|
27
|
+
} | undefined;
|
|
28
|
+
width: number;
|
|
29
|
+
height: number;
|
|
30
|
+
hidden?: boolean | undefined;
|
|
31
|
+
children: Snippet<[]>;
|
|
32
|
+
}>): void;
|
|
33
|
+
};
|
|
34
|
+
declare const ScaledContainer: import("svelte").Component<{
|
|
35
|
+
enableScaling?: boolean;
|
|
36
|
+
design?: {
|
|
37
|
+
width: number;
|
|
38
|
+
height: number;
|
|
39
|
+
};
|
|
40
|
+
clamping?: {
|
|
41
|
+
ui: {
|
|
42
|
+
min: number;
|
|
43
|
+
max: number;
|
|
44
|
+
};
|
|
45
|
+
textBase: {
|
|
46
|
+
min: number;
|
|
47
|
+
max: number;
|
|
48
|
+
};
|
|
49
|
+
textHeading: {
|
|
50
|
+
min: number;
|
|
51
|
+
max: number;
|
|
52
|
+
};
|
|
53
|
+
textUi: {
|
|
54
|
+
min: number;
|
|
55
|
+
max: number;
|
|
56
|
+
};
|
|
57
|
+
};
|
|
58
|
+
width: number;
|
|
59
|
+
height: number;
|
|
60
|
+
hidden?: boolean;
|
|
61
|
+
children: import("svelte").Snippet;
|
|
62
|
+
}, {}, "">;
|