@gears-frontx/ui-kit 0.4.9 → 0.5.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/dist/chunks/{filters.DcFdZpNG.css → filters.DQtlBXh7.css} +1 -1
- package/dist/chunks/grid.BvRXPN-7.css +1 -0
- package/dist/chunks/switch.BYqd9jlJ.css +1 -0
- package/dist/components/data-grid/components/filter-chip.d.ts +3 -2
- package/dist/components/data-grid/components/filter-chip.d.ts.map +1 -1
- package/dist/components/grid/grid-config.d.ts +29 -0
- package/dist/components/grid/grid-config.d.ts.map +1 -0
- package/dist/components/grid/grid-default-config.json.d.ts +19 -0
- package/dist/components/grid/grid-solver.d.ts +30 -0
- package/dist/components/grid/grid-solver.d.ts.map +1 -0
- package/dist/components/grid/grid.d.ts +24 -0
- package/dist/components/grid/grid.d.ts.map +1 -0
- package/dist/components/grid/public.d.ts +5 -0
- package/dist/components/grid/public.d.ts.map +1 -0
- package/dist/data-grid/filters.js +1 -1
- package/dist/data-grid/filters.js.map +1 -1
- package/dist/docs/grid.md +127 -0
- package/dist/frontx-ui-grid-css.mjs +82 -0
- package/dist/grid-config-check.mjs +78 -0
- package/dist/grid-css.mjs +32 -0
- package/dist/grid-default-config.json +16 -0
- package/dist/grid.d.ts +1 -0
- package/dist/grid.js +227 -0
- package/dist/grid.js.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +264 -260
- package/dist/index.js.map +1 -1
- package/dist/switch.js +10 -10
- package/llms.txt +9 -0
- package/package.json +6 -3
- package/dist/chunks/switch.D3_ZyuVP.css +0 -1
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
# Grid
|
|
2
|
+
|
|
3
|
+
## When to use
|
|
4
|
+
|
|
5
|
+
Use `Grid` for an ordered group of blocks whose widths follow size classes. Use one `Grid` per group. Each `GridItem` declares a unique `layoutId`, a size class, and an optional height class. The solver keeps DOM, focus, and segment order equal to input order.
|
|
6
|
+
|
|
7
|
+
## When not to use
|
|
8
|
+
|
|
9
|
+
Use a plain CSS grid when callers already know exact spans or need manual placement. Grid does not render dashboard data or support drag and resize editing.
|
|
10
|
+
|
|
11
|
+
## Props
|
|
12
|
+
|
|
13
|
+
| Component | Prop | Meaning |
|
|
14
|
+
| --- | --- | --- |
|
|
15
|
+
| Grid | `config` | `GridConfig` shared with the generated step CSS. Defaults to `defaultGridConfig`. |
|
|
16
|
+
| Grid | `flexible` | `false` (default): every item takes its size class's preferred span. `true`: spans may move inside each class's range to fill rows. |
|
|
17
|
+
| Grid | `className`, div props | Applied to the named container wrapper. |
|
|
18
|
+
| GridItem | `layoutId` | Required placement identity, unique within this Grid. Separate from HTML `id`. |
|
|
19
|
+
| GridItem | `size` | `small`, `medium`, or `large`. |
|
|
20
|
+
| GridItem | `height` | `low` (default, one row track) or `high` (two row tracks). |
|
|
21
|
+
| GridItem | `className`, div props | Applied to the item. Caller style is preserved; placement variables win on conflict. |
|
|
22
|
+
|
|
23
|
+
`Grid` accepts direct `GridItem` elements, arrays, and empty conditional entries (`null`, `undefined`, booleans). Fragments, wrappers, portals, and text throw. Keep a stable `layoutId` when content changes: a `key` on a GridItem is ignored, because Grid keys items by `layoutId`, and changing `layoutId` is what remounts an item. The solver is pure and runs during rendering, so the server and client get the same layout.
|
|
24
|
+
|
|
25
|
+
## Names
|
|
26
|
+
|
|
27
|
+
The step CSS is a global stylesheet matched by attribute, so its selectors and the container keep the `fx-` prefix: `data-fx-grid`, `data-fx-grid-item`, `data-fx-grid-flexible`, and the `fx-grid` container name. An unprefixed `data-grid` is already in use by other libraries (react-grid-layout puts `data-grid` on its children), and a global rule that matched it would style foreign markup. The custom properties need no prefix: Grid sets `--_grid-columns` and the per-step `--_grid-col-<step>` / `--_grid-row-<step>` only on its own elements. `--grid-gap` and `--grid-row-height` are consumer hooks that Grid only reads, and they inherit like any custom property, so a value declared on any ancestor, `:root` included, applies to every Grid below it.
|
|
28
|
+
|
|
29
|
+
## Layout and styling
|
|
30
|
+
|
|
31
|
+
The default config has 12 columns and four container steps: base 0px, sm 480px, md 768px, lg 1200px. Each size class has a preferred span per step, and with the default config every span is 12, 6 or 3 columns:
|
|
32
|
+
|
|
33
|
+
| Size | base | sm | md | lg |
|
|
34
|
+
| --- | --- | --- | --- | --- |
|
|
35
|
+
| `small` | 6 | 6 | 3 | 3 |
|
|
36
|
+
| `medium` | 12 | 6 | 6 | 6 |
|
|
37
|
+
| `large` | 12 | 12 | 12 | 12 |
|
|
38
|
+
|
|
39
|
+
By default a Grid places exactly these spans; a row they do not fill keeps its hole at the inline end, so `medium` + `small` at lg is 6 + 3 with three empty columns. A `flexible` Grid lets each span move inside its class's range in `defaultGridConfig` (at lg `small` 2..4, `medium` 4..8, `large` 7..12) to fill rows, so the same pair becomes 8 + 4. Flexible is set per Grid, that is per group. In both modes the solver minimizes internal holes, final holes, width deviation, and band count in that order, never reorders items, and leaves empty columns at the inline end.
|
|
40
|
+
|
|
41
|
+
### Row tracks and heights
|
|
42
|
+
|
|
43
|
+
Heights are fixed by the model. Row tracks have the size of the config's `rowHeight`, a positive length in px, rem or em (`10rem` in the default config): a `low` item is one track, a `high` item is two tracks and the row gap between them, so a high item is exactly as tall as two stacked lows with their gap. A two-track band holds high items and pairs of adjacent lows stacked in one column beside them; a low never stretches over two tracks, and a low that finds no partner beside a high goes to the next band. With the default config a high `medium` takes two smalls stacked beside it from sm on, and four smalls as two stacks at md and lg (`6 + 3 + 3`). An item is a one-column grid, so a single child (a Card) fills it.
|
|
44
|
+
|
|
45
|
+
### Scrolling and clipping
|
|
46
|
+
|
|
47
|
+
Content taller than its item scrolls inside the item and never overlaps a neighbour. The item is a scroll container, so it also clips what a child draws outside its own box (an outer shadow or outline). The default kit Card draws neither and its focus ring is inset; the `panel` Card's outer shadow and the forced-colors focus outline of an interactive Card are clipped at the item edge.
|
|
48
|
+
|
|
49
|
+
### Track override
|
|
50
|
+
|
|
51
|
+
The track size and the spans of the default config are not final; the config is the single place to change them (`rowHeight` for the track), and `--grid-row-height` overrides the track at runtime.
|
|
52
|
+
|
|
53
|
+
### Direction
|
|
54
|
+
|
|
55
|
+
Direction follows CSS grid lines, so `dir="rtl"` mirrors the layout without changing DOM order.
|
|
56
|
+
|
|
57
|
+
The wrapper is the named inline-size container. Size containment gives it no width of its own content, so it needs a width from outside: a block in normal flow or a stretched flex or grid child gets one; inside a shrink-to-fit box (an inline-block, a float, a `max-content` track, a flex item that does not grow) give the Grid a width. The grid element carries `data-fx-grid="<config.name>"`; each item carries `data-fx-grid-item`; a flexible Grid's grid element also carries `data-fx-grid-flexible`. The default generated CSS ships with the component, and nested Grids query their nearest `fx-grid` wrapper. Print uses block flow and a token gap.
|
|
58
|
+
|
|
59
|
+
## Config
|
|
60
|
+
|
|
61
|
+
A custom config starts from a copy of the shipped default config, `@gears-frontx/ui-kit/grid-default-config.json` in the install (`node_modules/@gears-frontx/ui-kit/dist/grid-default-config.json`), written as JSON:
|
|
62
|
+
|
|
63
|
+
```json
|
|
64
|
+
{
|
|
65
|
+
"name": "report",
|
|
66
|
+
"columns": 8,
|
|
67
|
+
"rowHeight": "120px",
|
|
68
|
+
"steps": [
|
|
69
|
+
{ "name": "base", "minWidth": 0, "gap": "--space-4" },
|
|
70
|
+
{ "name": "wide", "minWidth": 960, "gap": "--space-6" }
|
|
71
|
+
],
|
|
72
|
+
"sizes": {
|
|
73
|
+
"small": { "base": { "min": 2, "preferred": 2, "max": 4 }, "wide": { "min": 1, "preferred": 2, "max": 2 } },
|
|
74
|
+
"medium": { "base": { "min": 4, "preferred": 4, "max": 8 }, "wide": { "min": 2, "preferred": 4, "max": 4 } },
|
|
75
|
+
"large": { "base": { "min": 8, "preferred": 8, "max": 8 }, "wide": { "min": 4, "preferred": 8, "max": 8 } }
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
The example is valid JSON and passes the config validator unchanged:
|
|
81
|
+
|
|
82
|
+
- `name` is a lowercase CSS-safe name and not `default`, which is the kit's own scope and Grid refuses for any other config object.
|
|
83
|
+
- `columns` is an integer from 1 to 48.
|
|
84
|
+
- `rowHeight` is a positive length in px, rem or em.
|
|
85
|
+
- `steps[]` carries `name`, `minWidth` in px with the first step at 0 and the widths strictly increasing, and `gap`, a spacing token name such as `--space-4`.
|
|
86
|
+
- `sizes.<small|medium|large>.<step>` carries the span range with `1 <= min <= preferred <= max <= columns`.
|
|
87
|
+
|
|
88
|
+
Generate the step CSS and import it once beside the kit's own:
|
|
89
|
+
|
|
90
|
+
```sh
|
|
91
|
+
frontx-ui-grid-css ./grid-config.json ./grid-steps.css
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
The command also reads a `.mjs` or `.js` module with a default export. A `.js` config is loaded with `import()`, so Node decides its module type from the nearest `package.json` `"type"` field, or by syntax detection when there is none; a CommonJS `module.exports` object is accepted as the default export. Use `.mjs` or `.json` when unsure. The output path must not be the config file, under any name.
|
|
95
|
+
|
|
96
|
+
Pass that same config object to `Grid`. CSS selectors are scoped by config name, so two configs can coexist, and a custom stylesheet is needed for each custom config. The generated CSS and the passed config must use the same name and steps. The CSS has no viewport queries and resizing does not run JavaScript. For Shadow DOM, include the kit component CSS and generated CSS inside the shadow root.
|
|
97
|
+
|
|
98
|
+
`--grid-gap` overrides the configured spacing token at every step, and `--grid-row-height` the configured row track. `--_grid-columns` and the per-step `--_grid-col-<step>` / `--_grid-row-<step>` are set by Grid.
|
|
99
|
+
|
|
100
|
+
## Accessibility
|
|
101
|
+
|
|
102
|
+
Grid adds no role or focus behavior. Put meaningful content inside each item. DOM and focus order remain the input order. A paired stack reads as the first low followed by the second low. An item whose content overflows is a scroll container and becomes a tab stop in browsers with focusable scrollers, so content that must stay reachable everywhere should fit or carry its own focusable control.
|
|
103
|
+
|
|
104
|
+
## Anti-patterns
|
|
105
|
+
|
|
106
|
+
- A fragment or wrapper between Grid and GridItem: Grid throws instead of dropping items.
|
|
107
|
+
- A reused `layoutId` in one Grid: Grid throws (`Duplicate Grid layoutId: <layoutId>`).
|
|
108
|
+
- A custom config without its generated CSS loaded: nothing reads the placement variables, and the browser auto-places the items.
|
|
109
|
+
|
|
110
|
+
## Examples
|
|
111
|
+
|
|
112
|
+
```tsx
|
|
113
|
+
<Grid>
|
|
114
|
+
<GridItem layoutId="summary" size="medium" height="high">Summary</GridItem>
|
|
115
|
+
<GridItem layoutId="trend" size="small">Trend</GridItem>
|
|
116
|
+
<GridItem layoutId="alerts" size="small">Alerts</GridItem>
|
|
117
|
+
</Grid>
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
With a custom config and the stylesheet generated for it imported once:
|
|
121
|
+
|
|
122
|
+
```tsx
|
|
123
|
+
<Grid config={reportConfig}>
|
|
124
|
+
<GridItem layoutId="table" size="large">Table</GridItem>
|
|
125
|
+
<GridItem layoutId="notes" size="small">Notes</GridItem>
|
|
126
|
+
</Grid>
|
|
127
|
+
```
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/*
|
|
3
|
+
* frontx-ui-grid-css: writes the Grid step rules for a config.
|
|
4
|
+
*
|
|
5
|
+
* frontx-ui-grid-css [--kit-default] <config.json|config.mjs|config.js> <output.css>
|
|
6
|
+
*
|
|
7
|
+
* `@container` conditions cannot read `var()`, so every container step width
|
|
8
|
+
* has to be a literal in CSS; this command turns a GridConfig into those
|
|
9
|
+
* rules. The kit's grid-steps.css is this command's output for the default
|
|
10
|
+
* config, regenerated by `npm run grid:css -w @gears-frontx/ui-kit` and kept
|
|
11
|
+
* equal by a test. Rules are scoped by the config name through `data-fx-grid`,
|
|
12
|
+
* never by a CSS Module class, so a custom config's CSS coexists with the
|
|
13
|
+
* default.
|
|
14
|
+
*
|
|
15
|
+
* `default` is the kit's own scope: the command refuses a config under that
|
|
16
|
+
* name unless --kit-default is given. The flag is public on the installed bin
|
|
17
|
+
* and is meant for regenerating the kit's own stylesheet, which the kit's
|
|
18
|
+
* `grid:css` script and the consumer acceptance do; it guards against a
|
|
19
|
+
* custom config accidentally shadowing the shipped rules, not against doing
|
|
20
|
+
* so on purpose.
|
|
21
|
+
*
|
|
22
|
+
* The generator and the config checks it runs live in the component
|
|
23
|
+
* directory. The build copies grid-css.mjs and grid-config-check.mjs flat
|
|
24
|
+
* into dist/ beside the bin and rewrites the one import specifier below to
|
|
25
|
+
* './grid-css.mjs', a rewrite buildPlugin.ts guards by refusing to copy when
|
|
26
|
+
* this specifier text moves, so the specifier stays as written unless the
|
|
27
|
+
* copy step changes with it. The command stays in scripts/ because it alone
|
|
28
|
+
* needs the Node builtins the component source may not import.
|
|
29
|
+
*/
|
|
30
|
+
import { readFile, stat, writeFile } from 'node:fs/promises';
|
|
31
|
+
import { extname, resolve } from 'node:path';
|
|
32
|
+
import { pathToFileURL } from 'node:url';
|
|
33
|
+
|
|
34
|
+
import { generateGridCss } from './grid-css.mjs';
|
|
35
|
+
|
|
36
|
+
const USAGE = 'Usage: frontx-ui-grid-css [--kit-default] <config.json|config.mjs|config.js> <output.css>';
|
|
37
|
+
|
|
38
|
+
async function main() {
|
|
39
|
+
const args = process.argv.slice(2);
|
|
40
|
+
const kitDefault = args.includes('--kit-default');
|
|
41
|
+
const positionals = args.filter(argument => argument !== '--kit-default');
|
|
42
|
+
// An explicit help request succeeds: the usage text on stdout, exit 0.
|
|
43
|
+
if (args.includes('--help') || args.includes('-h')) {
|
|
44
|
+
console.log(USAGE);
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
// One option and two positionals: any other --word is a mistyped invocation,
|
|
48
|
+
// and any other arity has no reading, so both stop here instead of surfacing
|
|
49
|
+
// later as a missing or misread file. Apart from -h, a single dash stays a
|
|
50
|
+
// path character; a path that starts with -- is passed as ./--name.
|
|
51
|
+
if (args.some(argument => argument.startsWith('--') && argument !== '--kit-default') || positionals.length !== 2) {
|
|
52
|
+
throw new Error(USAGE);
|
|
53
|
+
}
|
|
54
|
+
const [input, output] = positionals;
|
|
55
|
+
const path = resolve(input);
|
|
56
|
+
// The output is written as CSS: the same file would replace the config.
|
|
57
|
+
// Checked before anything is read or written: by path, and for an existing
|
|
58
|
+
// output by filesystem identity (dev + ino), which catches a symlink, a hard
|
|
59
|
+
// link or a case alias. A missing output cannot be the config.
|
|
60
|
+
const sameFileError = new Error(`Output path ${output} is the config file; give the CSS its own path`);
|
|
61
|
+
if (path === resolve(output)) throw sameFileError;
|
|
62
|
+
const [configStat, outputStat] = await Promise.all([stat(path).catch(() => null), stat(resolve(output)).catch(() => null)]);
|
|
63
|
+
if (configStat && outputStat && configStat.dev === outputStat.dev && configStat.ino === outputStat.ino) throw sameFileError;
|
|
64
|
+
const extension = extname(path);
|
|
65
|
+
if (extension !== '.json' && extension !== '.mjs' && extension !== '.js') {
|
|
66
|
+
throw new Error('Grid config must be a .json file or an ES module (.mjs, .js) with a default export');
|
|
67
|
+
}
|
|
68
|
+
let config;
|
|
69
|
+
if (extension === '.json') {
|
|
70
|
+
config = JSON.parse(await readFile(path, 'utf8'));
|
|
71
|
+
} else {
|
|
72
|
+
const module = await import(pathToFileURL(path).href);
|
|
73
|
+
if (!('default' in module)) throw new Error(`Grid config module ${input} has no default export`);
|
|
74
|
+
config = module.default;
|
|
75
|
+
}
|
|
76
|
+
await writeFile(resolve(output), generateGridCss(config, { allowDefaultName: kitDefault }));
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
main().catch(error => {
|
|
80
|
+
console.error(error instanceof Error ? error.message : String(error));
|
|
81
|
+
process.exitCode = 1;
|
|
82
|
+
});
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* The one Grid config validator: grid-config.ts and the generator
|
|
3
|
+
* (grid-css.mjs, behind the frontx-ui-grid-css command) both import it, so a
|
|
4
|
+
* config object and the stylesheet generated from it cannot disagree. The
|
|
5
|
+
* build copies this module flat into dist/ next to the command. Plain
|
|
6
|
+
* dependency-free ESM, so the command runs in plain Node without loading any
|
|
7
|
+
* component code (the built entries import CSS).
|
|
8
|
+
*
|
|
9
|
+
* Types: grid-config-check.d.mts.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
export const SIZE_CLASSES = ['small', 'medium', 'large'];
|
|
13
|
+
// Bounds the solver's width loops, which run per column.
|
|
14
|
+
const MAX_COLUMNS = 48;
|
|
15
|
+
const NAME_PATTERN = /^[a-z][a-z0-9-]*$/;
|
|
16
|
+
const TOKEN_PATTERN = /^--[a-z][a-z0-9-]*$/;
|
|
17
|
+
const LENGTH_PATTERN = /^(?:\d+(?:\.\d+)?|\.\d+)(?:px|rem|em)$/;
|
|
18
|
+
|
|
19
|
+
function validRange(range, columns) {
|
|
20
|
+
return (
|
|
21
|
+
!!range &&
|
|
22
|
+
Number.isSafeInteger(range.min) &&
|
|
23
|
+
Number.isSafeInteger(range.preferred) &&
|
|
24
|
+
Number.isSafeInteger(range.max) &&
|
|
25
|
+
range.min >= 1 &&
|
|
26
|
+
range.min <= range.preferred &&
|
|
27
|
+
range.preferred <= range.max &&
|
|
28
|
+
range.max <= columns
|
|
29
|
+
);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Throws with a plain message when a config cannot drive the solver or the
|
|
34
|
+
* generated CSS. `allowDefaultName` admits the reserved `default` scope, which
|
|
35
|
+
* belongs to the kit's own defaultGridConfig and its shipped stylesheet; every
|
|
36
|
+
* other caller refuses it.
|
|
37
|
+
*/
|
|
38
|
+
export function validateGridConfig(config, { allowDefaultName = false } = {}) {
|
|
39
|
+
if (!config || typeof config !== 'object') throw new Error('Grid config must be an object');
|
|
40
|
+
if (typeof config.name !== 'string' || !NAME_PATTERN.test(config.name)) {
|
|
41
|
+
throw new Error('Grid config name must be a lowercase CSS-safe name');
|
|
42
|
+
}
|
|
43
|
+
if (!allowDefaultName && config.name === 'default') {
|
|
44
|
+
throw new Error('Grid config name "default" belongs to defaultGridConfig; give a custom config its own name');
|
|
45
|
+
}
|
|
46
|
+
if (!Number.isSafeInteger(config.columns) || config.columns < 1 || config.columns > MAX_COLUMNS) {
|
|
47
|
+
throw new Error(`Grid columns must be an integer from 1 to ${MAX_COLUMNS}`);
|
|
48
|
+
}
|
|
49
|
+
if (typeof config.rowHeight !== 'string' || !LENGTH_PATTERN.test(config.rowHeight) || parseFloat(config.rowHeight) <= 0) {
|
|
50
|
+
throw new Error('Grid rowHeight must be a positive CSS length in px, rem or em');
|
|
51
|
+
}
|
|
52
|
+
if (!Array.isArray(config.steps) || config.steps.length === 0) throw new Error('Grid steps must be nonempty');
|
|
53
|
+
const names = new Set();
|
|
54
|
+
let previousWidth = -1;
|
|
55
|
+
for (const step of config.steps) {
|
|
56
|
+
if (!step || typeof step.name !== 'string' || !NAME_PATTERN.test(step.name) || names.has(step.name)) {
|
|
57
|
+
throw new Error('Grid step names must be unique lowercase CSS-safe names');
|
|
58
|
+
}
|
|
59
|
+
if (!Number.isFinite(step.minWidth) || step.minWidth < 0 || step.minWidth <= previousWidth) {
|
|
60
|
+
throw new Error('Grid step widths must be finite, nonnegative, and strictly increasing');
|
|
61
|
+
}
|
|
62
|
+
if (typeof step.gap !== 'string' || !TOKEN_PATTERN.test(step.gap)) {
|
|
63
|
+
throw new Error(`Grid step ${step.name} gap must be a CSS token reference`);
|
|
64
|
+
}
|
|
65
|
+
names.add(step.name);
|
|
66
|
+
previousWidth = step.minWidth;
|
|
67
|
+
}
|
|
68
|
+
if (config.steps[0].minWidth !== 0) throw new Error('Grid first step must start at 0');
|
|
69
|
+
for (const size of SIZE_CLASSES) {
|
|
70
|
+
const steps = config.sizes?.[size];
|
|
71
|
+
if (!steps || typeof steps !== 'object') throw new Error(`Grid size ${size} is missing`);
|
|
72
|
+
for (const name of names) {
|
|
73
|
+
if (!validRange(steps[name], config.columns)) {
|
|
74
|
+
throw new Error(`Grid size ${size} step ${name} needs 1 <= min <= preferred <= max <= columns`);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* The Grid step-rule generator: turns a GridConfig into the stylesheet the
|
|
3
|
+
* component imports. The frontx-ui-grid-css command is a thin executable over
|
|
4
|
+
* this module, and the tests read generateGridCss from it in process, so the
|
|
5
|
+
* module carries no CLI of its own - a file a test imports cannot carry the
|
|
6
|
+
* executable's shebang.
|
|
7
|
+
*
|
|
8
|
+
* The config checks are grid-config-check.mjs, imported by this relative path
|
|
9
|
+
* both from this directory in the repository and from dist/, where the build
|
|
10
|
+
* copies it beside the command and this module.
|
|
11
|
+
*/
|
|
12
|
+
import { validateGridConfig } from './grid-config-check.mjs';
|
|
13
|
+
|
|
14
|
+
export function generateGridCss(config, { allowDefaultName = false } = {}) {
|
|
15
|
+
validateGridConfig(config, { allowDefaultName });
|
|
16
|
+
const grid = `:where([data-fx-grid="${config.name}"])`;
|
|
17
|
+
const item = `${grid} > :where([data-fx-grid-item])`;
|
|
18
|
+
const rules = config.steps.map(step => {
|
|
19
|
+
// Columns and the fixed row track are set once, in the base rule; only the gap changes per step.
|
|
20
|
+
const columns =
|
|
21
|
+
step.minWidth === 0
|
|
22
|
+
? ` grid-template-columns: repeat(var(--_grid-columns, ${config.columns}), minmax(0, 1fr)); grid-auto-rows: var(--grid-row-height, ${config.rowHeight});`
|
|
23
|
+
: '';
|
|
24
|
+
const lines = [
|
|
25
|
+
`${item} { grid-column: var(--_grid-col-${step.name}, auto); grid-row: var(--_grid-row-${step.name}, auto); }`,
|
|
26
|
+
`${grid} {${columns} gap: var(--grid-gap, var(${step.gap})); }`,
|
|
27
|
+
];
|
|
28
|
+
if (step.minWidth === 0) return lines.join('\n');
|
|
29
|
+
return `@container fx-grid (min-width: ${step.minWidth}px) {\n${lines.map(line => ` ${line}`).join('\n')}\n}`;
|
|
30
|
+
});
|
|
31
|
+
return `/* Generated by frontx-ui-grid-css, format 1. Regenerate with frontx-ui-grid-css after a breaking ui-kit release. */\n${rules.join('\n\n')}\n`;
|
|
32
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "default",
|
|
3
|
+
"columns": 12,
|
|
4
|
+
"rowHeight": "10rem",
|
|
5
|
+
"steps": [
|
|
6
|
+
{ "name": "base", "minWidth": 0, "gap": "--space-4" },
|
|
7
|
+
{ "name": "sm", "minWidth": 480, "gap": "--space-4" },
|
|
8
|
+
{ "name": "md", "minWidth": 768, "gap": "--space-6" },
|
|
9
|
+
{ "name": "lg", "minWidth": 1200, "gap": "--space-6" }
|
|
10
|
+
],
|
|
11
|
+
"sizes": {
|
|
12
|
+
"small": { "base": { "min": 6, "preferred": 6, "max": 6 }, "sm": { "min": 4, "preferred": 6, "max": 6 }, "md": { "min": 3, "preferred": 3, "max": 4 }, "lg": { "min": 2, "preferred": 3, "max": 4 } },
|
|
13
|
+
"medium": { "base": { "min": 12, "preferred": 12, "max": 12 }, "sm": { "min": 6, "preferred": 6, "max": 12 }, "md": { "min": 4, "preferred": 6, "max": 8 }, "lg": { "min": 4, "preferred": 6, "max": 8 } },
|
|
14
|
+
"large": { "base": { "min": 12, "preferred": 12, "max": 12 }, "sm": { "min": 12, "preferred": 12, "max": 12 }, "md": { "min": 8, "preferred": 12, "max": 12 }, "lg": { "min": 7, "preferred": 12, "max": 12 } }
|
|
15
|
+
}
|
|
16
|
+
}
|
package/dist/grid.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './components/grid/public.js'
|
package/dist/grid.js
ADDED
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
import { jsx as _ } from "react/jsx-runtime";
|
|
2
|
+
import { cx as j } from "class-variance-authority";
|
|
3
|
+
import { cloneElement as L, isValidElement as D } from "react";
|
|
4
|
+
import './chunks/grid.BvRXPN-7.css';const F = "default", K = 12, U = "10rem", q = [{ name: "base", minWidth: 0, gap: "--space-4" }, { name: "sm", minWidth: 480, gap: "--space-4" }, { name: "md", minWidth: 768, gap: "--space-6" }, { name: "lg", minWidth: 1200, gap: "--space-6" }], V = { small: { base: { min: 6, preferred: 6, max: 6 }, sm: { min: 4, preferred: 6, max: 6 }, md: { min: 3, preferred: 3, max: 4 }, lg: { min: 2, preferred: 3, max: 4 } }, medium: { base: { min: 12, preferred: 12, max: 12 }, sm: { min: 6, preferred: 6, max: 12 }, md: { min: 4, preferred: 6, max: 8 }, lg: { min: 4, preferred: 6, max: 8 } }, large: { base: { min: 12, preferred: 12, max: 12 }, sm: { min: 12, preferred: 12, max: 12 }, md: { min: 8, preferred: 12, max: 12 }, lg: { min: 7, preferred: 12, max: 12 } } }, X = {
|
|
5
|
+
name: F,
|
|
6
|
+
columns: K,
|
|
7
|
+
rowHeight: U,
|
|
8
|
+
steps: q,
|
|
9
|
+
sizes: V
|
|
10
|
+
}, P = ["small", "medium", "large"], H = 48, M = /^[a-z][a-z0-9-]*$/, Z = /^--[a-z][a-z0-9-]*$/, B = /^(?:\d+(?:\.\d+)?|\.\d+)(?:px|rem|em)$/;
|
|
11
|
+
function J(e, t) {
|
|
12
|
+
return !!e && Number.isSafeInteger(e.min) && Number.isSafeInteger(e.preferred) && Number.isSafeInteger(e.max) && e.min >= 1 && e.min <= e.preferred && e.preferred <= e.max && e.max <= t;
|
|
13
|
+
}
|
|
14
|
+
function Q(e, { allowDefaultName: t = !1 } = {}) {
|
|
15
|
+
var o;
|
|
16
|
+
if (!e || typeof e != "object") throw new Error("Grid config must be an object");
|
|
17
|
+
if (typeof e.name != "string" || !M.test(e.name))
|
|
18
|
+
throw new Error("Grid config name must be a lowercase CSS-safe name");
|
|
19
|
+
if (!t && e.name === "default")
|
|
20
|
+
throw new Error('Grid config name "default" belongs to defaultGridConfig; give a custom config its own name');
|
|
21
|
+
if (!Number.isSafeInteger(e.columns) || e.columns < 1 || e.columns > H)
|
|
22
|
+
throw new Error(`Grid columns must be an integer from 1 to ${H}`);
|
|
23
|
+
if (typeof e.rowHeight != "string" || !B.test(e.rowHeight) || parseFloat(e.rowHeight) <= 0)
|
|
24
|
+
throw new Error("Grid rowHeight must be a positive CSS length in px, rem or em");
|
|
25
|
+
if (!Array.isArray(e.steps) || e.steps.length === 0) throw new Error("Grid steps must be nonempty");
|
|
26
|
+
const r = /* @__PURE__ */ new Set();
|
|
27
|
+
let s = -1;
|
|
28
|
+
for (const n of e.steps) {
|
|
29
|
+
if (!n || typeof n.name != "string" || !M.test(n.name) || r.has(n.name))
|
|
30
|
+
throw new Error("Grid step names must be unique lowercase CSS-safe names");
|
|
31
|
+
if (!Number.isFinite(n.minWidth) || n.minWidth < 0 || n.minWidth <= s)
|
|
32
|
+
throw new Error("Grid step widths must be finite, nonnegative, and strictly increasing");
|
|
33
|
+
if (typeof n.gap != "string" || !Z.test(n.gap))
|
|
34
|
+
throw new Error(`Grid step ${n.name} gap must be a CSS token reference`);
|
|
35
|
+
r.add(n.name), s = n.minWidth;
|
|
36
|
+
}
|
|
37
|
+
if (e.steps[0].minWidth !== 0) throw new Error("Grid first step must start at 0");
|
|
38
|
+
for (const n of P) {
|
|
39
|
+
const c = (o = e.sizes) == null ? void 0 : o[n];
|
|
40
|
+
if (!c || typeof c != "object") throw new Error(`Grid size ${n} is missing`);
|
|
41
|
+
for (const S of r)
|
|
42
|
+
if (!J(c[S], e.columns))
|
|
43
|
+
throw new Error(`Grid size ${n} step ${S} needs 1 <= min <= preferred <= max <= columns`);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
function O(e) {
|
|
47
|
+
if (e && typeof e == "object") {
|
|
48
|
+
for (const t of Object.values(e)) O(t);
|
|
49
|
+
Object.freeze(e);
|
|
50
|
+
}
|
|
51
|
+
return e;
|
|
52
|
+
}
|
|
53
|
+
const G = O(structuredClone(X));
|
|
54
|
+
function Y(e) {
|
|
55
|
+
Q(e, { allowDefaultName: !0 });
|
|
56
|
+
}
|
|
57
|
+
const ee = { P: "0", T: "1", L: "2" };
|
|
58
|
+
function z(e, t) {
|
|
59
|
+
return e < t ? -1 : e > t ? 1 : 0;
|
|
60
|
+
}
|
|
61
|
+
function te(e, t) {
|
|
62
|
+
for (let r = 0; r < e.length; r++) if (e[r] !== t[r]) return e[r] - t[r];
|
|
63
|
+
return 0;
|
|
64
|
+
}
|
|
65
|
+
function re(e, t) {
|
|
66
|
+
return e.deviation - t.deviation || z(e.key, t.key);
|
|
67
|
+
}
|
|
68
|
+
function ne(e, t) {
|
|
69
|
+
return te(e.cost, t.cost) || z(e.ends, t.ends) || z(e.kinds, t.kinds);
|
|
70
|
+
}
|
|
71
|
+
function oe(e) {
|
|
72
|
+
if (!Array.isArray(e)) throw new Error("Grid items must be an array");
|
|
73
|
+
const t = /* @__PURE__ */ new Set();
|
|
74
|
+
for (const r of e) {
|
|
75
|
+
if (!r || typeof r.layoutId != "string" || r.layoutId.length === 0)
|
|
76
|
+
throw new Error("Grid item layoutId must be a nonempty string");
|
|
77
|
+
if (t.has(r.layoutId)) throw new Error(`Duplicate Grid layoutId: ${r.layoutId}`);
|
|
78
|
+
if (!P.includes(r.size))
|
|
79
|
+
throw new Error(`Unknown Grid size: ${String(r.size)}`);
|
|
80
|
+
if (r.height !== void 0 && r.height !== "low" && r.height !== "high")
|
|
81
|
+
throw new Error(`Unknown Grid height: ${String(r.height)}`);
|
|
82
|
+
t.add(r.layoutId);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
function se(e, t, r, s) {
|
|
86
|
+
const o = e.sizes[t][r];
|
|
87
|
+
return s ? o : { min: o.preferred, preferred: o.preferred, max: o.preferred };
|
|
88
|
+
}
|
|
89
|
+
function ie(e, t, r, s) {
|
|
90
|
+
const o = e.length, n = /* @__PURE__ */ Object.create(null);
|
|
91
|
+
if (o === 0) return { placements: n, rows: 0, holes: 0 };
|
|
92
|
+
const c = t.columns, S = e.map((i) => se(t, i.size, r, s)), p = e.map((i) => i.height === "high"), b = String(o).length, E = String(c).length, w = new Array(o + 1);
|
|
93
|
+
w[o] = { cost: [0, 0, 0, 0], ends: "", kinds: "" };
|
|
94
|
+
for (let i = o - 1; i >= 0; i--) {
|
|
95
|
+
let g;
|
|
96
|
+
const v = (d, l, u) => {
|
|
97
|
+
if (d.width === 0 || l === 2 && !d.sawHigh) return;
|
|
98
|
+
const a = l * (c - d.width), f = w[u], x = {
|
|
99
|
+
cost: [
|
|
100
|
+
(u < o ? a : 0) + f.cost[0],
|
|
101
|
+
(u === o ? a : 0) + f.cost[1],
|
|
102
|
+
d.deviation + f.cost[2],
|
|
103
|
+
1 + f.cost[3]
|
|
104
|
+
],
|
|
105
|
+
ends: `${String(u).padStart(b, "0")},${f.ends}`,
|
|
106
|
+
kinds: `${d.key}/${f.kinds}`,
|
|
107
|
+
band: { height: l, segments: d.segments },
|
|
108
|
+
next: f
|
|
109
|
+
};
|
|
110
|
+
(!g || ne(x, g) < 0) && (g = x);
|
|
111
|
+
};
|
|
112
|
+
for (const d of [1, 2]) {
|
|
113
|
+
const l = Math.min(o, i + (d === 1 ? c : 2 * c - 1)), u = Array.from({ length: l - i + 1 }, () => /* @__PURE__ */ new Map());
|
|
114
|
+
u[0].set("0:0", { width: 0, sawHigh: !1, deviation: 0, segments: [], key: "" });
|
|
115
|
+
for (let a = i; a <= l; a++)
|
|
116
|
+
for (const f of u[a - i].values()) {
|
|
117
|
+
if (v(f, d, a), a === l) continue;
|
|
118
|
+
const x = (m, h, A, R) => {
|
|
119
|
+
if (f.width + h > c || a + A > l) return;
|
|
120
|
+
const $ = {
|
|
121
|
+
width: f.width + h,
|
|
122
|
+
sawHigh: f.sawHigh || m === "T",
|
|
123
|
+
deviation: f.deviation + R,
|
|
124
|
+
segments: [...f.segments, { kind: m, index: a, width: h }],
|
|
125
|
+
key: f.key + ee[m] + String(h).padStart(E, "0")
|
|
126
|
+
}, C = u[a + A - i], T = `${$.width}:${Number($.sawHigh)}`, W = C.get(T);
|
|
127
|
+
(!W || re($, W) < 0) && C.set(T, $);
|
|
128
|
+
}, y = S[a];
|
|
129
|
+
if (p[a]) {
|
|
130
|
+
if (d === 1) continue;
|
|
131
|
+
for (let m = y.min; m <= y.max; m++)
|
|
132
|
+
x("T", m, 1, Math.abs(m - y.preferred));
|
|
133
|
+
continue;
|
|
134
|
+
}
|
|
135
|
+
if (d === 1) {
|
|
136
|
+
for (let m = y.min; m <= y.max; m++)
|
|
137
|
+
x("L", m, 1, Math.abs(m - y.preferred));
|
|
138
|
+
continue;
|
|
139
|
+
}
|
|
140
|
+
if (a + 1 < l && !p[a + 1]) {
|
|
141
|
+
const m = S[a + 1];
|
|
142
|
+
for (let h = Math.max(y.min, m.min); h <= Math.min(y.max, m.max); h++)
|
|
143
|
+
x("P", h, 2, Math.abs(h - y.preferred) + Math.abs(h - m.preferred));
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
if (!g) throw new Error(`No Grid layout for item ${e[i].layoutId}`);
|
|
148
|
+
w[i] = g;
|
|
149
|
+
}
|
|
150
|
+
let I = 1, k = 0;
|
|
151
|
+
for (let i = w[0]; i != null && i.band; i = i.next) {
|
|
152
|
+
const { height: g, segments: v } = i.band;
|
|
153
|
+
let d = 1;
|
|
154
|
+
for (const { kind: l, index: u, width: a } of v)
|
|
155
|
+
n[e[u].layoutId] = {
|
|
156
|
+
colStart: d,
|
|
157
|
+
colSpan: a,
|
|
158
|
+
rowStart: I,
|
|
159
|
+
rowSpan: l === "P" ? 1 : g
|
|
160
|
+
}, l === "P" && (n[e[u + 1].layoutId] = { colStart: d, colSpan: a, rowStart: I + 1, rowSpan: 1 }), d += a;
|
|
161
|
+
k += g * (c - d + 1), I += g;
|
|
162
|
+
}
|
|
163
|
+
return { placements: n, rows: I - 1, holes: k };
|
|
164
|
+
}
|
|
165
|
+
function ae(e, t = G, { flexible: r = !1 } = {}) {
|
|
166
|
+
Y(t), oe(e);
|
|
167
|
+
const s = /* @__PURE__ */ Object.create(null);
|
|
168
|
+
for (const o of t.steps) s[o.name] = ie(e, t, o.name, r);
|
|
169
|
+
return { steps: s };
|
|
170
|
+
}
|
|
171
|
+
const me = "_root_pa68e_9", de = "_grid_pa68e_20", fe = "_item_pa68e_31", N = {
|
|
172
|
+
root: me,
|
|
173
|
+
grid: de,
|
|
174
|
+
item: fe
|
|
175
|
+
};
|
|
176
|
+
function ce({ layoutId: e, size: t, height: r = "low", className: s, ...o }) {
|
|
177
|
+
return /* @__PURE__ */ _("div", { ...o, "data-fx-grid-item": "", className: j(N.item, s) });
|
|
178
|
+
}
|
|
179
|
+
function le(e) {
|
|
180
|
+
const t = [], r = (s) => {
|
|
181
|
+
if (!(s == null || typeof s == "boolean")) {
|
|
182
|
+
if (Array.isArray(s)) {
|
|
183
|
+
s.forEach(r);
|
|
184
|
+
return;
|
|
185
|
+
}
|
|
186
|
+
if (!D(s) || s.type !== ce)
|
|
187
|
+
throw new Error("Grid accepts only direct GridItem elements, arrays, or empty conditional children");
|
|
188
|
+
t.push(s);
|
|
189
|
+
}
|
|
190
|
+
};
|
|
191
|
+
return r(e), t;
|
|
192
|
+
}
|
|
193
|
+
function we({ config: e = G, flexible: t = !1, children: r, className: s, ...o }) {
|
|
194
|
+
if (e.name === G.name && e !== G)
|
|
195
|
+
throw new Error(`Grid config name "${G.name}" belongs to defaultGridConfig; give a custom config its own name`);
|
|
196
|
+
const n = le(r), c = ae(
|
|
197
|
+
n.map(({ props: p }) => ({ layoutId: p.layoutId, size: p.size, height: p.height })),
|
|
198
|
+
e,
|
|
199
|
+
{ flexible: t }
|
|
200
|
+
), S = n.map((p) => {
|
|
201
|
+
const b = {};
|
|
202
|
+
for (const E of e.steps) {
|
|
203
|
+
const w = c.steps[E.name].placements[p.props.layoutId];
|
|
204
|
+
b[`--_grid-col-${E.name}`] = `${w.colStart} / span ${w.colSpan}`, b[`--_grid-row-${E.name}`] = `${w.rowStart} / span ${w.rowSpan}`;
|
|
205
|
+
}
|
|
206
|
+
return L(p, {
|
|
207
|
+
key: p.props.layoutId,
|
|
208
|
+
style: { ...p.props.style, ...b }
|
|
209
|
+
});
|
|
210
|
+
});
|
|
211
|
+
return /* @__PURE__ */ _("div", { ...o, className: j(N.root, s), children: /* @__PURE__ */ _(
|
|
212
|
+
"div",
|
|
213
|
+
{
|
|
214
|
+
className: N.grid,
|
|
215
|
+
"data-fx-grid": e.name,
|
|
216
|
+
"data-fx-grid-flexible": t ? "" : void 0,
|
|
217
|
+
style: { "--_grid-columns": e.columns },
|
|
218
|
+
children: S
|
|
219
|
+
}
|
|
220
|
+
) });
|
|
221
|
+
}
|
|
222
|
+
export {
|
|
223
|
+
we as Grid,
|
|
224
|
+
ce as GridItem,
|
|
225
|
+
G as defaultGridConfig
|
|
226
|
+
};
|
|
227
|
+
//# sourceMappingURL=grid.js.map
|
package/dist/grid.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"grid.js","sources":["../src/components/grid/grid-config-check.mjs","../src/components/grid/grid-config.ts","../src/components/grid/grid-solver.ts","../src/components/grid/grid.tsx"],"sourcesContent":["/*\n * The one Grid config validator: grid-config.ts and the generator\n * (grid-css.mjs, behind the frontx-ui-grid-css command) both import it, so a\n * config object and the stylesheet generated from it cannot disagree. The\n * build copies this module flat into dist/ next to the command. Plain\n * dependency-free ESM, so the command runs in plain Node without loading any\n * component code (the built entries import CSS).\n *\n * Types: grid-config-check.d.mts.\n */\n\nexport const SIZE_CLASSES = ['small', 'medium', 'large'];\n// Bounds the solver's width loops, which run per column.\nconst MAX_COLUMNS = 48;\nconst NAME_PATTERN = /^[a-z][a-z0-9-]*$/;\nconst TOKEN_PATTERN = /^--[a-z][a-z0-9-]*$/;\nconst LENGTH_PATTERN = /^(?:\\d+(?:\\.\\d+)?|\\.\\d+)(?:px|rem|em)$/;\n\nfunction validRange(range, columns) {\n return (\n !!range &&\n Number.isSafeInteger(range.min) &&\n Number.isSafeInteger(range.preferred) &&\n Number.isSafeInteger(range.max) &&\n range.min >= 1 &&\n range.min <= range.preferred &&\n range.preferred <= range.max &&\n range.max <= columns\n );\n}\n\n/**\n * Throws with a plain message when a config cannot drive the solver or the\n * generated CSS. `allowDefaultName` admits the reserved `default` scope, which\n * belongs to the kit's own defaultGridConfig and its shipped stylesheet; every\n * other caller refuses it.\n */\nexport function validateGridConfig(config, { allowDefaultName = false } = {}) {\n if (!config || typeof config !== 'object') throw new Error('Grid config must be an object');\n if (typeof config.name !== 'string' || !NAME_PATTERN.test(config.name)) {\n throw new Error('Grid config name must be a lowercase CSS-safe name');\n }\n if (!allowDefaultName && config.name === 'default') {\n throw new Error('Grid config name \"default\" belongs to defaultGridConfig; give a custom config its own name');\n }\n if (!Number.isSafeInteger(config.columns) || config.columns < 1 || config.columns > MAX_COLUMNS) {\n throw new Error(`Grid columns must be an integer from 1 to ${MAX_COLUMNS}`);\n }\n if (typeof config.rowHeight !== 'string' || !LENGTH_PATTERN.test(config.rowHeight) || parseFloat(config.rowHeight) <= 0) {\n throw new Error('Grid rowHeight must be a positive CSS length in px, rem or em');\n }\n if (!Array.isArray(config.steps) || config.steps.length === 0) throw new Error('Grid steps must be nonempty');\n const names = new Set();\n let previousWidth = -1;\n for (const step of config.steps) {\n if (!step || typeof step.name !== 'string' || !NAME_PATTERN.test(step.name) || names.has(step.name)) {\n throw new Error('Grid step names must be unique lowercase CSS-safe names');\n }\n if (!Number.isFinite(step.minWidth) || step.minWidth < 0 || step.minWidth <= previousWidth) {\n throw new Error('Grid step widths must be finite, nonnegative, and strictly increasing');\n }\n if (typeof step.gap !== 'string' || !TOKEN_PATTERN.test(step.gap)) {\n throw new Error(`Grid step ${step.name} gap must be a CSS token reference`);\n }\n names.add(step.name);\n previousWidth = step.minWidth;\n }\n if (config.steps[0].minWidth !== 0) throw new Error('Grid first step must start at 0');\n for (const size of SIZE_CLASSES) {\n const steps = config.sizes?.[size];\n if (!steps || typeof steps !== 'object') throw new Error(`Grid size ${size} is missing`);\n for (const name of names) {\n if (!validRange(steps[name], config.columns)) {\n throw new Error(`Grid size ${size} step ${name} needs 1 <= min <= preferred <= max <= columns`);\n }\n }\n }\n}\n","import defaultConfig from './grid-default-config.json';\nimport { validateGridConfig as checkConfig } from './grid-config-check.mjs';\n\nexport type GridSizeClass = 'small' | 'medium' | 'large';\nexport type GridHeightClass = 'low' | 'high';\n\n/*\n * A size class's span at one step, in columns: 1 <= min <= preferred <= max\n * <= columns. A Grid places `preferred`; only a flexible Grid moves inside\n * min..max to fill its rows.\n */\nexport interface GridSpanRange {\n min: number;\n preferred: number;\n max: number;\n}\n\n/*\n * One container step. `minWidth` is the Grid container's inline size in px\n * from which the step applies; the first step starts at 0. `gap` names a\n * spacing token (`--space-4`), the gap from this step on.\n */\nexport interface GridStep {\n name: string;\n minWidth: number;\n gap: string;\n}\n\n/*\n * A Grid config is data, kept in one file: the step CSS is generated from the\n * same data (`frontx-ui-grid-css`), and the shipped default config is this\n * package's grid-default-config.json. `name` scopes the generated rules, so\n * two configs can render on one page; `default` is the kit's own scope.\n * `rowHeight` is the fixed size of one row track: a low block is one track, a\n * high block two tracks and the row gap between them.\n */\nexport interface GridConfig {\n name: string;\n columns: number;\n rowHeight: string;\n steps: GridStep[];\n sizes: Record<GridSizeClass, Record<string, GridSpanRange>>;\n}\n\nfunction deepFreeze<T>(value: T): T {\n if (value && typeof value === 'object') {\n for (const child of Object.values(value)) deepFreeze(child);\n Object.freeze(value);\n }\n return value;\n}\n\n// Frozen: every Grid reads this one object, and Grid tells it apart from a\n// custom config by identity (the reserved `default` name belongs to this\n// object alone), so a mutation through a held reference cannot leak into\n// other Grids. The kit's own step CSS is generated from these values.\nexport const defaultGridConfig: GridConfig = deepFreeze(structuredClone(defaultConfig));\n\n// One copy with the validator: grid-config-check.mjs defines the classes, and\n// the hand-written .d.mts beside it types them as GridSizeClass.\nexport { SIZE_CLASSES } from './grid-config-check.mjs';\n\n/**\n * Throws with a plain message when a config cannot drive the solver or the\n * generated CSS. One validator with the CSS command (grid-config-check.mjs);\n * the reserved `default` scope is admitted here because defaultGridConfig\n * itself carries it, and Grid refuses it for any other config object.\n */\nexport function validateGridConfig(config: GridConfig): void {\n checkConfig(config, { allowDefaultName: true });\n}\n","import {\n SIZE_CLASSES,\n defaultGridConfig,\n validateGridConfig,\n type GridConfig,\n type GridHeightClass,\n type GridSizeClass,\n type GridSpanRange,\n} from './grid-config.js';\n\nexport interface GridItemSpec {\n layoutId: string;\n size: GridSizeClass;\n height?: GridHeightClass;\n}\n\nexport interface GridPlacement {\n colStart: number;\n colSpan: number;\n rowStart: number;\n rowSpan: number;\n}\n\nexport interface GridStepLayout {\n placements: Record<string, GridPlacement>;\n rows: number;\n holes: number;\n}\n\nexport interface GridLayout {\n steps: Record<string, GridStepLayout>;\n}\n\n/*\n * `flexible` is a property of one group (one Grid). Off, the default, every\n * block takes its size class's preferred span at each step, so widths stay\n * on the config's few fixed values and a row that does not fill keeps its\n * hole. On, a span may move inside the class's min..max to fill rows.\n */\nexport interface GridSolveOptions {\n flexible?: boolean;\n}\n\n/*\n * The placement search, run once per config step. Items are cut, in input\n * order, into bands. A one-track band holds lows (L) side by side. A\n * two-track band holds at least one high and is read as column segments\n * from the inline start: T is a high over both tracks, P is a pair of two\n * adjacent lows of one width (first on top). Row tracks have a fixed size,\n * so a low never spans two tracks: beside a high it stands only as half of\n * a pair. Unused columns sit at the inline end of a band.\n *\n * Plans compare by a cost tuple, lexicographically: hole cells in every\n * band but the last, hole cells in the last band, the sum of\n * |span - preferred| (always 0 unless flexible), the band count. A\n * two-track band's unused column counts two cells. Equal costs fall back\n * to a total tie order: band end indices, then each band's segment kinds\n * (P before T before L) and widths, smaller first. The order never\n * overrides cost.\n *\n * best[i] is the cheapest plan for items i..n-1. For each start the search\n * extends one band at a time through an inner table keyed by (next item,\n * used width, high seen), keeping only the cheapest partial band per key,\n * so the search stays linear in items for a fixed column count. The tie\n * keys `ends` and `kinds` are suffix strings, so they grow with the item\n * count; at the sizes a Grid group holds that cost is negligible.\n */\n\ntype SegmentKind = 'L' | 'P' | 'T';\n\ninterface Segment {\n kind: SegmentKind;\n index: number;\n width: number;\n}\n\ninterface PartialBand {\n width: number;\n sawHigh: boolean;\n deviation: number;\n segments: Segment[];\n // Segment kinds and widths as a fixed-width string, the band's tie key.\n key: string;\n}\n\ntype Cost = [number, number, number, number];\n\ninterface Plan {\n cost: Cost;\n ends: string;\n kinds: string;\n band?: { height: number; segments: Segment[] };\n next?: Plan;\n}\n\nconst KIND_ORDER: Record<SegmentKind, string> = { P: '0', T: '1', L: '2' };\n\n// Code-unit order, independent of the runtime locale.\nfunction compareText(a: string, b: string): number {\n return a < b ? -1 : a > b ? 1 : 0;\n}\n\nfunction compareCost(a: Cost, b: Cost): number {\n for (let i = 0; i < a.length; i++) if (a[i] !== b[i]) return a[i] - b[i];\n return 0;\n}\n\nfunction comparePartial(a: PartialBand, b: PartialBand): number {\n return a.deviation - b.deviation || compareText(a.key, b.key);\n}\n\nfunction comparePlan(a: Plan, b: Plan): number {\n return compareCost(a.cost, b.cost) || compareText(a.ends, b.ends) || compareText(a.kinds, b.kinds);\n}\n\nfunction validateItems(items: GridItemSpec[]): void {\n if (!Array.isArray(items)) throw new Error('Grid items must be an array');\n const ids = new Set<string>();\n for (const item of items) {\n if (!item || typeof item.layoutId !== 'string' || item.layoutId.length === 0) {\n throw new Error('Grid item layoutId must be a nonempty string');\n }\n if (ids.has(item.layoutId)) throw new Error(`Duplicate Grid layoutId: ${item.layoutId}`);\n if (!SIZE_CLASSES.includes(item.size)) {\n throw new Error(`Unknown Grid size: ${String(item.size)}`);\n }\n if (item.height !== undefined && item.height !== 'low' && item.height !== 'high') {\n throw new Error(`Unknown Grid height: ${String(item.height)}`);\n }\n ids.add(item.layoutId);\n }\n}\n\n// The span range a block may take at a step: its class's range when flexible, else its preferred span only.\nfunction spanRange(config: GridConfig, size: GridSizeClass, step: string, flexible: boolean): GridSpanRange {\n const range = config.sizes[size][step];\n return flexible ? range : { min: range.preferred, preferred: range.preferred, max: range.preferred };\n}\n\nfunction solveStep(items: GridItemSpec[], config: GridConfig, step: string, flexible: boolean): GridStepLayout {\n const n = items.length;\n const placements = Object.create(null) as Record<string, GridPlacement>;\n if (n === 0) return { placements, rows: 0, holes: 0 };\n\n const columns = config.columns;\n const ranges = items.map(item => spanRange(config, item.size, step, flexible));\n const high = items.map(item => item.height === 'high');\n const indexWidth = String(n).length;\n const spanWidth = String(columns).length;\n const best: Plan[] = new Array<Plan>(n + 1);\n best[n] = { cost: [0, 0, 0, 0], ends: '', kinds: '' };\n\n for (let start = n - 1; start >= 0; start--) {\n let winner: Plan | undefined;\n\n const offer = (band: PartialBand, height: number, end: number): void => {\n if (band.width === 0 || (height === 2 && !band.sawHigh)) return;\n const holes = height * (columns - band.width);\n const suffix = best[end];\n const plan: Plan = {\n cost: [\n (end < n ? holes : 0) + suffix.cost[0],\n (end === n ? holes : 0) + suffix.cost[1],\n band.deviation + suffix.cost[2],\n 1 + suffix.cost[3],\n ],\n ends: `${String(end).padStart(indexWidth, '0')},${suffix.ends}`,\n kinds: `${band.key}/${suffix.kinds}`,\n band: { height, segments: band.segments },\n next: suffix,\n };\n if (!winner || comparePlan(plan, winner) < 0) winner = plan;\n };\n\n for (const height of [1, 2]) {\n // A one-track band holds at most one item per column; a two-track\n // band one high plus pairs in every other column.\n const limit = Math.min(n, start + (height === 1 ? columns : 2 * columns - 1));\n const table: Map<string, PartialBand>[] = Array.from({ length: limit - start + 1 }, () => new Map());\n table[0].set('0:0', { width: 0, sawHigh: false, deviation: 0, segments: [], key: '' });\n\n for (let index = start; index <= limit; index++) {\n for (const band of table[index - start].values()) {\n offer(band, height, index);\n if (index === limit) continue;\n\n const extend = (kind: SegmentKind, width: number, count: number, deviation: number): void => {\n if (band.width + width > columns || index + count > limit) return;\n const candidate: PartialBand = {\n width: band.width + width,\n sawHigh: band.sawHigh || kind === 'T',\n deviation: band.deviation + deviation,\n segments: [...band.segments, { kind, index, width }],\n key: band.key + KIND_ORDER[kind] + String(width).padStart(spanWidth, '0'),\n };\n const bucket = table[index + count - start];\n const bucketKey = `${candidate.width}:${Number(candidate.sawHigh)}`;\n const held = bucket.get(bucketKey);\n if (!held || comparePartial(candidate, held) < 0) bucket.set(bucketKey, candidate);\n };\n\n const range = ranges[index];\n if (high[index]) {\n if (height === 1) continue;\n for (let width = range.min; width <= range.max; width++) {\n extend('T', width, 1, Math.abs(width - range.preferred));\n }\n continue;\n }\n if (height === 1) {\n for (let width = range.min; width <= range.max; width++) {\n extend('L', width, 1, Math.abs(width - range.preferred));\n }\n continue;\n }\n if (index + 1 < limit && !high[index + 1]) {\n const other: GridSpanRange = ranges[index + 1];\n for (let width = Math.max(range.min, other.min); width <= Math.min(range.max, other.max); width++) {\n extend('P', width, 2, Math.abs(width - range.preferred) + Math.abs(width - other.preferred));\n }\n }\n }\n }\n }\n\n // Every item fits a band of its own, so a plan always exists.\n if (!winner) throw new Error(`No Grid layout for item ${items[start].layoutId}`);\n best[start] = winner;\n }\n\n let row = 1;\n let holes = 0;\n for (let plan: Plan | undefined = best[0]; plan?.band; plan = plan.next) {\n const { height, segments } = plan.band;\n let col = 1;\n for (const { kind, index, width } of segments) {\n placements[items[index].layoutId] = {\n colStart: col,\n colSpan: width,\n rowStart: row,\n rowSpan: kind === 'P' ? 1 : height,\n };\n if (kind === 'P') {\n placements[items[index + 1].layoutId] = { colStart: col, colSpan: width, rowStart: row + 1, rowSpan: 1 };\n }\n col += width;\n }\n holes += height * (columns - col + 1);\n row += height;\n }\n return { placements, rows: row - 1, holes };\n}\n\n/**\n * Places ordered items for every step of a config. Pure: no DOM, no\n * measurement, the same input always gives the same output. Throws on an\n * invalid config, a duplicate `layoutId` or an unknown size or height.\n */\nexport function solveGridLayout(\n items: GridItemSpec[],\n config: GridConfig = defaultGridConfig,\n { flexible = false }: GridSolveOptions = {},\n): GridLayout {\n validateGridConfig(config);\n validateItems(items);\n const steps = Object.create(null) as Record<string, GridStepLayout>;\n for (const step of config.steps) steps[step.name] = solveStep(items, config, step.name, flexible);\n return { steps };\n}\n","import { cx } from 'class-variance-authority';\nimport {\n cloneElement,\n isValidElement,\n type ComponentProps,\n type CSSProperties,\n type ReactElement,\n type ReactNode,\n} from 'react';\n\nimport { defaultGridConfig, type GridConfig, type GridHeightClass, type GridSizeClass } from './grid-config.js';\nimport { solveGridLayout } from './grid-solver.js';\nimport styles from './grid.module.css';\nimport './grid-steps.css';\n\n/*\n * An ordered group of blocks that declare a size class and a height class,\n * never a span. Grid solves a placement for every config step during\n * render (pure, SSR safe) and hands each item its placement as custom\n * properties; the generated step CSS picks the set for the current\n * container width, so resizing runs no JavaScript. The wrapper is the\n * named `fx-grid` size container, since a container cannot query itself.\n * No hook and no effect, so Grid renders on the server as well.\n */\n\nexport interface GridItemProps extends ComponentProps<'div'> {\n /** Placement identity, unique within one Grid. Separate from the HTML id. */\n layoutId: string;\n /** The span range the item takes at every step: small, medium or large. */\n size: GridSizeClass;\n /** `low` is one row track, `high` is two tracks and the row gap between them. @default 'low' */\n height?: GridHeightClass;\n}\n\nexport function GridItem({ layoutId: _layoutId, size: _size, height: _height = 'low', className, ...props }: GridItemProps) {\n return <div {...props} data-fx-grid-item=\"\" className={cx(styles.item, className)} />;\n}\n\nexport interface GridProps extends ComponentProps<'div'> {\n /**\n * The config the step CSS is generated from; a custom config needs the\n * stylesheet the `frontx-ui-grid-css` command writes for it.\n * @default defaultGridConfig\n */\n config?: GridConfig;\n /** Lets spans move inside each size class's range to fill rows. Off: preferred spans only. @default false */\n flexible?: boolean;\n children?: ReactNode;\n}\n\n// Only what Grid can read: a fragment or a wrapper hides its items, so it throws instead of dropping them.\nfunction directItems(children: ReactNode): ReactElement<GridItemProps>[] {\n const result: ReactElement<GridItemProps>[] = [];\n const visit = (child: ReactNode): void => {\n if (child === null || child === undefined || typeof child === 'boolean') return;\n if (Array.isArray(child)) {\n child.forEach(visit);\n return;\n }\n if (!isValidElement<GridItemProps>(child) || child.type !== GridItem) {\n throw new Error('Grid accepts only direct GridItem elements, arrays, or empty conditional children');\n }\n result.push(child);\n };\n visit(children);\n return result;\n}\n\nexport function Grid({ config = defaultGridConfig, flexible = false, children, className, ...props }: GridProps) {\n // The kit's CSS owns the `default` scope; a second config under that name would read missing step variables.\n if (config.name === defaultGridConfig.name && config !== defaultGridConfig) {\n throw new Error(`Grid config name \"${defaultGridConfig.name}\" belongs to defaultGridConfig; give a custom config its own name`);\n }\n const elements = directItems(children);\n const layout = solveGridLayout(\n elements.map(({ props: item }) => ({ layoutId: item.layoutId, size: item.size, height: item.height })),\n config,\n { flexible },\n );\n\n const placed = elements.map(element => {\n const placement: Record<string, string> = {};\n for (const step of config.steps) {\n const item = layout.steps[step.name].placements[element.props.layoutId];\n placement[`--_grid-col-${step.name}`] = `${item.colStart} / span ${item.colSpan}`;\n placement[`--_grid-row-${step.name}`] = `${item.rowStart} / span ${item.rowSpan}`;\n }\n // Caller style stays; the placement properties win on a clash. layoutId,\n // unique within the Grid, is the key: the items are flattened into one\n // list, where caller keys from separate arrays could collide, and a\n // conditional item earlier in the list must not remount the ones after it.\n return cloneElement(element, {\n key: element.props.layoutId,\n style: { ...element.props.style, ...placement } as CSSProperties,\n });\n });\n\n return (\n <div {...props} className={cx(styles.root, className)}>\n <div\n className={styles.grid}\n data-fx-grid={config.name}\n data-fx-grid-flexible={flexible ? '' : undefined}\n style={{ '--_grid-columns': config.columns } as CSSProperties}\n >\n {placed}\n </div>\n </div>\n );\n}\n"],"names":["SIZE_CLASSES","MAX_COLUMNS","NAME_PATTERN","TOKEN_PATTERN","LENGTH_PATTERN","validRange","range","columns","validateGridConfig","config","allowDefaultName","names","previousWidth","step","size","steps","_a","name","deepFreeze","value","child","defaultGridConfig","defaultConfig","checkConfig","KIND_ORDER","compareText","a","b","compareCost","i","comparePartial","comparePlan","validateItems","items","ids","item","spanRange","flexible","solveStep","n","placements","ranges","high","indexWidth","spanWidth","best","start","winner","offer","band","height","end","holes","suffix","plan","limit","table","index","extend","kind","width","count","deviation","candidate","bucket","bucketKey","held","other","row","segments","col","solveGridLayout","GridItem","_layoutId","_size","_height","className","props","jsx","cx","styles","directItems","children","result","visit","isValidElement","Grid","elements","layout","placed","element","placement","cloneElement"],"mappings":";;;;;;;;;GAWaA,IAAe,CAAC,SAA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