baseline-kit 2.0.0

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 (47) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +334 -0
  3. package/dist/README.md +334 -0
  4. package/dist/components/Baseline/Baseline.d.ts +48 -0
  5. package/dist/components/Baseline/index.d.ts +6 -0
  6. package/dist/components/Box/Box.d.ts +62 -0
  7. package/dist/components/Box/index.d.ts +6 -0
  8. package/dist/components/Config/Config.d.ts +136 -0
  9. package/dist/components/Config/defaults.d.ts +25 -0
  10. package/dist/components/Config/index.d.ts +11 -0
  11. package/dist/components/Guide/Guide.d.ts +60 -0
  12. package/dist/components/Guide/index.d.ts +12 -0
  13. package/dist/components/Guide/types.d.ts +144 -0
  14. package/dist/components/Guide/validation.d.ts +82 -0
  15. package/dist/components/Layout/Layout.d.ts +69 -0
  16. package/dist/components/Layout/index.d.ts +10 -0
  17. package/dist/components/Padder/Padder.d.ts +61 -0
  18. package/dist/components/Padder/index.d.ts +10 -0
  19. package/dist/components/Spacer/Spacer.d.ts +55 -0
  20. package/dist/components/Spacer/index.d.ts +10 -0
  21. package/dist/components/Stack/Stack.d.ts +77 -0
  22. package/dist/components/Stack/index.d.ts +10 -0
  23. package/dist/components/index.d.ts +15 -0
  24. package/dist/components/types.d.ts +102 -0
  25. package/dist/hooks/index.d.ts +11 -0
  26. package/dist/hooks/useBaseline.d.ts +72 -0
  27. package/dist/hooks/useConfig.d.ts +46 -0
  28. package/dist/hooks/useDebug.d.ts +54 -0
  29. package/dist/hooks/useGuide.d.ts +66 -0
  30. package/dist/hooks/useMeasure.d.ts +49 -0
  31. package/dist/hooks/useVirtual.d.ts +65 -0
  32. package/dist/index.cjs +32 -0
  33. package/dist/index.cjs.map +1 -0
  34. package/dist/index.d.ts +10 -0
  35. package/dist/index.mjs +1592 -0
  36. package/dist/index.mjs.map +1 -0
  37. package/dist/styles.css +1 -0
  38. package/dist/utils/convert.d.ts +46 -0
  39. package/dist/utils/index.d.ts +13 -0
  40. package/dist/utils/math.d.ts +64 -0
  41. package/dist/utils/merge.d.ts +68 -0
  42. package/dist/utils/normalize.d.ts +65 -0
  43. package/dist/utils/padding.d.ts +11 -0
  44. package/dist/utils/parse.d.ts +52 -0
  45. package/dist/utils/snapping.d.ts +33 -0
  46. package/dist/utils/timing.d.ts +50 -0
  47. package/package.json +113 -0
