@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 CHANGED
@@ -1,3 +1,62 @@
1
- # Temporary Holding Version
1
+ # @bingvader/fluid-scale
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Fluid responsive scaling utilities and platform adapters created by BingVader.
4
+
5
+ ## Modules
6
+
7
+ - `@bingvader/fluid-scale`: Core linear clamp calculation (`computeClamp`).
8
+ - `@bingvader/fluid-scale/postcss`: Build-time PostCSS plugin (`postcssFluidScale`).
9
+ - `@bingvader/fluid-scale/react`: React components (`FluidGrid`) and layout guards (`useLayoutGuard`).
10
+ - `@bingvader/fluid-scale/native`: React Native dimensions-aware hook (`useFluidNative`).
11
+
12
+ ## Core Usage
13
+
14
+ ```ts
15
+ import { computeClamp } from '@bingvader/fluid-scale';
16
+
17
+ const fontSize = computeClamp(32, 16);
18
+ ```
19
+
20
+ ## PostCSS Plugin
21
+
22
+ ```js
23
+ import postcssFluidScale from '@bingvader/fluid-scale/postcss';
24
+
25
+ export default {
26
+ plugins: [
27
+ postcssFluidScale({
28
+ minViewport: 375,
29
+ maxViewport: 1440,
30
+ minThresholdPx: 4,
31
+ }),
32
+ ],
33
+ };
34
+ ```
35
+
36
+ Declarations can opt out using `/* fluid-ignore */`. Media queries and values below `minThresholdPx` are automatically preserved.
37
+
38
+ ## React Grid & Layout Guard
39
+
40
+ ```tsx
41
+ import { FluidGrid, useLayoutGuard } from '@bingvader/fluid-scale/react';
42
+
43
+ export function GridExample() {
44
+ useLayoutGuard();
45
+ return (
46
+ <FluidGrid minItemWidth={280} gap={16}>
47
+ <div>Item</div>
48
+ </FluidGrid>
49
+ );
50
+ }
51
+ ```
52
+
53
+ ## React Native
54
+
55
+ ```tsx
56
+ import { useFluidNative } from '@bingvader/fluid-scale/native';
57
+
58
+ export function NativeExample() {
59
+ const { scale, moderateScale, isTablet } = useFluidNative();
60
+ return null;
61
+ }
62
+ ```
package/dist/index.cjs ADDED
@@ -0,0 +1,4 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_math = require("./math-DKxTMW4W.cjs");
3
+ exports.cleanNumber = require_math.cleanNumber;
4
+ exports.computeClamp = require_math.computeClamp;
@@ -0,0 +1,21 @@
1
+ import { t as FluidConfig } from "./types-AEQZQGT8.cjs";
2
+ /**
3
+ * Cleanly formats a floating point number up to a maximum number of decimal places,
4
+ * stripping unnecessary trailing zeros and avoiding negative zero (-0).
5
+ */
6
+ export declare function cleanNumber(num: number, maxDecimals?: number): string;
7
+ /**
8
+ * Computes a CSS `clamp()` expression providing linear fluid scaling between
9
+ * `minViewport` and `maxViewport`.
10
+ *
11
+ * @param maxPx - The target size in pixels at the maximum viewport width.
12
+ * @param minPx - Optional minimum size in pixels at the minimum viewport width. Defaults to `maxPx * minScaleRatio`.
13
+ * @param config - Optional configuration overrides for viewports, scale ratio, and root font size.
14
+ * @returns A CSS clamp string, e.g. `clamp(1rem, 0.6479rem + 1.5023vw, 2rem)`, or a static `rem` value if min equals max.
15
+ *
16
+ * @throws {TypeError} If inputs are non-finite numbers.
17
+ * @throws {RangeError} If rootFontSize <= 0, or minViewport/maxViewport are invalid or equal.
18
+ */
19
+ export declare function computeClamp(maxPx: number, minPx?: number, config?: FluidConfig): string;
20
+ export type { FluidConfig };
21
+ //# sourceMappingURL=index.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.cts","names":[],"sources":["../src/core/math.ts"],"mappings":";;;;;wBAMgB,YAAY,aAAa;;;;;;;;;;;;;wBAwBzB,aACd,eACA,gBACA,SAAS"}
@@ -0,0 +1,21 @@
1
+ import { t as FluidConfig } from "./types-CrliGpq8.mjs";
2
+ /**
3
+ * Cleanly formats a floating point number up to a maximum number of decimal places,
4
+ * stripping unnecessary trailing zeros and avoiding negative zero (-0).
5
+ */
6
+ export declare function cleanNumber(num: number, maxDecimals?: number): string;
7
+ /**
8
+ * Computes a CSS `clamp()` expression providing linear fluid scaling between
9
+ * `minViewport` and `maxViewport`.
10
+ *
11
+ * @param maxPx - The target size in pixels at the maximum viewport width.
12
+ * @param minPx - Optional minimum size in pixels at the minimum viewport width. Defaults to `maxPx * minScaleRatio`.
13
+ * @param config - Optional configuration overrides for viewports, scale ratio, and root font size.
14
+ * @returns A CSS clamp string, e.g. `clamp(1rem, 0.6479rem + 1.5023vw, 2rem)`, or a static `rem` value if min equals max.
15
+ *
16
+ * @throws {TypeError} If inputs are non-finite numbers.
17
+ * @throws {RangeError} If rootFontSize <= 0, or minViewport/maxViewport are invalid or equal.
18
+ */
19
+ export declare function computeClamp(maxPx: number, minPx?: number, config?: FluidConfig): string;
20
+ export type { FluidConfig };
21
+ //# sourceMappingURL=index.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.mts","names":[],"sources":["../src/core/math.ts"],"mappings":";;;;;wBAMgB,YAAY,aAAa;;;;;;;;;;;;;wBAwBzB,aACd,eACA,gBACA,SAAS"}
package/dist/index.mjs ADDED
@@ -0,0 +1 @@
1
+ export { t as cleanNumber, n as computeClamp } from "./math-BwacRfp6.mjs";
@@ -0,0 +1,55 @@
1
+ // src/core/math.ts
2
+ /**
3
+ * Cleanly formats a floating point number up to a maximum number of decimal places,
4
+ * stripping unnecessary trailing zeros and avoiding negative zero (-0).
5
+ */
6
+ function cleanNumber(num, maxDecimals = 4) {
7
+ if (Object.is(num, -0) || Math.abs(num) < 1e-12) return "0";
8
+ const factor = 10 ** maxDecimals;
9
+ const rounded = Math.round((num + Number.EPSILON) * factor) / factor;
10
+ if (Object.is(rounded, -0) || Math.abs(rounded) < 1e-12) return "0";
11
+ return rounded.toString();
12
+ }
13
+ /**
14
+ * Computes a CSS `clamp()` expression providing linear fluid scaling between
15
+ * `minViewport` and `maxViewport`.
16
+ *
17
+ * @param maxPx - The target size in pixels at the maximum viewport width.
18
+ * @param minPx - Optional minimum size in pixels at the minimum viewport width. Defaults to `maxPx * minScaleRatio`.
19
+ * @param config - Optional configuration overrides for viewports, scale ratio, and root font size.
20
+ * @returns A CSS clamp string, e.g. `clamp(1rem, 0.6479rem + 1.5023vw, 2rem)`, or a static `rem` value if min equals max.
21
+ *
22
+ * @throws {TypeError} If inputs are non-finite numbers.
23
+ * @throws {RangeError} If rootFontSize <= 0, or minViewport/maxViewport are invalid or equal.
24
+ */
25
+ function computeClamp(maxPx, minPx, config) {
26
+ if (!Number.isFinite(maxPx)) throw new TypeError(`maxPx must be a finite number, received: ${maxPx}`);
27
+ if (minPx !== void 0 && !Number.isFinite(minPx)) throw new TypeError(`minPx must be a finite number, received: ${minPx}`);
28
+ const minViewport = config?.minViewport ?? 375;
29
+ const maxViewport = config?.maxViewport ?? 1440;
30
+ const minScaleRatio = config?.minScaleRatio ?? .75;
31
+ const rootFontSize = config?.rootFontSize ?? 16;
32
+ if (!Number.isFinite(rootFontSize) || rootFontSize <= 0) throw new RangeError(`rootFontSize must be a positive number greater than 0, received: ${rootFontSize}`);
33
+ if (!Number.isFinite(minViewport) || minViewport <= 0) throw new RangeError(`minViewport must be a positive number greater than 0, received: ${minViewport}`);
34
+ if (!Number.isFinite(maxViewport) || maxViewport <= 0) throw new RangeError(`maxViewport must be a positive number greater than 0, received: ${maxViewport}`);
35
+ if (minViewport === maxViewport) throw new RangeError(`minViewport and maxViewport cannot be equal (${minViewport} === ${maxViewport})`);
36
+ const resolvedMinPx = minPx !== void 0 ? minPx : maxPx * minScaleRatio;
37
+ if (resolvedMinPx === maxPx) return `${cleanNumber(maxPx / rootFontSize)}rem`;
38
+ const slope = (maxPx - resolvedMinPx) / (maxViewport - minViewport);
39
+ const intercept = resolvedMinPx - slope * minViewport;
40
+ const slopeVw = slope * 100;
41
+ const interceptRem = intercept / rootFontSize;
42
+ const slopeStr = cleanNumber(slopeVw);
43
+ const interceptStr = cleanNumber(interceptRem);
44
+ let preferred;
45
+ if (slopeStr === "0") preferred = `${interceptStr}rem`;
46
+ else if (interceptStr === "0") preferred = `${slopeStr}vw`;
47
+ else if (Number(slopeStr) > 0) preferred = `${interceptStr}rem + ${slopeStr}vw`;
48
+ else preferred = `${interceptStr}rem - ${cleanNumber(Math.abs(Number(slopeStr)))}vw`;
49
+ const lowerRem = Math.min(resolvedMinPx, maxPx) / rootFontSize;
50
+ const upperRem = Math.max(resolvedMinPx, maxPx) / rootFontSize;
51
+ return `clamp(${cleanNumber(lowerRem)}rem, ${preferred}, ${cleanNumber(upperRem)}rem)`;
52
+ }
53
+ export { computeClamp as n, cleanNumber as t };
54
+
55
+ //# sourceMappingURL=math-BwacRfp6.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"math-BwacRfp6.mjs","names":[],"sources":["../src/core/math.ts"],"sourcesContent":["import type { FluidConfig } from './types.js';\n\n/**\n * Cleanly formats a floating point number up to a maximum number of decimal places,\n * stripping unnecessary trailing zeros and avoiding negative zero (-0).\n */\nexport function cleanNumber(num: number, maxDecimals: number = 4): string {\n if (Object.is(num, -0) || Math.abs(num) < 1e-12) {\n return '0';\n }\n const factor = 10 ** maxDecimals;\n const rounded = Math.round((num + Number.EPSILON) * factor) / factor;\n if (Object.is(rounded, -0) || Math.abs(rounded) < 1e-12) {\n return '0';\n }\n return rounded.toString();\n}\n\n/**\n * Computes a CSS `clamp()` expression providing linear fluid scaling between\n * `minViewport` and `maxViewport`.\n *\n * @param maxPx - The target size in pixels at the maximum viewport width.\n * @param minPx - Optional minimum size in pixels at the minimum viewport width. Defaults to `maxPx * minScaleRatio`.\n * @param config - Optional configuration overrides for viewports, scale ratio, and root font size.\n * @returns A CSS clamp string, e.g. `clamp(1rem, 0.6479rem + 1.5023vw, 2rem)`, or a static `rem` value if min equals max.\n *\n * @throws {TypeError} If inputs are non-finite numbers.\n * @throws {RangeError} If rootFontSize <= 0, or minViewport/maxViewport are invalid or equal.\n */\nexport function computeClamp(\n maxPx: number,\n minPx?: number,\n config?: FluidConfig\n): string {\n if (!Number.isFinite(maxPx)) {\n throw new TypeError(`maxPx must be a finite number, received: ${maxPx}`);\n }\n\n if (minPx !== undefined && !Number.isFinite(minPx)) {\n throw new TypeError(`minPx must be a finite number, received: ${minPx}`);\n }\n\n const minViewport = config?.minViewport ?? 375;\n const maxViewport = config?.maxViewport ?? 1440;\n const minScaleRatio = config?.minScaleRatio ?? 0.75;\n const rootFontSize = config?.rootFontSize ?? 16;\n\n if (!Number.isFinite(rootFontSize) || rootFontSize <= 0) {\n throw new RangeError(\n `rootFontSize must be a positive number greater than 0, received: ${rootFontSize}`\n );\n }\n\n if (!Number.isFinite(minViewport) || minViewport <= 0) {\n throw new RangeError(\n `minViewport must be a positive number greater than 0, received: ${minViewport}`\n );\n }\n\n if (!Number.isFinite(maxViewport) || maxViewport <= 0) {\n throw new RangeError(\n `maxViewport must be a positive number greater than 0, received: ${maxViewport}`\n );\n }\n\n if (minViewport === maxViewport) {\n throw new RangeError(\n `minViewport and maxViewport cannot be equal (${minViewport} === ${maxViewport})`\n );\n }\n\n const resolvedMinPx = minPx !== undefined ? minPx : maxPx * minScaleRatio;\n\n // Degenerate case: if min equals max, no clamp is required\n if (resolvedMinPx === maxPx) {\n return `${cleanNumber(maxPx / rootFontSize)}rem`;\n }\n\n // Calculate linear slope (px / px) and intercept (px)\n const slope = (maxPx - resolvedMinPx) / (maxViewport - minViewport);\n const intercept = resolvedMinPx - slope * minViewport;\n\n // Preferred value parts\n const slopeVw = slope * 100;\n const interceptRem = intercept / rootFontSize;\n\n const slopeStr = cleanNumber(slopeVw);\n const interceptStr = cleanNumber(interceptRem);\n\n let preferred: string;\n if (slopeStr === '0') {\n preferred = `${interceptStr}rem`;\n } else if (interceptStr === '0') {\n preferred = `${slopeStr}vw`;\n } else if (Number(slopeStr) > 0) {\n preferred = `${interceptStr}rem + ${slopeStr}vw`;\n } else {\n // slope is negative: \"interceptrem - |slope|vw\"\n const absSlopeStr = cleanNumber(Math.abs(Number(slopeStr)));\n preferred = `${interceptStr}rem - ${absSlopeStr}vw`;\n }\n\n // Ensure CSS clamp bounds: clamp(MIN, VAL, MAX) requires MIN <= MAX.\n // When minPx > maxPx, the value decreases with viewport width, so\n // maxPx / rootFontSize is the lower bound and resolvedMinPx / rootFontSize is the upper bound.\n const lowerRem = Math.min(resolvedMinPx, maxPx) / rootFontSize;\n const upperRem = Math.max(resolvedMinPx, maxPx) / rootFontSize;\n\n return `clamp(${cleanNumber(lowerRem)}rem, ${preferred}, ${cleanNumber(upperRem)}rem)`;\n}\n"],"mappings":";;;;;AAMA,SAAgB,YAAY,KAAa,cAAsB,GAAW;CACxE,IAAI,OAAO,GAAG,KAAK,EAAE,KAAK,KAAK,IAAI,GAAG,IAAI,OACxC,OAAO;CAET,MAAM,SAAS,MAAM;CACrB,MAAM,UAAU,KAAK,OAAO,MAAM,OAAO,WAAW,MAAM,IAAI;CAC9D,IAAI,OAAO,GAAG,SAAS,EAAE,KAAK,KAAK,IAAI,OAAO,IAAI,OAChD,OAAO;CAET,OAAO,QAAQ,SAAS;AAC1B;;;;;;;;;;;;;AAcA,SAAgB,aACd,OACA,OACA,QACQ;CACR,IAAI,CAAC,OAAO,SAAS,KAAK,GACxB,MAAM,IAAI,UAAU,4CAA4C,OAAO;CAGzE,IAAI,UAAU,KAAA,KAAa,CAAC,OAAO,SAAS,KAAK,GAC/C,MAAM,IAAI,UAAU,4CAA4C,OAAO;CAGzE,MAAM,cAAc,QAAQ,eAAe;CAC3C,MAAM,cAAc,QAAQ,eAAe;CAC3C,MAAM,gBAAgB,QAAQ,iBAAiB;CAC/C,MAAM,eAAe,QAAQ,gBAAgB;CAE7C,IAAI,CAAC,OAAO,SAAS,YAAY,KAAK,gBAAgB,GACpD,MAAM,IAAI,WACR,oEAAoE,cACtE;CAGF,IAAI,CAAC,OAAO,SAAS,WAAW,KAAK,eAAe,GAClD,MAAM,IAAI,WACR,mEAAmE,aACrE;CAGF,IAAI,CAAC,OAAO,SAAS,WAAW,KAAK,eAAe,GAClD,MAAM,IAAI,WACR,mEAAmE,aACrE;CAGF,IAAI,gBAAgB,aAClB,MAAM,IAAI,WACR,gDAAgD,YAAY,OAAO,YAAY,EACjF;CAGF,MAAM,gBAAgB,UAAU,KAAA,IAAY,QAAQ,QAAQ;CAG5D,IAAI,kBAAkB,OACpB,OAAO,GAAG,YAAY,QAAQ,YAAY,EAAE;CAI9C,MAAM,SAAS,QAAQ,kBAAkB,cAAc;CACvD,MAAM,YAAY,gBAAgB,QAAQ;CAG1C,MAAM,UAAU,QAAQ;CACxB,MAAM,eAAe,YAAY;CAEjC,MAAM,WAAW,YAAY,OAAO;CACpC,MAAM,eAAe,YAAY,YAAY;CAE7C,IAAI;CACJ,IAAI,aAAa,KACf,YAAY,GAAG,aAAa;MACvB,IAAI,iBAAiB,KAC1B,YAAY,GAAG,SAAS;MACnB,IAAI,OAAO,QAAQ,IAAI,GAC5B,YAAY,GAAG,aAAa,QAAQ,SAAS;MAI7C,YAAY,GAAG,aAAa,QADR,YAAY,KAAK,IAAI,OAAO,QAAQ,CAAC,CACX,EAAE;CAMlD,MAAM,WAAW,KAAK,IAAI,eAAe,KAAK,IAAI;CAClD,MAAM,WAAW,KAAK,IAAI,eAAe,KAAK,IAAI;CAElD,OAAO,SAAS,YAAY,QAAQ,EAAE,OAAO,UAAU,IAAI,YAAY,QAAQ,EAAE;AACnF"}
@@ -0,0 +1,64 @@
1
+ // src/core/math.ts
2
+ /**
3
+ * Cleanly formats a floating point number up to a maximum number of decimal places,
4
+ * stripping unnecessary trailing zeros and avoiding negative zero (-0).
5
+ */
6
+ function cleanNumber(num, maxDecimals = 4) {
7
+ if (Object.is(num, -0) || Math.abs(num) < 1e-12) return "0";
8
+ const factor = 10 ** maxDecimals;
9
+ const rounded = Math.round((num + Number.EPSILON) * factor) / factor;
10
+ if (Object.is(rounded, -0) || Math.abs(rounded) < 1e-12) return "0";
11
+ return rounded.toString();
12
+ }
13
+ /**
14
+ * Computes a CSS `clamp()` expression providing linear fluid scaling between
15
+ * `minViewport` and `maxViewport`.
16
+ *
17
+ * @param maxPx - The target size in pixels at the maximum viewport width.
18
+ * @param minPx - Optional minimum size in pixels at the minimum viewport width. Defaults to `maxPx * minScaleRatio`.
19
+ * @param config - Optional configuration overrides for viewports, scale ratio, and root font size.
20
+ * @returns A CSS clamp string, e.g. `clamp(1rem, 0.6479rem + 1.5023vw, 2rem)`, or a static `rem` value if min equals max.
21
+ *
22
+ * @throws {TypeError} If inputs are non-finite numbers.
23
+ * @throws {RangeError} If rootFontSize <= 0, or minViewport/maxViewport are invalid or equal.
24
+ */
25
+ function computeClamp(maxPx, minPx, config) {
26
+ if (!Number.isFinite(maxPx)) throw new TypeError(`maxPx must be a finite number, received: ${maxPx}`);
27
+ if (minPx !== void 0 && !Number.isFinite(minPx)) throw new TypeError(`minPx must be a finite number, received: ${minPx}`);
28
+ const minViewport = config?.minViewport ?? 375;
29
+ const maxViewport = config?.maxViewport ?? 1440;
30
+ const minScaleRatio = config?.minScaleRatio ?? .75;
31
+ const rootFontSize = config?.rootFontSize ?? 16;
32
+ if (!Number.isFinite(rootFontSize) || rootFontSize <= 0) throw new RangeError(`rootFontSize must be a positive number greater than 0, received: ${rootFontSize}`);
33
+ if (!Number.isFinite(minViewport) || minViewport <= 0) throw new RangeError(`minViewport must be a positive number greater than 0, received: ${minViewport}`);
34
+ if (!Number.isFinite(maxViewport) || maxViewport <= 0) throw new RangeError(`maxViewport must be a positive number greater than 0, received: ${maxViewport}`);
35
+ if (minViewport === maxViewport) throw new RangeError(`minViewport and maxViewport cannot be equal (${minViewport} === ${maxViewport})`);
36
+ const resolvedMinPx = minPx !== void 0 ? minPx : maxPx * minScaleRatio;
37
+ if (resolvedMinPx === maxPx) return `${cleanNumber(maxPx / rootFontSize)}rem`;
38
+ const slope = (maxPx - resolvedMinPx) / (maxViewport - minViewport);
39
+ const intercept = resolvedMinPx - slope * minViewport;
40
+ const slopeVw = slope * 100;
41
+ const interceptRem = intercept / rootFontSize;
42
+ const slopeStr = cleanNumber(slopeVw);
43
+ const interceptStr = cleanNumber(interceptRem);
44
+ let preferred;
45
+ if (slopeStr === "0") preferred = `${interceptStr}rem`;
46
+ else if (interceptStr === "0") preferred = `${slopeStr}vw`;
47
+ else if (Number(slopeStr) > 0) preferred = `${interceptStr}rem + ${slopeStr}vw`;
48
+ else preferred = `${interceptStr}rem - ${cleanNumber(Math.abs(Number(slopeStr)))}vw`;
49
+ const lowerRem = Math.min(resolvedMinPx, maxPx) / rootFontSize;
50
+ const upperRem = Math.max(resolvedMinPx, maxPx) / rootFontSize;
51
+ return `clamp(${cleanNumber(lowerRem)}rem, ${preferred}, ${cleanNumber(upperRem)}rem)`;
52
+ }
53
+ Object.defineProperty(exports, "cleanNumber", {
54
+ enumerable: true,
55
+ get: function() {
56
+ return cleanNumber;
57
+ }
58
+ });
59
+ Object.defineProperty(exports, "computeClamp", {
60
+ enumerable: true,
61
+ get: function() {
62
+ return computeClamp;
63
+ }
64
+ });
@@ -0,0 +1,43 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ let react = require("react");
3
+ let react_native = require("react-native");
4
+ // src/native/useFluidNative.ts
5
+ /**
6
+ * React Native hook that computes responsive scale functions based on dynamic window dimensions,
7
+ * accounting for device orientation, split-screen, foldables, and tablet scaling caps.
8
+ */
9
+ function useFluidNative(options = {}) {
10
+ const { guidelineBaseWidth = 375, guidelineBaseHeight = 812, maxTabletScale = 1.35 } = options;
11
+ const { width, height } = (0, react_native.useWindowDimensions)();
12
+ return (0, react.useMemo)(() => {
13
+ const isTablet = Math.min(width, height) >= 600;
14
+ const rawHorizontalScale = width / guidelineBaseWidth;
15
+ const rawVerticalScale = height / guidelineBaseHeight;
16
+ const horizontalScale = isTablet ? Math.min(rawHorizontalScale, maxTabletScale) : rawHorizontalScale;
17
+ const verticalScaleRatio = isTablet ? Math.min(rawVerticalScale, maxTabletScale) : rawVerticalScale;
18
+ const scale = (size) => {
19
+ return react_native.PixelRatio.roundToNearestPixel(size * horizontalScale);
20
+ };
21
+ const verticalScale = (size) => {
22
+ return react_native.PixelRatio.roundToNearestPixel(size * verticalScaleRatio);
23
+ };
24
+ const moderateScale = (size, factor = .5) => {
25
+ return react_native.PixelRatio.roundToNearestPixel(size + (scale(size) - size) * factor);
26
+ };
27
+ return {
28
+ scale,
29
+ verticalScale,
30
+ moderateScale,
31
+ isTablet,
32
+ width,
33
+ height
34
+ };
35
+ }, [
36
+ width,
37
+ height,
38
+ guidelineBaseWidth,
39
+ guidelineBaseHeight,
40
+ maxTabletScale
41
+ ]);
42
+ }
43
+ exports.useFluidNative = useFluidNative;
@@ -0,0 +1,52 @@
1
+ interface NativeScaleOptions {
2
+ /**
3
+ * Guideline screen width of the design prototype in dp.
4
+ * @default 375
5
+ */
6
+ guidelineBaseWidth?: number;
7
+ /**
8
+ * Guideline screen height of the design prototype in dp.
9
+ * @default 812
10
+ */
11
+ guidelineBaseHeight?: number;
12
+ /**
13
+ * Maximum scaling multiplier applied on tablet devices to prevent oversized elements.
14
+ * @default 1.35
15
+ */
16
+ maxTabletScale?: number;
17
+ }
18
+ interface FluidNativeResult {
19
+ /**
20
+ * Scales a size horizontally based on the current window width relative to guidelineBaseWidth.
21
+ */
22
+ scale: (size: number) => number;
23
+ /**
24
+ * Scales a size vertically based on the current window height relative to guidelineBaseHeight.
25
+ */
26
+ verticalScale: (size: number) => number;
27
+ /**
28
+ * Moderately scales a size with a configurable damping factor.
29
+ * @param size - The base size to scale.
30
+ * @param factor - Damping factor between 0 (unscaled) and 1 (fully scaled). Default 0.5.
31
+ */
32
+ moderateScale: (size: number, factor?: number) => number;
33
+ /**
34
+ * Whether the current screen is classified as a tablet (shortest dimension >= 600dp).
35
+ */
36
+ isTablet: boolean;
37
+ /**
38
+ * Current window width in dp.
39
+ */
40
+ width: number;
41
+ /**
42
+ * Current window height in dp.
43
+ */
44
+ height: number;
45
+ }
46
+ /**
47
+ * React Native hook that computes responsive scale functions based on dynamic window dimensions,
48
+ * accounting for device orientation, split-screen, foldables, and tablet scaling caps.
49
+ */
50
+ export declare function useFluidNative(options?: NativeScaleOptions): FluidNativeResult;
51
+ export type { FluidNativeResult, NativeScaleOptions };
52
+ //# sourceMappingURL=index.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.cts","names":[],"sources":["../../src/native/types.ts","../../src/native/useFluidNative.ts"],"mappings":"A,UAAiB;;;;;EAKf;;;;;EAMA;;;;;EAMA;;UAGe;;;;EAIf,QAAQ;;;;EAKR,gBAAgB;;;;;;EAOhB,gBAAgB,cAAc;;;;EAK9B;;;;EAKA;;;;EAKA;;;;;;wBC3Cc,eAAe,UAAS,qBAA0B"}
@@ -0,0 +1,52 @@
1
+ interface NativeScaleOptions {
2
+ /**
3
+ * Guideline screen width of the design prototype in dp.
4
+ * @default 375
5
+ */
6
+ guidelineBaseWidth?: number;
7
+ /**
8
+ * Guideline screen height of the design prototype in dp.
9
+ * @default 812
10
+ */
11
+ guidelineBaseHeight?: number;
12
+ /**
13
+ * Maximum scaling multiplier applied on tablet devices to prevent oversized elements.
14
+ * @default 1.35
15
+ */
16
+ maxTabletScale?: number;
17
+ }
18
+ interface FluidNativeResult {
19
+ /**
20
+ * Scales a size horizontally based on the current window width relative to guidelineBaseWidth.
21
+ */
22
+ scale: (size: number) => number;
23
+ /**
24
+ * Scales a size vertically based on the current window height relative to guidelineBaseHeight.
25
+ */
26
+ verticalScale: (size: number) => number;
27
+ /**
28
+ * Moderately scales a size with a configurable damping factor.
29
+ * @param size - The base size to scale.
30
+ * @param factor - Damping factor between 0 (unscaled) and 1 (fully scaled). Default 0.5.
31
+ */
32
+ moderateScale: (size: number, factor?: number) => number;
33
+ /**
34
+ * Whether the current screen is classified as a tablet (shortest dimension >= 600dp).
35
+ */
36
+ isTablet: boolean;
37
+ /**
38
+ * Current window width in dp.
39
+ */
40
+ width: number;
41
+ /**
42
+ * Current window height in dp.
43
+ */
44
+ height: number;
45
+ }
46
+ /**
47
+ * React Native hook that computes responsive scale functions based on dynamic window dimensions,
48
+ * accounting for device orientation, split-screen, foldables, and tablet scaling caps.
49
+ */
50
+ export declare function useFluidNative(options?: NativeScaleOptions): FluidNativeResult;
51
+ export type { FluidNativeResult, NativeScaleOptions };
52
+ //# sourceMappingURL=index.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.mts","names":[],"sources":["../../src/native/types.ts","../../src/native/useFluidNative.ts"],"mappings":"A,UAAiB;;;;;EAKf;;;;;EAMA;;;;;EAMA;;UAGe;;;;EAIf,QAAQ;;;;EAKR,gBAAgB;;;;;;EAOhB,gBAAgB,cAAc;;;;EAK9B;;;;EAKA;;;;EAKA;;;;;;wBC3Cc,eAAe,UAAS,qBAA0B"}
@@ -0,0 +1,44 @@
1
+ import { useMemo } from "react";
2
+ import { PixelRatio, useWindowDimensions } from "react-native";
3
+ // src/native/useFluidNative.ts
4
+ /**
5
+ * React Native hook that computes responsive scale functions based on dynamic window dimensions,
6
+ * accounting for device orientation, split-screen, foldables, and tablet scaling caps.
7
+ */
8
+ function useFluidNative(options = {}) {
9
+ const { guidelineBaseWidth = 375, guidelineBaseHeight = 812, maxTabletScale = 1.35 } = options;
10
+ const { width, height } = useWindowDimensions();
11
+ return useMemo(() => {
12
+ const isTablet = Math.min(width, height) >= 600;
13
+ const rawHorizontalScale = width / guidelineBaseWidth;
14
+ const rawVerticalScale = height / guidelineBaseHeight;
15
+ const horizontalScale = isTablet ? Math.min(rawHorizontalScale, maxTabletScale) : rawHorizontalScale;
16
+ const verticalScaleRatio = isTablet ? Math.min(rawVerticalScale, maxTabletScale) : rawVerticalScale;
17
+ const scale = (size) => {
18
+ return PixelRatio.roundToNearestPixel(size * horizontalScale);
19
+ };
20
+ const verticalScale = (size) => {
21
+ return PixelRatio.roundToNearestPixel(size * verticalScaleRatio);
22
+ };
23
+ const moderateScale = (size, factor = .5) => {
24
+ return PixelRatio.roundToNearestPixel(size + (scale(size) - size) * factor);
25
+ };
26
+ return {
27
+ scale,
28
+ verticalScale,
29
+ moderateScale,
30
+ isTablet,
31
+ width,
32
+ height
33
+ };
34
+ }, [
35
+ width,
36
+ height,
37
+ guidelineBaseWidth,
38
+ guidelineBaseHeight,
39
+ maxTabletScale
40
+ ]);
41
+ }
42
+ export { useFluidNative };
43
+
44
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.mjs","names":[],"sources":["../../src/native/useFluidNative.ts"],"sourcesContent":["import { useMemo } from 'react';\nimport { useWindowDimensions, PixelRatio } from 'react-native';\nimport type { NativeScaleOptions, FluidNativeResult } from './types.js';\n\n/**\n * React Native hook that computes responsive scale functions based on dynamic window dimensions,\n * accounting for device orientation, split-screen, foldables, and tablet scaling caps.\n */\nexport function useFluidNative(options: NativeScaleOptions = {}): FluidNativeResult {\n const {\n guidelineBaseWidth = 375,\n guidelineBaseHeight = 812,\n maxTabletScale = 1.35,\n } = options;\n\n const { width, height } = useWindowDimensions();\n\n return useMemo(() => {\n const shortestDimension = Math.min(width, height);\n const isTablet = shortestDimension >= 600;\n\n const rawHorizontalScale = width / guidelineBaseWidth;\n const rawVerticalScale = height / guidelineBaseHeight;\n\n const horizontalScale = isTablet\n ? Math.min(rawHorizontalScale, maxTabletScale)\n : rawHorizontalScale;\n\n const verticalScaleRatio = isTablet\n ? Math.min(rawVerticalScale, maxTabletScale)\n : rawVerticalScale;\n\n const scale = (size: number): number => {\n return PixelRatio.roundToNearestPixel(size * horizontalScale);\n };\n\n const verticalScale = (size: number): number => {\n return PixelRatio.roundToNearestPixel(size * verticalScaleRatio);\n };\n\n const moderateScale = (size: number, factor: number = 0.5): number => {\n return PixelRatio.roundToNearestPixel(size + (scale(size) - size) * factor);\n };\n\n return {\n scale,\n verticalScale,\n moderateScale,\n isTablet,\n width,\n height,\n };\n }, [width, height, guidelineBaseWidth, guidelineBaseHeight, maxTabletScale]);\n}\n"],"mappings":";;;;;;;AAQA,SAAgB,eAAe,UAA8B,CAAC,GAAsB;CAClF,MAAM,EACJ,qBAAqB,KACrB,sBAAsB,KACtB,iBAAiB,SACf;CAEJ,MAAM,EAAE,OAAO,WAAW,oBAAoB;CAE9C,OAAO,cAAc;EAEnB,MAAM,WADoB,KAAK,IAAI,OAAO,MACT,KAAK;EAEtC,MAAM,qBAAqB,QAAQ;EACnC,MAAM,mBAAmB,SAAS;EAElC,MAAM,kBAAkB,WACpB,KAAK,IAAI,oBAAoB,cAAc,IAC3C;EAEJ,MAAM,qBAAqB,WACvB,KAAK,IAAI,kBAAkB,cAAc,IACzC;EAEJ,MAAM,SAAS,SAAyB;GACtC,OAAO,WAAW,oBAAoB,OAAO,eAAe;EAC9D;EAEA,MAAM,iBAAiB,SAAyB;GAC9C,OAAO,WAAW,oBAAoB,OAAO,kBAAkB;EACjE;EAEA,MAAM,iBAAiB,MAAc,SAAiB,OAAgB;GACpE,OAAO,WAAW,oBAAoB,QAAQ,MAAM,IAAI,IAAI,QAAQ,MAAM;EAC5E;EAEA,OAAO;GACL;GACA;GACA;GACA;GACA;GACA;EACF;CACF,GAAG;EAAC;EAAO;EAAQ;EAAoB;EAAqB;CAAc,CAAC;AAC7E"}
@@ -0,0 +1,92 @@
1
+ Object.defineProperties(exports, {
2
+ __esModule: { value: true },
3
+ [Symbol.toStringTag]: { value: "Module" }
4
+ });
5
+ const require_math = require("../math-DKxTMW4W.cjs");
6
+ // src/postcss/index.ts
7
+ const DEFAULT_PROPERTIES = [
8
+ "font-size",
9
+ "padding",
10
+ "padding-top",
11
+ "padding-right",
12
+ "padding-bottom",
13
+ "padding-left",
14
+ "padding-inline",
15
+ "padding-block",
16
+ "margin",
17
+ "margin-top",
18
+ "margin-right",
19
+ "margin-bottom",
20
+ "margin-left",
21
+ "margin-inline",
22
+ "margin-block",
23
+ "gap",
24
+ "row-gap",
25
+ "column-gap",
26
+ "border-radius"
27
+ ];
28
+ /**
29
+ * Checks whether a declaration is nested within a `@media` at-rule.
30
+ */
31
+ function isInsideMediaRule(decl) {
32
+ let parent = decl.parent;
33
+ while (parent) {
34
+ if (parent.type === "atrule" && parent.name?.toLowerCase() === "media") return true;
35
+ parent = parent.parent;
36
+ }
37
+ return false;
38
+ }
39
+ /**
40
+ * Checks whether a declaration has an explicit `fluid-ignore` opt-out comment.
41
+ */
42
+ function hasFluidIgnore(decl) {
43
+ const prev = decl.prev();
44
+ if (prev && prev.type === "comment" && prev.text.trim().toLowerCase() === "fluid-ignore") {
45
+ const prevOfPrev = prev.prev?.();
46
+ if (!(prevOfPrev?.source?.end?.line && prev.source?.start?.line && prevOfPrev.source.end.line === prev.source.start.line)) return true;
47
+ }
48
+ const next = decl.next();
49
+ if (next && next.type === "comment" && next.text.trim().toLowerCase() === "fluid-ignore") {
50
+ if (decl.source?.end?.line && next.source?.start?.line && decl.source.end.line === next.source.start.line) return true;
51
+ }
52
+ const rawValue = decl.raws?.value?.raw;
53
+ if (rawValue && /\/\*\s*fluid-ignore\s*\*\//i.test(rawValue)) return true;
54
+ if (decl.value && /\/\*\s*fluid-ignore\s*\*\//i.test(decl.value)) return true;
55
+ return false;
56
+ }
57
+ /**
58
+ * PostCSS plugin that automatically converts pixel units to fluid clamp() expressions.
59
+ */
60
+ const postcssFluidScale = (options = {}) => {
61
+ const propertyList = options.properties ?? DEFAULT_PROPERTIES;
62
+ const targetProperties = new Set(propertyList.map((p) => p.toLowerCase()));
63
+ const minThresholdPx = options.minThresholdPx ?? 4;
64
+ const fluidConfig = {
65
+ minViewport: options.minViewport,
66
+ maxViewport: options.maxViewport,
67
+ minScaleRatio: options.minScaleRatio,
68
+ rootFontSize: options.rootFontSize
69
+ };
70
+ return {
71
+ postcssPlugin: "postcss-fluid-scale",
72
+ Declaration(decl) {
73
+ const propLower = decl.prop.toLowerCase();
74
+ if (!targetProperties.has(propLower)) return;
75
+ if (decl.value.includes("clamp(")) return;
76
+ if (isInsideMediaRule(decl)) return;
77
+ if (hasFluidIgnore(decl)) return;
78
+ const PX_REGEX = /(?<![\w-])(-?\d*\.?\d+)px\b/gi;
79
+ let transformed = false;
80
+ const newValue = decl.value.replace(PX_REGEX, (match, numStr) => {
81
+ const px = parseFloat(numStr);
82
+ if (!Number.isFinite(px) || Math.abs(px) < minThresholdPx) return match;
83
+ transformed = true;
84
+ return require_math.computeClamp(px, void 0, fluidConfig);
85
+ });
86
+ if (transformed) decl.value = newValue;
87
+ }
88
+ };
89
+ };
90
+ postcssFluidScale.postcss = true;
91
+ exports.default = postcssFluidScale;
92
+ exports.postcssFluidScale = postcssFluidScale;
@@ -0,0 +1,24 @@
1
+ import { PluginCreator } from "postcss";
2
+ import { t as FluidConfig } from "../types-AEQZQGT8.cjs";
3
+ /**
4
+ * Options for the postcssFluidScale plugin.
5
+ */
6
+ interface PostcssFluidOptions extends FluidConfig {
7
+ /**
8
+ * CSS property names to automatically scale. Case-insensitive.
9
+ * Defaults to typography, spacing (padding, margin, gap), and border-radius.
10
+ */
11
+ properties?: string[];
12
+ /**
13
+ * Minimum pixel threshold to scale. Absolute pixel values below this
14
+ * threshold (e.g. 1px borders, hairlines) are preserved as-is.
15
+ * @default 4
16
+ */
17
+ minThresholdPx?: number;
18
+ }
19
+ /**
20
+ * PostCSS plugin that automatically converts pixel units to fluid clamp() expressions.
21
+ */
22
+ declare const postcssFluidScale: PluginCreator<PostcssFluidOptions>;
23
+ export { type PostcssFluidOptions, postcssFluidScale as default, postcssFluidScale };
24
+ //# sourceMappingURL=index.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.cts","names":[],"sources":["../../src/postcss/types.ts","../../src/postcss/index.ts"],"mappings":";;;;;UAKiB,4BAA4B;;;;;EAK3C;;;;;;EAOA;;;;;cC0EI,mBAAmB,cAAc"}
@@ -0,0 +1,24 @@
1
+ import { PluginCreator } from "postcss";
2
+ import { t as FluidConfig } from "../types-CrliGpq8.mjs";
3
+ /**
4
+ * Options for the postcssFluidScale plugin.
5
+ */
6
+ interface PostcssFluidOptions extends FluidConfig {
7
+ /**
8
+ * CSS property names to automatically scale. Case-insensitive.
9
+ * Defaults to typography, spacing (padding, margin, gap), and border-radius.
10
+ */
11
+ properties?: string[];
12
+ /**
13
+ * Minimum pixel threshold to scale. Absolute pixel values below this
14
+ * threshold (e.g. 1px borders, hairlines) are preserved as-is.
15
+ * @default 4
16
+ */
17
+ minThresholdPx?: number;
18
+ }
19
+ /**
20
+ * PostCSS plugin that automatically converts pixel units to fluid clamp() expressions.
21
+ */
22
+ declare const postcssFluidScale: PluginCreator<PostcssFluidOptions>;
23
+ export { type PostcssFluidOptions, postcssFluidScale as default, postcssFluidScale };
24
+ //# sourceMappingURL=index.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.mts","names":[],"sources":["../../src/postcss/types.ts","../../src/postcss/index.ts"],"mappings":";;;;;UAKiB,4BAA4B;;;;;EAK3C;;;;;;EAOA;;;;;cC0EI,mBAAmB,cAAc"}