@schema-engine/layout 0.5.1 → 0.5.2

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.
@@ -29,18 +29,64 @@ export interface NamedPlacement {
29
29
  width?: GridWidthName;
30
30
  offset?: GridOffsetName;
31
31
  }
32
+ /** One authored entry of an element's grid: its cascade slot, its keys, and where it sits in the element. */
33
+ interface GridSlotEntry {
34
+ slot: CascadeSlot;
35
+ entry: Record<string, unknown>;
36
+ /** `['grid']` for the top level, `['grid', 'responsive', slot]` for a responsive entry, `default` included. */
37
+ path: readonly string[];
38
+ }
32
39
  /**
33
40
  * An element's grid entries in cascade order: the top level, `responsive.default`,
34
41
  * then each breakpoint that is set.
35
42
  */
36
- export declare function elementGridSlots(element: unknown): Array<{
37
- slot: CascadeSlot;
38
- entry: Record<string, unknown>;
39
- }>;
43
+ export declare function elementGridSlots(element: unknown): GridSlotEntry[];
40
44
  /** Keys an element's `grid` config sets to a value, at the top level or in any breakpoint. */
41
45
  export declare function elementGridKeys(element: unknown): ReadonlySet<string>;
42
46
  export declare function elementUsesGridWidths(element: unknown): boolean;
43
47
  export declare function usesGridWidths(elements: readonly unknown[]): boolean;
48
+ /** Whether an element lays its children on its parent grid's tracks (`grid.subgrid`). */
49
+ export declare function elementIsSubgrid(element: unknown): boolean;
50
+ /**
51
+ * Why a subgrid's placement is invalid, or `undefined` when it is fine.
52
+ *
53
+ * @remarks
54
+ * A subgrid spans its parent's full row, so a `width`, `offset`, `span`, raw `column` or `area` would make it
55
+ * span less, and CSS ignores `justify-self` on a subgrid. The path is relative to the element and names the first
56
+ * conflicting key at the slot that sets it, as authored; the message is a clause the domain prefixes with
57
+ * the element's name.
58
+ */
59
+ export declare function subgridPlacementIssue(element: unknown): LayoutIssue | undefined;
60
+ /**
61
+ * Why an element's `span` cannot sit beside its other placement, or `undefined` when it is fine.
62
+ *
63
+ * @remarks
64
+ * `span` sets the item's column like `width`, `offset`, a raw `column` and an `area` do, so a slot that
65
+ * sets it and one of them would have two answers. Slots may differ: a narrower slot's `width` and a
66
+ * wider slot's `span` is the usual way to change sizing mode. The path is relative to the element and
67
+ * names the first conflicting key at the slot that sets it, as authored; the message is a clause the
68
+ * domain prefixes with the element's name.
69
+ */
70
+ export declare function spanPlacementIssue(element: unknown): LayoutIssue | undefined;
71
+ /**
72
+ * Where each element's `span` meets a grid whose track count CSS cannot know.
73
+ *
74
+ * @param grid The grid that places `elements`; one with no `columns: 'auto'` has no issue.
75
+ * @param elements The elements the grid places: its items, and the children of every subgrid among them.
76
+ *
77
+ * @remarks
78
+ * `columns: 'auto'` makes as many tracks as fit, a count that depends on the container's width and the
79
+ * minimum column width and cannot be computed in CSS, so a span there falls back to one track. Rather than
80
+ * render that silently, each element is checked against every slot where the grid's cascaded `columns` is
81
+ * `'auto'`, with the placement in effect there (the last one a narrower or equal slot set): a span counts, and
82
+ * a wider slot's raw `column` replaces it. The first such slot is reported per element. A grid that draws
83
+ * `areas` or whose items use named widths has a known count and has no issue.
84
+ *
85
+ * The path starts with the element's index in `elements`, then names the `span` key the author wrote at
86
+ * the slot that sets the span in effect: `[2, 'grid', 'span']` or `[2, 'grid', 'responsive', 'md', 'span']`.
87
+ * The message is a clause the domain prefixes with the element's name.
88
+ */
89
+ export declare function gridSpanIssues(grid: unknown, elements: readonly unknown[]): LayoutIssue[];
44
90
  /** Updates `carried` with the width and offset a slot authored; the other keeps its earlier value. */
45
91
  export declare function carryNamedPlacement(carried: NamedPlacement, entry: NamedPlacement): void;
46
92
  /**
@@ -105,3 +151,4 @@ export declare function cascadeValues<T>(authored: Partial<Record<CascadeSlot, T
105
151
  * area can be located in a ragged one.
106
152
  */
107
153
  export declare function areaTemplateIssues(grid: unknown): LayoutIssue[];
