@schema-engine/layout 0.5.0 → 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 CHANGED
@@ -8,7 +8,7 @@ Domain-neutral layout for Schema Engine: a 12-track grid with named widths and d
8
8
  pnpm add @schema-engine/layout zod
9
9
  ```
10
10
 
11
- The grid, axis and recipe schemas use `zod/mini`, so `zod` is a peer dependency.
11
+ The grid and axis schemas use `zod/mini`, so `zod` is a peer dependency. A recipe's slot schemas take any [Standard Schema](https://standardschema.dev/) that validates synchronously (Zod, Valibot, or one you write); the spec's view schema, `spec.schema`, is a Standard Schema too, so validate with `safeParseStandardSchema` from `@schema-engine/registry`, not `.parse`.
12
12
 
13
13
  ## Example
14
14
 
@@ -39,18 +39,25 @@ export const itemVariables = getGridItemVariables({ width: 'half' });
39
39
 
40
40
  Emit `theme.css` once on the page, give the container the `GRID_CLASS` class and `data-se-theme="${theme.id}"`, and write the variables of `getGridVariables` and `getGridItemVariables` as its custom properties and those of its items.
41
41
 
42
+ Breakpoints measure the window by default. `createLayoutTheme({ grid: { query: 'container' } })` makes them measure the grid's own wrapper instead, so a grid in a card or a panel follows the room it has. The wrapper is an element with `GRID_CONTAINER_CLASS` and `data-se-theme="${theme.id}"` around each grid; a grid with no wrapper keeps its narrowest layout. The document is the same in both modes.
43
+
44
+ An element with `grid: { subgrid: true }` spans its parent's full row and lays its children on the parent's column tracks and gap instead of tracks of its own. The item, every box between it and the inner grid, and the inner `GRID_CLASS` grid carry `GRID_SUBGRID_CLASS` and `data-se-theme`, and none may be a `GRID_CONTAINER_CLASS` wrapper or set `container-type`, or the browser falls back to one column without a warning. Keep a `<fieldset>` out of the chain, because Chromium does not make one a subgrid; use a `div` with `role="group"` and `aria-labelledby` its heading. A domain passes the children of its subgrids among the items it gives `getGridVariables`.
45
+
46
+ An item with `grid: { span: n }` takes `n` tracks of the grid it sits in, never more (`span min(n, var(--se-grid-track-count, 1))`). The grid publishes its track count with its template, per breakpoint and in both query modes, and a subgrid passes its parent's count on, so a clamp switches at the width the tracks do. `autoFlow: 'dense'` on the grid backfills gaps. `columns: 'auto'` has no countable tracks in CSS, so a span there is one track and `gridSpanIssues` reports it; use `columns` per breakpoint with a container theme. An item and the grid it contains must be different elements.
47
+
42
48
  ## Entry points
43
49
 
44
- The package has one entry, `@schema-engine/layout`: `createLayoutTheme`, `defineAxis` and `builtInAxes`, the grid helpers (`getGridVariables`, `getGridItemVariables`), `getAppearanceAttributes`, and the recipe protocol (`defineRecipeProtocol`, `resolveRecipeView`).
50
+ The package has one entry, `@schema-engine/layout`: `createLayoutTheme`, `defineAxis` and `builtInAxes`, the grid helpers (`getGridVariables`, `getGridItemVariables`) and the hooks `GRID_CLASS`, `GRID_ITEM_CLASS`, `GRID_SUBGRID_CLASS` and `GRID_CONTAINER_CLASS`, the placement checks `elementIsSubgrid`, `subgridPlacementIssue`, `spanPlacementIssue` and `gridSpanIssues`, `getAppearanceAttributes`, and the recipe protocol (`defineRecipeProtocol`, `resolveRecipeView`).
45
51
 
46
52
  ## Documentation
47
53
 
48
54
  - [Layout](https://schema-engine.com/docs/layout/overview): install, compile a theme and place items with no forms.
49
55
  - [Grid and placement](https://schema-engine.com/docs/layout/grid-and-placement): widths, offsets, areas and breakpoints.
50
56
  - [Layout themes](https://schema-engine.com/docs/layout/layout-themes): compile, share and nest themes.
51
- - [Appearance axes](https://schema-engine.com/docs/layout/appearance-axes): `size`, `surface` and your own.
57
+ - [Appearance axes](https://schema-engine.com/docs/layout/appearance-axes): `size`, `surface` and your own, and identity tokens for values that every entity has for itself.
52
58
  - [Theming](https://schema-engine.com/docs/layout/theming): the custom properties a host overrides.
53
59
  - [Recipe protocol](https://schema-engine.com/docs/layout/recipe-protocol): declare the slots and kinds of a domain's view recipes.
60
+ - [Recipes outside forms](https://schema-engine.com/docs/layout/recipes-outside-forms): a card recipe bound for React and for Radiant.
54
61
  - [For AI agents](https://schema-engine.com/docs/schema-engine/agent-skill): the package ships its part of the agent skill.
55
62
 
56
63
  ## License
package/dist/index.d.ts CHANGED
@@ -17,10 +17,10 @@ export { ElementGridConfigSchema, GridBreakpointConfigSchema, GridGapTokens, Gri
17
17
  export type { ElementGridConfig, GridBreakpointConfig, GridGapToken, GridLayoutConfig, GridOffsetName, GridWidthName, ItemGridBreakpointConfig, } from './schemas/grid';
18
18
  export { builtInAxes, checkAppearance, defineAxis, getAppearanceAttributes, mergeAppearance, pickSupportedAppearance, } from './lib/appearance';
19
19
  export type { AnyAxisRegistration, AppearanceAxisList, AppearanceInput, AppearanceSelection, AppearanceTokens, AxisDefinition, AxisRegistration, AxisRegistry, BuiltInAppearanceAxes, ResolvedAppearanceAxes, SlotAppearanceAxes, } from './lib/appearance';
20
- export { GRID_TEMPLATE_KEYS, WIDTH_TRACKS, areaNames, areaTemplateIssues, cascadeValues, elementAreaSlots, elementGridKeys, elementHiddenSlots, elementUsesGridWidths, gridAreaTemplates, gridUsesAreas, namedPlacementOverflow, } from './lib/grid-placement';
20
+ export { GRID_TEMPLATE_KEYS, WIDTH_TRACKS, areaNames, areaTemplateIssues, cascadeValues, elementAreaSlots, elementGridKeys, elementHiddenSlots, elementIsSubgrid, elementUsesGridWidths, gridAreaTemplates, gridSpanIssues, gridUsesAreas, namedPlacementOverflow, spanPlacementIssue, subgridPlacementIssue, } from './lib/grid-placement';
21
21
  export type { CascadeSlot, GridAreaRows, GridAreaTemplates, GridBreakpointToken } from './lib/grid-placement';
22
- export { GRID_CLASS, GRID_ITEM_CLASS, getGridItemVariables, getGridVariables } from './lib/grid-styles';
23
- export type { CssVariables, GridGapScale, GridThemeOptions, NormalizedGridTheme } from './lib/grid-styles';
22
+ export { GRID_CLASS, GRID_CONTAINER_CLASS, GRID_ITEM_CLASS, GRID_SUBGRID_CLASS, getGridItemVariables, getGridVariables, } from './lib/grid-styles';
23
+ export type { CssVariables, GridGapScale, GridQueryMode, GridThemeOptions, NormalizedGridTheme, } from './lib/grid-styles';
24
24
  export { assertAxesNotReserved, createLayoutTheme, getDefaultLayoutTheme, isLayoutTheme } from './lib/layout-theme';
25
25
  export type { LayoutIssue } from './lib/layout-issue';
26
26
  export type { LayoutAxes, LayoutInput, LayoutTheme, LayoutThemeCompilerOptions, LayoutThemeOptions, } from './lib/layout-theme';
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import*as l from"zod/mini";var Ze=l.record(l.string(),l.string());function Q(e,t){let n=e.all().filter(r=>t===void 0||t.includes(r.$type)).map(r=>[r.$type,l.optional(l.enum(Object.keys(r.values)))]);return l.strictObject(Object.fromEntries(n))}function P(e){return"check"in e&&typeof e.check=="function"}function ee(e){return e._zod.def.type==="object"}function Ue(e){return e._zod.def.type==="pipe"}function Fe(e){return e._zod.def.type==="prefault"}function E(e,t){if(ee(e))return l.safeExtend(e,{appearance:t});if(Ue(e)){let{in:n,out:r}=e._zod.def;if(!P(n))return e;let o=E(n,t);return o===n?e:l.pipe(o,r)}if(Fe(e)){let{innerType:n,defaultValue:r}=e._zod.def;if(!P(n))return e;let o=E(n,t);return o===n?e:l.prefault(o,r)}return e}function He(e,t){return l.optional(Q(e,t)).check(l.describe("Named appearance values, one per declared axis"))}function te(e,t,n=[]){return E(e,He(t,n))}function Xe(e,t,n={}){if(!ee(e))return e;let r={};for(let[o,s]of Object.entries(e._zod.def.shape)){if(!P(s))continue;let a=te(s,t,n[o]);a!==s&&(r[o]=a)}return Object.keys(r).length===0?e:l.safeExtend(e,r)}import*as i from"zod/mini";var A=["none","compact","default","loose","wide"],$=i.union([i.enum(A),i.string()]).check(i.describe("Semantic gap token (none | compact | default | loose | wide) or a raw CSS length.")),Ye=["auto","span","none","default","inherit","initial","unset","revert","revert-layer"];function qe(e){return e.split("").map(t=>/[a-z]/i.test(t)?`[${t.toLowerCase()}${t.toUpperCase()}]`:t).join("")}var I=`(?!(?:${Ye.map(qe).join("|")})(?![\\w-]))-?[_a-zA-Z][_a-zA-Z0-9-]*`,Je=i.string().check(i.regex(new RegExp(`^${I}$`),'Area names are CSS identifiers such as "header" or "side-2".'),i.describe('Name of a cell group in the grid template: a CSS identifier such as "header" or "side-2".'));function re(e){return i.strictObject({default:i.optional(e),sm:i.optional(e),md:i.optional(e),lg:i.optional(e),xl:i.optional(e),"2xl":i.optional(e)})}function oe(e){return i.optional(re(e))}var Qe=i.string().check(i.regex(new RegExp(`^\\s*(?:\\.+|${I})(?:\\s+(?:\\.+|${I}))*\\s*$`),'A grid areas row lists area names (CSS identifiers) or "." for an empty cell, separated by spaces.')),ne=i.array(Qe).check(i.minLength(1)),et=i.union([ne,re(ne)]).check(i.describe('Rows of area names separated by spaces ("." is an empty cell), or a record of them per breakpoint (default, sm ... 2xl).')),ie=i.strictObject({areas:i.optional(et),columns:i.optional(i.union([i.number(),i.literal("auto")])),gap:i.optional($),gapX:i.optional($),gapY:i.optional($),minColumnWidth:i.optional(i.string()),justifyItems:i.optional(i.enum(["start","end","center","stretch"])),alignItems:i.optional(i.enum(["start","end","center","stretch"])),placeItems:i.optional(i.string()),justifyContent:i.optional(i.enum(["start","end","center","stretch","space-around","space-between","space-evenly"])),alignContent:i.optional(i.enum(["start","end","center","stretch","space-around","space-between","space-evenly"])),placeContent:i.optional(i.string())}),se=i.pick(ie,{columns:!0,gap:!0,gapX:!0,gapY:!0,minColumnWidth:!0}),tt=i.extend(ie,{responsive:oe(se)}),L=["full","three-quarters","two-thirds","half","third","quarter"],N=["three-quarters","two-thirds","half","third","quarter"],ae=i.strictObject({area:i.optional(Je).check(i.describe("Name of the cell group this item fills in the grid areas template.")),width:i.optional(i.enum(L)).check(i.describe(`Named share of the row (${L.join(" | ")}).`)),offset:i.optional(i.enum(N)).check(i.describe(`Named empty space before the item (${N.join(" | ")}).`)),column:i.optional(i.union([i.number(),i.string()])),row:i.optional(i.union([i.number(),i.string()])),justifySelf:i.optional(i.enum(["start","end","center","stretch"])),alignSelf:i.optional(i.enum(["start","end","center","stretch"])),placeSelf:i.optional(i.string()),marginBlockStart:i.optional($).check(i.describe("Extra space before this element, on top of the grid row gap.")),marginBlockEnd:i.optional($).check(i.describe("Extra space after this element, on top of the grid row gap."))}),ce=i.extend(i.omit(ae,{placeSelf:!0}),{hidden:i.optional(i.boolean())}),nt=i.extend(ae,{responsive:oe(ce)});import{createRegistry as rt}from"@schema-engine/registry";import*as z from"zod/mini";var ot=/^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$/,it=/^[A-Za-z0-9][A-Za-z0-9_-]*$/,st=/[{};<]|\/\*/,pe=2,de=5;function V(e,t){if(t.has(e))throw new Error(`Invalid appearance axis name '${e}': data-se-${e} is reserved by the renderer.`)}function le(e){let t=e.$type;if(!ot.test(t))throw new Error(`Invalid appearance axis name '${t}': use lowercase letters, digits and hyphens, starting with a letter.`);let n=Object.entries(e.values);if(n.length<pe||n.length>de)throw new Error(`Invalid appearance axis '${t}': an axis has ${pe} to ${de} values, found ${n.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 (${n.map(([r])=>r).join(", ")}).`);for(let[r,o]of n){if(!it.test(r))throw new Error(`Invalid appearance value '${r}' on axis '${t}': use letters, digits, hyphens and underscores.`);for(let[s,a]of Object.entries(o)){if(!s.startsWith("--")||s.length<3)throw new Error(`Invalid appearance token '${s}' on '${t}.${r}': tokens are CSS custom properties and start with '--'.`);if(st.test(String(a)))throw new Error(`Invalid appearance token value for '${s}' on '${t}.${r}'.`)}}}function _(e){let t={$type:e.$type,values:e.values,default:e.default,metadata:e.metadata,schema:z.enum(Object.keys(e.values)).check(z.describe(e.metadata.description??e.metadata.name))};return le(t),Object.freeze(t)}var at=_({$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))"}}}),ct=_({$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"}}}),ue=[at,ct];function fe(e,t){let n=[],r=[],o=`[data-se-theme="${t}"]`,s=`[data-se-theme]:not(${o})`;for(let a of e.registry.all())for(let[c,p]of Object.entries(a.values)){let u=Object.entries(p).map(([T,f])=>`${T}:${f};`);if(u.length===0)continue;let d=`{${u.join("")}}`,g=`[data-se-${a.$type}="${c}"]`,x=`${o} ${g}:not(${s},${o} ${s} *)`;n.push(`:where(${o}${g},${x})${d}`),r.push(`:where(:scope${g},${g})${d}`)}return r.length===0?"":[...n,`@scope (${o}) to (${s}){${r.join("")}}`].join(`
2
- `)}function me(e=ue,t={}){let n=rt("Axis",e),r=new Set(t.reservedNames);for(let o of n.all())le(o),V(o.$type,r);return Object.freeze({registry:n,axes:Object.freeze(Object.fromEntries(n.all().map(o=>[o.$type,Object.freeze(Object.keys(o.values))])))})}function pt(e){let t={};for(let[n,r]of Object.entries(e??{}))t[`data-se-${n}`]=r;return t}function M(e,t){return{...e,...t}}function dt(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function D(e,t){let n=[],r={};if(e===void 0)return{issues:n,appearance:r};if(!dt(e))return{issues:[{path:["appearance"],message:"Expected an object of axis names to values."}],appearance:r};let o=Object.keys(t.axes).join(", ");for(let[s,a]of Object.entries(e)){let c=Object.hasOwn(t.axes,s)?t.axes[s]:void 0;if(!c){n.push({path:["appearance",s],message:`Unknown axis '${s}'. Declared axes: ${o}.`});continue}if(t.supported!==void 0&&!t.supported.includes(s)){let p=t.supported.length>0?t.supported.join(", "):"(none)";n.push({path:["appearance",s],message:`${t.subject} does not support the axis '${s}'. Supported axes: ${p}.`});continue}if(typeof a!="string"){n.push({path:["appearance",s],message:`Expected one of ${c.join(", ")}.`});continue}if(!c.includes(a)){n.push({path:["appearance",s],message:`'${a}' is not a value of '${s}'. Allowed: ${c.join(", ")}.`});continue}r[s]=a}return{issues:n,appearance:r}}function B(e,t){let n={};for(let r of t??[]){let o=e[r];o!==void 0&&(n[r]=o)}return n}var h=["sm","md","lg","xl","2xl"],k=["default",...h],v=12,w={full:12,"three-quarters":9,"two-thirds":8,half:6,third:4,quarter:3},lt=["columns","minColumnWidth"];function S(e){return typeof e=="object"&&e!==null}function C(e){if(!S(e)||!S(e.grid))return[];let t=e.grid,n=[{slot:"default",entry:t}],r=t.responsive;if(!S(r))return n;for(let o of k){let s=r[o];S(s)&&n.push({slot:o,entry:s})}return n}function ye(e){let t=new Set;for(let{entry:n}of C(e))for(let[r,o]of Object.entries(n))r!=="responsive"&&o!==void 0&&t.add(r);return t}function he(e){let t=ye(e);return t.has("width")||t.has("offset")}function xe(e){return e.some(he)}function K(e,t){e.width=t.width??e.width,e.offset=t.offset??e.offset}function ut(e){let t={};for(let{slot:n,entry:r}of C(e)){if(r.width===void 0&&r.offset===void 0||(K(t,r),t.width===void 0||t.offset===void 0))continue;let o=(w[t.width]??0)+(w[t.offset]??0);if(o>v)return{slot:n,tracks:o}}}var Te=".";function ft(e){return typeof e!="string"?[]:e.trim().split(/\s+/).filter(Boolean).map(t=>/^\.+$/.test(t)?Te:t)}function ge(e){return Array.isArray(e)?e.map(ft):void 0}function b(e){if(!S(e)||e.areas===void 0)return{};if(Array.isArray(e.areas)){let n=ge(e.areas);return n?{default:n}:{}}if(!S(e.areas))return{};let t={};for(let n of k){let r=ge(e.areas[n]);r&&(t[n]=r)}return t}function mt(e){return Object.keys(b(e)).length>0}function Re(e){let t=new Set;for(let n of e)for(let r of n)r!==Te&&t.add(r);return[...t]}function Ae(e){return e.map(t=>`"${t.join(" ")}"`).join(" ")}function gt(e){let t={};for(let{slot:n,entry:r}of C(e))typeof r.area=="string"&&(t[n]=r.area);return t}function yt(e){let t={};for(let{slot:n,entry:r}of C(e))typeof r.hidden=="boolean"&&(t[n]=r.hidden);return t}function ht(e){let t;return k.map(n=>(t=e[n]??t,{slot:n,value:t}))}function xt(e){return`${e} ${e===1?"cell":"cells"}`}function Tt(e,t){let n=[];e.forEach((c,p)=>c.forEach((u,d)=>{u===t&&n.push([p,d])}));let r=n.map(([c])=>c),o=n.map(([,c])=>c),s=Math.max(...r)-Math.min(...r)+1,a=Math.max(...o)-Math.min(...o)+1;return s*a===n.length}function Rt(e){let t=b(e),n=S(e)&&Array.isArray(e.areas),r=[];for(let o of k){let s=t[o];if(!s)continue;let a=n?["areas"]:["areas",o],c=s[0]?.length??0,p=s.findIndex(u=>u.length!==c);if(p!==-1){r.push({path:a,message:`row ${p+1} has ${xt(s[p]?.length??0)} but row 1 has ${c}.`});continue}for(let u of Re(s))Tt(s,u)||r.push({path:a,message:`area '${u}' is not rectangular; CSS drops the whole template unless every area fills a rectangle.`})}return r}var At={sm:"40rem",md:"48rem",lg:"64rem",xl:"80rem","2xl":"96rem"},St={none:"0",compact:"0.5rem",default:"var(--space-stack, 1rem)",loose:"var(--space-block-lg, 1.5rem)",wide:"var(--space-block-xl, 2rem)"},kt="15.625rem",$t={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 H(e){return`--se-grid-gap-base-${e}`}function ze(e){return`var(${$t[e]}, var(${H(e)}))`}var Se=ze("default"),ve="var(--se-item-display-mode, block)",Ce=16;function Oe(e){Object.freeze(e);for(let t of Object.values(e))t!==null&&typeof t=="object"&&!Object.isFrozen(t)&&Oe(t);return e}function wt(e){let t={};for(let n of h){let r=e?.[n],o=A.filter(s=>r?.[s]!==void 0);o.length>0&&(t[n]=Object.fromEntries(o.map(s=>[s,r[s]])))}return t}function je(e){let t={...At,...e?.breakpoints},n={...St,...e?.gap},r=wt(e?.responsive),o=e?.minColumnWidth??kt;return zt(t),Oe({breakpoints:t,gap:n,responsive:r,minColumnWidth:o})}function bt(e){return e==="px"||e==="rem"||e==="em"}function Gt(e,t){let n=/^(\d+(?:\.\d+)?)(px|rem|em)$/.exec(t),r=n?.[2];if(!n||!bt(r))throw new Error(`Grid theme breakpoint '${e}' must be a px, rem, or em length; received '${t}'.`);let o=Number(n[1]);return r==="px"?o:o*Ce}function zt(e){let t=Number.NEGATIVE_INFINITY,n;for(let r of h){let o=e[r],s=Gt(r,o);if(n!==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 ${Ce}px root); '${r}' (${o}) is smaller than '${n}' (${e[n]}).`);t=s,n=r}}function vt(e){return h.flatMap(t=>{let n=e[t];if(!n)return[];let r=A.flatMap(o=>{let s=n[o];return s===void 0?[]:[[o,s]]});return[[t,r]]})}function Pe(e){return{breakpoints:e.breakpoints,gap:e.gap,responsive:vt(e.responsive),minColumnWidth:e.minColumnWidth}}var Ee="se-grid",Ie="se-grid-item",W=[["grid-template-columns","se-grid-template","repeat(1, minmax(0, 1fr))"],["grid-template-areas","se-grid-areas","none"],["row-gap","se-grid-gap-y",Se],["column-gap","se-grid-gap-x",Se]],Y="--se-grid-default-column",Z=[["display","se-item-display",ve],["grid-column","se-item-grid-column",`var(${Y}, 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"]],ke=[["justify-items","se-grid-justify-items","normal"],["align-items","se-grid-align-items","normal"],["justify-content","se-grid-justify-content","normal"],["align-content","se-grid-align-content","start"]];function Le(e){return e.replaceAll(", ",",")}function Ne(e,t,n,r){return`--${e}-${t}${n}${r}`}function Ct(e,t,n,r,o){let s=`var(--${r},${Le(o)})`;for(let a of h)s=`var(${Ne(e,t,n,a)},${s})`;return s}function $e(e,t,n){return n.map(([r,o,s],a)=>`${r}:${Ct(e,t,a,o,s)};`).join("")}function Ot(e){return e.map(([t,n,r])=>`${t}:var(--${n},${Le(r)});`).join("")}function we(e,t,n,r){return n.map(([,o],s)=>`${Ne(e,t,s,r)}:var(--${o}-${r});`).join("")}function U(e,t){return e.flatMap(([,n])=>[`--${n}`,...t?h.map(r=>`--${n}-${r}`):[]]).map(n=>`${n}:initial;`).join("")}function Ve(e,t){let n=`[data-se-theme="${t}"]`,r=`.${Ee}${n}`,o=`.${Ie}${n}`,s=A.map(c=>`${H(c)}:${e.gap[c]};`).join(""),a=[`${n}{${s}}`,`${r}{${U(W,!0)}${U(ke,!1)}${Y}:initial;display:grid;${$e(t,"g",W)}${Ot(ke)}}`,`${o}{${U(Z,!0)}${$e(t,"i",Z)}}`];for(let c of h){let p=e.responsive[c],u=p?A.filter(d=>p[d]!==void 0).map(d=>`${H(d)}:${p[d]};`).join(""):"";a.push(`@media (min-width:${e.breakpoints[c]}){${u?`${n}{${u}}`:""}${r}{${we(t,"g",W,c)}}${o}{${we(t,"i",Z,c)}}}`)}return a.join(`
3
- `)}function jt(e){for(let t of A)if(t===e)return!0;return!1}function G(e){if(e!==void 0)return jt(e)?ze(e):e}var Pt=new Set(["safe","unsafe","first","last"]);function X(e){if(e===void 0)return[void 0,void 0];let t=e.trim().split(/\s+/).filter(Boolean);if(t.length===0)return[void 0,void 0];let n=Pt.has(t[0])&&t.length>1?2:1,r=t.slice(0,n).join(" "),o=n<t.length?t.slice(n).join(" "):r;return[r,o]}function be(e,t){return e==="auto"?`repeat(auto-fit, minmax(min(${t}, 100%), 1fr))`:`repeat(${e}, minmax(0, 1fr))`}function y(e,t){return t==="default"?`--${e}`:`--${e}-${t}`}function F(e,t,n){if(!n)return;let r=G(n.gap),o=G(n.gapX)??r,s=G(n.gapY)??r;s!==void 0&&(e[y("se-grid-gap-y",t)]=s),o!==void 0&&(e[y("se-grid-gap-x",t)]=o)}function Et(e,t,n){let r={},[o,s]=X(e?.placeItems),[a,c]=X(e?.placeContent),p={"--se-grid-justify-items":e?.justifyItems??s,"--se-grid-align-items":e?.alignItems??o,"--se-grid-justify-content":e?.justifyContent??c,"--se-grid-align-content":e?.alignContent??a};for(let[f,m]of Object.entries(p))m!==void 0&&(r[f]=m);let u=1,d=t.minColumnWidth,g=(f,m)=>{m&&(m.columns===void 0&&m.minColumnWidth===void 0||(m.columns!==void 0&&(u=m.columns),m.minColumnWidth!==void 0&&(d=m.minColumnWidth),r[y("se-grid-template",f)]=be(u,d)))};xe(n)&&(r["--se-grid-template"]=`repeat(${v}, minmax(0, 1fr))`,r[Y]="1 / -1");let x=b(e);for(let f of k){let m=x[f];m&&(r[y("se-grid-areas",f)]=Ae(m),r[y("se-grid-template",f)]=be(m[0]?.length??1,t.minColumnWidth))}let T=e?.responsive;g("default",e),g("default",T?.default),F(r,"default",e),F(r,"default",T?.default);for(let f of h)g(f,T?.[f]),F(r,f,T?.[f]);return r}function It({width:e,offset:t}){let n=t===void 0?void 0:w[t]+1;if(e===void 0)return n===void 0?"auto":`${n} / -1`;let r=`span ${w[e]}`;return n===void 0?r:`${n} / ${r}`}function Ge(e){return typeof e=="number"?String(e):e}function O(e,t,n,r={}){if(!n)return;(n.width!==void 0||n.offset!==void 0)&&(K(r,n),e[y("se-item-grid-column",t)]=It(r)),n.area!==void 0&&(e[y("se-item-grid-column",t)]=n.area,e[y("se-item-grid-row",t)]=n.area),n.column!==void 0&&(e[y("se-item-grid-column",t)]=Ge(n.column)),n.row!==void 0&&(e[y("se-item-grid-row",t)]=Ge(n.row)),n.justifySelf!==void 0&&(e[y("se-item-justify-self",t)]=n.justifySelf),n.alignSelf!==void 0&&(e[y("se-item-align-self",t)]=n.alignSelf);let o=G(n.marginBlockStart);o!==void 0&&(e[y("se-item-margin-block-start",t)]=o);let s=G(n.marginBlockEnd);s!==void 0&&(e[y("se-item-margin-block-end",t)]=s),n.hidden!==void 0&&(e[y("se-item-display",t)]=n.hidden?"none":ve)}function Lt(e){let t={},[n,r]=X(e?.placeSelf),o={};O(t,"default",{alignSelf:n,justifySelf:r}),O(t,"default",e,o),O(t,"default",e?.responsive?.default,o);for(let s of h)O(t,s,e?.responsive?.[s],o);return t}var Me=Symbol.for("@schema-engine/layout/theme");function Nt(e){return typeof e=="object"&&e!==null&&Reflect.get(e,Me)===!0}function Vt(e){let t=5381;for(let n=0;n<e.length;n+=1)t=(t<<5)+t+e.charCodeAt(n)|0;return`l${(t>>>0).toString(36)}`}function _t(e){return e.registry.all().map(t=>[t.$type,t.default,Object.entries(t.values)])}function De(e,t={}){let n=je(e?.grid),r=me(e?.appearance,t),o=Vt(JSON.stringify({grid:Pe(n),appearance:_t(r)})),s=[Ve(n,o),fe(r,o)].filter(Boolean).join(`
4
- `),a={id:o,grid:n,axes:r.axes,appearance:r.registry,css:s};return Object.defineProperty(a,Me,{value:!0,enumerable:!1}),Object.freeze(a),a}var _e;function Mt(){return _e??=De(),_e}function Dt(e,t){let n=new Set(t);for(let r of Object.keys(e.axes))V(r,n)}function Bt(e,t){return{$type:e.$type,kind:e.kind,slots:e.slots,schema:e.schema,metadata:e.metadata,slotDefaults:e.slotDefaults,appearanceAxes:e.appearanceAxes,render:t}}import*as R from"zod/mini";import{createRegistry as Kt}from"@schema-engine/registry";function Be(e,t){if(e.length===0)throw new Error(`A recipe protocol must declare at least one ${t}.`);let n=new Set;for(let r of e){if(n.has(r))throw new Error(`A recipe protocol's ${t} '${r}' is declared twice.`);n.add(r)}}function Wt(e){return Be(e.slots,"slot"),Be(e.kinds,"kind"),Object.freeze({slots:Object.freeze([...e.slots]),kinds:Object.freeze([...e.kinds]),rules:Object.freeze([...e.rules??[]])})}function j(e,t){let n=e.kinds,r=e.slots;if(!n.includes(t.kind))throw new Error(`Recipe '${t.$type}' has kind '${t.kind}', which the protocol does not declare (kinds: ${e.kinds.join(", ")}).`);for(let o of t.slots)if(!r.includes(o))throw new Error(`Recipe '${t.$type}' declares slot '${o}', which the protocol does not declare (slots: ${e.slots.join(", ")}).`);for(let o of e.rules){let s=o.check(t);if(s!==void 0)throw new Error(`Recipe '${t.$type}' breaks rule '${o.name}': ${s}.`)}}function Zt(e,t){let n=Kt("Recipe",t);for(let r of n.all())j(e,r);return n}function Ut(e,t){let n={$type:R.literal(e)};for(let[r,o]of Object.entries(t))o&&(n[r]=R.prefault(o,{}));return R.strictObject(n)}function Ft(e,t,n){for(let[r,o]of Object.entries(n??{})){let s=t[r];if(!s)throw new Error(`Recipe '${e}' slotDefaults.${r}: the recipe does not declare a '${r}' slot.`);let a=R.safeParse(s,o);if(!a.success){let c=a.error.issues.map(p=>`${[...p.path,..."keys"in p&&Array.isArray(p.keys)?p.keys:[]].join(".")||"(value)"}: ${p.message}`);throw new Error(`Recipe '${e}' slotDefaults.${r} is invalid: ${c.join("; ")}`)}}}function Ht(e,t,n){for(let[r,o]of Object.entries(n??{})){if(!o)continue;let s=t[r];if(!s)throw new Error(`Recipe '${e}' appearanceAxes.${r}: the recipe does not declare a '${r}' slot.`);if(R.safeParse(s,{appearance:{}}).error?.issues.some(p=>p.code==="unrecognized_keys"&&p.keys.includes("appearance")))throw new Error(`Recipe '${e}' appearanceAxes.${r}: the '${r}' slot schema must accept an 'appearance' key (z.optional(AppearanceConfigSchema)).`)}}function Xt(e,t){let n=t.slotSchemas??{},r=Object.keys(n).filter(a=>n[a]);j(e,{$type:t.$type,kind:t.kind,slots:r});let o=e.slots.filter(a=>n[a]);Ft(t.$type,n,t.slotDefaults),Ht(t.$type,n,t.appearanceAxes);let s=Ut(t.$type,n);return{$type:t.$type,kind:t.kind,slots:o,slotSchemas:n,slotDefaults:t.slotDefaults,appearanceAxes:t.appearanceAxes,metadata:t.metadata,schema:s}}function Ke(e){if(typeof e!="object"||e===null)return!1;let t=Object.getPrototypeOf(e);return t===Object.prototype||t===null}function We(e,t){if(t===void 0)return e;if(!Ke(e)||!Ke(t))return t;let n={...e};for(let[r,o]of Object.entries(t))n[r]=We(e[r],o);return n}function q(e,t){if(!t)return e;let n={...e};for(let[r,o]of Object.entries(t))n[r]=We(o,e[r]);return n}function J(e){if(typeof e!="object"||e===null)return!1;let t=Object.getPrototypeOf(e);return t===Object.prototype||t===null}function Yt(e){if(!("appearance"in e))return e;let{appearance:t,...n}=e;return n}function qt(e,t){let n=e["~standard"].validate(t);if(n&&typeof n.then=="function")throw new Error("Async Standard Schema validation is not supported in this context");if(n===null||typeof n!="object")throw new Error("Standard Schema validation returned an invalid result");return n}function Jt(e,t,n){let r=[],o={...t},s={};for(let d of e.slots){let g=t[d],x=e.appearanceAxes?.[d]??[],T=D(J(g)?g.appearance:void 0,{axes:n.axes,subject:`Slot '${d}' of recipe '${e.$type}'`,supported:x});r.push(...T.issues.map(m=>({...m,path:[d,...m.path]})));let f=B(M(n.inherited,T.appearance),x);Object.keys(f).length>0&&(s[d]=f),J(g)&&(o[d]=Yt(g))}let a=qt(e.schema,q(o,e.slotDefaults));if(a.issues!==void 0)return{issues:r,schemaIssues:[...a.issues]};let c=a.value;if(typeof c!="object"||c===null||!("$type"in c)||typeof c.$type!="string")return r.push({path:["$type"],message:`Invalid view configuration for recipe '${e.$type}': parsed output is missing $type.`}),{issues:r};let p=new Set(e.slots);for(let d of Object.keys(t))d!=="$type"&&!p.has(d)&&r.push({path:[d],message:`Recipe '${e.$type}' does not accept view key '${d}'. Allowed: ${[...p].join(", ")||"(none)"}.`});let u={...c};for(let[d,g]of Object.entries(s)){let x=c[d];J(x)&&(u[d]={...x,appearance:g})}return{issues:r,view:u}}function Qt(e,t,n){return e[t]}export{Ze as AppearanceConfigSchema,nt as ElementGridConfigSchema,Ee as GRID_CLASS,Ie as GRID_ITEM_CLASS,lt as GRID_TEMPLATE_KEYS,se as GridBreakpointConfigSchema,A as GridGapTokens,tt as GridLayoutConfigSchema,N as GridOffsetNames,L as GridWidthNames,ce as ItemGridBreakpointSchema,v as WIDTH_TRACKS,Re as areaNames,Rt as areaTemplateIssues,Dt as assertAxesNotReserved,j as assertRecipeRules,Bt as bindRecipe,ue as builtInAxes,ht as cascadeValues,D as checkAppearance,Q as createAppearanceSchema,De as createLayoutTheme,Zt as createRecipeRegistry,_ as defineAxis,Xt as defineProtocolRecipeSpec,Wt as defineRecipeProtocol,gt as elementAreaSlots,ye as elementGridKeys,yt as elementHiddenSlots,he as elementUsesGridWidths,pt as getAppearanceAttributes,Mt as getDefaultLayoutTheme,Lt as getGridItemVariables,Et as getGridVariables,b as gridAreaTemplates,mt as gridUsesAreas,Nt as isLayoutTheme,M as mergeAppearance,q as mergeSlotDefaults,ut as namedPlacementOverflow,B as pickSupportedAppearance,Qt as readSlotConfig,Jt as resolveRecipeView,te as withAppearanceAxes,Xe as withSlotAppearanceAxes};
1
+ import*as f from"zod/mini";var nt=f.record(f.string(),f.string());function ie(e,t){let n=e.all().filter(r=>t===void 0||t.includes(r.$type)).map(r=>[r.$type,f.optional(f.enum(Object.keys(r.values)))]);return f.strictObject(Object.fromEntries(n))}function j(e){return"check"in e&&typeof e.check=="function"}function ae(e){return e._zod.def.type==="object"}function rt(e){return e._zod.def.type==="pipe"}function ot(e){return e._zod.def.type==="prefault"}function L(e,t){if(ae(e))return f.safeExtend(e,{appearance:t});if(rt(e)){let{in:n,out:r}=e._zod.def;if(!j(n))return e;let o=L(n,t);return o===n?e:f.pipe(o,r)}if(ot(e)){let{innerType:n,defaultValue:r}=e._zod.def;if(!j(n))return e;let o=L(n,t);return o===n?e:f.prefault(o,r)}return e}function st(e,t){return f.optional(ie(e,t)).check(f.describe("Named appearance values, one per declared axis"))}function ce(e,t,n=[]){return L(e,st(t,n))}function it(e,t,n={}){if(!ae(e))return e;let r={};for(let[o,s]of Object.entries(e._zod.def.shape)){if(!j(s))continue;let c=ce(s,t,n[o]);c!==s&&(r[o]=c)}return Object.keys(r).length===0?e:f.safeExtend(e,r)}import*as i from"zod/mini";var R=["none","compact","default","loose","wide"],w=i.union([i.enum(R),i.string()]).check(i.describe("Semantic gap token (none | compact | default | loose | wide) or a raw CSS length.")),at=["auto","span","none","default","inherit","initial","unset","revert","revert-layer"];function ct(e){return e.split("").map(t=>/[a-z]/i.test(t)?`[${t.toLowerCase()}${t.toUpperCase()}]`:t).join("")}var N=`(?!(?:${at.map(ct).join("|")})(?![\\w-]))-?[_a-zA-Z][_a-zA-Z0-9-]*`,pt=i.string().check(i.regex(new RegExp(`^${N}$`),'Area names are CSS identifiers such as "header" or "side-2".'),i.describe('Name of a cell group in the grid template: a CSS identifier such as "header" or "side-2".'));function de(e){return i.strictObject({default:i.optional(e),sm:i.optional(e),md:i.optional(e),lg:i.optional(e),xl:i.optional(e),"2xl":i.optional(e)})}function le(e){return i.optional(de(e))}var dt=i.string().check(i.regex(new RegExp(`^\\s*(?:\\.+|${N})(?:\\s+(?:\\.+|${N}))*\\s*$`),'A grid areas row lists area names (CSS identifiers) or "." for an empty cell, separated by spaces.')),pe=i.array(dt).check(i.minLength(1)),lt=i.union([pe,de(pe)]).check(i.describe('Rows of area names separated by spaces ("." is an empty cell), or a record of them per breakpoint (default, sm ... 2xl).')),ue=i.strictObject({areas:i.optional(lt),columns:i.optional(i.union([i.int().check(i.positive()),i.literal("auto")])),gap:i.optional(w),gapX:i.optional(w),gapY:i.optional(w),minColumnWidth:i.optional(i.string()),justifyItems:i.optional(i.enum(["start","end","center","stretch"])),alignItems:i.optional(i.enum(["start","end","center","stretch"])),placeItems:i.optional(i.string()),justifyContent:i.optional(i.enum(["start","end","center","stretch","space-around","space-between","space-evenly"])),alignContent:i.optional(i.enum(["start","end","center","stretch","space-around","space-between","space-evenly"])),placeContent:i.optional(i.string()),autoFlow:i.optional(i.enum(["row","dense"])).check(i.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."))}),fe=i.pick(ue,{columns:!0,gap:!0,gapX:!0,gapY:!0,minColumnWidth:!0}),ut=i.extend(ue,{responsive:le(fe)}),V=["full","three-quarters","two-thirds","half","third","quarter"],_=["three-quarters","two-thirds","half","third","quarter"],me=i.strictObject({area:i.optional(pt).check(i.describe("Name of the cell group this item fills in the grid areas template.")),width:i.optional(i.enum(V)).check(i.describe(`Named share of the row (${V.join(" | ")}).`)),offset:i.optional(i.enum(_)).check(i.describe(`Named empty space before the item (${_.join(" | ")}).`)),span:i.optional(i.int().check(i.positive())).check(i.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:i.optional(i.union([i.number(),i.string()])),row:i.optional(i.union([i.number(),i.string()])),justifySelf:i.optional(i.enum(["start","end","center","stretch"])),alignSelf:i.optional(i.enum(["start","end","center","stretch"])),placeSelf:i.optional(i.string()),subgrid:i.optional(i.boolean()).check(i.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:i.optional(w).check(i.describe("Extra space before this element, on top of the grid row gap.")),marginBlockEnd:i.optional(w).check(i.describe("Extra space after this element, on top of the grid row gap."))}),ge=i.extend(i.omit(me,{placeSelf:!0,subgrid:!0}),{hidden:i.optional(i.boolean())}),ft=i.extend(me,{responsive:le(ge)});import{createRegistry as mt}from"@schema-engine/registry";import*as v from"zod/mini";var gt=/^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$/,yt=/^[A-Za-z0-9][A-Za-z0-9_-]*$/,ht=/[{};<]|\/\*/,ye=2,he=5;function D(e,t){if(t.has(e))throw new Error(`Invalid appearance axis name '${e}': data-se-${e} is reserved by the renderer.`)}function Se(e){let t=e.$type;if(!gt.test(t))throw new Error(`Invalid appearance axis name '${t}': use lowercase letters, digits and hyphens, starting with a letter.`);let n=Object.entries(e.values);if(n.length<ye||n.length>he)throw new Error(`Invalid appearance axis '${t}': an axis has ${ye} to ${he} values, found ${n.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 (${n.map(([r])=>r).join(", ")}).`);for(let[r,o]of n){if(!yt.test(r))throw new Error(`Invalid appearance value '${r}' on axis '${t}': use letters, digits, hyphens and underscores.`);for(let[s,c]of Object.entries(o)){if(!s.startsWith("--")||s.length<3)throw new Error(`Invalid appearance token '${s}' on '${t}.${r}': tokens are CSS custom properties and start with '--'.`);if(ht.test(String(c)))throw new Error(`Invalid appearance token value for '${s}' on '${t}.${r}'.`)}}}function M(e){let t={$type:e.$type,values:e.values,default:e.default,metadata:e.metadata,schema:v.enum(Object.keys(e.values)).check(v.describe(e.metadata.description??e.metadata.name))};return Se(t),Object.freeze(t)}var St=M({$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))"}}}),xt=M({$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"}}}),xe=[St,xt];function Te(e,t){let n=[],r=[],o=`[data-se-theme="${t}"]`,s=`[data-se-theme]:not(${o})`;for(let c of e.registry.all())for(let[a,u]of Object.entries(c.values)){let d=Object.entries(u).map(([h,m])=>`${h}:${m};`);if(d.length===0)continue;let p=`{${d.join("")}}`,l=`[data-se-${c.$type}="${a}"]`,S=`${o} ${l}:not(${s},${o} ${s} *)`;n.push(`:where(${o}${l},${S})${p}`),r.push(`:where(:scope${l},${l})${p}`)}return r.length===0?"":[...n,`@scope (${o}) to (${s}){${r.join("")}}`].join(`
2
+ `)}function Re(e=xe,t={}){let n=mt("Axis",e),r=new Set(t.reservedNames);for(let o of n.all())Se(o),D(o.$type,r);return Object.freeze({registry:n,axes:Object.freeze(Object.fromEntries(n.all().map(o=>[o.$type,Object.freeze(Object.keys(o.values))])))})}function Tt(e){let t={};for(let[n,r]of Object.entries(e??{}))t[`data-se-${n}`]=r;return t}function K(e,t){return{...e,...t}}function Rt(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function B(e,t){let n=[],r={};if(e===void 0)return{issues:n,appearance:r};if(!Rt(e))return{issues:[{path:["appearance"],message:"Expected an object of axis names to values."}],appearance:r};let o=Object.keys(t.axes).join(", ");for(let[s,c]of Object.entries(e)){let a=Object.hasOwn(t.axes,s)?t.axes[s]:void 0;if(!a){n.push({path:["appearance",s],message:`Unknown axis '${s}'. Declared axes: ${o}.`});continue}if(t.supported!==void 0&&!t.supported.includes(s)){let u=t.supported.length>0?t.supported.join(", "):"(none)";n.push({path:["appearance",s],message:`${t.subject} does not support the axis '${s}'. Supported axes: ${u}.`});continue}if(typeof c!="string"){n.push({path:["appearance",s],message:`Expected one of ${a.join(", ")}.`});continue}if(!a.includes(c)){n.push({path:["appearance",s],message:`'${c}' is not a value of '${s}'. Allowed: ${a.join(", ")}.`});continue}r[s]=c}return{issues:n,appearance:r}}function W(e,t){let n={};for(let r of t??[]){let o=e[r];o!==void 0&&(n[r]=o)}return n}var x=["sm","md","lg","xl","2xl"],k=["default",...x],b=12,$={full:12,"three-quarters":9,"two-thirds":8,half:6,third:4,quarter:3},At=["columns","minColumnWidth"];function T(e){return typeof e=="object"&&e!==null}function A(e){if(!T(e)||!T(e.grid))return[];let t=e.grid,n=[{slot:"default",entry:t,path:["grid"]}],r=t.responsive;if(!T(r))return n;for(let o of k){let s=r[o];T(s)&&n.push({slot:o,entry:s,path:["grid","responsive",o]})}return n}function ke(e){let t=new Set;for(let{entry:n}of A(e))for(let[r,o]of Object.entries(n))r!=="responsive"&&o!==void 0&&t.add(r);return t}function we(e){let t=ke(e);return t.has("width")||t.has("offset")}function Z(e){return e.some(we)}function $e(e){return T(e)&&T(e.grid)&&e.grid.subgrid===!0}var kt=["width","offset","column","area","span","justifySelf","placeSelf"];function wt(e){if($e(e))for(let{entry:t,path:n}of A(e)){let r=kt.find(o=>t[o]!==void 0);if(r!==void 0)return{path:[...n,r],message:`sets grid 'subgrid' and '${r}'; a subgrid spans its parent's full row, so it takes no 'width', 'offset', 'column', 'area', 'span', 'justifySelf' or 'placeSelf'.`}}}var be=["width","offset","column","area"];function $t(e){for(let{slot:t,entry:n,path:r}of A(e)){if(n.span===void 0)continue;let o=be.find(s=>n[s]!==void 0);if(o!==void 0)return{path:[...r,o],message:`sets grid 'span' and '${o}'${t==="default"?"":` at '${t}'`}; a span is a placement of its own, so use 'span' or one of 'width', 'offset', 'column' and 'area' in a breakpoint, not together.`}}}function bt(e,t){if(!T(e)||ze(e)||Z(t))return[];let n={};for(let{slot:s,entry:c}of A({grid:e}))n[s]=c.columns??n[s];let r=new Set(U(n).filter(({value:s})=>s==="auto").map(({slot:s})=>s));if(r.size===0)return[];let o=[];return t.forEach((s,c)=>{let a={};for(let{slot:p,entry:l,path:S}of A(s))l.span!==void 0?a[p]={spanPath:[...S,"span"]}:be.some(h=>l[h]!==void 0)&&(a[p]={});let u=U(a).find(({slot:p,value:l})=>r.has(p)&&l?.spanPath),d=u?.value?.spanPath;!u||!d||o.push({path:[c,...d],message:`sets grid 'span' where the grid's columns are 'auto'${u.slot==="default"?"":` at '${u.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.`})}),o}function F(e,t){e.width=t.width??e.width,e.offset=t.offset??e.offset}function Gt(e){let t={};for(let{slot:n,entry:r}of A(e)){if(r.width===void 0&&r.offset===void 0||(F(t,r),t.width===void 0||t.offset===void 0))continue;let o=($[t.width]??0)+($[t.offset]??0);if(o>b)return{slot:n,tracks:o}}}var Ge=".";function zt(e){return typeof e!="string"?[]:e.trim().split(/\s+/).filter(Boolean).map(t=>/^\.+$/.test(t)?Ge:t)}function Ae(e){return Array.isArray(e)?e.map(zt):void 0}function G(e){if(!T(e)||e.areas===void 0)return{};if(Array.isArray(e.areas)){let n=Ae(e.areas);return n?{default:n}:{}}if(!T(e.areas))return{};let t={};for(let n of k){let r=Ae(e.areas[n]);r&&(t[n]=r)}return t}function ze(e){return Object.keys(G(e)).length>0}function ve(e){let t=new Set;for(let n of e)for(let r of n)r!==Ge&&t.add(r);return[...t]}function Ce(e){return e.map(t=>`"${t.join(" ")}"`).join(" ")}function vt(e){let t={};for(let{slot:n,entry:r}of A(e))typeof r.area=="string"&&(t[n]=r.area);return t}function Ct(e){let t={};for(let{slot:n,entry:r}of A(e))typeof r.hidden=="boolean"&&(t[n]=r.hidden);return t}function U(e){let t;return k.map(n=>(t=e[n]??t,{slot:n,value:t}))}function It(e){return`${e} ${e===1?"cell":"cells"}`}function Ot(e,t){let n=[];e.forEach((a,u)=>a.forEach((d,p)=>{d===t&&n.push([u,p])}));let r=n.map(([a])=>a),o=n.map(([,a])=>a),s=Math.max(...r)-Math.min(...r)+1,c=Math.max(...o)-Math.min(...o)+1;return s*c===n.length}function Pt(e){let t=G(e),n=T(e)&&Array.isArray(e.areas),r=[];for(let o of k){let s=t[o];if(!s)continue;let c=n?["areas"]:["areas",o],a=s[0]?.length??0,u=s.findIndex(d=>d.length!==a);if(u!==-1){r.push({path:c,message:`row ${u+1} has ${It(s[u]?.length??0)} but row 1 has ${a}.`});continue}for(let d of ve(s))Ot(s,d)||r.push({path:c,message:`area '${d}' is not rectangular; CSS drops the whole template unless every area fills a rectangle.`})}return r}var Et={sm:"40rem",md:"48rem",lg:"64rem",xl:"80rem","2xl":"96rem"},jt={none:"0",compact:"0.5rem",default:"var(--space-stack, 1rem)",loose:"var(--space-block-lg, 1.5rem)",wide:"var(--space-block-xl, 2rem)"},Lt="15.625rem",Nt={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 X(e){return`--se-grid-gap-base-${e}`}function _e(e){return`var(${Nt[e]}, var(${X(e)}))`}var Ie=_e("default"),H="--se-item-display-mode",De=`var(${H}, block)`,Me=16;function Ke(e){Object.freeze(e);for(let t of Object.values(e))t!==null&&typeof t=="object"&&!Object.isFrozen(t)&&Ke(t);return e}function Vt(e){let t={};for(let n of x){let r=e?.[n],o=R.filter(s=>r?.[s]!==void 0);o.length>0&&(t[n]=Object.fromEntries(o.map(s=>[s,r[s]])))}return t}function Be(e){let t={...Et,...e?.breakpoints},n={...jt,...e?.gap},r=Vt(e?.responsive),o=e?.minColumnWidth??Lt,s=e?.query??"media";return Kt(t),_t(s),Ke({breakpoints:t,gap:n,responsive:r,minColumnWidth:o,query:s})}function _t(e){if(e!=="media"&&e!=="container")throw new Error(`Grid theme query must be 'media' or 'container'; received '${e}'.`)}function Dt(e){return e==="px"||e==="rem"||e==="em"}function Mt(e,t){let n=/^(\d+(?:\.\d+)?)(px|rem|em)$/.exec(t),r=n?.[2];if(!n||!Dt(r))throw new Error(`Grid theme breakpoint '${e}' must be a px, rem, or em length; received '${t}'.`);let o=Number(n[1]);return r==="px"?o:o*Me}function Kt(e){let t=Number.NEGATIVE_INFINITY,n;for(let r of x){let o=e[r],s=Mt(r,o);if(n!==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 ${Me}px root); '${r}' (${o}) is smaller than '${n}' (${e[n]}).`);t=s,n=r}}function Bt(e){return x.flatMap(t=>{let n=e[t];if(!n)return[];let r=R.flatMap(o=>{let s=n[o];return s===void 0?[]:[[o,s]]});return[[t,r]]})}function We(e){return{breakpoints:e.breakpoints,gap:e.gap,responsive:Bt(e.responsive),minColumnWidth:e.minColumnWidth,...e.query==="media"?{}:{query:e.query}}}var Q="se-grid",J="se-grid-item",Ue="se-subgrid",Ze="se-grid-container",Oe="se-grid",te="--se-grid-track-count",C=[["grid-template-columns","se-grid-template","repeat(1, minmax(0, 1fr))"],["grid-template-areas","se-grid-areas","none"],["row-gap","se-grid-gap-y",Ie],["column-gap","se-grid-gap-x",Ie],[te,"se-grid-tracks","1"]],P="--se-grid-default-column",I=[["display","se-item-display",De],["grid-column","se-item-grid-column",`var(${P}, 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"]],Pe=[["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 Fe(e){return e.replaceAll(", ",",")}function ne(e,t,n,r){return`--${e}-${t}${n}${r}`}function Wt(e,t,n,r,o){let s=`var(--${r},${Fe(o)})`;for(let c of x)s=`var(${ne(e,t,n,c)},${s})`;return s}function Ee(e,t,n){return n.map(([r,o,s],c)=>`${r}:${Wt(e,t,c,o,s)};`).join("")}function Ut(e){return e.map(([t,n,r])=>`${t}:var(--${n},${Fe(r)});`).join("")}function je(e,t,n,r){return n.map(([,o],s)=>`${ne(e,t,s,r)}:var(--${o}-${r});`).join("")}function q(e,t){return e.flatMap(([,n])=>[`--${n}`,...t?x.map(r=>`--${n}-${r}`):[]]).map(n=>`${n}:initial;`).join("")}function Le(e,t,n){return n.flatMap((r,o)=>x.map(s=>`${ne(e,t,o,s)}:initial;`)).join("")}function qe(e,t){let n=`[data-se-theme="${t}"]`,r=`.${Q}${n}`,o=`.${J}${n}`,s=`.${Ue}${n}`,c=R.map(p=>`${X(p)}:${e.gap[p]};`).join(""),a=e.query==="container",u=a?`@container ${Oe}`:"@media",d=[`${n}{${c}}`,...a?[`.${Ze}${n}{display:block;width:100%;min-width:0;container-type:inline-size;container-name:${Oe};}`]:[],`${s}{${H}:grid;display:grid;grid-template-columns:subgrid;column-gap:normal;align-content:start;}`,`${s}>:not(.${J}){grid-column:1/-1;}`,`${r}{${a?Le(t,"g",C):""}${q(C,!0)}${q(Pe,!1)}${P}:initial;${H}:initial;display:grid;${Ee(t,"g",C)}${Ut(Pe)}}`,`.${Q}${s}{--se-grid-template:subgrid;--se-grid-gap-x:normal;${P}:inherit;${te}:inherit;}`,`${o}{${a?Le(t,"i",I):""}${q(I,!0)}${Ee(t,"i",I)}}`];for(let p of x){let l=e.responsive[p],S=l?R.filter(h=>l[h]!==void 0).map(h=>`${X(h)}:${l[h]};`).join(""):"";d.push(`${u} (min-width:${e.breakpoints[p]}){${S?`${n}{${S}}`:""}${r}{${je(t,"g",C,p)}}${o}{${je(t,"i",I,p)}}}`)}return d.join(`
3
+ `)}function Zt(e){for(let t of R)if(t===e)return!0;return!1}function z(e){if(e!==void 0)return Zt(e)?_e(e):e}var Ft=new Set(["safe","unsafe","first","last"]);function ee(e){if(e===void 0)return[void 0,void 0];let t=e.trim().split(/\s+/).filter(Boolean);if(t.length===0)return[void 0,void 0];let n=Ft.has(t[0])&&t.length>1?2:1,r=t.slice(0,n).join(" "),o=n<t.length?t.slice(n).join(" "):r;return[r,o]}function Ne(e,t){return e==="auto"?`repeat(auto-fit, minmax(min(${t}, 100%), 1fr))`:`repeat(${e}, minmax(0, 1fr))`}function y(e,t){return t==="default"?`--${e}`:`--${e}-${t}`}function Y(e,t,n){if(!n)return;let r=z(n.gap),o=z(n.gapX)??r,s=z(n.gapY)??r;s!==void 0&&(e[y("se-grid-gap-y",t)]=s),o!==void 0&&(e[y("se-grid-gap-x",t)]=o)}function qt(e,t,n){let r={},[o,s]=ee(e?.placeItems),[c,a]=ee(e?.placeContent),u={"--se-grid-justify-items":e?.justifyItems??s,"--se-grid-align-items":e?.alignItems??o,"--se-grid-justify-content":e?.justifyContent??a,"--se-grid-align-content":e?.alignContent??c,"--se-grid-auto-flow":e?.autoFlow};for(let[m,g]of Object.entries(u))g!==void 0&&(r[m]=g);let d=1,p=t.minColumnWidth,l=(m,g)=>{g&&(g.columns===void 0&&g.minColumnWidth===void 0||(g.columns!==void 0&&(d=g.columns),g.minColumnWidth!==void 0&&(p=g.minColumnWidth),r[y("se-grid-template",m)]=Ne(d,p),r[y("se-grid-tracks",m)]=String(d==="auto"?1:d)))};Z(n)&&(r["--se-grid-template"]=`repeat(${b}, minmax(0, 1fr))`,r["--se-grid-tracks"]=String(b),r[P]="1 / -1");let S=G(e);for(let m of k){let g=S[m];g&&(r[y("se-grid-areas",m)]=Ce(g),r[y("se-grid-template",m)]=Ne(g[0]?.length??1,t.minColumnWidth),r[y("se-grid-tracks",m)]=String(g[0]?.length??1))}let h=e?.responsive;l("default",e),l("default",h?.default),Y(r,"default",e),Y(r,"default",h?.default);for(let m of x)l(m,h?.[m]),Y(r,m,h?.[m]);return r}function Yt({width:e,offset:t}){let n=t===void 0?void 0:$[t]+1;if(e===void 0)return n===void 0?"auto":`${n} / -1`;let r=`span ${$[e]}`;return n===void 0?r:`${n} / ${r}`}function Xt(e){return`span min(${e},var(${te},1))`}function Ve(e){return typeof e=="number"?String(e):e}function O(e,t,n,r={}){if(!n)return;(n.width!==void 0||n.offset!==void 0)&&(F(r,n),e[y("se-item-grid-column",t)]=Yt(r)),n.span!==void 0&&(e[y("se-item-grid-column",t)]=Xt(n.span)),n.area!==void 0&&(e[y("se-item-grid-column",t)]=n.area,e[y("se-item-grid-row",t)]=n.area),n.column!==void 0&&(e[y("se-item-grid-column",t)]=Ve(n.column)),n.row!==void 0&&(e[y("se-item-grid-row",t)]=Ve(n.row)),n.justifySelf!==void 0&&(e[y("se-item-justify-self",t)]=n.justifySelf),n.alignSelf!==void 0&&(e[y("se-item-align-self",t)]=n.alignSelf);let o=z(n.marginBlockStart);o!==void 0&&(e[y("se-item-margin-block-start",t)]=o);let s=z(n.marginBlockEnd);s!==void 0&&(e[y("se-item-margin-block-end",t)]=s),n.hidden!==void 0&&(e[y("se-item-display",t)]=n.hidden?"none":De)}function Ht(e){let t={},[n,r]=ee(e?.placeSelf);e?.subgrid&&(t["--se-item-grid-column"]="1 / -1");let o={};O(t,"default",{alignSelf:n,justifySelf:r}),O(t,"default",e,o),O(t,"default",e?.responsive?.default,o);for(let s of x)O(t,s,e?.responsive?.[s],o);return t}var Xe=Symbol.for("@schema-engine/layout/theme");function Qt(e){return typeof e=="object"&&e!==null&&Reflect.get(e,Xe)===!0}function Jt(e){let t=5381;for(let n=0;n<e.length;n+=1)t=(t<<5)+t+e.charCodeAt(n)|0;return`l${(t>>>0).toString(36)}`}function en(e){return e.registry.all().map(t=>[t.$type,t.default,Object.entries(t.values)])}function He(e,t={}){let n=Be(e?.grid),r=Re(e?.appearance,t),o=Jt(JSON.stringify({grid:We(n),appearance:en(r)})),s=[qe(n,o),Te(r,o)].filter(Boolean).join(`
4
+ `),c={id:o,grid:n,axes:r.axes,appearance:r.registry,css:s};return Object.defineProperty(c,Xe,{value:!0,enumerable:!1}),Object.freeze(c),c}var Ye;function tn(){return Ye??=He(),Ye}function nn(e,t){let n=new Set(t);for(let r of Object.keys(e.axes))D(r,n)}function rn(e,t){return{$type:e.$type,kind:e.kind,slots:e.slots,schema:e.schema,metadata:e.metadata,slotDefaults:e.slotDefaults,appearanceAxes:e.appearanceAxes,slotSchemas:e.slotSchemas,render:t}}import{formatIssuePath as fn,safeParseStandardSchema as tt,standardSchema as mn}from"@schema-engine/registry";import{assertStandardSchema as on,createRegistry as sn}from"@schema-engine/registry";function Qe(e,t){if(e.length===0)throw new Error(`A recipe protocol must declare at least one ${t}.`);let n=new Set;for(let r of e){if(n.has(r))throw new Error(`A recipe protocol's ${t} '${r}' is declared twice.`);n.add(r)}}function an(e){return Qe(e.slots,"slot"),Qe(e.kinds,"kind"),Object.freeze({slots:Object.freeze([...e.slots]),kinds:Object.freeze([...e.kinds]),rules:Object.freeze([...e.rules??[]])})}function E(e,t){let n=e.kinds,r=e.slots;if(!n.includes(t.kind))throw new Error(`Recipe '${t.$type}' has kind '${t.kind}', which the protocol does not declare (kinds: ${e.kinds.join(", ")}).`);for(let o of t.slots)if(!r.includes(o))throw new Error(`Recipe '${t.$type}' declares slot '${o}', which the protocol does not declare (slots: ${e.slots.join(", ")}).`);for(let o of e.rules){let s=o.check(t);if(s!==void 0)throw new Error(`Recipe '${t.$type}' breaks rule '${o.name}': ${s}.`)}}function cn(e,t){let{slotSchemas:n}=t;if(n===void 0)return;let r=`${e} '${t.$type}' slotSchemas`,o=Object.keys(n).filter(a=>n[a]!==void 0),s=t.slots.filter(a=>!o.includes(a)),c=o.filter(a=>!t.slots.includes(a));if(s.length>0||c.length>0)throw new Error(`${r} must list exactly the recipe's slots (${t.slots.join(", ")||"none"}): ${[...s.map(a=>`'${a}' has no schema`),...c.map(a=>`'${a}' is not a declared slot`)].join(", ")}.`);for(let a of o)on(n[a],`${r}.${a}`)}function pn(e,t){let n=sn("Recipe",t);for(let r of n.all())E(e,r),cn(n.kind,r);return n}import{safeParseStandardSchema as dn}from"@schema-engine/registry";function Je(e){if(typeof e!="object"||e===null)return!1;let t=Object.getPrototypeOf(e);return t===Object.prototype||t===null}function et(e,t){if(t===void 0)return e;if(!Je(e)||!Je(t))return t;let n={...e};for(let[r,o]of Object.entries(t))n[r]=et(e[r],o);return n}function re(e,t){if(!t)return e;let n={...e};for(let[r,o]of Object.entries(t))n[r]=et(o,e[r]);return n}function oe(e){if(typeof e!="object"||e===null)return!1;let t=Object.getPrototypeOf(e);return t===Object.prototype||t===null}function ln(e){if(!("appearance"in e))return e;let{appearance:t,...n}=e;return n}function se(e,t,n){return`Recipe '${e}' does not accept view key '${t}'. Allowed: ${n.join(", ")||"(none)"}.`}function un(e,t,n){let r=[],o={...t},s={};for(let p of e.slots){let l=t[p],S=e.appearanceAxes?.[p]??[],h=B(oe(l)?l.appearance:void 0,{axes:n.axes,subject:`Slot '${p}' of recipe '${e.$type}'`,supported:S});r.push(...h.issues.map(g=>({...g,path:[p,...g.path]})));let m=W(K(n.inherited,h.appearance),S);Object.keys(m).length>0&&(s[p]=m),oe(l)&&(o[p]=ln(l))}let c=dn(e.schema,re(o,e.slotDefaults));if(!c.success)return{issues:r,schemaIssues:c.error.issues};let a=c.data;if(typeof a!="object"||a===null||!("$type"in a)||typeof a.$type!="string")return r.push({path:["$type"],message:`Invalid view configuration for recipe '${e.$type}': parsed output is missing $type.`}),{issues:r};let u=new Set(e.slots);for(let p of Object.keys(t))p!=="$type"&&!u.has(p)&&r.push({path:[p],message:se(e.$type,p,e.slots)});let d={...a};for(let[p,l]of Object.entries(s)){let S=a[p];oe(S)&&(d[p]={...S,appearance:l})}return{issues:r,view:d}}function gn(e,t,n){return mn(r=>{if(typeof r!="object"||r===null||Array.isArray(r))return{issues:[{message:"Expected a view object.",path:[]}]};let o=r,s=[];o.$type!==e&&s.push({message:`Expected $type '${e}'.`,path:["$type"]});for(let a of Object.keys(o))a!=="$type"&&!t.includes(a)&&s.push({message:se(e,a,t),path:[a]});let c={$type:e};for(let a of t){let u=n[a];if(!u)continue;let d=tt(u,o[a]===void 0?{}:o[a]);d.success?c[a]=d.data:s.push(...d.error.issues.map(p=>({...p,path:[a,...p.path??[]]})))}return s.length>0?{issues:s}:{value:c}})}function yn(e){let t=e.keys,n=Array.isArray(t)?t.filter(o=>typeof o=="string"||typeof o=="number"):[];return(n.length>0?n.map(o=>[...e.path??[],o]):[e.path]).map(o=>`${fn(o)||"(value)"}: ${e.message}`)}function hn(e,t,n){for(let[r,o]of Object.entries(n??{})){let s=t[r];if(!s)throw new Error(`Recipe '${e}' slotDefaults.${r}: the recipe does not declare a '${r}' slot.`);let c=tt(s,o);if(!c.success){let a=c.error.issues.flatMap(yn);throw new Error(`Recipe '${e}' slotDefaults.${r} is invalid: ${a.join("; ")}`)}}}function Sn(e,t,n){for(let[r,o]of Object.entries(n??{}))if(o&&!t[r])throw new Error(`Recipe '${e}' appearanceAxes.${r}: the recipe does not declare a '${r}' slot.`)}function xn(e,t){let n=t.slotSchemas??{},r=Object.keys(n).filter(c=>n[c]);E(e,{$type:t.$type,kind:t.kind,slots:r});let o=e.slots.filter(c=>n[c]);hn(t.$type,n,t.slotDefaults),Sn(t.$type,n,t.appearanceAxes);let s=gn(t.$type,o,n);return{$type:t.$type,kind:t.kind,slots:o,slotSchemas:n,slotDefaults:t.slotDefaults,appearanceAxes:t.appearanceAxes,metadata:t.metadata,schema:s}}function Tn(e,t,n){return e[t]}export{nt as AppearanceConfigSchema,ft as ElementGridConfigSchema,Q as GRID_CLASS,Ze as GRID_CONTAINER_CLASS,J as GRID_ITEM_CLASS,Ue as GRID_SUBGRID_CLASS,At as GRID_TEMPLATE_KEYS,fe as GridBreakpointConfigSchema,R as GridGapTokens,ut as GridLayoutConfigSchema,_ as GridOffsetNames,V as GridWidthNames,ge as ItemGridBreakpointSchema,b as WIDTH_TRACKS,ve as areaNames,Pt as areaTemplateIssues,nn as assertAxesNotReserved,E as assertRecipeRules,rn as bindRecipe,xe as builtInAxes,U as cascadeValues,B as checkAppearance,ie as createAppearanceSchema,He as createLayoutTheme,pn as createRecipeRegistry,M as defineAxis,xn as defineProtocolRecipeSpec,an as defineRecipeProtocol,vt as elementAreaSlots,ke as elementGridKeys,Ct as elementHiddenSlots,$e as elementIsSubgrid,we as elementUsesGridWidths,Tt as getAppearanceAttributes,tn as getDefaultLayoutTheme,Ht as getGridItemVariables,qt as getGridVariables,G as gridAreaTemplates,bt as gridSpanIssues,ze as gridUsesAreas,Qt as isLayoutTheme,K as mergeAppearance,re as mergeSlotDefaults,Gt as namedPlacementOverflow,W as pickSupportedAppearance,Tn as readSlotConfig,un as resolveRecipeView,$t as spanPlacementIssue,wt as subgridPlacementIssue,ce as withAppearanceAxes,it as withSlotAppearanceAxes};