@cssints/fluid 0.0.0-stage → 0.2.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 ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Alexei Accio
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,69 @@
1
- # Temporary Holding Version
1
+ # @cssints/fluid
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 lengths for [cssints](../../README.md): `fluid(min, max)` is a length that is `min` on a narrow viewport, `max` on a
4
+ wide one, and grows linearly between. The `clamp()` is computed at build time, and a range that breaks text resizing
5
+ (WCAG 1.4.4) fails the build. Two value members of `cssints/plugin` `scope()` (`fn({ args, value })`, positional
6
+ arguments and an options object). No runtime.
7
+
8
+ ```ts
9
+ import { fontSize, padding } from "cssints" with { type: "cssints" };
10
+ import { fluid } from "@cssints/fluid" with { type: "cssints" };
11
+
12
+ // fluid(min, max, { from?, to?, zoom? }): from and to are the widths, 20rem and 80rem when left out
13
+ export const title = fontSize(fluid("1rem", "1.5rem"));
14
+ export const lead = fontSize(fluid("16px", "24px", { from: "40rem", to: "90rem" }));
15
+ // against the inline size of the nearest container instead of the viewport
16
+ export const card = padding(fluid.container("1rem", "2rem", { to: "60rem" }));
17
+
18
+ export const hero = fontSize(fluid("1rem", "4rem")); // build error: fails WCAG 1.4.4
19
+ ```
20
+
21
+ ```css
22
+ ._bkcdcr {
23
+ font-size: clamp(1rem, 0.8333vw + 0.8333rem, 1.5rem);
24
+ }
25
+ ._1wkr2lu {
26
+ font-size: clamp(16px, 1vw + 0.6rem, 24px);
27
+ }
28
+ ._ekb8uj {
29
+ padding: clamp(1rem, 2.5cqi + 0.5rem, 2rem);
30
+ }
31
+ ```
32
+
33
+ ## Rules
34
+
35
+ - **The math.** The slope is `(max - min) / (to - from)` and the intercept `min - slope × from`, written
36
+ `clamp(min, <slope × 100>vw + <intercept>rem, max)`, rounded to 4 decimals. The intercept is in rem, so the value follows
37
+ the user's font size. A `max` below `min` makes a value that shrinks: the bounds are sorted for `clamp()` and the slope is
38
+ negative.
39
+ - **Units.** `min`, `max`, `from` and `to` are px or rem, at 16px to the rem; the bounds keep the unit you wrote. Other
40
+ units (`em`, `vw`, `%`, `calc()`, tokens) cannot be computed at build time: the build rejects them (the types check a
41
+ non-negative `<length>`, and a grammar cannot name units).
42
+ - **WCAG 1.4.4.** The check of [fluid-tailwind](https://github.com/barvian/fluid-tailwind): at 500% zoom the viewport is a
43
+ fifth as wide and the rem five times larger, and the value must still reach twice its size at 100%, or text cannot be
44
+ resized to 200%. It is checked at every width (at the four kinks of the two curves), and a failure is a build error at
45
+ the call that names the width: `cssints: fluid: 1rem to 4rem between 20rem and 80rem fails WCAG 1.4.4: at 80rem wide,
46
+ 500% zoom gives 5rem, under twice 4rem; narrow the range of sizes or widen the widths`. A ratio of `max` to `min` up to
47
+ about 2.5 passes with the default widths.
48
+ - **A length.** The result is a Typed OM length (`CSSStyleValue<"length">`): it goes where a length goes, in the types,
49
+ and `color(fluid(...))` is an error. It can be an argument of `clamp()`, `min()` and `max()` of cssints.
50
+ - **Build errors** (at the call): a unit that is not px or rem, `min` equal to `max`, `from` not below `to`, a failed
51
+ 1.4.4 check, and the grammar of the arguments, by position (`fluid.container(2): unexpected "red" in "red", expected
52
+ <length>`).
53
+
54
+ ## Limits
55
+
56
+ - The 1.4.4 check runs on every call unless `{ zoom: false }` is passed, which is for lengths that are not text (a
57
+ padding, a gap): `padding(fluid("1rem", "4rem", { zoom: false }))`.
58
+ - `fluid.container()` uses the same check with the container's width in place of the viewport's, which holds when the
59
+ container scales with the viewport.
60
+ - No defaults from a token set, and no token as an argument: a token is a `var()`, which the build cannot compute with.
61
+
62
+ ```bash
63
+ cd packages/fluid && bun run test # fixtures through the engine (output, errors), and the type test via bun run typecheck
64
+ ```
65
+
66
+ ## Credits
67
+
68
+ The WCAG 1.4.4 check follows [fluid-tailwind](https://github.com/barvian/fluid-tailwind) (MIT, Maxwell Barvian).
69
+ The check is written here; no code is copied.
@@ -0,0 +1,40 @@
1
+ import { CSSStyleValue } from "cssints";
2
+ //#region src/index.d.ts
3
+ /** What `fluid()` gives: a length, for any property that takes one. */
4
+ export type Fluid = CSSStyleValue<"length">;
5
+ declare class Clamp extends CSSStyleValue<"length"> {
6
+ readonly text: string;
7
+ constructor(text: string);
8
+ toString(): string;
9
+ }
10
+ declare const fluidScope: import("cssints/plugin").Scope<"fluid", {
11
+ readonly fluid: {
12
+ args: readonly ["<length [0,∞]>", "<length [0,∞]>", {
13
+ readonly "from?": "<length [0,∞]>";
14
+ readonly "to?": "<length [0,∞]>";
15
+ readonly "zoom?": import("cssints/plugin").Typed<boolean>;
16
+ }];
17
+ label?: undefined;
18
+ value(args: never): Clamp;
19
+ };
20
+ readonly fluidContainer: {
21
+ args: readonly ["<length [0,∞]>", "<length [0,∞]>", {
22
+ readonly "from?": "<length [0,∞]>";
23
+ readonly "to?": "<length [0,∞]>";
24
+ readonly "zoom?": import("cssints/plugin").Typed<boolean>;
25
+ }];
26
+ label?: "fluid.container" | undefined;
27
+ value(args: never): Clamp;
28
+ };
29
+ }>;
30
+ type Members = ReturnType<typeof fluidScope.export>;
31
+ /**
32
+ * `fluid(min, max, { from?, to?, zoom? })`: a length that is `min` at the viewport width `from` (20rem), `max` at `to`
33
+ * (80rem), and grows linearly between, computed at build time into `clamp(min, <slope>vw + <intercept>rem, max)`. Lengths
34
+ * in px or rem. A range that fails WCAG 1.4.4 (500% zoom cannot reach twice the size) is a build error at the call, unless
35
+ * `zoom: false`. `fluid.container(...)` is the same against the width of the nearest container (`cqi`).
36
+ */
37
+ export declare const fluid: Members["fluid"] & {
38
+ container: Members["fluidContainer"];
39
+ };
40
+ //#endregion
package/dist/index.mjs ADDED
@@ -0,0 +1,71 @@
1
+ import { CSSStyleValue } from "cssints";
2
+ import { arg, fn, scope } from "cssints/plugin";
3
+ //#region src/index.ts
4
+ var Clamp = class extends CSSStyleValue {
5
+ text;
6
+ constructor(text) {
7
+ super();
8
+ this.text = text;
9
+ }
10
+ toString() {
11
+ return this.text;
12
+ }
13
+ };
14
+ const rem = (label, text) => {
15
+ const m = /^(\d*\.?\d+)(px|rem)$/.exec(text);
16
+ if (!m) throw new Error(`cssints: ${label}: ${text} is not in px or rem: the slope is computed at build time`);
17
+ return m[2] === "px" ? Number(m[1]) / 16 : Number(m[1]);
18
+ };
19
+ const num = (n) => String(Number(n.toFixed(4)) + 0);
20
+ const compute = (label, unit) => ([min, max, { from = "20rem", to = "80rem", zoom = true }]) => {
21
+ const [lo = 0, hi = 0, a = 0, b = 0] = [
22
+ min,
23
+ max,
24
+ from,
25
+ to
26
+ ].map((t) => rem(label, t));
27
+ if (lo === hi) throw new Error(`cssints: ${label}: ${min} and ${max} are the same size: use the length itself`);
28
+ if (a >= b) throw new Error(`cssints: ${label}: from ${from} must be below to ${to}`);
29
+ const slope = (hi - lo) / (b - a);
30
+ const intercept = lo - slope * a;
31
+ const [low, high] = lo < hi ? [min, max] : [max, min];
32
+ const at = (w) => Math.min(Math.max(intercept + slope * w, Math.min(lo, hi)), Math.max(lo, hi));
33
+ const fails = zoom ? [
34
+ a,
35
+ b,
36
+ 5 * a,
37
+ 5 * b
38
+ ].find((w) => 5 * at(w / 5) < 2 * at(w) - 1e-9) : void 0;
39
+ if (fails !== void 0) throw new Error(`cssints: ${label}: ${min} to ${max} between ${from} and ${to} fails WCAG 1.4.4: at ${num(fails)}rem wide, 500% zoom gives ${num(5 * at(fails / 5))}rem, under twice ${num(at(fails))}rem; narrow the range of sizes or widen the widths`);
40
+ const sign = intercept < 0 ? "-" : "+";
41
+ return new Clamp(`clamp(${low}, ${num(slope * 100)}${unit} ${sign} ${num(Math.abs(intercept))}rem, ${high})`);
42
+ };
43
+ const args = [
44
+ "<length [0,∞]>",
45
+ "<length [0,∞]>",
46
+ {
47
+ "from?": "<length [0,∞]>",
48
+ "to?": "<length [0,∞]>",
49
+ "zoom?": arg()
50
+ }
51
+ ];
52
+ const members = scope("fluid", {
53
+ fluid: fn({
54
+ args,
55
+ value: compute("fluid", "vw")
56
+ }),
57
+ fluidContainer: fn({
58
+ args,
59
+ label: "fluid.container",
60
+ value: compute("fluid.container", "cqi")
61
+ })
62
+ }).export();
63
+ /**
64
+ * `fluid(min, max, { from?, to?, zoom? })`: a length that is `min` at the viewport width `from` (20rem), `max` at `to`
65
+ * (80rem), and grows linearly between, computed at build time into `clamp(min, <slope>vw + <intercept>rem, max)`. Lengths
66
+ * in px or rem. A range that fails WCAG 1.4.4 (500% zoom cannot reach twice the size) is a build error at the call, unless
67
+ * `zoom: false`. `fluid.container(...)` is the same against the width of the nearest container (`cqi`).
68
+ */
69
+ const fluid = Object.assign(members.fluid, { container: members.fluidContainer });
70
+ //#endregion
71
+ export { fluid };
package/package.json CHANGED
@@ -1,6 +1,32 @@
1
1
  {
2
2
  "name": "@cssints/fluid",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.2.0",
4
+ "description": "fluid() for cssints: clamp() between two widths, computed at build time, with the WCAG 1.4.4 zoom check",
5
+ "license": "MIT",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/alexeiaccio/css-in-ts-compiler.git",
9
+ "directory": "packages/fluid"
10
+ },
11
+ "homepage": "https://cssints.dev",
12
+ "files": [
13
+ "dist"
14
+ ],
15
+ "type": "module",
16
+ "sideEffects": false,
17
+ "exports": {
18
+ ".": {
19
+ "types": "./dist/index.d.mts",
20
+ "default": "./dist/index.mjs"
21
+ }
22
+ },
23
+ "peerDependencies": {
24
+ "cssints": "^0.2.0"
25
+ },
26
+ "engines": {
27
+ "node": ">=22"
28
+ },
29
+ "publishConfig": {
30
+ "access": "public"
31
+ }
32
+ }