@draftbit/theme 50.6.2-fba047.2 → 50.6.3

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.
Files changed (36) hide show
  1. package/lib/commonjs/Provider.js +1 -1
  2. package/lib/commonjs/createTheme.js +1 -1
  3. package/lib/commonjs/createThemeValuesProxy.js +1 -1
  4. package/lib/commonjs/utils.js +1 -0
  5. package/lib/commonjs/validators.js +1 -1
  6. package/lib/typescript/src/Provider.js +29 -12
  7. package/lib/typescript/src/Provider.js.map +1 -1
  8. package/lib/typescript/src/createTheme.d.ts +1 -13
  9. package/lib/typescript/src/createTheme.js +19 -7
  10. package/lib/typescript/src/createTheme.js.map +1 -1
  11. package/lib/typescript/src/createThemeValuesProxy.d.ts +9 -1
  12. package/lib/typescript/src/createThemeValuesProxy.js +26 -24
  13. package/lib/typescript/src/createThemeValuesProxy.js.map +1 -1
  14. package/lib/typescript/src/utils.d.ts +3 -0
  15. package/lib/typescript/src/utils.js +25 -0
  16. package/lib/typescript/src/utils.js.map +1 -0
  17. package/lib/typescript/src/validators.d.ts +1 -3
  18. package/lib/typescript/src/validators.js +74 -10
  19. package/lib/typescript/src/validators.js.map +1 -1
  20. package/lib/typescript/tsconfig.tsbuildinfo +1 -1
  21. package/package.json +5 -3
  22. package/src/Provider.js +29 -12
  23. package/src/Provider.js.map +1 -1
  24. package/src/Provider.tsx +28 -42
  25. package/src/createTheme.js +19 -7
  26. package/src/createTheme.js.map +1 -1
  27. package/src/createTheme.ts +28 -7
  28. package/src/createThemeValuesProxy.js +26 -24
  29. package/src/createThemeValuesProxy.js.map +1 -1
  30. package/src/createThemeValuesProxy.ts +44 -90
  31. package/src/utils.js +25 -0
  32. package/src/utils.js.map +1 -0
  33. package/src/utils.ts +28 -0
  34. package/src/validators.js +74 -10
  35. package/src/validators.js.map +1 -1
  36. package/src/validators.ts +93 -12
