@weser/styling 0.0.9
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/LICENSE +21 -0
- package/README.md +53 -0
- package/dist/core/createRenderer.d.ts +20 -0
- package/dist/core/createRenderer.js +22 -0
- package/dist/core/fallbackValue.d.ts +6 -0
- package/dist/core/fallbackValue.js +7 -0
- package/dist/core/fallbackValuePlugin.d.ts +2 -0
- package/dist/core/fallbackValuePlugin.js +29 -0
- package/dist/core/getFallbackCSS.d.ts +2 -0
- package/dist/core/getFallbackCSS.js +26 -0
- package/dist/core/getFallbackVariable.d.ts +1 -0
- package/dist/core/getFallbackVariable.js +3 -0
- package/dist/helpers/useCSSVariable.d.ts +1 -0
- package/dist/helpers/useCSSVariable.js +6 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.js +8 -0
- package/dist/modules/fela.d.ts +126 -0
- package/dist/plugins/debug.d.ts +5 -0
- package/dist/plugins/debug.js +14 -0
- package/dist/plugins/enforceLonghand.d.ts +4 -0
- package/dist/plugins/enforceLonghand.js +107 -0
- package/dist/plugins/prefixer.d.ts +3 -0
- package/dist/plugins/prefixer.js +89 -0
- package/dist/plugins/responsiveValue.d.ts +7 -0
- package/dist/plugins/responsiveValue.js +33 -0
- package/dist/plugins/sortProperty.d.ts +5 -0
- package/dist/plugins/sortProperty.js +23 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/dist/types.d.ts +12 -0
- package/dist/types.js +1 -0
- package/package.json +61 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2022-present Robin Weser
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
# @weser/context
|
|
2
|
+
|
|
3
|
+
<img alt="npm version" src="https://badge.fury.io/js/@weser%2Fcontext.svg"> <img alt="npm downloads" src="https://img.shields.io/npm/dm/@weser/context.svg"> <a href="https://bundlephobia.com/result?p=@weser/context@latest"><img alt="Bundlephobia" src="https://img.shields.io/bundlephobia/minzip/@weser/context.svg"></a>
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```sh
|
|
8
|
+
# npm
|
|
9
|
+
npm i --save @weser/context
|
|
10
|
+
# yarn
|
|
11
|
+
yarn add @weser/context
|
|
12
|
+
# pnpm
|
|
13
|
+
pnpm add @weser/context
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
## Documentation
|
|
17
|
+
|
|
18
|
+
### `createContext<T>`
|
|
19
|
+
|
|
20
|
+
#### Parameters
|
|
21
|
+
|
|
22
|
+
| Parameter | Type | Default | Description |
|
|
23
|
+
| ------------ | --------- | ------- | -------------------------------------------------------- |
|
|
24
|
+
| defaultValue | `T` | `null` | The default value for when no provider is used |
|
|
25
|
+
| name | `string` | `""` | (Optional) A name for the context used in error messages |
|
|
26
|
+
|
|
27
|
+
```tsx
|
|
28
|
+
import { createContext } from '@weser/context'
|
|
29
|
+
|
|
30
|
+
type Theme = 'light' | 'dark'
|
|
31
|
+
|
|
32
|
+
const [useTheme, ThemeProvider] = createContext<Theme>('light', 'theme')
|
|
33
|
+
|
|
34
|
+
function App({ children }) {
|
|
35
|
+
return <ThemeProvider value="dark">{children}</ThemeProvider>
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function Component() {
|
|
39
|
+
const theme = useTheme()
|
|
40
|
+
|
|
41
|
+
return (
|
|
42
|
+
<div style={{ backgroundColor: theme === 'dark' ? 'black' : 'white' }}>
|
|
43
|
+
Hello
|
|
44
|
+
</div>
|
|
45
|
+
)
|
|
46
|
+
}
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
## License
|
|
50
|
+
|
|
51
|
+
@weser/context is licensed under the [MIT License](http://opensource.org/licenses/MIT).<br>
|
|
52
|
+
Documentation is licensed under [Creative Common License](http://creativecommons.org/licenses/by/4.0/).<br>
|
|
53
|
+
Created with ♥ by [@robinweser](http://weser.io).
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { CSSProperties } from 'react';
|
|
2
|
+
import { createHooks as baseCreateHooks } from '@css-hooks/react';
|
|
3
|
+
import { WithHooks } from '@css-hooks/core';
|
|
4
|
+
import { assignStyle } from 'css-in-js-utils';
|
|
5
|
+
import { T_Fallback } from '../types.js';
|
|
6
|
+
type Plugin<T> = (style: T) => T;
|
|
7
|
+
type HookOptions<Hooks extends string> = Parameters<typeof baseCreateHooks<Hooks>>[0];
|
|
8
|
+
type Config<T, Hooks extends string> = {
|
|
9
|
+
hooks: HookOptions<Hooks>;
|
|
10
|
+
fallbacks?: Array<T_Fallback>;
|
|
11
|
+
plugins?: Array<Plugin<T>>;
|
|
12
|
+
mergeStyle?: typeof assignStyle;
|
|
13
|
+
};
|
|
14
|
+
type Properties<T, Hooks> = Array<Properties<T, Hooks>> | WithHooks<Hooks, T> | undefined;
|
|
15
|
+
type CSSFunction<T, Hooks> = (...style: Array<Properties<T, Hooks>>) => CSSProperties;
|
|
16
|
+
export default function createRenderer<Hooks extends Record<string, string>, T extends Record<string, any> = CSSProperties>({ hooks, fallbacks, plugins, mergeStyle, }: Config<T, keyof Hooks & string>): [
|
|
17
|
+
string,
|
|
18
|
+
CSSFunction<T, keyof Hooks & string>
|
|
19
|
+
];
|
|
20
|
+
export {};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { createHooks as baseCreateHooks } from '@css-hooks/react';
|
|
2
|
+
import { assignStyle } from 'css-in-js-utils';
|
|
3
|
+
import fallbackValuePlugin from './fallbackValuePlugin.js';
|
|
4
|
+
import getFallbackCSS from './getFallbackCSS.js';
|
|
5
|
+
export default function createRenderer({ hooks, fallbacks = [], plugins = [], mergeStyle = assignStyle, }) {
|
|
6
|
+
if (fallbacks.length > 0) {
|
|
7
|
+
plugins.unshift(fallbackValuePlugin(fallbacks));
|
|
8
|
+
}
|
|
9
|
+
const fallbackCSS = getFallbackCSS(fallbacks);
|
|
10
|
+
const [baseCSS, fn] = baseCreateHooks(hooks);
|
|
11
|
+
const staticCSS = [baseCSS, fallbackCSS].join('');
|
|
12
|
+
function css(...style) {
|
|
13
|
+
// we ignore the "Type instantiation is excessively deep and possibly infinite."
|
|
14
|
+
// @ts-ignore
|
|
15
|
+
const flattened = style.flat(Infinity);
|
|
16
|
+
const filtered = flattened.filter(Boolean);
|
|
17
|
+
const merged = mergeStyle({}, ...filtered);
|
|
18
|
+
const processed = plugins.reduce((processed, plugin) => plugin(processed), merged);
|
|
19
|
+
return fn(processed);
|
|
20
|
+
}
|
|
21
|
+
return [staticCSS, css];
|
|
22
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
// @ts-nocheck
|
|
2
|
+
import isPlainObject from 'isobject';
|
|
3
|
+
import getFallbackVariable from './getFallbackVariable.js';
|
|
4
|
+
export default function fallbackValuePlugin(fallbacks = []) {
|
|
5
|
+
const fallbackMap = fallbacks.reduce((map, { property, values, match }) => {
|
|
6
|
+
// use the last value as a default matcher if no match is provided
|
|
7
|
+
const actualMatch = match || values[values.length - 1];
|
|
8
|
+
[].concat(property).forEach((prop) => {
|
|
9
|
+
map[prop] = actualMatch;
|
|
10
|
+
});
|
|
11
|
+
return map;
|
|
12
|
+
}, {});
|
|
13
|
+
return function resolveFallbackValue(style) {
|
|
14
|
+
for (let property in style) {
|
|
15
|
+
const value = style[property];
|
|
16
|
+
if (isPlainObject(value)) {
|
|
17
|
+
style[property] = resolveFallbackValue(value);
|
|
18
|
+
}
|
|
19
|
+
else {
|
|
20
|
+
const fallback = fallbackMap[property];
|
|
21
|
+
if (fallback && fallback === value) {
|
|
22
|
+
style[property] =
|
|
23
|
+
'var(' + getFallbackVariable(property, fallback) + ')';
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
return style;
|
|
28
|
+
};
|
|
29
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { hyphenateProperty } from 'css-in-js-utils';
|
|
2
|
+
import getFallbackVariable from './getFallbackVariable.js';
|
|
3
|
+
export default function getFallbackCSS(fallbacks) {
|
|
4
|
+
const rootCSS = fallbacks.reduce((css, { property, values = [], match }) => {
|
|
5
|
+
// use the last value as a default matcher if no match is provided
|
|
6
|
+
const actualMatch = match || values[values.length - 1];
|
|
7
|
+
return (css +
|
|
8
|
+
[]
|
|
9
|
+
// @ts-ignore
|
|
10
|
+
.concat(property)
|
|
11
|
+
.map((prop) => `${getFallbackVariable(prop, actualMatch)}:;`)
|
|
12
|
+
.join(''));
|
|
13
|
+
}, '');
|
|
14
|
+
const supportsCSS = fallbacks.map(({ property, values = [], match }) => {
|
|
15
|
+
// use the last value as a default matcher if no match is provided
|
|
16
|
+
const actualMatch = match || values[values.length - 1];
|
|
17
|
+
return values
|
|
18
|
+
.map((value) => []
|
|
19
|
+
// @ts-ignore
|
|
20
|
+
.concat(property)
|
|
21
|
+
.map((prop) => `@supports (${hyphenateProperty(prop)}:${value}){:root{${getFallbackVariable(prop, actualMatch)}:${value}}}`)
|
|
22
|
+
.join(''))
|
|
23
|
+
.join('');
|
|
24
|
+
});
|
|
25
|
+
return (rootCSS ? `:root {${rootCSS}}` : '') + supportsCSS.join('');
|
|
26
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function getFallbackVariable(property: string, value: string): string;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function useCSSVariable(): [`--${string}`, string];
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export { default as createRenderer } from './core/createRenderer.js';
|
|
2
|
+
export { default as fallbackValue } from './core/fallbackValue.js';
|
|
3
|
+
export { default as responsiveValuePlugin, T_ResponsiveStyle, } from './plugins/responsiveValue.js';
|
|
4
|
+
export { default as prefixerPlugin, fallbacks as prefixerFallbacks, } from './plugins/prefixer.js';
|
|
5
|
+
export { default as debugPlugin } from './plugins/debug.js';
|
|
6
|
+
export { default as enforceLonghandPlugin } from './plugins/enforceLonghand.js';
|
|
7
|
+
export { default as sortPropertyPlugin } from './plugins/sortProperty.js';
|
|
8
|
+
export { default as useCSSVariable } from './helpers/useCSSVariable.js';
|
|
9
|
+
export { T_Fallback, T_Style } from './types.js';
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export { default as createRenderer } from './core/createRenderer.js';
|
|
2
|
+
export { default as fallbackValue } from './core/fallbackValue.js';
|
|
3
|
+
export { default as responsiveValuePlugin, } from './plugins/responsiveValue.js';
|
|
4
|
+
export { default as prefixerPlugin, fallbacks as prefixerFallbacks, } from './plugins/prefixer.js';
|
|
5
|
+
export { default as debugPlugin } from './plugins/debug.js';
|
|
6
|
+
export { default as enforceLonghandPlugin } from './plugins/enforceLonghand.js';
|
|
7
|
+
export { default as sortPropertyPlugin } from './plugins/sortProperty.js';
|
|
8
|
+
export { default as useCSSVariable } from './helpers/useCSSVariable.js';
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
declare module 'fela-plugin-bidi' {
|
|
2
|
+
import { T_Style } from '@weser/styling'
|
|
3
|
+
|
|
4
|
+
export default function bidi<T = T_Style>(
|
|
5
|
+
direction?: 'ltr' | 'rtl'
|
|
6
|
+
): (style: T) => T
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
declare module 'fela-plugin-custom-property' {
|
|
10
|
+
import { T_Style } from '@weser/styling'
|
|
11
|
+
|
|
12
|
+
export default function customProperty<P extends Record<string, any>>(
|
|
13
|
+
properties: P
|
|
14
|
+
): (
|
|
15
|
+
style: Partial<{
|
|
16
|
+
[Property in keyof P]: Parameters<P[Property]>[0]
|
|
17
|
+
}>
|
|
18
|
+
) => T_Style
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
declare module 'fela-plugin-expand-shorthand' {
|
|
22
|
+
import { T_Style } from '@weser/styling'
|
|
23
|
+
|
|
24
|
+
export default function expandShorthand<T = T_Style>(): (style: T) => T
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
declare module 'fela-plugin-extend' {
|
|
28
|
+
import { T_Style } from '@weser/styling'
|
|
29
|
+
import { WithHooks } from '@css-hooks/core'
|
|
30
|
+
|
|
31
|
+
type Extension<T, Hooks> = {
|
|
32
|
+
condition: boolean | undefined
|
|
33
|
+
style: ExtendStyle<T, Hooks>
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export type ExtendStyle<T, Hooks> = WithHooks<keyof Hooks, T> & {
|
|
37
|
+
extend?: Extension<T, Hooks> | Array<Extension<T, Hooks>>
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export default function extend<Hooks, T = T_Style>(): (
|
|
41
|
+
style: ExtendStyle<T, Hooks>
|
|
42
|
+
) => T_Style
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
declare module 'fela-plugin-hover-media' {
|
|
46
|
+
import { T_Style } from '@weser/styling'
|
|
47
|
+
|
|
48
|
+
export default function hoverMedia(): (style: T_Style) => T_Style
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
declare module 'fela-plugin-important' {
|
|
52
|
+
import { T_Style } from '@weser/styling'
|
|
53
|
+
|
|
54
|
+
export default function important(): (style: T_Style) => T_Style
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
declare module 'fela-plugin-isolation' {
|
|
58
|
+
import { T_RawStyle, T_Style } from '@weser/styling'
|
|
59
|
+
|
|
60
|
+
type Config = {
|
|
61
|
+
exclude: Array<keyof T_RawStyle>
|
|
62
|
+
}
|
|
63
|
+
export default function isolation<T = T_Style>(
|
|
64
|
+
config?: Config
|
|
65
|
+
): (style: T) => T
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
declare module 'fela-plugin-kebab-case' {
|
|
69
|
+
import { T_Style } from '@weser/styling'
|
|
70
|
+
|
|
71
|
+
export default function kebabCase<T = T_Style>(): (style: T) => T
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
declare module 'fela-plugin-logger' {
|
|
75
|
+
import { T_Style } from '@weser/styling'
|
|
76
|
+
|
|
77
|
+
export default function logger<T = T_Style>(): (style: T) => T
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
declare module 'fela-plugin-rtl' {
|
|
81
|
+
import { T_Style } from '@weser/styling'
|
|
82
|
+
|
|
83
|
+
export default function rtl<T = T_Style>(
|
|
84
|
+
direction?: 'ltr' | 'rtl'
|
|
85
|
+
): (style: T) => T
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
declare module 'fela-plugin-unit' {
|
|
89
|
+
import { T_RawStyle, T_Style } from '@weser/styling'
|
|
90
|
+
|
|
91
|
+
type Unit =
|
|
92
|
+
| 'ch'
|
|
93
|
+
| 'em'
|
|
94
|
+
| 'ex'
|
|
95
|
+
| 'rem'
|
|
96
|
+
| 'vh'
|
|
97
|
+
| 'vw'
|
|
98
|
+
| 'vmin'
|
|
99
|
+
| 'vmax'
|
|
100
|
+
| 'px'
|
|
101
|
+
| 'cm'
|
|
102
|
+
| 'mm'
|
|
103
|
+
| 'in'
|
|
104
|
+
| 'pc'
|
|
105
|
+
| 'pt'
|
|
106
|
+
| 'mozmm'
|
|
107
|
+
|
|
108
|
+
export default function unit<T = T_Style>(
|
|
109
|
+
unit?: Unit,
|
|
110
|
+
unitPerProperty?: { [P in keyof T_RawStyle]: Unit },
|
|
111
|
+
isUnitlessProperty?: (property: string) => boolean
|
|
112
|
+
): (style: T) => T
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
declare module 'fela-plugin-validator' {
|
|
116
|
+
import { T_Style } from '@weser/styling'
|
|
117
|
+
|
|
118
|
+
type Config = {
|
|
119
|
+
logInvalid?: boolean
|
|
120
|
+
deleteInvalid?: boolean
|
|
121
|
+
useCSSLint?: boolean
|
|
122
|
+
}
|
|
123
|
+
export default function validator<T = T_Style>(
|
|
124
|
+
config?: Config
|
|
125
|
+
): (style: T) => T
|
|
126
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { CreateStylesDebugger as createStylesDebugger, } from 'styles-debugger';
|
|
2
|
+
export default function debugPlugin(autoActive = true, config = {}) {
|
|
3
|
+
const debugStyle = createStylesDebugger(config);
|
|
4
|
+
return function debug(style) {
|
|
5
|
+
if (autoActive || style?.debug) {
|
|
6
|
+
const { debug, ...rest } = style;
|
|
7
|
+
return {
|
|
8
|
+
...rest,
|
|
9
|
+
...debugStyle(),
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
return style;
|
|
13
|
+
};
|
|
14
|
+
}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import sortProperty from './sortProperty.js';
|
|
2
|
+
function capitalize(str) {
|
|
3
|
+
return str.charAt(0).toUpperCase() + str.slice(1);
|
|
4
|
+
}
|
|
5
|
+
function getPropertyPriority({ borderLonghand, borderDirectional, borderDirectionalLonghand, }) {
|
|
6
|
+
const propertyPriority = {
|
|
7
|
+
marginLeft: 2,
|
|
8
|
+
marginRight: 2,
|
|
9
|
+
marginTop: 2,
|
|
10
|
+
marginBottom: 2,
|
|
11
|
+
marginInline: 2,
|
|
12
|
+
marginBlock: 2,
|
|
13
|
+
marginInlineStart: 3,
|
|
14
|
+
marginInlineEnd: 3,
|
|
15
|
+
marginBlockStart: 3,
|
|
16
|
+
marginBlockEnd: 3,
|
|
17
|
+
paddingLeft: 2,
|
|
18
|
+
paddingRight: 2,
|
|
19
|
+
paddingBottom: 2,
|
|
20
|
+
paddingTop: 2,
|
|
21
|
+
paddingInline: 2,
|
|
22
|
+
paddingBlock: 2,
|
|
23
|
+
paddingInlineStart: 3,
|
|
24
|
+
paddingInlineEnd: 3,
|
|
25
|
+
paddingBlockStart: 3,
|
|
26
|
+
paddingBlockEnd: 3,
|
|
27
|
+
flexWrap: 2,
|
|
28
|
+
flexShrink: 2,
|
|
29
|
+
flexBasis: 2,
|
|
30
|
+
backgroundColor: 2,
|
|
31
|
+
backgroundRepeat: 2,
|
|
32
|
+
backgroundPosition: 2,
|
|
33
|
+
backgroundImage: 2,
|
|
34
|
+
backgroundOrigin: 2,
|
|
35
|
+
backgroundClip: 2,
|
|
36
|
+
backgroundSize: 2,
|
|
37
|
+
transitionProperty: 2,
|
|
38
|
+
transitionTimingFunction: 2,
|
|
39
|
+
transitionDuration: 2,
|
|
40
|
+
transitionDelay: 2,
|
|
41
|
+
animationDelay: 2,
|
|
42
|
+
animationDirection: 2,
|
|
43
|
+
animationDuration: 2,
|
|
44
|
+
animationFillMode: 2,
|
|
45
|
+
animationIterationCount: 2,
|
|
46
|
+
animationName: 2,
|
|
47
|
+
animationPlayState: 2,
|
|
48
|
+
animationTimingFunction: 2,
|
|
49
|
+
borderWidth: borderLonghand,
|
|
50
|
+
borderStyle: borderLonghand,
|
|
51
|
+
borderColor: borderLonghand,
|
|
52
|
+
// these conflict with the longhands above
|
|
53
|
+
borderTop: borderDirectional,
|
|
54
|
+
borderRight: borderDirectional,
|
|
55
|
+
borderBottom: borderDirectional,
|
|
56
|
+
borderLeft: borderDirectional,
|
|
57
|
+
borderTopWidth: borderDirectionalLonghand,
|
|
58
|
+
borderTopStyle: borderDirectionalLonghand,
|
|
59
|
+
borderTopColor: borderDirectionalLonghand,
|
|
60
|
+
borderRightWidth: borderDirectionalLonghand,
|
|
61
|
+
borderRightStyle: borderDirectionalLonghand,
|
|
62
|
+
borderRightColor: borderDirectionalLonghand,
|
|
63
|
+
borderBottomWidth: borderDirectionalLonghand,
|
|
64
|
+
borderBottomStyle: borderDirectionalLonghand,
|
|
65
|
+
borderBottomColor: borderDirectionalLonghand,
|
|
66
|
+
borderLeftWidth: borderDirectionalLonghand,
|
|
67
|
+
borderLeftStyle: borderDirectionalLonghand,
|
|
68
|
+
borderLeftColor: borderDirectionalLonghand,
|
|
69
|
+
borderBottomLeftRadius: 2,
|
|
70
|
+
borderBottomRightRadius: 2,
|
|
71
|
+
borderTopLeftRadius: 2,
|
|
72
|
+
borderTopRightRadius: 2,
|
|
73
|
+
borderImageOutset: 2,
|
|
74
|
+
borderImageRepeat: 2,
|
|
75
|
+
borderImageSlice: 2,
|
|
76
|
+
borderImageSource: 2,
|
|
77
|
+
borderImageWidth: 2,
|
|
78
|
+
columnWidth: 2,
|
|
79
|
+
columnCount: 2,
|
|
80
|
+
listStyleImage: 2,
|
|
81
|
+
listStylePosition: 2,
|
|
82
|
+
listStyleType: 2,
|
|
83
|
+
outlineWidth: 2,
|
|
84
|
+
outlineStyle: 2,
|
|
85
|
+
outlineColor: 2,
|
|
86
|
+
overflowX: 2,
|
|
87
|
+
overflowY: 2,
|
|
88
|
+
textDecorationLine: 2,
|
|
89
|
+
textDecorationStyle: 2,
|
|
90
|
+
textDecorationColor: 2,
|
|
91
|
+
};
|
|
92
|
+
// Add all possible vendor prefixes to all properties
|
|
93
|
+
// prefixerPlugin converts properties to prefixed ones like `WebkitBackgroundColor`
|
|
94
|
+
return Object.entries(propertyPriority).reduce((acc, [property, priority]) => {
|
|
95
|
+
// @ts-ignore
|
|
96
|
+
acc['Webkit' + capitalize(property)] = priority;
|
|
97
|
+
return acc;
|
|
98
|
+
}, propertyPriority);
|
|
99
|
+
}
|
|
100
|
+
export default function enforceLonghandPlugin(borderMode = 'none') {
|
|
101
|
+
const propertyPriority = getPropertyPriority({
|
|
102
|
+
borderDirectional: borderMode === 'directional' ? 3 : 2,
|
|
103
|
+
borderLonghand: borderMode === 'longhand' ? 3 : 2,
|
|
104
|
+
borderDirectionalLonghand: borderMode === 'none' ? 3 : 4,
|
|
105
|
+
});
|
|
106
|
+
return sortProperty(propertyPriority);
|
|
107
|
+
}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import isObject from 'isobject';
|
|
2
|
+
function capitalize(str) {
|
|
3
|
+
return str.charAt(0).toUpperCase() + str.slice(1);
|
|
4
|
+
}
|
|
5
|
+
const w = 'Webkit';
|
|
6
|
+
const m = 'Moz';
|
|
7
|
+
const prefixes = {
|
|
8
|
+
textEmphasisPosition: w,
|
|
9
|
+
textEmphasis: w,
|
|
10
|
+
textEmphasisStyle: w,
|
|
11
|
+
textEmphasisColor: w,
|
|
12
|
+
boxDecorationBreak: w,
|
|
13
|
+
maskImage: w,
|
|
14
|
+
maskMode: w,
|
|
15
|
+
maskRepeat: w,
|
|
16
|
+
maskPosition: w,
|
|
17
|
+
maskClip: w,
|
|
18
|
+
maskOrigin: w,
|
|
19
|
+
maskSize: w,
|
|
20
|
+
maskComposite: w,
|
|
21
|
+
mask: w,
|
|
22
|
+
maskBorderSource: w,
|
|
23
|
+
maskBorderMode: w,
|
|
24
|
+
maskBorderSlice: w,
|
|
25
|
+
maskBorderWidth: w,
|
|
26
|
+
maskBorderOutset: w,
|
|
27
|
+
maskBorderRepeat: w,
|
|
28
|
+
maskBorder: w,
|
|
29
|
+
maskType: w,
|
|
30
|
+
appearance: w,
|
|
31
|
+
userSelect: w,
|
|
32
|
+
backdropFilter: w,
|
|
33
|
+
clipPath: w,
|
|
34
|
+
hyphens: w,
|
|
35
|
+
textOrientation: w,
|
|
36
|
+
tabSize: m,
|
|
37
|
+
fontKerning: w,
|
|
38
|
+
textSizeAdjust: w,
|
|
39
|
+
textDecorationStyle: w,
|
|
40
|
+
textDecorationSkip: w,
|
|
41
|
+
textDecorationLine: w,
|
|
42
|
+
textDecorationColor: w,
|
|
43
|
+
};
|
|
44
|
+
export default function prefixerPlugin() {
|
|
45
|
+
return function addVendorPrefixes(style) {
|
|
46
|
+
const prefixed = {};
|
|
47
|
+
for (const property in style) {
|
|
48
|
+
const value = style[property];
|
|
49
|
+
if (isObject(value)) {
|
|
50
|
+
// @ts-ignore
|
|
51
|
+
prefixed[property] = addVendorPrefixes(value);
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
54
|
+
// @ts-ignore
|
|
55
|
+
if (prefixes[property]) {
|
|
56
|
+
// @ts-ignore
|
|
57
|
+
prefixed[prefixes[property] + capitalize(property)] = value;
|
|
58
|
+
}
|
|
59
|
+
// @ts-ignore
|
|
60
|
+
prefixed[property] = value;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
return prefixed;
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
export const fallbacks = [
|
|
67
|
+
{
|
|
68
|
+
property: [
|
|
69
|
+
'width',
|
|
70
|
+
'minWidth',
|
|
71
|
+
'maxWidth',
|
|
72
|
+
'height',
|
|
73
|
+
'minHeight',
|
|
74
|
+
'maxHeight',
|
|
75
|
+
],
|
|
76
|
+
values: ['-webkit-min-content', 'min-content'],
|
|
77
|
+
},
|
|
78
|
+
{
|
|
79
|
+
property: [
|
|
80
|
+
'width',
|
|
81
|
+
'minWidth',
|
|
82
|
+
'maxWidth',
|
|
83
|
+
'height',
|
|
84
|
+
'minHeight',
|
|
85
|
+
'maxHeight',
|
|
86
|
+
],
|
|
87
|
+
values: ['-webkit-max-content', 'max-content'],
|
|
88
|
+
},
|
|
89
|
+
];
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { T_Style } from '../types.js';
|
|
2
|
+
type T_Responsive<T> = T | (T | undefined)[];
|
|
3
|
+
export type T_ResponsiveStyle<T = T_Style> = {
|
|
4
|
+
[P in keyof T]: T_Responsive<T[P]>;
|
|
5
|
+
};
|
|
6
|
+
export default function responsiveValuePlugin<T = T_Style>(mediaQueries: Array<string>): (style: T) => T;
|
|
7
|
+
export {};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import isPlainObject from 'isobject';
|
|
2
|
+
import { assignStyle } from 'css-in-js-utils';
|
|
3
|
+
function resolveResponsiveValues(style, mediaQueries) {
|
|
4
|
+
for (const key in style) {
|
|
5
|
+
const property = key;
|
|
6
|
+
const value = style[property];
|
|
7
|
+
if (isPlainObject(value)) {
|
|
8
|
+
// @ts-ignore
|
|
9
|
+
style[property] = resolveResponsiveValues(value, mediaQueries);
|
|
10
|
+
}
|
|
11
|
+
if (Array.isArray(value)) {
|
|
12
|
+
const [defaultValue, ...mediaValues] = value;
|
|
13
|
+
// @ts-ignore
|
|
14
|
+
style[property] = defaultValue;
|
|
15
|
+
mediaQueries.slice(0, mediaValues.length).forEach((query, index) => {
|
|
16
|
+
if (mediaValues[index] !== null && mediaValues[index] !== undefined) {
|
|
17
|
+
// @ts-ignore
|
|
18
|
+
assignStyle(style, {
|
|
19
|
+
[query]: {
|
|
20
|
+
[property]: mediaValues[index],
|
|
21
|
+
},
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
return style;
|
|
28
|
+
}
|
|
29
|
+
export default function responsiveValuePlugin(mediaQueries) {
|
|
30
|
+
return function responsiveValue(style) {
|
|
31
|
+
return resolveResponsiveValues(style, mediaQueries);
|
|
32
|
+
};
|
|
33
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import isPlainObject from 'isobject';
|
|
2
|
+
export default function sortPropertyPlugin(propertyPriority) {
|
|
3
|
+
function getPriority(property) {
|
|
4
|
+
return propertyPriority[property] || 0;
|
|
5
|
+
}
|
|
6
|
+
return function sortProperty(style) {
|
|
7
|
+
return Object.keys(style)
|
|
8
|
+
.sort((a, b) => getPriority(a) - getPriority(b))
|
|
9
|
+
.reduce((out, property) => {
|
|
10
|
+
const value = style[property];
|
|
11
|
+
if (isPlainObject(value)) {
|
|
12
|
+
return {
|
|
13
|
+
...out,
|
|
14
|
+
[property]: sortProperty(value),
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
return {
|
|
18
|
+
...out,
|
|
19
|
+
[property]: value,
|
|
20
|
+
};
|
|
21
|
+
}, {});
|
|
22
|
+
};
|
|
23
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"root":["../src/index.ts","../src/types.ts","../src/core/createrenderer.ts","../src/core/fallbackvalue.ts","../src/core/fallbackvalueplugin.ts","../src/core/getfallbackcss.ts","../src/core/getfallbackvariable.ts","../src/helpers/usecssvariable.ts","../src/modules/css-in-js-utils.d.ts","../src/modules/styles-debugger.d.ts","../src/plugins/debug.ts","../src/plugins/enforcelonghand.ts","../src/plugins/prefixer.ts","../src/plugins/responsivevalue.ts","../src/plugins/sortproperty.ts"],"version":"5.9.2"}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { CSSProperties } from 'react';
|
|
2
|
+
export type T_Fallback = {
|
|
3
|
+
property: string | Array<string>;
|
|
4
|
+
values: Array<string>;
|
|
5
|
+
match?: string;
|
|
6
|
+
};
|
|
7
|
+
type T_VariableStyle = {
|
|
8
|
+
[key: `--${string}`]: string | number;
|
|
9
|
+
};
|
|
10
|
+
type T_RawStyle = CSSProperties;
|
|
11
|
+
export type T_Style = T_RawStyle & T_VariableStyle;
|
|
12
|
+
export {};
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/package.json
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@weser/styling",
|
|
3
|
+
"version": "0.0.9",
|
|
4
|
+
"description": "Utils for styling with CSS hooks",
|
|
5
|
+
"author": "Robin Weser <robin@weser.io>",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"homepage": "https://github.com/robinweser/weser.git",
|
|
8
|
+
"repository": "https://github.com/robinweser/weser.git",
|
|
9
|
+
"type": "module",
|
|
10
|
+
"main": "dist/index.js",
|
|
11
|
+
"module": "dist/index.js",
|
|
12
|
+
"types": "dist/index.d.ts",
|
|
13
|
+
"sideEffects": false,
|
|
14
|
+
"publishConfig": {
|
|
15
|
+
"access": "public"
|
|
16
|
+
},
|
|
17
|
+
"files": [
|
|
18
|
+
"LICENSE",
|
|
19
|
+
"README.md",
|
|
20
|
+
"dist/**"
|
|
21
|
+
],
|
|
22
|
+
"browserslist": [
|
|
23
|
+
"IE >= 11",
|
|
24
|
+
"Firefox >= 60",
|
|
25
|
+
"Safari >= 11.1",
|
|
26
|
+
"Chrome >= 66",
|
|
27
|
+
"ChromeAndroid >= 66",
|
|
28
|
+
"iOS >= 11.3",
|
|
29
|
+
"Edge >= 15"
|
|
30
|
+
],
|
|
31
|
+
"scripts": {
|
|
32
|
+
"setup": "pnpm build",
|
|
33
|
+
"clean": "rimraf dist",
|
|
34
|
+
"build": "tsc -b",
|
|
35
|
+
"dev": "pnpm build -w",
|
|
36
|
+
"test": "echo 1"
|
|
37
|
+
},
|
|
38
|
+
"keywords": [],
|
|
39
|
+
"dependencies": {
|
|
40
|
+
"css-in-js-utils": "^3.1.0",
|
|
41
|
+
"isobject": "^4.0.0"
|
|
42
|
+
},
|
|
43
|
+
"peerDependencies": {
|
|
44
|
+
"@css-hooks/core": "^1.0.0",
|
|
45
|
+
"@css-hooks/react": "^1.0.0"
|
|
46
|
+
},
|
|
47
|
+
"optionalDependencies": {
|
|
48
|
+
"styles-debugger": "^1.0.0"
|
|
49
|
+
},
|
|
50
|
+
"devDependencies": {
|
|
51
|
+
"@css-hooks/core": "1.8.2",
|
|
52
|
+
"@css-hooks/react": "1.8.2",
|
|
53
|
+
"@types/react": "18.2.55",
|
|
54
|
+
"ava": "^6.1.3",
|
|
55
|
+
"react": "^19.1.0",
|
|
56
|
+
"rimraf": "^3.0.2",
|
|
57
|
+
"styles-debugger": "^1.0.0",
|
|
58
|
+
"typescript": "^5.9.2"
|
|
59
|
+
},
|
|
60
|
+
"gitHead": "abbfb42cee4e8bdbbd870bd1086ebc65b6074584"
|
|
61
|
+
}
|