@bingvader/fluid-scale 0.0.0-stage → 0.1.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/README.md +61 -2
- package/dist/index.cjs +4 -0
- package/dist/index.d.cts +21 -0
- package/dist/index.d.cts.map +1 -0
- package/dist/index.d.mts +21 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +1 -0
- package/dist/math-BwacRfp6.mjs +55 -0
- package/dist/math-BwacRfp6.mjs.map +1 -0
- package/dist/math-DKxTMW4W.cjs +64 -0
- package/dist/native/index.cjs +43 -0
- package/dist/native/index.d.cts +52 -0
- package/dist/native/index.d.cts.map +1 -0
- package/dist/native/index.d.mts +52 -0
- package/dist/native/index.d.mts.map +1 -0
- package/dist/native/index.mjs +44 -0
- package/dist/native/index.mjs.map +1 -0
- package/dist/postcss/index.cjs +92 -0
- package/dist/postcss/index.d.cts +24 -0
- package/dist/postcss/index.d.cts.map +1 -0
- package/dist/postcss/index.d.mts +24 -0
- package/dist/postcss/index.d.mts.map +1 -0
- package/dist/postcss/index.mjs +89 -0
- package/dist/postcss/index.mjs.map +1 -0
- package/dist/react/index.cjs +129 -0
- package/dist/react/index.d.cts +68 -0
- package/dist/react/index.d.cts.map +1 -0
- package/dist/react/index.d.mts +68 -0
- package/dist/react/index.d.mts.map +1 -0
- package/dist/react/index.mjs +107 -0
- package/dist/react/index.mjs.map +1 -0
- package/dist/types-AEQZQGT8.d.cts +28 -0
- package/dist/types-AEQZQGT8.d.cts.map +1 -0
- package/dist/types-CrliGpq8.d.mts +28 -0
- package/dist/types-CrliGpq8.d.mts.map +1 -0
- package/package.json +73 -4
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { n as computeClamp } from "../math-BwacRfp6.mjs";
|
|
2
|
+
// src/postcss/index.ts
|
|
3
|
+
const DEFAULT_PROPERTIES = [
|
|
4
|
+
"font-size",
|
|
5
|
+
"padding",
|
|
6
|
+
"padding-top",
|
|
7
|
+
"padding-right",
|
|
8
|
+
"padding-bottom",
|
|
9
|
+
"padding-left",
|
|
10
|
+
"padding-inline",
|
|
11
|
+
"padding-block",
|
|
12
|
+
"margin",
|
|
13
|
+
"margin-top",
|
|
14
|
+
"margin-right",
|
|
15
|
+
"margin-bottom",
|
|
16
|
+
"margin-left",
|
|
17
|
+
"margin-inline",
|
|
18
|
+
"margin-block",
|
|
19
|
+
"gap",
|
|
20
|
+
"row-gap",
|
|
21
|
+
"column-gap",
|
|
22
|
+
"border-radius"
|
|
23
|
+
];
|
|
24
|
+
/**
|
|
25
|
+
* Checks whether a declaration is nested within a `@media` at-rule.
|
|
26
|
+
*/
|
|
27
|
+
function isInsideMediaRule(decl) {
|
|
28
|
+
let parent = decl.parent;
|
|
29
|
+
while (parent) {
|
|
30
|
+
if (parent.type === "atrule" && parent.name?.toLowerCase() === "media") return true;
|
|
31
|
+
parent = parent.parent;
|
|
32
|
+
}
|
|
33
|
+
return false;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Checks whether a declaration has an explicit `fluid-ignore` opt-out comment.
|
|
37
|
+
*/
|
|
38
|
+
function hasFluidIgnore(decl) {
|
|
39
|
+
const prev = decl.prev();
|
|
40
|
+
if (prev && prev.type === "comment" && prev.text.trim().toLowerCase() === "fluid-ignore") {
|
|
41
|
+
const prevOfPrev = prev.prev?.();
|
|
42
|
+
if (!(prevOfPrev?.source?.end?.line && prev.source?.start?.line && prevOfPrev.source.end.line === prev.source.start.line)) return true;
|
|
43
|
+
}
|
|
44
|
+
const next = decl.next();
|
|
45
|
+
if (next && next.type === "comment" && next.text.trim().toLowerCase() === "fluid-ignore") {
|
|
46
|
+
if (decl.source?.end?.line && next.source?.start?.line && decl.source.end.line === next.source.start.line) return true;
|
|
47
|
+
}
|
|
48
|
+
const rawValue = decl.raws?.value?.raw;
|
|
49
|
+
if (rawValue && /\/\*\s*fluid-ignore\s*\*\//i.test(rawValue)) return true;
|
|
50
|
+
if (decl.value && /\/\*\s*fluid-ignore\s*\*\//i.test(decl.value)) return true;
|
|
51
|
+
return false;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* PostCSS plugin that automatically converts pixel units to fluid clamp() expressions.
|
|
55
|
+
*/
|
|
56
|
+
const postcssFluidScale = (options = {}) => {
|
|
57
|
+
const propertyList = options.properties ?? DEFAULT_PROPERTIES;
|
|
58
|
+
const targetProperties = new Set(propertyList.map((p) => p.toLowerCase()));
|
|
59
|
+
const minThresholdPx = options.minThresholdPx ?? 4;
|
|
60
|
+
const fluidConfig = {
|
|
61
|
+
minViewport: options.minViewport,
|
|
62
|
+
maxViewport: options.maxViewport,
|
|
63
|
+
minScaleRatio: options.minScaleRatio,
|
|
64
|
+
rootFontSize: options.rootFontSize
|
|
65
|
+
};
|
|
66
|
+
return {
|
|
67
|
+
postcssPlugin: "postcss-fluid-scale",
|
|
68
|
+
Declaration(decl) {
|
|
69
|
+
const propLower = decl.prop.toLowerCase();
|
|
70
|
+
if (!targetProperties.has(propLower)) return;
|
|
71
|
+
if (decl.value.includes("clamp(")) return;
|
|
72
|
+
if (isInsideMediaRule(decl)) return;
|
|
73
|
+
if (hasFluidIgnore(decl)) return;
|
|
74
|
+
const PX_REGEX = /(?<![\w-])(-?\d*\.?\d+)px\b/gi;
|
|
75
|
+
let transformed = false;
|
|
76
|
+
const newValue = decl.value.replace(PX_REGEX, (match, numStr) => {
|
|
77
|
+
const px = parseFloat(numStr);
|
|
78
|
+
if (!Number.isFinite(px) || Math.abs(px) < minThresholdPx) return match;
|
|
79
|
+
transformed = true;
|
|
80
|
+
return computeClamp(px, void 0, fluidConfig);
|
|
81
|
+
});
|
|
82
|
+
if (transformed) decl.value = newValue;
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
};
|
|
86
|
+
postcssFluidScale.postcss = true;
|
|
87
|
+
export { postcssFluidScale as default, postcssFluidScale };
|
|
88
|
+
|
|
89
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../../src/postcss/index.ts"],"sourcesContent":["import type { PluginCreator, Declaration } from 'postcss';\nimport { computeClamp } from '../core/math.js';\nimport type { PostcssFluidOptions } from './types.js';\n\nexport type { PostcssFluidOptions };\n\nconst DEFAULT_PROPERTIES = [\n 'font-size',\n 'padding',\n 'padding-top',\n 'padding-right',\n 'padding-bottom',\n 'padding-left',\n 'padding-inline',\n 'padding-block',\n 'margin',\n 'margin-top',\n 'margin-right',\n 'margin-bottom',\n 'margin-left',\n 'margin-inline',\n 'margin-block',\n 'gap',\n 'row-gap',\n 'column-gap',\n 'border-radius',\n];\n\n/**\n * Checks whether a declaration is nested within a `@media` at-rule.\n */\nfunction isInsideMediaRule(decl: Declaration): boolean {\n let parent: any = decl.parent;\n while (parent) {\n if (parent.type === 'atrule' && parent.name?.toLowerCase() === 'media') {\n return true;\n }\n parent = parent.parent;\n }\n return false;\n}\n\n/**\n * Checks whether a declaration has an explicit `fluid-ignore` opt-out comment.\n */\nfunction hasFluidIgnore(decl: Declaration): boolean {\n // Check preceding comment node\n const prev: any = decl.prev();\n if (prev && prev.type === 'comment' && prev.text.trim().toLowerCase() === 'fluid-ignore') {\n // If the comment was on the same line as the node before it, it's trailing that previous node,\n // not a preceding comment for this declaration.\n const prevOfPrev = prev.prev?.();\n const isTrailingPrev =\n prevOfPrev?.source?.end?.line &&\n prev.source?.start?.line &&\n prevOfPrev.source.end.line === prev.source.start.line;\n\n if (!isTrailingPrev) {\n return true;\n }\n }\n\n // Check next/trailing comment node on the same line as this declaration\n const next: any = decl.next();\n if (next && next.type === 'comment' && next.text.trim().toLowerCase() === 'fluid-ignore') {\n const isTrailingThis =\n decl.source?.end?.line &&\n next.source?.start?.line &&\n decl.source.end.line === next.source.start.line;\n\n if (isTrailingThis) {\n return true;\n }\n }\n\n // Inline comment in raw value (e.g. `padding: 16px /* fluid-ignore */;`)\n const rawValue = decl.raws?.value?.raw;\n if (rawValue && /\\/\\*\\s*fluid-ignore\\s*\\*\\//i.test(rawValue)) {\n return true;\n }\n\n if (decl.value && /\\/\\*\\s*fluid-ignore\\s*\\*\\//i.test(decl.value)) {\n return true;\n }\n\n return false;\n}\n\n/**\n * PostCSS plugin that automatically converts pixel units to fluid clamp() expressions.\n */\nconst postcssFluidScale: PluginCreator<PostcssFluidOptions> = (options = {}) => {\n const propertyList = options.properties ?? DEFAULT_PROPERTIES;\n const targetProperties = new Set(propertyList.map((p) => p.toLowerCase()));\n const minThresholdPx = options.minThresholdPx ?? 4;\n\n const fluidConfig = {\n minViewport: options.minViewport,\n maxViewport: options.maxViewport,\n minScaleRatio: options.minScaleRatio,\n rootFontSize: options.rootFontSize,\n };\n\n return {\n postcssPlugin: 'postcss-fluid-scale',\n\n Declaration(decl) {\n const propLower = decl.prop.toLowerCase();\n if (!targetProperties.has(propLower)) {\n return;\n }\n\n // Skip already transformed or custom clamp values\n if (decl.value.includes('clamp(')) {\n return;\n }\n\n // Skip media query overrides\n if (isInsideMediaRule(decl)) {\n return;\n }\n\n // Skip explicit fluid-ignore opt-outs\n if (hasFluidIgnore(decl)) {\n return;\n }\n\n // Safe standalone pixel matching with negative boundary check\n const PX_REGEX = /(?<![\\w-])(-?\\d*\\.?\\d+)px\\b/gi;\n let transformed = false;\n\n const newValue = decl.value.replace(PX_REGEX, (match, numStr) => {\n const px = parseFloat(numStr);\n if (!Number.isFinite(px) || Math.abs(px) < minThresholdPx) {\n return match;\n }\n transformed = true;\n return computeClamp(px, undefined, fluidConfig);\n });\n\n if (transformed) {\n decl.value = newValue;\n }\n },\n };\n};\n\npostcssFluidScale.postcss = true;\n\nexport default postcssFluidScale;\nexport { postcssFluidScale };\n"],"mappings":";;AAMA,MAAM,qBAAqB;CACzB;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF;;;;AAKA,SAAS,kBAAkB,MAA4B;CACrD,IAAI,SAAc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BAAiB,IAAI,SAAS,GACjC;GAIF,IAAI,KAAK,MAAM,SAAS,QAAQ,GAC9B;GAIF,IAAI,kBAAkB,IAAI,GACxB;GAIF,IAAI,eAAe,IAAI,GACrB;GAIF,MAAM,WAAW;GACjB,IAAI,cAAc;GAElB,MAAM,WAAW,KAAK,MAAM,QAAQ,WAAW,OAAO,WAAW;IAC/D,MAAM,KAAK,WAAW,MAAM;IAC5B,IAAI,CAAC,OAAO,SAAS,EAAE,KAAK,KAAK,IAAI,EAAE,IAAI,gBACzC,OAAO;IAET,cAAc;IACd,OAAO,aAAa,IAAI,KAAA,GAAW,WAAW;GAChD,CAAC;GAED,IAAI,aACF,KAAK,QAAQ;EAEjB;CACF;AACF;AAEA,kBAAkB,UAAU"}
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
// \0rolldown/runtime.js
|
|
3
|
+
var __create = Object.create;
|
|
4
|
+
var __defProp = Object.defineProperty;
|
|
5
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
8
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
11
|
+
key = keys[i];
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
13
|
+
get: ((k) => from[k]).bind(null, key),
|
|
14
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule || !__hasOwnProp.call(mod, "default") ? __defProp(target, "default", {
|
|
20
|
+
value: mod,
|
|
21
|
+
enumerable: true
|
|
22
|
+
}) : target, mod));
|
|
23
|
+
let react = require("react");
|
|
24
|
+
const require_math = require("../math-DKxTMW4W.cjs");
|
|
25
|
+
let react_jsx_runtime = require("react/jsx-runtime");
|
|
26
|
+
react = __toESM(react, 1);
|
|
27
|
+
// src/react/FluidGrid.tsx
|
|
28
|
+
/**
|
|
29
|
+
* A fluid responsive CSS Grid container that automatically fits columns
|
|
30
|
+
* based on minItemWidth and applies fluid clamp spacing for gaps.
|
|
31
|
+
*/
|
|
32
|
+
const FluidGrid = react.default.forwardRef(function FluidGrid({ minItemWidth = 280, gap = 16, minGap, config, as: Component = "div", style, children, ...rest }, ref) {
|
|
33
|
+
const computedGap = require_math.computeClamp(gap, minGap, config);
|
|
34
|
+
const gridStyle = {
|
|
35
|
+
display: "grid",
|
|
36
|
+
gridTemplateColumns: `repeat(auto-fit, minmax(min(100%, ${minItemWidth}px), 1fr))`,
|
|
37
|
+
gap: computedGap,
|
|
38
|
+
...style
|
|
39
|
+
};
|
|
40
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Component, {
|
|
41
|
+
ref,
|
|
42
|
+
style: gridStyle,
|
|
43
|
+
...rest,
|
|
44
|
+
children
|
|
45
|
+
});
|
|
46
|
+
});
|
|
47
|
+
FluidGrid.displayName = "FluidGrid";
|
|
48
|
+
// src/react/useLayoutGuard.ts
|
|
49
|
+
/**
|
|
50
|
+
* React hook that inspects layouts in development mode for horizontal overflow
|
|
51
|
+
* and undersized touch targets on mobile viewports.
|
|
52
|
+
*
|
|
53
|
+
* Automatically no-ops during SSR and production builds.
|
|
54
|
+
*/
|
|
55
|
+
function useLayoutGuard(enabledOrOptions) {
|
|
56
|
+
const options = typeof enabledOrOptions === "boolean" ? { enabled: enabledOrOptions } : enabledOrOptions ?? {};
|
|
57
|
+
const isDev = typeof process !== "undefined" && process.env?.NODE_ENV !== void 0 ? process.env.NODE_ENV !== "production" : true;
|
|
58
|
+
const isEnabled = options.enabled ?? isDev;
|
|
59
|
+
const minTouchSize = options.minTouchTargetSize ?? 44;
|
|
60
|
+
const touchViewportThreshold = options.touchTargetViewportThreshold ?? options.config?.minViewport ?? 480;
|
|
61
|
+
const warnInConsole = options.warnInConsole ?? true;
|
|
62
|
+
const warnedOverflowRef = (0, react.useRef)(false);
|
|
63
|
+
(0, react.useEffect)(() => {
|
|
64
|
+
if (!isEnabled || typeof window === "undefined" || typeof document === "undefined") return;
|
|
65
|
+
const checkLayout = () => {
|
|
66
|
+
const docEl = document.documentElement;
|
|
67
|
+
const windowWidth = window.innerWidth || docEl.clientWidth;
|
|
68
|
+
const scrollWidth = docEl.scrollWidth;
|
|
69
|
+
if (scrollWidth > windowWidth + 1) {
|
|
70
|
+
if (!docEl.hasAttribute("data-fluid-overflow")) docEl.setAttribute("data-fluid-overflow", "true");
|
|
71
|
+
const allElements = document.body?.querySelectorAll("*") ?? [];
|
|
72
|
+
const culprits = [];
|
|
73
|
+
allElements.forEach((el) => {
|
|
74
|
+
if (el.getBoundingClientRect().right > windowWidth + 1 || el.scrollWidth > el.clientWidth && el.scrollWidth > windowWidth) {
|
|
75
|
+
if (!el.hasAttribute("data-fluid-overflow-culprit")) el.setAttribute("data-fluid-overflow-culprit", "true");
|
|
76
|
+
culprits.push(el);
|
|
77
|
+
} else if (el.hasAttribute("data-fluid-overflow-culprit")) el.removeAttribute("data-fluid-overflow-culprit");
|
|
78
|
+
});
|
|
79
|
+
if (warnInConsole && !warnedOverflowRef.current) {
|
|
80
|
+
console.warn(`[fluid-scale] Layout overflow detected: document.scrollWidth (${scrollWidth}px) exceeds viewport (${windowWidth}px). Offending elements:`, culprits);
|
|
81
|
+
warnedOverflowRef.current = true;
|
|
82
|
+
}
|
|
83
|
+
} else {
|
|
84
|
+
if (docEl.hasAttribute("data-fluid-overflow")) docEl.removeAttribute("data-fluid-overflow");
|
|
85
|
+
document.querySelectorAll("[data-fluid-overflow-culprit]").forEach((el) => {
|
|
86
|
+
el.removeAttribute("data-fluid-overflow-culprit");
|
|
87
|
+
});
|
|
88
|
+
warnedOverflowRef.current = false;
|
|
89
|
+
}
|
|
90
|
+
if (windowWidth <= touchViewportThreshold) document.querySelectorAll("button, a[href], input, select, textarea, [role=\"button\"], [tabindex]:not([tabindex=\"-1\"])").forEach((el) => {
|
|
91
|
+
const rect = el.getBoundingClientRect();
|
|
92
|
+
if (rect.width === 0 && rect.height === 0) return;
|
|
93
|
+
if (rect.width < minTouchSize || rect.height < minTouchSize) {
|
|
94
|
+
if (el.getAttribute("data-fluid-touch-target") !== "too-small") el.setAttribute("data-fluid-touch-target", "too-small");
|
|
95
|
+
} else if (el.hasAttribute("data-fluid-touch-target")) el.removeAttribute("data-fluid-touch-target");
|
|
96
|
+
});
|
|
97
|
+
else document.querySelectorAll("[data-fluid-touch-target]").forEach((el) => {
|
|
98
|
+
el.removeAttribute("data-fluid-touch-target");
|
|
99
|
+
});
|
|
100
|
+
};
|
|
101
|
+
checkLayout();
|
|
102
|
+
let observer = null;
|
|
103
|
+
if (typeof ResizeObserver !== "undefined" && document.body) {
|
|
104
|
+
observer = new ResizeObserver(() => {
|
|
105
|
+
checkLayout();
|
|
106
|
+
});
|
|
107
|
+
observer.observe(document.body);
|
|
108
|
+
}
|
|
109
|
+
window.addEventListener("resize", checkLayout, { passive: true });
|
|
110
|
+
return () => {
|
|
111
|
+
if (observer) observer.disconnect();
|
|
112
|
+
window.removeEventListener("resize", checkLayout);
|
|
113
|
+
if (document.documentElement.hasAttribute("data-fluid-overflow")) document.documentElement.removeAttribute("data-fluid-overflow");
|
|
114
|
+
document.querySelectorAll("[data-fluid-overflow-culprit]").forEach((el) => {
|
|
115
|
+
el.removeAttribute("data-fluid-overflow-culprit");
|
|
116
|
+
});
|
|
117
|
+
document.querySelectorAll("[data-fluid-touch-target]").forEach((el) => {
|
|
118
|
+
el.removeAttribute("data-fluid-touch-target");
|
|
119
|
+
});
|
|
120
|
+
};
|
|
121
|
+
}, [
|
|
122
|
+
isEnabled,
|
|
123
|
+
minTouchSize,
|
|
124
|
+
touchViewportThreshold,
|
|
125
|
+
warnInConsole
|
|
126
|
+
]);
|
|
127
|
+
}
|
|
128
|
+
exports.FluidGrid = FluidGrid;
|
|
129
|
+
exports.useLayoutGuard = useLayoutGuard;
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { t as FluidConfig } from "../types-AEQZQGT8.cjs";
|
|
3
|
+
interface FluidGridProps extends React.HTMLAttributes<HTMLDivElement> {
|
|
4
|
+
/**
|
|
5
|
+
* Minimum width for grid columns in pixels.
|
|
6
|
+
* @default 280
|
|
7
|
+
*/
|
|
8
|
+
minItemWidth?: number;
|
|
9
|
+
/**
|
|
10
|
+
* Target gap between grid items in pixels at max viewport.
|
|
11
|
+
* @default 16
|
|
12
|
+
*/
|
|
13
|
+
gap?: number;
|
|
14
|
+
/**
|
|
15
|
+
* Minimum gap between grid items in pixels at min viewport.
|
|
16
|
+
* Defaults to `gap * minScaleRatio`.
|
|
17
|
+
*/
|
|
18
|
+
minGap?: number;
|
|
19
|
+
/**
|
|
20
|
+
* Fluid scaling configuration options.
|
|
21
|
+
*/
|
|
22
|
+
config?: FluidConfig;
|
|
23
|
+
/**
|
|
24
|
+
* The HTML element or component to render as.
|
|
25
|
+
* @default 'div'
|
|
26
|
+
*/
|
|
27
|
+
as?: React.ElementType;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* A fluid responsive CSS Grid container that automatically fits columns
|
|
31
|
+
* based on minItemWidth and applies fluid clamp spacing for gaps.
|
|
32
|
+
*/
|
|
33
|
+
export declare const FluidGrid: React.ForwardRefExoticComponent<FluidGridProps & React.RefAttributes<HTMLDivElement>>;
|
|
34
|
+
interface LayoutGuardOptions {
|
|
35
|
+
/**
|
|
36
|
+
* Explicitly enable or disable layout inspections.
|
|
37
|
+
* Defaults to true in development, false in production.
|
|
38
|
+
*/
|
|
39
|
+
enabled?: boolean;
|
|
40
|
+
/**
|
|
41
|
+
* Minimum touch target size in pixels.
|
|
42
|
+
* @default 44
|
|
43
|
+
*/
|
|
44
|
+
minTouchTargetSize?: number;
|
|
45
|
+
/**
|
|
46
|
+
* Viewport width threshold in pixels below which touch-target checks are enforced.
|
|
47
|
+
* Defaults to config.minViewport or 480.
|
|
48
|
+
*/
|
|
49
|
+
touchTargetViewportThreshold?: number;
|
|
50
|
+
/**
|
|
51
|
+
* Configuration options for fluid scaling.
|
|
52
|
+
*/
|
|
53
|
+
config?: FluidConfig;
|
|
54
|
+
/**
|
|
55
|
+
* Whether to log warnings to the browser console.
|
|
56
|
+
* @default true
|
|
57
|
+
*/
|
|
58
|
+
warnInConsole?: boolean;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* React hook that inspects layouts in development mode for horizontal overflow
|
|
62
|
+
* and undersized touch targets on mobile viewports.
|
|
63
|
+
*
|
|
64
|
+
* Automatically no-ops during SSR and production builds.
|
|
65
|
+
*/
|
|
66
|
+
export declare function useLayoutGuard(enabledOrOptions?: boolean | LayoutGuardOptions): void;
|
|
67
|
+
export type { FluidGridProps, LayoutGuardOptions };
|
|
68
|
+
//# sourceMappingURL=index.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.cts","names":[],"sources":["../../src/react/FluidGrid.tsx","../../src/react/useLayoutGuard.ts"],"mappings":";;UAIiB,uBAAuB,MAAM,eAAe;;;;;EAK3D;;;;;EAMA;;;;;EAMA;;;;EAKA,SAAS;;;;;EAMT,KAAK,MAAM;;;;;;qBAOA,WAAS,MAAA,0BAAA,iBAAA,MAAA,cAAA;UCpCL;;;;;EAKf;;;;;EAMA;;;;;EAMA;;;;EAKA,SAAS;;;;;EAMT;;;;;;;;wBASc,eACd,6BAA6B"}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { t as FluidConfig } from "../types-CrliGpq8.mjs";
|
|
3
|
+
interface FluidGridProps extends React.HTMLAttributes<HTMLDivElement> {
|
|
4
|
+
/**
|
|
5
|
+
* Minimum width for grid columns in pixels.
|
|
6
|
+
* @default 280
|
|
7
|
+
*/
|
|
8
|
+
minItemWidth?: number;
|
|
9
|
+
/**
|
|
10
|
+
* Target gap between grid items in pixels at max viewport.
|
|
11
|
+
* @default 16
|
|
12
|
+
*/
|
|
13
|
+
gap?: number;
|
|
14
|
+
/**
|
|
15
|
+
* Minimum gap between grid items in pixels at min viewport.
|
|
16
|
+
* Defaults to `gap * minScaleRatio`.
|
|
17
|
+
*/
|
|
18
|
+
minGap?: number;
|
|
19
|
+
/**
|
|
20
|
+
* Fluid scaling configuration options.
|
|
21
|
+
*/
|
|
22
|
+
config?: FluidConfig;
|
|
23
|
+
/**
|
|
24
|
+
* The HTML element or component to render as.
|
|
25
|
+
* @default 'div'
|
|
26
|
+
*/
|
|
27
|
+
as?: React.ElementType;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* A fluid responsive CSS Grid container that automatically fits columns
|
|
31
|
+
* based on minItemWidth and applies fluid clamp spacing for gaps.
|
|
32
|
+
*/
|
|
33
|
+
export declare const FluidGrid: React.ForwardRefExoticComponent<FluidGridProps & React.RefAttributes<HTMLDivElement>>;
|
|
34
|
+
interface LayoutGuardOptions {
|
|
35
|
+
/**
|
|
36
|
+
* Explicitly enable or disable layout inspections.
|
|
37
|
+
* Defaults to true in development, false in production.
|
|
38
|
+
*/
|
|
39
|
+
enabled?: boolean;
|
|
40
|
+
/**
|
|
41
|
+
* Minimum touch target size in pixels.
|
|
42
|
+
* @default 44
|
|
43
|
+
*/
|
|
44
|
+
minTouchTargetSize?: number;
|
|
45
|
+
/**
|
|
46
|
+
* Viewport width threshold in pixels below which touch-target checks are enforced.
|
|
47
|
+
* Defaults to config.minViewport or 480.
|
|
48
|
+
*/
|
|
49
|
+
touchTargetViewportThreshold?: number;
|
|
50
|
+
/**
|
|
51
|
+
* Configuration options for fluid scaling.
|
|
52
|
+
*/
|
|
53
|
+
config?: FluidConfig;
|
|
54
|
+
/**
|
|
55
|
+
* Whether to log warnings to the browser console.
|
|
56
|
+
* @default true
|
|
57
|
+
*/
|
|
58
|
+
warnInConsole?: boolean;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* React hook that inspects layouts in development mode for horizontal overflow
|
|
62
|
+
* and undersized touch targets on mobile viewports.
|
|
63
|
+
*
|
|
64
|
+
* Automatically no-ops during SSR and production builds.
|
|
65
|
+
*/
|
|
66
|
+
export declare function useLayoutGuard(enabledOrOptions?: boolean | LayoutGuardOptions): void;
|
|
67
|
+
export type { FluidGridProps, LayoutGuardOptions };
|
|
68
|
+
//# sourceMappingURL=index.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../../src/react/FluidGrid.tsx","../../src/react/useLayoutGuard.ts"],"mappings":";;UAIiB,uBAAuB,MAAM,eAAe;;;;;EAK3D;;;;;EAMA;;;;;EAMA;;;;EAKA,SAAS;;;;;EAMT,KAAK,MAAM;;;;;;qBAOA,WAAS,MAAA,0BAAA,iBAAA,MAAA,cAAA;UCpCL;;;;;EAKf;;;;;EAMA;;;;;EAMA;;;;EAKA,SAAS;;;;;EAMT;;;;;;;;wBASc,eACd,6BAA6B"}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import React, { useEffect, useRef } from "react";
|
|
2
|
+
import { n as computeClamp } from "../math-BwacRfp6.mjs";
|
|
3
|
+
import { jsx } from "react/jsx-runtime";
|
|
4
|
+
// src/react/FluidGrid.tsx
|
|
5
|
+
/**
|
|
6
|
+
* A fluid responsive CSS Grid container that automatically fits columns
|
|
7
|
+
* based on minItemWidth and applies fluid clamp spacing for gaps.
|
|
8
|
+
*/
|
|
9
|
+
const FluidGrid = React.forwardRef(function FluidGrid({ minItemWidth = 280, gap = 16, minGap, config, as: Component = "div", style, children, ...rest }, ref) {
|
|
10
|
+
const computedGap = computeClamp(gap, minGap, config);
|
|
11
|
+
const gridStyle = {
|
|
12
|
+
display: "grid",
|
|
13
|
+
gridTemplateColumns: `repeat(auto-fit, minmax(min(100%, ${minItemWidth}px), 1fr))`,
|
|
14
|
+
gap: computedGap,
|
|
15
|
+
...style
|
|
16
|
+
};
|
|
17
|
+
return /* @__PURE__ */ jsx(Component, {
|
|
18
|
+
ref,
|
|
19
|
+
style: gridStyle,
|
|
20
|
+
...rest,
|
|
21
|
+
children
|
|
22
|
+
});
|
|
23
|
+
});
|
|
24
|
+
FluidGrid.displayName = "FluidGrid";
|
|
25
|
+
// src/react/useLayoutGuard.ts
|
|
26
|
+
/**
|
|
27
|
+
* React hook that inspects layouts in development mode for horizontal overflow
|
|
28
|
+
* and undersized touch targets on mobile viewports.
|
|
29
|
+
*
|
|
30
|
+
* Automatically no-ops during SSR and production builds.
|
|
31
|
+
*/
|
|
32
|
+
function useLayoutGuard(enabledOrOptions) {
|
|
33
|
+
const options = typeof enabledOrOptions === "boolean" ? { enabled: enabledOrOptions } : enabledOrOptions ?? {};
|
|
34
|
+
const isDev = typeof process !== "undefined" && process.env?.NODE_ENV !== void 0 ? process.env.NODE_ENV !== "production" : true;
|
|
35
|
+
const isEnabled = options.enabled ?? isDev;
|
|
36
|
+
const minTouchSize = options.minTouchTargetSize ?? 44;
|
|
37
|
+
const touchViewportThreshold = options.touchTargetViewportThreshold ?? options.config?.minViewport ?? 480;
|
|
38
|
+
const warnInConsole = options.warnInConsole ?? true;
|
|
39
|
+
const warnedOverflowRef = useRef(false);
|
|
40
|
+
useEffect(() => {
|
|
41
|
+
if (!isEnabled || typeof window === "undefined" || typeof document === "undefined") return;
|
|
42
|
+
const checkLayout = () => {
|
|
43
|
+
const docEl = document.documentElement;
|
|
44
|
+
const windowWidth = window.innerWidth || docEl.clientWidth;
|
|
45
|
+
const scrollWidth = docEl.scrollWidth;
|
|
46
|
+
if (scrollWidth > windowWidth + 1) {
|
|
47
|
+
if (!docEl.hasAttribute("data-fluid-overflow")) docEl.setAttribute("data-fluid-overflow", "true");
|
|
48
|
+
const allElements = document.body?.querySelectorAll("*") ?? [];
|
|
49
|
+
const culprits = [];
|
|
50
|
+
allElements.forEach((el) => {
|
|
51
|
+
if (el.getBoundingClientRect().right > windowWidth + 1 || el.scrollWidth > el.clientWidth && el.scrollWidth > windowWidth) {
|
|
52
|
+
if (!el.hasAttribute("data-fluid-overflow-culprit")) el.setAttribute("data-fluid-overflow-culprit", "true");
|
|
53
|
+
culprits.push(el);
|
|
54
|
+
} else if (el.hasAttribute("data-fluid-overflow-culprit")) el.removeAttribute("data-fluid-overflow-culprit");
|
|
55
|
+
});
|
|
56
|
+
if (warnInConsole && !warnedOverflowRef.current) {
|
|
57
|
+
console.warn(`[fluid-scale] Layout overflow detected: document.scrollWidth (${scrollWidth}px) exceeds viewport (${windowWidth}px). Offending elements:`, culprits);
|
|
58
|
+
warnedOverflowRef.current = true;
|
|
59
|
+
}
|
|
60
|
+
} else {
|
|
61
|
+
if (docEl.hasAttribute("data-fluid-overflow")) docEl.removeAttribute("data-fluid-overflow");
|
|
62
|
+
document.querySelectorAll("[data-fluid-overflow-culprit]").forEach((el) => {
|
|
63
|
+
el.removeAttribute("data-fluid-overflow-culprit");
|
|
64
|
+
});
|
|
65
|
+
warnedOverflowRef.current = false;
|
|
66
|
+
}
|
|
67
|
+
if (windowWidth <= touchViewportThreshold) document.querySelectorAll("button, a[href], input, select, textarea, [role=\"button\"], [tabindex]:not([tabindex=\"-1\"])").forEach((el) => {
|
|
68
|
+
const rect = el.getBoundingClientRect();
|
|
69
|
+
if (rect.width === 0 && rect.height === 0) return;
|
|
70
|
+
if (rect.width < minTouchSize || rect.height < minTouchSize) {
|
|
71
|
+
if (el.getAttribute("data-fluid-touch-target") !== "too-small") el.setAttribute("data-fluid-touch-target", "too-small");
|
|
72
|
+
} else if (el.hasAttribute("data-fluid-touch-target")) el.removeAttribute("data-fluid-touch-target");
|
|
73
|
+
});
|
|
74
|
+
else document.querySelectorAll("[data-fluid-touch-target]").forEach((el) => {
|
|
75
|
+
el.removeAttribute("data-fluid-touch-target");
|
|
76
|
+
});
|
|
77
|
+
};
|
|
78
|
+
checkLayout();
|
|
79
|
+
let observer = null;
|
|
80
|
+
if (typeof ResizeObserver !== "undefined" && document.body) {
|
|
81
|
+
observer = new ResizeObserver(() => {
|
|
82
|
+
checkLayout();
|
|
83
|
+
});
|
|
84
|
+
observer.observe(document.body);
|
|
85
|
+
}
|
|
86
|
+
window.addEventListener("resize", checkLayout, { passive: true });
|
|
87
|
+
return () => {
|
|
88
|
+
if (observer) observer.disconnect();
|
|
89
|
+
window.removeEventListener("resize", checkLayout);
|
|
90
|
+
if (document.documentElement.hasAttribute("data-fluid-overflow")) document.documentElement.removeAttribute("data-fluid-overflow");
|
|
91
|
+
document.querySelectorAll("[data-fluid-overflow-culprit]").forEach((el) => {
|
|
92
|
+
el.removeAttribute("data-fluid-overflow-culprit");
|
|
93
|
+
});
|
|
94
|
+
document.querySelectorAll("[data-fluid-touch-target]").forEach((el) => {
|
|
95
|
+
el.removeAttribute("data-fluid-touch-target");
|
|
96
|
+
});
|
|
97
|
+
};
|
|
98
|
+
}, [
|
|
99
|
+
isEnabled,
|
|
100
|
+
minTouchSize,
|
|
101
|
+
touchViewportThreshold,
|
|
102
|
+
warnInConsole
|
|
103
|
+
]);
|
|
104
|
+
}
|
|
105
|
+
export { FluidGrid, useLayoutGuard };
|
|
106
|
+
|
|
107
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../../src/react/FluidGrid.tsx","../../src/react/useLayoutGuard.ts"],"sourcesContent":["import React from 'react';\nimport { computeClamp } from '../core/math.js';\nimport type { FluidConfig } from '../core/types.js';\n\nexport interface FluidGridProps extends React.HTMLAttributes<HTMLDivElement> {\n /**\n * Minimum width for grid columns in pixels.\n * @default 280\n */\n minItemWidth?: number;\n\n /**\n * Target gap between grid items in pixels at max viewport.\n * @default 16\n */\n gap?: number;\n\n /**\n * Minimum gap between grid items in pixels at min viewport.\n * Defaults to `gap * minScaleRatio`.\n */\n minGap?: number;\n\n /**\n * Fluid scaling configuration options.\n */\n config?: FluidConfig;\n\n /**\n * The HTML element or component to render as.\n * @default 'div'\n */\n as?: React.ElementType;\n}\n\n/**\n * A fluid responsive CSS Grid container that automatically fits columns\n * based on minItemWidth and applies fluid clamp spacing for gaps.\n */\nexport const FluidGrid = React.forwardRef<HTMLDivElement, FluidGridProps>(\n function FluidGrid(\n {\n minItemWidth = 280,\n gap = 16,\n minGap,\n config,\n as: Component = 'div',\n style,\n children,\n ...rest\n },\n ref\n ) {\n const computedGap = computeClamp(gap, minGap, config);\n\n const gridStyle: React.CSSProperties = {\n display: 'grid',\n gridTemplateColumns: `repeat(auto-fit, minmax(min(100%, ${minItemWidth}px), 1fr))`,\n gap: computedGap,\n ...style,\n };\n\n return (\n <Component ref={ref} style={gridStyle} {...rest}>\n {children}\n </Component>\n );\n }\n);\n\nFluidGrid.displayName = 'FluidGrid';\n","import { useEffect, useRef } from 'react';\nimport type { FluidConfig } from '../core/types.js';\n\nexport interface LayoutGuardOptions {\n /**\n * Explicitly enable or disable layout inspections.\n * Defaults to true in development, false in production.\n */\n enabled?: boolean;\n\n /**\n * Minimum touch target size in pixels.\n * @default 44\n */\n minTouchTargetSize?: number;\n\n /**\n * Viewport width threshold in pixels below which touch-target checks are enforced.\n * Defaults to config.minViewport or 480.\n */\n touchTargetViewportThreshold?: number;\n\n /**\n * Configuration options for fluid scaling.\n */\n config?: FluidConfig;\n\n /**\n * Whether to log warnings to the browser console.\n * @default true\n */\n warnInConsole?: boolean;\n}\n\n/**\n * React hook that inspects layouts in development mode for horizontal overflow\n * and undersized touch targets on mobile viewports.\n *\n * Automatically no-ops during SSR and production builds.\n */\nexport function useLayoutGuard(\n enabledOrOptions?: boolean | LayoutGuardOptions\n): void {\n const options: LayoutGuardOptions =\n typeof enabledOrOptions === 'boolean'\n ? { enabled: enabledOrOptions }\n : (enabledOrOptions ?? {});\n\n const isDev =\n typeof process !== 'undefined' && process.env?.NODE_ENV !== undefined\n ? process.env.NODE_ENV !== 'production'\n : true;\n\n const isEnabled = options.enabled ?? isDev;\n const minTouchSize = options.minTouchTargetSize ?? 44;\n const touchViewportThreshold =\n options.touchTargetViewportThreshold ?? options.config?.minViewport ?? 480;\n const warnInConsole = options.warnInConsole ?? true;\n\n const warnedOverflowRef = useRef<boolean>(false);\n\n useEffect(() => {\n if (!isEnabled || typeof window === 'undefined' || typeof document === 'undefined') {\n return;\n }\n\n const checkLayout = () => {\n const docEl = document.documentElement;\n const windowWidth = window.innerWidth || docEl.clientWidth;\n const scrollWidth = docEl.scrollWidth;\n\n // 1. Horizontal Overflow Detection (allowing 1px subpixel tolerance)\n if (scrollWidth > windowWidth + 1) {\n if (!docEl.hasAttribute('data-fluid-overflow')) {\n docEl.setAttribute('data-fluid-overflow', 'true');\n }\n\n const allElements = document.body?.querySelectorAll<HTMLElement>('*') ?? [];\n const culprits: HTMLElement[] = [];\n\n allElements.forEach((el) => {\n const rect = el.getBoundingClientRect();\n if (\n rect.right > windowWidth + 1 ||\n (el.scrollWidth > el.clientWidth && el.scrollWidth > windowWidth)\n ) {\n if (!el.hasAttribute('data-fluid-overflow-culprit')) {\n el.setAttribute('data-fluid-overflow-culprit', 'true');\n }\n culprits.push(el);\n } else if (el.hasAttribute('data-fluid-overflow-culprit')) {\n el.removeAttribute('data-fluid-overflow-culprit');\n }\n });\n\n if (warnInConsole && !warnedOverflowRef.current) {\n console.warn(\n `[fluid-scale] Layout overflow detected: document.scrollWidth (${scrollWidth}px) exceeds viewport (${windowWidth}px). Offending elements:`,\n culprits\n );\n warnedOverflowRef.current = true;\n }\n } else {\n if (docEl.hasAttribute('data-fluid-overflow')) {\n docEl.removeAttribute('data-fluid-overflow');\n }\n document.querySelectorAll('[data-fluid-overflow-culprit]').forEach((el) => {\n el.removeAttribute('data-fluid-overflow-culprit');\n });\n warnedOverflowRef.current = false;\n }\n\n // 2. Touch Target Accessibility Check (on mobile/narrow viewports)\n if (windowWidth <= touchViewportThreshold) {\n const interactiveElements = document.querySelectorAll<HTMLElement>(\n 'button, a[href], input, select, textarea, [role=\"button\"], [tabindex]:not([tabindex=\"-1\"])'\n );\n\n interactiveElements.forEach((el) => {\n const rect = el.getBoundingClientRect();\n if (rect.width === 0 && rect.height === 0) return;\n\n if (rect.width < minTouchSize || rect.height < minTouchSize) {\n if (el.getAttribute('data-fluid-touch-target') !== 'too-small') {\n el.setAttribute('data-fluid-touch-target', 'too-small');\n }\n } else if (el.hasAttribute('data-fluid-touch-target')) {\n el.removeAttribute('data-fluid-touch-target');\n }\n });\n } else {\n document.querySelectorAll('[data-fluid-touch-target]').forEach((el) => {\n el.removeAttribute('data-fluid-touch-target');\n });\n }\n };\n\n checkLayout();\n\n let observer: ResizeObserver | null = null;\n if (typeof ResizeObserver !== 'undefined' && document.body) {\n observer = new ResizeObserver(() => {\n checkLayout();\n });\n observer.observe(document.body);\n }\n\n window.addEventListener('resize', checkLayout, { passive: true });\n\n return () => {\n if (observer) {\n observer.disconnect();\n }\n window.removeEventListener('resize', checkLayout);\n\n if (document.documentElement.hasAttribute('data-fluid-overflow')) {\n document.documentElement.removeAttribute('data-fluid-overflow');\n }\n document.querySelectorAll('[data-fluid-overflow-culprit]').forEach((el) => {\n el.removeAttribute('data-fluid-overflow-culprit');\n });\n document.querySelectorAll('[data-fluid-touch-target]').forEach((el) => {\n el.removeAttribute('data-fluid-touch-target');\n });\n };\n }, [isEnabled, minTouchSize, touchViewportThreshold, warnInConsole]);\n}\n"],"mappings":";;;;;;;;AAuCA,MAAa,YAAY,MAAM,WAC7B,SAAS,UACP,EACE,eAAe,KACf,MAAM,IACN,QACA,QACA,IAAI,YAAY,OAChB,OACA,UACA,GAAG,QAEL,KACA;CACA,MAAM,cAAc,aAAa,KAAK,QAAQ,MAAM;CAEpD,MAAM,YA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6BAA6B;GAClD,CAAC;GACD,SAAS,iBAAiB,2BAA2B,CAAC,CAAC,SAAS,OAAO;IACrE,GAAG,gBAAgB,yBAAyB;GAC9C,CAAC;EACH;CACF,GAAG;EAAC;EAAW;EAAc;EAAwB;CAAa,CAAC;AACrE"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Configuration options for fluid scaling calculations.
|
|
3
|
+
*/
|
|
4
|
+
interface FluidConfig {
|
|
5
|
+
/**
|
|
6
|
+
* Lower viewport width bound in pixels where fluid scaling begins.
|
|
7
|
+
* @default 375
|
|
8
|
+
*/
|
|
9
|
+
minViewport?: number;
|
|
10
|
+
/**
|
|
11
|
+
* Upper viewport width bound in pixels where fluid scaling caps.
|
|
12
|
+
* @default 1440
|
|
13
|
+
*/
|
|
14
|
+
maxViewport?: number;
|
|
15
|
+
/**
|
|
16
|
+
* Default ratio used to derive minPx from maxPx when minPx is not explicitly provided.
|
|
17
|
+
* For example, 0.75 means minPx will be 75% of maxPx.
|
|
18
|
+
* @default 0.75
|
|
19
|
+
*/
|
|
20
|
+
minScaleRatio?: number;
|
|
21
|
+
/**
|
|
22
|
+
* Root element font-size in pixels used for rem conversions.
|
|
23
|
+
* @default 16
|
|
24
|
+
*/
|
|
25
|
+
rootFontSize?: number;
|
|
26
|
+
}
|
|
27
|
+
export { FluidConfig as t };
|
|
28
|
+
//# sourceMappingURL=types-AEQZQGT8.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types-AEQZQGT8.d.cts","names":[],"sources":["../src/core/types.ts"],"mappings":";;;UAGiB;;;;;EAKf;;;;;EAMA;;;;;;EAOA;;;;;EAMA"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Configuration options for fluid scaling calculations.
|
|
3
|
+
*/
|
|
4
|
+
interface FluidConfig {
|
|
5
|
+
/**
|
|
6
|
+
* Lower viewport width bound in pixels where fluid scaling begins.
|
|
7
|
+
* @default 375
|
|
8
|
+
*/
|
|
9
|
+
minViewport?: number;
|
|
10
|
+
/**
|
|
11
|
+
* Upper viewport width bound in pixels where fluid scaling caps.
|
|
12
|
+
* @default 1440
|
|
13
|
+
*/
|
|
14
|
+
maxViewport?: number;
|
|
15
|
+
/**
|
|
16
|
+
* Default ratio used to derive minPx from maxPx when minPx is not explicitly provided.
|
|
17
|
+
* For example, 0.75 means minPx will be 75% of maxPx.
|
|
18
|
+
* @default 0.75
|
|
19
|
+
*/
|
|
20
|
+
minScaleRatio?: number;
|
|
21
|
+
/**
|
|
22
|
+
* Root element font-size in pixels used for rem conversions.
|
|
23
|
+
* @default 16
|
|
24
|
+
*/
|
|
25
|
+
rootFontSize?: number;
|
|
26
|
+
}
|
|
27
|
+
export { FluidConfig as t };
|
|
28
|
+
//# sourceMappingURL=types-CrliGpq8.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types-CrliGpq8.d.mts","names":[],"sources":["../src/core/types.ts"],"mappings":";;;UAGiB;;;;;EAKf;;;;;EAMA;;;;;;EAOA;;;;;EAMA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,75 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bingvader/fluid-scale",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Zero-dependency fluid clamp math with optional PostCSS, React and Native adapters",
|
|
5
|
+
"publishConfig": {
|
|
6
|
+
"access": "public"
|
|
7
|
+
},
|
|
8
|
+
"type": "module",
|
|
9
|
+
"author": "BingVader",
|
|
10
|
+
"license": "MIT",
|
|
11
|
+
"main": "./dist/index.cjs",
|
|
12
|
+
"module": "./dist/index.mjs",
|
|
13
|
+
"types": "./dist/index.d.mts",
|
|
14
|
+
"exports": {
|
|
15
|
+
".": {
|
|
16
|
+
"types": "./dist/index.d.mts",
|
|
17
|
+
"import": "./dist/index.mjs",
|
|
18
|
+
"require": "./dist/index.cjs"
|
|
19
|
+
},
|
|
20
|
+
"./postcss": {
|
|
21
|
+
"types": "./dist/postcss/index.d.mts",
|
|
22
|
+
"import": "./dist/postcss/index.mjs",
|
|
23
|
+
"require": "./dist/postcss/index.cjs"
|
|
24
|
+
},
|
|
25
|
+
"./react": {
|
|
26
|
+
"types": "./dist/react/index.d.mts",
|
|
27
|
+
"import": "./dist/react/index.mjs",
|
|
28
|
+
"require": "./dist/react/index.cjs"
|
|
29
|
+
},
|
|
30
|
+
"./native": {
|
|
31
|
+
"types": "./dist/native/index.d.mts",
|
|
32
|
+
"import": "./dist/native/index.mjs",
|
|
33
|
+
"require": "./dist/native/index.cjs"
|
|
34
|
+
}
|
|
35
|
+
},
|
|
36
|
+
"files": [
|
|
37
|
+
"dist",
|
|
38
|
+
"README.md"
|
|
39
|
+
],
|
|
40
|
+
"sideEffects": false,
|
|
41
|
+
"scripts": {
|
|
42
|
+
"build": "tsdown",
|
|
43
|
+
"test": "vitest run",
|
|
44
|
+
"typecheck": "tsc --noEmit",
|
|
45
|
+
"prepublishOnly": "npm run typecheck && npm test && npm run build"
|
|
46
|
+
},
|
|
47
|
+
"peerDependencies": {
|
|
48
|
+
"postcss": "^8.0.0",
|
|
49
|
+
"react": ">=16.8.0 || ^18.0.0 || ^19.0.0",
|
|
50
|
+
"react-native": "*"
|
|
51
|
+
},
|
|
52
|
+
"peerDependenciesMeta": {
|
|
53
|
+
"postcss": {
|
|
54
|
+
"optional": true
|
|
55
|
+
},
|
|
56
|
+
"react": {
|
|
57
|
+
"optional": true
|
|
58
|
+
},
|
|
59
|
+
"react-native": {
|
|
60
|
+
"optional": true
|
|
61
|
+
}
|
|
62
|
+
},
|
|
63
|
+
"devDependencies": {
|
|
64
|
+
"@types/node": "^22.13.0",
|
|
65
|
+
"@types/react": "^19.0.0",
|
|
66
|
+
"@types/react-dom": "^19.0.0",
|
|
67
|
+
"happy-dom": "^17.0.0",
|
|
68
|
+
"postcss": "^8.4.49",
|
|
69
|
+
"react": "^19.0.0",
|
|
70
|
+
"react-dom": "^19.0.0",
|
|
71
|
+
"tsdown": "^0.23.7",
|
|
72
|
+
"typescript": "^5.7.0",
|
|
73
|
+
"vitest": "^3.0.0"
|
|
74
|
+
}
|
|
75
|
+
}
|