Skip to content

Commit 90a5e07

Browse files
committed
refactor: codestyle (move type imports to top of file)
1 parent 94e7dec commit 90a5e07

7 files changed

+44
-42
lines changed

index.js

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
export {combineStyles} from './lib/combine-styles.js';
22
export {createCssVariables} from './lib/create-css-variables.js';
33
export {createThemeRenderer} from './lib/create-theme-renderer.js';
4+
45
export * from './lib/types.js';

lib/combine-styles.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
import {combineRules} from 'fela';
2-
import {isPlainObject, k} from 'uinix-fp';
3-
41
/**
52
* @typedef {import('./types.js').Style} Style
63
* @typedef {import('./types.js').StyleRule} StyleRule
74
*/
85

6+
import {combineRules} from 'fela';
7+
import {isPlainObject, k} from 'uinix-fp';
8+
99
/**
1010
* Combines a singleton or array of styles (either objects or rules) to a single style rule.
1111
* @param {Style|Style[]} styles

lib/create-css-variables.js

+24-24
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,11 @@
1-
import {isUnitlessProperty} from 'css-in-js-utils';
2-
import {isPlainObject} from 'uinix-fp';
3-
4-
import {createCssVariable} from './utils/create-css-variable.js';
5-
61
/**
72
* @typedef {import('./types.js').Theme} Theme
83
*/
94

10-
/**
11-
* Returns a flattened object with property path as keys
12-
* @param {Object.<string, any>} object
13-
* @param {string} path
14-
* @returns {Object}
15-
*/
16-
const flatten = (object, path = '') => {
17-
/** @type {Record<string, any>} */
18-
const result = {};
19-
return Object.keys(object).reduce((acc, k) => {
20-
const prepath = path.length > 0 ? path + '.' : '';
21-
if (isPlainObject(object[k])) {
22-
Object.assign(acc, flatten(object[k], prepath + k));
23-
} else {
24-
acc[prepath + k] = object[k];
25-
}
5+
import {isUnitlessProperty} from 'css-in-js-utils';
6+
import {isPlainObject} from 'uinix-fp';
267

27-
return acc;
28-
}, result);
29-
};
8+
import {createCssVariable} from './utils/create-css-variable.js';
309

3110
/**
3211
* Transforms the provided nested theme into a flat object of CSS variables
@@ -52,4 +31,25 @@ export const createCssVariables = (theme = {}, options = defaultOptions) => {
5231
);
5332
};
5433

34+
/**
35+
* Returns a flattened object with property path as keys
36+
* @param {Object.<string, any>} object
37+
* @param {string} path
38+
* @returns {Object}
39+
*/
40+
const flatten = (object, path = '') => {
41+
/** @type {Record<string, any>} */
42+
const result = {};
43+
return Object.keys(object).reduce((acc, k) => {
44+
const prepath = path.length > 0 ? path + '.' : '';
45+
if (isPlainObject(object[k])) {
46+
Object.assign(acc, flatten(object[k], prepath + k));
47+
} else {
48+
acc[prepath + k] = object[k];
49+
}
50+
51+
return acc;
52+
}, result);
53+
};
54+
5555
const defaultOptions = {namespace: ''};

lib/create-theme-renderer.js

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
/**
2+
* @typedef {import('./types.js').StyleObject} StyleObject
3+
* @typedef {import('./types.js').StyleRule} StyleRule
4+
* @typedef {import('./types.js').Theme} Theme
5+
* @typedef {import('./types.js').ThemeSpec} ThemeSpec
6+
*/
7+
18
import {isUnitlessProperty} from 'css-in-js-utils';
29
import {createRenderer} from 'fela';
310
import {render as renderToDom} from 'fela-dom';
@@ -12,13 +19,6 @@ import {responsiveValue} from './utils/plugin-responsive-value.js';
1219
import {themeValue} from './utils/plugin-theme-value.js';
1320
import {validateNamespacePrefix} from './utils/validate-namespace-prefix.js';
1421

15-
/**
16-
* @typedef {import('./types.js').StyleObject} StyleObject
17-
* @typedef {import('./types.js').StyleRule} StyleRule
18-
* @typedef {import('./types.js').Theme} Theme
19-
* @typedef {import('./types.js').ThemeSpec} ThemeSpec
20-
*/
21-
2222
/**
2323
* Returns a theme renderer supporting themable and responsive style rendering.
2424
*

lib/utils/create-css-variable.js

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import {validateNamespacePrefix} from './validate-namespace-prefix.js';
2+
23
/**
34
* Creates a valid CSS variable (i.e. /^--[a-z0-9-_]+/)
45
* @param {string} key

lib/utils/plugin-responsive-value.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
import felaResponsiveValue from 'fela-plugin-responsive-value'; // type-coverage:ignore-line
2-
3-
import {coerceEsm} from './coerce-esm.js';
4-
51
/**
62
* @typedef {import('fela').TPlugin} FelaPlugin
73
*/
84

5+
import felaResponsiveValue from 'fela-plugin-responsive-value'; // type-coverage:ignore-line
6+
7+
import {coerceEsm} from './coerce-esm.js';
8+
99
/**
1010
* Customized Fela responsive value plugin.
1111
*

lib/utils/plugin-theme-value.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
import {isPlainObject, props} from 'uinix-fp';
2-
3-
import {createCssVariable} from './create-css-variable.js';
4-
51
/**
62
* @typedef {import('fela').TPlugin} FelaPlugin
73
* @typedef {import('../types.js').CssValue} CssValue
@@ -12,6 +8,10 @@ import {createCssVariable} from './create-css-variable.js';
128
* @typedef {import('../types.js').ThemeSpec} ThemeSpec
139
*/
1410

11+
import {isPlainObject, props} from 'uinix-fp';
12+
13+
import {createCssVariable} from './create-css-variable.js';
14+
1515
/**
1616
* Customized Fela theme value plugin.
1717
* @param {Object} params

0 commit comments

Comments
 (0)