154
+ export {};
@@ -1 +1 @@
1
- var g=["sm","md","lg","xl","2xl"],f=["default",...g],R=12,m={full:12,"three-quarters":9,"two-thirds":8,half:6,third:4,quarter:3},P=["columns","minColumnWidth"];function i(e){return typeof e=="object"&&e!==null}function l(e){if(!i(e)||!i(e.grid))return[];let t=e.grid,n=[{slot:"default",entry:t}],o=t.responsive;if(!i(o))return n;for(let r of f){let s=o[r];i(s)&&n.push({slot:r,entry:s})}return n}function k(e){let t=new Set;for(let{entry:n}of l(e))for(let[o,r]of Object.entries(n))o!=="responsive"&&r!==void 0&&t.add(o);return t}function x(e){let t=k(e);return t.has("width")||t.has("offset")}function b(e){return e.some(x)}function A(e,t){e.width=t.width??e.width,e.offset=t.offset??e.offset}function N(e){let t={};for(let{slot:n,entry:o}of l(e)){if(o.width===void 0&&o.offset===void 0||(A(t,o),t.width===void 0||t.offset===void 0))continue;let r=(m[t.width]??0)+(m[t.offset]??0);if(r>R)return{slot:n,tracks:r}}}var h=".";function S(e){return typeof e!="string"?[]:e.trim().split(/\s+/).filter(Boolean).map(t=>/^\.+$/.test(t)?h:t)}function p(e){return Array.isArray(e)?e.map(S):void 0}function y(e){if(!i(e)||e.areas===void 0)return{};if(Array.isArray(e.areas)){let n=p(e.areas);return n?{default:n}:{}}if(!i(e.areas))return{};let t={};for(let n of f){let o=p(e.areas[n]);o&&(t[n]=o)}return t}function E(e){return Object.keys(y(e)).length>0}function G(e){let t=new Set;for(let n of e)for(let o of n)o!==h&&t.add(o);return[...t]}function I(e){return e.map(t=>`"${t.join(" ")}"`).join(" ")}function O(e){let t={};for(let{slot:n,entry:o}of l(e))typeof o.area=="string"&&(t[n]=o.area);return t}function v(e){let t={};for(let{slot:n,entry:o}of l(e))typeof o.hidden=="boolean"&&(t[n]=o.hidden);return t}function W(e){let t;return f.map(n=>(t=e[n]??t,{slot:n,value:t}))}function C(e){return`${e} ${e===1?"cell":"cells"}`}function T(e,t){let n=[];e.forEach((a,c)=>a.forEach((d,w)=>{d===t&&n.push([c,w])}));let o=n.map(([a])=>a),r=n.map(([,a])=>a),s=Math.max(...o)-Math.min(...o)+1,u=Math.max(...r)-Math.min(...r)+1;return s*u===n.length}function _(e){let t=y(e),n=i(e)&&Array.isArray(e.areas),o=[];for(let r of f){let s=t[r];if(!s)continue;let u=n?["areas"]:["areas",r],a=s[0]?.length??0,c=s.findIndex(d=>d.length!==a);if(c!==-1){o.push({path:u,message:`row ${c+1} has ${C(s[c]?.length??0)} but row 1 has ${a}.`});continue}for(let d of G(s))T(s,d)||o.push({path:u,message:`area '${d}' is not rectangular; CSS drops the whole template unless every area fills a rectangle.`})}return o}export{g as BREAKPOINT_ORDER,f as CASCADE_SLOTS,P as GRID_TEMPLATE_KEYS,m as WIDTH_SPANS,R as WIDTH_TRACKS,G as areaNames,_ as areaTemplateIssues,I as areasTemplateValue,A as carryNamedPlacement,W as cascadeValues,O as elementAreaSlots,k as elementGridKeys,l as elementGridSlots,v as elementHiddenSlots,x as elementUsesGridWidths,y as gridAreaTemplates,E as gridUsesAreas,N as namedPlacementOverflow,b as usesGridWidths};
1
+ var b=["sm","md","lg","xl","2xl"],m=["default",...b],A=12,h={full:12,"three-quarters":9,"two-thirds":8,half:6,third:4,quarter:3},O=["columns","minColumnWidth"];function u(e){return typeof e=="object"&&e!==null}function c(e){if(!u(e)||!u(e.grid))return[];let n=e.grid,t=[{slot:"default",entry:n,path:["grid"]}],o=n.responsive;if(!u(o))return t;for(let r of m){let s=o[r];u(s)&&t.push({slot:r,entry:s,path:["grid","responsive",r]})}return t}function P(e){let n=new Set;for(let{entry:t}of c(e))for(let[o,r]of Object.entries(t))o!=="responsive"&&r!==void 0&&n.add(o);return n}function G(e){let n=P(e);return n.has("width")||n.has("offset")}function C(e){return e.some(G)}function E(e){return u(e)&&u(e.grid)&&e.grid.subgrid===!0}var I=["width","offset","column","area","span","justifySelf","placeSelf"];function B(e){if(E(e))for(let{entry:n,path:t}of c(e)){let o=I.find(r=>n[r]!==void 0);if(o!==void 0)return{path:[...t,o],message:`sets grid 'subgrid' and '${o}'; a subgrid spans its parent's full row, so it takes no 'width', 'offset', 'column', 'area', 'span', 'justifySelf' or 'placeSelf'.`}}}var g=["width","offset","column","area"];function W(e){for(let{slot:n,entry:t,path:o}of c(e)){if(t.span===void 0)continue;let r=g.find(s=>t[s]!==void 0);if(r!==void 0)return{path:[...o,r],message:`sets grid 'span' and '${r}'${n==="default"?"":` at '${n}'`}; a span is a placement of its own, so use 'span' or one of 'width', 'offset', 'column' and 'area' in a breakpoint, not together.`}}}function j(e,n){if(!u(e)||$(e)||C(n))return[];let t={};for(let{slot:s,entry:f}of c({grid:e}))t[s]=f.columns??t[s];let o=new Set(w(t).filter(({value:s})=>s==="auto").map(({slot:s})=>s));if(o.size===0)return[];let r=[];return n.forEach((s,f)=>{let a={};for(let{slot:l,entry:p,path:x}of c(s))p.span!==void 0?a[l]={spanPath:[...x,"span"]}:g.some(R=>p[R]!==void 0)&&(a[l]={});let i=w(a).find(({slot:l,value:p})=>o.has(l)&&p?.spanPath),d=i?.value?.spanPath;!i||!d||r.push({path:[f,...d],message:`sets grid 'span' where the grid's columns are 'auto'${i.slot==="default"?"":` at '${i.slot}'`}; CSS cannot know how many tracks 'auto' makes, so the span falls back to one track. Set 'columns' to a number, per breakpoint if it changes, and use a theme with query 'container' so the breakpoints follow the grid's container.`})}),r}function T(e,n){e.width=n.width??e.width,e.offset=n.offset??e.offset}function D(e){let n={};for(let{slot:t,entry:o}of c(e)){if(o.width===void 0&&o.offset===void 0||(T(n,o),n.width===void 0||n.offset===void 0))continue;let r=(h[n.width]??0)+(h[n.offset]??0);if(r>A)return{slot:t,tracks:r}}}var S=".";function N(e){return typeof e!="string"?[]:e.trim().split(/\s+/).filter(Boolean).map(n=>/^\.+$/.test(n)?S:n)}function y(e){return Array.isArray(e)?e.map(N):void 0}function k(e){if(!u(e)||e.areas===void 0)return{};if(Array.isArray(e.areas)){let t=y(e.areas);return t?{default:t}:{}}if(!u(e.areas))return{};let n={};for(let t of m){let o=y(e.areas[t]);o&&(n[t]=o)}return n}function $(e){return Object.keys(k(e)).length>0}function L(e){let n=new Set;for(let t of e)for(let o of t)o!==S&&n.add(o);return[...n]}function K(e){return e.map(n=>`"${n.join(" ")}"`).join(" ")}function U(e){let n={};for(let{slot:t,entry:o}of c(e))typeof o.area=="string"&&(n[t]=o.area);return n}function M(e){let n={};for(let{slot:t,entry:o}of c(e))typeof o.hidden=="boolean"&&(n[t]=o.hidden);return n}function w(e){let n;return m.map(t=>(n=e[t]??n,{slot:t,value:n}))}function _(e){return`${e} ${e===1?"cell":"cells"}`}function v(e,n){let t=[];e.forEach((a,i)=>a.forEach((d,l)=>{d===n&&t.push([i,l])}));let o=t.map(([a])=>a),r=t.map(([,a])=>a),s=Math.max(...o)-Math.min(...o)+1,f=Math.max(...r)-Math.min(...r)+1;return s*f===t.length}function V(e){let n=k(e),t=u(e)&&Array.isArray(e.areas),o=[];for(let r of m){let s=n[r];if(!s)continue;let f=t?["areas"]:["areas",r],a=s[0]?.length??0,i=s.findIndex(d=>d.length!==a);if(i!==-1){o.push({path:f,message:`row ${i+1} has ${_(s[i]?.length??0)} but row 1 has ${a}.`});continue}for(let d of L(s))v(s,d)||o.push({path:f,message:`area '${d}' is not rectangular; CSS drops the whole template unless every area fills a rectangle.`})}return o}export{b as BREAKPOINT_ORDER,m as CASCADE_SLOTS,O as GRID_TEMPLATE_KEYS,h as WIDTH_SPANS,A as WIDTH_TRACKS,L as areaNames,V as areaTemplateIssues,K as areasTemplateValue,T as carryNamedPlacement,w as cascadeValues,U as elementAreaSlots,P as elementGridKeys,c as elementGridSlots,M as elementHiddenSlots,E as elementIsSubgrid,G as elementUsesGridWidths,k as gridAreaTemplates,j as gridSpanIssues,$ as gridUsesAreas,D as namedPlacementOverflow,W as spanPlacementIssue,B as subgridPlacementIssue,C as usesGridWidths};
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/lib/grid-placement.ts"],
4
- "sourcesContent": ["import type { GridBreakpointConfig, GridOffsetName, GridWidthName } from '@/schemas/grid';\nimport type { LayoutIssue } from './layout-issue';\n\n/**\n * Reads of an element's grid placement shared by the stylesheet emitter and\n * validation, so the cascade the author is checked against is the one emitted.\n *\n * @remarks\n * Elements arrive as `unknown` because they are read before, or without, a\n * registered schema narrowing them: a registration may declare `grid` loosely.\n */\n\nexport const BREAKPOINT_ORDER = ['sm', 'md', 'lg', 'xl', '2xl'] as const;\n\n/** Named breakpoint tokens. Thresholds are configured on the layout theme's `grid` option. */\nexport type GridBreakpointToken = (typeof BREAKPOINT_ORDER)[number];\n\nexport type CascadeSlot = 'default' | GridBreakpointToken;\n\n/** Every slot of the cascade, narrowest first. */\nexport const CASCADE_SLOTS: readonly CascadeSlot[] = ['default', ...BREAKPOINT_ORDER];\n\n/** Tracks a grid has once its items use named widths. */\nexport const WIDTH_TRACKS = 12;\n\nexport const WIDTH_SPANS: Readonly<Record<GridWidthName, number>> = {\n\tfull: 12,\n\t'three-quarters': 9,\n\t'two-thirds': 8,\n\thalf: 6,\n\tthird: 4,\n\tquarter: 3,\n};\n\n/**\n * Grid keys that define the template, and so cannot meet named widths.\n *\n * @remarks\n * Typed against the breakpoint schema so a renamed key fails to compile here.\n */\nexport const GRID_TEMPLATE_KEYS = [\n\t'columns',\n\t'minColumnWidth',\n] as const satisfies readonly (keyof GridBreakpointConfig)[];\n\n/** The width and offset an item has authored so far, carried through the cascade. */\nexport interface NamedPlacement {\n\twidth?: GridWidthName;\n\toffset?: GridOffsetName;\n}\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n\treturn typeof value === 'object' && value !== null;\n}\n\n/**\n * An element's grid entries in cascade order: the top level, `responsive.default`,\n * then each breakpoint that is set.\n */\nexport function elementGridSlots(element: unknown): Array<{ slot: CascadeSlot; entry: Record<string, unknown> }> {\n\tif (!isRecord(element) || !isRecord(element.grid)) return [];\n\tconst grid = element.grid;\n\tconst slots: Array<{ slot: CascadeSlot; entry: Record<string, unknown> }> = [{ slot: 'default', entry: grid }];\n\tconst responsive = grid.responsive;\n\tif (!isRecord(responsive)) return slots;\n\tfor (const slot of CASCADE_SLOTS) {\n\t\tconst entry = responsive[slot];\n\t\tif (isRecord(entry)) slots.push({ slot, entry });\n\t}\n\treturn slots;\n}\n\n/** Keys an element's `grid` config sets to a value, at the top level or in any breakpoint. */\nexport function elementGridKeys(element: unknown): ReadonlySet<string> {\n\tconst keys = new Set<string>();\n\tfor (const { entry } of elementGridSlots(element)) {\n\t\tfor (const [key, value] of Object.entries(entry)) {\n\t\t\tif (key !== 'responsive' && value !== undefined) keys.add(key);\n\t\t}\n\t}\n\treturn keys;\n}\n\nexport function elementUsesGridWidths(element: unknown): boolean {\n\tconst keys = elementGridKeys(element);\n\treturn keys.has('width') || keys.has('offset');\n}\n\nexport function usesGridWidths(elements: readonly unknown[]): boolean {\n\treturn elements.some(elementUsesGridWidths);\n}\n\n/** Updates `carried` with the width and offset a slot authored; the other keeps its earlier value. */\nexport function carryNamedPlacement(carried: NamedPlacement, entry: NamedPlacement): void {\n\tcarried.width = entry.width ?? carried.width;\n\tcarried.offset = entry.offset ?? carried.offset;\n}\n\n/**\n * The first slot where an element's offset and width together pass the grid's\n * tracks, with the tracks they span, or `undefined` when none does.\n *\n * @remarks\n * Follows the same carry-over as emission: a slot that sets one of the pair is\n * checked against the other as the narrower slots left it, so two slots that\n * each look valid can still overflow together.\n */\nexport function namedPlacementOverflow(element: unknown): { slot: CascadeSlot; tracks: number } | undefined {\n\tconst carried: NamedPlacement = {};\n\tfor (const { slot, entry } of elementGridSlots(element)) {\n\t\tif (entry.width === undefined && entry.offset === undefined) continue;\n\t\tcarryNamedPlacement(carried, entry as NamedPlacement);\n\t\tif (carried.width === undefined || carried.offset === undefined) continue;\n\t\tconst tracks = (WIDTH_SPANS[carried.width] ?? 0) + (WIDTH_SPANS[carried.offset] ?? 0);\n\t\tif (tracks > WIDTH_TRACKS) return { slot, tracks };\n\t}\n\treturn undefined;\n}\n\n/** The cells of each row of a template; `.` marks an empty cell. */\nexport type GridAreaRows = readonly (readonly string[])[];\n\n/** Templates by the slot that sets them. */\nexport type GridAreaTemplates = Partial<Record<CascadeSlot, GridAreaRows>>;\n\nconst EMPTY_CELL = '.';\n\nfunction splitRow(row: unknown): string[] {\n\tif (typeof row !== 'string') return [];\n\treturn row\n\t\t.trim()\n\t\t.split(/\\s+/)\n\t\t.filter(Boolean)\n\t\t.map((cell) => (/^\\.+$/.test(cell) ? EMPTY_CELL : cell));\n}\n\nfunction toRows(rows: unknown): GridAreaRows | undefined {\n\treturn Array.isArray(rows) ? rows.map(splitRow) : undefined;\n}\n\n/**\n * The templates a grid's `areas` sets, by slot. An array is the `default` template.\n *\n * @remarks\n * A run of dots is one empty cell, normalised to a single `.`, so a template\n * compares and emits the same however the author spaced it.\n */\nexport function gridAreaTemplates(grid: unknown): GridAreaTemplates {\n\tif (!isRecord(grid) || grid.areas === undefined) return {};\n\tif (Array.isArray(grid.areas)) {\n\t\tconst rows = toRows(grid.areas);\n\t\treturn rows ? { default: rows } : {};\n\t}\n\tif (!isRecord(grid.areas)) return {};\n\tconst templates: GridAreaTemplates = {};\n\tfor (const slot of CASCADE_SLOTS) {\n\t\tconst rows = toRows(grid.areas[slot]);\n\t\tif (rows) templates[slot] = rows;\n\t}\n\treturn templates;\n}\n\n/** Whether a grid draws its layout with `areas`. */\nexport function gridUsesAreas(grid: unknown): boolean {\n\treturn Object.keys(gridAreaTemplates(grid)).length > 0;\n}\n\n/** Area names a template uses, in order of first appearance. */\nexport function areaNames(rows: GridAreaRows): string[] {\n\tconst names = new Set<string>();\n\tfor (const row of rows) {\n\t\tfor (const cell of row) if (cell !== EMPTY_CELL) names.add(cell);\n\t}\n\treturn [...names];\n}\n\n/** The `grid-template-areas` value for a template: one quoted string per row. */\nexport function areasTemplateValue(rows: GridAreaRows): string {\n\treturn rows.map((row) => `\"${row.join(' ')}\"`).join(' ');\n}\n\n/**\n * The area an element authored at each slot it sets one. Within a slot,\n * `responsive.default` beats the top level, as in emission.\n */\nexport function elementAreaSlots(element: unknown): Partial<Record<CascadeSlot, string>> {\n\tconst areas: Partial<Record<CascadeSlot, string>> = {};\n\tfor (const { slot, entry } of elementGridSlots(element)) {\n\t\tif (typeof entry.area === 'string') areas[slot] = entry.area;\n\t}\n\treturn areas;\n}\n\n/** Whether an element hides itself at each slot it sets `hidden`, in cascade order within a slot. */\nexport function elementHiddenSlots(element: unknown): Partial<Record<CascadeSlot, boolean>> {\n\tconst hidden: Partial<Record<CascadeSlot, boolean>> = {};\n\tfor (const { slot, entry } of elementGridSlots(element)) {\n\t\tif (typeof entry.hidden === 'boolean') hidden[slot] = entry.hidden;\n\t}\n\treturn hidden;\n}\n\n/**\n * What each slot resolves to: the value set at that slot, else the last one a\n * narrower slot set.\n *\n * @remarks\n * Emission falls back through narrower slots in the stylesheet, so validation\n * reads templates and areas the same way to check what a viewport gets.\n */\nexport function cascadeValues<T>(\n\tauthored: Partial<Record<CascadeSlot, T>>,\n): Array<{ slot: CascadeSlot; value: T | undefined }> {\n\tlet carried: T | undefined;\n\treturn CASCADE_SLOTS.map((slot) => {\n\t\tcarried = authored[slot] ?? carried;\n\t\treturn { slot, value: carried };\n\t});\n}\n\nfunction cellCount(count: number): string {\n\treturn `${count} ${count === 1 ? 'cell' : 'cells'}`;\n}\n\nfunction isRectangle(rows: GridAreaRows, name: string): boolean {\n\tconst cells: Array<[row: number, column: number]> = [];\n\trows.forEach((row, rowIndex) =>\n\t\trow.forEach((cell, columnIndex) => {\n\t\t\tif (cell === name) cells.push([rowIndex, columnIndex]);\n\t\t}),\n\t);\n\tconst rowsUsed = cells.map(([row]) => row);\n\tconst columnsUsed = cells.map(([, column]) => column);\n\tconst height = Math.max(...rowsUsed) - Math.min(...rowsUsed) + 1;\n\tconst width = Math.max(...columnsUsed) - Math.min(...columnsUsed) + 1;\n\treturn height * width === cells.length;\n}\n\n/**\n * Why CSS would drop a template: rows of unequal length, or an area whose cells\n * do not fill a rectangle.\n *\n * @param grid A grid config; one that sets no `areas` has no issue.\n *\n * @remarks\n * Each issue's `path` is relative to the grid: `['areas']` for the array form of the default\n * template, else `['areas', slot]`. Rows of unequal length stop the check for that template, as no\n * area can be located in a ragged one.\n */\nexport function areaTemplateIssues(grid: unknown): LayoutIssue[] {\n\tconst templates = gridAreaTemplates(grid);\n\tconst arrayForm = isRecord(grid) && Array.isArray(grid.areas);\n\tconst issues: LayoutIssue[] = [];\n\tfor (const slot of CASCADE_SLOTS) {\n\t\tconst rows = templates[slot];\n\t\tif (!rows) continue;\n\t\tconst path = arrayForm ? ['areas'] : ['areas', slot];\n\t\tconst width = rows[0]?.length ?? 0;\n\t\tconst ragged = rows.findIndex((row) => row.length !== width);\n\t\tif (ragged !== -1) {\n\t\t\tissues.push({\n\t\t\t\tpath,\n\t\t\t\tmessage: `row ${ragged + 1} has ${cellCount(rows[ragged]?.length ?? 0)} but row 1 has ${width}.`,\n\t\t\t});\n\t\t\tcontinue;\n\t\t}\n\t\tfor (const name of areaNames(rows)) {\n\t\t\tif (!isRectangle(rows, name)) {\n\t\t\t\tissues.push({\n\t\t\t\t\tpath,\n\t\t\t\t\tmessage: `area '${name}' is not rectangular; CSS drops the whole template unless every area fills a rectangle.`,\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\t}\n\treturn issues;\n}\n"],
5
- "mappings": "AAYO,IAAMA,EAAmB,CAAC,KAAM,KAAM,KAAM,KAAM,KAAK,EAQjDC,EAAwC,CAAC,UAAW,GAAGD,CAAgB,EAGvEE,EAAe,GAEfC,EAAuD,CACnE,KAAM,GACN,iBAAkB,EAClB,aAAc,EACd,KAAM,EACN,MAAO,EACP,QAAS,CACV,EAQaC,EAAqB,CACjC,UACA,gBACD,EAQA,SAASC,EAASC,EAAkD,CACnE,OAAO,OAAOA,GAAU,UAAYA,IAAU,IAC/C,CAMO,SAASC,EAAiBC,EAAgF,CAChH,GAAI,CAACH,EAASG,CAAO,GAAK,CAACH,EAASG,EAAQ,IAAI,EAAG,MAAO,CAAC,EAC3D,IAAMC,EAAOD,EAAQ,KACfE,EAAsE,CAAC,CAAE,KAAM,UAAW,MAAOD,CAAK,CAAC,EACvGE,EAAaF,EAAK,WACxB,GAAI,CAACJ,EAASM,C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,CACjC,IAAM4B,EAAOE,EAAUnB,CAAI,EAC3B,GAAI,CAACiB,EAAM,SACX,IAAM4B,EAAOF,EAAY,CAAC,OAAO,EAAI,CAAC,QAAS3C,CAAI,EAC7CyC,EAAQxB,EAAK,CAAC,GAAG,QAAU,EAC3B6B,EAAS7B,EAAK,UAAWH,GAAQA,EAAI,SAAW2B,CAAK,EAC3D,GAAIK,IAAW,GAAI,CAClBF,EAAO,KAAK,CACX,KAAAC,EACA,QAAS,OAAOC,EAAS,CAAC,QAAQhB,EAAUb,EAAK6B,CAAM,GAAG,QAAU,CAAC,CAAC,kBAAkBL,CAAK,GAC9F,CAAC,EACD,QACD,CACA,QAAWR,KAAQZ,EAAUJ,CAAI,EAC3Be,EAAYf,EAAMgB,CAAI,GAC1BW,EAAO,KAAK,CACX,KAAAC,EACA,QAAS,SAASZ,CAAI,yFACvB,CAAC,CAGJ,CACA,OAAOW,CACR",
6
- "names": ["BREAKPOINT_ORDER", "CASCADE_SLOTS", "WIDTH_TRACKS", "WIDTH_SPANS", "GRID_TEMPLATE_KEYS", "isRecord", "value", "elementGridSlots", "element", "grid", "slots", "responsive", "slot", "entry", "elementGridKeys", "keys", "key", "elementUsesGridWidths", "usesGridWidths", "elements", "carryNamedPlacement", "carried", "namedPlacementOverflow", "tracks", "EMPTY_CELL", "splitRow", "row", "cell", "toRows", "rows", "gridAreaTemplates", "templates", "gridUsesAreas", "areaNames", "names", "areasTemplateValue", "elementAreaSlots", "areas", "elementHiddenSlots", "hidden", "cascadeValues", "authored", "cellCount", "count", "isRectangle", "name", "cells", "rowIndex", "columnIndex", "rowsUsed", "columnsUsed", "column", "height", "width", "areaTemplateIssues", "arrayForm", "issues", "path", "ragged"]
4
+ "sourcesContent": ["import type { GridBreakpointConfig, GridOffsetName, GridWidthName } from '@/schemas/grid';\nimport type { LayoutIssue } from './layout-issue';\n\n/**\n * Reads of an element's grid placement shared by the stylesheet emitter and\n * validation, so the cascade the author is checked against is the one emitted.\n *\n * @remarks\n * Elements arrive as `unknown` because they are read before, or without, a\n * registered schema narrowing them: a registration may declare `grid` loosely.\n */\n\nexport const BREAKPOINT_ORDER = ['sm', 'md', 'lg', 'xl', '2xl'] as const;\n\n/** Named breakpoint tokens. Thresholds are configured on the layout theme's `grid` option. */\nexport type GridBreakpointToken = (typeof BREAKPOINT_ORDER)[number];\n\nexport type CascadeSlot = 'default' | GridBreakpointToken;\n\n/** Every slot of the cascade, narrowest first. */\nexport const CASCADE_SLOTS: readonly CascadeSlot[] = ['default', ...BREAKPOINT_ORDER];\n\n/** Tracks a grid has once its items use named widths. */\nexport const WIDTH_TRACKS = 12;\n\nexport const WIDTH_SPANS: Readonly<Record<GridWidthName, number>> = {\n\tfull: 12,\n\t'three-quarters': 9,\n\t'two-thirds': 8,\n\thalf: 6,\n\tthird: 4,\n\tquarter: 3,\n};\n\n/**\n * Grid keys that define the template, and so cannot meet named widths.\n *\n * @remarks\n * Typed against the breakpoint schema so a renamed key fails to compile here.\n */\nexport const GRID_TEMPLATE_KEYS = [\n\t'columns',\n\t'minColumnWidth',\n] as const satisfies readonly (keyof GridBreakpointConfig)[];\n\n/** The width and offset an item has authored so far, carried through the cascade. */\nexport interface NamedPlacement {\n\twidth?: GridWidthName;\n\toffset?: GridOffsetName;\n}\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n\treturn typeof value === 'object' && value !== null;\n}\n\n/** One authored entry of an element's grid: its cascade slot, its keys, and where it sits in the element. */\ninterface GridSlotEntry {\n\tslot: CascadeSlot;\n\tentry: Record<string, unknown>;\n\t/** `['grid']` for the top level, `['grid', 'responsive', slot]` for a responsive entry, `default` included. */\n\tpath: readonly string[];\n}\n\n/**\n * An element's grid entries in cascade order: the top level, `responsive.default`,\n * then each breakpoint that is set.\n */\nexport function elementGridSlots(element: unknown): GridSlotEntry[] {\n\tif (!isRecord(element) || !isRecord(element.grid)) return [];\n\tconst grid = element.grid;\n\tconst slots: GridSlotEntry[] = [{ slot: 'default', entry: grid, path: ['grid'] }];\n\tconst responsive = grid.responsive;\n\tif (!isRecord(responsive)) return slots;\n\tfor (const slot of CASCADE_SLOTS) {\n\t\tconst entry = responsive[slot];\n\t\tif (isRecord(entry)) slots.push({ slot, entry, path: ['grid', 'responsive', slot] });\n\t}\n\treturn slots;\n}\n\n/** Keys an element's `grid` config sets to a value, at the top level or in any breakpoint. */\nexport function elementGridKeys(element: unknown): ReadonlySet<string> {\n\tconst keys = new Set<string>();\n\tfor (const { entry } of elementGridSlots(element)) {\n\t\tfor (const [key, value] of Object.entries(entry)) {\n\t\t\tif (key !== 'responsive' && value !== undefined) keys.add(key);\n\t\t}\n\t}\n\treturn keys;\n}\n\nexport function elementUsesGridWidths(element: unknown): boolean {\n\tconst keys = elementGridKeys(element);\n\treturn keys.has('width') || keys.has('offset');\n}\n\nexport function usesGridWidths(elements: readonly unknown[]): boolean {\n\treturn elements.some(elementUsesGridWidths);\n}\n\n/** Whether an element lays its children on its parent grid's tracks (`grid.subgrid`). */\nexport function elementIsSubgrid(element: unknown): boolean {\n\treturn isRecord(element) && isRecord(element.grid) && element.grid.subgrid === true;\n}\n\n/** Placement keys a subgrid cannot set: it always spans its parent's full row and is stretched on it. */\nconst SUBGRID_EXCLUSIVE_KEYS = ['width', 'offset', 'column', 'area', 'span', 'justifySelf', 'placeSelf'] as const;\n\n/**\n * Why a subgrid's placement is invalid, or `undefined` when it is fine.\n *\n * @remarks\n * A subgrid spans its parent's full row, so a `width`, `offset`, `span`, raw `column` or `area` would make it\n * span less, and CSS ignores `justify-self` on a subgrid. The path is relative to the element and names the first\n * conflicting key at the slot that sets it, as authored; the message is a clause the domain prefixes with\n * the element's name.\n */\nexport function subgridPlacementIssue(element: unknown): LayoutIssue | undefined {\n\tif (!elementIsSubgrid(element)) return undefined;\n\tfor (const { entry, path } of elementGridSlots(element)) {\n\t\tconst key = SUBGRID_EXCLUSIVE_KEYS.find((name) => entry[name] !== undefined);\n\t\tif (key === undefined) continue;\n\t\treturn {\n\t\t\tpath: [...path, key],\n\t\t\tmessage: `sets grid 'subgrid' and '${key}'; a subgrid spans its parent's full row, so it takes no 'width', 'offset', 'column', 'area', 'span', 'justifySelf' or 'placeSelf'.`,\n\t\t};\n\t}\n\treturn undefined;\n}\n\n/** Placement keys that `span` cannot share a slot with, because each sets the item's `grid-column` too. */\nconst SPAN_EXCLUSIVE_KEYS = ['width', 'offset', 'column', 'area'] as const;\n\n/**\n * Why an element's `span` cannot sit beside its other placement, or `undefined` when it is fine.\n *\n * @remarks\n * `span` sets the item's column like `width`, `offset`, a raw `column` and an `area` do, so a slot that\n * sets it and one of them would have two answers. Slots may differ: a narrower slot's `width` and a\n * wider slot's `span` is the usual way to change sizing mode. The path is relative to the element and\n * names the first conflicting key at the slot that sets it, as authored; the message is a clause the\n * domain prefixes with the element's name.\n */\nexport function spanPlacementIssue(element: unknown): LayoutIssue | undefined {\n\tfor (const { slot, entry, path } of elementGridSlots(element)) {\n\t\tif (entry.span === undefined) continue;\n\t\tconst key = SPAN_EXCLUSIVE_KEYS.find((name) => entry[name] !== undefined);\n\t\tif (key === undefined) continue;\n\t\treturn {\n\t\t\tpath: [...path, key],\n\t\t\tmessage: `sets grid 'span' and '${key}'${slot === 'default' ? '' : ` at '${slot}'`}; a span is a placement of its own, so use 'span' or one of 'width', 'offset', 'column' and 'area' in a breakpoint, not together.`,\n\t\t};\n\t}\n\treturn undefined;\n}\n\n/**\n * Where each element's `span` meets a grid whose track count CSS cannot know.\n *\n * @param grid The grid that places `elements`; one with no `columns: 'auto'` has no issue.\n * @param elements The elements the grid places: its items, and the children of every subgrid among them.\n *\n * @remarks\n * `columns: 'auto'` makes as many tracks as fit, a count that depends on the container's width and the\n * minimum column width and cannot be computed in CSS, so a span there falls back to one track. Rather than\n * render that silently, each element is checked against every slot where the grid's cascaded `columns` is\n * `'auto'`, with the placement in effect there (the last one a narrower or equal slot set): a span counts, and\n * a wider slot's raw `column` replaces it. The first such slot is reported per element. A grid that draws\n * `areas` or whose items use named widths has a known count and has no issue.\n *\n * The path starts with the element's index in `elements`, then names the `span` key the author wrote at\n * the slot that sets the span in effect: `[2, 'grid', 'span']` or `[2, 'grid', 'responsive', 'md', 'span']`.\n * The message is a clause the domain prefixes with the element's name.\n */\nexport function gridSpanIssues(grid: unknown, elements: readonly unknown[]): LayoutIssue[] {\n\tif (!isRecord(grid) || gridUsesAreas(grid) || usesGridWidths(elements)) return [];\n\tconst columns: Partial<Record<CascadeSlot, unknown>> = {};\n\tfor (const { slot, entry } of elementGridSlots({ grid })) columns[slot] = entry.columns ?? columns[slot];\n\tconst autoSlots = new Set(\n\t\tcascadeValues(columns)\n\t\t\t.filter(({ value }) => value === 'auto')\n\t\t\t.map(({ slot }) => slot),\n\t);\n\tif (autoSlots.size === 0) return [];\n\n\tconst issues: LayoutIssue[] = [];\n\telements.forEach((element, index) => {\n\t\tconst placements: Partial<Record<CascadeSlot, { spanPath?: readonly string[] }>> = {};\n\t\tfor (const { slot, entry, path } of elementGridSlots(element)) {\n\t\t\tif (entry.span !== undefined) placements[slot] = { spanPath: [...path, 'span'] };\n\t\t\telse if (SPAN_EXCLUSIVE_KEYS.some((key) => entry[key] !== undefined)) placements[slot] = {};\n\t\t}\n\t\tconst offending = cascadeValues(placements).find(({ slot, value }) => autoSlots.has(slot) && value?.spanPath);\n\t\tconst spanPath = offending?.value?.spanPath;\n\t\tif (!offending || !spanPath) return;\n\t\tissues.push({\n\t\t\tpath: [index, ...spanPath],\n\t\t\tmessage: `sets grid 'span' where the grid's columns are 'auto'${offending.slot === 'default' ? '' : ` at '${offending.slot}'`}; CSS cannot know how many tracks 'auto' makes, so the span falls back to one track. Set 'columns' to a number, per breakpoint if it changes, and use a theme with query 'container' so the breakpoints follow the grid's container.`,\n\t\t});\n\t});\n\treturn issues;\n}\n\n/** Updates `carried` with the width and offset a slot authored; the other keeps its earlier value. */\nexport function carryNamedPlacement(carried: NamedPlacement, entry: NamedPlacement): void {\n\tcarried.width = entry.width ?? carried.width;\n\tcarried.offset = entry.offset ?? carried.offset;\n}\n\n/**\n * The first slot where an element's offset and width together pass the grid's\n * tracks, with the tracks they span, or `undefined` when none does.\n *\n * @remarks\n * Follows the same carry-over as emission: a slot that sets one of the pair is\n * checked against the other as the narrower slots left it, so two slots that\n * each look valid can still overflow together.\n */\nexport function namedPlacementOverflow(element: unknown): { slot: CascadeSlot; tracks: number } | undefined {\n\tconst carried: NamedPlacement = {};\n\tfor (const { slot, entry } of elementGridSlots(element)) {\n\t\tif (entry.width === undefined && entry.offset === undefined) continue;\n\t\tcarryNamedPlacement(carried, entry as NamedPlacement);\n\t\tif (carried.width === undefined || carried.offset === undefined) continue;\n\t\tconst tracks = (WIDTH_SPANS[carried.width] ?? 0) + (WIDTH_SPANS[carried.offset] ?? 0);\n\t\tif (tracks > WIDTH_TRACKS) return { slot, tracks };\n\t}\n\treturn undefined;\n}\n\n/** The cells of each row of a template; `.` marks an empty cell. */\nexport type GridAreaRows = readonly (readonly string[])[];\n\n/** Templates by the slot that sets them. */\nexport type GridAreaTemplates = Partial<Record<CascadeSlot, GridAreaRows>>;\n\nconst EMPTY_CELL = '.';\n\nfunction splitRow(row: unknown): string[] {\n\tif (typeof row !== 'string') return [];\n\treturn row\n\t\t.trim()\n\t\t.split(/\\s+/)\n\t\t.filter(Boolean)\n\t\t.map((cell) => (/^\\.+$/.test(cell) ? EMPTY_CELL : cell));\n}\n\nfunction toRows(rows: unknown): GridAreaRows | undefined {\n\treturn Array.isArray(rows) ? rows.map(splitRow) : undefined;\n}\n\n/**\n * The templates a grid's `areas` sets, by slot. An array is the `default` template.\n *\n * @remarks\n * A run of dots is one empty cell, normalised to a single `.`, so a template\n * compares and emits the same however the author spaced it.\n */\nexport function gridAreaTemplates(grid: unknown): GridAreaTemplates {\n\tif (!isRecord(grid) || grid.areas === undefined) return {};\n\tif (Array.isArray(grid.areas)) {\n\t\tconst rows = toRows(grid.areas);\n\t\treturn rows ? { default: rows } : {};\n\t}\n\tif (!isRecord(grid.areas)) return {};\n\tconst templates: GridAreaTemplates = {};\n\tfor (const slot of CASCADE_SLOTS) {\n\t\tconst rows = toRows(grid.areas[slot]);\n\t\tif (rows) templates[slot] = rows;\n\t}\n\treturn templates;\n}\n\n/** Whether a grid draws its layout with `areas`. */\nexport function gridUsesAreas(grid: unknown): boolean {\n\treturn Object.keys(gridAreaTemplates(grid)).length > 0;\n}\n\n/** Area names a template uses, in order of first appearance. */\nexport function areaNames(rows: GridAreaRows): string[] {\n\tconst names = new Set<string>();\n\tfor (const row of rows) {\n\t\tfor (const cell of row) if (cell !== EMPTY_CELL) names.add(cell);\n\t}\n\treturn [...names];\n}\n\n/** The `grid-template-areas` value for a template: one quoted string per row. */\nexport function areasTemplateValue(rows: GridAreaRows): string {\n\treturn rows.map((row) => `\"${row.join(' ')}\"`).join(' ');\n}\n\n/**\n * The area an element authored at each slot it sets one. Within a slot,\n * `responsive.default` beats the top level, as in emission.\n */\nexport function elementAreaSlots(element: unknown): Partial<Record<CascadeSlot, string>> {\n\tconst areas: Partial<Record<CascadeSlot, string>> = {};\n\tfor (const { slot, entry } of elementGridSlots(element)) {\n\t\tif (typeof entry.area === 'string') areas[slot] = entry.area;\n\t}\n\treturn areas;\n}\n\n/** Whether an element hides itself at each slot it sets `hidden`, in cascade order within a slot. */\nexport function elementHiddenSlots(element: unknown): Partial<Record<CascadeSlot, boolean>> {\n\tconst hidden: Partial<Record<CascadeSlot, boolean>> = {};\n\tfor (const { slot, entry } of elementGridSlots(element)) {\n\t\tif (typeof entry.hidden === 'boolean') hidden[slot] = entry.hidden;\n\t}\n\treturn hidden;\n}\n\n/**\n * What each slot resolves to: the value set at that slot, else the last one a\n * narrower slot set.\n *\n * @remarks\n * Emission falls back through narrower slots in the stylesheet, so validation\n * reads templates and areas the same way to check what a viewport gets.\n */\nexport function cascadeValues<T>(\n\tauthored: Partial<Record<CascadeSlot, T>>,\n): Array<{ slot: CascadeSlot; value: T | undefined }> {\n\tlet carried: T | undefined;\n\treturn CASCADE_SLOTS.map((slot) => {\n\t\tcarried = authored[slot] ?? carried;\n\t\treturn { slot, value: carried };\n\t});\n}\n\nfunction cellCount(count: number): string {\n\treturn `${count} ${count === 1 ? 'cell' : 'cells'}`;\n}\n\nfunction isRectangle(rows: GridAreaRows, name: string): boolean {\n\tconst cells: Array<[row: number, column: number]> = [];\n\trows.forEach((row, rowIndex) =>\n\t\trow.forEach((cell, columnIndex) => {\n\t\t\tif (cell === name) cells.push([rowIndex, columnIndex]);\n\t\t}),\n\t);\n\tconst rowsUsed = cells.map(([row]) => row);\n\tconst columnsUsed = cells.map(([, column]) => column);\n\tconst height = Math.max(...rowsUsed) - Math.min(...rowsUsed) + 1;\n\tconst width = Math.max(...columnsUsed) - Math.min(...columnsUsed) + 1;\n\treturn height * width === cells.length;\n}\n\n/**\n * Why CSS would drop a template: rows of unequal length, or an area whose cells\n * do not fill a rectangle.\n *\n * @param grid A grid config; one that sets no `areas` has no issue.\n *\n * @remarks\n * Each issue's `path` is relative to the grid: `['areas']` for the array form of the default\n * template, else `['areas', slot]`. Rows of unequal length stop the check for that template, as no\n * area can be located in a ragged one.\n */\nexport function areaTemplateIssues(grid: unknown): LayoutIssue[] {\n\tconst templates = gridAreaTemplates(grid);\n\tconst arrayForm = isRecord(grid) && Array.isArray(grid.areas);\n\tconst issues: LayoutIssue[] = [];\n\tfor (const slot of CASCADE_SLOTS) {\n\t\tconst rows = templates[slot];\n\t\tif (!rows) continue;\n\t\tconst path = arrayForm ? ['areas'] : ['areas', slot];\n\t\tconst width = rows[0]?.length ?? 0;\n\t\tconst ragged = rows.findIndex((row) => row.length !== width);\n\t\tif (ragged !== -1) {\n\t\t\tissues.push({\n\t\t\t\tpath,\n\t\t\t\tmessage: `row ${ragged + 1} has ${cellCount(rows[ragged]?.length ?? 0)} but row 1 has ${width}.`,\n\t\t\t});\n\t\t\tcontinue;\n\t\t}\n\t\tfor (const name of areaNames(rows)) {\n\t\t\tif (!isRectangle(rows, name)) {\n\t\t\t\tissues.push({\n\t\t\t\t\tpath,\n\t\t\t\t\tmessage: `area '${name}' is not rectangular; CSS drops the whole template unless every area fills a rectangle.`,\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\t}\n\treturn issues;\n}\n"],
5
+ "mappings": "AAYO,IAAMA,EAAmB,CAAC,KAAM,KAAM,KAAM,KAAM,KAAK,EAQjDC,EAAwC,CAAC,UAAW,GAAGD,CAAgB,EAGvEE,EAAe,GAEfC,EAAuD,CACnE,KAAM,GACN,iBAAkB,EAClB,aAAc,EACd,KAAM,EACN,MAAO,EACP,QAAS,CACV,EAQaC,EAAqB,CACjC,UACA,gBACD,EAQA,SAASC,EAASC,EAAkD,CACnE,OAAO,OAAOA,GAAU,UAAYA,IAAU,IAC/C,CAcO,SAASC,EAAiBC,EAAmC,CACnE,GAAI,CAACH,EAASG,CAAO,GAAK,CAACH,EAASG,EAAQ,IAAI,EAAG,MAAO,CAAC,EAC3D,IAAMC,EAAOD,EAAQ,KACfE,EAAyB,CAAC,CAAE,KAAM,UAAW,MAAOD,EAAM,KAAM,CAAC,MAAM,CAAE,CAAC,EAC1EE,EAAaF,EAAK,WACxB,GAAI,CAACJ,EAASM,CAAU,EAAG,OAAOD,EAClC,QAAWE,KAAQX,EAAe,CACjC,IAAMY,EAAQF,EAAWC,CAAI,EACzBP,EAASQ,CAAK,GAAGH,EAAM,KAAK,CAAE,KAAAE,EAAM,MAAAC,EAAO,KAAM,CAAC,OAAQ,aAAcD,CAAI,CAAE,CAAC,CACpF,CACA,OAAOF,CACR,CAGO,SAASI,EAAgBN,EAAuC,CACtE,IAAMO,EAAO,IAAI,IACjB,OAAW,CAAE,MAAAF,CAAM,IAAKN,EAAiBC,CAAO,EAC/C,OAAW,CAACQ,EAAKV,CAAK,IAAK,OAAO,QAAQO,CAAK,EAC1CG,IAAQ,cAAgBV,IAAU,QAAWS,EAAK,IAAIC,CAAG,EAG/D,OAAOD,CACR,CAEO,SAASE,EAAsBT,EAA2B,CAChE,IAAMO,EAAOD,EAAgBN,CAAO,EACpC,OAA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CAAG,EACnCqB,EAAcJ,EAAM,IAAI,CAAC,CAAC,CAAEK,CAAM,IAAMA,CAAM,EAC9CC,EAAS,KAAK,IAAI,GAAGH,CAAQ,EAAI,KAAK,IAAI,GAAGA,CAAQ,EAAI,EACzDI,EAAQ,KAAK,IAAI,GAAGH,CAAW,EAAI,KAAK,IAAI,GAAGA,CAAW,EAAI,EACpE,OAAOE,EAASC,IAAUP,EAAM,MACjC,CAaO,SAASQ,EAAmB3D,EAA8B,CAChE,IAAMuC,EAAYD,EAAkBtC,CAAI,EAClC4D,EAAYhE,EAASI,CAAI,GAAK,MAAM,QAAQA,EAAK,KAAK,EACtDuB,EAAwB,CAAC,EAC/B,QAAWpB,KAAQX,EAAe,CACjC,IAAM6C,EAAOE,EAAUpC,CAAI,EAC3B,GAAI,CAACkC,EAAM,SACX,IAAMvB,EAAO8C,EAAY,CAAC,OAAO,EAAI,CAAC,QAASzD,CAAI,EAC7CuD,EAAQrB,EAAK,CAAC,GAAG,QAAU,EAC3BwB,EAASxB,EAAK,UAAWH,GAAQA,EAAI,SAAWwB,CAAK,EAC3D,GAAIG,IAAW,GAAI,CAClBtC,EAAO,KAAK,CACX,KAAAT,EACA,QAAS,OAAO+C,EAAS,CAAC,QAAQb,EAAUX,EAAKwB,CAAM,GAAG,QAAU,CAAC,CAAC,kBAAkBH,CAAK,GAC9F,CAAC,EACD,QACD,CACA,QAAW3C,KAAQyB,EAAUH,CAAI,EAC3Ba,EAAYb,EAAMtB,CAAI,GAC1BQ,EAAO,KAAK,CACX,KAAAT,EACA,QAAS,SAASC,CAAI,yFACvB,CAAC,CAGJ,CACA,OAAOQ,CACR",
6
+ "names": ["BREAKPOINT_ORDER", "CASCADE_SLOTS", "WIDTH_TRACKS", "WIDTH_SPANS", "GRID_TEMPLATE_KEYS", "isRecord", "value", "elementGridSlots", "element", "grid", "slots", "responsive", "slot", "entry", "elementGridKeys", "keys", "key", "elementUsesGridWidths", "usesGridWidths", "elements", "elementIsSubgrid", "SUBGRID_EXCLUSIVE_KEYS", "subgridPlacementIssue", "path", "name", "SPAN_EXCLUSIVE_KEYS", "spanPlacementIssue", "gridSpanIssues", "gridUsesAreas", "columns", "autoSlots", "cascadeValues", "issues", "index", "placements", "offending", "spanPath", "carryNamedPlacement", "carried", "namedPlacementOverflow", "tracks", "EMPTY_CELL", "splitRow", "row", "cell", "toRows", "rows", "gridAreaTemplates", "templates", "areaNames", "names", "areasTemplateValue", "elementAreaSlots", "areas", "elementHiddenSlots", "hidden", "authored", "cellCount", "count", "isRectangle", "cells", "rowIndex", "columnIndex", "rowsUsed", "columnsUsed", "column", "height", "width", "areaTemplateIssues", "arrayForm", "ragged"]
7
7
  }
