-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat!: make utils configurable for v1 release
- Loading branch information
1 parent
d0692c9
commit 90db661
Showing
11 changed files
with
307 additions
and
325 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,3 @@ | ||
/** | ||
* @typedef {import('./lib/types.js').Theme} Theme | ||
* @typedef {import('./lib/types.js').ThemeMapping} ThemeMapping | ||
*/ | ||
|
||
export {createTheme} from './lib/create-theme.js'; | ||
export {themeMapping} from './lib/theme-mapping.js'; | ||
export * as types from './lib/types.js'; | ||
export {defaultThemeSpec} from './lib/default-theme-spec.js'; | ||
export * from './lib/types.js'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,28 @@ | ||
import {merge} from 'uinix-fp-merge'; | ||
|
||
import {themeMapping} from './theme-mapping.js'; | ||
import {defaultThemeSpec} from './default-theme-spec.js'; | ||
|
||
export {createTheme}; | ||
|
||
/** | ||
* @typedef {import('./types.js').Theme} Theme | ||
* @typedef {import('./types.js').ThemeSpec} ThemeSpec | ||
*/ | ||
|
||
/** | ||
* Creates a uinix `Theme` object. | ||
* | ||
* The theme is a mapping of `ThemeProperty` to `ThemePropertyDefinition` (arbitarily nested), which eventually resolves to valid `ThemePropertyValue`s. | ||
* Creates a theme based on the provided theme spec and override theme. | ||
* Theme properties not specified in the theme spec are not included in the | ||
* resolved theme. | ||
* | ||
* Supports deep-merging and overriding with a partial theme. | ||
* | ||
* @param {Partial<Theme>} theme | ||
* @returns {Theme} | ||
* @template {Theme} T | ||
* @template {ThemeSpec} S | ||
* @param {T} [theme] | ||
* @param {S} [themeSpec] | ||
* @returns {T & Record<keyof S, {}>} | ||
*/ | ||
const createTheme = (theme = {}) => { | ||
const defaultTheme = Object.fromEntries( | ||
Object.keys(themeMapping).map((themeProperty) => [themeProperty, {}]), | ||
const createTheme = (theme, themeSpec) => | ||
// @ts-ignore (insufficient TS-inference) | ||
Object.fromEntries( | ||
Object.keys(themeSpec || defaultThemeSpec).map((themeProperty) => [ | ||
themeProperty, | ||
theme?.[themeProperty] || {}, | ||
]), | ||
); | ||
|
||
return merge(defaultTheme)(theme); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.