@refineui/utilities 0.0.1

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/lib/index.cjs ADDED
@@ -0,0 +1,351 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+
30
+ // src/index.ts
31
+ var index_exports = {};
32
+ __export(index_exports, {
33
+ acquireBodyScrollLock: () => acquireBodyScrollLock,
34
+ ariaAttr: () => ariaAttr,
35
+ buttonProps: () => buttonProps,
36
+ composeRef: () => composeRef,
37
+ composeRefs: () => composeRefs,
38
+ createAnimationStyle: () => createAnimationStyle,
39
+ createTransitionStyle: () => createTransitionStyle,
40
+ dataAttr: () => dataAttr,
41
+ elementProps: () => elementProps,
42
+ foundationTypographyToken: () => foundationTypographyToken,
43
+ foundationTypographyUtilityClass: () => foundationTypographyUtilityClass,
44
+ getMergeableTriggerChild: () => getMergeableTriggerChild,
45
+ getReducedMotionQuery: () => getReducedMotionQuery,
46
+ hexToRgba: () => hexToRgba,
47
+ imgProps: () => imgProps,
48
+ inputProps: () => inputProps,
49
+ isColorTokenRef: () => isColorTokenRef,
50
+ isSemanticTextTokenRef: () => isSemanticTextTokenRef,
51
+ labelProps: () => labelProps,
52
+ motionDurations: () => motionDurations,
53
+ motionEasings: () => motionEasings,
54
+ motionKeyframesCss: () => motionKeyframesCss,
55
+ motionMsToNumber: () => motionMsToNumber,
56
+ motionPresets: () => motionPresets,
57
+ paletteColorCssVar: () => paletteColorCssVar,
58
+ paletteColorToken: () => paletteColorToken,
59
+ resolveColorToken: () => resolveColorToken,
60
+ resolveColorTokenValue: () => resolveColorTokenValue,
61
+ semanticColorCssVar: () => semanticColorCssVar,
62
+ semanticColorToken: () => semanticColorToken,
63
+ semanticTextToken: () => semanticTextToken,
64
+ shadowWithColor: () => shadowWithColor,
65
+ toKebab: () => toKebab,
66
+ useComposedRefs: () => useComposedRefs
67
+ });
68
+ module.exports = __toCommonJS(index_exports);
69
+
70
+ // src/animation.ts
71
+ var motionDurations = {
72
+ // Resolve via `@refineui/tokens` CSS (Foundation → semanticInteraction roles)
73
+ instant: "var(--refineui-motion-duration-instant)",
74
+ fast: "var(--refineui-motion-duration-fast)",
75
+ normal: "var(--refineui-motion-duration-normal)",
76
+ slow: "var(--refineui-motion-duration-slow)",
77
+ toast: "var(--refineui-motion-duration-panel)"
78
+ };
79
+ var motionEasings = {
80
+ standard: "var(--refineui-motion-easing-standard)",
81
+ emphasized: "var(--refineui-motion-easing-emphasized)",
82
+ linear: "var(--refineui-motion-easing-linear)"
83
+ };
84
+ var motionPresets = {
85
+ fadeIn: { keyframes: "refineui-fade-in", duration: "normal", easing: "standard", fillMode: "both" },
86
+ fadeOut: { keyframes: "refineui-fade-out", duration: "normal", easing: "standard", fillMode: "both" },
87
+ fadeInUp: { keyframes: "refineui-fade-in-up", duration: "normal", easing: "standard", fillMode: "both" },
88
+ fadeInDown: { keyframes: "refineui-fade-in-down", duration: "normal", easing: "standard", fillMode: "both" },
89
+ scaleIn: { keyframes: "refineui-scale-in", duration: "normal", easing: "emphasized", fillMode: "both" },
90
+ scaleOut: { keyframes: "refineui-scale-out", duration: "normal", easing: "emphasized", fillMode: "both" }
91
+ };
92
+ function createAnimationStyle(options) {
93
+ const preset = motionPresets[options.preset];
94
+ const duration = options.duration ?? preset.duration;
95
+ const easing = options.easing ?? preset.easing;
96
+ if (options.reduceMotion) {
97
+ return {
98
+ animationName: "none",
99
+ animationDuration: motionDurations.instant,
100
+ animationDelay: "0ms"
101
+ };
102
+ }
103
+ return {
104
+ animationName: preset.keyframes,
105
+ animationDuration: typeof duration === "string" && duration in motionDurations ? motionDurations[duration] : duration,
106
+ animationTimingFunction: typeof easing === "string" && easing in motionEasings ? motionEasings[easing] : easing,
107
+ animationDelay: `${Math.max(0, options.delayMs ?? 0)}ms`,
108
+ animationIterationCount: options.iterationCount ?? 1,
109
+ animationDirection: options.direction ?? "normal",
110
+ animationPlayState: options.playState ?? "running",
111
+ animationFillMode: options.fillMode ?? preset.fillMode ?? "both"
112
+ };
113
+ }
114
+ function createTransitionStyle(options) {
115
+ const duration = options.duration ?? "fast";
116
+ const easing = options.easing ?? "standard";
117
+ const props = Array.isArray(options.properties) ? options.properties.join(", ") : options.properties;
118
+ if (options.reduceMotion) {
119
+ return {
120
+ transitionProperty: props,
121
+ transitionDuration: motionDurations.instant,
122
+ transitionTimingFunction: motionEasings.linear,
123
+ transitionDelay: "0ms"
124
+ };
125
+ }
126
+ return {
127
+ transitionProperty: props,
128
+ transitionDuration: typeof duration === "string" && duration in motionDurations ? motionDurations[duration] : duration,
129
+ transitionTimingFunction: typeof easing === "string" && easing in motionEasings ? motionEasings[easing] : easing,
130
+ transitionDelay: `${Math.max(0, options.delayMs ?? 0)}ms`
131
+ };
132
+ }
133
+ function getReducedMotionQuery() {
134
+ return "@media (prefers-reduced-motion: reduce)";
135
+ }
136
+ function motionMsToNumber(value) {
137
+ if (value.endsWith("ms")) return Number.parseFloat(value.slice(0, -2)) || 0;
138
+ if (value.endsWith("s")) return (Number.parseFloat(value.slice(0, -1)) || 0) * 1e3;
139
+ return Number.parseFloat(value) || 0;
140
+ }
141
+ var motionKeyframesCss = `
142
+ @keyframes refineui-fade-in {
143
+ from { opacity: 0; }
144
+ to { opacity: 1; }
145
+ }
146
+ @keyframes refineui-fade-out {
147
+ from { opacity: 1; }
148
+ to { opacity: 0; }
149
+ }
150
+ @keyframes refineui-fade-in-up {
151
+ from { opacity: 0; transform: translateY(4px); }
152
+ to { opacity: 1; transform: translateY(0); }
153
+ }
154
+ @keyframes refineui-fade-in-down {
155
+ from { opacity: 0; transform: translateY(-4px); }
156
+ to { opacity: 1; transform: translateY(0); }
157
+ }
158
+ @keyframes refineui-scale-in {
159
+ from { opacity: 0; transform: scale(0.98); }
160
+ to { opacity: 1; transform: scale(1); }
161
+ }
162
+ @keyframes refineui-scale-out {
163
+ from { opacity: 1; transform: scale(1); }
164
+ to { opacity: 0; transform: scale(0.98); }
165
+ }
166
+ `;
167
+
168
+ // src/color.ts
169
+ function toKebab(str) {
170
+ return str.replace(/([a-z0-9])([A-Z])/g, "$1-$2").replace(/([A-Z]+)([A-Z][a-z])/g, "$1-$2").replace(/([a-zA-Z])(\d)/g, "$1-$2").toLowerCase();
171
+ }
172
+ function semanticColorToken(name) {
173
+ return { type: "semantic", name };
174
+ }
175
+ function paletteColorToken(name) {
176
+ return { type: "palette", name };
177
+ }
178
+ function semanticColorCssVar(name) {
179
+ return `var(--refineui-color-alias-${toKebab(name)})`;
180
+ }
181
+ function paletteColorCssVar(name) {
182
+ return `var(--refineui-color-${toKebab(name)})`;
183
+ }
184
+ function resolveColorToken(token) {
185
+ return token.type === "semantic" ? semanticColorCssVar(token.name) : paletteColorCssVar(token.name);
186
+ }
187
+ function isColorTokenRef(value) {
188
+ if (typeof value !== "object" || value === null) return false;
189
+ const candidate = value;
190
+ if (candidate.type !== "semantic" && candidate.type !== "palette") return false;
191
+ return typeof candidate.name === "string";
192
+ }
193
+ function resolveColorTokenValue(value) {
194
+ return typeof value === "string" ? value : resolveColorToken(value);
195
+ }
196
+ function hexToRgba(hex, alpha) {
197
+ const h = hex.replace("#", "");
198
+ const r = h.length === 3 ? parseInt(h[0] + h[0], 16) : parseInt(h.slice(0, 2), 16);
199
+ const g = h.length === 3 ? parseInt(h[1] + h[1], 16) : parseInt(h.slice(2, 4), 16);
200
+ const b = h.length === 3 ? parseInt(h[2] + h[2], 16) : parseInt(h.slice(4, 6), 16);
201
+ return `rgba(${r}, ${g}, ${b}, ${alpha})`;
202
+ }
203
+ function shadowWithColor(keyDim, ambientDim, keyColor, ambientColor) {
204
+ return `${keyDim} ${keyColor}, ${ambientDim} ${ambientColor}`;
205
+ }
206
+
207
+ // src/dom.ts
208
+ var dataAttr = (guard) => {
209
+ return guard ? "" : void 0;
210
+ };
211
+ var ariaAttr = (guard) => {
212
+ return guard ? "true" : void 0;
213
+ };
214
+ var elementProps = (props) => props;
215
+ var inputProps = (props) => props;
216
+ var labelProps = (props) => props;
217
+ var buttonProps = (props) => props;
218
+ var imgProps = (props) => props;
219
+
220
+ // src/bodyScrollLock.ts
221
+ var lockCount = 0;
222
+ var bodyOverflow = "";
223
+ var htmlOverflow = "";
224
+ var bodyPosition = "";
225
+ var bodyTop = "";
226
+ var bodyWidth = "";
227
+ var lockedScrollY = 0;
228
+ function applyLock() {
229
+ if (typeof document === "undefined") return;
230
+ lockedScrollY = window.scrollY;
231
+ bodyOverflow = document.body.style.overflow;
232
+ htmlOverflow = document.documentElement.style.overflow;
233
+ bodyPosition = document.body.style.position;
234
+ bodyTop = document.body.style.top;
235
+ bodyWidth = document.body.style.width;
236
+ document.body.style.overflow = "hidden";
237
+ document.documentElement.style.overflow = "hidden";
238
+ document.body.style.position = "fixed";
239
+ document.body.style.top = `-${lockedScrollY}px`;
240
+ document.body.style.width = "100%";
241
+ }
242
+ function releaseLock() {
243
+ if (typeof document === "undefined") return;
244
+ document.body.style.overflow = bodyOverflow;
245
+ document.documentElement.style.overflow = htmlOverflow;
246
+ document.body.style.position = bodyPosition;
247
+ document.body.style.top = bodyTop;
248
+ document.body.style.width = bodyWidth;
249
+ window.scrollTo(0, lockedScrollY);
250
+ }
251
+ function acquireBodyScrollLock() {
252
+ if (typeof document === "undefined") return () => {
253
+ };
254
+ lockCount += 1;
255
+ if (lockCount === 1) applyLock();
256
+ return () => {
257
+ lockCount -= 1;
258
+ if (lockCount <= 0) {
259
+ lockCount = 0;
260
+ releaseLock();
261
+ }
262
+ };
263
+ }
264
+
265
+ // src/composeRefs.ts
266
+ var React = __toESM(require("react"), 1);
267
+ function setRef(ref, value) {
268
+ if (typeof ref === "function") {
269
+ ref(value);
270
+ } else if (ref != null) {
271
+ ref.current = value;
272
+ }
273
+ }
274
+ function composeRefs(...refs) {
275
+ return (instance) => refs.forEach((ref) => setRef(ref, instance));
276
+ }
277
+ function useComposedRefs(...refs) {
278
+ return React.useCallback(composeRefs(...refs), refs);
279
+ }
280
+ var composeRef = composeRefs;
281
+
282
+ // src/mergeTriggerChild.ts
283
+ var import_react = require("react");
284
+ function getMergeableTriggerChild(children) {
285
+ let node;
286
+ try {
287
+ node = import_react.Children.only(children);
288
+ } catch {
289
+ return null;
290
+ }
291
+ if (!(0, import_react.isValidElement)(node)) return null;
292
+ if (node.type === import_react.Fragment) {
293
+ const inner = import_react.Children.toArray(node.props.children);
294
+ if (inner.length !== 1 || !(0, import_react.isValidElement)(inner[0])) return null;
295
+ return inner[0];
296
+ }
297
+ return node;
298
+ }
299
+
300
+ // src/typography.ts
301
+ function semanticTextToken(name) {
302
+ return { type: "semantic-text", name };
303
+ }
304
+ function foundationTypographyToken(name) {
305
+ return { type: "foundation-typography", name };
306
+ }
307
+ function foundationTypographyUtilityClass(foundationKey) {
308
+ return `refineui-typo-${toKebab(foundationKey)}`;
309
+ }
310
+ function isSemanticTextTokenRef(value) {
311
+ if (typeof value !== "object" || value === null) return false;
312
+ const candidate = value;
313
+ return candidate.type === "semantic-text" && typeof candidate.name === "string";
314
+ }
315
+ // Annotate the CommonJS export names for ESM import in node:
316
+ 0 && (module.exports = {
317
+ acquireBodyScrollLock,
318
+ ariaAttr,
319
+ buttonProps,
320
+ composeRef,
321
+ composeRefs,
322
+ createAnimationStyle,
323
+ createTransitionStyle,
324
+ dataAttr,
325
+ elementProps,
326
+ foundationTypographyToken,
327
+ foundationTypographyUtilityClass,
328
+ getMergeableTriggerChild,
329
+ getReducedMotionQuery,
330
+ hexToRgba,
331
+ imgProps,
332
+ inputProps,
333
+ isColorTokenRef,
334
+ isSemanticTextTokenRef,
335
+ labelProps,
336
+ motionDurations,
337
+ motionEasings,
338
+ motionKeyframesCss,
339
+ motionMsToNumber,
340
+ motionPresets,
341
+ paletteColorCssVar,
342
+ paletteColorToken,
343
+ resolveColorToken,
344
+ resolveColorTokenValue,
345
+ semanticColorCssVar,
346
+ semanticColorToken,
347
+ semanticTextToken,
348
+ shadowWithColor,
349
+ toKebab,
350
+ useComposedRefs
351
+ });
@@ -0,0 +1,132 @@
1
+ import * as React from 'react';
2
+ import { CSSProperties, Ref, ReactNode, ReactElement } from 'react';
3
+
4
+ declare const motionDurations: {
5
+ readonly instant: "var(--refineui-motion-duration-instant)";
6
+ readonly fast: "var(--refineui-motion-duration-fast)";
7
+ readonly normal: "var(--refineui-motion-duration-normal)";
8
+ readonly slow: "var(--refineui-motion-duration-slow)";
9
+ readonly toast: "var(--refineui-motion-duration-panel)";
10
+ };
11
+ declare const motionEasings: {
12
+ readonly standard: "var(--refineui-motion-easing-standard)";
13
+ readonly emphasized: "var(--refineui-motion-easing-emphasized)";
14
+ readonly linear: "var(--refineui-motion-easing-linear)";
15
+ };
16
+ type MotionDuration = keyof typeof motionDurations;
17
+ type MotionEasing = keyof typeof motionEasings;
18
+ type MotionPresetName = "fadeIn" | "fadeOut" | "fadeInUp" | "fadeInDown" | "scaleIn" | "scaleOut";
19
+ type MotionPreset = Readonly<{
20
+ keyframes: string;
21
+ duration: MotionDuration;
22
+ easing: MotionEasing;
23
+ fillMode?: CSSProperties["animationFillMode"];
24
+ }>;
25
+ declare const motionPresets: Readonly<Record<MotionPresetName, MotionPreset>>;
26
+ type AnimationStyleOptions = Readonly<{
27
+ preset: MotionPresetName;
28
+ duration?: MotionDuration | string;
29
+ easing?: MotionEasing | string;
30
+ delayMs?: number;
31
+ iterationCount?: CSSProperties["animationIterationCount"];
32
+ direction?: CSSProperties["animationDirection"];
33
+ playState?: CSSProperties["animationPlayState"];
34
+ fillMode?: CSSProperties["animationFillMode"];
35
+ reduceMotion?: boolean;
36
+ }>;
37
+ declare function createAnimationStyle(options: AnimationStyleOptions): CSSProperties;
38
+ type TransitionStyleOptions = Readonly<{
39
+ properties: string | readonly string[];
40
+ duration?: MotionDuration | string;
41
+ easing?: MotionEasing | string;
42
+ delayMs?: number;
43
+ reduceMotion?: boolean;
44
+ }>;
45
+ declare function createTransitionStyle(options: TransitionStyleOptions): CSSProperties;
46
+ declare function getReducedMotionQuery(): string;
47
+ /** "180ms" -> 180 */
48
+ declare function motionMsToNumber(value: string): number;
49
+ /**
50
+ * Optional CSS you can include once in a global stylesheet.
51
+ * If you use `createAnimationStyle`, ensure these keyframes exist.
52
+ */
53
+ declare const motionKeyframesCss = "\n@keyframes refineui-fade-in {\n from { opacity: 0; }\n to { opacity: 1; }\n}\n@keyframes refineui-fade-out {\n from { opacity: 1; }\n to { opacity: 0; }\n}\n@keyframes refineui-fade-in-up {\n from { opacity: 0; transform: translateY(4px); }\n to { opacity: 1; transform: translateY(0); }\n}\n@keyframes refineui-fade-in-down {\n from { opacity: 0; transform: translateY(-4px); }\n to { opacity: 1; transform: translateY(0); }\n}\n@keyframes refineui-scale-in {\n from { opacity: 0; transform: scale(0.98); }\n to { opacity: 1; transform: scale(1); }\n}\n@keyframes refineui-scale-out {\n from { opacity: 1; transform: scale(1); }\n to { opacity: 0; transform: scale(0.98); }\n}\n";
54
+
55
+ type SemanticColorTokenRef<TName extends string = string> = Readonly<{
56
+ type: "semantic";
57
+ name: TName;
58
+ }>;
59
+ type PaletteColorTokenRef<TName extends string = string> = Readonly<{
60
+ type: "palette";
61
+ name: TName;
62
+ }>;
63
+ type ColorTokenRef = SemanticColorTokenRef | PaletteColorTokenRef;
64
+ type ColorTokenValue = ColorTokenRef | string;
65
+ declare function toKebab(str: string): string;
66
+ declare function semanticColorToken<TName extends string>(name: TName): SemanticColorTokenRef<TName>;
67
+ declare function paletteColorToken<TName extends string>(name: TName): PaletteColorTokenRef<TName>;
68
+ declare function semanticColorCssVar(name: string): string;
69
+ declare function paletteColorCssVar(name: string): string;
70
+ declare function resolveColorToken(token: ColorTokenRef): string;
71
+ declare function isColorTokenRef(value: unknown): value is ColorTokenRef;
72
+ declare function resolveColorTokenValue<T extends string>(value: T): T;
73
+ declare function resolveColorTokenValue(value: ColorTokenRef): string;
74
+ /**
75
+ * Convert hex to rgba (e.g. palette colors)
76
+ */
77
+ declare function hexToRgba(hex: string, alpha: number): string;
78
+ /** Build a box-shadow string from dimensions (x y blur spread) + colors */
79
+ declare function shadowWithColor(keyDim: string, ambientDim: string, keyColor: string, ambientColor: string): string;
80
+
81
+ type Booleanish = boolean | "true" | "false";
82
+ declare const dataAttr: (guard: boolean | undefined) => "" | undefined;
83
+ declare const ariaAttr: (guard: boolean | undefined) => Booleanish | undefined;
84
+ type DataAttr = {
85
+ [key in `data-${string}`]?: string | undefined;
86
+ };
87
+ type WithoutRef<T> = Omit<T, "ref">;
88
+ declare const elementProps: (props: React.HTMLAttributes<HTMLElement> & DataAttr) => WithoutRef<React.HTMLAttributes<HTMLElement>>;
89
+ declare const inputProps: (props: React.InputHTMLAttributes<HTMLInputElement> & DataAttr) => WithoutRef<React.InputHTMLAttributes<HTMLInputElement>>;
90
+ declare const labelProps: (props: React.LabelHTMLAttributes<HTMLLabelElement> & DataAttr) => WithoutRef<React.LabelHTMLAttributes<HTMLLabelElement>>;
91
+ declare const buttonProps: (props: React.ButtonHTMLAttributes<HTMLButtonElement> & DataAttr) => WithoutRef<React.ButtonHTMLAttributes<HTMLButtonElement>>;
92
+ declare const imgProps: (props: React.ImgHTMLAttributes<HTMLImageElement> & DataAttr) => WithoutRef<React.ImgHTMLAttributes<HTMLImageElement>>;
93
+
94
+ /**
95
+ * Root document scroll lock with ref-counting for nested overlays.
96
+ *
97
+ * Radix often uses `react-remove-scroll` with portals/focus scope.
98
+ * RefineUI locks only document `overflow`/`position` without extra dependencies.
99
+ */
100
+ /**
101
+ * Block background (document) scroll while menus/modals are open.
102
+ * @returns Release function — call on unmount/close
103
+ */
104
+ declare function acquireBodyScrollLock(): () => void;
105
+
106
+ declare function composeRefs<T>(...refs: (Ref<T> | undefined)[]): (instance: T | null) => void;
107
+ /** Radix `useComposedRefs` — stable ref callback when merging cloneElement + forwardRef */
108
+ declare function useComposedRefs<T>(...refs: (Ref<T> | undefined)[]): (instance: T | null) => void;
109
+ /** @deprecated Prefer `composeRefs` */
110
+ declare const composeRef: typeof composeRefs;
111
+
112
+ /**
113
+ * Resolve a single mergeable child so events/refs attach to one element.
114
+ * (Unwraps one Fragment layer; otherwise returns `null` — caller supplies a default button/span wrapper.)
115
+ */
116
+ declare function getMergeableTriggerChild(children: ReactNode): ReactElement | null;
117
+
118
+ type SemanticTextTokenRef<TName extends string = string> = Readonly<{
119
+ type: "semantic-text";
120
+ name: TName;
121
+ }>;
122
+ type FoundationTypographyTokenRef<TName extends string = string> = Readonly<{
123
+ type: "foundation-typography";
124
+ name: TName;
125
+ }>;
126
+ declare function semanticTextToken<TName extends string>(name: TName): SemanticTextTokenRef<TName>;
127
+ declare function foundationTypographyToken<TName extends string>(name: TName): FoundationTypographyTokenRef<TName>;
128
+ /** Tailwind `@utility refineui-typo-*` class for a Foundation typography key (`body2`, `caption1`, …). */
129
+ declare function foundationTypographyUtilityClass(foundationKey: string): string;
130
+ declare function isSemanticTextTokenRef(value: unknown): value is SemanticTextTokenRef;
131
+
132
+ export { type AnimationStyleOptions, type ColorTokenRef, type ColorTokenValue, type FoundationTypographyTokenRef, type MotionDuration, type MotionEasing, type MotionPresetName, type PaletteColorTokenRef, type SemanticColorTokenRef, type SemanticTextTokenRef, type TransitionStyleOptions, acquireBodyScrollLock, ariaAttr, buttonProps, composeRef, composeRefs, createAnimationStyle, createTransitionStyle, dataAttr, elementProps, foundationTypographyToken, foundationTypographyUtilityClass, getMergeableTriggerChild, getReducedMotionQuery, hexToRgba, imgProps, inputProps, isColorTokenRef, isSemanticTextTokenRef, labelProps, motionDurations, motionEasings, motionKeyframesCss, motionMsToNumber, motionPresets, paletteColorCssVar, paletteColorToken, resolveColorToken, resolveColorTokenValue, semanticColorCssVar, semanticColorToken, semanticTextToken, shadowWithColor, toKebab, useComposedRefs };
package/lib/index.d.ts ADDED
@@ -0,0 +1,132 @@
1
+ import * as React from 'react';
2
+ import { CSSProperties, Ref, ReactNode, ReactElement } from 'react';
3
+
4
+ declare const motionDurations: {
5
+ readonly instant: "var(--refineui-motion-duration-instant)";
6
+ readonly fast: "var(--refineui-motion-duration-fast)";
7
+ readonly normal: "var(--refineui-motion-duration-normal)";
8
+ readonly slow: "var(--refineui-motion-duration-slow)";
9
+ readonly toast: "var(--refineui-motion-duration-panel)";
10
+ };
11
+ declare const motionEasings: {
12
+ readonly standard: "var(--refineui-motion-easing-standard)";
13
+ readonly emphasized: "var(--refineui-motion-easing-emphasized)";
14
+ readonly linear: "var(--refineui-motion-easing-linear)";
15
+ };
16
+ type MotionDuration = keyof typeof motionDurations;
17
+ type MotionEasing = keyof typeof motionEasings;
18
+ type MotionPresetName = "fadeIn" | "fadeOut" | "fadeInUp" | "fadeInDown" | "scaleIn" | "scaleOut";
19
+ type MotionPreset = Readonly<{
20
+ keyframes: string;
21
+ duration: MotionDuration;
22
+ easing: MotionEasing;
23
+ fillMode?: CSSProperties["animationFillMode"];
24
+ }>;
25
+ declare const motionPresets: Readonly<Record<MotionPresetName, MotionPreset>>;
26
+ type AnimationStyleOptions = Readonly<{
27
+ preset: MotionPresetName;
28
+ duration?: MotionDuration | string;
29
+ easing?: MotionEasing | string;
30
+ delayMs?: number;
31
+ iterationCount?: CSSProperties["animationIterationCount"];
32
+ direction?: CSSProperties["animationDirection"];
33
+ playState?: CSSProperties["animationPlayState"];
34
+ fillMode?: CSSProperties["animationFillMode"];
35
+ reduceMotion?: boolean;
36
+ }>;
37
+ declare function createAnimationStyle(options: AnimationStyleOptions): CSSProperties;
38
+ type TransitionStyleOptions = Readonly<{
39
+ properties: string | readonly string[];
40
+ duration?: MotionDuration | string;
41
+ easing?: MotionEasing | string;
42
+ delayMs?: number;
43
+ reduceMotion?: boolean;
44
+ }>;
45
+ declare function createTransitionStyle(options: TransitionStyleOptions): CSSProperties;
46
+ declare function getReducedMotionQuery(): string;
47
+ /** "180ms" -> 180 */
48
+ declare function motionMsToNumber(value: string): number;
49
+ /**
50
+ * Optional CSS you can include once in a global stylesheet.
51
+ * If you use `createAnimationStyle`, ensure these keyframes exist.
52
+ */
53
+ declare const motionKeyframesCss = "\n@keyframes refineui-fade-in {\n from { opacity: 0; }\n to { opacity: 1; }\n}\n@keyframes refineui-fade-out {\n from { opacity: 1; }\n to { opacity: 0; }\n}\n@keyframes refineui-fade-in-up {\n from { opacity: 0; transform: translateY(4px); }\n to { opacity: 1; transform: translateY(0); }\n}\n@keyframes refineui-fade-in-down {\n from { opacity: 0; transform: translateY(-4px); }\n to { opacity: 1; transform: translateY(0); }\n}\n@keyframes refineui-scale-in {\n from { opacity: 0; transform: scale(0.98); }\n to { opacity: 1; transform: scale(1); }\n}\n@keyframes refineui-scale-out {\n from { opacity: 1; transform: scale(1); }\n to { opacity: 0; transform: scale(0.98); }\n}\n";
54
+
55
+ type SemanticColorTokenRef<TName extends string = string> = Readonly<{
56
+ type: "semantic";
57
+ name: TName;
58
+ }>;
59
+ type PaletteColorTokenRef<TName extends string = string> = Readonly<{
60
+ type: "palette";
61
+ name: TName;
62
+ }>;
63
+ type ColorTokenRef = SemanticColorTokenRef | PaletteColorTokenRef;
64
+ type ColorTokenValue = ColorTokenRef | string;
65
+ declare function toKebab(str: string): string;
66
+ declare function semanticColorToken<TName extends string>(name: TName): SemanticColorTokenRef<TName>;
67
+ declare function paletteColorToken<TName extends string>(name: TName): PaletteColorTokenRef<TName>;
68
+ declare function semanticColorCssVar(name: string): string;
69
+ declare function paletteColorCssVar(name: string): string;
70
+ declare function resolveColorToken(token: ColorTokenRef): string;
71
+ declare function isColorTokenRef(value: unknown): value is ColorTokenRef;
72
+ declare function resolveColorTokenValue<T extends string>(value: T): T;
73
+ declare function resolveColorTokenValue(value: ColorTokenRef): string;
74
+ /**
75
+ * Convert hex to rgba (e.g. palette colors)
76
+ */
77
+ declare function hexToRgba(hex: string, alpha: number): string;
78
+ /** Build a box-shadow string from dimensions (x y blur spread) + colors */
79
+ declare function shadowWithColor(keyDim: string, ambientDim: string, keyColor: string, ambientColor: string): string;
80
+
81
+ type Booleanish = boolean | "true" | "false";
82
+ declare const dataAttr: (guard: boolean | undefined) => "" | undefined;
83
+ declare const ariaAttr: (guard: boolean | undefined) => Booleanish | undefined;
84
+ type DataAttr = {
85
+ [key in `data-${string}`]?: string | undefined;
86
+ };
87
+ type WithoutRef<T> = Omit<T, "ref">;
88
+ declare const elementProps: (props: React.HTMLAttributes<HTMLElement> & DataAttr) => WithoutRef<React.HTMLAttributes<HTMLElement>>;
89
+ declare const inputProps: (props: React.InputHTMLAttributes<HTMLInputElement> & DataAttr) => WithoutRef<React.InputHTMLAttributes<HTMLInputElement>>;
90
+ declare const labelProps: (props: React.LabelHTMLAttributes<HTMLLabelElement> & DataAttr) => WithoutRef<React.LabelHTMLAttributes<HTMLLabelElement>>;
91
+ declare const buttonProps: (props: React.ButtonHTMLAttributes<HTMLButtonElement> & DataAttr) => WithoutRef<React.ButtonHTMLAttributes<HTMLButtonElement>>;
92
+ declare const imgProps: (props: React.ImgHTMLAttributes<HTMLImageElement> & DataAttr) => WithoutRef<React.ImgHTMLAttributes<HTMLImageElement>>;
93
+
94
+ /**
95
+ * Root document scroll lock with ref-counting for nested overlays.
96
+ *
97
+ * Radix often uses `react-remove-scroll` with portals/focus scope.
98
+ * RefineUI locks only document `overflow`/`position` without extra dependencies.
99
+ */
100
+ /**
101
+ * Block background (document) scroll while menus/modals are open.
102
+ * @returns Release function — call on unmount/close
103
+ */
104
+ declare function acquireBodyScrollLock(): () => void;
105
+
106
+ declare function composeRefs<T>(...refs: (Ref<T> | undefined)[]): (instance: T | null) => void;
107
+ /** Radix `useComposedRefs` — stable ref callback when merging cloneElement + forwardRef */
108
+ declare function useComposedRefs<T>(...refs: (Ref<T> | undefined)[]): (instance: T | null) => void;
109
+ /** @deprecated Prefer `composeRefs` */
110
+ declare const composeRef: typeof composeRefs;
111
+
112
+ /**
113
+ * Resolve a single mergeable child so events/refs attach to one element.
114
+ * (Unwraps one Fragment layer; otherwise returns `null` — caller supplies a default button/span wrapper.)
115
+ */
116
+ declare function getMergeableTriggerChild(children: ReactNode): ReactElement | null;
117
+
118
+ type SemanticTextTokenRef<TName extends string = string> = Readonly<{
119
+ type: "semantic-text";
120
+ name: TName;
121
+ }>;
122
+ type FoundationTypographyTokenRef<TName extends string = string> = Readonly<{
123
+ type: "foundation-typography";
124
+ name: TName;
125
+ }>;
126
+ declare function semanticTextToken<TName extends string>(name: TName): SemanticTextTokenRef<TName>;
127
+ declare function foundationTypographyToken<TName extends string>(name: TName): FoundationTypographyTokenRef<TName>;
128
+ /** Tailwind `@utility refineui-typo-*` class for a Foundation typography key (`body2`, `caption1`, …). */
129
+ declare function foundationTypographyUtilityClass(foundationKey: string): string;
130
+ declare function isSemanticTextTokenRef(value: unknown): value is SemanticTextTokenRef;
131
+
132
+ export { type AnimationStyleOptions, type ColorTokenRef, type ColorTokenValue, type FoundationTypographyTokenRef, type MotionDuration, type MotionEasing, type MotionPresetName, type PaletteColorTokenRef, type SemanticColorTokenRef, type SemanticTextTokenRef, type TransitionStyleOptions, acquireBodyScrollLock, ariaAttr, buttonProps, composeRef, composeRefs, createAnimationStyle, createTransitionStyle, dataAttr, elementProps, foundationTypographyToken, foundationTypographyUtilityClass, getMergeableTriggerChild, getReducedMotionQuery, hexToRgba, imgProps, inputProps, isColorTokenRef, isSemanticTextTokenRef, labelProps, motionDurations, motionEasings, motionKeyframesCss, motionMsToNumber, motionPresets, paletteColorCssVar, paletteColorToken, resolveColorToken, resolveColorTokenValue, semanticColorCssVar, semanticColorToken, semanticTextToken, shadowWithColor, toKebab, useComposedRefs };