@@ -1 +1 @@
1
- import _asyncToGenerator from"@babel/runtime/helpers/asyncToGenerator";import _slicedToArray from"@babel/runtime/helpers/slicedToArray";var _this=this,_jsxFileName="/home/runner/work/react-native-jigsaw/react-native-jigsaw/packages/theme/src/Provider.tsx";import React from"react";import{Dimensions,Platform,useColorScheme}from"react-native";import AsyncStorage from"@react-native-async-storage/async-storage";import createThemeValuesProxy from"./createThemeValuesProxy";import DefaultTheme from"./DefaultTheme";import{jsx as _jsx}from"react/jsx-runtime";var SAVED_SELECTED_THEME_KEY="saved_selected_theme";var ThemeContext=React.createContext({theme:DefaultTheme,changeTheme:function changeTheme(){}});var Provider=function Provider(_ref){var _themes$find;var themes=_ref.themes,breakpoints=_ref.breakpoints,initialThemeName=_ref.initialThemeName,children=_ref.children;var initialTheme=(_themes$find=themes.find(function(theme){return theme.name===initialThemeName;}))!=null?_themes$find:DefaultTheme;var _React$useState=React.useState(initialTheme),_React$useState2=_slicedToArray(_React$useState,2),currentTheme=_React$useState2[0],setCurrentTheme=_React$useState2[1];var _React$useState3=React.useState(Dimensions.get("window").width),_React$useState4=_slicedToArray(_React$useState3,2),deviceWidth=_React$useState4[0],setDeviceWidth=_React$useState4[1];var colorScheme=useColorScheme();var lightDarkSelection=colorScheme!=null?colorScheme:"light";var changeTheme=React.useCallback(function(themeName,options){var theme=themes.find(function(t){return t.name===themeName;});if(!theme){console.warn("Theme with name",themeName,"not found. Make sure it's passed into the top level ThemeProvider");return;}setCurrentTheme(theme);if((options==null?void 0:options.persistent)===true){AsyncStorage.setItem(SAVED_SELECTED_THEME_KEY,themeName).catch(function(e){console.warn("Failed to persist selected theme",e);});}},[themes,setCurrentTheme]);var proxiedTheme=React.useMemo(function(){return Object.assign({},currentTheme,{colors:{branding:createThemeValuesProxy(currentTheme.colors.branding,breakpoints,deviceWidth,Platform.OS,lightDarkSelection),text:createThemeValuesProxy(currentTheme.colors.text,breakpoints,deviceWidth,Platform.OS,lightDarkSelection),background:createThemeValuesProxy(currentTheme.colors.background,breakpoints,deviceWidth,Platform.OS,lightDarkSelection),foreground:createThemeValuesProxy(currentTheme.colors.foreground,breakpoints,deviceWidth,Platform.OS,lightDarkSelection),border:createThemeValuesProxy(currentTheme.colors.border,breakpoints,deviceWidth,Platform.OS,lightDarkSelection)},typography:currentTheme.typography});},[currentTheme,deviceWidth,breakpoints,lightDarkSelection]);React.useEffect(function(){var listener=Dimensions.addEventListener("change",function(_ref2){var window=_ref2.window;return setDeviceWidth(window.width);});return function(){listener.remove();};});React.useEffect(function(){var run=function(){var _ref3=_asyncToGenerator(function*(){var savedSelectedThemeName=yield AsyncStorage.getItem(SAVED_SELECTED_THEME_KEY);if(savedSelectedThemeName){changeTheme(savedSelectedThemeName);}});return function run(){return _ref3.apply(this,arguments);};}();run();},[]);return _jsx(ThemeContext.Provider,{value:{theme:proxiedTheme,changeTheme:changeTheme},children:children});};var useTheme=function useTheme(){var _React$useContext=React.useContext(ThemeContext),theme=_React$useContext.theme;return theme;};var useChangeTheme=function useChangeTheme(){var _React$useContext2=React.useContext(ThemeContext),changeTheme=_React$useContext2.changeTheme;return changeTheme;};var withTheme=function withTheme(Component){return React.forwardRef(function(props,ref){var _React$useContext3=React.useContext(ThemeContext),theme=_React$useContext3.theme;return _jsx(Component,Object.assign({},props,{theme:theme,ref:ref}));});};export{Provider,useTheme,useChangeTheme,withTheme};
1
+ import _asyncToGenerator from"@babel/runtime/helpers/asyncToGenerator";import _slicedToArray from"@babel/runtime/helpers/slicedToArray";var _this=this,_jsxFileName="/home/runner/work/react-native-jigsaw/react-native-jigsaw/packages/theme/src/Provider.tsx";import React from"react";import{Dimensions,Platform,useColorScheme}from"react-native";import AsyncStorage from"@react-native-async-storage/async-storage";import createThemeValuesProxy from"./createThemeValuesProxy";import DefaultTheme from"./DefaultTheme";import{jsx as _jsx}from"react/jsx-runtime";var SAVED_SELECTED_THEME_KEY="saved_selected_theme";var ThemeContext=React.createContext({theme:DefaultTheme,changeTheme:function changeTheme(){}});var Provider=function Provider(_ref){var _themes$find;var themes=_ref.themes,breakpoints=_ref.breakpoints,initialThemeName=_ref.initialThemeName,children=_ref.children;var initialTheme=(_themes$find=themes.find(function(theme){return theme.name===initialThemeName;}))!=null?_themes$find:DefaultTheme;var _React$useState=React.useState(initialTheme),_React$useState2=_slicedToArray(_React$useState,2),currentTheme=_React$useState2[0],setCurrentTheme=_React$useState2[1];var _React$useState3=React.useState(Dimensions.get("window").width),_React$useState4=_slicedToArray(_React$useState3,2),deviceWidth=_React$useState4[0],setDeviceWidth=_React$useState4[1];var colorScheme=useColorScheme();var lightDarkSelection=colorScheme!=null?colorScheme:"light";var changeTheme=React.useCallback(function(themeName,options){var theme=themes.find(function(t){return t.name===themeName;});if(!theme){console.warn("Theme with name",themeName,"not found. Make sure it's passed into the top level ThemeProvider");return;}setCurrentTheme(theme);if((options==null?void 0:options.persistent)===true){AsyncStorage.setItem(SAVED_SELECTED_THEME_KEY,themeName).catch(function(e){console.warn("Failed to persist selected theme",e);});}},[themes,setCurrentTheme]);var proxiedTheme=React.useMemo(function(){var createProxiedThemeValue=function createProxiedThemeValue(value){return createThemeValuesProxy({value:value,breakpoints:breakpoints,deviceWidth:deviceWidth,devicePlatform:Platform.OS,currentLightDarkSelection:lightDarkSelection});};return Object.assign({},currentTheme,{colors:{branding:createProxiedThemeValue(currentTheme.colors.branding),text:createProxiedThemeValue(currentTheme.colors.text),background:createProxiedThemeValue(currentTheme.colors.background),foreground:createProxiedThemeValue(currentTheme.colors.foreground),border:createProxiedThemeValue(currentTheme.colors.border)},typography:createProxiedThemeValue(currentTheme.typography)});},[currentTheme,deviceWidth,breakpoints,lightDarkSelection]);React.useEffect(function(){var listener=Dimensions.addEventListener("change",function(_ref2){var window=_ref2.window;return setDeviceWidth(window.width);});return function(){listener.remove();};});React.useEffect(function(){var run=function(){var _ref3=_asyncToGenerator(function*(){var savedSelectedThemeName=yield AsyncStorage.getItem(SAVED_SELECTED_THEME_KEY);var themeExists=themes.some(function(t){return t.name===savedSelectedThemeName;});if(savedSelectedThemeName){if(themeExists){changeTheme(savedSelectedThemeName);}else{AsyncStorage.removeItem(SAVED_SELECTED_THEME_KEY).catch(function(e){console.warn("Failed to reset persisted selected theme",e);});}}});return function run(){return _ref3.apply(this,arguments);};}();run();},[]);return _jsx(ThemeContext.Provider,{value:{theme:proxiedTheme,changeTheme:changeTheme},children:children});};var useTheme=function useTheme(){var _React$useContext=React.useContext(ThemeContext),theme=_React$useContext.theme;return theme;};var useChangeTheme=function useChangeTheme(){var _React$useContext2=React.useContext(ThemeContext),changeTheme=_React$useContext2.changeTheme;return changeTheme;};var withTheme=function withTheme(Component){return React.forwardRef(function(props,ref){var _React$useContext3=React.useContext(ThemeContext),theme=_React$useContext3.theme;return _jsx(Component,Object.assign({},props,{theme:theme,ref:ref}));});};export{Provider,useTheme,useChangeTheme,withTheme};
@@ -1 +1 @@
1
- import merge from"deepmerge";export default function createTheme(_ref){var theme=_ref.theme,baseTheme=_ref.baseTheme;var resultTheme=theme;if(baseTheme){resultTheme=merge(baseTheme,theme);}return Object.assign({},resultTheme,{validated:true});}
1
+ import{deepmergeCustom}from"deepmerge-ts";import{validateBreakpoints,validatePalettes,validateTheme}from"./validators";import{isTextStyleObject}from"./utils";var themeMerge=deepmergeCustom({enableImplicitDefaultMerging:true,mergeRecords:function mergeRecords(values,utils,meta){var firstValue=values[0];if(isTextStyleObject(firstValue)){return utils.defaultMergeFunctions.mergeRecords(values.slice(1),utils,meta);}return utils.defaultMergeFunctions.mergeRecords(values,utils,meta);}});export default function createTheme(_ref){var breakpoints=_ref.breakpoints,palettes=_ref.palettes,theme=_ref.theme,baseTheme=_ref.baseTheme;validateBreakpoints(breakpoints);validatePalettes(palettes);validateTheme(theme);var resultTheme=theme;if(baseTheme){validateTheme(baseTheme);resultTheme=themeMerge(baseTheme,theme);}return Object.assign({},resultTheme,{validated:true});}
@@ -1 +1 @@
1
- import _slicedToArray from"@babel/runtime/helpers/slicedToArray";import{isObject}from"lodash";export default function createThemeValuesProxy(value,breakpoints,deviceWidth,devicePlatform,currentLightDarkSelection){if(value===undefined||value===null){return undefined;}return new Proxy(value,{get:function get(target,key){var currentValue=target[key];var valueAsThemeValues=isObject(currentValue)?currentValue:undefined;if(valueAsThemeValues){var platformKeys=["ios","android","web","macos","windows"];var breakpointKeys=Object.keys(breakpoints);var lightDarkKeys=["light","dark"];var keysType=getKeysType(valueAsThemeValues,platformKeys,breakpointKeys,lightDarkKeys);if(keysType==="default"){return createThemeValuesProxy(valueAsThemeValues,breakpoints,deviceWidth,devicePlatform,currentLightDarkSelection);}else if(keysType==="platform"){return getPlatformValue(valueAsThemeValues,breakpoints,deviceWidth,devicePlatform,currentLightDarkSelection);}else if(keysType==="breakpoint"){return getBreakpointValue(valueAsThemeValues,breakpoints,deviceWidth,devicePlatform,currentLightDarkSelection);}else if(keysType==="lightDark"){return getLightDarkValue(valueAsThemeValues,breakpoints,deviceWidth,devicePlatform,currentLightDarkSelection);}else{return undefined;}}else{return currentValue;}},set:function set(){throw new Error("Theme is read only, cannot be modified at runtime");}});}function getKeysType(value,platformKeys,breakpointKeys,lightDarkKeys){var hasPlatformKeys=platformKeys.some(function(key){return value[key]!==undefined;});var hasBreakpointKeys=breakpointKeys.some(function(key){return value[key]!==undefined;});var hasLightDarkKeys=lightDarkKeys.some(function(key){return value[key]!==undefined;});var hasUserDefinedKeys=Object.keys(value).some(function(key){return!platformKeys.includes(key)&&!breakpointKeys.includes(key)&&!lightDarkKeys.includes(key)&&key!=="default";});if(!onlyOneTrue(hasPlatformKeys,hasBreakpointKeys,hasUserDefinedKeys,hasLightDarkKeys)&&!allFalse(hasPlatformKeys,hasBreakpointKeys,hasUserDefinedKeys,hasLightDarkKeys)){throw new Error("Cannot mix usage of platform keys, breakpoint keys, light/dark keys, and custom defined keys on the same level"+`\nKeys: ${Object.keys(value).join(", ")}`);}else if(hasPlatformKeys){return"platform";}else if(hasBreakpointKeys){return"breakpoint";}else if(hasLightDarkKeys){return"lightDark";}else{return"default";}}function onlyOneTrue(a,b,c,d){return[a,b,c,d].filter(function(x){return x;}).length===1;}function allFalse(a,b,c,d){return[a,b,c,d].filter(function(x){return x;}).length===0;}function getPlatformValue(value,breakpoints,deviceWidth,devicePlatform,currentLightDarkSelection){var _value$devicePlatform;var currentPlatformValue=(_value$devicePlatform=value==null?void 0:value[devicePlatform])!=null?_value$devicePlatform:value==null?void 0:value.default;var valueAsThemeValues=isObject(currentPlatformValue)?currentPlatformValue:undefined;if(valueAsThemeValues){return createThemeValuesProxy(valueAsThemeValues,breakpoints,deviceWidth,devicePlatform,currentLightDarkSelection);}else{return currentPlatformValue;}}function getBreakpointValue(value,breakpoints,deviceWidth,devicePlatform,currentLightDarkSelection){var _value$currentBreakpo;var keysToBreakpointValue=Object.keys(value!=null?value:{}).map(function(key){return[key,breakpoints[key]];});var orderedBreakpoints=keysToBreakpointValue.sort(function(_ref){var _ref2=_slicedToArray(_ref,2),_=_ref2[0],val=_ref2[1];return val;});var currentBreakpointKey="";for(var _ref3 of orderedBreakpoints){var _ref4=_slicedToArray(_ref3,2);var breakpointKey=_ref4[0];var breakpointValue=_ref4[1];if(deviceWidth>=breakpointValue){currentBreakpointKey=breakpointKey;}}var currentBreakpointValue=(_value$currentBreakpo=value==null?void 0:value[currentBreakpointKey])!=null?_value$currentBreakpo:value==null?void 0:value.default;var valueAsThemeValues=isObject(currentBreakpointKey)?currentBreakpointKey:undefined;if(valueAsThemeValues){return createThemeValuesProxy(valueAsThemeValues,breakpoints,deviceWidth,devicePlatform,currentLightDarkSelection);}else{return currentBreakpointValue;}}function getLightDarkValue(value,breakpoints,deviceWidth,devicePlatform,currentLightDarkSelection){var _value$currentLightDa;var currentLightDarkValue=(_value$currentLightDa=value==null?void 0:value[currentLightDarkSelection])!=null?_value$currentLightDa:value==null?void 0:value.default;var valueAsThemeValues=isObject(currentLightDarkSelection)?currentLightDarkSelection:undefined;if(valueAsThemeValues){return createThemeValuesProxy(valueAsThemeValues,breakpoints,deviceWidth,devicePlatform,currentLightDarkSelection);}else{return currentLightDarkValue;}}
1
+ import _slicedToArray from"@babel/runtime/helpers/slicedToArray";import{asThemeValuesObject}from"./utils";export default function createThemeValuesProxy(_ref){var value=_ref.value,breakpoints=_ref.breakpoints,deviceWidth=_ref.deviceWidth,devicePlatform=_ref.devicePlatform,currentLightDarkSelection=_ref.currentLightDarkSelection;if(value===undefined||value===null){return undefined;}return new Proxy(value,{get:function get(target,key){var currentValue=target[key];var valueAsThemeValues=asThemeValuesObject(currentValue);if(valueAsThemeValues){var platformKeys=["ios","android","web","macos","windows"];var breakpointKeys=Object.keys(breakpoints);var lightDarkKeys=["light","dark"];var keysType=getKeysType(valueAsThemeValues,platformKeys,breakpointKeys,lightDarkKeys);var input={value:valueAsThemeValues,breakpoints:breakpoints,deviceWidth:deviceWidth,devicePlatform:devicePlatform,currentLightDarkSelection:currentLightDarkSelection};if(keysType==="default"){return createThemeValuesProxy(input);}else if(keysType==="platform"){return getPlatformValue(input);}else if(keysType==="breakpoint"){return getBreakpointValue(input);}else if(keysType==="lightDark"){return getLightDarkValue(input);}else{return undefined;}}else{return currentValue;}},set:function set(){throw new Error("Theme is read only, cannot be modified at runtime");}});}function getKeysType(value,platformKeys,breakpointKeys,lightDarkKeys){var hasPlatformKeys=platformKeys.some(function(key){return value[key]!==undefined;});var hasBreakpointKeys=breakpointKeys.some(function(key){return value[key]!==undefined;});var hasLightDarkKeys=lightDarkKeys.some(function(key){return value[key]!==undefined;});var hasUserDefinedKeys=Object.keys(value).some(function(key){return!platformKeys.includes(key)&&!breakpointKeys.includes(key)&&!lightDarkKeys.includes(key)&&key!=="default";});if(!onlyOneTrue(hasPlatformKeys,hasBreakpointKeys,hasUserDefinedKeys,hasLightDarkKeys)&&!allFalse(hasPlatformKeys,hasBreakpointKeys,hasUserDefinedKeys,hasLightDarkKeys)){throw new Error("Cannot mix usage of platform keys, breakpoint keys, light/dark keys, and custom defined keys on the same level"+`\nKeys: ${Object.keys(value).join(", ")}`);}else if(hasPlatformKeys){return"platform";}else if(hasBreakpointKeys){return"breakpoint";}else if(hasLightDarkKeys){return"lightDark";}else{return"default";}}function onlyOneTrue(a,b,c,d){return[a,b,c,d].filter(function(x){return x;}).length===1;}function allFalse(a,b,c,d){return[a,b,c,d].filter(function(x){return x;}).length===0;}function getPlatformValue(input){var _value$devicePlatform;var value=input.value,devicePlatform=input.devicePlatform;var currentPlatformValue=(_value$devicePlatform=value==null?void 0:value[devicePlatform])!=null?_value$devicePlatform:value==null?void 0:value.default;var valueAsThemeValues=asThemeValuesObject(currentPlatformValue);if(valueAsThemeValues){return createThemeValuesProxy(Object.assign({},input,{value:valueAsThemeValues}));}else{return currentPlatformValue;}}function getBreakpointValue(input){var _value$currentBreakpo;var value=input.value,breakpoints=input.breakpoints,deviceWidth=input.deviceWidth;var keysToBreakpointValue=Object.keys(value!=null?value:{}).map(function(key){return[key,breakpoints[key]];});var orderedBreakpoints=keysToBreakpointValue.sort(function(_ref2){var _ref3=_slicedToArray(_ref2,2),_=_ref3[0],val=_ref3[1];return val;});var currentBreakpointKey="";for(var _ref4 of orderedBreakpoints){var _ref5=_slicedToArray(_ref4,2);var breakpointKey=_ref5[0];var breakpointValue=_ref5[1];if(deviceWidth>=breakpointValue){currentBreakpointKey=breakpointKey;}}var currentBreakpointValue=(_value$currentBreakpo=value==null?void 0:value[currentBreakpointKey])!=null?_value$currentBreakpo:value==null?void 0:value.default;var valueAsThemeValues=asThemeValuesObject(currentBreakpointValue);if(valueAsThemeValues){return createThemeValuesProxy(Object.assign({},input,{value:valueAsThemeValues}));}else{return currentBreakpointValue;}}function getLightDarkValue(input){var _value$currentLightDa;var value=input.value,currentLightDarkSelection=input.currentLightDarkSelection;var currentLightDarkValue=(_value$currentLightDa=value==null?void 0:value[currentLightDarkSelection])!=null?_value$currentLightDa:value==null?void 0:value.default;var valueAsThemeValues=asThemeValuesObject(currentLightDarkValue);if(valueAsThemeValues){return createThemeValuesProxy(Object.assign({},input,{value:valueAsThemeValues}));}else{return currentLightDarkValue;}}
@@ -0,0 +1 @@
1
+ import{isObject}from"lodash";export function isTextStyleObject(value){try{return Object.keys(value).some(function(key){return["fontFamily","fontWeight","fontSize","fontStyle","lineHeight","letterSpacing"].includes(key);});}catch(e){return false;}}export function asThemeValuesObject(value){return!isTextStyleObject(value)&&isObject(value)?value:null;}
@@ -1 +1 @@
1
- export function validatePalettes(palettes){palettes;}export function validateBreakpoints(breakpoints){breakpoints;}export function validateTheme(theme){theme;}export function isTextStyleObject(value){value;return true;}export function asThemeValuesObject(value){return value;}
1
+ import{z}from"zod";var PaletteSchema=z.record(z.string(),z.record(z.string(),z.string()));var BreakpointSchema=z.record(z.string(),z.number());var TextStyleSchema=z.union([z.object({fontSize:z.number()}),z.object({fontFamily:z.string()}),z.object({fontWeight:z.enum(["normal","bold","100","200","300","400","500","600","700","800","900"])}),z.object({fontStyle:z.enum(["normal","italic"])}),z.object({letterSpacing:z.number()}),z.object({lineHeight:z.number()})]);var ThemeValuesSchema=z.record(z.string(),z.lazy(function(){return z.union([z.string(),z.number(),TextStyleSchema,ThemeValuesSchema]);}));var TextStyleOrThemeValuesSchema=z.union([TextStyleSchema,ThemeValuesSchema]);var ThemeSchema=z.object({name:z.string(),colors:z.object({branding:ThemeValuesSchema.optional(),text:ThemeValuesSchema.optional(),background:ThemeValuesSchema.optional(),foreground:ThemeValuesSchema.optional(),border:ThemeValuesSchema.optional()}),typography:z.object({body1:TextStyleOrThemeValuesSchema.optional(),body2:TextStyleOrThemeValuesSchema.optional(),button:TextStyleOrThemeValuesSchema.optional(),caption:TextStyleOrThemeValuesSchema.optional(),headline1:TextStyleOrThemeValuesSchema.optional(),headline2:TextStyleOrThemeValuesSchema.optional(),headline3:TextStyleOrThemeValuesSchema.optional(),headline4:TextStyleOrThemeValuesSchema.optional(),headline5:TextStyleOrThemeValuesSchema.optional(),headline6:TextStyleOrThemeValuesSchema.optional(),overline:TextStyleOrThemeValuesSchema.optional(),subtitle1:TextStyleOrThemeValuesSchema.optional(),subtitle2:TextStyleOrThemeValuesSchema.optional()})});export function validatePalettes(palettes){var result=PaletteSchema.safeParse(palettes);if(!result.success){throw new Error("Invalid palettes object: "+result.error.message);}}export function validateBreakpoints(breakpoints){var result=BreakpointSchema.safeParse(breakpoints);if(!result.success){throw new Error("Invalid breakpoints object: "+result.error.message);}}export function validateTheme(theme){var result=ThemeSchema.safeParse(theme);if(!result.success){throw new Error("Invalid theme object: "+result.error.message);}}
@@ -28,17 +28,26 @@ const Provider = ({ themes, breakpoints, initialThemeName, children, }) => {
28
28
  });
