@zaide6137/m3-components-web 0.1.1 → 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/README.md +0 -0
- package/dist/index.d.mts +62 -0
- package/dist/index.d.ts +62 -0
- package/dist/index.js +1 -0
- package/dist/index.mjs +1 -0
- package/package.json +18 -2
package/README.md
ADDED
|
File without changes
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import * as react from 'react';
|
|
2
|
+
|
|
3
|
+
interface MaterialTheme {
|
|
4
|
+
primary: string;
|
|
5
|
+
onPrimary: string;
|
|
6
|
+
primaryContainer: string;
|
|
7
|
+
onPrimaryContainer: string;
|
|
8
|
+
secondary: string;
|
|
9
|
+
onSecondary: string;
|
|
10
|
+
secondaryContainer: string;
|
|
11
|
+
onSecondaryContainer: string;
|
|
12
|
+
tertiary: string;
|
|
13
|
+
onTertiary: string;
|
|
14
|
+
tertiaryContainer: string;
|
|
15
|
+
onTertiaryContainer: string;
|
|
16
|
+
error: string;
|
|
17
|
+
onError: string;
|
|
18
|
+
errorContainer: string;
|
|
19
|
+
onErrorContainer: string;
|
|
20
|
+
background: string;
|
|
21
|
+
onBackground: string;
|
|
22
|
+
surface: string;
|
|
23
|
+
onSurface: string;
|
|
24
|
+
surfaceVariant: string;
|
|
25
|
+
onSurfaceVariant: string;
|
|
26
|
+
outline: string;
|
|
27
|
+
outlineVariant: string;
|
|
28
|
+
shadow: string;
|
|
29
|
+
scrim: string;
|
|
30
|
+
inverseSurface: string;
|
|
31
|
+
inverseOnSurface: string;
|
|
32
|
+
inversePrimary: string;
|
|
33
|
+
surfaceDim: string;
|
|
34
|
+
surfaceBright: string;
|
|
35
|
+
surfaceContainerLowest: string;
|
|
36
|
+
surfaceContainerLow: string;
|
|
37
|
+
surfaceContainer: string;
|
|
38
|
+
surfaceContainerHigh: string;
|
|
39
|
+
surfaceContainerHighest: string;
|
|
40
|
+
}
|
|
41
|
+
type MaterialTokenKey = keyof MaterialTheme;
|
|
42
|
+
type DefaultColorScheme = 'light' | 'dark' | 'auto';
|
|
43
|
+
interface ThemeContextType {
|
|
44
|
+
themeColors: MaterialTheme;
|
|
45
|
+
setThemeColors: (seed: string) => void;
|
|
46
|
+
systemTheme: DefaultColorScheme;
|
|
47
|
+
}
|
|
48
|
+
interface ThemeProviderProps {
|
|
49
|
+
children: React.ReactNode;
|
|
50
|
+
seedColor?: string;
|
|
51
|
+
defaultColorScheme?: DefaultColorScheme;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
declare const ThemeContext: react.Context<ThemeContextType | null>;
|
|
55
|
+
declare const ThemeProvider: React.FC<ThemeProviderProps>;
|
|
56
|
+
declare const useGlobalTheme: () => ThemeContextType;
|
|
57
|
+
|
|
58
|
+
declare function createModernTheme(seedHex: string, isDark: boolean): MaterialTheme;
|
|
59
|
+
declare function hexToArgba(hex: string, alpha: number): string;
|
|
60
|
+
declare function isDarkBackground(hex: string): boolean;
|
|
61
|
+
|
|
62
|
+
export { type DefaultColorScheme, type MaterialTheme, type MaterialTokenKey, ThemeContext, type ThemeContextType, ThemeProvider, type ThemeProviderProps, createModernTheme, hexToArgba, isDarkBackground, useGlobalTheme };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import * as react from 'react';
|
|
2
|
+
|
|
3
|
+
interface MaterialTheme {
|
|
4
|
+
primary: string;
|
|
5
|
+
onPrimary: string;
|
|
6
|
+
primaryContainer: string;
|
|
7
|
+
onPrimaryContainer: string;
|
|
8
|
+
secondary: string;
|
|
9
|
+
onSecondary: string;
|
|
10
|
+
secondaryContainer: string;
|
|
11
|
+
onSecondaryContainer: string;
|
|
12
|
+
tertiary: string;
|
|
13
|
+
onTertiary: string;
|
|
14
|
+
tertiaryContainer: string;
|
|
15
|
+
onTertiaryContainer: string;
|
|
16
|
+
error: string;
|
|
17
|
+
onError: string;
|
|
18
|
+
errorContainer: string;
|
|
19
|
+
onErrorContainer: string;
|
|
20
|
+
background: string;
|
|
21
|
+
onBackground: string;
|
|
22
|
+
surface: string;
|
|
23
|
+
onSurface: string;
|
|
24
|
+
surfaceVariant: string;
|
|
25
|
+
onSurfaceVariant: string;
|
|
26
|
+
outline: string;
|
|
27
|
+
outlineVariant: string;
|
|
28
|
+
shadow: string;
|
|
29
|
+
scrim: string;
|
|
30
|
+
inverseSurface: string;
|
|
31
|
+
inverseOnSurface: string;
|
|
32
|
+
inversePrimary: string;
|
|
33
|
+
surfaceDim: string;
|
|
34
|
+
surfaceBright: string;
|
|
35
|
+
surfaceContainerLowest: string;
|
|
36
|
+
surfaceContainerLow: string;
|
|
37
|
+
surfaceContainer: string;
|
|
38
|
+
surfaceContainerHigh: string;
|
|
39
|
+
surfaceContainerHighest: string;
|
|
40
|
+
}
|
|
41
|
+
type MaterialTokenKey = keyof MaterialTheme;
|
|
42
|
+
type DefaultColorScheme = 'light' | 'dark' | 'auto';
|
|
43
|
+
interface ThemeContextType {
|
|
44
|
+
themeColors: MaterialTheme;
|
|
45
|
+
setThemeColors: (seed: string) => void;
|
|
46
|
+
systemTheme: DefaultColorScheme;
|
|
47
|
+
}
|
|
48
|
+
interface ThemeProviderProps {
|
|
49
|
+
children: React.ReactNode;
|
|
50
|
+
seedColor?: string;
|
|
51
|
+
defaultColorScheme?: DefaultColorScheme;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
declare const ThemeContext: react.Context<ThemeContextType | null>;
|
|
55
|
+
declare const ThemeProvider: React.FC<ThemeProviderProps>;
|
|
56
|
+
declare const useGlobalTheme: () => ThemeContextType;
|
|
57
|
+
|
|
58
|
+
declare function createModernTheme(seedHex: string, isDark: boolean): MaterialTheme;
|
|
59
|
+
declare function hexToArgba(hex: string, alpha: number): string;
|
|
60
|
+
declare function isDarkBackground(hex: string): boolean;
|
|
61
|
+
|
|
62
|
+
export { type DefaultColorScheme, type MaterialTheme, type MaterialTokenKey, ThemeContext, type ThemeContextType, ThemeProvider, type ThemeProviderProps, createModernTheme, hexToArgba, isDarkBackground, useGlobalTheme };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
'use strict';var react=require('react'),materialColorUtilities=require('@material/material-color-utilities'),jsxRuntime=require('react/jsx-runtime');function c(o,r){let t=materialColorUtilities.Hct.fromInt(materialColorUtilities.argbFromHex(o)),a=new materialColorUtilities.SchemeVibrant(t,r,0),n={},e=["primary","onPrimary","primaryContainer","onPrimaryContainer","secondary","onSecondary","secondaryContainer","onSecondaryContainer","tertiary","onTertiary","tertiaryContainer","onTertiaryContainer","error","onError","errorContainer","onErrorContainer","background","onBackground","surface","onSurface","surfaceVariant","onSurfaceVariant","outline","outlineVariant","shadow","scrim","inverseSurface","inverseOnSurface","inversePrimary","surfaceDim","surfaceBright","surfaceContainerLowest","surfaceContainerLow","surfaceContainer","surfaceContainerHigh","surfaceContainerHighest"];for(let u of e){let m=MaterialDynamicColors[u];m&&(n[u]=materialColorUtilities.hexFromArgb(m.getArgb(a)));}return n}function v(o,r){let t=o.replace("#",""),a=parseInt(t.substring(0,2),16),n=parseInt(t.substring(2,4),16),e=parseInt(t.substring(4,6),16);return `rgba(${a}, ${n}, ${e}, ${r})`}function P(o){let r=o.replace("#",""),t=parseInt(r.substring(0,2),16),a=parseInt(r.substring(2,4),16),n=parseInt(r.substring(4,6),16);return .2126*t+.7152*a+.0722*n<128}var l=react.createContext(null),w=c("#6750A4",false),H=({children:o,seedColor:r="#6750A4",defaultColorScheme:t="auto"})=>{let[a,n]=react.useState(()=>{let s=t==="dark";return t==="auto"&&typeof window<"u"&&(s=window.matchMedia("(prefers-color-scheme: dark)").matches),c(r,s)}),[e,u]=react.useState(t);react.useEffect(()=>{if(e==="auto"&&typeof window<"u"){let s=window.matchMedia("(prefers-color-scheme: dark)"),i=f=>{n(c(r,f.matches));};return s.addEventListener("change",i),()=>s.removeEventListener("change",i)}},[e,r]);let m=react.useMemo(()=>({themeColors:a,systemTheme:e,setThemeColors:s=>{let i=e==="dark";e==="auto"?i=typeof window<"u"?window.matchMedia("(prefers-color-scheme: dark)").matches:false:e==="light"&&(i=false),n(c(s,i));}}),[a,e]);return jsxRuntime.jsx(l.Provider,{value:m,children:o})},I=()=>{let o=react.useContext(l);return o||{themeColors:w,systemTheme:"auto",setThemeColors:()=>{throw new Error("[@zaide6137/m3-components-web] Cannot call `setThemeColors` outside of a <ThemeProvider>. Wrap your app in the provider to enable dynamic theme switching.")}}};exports.ThemeContext=l;exports.ThemeProvider=H;exports.createModernTheme=c;exports.hexToArgba=v;exports.isDarkBackground=P;exports.useGlobalTheme=I;
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import {createContext,useState,useEffect,useMemo,useContext}from'react';import {Hct,argbFromHex,SchemeVibrant,hexFromArgb}from'@material/material-color-utilities';import {jsx}from'react/jsx-runtime';function c(o,r){let t=Hct.fromInt(argbFromHex(o)),a=new SchemeVibrant(t,r,0),n={},e=["primary","onPrimary","primaryContainer","onPrimaryContainer","secondary","onSecondary","secondaryContainer","onSecondaryContainer","tertiary","onTertiary","tertiaryContainer","onTertiaryContainer","error","onError","errorContainer","onErrorContainer","background","onBackground","surface","onSurface","surfaceVariant","onSurfaceVariant","outline","outlineVariant","shadow","scrim","inverseSurface","inverseOnSurface","inversePrimary","surfaceDim","surfaceBright","surfaceContainerLowest","surfaceContainerLow","surfaceContainer","surfaceContainerHigh","surfaceContainerHighest"];for(let u of e){let m=MaterialDynamicColors[u];m&&(n[u]=hexFromArgb(m.getArgb(a)));}return n}function v(o,r){let t=o.replace("#",""),a=parseInt(t.substring(0,2),16),n=parseInt(t.substring(2,4),16),e=parseInt(t.substring(4,6),16);return `rgba(${a}, ${n}, ${e}, ${r})`}function P(o){let r=o.replace("#",""),t=parseInt(r.substring(0,2),16),a=parseInt(r.substring(2,4),16),n=parseInt(r.substring(4,6),16);return .2126*t+.7152*a+.0722*n<128}var l=createContext(null),w=c("#6750A4",false),H=({children:o,seedColor:r="#6750A4",defaultColorScheme:t="auto"})=>{let[a,n]=useState(()=>{let s=t==="dark";return t==="auto"&&typeof window<"u"&&(s=window.matchMedia("(prefers-color-scheme: dark)").matches),c(r,s)}),[e,u]=useState(t);useEffect(()=>{if(e==="auto"&&typeof window<"u"){let s=window.matchMedia("(prefers-color-scheme: dark)"),i=f=>{n(c(r,f.matches));};return s.addEventListener("change",i),()=>s.removeEventListener("change",i)}},[e,r]);let m=useMemo(()=>({themeColors:a,systemTheme:e,setThemeColors:s=>{let i=e==="dark";e==="auto"?i=typeof window<"u"?window.matchMedia("(prefers-color-scheme: dark)").matches:false:e==="light"&&(i=false),n(c(s,i));}}),[a,e]);return jsx(l.Provider,{value:m,children:o})},I=()=>{let o=useContext(l);return o||{themeColors:w,systemTheme:"auto",setThemeColors:()=>{throw new Error("[@zaide6137/m3-components-web] Cannot call `setThemeColors` outside of a <ThemeProvider>. Wrap your app in the provider to enable dynamic theme switching.")}}};export{l as ThemeContext,H as ThemeProvider,c as createModernTheme,v as hexToArgba,P as isDarkBackground,I as useGlobalTheme};
|
package/package.json
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
"email": "lbd6137@gmail.com",
|
|
6
6
|
"url": "https://jiandale.zaidellc.com"
|
|
7
7
|
},
|
|
8
|
-
"version": "0.1.
|
|
8
|
+
"version": "0.1.2",
|
|
9
9
|
"description": "Material 3 React Web Components",
|
|
10
10
|
"main": "./dist/index.js",
|
|
11
11
|
"module": "./dist/index.mjs",
|
|
@@ -18,11 +18,27 @@
|
|
|
18
18
|
"publishConfig": {
|
|
19
19
|
"access": "public"
|
|
20
20
|
},
|
|
21
|
+
"exports": {
|
|
22
|
+
".": {
|
|
23
|
+
"types": "./dist/index.d.ts",
|
|
24
|
+
"import": "./dist/index.mjs",
|
|
25
|
+
"require": "./dist/index.js"
|
|
26
|
+
}
|
|
27
|
+
},
|
|
28
|
+
"files": [
|
|
29
|
+
"dist"
|
|
30
|
+
],
|
|
21
31
|
"peerDependencies": {
|
|
22
32
|
"react": ">=18",
|
|
23
33
|
"react-dom": ">=18"
|
|
24
34
|
},
|
|
25
35
|
"dependencies": {
|
|
26
|
-
"
|
|
36
|
+
"@material/material-color-utilities": "^0.4.0"
|
|
37
|
+
},
|
|
38
|
+
"devDependencies": {
|
|
39
|
+
"@types/react": "^19.2.14",
|
|
40
|
+
"@types/react-dom": "^19.2.3",
|
|
41
|
+
"tsup": "^8.5.1",
|
|
42
|
+
"typescript": "^5.9.3"
|
|
27
43
|
}
|
|
28
44
|
}
|