@docsplain-kit/core 0.0.56 → 0.0.57

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/README.md CHANGED
@@ -62,3 +62,39 @@ export default function Page() {
62
62
  ```
63
63
 
64
64
  📖 **See [SERVER_COMPONENTS.md](./SERVER_COMPONENTS.md) for a complete guide** with examples, best practices, and troubleshooting.
65
+
66
+ ---
67
+
68
+ ## 🎨 **Theme-Aware Div Colors**
69
+
70
+ `Div` supports `bgColor` and `borderColor` props. Pass Tailwind color tokens without the utility prefix:
71
+
72
+ ```tsx
73
+ <Div bgColor="control-50" borderColor="control-200" />
74
+ ```
75
+
76
+ The dark-mode color is generated by `withUiKit`. Numeric shades reverse automatically, so `control-50` becomes `control-950`.
77
+
78
+ You can override any reverse color from `tailwind.config.js`:
79
+
80
+ ```js
81
+ const withUiKit = require('@docsplain-kit/core/withUiKit');
82
+
83
+ module.exports = withUiKit({
84
+ content: ['./src/**/*.{js,ts,jsx,tsx}'],
85
+ theme: { extend: {} },
86
+ plugins: [],
87
+ uiKit: {
88
+ reverseColors: {
89
+ bg: {
90
+ white: 'control-800',
91
+ },
92
+ border: {
93
+ white: 'control-700',
94
+ },
95
+ },
96
+ },
97
+ });
98
+ ```
99
+
100
+ Use a top-level key such as `white: 'control-800'` when the same reverse color should apply to both `bgColor` and `borderColor`.
package/div/div.js CHANGED
@@ -5,9 +5,27 @@ exports.Div = void 0;
5
5
  var tslib_1 = require("tslib");
6
6
  var react_1 = tslib_1.__importStar(require("react"));
7
7
  var tailwind_merge_config_1 = require("../tailwind-merge-config");
8
+ var normalizeColorToken = function (color) {
9
+ if (!color) {
10
+ return undefined;
11
+ }
12
+ return color
13
+ .trim()
14
+ .replace(/^!?(bg|border)-/, '')
15
+ .replace(/\./g, '-');
16
+ };
17
+ var getColorClass = function (type, color) {
18
+ var colorToken = normalizeColorToken(color);
19
+ if (!colorToken) {
20
+ return undefined;
21
+ }
22
+ return type === 'bg'
23
+ ? "bg-[var(--dpc-bg-color)] dpc-bg-".concat(colorToken)
24
+ : "border-[var(--dpc-border-color)] dpc-border-".concat(colorToken);
25
+ };
8
26
  exports.Div = (0, react_1.forwardRef)(function Div(props, ref) {
9
- var children = props.children, style = props.style, onClick = props.onClick, dangerouslySetInnerHTML = props.dangerouslySetInnerHTML, dataTestId = props.dataTestId, role = props.role, className = props.className, id = props.id, onMouseOver = props.onMouseOver, onMouseLeave = props.onMouseLeave, rest = tslib_1.__rest(props, ["children", "style", "onClick", "dangerouslySetInnerHTML", "dataTestId", "role", "className", "id", "onMouseOver", "onMouseLeave"]);
10
- return (react_1["default"].createElement("div", tslib_1.__assign({ "data-testid": dataTestId, id: id, role: role, className: (0, tailwind_merge_config_1.twMerge)("flex flex-row", className), dangerouslySetInnerHTML: dangerouslySetInnerHTML, onClick: onClick, style: style, ref: ref, onMouseOver: onMouseOver, onMouseLeave: onMouseLeave }, rest), children));
27
+ var children = props.children, style = props.style, onClick = props.onClick, dangerouslySetInnerHTML = props.dangerouslySetInnerHTML, dataTestId = props.dataTestId, role = props.role, className = props.className, id = props.id, onMouseOver = props.onMouseOver, onMouseLeave = props.onMouseLeave, bgColor = props.bgColor, borderColor = props.borderColor, rest = tslib_1.__rest(props, ["children", "style", "onClick", "dangerouslySetInnerHTML", "dataTestId", "role", "className", "id", "onMouseOver", "onMouseLeave", "bgColor", "borderColor"]);
28
+ return (react_1["default"].createElement("div", tslib_1.__assign({ "data-testid": dataTestId, id: id, role: role, className: (0, tailwind_merge_config_1.twMerge)('flex flex-row', getColorClass('bg', bgColor), getColorClass('border', borderColor), className), dangerouslySetInnerHTML: dangerouslySetInnerHTML, onClick: onClick, style: style, ref: ref, onMouseOver: onMouseOver, onMouseLeave: onMouseLeave }, rest), children));
11
29
  });
12
30
  exports["default"] = exports.Div;
13
31
  //# sourceMappingURL=div.js.map
package/div/div.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"div.js","sourceRoot":"","sources":["../../div/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AAY,EAAE,YAAY,IACtB,IAAI,GAEP,QAAQ,CACL,CACP,CAAC;AACJ,CAAC,CAAC,CAAC;AAEH,qBAAe,WAAG,CAAC"}
@@ -5,6 +5,8 @@ export interface DivProps {
5
5
  itemProp?: string;
6
6
  children?: ReactNode;
7
7
  className?: string | undefined;
8
+ bgColor?: string;
9
+ borderColor?: string;
8
10
  style?: CSSProperties | undefined;
9
11
  dangerouslySetInnerHTML?: any;
10
12
  role?: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@docsplain-kit/core",
3
- "version": "0.0.56",
3
+ "version": "0.0.57",
4
4
  "main": "./index.js",
5
5
  "module": "./index.js",
6
6
  "types": "./index.d.ts",
package/withUiKit.js CHANGED
@@ -10,15 +10,209 @@ const { lineHeights } = require('./config/typography/line-heights');
10
10
  const { fontFamily } = require('./config/typography/font-family');
11
11
  const { widthHeight } = require('./config/width-height');
12
12
 
13
- const withUiKit = (tailwindConfig) => {
13
+ const DEFAULT_REVERSE_COLOR_SHADES = {
14
+ 50: '950',
15
+ 100: '900',
16
+ 200: '800',
17
+ 300: '700',
18
+ 400: '600',
19
+ 500: '500',
20
+ 600: '400',
21
+ 700: '300',
22
+ 800: '200',
23
+ 900: '100',
24
+ 950: '50',
25
+ };
26
+
27
+ const DEPRECATED_TAILWIND_COLOR_KEYS = ['lightBlue', 'warmGray', 'trueGray', 'coolGray', 'blueGray'];
28
+
29
+ const UI_KIT_COLORS = {
30
+ 'transparent': 'transparent',
31
+ 'white': '#FFFFFF',
32
+ 'black': '#000000',
33
+ 'primary': {
34
+ ...primary,
35
+ light: primary['300'],
36
+ DEFAULT: primary['500'],
37
+ dark: primary['700'],
38
+ },
39
+ 'secondary': {
40
+ ...secondary,
41
+ light: secondary['300'],
42
+ DEFAULT: secondary['500'],
43
+ dark: secondary['700'],
44
+ },
45
+ 'info': {
46
+ ...info,
47
+ light: info['300'],
48
+ DEFAULT: info['500'],
49
+ dark: info['700'],
50
+ },
51
+ 'success': {
52
+ ...success,
53
+ light: success['300'],
54
+ DEFAULT: success['500'],
55
+ dark: success['700'],
56
+ },
57
+ 'warning': {
58
+ ...warning,
59
+ light: warning['300'],
60
+ DEFAULT: warning['500'],
61
+ dark: warning['700'],
62
+ },
63
+ 'danger': {
64
+ ...danger,
65
+ light: danger['300'],
66
+ DEFAULT: danger['500'],
67
+ dark: danger['700'],
68
+ },
69
+ 'control': {
70
+ ...control,
71
+ light: control['300'],
72
+ DEFAULT: control['500'],
73
+ dark: control['700'],
74
+ },
75
+ };
76
+
77
+ const normalizeColorToken = (color) => {
78
+ if (typeof color !== 'string') {
79
+ return color;
80
+ }
81
+
82
+ return color
83
+ .trim()
84
+ .replace(/^!?(bg|border)-/, '')
85
+ .replace(/\./g, '-');
86
+ };
87
+
88
+ const flattenColorPalette = (colors, prefix = '') => {
89
+ return Object.keys(colors || {}).reduce((result, key) => {
90
+ if (DEPRECATED_TAILWIND_COLOR_KEYS.includes(key)) {
91
+ return result;
92
+ }
93
+
94
+ const value = colors[key];
95
+
96
+ if (typeof value === 'string') {
97
+ const colorKey = key === 'DEFAULT' ? prefix : [prefix, key].filter(Boolean).join('-');
98
+
99
+ if (colorKey) {
100
+ result[colorKey] = value;
101
+ }
102
+
103
+ return result;
104
+ }
105
+
106
+ if (value && typeof value === 'object' && !Array.isArray(value)) {
107
+ return Object.assign(result, flattenColorPalette(value, [prefix, key].filter(Boolean).join('-')));
108
+ }
109
+
110
+ return result;
111
+ }, {});
112
+ };
113
+
114
+ const getReverseColorToken = (token, type, reverseColors, colorMap) => {
115
+ const typeReverseColors = reverseColors && reverseColors[type];
116
+ const configuredReverseColor = (
117
+ typeReverseColors && typeReverseColors[token]
118
+ ) || (reverseColors && reverseColors[token]);
119
+
120
+ if (configuredReverseColor) {
121
+ return normalizeColorToken(configuredReverseColor);
122
+ }
123
+
124
+ if (token === 'white') {
125
+ return 'black';
126
+ }
127
+
128
+ if (token === 'black') {
129
+ return 'white';
130
+ }
131
+
132
+ const shadeMatch = token.match(/^(.*)-(\d{2,3})$/);
133
+
134
+ if (!shadeMatch) {
135
+ return token;
136
+ }
137
+
138
+ const [, colorName, shade] = shadeMatch;
139
+ const reverseShade = DEFAULT_REVERSE_COLOR_SHADES[shade];
140
+ const reverseToken = `${colorName}-${reverseShade}`;
141
+
142
+ return colorMap[reverseToken] ? reverseToken : token;
143
+ };
144
+
145
+ const createThemedColorUtilities = (reverseColors = {}) => {
146
+ return ({ addUtilities, theme, e }) => {
147
+ const colorMap = flattenColorPalette(theme('colors') || {});
148
+ const utilities = {};
149
+
150
+ Object.entries(colorMap).forEach(([token, value]) => {
151
+ const bgClassName = e(`dpc-bg-${token}`);
152
+ const borderClassName = e(`dpc-border-${token}`);
153
+ const reverseBgToken = getReverseColorToken(token, 'bg', reverseColors, colorMap);
154
+ const reverseBorderToken = getReverseColorToken(token, 'border', reverseColors, colorMap);
155
+ const reverseBgValue = colorMap[reverseBgToken] || value;
156
+ const reverseBorderValue = colorMap[reverseBorderToken] || value;
157
+
158
+ utilities[`.${bgClassName}`] = {
159
+ '--dpc-bg-color': value,
160
+ };
161
+ utilities[`.dark .${bgClassName}, [data-theme="dark"] .${bgClassName}, .${bgClassName}.dark, .${bgClassName}[data-theme="dark"]`] = {
162
+ '--dpc-bg-color': reverseBgValue,
163
+ };
164
+ utilities[`.${borderClassName}`] = {
165
+ '--dpc-border-color': value,
166
+ };
167
+ utilities[`.dark .${borderClassName}, [data-theme="dark"] .${borderClassName}, .${borderClassName}.dark, .${borderClassName}[data-theme="dark"]`] = {
168
+ '--dpc-border-color': reverseBorderValue,
169
+ };
170
+ });
171
+
172
+ addUtilities(utilities);
173
+ };
174
+ };
175
+
176
+ const getThemedColorSafelist = (tailwindConfig) => {
177
+ const tailwindTheme = tailwindConfig.theme || {};
178
+ const tailwindExtend = tailwindTheme.extend || {};
179
+ let tailwindDefaultColors = {};
180
+
181
+ try {
182
+ tailwindDefaultColors = require('tailwindcss/colors');
183
+ } catch {
184
+ tailwindDefaultColors = {};
185
+ }
186
+
187
+ const configuredColors = Object.assign(
188
+ {},
189
+ tailwindDefaultColors,
190
+ UI_KIT_COLORS,
191
+ tailwindTheme.colors || {},
192
+ tailwindExtend.colors || {},
193
+ );
194
+ const colorTokens = Object.keys(flattenColorPalette(configuredColors));
195
+
196
+ return colorTokens.flatMap((token) => [`dpc-bg-${token}`, `dpc-border-${token}`]);
197
+ };
198
+
199
+ const withUiKit = (tailwindConfig = {}) => {
200
+ const theme = tailwindConfig.theme || {};
201
+ const themeExtend = theme.extend || {};
202
+ const uiKit = tailwindConfig.uiKit || {};
203
+
14
204
  return {
15
205
  darkMode: 'selector',
206
+ safelist: [
207
+ ...(tailwindConfig.safelist || []),
208
+ ...getThemedColorSafelist(tailwindConfig),
209
+ ],
16
210
  content: [
17
211
  './node_modules/@docsplain-kit/core/**/*',
18
- ...tailwindConfig.content,
212
+ ...(tailwindConfig.content || []),
19
213
  ],
20
214
  theme: {
21
- ...tailwindConfig.theme,
215
+ ...theme,
22
216
  screens: {
23
217
  'sm': '640px',
24
218
  'md': '1024px',
@@ -34,87 +228,44 @@ const withUiKit = (tailwindConfig) => {
34
228
  'gt-xs': { 'min': '640px' },
35
229
  'gt-sm': { 'min': '1024px' },
36
230
  'gt-md': { 'min': '1200px' },
37
- ...tailwindConfig.theme.screens,
231
+ ...theme.screens,
38
232
  },
39
233
  fontSize: {
40
234
  ...fontSizes,
41
- ...tailwindConfig.theme.fontSize,
235
+ ...theme.fontSize,
42
236
  },
43
237
  fontFamily: {
44
238
  ...fontFamily,
45
- ...tailwindConfig.theme.fontFamily,
239
+ ...theme.fontFamily,
46
240
  },
47
241
  lineHeight: {
48
242
  ...lineHeights,
49
- ...tailwindConfig.theme.lineHeight,
243
+ ...theme.lineHeight,
50
244
  },
51
245
  minWidth: {
52
246
  ...widthHeight,
53
- ...tailwindConfig.theme.minWidth,
247
+ ...theme.minWidth,
54
248
  },
55
249
  minHeight: {
56
250
  ...widthHeight,
57
- ...tailwindConfig.theme.minHeight,
251
+ ...theme.minHeight,
58
252
  },
59
253
  extend: {
60
- ...tailwindConfig.theme.extend,
61
- colors: Object.assign({}, {
62
- 'transparent': 'transparent',
63
- 'white': '#FFFFFF',
64
- 'black': '#000000',
65
- 'primary': {
66
- ...primary,
67
- light: primary['300'],
68
- DEFAULT: primary['500'],
69
- dark: primary['700'],
70
- },
71
- 'secondary': {
72
- ...secondary,
73
- light: secondary['300'],
74
- DEFAULT: secondary['500'],
75
- dark: secondary['700'],
76
- },
77
- 'info': {
78
- ...info,
79
- light: info['300'],
80
- DEFAULT: info['500'],
81
- dark: info['700'],
82
- },
83
- 'success': {
84
- ...success,
85
- light: success['300'],
86
- DEFAULT: success['500'],
87
- dark: success['700'],
88
- },
89
- 'warning': {
90
- ...warning,
91
- light: warning['300'],
92
- DEFAULT: warning['500'],
93
- dark: warning['700'],
94
- },
95
- 'danger': {
96
- ...danger,
97
- light: danger['300'],
98
- DEFAULT: danger['500'],
99
- dark: danger['700'],
100
- },
101
- 'control': {
102
- ...control,
103
- light: control['300'],
104
- DEFAULT: control['500'],
105
- dark: control['700'],
106
- },
107
- }, tailwindConfig.theme.extend.colors),
254
+ ...themeExtend,
255
+ colors: Object.assign({}, UI_KIT_COLORS, themeExtend.colors),
108
256
  height: {
109
257
  'dvh': '100dvh',
258
+ ...themeExtend.height,
110
259
  },
111
260
  direction: {
112
261
  'inherit': 'inherit',
262
+ ...themeExtend.direction,
113
263
  },
114
264
  },
115
265
  },
116
266
  plugins: [
117
- ...tailwindConfig.plugins,
267
+ createThemedColorUtilities(uiKit.reverseColors || {}),
268
+ ...(tailwindConfig.plugins || []),
118
269
  ],
119
270
  };
120
271
  };