29
29
  }
30
30
  }, [themes, setCurrentTheme]);
31
- const proxiedTheme = React.useMemo(() => ({
32
- ...currentTheme,
33
- colors: {
34
- branding: createThemeValuesProxy(currentTheme.colors.branding, breakpoints, deviceWidth, Platform.OS, lightDarkSelection),
35
- text: createThemeValuesProxy(currentTheme.colors.text, breakpoints, deviceWidth, Platform.OS, lightDarkSelection),
36
- background: createThemeValuesProxy(currentTheme.colors.background, breakpoints, deviceWidth, Platform.OS, lightDarkSelection),
37
- foreground: createThemeValuesProxy(currentTheme.colors.foreground, breakpoints, deviceWidth, Platform.OS, lightDarkSelection),
38
- border: createThemeValuesProxy(currentTheme.colors.border, breakpoints, deviceWidth, Platform.OS, lightDarkSelection),
39
- },
40
- typography: currentTheme.typography,
41
- }), [currentTheme, deviceWidth, breakpoints, lightDarkSelection]);
31
+ const proxiedTheme = React.useMemo(() => {
32
+ const createProxiedThemeValue = (value) => createThemeValuesProxy({
33
+ value,
34
+ breakpoints,
35
+ deviceWidth,
36
+ devicePlatform: Platform.OS,
37
+ currentLightDarkSelection: lightDarkSelection,
38
+ });
39
+ return {
40
+ ...currentTheme,
41
+ colors: {
42
+ branding: createProxiedThemeValue(currentTheme.colors.branding),
43
+ text: createProxiedThemeValue(currentTheme.colors.text),
44
+ background: createProxiedThemeValue(currentTheme.colors.background),
45
+ foreground: createProxiedThemeValue(currentTheme.colors.foreground),
46
+ border: createProxiedThemeValue(currentTheme.colors.border),
47
+ },
48
+ typography: createProxiedThemeValue(currentTheme.typography),
49
+ };
50
+ }, [currentTheme, deviceWidth, breakpoints, lightDarkSelection]);
42
51
  React.useEffect(() => {
43
52
  const listener = Dimensions.addEventListener("change", ({ window }) => setDeviceWidth(window.width));
44
53
  return () => {
@@ -48,8 +57,16 @@ const Provider = ({ themes, breakpoints, initialThemeName, children, }) => {
48
57
  React.useEffect(() => {
49
58
  const run = async () => {
50
59
  const savedSelectedThemeName = await AsyncStorage.getItem(SAVED_SELECTED_THEME_KEY);
60
+ const themeExists = themes.some((t) => t.name === savedSelectedThemeName);
51
61
  if (savedSelectedThemeName) {
52
- changeTheme(savedSelectedThemeName);
62
+ if (themeExists) {
63
+ changeTheme(savedSelectedThemeName);
64
+ }
65
+ else {
66
+ AsyncStorage.removeItem(SAVED_SELECTED_THEME_KEY).catch((e) => {
67
+ console.warn("Failed to reset persisted selected theme", e);
68
+ });
69
+ }
53
70
  }
54
71
  };
55
72
  run();
@@ -1 +1 @@
1
- {"version":3,"file":"Provider.js","sourceRoot":"","sources":["../../../src/Provider.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AACpE,OAAO,YAAY,MAAM,2CAA2C,CAAC;AACrE,OAAO,sBAAsB,MAAM,0BAA0B,CAAC;AAC9D,OAAO,YAAY,MAAM,gBAAgB,CAAC;AAQ1C,MAAM,wBAAwB,GAAG,sBAAsB,CAAC;AAOxD,MAAM,YAAY,GAAG,KAAK,CAAC,aAAa,CAAmB;IACzD,KAAK,EAAE,YAAY;IACnB,WAAW,EAAE,GAAG,EAAE,GAAE,CAAC;CACtB,CAAC,CAAC;AAQH,MAAM,QAAQ,GAAqD,CAAC,EAClE,MAAM,EACN,WAAW,EACX,gBAAgB,EAChB,QAAQ,GACT,EAAE,EAAE;;IACH,MAAM,YAAY,GAChB,MAAA,MAAM,CAAC,IAAI,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,IAAI,KAA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WAAW,EAAE,GAAG,KAAK,CAAC,UAAU,CAAC,YAAY,CAAC,CAAC;IACvD,OAAO,WAAW,CAAC;AACrB,CAAC,CAAC;AAEF,MAAM,SAAS,GAAG,CAChB,SAAqC,EACrC,EAAE;IACF,OAAO,KAAK,CAAC,UAAU,CACrB,CAAC,KAA2B,EAAE,GAAmB,EAAE,EAAE;QACnD,MAAM,EAAE,KAAK,EAAE,GAAG,KAAK,CAAC,UAAU,CAAC,YAAY,CAAC,CAAC;QACjD,OAAO,oBAAC,SAAS,OAAM,KAAe,EAAE,KAAK,EAAE,KAAK,EAAE,GAAG,EAAE,GAAG,GAAI,CAAC;IACrE,CAAC,CACF,CAAC;AACJ,CAAC,CAAC;AAEF,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,cAAc,EAAE,SAAS,EAAE,CAAC"}
@@ -1,17 +1,5 @@
1
1
  import type { Breakpoints, Theme, ValidatedTheme, ColorPalettes } from "./types";
2
- /**
3
- * Custom deepmerge function to skip merging of typography/text style objects.
4
- *
5
- * The theme object allows for special keys that trigger variability depending
6
- * on platform, breakpoint, color mode, etc.
7
- *
8
- * Text style objects can break this logic when merged with other objects.
9
- * For example, if you merge a standard text style object with another object that
10
- * has variability through the special keys, you get an object with both special
11
- * keys and the keys of the style object which breaks how the proxy is able to
12
- * return the correct value.
13
- */
14
- export default function createTheme({ theme, baseTheme, }: {
2
+ export default function createTheme({ breakpoints, palettes, theme, baseTheme, }: {
15
3
  breakpoints: Breakpoints;
16
4
  palettes: ColorPalettes;
17
5
  theme: Theme;
@@ -1,4 +1,6 @@
1
- import merge from "deepmerge";
1
+ import { deepmergeCustom } from "deepmerge-ts";
2
+ import { validateBreakpoints, validatePalettes, validateTheme, } from "./validators";
3
+ import { isTextStyleObject } from "./utils";
2
4
  /**
3
5
  * Custom deepmerge function to skip merging of typography/text style objects.
4
6
  *
@@ -11,14 +13,24 @@ import merge from "deepmerge";
11
13
  * keys and the keys of the style object which breaks how the proxy is able to
12
14
  * return the correct value.
13
15
  */
14
- export default function createTheme({ theme, baseTheme, }) {
15
- // validateBreakpoints(breakpoints);
16
- // validatePalettes(palettes);
17
- // validateTheme(theme);
16
+ const themeMerge = deepmergeCustom({
17
+ enableImplicitDefaultMerging: true,
18
+ mergeRecords(values, utils, meta) {
19
+ const firstValue = values[0];
20
+ if (isTextStyleObject(firstValue)) {
21
+ return utils.defaultMergeFunctions.mergeRecords(values.slice(1), utils, meta);
22
+ }
23
+ return utils.defaultMergeFunctions.mergeRecords(values, utils, meta);
24
+ },
25
+ });
26
+ export default function createTheme({ breakpoints, palettes, theme, baseTheme, }) {
27
+ validateBreakpoints(breakpoints);
28
+ validatePalettes(palettes);
29
+ validateTheme(theme);
18
30
  let resultTheme = theme;
19
31
  if (baseTheme) {
20
- //validateTheme(baseTheme);
21
- resultTheme = merge(baseTheme, theme);
32
+ validateTheme(baseTheme);
33
+ resultTheme = themeMerge(baseTheme, theme);
22
34
  }
23
35
  return {
24
36
  ...resultTheme,
@@ -1 +1 @@
1
- {"version":3,"file":"createTheme.js","sourceRoot":"","sources":["../../../src/createTheme.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,MAAM,WAAW,CAAC;AAE9B;;;;;;;;;;;GAWG;AAEH,MAAM,CAAC,OAAO,UAAU,WAAW,CAAC,EAClC,KAAK,EACL,SAAS,GAMV;IACC,oCAAoC;IACpC,8BAA8B;IAC9B,wBAAwB;IAExB,IAAI,WAAW,GAAG,KAAK,CAAC;IAExB,IAAI,SAAS,EAAE;QACb,2BAA2B;QAC3B,WAAW,GAAG,KAAK,CAAC,SAAS,EAAE,KAAK,CAAC,CAAC;KACvC;IAED,OAAO;QACL,GAAG,WAAW;QACd,SAAS,EAAE,IAAI;KAChB,CAAC;AACJ,CAAC"}
1
+ {"version":3,"file":"createTheme.js","sourceRoot":"","sources":["../../../src/createTheme.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAO/C,OAAO,EACL,mBAAmB,EACnB,gBAAgB,EAChB,aAAa,GACd,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAC;AAE5C;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,GAAG,eAAe,CAAC;IACjC,4BAA4B,EAAE,IAAI;IAClC,YAAY,CAAC,MAAM,EAAE,KAAK,EAAE,IAAI;QAC9B,MAAM,UAAU,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC;QAC7B,IAAI,iBAAiB,CAAC,UAAU,CAAC,EAAE;YACjC,OAAO,KAAK,CAAC,qBAAqB,CAAC,YAAY,CAC7C,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,EACf,KAAK,EACL,IAAI,CACL,CAAC;SACH;QACD,OAAO,KAAK,CAAC,qBAAqB,CAAC,YAAY,CAAC,MAAM,EAAE,KAAK,EAAE,IAAI,CAAC,CAAC;IACvE,CAAC;CACF,CAAC,CAAC;AAEH,MAAM,CAAC,OAAO,UAAU,WAAW,CAAC,EAClC,WAAW,EACX,QAAQ,EACR,KAAK,EACL,SAAS,GAMV;IACC,mBAAmB,CAAC,WAAW,CAAC,CAAC;IACjC,gBAAgB,CAAC,QAAQ,CAAC,CAAC;IAC3B,aAAa,CAAC,KAAK,CAAC,CAAC;IAErB,IAAI,WAAW,GAAG,KAAK,CAAC;IAExB,IAAI,SAAS,EAAE;QACb,aAAa,CAAC,SAAS,CAAC,CAAC;QACzB,WAAW,GAAG,UAAU,CAAC,SAAS,EAAE,KAAK,CAAC,CAAC;KAC5C;IAED,OAAO;QACL,GAAG,WAAW;QACd,SAAS,EAAE,IAAI;KAChB,CAAC;AACJ,CAAC"}
@@ -1,5 +1,12 @@
1
1
  import { ThemeValues, Breakpoints } from "./types";
2
2
  import { Platform } from "react-native";
3
+ interface CreateThemeValuesProxyInput {
4
+ value: ThemeValues | undefined;
5
+ breakpoints: Breakpoints;
6
+ deviceWidth: number;
7
+ devicePlatform: typeof Platform.OS;
8
+ currentLightDarkSelection: "light" | "dark";
9
+ }
3
10
  /**
4
11
  * Creates a proxy for theme value objects to select a value whenever
5
12
  * multiple values are provided for different platforms, breakpoints, and/or light/dark modes
@@ -7,4 +14,5 @@ import { Platform } from "react-native";
7
14
  * Ex: {color: {ios: "blue", android: "red"}}
8
15
  * -> theme.color returns "blue" when the platform is ios and "red" when android
9
16
  */
10
- export default function createThemeValuesProxy(value: ThemeValues | undefined, breakpoints: Breakpoints, deviceWidth: number, devicePlatform: typeof Platform.OS, currentLightDarkSelection: "light" | "dark"): any;
17
+ export default function createThemeValuesProxy({ value, breakpoints, deviceWidth, devicePlatform, currentLightDarkSelection, }: CreateThemeValuesProxyInput): any;
18
+ export {};
@@ -1,4 +1,4 @@
1
- import { isObject } from "lodash";
1
+ import { asThemeValuesObject } from "./utils";
2
2
  /**
3
3
  * Creates a proxy for theme value objects to select a value whenever
4
4
  * multiple values are provided for different platforms, breakpoints, and/or light/dark modes
@@ -6,32 +6,37 @@ import { isObject } from "lodash";
6
6
  * Ex: {color: {ios: "blue", android: "red"}}
7
7
  * -> theme.color returns "blue" when the platform is ios and "red" when android
8
8
  */
9
- export default function createThemeValuesProxy(value, breakpoints, deviceWidth, devicePlatform, currentLightDarkSelection) {
9
+ export default function createThemeValuesProxy({ value, breakpoints, deviceWidth, devicePlatform, currentLightDarkSelection, }) {
10
10
  if (value === undefined || value === null) {
11
11
  return undefined;
12
12
  }
13
13
  return new Proxy(value, {
14
14
  get: (target, key) => {
15
15
  const currentValue = target[key];
16
- const valueAsThemeValues = isObject(currentValue)
17
- ? currentValue
18
- : undefined;
16
+ const valueAsThemeValues = asThemeValuesObject(currentValue);
19
17
  if (valueAsThemeValues) {
20
18
  const platformKeys = ["ios", "android", "web", "macos", "windows"];
21
19
  const breakpointKeys = Object.keys(breakpoints);
22
20
  const lightDarkKeys = ["light", "dark"];
23
21
  const keysType = getKeysType(valueAsThemeValues, platformKeys, breakpointKeys, lightDarkKeys);
22
+ const input = {
23
+ value: valueAsThemeValues,
24
+ breakpoints,
25
+ deviceWidth,
26
+ devicePlatform,
27
+ currentLightDarkSelection,
28
+ };
24
29
  if (keysType === "default") {
25
- return createThemeValuesProxy(valueAsThemeValues, breakpoints, deviceWidth, devicePlatform, currentLightDarkSelection);
30
+ return createThemeValuesProxy(input);
26
31
  }
27
32
  else if (keysType === "platform") {
28
- return getPlatformValue(valueAsThemeValues, breakpoints, deviceWidth, devicePlatform, currentLightDarkSelection);
33
+ return getPlatformValue(input);
29
34
  }
30
35
  else if (keysType === "breakpoint") {
31
- return getBreakpointValue(valueAsThemeValues, breakpoints, deviceWidth, devicePlatform, currentLightDarkSelection);
36
+ return getBreakpointValue(input);
32
37
  }
33
38
  else if (keysType === "lightDark") {
34
- return getLightDarkValue(valueAsThemeValues, breakpoints, deviceWidth, devicePlatform, currentLightDarkSelection);
39
+ return getLightDarkValue(input);
35
40
  }
36
41
  else {
37
42
  return undefined;
@@ -78,21 +83,21 @@ function onlyOneTrue(a, b, c, d) {
78
83
  function allFalse(a, b, c, d) {
79
84
  return [a, b, c, d].filter((x) => x).length === 0;
80
85
  }
81
- function getPlatformValue(value, breakpoints, deviceWidth, devicePlatform, currentLightDarkSelection) {
86
+ function getPlatformValue(input) {
82
87
  var _a;
88
+ const { value, devicePlatform } = input;
83
89
  const currentPlatformValue = (_a = value === null || value === void 0 ? void 0 : value[devicePlatform]) !== null && _a !== void 0 ? _a : value === null || value === void 0 ? void 0 : value.default;
84
- const valueAsThemeValues = isObject(currentPlatformValue)
85
- ? currentPlatformValue
86
- : undefined;
90
+ const valueAsThemeValues = asThemeValuesObject(currentPlatformValue);
87
91
  if (valueAsThemeValues) {
88
- return createThemeValuesProxy(valueAsThemeValues, breakpoints, deviceWidth, devicePlatform, currentLightDarkSelection);
92
+ return createThemeValuesProxy({ ...input, value: valueAsThemeValues });
89
93
  }
90
94
  else {
91
95
  return currentPlatformValue;
92
96
  }
93
97
  }
94
- function getBreakpointValue(value, breakpoints, deviceWidth, devicePlatform, currentLightDarkSelection) {
98
+ function getBreakpointValue(input) {
95
99
  var _a;
100
+ const { value, breakpoints, deviceWidth } = input;
96
101
  const keysToBreakpointValue = Object.keys(value !== null && value !== void 0 ? value : {}).map((key) => [key, breakpoints[key]]);
97
102
  const orderedBreakpoints = keysToBreakpointValue.sort(([_, val]) => val);
98
103
  let currentBreakpointKey = "";
@@ -102,24 +107,21 @@ function getBreakpointValue(value, breakpoints, deviceWidth, devicePlatform, cur
102
107
  }
103
108
  }
104
109
  const currentBreakpointValue = (_a = value === null || value === void 0 ? void 0 : value[currentBreakpointKey]) !== null && _a !== void 0 ? _a : value === null || value === void 0 ? void 0 : value.default;
105
- const valueAsThemeValues = isObject(currentBreakpointKey)
106
- ? currentBreakpointKey
107
- : undefined;
110
+ const valueAsThemeValues = asThemeValuesObject(currentBreakpointValue);
108
111
  if (valueAsThemeValues) {
109
- return createThemeValuesProxy(valueAsThemeValues, breakpoints, deviceWidth, devicePlatform, currentLightDarkSelection);
112
+ return createThemeValuesProxy({ ...input, value: valueAsThemeValues });
110
113
  }
111
114
  else {
112
115
  return currentBreakpointValue;
113
116
  }
114
117
  }
115
- function getLightDarkValue(value, breakpoints, deviceWidth, devicePlatform, currentLightDarkSelection) {
118
+ function getLightDarkValue(input) {
116
119
  var _a;
120
+ const { value, currentLightDarkSelection } = input;
117
121
  const currentLightDarkValue = (_a = value === null || value === void 0 ? void 0 : value[currentLightDarkSelection]) !== null && _a !== void 0 ? _a : value === null || value === void 0 ? void 0 : value.default;
118
- const valueAsThemeValues = isObject(currentLightDarkSelection)
119
- ? currentLightDarkSelection
120
- : undefined;
122
+ const valueAsThemeValues = asThemeValuesObject(currentLightDarkValue);
121
123
  if (valueAsThemeValues) {
122
- return createThemeValuesProxy(valueAsThemeValues, breakpoints, deviceWidth, devicePlatform, currentLightDarkSelection);
124
+ return createThemeValuesProxy({ ...input, value: valueAsThemeValues });
123
125
  }
124
126
  else {
125
127
  return currentLightDarkValue;
@@ -1 +1 @@
1
- {"version":3,"file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cAAc,EACd,yBAAyB,CAC1B,CAAC;KACH;SAAM;QACL,OAAO,sBAAsB,CAAC;KAC/B;AACH,CAAC;AAED,SAAS,iBAAiB,CACxB,KAA8B,EAC9B,WAAwB,EACxB,WAAmB,EACnB,cAAkC,EAClC,yBAA2C;;IAE3C,MAAM,qBAAqB,GACzB,MAAA,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAG,yBAAyB,CAAC,mCAAI,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,OAAO,CAAC;IACvD,MAAM,kBAAkB,GAAG,QAAQ,CAAC,yBAAyB,CAAC;QAC5D,CAAC,CAAE,yBAAyC;QAC5C,CAAC,CAAC,SAAS,CAAC;IAEd,IAAI,kBAAkB,EAAE;QACtB,OAAO,sBAAsB,CAC3B,kBAAkB,EAClB,WAAW,EACX,WAAW,EACX,cAAc,EACd,yBAAyB,CAC1B,CAAC;KACH;SAAM;QACL,OAAO,qBAAqB,CAAC;KAC9B;AACH,CAAC"}
1
+ {"version":3,"file":"createThemeValuesProxy.js","sourceRoot":"","sources":["../../../src/createThemeValuesProxy.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAC;AAU9C;;;;;;GAMG;AACH,MAAM,CAAC,OAAO,UAAU,sBAAsB,CAAC,EAC7C,KAAK,EACL,WAAW,EACX,WAAW,EACX,cAAc,EACd,yBAAyB,GACG;IAC5B,IAAI,KAAK,KAAK,SAAS,IAAI,KAAK,KAAK,IAAI,EAAE;QACzC,OAAO,SAAS,CAAC;KAClB;IACD,OAAO,IAAI,KAAK,CAAC,KAAK,EAAE;QACtB,GAAG,EAAE,CACH,MAAmB,EACnB,GAAW,EAC4C,EAAE;YACzD,MAAM,YAAY,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC;YAEjC,MAAM,kBAAkB,GAAG,mBAAmB,CAAC,YAAY,CAAC,CAAC;YAE7D,IAAI,kBAAkB,EAAE;gBACtB,MAAM,YAAY,GAAG,CAAC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a,EAAE,eAAe,CAAC,IAAI,kBAAkB,EAAE;QACjE,IAAI,WAAW,IAAI,eAAe,EAAE;YAClC,oBAAoB,GAAG,aAAa,CAAC;SACtC;KACF;IACD,MAAM,sBAAsB,GAC1B,MAAA,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAG,oBAAoB,CAAC,mCAAI,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,OAAO,CAAC;IAClD,MAAM,kBAAkB,GAAG,mBAAmB,CAAC,sBAAsB,CAAC,CAAC;IAEvE,IAAI,kBAAkB,EAAE;QACtB,OAAO,sBAAsB,CAAC,EAAE,GAAG,KAAK,EAAE,KAAK,EAAE,kBAAkB,EAAE,CAAC,CAAC;KACxE;SAAM;QACL,OAAO,sBAAsB,CAAC;KAC/B;AACH,CAAC;AAED,SAAS,iBAAiB,CAAC,KAAkC;;IAC3D,MAAM,EAAE,KAAK,EAAE,yBAAyB,EAAE,GAAG,KAAK,CAAC;IAEnD,MAAM,qBAAqB,GACzB,MAAA,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAG,yBAAyB,CAAC,mCAAI,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,OAAO,CAAC;IACvD,MAAM,kBAAkB,GAAG,mBAAmB,CAAC,qBAAqB,CAAC,CAAC;IAEtE,IAAI,kBAAkB,EAAE;QACtB,OAAO,sBAAsB,CAAC,EAAE,GAAG,KAAK,EAAE,KAAK,EAAE,kBAAkB,EAAE,CAAC,CAAC;KACxE;SAAM;QACL,OAAO,qBAAqB,CAAC;KAC9B;AACH,CAAC"}
@@ -0,0 +1,3 @@
1
+ import type { ThemeValues } from "./types";
2
+ export declare function isTextStyleObject(value: any): boolean;
3
+ export declare function asThemeValuesObject(value: any): ThemeValues | null;
@@ -0,0 +1,25 @@
1
+ import { isObject } from "lodash";
2
+ export function isTextStyleObject(value) {
3
+ try {
4
+ return Object.keys(value).some((key) => [
5
+ "fontFamily",
6
+ "fontWeight",
7
+ "fontSize",
8
+ "fontStyle",
9
+ "lineHeight",
10
+ "letterSpacing",
11
+ ].includes(key));
12
+ }
13
+ catch (e) {
14
+ // If `value` is not an object, the above code will throw an error
15
+ // Catch error and return false is more efficient than a call to `isObject`
16
+ return false;
17
+ }
18
+ }
19
+ export function asThemeValuesObject(value) {
20
+ // Any object that isn't a text style object is considered a ThemeValues object
21
+ return !isTextStyleObject(value) && isObject(value)
22
+ ? value
23
+ : null;
24
+ }
25
+ //# sourceMappingURL=utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAC;AAGlC,MAAM,UAAU,iBAAiB,CAAC,KAAU;IAC1C,IAAI;QACF,OAAO,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,CAAC,GAAG,EAAE,EAAE,CACrC;YACE,YAAY;YACZ,YAAY;YACZ,UAAU;YACV,WAAW;YACX,YAAY;YACZ,eAAe;SAChB,CAAC,QAAQ,CAAC,GAAG,CAAC,CAChB,CAAC;KACH;IAAC,OAAO,CAAC,EAAE;QACV,kEAAkE;QAClE,2EAA2E;QAC3E,OAAO,KAAK,CAAC;KACd;AACH,CAAC;AAED,MAAM,UAAU,mBAAmB,CAAC,KAAU;IAC5C,+EAA+E;IAC/E,OAAO,CAAC,iBAAiB,CAAC,KAAK,CAAC,IAAI,QAAQ,CAAC,KAAK,CAAC;QACjD,CAAC,CAAE,KAAqB;QACxB,CAAC,CAAC,IAAI,CAAC;AACX,CAAC"}
@@ -1,6 +1,4 @@
1
- import { ColorPalettes, Breakpoints, Theme, ThemeValues } from "./types";
1
+ import { ColorPalettes, Breakpoints, Theme } from "./types";
2
2
  export declare function validatePalettes(palettes: ColorPalettes): void;
3
3
  export declare function validateBreakpoints(breakpoints: Breakpoints): void;
4
4
  export declare function validateTheme(theme: Theme): void;
5
- export declare function isTextStyleObject(value: any): boolean;
6
- export declare function asThemeValuesObject(value: any): ThemeValues | null;
@@ -1,17 +1,81 @@
1
+ import { z } from "zod";
2
+ const PaletteSchema = z.record(z.string(), z.record(z.string(), z.string()));
3
+ const BreakpointSchema = z.record(z.string(), z.number());
4
+ const TextStyleSchema = z.union([
5
+ z.object({
6
+ fontSize: z.number(),
7
+ }),
8
+ z.object({
9
+ fontFamily: z.string(),
10
+ }),
11
+ z.object({
12
+ fontWeight: z.enum([
13
+ "normal",
14
+ "bold",
15
+ "100",
16
+ "200",
17
+ "300",
18
+ "400",
19
+ "500",
20
+ "600",
21
+ "700",
22
+ "800",
23
+ "900",
24
+ ]),
25
+ }),
26
+ z.object({
27
+ fontStyle: z.enum(["normal", "italic"]),
28
+ }),
29
+ z.object({
30
+ letterSpacing: z.number(),
31
+ }),
32
+ z.object({
33
+ lineHeight: z.number(),
34
+ }),
35
+ ]);
36
+ const ThemeValuesSchema = z.record(z.string(), z.lazy(() => z.union([z.string(), z.number(), TextStyleSchema, ThemeValuesSchema])));
37
+ const TextStyleOrThemeValuesSchema = z.union([TextStyleSchema, ThemeValuesSchema]);
38
+ const ThemeSchema = z.object({
39
+ name: z.string(),
40
+ colors: z.object({
41
+ branding: ThemeValuesSchema.optional(),
42
+ text: ThemeValuesSchema.optional(),
43
+ background: ThemeValuesSchema.optional(),
44
+ foreground: ThemeValuesSchema.optional(),
45
+ border: ThemeValuesSchema.optional(),
46
+ }),
47
+ typography: z.object({
48
+ body1: TextStyleOrThemeValuesSchema.optional(),
49
+ body2: TextStyleOrThemeValuesSchema.optional(),
50
+ button: TextStyleOrThemeValuesSchema.optional(),
51
+ caption: TextStyleOrThemeValuesSchema.optional(),
52
+ headline1: TextStyleOrThemeValuesSchema.optional(),
53
+ headline2: TextStyleOrThemeValuesSchema.optional(),
54
+ headline3: TextStyleOrThemeValuesSchema.optional(),
55
+ headline4: TextStyleOrThemeValuesSchema.optional(),
56
+ headline5: TextStyleOrThemeValuesSchema.optional(),
57
+ headline6: TextStyleOrThemeValuesSchema.optional(),
58
+ overline: TextStyleOrThemeValuesSchema.optional(),
59
+ subtitle1: TextStyleOrThemeValuesSchema.optional(),
60
+ subtitle2: TextStyleOrThemeValuesSchema.optional(),
61
+ }),
62
+ });
1
63
  export function validatePalettes(palettes) {
2
- palettes;
64
+ const result = PaletteSchema.safeParse(palettes);
65
+ if (!result.success) {
66
+ throw new Error("Invalid palettes object: " + result.error.message);
67
+ }
3
68
  }
4
69
  export function validateBreakpoints(breakpoints) {
5
- breakpoints;
70
+ const result = BreakpointSchema.safeParse(breakpoints);
71
+ if (!result.success) {
72
+ throw new Error("Invalid breakpoints object: " + result.error.message);
73
+ }
6
74
  }
7
75
  export function validateTheme(theme) {
8
- theme;
9
- }
10
- export function isTextStyleObject(value) {
11
- value;
12
- return true;
13
- }
14
- export function asThemeValuesObject(value) {
15
- return value;
76
+ const result = ThemeSchema.safeParse(theme);
77
+ if (!result.success) {
78
+ throw new Error("Invalid theme object: " + result.error.message);
79
+ }
16
80
  }
17
81
  //# sourceMappingURL=validators.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"validators.js","sourceRoot":"","sources":["../../../src/validators.ts"],"names":[],"mappings":"AAEA,MAAM,UAAU,gBAAgB,CAAC,QAAuB;IACtD,QAAQ,CAAC;AACX,CAAC;AAED,MAAM,UAAU,mBAAmB,CAAC,WAAwB;IAC1D,WAAW,CAAC;AACd,CAAC;AAED,MAAM,UAAU,aAAa,CAAC,KAAY;IACxC,KAAK,CAAC;AACR,CAAC;AAED,MAAM,UAAU,iBAAiB,CAAC,KAAU;IAC1C,KAAK,CAAC;IACN,OAAO,IAAI,CAAC;AACd,CAAC;AAED,MAAM,UAAU,mBAAmB,CAAC,KAAU;IAC5C,OAAO,KAAK,CAAC;AACf,CAAC"}
1
+ {"version":3,"file":"validators.js","sourceRoot":"","sources":["../../../src/validators.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,MAAM,aAAa,GAA6B,CA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