@@ -0,0 +1,61 @@
1
+ /**
2
+ * @file Padder Component
3
+ * @description Low-level padding management with visual debugging
4
+ * @module components
5
+ */
6
+ import * as React from 'react';
7
+ import { IndicatorNode } from '../Spacer';
8
+ /**
9
+ * A foundational component that manages consistent padding with visual debugging.
10
+ *
11
+ * @remarks
12
+ * Padder is a low-level utility that:
13
+ * - Applies consistent padding around content
14
+ * - Supports visual debugging of spacing
15
+ * - Maintains baseline grid alignment
16
+ * - Uses Spacer components for visual padding representation
17
+ *
18
+ * When debugging is enabled (`"visible"` or `"hidden"`), padding is represented
19
+ * using Spacer components. When debugging is `"none"`, direct CSS padding is
20
+ * applied for better performance.
21
+ *
22
+ * @example
23
+ * ```tsx
24
+ * // Basic usage
25
+ * <Padder block={16} inline={8}>
26
+ * <div>Content with consistent padding</div>
27
+ * </Padder>
28
+ *
29
+ * // With debug visuals and custom indicators
30
+ * <Padder
31
+ * block={[8, 16]}
32
+ * inline={[16, 24]}
33
+ * debugging="visible"
34
+ * indicatorNode={(value, dim) => (
35
+ * <span className="text-sm">{dim}: {value}px</span>
36
+ * )}
37
+ * >
38
+ * <div>Content with visible padding guides</div>
39
+ * </Padder>
40
+ *
41
+ * // Direct padding mode
42
+ * <Padder
43
+ * block={16}
44
+ * inline={24}
45
+ * debugging="none"
46
+ * >
47
+ * <div>Content with direct CSS padding</div>
48
+ * </Padder>
49
+ * ```
50
+ */
51
+ export declare const Padder: React.NamedExoticComponent<{
52
+ /** Render function for custom measurement indicators */
53
+ indicatorNode?: IndicatorNode;
54
+ children?: React.ReactNode;
55
+ } & {
56
+ debugging?: import("..").DebuggingMode;
57
+ className?: string;
58
+ style?: React.CSSProperties;
59
+ height?: React.CSSProperties["height"];
60
+ width?: React.CSSProperties["width"];
61
+ } & import("..").SpacingProps & React.RefAttributes<HTMLDivElement>>;
@@ -0,0 +1,10 @@
1
+ /**
2
+ * @file Padder Component Entry (components/Padder/index.ts)
3
+ * @description Low-level padding management with debugging support
4
+ * @module baseline-kit/components/Padder
5
+ *
6
+ * @remarks
7
+ * Core component for managing padding and spacing visualization
8
+ * in the baseline grid system.
9
+ */
10
+ export * from './Padder';
@@ -0,0 +1,55 @@
1
+ /**
2
+ * @file Spacer Component
3
+ * @description Flexible spacing element with measurement indicators
4
+ * @module components
5
+ */
6
+ import * as React from 'react';
7
+ import { ComponentsProps, Variant } from '../types';
8
+ /**
9
+ * Function signature for custom measurement indicators.
10
+ *
11
+ * @param value - The measurement in pixels
12
+ * @param dimension - Which dimension is being measured ('width' | 'height')
13
+ * @returns React node to display as the indicator
14
+ */
15
+ export type IndicatorNode = (value: number, dimension: 'width' | 'height') => React.ReactNode;
16
+ export type SpacerProps = {
17
+ /** Render function for custom measurement display */
18
+ indicatorNode?: IndicatorNode;
19
+ /** Visual style when debugging is enabled */
20
+ variant?: Variant;
21
+ /** Base unit for measurements (defaults to theme value) */
22
+ base?: number;
23
+ /** Color override for visual indicators */
24
+ color?: string;
25
+ } & ComponentsProps;
26
+ /**
27
+ * A flexible layout element that adds precise vertical or horizontal spacing.
28
+ *
29
+ * @remarks
30
+ * Spacer provides:
31
+ * - Consistent spacing in layouts
32
+ * - Optional measurement indicators for debugging
33
+ * - Multiple visual styles for different debugging needs
34
+ * - Automatic dimension normalization
35
+ *
36
+ * @example
37
+ * ```tsx
38
+ * // Basic vertical spacing
39
+ * <Spacer
40
+ * height="24px"
41
+ * base={8}
42
+ * />
43
+ *
44
+ * // Custom style with indicators
45
+ * <Spacer
46
+ * width="32px"
47
+ * height="100%"
48
+ * base={4}
49
+ * color="#ff0000"
50
+ * debugging="visible"
51
+ * indicatorNode={(value, dim) => `${dim}: ${value}px`}
52
+ * />
53
+ * ```
54
+ */
55
+ export declare const Spacer: React.NamedExoticComponent<SpacerProps>;
@@ -0,0 +1,10 @@
1
+ /**
2
+ * @file Spacer Component Entry (components/Spacer/index.ts)
3
+ * @description Spacing management component with measurement indicators
4
+ * @module baseline-kit/components/Spacer
5
+ *
6
+ * @remarks
7
+ * Provides both horizontal and vertical spacing with optional
8
+ * visual debugging features.
9
+ */
10
+ export * from './Spacer';
@@ -0,0 +1,77 @@
1
+ /**
2
+ * @file Stack Component
3
+ * @description Flex container with baseline grid alignment
4
+ * @module components
5
+ */
6
+ import * as React from 'react';
7
+ import type { Gaps, IndicatorNode } from '@components';
8
+ import { ComponentsProps, Variant } from '../types';
9
+ export type StackProps = {
10
+ /** Main axis orientation */
11
+ direction?: 'row' | 'column';
12
+ /** Distribution of space on main axis */
13
+ justify?: React.CSSProperties['justifyContent'];
14
+ /** Alignment on cross axis */
15
+ align?: React.CSSProperties['alignItems'];
16
+ /** Container width (defaults to "fit-content") */
17
+ width?: React.CSSProperties['width'];
18
+ /** Container height (defaults to "fit-content") */
19
+ height?: React.CSSProperties['height'];
20
+ /** Custom measurement indicator renderer */
21
+ indicatorNode?: IndicatorNode;
22
+ /** Visual style in debug mode */
23
+ variant?: Variant;
24
+ children?: React.ReactNode;
25
+ } & ComponentsProps & Gaps;
26
+ /**
27
+ * A flexible container component aligning children to the baseline grid.
28
+ *
29
+ * @remarks
30
+ * Stack provides a flex container that:
31
+ * - Maintains baseline grid alignment
32
+ * - Supports both row and column layouts
33
+ * - Handles consistent spacing between items
34
+ * - Includes visual debug overlays
35
+ *
36
+ * Key features:
37
+ * - Automatic dimension management (defaults to fit-content)
38
+ * - Direct padding application in non-debug mode
39
+ * - Comprehensive alignment controls
40
+ * - Theme-aware debug visuals
41
+ *
42
+ * @example
43
+ * ```tsx
44
+ * // Basic horizontal stack
45
+ * <Stack gap={16}>
46
+ * <div>Item 1</div>
47
+ * <div>Item 2</div>
48
+ * </Stack>
49
+ *
50
+ * // Vertical stack with alignment
51
+ * <Stack
52
+ * direction="column"
53
+ * gap={24}
54
+ * align="center"
55
+ * justify="space-between"
56
+ * debugging="visible"
57
+ * >
58
+ * <div>Top</div>
59
+ * <div>Middle</div>
60
+ * <div>Bottom</div>
61
+ * </Stack>
62
+ *
63
+ * // Complex layout with padding
64
+ * <Stack
65
+ * direction="row"
66
+ * gap={32}
67
+ * align="stretch"
68
+ * block={[16, 24]}
69
+ * inline={16}
70
+ * debugging="visible"
71
+ * >
72
+ * <div>Panel 1</div>
73
+ * <div>Panel 2</div>
74
+ * </Stack>
75
+ * ```
76
+ */
77
+ export declare const Stack: React.NamedExoticComponent<StackProps>;
@@ -0,0 +1,10 @@
1
+ /**
2
+ * @file Stack/Flex Component Entry (components/Stack/index.ts)
3
+ * @description Flexible container with baseline grid alignment
4
+ * @module baseline-kit/components/Stack
5
+ *
6
+ * @remarks
7
+ * While the component is called Stack internally, it's exported as Flex
8
+ * for API consistency.
9
+ */
10
+ export * from './Stack';
@@ -0,0 +1,15 @@
1
+ /**
2
+ * @file Component Exports (components/index.ts)
3
+ * @description Main entry point for baseline-kit components
4
+ * @module baseline-kit/components
5
+ */
6
+ import './styles/index.css';
7
+ export * from './Layout';
8
+ export * from './Box';
9
+ export * from './Stack';
10
+ export * from './Guide';
11
+ export * from './Baseline';
12
+ export * from './Spacer';
13
+ export * from './Padder';
14
+ export * from './Config';
15
+ export * from './types';
@@ -0,0 +1,102 @@
1
+ import * as React from 'react';
2
+ import { DebuggingMode } from '@components';
3
+ /**
4
+ * Defines spacing as either a single value, start/end pair, or object with explicit edges.
5
+ * Used for block and inline spacing across components.
6
+ *
7
+ * @example
8
+ * ```tsx
9
+ * // Single value
10
+ * <Box block={8} />
11
+ *
12
+ * // Start/end pair
13
+ * <Box block={[8, 16]} />
14
+ *
15
+ * // Object with explicit values
16
+ * <Box block={{ start: 8, end: 16 }} />
17
+ * ```
18
+ */
19
+ export type Spacing = number | [number, number] | {
20
+ start?: number;
21
+ end?: number;
22
+ };
23
+ /**
24
+ * Flexible padding definition that supports multiple formats for setting padding on all sides.
25
+ *
26
+ * @example
27
+ * ```tsx
28
+ * // Single value for all sides
29
+ * padding={8}
30
+ *
31
+ * // Block and inline pairs
32
+ * padding={[8, 16]}
33
+ *
34
+ * // Explicit values for each side
35
+ * padding={[8, 16, 8, 16]}
36
+ *
37
+ * // Object with named sides
38
+ * padding={{ top: 8, right: 16, bottom: 8, left: 16 }}
39
+ * ```
40
+ */
41
+ export type PaddingValue = number | [number, number] | [number, number, number, number] | {
42
+ top?: number;
43
+ bottom?: number;
44
+ left?: number;
45
+ right?: number;
46
+ };
47
+ /** Resolved padding values for all edges after normalization. */
48
+ export type Padding = {
49
+ top: number;
50
+ right: number;
51
+ bottom: number;
52
+ left: number;
53
+ };
54
+ /** Props interface for components that support spacing configuration. */
55
+ export type SpacingProps = {
56
+ padding?: PaddingValue;
57
+ block?: Spacing;
58
+ inline?: Spacing;
59
+ };
60
+ /** Controls how columns are laid out in grid components. */
61
+ export type GuideVariant = 'line' | 'pattern' | 'fixed' | 'auto';
62
+ /**
63
+ * Valid value types for grid columns. Can be a CSS length, fractional unit,
64
+ * or 'auto' for automatic sizing.
65
+ */
66
+ export type GuideColumnValue = string | number | undefined | 'auto';
67
+ /** Array of column definitions for pattern-based grid layouts. */
68
+ export type GuideColumnsPattern = readonly GuideColumnValue[];
69
+ /** Valid grid alignment values. */
70
+ export declare const GRID_ALIGNMENTS: readonly ["start", "center", "end"];
71
+ export type GridAlignment = typeof GRID_ALIGNMENTS[number];
72
+ /** Valid component variants affecting visual style. */
73
+ export declare const PADD_VARIANTS: readonly ["line", "flat"];
74
+ export type PaddedVariant = typeof PADD_VARIANTS[number];
75
+ /**
76
+ * Common props shared across library components.
77
+ * Provides consistent sizing, spacing, styling, and debugging options.
78
+ */
79
+ export type ComponentsProps = {
80
+ debugging?: DebuggingMode;
81
+ className?: string;
82
+ style?: React.CSSProperties;
83
+ height?: React.CSSProperties['height'];
84
+ width?: React.CSSProperties['width'];
85
+ } & SpacingProps;
86
+ /** Base configuration for components that support padding. */
87
+ export type PaddedBaseConfig = {
88
+ base?: number;
89
+ color?: React.CSSProperties['color'] | React.CSSProperties['backgroundColor'];
90
+ zIndex?: React.CSSProperties['zIndex'];
91
+ };
92
+ export type Variant = 'line' | 'flat' | 'pattern';
93
+ export type Gaps = {
94
+ gap?: React.CSSProperties['gap'];
95
+ rowGap?: never;
96
+ columnGap?: never;
97
+ } | {
98
+ /** When using separate gaps, omit unified gap */
99
+ gap?: never;
100
+ rowGap?: React.CSSProperties['rowGap'];
101
+ columnGap?: React.CSSProperties['columnGap'];
102
+ };
@@ -0,0 +1,11 @@
1
+ /**
2
+ * @file Hook Exports (hooks/index.ts)
3
+ * @description React hooks for baseline-kit functionality
4
+ * @module baseline-kit/hooks
5
+ */
6
+ export * from './useMeasure';
7
+ export * from './useVirtual';
8
+ export * from './useBaseline';
9
+ export * from './useGuide';
10
+ export * from './useConfig';
11
+ export * from './useDebug';
@@ -0,0 +1,72 @@
1
+ /**
2
+ * @file useBaseline Hook
3
+ * @description Manages baseline grid alignment calculations
4
+ * @module hooks
5
+ */
6
+ import { RefObject } from 'react';
7
+ import { SnappingMode, Padding } from '@components';
8
+ export interface BaselineOptions {
9
+ /** Base unit for alignment calculations (default: 8) */
10
+ base?: number;
11
+ /** Alignment strategy to apply (default: 'none') */
12
+ snapping?: SnappingMode;
13
+ /** Initial spacing configuration */
14
+ spacing?: Partial<Padding> | number;
15
+ /** Enable console warnings for misalignments */
16
+ warnOnMisalignment?: boolean;
17
+ }
18
+ export interface BaselineResult {
19
+ /** Final adjusted padding values */
20
+ padding: Padding;
21
+ /** Whether the measured height is a multiple of base */
22
+ isAligned: boolean;
23
+ /** Raw measured height in pixels */
24
+ height: number;
25
+ }
26
+ /**
27
+ * Hook for managing baseline grid alignment in components.
28
+ *
29
+ * @remarks
30
+ * This hook handles the complex calculations needed to maintain baseline grid
31
+ * alignment, including:
32
+ * - Measuring element dimensions
33
+ * - Calculating padding adjustments
34
+ * - Snapping values to the grid
35
+ * - Warning about misalignments
36
+ *
37
+ * Different snapping modes affect how spacing is adjusted:
38
+ * - 'none': Uses raw spacing values without adjustment
39
+ * - 'height': Adjusts only the final height to align
40
+ * - 'clamp': Adjusts both height and spacing values
41
+ *
42
+ * @param ref - Reference to the DOM element to measure
43
+ * @param options - Configuration options for alignment behavior
44
+ * @returns Object containing adjusted padding, alignment status, and height
45
+ *
46
+ * @example
47
+ * ```tsx
48
+ * function MyComponent() {
49
+ * const ref = useRef<HTMLDivElement>(null);
50
+ * const { padding, isAligned } = useBaseline(ref, {
51
+ * base: 8,
52
+ * snapping: 'height',
53
+ * spacing: { top: 10, bottom: 20 }
54
+ * });
55
+ *
56
+ * return (
57
+ * <div
58
+ * ref={ref}
59
+ * style={{
60
+ * paddingTop: padding.top,
61
+ * paddingBottom: padding.bottom
62
+ * }}
63
+ * >
64
+ * Content
65
+ * </div>
66
+ * );
67
+ * }
68
+ * ```
69
+ *
70
+ * @throws {Error} if base is less than 1
71
+ */
72
+ export declare function useBaseline(ref: RefObject<HTMLElement | null>, { base, snapping, spacing, warnOnMisalignment, }?: BaselineOptions): BaselineResult;
@@ -0,0 +1,46 @@
1
+ /**
2
+ * @file useConfig Hook
3
+ * @description Manages component-specific theme configuration
4
+ * @module hooks
5
+ */
6
+ import { Config } from '@components';
7
+ /** Type helper that merges base configuration with component-specific settings. */
8
+ export type ComponentConfig<K extends keyof Config> = Config[K] & {
9
+ /** Base unit for spacing calculations */
10
+ base: number;
11
+ };
12
+ /**
13
+ * Hook for accessing component-specific theme configuration.
14
+ *
15
+ * @remarks
16
+ * This hook provides:
17
+ * - Access to component-specific theme settings
18
+ * - Automatic base unit inheritance
19
+ * - Memoized configuration to prevent unnecessary updates
20
+ * - Type-safe configuration access
21
+ *
22
+ * It merges:
23
+ * - Global base unit settings
24
+ * - Component-specific configurations
25
+ * - Theme-based color schemes
26
+ *
27
+ * @param component - Name of the component requesting configuration
28
+ * @returns Merged configuration for the specific component
29
+ *
30
+ * @example
31
+ * ```tsx
32
+ * function Box() {
33
+ * const config = useConfig('box');
34
+ *
35
+ * return (
36
+ * <div style={{
37
+ * '--box-base': `${config.base}px`,
38
+ * '--box-color': config.colors.line
39
+ * }}>
40
+ * {children}
41
+ * </div>
42
+ * );
43
+ * }
44
+ * ```
45
+ */
46
+ export declare function useConfig<K extends keyof Config>(component: K): ComponentConfig<K>;
@@ -0,0 +1,54 @@
1
+ /**
2
+ * @file useDebug Hook
3
+ * @description Manages component debugging state
4
+ * @module hooks
5
+ */
6
+ import { DebuggingMode } from '@components';
7
+ interface DebugResult {
8
+ /** Whether debug visuals should be shown */
9
+ isShown: boolean;
10
+ /** Whether debug features exist but are hidden */
11
+ isHidden: boolean;
12
+ /** Whether debug features are disabled */
13
+ isNone: boolean;
14
+ /** Current debugging mode */
15
+ debugging: DebuggingMode | undefined;
16
+ }
17
+ /**
18
+ * Hook for managing component debug state and visibility.
19
+ *
20
+ * @remarks
21
+ * Determines the active debugging mode by:
22
+ * - Using prop value if provided
23
+ * - Falling back to config value if prop is undefined
24
+ * - Computing visibility states based on active mode
25
+ *
26
+ * This hook helps components:
27
+ * - Control debug visual rendering
28
+ * - Manage debug feature states
29
+ * - Handle prop/config inheritance
30
+ *
31
+ * @param debuggingProp - Optional debugging mode from props
32
+ * @param debuggingConfig - Debugging mode from theme/config
33
+ * @returns Debug state information
34
+ *
35
+ * @example
36
+ * ```tsx
37
+ * function DebugComponent({ debugging: debugProp }) {
38
+ * const { isShown, isHidden, isNone } = useDebug(
39
+ * debugProp,
40
+ * 'hidden' // Default from config
41
+ * );
42
+ *
43
+ * return (
44
+ * <div>
45
+ * {isShown && <DebugOverlay />}
46
+ * {!isNone && <DebugFeatures />}
47
+ * <Content />
48
+ * </div>
49
+ * );
50
+ * }
51
+ * ```
52
+ */
53
+ export declare function useDebug(debuggingProp?: DebuggingMode, debuggingConfig?: DebuggingMode): DebugResult;
54
+ export {};
@@ -0,0 +1,66 @@
1
+ /**
2
+ * @file useGuide Hook
3
+ * @description Manages grid layout calculations for guide overlays
4
+ * @module hooks
5
+ */
6
+ import { RefObject } from 'react';
7
+ import { GuideConfig } from '@components';
8
+ export interface GuideResult {
9
+ /** CSS grid template string */
10
+ template: string;
11
+ /** Total number of columns */
12
+ columnsCount: number;
13
+ /** Final gap size in pixels */
14
+ calculatedGap: number;
15
+ /** Whether the configuration is valid */
16
+ isValid: boolean;
17
+ }
18
+ /**
19
+ * Hook for calculating grid layout parameters based on container dimensions.
20
+ *
21
+ * @remarks
22
+ * This hook handles complex grid calculations for different layout variants:
23
+ * - 'line': Evenly spaced vertical lines
24
+ * - 'pattern': Custom repeating column patterns
25
+ * - 'fixed': Set number of columns with optional width
26
+ * - 'auto': Dynamic columns based on available space
27
+ *
28
+ * Key features:
29
+ * - Responsive grid calculations
30
+ * - Pattern validation
31
+ * - Gap management
32
+ * - Error handling
33
+ *
34
+ * @param ref - Reference to container element
35
+ * @param config - Grid configuration object
36
+ * @returns Grid calculation results
37
+ *
38
+ * @example
39
+ * ```tsx
40
+ * function GridOverlay() {
41
+ * const ref = useRef<HTMLDivElement>(null);
42
+ * const { template, columnsCount } = useGuide(ref, {
43
+ * variant: 'fixed',
44
+ * columns: 12,
45
+ * gap: 16,
46
+ * base: 8
47
+ * });
48
+ *
49
+ * return (
50
+ * <div
51
+ * ref={ref}
52
+ * style={{
53
+ * display: 'grid',
54
+ * gridTemplateColumns: template,
55
+ * gap: calculatedGap
56
+ * }}
57
+ * >
58
+ * {Array(columnsCount).fill(null).map((_, i) => (
59
+ * <div key={i} className="grid-line" />
60
+ * ))}
61
+ * </div>
62
+ * );
63
+ * }
64
+ * ```
65
+ */
66
+ export declare function useGuide(ref: RefObject<HTMLElement | null>, config: GuideConfig): GuideResult;
@@ -0,0 +1,49 @@
1
+ /**
2
+ * @file useMeasure Hook
3
+ * @description Tracks element dimensions using ResizeObserver
4
+ * @module hooks
5
+ */
6
+ import { RefObject } from 'react';
7
+ export interface MeasureResult {
8
+ /** Measured width in pixels */
9
+ width: number;
10
+ /** Measured height in pixels */
11
+ height: number;
12
+ /** Function to force a remeasurement */
13
+ refresh: () => void;
14
+ }
15
+ /**
16
+ * Hook for measuring and tracking DOM element dimensions.
17
+ *
18
+ * @remarks
19
+ * Provides responsive element measurements using ResizeObserver, with:
20
+ * - Performance optimization via RAF throttling
21
+ * - Cache to prevent unnecessary updates
22
+ * - Error handling and recovery
23
+ * - Manual refresh capability
24
+ *
25
+ * The hook automatically:
26
+ * - Initializes with 0x0 dimensions
27
+ * - Updates on element resize
28
+ * - Cleans up observers on unmount
29
+ * - Rounds dimensions to whole pixels
30
+ *
31
+ * @param ref - Reference to the DOM element to measure
32
+ * @returns Current dimensions and refresh function
33
+ *
34
+ * @example
35
+ * ```tsx
36
+ * function ResponsiveBox() {
37
+ * const ref = useRef<HTMLDivElement>(null);
38
+ * const { width, height, refresh } = useMeasure(ref);
39
+ *
40
+ * return (
41
+ * <div ref={ref} className="responsive-box">
42
+ * Width: {width}px, Height: {height}px
43
+ * <button onClick={refresh}>Remeasure</button>
44
+ * </div>
45
+ * );
46
+ * }
47
+ * ```
48
+ */
49
+ export declare function useMeasure(ref: RefObject<HTMLElement | null>): MeasureResult;