@danielito1996/compose-svelted 0.0.1
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/.vscode/extensions.json +3 -0
- package/README.md +274 -0
- package/docs/assets/components/button/button.png +0 -0
- package/docs/assets/components/surface/surface_simple.png +0 -0
- package/docs/assets/components/text/text.png +0 -0
- package/docs/assets/components/textfield/textfield_simple.png +0 -0
- package/docs/assets/svelted.png +0 -0
- package/docs/assets/svelted.svg +41 -0
- package/docs/getting_started.md +116 -0
- package/docs/index.md +106 -0
- package/index.html +14 -0
- package/package.json +49 -0
- package/public/vite.svg +1 -0
- package/screenshots/Captura de pantalla 2025-12-20 022710.png +0 -0
- package/screenshots/capturas.txt +1 -0
- package/src/App.svelte +39 -0
- package/src/app.css +23 -0
- package/src/assets/img/hav3m.png +0 -0
- package/src/assets/img/vessel.jpg +0 -0
- package/src/assets/raw/boat.svg +15 -0
- package/src/assets/raw/cash.svg +39 -0
- package/src/assets/raw/police.json +1 -0
- package/src/assets/raw/svelte.svg +1 -0
- package/src/lib/Counter.svelte +10 -0
- package/src/lib/components/AppRoot.svelte +15 -0
- package/src/lib/components/ContentScale.ts +12 -0
- package/src/lib/components/Icon.svelte +47 -0
- package/src/lib/components/Image.svelte +31 -0
- package/src/lib/components/Spacer.svelte +11 -0
- package/src/lib/components/Surface.svelte +19 -0
- package/src/lib/components/Text.svelte +23 -0
- package/src/lib/components/TonalButton.svelte +34 -0
- package/src/lib/components/buttons/Button.svelte +34 -0
- package/src/lib/components/buttons/ButtonWithIcon.svelte +0 -0
- package/src/lib/components/buttons/IconButton.svelte +0 -0
- package/src/lib/components/buttons/OutlinedButton.svelte +0 -0
- package/src/lib/components/buttons/OutlinedButtonWithIcon.svelte +0 -0
- package/src/lib/components/buttons/OutlinedIconButton.svelte +0 -0
- package/src/lib/components/buttons/TextButton.svelte +0 -0
- package/src/lib/components/cards/Card.svelte +0 -0
- package/src/lib/components/cards/OutlinedCard.svelte +0 -0
- package/src/lib/components/layouts/Alignment.ts +37 -0
- package/src/lib/components/layouts/Arrangement.ts +66 -0
- package/src/lib/components/layouts/Box.svelte +25 -0
- package/src/lib/components/layouts/Column.svelte +23 -0
- package/src/lib/components/layouts/LazyColumn.svelte +0 -0
- package/src/lib/components/layouts/LazyRow.svelte +0 -0
- package/src/lib/components/layouts/Row.svelte +23 -0
- package/src/lib/components/layouts/Scafold.svelte +0 -0
- package/src/lib/components/menus/DropdownMenu.svelte +0 -0
- package/src/lib/components/menus/DropdownMenuItem.svelte +0 -0
- package/src/lib/components/textFields/BaseTextField.svelte +130 -0
- package/src/lib/components/textFields/OutlinedTextField.svelte +52 -0
- package/src/lib/components/textFields/TextField.svelte +36 -0
- package/src/lib/components/textFields/TextFieldColors.ts +11 -0
- package/src/lib/components/textFields/TextFieldDefaults.ts +48 -0
- package/src/lib/core/helpers/painterResource.ts +26 -0
- package/src/lib/core/modifier/Modifier.ts +259 -0
- package/src/lib/core/modifier/ModifierImpl.ts +275 -0
- package/src/lib/core/shapes/RoundedCornerShape.ts +53 -0
- package/src/lib/core/shapes/Shape.ts +3 -0
- package/src/lib/core/theme/ColorScheme.ts +25 -0
- package/src/lib/core/theme/ComposeTheme.svelte +22 -0
- package/src/lib/core/theme/TextStyle.ts +25 -0
- package/src/lib/core/theme/colors.ts +21 -0
- package/src/lib/core/theme/cssVars.ts +32 -0
- package/src/lib/core/theme/defaults/darkColors.ts +17 -0
- package/src/lib/core/theme/defaults/defaultTheme.ts +35 -0
- package/src/lib/core/theme/defaults/lightColors.ts +17 -0
- package/src/lib/core/theme/defaults/typography.ts +128 -0
- package/src/lib/core/theme/elevation.ts +7 -0
- package/src/lib/core/theme/getCurrentColor.ts +10 -0
- package/src/lib/core/theme/resolve.ts +29 -0
- package/src/lib/core/theme/shapes.ts +7 -0
- package/src/lib/core/theme/spacing.ts +7 -0
- package/src/lib/core/theme/store.ts +26 -0
- package/src/lib/core/theme/systemTheme.ts +20 -0
- package/src/lib/core/theme/theme.ts +15 -0
- package/src/lib/core/theme/typography.ts +29 -0
- package/src/lib/index.ts +42 -0
- package/src/main.ts +9 -0
- package/svelte.config.js +8 -0
- package/tsconfig.app.json +21 -0
- package/tsconfig.json +7 -0
- package/tsconfig.node.json +26 -0
- package/vite.config.ts +11 -0
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { ColorScheme as Def } from "./colors";
|
|
2
|
+
|
|
3
|
+
export type ColorToken = keyof Def;
|
|
4
|
+
|
|
5
|
+
export const ColorScheme = {
|
|
6
|
+
Primary: "primary",
|
|
7
|
+
OnPrimary: "onPrimary",
|
|
8
|
+
|
|
9
|
+
Secondary: "secondary",
|
|
10
|
+
OnSecondary: "onSecondary",
|
|
11
|
+
|
|
12
|
+
Background: "background",
|
|
13
|
+
OnBackground: "onBackground",
|
|
14
|
+
|
|
15
|
+
Surface: "surface",
|
|
16
|
+
OnSurface: "onSurface",
|
|
17
|
+
|
|
18
|
+
SurfaceVariant: "surfaceVariant",
|
|
19
|
+
OnSurfaceVariant: "onSurfaceVariant",
|
|
20
|
+
|
|
21
|
+
Outline: "outline",
|
|
22
|
+
|
|
23
|
+
Error: "error",
|
|
24
|
+
OnError: "onError",
|
|
25
|
+
} as const;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { themeState, resolvedTheme } from "./store";
|
|
3
|
+
import { themeToCssVars } from "./cssVars";
|
|
4
|
+
import { defaultLightTheme, defaultDarkTheme } from "./defaults/defaultTheme";
|
|
5
|
+
import type { ComposeTheme as Theme, ThemeMode } from "./theme";
|
|
6
|
+
|
|
7
|
+
export let light: Theme | undefined = undefined;
|
|
8
|
+
export let dark: Theme | undefined = undefined;
|
|
9
|
+
export let mode: ThemeMode = "system";
|
|
10
|
+
|
|
11
|
+
$: themeState.set({
|
|
12
|
+
light: light ?? defaultLightTheme,
|
|
13
|
+
dark: dark ?? defaultDarkTheme,
|
|
14
|
+
mode,
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
$: css = $resolvedTheme ? themeToCssVars($resolvedTheme) : "";
|
|
18
|
+
</script>
|
|
19
|
+
|
|
20
|
+
<div style={css}>
|
|
21
|
+
<slot />
|
|
22
|
+
</div>
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { Typography } from "./typography";
|
|
2
|
+
|
|
3
|
+
export type TextStyleToken = keyof Typography;
|
|
4
|
+
|
|
5
|
+
export const TextStyle = {
|
|
6
|
+
DisplayLarge: "displayLarge",
|
|
7
|
+
DisplayMedium: "displayMedium",
|
|
8
|
+
DisplaySmall: "displaySmall",
|
|
9
|
+
|
|
10
|
+
HeadlineLarge: "headlineLarge",
|
|
11
|
+
HeadlineMedium: "headlineMedium",
|
|
12
|
+
HeadlineSmall: "headlineSmall",
|
|
13
|
+
|
|
14
|
+
TitleLarge: "titleLarge",
|
|
15
|
+
TitleMedium: "titleMedium",
|
|
16
|
+
TitleSmall: "titleSmall",
|
|
17
|
+
|
|
18
|
+
BodyLarge: "bodyLarge",
|
|
19
|
+
BodyMedium: "bodyMedium",
|
|
20
|
+
BodySmall: "bodySmall",
|
|
21
|
+
|
|
22
|
+
LabelLarge: "labelLarge",
|
|
23
|
+
LabelMedium: "labelMedium",
|
|
24
|
+
LabelSmall: "labelSmall",
|
|
25
|
+
} as const;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export interface ColorScheme {
|
|
2
|
+
primary: string;
|
|
3
|
+
onPrimary: string;
|
|
4
|
+
|
|
5
|
+
secondary: string;
|
|
6
|
+
onSecondary: string;
|
|
7
|
+
|
|
8
|
+
background: string;
|
|
9
|
+
onBackground: string;
|
|
10
|
+
|
|
11
|
+
surface: string;
|
|
12
|
+
onSurface: string;
|
|
13
|
+
|
|
14
|
+
surfaceVariant: string;
|
|
15
|
+
onSurfaceVariant: string;
|
|
16
|
+
|
|
17
|
+
outline: string;
|
|
18
|
+
|
|
19
|
+
error: string;
|
|
20
|
+
onError: string;
|
|
21
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { ComposeTheme } from "./theme";
|
|
2
|
+
|
|
3
|
+
export function themeToCssVars(theme: ComposeTheme): string {
|
|
4
|
+
const vars: string[] = [];
|
|
5
|
+
|
|
6
|
+
Object.entries(theme.colorScheme).forEach(([k, v]) =>
|
|
7
|
+
vars.push(`--md-sys-color-${k}: ${v};`)
|
|
8
|
+
);
|
|
9
|
+
|
|
10
|
+
// === Tipografía: una variable por cada propiedad (¡esto soluciona el bug!) ===
|
|
11
|
+
Object.entries(theme.typography).forEach(([styleKey, style]) => {
|
|
12
|
+
vars.push(`--md-sys-typescale-${styleKey}-font-family: ${style.fontFamily};`);
|
|
13
|
+
vars.push(`--md-sys-typescale-${styleKey}-font-size: ${style.fontSize};`);
|
|
14
|
+
vars.push(`--md-sys-typescale-${styleKey}-line-height: ${style.lineHeight};`);
|
|
15
|
+
vars.push(`--md-sys-typescale-${styleKey}-letter-spacing: ${style.letterSpacing};`);
|
|
16
|
+
vars.push(`--md-sys-typescale-${styleKey}-font-weight: ${style.fontWeight};`);
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
Object.entries(theme.shapes).forEach(([k, v]) =>
|
|
20
|
+
vars.push(`--md-sys-shape-${k}: ${v};`)
|
|
21
|
+
);
|
|
22
|
+
|
|
23
|
+
Object.entries(theme.elevation).forEach(([k, v]) =>
|
|
24
|
+
vars.push(`--md-sys-elevation-${k}: ${v};`)
|
|
25
|
+
);
|
|
26
|
+
|
|
27
|
+
Object.entries(theme.spacing).forEach(([k, v]) =>
|
|
28
|
+
vars.push(`--md-sys-spacing-${k}: ${v};`)
|
|
29
|
+
);
|
|
30
|
+
|
|
31
|
+
return vars.join("\n");
|
|
32
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { ColorScheme } from "../colors";
|
|
2
|
+
|
|
3
|
+
export const darkColors: ColorScheme = {
|
|
4
|
+
primary: "#FFD700",
|
|
5
|
+
onPrimary: "#080808",
|
|
6
|
+
secondary: "#3A3E49",
|
|
7
|
+
onSecondary: "#E6E6E6",
|
|
8
|
+
background: "#080808",
|
|
9
|
+
onBackground: "#E6E6E6",
|
|
10
|
+
surface: "#101010",
|
|
11
|
+
onSurface: "#E6E6E6",
|
|
12
|
+
surfaceVariant: "#1E1E1E",
|
|
13
|
+
onSurfaceVariant: "#CAC4D0",
|
|
14
|
+
outline: "#4A4A4A",
|
|
15
|
+
error: "#FF6F61",
|
|
16
|
+
onError: "#080808",
|
|
17
|
+
};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { lightColors } from "./lightColors"
|
|
2
|
+
import { darkColors } from "./darkColors"
|
|
3
|
+
import { defaultTypography } from "./typography"
|
|
4
|
+
import type { ComposeTheme } from "../theme"
|
|
5
|
+
|
|
6
|
+
export const defaultLightTheme: ComposeTheme = {
|
|
7
|
+
colorScheme: lightColors,
|
|
8
|
+
typography: defaultTypography,
|
|
9
|
+
shapes: {
|
|
10
|
+
none: "0px",
|
|
11
|
+
extraSmall: "4px",
|
|
12
|
+
small: "8px",
|
|
13
|
+
medium: "12px",
|
|
14
|
+
large: "16px",
|
|
15
|
+
},
|
|
16
|
+
spacing: {
|
|
17
|
+
xs: "4px",
|
|
18
|
+
sm: "8px",
|
|
19
|
+
md: "16px",
|
|
20
|
+
lg: "24px",
|
|
21
|
+
xl: "32px",
|
|
22
|
+
},
|
|
23
|
+
elevation: {
|
|
24
|
+
level0: "none",
|
|
25
|
+
level1: "0 1px 2px rgba(0,0,0,0.2)",
|
|
26
|
+
level2: "0 2px 6px rgba(0,0,0,0.2)",
|
|
27
|
+
level3: "0 6px 12px rgba(0,0,0,0.25)",
|
|
28
|
+
level4: "0 12px 24px rgba(0,0,0,0.3)",
|
|
29
|
+
},
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export const defaultDarkTheme: ComposeTheme = {
|
|
33
|
+
...defaultLightTheme,
|
|
34
|
+
colorScheme: darkColors,
|
|
35
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { ColorScheme } from "../colors";
|
|
2
|
+
|
|
3
|
+
export const lightColors: ColorScheme = {
|
|
4
|
+
primary: "#D4AF37", // Violeta más intenso
|
|
5
|
+
onPrimary: "#080808",
|
|
6
|
+
secondary: "#3A3E49", // Teal vibrante
|
|
7
|
+
onSecondary: "#FFFFFF",
|
|
8
|
+
background: "#FFFBF2",
|
|
9
|
+
onBackground: "#1C1B1F",
|
|
10
|
+
surface: "#FFFFFF",
|
|
11
|
+
onSurface: "#1C1B1F",
|
|
12
|
+
surfaceVariant: "#F8F9FA",
|
|
13
|
+
onSurfaceVariant: "#DEE1E6",
|
|
14
|
+
outline: "#B0B0B0",
|
|
15
|
+
error: "#BA1A1A",
|
|
16
|
+
onError: "#FFFFFF",
|
|
17
|
+
};
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import type { Typography } from "../typography";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Material Design 3 - Type Scale
|
|
5
|
+
* Nombres EXACTOS a Jetpack Compose Material 3:
|
|
6
|
+
* displayLarge, displayMedium, displaySmall,
|
|
7
|
+
* headlineLarge, headlineMedium, headlineSmall,
|
|
8
|
+
* titleLarge, titleMedium, titleSmall,
|
|
9
|
+
* bodyLarge, bodyMedium, bodySmall,
|
|
10
|
+
* labelLarge, labelMedium, labelSmall
|
|
11
|
+
*
|
|
12
|
+
* Valores (size/lineHeight/letterSpacing/fontWeight) corresponden a MD3.
|
|
13
|
+
* fontFamily: system stack por defecto (overrideable por el consumidor).
|
|
14
|
+
*/
|
|
15
|
+
const fontFamily =
|
|
16
|
+
"system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif";
|
|
17
|
+
|
|
18
|
+
export const defaultTypography: Typography = {
|
|
19
|
+
displayLarge: {
|
|
20
|
+
fontFamily,
|
|
21
|
+
fontSize: "57px",
|
|
22
|
+
lineHeight: "64px",
|
|
23
|
+
letterSpacing: "-0.25px",
|
|
24
|
+
fontWeight: 400,
|
|
25
|
+
},
|
|
26
|
+
displayMedium: {
|
|
27
|
+
fontFamily,
|
|
28
|
+
fontSize: "45px",
|
|
29
|
+
lineHeight: "52px",
|
|
30
|
+
letterSpacing: "0px",
|
|
31
|
+
fontWeight: 400,
|
|
32
|
+
},
|
|
33
|
+
displaySmall: {
|
|
34
|
+
fontFamily,
|
|
35
|
+
fontSize: "36px",
|
|
36
|
+
lineHeight: "44px",
|
|
37
|
+
letterSpacing: "0px",
|
|
38
|
+
fontWeight: 400,
|
|
39
|
+
},
|
|
40
|
+
|
|
41
|
+
headlineLarge: {
|
|
42
|
+
fontFamily,
|
|
43
|
+
fontSize: "32px",
|
|
44
|
+
lineHeight: "40px",
|
|
45
|
+
letterSpacing: "0px",
|
|
46
|
+
fontWeight: 400,
|
|
47
|
+
},
|
|
48
|
+
headlineMedium: {
|
|
49
|
+
fontFamily,
|
|
50
|
+
fontSize: "28px",
|
|
51
|
+
lineHeight: "36px",
|
|
52
|
+
letterSpacing: "0px",
|
|
53
|
+
fontWeight: 400,
|
|
54
|
+
},
|
|
55
|
+
headlineSmall: {
|
|
56
|
+
fontFamily,
|
|
57
|
+
fontSize: "24px",
|
|
58
|
+
lineHeight: "32px",
|
|
59
|
+
letterSpacing: "0px",
|
|
60
|
+
fontWeight: 400,
|
|
61
|
+
},
|
|
62
|
+
|
|
63
|
+
titleLarge: {
|
|
64
|
+
fontFamily,
|
|
65
|
+
fontSize: "22px",
|
|
66
|
+
lineHeight: "28px",
|
|
67
|
+
letterSpacing: "0px",
|
|
68
|
+
fontWeight: 400,
|
|
69
|
+
},
|
|
70
|
+
titleMedium: {
|
|
71
|
+
fontFamily,
|
|
72
|
+
fontSize: "16px",
|
|
73
|
+
lineHeight: "24px",
|
|
74
|
+
letterSpacing: "0.15px",
|
|
75
|
+
fontWeight: 500,
|
|
76
|
+
},
|
|
77
|
+
titleSmall: {
|
|
78
|
+
fontFamily,
|
|
79
|
+
fontSize: "14px",
|
|
80
|
+
lineHeight: "20px",
|
|
81
|
+
letterSpacing: "0.1px",
|
|
82
|
+
fontWeight: 500,
|
|
83
|
+
},
|
|
84
|
+
|
|
85
|
+
bodyLarge: {
|
|
86
|
+
fontFamily,
|
|
87
|
+
fontSize: "16px",
|
|
88
|
+
lineHeight: "24px",
|
|
89
|
+
letterSpacing: "0.5px",
|
|
90
|
+
fontWeight: 400,
|
|
91
|
+
},
|
|
92
|
+
bodyMedium: {
|
|
93
|
+
fontFamily,
|
|
94
|
+
fontSize: "14px",
|
|
95
|
+
lineHeight: "20px",
|
|
96
|
+
letterSpacing: "0.25px",
|
|
97
|
+
fontWeight: 400,
|
|
98
|
+
},
|
|
99
|
+
bodySmall: {
|
|
100
|
+
fontFamily,
|
|
101
|
+
fontSize: "12px",
|
|
102
|
+
lineHeight: "16px",
|
|
103
|
+
letterSpacing: "0.4px",
|
|
104
|
+
fontWeight: 400,
|
|
105
|
+
},
|
|
106
|
+
|
|
107
|
+
labelLarge: {
|
|
108
|
+
fontFamily,
|
|
109
|
+
fontSize: "14px",
|
|
110
|
+
lineHeight: "20px",
|
|
111
|
+
letterSpacing: "0.1px",
|
|
112
|
+
fontWeight: 500,
|
|
113
|
+
},
|
|
114
|
+
labelMedium: {
|
|
115
|
+
fontFamily,
|
|
116
|
+
fontSize: "12px",
|
|
117
|
+
lineHeight: "16px",
|
|
118
|
+
letterSpacing: "0.5px",
|
|
119
|
+
fontWeight: 500,
|
|
120
|
+
},
|
|
121
|
+
labelSmall: {
|
|
122
|
+
fontFamily,
|
|
123
|
+
fontSize: "11px",
|
|
124
|
+
lineHeight: "16px",
|
|
125
|
+
letterSpacing: "0.5px",
|
|
126
|
+
fontWeight: 500,
|
|
127
|
+
},
|
|
128
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { get } from "svelte/store";
|
|
2
|
+
import { resolvedTheme } from "./store";
|
|
3
|
+
|
|
4
|
+
export function getCurrentColor(token: string): string {
|
|
5
|
+
const theme = get(resolvedTheme);
|
|
6
|
+
if (!theme) return "#2a2a2a"; // fallback
|
|
7
|
+
|
|
8
|
+
// Buscamos el token en el colorScheme actual
|
|
9
|
+
return theme.colorScheme[token as keyof typeof theme.colorScheme] || "#2a2a2a";
|
|
10
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { ColorToken } from "./ColorScheme";
|
|
2
|
+
import type { TextStyleToken } from "./TextStyle";
|
|
3
|
+
|
|
4
|
+
export const resolveColor = (c: ColorToken) =>
|
|
5
|
+
`var(--md-sys-color-${c})`;
|
|
6
|
+
|
|
7
|
+
export function resolveTintColor(color: ColorToken | string): string {
|
|
8
|
+
if (color.startsWith("#") || color.startsWith("rgb") || color.startsWith("hsl")) {
|
|
9
|
+
return color; // directo
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
// Para token del tema, resolvemos var a hex/RGB real usando getComputedStyle
|
|
13
|
+
const dummy = document.createElement("div");
|
|
14
|
+
dummy.style.color = resolveColor(color as ColorToken); // var(--...)
|
|
15
|
+
document.body.appendChild(dummy);
|
|
16
|
+
const computed = getComputedStyle(dummy).color; // rgb(...) o hex
|
|
17
|
+
document.body.removeChild(dummy);
|
|
18
|
+
|
|
19
|
+
return computed;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
// Ahora resolvemos cada propiedad por separado
|
|
23
|
+
export const resolveTextStyle = (t: TextStyleToken) => `
|
|
24
|
+
font-family: var(--md-sys-typescale-${t}-font-family);
|
|
25
|
+
font-size: var(--md-sys-typescale-${t}-font-size);
|
|
26
|
+
line-height: var(--md-sys-typescale-${t}-line-height);
|
|
27
|
+
letter-spacing: var(--md-sys-typescale-${t}-letter-spacing);
|
|
28
|
+
font-weight: var(--md-sys-typescale-${t}-font-weight);
|
|
29
|
+
`;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { writable, derived } from "svelte/store";
|
|
2
|
+
import type { ComposeTheme, ThemeMode } from "./theme";
|
|
3
|
+
import { systemTheme } from "./systemTheme";
|
|
4
|
+
|
|
5
|
+
export const themeState = writable<{
|
|
6
|
+
light: ComposeTheme;
|
|
7
|
+
dark: ComposeTheme;
|
|
8
|
+
mode: ThemeMode;
|
|
9
|
+
} | null>(null);
|
|
10
|
+
|
|
11
|
+
// 🔑 ESTE es el tema efectivo (como MaterialTheme)
|
|
12
|
+
export const resolvedTheme = derived(
|
|
13
|
+
[themeState, systemTheme],
|
|
14
|
+
([$theme, $system]) => {
|
|
15
|
+
if (!$theme) return null;
|
|
16
|
+
|
|
17
|
+
const mode =
|
|
18
|
+
$theme.mode === "system"
|
|
19
|
+
? $system
|
|
20
|
+
: $theme.mode;
|
|
21
|
+
|
|
22
|
+
return mode === "dark"
|
|
23
|
+
? $theme.dark
|
|
24
|
+
: $theme.light;
|
|
25
|
+
}
|
|
26
|
+
);
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { readable } from "svelte/store";
|
|
2
|
+
|
|
3
|
+
export type SystemTheme = "light" | "dark";
|
|
4
|
+
|
|
5
|
+
export const systemTheme = readable<SystemTheme>("light", (set) => {
|
|
6
|
+
if (typeof window === "undefined") return;
|
|
7
|
+
|
|
8
|
+
const media = window.matchMedia("(prefers-color-scheme: dark)");
|
|
9
|
+
|
|
10
|
+
const update = () => {
|
|
11
|
+
set(media.matches ? "dark" : "light");
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
update(); // estado inicial
|
|
15
|
+
media.addEventListener("change", update);
|
|
16
|
+
|
|
17
|
+
return () => {
|
|
18
|
+
media.removeEventListener("change", update);
|
|
19
|
+
};
|
|
20
|
+
});
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { ColorScheme } from "./colors";
|
|
2
|
+
import type { Typography } from "./typography";
|
|
3
|
+
import type { Shapes } from "./shapes";
|
|
4
|
+
import type { Spacing } from "./spacing";
|
|
5
|
+
import type { Elevation } from "./elevation";
|
|
6
|
+
|
|
7
|
+
export interface ComposeTheme {
|
|
8
|
+
colorScheme: ColorScheme;
|
|
9
|
+
typography: Typography;
|
|
10
|
+
shapes: Shapes;
|
|
11
|
+
spacing: Spacing;
|
|
12
|
+
elevation: Elevation;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export type ThemeMode = "light" | "dark" | "system";
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
export interface TextStyle {
|
|
2
|
+
fontFamily: string;
|
|
3
|
+
fontSize: string;
|
|
4
|
+
lineHeight: string;
|
|
5
|
+
letterSpacing: string;
|
|
6
|
+
fontWeight: number;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export interface Typography {
|
|
10
|
+
displayLarge: TextStyle;
|
|
11
|
+
displayMedium: TextStyle;
|
|
12
|
+
displaySmall: TextStyle;
|
|
13
|
+
|
|
14
|
+
headlineLarge: TextStyle;
|
|
15
|
+
headlineMedium: TextStyle;
|
|
16
|
+
headlineSmall: TextStyle;
|
|
17
|
+
|
|
18
|
+
titleLarge: TextStyle;
|
|
19
|
+
titleMedium: TextStyle;
|
|
20
|
+
titleSmall: TextStyle;
|
|
21
|
+
|
|
22
|
+
bodyLarge: TextStyle;
|
|
23
|
+
bodyMedium: TextStyle;
|
|
24
|
+
bodySmall: TextStyle;
|
|
25
|
+
|
|
26
|
+
labelLarge: TextStyle;
|
|
27
|
+
labelMedium: TextStyle;
|
|
28
|
+
labelSmall: TextStyle;
|
|
29
|
+
}
|
package/src/lib/index.ts
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
// =========================
|
|
2
|
+
// COMPONENTS (Svelte)
|
|
3
|
+
// =========================
|
|
4
|
+
// LAYOUTS
|
|
5
|
+
export { default as ComposeTheme } from "./core/theme/ComposeTheme.svelte";
|
|
6
|
+
export { default as AppRoot } from "./components/AppRoot.svelte"
|
|
7
|
+
// COMPONENTS
|
|
8
|
+
export { default as Surface } from "./components/Surface.svelte";
|
|
9
|
+
export { default as Text } from "./components/Text.svelte";
|
|
10
|
+
export { default as Column } from "./components/layouts/Column.svelte";
|
|
11
|
+
export { default as Row } from "./components/layouts/Row.svelte";
|
|
12
|
+
export { default as Box } from "./components/layouts/Box.svelte";
|
|
13
|
+
export { default as Spacer } from "./components/Spacer.svelte"
|
|
14
|
+
export { default as Button } from "./components/buttons/Button.svelte"
|
|
15
|
+
export { default as IconButton } from "./components/buttons/IconButton.svelte"
|
|
16
|
+
export { default as ButtonWithIcon } from "./components/buttons/ButtonWithIcon.svelte"
|
|
17
|
+
export { default as OutlinedIconButton } from "./components/buttons/OutlinedButton.svelte"
|
|
18
|
+
export { default as OutlinedButtonWithIcon } from "./components/buttons/OutlinedButtonWithIcon.svelte"
|
|
19
|
+
export { default as TextButton } from "./components/buttons/TextButton.svelte"
|
|
20
|
+
export { default as OutlinedButton } from "./components/buttons/OutlinedButton.svelte"
|
|
21
|
+
export { default as Card } from "./components/cards/Card.svelte"
|
|
22
|
+
export { default as OutlinedCard } from "./components/cards/OutlinedCard.svelte"
|
|
23
|
+
export { default as TextField } from "./components/textFields/TextField.svelte"
|
|
24
|
+
export { default as OutlinedTextField } from "./components/textFields/OutlinedTextField.svelte"
|
|
25
|
+
export { default as TonalButton } from "./components/TonalButton.svelte"
|
|
26
|
+
export { default as LazyColumn } from "./components/layouts/LazyColumn.svelte"
|
|
27
|
+
export { default as LazyRow } from "./components/layouts/LazyRow.svelte"
|
|
28
|
+
export { default as Icon } from "./components/Icon.svelte"
|
|
29
|
+
export { default as Image } from "./components/Image.svelte"
|
|
30
|
+
|
|
31
|
+
// =========================
|
|
32
|
+
// TOKENS / API (TS only)
|
|
33
|
+
// =========================
|
|
34
|
+
export * from "./core/shapes/RoundedCornerShape"
|
|
35
|
+
export * from "./core/theme/ColorScheme";
|
|
36
|
+
export * from "./core/theme/TextStyle";
|
|
37
|
+
export * from "./core/modifier/Modifier"
|
|
38
|
+
export * from "./components/layouts/Arrangement";
|
|
39
|
+
export * from "./components/layouts/Alignment";
|
|
40
|
+
export * from "./components/ContentScale"
|
|
41
|
+
export * from "./core/helpers/painterResource"
|
|
42
|
+
export * from "./components/ContentScale"
|
package/src/main.ts
ADDED
package/svelte.config.js
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { vitePreprocess } from '@sveltejs/vite-plugin-svelte'
|
|
2
|
+
|
|
3
|
+
/** @type {import("@sveltejs/vite-plugin-svelte").SvelteConfig} */
|
|
4
|
+
export default {
|
|
5
|
+
// Consult https://svelte.dev/docs#compile-time-svelte-preprocess
|
|
6
|
+
// for more information about preprocessors
|
|
7
|
+
preprocess: vitePreprocess(),
|
|
8
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": "@tsconfig/svelte/tsconfig.json",
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
"tsBuildInfoFile": "./node_modules/.tmp/tsconfig.app.tsbuildinfo",
|
|
5
|
+
"target": "ES2022",
|
|
6
|
+
"useDefineForClassFields": true,
|
|
7
|
+
"module": "ESNext",
|
|
8
|
+
"types": ["svelte", "vite/client"],
|
|
9
|
+
"noEmit": true,
|
|
10
|
+
/**
|
|
11
|
+
* Typecheck JS in `.svelte` and `.js` files by default.
|
|
12
|
+
* Disable checkJs if you'd like to use dynamic types in JS.
|
|
13
|
+
* Note that setting allowJs false does not prevent the use
|
|
14
|
+
* of JS in `.svelte` files.
|
|
15
|
+
*/
|
|
16
|
+
"allowJs": true,
|
|
17
|
+
"checkJs": true,
|
|
18
|
+
"moduleDetection": "force"
|
|
19
|
+
},
|
|
20
|
+
"include": ["src/**/*.ts", "src/**/*.js", "src/**/*.svelte"]
|
|
21
|
+
}
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"tsBuildInfoFile": "./node_modules/.tmp/tsconfig.node.tsbuildinfo",
|
|
4
|
+
"target": "ES2023",
|
|
5
|
+
"lib": ["ES2023"],
|
|
6
|
+
"module": "ESNext",
|
|
7
|
+
"types": ["node"],
|
|
8
|
+
"skipLibCheck": true,
|
|
9
|
+
|
|
10
|
+
/* Bundler mode */
|
|
11
|
+
"moduleResolution": "bundler",
|
|
12
|
+
"allowImportingTsExtensions": true,
|
|
13
|
+
"verbatimModuleSyntax": true,
|
|
14
|
+
"moduleDetection": "force",
|
|
15
|
+
"noEmit": true,
|
|
16
|
+
|
|
17
|
+
/* Linting */
|
|
18
|
+
"strict": true,
|
|
19
|
+
"noUnusedLocals": true,
|
|
20
|
+
"noUnusedParameters": true,
|
|
21
|
+
"erasableSyntaxOnly": true,
|
|
22
|
+
"noFallthroughCasesInSwitch": true,
|
|
23
|
+
"noUncheckedSideEffectImports": true
|
|
24
|
+
},
|
|
25
|
+
"include": ["vite.config.ts"]
|
|
26
|
+
}
|
package/vite.config.ts
ADDED