@momo-webplatform/mobase 0.0.22 → 0.0.23
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/package.json +2 -2
- package/publish/cjs/mobase-tw-plugin/font-sizes.js +98 -0
- package/publish/cjs/mobase-tw-plugin/layout.js +37 -0
- package/publish/cjs/mobase-tw-plugin/plugin.js +61 -17
- package/publish/cjs/mobase-tw-plugin/radius.js +16 -0
- package/publish/cjs/mobase-tw-plugin/types.js +54 -0
- package/publish/cjs/mobase-tw-plugin/utils/object.js +36 -17
- package/publish/cjs/mobase-tw-plugin/utils/theme.js +70 -0
- package/publish/cjs/tsconfig.lib.tsbuildinfo +1 -1
- package/publish/esm/mobase-tw-plugin/{foundation/font-sizes/index.d.ts → font-sizes.d.ts} +1 -1
- package/publish/esm/mobase-tw-plugin/font-sizes.js +94 -0
- package/publish/esm/mobase-tw-plugin/layout.d.ts +34 -0
- package/publish/esm/mobase-tw-plugin/layout.js +34 -0
- package/publish/esm/mobase-tw-plugin/plugin.js +58 -14
- package/publish/esm/mobase-tw-plugin/radius.d.ts +9 -0
- package/publish/esm/mobase-tw-plugin/radius.js +12 -0
- package/publish/esm/mobase-tw-plugin/types.d.ts +103 -0
- package/publish/esm/mobase-tw-plugin/types.js +51 -0
- package/publish/esm/mobase-tw-plugin/utils/object.d.ts +3 -18
- package/publish/esm/mobase-tw-plugin/utils/object.js +30 -15
- package/publish/esm/mobase-tw-plugin/utils/theme.d.ts +2 -0
- package/publish/esm/mobase-tw-plugin/utils/theme.js +65 -0
- package/publish/esm/tsconfig.lib.tsbuildinfo +1 -1
- package/publish/cjs/mobase-tw-plugin/foundation/font-sizes/index.js +0 -94
- package/publish/cjs/mobase-tw-plugin/foundation/index.js +0 -20
- package/publish/cjs/mobase-tw-plugin/foundation/shadows/index.js +0 -12
- package/publish/esm/mobase-tw-plugin/foundation/font-sizes/index.js +0 -91
- package/publish/esm/mobase-tw-plugin/foundation/index.d.ts +0 -4
- package/publish/esm/mobase-tw-plugin/foundation/index.js +0 -4
- package/publish/esm/mobase-tw-plugin/foundation/shadows/index.d.ts +0 -10
- package/publish/esm/mobase-tw-plugin/foundation/shadows/index.js +0 -9
- /package/publish/cjs/mobase-tw-plugin/{foundation/animations → animations}/index.js +0 -0
- /package/publish/cjs/mobase-tw-plugin/{foundation/colors → colors}/blue.js +0 -0
- /package/publish/cjs/mobase-tw-plugin/{foundation/colors → colors}/common.js +0 -0
- /package/publish/cjs/mobase-tw-plugin/{foundation/colors → colors}/gray.js +0 -0
- /package/publish/cjs/mobase-tw-plugin/{foundation/colors → colors}/green.js +0 -0
- /package/publish/cjs/mobase-tw-plugin/{foundation/colors → colors}/index.js +0 -0
- /package/publish/cjs/mobase-tw-plugin/{foundation/colors → colors}/orange.js +0 -0
- /package/publish/cjs/mobase-tw-plugin/{foundation/colors → colors}/pink.js +0 -0
- /package/publish/cjs/mobase-tw-plugin/{foundation/colors → colors}/purple.js +0 -0
- /package/publish/cjs/mobase-tw-plugin/{foundation/colors → colors}/red.js +0 -0
- /package/publish/cjs/mobase-tw-plugin/{foundation/colors → colors}/yellow.js +0 -0
- /package/publish/esm/mobase-tw-plugin/{foundation/animations → animations}/index.d.ts +0 -0
- /package/publish/esm/mobase-tw-plugin/{foundation/animations → animations}/index.js +0 -0
- /package/publish/esm/mobase-tw-plugin/{foundation/colors → colors}/blue.d.ts +0 -0
- /package/publish/esm/mobase-tw-plugin/{foundation/colors → colors}/blue.js +0 -0
- /package/publish/esm/mobase-tw-plugin/{foundation/colors → colors}/common.d.ts +0 -0
- /package/publish/esm/mobase-tw-plugin/{foundation/colors → colors}/common.js +0 -0
- /package/publish/esm/mobase-tw-plugin/{foundation/colors → colors}/gray.d.ts +0 -0
- /package/publish/esm/mobase-tw-plugin/{foundation/colors → colors}/gray.js +0 -0
- /package/publish/esm/mobase-tw-plugin/{foundation/colors → colors}/green.d.ts +0 -0
- /package/publish/esm/mobase-tw-plugin/{foundation/colors → colors}/green.js +0 -0
- /package/publish/esm/mobase-tw-plugin/{foundation/colors → colors}/index.d.ts +0 -0
- /package/publish/esm/mobase-tw-plugin/{foundation/colors → colors}/index.js +0 -0
- /package/publish/esm/mobase-tw-plugin/{foundation/colors → colors}/orange.d.ts +0 -0
- /package/publish/esm/mobase-tw-plugin/{foundation/colors → colors}/orange.js +0 -0
- /package/publish/esm/mobase-tw-plugin/{foundation/colors → colors}/pink.d.ts +0 -0
- /package/publish/esm/mobase-tw-plugin/{foundation/colors → colors}/pink.js +0 -0
- /package/publish/esm/mobase-tw-plugin/{foundation/colors → colors}/purple.d.ts +0 -0
- /package/publish/esm/mobase-tw-plugin/{foundation/colors → colors}/purple.js +0 -0
- /package/publish/esm/mobase-tw-plugin/{foundation/colors → colors}/red.d.ts +0 -0
- /package/publish/esm/mobase-tw-plugin/{foundation/colors → colors}/red.js +0 -0
- /package/publish/esm/mobase-tw-plugin/{foundation/colors → colors}/yellow.d.ts +0 -0
- /package/publish/esm/mobase-tw-plugin/{foundation/colors → colors}/yellow.js +0 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@momo-webplatform/mobase",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.23",
|
|
4
4
|
"description": "Mobase is the UI framework upon we build product experiences at MoMo.vn, base on Radix primitives, and Tailwind CSS.",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"dev": "next dev",
|
|
@@ -65,12 +65,12 @@
|
|
|
65
65
|
"class-variance-authority": "^0.7.0",
|
|
66
66
|
"clsx": "^2.1.0",
|
|
67
67
|
"cmdk": "^0.2.0",
|
|
68
|
+
"color": "^4.2.3",
|
|
68
69
|
"date-fns": "^3.2.0",
|
|
69
70
|
"deepmerge": "^4.3.1",
|
|
70
71
|
"dlv": "^1.1.3",
|
|
71
72
|
"flat": "^3.0.1",
|
|
72
73
|
"framer-motion": "^11.0.3",
|
|
73
|
-
"fs": "0.0.1-security",
|
|
74
74
|
"lodash": "^4.17.21",
|
|
75
75
|
"lodash.foreach": "^4.5.0",
|
|
76
76
|
"lodash.omit": "^4.5.0",
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.fontSizes = void 0;
|
|
4
|
+
function fontSizes(prefix) {
|
|
5
|
+
const fontSizes = {
|
|
6
|
+
xxs: [
|
|
7
|
+
`var(--${prefix}-font-size-xxs)`,
|
|
8
|
+
{
|
|
9
|
+
lineHeight: "1rem",
|
|
10
|
+
},
|
|
11
|
+
],
|
|
12
|
+
xs: [
|
|
13
|
+
`var(--${prefix}-font-size-xs)`,
|
|
14
|
+
{
|
|
15
|
+
lineHeight: "1rem",
|
|
16
|
+
},
|
|
17
|
+
],
|
|
18
|
+
sm: [
|
|
19
|
+
`var(--${prefix}-font-size-sm)`,
|
|
20
|
+
{
|
|
21
|
+
lineHeight: "1.25rem",
|
|
22
|
+
},
|
|
23
|
+
],
|
|
24
|
+
base: [
|
|
25
|
+
`var(--${prefix}-font-size-base)`,
|
|
26
|
+
{
|
|
27
|
+
lineHeight: "1.5rem",
|
|
28
|
+
},
|
|
29
|
+
],
|
|
30
|
+
lg: [
|
|
31
|
+
`var(--${prefix}-font-size-lg)`,
|
|
32
|
+
{
|
|
33
|
+
lineHeight: "1.75rem",
|
|
34
|
+
},
|
|
35
|
+
],
|
|
36
|
+
xl: [
|
|
37
|
+
`var(--${prefix}-font-size-xl)`,
|
|
38
|
+
{
|
|
39
|
+
lineHeight: "1.75rem",
|
|
40
|
+
},
|
|
41
|
+
],
|
|
42
|
+
"2xl": [
|
|
43
|
+
`var(--${prefix}-font-size-2xl)`,
|
|
44
|
+
{
|
|
45
|
+
lineHeight: "2rem",
|
|
46
|
+
},
|
|
47
|
+
],
|
|
48
|
+
"3xl": [
|
|
49
|
+
`var(--${prefix}-font-size-3xl)`,
|
|
50
|
+
{
|
|
51
|
+
lineHeight: "2.25rem",
|
|
52
|
+
},
|
|
53
|
+
],
|
|
54
|
+
"4xl": [
|
|
55
|
+
`var(--${prefix}-font-size-4xl)`,
|
|
56
|
+
{
|
|
57
|
+
lineHeight: "2.5rem",
|
|
58
|
+
},
|
|
59
|
+
],
|
|
60
|
+
"5xl": [
|
|
61
|
+
`var(--${prefix}-font-size-5xl)`,
|
|
62
|
+
{
|
|
63
|
+
lineHeight: "3.5rem",
|
|
64
|
+
letterSpacing: "-0.075rem",
|
|
65
|
+
},
|
|
66
|
+
],
|
|
67
|
+
"6xl": [
|
|
68
|
+
`var(--${prefix}-font-size-6xl)`,
|
|
69
|
+
{
|
|
70
|
+
lineHeight: "4.5rem",
|
|
71
|
+
letterSpacing: "-0.09375rem",
|
|
72
|
+
},
|
|
73
|
+
],
|
|
74
|
+
"7xl": [
|
|
75
|
+
`var(--${prefix}-font-size-7xl)`,
|
|
76
|
+
{
|
|
77
|
+
lineHeight: "5rem",
|
|
78
|
+
letterSpacing: "-0.1125rem",
|
|
79
|
+
},
|
|
80
|
+
],
|
|
81
|
+
"8xl": [
|
|
82
|
+
`var(--${prefix}-font-size-8xl)`,
|
|
83
|
+
{
|
|
84
|
+
lineHeight: "6.5rem",
|
|
85
|
+
letterSpacing: "-0.15rem",
|
|
86
|
+
},
|
|
87
|
+
],
|
|
88
|
+
"9xl": [
|
|
89
|
+
`var(--${prefix}-font-size-9xl)`,
|
|
90
|
+
{
|
|
91
|
+
lineHeight: "8rem",
|
|
92
|
+
letterSpacing: "-0.2rem",
|
|
93
|
+
},
|
|
94
|
+
],
|
|
95
|
+
};
|
|
96
|
+
return fontSizes;
|
|
97
|
+
}
|
|
98
|
+
exports.fontSizes = fontSizes;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.layout = void 0;
|
|
4
|
+
exports.layout = {
|
|
5
|
+
"spacing-unit": 4,
|
|
6
|
+
"disabled-opacity": 0.5, // Numeric values don't need quotes
|
|
7
|
+
"font-size": {
|
|
8
|
+
xxs: "0.625rem",
|
|
9
|
+
xs: "0.75rem",
|
|
10
|
+
sm: "0.875rem",
|
|
11
|
+
base: "1rem",
|
|
12
|
+
lg: "1.125rem",
|
|
13
|
+
xl: "1.25rem",
|
|
14
|
+
"2xl": "1.5rem",
|
|
15
|
+
"3xl": "1.875rem",
|
|
16
|
+
"4xl": "2.25rem",
|
|
17
|
+
"5xl": "3rem",
|
|
18
|
+
"6xl": "3.75rem",
|
|
19
|
+
"7xl": "4.5rem",
|
|
20
|
+
"8xl": "6rem",
|
|
21
|
+
"9xl": "8rem",
|
|
22
|
+
},
|
|
23
|
+
radius: {
|
|
24
|
+
sm: "0.125rem",
|
|
25
|
+
base: "0.25rem",
|
|
26
|
+
md: "0.375rem",
|
|
27
|
+
lg: "0.5rem",
|
|
28
|
+
xl: "0.75rem",
|
|
29
|
+
"2xl": "1rem",
|
|
30
|
+
"3xl": "1.5rem",
|
|
31
|
+
},
|
|
32
|
+
"box-shadow": {
|
|
33
|
+
small: "0px 0px 5px 0px rgb(0 0 0 / 0.02), 0px 2px 10px 0px rgb(0 0 0 / 0.06), 0px 0px 1px 0px rgb(0 0 0 / 0.3)",
|
|
34
|
+
medium: "0px 0px 15px 0px rgb(0 0 0 / 0.03), 0px 2px 30px 0px rgb(0 0 0 / 0.08), 0px 0px 1px 0px rgb(0 0 0 / 0.3)",
|
|
35
|
+
large: "0px 0px 30px 0px rgb(0 0 0 / 0.04), 0px 30px 60px 0px rgb(0 0 0 / 0.12), 0px 0px 1px 0px rgb(0 0 0 / 0.3)",
|
|
36
|
+
},
|
|
37
|
+
};
|
|
@@ -16,27 +16,32 @@ exports.mobaseTW = void 0;
|
|
|
16
16
|
const color_1 = __importDefault(require("color"));
|
|
17
17
|
const plugin_js_1 = __importDefault(require("tailwindcss/plugin.js"));
|
|
18
18
|
const utilities_1 = require("./utilities");
|
|
19
|
-
const
|
|
20
|
-
const
|
|
21
|
-
const
|
|
22
|
-
const
|
|
23
|
-
const
|
|
19
|
+
const object_1 = require("./utils/object");
|
|
20
|
+
const theme_1 = require("./utils/theme");
|
|
21
|
+
const colors_1 = require("./colors");
|
|
22
|
+
const layout_1 = require("./layout");
|
|
23
|
+
const animations_1 = require("./animations");
|
|
24
|
+
const font_sizes_1 = require("./font-sizes");
|
|
25
|
+
const radius_1 = require("./radius");
|
|
26
|
+
// import { animations } from "./animations";
|
|
27
|
+
// import { fontSizes } from "./font-sizes";
|
|
28
|
+
// import { radius } from "./radius";
|
|
29
|
+
const resolveConfig = (prefix) => {
|
|
24
30
|
const resolved = {
|
|
25
31
|
utilities: {},
|
|
26
32
|
colors: {},
|
|
27
33
|
};
|
|
28
|
-
const flatColors = (0,
|
|
34
|
+
const flatColors = (0, object_1.flattenThemeObject)(colors_1.colors);
|
|
35
|
+
const flatLayout = layout_1.layout;
|
|
29
36
|
const cssSelector = ":root";
|
|
30
37
|
resolved.utilities[cssSelector] = {};
|
|
31
|
-
|
|
38
|
+
// Color
|
|
39
|
+
Object.entries(flatColors).forEach(([colorName, colorValue]) => {
|
|
32
40
|
if (!colorValue)
|
|
33
41
|
return;
|
|
34
42
|
try {
|
|
35
|
-
const
|
|
36
|
-
|
|
37
|
-
parsedColorsCache[colorValue] = parsedColor;
|
|
38
|
-
const [r, g, b] = parsedColor;
|
|
39
|
-
const colorVar = `--${colorName}`;
|
|
43
|
+
const [r, g, b] = (0, color_1.default)(colorValue).rgb().array();
|
|
44
|
+
const colorVar = `--${prefix}-${colorName}`;
|
|
40
45
|
// Set the css variable in "@layer utilities"
|
|
41
46
|
resolved.utilities[cssSelector][colorVar] = `${r} ${g} ${b}`;
|
|
42
47
|
resolved.colors[colorName] = `rgb(var(${colorVar}) / <alpha-value>)`;
|
|
@@ -46,10 +51,37 @@ const resolveConfig = () => {
|
|
|
46
51
|
console.log("error", error?.message);
|
|
47
52
|
}
|
|
48
53
|
});
|
|
54
|
+
// Layout
|
|
55
|
+
Object.entries(flatLayout).forEach(([key, value]) => {
|
|
56
|
+
if (!value)
|
|
57
|
+
return;
|
|
58
|
+
const layoutVariablePrefix = `--${prefix}-${key}`;
|
|
59
|
+
if (typeof value === "object") {
|
|
60
|
+
Object.entries(value).forEach(([nestedKey, nestedValue]) => {
|
|
61
|
+
const nestedLayoutVariable = `${layoutVariablePrefix}-${nestedKey}`;
|
|
62
|
+
resolved.utilities[cssSelector][nestedLayoutVariable] = nestedValue;
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
else if (key === "spacing-unit") {
|
|
66
|
+
resolved.utilities[cssSelector][layoutVariablePrefix] = value;
|
|
67
|
+
const spacingScale = (0, theme_1.generateSpacingScale)(Number(value));
|
|
68
|
+
Object.entries(spacingScale).forEach(([scaleKey, scaleValue]) => {
|
|
69
|
+
const spacingVariable = `${layoutVariablePrefix}-${scaleKey}`;
|
|
70
|
+
resolved.utilities[cssSelector][spacingVariable] = scaleValue;
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
else {
|
|
74
|
+
const formattedValue = layoutVariablePrefix.includes("opacity") && typeof value === "number"
|
|
75
|
+
? value.toString().replace(/^0\./, ".")
|
|
76
|
+
: value;
|
|
77
|
+
resolved.utilities[cssSelector][layoutVariablePrefix] = formattedValue;
|
|
78
|
+
}
|
|
79
|
+
});
|
|
49
80
|
return resolved;
|
|
50
81
|
};
|
|
51
82
|
const mobaseTW = () => {
|
|
52
|
-
const
|
|
83
|
+
const prefix = "mobase";
|
|
84
|
+
const resolved = resolveConfig(prefix);
|
|
53
85
|
return (0, plugin_js_1.default)(({ addBase, addUtilities }) => {
|
|
54
86
|
addBase({
|
|
55
87
|
":root": {
|
|
@@ -67,16 +99,28 @@ const mobaseTW = () => {
|
|
|
67
99
|
theme: {
|
|
68
100
|
extend: {
|
|
69
101
|
colors: {
|
|
70
|
-
...
|
|
102
|
+
...colors_1.colors,
|
|
71
103
|
...resolved?.colors,
|
|
72
104
|
},
|
|
73
105
|
boxShadow: {
|
|
74
|
-
|
|
106
|
+
small: `var(--${prefix}-box-shadow-small)`,
|
|
107
|
+
medium: `var(--${prefix}-box-shadow-medium)`,
|
|
108
|
+
large: `var(--${prefix}-box-shadow-large)`,
|
|
109
|
+
},
|
|
110
|
+
// fontSize: {
|
|
111
|
+
// ...fontSizes,
|
|
112
|
+
// },
|
|
113
|
+
borderRadius: {
|
|
114
|
+
...(0, radius_1.radius)(prefix),
|
|
75
115
|
},
|
|
76
116
|
fontSize: {
|
|
77
|
-
...
|
|
117
|
+
...(0, font_sizes_1.fontSizes)(prefix),
|
|
118
|
+
},
|
|
119
|
+
spacing: {
|
|
120
|
+
unit: `var(--${prefix}-spacing-unit)`,
|
|
121
|
+
...(0, theme_1.createSpacingUnits)(prefix),
|
|
78
122
|
},
|
|
79
|
-
...
|
|
123
|
+
...animations_1.animations,
|
|
80
124
|
},
|
|
81
125
|
},
|
|
82
126
|
});
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.radius = void 0;
|
|
4
|
+
function radius(prefix) {
|
|
5
|
+
const radius = {
|
|
6
|
+
sm: `var(--${prefix}-radius-sm)`,
|
|
7
|
+
DEFAULT: `var(--${prefix}-radius-base)`,
|
|
8
|
+
md: `var(--${prefix}-radius-md)`,
|
|
9
|
+
lg: `var(--${prefix}-radius-lg)`,
|
|
10
|
+
xl: `var(--${prefix}-radius-xl)`,
|
|
11
|
+
"2xl": `var(--${prefix}-radius-2xl)`,
|
|
12
|
+
"3xl": `var(--${prefix}-radius-3xl)`,
|
|
13
|
+
};
|
|
14
|
+
return radius;
|
|
15
|
+
}
|
|
16
|
+
exports.radius = radius;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.mappedSpacingScaleKeys = exports.spacingScaleKeys = void 0;
|
|
4
|
+
exports.spacingScaleKeys = [
|
|
5
|
+
"0",
|
|
6
|
+
"xs",
|
|
7
|
+
"sm",
|
|
8
|
+
"md",
|
|
9
|
+
"lg",
|
|
10
|
+
"xl",
|
|
11
|
+
"2xl",
|
|
12
|
+
"3xl",
|
|
13
|
+
"4xl",
|
|
14
|
+
"5xl",
|
|
15
|
+
"6xl",
|
|
16
|
+
"7xl",
|
|
17
|
+
"8xl",
|
|
18
|
+
"9xl",
|
|
19
|
+
"1",
|
|
20
|
+
"2",
|
|
21
|
+
"3",
|
|
22
|
+
"3.5",
|
|
23
|
+
"4",
|
|
24
|
+
"5",
|
|
25
|
+
"6",
|
|
26
|
+
"7",
|
|
27
|
+
"8",
|
|
28
|
+
"9",
|
|
29
|
+
"10",
|
|
30
|
+
"11",
|
|
31
|
+
"12",
|
|
32
|
+
"13",
|
|
33
|
+
"14",
|
|
34
|
+
"15",
|
|
35
|
+
"16",
|
|
36
|
+
"17",
|
|
37
|
+
"18",
|
|
38
|
+
"20",
|
|
39
|
+
"24",
|
|
40
|
+
"28",
|
|
41
|
+
"32",
|
|
42
|
+
"36",
|
|
43
|
+
"40",
|
|
44
|
+
"44",
|
|
45
|
+
"48",
|
|
46
|
+
"52",
|
|
47
|
+
"56",
|
|
48
|
+
"60",
|
|
49
|
+
"64",
|
|
50
|
+
"72",
|
|
51
|
+
"80",
|
|
52
|
+
"96",
|
|
53
|
+
];
|
|
54
|
+
exports.mappedSpacingScaleKeys = exports.spacingScaleKeys.map((key) => `unit-${key}`);
|
|
@@ -1,23 +1,44 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.flattenThemeObject = exports.
|
|
4
|
-
const flat_1 = require("flat");
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
const
|
|
12
|
-
|
|
13
|
-
|
|
6
|
+
exports.flattenThemeObject = exports.removeDefaultKeys = exports.swapColorValues = void 0;
|
|
7
|
+
const flat_1 = __importDefault(require("flat"));
|
|
8
|
+
function swapColorValues(colors) {
|
|
9
|
+
const swappedColors = {};
|
|
10
|
+
const keys = Object.keys(colors);
|
|
11
|
+
const length = keys.length;
|
|
12
|
+
for (let i = 0; i < length / 2; i++) {
|
|
13
|
+
const key1 = keys[i];
|
|
14
|
+
const key2 = keys[length - 1 - i];
|
|
15
|
+
// @ts-ignore
|
|
16
|
+
swappedColors[key1] = colors[key2];
|
|
17
|
+
// @ts-ignore
|
|
18
|
+
swappedColors[key2] = colors[key1];
|
|
19
|
+
}
|
|
20
|
+
if (length % 2 !== 0) {
|
|
21
|
+
const middleKey = keys[Math.floor(length / 2)];
|
|
22
|
+
// @ts-ignore
|
|
23
|
+
swappedColors[middleKey] = colors[middleKey];
|
|
24
|
+
}
|
|
25
|
+
return swappedColors;
|
|
26
|
+
}
|
|
27
|
+
exports.swapColorValues = swapColorValues;
|
|
28
|
+
function removeDefaultKeys(obj) {
|
|
14
29
|
const newObj = {};
|
|
15
30
|
for (const key in obj) {
|
|
16
|
-
|
|
17
|
-
|
|
31
|
+
if (key.endsWith("-DEFAULT")) {
|
|
32
|
+
// @ts-ignore
|
|
33
|
+
newObj[key.replace("-DEFAULT", "")] = obj[key];
|
|
34
|
+
continue;
|
|
35
|
+
}
|
|
36
|
+
// @ts-ignore
|
|
37
|
+
newObj[key] = obj[key];
|
|
18
38
|
}
|
|
19
39
|
return newObj;
|
|
20
|
-
}
|
|
40
|
+
}
|
|
41
|
+
exports.removeDefaultKeys = removeDefaultKeys;
|
|
21
42
|
/**
|
|
22
43
|
*
|
|
23
44
|
* Flatten theme object and remove default keys
|
|
@@ -25,9 +46,7 @@ const removeDefaultKeys = (obj) => {
|
|
|
25
46
|
* @param obj theme object
|
|
26
47
|
* @returns object with flattened keys
|
|
27
48
|
*/
|
|
28
|
-
const flattenThemeObject = (obj) => removeDefaultKeys(
|
|
29
|
-
// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
|
|
30
|
-
(0, flat_1.flatten)(obj, {
|
|
49
|
+
const flattenThemeObject = (obj) => removeDefaultKeys((0, flat_1.default)(obj, {
|
|
31
50
|
safe: true,
|
|
32
51
|
delimiter: "-",
|
|
33
52
|
}));
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createSpacingUnits = exports.generateSpacingScale = void 0;
|
|
4
|
+
const types_1 = require("../types");
|
|
5
|
+
/**
|
|
6
|
+
* Determines if the theme is a base theme
|
|
7
|
+
*
|
|
8
|
+
* @param theme string
|
|
9
|
+
* @returns "light" | "dark
|
|
10
|
+
*/
|
|
11
|
+
const ROOT_FONT_SIZE = 16;
|
|
12
|
+
const baseScale = [
|
|
13
|
+
0.5, 1, 1.5, 2, 2.5, 3, 3.5, 4, 5, 6, 7, 8, 9, 10, 11, 12, 14, 16, 18,
|
|
14
|
+
];
|
|
15
|
+
const extendedScale = [
|
|
16
|
+
20, 24, 28, 32, 36, 40, 44, 48, 52, 56, 60, 64, 72, 80, 96,
|
|
17
|
+
];
|
|
18
|
+
const generateSpacingScale = (spacingUnit) => {
|
|
19
|
+
const scaleLabels = {
|
|
20
|
+
xs: 2,
|
|
21
|
+
sm: 3,
|
|
22
|
+
md: 4,
|
|
23
|
+
lg: 5.5,
|
|
24
|
+
xl: 9,
|
|
25
|
+
"2xl": 12,
|
|
26
|
+
"3xl": 20,
|
|
27
|
+
"4xl": 30,
|
|
28
|
+
"5xl": 56,
|
|
29
|
+
"6xl": 72,
|
|
30
|
+
"7xl": 96,
|
|
31
|
+
"8xl": 128,
|
|
32
|
+
"9xl": 160,
|
|
33
|
+
};
|
|
34
|
+
const scale = { 0: "0px" };
|
|
35
|
+
Object.entries(scaleLabels).forEach(([label, multiplier]) => {
|
|
36
|
+
scale[label] = multiplier
|
|
37
|
+
? `${(spacingUnit * multiplier) / ROOT_FONT_SIZE}rem`
|
|
38
|
+
: `${spacingUnit / ROOT_FONT_SIZE}rem`;
|
|
39
|
+
});
|
|
40
|
+
baseScale.forEach((i) => {
|
|
41
|
+
let key = `${i}`;
|
|
42
|
+
// if the key has decimal e.g 3.5 change it to "3-5" format
|
|
43
|
+
if (key.includes(".")) {
|
|
44
|
+
const [first, second] = key.split(".");
|
|
45
|
+
key = `${first}_${second}`;
|
|
46
|
+
}
|
|
47
|
+
scale[key] = `${(spacingUnit * i) / ROOT_FONT_SIZE}rem`;
|
|
48
|
+
});
|
|
49
|
+
extendedScale.forEach((i) => {
|
|
50
|
+
const key = `${i}`;
|
|
51
|
+
scale[key] = `${(spacingUnit * i) / ROOT_FONT_SIZE}rem`;
|
|
52
|
+
});
|
|
53
|
+
return scale;
|
|
54
|
+
};
|
|
55
|
+
exports.generateSpacingScale = generateSpacingScale;
|
|
56
|
+
function createSpacingUnits(prefix) {
|
|
57
|
+
const result = types_1.spacingScaleKeys.reduce((acc, key) => {
|
|
58
|
+
let value = `var(--${prefix}-spacing-unit-${key})`;
|
|
59
|
+
if (key.includes(".")) {
|
|
60
|
+
const [first, second] = key.split(".");
|
|
61
|
+
value = `var(--${prefix}-spacing-unit-${first}_${second})`;
|
|
62
|
+
}
|
|
63
|
+
return {
|
|
64
|
+
...acc,
|
|
65
|
+
[`${key}`]: value,
|
|
66
|
+
};
|
|
67
|
+
}, {});
|
|
68
|
+
return result;
|
|
69
|
+
}
|
|
70
|
+
exports.createSpacingUnits = createSpacingUnits;
|