@momo-webplatform/mobase 0.0.21 → 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.
Files changed (64) hide show
  1. package/package.json +2 -4
  2. package/publish/cjs/mobase-tw-plugin/font-sizes.js +98 -0
  3. package/publish/cjs/mobase-tw-plugin/layout.js +37 -0
  4. package/publish/cjs/mobase-tw-plugin/plugin.js +61 -17
  5. package/publish/cjs/mobase-tw-plugin/radius.js +16 -0
  6. package/publish/cjs/mobase-tw-plugin/types.js +54 -0
  7. package/publish/cjs/mobase-tw-plugin/utils/object.js +36 -17
  8. package/publish/cjs/mobase-tw-plugin/utils/theme.js +70 -0
  9. package/publish/cjs/tsconfig.lib.tsbuildinfo +1 -1
  10. package/publish/esm/mobase-tw-plugin/{foundation/font-sizes/index.d.ts → font-sizes.d.ts} +1 -1
  11. package/publish/esm/mobase-tw-plugin/font-sizes.js +94 -0
  12. package/publish/esm/mobase-tw-plugin/layout.d.ts +34 -0
  13. package/publish/esm/mobase-tw-plugin/layout.js +34 -0
  14. package/publish/esm/mobase-tw-plugin/plugin.js +58 -14
  15. package/publish/esm/mobase-tw-plugin/radius.d.ts +9 -0
  16. package/publish/esm/mobase-tw-plugin/radius.js +12 -0
  17. package/publish/esm/mobase-tw-plugin/types.d.ts +103 -0
  18. package/publish/esm/mobase-tw-plugin/types.js +51 -0
  19. package/publish/esm/mobase-tw-plugin/utils/object.d.ts +3 -18
  20. package/publish/esm/mobase-tw-plugin/utils/object.js +30 -15
  21. package/publish/esm/mobase-tw-plugin/utils/theme.d.ts +2 -0
  22. package/publish/esm/mobase-tw-plugin/utils/theme.js +65 -0
  23. package/publish/esm/tsconfig.lib.tsbuildinfo +1 -1
  24. package/publish/cjs/mobase-tw-plugin/foundation/font-sizes/index.js +0 -94
  25. package/publish/cjs/mobase-tw-plugin/foundation/index.js +0 -20
  26. package/publish/cjs/mobase-tw-plugin/foundation/shadows/index.js +0 -12
  27. package/publish/esm/mobase-tw-plugin/foundation/font-sizes/index.js +0 -91
  28. package/publish/esm/mobase-tw-plugin/foundation/index.d.ts +0 -4
  29. package/publish/esm/mobase-tw-plugin/foundation/index.js +0 -4
  30. package/publish/esm/mobase-tw-plugin/foundation/shadows/index.d.ts +0 -10
  31. package/publish/esm/mobase-tw-plugin/foundation/shadows/index.js +0 -9
  32. /package/publish/cjs/mobase-tw-plugin/{foundation/animations → animations}/index.js +0 -0
  33. /package/publish/cjs/mobase-tw-plugin/{foundation/colors → colors}/blue.js +0 -0
  34. /package/publish/cjs/mobase-tw-plugin/{foundation/colors → colors}/common.js +0 -0
  35. /package/publish/cjs/mobase-tw-plugin/{foundation/colors → colors}/gray.js +0 -0
  36. /package/publish/cjs/mobase-tw-plugin/{foundation/colors → colors}/green.js +0 -0
  37. /package/publish/cjs/mobase-tw-plugin/{foundation/colors → colors}/index.js +0 -0
  38. /package/publish/cjs/mobase-tw-plugin/{foundation/colors → colors}/orange.js +0 -0
  39. /package/publish/cjs/mobase-tw-plugin/{foundation/colors → colors}/pink.js +0 -0
  40. /package/publish/cjs/mobase-tw-plugin/{foundation/colors → colors}/purple.js +0 -0
  41. /package/publish/cjs/mobase-tw-plugin/{foundation/colors → colors}/red.js +0 -0
  42. /package/publish/cjs/mobase-tw-plugin/{foundation/colors → colors}/yellow.js +0 -0
  43. /package/publish/esm/mobase-tw-plugin/{foundation/animations → animations}/index.d.ts +0 -0
  44. /package/publish/esm/mobase-tw-plugin/{foundation/animations → animations}/index.js +0 -0
  45. /package/publish/esm/mobase-tw-plugin/{foundation/colors → colors}/blue.d.ts +0 -0
  46. /package/publish/esm/mobase-tw-plugin/{foundation/colors → colors}/blue.js +0 -0
  47. /package/publish/esm/mobase-tw-plugin/{foundation/colors → colors}/common.d.ts +0 -0
  48. /package/publish/esm/mobase-tw-plugin/{foundation/colors → colors}/common.js +0 -0
  49. /package/publish/esm/mobase-tw-plugin/{foundation/colors → colors}/gray.d.ts +0 -0
  50. /package/publish/esm/mobase-tw-plugin/{foundation/colors → colors}/gray.js +0 -0
  51. /package/publish/esm/mobase-tw-plugin/{foundation/colors → colors}/green.d.ts +0 -0
  52. /package/publish/esm/mobase-tw-plugin/{foundation/colors → colors}/green.js +0 -0
  53. /package/publish/esm/mobase-tw-plugin/{foundation/colors → colors}/index.d.ts +0 -0
  54. /package/publish/esm/mobase-tw-plugin/{foundation/colors → colors}/index.js +0 -0
  55. /package/publish/esm/mobase-tw-plugin/{foundation/colors → colors}/orange.d.ts +0 -0
  56. /package/publish/esm/mobase-tw-plugin/{foundation/colors → colors}/orange.js +0 -0
  57. /package/publish/esm/mobase-tw-plugin/{foundation/colors → colors}/pink.d.ts +0 -0
  58. /package/publish/esm/mobase-tw-plugin/{foundation/colors → colors}/pink.js +0 -0
  59. /package/publish/esm/mobase-tw-plugin/{foundation/colors → colors}/purple.d.ts +0 -0
  60. /package/publish/esm/mobase-tw-plugin/{foundation/colors → colors}/purple.js +0 -0
  61. /package/publish/esm/mobase-tw-plugin/{foundation/colors → colors}/red.d.ts +0 -0
  62. /package/publish/esm/mobase-tw-plugin/{foundation/colors → colors}/red.js +0 -0
  63. /package/publish/esm/mobase-tw-plugin/{foundation/colors → colors}/yellow.d.ts +0 -0
  64. /package/publish/esm/mobase-tw-plugin/{foundation/colors → colors}/yellow.js +0 -0
