forked from csstools/postcss-plugins
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.ts
More file actions
46 lines (38 loc) · 1.31 KB
/
Copy pathindex.ts
File metadata and controls
46 lines (38 loc) · 1.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import type { PluginCreator } from 'postcss';
import { DirectionFlow } from './lib/types';
import { transformAxes } from './lib/transform-axes';
export type { DirectionFlow } from './lib/types';
/** postcss-logical-overscroll-behavior plugin options */
export type pluginOptions = {
/** Sets the direction for inline. default: left-to-right */
inlineDirection?: DirectionFlow,
};
const creator: PluginCreator<pluginOptions> = (opts?: pluginOptions) => {
const options = Object.assign(
// Default options
{
inlineDirection: DirectionFlow.LeftToRight,
},
// Provided options
opts,
);
switch (options.inlineDirection) {
case DirectionFlow.LeftToRight:
case DirectionFlow.RightToLeft:
case DirectionFlow.TopToBottom:
case DirectionFlow.BottomToTop:
break;
default:
throw new Error(`[postcss-logical-viewport-units] "inlineDirection" must be one of ${Object.values(DirectionFlow).join(', ')}`);
}
const isHorizontal = [DirectionFlow.LeftToRight, DirectionFlow.RightToLeft].includes(options.inlineDirection);
return {
postcssPlugin: 'postcss-logical-overscroll-behavior',
Declaration: {
'overscroll-behavior-block': (decl) => transformAxes(decl, isHorizontal),
'overscroll-behavior-inline': (decl) => transformAxes(decl, isHorizontal),
},
};
};
creator.postcss = true;
export default creator;