rsuite 6.0.0-canary-20250620 → 6.0.0-canary-20250622

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 (193) hide show
  1. package/Accordion/styles/index.css +0 -78
  2. package/AutoComplete/styles/index.css +1 -79
  3. package/Avatar/styles/index.css +0 -78
  4. package/AvatarGroup/styles/index.css +0 -78
  5. package/Badge/styles/index.css +0 -78
  6. package/Box/styles/index.css +0 -78
  7. package/Breadcrumb/styles/index.css +0 -78
  8. package/Button/styles/index.css +0 -78
  9. package/ButtonGroup/styles/index.css +0 -78
  10. package/ButtonToolbar/styles/index.css +0 -82
  11. package/Calendar/styles/index.css +0 -78
  12. package/Card/styles/index.css +0 -78
  13. package/CardGroup/styles/index.css +0 -78
  14. package/Carousel/styles/index.css +0 -78
  15. package/CascadeTree/styles/index.css +0 -78
  16. package/Cascader/styles/index.css +1 -79
  17. package/Center/styles/index.css +0 -78
  18. package/CheckPicker/styles/index.css +1 -79
  19. package/CheckTree/styles/index.css +1 -79
  20. package/CheckTreePicker/styles/index.css +1 -79
  21. package/Checkbox/styles/index.css +0 -78
  22. package/CheckboxGroup/styles/index.css +0 -78
  23. package/Container/styles/index.css +0 -78
  24. package/Content/styles/index.css +0 -78
  25. package/DateInput/styles/index.css +0 -78
  26. package/DatePicker/styles/index.css +1 -79
  27. package/DateRangeInput/styles/index.css +0 -78
  28. package/DateRangePicker/styles/index.css +1 -79
  29. package/Divider/styles/index.css +0 -78
  30. package/Drawer/styles/index.css +0 -78
  31. package/Dropdown/styles/index.css +0 -78
  32. package/FlexboxGrid/styles/index.css +0 -78
  33. package/Footer/styles/index.css +0 -78
  34. package/Form/styles/index.css +0 -78
  35. package/FormControl/styles/index.css +0 -78
  36. package/FormControlLabel/styles/index.css +0 -78
  37. package/FormErrorMessage/styles/index.css +0 -78
  38. package/FormGroup/styles/index.css +0 -78
  39. package/FormHelpText/styles/index.css +0 -78
  40. package/FormStack/styles/index.css +0 -78
  41. package/Grid/styles/index.css +0 -78
  42. package/Header/styles/index.css +0 -78
  43. package/Heading/styles/index.css +0 -78
  44. package/HeadingGroup/styles/index.css +0 -78
  45. package/Highlight/styles/index.css +0 -78
  46. package/IconButton/styles/index.css +0 -78
  47. package/Image/styles/index.css +0 -78
  48. package/InlineEdit/styles/index.css +0 -78
  49. package/Input/styles/index.css +0 -78
  50. package/InputGroup/styles/index.css +1 -79
  51. package/InputNumber/styles/index.css +1 -79
  52. package/InputPicker/styles/index.css +1 -79
  53. package/Kbd/styles/index.css +0 -78
  54. package/Link/styles/index.css +0 -78
  55. package/List/styles/index.css +0 -78
  56. package/Loader/styles/index.css +0 -78
  57. package/Menu/styles/index.css +0 -78
  58. package/Message/styles/index.css +0 -78
  59. package/Modal/styles/index.css +0 -78
  60. package/MultiCascadeTree/styles/index.css +1 -79
  61. package/MultiCascader/styles/index.css +1 -79
  62. package/Nav/styles/index.css +0 -78
  63. package/Navbar/styles/index.css +0 -78
  64. package/Notification/styles/index.css +0 -78
  65. package/NumberInput/styles/index.css +1 -79
  66. package/Pagination/styles/index.css +1 -79
  67. package/Panel/styles/index.css +0 -78
  68. package/PanelGroup/styles/index.css +0 -78
  69. package/PasswordInput/styles/index.css +1 -79
  70. package/PasswordStrengthMeter/styles/index.css +0 -78
  71. package/PinInput/styles/index.css +0 -78
  72. package/Placeholder/styles/index.css +0 -78
  73. package/Popover/styles/index.css +0 -78
  74. package/Progress/styles/index.css +0 -78
  75. package/ProgressCircle/styles/index.css +0 -78
  76. package/Radio/styles/index.css +0 -78
  77. package/RadioGroup/styles/index.css +0 -78
  78. package/RadioTile/styles/index.css +0 -78
  79. package/RangeSlider/styles/index.css +0 -78
  80. package/Rate/styles/index.css +0 -78
  81. package/SegmentedControl/package.json +7 -0
  82. package/SegmentedControl/styles/index.css +159 -0
  83. package/SelectPicker/styles/index.css +1 -79
  84. package/Sidebar/styles/index.css +0 -78
  85. package/Sidenav/styles/index.css +0 -78
  86. package/Slider/styles/index.css +0 -78
  87. package/Stack/styles/index.css +0 -78
  88. package/Stat/styles/index.css +0 -78
  89. package/StatGroup/styles/index.css +0 -78
  90. package/Steps/styles/index.css +0 -78
  91. package/Table/styles/index.css +0 -78
  92. package/Tabs/styles/index.css +0 -78
  93. package/Tag/styles/index.css +0 -78
  94. package/TagGroup/styles/index.css +0 -78
  95. package/TagInput/styles/index.css +1 -79
  96. package/TagPicker/styles/index.css +1 -79
  97. package/Text/styles/index.css +0 -78
  98. package/Textarea/styles/index.css +0 -78
  99. package/TimePicker/styles/index.css +1 -79
  100. package/TimeRangePicker/styles/index.css +1 -79
  101. package/Timeline/styles/index.css +0 -78
  102. package/Toggle/styles/index.css +0 -78
  103. package/Tooltip/styles/index.css +0 -78
  104. package/Tree/styles/index.css +1 -79
  105. package/TreePicker/styles/index.css +1 -79
  106. package/Uploader/styles/index.css +0 -78
  107. package/cjs/ButtonToolbar/ButtonToolbar.js +2 -0
  108. package/cjs/Grid/utils/styles.d.ts +1 -1
  109. package/cjs/InputPicker/utils.d.ts +1 -1
  110. package/cjs/Nav/Nav.d.ts +2 -3
  111. package/cjs/RadioGroup/RadioGroup.d.ts +4 -1
  112. package/cjs/SegmentedControl/Indicator.d.ts +10 -0
  113. package/cjs/SegmentedControl/Indicator.js +22 -0
  114. package/cjs/SegmentedControl/SegmentedControl.d.ts +27 -0
  115. package/cjs/SegmentedControl/SegmentedControl.js +87 -0
  116. package/cjs/SegmentedControl/SegmentedItem.d.ts +16 -0
  117. package/cjs/SegmentedControl/SegmentedItem.js +44 -0
  118. package/cjs/SegmentedControl/hooks/useIndicatorPosition.d.ts +17 -0
  119. package/cjs/SegmentedControl/hooks/useIndicatorPosition.js +55 -0
  120. package/cjs/SegmentedControl/index.d.ts +4 -0
  121. package/cjs/SegmentedControl/index.js +11 -0
  122. package/cjs/Slider/ProgressBar.js +1 -1
  123. package/cjs/Stack/Stack.js +20 -5
  124. package/cjs/Stack/utils.d.ts +9 -0
  125. package/cjs/Stack/utils.js +38 -0
  126. package/cjs/Tabs/Tabs.d.ts +4 -2
  127. package/cjs/index.d.ts +1 -0
  128. package/cjs/index.js +6 -0
  129. package/cjs/internals/Box/Box.d.ts +27 -27
  130. package/cjs/internals/Box/Box.js +13 -8
  131. package/cjs/internals/Box/utils.d.ts +4 -1
  132. package/cjs/internals/Box/utils.js +154 -13
  133. package/cjs/internals/Provider/types.d.ts +2 -0
  134. package/cjs/internals/constants/index.js +2 -2
  135. package/cjs/internals/hooks/useElementResize.d.ts +2 -1
  136. package/cjs/internals/hooks/useElementResize.js +50 -7
  137. package/cjs/internals/hooks/useStyled.d.ts +60 -0
  138. package/cjs/internals/hooks/useStyled.js +257 -0
  139. package/cjs/internals/utils/colours.js +1 -1
  140. package/cjs/internals/utils/style-sheet/css.d.ts +1 -1
  141. package/cjs/internals/utils/style-sheet/css.js +1 -1
  142. package/cjs/internals/utils/style-sheet/index.d.ts +1 -0
  143. package/cjs/internals/utils/style-sheet/index.js +6 -0
  144. package/cjs/internals/utils/style-sheet/style-manager.d.ts +50 -0
  145. package/cjs/internals/utils/style-sheet/style-manager.js +97 -0
  146. package/dist/rsuite-no-reset.css +200 -101
  147. package/dist/rsuite-no-reset.min.css +1 -1
  148. package/dist/rsuite.css +200 -101
  149. package/dist/rsuite.js +172 -14
  150. package/dist/rsuite.js.map +1 -1
  151. package/dist/rsuite.min.css +1 -1
  152. package/dist/rsuite.min.js +1 -1
  153. package/dist/rsuite.min.js.map +1 -1
  154. package/esm/ButtonToolbar/ButtonToolbar.js +2 -0
  155. package/esm/Grid/utils/styles.d.ts +1 -1
  156. package/esm/InputPicker/utils.d.ts +1 -1
  157. package/esm/Nav/Nav.d.ts +2 -3
  158. package/esm/RadioGroup/RadioGroup.d.ts +4 -1
  159. package/esm/SegmentedControl/Indicator.d.ts +10 -0
  160. package/esm/SegmentedControl/Indicator.js +17 -0
  161. package/esm/SegmentedControl/SegmentedControl.d.ts +27 -0
  162. package/esm/SegmentedControl/SegmentedControl.js +81 -0
  163. package/esm/SegmentedControl/SegmentedItem.d.ts +16 -0
  164. package/esm/SegmentedControl/SegmentedItem.js +39 -0
  165. package/esm/SegmentedControl/hooks/useIndicatorPosition.d.ts +17 -0
  166. package/esm/SegmentedControl/hooks/useIndicatorPosition.js +50 -0
  167. package/esm/SegmentedControl/index.d.ts +4 -0
  168. package/esm/SegmentedControl/index.js +8 -0
  169. package/esm/Slider/ProgressBar.js +1 -1
  170. package/esm/Stack/Stack.js +21 -6
  171. package/esm/Stack/utils.d.ts +9 -0
  172. package/esm/Stack/utils.js +35 -0
  173. package/esm/Tabs/Tabs.d.ts +4 -2
  174. package/esm/index.d.ts +1 -0
  175. package/esm/index.js +1 -0
  176. package/esm/internals/Box/Box.d.ts +27 -27
  177. package/esm/internals/Box/Box.js +9 -4
  178. package/esm/internals/Box/utils.d.ts +4 -1
  179. package/esm/internals/Box/utils.js +153 -13
  180. package/esm/internals/Provider/types.d.ts +2 -0
  181. package/esm/internals/constants/index.js +2 -2
  182. package/esm/internals/hooks/useElementResize.d.ts +2 -1
  183. package/esm/internals/hooks/useElementResize.js +50 -7
  184. package/esm/internals/hooks/useStyled.d.ts +60 -0
  185. package/esm/internals/hooks/useStyled.js +251 -0
  186. package/esm/internals/utils/colours.js +1 -1
  187. package/esm/internals/utils/style-sheet/css.d.ts +1 -1
  188. package/esm/internals/utils/style-sheet/css.js +1 -1
  189. package/esm/internals/utils/style-sheet/index.d.ts +1 -0
  190. package/esm/internals/utils/style-sheet/index.js +2 -1
  191. package/esm/internals/utils/style-sheet/style-manager.d.ts +50 -0
  192. package/esm/internals/utils/style-sheet/style-manager.js +93 -0
  193. package/package.json +1 -1
