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.
- package/LICENSE +21 -0
- package/README.md +334 -0
- package/dist/README.md +334 -0
- package/dist/components/Baseline/Baseline.d.ts +48 -0
- package/dist/components/Baseline/index.d.ts +6 -0
- package/dist/components/Box/Box.d.ts +62 -0
- package/dist/components/Box/index.d.ts +6 -0
- package/dist/components/Config/Config.d.ts +136 -0
- package/dist/components/Config/defaults.d.ts +25 -0
- package/dist/components/Config/index.d.ts +11 -0
- package/dist/components/Guide/Guide.d.ts +60 -0
- package/dist/components/Guide/index.d.ts +12 -0
- package/dist/components/Guide/types.d.ts +144 -0
- package/dist/components/Guide/validation.d.ts +82 -0
- package/dist/components/Layout/Layout.d.ts +69 -0
- package/dist/components/Layout/index.d.ts +10 -0
- package/dist/components/Padder/Padder.d.ts +61 -0
- package/dist/components/Padder/index.d.ts +10 -0
- package/dist/components/Spacer/Spacer.d.ts +55 -0
- package/dist/components/Spacer/index.d.ts +10 -0
- package/dist/components/Stack/Stack.d.ts +77 -0
- package/dist/components/Stack/index.d.ts +10 -0
- package/dist/components/index.d.ts +15 -0
- package/dist/components/types.d.ts +102 -0
- package/dist/hooks/index.d.ts +11 -0
- package/dist/hooks/useBaseline.d.ts +72 -0
- package/dist/hooks/useConfig.d.ts +46 -0
- package/dist/hooks/useDebug.d.ts +54 -0
- package/dist/hooks/useGuide.d.ts +66 -0
- package/dist/hooks/useMeasure.d.ts +49 -0
- package/dist/hooks/useVirtual.d.ts +65 -0
- package/dist/index.cjs +32 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.mjs +1592 -0
- package/dist/index.mjs.map +1 -0
- package/dist/styles.css +1 -0
- package/dist/utils/convert.d.ts +46 -0
- package/dist/utils/index.d.ts +13 -0
- package/dist/utils/math.d.ts +64 -0
- package/dist/utils/merge.d.ts +68 -0
- package/dist/utils/normalize.d.ts +65 -0
- package/dist/utils/padding.d.ts +11 -0
- package/dist/utils/parse.d.ts +52 -0
- package/dist/utils/snapping.d.ts +33 -0
- package/dist/utils/timing.d.ts +50 -0
- package/package.json +113 -0
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
export interface NormalizationOptions {
|
|
2
|
+
/** Base unit for normalization */
|
|
3
|
+
base?: number;
|
|
4
|
+
/** Whether to round to nearest base multiple */
|
|
5
|
+
round?: boolean;
|
|
6
|
+
/** Optional value clamping */
|
|
7
|
+
clamp?: {
|
|
8
|
+
min?: number;
|
|
9
|
+
max?: number;
|
|
10
|
+
};
|
|
11
|
+
/** Suppress warning messages */
|
|
12
|
+
suppressWarnings?: boolean;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Normalizes CSS values to a consistent format based on base unit.
|
|
16
|
+
*
|
|
17
|
+
* @remarks
|
|
18
|
+
* Handles:
|
|
19
|
+
* - CSS length values
|
|
20
|
+
* - Numeric values
|
|
21
|
+
* - Special values (auto)
|
|
22
|
+
* - Rounding to base unit
|
|
23
|
+
* - Value clamping
|
|
24
|
+
*
|
|
25
|
+
* @param value - Value to normalize
|
|
26
|
+
* @param options - Normalization configuration
|
|
27
|
+
* @returns Normalized numeric value
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* ```ts
|
|
31
|
+
* // Base unit normalization
|
|
32
|
+
* normalizeValue(14, { base: 8 }) // => 16
|
|
33
|
+
*
|
|
34
|
+
* // With clamping
|
|
35
|
+
* normalizeValue(14, {
|
|
36
|
+
* base: 8,
|
|
37
|
+
* clamp: { min: 8, max: 24 }
|
|
38
|
+
* }) // => 16
|
|
39
|
+
*
|
|
40
|
+
* // Without rounding
|
|
41
|
+
* normalizeValue(14, {
|
|
42
|
+
* base: 8,
|
|
43
|
+
* round: false
|
|
44
|
+
* }) // => 14
|
|
45
|
+
* ```
|
|
46
|
+
*/
|
|
47
|
+
export declare function normalizeValue(value: string | number | undefined, options?: NormalizationOptions): number;
|
|
48
|
+
/**
|
|
49
|
+
* Normalizes a pair of CSS values.
|
|
50
|
+
*
|
|
51
|
+
* @param values - Tuple of values to normalize
|
|
52
|
+
* @param defaults - Default values if input is undefined
|
|
53
|
+
* @param options - Normalization options
|
|
54
|
+
* @returns Tuple of normalized values
|
|
55
|
+
*
|
|
56
|
+
* @example
|
|
57
|
+
* ```ts
|
|
58
|
+
* normalizeValuePair(
|
|
59
|
+
* ['14px', '20px'],
|
|
60
|
+
* [0, 0],
|
|
61
|
+
* { base: 8 }
|
|
62
|
+
* ) // => [16, 24]
|
|
63
|
+
* ```
|
|
64
|
+
*/
|
|
65
|
+
export declare function normalizeValuePair(values: [string | number | undefined, string | number | undefined] | undefined, defaults: [number, number], options?: NormalizationOptions): [number, number];
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Padding, SpacingProps } from '@components';
|
|
2
|
+
/**
|
|
3
|
+
* Extract numeric top, right, bottom, left (in px) from `padding` or `block/inline`.
|
|
4
|
+
* @param spacing - The props which may include padding, block, inline
|
|
5
|
+
* @returns { top, right, bottom, left } with 0 defaults
|
|
6
|
+
*
|
|
7
|
+
* Priority (if padding is defined, it overrides block/inline):
|
|
8
|
+
* - If `padding` is present, parse it fully (4 edges).
|
|
9
|
+
* - Otherwise, parse `block` for top/bottom and `inline` for left/right.
|
|
10
|
+
*/
|
|
11
|
+
export declare function parsePadding(spacing: SpacingProps): Padding;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file parse.ts
|
|
3
|
+
* @description CSS value parsing utilities
|
|
4
|
+
* @module utils
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Parses a CSS unit string into its numeric value and unit.
|
|
8
|
+
*
|
|
9
|
+
* @remarks
|
|
10
|
+
* Handles:
|
|
11
|
+
* - Integer and decimal values
|
|
12
|
+
* - All CSS units (px, em, rem, etc.)
|
|
13
|
+
* - Percentage values
|
|
14
|
+
* - Sign prefixes (+ and -)
|
|
15
|
+
*
|
|
16
|
+
* @param value - CSS value string to parse
|
|
17
|
+
* @returns Object with value and unit, or null if parsing fails
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* ```ts
|
|
21
|
+
* parseUnit('100px') // => { value: 100, unit: 'px' }
|
|
22
|
+
* parseUnit('1.5rem') // => { value: 1.5, unit: 'rem' }
|
|
23
|
+
* parseUnit('-20%') // => { value: -20, unit: '%' }
|
|
24
|
+
* parseUnit('invalid') // => null
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
export declare function parseUnit(value: string): {
|
|
28
|
+
value: number;
|
|
29
|
+
unit: string;
|
|
30
|
+
} | null;
|
|
31
|
+
/**
|
|
32
|
+
* Formats a value as a valid CSS string.
|
|
33
|
+
*
|
|
34
|
+
* @remarks
|
|
35
|
+
* Handles:
|
|
36
|
+
* - Numbers (adds px suffix)
|
|
37
|
+
* - Special values (auto, 100%, etc.)
|
|
38
|
+
* - Undefined values with defaults
|
|
39
|
+
*
|
|
40
|
+
* @param value - Value to format
|
|
41
|
+
* @param defaultValue - Optional default if value is undefined
|
|
42
|
+
* @returns Formatted CSS string
|
|
43
|
+
*
|
|
44
|
+
* @example
|
|
45
|
+
* ```ts
|
|
46
|
+
* formatValue(14) // => "14px"
|
|
47
|
+
* formatValue('auto') // => "auto"
|
|
48
|
+
* formatValue(undefined, 10) // => "10px"
|
|
49
|
+
* formatValue('1fr') // => "1fr"
|
|
50
|
+
* ```
|
|
51
|
+
*/
|
|
52
|
+
export declare function formatValue(value: string | number | undefined, defaultValue?: number): string;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file snapping.ts
|
|
3
|
+
* @description Baseline grid snapping utilities
|
|
4
|
+
* @module utils
|
|
5
|
+
*/
|
|
6
|
+
import { SnappingMode, Padding, PaddingValue } from '@components';
|
|
7
|
+
/**
|
|
8
|
+
* Calculates spacing adjustments to maintain baseline grid alignment.
|
|
9
|
+
*
|
|
10
|
+
* @remarks
|
|
11
|
+
* Provides different snapping behaviors:
|
|
12
|
+
* - none: No adjustments
|
|
13
|
+
* - height: Adjusts bottom padding only
|
|
14
|
+
* - clamp: Adjusts both top and bottom padding
|
|
15
|
+
*
|
|
16
|
+
* @param height - Measured element height
|
|
17
|
+
* @param base - Grid base unit
|
|
18
|
+
* @param initial - Initial spacing values
|
|
19
|
+
* @param snapping - Snapping mode to apply
|
|
20
|
+
* @returns Adjusted spacing values
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* ```ts
|
|
24
|
+
* // Height snapping mode
|
|
25
|
+
* calculateSnappedSpacing(46, 8, { top: 10, bottom: 10 }, 'height')
|
|
26
|
+
* // => { top: 10, right: 0, bottom: 12, left: 0 }
|
|
27
|
+
*
|
|
28
|
+
* // Clamp mode
|
|
29
|
+
* calculateSnappedSpacing(45, 8, { top: 10, bottom: 6 }, 'clamp')
|
|
30
|
+
* // => { top: 2, right: 0, bottom: 1, left: 0 }
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
export declare function calculateSnappedSpacing(height: number, base: number, initial: PaddingValue, snapping: SnappingMode): Padding;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file timing.ts
|
|
3
|
+
* @description Performance optimization utilities
|
|
4
|
+
* @module utils
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Creates a debounced version of a function.
|
|
8
|
+
*
|
|
9
|
+
* @remarks
|
|
10
|
+
* Useful for:
|
|
11
|
+
* - Handling rapid event sequences
|
|
12
|
+
* - Limiting API calls
|
|
13
|
+
* - Performance optimization
|
|
14
|
+
*
|
|
15
|
+
* @param fn - Function to debounce
|
|
16
|
+
* @param delay - Delay in milliseconds
|
|
17
|
+
* @returns Debounced function
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* ```ts
|
|
21
|
+
* const handleResize = debounce(() => {
|
|
22
|
+
* // Expensive calculation
|
|
23
|
+
* }, 100);
|
|
24
|
+
*
|
|
25
|
+
* window.addEventListener('resize', handleResize);
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
export declare const debounce: <T extends (...args: unknown[]) => void>(fn: T, delay: number) => T;
|
|
29
|
+
/**
|
|
30
|
+
* Creates a requestAnimationFrame-based throttled function.
|
|
31
|
+
*
|
|
32
|
+
* @remarks
|
|
33
|
+
* Optimizes performance by:
|
|
34
|
+
* - Limiting execution to animation frames
|
|
35
|
+
* - Preventing rapid-fire calls
|
|
36
|
+
* - Maintaining visual smoothness
|
|
37
|
+
*
|
|
38
|
+
* @param fn - Function to throttle
|
|
39
|
+
* @returns RAF-throttled function
|
|
40
|
+
*
|
|
41
|
+
* @example
|
|
42
|
+
* ```ts
|
|
43
|
+
* const updateScroll = rafThrottle(() => {
|
|
44
|
+
* // Update scroll position
|
|
45
|
+
* });
|
|
46
|
+
*
|
|
47
|
+
* document.addEventListener('scroll', updateScroll);
|
|
48
|
+
* ```
|
|
49
|
+
*/
|
|
50
|
+
export declare const rafThrottle: <T extends (...args: unknown[]) => void>(fn: T) => T;
|
package/package.json
ADDED
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
{
|
|
2
|
+
"scripts": {
|
|
3
|
+
"lint": "eslint src/lib --fix",
|
|
4
|
+
"build:type": "tsc -p tsconfig.build.json",
|
|
5
|
+
"prepare": "bun run build && bun run build:type",
|
|
6
|
+
"version": "changeset version",
|
|
7
|
+
"test:coverage": "vitest run --coverage",
|
|
8
|
+
"release": "changeset publish",
|
|
9
|
+
"typecheck": "tsc --noEmit",
|
|
10
|
+
"test:ui": "vitest --ui",
|
|
11
|
+
"dev": "vite",
|
|
12
|
+
"test:ci": "vitest run",
|
|
13
|
+
"format": "prettier --write \"src/lib/**/*.{ts,tsx,css}\"",
|
|
14
|
+
"prepublishOnly": "bun run build && bun run build:type",
|
|
15
|
+
"changeset": "changeset",
|
|
16
|
+
"test": "vitest",
|
|
17
|
+
"build": "vite build"
|
|
18
|
+
},
|
|
19
|
+
"peerDependencies": {
|
|
20
|
+
"react": "19.0.0",
|
|
21
|
+
"react-dom": "19.0.0",
|
|
22
|
+
"typescript": "^5.7.3"
|
|
23
|
+
},
|
|
24
|
+
"main": "dist/index.cjs",
|
|
25
|
+
"engines": {
|
|
26
|
+
"node": ">=18"
|
|
27
|
+
},
|
|
28
|
+
"keywords": [
|
|
29
|
+
"react",
|
|
30
|
+
"grid",
|
|
31
|
+
"layout",
|
|
32
|
+
"typescript",
|
|
33
|
+
"baseline",
|
|
34
|
+
"guide",
|
|
35
|
+
"box",
|
|
36
|
+
"layout",
|
|
37
|
+
"typography",
|
|
38
|
+
"spacing",
|
|
39
|
+
"stack",
|
|
40
|
+
"padding",
|
|
41
|
+
"debug",
|
|
42
|
+
"dev-tool",
|
|
43
|
+
"pixel-perfect",
|
|
44
|
+
"vertical-rhythm"
|
|
45
|
+
],
|
|
46
|
+
"repository": {
|
|
47
|
+
"type": "git",
|
|
48
|
+
"url": "git+https://github.com/dnvt/baseline-kit.git"
|
|
49
|
+
},
|
|
50
|
+
"devDependencies": {
|
|
51
|
+
"@changesets/cli": "^2.27.12",
|
|
52
|
+
"@testing-library/jest-dom": "^6.6.3",
|
|
53
|
+
"@testing-library/react": "^16.2.0",
|
|
54
|
+
"@types/node": "^22.13.0",
|
|
55
|
+
"@types/react": "^19.0.8",
|
|
56
|
+
"@types/react-dom": "^19.0.3",
|
|
57
|
+
"@typescript-eslint/eslint-plugin": "^6.21.0",
|
|
58
|
+
"@typescript-eslint/parser": "^6.21.0",
|
|
59
|
+
"@vitejs/plugin-react-swc": "^3.7.2",
|
|
60
|
+
"@vitest/coverage-v8": "^2.1.8",
|
|
61
|
+
"autoprefixer": "^10.4.20",
|
|
62
|
+
"cssnano": "^7.0.6",
|
|
63
|
+
"eslint": "^8.57.1",
|
|
64
|
+
"eslint-config-prettier": "^9.1.0",
|
|
65
|
+
"eslint-plugin-react": "^7.37.4",
|
|
66
|
+
"eslint-plugin-react-hooks": "^4.6.2",
|
|
67
|
+
"jsdom": "^25.0.1",
|
|
68
|
+
"prettier": "^3.4.2",
|
|
69
|
+
"rollup": "^4.34.0",
|
|
70
|
+
"rollup-plugin-dts": "^6.1.1",
|
|
71
|
+
"rollup-plugin-visualizer": "^5.14.0",
|
|
72
|
+
"vite": "^6.1.0",
|
|
73
|
+
"vite-plugin-static-copy": "^2.2.0",
|
|
74
|
+
"vitest": "^2.1.8"
|
|
75
|
+
},
|
|
76
|
+
"name": "baseline-kit",
|
|
77
|
+
"version": "2.0.0",
|
|
78
|
+
"type": "module",
|
|
79
|
+
"homepage": "https://github.com/dnvt/baseline-kit#readme",
|
|
80
|
+
"types": "dist/index.d.ts",
|
|
81
|
+
"exports": {
|
|
82
|
+
".": {
|
|
83
|
+
"types": "./dist/index.d.ts",
|
|
84
|
+
"import": "./dist/index.mjs",
|
|
85
|
+
"require": "./dist/index.cjs"
|
|
86
|
+
},
|
|
87
|
+
"./styles.css": "./dist/styles.css"
|
|
88
|
+
},
|
|
89
|
+
"files": [
|
|
90
|
+
"dist",
|
|
91
|
+
"LICENSE",
|
|
92
|
+
"README.md"
|
|
93
|
+
],
|
|
94
|
+
"style": "dist/styles.css",
|
|
95
|
+
"sideEffects": [
|
|
96
|
+
"dist/styles.css"
|
|
97
|
+
],
|
|
98
|
+
"bugs": {
|
|
99
|
+
"url": "https://github.com/dnvt/baseline-kit/issues"
|
|
100
|
+
},
|
|
101
|
+
"license": "MIT",
|
|
102
|
+
"module": "dist/index.mjs",
|
|
103
|
+
"publishConfig": {
|
|
104
|
+
"access": "public",
|
|
105
|
+
"registry": "https://registry.npmjs.org/"
|
|
106
|
+
},
|
|
107
|
+
"author": "Francois Denavaut",
|
|
108
|
+
"description": "Baseline Kit is a lightweight development tool for visualizing and debugging grid systems and spacing in React applications. It provides configurable overlays for both column-based and baseline grids, flexible spacing components, and theme-aware configuration—all optimized for performance and built with TypeScript.",
|
|
109
|
+
"dependencies": {
|
|
110
|
+
"esbuild": "^0.24.2",
|
|
111
|
+
"postcss-preset-env": "^10.1.3"
|
|
112
|
+
}
|
|
113
|
+
}
|