@hkdigital/lib-core 0.5.4 → 0.5.6

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 { enableContainerScaling } from '../../../design/index.js';
9
+ import ScaledContainer from './ScaledContainer.svelte';
10
10
 
11
11
  /**
12
12
  * @typedef {{
@@ -140,7 +140,8 @@
140
140
  return; // Skip first of the two resize events
141
141
  }
142
142
 
143
- skipNextResize = true;
143
+ // skipNextResize = true; // disabled to test <<
144
+
144
145
  debouncedWindowWidth = windowWidth;
145
146
  debouncedWindowHeight = windowHeight;
146
147
 
@@ -193,9 +194,6 @@
193
194
  $inspect('windowWidth/Height', windowWidth, windowHeight);
194
195
  $inspect('iosWindowWidth/Height', iosWindowWidth, iosWindowHeight);
195
196
 
196
- // Game container reference
197
- let gameContainer = $state();
198
-
199
197
  // Update game dimensions based on window size and orientation
200
198
  $effect(() => {
201
199
  const width = iosWindowWidth ?? windowWidth;
@@ -248,33 +246,6 @@
248
246
  }
249
247
  });
250
248
 
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
249
  let show = $state(false);
279
250
 
280
251
  let isPwa = $state(false);
@@ -460,7 +431,6 @@
460
431
  <div
461
432
  data-component="game-box"
462
433
  data-orientation={isLandscape ? 'landscape' : 'portrait'}
463
- bind:this={gameContainer}
464
434
  class="{base} {bg} {classes}"
465
435
  class:isMobile
466
436
  style:width="{gameWidth}px"
@@ -476,10 +446,13 @@
476
446
  <!-- Require fullscreen -->
477
447
  {#if isFullscreen && !isDevMode}
478
448
  <!-- Landscape content -->
479
- <div
480
- class:hidden={!isLandscape}
481
- style:width="{gameWidthOnLandscape}px"
482
- style:height="{gameHeightOnLandscape}px"
449
+ <ScaledContainer
450
+ enableScaling={enableScaling}
451
+ design={designLandscape}
452
+ {clamping}
453
+ width={gameWidthOnLandscape}
454
+ height={gameHeightOnLandscape}
455
+ hidden={!isLandscape}
483
456
  >
484
457
  {@render snippetLandscape({
485
458
  isLandscape,
@@ -495,12 +468,15 @@
495
468
  gameWidth,
496
469
  gameHeight
497
470
  })}
498
- </div>
471
+ </ScaledContainer>
499
472
  <!-- Portrait content -->
500
- <div
501
- class:hidden={isLandscape}
502
- style:width="{gameWidthOnPortrait}px"
503
- style:height="{gameHeightOnPortrait}px"
473
+ <ScaledContainer
474
+ enableScaling={enableScaling}
475
+ design={designPortrait}
476
+ {clamping}
477
+ width={gameWidthOnPortrait}
478
+ height={gameHeightOnPortrait}
479
+ hidden={isLandscape}
504
480
  >
505
481
  {@render snippetPortrait({
506
482
  isLandscape,
@@ -516,10 +492,16 @@
516
492
  gameWidth,
517
493
  gameHeight
518
494
  })}
519
- </div>
495
+ </ScaledContainer>
520
496
  {:else if supportsFullscreen && !isDevMode}
521
497
  <!-- Require fullscreen -->
522
- <div style:width="{gameWidth}px" style:height="{gameHeight}px">
498
+ <ScaledContainer
499
+ enableScaling={enableScaling}
500
+ design={isLandscape ? designLandscape : designPortrait}
501
+ {clamping}
502
+ width={gameWidth}
503
+ height={gameHeight}
504
+ >
523
505
  {@render snippetRequireFullscreen({
524
506
  isLandscape,
525
507
  isPortrait: !isLandscape,
@@ -534,10 +516,16 @@
534
516
  gameWidth,
535
517
  gameHeight
536
518
  })}
537
- </div>
519
+ </ScaledContainer>
538
520
  {:else if isMobile && snippetInstallOnHomeScreen && !isDevMode}
539
521
  <!-- Require install on home screen on mobile -->
540
- <div style:width="{gameWidth}px" style:height="{gameHeight}px">
522
+ <ScaledContainer
523
+ enableScaling={enableScaling}
524
+ design={isLandscape ? designLandscape : designPortrait}
525
+ {clamping}
526
+ width={gameWidth}
527
+ height={gameHeight}
528
+ >
541
529
  {@render snippetInstallOnHomeScreen({
542
530
  isLandscape,
543
531
  isPortrait: !isLandscape,
@@ -552,13 +540,16 @@
552
540
  gameWidth,
553
541
  gameHeight
554
542
  })}
555
- </div>
543
+ </ScaledContainer>
556
544
  {:else}
557
545
  <!-- Landscape content -->
558
- <div
559
- class:hidden={!isLandscape}
560
- style:width="{gameWidthOnLandscape}px"
561
- style:height="{gameHeightOnLandscape}px"
546
+ <ScaledContainer
547
+ enableScaling={enableScaling}
548
+ design={designLandscape}
549
+ {clamping}
550
+ width={gameWidthOnLandscape}
551
+ height={gameHeightOnLandscape}
552
+ hidden={!isLandscape}
562
553
  >
563
554
  {@render snippetLandscape({
564
555
  isLandscape,
@@ -574,12 +565,15 @@
574
565
  gameWidth,
575
566
  gameHeight
576
567
  })}
577
- </div>
568
+ </ScaledContainer>
578
569
  <!-- Portrait content -->
579
- <div
580
- class:hidden={isLandscape}
581
- style:width="{gameWidthOnPortrait}px"
582
- style:height="{gameHeightOnPortrait}px"
570
+ <ScaledContainer
571
+ enableScaling={enableScaling}
572
+ design={designPortrait}
573
+ {clamping}
574
+ width={gameWidthOnPortrait}
575
+ height={gameHeightOnPortrait}
576
+ hidden={isLandscape}
583
577
  >
584
578
  {@render snippetPortrait({
585
579
  isLandscape,
@@ -595,15 +589,18 @@
595
589
  gameWidth,
596
590
  gameHeight
597
591
  })}
598
- </div>
592
+ </ScaledContainer>
599
593
  {/if}
600
594
  {:else}
601
595
  <!-- Do not require fullscreen -->
602
596
  <!-- Landscape content -->
603
- <div
604
- class:hidden={!isLandscape}
605
- style:width="{gameWidthOnLandscape}px"
606
- style:height="{gameHeightOnLandscape}px"
597
+ <ScaledContainer
598
+ enableScaling={enableScaling}
599
+ design={designLandscape}
600
+ {clamping}
601
+ width={gameWidthOnLandscape}
602
+ height={gameHeightOnLandscape}
603
+ hidden={!isLandscape}
607
604
  >
608
605
  {@render snippetLandscape({
609
606
  isLandscape,
@@ -617,12 +614,15 @@
617
614
  gameWidth,
618
615
  gameHeight
619
616
  })}
620
- </div>
617
+ </ScaledContainer>
621
618
  <!-- Portrait content -->
622
- <div
623
- class:hidden={isLandscape}
624
- style:width="{gameWidthOnPortrait}px"
625
- style:height="{gameHeightOnPortrait}px"
619
+ <ScaledContainer
620
+ enableScaling={enableScaling}
621
+ design={designPortrait}
622
+ {clamping}
623
+ width={gameWidthOnPortrait}
624
+ height={gameHeightOnPortrait}
625
+ hidden={isLandscape}
626
626
  >
627
627
  {@render snippetPortrait({
628
628
  isLandscape,
@@ -636,7 +636,7 @@
636
636
  gameWidth,
637
637
  gameHeight
638
638
  })}
639
- </div>
639
+ </ScaledContainer>
640
640
  {/if}
641
641
  {/if}
642
642
  </div>
@@ -653,10 +653,6 @@
653
653
  /* border: solid 1px red;*/
654
654
  }
655
655
 
656
- .hidden {
657
- visibility: hidden;
658
- }
659
-
660
656
  :global(html.game-box-no-scroll) {
661
657
  overflow: clip;
662
658
  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
+ }, {}, "">;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hkdigital/lib-core",
3
- "version": "0.5.4",
3
+ "version": "0.5.6",
4
4
  "author": {
5
5
  "name": "HKdigital",
6
6
  "url": "https://hkdigital.nl"