@@ -0,0 +1,257 @@
1
+ 'use client';
2
+ "use strict";
3
+
4
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
5
+ exports.__esModule = true;
6
+ exports.default = void 0;
7
+ exports.useStyled = useStyled;
8
+ var _react = require("react");
9
+ var _isEmpty = _interopRequireDefault(require("lodash/isEmpty"));
10
+ var _styleManager = require("../utils/style-sheet/style-manager");
11
+ var _constants = require("../constants");
12
+ var _CustomContext = require("../Provider/CustomContext");
13
+ // CSS Property Map
14
+ const propertyMap = {
15
+ // Padding
16
+ p: 'padding',
17
+ pt: 'padding-top',
18
+ pr: 'padding-right',
19
+ pb: 'padding-bottom',
20
+ pl: 'padding-left',
21
+ px: 'padding-inline',
22
+ py: 'padding-block',
23
+ // Margin
24
+ m: 'margin',
25
+ mt: 'margin-top',
26
+ mr: 'margin-right',
27
+ mb: 'margin-bottom',
28
+ ml: 'margin-left',
29
+ mx: 'margin-inline',
30
+ my: 'margin-block',
31
+ // Size
32
+ w: 'width',
33
+ h: 'height',
34
+ minw: 'min-width',
35
+ maxw: 'max-width',
36
+ minh: 'min-height',
37
+ maxh: 'max-height',
38
+ // Display
39
+ display: 'display',
40
+ // Color and Background
41
+ c: 'color',
42
+ bg: 'background',
43
+ // Border
44
+ bd: 'border',
45
+ rounded: 'border-radius',
46
+ // Shadow
47
+ shadow: 'box-shadow',
48
+ // Stack
49
+ spacing: 'gap',
50
+ align: 'align-items',
51
+ justify: 'justify-content'
52
+ };
53
+
54
+ // Breakpoint values in pixels - matching SCSS variables
55
+ const breakpointValues = {
56
+ xs: 0,
57
+ // Base mobile first
58
+ sm: 576,
59
+ // $screen-sm
60
+ md: 768,
61
+ // $screen-md
62
+ lg: 992,
63
+ // $screen-lg
64
+ xl: 1200,
65
+ // $screen-xl
66
+ xxl: 1400 // $screen-xxl
67
+ };
68
+
69
+ /**
70
+ * Options for the useStyled hook
71
+ */
72
+
73
+ /**
74
+ * Result of the useStyled hook
75
+ */
76
+
77
+ /**
78
+ * Checks if a value is a responsive value object
79
+ * @param value - Value to check
80
+ * @returns True if the value is a responsive value object
81
+ */
82
+ function isResponsiveValue(value) {
83
+ return value !== null && typeof value === 'object' && !Array.isArray(value) && Object.keys(value).some(key => _constants.BREAKPOINTS.includes(key));
84
+ }
85
+
86
+ /**
87
+ * Custom hook for managing component styling with scoped CSS variables
88
+ *
89
+ * This hook handles:
90
+ * 1. Generating a unique class name for the component
91
+ * 2. Creating a scoped style rule to prevent CSS variable inheritance
92
+ * 3. Managing the lifecycle of style rules
93
+ * 4. Handling responsive values for different breakpoints
94
+ *
95
+ * @param options - Styling options
96
+ * @returns Styling properties to apply to the component
97
+ */
98
+ function useStyled(options) {
99
+ const {
100
+ cssVars = {},
101
+ className,
102
+ style,
103
+ enabled = true,
104
+ prefix = 'box'
105
+ } = options;
106
+
107
+ // CSS Variable Prefix, e.g. --rs-box-
108
+ const cssVarPrefix = `--rs-${prefix}-`;
109
+ const {
110
+ csp
111
+ } = (0, _react.useContext)(_CustomContext.CustomContext);
112
+
113
+ // Generate a unique ID for this component instance
114
+ const uniqueId = (0, _react.useId)().replace(/:/g, '');
115
+ const componentId = `rs-${prefix}-${uniqueId}`;
116
+
117
+ // Only apply styling if enabled and there are CSS variables
118
+ const shouldApplyStyles = enabled && !(0, _isEmpty.default)(cssVars);
119
+
120
+ // Apply CSS variables through StyleManager
121
+ (0, _react.useLayoutEffect)(() => {
122
+ if (!shouldApplyStyles) return;
123
+
124
+ // Create base CSS rules for the variables
125
+ let baseVarRules = '';
126
+ let basePropRules = '';
127
+
128
+ // Track responsive variables to handle separately
129
+ const responsiveVars = {};
130
+
131
+ // Process CSS variables, separating responsive from non-responsive
132
+ Object.entries(cssVars).forEach(([key, value]) => {
133
+ if (value !== undefined) {
134
+ if (isResponsiveValue(value)) {
135
+ // Store responsive values for later processing
136
+ responsiveVars[key] = value;
137
+
138
+ // Add xs (mobile first) values to base styles if present
139
+ const xsValue = value.xs;
140
+ if (xsValue !== undefined) {
141
+ baseVarRules += `${key}: ${xsValue}; `;
142
+ }
143
+ } else {
144
+ // Add non-responsive values directly
145
+ baseVarRules += `${key}: ${value}; `;
146
+ }
147
+ }
148
+ });
149
+
150
+ // Add actual style rules based on CSS variables
151
+ Object.keys(cssVars).forEach(varName => {
152
+ // Skip responsive values that don't have xs values
153
+ if (responsiveVars[varName] && !responsiveVars[varName].xs) return;
154
+
155
+ // Extract property name from variable name (remove prefix)
156
+ const propName = varName.startsWith(cssVarPrefix) ? varName.substring(cssVarPrefix.length) : varName;
157
+
158
+ // Check if the property has a corresponding CSS property mapping
159
+ const cssProperty = propertyMap[propName];
160
+ if (cssProperty) {
161
+ basePropRules += `${cssProperty}: var(${varName}); `;
162
+ }
163
+ });
164
+
165
+ // Combine variable definitions and property assignments
166
+ const baseCssRules = baseVarRules + basePropRules;
167
+
168
+ // Add the base rule to the style manager
169
+ _styleManager.StyleManager.addRule(`.${componentId}`, baseCssRules, {
170
+ nonce: csp === null || csp === void 0 ? void 0 : csp.nonce
171
+ });
172
+
173
+ // Process responsive variables
174
+ if (!(0, _isEmpty.default)(responsiveVars)) {
175
+ // Create media queries for each breakpoint
176
+ const breakpointVarRules = {
177
+ xs: '',
178
+ // xs rules will be merged into base styles
179
+ sm: '',
180
+ md: '',
181
+ lg: '',
182
+ xl: '',
183
+ xxl: ''
184
+ };
185
+ const breakpointPropRules = {
186
+ xs: '',
187
+ sm: '',
188
+ md: '',
189
+ lg: '',
190
+ xl: '',
191
+ xxl: ''
192
+ };
193
+
194
+ // Group styles by breakpoint
195
+ Object.entries(responsiveVars).forEach(([varName, responsiveValue]) => {
196
+ Object.entries(responsiveValue).forEach(([breakpoint, value]) => {
197
+ const bp = breakpoint;
198
+ if (value !== undefined && bp !== 'xs') {
199
+ // Skip xs as it's already in base styles
200
+ // Add the CSS variable definition for this breakpoint
201
+ breakpointVarRules[bp] += `${varName}: ${value}; `;
202
+
203
+ // Extract property name from variable name (remove prefix)
204
+ const propName = varName.startsWith(cssVarPrefix) ? varName.substring(cssVarPrefix.length) : varName;
205
+
206
+ // Check if the property has a corresponding CSS property mapping
207
+ const cssProperty = propertyMap[propName];
208
+ if (cssProperty) {
209
+ breakpointPropRules[bp] += `${cssProperty}: var(${varName}); `;
210
+ }
211
+ }
212
+ });
213
+ });
214
+
215
+ // Combine variable definitions and property assignments for each breakpoint
216
+ const breakpointRules = {
217
+ xs: '',
218
+ sm: breakpointVarRules.sm + breakpointPropRules.sm,
219
+ md: breakpointVarRules.md + breakpointPropRules.md,
220
+ lg: breakpointVarRules.lg + breakpointPropRules.lg,
221
+ xl: breakpointVarRules.xl + breakpointPropRules.xl,
222
+ xxl: breakpointVarRules.xxl + breakpointPropRules.xxl
223
+ };
224
+
225
+ // Add media queries for each breakpoint with rules (skip xs)
226
+ Object.entries(breakpointRules).forEach(([breakpoint, rules]) => {
227
+ if (rules && breakpoint !== 'xs') {
228
+ const bp = breakpoint;
229
+ const minWidth = breakpointValues[bp];
230
+ _styleManager.StyleManager.addRule(`@media (min-width: ${minWidth}px)`, `.${componentId} { ${rules} }`, {
231
+ nonce: csp === null || csp === void 0 ? void 0 : csp.nonce
232
+ });
233
+ }
234
+ });
235
+ }
236
+ return () => {
237
+ // Clean up rules when component unmounts
238
+ _styleManager.StyleManager.removeRule(`.${componentId}`);
239
+
240
+ // Clean up media query rules
241
+ Object.keys(breakpointValues).forEach(breakpoint => {
242
+ const bp = breakpoint;
243
+ const minWidth = breakpointValues[bp];
244
+ _styleManager.StyleManager.removeRule(`@media (min-width: ${minWidth}px)`);
245
+ });
246
+ };
247
+ }, [componentId, cssVars, shouldApplyStyles]);
248
+
249
+ // Combine class names
250
+ const combinedClassName = shouldApplyStyles ? `${className || ''} ${componentId}`.trim() : className;
251
+ return {
252
+ className: combinedClassName || undefined,
253
+ style,
254
+ id: componentId
255
+ };
256
+ }
257
+ var _default = exports.default = useStyled;
@@ -22,7 +22,7 @@ const getColorVar = color => {
22
22
 
23
23
  // Check if color is a color with shade (e.g., 'red.50', 'gray.900')
24
24
  const colorWithShadeRegex = /^(red|orange|yellow|green|cyan|blue|violet|gray)\.([1-9]00|50)$/;
25
- const match = color.match(colorWithShadeRegex);
25
+ const match = color === null || color === void 0 ? void 0 : color.match(colorWithShadeRegex);
26
26
  if (match) {
27
27
  const [, colorName, shade] = match;
28
28
  return `var(--rs-${colorName}-${shade})`;
@@ -3,7 +3,7 @@ import type { StyleProperties } from '../../types';
3
3
  /**
4
4
  * Processes and returns a value suitable for CSS (with a unit).
5
5
  */
6
- export declare function getCssValue(value?: number | string | null, unit?: string): string;
6
+ export declare function getCssValue(value?: number | string | null, unit?: string): string | undefined;
7
7
  /**
8
8
  * Merge multiple style objects, filtering out undefined values
9
9
  */
@@ -12,7 +12,7 @@ var _isEmpty = _interopRequireDefault(require("lodash/isEmpty"));
12
12
  */
13
13
  function getCssValue(value, unit = 'px') {
14
14
  if (value === undefined || value === null || value === '') {
15
- return '';
15
+ return undefined;
16
16
  }
17
17
 
18
18
  // If the value is 0, return it as a string without unit
@@ -2,3 +2,4 @@ export * from './styles';
2
2
  export * from './css';
3
3
  export * from './prefix';
4
4
  export * from './responsive';
5
+ export * from './style-manager';
@@ -25,4 +25,10 @@ Object.keys(_responsive).forEach(function (key) {
25
25
  if (key === "default" || key === "__esModule") return;
26
26
  if (key in exports && exports[key] === _responsive[key]) return;
27
27
  exports[key] = _responsive[key];
28
+ });
29
+ var _styleManager = require("./style-manager");
30
+ Object.keys(_styleManager).forEach(function (key) {
31
+ if (key === "default" || key === "__esModule") return;
32
+ if (key in exports && exports[key] === _styleManager[key]) return;
33
+ exports[key] = _styleManager[key];
28
34
  });
@@ -0,0 +1,50 @@
1
+ /**
2
+ * StyleManager - A utility for managing CSS styles dynamically
3
+ *
4
+ * This manager creates and maintains a single style element in the document head
5
+ * and provides methods to add, update, and remove CSS rules.
6
+ * Supports CSP nonce for Content Security Policy compliance.
7
+ */
8
+ export declare const StyleManager: {
9
+ styleElement: HTMLStyleElement | null;
10
+ styleMap: Map<string, string>;
11
+ nonce: string | undefined;
12
+ /**
13
+ * Initialize the style element if it doesn't exist
14
+ * @param options - Optional configuration options
15
+ * @param options.nonce - CSP nonce to apply to the style element
16
+ * @returns The style element
17
+ */
18
+ init(options?: {
19
+ nonce?: string;
20
+ }): HTMLStyleElement | null;
21
+ /**
22
+ * Set the CSP nonce for the style element
23
+ * @param nonce - CSP nonce value
24
+ */
25
+ setNonce(nonce?: string): void;
26
+ /**
27
+ * Add a CSS rule to the style sheet
28
+ * @param selector - CSS selector
29
+ * @param cssText - CSS properties and values
30
+ * @param options - Optional configuration options
31
+ * @param options.nonce - CSP nonce to apply to the style element
32
+ */
33
+ addRule(selector: string, cssText: string, options?: {
34
+ nonce?: string;
35
+ }): void;
36
+ /**
37
+ * Remove a CSS rule from the style sheet
38
+ * @param selector - CSS selector to remove
39
+ */
40
+ removeRule(selector: string): void;
41
+ /**
42
+ * Update the style element with all current rules
43
+ */
44
+ updateStyles(): void;
45
+ /**
46
+ * Clear all rules from the style sheet
47
+ */
48
+ clearRules(): void;
49
+ };
50
+ export default StyleManager;
@@ -0,0 +1,97 @@
1
+ 'use client';
2
+ "use strict";
3
+
4
+ exports.__esModule = true;
5
+ exports.default = exports.StyleManager = void 0;
6
+ /**
7
+ * StyleManager - A utility for managing CSS styles dynamically
8
+ *
9
+ * This manager creates and maintains a single style element in the document head
10
+ * and provides methods to add, update, and remove CSS rules.
11
+ * Supports CSP nonce for Content Security Policy compliance.
12
+ */
13
+
14
+ // Global style sheet manager
15
+ const StyleManager = exports.StyleManager = {
16
+ styleElement: null,
17
+ styleMap: new Map(),
18
+ nonce: undefined,
19
+ /**
20
+ * Initialize the style element if it doesn't exist
21
+ * @param options - Optional configuration options
22
+ * @param options.nonce - CSP nonce to apply to the style element
23
+ * @returns The style element
24
+ */
25
+ init(options) {
26
+ if (!this.styleElement && typeof document !== 'undefined') {
27
+ this.styleElement = document.createElement('style');
28
+ this.styleElement.setAttribute('data-rs-style-manager', '');
29
+
30
+ // Apply CSP nonce if provided
31
+ const nonce = (options === null || options === void 0 ? void 0 : options.nonce) || this.nonce;
32
+ if (nonce) {
33
+ this.styleElement.setAttribute('nonce', nonce);
34
+ this.nonce = nonce; // Store for future use
35
+ }
36
+ document.head.appendChild(this.styleElement);
37
+ }
38
+ return this.styleElement;
39
+ },
40
+ /**
41
+ * Set the CSP nonce for the style element
42
+ * @param nonce - CSP nonce value
43
+ */
44
+ setNonce(nonce) {
45
+ this.nonce = nonce;
46
+
47
+ // Apply to existing style element if it exists
48
+ if (this.styleElement && nonce) {
49
+ this.styleElement.setAttribute('nonce', nonce);
50
+ }
51
+ },
52
+ /**
53
+ * Add a CSS rule to the style sheet
54
+ * @param selector - CSS selector
55
+ * @param cssText - CSS properties and values
56
+ * @param options - Optional configuration options
57
+ * @param options.nonce - CSP nonce to apply to the style element
58
+ */
59
+ addRule(selector, cssText, options) {
60
+ this.init(options);
61
+ if (!this.styleMap.has(selector) || this.styleMap.get(selector) !== cssText) {
62
+ this.styleMap.set(selector, cssText);
63
+ this.updateStyles();
64
+ }
65
+ },
66
+ /**
67
+ * Remove a CSS rule from the style sheet
68
+ * @param selector - CSS selector to remove
69
+ */
70
+ removeRule(selector) {
71
+ if (this.styleMap.has(selector)) {
72
+ this.styleMap.delete(selector);
73
+ this.updateStyles();
74
+ }
75
+ },
76
+ /**
77
+ * Update the style element with all current rules
78
+ */
79
+ updateStyles() {
80
+ if (!this.styleElement) return;
81
+ let cssText = '';
82
+ this.styleMap.forEach((rules, selector) => {
83
+ cssText += `${selector} { ${rules} }\n`;
84
+ });
85
+ this.styleElement.textContent = cssText;
86
+ },
87
+ /**
88
+ * Clear all rules from the style sheet
89
+ */
90
+ clearRules() {
91
+ this.styleMap.clear();
92
+ if (this.styleElement) {
93
+ this.styleElement.textContent = '';
94
+ }
95
+ }
96
+ };
97
+ var _default = exports.default = StyleManager;