@@ -7,7 +7,7 @@ type FontSizeValue = [
7
7
  }
8
8
  ];
9
9
  export type FontSizes = Record<string, FontSizeValue>;
10
- export declare const fontSizes: {
10
+ export declare function fontSizes(prefix: string): {
11
11
  xxs: [string, {
12
12
  lineHeight: string;
13
13
  }];
@@ -0,0 +1,94 @@
1
+ export function fontSizes(prefix) {
2
+ const fontSizes = {
3
+ xxs: [
4
+ `var(--${prefix}-font-size-xxs)`,
5
+ {
6
+ lineHeight: "1rem",
7
+ },
8
+ ],
9
+ xs: [
10
+ `var(--${prefix}-font-size-xs)`,
11
+ {
12
+ lineHeight: "1rem",
13
+ },
14
+ ],
15
+ sm: [
16
+ `var(--${prefix}-font-size-sm)`,
17
+ {
18
+ lineHeight: "1.25rem",
19
+ },
20
+ ],
21
+ base: [
22
+ `var(--${prefix}-font-size-base)`,
23
+ {
24
+ lineHeight: "1.5rem",
25
+ },
26
+ ],
27
+ lg: [
28
+ `var(--${prefix}-font-size-lg)`,
29
+ {
30
+ lineHeight: "1.75rem",
31
+ },
32
+ ],
33
+ xl: [
34
+ `var(--${prefix}-font-size-xl)`,
35
+ {
36
+ lineHeight: "1.75rem",
37
+ },
38
+ ],
39
+ "2xl": [
40
+ `var(--${prefix}-font-size-2xl)`,
41
+ {
42
+ lineHeight: "2rem",
43
+ },
44
+ ],
45
+ "3xl": [
46
+ `var(--${prefix}-font-size-3xl)`,
47
+ {
48
+ lineHeight: "2.25rem",
49
+ },
50
+ ],
51
+ "4xl": [
52
+ `var(--${prefix}-font-size-4xl)`,
53
+ {
54
+ lineHeight: "2.5rem",
55
+ },
56
+ ],
57
+ "5xl": [
58
+ `var(--${prefix}-font-size-5xl)`,
59
+ {
60
+ lineHeight: "3.5rem",
61
+ letterSpacing: "-0.075rem",
62
+ },
63
+ ],
64
+ "6xl": [
65
+ `var(--${prefix}-font-size-6xl)`,
66
+ {
67
+ lineHeight: "4.5rem",
68
+ letterSpacing: "-0.09375rem",
69
+ },
70
+ ],
71
+ "7xl": [
72
+ `var(--${prefix}-font-size-7xl)`,
73
+ {
74
+ lineHeight: "5rem",
75
+ letterSpacing: "-0.1125rem",
76
+ },
77
+ ],
78
+ "8xl": [
79
+ `var(--${prefix}-font-size-8xl)`,
80
+ {
81
+ lineHeight: "6.5rem",
82
+ letterSpacing: "-0.15rem",
83
+ },
84
+ ],
85
+ "9xl": [
86
+ `var(--${prefix}-font-size-9xl)`,
87
+ {
88
+ lineHeight: "8rem",
89
+ letterSpacing: "-0.2rem",
90
+ },
91
+ ],
92
+ };
93
+ return fontSizes;
94
+ }
@@ -0,0 +1,34 @@
1
+ export declare const layout: {
2
+ "spacing-unit": number;
3
+ "disabled-opacity": number;
4
+ "font-size": {
5
+ xxs: string;
6
+ xs: string;
7
+ sm: string;
8
+ base: string;
9
+ lg: string;
10
+ xl: string;
11
+ "2xl": string;
12
+ "3xl": string;
13
+ "4xl": string;
14
+ "5xl": string;
15
+ "6xl": string;
16
+ "7xl": string;
17
+ "8xl": string;
18
+ "9xl": string;
19
+ };
20
+ radius: {
21
+ sm: string;
22
+ base: string;
23
+ md: string;
24
+ lg: string;
25
+ xl: string;
26
+ "2xl": string;
27
+ "3xl": string;
28
+ };
29
+ "box-shadow": {
30
+ small: string;
31
+ medium: string;
32
+ large: string;
33
+ };
34
+ };
@@ -0,0 +1,34 @@
1
+ export const layout = {
2
+ "spacing-unit": 4,
3
+ "disabled-opacity": 0.5, // Numeric values don't need quotes
4
+ "font-size": {
5
+ xxs: "0.625rem",
6
+ xs: "0.75rem",
7
+ sm: "0.875rem",
8
+ base: "1rem",
9
+ lg: "1.125rem",
10
+ xl: "1.25rem",
11
+ "2xl": "1.5rem",
12
+ "3xl": "1.875rem",
13
+ "4xl": "2.25rem",
14
+ "5xl": "3rem",
15
+ "6xl": "3.75rem",
16
+ "7xl": "4.5rem",
17
+ "8xl": "6rem",
18
+ "9xl": "8rem",
19
+ },
20
+ radius: {
21
+ sm: "0.125rem",
22
+ base: "0.25rem",
23
+ md: "0.375rem",
24
+ lg: "0.5rem",
25
+ xl: "0.75rem",
26
+ "2xl": "1rem",
27
+ "3xl": "1.5rem",
28
+ },
29
+ "box-shadow": {
30
+ 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)",
31
+ 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)",
32
+ 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)",
33
+ },
34
+ };
@@ -10,27 +10,32 @@
10
10
  import Color from "color";
