@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.
- package/README.md +10 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.js +4 -4
- package/dist/index.js.map +4 -4
- package/dist/lib/grid-placement.d.ts +51 -4
- package/dist/lib/grid-placement.js +1 -1
- package/dist/lib/grid-placement.js.map +3 -3
- package/dist/lib/grid-styles.d.ts +79 -5
- package/dist/lib/grid-styles.js +2 -2
- package/dist/lib/grid-styles.js.map +3 -3
- package/dist/lib/layout-theme.js +4 -4
- package/dist/lib/layout-theme.js.map +3 -3
- package/dist/recipes/bind-recipe.d.ts +3 -3
- package/dist/recipes/bind-recipe.js +1 -1
- package/dist/recipes/bind-recipe.js.map +2 -2
- package/dist/recipes/define-recipe-spec.d.ts +37 -13
- package/dist/recipes/define-recipe-spec.js +1 -1
- package/dist/recipes/define-recipe-spec.js.map +4 -4
- package/dist/recipes/protocol.d.ts +5 -2
- package/dist/recipes/protocol.js +1 -1
- package/dist/recipes/protocol.js.map +3 -3
- package/dist/recipes/resolve-recipe-view.d.ts +2 -0
- package/dist/recipes/resolve-recipe-view.js +1 -1
- package/dist/recipes/resolve-recipe-view.js.map +4 -4
- package/dist/recipes/types.d.ts +21 -6
- package/dist/recipes/view-model.d.ts +2 -2
- package/dist/recipes/view-model.js +1 -1
- package/dist/recipes/view-model.js.map +2 -2
- package/dist/schemas/grid.d.ts +28 -15
- package/dist/schemas/grid.js +1 -1
- package/dist/schemas/grid.js.map +2 -2
- package/package.json +5 -2
- package/skill/SKILL.md +26 -25
- package/skill/reference/layout.md +61 -2
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/schemas/grid.ts", "../../src/lib/grid-placement.ts", "../../src/lib/grid-styles.ts"],
|
|
4
|
-
"sourcesContent": ["import * as z from 'zod/mini';\n\n/**\n * Semantic gap tokens for grid layouts.\n *\n * @remarks\n * Tokens are indirections to overridable CSS variables: the renderer emits\n * `var(--se-grid-gap-<token>)`, so hosts restyle every grid by overriding the\n * token at `:root`. Raw CSS strings (e.g. `'1.5rem'`) are the one-off escape\n * hatch.\n */\nexport const GridGapTokens = ['none', 'compact', 'default', 'loose', 'wide'] as const;\n\nexport type GridGapToken = (typeof GridGapTokens)[number];\n\n/**\n * Semantic gap token or a raw CSS length.\n *\n * @remarks\n * The enum branch is redundant for validation \u2014 the string branch accepts the\n * same values \u2014 and `z.infer` collapses the union to `string`. It is kept\n * because `z.toJSONSchema` emits it as `anyOf: [{enum: [...]}, {type: string}]`,\n * which is how the token vocabulary reaches registry and docs consumers.\n */\nexport const GridGapValueSchema = z\n\t.union([z.enum(GridGapTokens), z.string()])\n\t.check(z.describe('Semantic gap token (none | compact | default | loose | wide) or a raw CSS length.'));\n\n/**\n * Words that are not valid grid area names: `grid-area` reads `auto` and `span`\n * as placement keywords, the CSS-wide keywords reset a declaration, and `none`\n * and `default` are excluded from a `<custom-ident>` by the CSS grammar.\n */\nconst RESERVED_AREA_NAMES = [\n\t'auto',\n\t'span',\n\t'none',\n\t'default',\n\t'inherit',\n\t'initial',\n\t'unset',\n\t'revert',\n\t'revert-layer',\n];\n\n/**\n * A word as a pattern that matches it in any letter case.\n *\n * @remarks\n * Spelled with character classes instead of an `i` flag because the JSON Schema\n * export keeps only a regex's source, so a flag would be lost and editors would\n * accept `AUTO` and reject `Street`.\n */\nfunction anyCase(word: string): string {\n\treturn word\n\t\t.split('')\n\t\t.map((char) => (/[a-z]/i.test(char) ? `[${char.toLowerCase()}${char.toUpperCase()}]` : char))\n\t\t.join('');\n}\n\nconst AREA_NAME_SOURCE = `(?!(?:${RESERVED_AREA_NAMES.map(anyCase).join('|')})(?![\\\\w-]))-?[_a-zA-Z][_a-zA-Z0-9-]*`;\n\n/**\n * Name of a grid area: an ASCII CSS identifier that is not a reserved word.\n *\n * @remarks\n * Names are written into a custom property that the stylesheet reads as CSS, so\n * the pattern is the injection guard. Nothing outside `[A-Za-z0-9_-]` can reach the\n * property, which rules out quotes, semicolons, braces and whitespace.\n */\nconst GridAreaNameSchema = z\n\t.string()\n\t.check(\n\t\tz.regex(new RegExp(`^${AREA_NAME_SOURCE}$`), 'Area names are CSS identifiers such as \"header\" or \"side-2\".'),\n\t\tz.describe('Name of a cell group in the grid template: a CSS identifier such as \"header\" or \"side-2\".'),\n\t);\n\n/** A value per cascade slot (`default`, `sm` ... `2xl`), each optional. */\nfunction perBreakpoint<T extends z.ZodMiniType>(schema: T) {\n\treturn z.strictObject({\n\t\tdefault: z.optional(schema),\n\t\tsm: z.optional(schema),\n\t\tmd: z.optional(schema),\n\t\tlg: z.optional(schema),\n\t\txl: z.optional(schema),\n\t\t'2xl': z.optional(schema),\n\t});\n}\n\nfunction responsiveSchema<T extends z.ZodMiniType>(schema: T) {\n\treturn z.optional(perBreakpoint(schema));\n}\n\n/** One row of a template: area names or `.` for an empty cell, separated by spaces. */\nconst GridAreaRowSchema = z\n\t.string()\n\t.check(\n\t\tz.regex(\n\t\t\tnew RegExp(`^\\\\s*(?:\\\\.+|${AREA_NAME_SOURCE})(?:\\\\s+(?:\\\\.+|${AREA_NAME_SOURCE}))*\\\\s*$`),\n\t\t\t'A grid areas row lists area names (CSS identifiers) or \".\" for an empty cell, separated by spaces.',\n\t\t),\n\t);\n\nconst GridAreaRowsSchema = z.array(GridAreaRowSchema).check(z.minLength(1));\n\n/**\n * A drawn layout: rows of area names, optionally per breakpoint.\n *\n * @remarks\n * The column count comes from the rows, so a grid with `areas` sets no\n * `columns`. Rows of one template must be the same length and each name must\n * fill a rectangle; the domain validator checks both, as CSS drops a template that\n * breaks either.\n */\nconst GridAreasSchema = z\n\t.union([GridAreaRowsSchema, perBreakpoint(GridAreaRowsSchema)])\n\t.check(\n\t\tz.describe(\n\t\t\t'Rows of area names separated by spaces (\".\" is an empty cell), or a record of them per breakpoint (default, sm ... 2xl).',\n\t\t),\n\t);\n\nconst GridLayoutPropertiesSchema = z.strictObject({\n\tareas: z.optional(GridAreasSchema),\n\tcolumns: z.optional(z.union([z.number(), z.literal('auto')])),\n\tgap: z.optional(GridGapValueSchema),\n\tgapX: z.optional(GridGapValueSchema),\n\tgapY: z.optional(GridGapValueSchema),\n\tminColumnWidth: z.optional(z.string()),\n\tjustifyItems: z.optional(z.enum(['start', 'end', 'center', 'stretch'])),\n\talignItems: z.optional(z.enum(['start', 'end', 'center', 'stretch'])),\n\tplaceItems: z.optional(z.string()),\n\tjustifyContent: z.optional(\n\t\tz.enum(['start', 'end', 'center', 'stretch', 'space-around', 'space-between', 'space-evenly']),\n\t),\n\talignContent: z.optional(\n\t\tz.enum(['start', 'end', 'center', 'stretch', 'space-around', 'space-between', 'space-evenly']),\n\t),\n\tplaceContent: z.optional(z.string()),\n});\n\nexport const GridBreakpointConfigSchema = z.pick(GridLayoutPropertiesSchema, {\n\tcolumns: true,\n\tgap: true,\n\tgapX: true,\n\tgapY: true,\n\tminColumnWidth: true,\n});\n\nexport const GridLayoutConfigSchema = z.extend(GridLayoutPropertiesSchema, {\n\tresponsive: responsiveSchema(GridBreakpointConfigSchema),\n});\n\n/**\n * Named item widths, as shares of the row.\n *\n * @remarks\n * A grid whose items use `width` or `offset` is laid out on 12 tracks, so\n * every name is a whole number of tracks: `full` 12, `three-quarters` 9,\n * `two-thirds` 8, `half` 6, `third` 4, `quarter` 3. An item that sets no width\n * fills the row.\n */\nexport const GridWidthNames = ['full', 'three-quarters', 'two-thirds', 'half', 'third', 'quarter'] as const;\n\nexport type GridWidthName = (typeof GridWidthNames)[number];\n\n/** Named offsets: the widths that are a fraction of the row, without `full`. */\nexport const GridOffsetNames = ['three-quarters', 'two-thirds', 'half', 'third', 'quarter'] as const;\n\nexport type GridOffsetName = (typeof GridOffsetNames)[number];\n\nconst ElementGridPropertiesSchema = z.strictObject({\n\tarea: z\n\t\t.optional(GridAreaNameSchema)\n\t\t.check(z.describe('Name of the cell group this item fills in the grid areas template.')),\n\twidth: z\n\t\t.optional(z.enum(GridWidthNames))\n\t\t.check(z.describe(`Named share of the row (${GridWidthNames.join(' | ')}).`)),\n\toffset: z\n\t\t.optional(z.enum(GridOffsetNames))\n\t\t.check(z.describe(`Named empty space before the item (${GridOffsetNames.join(' | ')}).`)),\n\tcolumn: z.optional(z.union([z.number(), z.string()])),\n\trow: z.optional(z.union([z.number(), z.string()])),\n\tjustifySelf: z.optional(z.enum(['start', 'end', 'center', 'stretch'])),\n\talignSelf: z.optional(z.enum(['start', 'end', 'center', 'stretch'])),\n\tplaceSelf: z.optional(z.string()),\n\tmarginBlockStart: z\n\t\t.optional(GridGapValueSchema)\n\t\t.check(z.describe('Extra space before this element, on top of the grid row gap.')),\n\tmarginBlockEnd: z\n\t\t.optional(GridGapValueSchema)\n\t\t.check(z.describe('Extra space after this element, on top of the grid row gap.')),\n});\n\nexport const ItemGridBreakpointSchema = z.extend(z.omit(ElementGridPropertiesSchema, { placeSelf: true }), {\n\thidden: z.optional(z.boolean()),\n});\n\nexport const ElementGridConfigSchema = z.extend(ElementGridPropertiesSchema, {\n\tresponsive: responsiveSchema(ItemGridBreakpointSchema),\n});\n\nexport type GridBreakpointConfig = z.infer<typeof GridBreakpointConfigSchema>;\nexport type ItemGridBreakpointConfig = z.infer<typeof ItemGridBreakpointSchema>;\nexport type ElementGridConfig = z.infer<typeof ElementGridConfigSchema>;\nexport type GridLayoutConfig = z.infer<typeof GridLayoutConfigSchema>;\n", "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", "import type { ElementGridConfig, GridGapToken, GridLayoutConfig, GridOffsetName, GridWidthName } from '@/schemas/grid';\nimport type { DeepReadonly } from '@/lib/deep-readonly';\nimport { GridGapTokens } from '@/schemas/grid';\nimport {\n\tareasTemplateValue,\n\tBREAKPOINT_ORDER,\n\tcarryNamedPlacement,\n\tCASCADE_SLOTS,\n\tgridAreaTemplates,\n\tusesGridWidths,\n\tWIDTH_SPANS,\n\tWIDTH_TRACKS,\n\ttype CascadeSlot,\n\ttype GridBreakpointToken,\n\ttype NamedPlacement,\n} from '@/lib/grid-placement';\n\n/**\n * Maps authored grid values to theme-scoped CSS variables.\n *\n * @remarks\n * The theme owns the grid vocabulary: breakpoint thresholds, gap tokens,\n * and the default minimum column width. The document owns layout intent:\n * columns, responsive changes, gap selection, item placement.\n *\n * Compile once, with the rest of the layout theme ({@link createLayoutTheme}); renderers\n * emit the resulting stylesheet and per-container CSS variables inline. Breakpoint\n * behavior lives entirely in the generated media queries \u2014 no runtime\n * observers, and layout is correct with JavaScript disabled.\n *\n * Cascade contract for sparse responsive entries (see tests): initialize from\n * top-level values, apply `responsive.default`, then each successive\n * breakpoint. Within an entry, axis-specific gaps (`gapX`/`gapY`) beat the\n * entry's general `gap`.\n *\n * `place-*` shorthands are resolved into their axis longhands here rather than\n * emitted as CSS. A shorthand declaration would have to follow the longhands\n * in the generated rule and would then reset them, so authored `justifyItems`\n * or `justifySelf` could never take effect. Resolving in one place also lets\n * `placeSelf` join the responsive cascade for free.\n *\n * Only authored values are emitted, as custom properties (not camelCase CSS\n * keys) so the return type is a `--*` record assignable to React\n * `CSSProperties` and to inline `style` attributes without a cast. Neutral\n * defaults, the breakpoint cascade, and the resets that stop a nested grid\n * inheriting its parent's placement all live in the generated stylesheet.\n */\n\n/**\n * Inline style consisting only of CSS custom properties.\n *\n * @remarks\n * React 19 `CSSProperties` indexes `--${string}`; a `string` index does not,\n * which is why earlier `Record<string, string>` returns needed a cast.\n */\nexport type CssVariables = {\n\t[property: `--${string}`]: string | undefined;\n};\n\nexport interface GridThemeOptions {\n\t/**\n\t * Breakpoint thresholds in CSS lengths (`rem` recommended for zoom).\n\t * Overrides only the named token; the rest keep library defaults.\n\t *\n\t * @remarks\n\t * Configured thresholds must preserve named cascade order\n\t * (`sm \u2264 md \u2264 lg \u2264 xl \u2264 2xl`). `rem`/`em` values are compared at a 16px\n\t * root so mixed units cannot invert the sequence.\n\t */\n\tbreakpoints?: Partial<Record<GridBreakpointToken, string>>;\n\t/** Gap token definitions as CSS values, overriding only the named tokens. */\n\tgap?: GridGapScale;\n\t/** Default minimum column width used by `columns: 'auto'` grids. */\n\tminColumnWidth?: string;\n\t/**\n\t * Token values that change from a breakpoint up.\n\t *\n\t * @remarks\n\t * Breakpoint-major, like a document's own `responsive`: one entry per width\n\t * listing the tokens that change there, rather than one entry per token\n\t * listing its widths. Base values stay in `gap`, so there is no `default`\n\t * entry here \u2014 and no collision between the `default` *token* and a\n\t * `default` *slot*.\n\t *\n\t * Tokens are axis-agnostic: a document picks which token each axis uses via\n\t * `gapX`/`gapY`, so a theme never declares an axis.\n\t *\n\t * ```ts\n\t * grid: {\n\t * gap: { default: '1rem', loose: '1.5rem' },\n\t * responsive: {\n\t * md: { default: '1.25rem' },\n\t * lg: { default: '1.5rem', loose: '2rem' },\n\t * },\n\t * }\n\t * ```\n\t */\n\tresponsive?: Partial<Record<GridBreakpointToken, GridGapScale>>;\n}\n\n/** Gap token values at one width. Unlisted tokens keep the value from the next narrower width. */\nexport type GridGapScale = Partial<Record<GridGapToken, string>>;\n\nexport interface NormalizedGridTheme {\n\treadonly breakpoints: Readonly<Record<GridBreakpointToken, string>>;\n\treadonly gap: Readonly<Record<GridGapToken, string>>;\n\t/** Token overrides per breakpoint; only the tokens a width changes. */\n\treadonly responsive: Readonly<Partial<Record<GridBreakpointToken, Readonly<GridGapScale>>>>;\n\treadonly minColumnWidth: string;\n}\n\nconst DEFAULT_BREAKPOINTS: Record<GridBreakpointToken, string> = {\n\tsm: '40rem',\n\tmd: '48rem',\n\tlg: '64rem',\n\txl: '80rem',\n\t'2xl': '96rem',\n};\n\nconst DEFAULT_GAP: Record<GridGapToken, string> = {\n\tnone: '0',\n\tcompact: '0.5rem',\n\tdefault: 'var(--space-stack, 1rem)',\n\tloose: 'var(--space-block-lg, 1.5rem)',\n\twide: 'var(--space-block-xl, 2rem)',\n};\n\nconst DEFAULT_MIN_COLUMN_WIDTH = '15.625rem';\n\n/**\n * Public gap tokens. Hosts override these at `:root` to restyle every grid.\n *\n * @remarks\n * The theme must never declare these on an element: an element's own\n * declaration beats an inherited one, which would make the documented `:root`\n * override a no-op. The theme's value is declared under\n * {@link gapBaseVariable} instead and reached through a `var()` fallback.\n *\n * A host override therefore replaces the token at *every* width, including one\n * a theme ramps through `responsive` \u2014 the public token is the first `var()`\n * argument and a ramp only ever redeclares the fallback. A host that wants its\n * own rhythm declares its own media queries.\n */\nconst GAP_TOKEN_VARIABLES: Record<GridGapToken, `--${string}`> = {\n\tnone: '--se-grid-gap-none',\n\tcompact: '--se-grid-gap-compact',\n\tdefault: '--se-grid-gap-default',\n\tloose: '--se-grid-gap-loose',\n\twide: '--se-grid-gap-wide',\n};\n\n/** Theme default for a gap token, shadowed by the public token when a host sets it. */\nfunction gapBaseVariable(token: GridGapToken): `--${string}` {\n\treturn `--se-grid-gap-base-${token}`;\n}\n\n/** A gap token as CSS: the host's override if present, else the theme default. */\nfunction gapTokenValue(token: GridGapToken): string {\n\treturn `var(${GAP_TOKEN_VARIABLES[token]}, var(${gapBaseVariable(token)}))`;\n}\n\nconst DEFAULT_GAP_CSS = gapTokenValue('default');\n\n/**\n * Variable a host sets on an item to choose the display the item rule applies.\n *\n * @remarks\n * The item rule outranks a component's own `display` (class plus attribute\n * beats a lone class), so a host that needs its own layout sets this variable\n * rather than `display`. Responsive `hidden` then toggles between `none` and\n * that mode instead of forcing `block`. Custom properties inherit, so the grid\n * rule resets it: a fieldset that sets `grid` for itself must not turn the\n * fields of its own grid into grids.\n */\nconst ITEM_DISPLAY_MODE_VARIABLE = '--se-item-display-mode';\n\n/** Display a visible item falls back to. See {@link ITEM_DISPLAY_MODE_VARIABLE}. */\nconst ITEM_DISPLAY_MODE = `var(${ITEM_DISPLAY_MODE_VARIABLE}, block)`;\n\n/** Root font size used when comparing `rem`/`em` breakpoint thresholds. */\nconst ROOT_FONT_PX = 16;\n\ntype CssLengthUnit = 'px' | 'rem' | 'em';\n\n/** CSS property, its variable base name, and the value used when unauthored. */\ntype ResponsiveProperty = readonly [property: string, variable: string, fallback: string];\n\nfunction deepFreeze<T extends object>(value: T): T {\n\tObject.freeze(value);\n\tfor (const child of Object.values(value)) {\n\t\tif (child !== null && typeof child === 'object' && !Object.isFrozen(child)) {\n\t\t\tdeepFreeze(child);\n\t\t}\n\t}\n\treturn value;\n}\n\n/** Drops empty entries so an unramped theme normalizes to `{}` and emits nothing extra. */\nfunction resolveResponsiveGap(\n\toverrides?: Partial<Record<GridBreakpointToken, GridGapScale>>,\n): Partial<Record<GridBreakpointToken, GridGapScale>> {\n\tconst resolved: Partial<Record<GridBreakpointToken, GridGapScale>> = {};\n\tfor (const breakpoint of BREAKPOINT_ORDER) {\n\t\tconst entry = overrides?.[breakpoint];\n\t\tconst tokens = GridGapTokens.filter((token) => entry?.[token] !== undefined);\n\t\tif (tokens.length > 0) {\n\t\t\tresolved[breakpoint] = Object.fromEntries(tokens.map((token) => [token, entry![token]])) as GridGapScale;\n\t\t}\n\t}\n\treturn resolved;\n}\n\n/**\n * Resolves the immutable grid theme from the `grid` option of a layout theme.\n *\n * @remarks\n * Threshold overrides replace only the named breakpoint; the rest keep\n * library defaults. Thresholds accept `px`/`rem`/`em` lengths and must\n * preserve named cascade order. `rem`/`em` compare at a 16px root.\n * Media queries follow viewport width \u2014 a grid inside a narrow sidebar\n * still receives the desktop rules of the wide screen it lives on.\n */\nexport function resolveGridTheme(options?: GridThemeOptions): NormalizedGridTheme {\n\tconst breakpoints = { ...DEFAULT_BREAKPOINTS, ...options?.breakpoints };\n\tconst gap = { ...DEFAULT_GAP, ...options?.gap };\n\tconst responsive = resolveResponsiveGap(options?.responsive);\n\tconst minColumnWidth = options?.minColumnWidth ?? DEFAULT_MIN_COLUMN_WIDTH;\n\tassertBreakpointOrder(breakpoints);\n\treturn deepFreeze({\n\t\tbreakpoints,\n\t\tgap,\n\t\tresponsive,\n\t\tminColumnWidth,\n\t});\n}\n\nfunction isCssLengthUnit(unit: string | undefined): unit is CssLengthUnit {\n\treturn unit === 'px' || unit === 'rem' || unit === 'em';\n}\n\nfunction thresholdToPx(token: GridBreakpointToken, threshold: string): number {\n\tconst match = /^(\\d+(?:\\.\\d+)?)(px|rem|em)$/.exec(threshold);\n\tconst rawUnit = match?.[2];\n\tif (!match || !isCssLengthUnit(rawUnit)) {\n\t\tthrow new Error(`Grid theme breakpoint '${token}' must be a px, rem, or em length; received '${threshold}'.`);\n\t}\n\tconst value = Number(match[1]);\n\treturn rawUnit === 'px' ? value : value * ROOT_FONT_PX;\n}\n\nfunction assertBreakpointOrder(breakpoints: Record<GridBreakpointToken, string>): void {\n\tlet previousPx = Number.NEGATIVE_INFINITY;\n\tlet previousToken: GridBreakpointToken | undefined;\n\tfor (const token of BREAKPOINT_ORDER) {\n\t\tconst threshold = breakpoints[token];\n\t\tconst px = thresholdToPx(token, threshold);\n\t\tif (previousToken !== undefined && px < previousPx) {\n\t\t\tthrow new Error(\n\t\t\t\t`Grid theme breakpoints must preserve cascade order sm \u2264 md \u2264 lg \u2264 xl \u2264 2xl (rem/em compared at ${ROOT_FONT_PX}px root); '${token}' (${threshold}) is smaller than '${previousToken}' (${breakpoints[previousToken]}).`,\n\t\t\t);\n\t\t}\n\t\tpreviousPx = px;\n\t\tpreviousToken = token;\n\t}\n}\n\n/**\n * Responsive gap overrides as ordered pairs, independent of authored key order.\n *\n * @remarks\n * These come from consumer options, so `{ md, lg }` and `{ lg, md }` describe\n * one theme with different `JSON.stringify` output. Hashing that directly would\n * mint two ids for the same theme and emit its stylesheet twice under different\n * scopes, defeating the sharing of one compiled theme.\n */\nfunction canonicalResponsiveGap(\n\tresponsive: Readonly<Partial<Record<GridBreakpointToken, Readonly<GridGapScale>>>>,\n): Array<[string, Array<[string, string]>]> {\n\treturn BREAKPOINT_ORDER.flatMap((breakpoint) => {\n\t\tconst entry = responsive[breakpoint];\n\t\tif (!entry) return [];\n\t\tconst tokens = GridGapTokens.flatMap((token) => {\n\t\t\tconst value = entry[token];\n\t\t\treturn value === undefined ? [] : [[token, value] as [string, string]];\n\t\t});\n\t\treturn [[breakpoint, tokens] as [string, Array<[string, string]>]];\n\t});\n}\n\n/** The normalized grid theme in a stable shape, for hashing into a layout theme id. */\nexport function canonicalGridTheme(theme: NormalizedGridTheme) {\n\treturn {\n\t\tbreakpoints: theme.breakpoints,\n\t\tgap: theme.gap,\n\t\tresponsive: canonicalResponsiveGap(theme.responsive),\n\t\tminColumnWidth: theme.minColumnWidth,\n\t};\n}\n\n/**\n * Class a grid container carries, and the stylesheet's hook for it.\n *\n * @remarks\n * Neutral on purpose: a domain's renderer adds this beside its own class,\n * so a step, a page section and a container of any domain share one set of rules. The stylesheet\n * keys on this class, {@link GRID_ITEM_CLASS} and `[data-se-theme]` only, with no alias for a\n * domain's own class.\n */\nexport const GRID_CLASS = 'se-grid';\n\n/** Class an element placed in a grid carries, and the stylesheet's hook for it. See {@link GRID_CLASS}. */\nexport const GRID_ITEM_CLASS = 'se-grid-item';\n\n/**\n * Grid container properties that change per breakpoint.\n *\n * @remarks\n * One table drives the base rule, every media query, and the inheritance\n * resets, so a property cannot be declared at one width and forgotten at\n * another.\n */\nconst GRID_PROPERTIES: readonly ResponsiveProperty[] = [\n\t['grid-template-columns', 'se-grid-template', 'repeat(1, minmax(0, 1fr))'],\n\t['grid-template-areas', 'se-grid-areas', 'none'],\n\t['row-gap', 'se-grid-gap-y', DEFAULT_GAP_CSS],\n\t['column-gap', 'se-grid-gap-x', DEFAULT_GAP_CSS],\n];\n\n/**\n * Placement an item takes when it sets none, declared on its grid.\n *\n * @remarks\n * A grid whose items use named widths has 12 tracks, so an item that sets no\n * width would otherwise fall into one of them. The grid declares `1 / -1` here\n * and the item's `grid-column` falls back to it, which keeps the rule in the\n * stylesheet. The grid rule resets it so a nested grid does not inherit its\n * parent's default.\n */\nconst DEFAULT_COLUMN_VARIABLE = '--se-grid-default-column';\n\n/**\n * Item placement properties that change per breakpoint.\n *\n * @remarks\n * `justify-self`/`align-self` fall back to `auto`, which defers to the grid's\n * own `justify-items`/`align-items`. Any other fallback would silently beat\n * grid-level alignment on every item.\n */\nconst ITEM_PROPERTIES: readonly ResponsiveProperty[] = [\n\t['display', 'se-item-display', ITEM_DISPLAY_MODE],\n\t['grid-column', 'se-item-grid-column', `var(${DEFAULT_COLUMN_VARIABLE}, auto)`],\n\t['grid-row', 'se-item-grid-row', 'auto'],\n\t['justify-self', 'se-item-justify-self', 'auto'],\n\t['align-self', 'se-item-align-self', 'auto'],\n\t['margin-block-start', 'se-item-margin-block-start', '0'],\n\t['margin-block-end', 'se-item-margin-block-end', '0'],\n];\n\n/** Grid alignment, authored once for all widths. */\nconst GRID_ALIGNMENT_PROPERTIES: readonly ResponsiveProperty[] = [\n\t['justify-items', 'se-grid-justify-items', 'normal'],\n\t['align-items', 'se-grid-align-items', 'normal'],\n\t['justify-content', 'se-grid-justify-content', 'normal'],\n\t['align-content', 'se-grid-align-content', 'start'],\n];\n\n/** Removes the space after each comma of a stylesheet-only fallback, which `var()` ignores. */\nfunction tight(fallback: string): string {\n\treturn fallback.replaceAll(', ', ',');\n}\n\n/**\n * Name of the stylesheet-private custom property that gates one cascade slot of one table row.\n *\n * @remarks\n * A gate is declared inside the slot's media query as a copy of the public slot variable, so\n * outside that query it is the guaranteed-invalid value and the `var()` chain skips it. The names\n * are private to the stylesheet (a form never writes them, and they carry no contract) and carry\n * the theme id: custom properties inherit, so a gate named alike in two themes would let a theme\n * with a wider threshold read the gate its ancestor's narrower query declared. Within one theme\n * every element the rules reach declares its own gates wherever the query applies, so no reset\n * is needed.\n *\n * Read a name in devtools as theme id, table (`g` grid, `i` item), the property's row in that\n * table, and the breakpoint token: `--l1abc-i1md` is the `md` gate of the item `grid-column`.\n */\nfunction gateName(themeId: string, table: string, row: number, slot: GridBreakpointToken): string {\n\treturn `--${themeId}-${table}${row}${slot}`;\n}\n\n/**\n * `var(--g-2xl, var(--g-xl, ... var(--x, fallback)))`: the widest slot whose media query applies wins.\n *\n * @remarks\n * The chain is written once, in the base rule. A slot's gate is declared only inside its media\n * query (see {@link gateName}), so the cascade across widths costs one short declaration per slot\n * instead of restating the whole chain in every query. An unset slot resolves to the nearest\n * narrower one, so a renderer emits only the breakpoints an author wrote.\n */\nfunction cascadingVar(themeId: string, table: string, row: number, variable: string, fallback: string): string {\n\tlet value = `var(--${variable},${tight(fallback)})`;\n\tfor (const slot of BREAKPOINT_ORDER) {\n\t\tvalue = `var(${gateName(themeId, table, row, slot)},${value})`;\n\t}\n\treturn value;\n}\n\nfunction declarations(themeId: string, table: string, properties: readonly ResponsiveProperty[]): string {\n\treturn properties\n\t\t.map(\n\t\t\t([property, variable, fallback], row) =>\n\t\t\t\t`${property}:${cascadingVar(themeId, table, row, variable, fallback)};`,\n\t\t)\n\t\t.join('');\n}\n\n/** Alignment is authored once for all widths, so it has no slots and no gates. */\nfunction flatDeclarations(properties: readonly ResponsiveProperty[]): string {\n\treturn properties\n\t\t.map(([property, variable, fallback]) => `${property}:var(--${variable},${tight(fallback)});`)\n\t\t.join('');\n}\n\n/** One slot's gates: each property's public slot variable, copied inside the slot's media query. */\nfunction gates(\n\tthemeId: string,\n\ttable: string,\n\tproperties: readonly ResponsiveProperty[],\n\tslot: GridBreakpointToken,\n): string {\n\treturn properties\n\t\t.map(([, variable], row) => `${gateName(themeId, table, row, slot)}:var(--${variable}-${slot});`)\n\t\t.join('');\n}\n\n/**\n * Resets every slot so custom properties do not inherit past a host.\n *\n * @remarks\n * Custom properties inherit, so a nested grid or item would otherwise pick up\n * its ancestor's placement. `initial` makes `var()` fall through to the chain\n * above, and an inline value on the same element still wins the cascade.\n * Only a table with slots resets them: alignment is authored once for all widths, so its\n * slot variables are never written and never read.\n */\nfunction inheritanceResets(properties: readonly ResponsiveProperty[], withSlots: boolean): string {\n\treturn properties\n\t\t.flatMap(([, variable]) => [\n\t\t\t`--${variable}`,\n\t\t\t...(withSlots ? BREAKPOINT_ORDER.map((slot) => `--${variable}-${slot}`) : []),\n\t\t])\n\t\t.map((name) => `${name}:initial;`)\n\t\t.join('');\n}\n\n/**\n * Generates the theme-scoped stylesheet.\n *\n * @remarks\n * Rules are scoped under `[data-se-theme=\"<id>\"]`, which the renderer\n * places on every grid container and item, so two themes that differ\n * cannot overwrite each other. Item rules are scoped under the item that\n * carries the theme attribute so nested grids do not leak styles across themes.\n * Selectors use only {@link GRID_CLASS}, {@link GRID_ITEM_CLASS} and that attribute.\n *\n * Each responsive property is declared once, in the base rule, as a `var()` chain over the\n * slot gates ({@link gateName}); a media query only declares the gates of its slot.\n *\n * @param theme The resolved grid vocabulary.\n * @param themeId The id of the layout theme the rules are scoped to.\n */\nexport function getGridThemeCss(theme: NormalizedGridTheme, themeId: string): string {\n\tconst scope = `[data-se-theme=\"${themeId}\"]`;\n\tconst gridScope = `.${GRID_CLASS}${scope}`;\n\tconst itemScope = `.${GRID_ITEM_CLASS}${scope}`;\n\tconst tokens = GridGapTokens.map((token) => `${gapBaseVariable(token)}:${theme.gap[token]};`).join('');\n\tconst lines: string[] = [\n\t\t`${scope}{${tokens}}`,\n\t\t`${gridScope}{${inheritanceResets(GRID_PROPERTIES, true)}${inheritanceResets(GRID_ALIGNMENT_PROPERTIES, false)}${DEFAULT_COLUMN_VARIABLE}:initial;${ITEM_DISPLAY_MODE_VARIABLE}:initial;display:grid;${declarations(themeId, 'g', GRID_PROPERTIES)}${flatDeclarations(GRID_ALIGNMENT_PROPERTIES)}}`,\n\t\t`${itemScope}{${inheritanceResets(ITEM_PROPERTIES, true)}${declarations(themeId, 'i', ITEM_PROPERTIES)}}`,\n\t];\n\tfor (const breakpoint of BREAKPOINT_ORDER) {\n\t\tconst ramped = theme.responsive[breakpoint];\n\t\tconst rampedTokens = ramped\n\t\t\t? GridGapTokens.filter((token) => ramped[token] !== undefined)\n\t\t\t\t\t.map((token) => `${gapBaseVariable(token)}:${ramped[token]};`)\n\t\t\t\t\t.join('')\n\t\t\t: '';\n\t\tlines.push(\n\t\t\t`@media (min-width:${theme.breakpoints[breakpoint]}){${rampedTokens ? `${scope}{${rampedTokens}}` : ''}${gridScope}{${gates(themeId, 'g', GRID_PROPERTIES, breakpoint)}}${itemScope}{${gates(themeId, 'i', ITEM_PROPERTIES, breakpoint)}}}`,\n\t\t);\n\t}\n\treturn lines.join('\\n');\n}\n\nfunction isGridGapToken(value: string): value is GridGapToken {\n\tfor (const token of GridGapTokens) {\n\t\tif (token === value) return true;\n\t}\n\treturn false;\n}\n\n/**\n * Maps an authored gap value (semantic token or raw CSS value) to its\n * variable reference or literal.\n */\nfunction resolveGridGap(value: string | undefined): string | undefined {\n\tif (value === undefined) return undefined;\n\tif (isGridGapToken(value)) {\n\t\treturn gapTokenValue(value);\n\t}\n\treturn value;\n}\n\n/** Keywords that qualify the position keyword that follows them. */\nconst AXIS_QUALIFIERS = new Set(['safe', 'unsafe', 'first', 'last']);\n\n/**\n * Splits a `place-*` shorthand into `[align, justify]` per the CSS grammar.\n *\n * @remarks\n * The shorthand is align-first and a single axis value sets both axes \u2014 but an\n * axis value can be two keywords, an overflow position (`safe`/`unsafe`) or a\n * baseline modifier (`first`/`last`) plus its position. So `safe center` is one\n * value for both axes, while `center start` is one value per axis. Splitting on\n * whitespace alone would emit `align-self: safe`, which is not valid CSS.\n */\nfunction splitPlaceShorthand(value: string | undefined): [string | undefined, string | undefined] {\n\tif (value === undefined) return [undefined, undefined];\n\tconst tokens = value.trim().split(/\\s+/).filter(Boolean);\n\tif (tokens.length === 0) return [undefined, undefined];\n\tconst alignLength = AXIS_QUALIFIERS.has(tokens[0] as string) && tokens.length > 1 ? 2 : 1;\n\tconst align = tokens.slice(0, alignLength).join(' ');\n\tconst justify = alignLength < tokens.length ? tokens.slice(alignLength).join(' ') : align;\n\treturn [align, justify];\n}\n\nfunction toGridTemplate(columns: number | 'auto', minColumnWidth: string): string {\n\tif (columns === 'auto') {\n\t\treturn `repeat(auto-fit, minmax(min(${minColumnWidth}, 100%), 1fr))`;\n\t}\n\treturn `repeat(${columns}, minmax(0, 1fr))`;\n}\n\nfunction customProperty(name: string, slot: CascadeSlot): `--${string}` {\n\treturn slot === 'default' ? `--${name}` : `--${name}-${slot}`;\n}\n\n/** Layout values a single cascade slot may set; the top-level config is the `default` slot. */\ninterface GridEntry {\n\tcolumns?: number | 'auto';\n\tminColumnWidth?: string;\n\tgap?: string;\n\tgapX?: string;\n\tgapY?: string;\n}\n\n/** Placement a single cascade slot may set; the top-level config is the `default` slot. */\ninterface GridItemEntry {\n\tarea?: string;\n\twidth?: GridWidthName;\n\toffset?: GridOffsetName;\n\tcolumn?: number | string;\n\trow?: number | string;\n\tjustifySelf?: string;\n\talignSelf?: string;\n\thidden?: boolean;\n\tmarginBlockStart?: string;\n\tmarginBlockEnd?: string;\n}\n\nfunction emitGapEntry(variables: CssVariables, slot: CascadeSlot, entry: GridEntry | undefined): void {\n\tif (!entry) return;\n\tconst entryGap = resolveGridGap(entry.gap);\n\tconst gapX = resolveGridGap(entry.gapX) ?? entryGap;\n\tconst gapY = resolveGridGap(entry.gapY) ?? entryGap;\n\tif (gapY !== undefined) variables[customProperty('se-grid-gap-y', slot)] = gapY;\n\tif (gapX !== undefined) variables[customProperty('se-grid-gap-x', slot)] = gapX;\n}\n\n/**\n * Resolves a grid against the theme into one inline style record.\n *\n * @remarks\n * Only values an author wrote are emitted; the generated stylesheet falls back\n * through the narrower breakpoints, so an unconfigured grid carries no inline\n * style. `columns` and `minColumnWidth` are the one coupled pair \u2014 they share a\n * single template \u2014 so they are the only values carried across slots. Axis\n * properties win over the matching `placeItems`/`placeContent` shorthand.\n *\n * When `elements` (the items this grid places) use named widths, the grid\n * gets 12 tracks and a `1 / -1` default placement for items that set no width. Validation keeps that from meeting `columns`.\n *\n * A grid with `areas` gets the template of each slot that sets one: the quoted\n * rows as `--se-grid-areas` and the track count they draw as `--se-grid-template`,\n * derived from the rows rather than authored, as with named widths.\n */\nexport function getGridVariables(\n\tgrid: DeepReadonly<GridLayoutConfig> | undefined,\n\ttheme: NormalizedGridTheme,\n\telements: readonly unknown[],\n): CssVariables {\n\tconst variables: CssVariables = {};\n\n\tconst [placeAlignItems, placeJustifyItems] = splitPlaceShorthand(grid?.placeItems);\n\tconst [placeAlignContent, placeJustifyContent] = splitPlaceShorthand(grid?.placeContent);\n\tconst alignment: Record<string, string | undefined> = {\n\t\t'--se-grid-justify-items': grid?.justifyItems ?? placeJustifyItems,\n\t\t'--se-grid-align-items': grid?.alignItems ?? placeAlignItems,\n\t\t'--se-grid-justify-content': grid?.justifyContent ?? placeJustifyContent,\n\t\t'--se-grid-align-content': grid?.alignContent ?? placeAlignContent,\n\t};\n\tfor (const [name, value] of Object.entries(alignment)) {\n\t\tif (value !== undefined) variables[name as `--${string}`] = value;\n\t}\n\n\tlet columns: number | 'auto' = 1;\n\tlet minColumnWidth = theme.minColumnWidth;\n\tconst emitTemplate = (slot: CascadeSlot, entry: GridEntry | undefined): void => {\n\t\tif (!entry) return;\n\t\tif (entry.columns === undefined && entry.minColumnWidth === undefined) return;\n\t\tif (entry.columns !== undefined) columns = entry.columns;\n\t\tif (entry.minColumnWidth !== undefined) minColumnWidth = entry.minColumnWidth;\n\t\tvariables[customProperty('se-grid-template', slot)] = toGridTemplate(columns, minColumnWidth);\n\t};\n\n\tif (usesGridWidths(elements)) {\n\t\tvariables['--se-grid-template'] = `repeat(${WIDTH_TRACKS}, minmax(0, 1fr))`;\n\t\tvariables[DEFAULT_COLUMN_VARIABLE] = '1 / -1';\n\t}\n\n\tconst templates = gridAreaTemplates(grid);\n\tfor (const slot of CASCADE_SLOTS) {\n\t\tconst rows = templates[slot];\n\t\tif (!rows) continue;\n\t\tvariables[customProperty('se-grid-areas', slot)] = areasTemplateValue(rows);\n\t\tvariables[customProperty('se-grid-template', slot)] = toGridTemplate(\n\t\t\trows[0]?.length ?? 1,\n\t\t\ttheme.minColumnWidth,\n\t\t);\n\t}\n\n\tconst responsive = grid?.responsive;\n\temitTemplate('default', grid);\n\temitTemplate('default', responsive?.default);\n\temitGapEntry(variables, 'default', grid);\n\temitGapEntry(variables, 'default', responsive?.default);\n\n\tfor (const breakpoint of BREAKPOINT_ORDER) {\n\t\temitTemplate(breakpoint, responsive?.[breakpoint]);\n\t\temitGapEntry(variables, breakpoint, responsive?.[breakpoint]);\n\t}\n\treturn variables;\n}\n\n/**\n * `grid-column` for a width and offset.\n *\n * @remarks\n * Both names resolve into one declaration, so a slot that authors only one of\n * them is emitted together with the other as the narrower slots left it \u2014\n * the same coupling `columns` and `minColumnWidth` have for the grid template.\n * An offset with no width runs to the end of the row.\n */\nfunction namedColumn({ width, offset }: NamedPlacement): string {\n\tconst start = offset === undefined ? undefined : WIDTH_SPANS[offset] + 1;\n\tif (width === undefined) return start === undefined ? 'auto' : `${start} / -1`;\n\tconst span = `span ${WIDTH_SPANS[width]}`;\n\treturn start === undefined ? span : `${start} / ${span}`;\n}\n\nfunction formatGridLine(value: number | string): string {\n\treturn typeof value === 'number' ? String(value) : value;\n}\n\nfunction emitItemEntry(\n\tvariables: CssVariables,\n\tslot: CascadeSlot,\n\tentry: GridItemEntry | undefined,\n\tnamed: NamedPlacement = {},\n): void {\n\tif (!entry) return;\n\tif (entry.width !== undefined || entry.offset !== undefined) {\n\t\tcarryNamedPlacement(named, entry);\n\t\tvariables[customProperty('se-item-grid-column', slot)] = namedColumn(named);\n\t}\n\tif (entry.area !== undefined) {\n\t\tvariables[customProperty('se-item-grid-column', slot)] = entry.area;\n\t\tvariables[customProperty('se-item-grid-row', slot)] = entry.area;\n\t}\n\tif (entry.column !== undefined) {\n\t\tvariables[customProperty('se-item-grid-column', slot)] = formatGridLine(entry.column);\n\t}\n\tif (entry.row !== undefined) variables[customProperty('se-item-grid-row', slot)] = formatGridLine(entry.row);\n\tif (entry.justifySelf !== undefined) variables[customProperty('se-item-justify-self', slot)] = entry.justifySelf;\n\tif (entry.alignSelf !== undefined) variables[customProperty('se-item-align-self', slot)] = entry.alignSelf;\n\tconst marginBlockStart = resolveGridGap(entry.marginBlockStart);\n\tif (marginBlockStart !== undefined) {\n\t\tvariables[customProperty('se-item-margin-block-start', slot)] = marginBlockStart;\n\t}\n\tconst marginBlockEnd = resolveGridGap(entry.marginBlockEnd);\n\tif (marginBlockEnd !== undefined) {\n\t\tvariables[customProperty('se-item-margin-block-end', slot)] = marginBlockEnd;\n\t}\n\tif (entry.hidden !== undefined) {\n\t\tvariables[customProperty('se-item-display', slot)] = entry.hidden ? 'none' : ITEM_DISPLAY_MODE;\n\t}\n}\n\n/**\n * Resolves a single element's grid placement and spacing into inline style variables.\n *\n * @remarks\n * Each slot emits exactly what its entry authored \u2014 no value is carried across\n * breakpoints, because the generated stylesheet already falls back through the\n * narrower slots. The one exception is `width` and `offset`, which share the\n * single `grid-column` declaration (see {@link namedColumn}). An `area` is one\n * name written to both `grid-column` and `grid-row`, where a lone name reads as\n * that area's start and end lines. An element without a `grid` config produces\n * no inline style.\n * `placeSelf` is applied before the axis properties, so those win.\n *\n * `marginBlockStart`/`marginBlockEnd` accept the same gap tokens as the grid, so\n * a one-off rhythm around a non-input element reads in the same vocabulary as\n * the grid's spacing. They ride the shared item property table rather than a\n * separate mechanism, which is what gives them the breakpoint cascade and the\n * inheritance resets for free \u2014 and keeps a single system owning the block axis\n * instead of two fighting over it.\n */\nexport function getGridItemVariables(grid?: ElementGridConfig): CssVariables {\n\tconst variables: CssVariables = {};\n\tconst [alignSelf, justifySelf] = splitPlaceShorthand(grid?.placeSelf);\n\n\tconst named: NamedPlacement = {};\n\temitItemEntry(variables, 'default', { alignSelf, justifySelf });\n\temitItemEntry(variables, 'default', grid, named);\n\temitItemEntry(variables, 'default', grid?.responsive?.default, named);\n\n\tfor (const breakpoint of BREAKPOINT_ORDER) {\n\t\temitItemEntry(variables, breakpoint, grid?.responsive?.[breakpoint], named);\n\t}\n\treturn variables;\n}\n"],
|
|
5
|
-
"mappings": "AAAA,UAAYA,MAAO,WAWZ,IAAMC,EAAgB,CAAC,OAAQ,UAAW,UAAW,QAAS,MAAM,EAa9DC,EACX,QAAM,CAAG,OAAKD,CAAa,EAAK,SAAO,CAAC,CAAC,EACzC,MAAQ,WAAS,mFAAmF,CAAC,EAOjGE,GAAsB,CAC3B,OACA,OACA,OACA,UACA,UACA,UACA,QACA,SACA,cACD,EAUA,SAASC,GAAQC,EAAsB,CACtC,OAAOA,EACL,MAAM,EAAE,EACR,IAAKC,GAAU,SAAS,KAAKA,CAAI,EAAI,IAAIA,EAAK,YAAY,CAAC,GAAGA,EAAK,YAAY,CAAC,IAAMA,CAAK,EAC3F,KAAK,EAAE,CACV,CAEA,IAAMC,EAAmB,SAASJ,GAAoB,IAAIC,EAAO,EAAE,KAAK,GAAG,CAAC,wCAUtEI,GACJ,SAAO,EACP,MACE,QAAM,IAAI,OAAO,IAAID,CAAgB,GAAG,EAAG,8DAA8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OAAO5B,CACR",
|
|
6
|
-
"names": ["z", "GridGapTokens", "GridGapValueSchema", "RESERVED_AREA_NAMES", "anyCase", "word", "char", "AREA_NAME_SOURCE", "GridAreaNameSchema", "perBreakpoint", "schema", "responsiveSchema", "GridAreaRowSchema", "GridAreaRowsSchema", "GridAreasSchema", "GridLayoutPropertiesSchema", "GridBreakpointConfigSchema", "GridLayoutConfigSchema", "GridWidthNames", "GridOffsetNames", "ElementGridPropertiesSchema", "ItemGridBreakpointSchema", "ElementGridConfigSchema", "BREAKPOINT_ORDER", "CASCADE_SLOTS", "WIDTH_TRACKS", "WIDTH_SPANS", "isRecord", "value", "elementGridSlots", "element", "grid", "slots", "responsive", "slot", "CASCADE_SLOTS", "entry", "elementGridKeys", "keys", "key", "elementUsesGridWidths", "usesGridWidths", "elements", "carryNamedPlacement", "carried", "EMPTY_CELL", "splitRow", "row", "cell", "toRows", "rows", "gridAreaTemplates", "grid", "isRecord", "templates", "slot", "CASCADE_SLOTS", "areasTemplateValue", "rows", "row", "DEFAULT_BREAKPOINTS", "DEFAULT_GAP", "DEFAULT_MIN_COLUMN_WIDTH", "GAP_TOKEN_VARIABLES", "gapBaseVariable", "token", "gapTokenValue", "DEFAULT_GAP_CSS", "ITEM_DISPLAY_MODE_VARIABLE", "ITEM_DISPLAY_MODE", "ROOT_FONT_PX", "deepFreeze", "value", "child", "resolveResponsiveGap", "overrides", "resolved", "breakpoint", "BREAKPOINT_ORDER", "entry", "tokens", "GridGapTokens", "resolveGridTheme", "options", "breakpoints", "gap", "responsive", "minColumnWidth", "assertBreakpointOrder", "isCssLengthUnit", "unit", "thresholdToPx", "threshold", "match", "rawUnit", "previousPx", "previousToken", "px", "canonicalResponsiveGap", "canonicalGridTheme", "theme", "GRID_CLASS", "GRID_ITEM_CLASS", "GRID_PROPERTIES", "DEFAULT_COLUMN_VARIABLE", "ITEM_PROPERTIES", "GRID_ALIGNMENT_PROPERTIES", "tight", "fallback", "gateName", "themeId", "table", "row", "slot", "cascadingVar", "variable", "declarations", "properties", "property", "flatDeclarations", "gates", "inheritanceResets", "withSlots", "name", "getGridThemeCss", "scope", "gridScope", "itemScope", "lines", "ramped", "rampedTokens", "isGridGapToken", "resolveGridGap", "AXIS_QUALIFIERS", "splitPlaceShorthand", "alignLength", "align", "justify", "toGridTemplate", "columns", "customProperty", "emitGapEntry", "variables", "entryGap", "gapX", "gapY", "getGridVariables", "grid", "elements", "placeAlignItems", "placeJustifyItems", "placeAlignContent", "placeJustifyContent", "alignment", "emitTemplate", "usesGridWidths", "WIDTH_TRACKS", "templates", "gridAreaTemplates", "CASCADE_SLOTS", "rows", "areasTemplateValue", "namedColumn", "width", "offset", "start", "WIDTH_SPANS", "span", "formatGridLine", "emitItemEntry", "named", "carryNamedPlacement", "marginBlockStart", "marginBlockEnd", "getGridItemVariables", "alignSelf", "justifySelf"]
|
|
4
|
+
"sourcesContent": ["import * as z from 'zod/mini';\n\n/**\n * Semantic gap tokens for grid layouts.\n *\n * @remarks\n * Tokens are indirections to overridable CSS variables: the renderer emits\n * `var(--se-grid-gap-<token>)`, so hosts restyle every grid by overriding the\n * token at `:root`. Raw CSS strings (e.g. `'1.5rem'`) are the one-off escape\n * hatch.\n */\nexport const GridGapTokens = ['none', 'compact', 'default', 'loose', 'wide'] as const;\n\nexport type GridGapToken = (typeof GridGapTokens)[number];\n\n/**\n * Semantic gap token or a raw CSS length.\n *\n * @remarks\n * The enum branch is redundant for validation \u2014 the string branch accepts the\n * same values \u2014 and `z.infer` collapses the union to `string`. It is kept\n * because `z.toJSONSchema` emits it as `anyOf: [{enum: [...]}, {type: string}]`,\n * which is how the token vocabulary reaches registry and docs consumers.\n */\nexport const GridGapValueSchema = z\n\t.union([z.enum(GridGapTokens), z.string()])\n\t.check(z.describe('Semantic gap token (none | compact | default | loose | wide) or a raw CSS length.'));\n\n/**\n * Words that are not valid grid area names: `grid-area` reads `auto` and `span`\n * as placement keywords, the CSS-wide keywords reset a declaration, and `none`\n * and `default` are excluded from a `<custom-ident>` by the CSS grammar.\n */\nconst RESERVED_AREA_NAMES = [\n\t'auto',\n\t'span',\n\t'none',\n\t'default',\n\t'inherit',\n\t'initial',\n\t'unset',\n\t'revert',\n\t'revert-layer',\n];\n\n/**\n * A word as a pattern that matches it in any letter case.\n *\n * @remarks\n * Spelled with character classes instead of an `i` flag because the JSON Schema\n * export keeps only a regex's source, so a flag would be lost and editors would\n * accept `AUTO` and reject `Street`.\n */\nfunction anyCase(word: string): string {\n\treturn word\n\t\t.split('')\n\t\t.map((char) => (/[a-z]/i.test(char) ? `[${char.toLowerCase()}${char.toUpperCase()}]` : char))\n\t\t.join('');\n}\n\nconst AREA_NAME_SOURCE = `(?!(?:${RESERVED_AREA_NAMES.map(anyCase).join('|')})(?![\\\\w-]))-?[_a-zA-Z][_a-zA-Z0-9-]*`;\n\n/**\n * Name of a grid area: an ASCII CSS identifier that is not a reserved word.\n *\n * @remarks\n * Names are written into a custom property that the stylesheet reads as CSS, so\n * the pattern is the injection guard. Nothing outside `[A-Za-z0-9_-]` can reach the\n * property, which rules out quotes, semicolons, braces and whitespace.\n */\nconst GridAreaNameSchema = z\n\t.string()\n\t.check(\n\t\tz.regex(new RegExp(`^${AREA_NAME_SOURCE}$`), 'Area names are CSS identifiers such as \"header\" or \"side-2\".'),\n\t\tz.describe('Name of a cell group in the grid template: a CSS identifier such as \"header\" or \"side-2\".'),\n\t);\n\n/** A value per cascade slot (`default`, `sm` ... `2xl`), each optional. */\nfunction perBreakpoint<T extends z.ZodMiniType>(schema: T) {\n\treturn z.strictObject({\n\t\tdefault: z.optional(schema),\n\t\tsm: z.optional(schema),\n\t\tmd: z.optional(schema),\n\t\tlg: z.optional(schema),\n\t\txl: z.optional(schema),\n\t\t'2xl': z.optional(schema),\n\t});\n}\n\nfunction responsiveSchema<T extends z.ZodMiniType>(schema: T) {\n\treturn z.optional(perBreakpoint(schema));\n}\n\n/** One row of a template: area names or `.` for an empty cell, separated by spaces. */\nconst GridAreaRowSchema = z\n\t.string()\n\t.check(\n\t\tz.regex(\n\t\t\tnew RegExp(`^\\\\s*(?:\\\\.+|${AREA_NAME_SOURCE})(?:\\\\s+(?:\\\\.+|${AREA_NAME_SOURCE}))*\\\\s*$`),\n\t\t\t'A grid areas row lists area names (CSS identifiers) or \".\" for an empty cell, separated by spaces.',\n\t\t),\n\t);\n\nconst GridAreaRowsSchema = z.array(GridAreaRowSchema).check(z.minLength(1));\n\n/**\n * A drawn layout: rows of area names, optionally per breakpoint.\n *\n * @remarks\n * The column count comes from the rows, so a grid with `areas` sets no\n * `columns`. Rows of one template must be the same length and each name must\n * fill a rectangle; the domain validator checks both, as CSS drops a template that\n * breaks either.\n */\nconst GridAreasSchema = z\n\t.union([GridAreaRowsSchema, perBreakpoint(GridAreaRowsSchema)])\n\t.check(\n\t\tz.describe(\n\t\t\t'Rows of area names separated by spaces (\".\" is an empty cell), or a record of them per breakpoint (default, sm ... 2xl).',\n\t\t),\n\t);\n\nconst GridLayoutPropertiesSchema = z.strictObject({\n\tareas: z.optional(GridAreasSchema),\n\tcolumns: z.optional(z.union([z.int().check(z.positive()), z.literal('auto')])),\n\tgap: z.optional(GridGapValueSchema),\n\tgapX: z.optional(GridGapValueSchema),\n\tgapY: z.optional(GridGapValueSchema),\n\tminColumnWidth: z.optional(z.string()),\n\tjustifyItems: z.optional(z.enum(['start', 'end', 'center', 'stretch'])),\n\talignItems: z.optional(z.enum(['start', 'end', 'center', 'stretch'])),\n\tplaceItems: z.optional(z.string()),\n\tjustifyContent: z.optional(\n\t\tz.enum(['start', 'end', 'center', 'stretch', 'space-around', 'space-between', 'space-evenly']),\n\t),\n\talignContent: z.optional(\n\t\tz.enum(['start', 'end', 'center', 'stretch', 'space-around', 'space-between', 'space-evenly']),\n\t),\n\tplaceContent: z.optional(z.string()),\n\tautoFlow: z\n\t\t.optional(z.enum(['row', 'dense']))\n\t\t.check(\n\t\t\tz.describe(\n\t\t\t\t\"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.\",\n\t\t\t),\n\t\t),\n});\n\nexport const GridBreakpointConfigSchema = z.pick(GridLayoutPropertiesSchema, {\n\tcolumns: true,\n\tgap: true,\n\tgapX: true,\n\tgapY: true,\n\tminColumnWidth: true,\n});\n\nexport const GridLayoutConfigSchema = z.extend(GridLayoutPropertiesSchema, {\n\tresponsive: responsiveSchema(GridBreakpointConfigSchema),\n});\n\n/**\n * Named item widths, as shares of the row.\n *\n * @remarks\n * A grid whose items use `width` or `offset` is laid out on 12 tracks, so\n * every name is a whole number of tracks: `full` 12, `three-quarters` 9,\n * `two-thirds` 8, `half` 6, `third` 4, `quarter` 3. An item that sets no width\n * fills the row.\n */\nexport const GridWidthNames = ['full', 'three-quarters', 'two-thirds', 'half', 'third', 'quarter'] as const;\n\nexport type GridWidthName = (typeof GridWidthNames)[number];\n\n/** Named offsets: the widths that are a fraction of the row, without `full`. */\nexport const GridOffsetNames = ['three-quarters', 'two-thirds', 'half', 'third', 'quarter'] as const;\n\nexport type GridOffsetName = (typeof GridOffsetNames)[number];\n\nconst ElementGridPropertiesSchema = z.strictObject({\n\tarea: z\n\t\t.optional(GridAreaNameSchema)\n\t\t.check(z.describe('Name of the cell group this item fills in the grid areas template.')),\n\twidth: z\n\t\t.optional(z.enum(GridWidthNames))\n\t\t.check(z.describe(`Named share of the row (${GridWidthNames.join(' | ')}).`)),\n\toffset: z\n\t\t.optional(z.enum(GridOffsetNames))\n\t\t.check(z.describe(`Named empty space before the item (${GridOffsetNames.join(' | ')}).`)),\n\tspan: z\n\t\t.optional(z.int().check(z.positive()))\n\t\t.check(\n\t\t\tz.describe(\n\t\t\t\t'Number of tracks to span, never more than the grid has. Needs a grid with a known track count, so not `columns: \"auto\"`.',\n\t\t\t),\n\t\t),\n\tcolumn: z.optional(z.union([z.number(), z.string()])),\n\trow: z.optional(z.union([z.number(), z.string()])),\n\tjustifySelf: z.optional(z.enum(['start', 'end', 'center', 'stretch'])),\n\talignSelf: z.optional(z.enum(['start', 'end', 'center', 'stretch'])),\n\tplaceSelf: z.optional(z.string()),\n\tsubgrid: z\n\t\t.optional(z.boolean())\n\t\t.check(\n\t\t\tz.describe(\n\t\t\t\t\"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.\",\n\t\t\t),\n\t\t),\n\tmarginBlockStart: z\n\t\t.optional(GridGapValueSchema)\n\t\t.check(z.describe('Extra space before this element, on top of the grid row gap.')),\n\tmarginBlockEnd: z\n\t\t.optional(GridGapValueSchema)\n\t\t.check(z.describe('Extra space after this element, on top of the grid row gap.')),\n});\n\nexport const ItemGridBreakpointSchema = z.extend(\n\tz.omit(ElementGridPropertiesSchema, { placeSelf: true, subgrid: true }),\n\t{\n\t\thidden: z.optional(z.boolean()),\n\t},\n);\n\nexport const ElementGridConfigSchema = z.extend(ElementGridPropertiesSchema, {\n\tresponsive: responsiveSchema(ItemGridBreakpointSchema),\n});\n\nexport type GridBreakpointConfig = z.infer<typeof GridBreakpointConfigSchema>;\nexport type ItemGridBreakpointConfig = z.infer<typeof ItemGridBreakpointSchema>;\nexport type ElementGridConfig = z.infer<typeof ElementGridConfigSchema>;\nexport type GridLayoutConfig = z.infer<typeof GridLayoutConfigSchema>;\n", "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", "import type { ElementGridConfig, GridGapToken, GridLayoutConfig, GridOffsetName, GridWidthName } from '@/schemas/grid';\nimport type { DeepReadonly } from '@/lib/deep-readonly';\nimport { GridGapTokens } from '@/schemas/grid';\nimport {\n\tareasTemplateValue,\n\tBREAKPOINT_ORDER,\n\tcarryNamedPlacement,\n\tCASCADE_SLOTS,\n\tgridAreaTemplates,\n\tusesGridWidths,\n\tWIDTH_SPANS,\n\tWIDTH_TRACKS,\n\ttype CascadeSlot,\n\ttype GridBreakpointToken,\n\ttype NamedPlacement,\n} from '@/lib/grid-placement';\n\n/**\n * Maps authored grid values to theme-scoped CSS variables.\n *\n * @remarks\n * The theme owns the grid vocabulary: breakpoint thresholds, gap tokens,\n * and the default minimum column width. The document owns layout intent:\n * columns, responsive changes, gap selection, item placement.\n *\n * Compile once, with the rest of the layout theme ({@link createLayoutTheme}); renderers\n * emit the resulting stylesheet and per-container CSS variables inline. Breakpoint\n * behavior lives entirely in generated media or container queries \u2014 no runtime\n * observers, and layout is correct with JavaScript disabled.\n *\n * Cascade contract for sparse responsive entries (see tests): initialize from\n * top-level values, apply `responsive.default`, then each successive\n * breakpoint. Within an entry, axis-specific gaps (`gapX`/`gapY`) beat the\n * entry's general `gap`.\n *\n * `place-*` shorthands are resolved into their axis longhands here rather than\n * emitted as CSS. A shorthand declaration would have to follow the longhands\n * in the generated rule and would then reset them, so authored `justifyItems`\n * or `justifySelf` could never take effect. Resolving in one place also lets\n * `placeSelf` join the responsive cascade for free.\n *\n * Only authored values are emitted, as custom properties (not camelCase CSS\n * keys) so the return type is a `--*` record assignable to React\n * `CSSProperties` and to inline `style` attributes without a cast. Neutral\n * defaults, the breakpoint cascade, and the resets that stop a nested grid\n * inheriting its parent's placement all live in the generated stylesheet.\n */\n\n/**\n * Inline style consisting only of CSS custom properties.\n *\n * @remarks\n * React 19 `CSSProperties` indexes `--${string}`; a `string` index does not,\n * which is why earlier `Record<string, string>` returns needed a cast.\n */\nexport type CssVariables = {\n\t[property: `--${string}`]: string | undefined;\n};\n\nexport interface GridThemeOptions {\n\t/**\n\t * Breakpoint thresholds in CSS lengths (`rem` recommended for zoom).\n\t * Overrides only the named token; the rest keep library defaults.\n\t *\n\t * @remarks\n\t * Configured thresholds must preserve named cascade order\n\t * (`sm \u2264 md \u2264 lg \u2264 xl \u2264 2xl`). `rem`/`em` values are compared at a 16px\n\t * root so mixed units cannot invert the sequence.\n\t */\n\tbreakpoints?: Partial<Record<GridBreakpointToken, string>>;\n\t/** Gap token definitions as CSS values, overriding only the named tokens. */\n\tgap?: GridGapScale;\n\t/** Default minimum column width used by `columns: 'auto'` grids. */\n\tminColumnWidth?: string;\n\t/**\n\t * Token values that change from a breakpoint up.\n\t *\n\t * @remarks\n\t * Breakpoint-major, like a document's own `responsive`: one entry per width\n\t * listing the tokens that change there, rather than one entry per token\n\t * listing its widths. Base values stay in `gap`, so there is no `default`\n\t * entry here \u2014 and no collision between the `default` *token* and a\n\t * `default` *slot*.\n\t *\n\t * Tokens are axis-agnostic: a document picks which token each axis uses via\n\t * `gapX`/`gapY`, so a theme never declares an axis.\n\t *\n\t * ```ts\n\t * grid: {\n\t * gap: { default: '1rem', loose: '1.5rem' },\n\t * responsive: {\n\t * md: { default: '1.25rem' },\n\t * lg: { default: '1.5rem', loose: '2rem' },\n\t * },\n\t * }\n\t * ```\n\t */\n\tresponsive?: Partial<Record<GridBreakpointToken, GridGapScale>>;\n\t/**\n\t * What the breakpoints measure: the viewport (`'media'`, the default) or the grid's own available width (`'container'`).\n\t *\n\t * @remarks\n\t * Container mode emits `@container se-grid (min-width: ...)` where media mode emits `@media`, with\n\t * the same breakpoint tokens, gap ramps and cascade, so a document reads the same in both. The\n\t * rules query the nearest ancestor that carries {@link GRID_CONTAINER_CLASS}, which an element\n\t * cannot be for its own children's placement: the renderer wraps each grid in one, and markup you\n\t * write wraps each grid itself. A grid with no such ancestor never matches a breakpoint and keeps\n\t * its base layout.\n\t *\n\t * The theme decides how breakpoints are queried and the document says what changes at each, so a\n\t * document is unchanged by where it is mounted. In a container query `em` resolves against the\n\t * container's font size.\n\t */\n\tquery?: GridQueryMode;\n}\n\n/** How a theme's breakpoints are queried; see {@link GridThemeOptions.query}. */\nexport type GridQueryMode = 'media' | 'container';\n\n/** Gap token values at one width. Unlisted tokens keep the value from the next narrower width. */\nexport type GridGapScale = Partial<Record<GridGapToken, string>>;\n\nexport interface NormalizedGridTheme {\n\treadonly breakpoints: Readonly<Record<GridBreakpointToken, string>>;\n\treadonly gap: Readonly<Record<GridGapToken, string>>;\n\t/** Token overrides per breakpoint; only the tokens a width changes. */\n\treadonly responsive: Readonly<Partial<Record<GridBreakpointToken, Readonly<GridGapScale>>>>;\n\treadonly minColumnWidth: string;\n\treadonly query: GridQueryMode;\n}\n\nconst DEFAULT_BREAKPOINTS: Record<GridBreakpointToken, string> = {\n\tsm: '40rem',\n\tmd: '48rem',\n\tlg: '64rem',\n\txl: '80rem',\n\t'2xl': '96rem',\n};\n\nconst DEFAULT_GAP: Record<GridGapToken, string> = {\n\tnone: '0',\n\tcompact: '0.5rem',\n\tdefault: 'var(--space-stack, 1rem)',\n\tloose: 'var(--space-block-lg, 1.5rem)',\n\twide: 'var(--space-block-xl, 2rem)',\n};\n\nconst DEFAULT_MIN_COLUMN_WIDTH = '15.625rem';\n\n/**\n * Public gap tokens. Hosts override these at `:root` to restyle every grid.\n *\n * @remarks\n * The theme must never declare these on an element: an element's own\n * declaration beats an inherited one, which would make the documented `:root`\n * override a no-op. The theme's value is declared under\n * {@link gapBaseVariable} instead and reached through a `var()` fallback.\n *\n * A host override therefore replaces the token at *every* width, including one\n * a theme ramps through `responsive` \u2014 the public token is the first `var()`\n * argument and a ramp only ever redeclares the fallback. A host that wants its\n * own rhythm declares its own media queries.\n */\nconst GAP_TOKEN_VARIABLES: Record<GridGapToken, `--${string}`> = {\n\tnone: '--se-grid-gap-none',\n\tcompact: '--se-grid-gap-compact',\n\tdefault: '--se-grid-gap-default',\n\tloose: '--se-grid-gap-loose',\n\twide: '--se-grid-gap-wide',\n};\n\n/** Theme default for a gap token, shadowed by the public token when a host sets it. */\nfunction gapBaseVariable(token: GridGapToken): `--${string}` {\n\treturn `--se-grid-gap-base-${token}`;\n}\n\n/** A gap token as CSS: the host's override if present, else the theme default. */\nfunction gapTokenValue(token: GridGapToken): string {\n\treturn `var(${GAP_TOKEN_VARIABLES[token]}, var(${gapBaseVariable(token)}))`;\n}\n\nconst DEFAULT_GAP_CSS = gapTokenValue('default');\n\n/**\n * Variable a host sets on an item to choose the display the item rule applies.\n *\n * @remarks\n * The item rule outranks a component's own `display` (class plus attribute\n * beats a lone class), so a host that needs its own layout sets this variable\n * rather than `display`. Responsive `hidden` then toggles between `none` and\n * that mode instead of forcing `block`. Custom properties inherit, so the grid\n * rule resets it: a fieldset that sets `grid` for itself must not turn the\n * fields of its own grid into grids.\n */\nconst ITEM_DISPLAY_MODE_VARIABLE = '--se-item-display-mode';\n\n/** Display a visible item falls back to. See {@link ITEM_DISPLAY_MODE_VARIABLE}. */\nconst ITEM_DISPLAY_MODE = `var(${ITEM_DISPLAY_MODE_VARIABLE}, block)`;\n\n/** Root font size used when comparing `rem`/`em` breakpoint thresholds. */\nconst ROOT_FONT_PX = 16;\n\ntype CssLengthUnit = 'px' | 'rem' | 'em';\n\n/** CSS property, its variable base name, and the value used when unauthored. */\ntype ResponsiveProperty = readonly [property: string, variable: string, fallback: string];\n\nfunction deepFreeze<T extends object>(value: T): T {\n\tObject.freeze(value);\n\tfor (const child of Object.values(value)) {\n\t\tif (child !== null && typeof child === 'object' && !Object.isFrozen(child)) {\n\t\t\tdeepFreeze(child);\n\t\t}\n\t}\n\treturn value;\n}\n\n/** Drops empty entries so an unramped theme normalizes to `{}` and emits nothing extra. */\nfunction resolveResponsiveGap(\n\toverrides?: Partial<Record<GridBreakpointToken, GridGapScale>>,\n): Partial<Record<GridBreakpointToken, GridGapScale>> {\n\tconst resolved: Partial<Record<GridBreakpointToken, GridGapScale>> = {};\n\tfor (const breakpoint of BREAKPOINT_ORDER) {\n\t\tconst entry = overrides?.[breakpoint];\n\t\tconst tokens = GridGapTokens.filter((token) => entry?.[token] !== undefined);\n\t\tif (tokens.length > 0) {\n\t\t\tresolved[breakpoint] = Object.fromEntries(tokens.map((token) => [token, entry![token]])) as GridGapScale;\n\t\t}\n\t}\n\treturn resolved;\n}\n\n/**\n * Resolves the immutable grid theme from the `grid` option of a layout theme.\n *\n * @remarks\n * Threshold overrides replace only the named breakpoint; the rest keep\n * library defaults. Thresholds accept `px`/`rem`/`em` lengths and must\n * preserve named cascade order. `rem`/`em` compare at a 16px root.\n * Media queries (the default `query`) follow viewport width \u2014 a grid inside a\n * narrow sidebar still receives the desktop rules of the wide screen it lives\n * on; `query: 'container'` follows the grid's wrapper instead.\n */\nexport function resolveGridTheme(options?: GridThemeOptions): NormalizedGridTheme {\n\tconst breakpoints = { ...DEFAULT_BREAKPOINTS, ...options?.breakpoints };\n\tconst gap = { ...DEFAULT_GAP, ...options?.gap };\n\tconst responsive = resolveResponsiveGap(options?.responsive);\n\tconst minColumnWidth = options?.minColumnWidth ?? DEFAULT_MIN_COLUMN_WIDTH;\n\tconst query = options?.query ?? 'media';\n\tassertBreakpointOrder(breakpoints);\n\tassertQueryMode(query);\n\treturn deepFreeze({\n\t\tbreakpoints,\n\t\tgap,\n\t\tresponsive,\n\t\tminColumnWidth,\n\t\tquery,\n\t});\n}\n\nfunction assertQueryMode(query: string): asserts query is GridQueryMode {\n\tif (query !== 'media' && query !== 'container') {\n\t\tthrow new Error(`Grid theme query must be 'media' or 'container'; received '${query}'.`);\n\t}\n}\n\nfunction isCssLengthUnit(unit: string | undefined): unit is CssLengthUnit {\n\treturn unit === 'px' || unit === 'rem' || unit === 'em';\n}\n\nfunction thresholdToPx(token: GridBreakpointToken, threshold: string): number {\n\tconst match = /^(\\d+(?:\\.\\d+)?)(px|rem|em)$/.exec(threshold);\n\tconst rawUnit = match?.[2];\n\tif (!match || !isCssLengthUnit(rawUnit)) {\n\t\tthrow new Error(`Grid theme breakpoint '${token}' must be a px, rem, or em length; received '${threshold}'.`);\n\t}\n\tconst value = Number(match[1]);\n\treturn rawUnit === 'px' ? value : value * ROOT_FONT_PX;\n}\n\nfunction assertBreakpointOrder(breakpoints: Record<GridBreakpointToken, string>): void {\n\tlet previousPx = Number.NEGATIVE_INFINITY;\n\tlet previousToken: GridBreakpointToken | undefined;\n\tfor (const token of BREAKPOINT_ORDER) {\n\t\tconst threshold = breakpoints[token];\n\t\tconst px = thresholdToPx(token, threshold);\n\t\tif (previousToken !== undefined && px < previousPx) {\n\t\t\tthrow new Error(\n\t\t\t\t`Grid theme breakpoints must preserve cascade order sm \u2264 md \u2264 lg \u2264 xl \u2264 2xl (rem/em compared at ${ROOT_FONT_PX}px root); '${token}' (${threshold}) is smaller than '${previousToken}' (${breakpoints[previousToken]}).`,\n\t\t\t);\n\t\t}\n\t\tpreviousPx = px;\n\t\tpreviousToken = token;\n\t}\n}\n\n/**\n * Responsive gap overrides as ordered pairs, independent of authored key order.\n *\n * @remarks\n * These come from consumer options, so `{ md, lg }` and `{ lg, md }` describe\n * one theme with different `JSON.stringify` output. Hashing that directly would\n * mint two ids for the same theme and emit its stylesheet twice under different\n * scopes, defeating the sharing of one compiled theme.\n */\nfunction canonicalResponsiveGap(\n\tresponsive: Readonly<Partial<Record<GridBreakpointToken, Readonly<GridGapScale>>>>,\n): Array<[string, Array<[string, string]>]> {\n\treturn BREAKPOINT_ORDER.flatMap((breakpoint) => {\n\t\tconst entry = responsive[breakpoint];\n\t\tif (!entry) return [];\n\t\tconst tokens = GridGapTokens.flatMap((token) => {\n\t\t\tconst value = entry[token];\n\t\t\treturn value === undefined ? [] : [[token, value] as [string, string]];\n\t\t});\n\t\treturn [[breakpoint, tokens] as [string, Array<[string, string]>]];\n\t});\n}\n\n/**\n * The normalized grid theme in a stable shape, for hashing into a layout theme id.\n *\n * @remarks\n * The default query mode is left out, so a media theme keeps the id it had before the option existed.\n */\nexport function canonicalGridTheme(theme: NormalizedGridTheme) {\n\treturn {\n\t\tbreakpoints: theme.breakpoints,\n\t\tgap: theme.gap,\n\t\tresponsive: canonicalResponsiveGap(theme.responsive),\n\t\tminColumnWidth: theme.minColumnWidth,\n\t\t...(theme.query === 'media' ? {} : { query: theme.query }),\n\t};\n}\n\n/**\n * Class a grid container carries, and the stylesheet's hook for it.\n *\n * @remarks\n * Neutral on purpose: a domain's renderer adds this beside its own class,\n * so a step, a page section and a container of any domain share one set of rules. The stylesheet\n * keys on this class, {@link GRID_ITEM_CLASS} and `[data-se-theme]` only, with no alias for a\n * domain's own class.\n */\nexport const GRID_CLASS = 'se-grid';\n\n/**\n * Class an element placed in a grid carries, and the stylesheet's hook for it. See {@link GRID_CLASS}.\n *\n * @remarks\n * An item and the grid it contains must be different elements, as they are in both renderers. An item's\n * `span` reads the track count its parent grid computed, and an element that is both would read its own.\n */\nexport const GRID_ITEM_CLASS = 'se-grid-item';\n\n/**\n * Class of every box that passes its parent grid's column tracks down to a nested grid, and the stylesheet's hook for it.\n *\n * @remarks\n * `grid-template-columns: subgrid` only works on a grid item of the grid whose tracks it takes, so the\n * element with `grid.subgrid`, every box between it and the grid that lays out its children, and that\n * {@link GRID_CLASS} grid itself must all carry this class. A box in the chain that does not (a plain\n * `div`) computes its template to `none` and the children fall back to one column, with nothing reported.\n *\n * Keep a `<fieldset>` out of the chain: Chromium lays a fieldset's content out in an anonymous box that does\n * not take the subgrid, so its children fall back to one column there (Firefox and WebKit pass the tracks on).\n * Use a box with `role=\"group\"` and `aria-labelledby` its heading instead, which gives the same group and name\n * to assistive technology in every engine; `display: contents` on the fieldset is no answer, since engines expose\n * its semantics inconsistently. The grid of the children gets no tracks of its own, so it takes no\n * {@link GRID_CONTAINER_CLASS} wrapper either: layout containment would make it an independent formatting\n * context, and a subgrid inside one is `none`. Its breakpoints are queried against the container of the grid\n * the chain hangs from.\n */\nexport const GRID_SUBGRID_CLASS = 'se-subgrid';\n\n/**\n * Class of the element a grid in a `query: 'container'` theme is measured against, and the stylesheet's hook for it.\n *\n * @remarks\n * Put it, with `data-se-theme`, on an element that wraps one grid and fills its parent: the\n * breakpoints then follow that element's width. It must be an ancestor of the grid, because the\n * template of a grid and the placement of its items have to query one box, and an element cannot\n * query its own size. The stylesheet declares it only in container mode, as a block with\n * `container-type: inline-size`. Inline-size containment means it no longer sizes to its content, so\n * it collapses in a shrink-to-fit parent (an inline-block, a flex item without a basis, an `auto` grid\n * track). Wrap each grid, nested grids included, so an inner grid follows its own box.\n */\nexport const GRID_CONTAINER_CLASS = 'se-grid-container';\n\n/** Name of the container the container-mode rules query, so an unrelated container in between cannot capture them. */\nconst GRID_CONTAINER_NAME = 'se-grid';\n\n/**\n * Custom property a grid declares with the number of column tracks its template draws, which its items read to clamp a `span`.\n *\n * @remarks\n * It is a row of {@link GRID_PROPERTIES}, so it follows the template through the same gated cascade, per\n * slot and in both query modes, and a `span` clamps at the width the template switches at. The renderer\n * writes the count beside each template as `--se-grid-tracks[-slot]` ({@link getGridVariables}); an\n * unauthored grid draws one track. A subgrid inherits the resolved count of the grid it sits in, since\n * its children are placed on that grid's tracks.\n */\nconst TRACK_COUNT_VARIABLE = '--se-grid-track-count';\n\n/**\n * Grid container properties that change per breakpoint.\n *\n * @remarks\n * One table drives the base rule, every media query, and the inheritance\n * resets, so a property cannot be declared at one width and forgotten at\n * another.\n */\nconst GRID_PROPERTIES: readonly ResponsiveProperty[] = [\n\t['grid-template-columns', 'se-grid-template', 'repeat(1, minmax(0, 1fr))'],\n\t['grid-template-areas', 'se-grid-areas', 'none'],\n\t['row-gap', 'se-grid-gap-y', DEFAULT_GAP_CSS],\n\t['column-gap', 'se-grid-gap-x', DEFAULT_GAP_CSS],\n\t[TRACK_COUNT_VARIABLE, 'se-grid-tracks', '1'],\n];\n\n/**\n * Placement an item takes when it sets none, declared on its grid.\n *\n * @remarks\n * A grid whose items use named widths has 12 tracks, so an item that sets no\n * width would otherwise fall into one of them. The grid declares `1 / -1` here\n * and the item's `grid-column` falls back to it, which keeps the rule in the\n * stylesheet. The grid rule resets it so a nested grid does not inherit its\n * parent's default.\n */\nconst DEFAULT_COLUMN_VARIABLE = '--se-grid-default-column';\n\n/**\n * Item placement properties that change per breakpoint.\n *\n * @remarks\n * `justify-self`/`align-self` fall back to `auto`, which defers to the grid's\n * own `justify-items`/`align-items`. Any other fallback would silently beat\n * grid-level alignment on every item.\n */\nconst ITEM_PROPERTIES: readonly ResponsiveProperty[] = [\n\t['display', 'se-item-display', ITEM_DISPLAY_MODE],\n\t['grid-column', 'se-item-grid-column', `var(${DEFAULT_COLUMN_VARIABLE}, auto)`],\n\t['grid-row', 'se-item-grid-row', 'auto'],\n\t['justify-self', 'se-item-justify-self', 'auto'],\n\t['align-self', 'se-item-align-self', 'auto'],\n\t['margin-block-start', 'se-item-margin-block-start', '0'],\n\t['margin-block-end', 'se-item-margin-block-end', '0'],\n];\n\n/** Grid alignment, authored once for all widths. */\nconst GRID_ALIGNMENT_PROPERTIES: readonly ResponsiveProperty[] = [\n\t['justify-items', 'se-grid-justify-items', 'normal'],\n\t['align-items', 'se-grid-align-items', 'normal'],\n\t['justify-content', 'se-grid-justify-content', 'normal'],\n\t['align-content', 'se-grid-align-content', 'start'],\n\t['grid-auto-flow', 'se-grid-auto-flow', 'row'],\n];\n\n/** Removes the space after each comma of a stylesheet-only fallback, which `var()` ignores. */\nfunction tight(fallback: string): string {\n\treturn fallback.replaceAll(', ', ',');\n}\n\n/**\n * Name of the stylesheet-private custom property that gates one cascade slot of one table row.\n *\n * @remarks\n * A gate is declared inside the slot's media query as a copy of the public slot variable, so\n * outside that query it is the guaranteed-invalid value and the `var()` chain skips it. The names\n * are private to the stylesheet (a form never writes them, and they carry no contract) and carry\n * the theme id: custom properties inherit, so a gate named alike in two themes would let a theme\n * with a wider threshold read the gate its ancestor's narrower query declared. In a media theme\n * every element of a theme shares the viewport, so one that is reached declares its own gates\n * wherever the query applies and needs no reset. A container theme measures each grid against its\n * own container, so a nested grid can sit below a breakpoint its ancestor is above and would read the\n * ancestor's gate: its rules reset every gate ({@link gateResets}).\n *\n * Read a name in devtools as theme id, table (`g` grid, `i` item), the property's row in that\n * table, and the breakpoint token: `--l1abc-i1md` is the `md` gate of the item `grid-column`.\n */\nfunction gateName(themeId: string, table: string, row: number, slot: GridBreakpointToken): string {\n\treturn `--${themeId}-${table}${row}${slot}`;\n}\n\n/**\n * `var(--g-2xl, var(--g-xl, ... var(--x, fallback)))`: the widest slot whose media query applies wins.\n *\n * @remarks\n * The chain is written once, in the base rule. A slot's gate is declared only inside its media\n * query (see {@link gateName}), so the cascade across widths costs one short declaration per slot\n * instead of restating the whole chain in every query. An unset slot resolves to the nearest\n * narrower one, so a renderer emits only the breakpoints an author wrote.\n */\nfunction cascadingVar(themeId: string, table: string, row: number, variable: string, fallback: string): string {\n\tlet value = `var(--${variable},${tight(fallback)})`;\n\tfor (const slot of BREAKPOINT_ORDER) {\n\t\tvalue = `var(${gateName(themeId, table, row, slot)},${value})`;\n\t}\n\treturn value;\n}\n\nfunction declarations(themeId: string, table: string, properties: readonly ResponsiveProperty[]): string {\n\treturn properties\n\t\t.map(\n\t\t\t([property, variable, fallback], row) =>\n\t\t\t\t`${property}:${cascadingVar(themeId, table, row, variable, fallback)};`,\n\t\t)\n\t\t.join('');\n}\n\n/** Alignment is authored once for all widths, so it has no slots and no gates. */\nfunction flatDeclarations(properties: readonly ResponsiveProperty[]): string {\n\treturn properties\n\t\t.map(([property, variable, fallback]) => `${property}:var(--${variable},${tight(fallback)});`)\n\t\t.join('');\n}\n\n/** One slot's gates: each property's public slot variable, copied inside the slot's media query. */\nfunction gates(\n\tthemeId: string,\n\ttable: string,\n\tproperties: readonly ResponsiveProperty[],\n\tslot: GridBreakpointToken,\n): string {\n\treturn properties\n\t\t.map(([, variable], row) => `${gateName(themeId, table, row, slot)}:var(--${variable}-${slot});`)\n\t\t.join('');\n}\n\n/**\n * Resets every slot so custom properties do not inherit past a host.\n *\n * @remarks\n * Custom properties inherit, so a nested grid or item would otherwise pick up\n * its ancestor's placement. `initial` makes `var()` fall through to the chain\n * above, and an inline value on the same element still wins the cascade.\n * Only a table with slots resets them: alignment is authored once for all widths, so its\n * slot variables are never written and never read.\n */\nfunction inheritanceResets(properties: readonly ResponsiveProperty[], withSlots: boolean): string {\n\treturn properties\n\t\t.flatMap(([, variable]) => [\n\t\t\t`--${variable}`,\n\t\t\t...(withSlots ? BREAKPOINT_ORDER.map((slot) => `--${variable}-${slot}`) : []),\n\t\t])\n\t\t.map((name) => `${name}:initial;`)\n\t\t.join('');\n}\n\n/**\n * Resets every gate of a table, so an element reads only the gates its own container's query declares.\n *\n * @remarks\n * A gate is declared on the element a query matches and inherits from there. Under a container query a\n * nested grid or item sits in a narrower container than its ancestors, so the breakpoint they match\n * can be one it does not, and it would take their resolved values over its own cascade. `initial`\n * returns the gate to the guaranteed-invalid value, which the `var()` chain skips; the element's own\n * matching query block comes later in the sheet at the same specificity and declares it again.\n */\nfunction gateResets(themeId: string, table: string, properties: readonly ResponsiveProperty[]): string {\n\treturn properties\n\t\t.flatMap((_, row) => BREAKPOINT_ORDER.map((slot) => `${gateName(themeId, table, row, slot)}:initial;`))\n\t\t.join('');\n}\n\n/**\n * Generates the theme-scoped stylesheet.\n *\n * @remarks\n * Rules are scoped under `[data-se-theme=\"<id>\"]`, which the renderer\n * places on every grid container and item, so two themes that differ\n * cannot overwrite each other. Item rules are scoped under the item that\n * carries the theme attribute so nested grids do not leak styles across themes.\n * Selectors use only {@link GRID_CLASS}, {@link GRID_ITEM_CLASS} and that attribute.\n *\n * Each responsive property is declared once, in the base rule, as a `var()` chain over the\n * slot gates ({@link gateName}); a media query only declares the gates of its slot.\n * A `query: 'container'` theme changes the at-rule, to `@container se-grid`, adds the rule of\n * {@link GRID_CONTAINER_CLASS} and resets each grid's and item's gates in its base rule\n * ({@link gateResets}); a media theme emits neither.\n *\n * @param theme The resolved grid vocabulary.\n * @param themeId The id of the layout theme the rules are scoped to.\n */\nexport function getGridThemeCss(theme: NormalizedGridTheme, themeId: string): string {\n\tconst scope = `[data-se-theme=\"${themeId}\"]`;\n\tconst gridScope = `.${GRID_CLASS}${scope}`;\n\tconst itemScope = `.${GRID_ITEM_CLASS}${scope}`;\n\tconst subgridScope = `.${GRID_SUBGRID_CLASS}${scope}`;\n\tconst tokens = GridGapTokens.map((token) => `${gapBaseVariable(token)}:${theme.gap[token]};`).join('');\n\tconst container = theme.query === 'container';\n\tconst atRule = container ? `@container ${GRID_CONTAINER_NAME}` : '@media';\n\tconst lines: string[] = [\n\t\t`${scope}{${tokens}}`,\n\t\t...(container\n\t\t\t? [\n\t\t\t\t\t`.${GRID_CONTAINER_CLASS}${scope}{display:block;width:100%;min-width:0;container-type:inline-size;container-name:${GRID_CONTAINER_NAME};}`,\n\t\t\t\t]\n\t\t\t: []),\n\t\t`${subgridScope}{${ITEM_DISPLAY_MODE_VARIABLE}:grid;display:grid;grid-template-columns:subgrid;column-gap:normal;align-content:start;}`,\n\t\t`${subgridScope}>:not(.${GRID_ITEM_CLASS}){grid-column:1/-1;}`,\n\t\t`${gridScope}{${container ? gateResets(themeId, 'g', GRID_PROPERTIES) : ''}${inheritanceResets(GRID_PROPERTIES, true)}${inheritanceResets(GRID_ALIGNMENT_PROPERTIES, false)}${DEFAULT_COLUMN_VARIABLE}:initial;${ITEM_DISPLAY_MODE_VARIABLE}:initial;display:grid;${declarations(themeId, 'g', GRID_PROPERTIES)}${flatDeclarations(GRID_ALIGNMENT_PROPERTIES)}}`,\n\t\t`.${GRID_CLASS}${subgridScope}{--se-grid-template:subgrid;--se-grid-gap-x:normal;${DEFAULT_COLUMN_VARIABLE}:inherit;${TRACK_COUNT_VARIABLE}:inherit;}`,\n\t\t`${itemScope}{${container ? gateResets(themeId, 'i', ITEM_PROPERTIES) : ''}${inheritanceResets(ITEM_PROPERTIES, true)}${declarations(themeId, 'i', ITEM_PROPERTIES)}}`,\n\t];\n\tfor (const breakpoint of BREAKPOINT_ORDER) {\n\t\tconst ramped = theme.responsive[breakpoint];\n\t\tconst rampedTokens = ramped\n\t\t\t? GridGapTokens.filter((token) => ramped[token] !== undefined)\n\t\t\t\t\t.map((token) => `${gapBaseVariable(token)}:${ramped[token]};`)\n\t\t\t\t\t.join('')\n\t\t\t: '';\n\t\tlines.push(\n\t\t\t`${atRule} (min-width:${theme.breakpoints[breakpoint]}){${rampedTokens ? `${scope}{${rampedTokens}}` : ''}${gridScope}{${gates(themeId, 'g', GRID_PROPERTIES, breakpoint)}}${itemScope}{${gates(themeId, 'i', ITEM_PROPERTIES, breakpoint)}}}`,\n\t\t);\n\t}\n\treturn lines.join('\\n');\n}\n\nfunction isGridGapToken(value: string): value is GridGapToken {\n\tfor (const token of GridGapTokens) {\n\t\tif (token === value) return true;\n\t}\n\treturn false;\n}\n\n/**\n * Maps an authored gap value (semantic token or raw CSS value) to its\n * variable reference or literal.\n */\nfunction resolveGridGap(value: string | undefined): string | undefined {\n\tif (value === undefined) return undefined;\n\tif (isGridGapToken(value)) {\n\t\treturn gapTokenValue(value);\n\t}\n\treturn value;\n}\n\n/** Keywords that qualify the position keyword that follows them. */\nconst AXIS_QUALIFIERS = new Set(['safe', 'unsafe', 'first', 'last']);\n\n/**\n * Splits a `place-*` shorthand into `[align, justify]` per the CSS grammar.\n *\n * @remarks\n * The shorthand is align-first and a single axis value sets both axes \u2014 but an\n * axis value can be two keywords, an overflow position (`safe`/`unsafe`) or a\n * baseline modifier (`first`/`last`) plus its position. So `safe center` is one\n * value for both axes, while `center start` is one value per axis. Splitting on\n * whitespace alone would emit `align-self: safe`, which is not valid CSS.\n */\nfunction splitPlaceShorthand(value: string | undefined): [string | undefined, string | undefined] {\n\tif (value === undefined) return [undefined, undefined];\n\tconst tokens = value.trim().split(/\\s+/).filter(Boolean);\n\tif (tokens.length === 0) return [undefined, undefined];\n\tconst alignLength = AXIS_QUALIFIERS.has(tokens[0] as string) && tokens.length > 1 ? 2 : 1;\n\tconst align = tokens.slice(0, alignLength).join(' ');\n\tconst justify = alignLength < tokens.length ? tokens.slice(alignLength).join(' ') : align;\n\treturn [align, justify];\n}\n\nfunction toGridTemplate(columns: number | 'auto', minColumnWidth: string): string {\n\tif (columns === 'auto') {\n\t\treturn `repeat(auto-fit, minmax(min(${minColumnWidth}, 100%), 1fr))`;\n\t}\n\treturn `repeat(${columns}, minmax(0, 1fr))`;\n}\n\nfunction customProperty(name: string, slot: CascadeSlot): `--${string}` {\n\treturn slot === 'default' ? `--${name}` : `--${name}-${slot}`;\n}\n\n/** Layout values a single cascade slot may set; the top-level config is the `default` slot. */\ninterface GridEntry {\n\tcolumns?: number | 'auto';\n\tminColumnWidth?: string;\n\tgap?: string;\n\tgapX?: string;\n\tgapY?: string;\n}\n\n/** Placement a single cascade slot may set; the top-level config is the `default` slot. */\ninterface GridItemEntry {\n\tarea?: string;\n\twidth?: GridWidthName;\n\toffset?: GridOffsetName;\n\tspan?: number;\n\tcolumn?: number | string;\n\trow?: number | string;\n\tjustifySelf?: string;\n\talignSelf?: string;\n\thidden?: boolean;\n\tmarginBlockStart?: string;\n\tmarginBlockEnd?: string;\n}\n\nfunction emitGapEntry(variables: CssVariables, slot: CascadeSlot, entry: GridEntry | undefined): void {\n\tif (!entry) return;\n\tconst entryGap = resolveGridGap(entry.gap);\n\tconst gapX = resolveGridGap(entry.gapX) ?? entryGap;\n\tconst gapY = resolveGridGap(entry.gapY) ?? entryGap;\n\tif (gapY !== undefined) variables[customProperty('se-grid-gap-y', slot)] = gapY;\n\tif (gapX !== undefined) variables[customProperty('se-grid-gap-x', slot)] = gapX;\n}\n\n/**\n * Resolves a grid against the theme into one inline style record.\n *\n * @remarks\n * Only values an author wrote are emitted; the generated stylesheet falls back\n * through the narrower breakpoints, so an unconfigured grid carries no inline\n * style. `columns` and `minColumnWidth` are the one coupled pair \u2014 they share a\n * single template \u2014 so they are the only values carried across slots. Axis\n * properties win over the matching `placeItems`/`placeContent` shorthand.\n *\n * When `elements` (the items this grid places) use named widths, the grid\n * gets 12 tracks and a `1 / -1` default placement for items that set no width. Validation keeps that from meeting `columns`.\n * The items include the children of every subgrid element, however deep, because a subgrid places\n * them on this grid's tracks; a domain walks its children and passes them in. The grid of a subgrid\n * has no tracks of its own, so its renderer does not call this.\n *\n * A grid with `areas` gets the template of each slot that sets one: the quoted\n * rows as `--se-grid-areas` and the track count they draw as `--se-grid-template`,\n * derived from the rows rather than authored, as with named widths.\n */\nexport function getGridVariables(\n\tgrid: DeepReadonly<GridLayoutConfig> | undefined,\n\ttheme: NormalizedGridTheme,\n\telements: readonly unknown[],\n): CssVariables {\n\tconst variables: CssVariables = {};\n\n\tconst [placeAlignItems, placeJustifyItems] = splitPlaceShorthand(grid?.placeItems);\n\tconst [placeAlignContent, placeJustifyContent] = splitPlaceShorthand(grid?.placeContent);\n\tconst alignment: Record<string, string | undefined> = {\n\t\t'--se-grid-justify-items': grid?.justifyItems ?? placeJustifyItems,\n\t\t'--se-grid-align-items': grid?.alignItems ?? placeAlignItems,\n\t\t'--se-grid-justify-content': grid?.justifyContent ?? placeJustifyContent,\n\t\t'--se-grid-align-content': grid?.alignContent ?? placeAlignContent,\n\t\t'--se-grid-auto-flow': grid?.autoFlow,\n\t};\n\tfor (const [name, value] of Object.entries(alignment)) {\n\t\tif (value !== undefined) variables[name as `--${string}`] = value;\n\t}\n\n\tlet columns: number | 'auto' = 1;\n\tlet minColumnWidth = theme.minColumnWidth;\n\tconst emitTemplate = (slot: CascadeSlot, entry: GridEntry | undefined): void => {\n\t\tif (!entry) return;\n\t\tif (entry.columns === undefined && entry.minColumnWidth === undefined) return;\n\t\tif (entry.columns !== undefined) columns = entry.columns;\n\t\tif (entry.minColumnWidth !== undefined) minColumnWidth = entry.minColumnWidth;\n\t\tvariables[customProperty('se-grid-template', slot)] = toGridTemplate(columns, minColumnWidth);\n\t\tvariables[customProperty('se-grid-tracks', slot)] = String(columns === 'auto' ? 1 : columns);\n\t};\n\n\tif (usesGridWidths(elements)) {\n\t\tvariables['--se-grid-template'] = `repeat(${WIDTH_TRACKS}, minmax(0, 1fr))`;\n\t\tvariables['--se-grid-tracks'] = String(WIDTH_TRACKS);\n\t\tvariables[DEFAULT_COLUMN_VARIABLE] = '1 / -1';\n\t}\n\n\tconst templates = gridAreaTemplates(grid);\n\tfor (const slot of CASCADE_SLOTS) {\n\t\tconst rows = templates[slot];\n\t\tif (!rows) continue;\n\t\tvariables[customProperty('se-grid-areas', slot)] = areasTemplateValue(rows);\n\t\tvariables[customProperty('se-grid-template', slot)] = toGridTemplate(\n\t\t\trows[0]?.length ?? 1,\n\t\t\ttheme.minColumnWidth,\n\t\t);\n\t\tvariables[customProperty('se-grid-tracks', slot)] = String(rows[0]?.length ?? 1);\n\t}\n\n\tconst responsive = grid?.responsive;\n\temitTemplate('default', grid);\n\temitTemplate('default', responsive?.default);\n\temitGapEntry(variables, 'default', grid);\n\temitGapEntry(variables, 'default', responsive?.default);\n\n\tfor (const breakpoint of BREAKPOINT_ORDER) {\n\t\temitTemplate(breakpoint, responsive?.[breakpoint]);\n\t\temitGapEntry(variables, breakpoint, responsive?.[breakpoint]);\n\t}\n\treturn variables;\n}\n\n/**\n * `grid-column` for a width and offset.\n *\n * @remarks\n * Both names resolve into one declaration, so a slot that authors only one of\n * them is emitted together with the other as the narrower slots left it \u2014\n * the same coupling `columns` and `minColumnWidth` have for the grid template.\n * An offset with no width runs to the end of the row.\n */\nfunction namedColumn({ width, offset }: NamedPlacement): string {\n\tconst start = offset === undefined ? undefined : WIDTH_SPANS[offset] + 1;\n\tif (width === undefined) return start === undefined ? 'auto' : `${start} / -1`;\n\tconst span = `span ${WIDTH_SPANS[width]}`;\n\treturn start === undefined ? span : `${start} / ${span}`;\n}\n\n/**\n * `grid-column` for a numeric span: `n` tracks, or the grid's own track count when that is fewer.\n *\n * @remarks\n * The count is {@link TRACK_COUNT_VARIABLE}, which the item inherits from the grid it sits in, so the clamp\n * changes at the width the grid's template does. `var()` inside `min()` inside a grid line is valid in Chromium,\n * Firefox and WebKit (the browser test of this package measures it); a grid that publishes no count gives\n * one track, never an implicit column.\n */\nfunction spanColumn(span: number): string {\n\treturn `span min(${span},var(${TRACK_COUNT_VARIABLE},1))`;\n}\n\nfunction formatGridLine(value: number | string): string {\n\treturn typeof value === 'number' ? String(value) : value;\n}\n\nfunction emitItemEntry(\n\tvariables: CssVariables,\n\tslot: CascadeSlot,\n\tentry: GridItemEntry | undefined,\n\tnamed: NamedPlacement = {},\n): void {\n\tif (!entry) return;\n\tif (entry.width !== undefined || entry.offset !== undefined) {\n\t\tcarryNamedPlacement(named, entry);\n\t\tvariables[customProperty('se-item-grid-column', slot)] = namedColumn(named);\n\t}\n\tif (entry.span !== undefined) {\n\t\tvariables[customProperty('se-item-grid-column', slot)] = spanColumn(entry.span);\n\t}\n\tif (entry.area !== undefined) {\n\t\tvariables[customProperty('se-item-grid-column', slot)] = entry.area;\n\t\tvariables[customProperty('se-item-grid-row', slot)] = entry.area;\n\t}\n\tif (entry.column !== undefined) {\n\t\tvariables[customProperty('se-item-grid-column', slot)] = formatGridLine(entry.column);\n\t}\n\tif (entry.row !== undefined) variables[customProperty('se-item-grid-row', slot)] = formatGridLine(entry.row);\n\tif (entry.justifySelf !== undefined) variables[customProperty('se-item-justify-self', slot)] = entry.justifySelf;\n\tif (entry.alignSelf !== undefined) variables[customProperty('se-item-align-self', slot)] = entry.alignSelf;\n\tconst marginBlockStart = resolveGridGap(entry.marginBlockStart);\n\tif (marginBlockStart !== undefined) {\n\t\tvariables[customProperty('se-item-margin-block-start', slot)] = marginBlockStart;\n\t}\n\tconst marginBlockEnd = resolveGridGap(entry.marginBlockEnd);\n\tif (marginBlockEnd !== undefined) {\n\t\tvariables[customProperty('se-item-margin-block-end', slot)] = marginBlockEnd;\n\t}\n\tif (entry.hidden !== undefined) {\n\t\tvariables[customProperty('se-item-display', slot)] = entry.hidden ? 'none' : ITEM_DISPLAY_MODE;\n\t}\n}\n\n/**\n * Resolves a single element's grid placement and spacing into inline style variables.\n *\n * @remarks\n * Each slot emits exactly what its entry authored \u2014 no value is carried across\n * breakpoints, because the generated stylesheet already falls back through the\n * narrower slots. The one exception is `width` and `offset`, which share the\n * single `grid-column` declaration (see {@link namedColumn}). An `area` is one\n * name written to both `grid-column` and `grid-row`, where a lone name reads as\n * that area's start and end lines. An element without a `grid` config produces\n * no inline style.\n * `placeSelf` is applied before the axis properties, so those win.\n *\n * `subgrid` makes the element span `1 / -1`, its parent's whole row. It is the only placement a\n * subgrid takes, so validation rejects the other column keys beside it, and the stylesheet does the rest\n * under {@link GRID_SUBGRID_CLASS}.\n *\n * `marginBlockStart`/`marginBlockEnd` accept the same gap tokens as the grid, so\n * a one-off rhythm around a non-input element reads in the same vocabulary as\n * the grid's spacing. They ride the shared item property table rather than a\n * separate mechanism, which is what gives them the breakpoint cascade and the\n * inheritance resets for free \u2014 and keeps a single system owning the block axis\n * instead of two fighting over it.\n */\nexport function getGridItemVariables(grid?: ElementGridConfig): CssVariables {\n\tconst variables: CssVariables = {};\n\tconst [alignSelf, justifySelf] = splitPlaceShorthand(grid?.placeSelf);\n\n\tif (grid?.subgrid) variables['--se-item-grid-column'] = '1 / -1';\n\tconst named: NamedPlacement = {};\n\temitItemEntry(variables, 'default', { alignSelf, justifySelf });\n\temitItemEntry(variables, 'default', grid, named);\n\temitItemEntry(variables, 'default', grid?.responsive?.default, named);\n\n\tfor (const breakpoint of BREAKPOINT_ORDER) {\n\t\temitItemEntry(variables, breakpoint, grid?.responsive?.[breakpoint], named);\n\t}\n\treturn variables;\n}\n"],
|
|
5
|
+
"mappings": "AAAA,UAAYA,MAAO,WAWZ,IAAMC,EAAgB,CAAC,OAAQ,UAAW,UAAW,QAAS,MAAM,EAa9DC,EACX,QAAM,CAAG,OAAKD,CAAa,EAAK,SAAO,CAAC,CAAC,EACzC,MAAQ,WAAS,mFAAmF,CAAC,EAOjGE,GAAsB,CAC3B,OACA,OACA,OACA,UACA,UACA,UACA,QACA,SACA,cACD,EAUA,SAASC,GAAQC,EAAsB,CACtC,OAAOA,EACL,MAAM,EAAE,EACR,IAAKC,GAAU,SAAS,KAAKA,CAAI,EAAI,IAAIA,EAAK,YAAY,CAAC,GAAGA,EAAK,YAAY,CAAC,IAAMA,CAAK,EAC3F,KAAK,EAAE,CACV,CAEA,IAAMC,EAAmB,SAASJ,GAAoB,IAAIC,EAAO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EAAIiE,GAEjE,IAAMC,EAAiB1C,EAAehE,EAAM,cAAc,EACtD0G,IAAmB,SACtBhC,EAAUF,EAAe,2BAA4BhC,CAAI,CAAC,EAAIkE,GAE3D1G,EAAM,SAAW,SACpB0E,EAAUF,EAAe,kBAAmBhC,CAAI,CAAC,EAAIxC,EAAM,OAAS,OAASV,GAE/E,CA0BO,SAASqH,GAAqB5B,EAAwC,CAC5E,IAAML,EAA0B,CAAC,EAC3B,CAACkC,EAAWC,CAAW,EAAI3C,EAAoBa,GAAM,SAAS,EAEhEA,GAAM,UAASL,EAAU,uBAAuB,EAAI,UACxD,IAAM6B,EAAwB,CAAC,EAC/BD,EAAc5B,EAAW,UAAW,CAAE,UAAAkC,EAAW,YAAAC,CAAY,CAAC,EAC9DP,EAAc5B,EAAW,UAAWK,EAAMwB,CAAK,EAC/CD,EAAc5B,EAAW,UAAWK,GAAM,YAAY,QAASwB,CAAK,EAEpE,QAAWzG,KAAcC,EACxBuG,EAAc5B,EAAW5E,EAAYiF,GAAM,aAAajF,CAAU,EAAGyG,CAAK,EAE3E,OAAO7B,CACR",
|
|
6
|
+
"names": ["z", "GridGapTokens", "GridGapValueSchema", "RESERVED_AREA_NAMES", "anyCase", "word", "char", "AREA_NAME_SOURCE", "GridAreaNameSchema", "perBreakpoint", "schema", "responsiveSchema", "GridAreaRowSchema", "GridAreaRowsSchema", "GridAreasSchema", "GridLayoutPropertiesSchema", "GridBreakpointConfigSchema", "GridLayoutConfigSchema", "GridWidthNames", "GridOffsetNames", "ElementGridPropertiesSchema", "ItemGridBreakpointSchema", "ElementGridConfigSchema", "BREAKPOINT_ORDER", "CASCADE_SLOTS", "WIDTH_TRACKS", "WIDTH_SPANS", "isRecord", "value", "elementGridSlots", "element", "grid", "slots", "responsive", "slot", "CASCADE_SLOTS", "entry", "elementGridKeys", "keys", "key", "elementUsesGridWidths", "usesGridWidths", "elements", "carryNamedPlacement", "carried", "entry", "EMPTY_CELL", "splitRow", "row", "cell", "toRows", "rows", "gridAreaTemplates", "grid", "isRecord", "templates", "slot", "CASCADE_SLOTS", "areasTemplateValue", "rows", "row", "DEFAULT_BREAKPOINTS", "DEFAULT_GAP", "DEFAULT_MIN_COLUMN_WIDTH", "GAP_TOKEN_VARIABLES", "gapBaseVariable", "token", "gapTokenValue", "DEFAULT_GAP_CSS", "ITEM_DISPLAY_MODE_VARIABLE", "ITEM_DISPLAY_MODE", "ROOT_FONT_PX", "deepFreeze", "value", "child", "resolveResponsiveGap", "overrides", "resolved", "breakpoint", "BREAKPOINT_ORDER", "entry", "tokens", "GridGapTokens", "resolveGridTheme", "options", "breakpoints", "gap", "responsive", "minColumnWidth", "query", "assertBreakpointOrder", "assertQueryMode", "isCssLengthUnit", "unit", "thresholdToPx", "threshold", "match", "rawUnit", "previousPx", "previousToken", "px", "canonicalResponsiveGap", "canonicalGridTheme", "theme", "GRID_CLASS", "GRID_ITEM_CLASS", "GRID_SUBGRID_CLASS", "GRID_CONTAINER_CLASS", "GRID_CONTAINER_NAME", "TRACK_COUNT_VARIABLE", "GRID_PROPERTIES", "DEFAULT_COLUMN_VARIABLE", "ITEM_PROPERTIES", "GRID_ALIGNMENT_PROPERTIES", "tight", "fallback", "gateName", "themeId", "table", "row", "slot", "cascadingVar", "variable", "declarations", "properties", "property", "flatDeclarations", "gates", "inheritanceResets", "withSlots", "name", "gateResets", "_", "getGridThemeCss", "scope", "gridScope", "itemScope", "subgridScope", "container", "atRule", "lines", "ramped", "rampedTokens", "isGridGapToken", "resolveGridGap", "AXIS_QUALIFIERS", "splitPlaceShorthand", "alignLength", "align", "justify", "toGridTemplate", "columns", "customProperty", "emitGapEntry", "variables", "entryGap", "gapX", "gapY", "getGridVariables", "grid", "elements", "placeAlignItems", "placeJustifyItems", "placeAlignContent", "placeJustifyContent", "alignment", "emitTemplate", "usesGridWidths", "WIDTH_TRACKS", "templates", "gridAreaTemplates", "CASCADE_SLOTS", "rows", "areasTemplateValue", "namedColumn", "width", "offset", "start", "WIDTH_SPANS", "span", "spanColumn", "formatGridLine", "emitItemEntry", "named", "carryNamedPlacement", "marginBlockStart", "marginBlockEnd", "getGridItemVariables", "alignSelf", "justifySelf"]
|
|
7
7
|
}
|
package/dist/lib/layout-theme.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{createRegistry as
|
|
2
|
-
`)}function
|
|
3
|
-
`)}var
|
|
4
|
-
`),
|
|
1
|
+
import{createRegistry as ae}from"@schema-engine/registry";import*as h from"zod/mini";var se=/^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$/,ie=/^[A-Za-z0-9][A-Za-z0-9_-]*$/,de=/[{};<]|\/\*/,z=2,v=5;function T(e,t){if(t.has(e))throw new Error(`Invalid appearance axis name '${e}': data-se-${e} is reserved by the renderer.`)}function C(e){let t=e.$type;if(!se.test(t))throw new Error(`Invalid appearance axis name '${t}': use lowercase letters, digits and hyphens, starting with a letter.`);let r=Object.entries(e.values);if(r.length<z||r.length>v)throw new Error(`Invalid appearance axis '${t}': an axis has ${z} to ${v} values, found ${r.length}. A raw value is a token override, not an axis value.`);if(!Object.hasOwn(e.values,e.default))throw new Error(`Invalid appearance axis '${t}': default '${e.default}' is not one of its values (${r.map(([o])=>o).join(", ")}).`);for(let[o,a]of r){if(!ie.test(o))throw new Error(`Invalid appearance value '${o}' on axis '${t}': use letters, digits, hyphens and underscores.`);for(let[s,i]of Object.entries(a)){if(!s.startsWith("--")||s.length<3)throw new Error(`Invalid appearance token '${s}' on '${t}.${o}': tokens are CSS custom properties and start with '--'.`);if(de.test(String(i)))throw new Error(`Invalid appearance token value for '${s}' on '${t}.${o}'.`)}}}function E(e){let t={$type:e.$type,values:e.values,default:e.default,metadata:e.metadata,schema:h.enum(Object.keys(e.values)).check(h.describe(e.metadata.description??e.metadata.name))};return C(t),Object.freeze(t)}var ce=E({$type:"size",metadata:{name:"Size",description:"How much room components take: spacing, type size, control height and readable width."},default:"default",values:{compact:{"--se-space":"var(--se-space-compact, var(--se-renderer-space-compact, 1rem))","--se-font-size":"0.875rem","--se-measure":"24rem","--se-control-height":"var(--se-control-height-compact, var(--se-renderer-control-height-compact, 1.75rem))"},default:{"--se-space":"initial","--se-font-size":"initial","--se-measure":"initial","--se-control-height":"initial"},comfortable:{"--se-space":"var(--se-space-comfortable, var(--se-renderer-space-comfortable, 2rem))","--se-font-size":"1.0625rem","--se-measure":"32rem","--se-control-height":"var(--se-control-height-comfortable, var(--se-renderer-control-height-comfortable, 2.25rem))"}}}),pe=E({$type:"surface",metadata:{name:"Surface",description:"How a container sets itself apart: border, shadow and background."},default:"elevated",values:{flat:{"--se-border-width":"0","--se-shadow":"none","--se-surface-background":"initial"},outlined:{"--se-border-width":"1px","--se-shadow":"none","--se-surface-background":"initial"},elevated:{"--se-border-width":"initial","--se-shadow":"initial","--se-surface-background":"initial"}}}),le=[ce,pe];function I(e,t){let r=[],o=[],a=`[data-se-theme="${t}"]`,s=`[data-se-theme]:not(${a})`;for(let i of e.registry.all())for(let[l,k]of Object.entries(i.values)){let m=Object.entries(k).map(([u,oe])=>`${u}:${oe};`);if(m.length===0)continue;let d=`{${m.join("")}}`,p=`[data-se-${i.$type}="${l}"]`,y=`${a} ${p}:not(${s},${a} ${s} *)`;r.push(`:where(${a}${p},${y})${d}`),o.push(`:where(:scope${p},${p})${d}`)}return o.length===0?"":[...r,`@scope (${a}) to (${s}){${o.join("")}}`].join(`
|
|
2
|
+
`)}function N(e=le,t={}){let r=ae("Axis",e),o=new Set(t.reservedNames);for(let a of r.all())C(a),T(a.$type,o);return Object.freeze({registry:r,axes:Object.freeze(Object.fromEntries(r.all().map(a=>[a.$type,Object.freeze(Object.keys(a.values))])))})}import*as n from"zod/mini";var f=["none","compact","default","loose","wide"],g=n.union([n.enum(f),n.string()]).check(n.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 fe(e){return e.split("").map(t=>/[a-z]/i.test(t)?`[${t.toLowerCase()}${t.toUpperCase()}]`:t).join("")}var $=`(?!(?:${ue.map(fe).join("|")})(?![\\w-]))-?[_a-zA-Z][_a-zA-Z0-9-]*`,me=n.string().check(n.regex(new RegExp(`^${$}$`),'Area names are CSS identifiers such as "header" or "side-2".'),n.describe('Name of a cell group in the grid template: a CSS identifier such as "header" or "side-2".'));function P(e){return n.strictObject({default:n.optional(e),sm:n.optional(e),md:n.optional(e),lg:n.optional(e),xl:n.optional(e),"2xl":n.optional(e)})}function _(e){return n.optional(P(e))}var ge=n.string().check(n.regex(new RegExp(`^\\s*(?:\\.+|${$})(?:\\s+(?:\\.+|${$}))*\\s*$`),'A grid areas row lists area names (CSS identifiers) or "." for an empty cell, separated by spaces.')),L=n.array(ge).check(n.minLength(1)),ye=n.union([L,P(L)]).check(n.describe('Rows of area names separated by spaces ("." is an empty cell), or a record of them per breakpoint (default, sm ... 2xl).')),B=n.strictObject({areas:n.optional(ye),columns:n.optional(n.union([n.int().check(n.positive()),n.literal("auto")])),gap:n.optional(g),gapX:n.optional(g),gapY:n.optional(g),minColumnWidth:n.optional(n.string()),justifyItems:n.optional(n.enum(["start","end","center","stretch"])),alignItems:n.optional(n.enum(["start","end","center","stretch"])),placeItems:n.optional(n.string()),justifyContent:n.optional(n.enum(["start","end","center","stretch","space-around","space-between","space-evenly"])),alignContent:n.optional(n.enum(["start","end","center","stretch","space-around","space-between","space-evenly"])),placeContent:n.optional(n.string()),autoFlow:n.optional(n.enum(["row","dense"])).check(n.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=n.pick(B,{columns:!0,gap:!0,gapX:!0,gapY:!0,minColumnWidth:!0}),De=n.extend(B,{responsive:_(he)}),O=["full","three-quarters","two-thirds","half","third","quarter"],j=["three-quarters","two-thirds","half","third","quarter"],V=n.strictObject({area:n.optional(me).check(n.describe("Name of the cell group this item fills in the grid areas template.")),width:n.optional(n.enum(O)).check(n.describe(`Named share of the row (${O.join(" | ")}).`)),offset:n.optional(n.enum(j)).check(n.describe(`Named empty space before the item (${j.join(" | ")}).`)),span:n.optional(n.int().check(n.positive())).check(n.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:n.optional(n.union([n.number(),n.string()])),row:n.optional(n.union([n.number(),n.string()])),justifySelf:n.optional(n.enum(["start","end","center","stretch"])),alignSelf:n.optional(n.enum(["start","end","center","stretch"])),placeSelf:n.optional(n.string()),subgrid:n.optional(n.boolean()).check(n.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:n.optional(g).check(n.describe("Extra space before this element, on top of the grid row gap.")),marginBlockEnd:n.optional(g).check(n.describe("Extra space after this element, on top of the grid row gap."))}),xe=n.extend(n.omit(V,{placeSelf:!0,subgrid:!0}),{hidden:n.optional(n.boolean())}),Me=n.extend(V,{responsive:_(xe)});var c=["sm","md","lg","xl","2xl"],Ae=["default",...c];var ke={sm:"40rem",md:"48rem",lg:"64rem",xl:"80rem","2xl":"96rem"},Te={none:"0",compact:"0.5rem",default:"var(--space-stack, 1rem)",loose:"var(--space-block-lg, 1.5rem)",wide:"var(--space-block-xl, 2rem)"},$e="15.625rem",Re={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 G(e){return`--se-grid-gap-base-${e}`}function Ge(e){return`var(${Re[e]}, var(${G(e)}))`}var D=Ge("default"),S="--se-item-display-mode",Se=`var(${S}, block)`,Y=16;function H(e){Object.freeze(e);for(let t of Object.values(e))t!==null&&typeof t=="object"&&!Object.isFrozen(t)&&H(t);return e}function be(e){let t={};for(let r of c){let o=e?.[r],a=f.filter(s=>o?.[s]!==void 0);a.length>0&&(t[r]=Object.fromEntries(a.map(s=>[s,o[s]])))}return t}function Q(e){let t={...ke,...e?.breakpoints},r={...Te,...e?.gap},o=be(e?.responsive),a=e?.minColumnWidth??$e,s=e?.query??"media";return Ce(t),we(s),H({breakpoints:t,gap:r,responsive:o,minColumnWidth:a,query:s})}function we(e){if(e!=="media"&&e!=="container")throw new Error(`Grid theme query must be 'media' or 'container'; received '${e}'.`)}function ze(e){return e==="px"||e==="rem"||e==="em"}function ve(e,t){let r=/^(\d+(?:\.\d+)?)(px|rem|em)$/.exec(t),o=r?.[2];if(!r||!ze(o))throw new Error(`Grid theme breakpoint '${e}' must be a px, rem, or em length; received '${t}'.`);let a=Number(r[1]);return o==="px"?a:a*Y}function Ce(e){let t=Number.NEGATIVE_INFINITY,r;for(let o of c){let a=e[o],s=ve(o,a);if(r!==void 0&&s<t)throw new Error(`Grid theme breakpoints must preserve cascade order sm \u2264 md \u2264 lg \u2264 xl \u2264 2xl (rem/em compared at ${Y}px root); '${o}' (${a}) is smaller than '${r}' (${e[r]}).`);t=s,r=o}}function Ee(e){return c.flatMap(t=>{let r=e[t];if(!r)return[];let o=f.flatMap(a=>{let s=r[a];return s===void 0?[]:[[a,s]]});return[[t,o]]})}function Z(e){return{breakpoints:e.breakpoints,gap:e.gap,responsive:Ee(e.responsive),minColumnWidth:e.minColumnWidth,...e.query==="media"?{}:{query:e.query}}}var M="se-grid",W="se-grid-item",Ie="se-subgrid",Ne="se-grid-container",U="se-grid",J="--se-grid-track-count",x=[["grid-template-columns","se-grid-template","repeat(1, minmax(0, 1fr))"],["grid-template-areas","se-grid-areas","none"],["row-gap","se-grid-gap-y",D],["column-gap","se-grid-gap-x",D],[J,"se-grid-tracks","1"]],b="--se-grid-default-column",A=[["display","se-item-display",Se],["grid-column","se-item-grid-column",`var(${b}, 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"],["grid-auto-flow","se-grid-auto-flow","row"]];function ee(e){return e.replaceAll(", ",",")}function w(e,t,r,o){return`--${e}-${t}${r}${o}`}function Le(e,t,r,o,a){let s=`var(--${o},${ee(a)})`;for(let i of c)s=`var(${w(e,t,r,i)},${s})`;return s}function F(e,t,r){return r.map(([o,a,s],i)=>`${o}:${Le(e,t,i,a,s)};`).join("")}function Oe(e){return e.map(([t,r,o])=>`${t}:var(--${r},${ee(o)});`).join("")}function q(e,t,r,o){return r.map(([,a],s)=>`${w(e,t,s,o)}:var(--${a}-${o});`).join("")}function R(e,t){return e.flatMap(([,r])=>[`--${r}`,...t?c.map(o=>`--${r}-${o}`):[]]).map(r=>`${r}:initial;`).join("")}function X(e,t,r){return r.flatMap((o,a)=>c.map(s=>`${w(e,t,a,s)}:initial;`)).join("")}function ne(e,t){let r=`[data-se-theme="${t}"]`,o=`.${M}${r}`,a=`.${W}${r}`,s=`.${Ie}${r}`,i=f.map(d=>`${G(d)}:${e.gap[d]};`).join(""),l=e.query==="container",k=l?`@container ${U}`:"@media",m=[`${r}{${i}}`,...l?[`.${Ne}${r}{display:block;width:100%;min-width:0;container-type:inline-size;container-name:${U};}`]:[],`${s}{${S}:grid;display:grid;grid-template-columns:subgrid;column-gap:normal;align-content:start;}`,`${s}>:not(.${W}){grid-column:1/-1;}`,`${o}{${l?X(t,"g",x):""}${R(x,!0)}${R(K,!1)}${b}:initial;${S}:initial;display:grid;${F(t,"g",x)}${Oe(K)}}`,`.${M}${s}{--se-grid-template:subgrid;--se-grid-gap-x:normal;${b}:inherit;${J}:inherit;}`,`${a}{${l?X(t,"i",A):""}${R(A,!0)}${F(t,"i",A)}}`];for(let d of c){let p=e.responsive[d],y=p?f.filter(u=>p[u]!==void 0).map(u=>`${G(u)}:${p[u]};`).join(""):"";m.push(`${k} (min-width:${e.breakpoints[d]}){${y?`${r}{${y}}`:""}${o}{${q(t,"g",x,d)}}${a}{${q(t,"i",A,d)}}}`)}return m.join(`
|
|
3
|
+
`)}var re=Symbol.for("@schema-engine/layout/theme");function tn(e){return typeof e=="object"&&e!==null&&Reflect.get(e,re)===!0}function je(e){let t=5381;for(let r=0;r<e.length;r+=1)t=(t<<5)+t+e.charCodeAt(r)|0;return`l${(t>>>0).toString(36)}`}function Pe(e){return e.registry.all().map(t=>[t.$type,t.default,Object.entries(t.values)])}function _e(e,t={}){let r=Q(e?.grid),o=N(e?.appearance,t),a=je(JSON.stringify({grid:Z(r),appearance:Pe(o)})),s=[ne(r,a),I(o,a)].filter(Boolean).join(`
|
|
4
|
+
`),i={id:a,grid:r,axes:o.axes,appearance:o.registry,css:s};return Object.defineProperty(i,re,{value:!0,enumerable:!1}),Object.freeze(i),i}var te;function rn(){return te??=_e(),te}function on(e,t){let r=new Set(t);for(let o of Object.keys(e.axes))T(o,r)}export{on as assertAxesNotReserved,_e as createLayoutTheme,rn as getDefaultLayoutTheme,tn as isLayoutTheme};
|