@hkdigital/lib-sveltekit 0.1.0 → 0.1.2
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.
- package/dist/classes/svelte/audio/AudioScene.svelte.js +1 -1
- package/dist/classes/svelte/image/ImageLoader.svelte.js +1 -1
- package/dist/classes/svelte/image/ImageScene.svelte.js +1 -1
- package/dist/classes/svelte/network-loader/NetworkLoader.svelte.js +1 -1
- package/dist/components/area/HkArea.svelte +1 -1
- package/dist/components/area/HkArea.svelte.d.ts +14 -0
- package/dist/components/area/HkGridArea.svelte +1 -1
- package/dist/components/area/HkGridArea.svelte.d.ts +22 -0
- package/dist/components/boxes/game-box/GameBox.svelte +112 -0
- package/dist/components/boxes/game-box/GameBox.svelte.d.ts +28 -0
- package/dist/components/boxes/game-box/gamebox.util.d.ts +32 -0
- package/dist/components/boxes/game-box/gamebox.util.js +83 -0
- package/dist/components/boxes/index.d.ts +2 -0
- package/dist/components/boxes/index.js +2 -0
- package/dist/components/boxes/virtual-viewport/VirtualViewport.svelte +199 -0
- package/dist/components/boxes/virtual-viewport/VirtualViewport.svelte.d.ts +42 -0
- package/dist/components/buttons/button/Button.svelte +75 -0
- package/dist/components/buttons/button/Button.svelte.d.ts +40 -0
- package/dist/components/buttons/button-text/TextButton.svelte +21 -0
- package/dist/components/buttons/button-text/TextButton.svelte.d.ts +12 -0
- package/dist/components/buttons/index.d.ts +2 -1
- package/dist/components/buttons/index.js +2 -1
- package/dist/components/hkdev/blocks/TextBlock.svelte +47 -0
- package/dist/components/hkdev/blocks/TextBlock.svelte.d.ts +24 -0
- package/dist/components/hkdev/buttons/CheckButton.svelte +63 -0
- package/dist/components/hkdev/buttons/CheckButton.svelte.d.ts +34 -0
- package/dist/components/icon/HkIcon.svelte +1 -1
- package/dist/components/icon/HkIcon.svelte.d.ts +12 -0
- package/dist/components/icon/HkTabIcon.svelte +6 -2
- package/dist/components/icon/HkTabIcon.svelte.d.ts +21 -0
- package/dist/components/image/EnhancedImage.svelte__ +1 -1
- package/dist/components/image/ImageBox.svelte.d.ts +19 -0
- package/dist/components/image/ResponsiveImage.svelte +1 -1
- package/dist/components/image/ResponsiveImage.svelte.d.ts +16 -0
- package/dist/components/image/ResponsiveImage.svelte__ +1 -1
- package/dist/components/inputs/text-input/TestTextInput.svelte__ +2 -2
- package/dist/components/inputs/text-input/TextInput.svelte +1 -1
- package/dist/components/inputs/text-input/TextInput.svelte.d.ts +28 -0
- package/dist/components/inputs/text-input/TextInput.svelte___ +1 -1
- package/dist/components/layout/HkAppLayout.svelte.d.ts +11 -0
- package/dist/components/layout/HkGridLayers.svelte +1 -1
- package/dist/components/layout/HkGridLayers.svelte.d.ts +23 -0
- package/dist/components/panels/plain-panel/PlainPanel.svelte +1 -1
- package/dist/components/panels/plain-panel/PlainPanel.svelte.d.ts +12 -0
- package/dist/components/rows/panel-grid-row/PanelGridRow.svelte +1 -1
- package/dist/components/rows/panel-grid-row/PanelGridRow.svelte.d.ts +14 -0
- package/dist/components/rows/panel-row-2/PanelRow2.svelte +1 -1
- package/dist/components/rows/panel-row-2/PanelRow2.svelte.d.ts +14 -0
- package/dist/components/tab-bar/HkTabBar.svelte +1 -1
- package/dist/components/tab-bar/HkTabBar.svelte.d.ts +18 -0
- package/dist/components/tab-bar/HkTabBarSelector.svelte +1 -1
- package/dist/components/tab-bar/HkTabBarSelector.svelte.d.ts +19 -0
- package/dist/components/widgets/compare-left-right/CompareLeftRight.svelte.d.ts +10 -0
- package/dist/design-system/design-config.d.ts +156 -0
- package/dist/design-system/design-config.js +73 -0
- package/dist/design-system/tailwind-theme-extend.d.ts +23 -0
- package/dist/design-system/tailwind-theme-extend.js +151 -0
- package/dist/themes/hkdev/components/blocks/text-block.postcss +41 -0
- package/dist/themes/hkdev/components/buttons/button-text.postcss +34 -0
- package/dist/themes/hkdev/components/buttons/button.postcss +138 -0
- package/dist/themes/hkdev/components/buttons/button.postcss__ +40 -0
- package/dist/themes/hkdev/components/buttons/button.postcss___ +91 -0
- package/dist/themes/hkdev/components.postcss +8 -2
- package/dist/themes/hkdev/globals.postcss +5 -6
- package/dist/util/css/css-vars.d.ts +24 -0
- package/dist/util/css/css-vars.js +83 -0
- package/dist/util/css/index.d.ts +1 -0
- package/dist/util/css/index.js +1 -0
- package/dist/util/design-system/components/states.d.ts +15 -0
- package/dist/util/design-system/components/states.js +22 -0
- package/dist/util/design-system/css/clamp.d.ts +17 -0
- package/dist/util/design-system/css/clamp.js +66 -0
- package/dist/util/design-system/css/root-design-vars.d.ts +77 -0
- package/dist/util/design-system/css/root-design-vars.js +100 -0
- package/dist/util/design-system/index.d.ts +5 -0
- package/dist/util/design-system/index.js +5 -0
- package/dist/util/design-system/layout/scaling.d.ts +44 -0
- package/dist/util/design-system/layout/scaling.js +97 -0
- package/dist/util/design-system/tailwind.d.ts +176 -0
- package/dist/util/design-system/tailwind.js +289 -0
- package/dist/util/http/index.js +1 -1
- package/package.json +18 -18
- package/dist/components/buttons/plain-button/PlainButton.svelte +0 -37
- package/dist/components/buttons/plain-button/PlainButton.svelte.d.ts +0 -10
- package/dist/config/tailwind.extend.d.ts +0 -56
- package/dist/config/tailwind.extend.js +0 -64
- package/dist/themes/hkdev/components/buttons/plain-button.postcss +0 -73
@@ -1,4 +1,18 @@
|
|
1
1
|
export default HkArea;
|
2
|
+
type HkArea = {
|
3
|
+
$on?(type: string, callback: (e: any) => void): () => void;
|
4
|
+
$set?(props: Partial<{
|
5
|
+
base?: string;
|
6
|
+
bg?: string;
|
7
|
+
padding?: string;
|
8
|
+
margin?: string;
|
9
|
+
classes?: string;
|
10
|
+
style?: string;
|
11
|
+
children: Snippet<[]>;
|
12
|
+
} & {
|
13
|
+
[attr: string]: any;
|
14
|
+
}>): void;
|
15
|
+
};
|
2
16
|
declare const HkArea: import("svelte").Component<{
|
3
17
|
base?: string;
|
4
18
|
bg?: string;
|
@@ -1,4 +1,26 @@
|
|
1
1
|
export default HkGridArea;
|
2
|
+
type HkGridArea = {
|
3
|
+
$on?(type: string, callback: (e: any) => void): () => void;
|
4
|
+
$set?(props: Partial<{
|
5
|
+
base?: string;
|
6
|
+
bg?: string;
|
7
|
+
padding?: string;
|
8
|
+
margin?: string;
|
9
|
+
classes?: string;
|
10
|
+
style?: string;
|
11
|
+
boxBase?: string;
|
12
|
+
boxBg?: string;
|
13
|
+
boxPadding?: string;
|
14
|
+
boxMargin?: string;
|
15
|
+
boxClasses?: string;
|
16
|
+
boxAttrs?: {
|
17
|
+
[attr: string]: any;
|
18
|
+
};
|
19
|
+
children: Snippet<[]>;
|
20
|
+
} & {
|
21
|
+
[attr: string]: any;
|
22
|
+
}>): void;
|
23
|
+
};
|
2
24
|
declare const HkGridArea: import("svelte").Component<{
|
3
25
|
base?: string;
|
4
26
|
bg?: string;
|
@@ -0,0 +1,112 @@
|
|
1
|
+
<script>
|
2
|
+
import {
|
3
|
+
getGameWidthOnLandscape,
|
4
|
+
getGameWidthOnPortrait
|
5
|
+
} from './gamebox.util.js';
|
6
|
+
|
7
|
+
/**
|
8
|
+
* @type {{
|
9
|
+
* base?: string,
|
10
|
+
* bg?: string,
|
11
|
+
* classes?: string,
|
12
|
+
* style?: string,
|
13
|
+
* aspectOnLandscape? :number,
|
14
|
+
* aspectOnPortrait? :number,
|
15
|
+
* onLandscape?: import('svelte').Snippet,
|
16
|
+
* onPortrait?: import('svelte').Snippet
|
17
|
+
* } & { [attr: string]: any }}
|
18
|
+
*/
|
19
|
+
const {
|
20
|
+
// > Style
|
21
|
+
base,
|
22
|
+
bg,
|
23
|
+
classes,
|
24
|
+
style,
|
25
|
+
|
26
|
+
// > Functional
|
27
|
+
aspectOnLandscape,
|
28
|
+
aspectOnPortrait,
|
29
|
+
|
30
|
+
// >Snippets
|
31
|
+
snippetLandscape,
|
32
|
+
snippetPortrait
|
33
|
+
} = $props();
|
34
|
+
|
35
|
+
// > Game width and height
|
36
|
+
|
37
|
+
let windowWidth = $state();
|
38
|
+
let windowHeight = $state();
|
39
|
+
|
40
|
+
let gameWidth = $state();
|
41
|
+
let gameHeight = $state();
|
42
|
+
|
43
|
+
let isLandscape = $derived(gameWidth > gameHeight);
|
44
|
+
|
45
|
+
$effect(() => {
|
46
|
+
// Determine game width and height from
|
47
|
+
// window dimensions and desired game aspect
|
48
|
+
|
49
|
+
let gameAspect;
|
50
|
+
|
51
|
+
if (windowWidth > windowHeight) {
|
52
|
+
gameWidth = getGameWidthOnLandscape({
|
53
|
+
windowWidth,
|
54
|
+
windowHeight,
|
55
|
+
aspectOnLandscape
|
56
|
+
});
|
57
|
+
|
58
|
+
gameAspect = aspectOnLandscape;
|
59
|
+
} else {
|
60
|
+
gameWidth = getGameWidthOnPortrait({
|
61
|
+
windowWidth,
|
62
|
+
windowHeight,
|
63
|
+
aspectOnPortrait
|
64
|
+
});
|
65
|
+
|
66
|
+
gameAspect = aspectOnPortrait;
|
67
|
+
}
|
68
|
+
|
69
|
+
if (gameAspect) {
|
70
|
+
gameHeight = gameWidth / gameAspect;
|
71
|
+
} else {
|
72
|
+
gameHeight = windowHeight;
|
73
|
+
}
|
74
|
+
});
|
75
|
+
|
76
|
+
// $inspect({ windowWidth, windowHeight, gameWidth, gameHeight, isLandscape });
|
77
|
+
|
78
|
+
// $effect(() => {
|
79
|
+
// console.log({
|
80
|
+
// windowWidth,
|
81
|
+
// windowHeight,
|
82
|
+
// gameWidth,
|
83
|
+
// gameHeight,
|
84
|
+
// isLandscape
|
85
|
+
// });
|
86
|
+
// });
|
87
|
+
</script>
|
88
|
+
|
89
|
+
<svelte:window bind:innerWidth={windowWidth} bind:innerHeight={windowHeight} />
|
90
|
+
|
91
|
+
{#if gameHeight}
|
92
|
+
<!-- <div
|
93
|
+
data-boxes="game-box"
|
94
|
+
class="{base} {bg} {classes}"
|
95
|
+
style="width: {gameWidth}px; height: {gameHeight}px;--game-width={gameWidth};--game-height={gameHeight}; {style}" -->
|
96
|
+
|
97
|
+
<div
|
98
|
+
data-boxes="game-box"
|
99
|
+
class="{base} {bg} {classes}"
|
100
|
+
style:width="{gameWidth}px"
|
101
|
+
style:height="{gameHeight}px"
|
102
|
+
style:--game-width={gameWidth}
|
103
|
+
style:--game-height={gameHeight}
|
104
|
+
{style}
|
105
|
+
>
|
106
|
+
{#if isLandscape}
|
107
|
+
{@render snippetLandscape()}
|
108
|
+
{:else}
|
109
|
+
{@render snippetPortrait()}
|
110
|
+
{/if}
|
111
|
+
</div>
|
112
|
+
{/if}
|
@@ -0,0 +1,28 @@
|
|
1
|
+
export default GameBox;
|
2
|
+
type GameBox = {
|
3
|
+
$on?(type: string, callback: (e: any) => void): () => void;
|
4
|
+
$set?(props: Partial<{
|
5
|
+
base?: string;
|
6
|
+
bg?: string;
|
7
|
+
classes?: string;
|
8
|
+
style?: string;
|
9
|
+
aspectOnLandscape?: number;
|
10
|
+
aspectOnPortrait?: number;
|
11
|
+
onLandscape?: Snippet<[]>;
|
12
|
+
onPortrait?: Snippet<[]>;
|
13
|
+
} & {
|
14
|
+
[attr: string]: any;
|
15
|
+
}>): void;
|
16
|
+
};
|
17
|
+
declare const GameBox: import("svelte").Component<{
|
18
|
+
base?: string;
|
19
|
+
bg?: string;
|
20
|
+
classes?: string;
|
21
|
+
style?: string;
|
22
|
+
aspectOnLandscape?: number;
|
23
|
+
aspectOnPortrait?: number;
|
24
|
+
onLandscape?: import("svelte").Snippet;
|
25
|
+
onPortrait?: import("svelte").Snippet;
|
26
|
+
} & {
|
27
|
+
[attr: string]: any;
|
28
|
+
}, {}, "">;
|
@@ -0,0 +1,32 @@
|
|
1
|
+
/**
|
2
|
+
* Get game width for landscape mode
|
3
|
+
*
|
4
|
+
* @param {object} _
|
5
|
+
* @param {number} _.windowWidth
|
6
|
+
* @param {number} _.windowHeight
|
7
|
+
* @param {number} [_.aspectOnLandscape]
|
8
|
+
*
|
9
|
+
* @returns {number} game width
|
10
|
+
*/
|
11
|
+
export function getGameWidthOnLandscape({ windowWidth, windowHeight, aspectOnLandscape }: {
|
12
|
+
windowWidth: number;
|
13
|
+
windowHeight: number;
|
14
|
+
aspectOnLandscape?: number;
|
15
|
+
}): number;
|
16
|
+
/**
|
17
|
+
* Get game width for portrait mode
|
18
|
+
*
|
19
|
+
* @param {object} _
|
20
|
+
* @param {number} _.windowWidth
|
21
|
+
* @param {number} _.windowHeight
|
22
|
+
* @param {number} [_.aspectOnPortrait]
|
23
|
+
*
|
24
|
+
* @returns {number} game width
|
25
|
+
*/
|
26
|
+
export function getGameWidthOnPortrait({ windowWidth, windowHeight, aspectOnPortrait }: {
|
27
|
+
windowWidth: number;
|
28
|
+
windowHeight: number;
|
29
|
+
aspectOnPortrait?: number;
|
30
|
+
}): number;
|
31
|
+
export const ERROR_WINDOW_SIZE_NOT_LANDSCAPE: "Window size is not landsccape";
|
32
|
+
export const ERROR_WINDOW_SIZE_NOT_PORTRAIT: "Window size is not portrait";
|
@@ -0,0 +1,83 @@
|
|
1
|
+
export const ERROR_WINDOW_SIZE_NOT_LANDSCAPE = 'Window size is not landsccape';
|
2
|
+
|
3
|
+
export const ERROR_WINDOW_SIZE_NOT_PORTRAIT = 'Window size is not portrait';
|
4
|
+
|
5
|
+
/**
|
6
|
+
* Get game width for landscape mode
|
7
|
+
*
|
8
|
+
* @param {object} _
|
9
|
+
* @param {number} _.windowWidth
|
10
|
+
* @param {number} _.windowHeight
|
11
|
+
* @param {number} [_.aspectOnLandscape]
|
12
|
+
*
|
13
|
+
* @returns {number} game width
|
14
|
+
*/
|
15
|
+
export function getGameWidthOnLandscape({
|
16
|
+
windowWidth,
|
17
|
+
windowHeight,
|
18
|
+
aspectOnLandscape
|
19
|
+
}) {
|
20
|
+
if (!windowHeight) {
|
21
|
+
return 0;
|
22
|
+
}
|
23
|
+
|
24
|
+
if (windowWidth < windowHeight) {
|
25
|
+
throw new Error(ERROR_WINDOW_SIZE_NOT_LANDSCAPE);
|
26
|
+
}
|
27
|
+
|
28
|
+
if (!aspectOnLandscape) {
|
29
|
+
// No game aspect specified for landscape
|
30
|
+
// => return full width
|
31
|
+
return windowWidth;
|
32
|
+
}
|
33
|
+
|
34
|
+
const windowAspect = windowWidth / windowHeight;
|
35
|
+
|
36
|
+
if (windowAspect > aspectOnLandscape) {
|
37
|
+
// aspect of window if wider than game aspect => fill height
|
38
|
+
return aspectOnLandscape * windowHeight;
|
39
|
+
} else {
|
40
|
+
// aspect of game is wider => fill width
|
41
|
+
return windowWidth;
|
42
|
+
}
|
43
|
+
}
|
44
|
+
|
45
|
+
/**
|
46
|
+
* Get game width for portrait mode
|
47
|
+
*
|
48
|
+
* @param {object} _
|
49
|
+
* @param {number} _.windowWidth
|
50
|
+
* @param {number} _.windowHeight
|
51
|
+
* @param {number} [_.aspectOnPortrait]
|
52
|
+
*
|
53
|
+
* @returns {number} game width
|
54
|
+
*/
|
55
|
+
export function getGameWidthOnPortrait({
|
56
|
+
windowWidth,
|
57
|
+
windowHeight,
|
58
|
+
aspectOnPortrait
|
59
|
+
}) {
|
60
|
+
if (!windowHeight) {
|
61
|
+
return 0;
|
62
|
+
}
|
63
|
+
|
64
|
+
if (windowHeight < windowWidth) {
|
65
|
+
throw new Error(ERROR_WINDOW_SIZE_NOT_PORTRAIT);
|
66
|
+
}
|
67
|
+
|
68
|
+
if (!aspectOnPortrait) {
|
69
|
+
// No game aspect specified for portrait
|
70
|
+
// => return full width
|
71
|
+
return windowWidth;
|
72
|
+
}
|
73
|
+
|
74
|
+
const windowAspect = windowWidth / windowHeight;
|
75
|
+
|
76
|
+
if (windowAspect > aspectOnPortrait) {
|
77
|
+
// aspect of window if wider than game aspect => fill height
|
78
|
+
return aspectOnPortrait * windowHeight;
|
79
|
+
} else {
|
80
|
+
// aspect of game is wider => fill width
|
81
|
+
return windowWidth;
|
82
|
+
}
|
83
|
+
}
|
@@ -0,0 +1,199 @@
|
|
1
|
+
<script>
|
2
|
+
import { onMount } from 'svelte';
|
3
|
+
import {
|
4
|
+
getRootCssDesignWidth,
|
5
|
+
getRootCssDesignHeight,
|
6
|
+
getClampParams,
|
7
|
+
clamp
|
8
|
+
} from '../../../util/design-system/index.js';
|
9
|
+
|
10
|
+
/**
|
11
|
+
* Virtual viewport component that creates a container with its own scaling
|
12
|
+
* system based on its actual dimensions.
|
13
|
+
*
|
14
|
+
* @type {{
|
15
|
+
* base?: string,
|
16
|
+
* bg?: string,
|
17
|
+
* classes?: string,
|
18
|
+
* width?: string,
|
19
|
+
* height?: string,
|
20
|
+
* overflow?: string,
|
21
|
+
* designWidth?: number,
|
22
|
+
* designHeight?: number,
|
23
|
+
* scaleViewport?: number,
|
24
|
+
* scaleW?: number,
|
25
|
+
* scaleH?: number,
|
26
|
+
* scaleUI?: number,
|
27
|
+
* scaleTextContent?: number,
|
28
|
+
* scaleTextHeading?: number,
|
29
|
+
* scaleTextUI?: number,
|
30
|
+
* children?: import('svelte').Snippet,
|
31
|
+
* [attr: string]: any
|
32
|
+
* }}
|
33
|
+
*/
|
34
|
+
let {
|
35
|
+
// Style related props first
|
36
|
+
base,
|
37
|
+
bg,
|
38
|
+
classes,
|
39
|
+
width,
|
40
|
+
height,
|
41
|
+
overflow = 'overflow-clip',
|
42
|
+
|
43
|
+
// Functional bindable props
|
44
|
+
designWidth = $bindable(0),
|
45
|
+
designHeight = $bindable(0),
|
46
|
+
scaleViewport = $bindable(0),
|
47
|
+
scaleW = $bindable(0),
|
48
|
+
scaleH = $bindable(0),
|
49
|
+
scaleUI = $bindable(0),
|
50
|
+
scaleTextContent = $bindable(0),
|
51
|
+
scaleTextHeading = $bindable(0),
|
52
|
+
scaleTextUI = $bindable(0),
|
53
|
+
|
54
|
+
// Snippets
|
55
|
+
children,
|
56
|
+
|
57
|
+
// Rest of attributes
|
58
|
+
...attrs
|
59
|
+
} = $props();
|
60
|
+
|
61
|
+
/**
|
62
|
+
* References to the container element for measurement
|
63
|
+
* @type {HTMLDivElement}
|
64
|
+
*/
|
65
|
+
let container;
|
66
|
+
|
67
|
+
/**
|
68
|
+
* Current scaling variables
|
69
|
+
*/
|
70
|
+
let scaleVars = $state('');
|
71
|
+
|
72
|
+
// No separate variables for design dimensions
|
73
|
+
|
74
|
+
/**
|
75
|
+
* Error state for CSS variable parsing
|
76
|
+
*/
|
77
|
+
let cssParsingError = $state(null);
|
78
|
+
|
79
|
+
/**
|
80
|
+
* Update scaling based on current dimensions
|
81
|
+
*/
|
82
|
+
function updateScaling() {
|
83
|
+
if (!container) return;
|
84
|
+
|
85
|
+
// Get actual container dimensions
|
86
|
+
const rect = container.getBoundingClientRect();
|
87
|
+
const containerWidth = rect.width;
|
88
|
+
const containerHeight = rect.height;
|
89
|
+
|
90
|
+
// Calculate ratios similar to root variables
|
91
|
+
scaleW = containerWidth / designWidth;
|
92
|
+
scaleH = containerHeight / designHeight;
|
93
|
+
|
94
|
+
// Use the smaller ratio to ensure content fits (from vars.postcss)
|
95
|
+
scaleViewport = Math.min(scaleW, scaleH);
|
96
|
+
|
97
|
+
try {
|
98
|
+
// Get clamp parameters from CSS variables
|
99
|
+
const uiParams = getClampParams('scale-ui');
|
100
|
+
const contentParams = getClampParams('scale-text-content');
|
101
|
+
const headingParams = getClampParams('scale-text-heading');
|
102
|
+
const textUIParams = getClampParams('scale-text-ui');
|
103
|
+
|
104
|
+
// Apply scaling according to extracted clamp parameters
|
105
|
+
scaleUI = clamp(uiParams.min, scaleViewport, uiParams.max);
|
106
|
+
scaleTextContent = clamp(
|
107
|
+
contentParams.min,
|
108
|
+
scaleViewport,
|
109
|
+
contentParams.max
|
110
|
+
);
|
111
|
+
scaleTextHeading = clamp(
|
112
|
+
headingParams.min,
|
113
|
+
scaleViewport,
|
114
|
+
headingParams.max
|
115
|
+
);
|
116
|
+
scaleTextUI = clamp(textUIParams.min, scaleViewport, textUIParams.max);
|
117
|
+
|
118
|
+
// Clear any previous error
|
119
|
+
cssParsingError = null;
|
120
|
+
} catch (error) {
|
121
|
+
// Store the error for debugging
|
122
|
+
cssParsingError = error;
|
123
|
+
console.error('VirtualViewport scaling error:', error);
|
124
|
+
|
125
|
+
// Fallback to simple scaling without clamping
|
126
|
+
scaleUI = scaleViewport;
|
127
|
+
scaleTextContent = scaleViewport;
|
128
|
+
scaleTextHeading = scaleViewport;
|
129
|
+
scaleTextUI = scaleViewport;
|
130
|
+
}
|
131
|
+
|
132
|
+
// Update the style variables
|
133
|
+
scaleVars = `
|
134
|
+
--scale-w: ${scaleW};
|
135
|
+
--scale-h: ${scaleH};
|
136
|
+
--scale-viewport: ${scaleViewport};
|
137
|
+
--scale-ui: ${scaleUI};
|
138
|
+
--scale-text-content: ${scaleTextContent};
|
139
|
+
--scale-text-heading: ${scaleTextHeading};
|
140
|
+
--scale-text-ui: ${scaleTextUI};
|
141
|
+
`;
|
142
|
+
}
|
143
|
+
|
144
|
+
// Watch for changes and update scaling
|
145
|
+
$effect(() => {
|
146
|
+
updateScaling();
|
147
|
+
});
|
148
|
+
|
149
|
+
onMount(() => {
|
150
|
+
try {
|
151
|
+
// Get design dimensions from CSS variables if props are zero
|
152
|
+
if (designWidth === 0) {
|
153
|
+
designWidth = getRootCssDesignWidth() ?? 1920;
|
154
|
+
}
|
155
|
+
|
156
|
+
if (designHeight === 0) {
|
157
|
+
designHeight = getRootCssDesignHeight() ?? 1080;
|
158
|
+
}
|
159
|
+
|
160
|
+
// Initial calculation
|
161
|
+
updateScaling();
|
162
|
+
|
163
|
+
// Set up ResizeObserver to update scaling when container size changes
|
164
|
+
const resizeObserver = new ResizeObserver(() => {
|
165
|
+
updateScaling();
|
166
|
+
});
|
167
|
+
|
168
|
+
resizeObserver.observe(container);
|
169
|
+
|
170
|
+
// Clean up
|
171
|
+
return () => {
|
172
|
+
resizeObserver.disconnect();
|
173
|
+
};
|
174
|
+
} catch (error) {
|
175
|
+
cssParsingError = error;
|
176
|
+
console.error('VirtualViewport initialization error:', error);
|
177
|
+
}
|
178
|
+
});
|
179
|
+
</script>
|
180
|
+
|
181
|
+
<div
|
182
|
+
data-component="virtual-viewport"
|
183
|
+
bind:this={container}
|
184
|
+
class="{base} {bg} {width} {height} {overflow} {classes}"
|
185
|
+
style={scaleVars}
|
186
|
+
style:width={width ? width : '100%'}
|
187
|
+
style:height={height ? height : '100%'}
|
188
|
+
{...attrs}
|
189
|
+
>
|
190
|
+
{#if cssParsingError}
|
191
|
+
<!-- Add a discreet error indicator for development -->
|
192
|
+
<div
|
193
|
+
class="absolute top-0 right-0 p-1 text-red-500 text-xs bg-black bg-opacity-50 rounded-bl"
|
194
|
+
>
|
195
|
+
CSS Parsing Error
|
196
|
+
</div>
|
197
|
+
{/if}
|
198
|
+
{@render children()}
|
199
|
+
</div>
|
@@ -0,0 +1,42 @@
|
|
1
|
+
export default VirtualViewport;
|
2
|
+
type VirtualViewport = {
|
3
|
+
$on?(type: string, callback: (e: any) => void): () => void;
|
4
|
+
$set?(props: Partial<{
|
5
|
+
[attr: string]: any;
|
6
|
+
base?: string;
|
7
|
+
bg?: string;
|
8
|
+
classes?: string;
|
9
|
+
width?: string;
|
10
|
+
height?: string;
|
11
|
+
overflow?: string;
|
12
|
+
designWidth?: number;
|
13
|
+
designHeight?: number;
|
14
|
+
scaleViewport?: number;
|
15
|
+
scaleW?: number;
|
16
|
+
scaleH?: number;
|
17
|
+
scaleUI?: number;
|
18
|
+
scaleTextContent?: number;
|
19
|
+
scaleTextHeading?: number;
|
20
|
+
scaleTextUI?: number;
|
21
|
+
children?: Snippet<[]>;
|
22
|
+
}>): void;
|
23
|
+
};
|
24
|
+
declare const VirtualViewport: import("svelte").Component<{
|
25
|
+
[attr: string]: any;
|
26
|
+
base?: string;
|
27
|
+
bg?: string;
|
28
|
+
classes?: string;
|
29
|
+
width?: string;
|
30
|
+
height?: string;
|
31
|
+
overflow?: string;
|
32
|
+
designWidth?: number;
|
33
|
+
designHeight?: number;
|
34
|
+
scaleViewport?: number;
|
35
|
+
scaleW?: number;
|
36
|
+
scaleH?: number;
|
37
|
+
scaleUI?: number;
|
38
|
+
scaleTextContent?: number;
|
39
|
+
scaleTextHeading?: number;
|
40
|
+
scaleTextUI?: number;
|
41
|
+
children?: import("svelte").Snippet;
|
42
|
+
}, {}, "designWidth" | "designHeight" | "scaleViewport" | "scaleW" | "scaleH" | "scaleUI" | "scaleTextContent" | "scaleTextHeading" | "scaleTextUI">;
|
@@ -0,0 +1,75 @@
|
|
1
|
+
<script>
|
2
|
+
import { toStateClasses } from '../../../util/design-system/index.js';
|
3
|
+
|
4
|
+
/**
|
5
|
+
* @type {{
|
6
|
+
* base?: string,
|
7
|
+
* bg?: string,
|
8
|
+
* classes?: string,
|
9
|
+
* type?: string,
|
10
|
+
* role?: 'primary' | 'secondary',
|
11
|
+
* size?: 'sm' | 'md' | 'lg',
|
12
|
+
* variant?: string,
|
13
|
+
* active?: boolean,
|
14
|
+
* selected?: boolean,
|
15
|
+
* loading?: boolean,
|
16
|
+
* error?: boolean,
|
17
|
+
* disabled?: boolean,
|
18
|
+
* snippetLoading?: import('svelte').Snippet,
|
19
|
+
* snippetError?: import('svelte').Snippet,
|
20
|
+
* children: import('svelte').Snippet,
|
21
|
+
* [key: string]: any
|
22
|
+
* }}
|
23
|
+
*/
|
24
|
+
const {
|
25
|
+
// Style
|
26
|
+
base,
|
27
|
+
bg,
|
28
|
+
classes,
|
29
|
+
type = '',
|
30
|
+
role = 'primary',
|
31
|
+
size = 'md',
|
32
|
+
variant = '',
|
33
|
+
|
34
|
+
// States
|
35
|
+
active = $bindable(false),
|
36
|
+
selected = $bindable(false),
|
37
|
+
loading = $bindable(false),
|
38
|
+
error = $bindable(false),
|
39
|
+
disabled = $bindable(false),
|
40
|
+
|
41
|
+
// Snippets
|
42
|
+
snippetLoading,
|
43
|
+
snippetError,
|
44
|
+
children,
|
45
|
+
|
46
|
+
// Attributes
|
47
|
+
...attrs
|
48
|
+
} = $props();
|
49
|
+
|
50
|
+
let stateClasses = $derived.by(() => {
|
51
|
+
return toStateClasses({ active, selected, loading, error, disabled });
|
52
|
+
});
|
53
|
+
</script>
|
54
|
+
|
55
|
+
<button
|
56
|
+
data-component="button"
|
57
|
+
data-type={type}
|
58
|
+
data-role={role}
|
59
|
+
data-size={size}
|
60
|
+
data-variant={variant}
|
61
|
+
type="button"
|
62
|
+
class="{base} {bg} {classes} {stateClasses}"
|
63
|
+
disabled={disabled || loading}
|
64
|
+
aria-busy={loading}
|
65
|
+
aria-pressed={selected}
|
66
|
+
{...attrs}
|
67
|
+
>
|
68
|
+
{#if loading && snippetLoading}
|
69
|
+
{@render snippetLoading()}
|
70
|
+
{:else if error && snippetError}
|
71
|
+
{@render snippetError()}
|
72
|
+
{:else}
|
73
|
+
{@render children()}
|
74
|
+
{/if}
|
75
|
+
</button>
|