@@ -11,7 +11,7 @@ import { type GridBreakpointToken } from './grid-placement.js';
11
11
  *
12
12
  * Compile once, with the rest of the layout theme ({@link createLayoutTheme}); renderers
13
13
  * emit the resulting stylesheet and per-container CSS variables inline. Breakpoint
14
- * behavior lives entirely in the generated media queries — no runtime
14
+ * behavior lives entirely in generated media or container queries — no runtime
15
15
  * observers, and layout is correct with JavaScript disabled.
16
16
  *
17
17
  * Cascade contract for sparse responsive entries (see tests): initialize from
@@ -80,7 +80,25 @@ export interface GridThemeOptions {
80
80
  * ```
81
81
  */
82
82
  responsive?: Partial<Record<GridBreakpointToken, GridGapScale>>;
83
+ /**
84
+ * What the breakpoints measure: the viewport (`'media'`, the default) or the grid's own available width (`'container'`).
85
+ *
86
+ * @remarks
87
+ * Container mode emits `@container se-grid (min-width: ...)` where media mode emits `@media`, with
88
+ * the same breakpoint tokens, gap ramps and cascade, so a document reads the same in both. The
89
+ * rules query the nearest ancestor that carries {@link GRID_CONTAINER_CLASS}, which an element
90
+ * cannot be for its own children's placement: the renderer wraps each grid in one, and markup you
91
+ * write wraps each grid itself. A grid with no such ancestor never matches a breakpoint and keeps
92
+ * its base layout.
93
+ *
94
+ * The theme decides how breakpoints are queried and the document says what changes at each, so a
95
+ * document is unchanged by where it is mounted. In a container query `em` resolves against the
96
+ * container's font size.
97
+ */
98
+ query?: GridQueryMode;
83
99
  }
100
+ /** How a theme's breakpoints are queried; see {@link GridThemeOptions.query}. */
101
+ export type GridQueryMode = 'media' | 'container';
84
102
  /** Gap token values at one width. Unlisted tokens keep the value from the next narrower width. */
85
103
  export type GridGapScale = Partial<Record<GridGapToken, string>>;
86
104
  export interface NormalizedGridTheme {
@@ -89,6 +107,7 @@ export interface NormalizedGridTheme {
89
107
  /** Token overrides per breakpoint; only the tokens a width changes. */
90
108
  readonly responsive: Readonly<Partial<Record<GridBreakpointToken, Readonly<GridGapScale>>>>;
91
109
  readonly minColumnWidth: string;
110
+ readonly query: GridQueryMode;
92
111
  }
93
112
  /**
94
113
  * Resolves the immutable grid theme from the `grid` option of a layout theme.
@@ -97,12 +116,19 @@ export interface NormalizedGridTheme {
97
116
  * Threshold overrides replace only the named breakpoint; the rest keep
98
117
  * library defaults. Thresholds accept `px`/`rem`/`em` lengths and must
99
118
  * preserve named cascade order. `rem`/`em` compare at a 16px root.
100
- * Media queries follow viewport width — a grid inside a narrow sidebar
101
- * still receives the desktop rules of the wide screen it lives on.
119
+ * Media queries (the default `query`) follow viewport width — a grid inside a
120
+ * narrow sidebar still receives the desktop rules of the wide screen it lives
121
+ * on; `query: 'container'` follows the grid's wrapper instead.
102
122
  */
103
123
  export declare function resolveGridTheme(options?: GridThemeOptions): NormalizedGridTheme;
104
- /** The normalized grid theme in a stable shape, for hashing into a layout theme id. */
124
+ /**
125
+ * The normalized grid theme in a stable shape, for hashing into a layout theme id.
126
+ *
127
+ * @remarks
128
+ * The default query mode is left out, so a media theme keeps the id it had before the option existed.
129
+ */
105
130
  export declare function canonicalGridTheme(theme: NormalizedGridTheme): {
131
+ query?: "container" | undefined;
106
132
  breakpoints: Readonly<Record<"sm" | "md" | "lg" | "xl" | "2xl", string>>;
107
133
  gap: Readonly<Record<"default" | "none" | "compact" | "loose" | "wide", string>>;
108
134
  responsive: [string, [string, string][]][];
@@ -118,8 +144,46 @@ export declare function canonicalGridTheme(theme: NormalizedGridTheme): {
118
144
  * domain's own class.
119
145
  */
120
146
  export declare const GRID_CLASS = "se-grid";
121
- /** Class an element placed in a grid carries, and the stylesheet's hook for it. See {@link GRID_CLASS}. */
147
+ /**
148
+ * Class an element placed in a grid carries, and the stylesheet's hook for it. See {@link GRID_CLASS}.
149
+ *
150
+ * @remarks
151
+ * An item and the grid it contains must be different elements, as they are in both renderers. An item's
152
+ * `span` reads the track count its parent grid computed, and an element that is both would read its own.
153
+ */
122
154
  export declare const GRID_ITEM_CLASS = "se-grid-item";
155
+ /**
156
+ * Class of every box that passes its parent grid's column tracks down to a nested grid, and the stylesheet's hook for it.
157
+ *
158
+ * @remarks
159
+ * `grid-template-columns: subgrid` only works on a grid item of the grid whose tracks it takes, so the
160
+ * element with `grid.subgrid`, every box between it and the grid that lays out its children, and that
161
+ * {@link GRID_CLASS} grid itself must all carry this class. A box in the chain that does not (a plain
162
+ * `div`) computes its template to `none` and the children fall back to one column, with nothing reported.
163
+ *
164
+ * Keep a `<fieldset>` out of the chain: Chromium lays a fieldset's content out in an anonymous box that does
165
+ * not take the subgrid, so its children fall back to one column there (Firefox and WebKit pass the tracks on).
166
+ * Use a box with `role="group"` and `aria-labelledby` its heading instead, which gives the same group and name
167
+ * to assistive technology in every engine; `display: contents` on the fieldset is no answer, since engines expose
168
+ * its semantics inconsistently. The grid of the children gets no tracks of its own, so it takes no
169
+ * {@link GRID_CONTAINER_CLASS} wrapper either: layout containment would make it an independent formatting
170
+ * context, and a subgrid inside one is `none`. Its breakpoints are queried against the container of the grid
171
+ * the chain hangs from.
172
+ */
173
+ export declare const GRID_SUBGRID_CLASS = "se-subgrid";
174
+ /**
175
+ * Class of the element a grid in a `query: 'container'` theme is measured against, and the stylesheet's hook for it.
176
+ *
177
+ * @remarks
178
+ * Put it, with `data-se-theme`, on an element that wraps one grid and fills its parent: the
179
+ * breakpoints then follow that element's width. It must be an ancestor of the grid, because the
180
+ * template of a grid and the placement of its items have to query one box, and an element cannot
181
+ * query its own size. The stylesheet declares it only in container mode, as a block with
182
+ * `container-type: inline-size`. Inline-size containment means it no longer sizes to its content, so
183
+ * it collapses in a shrink-to-fit parent (an inline-block, a flex item without a basis, an `auto` grid
184
+ * track). Wrap each grid, nested grids included, so an inner grid follows its own box.
185
+ */
186
+ export declare const GRID_CONTAINER_CLASS = "se-grid-container";
123
187
  /**
124
188
  * Generates the theme-scoped stylesheet.
125
189
  *
@@ -132,6 +196,9 @@ export declare const GRID_ITEM_CLASS = "se-grid-item";
132
196
  *
133
197
  * Each responsive property is declared once, in the base rule, as a `var()` chain over the
134
198
  * slot gates ({@link gateName}); a media query only declares the gates of its slot.
199
+ * A `query: 'container'` theme changes the at-rule, to `@container se-grid`, adds the rule of
200
+ * {@link GRID_CONTAINER_CLASS} and resets each grid's and item's gates in its base rule
201
+ * ({@link gateResets}); a media theme emits neither.
135
202
  *
136
203
  * @param theme The resolved grid vocabulary.
137
204
  * @param themeId The id of the layout theme the rules are scoped to.
@@ -149,6 +216,9 @@ export declare function getGridThemeCss(theme: NormalizedGridTheme, themeId: str
149
216
  *
150
217
  * When `elements` (the items this grid places) use named widths, the grid
151
218
  * gets 12 tracks and a `1 / -1` default placement for items that set no width. Validation keeps that from meeting `columns`.
219
+ * The items include the children of every subgrid element, however deep, because a subgrid places
220
+ * them on this grid's tracks; a domain walks its children and passes them in. The grid of a subgrid
221
+ * has no tracks of its own, so its renderer does not call this.
152
222
  *
153
223
  * A grid with `areas` gets the template of each slot that sets one: the quoted
154
224
  * rows as `--se-grid-areas` and the track count they draw as `--se-grid-template`,
@@ -168,6 +238,10 @@ export declare function getGridVariables(grid: DeepReadonly<GridLayoutConfig> |
168
238
  * no inline style.
169
239
  * `placeSelf` is applied before the axis properties, so those win.
170
240
  *
241
+ * `subgrid` makes the element span `1 / -1`, its parent's whole row. It is the only placement a
242
+ * subgrid takes, so validation rejects the other column keys beside it, and the stylesheet does the rest
243
+ * under {@link GRID_SUBGRID_CLASS}.
244
+ *
171
245
  * `marginBlockStart`/`marginBlockEnd` accept the same gap tokens as the grid, so
172
246
  * a one-off rhythm around a non-input element reads in the same vocabulary as
173
247
  * the grid's spacing. They ride the shared item property table rather than a
@@ -1,2 +1,2 @@
1
- import*as t from"zod/mini";var m=["none","compact","default","loose","wide"],y=t.union([t.enum(m),t.string()]).check(t.describe("Semantic gap token (none | compact | default | loose | wide) or a raw CSS length.")),ae=["auto","span","none","default","inherit","initial","unset","revert","revert-layer"];function se(e){return e.split("").map(n=>/[a-z]/i.test(n)?`[${n.toLowerCase()}${n.toUpperCase()}]`:n).join("")}var R=`(?!(?:${ae.map(se).join("|")})(?![\\w-]))-?[_a-zA-Z][_a-zA-Z0-9-]*`,de=t.string().check(t.regex(new RegExp(`^${R}$`),'Area names are CSS identifiers such as "header" or "side-2".'),t.describe('Name of a cell group in the grid template: a CSS identifier such as "header" or "side-2".'));function B(e){return t.strictObject({default:t.optional(e),sm:t.optional(e),md:t.optional(e),lg:t.optional(e),xl:t.optional(e),"2xl":t.optional(e)})}function _(e){return t.optional(B(e))}var ce=t.string().check(t.regex(new RegExp(`^\\s*(?:\\.+|${R})(?:\\s+(?:\\.+|${R}))*\\s*$`),'A grid areas row lists area names (CSS identifiers) or "." for an empty cell, separated by spaces.')),I=t.array(ce).check(t.minLength(1)),le=t.union([I,B(I)]).check(t.describe('Rows of area names separated by spaces ("." is an empty cell), or a record of them per breakpoint (default, sm ... 2xl).')),O=t.strictObject({areas:t.optional(le),columns:t.optional(t.union([t.number(),t.literal("auto")])),gap:t.optional(y),gapX:t.optional(y),gapY:t.optional(y),minColumnWidth:t.optional(t.string()),justifyItems:t.optional(t.enum(["start","end","center","stretch"])),alignItems:t.optional(t.enum(["start","end","center","stretch"])),placeItems:t.optional(t.string()),justifyContent:t.optional(t.enum(["start","end","center","stretch","space-around","space-between","space-evenly"])),alignContent:t.optional(t.enum(["start","end","center","stretch","space-around","space-between","space-evenly"])),placeContent:t.optional(t.string())}),pe=t.pick(O,{columns:!0,gap:!0,gapX:!0,gapY:!0,minColumnWidth:!0}),ve=t.extend(O,{responsive:_(pe)}),v=["full","three-quarters","two-thirds","half","third","quarter"],j=["three-quarters","two-thirds","half","third","quarter"],L=t.strictObject({area:t.optional(de).check(t.describe("Name of the cell group this item fills in the grid areas template.")),width:t.optional(t.enum(v)).check(t.describe(`Named share of the row (${v.join(" | ")}).`)),offset:t.optional(t.enum(j)).check(t.describe(`Named empty space before the item (${j.join(" | ")}).`)),column:t.optional(t.union([t.number(),t.string()])),row:t.optional(t.union([t.number(),t.string()])),justifySelf:t.optional(t.enum(["start","end","center","stretch"])),alignSelf:t.optional(t.enum(["start","end","center","stretch"])),placeSelf:t.optional(t.string()),marginBlockStart:t.optional(y).check(t.describe("Extra space before this element, on top of the grid row gap.")),marginBlockEnd:t.optional(y).check(t.describe("Extra space after this element, on top of the grid row gap."))}),ue=t.extend(t.omit(L,{placeSelf:!0}),{hidden:t.optional(t.boolean())}),je=t.extend(L,{responsive:_(ue)});var l=["sm","md","lg","xl","2xl"],T=["default",...l],D=12,x={full:12,"three-quarters":9,"two-thirds":8,half:6,third:4,quarter:3};function g(e){return typeof e=="object"&&e!==null}function fe(e){if(!g(e)||!g(e.grid))return[];let n=e.grid,r=[{slot:"default",entry:n}],i=n.responsive;if(!g(i))return r;for(let o of T){let a=i[o];g(a)&&r.push({slot:o,entry:a})}return r}function me(e){let n=new Set;for(let{entry:r}of fe(e))for(let[i,o]of Object.entries(r))i!=="responsive"&&o!==void 0&&n.add(i);return n}function ge(e){let n=me(e);return n.has("width")||n.has("offset")}function M(e){return e.some(ge)}function V(e,n){e.width=n.width??e.width,e.offset=n.offset??e.offset}var he=".";function Ge(e){return typeof e!="string"?[]:e.trim().split(/\s+/).filter(Boolean).map(n=>/^\.+$/.test(n)?he:n)}function W(e){return Array.isArray(e)?e.map(Ge):void 0}function U(e){if(!g(e)||e.areas===void 0)return{};if(Array.isArray(e.areas)){let r=W(e.areas);return r?{default:r}:{}}if(!g(e.areas))return{};let n={};for(let r of T){let i=W(e.areas[r]);i&&(n[r]=i)}return n}function F(e){return e.map(n=>`"${n.join(" ")}"`).join(" ")}var ye={sm:"40rem",md:"48rem",lg:"64rem",xl:"80rem","2xl":"96rem"},ke={none:"0",compact:"0.5rem",default:"var(--space-stack, 1rem)",loose:"var(--space-block-lg, 1.5rem)",wide:"var(--space-block-xl, 2rem)"},Se="15.625rem",Te={none:"--se-grid-gap-none",compact:"--se-grid-gap-compact",default:"--se-grid-gap-default",loose:"--se-grid-gap-loose",wide:"--se-grid-gap-wide"};function E(e){return`--se-grid-gap-base-${e}`}function J(e){return`var(${Te[e]}, var(${E(e)}))`}var Y=J("default"),Q="--se-item-display-mode",ee=`var(${Q}, block)`,ne=16;function te(e){Object.freeze(e);for(let n of Object.values(e))n!==null&&typeof n=="object"&&!Object.isFrozen(n)&&te(n);return e}function ze(e){let n={};for(let r of l){let i=e?.[r],o=m.filter(a=>i?.[a]!==void 0);o.length>0&&(n[r]=Object.fromEntries(o.map(a=>[a,i[a]])))}return n}function We(e){let n={...ye,...e?.breakpoints},r={...ke,...e?.gap},i=ze(e?.responsive),o=e?.minColumnWidth??Se;return xe(n),te({breakpoints:n,gap:r,responsive:i,minColumnWidth:o})}function $e(e){return e==="px"||e==="rem"||e==="em"}function Re(e,n){let r=/^(\d+(?:\.\d+)?)(px|rem|em)$/.exec(n),i=r?.[2];if(!r||!$e(i))throw new Error(`Grid theme breakpoint '${e}' must be a px, rem, or em length; received '${n}'.`);let o=Number(r[1]);return i==="px"?o:o*ne}function xe(e){let n=Number.NEGATIVE_INFINITY,r;for(let i of l){let o=e[i],a=Re(i,o);if(r!==void 0&&a<n)throw new Error(`Grid theme breakpoints must preserve cascade order sm \u2264 md \u2264 lg \u2264 xl \u2264 2xl (rem/em compared at ${ne}px root); '${i}' (${o}) is smaller than '${r}' (${e[r]}).`);n=a,r=i}}function Ce(e){return l.flatMap(n=>{let r=e[n];if(!r)return[];let i=m.flatMap(o=>{let a=r[o];return a===void 0?[]:[[o,a]]});return[[n,i]]})}function De(e){return{breakpoints:e.breakpoints,gap:e.gap,responsive:Ce(e.responsive),minColumnWidth:e.minColumnWidth}}var be="se-grid",we="se-grid-item",C=[["grid-template-columns","se-grid-template","repeat(1, minmax(0, 1fr))"],["grid-template-areas","se-grid-areas","none"],["row-gap","se-grid-gap-y",Y],["column-gap","se-grid-gap-x",Y]],N="--se-grid-default-column",b=[["display","se-item-display",ee],["grid-column","se-item-grid-column",`var(${N}, auto)`],["grid-row","se-item-grid-row","auto"],["justify-self","se-item-justify-self","auto"],["align-self","se-item-align-self","auto"],["margin-block-start","se-item-margin-block-start","0"],["margin-block-end","se-item-margin-block-end","0"]],K=[["justify-items","se-grid-justify-items","normal"],["align-items","se-grid-align-items","normal"],["justify-content","se-grid-justify-content","normal"],["align-content","se-grid-align-content","start"]];function re(e){return e.replaceAll(", ",",")}function ie(e,n,r,i){return`--${e}-${n}${r}${i}`}function Ae(e,n,r,i,o){let a=`var(--${i},${re(o)})`;for(let u of l)a=`var(${ie(e,n,r,u)},${a})`;return a}function X(e,n,r){return r.map(([i,o,a],u)=>`${i}:${Ae(e,n,u,o,a)};`).join("")}function Ee(e){return e.map(([n,r,i])=>`${n}:var(--${r},${re(i)});`).join("")}function q(e,n,r,i){return r.map(([,o],a)=>`${ie(e,n,a,i)}:var(--${o}-${i});`).join("")}function w(e,n){return e.flatMap(([,r])=>[`--${r}`,...n?l.map(i=>`--${r}-${i}`):[]]).map(r=>`${r}:initial;`).join("")}function Me(e,n){let r=`[data-se-theme="${n}"]`,i=`.${be}${r}`,o=`.${we}${r}`,a=m.map(p=>`${E(p)}:${e.gap[p]};`).join(""),u=[`${r}{${a}}`,`${i}{${w(C,!0)}${w(K,!1)}${N}:initial;${Q}:initial;display:grid;${X(n,"g",C)}${Ee(K)}}`,`${o}{${w(b,!0)}${X(n,"i",b)}}`];for(let p of l){let h=e.responsive[p],G=h?m.filter(f=>h[f]!==void 0).map(f=>`${E(f)}:${h[f]};`).join(""):"";u.push(`@media (min-width:${e.breakpoints[p]}){${G?`${r}{${G}}`:""}${i}{${q(n,"g",C,p)}}${o}{${q(n,"i",b,p)}}}`)}return u.join(`
2
- `)}function Pe(e){for(let n of m)if(n===e)return!0;return!1}function k(e){if(e!==void 0)return Pe(e)?J(e):e}var Ne=new Set(["safe","unsafe","first","last"]);function P(e){if(e===void 0)return[void 0,void 0];let n=e.trim().split(/\s+/).filter(Boolean);if(n.length===0)return[void 0,void 0];let r=Ne.has(n[0])&&n.length>1?2:1,i=n.slice(0,r).join(" "),o=r<n.length?n.slice(r).join(" "):i;return[i,o]}function H(e,n){return e==="auto"?`repeat(auto-fit, minmax(min(${n}, 100%), 1fr))`:`repeat(${e}, minmax(0, 1fr))`}function s(e,n){return n==="default"?`--${e}`:`--${e}-${n}`}function A(e,n,r){if(!r)return;let i=k(r.gap),o=k(r.gapX)??i,a=k(r.gapY)??i;a!==void 0&&(e[s("se-grid-gap-y",n)]=a),o!==void 0&&(e[s("se-grid-gap-x",n)]=o)}function Ve(e,n,r){let i={},[o,a]=P(e?.placeItems),[u,p]=P(e?.placeContent),h={"--se-grid-justify-items":e?.justifyItems??a,"--se-grid-align-items":e?.alignItems??o,"--se-grid-justify-content":e?.justifyContent??p,"--se-grid-align-content":e?.alignContent??u};for(let[c,d]of Object.entries(h))d!==void 0&&(i[c]=d);let G=1,f=n.minColumnWidth,$=(c,d)=>{d&&(d.columns===void 0&&d.minColumnWidth===void 0||(d.columns!==void 0&&(G=d.columns),d.minColumnWidth!==void 0&&(f=d.minColumnWidth),i[s("se-grid-template",c)]=H(G,f)))};M(r)&&(i["--se-grid-template"]=`repeat(${D}, minmax(0, 1fr))`,i[N]="1 / -1");let oe=U(e);for(let c of T){let d=oe[c];d&&(i[s("se-grid-areas",c)]=F(d),i[s("se-grid-template",c)]=H(d[0]?.length??1,n.minColumnWidth))}let S=e?.responsive;$("default",e),$("default",S?.default),A(i,"default",e),A(i,"default",S?.default);for(let c of l)$(c,S?.[c]),A(i,c,S?.[c]);return i}function Ie({width:e,offset:n}){let r=n===void 0?void 0:x[n]+1;if(e===void 0)return r===void 0?"auto":`${r} / -1`;let i=`span ${x[e]}`;return r===void 0?i:`${r} / ${i}`}function Z(e){return typeof e=="number"?String(e):e}function z(e,n,r,i={}){if(!r)return;(r.width!==void 0||r.offset!==void 0)&&(V(i,r),e[s("se-item-grid-column",n)]=Ie(i)),r.area!==void 0&&(e[s("se-item-grid-column",n)]=r.area,e[s("se-item-grid-row",n)]=r.area),r.column!==void 0&&(e[s("se-item-grid-column",n)]=Z(r.column)),r.row!==void 0&&(e[s("se-item-grid-row",n)]=Z(r.row)),r.justifySelf!==void 0&&(e[s("se-item-justify-self",n)]=r.justifySelf),r.alignSelf!==void 0&&(e[s("se-item-align-self",n)]=r.alignSelf);let o=k(r.marginBlockStart);o!==void 0&&(e[s("se-item-margin-block-start",n)]=o);let a=k(r.marginBlockEnd);a!==void 0&&(e[s("se-item-margin-block-end",n)]=a),r.hidden!==void 0&&(e[s("se-item-display",n)]=r.hidden?"none":ee)}function Ue(e){let n={},[r,i]=P(e?.placeSelf),o={};z(n,"default",{alignSelf:r,justifySelf:i}),z(n,"default",e,o),z(n,"default",e?.responsive?.default,o);for(let a of l)z(n,a,e?.responsive?.[a],o);return n}export{be as GRID_CLASS,we as GRID_ITEM_CLASS,De as canonicalGridTheme,Ue as getGridItemVariables,Me as getGridThemeCss,Ve as getGridVariables,We as resolveGridTheme};
1
+ import*as t from"zod/mini";var h=["none","compact","default","loose","wide"],k=t.union([t.enum(h),t.string()]).check(t.describe("Semantic gap token (none | compact | default | loose | wide) or a raw CSS length.")),ue=["auto","span","none","default","inherit","initial","unset","revert","revert-layer"];function pe(e){return e.split("").map(n=>/[a-z]/i.test(n)?`[${n.toLowerCase()}${n.toUpperCase()}]`:n).join("")}var x=`(?!(?:${ue.map(pe).join("|")})(?![\\w-]))-?[_a-zA-Z][_a-zA-Z0-9-]*`,fe=t.string().check(t.regex(new RegExp(`^${x}$`),'Area names are CSS identifiers such as "header" or "side-2".'),t.describe('Name of a cell group in the grid template: a CSS identifier such as "header" or "side-2".'));function W(e){return t.strictObject({default:t.optional(e),sm:t.optional(e),md:t.optional(e),lg:t.optional(e),xl:t.optional(e),"2xl":t.optional(e)})}function M(e){return t.optional(W(e))}var me=t.string().check(t.regex(new RegExp(`^\\s*(?:\\.+|${x})(?:\\s+(?:\\.+|${x}))*\\s*$`),'A grid areas row lists area names (CSS identifiers) or "." for an empty cell, separated by spaces.')),L=t.array(me).check(t.minLength(1)),ge=t.union([L,W(L)]).check(t.describe('Rows of area names separated by spaces ("." is an empty cell), or a record of them per breakpoint (default, sm ... 2xl).')),V=t.strictObject({areas:t.optional(ge),columns:t.optional(t.union([t.int().check(t.positive()),t.literal("auto")])),gap:t.optional(k),gapX:t.optional(k),gapY:t.optional(k),minColumnWidth:t.optional(t.string()),justifyItems:t.optional(t.enum(["start","end","center","stretch"])),alignItems:t.optional(t.enum(["start","end","center","stretch"])),placeItems:t.optional(t.string()),justifyContent:t.optional(t.enum(["start","end","center","stretch","space-around","space-between","space-evenly"])),alignContent:t.optional(t.enum(["start","end","center","stretch","space-around","space-between","space-evenly"])),placeContent:t.optional(t.string()),autoFlow:t.optional(t.enum(["row","dense"])).check(t.describe("How items without a position fill the tracks: 'row' in source order, 'dense' backfills earlier gaps with later, smaller items. Dense changes the visual order, not the DOM or focus order. Top level only."))}),he=t.pick(V,{columns:!0,gap:!0,gapX:!0,gapY:!0,minColumnWidth:!0}),We=t.extend(V,{responsive:M(he)}),O=["full","three-quarters","two-thirds","half","third","quarter"],D=["three-quarters","two-thirds","half","third","quarter"],U=t.strictObject({area:t.optional(fe).check(t.describe("Name of the cell group this item fills in the grid areas template.")),width:t.optional(t.enum(O)).check(t.describe(`Named share of the row (${O.join(" | ")}).`)),offset:t.optional(t.enum(D)).check(t.describe(`Named empty space before the item (${D.join(" | ")}).`)),span:t.optional(t.int().check(t.positive())).check(t.describe('Number of tracks to span, never more than the grid has. Needs a grid with a known track count, so not `columns: "auto"`.')),column:t.optional(t.union([t.number(),t.string()])),row:t.optional(t.union([t.number(),t.string()])),justifySelf:t.optional(t.enum(["start","end","center","stretch"])),alignSelf:t.optional(t.enum(["start","end","center","stretch"])),placeSelf:t.optional(t.string()),subgrid:t.optional(t.boolean()).check(t.describe("Spans the parent grid's full row and lays this element's children on the parent's column tracks and gap. Set on a container element, never per breakpoint.")),marginBlockStart:t.optional(k).check(t.describe("Extra space before this element, on top of the grid row gap.")),marginBlockEnd:t.optional(k).check(t.describe("Extra space after this element, on top of the grid row gap."))}),ye=t.extend(t.omit(U,{placeSelf:!0,subgrid:!0}),{hidden:t.optional(t.boolean())}),Me=t.extend(U,{responsive:M(ye)});var l=["sm","md","lg","xl","2xl"],w=["default",...l],E=12,A={full:12,"three-quarters":9,"two-thirds":8,half:6,third:4,quarter:3};function G(e){return typeof e=="object"&&e!==null}function Ge(e){if(!G(e)||!G(e.grid))return[];let n=e.grid,r=[{slot:"default",entry:n,path:["grid"]}],o=n.responsive;if(!G(o))return r;for(let i of w){let a=o[i];G(a)&&r.push({slot:i,entry:a,path:["grid","responsive",i]})}return r}function ke(e){let n=new Set;for(let{entry:r}of Ge(e))for(let[o,i]of Object.entries(r))o!=="responsive"&&i!==void 0&&n.add(o);return n}function Se(e){let n=ke(e);return n.has("width")||n.has("offset")}function F(e){return e.some(Se)}function K(e,n){e.width=n.width??e.width,e.offset=n.offset??e.offset}var $e=".";function we(e){return typeof e!="string"?[]:e.trim().split(/\s+/).filter(Boolean).map(n=>/^\.+$/.test(n)?$e:n)}function q(e){return Array.isArray(e)?e.map(we):void 0}function Y(e){if(!G(e)||e.areas===void 0)return{};if(Array.isArray(e.areas)){let r=q(e.areas);return r?{default:r}:{}}if(!G(e.areas))return{};let n={};for(let r of w){let o=q(e.areas[r]);o&&(n[r]=o)}return n}function X(e){return e.map(n=>`"${n.join(" ")}"`).join(" ")}var be={sm:"40rem",md:"48rem",lg:"64rem",xl:"80rem","2xl":"96rem"},ze={none:"0",compact:"0.5rem",default:"var(--space-stack, 1rem)",loose:"var(--space-block-lg, 1.5rem)",wide:"var(--space-block-xl, 2rem)"},Re="15.625rem",Te={none:"--se-grid-gap-none",compact:"--se-grid-gap-compact",default:"--se-grid-gap-default",loose:"--se-grid-gap-loose",wide:"--se-grid-gap-wide"};function N(e){return`--se-grid-gap-base-${e}`}function ae(e){return`var(${Te[e]}, var(${N(e)}))`}var H=ae("default"),v="--se-item-display-mode",se=`var(${v}, block)`,de=16;function ce(e){Object.freeze(e);for(let n of Object.values(e))n!==null&&typeof n=="object"&&!Object.isFrozen(n)&&ce(n);return e}function Ce(e){let n={};for(let r of l){let o=e?.[r],i=h.filter(a=>o?.[a]!==void 0);i.length>0&&(n[r]=Object.fromEntries(i.map(a=>[a,o[a]])))}return n}function Ke(e){let n={...be,...e?.breakpoints},r={...ze,...e?.gap},o=Ce(e?.responsive),i=e?.minColumnWidth??Re,a=e?.query??"media";return Pe(n),xe(a),ce({breakpoints:n,gap:r,responsive:o,minColumnWidth:i,query:a})}function xe(e){if(e!=="media"&&e!=="container")throw new Error(`Grid theme query must be 'media' or 'container'; received '${e}'.`)}function Ee(e){return e==="px"||e==="rem"||e==="em"}function Ae(e,n){let r=/^(\d+(?:\.\d+)?)(px|rem|em)$/.exec(n),o=r?.[2];if(!r||!Ee(o))throw new Error(`Grid theme breakpoint '${e}' must be a px, rem, or em length; received '${n}'.`);let i=Number(r[1]);return o==="px"?i:i*de}function Pe(e){let n=Number.NEGATIVE_INFINITY,r;for(let o of l){let i=e[o],a=Ae(o,i);if(r!==void 0&&a<n)throw new Error(`Grid theme breakpoints must preserve cascade order sm \u2264 md \u2264 lg \u2264 xl \u2264 2xl (rem/em compared at ${de}px root); '${o}' (${i}) is smaller than '${r}' (${e[r]}).`);n=a,r=o}}function Ie(e){return l.flatMap(n=>{let r=e[n];if(!r)return[];let o=h.flatMap(i=>{let a=r[i];return a===void 0?[]:[[i,a]]});return[[n,o]]})}function Ye(e){return{breakpoints:e.breakpoints,gap:e.gap,responsive:Ie(e.responsive),minColumnWidth:e.minColumnWidth,...e.query==="media"?{}:{query:e.query}}}var Q="se-grid",Z="se-grid-item",Ne="se-subgrid",ve="se-grid-container",J="se-grid",j="--se-grid-track-count",b=[["grid-template-columns","se-grid-template","repeat(1, minmax(0, 1fr))"],["grid-template-areas","se-grid-areas","none"],["row-gap","se-grid-gap-y",H],["column-gap","se-grid-gap-x",H],[j,"se-grid-tracks","1"]],T="--se-grid-default-column",z=[["display","se-item-display",se],["grid-column","se-item-grid-column",`var(${T}, auto)`],["grid-row","se-item-grid-row","auto"],["justify-self","se-item-justify-self","auto"],["align-self","se-item-align-self","auto"],["margin-block-start","se-item-margin-block-start","0"],["margin-block-end","se-item-margin-block-end","0"]],ee=[["justify-items","se-grid-justify-items","normal"],["align-items","se-grid-align-items","normal"],["justify-content","se-grid-justify-content","normal"],["align-content","se-grid-align-content","start"],["grid-auto-flow","se-grid-auto-flow","row"]];function le(e){return e.replaceAll(", ",",")}function B(e,n,r,o){return`--${e}-${n}${r}${o}`}function _e(e,n,r,o,i){let a=`var(--${o},${le(i)})`;for(let f of l)a=`var(${B(e,n,r,f)},${a})`;return a}function ne(e,n,r){return r.map(([o,i,a],f)=>`${o}:${_e(e,n,f,i,a)};`).join("")}function je(e){return e.map(([n,r,o])=>`${n}:var(--${r},${le(o)});`).join("")}function te(e,n,r,o){return r.map(([,i],a)=>`${B(e,n,a,o)}:var(--${i}-${o});`).join("")}function P(e,n){return e.flatMap(([,r])=>[`--${r}`,...n?l.map(o=>`--${r}-${o}`):[]]).map(r=>`${r}:initial;`).join("")}function re(e,n,r){return r.flatMap((o,i)=>l.map(a=>`${B(e,n,i,a)}:initial;`)).join("")}function Xe(e,n){let r=`[data-se-theme="${n}"]`,o=`.${Q}${r}`,i=`.${Z}${r}`,a=`.${Ne}${r}`,f=h.map(u=>`${N(u)}:${e.gap[u]};`).join(""),y=e.query==="container",C=y?`@container ${J}`:"@media",m=[`${r}{${f}}`,...y?[`.${ve}${r}{display:block;width:100%;min-width:0;container-type:inline-size;container-name:${J};}`]:[],`${a}{${v}:grid;display:grid;grid-template-columns:subgrid;column-gap:normal;align-content:start;}`,`${a}>:not(.${Z}){grid-column:1/-1;}`,`${o}{${y?re(n,"g",b):""}${P(b,!0)}${P(ee,!1)}${T}:initial;${v}:initial;display:grid;${ne(n,"g",b)}${je(ee)}}`,`.${Q}${a}{--se-grid-template:subgrid;--se-grid-gap-x:normal;${T}:inherit;${j}:inherit;}`,`${i}{${y?re(n,"i",z):""}${P(z,!0)}${ne(n,"i",z)}}`];for(let u of l){let g=e.responsive[u],$=g?h.filter(p=>g[p]!==void 0).map(p=>`${N(p)}:${g[p]};`).join(""):"";m.push(`${C} (min-width:${e.breakpoints[u]}){${$?`${r}{${$}}`:""}${o}{${te(n,"g",b,u)}}${i}{${te(n,"i",z,u)}}}`)}return m.join(`
2
+ `)}function Be(e){for(let n of h)if(n===e)return!0;return!1}function S(e){if(e!==void 0)return Be(e)?ae(e):e}var Le=new Set(["safe","unsafe","first","last"]);function _(e){if(e===void 0)return[void 0,void 0];let n=e.trim().split(/\s+/).filter(Boolean);if(n.length===0)return[void 0,void 0];let r=Le.has(n[0])&&n.length>1?2:1,o=n.slice(0,r).join(" "),i=r<n.length?n.slice(r).join(" "):o;return[o,i]}function oe(e,n){return e==="auto"?`repeat(auto-fit, minmax(min(${n}, 100%), 1fr))`:`repeat(${e}, minmax(0, 1fr))`}function s(e,n){return n==="default"?`--${e}`:`--${e}-${n}`}function I(e,n,r){if(!r)return;let o=S(r.gap),i=S(r.gapX)??o,a=S(r.gapY)??o;a!==void 0&&(e[s("se-grid-gap-y",n)]=a),i!==void 0&&(e[s("se-grid-gap-x",n)]=i)}function He(e,n,r){let o={},[i,a]=_(e?.placeItems),[f,y]=_(e?.placeContent),C={"--se-grid-justify-items":e?.justifyItems??a,"--se-grid-align-items":e?.alignItems??i,"--se-grid-justify-content":e?.justifyContent??y,"--se-grid-align-content":e?.alignContent??f,"--se-grid-auto-flow":e?.autoFlow};for(let[c,d]of Object.entries(C))d!==void 0&&(o[c]=d);let m=1,u=n.minColumnWidth,g=(c,d)=>{d&&(d.columns===void 0&&d.minColumnWidth===void 0||(d.columns!==void 0&&(m=d.columns),d.minColumnWidth!==void 0&&(u=d.minColumnWidth),o[s("se-grid-template",c)]=oe(m,u),o[s("se-grid-tracks",c)]=String(m==="auto"?1:m)))};F(r)&&(o["--se-grid-template"]=`repeat(${E}, minmax(0, 1fr))`,o["--se-grid-tracks"]=String(E),o[T]="1 / -1");let $=Y(e);for(let c of w){let d=$[c];d&&(o[s("se-grid-areas",c)]=X(d),o[s("se-grid-template",c)]=oe(d[0]?.length??1,n.minColumnWidth),o[s("se-grid-tracks",c)]=String(d[0]?.length??1))}let p=e?.responsive;g("default",e),g("default",p?.default),I(o,"default",e),I(o,"default",p?.default);for(let c of l)g(c,p?.[c]),I(o,c,p?.[c]);return o}function Oe({width:e,offset:n}){let r=n===void 0?void 0:A[n]+1;if(e===void 0)return r===void 0?"auto":`${r} / -1`;let o=`span ${A[e]}`;return r===void 0?o:`${r} / ${o}`}function De(e){return`span min(${e},var(${j},1))`}function ie(e){return typeof e=="number"?String(e):e}function R(e,n,r,o={}){if(!r)return;(r.width!==void 0||r.offset!==void 0)&&(K(o,r),e[s("se-item-grid-column",n)]=Oe(o)),r.span!==void 0&&(e[s("se-item-grid-column",n)]=De(r.span)),r.area!==void 0&&(e[s("se-item-grid-column",n)]=r.area,e[s("se-item-grid-row",n)]=r.area),r.column!==void 0&&(e[s("se-item-grid-column",n)]=ie(r.column)),r.row!==void 0&&(e[s("se-item-grid-row",n)]=ie(r.row)),r.justifySelf!==void 0&&(e[s("se-item-justify-self",n)]=r.justifySelf),r.alignSelf!==void 0&&(e[s("se-item-align-self",n)]=r.alignSelf);let i=S(r.marginBlockStart);i!==void 0&&(e[s("se-item-margin-block-start",n)]=i);let a=S(r.marginBlockEnd);a!==void 0&&(e[s("se-item-margin-block-end",n)]=a),r.hidden!==void 0&&(e[s("se-item-display",n)]=r.hidden?"none":se)}function Qe(e){let n={},[r,o]=_(e?.placeSelf);e?.subgrid&&(n["--se-item-grid-column"]="1 / -1");let i={};R(n,"default",{alignSelf:r,justifySelf:o}),R(n,"default",e,i),R(n,"default",e?.responsive?.default,i);for(let a of l)R(n,a,e?.responsive?.[a],i);return n}export{Q as GRID_CLASS,ve as GRID_CONTAINER_CLASS,Z as GRID_ITEM_CLASS,Ne as GRID_SUBGRID_CLASS,Ye as canonicalGridTheme,Qe as getGridItemVariables,Xe as getGridThemeCss,He as getGridVariables,Ke as resolveGridTheme};