11
11
  import plugin from "tailwindcss/plugin.js";
12
12
  import { utilities } from "./utilities";
13
- import { flattenThemeObject } from "./utils";
14
- import { colors as listColors, fontSizes, boxShadows, animations, } from "./foundation";
15
- import forEach from "lodash.foreach";
16
- const parsedColorsCache = {};
17
- const resolveConfig = () => {
13
+ import { flattenThemeObject } from "./utils/object";
14
+ import { createSpacingUnits, generateSpacingScale } from "./utils/theme";
15
+ import { colors as listColors } from "./colors";
16
+ import { layout } from "./layout";
17
+ import { animations } from "./animations";
18
+ import { fontSizes } from "./font-sizes";
19
+ import { radius } from "./radius";
20
+ // import { animations } from "./animations";
21
+ // import { fontSizes } from "./font-sizes";
22
+ // import { radius } from "./radius";
23
+ const resolveConfig = (prefix) => {
18
24
  const resolved = {
19
25
  utilities: {},
20
26
  colors: {},
21
27
  };
22
28
  const flatColors = flattenThemeObject(listColors);
29
+ const flatLayout = layout;
23
30
  const cssSelector = ":root";
24
31
  resolved.utilities[cssSelector] = {};
25
- forEach(flatColors, (colorValue, colorName) => {
32
+ // Color
33
+ Object.entries(flatColors).forEach(([colorName, colorValue]) => {
26
34
  if (!colorValue)
27
35
  return;
28
36
  try {
29
- const parsedColor = parsedColorsCache[colorValue] ||
30
- Color(colorValue).rgb().round().array();
31
- parsedColorsCache[colorValue] = parsedColor;
32
- const [r, g, b] = parsedColor;
33
- const colorVar = `--${colorName}`;
37
+ const [r, g, b] = Color(colorValue).rgb().array();
38
+ const colorVar = `--${prefix}-${colorName}`;
34
39
  // Set the css variable in "@layer utilities"
35
40
  resolved.utilities[cssSelector][colorVar] = `${r} ${g} ${b}`;
36
41
  resolved.colors[colorName] = `rgb(var(${colorVar}) / <alpha-value>)`;
@@ -40,10 +45,37 @@ const resolveConfig = () => {
40
45
  console.log("error", error?.message);
41
46
  }
42
47
  });
48
+ // Layout
49
+ Object.entries(flatLayout).forEach(([key, value]) => {
50
+ if (!value)
51
+ return;
52
+ const layoutVariablePrefix = `--${prefix}-${key}`;
53
+ if (typeof value === "object") {
54
+ Object.entries(value).forEach(([nestedKey, nestedValue]) => {
55
+ const nestedLayoutVariable = `${layoutVariablePrefix}-${nestedKey}`;
56
+ resolved.utilities[cssSelector][nestedLayoutVariable] = nestedValue;
57
+ });
58
+ }
59
+ else if (key === "spacing-unit") {
60
+ resolved.utilities[cssSelector][layoutVariablePrefix] = value;
61
+ const spacingScale = generateSpacingScale(Number(value));
62
+ Object.entries(spacingScale).forEach(([scaleKey, scaleValue]) => {
63
+ const spacingVariable = `${layoutVariablePrefix}-${scaleKey}`;
64
+ resolved.utilities[cssSelector][spacingVariable] = scaleValue;
65
+ });
66
+ }
67
+ else {
68
+ const formattedValue = layoutVariablePrefix.includes("opacity") && typeof value === "number"
69
+ ? value.toString().replace(/^0\./, ".")
70
+ : value;
71
+ resolved.utilities[cssSelector][layoutVariablePrefix] = formattedValue;
72
+ }
73
+ });
43
74
  return resolved;
44
75
  };
45
76
  export const mobaseTW = () => {
46
- const resolved = resolveConfig();
77
+ const prefix = "mobase";
78
+ const resolved = resolveConfig(prefix);
47
79
  return plugin(({ addBase, addUtilities }) => {
48
80
  addBase({
49
81
  ":root": {
@@ -65,10 +97,22 @@ export const mobaseTW = () => {
65
97
  ...resolved?.colors,
66
98
  },
67
99
  boxShadow: {
68
- ...boxShadows,
100
+ small: `var(--${prefix}-box-shadow-small)`,
101
+ medium: `var(--${prefix}-box-shadow-medium)`,
102
+ large: `var(--${prefix}-box-shadow-large)`,
103
+ },
104
+ // fontSize: {
105
+ // ...fontSizes,
106
+ // },
107
+ borderRadius: {
108
+ ...radius(prefix),
69
109
  },
70
110
  fontSize: {
71
- ...fontSizes,
111
+ ...fontSizes(prefix),
112
+ },
113
+ spacing: {
114
+ unit: `var(--${prefix}-spacing-unit)`,
115
+ ...createSpacingUnits(prefix),
72
116
  },
73
117
  ...animations,
74
118
  },
@@ -0,0 +1,9 @@
1
+ export declare function radius(prefix: string): {
2
+ sm: string;
3
+ DEFAULT: string;
4
+ md: string;
5
+ lg: string;
6
+ xl: string;
7
+ "2xl": string;
8
+ "3xl": string;
9
+ };
@@ -0,0 +1,12 @@
1
+ export function radius(prefix) {
2
+ const radius = {
3
+ sm: `var(--${prefix}-radius-sm)`,
4
+ DEFAULT: `var(--${prefix}-radius-base)`,
5
+ md: `var(--${prefix}-radius-md)`,
6
+ lg: `var(--${prefix}-radius-lg)`,
7
+ xl: `var(--${prefix}-radius-xl)`,
8
+ "2xl": `var(--${prefix}-radius-2xl)`,
9
+ "3xl": `var(--${prefix}-radius-3xl)`,
10
+ };
11
+ return radius;
12
+ }
@@ -0,0 +1,103 @@
1
+ export interface BaseThemeUnit {
2
+ small?: string;
3
+ medium?: string;
4
+ large?: string;
5
+ }
6
+ export type FontThemeUnit = BaseThemeUnit & {
7
+ tiny?: string;
8
+ };
9
+ export declare const spacingScaleKeys: string[];
10
+ export declare const mappedSpacingScaleKeys: string[];
11
+ export type SpacingScaleKeys = (typeof spacingScaleKeys)[number];
12
+ export type SpacingScale = Partial<Record<SpacingScaleKeys, string>>;
13
+ export interface LayoutTheme {
14
+ /**
15
+ * Base unit token that defines a consistent spacing scale across the components.
16
+ *
17
+ * @default 4 (px)
18
+ */
19
+ spacingUnit?: number;
20
+ /**
21
+ * The default font size applied across the components.
22
+ *
23
+ * @default
24
+ * {
25
+ * tiny: "0.75rem",
26
+ * small: "0.875rem",
27
+ * medium: "1rem",
28
+ * large: "1.125rem",
29
+ * DEFAULT: "1rem",
30
+ * }
31
+ */
32
+ fontSize?: FontThemeUnit;
33
+ /**
34
+ * The default line height applied across the components.
35
+ *
36
+ * @default
37
+ * {
38
+ * tiny: "1rem",
39
+ * small: "1.25rem",
40
+ * medium: "1.5rem",
41
+ * large: "1.75rem",
42
+ * DEFAULT: "1.5rem",
43
+ * }
44
+ */
45
+ lineHeight?: FontThemeUnit;
46
+ /**
47
+ * The default radius applied across the components.
48
+ * we recommend to use `rem` units.
49
+ *
50
+ * @default
51
+ * {
52
+ * small: "0.25rem",
53
+ * medium: "0.5rem",
54
+ * large: "0.75rem",
55
+ * }
56
+ */
57
+ radius?: BaseThemeUnit;
58
+ /**
59
+ * A number between 0 and 1 that is applied as opacity-[value] when the component is disabled.
60
+ *
61
+ * format: ".[value]"
62
+ *
63
+ * @default .5
64
+ */
65
+ disabledOpacity?: string | number;
66
+ /**
67
+ * A number between 0 and 1 that is applied as opacity-[value] when the component is hovered.
68
+ *
69
+ * format: ".[value]"
70
+ *
71
+ * @default .8
72
+ */
73
+ hoverOpacity?: string | number;
74
+ /**
75
+ * The default height applied to the divider component.
76
+ * we recommend to use `px` units.
77
+ *
78
+ * @default 1px
79
+ */
80
+ dividerWeight?: string;
81
+ /**
82
+ * The border width applied across the components.
83
+ * @default
84
+ * {
85
+ * small: "1px",
86
+ * medium: "2px",
87
+ * large: "3px",
88
+ * }
89
+ *
90
+ */
91
+ borderWidth?: BaseThemeUnit;
92
+ /**
93
+ * The box shadow applied across the components.
94
+ *
95
+ * @default
96
+ * {
97
+ * small: 0px 0px 5px 0px rgb(0 0 0 / 0.01), 0px 2px 10px 0px rgb(0 0 0 / 0.06),
98
+ * medium: 0px 0px 15px 0px rgb(0 0 0 / 0.02), 0px 2px 30px 0px rgb(0 0 0 / 0.08),
99
+ * large: 0px 0px 30px 0px rgb(0 0 0 / 0.03), 0px 30px 60px 0px rgb(0 0 0 / 0.12),
100
+ * }
101
+ */
102
+ boxShadow?: BaseThemeUnit;
103
+ }
@@ -0,0 +1,51 @@
1
+ export const spacingScaleKeys = [
2
+ "0",
3
+ "xs",
4
+ "sm",
5
+ "md",
6
+ "lg",
7
+ "xl",
8
+ "2xl",
9
+ "3xl",
10
+ "4xl",
11
+ "5xl",
12
+ "6xl",
13
+ "7xl",
14
+ "8xl",
15
+ "9xl",
16
+ "1",
17
+ "2",
18
+ "3",
19
+ "3.5",
20
+ "4",
21
+ "5",
22
+ "6",
23
+ "7",
24
+ "8",
25
+ "9",
26
+ "10",
27
+ "11",
28
+ "12",
29
+ "13",
30
+ "14",
31
+ "15",
32
+ "16",
33
+ "17",
34
+ "18",
35
+ "20",
36
+ "24",
37
+ "28",
38
+ "32",
39
+ "36",
40
+ "40",
41
+ "44",
42
+ "48",
43
+ "52",
44
+ "56",
45
+ "60",
46
+ "64",
47
+ "72",
48
+ "80",
49
+ "96",
50
+ ];
51
+ export const mappedSpacingScaleKeys = spacingScaleKeys.map((key) => `unit-${key}`);
@@ -1,19 +1,5 @@
1
- /**
2
- * Determines if the theme is a base theme
3
- *
4
- * @param theme string
5
- * @returns "light" | "dark
6
- */
7
- export declare const isBaseTheme: (theme: string) => boolean;
8
- /**
9
- * Removes keys with "-DEFAULT" suffix from the given object and returns a new object.
10
- *
11
- * @param obj - The object to remove keys from.
12
- * @returns A new object with keys ending in "-DEFAULT" removed.
13
- */
14
- type TransformedKeys<T extends Record<string, unknown>> = {
15
- [K in keyof T as K extends `${infer Prefix}-DEFAULT` ? Prefix : K]: T[K];
16
- };
1
+ export declare function swapColorValues<T extends Object>(colors: T): {};
2
+ export declare function removeDefaultKeys<T extends Object>(obj: T): {};
17
3
  /**
18
4
  *
19
5
  * Flatten theme object and remove default keys
@@ -21,5 +7,4 @@ type TransformedKeys<T extends Record<string, unknown>> = {
21
7
  * @param obj theme object
22
8
  * @returns object with flattened keys
23
9
  */
24
- export declare const flattenThemeObject: <T>(obj: T) => TransformedKeys<Record<string, unknown>>;
25
- export {};
10
+ export declare const flattenThemeObject: <TTarget>(obj: TTarget) => {};
@@ -1,19 +1,36 @@
1
- import { flatten } from "flat";
2
- /**
3
- * Determines if the theme is a base theme
4
- *
5
- * @param theme string
6
- * @returns "light" | "dark
7
- */
8
- export const isBaseTheme = (theme) => theme === "light" || theme === "dark";
9
- const removeDefaultKeys = (obj) => {
1
+ import flatten from "flat";
2
+ export function swapColorValues(colors) {
3
+ const swappedColors = {};
4
+ const keys = Object.keys(colors);
5
+ const length = keys.length;
6
+ for (let i = 0; i < length / 2; i++) {
7
+ const key1 = keys[i];
8
+ const key2 = keys[length - 1 - i];
9
+ // @ts-ignore
10
+ swappedColors[key1] = colors[key2];
11
+ // @ts-ignore
12
+ swappedColors[key2] = colors[key1];
13
+ }
14
+ if (length % 2 !== 0) {
15
+ const middleKey = keys[Math.floor(length / 2)];
16
+ // @ts-ignore
17
+ swappedColors[middleKey] = colors[middleKey];
18
+ }
19
+ return swappedColors;
20
+ }
21
+ export function removeDefaultKeys(obj) {
10
22
  const newObj = {};
11
23
  for (const key in obj) {
12
- const newKey = key.endsWith("-DEFAULT") ? key.replace("-DEFAULT", "") : key;
13
- newObj[newKey] = obj[key];
24
+ if (key.endsWith("-DEFAULT")) {
25
+ // @ts-ignore
26
+ newObj[key.replace("-DEFAULT", "")] = obj[key];
27
+ continue;
28
+ }
29
+ // @ts-ignore
30
+ newObj[key] = obj[key];
14
31
  }
15
32
  return newObj;
16
- };
33
+ }
17
34
  /**
18
35
  *
19
36
  * Flatten theme object and remove default keys
@@ -21,9 +38,7 @@ const removeDefaultKeys = (obj) => {
21
38
  * @param obj theme object
22
39
  * @returns object with flattened keys
23
40
  */
24
- export const flattenThemeObject = (obj) => removeDefaultKeys(
25
- // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
26
- flatten(obj, {
41
+ export const flattenThemeObject = (obj) => removeDefaultKeys(flatten(obj, {
27
42
  safe: true,
28
43
  delimiter: "-",
29
44
  }));
@@ -0,0 +1,2 @@
1
+ export declare const generateSpacingScale: (spacingUnit: number) => Partial<Record<string, string>>;
2
+ export declare function createSpacingUnits(prefix: string): Record<string, string>;
@@ -0,0 +1,65 @@
1
+ import { spacingScaleKeys } from "../types";
2
+ /**
3
+ * Determines if the theme is a base theme
4
+ *
5
+ * @param theme string
6
+ * @returns "light" | "dark
7
+ */
8
+ const ROOT_FONT_SIZE = 16;
9
+ const baseScale = [
10
+ 0.5, 1, 1.5, 2, 2.5, 3, 3.5, 4, 5, 6, 7, 8, 9, 10, 11, 12, 14, 16, 18,
11
+ ];
12
+ const extendedScale = [
13
+ 20, 24, 28, 32, 36, 40, 44, 48, 52, 56, 60, 64, 72, 80, 96,
14
+ ];
15
+ export const generateSpacingScale = (spacingUnit) => {
16
+ const scaleLabels = {
17
+ xs: 2,
18
+ sm: 3,
19
+ md: 4,
20
+ lg: 5.5,
21
+ xl: 9,
22
+ "2xl": 12,
23
+ "3xl": 20,
24
+ "4xl": 30,
25
+ "5xl": 56,
26
+ "6xl": 72,
27
+ "7xl": 96,
28
+ "8xl": 128,
29
+ "9xl": 160,
30
+ };
31
+ const scale = { 0: "0px" };
32
+ Object.entries(scaleLabels).forEach(([label, multiplier]) => {
33
+ scale[label] = multiplier
34
+ ? `${(spacingUnit * multiplier) / ROOT_FONT_SIZE}rem`
35
+ : `${spacingUnit / ROOT_FONT_SIZE}rem`;
36
+ });
37
+ baseScale.forEach((i) => {
38
+ let key = `${i}`;
39
+ // if the key has decimal e.g 3.5 change it to "3-5" format
40
+ if (key.includes(".")) {
41
+ const [first, second] = key.split(".");
42
+ key = `${first}_${second}`;
43
+ }
44
+ scale[key] = `${(spacingUnit * i) / ROOT_FONT_SIZE}rem`;
45
+ });
46
+ extendedScale.forEach((i) => {
47
+ const key = `${i}`;
48
+ scale[key] = `${(spacingUnit * i) / ROOT_FONT_SIZE}rem`;
49
+ });
50
+ return scale;
51
+ };
52
+ export function createSpacingUnits(prefix) {
53
+ const result = spacingScaleKeys.reduce((acc, key) => {
54
+ let value = `var(--${prefix}-spacing-unit-${key})`;
55
+ if (key.includes(".")) {
56
+ const [first, second] = key.split(".");
57
+ value = `var(--${prefix}-spacing-unit-${first}_${second})`;
58
+ }
59
+ return {
60
+ ...acc,
61
+ [`${key}`]: value,
62
+ };
63
+ }, {});
64
+ return result;
65
+ }