@lidofinance/lido-ui 3.0.0-next.4 → 3.0.0-next.7
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/cjs/cookie-theme-toggler/src/cookie-theme-toggler.js +4 -4
- package/dist/cjs/cookie-theme-toggler/src/cookie-theme-toggler.js.map +1 -1
- package/dist/cjs/cookie-theme-toggler/src/index.js +0 -2
- package/dist/cjs/cookie-theme-toggler/src/index.js.map +1 -1
- package/dist/cjs/cookie-theme-toggler/src/styles.js +25 -3
- package/dist/cjs/cookie-theme-toggler/src/styles.js.map +1 -1
- package/dist/cjs/hooks/src/useSystemTheme.js +1 -1
- package/dist/cjs/hooks/src/useSystemTheme.js.map +1 -1
- package/dist/cjs/loaders/src/InlineLoaderStyles.js +2 -2
- package/dist/cjs/loaders/src/InlineLoaderStyles.js.map +1 -1
- package/dist/cjs/loaders/src/LoaderStyles.js +2 -2
- package/dist/cjs/loaders/src/LoaderStyles.js.map +1 -1
- package/dist/cjs/theme/src/base/colors.js +2 -0
- package/dist/cjs/theme/src/base/colors.js.map +1 -1
- package/dist/cjs/theme/src/constants.js +17 -12
- package/dist/cjs/theme/src/constants.js.map +1 -1
- package/dist/cjs/theme/src/cookie-theme-provider.js +110 -0
- package/dist/cjs/theme/src/cookie-theme-provider.js.map +1 -0
- package/dist/cjs/theme/src/document-head-contents/element-theme-colors.js +33 -20
- package/dist/cjs/theme/src/document-head-contents/element-theme-colors.js.map +1 -1
- package/dist/cjs/theme/src/document-head-contents/element-theme-script.js +26 -13
- package/dist/cjs/theme/src/document-head-contents/element-theme-script.js.map +1 -1
- package/dist/cjs/{cookie-theme-toggler → theme}/src/hooks.js +0 -0
- package/dist/cjs/theme/src/hooks.js.map +1 -0
- package/dist/cjs/theme/src/index.js +3 -1
- package/dist/cjs/theme/src/index.js.map +1 -1
- package/dist/cjs/theme/src/{provider.js → theme-provider.js} +13 -8
- package/dist/cjs/theme/src/theme-provider.js.map +1 -0
- package/dist/cjs/theme/src/themes.js +27 -3
- package/dist/cjs/theme/src/themes.js.map +1 -1
- package/dist/cjs/theme/src/types.js.map +1 -1
- package/dist/cjs/{cookie-theme-toggler/src/utils.js → theme/src/utils/cookies.js} +5 -3
- package/dist/cjs/theme/src/utils/cookies.js.map +1 -0
- package/dist/cjs/theme/src/{document-head-contents/utils → utils}/generate-css-color-variables.js +2 -2
- package/dist/cjs/theme/src/utils/generate-css-color-variables.js.map +1 -0
- package/dist/cjs/utils/src/index.js +10 -3
- package/dist/cjs/utils/src/index.js.map +1 -1
- package/dist/esm/cookie-theme-toggler/src/cookie-theme-toggler.js +4 -4
- package/dist/esm/cookie-theme-toggler/src/cookie-theme-toggler.js.map +1 -1
- package/dist/esm/cookie-theme-toggler/src/index.js +0 -2
- package/dist/esm/cookie-theme-toggler/src/index.js.map +1 -1
- package/dist/esm/cookie-theme-toggler/src/styles.js +14 -0
- package/dist/esm/cookie-theme-toggler/src/styles.js.map +1 -1
- package/dist/esm/hooks/src/useSystemTheme.js +2 -2
- package/dist/esm/hooks/src/useSystemTheme.js.map +1 -1
- package/dist/esm/loaders/src/InlineLoaderStyles.js +2 -2
- package/dist/esm/loaders/src/InlineLoaderStyles.js.map +1 -1
- package/dist/esm/loaders/src/LoaderStyles.js +2 -2
- package/dist/esm/loaders/src/LoaderStyles.js.map +1 -1
- package/dist/esm/theme/src/base/colors.js +2 -0
- package/dist/esm/theme/src/base/colors.js.map +1 -1
- package/dist/esm/theme/src/constants.js +11 -8
- package/dist/esm/theme/src/constants.js.map +1 -1
- package/dist/esm/theme/src/cookie-theme-provider.js +102 -0
- package/dist/esm/theme/src/cookie-theme-provider.js.map +1 -0
- package/dist/esm/theme/src/document-head-contents/element-theme-colors.js +28 -15
- package/dist/esm/theme/src/document-head-contents/element-theme-colors.js.map +1 -1
- package/dist/esm/theme/src/document-head-contents/element-theme-script.js +24 -10
- package/dist/esm/theme/src/document-head-contents/element-theme-script.js.map +1 -1
- package/dist/esm/{cookie-theme-toggler → theme}/src/hooks.js +0 -0
- package/dist/esm/theme/src/hooks.js.map +1 -0
- package/dist/esm/theme/src/index.js +3 -1
- package/dist/esm/theme/src/index.js.map +1 -1
- package/dist/esm/theme/src/theme-provider.js +37 -0
- package/dist/esm/theme/src/theme-provider.js.map +1 -0
- package/dist/esm/theme/src/themes.js +23 -1
- package/dist/esm/theme/src/themes.js.map +1 -1
- package/dist/esm/theme/src/types.js.map +1 -1
- package/dist/esm/{cookie-theme-toggler/src/utils.js → theme/src/utils/cookies.js} +5 -3
- package/dist/esm/theme/src/utils/cookies.js.map +1 -0
- package/dist/esm/theme/src/{document-head-contents/utils → utils}/generate-css-color-variables.js +2 -2
- package/dist/esm/theme/src/utils/generate-css-color-variables.js.map +1 -0
- package/dist/esm/utils/src/index.js +2 -0
- package/dist/esm/utils/src/index.js.map +1 -1
- package/dist/types/accordion/src/AccordionStyles.d.ts +1 -1
- package/dist/types/checkbox/src/CheckboxStyles.d.ts +1 -1
- package/dist/types/cookie-theme-toggler/src/cookie-theme-toggler.d.ts.map +1 -1
- package/dist/types/cookie-theme-toggler/src/index.d.ts +0 -2
- package/dist/types/cookie-theme-toggler/src/index.d.ts.map +1 -1
- package/dist/types/cookie-theme-toggler/src/styles.d.ts +3 -0
- package/dist/types/cookie-theme-toggler/src/styles.d.ts.map +1 -1
- package/dist/types/data-table/src/DataTableStyles.d.ts +1 -1
- package/dist/types/hooks/src/useSystemTheme.d.ts +2 -2
- package/dist/types/hooks/src/useSystemTheme.d.ts.map +1 -1
- package/dist/types/icons/src/index.d.ts +76 -76
- package/dist/types/select/src/Select.d.ts +1 -1
- package/dist/types/select/src/SelectArrowStyles.d.ts +1 -1
- package/dist/types/select/src/SelectIconStyles.d.ts +1 -1
- package/dist/types/select/src/SelectStyles.d.ts +1 -1
- package/dist/types/table/src/styles.d.ts +2 -2
- package/dist/types/theme/src/base/colors.d.ts +2 -0
- package/dist/types/theme/src/base/colors.d.ts.map +1 -1
- package/dist/types/theme/src/base/index.d.ts +2 -0
- package/dist/types/theme/src/base/index.d.ts.map +1 -1
- package/dist/types/theme/src/constants.d.ts +6 -4
- package/dist/types/theme/src/constants.d.ts.map +1 -1
- package/dist/types/theme/src/cookie-theme-provider.d.ts +17 -0
- package/dist/types/theme/src/cookie-theme-provider.d.ts.map +1 -0
- package/dist/types/theme/src/document-head-contents/element-theme-colors.d.ts.map +1 -1
- package/dist/types/theme/src/document-head-contents/element-theme-script.d.ts +0 -1
- package/dist/types/theme/src/document-head-contents/element-theme-script.d.ts.map +1 -1
- package/dist/types/theme/src/hooks.d.ts +3 -0
- package/dist/types/theme/src/hooks.d.ts.map +1 -0
- package/dist/types/theme/src/index.d.ts +3 -1
- package/dist/types/theme/src/index.d.ts.map +1 -1
- package/dist/types/theme/src/theme-provider.d.ts +8 -0
- package/dist/types/theme/src/theme-provider.d.ts.map +1 -0
- package/dist/types/theme/src/themes.d.ts +438 -1
- package/dist/types/theme/src/themes.d.ts.map +1 -1
- package/dist/types/theme/src/types.d.ts +5 -1
- package/dist/types/theme/src/types.d.ts.map +1 -1
- package/dist/types/theme/src/utils/cookies.d.ts +3 -0
- package/dist/types/theme/src/utils/cookies.d.ts.map +1 -0
- package/dist/types/theme/src/{document-head-contents/utils → utils}/generate-css-color-variables.d.ts +0 -0
- package/dist/types/theme/src/utils/generate-css-color-variables.d.ts.map +1 -0
- package/dist/types/utils/src/index.d.ts +1 -0
- package/dist/types/utils/src/index.d.ts.map +1 -1
- package/package.json +2 -2
- package/dist/cjs/cookie-theme-toggler/src/constants.js +0 -18
- package/dist/cjs/cookie-theme-toggler/src/constants.js.map +0 -1
- package/dist/cjs/cookie-theme-toggler/src/cookie-theme-provider.js +0 -66
- package/dist/cjs/cookie-theme-toggler/src/cookie-theme-provider.js.map +0 -1
- package/dist/cjs/cookie-theme-toggler/src/hooks.js.map +0 -1
- package/dist/cjs/cookie-theme-toggler/src/utils.js.map +0 -1
- package/dist/cjs/theme/src/document-head-contents/utils/generate-css-color-variables.js.map +0 -1
- package/dist/cjs/theme/src/globals.js +0 -26
- package/dist/cjs/theme/src/globals.js.map +0 -1
- package/dist/cjs/theme/src/provider.js.map +0 -1
- package/dist/cjs/theme/src/styles.js +0 -47
- package/dist/cjs/theme/src/styles.js.map +0 -1
- package/dist/esm/cookie-theme-toggler/src/constants.js +0 -4
- package/dist/esm/cookie-theme-toggler/src/constants.js.map +0 -1
- package/dist/esm/cookie-theme-toggler/src/cookie-theme-provider.js +0 -53
- package/dist/esm/cookie-theme-toggler/src/cookie-theme-provider.js.map +0 -1
- package/dist/esm/cookie-theme-toggler/src/hooks.js.map +0 -1
- package/dist/esm/cookie-theme-toggler/src/utils.js.map +0 -1
- package/dist/esm/theme/src/document-head-contents/utils/generate-css-color-variables.js.map +0 -1
- package/dist/esm/theme/src/globals.js +0 -11
- package/dist/esm/theme/src/globals.js.map +0 -1
- package/dist/esm/theme/src/provider.js +0 -32
- package/dist/esm/theme/src/provider.js.map +0 -1
- package/dist/esm/theme/src/styles.js +0 -38
- package/dist/esm/theme/src/styles.js.map +0 -1
- package/dist/types/cookie-theme-toggler/src/constants.d.ts +0 -3
- package/dist/types/cookie-theme-toggler/src/constants.d.ts.map +0 -1
- package/dist/types/cookie-theme-toggler/src/cookie-theme-provider.d.ts +0 -13
- package/dist/types/cookie-theme-toggler/src/cookie-theme-provider.d.ts.map +0 -1
- package/dist/types/cookie-theme-toggler/src/hooks.d.ts +0 -3
- package/dist/types/cookie-theme-toggler/src/hooks.d.ts.map +0 -1
- package/dist/types/cookie-theme-toggler/src/utils.d.ts +0 -3
- package/dist/types/cookie-theme-toggler/src/utils.d.ts.map +0 -1
- package/dist/types/theme/src/document-head-contents/utils/generate-css-color-variables.d.ts.map +0 -1
- package/dist/types/theme/src/globals.d.ts +0 -8
- package/dist/types/theme/src/globals.d.ts.map +0 -1
- package/dist/types/theme/src/provider.d.ts +0 -11
- package/dist/types/theme/src/provider.d.ts.map +0 -1
|
@@ -6,15 +6,15 @@ Object.defineProperty(exports, "ThemeToggler", {
|
|
|
6
6
|
enumerable: true,
|
|
7
7
|
get: ()=>ThemeToggler
|
|
8
8
|
});
|
|
9
|
-
const _icons = require("../../icons/src/index");
|
|
10
9
|
const _styles = require("./styles");
|
|
11
|
-
const
|
|
10
|
+
const _icons = require("../../icons/src/index");
|
|
11
|
+
const _theme = require("../../theme/src/index");
|
|
12
12
|
const ThemeToggler = ()=>{
|
|
13
|
-
const { toggleTheme
|
|
13
|
+
const { toggleTheme } = (0, _theme.useThemeToggle)();
|
|
14
14
|
return /*#__PURE__*/ React.createElement(_styles.CookieThemeTogglerStyle, {
|
|
15
15
|
color: "secondary",
|
|
16
16
|
onClick: toggleTheme
|
|
17
|
-
},
|
|
17
|
+
}, /*#__PURE__*/ React.createElement(_styles.DarkWrapper, null, /*#__PURE__*/ React.createElement(_icons.Dark, null)), /*#__PURE__*/ React.createElement(_styles.LightWrapper, null, /*#__PURE__*/ React.createElement(_icons.Light, null)));
|
|
18
18
|
};
|
|
19
19
|
|
|
20
20
|
//# sourceMappingURL=cookie-theme-toggler.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../packages/cookie-theme-toggler/src/cookie-theme-toggler.tsx"],"sourcesContent":["import { FC } from 'react'\nimport {
|
|
1
|
+
{"version":3,"sources":["../../../../packages/cookie-theme-toggler/src/cookie-theme-toggler.tsx"],"sourcesContent":["import { FC } from 'react'\nimport { CookieThemeTogglerStyle, DarkWrapper, LightWrapper } from './styles'\nimport { Dark, Light } from '@lidofinance/icons'\nimport { useThemeToggle } from '@lidofinance/theme'\n\nexport const ThemeToggler: FC = () => {\n const { toggleTheme } = useThemeToggle()\n\n return (\n <CookieThemeTogglerStyle color='secondary' onClick={toggleTheme}>\n <DarkWrapper>\n <Dark />\n </DarkWrapper>\n <LightWrapper>\n <Light />\n </LightWrapper>\n </CookieThemeTogglerStyle>\n )\n}\n"],"names":["ThemeToggler","toggleTheme","useThemeToggle","CookieThemeTogglerStyle","color","onClick","DarkWrapper","Dark","LightWrapper","Light"],"mappings":"AAAA;;;;+BAKaA,cAAY;;aAAZA,YAAY;;wBAJ0C,UAAU;uBACjD,uBAAoB;uBACjB,uBAAoB;AAE5C,MAAMA,YAAY,GAAO,IAAM;IACpC,MAAM,EAAEC,WAAW,CAAA,EAAE,GAAGC,IAAAA,MAAc,eAAA,GAAE;IAExC,qBACE,oBAACC,OAAuB,wBAAA;QAACC,KAAK,EAAC,WAAW;QAACC,OAAO,EAAEJ,WAAW;qBAC7D,oBAACK,OAAW,YAAA,sBACV,oBAACC,MAAI,KAAA,OAAG,CACI,gBACd,oBAACC,OAAY,aAAA,sBACX,oBAACC,MAAK,MAAA,OAAG,CACI,CACS,CAC3B;AACH,CAAC"}
|
|
@@ -3,8 +3,6 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
3
3
|
value: true
|
|
4
4
|
});
|
|
5
5
|
const _exportStar = require("@swc/helpers/lib/_export_star.js").default;
|
|
6
|
-
_exportStar(require("./cookie-theme-provider"), exports);
|
|
7
6
|
_exportStar(require("./cookie-theme-toggler"), exports);
|
|
8
|
-
_exportStar(require("./hooks"), exports);
|
|
9
7
|
|
|
10
8
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../packages/cookie-theme-toggler/src/index.ts"],"sourcesContent":["export * from './cookie-theme-
|
|
1
|
+
{"version":3,"sources":["../../../../packages/cookie-theme-toggler/src/index.ts"],"sourcesContent":["export * from './cookie-theme-toggler'\n"],"names":[],"mappings":"AAAA;;;;;oBAAc,wBAAwB"}
|
|
@@ -2,9 +2,17 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", {
|
|
3
3
|
value: true
|
|
4
4
|
});
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
function _export(target, all) {
|
|
6
|
+
for(var name in all)Object.defineProperty(target, name, {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: all[name]
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
_export(exports, {
|
|
12
|
+
CookieThemeTogglerStyle: ()=>CookieThemeTogglerStyle,
|
|
13
|
+
IconWrapper: ()=>IconWrapper,
|
|
14
|
+
LightWrapper: ()=>LightWrapper,
|
|
15
|
+
DarkWrapper: ()=>DarkWrapper
|
|
8
16
|
});
|
|
9
17
|
const _interopRequireDefault = require("@swc/helpers/lib/_interop_require_default.js").default;
|
|
10
18
|
const _styledComponents = /*#__PURE__*/ _interopRequireDefault(require("styled-components"));
|
|
@@ -22,6 +30,20 @@ const CookieThemeTogglerStyle = (0, _styledComponents.default)(_button.Button).a
|
|
|
22
30
|
padding-right: 10px;
|
|
23
31
|
line-height: 0;
|
|
24
32
|
font-size: 0;
|
|
33
|
+
|
|
34
|
+
width: 44px;
|
|
35
|
+
height: 44px;
|
|
36
|
+
`;
|
|
37
|
+
const IconWrapper = _styledComponents.default.span`
|
|
38
|
+
position: absolute;
|
|
39
|
+
top: -12px;
|
|
40
|
+
left: -12px;
|
|
41
|
+
`;
|
|
42
|
+
const LightWrapper = (0, _styledComponents.default)(IconWrapper)`
|
|
43
|
+
visibility: var(--lido-color-lightModeVisibility);
|
|
44
|
+
`;
|
|
45
|
+
const DarkWrapper = (0, _styledComponents.default)(IconWrapper)`
|
|
46
|
+
visibility: var(--lido-color-darkModeVisibility);
|
|
25
47
|
`;
|
|
26
48
|
|
|
27
49
|
//# sourceMappingURL=styles.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../packages/cookie-theme-toggler/src/styles.tsx"],"sourcesContent":["import styled from 'styled-components'\nimport { Button } from '@lidofinance/button'\n\nexport const CookieThemeTogglerStyle = styled(Button).attrs({\n variant: 'text',\n size: 'xs',\n})`\n min-width: 0;\n margin-left: ${({ theme }) => theme.spaceMap.sm}px;\n padding-left: 10px;\n padding-right: 10px;\n line-height: 0;\n font-size: 0;\n`\n"],"names":["CookieThemeTogglerStyle","styled","Button","attrs","variant","size","theme","spaceMap","sm"],"mappings":"AAAA
|
|
1
|
+
{"version":3,"sources":["../../../../packages/cookie-theme-toggler/src/styles.tsx"],"sourcesContent":["import styled from 'styled-components'\nimport { Button } from '@lidofinance/button'\n\nexport const CookieThemeTogglerStyle = styled(Button).attrs({\n variant: 'text',\n size: 'xs',\n})`\n min-width: 0;\n margin-left: ${({ theme }) => theme.spaceMap.sm}px;\n padding-left: 10px;\n padding-right: 10px;\n line-height: 0;\n font-size: 0;\n\n width: 44px;\n height: 44px;\n`\n\nexport const IconWrapper = styled.span`\n position: absolute;\n top: -12px;\n left: -12px;\n`\n\nexport const LightWrapper = styled(IconWrapper)`\n visibility: var(--lido-color-lightModeVisibility);\n`\n\nexport const DarkWrapper = styled(IconWrapper)`\n visibility: var(--lido-color-darkModeVisibility);\n`\n"],"names":["CookieThemeTogglerStyle","IconWrapper","LightWrapper","DarkWrapper","styled","Button","attrs","variant","size","theme","spaceMap","sm","span"],"mappings":"AAAA;;;;;;;;;;;IAGaA,uBAAuB,MAAvBA,uBAAuB;IAevBC,WAAW,MAAXA,WAAW;IAMXC,YAAY,MAAZA,YAAY;IAIZC,WAAW,MAAXA,WAAW;;;uEA5BL,mBAAmB;wBACf,wBAAqB;AAErC,MAAMH,uBAAuB,GAAGI,IAAAA,iBAAM,QAAA,EAACC,OAAM,OAAA,CAAC,CAACC,KAAK,CAAC;IAC1DC,OAAO,EAAE,MAAM;IACfC,IAAI,EAAE,IAAI;CACX,CAAC,CAAC;;eAEY,EAAE,SAAeC;QAAd,EAAEA,KAAK,CAAA,EAAE;WAAKA,KAAK,CAACC,QAAQ,CAACC,EAAE;AAAD,CAAC,CAAC;;;;;;;;AAQlD,CAAC;AAEM,MAAMV,WAAW,GAAGG,iBAAM,QAAA,CAACQ,IAAI,CAAC;;;;AAIvC,CAAC;AAEM,MAAMV,YAAY,GAAGE,IAAAA,iBAAM,QAAA,EAACH,WAAW,CAAC,CAAC;;AAEhD,CAAC;AAEM,MAAME,WAAW,GAAGC,IAAAA,iBAAM,QAAA,EAACH,WAAW,CAAC,CAAC;;AAE/C,CAAC"}
|
|
@@ -14,7 +14,7 @@ const useSystemTheme = ()=>{
|
|
|
14
14
|
const mql = window.matchMedia('(prefers-color-scheme: dark)');
|
|
15
15
|
const setThemeFromQuery = (param)=>{
|
|
16
16
|
let { matches } = param;
|
|
17
|
-
setSystemTheme(matches ? _theme.
|
|
17
|
+
setSystemTheme(matches ? _theme.ThemeName.dark : _theme.ThemeName.light);
|
|
18
18
|
};
|
|
19
19
|
mql.addEventListener('change', setThemeFromQuery);
|
|
20
20
|
setThemeFromQuery(mql);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../packages/hooks/src/useSystemTheme.ts"],"sourcesContent":["import { useEffect, useState } from 'react'\n\nimport {
|
|
1
|
+
{"version":3,"sources":["../../../../packages/hooks/src/useSystemTheme.ts"],"sourcesContent":["import { useEffect, useState } from 'react'\n\nimport { ThemeName } from '@lidofinance/theme'\n\nexport const useSystemTheme = (): ThemeName | undefined => {\n const [systemTheme, setSystemTheme] = useState<ThemeName>()\n\n useEffect(() => {\n const mql = window.matchMedia('(prefers-color-scheme: dark)')\n\n const setThemeFromQuery = ({ matches }: { matches: boolean }) => {\n setSystemTheme(matches ? ThemeName.dark : ThemeName.light)\n }\n\n mql.addEventListener('change', setThemeFromQuery)\n setThemeFromQuery(mql)\n\n return () => {\n mql.removeEventListener('change', setThemeFromQuery)\n }\n }, [])\n\n return systemTheme\n}\n"],"names":["useSystemTheme","systemTheme","setSystemTheme","useState","useEffect","mql","window","matchMedia","setThemeFromQuery","matches","ThemeName","dark","light","addEventListener","removeEventListener"],"mappings":"AAAA;;;;+BAIaA,gBAAc;;aAAdA,cAAc;;uBAJS,OAAO;uBAEjB,uBAAoB;AAEvC,MAAMA,cAAc,GAAG,IAA6B;IACzD,MAAM,CAACC,WAAW,EAAEC,cAAc,CAAC,GAAGC,IAAAA,MAAQ,SAAA,GAAa;IAE3DC,IAAAA,MAAS,UAAA,EAAC,IAAM;QACd,MAAMC,GAAG,GAAGC,MAAM,CAACC,UAAU,CAAC,8BAA8B,CAAC;QAE7D,MAAMC,iBAAiB,GAAG,SAAuC;gBAAtC,EAAEC,OAAO,CAAA,EAAwB;YAC1DP,cAAc,CAACO,OAAO,GAAGC,MAAS,UAAA,CAACC,IAAI,GAAGD,MAAS,UAAA,CAACE,KAAK,CAAC;QAC5D,CAAC;QAEDP,GAAG,CAACQ,gBAAgB,CAAC,QAAQ,EAAEL,iBAAiB,CAAC;QACjDA,iBAAiB,CAACH,GAAG,CAAC;QAEtB,OAAO,IAAM;YACXA,GAAG,CAACS,mBAAmB,CAAC,QAAQ,EAAEN,iBAAiB,CAAC;QACtD,CAAC,CAAA;IACH,CAAC,EAAE,EAAE,CAAC;IAEN,OAAOP,WAAW,CAAA;AACpB,CAAC"}
|
|
@@ -21,8 +21,8 @@ const translation = (0, _styledComponents.keyframes)`
|
|
|
21
21
|
`;
|
|
22
22
|
const InlineLoaderStyle = _styledComponents.default.span`
|
|
23
23
|
--loader-color: ${(param)=>{
|
|
24
|
-
let {
|
|
25
|
-
return $color ?
|
|
24
|
+
let { $color } = param;
|
|
25
|
+
return $color ? `var(--lido-color-${$color})` : 'currentColor';
|
|
26
26
|
}};
|
|
27
27
|
|
|
28
28
|
width: 100%;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../packages/loaders/src/InlineLoaderStyles.tsx"],"sourcesContent":["import styled, { keyframes } from 'styled-components'\nimport { InlineLoaderColors } from './types'\n\nexport const translation = keyframes`\n 100% {\n background-position: 0 0;\n }\n`\n\nexport const InlineLoaderStyle = styled.span<{ $color?: InlineLoaderColors }>`\n --loader-color: ${({
|
|
1
|
+
{"version":3,"sources":["../../../../packages/loaders/src/InlineLoaderStyles.tsx"],"sourcesContent":["import styled, { keyframes } from 'styled-components'\nimport { InlineLoaderColors } from './types'\n\nexport const translation = keyframes`\n 100% {\n background-position: 0 0;\n }\n`\n\nexport const InlineLoaderStyle = styled.span<{ $color?: InlineLoaderColors }>`\n --loader-color: ${({ $color }) =>\n $color ? `var(--lido-color-${$color})` : 'currentColor'};\n\n width: 100%;\n display: inline-block;\n vertical-align: top;\n border-radius: 1000px;\n position: relative;\n overflow: hidden;\n user-select: none;\n opacity: 0.05;\n animation: ${translation} 2s infinite;\n background-size: 300% 100%;\n background-position: 100% 0;\n background-image: linear-gradient(\n 90deg,\n var(--loader-color) 0,\n var(--loader-color) 33.33%,\n transparent 44.44%,\n transparent 55.55%,\n var(--loader-color) 66.66%,\n var(--loader-color) 100%\n );\n\n &:after {\n content: '';\n position: absolute;\n top: 0;\n right: 0;\n bottom: 0;\n left: 0;\n background: var(--loader-color);\n opacity: 0.2;\n }\n`\n"],"names":["translation","InlineLoaderStyle","keyframes","styled","span","$color"],"mappings":"AAAA;;;;;;;;;;;IAGaA,WAAW,MAAXA,WAAW;IAMXC,iBAAiB,MAAjBA,iBAAiB;;;wEATI,mBAAmB;AAG9C,MAAMD,WAAW,GAAGE,IAAAA,iBAAS,UAAA,CAAA,CAAC;;;;AAIrC,CAAC;AAEM,MAAMD,iBAAiB,GAAGE,iBAAM,QAAA,CAACC,IAAI,AAAiC,CAAC;kBAC5D,EAAE,SAChBC;QADiB,EAAEA,MAAM,CAAA,EAAE;WAC3BA,MAAM,GAAG,CAAC,iBAAiB,EAAEA,MAAM,CAAC,CAAC,CAAC,GAAG,cAAc;AAAD,CAAC,CAAC;;;;;;;;;;aAU/C,EAAEL,WAAW,CAAC;;;;;;;;;;;;;;;;;;;;;;;AAuB3B,CAAC"}
|
|
@@ -28,8 +28,8 @@ const LoaderStyle = _styledComponents.default.div`
|
|
|
28
28
|
width: ${(props)=>props.$size}px;
|
|
29
29
|
height: ${(props)=>props.$size}px;
|
|
30
30
|
color: ${(param)=>{
|
|
31
|
-
let {
|
|
32
|
-
return
|
|
31
|
+
let { $color } = param;
|
|
32
|
+
return `var(--lido-color-${$color})`;
|
|
33
33
|
}};
|
|
34
34
|
`;
|
|
35
35
|
const LoaderCircleBgStyle = _styledComponents.default.circle`
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../packages/loaders/src/LoaderStyles.tsx"],"sourcesContent":["import styled, { keyframes } from 'styled-components'\nimport { LoaderColors } from './types'\n\nexport const rotation = keyframes`\n 100% {\n transform: rotate(360deg);\n }\n`\n\nexport const LoaderStyle = styled.div<{\n $size: number\n $color: LoaderColors\n}>`\n margin: 0;\n padding: 0;\n line-height: 0;\n width: ${(props) => props.$size}px;\n height: ${(props) => props.$size}px;\n color: ${({
|
|
1
|
+
{"version":3,"sources":["../../../../packages/loaders/src/LoaderStyles.tsx"],"sourcesContent":["import styled, { keyframes } from 'styled-components'\nimport { LoaderColors } from './types'\n\nexport const rotation = keyframes`\n 100% {\n transform: rotate(360deg);\n }\n`\n\nexport const LoaderStyle = styled.div<{\n $size: number\n $color: LoaderColors\n}>`\n margin: 0;\n padding: 0;\n line-height: 0;\n width: ${(props) => props.$size}px;\n height: ${(props) => props.$size}px;\n color: ${({ $color }) => `var(--lido-color-${$color})`};\n`\n\nexport const LoaderCircleBgStyle = styled.circle<{ $thickness: number }>`\n fill: none;\n stroke: currentColor;\n stroke-width: ${(props) => props.$thickness};\n opacity: 0.2;\n`\n\nexport const LoaderCircleFgStyle = styled.circle<{\n $thickness: number\n r: number\n}>`\n fill: none;\n stroke: currentColor;\n stroke-linecap: round;\n stroke-width: ${(props) => props.$thickness};\n stroke-dasharray: ${(props) => {\n const circumference = 2 * props.r * Math.PI\n const filledPart = 0.25\n\n return `${circumference * filledPart} ${circumference * (1 - filledPart)}`\n }};\n transform: rotate(0deg);\n transform-origin: 50% 50%;\n animation: ${rotation} 1.4s linear infinite;\n`\n"],"names":["rotation","LoaderStyle","LoaderCircleBgStyle","LoaderCircleFgStyle","keyframes","styled","div","props","$size","$color","circle","$thickness","circumference","r","Math","PI","filledPart"],"mappings":"AAAA;;;;;;;;;;;IAGaA,QAAQ,MAARA,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ryHover: '#009bf2',\n primaryContrast: '#fff',\n primaryVisited: '#4bbeff',\n\n accent: '#27272e',\n accentContrast: '#fff',\n accentContrastSecondary: 'rgba(255, 255, 255, 0.6)',\n accentDarken: 'rgba(0, 0, 0, .2)',\n accentControlBg: 'rgba(0, 0, 0, .1)',\n accentBorder: 'rgba(255, 255, 255, 0.2)',\n accentBorderHover: 'rgba(255, 255, 255, 0.3)',\n\n error: '#e14d4d',\n errorHover: '#d44c4d',\n errorContrast: '#fff',\n\n warning: '#EC8600',\n warningHover: '#f0a431',\n warningContrast: '#fff',\n\n success: '#53BA95',\n successHover: '#5dae5e',\n successContrast: '#fff',\n} as const\n\nexport default { colors }\n"],"names":["colors","primary","primaryHover","primaryContrast","primaryVisited","accent","accentContrast","accentContrastSecondary","accentDarken","accentControlBg","accentBorder","accentBorderHover","error","errorHover","errorContrast","warning","warningHover","warningContrast","success","successHover","successContrast"],"mappings":"AAAA;;;;+
|
|
1
|
+
{"version":3,"sources":["../../../../../packages/theme/src/base/colors.ts"],"sourcesContent":["const colors = {\n darkThemeOpacity: '0',\n lightThemeOpacity: '1',\n primary: '#00a3ff',\n primaryHover: '#009bf2',\n primaryContrast: '#fff',\n primaryVisited: '#4bbeff',\n\n accent: '#27272e',\n accentContrast: '#fff',\n accentContrastSecondary: 'rgba(255, 255, 255, 0.6)',\n accentDarken: 'rgba(0, 0, 0, .2)',\n accentControlBg: 'rgba(0, 0, 0, .1)',\n accentBorder: 'rgba(255, 255, 255, 0.2)',\n accentBorderHover: 'rgba(255, 255, 255, 0.3)',\n\n error: '#e14d4d',\n errorHover: '#d44c4d',\n errorContrast: '#fff',\n\n warning: '#EC8600',\n warningHover: '#f0a431',\n warningContrast: '#fff',\n\n success: '#53BA95',\n successHover: '#5dae5e',\n successContrast: '#fff',\n} as const\n\nexport default { colors }\n"],"names":["colors","darkThemeOpacity","lightThemeOpacity","primary","primaryHover","primaryContrast","primaryVisited","accent","accentContrast","accentContrastSecondary","accentDarken","accentControlBg","accentBorder","accentBorderHover","error","errorHover","errorContrast","warning","warningHover","warningContrast","success","successHover","successContrast"],"mappings":"AAAA;;;;+BA6BA,SAAyB;;aAAzB,QAAyB;;AA7BzB,MAAMA,MAAM,GAAG;IACbC,gBAAgB,EAAE,GAAG;IACrBC,iBAAiB,EAAE,GAAG;IACtBC,OAAO,EAAE,SAAS;IAClBC,YAAY,EAAE,SAAS;IACvBC,eAAe,EAAE,MAAM;IACvBC,cAAc,EAAE,SAAS;IAEzBC,MAAM,EAAE,SAAS;IACjBC,cAAc,EAAE,MAAM;IACtBC,uBAAuB,EAAE,0BAA0B;IACnDC,YAAY,EAAE,mBAAmB;IACjCC,eAAe,EAAE,mBAAmB;IACpCC,YAAY,EAAE,0BAA0B;IACxCC,iBAAiB,EAAE,0BAA0B;IAE7CC,KAAK,EAAE,SAAS;IAChBC,UAAU,EAAE,SAAS;IACrBC,aAAa,EAAE,MAAM;IAErBC,OAAO,EAAE,SAAS;IAClBC,YAAY,EAAE,SAAS;IACvBC,eAAe,EAAE,MAAM;IAEvBC,OAAO,EAAE,SAAS;IAClBC,YAAY,EAAE,SAAS;IACvBC,eAAe,EAAE,MAAM;CACxB,AAAS;MAEV,QAAyB,GAAV;IAAEtB,MAAM;CAAE"}
|
|
@@ -9,18 +9,23 @@ function _export(target, all) {
|
|
|
9
9
|
});
|
|
10
10
|
}
|
|
11
11
|
_export(exports, {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
12
|
+
ThemeName: ()=>ThemeName,
|
|
13
|
+
DEFAULT_THEME_NAME: ()=>DEFAULT_THEME_NAME,
|
|
14
|
+
themeCookieKey: ()=>themeCookieKey,
|
|
15
|
+
globalStyleDataAttribute: ()=>globalStyleDataAttribute,
|
|
16
|
+
themeCookieExpire: ()=>themeCookieExpire,
|
|
17
|
+
prefersDarkThemeMediaQuery: ()=>prefersDarkThemeMediaQuery
|
|
16
18
|
});
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
const
|
|
19
|
+
var ref;
|
|
20
|
+
var ThemeName;
|
|
21
|
+
(function(ThemeName) {
|
|
22
|
+
ThemeName["light"] = "light";
|
|
23
|
+
ThemeName["dark"] = "dark";
|
|
24
|
+
})(ThemeName || (ThemeName = {}));
|
|
25
|
+
const DEFAULT_THEME_NAME = ThemeName.light;
|
|
26
|
+
const themeCookieKey = 'lido-theme-manual';
|
|
27
|
+
const globalStyleDataAttribute = 'data-lido-ui-global-style';
|
|
28
|
+
const themeCookieExpire = 365;
|
|
29
|
+
const prefersDarkThemeMediaQuery = window === null || window === void 0 ? void 0 : (ref = window.matchMedia) === null || ref === void 0 ? void 0 : ref.call(window, '(prefers-color-scheme: dark)');
|
|
25
30
|
|
|
26
31
|
//# sourceMappingURL=constants.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../packages/theme/src/constants.ts"],"sourcesContent":["export
|
|
1
|
+
{"version":3,"sources":["../../../../packages/theme/src/constants.ts"],"sourcesContent":["export enum ThemeName {\n light = 'light',\n dark = 'dark',\n}\n\nexport const DEFAULT_THEME_NAME = ThemeName.light\n\nexport const themeCookieKey = 'lido-theme-manual'\nexport const globalStyleDataAttribute = 'data-lido-ui-global-style'\n\nexport const themeCookieExpire = 365\n\nexport const prefersDarkThemeMediaQuery = window?.matchMedia?.(\n '(prefers-color-scheme: dark)'\n)\n"],"names":["DEFAULT_THEME_NAME","themeCookieKey","globalStyleDataAttribute","themeCookieExpire","prefersDarkThemeMediaQuery","window","ThemeName","light","dark","matchMedia"],"mappings":"AAAA;;;;;;;;;;;;IAKaA,kBAAkB,MAAlBA,kBAAkB;IAElBC,cAAc,MAAdA,cAAc;IACdC,wBAAwB,MAAxBA,wBAAwB;IAExBC,iBAAiB,MAAjBA,iBAAiB;IAEjBC,0BAA0B,MAA1BA,0BAA0B;;IAAGC,GAAkB;IAZrD,SAGN;UAHWC,SAAS;IAATA,SAAS,CACnBC,OAAK,IAALA,OAAK;IADKD,SAAS,CAEnBE,MAAI,IAAJA,MAAI;GAFMF,SAAS,KAATA,SAAS;AAKd,MAAMN,kBAAkB,GAAGM,SAAS,CAACC,KAAK;AAE1C,MAAMN,cAAc,GAAG,mBAAmB;AAC1C,MAAMC,wBAAwB,GAAG,2BAA2B;AAE5D,MAAMC,iBAAiB,GAAG,GAAG;AAE7B,MAAMC,0BAA0B,GAAGC,MAAM,aAANA,MAAM,WAAY,GAAlBA,KAAAA,CAAkB,GAAlBA,CAAAA,GAAkB,GAAlBA,MAAM,CAAEI,UAAU,cAAlBJ,GAAkB,WAE3D,GAFyCA,KAAAA,CAEzC,GAFyCA,GAAkB,CAAlBA,IAEzC,CAFyCA,MAAM,EAC9C,8BAA8B,CAC/B"}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
function _export(target, all) {
|
|
6
|
+
for(var name in all)Object.defineProperty(target, name, {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: all[name]
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
_export(exports, {
|
|
12
|
+
ThemeToggleContext: ()=>ThemeToggleContext,
|
|
13
|
+
CookieThemeProvider: ()=>CookieThemeProvider
|
|
14
|
+
});
|
|
15
|
+
const _interopRequireWildcard = require("@swc/helpers/lib/_interop_require_wildcard.js").default;
|
|
16
|
+
const _react = /*#__PURE__*/ _interopRequireWildcard(require("react"));
|
|
17
|
+
const _constants = require("./constants");
|
|
18
|
+
const _themes = require("./themes");
|
|
19
|
+
const _cookies = require("./utils/cookies");
|
|
20
|
+
const _documentHeadContents = require("./document-head-contents/index");
|
|
21
|
+
const _elementThemeScript = require("./document-head-contents/element-theme-script");
|
|
22
|
+
const _styledComponents = require("styled-components");
|
|
23
|
+
const defaultThemeContext = {};
|
|
24
|
+
const ThemeToggleContext = /*#__PURE__*/ (0, _react.createContext)(defaultThemeContext);
|
|
25
|
+
// we need to initialize this before react component code if we're using this provider or ThemeProvider
|
|
26
|
+
(0, _documentHeadContents.initColors)();
|
|
27
|
+
const CookieThemeProvider = /*#__PURE__*/ _react.default.memo((param)=>{
|
|
28
|
+
let { children , initialThemeName , // overrideThemeName is mainly used for storybook
|
|
29
|
+
overrideThemeName , } = param;
|
|
30
|
+
const parentTheme = (0, _react.useContext)(ThemeToggleContext);
|
|
31
|
+
// we do not want to do nested injections, and we're checking
|
|
32
|
+
// if context we inject in this component is already provided
|
|
33
|
+
const isTopLevelProvider = parentTheme === defaultThemeContext;
|
|
34
|
+
// we always start with default theme, or, if server wants to provide
|
|
35
|
+
// specific default theme, with server-provided theme to avoid hydration errors
|
|
36
|
+
const [internalThemeName, setThemeName] = (0, _react.useState)(initialThemeName || _constants.DEFAULT_THEME_NAME);
|
|
37
|
+
// since we're using this component to provide cookie-theme,
|
|
38
|
+
// we eventually want to respect theme provided in cookie, not general theme,
|
|
39
|
+
// so we're picking `parentTheme.themeName` if we have one.
|
|
40
|
+
// If user needs custom theme, not "cookie theme", he should use ThemeProvider instead.
|
|
41
|
+
const themeName = parentTheme.themeName || internalThemeName;
|
|
42
|
+
const theme = _themes.themeMap[themeName];
|
|
43
|
+
// This logic is really hydrating everything, since we started with server-rendered default prop.
|
|
44
|
+
// It also follows cookie value change.
|
|
45
|
+
(0, _react.useEffect)(()=>{
|
|
46
|
+
// This logic is useless if we're nested - it is already done in top-level provider
|
|
47
|
+
if (!isTopLevelProvider) {
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
const setTheme = ()=>{
|
|
51
|
+
const systemThemeName = (_constants.prefersDarkThemeMediaQuery === null || _constants.prefersDarkThemeMediaQuery === void 0 ? void 0 : _constants.prefersDarkThemeMediaQuery.matches) ? _constants.ThemeName.dark : _constants.ThemeName.light;
|
|
52
|
+
const themeNameCookie = (0, _cookies.getThemeNameFromCookies)();
|
|
53
|
+
const newThemeName = // first, if we have some override (e.g. in Storybook), we respect it
|
|
54
|
+
overrideThemeName || // then, if we have cookie theme, we use theme from cookie
|
|
55
|
+
themeNameCookie || // else, we follow theme we were provided in initialization from server,
|
|
56
|
+
// which means server explicitly wants specific theme by default, not "follow-system"
|
|
57
|
+
initialThemeName || // then, we use media query theme, if available (not all browsers may still support it)
|
|
58
|
+
systemThemeName || // and, finally, falling back to default
|
|
59
|
+
_constants.DEFAULT_THEME_NAME;
|
|
60
|
+
setThemeName(newThemeName);
|
|
61
|
+
// and when theme is switched, we're setting global-level CSS variable data-attribute
|
|
62
|
+
// to modify CSS vars provided on a top-level
|
|
63
|
+
document.documentElement.dataset.lidoTheme = newThemeName;
|
|
64
|
+
};
|
|
65
|
+
// Users may have auto-theme (switching on sunset or schedule or whatever) so we need to listen for this event
|
|
66
|
+
_constants.prefersDarkThemeMediaQuery === null || _constants.prefersDarkThemeMediaQuery === void 0 ? void 0 : _constants.prefersDarkThemeMediaQuery.addEventListener('change', setTheme);
|
|
67
|
+
setTheme();
|
|
68
|
+
}, [
|
|
69
|
+
initialThemeName,
|
|
70
|
+
isTopLevelProvider,
|
|
71
|
+
overrideThemeName,
|
|
72
|
+
parentTheme,
|
|
73
|
+
theme,
|
|
74
|
+
]);
|
|
75
|
+
const value = (0, _react.useMemo)(()=>({
|
|
76
|
+
themeName,
|
|
77
|
+
toggleTheme () {
|
|
78
|
+
setThemeName((themeName)=>{
|
|
79
|
+
const newThemeName = themeName === _constants.ThemeName.light ? _constants.ThemeName.dark : _constants.ThemeName.light;
|
|
80
|
+
// note that we're writing cookie theme only on explicit calls,
|
|
81
|
+
// not on "internal theme state" change
|
|
82
|
+
(0, _elementThemeScript.updateGlobalTheme)(newThemeName);
|
|
83
|
+
return newThemeName;
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
}), [
|
|
87
|
+
themeName
|
|
88
|
+
]);
|
|
89
|
+
if (isTopLevelProvider) {
|
|
90
|
+
// if this provider is top-level we rely on element-theme-script.tsx logic
|
|
91
|
+
// which defines data-lido-theme injection
|
|
92
|
+
return /*#__PURE__*/ _react.default.createElement(ThemeToggleContext.Provider, {
|
|
93
|
+
value: value
|
|
94
|
+
}, /*#__PURE__*/ _react.default.createElement(_styledComponents.ThemeProvider, {
|
|
95
|
+
theme: theme
|
|
96
|
+
}, children));
|
|
97
|
+
} else {
|
|
98
|
+
return /*#__PURE__*/ _react.default.createElement("div", {
|
|
99
|
+
style: {
|
|
100
|
+
display: 'contents'
|
|
101
|
+
},
|
|
102
|
+
"data-lido-theme": themeName
|
|
103
|
+
}, /*#__PURE__*/ _react.default.createElement(_styledComponents.ThemeProvider, {
|
|
104
|
+
theme: theme
|
|
105
|
+
}, children));
|
|
106
|
+
}
|
|
107
|
+
});
|
|
108
|
+
CookieThemeProvider.displayName = 'CookieThemeProvider';
|
|
109
|
+
|
|
110
|
+
//# sourceMappingURL=cookie-theme-provider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../packages/theme/src/cookie-theme-provider.tsx"],"sourcesContent":["import React, {\n createContext,\n FC,\n PropsWithChildren,\n useContext,\n useEffect,\n useMemo,\n useState,\n} from 'react'\nimport {\n DEFAULT_THEME_NAME,\n prefersDarkThemeMediaQuery,\n ThemeName,\n} from './constants'\nimport { themeMap } from './themes'\nimport { getThemeNameFromCookies } from './utils/cookies'\nimport { initColors } from './document-head-contents'\nimport { updateGlobalTheme } from './document-head-contents/element-theme-script'\nimport { ThemeProvider as StyledThemeProvider } from 'styled-components'\nimport { ThemeContext } from './types'\n\nconst defaultThemeContext = {} as ThemeContext\nexport const ThemeToggleContext =\n createContext<ThemeContext>(defaultThemeContext)\n\n// we need to initialize this before react component code if we're using this provider or ThemeProvider\ninitColors()\n\n/**\n * This is really complicated logic here. Comments will be added on specific lines\n *\n * Cookie theme provider acts differently from common theme provider.\n * 1. it can be nested, BUT it should re-use value provided by itself for optimisation purposes\n * 2. if it is top-level, it is not altering itself, but instead altering theme behavior on HTMLElement level\n * 3. it does not support custom themes, preferring pre-defined themes instead\n * */\n\nexport const CookieThemeProvider: FC<\n PropsWithChildren<{\n // Use themeNameParent if you need get cookie in SSR\n initialThemeName?: ThemeName\n overrideThemeName?: ThemeName\n }>\n> = React.memo(\n ({\n children,\n initialThemeName,\n // overrideThemeName is mainly used for storybook\n overrideThemeName,\n }) => {\n const parentTheme = useContext(ThemeToggleContext)\n // we do not want to do nested injections, and we're checking\n // if context we inject in this component is already provided\n const isTopLevelProvider = parentTheme === defaultThemeContext\n // we always start with default theme, or, if server wants to provide\n // specific default theme, with server-provided theme to avoid hydration errors\n const [internalThemeName, setThemeName] = useState<ThemeName>(\n initialThemeName || DEFAULT_THEME_NAME\n )\n // since we're using this component to provide cookie-theme,\n // we eventually want to respect theme provided in cookie, not general theme,\n // so we're picking `parentTheme.themeName` if we have one.\n // If user needs custom theme, not \"cookie theme\", he should use ThemeProvider instead.\n const themeName = parentTheme.themeName || internalThemeName\n\n const theme = themeMap[themeName]\n\n // This logic is really hydrating everything, since we started with server-rendered default prop.\n // It also follows cookie value change.\n useEffect(() => {\n // This logic is useless if we're nested - it is already done in top-level provider\n if (!isTopLevelProvider) {\n return\n }\n\n const setTheme = () => {\n const systemThemeName = prefersDarkThemeMediaQuery?.matches\n ? ThemeName.dark\n : ThemeName.light\n const themeNameCookie = getThemeNameFromCookies()\n const newThemeName =\n // first, if we have some override (e.g. in Storybook), we respect it\n overrideThemeName ||\n // then, if we have cookie theme, we use theme from cookie\n themeNameCookie ||\n // else, we follow theme we were provided in initialization from server,\n // which means server explicitly wants specific theme by default, not \"follow-system\"\n initialThemeName ||\n // then, we use media query theme, if available (not all browsers may still support it)\n systemThemeName ||\n // and, finally, falling back to default\n DEFAULT_THEME_NAME\n setThemeName(newThemeName)\n // and when theme is switched, we're setting global-level CSS variable data-attribute\n // to modify CSS vars provided on a top-level\n document.documentElement.dataset.lidoTheme = newThemeName\n }\n\n // Users may have auto-theme (switching on sunset or schedule or whatever) so we need to listen for this event\n prefersDarkThemeMediaQuery?.addEventListener('change', setTheme)\n setTheme()\n }, [\n initialThemeName,\n isTopLevelProvider,\n overrideThemeName,\n parentTheme,\n theme,\n ])\n\n const value = useMemo(\n () => ({\n themeName,\n toggleTheme() {\n setThemeName((themeName) => {\n const newThemeName =\n themeName === ThemeName.light ? ThemeName.dark : ThemeName.light\n // note that we're writing cookie theme only on explicit calls,\n // not on \"internal theme state\" change\n updateGlobalTheme(newThemeName)\n return newThemeName\n })\n },\n }),\n [themeName]\n )\n\n if (isTopLevelProvider) {\n // if this provider is top-level we rely on element-theme-script.tsx logic\n // which defines data-lido-theme injection\n return (\n <ThemeToggleContext.Provider value={value}>\n <StyledThemeProvider theme={theme}>{children}</StyledThemeProvider>\n </ThemeToggleContext.Provider>\n )\n } else {\n return (\n <div style={{ display: 'contents' }} data-lido-theme={themeName}>\n <StyledThemeProvider theme={theme}>{children}</StyledThemeProvider>\n </div>\n )\n }\n }\n)\n\nCookieThemeProvider.displayName = 'CookieThemeProvider'\n"],"names":["ThemeToggleContext","CookieThemeProvider","defaultThemeContext","createContext","initColors","React","memo","children","initialThemeName","overrideThemeName","parentTheme","useContext","isTopLevelProvider","internalThemeName","setThemeName","useState","DEFAULT_THEME_NAME","themeName","theme","themeMap","useEffect","setTheme","systemThemeName","prefersDarkThemeMediaQuery","matches","ThemeName","dark","light","themeNameCookie","getThemeNameFromCookies","newThemeName","document","documentElement","dataset","lidoTheme","addEventListener","value","useMemo","toggleTheme","updateGlobalTheme","Provider","StyledThemeProvider","div","style","display","data-lido-theme","displayName"],"mappings":"AAAA;;;;;;;;;;;IAsBaA,kBAAkB,MAAlBA,kBAAkB;IAelBC,mBAAmB,MAAnBA,mBAAmB;;;6DA7BzB,OAAO;2BAKP,aAAa;wBACK,UAAU;yBACK,iBAAiB;sCAC9B,gCAA0B;oCACnB,+CAA+C;kCAC5B,mBAAmB;AAGxE,MAAMC,mBAAmB,GAAG,EAAE,AAAgB;AACvC,MA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,qBACE,6BAACmC,KAAG;YAACC,KAAK,EAAE;gBAAEC,OAAO,EAAE,UAAU;aAAE;YAAEC,iBAAe,EAAE5B,SAAS;yBAC7D,6BAACwB,iBAAmB,cAAA;YAACvB,KAAK,EAAEA,KAAK;WAAGX,QAAQ,CAAuB,CAC/D,CACP;IACH,CAAC;AACH,CAAC,CACF;AAEDN,mBAAmB,CAAC6C,WAAW,GAAG,qBAAqB"}
|
|
@@ -17,40 +17,53 @@ const _extends = require("@swc/helpers/lib/_extends.js").default;
|
|
|
17
17
|
const _interopRequireDefault = require("@swc/helpers/lib/_interop_require_default.js").default;
|
|
18
18
|
const _react = /*#__PURE__*/ _interopRequireDefault(require("react"));
|
|
19
19
|
const _themes = require("../themes");
|
|
20
|
-
const
|
|
21
|
-
const
|
|
22
|
-
const
|
|
20
|
+
const _generateCssColorVariables = require("../utils/generate-css-color-variables");
|
|
21
|
+
const _constants = require("../constants");
|
|
22
|
+
const _utils = require("../../../utils/src/index");
|
|
23
|
+
/**
|
|
24
|
+
* What is happening here:
|
|
25
|
+
* We want to have React dehydrated HTML to be loaded after theme is initialized.
|
|
26
|
+
* That means that we need to have some code executed BEFORE main react components code,
|
|
27
|
+
* before even injected script itself, so we need to provide some CSS and JS in document head
|
|
28
|
+
* to read the theme from cookie and make global CSS follow preferred palette.
|
|
29
|
+
* This file is providing CSS themes that defines custom CSS variables with palette to
|
|
30
|
+
* make HTML document styled even before any code is loaded
|
|
31
|
+
* */ const darkThemeColors = (0, _generateCssColorVariables.generateCssColorVariables)(_themes.themeDark.colors);
|
|
23
32
|
const lightThemeColors = (0, _generateCssColorVariables.generateCssColorVariables)(_themes.themeLight.colors);
|
|
24
|
-
let initGlobalColors =
|
|
33
|
+
let initGlobalColors = _utils.VOID_FN;
|
|
25
34
|
const themeCSSValueString = `
|
|
26
|
-
html, [data-theme='${
|
|
27
|
-
|
|
28
|
-
|
|
35
|
+
html, [data-lido-theme='${_constants.ThemeName.light}'] {
|
|
36
|
+
color-theme: light;
|
|
37
|
+
${lightThemeColors}
|
|
29
38
|
}
|
|
30
39
|
@media (prefers-color-scheme: dark) {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
40
|
+
html:not([data-lido-theme='${_constants.ThemeName.light}']) {
|
|
41
|
+
color-theme: dark;
|
|
42
|
+
${darkThemeColors}
|
|
43
|
+
}
|
|
35
44
|
}
|
|
36
|
-
[data-theme='${
|
|
37
|
-
|
|
38
|
-
|
|
45
|
+
[data-lido-theme='${_constants.ThemeName.dark}'] {
|
|
46
|
+
color-theme: dark;
|
|
47
|
+
${darkThemeColors}
|
|
39
48
|
}`;
|
|
40
49
|
if (typeof window !== 'undefined') {
|
|
41
|
-
if (!document.querySelector(`style[${
|
|
50
|
+
if (!document.querySelector(`style[${_constants.globalStyleDataAttribute}]`)) {
|
|
42
51
|
initGlobalColors = ()=>{
|
|
43
52
|
const style = document.createElement('style');
|
|
44
|
-
style.setAttribute(
|
|
45
|
-
style.
|
|
53
|
+
style.setAttribute(_constants.globalStyleDataAttribute, '');
|
|
54
|
+
style.innerHTML = themeCSSValueString;
|
|
46
55
|
document.head.appendChild(style);
|
|
47
56
|
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
48
|
-
initGlobalColors =
|
|
57
|
+
initGlobalColors = _utils.VOID_FN;
|
|
49
58
|
};
|
|
50
59
|
}
|
|
51
60
|
}
|
|
52
61
|
const StyleThemeColors = ()=>/*#__PURE__*/ _react.default.createElement("style", _extends({}, {
|
|
53
|
-
[
|
|
54
|
-
}
|
|
62
|
+
[_constants.globalStyleDataAttribute]: true
|
|
63
|
+
}, {
|
|
64
|
+
dangerouslySetInnerHTML: {
|
|
65
|
+
__html: themeCSSValueString
|
|
66
|
+
}
|
|
67
|
+
}));
|
|
55
68
|
|
|
56
69
|
//# sourceMappingURL=element-theme-colors.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../packages/theme/src/document-head-contents/element-theme-colors.tsx"],"sourcesContent":["import React from 'react'\nimport { themeDark, themeLight } from '../themes'\nimport { globalStyleDataAttribute, ThemeName
|
|
1
|
+
{"version":3,"sources":["../../../../../packages/theme/src/document-head-contents/element-theme-colors.tsx"],"sourcesContent":["import React from 'react'\nimport { themeDark, themeLight } from '../themes'\nimport { generateCssColorVariables } from '../utils/generate-css-color-variables'\nimport { globalStyleDataAttribute, ThemeName } from '../constants'\nimport { VOID_FN } from '@lidofinance/utils'\n\n/**\n * What is happening here:\n * We want to have React dehydrated HTML to be loaded after theme is initialized.\n * That means that we need to have some code executed BEFORE main react components code,\n * before even injected script itself, so we need to provide some CSS and JS in document head\n * to read the theme from cookie and make global CSS follow preferred palette.\n * This file is providing CSS themes that defines custom CSS variables with palette to\n * make HTML document styled even before any code is loaded\n * */\n\nconst darkThemeColors = generateCssColorVariables(themeDark.colors)\nconst lightThemeColors = generateCssColorVariables(themeLight.colors)\n\nexport let initGlobalColors = VOID_FN\nexport const themeCSSValueString = `\nhtml, [data-lido-theme='${ThemeName.light}'] {\ncolor-theme: light;\n${lightThemeColors}\n}\n@media (prefers-color-scheme: dark) {\nhtml:not([data-lido-theme='${ThemeName.light}']) { \ncolor-theme: dark;\n${darkThemeColors} \n}\n}\n[data-lido-theme='${ThemeName.dark}'] {\ncolor-theme: dark;\n${darkThemeColors}\n}`\n\nif (typeof window !== 'undefined') {\n if (!document.querySelector(`style[${globalStyleDataAttribute}]`)) {\n initGlobalColors = () => {\n const style = document.createElement('style')\n style.setAttribute(globalStyleDataAttribute, '')\n style.innerHTML = themeCSSValueString\n\n document.head.appendChild(style)\n // eslint-disable-next-line @typescript-eslint/no-empty-function\n initGlobalColors = VOID_FN\n }\n }\n}\n\nexport const StyleThemeColors = () => (\n <style\n {...{ [globalStyleDataAttribute]: true }}\n dangerouslySetInnerHTML={{ __html: themeCSSValueString }}\n />\n)\n"],"names":["initGlobalColors","themeCSSValueString","StyleThemeColors","darkThemeColors","generateCssColorVariables","themeDark","colors","lightThemeColors","themeLight","VOID_FN","ThemeName","light","dark","window","document","querySelector","globalStyleDataAttribute","style","createElement","setAttribute","innerHTML","head","appendChild","dangerouslySetInnerHTML","__html"],"mappings":"AAAA;;;;;;;;;;;IAmBWA,gBAAgB,MAAhBA,gBAAgB;IACdC,mBAAmB,MAAnBA,mBAAmB;IA8BnBC,gBAAgB,MAAhBA,gBAAgB;;;;4DAlDX,OAAO;wBACa,WAAW;2CACP,uCAAuC;2BAC7B,cAAc;uBAC1C,0BAAoB;AAE5C;;;;;;;;GAQG,GAEH,MAAMC,eAAe,GAAGC,IAAAA,0BAAyB,0BAAA,EAACC,OAAS,UAAA,CAACC,MAAM,CAAC;AACnE,MAAMC,gBAAgB,GAAGH,IAAAA,0BAAyB,0BAAA,EAACI,OAAU,WAAA,CAACF,MAAM,CAAC;AAE9D,IAAIN,gBAAgB,GAAGS,MAAO,QAAA;AAC9B,MAAMR,mBAAmB,GAAG,CAAC;wBACZ,EAAES,UAAS,UAAA,CAACC,KAAK,CAAC;;AAE1C,EAAEJ,gBAAgB,CAAC;;;2BAGQ,EAAEG,UAAS,UAAA,CAACC,KAAK,CAAC;;AAE7C,EAAER,eAAe,CAAC;;;kBAGA,EAAEO,UAAS,UAAA,CAACE,IAAI,CAAC;;AAEnC,EAAET,eAAe,CAAC;CACjB,CAAC;AAEF,IAAI,OAAOU,MAAM,KAAK,WAAW,EAAE;IACjC,IAAI,CAACC,QAAQ,CAACC,aAAa,CAAC,CAAC,MAAM,EAAEC,UAAwB,yBAAA,CAAC,CAAC,CAAC,CAAC,EAAE;QACjEhB,gBAAgB,GAAG,IAAM;YACvB,MAAMiB,KAAK,GAAGH,QAAQ,CAACI,aAAa,CAAC,OAAO,CAAC;YAC7CD,KAAK,CAACE,YAAY,CAACH,UAAwB,yBAAA,EAAE,EAAE,CAAC;YAChDC,KAAK,CAACG,SAAS,GAAGnB,mBAAmB;YAErCa,QAAQ,CAACO,IAAI,CAACC,WAAW,CAACL,KAAK,CAAC;YAChC,gEAAgE;YAChEjB,gBAAgB,GAAGS,MAAO,QAAA;QAC5B,CAAC;IACH,CAAC;AACH,CAAC;AAEM,MAAMP,gBAAgB,GAAG,kBAC9B,6BAACe,OAAK,eACA;QAAE,CAACD,UAAwB,yBAAA,CAAC,EAAE,IAAI;KAAE;QACxCO,uBAAuB,EAAE;YAAEC,MAAM,EAAEvB,mBAAmB;SAAE;OACxD,AACH"}
|
|
@@ -9,18 +9,25 @@ function _export(target, all) {
|
|
|
9
9
|
});
|
|
10
10
|
}
|
|
11
11
|
_export(exports, {
|
|
12
|
-
themeScriptValue: ()=>themeScriptValue,
|
|
13
12
|
updateGlobalTheme: ()=>updateGlobalTheme,
|
|
14
13
|
initGlobalCookieTheme: ()=>initGlobalCookieTheme,
|
|
15
14
|
ScriptThemeValue: ()=>ScriptThemeValue
|
|
16
15
|
});
|
|
17
16
|
const _interopRequireDefault = require("@swc/helpers/lib/_interop_require_default.js").default;
|
|
18
17
|
const _react = /*#__PURE__*/ _interopRequireDefault(require("react"));
|
|
19
|
-
const _globals = require("../globals");
|
|
20
|
-
const _constants = require("../../../cookie-theme-toggler/src/constants");
|
|
21
18
|
const _utils = require("../../../utils/src/index");
|
|
19
|
+
const _constants = require("../constants");
|
|
22
20
|
/**
|
|
21
|
+
* What is happening here:
|
|
22
|
+
* We want to have React dehydrated HTML to be loaded after theme is initialized.
|
|
23
|
+
* That means that we need to have some code executed BEFORE main react components code,
|
|
24
|
+
* before even injected script itself, so we need to provide some CSS and JS in document head
|
|
25
|
+
* to read the theme from cookie and make global CSS follow preferred palette.
|
|
26
|
+
* This file is providing JS code that reads/writes cookie value, including <script> element to inject
|
|
27
|
+
* */ /**
|
|
23
28
|
* this FN should be hermetic and has zero external items - it is inlined via .toString()
|
|
29
|
+
* __PURE__ annotation may throw an error on some external usage cases
|
|
30
|
+
* (with chances, but it is better than nothing)
|
|
24
31
|
* */ /*#__PURE__*/ const themeScriptValueString = function(key) {
|
|
25
32
|
if (!window.matchMedia) {
|
|
26
33
|
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
@@ -28,28 +35,34 @@ const _utils = require("../../../utils/src/index");
|
|
|
28
35
|
}
|
|
29
36
|
const match = window.matchMedia('(prefers-color-scheme: dark)');
|
|
30
37
|
const setTheme = ()=>{
|
|
31
|
-
|
|
38
|
+
var ref;
|
|
39
|
+
const cookieMatcher = new RegExp(`(^| )${key}=([^;]+)`);
|
|
40
|
+
var ref1;
|
|
41
|
+
const themeCookie = (ref1 = (ref = document.cookie.match(cookieMatcher)) === null || ref === void 0 ? void 0 : ref[2]) !== null && ref1 !== void 0 ? ref1 : null;
|
|
32
42
|
if (themeCookie) {
|
|
33
|
-
document.documentElement.dataset.
|
|
43
|
+
document.documentElement.dataset.lidoTheme = themeCookie.split('=')[1];
|
|
34
44
|
} else {
|
|
35
|
-
delete document.documentElement.dataset.
|
|
45
|
+
delete document.documentElement.dataset.lidoTheme;
|
|
36
46
|
}
|
|
37
47
|
};
|
|
38
48
|
setTheme();
|
|
39
49
|
match.addEventListener('change', setTheme);
|
|
40
50
|
return setTheme;
|
|
41
51
|
};
|
|
42
|
-
|
|
43
|
-
let
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
initGlobalCookieTheme = _globals.VOID_FN;
|
|
52
|
+
let updateGlobalTheme = _utils.VOID_FN;
|
|
53
|
+
let initGlobalCookieTheme = typeof window === 'undefined' ? _utils.VOID_FN : ()=>{
|
|
54
|
+
const setTheme = themeScriptValueString(_constants.themeCookieKey);
|
|
55
|
+
initGlobalCookieTheme = _utils.VOID_FN;
|
|
47
56
|
const topLevelDomain = (0, _utils.getTopLevelDomain)();
|
|
48
57
|
updateGlobalTheme = (theme)=>{
|
|
49
|
-
document.cookie = `${_constants.
|
|
58
|
+
document.cookie = `${_constants.themeCookieKey}=${theme};expires=${_constants.themeCookieExpire};path=/;domain=${topLevelDomain};samesite=None;secure;`;
|
|
50
59
|
setTheme();
|
|
51
60
|
};
|
|
52
61
|
};
|
|
53
|
-
const ScriptThemeValue = ()=>/*#__PURE__*/ _react.default.createElement("script",
|
|
62
|
+
const ScriptThemeValue = ()=>/*#__PURE__*/ _react.default.createElement("script", {
|
|
63
|
+
dangerouslySetInnerHTML: {
|
|
64
|
+
__html: `(${themeScriptValueString.toString()})("${_constants.themeCookieKey}")`
|
|
65
|
+
}
|
|
66
|
+
});
|
|
54
67
|
|
|
55
68
|
//# sourceMappingURL=element-theme-script.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../packages/theme/src/document-head-contents/element-theme-script.tsx"],"sourcesContent":["import React from 'react'\nimport {
|
|
1
|
+
{"version":3,"sources":["../../../../../packages/theme/src/document-head-contents/element-theme-script.tsx"],"sourcesContent":["import React from 'react'\nimport { getTopLevelDomain, VOID_FN } from '@lidofinance/utils'\nimport { themeCookieExpire, themeCookieKey, ThemeName } from '../constants'\n\n/**\n * What is happening here:\n * We want to have React dehydrated HTML to be loaded after theme is initialized.\n * That means that we need to have some code executed BEFORE main react components code,\n * before even injected script itself, so we need to provide some CSS and JS in document head\n * to read the theme from cookie and make global CSS follow preferred palette.\n * This file is providing JS code that reads/writes cookie value, including <script> element to inject\n * */\n\n/**\n * this FN should be hermetic and has zero external items - it is inlined via .toString()\n * __PURE__ annotation may throw an error on some external usage cases\n * (with chances, but it is better than nothing)\n * */\n/*#__PURE__*/\nconst themeScriptValueString = function (key: string) {\n if (!window.matchMedia) {\n // eslint-disable-next-line @typescript-eslint/no-empty-function\n return () => {}\n }\n const match = window.matchMedia('(prefers-color-scheme: dark)')\n const setTheme = () => {\n const cookieMatcher = new RegExp(`(^| )${key}=([^;]+)`)\n const themeCookie =\n (document.cookie.match(cookieMatcher)?.[2] as ThemeName) ?? null\n if (themeCookie) {\n document.documentElement.dataset.lidoTheme = themeCookie.split('=')[1]\n } else {\n delete document.documentElement.dataset.lidoTheme\n }\n }\n setTheme()\n match.addEventListener('change', setTheme)\n return setTheme\n}\n\n// eslint-disable-next-line @typescript-eslint/no-empty-function\nexport let updateGlobalTheme: (theme: string) => void = VOID_FN\n\nexport let initGlobalCookieTheme =\n typeof window === 'undefined'\n ? VOID_FN\n : () => {\n const setTheme = themeScriptValueString(themeCookieKey)\n initGlobalCookieTheme = VOID_FN\n const topLevelDomain = getTopLevelDomain()\n updateGlobalTheme = (theme: ThemeName) => {\n document.cookie = `${themeCookieKey}=${theme};expires=${themeCookieExpire};path=/;domain=${topLevelDomain};samesite=None;secure;`\n setTheme()\n }\n }\n\nexport const ScriptThemeValue = () => (\n <script\n dangerouslySetInnerHTML={{\n __html: `(${themeScriptValueString.toString()})(\"${themeCookieKey}\")`,\n }}\n />\n)\n"],"names":["updateGlobalTheme","initGlobalCookieTheme","ScriptThemeValue","themeScriptValueString","key","window","matchMedia","match","setTheme","document","cookieMatcher","RegExp","themeCookie","cookie","documentElement","dataset","lidoTheme","split","addEventListener","VOID_FN","themeCookieKey","topLevelDomain","getTopLevelDomain","theme","themeCookieExpire","script","dangerouslySetInnerHTML","__html","toString"],"mappings":"AAAA;;;;;;;;;;;IAyCWA,iBAAiB,MAAjBA,iBAAiB;IAEjBC,qBAAqB,MAArBA,qBAAqB;IAanBC,gBAAgB,MAAhBA,gBAAgB;;;4DAxDX,OAAO;uBACkB,0BAAoB;2BACF,cAAc;AAE3E;;;;;;;GAOG,GAEH;;;;GAIG,GACH,WAAW,GACX,MAAMC,sBAAsB,GAAG,SAAUC,GAAW,EAAE;IACpD,IAAI,CAACC,MAAM,CAACC,UAAU,EAAE;QACtB,gEAAgE;QAChE,OAAO,IAAM,CAAC,CAAC,CAAA;IACjB,CAAC;IACD,MAAMC,KAAK,GAAGF,MAAM,CAACC,UAAU,CAAC,8BAA8B,CAAC;IAC/D,MAAME,QAAQ,GAAG,IAAM;YAGlBC,GAAoC;QAFvC,MAAMC,aAAa,GAAG,IAAIC,MAAM,CAAC,CAAC,KAAK,EAAEP,GAAG,CAAC,QAAQ,CAAC,CAAC;YAErD,IAAwD;QAD1D,MAAMQ,WAAW,GACf,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,CAAC,GAAG,EAAER,UAAc,eAAA,CAAC,EAAE,CAAC;SACtE;MACD,AACH"}
|
|
File without changes
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../packages/theme/src/hooks.ts"],"sourcesContent":["import { useContext } from 'react'\nimport { ThemeToggleContext } from './cookie-theme-provider'\nimport { ThemeContext } from './types'\n\nexport const useThemeToggle = (): ThemeContext => {\n return useContext(ThemeToggleContext)\n}\n"],"names":["useThemeToggle","useContext","ThemeToggleContext"],"mappings":"AAAA;;;;+BAIaA,gBAAc;;aAAdA,cAAc;;uBAJA,OAAO;qCACC,yBAAyB;AAGrD,MAAMA,cAAc,GAAG,IAAoB;IAChD,OAAOC,IAAAA,MAAU,WAAA,EAACC,oBAAkB,mBAAA,CAAC,CAAA;AACvC,CAAC"}
|
|
@@ -3,10 +3,12 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
3
3
|
value: true
|
|
4
4
|
});
|
|
5
5
|
const _exportStar = require("@swc/helpers/lib/_export_star.js").default;
|
|
6
|
-
_exportStar(require("./provider"), exports);
|
|
6
|
+
_exportStar(require("./cookie-theme-provider"), exports);
|
|
7
|
+
_exportStar(require("./theme-provider"), exports);
|
|
7
8
|
_exportStar(require("./document-head-contents/index"), exports);
|
|
8
9
|
_exportStar(require("./constants"), exports);
|
|
9
10
|
_exportStar(require("./themes"), exports);
|
|
11
|
+
_exportStar(require("./hooks"), exports);
|
|
10
12
|
_exportStar(require("./types"), exports);
|
|
11
13
|
|
|
12
14
|
//# sourceMappingURL=index.js.map
|