@geoffcox/sterling-svelte 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/README.md ADDED
@@ -0,0 +1,14 @@
1
+ # sterling-svelte
2
+
3
+ A modern, accessible, and lightweight component library for Svelte.
4
+
5
+ ## Installation
6
+
7
+ ```
8
+ npm install @geoffcox/sterling-svelte
9
+ ```
10
+
11
+ ## Documentation
12
+
13
+ The project builds the documentation for the library as a SvelteKit application.
14
+ See the published version of the [documentation](https://geoffcox.github.io/demos/sterling-svelte/).
package/index.d.ts ADDED
@@ -0,0 +1 @@
1
+ export { type Theme, type ThemeActionParams, applyDarkTheme, applyLightTheme, applyTheme, darkTheme, lightTheme, neutrals, toggleDarkTheme } from './theme';
package/index.js ADDED
@@ -0,0 +1 @@
1
+ export { applyDarkTheme, applyLightTheme, applyTheme, darkTheme, lightTheme, neutrals, toggleDarkTheme } from './theme';
package/package.json ADDED
@@ -0,0 +1,41 @@
1
+ {
2
+ "name": "@geoffcox/sterling-svelte",
3
+ "version": "0.0.1",
4
+ "devDependencies": {
5
+ "@fontsource/fira-mono": "^4.5.10",
6
+ "@fontsource/overpass": "^4.5.10",
7
+ "@playwright/test": "^1.28.1",
8
+ "@sveltejs/adapter-auto": "^1.0.0",
9
+ "@sveltejs/adapter-static": "^1.0.0",
10
+ "@sveltejs/kit": "^1.0.0",
11
+ "@sveltejs/package": "^1.0.0",
12
+ "@typescript-eslint/eslint-plugin": "^5.45.0",
13
+ "@typescript-eslint/parser": "^5.45.0",
14
+ "eslint": "^8.28.0",
15
+ "eslint-config-prettier": "^8.5.0",
16
+ "eslint-plugin-svelte3": "^4.0.0",
17
+ "mdsvex": "^0.10.6",
18
+ "prettier": "^2.8.0",
19
+ "prettier-plugin-svelte": "^2.8.1",
20
+ "svelte": "^3.54.0",
21
+ "svelte-check": "^2.9.2",
22
+ "tslib": "^2.4.1",
23
+ "typescript": "^4.9.3",
24
+ "vite": "^4.0.0",
25
+ "vitest": "^0.25.3"
26
+ },
27
+ "type": "module",
28
+ "exports": {
29
+ "./package.json": "./package.json",
30
+ ".": "./index.js",
31
+ "./theme/applyDarkTheme": "./theme/applyDarkTheme.js",
32
+ "./theme/applyLightTheme": "./theme/applyLightTheme.js",
33
+ "./theme/applyTheme": "./theme/applyTheme.js",
34
+ "./theme/colors": "./theme/colors.js",
35
+ "./theme/darkTheme": "./theme/darkTheme.js",
36
+ "./theme": "./theme/index.js",
37
+ "./theme/lightTheme": "./theme/lightTheme.js",
38
+ "./theme/toggleDarkTheme": "./theme/toggleDarkTheme.js",
39
+ "./theme/types": "./theme/types.js"
40
+ }
41
+ }
@@ -0,0 +1,7 @@
1
+ import type { ThemeActionParams } from './types';
2
+ /**
3
+ * Applies the default dark theme.
4
+ */
5
+ export declare const applyDarkTheme: (node: HTMLElement, params?: Omit<ThemeActionParams, 'theme' | 'context'>) => {
6
+ update: (params?: ThemeActionParams | undefined) => void;
7
+ };
@@ -0,0 +1,11 @@
1
+ import { applyTheme } from './applyTheme';
2
+ import { darkTheme } from './darkTheme';
3
+ /**
4
+ * Applies the default dark theme.
5
+ */
6
+ export const applyDarkTheme = (node, params) => {
7
+ return applyTheme(node, {
8
+ ...params,
9
+ theme: darkTheme
10
+ });
11
+ };
@@ -0,0 +1,7 @@
1
+ import type { ThemeActionParams } from './types';
2
+ /**
3
+ * Applies the default light theme.
4
+ */
5
+ export declare const applyLightTheme: (node: HTMLElement, params?: Omit<ThemeActionParams, 'theme' | 'context'>) => {
6
+ update: (params?: ThemeActionParams | undefined) => void;
7
+ };
@@ -0,0 +1,11 @@
1
+ import { applyTheme } from './applyTheme';
2
+ import { lightTheme } from './lightTheme';
3
+ /**
4
+ * Applies the default light theme.
5
+ */
6
+ export const applyLightTheme = (node, params) => {
7
+ return applyTheme(node, {
8
+ ...params,
9
+ theme: lightTheme
10
+ });
11
+ };
@@ -0,0 +1,7 @@
1
+ import type { ThemeActionParams } from './types';
2
+ /**
3
+ * Applies a theme.
4
+ */
5
+ export declare const applyTheme: (node: HTMLElement, params: ThemeActionParams) => {
6
+ update: (params?: ThemeActionParams) => void;
7
+ };
@@ -0,0 +1,19 @@
1
+ const _applyTheme = (node, theme) => {
2
+ Object.keys(theme).map((key) => {
3
+ node.style.setProperty(key, theme[key] ? `${theme[key]}` : null);
4
+ });
5
+ };
6
+ /**
7
+ * Applies a theme.
8
+ */
9
+ export const applyTheme = (node, params) => {
10
+ const element = params.atDocumentRoot ? document.documentElement : node;
11
+ _applyTheme(element, params.theme);
12
+ return {
13
+ update: (params) => {
14
+ if (params) {
15
+ _applyTheme(document.documentElement, params?.theme);
16
+ }
17
+ }
18
+ };
19
+ };
@@ -0,0 +1 @@
1
+ export declare const neutrals: Record<string, string>;
@@ -0,0 +1,13 @@
1
+ export const neutrals = {
2
+ neutral0: 'hsl(0, 0%, 0%)',
3
+ neutral15: 'hsl(0, 0%, 15%)',
4
+ neutral30: 'hsl(0, 0%, 30%)',
5
+ neutral45: 'hsl(0, 0%, 45%)',
6
+ neutral60: 'hsl(0, 0%, 60%)',
7
+ neutral75: 'hsl(0, 0%, 75%)',
8
+ neutral85: 'hsl(0, 0%, 85%)',
9
+ neutral92: 'hsl(0, 0%, 92%)',
10
+ neutral96: 'hsl(0, 0%, 96%)',
11
+ neutral98: 'hsl(0, 0%, 98%)',
12
+ neutral100: 'hsl(0, 0%, 100%)'
13
+ };
@@ -0,0 +1,2 @@
1
+ import type { Theme } from './types';
2
+ export declare const darkTheme: Theme;
@@ -0,0 +1,94 @@
1
+ import { neutrals } from './colors';
2
+ export const darkTheme = {
3
+ // ----- Common ---- //
4
+ '--Common__background-color': neutrals.neutral15,
5
+ '--Common__border-color': neutrals.neutral92,
6
+ '--Common__border-radius': '0',
7
+ '--Common__border-style': 'solid',
8
+ '--Common__border-width': '2px',
9
+ '--Common__color': neutrals.neutral100,
10
+ // hover
11
+ '--Common__background-color--hover': neutrals.neutral15,
12
+ '--Common__border-color--hover': neutrals.neutral96,
13
+ '--Common__color--hover': neutrals.neutral100,
14
+ // focus
15
+ '--Common__background-color--focus': neutrals.neutral45,
16
+ '--Common__border-color--focus': neutrals.neutral100,
17
+ '--Common__color--focus': neutrals.neutral100,
18
+ // outline
19
+ '--Common__outline-color': neutrals.neutral100,
20
+ '--Common__outline-offset': '0',
21
+ '--Common__outline-style': 'solid',
22
+ '--Common__outline-width': '2px',
23
+ // disabled
24
+ '--Common__background-color--disabled': neutrals.neutral45,
25
+ '--Common__border-color--disabled': neutrals.neutral92,
26
+ '--Common__color--disabled': neutrals.neutral92,
27
+ // ----- BaseLayer ---- //
28
+ '--BaseLayer__background-color': neutrals.neutral15,
29
+ '--BaseLayer__color': neutrals.neutral100,
30
+ '--BaseLayer__background-color--1': neutrals.neutral30,
31
+ '--BaseLayer__color--1': neutrals.neutral100,
32
+ '--BaseLayer__background-color--2': neutrals.neutral45,
33
+ '--BaseLayer__color--2': neutrals.neutral100,
34
+ '--BaseLayer__background-color--3': neutrals.neutral60,
35
+ '--BaseLayer__color--3': neutrals.neutral100,
36
+ // ----- Button ----- //
37
+ '--Button__background-color': neutrals.neutral45,
38
+ '--Button__border-color': neutrals.neutral92,
39
+ '--Button__border-radius': '8px',
40
+ '--Button__border-style': 'solid',
41
+ '--Button__border-width': '2px',
42
+ '--Button__color': neutrals.neutral100,
43
+ // hover
44
+ '--Button__background-color--hover': neutrals.neutral45,
45
+ '--Button__border-color--hover': neutrals.neutral96,
46
+ '--Button__color--hover': neutrals.neutral100,
47
+ // active
48
+ '--Button__background-color--active': neutrals.neutral60,
49
+ '--Button__border-color--active': neutrals.neutral98,
50
+ '--Button__color--active': neutrals.neutral98,
51
+ // focus
52
+ '--Button__background-color--focus': neutrals.neutral45,
53
+ '--Button__border-color--focus': neutrals.neutral100,
54
+ '--Button__color--focus': neutrals.neutral100,
55
+ // disabled
56
+ '--Button__background-color--disabled': neutrals.neutral75,
57
+ '--Button__border-color--disabled': neutrals.neutral92,
58
+ '--Button__color--disabled': neutrals.neutral92,
59
+ // ----- Input ----- //
60
+ '--Input__background-color': neutrals.neutral30,
61
+ '--Input__border-color': neutrals.neutral92,
62
+ '--Input__border-radius': '3px',
63
+ '--Input__border-style': 'solid',
64
+ '--Input__border-width': '2px',
65
+ '--Input__color': neutrals.neutral100,
66
+ // hover
67
+ '--Input__background-color--hover': neutrals.neutral15,
68
+ '--Input__border-color--hover': neutrals.neutral96,
69
+ '--Input__color--hover': neutrals.neutral100,
70
+ // focus
71
+ '--Input__background-color--focus': neutrals.neutral15,
72
+ '--Input__border-color--focus': neutrals.neutral100,
73
+ '--Input__color--focus': neutrals.neutral100,
74
+ // selected
75
+ '--Input__background-color--selected': neutrals.neutral60,
76
+ '--Input__border-color--selected': neutrals.neutral98,
77
+ '--Input__color--selected': neutrals.neutral100,
78
+ // disabled
79
+ '--Input__background-color--disabled': neutrals.neutral45,
80
+ '--Input__border-color--disabled': neutrals.neutral85,
81
+ '--Input__color--disabled': neutrals.neutral85,
82
+ // ----- Display ----- //
83
+ '--Display__background-color': neutrals.neutral60,
84
+ '--Display__border-color': neutrals.neutral92,
85
+ '--Display__color': neutrals.neutral100,
86
+ '--Display__color--subtle': neutrals.neutral96,
87
+ '--Display__color--faint': neutrals.neutral45,
88
+ '--Display__color--disabled': neutrals.neutral45,
89
+ '--Display__color--info': '#025E73',
90
+ '--Display__color--progress': '#0099DD',
91
+ '--Display__color--success': '#03A64A',
92
+ '--Display__color--warning': '#F2A71B',
93
+ '--Display__color--error': '#A62B1F'
94
+ };
@@ -0,0 +1,8 @@
1
+ export * from './applyDarkTheme';
2
+ export * from './applyLightTheme';
3
+ export * from './applyTheme';
4
+ export * from './colors';
5
+ export * from './darkTheme';
6
+ export * from './lightTheme';
7
+ export * from './toggleDarkTheme';
8
+ export * from './types';
package/theme/index.js ADDED
@@ -0,0 +1,8 @@
1
+ export * from './applyDarkTheme';
2
+ export * from './applyLightTheme';
3
+ export * from './applyTheme';
4
+ export * from './colors';
5
+ export * from './darkTheme';
6
+ export * from './lightTheme';
7
+ export * from './toggleDarkTheme';
8
+ export * from './types';
@@ -0,0 +1,2 @@
1
+ import type { Theme } from './types';
2
+ export declare const lightTheme: Theme;
@@ -0,0 +1,94 @@
1
+ import { neutrals } from './colors';
2
+ export const lightTheme = {
3
+ // ----- Common ---- //
4
+ '--Common__background-color': neutrals.neutral100,
5
+ '--Common__border-color': neutrals.neutral60,
6
+ '--Common__border-radius': '0',
7
+ '--Common__border-style': 'solid',
8
+ '--Common__border-width': '2px',
9
+ '--Common__color': neutrals.neutral15,
10
+ // hover
11
+ '--Common__background-color--hover': neutrals.neutral100,
12
+ '--Common__border-color--hover': neutrals.neutral45,
13
+ '--Common__color--hover': neutrals.neutral15,
14
+ // focus
15
+ '--Common__background-color--focus': neutrals.neutral96,
16
+ '--Common__border-color--focus': neutrals.neutral0,
17
+ '--Common__color--focus': neutrals.neutral15,
18
+ // outline
19
+ '--Common__outline-color': neutrals.neutral15,
20
+ '--Common__outline-offset': '0',
21
+ '--Common__outline-style': 'solid',
22
+ '--Common__outline-width': '2px',
23
+ // disabled
24
+ '--Common__background-color--disabled': neutrals.neutral96,
25
+ '--Common__border-color--disabled': neutrals.neutral60,
26
+ '--Common__color--disabled': neutrals.neutral60,
27
+ // ----- BaseLayer ---- //
28
+ '--BaseLayer__background-color': neutrals.neutral100,
29
+ '--BaseLayer__color': neutrals.neutral15,
30
+ '--BaseLayer__background-color--1': neutrals.neutral98,
31
+ '--BaseLayer__color--1': neutrals.neutral15,
32
+ '--BaseLayer__background-color--2': neutrals.neutral96,
33
+ '--BaseLayer__color--2': neutrals.neutral15,
34
+ '--BaseLayer__background-color--3': neutrals.neutral92,
35
+ '--BaseLayer__color--3': neutrals.neutral15,
36
+ // ----- Button ----- //
37
+ '--Button__background-color': neutrals.neutral96,
38
+ '--Button__border-color': neutrals.neutral60,
39
+ '--Button__border-radius': '8px',
40
+ '--Button__border-style': 'solid',
41
+ '--Button__border-width': '2px',
42
+ '--Button__color': neutrals.neutral15,
43
+ // hover
44
+ '--Button__background-color--hover': neutrals.neutral96,
45
+ '--Button__border-color--hover': neutrals.neutral45,
46
+ '--Button__color--hover': neutrals.neutral15,
47
+ // active
48
+ '--Button__background-color--active': neutrals.neutral92,
49
+ '--Button__border-color--active': neutrals.neutral30,
50
+ '--Button__color--active': neutrals.neutral30,
51
+ // focus
52
+ '--Button__background-color--focus': neutrals.neutral96,
53
+ '--Button__border-color--focus': neutrals.neutral0,
54
+ '--Button__color--focus': neutrals.neutral15,
55
+ // disabled
56
+ '--Button__background-color--disabled': neutrals.neutral85,
57
+ '--Button__border-color--disabled': neutrals.neutral60,
58
+ '--Button__color--disabled': neutrals.neutral60,
59
+ // ----- Input ----- //
60
+ '--Input__background-color': neutrals.neutral98,
61
+ '--Input__border-color': neutrals.neutral60,
62
+ '--Input__border-radius': '3px',
63
+ '--Input__border-style': 'solid',
64
+ '--Input__border-width': '2px',
65
+ '--Input__color': neutrals.neutral15,
66
+ // hover
67
+ '--Input__background-color--hover': neutrals.neutral100,
68
+ '--Input__border-color--hover': neutrals.neutral45,
69
+ '--Input__color--hover': neutrals.neutral15,
70
+ // focus
71
+ '--Input__background-color--focus': neutrals.neutral100,
72
+ '--Input__border-color--focus': neutrals.neutral15,
73
+ '--Input__color--focus': neutrals.neutral15,
74
+ // selected
75
+ '--Input__background-color--selected': neutrals.neutral92,
76
+ '--Input__border-color--selected': neutrals.neutral30,
77
+ '--Input__color--selected': neutrals.neutral15,
78
+ // disabled
79
+ '--Input__background-color--disabled': neutrals.neutral96,
80
+ '--Input__border-color--disabled': neutrals.neutral75,
81
+ '--Input__color--disabled': neutrals.neutral75,
82
+ // ----- Display ----- //
83
+ '--Display__background-color': neutrals.neutral92,
84
+ '--Display__border-color': neutrals.neutral60,
85
+ '--Display__color': neutrals.neutral15,
86
+ '--Display__color--subtle': neutrals.neutral30,
87
+ '--Display__color--faint': neutrals.neutral85,
88
+ '--Display__color--disabled': neutrals.neutral85,
89
+ '--Display__color--info': '#025E73',
90
+ '--Display__color--progress': '#0099DD',
91
+ '--Display__color--success': '#03A64A',
92
+ '--Display__color--warning': '#F2A71B',
93
+ '--Display__color--error': '#A62B1F'
94
+ };
@@ -0,0 +1,18 @@
1
+ import type { ThemeActionParams } from './types';
2
+ type Params = Omit<ThemeActionParams, 'theme'> & {
3
+ dark?: boolean;
4
+ };
5
+ /**
6
+ * An action that applies
7
+ * - `darkTheme` when dark is true
8
+ * - `lightTheme` when dark is false
9
+ * - `darkTheme` or `lightTheme` based on `prefers-color-scheme` when dark is undefined
10
+ *
11
+ * @example ```use:toggleDarkMode```
12
+ * @example ```use:toggleDarkMode={{ dark: myToggleVariable }}```
13
+ */
14
+ export declare const toggleDarkTheme: (node: HTMLElement, params?: Params) => {
15
+ destory(): void;
16
+ update(params?: Params): void;
17
+ };
18
+ export {};
@@ -0,0 +1,53 @@
1
+ import { applyDarkTheme } from './applyDarkTheme';
2
+ import { applyLightTheme } from './applyLightTheme';
3
+ const _applyTheme = (node, params) => {
4
+ let dark = params?.dark;
5
+ if (params?.dark === undefined) {
6
+ dark = window.matchMedia('(prefers-color-scheme: dark)').matches;
7
+ }
8
+ if (dark) {
9
+ applyDarkTheme(node, params);
10
+ }
11
+ else {
12
+ applyLightTheme(node, params);
13
+ }
14
+ };
15
+ const onPrefersColorSchemeDarkChanged = (e, node, params) => {
16
+ let dark = params?.dark;
17
+ if (params?.dark === undefined) {
18
+ dark = e.matches;
19
+ }
20
+ if (dark) {
21
+ applyDarkTheme(node, params);
22
+ }
23
+ else {
24
+ applyLightTheme(node, params);
25
+ }
26
+ };
27
+ /**
28
+ * An action that applies
29
+ * - `darkTheme` when dark is true
30
+ * - `lightTheme` when dark is false
31
+ * - `darkTheme` or `lightTheme` based on `prefers-color-scheme` when dark is undefined
32
+ *
33
+ * @example ```use:toggleDarkMode```
34
+ * @example ```use:toggleDarkMode={{ dark: myToggleVariable }}```
35
+ */
36
+ export const toggleDarkTheme = (node, params) => {
37
+ let mediaChangeHandler = (e) => onPrefersColorSchemeDarkChanged(e, node, params);
38
+ const matchMedia = window.matchMedia('(prefers-color-scheme: dark)');
39
+ matchMedia.addEventListener('change', mediaChangeHandler);
40
+ _applyTheme(node, params);
41
+ return {
42
+ destory() {
43
+ matchMedia.removeEventListener('change', mediaChangeHandler);
44
+ },
45
+ update(params) {
46
+ // dark might have changed so resubscribe using new params
47
+ matchMedia.removeEventListener('change', mediaChangeHandler);
48
+ mediaChangeHandler = (e) => onPrefersColorSchemeDarkChanged(e, node, params);
49
+ matchMedia.addEventListener('change', mediaChangeHandler);
50
+ _applyTheme(node, params);
51
+ }
52
+ };
53
+ };
@@ -0,0 +1,21 @@
1
+ type CSSVarProperty = string;
2
+ type CSSVarValue = undefined | string | number | boolean;
3
+ /**
4
+ * A theme consisting of CSS variable property/value pairs.
5
+ */
6
+ export type Theme = Record<CSSVarProperty, CSSVarValue>;
7
+ /**
8
+ * Parameters passed to the theme action.
9
+ */
10
+ export type ThemeActionParams = {
11
+ /**
12
+ * The theme to use.
13
+ */
14
+ theme: Theme;
15
+ /**
16
+ * When true, applies the theme to the document.DocumentElement.
17
+ * Otherwise applies the theme to the element where this action was used.
18
+ */
19
+ atDocumentRoot?: boolean;
20
+ };
21
+ export {};
package/theme/types.js ADDED
@@ -0,0 +1 @@
1
+ export {};